@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.
Files changed (105) hide show
  1. package/dist/async.d.ts +144 -0
  2. package/dist/async.d.ts.map +1 -0
  3. package/dist/async.js +235 -0
  4. package/dist/async.js.map +1 -0
  5. package/dist/core/encoder.d.ts +5 -0
  6. package/dist/core/encoder.d.ts.map +1 -0
  7. package/dist/core/encoder.js +3 -0
  8. package/dist/core/encoder.js.map +1 -0
  9. package/dist/core/encoders/base64.d.ts +6 -0
  10. package/dist/core/encoders/base64.d.ts.map +1 -0
  11. package/dist/core/encoders/base64.js +13 -0
  12. package/dist/core/encoders/base64.js.map +1 -0
  13. package/dist/core/encoders/json.d.ts +6 -0
  14. package/dist/core/encoders/json.d.ts.map +1 -0
  15. package/dist/core/encoders/json.js +65 -0
  16. package/dist/core/encoders/json.js.map +1 -0
  17. package/dist/core/errors.d.ts +21 -0
  18. package/dist/core/errors.d.ts.map +1 -0
  19. package/dist/core/errors.js +38 -0
  20. package/dist/core/errors.js.map +1 -0
  21. package/dist/core/execution.d.ts +44 -0
  22. package/dist/core/execution.d.ts.map +1 -0
  23. package/dist/core/execution.js +206 -0
  24. package/dist/core/execution.js.map +1 -0
  25. package/dist/core/future.d.ts +54 -0
  26. package/dist/core/future.d.ts.map +1 -0
  27. package/dist/core/future.js +101 -0
  28. package/dist/core/future.js.map +1 -0
  29. package/dist/core/invocation.d.ts +43 -0
  30. package/dist/core/invocation.d.ts.map +1 -0
  31. package/dist/core/invocation.js +77 -0
  32. package/dist/core/invocation.js.map +1 -0
  33. package/dist/core/logger.d.ts +10 -0
  34. package/dist/core/logger.d.ts.map +1 -0
  35. package/dist/core/logger.js +3 -0
  36. package/dist/core/logger.js.map +1 -0
  37. package/dist/core/loggers/logger.d.ts +13 -0
  38. package/dist/core/loggers/logger.d.ts.map +1 -0
  39. package/dist/core/loggers/logger.js +48 -0
  40. package/dist/core/loggers/logger.js.map +1 -0
  41. package/dist/core/options.d.ts +84 -0
  42. package/dist/core/options.d.ts.map +1 -0
  43. package/dist/core/options.js +8 -0
  44. package/dist/core/options.js.map +1 -0
  45. package/dist/core/promises/promises.d.ts +48 -0
  46. package/dist/core/promises/promises.d.ts.map +1 -0
  47. package/dist/core/promises/promises.js +133 -0
  48. package/dist/core/promises/promises.js.map +1 -0
  49. package/dist/core/promises/types.d.ts +99 -0
  50. package/dist/core/promises/types.d.ts.map +1 -0
  51. package/dist/core/promises/types.js +40 -0
  52. package/dist/core/promises/types.js.map +1 -0
  53. package/dist/core/retries/retry.d.ts +20 -0
  54. package/dist/core/retries/retry.d.ts.map +1 -0
  55. package/dist/core/retries/retry.js +41 -0
  56. package/dist/core/retries/retry.js.map +1 -0
  57. package/dist/core/retry.d.ts +27 -0
  58. package/dist/core/retry.d.ts.map +1 -0
  59. package/dist/core/retry.js +22 -0
  60. package/dist/core/retry.js.map +1 -0
  61. package/dist/core/schedules/types.d.ts +19 -0
  62. package/dist/core/schedules/types.d.ts.map +1 -0
  63. package/dist/core/schedules/types.js +8 -0
  64. package/dist/core/schedules/types.js.map +1 -0
  65. package/dist/core/storage.d.ts +6 -0
  66. package/dist/core/storage.d.ts.map +1 -0
  67. package/dist/core/storage.js +3 -0
  68. package/dist/core/storage.js.map +1 -0
  69. package/dist/core/storages/memory.d.ts +8 -0
  70. package/dist/core/storages/memory.d.ts.map +1 -0
  71. package/dist/core/storages/memory.js +27 -0
  72. package/dist/core/storages/memory.js.map +1 -0
  73. package/dist/core/storages/withTimeout.d.ts +10 -0
  74. package/dist/core/storages/withTimeout.d.ts.map +1 -0
  75. package/dist/core/storages/withTimeout.js +43 -0
  76. package/dist/core/storages/withTimeout.js.map +1 -0
  77. package/dist/core/store.d.ts +139 -0
  78. package/dist/core/store.d.ts.map +1 -0
  79. package/dist/core/store.js +3 -0
  80. package/dist/core/store.js.map +1 -0
  81. package/dist/core/stores/local.d.ts +54 -0
  82. package/dist/core/stores/local.d.ts.map +1 -0
  83. package/dist/core/stores/local.js +399 -0
  84. package/dist/core/stores/local.js.map +1 -0
  85. package/dist/core/stores/remote.d.ts +48 -0
  86. package/dist/core/stores/remote.d.ts.map +1 -0
  87. package/dist/core/stores/remote.js +407 -0
  88. package/dist/core/stores/remote.js.map +1 -0
  89. package/dist/core/utils.d.ts +3 -0
  90. package/dist/core/utils.d.ts.map +1 -0
  91. package/dist/core/utils.js +19 -0
  92. package/dist/core/utils.js.map +1 -0
  93. package/dist/generator.d.ts +187 -0
  94. package/dist/generator.d.ts.map +1 -0
  95. package/dist/generator.js +426 -0
  96. package/dist/generator.js.map +1 -0
  97. package/dist/index.d.ts +4 -0
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +32 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/resonate.d.ts +74 -0
  102. package/dist/resonate.d.ts.map +1 -0
  103. package/dist/resonate.js +172 -0
  104. package/dist/resonate.js.map +1 -0
  105. package/package.json +15 -11
@@ -0,0 +1,144 @@
1
+ import { ResonatePromise } from "./core/future";
2
+ import { Invocation } from "./core/invocation";
3
+ import { ResonateOptions, Options, PartialOptions } from "./core/options";
4
+ import { ResonateBase } from "./resonate";
5
+ export type AFunc = (ctx: Context, ...args: any[]) => any;
6
+ export type IFunc = (info: Info, ...args: any[]) => any;
7
+ export type Params<F> = F extends (ctx: any, ...args: infer P) => any ? P : never;
8
+ export type Return<F> = F extends (...args: any[]) => infer T ? Awaited<T> : never;
9
+ export declare class Resonate extends ResonateBase {
10
+ private scheduler;
11
+ /**
12
+ * Creates a Resonate instance. This is the starting point for using Resonate.
13
+ *
14
+ * @constructor
15
+ * @param opts - A partial {@link ResonateOptions} object.
16
+ */
17
+ constructor(opts?: Partial<ResonateOptions>);
18
+ /**
19
+ * Register a function with Resonate. Registered functions can be invoked by calling {@link run}, or by the returned function.
20
+ *
21
+ * @template F The type of the function.
22
+ * @param name A unique name to identify the function.
23
+ * @param func The function to register with Resonate.
24
+ * @param opts Resonate options, can be constructed by calling {@link options}.
25
+ * @returns Resonate function
26
+ */
27
+ register<F extends AFunc>(name: string, func: F, opts?: Partial<Options>): (id: string, ...args: any) => ResonatePromise<Return<F>>;
28
+ /**
29
+ * Register a function with Resonate. Registered functions can be invoked by calling {@link run}, or by the returned function.
30
+ *
31
+ * @template F The type of the function.
32
+ * @param name A unique name to identify the function.
33
+ * @param version Version of the function.
34
+ * @param func The function to register with Resonate.
35
+ * @param opts Resonate options, can be constructed by calling {@link options}.
36
+ * @returns Resonate function
37
+ */
38
+ register<F extends AFunc>(name: string, version: number, func: F, opts?: Partial<Options>): (id: string, ...args: any) => ResonatePromise<Return<F>>;
39
+ /**
40
+ * Register a module with Resonate. Registered functions can be invoked by calling {@link run}.
41
+ *
42
+ * @template F The type of the function.
43
+ * @param module The module to register with Resonate.
44
+ * @param opts Resonate options, can be constructed by calling {@link options}.
45
+ * @returns Resonate function
46
+ */
47
+ registerModule<F extends AFunc>(module: Record<string, F>, opts?: Partial<Options>): void;
48
+ protected execute<F extends AFunc>(name: string, version: number, id: string, func: F, args: Params<F>, opts: Options): ResonatePromise<Return<F>>;
49
+ }
50
+ export declare class Info {
51
+ private invocation;
52
+ constructor(invocation: Invocation<any>);
53
+ /**
54
+ * The running count of function execution attempts.
55
+ */
56
+ get attempt(): number;
57
+ /**
58
+ * Uniquely identifies the function invocation.
59
+ */
60
+ get id(): string;
61
+ /**
62
+ * Deduplicates function invocations with the same id.
63
+ */
64
+ get idempotencyKey(): string | undefined;
65
+ /**
66
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
67
+ */
68
+ get timeout(): number;
69
+ /**
70
+ * The resonate function version.
71
+ */
72
+ get version(): number;
73
+ }
74
+ export declare class Context {
75
+ private invocation;
76
+ constructor(invocation: Invocation<any>);
77
+ /**
78
+ * The running count of child function invocations.
79
+ */
80
+ get counter(): number;
81
+ /**
82
+ * Uniquely identifies the function invocation.
83
+ */
84
+ get id(): string;
85
+ /**
86
+ * Deduplicates function invocations with the same id.
87
+ */
88
+ get idempotencyKey(): string | undefined;
89
+ /**
90
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
91
+ */
92
+ get timeout(): number;
93
+ /**
94
+ * The resonate function version.
95
+ */
96
+ get version(): number;
97
+ /**
98
+ * Invoke a function.
99
+ *
100
+ * @template F The type of the function.
101
+ * @param func The function to invoke.
102
+ * @param args The function arguments, optionally followed by {@link options}.
103
+ * @returns A promise that resolves to the return value of the function.
104
+ */
105
+ run<F extends AFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): ResonatePromise<Return<F>>;
106
+ /**
107
+ * Invoke a remote function.
108
+ *
109
+ * @template T The return type of the remote function.
110
+ * @param func The id of the remote function.
111
+ * @param args The arguments to pass to the remote function.
112
+ * @param opts Optional {@link options}.
113
+ * @returns A promise that resolves to the resolved value of the remote function.
114
+ */
115
+ run<T>(func: string, args: any, opts?: PartialOptions): ResonatePromise<T>;
116
+ /**
117
+ * Invoke a remote function.
118
+ *
119
+ * @template T The return type of the remote function.
120
+ * @param func The id of the remote function.
121
+ * @param opts Optional {@link options}.
122
+ * @returns A promise that resolves to the resolved value of the remote function.
123
+ */
124
+ run<T>(func: string, opts?: PartialOptions): ResonatePromise<T>;
125
+ /**
126
+ * Invoke an io function.
127
+ *
128
+ * @template F The type of the function.
129
+ * @param func The function to invoke.
130
+ * @param args The function arguments, optionally followed by {@link options}.
131
+ * @returns A promise that resolves to the return value of the function.
132
+ */
133
+ io<F extends IFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): ResonatePromise<Return<F>>;
134
+ /**
135
+ * Construct options.
136
+ *
137
+ * @param opts A partial {@link Options} object.
138
+ * @returns Options with the __resonate flag set.
139
+ */
140
+ options(opts?: Partial<Options>): Partial<Options> & {
141
+ __resonate: true;
142
+ };
143
+ }
144
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../lib/async.ts"],"names":[],"mappings":"AACA,O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,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEnG;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC;IAE1E;;;;;;;OAOG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC;IA4C/D;;;;;;;OAOG;IACH,EAAE,CAAC,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IA0BlG;;;;;OAKG;IACH,OAAO,CAAC,IAAI,GAAE,OAAO,CAAC,OAAO,CAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG;QAAE,UAAU,EAAE,IAAI,CAAA;KAAE;CAG9E"}
package/dist/async.js ADDED
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Context = exports.Info = exports.Resonate = void 0;
27
+ const execution_1 = require("./core/execution");
28
+ const invocation_1 = require("./core/invocation");
29
+ const retry_1 = require("./core/retries/retry");
30
+ const utils = __importStar(require("./core/utils"));
31
+ const resonate_1 = require("./resonate");
32
+ /////////////////////////////////////////////////////////////////////
33
+ // Resonate
34
+ /////////////////////////////////////////////////////////////////////
35
+ class Resonate extends resonate_1.ResonateBase {
36
+ scheduler;
37
+ /**
38
+ * Creates a Resonate instance. This is the starting point for using Resonate.
39
+ *
40
+ * @constructor
41
+ * @param opts - A partial {@link ResonateOptions} object.
42
+ */
43
+ constructor(opts = {}) {
44
+ super(opts);
45
+ this.scheduler = new Scheduler();
46
+ }
47
+ register(name, funcOrVersion, funcOrOpts) {
48
+ return super.register(name, funcOrVersion, funcOrOpts);
49
+ }
50
+ /**
51
+ * Register a module with Resonate. Registered functions can be invoked by calling {@link run}.
52
+ *
53
+ * @template F The type of the function.
54
+ * @param module The module to register with Resonate.
55
+ * @param opts Resonate options, can be constructed by calling {@link options}.
56
+ * @returns Resonate function
57
+ */
58
+ registerModule(module, opts = {}) {
59
+ super.registerModule(module, opts);
60
+ }
61
+ execute(name, version, id, func, args, opts) {
62
+ return this.scheduler.add(name, version, id, func, args, opts);
63
+ }
64
+ }
65
+ exports.Resonate = Resonate;
66
+ /////////////////////////////////////////////////////////////////////
67
+ // Context
68
+ /////////////////////////////////////////////////////////////////////
69
+ class Info {
70
+ invocation;
71
+ constructor(invocation) {
72
+ this.invocation = invocation;
73
+ }
74
+ /**
75
+ * The running count of function execution attempts.
76
+ */
77
+ get attempt() {
78
+ return this.invocation.attempt;
79
+ }
80
+ /**
81
+ * Uniquely identifies the function invocation.
82
+ */
83
+ get id() {
84
+ return this.invocation.id;
85
+ }
86
+ /**
87
+ * Deduplicates function invocations with the same id.
88
+ */
89
+ get idempotencyKey() {
90
+ return this.invocation.idempotencyKey;
91
+ }
92
+ /**
93
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
94
+ */
95
+ get timeout() {
96
+ return this.invocation.timeout;
97
+ }
98
+ /**
99
+ * The resonate function version.
100
+ */
101
+ get version() {
102
+ return this.invocation.version;
103
+ }
104
+ }
105
+ exports.Info = Info;
106
+ class Context {
107
+ invocation;
108
+ constructor(invocation) {
109
+ this.invocation = invocation;
110
+ }
111
+ /**
112
+ * The running count of child function invocations.
113
+ */
114
+ get counter() {
115
+ return this.invocation.counter;
116
+ }
117
+ /**
118
+ * Uniquely identifies the function invocation.
119
+ */
120
+ get id() {
121
+ return this.invocation.id;
122
+ }
123
+ /**
124
+ * Deduplicates function invocations with the same id.
125
+ */
126
+ get idempotencyKey() {
127
+ return this.invocation.idempotencyKey;
128
+ }
129
+ /**
130
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
131
+ */
132
+ get timeout() {
133
+ return this.invocation.timeout;
134
+ }
135
+ /**
136
+ * The resonate function version.
137
+ */
138
+ get version() {
139
+ return this.invocation.version;
140
+ }
141
+ run(func, ...argsWithOpts) {
142
+ // the parent is the current invocation
143
+ const parent = this.invocation;
144
+ // the id is either:
145
+ // 1. a provided string in the case of a deferred execution
146
+ // 2. a generated string in the case of an ordinary execution
147
+ const id = typeof func === "string" ? func : `${parent.id}.${parent.counter}`;
148
+ // human readable name of the function
149
+ const name = typeof func === "string" ? func : func.name;
150
+ // version is inherited from the parent
151
+ const version = parent.version;
152
+ // the idempotency key is a hash of the id
153
+ const idempotencyKey = utils.hash(id);
154
+ // opts are optional and can be provided as the last arg
155
+ const { args, opts } = this.invocation.split(argsWithOpts);
156
+ // create a new invocation
157
+ const invocation = new invocation_1.Invocation(name, version, id, idempotencyKey, undefined, undefined, opts, parent);
158
+ let execution;
159
+ if (typeof func === "string") {
160
+ // create a deferred execution
161
+ // this execution will be fulfilled out-of-process
162
+ execution = new execution_1.DeferredExecution(invocation);
163
+ }
164
+ else {
165
+ // create an ordinary execution// human readable name of the function
166
+ // this execution wraps a user-provided function
167
+ const ctx = new Context(invocation);
168
+ execution = new execution_1.OrdinaryExecution(invocation, () => func(ctx, ...args), retry_1.Retry.never());
169
+ }
170
+ // bump the counter
171
+ parent.counter++;
172
+ // return a resonate promise
173
+ return execution.execute();
174
+ }
175
+ io(func, ...argsWithOpts) {
176
+ const parent = this.invocation;
177
+ const id = `${parent.id}.${parent.counter}`;
178
+ const idempotencyKey = utils.hash(id);
179
+ const { args, opts } = this.invocation.split(argsWithOpts);
180
+ const name = func.name;
181
+ const version = parent.version;
182
+ const invocation = new invocation_1.Invocation(name, version, id, idempotencyKey, undefined, undefined, opts, parent);
183
+ // create an ordinary execution
184
+ // this execution wraps a user-provided io function
185
+ // unlike run, an io function can not create child invocations
186
+ const info = new Info(invocation);
187
+ const execution = new execution_1.OrdinaryExecution(invocation, () => func(info, ...args));
188
+ // bump the counter
189
+ parent.counter++;
190
+ // return a resonate promise
191
+ return execution.execute();
192
+ }
193
+ /**
194
+ * Construct options.
195
+ *
196
+ * @param opts A partial {@link Options} object.
197
+ * @returns Options with the __resonate flag set.
198
+ */
199
+ options(opts = {}) {
200
+ return { ...opts, __resonate: true };
201
+ }
202
+ }
203
+ exports.Context = Context;
204
+ /////////////////////////////////////////////////////////////////////
205
+ // Scheduler
206
+ /////////////////////////////////////////////////////////////////////
207
+ class Scheduler {
208
+ cache = {};
209
+ add(name, version, id, func, args, opts) {
210
+ // if the execution is already running, and not killed,
211
+ // return the promise
212
+ if (this.cache[id] && !this.cache[id].killed) {
213
+ // execute is idempotent
214
+ return this.cache[id].execute();
215
+ }
216
+ // the idempotency key is a hash of the id
217
+ const idempotencyKey = utils.hash(id);
218
+ // params, used for recovery
219
+ const param = {
220
+ func: name,
221
+ version,
222
+ args,
223
+ };
224
+ // create a new invocation
225
+ const invocation = new invocation_1.Invocation(name, version, id, idempotencyKey, undefined, param, opts);
226
+ // create a new execution
227
+ const ctx = new Context(invocation);
228
+ const execution = new execution_1.OrdinaryExecution(invocation, () => func(ctx, ...args));
229
+ // store the execution,
230
+ // will be used if run is called again with the same id
231
+ this.cache[id] = execution;
232
+ return execution.execute();
233
+ }
234
+ }
235
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../lib/async.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAmF;AAEnF,kDAA+C;AAE/C,gDAA6C;AAC7C,oDAAsC;AACtC,yCAA0C;AAc1C,qEAAqE;AACrE,WAAW;AACX,qEAAqE;AAErE,MAAa,QAAS,SAAQ,uBAAY;IAChC,SAAS,CAAY;IAE7B;;;;;OAKG;IACH,YAAY,OAAiC,EAAE;QAC7C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IACnC,CAAC;IAiCD,QAAQ,CACN,IAAY,EACZ,aAAyB,EACzB,UAAgC;QAEhC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACH,cAAc,CAAkB,MAAyB,EAAE,OAAyB,EAAE;QACpF,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAES,OAAO,CACf,IAAY,EACZ,OAAe,EACf,EAAU,EACV,IAAO,EACP,IAAe,EACf,IAAa;QAEb,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;CACF;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ot":"","sources":["../../lib/core/encoder.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC5B,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;CACpB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../lib/core/encoder.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { IEncoder } from "../encoder";
2
+ export declare class Base64Encoder implements IEncoder<string, string> {
3
+ encode(data: string): string;
4
+ decode(data: string): string;
5
+ }
6
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../lib/core/encoders/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,qBAAa,aAAc,YAAW,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAC5D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAG7B"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base64Encoder = void 0;
4
+ class Base64Encoder {
5
+ encode(data) {
6
+ return btoa(data);
7
+ }
8
+ decode(data) {
9
+ return atob(data);
10
+ }
11
+ }
12
+ exports.Base64Encoder = Base64Encoder;
13
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../lib/core/encoders/base64.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IACxB,MAAM,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACF;AARD,sCAQC"}
@@ -0,0 +1,6 @@
1
+ import { IEncoder } from "../encoder";
2
+ export declare class JSONEncoder implements IEncoder<unknown, string | undefined> {
3
+ encode(data: unknown): string | undefined;
4
+ decode(data: string | undefined): unknown;
5
+ }
6
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../lib/core/encoders/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,qBAAa,WAAY,YAAW,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACvE,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IA2CzC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO;CAuB1C"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONEncoder = void 0;
4
+ const errors_1 = require("../errors");
5
+ class JSONEncoder {
6
+ encode(data) {
7
+ // note about undefined:
8
+ // undefined is not json serializable, so immediately return undefined
9
+ if (data === undefined) {
10
+ return undefined;
11
+ }
12
+ return JSON.stringify(data, (_, value) => {
13
+ if (value instanceof AggregateError) {
14
+ return {
15
+ __type: "aggregate_error",
16
+ message: value.message,
17
+ stack: value.stack,
18
+ name: value.name,
19
+ errors: value.errors,
20
+ };
21
+ }
22
+ if (value instanceof errors_1.ResonateError) {
23
+ return {
24
+ __type: "resonate_error",
25
+ message: value.message,
26
+ stack: value.stack,
27
+ name: value.name,
28
+ code: value.code,
29
+ cause: value.cause,
30
+ retriable: value.retriable,
31
+ };
32
+ }
33
+ if (value instanceof Error) {
34
+ return {
35
+ __type: "error",
36
+ message: value.message,
37
+ stack: value.stack,
38
+ name: value.name,
39
+ };
40
+ }
41
+ return value;
42
+ });
43
+ }
44
+ decode(data) {
45
+ // note about undefined:
46
+ // undefined causes JSON.parse to throw, so immediately return undefined
47
+ if (data === undefined) {
48
+ return undefined;
49
+ }
50
+ return JSON.parse(data, (_, value) => {
51
+ if (value?.__type === "aggregate_error") {
52
+ return Object.assign(new AggregateError(value.errors, value.message), value);
53
+ }
54
+ if (value?.__type === "resonate_error") {
55
+ return Object.assign(new errors_1.ResonateError(value.message, value.code, value.cause, value.retriable), value);
56
+ }
57
+ if (value?.__type === "error") {
58
+ return Object.assign(new Error(value.message), value);
59
+ }
60
+ return value;
61
+ });
62
+ }
63
+ }
64
+ exports.JSONEncoder = JSONEncoder;
65
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../lib/core/encoders/json.ts"],"names":[],"mappings":";;;AACA,sCAA0C;AAE1C,MAAa,WAAW;IACtB,MAAM,CAAC,IAAa;QAClB,wBAAwB;QACxB,sEAAsE;QACtE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;gBACpC,OAAO;oBACL,MAAM,EAAE,iBAAiB;oBACzB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,MAAM,EAAE,KAAK,CAAC,MAAM;iBACrB,CAAC;YACJ,CAAC;YAED,IAAI,KAAK,YAAY,sBAAa,EAAE,CAAC;gBACnC,OAAO;oBACL,MAAM,EAAE,gBAAgB;oBACxB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KA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AAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnED,kCAmEC"}
@@ -0,0 +1,21 @@
1
+ export declare enum ErrorCodes {
2
+ UNKNOWN = 0,
3
+ CANCELED = 10,
4
+ TIMEDOUT = 20,
5
+ KILLED = 30,
6
+ STORE = 40,
7
+ STORE_PAYLOAD = 41,
8
+ STORE_FORBIDDEN = 42,
9
+ STORE_NOT_FOUND = 43,
10
+ STORE_ALREADY_EXISTS = 44,
11
+ STORE_INVALID_STATE = 45,
12
+ STORE_ENCODER = 46
13
+ }
14
+ export declare class ResonateError extends Error {
15
+ readonly code: ErrorCodes;
16
+ readonly cause?: any;
17
+ readonly retriable: boolean;
18
+ constructor(message: string, code: ErrorCodes, cause?: any, retriable?: boolean);
19
+ static fromError(e: unknown): ResonateError;
20
+ }
21
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../lib/core/errors.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAEpB,OAAO,IAAI;IAGX,QAAQ,KAAK;IAGb,QAAQ,KAAK;IAGb,MAAM,KAAK;IAGX,KAAK,KAAK;IACV,aAAa,KAAK;IAClB,eAAe,KAAK;IACpB,eAAe,KAAK;IACpB,oBAAoB,KAAK;IACzB,mBAAmB,KAAK;IACxB,aAAa,KAAK;CACnB;AAED,qBAAa,aAAc,SAAQ,KAAK;aAGpB,IAAI,EAAE,UAAU;aAChB,KAAK,CAAC;aACN,SAAS,EAAE,OAAO;gBAHlC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,KAAK,EACX,SAAS,GAAE,OAAe;WAK9B,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,aAAa;CAGnD"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResonateError = exports.ErrorCodes = void 0;
4
+ var ErrorCodes;
5
+ (function (ErrorCodes) {
6
+ // unknown
7
+ ErrorCodes[ErrorCodes["UNKNOWN"] = 0] = "UNKNOWN";
8
+ // canceled
9
+ ErrorCodes[ErrorCodes["CANCELED"] = 10] = "CANCELED";
10
+ // timedout
11
+ ErrorCodes[ErrorCodes["TIMEDOUT"] = 20] = "TIMEDOUT";
12
+ // killed
13
+ ErrorCodes[ErrorCodes["KILLED"] = 30] = "KILLED";
14
+ // store
15
+ ErrorCodes[ErrorCodes["STORE"] = 40] = "STORE";
16
+ ErrorCodes[ErrorCodes["STORE_PAYLOAD"] = 41] = "STORE_PAYLOAD";
17
+ ErrorCodes[ErrorCodes["STORE_FORBIDDEN"] = 42] = "STORE_FORBIDDEN";
18
+ ErrorCodes[ErrorCodes["STORE_NOT_FOUND"] = 43] = "STORE_NOT_FOUND";
19
+ ErrorCodes[ErrorCodes["STORE_ALREADY_EXISTS"] = 44] = "STORE_ALREADY_EXISTS";
20
+ ErrorCodes[ErrorCodes["STORE_INVALID_STATE"] = 45] = "STORE_INVALID_STATE";
21
+ ErrorCodes[ErrorCodes["STORE_ENCODER"] = 46] = "STORE_ENCODER";
22
+ })(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {}));
23
+ class ResonateError extends Error {
24
+ code;
25
+ cause;
26
+ retriable;
27
+ constructor(message, code, cause, retriable = false) {
28
+ super(message);
29
+ this.code = code;
30
+ this.cause = cause;
31
+ this.retriable = retriable;
32
+ }
33
+ static fromError(e) {
34
+ return e instanceof ResonateError ? e : new ResonateError("Unknown error", ErrorCodes.UNKNOWN, e, true);
35
+ }
36
+ }
37
+ exports.ResonateError = ResonateError;
38
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/core/errors.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAqBX;AArBD,WAAY,UAAU;IACpB,UAAU;IACV,iDAAW,CAAA;IAEX,WAAW;IACX,oDAAa,CAAA;IAEb,WAAW;IACX,oDAAa,CAAA;IAEb,SAAS;IACT,gDAAW,CAAA;IAEX,QAAQ;IACR,8CAAU,CAAA;IACV,8DAAkB,CAAA;IAClB,kEAAoB,CAAA;IACpB,kEAAoB,CAAA;IACpB,4EAAyB,CAAA;IACzB,0EAAwB,CAAA;IACxB,8DAAkB,CAAA;AACpB,CAAC,EArBW,UAAU,0BAAV,UAAU,QAqBrB;AAED,MAAa,aAAc,SAAQ,KAAK;IAGpB;IACA;IACA;IAJlB,YACE,OAAe,EACC,IAAgB,EAChB,KAAW,EACX,YAAqB,KAAK;QAE1C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAY;QAChB,UAAK,GAAL,KAAK,CAAM;QACX,cAAS,GAAT,SAAS,CAAiB;IAG5C,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,CAAU;QAChC,OAAO,CAAC,YAAY,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1G,CAAC;CACF;AAbD,sCAaC"}
@@ -0,0 +1,44 @@
1
+ import { Future, ResonatePromise } from "./future";
2
+ import { Invocation } from "./invocation";
3
+ import { DurablePromise } from "./promises/promises";
4
+ import { IRetry } from "./retry";
5
+ export declare abstract class Execution<T> {
6
+ invocation: Invocation<T>;
7
+ private promise;
8
+ /**
9
+ * Represents an execution of a Resonate function invocation.
10
+ *
11
+ * @constructor
12
+ * @param invocation - An invocation correpsonding to the Resonate function.
13
+ */
14
+ constructor(invocation: Invocation<T>);
15
+ execute(): ResonatePromise<T>;
16
+ protected abstract fork(): Promise<Future<T>>;
17
+ protected abstract join(future: Future<T>): Promise<T>;
18
+ get killed(): boolean;
19
+ kill(error: unknown): void;
20
+ protected tags(): Record<string, string>;
21
+ }
22
+ export declare class OrdinaryExecution<T> extends Execution<T> {
23
+ private func;
24
+ private retry;
25
+ constructor(invocation: Invocation<T>, func: () => T, retry?: IRetry);
26
+ protected fork(): Promise<Future<T>>;
27
+ protected join(future: Future<T>): Promise<T>;
28
+ private run;
29
+ }
30
+ export declare class DeferredExecution<T> extends Execution<T> {
31
+ constructor(invocation: Invocation<T>);
32
+ protected fork(): Promise<Future<T>>;
33
+ protected join(future: Future<T>): Promise<T>;
34
+ }
35
+ export declare class GeneratorExecution<T> extends Execution<T> {
36
+ generator: Generator<any, T>;
37
+ constructor(invocation: Invocation<T>, generator: Generator<any, T>);
38
+ create(): Promise<DurablePromise<T> | undefined>;
39
+ resolve(promise: DurablePromise<T>, value: T): Promise<DurablePromise<T>>;
40
+ reject(promise: DurablePromise<T>, error: any): Promise<DurablePromise<T>>;
41
+ protected fork(): Promise<Future<T>>;
42
+ protected join(future: Future<T>): Promise<T>;
43
+ }
44
+ //# sourceMappingURL=execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../lib/core/execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAMjC,8BAAsB,SAAS,CAAC,CAAC;IASZ,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAR5C,OAAO,CAAC,OAAO,CAAmC;IAElD;;;;;OAKG;gBACgB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAE5C,OAAO,IAAI,eAAe,CAAC,CAAC,CAAC;IAY7B,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7C,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