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,119 +1,252 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sqlFromSpecification = void 0;
3
+ exports.sqlFromFeed = exports.sqlFromSpecification = void 0;
4
+ const jinaga_1 = require("jinaga");
4
5
  const maps_1 = require("./maps");
5
- const query_description_1 = require("./query-description");
6
- const query_description_builder_1 = require("./query-description-builder");
7
- class DescriptionBuilder extends query_description_builder_1.QueryDescriptionBuilder {
8
- constructor(factTypes, roleMap) { super(factTypes, roleMap); }
9
- buildDescriptions(start, specification) {
10
- // Verify that the number of start facts equals the number of inputs
11
- if (start.length !== specification.given.length) {
12
- throw new Error(`The number of start facts (${start.length}) does not equal the number of inputs (${specification.given.length})`);
13
- }
14
- // Verify that the input type matches the start fact type
15
- for (let i = 0; i < start.length; i++) {
16
- if (start[i].type !== specification.given[i].type) {
17
- throw new Error(`The type of start fact ${i} (${start[i].type}) does not match the type of input ${i} (${specification.given[i].type})`);
6
+ ;
7
+ class QueryDescription {
8
+ constructor(inputs, parameters, outputs, edges, notExistsConditions = []) {
9
+ this.inputs = inputs;
10
+ this.parameters = parameters;
11
+ this.outputs = outputs;
12
+ this.edges = edges;
13
+ this.notExistsConditions = notExistsConditions;
14
+ }
15
+ generateSqlQuery(bookmark, limit) {
16
+ const hashes = this.outputs
17
+ .map(output => `f${output.factIndex}.hash as hash${output.factIndex}`)
18
+ .join(", ");
19
+ const factIds = this.outputs
20
+ .map(output => `f${output.factIndex}.fact_id`)
21
+ .join(", ");
22
+ const firstEdge = this.edges[0];
23
+ const predecessorFact = this.inputs.find(i => i.factIndex === firstEdge.predecessorFactIndex);
24
+ const successorFact = this.inputs.find(i => i.factIndex === firstEdge.successorFactIndex);
25
+ const firstFactIndex = predecessorFact ? predecessorFact.factIndex : successorFact.factIndex;
26
+ const writtenFactIndexes = new Set().add(firstFactIndex);
27
+ const joins = generateJoins(this.edges, writtenFactIndexes);
28
+ const inputWhereClauses = this.inputs
29
+ .filter(input => input.factTypeParameter !== 0)
30
+ .map(input => `f${input.factIndex}.fact_type_id = $${input.factTypeParameter} AND f${input.factIndex}.hash = $${input.factHashParameter}`)
31
+ .join(" AND ");
32
+ const notExistsWhereClauses = this.notExistsConditions
33
+ .map(notExistsWhereClause => ` AND NOT EXISTS (${generateNotExistsWhereClause(notExistsWhereClause, writtenFactIndexes)})`)
34
+ .join("");
35
+ const bookmarkParameter = this.parameters.length + 1;
36
+ const limitParameter = bookmarkParameter + 1;
37
+ 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}`;
38
+ const bookmarkValue = parseBookmark(bookmark);
39
+ return {
40
+ sql,
41
+ parameters: [...this.parameters, bookmarkValue, limit],
42
+ labels: this.outputs.map(output => ({
43
+ type: output.type,
44
+ index: output.factIndex
45
+ })),
46
+ bookmark: "[]"
47
+ };
48
+ }
49
+ }
50
+ function generateJoins(edges, writtenFactIndexes) {
51
+ const joins = [];
52
+ edges.forEach(edge => {
53
+ if (writtenFactIndexes.has(edge.predecessorFactIndex)) {
54
+ if (writtenFactIndexes.has(edge.successorFactIndex)) {
55
+ joins.push(` JOIN public.edge e${edge.edgeIndex}` +
56
+ ` ON e${edge.edgeIndex}.predecessor_fact_id = f${edge.predecessorFactIndex}.fact_id` +
57
+ ` AND e${edge.edgeIndex}.successor_fact_id = f${edge.successorFactIndex}.fact_id` +
58
+ ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
59
+ }
60
+ else {
61
+ joins.push(` JOIN public.edge e${edge.edgeIndex}` +
62
+ ` ON e${edge.edgeIndex}.predecessor_fact_id = f${edge.predecessorFactIndex}.fact_id` +
63
+ ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
64
+ joins.push(` JOIN public.fact f${edge.successorFactIndex}` +
65
+ ` ON f${edge.successorFactIndex}.fact_id = e${edge.edgeIndex}.successor_fact_id`);
66
+ writtenFactIndexes.add(edge.successorFactIndex);
18
67
  }
19
68
  }
20
- // Allocate a fact table for each given.
21
- // While the fact type and hash parameters are zero, the join will not be written.
22
- const inputs = specification.given
23
- .map((label, i) => ({
24
- label: label.name,
25
- factIndex: i + 1,
26
- factTypeId: (0, maps_1.getFactTypeId)(this.factTypes, label.type),
27
- factHash: start[i].hash,
28
- factTypeParameter: 0,
29
- factHashParameter: 0
30
- }));
31
- const facts = specification.given
32
- .map((label, i) => ({
33
- factIndex: i + 1,
34
- type: label.type
35
- }));
36
- const givenFacts = specification.given.reduce((knownFacts, label, i) => (Object.assign(Object.assign({}, knownFacts), { [label.name]: facts[i] })), {});
37
- // The QueryDescription is an immutable data type.
38
- // Initialize it with the inputs and facts.
39
- // The DescriptionBuilder will branch at various points, and
40
- // build on the current query description along each branch.
41
- const initialQueryDescription = new query_description_1.QueryDescription(inputs, [], [], facts, [], []);
42
- const { queryDescriptions, knownFacts } = this.addEdges(initialQueryDescription, givenFacts, [], "", specification.matches);
43
- // The final query description represents the complete tuple.
44
- // Build projections onto that one.
45
- const finalQueryDescription = queryDescriptions[queryDescriptions.length - 1];
46
- if (Array.isArray(specification.childProjections)) {
47
- const queryDescriptionsWithProjections = this.addProjections(finalQueryDescription, knownFacts, specification.childProjections);
48
- return [...queryDescriptions, ...queryDescriptionsWithProjections];
69
+ else if (writtenFactIndexes.has(edge.successorFactIndex)) {
70
+ joins.push(` JOIN public.edge e${edge.edgeIndex}` +
71
+ ` ON e${edge.edgeIndex}.successor_fact_id = f${edge.successorFactIndex}.fact_id` +
72
+ ` AND e${edge.edgeIndex}.role_id = $${edge.roleParameter}`);
73
+ joins.push(` JOIN public.fact f${edge.predecessorFactIndex}` +
74
+ ` ON f${edge.predecessorFactIndex}.fact_id = e${edge.edgeIndex}.predecessor_fact_id`);
75
+ writtenFactIndexes.add(edge.predecessorFactIndex);
76
+ }
77
+ else {
78
+ throw new Error("Neither predecessor nor successor fact has been written");
79
+ }
80
+ });
81
+ return joins;
82
+ }
83
+ function generateNotExistsWhereClause(notExistsWhereClause, outerFactIndexes) {
84
+ const firstEdge = notExistsWhereClause.edges[0];
85
+ const writtenFactIndexes = new Set(outerFactIndexes);
86
+ const firstJoin = [];
87
+ const whereClause = [];
88
+ if (writtenFactIndexes.has(firstEdge.predecessorFactIndex)) {
89
+ if (writtenFactIndexes.has(firstEdge.successorFactIndex)) {
90
+ throw new Error("Not yet implemented");
49
91
  }
50
92
  else {
51
- return queryDescriptions;
93
+ whereClause.push(`e${firstEdge.edgeIndex}.predecessor_fact_id = f${firstEdge.predecessorFactIndex}.fact_id` +
94
+ ` AND e${firstEdge.edgeIndex}.role_id = $${firstEdge.roleParameter}`);
95
+ firstJoin.push(` JOIN public.fact f${firstEdge.successorFactIndex}` +
96
+ ` ON f${firstEdge.successorFactIndex}.fact_id = e${firstEdge.edgeIndex}.successor_fact_id`);
97
+ writtenFactIndexes.add(firstEdge.successorFactIndex);
52
98
  }
53
99
  }
54
- addEdges(queryDescription, knownFacts, path, prefix, matches) {
55
- const queryDescriptions = [];
56
- for (const match of matches) {
57
- for (const condition of match.conditions) {
58
- if (condition.type === "path") {
59
- ({ queryDescription, knownFacts } = this.addPathCondition(queryDescription, knownFacts, path, match.unknown, prefix, condition));
60
- }
61
- else if (condition.type === "existential") {
62
- if (condition.exists) {
63
- // Include the edges of the existential condition into the current
64
- // query description.
65
- const { queryDescriptions: newQueryDescriptions } = this.addEdges(queryDescription, knownFacts, path, prefix, condition.matches);
66
- const last = newQueryDescriptions.length - 1;
67
- queryDescriptions.push(...newQueryDescriptions.slice(0, last));
68
- queryDescription = newQueryDescriptions[last];
69
- }
70
- else {
71
- // Branch from the current query description and follow the
72
- // edges of the existential condition.
73
- // This will produce tuples that prove the condition false.
74
- const { queryDescriptions: newQueryDescriptions } = this.addEdges(queryDescription, knownFacts, path, prefix, condition.matches);
75
- // Then apply the where clause and continue with the tuple where it is true.
76
- // The path describes which not-exists condition we are currently building on.
77
- // Because the path is not empty, labeled facts will be included in the output.
78
- const { query: queryDescriptionWithNotExist, path: conditionalPath } = queryDescription.withNotExistsCondition(path);
79
- const { queryDescriptions: newQueryDescriptionsWithNotExists } = this.addEdges(queryDescriptionWithNotExist, knownFacts, conditionalPath, prefix, condition.matches);
80
- const last = newQueryDescriptionsWithNotExists.length - 1;
81
- const queryDescriptionConditional = newQueryDescriptionsWithNotExists[last];
82
- // If the negative existential condition is not satisfiable, then
83
- // that means that the condition will always be true.
84
- // We can therefore skip the branch for the negative existential condition.
85
- if (queryDescriptionConditional.isSatisfiable()) {
86
- queryDescriptions.push(...newQueryDescriptions);
87
- queryDescriptions.push(...newQueryDescriptionsWithNotExists.slice(0, last));
88
- queryDescription = queryDescriptionConditional;
89
- }
90
- }
91
- }
100
+ else if (writtenFactIndexes.has(firstEdge.successorFactIndex)) {
101
+ whereClause.push(`e${firstEdge.edgeIndex}.successor_fact_id = f${firstEdge.successorFactIndex}.fact_id` +
102
+ ` AND e${firstEdge.edgeIndex}.role_id = $${firstEdge.roleParameter}`);
103
+ firstJoin.push(` JOIN public.fact f${firstEdge.predecessorFactIndex}` +
104
+ ` ON f${firstEdge.predecessorFactIndex}.fact_id = e${firstEdge.edgeIndex}.predecessor_fact_id`);
105
+ writtenFactIndexes.add(firstEdge.predecessorFactIndex);
106
+ }
107
+ else {
108
+ throw new Error("Neither predecessor nor successor fact has been written");
109
+ }
110
+ const tailJoins = generateJoins(notExistsWhereClause.edges.slice(1), writtenFactIndexes);
111
+ const joins = firstJoin.concat(tailJoins);
112
+ return `SELECT 1 FROM public.edge e${firstEdge.edgeIndex}${joins.join("")} WHERE ${whereClause.join(" AND ")}`;
113
+ }
114
+ function parseBookmark(bookmark) {
115
+ if (bookmark === undefined || bookmark === null || bookmark === "") {
116
+ return [];
117
+ }
118
+ else {
119
+ return bookmark.split(".").map(str => parseInt(str));
120
+ }
121
+ }
122
+ class DescriptionBuilder {
123
+ constructor(factTypes, roleMap) {
124
+ this.factTypes = factTypes;
125
+ this.roleMap = roleMap;
126
+ }
127
+ isSatisfiable(feed, edges) {
128
+ for (const edge of edges) {
129
+ const successor = feed.facts.find(f => f.factIndex === edge.successorFactIndex);
130
+ if (!successor) {
131
+ return false;
132
+ }
133
+ const predecessor = feed.facts.find(f => f.factIndex === edge.predecessorFactIndex);
134
+ if (!predecessor) {
135
+ return false;
136
+ }
137
+ const successorFactTypeId = (0, maps_1.getFactTypeId)(this.factTypes, successor.factType);
138
+ if (!successorFactTypeId) {
139
+ return false;
140
+ }
141
+ if (!(0, maps_1.getRoleId)(this.roleMap, successorFactTypeId, edge.roleName)) {
142
+ return false;
143
+ }
144
+ const predecessorFactTypeId = (0, maps_1.getFactTypeId)(this.factTypes, predecessor.factType);
145
+ if (!predecessorFactTypeId) {
146
+ return false;
92
147
  }
93
148
  }
94
- queryDescriptions.push(queryDescription);
95
- return { queryDescriptions, knownFacts };
149
+ return true;
96
150
  }
97
- addProjections(queryDescription, knownFacts, projections) {
98
- const queryDescriptions = [];
99
- projections.forEach(projection => {
100
- if (projection.type === "specification") {
101
- // Produce more facts in the tuple, and prefix the labels with the projection name.
102
- const prefix = projection.name + ".";
103
- const { queryDescriptions: queryDescriptionsWithEdges } = this.addEdges(queryDescription, knownFacts, [], prefix, projection.matches);
104
- queryDescriptions.push(...queryDescriptionsWithEdges);
105
- }
106
- });
107
- return queryDescriptions;
151
+ buildDescription(feed) {
152
+ const parameters = [];
153
+ function addParameter(value) {
154
+ parameters.push(value);
155
+ return parameters.length;
156
+ }
157
+ // Allocate parameters for the inputs.
158
+ const inputs = feed.inputs.map(input => this.buildInputDescription(feed, input, addParameter));
159
+ // Allocate parameters for the edge roles.
160
+ const edges = feed.edges.map(edge => this.buildEdgeDescription(feed, edge, addParameter));
161
+ // Allocate parameters for the conditional roles.
162
+ const satisfiableNotExistsConditions = feed.notExistsConditions.filter(condition => this.isSatisfiable(feed, condition.edges));
163
+ const notExistsConditions = satisfiableNotExistsConditions.map(condition => this.buildNotExistsConditionDescription(feed, condition, addParameter));
164
+ const outputs = feed.outputs.map(output => this.buildOutputDescription(feed, output));
165
+ return new QueryDescription(inputs, parameters, outputs, edges, notExistsConditions);
166
+ }
167
+ buildInputDescription(feed, input, addParameter) {
168
+ const fact = feed.facts.find(f => f.factIndex === input.factIndex);
169
+ if (!fact) {
170
+ throw new Error(`Fact not found: ${input.factIndex}`);
171
+ }
172
+ const factTypeId = (0, maps_1.getFactTypeId)(this.factTypes, fact.factType);
173
+ if (!factTypeId) {
174
+ throw new Error(`Fact type not found: ${fact.factType}`);
175
+ }
176
+ const factTypeParameter = addParameter(factTypeId);
177
+ const factHashParameter = addParameter(input.factHash);
178
+ return {
179
+ factIndex: input.factIndex,
180
+ factTypeId,
181
+ factTypeParameter,
182
+ factHash: input.factHash,
183
+ factHashParameter
184
+ };
185
+ }
186
+ buildEdgeDescription(feed, edge, addParameter) {
187
+ const fact = feed.facts.find(f => f.factIndex === edge.successorFactIndex);
188
+ if (!fact) {
189
+ throw new Error(`Fact not found: ${edge.successorFactIndex}`);
190
+ }
191
+ const factTypeId = (0, maps_1.getFactTypeId)(this.factTypes, fact.factType);
192
+ if (!factTypeId) {
193
+ throw new Error(`Fact type not found: ${fact.factType}`);
194
+ }
195
+ const roleId = (0, maps_1.getRoleId)(this.roleMap, factTypeId, edge.roleName);
196
+ if (!roleId) {
197
+ throw new Error(`Role not found: ${fact.factType}.${edge.roleName}`);
198
+ }
199
+ const roleParameter = addParameter(roleId);
200
+ return {
201
+ edgeIndex: edge.edgeIndex,
202
+ predecessorFactIndex: edge.predecessorFactIndex,
203
+ successorFactIndex: edge.successorFactIndex,
204
+ roleParameter
205
+ };
206
+ }
207
+ buildOutputDescription(feed, output) {
208
+ const fact = feed.facts.find(f => f.factIndex === output.factIndex);
209
+ if (!fact) {
210
+ throw new Error(`Fact not found: ${output.factIndex}`);
211
+ }
212
+ return {
213
+ factIndex: output.factIndex,
214
+ type: fact.factType
215
+ };
216
+ }
217
+ buildNotExistsConditionDescription(feed, condition, addParameter) {
218
+ const edges = condition.edges.map(edge => this.buildEdgeDescription(feed, edge, addParameter));
219
+ const notExistsConditions = condition.notExistsConditions.map(condition => this.buildNotExistsConditionDescription(feed, condition, addParameter));
220
+ return {
221
+ edges,
222
+ notExistsConditions
223
+ };
108
224
  }
109
225
  }
110
226
  function sqlFromSpecification(start, bookmarks, limit, specification, factTypes, roleMap) {
227
+ const feeds = (0, jinaga_1.buildFeeds)(start, specification);
111
228
  const descriptionBuilder = new DescriptionBuilder(factTypes, roleMap);
112
- const descriptions = descriptionBuilder.buildDescriptions(start, specification);
113
- // Only generate SQL for satisfiable queries.
114
- return descriptions
115
- .filter(description => description.isSatisfiable())
116
- .map(description => description.generateSqlQuery(bookmarks, limit));
229
+ const feedAndBookmark = feeds.map((feed, index) => ({
230
+ feed,
231
+ bookmark: bookmarks[index]
232
+ }));
233
+ const satisfiableFeedsAndBookmarks = feedAndBookmark.filter(fb => descriptionBuilder.isSatisfiable(fb.feed, fb.feed.edges));
234
+ const sqlQueries = satisfiableFeedsAndBookmarks.map(fb => {
235
+ const description = descriptionBuilder.buildDescription(fb.feed);
236
+ const sql = description.generateSqlQuery(fb.bookmark, limit);
237
+ return sql;
238
+ });
239
+ return sqlQueries;
117
240
  }
118
241
  exports.sqlFromSpecification = sqlFromSpecification;
242
+ function sqlFromFeed(feed, bookmark, limit, factTypes, roleMap) {
243
+ const descriptionBuilder = new DescriptionBuilder(factTypes, roleMap);
244
+ if (!descriptionBuilder.isSatisfiable(feed, feed.edges)) {
245
+ return null;
246
+ }
247
+ const description = descriptionBuilder.buildDescription(feed);
248
+ const sql = description.generateSqlQuery(bookmark, limit);
249
+ return sql;
250
+ }
251
+ exports.sqlFromFeed = sqlFromFeed;
119
252
  //# sourceMappingURL=specification-sql.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"specification-sql.js","sourceRoot":"","sources":["../../src/postgres/specification-sql.ts"],"names":[],"mappings":";;;AAEA,iCAA6D;AAC7D,2DAAiH;AACjH,2EAAsE;AAMtE,MAAM,kBAAmB,SAAQ,mDAAuB;IACpD,YACI,SAAsB,EACtB,OAAgB,IAChB,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB,iBAAiB,CAAC,KAAsB,EAAE,aAA4B;QACzE,oEAAoE;QACpE,IAAI,KAAK,CAAC,MAAM,KAAK,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE;YAC7C,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,MAAM,0CAA0C,aAAa,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;SACtI;QACD,yDAAyD;QACzD,KAAK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O,CAAC,CAAC;IACtE,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;QACrD,OAAO,IAAI,CAAC;KACf;IACD,MAAM,WAAW,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,WAAW,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,GAAG,CAAC;AACf,CAAC;AARD,kCAQC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jinaga-server",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Application-agnostic back end for web applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "express": "^4.18.1",
46
- "jinaga": "^4.0.1",
46
+ "jinaga": "^4.1.0",
47
47
  "node-forge": "^1.3.1",
48
48
  "passport": "^0.6.0",
49
49
  "pg": "^8.7.1"
@@ -3,6 +3,7 @@ import {
3
3
  FactEnvelope,
4
4
  FactRecord,
5
5
  FactReference,
6
+ Feed,
6
7
  Fork,
7
8
  LoginResponse,
8
9
  Observable,
@@ -10,6 +11,7 @@ import {
10
11
  Specification,
11
12
  UserIdentity,
12
13
  } from "jinaga";
14
+ import { FactFeed } from "jinaga/dist/storage";
13
15
 
14
16
  import { Keystore } from "../keystore";
15
17
  import { Authentication } from "./authentication";
@@ -50,6 +52,10 @@ export class AuthenticationDevice implements Authentication {
50
52
  return this.inner.read(start, specification);
51
53
  }
52
54
 
55
+ feed(feed: Feed, bookmark: string): Promise<FactFeed> {
56
+ return this.inner.feed(feed, bookmark);
57
+ }
58
+
53
59
  whichExist(references: FactReference[]): Promise<FactReference[]> {
54
60
  throw new Error("whichExist method not implemented on AuthenticationDevice.");
55
61
  }
@@ -1,4 +1,5 @@
1
- import { Channel, FactEnvelope, FactRecord, FactReference, Fork, Observable, Query, Specification, WebClient } from "jinaga";
1
+ import { Channel, FactEnvelope, FactRecord, FactReference, Feed, Fork, Observable, Query, Specification, WebClient } from "jinaga";
2
+ import { FactFeed } from "jinaga/dist/storage";
2
3
 
3
4
  import { Authentication } from "./authentication";
4
5
 
@@ -7,8 +8,6 @@ export class Principal {
7
8
  }
8
9
 
9
10
  export class AuthenticationImpl implements Authentication {
10
- private principal: Principal;
11
-
12
11
  constructor(private inner: Fork, private client: WebClient) {
13
12
  }
14
13
 
@@ -37,6 +36,10 @@ export class AuthenticationImpl implements Authentication {
37
36
  return this.inner.read(start, specification);
38
37
  }
39
38
 
39
+ feed(feed: Feed, bookmark: string): Promise<FactFeed> {
40
+ return this.inner.feed(feed, bookmark);
41
+ }
42
+
40
43
  whichExist(references: FactReference[]): Promise<FactReference[]> {
41
44
  throw new Error("whichExist method not implemented on AuthenticationImpl.");
42
45
  }
@@ -8,10 +8,12 @@ import {
8
8
  Feed,
9
9
  LoginResponse,
10
10
  Observable,
11
+ ObservableSource,
11
12
  Query,
12
13
  Specification,
13
14
  UserIdentity,
14
15
  } from "jinaga";
16
+ import { FactFeed } from "jinaga/dist/storage";
15
17
 
16
18
  import { Keystore } from "../keystore";
17
19
  import { Authentication } from "./authentication";
@@ -20,7 +22,7 @@ export class AuthenticationSession implements Authentication {
20
22
  private authorizationEngine: AuthorizationEngine | null;
21
23
 
22
24
  constructor(
23
- private inner: Feed,
25
+ private inner: ObservableSource,
24
26
  private keystore: Keystore,
25
27
  authorizationRules: AuthorizationRules | null,
26
28
  private userIdentity: UserIdentity,
@@ -65,7 +67,9 @@ export class AuthenticationSession implements Authentication {
65
67
  async save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]> {
66
68
  const userFact = await this.keystore.getUserFact(this.userIdentity);
67
69
  const facts = envelopes.map(envelope => envelope.fact);
68
- const authorizedFacts = await this.authorizationEngine.authorizeFacts(facts, userFact);
70
+ const authorizedFacts = this.authorizationEngine
71
+ ? await this.authorizationEngine.authorizeFacts(facts, userFact)
72
+ : facts;
69
73
  const signedFacts = await this.keystore.signFacts(this.userIdentity, authorizedFacts);
70
74
  return await this.inner.save(signedFacts);
71
75
  }
@@ -78,6 +82,10 @@ export class AuthenticationSession implements Authentication {
78
82
  return this.inner.read(start, specification);
79
83
  }
80
84
 
85
+ feed(feed: Feed, bookmark: string): Promise<FactFeed> {
86
+ return this.inner.feed(feed, bookmark);
87
+ }
88
+
81
89
  whichExist(references: FactReference[]): Promise<FactReference[]> {
82
90
  throw new Error("WhichExist method not implemented on AuthenticationSession.");
83
91
  }
@@ -87,7 +95,7 @@ export class AuthenticationSession implements Authentication {
87
95
  }
88
96
 
89
97
  addChannel(fact: FactReference, query: Query): Channel {
90
- return null;
98
+ return new Channel(async () => {});
91
99
  }
92
100
 
93
101
  removeChannel(channel: Channel): void {
@@ -1,13 +1,22 @@
1
- import { FactEnvelope, FactRecord, FactReference, Feed, Observable, Query, Specification, WebClient } from "jinaga";
1
+ import {
2
+ FactEnvelope,
3
+ FactRecord,
4
+ FactReference,
5
+ Feed,
6
+ Observable,
7
+ ObservableSource,
8
+ Query,
9
+ Specification,
10
+ WebClient,
11
+ } from "jinaga";
12
+ import { FactFeed } from "jinaga/dist/storage";
2
13
 
3
14
  export class Principal {
4
15
 
5
16
  }
6
17
 
7
- export class Authentication implements Feed {
8
- private principal: Principal;
9
-
10
- constructor(private inner: Feed, private client: WebClient) {
18
+ export class Authentication implements ObservableSource {
19
+ constructor(private inner: ObservableSource, private client: WebClient) {
11
20
  }
12
21
 
13
22
  async close(): Promise<void> {
@@ -31,6 +40,10 @@ export class Authentication implements Feed {
31
40
  return this.inner.read(start, specification);
32
41
  }
33
42
 
43
+ feed(feed: Feed, bookmark: string): Promise<FactFeed> {
44
+ return this.inner.feed(feed, bookmark);
45
+ }
46
+
34
47
  whichExist(references: FactReference[]): Promise<FactReference[]> {
35
48
  throw new Error("whichExist method not implemented on Authentication.");
36
49
  }
@@ -6,10 +6,12 @@ import {
6
6
  FactRecord,
7
7
  FactReference,
8
8
  Feed,
9
+ ObservableSource,
9
10
  Query,
10
11
  Specification,
11
12
  UserIdentity,
12
13
  } from "jinaga";
14
+ import { FactFeed } from "jinaga/dist/storage";
13
15
 
14
16
  import { Keystore } from "../keystore";
15
17
 
@@ -17,12 +19,12 @@ export class AuthorizationKeystore implements Authorization {
17
19
  private authorizationEngine: AuthorizationEngine | null;
18
20
 
19
21
  constructor(
20
- private feed: Feed,
22
+ private observableSource: ObservableSource,
21
23
  private keystore: Keystore,
22
24
  authorizationRules: AuthorizationRules | null) {
23
25
 
24
26
  this.authorizationEngine = authorizationRules &&
25
- new AuthorizationEngine(authorizationRules, feed);
27
+ new AuthorizationEngine(authorizationRules, observableSource);
26
28
  }
27
29
 
28
30
  async getOrCreateUserFact(userIdentity: UserIdentity) {
@@ -33,25 +35,29 @@ export class AuthorizationKeystore implements Authorization {
33
35
  signatures: []
34
36
  }
35
37
  ];
36
- await this.feed.save(envelopes);
38
+ await this.observableSource.save(envelopes);
37
39
  return userFact;
38
40
  }
39
41
 
40
42
  query(userIdentity: UserIdentity, start: FactReference, query: Query) {
41
- return this.feed.query(start, query);
43
+ return this.observableSource.query(start, query);
42
44
  }
43
45
 
44
46
  read(userIdentity: UserIdentity, start: FactReference[], specification: Specification) {
45
- return this.feed.read(start, specification);
47
+ return this.observableSource.read(start, specification);
48
+ }
49
+
50
+ feed(userIdentity: UserIdentity, feed: Feed, bookmark: string): Promise<FactFeed> {
51
+ return this.observableSource.feed(feed, bookmark);
46
52
  }
47
53
 
48
54
  load(userIdentity: UserIdentity, references: FactReference[]) {
49
- return this.feed.load(references);
55
+ return this.observableSource.load(references);
50
56
  }
51
57
 
52
58
  async save(userIdentity: UserIdentity, facts: FactRecord[]) {
53
59
  if (!this.authorizationEngine) {
54
- const envelopes = await this.feed.save(facts.map(fact => ({
60
+ const envelopes = await this.observableSource.save(facts.map(fact => ({
55
61
  fact,
56
62
  signatures: []
57
63
  })));
@@ -61,7 +67,7 @@ export class AuthorizationKeystore implements Authorization {
61
67
  const userFact = await this.keystore.getUserFact(userIdentity);
62
68
  const authorizedFacts = await this.authorizationEngine.authorizeFacts(facts, userFact);
63
69
  const signedFacts = await this.keystore.signFacts(userIdentity, authorizedFacts);
64
- const envelopes = await this.feed.save(signedFacts);
70
+ const envelopes = await this.observableSource.save(signedFacts);
65
71
  return envelopes.map(envelope => envelope.fact);
66
72
  }
67
73
  }
@@ -0,0 +1,6 @@
1
+ import { Feed } from "jinaga";
2
+
3
+ export interface FeedCache {
4
+ storeFeed(feedHash: string, feed: Feed): Promise<void>;
5
+ getFeed(feedHash: string): Promise<Feed | undefined>;
6
+ }