jinaga-server 3.5.1 → 3.5.3
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/dist/authorization/authorization-keystore.js +2 -2
- package/dist/authorization/authorization-keystore.js.map +1 -1
- package/dist/http/csv-metadata.d.ts +24 -0
- package/dist/http/csv-metadata.js +3 -0
- package/dist/http/csv-metadata.js.map +1 -0
- package/dist/http/csv-validator.d.ts +23 -0
- package/dist/http/csv-validator.js +83 -0
- package/dist/http/csv-validator.js.map +1 -0
- package/dist/http/output-formatters.d.ts +28 -0
- package/dist/http/output-formatters.js +197 -0
- package/dist/http/output-formatters.js.map +1 -0
- package/dist/http/result-stream.d.ts +35 -0
- package/dist/http/result-stream.js +78 -0
- package/dist/http/result-stream.js.map +1 -0
- package/dist/http/router.d.ts +7 -1
- package/dist/http/router.js +276 -70
- package/dist/http/router.js.map +1 -1
- package/dist/http/stream.d.ts +3 -0
- package/dist/http/stream.js +79 -5
- package/dist/http/stream.js.map +1 -1
- package/dist/postgres/postgres-store.js +7 -5
- package/dist/postgres/postgres-store.js.map +1 -1
- package/dist/postgres/purge-sql.js +15 -2
- package/dist/postgres/purge-sql.js.map +1 -1
- package/dist/postgres/specification-result-sql.d.ts +2 -0
- package/dist/postgres/specification-result-sql.js +49 -5
- package/dist/postgres/specification-result-sql.js.map +1 -1
- package/dist/postgres/specification-sql.js +28 -6
- package/dist/postgres/specification-sql.js.map +1 -1
- package/docs/analysis/DIAGNOSTIC_LOGGING_README.md +201 -0
- package/docs/analysis/security-audit-feeds-hash-handler.md +407 -0
- package/docs/design/feeds-persistent-proxy-plan.md +294 -0
- package/integration-test/integration-test/jinaga-test/package-lock.json +6 -0
- package/integration-test/jinaga-test/Dockerfile +1 -6
- package/integration-test/jinaga-test/http-test-helpers.js +77 -0
- package/integration-test/jinaga-test/jinaga.test.js +9 -9
- package/integration-test/jinaga-test/package-lock.json +329 -32
- package/integration-test/jinaga-test/package.json +5 -1
- package/integration-test/jinaga-test/read-csv.test.js +330 -0
- package/integration-test/jinaga-test/read-endpoint.test.js +442 -0
- package/integration-test/jinaga-test/read-performance.test.js +221 -0
- package/integration-test/jinaga-test/read-streaming.test.js +199 -0
- package/integration-test/jinaga-test/specification-conditions.test.js +147 -0
- package/integration-test/jinaga-test/test-helpers.js +12 -0
- package/integration-test/jinaga-test/time-projection.test.js +235 -0
- package/package.json +3 -2
- package/src/authorization/authorization-keystore.ts +4 -4
- package/src/http/csv-metadata.ts +34 -0
- package/src/http/csv-validator.ts +90 -0
- package/src/http/output-formatters.ts +196 -0
- package/src/http/result-stream.ts +69 -0
- package/src/http/router.ts +344 -62
- package/src/http/stream.ts +97 -5
- package/src/postgres/postgres-store.ts +13 -6
- package/src/postgres/purge-sql.ts +18 -2
- package/src/postgres/specification-result-sql.ts +70 -8
- package/src/postgres/specification-sql.ts +36 -8
- package/test/http/csv-validatorSpec.ts +205 -0
- package/test/http/result-streamSpec.ts +151 -0
- package/test/postgres/postgresReadSpec.ts +192 -14
- package/test/postgres/postgresSpecificationSpec.ts +3 -3
- package/test/postgres/specificationConditionsSpec.ts +268 -0
- package/test-concurrent-streams.js +219 -0
- package/documentation/streaming-feeds-full-results-solution.md +0 -230
|
@@ -42,7 +42,7 @@ class AuthorizationKeystore {
|
|
|
42
42
|
const userReference = userIdentity
|
|
43
43
|
? yield this.keystore.getUserFact(userIdentity)
|
|
44
44
|
: null;
|
|
45
|
-
const namedStart = specification.given.reduce((map,
|
|
45
|
+
const namedStart = specification.given.reduce((map, g, index) => (Object.assign(Object.assign({}, map), { [g.label.name]: start[index] })), {});
|
|
46
46
|
// Break the specification into feeds and check distribution.
|
|
47
47
|
const feeds = (0, jinaga_1.buildFeeds)(specification);
|
|
48
48
|
const canDistribute = yield this.distributionEngine.canDistributeToAll(feeds, namedStart, userReference);
|
|
@@ -59,7 +59,7 @@ class AuthorizationKeystore {
|
|
|
59
59
|
const userReference = userIdentity
|
|
60
60
|
? yield this.keystore.getUserFact(userIdentity)
|
|
61
61
|
: null;
|
|
62
|
-
const namedStart = specification.given.reduce((map,
|
|
62
|
+
const namedStart = specification.given.reduce((map, g, index) => (Object.assign(Object.assign({}, map), { [g.label.name]: start[index] })), {});
|
|
63
63
|
const canDistribute = yield this.distributionEngine.canDistributeToAll([specification], namedStart, userReference);
|
|
64
64
|
if (canDistribute.type === "failure") {
|
|
65
65
|
throw new jinaga_1.Forbidden(canDistribute.reason);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-keystore.js","sourceRoot":"","sources":["../../src/authorization/authorization-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAiBgB;AAGhB,qEAAgE;AAEhE,MAAa,qBAAqB;IAK9B,YACY,WAAwB,EACxB,KAAc,EACd,QAAkB,EAC1B,kBAA6C,EAC7C,iBAA2C;QAJnC,gBAAW,GAAX,WAAW,CAAa;QACxB,UAAK,GAAL,KAAK,CAAS;QACd,aAAQ,GAAR,QAAQ,CAAU;QALtB,qBAAgB,GAAyB,IAAI,6CAAoB,EAAE,CAAC;QASxE,IAAI,CAAC,mBAAmB,GAAG,kBAAkB;YACzC,IAAI,4BAAmB,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB;YACvC,IAAI,2BAAkB,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IAEK,mBAAmB,CAAC,YAA0B;;YAChD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;YACvE,MAAM,SAAS,GAAG;gBACA;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE,EAAE;iBACjB;aACJ,CAAC;YACF,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACjC,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;IAEK,IAAI,CAAC,YAAiC,EAAE,KAAsB,EAAE,aAA4B;;YAC9F,IAAI,IAAI,CAAC,kBAAkB,EAAE;gBACzB,MAAM,aAAa,GAAyB,YAAY;oBACpD,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC;oBAC/C,CAAC,CAAC,IAAI,CAAC;gBACX,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"authorization-keystore.js","sourceRoot":"","sources":["../../src/authorization/authorization-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAiBgB;AAGhB,qEAAgE;AAEhE,MAAa,qBAAqB;IAK9B,YACY,WAAwB,EACxB,KAAc,EACd,QAAkB,EAC1B,kBAA6C,EAC7C,iBAA2C;QAJnC,gBAAW,GAAX,WAAW,CAAa;QACxB,UAAK,GAAL,KAAK,CAAS;QACd,aAAQ,GAAR,QAAQ,CAAU;QALtB,qBAAgB,GAAyB,IAAI,6CAAoB,EAAE,CAAC;QASxE,IAAI,CAAC,mBAAmB,GAAG,kBAAkB;YACzC,IAAI,4BAAmB,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB;YACvC,IAAI,2BAAkB,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IAEK,mBAAmB,CAAC,YAA0B;;YAChD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;YACvE,MAAM,SAAS,GAAG;gBACA;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE,EAAE;iBACjB;aACJ,CAAC;YACF,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACjC,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;IAEK,IAAI,CAAC,YAAiC,EAAE,KAAsB,E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AW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC9D,OAAO,cAAc,CAAC;aACzB;QACL,CAAC;KAAA;IAEK,kBAAkB,CAAC,YAAiC,EAAE,KAAsB,EAAE,UAA4B;;YAC5G,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;gBAC1B,OAAO;aACV;YAED,MAAM,aAAa,GAAyB,YAAY;gBACpD,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC;gBAC/C,CAAC,CAAC,IAAI,CAAC;YACX,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;YACzG,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE;gBAClC,MAAM,IAAI,kBAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;aAC7C;QACL,CAAC;KAAA;CACJ;AAjJD,sDAiJC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata for CSV export derived from specification
|
|
3
|
+
*/
|
|
4
|
+
export interface CsvMetadata {
|
|
5
|
+
/** Column headers in order (from specification projection labels) */
|
|
6
|
+
headers: string[];
|
|
7
|
+
/** Whether the projection is valid for CSV */
|
|
8
|
+
isValid: boolean;
|
|
9
|
+
/** Validation errors if any */
|
|
10
|
+
errors: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Projection component types
|
|
14
|
+
*/
|
|
15
|
+
export type ProjectionComponentType = 'field' | 'hash' | 'type' | 'array' | 'nested' | 'unknown';
|
|
16
|
+
/**
|
|
17
|
+
* Information about a single projection component
|
|
18
|
+
*/
|
|
19
|
+
export interface ProjectionComponent {
|
|
20
|
+
label: string;
|
|
21
|
+
type: ProjectionComponentType;
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-metadata.js","sourceRoot":"","sources":["../../src/http/csv-metadata.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Specification } from 'jinaga';
|
|
2
|
+
import { CsvMetadata } from './csv-metadata';
|
|
3
|
+
/**
|
|
4
|
+
* Validates a specification for CSV compatibility.
|
|
5
|
+
* Returns metadata including headers and validation results.
|
|
6
|
+
*
|
|
7
|
+
* CSV requires flat projections with single-valued components:
|
|
8
|
+
* - ✅ Fields (scalar values from matched facts)
|
|
9
|
+
* - ✅ Hashes
|
|
10
|
+
* - ✅ Timestamps
|
|
11
|
+
* - ❌ Arrays (nested specifications)
|
|
12
|
+
* - ❌ Nested objects (composite projections)
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateSpecificationForCsv(specification: Specification): CsvMetadata;
|
|
15
|
+
/**
|
|
16
|
+
* Extract value from result object using projection label.
|
|
17
|
+
* Since CSV only supports flat projections, labels are simple property names.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractValueByLabel(result: any, label: string): any;
|
|
20
|
+
/**
|
|
21
|
+
* Format a value for CSV output
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatValueForCsv(value: any): string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatValueForCsv = exports.extractValueByLabel = exports.validateSpecificationForCsv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validates a specification for CSV compatibility.
|
|
6
|
+
* Returns metadata including headers and validation results.
|
|
7
|
+
*
|
|
8
|
+
* CSV requires flat projections with single-valued components:
|
|
9
|
+
* - ✅ Fields (scalar values from matched facts)
|
|
10
|
+
* - ✅ Hashes
|
|
11
|
+
* - ✅ Timestamps
|
|
12
|
+
* - ❌ Arrays (nested specifications)
|
|
13
|
+
* - ❌ Nested objects (composite projections)
|
|
14
|
+
*/
|
|
15
|
+
function validateSpecificationForCsv(specification) {
|
|
16
|
+
const headers = [];
|
|
17
|
+
const errors = [];
|
|
18
|
+
// Ensure projection is composite
|
|
19
|
+
if (specification.projection.type !== 'composite') {
|
|
20
|
+
return {
|
|
21
|
+
headers: [],
|
|
22
|
+
isValid: false,
|
|
23
|
+
errors: ['Specification projection must be composite for CSV export']
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Ensure that the composite has components.
|
|
27
|
+
// An empty composite represents a missing projection.
|
|
28
|
+
if (specification.projection.components.length === 0) {
|
|
29
|
+
return {
|
|
30
|
+
headers: [],
|
|
31
|
+
isValid: false,
|
|
32
|
+
errors: ['Specification must have a projection for CSV export']
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
for (const component of specification.projection.components) {
|
|
36
|
+
if (component.type === 'field' || component.type === 'hash' || component.type === 'time') {
|
|
37
|
+
headers.push(component.name);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
errors.push(`Unsupported projection type of field '${component.name}' for CSV export. Only flat field projections are allowed.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
headers,
|
|
45
|
+
isValid: errors.length === 0,
|
|
46
|
+
errors
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.validateSpecificationForCsv = validateSpecificationForCsv;
|
|
50
|
+
/**
|
|
51
|
+
* Extract value from result object using projection label.
|
|
52
|
+
* Since CSV only supports flat projections, labels are simple property names.
|
|
53
|
+
*/
|
|
54
|
+
function extractValueByLabel(result, label) {
|
|
55
|
+
if (result == null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
// Direct property access
|
|
59
|
+
const value = result[label];
|
|
60
|
+
// Return null instead of undefined
|
|
61
|
+
return value !== null && value !== void 0 ? value : null;
|
|
62
|
+
}
|
|
63
|
+
exports.extractValueByLabel = extractValueByLabel;
|
|
64
|
+
/**
|
|
65
|
+
* Format a value for CSV output
|
|
66
|
+
*/
|
|
67
|
+
function formatValueForCsv(value) {
|
|
68
|
+
if (value === null || value === undefined) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
// Handle dates
|
|
72
|
+
if (value instanceof Date) {
|
|
73
|
+
return value.toISOString();
|
|
74
|
+
}
|
|
75
|
+
// Handle booleans
|
|
76
|
+
if (typeof value === 'boolean') {
|
|
77
|
+
return value ? 'true' : 'false';
|
|
78
|
+
}
|
|
79
|
+
// Default: convert to string
|
|
80
|
+
return String(value);
|
|
81
|
+
}
|
|
82
|
+
exports.formatValueForCsv = formatValueForCsv;
|
|
83
|
+
//# sourceMappingURL=csv-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv-validator.js","sourceRoot":"","sources":["../../src/http/csv-validator.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;GAUG;AACH,SAAgB,2BAA2B,CAAC,aAA4B;IACpE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,iCAAiC;IACjC,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,KAAK,WAAW,EAAE;QAC/C,OAAO;YACH,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,CAAC,2DAA2D,CAAC;SACxE,CAAC;KACL;IAED,4CAA4C;IAC5C,sDAAsD;IACtD,IAAI,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAClD,OAAO;YACH,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,CAAC,qDAAqD,CAAC;SAClE,CAAC;KACL;IAED,KAAK,MAAM,SAAS,IAAI,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE;QACzD,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE;YACtF,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SAChC;aACI;YACD,MAAM,CAAC,IAAI,CAAC,yCAAyC,SAAS,CAAC,IAAI,4DAA4D,CAAC,CAAC;SACpI;KACJ;IAED,OAAO;QACH,OAAO;QACP,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACT,CAAC;AACN,CAAC;AArCD,kEAqCC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,MAAW,EAAE,KAAa;IAC1D,IAAI,MAAM,IAAI,IAAI,EAAE;QAChB,OAAO,IAAI,CAAC;KACf;IAED,yBAAyB;IACzB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE5B,mCAAmC;IACnC,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,CAAC;AACzB,CAAC;AAVD,kDAUC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAU;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;QACvC,OAAO,EAAE,CAAC;KACb;IAED,eAAe;IACf,IAAI,KAAK,YAAY,IAAI,EAAE;QACvB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC9B;IAED,kBAAkB;IAClB,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;QAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;KACnC;IAED,6BAA6B;IAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAjBD,8CAiBC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
import { CsvMetadata } from "./csv-metadata";
|
|
3
|
+
import { ResultStream } from "./result-stream";
|
|
4
|
+
/**
|
|
5
|
+
* Output read results with streaming support.
|
|
6
|
+
* Handles content negotiation and streams data when possible.
|
|
7
|
+
*/
|
|
8
|
+
export declare function outputReadResultsStreaming(result: ResultStream<any>, res: Response, acceptType: string, csvMetadata?: CsvMetadata): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Stream results as NDJSON (newline-delimited JSON).
|
|
11
|
+
* Each result is written as a separate line.
|
|
12
|
+
*/
|
|
13
|
+
export declare function streamAsNDJSON(stream: ResultStream<any>, res: Response): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Collect all results from stream and send as compact JSON.
|
|
16
|
+
* Used for application/json format.
|
|
17
|
+
*/
|
|
18
|
+
export declare function collectAndSendCompactJSON(stream: ResultStream<any>, res: Response): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Collect all results from stream and send as pretty-printed JSON.
|
|
21
|
+
* Used for text/plain format and as default for unrecognized Accept types.
|
|
22
|
+
*/
|
|
23
|
+
export declare function collectAndSendPrettyJSON(stream: ResultStream<any>, res: Response): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Stream results as CSV using csv-stringify library.
|
|
26
|
+
* Headers are provided from the specification metadata.
|
|
27
|
+
*/
|
|
28
|
+
export declare function streamAsCSVWithStringify(stream: ResultStream<any>, res: Response, csvMetadata: CsvMetadata): Promise<void>;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.streamAsCSVWithStringify = exports.collectAndSendPrettyJSON = exports.collectAndSendCompactJSON = exports.streamAsNDJSON = exports.outputReadResultsStreaming = void 0;
|
|
13
|
+
const csv_stringify_1 = require("csv-stringify");
|
|
14
|
+
const csv_validator_1 = require("./csv-validator");
|
|
15
|
+
/**
|
|
16
|
+
* Output read results with streaming support.
|
|
17
|
+
* Handles content negotiation and streams data when possible.
|
|
18
|
+
*/
|
|
19
|
+
function outputReadResultsStreaming(result, res, acceptType, csvMetadata) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
switch (acceptType) {
|
|
22
|
+
case "application/x-ndjson":
|
|
23
|
+
// NDJSON format - stream one JSON object per line
|
|
24
|
+
yield streamAsNDJSON(result, res);
|
|
25
|
+
break;
|
|
26
|
+
case "text/csv":
|
|
27
|
+
// CSV format - stream as CSV using csv-stringify
|
|
28
|
+
if (csvMetadata) {
|
|
29
|
+
yield streamAsCSVWithStringify(result, res, csvMetadata);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error("CSV metadata is required for CSV output format");
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
case "application/json":
|
|
36
|
+
// Compact JSON
|
|
37
|
+
yield collectAndSendCompactJSON(result, res);
|
|
38
|
+
break;
|
|
39
|
+
case "text/plain":
|
|
40
|
+
// Pretty-printed JSON
|
|
41
|
+
yield collectAndSendPrettyJSON(result, res);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
// Default to pretty-printed JSON for unrecognized types
|
|
45
|
+
yield collectAndSendPrettyJSON(result, res);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.outputReadResultsStreaming = outputReadResultsStreaming;
|
|
51
|
+
/**
|
|
52
|
+
* Stream results as NDJSON (newline-delimited JSON).
|
|
53
|
+
* Each result is written as a separate line.
|
|
54
|
+
*/
|
|
55
|
+
function streamAsNDJSON(stream, res) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
res.type("application/x-ndjson");
|
|
58
|
+
try {
|
|
59
|
+
let item;
|
|
60
|
+
while ((item = yield stream.next()) !== null) {
|
|
61
|
+
res.write(JSON.stringify(item) + '\n');
|
|
62
|
+
}
|
|
63
|
+
res.end();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// Send error as NDJSON line
|
|
67
|
+
const errorFrame = {
|
|
68
|
+
error: true,
|
|
69
|
+
message: error instanceof Error ? error.message : String(error)
|
|
70
|
+
};
|
|
71
|
+
res.write(JSON.stringify(errorFrame) + '\n');
|
|
72
|
+
res.end();
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
yield stream.close();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.streamAsNDJSON = streamAsNDJSON;
|
|
80
|
+
/**
|
|
81
|
+
* Collect all results from stream and send as compact JSON.
|
|
82
|
+
* Used for application/json format.
|
|
83
|
+
*/
|
|
84
|
+
function collectAndSendCompactJSON(stream, res) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
const results = [];
|
|
88
|
+
let item;
|
|
89
|
+
while ((item = yield stream.next()) !== null) {
|
|
90
|
+
results.push(item);
|
|
91
|
+
}
|
|
92
|
+
res.type("application/json");
|
|
93
|
+
res.send(JSON.stringify(results));
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
yield stream.close();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.collectAndSendCompactJSON = collectAndSendCompactJSON;
|
|
101
|
+
/**
|
|
102
|
+
* Collect all results from stream and send as pretty-printed JSON.
|
|
103
|
+
* Used for text/plain format and as default for unrecognized Accept types.
|
|
104
|
+
*/
|
|
105
|
+
function collectAndSendPrettyJSON(stream, res) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
try {
|
|
108
|
+
const results = [];
|
|
109
|
+
let item;
|
|
110
|
+
while ((item = yield stream.next()) !== null) {
|
|
111
|
+
results.push(item);
|
|
112
|
+
}
|
|
113
|
+
res.type("text/plain");
|
|
114
|
+
res.send(JSON.stringify(results, null, 2));
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
yield stream.close();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
exports.collectAndSendPrettyJSON = collectAndSendPrettyJSON;
|
|
122
|
+
/**
|
|
123
|
+
* Stream results as CSV using csv-stringify library.
|
|
124
|
+
* Headers are provided from the specification metadata.
|
|
125
|
+
*/
|
|
126
|
+
function streamAsCSVWithStringify(stream, res, csvMetadata) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
res.type("text/csv");
|
|
129
|
+
// Helper to await 'finish' or 'error' events on a stream
|
|
130
|
+
function finishedAsync(stream) {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
stream.once('finish', resolve);
|
|
133
|
+
stream.once('error', reject);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
let stringifier;
|
|
137
|
+
try {
|
|
138
|
+
// Create csv-stringify stringifier with headers from specification
|
|
139
|
+
stringifier = (0, csv_stringify_1.stringify)({
|
|
140
|
+
header: true,
|
|
141
|
+
columns: csvMetadata.headers,
|
|
142
|
+
cast: {
|
|
143
|
+
// Custom casting for special types
|
|
144
|
+
boolean: (value) => value ? 'true' : 'false',
|
|
145
|
+
date: (value) => {
|
|
146
|
+
if (value instanceof Date) {
|
|
147
|
+
return value.toISOString();
|
|
148
|
+
}
|
|
149
|
+
return String(value);
|
|
150
|
+
},
|
|
151
|
+
object: (value) => {
|
|
152
|
+
// Handle nested objects
|
|
153
|
+
if (value && typeof value === 'object') {
|
|
154
|
+
// Fact reference - just use hash
|
|
155
|
+
if (value.type && value.hash) {
|
|
156
|
+
return value.hash;
|
|
157
|
+
}
|
|
158
|
+
// Other objects - stringify
|
|
159
|
+
return JSON.stringify(value);
|
|
160
|
+
}
|
|
161
|
+
return String(value);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
// Pipe stringifier to response
|
|
166
|
+
stringifier.pipe(res);
|
|
167
|
+
// Stream data through stringifier
|
|
168
|
+
let item = null;
|
|
169
|
+
while ((item = yield stream.next()) !== null) {
|
|
170
|
+
// Extract values in header order
|
|
171
|
+
const row = {};
|
|
172
|
+
for (const header of csvMetadata.headers) {
|
|
173
|
+
const value = (0, csv_validator_1.extractValueByLabel)(item, header);
|
|
174
|
+
row[header] = value !== null && value !== undefined ? value : '';
|
|
175
|
+
}
|
|
176
|
+
// Write row to stringifier
|
|
177
|
+
stringifier.write(row);
|
|
178
|
+
}
|
|
179
|
+
// Signal end of data
|
|
180
|
+
stringifier.end();
|
|
181
|
+
// Await finish or error
|
|
182
|
+
yield finishedAsync(stringifier);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
console.error('Error in CSV streaming:', error);
|
|
186
|
+
if (!res.headersSent) {
|
|
187
|
+
res.status(500).send('Error generating CSV');
|
|
188
|
+
}
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
yield stream.close();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
exports.streamAsCSVWithStringify = streamAsCSVWithStringify;
|
|
197
|
+
//# sourceMappingURL=output-formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-formatters.js","sourceRoot":"","sources":["../../src/http/output-formatters.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA0C;AAG1C,mDAAsD;AAGtD;;;GAGG;AACH,SAAsB,0BAA0B,CAC5C,MAAyB,EACzB,GAAa,EACb,UAAkB,EAClB,WAAyB;;QAEzB,QAAQ,UAAU,EAAE;YAChB,KAAK,sBAAsB;gBACvB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C;YAEH,+BAA+B;YAC/B,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEtB,kCAAkC;YAClC,IAAI,IAAI,GAAQ,IAAI,CAAC;YACrB,OAAO,CAAC,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE;gBAC1C,iCAAiC;gBACjC,MAAM,GAAG,GAAQ,EAAE,CAAC;gBACpB,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,OAAO,EAAE;oBACtC,MAAM,KAAK,GAAG,IAAA,mCAAmB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBAChD,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpE;gBAED,2BAA2B;gBAC3B,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC1B;YAED,qBAAqB;YACrB,WAAW,CAAC,GAAG,EAAE,CAAC;YAElB,wBAAwB;YACxB,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;SAEpC;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;aAChD;YACD,MAAM,KAAK,CAAC;SACf;gBAAS;YACN,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;SACxB;IACL,CAAC;CAAA;AA7ED,4DA6EC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResultStream interface for streaming query results incrementally.
|
|
3
|
+
* This abstraction allows for memory-efficient processing of large result sets.
|
|
4
|
+
*/
|
|
5
|
+
export interface ResultStream<T> {
|
|
6
|
+
/**
|
|
7
|
+
* Get the next item in the stream.
|
|
8
|
+
* @returns Promise resolving to the next item, or null if stream is exhausted
|
|
9
|
+
*/
|
|
10
|
+
next(): Promise<T | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Close the stream and release resources.
|
|
13
|
+
*/
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Implements ResultStream for AsyncIterable sources.
|
|
18
|
+
* Useful for streaming data from database cursors or other async sources.
|
|
19
|
+
*/
|
|
20
|
+
export declare class AsyncIterableResultStream<T> implements ResultStream<T> {
|
|
21
|
+
private iterator;
|
|
22
|
+
private closed;
|
|
23
|
+
constructor(iterable: AsyncIterable<T>);
|
|
24
|
+
next(): Promise<T | null>;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts an array to a ResultStream.
|
|
29
|
+
* Useful for backward compatibility and testing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function arrayAsyncIterable<T>(array: T[]): AsyncIterable<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Helper function to convert an array to a ResultStream.
|
|
34
|
+
*/
|
|
35
|
+
export declare function arrayToResultStream<T>(array: T[]): ResultStream<T>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
17
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
18
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
19
|
+
function fulfill(value) { resume("next", value); }
|
|
20
|
+
function reject(value) { resume("throw", value); }
|
|
21
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.arrayToResultStream = exports.arrayAsyncIterable = exports.AsyncIterableResultStream = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Implements ResultStream for AsyncIterable sources.
|
|
27
|
+
* Useful for streaming data from database cursors or other async sources.
|
|
28
|
+
*/
|
|
29
|
+
class AsyncIterableResultStream {
|
|
30
|
+
constructor(iterable) {
|
|
31
|
+
this.closed = false;
|
|
32
|
+
this.iterator = iterable[Symbol.asyncIterator]();
|
|
33
|
+
}
|
|
34
|
+
next() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (this.closed) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const result = yield this.iterator.next();
|
|
40
|
+
if (result.done) {
|
|
41
|
+
yield this.close();
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return result.value;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
close() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!this.closed) {
|
|
50
|
+
this.closed = true;
|
|
51
|
+
if (this.iterator.return) {
|
|
52
|
+
yield this.iterator.return();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AsyncIterableResultStream = AsyncIterableResultStream;
|
|
59
|
+
/**
|
|
60
|
+
* Converts an array to a ResultStream.
|
|
61
|
+
* Useful for backward compatibility and testing.
|
|
62
|
+
*/
|
|
63
|
+
function arrayAsyncIterable(array) {
|
|
64
|
+
return __asyncGenerator(this, arguments, function* arrayAsyncIterable_1() {
|
|
65
|
+
for (const item of array) {
|
|
66
|
+
yield yield __await(item);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.arrayAsyncIterable = arrayAsyncIterable;
|
|
71
|
+
/**
|
|
72
|
+
* Helper function to convert an array to a ResultStream.
|
|
73
|
+
*/
|
|
74
|
+
function arrayToResultStream(array) {
|
|
75
|
+
return new AsyncIterableResultStream(arrayAsyncIterable(array));
|
|
76
|
+
}
|
|
77
|
+
exports.arrayToResultStream = arrayToResultStream;
|
|
78
|
+
//# sourceMappingURL=result-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-stream.js","sourceRoot":"","sources":["../../src/http/result-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;GAGG;AACH,MAAa,yBAAyB;IAIlC,YAAY,QAA0B;QAF9B,WAAM,GAAY,KAAK,CAAC;QAG5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IACrD,CAAC;IAEK,IAAI;;YACN,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,OAAO,IAAI,CAAC;aACf;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,MAAM,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;aACf;YAED,OAAO,MAAM,CAAC,KAAK,CAAC;QACxB,CAAC;KAAA;IAEK,KAAK;;YACP,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;oBACtB,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;iBAChC;aACJ;QACL,CAAC;KAAA;CACJ;AA9BD,8DA8BC;AAED;;;GAGG;AACH,SAAuB,kBAAkB,CAAI,KAAU;;QACnD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACtB,oBAAM,IAAI,CAAA,CAAC;SACd;IACL,CAAC;CAAA;AAJD,gDAIC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAI,KAAU;IAC7C,OAAO,IAAI,yBAAyB,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,CAAC;AAFD,kDAEC"}
|
package/dist/http/router.d.ts
CHANGED
|
@@ -15,7 +15,13 @@ export declare class HttpRouter {
|
|
|
15
15
|
private login;
|
|
16
16
|
private load;
|
|
17
17
|
private save;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Read with streaming support.
|
|
20
|
+
* Uses readStream if available on the authorization object, otherwise falls back to read().
|
|
21
|
+
*
|
|
22
|
+
* When CSV format is requested, validates that the specification contains only flat projections.
|
|
23
|
+
*/
|
|
24
|
+
private readWithStreaming;
|
|
19
25
|
private write;
|
|
20
26
|
private feeds;
|
|
21
27
|
private feed;
|