@superdurable/dex 0.1.3 → 0.1.5
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/README.md +69 -3
- package/dist/src/attribute-store-sync.d.ts +5 -0
- package/dist/src/attribute-store-sync.js +19 -0
- package/dist/src/attribute-store-sync.js.map +1 -0
- package/dist/src/blob-cache.d.ts +36 -0
- package/dist/src/blob-cache.js +13 -0
- package/dist/src/blob-cache.js.map +1 -1
- package/dist/src/client.d.ts +205 -4
- package/dist/src/client.js +201 -37
- package/dist/src/client.js.map +1 -1
- package/dist/src/codec.d.ts +73 -0
- package/dist/src/codec.js +23 -0
- package/dist/src/codec.js.map +1 -1
- package/dist/src/context.d.ts +92 -0
- package/dist/src/errors.d.ts +122 -6
- package/dist/src/errors.js +139 -9
- package/dist/src/errors.js.map +1 -1
- package/dist/src/flow.d.ts +36 -1
- package/dist/src/flow.js +96 -28
- package/dist/src/flow.js.map +1 -1
- package/dist/src/gen/dex.d.ts +58 -9
- package/dist/src/gen/dex.js +417 -55
- package/dist/src/gen/dex.js.map +1 -1
- package/dist/src/grpc-status.d.ts +5 -4
- package/dist/src/grpc-status.js +52 -6
- package/dist/src/grpc-status.js.map +1 -1
- package/dist/src/invocation-context.d.ts +2 -0
- package/dist/src/invocation-context.js +33 -0
- package/dist/src/invocation-context.js.map +1 -1
- package/dist/src/options.d.ts +150 -1
- package/dist/src/options.js +53 -0
- package/dist/src/options.js.map +1 -1
- package/dist/src/persistence.d.ts +115 -0
- package/dist/src/persistence.js +114 -0
- package/dist/src/persistence.js.map +1 -1
- package/dist/src/rpc.d.ts +53 -0
- package/dist/src/rpc.js +17 -0
- package/dist/src/rpc.js.map +1 -1
- package/dist/src/step.d.ts +163 -1
- package/dist/src/step.js +86 -1
- package/dist/src/step.js.map +1 -1
- package/dist/src/value-mapper.js +48 -18
- package/dist/src/value-mapper.js.map +1 -1
- package/dist/src/wait.d.ts +193 -0
- package/dist/src/wait.js +174 -0
- package/dist/src/wait.js.map +1 -1
- package/dist/src/worker-dispatcher.js +67 -35
- package/dist/src/worker-dispatcher.js.map +1 -1
- package/dist/src/worker.d.ts +30 -1
- package/dist/src/worker.js +48 -2
- package/dist/src/worker.js.map +1 -1
- package/native/linux-aarch64/dex_blob_cache_node.node +0 -0
- package/native/linux-x86_64/dex_blob_cache_node.node +0 -0
- package/native/macos-aarch64/dex_blob_cache_node.node +0 -0
- package/native/macos-x86_64/dex_blob_cache_node.node +0 -0
- package/native/windows-x86_64/dex_blob_cache_node.node +0 -0
- package/package.json +2 -1
package/dist/src/wait.d.ts
CHANGED
|
@@ -1,57 +1,250 @@
|
|
|
1
1
|
import type { Codec } from "./codec.js";
|
|
2
2
|
import type { Context } from "./context.js";
|
|
3
|
+
/** Describes one durable Timer or Channel readiness condition. */
|
|
3
4
|
export interface Condition {
|
|
5
|
+
/** Condition family interpreted by Dex. */
|
|
4
6
|
readonly kind: "timer" | "channel";
|
|
7
|
+
/** Optional stable ID unique within the Wait tree. */
|
|
5
8
|
readonly conditionId?: string;
|
|
9
|
+
/** Timer delay in non-negative milliseconds. */
|
|
6
10
|
readonly durationMs?: number;
|
|
11
|
+
/** Physical Channel name for a Channel condition. */
|
|
7
12
|
readonly channelName?: string;
|
|
13
|
+
/** ChannelMap instance for a map condition. */
|
|
8
14
|
readonly instance?: string;
|
|
15
|
+
/** Inclusive lower queued-value bound. */
|
|
9
16
|
readonly atLeast?: number;
|
|
17
|
+
/** Inclusive upper queued-value bound. */
|
|
10
18
|
readonly atMost?: number;
|
|
11
19
|
}
|
|
20
|
+
/** Groups Conditions that must become ready together. */
|
|
12
21
|
export interface ConditionCombination {
|
|
22
|
+
/** Ordered Conditions in this all-of group. */
|
|
13
23
|
readonly conditions: readonly Condition[];
|
|
14
24
|
}
|
|
25
|
+
/** Creates all-of Condition groups for `Wait.anyCombinationOf`. */
|
|
15
26
|
export declare const ConditionCombination: Readonly<{
|
|
27
|
+
/**
|
|
28
|
+
* Groups conditions that must all become ready together.
|
|
29
|
+
* @param conditions - Conditions in stable evaluation order.
|
|
30
|
+
* @returns A group with the conditions.
|
|
31
|
+
*/
|
|
16
32
|
of(...conditions: readonly Condition[]): ConditionCombination;
|
|
17
33
|
}>;
|
|
34
|
+
/** Creates durable Timer conditions without blocking a worker thread. */
|
|
18
35
|
export declare const Timer: Readonly<{
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Timer ready after a non-negative delay.
|
|
38
|
+
* @param durationMs - Durable delay in milliseconds.
|
|
39
|
+
* @param conditionId - Optional stable ID used by skip-Timer APIs.
|
|
40
|
+
* @returns A Timer condition accepted by Wait factories.
|
|
41
|
+
*/
|
|
19
42
|
byDuration(durationMs: number, conditionId?: string): Condition;
|
|
20
43
|
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Defines a typed, durable singleton message stream owned by a Flow.
|
|
46
|
+
* @typeParam T - Type of every published value.
|
|
47
|
+
*/
|
|
21
48
|
export declare class Channel<T> {
|
|
22
49
|
readonly name: string;
|
|
23
50
|
readonly codec: Codec<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a Channel definition.
|
|
53
|
+
* @param name - Non-empty name unique within the Flow.
|
|
54
|
+
* @param codec - Element codec.
|
|
55
|
+
*/
|
|
24
56
|
constructor(name: string, codec: Codec<T>);
|
|
57
|
+
/**
|
|
58
|
+
* Stages one value to append with the current decision.
|
|
59
|
+
* @param context - Current Step or RPC Context.
|
|
60
|
+
* @param value - Typed value to append.
|
|
61
|
+
*/
|
|
25
62
|
publish(context: Context, value: T): void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the current queued value count.
|
|
65
|
+
* @param context - Current Step or RPC Context.
|
|
66
|
+
* @returns Non-negative queued value count.
|
|
67
|
+
*/
|
|
26
68
|
size(context: Context): number;
|
|
69
|
+
/**
|
|
70
|
+
* Returns values selected by this Step's satisfied condition.
|
|
71
|
+
* @param context - Current Step Context.
|
|
72
|
+
* @returns Ordered values, or an empty array when this Channel was not selected.
|
|
73
|
+
*/
|
|
27
74
|
results(context: Context): readonly T[];
|
|
75
|
+
/**
|
|
76
|
+
* Creates a condition consuming exactly one value.
|
|
77
|
+
* @param conditionId - Optional stable condition identifier.
|
|
78
|
+
* @returns An exact-one Channel condition.
|
|
79
|
+
*/
|
|
28
80
|
forOne(conditionId?: string): Condition;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a condition consuming exactly `count` values.
|
|
83
|
+
* @param count - Required non-negative count.
|
|
84
|
+
* @param conditionId - Optional stable condition identifier.
|
|
85
|
+
* @returns A condition with equal lower and upper bounds.
|
|
86
|
+
*/
|
|
29
87
|
forN(count: number, conditionId?: string): Condition;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a condition requiring at least `count` values.
|
|
90
|
+
* @param count - Inclusive non-negative lower bound.
|
|
91
|
+
* @param conditionId - Optional stable condition identifier.
|
|
92
|
+
* @returns A condition without an upper bound.
|
|
93
|
+
*/
|
|
30
94
|
atLeast(count: number, conditionId?: string): Condition;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a condition consuming at most `count` available values.
|
|
97
|
+
* @param count - Inclusive non-negative upper bound.
|
|
98
|
+
* @param conditionId - Optional stable condition identifier.
|
|
99
|
+
* @returns A condition without a positive lower bound.
|
|
100
|
+
*/
|
|
31
101
|
atMost(count: number, conditionId?: string): Condition;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a bounded condition for queued Channel values.
|
|
104
|
+
* @param atLeast - Optional inclusive lower bound.
|
|
105
|
+
* @param atMost - Optional inclusive upper bound.
|
|
106
|
+
* @param conditionId - Optional stable condition identifier.
|
|
107
|
+
* @returns A validated Channel condition.
|
|
108
|
+
*/
|
|
32
109
|
range(atLeast?: number, atMost?: number, conditionId?: string): Condition;
|
|
33
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Defines keyed Channel instances that share one typed schema.
|
|
113
|
+
* @typeParam T - Type of every published value.
|
|
114
|
+
*/
|
|
34
115
|
export declare class ChannelMap<T> {
|
|
35
116
|
readonly name: string;
|
|
36
117
|
readonly codec: Codec<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Creates a ChannelMap definition.
|
|
120
|
+
* @param name - Non-empty name unique within the Flow.
|
|
121
|
+
* @param codec - Element codec shared by every instance.
|
|
122
|
+
*/
|
|
37
123
|
constructor(name: string, codec: Codec<T>);
|
|
124
|
+
/**
|
|
125
|
+
* Stages one value for a ChannelMap instance.
|
|
126
|
+
* @param context - Current Step or RPC Context.
|
|
127
|
+
* @param instance - Non-empty logical map key.
|
|
128
|
+
* @param value - Typed value to append.
|
|
129
|
+
*/
|
|
38
130
|
publish(context: Context, instance: string, value: T): void;
|
|
131
|
+
/**
|
|
132
|
+
* Returns one instance's queued value count.
|
|
133
|
+
* @param context - Current Step or RPC Context.
|
|
134
|
+
* @param instance - Non-empty logical map key.
|
|
135
|
+
* @returns Non-negative queued value count.
|
|
136
|
+
*/
|
|
39
137
|
size(context: Context, instance: string): number;
|
|
138
|
+
/**
|
|
139
|
+
* Returns the number of non-empty instances visible to the current RPC.
|
|
140
|
+
* @param context - Current RPC Context.
|
|
141
|
+
* @returns The number of keys after including publications buffered by this RPC.
|
|
142
|
+
*/
|
|
143
|
+
getMapSize(context: Context): number;
|
|
144
|
+
/**
|
|
145
|
+
* Returns decoded non-empty instance keys in ascending order.
|
|
146
|
+
* @param context - Current RPC Context.
|
|
147
|
+
* @returns Keys including publications buffered by the current RPC.
|
|
148
|
+
*/
|
|
149
|
+
getAllInstanceKeys(context: Context): readonly string[];
|
|
150
|
+
/**
|
|
151
|
+
* Returns values selected for one instance by the satisfied condition.
|
|
152
|
+
* @param context - Current Step Context.
|
|
153
|
+
* @param instance - Non-empty logical map key.
|
|
154
|
+
* @returns Ordered values for this Step execution.
|
|
155
|
+
*/
|
|
40
156
|
results(context: Context, instance: string): readonly T[];
|
|
157
|
+
/**
|
|
158
|
+
* Creates an instance condition consuming exactly one value.
|
|
159
|
+
* @param instance - Non-empty logical map key.
|
|
160
|
+
* @param conditionId - Optional stable condition identifier.
|
|
161
|
+
* @returns An exact-one instance condition.
|
|
162
|
+
*/
|
|
41
163
|
forOne(instance: string, conditionId?: string): Condition;
|
|
164
|
+
/**
|
|
165
|
+
* Creates an instance condition consuming exactly `count` values.
|
|
166
|
+
* @param instance - Non-empty logical map key.
|
|
167
|
+
* @param count - Required non-negative count.
|
|
168
|
+
* @param conditionId - Optional stable condition identifier.
|
|
169
|
+
* @returns A condition with equal bounds.
|
|
170
|
+
*/
|
|
42
171
|
forN(instance: string, count: number, conditionId?: string): Condition;
|
|
172
|
+
/**
|
|
173
|
+
* Creates an instance condition requiring at least `count` values.
|
|
174
|
+
* @param instance - Non-empty logical map key.
|
|
175
|
+
* @param count - Inclusive non-negative lower bound.
|
|
176
|
+
* @param conditionId - Optional stable condition identifier.
|
|
177
|
+
* @returns A condition without an upper bound.
|
|
178
|
+
*/
|
|
43
179
|
atLeast(instance: string, count: number, conditionId?: string): Condition;
|
|
180
|
+
/**
|
|
181
|
+
* Creates an instance condition consuming at most `count` values.
|
|
182
|
+
* @param instance - Non-empty logical map key.
|
|
183
|
+
* @param count - Inclusive non-negative upper bound.
|
|
184
|
+
* @param conditionId - Optional stable condition identifier.
|
|
185
|
+
* @returns A condition without a positive lower bound.
|
|
186
|
+
*/
|
|
44
187
|
atMost(instance: string, count: number, conditionId?: string): Condition;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a bounded condition for one ChannelMap instance.
|
|
190
|
+
* @param instance - Non-empty logical map key.
|
|
191
|
+
* @param atLeast - Optional inclusive lower bound.
|
|
192
|
+
* @param atMost - Optional inclusive upper bound.
|
|
193
|
+
* @param conditionId - Optional stable condition identifier.
|
|
194
|
+
* @returns A validated instance condition.
|
|
195
|
+
*/
|
|
45
196
|
range(instance: string, atLeast?: number, atMost?: number, conditionId?: string): Condition;
|
|
46
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Describes the durable readiness rule evaluated before a Step executes.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const approvals = new Channel("approvals", stringCodec);
|
|
204
|
+
* const wait = Wait.anyOf(
|
|
205
|
+
* approvals.forOne("approved"),
|
|
206
|
+
* Timer.byDuration(5 * 60_000, "timeout"),
|
|
207
|
+
* );
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
47
210
|
export type Wait = Readonly<{
|
|
211
|
+
/** Combination rule interpreted by Dex. */
|
|
48
212
|
kind: "skipImmediately" | "allOf" | "anyOf" | "anyCombinationOf";
|
|
213
|
+
/** Direct conditions for all-of or any-of waits. */
|
|
49
214
|
conditions: readonly Condition[];
|
|
215
|
+
/** Alternative all-of groups for any-combination waits. */
|
|
50
216
|
combinations: readonly ConditionCombination[];
|
|
51
217
|
}>;
|
|
218
|
+
/** Creates durable Step Wait values. */
|
|
52
219
|
export declare const Wait: Readonly<{
|
|
220
|
+
/**
|
|
221
|
+
* Creates an immediate Wait.
|
|
222
|
+
* @returns A Wait that proceeds to `execute` immediately.
|
|
223
|
+
*/
|
|
53
224
|
skipImmediately(): Wait;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a Wait for one condition.
|
|
227
|
+
* @param condition - The only readiness condition.
|
|
228
|
+
* @returns An all-of Wait with the condition.
|
|
229
|
+
*/
|
|
230
|
+
until(condition: Condition): Wait;
|
|
231
|
+
/**
|
|
232
|
+
* Creates a Wait requiring every condition.
|
|
233
|
+
* @param conditions - Conditions evaluated as one all-of group.
|
|
234
|
+
* @returns An all-of Wait.
|
|
235
|
+
*/
|
|
54
236
|
allOf(...conditions: readonly Condition[]): Wait;
|
|
237
|
+
/**
|
|
238
|
+
* Creates a Wait that continues when any condition is ready.
|
|
239
|
+
* @param conditions - Alternative readiness conditions.
|
|
240
|
+
* @returns An any-of Wait.
|
|
241
|
+
*/
|
|
55
242
|
anyOf(...conditions: readonly Condition[]): Wait;
|
|
243
|
+
/**
|
|
244
|
+
* Creates a Wait accepting any complete condition combination.
|
|
245
|
+
* Every Condition requires a non-empty user ID; the same instance may be reused.
|
|
246
|
+
* @param combinations - Alternative all-of condition groups.
|
|
247
|
+
* @returns An any-combination Wait.
|
|
248
|
+
*/
|
|
56
249
|
anyCombinationOf(...combinations: readonly ConditionCombination[]): Wait;
|
|
57
250
|
}>;
|
package/dist/src/wait.js
CHANGED
|
@@ -6,12 +6,25 @@
|
|
|
6
6
|
//
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
|
|
8
8
|
import { requireConditionId, requireName, validateChannelBounds, } from "./validation.js";
|
|
9
|
+
/** Creates all-of Condition groups for `Wait.anyCombinationOf`. */
|
|
9
10
|
export const ConditionCombination = Object.freeze({
|
|
11
|
+
/**
|
|
12
|
+
* Groups conditions that must all become ready together.
|
|
13
|
+
* @param conditions - Conditions in stable evaluation order.
|
|
14
|
+
* @returns A group with the conditions.
|
|
15
|
+
*/
|
|
10
16
|
of(...conditions) {
|
|
11
17
|
return { conditions };
|
|
12
18
|
},
|
|
13
19
|
});
|
|
20
|
+
/** Creates durable Timer conditions without blocking a worker thread. */
|
|
14
21
|
export const Timer = Object.freeze({
|
|
22
|
+
/**
|
|
23
|
+
* Creates a Timer ready after a non-negative delay.
|
|
24
|
+
* @param durationMs - Durable delay in milliseconds.
|
|
25
|
+
* @param conditionId - Optional stable ID used by skip-Timer APIs.
|
|
26
|
+
* @returns A Timer condition accepted by Wait factories.
|
|
27
|
+
*/
|
|
15
28
|
byDuration(durationMs, conditionId) {
|
|
16
29
|
if (durationMs < 0 || !Number.isFinite(durationMs)) {
|
|
17
30
|
throw new RangeError("timer duration must be non-negative");
|
|
@@ -24,35 +37,89 @@ export const Timer = Object.freeze({
|
|
|
24
37
|
};
|
|
25
38
|
},
|
|
26
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Defines a typed, durable singleton message stream owned by a Flow.
|
|
42
|
+
* @typeParam T - Type of every published value.
|
|
43
|
+
*/
|
|
27
44
|
export class Channel {
|
|
28
45
|
name;
|
|
29
46
|
codec;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a Channel definition.
|
|
49
|
+
* @param name - Non-empty name unique within the Flow.
|
|
50
|
+
* @param codec - Element codec.
|
|
51
|
+
*/
|
|
30
52
|
constructor(name, codec) {
|
|
31
53
|
this.name = name;
|
|
32
54
|
this.codec = codec;
|
|
33
55
|
requireName(name);
|
|
34
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Stages one value to append with the current decision.
|
|
59
|
+
* @param context - Current Step or RPC Context.
|
|
60
|
+
* @param value - Typed value to append.
|
|
61
|
+
*/
|
|
35
62
|
publish(context, value) {
|
|
36
63
|
context.publish(this, value);
|
|
37
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current queued value count.
|
|
67
|
+
* @param context - Current Step or RPC Context.
|
|
68
|
+
* @returns Non-negative queued value count.
|
|
69
|
+
*/
|
|
38
70
|
size(context) {
|
|
39
71
|
return context.channelSize(this);
|
|
40
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns values selected by this Step's satisfied condition.
|
|
75
|
+
* @param context - Current Step Context.
|
|
76
|
+
* @returns Ordered values, or an empty array when this Channel was not selected.
|
|
77
|
+
*/
|
|
41
78
|
results(context) {
|
|
42
79
|
return context.channelResults(this);
|
|
43
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a condition consuming exactly one value.
|
|
83
|
+
* @param conditionId - Optional stable condition identifier.
|
|
84
|
+
* @returns An exact-one Channel condition.
|
|
85
|
+
*/
|
|
44
86
|
forOne(conditionId) {
|
|
45
87
|
return this.range(1, 1, conditionId);
|
|
46
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a condition consuming exactly `count` values.
|
|
91
|
+
* @param count - Required non-negative count.
|
|
92
|
+
* @param conditionId - Optional stable condition identifier.
|
|
93
|
+
* @returns A condition with equal lower and upper bounds.
|
|
94
|
+
*/
|
|
47
95
|
forN(count, conditionId) {
|
|
48
96
|
return this.range(count, count, conditionId);
|
|
49
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates a condition requiring at least `count` values.
|
|
100
|
+
* @param count - Inclusive non-negative lower bound.
|
|
101
|
+
* @param conditionId - Optional stable condition identifier.
|
|
102
|
+
* @returns A condition without an upper bound.
|
|
103
|
+
*/
|
|
50
104
|
atLeast(count, conditionId) {
|
|
51
105
|
return this.range(count, undefined, conditionId);
|
|
52
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a condition consuming at most `count` available values.
|
|
109
|
+
* @param count - Inclusive non-negative upper bound.
|
|
110
|
+
* @param conditionId - Optional stable condition identifier.
|
|
111
|
+
* @returns A condition without a positive lower bound.
|
|
112
|
+
*/
|
|
53
113
|
atMost(count, conditionId) {
|
|
54
114
|
return this.range(undefined, count, conditionId);
|
|
55
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Creates a bounded condition for queued Channel values.
|
|
118
|
+
* @param atLeast - Optional inclusive lower bound.
|
|
119
|
+
* @param atMost - Optional inclusive upper bound.
|
|
120
|
+
* @param conditionId - Optional stable condition identifier.
|
|
121
|
+
* @returns A validated Channel condition.
|
|
122
|
+
*/
|
|
56
123
|
range(atLeast, atMost, conditionId) {
|
|
57
124
|
validateChannelBounds(atLeast, atMost);
|
|
58
125
|
requireConditionId(conditionId);
|
|
@@ -65,35 +132,113 @@ export class Channel {
|
|
|
65
132
|
};
|
|
66
133
|
}
|
|
67
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Defines keyed Channel instances that share one typed schema.
|
|
137
|
+
* @typeParam T - Type of every published value.
|
|
138
|
+
*/
|
|
68
139
|
export class ChannelMap {
|
|
69
140
|
name;
|
|
70
141
|
codec;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a ChannelMap definition.
|
|
144
|
+
* @param name - Non-empty name unique within the Flow.
|
|
145
|
+
* @param codec - Element codec shared by every instance.
|
|
146
|
+
*/
|
|
71
147
|
constructor(name, codec) {
|
|
72
148
|
this.name = name;
|
|
73
149
|
this.codec = codec;
|
|
74
150
|
requireName(name);
|
|
75
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Stages one value for a ChannelMap instance.
|
|
154
|
+
* @param context - Current Step or RPC Context.
|
|
155
|
+
* @param instance - Non-empty logical map key.
|
|
156
|
+
* @param value - Typed value to append.
|
|
157
|
+
*/
|
|
76
158
|
publish(context, instance, value) {
|
|
77
159
|
context.publish(this, value, instance);
|
|
78
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns one instance's queued value count.
|
|
163
|
+
* @param context - Current Step or RPC Context.
|
|
164
|
+
* @param instance - Non-empty logical map key.
|
|
165
|
+
* @returns Non-negative queued value count.
|
|
166
|
+
*/
|
|
79
167
|
size(context, instance) {
|
|
80
168
|
return context.channelSize(this, instance);
|
|
81
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns the number of non-empty instances visible to the current RPC.
|
|
172
|
+
* @param context - Current RPC Context.
|
|
173
|
+
* @returns The number of keys after including publications buffered by this RPC.
|
|
174
|
+
*/
|
|
175
|
+
getMapSize(context) {
|
|
176
|
+
return this.getAllInstanceKeys(context).length;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns decoded non-empty instance keys in ascending order.
|
|
180
|
+
* @param context - Current RPC Context.
|
|
181
|
+
* @returns Keys including publications buffered by the current RPC.
|
|
182
|
+
*/
|
|
183
|
+
getAllInstanceKeys(context) {
|
|
184
|
+
return context.channelMapKeys(this);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns values selected for one instance by the satisfied condition.
|
|
188
|
+
* @param context - Current Step Context.
|
|
189
|
+
* @param instance - Non-empty logical map key.
|
|
190
|
+
* @returns Ordered values for this Step execution.
|
|
191
|
+
*/
|
|
82
192
|
results(context, instance) {
|
|
83
193
|
return context.channelResults(this, instance);
|
|
84
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Creates an instance condition consuming exactly one value.
|
|
197
|
+
* @param instance - Non-empty logical map key.
|
|
198
|
+
* @param conditionId - Optional stable condition identifier.
|
|
199
|
+
* @returns An exact-one instance condition.
|
|
200
|
+
*/
|
|
85
201
|
forOne(instance, conditionId) {
|
|
86
202
|
return this.range(instance, 1, 1, conditionId);
|
|
87
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Creates an instance condition consuming exactly `count` values.
|
|
206
|
+
* @param instance - Non-empty logical map key.
|
|
207
|
+
* @param count - Required non-negative count.
|
|
208
|
+
* @param conditionId - Optional stable condition identifier.
|
|
209
|
+
* @returns A condition with equal bounds.
|
|
210
|
+
*/
|
|
88
211
|
forN(instance, count, conditionId) {
|
|
89
212
|
return this.range(instance, count, count, conditionId);
|
|
90
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates an instance condition requiring at least `count` values.
|
|
216
|
+
* @param instance - Non-empty logical map key.
|
|
217
|
+
* @param count - Inclusive non-negative lower bound.
|
|
218
|
+
* @param conditionId - Optional stable condition identifier.
|
|
219
|
+
* @returns A condition without an upper bound.
|
|
220
|
+
*/
|
|
91
221
|
atLeast(instance, count, conditionId) {
|
|
92
222
|
return this.range(instance, count, undefined, conditionId);
|
|
93
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Creates an instance condition consuming at most `count` values.
|
|
226
|
+
* @param instance - Non-empty logical map key.
|
|
227
|
+
* @param count - Inclusive non-negative upper bound.
|
|
228
|
+
* @param conditionId - Optional stable condition identifier.
|
|
229
|
+
* @returns A condition without a positive lower bound.
|
|
230
|
+
*/
|
|
94
231
|
atMost(instance, count, conditionId) {
|
|
95
232
|
return this.range(instance, undefined, count, conditionId);
|
|
96
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Creates a bounded condition for one ChannelMap instance.
|
|
236
|
+
* @param instance - Non-empty logical map key.
|
|
237
|
+
* @param atLeast - Optional inclusive lower bound.
|
|
238
|
+
* @param atMost - Optional inclusive upper bound.
|
|
239
|
+
* @param conditionId - Optional stable condition identifier.
|
|
240
|
+
* @returns A validated instance condition.
|
|
241
|
+
*/
|
|
97
242
|
range(instance, atLeast, atMost, conditionId) {
|
|
98
243
|
validateChannelBounds(atLeast, atMost);
|
|
99
244
|
requireConditionId(conditionId);
|
|
@@ -107,16 +252,45 @@ export class ChannelMap {
|
|
|
107
252
|
};
|
|
108
253
|
}
|
|
109
254
|
}
|
|
255
|
+
/** Creates durable Step Wait values. */
|
|
110
256
|
export const Wait = Object.freeze({
|
|
257
|
+
/**
|
|
258
|
+
* Creates an immediate Wait.
|
|
259
|
+
* @returns A Wait that proceeds to `execute` immediately.
|
|
260
|
+
*/
|
|
111
261
|
skipImmediately() {
|
|
112
262
|
return { kind: "skipImmediately", conditions: [], combinations: [] };
|
|
113
263
|
},
|
|
264
|
+
/**
|
|
265
|
+
* Creates a Wait for one condition.
|
|
266
|
+
* @param condition - The only readiness condition.
|
|
267
|
+
* @returns An all-of Wait with the condition.
|
|
268
|
+
*/
|
|
269
|
+
until(condition) {
|
|
270
|
+
return Wait.allOf(condition);
|
|
271
|
+
},
|
|
272
|
+
/**
|
|
273
|
+
* Creates a Wait requiring every condition.
|
|
274
|
+
* @param conditions - Conditions evaluated as one all-of group.
|
|
275
|
+
* @returns An all-of Wait.
|
|
276
|
+
*/
|
|
114
277
|
allOf(...conditions) {
|
|
115
278
|
return { kind: "allOf", conditions, combinations: [] };
|
|
116
279
|
},
|
|
280
|
+
/**
|
|
281
|
+
* Creates a Wait that continues when any condition is ready.
|
|
282
|
+
* @param conditions - Alternative readiness conditions.
|
|
283
|
+
* @returns An any-of Wait.
|
|
284
|
+
*/
|
|
117
285
|
anyOf(...conditions) {
|
|
118
286
|
return { kind: "anyOf", conditions, combinations: [] };
|
|
119
287
|
},
|
|
288
|
+
/**
|
|
289
|
+
* Creates a Wait accepting any complete condition combination.
|
|
290
|
+
* Every Condition requires a non-empty user ID; the same instance may be reused.
|
|
291
|
+
* @param combinations - Alternative all-of condition groups.
|
|
292
|
+
* @returns An any-combination Wait.
|
|
293
|
+
*/
|
|
120
294
|
anyCombinationOf(...combinations) {
|
|
121
295
|
return { kind: "anyCombinationOf", conditions: [], combinations };
|
|
122
296
|
},
|
package/dist/src/wait.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/wait.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAIxD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/wait.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,wDAAwD;AAIxD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AA0BzB,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD;;;;OAIG;IACH,EAAE,CAAC,GAAG,UAAgC;QACpC,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;CACF,CAAC,CAAC;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IACjC;;;;;OAKG;IACH,UAAU,CAAC,UAAkB,EAAE,WAAoB;QACjD,IAAI,UAAU,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;QAC9D,CAAC;QACD,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAChC,OAAO;YACL,IAAI,EAAE,OAAO;YACb,UAAU;YACV,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;SACtD,CAAC;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