@comunica/bus-dereference 3.0.3 → 3.2.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.
|
@@ -63,7 +63,8 @@ class ActorDereferenceParse extends ActorDereferenceBase_1.ActorDereferenceBase
|
|
|
63
63
|
result = (await this.mediatorParse.mediate({
|
|
64
64
|
context,
|
|
65
65
|
handle: { context, ...dereference, metadata: await this.getMetadata(dereference) },
|
|
66
|
-
|
|
66
|
+
// eslint-disable-next-line ts/prefer-nullish-coalescing
|
|
67
|
+
handleMediaType: (dereference.mediaType ||
|
|
67
68
|
getMediaTypeFromExtension(dereference.url, this.mediaMappings)) ||
|
|
68
69
|
action.mediaType,
|
|
69
70
|
})).handle;
|
|
@@ -1 +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,wDAAwD;IACxD,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5E,CAAC;AALD,8DAKC;AAiBD;;;;;;;;GAQG;AACH,MAAsB,qBAIpB,SAAQ,2CAAgG;IAMxG,YAAmB,IAAyC;QAC1D,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAA2B;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACO,6BAA6B,CACrC,MAAkC,EAClC,IAAO;QAEP,oGAAoG;QACpG,IAAI,CAAC,IAAA,kCA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,MAAM,CAAC,SAAS;aACnB,CAAC,CAAC,CAAC,MAAM,CAAC;YACX,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,6BAA6B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,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;QACjE,CAAC;QAED,4CAA4C;QAC5C,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,MAAM,EAAE,CAAC;IACvC,CAAC;CACF;AArED,sDAqEC","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 // eslint-disable-next-line ts/prefer-nullish-coalescing\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.logWarn(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 // eslint-disable-next-line ts/prefer-nullish-coalescing\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/bus-dereference",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "A bus for dereferencing a path or URL into a (generic) stream.",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"lib/**/*.js.map"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "
|
|
34
|
+
"build": "yarn run build:ts && yarn run build:components",
|
|
35
35
|
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
|
|
36
36
|
"build:components": "componentsjs-generator"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@comunica/actor-abstract-mediatyped": "^3.0
|
|
40
|
-
"@comunica/actor-abstract-parse": "^3.0
|
|
41
|
-
"@comunica/context-entries": "^3.0
|
|
42
|
-
"@comunica/core": "^3.0
|
|
43
|
-
"@comunica/types": "^3.0
|
|
39
|
+
"@comunica/actor-abstract-mediatyped": "^3.2.0",
|
|
40
|
+
"@comunica/actor-abstract-parse": "^3.2.0",
|
|
41
|
+
"@comunica/context-entries": "^3.2.0",
|
|
42
|
+
"@comunica/core": "^3.2.0",
|
|
43
|
+
"@comunica/types": "^3.2.0",
|
|
44
44
|
"readable-stream": "^4.4.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "87baf2afed021a254859e64b92f34d9b51c6a7db"
|
|
47
47
|
}
|