@comunica/bus-dereference 4.4.1 → 4.4.2-alpha.49.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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,6 +10,11 @@ export declare function emptyReadable<S extends Readable>(): S;
10
10
  * @return {boolean} If hard errors are enabled.
11
11
  */
12
12
  export declare function isHardError(context: IActionContext): boolean;
13
+ /**
14
+ * If a warning should be emitted for the given type of error.
15
+ * @param error An error.
16
+ */
17
+ export declare function shouldLogWarning(error: Error): boolean;
13
18
  /**
14
19
  * A base actor for dereferencing URLs to (generic) streams.
15
20
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActorDereferenceBase = exports.isHardError = exports.emptyReadable = void 0;
3
+ exports.ActorDereferenceBase = exports.shouldLogWarning = exports.isHardError = exports.emptyReadable = void 0;
4
4
  const context_entries_1 = require("@comunica/context-entries");
5
5
  const core_1 = require("@comunica/core");
6
6
  const readable_stream_1 = require("readable-stream");
@@ -19,6 +19,14 @@ function isHardError(context) {
19
19
  return !context.get(context_entries_1.KeysInitQuery.lenient);
20
20
  }
21
21
  exports.isHardError = isHardError;
22
+ /**
23
+ * If a warning should be emitted for the given type of error.
24
+ * @param error An error.
25
+ */
26
+ function shouldLogWarning(error) {
27
+ return error.name !== 'AbortError';
28
+ }
29
+ exports.shouldLogWarning = shouldLogWarning;
22
30
  /**
23
31
  * A base actor for dereferencing URLs to (generic) streams.
24
32
  *
@@ -45,7 +53,9 @@ class ActorDereferenceBase extends core_1.Actor {
45
53
  if (isHardError(action.context)) {
46
54
  throw error;
47
55
  }
48
- this.logWarn(action.context, error.message, () => ({ url: action.url }));
56
+ if (shouldLogWarning(error)) {
57
+ this.logWarn(action.context, error.message, () => ({ url: action.url }));
58
+ }
49
59
  return { ...output, data: emptyReadable() };
50
60
  }
51
61
  }
@@ -1 +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,oBAMpB,SAAQ,YAAkB;IAC1B,YAAmB,IAA6B;QAC9C,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,CAAC;YAChC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAW,KAAM,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACnF,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,aAAa,EAAK,EAAE,CAAC;IACjD,CAAC;CACF;AA7BD,oDA6BC","sourcesContent":["import { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorArgs, IActorTest } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type { IActionContext } from '@comunica/types';\nimport { Readable } from 'readable-stream';\nimport type { IActorDereferenceOutput, IActionDereference } from './ActorDereference';\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 {IActionContext} context An action context.\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<\n I extends IActionDereference,\nT extends IActorTest,\nO extends IActorDereferenceOutput,\nTS = undefined,\n>\n extends Actor<I, T, O, TS> {\n public constructor(args: IActorArgs<I, T, O, TS>) {\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.logWarn(action.context, (<Error> error).message, () => ({ url: action.url }));\n return { ...output, data: emptyReadable<M>() };\n }\n}\n"]}
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;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAAY;IAC3C,OAAO,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;AACrC,CAAC;AAFD,4CAEC;AAED;;;;;;;;;;GAUG;AACH,MAAsB,oBAMpB,SAAQ,YAAkB;IAC1B,YAAmB,IAA6B;QAC9C,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,CAAC;YAChC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,IAAI,gBAAgB,CAAS,KAAK,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAU,KAAM,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,aAAa,EAAK,EAAE,CAAC;IACjD,CAAC;CACF;AA/BD,oDA+BC","sourcesContent":["import { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorArgs, IActorTest } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type { IActionContext } from '@comunica/types';\nimport { Readable } from 'readable-stream';\nimport type { IActorDereferenceOutput, IActionDereference } from './ActorDereference';\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 {IActionContext} context An action context.\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 * If a warning should be emitted for the given type of error.\n * @param error An error.\n */\nexport function shouldLogWarning(error: Error): boolean {\n return error.name !== 'AbortError';\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<\n I extends IActionDereference,\nT extends IActorTest,\nO extends IActorDereferenceOutput,\nTS = undefined,\n>\n extends Actor<I, T, O, TS> {\n public constructor(args: IActorArgs<I, T, O, TS>) {\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 if (shouldLogWarning(<Error> error)) {\n this.logWarn(action.context, (<Error>error).message, () => ({ url: action.url }));\n }\n return { ...output, data: emptyReadable<M>() };\n }\n}\n"]}
File without changes
@@ -45,7 +45,9 @@ class ActorDereferenceParse extends ActorDereferenceBase_1.ActorDereferenceBase
45
45
  // If we don't emit hard errors, make parsing error events log instead, and silence them downstream.
46
46
  if (!(0, ActorDereferenceBase_1.isHardError)(action.context)) {
47
47
  data.on('error', (error) => {
48
- this.logWarn(action.context, error.message, () => ({ url: action.url }));
48
+ if ((0, ActorDereferenceBase_1.shouldLogWarning)(error)) {
49
+ this.logWarn(action.context, error.message, () => ({ url: action.url }));
50
+ }
49
51
  // Make sure the errored stream is ended.
50
52
  data.push(null);
51
53
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ActorDereferenceParse.js","sourceRoot":"","sources":["ActorDereferenceParse.ts"],"names":[],"mappings":";;;AAGA,yCAA8C;AAE9C,qDAA8C;AAE9C,iEAA0F;AAE1F;;;;;;;GAOG;AACH,SAAgB,yBAAyB,CAAC,IAAY,EAAE,aAAsC;IAC5F,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAA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,sDA4EC","sourcesContent":["import type { MediateMediaTyped, MediateMediaTypes } from '@comunica/actor-abstract-mediatyped';\nimport type { IActionParse, IActorParseOutput, IParseMetadata } from '@comunica/actor-abstract-parse';\nimport type { IActorArgs, IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { Readable } from 'readable-stream';\nimport { PassThrough } from 'readable-stream';\nimport type { IActionDereference, IActorDereferenceOutput, MediatorDereference } from './ActorDereference';\nimport { ActorDereferenceBase, isHardError, emptyReadable } 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<TestResult<IActorTest>> {\n return passTestVoid();\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\n if (dereference.exists) {\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 || action.mediaType ||\n getMediaTypeFromExtension(dereference.url, this.mediaMappings),\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 } else {\n // Close the dereference stream and return an empty response directly to avoid unnecessary processing.\n // This code is equivalent to the error handler above in the catch clause, but avoids redundant processing.\n await dereference.data.close?.();\n result = { data: emptyReadable() };\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"]}
1
+ {"version":3,"file":"ActorDereferenceParse.js","sourceRoot":"","sources":["ActorDereferenceParse.ts"],"names":[],"mappings":";;;AAGA,yCAA8C;AAE9C,qDAA8C;AAE9C,iEAA4G;AAE5G;;;;;;;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,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACO,6BAA6B,CACrC,MAAkC,EAClC,IAAO;QAEP,oGAAoG;QACpG,IAAI,CAAC,IAAA,kCAAW,EAAC,MAAM,CAAC,OAAO,CAAC,E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AC,SAAS,IAAI,MAAM,CAAC,SAAS;wBACxD,yBAAyB,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC;iBACjE,CAAC,CAAC,CAAC,MAAM,CAAC;gBACX,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,6BAA6B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YACxE,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,2CAA2C;gBAC3C,MAAM,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;gBACjC,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,sGAAsG;YACtG,2GAA2G;YAC3G,MAAM,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACjC,MAAM,GAAG,EAAE,IAAI,EAAE,IAAA,oCAAa,GAAE,EAAE,CAAC;QACrC,CAAC;QAED,4CAA4C;QAC5C,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,MAAM,EAAE,CAAC;IACvC,CAAC;CACF;AA9ED,sDA8EC","sourcesContent":["import type { MediateMediaTyped, MediateMediaTypes } from '@comunica/actor-abstract-mediatyped';\nimport type { IActionParse, IActorParseOutput, IParseMetadata } from '@comunica/actor-abstract-parse';\nimport type { IActorArgs, IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { Readable } from 'readable-stream';\nimport { PassThrough } from 'readable-stream';\nimport type { IActionDereference, IActorDereferenceOutput, MediatorDereference } from './ActorDereference';\nimport { ActorDereferenceBase, isHardError, emptyReadable, shouldLogWarning } 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<TestResult<IActorTest>> {\n return passTestVoid();\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 if (shouldLogWarning(error)) {\n this.logWarn(action.context, error.message, () => ({ url: action.url }));\n }\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\n if (dereference.exists) {\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 || action.mediaType ||\n getMediaTypeFromExtension(dereference.url, this.mediaMappings),\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 } else {\n // Close the dereference stream and return an empty response directly to avoid unnecessary processing.\n // This code is equivalent to the error handler above in the catch clause, but avoids redundant processing.\n await dereference.data.close?.();\n result = { data: emptyReadable() };\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/lib/index.d.ts CHANGED
File without changes
package/lib/index.js CHANGED
File without changes
package/lib/index.js.map CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/bus-dereference",
3
- "version": "4.4.1",
3
+ "version": "4.4.2-alpha.49.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",
@@ -40,12 +40,12 @@
40
40
  "build:components": "componentsjs-generator"
41
41
  },
42
42
  "dependencies": {
43
- "@comunica/actor-abstract-mediatyped": "^4.4.0",
44
- "@comunica/actor-abstract-parse": "^4.4.0",
45
- "@comunica/context-entries": "^4.4.1",
46
- "@comunica/core": "^4.4.0",
47
- "@comunica/types": "^4.4.0",
43
+ "@comunica/actor-abstract-mediatyped": "4.4.2-alpha.49.0",
44
+ "@comunica/actor-abstract-parse": "4.4.2-alpha.49.0",
45
+ "@comunica/context-entries": "4.4.2-alpha.49.0",
46
+ "@comunica/core": "4.4.2-alpha.49.0",
47
+ "@comunica/types": "4.4.2-alpha.49.0",
48
48
  "readable-stream": "^4.5.2"
49
49
  },
50
- "gitHead": "c5cc36caf88da31173a0969a7da88cadb7f469ac"
50
+ "gitHead": "ef6f96cfd8faf7c37955bb7e0fe9f6fc6a994bdf"
51
51
  }