Skip to content

Commit

Permalink
use async generator
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Sep 26, 2024
1 parent 36a7648 commit bb137fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions cli/lib/replace.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import through2 from 'through2'
import type { Quad } from '@rdfjs/types'
import $rdf from 'rdf-ext'
import { Context } from 'barnard59-core'

function replace(version: string) {
export default function replace(this: Context, version: string) {
const prefix = 'https://cube.link/latest/'
const replacement = `https://cube.link/${version}/`
return through2.obj(function (quad: Quad, _, done) {
if (quad.predicate.value === 'https://code.described.at/imports' && quad.object.value.startsWith(prefix)) {
const replaced = quad.object.value.replace(prefix, replacement)
const triple = $rdf.triple(quad.subject, quad.predicate, $rdf.namedNode(replaced))
done(null, triple)
} else {
done(null, quad)
const { env } = this

return async function * (stream: AsyncIterable<Quad>) {
for await (const quad of stream) {
if (quad.predicate.equals(env.ns.code.imports) && quad.object.value.startsWith(prefix)) {
const replaced = quad.object.value.replace(prefix, replacement)
yield env.quad(quad.subject, quad.predicate, env.namedNode(replaced))
} else {
yield quad
}
}
})
}
}

export default replace
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"alcaeus": "^2",
"aws-sdk": "^2.559.0",
"barnard59": "^5.0.4",
"barnard59-core": "^6.0.0",
"barnard59-base": "^2.4.2",
"barnard59-cube": "^1.4.8",
"barnard59-formats": "^4.0.0",
Expand Down Expand Up @@ -112,7 +113,6 @@
"@types/sinon-chai": "^3.2.4",
"@types/sparql-http-client": "^2",
"@types/through2": "^2.0.36",
"barnard59-core": "^6.0.0",
"chai": "^4.3.4",
"dotenv": "^16.0.0",
"dotenv-cli": "^5.0.0",
Expand Down

0 comments on commit bb137fe

Please sign in to comment.