@procedures/client 0.15.0 → 0.15.1

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 (59) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapters/http/server/handler.d.ts.map +1 -1
  4. package/dist/adapters/http/server/handler.js +5 -3
  5. package/dist/adapters/http/server/handler.js.map +1 -1
  6. package/dist/browser.d.ts +2 -1
  7. package/dist/browser.d.ts.map +1 -1
  8. package/dist/browser.js.map +1 -1
  9. package/dist/client/errors/registry.d.ts.map +1 -1
  10. package/dist/client/errors/registry.js +12 -0
  11. package/dist/client/errors/registry.js.map +1 -1
  12. package/dist/client/middleware/rate-limit.d.ts +17 -0
  13. package/dist/client/middleware/rate-limit.d.ts.map +1 -1
  14. package/dist/client/middleware/rate-limit.js +94 -39
  15. package/dist/client/middleware/rate-limit.js.map +1 -1
  16. package/dist/events/index.d.ts +1 -0
  17. package/dist/events/index.d.ts.map +1 -1
  18. package/dist/events/index.js.map +1 -1
  19. package/dist/events/publisher.d.ts +46 -1
  20. package/dist/events/publisher.d.ts.map +1 -1
  21. package/dist/events/publisher.js +95 -5
  22. package/dist/events/publisher.js.map +1 -1
  23. package/dist/events/recheck.d.ts +84 -0
  24. package/dist/events/recheck.d.ts.map +1 -0
  25. package/dist/events/recheck.js +135 -0
  26. package/dist/events/recheck.js.map +1 -0
  27. package/dist/protocol.d.ts +1 -1
  28. package/dist/protocol.d.ts.map +1 -1
  29. package/dist/protocol.js +1 -0
  30. package/dist/protocol.js.map +1 -1
  31. package/dist/server/host-policy.d.ts +17 -0
  32. package/dist/server/host-policy.d.ts.map +1 -1
  33. package/dist/server/host-policy.js +7 -0
  34. package/dist/server/host-policy.js.map +1 -1
  35. package/dist/server/limits.d.ts +122 -0
  36. package/dist/server/limits.d.ts.map +1 -0
  37. package/dist/server/limits.js +153 -0
  38. package/dist/server/limits.js.map +1 -0
  39. package/dist/server/procedure-server.d.ts +31 -1
  40. package/dist/server/procedure-server.d.ts.map +1 -1
  41. package/dist/server/procedure-server.js +38 -2
  42. package/dist/server/procedure-server.js.map +1 -1
  43. package/dist/server/request-auth.d.ts +5 -1
  44. package/dist/server/request-auth.d.ts.map +1 -1
  45. package/dist/server/request-auth.js +19 -2
  46. package/dist/server/request-auth.js.map +1 -1
  47. package/package.json +3 -3
  48. package/src/adapters/http/server/handler.ts +5 -3
  49. package/src/browser.ts +4 -0
  50. package/src/client/errors/registry.ts +13 -0
  51. package/src/client/middleware/rate-limit.ts +116 -41
  52. package/src/events/index.ts +1 -0
  53. package/src/events/publisher.ts +116 -6
  54. package/src/events/recheck.ts +182 -0
  55. package/src/protocol.ts +3 -1
  56. package/src/server/host-policy.ts +22 -0
  57. package/src/server/limits.ts +254 -0
  58. package/src/server/procedure-server.ts +55 -3
  59. package/src/server/request-auth.ts +19 -2
@@ -32,6 +32,7 @@ export { DefaultEventBus } from "./bus.js";
32
32
  export { createEventBus, createTypedEventBus, getGlobalEventBus, resetGlobalEventBus, withEventBusSignal, } from "./bus.js";
33
33
  export { EventPublisher, topicMatcher, MAX_SUBSCRIPTION_TOPICS, MAX_TOPIC_LENGTH } from "./publisher.js";
34
34
  export type { EventPublisherOptions, TopicRule, TopicCall } from "./publisher.js";
35
+ export type { RightsChange, SubscriptionRecheck } from "./recheck.js";
35
36
  export { EVENTS_SUBSCRIBE_PATH, SubscriptionError, remoteEvents, subscribeRemote } from "./remote.js";
36
37
  export type { EventItem, EventTransport, RemoteEvent, RemoteEventHandler, RemoteEventsOptions, ResubscribeBackoff, SubscribeInput, SubscribeOptions, Subscription, SubscriptionHooks, } from "./remote.js";
37
38
  export { createChannelPrefix, forwardChannel, mergeChannels, filterChannel, mapChannel, debounceChannel, throttleChannel, } from "./bus.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,YAAY,EACV,KAAK,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACzG,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtG,YAAY,EACV,SAAS,EACT,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,YAAY,EACV,KAAK,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,YAAY,CAAC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AO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AActG,YAAY;AACZ,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,GAChB,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAkBH,iBAAiB;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,oBAAoB;AACpB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,4FAA4F;AAC5F,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGzG,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AActG,YAAY;AACZ,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,GAChB,MAAM,UAAU,CAAC"}
@@ -18,6 +18,8 @@
18
18
  *
19
19
  * - A value with rows (`withRows()`) reaches each subscriber through the output filter of its host
20
20
  * (`ctx.admit`): each row passes the filter, and the subscriber gets only the admitted rows.
21
+ * - An open subscription gets the same checks again at a change of the rights (`rightsChanged()`,
22
+ * `recheck.rightsChanges`) and after `recheck.maxAge` (roadmap CLI-44). A refusal ends it.
21
23
  *
22
24
  * The delivery is at most once. The queue of a subscription holds at most `buffer` events. When
23
25
  * it is full, the publisher drops the oldest event, and the next event tells the number of lost
@@ -26,6 +28,8 @@
26
28
  import type { AnyProcedure, Capability } from "../procedures/types.js";
27
29
  import type { Principal } from "../server/types.js";
28
30
  import type { EventBus } from "./types.js";
31
+ import { type Clock } from "../clock.js";
32
+ import { type RightsChange, type SubscriptionRecheck } from "./recheck.js";
29
33
  /** The number of topics that one subscription can name. */
30
34
  export declare const MAX_SUBSCRIPTION_TOPICS = 64;
31
35
  /** The number of characters of a topic name. */
@@ -58,7 +62,8 @@ export interface EventPublisherOptions {
58
62
  allow?: ((topic: string, call: TopicCall) => boolean) | undefined;
59
63
  /**
60
64
  * The number of events that one subscription holds for a slow subscriber. When the queue is
61
- * full, the publisher drops the oldest event.
65
+ * full, the publisher drops the oldest event. The events that wait for a re-check (roadmap
66
+ * CLI-44) are in the same queue, so a slow check holds at most this number of events too.
62
67
  * @default 1024
63
68
  */
64
69
  buffer?: number | undefined;
@@ -74,6 +79,23 @@ export interface EventPublisherOptions {
74
79
  * @default the read of the collection of `collectionTopicTarget()`, with the repository of the call
75
80
  */
76
81
  reads?: ((topic: string) => readonly string[]) | undefined;
82
+ /**
83
+ * The clock of the re-check after `recheck.maxAge` (roadmap CLI-44). A test gives the
84
+ * `fakeClock` of `@mark1russell7/service/testing`. A `ProcedureServer` gives its own clock to the
85
+ * publisher that it makes from its option `events`.
86
+ * @default the clock of the platform
87
+ */
88
+ clock?: Clock | undefined;
89
+ /**
90
+ * The re-check of the admission of each open subscription (roadmap CLI-44). A right can change
91
+ * after the start of a subscription. The publisher then examines the subscription again with the
92
+ * same checks: the topic rule, the reads, `allow` and the partition. A refusal ends it, for
93
+ * example with `FORBIDDEN`. `maxAge` starts a check after a time on the clock, and
94
+ * `rightsChanges` starts a check at each change from a source of the app. `rightsChanged()` also
95
+ * starts a check.
96
+ * @default no check after the start, other than at a call of `rightsChanged()`
97
+ */
98
+ recheck?: SubscriptionRecheck | undefined;
77
99
  }
78
100
  /** This function gives the test of a topic rule. */
79
101
  export declare function topicMatcher(rule: TopicRule): (topic: string) => boolean;
@@ -100,6 +122,8 @@ export declare class EventPublisher {
100
122
  private readonly defaultReads;
101
123
  private readonly buffer;
102
124
  private readonly open;
125
+ /** The re-checks of the admission of the open subscriptions (roadmap CLI-44) */
126
+ private readonly rechecks;
103
127
  constructor(options: EventPublisherOptions);
104
128
  /** This function publishes an event on the bus: each subscription of the topic gets it. */
105
129
  publish<T>(topic: string, data: T): void;
@@ -110,6 +134,15 @@ export declare class EventPublisher {
110
134
  * A subscriber resubscribes after its backoff. `ProcedureServer.stop()` calls it first.
111
135
  */
112
136
  end(): void;
137
+ /**
138
+ * This function tells the publisher that rights changed (roadmap CLI-44). Each open subscription
139
+ * that the change touches gets the checks of its start again: the topic rule, the reads, `allow`
140
+ * and the partition. Its events wait for the check. A refusal ends the subscription with its
141
+ * error, for example `FORBIDDEN`. The promise ends when each check ends, and it does not reject.
142
+ *
143
+ * @param change - The subscriptions that the change touches. Without it, each open subscription gets a check.
144
+ */
145
+ rightsChanged(change?: RightsChange): Promise<void>;
113
146
  /**
114
147
  * The topic of the bus for a topic of a subscriber (roadmap CLI-17). A topic of a partitioned
115
148
  * collection names the partition that the subscriber asks for, as the input of a procedure does:
@@ -123,6 +156,18 @@ export declare class EventPublisher {
123
156
  * listener name the same collection.
124
157
  */
125
158
  private readsOf;
159
+ /**
160
+ * The checks of the topics of a call: the topic rule, the reads of the capability and `allow`.
161
+ * A subscription passes them at its start and at each re-check (roadmap CLI-44).
162
+ */
163
+ private admitTopics;
164
+ /**
165
+ * The admission of an open subscription again (roadmap CLI-44): the checks of its start, and the
166
+ * partition of each topic. A refusal of the resolver throws its error. A topic whose partition
167
+ * changed throws `FORBIDDEN` (reason `partition-not-allowed`), because the listener has the old
168
+ * partition.
169
+ */
170
+ private readmit;
126
171
  /**
127
172
  * The stream of one subscription. The publisher examines each topic before it adds a listener:
128
173
  * the topic rule, the reads, `allow`, and the partition. A call with one bad topic makes no subscription.
@@ -1 +1 @@
1
- {"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/events/publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAQH,O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,KAAK,EAAE,MAAM,KAAK,OAAO,CAWxE;AA8OD;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IACzB,2CAA2C;IAC3C,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;IACvB,gGAAgG;IAChG,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAC7D,0FAA0F;IAC1F,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgC;IACrD,gFAAgF;IAChF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAEhD,YAAY,OAAO,EAAE,qBAAqB,EAmBzC;IAED,2FAA2F;IAC3F,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAEvC;IAED,wCAAwC;IACxC,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;OAGG;IACH,GAAG,IAAI,IAAI,CAEV;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAED;;;;;OAKG;YACW,QAAQ;IAOtB;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAMf;;;OAGG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;;;OAKG;YACW,OAAO;IASrB;;;OAGG;YACW,SAAS;CAWxB"}
@@ -18,6 +18,8 @@
18
18
  *
19
19
  * - A value with rows (`withRows()`) reaches each subscriber through the output filter of its host
20
20
  * (`ctx.admit`): each row passes the filter, and the subscriber gets only the admitted rows.
21
+ * - An open subscription gets the same checks again at a change of the rights (`rightsChanged()`,
22
+ * `recheck.rightsChanges`) and after `recheck.maxAge` (roadmap CLI-44). A refusal ends it.
21
23
  *
22
24
  * The delivery is at most once. The queue of a subscription holds at most `buffer` events. When
23
25
  * it is full, the publisher drops the oldest event, and the next event tells the number of lost
@@ -32,6 +34,8 @@ import { collectionTopicTarget, partitionOfCall } from "../procedures/collection
32
34
  import { getGlobalEventBus } from "./bus.js";
33
35
  import { EVENTS_SUBSCRIBE_PATH } from "./remote.js";
34
36
  import { admittedValue, rowsOf } from "./rows.js";
37
+ import { realClock } from "../clock.js";
38
+ import { SubscriptionRechecks } from "./recheck.js";
35
39
  /** The number of topics that one subscription can name. */
36
40
  export const MAX_SUBSCRIPTION_TOPICS = 64;
37
41
  /** The number of characters of a topic name. */
@@ -111,6 +115,10 @@ class TopicSubscription {
111
115
  closed = false;
112
116
  failure;
113
117
  unsubscribes;
118
+ /** The re-check of the admission that runs (roadmap CLI-44). The events wait for it. */
119
+ recheck;
120
+ /** The functions that run when the subscription ends */
121
+ endListeners = [];
114
122
  constructor(bus,
115
123
  /** The topics of the subscriber, each with the topic of the bus that it listens to */
116
124
  routes, buffer, signal, onClose,
@@ -141,7 +149,7 @@ class TopicSubscription {
141
149
  return;
142
150
  const event = { type: "event", topic, data, seq: ++this.seq };
143
151
  const waiter = this.waiter;
144
- if (waiter && this.queue.length === 0) {
152
+ if (waiter && this.queue.length === 0 && !this.recheck) {
145
153
  this.waiter = undefined;
146
154
  waiter.resolve(this.deliver(event));
147
155
  return;
@@ -178,6 +186,9 @@ class TopicSubscription {
178
186
  this.confirmation = undefined;
179
187
  return Promise.resolve({ value: confirmation, done: false });
180
188
  }
189
+ // The events wait for a re-check of the admission (roadmap CLI-44)
190
+ if (this.recheck)
191
+ return this.recheck.then(() => this.next());
181
192
  const event = this.queue.shift();
182
193
  if (event)
183
194
  return this.deliver(event);
@@ -236,8 +247,50 @@ class TopicSubscription {
236
247
  unsubscribe();
237
248
  this.signal?.removeEventListener("abort", this.onAbort);
238
249
  this.onClose(this);
250
+ for (const listener of this.endListeners.splice(0))
251
+ listener();
252
+ }
253
+ /**
254
+ * This function holds the events until the check ends (roadmap CLI-44). A check that passes gives
255
+ * the held events to the reader. A check that fails ends the subscription with its error, and the
256
+ * held events go. The promise ends when the check ends, and it does not reject.
257
+ */
258
+ hold(check) {
259
+ if (this.closed)
260
+ return check.then(ignore, ignore);
261
+ const running = check.then(() => {
262
+ if (this.recheck === running)
263
+ this.recheck = undefined;
264
+ this.flush();
265
+ }, (error) => {
266
+ if (this.recheck === running)
267
+ this.recheck = undefined;
268
+ this.queue.length = 0;
269
+ this.fail(error);
270
+ });
271
+ this.recheck = running;
272
+ return running;
273
+ }
274
+ /** This function runs the listener when the subscription ends, or at once after its end. */
275
+ onEnd(listener) {
276
+ if (this.closed)
277
+ listener();
278
+ else
279
+ this.endListeners.push(listener);
280
+ }
281
+ /** This function gives the first held event to a reader that waits, after a check passes. */
282
+ flush() {
283
+ const waiter = this.waiter;
284
+ const event = this.queue[0];
285
+ if (!waiter || !event || this.recheck)
286
+ return;
287
+ this.waiter = undefined;
288
+ this.queue.shift();
289
+ waiter.resolve(this.deliver(event));
239
290
  }
240
291
  }
292
+ /** This function does nothing: the end of a check of a closed subscription. */
293
+ function ignore() { }
241
294
  /**
242
295
  * The publisher of the remote events: it serves `events.subscribe` from a bus, under a topic
243
296
  * rule. `ProcedureServer` makes one from its option `events`.
@@ -261,7 +314,10 @@ export class EventPublisher {
261
314
  defaultReads;
262
315
  buffer;
263
316
  open = new Set();
317
+ /** The re-checks of the admission of the open subscriptions (roadmap CLI-44) */
318
+ rechecks;
264
319
  constructor(options) {
320
+ this.rechecks = new SubscriptionRechecks(options.recheck ?? {}, options.clock ?? realClock);
265
321
  this.bus = options.bus ?? getGlobalEventBus();
266
322
  this.known = topicMatcher(options.topics);
267
323
  this.allow = options.allow;
@@ -296,6 +352,17 @@ export class EventPublisher {
296
352
  for (const subscription of [...this.open])
297
353
  subscription.fail(stoppedError());
298
354
  }
355
+ /**
356
+ * This function tells the publisher that rights changed (roadmap CLI-44). Each open subscription
357
+ * that the change touches gets the checks of its start again: the topic rule, the reads, `allow`
358
+ * and the partition. Its events wait for the check. A refusal ends the subscription with its
359
+ * error, for example `FORBIDDEN`. The promise ends when each check ends, and it does not reject.
360
+ *
361
+ * @param change - The subscriptions that the change touches. Without it, each open subscription gets a check.
362
+ */
363
+ rightsChanged(change) {
364
+ return this.rechecks.rightsChanged(change);
365
+ }
299
366
  /**
300
367
  * The topic of the bus for a topic of a subscriber (roadmap CLI-17). A topic of a partitioned
301
368
  * collection names the partition that the subscriber asks for, as the input of a procedure does:
@@ -321,11 +388,10 @@ export class EventPublisher {
321
388
  return target ? [`collection:${target.collection}`] : [];
322
389
  }
323
390
  /**
324
- * The stream of one subscription. The publisher examines each topic before it adds a listener:
325
- * the topic rule, the reads, `allow`, and the partition. A call with one bad topic makes no subscription.
391
+ * The checks of the topics of a call: the topic rule, the reads of the capability and `allow`.
392
+ * A subscription passes them at its start and at each re-check (roadmap CLI-44).
326
393
  */
327
- async subscribe(topics, ctx) {
328
- const unique = [...new Set(topics)];
394
+ admitTopics(unique, ctx) {
329
395
  for (const topic of unique) {
330
396
  if (!this.known(topic))
331
397
  throw new TopicNotFoundError(`The host has no topic "${topic}"`);
@@ -347,11 +413,35 @@ export class EventPublisher {
347
413
  }
348
414
  }
349
415
  }
416
+ }
417
+ /**
418
+ * The admission of an open subscription again (roadmap CLI-44): the checks of its start, and the
419
+ * partition of each topic. A refusal of the resolver throws its error. A topic whose partition
420
+ * changed throws `FORBIDDEN` (reason `partition-not-allowed`), because the listener has the old
421
+ * partition.
422
+ */
423
+ async readmit(routes, ctx) {
424
+ this.admitTopics(routes.map(([topic]) => topic), ctx);
425
+ for (const [topic, busTopic] of routes) {
426
+ if ((await this.busTopic(topic, ctx)) !== busTopic) {
427
+ throw new InvocationError("FORBIDDEN", `The partition of the topic "${topic}" changed, so the subscription ends`, ctx.path, "partition-not-allowed");
428
+ }
429
+ }
430
+ }
431
+ /**
432
+ * The stream of one subscription. The publisher examines each topic before it adds a listener:
433
+ * the topic rule, the reads, `allow`, and the partition. A call with one bad topic makes no subscription.
434
+ */
435
+ async subscribe(topics, ctx) {
436
+ const unique = [...new Set(topics)];
437
+ this.admitTopics(unique, ctx);
350
438
  const routes = [];
351
439
  for (const topic of unique)
352
440
  routes.push([topic, await this.busTopic(topic, ctx)]);
353
441
  const subscription = new TopicSubscription(this.bus, routes, this.buffer, ctx.signal, (closed) => this.open.delete(closed), ctx.admit, ctx.invocation);
354
442
  this.open.add(subscription);
443
+ // The same checks run again at a change of the rights and after the max age (roadmap CLI-44)
444
+ this.rechecks.watch(subscription, ctx.principal, () => this.readmit(routes, ctx));
355
445
  return subscription.closeIfAborted();
356
446
  }
357
447
  }
@@ -1 +1 @@
1
- {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/events/publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAI/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAuC,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAElD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAkDpC,yFAAy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,IAAI,EAAE,uBAAuB,CAAC,CAAC;YACvJ,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,SAAS,CAAC,MAAyB,EAAE,GAAqB;QACtE,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACpC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAqC,EAAE,CAAC;QACpD,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAClF,MAAM,YAAY,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QACvJ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5B,6FAA6F;QAC7F,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;QAClF,OAAO,YAAY,CAAC,cAAc,EAAE,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The re-check of the admission of the open subscriptions (roadmap CLI-44).
3
+ *
4
+ * At the start of a subscription, a publisher examines the rights of the subscriber. It examines
5
+ * the topic rule, the reads of the capability, `allow` and the partition. A right can change
6
+ * later, for example when the app removes a user from a group. Thus the publisher examines each
7
+ * open subscription again:
8
+ *
9
+ * - At a change of the rights. The host uses `rightsChanged()` of the publisher, or the source of
10
+ * the option `recheck.rightsChanges` gives the change to its listener.
11
+ * - After the time `recheck.maxAge` on the clock of the publisher, from the last check.
12
+ *
13
+ * The check is the same function as at the start. While it operates, the events of the
14
+ * subscription wait. A refusal ends the subscription with its error, for example `FORBIDDEN`, and
15
+ * the events that wait go. Without a call of `rightsChanged()` and without the option, nothing
16
+ * changes.
17
+ */
18
+ import type { Clock } from "../clock.js";
19
+ import { type Duration } from "../duration.js";
20
+ import type { Principal } from "../server/types.js";
21
+ /**
22
+ * The subscriptions that a change of the rights touches: the id of a principal, or a test of the
23
+ * principal of a subscription. A subscription without a principal (a call from this process) has
24
+ * no id, so only a test or a change of each subscription touches it.
25
+ */
26
+ export type RightsChange = string | ((principal: Principal | undefined) => boolean);
27
+ /** The options of the re-check of the open subscriptions of a publisher (roadmap CLI-44). */
28
+ export interface SubscriptionRecheck {
29
+ /**
30
+ * The longest time from one check of a subscription to the next check, for example `minutes(1)`.
31
+ * The time is on the clock of the publisher. Without it, only a change of the rights starts a
32
+ * check.
33
+ */
34
+ readonly maxAge?: Duration | undefined;
35
+ /**
36
+ * The source of the changes of the rights of the app. While the publisher has an open
37
+ * subscription, the source has one listener of the publisher. The source gives the function that
38
+ * removes the listener. Each call of the listener is a call of `rightsChanged()`: without a
39
+ * change, each subscription gets a check.
40
+ */
41
+ readonly rightsChanges?: ((listener: (change?: RightsChange) => void) => () => void) | undefined;
42
+ }
43
+ /** A subscription that the re-checks can hold and watch. */
44
+ export interface RecheckedSubscription {
45
+ /**
46
+ * This function holds the events of the subscription until the check ends. A refusal ends the
47
+ * subscription with its error. The promise ends with the check, and it does not reject.
48
+ */
49
+ hold(check: Promise<void>): Promise<void>;
50
+ /** This function runs the listener when the subscription ends. */
51
+ onEnd(listener: () => void): void;
52
+ }
53
+ /**
54
+ * The re-checks of the open subscriptions of one publisher (roadmap CLI-44). The publisher gives
55
+ * each new subscription to `watch()`, with the check of its admission.
56
+ */
57
+ export declare class SubscriptionRechecks {
58
+ private readonly clock;
59
+ private readonly watches;
60
+ private readonly maxAgeMs;
61
+ private readonly source;
62
+ /** The function that removes the listener of the source, while a subscription is open */
63
+ private stopListening;
64
+ constructor(options: SubscriptionRecheck, clock: Clock);
65
+ /** The number of the subscriptions that the re-checks watch. */
66
+ get size(): number;
67
+ /**
68
+ * This function watches a subscription until it ends. A change of the rights of its principal
69
+ * and its max age start the check. The check must throw the refusal.
70
+ */
71
+ watch(subscription: RecheckedSubscription, principal: Principal | undefined, check: () => Promise<void>): void;
72
+ /**
73
+ * This function starts a check of each watched subscription that the change touches. The
74
+ * promise ends when each check ends.
75
+ */
76
+ rightsChanged(change?: RightsChange): Promise<void>;
77
+ /** This function stops the watch of a subscription that ended. */
78
+ private unwatch;
79
+ /** This function starts the timer of the max age of a subscription. */
80
+ private startTimer;
81
+ /** This function stops the timer of the max age of a subscription. */
82
+ private stopTimer;
83
+ }
84
+ //# sourceMappingURL=recheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recheck.d.ts","sourceRoot":"","sources":["../../src/events/recheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,OAAO,CAAC,CAAC;AAEpF,6FAA6F;AAC7F,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,YAAY,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAClG;AAED,4DAA4D;AAC5D,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,kEAAkE;IAClE,KAAK,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CACnC;AA2BD;;;GAGG;AACH,qBAAa,oBAAoB;IAS7B,OAAO,CAAC,QAAQ,CAAC,KAAK;IARxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,yFAAyF;IACzF,OAAO,CAAC,aAAa,CAA2B;IAEhD,YACE,OAAO,EAAE,mBAAmB,EACX,KAAK,EAAE,KAAK,EAQ9B;IAED,gEAAgE;IAChE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAwB7G;IAED;;;OAGG;IACH,aAAa,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAMlD;IAED,kEAAkE;IAClE,OAAO,CAAC,OAAO;IASf,uEAAuE;IACvE,OAAO,CAAC,UAAU;IAYlB,sEAAsE;IACtE,OAAO,CAAC,SAAS;CAKlB"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The re-check of the admission of the open subscriptions (roadmap CLI-44).
3
+ *
4
+ * At the start of a subscription, a publisher examines the rights of the subscriber. It examines
5
+ * the topic rule, the reads of the capability, `allow` and the partition. A right can change
6
+ * later, for example when the app removes a user from a group. Thus the publisher examines each
7
+ * open subscription again:
8
+ *
9
+ * - At a change of the rights. The host uses `rightsChanged()` of the publisher, or the source of
10
+ * the option `recheck.rightsChanges` gives the change to its listener.
11
+ * - After the time `recheck.maxAge` on the clock of the publisher, from the last check.
12
+ *
13
+ * The check is the same function as at the start. While it operates, the events of the
14
+ * subscription wait. A refusal ends the subscription with its error, for example `FORBIDDEN`, and
15
+ * the events that wait go. Without a call of `rightsChanged()` and without the option, nothing
16
+ * changes.
17
+ */
18
+ import { toMs } from "../duration.js";
19
+ /** True when the change touches a subscription of the principal. A test that throws touches it. */
20
+ function touches(change, principal) {
21
+ if (change === undefined)
22
+ return true;
23
+ if (typeof change === "string")
24
+ return principal?.id === change;
25
+ try {
26
+ return change(principal);
27
+ }
28
+ catch {
29
+ return true;
30
+ }
31
+ }
32
+ /** The promise of a check. A check that throws at once gives a rejected promise. */
33
+ function started(check) {
34
+ return new Promise((resolve) => resolve(check()));
35
+ }
36
+ /**
37
+ * The re-checks of the open subscriptions of one publisher (roadmap CLI-44). The publisher gives
38
+ * each new subscription to `watch()`, with the check of its admission.
39
+ */
40
+ export class SubscriptionRechecks {
41
+ clock;
42
+ watches = new Set();
43
+ maxAgeMs;
44
+ source;
45
+ /** The function that removes the listener of the source, while a subscription is open */
46
+ stopListening;
47
+ constructor(options, clock) {
48
+ this.clock = clock;
49
+ const maxAgeMs = options.maxAge === undefined ? undefined : toMs(options.maxAge, "recheck.maxAge");
50
+ if (maxAgeMs !== undefined && !(maxAgeMs > 0)) {
51
+ throw new TypeError(`recheck.maxAge must be more than 0 ms, got ${maxAgeMs} ms`);
52
+ }
53
+ this.maxAgeMs = maxAgeMs;
54
+ this.source = options.rightsChanges;
55
+ }
56
+ /** The number of the subscriptions that the re-checks watch. */
57
+ get size() {
58
+ return this.watches.size;
59
+ }
60
+ /**
61
+ * This function watches a subscription until it ends. A change of the rights of its principal
62
+ * and its max age start the check. The check must throw the refusal.
63
+ */
64
+ watch(subscription, principal, check) {
65
+ const watch = {
66
+ principal,
67
+ timer: undefined,
68
+ recheck: () => {
69
+ this.stopTimer(watch);
70
+ return subscription.hold(started(check)).then(() => {
71
+ // A check that passes gives the admission a new age
72
+ if (this.watches.has(watch))
73
+ this.startTimer(watch);
74
+ });
75
+ },
76
+ };
77
+ this.watches.add(watch);
78
+ subscription.onEnd(() => this.unwatch(watch));
79
+ if (!this.watches.has(watch))
80
+ return;
81
+ this.startTimer(watch);
82
+ if (this.source && !this.stopListening) {
83
+ try {
84
+ this.stopListening = this.source((change) => void this.rightsChanged(change));
85
+ }
86
+ catch (error) {
87
+ // A source that cannot listen cannot tell a revocation: the subscription ends
88
+ void subscription.hold(Promise.reject(error));
89
+ }
90
+ }
91
+ }
92
+ /**
93
+ * This function starts a check of each watched subscription that the change touches. The
94
+ * promise ends when each check ends.
95
+ */
96
+ rightsChanged(change) {
97
+ const checks = [];
98
+ for (const watch of [...this.watches]) {
99
+ if (touches(change, watch.principal))
100
+ checks.push(watch.recheck());
101
+ }
102
+ return Promise.all(checks).then(() => undefined);
103
+ }
104
+ /** This function stops the watch of a subscription that ended. */
105
+ unwatch(watch) {
106
+ this.stopTimer(watch);
107
+ if (!this.watches.delete(watch) || this.watches.size > 0)
108
+ return;
109
+ // The last subscription ended: the publisher does not listen to the source
110
+ const stop = this.stopListening;
111
+ this.stopListening = undefined;
112
+ stop?.();
113
+ }
114
+ /** This function starts the timer of the max age of a subscription. */
115
+ startTimer(watch) {
116
+ if (this.maxAgeMs === undefined)
117
+ return;
118
+ this.stopTimer(watch);
119
+ const timer = this.clock.after(this.maxAgeMs, () => {
120
+ if (watch.timer === timer)
121
+ watch.timer = undefined;
122
+ void watch.recheck();
123
+ });
124
+ // A check does not keep a Node process alive
125
+ timer.unref?.();
126
+ watch.timer = timer;
127
+ }
128
+ /** This function stops the timer of the max age of a subscription. */
129
+ stopTimer(watch) {
130
+ const timer = watch.timer;
131
+ watch.timer = undefined;
132
+ timer?.();
133
+ }
134
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,KAAK,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,6CAA6C;QAC7C,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QAChB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,sEAAsE;IAC9D,SAAS,CAAC,KAAY;QAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC1B,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;QACxB,KAAK,EAAE,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -21,7 +21,7 @@ export interface ErrorCodeInfo {
21
21
  readonly meaning: string;
22
22
  }
23
23
  /** An error code of the protocol. */
24
- export type ProtocolErrorCode = "NOT_FOUND" | "NO_HANDLER" | "NOT_EXPOSED" | "NOT_DECLARED" | "FORBIDDEN" | "UNAUTHORIZED" | "VALIDATION_ERROR" | "INVALID_REQUEST" | "PROTOCOL_VERSION" | "OUTPUT_VALIDATION_ERROR" | "NO_OUTPUT" | "HANDLER_ERROR" | "INTERNAL_ERROR" | "NOT_ACCEPTABLE" | "DUPLICATE" | "DUPLICATE_REQUEST" | "ABORTED" | "TIMEOUT" | "UNAVAILABLE" | "CONNECTION_CLOSED" | "CONNECTION_NOT_FOUND" | "TOPIC_NOT_FOUND" | "TOPIC_CLEARED" | "VERSION_CONFLICT";
24
+ export type ProtocolErrorCode = "NOT_FOUND" | "NO_HANDLER" | "NOT_EXPOSED" | "NOT_DECLARED" | "FORBIDDEN" | "UNAUTHORIZED" | "VALIDATION_ERROR" | "INVALID_REQUEST" | "PROTOCOL_VERSION" | "OUTPUT_VALIDATION_ERROR" | "NO_OUTPUT" | "HANDLER_ERROR" | "INTERNAL_ERROR" | "NOT_ACCEPTABLE" | "DUPLICATE" | "DUPLICATE_REQUEST" | "ABORTED" | "TIMEOUT" | "UNAVAILABLE" | "CONNECTION_CLOSED" | "CONNECTION_NOT_FOUND" | "TOPIC_NOT_FOUND" | "TOPIC_CLEARED" | "VERSION_CONFLICT" | "RATE_LIMITED";
25
25
  /**
26
26
  * The error codes of the protocol, on each face (HTTP, WebSocket, MCP, local). An error that a
27
27
  * handler throws with its own `code` keeps it, for a value and for a stream (`errorCodeOf`). The
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,iFAAiF;AACjF,eAAO,MAAM,eAAe,wBAAwB,CAAC;AAErD,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,2BAA2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,qCAAqC;AACrC,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,YAAY,GACZ,aAAa,GACb,cAAc,GACd,WAAW,GACX,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,yBAAyB,GACzB,WAAW,GACX,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,WAAW,GACX,mBAAmB,GACnB,SAAS,GACT,SAAS,GACT,aAAa,GACb,mBAAmB,GACnB,sBAAsB,GACtB,iBAAiB,GACjB,eAAe,GACf,kBAAkB,CAAC;AAEvB;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAyB1E,CAAC;AAEF,yDAAyD;AACzD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,iBAAiB,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGlD;AAED,yFAAyF;AACzF,wBAAgB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ACzF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE9D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGpE"}
package/dist/protocol.js CHANGED
@@ -42,6 +42,7 @@ export const ERROR_CODES = {
42
42
  TOPIC_NOT_FOUND: { http: 404, retryable: false, meaning: "The topic rule of the host has no topic with this name" },
43
43
  TOPIC_CLEARED: { http: 410, retryable: false, meaning: "The host cleared a topic of the subscription: clear() of its bus removed the listener" },
44
44
  VERSION_CONFLICT: { http: 409, retryable: false, meaning: "The current item does not have the version that the write expects. The metadata key conflicts has the current items" },
45
+ RATE_LIMITED: { http: 429, retryable: true, meaning: "A limit of the host refuses the call. The metadata key retry-after gives the wait, and reason gives the cause" },
45
46
  };
46
47
  /** True when a code is an error code of the protocol. */
47
48
  export function isProtocolErrorCode(code) {