@resonatehq/sdk 0.3.2 → 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.
- package/dist/async.d.ts +135 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +205 -0
- package/dist/core/encoder.d.ts +5 -0
- package/dist/core/encoder.d.ts.map +1 -0
- package/dist/core/encoder.js +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 +8 -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 +60 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +33 -0
- package/dist/core/execution.d.ts +44 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +195 -0
- package/dist/core/future.d.ts +54 -0
- package/dist/core/future.d.ts.map +1 -0
- package/dist/core/future.js +95 -0
- package/dist/core/invocation.d.ts +43 -0
- package/dist/core/invocation.d.ts.map +1 -0
- package/dist/core/invocation.js +72 -0
- package/dist/core/logger.d.ts +10 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +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 +43 -0
- package/dist/core/options.d.ts +79 -0
- package/dist/core/options.d.ts.map +1 -0
- package/dist/core/options.js +3 -0
- package/dist/core/promises/promises.d.ts +47 -0
- package/dist/core/promises/promises.d.ts.map +1 -0
- package/dist/core/promises/promises.js +128 -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 +29 -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 +36 -0
- package/dist/core/retry.d.ts +27 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +17 -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 +3 -0
- package/dist/core/storage.d.ts +6 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/core/storage.js +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 +22 -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 +38 -0
- package/dist/core/store.d.ts +139 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +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 +368 -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 +399 -0
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +13 -0
- package/dist/generator.d.ts +187 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +396 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/resonate.d.ts +73 -0
- package/dist/resonate.d.ts.map +1 -0
- package/dist/resonate.js +142 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IEncoder } from "../encoder";
|
|
2
|
+
import { IPromiseStore } from "../store";
|
|
3
|
+
import { PendingPromise, ResolvedPromise, RejectedPromise, CanceledPromise, TimedoutPromise } from "./types";
|
|
4
|
+
export type CreateOptions = {
|
|
5
|
+
idempotencyKey: string;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
tags: Record<string, string>;
|
|
8
|
+
strict: boolean;
|
|
9
|
+
poll: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type CompleteOptions = {
|
|
12
|
+
idempotencyKey: string;
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
strict: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare class DurablePromise<T> {
|
|
17
|
+
private store;
|
|
18
|
+
private encoder;
|
|
19
|
+
private promise;
|
|
20
|
+
readonly created: Promise<DurablePromise<T>>;
|
|
21
|
+
readonly completed: Promise<DurablePromise<T>>;
|
|
22
|
+
private complete;
|
|
23
|
+
private interval;
|
|
24
|
+
constructor(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, promise: PendingPromise | ResolvedPromise | RejectedPromise | CanceledPromise | TimedoutPromise, poll?: boolean);
|
|
25
|
+
get id(): string;
|
|
26
|
+
get idempotencyKeyForCreate(): string | undefined;
|
|
27
|
+
get idempotencyKeyForComplete(): string | undefined;
|
|
28
|
+
get pending(): boolean;
|
|
29
|
+
get resolved(): boolean;
|
|
30
|
+
get rejected(): boolean;
|
|
31
|
+
get canceled(): boolean;
|
|
32
|
+
get timedout(): boolean;
|
|
33
|
+
param(): unknown;
|
|
34
|
+
value(): T;
|
|
35
|
+
error(): unknown;
|
|
36
|
+
static create<T>(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string, timeout: number, param?: unknown, opts?: Partial<CreateOptions>): Promise<DurablePromise<T>>;
|
|
37
|
+
static resolve<T>(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string, value: T, opts?: Partial<CompleteOptions>): Promise<DurablePromise<T>>;
|
|
38
|
+
static reject<T>(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string, error: any, opts?: Partial<CompleteOptions>): Promise<DurablePromise<T>>;
|
|
39
|
+
static cancel<T>(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string, error: any, opts?: Partial<CompleteOptions>): Promise<DurablePromise<T>>;
|
|
40
|
+
static get<T>(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string): Promise<DurablePromise<T>>;
|
|
41
|
+
static search(store: IPromiseStore, encoder: IEncoder<unknown, string | undefined>, id: string, state?: string, tags?: Record<string, string>, limit?: number): AsyncGenerator<DurablePromise<any>[], void>;
|
|
42
|
+
resolve(value: T, opts?: Partial<CompleteOptions>): Promise<this>;
|
|
43
|
+
reject(error: any, opts?: Partial<CompleteOptions>): Promise<this>;
|
|
44
|
+
cancel(error: any, opts?: Partial<CompleteOptions>): Promise<this>;
|
|
45
|
+
private poll;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=promises.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../../lib/core/promises/promises.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE7G,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qBAAa,cAAc,CAAC,CAAC;IAQzB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IATjB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAA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,eAAe,CAAM;WASxB,MAAM,CAAC,CAAC,EACnB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,EAC9C,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,GAAG,EACV,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM;WASxB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM;WAItF,MAAM,CAClB,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,EAC9C,EAAE,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC;IAMxC,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM;IAkBrD,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM;IAkBtD,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM;YAkB9C,IAAI;CAYnB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ErrorCodes, ResonateError } from "../errors";
|
|
2
|
+
export class DurablePromise {
|
|
3
|
+
store;
|
|
4
|
+
encoder;
|
|
5
|
+
promise;
|
|
6
|
+
created;
|
|
7
|
+
completed;
|
|
8
|
+
complete;
|
|
9
|
+
interval;
|
|
10
|
+
constructor(store, encoder, promise, poll = false) {
|
|
11
|
+
this.store = store;
|
|
12
|
+
this.encoder = encoder;
|
|
13
|
+
this.promise = promise;
|
|
14
|
+
this.created = Promise.resolve(this);
|
|
15
|
+
this.completed = new Promise((resolve) => {
|
|
16
|
+
this.complete = resolve;
|
|
17
|
+
});
|
|
18
|
+
if (poll) {
|
|
19
|
+
this.interval = setInterval(() => this.poll(), 5000);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
get id() {
|
|
23
|
+
return this.promise.id;
|
|
24
|
+
}
|
|
25
|
+
get idempotencyKeyForCreate() {
|
|
26
|
+
return this.promise.idempotencyKeyForCreate;
|
|
27
|
+
}
|
|
28
|
+
get idempotencyKeyForComplete() {
|
|
29
|
+
return this.promise.idempotencyKeyForComplete;
|
|
30
|
+
}
|
|
31
|
+
get pending() {
|
|
32
|
+
return this.promise.state === "PENDING";
|
|
33
|
+
}
|
|
34
|
+
get resolved() {
|
|
35
|
+
return this.promise.state === "RESOLVED";
|
|
36
|
+
}
|
|
37
|
+
get rejected() {
|
|
38
|
+
return this.promise.state === "REJECTED";
|
|
39
|
+
}
|
|
40
|
+
get canceled() {
|
|
41
|
+
return this.promise.state === "REJECTED_CANCELED";
|
|
42
|
+
}
|
|
43
|
+
get timedout() {
|
|
44
|
+
return this.promise.state === "REJECTED_TIMEDOUT";
|
|
45
|
+
}
|
|
46
|
+
param() {
|
|
47
|
+
return this.encoder.decode(this.promise.param.data);
|
|
48
|
+
}
|
|
49
|
+
value() {
|
|
50
|
+
if (!this.resolved) {
|
|
51
|
+
throw new Error("Promise is not resolved");
|
|
52
|
+
}
|
|
53
|
+
return this.encoder.decode(this.promise.value.data);
|
|
54
|
+
}
|
|
55
|
+
error() {
|
|
56
|
+
if (this.rejected) {
|
|
57
|
+
return this.encoder.decode(this.promise.value.data);
|
|
58
|
+
}
|
|
59
|
+
else if (this.canceled) {
|
|
60
|
+
return new ResonateError("Resonate function canceled", ErrorCodes.CANCELED, this.encoder.decode(this.promise.value.data));
|
|
61
|
+
}
|
|
62
|
+
else if (this.timedout) {
|
|
63
|
+
return new ResonateError(`Resonate function timedout at ${new Date(this.promise.timeout).toISOString()}`, ErrorCodes.TIMEDOUT);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error("Promise is not rejected, canceled, or timedout");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static async create(store, encoder, id, timeout, param = undefined, opts = {}) {
|
|
70
|
+
return new DurablePromise(store, encoder, await store.create(id, opts.idempotencyKey, opts.strict ?? false, opts.headers, encoder.encode(param), timeout, opts.tags), opts.poll ?? false);
|
|
71
|
+
}
|
|
72
|
+
static async resolve(store, encoder, id, value, opts = {}) {
|
|
73
|
+
return new DurablePromise(store, encoder, await store.resolve(id, opts.idempotencyKey, opts.strict ?? false, opts.headers, encoder.encode(value)));
|
|
74
|
+
}
|
|
75
|
+
static async reject(store, encoder, id, error, opts = {}) {
|
|
76
|
+
return new DurablePromise(store, encoder, await store.reject(id, opts.idempotencyKey, opts.strict ?? false, opts.headers, encoder.encode(error)));
|
|
77
|
+
}
|
|
78
|
+
static async cancel(store, encoder, id, error, opts = {}) {
|
|
79
|
+
return new DurablePromise(store, encoder, await store.cancel(id, opts.idempotencyKey, opts.strict ?? false, opts.headers, encoder.encode(error)));
|
|
80
|
+
}
|
|
81
|
+
static async get(store, encoder, id) {
|
|
82
|
+
return new DurablePromise(store, encoder, await store.get(id));
|
|
83
|
+
}
|
|
84
|
+
static async *search(store, encoder, id, state, tags, limit) {
|
|
85
|
+
for await (const promises of store.search(id, state, tags, limit)) {
|
|
86
|
+
yield promises.map((p) => new DurablePromise(store, encoder, p));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async resolve(value, opts = {}) {
|
|
90
|
+
this.promise = !this.pending
|
|
91
|
+
? this.promise
|
|
92
|
+
: await this.store.resolve(this.id, opts.idempotencyKey, opts.strict ?? false, opts.headers, this.encoder.encode(value));
|
|
93
|
+
if (!this.pending) {
|
|
94
|
+
this.complete(this);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
async reject(error, opts = {}) {
|
|
99
|
+
this.promise = !this.pending
|
|
100
|
+
? this.promise
|
|
101
|
+
: await this.store.reject(this.id, opts.idempotencyKey, opts.strict ?? false, opts.headers, this.encoder.encode(error));
|
|
102
|
+
if (!this.pending) {
|
|
103
|
+
this.complete(this);
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
async cancel(error, opts = {}) {
|
|
108
|
+
this.promise = !this.pending
|
|
109
|
+
? this.promise
|
|
110
|
+
: await this.store.cancel(this.id, opts.idempotencyKey, opts.strict ?? false, opts.headers, this.encoder.encode(error));
|
|
111
|
+
if (!this.pending) {
|
|
112
|
+
this.complete(this);
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
async poll() {
|
|
117
|
+
try {
|
|
118
|
+
this.promise = await this.store.get(this.id);
|
|
119
|
+
if (!this.pending) {
|
|
120
|
+
this.complete(this);
|
|
121
|
+
clearInterval(this.interval);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
// TODO: log
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type DurablePromise = PendingPromise | ResolvedPromise | RejectedPromise | CanceledPromise | TimedoutPromise;
|
|
2
|
+
export type PendingPromise = {
|
|
3
|
+
state: "PENDING";
|
|
4
|
+
id: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
param: {
|
|
7
|
+
headers: Record<string, string> | undefined;
|
|
8
|
+
data: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
value: {
|
|
11
|
+
headers: undefined;
|
|
12
|
+
data: undefined;
|
|
13
|
+
};
|
|
14
|
+
createdOn: number;
|
|
15
|
+
completedOn: undefined;
|
|
16
|
+
idempotencyKeyForCreate: string | undefined;
|
|
17
|
+
idempotencyKeyForComplete: undefined;
|
|
18
|
+
tags: Record<string, string> | undefined;
|
|
19
|
+
};
|
|
20
|
+
export type ResolvedPromise = {
|
|
21
|
+
state: "RESOLVED";
|
|
22
|
+
id: string;
|
|
23
|
+
timeout: number;
|
|
24
|
+
param: {
|
|
25
|
+
headers: Record<string, string> | undefined;
|
|
26
|
+
data: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
value: {
|
|
29
|
+
headers: Record<string, string> | undefined;
|
|
30
|
+
data: string | undefined;
|
|
31
|
+
};
|
|
32
|
+
createdOn: number;
|
|
33
|
+
completedOn: number;
|
|
34
|
+
idempotencyKeyForCreate: string | undefined;
|
|
35
|
+
idempotencyKeyForComplete: string | undefined;
|
|
36
|
+
tags: Record<string, string> | undefined;
|
|
37
|
+
};
|
|
38
|
+
export type RejectedPromise = {
|
|
39
|
+
state: "REJECTED";
|
|
40
|
+
id: string;
|
|
41
|
+
timeout: number;
|
|
42
|
+
param: {
|
|
43
|
+
headers: Record<string, string> | undefined;
|
|
44
|
+
data: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
value: {
|
|
47
|
+
headers: Record<string, string> | undefined;
|
|
48
|
+
data: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
createdOn: number;
|
|
51
|
+
completedOn: number;
|
|
52
|
+
idempotencyKeyForCreate: string | undefined;
|
|
53
|
+
idempotencyKeyForComplete: string | undefined;
|
|
54
|
+
tags: Record<string, string> | undefined;
|
|
55
|
+
};
|
|
56
|
+
export type CanceledPromise = {
|
|
57
|
+
state: "REJECTED_CANCELED";
|
|
58
|
+
id: string;
|
|
59
|
+
timeout: number;
|
|
60
|
+
param: {
|
|
61
|
+
headers: Record<string, string> | undefined;
|
|
62
|
+
data: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
value: {
|
|
65
|
+
headers: Record<string, string> | undefined;
|
|
66
|
+
data: string | undefined;
|
|
67
|
+
};
|
|
68
|
+
createdOn: number;
|
|
69
|
+
completedOn: number;
|
|
70
|
+
idempotencyKeyForCreate: string | undefined;
|
|
71
|
+
idempotencyKeyForComplete: string | undefined;
|
|
72
|
+
tags: Record<string, string> | undefined;
|
|
73
|
+
};
|
|
74
|
+
export type TimedoutPromise = {
|
|
75
|
+
state: "REJECTED_TIMEDOUT";
|
|
76
|
+
id: string;
|
|
77
|
+
timeout: number;
|
|
78
|
+
param: {
|
|
79
|
+
headers: Record<string, string> | undefined;
|
|
80
|
+
data: string | undefined;
|
|
81
|
+
};
|
|
82
|
+
value: {
|
|
83
|
+
headers: undefined;
|
|
84
|
+
data: undefined;
|
|
85
|
+
};
|
|
86
|
+
createdOn: number;
|
|
87
|
+
completedOn: number;
|
|
88
|
+
idempotencyKeyForCreate: string | undefined;
|
|
89
|
+
idempotencyKeyForComplete: undefined;
|
|
90
|
+
tags: Record<string, string> | undefined;
|
|
91
|
+
};
|
|
92
|
+
export declare function isDurablePromise(p: unknown): p is DurablePromise;
|
|
93
|
+
export declare function isPendingPromise(p: unknown): p is PendingPromise;
|
|
94
|
+
export declare function isResolvedPromise(p: unknown): p is ResolvedPromise;
|
|
95
|
+
export declare function isRejectedPromise(p: unknown): p is RejectedPromise;
|
|
96
|
+
export declare function isCanceledPromise(p: unknown): p is CanceledPromise;
|
|
97
|
+
export declare function isTimedoutPromise(p: unknown): p is TimedoutPromise;
|
|
98
|
+
export declare function isCompletedPromise(p: unknown): p is ResolvedPromise | RejectedPromise | CanceledPromise | TimedoutPromise;
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/core/promises/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe,CAAC;AAEpH,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,SAAS,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC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MAAM,CAAC;IAChB,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;QAC5C,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;KAC1B,CAAC;IACF,KAAK,EAAE;QACL,OAAO,EAAE,SAAS,CAAC;QACnB,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,yBAAyB,EAAE,SAAS,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAC1C,CAAC;AAIF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,CAYhE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,CAEhE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,eAAe,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe,CAE5E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Type guards
|
|
2
|
+
export function isDurablePromise(p) {
|
|
3
|
+
if (p !== null &&
|
|
4
|
+
typeof p === "object" &&
|
|
5
|
+
"state" in p &&
|
|
6
|
+
typeof p.state === "string" &&
|
|
7
|
+
["PENDING", "RESOLVED", "REJECTED", "REJECTED_CANCELED", "REJECTED_TIMEDOUT"].includes(p.state)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export function isPendingPromise(p) {
|
|
13
|
+
return isDurablePromise(p) && p.state === "PENDING";
|
|
14
|
+
}
|
|
15
|
+
export function isResolvedPromise(p) {
|
|
16
|
+
return isDurablePromise(p) && p.state === "RESOLVED";
|
|
17
|
+
}
|
|
18
|
+
export function isRejectedPromise(p) {
|
|
19
|
+
return isDurablePromise(p) && p.state === "REJECTED";
|
|
20
|
+
}
|
|
21
|
+
export function isCanceledPromise(p) {
|
|
22
|
+
return isDurablePromise(p) && p.state === "REJECTED_CANCELED";
|
|
23
|
+
}
|
|
24
|
+
export function isTimedoutPromise(p) {
|
|
25
|
+
return isDurablePromise(p) && p.state === "REJECTED_TIMEDOUT";
|
|
26
|
+
}
|
|
27
|
+
export function isCompletedPromise(p) {
|
|
28
|
+
return isDurablePromise(p) && ["RESOLVED", "REJECTED", "REJECTED_CANCELED", "REJECTED_TIMEDOUT"].includes(p.state);
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IRetry, IterableRetry } from "../retry";
|
|
2
|
+
export declare class Retry extends IterableRetry implements IRetry {
|
|
3
|
+
private initialDelay;
|
|
4
|
+
private backoffFactor;
|
|
5
|
+
private maxAttempts;
|
|
6
|
+
private maxDelay;
|
|
7
|
+
constructor(initialDelay: number, backoffFactor: number, maxAttempts: number, maxDelay: number);
|
|
8
|
+
static exponential(initialDelay?: number, backoffFactor?: number, maxAttempts?: number, maxDelay?: number): Retry;
|
|
9
|
+
static linear(delay?: number, // 1 second
|
|
10
|
+
maxAttempts?: number): Retry;
|
|
11
|
+
static never(): Retry;
|
|
12
|
+
next<T extends {
|
|
13
|
+
attempt: number;
|
|
14
|
+
timeout: number;
|
|
15
|
+
}>(ctx: T): {
|
|
16
|
+
done: boolean;
|
|
17
|
+
delay?: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../lib/core/retries/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjD,qBAAa,KAAM,SAAQ,aAAc,YAAW,MAAM;IAEtD,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,QAAQ;gBAHR,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM;IAK1B,MAAM,CAAC,WAAW,CAChB,YAAY,GAAE,MAAY,EAC1B,aAAa,GAAE,MAAU,EACzB,WAAW,GAAE,MAAiB,EAC9B,QAAQ,GAAE,MAAc,GACvB,KAAK;IAIR,MAAM,CAAC,MAAM,CACX,KAAK,GAAE,MAAa,EAAE,WAAW;IACjC,WAAW,GAAE,MAAiB,GAC7B,KAAK;IAIR,MAAM,CAAC,KAAK,IAAI,KAAK;IAIrB,IAAI,CAAC,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;CAiBhG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IterableRetry } from "../retry";
|
|
2
|
+
export class Retry extends IterableRetry {
|
|
3
|
+
initialDelay;
|
|
4
|
+
backoffFactor;
|
|
5
|
+
maxAttempts;
|
|
6
|
+
maxDelay;
|
|
7
|
+
constructor(initialDelay, backoffFactor, maxAttempts, maxDelay) {
|
|
8
|
+
super();
|
|
9
|
+
this.initialDelay = initialDelay;
|
|
10
|
+
this.backoffFactor = backoffFactor;
|
|
11
|
+
this.maxAttempts = maxAttempts;
|
|
12
|
+
this.maxDelay = maxDelay;
|
|
13
|
+
}
|
|
14
|
+
static exponential(initialDelay = 100, backoffFactor = 2, maxAttempts = Infinity, maxDelay = 60000) {
|
|
15
|
+
return new Retry(initialDelay, backoffFactor, maxAttempts, maxDelay);
|
|
16
|
+
}
|
|
17
|
+
static linear(delay = 1000, // 1 second
|
|
18
|
+
maxAttempts = Infinity) {
|
|
19
|
+
return new Retry(delay, 1, maxAttempts, delay);
|
|
20
|
+
}
|
|
21
|
+
static never() {
|
|
22
|
+
return new Retry(0, 0, 1, 0);
|
|
23
|
+
}
|
|
24
|
+
next(ctx) {
|
|
25
|
+
// attempt 0: 0ms delay
|
|
26
|
+
// attampt n: {initial * factor^(attempt-1)}ms delay (or max delay)
|
|
27
|
+
const delay = Math.min(Math.min(ctx.attempt, 1) * this.initialDelay * Math.pow(this.backoffFactor, ctx.attempt - 1), this.maxDelay);
|
|
28
|
+
if (Date.now() + delay >= ctx.timeout || ctx.attempt >= this.maxAttempts) {
|
|
29
|
+
return { done: true };
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
done: false,
|
|
33
|
+
delay: delay,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface IRetry {
|
|
2
|
+
next<T extends {
|
|
3
|
+
attempt: number;
|
|
4
|
+
timeout: number;
|
|
5
|
+
}>(ctx: T): {
|
|
6
|
+
done: boolean;
|
|
7
|
+
delay?: number;
|
|
8
|
+
};
|
|
9
|
+
iterator<T extends {
|
|
10
|
+
attempt: number;
|
|
11
|
+
timeout: number;
|
|
12
|
+
}>(ctx: T): IterableIterator<number>;
|
|
13
|
+
}
|
|
14
|
+
export declare class IterableRetry implements IRetry {
|
|
15
|
+
next<T extends {
|
|
16
|
+
attempt: number;
|
|
17
|
+
timeout: number;
|
|
18
|
+
}>(ctx: T): {
|
|
19
|
+
done: boolean;
|
|
20
|
+
delay?: number;
|
|
21
|
+
};
|
|
22
|
+
iterator<T extends {
|
|
23
|
+
attempt: number;
|
|
24
|
+
timeout: number;
|
|
25
|
+
}>(ctx: T): IterableIterator<number>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../lib/core/retry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChG,QAAQ,CAAC,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;CAC5F;AAED,qBAAa,aAAc,YAAW,MAAM;IAC1C,IAAI,CAAC,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAI/F,QAAQ,CAAC,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC;CAa3F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class IterableRetry {
|
|
2
|
+
next(ctx) {
|
|
3
|
+
throw new Error("Method not implemented");
|
|
4
|
+
}
|
|
5
|
+
iterator(ctx) {
|
|
6
|
+
const self = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
7
|
+
return {
|
|
8
|
+
next() {
|
|
9
|
+
const { done, delay } = self.next(ctx);
|
|
10
|
+
return { done, value: delay || 0 };
|
|
11
|
+
},
|
|
12
|
+
[Symbol.iterator]() {
|
|
13
|
+
return this;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Schedule = {
|
|
2
|
+
id: string;
|
|
3
|
+
description: string | undefined;
|
|
4
|
+
cron: string;
|
|
5
|
+
tags: Record<string, string> | undefined;
|
|
6
|
+
promiseId: string;
|
|
7
|
+
promiseTimeout: number;
|
|
8
|
+
promiseParam: {
|
|
9
|
+
data: string | undefined;
|
|
10
|
+
headers: Record<string, string> | undefined;
|
|
11
|
+
};
|
|
12
|
+
promiseTags: Record<string, string> | undefined;
|
|
13
|
+
lastRunTime: number | undefined;
|
|
14
|
+
nextRunTime: number;
|
|
15
|
+
idempotencyKey: string | undefined;
|
|
16
|
+
createdOn: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function isSchedule(s: unknown): s is Schedule;
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/core/schedules/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;KAC7C,CAAC;IACF,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAChD,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,QAAQ,CAEpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../lib/core/storage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvF,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,GAAG,IAAI,cAAc,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IStorage } from "../storage";
|
|
2
|
+
export declare class MemoryStorage<T> implements IStorage<T> {
|
|
3
|
+
private items;
|
|
4
|
+
rmw<X extends T | undefined>(id: string, func: (item: T | undefined) => X): Promise<X>;
|
|
5
|
+
rmd(id: string, func: (item: T) => boolean): Promise<boolean>;
|
|
6
|
+
all(): AsyncGenerator<T[], void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../lib/core/storages/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,KAAK,CAAyB;IAEhC,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAStF,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAW5D,GAAG,IAAI,cAAc,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC;CAGxC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class MemoryStorage {
|
|
2
|
+
items = {};
|
|
3
|
+
async rmw(id, func) {
|
|
4
|
+
const item = func(this.items[id]);
|
|
5
|
+
if (item) {
|
|
6
|
+
this.items[id] = item;
|
|
7
|
+
}
|
|
8
|
+
return item;
|
|
9
|
+
}
|
|
10
|
+
async rmd(id, func) {
|
|
11
|
+
const item = this.items[id];
|
|
12
|
+
let result = false;
|
|
13
|
+
if (item && func(item)) {
|
|
14
|
+
delete this.items[id];
|
|
15
|
+
result = true;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
async *all() {
|
|
20
|
+
yield Object.values(this.items);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DurablePromise } from "../promises/types";
|
|
2
|
+
import { IStorage } from "../storage";
|
|
3
|
+
export declare class WithTimeout implements IStorage<DurablePromise> {
|
|
4
|
+
private storage;
|
|
5
|
+
constructor(storage: IStorage<DurablePromise>);
|
|
6
|
+
rmw<T extends DurablePromise | undefined>(id: string, func: (item: DurablePromise | undefined) => T): Promise<T>;
|
|
7
|
+
rmd(id: string, func: (item: DurablePromise) => boolean): Promise<boolean>;
|
|
8
|
+
all(): AsyncGenerator<DurablePromise[], void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=withTimeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTimeout.d.ts","sourceRoot":"","sources":["../../../lib/core/storages/withTimeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqC,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,qBAAa,WAAY,YAAW,QAAQ,CAAC,cAAc,CAAC;IAC9C,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC;IAErD,GAAG,CAAC,CAAC,SAAS,cAAc,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhH,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAInE,GAAG,IAAI,cAAc,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC;CAKrD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isPendingPromise } from "../promises/types";
|
|
2
|
+
export class WithTimeout {
|
|
3
|
+
storage;
|
|
4
|
+
constructor(storage) {
|
|
5
|
+
this.storage = storage;
|
|
6
|
+
}
|
|
7
|
+
rmw(id, func) {
|
|
8
|
+
return this.storage.rmw(id, (p) => func(p ? timeout(p) : undefined));
|
|
9
|
+
}
|
|
10
|
+
rmd(id, func) {
|
|
11
|
+
return this.storage.rmd(id, (p) => func(timeout(p)));
|
|
12
|
+
}
|
|
13
|
+
async *all() {
|
|
14
|
+
for await (const promises of this.storage.all()) {
|
|
15
|
+
yield promises.map(timeout);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function timeout(promise) {
|
|
20
|
+
if (isPendingPromise(promise) && Date.now() >= promise.timeout) {
|
|
21
|
+
return {
|
|
22
|
+
state: "REJECTED_TIMEDOUT",
|
|
23
|
+
id: promise.id,
|
|
24
|
+
timeout: promise.timeout,
|
|
25
|
+
param: promise.param,
|
|
26
|
+
value: {
|
|
27
|
+
headers: undefined,
|
|
28
|
+
data: undefined,
|
|
29
|
+
},
|
|
30
|
+
createdOn: promise.createdOn,
|
|
31
|
+
completedOn: promise.timeout,
|
|
32
|
+
idempotencyKeyForCreate: promise.idempotencyKeyForCreate,
|
|
33
|
+
idempotencyKeyForComplete: undefined,
|
|
34
|
+
tags: promise.tags,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return promise;
|
|
38
|
+
}
|