@comunica/actor-query-result-serialize-table 3.3.0 → 4.0.1-alpha.48.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.
- package/README.md +1 -1
- package/components/ActorQueryResultSerializeTable.jsonld +44 -12
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +7 -1
- package/lib/ActorQueryResultSerializeTable.d.ts +2 -1
- package/lib/ActorQueryResultSerializeTable.js +7 -7
- package/lib/ActorQueryResultSerializeTable.js.map +1 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
22
22
|
{
|
|
23
23
|
"@context": [
|
|
24
24
|
...
|
|
25
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^
|
|
25
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^4.0.0/components/context.jsonld"
|
|
26
26
|
],
|
|
27
27
|
"actors": [
|
|
28
28
|
...
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-result-serialize/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^4.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^4.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-result-serialize/^4.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/actor-query-result-serialize-table",
|
|
8
8
|
"components": [
|
|
@@ -77,29 +77,37 @@
|
|
|
77
77
|
"genericTypeInstances": [
|
|
78
78
|
{
|
|
79
79
|
"@type": "ParameterRangeGenericTypeReference",
|
|
80
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
80
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
"@type": "ParameterRangeGenericTypeReference",
|
|
84
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
84
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"@type": "ParameterRangeGenericTypeReference",
|
|
88
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
88
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
92
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
89
93
|
}
|
|
90
94
|
]
|
|
91
95
|
},
|
|
92
96
|
{
|
|
93
97
|
"@type": "ParameterRangeGenericTypeReference",
|
|
94
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
98
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
102
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
95
103
|
},
|
|
96
104
|
{
|
|
97
105
|
"@type": "ParameterRangeGenericTypeReference",
|
|
98
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
106
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
99
107
|
},
|
|
100
108
|
{
|
|
101
109
|
"@type": "ParameterRangeGenericTypeReference",
|
|
102
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
110
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
103
111
|
}
|
|
104
112
|
]
|
|
105
113
|
},
|
|
@@ -109,6 +117,20 @@
|
|
|
109
117
|
},
|
|
110
118
|
"comment": "The bus this actor subscribes to."
|
|
111
119
|
},
|
|
120
|
+
{
|
|
121
|
+
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_busFailMessage",
|
|
122
|
+
"range": {
|
|
123
|
+
"@type": "ParameterRangeUnion",
|
|
124
|
+
"parameterRangeElements": [
|
|
125
|
+
"xsd:string",
|
|
126
|
+
{
|
|
127
|
+
"@type": "ParameterRangeUndefined"
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"default": "Query result serialization failed: none of the configured actors were able to serialize for type ${action.handle.type}",
|
|
132
|
+
"comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
|
|
133
|
+
},
|
|
112
134
|
{
|
|
113
135
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_beforeActors",
|
|
114
136
|
"range": {
|
|
@@ -122,15 +144,19 @@
|
|
|
122
144
|
"genericTypeInstances": [
|
|
123
145
|
{
|
|
124
146
|
"@type": "ParameterRangeGenericTypeReference",
|
|
125
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
147
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
126
148
|
},
|
|
127
149
|
{
|
|
128
150
|
"@type": "ParameterRangeGenericTypeReference",
|
|
129
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
151
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
130
152
|
},
|
|
131
153
|
{
|
|
132
154
|
"@type": "ParameterRangeGenericTypeReference",
|
|
133
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
155
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
159
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
134
160
|
}
|
|
135
161
|
]
|
|
136
162
|
}
|
|
@@ -227,6 +253,12 @@
|
|
|
227
253
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_bus"
|
|
228
254
|
}
|
|
229
255
|
},
|
|
256
|
+
{
|
|
257
|
+
"keyRaw": "busFailMessage",
|
|
258
|
+
"value": {
|
|
259
|
+
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_busFailMessage"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
230
262
|
{
|
|
231
263
|
"keyRaw": "beforeActors",
|
|
232
264
|
"value": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-query-result-serialize-table/^4.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-query-result-serialize-table",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
|
|
4
4
|
{
|
|
5
5
|
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
-
"caqrst": "npmd:@comunica/actor-query-result-serialize-table/^
|
|
6
|
+
"caqrst": "npmd:@comunica/actor-query-result-serialize-table/^4.0.0/",
|
|
7
7
|
"ActorQueryResultSerializeTable": {
|
|
8
8
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable",
|
|
9
9
|
"@prefix": true,
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"args_bus": {
|
|
29
29
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_bus"
|
|
30
30
|
},
|
|
31
|
+
"args_busFailMessage": {
|
|
32
|
+
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_busFailMessage"
|
|
33
|
+
},
|
|
31
34
|
"args_beforeActors": {
|
|
32
35
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_beforeActors",
|
|
33
36
|
"@container": "@list"
|
|
@@ -52,6 +55,9 @@
|
|
|
52
55
|
"bus": {
|
|
53
56
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_bus"
|
|
54
57
|
},
|
|
58
|
+
"busFailMessage": {
|
|
59
|
+
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_busFailMessage"
|
|
60
|
+
},
|
|
55
61
|
"beforeActors": {
|
|
56
62
|
"@id": "caqrst:components/ActorQueryResultSerializeTable.jsonld#ActorQueryResultSerializeTable_args_beforeActors",
|
|
57
63
|
"@container": "@list"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IActionSparqlSerialize, IActorQueryResultSerializeFixedMediaTypesArgs, IActorQueryResultSerializeOutput } from '@comunica/bus-query-result-serialize';
|
|
2
2
|
import { ActorQueryResultSerializeFixedMediaTypes } from '@comunica/bus-query-result-serialize';
|
|
3
|
+
import type { TestResult } from '@comunica/core';
|
|
3
4
|
import type { Bindings, IActionContext } from '@comunica/types';
|
|
4
5
|
import type * as RDF from '@rdfjs/types';
|
|
5
6
|
import { Readable } from 'readable-stream';
|
|
@@ -16,7 +17,7 @@ export declare class ActorQueryResultSerializeTable extends ActorQueryResultSeri
|
|
|
16
17
|
*/
|
|
17
18
|
constructor(args: IActorQueryResultSerializeTableArgs);
|
|
18
19
|
static repeat(str: string, count: number): string;
|
|
19
|
-
testHandleChecked(action: IActionSparqlSerialize, _context: IActionContext): Promise<boolean
|
|
20
|
+
testHandleChecked(action: IActionSparqlSerialize, _context: IActionContext): Promise<TestResult<boolean>>;
|
|
20
21
|
termToString(term: RDF.Term): string;
|
|
21
22
|
pad(str: string): string;
|
|
22
23
|
pushHeader(data: Readable, labels: RDF.Variable[]): void;
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActorQueryResultSerializeTable = void 0;
|
|
4
4
|
const bus_query_result_serialize_1 = require("@comunica/bus-query-result-serialize");
|
|
5
|
-
const
|
|
5
|
+
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
+
const core_1 = require("@comunica/core");
|
|
6
7
|
const rdf_string_1 = require("rdf-string");
|
|
7
8
|
const rdf_terms_1 = require("rdf-terms");
|
|
8
9
|
const readable_stream_1 = require("readable-stream");
|
|
9
|
-
const DF = new rdf_data_factory_1.DataFactory();
|
|
10
|
-
const QUAD_TERM_NAMES_VARS = rdf_terms_1.QUAD_TERM_NAMES.map(name => DF.variable(name));
|
|
11
10
|
/**
|
|
12
11
|
* A comunica Table Sparql Serialize Actor.
|
|
13
12
|
*/
|
|
@@ -26,9 +25,9 @@ class ActorQueryResultSerializeTable extends bus_query_result_serialize_1.ActorQ
|
|
|
26
25
|
}
|
|
27
26
|
async testHandleChecked(action, _context) {
|
|
28
27
|
if (!['bindings', 'quads'].includes(action.type)) {
|
|
29
|
-
|
|
28
|
+
return (0, core_1.failTest)('This actor can only handle bindings or quad streams.');
|
|
30
29
|
}
|
|
31
|
-
return
|
|
30
|
+
return (0, core_1.passTestVoid)();
|
|
32
31
|
}
|
|
33
32
|
termToString(term) {
|
|
34
33
|
return term.termType === 'Quad' ? (0, rdf_string_1.termToString)(term) : term.value;
|
|
@@ -54,12 +53,13 @@ class ActorQueryResultSerializeTable extends bus_query_result_serialize_1.ActorQ
|
|
|
54
53
|
let resultStream;
|
|
55
54
|
if (action.type === 'bindings') {
|
|
56
55
|
resultStream = action.bindingsStream.map(bindings => this.createRow(labels, bindings));
|
|
57
|
-
const labels = (await action.metadata()).variables;
|
|
56
|
+
const labels = (await action.metadata()).variables.map(v => v.variable);
|
|
58
57
|
this.pushHeader(data, labels);
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
resultStream = action.quadStream.map(quad => `${(0, rdf_terms_1.getTerms)(quad).map(term => this.pad(this.termToString(term))).join(' ')}\n`);
|
|
62
|
-
|
|
61
|
+
const dataFactory = action.context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
62
|
+
this.pushHeader(data, rdf_terms_1.QUAD_TERM_NAMES.map(name => dataFactory.variable(name)));
|
|
63
63
|
}
|
|
64
64
|
data.wrap(resultStream);
|
|
65
65
|
return { data };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryResultSerializeTable.js","sourceRoot":"","sources":["ActorQueryResultSerializeTable.ts"],"names":[],"mappings":";;;AAKA,qFAAgG;
|
|
1
|
+
{"version":3,"file":"ActorQueryResultSerializeTable.js","sourceRoot":"","sources":["ActorQueryResultSerializeTable.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n IActionSparqlSerialize,\n IActorQueryResultSerializeFixedMediaTypesArgs,\n IActorQueryResultSerializeOutput,\n} from '@comunica/bus-query-result-serialize';\nimport { ActorQueryResultSerializeFixedMediaTypes } from '@comunica/bus-query-result-serialize';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { failTest, passTestVoid } from '@comunica/core';\nimport type {\n Bindings,\n ComunicaDataFactory,\n IActionContext,\n IQueryOperationResultBindings,\n IQueryOperationResultQuads,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { termToString } from 'rdf-string';\nimport { getTerms, QUAD_TERM_NAMES } from 'rdf-terms';\nimport { Readable } from 'readable-stream';\n\n/**\n * A comunica Table Sparql Serialize Actor.\n */\nexport class ActorQueryResultSerializeTable extends ActorQueryResultSerializeFixedMediaTypes\n implements IActorQueryResultSerializeTableArgs {\n public readonly columnWidth: number;\n public readonly padding: string;\n\n /**\n * @param args -\n * \\ @defaultNested {{ \"table\": 0.6 }} mediaTypePriorities\n * \\ @defaultNested {{ \"table\": \"https://comunica.linkeddatafragments.org/#results_table\" }} mediaTypeFormats\n */\n public constructor(args: IActorQueryResultSerializeTableArgs) {\n super(args);\n this.padding = ActorQueryResultSerializeTable.repeat(' ', this.columnWidth);\n }\n\n public static repeat(str: string, count: number): string {\n return str.repeat(count);\n }\n\n public override async testHandleChecked(\n action: IActionSparqlSerialize,\n _context: IActionContext,\n ): Promise<TestResult<boolean>> {\n if (![ 'bindings', 'quads' ].includes(action.type)) {\n return failTest('This actor can only handle bindings or quad streams.');\n }\n return passTestVoid();\n }\n\n public termToString(term: RDF.Term): string {\n return term.termType === 'Quad' ? termToString(term) : term.value;\n }\n\n public pad(str: string): string {\n if (str.length <= this.columnWidth) {\n return str + this.padding.slice(str.length);\n }\n return `${str.slice(0, this.columnWidth - 1)}…`;\n }\n\n public pushHeader(data: Readable, labels: RDF.Variable[]): void {\n const header: string = labels.map(label => this.pad(label.value)).join(' ');\n data.push(`${header}\\n${ActorQueryResultSerializeTable.repeat('-', header.length)}\\n`);\n }\n\n public createRow(labels: RDF.Variable[], bindings: Bindings): string {\n return `${labels\n .map(label => bindings.has(label) ? this.termToString(bindings.get(label)!) : '')\n .map(label => this.pad(label))\n .join(' ')}\\n`;\n }\n\n public async runHandle(action: IActionSparqlSerialize, _mediaType: string, _context: IActionContext):\n Promise<IActorQueryResultSerializeOutput> {\n const data = new Readable();\n\n let resultStream: NodeJS.EventEmitter;\n if (action.type === 'bindings') {\n resultStream = (<IQueryOperationResultBindings>action).bindingsStream.map(\n bindings => this.createRow(labels, bindings),\n );\n const labels = (await (<IQueryOperationResultBindings>action).metadata()).variables.map(v => v.variable);\n this.pushHeader(data, labels);\n } else {\n resultStream = (<IQueryOperationResultQuads>action).quadStream.map(quad => `${getTerms(quad).map(term => this.pad(this.termToString(term))).join(' ')}\\n`);\n const dataFactory: ComunicaDataFactory = action.context.getSafe(KeysInitQuery.dataFactory);\n this.pushHeader(data, QUAD_TERM_NAMES.map(name => dataFactory.variable(name)));\n }\n data.wrap(<any> resultStream);\n\n return { data };\n }\n}\n\nexport interface IActorQueryResultSerializeTableArgs extends IActorQueryResultSerializeFixedMediaTypesArgs {\n /**\n * The table column width in number of characters\n * @range {integer}\n * @default {50}\n */\n columnWidth: number;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-result-serialize-table",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1-alpha.48.0",
|
|
4
4
|
"description": "A table query-result-serialize actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"funding": {
|
|
8
|
+
"type": "opencollective",
|
|
9
|
+
"url": "https://opencollective.com/comunica-association"
|
|
10
|
+
},
|
|
7
11
|
"homepage": "https://comunica.dev/",
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
@@ -37,13 +41,14 @@
|
|
|
37
41
|
"build:components": "componentsjs-generator"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@comunica/bus-query-result-serialize": "
|
|
41
|
-
"@comunica/
|
|
44
|
+
"@comunica/bus-query-result-serialize": "4.0.1-alpha.48.0",
|
|
45
|
+
"@comunica/context-entries": "4.0.1-alpha.48.0",
|
|
46
|
+
"@comunica/core": "4.0.1-alpha.48.0",
|
|
47
|
+
"@comunica/types": "4.0.1-alpha.48.0",
|
|
42
48
|
"@rdfjs/types": "*",
|
|
43
|
-
"rdf-data-factory": "^1.1.1",
|
|
44
49
|
"rdf-string": "^1.6.3",
|
|
45
50
|
"rdf-terms": "^1.11.0",
|
|
46
|
-
"readable-stream": "^4.
|
|
51
|
+
"readable-stream": "^4.5.2"
|
|
47
52
|
},
|
|
48
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "4cc37905eab2c94a2e1d9cee0f51c53604f07da1"
|
|
49
54
|
}
|