jinaga-server 1.0.0 → 1.1.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.
Files changed (63) hide show
  1. package/README.md +103 -0
  2. package/dist/authentication/authentication-device.d.ts +3 -1
  3. package/dist/authentication/authentication-device.js +3 -0
  4. package/dist/authentication/authentication-device.js.map +1 -1
  5. package/dist/authentication/authentication-impl.d.ts +3 -2
  6. package/dist/authentication/authentication-impl.js +3 -0
  7. package/dist/authentication/authentication-impl.js.map +1 -1
  8. package/dist/authentication/authentication-session.d.ts +4 -2
  9. package/dist/authentication/authentication-session.js +7 -2
  10. package/dist/authentication/authentication-session.js.map +1 -1
  11. package/dist/authentication.d.ts +5 -4
  12. package/dist/authentication.js +3 -0
  13. package/dist/authentication.js.map +1 -1
  14. package/dist/authorization/authorization-keystore.d.ts +5 -3
  15. package/dist/authorization/authorization-keystore.js +12 -9
  16. package/dist/authorization/authorization-keystore.js.map +1 -1
  17. package/dist/http/feed-cache.d.ts +5 -0
  18. package/dist/http/feed-cache.js +3 -0
  19. package/dist/http/feed-cache.js.map +1 -0
  20. package/dist/http/node-http.js +4 -1
  21. package/dist/http/node-http.js.map +1 -1
  22. package/dist/http/router.d.ts +5 -1
  23. package/dist/http/router.js +157 -24
  24. package/dist/http/router.js.map +1 -1
  25. package/dist/jinaga-server.js +6 -4
  26. package/dist/jinaga-server.js.map +1 -1
  27. package/dist/memory/memory-feed-cache.d.ts +7 -0
  28. package/dist/memory/memory-feed-cache.js +17 -0
  29. package/dist/memory/memory-feed-cache.js.map +1 -0
  30. package/dist/postgres/postgres-store.d.ts +5 -2
  31. package/dist/postgres/postgres-store.js +53 -28
  32. package/dist/postgres/postgres-store.js.map +1 -1
  33. package/dist/postgres/specification-result-sql.d.ts +11 -4
  34. package/dist/postgres/specification-result-sql.js +302 -5
  35. package/dist/postgres/specification-result-sql.js.map +1 -1
  36. package/dist/postgres/specification-sql.d.ts +14 -3
  37. package/dist/postgres/specification-sql.js +233 -100
  38. package/dist/postgres/specification-sql.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/authentication/authentication-device.ts +6 -0
  41. package/src/authentication/authentication-impl.ts +6 -3
  42. package/src/authentication/authentication-session.ts +11 -3
  43. package/src/authentication.ts +18 -5
  44. package/src/authorization/authorization-keystore.ts +14 -8
  45. package/src/http/feed-cache.ts +6 -0
  46. package/src/http/node-http.ts +5 -2
  47. package/src/http/router.ts +179 -31
  48. package/src/jinaga-server.ts +11 -9
  49. package/src/memory/memory-feed-cache.ts +15 -0
  50. package/src/postgres/postgres-store.ts +59 -31
  51. package/src/postgres/specification-result-sql.ts +450 -10
  52. package/src/postgres/specification-sql.ts +335 -115
  53. package/test/authorization/authorizationSpec.ts +11 -2
  54. package/test/postgres/postgresSpec.ts +31 -25
  55. package/test/postgres/postgresSpecificationSpec.ts +40 -68
  56. package/dist/postgres/query-description-builder.d.ts +0 -13
  57. package/dist/postgres/query-description-builder.js +0 -104
  58. package/dist/postgres/query-description-builder.js.map +0 -1
  59. package/dist/postgres/query-description.d.ts +0 -71
  60. package/dist/postgres/query-description.js +0 -256
  61. package/dist/postgres/query-description.js.map +0 -1
  62. package/src/postgres/query-description-builder.ts +0 -116
  63. package/src/postgres/query-description.ts +0 -385
@@ -1,71 +0,0 @@
1
- import { FactBookmark } from "jinaga";
2
- export interface SpecificationLabel {
3
- name: string;
4
- type: string;
5
- index: number;
6
- }
7
- export declare type SpecificationSqlQuery = {
8
- sql: string;
9
- parameters: (string | number | number[])[];
10
- labels: SpecificationLabel[];
11
- bookmark: string;
12
- };
13
- export interface InputDescription {
14
- label: string;
15
- factIndex: number;
16
- factTypeId: number;
17
- factHash: string;
18
- factTypeParameter: number;
19
- factHashParameter: number;
20
- }
21
- interface OutputDescription {
22
- label: string;
23
- type: string;
24
- factIndex: number;
25
- }
26
- export interface FactDescription {
27
- type: string;
28
- factIndex: number;
29
- }
30
- interface EdgeDescription {
31
- edgeIndex: number;
32
- predecessorFactIndex: number;
33
- successorFactIndex: number;
34
- roleParameter: number;
35
- }
36
- interface NotExistsConditionDescription {
37
- edges: EdgeDescription[];
38
- notExistsConditions: NotExistsConditionDescription[];
39
- }
40
- export declare class QueryDescription {
41
- private readonly inputs;
42
- private readonly parameters;
43
- private readonly outputs;
44
- private readonly facts;
45
- private readonly edges;
46
- private readonly notExistsConditions;
47
- static unsatisfiable: QueryDescription;
48
- constructor(inputs: InputDescription[], parameters: (string | number)[], outputs: OutputDescription[], facts: FactDescription[], edges: EdgeDescription[], notExistsConditions?: NotExistsConditionDescription[]);
49
- withParameter(parameter: string | number): {
50
- query: QueryDescription;
51
- parameterIndex: number;
52
- };
53
- withInputParameter(label: string): QueryDescription;
54
- withFact(type: string): {
55
- query: QueryDescription;
56
- factIndex: number;
57
- };
58
- withOutput(label: string, type: string, factIndex: number): QueryDescription;
59
- withEdge(predecessorFactIndex: number, successorFactIndex: number, roleParameter: number, path: number[]): QueryDescription;
60
- withNotExistsCondition(path: number[]): {
61
- query: QueryDescription;
62
- path: number[];
63
- };
64
- isSatisfiable(): boolean;
65
- hasOutput(label: string): boolean;
66
- inputByLabel(label: string): InputDescription | undefined;
67
- outputLength(): number;
68
- generateSqlQuery(bookmarks: FactBookmark[], limit: number): SpecificationSqlQuery;
69
- generateResultSqlQuery(): SpecificationSqlQuery;
70
- }
71
- export {};
@@ -1,256 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryDescription = void 0;
4
- function notExistsWithEdge(notExistsConditions, edge, path) {
5
- if (path.length === 1) {
6
- return notExistsConditions.map((c, i) => i === path[0] ?
7
- {
8
- edges: [...c.edges, edge],
9
- notExistsConditions: c.notExistsConditions
10
- } :
11
- c);
12
- }
13
- else {
14
- return notExistsConditions.map((c, i) => i === path[0] ?
15
- {
16
- edges: c.edges,
17
- notExistsConditions: notExistsWithEdge(c.notExistsConditions, edge, path.slice(1))
18
- } :
19
- c);
20
- }
21
- }
22
- function notExistsWithCondition(notExistsConditions, path) {
23
- if (path.length === 0) {
24
- path = [notExistsConditions.length];
25
- notExistsConditions = [
26
- ...notExistsConditions,
27
- {
28
- edges: [],
29
- notExistsConditions: []
30
- }
31
- ];
32
- return { notExistsConditions, path };
33
- }
34
- else {
35
- const { notExistsConditions: newNotExistsConditions, path: newPath } = notExistsWithCondition(notExistsConditions[path[0]].notExistsConditions, path.slice(1));
36
- notExistsConditions = notExistsConditions.map((c, i) => i === path[0] ?
37
- {
38
- edges: c.edges,
39
- notExistsConditions: newNotExistsConditions
40
- } :
41
- c);
42
- path = [path[0], ...newPath];
43
- return { notExistsConditions, path };
44
- }
45
- }
46
- function countEdges(notExistsConditions) {
47
- return notExistsConditions.reduce((count, c) => count + c.edges.length + countEdges(c.notExistsConditions), 0);
48
- }
49
- class QueryDescription {
50
- constructor(inputs, parameters, outputs, facts, edges, notExistsConditions = []) {
51
- this.inputs = inputs;
52
- this.parameters = parameters;
53
- this.outputs = outputs;
54
- this.facts = facts;
55
- this.edges = edges;
56
- this.notExistsConditions = notExistsConditions;
57
- }
58
- withParameter(parameter) {
59
- const parameterIndex = this.parameters.length + 1;
60
- const query = new QueryDescription(this.inputs, this.parameters.concat(parameter), this.outputs, this.facts, this.edges, this.notExistsConditions);
61
- return { query, parameterIndex };
62
- }
63
- withInputParameter(label) {
64
- const factTypeParameter = this.parameters.length + 1;
65
- const factHashParameter = factTypeParameter + 1;
66
- const input = this.inputs.find(i => i.label === label);
67
- const inputs = this.inputs.map(input => input.label === label
68
- ? Object.assign(Object.assign({}, input), { factTypeParameter, factHashParameter }) : input);
69
- return new QueryDescription(inputs, this.parameters.concat(input.factTypeId, input.factHash), this.outputs, this.facts, this.edges, this.notExistsConditions);
70
- }
71
- withFact(type) {
72
- const factIndex = this.facts.length + 1;
73
- const fact = { factIndex, type };
74
- const query = new QueryDescription(this.inputs, this.parameters, this.outputs, this.facts.concat(fact), this.edges, this.notExistsConditions);
75
- return { query, factIndex };
76
- }
77
- withOutput(label, type, factIndex) {
78
- const output = { label, type, factIndex };
79
- const query = new QueryDescription(this.inputs, this.parameters, this.outputs.concat(output), this.facts, this.edges, this.notExistsConditions);
80
- return query;
81
- }
82
- withEdge(predecessorFactIndex, successorFactIndex, roleParameter, path) {
83
- const edge = {
84
- edgeIndex: this.edges.length + countEdges(this.notExistsConditions) + 1,
85
- predecessorFactIndex,
86
- successorFactIndex,
87
- roleParameter
88
- };
89
- const query = (path.length === 0)
90
- ? new QueryDescription(this.inputs, this.parameters, this.outputs, this.facts, this.edges.concat(edge), this.notExistsConditions)
91
- : new QueryDescription(this.inputs, this.parameters, this.outputs, this.facts, this.edges, notExistsWithEdge(this.notExistsConditions, edge, path));
92
- return query;
93
- }
94
- withNotExistsCondition(path) {
95
- const { notExistsConditions: newNotExistsConditions, path: newPath } = notExistsWithCondition(this.notExistsConditions, path);
96
- const query = new QueryDescription(this.inputs, this.parameters, this.outputs, this.facts, this.edges, newNotExistsConditions);
97
- return { query, path: newPath };
98
- }
99
- isSatisfiable() {
100
- return this.inputs.length > 0;
101
- }
102
- hasOutput(label) {
103
- return this.outputs.some(o => o.label === label);
104
- }
105
- inputByLabel(label) {
106
- return this.inputs.find(i => i.label === label);
107
- }
108
- outputLength() {
109
- return this.outputs.length;
110
- }
111
- generateSqlQuery(bookmarks, limit) {
112
- const hashes = this.outputs
113
- .map(output => `f${output.factIndex}.hash as hash${output.factIndex}`)
114
- .join(", ");
115
- const factIds = this.outputs
116
- .map(output => `f${output.factIndex}.fact_id`)
117
- .join(", ");
118
- const firstEdge = this.edges[0];
119
- const predecessorFact = this.inputs.find(i => i.factIndex === firstEdge.predecessorFactIndex);
120
- const successorFact = this.inputs.find(i => i.factIndex === firstEdge.successorFactIndex);
121
- const firstFactIndex = predecessorFact ? predecessorFact.factIndex : successorFact.factIndex;
122
- const writtenFactIndexes = new Set().add(firstFactIndex);
123
- const joins = generateJoins(this.edges, writtenFactIndexes);
124
- const inputWhereClauses = this.inputs
125
- .filter(input => input.factTypeParameter !== 0)
126
- .map(input => `f${input.factIndex}.fact_type_id = $${input.factTypeParameter} AND f${input.factIndex}.hash = $${input.factHashParameter}`)
127
- .join(" AND ");
128
- const notExistsWhereClauses = this.notExistsConditions
129
- .map(notExistsWhereClause => ` AND NOT EXISTS (${generateNotExistsWhereClause(notExistsWhereClause, writtenFactIndexes)})`)
130
- .join("");
131
- const bookmarkParameter = this.parameters.length + 1;
132
- const limitParameter = bookmarkParameter + 1;
133
- const bookmark = bookmarks.find(bookmark => bookmark.labels.length === this.outputs.length &&
134
- bookmark.labels.every((label, index) => label === this.outputs[index].label));
135
- const sql = `SELECT ${hashes}, sort(array[${factIds}], 'desc') as bookmark FROM public.fact f${firstFactIndex}${joins.join("")} WHERE ${inputWhereClauses}${notExistsWhereClauses} AND sort(array[${factIds}], 'desc') > $${bookmarkParameter} ORDER BY bookmark ASC LIMIT $${limitParameter}`;
136
- const bookmarkValue = parseBookmark(bookmark);
137
- return {
138
- sql,
139
- parameters: [...this.parameters, bookmarkValue, limit],
140
- labels: this.outputs.map(output => ({
141
- name: output.label,
142
- type: output.type,
143
- index: output.factIndex
144
- })),
145
- bookmark: "[]"
146
- };
147
- }
148
- generateResultSqlQuery() {
149
- const columns = this.outputs
150
- .map(output => `f${output.factIndex}.hash as hash${output.factIndex}, f${output.factIndex}.fact_id as id${output.factIndex}, f${output.factIndex}.data as data${output.factIndex}`)
151
- .join(", ");
152
- const firstEdge = this.edges[0];
153
- const predecessorFact = this.inputs.find(i => i.factIndex === firstEdge.predecessorFactIndex);
154
- const successorFact = this.inputs.find(i => i.factIndex === firstEdge.successorFactIndex);
155
- const firstFactIndex = predecessorFact ? predecessorFact.factIndex : successorFact.factIndex;
156
- const writtenFactIndexes = new Set().add(firstFactIndex);
157
- const joins = generateJoins(this.edges, writtenFactIndexes);
158
- const inputWhereClauses = this.inputs
159
- .filter(input => input.factTypeParameter !== 0)
160
- .map(input => `f${input.factIndex}.fact_type_id = $${input.factTypeParameter} AND f${input.factIndex}.hash = $${input.factHashParameter}`)
161
- .join(" AND ");
162
- const notExistsWhereClauses = this.notExistsConditions
163
- .map(notExistsWhereClause => ` AND NOT EXISTS (${generateNotExistsWhereClause(notExistsWhereClause, writtenFactIndexes)})`)
164
- .join("");
165
- const orderByClause = this.outputs
166
- .map(output => `f${output.factIndex}.fact_id ASC`)
167
- .join(", ");
168
- const sql = `SELECT ${columns} FROM public.fact f${firstFactIndex}${joins.join("")} WHERE ${inputWhereClauses}${notExistsWhereClauses} ORDER BY ${orderByClause}`;
169
- return {
170
- sql,
171
- parameters: this.parameters,
172
- labels: this.outputs.map(output => ({
173
- name: output.label,
174
- type: output.type,
175
- index: output.factIndex
176
- })),
177
- bookmark: "[]"
178
- };
179
- }
180
- }
181
- exports.QueryDescription = QueryDescription;
182
- // An unsatisfiable query description will produce no results.
183
- QueryDescription.unsatisfiable = new QueryDescription([], [], [], [], [], []);
184
- function generateJoins(edges, writtenFactIndexes) {
185
- const joins = [];
186
- edges.forEach(edge => {
187
- if (writtenFactIndexes.has(edge.predecessorFactIndex)) {
188
- if (writtenFactIndexes.has(edge.successorFactIndex)) {
189
- joins.push(` JOIN public.edge e${edge.edgeIndex}` +
190
- ` ON e${edge.edgeIndex}.predecessor_fact_id = f${edge.predecessorFactIndex}.fact_id` +
191
- ` AND e${edge.edgeIndex}.successor_fact_id = f${edge.successorFactIndex}.fact_id` +
192
- ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
193
- }
194
- else {
195
- joins.push(` JOIN public.edge e${edge.edgeIndex}` +
196
- ` ON e${edge.edgeIndex}.predecessor_fact_id = f${edge.predecessorFactIndex}.fact_id` +
197
- ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
198
- joins.push(` JOIN public.fact f${edge.successorFactIndex}` +
199
- ` ON f${edge.successorFactIndex}.fact_id = e${edge.edgeIndex}.successor_fact_id`);
200
- writtenFactIndexes.add(edge.successorFactIndex);
201
- }
202
- }
203
- else if (writtenFactIndexes.has(edge.successorFactIndex)) {
204
- joins.push(` JOIN public.edge e${edge.edgeIndex}` +
205
- ` ON e${edge.edgeIndex}.successor_fact_id = f${edge.successorFactIndex}.fact_id` +
206
- ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
207
- joins.push(` JOIN public.fact f${edge.predecessorFactIndex}` +
208
- ` ON f${edge.predecessorFactIndex}.fact_id = e${edge.edgeIndex}.predecessor_fact_id`);
209
- writtenFactIndexes.add(edge.predecessorFactIndex);
210
- }
211
- else {
212
- throw new Error("Neither predecessor nor successor fact has been written");
213
- }
214
- });
215
- return joins;
216
- }
217
- function generateNotExistsWhereClause(notExistsWhereClause, outerFactIndexes) {
218
- const firstEdge = notExistsWhereClause.edges[0];
219
- const writtenFactIndexes = new Set(outerFactIndexes);
220
- const firstJoin = [];
221
- const whereClause = [];
222
- if (writtenFactIndexes.has(firstEdge.predecessorFactIndex)) {
223
- if (writtenFactIndexes.has(firstEdge.successorFactIndex)) {
224
- throw new Error("Not yet implemented");
225
- }
226
- else {
227
- whereClause.push(`e${firstEdge.edgeIndex}.predecessor_fact_id = f${firstEdge.predecessorFactIndex}.fact_id` +
228
- ` AND e${firstEdge.edgeIndex}.role_id = $${firstEdge.roleParameter}`);
229
- firstJoin.push(` JOIN public.fact f${firstEdge.successorFactIndex}` +
230
- ` ON f${firstEdge.successorFactIndex}.fact_id = e${firstEdge.edgeIndex}.successor_fact_id`);
231
- writtenFactIndexes.add(firstEdge.successorFactIndex);
232
- }
233
- }
234
- else if (writtenFactIndexes.has(firstEdge.successorFactIndex)) {
235
- whereClause.push(`e${firstEdge.edgeIndex}.successor_fact_id = f${firstEdge.successorFactIndex}.fact_id` +
236
- ` AND e${firstEdge.edgeIndex}.role_id = $${firstEdge.roleParameter}`);
237
- firstJoin.push(` JOIN public.fact f${firstEdge.predecessorFactIndex}` +
238
- ` ON f${firstEdge.predecessorFactIndex}.fact_id = e${firstEdge.edgeIndex}.predecessor_fact_id`);
239
- writtenFactIndexes.add(firstEdge.predecessorFactIndex);
240
- }
241
- else {
242
- throw new Error("Neither predecessor nor successor fact has been written");
243
- }
244
- const tailJoins = generateJoins(notExistsWhereClause.edges.slice(1), writtenFactIndexes);
245
- const joins = firstJoin.concat(tailJoins);
246
- return `SELECT 1 FROM public.edge e${firstEdge.edgeIndex}${joins.join("")} WHERE ${whereClause.join(" AND ")}`;
247
- }
248
- function parseBookmark(bookmark) {
249
- if (bookmark === undefined || bookmark === null || bookmark.bookmark === "") {
250
- return [];
251
- }
252
- else {
253
- return bookmark.bookmark.split(".").map(str => parseInt(str));
254
- }
255
- }
256
- //# sourceMappingURL=query-description.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-description.js","sourceRoot":"","sources":["../../src/postgres/query-description.ts"],"names":[],"mappings":";;;AAyCA,SAAS,iBAAiB,CAAC,mBAAoD,EAAE,IAA6G,EAAE,IAAc;IAC1M,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACnB,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD;gBACI,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC;gBACzB,mBAAmB,EAAE,CAAC,CAAC,mBAAmB;aAC7C,CAAC,CAAC;YACH,CAAC,CACJ,CAAC;KACL;SACI;QACD,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD;gBACI,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACrF,CAAC,CAAC;YACH,CAAC,CACJ,CAAC;KACL;AACL,CAAC;AACD,SAAS,sB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AAkB,CAAC,EAAE;QAC3D,WAAW,CAAC,IAAI,CACZ,IAAI,SAAS,CAAC,SAAS,yBAAyB,SAAS,CAAC,kBAAkB,UAAU;YACtF,SAAS,SAAS,CAAC,SAAS,eAAe,SAAS,CAAC,aAAa,EAAE,CACvE,CAAC;QACF,SAAS,CAAC,IAAI,CACV,sBAAsB,SAAS,CAAC,oBAAoB,EAAE;YACtD,QAAQ,SAAS,CAAC,oBAAoB,eAAe,SAAS,CAAC,SAAS,sBAAsB,CACjG,CAAC;QACF,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;KAC1D;SACI;QACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;KAC9E;IACD,MAAM,SAAS,GAAa,aAAa,CAAC,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACnG,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1C,OAAO,8BAA8B,SAAS,CAAC,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AACnH,CAAC;AAED,SAAS,aAAa,CAAC,QAAsB;IACzC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,QAAQ,KAAK,EAAE,EAAE;QACzE,OAAO,EAAE,CAAC;KACb;SACI;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;KACjE;AACL,CAAC"}
@@ -1,116 +0,0 @@
1
- import { Label, PathCondition } from "jinaga";
2
-
3
- import { FactTypeMap, getFactTypeId, getRoleId, RoleMap } from "./maps";
4
- import { QueryDescription } from "./query-description";
5
- import { FactByIdentifier } from "./specification-result-sql";
6
-
7
- export class QueryDescriptionBuilder {
8
- constructor(
9
- protected readonly factTypes: FactTypeMap,
10
- protected readonly roleMap: RoleMap
11
- ) { }
12
-
13
- protected addPathCondition(queryDescription: QueryDescription, knownFacts: FactByIdentifier, path: number[], unknown: Label, prefix: string, condition: PathCondition): { queryDescription: QueryDescription, knownFacts: FactByIdentifier } {
14
- // If no input parameter has been allocated, allocate one now.
15
- const input = queryDescription.inputByLabel(condition.labelRight);
16
- if (input && input.factTypeParameter === 0) {
17
- queryDescription = queryDescription.withInputParameter(input.label);
18
- }
19
-
20
- // Determine whether we have already written the output.
21
- const knownFact = knownFacts[unknown.name];
22
- const roleCount = condition.rolesLeft.length + condition.rolesRight.length;
23
-
24
- // Walk up the right-hand side.
25
- // This generates predecessor joins from a given or prior label.
26
- let fact = knownFacts[condition.labelRight];
27
- if (!fact) {
28
- throw new Error(`Label ${condition.labelRight} not found. Known labels: ${Object.keys(knownFacts).join(", ")}`);
29
- }
30
- let type = fact.type;
31
- let factIndex = fact.factIndex;
32
- for (const [i, role] of condition.rolesRight.entries()) {
33
- // If the type or role is not known, then no facts matching the condition can
34
- // exist. The query is unsatisfiable.
35
- const typeId = getFactTypeId(this.factTypes, type);
36
- if (!typeId) {
37
- return { queryDescription: QueryDescription.unsatisfiable, knownFacts };
38
- }
39
- const roleId = getRoleId(this.roleMap, typeId, role.name);
40
- if (!roleId) {
41
- return { queryDescription: QueryDescription.unsatisfiable, knownFacts };
42
- }
43
-
44
- const { query: queryWithParameter, parameterIndex: roleParameter } = queryDescription.withParameter(roleId);
45
- if (i === roleCount - 1 && knownFact) {
46
- // If we have already written the output, we can use the fact index.
47
- queryDescription = queryWithParameter.withEdge(knownFact.factIndex, factIndex, roleParameter, path);
48
- factIndex = knownFact.factIndex;
49
- }
50
- else {
51
- // If we have not written the fact, we need to write it now.
52
- const { query, factIndex: predecessorFactIndex } = queryWithParameter.withFact(role.targetType);
53
- queryDescription = query.withEdge(predecessorFactIndex, factIndex, roleParameter, path);
54
- factIndex = predecessorFactIndex;
55
- }
56
- type = role.targetType;
57
- }
58
-
59
- const rightType = type;
60
-
61
- // Walk up the left-hand side.
62
- // We will need to reverse this walk to generate successor joins.
63
- type = unknown.type;
64
- const newEdges: {
65
- roleId: number;
66
- declaringType: string;
67
- }[] = [];
68
- for (const role of condition.rolesLeft) {
69
- // If the type or role is not known, then no facts matching the condition can
70
- // exist. The query is unsatisfiable.
71
- const typeId = getFactTypeId(this.factTypes, type);
72
- if (!typeId) {
73
- return { queryDescription: QueryDescription.unsatisfiable, knownFacts };
74
- }
75
- const roleId = getRoleId(this.roleMap, typeId, role.name);
76
- if (!roleId) {
77
- return { queryDescription: QueryDescription.unsatisfiable, knownFacts };
78
- }
79
-
80
- newEdges.push({
81
- roleId,
82
- declaringType: type
83
- });
84
- type = role.targetType;
85
- }
86
-
87
- if (type !== rightType) {
88
- throw new Error(`Type mismatch: ${type} is compared to ${rightType}`);
89
- }
90
-
91
- newEdges.reverse().forEach(({ roleId, declaringType }, i) => {
92
- const { query: queryWithParameter, parameterIndex: roleParameter } = queryDescription.withParameter(roleId);
93
- if (condition.rolesRight.length + i === roleCount - 1 && knownFact) {
94
- queryDescription = queryWithParameter.withEdge(factIndex, knownFact.factIndex, roleParameter, path);
95
- factIndex = knownFact.factIndex;
96
- }
97
- else {
98
- const { query: queryWithFact, factIndex: successorFactIndex } = queryWithParameter.withFact(declaringType);
99
- queryDescription = queryWithFact.withEdge(factIndex, successorFactIndex, roleParameter, path);
100
- factIndex = successorFactIndex;
101
- }
102
- });
103
-
104
- // If we have not captured the known fact, add it now.
105
- if (!knownFact) {
106
- knownFacts = { ...knownFacts, [unknown.name]: { factIndex, type: unknown.type } };
107
- // If we have not written the output, write it now.
108
- // Only write the output if we are not inside of an existential condition.
109
- // Use the prefix, which will be set for projections.
110
- if (path.length === 0) {
111
- queryDescription = queryDescription.withOutput(prefix + unknown.name, unknown.type, factIndex);
112
- }
113
- }
114
- return { queryDescription, knownFacts };
115
- }
116
- }