@rdfc/sparql-ingest-processor-ts 2.1.5 → 2.1.6

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.
@@ -1,4 +1,5 @@
1
1
  import { Processor } from "@rdfc/js-runner";
2
+ import { Agent } from "undici";
2
3
  import { RdfStore } from "rdf-stores";
3
4
  import { Logger } from "winston";
4
5
  import type { Quad, Term } from "@rdfjs/types";
@@ -46,6 +47,7 @@ type SPARQLIngestArgs = {
46
47
  sparqlWriter?: Writer;
47
48
  };
48
49
  export declare class SPARQLIngest extends Processor<SPARQLIngestArgs> {
50
+ protected globalDispatcher: Agent;
49
51
  protected transactionMembers: TransactionMember[];
50
52
  protected memberBatch: Quad[];
51
53
  protected requestsPerformance: number[];
@@ -1,5 +1,6 @@
1
1
  import { Processor, extendLogger } from "@rdfc/js-runner";
2
2
  import { SDS } from "@treecg/types";
3
+ import { Agent } from "undici";
3
4
  import { DataFactory } from "rdf-data-factory";
4
5
  import { RdfStore } from "rdf-stores";
5
6
  import { Parser } from "n3";
@@ -13,6 +14,7 @@ export var OperationMode;
13
14
  OperationMode["SYNC"] = "Sync";
14
15
  })(OperationMode || (OperationMode = {}));
15
16
  export class SPARQLIngest extends Processor {
17
+ globalDispatcher;
16
18
  transactionMembers = [];
17
19
  memberBatch = [];
18
20
  requestsPerformance = [];
@@ -22,6 +24,10 @@ export class SPARQLIngest extends Processor {
22
24
  async init() {
23
25
  this.createTransactionQueriesLogger = extendLogger(this.logger, "createTransactionQueries");
24
26
  this.doSPARQLRequestLogger = extendLogger(this.logger, "doSPARQLRequest");
27
+ this.globalDispatcher = new Agent({
28
+ headersTimeout: (this.config.measurePerformance?.queryTimeout || 600) * 1000,
29
+ bodyTimeout: (this.config.measurePerformance?.queryTimeout || 600) * 1000,
30
+ });
25
31
  if (!this.config.operationMode) {
26
32
  this.config.operationMode = OperationMode.SYNC;
27
33
  }
@@ -159,7 +165,7 @@ export class SPARQLIngest extends Processor {
159
165
  if (this.config.graphStoreUrl) {
160
166
  try {
161
167
  const t0 = Date.now();
162
- await doSPARQLRequest(query, this.config, this.logger);
168
+ await doSPARQLRequest(query, this.config, this.globalDispatcher, this.logger);
163
169
  const reqTime = Date.now() - t0;
164
170
  if (this.config.measurePerformance) {
165
171
  this.requestsPerformance.push(reqTime);
@@ -193,7 +199,7 @@ export class SPARQLIngest extends Processor {
193
199
  if (this.config.operationMode === OperationMode.REPLICATION) {
194
200
  try {
195
201
  const t0 = Date.now();
196
- await doSPARQLRequest(this.memberBatch, this.config, this.logger);
202
+ await doSPARQLRequest(this.memberBatch, this.config, this.globalDispatcher, this.logger);
197
203
  const reqTime = Date.now() - t0;
198
204
  if (this.config.measurePerformance) {
199
205
  this.requestsPerformance.push(reqTime);
@@ -222,7 +228,7 @@ export class SPARQLIngest extends Processor {
222
228
  if (this.config.operationMode === OperationMode.REPLICATION && this.memberBatch.length > 0) {
223
229
  try {
224
230
  const t0 = Date.now();
225
- await doSPARQLRequest(this.memberBatch, this.config, this.logger);
231
+ await doSPARQLRequest(this.memberBatch, this.config, this.globalDispatcher, this.logger);
226
232
  const reqTime = Date.now() - t0;
227
233
  if (this.config.measurePerformance) {
228
234
  this.requestsPerformance.push(reqTime);
@@ -250,6 +256,7 @@ export class SPARQLIngest extends Processor {
250
256
  if (this.config.measurePerformance) {
251
257
  await writeFile(`${this.config.measurePerformance.outputPath}/${this.config.measurePerformance.name}.json`, JSON.stringify(this.requestsPerformance), "utf-8");
252
258
  }
259
+ await this.globalDispatcher.close();
253
260
  }
254
261
  async produce() {
255
262
  }
package/lib/Utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RdfStore } from "rdf-stores";
2
+ import { Agent } from "undici";
2
3
  import { Logger } from "winston";
3
4
  import type { Term, Quad_Subject, Quad_Object, Quad, Quad_Graph } from "@rdfjs/types";
4
5
  import type { IngestConfig } from "./SPARQLIngest.js";
@@ -10,4 +11,4 @@ export declare function splitStorePerNamedGraph(store: RdfStore): {
10
11
  }[];
11
12
  export declare function splitStoreOnSize(store: RdfStore, threshold: number): RdfStore[];
12
13
  export declare function sanitizeQuads(store: RdfStore): void;
13
- export declare function doSPARQLRequest(query: string[] | Quad[], config: IngestConfig, logger: Logger): Promise<void>;
14
+ export declare function doSPARQLRequest(query: string[] | Quad[], config: IngestConfig, dispatcher: Agent, logger: Logger): Promise<void>;
package/lib/Utils.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { XSD } from "@treecg/types";
2
2
  import { DataFactory } from "rdf-data-factory";
3
3
  import { RdfStore } from "rdf-stores";
4
- import { Agent } from "undici";
5
4
  import { Writer as N3Writer } from "n3";
6
5
  const df = new DataFactory();
7
6
  export function getSubjects(store, predicate, object, graph) {
@@ -76,7 +75,7 @@ export function sanitizeQuads(store) {
76
75
  }
77
76
  }
78
77
  }
79
- export async function doSPARQLRequest(query, config, logger) {
78
+ export async function doSPARQLRequest(query, config, dispatcher, logger) {
80
79
  try {
81
80
  const timeout = config.measurePerformance?.queryTimeout || 1800;
82
81
  if (query.length > 0 && typeof query[0] !== 'string') {
@@ -99,10 +98,7 @@ export async function doSPARQLRequest(query, config, logger) {
99
98
  'Content-Type': hasQuads ? 'application/n-quads' : 'application/n-triples',
100
99
  },
101
100
  body: serialized,
102
- dispatcher: new Agent({
103
- headersTimeout: timeout * 1000,
104
- bodyTimeout: timeout * 1000,
105
- }),
101
+ dispatcher,
106
102
  });
107
103
  if (!res.ok) {
108
104
  throw new Error(`HTTP request failed with code ${res.status} and message: \n${await res.text()}`);
@@ -125,10 +121,7 @@ export async function doSPARQLRequest(query, config, logger) {
125
121
  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
126
122
  },
127
123
  body: `update=${fixedEncodeURIComponent(q)}${config.accessToken ? `&access-token=${config.accessToken}` : ''}`,
128
- dispatcher: new Agent({
129
- headersTimeout: timeout * 1000,
130
- bodyTimeout: timeout * 1000,
131
- }),
124
+ dispatcher,
132
125
  });
133
126
  if (!res.ok) {
134
127
  throw new Error(`HTTP request failed with code ${res.status} and message: \n${await res.text()}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdfc/sparql-ingest-processor-ts",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "SPARQL Update function to be within RDF-Connect pipelines",
5
5
  "author": "Julián Rojas",
6
6
  "contributors": [
@@ -31,7 +31,7 @@
31
31
  "n3": "^1.26.0",
32
32
  "rdf-data-factory": "^2.0.2",
33
33
  "rdf-stores": "^2.1.1",
34
- "undici": "^7.21.0",
34
+ "undici": "^7.22.0",
35
35
  "winston": "^3.19.0"
36
36
  },
37
37
  "devDependencies": {
@@ -39,18 +39,18 @@
39
39
  "@rdfc/js-runner": "^3.0.2",
40
40
  "@rdfjs/types": "^2.0.1",
41
41
  "@types/n3": "^1.26.1",
42
- "@types/node": "^25.2.2",
43
- "@typescript-eslint/eslint-plugin": "^8.55.0",
44
- "@typescript-eslint/parser": "^8.55.0",
42
+ "@types/node": "^25.3.0",
43
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
44
+ "@typescript-eslint/parser": "^8.56.1",
45
45
  "@vitest/coverage-v8": "^4.0.18",
46
- "eslint": "^9.39.2",
46
+ "eslint": "^9.39.3",
47
47
  "eslint-config-prettier": "^10.1.8",
48
48
  "fastify": "^5.7.4",
49
49
  "husky": "^9.1.7",
50
50
  "ts-patch": "^3.3.0",
51
51
  "tsc-alias": "^1.8.16",
52
52
  "typescript": "^5.9.3",
53
- "vite-tsconfig-paths": "^6.1.0",
53
+ "vite-tsconfig-paths": "^6.1.1",
54
54
  "vitest": "^4.0.18"
55
55
  }
56
- }
56
+ }