@procedures/client 0.35.1 → 0.36.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.
- package/CHANGELOG.md +33 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.d.ts +3 -3
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2 -0
- package/dist/browser.js.map +1 -1
- package/dist/events/bus.d.ts.map +1 -1
- package/dist/events/bus.js +5 -1
- package/dist/events/bus.js.map +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/publisher.d.ts +18 -2
- package/dist/events/publisher.d.ts.map +1 -1
- package/dist/events/publisher.js +142 -25
- package/dist/events/publisher.js.map +1 -1
- package/dist/events/recheck.d.ts +27 -5
- package/dist/events/recheck.d.ts.map +1 -1
- package/dist/events/recheck.js +11 -10
- package/dist/events/recheck.js.map +1 -1
- package/dist/procedures/collection/admission.d.ts +26 -7
- package/dist/procedures/collection/admission.d.ts.map +1 -1
- package/dist/procedures/collection/admission.js +39 -7
- package/dist/procedures/collection/admission.js.map +1 -1
- package/dist/procedures/collection/changes.d.ts +13 -4
- package/dist/procedures/collection/changes.d.ts.map +1 -1
- package/dist/procedures/collection/changes.js +50 -6
- package/dist/procedures/collection/changes.js.map +1 -1
- package/dist/procedures/collection/hint-filter.d.ts +143 -0
- package/dist/procedures/collection/hint-filter.d.ts.map +1 -0
- package/dist/procedures/collection/hint-filter.js +311 -0
- package/dist/procedures/collection/hint-filter.js.map +1 -0
- package/dist/procedures/collection/index.d.ts +2 -0
- package/dist/procedures/collection/index.d.ts.map +1 -1
- package/dist/procedures/collection/index.js +2 -0
- package/dist/procedures/collection/index.js.map +1 -1
- package/dist/procedures/collection/procedures.d.ts +2 -2
- package/dist/procedures/collection/procedures.d.ts.map +1 -1
- package/dist/procedures/collection/procedures.js +6 -4
- package/dist/procedures/collection/procedures.js.map +1 -1
- package/dist/procedures/index.d.ts +2 -2
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +3 -1
- package/dist/procedures/index.js.map +1 -1
- package/package.json +1 -1
- package/src/browser.ts +7 -0
- package/src/events/bus.ts +6 -1
- package/src/events/index.ts +1 -1
- package/src/events/publisher.ts +150 -26
- package/src/events/recheck.ts +38 -13
- package/src/procedures/collection/admission.ts +50 -9
- package/src/procedures/collection/changes.ts +56 -7
- package/src/procedures/collection/hint-filter.ts +376 -0
- package/src/procedures/collection/index.ts +3 -0
- package/src/procedures/collection/procedures.ts +8 -6
- package/src/procedures/index.ts +5 -0
|
@@ -22,8 +22,13 @@
|
|
|
22
22
|
* listens to the topic, the procedures publish nothing, and the chain stops.
|
|
23
23
|
* - The publishes of one storage and one topic run one at a time, in the order of the writes. A
|
|
24
24
|
* write resolves after its event is on the bus. A failed publish never fails the write.
|
|
25
|
+
* - With the rule `admission.admit`, the publisher filters the ids of each event for each
|
|
26
|
+
* subscriber (roadmap CLI-78, `hint-filter.ts`). The event carries the rows after the changes,
|
|
27
|
+
* from the change log. While a subscriber has a filter, each write first reads the rows before
|
|
28
|
+
* it (`getBatch`). Thus a row that leaves the rule reaches that subscriber as a delete.
|
|
25
29
|
*/
|
|
26
30
|
import { withRows } from "../../events/rows.js";
|
|
31
|
+
import { hasFilteredSubscriber, withHintImages } from "./hint-filter.js";
|
|
27
32
|
import { collectionTopicTarget } from "./topic.js";
|
|
28
33
|
export { collectionChangeTopic } from "./topic.js";
|
|
29
34
|
/**
|
|
@@ -81,7 +86,8 @@ function hint(version, origin) {
|
|
|
81
86
|
/**
|
|
82
87
|
* The event of a delta with the values of the changed items. Each row `{ id, value }` passes the
|
|
83
88
|
* output filter of each subscriber and the rule of the rows of the collection, and a refused row
|
|
84
|
-
* goes from `values` to `withheld`.
|
|
89
|
+
* goes from `values` to `withheld`. The row filter of a subscriber (roadmap CLI-78) first takes the
|
|
90
|
+
* rows that the rule refuses out of the event. Thus only the output filter of the host withholds a row.
|
|
85
91
|
*/
|
|
86
92
|
function withValues(event, entries, admit) {
|
|
87
93
|
return withRows({ ...event, values: entries }, {
|
|
@@ -99,7 +105,8 @@ function withValues(event, entries, admit) {
|
|
|
99
105
|
});
|
|
100
106
|
}
|
|
101
107
|
/** One publish: the event of the writes that ended since the last publish. */
|
|
102
|
-
async function publish(chain, storage, bus, topic, values,
|
|
108
|
+
async function publish(chain, storage, bus, topic, values, admission) {
|
|
109
|
+
const admit = admission?.admit;
|
|
103
110
|
const writes = chain.ended.splice(0);
|
|
104
111
|
// An earlier publish told these writes
|
|
105
112
|
if (writes.length === 0)
|
|
@@ -139,7 +146,35 @@ async function publish(chain, storage, bus, topic, values, admit) {
|
|
|
139
146
|
deleted: changes.deleted,
|
|
140
147
|
...(origin !== undefined && { origin }),
|
|
141
148
|
};
|
|
142
|
-
|
|
149
|
+
const out = values ? withValues(event, changes.changed.map(([id, value]) => ({ id, value })), admit) : event;
|
|
150
|
+
// The rows of the event for the row filter of each subscriber (roadmap CLI-78)
|
|
151
|
+
bus.emit(topic, admit ? withHintImages(out, { after: afterOf(changes), before: beforeOf(writes), admission: admission }) : out);
|
|
152
|
+
}
|
|
153
|
+
/** The rows after the changes, from the change log: a changed id has its item, a deleted id has none. */
|
|
154
|
+
function afterOf(changes) {
|
|
155
|
+
const after = new Map();
|
|
156
|
+
for (const id of changes.deleted)
|
|
157
|
+
after.set(id, { found: false });
|
|
158
|
+
for (const [id, value] of changes.changed)
|
|
159
|
+
after.set(id, { found: true, value });
|
|
160
|
+
return after;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The rows before the changes: for each id, the read of the first write that read it. An id
|
|
164
|
+
* without a read is unknown, so the filter of a subscriber makes a hint without ids for it.
|
|
165
|
+
*/
|
|
166
|
+
function beforeOf(writes) {
|
|
167
|
+
const before = new Map();
|
|
168
|
+
for (const write of writes) {
|
|
169
|
+
if (!write.before || write.ids === "*")
|
|
170
|
+
continue;
|
|
171
|
+
for (const id of write.ids) {
|
|
172
|
+
if (before.has(id))
|
|
173
|
+
continue;
|
|
174
|
+
before.set(id, write.before.has(id) ? { found: true, value: write.before.get(id) } : { found: false });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return before;
|
|
143
178
|
}
|
|
144
179
|
/**
|
|
145
180
|
* This function runs a write of a collection procedure, and then publishes the change event of
|
|
@@ -154,19 +189,28 @@ async function publish(chain, storage, bus, topic, values, admit) {
|
|
|
154
189
|
* @param origin - The origin of the write
|
|
155
190
|
* @param write - The write
|
|
156
191
|
* @param values - True: the events carry the values, for the output filter of each subscriber
|
|
157
|
-
* @param
|
|
192
|
+
* @param admission - The rules of the rows of the collection: each subscriber applies `admit` to the rows of the event (roadmap CLI-41, CLI-78)
|
|
158
193
|
*/
|
|
159
|
-
export async function writeWithChangeEvent(bus, storage, topic, ids, origin, write, values = false,
|
|
194
|
+
export async function writeWithChangeEvent(bus, storage, topic, ids, origin, write, values = false, admission) {
|
|
160
195
|
if (bus === undefined || topic === undefined)
|
|
161
196
|
return write();
|
|
162
197
|
const chain = chainOf(storage, topic);
|
|
163
198
|
const started = { ids, origin, anchored: chain.anchor !== undefined };
|
|
199
|
+
// A subscriber with a row filter: the rows before the write tell it which rows left the rule (roadmap CLI-78)
|
|
200
|
+
if (admission?.admit && ids !== "*" && ids.length > 0 && storage.getBatch && hasFilteredSubscriber(bus, topic) && bus.hasSubscribers(topic)) {
|
|
201
|
+
try {
|
|
202
|
+
started.before = await storage.getBatch([...ids]);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// Without the rows before the write, the filter of a subscriber makes a hint without ids
|
|
206
|
+
}
|
|
207
|
+
}
|
|
164
208
|
try {
|
|
165
209
|
return await write();
|
|
166
210
|
}
|
|
167
211
|
finally {
|
|
168
212
|
chain.ended.push(started);
|
|
169
|
-
const run = chain.tail.then(() => publish(chain, storage, bus, topic, values,
|
|
213
|
+
const run = chain.tail.then(() => publish(chain, storage, bus, topic, values, admission));
|
|
170
214
|
chain.tail = run.catch(() => undefined);
|
|
171
215
|
await chain.tail;
|
|
172
216
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changes.js","sourceRoot":"","sources":["../../../src/procedures/collection/changes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"changes.js","sourceRoot":"","sources":["../../../src/procedures/collection/changes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AAE5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA4CnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa,EAAE,UAA+B;IACjF,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC;AA8BD,+FAA+F;AAC/F,MAAM,MAAM,GAAG,IAAI,OAAO,EAAoC,CAAC;AAE/D,SAAS,OAAO,CAAC,OAAe,EAAE,KAAa;IAC7C,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACnB,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,EAAE,MAAM,EAAE,SAA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of a collection (roadmap CLI-78).
|
|
3
|
+
*
|
|
4
|
+
* A change event names the ids that changed. Before CLI-78, each subscriber of a topic got all the
|
|
5
|
+
* ids, so only a principal that reads the whole partition could subscribe. With CLI-78, the publisher
|
|
6
|
+
* filters each event row by row for each subscriber, with the rule of the rows of the collection
|
|
7
|
+
* (`admission.admit`). The reads apply the same rule (`admittedStorage()`).
|
|
8
|
+
*
|
|
9
|
+
* - The rule comes from the registry of the call: `createCollectionProcedures()` puts its rules on
|
|
10
|
+
* the metadata of its procedures. An event can also carry the rules in its images.
|
|
11
|
+
* - The rule examines the rows of the images of the event (`withHintImages()`): the row after the
|
|
12
|
+
* changes, and the row before them. The publisher does not read a storage.
|
|
13
|
+
* - A changed row that the rule admits stays in `changed`. A changed row that the rule refuses, or
|
|
14
|
+
* a deleted row, goes to `deleted` only when the rule admitted its row before the changes.
|
|
15
|
+
* Otherwise the subscriber does not get its id.
|
|
16
|
+
* - When an image is missing, or the rule fails, the subscriber gets a hint without ids and
|
|
17
|
+
* without `since`. It then reads the changes, through the rule of the reads.
|
|
18
|
+
* - An event without ids, and a `reset` event, pass without ids.
|
|
19
|
+
* - When the subscriber gets no id of an event, it gets no event. The `since` of its next event is
|
|
20
|
+
* then the `version` of the last event that it got. Thus it applies the next delta without a read.
|
|
21
|
+
* - `admission.admitsAll` tells that a subscriber reads each row of its partition. Its events then
|
|
22
|
+
* pass as before CLI-78, with no cost.
|
|
23
|
+
*/
|
|
24
|
+
import type { Invocation } from "../invoke.js";
|
|
25
|
+
import type { AnyProcedure, ProcedureContext } from "../types.js";
|
|
26
|
+
import type { CollectionAdmission } from "./admission.js";
|
|
27
|
+
import type { EventBus } from "../../events/types.js";
|
|
28
|
+
/** The state of one row in an image: the stored item, or no item. */
|
|
29
|
+
export type HintRowState = {
|
|
30
|
+
readonly found: true;
|
|
31
|
+
readonly value: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
readonly found: false;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The rows of a change event, for the row filter of each subscriber (roadmap CLI-78). A missing id
|
|
37
|
+
* in a map is unknown. The images are on a symbol key, so they stay in this process: JSON does
|
|
38
|
+
* not take them.
|
|
39
|
+
*/
|
|
40
|
+
export interface HintImages {
|
|
41
|
+
/** The rows after the changes of the event, by id. */
|
|
42
|
+
readonly after?: ReadonlyMap<string, HintRowState> | undefined;
|
|
43
|
+
/** The rows before the changes of the event (at its `since`), by id. */
|
|
44
|
+
readonly before?: ReadonlyMap<string, HintRowState> | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The rules of the rows of the collection. The publisher uses the rules from its registry
|
|
47
|
+
* first, and these rules only when the registry has none.
|
|
48
|
+
*/
|
|
49
|
+
readonly admission?: CollectionAdmission | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This function gives the event with its images, for the row filter of each subscriber (roadmap
|
|
53
|
+
* CLI-78). The images are not enumerable: a copy or a comparison of the event does not see them.
|
|
54
|
+
*/
|
|
55
|
+
export declare function withHintImages<T extends object>(event: T, images: HintImages): T;
|
|
56
|
+
/** The images of an event, or undefined for an event without images. */
|
|
57
|
+
export declare function hintImagesOf(event: unknown): HintImages | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* This function puts the rules of a collection on the metadata of its procedures, so the publisher
|
|
60
|
+
* of the events finds them in the registry. The key is not enumerable.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withCollectionRules(procedures: AnyProcedure[], admission: CollectionAdmission | undefined): AnyProcedure[];
|
|
63
|
+
/**
|
|
64
|
+
* The rules of a collection in the registry of a call. It gives the rules, or `null` for a
|
|
65
|
+
* collection without rules. It gives undefined when the registry does not know the procedures.
|
|
66
|
+
*/
|
|
67
|
+
export declare function collectionRulesOf(ctx: ProcedureContext, collection: string): CollectionAdmission | null | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The invocation that the rules of a collection get for the events of one topic (roadmap CLI-78).
|
|
70
|
+
* It has the principal, the capability, the metadata and the signal of the subscription. Its path
|
|
71
|
+
* is the path of `changes` of the collection, and its input has the partition of the topic. Thus
|
|
72
|
+
* a rule that reads `invocation.input.partition` sees the same input as in a read of the topic.
|
|
73
|
+
*
|
|
74
|
+
* @param base - The invocation of the subscription
|
|
75
|
+
* @param ctx - The context of the subscription. Its registry gives the procedure of `changes`.
|
|
76
|
+
* @param collection - The collection of the topic
|
|
77
|
+
* @param partition - The partition that the topic names, before the resolver
|
|
78
|
+
*/
|
|
79
|
+
export declare function collectionInvocation(base: Invocation | undefined, ctx: ProcedureContext, collection: string, partition: string | undefined): Invocation | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* This function marks a topic of a bus: a subscription of the topic has a row filter. It gives the
|
|
82
|
+
* function that removes the mark. A second call of that function does nothing.
|
|
83
|
+
*/
|
|
84
|
+
export declare function markFilteredTopic(bus: EventBus, topic: string): () => void;
|
|
85
|
+
/** True when a subscription of the topic of the bus has a row filter. */
|
|
86
|
+
export declare function hasFilteredSubscriber(bus: EventBus, topic: string): boolean;
|
|
87
|
+
/** The result of the filter for an event that the subscriber does not get. */
|
|
88
|
+
export declare const DROPPED: unique symbol;
|
|
89
|
+
/**
|
|
90
|
+
* The mode of a filter. `pass` gives each event as before CLI-78, and `filter` examines each row.
|
|
91
|
+
* `unknown` uses the rules of the images of each event.
|
|
92
|
+
*/
|
|
93
|
+
export type HintFilterMode = "pass" | "filter" | "unknown";
|
|
94
|
+
/**
|
|
95
|
+
* The row filter of one topic of one subscription (roadmap CLI-78). The publisher gives each event
|
|
96
|
+
* of the topic to `apply()`, one at a time, in the order of the bus.
|
|
97
|
+
*/
|
|
98
|
+
export declare class RowHintFilter {
|
|
99
|
+
/** The rules of the collection from the registry of the call. */
|
|
100
|
+
private readonly lookup;
|
|
101
|
+
/** The invocation of the topic (`collectionInvocation()`): the rules get it. */
|
|
102
|
+
readonly invocation: Invocation | undefined;
|
|
103
|
+
/** The partition of the topic: `admitsAll` gets it. */
|
|
104
|
+
private readonly partition;
|
|
105
|
+
/** The rules from the registry: undefined when the registry does not know the collection. */
|
|
106
|
+
private rules;
|
|
107
|
+
/** The result of `admitsAll` for one set of rules. */
|
|
108
|
+
private all;
|
|
109
|
+
/** The `version` of the last event of the chain, also of an event that the subscriber did not get. */
|
|
110
|
+
private head;
|
|
111
|
+
/** The `since` that the next event of the chain gets: the `version` of the last event that the subscriber got. */
|
|
112
|
+
private base;
|
|
113
|
+
/** The filters, one at a time. */
|
|
114
|
+
private tail;
|
|
115
|
+
constructor(
|
|
116
|
+
/** The rules of the collection from the registry of the call. */
|
|
117
|
+
lookup: () => CollectionAdmission | null | undefined,
|
|
118
|
+
/** The invocation of the topic (`collectionInvocation()`): the rules get it. */
|
|
119
|
+
invocation: Invocation | undefined,
|
|
120
|
+
/** The partition of the topic: `admitsAll` gets it. */
|
|
121
|
+
partition: string | undefined);
|
|
122
|
+
/** The mode of the filter, from the rules and from the last result of `admitsAll`. */
|
|
123
|
+
get mode(): HintFilterMode;
|
|
124
|
+
/**
|
|
125
|
+
* This function reads the rules again and asks `admitsAll` again: at the start of the
|
|
126
|
+
* subscription and at each re-check (roadmap CLI-44). It gives the new mode.
|
|
127
|
+
*/
|
|
128
|
+
refresh(): Promise<HintFilterMode>;
|
|
129
|
+
/** This function forgets the chain: the next event keeps its own `since`. */
|
|
130
|
+
forget(): void;
|
|
131
|
+
/**
|
|
132
|
+
* The event for the subscriber. It gives undefined when the event passes as it is (no wait).
|
|
133
|
+
* Otherwise it gives a promise of the event for the subscriber, or of `DROPPED` for no event.
|
|
134
|
+
*/
|
|
135
|
+
apply(data: unknown): Promise<unknown> | undefined;
|
|
136
|
+
/** The result of `admitsAll` for a set of rules. An error gives false. */
|
|
137
|
+
private admitsAll;
|
|
138
|
+
/** The filter of one event with the rule of the rows. */
|
|
139
|
+
private filter;
|
|
140
|
+
/** An event of the chain that the subscriber does not get: the next event keeps the `since` of the last one. */
|
|
141
|
+
private skip;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=hint-filter.d.ts.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AI,GAAG,SAAS;IACrE,gFAAgF;IACvE,UAAU,EAAE,UAAU,GAAG,SAAS;IAC3C,uDAAuD;IACtC,SAAS,EAAE,MAAM,GAAG,SAAS,EAG/C;IAED,sFAAsF;IACtF,IAAI,IAAI,IAAI,cAAc,CAKzB;IAED;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,CAKvC;IAED,6EAA6E;IAC7E,MAAM,IAAI,IAAI,CAGb;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CASjD;IAED,0EAA0E;YAC5D,SAAS;IAevB,yDAAyD;YAC3C,MAAM;IAkFpB,gHAAgH;IAChH,OAAO,CAAC,IAAI;CAUb"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { withRows } from "../../events/rows.js";
|
|
2
|
+
/** The key of the images of an event. */
|
|
3
|
+
const IMAGES = Symbol.for("procedures.hintImages");
|
|
4
|
+
/**
|
|
5
|
+
* This function gives the event with its images, for the row filter of each subscriber (roadmap
|
|
6
|
+
* CLI-78). The images are not enumerable: a copy or a comparison of the event does not see them.
|
|
7
|
+
*/
|
|
8
|
+
export function withHintImages(event, images) {
|
|
9
|
+
return Object.defineProperty(event, IMAGES, { value: images, enumerable: false, configurable: true });
|
|
10
|
+
}
|
|
11
|
+
/** The images of an event, or undefined for an event without images. */
|
|
12
|
+
export function hintImagesOf(event) {
|
|
13
|
+
if (typeof event !== "object" || event === null)
|
|
14
|
+
return undefined;
|
|
15
|
+
const images = event[IMAGES];
|
|
16
|
+
return typeof images === "object" && images !== null ? images : undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The key of the rules of a collection on the metadata of its procedures. */
|
|
19
|
+
const RULES = Symbol.for("procedures.collectionRules");
|
|
20
|
+
/**
|
|
21
|
+
* This function puts the rules of a collection on the metadata of its procedures, so the publisher
|
|
22
|
+
* of the events finds them in the registry. The key is not enumerable.
|
|
23
|
+
*/
|
|
24
|
+
export function withCollectionRules(procedures, admission) {
|
|
25
|
+
for (const procedure of procedures) {
|
|
26
|
+
const metadata = procedure.metadata;
|
|
27
|
+
if (metadata)
|
|
28
|
+
Object.defineProperty(metadata, RULES, { value: { admission }, enumerable: false, configurable: true });
|
|
29
|
+
}
|
|
30
|
+
return procedures;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The rules of a collection in the registry of a call. It gives the rules, or `null` for a
|
|
34
|
+
* collection without rules. It gives undefined when the registry does not know the procedures.
|
|
35
|
+
*/
|
|
36
|
+
export function collectionRulesOf(ctx, collection) {
|
|
37
|
+
const registry = ctx.registry;
|
|
38
|
+
if (!registry)
|
|
39
|
+
return undefined;
|
|
40
|
+
for (const operation of ["changes", "get"]) {
|
|
41
|
+
const metadata = registry.get(["collections", collection, operation])?.metadata;
|
|
42
|
+
const rules = metadata?.[RULES];
|
|
43
|
+
if (rules)
|
|
44
|
+
return rules.admission ?? null;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The invocation that the rules of a collection get for the events of one topic (roadmap CLI-78).
|
|
50
|
+
* It has the principal, the capability, the metadata and the signal of the subscription. Its path
|
|
51
|
+
* is the path of `changes` of the collection, and its input has the partition of the topic. Thus
|
|
52
|
+
* a rule that reads `invocation.input.partition` sees the same input as in a read of the topic.
|
|
53
|
+
*
|
|
54
|
+
* @param base - The invocation of the subscription
|
|
55
|
+
* @param ctx - The context of the subscription. Its registry gives the procedure of `changes`.
|
|
56
|
+
* @param collection - The collection of the topic
|
|
57
|
+
* @param partition - The partition that the topic names, before the resolver
|
|
58
|
+
*/
|
|
59
|
+
export function collectionInvocation(base, ctx, collection, partition) {
|
|
60
|
+
if (base === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const procedure = ctx.registry?.get(["collections", collection, "changes"]);
|
|
63
|
+
return {
|
|
64
|
+
...base,
|
|
65
|
+
...(procedure !== undefined && { procedure, path: procedure.path }),
|
|
66
|
+
input: partition === undefined ? {} : { partition },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** The subscriptions with a row filter, by bus and by topic: the writes read the rows before them only for these. */
|
|
70
|
+
const FILTERED = new WeakMap();
|
|
71
|
+
/** The key of the bus under a view of a bus (`withEventBusSignal()`). */
|
|
72
|
+
const BASE_BUS = Symbol.for("procedures.baseBus");
|
|
73
|
+
/** The bus under a view of a bus, or the bus itself. */
|
|
74
|
+
function baseOf(bus) {
|
|
75
|
+
return bus[BASE_BUS] ?? bus;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* This function marks a topic of a bus: a subscription of the topic has a row filter. It gives the
|
|
79
|
+
* function that removes the mark. A second call of that function does nothing.
|
|
80
|
+
*/
|
|
81
|
+
export function markFilteredTopic(bus, topic) {
|
|
82
|
+
const base = baseOf(bus);
|
|
83
|
+
let topics = FILTERED.get(base);
|
|
84
|
+
if (!topics) {
|
|
85
|
+
topics = new Map();
|
|
86
|
+
FILTERED.set(base, topics);
|
|
87
|
+
}
|
|
88
|
+
topics.set(topic, (topics.get(topic) ?? 0) + 1);
|
|
89
|
+
let marked = true;
|
|
90
|
+
return () => {
|
|
91
|
+
if (!marked)
|
|
92
|
+
return;
|
|
93
|
+
marked = false;
|
|
94
|
+
const count = (topics.get(topic) ?? 1) - 1;
|
|
95
|
+
if (count > 0)
|
|
96
|
+
topics.set(topic, count);
|
|
97
|
+
else
|
|
98
|
+
topics.delete(topic);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** True when a subscription of the topic of the bus has a row filter. */
|
|
102
|
+
export function hasFilteredSubscriber(bus, topic) {
|
|
103
|
+
return (FILTERED.get(baseOf(bus))?.get(topic) ?? 0) > 0;
|
|
104
|
+
}
|
|
105
|
+
/** The result of the filter for an event that the subscriber does not get. */
|
|
106
|
+
export const DROPPED = Symbol("procedures.droppedHint");
|
|
107
|
+
/** True for a value with the shape of a change event: the arrays `changed` and `deleted`. */
|
|
108
|
+
function isChangeEvent(data) {
|
|
109
|
+
if (typeof data !== "object" || data === null)
|
|
110
|
+
return false;
|
|
111
|
+
const event = data;
|
|
112
|
+
return Array.isArray(event.changed) && Array.isArray(event.deleted);
|
|
113
|
+
}
|
|
114
|
+
/** The fields `version` and `origin` of an event, when they are strings. */
|
|
115
|
+
function headOf(event) {
|
|
116
|
+
return {
|
|
117
|
+
...(typeof event.version === "string" && { version: event.version }),
|
|
118
|
+
...(typeof event.origin === "string" && { origin: event.origin }),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** This function does nothing: the end of a filter that failed. */
|
|
122
|
+
function ignore() { }
|
|
123
|
+
/**
|
|
124
|
+
* The row filter of one topic of one subscription (roadmap CLI-78). The publisher gives each event
|
|
125
|
+
* of the topic to `apply()`, one at a time, in the order of the bus.
|
|
126
|
+
*/
|
|
127
|
+
export class RowHintFilter {
|
|
128
|
+
lookup;
|
|
129
|
+
invocation;
|
|
130
|
+
partition;
|
|
131
|
+
/** The rules from the registry: undefined when the registry does not know the collection. */
|
|
132
|
+
rules;
|
|
133
|
+
/** The result of `admitsAll` for one set of rules. */
|
|
134
|
+
all;
|
|
135
|
+
/** The `version` of the last event of the chain, also of an event that the subscriber did not get. */
|
|
136
|
+
head;
|
|
137
|
+
/** The `since` that the next event of the chain gets: the `version` of the last event that the subscriber got. */
|
|
138
|
+
base;
|
|
139
|
+
/** The filters, one at a time. */
|
|
140
|
+
tail = Promise.resolve();
|
|
141
|
+
constructor(
|
|
142
|
+
/** The rules of the collection from the registry of the call. */
|
|
143
|
+
lookup,
|
|
144
|
+
/** The invocation of the topic (`collectionInvocation()`): the rules get it. */
|
|
145
|
+
invocation,
|
|
146
|
+
/** The partition of the topic: `admitsAll` gets it. */
|
|
147
|
+
partition) {
|
|
148
|
+
this.lookup = lookup;
|
|
149
|
+
this.invocation = invocation;
|
|
150
|
+
this.partition = partition;
|
|
151
|
+
this.rules = lookup();
|
|
152
|
+
}
|
|
153
|
+
/** The mode of the filter, from the rules and from the last result of `admitsAll`. */
|
|
154
|
+
get mode() {
|
|
155
|
+
const rules = this.rules;
|
|
156
|
+
if (rules === undefined)
|
|
157
|
+
return "unknown";
|
|
158
|
+
if (rules === null || !rules.admit)
|
|
159
|
+
return "pass";
|
|
160
|
+
return this.all?.admission === rules && this.all.value ? "pass" : "filter";
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* This function reads the rules again and asks `admitsAll` again: at the start of the
|
|
164
|
+
* subscription and at each re-check (roadmap CLI-44). It gives the new mode.
|
|
165
|
+
*/
|
|
166
|
+
async refresh() {
|
|
167
|
+
this.rules = this.lookup();
|
|
168
|
+
this.all = undefined;
|
|
169
|
+
if (this.rules?.admit)
|
|
170
|
+
await this.admitsAll(this.rules);
|
|
171
|
+
return this.mode;
|
|
172
|
+
}
|
|
173
|
+
/** This function forgets the chain: the next event keeps its own `since`. */
|
|
174
|
+
forget() {
|
|
175
|
+
this.head = undefined;
|
|
176
|
+
this.base = undefined;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The event for the subscriber. It gives undefined when the event passes as it is (no wait).
|
|
180
|
+
* Otherwise it gives a promise of the event for the subscriber, or of `DROPPED` for no event.
|
|
181
|
+
*/
|
|
182
|
+
apply(data) {
|
|
183
|
+
if (!isChangeEvent(data))
|
|
184
|
+
return undefined;
|
|
185
|
+
const mode = this.mode;
|
|
186
|
+
if (mode === "pass")
|
|
187
|
+
return undefined;
|
|
188
|
+
const admission = this.rules ?? hintImagesOf(data)?.admission;
|
|
189
|
+
if (!admission?.admit)
|
|
190
|
+
return undefined;
|
|
191
|
+
const run = this.tail.then(() => this.filter(data, admission));
|
|
192
|
+
this.tail = run.catch(ignore);
|
|
193
|
+
return run;
|
|
194
|
+
}
|
|
195
|
+
/** The result of `admitsAll` for a set of rules. An error gives false. */
|
|
196
|
+
async admitsAll(admission) {
|
|
197
|
+
if (this.all?.admission === admission)
|
|
198
|
+
return this.all.value;
|
|
199
|
+
let value = false;
|
|
200
|
+
const invocation = this.invocation;
|
|
201
|
+
if (admission.admitsAll && invocation) {
|
|
202
|
+
try {
|
|
203
|
+
value = (await admission.admitsAll(invocation, this.partition)) === true;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
value = false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
this.all = { admission, value };
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
/** The filter of one event with the rule of the rows. */
|
|
213
|
+
async filter(event, admission) {
|
|
214
|
+
// Rules from the images of an event: the subscriber can read each row
|
|
215
|
+
if (await this.admitsAll(admission))
|
|
216
|
+
return event;
|
|
217
|
+
if (event.reset === true) {
|
|
218
|
+
this.forget();
|
|
219
|
+
return { ...headOf(event), changed: [], deleted: [], reset: true };
|
|
220
|
+
}
|
|
221
|
+
const since = typeof event.since === "string" ? event.since : undefined;
|
|
222
|
+
if (event.changed.length === 0 && event.deleted.length === 0) {
|
|
223
|
+
if (since === undefined) {
|
|
224
|
+
// A hint: the subscriber reads the changes through the rule of the reads
|
|
225
|
+
this.forget();
|
|
226
|
+
return { ...headOf(event), changed: [], deleted: [] };
|
|
227
|
+
}
|
|
228
|
+
return this.skip(since, event);
|
|
229
|
+
}
|
|
230
|
+
const admit = admission.admit;
|
|
231
|
+
const invocation = this.invocation;
|
|
232
|
+
const images = hintImagesOf(event);
|
|
233
|
+
const verdict = async (id, state) => {
|
|
234
|
+
if (state === undefined)
|
|
235
|
+
return undefined;
|
|
236
|
+
if (!state.found || invocation === undefined)
|
|
237
|
+
return false;
|
|
238
|
+
try {
|
|
239
|
+
return (await admit({ id, value: state.value }, invocation)) === true;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const before = (id) => verdict(id, images?.before?.get(id));
|
|
246
|
+
const changed = await Promise.all(event.changed.map(async (id) => {
|
|
247
|
+
const now = await verdict(id, images?.after?.get(id));
|
|
248
|
+
if (now === true)
|
|
249
|
+
return "changed";
|
|
250
|
+
if (now === undefined)
|
|
251
|
+
return undefined;
|
|
252
|
+
// The row left the rule, or it has no item: a delete for a subscriber that had it
|
|
253
|
+
const was = await before(id);
|
|
254
|
+
return was === undefined ? undefined : was ? "deleted" : "none";
|
|
255
|
+
}));
|
|
256
|
+
const deleted = await Promise.all(event.deleted.map(before));
|
|
257
|
+
if (changed.includes(undefined) || deleted.includes(undefined)) {
|
|
258
|
+
// The filter cannot tell the rows: the subscriber reads the changes through the rule of the reads
|
|
259
|
+
this.forget();
|
|
260
|
+
return { ...headOf(event), changed: [], deleted: [] };
|
|
261
|
+
}
|
|
262
|
+
const visible = event.changed.filter((_, index) => changed[index] === "changed");
|
|
263
|
+
const gone = [...event.changed.filter((_, index) => changed[index] === "deleted"), ...event.deleted.filter((_, index) => deleted[index] === true)];
|
|
264
|
+
if (visible.length === 0 && gone.length === 0) {
|
|
265
|
+
if (since === undefined)
|
|
266
|
+
return DROPPED;
|
|
267
|
+
return this.skip(since, event);
|
|
268
|
+
}
|
|
269
|
+
const kept = new Set(visible);
|
|
270
|
+
const chained = since === undefined ? undefined : since === this.head ? this.base : since;
|
|
271
|
+
if (since !== undefined && typeof event.version === "string") {
|
|
272
|
+
this.head = event.version;
|
|
273
|
+
this.base = event.version;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.forget();
|
|
277
|
+
}
|
|
278
|
+
const out = {
|
|
279
|
+
...(chained !== undefined && { since: chained }),
|
|
280
|
+
...(typeof event.version === "string" && { version: event.version }),
|
|
281
|
+
changed: visible,
|
|
282
|
+
deleted: gone,
|
|
283
|
+
...(event.versions && { versions: event.versions.filter(({ id }) => kept.has(id)) }),
|
|
284
|
+
...(typeof event.origin === "string" && { origin: event.origin }),
|
|
285
|
+
};
|
|
286
|
+
if (!event.values)
|
|
287
|
+
return out;
|
|
288
|
+
const values = event.values.filter(({ id }) => kept.has(id));
|
|
289
|
+
// The rows pass the output filter of the host for the subscriber, as before
|
|
290
|
+
return withRows({ ...out, values }, {
|
|
291
|
+
rows: values,
|
|
292
|
+
keep: (admitted) => {
|
|
293
|
+
const withheld = values.filter((_, index) => !admitted[index]).map(({ id }) => id);
|
|
294
|
+
return { ...out, values: values.filter((_, index) => admitted[index]), ...(withheld.length > 0 && { withheld }) };
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/** An event of the chain that the subscriber does not get: the next event keeps the `since` of the last one. */
|
|
299
|
+
skip(since, event) {
|
|
300
|
+
const chained = since === this.head ? this.base : since;
|
|
301
|
+
if (typeof event.version === "string" && chained !== undefined) {
|
|
302
|
+
this.head = event.version;
|
|
303
|
+
this.base = chained;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.forget();
|
|
307
|
+
}
|
|
308
|
+
return DROPPED;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=hint-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hint-filter.js","sourceRoot":"","sources":["../../../src/procedures/collection/hint-filter.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAuBhD,yCAAyC;AACzC,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAmB,KAAQ,EAAE,MAAkB;IAC3E,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;AACxG,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,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AK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;gBACnF,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;YACpH,CAAC;SACF,CACF,CAAC;IACJ,CAAC;IAED,gHAAgH;IACxG,IAAI,CAAC,KAAa,EAAE,KAAuB;QACjD,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QACxD,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC/D,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -15,6 +15,8 @@ export { collectionTopicRule } from "./topic.js";
|
|
|
15
15
|
export type { CollectionPartitions, PartitionInput, PartitionResolver } from "./partition.js";
|
|
16
16
|
export { admittedStorage, admitsRow } from "./admission.js";
|
|
17
17
|
export type { CollectionAdmission, CollectionRow, CollectionWrite, CollectionWriteGuard } from "./admission.js";
|
|
18
|
+
export { withHintImages, hintImagesOf } from "./hint-filter.js";
|
|
19
|
+
export type { HintImages, HintRowState } from "./hint-filter.js";
|
|
18
20
|
export type { CollectionStorage, StorageChanges, StorageMetadata, StorageWriteOptions, StorageItemWriteOptions, StorageBatchWriteOptions, StorageSetChange, StorageDeleteChange, StorageClearChange, StorageChangeEvent, StorageChangeBatch, StorageObserver, } from "./storage.js";
|
|
19
21
|
export { MAX_EXPECTED_VERSION_LENGTH, PRECONDITION_NOT_SUPPORTED, VERSION_CONFLICTS_METADATA_KEY, VersionConflictError, asVersionConflictError, isExpectedVersion, preconditionNotSupported, versionConflict, versionConflicts, versionConflictsOf, } from "./precondition.js";
|
|
20
22
|
export type { CurrentItem, VersionConflict, VersionOf } from "./precondition.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/procedures/collection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,eAAe,EACf,SAAS,EACT,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,SAAS,EACT,UAAU,EACV,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,YAAY,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AAGlG,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnJ,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG9F,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC5D,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/procedures/collection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV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ChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,8BAA8B,EAC9B,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAIjF,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -17,6 +17,8 @@ export { CollectionTopicCollisionError } from "./partition.js";
|
|
|
17
17
|
export { collectionTopicRule } from "./topic.js";
|
|
18
18
|
// The rules of the rows of a collection: a filter of the reads and a guard of the writes (roadmap CLI-41)
|
|
19
19
|
export { admittedStorage, admitsRow } from "./admission.js";
|
|
20
|
+
// The images of the rows of a change event, for the row filter of each subscriber (roadmap CLI-78)
|
|
21
|
+
export { withHintImages, hintImagesOf } from "./hint-filter.js";
|
|
20
22
|
// The precondition of the writes: the expected version and VERSION_CONFLICT (roadmap CLI-16)
|
|
21
23
|
export { MAX_EXPECTED_VERSION_LENGTH, PRECONDITION_NOT_SUPPORTED, VERSION_CONFLICTS_METADATA_KEY, VersionConflictError, asVersionConflictError, isExpectedVersion, preconditionNotSupported, versionConflict, versionConflicts, versionConflictsOf, } from "./precondition.js";
|
|
22
24
|
// The query language of the storages: the same JSON on the wire and in query() (roadmap CLI-34:
|