jinaga-server 3.5.5 → 3.7.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 (50) hide show
  1. package/dist/authorization/authorization-keystore.d.ts +34 -2
  2. package/dist/authorization/authorization-keystore.js +59 -4
  3. package/dist/authorization/authorization-keystore.js.map +1 -1
  4. package/dist/feeds/feed-stream-session.d.ts +84 -0
  5. package/dist/feeds/feed-stream-session.js +331 -0
  6. package/dist/feeds/feed-stream-session.js.map +1 -0
  7. package/dist/http/router.d.ts +10 -3
  8. package/dist/http/router.js +186 -184
  9. package/dist/http/router.js.map +1 -1
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.js +5 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/jinaga-server.d.ts +7 -0
  14. package/dist/jinaga-server.js +19 -2
  15. package/dist/jinaga-server.js.map +1 -1
  16. package/dist/memory/memory-keystore.js +1 -1
  17. package/dist/memory/memory-keystore.js.map +1 -1
  18. package/dist/postgres/query-description.d.ts +1 -0
  19. package/dist/postgres/query-description.js +34 -3
  20. package/dist/postgres/query-description.js.map +1 -1
  21. package/dist/postgres/specification-sql.js +7 -1
  22. package/dist/postgres/specification-sql.js.map +1 -1
  23. package/docs/design/feeds-persistent-proxy-plan.md +11 -1
  24. package/integration-test/jinaga-test/distribution-multi-given.test.js +184 -0
  25. package/integration-test/jinaga-test/distribution-negating-feed.test.js +202 -0
  26. package/integration-test/jinaga-test/feed-existential-input.test.js +241 -0
  27. package/integration-test/jinaga-test/feeds-endpoint.test.js +140 -0
  28. package/integration-test/jinaga-test/package-lock.json +4 -4
  29. package/integration-test/jinaga-test/package.json +3 -2
  30. package/integration-test/jinaga-test/subscription-anchor-arrival.test.js +129 -0
  31. package/integration-test/jinaga-test/subscription-helpers.js +60 -0
  32. package/integration-test/jinaga-test/subscription-late-auth.test.js +245 -0
  33. package/integration-test/jinaga-test/subscription-no-rule.test.js +137 -0
  34. package/package.json +2 -2
  35. package/src/authorization/authorization-keystore.ts +106 -5
  36. package/src/feeds/feed-stream-session.ts +386 -0
  37. package/src/http/router.ts +212 -237
  38. package/src/index.ts +2 -1
  39. package/src/jinaga-server.ts +45 -5
  40. package/src/memory/memory-keystore.ts +1 -1
  41. package/src/postgres/query-description.ts +66 -11
  42. package/src/postgres/specification-sql.ts +7 -1
  43. package/test/authorization/intermediateProjectionFeedSpec.ts +189 -0
  44. package/test/authorization/subscriptionIntersectionSpec.ts +220 -0
  45. package/test/feeds/feedStreamSessionRegressionSpec.ts +227 -0
  46. package/test/feeds/feedStreamSessionSpec.ts +351 -0
  47. package/test/http/anchorListenerSpec.ts +117 -0
  48. package/test/http/feedStreamSessionIntegrationSpec.ts +202 -0
  49. package/test/http/lateAuthRecoverySpec.ts +435 -0
  50. package/test/http/streamFeedAnchorSpec.ts +171 -0
@@ -1,6 +1,35 @@
1
- import { Authorization, AuthorizationRules, DistributionRules, FactEnvelope, FactFeed, FactManager, FactReference, ReferencesByName, Specification, Storage, UserIdentity } from "jinaga";
1
+ import { Authorization, AuthorizationRules, DistributionDenialCode, DistributionRules, FactEnvelope, FactFeed, FactManager, FactReference, ReferencesByName, Specification, Storage, UserIdentity } from "jinaga";
2
+ export interface DistributionIntersectionBranch {
3
+ start: FactReference[];
4
+ specification: Specification;
5
+ }
6
+ export interface DistributionDenial {
7
+ reason: string;
8
+ code: DistributionDenialCode;
9
+ }
10
+ export type DistributionBranchesResult = {
11
+ type: "success";
12
+ branches: DistributionIntersectionBranch[];
13
+ denial?: DistributionDenial;
14
+ } | {
15
+ type: "denied";
16
+ reason: string;
17
+ code: DistributionDenialCode;
18
+ };
19
+ export type FeedResult = {
20
+ type: "success";
21
+ feed: FactFeed;
22
+ } | {
23
+ type: "denied";
24
+ reason: string;
25
+ };
26
+ export interface SubscriptionAuthorizer {
27
+ verifyDistributionOrIntersect(userIdentity: UserIdentity | null, specification: Specification, namedStart: ReferencesByName): Promise<DistributionBranchesResult>;
28
+ feedPreVerified(userIdentity: UserIdentity | null, specification: Specification, start: FactReference[], bookmark: string): Promise<FactFeed>;
29
+ feedWithDistribution(userIdentity: UserIdentity | null, specification: Specification, start: FactReference[], bookmark: string): Promise<FeedResult>;
30
+ }
2
31
  import { Keystore } from "../keystore";
3
- export declare class AuthorizationKeystore implements Authorization {
32
+ export declare class AuthorizationKeystore implements Authorization, SubscriptionAuthorizer {
4
33
  private factManager;
5
34
  private store;
6
35
  private keystore;
@@ -11,7 +40,10 @@ export declare class AuthorizationKeystore implements Authorization {
11
40
  getOrCreateUserFact(userIdentity: UserIdentity): Promise<import("jinaga").FactRecord>;
12
41
  read(userIdentity: UserIdentity | null, start: FactReference[], specification: Specification): Promise<import("jinaga").ProjectedResult[]>;
13
42
  feed(userIdentity: UserIdentity | null, specification: Specification, start: FactReference[], bookmark: string): Promise<FactFeed>;
43
+ feedWithDistribution(userIdentity: UserIdentity | null, specification: Specification, start: FactReference[], bookmark: string): Promise<FeedResult>;
44
+ feedPreVerified(userIdentity: UserIdentity | null, specification: Specification, start: FactReference[], bookmark: string): Promise<FactFeed>;
14
45
  load(userIdentity: UserIdentity, references: FactReference[]): Promise<FactEnvelope[]>;
15
46
  save(userIdentity: UserIdentity | null, envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
16
47
  verifyDistribution(userIdentity: UserIdentity | null, feeds: Specification[], namedStart: ReferencesByName): Promise<void>;
48
+ verifyDistributionOrIntersect(userIdentity: UserIdentity | null, specification: Specification, namedStart: ReferencesByName): Promise<DistributionBranchesResult>;
17
49
  }
@@ -54,6 +54,15 @@ class AuthorizationKeystore {
54
54
  });
55
55
  }
56
56
  feed(userIdentity, specification, start, bookmark) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const result = yield this.feedWithDistribution(userIdentity, specification, start, bookmark);
59
+ if (result.type === "denied") {
60
+ throw new jinaga_1.Forbidden(result.reason);
61
+ }
62
+ return result.feed;
63
+ });
64
+ }
65
+ feedWithDistribution(userIdentity, specification, start, bookmark) {
57
66
  return __awaiter(this, void 0, void 0, function* () {
58
67
  if (this.distributionEngine) {
59
68
  const userReference = userIdentity
@@ -62,18 +71,36 @@ class AuthorizationKeystore {
62
71
  const namedStart = specification.given.reduce((map, g, index) => (Object.assign(Object.assign({}, map), { [g.label.name]: start[index] })), {});
63
72
  const canDistribute = yield this.distributionEngine.canDistributeToAll([specification], namedStart, userReference);
64
73
  if (canDistribute.type === "failure") {
65
- throw new jinaga_1.Forbidden(canDistribute.reason);
74
+ return { type: "denied", reason: canDistribute.reason };
66
75
  }
67
76
  const factFeed = yield this.store.feed(specification, start, bookmark);
68
77
  const factReferences = factFeed.tuples
69
78
  .flatMap(tuple => tuple.facts)
70
79
  .filter((value, index, self) => self.findIndex((0, jinaga_1.factReferenceEquals)(value)) === index);
71
80
  this.distributedFacts.add(factReferences, userReference);
72
- return factFeed;
81
+ return { type: "success", feed: factFeed };
73
82
  }
74
- else {
75
- return yield this.store.feed(specification, start, bookmark);
83
+ return { type: "success", feed: yield this.store.feed(specification, start, bookmark) };
84
+ });
85
+ }
86
+ feedPreVerified(userIdentity, specification, start, bookmark) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ // Caller has already established that this feed is safe to serve
89
+ // (e.g. produced by intersectForSubscribe — the spec lifts its own
90
+ // authorization condition into the matches and therefore self-
91
+ // filters). Skip the redundant per-query distribution check, but
92
+ // keep tracking the returned references so /load stays consistent.
93
+ const factFeed = yield this.store.feed(specification, start, bookmark);
94
+ if (this.distributionEngine) {
95
+ const userReference = userIdentity
96
+ ? yield this.keystore.getUserFact(userIdentity)
97
+ : null;
98
+ const factReferences = factFeed.tuples
99
+ .flatMap(tuple => tuple.facts)
100
+ .filter((value, index, self) => self.findIndex((0, jinaga_1.factReferenceEquals)(value)) === index);
101
+ this.distributedFacts.add(factReferences, userReference);
76
102
  }
103
+ return factFeed;
77
104
  });
78
105
  }
79
106
  load(userIdentity, references) {
@@ -150,6 +177,34 @@ class AuthorizationKeystore {
150
177
  }
151
178
  });
152
179
  }
180
+ verifyDistributionOrIntersect(userIdentity, specification, namedStart) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ const start = specification.given.map(g => namedStart[g.label.name]);
183
+ if (!this.distributionEngine) {
184
+ return { type: "success", branches: [{ start, specification }] };
185
+ }
186
+ const userReference = userIdentity
187
+ ? yield this.keystore.getUserFact(userIdentity)
188
+ : null;
189
+ const targetFeeds = (0, jinaga_1.buildFeeds)(specification);
190
+ const canDistribute = yield this.distributionEngine.canDistributeToAll(targetFeeds, namedStart, userReference);
191
+ if (canDistribute.type === "success") {
192
+ return { type: "success", branches: [{ start, specification }] };
193
+ }
194
+ // Preserve the structured engine failure so the caller can classify
195
+ // the feed (issue #168 S1). `canDistribute` is narrowed to a failure
196
+ // here, so `code`/`reason` are available.
197
+ const denial = { reason: canDistribute.reason, code: canDistribute.code };
198
+ const result = yield this.distributionEngine.intersectForSubscribe(start, specification, userReference);
199
+ if (!result.intersected) {
200
+ return { type: "denied", reason: denial.reason, code: denial.code };
201
+ }
202
+ // Authorized via intersection: the spec is denied for this user right
203
+ // now (denial carries why) but self-heals once the authorizing fact
204
+ // arrives. The router reports this as `reactive`.
205
+ return { type: "success", branches: result.branches, denial };
206
+ });
207
+ }
153
208
  }
154
209
  exports.AuthorizationKeystore = AuthorizationKeystore;
155
210
  //# sourceMappingURL=authorization-keystore.js.map
@@ -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,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AAM,EAAE,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC;YAC9F,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;YACxG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;gBACrB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;aACvE;YACD,sEAAsE;YACtE,oEAAoE;YACpE,kDAAkD;YAClD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QAClE,CAAC;KAAA;CACJ;AAzMD,sDAyMC"}
@@ -0,0 +1,84 @@
1
+ import { FactManager, FactReference, FeedObject, FeedResponse } from "jinaga";
2
+ import { FeedResult } from "../authorization/authorization-keystore";
3
+ import { Stream } from "../http/stream";
4
+ /**
5
+ * A function that queries the feed for the next page of tuples, starting
6
+ * from the supplied bookmark. Returns a {@link FeedResult} so the session
7
+ * can keep the stream alive when distribution is denied at query time.
8
+ */
9
+ export type FeedQuery = (bookmark: string) => Promise<FeedResult>;
10
+ export interface FeedStreamSessionConfig {
11
+ /** Maximum number of pages to stream before giving up (infinite-loop guard). */
12
+ maxInitialPages: number;
13
+ /** Maximum number of references the waitlist may hold before the stream is dropped. */
14
+ waitlistCap: number;
15
+ /** Insert a small delay every N pages to avoid overwhelming the database. */
16
+ pageDelayEvery: number;
17
+ /** Length of the delay inserted by {@link pageDelayEvery}, in milliseconds. */
18
+ pageDelayMs: number;
19
+ }
20
+ export declare const defaultFeedStreamSessionConfig: FeedStreamSessionConfig;
21
+ /**
22
+ * Per-connection proxy for a streaming feed subscription.
23
+ *
24
+ * The session funnels every fetch and stream operation through a single
25
+ * "query cycle" driven by the current bookmark. Inverse observers never
26
+ * fetch or stream directly; they only enqueue fact references onto a
27
+ * waitlist and wake the cycle. This serialization removes the race between
28
+ * listener callbacks and bookmark mutation, guarantees tuple completeness,
29
+ * and ensures no update is lost when facts arrive between pages.
30
+ *
31
+ * See docs/design/feeds-persistent-proxy-plan.md for the full design.
32
+ */
33
+ export declare class FeedStreamSession {
34
+ private readonly query;
35
+ private readonly factManager;
36
+ private readonly feedDefinition;
37
+ private readonly startReferences;
38
+ private readonly givenHash;
39
+ private readonly stream;
40
+ private readonly connectionId;
41
+ private bookmark;
42
+ private readonly config;
43
+ private readonly waitlist;
44
+ private activeCycle;
45
+ private needsCycle;
46
+ private shuttingDown;
47
+ private listeners;
48
+ private readonly telemetry;
49
+ constructor(query: FeedQuery, factManager: FactManager, feedDefinition: FeedObject, startReferences: FactReference[], givenHash: string, stream: Stream<FeedResponse>, initialBookmark: string, connectionId?: string, config?: Partial<FeedStreamSessionConfig>);
50
+ /** Current number of references on the waitlist (observability/testing). */
51
+ get waitlistSize(): number;
52
+ /**
53
+ * Register inverse and anchor observers, then kick off the initial
54
+ * paginated backfill. Resolves once the observers are registered; the
55
+ * cycle continues to run asynchronously, feeding the stream.
56
+ */
57
+ start(): void;
58
+ /**
59
+ * Tear down all observers and prevent any further cycles. Idempotent.
60
+ */
61
+ dispose(): void;
62
+ /**
63
+ * Add fact references to the waitlist and wake the cycle. Called by the
64
+ * inverse observers; never fetches or streams directly.
65
+ */
66
+ onInverseMatch(references: FactReference[]): void;
67
+ /**
68
+ * Start a cycle if one is not already running. If a cycle is active,
69
+ * mark that another pass is needed once it completes.
70
+ */
71
+ private wake;
72
+ /**
73
+ * The single serialized query cycle. Pages through the feed until both
74
+ * the query returns no tuples and the waitlist is empty, then emits a
75
+ * SYNC frame. Guarded by activeCycle so no two cycles run concurrently.
76
+ */
77
+ private runCycle;
78
+ private streamPage;
79
+ private streamSync;
80
+ private removeFromWaitlist;
81
+ private delay;
82
+ private registerInverseListeners;
83
+ private registerAnchorListeners;
84
+ }
@@ -0,0 +1,331 @@
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.FeedStreamSession = exports.defaultFeedStreamSessionConfig = void 0;
13
+ const jinaga_1 = require("jinaga");
14
+ exports.defaultFeedStreamSessionConfig = {
15
+ maxInitialPages: 1000,
16
+ waitlistCap: 50000,
17
+ pageDelayEvery: 10,
18
+ pageDelayMs: 10
19
+ };
20
+ function referenceKey(reference) {
21
+ return `${reference.type}:${reference.hash}`;
22
+ }
23
+ function dedupeReferences(references) {
24
+ const seen = new Set();
25
+ const result = [];
26
+ for (const reference of references) {
27
+ const key = referenceKey(reference);
28
+ if (!seen.has(key)) {
29
+ seen.add(key);
30
+ result.push(reference);
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ /**
36
+ * Per-connection proxy for a streaming feed subscription.
37
+ *
38
+ * The session funnels every fetch and stream operation through a single
39
+ * "query cycle" driven by the current bookmark. Inverse observers never
40
+ * fetch or stream directly; they only enqueue fact references onto a
41
+ * waitlist and wake the cycle. This serialization removes the race between
42
+ * listener callbacks and bookmark mutation, guarantees tuple completeness,
43
+ * and ensures no update is lost when facts arrive between pages.
44
+ *
45
+ * See docs/design/feeds-persistent-proxy-plan.md for the full design.
46
+ */
47
+ class FeedStreamSession {
48
+ constructor(query, factManager, feedDefinition, startReferences, givenHash, stream, initialBookmark, connectionId = Math.random().toString(36).substring(2, 10), config = {}) {
49
+ this.query = query;
50
+ this.factManager = factManager;
51
+ this.feedDefinition = feedDefinition;
52
+ this.startReferences = startReferences;
53
+ this.givenHash = givenHash;
54
+ this.stream = stream;
55
+ this.connectionId = connectionId;
56
+ // Waitlist of fact references surfaced by inverse observers, keyed by
57
+ // "{type}:{hash}" so duplicates collapse. A reference stays on the
58
+ // waitlist until the tuple that contains it is streamed, preserving
59
+ // tuple completeness.
60
+ this.waitlist = new Map();
61
+ // Single-cycle execution guard. Only one runCycle() executes at a time;
62
+ // wake-ups that arrive while a cycle runs set needsCycle so the loop
63
+ // re-evaluates before returning.
64
+ this.activeCycle = false;
65
+ this.needsCycle = false;
66
+ this.shuttingDown = false;
67
+ this.listeners = [];
68
+ this.telemetry = {
69
+ initialPages: 0,
70
+ referencesStreamed: 0,
71
+ cycles: 0,
72
+ syncFrames: 0,
73
+ waitlistRestarts: 0,
74
+ waitlistHighWater: 0
75
+ };
76
+ this.bookmark = initialBookmark;
77
+ this.config = Object.assign(Object.assign({}, exports.defaultFeedStreamSessionConfig), config);
78
+ }
79
+ /** Current number of references on the waitlist (observability/testing). */
80
+ get waitlistSize() {
81
+ return this.waitlist.size;
82
+ }
83
+ /**
84
+ * Register inverse and anchor observers, then kick off the initial
85
+ * paginated backfill. Resolves once the observers are registered; the
86
+ * cycle continues to run asynchronously, feeding the stream.
87
+ */
88
+ start() {
89
+ this.registerInverseListeners();
90
+ this.registerAnchorListeners();
91
+ // Kick off the initial backfill. Errors are isolated so a failed
92
+ // cycle never rejects the caller's setup path.
93
+ this.wake();
94
+ }
95
+ /**
96
+ * Tear down all observers and prevent any further cycles. Idempotent.
97
+ */
98
+ dispose() {
99
+ if (this.shuttingDown) {
100
+ return;
101
+ }
102
+ this.shuttingDown = true;
103
+ for (const listener of this.listeners) {
104
+ try {
105
+ this.factManager.removeSpecificationListener(listener);
106
+ }
107
+ catch (error) {
108
+ jinaga_1.Trace.error(error);
109
+ }
110
+ }
111
+ this.listeners = [];
112
+ // Use a stable metric name so a metrics backend does not see
113
+ // unbounded cardinality from per-connection IDs. The connection ID
114
+ // is logged separately for correlation.
115
+ jinaga_1.Trace.info(`Feed stream session ${this.connectionId} closed`);
116
+ jinaga_1.Trace.metric("Feed stream session closed", {
117
+ initialPages: this.telemetry.initialPages,
118
+ referencesStreamed: this.telemetry.referencesStreamed,
119
+ cycles: this.telemetry.cycles,
120
+ syncFrames: this.telemetry.syncFrames,
121
+ waitlistRestarts: this.telemetry.waitlistRestarts,
122
+ waitlistHighWater: this.telemetry.waitlistHighWater
123
+ });
124
+ }
125
+ /**
126
+ * Add fact references to the waitlist and wake the cycle. Called by the
127
+ * inverse observers; never fetches or streams directly.
128
+ */
129
+ onInverseMatch(references) {
130
+ if (this.shuttingDown) {
131
+ return;
132
+ }
133
+ for (const reference of references) {
134
+ this.waitlist.set(referenceKey(reference), reference);
135
+ }
136
+ if (this.waitlist.size > this.telemetry.waitlistHighWater) {
137
+ this.telemetry.waitlistHighWater = this.waitlist.size;
138
+ }
139
+ if (this.waitlist.size > this.config.waitlistCap) {
140
+ jinaga_1.Trace.warn(`Feed stream session ${this.connectionId} waitlist exceeded cap ` +
141
+ `(${this.waitlist.size} > ${this.config.waitlistCap}); closing stream.`);
142
+ this.dispose();
143
+ this.stream.close();
144
+ return;
145
+ }
146
+ this.wake();
147
+ }
148
+ /**
149
+ * Start a cycle if one is not already running. If a cycle is active,
150
+ * mark that another pass is needed once it completes.
151
+ */
152
+ wake() {
153
+ if (this.shuttingDown) {
154
+ return;
155
+ }
156
+ if (this.activeCycle) {
157
+ this.needsCycle = true;
158
+ return;
159
+ }
160
+ // Run the cycle without awaiting; isolate failures.
161
+ void this.runCycle().catch(error => jinaga_1.Trace.error(error));
162
+ }
163
+ /**
164
+ * The single serialized query cycle. Pages through the feed until both
165
+ * the query returns no tuples and the waitlist is empty, then emits a
166
+ * SYNC frame. Guarded by activeCycle so no two cycles run concurrently.
167
+ */
168
+ runCycle() {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ if (this.activeCycle) {
171
+ this.needsCycle = true;
172
+ return;
173
+ }
174
+ this.activeCycle = true;
175
+ this.telemetry.cycles++;
176
+ try {
177
+ let pagesThisCycle = 0;
178
+ let keepGoing = true;
179
+ while (keepGoing && !this.shuttingDown) {
180
+ this.needsCycle = false;
181
+ const result = yield this.query(this.bookmark);
182
+ if (this.shuttingDown) {
183
+ break;
184
+ }
185
+ if (result.type === "denied") {
186
+ // Distribution denied at query time. Keep the stream
187
+ // alive (an authorizing fact may arrive later and wake a
188
+ // new cycle) but stop the loop without emitting SYNC,
189
+ // since we are not actually caught up.
190
+ jinaga_1.Trace.info(`Feed stream session ${this.connectionId} query denied: ${result.reason}`);
191
+ break;
192
+ }
193
+ const feed = result.feed;
194
+ if (feed.tuples.length > 0) {
195
+ const references = dedupeReferences(feed.tuples.flatMap(t => t.facts));
196
+ this.streamPage(references, feed.bookmark);
197
+ this.removeFromWaitlist(references);
198
+ pagesThisCycle++;
199
+ this.telemetry.initialPages++;
200
+ if (feed.bookmark === this.bookmark) {
201
+ // The store returned results but the bookmark did not
202
+ // advance, meaning it cannot paginate further (e.g.
203
+ // MemoryStore returns the full result set on every
204
+ // call). Everything available has been delivered, so
205
+ // treat this as caught-up: drop any waitlist entries
206
+ // that the full page did not satisfy and emit SYNC.
207
+ // Re-querying with the same bookmark would loop
208
+ // forever re-delivering identical tuples.
209
+ this.waitlist.clear();
210
+ this.streamSync();
211
+ keepGoing = false;
212
+ }
213
+ else {
214
+ this.bookmark = feed.bookmark;
215
+ if (pagesThisCycle >= this.config.maxInitialPages) {
216
+ jinaga_1.Trace.warn(`Feed stream session ${this.connectionId} hit max page limit ` +
217
+ `(${this.config.maxInitialPages}); ending cycle.`);
218
+ break;
219
+ }
220
+ if (this.config.pageDelayEvery > 0 &&
221
+ pagesThisCycle % this.config.pageDelayEvery === 0) {
222
+ yield this.delay(this.config.pageDelayMs);
223
+ }
224
+ // Continue paging.
225
+ }
226
+ }
227
+ else {
228
+ // No tuples this query.
229
+ if (this.waitlist.size === 0) {
230
+ this.streamSync();
231
+ keepGoing = false;
232
+ }
233
+ else if (this.needsCycle) {
234
+ // A wake arrived during this query; re-run so the
235
+ // just-arrived facts get a chance to produce tuples.
236
+ this.telemetry.waitlistRestarts++;
237
+ }
238
+ else {
239
+ // The waitlist holds references whose tuples are not
240
+ // completable at the current bookmark (e.g. a missing
241
+ // predecessor). They cannot produce a tuple now, so
242
+ // drop them to avoid spinning and emit SYNC. A later
243
+ // trigger will re-add them once they are completable.
244
+ this.waitlist.clear();
245
+ this.streamSync();
246
+ keepGoing = false;
247
+ }
248
+ }
249
+ }
250
+ }
251
+ finally {
252
+ this.activeCycle = false;
253
+ // A wake that arrived as the loop exited must start a fresh
254
+ // cycle, since this one already cleared activeCycle.
255
+ if (this.needsCycle && !this.shuttingDown) {
256
+ this.needsCycle = false;
257
+ this.wake();
258
+ }
259
+ }
260
+ });
261
+ }
262
+ streamPage(references, bookmark) {
263
+ const response = { references, bookmark };
264
+ this.telemetry.referencesStreamed += references.length;
265
+ this.stream.feed(response);
266
+ }
267
+ streamSync() {
268
+ const response = { references: [], bookmark: this.bookmark };
269
+ this.telemetry.syncFrames++;
270
+ this.stream.feed(response);
271
+ }
272
+ removeFromWaitlist(references) {
273
+ for (const reference of references) {
274
+ this.waitlist.delete(referenceKey(reference));
275
+ }
276
+ }
277
+ delay(ms) {
278
+ return new Promise(resolve => setTimeout(resolve, ms));
279
+ }
280
+ registerInverseListeners() {
281
+ const inverses = (0, jinaga_1.invertSpecification)(this.feedDefinition.feed);
282
+ for (const inverse of inverses) {
283
+ const listener = this.factManager.addSpecificationListener(inverse.inverseSpecification, (results) => __awaiter(this, void 0, void 0, function* () {
284
+ if (this.shuttingDown) {
285
+ return;
286
+ }
287
+ // Only enqueue results whose given subset matches this
288
+ // subscription's given.
289
+ const matching = results.filter(pr => this.givenHash === (0, jinaga_1.computeTupleSubsetHash)(pr.tuple, inverse.givenSubset));
290
+ if (matching.length === 0) {
291
+ return;
292
+ }
293
+ const references = dedupeReferences(matching.flatMap(pr => Object.values(pr.tuple)));
294
+ this.onInverseMatch(references);
295
+ }));
296
+ this.listeners.push(listener);
297
+ }
298
+ }
299
+ registerAnchorListeners() {
300
+ // Anchor listeners (jinaga.js#129): the inverse-listener path only
301
+ // fires when a descendant of the given arrives. If the given fact
302
+ // itself isn't yet in the store when the client subscribes, no
303
+ // inverse can deliver results until the given is recorded. Register
304
+ // a listener per unique anchor that wakes the cycle the moment a
305
+ // saved fact matches the anchor's (type, hash). The anchor itself is
306
+ // not added to the waitlist; the query will surface its descendants.
307
+ const uniqueAnchors = this.startReferences.filter((s, i, arr) => arr.findIndex(other => other.type === s.type && other.hash === s.hash) === i);
308
+ for (const anchor of uniqueAnchors) {
309
+ const anchorSpec = {
310
+ given: [{ label: { name: "x", type: anchor.type }, conditions: [] }],
311
+ matches: [],
312
+ projection: { type: "fact", label: "x" }
313
+ };
314
+ const listener = this.factManager.addSpecificationListener(anchorSpec, (results) => __awaiter(this, void 0, void 0, function* () {
315
+ if (this.shuttingDown) {
316
+ return;
317
+ }
318
+ const matched = results.some(pr => {
319
+ const ref = pr.tuple && pr.tuple.x;
320
+ return ref && ref.type === anchor.type && ref.hash === anchor.hash;
321
+ });
322
+ if (matched) {
323
+ this.wake();
324
+ }
325
+ }));
326
+ this.listeners.push(listener);
327
+ }
328
+ }
329
+ }
330
+ exports.FeedStreamSession = FeedStreamSession;
331
+ //# sourceMappingURL=feed-stream-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed-stream-session.js","sourceRoot":"","sources":["../../src/feeds/feed-stream-session.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAWgB;AAsBH,QAAA,8BAA8B,GAA4B;IACnE,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,KAAK;IAClB,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;CAClB,CAAC;AAWF,SAAS,YAAY,CAAC,SAAwB;IAC1C,OAAO,GAAG,SAAS,CAAC,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CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE;YAChC,MAAM,UAAU,GAAkB;gBAC9B,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;gBACpE,OAAO,EAAE,EAAE;gBACX,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE;aAC3C,CAAC;YACF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,wBAAwB,CAAC,UAAU,EAAE,CAAO,OAA0B,EAAE,EAAE;gBACxG,IAAI,IAAI,CAAC,YAAY,EAAE;oBACnB,OAAO;iBACV;gBACD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBAC9B,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,IAAK,EAAE,CAAC,KAAa,CAAC,CAAC,CAAC;oBAC5C,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC;gBACvE,CAAC,CAAC,CAAC;gBACH,IAAI,OAAO,EAAE;oBACT,IAAI,CAAC,IAAI,EAAE,CAAC;iBACf;YACL,CAAC,CAAA,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;IACL,CAAC;CACJ;AAnTD,8CAmTC"}
@@ -1,5 +1,7 @@
1
1
  import { Handler } from "express";
2
2
  import { Authorization, FactManager, FeedCache, ProfileMessage } from "jinaga";
3
+ import { SubscriptionAuthorizer } from "../authorization/authorization-keystore";
4
+ import { FeedStreamSessionConfig } from "../feeds/feed-stream-session";
3
5
  export interface RequestUser {
4
6
  provider: string;
5
7
  id: string;
@@ -10,8 +12,10 @@ export declare class HttpRouter {
10
12
  private authorization;
11
13
  private feedCache;
12
14
  private allowedOrigin;
15
+ private feedStreamConfig;
13
16
  handler: Handler;
14
- constructor(factManager: FactManager, authorization: Authorization, feedCache: FeedCache, allowedOrigin: string | string[] | ((origin: string, callback: (err: Error | null, allow?: boolean) => void) => void));
17
+ private intersectedFeedOwners;
18
+ constructor(factManager: FactManager, authorization: Authorization & SubscriptionAuthorizer, feedCache: FeedCache, allowedOrigin: string | string[] | ((origin: string, callback: (err: Error | null, allow?: boolean) => void) => void), feedStreamConfig?: Partial<FeedStreamSessionConfig>);
15
19
  private login;
16
20
  private load;
17
21
  private save;
@@ -24,12 +28,15 @@ export declare class HttpRouter {
24
28
  private readWithStreaming;
25
29
  private write;
26
30
  private feeds;
31
+ private queryFeed;
27
32
  private feed;
28
33
  private streamFeed;
29
- private streamAllInitialResults;
30
- private streamFeedResponse;
31
34
  private getKnownFacts;
32
35
  private selectStart;
33
36
  private setOptions;
34
37
  private applyAllowOrigin;
35
38
  }
39
+ export declare class FeedNotFound extends Error {
40
+ readonly feedHash: string;
41
+ constructor(feedHash: string);
42
+ }