@restatedev/restate-sdk 1.17.2 → 1.17.3
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/context_impl.cjs +74 -17
- package/dist/context_impl.d.ts.map +1 -1
- package/dist/context_impl.js +74 -17
- package/dist/context_impl.js.map +1 -1
- package/dist/endpoint/endpoint.cjs +1 -1
- package/dist/endpoint/endpoint.js +1 -1
- package/dist/endpoint/endpoint.js.map +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.cjs +21 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +10 -0
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +21 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
- package/dist/internal.cjs +19 -1
- package/dist/internal.d.cts +67 -4
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +67 -4
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +19 -1
- package/dist/internal.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/promises.cjs +5 -1
- package/dist/promises.d.cts.map +1 -1
- package/dist/promises.d.ts.map +1 -1
- package/dist/promises.js +5 -1
- package/dist/promises.js.map +1 -1
- package/dist/types/errors.cjs +2 -2
- package/dist/types/errors.d.cts +1 -1
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -2
- package/dist/types/errors.js.map +1 -1
- package/package.json +2 -2
package/dist/internal.cjs
CHANGED
|
@@ -2,7 +2,25 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_errors = require('./types/errors.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/internal.ts
|
|
5
|
-
var internal_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
5
|
+
var internal_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
6
|
+
asInternal: () => asInternal,
|
|
7
|
+
isSuspendedError: () => require_errors.isSuspendedError
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Downcast the given context to {@link ContextInternal}, to access the internal APIs.
|
|
11
|
+
*
|
|
12
|
+
* Works with every context type passed to handlers, e.g. `Context`, `ObjectContext`, `ObjectSharedContext`, `WorkflowContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
function asInternal(ctx) {
|
|
22
|
+
return ctx;
|
|
23
|
+
}
|
|
6
24
|
|
|
7
25
|
//#endregion
|
|
8
26
|
Object.defineProperty(exports, 'internal_exports', {
|
package/dist/internal.d.cts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { isSuspendedError } from "./types/errors.cjs";
|
|
2
2
|
import { Context, InvocationId, RestatePromise } from "./context.cjs";
|
|
3
|
+
import { Serde } from "@restatedev/restate-sdk-core";
|
|
3
4
|
|
|
4
5
|
//#region src/internal.d.ts
|
|
5
6
|
declare namespace internal_d_exports {
|
|
6
|
-
export { ContextInternal, isSuspendedError };
|
|
7
|
+
export { ContextInternal, GetProjectOptions, asInternal, isSuspendedError };
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Downcast the given context to {@link ContextInternal}, to access the internal APIs.
|
|
11
|
+
*
|
|
12
|
+
* Works with every context type passed to handlers, e.g. `Context`, `ObjectContext`, `ObjectSharedContext`, `WorkflowContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
declare function asInternal(ctx: Context): ContextInternal;
|
|
8
22
|
/**
|
|
9
23
|
* Internal {@link Context} interface exposing additional features.
|
|
10
24
|
*
|
|
@@ -40,7 +54,7 @@ interface ContextInternal extends Context {
|
|
|
40
54
|
* name: "greeter",
|
|
41
55
|
* handlers: {
|
|
42
56
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
43
|
-
* ctxInternal =
|
|
57
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
44
58
|
* const result = await RestatePromise.race([
|
|
45
59
|
* ctx.run(() => longRunningTask(name)),
|
|
46
60
|
* ctxInternal.cancellation().map(() => { throw new restate.TerminalError("Cancelled") }),
|
|
@@ -58,7 +72,7 @@ interface ContextInternal extends Context {
|
|
|
58
72
|
* name: "greeter",
|
|
59
73
|
* handlers: {
|
|
60
74
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
61
|
-
* const ctxInternal =
|
|
75
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
62
76
|
* const controller = new AbortController();
|
|
63
77
|
* const cancellation = ctxInternal.cancellation()
|
|
64
78
|
* .map(() => {
|
|
@@ -82,7 +96,7 @@ interface ContextInternal extends Context {
|
|
|
82
96
|
* name: "greeter",
|
|
83
97
|
* handlers: {
|
|
84
98
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
85
|
-
* const ctxInternal =
|
|
99
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
86
100
|
* try {
|
|
87
101
|
* return await RestatePromise.race([
|
|
88
102
|
* ctx.run(() => longRunningTask(name)),
|
|
@@ -118,7 +132,56 @@ interface ContextInternal extends Context {
|
|
|
118
132
|
* @experimental
|
|
119
133
|
*/
|
|
120
134
|
cancelPreviousCalls(): RestatePromise<InvocationId[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Get state from the Restate runtime, apply the given `projection` to it,
|
|
137
|
+
* and record in the journal only the result of the projection.
|
|
138
|
+
*
|
|
139
|
+
* Use this to read big state values when you need only a small part of them:
|
|
140
|
+
* unlike `ctx.get`, the complete state value is not recorded in the journal,
|
|
141
|
+
* only its projection.
|
|
142
|
+
*
|
|
143
|
+
* It will appear in the UI as run(project:state_key).
|
|
144
|
+
*
|
|
145
|
+
* This method **MUST** only be used within Virtual Object and Workflow handlers.
|
|
146
|
+
*
|
|
147
|
+
* **NOTE:** Requires Restate >= 1.8 with service protocol V8 enabled, and **does not** work with request/response protocol mode (e.g. with AWS Lambda).
|
|
148
|
+
*
|
|
149
|
+
* @param name key of the state to retrieve
|
|
150
|
+
* @param projection function receiving the state value, or `null` if the state is empty.
|
|
151
|
+
* @param options serde for the state value, and serde for the projection result.
|
|
152
|
+
* @returns a {@link RestatePromise} resolved with the result of the projection.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
157
|
+
* const itemsCount = await ctxInternal.getProject<Item[], number>(
|
|
158
|
+
* "items",
|
|
159
|
+
* (items) => items?.length ?? 0
|
|
160
|
+
* );
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @experimental
|
|
164
|
+
*/
|
|
165
|
+
getProject<TValue, TResult>(name: string, projection: (value: TValue | null) => TResult | Promise<TResult>, options?: GetProjectOptions<TValue, TResult>): RestatePromise<TResult>;
|
|
121
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Options for {@link ContextInternal.getProject}.
|
|
169
|
+
*
|
|
170
|
+
* @experimental
|
|
171
|
+
*/
|
|
172
|
+
type GetProjectOptions<TValue, TResult> = {
|
|
173
|
+
/**
|
|
174
|
+
* Serde used to deserialize the state value.
|
|
175
|
+
*/
|
|
176
|
+
serde?: Serde<TValue>;
|
|
177
|
+
/**
|
|
178
|
+
* Serde used to serialize the projection result, recorded in the journal.
|
|
179
|
+
*
|
|
180
|
+
* If not set, defaults to {@link GetProjectOptions.serde} when that is set,
|
|
181
|
+
* otherwise to the default serde.
|
|
182
|
+
*/
|
|
183
|
+
resultSerde?: Serde<TResult>;
|
|
184
|
+
};
|
|
122
185
|
//#endregion
|
|
123
186
|
export { internal_d_exports };
|
|
124
187
|
//# sourceMappingURL=internal.d.cts.map
|
package/dist/internal.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.cts","names":[],"sources":["../src/internal.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.cts","names":[],"sources":["../src/internal.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;AAiBA;AAWA;;AA2GwC,iBAtHxB,UAAA,CAsHwB,GAAA,EAtHR,OAsHQ,CAAA,EAtHE,eAsHF;;;;;;;;AAmC1B,UA9IG,eAAA,SAAwB,OA8I3B,CAAA;EACM;;;;AAQpB;;;;EAYgB,YAAA,EAAA,EAAA,OAAA;EAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAnEH;;;;;;;;;;yBAWO,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEAkChB,kBAAkB,UAAU,QAAQ,oBAC9C,kBAAkB,QAAQ,WACnC,eAAe;;;;;;;KAQR;;;;UAIF,MAAM;;;;;;;gBAQA,MAAM"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { isSuspendedError } from "./types/errors.js";
|
|
2
2
|
import { Context, InvocationId, RestatePromise } from "./context.js";
|
|
3
|
+
import { Serde } from "@restatedev/restate-sdk-core";
|
|
3
4
|
|
|
4
5
|
//#region src/internal.d.ts
|
|
5
6
|
declare namespace internal_d_exports {
|
|
6
|
-
export { ContextInternal, isSuspendedError };
|
|
7
|
+
export { ContextInternal, GetProjectOptions, asInternal, isSuspendedError };
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Downcast the given context to {@link ContextInternal}, to access the internal APIs.
|
|
11
|
+
*
|
|
12
|
+
* Works with every context type passed to handlers, e.g. `Context`, `ObjectContext`, `ObjectSharedContext`, `WorkflowContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
declare function asInternal(ctx: Context): ContextInternal;
|
|
8
22
|
/**
|
|
9
23
|
* Internal {@link Context} interface exposing additional features.
|
|
10
24
|
*
|
|
@@ -40,7 +54,7 @@ interface ContextInternal extends Context {
|
|
|
40
54
|
* name: "greeter",
|
|
41
55
|
* handlers: {
|
|
42
56
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
43
|
-
* ctxInternal =
|
|
57
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
44
58
|
* const result = await RestatePromise.race([
|
|
45
59
|
* ctx.run(() => longRunningTask(name)),
|
|
46
60
|
* ctxInternal.cancellation().map(() => { throw new restate.TerminalError("Cancelled") }),
|
|
@@ -58,7 +72,7 @@ interface ContextInternal extends Context {
|
|
|
58
72
|
* name: "greeter",
|
|
59
73
|
* handlers: {
|
|
60
74
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
61
|
-
* const ctxInternal =
|
|
75
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
62
76
|
* const controller = new AbortController();
|
|
63
77
|
* const cancellation = ctxInternal.cancellation()
|
|
64
78
|
* .map(() => {
|
|
@@ -82,7 +96,7 @@ interface ContextInternal extends Context {
|
|
|
82
96
|
* name: "greeter",
|
|
83
97
|
* handlers: {
|
|
84
98
|
* greet: async (ctx: restate.Context, name: string) => {
|
|
85
|
-
* const ctxInternal =
|
|
99
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
86
100
|
* try {
|
|
87
101
|
* return await RestatePromise.race([
|
|
88
102
|
* ctx.run(() => longRunningTask(name)),
|
|
@@ -118,7 +132,56 @@ interface ContextInternal extends Context {
|
|
|
118
132
|
* @experimental
|
|
119
133
|
*/
|
|
120
134
|
cancelPreviousCalls(): RestatePromise<InvocationId[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Get state from the Restate runtime, apply the given `projection` to it,
|
|
137
|
+
* and record in the journal only the result of the projection.
|
|
138
|
+
*
|
|
139
|
+
* Use this to read big state values when you need only a small part of them:
|
|
140
|
+
* unlike `ctx.get`, the complete state value is not recorded in the journal,
|
|
141
|
+
* only its projection.
|
|
142
|
+
*
|
|
143
|
+
* It will appear in the UI as run(project:state_key).
|
|
144
|
+
*
|
|
145
|
+
* This method **MUST** only be used within Virtual Object and Workflow handlers.
|
|
146
|
+
*
|
|
147
|
+
* **NOTE:** Requires Restate >= 1.8 with service protocol V8 enabled, and **does not** work with request/response protocol mode (e.g. with AWS Lambda).
|
|
148
|
+
*
|
|
149
|
+
* @param name key of the state to retrieve
|
|
150
|
+
* @param projection function receiving the state value, or `null` if the state is empty.
|
|
151
|
+
* @param options serde for the state value, and serde for the projection result.
|
|
152
|
+
* @returns a {@link RestatePromise} resolved with the result of the projection.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
157
|
+
* const itemsCount = await ctxInternal.getProject<Item[], number>(
|
|
158
|
+
* "items",
|
|
159
|
+
* (items) => items?.length ?? 0
|
|
160
|
+
* );
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @experimental
|
|
164
|
+
*/
|
|
165
|
+
getProject<TValue, TResult>(name: string, projection: (value: TValue | null) => TResult | Promise<TResult>, options?: GetProjectOptions<TValue, TResult>): RestatePromise<TResult>;
|
|
121
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Options for {@link ContextInternal.getProject}.
|
|
169
|
+
*
|
|
170
|
+
* @experimental
|
|
171
|
+
*/
|
|
172
|
+
type GetProjectOptions<TValue, TResult> = {
|
|
173
|
+
/**
|
|
174
|
+
* Serde used to deserialize the state value.
|
|
175
|
+
*/
|
|
176
|
+
serde?: Serde<TValue>;
|
|
177
|
+
/**
|
|
178
|
+
* Serde used to serialize the projection result, recorded in the journal.
|
|
179
|
+
*
|
|
180
|
+
* If not set, defaults to {@link GetProjectOptions.serde} when that is set,
|
|
181
|
+
* otherwise to the default serde.
|
|
182
|
+
*/
|
|
183
|
+
resultSerde?: Serde<TResult>;
|
|
184
|
+
};
|
|
122
185
|
//#endregion
|
|
123
186
|
export { internal_d_exports };
|
|
124
187
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","names":[],"sources":["../src/internal.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","names":[],"sources":["../src/internal.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;AAiBA;AAWA;;AA2GwC,iBAtHxB,UAAA,CAsHwB,GAAA,EAtHR,OAsHQ,CAAA,EAtHE,eAsHF;;;;;;;;AAmC1B,UA9IG,eAAA,SAAwB,OA8I3B,CAAA;EACM;;;;AAQpB;;;;EAYgB,YAAA,EAAA,EAAA,OAAA;EAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAnEH;;;;;;;;;;yBAWO,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEAkChB,kBAAkB,UAAU,QAAQ,oBAC9C,kBAAkB,QAAQ,WACnC,eAAe;;;;;;;KAQR;;;;UAIF,MAAM;;;;;;;gBAQA,MAAM"}
|
package/dist/internal.js
CHANGED
|
@@ -2,7 +2,25 @@ import { __export } from "./_virtual/rolldown_runtime.js";
|
|
|
2
2
|
import { isSuspendedError } from "./types/errors.js";
|
|
3
3
|
|
|
4
4
|
//#region src/internal.ts
|
|
5
|
-
var internal_exports = /* @__PURE__ */ __export({
|
|
5
|
+
var internal_exports = /* @__PURE__ */ __export({
|
|
6
|
+
asInternal: () => asInternal,
|
|
7
|
+
isSuspendedError: () => isSuspendedError
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Downcast the given context to {@link ContextInternal}, to access the internal APIs.
|
|
11
|
+
*
|
|
12
|
+
* Works with every context type passed to handlers, e.g. `Context`, `ObjectContext`, `ObjectSharedContext`, `WorkflowContext`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ctxInternal = restate.internal.asInternal(ctx);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
function asInternal(ctx) {
|
|
22
|
+
return ctx;
|
|
23
|
+
}
|
|
6
24
|
|
|
7
25
|
//#endregion
|
|
8
26
|
export { internal_exports };
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","names":[],"sources":["../src/internal.ts"],"sourcesContent":["import { Context, InvocationId, RestatePromise } from \"./context.js\";\n\nexport { isSuspendedError } from \"./types/errors.js\";\n\n/**\n * Internal {@link Context} interface exposing additional features.\n *\n * Please note that this API is to be considered experimental and might change without notice.\n *\n * @experimental\n */\nexport interface ContextInternal extends Context {\n /**\n * Returns true if the handler is in the processing phase.\n * This is the mechanism used by `ctx.console` to distinguish whether we should log or not in replaying/processing.\n *\n * **WARNING**: This method should not be used to influence control flow, as it will **surely** lead to non-determinism errors!\n *\n * @experimental\n */\n isProcessing(): boolean;\n\n /**\n * Returns a {@link RestatePromise} that resolves with `undefined` when Restate signals cancellation\n * of the current invocation.\n *\n * This method **MUST** only be used when the handler (or its parent service/endpoint) is configured\n * with `explicitCancellation: true`. Without configuring this option, cancellations are propagated automatically,\n * and this promise will **NEVER** resolve.\n *\n * **Promise reuse:** calling this method multiple times returns the **same** promise instance as long as\n * the current cancellation signal has not yet arrived. Once the promise resolves (cancellation received),\n * later calls return a **new** promise that will resolve on the next cancellation signal.\n *\n * @example Race a long-running side effect against cancellation\n * ```ts\n * const greeter = restate.service({\n * name: \"greeter\",\n * handlers: {\n * greet: async (ctx: restate.Context, name: string) => {\n * ctxInternal =
|
|
1
|
+
{"version":3,"file":"internal.js","names":[],"sources":["../src/internal.ts"],"sourcesContent":["import { Context, InvocationId, RestatePromise } from \"./context.js\";\nimport type { Serde } from \"@restatedev/restate-sdk-core\";\n\nexport { isSuspendedError } from \"./types/errors.js\";\n\n/**\n * Downcast the given context to {@link ContextInternal}, to access the internal APIs.\n *\n * Works with every context type passed to handlers, e.g. `Context`, `ObjectContext`, `ObjectSharedContext`, `WorkflowContext`.\n *\n * @example\n * ```ts\n * const ctxInternal = restate.internal.asInternal(ctx);\n * ```\n *\n * @experimental\n */\nexport function asInternal(ctx: Context): ContextInternal {\n return ctx as ContextInternal;\n}\n\n/**\n * Internal {@link Context} interface exposing additional features.\n *\n * Please note that this API is to be considered experimental and might change without notice.\n *\n * @experimental\n */\nexport interface ContextInternal extends Context {\n /**\n * Returns true if the handler is in the processing phase.\n * This is the mechanism used by `ctx.console` to distinguish whether we should log or not in replaying/processing.\n *\n * **WARNING**: This method should not be used to influence control flow, as it will **surely** lead to non-determinism errors!\n *\n * @experimental\n */\n isProcessing(): boolean;\n\n /**\n * Returns a {@link RestatePromise} that resolves with `undefined` when Restate signals cancellation\n * of the current invocation.\n *\n * This method **MUST** only be used when the handler (or its parent service/endpoint) is configured\n * with `explicitCancellation: true`. Without configuring this option, cancellations are propagated automatically,\n * and this promise will **NEVER** resolve.\n *\n * **Promise reuse:** calling this method multiple times returns the **same** promise instance as long as\n * the current cancellation signal has not yet arrived. Once the promise resolves (cancellation received),\n * later calls return a **new** promise that will resolve on the next cancellation signal.\n *\n * @example Race a long-running side effect against cancellation\n * ```ts\n * const greeter = restate.service({\n * name: \"greeter\",\n * handlers: {\n * greet: async (ctx: restate.Context, name: string) => {\n * const ctxInternal = restate.internal.asInternal(ctx);\n * const result = await RestatePromise.race([\n * ctx.run(() => longRunningTask(name)),\n * ctxInternal.cancellation().map(() => { throw new restate.TerminalError(\"Cancelled\") }),\n * ]);\n * return result;\n * },\n * },\n * options: { explicitCancellation: true },\n * });\n * ```\n *\n * @example Use the cancellation promise to create an AbortSignal for ctx.run\n * ```ts\n * const greeter = restate.service({\n * name: \"greeter\",\n * handlers: {\n * greet: async (ctx: restate.Context, name: string) => {\n * const ctxInternal = restate.internal.asInternal(ctx);\n * const controller = new AbortController();\n * const cancellation = ctxInternal.cancellation()\n * .map(() => {\n * controller.abort();\n * throw new restate.TerminalError(\"Cancelled\");\n * });\n *\n * return RestatePromise.race([\n * ctx.run(() => fetch(`https://api.example.com/greet/${name}`, { signal: controller.signal })),\n * cancellation,\n * ]);\n * },\n * },\n * options: { explicitCancellation: true },\n * });\n * ```\n *\n * @example Handle cancellation, perform cleanup, then listen for the next cancellation\n * ```ts\n * const greeter = restate.service({\n * name: \"greeter\",\n * handlers: {\n * greet: async (ctx: restate.Context, name: string) => {\n * const ctxInternal = restate.internal.asInternal(ctx);\n * try {\n * return await RestatePromise.race([\n * ctx.run(() => longRunningTask(name)),\n * ctxInternal.cancellation().map(() => { throw new restate.TerminalError(\"Cancelled\") }),\n * ]);\n * } catch (e) {\n * // Perform cleanup\n * await ctx.run(() => cleanupResources(name));\n *\n * // After cancellation is resolved, ctx.cancellation() returns a fresh promise.\n * // Race cleanup confirmation against the next cancellation signal.\n * await RestatePromise.race([\n * ctx.run(() => confirmCleanup(name)),\n * ctxInternal.cancellation().map(() => { throw new restate.TerminalError(\"Canceled during cleanup\") }),\n * ]);\n * }\n * },\n * },\n * options: { explicitCancellation: true },\n * });\n * ```\n *\n * @experimental\n */\n cancellation(): RestatePromise<void>;\n\n /**\n * Cancel all previous calls made from this handler.\n *\n * This method **MUST** only be used when the handler (or its parent service/endpoint) is configured\n * with `explicitCancellation: true`. Without configuring this option, this operation will always be a no-op.\n *\n * @return the invocation id of the canceled calls.\n * @experimental\n */\n cancelPreviousCalls(): RestatePromise<InvocationId[]>;\n\n /**\n * Get state from the Restate runtime, apply the given `projection` to it,\n * and record in the journal only the result of the projection.\n *\n * Use this to read big state values when you need only a small part of them:\n * unlike `ctx.get`, the complete state value is not recorded in the journal,\n * only its projection.\n *\n * It will appear in the UI as run(project:state_key).\n *\n * This method **MUST** only be used within Virtual Object and Workflow handlers.\n *\n * **NOTE:** Requires Restate >= 1.8 with service protocol V8 enabled, and **does not** work with request/response protocol mode (e.g. with AWS Lambda).\n *\n * @param name key of the state to retrieve\n * @param projection function receiving the state value, or `null` if the state is empty.\n * @param options serde for the state value, and serde for the projection result.\n * @returns a {@link RestatePromise} resolved with the result of the projection.\n *\n * @example\n * ```ts\n * const ctxInternal = restate.internal.asInternal(ctx);\n * const itemsCount = await ctxInternal.getProject<Item[], number>(\n * \"items\",\n * (items) => items?.length ?? 0\n * );\n * ```\n *\n * @experimental\n */\n getProject<TValue, TResult>(\n name: string,\n projection: (value: TValue | null) => TResult | Promise<TResult>,\n options?: GetProjectOptions<TValue, TResult>\n ): RestatePromise<TResult>;\n}\n\n/**\n * Options for {@link ContextInternal.getProject}.\n *\n * @experimental\n */\nexport type GetProjectOptions<TValue, TResult> = {\n /**\n * Serde used to deserialize the state value.\n */\n serde?: Serde<TValue>;\n\n /**\n * Serde used to serialize the projection result, recorded in the journal.\n *\n * If not set, defaults to {@link GetProjectOptions.serde} when that is set,\n * otherwise to the default serde.\n */\n resultSerde?: Serde<TResult>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,WAAW,KAA+B;AACxD,QAAO"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
package/dist/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@restatedev/restate-sdk\",\n \"version\": \"1.17.
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@restatedev/restate-sdk\",\n \"version\": \"1.17.3\",\n \"description\": \"Typescript SDK for Restate\",\n \"author\": \"Restate Developers\",\n \"email\": \"code@restate.dev\",\n \"license\": \"MIT\",\n \"homepage\": \"https://github.com/restatedev/sdk-typescript#readme\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/restatedev/sdk-typescript.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/restatedev/sdk-typescript/issues\"\n },\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.cts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./fetch\": {\n \"import\": \"./dist/fetch.js\",\n \"require\": \"./dist/fetch.cjs\"\n },\n \"./lambda\": {\n \"import\": \"./dist/lambda.js\",\n \"require\": \"./dist/lambda.cjs\"\n },\n \"./node\": {\n \"import\": \"./dist/node.js\",\n \"require\": \"./dist/node.cjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"scripts\": {\n \"test\": \"turbo run _test --filter={.}...\",\n \"_test\": \"vitest run\",\n \"build\": \"turbo run _build --filter={.}...\",\n \"_build\": \"tsc --noEmit && tsdown\",\n \"dev\": \"tsc --noEmit --watch\",\n \"clean\": \"rm -rf dist *.tsbuildinfo .turbo\",\n \"check:types\": \"turbo run _check:types --filter={.}...\",\n \"_check:types\": \"tsc --noEmit --project tsconfig.build.json\",\n \"lint\": \"eslint .\",\n \"check:exports\": \"turbo run _check:exports --filter={.}...\",\n \"_check:exports\": \"attw --pack .\",\n \"check:api\": \"turbo run _check:api --filter={.}...\",\n \"_check:api\": \"api-extractor run --local && api-extractor run --local --config api-extractor.fetch.json && api-extractor run --local --config api-extractor.lambda.json && api-extractor run --local --config api-extractor.node.json\",\n \"prepublishOnly\": \"pnpm -w verify\"\n },\n \"dependencies\": {\n \"@restatedev/restate-sdk-core\": \"workspace:*\"\n },\n \"devDependencies\": {\n \"@types/aws-lambda\": \"^8.10.115\"\n },\n \"typesVersions\": {\n \"*\": {\n \"fetch\": [\n \"./dist/fetch.d.ts\"\n ],\n \"lambda\": [\n \"./dist/lambda.d.ts\"\n ],\n \"node\": [\n \"./dist/node.d.ts\"\n ]\n }\n }\n}\n"],"mappings":";cAEa"}
|
package/dist/promises.cjs
CHANGED
|
@@ -234,10 +234,11 @@ var ConstRestatePromise = class ConstRestatePromise extends InternalRestatePromi
|
|
|
234
234
|
* Promises executor, gluing VM with I/O and Promises given to user space.
|
|
235
235
|
*/
|
|
236
236
|
var PromisesExecutor = class {
|
|
237
|
-
constructor(coreVm, outputPump, runClosuresTracker, externalProgressChannel, errorCallback) {
|
|
237
|
+
constructor(coreVm, outputPump, runClosuresTracker, ephemeralRequestTracker, externalProgressChannel, errorCallback) {
|
|
238
238
|
this.coreVm = coreVm;
|
|
239
239
|
this.outputPump = outputPump;
|
|
240
240
|
this.runClosuresTracker = runClosuresTracker;
|
|
241
|
+
this.ephemeralRequestTracker = ephemeralRequestTracker;
|
|
241
242
|
this.externalProgressChannel = externalProgressChannel;
|
|
242
243
|
this.errorCallback = errorCallback;
|
|
243
244
|
}
|
|
@@ -263,6 +264,9 @@ var PromisesExecutor = class {
|
|
|
263
264
|
} else if (doProgressResult === "CancelSignalReceived") {
|
|
264
265
|
restatePromise.tryCancel();
|
|
265
266
|
return;
|
|
267
|
+
} else if ("EphemeralNotificationReady" in doProgressResult) {
|
|
268
|
+
const completionId = doProgressResult.EphemeralNotificationReady;
|
|
269
|
+
await this.ephemeralRequestTracker.complete(completionId, this.coreVm.take_ephemeral_notification(completionId));
|
|
266
270
|
} else {
|
|
267
271
|
this.runClosuresTracker.executeRun(doProgressResult.ExecuteRun);
|
|
268
272
|
await (0, node_timers_promises.setImmediate)();
|
package/dist/promises.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.d.cts","names":[],"sources":["../src/promises.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"promises.d.cts","names":[],"sources":["../src/promises.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;iBAkDgB,uBAAuB,QAAQ,UAAU,eAAe"}
|
package/dist/promises.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.d.ts","names":[],"sources":["../src/promises.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"promises.d.ts","names":[],"sources":["../src/promises.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;iBAkDgB,uBAAuB,QAAQ,UAAU,eAAe"}
|
package/dist/promises.js
CHANGED
|
@@ -232,10 +232,11 @@ var ConstRestatePromise = class ConstRestatePromise extends InternalRestatePromi
|
|
|
232
232
|
* Promises executor, gluing VM with I/O and Promises given to user space.
|
|
233
233
|
*/
|
|
234
234
|
var PromisesExecutor = class {
|
|
235
|
-
constructor(coreVm, outputPump, runClosuresTracker, externalProgressChannel, errorCallback) {
|
|
235
|
+
constructor(coreVm, outputPump, runClosuresTracker, ephemeralRequestTracker, externalProgressChannel, errorCallback) {
|
|
236
236
|
this.coreVm = coreVm;
|
|
237
237
|
this.outputPump = outputPump;
|
|
238
238
|
this.runClosuresTracker = runClosuresTracker;
|
|
239
|
+
this.ephemeralRequestTracker = ephemeralRequestTracker;
|
|
239
240
|
this.externalProgressChannel = externalProgressChannel;
|
|
240
241
|
this.errorCallback = errorCallback;
|
|
241
242
|
}
|
|
@@ -261,6 +262,9 @@ var PromisesExecutor = class {
|
|
|
261
262
|
} else if (doProgressResult === "CancelSignalReceived") {
|
|
262
263
|
restatePromise.tryCancel();
|
|
263
264
|
return;
|
|
265
|
+
} else if ("EphemeralNotificationReady" in doProgressResult) {
|
|
266
|
+
const completionId = doProgressResult.EphemeralNotificationReady;
|
|
267
|
+
await this.ephemeralRequestTracker.complete(completionId, this.coreVm.take_ephemeral_notification(completionId));
|
|
264
268
|
} else {
|
|
265
269
|
this.runClosuresTracker.executeRun(doProgressResult.ExecuteRun);
|
|
266
270
|
await setImmediate();
|
package/dist/promises.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.js","names":["handle: number","completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>","invocationIdPromise: Promise<InvocationId>","combinatorVariant: CombinatorVariant","childs: Array<InternalRestatePromise<any>>","castedPromises: InternalRestatePromise<any>[]","foundContext: ContextImpl | undefined","inner: InternalRestatePromise<T>","promiseFactory: () => Promise<T>","settled: boolean","coreVm: vm.WasmVM","outputPump: OutputPump","runClosuresTracker: RunClosuresTracker","externalProgressChannel: ExternalProgressChannel","errorCallback: (e: any) => void"],"sources":["../src/promises.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2025 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type {\n RestatePromise,\n InvocationId,\n InvocationPromise,\n} from \"./context.js\";\nimport type * as vm from \"./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js\";\nimport {\n CancelledError,\n RestateError,\n TerminalError,\n TimeoutError,\n} from \"./types/errors.js\";\nimport type { ContextImpl, RunClosuresTracker } from \"./context_impl.js\";\nimport { setImmediate } from \"node:timers/promises\";\nimport type { OutputPump } from \"./io.js\";\nimport type { ExternalProgressChannel } from \"./utils/external_progress_channel.js\";\nimport type { Duration } from \"@restatedev/restate-sdk-core\";\n\n// A promise that is never completed\nexport function pendingPromise<T>(): Promise<T> {\n return new Promise<T>(() => {});\n}\n\n// ------ Restate promises ------\n// These promises are \"proxy promises\" that will be handed over to the user,\n// and moved forward by the PromiseExecutor below when the user awaits on them.\n\n/**\n * Returns `true` if the given value is a {@link RestatePromise}.\n *\n * Use this for runtime type detection when you need to distinguish Restate promises\n * from regular promises, e.g. for overload resolution.\n */\nexport function isRestatePromise<T>(p: Promise<T>): p is RestatePromise<T> {\n return p instanceof InternalRestatePromise;\n}\n\nenum PromiseState {\n COMPLETED,\n NOT_COMPLETED,\n}\n\nexport abstract class InternalRestatePromise<T> implements RestatePromise<T> {\n abstract then<TResult1, TResult2>(\n onfulfilled:\n | ((value: T) => PromiseLike<TResult1> | TResult1)\n | undefined\n | null,\n onrejected:\n | ((reason: any) => PromiseLike<TResult2> | TResult2)\n | undefined\n | null\n ): Promise<TResult1 | TResult2>;\n abstract catch<TResult>(\n onrejected:\n | ((reason: any) => PromiseLike<TResult> | TResult)\n | undefined\n | null\n ): Promise<T | TResult>;\n abstract finally(onfinally: (() => void) | undefined | null): Promise<T>;\n\n abstract map<U>(\n mapper: (value?: T, failure?: TerminalError) => U\n ): RestatePromise<U>;\n abstract orTimeout(millis: Duration | number): RestatePromise<T>;\n\n abstract tryCancel(): void;\n abstract tryComplete(): Promise<void>;\n abstract unresolvedFuture(): vm.WasmUnresolvedFuture | null;\n abstract publicPromise(): Promise<T>;\n\n abstract readonly [Symbol.toStringTag]: string;\n}\n\nexport type AsyncResultValue =\n | \"Empty\"\n | { Success: Uint8Array }\n | { Failure: vm.WasmFailure }\n | { StateKeys: string[] }\n | { InvocationId: string };\n\nconst RESTATE_CTX_SYMBOL = Symbol(\"restateContext\");\n\nfunction extractContext(n: any): ContextImpl | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return n[RESTATE_CTX_SYMBOL] as ContextImpl | undefined;\n}\n\nabstract class BaseRestatePromise<T> extends InternalRestatePromise<T> {\n [RESTATE_CTX_SYMBOL]: ContextImpl;\n private pollingPromise?: Promise<any>;\n private cancelPromise: PromiseWithResolvers<any> = Promise.withResolvers();\n\n protected constructor(ctx: ContextImpl) {\n super();\n this[RESTATE_CTX_SYMBOL] = ctx;\n }\n\n // --- Promise methods\n\n then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(\n onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null\n ): Promise<T | TResult> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().catch(onrejected);\n }\n\n finally(onfinally?: (() => void) | null): Promise<T> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().finally(onfinally);\n }\n\n private publicPromiseOrCancelPromise(): Promise<T> {\n return Promise.race([\n this.cancelPromise.promise as Promise<T>,\n this.publicPromise(),\n ]);\n }\n\n // --- RestatePromise methods\n\n orTimeout(duration: number | Duration): RestatePromise<T> {\n return new CombinatorRestatePromise(\n this[RESTATE_CTX_SYMBOL],\n \"Unknown\",\n ([thisPromise, sleepPromise]: Promise<any>[]) => {\n return new Promise((resolve, reject) => {\n thisPromise!.then(resolve, reject);\n sleepPromise!.then(() => {\n reject(new TimeoutError());\n }, reject);\n });\n },\n [\n this,\n this[RESTATE_CTX_SYMBOL].sleep(duration) as InternalRestatePromise<any>,\n ]\n ) as RestatePromise<T>;\n }\n\n map<U>(mapper: (value?: T, failure?: TerminalError) => U): RestatePromise<U> {\n return new MappedRestatePromise(this[RESTATE_CTX_SYMBOL], this, mapper);\n }\n\n tryCancel() {\n this.cancelPromise.reject(new CancelledError());\n }\n\n abstract override tryComplete(): Promise<void>;\n\n abstract override unresolvedFuture(): vm.WasmUnresolvedFuture | null;\n\n abstract override publicPromise(): Promise<T>;\n\n abstract override [Symbol.toStringTag]: string;\n}\n\nexport class SingleRestatePromise<T> extends BaseRestatePromise<T> {\n private state: PromiseState = PromiseState.NOT_COMPLETED;\n private completablePromise: PromiseWithResolvers<T> = Promise.withResolvers();\n\n constructor(\n ctx: ContextImpl,\n readonly handle: number,\n private readonly completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>\n ) {\n super(ctx);\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n return this.state === PromiseState.COMPLETED\n ? null\n : { Single: this.handle };\n }\n\n async tryComplete(): Promise<void> {\n if (this.state === PromiseState.COMPLETED) {\n return;\n }\n const notification = this[RESTATE_CTX_SYMBOL].coreVm.take_notification(\n this.handle\n );\n if (notification === \"NotReady\") {\n return;\n }\n this.state = PromiseState.COMPLETED;\n await this.completer(notification, this.completablePromise);\n }\n\n publicPromise(): Promise<T> {\n return this.completablePromise.promise;\n }\n\n isCompleted(): boolean {\n return this.state === PromiseState.COMPLETED;\n }\n\n readonly [Symbol.toStringTag] = \"RestateSinglePromise\";\n}\n\nexport class InvocationRestatePromise<T>\n extends SingleRestatePromise<T>\n implements InvocationPromise<T>\n{\n constructor(\n ctx: ContextImpl,\n handle: number,\n completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>,\n private readonly invocationIdPromise: Promise<InvocationId>\n ) {\n super(ctx, handle, completer);\n }\n\n get invocationId(): Promise<InvocationId> {\n return this.invocationIdPromise;\n }\n}\n\nexport type CombinatorVariant =\n | \"Unknown\"\n | \"FirstCompleted\" // race\n | \"AllCompleted\" // allSettled\n | \"FirstSucceededOrAllFailed\" // any\n | \"AllSucceededOrFirstFailed\"; // all\n\nexport class CombinatorRestatePromise extends BaseRestatePromise<any> {\n private state: PromiseState = PromiseState.NOT_COMPLETED;\n private readonly combinatorPromise: Promise<any>;\n\n constructor(\n ctx: ContextImpl,\n private readonly combinatorVariant: CombinatorVariant,\n combinatorConstructor: (promises: Promise<any>[]) => Promise<any>,\n readonly childs: Array<InternalRestatePromise<any>>\n ) {\n super(ctx);\n this.combinatorPromise = combinatorConstructor(\n childs.map((p) => p.publicPromise())\n ).finally(() => {\n this.state = PromiseState.COMPLETED;\n });\n }\n\n // Used by static methods of RestatePromise\n public static fromPromises<T extends readonly RestatePromise<unknown>[]>(\n combinatorVariant: CombinatorVariant,\n combinatorConstructor: (promises: Promise<any>[]) => Promise<any>,\n promises: T\n ): RestatePromise<unknown> {\n const castedPromises: InternalRestatePromise<any>[] = [];\n let foundContext: ContextImpl | undefined = undefined;\n\n for (const [idx, promise] of promises.entries()) {\n if (!isRestatePromise(promise)) {\n throw new Error(\n `Promise index ${idx} used inside the combinator is not an instance of RestatePromise. This is not supported.`\n );\n } else if (foundContext === undefined) {\n foundContext = extractContext(promise);\n } else {\n const thisContext = extractContext(promise);\n if (thisContext !== undefined && thisContext !== foundContext) {\n throw new Error(\n \"You're mixing up RestatePromises from different RestateContext. This is not supported.\"\n );\n }\n }\n castedPromises.push(promise as InternalRestatePromise<any>);\n }\n\n if (foundContext === undefined) {\n // The only situation where this can happen is when the combined promise contains only ConstRestatePromise as children.\n // In this case, just return back a nice and clean ConstRestatePromise.\n // There is a specific workaround for the funky interface of Promise.race, inside the RestatePromise.race factory method.\n return ConstRestatePromise.fromPromise(\n combinatorConstructor(castedPromises),\n true\n );\n }\n\n return new CombinatorRestatePromise(\n foundContext,\n combinatorVariant,\n combinatorConstructor,\n castedPromises\n );\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n if (this.state === PromiseState.COMPLETED) return null;\n const children = this.childs\n .map((p) => p.unresolvedFuture())\n .filter((f): f is vm.WasmUnresolvedFuture => f !== null);\n if (children.length === 0) return null;\n return { [this.combinatorVariant]: children } as vm.WasmUnresolvedFuture;\n }\n\n async tryComplete(): Promise<void> {\n await Promise.allSettled(this.childs.map((c) => c.tryComplete()));\n }\n\n publicPromise(): Promise<unknown> {\n return this.combinatorPromise;\n }\n\n readonly [Symbol.toStringTag] = \"RestateCombinatorPromise\";\n}\n\nexport class MappedRestatePromise<T, U> extends BaseRestatePromise<U> {\n private publicPromiseMapper: (\n value?: T,\n failure?: TerminalError\n ) => Promise<U>;\n // Memoized so the mapper fires at most once regardless of how many times\n // the promise is awaited / consumed via then/catch/finally/publicPromise.\n private _mappedPromise?: Promise<U>;\n\n constructor(\n ctx: ContextImpl,\n readonly inner: InternalRestatePromise<T>,\n mapper: (value?: T, failure?: TerminalError) => U\n ) {\n super(ctx);\n this.publicPromiseMapper = (value?: T, failure?: TerminalError) => {\n try {\n return Promise.resolve(mapper(value, failure));\n } catch (e) {\n if (e instanceof TerminalError) {\n return Promise.reject(e);\n } else {\n ctx.abortAttempt(e);\n return pendingPromise();\n }\n }\n };\n }\n\n async tryComplete(): Promise<void> {\n await this.inner.tryComplete();\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n const inner = this.inner.unresolvedFuture();\n return inner === null ? null : { Unknown: [inner] };\n }\n\n publicPromise(): Promise<U> {\n return (this._mappedPromise ??= this.buildMappedPromise());\n }\n\n private buildMappedPromise(): Promise<U> {\n const promiseMapper = this.publicPromiseMapper;\n return this.inner.publicPromise().then(\n (t) => promiseMapper(t, undefined),\n (error) => {\n if (error instanceof RestateError) {\n return promiseMapper(undefined, error);\n } else {\n // Something else, just re-throw it\n throw error;\n }\n }\n );\n }\n\n readonly [Symbol.toStringTag] = \"RestateMappedPromise\";\n}\n\nexport class ConstRestatePromise<T> extends InternalRestatePromise<T> {\n private _constPromise?: Promise<T>;\n\n private constructor(\n // Factory for the underlying promise. Called at most once, memoized in\n // `_constPromise`.\n //\n // This way `map` is lazy, making it deterministically invoked on await points.\n private readonly promiseFactory: () => Promise<T>,\n private readonly settled: boolean\n ) {\n super();\n }\n\n private get constPromise(): Promise<T> {\n return (this._constPromise ??= this.promiseFactory());\n }\n\n static resolve<T>(value: T): ConstRestatePromise<Awaited<T>> {\n return new ConstRestatePromise(() => Promise.resolve(value), true);\n }\n\n static reject<T = never>(reason: TerminalError): ConstRestatePromise<T> {\n return new ConstRestatePromise<T>(() => Promise.reject(reason), true);\n }\n\n static pending<T>(): ConstRestatePromise<T> {\n return new ConstRestatePromise<T>(() => pendingPromise<T>(), false);\n }\n\n static fromPromise<T>(\n promise: Promise<T>,\n settled: boolean\n ): ConstRestatePromise<T> {\n return new ConstRestatePromise(() => promise, settled);\n }\n\n // --- Promise methods\n\n then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n return this.constPromise.then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(\n onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null\n ): Promise<T | TResult> {\n return this.constPromise.catch(onrejected);\n }\n\n finally(onfinally?: (() => void) | null): Promise<T> {\n return this.constPromise.finally(onfinally);\n }\n\n // --- RestatePromise methods\n\n orTimeout(): RestatePromise<T> {\n if (this.settled) return this;\n return ConstRestatePromise.reject(new TimeoutError());\n }\n\n map<U>(mapper: (value?: T, failure?: TerminalError) => U): RestatePromise<U> {\n if (!this.settled) return this as unknown as RestatePromise<U>;\n const selfConstPromise = this.constPromise;\n return new ConstRestatePromise<U>(\n () =>\n selfConstPromise.then(\n (value) => mapper(value, undefined),\n (reason) => mapper(undefined, reason as TerminalError)\n ),\n this.settled\n );\n }\n\n tryCancel() {}\n\n publicPromise(): Promise<T> {\n return this.constPromise;\n }\n\n tryComplete(): Promise<void> {\n return Promise.resolve();\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n return null;\n }\n\n readonly [Symbol.toStringTag] = \"ConstRestatePromise\";\n}\n\n/**\n * Promises executor, gluing VM with I/O and Promises given to user space.\n */\nexport class PromisesExecutor {\n constructor(\n private readonly coreVm: vm.WasmVM,\n private readonly outputPump: OutputPump,\n private readonly runClosuresTracker: RunClosuresTracker,\n private readonly externalProgressChannel: ExternalProgressChannel,\n private readonly errorCallback: (e: any) => void\n ) {}\n\n async doProgress(restatePromise: InternalRestatePromise<unknown>) {\n // Only the first time try process output\n await this.outputPump.awaitNextProgress();\n await this.doProgressInner(restatePromise);\n }\n\n private async doProgressInner(\n restatePromise: InternalRestatePromise<unknown>\n ) {\n // Try complete the promise\n try {\n await restatePromise.tryComplete();\n } catch (e) {\n // This can happen if either take_notification throws an exception or completer throws an exception.\n // This could either happen for a deserialization issue, or for an SDK bug, but we cover them here.\n this.errorCallback(e);\n return Promise.resolve();\n }\n\n // tl;dr don't touch this, or you can break combineable promises,\n // slinkydeveloper won't be happy about it\n //\n // The reason for this setTimeout is that we need to enqueue the polling after\n // we eventually resolve some promises. This is especially crucial for RestateCombinatorPromise\n // as it flips the completed state using .finally() on the combinator.\n return setImmediate().then(async () => {\n try {\n // Invoke do progress on the vm\n const unresolvedFuture = restatePromise.unresolvedFuture();\n if (unresolvedFuture === null) {\n // Completed, we're good!\n return;\n }\n const doProgressResult = this.coreVm.do_progress(unresolvedFuture);\n\n if (doProgressResult === \"AnyCompleted\") {\n // Next recursion will cause the promise to do some progress\n } else if (doProgressResult === \"WaitExternalProgress\") {\n // The shared-core now can't make progress without \"external progress\".\n //\n // There are really 3 situations here:\n // * Input is still open, and a run is being executed.\n // Both reading from input or proposing a run completion causes the invocation to make progress.\n // * Input is still open, there is no run being executed.\n // Only reading from input causes the invocation to make progress.\n // * Input is closed, a run is being executed.\n // Only proposing a run completion causes the invocation to make progress.\n\n // In this scenario, we might need to write some stuff out which might be in the shared-core buffer.\n await this.outputPump.awaitNextProgress();\n\n // Await next external progress\n await this.externalProgressChannel.awaitNext();\n } else if (doProgressResult === \"CancelSignalReceived\") {\n restatePromise.tryCancel();\n return;\n } else {\n // We need to execute a run closure\n this.runClosuresTracker.executeRun(doProgressResult.ExecuteRun);\n // Let the run context switch, then come back to this flow.\n await setImmediate();\n }\n\n // Recursion\n await this.doProgressInner(restatePromise);\n } catch (e) {\n // Not good, this is a retryable error.\n this.errorCallback(e);\n }\n });\n }\n}\n"],"mappings":";;;;AAgCA,SAAgB,iBAAgC;AAC9C,QAAO,IAAI,cAAiB,GAAG;;;;;;;;AAajC,SAAgB,iBAAoB,GAAuC;AACzE,QAAO,aAAa;;AAGtB,IAAK,wDAAL;AACE;AACA;;EAFG;AAKL,IAAsB,yBAAtB,MAA6E;AAuC7E,MAAM,qBAAqB,OAAO,iBAAiB;AAEnD,SAAS,eAAe,GAAiC;AAEvD,QAAO,EAAE;;AAGX,IAAe,qBAAf,cAA6C,uBAA0B;CACrE,CAAC;CACD,AAAQ;CACR,AAAQ,gBAA2C,QAAQ,eAAe;CAE1E,AAAU,YAAY,KAAkB;AACtC,SAAO;AACP,OAAK,sBAAsB;;CAK7B,KACE,aACA,YAC8B;AAC9B,OAAK,iBACH,KAAK,kBACL,KAAK,oBAAoB,iBACtB,WAAW,KAAK,CAChB,YAAY,GAAG;AACpB,SAAO,KAAK,8BAA8B,CAAC,KAAK,aAAa,WAAW;;CAG1E,MACE,YACsB;AACtB,OAAK,iBACH,KAAK,kBACL,KAAK,oBAAoB,iBACtB,WAAW,KAAK,CAChB,YAAY,GAAG;AACpB,SAAO,KAAK,8BAA8B,CAAC,MAAM,WAAW;;CAG9D,QAAQ,WAA6C;AACnD,OAAK,iBACH,KAAK,kBACL,KAAK,oBAAoB,iBACtB,WAAW,KAAK,CAChB,YAAY,GAAG;AACpB,SAAO,KAAK,8BAA8B,CAAC,QAAQ,UAAU;;CAG/D,AAAQ,+BAA2C;AACjD,SAAO,QAAQ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rC,qBAAqB,wBAAwB;AACtD,oBAAe,WAAW;AAC1B;WACK;AAEL,UAAK,mBAAmB,WAAW,iBAAiB,WAAW;AAE/D,WAAM,cAAc;;AAItB,UAAM,KAAK,gBAAgB,eAAe;YACnC,GAAG;AAEV,SAAK,cAAc,EAAE;;IAEvB"}
|
|
1
|
+
{"version":3,"file":"promises.js","names":["handle: number","completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>","invocationIdPromise: Promise<InvocationId>","combinatorVariant: CombinatorVariant","childs: Array<InternalRestatePromise<any>>","castedPromises: InternalRestatePromise<any>[]","foundContext: ContextImpl | undefined","inner: InternalRestatePromise<T>","promiseFactory: () => Promise<T>","settled: boolean","coreVm: vm.WasmVM","outputPump: OutputPump","runClosuresTracker: RunClosuresTracker","ephemeralRequestTracker: EphemeralRequestTracker","externalProgressChannel: ExternalProgressChannel","errorCallback: (e: any) => void"],"sources":["../src/promises.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2025 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type {\n RestatePromise,\n InvocationId,\n InvocationPromise,\n} from \"./context.js\";\nimport type * as vm from \"./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js\";\nimport {\n CancelledError,\n RestateError,\n TerminalError,\n TimeoutError,\n} from \"./types/errors.js\";\nimport type {\n ContextImpl,\n RunClosuresTracker,\n EphemeralRequestTracker,\n} from \"./context_impl.js\";\nimport { setImmediate } from \"node:timers/promises\";\nimport type { OutputPump } from \"./io.js\";\nimport type { ExternalProgressChannel } from \"./utils/external_progress_channel.js\";\nimport type { Duration } from \"@restatedev/restate-sdk-core\";\n\n// A promise that is never completed\nexport function pendingPromise<T>(): Promise<T> {\n return new Promise<T>(() => {});\n}\n\n// ------ Restate promises ------\n// These promises are \"proxy promises\" that will be handed over to the user,\n// and moved forward by the PromiseExecutor below when the user awaits on them.\n\n/**\n * Returns `true` if the given value is a {@link RestatePromise}.\n *\n * Use this for runtime type detection when you need to distinguish Restate promises\n * from regular promises, e.g. for overload resolution.\n */\nexport function isRestatePromise<T>(p: Promise<T>): p is RestatePromise<T> {\n return p instanceof InternalRestatePromise;\n}\n\nenum PromiseState {\n COMPLETED,\n NOT_COMPLETED,\n}\n\nexport abstract class InternalRestatePromise<T> implements RestatePromise<T> {\n abstract then<TResult1, TResult2>(\n onfulfilled:\n | ((value: T) => PromiseLike<TResult1> | TResult1)\n | undefined\n | null,\n onrejected:\n | ((reason: any) => PromiseLike<TResult2> | TResult2)\n | undefined\n | null\n ): Promise<TResult1 | TResult2>;\n abstract catch<TResult>(\n onrejected:\n | ((reason: any) => PromiseLike<TResult> | TResult)\n | undefined\n | null\n ): Promise<T | TResult>;\n abstract finally(onfinally: (() => void) | undefined | null): Promise<T>;\n\n abstract map<U>(\n mapper: (value?: T, failure?: TerminalError) => U\n ): RestatePromise<U>;\n abstract orTimeout(millis: Duration | number): RestatePromise<T>;\n\n abstract tryCancel(): void;\n abstract tryComplete(): Promise<void>;\n abstract unresolvedFuture(): vm.WasmUnresolvedFuture | null;\n abstract publicPromise(): Promise<T>;\n\n abstract readonly [Symbol.toStringTag]: string;\n}\n\nexport type AsyncResultValue =\n | \"Empty\"\n | { Success: Uint8Array }\n | { Failure: vm.WasmFailure }\n | { StateKeys: string[] }\n | { InvocationId: string };\n\nconst RESTATE_CTX_SYMBOL = Symbol(\"restateContext\");\n\nfunction extractContext(n: any): ContextImpl | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return n[RESTATE_CTX_SYMBOL] as ContextImpl | undefined;\n}\n\nabstract class BaseRestatePromise<T> extends InternalRestatePromise<T> {\n [RESTATE_CTX_SYMBOL]: ContextImpl;\n private pollingPromise?: Promise<any>;\n private cancelPromise: PromiseWithResolvers<any> = Promise.withResolvers();\n\n protected constructor(ctx: ContextImpl) {\n super();\n this[RESTATE_CTX_SYMBOL] = ctx;\n }\n\n // --- Promise methods\n\n then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(\n onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null\n ): Promise<T | TResult> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().catch(onrejected);\n }\n\n finally(onfinally?: (() => void) | null): Promise<T> {\n this.pollingPromise =\n this.pollingPromise ||\n this[RESTATE_CTX_SYMBOL].promisesExecutor\n .doProgress(this)\n .catch(() => {});\n return this.publicPromiseOrCancelPromise().finally(onfinally);\n }\n\n private publicPromiseOrCancelPromise(): Promise<T> {\n return Promise.race([\n this.cancelPromise.promise as Promise<T>,\n this.publicPromise(),\n ]);\n }\n\n // --- RestatePromise methods\n\n orTimeout(duration: number | Duration): RestatePromise<T> {\n return new CombinatorRestatePromise(\n this[RESTATE_CTX_SYMBOL],\n \"Unknown\",\n ([thisPromise, sleepPromise]: Promise<any>[]) => {\n return new Promise((resolve, reject) => {\n thisPromise!.then(resolve, reject);\n sleepPromise!.then(() => {\n reject(new TimeoutError());\n }, reject);\n });\n },\n [\n this,\n this[RESTATE_CTX_SYMBOL].sleep(duration) as InternalRestatePromise<any>,\n ]\n ) as RestatePromise<T>;\n }\n\n map<U>(mapper: (value?: T, failure?: TerminalError) => U): RestatePromise<U> {\n return new MappedRestatePromise(this[RESTATE_CTX_SYMBOL], this, mapper);\n }\n\n tryCancel() {\n this.cancelPromise.reject(new CancelledError());\n }\n\n abstract override tryComplete(): Promise<void>;\n\n abstract override unresolvedFuture(): vm.WasmUnresolvedFuture | null;\n\n abstract override publicPromise(): Promise<T>;\n\n abstract override [Symbol.toStringTag]: string;\n}\n\nexport class SingleRestatePromise<T> extends BaseRestatePromise<T> {\n private state: PromiseState = PromiseState.NOT_COMPLETED;\n private completablePromise: PromiseWithResolvers<T> = Promise.withResolvers();\n\n constructor(\n ctx: ContextImpl,\n readonly handle: number,\n private readonly completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>\n ) {\n super(ctx);\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n return this.state === PromiseState.COMPLETED\n ? null\n : { Single: this.handle };\n }\n\n async tryComplete(): Promise<void> {\n if (this.state === PromiseState.COMPLETED) {\n return;\n }\n const notification = this[RESTATE_CTX_SYMBOL].coreVm.take_notification(\n this.handle\n );\n if (notification === \"NotReady\") {\n return;\n }\n this.state = PromiseState.COMPLETED;\n await this.completer(notification, this.completablePromise);\n }\n\n publicPromise(): Promise<T> {\n return this.completablePromise.promise;\n }\n\n isCompleted(): boolean {\n return this.state === PromiseState.COMPLETED;\n }\n\n readonly [Symbol.toStringTag] = \"RestateSinglePromise\";\n}\n\nexport class InvocationRestatePromise<T>\n extends SingleRestatePromise<T>\n implements InvocationPromise<T>\n{\n constructor(\n ctx: ContextImpl,\n handle: number,\n completer: (\n value: AsyncResultValue,\n prom: PromiseWithResolvers<T>\n ) => Promise<void>,\n private readonly invocationIdPromise: Promise<InvocationId>\n ) {\n super(ctx, handle, completer);\n }\n\n get invocationId(): Promise<InvocationId> {\n return this.invocationIdPromise;\n }\n}\n\nexport type CombinatorVariant =\n | \"Unknown\"\n | \"FirstCompleted\" // race\n | \"AllCompleted\" // allSettled\n | \"FirstSucceededOrAllFailed\" // any\n | \"AllSucceededOrFirstFailed\"; // all\n\nexport class CombinatorRestatePromise extends BaseRestatePromise<any> {\n private state: PromiseState = PromiseState.NOT_COMPLETED;\n private readonly combinatorPromise: Promise<any>;\n\n constructor(\n ctx: ContextImpl,\n private readonly combinatorVariant: CombinatorVariant,\n combinatorConstructor: (promises: Promise<any>[]) => Promise<any>,\n readonly childs: Array<InternalRestatePromise<any>>\n ) {\n super(ctx);\n this.combinatorPromise = combinatorConstructor(\n childs.map((p) => p.publicPromise())\n ).finally(() => {\n this.state = PromiseState.COMPLETED;\n });\n }\n\n // Used by static methods of RestatePromise\n public static fromPromises<T extends readonly RestatePromise<unknown>[]>(\n combinatorVariant: CombinatorVariant,\n combinatorConstructor: (promises: Promise<any>[]) => Promise<any>,\n promises: T\n ): RestatePromise<unknown> {\n const castedPromises: InternalRestatePromise<any>[] = [];\n let foundContext: ContextImpl | undefined = undefined;\n\n for (const [idx, promise] of promises.entries()) {\n if (!isRestatePromise(promise)) {\n throw new Error(\n `Promise index ${idx} used inside the combinator is not an instance of RestatePromise. This is not supported.`\n );\n } else if (foundContext === undefined) {\n foundContext = extractContext(promise);\n } else {\n const thisContext = extractContext(promise);\n if (thisContext !== undefined && thisContext !== foundContext) {\n throw new Error(\n \"You're mixing up RestatePromises from different RestateContext. This is not supported.\"\n );\n }\n }\n castedPromises.push(promise as InternalRestatePromise<any>);\n }\n\n if (foundContext === undefined) {\n // The only situation where this can happen is when the combined promise contains only ConstRestatePromise as children.\n // In this case, just return back a nice and clean ConstRestatePromise.\n // There is a specific workaround for the funky interface of Promise.race, inside the RestatePromise.race factory method.\n return ConstRestatePromise.fromPromise(\n combinatorConstructor(castedPromises),\n true\n );\n }\n\n return new CombinatorRestatePromise(\n foundContext,\n combinatorVariant,\n combinatorConstructor,\n castedPromises\n );\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n if (this.state === PromiseState.COMPLETED) return null;\n const children = this.childs\n .map((p) => p.unresolvedFuture())\n .filter((f): f is vm.WasmUnresolvedFuture => f !== null);\n if (children.length === 0) return null;\n return { [this.combinatorVariant]: children } as vm.WasmUnresolvedFuture;\n }\n\n async tryComplete(): Promise<void> {\n await Promise.allSettled(this.childs.map((c) => c.tryComplete()));\n }\n\n publicPromise(): Promise<unknown> {\n return this.combinatorPromise;\n }\n\n readonly [Symbol.toStringTag] = \"RestateCombinatorPromise\";\n}\n\nexport class MappedRestatePromise<T, U> extends BaseRestatePromise<U> {\n private publicPromiseMapper: (\n value?: T,\n failure?: TerminalError\n ) => Promise<U>;\n // Memoized so the mapper fires at most once regardless of how many times\n // the promise is awaited / consumed via then/catch/finally/publicPromise.\n private _mappedPromise?: Promise<U>;\n\n constructor(\n ctx: ContextImpl,\n readonly inner: InternalRestatePromise<T>,\n mapper: (value?: T, failure?: TerminalError) => U\n ) {\n super(ctx);\n this.publicPromiseMapper = (value?: T, failure?: TerminalError) => {\n try {\n return Promise.resolve(mapper(value, failure));\n } catch (e) {\n if (e instanceof TerminalError) {\n return Promise.reject(e);\n } else {\n ctx.abortAttempt(e);\n return pendingPromise();\n }\n }\n };\n }\n\n async tryComplete(): Promise<void> {\n await this.inner.tryComplete();\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n const inner = this.inner.unresolvedFuture();\n return inner === null ? null : { Unknown: [inner] };\n }\n\n publicPromise(): Promise<U> {\n return (this._mappedPromise ??= this.buildMappedPromise());\n }\n\n private buildMappedPromise(): Promise<U> {\n const promiseMapper = this.publicPromiseMapper;\n return this.inner.publicPromise().then(\n (t) => promiseMapper(t, undefined),\n (error) => {\n if (error instanceof RestateError) {\n return promiseMapper(undefined, error);\n } else {\n // Something else, just re-throw it\n throw error;\n }\n }\n );\n }\n\n readonly [Symbol.toStringTag] = \"RestateMappedPromise\";\n}\n\nexport class ConstRestatePromise<T> extends InternalRestatePromise<T> {\n private _constPromise?: Promise<T>;\n\n private constructor(\n // Factory for the underlying promise. Called at most once, memoized in\n // `_constPromise`.\n //\n // This way `map` is lazy, making it deterministically invoked on await points.\n private readonly promiseFactory: () => Promise<T>,\n private readonly settled: boolean\n ) {\n super();\n }\n\n private get constPromise(): Promise<T> {\n return (this._constPromise ??= this.promiseFactory());\n }\n\n static resolve<T>(value: T): ConstRestatePromise<Awaited<T>> {\n return new ConstRestatePromise(() => Promise.resolve(value), true);\n }\n\n static reject<T = never>(reason: TerminalError): ConstRestatePromise<T> {\n return new ConstRestatePromise<T>(() => Promise.reject(reason), true);\n }\n\n static pending<T>(): ConstRestatePromise<T> {\n return new ConstRestatePromise<T>(() => pendingPromise<T>(), false);\n }\n\n static fromPromise<T>(\n promise: Promise<T>,\n settled: boolean\n ): ConstRestatePromise<T> {\n return new ConstRestatePromise(() => promise, settled);\n }\n\n // --- Promise methods\n\n then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n return this.constPromise.then(onfulfilled, onrejected);\n }\n\n catch<TResult = never>(\n onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null\n ): Promise<T | TResult> {\n return this.constPromise.catch(onrejected);\n }\n\n finally(onfinally?: (() => void) | null): Promise<T> {\n return this.constPromise.finally(onfinally);\n }\n\n // --- RestatePromise methods\n\n orTimeout(): RestatePromise<T> {\n if (this.settled) return this;\n return ConstRestatePromise.reject(new TimeoutError());\n }\n\n map<U>(mapper: (value?: T, failure?: TerminalError) => U): RestatePromise<U> {\n if (!this.settled) return this as unknown as RestatePromise<U>;\n const selfConstPromise = this.constPromise;\n return new ConstRestatePromise<U>(\n () =>\n selfConstPromise.then(\n (value) => mapper(value, undefined),\n (reason) => mapper(undefined, reason as TerminalError)\n ),\n this.settled\n );\n }\n\n tryCancel() {}\n\n publicPromise(): Promise<T> {\n return this.constPromise;\n }\n\n tryComplete(): Promise<void> {\n return Promise.resolve();\n }\n\n unresolvedFuture(): vm.WasmUnresolvedFuture | null {\n return null;\n }\n\n readonly [Symbol.toStringTag] = \"ConstRestatePromise\";\n}\n\n/**\n * Promises executor, gluing VM with I/O and Promises given to user space.\n */\nexport class PromisesExecutor {\n constructor(\n private readonly coreVm: vm.WasmVM,\n private readonly outputPump: OutputPump,\n private readonly runClosuresTracker: RunClosuresTracker,\n private readonly ephemeralRequestTracker: EphemeralRequestTracker,\n private readonly externalProgressChannel: ExternalProgressChannel,\n private readonly errorCallback: (e: any) => void\n ) {}\n\n async doProgress(restatePromise: InternalRestatePromise<unknown>) {\n // Only the first time try process output\n await this.outputPump.awaitNextProgress();\n await this.doProgressInner(restatePromise);\n }\n\n private async doProgressInner(\n restatePromise: InternalRestatePromise<unknown>\n ) {\n // Try complete the promise\n try {\n await restatePromise.tryComplete();\n } catch (e) {\n // This can happen if either take_notification throws an exception or completer throws an exception.\n // This could either happen for a deserialization issue, or for an SDK bug, but we cover them here.\n this.errorCallback(e);\n return Promise.resolve();\n }\n\n // tl;dr don't touch this, or you can break combineable promises,\n // slinkydeveloper won't be happy about it\n //\n // The reason for this setTimeout is that we need to enqueue the polling after\n // we eventually resolve some promises. This is especially crucial for RestateCombinatorPromise\n // as it flips the completed state using .finally() on the combinator.\n return setImmediate().then(async () => {\n try {\n // Invoke do progress on the vm\n const unresolvedFuture = restatePromise.unresolvedFuture();\n if (unresolvedFuture === null) {\n // Completed, we're good!\n return;\n }\n const doProgressResult = this.coreVm.do_progress(unresolvedFuture);\n\n if (doProgressResult === \"AnyCompleted\") {\n // Next recursion will cause the promise to do some progress\n } else if (doProgressResult === \"WaitExternalProgress\") {\n // The shared-core now can't make progress without \"external progress\".\n //\n // There are really 3 situations here:\n // * Input is still open, and a run is being executed.\n // Both reading from input or proposing a run completion causes the invocation to make progress.\n // * Input is still open, there is no run being executed.\n // Only reading from input causes the invocation to make progress.\n // * Input is closed, a run is being executed.\n // Only proposing a run completion causes the invocation to make progress.\n\n // In this scenario, we might need to write some stuff out which might be in the shared-core buffer.\n await this.outputPump.awaitNextProgress();\n\n // Await next external progress\n await this.externalProgressChannel.awaitNext();\n } else if (doProgressResult === \"CancelSignalReceived\") {\n restatePromise.tryCancel();\n return;\n } else if (\"EphemeralNotificationReady\" in doProgressResult) {\n // The notification of an ephemeral command is ready, this takes precedence over everything else.\n // Complete the related promise, then the next recursion will continue making progress.\n const completionId = doProgressResult.EphemeralNotificationReady;\n await this.ephemeralRequestTracker.complete(\n completionId,\n this.coreVm.take_ephemeral_notification(completionId)\n );\n } else {\n // We need to execute a run closure\n this.runClosuresTracker.executeRun(doProgressResult.ExecuteRun);\n // Let the run context switch, then come back to this flow.\n await setImmediate();\n }\n\n // Recursion\n await this.doProgressInner(restatePromise);\n } catch (e) {\n // Not good, this is a retryable error.\n this.errorCallback(e);\n }\n });\n }\n}\n"],"mappings":";;;;AAoCA,SAAgB,iBAAgC;AAC9C,QAAO,IAAI,cAAiB,GAAG;;;;;;;;AAajC,SAAgB,iBAAoB,GAAuC;AACzE,QAAO,aAAa;;AAGtB,IAAK,wDAAL;AACE;AACA;;EAFG;AAKL,IAAsB,yBAAtB,MAA6E;AAuC7E,MAAM,qBAAqB,OAAO,iBAAiB;AAEnD,SAAS,eAAe,GAAiC;AAEvD,QAAO,EAAE;;AAGX,IAAe,qBAAf,cAA6C,uBAA0B;CACrE,CAAC;CACD,AAAQ;CACR,AAAQ,gBAA2C,QAAQ,eAAe;CAE1E,AAAU,YAAY,KAAkB;AACtC,SAAO;AACP,OAAK,sBAAsB;;CAK7B,KACE,aACA,YAC8B;AAC9B,OAAK,iBACH,KAAK,kBACL,KAAK,oBAAoB,iBACtB,WAAW,KAAK,CAChB,YAAY,GAAG;AACpB,SAAO,KAAK,8BAA8B,CAAC,KAAK,aAAa,WAAW;;CAG1E,MACE,YACsB;AACtB,OAAK,iBACH,KAAK,kBACL,KAAK,oBAAoB,iBACtB,WAAW,KAAK,CAChB,YAAY,GAAG;AACpB,SAAO,KAAK,8BAA8B,CAAC,MAAM,WAAW;;CAG9D,QAAQ,WAA6C;AACnD,OAAK,iBAC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EvB;IAEF,MAAM,mBAAmB,KAAK,OAAO,YAAY,iBAAiB;AAElE,QAAI,qBAAqB,gBAAgB,YAE9B,qBAAqB,wBAAwB;AAYtD,WAAM,KAAK,WAAW,mBAAmB;AAGzC,WAAM,KAAK,wBAAwB,WAAW;eACrC,qBAAqB,wBAAwB;AACtD,oBAAe,WAAW;AAC1B;eACS,gCAAgC,kBAAkB;KAG3D,MAAM,eAAe,iBAAiB;AACtC,WAAM,KAAK,wBAAwB,SACjC,cACA,KAAK,OAAO,4BAA4B,aAAa,CACtD;WACI;AAEL,UAAK,mBAAmB,WAAW,iBAAiB,WAAW;AAE/D,WAAM,cAAc;;AAItB,UAAM,KAAK,gBAAgB,eAAe;YACnC,GAAG;AAEV,SAAK,cAAc,EAAE;;IAEvB"}
|
package/dist/types/errors.cjs
CHANGED
|
@@ -105,7 +105,7 @@ var RetryableError = class RetryableError extends RestateError {
|
|
|
105
105
|
*
|
|
106
106
|
* You can wrap another error using {@link from}.
|
|
107
107
|
*/
|
|
108
|
-
var PauseError = class extends RestateError {
|
|
108
|
+
var PauseError = class PauseError extends RestateError {
|
|
109
109
|
name = "PauseError";
|
|
110
110
|
constructor(message, options) {
|
|
111
111
|
super(message, {
|
|
@@ -118,7 +118,7 @@ var PauseError = class extends RestateError {
|
|
|
118
118
|
*/
|
|
119
119
|
static from(cause) {
|
|
120
120
|
const error = ensureError(cause);
|
|
121
|
-
return new
|
|
121
|
+
return new PauseError(error.message, {
|
|
122
122
|
errorCode: error["errorCode"],
|
|
123
123
|
cause
|
|
124
124
|
});
|
package/dist/types/errors.d.cts
CHANGED
|
@@ -85,7 +85,7 @@ declare class PauseError extends RestateError {
|
|
|
85
85
|
/**
|
|
86
86
|
* Create a `PauseError` from the given cause.
|
|
87
87
|
*/
|
|
88
|
-
static from(cause: any):
|
|
88
|
+
static from(cause: any): PauseError;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Returns true if the error indicates the current attempt is ending without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/types/errors.ts"],"sourcesContent":[],"mappings":";;;;AAwHa,cA3CA,YAAA,SAAqB,KAAA,CA2Ca;EAWlC,SAAA,IAAA,EAAA,MAAe;EAQX,IAAA,EAAA,MAAA;EAaJ,WAAA,CAAA,OAAe,EAAA,MAAA,EAAA,OAuBQ,CAvBR,EAAA;IAGJ,SAAA,CAAA,EAAA,MAAA;IAIV,KAAA,CAAA,EAAA,GAAA;EAgBsB,CAAA;;;;AAgBpC;
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../../src/types/errors.ts"],"sourcesContent":[],"mappings":";;;;AAwHa,cA3CA,YAAA,SAAqB,KAAA,CA2Ca;EAWlC,SAAA,IAAA,EAAA,MAAe;EAQX,IAAA,EAAA,MAAA;EAaJ,WAAA,CAAA,OAAe,EAAA,MAAA,EAAA,OAuBQ,CAvBR,EAAA;IAGJ,SAAA,CAAA,EAAA,MAAA;IAIV,KAAA,CAAA,EAAA,GAAA;EAgBsB,CAAA;;;;AAgBpC;AAuCA;;cA1Ia,aAAA,SAAsB,YAAA;;sBAEN;;;;;;;;;;;;eAeZ;;;;;;cAWJ,YAAA,SAAqB,aAAA;;;;;;;cAWrB,cAAA,SAAuB,aAAA;;;;UAQnB,qBAAA;;;;eAIF;;;;;;;;cASF,cAAA,SAAuB,YAAA;;wBAGZ;yCAIV;;;;;;;oCAgBsB,wBAAwB;;;;;;;;cAgB/C,UAAA,SAAmB,YAAA;;;;;;;;;2BAoBL;;;;;;;;;;;iBAmBX,gBAAA"}
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ declare class PauseError extends RestateError {
|
|
|
85
85
|
/**
|
|
86
86
|
* Create a `PauseError` from the given cause.
|
|
87
87
|
*/
|
|
88
|
-
static from(cause: any):
|
|
88
|
+
static from(cause: any): PauseError;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Returns true if the error indicates the current attempt is ending without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../src/types/errors.ts"],"sourcesContent":[],"mappings":";;;;AAwHa,cA3CA,YAAA,SAAqB,KAAA,CA2Ca;EAWlC,SAAA,IAAA,EAAA,MAAe;EAQX,IAAA,EAAA,MAAA;EAaJ,WAAA,CAAA,OAAe,EAAA,MAAA,EAAA,OAuBQ,CAvBR,EAAA;IAGJ,SAAA,CAAA,EAAA,MAAA;IAIV,KAAA,CAAA,EAAA,GAAA;EAgBsB,CAAA;;;;AAgBpC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../src/types/errors.ts"],"sourcesContent":[],"mappings":";;;;AAwHa,cA3CA,YAAA,SAAqB,KAAA,CA2Ca;EAWlC,SAAA,IAAA,EAAA,MAAe;EAQX,IAAA,EAAA,MAAA;EAaJ,WAAA,CAAA,OAAe,EAAA,MAAA,EAAA,OAuBQ,CAvBR,EAAA;IAGJ,SAAA,CAAA,EAAA,MAAA;IAIV,KAAA,CAAA,EAAA,GAAA;EAgBsB,CAAA;;;;AAgBpC;AAuCA;;cA1Ia,aAAA,SAAsB,YAAA;;sBAEN;;;;;;;;;;;;eAeZ;;;;;;cAWJ,YAAA,SAAqB,aAAA;;;;;;;cAWrB,cAAA,SAAuB,aAAA;;;;UAQnB,qBAAA;;;;eAIF;;;;;;;;cASF,cAAA,SAAuB,YAAA;;wBAGZ;yCAIV;;;;;;;oCAgBsB,wBAAwB;;;;;;;;cAgB/C,UAAA,SAAmB,YAAA;;;;;;;;;2BAoBL;;;;;;;;;;;iBAmBX,gBAAA"}
|
package/dist/types/errors.js
CHANGED
|
@@ -104,7 +104,7 @@ var RetryableError = class RetryableError extends RestateError {
|
|
|
104
104
|
*
|
|
105
105
|
* You can wrap another error using {@link from}.
|
|
106
106
|
*/
|
|
107
|
-
var PauseError = class extends RestateError {
|
|
107
|
+
var PauseError = class PauseError extends RestateError {
|
|
108
108
|
name = "PauseError";
|
|
109
109
|
constructor(message, options) {
|
|
110
110
|
super(message, {
|
|
@@ -117,7 +117,7 @@ var PauseError = class extends RestateError {
|
|
|
117
117
|
*/
|
|
118
118
|
static from(cause) {
|
|
119
119
|
const error = ensureError(cause);
|
|
120
|
-
return new
|
|
120
|
+
return new PauseError(error.message, {
|
|
121
121
|
errorCode: error["errorCode"],
|
|
122
122
|
cause
|
|
123
123
|
});
|