@resonatehq/sdk 0.3.3 → 0.3.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/dist/async.d.ts +144 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +235 -0
- package/dist/async.js.map +1 -0
- package/dist/core/encoder.d.ts +5 -0
- package/dist/core/encoder.d.ts.map +1 -0
- package/dist/core/encoder.js +3 -0
- package/dist/core/encoder.js.map +1 -0
- package/dist/core/encoders/base64.d.ts +6 -0
- package/dist/core/encoders/base64.d.ts.map +1 -0
- package/dist/core/encoders/base64.js +13 -0
- package/dist/core/encoders/base64.js.map +1 -0
- package/dist/core/encoders/json.d.ts +6 -0
- package/dist/core/encoders/json.d.ts.map +1 -0
- package/dist/core/encoders/json.js +65 -0
- package/dist/core/encoders/json.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +38 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/execution.d.ts +44 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +206 -0
- package/dist/core/execution.js.map +1 -0
- package/dist/core/future.d.ts +54 -0
- package/dist/core/future.d.ts.map +1 -0
- package/dist/core/future.js +101 -0
- package/dist/core/future.js.map +1 -0
- package/dist/core/invocation.d.ts +43 -0
- package/dist/core/invocation.d.ts.map +1 -0
- package/dist/core/invocation.js +77 -0
- package/dist/core/invocation.js.map +1 -0
- package/dist/core/logger.d.ts +10 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +3 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loggers/logger.d.ts +13 -0
- package/dist/core/loggers/logger.d.ts.map +1 -0
- package/dist/core/loggers/logger.js +48 -0
- package/dist/core/loggers/logger.js.map +1 -0
- package/dist/core/options.d.ts +84 -0
- package/dist/core/options.d.ts.map +1 -0
- package/dist/core/options.js +8 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/promises/promises.d.ts +48 -0
- package/dist/core/promises/promises.d.ts.map +1 -0
- package/dist/core/promises/promises.js +133 -0
- package/dist/core/promises/promises.js.map +1 -0
- package/dist/core/promises/types.d.ts +99 -0
- package/dist/core/promises/types.d.ts.map +1 -0
- package/dist/core/promises/types.js +40 -0
- package/dist/core/promises/types.js.map +1 -0
- package/dist/core/retries/retry.d.ts +20 -0
- package/dist/core/retries/retry.d.ts.map +1 -0
- package/dist/core/retries/retry.js +41 -0
- package/dist/core/retries/retry.js.map +1 -0
- package/dist/core/retry.d.ts +27 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +22 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/schedules/types.d.ts +19 -0
- package/dist/core/schedules/types.d.ts.map +1 -0
- package/dist/core/schedules/types.js +8 -0
- package/dist/core/schedules/types.js.map +1 -0
- package/dist/core/storage.d.ts +6 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/core/storage.js +3 -0
- package/dist/core/storage.js.map +1 -0
- package/dist/core/storages/memory.d.ts +8 -0
- package/dist/core/storages/memory.d.ts.map +1 -0
- package/dist/core/storages/memory.js +27 -0
- package/dist/core/storages/memory.js.map +1 -0
- package/dist/core/storages/withTimeout.d.ts +10 -0
- package/dist/core/storages/withTimeout.d.ts.map +1 -0
- package/dist/core/storages/withTimeout.js +43 -0
- package/dist/core/storages/withTimeout.js.map +1 -0
- package/dist/core/store.d.ts +139 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +3 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/stores/local.d.ts +54 -0
- package/dist/core/stores/local.d.ts.map +1 -0
- package/dist/core/stores/local.js +399 -0
- package/dist/core/stores/local.js.map +1 -0
- package/dist/core/stores/remote.d.ts +48 -0
- package/dist/core/stores/remote.d.ts.map +1 -0
- package/dist/core/stores/remote.js +407 -0
- package/dist/core/stores/remote.js.map +1 -0
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +19 -0
- package/dist/core/utils.js.map +1 -0
- package/dist/generator.d.ts +187 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +426 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/resonate.d.ts +74 -0
- package/dist/resonate.d.ts.map +1 -0
- package/dist/resonate.js +172 -0
- package/dist/resonate.js.map +1 -0
- package/package.json +15 -11
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratorExecution = exports.DeferredExecution = exports.OrdinaryExecution = exports.Execution = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const future_1 = require("./future");
|
|
6
|
+
const promises_1 = require("./promises/promises");
|
|
7
|
+
/////////////////////////////////////////////////////////////////////
|
|
8
|
+
// Execution
|
|
9
|
+
/////////////////////////////////////////////////////////////////////
|
|
10
|
+
class Execution {
|
|
11
|
+
invocation;
|
|
12
|
+
promise = null;
|
|
13
|
+
/**
|
|
14
|
+
* Represents an execution of a Resonate function invocation.
|
|
15
|
+
*
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param invocation - An invocation correpsonding to the Resonate function.
|
|
18
|
+
*/
|
|
19
|
+
constructor(invocation) {
|
|
20
|
+
this.invocation = invocation;
|
|
21
|
+
}
|
|
22
|
+
execute() {
|
|
23
|
+
if (this.promise) {
|
|
24
|
+
return this.promise;
|
|
25
|
+
}
|
|
26
|
+
const forkPromise = this.fork();
|
|
27
|
+
const joinPromise = forkPromise.then((f) => this.join(f));
|
|
28
|
+
this.promise = new future_1.ResonatePromise(this.invocation.id, forkPromise, joinPromise);
|
|
29
|
+
return this.promise;
|
|
30
|
+
}
|
|
31
|
+
get killed() {
|
|
32
|
+
return this.invocation.root.killed;
|
|
33
|
+
}
|
|
34
|
+
kill(error) {
|
|
35
|
+
// this will mark the entire invocation tree as killed
|
|
36
|
+
this.invocation.root.killed = true;
|
|
37
|
+
// reject only the root invocation
|
|
38
|
+
this.invocation.root.reject(new errors_1.ResonateError("Resonate function killed", errors_1.ErrorCodes.KILLED, error, true));
|
|
39
|
+
}
|
|
40
|
+
tags() {
|
|
41
|
+
if (this.invocation.parent === null) {
|
|
42
|
+
return { ...this.invocation.opts.tags, "resonate:invocation": "true" };
|
|
43
|
+
}
|
|
44
|
+
return this.invocation.opts.tags;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Execution = Execution;
|
|
48
|
+
class OrdinaryExecution extends Execution {
|
|
49
|
+
func;
|
|
50
|
+
retry;
|
|
51
|
+
constructor(invocation, func, retry = invocation.opts.retry) {
|
|
52
|
+
super(invocation);
|
|
53
|
+
this.func = func;
|
|
54
|
+
this.retry = retry;
|
|
55
|
+
}
|
|
56
|
+
async fork() {
|
|
57
|
+
try {
|
|
58
|
+
// create a durable promise
|
|
59
|
+
const promise = await promises_1.DurablePromise.create(this.invocation.opts.store.promises, this.invocation.opts.encoder, this.invocation.id, this.invocation.timeout, {
|
|
60
|
+
idempotencyKey: this.invocation.idempotencyKey,
|
|
61
|
+
headers: this.invocation.headers,
|
|
62
|
+
param: this.invocation.param,
|
|
63
|
+
tags: this.tags(),
|
|
64
|
+
});
|
|
65
|
+
if (promise.pending) {
|
|
66
|
+
// if pending, invoke the function and resolve/reject the durable promise
|
|
67
|
+
await this.run().then((v) => promise.resolve(v, { idempotencyKey: this.invocation.idempotencyKey }), (e) => promise.reject(e, { idempotencyKey: this.invocation.idempotencyKey }));
|
|
68
|
+
}
|
|
69
|
+
// resolve/reject the invocation
|
|
70
|
+
if (promise.resolved) {
|
|
71
|
+
this.invocation.resolve(promise.value());
|
|
72
|
+
}
|
|
73
|
+
else if (promise.rejected || promise.canceled || promise.timedout) {
|
|
74
|
+
this.invocation.reject(promise.error());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// if an error occurs, kill the execution
|
|
79
|
+
this.kill(e);
|
|
80
|
+
}
|
|
81
|
+
return this.invocation.future;
|
|
82
|
+
}
|
|
83
|
+
async join(future) {
|
|
84
|
+
return await future.promise;
|
|
85
|
+
}
|
|
86
|
+
async run() {
|
|
87
|
+
let error;
|
|
88
|
+
// invoke the function according to the retry policy
|
|
89
|
+
for (const delay of this.retry.iterator(this.invocation)) {
|
|
90
|
+
try {
|
|
91
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
92
|
+
return await this.func();
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
error = e;
|
|
96
|
+
// bump the attempt count
|
|
97
|
+
this.invocation.attempt++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// if all attempts fail throw the last error
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.OrdinaryExecution = OrdinaryExecution;
|
|
105
|
+
class DeferredExecution extends Execution {
|
|
106
|
+
constructor(invocation) {
|
|
107
|
+
super(invocation);
|
|
108
|
+
}
|
|
109
|
+
async fork() {
|
|
110
|
+
try {
|
|
111
|
+
// create a durable promise
|
|
112
|
+
const promise = await promises_1.DurablePromise.create(this.invocation.opts.store.promises, this.invocation.opts.encoder, this.invocation.id, this.invocation.timeout, {
|
|
113
|
+
idempotencyKey: this.invocation.idempotencyKey,
|
|
114
|
+
headers: this.invocation.headers,
|
|
115
|
+
param: this.invocation.param,
|
|
116
|
+
tags: this.tags(),
|
|
117
|
+
poll: this.invocation.opts.poll,
|
|
118
|
+
});
|
|
119
|
+
// poll the completion of the durable promise
|
|
120
|
+
promise.completed.then((p) => p.resolved ? this.invocation.resolve(p.value()) : this.invocation.reject(p.error()));
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
// if an error occurs, kill the execution
|
|
124
|
+
this.kill(e);
|
|
125
|
+
}
|
|
126
|
+
return this.invocation.future;
|
|
127
|
+
}
|
|
128
|
+
async join(future) {
|
|
129
|
+
return await future.promise;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.DeferredExecution = DeferredExecution;
|
|
133
|
+
class GeneratorExecution extends Execution {
|
|
134
|
+
generator;
|
|
135
|
+
constructor(invocation, generator) {
|
|
136
|
+
super(invocation);
|
|
137
|
+
this.generator = generator;
|
|
138
|
+
}
|
|
139
|
+
async create() {
|
|
140
|
+
try {
|
|
141
|
+
// create a durable promise
|
|
142
|
+
const promise = await promises_1.DurablePromise.create(this.invocation.opts.store.promises, this.invocation.opts.encoder, this.invocation.id, this.invocation.timeout, {
|
|
143
|
+
idempotencyKey: this.invocation.idempotencyKey,
|
|
144
|
+
headers: this.invocation.headers,
|
|
145
|
+
param: this.invocation.param,
|
|
146
|
+
tags: this.tags(),
|
|
147
|
+
});
|
|
148
|
+
// resolve/reject the invocation if already completed
|
|
149
|
+
if (promise.resolved) {
|
|
150
|
+
this.invocation.resolve(promise.value());
|
|
151
|
+
}
|
|
152
|
+
else if (promise.rejected || promise.canceled || promise.timedout) {
|
|
153
|
+
this.invocation.reject(promise.error());
|
|
154
|
+
}
|
|
155
|
+
return promise;
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
// if an error occurs, kill the execution
|
|
159
|
+
this.kill(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async resolve(promise, value) {
|
|
163
|
+
try {
|
|
164
|
+
// resolve the durable promise
|
|
165
|
+
await promise.resolve(value, { idempotencyKey: this.invocation.idempotencyKey });
|
|
166
|
+
// resolve/reject the invocation
|
|
167
|
+
if (promise.resolved) {
|
|
168
|
+
this.invocation.resolve(promise.value());
|
|
169
|
+
}
|
|
170
|
+
else if (promise.rejected || promise.canceled || promise.timedout) {
|
|
171
|
+
this.invocation.reject(promise.error());
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
// if an error occurs, kill the execution
|
|
176
|
+
this.kill(e);
|
|
177
|
+
}
|
|
178
|
+
return promise;
|
|
179
|
+
}
|
|
180
|
+
async reject(promise, error) {
|
|
181
|
+
try {
|
|
182
|
+
// reject the durable promise
|
|
183
|
+
await promise.reject(error, { idempotencyKey: this.invocation.idempotencyKey });
|
|
184
|
+
// resolve/reject the invocation
|
|
185
|
+
if (promise.resolved) {
|
|
186
|
+
this.invocation.resolve(promise.value());
|
|
187
|
+
}
|
|
188
|
+
else if (promise.rejected || promise.canceled || promise.timedout) {
|
|
189
|
+
this.invocation.reject(promise.error());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
// if an error occurs, kill the execution
|
|
194
|
+
this.kill(e);
|
|
195
|
+
}
|
|
196
|
+
return promise;
|
|
197
|
+
}
|
|
198
|
+
async fork() {
|
|
199
|
+
return this.invocation.future;
|
|
200
|
+
}
|
|
201
|
+
async join(future) {
|
|
202
|
+
return await future.promise;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.GeneratorExecution = GeneratorExecution;
|
|
206
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../lib/core/execution.ts"],"names":[],"mappings":";;;AAAA,qCAAqD;AACrD,qCAAmD;AAEnD,kDAAqD;AAGrD,qEAAqE;AACrE,YAAY;AACZ,qEAAqE;AAErE,MAAsB,SAAS;IASV;IARX,OAAO,GAA8B,IAAI,CAAC;IAElD;;;;;OAKG;IACH,YAAmB,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAG,CAAC;IAEhD,OAAO;QACL,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,WAAW,CAA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AE,CAAC;YACX,yCAAyC;YACzC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAA0B,EAAE,KAAU;QACjD,IAAI,CAAC;YACH,6BAA6B;YAC7B,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC;YAEhF,gCAAgC;YAChC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,CAAC;iBAAM,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACpE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,yCAAyC;YACzC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAES,KAAK,CAAC,IAAI;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAES,KAAK,CAAC,IAAI,CAAC,MAAiB;QACpC,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC;IAC9B,CAAC;CACF;AAlFD,gDAkFC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Invocation } from "./invocation";
|
|
2
|
+
export declare class ResonatePromise<T> extends Promise<T> {
|
|
3
|
+
id: string;
|
|
4
|
+
created: Promise<string>;
|
|
5
|
+
static [Symbol.species]: PromiseConstructor;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the eventual return value of a Resonate function. This is achieved by wrapping a Javscript promise.
|
|
8
|
+
*
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param id - A unique identifier for this promise.
|
|
11
|
+
* @param created - A promise that resolves when the durable promise has been created.
|
|
12
|
+
* @param completed - A promise that resolves when the durable promise has been fulfilled.
|
|
13
|
+
*/
|
|
14
|
+
constructor(id: string, created: Promise<any>, completed: Promise<T>);
|
|
15
|
+
}
|
|
16
|
+
export type Value<T> = {
|
|
17
|
+
kind: "pending";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "resolved";
|
|
20
|
+
value: T;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "rejected";
|
|
23
|
+
error: unknown;
|
|
24
|
+
};
|
|
25
|
+
export declare class Future<T> {
|
|
26
|
+
private invocation;
|
|
27
|
+
promise: Promise<T>;
|
|
28
|
+
private _resolve;
|
|
29
|
+
private _reject;
|
|
30
|
+
readonly kind = "future";
|
|
31
|
+
private _value;
|
|
32
|
+
/**
|
|
33
|
+
* Represents the eventual return value of a Resonate function.
|
|
34
|
+
*
|
|
35
|
+
* @constructor
|
|
36
|
+
* @param invocation - An invocation correpsonding to the Resonate function.
|
|
37
|
+
* @param promise - A promise that resolves to the return value of the Resonate function.
|
|
38
|
+
*/
|
|
39
|
+
constructor(invocation: Invocation<T>, promise: Promise<T>, _resolve: (v: T) => void, _reject: (v?: unknown) => void);
|
|
40
|
+
static deferred<T>(invocation: Invocation<T>): {
|
|
41
|
+
future: Future<T>;
|
|
42
|
+
resolve: (value: T) => void;
|
|
43
|
+
reject: (error: unknown) => void;
|
|
44
|
+
};
|
|
45
|
+
get id(): string;
|
|
46
|
+
get idempotencyKey(): string | undefined;
|
|
47
|
+
get root(): Future<any>;
|
|
48
|
+
get parent(): Future<any> | null;
|
|
49
|
+
get children(): Future<any>[];
|
|
50
|
+
get value(): Value<T>;
|
|
51
|
+
private resolve;
|
|
52
|
+
private reject;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=future.d.ts.map
|
|
@@ -0,0 +1 @@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AAE,WAEL;IAED,IAAI,cAAc,uBAEjB;IAED,IAAI,IAAI,gBAEP;IAED,IAAI,MAAM,uBAET;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,KAAK,aAER;IAED,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,MAAM;CAIf"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Future = exports.ResonatePromise = void 0;
|
|
4
|
+
/////////////////////////////////////////////////////////////////////
|
|
5
|
+
// Promise
|
|
6
|
+
/////////////////////////////////////////////////////////////////////
|
|
7
|
+
class ResonatePromise extends Promise {
|
|
8
|
+
id;
|
|
9
|
+
// resolves to the id of the durable promise
|
|
10
|
+
// can be used to await durable promise creation
|
|
11
|
+
created;
|
|
12
|
+
// You are not expected to understand this (we don't either)
|
|
13
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/@@species
|
|
14
|
+
static [Symbol.species] = Promise;
|
|
15
|
+
/**
|
|
16
|
+
* Represents the eventual return value of a Resonate function. This is achieved by wrapping a Javscript promise.
|
|
17
|
+
*
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param id - A unique identifier for this promise.
|
|
20
|
+
* @param created - A promise that resolves when the durable promise has been created.
|
|
21
|
+
* @param completed - A promise that resolves when the durable promise has been fulfilled.
|
|
22
|
+
*/
|
|
23
|
+
constructor(id, created, completed) {
|
|
24
|
+
// bind the promise to the completed promise
|
|
25
|
+
super((resolve, reject) => {
|
|
26
|
+
completed.then(resolve, reject);
|
|
27
|
+
});
|
|
28
|
+
this.id = id;
|
|
29
|
+
// expose the id when the durable promise has been created
|
|
30
|
+
this.created = created.then(() => this.id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ResonatePromise = ResonatePromise;
|
|
34
|
+
class Future {
|
|
35
|
+
invocation;
|
|
36
|
+
promise;
|
|
37
|
+
_resolve;
|
|
38
|
+
_reject;
|
|
39
|
+
// a discriminate property
|
|
40
|
+
kind = "future";
|
|
41
|
+
// initial value
|
|
42
|
+
_value = { kind: "pending" };
|
|
43
|
+
/**
|
|
44
|
+
* Represents the eventual return value of a Resonate function.
|
|
45
|
+
*
|
|
46
|
+
* @constructor
|
|
47
|
+
* @param invocation - An invocation correpsonding to the Resonate function.
|
|
48
|
+
* @param promise - A promise that resolves to the return value of the Resonate function.
|
|
49
|
+
*/
|
|
50
|
+
constructor(invocation, promise, _resolve, _reject) {
|
|
51
|
+
this.invocation = invocation;
|
|
52
|
+
this.promise = promise;
|
|
53
|
+
this._resolve = _resolve;
|
|
54
|
+
this._reject = _reject;
|
|
55
|
+
}
|
|
56
|
+
static deferred(invocation) {
|
|
57
|
+
let resolve;
|
|
58
|
+
let reject;
|
|
59
|
+
// construct a javascript promise
|
|
60
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
61
|
+
resolve = _resolve;
|
|
62
|
+
reject = _reject;
|
|
63
|
+
});
|
|
64
|
+
// construct a new future
|
|
65
|
+
const future = new Future(invocation, promise, resolve, reject);
|
|
66
|
+
// return future and resolvers
|
|
67
|
+
return {
|
|
68
|
+
future: future,
|
|
69
|
+
resolve: future.resolve.bind(future),
|
|
70
|
+
reject: future.reject.bind(future),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
get id() {
|
|
74
|
+
return this.invocation.id;
|
|
75
|
+
}
|
|
76
|
+
get idempotencyKey() {
|
|
77
|
+
return this.invocation.idempotencyKey;
|
|
78
|
+
}
|
|
79
|
+
get root() {
|
|
80
|
+
return this.invocation.root.future;
|
|
81
|
+
}
|
|
82
|
+
get parent() {
|
|
83
|
+
return this.invocation.parent?.future ?? null;
|
|
84
|
+
}
|
|
85
|
+
get children() {
|
|
86
|
+
return this.invocation.children.map((i) => i.future);
|
|
87
|
+
}
|
|
88
|
+
get value() {
|
|
89
|
+
return this._value;
|
|
90
|
+
}
|
|
91
|
+
resolve(value) {
|
|
92
|
+
this._resolve(value);
|
|
93
|
+
this._value = { kind: "resolved", value };
|
|
94
|
+
}
|
|
95
|
+
reject(error) {
|
|
96
|
+
this._reject(error);
|
|
97
|
+
this._value = { kind: "rejected", error };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.Future = Future;
|
|
101
|
+
//# sourceMappingURL=future.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"future.js","sourceRoot":"","sources":["../../lib/core/future.ts"],"names":[],"mappings":";;;AAEA,qEAAqE;AACrE,UAAU;AACV,qEAAqE;AAErE,MAAa,eAAmB,SAAQ,OAAU;IAkBvC;IAjBT,4CAA4C;IAC5C,gDAAgD;IAChD,OAAO,CAAkB;IAEzB,4DAA4D;IAC5D,qGAAqG;IACrG,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAElC;;;;;;;OAOG;IACH,YACS,EAAU,EACjB,OAAqB,EACrB,SAAqB;QAErB,4CAA4C;QAC5C,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxB,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAPI,OAAE,GAAF,EAAE,CAAQ;QASjB,0DAA0D;QAC1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;;AA7BH,0CA8BC;AAQD,MAAa,MAAM;IAeP;IACD;IACC;IACA;IAjBV,0BAA0B;IACjB,IAAI,GAAG,QAAQ,CAAC;IAEzB,gBAAgB;IACR,MAAM,GAAa,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAE/C;;;;;;OAMG;IACH,YACU,UAAyB,EAC1B,OAAmB,EAClB,QAAwB,EACxB,OAA8B;QAH9B,eAAU,GAAV,UAAU,CAAe;QAC1B,YAAO,GAAP,OAAO,CA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O,OAAO,CAAC,KAAQ;QACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC5C,CAAC;IAEO,MAAM,CAAC,KAAc;QAC3B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC5C,CAAC;CACF;AA3ED,wBA2EC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Future } from "./future";
|
|
2
|
+
import { Options, PartialOptions } from "./options";
|
|
3
|
+
export declare class Invocation<T> {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly version: number;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly idempotencyKey: string | undefined;
|
|
8
|
+
readonly headers: Record<string, string> | undefined;
|
|
9
|
+
readonly param: unknown;
|
|
10
|
+
readonly opts: Options;
|
|
11
|
+
future: Future<T>;
|
|
12
|
+
resolve: (v: T) => void;
|
|
13
|
+
reject: (e: unknown) => void;
|
|
14
|
+
killed: boolean;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
counter: number;
|
|
17
|
+
attempt: number;
|
|
18
|
+
awaited: Future<any>[];
|
|
19
|
+
blocked: Future<any> | null;
|
|
20
|
+
readonly root: Invocation<any>;
|
|
21
|
+
readonly parent: Invocation<any> | null;
|
|
22
|
+
readonly children: Invocation<any>[];
|
|
23
|
+
/**
|
|
24
|
+
* Represents a Resonate function invocation.
|
|
25
|
+
*
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param id - A unique id for this invocation.
|
|
28
|
+
* @param idempotencyKey - An idempotency key used to deduplicate invocations.
|
|
29
|
+
* @param opts - The invocation options.
|
|
30
|
+
* @param parent - The parent invocation.
|
|
31
|
+
*/
|
|
32
|
+
constructor(name: string, version: number, id: string, idempotencyKey: string | undefined, headers: Record<string, string> | undefined, param: unknown, opts: Options, parent?: Invocation<any>);
|
|
33
|
+
get timeout(): number;
|
|
34
|
+
addChild(child: Invocation<any>): void;
|
|
35
|
+
await(future: Future<any>): void;
|
|
36
|
+
block(future: Future<any>): void;
|
|
37
|
+
unblock(): void;
|
|
38
|
+
split(args: [...any, PartialOptions?]): {
|
|
39
|
+
args: any[];
|
|
40
|
+
opts: Options;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=invocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../lib/core/invocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAoB,MAAM,WAAW,CAAC;AAMtE,qBAAa,UAAU,CAAC,CAAC;aA4BL,IAAI,EAAE,MAAM;aACZ,OAAO,EAAE,MAAM;aACf,EAAE,EAAE,MAAM;aACV,cAAc,EAAE,MAAM,GAAG,SAAS;aAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;aAC3C,KAAK,EAAE,OAAO;aACd,IAAI,EAAE,OAAO;IAjC/B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAE7B,MAAM,EAAE,OAAO,CAAS;IAExB,SAAS,EAAE,MAAM,CAAc;IAC/B,OAAO,EAAE,MAAM,CAAK;IACpB,OAAO,EAAE,MAAM,CAAK;IAEpB,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAM;IAC5B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAEnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAM;IAE1C;;;;;;;;OAQG;gBAEe,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,OAAO,EAC7B,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC;IAW1B,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC;IAI/B,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;IAIzB,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;IAIzB,OAAO;IAIP,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,EAAE,cAAc,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE;CAQvE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Invocation = void 0;
|
|
4
|
+
const future_1 = require("./future");
|
|
5
|
+
const options_1 = require("./options");
|
|
6
|
+
/////////////////////////////////////////////////////////////////////
|
|
7
|
+
// Invocation
|
|
8
|
+
/////////////////////////////////////////////////////////////////////
|
|
9
|
+
class Invocation {
|
|
10
|
+
name;
|
|
11
|
+
version;
|
|
12
|
+
id;
|
|
13
|
+
idempotencyKey;
|
|
14
|
+
headers;
|
|
15
|
+
param;
|
|
16
|
+
opts;
|
|
17
|
+
future;
|
|
18
|
+
resolve;
|
|
19
|
+
reject;
|
|
20
|
+
killed = false;
|
|
21
|
+
createdAt = Date.now();
|
|
22
|
+
counter = 0;
|
|
23
|
+
attempt = 0;
|
|
24
|
+
awaited = [];
|
|
25
|
+
blocked = null;
|
|
26
|
+
root;
|
|
27
|
+
parent;
|
|
28
|
+
children = [];
|
|
29
|
+
/**
|
|
30
|
+
* Represents a Resonate function invocation.
|
|
31
|
+
*
|
|
32
|
+
* @constructor
|
|
33
|
+
* @param id - A unique id for this invocation.
|
|
34
|
+
* @param idempotencyKey - An idempotency key used to deduplicate invocations.
|
|
35
|
+
* @param opts - The invocation options.
|
|
36
|
+
* @param parent - The parent invocation.
|
|
37
|
+
*/
|
|
38
|
+
constructor(name, version, id, idempotencyKey, headers, param, opts, parent) {
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.version = version;
|
|
41
|
+
this.id = id;
|
|
42
|
+
this.idempotencyKey = idempotencyKey;
|
|
43
|
+
this.headers = headers;
|
|
44
|
+
this.param = param;
|
|
45
|
+
this.opts = opts;
|
|
46
|
+
const { future, resolve, reject } = future_1.Future.deferred(this);
|
|
47
|
+
this.future = future;
|
|
48
|
+
this.resolve = resolve;
|
|
49
|
+
this.reject = reject;
|
|
50
|
+
this.root = parent?.root ?? this;
|
|
51
|
+
this.parent = parent ?? null;
|
|
52
|
+
}
|
|
53
|
+
get timeout() {
|
|
54
|
+
return Math.min(this.createdAt + this.opts.timeout, this.parent?.timeout ?? Infinity);
|
|
55
|
+
}
|
|
56
|
+
addChild(child) {
|
|
57
|
+
this.children.push(child);
|
|
58
|
+
}
|
|
59
|
+
await(future) {
|
|
60
|
+
this.awaited.push(future);
|
|
61
|
+
}
|
|
62
|
+
block(future) {
|
|
63
|
+
this.blocked = future;
|
|
64
|
+
}
|
|
65
|
+
unblock() {
|
|
66
|
+
this.blocked = null;
|
|
67
|
+
}
|
|
68
|
+
split(args) {
|
|
69
|
+
const opts = args[args.length - 1];
|
|
70
|
+
const parentOpts = this.parent?.opts ?? this.root.opts;
|
|
71
|
+
return (0, options_1.isPartialOptions)(opts)
|
|
72
|
+
? { args: args.slice(0, -1), opts: { ...parentOpts, ...opts, tags: { ...parentOpts.tags, ...opts.tags } } }
|
|
73
|
+
: { args, opts: parentOpts };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Invocation = Invocation;
|
|
77
|
+
//# sourceMappingURL=invocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../../lib/core/invocation.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,uCAAsE;AAEtE,qEAAqE;AACrE,aAAa;AACb,qEAAqE;AAErE,MAAa,UAAU;IA4BH;IACA;IACA;IACA;IACA;IACA;IACA;IAjClB,MAAM,CAAY;IAClB,OAAO,CAAiB;IACxB,MAAM,CAAuB;IAE7B,MAAM,GAAY,KAAK,CAAC;IAExB,SAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IAC/B,OAAO,GAAW,CAAC,CAAC;IACpB,OAAO,GAAW,CAAC,CAAC;IAEpB,OAAO,GAAkB,EAAE,CAAC;IAC5B,OAAO,GAAuB,IAAI,CAAC;IAE1B,IAAI,CAAkB;IACtB,MAAM,CAAyB;IAC/B,QAAQ,GAAsB,EAAE,CAAC;IAE1C;;;;;;;;OAQG;IACH,YACkB,IAAY,EACZ,OAAe,EACf,EAAU,EACV,cAAkC,EAClC,OAA2C,EAC3C,KAAc,EACd,IAAa,EAC7B,MAAwB;QAPR,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,OAAE,GAAF,EAAE,CAAQ;QACV,mBAAc,GAAd,cAAc,CAAoB;QAClC,YAAO,GAAP,OAAO,CAAoC;QAC3C,UAAK,GAAL,KAAK,CAAS;QACd,SAAI,GAAJ,IAAI,CAAS;QAG7B,MAAM,EAAE,MAAM,EAAE,OAAO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,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE;YAC3G,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IACjC,CAAC;CACF;AA1ED,gCA0EC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
2
|
+
export interface ILogger {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
debug(...args: any[]): void;
|
|
5
|
+
info(...args: any[]): void;
|
|
6
|
+
warn(...args: any[]): void;
|
|
7
|
+
error(...args: any[]): void;
|
|
8
|
+
table(...args: any[]): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../lib/core/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/core/logger.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ILogger, LogLevel } from "../logger";
|
|
2
|
+
export declare class Logger implements ILogger {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
private _level;
|
|
5
|
+
constructor(level?: LogLevel);
|
|
6
|
+
debug(...args: any[]): void;
|
|
7
|
+
info(...args: any[]): void;
|
|
8
|
+
warn(...args: any[]): void;
|
|
9
|
+
error(...args: any[]): void;
|
|
10
|
+
table(...args: any[]): void;
|
|
11
|
+
private log;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../lib/core/loggers/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE9C,qBAAa,MAAO,YAAW,OAAO;IAC7B,KAAK,EAAE,QAAQ,CAAC;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,KAAK,CAAC,EAAE,QAAQ;IAmB5B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI1B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3B,OAAO,CAAC,GAAG;CAKZ"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
level;
|
|
6
|
+
_level;
|
|
7
|
+
constructor(level) {
|
|
8
|
+
this.level = level ?? process.env.LOG_LEVEL ?? "info";
|
|
9
|
+
switch (this.level) {
|
|
10
|
+
case "debug":
|
|
11
|
+
this._level = 0;
|
|
12
|
+
break;
|
|
13
|
+
case "info":
|
|
14
|
+
this._level = 1;
|
|
15
|
+
break;
|
|
16
|
+
case "warn":
|
|
17
|
+
this._level = 2;
|
|
18
|
+
break;
|
|
19
|
+
case "error":
|
|
20
|
+
this._level = 3;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
debug(...args) {
|
|
25
|
+
this.log(0, args);
|
|
26
|
+
}
|
|
27
|
+
info(...args) {
|
|
28
|
+
this.log(1, args);
|
|
29
|
+
}
|
|
30
|
+
warn(...args) {
|
|
31
|
+
this.log(2, args);
|
|
32
|
+
}
|
|
33
|
+
error(...args) {
|
|
34
|
+
this.log(3, args);
|
|
35
|
+
}
|
|
36
|
+
table(...args) {
|
|
37
|
+
if (this._level <= 0) {
|
|
38
|
+
console.table(args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
log(level, args) {
|
|
42
|
+
if (this._level <= level) {
|
|
43
|
+
console.log(...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Logger = Logger;
|
|
48
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../lib/core/loggers/logger.ts"],"names":[],"mappings":";;;AAEA,MAAa,MAAM;IACV,KAAK,CAAW;IACf,MAAM,CAAS;IAEvB,YAAY,KAAgB;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,IAAK,OAAO,CAAC,GAAG,CAAC,SAAsB,IAAI,MAAM,CAAC;QAEpE,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,KAAK,OAAO;gBACV,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;gBAChB,MAAM;YACR,KAAK,MAAM;gBACT,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;gBAChB,MAAM;YACR,KAAK,MAAM;gBACT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