@comunica/bus-dereference 4.1.0 → 4.4.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
@@ -37,7 +37,7 @@
37
37
  "genericTypeParameters": [
38
38
  {
39
39
  "@id": "cbd:components/ActorDereferenceBase.jsonld#ActorDereferenceBase__generic_I",
40
- "range": "cc:components/Actor.jsonld#IAction"
40
+ "range": "cbd:components/ActorDereference.jsonld#IActionDereference"
41
41
  },
42
42
  {
43
43
  "@id": "cbd:components/ActorDereferenceBase.jsonld#ActorDereferenceBase__generic_T",
File without changes
File without changes
File without changes
@@ -66,6 +66,10 @@ export interface IActorDereferenceOutput extends IActorOutput {
66
66
  * as this may have changed due to redirects.
67
67
  */
68
68
  url: string;
69
+ /**
70
+ * BaseIRI, this is used over url when passed to metadata.baseIRI in ActorDereferenceRdfParse.ts
71
+ */
72
+ baseIRI?: string;
69
73
  /**
70
74
  * The resulting stream.
71
75
  */
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"ActorDereference.js","sourceRoot":"","sources":["ActorDereference.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAE9D;;;;;;;;;;GAUG;AACH,MAAsB,gBAAiB,SACrC,2CAA6E;IAC7E,4BAA4B;IAC5B;;;;OAIG;IACH,2BAA2B;IAC3B,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;AA9BD,4CA8BC","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 /* eslint-disable max-len */\n /**\n * @param args -\n * \\ @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus\n * \\ @defaultNested {Dereferencing failed: none of the configured actors were able to handle ${action.url}} busFailMessage\n */\n /* eslint-enable max-len */\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"]}
1
+ {"version":3,"file":"ActorDereference.js","sourceRoot":"","sources":["ActorDereference.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAE9D;;;;;;;;;;GAUG;AACH,MAAsB,gBAAiB,SACrC,2CAA6E;IAC7E,4BAA4B;IAC5B;;;;OAIG;IACH,2BAA2B;IAC3B,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;AA9BD,4CA8BC","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 /* eslint-disable max-len */\n /**\n * @param args -\n * \\ @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus\n * \\ @defaultNested {Dereferencing failed: none of the configured actors were able to handle ${action.url}} busFailMessage\n */\n /* eslint-enable max-len */\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 * BaseIRI, this is used over url when passed to metadata.baseIRI in ActorDereferenceRdfParse.ts\n */\n baseIRI?: 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"]}
@@ -1,8 +1,8 @@
1
- import type { IAction, IActorArgs, IActorTest } from '@comunica/core';
1
+ import type { IActorArgs, IActorTest } from '@comunica/core';
2
2
  import { Actor } from '@comunica/core';
3
3
  import type { IActionContext } from '@comunica/types';
4
4
  import { Readable } from 'readable-stream';
5
- import type { IActorDereferenceOutput } from '.';
5
+ import type { IActorDereferenceOutput, IActionDereference } from './ActorDereference';
6
6
  export declare function emptyReadable<S extends Readable>(): S;
7
7
  /**
8
8
  * Check if hard errors should occur on HTTP or parse errors.
@@ -21,7 +21,7 @@ export declare function isHardError(context: IActionContext): boolean;
21
21
  * @see IActionDereference
22
22
  * @see IActorDereferenceOutput
23
23
  */
24
- export declare abstract class ActorDereferenceBase<I extends IAction, T extends IActorTest, O extends IActorDereferenceOutput, TS = undefined> extends Actor<I, T, O, TS> {
24
+ export declare abstract class ActorDereferenceBase<I extends IActionDereference, T extends IActorTest, O extends IActorDereferenceOutput, TS = undefined> extends Actor<I, T, O, TS> {
25
25
  constructor(args: IActorArgs<I, T, O, TS>);
26
26
  /**
27
27
  * Handle the given error as a rejection or delegate it to the logger,
@@ -45,7 +45,7 @@ class ActorDereferenceBase extends core_1.Actor {
45
45
  if (isHardError(action.context)) {
46
46
  throw error;
47
47
  }
48
- this.logWarn(action.context, error.message);
48
+ this.logWarn(action.context, error.message, () => ({ url: action.url }));
49
49
  return { ...output, data: emptyReadable() };
50
50
  }
51
51
  }
@@ -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,CAAC,CAAC;QACtD,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 { 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 {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 IAction,\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);\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;;;;;;;;;;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"]}
File without changes
@@ -60,21 +60,28 @@ class ActorDereferenceParse extends ActorDereferenceBase_1.ActorDereferenceBase
60
60
  mediaTypes: async () => (await this.mediatorParseMediatypes?.mediate({ context, mediaTypes: true }))?.mediaTypes,
61
61
  });
62
62
  let result;
63
- try {
64
- result = (await this.mediatorParse.mediate({
65
- context,
66
- handle: { context, ...dereference, metadata: await this.getMetadata(dereference) },
67
- // eslint-disable-next-line ts/prefer-nullish-coalescing
68
- handleMediaType: (dereference.mediaType ||
69
- getMediaTypeFromExtension(dereference.url, this.mediaMappings)) ||
70
- action.mediaType,
71
- })).handle;
72
- result.data = this.handleDereferenceStreamErrors(action, result.data);
63
+ if (dereference.exists) {
64
+ try {
65
+ result = (await this.mediatorParse.mediate({
66
+ context,
67
+ handle: { context, ...dereference, metadata: await this.getMetadata(dereference) },
68
+ // eslint-disable-next-line ts/prefer-nullish-coalescing
69
+ handleMediaType: dereference.mediaType || action.mediaType ||
70
+ getMediaTypeFromExtension(dereference.url, this.mediaMappings),
71
+ })).handle;
72
+ result.data = this.handleDereferenceStreamErrors(action, result.data);
73
+ }
74
+ catch (error) {
75
+ // Close the body, to avoid process to hang
76
+ await dereference.data.close?.();
77
+ result = await this.dereferenceErrorHandler(action, error, {});
78
+ }
73
79
  }
74
- catch (error) {
75
- // Close the body, to avoid process to hang
80
+ else {
81
+ // Close the dereference stream and return an empty response directly to avoid unnecessary processing.
82
+ // This code is equivalent to the error handler above in the catch clause, but avoids redundant processing.
76
83
  await dereference.data.close?.();
77
- result = await this.dereferenceErrorHandler(action, error, {});
84
+ result = { data: (0, ActorDereferenceBase_1.emptyReadable)() };
78
85
  }
79
86
  // Return the parsed stream and any metadata
80
87
  return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,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, 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 } 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 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"]}
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,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,EAAE,CAAC;YACjC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACzB,IA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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;AA5ED,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"]}
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.1.0",
3
+ "version": "4.4.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.1.0",
44
- "@comunica/actor-abstract-parse": "^4.1.0",
45
- "@comunica/context-entries": "^4.1.0",
46
- "@comunica/core": "^4.1.0",
47
- "@comunica/types": "^4.1.0",
43
+ "@comunica/actor-abstract-mediatyped": "^4.4.0",
44
+ "@comunica/actor-abstract-parse": "^4.4.0",
45
+ "@comunica/context-entries": "^4.4.0",
46
+ "@comunica/core": "^4.4.0",
47
+ "@comunica/types": "^4.4.0",
48
48
  "readable-stream": "^4.5.2"
49
49
  },
50
- "gitHead": "711446473d18f5fd47aa1a67e6c23582234221ec"
50
+ "gitHead": "27acde56dfe0c1ff1162c1f46818ad752296ca88"
51
51
  }