@comunica/bus-dereference 2.4.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActorDereference.js","sourceRoot":"","sources":["ActorDereference.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAE9D;;;;;;;;;;GAUG;AACH,MAAsB,gBAAiB,SACrC,2CAA6E;IAC7E;;OAEG;IACH,YAAmB,IAA2B;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACO,KAAK,CAAC,uBAAuB,CACrC,MAA0B,EAC1B,KAAc,EACd,OAA6B,EAC7B,WAAW,GAAG,CAAC;QAEf,OAAO,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAC/G,CAAC;CACF;AA1BD,4CA0BC","sourcesContent":["import type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';\nimport { ActorDereferenceBase } from './ActorDereferenceBase';\n\n/**\n * A base actor for dereferencing URLs to (generic) streams.\n *\n * Actor types:\n * * Input: IActionDereference: A URL.\n * * Test: <none>\n * * Output: IActorDereferenceOutput: A Readable stream\n *\n * @see IActionDereference\n * @see IActorDereferenceOutput\n */\nexport abstract class ActorDereference extends\n ActorDereferenceBase<IActionDereference, IActorTest, IActorDereferenceOutput> {\n /**\n * @param args - @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus\n */\n public constructor(args: IActorDereferenceArgs) {\n super(args);\n }\n\n /**\n * Handle the given error as a rejection or delegate it to the logger,\n * depending on whether or not hard errors are enabled.\n * @param {IActionDereference} action A dereference action.\n * @param {Error} error An error that has occurred.\n * @param headers Optional HTTP headers to pass.\n * @param {number} requestTime The time it took to request the page in milliseconds.\n * @return {Promise<IActorDereferenceOutput>} A promise that rejects or resolves to an empty output.\n */\n protected async handleDereferenceErrors(\n action: IActionDereference,\n error: unknown,\n headers?: Headers | undefined,\n requestTime = 0,\n ): Promise<IActorDereferenceOutput> {\n return this.dereferenceErrorHandler(action, error, { url: action.url, exists: false, headers, requestTime });\n }\n}\n\nexport interface IActionDereference extends IAction {\n /**\n * The URL to dereference\n */\n url: string;\n /**\n * By default, actors will reject upon receiving non-200 HTTP responses.\n * If this option is true, then all HTTP responses will cause the action to resolve,\n * but some outputs may therefore contain empty quad streams.\n */\n acceptErrors?: boolean;\n /**\n * Optional HTTP method to use.\n * Defaults to GET.\n */\n method?: string;\n /**\n * Optional HTTP headers to pass.\n */\n headers?: Headers;\n /**\n * An optional callback to retrieve the mediaType mappings\n */\n mediaTypes?: () => Promise<Record<string, number> | undefined>;\n}\n\ninterface IReadableClose extends NodeJS.ReadableStream {\n close?: () => void | Promise<void>;\n}\n\nexport interface IActorDereferenceOutput extends IActorOutput {\n /**\n * The page on which the output was found.\n *\n * This is not necessarily the same as the original input url,\n * as this may have changed due to redirects.\n */\n url: string;\n /**\n * The resulting stream.\n */\n data: IReadableClose;\n /**\n * This will always be true, unless `acceptErrors` was set to true in the action and the dereferencing failed.\n */\n exists: boolean;\n /**\n * The time it took to request the page in milliseconds.\n * This is the time until the first byte arrives.\n */\n requestTime: number;\n /**\n * The returned headers of the final URL.\n */\n headers?: Headers;\n /**\n * The mediatype of the source\n */\n mediaType?: string;\n}\n\nexport type IActorDereferenceArgs = IActorArgs<IActionDereference, IActorTest, IActorDereferenceOutput>;\n\nexport type MediatorDereference = Mediate<IActionDereference, IActorDereferenceOutput>;\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActorDereferenceBase.js","sourceRoot":"","sources":["ActorDereferenceBase.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,yCAAuC;AAEvC,qDAA2C;AAG3C,SAAgB,aAAa;IAC3B,MAAM,IAAI,GAAG,IAAI,0BAAQ,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,OAAW,IAAI,CAAC;AAClB,CAAC;AAJD,sCAIC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,OAAuB;IACjD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAFD,kCAEC;AAED;;;;;;;;;;GAUG;AACH,MAAsB,oBACpB,SAAQ,YAAc;IACtB,YAAmB,IAAyB;QAC1C,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,uBAAuB,CACrC,MAAS,EACT,KAAc,EACd,MAAS;QAET,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;YAC/B,MAAM,KAAK,CAAC;SACb;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAW,KAAM,CAAC,OAAO,CAAC,CAAC;QACvD,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,aAAa,EAAK,EAAE,CAAC;IACjD,CAAC;CACF;AAxBD,oDAwBC","sourcesContent":["import { KeysInitQuery } from '@comunica/context-entries';\nimport type { IAction, IActorArgs, IActorTest } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type { IActionContext } from '@comunica/types';\nimport { Readable } from 'readable-stream';\nimport type { IActorDereferenceOutput } from '.';\n\nexport function emptyReadable<S extends Readable>(): S {\n const data = new Readable();\n data.push(null);\n return <S> data;\n}\n\n/**\n * Check if hard errors should occur on HTTP or parse errors.\n * @param {IActionDereference} action A dereference action.\n * @return {boolean} If hard errors are enabled.\n */\nexport function isHardError(context: IActionContext): boolean {\n return !context.get(KeysInitQuery.lenient);\n}\n\n/**\n * A base actor for dereferencing URLs to (generic) streams.\n *\n * Actor types:\n * * Input: IActionDereference: A URL.\n * * Test: <none>\n * * Output: IActorDereferenceOutput: A Readable stream\n *\n * @see IActionDereference\n * @see IActorDereferenceOutput\n */\nexport abstract class ActorDereferenceBase<I extends IAction, T extends IActorTest, O extends IActorDereferenceOutput>\n extends Actor<I, T, O> {\n public constructor(args: IActorArgs<I, T, O>) {\n super(args);\n }\n\n /**\n * Handle the given error as a rejection or delegate it to the logger,\n * depending on whether or not hard errors are enabled.\n * @param {I} action An action.\n * @param {Error} error An error that has occurred.\n * @param {N} output Data to add to the output\n */\n protected async dereferenceErrorHandler<N, M extends Readable>(\n action: I,\n error: unknown,\n output: N,\n ): Promise<N & { data: M }> {\n if (isHardError(action.context)) {\n throw error;\n }\n this.logError(action.context, (<Error> error).message);\n return { ...output, data: emptyReadable<M>() };\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActorDereferenceParse.js","sourceRoot":"","sources":["ActorDereferenceParse.ts"],"names":[],"mappings":";;;AAIA,qDAA8C;AAE9C,iEAA2E;AAE3E;;;;;;;GAOG;AACH,SAAgB,yBAAyB,CAAC,IAAY,EAAE,aAAsC;IAC5F,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,gDAAgD;IAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5E,CAAC;AAJD,8DAIC;AAiBD;;;;;;;;GAQG;AACH,MAAsB,qBAIpB,SAAQ,2CAAgG;IAMxG,YAAmB,IAAyC;QAC1D,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAA0B;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACO,6BAA6B,CACrC,MAAkC,EAClC,IAAO;QAEP,oGAAoG;QACpG,IAAI,CAAC,IAAA,kCAAW,EAAC,MAAM,CAAC,OAAO,CAAC,EAAE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,IAAI,GAAG,IAAI,CAAC,6BAA6B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;SACvE;QAAC,OAAO,KAAc,EAAE;YACvB,2CAA2C;YAC3C,MAAM,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACjC,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;SAChE;QAED,4CAA4C;QAC5C,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,MAAM,EAAE,CAAC;IACvC,CAAC;CACF;AApED,sDAoEC","sourcesContent":["import type { MediateMediaTyped, MediateMediaTypes } from '@comunica/actor-abstract-mediatyped';\nimport type { IActionParse, IActorParseOutput, IParseMetadata } from '@comunica/actor-abstract-parse';\nimport type { IActorArgs, IActorTest } from '@comunica/core';\nimport type { Readable } from 'readable-stream';\nimport { PassThrough } from 'readable-stream';\nimport type { IActionDereference, IActorDereferenceOutput, MediatorDereference } from './ActorDereference';\nimport { ActorDereferenceBase, isHardError } from './ActorDereferenceBase';\n\n/**\n * Get the media type based on the extension of the given path,\n * which can be an URL or file path.\n * @param {string} path A path.\n * @param {Record<string, string>} mediaMappings A collection of mappings,\n * mapping file extensions to their corresponding media type.\n * @return {string} A media type or the empty string.\n */\nexport function getMediaTypeFromExtension(path: string, mediaMappings?: Record<string, string>): string {\n const dotIndex = path.lastIndexOf('.');\n // Get extension after last dot and map to media\n return (dotIndex >= 0 && mediaMappings?.[path.slice(dotIndex + 1)]) || '';\n}\n\nexport interface IActorDereferenceParseArgs<\n S,\n K extends IParseMetadata = IParseMetadata,\n M extends IParseMetadata = IParseMetadata\n> extends IActorArgs<IActionDereferenceParse<K>, IActorTest, IActorDereferenceParseOutput<S, M>> {\n mediatorDereference: MediatorDereference;\n mediatorParse: MediateMediaTyped<IActionParse<K>, IActorTest, IActorParseOutput<S, M>>;\n mediatorParseMediatypes: MediateMediaTypes;\n /**\n * A collection of mappings, mapping file extensions to their corresponding media type.\n * @range {json}\n */\n mediaMappings: Record<string, string>;\n}\n\n/**\n * An abstract actor that handles dereference and parse actions.\n *\n * Actor types:\n * Input: IActionDereferenceParse: A URL.\n * Test: <none>\n * Output: IActorDereferenceParseOutput: A data stream of type output by the Parser.\n *\n */\nexport abstract class ActorDereferenceParse<\n S,\n K extends IParseMetadata = IParseMetadata,\n M extends IParseMetadata = IParseMetadata\n> extends ActorDereferenceBase<IActionDereferenceParse<K>, IActorTest, IActorDereferenceParseOutput<S, M>> {\n public readonly mediatorDereference: MediatorDereference;\n public readonly mediatorParse: MediateMediaTyped<IActionParse<K>, IActorTest, IActorParseOutput<S, M>>;\n public readonly mediatorParseMediatypes: MediateMediaTypes;\n public readonly mediaMappings: Record<string, string>;\n\n public constructor(args: IActorDereferenceParseArgs<S, K, M>) {\n super(args);\n }\n\n public async test(action: IActionDereference): Promise<IActorTest> {\n return true;\n }\n\n /**\n * If hard errors are disabled, modify the given stream so that errors are delegated to the logger.\n * @param {IActionDereferenceParse} action A dereference action.\n * @param {Readable} data A data stream.\n * @return {Readable} The resulting data stream.\n */\n protected handleDereferenceStreamErrors<L extends IParseMetadata, T extends Readable>(\n action: IActionDereferenceParse<L>,\n data: T,\n ): T {\n // If we don't emit hard errors, make parsing error events log instead, and silence them downstream.\n if (!isHardError(action.context)) {\n data.on('error', error => {\n this.logError(action.context, error.message, () => ({ url: action.url }));\n // Make sure the errored stream is ended.\n data.push(null);\n });\n data = <PassThrough & T> data.pipe(new PassThrough({ objectMode: true }));\n }\n return data;\n }\n\n public abstract getMetadata(dereference: IActorDereferenceOutput): Promise<K | undefined>;\n\n public async run(action: IActionDereferenceParse<K>): Promise<IActorDereferenceParseOutput<S, M>> {\n const { context } = action;\n const dereference = await this.mediatorDereference.mediate({\n ...action,\n mediaTypes: async() => (await this.mediatorParseMediatypes?.mediate({ context, mediaTypes: true }))?.mediaTypes,\n });\n\n let result: IActorParseOutput<S, M>;\n try {\n result = (await this.mediatorParse.mediate({\n context,\n handle: { context, ...dereference, metadata: await this.getMetadata(dereference) },\n handleMediaType: dereference.mediaType ||\n getMediaTypeFromExtension(dereference.url, this.mediaMappings) ||\n action.mediaType,\n })).handle;\n result.data = this.handleDereferenceStreamErrors(action, result.data);\n } catch (error: unknown) {\n // Close the body, to avoid process to hang\n await dereference.data.close?.();\n result = await this.dereferenceErrorHandler(action, error, {});\n }\n\n // Return the parsed stream and any metadata\n return { ...dereference, ...result };\n }\n}\n\nexport interface IActionDereferenceParse<T extends IParseMetadata = IParseMetadata> extends IActionDereference {\n /**\n * The mediatype of the source (if it can't be inferred from the source)\n */\n mediaType?: string;\n /**\n * Metadata to be given to the parser\n */\n metadata?: T;\n}\n\nexport type IActorDereferenceParseOutput<T, K extends IParseMetadata = IParseMetadata>\n = Omit<IActorDereferenceOutput, 'data'> & IActorParseOutput<T, K>;\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,0DAAwC;AACxC,yDAAuC","sourcesContent":["export * from './ActorDereference';\nexport * from './ActorDereferenceParse';\nexport * from './ActorDereferenceBase';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/bus-dereference",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "description": "A bus for dereferencing a path or URL into a (generic) stream.",
5
5
  "lsd:module": true,
6
6
  "main": "lib/index.js",
@@ -27,14 +27,15 @@
27
27
  "files": [
28
28
  "components",
29
29
  "lib/**/*.d.ts",
30
- "lib/**/*.js"
30
+ "lib/**/*.js",
31
+ "lib/**/*.js.map"
31
32
  ],
32
33
  "dependencies": {
33
- "@comunica/actor-abstract-mediatyped": "^2.4.0",
34
- "@comunica/actor-abstract-parse": "^2.4.0",
35
- "@comunica/context-entries": "^2.4.0",
36
- "@comunica/core": "^2.4.0",
37
- "@comunica/types": "^2.4.0",
34
+ "@comunica/actor-abstract-mediatyped": "^2.5.0",
35
+ "@comunica/actor-abstract-parse": "^2.5.0",
36
+ "@comunica/context-entries": "^2.5.0",
37
+ "@comunica/core": "^2.5.0",
38
+ "@comunica/types": "^2.5.0",
38
39
  "readable-stream": "^4.0.0"
39
40
  },
40
41
  "scripts": {
@@ -42,5 +43,5 @@
42
43
  "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
43
44
  "build:components": "componentsjs-generator"
44
45
  },
45
- "gitHead": "ead42818468757f23a7837969e14b83cf19c4438"
46
+ "gitHead": "349d57f5d1e539200e980bdff96973c2e0b66caa"
46
47
  }
package/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
4
- Comunica Association and Ghent University – imec, Belgium
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.