@resonatehq/sdk 0.3.3 → 0.3.4

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 (79) hide show
  1. package/dist/async.d.ts +135 -0
  2. package/dist/async.d.ts.map +1 -0
  3. package/dist/async.js +205 -0
  4. package/dist/core/encoder.d.ts +5 -0
  5. package/dist/core/encoder.d.ts.map +1 -0
  6. package/dist/core/encoder.js +1 -0
  7. package/dist/core/encoders/base64.d.ts +6 -0
  8. package/dist/core/encoders/base64.d.ts.map +1 -0
  9. package/dist/core/encoders/base64.js +8 -0
  10. package/dist/core/encoders/json.d.ts +6 -0
  11. package/dist/core/encoders/json.d.ts.map +1 -0
  12. package/dist/core/encoders/json.js +60 -0
  13. package/dist/core/errors.d.ts +21 -0
  14. package/dist/core/errors.d.ts.map +1 -0
  15. package/dist/core/errors.js +33 -0
  16. package/dist/core/execution.d.ts +44 -0
  17. package/dist/core/execution.d.ts.map +1 -0
  18. package/dist/core/execution.js +195 -0
  19. package/dist/core/future.d.ts +54 -0
  20. package/dist/core/future.d.ts.map +1 -0
  21. package/dist/core/future.js +95 -0
  22. package/dist/core/invocation.d.ts +43 -0
  23. package/dist/core/invocation.d.ts.map +1 -0
  24. package/dist/core/invocation.js +72 -0
  25. package/dist/core/logger.d.ts +10 -0
  26. package/dist/core/logger.d.ts.map +1 -0
  27. package/dist/core/logger.js +1 -0
  28. package/dist/core/loggers/logger.d.ts +13 -0
  29. package/dist/core/loggers/logger.d.ts.map +1 -0
  30. package/dist/core/loggers/logger.js +43 -0
  31. package/dist/core/options.d.ts +79 -0
  32. package/dist/core/options.d.ts.map +1 -0
  33. package/dist/core/options.js +3 -0
  34. package/dist/core/promises/promises.d.ts +47 -0
  35. package/dist/core/promises/promises.d.ts.map +1 -0
  36. package/dist/core/promises/promises.js +128 -0
  37. package/dist/core/promises/types.d.ts +99 -0
  38. package/dist/core/promises/types.d.ts.map +1 -0
  39. package/dist/core/promises/types.js +29 -0
  40. package/dist/core/retries/retry.d.ts +20 -0
  41. package/dist/core/retries/retry.d.ts.map +1 -0
  42. package/dist/core/retries/retry.js +36 -0
  43. package/dist/core/retry.d.ts +27 -0
  44. package/dist/core/retry.d.ts.map +1 -0
  45. package/dist/core/retry.js +17 -0
  46. package/dist/core/schedules/types.d.ts +19 -0
  47. package/dist/core/schedules/types.d.ts.map +1 -0
  48. package/dist/core/schedules/types.js +3 -0
  49. package/dist/core/storage.d.ts +6 -0
  50. package/dist/core/storage.d.ts.map +1 -0
  51. package/dist/core/storage.js +1 -0
  52. package/dist/core/storages/memory.d.ts +8 -0
  53. package/dist/core/storages/memory.d.ts.map +1 -0
  54. package/dist/core/storages/memory.js +22 -0
  55. package/dist/core/storages/withTimeout.d.ts +10 -0
  56. package/dist/core/storages/withTimeout.d.ts.map +1 -0
  57. package/dist/core/storages/withTimeout.js +38 -0
  58. package/dist/core/store.d.ts +139 -0
  59. package/dist/core/store.d.ts.map +1 -0
  60. package/dist/core/store.js +1 -0
  61. package/dist/core/stores/local.d.ts +54 -0
  62. package/dist/core/stores/local.d.ts.map +1 -0
  63. package/dist/core/stores/local.js +368 -0
  64. package/dist/core/stores/remote.d.ts +48 -0
  65. package/dist/core/stores/remote.d.ts.map +1 -0
  66. package/dist/core/stores/remote.js +399 -0
  67. package/dist/core/utils.d.ts +3 -0
  68. package/dist/core/utils.d.ts.map +1 -0
  69. package/dist/core/utils.js +13 -0
  70. package/dist/generator.d.ts +187 -0
  71. package/dist/generator.d.ts.map +1 -0
  72. package/dist/generator.js +396 -0
  73. package/dist/index.d.ts +4 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +3 -0
  76. package/dist/resonate.d.ts +73 -0
  77. package/dist/resonate.d.ts.map +1 -0
  78. package/dist/resonate.js +142 -0
  79. package/package.json +1 -1
@@ -0,0 +1,135 @@
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 an io function.
118
+ *
119
+ * @template F The type of the function.
120
+ * @param func The function to invoke.
121
+ * @param args The function arguments, optionally followed by {@link options}.
122
+ * @returns A promise that resolves to the return value of the function.
123
+ */
124
+ io<F extends IFunc>(func: F, ...args: [...Params<F>, PartialOptions?]): ResonatePromise<Return<F>>;
125
+ /**
126
+ * Construct options.
127
+ *
128
+ * @param opts A partial {@link Options} object.
129
+ * @returns Options with the __resonate flag set.
130
+ */
131
+ options(opts?: Partial<Options>): Partial<Options> & {
132
+ __resonate: true;
133
+ };
134
+ }
135
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../lib/async.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE1D,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAExD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AAElF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAMnF,qBAAa,QAAS,SAAQ,YAAY;IACxC,OAAO,CAAC,SAAS,CAAY;IAE7B;;;;;OAKG;gBACS,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM;IAK/C;;;;;;;;OAQG;IACH,QA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C,UAAU;gBAAV,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC;IAE/C;;OAEG;IACH,IAAI,OAAO,WAEV;IAED;;OAEG;IACH,IAAI,EAAE,WAEL;IAED;;OAEG;IACH,IAAI,cAAc,uBAEjB;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAED;;;;;;;OAOG;IACH,GAAG,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;IAEnG;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC;IA4C3E;;;;;;;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,205 @@
1
+ import { OrdinaryExecution, DeferredExecution } from "./core/execution";
2
+ import { Invocation } from "./core/invocation";
3
+ import { Retry } from "./core/retries/retry";
4
+ import * as utils from "./core/utils";
5
+ import { ResonateBase } from "./resonate";
6
+ /////////////////////////////////////////////////////////////////////
7
+ // Resonate
8
+ /////////////////////////////////////////////////////////////////////
9
+ export class Resonate extends ResonateBase {
10
+ 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 = {}) {
18
+ super(opts);
19
+ this.scheduler = new Scheduler();
20
+ }
21
+ register(name, funcOrVersion, funcOrOpts) {
22
+ return super.register(name, funcOrVersion, funcOrOpts);
23
+ }
24
+ /**
25
+ * Register a module with Resonate. Registered functions can be invoked by calling {@link run}.
26
+ *
27
+ * @template F The type of the function.
28
+ * @param module The module to register with Resonate.
29
+ * @param opts Resonate options, can be constructed by calling {@link options}.
30
+ * @returns Resonate function
31
+ */
32
+ registerModule(module, opts = {}) {
33
+ super.registerModule(module, opts);
34
+ }
35
+ execute(name, version, id, func, args, opts) {
36
+ return this.scheduler.add(name, version, id, func, args, opts);
37
+ }
38
+ }
39
+ /////////////////////////////////////////////////////////////////////
40
+ // Context
41
+ /////////////////////////////////////////////////////////////////////
42
+ export class Info {
43
+ invocation;
44
+ constructor(invocation) {
45
+ this.invocation = invocation;
46
+ }
47
+ /**
48
+ * The running count of function execution attempts.
49
+ */
50
+ get attempt() {
51
+ return this.invocation.attempt;
52
+ }
53
+ /**
54
+ * Uniquely identifies the function invocation.
55
+ */
56
+ get id() {
57
+ return this.invocation.id;
58
+ }
59
+ /**
60
+ * Deduplicates function invocations with the same id.
61
+ */
62
+ get idempotencyKey() {
63
+ return this.invocation.idempotencyKey;
64
+ }
65
+ /**
66
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
67
+ */
68
+ get timeout() {
69
+ return this.invocation.timeout;
70
+ }
71
+ /**
72
+ * The resonate function version.
73
+ */
74
+ get version() {
75
+ return this.invocation.version;
76
+ }
77
+ }
78
+ export class Context {
79
+ invocation;
80
+ constructor(invocation) {
81
+ this.invocation = invocation;
82
+ }
83
+ /**
84
+ * The running count of child function invocations.
85
+ */
86
+ get counter() {
87
+ return this.invocation.counter;
88
+ }
89
+ /**
90
+ * Uniquely identifies the function invocation.
91
+ */
92
+ get id() {
93
+ return this.invocation.id;
94
+ }
95
+ /**
96
+ * Deduplicates function invocations with the same id.
97
+ */
98
+ get idempotencyKey() {
99
+ return this.invocation.idempotencyKey;
100
+ }
101
+ /**
102
+ * The timestamp in ms, once this time elapses the function invocation will timeout.
103
+ */
104
+ get timeout() {
105
+ return this.invocation.timeout;
106
+ }
107
+ /**
108
+ * The resonate function version.
109
+ */
110
+ get version() {
111
+ return this.invocation.version;
112
+ }
113
+ run(func, ...argsWithOpts) {
114
+ // the parent is the current invocation
115
+ const parent = this.invocation;
116
+ // the id is either:
117
+ // 1. a provided string in the case of a deferred execution
118
+ // 2. a generated string in the case of an ordinary execution
119
+ const id = typeof func === "string" ? func : `${parent.id}.${parent.counter}`;
120
+ // human readable name of the function
121
+ const name = typeof func === "string" ? func : func.name;
122
+ // version is inherited from the parent
123
+ const version = parent.version;
124
+ // the idempotency key is a hash of the id
125
+ const idempotencyKey = utils.hash(id);
126
+ // opts are optional and can be provided as the last arg
127
+ const { args, opts } = this.invocation.split(argsWithOpts);
128
+ // create a new invocation
129
+ const invocation = new Invocation(name, version, id, idempotencyKey, undefined, undefined, opts, parent);
130
+ let execution;
131
+ if (typeof func === "string") {
132
+ // create a deferred execution
133
+ // this execution will be fulfilled out-of-process
134
+ execution = new DeferredExecution(invocation);
135
+ }
136
+ else {
137
+ // create an ordinary execution// human readable name of the function
138
+ // this execution wraps a user-provided function
139
+ const ctx = new Context(invocation);
140
+ execution = new OrdinaryExecution(invocation, () => func(ctx, ...args), Retry.never());
141
+ }
142
+ // bump the counter
143
+ parent.counter++;
144
+ // return a resonate promise
145
+ return execution.execute();
146
+ }
147
+ io(func, ...argsWithOpts) {
148
+ const parent = this.invocation;
149
+ const id = `${parent.id}.${parent.counter}`;
150
+ const idempotencyKey = utils.hash(id);
151
+ const { args, opts } = this.invocation.split(argsWithOpts);
152
+ const name = func.name;
153
+ const version = parent.version;
154
+ const invocation = new Invocation(name, version, id, idempotencyKey, undefined, undefined, opts, parent);
155
+ // create an ordinary execution
156
+ // this execution wraps a user-provided io function
157
+ // unlike run, an io function can not create child invocations
158
+ const info = new Info(invocation);
159
+ const execution = new OrdinaryExecution(invocation, () => func(info, ...args));
160
+ // bump the counter
161
+ parent.counter++;
162
+ // return a resonate promise
163
+ return execution.execute();
164
+ }
165
+ /**
166
+ * Construct options.
167
+ *
168
+ * @param opts A partial {@link Options} object.
169
+ * @returns Options with the __resonate flag set.
170
+ */
171
+ options(opts = {}) {
172
+ return { ...opts, __resonate: true };
173
+ }
174
+ }
175
+ /////////////////////////////////////////////////////////////////////
176
+ // Scheduler
177
+ /////////////////////////////////////////////////////////////////////
178
+ class Scheduler {
179
+ cache = {};
180
+ add(name, version, id, func, args, opts) {
181
+ // if the execution is already running, and not killed,
182
+ // return the promise
183
+ if (this.cache[id] && !this.cache[id].killed) {
184
+ // execute is idempotent
185
+ return this.cache[id].execute();
186
+ }
187
+ // the idempotency key is a hash of the id
188
+ const idempotencyKey = utils.hash(id);
189
+ // params, used for recovery
190
+ const param = {
191
+ func: name,
192
+ version,
193
+ args,
194
+ };
195
+ // create a new invocation
196
+ const invocation = new Invocation(name, version, id, idempotencyKey, undefined, param, opts);
197
+ // create a new execution
198
+ const ctx = new Context(invocation);
199
+ const execution = new OrdinaryExecution(invocation, () => func(ctx, ...args));
200
+ // store the execution,
201
+ // will be used if run is called again with the same id
202
+ this.cache[id] = execution;
203
+ return execution.execute();
204
+ }
205
+ }
@@ -0,0 +1,5 @@
1
+ export interface IEncoder<I, O> {
2
+ encode(data: I): O;
3
+ decode(data: O): I;
4
+ }
5
+ //# sourceMappingURL=encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.d.ts","sourceRoot":"","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 @@
1
+ export {};
@@ -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,8 @@
1
+ export class Base64Encoder {
2
+ encode(data) {
3
+ return btoa(data);
4
+ }
5
+ decode(data) {
6
+ return atob(data);
7
+ }
8
+ }
@@ -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,60 @@
1
+ import { ResonateError } from "../errors";
2
+ export class JSONEncoder {
3
+ encode(data) {
4
+ // note about undefined:
5
+ // undefined is not json serializable, so immediately return undefined
6
+ if (data === undefined) {
7
+ return undefined;
8
+ }
9
+ return JSON.stringify(data, (_, value) => {
10
+ if (value instanceof AggregateError) {
11
+ return {
12
+ __type: "aggregate_error",
13
+ message: value.message,
14
+ stack: value.stack,
15
+ name: value.name,
16
+ errors: value.errors,
17
+ };
18
+ }
19
+ if (value instanceof ResonateError) {
20
+ return {
21
+ __type: "resonate_error",
22
+ message: value.message,
23
+ stack: value.stack,
24
+ name: value.name,
25
+ code: value.code,
26
+ cause: value.cause,
27
+ retriable: value.retriable,
28
+ };
29
+ }
30
+ if (value instanceof Error) {
31
+ return {
32
+ __type: "error",
33
+ message: value.message,
34
+ stack: value.stack,
35
+ name: value.name,
36
+ };
37
+ }
38
+ return value;
39
+ });
40
+ }
41
+ decode(data) {
42
+ // note about undefined:
43
+ // undefined causes JSON.parse to throw, so immediately return undefined
44
+ if (data === undefined) {
45
+ return undefined;
46
+ }
47
+ return JSON.parse(data, (_, value) => {
48
+ if (value?.__type === "aggregate_error") {
49
+ return Object.assign(new AggregateError(value.errors, value.message), value);
50
+ }
51
+ if (value?.__type === "resonate_error") {
52
+ return Object.assign(new ResonateError(value.message, value.code, value.cause, value.retriable), value);
53
+ }
54
+ if (value?.__type === "error") {
55
+ return Object.assign(new Error(value.message), value);
56
+ }
57
+ return value;
58
+ });
59
+ }
60
+ }
@@ -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,33 @@
1
+ export var ErrorCodes;
2
+ (function (ErrorCodes) {
3
+ // unknown
4
+ ErrorCodes[ErrorCodes["UNKNOWN"] = 0] = "UNKNOWN";
5
+ // canceled
6
+ ErrorCodes[ErrorCodes["CANCELED"] = 10] = "CANCELED";
7
+ // timedout
8
+ ErrorCodes[ErrorCodes["TIMEDOUT"] = 20] = "TIMEDOUT";
9
+ // killed
10
+ ErrorCodes[ErrorCodes["KILLED"] = 30] = "KILLED";
11
+ // store
12
+ ErrorCodes[ErrorCodes["STORE"] = 40] = "STORE";
13
+ ErrorCodes[ErrorCodes["STORE_PAYLOAD"] = 41] = "STORE_PAYLOAD";
14
+ ErrorCodes[ErrorCodes["STORE_FORBIDDEN"] = 42] = "STORE_FORBIDDEN";
15
+ ErrorCodes[ErrorCodes["STORE_NOT_FOUND"] = 43] = "STORE_NOT_FOUND";
16
+ ErrorCodes[ErrorCodes["STORE_ALREADY_EXISTS"] = 44] = "STORE_ALREADY_EXISTS";
17
+ ErrorCodes[ErrorCodes["STORE_INVALID_STATE"] = 45] = "STORE_INVALID_STATE";
18
+ ErrorCodes[ErrorCodes["STORE_ENCODER"] = 46] = "STORE_ENCODER";
19
+ })(ErrorCodes || (ErrorCodes = {}));
20
+ export class ResonateError extends Error {
21
+ code;
22
+ cause;
23
+ retriable;
24
+ constructor(message, code, cause, retriable = false) {
25
+ super(message);
26
+ this.code = code;
27
+ this.cause = cause;
28
+ this.retriable = retriable;
29
+ }
30
+ static fromError(e) {
31
+ return e instanceof ResonateError ? e : new ResonateError("Unknown error", ErrorCodes.UNKNOWN, e, true);
32
+ }
33
+ }
@@ -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,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAEtD,IAAI,MAAM,YAET;IAED,IAAI,CAAC,KAAK,EAAE,OAAO;IAQnB,SAAS,CAAC,IAAI;CAOf;AAED,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAGlD,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,KAAK;gBAFb,UAAU,EA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