Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(formats): type declarations #298

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-papayas-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"barnard59-formats": patch
---

Added type declarations
5 changes: 5 additions & 0 deletions .changeset/eighty-melons-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"barnard59-env": patch
---

Update `@zazuko/env-node`
5 changes: 5 additions & 0 deletions .changeset/young-turkeys-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"barnard59-formats": patch
---

Ensures that the RDF/JS environment is used with parser streams
40 changes: 26 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
env:
- os: ubuntu-latest
node: 20
- os: macos-latest
node: 20
- os: windows-latest
node: 20.12.1 # Pinned, because of https://github.com/approvals/Approvals.NodeJS/issues/176
runs-on: ${{ matrix.env.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.env.node }}
cache: npm
- run: npm ci
- run: npx barnard59 run test/e2e/definitions/file-loader.ttl
- run: npx barnard59 run test/e2e/definitions/foreach/with-handler.ttl
Expand All @@ -103,25 +109,31 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
env:
- os: ubuntu-latest
node: 20
- os: macos-latest
node: 20
- os: windows-latest
node: 20.12.1 # Pinned, because of https://github.com/approvals/Approvals.NodeJS/issues/176
runs-on: ${{ matrix.env.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.env.node }}
cache: npm
- run: npm ci
- name: pack all
run: npm pack -ws
- run: npm install -g barnard59-*.tgz
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
if: matrix.env.os == 'ubuntu-latest' || matrix.env.os == 'macos-latest'
- run: cmd /c npm install -g (Get-ChildItem -Filter barnard59-*.tgz).FullName
if: matrix.os == 'windows-latest'
if: matrix.env.os == 'windows-latest'
- run: which barnard59
- run: barnard59 --help
- run: barnard59 shacl validate --shapes test/support/pipeline-shapes.ttl < test/e2e/definitions/file-loader.ttl
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
if: matrix.env.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
- run: barnard59 shacl validate --shapes test/support/pipeline-shapes.ttl < test/e2e/definitions/file-loader.ttl
if: matrix.os == 'windows-latest'
if: matrix.env.os == 'windows-latest'
shell: cmd
132 changes: 56 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"mocha": "^10.2.0",
"sinon-chai": "^3.7.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.2",
"typescript": "^5.4.5",
"wsrun": "^5.2.4"
},
"lint-staged": {
Expand Down
30 changes: 29 additions & 1 deletion packages/formats/csvw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,41 @@
import tracer from './lib/tracer.js'
import { toDataset } from './lib/stream.js'

/**
* @typedef {{
* metadata: import('@rdfjs/types').DatasetCore
* timezone?: string
* relaxColumnCount?: boolean
* skipLinesWithError?: boolean
* }} Options
*/

/**
* @overload
* @param {Options} args
* @return {import('duplexify').Duplexify}
*/

/**
* @overload
* @param {import('@rdfjs/types').DatasetCore} metadata
* @return {import('duplexify').Duplexify}
*/

/**
* @this {import('barnard59-core').Context}
* @param {Options | import('@rdfjs/types').DatasetCore} args
*/

Check warning on line 30 in packages/formats/csvw.js

View check run for this annotation

Codecov / codecov/patch

packages/formats/csvw.js#L6-L30

Added lines #L6 - L30 were not covered by tests
function parse(args) {
/**
* @type {import('@rdfjs/types').DatasetCore}
*/

Check warning on line 34 in packages/formats/csvw.js

View check run for this annotation

Codecov / codecov/patch

packages/formats/csvw.js#L32-L34

Added lines #L32 - L34 were not covered by tests
let metadata
let relaxColumnCount = false
let skipLinesWithError = false
let timezone = 'local'

if (args.metadata) {
if ('metadata' in args) {

Check warning on line 40 in packages/formats/csvw.js

View check run for this annotation

Codecov / codecov/patch

packages/formats/csvw.js#L40

Added line #L40 was not covered by tests
metadata = args.metadata

if (typeof args.relaxColumnCount !== 'undefined') {
Expand Down
23 changes: 17 additions & 6 deletions packages/formats/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
import { combine, jsonStringify } from 'barnard59-base'
import tracer from './lib/tracer.js'

/**
* @this {import('barnard59-core').Context}
* @param {Object} [options]
* @param {string | Record<string, string>} [options.localContext]
*/
function parse({ localContext } = {}) {
let documentLoader = null
/**
* @type {import('@rdfjs/parser-jsonld').DocumentLoader | undefined}
*/
let documentLoader

if (localContext) {
if (typeof localContext === 'string') {
localContext = JSON.parse(localContext)
documentLoader = new FsDocumentLoader(JSON.parse(localContext))
} else {
documentLoader = new FsDocumentLoader(localContext)
}

documentLoader = new FsDocumentLoader(localContext)
}

return tracer.startActiveSpan('jsonld:parse', span => {
const stream = sinkToDuplex(new Parser({ factory: this.env, documentLoader }), { objectMode: true })
stream.on('error', err => {
stream.on('error', /** @type {any} */ err => {
span.recordException(err)
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
span.end()
Expand All @@ -29,10 +37,13 @@
})
}

/**
* @this {import('barnard59-core').Context}
*/
const parseObject = function () {
return tracer.startActiveSpan('jsonld:parse.object', span => {
const stream = combine([jsonStringify(), parse.call(this)], { objectMode: true })
stream.on('error', err => {
stream.on('error', (/** @type Error */ err) => {

Check warning on line 46 in packages/formats/jsonld.js

View check run for this annotation

Codecov / codecov/patch

packages/formats/jsonld.js#L46

Added line #L46 was not covered by tests
span.recordException(err)
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
span.end()
Expand Down
Loading
Loading