@restatedev/restate-sdk 1.11.0 → 1.12.0
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/_virtual/rolldown_runtime.cjs +9 -0
- package/dist/common_api.cjs +2 -1
- package/dist/common_api.d.cts +6 -2
- package/dist/common_api.d.cts.map +1 -1
- package/dist/common_api.d.ts +6 -2
- package/dist/common_api.d.ts.map +1 -1
- package/dist/common_api.js +2 -1
- package/dist/common_api.js.map +1 -1
- package/dist/context.cjs +13 -9
- package/dist/context.d.cts +36 -29
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.ts +36 -29
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +13 -9
- package/dist/context.js.map +1 -1
- package/dist/context_impl.cjs +150 -91
- package/dist/context_impl.d.cts +8 -0
- package/dist/context_impl.d.ts +8 -72
- package/dist/context_impl.d.ts.map +1 -1
- package/dist/context_impl.js +151 -93
- package/dist/context_impl.js.map +1 -1
- package/dist/endpoint/components.cjs +35 -20
- package/dist/endpoint/components.d.cts +5 -0
- package/dist/endpoint/components.d.ts +5 -97
- package/dist/endpoint/components.d.ts.map +1 -1
- package/dist/endpoint/components.js +35 -20
- package/dist/endpoint/components.js.map +1 -1
- package/dist/endpoint/endpoint.cjs +2 -2
- package/dist/endpoint/endpoint.d.cts +5 -0
- package/dist/endpoint/endpoint.d.ts +5 -39
- package/dist/endpoint/endpoint.js +2 -2
- package/dist/endpoint/endpoint.js.map +1 -1
- package/dist/endpoint/handlers/generic.cjs +115 -39
- package/dist/endpoint/handlers/generic.d.ts.map +1 -1
- package/dist/endpoint/handlers/generic.js +115 -39
- package/dist/endpoint/handlers/generic.js.map +1 -1
- package/dist/endpoint/handlers/types.d.cts +1 -0
- package/dist/endpoint/handlers/types.d.ts +1 -41
- package/dist/endpoint/handlers/utils.cjs +1 -1
- package/dist/endpoint/handlers/utils.js +1 -1
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.cjs +43 -3
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +19 -1
- 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 +43 -3
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
- package/dist/endpoint/node_endpoint.cjs +28 -12
- package/dist/endpoint/node_endpoint.d.ts +14 -2
- package/dist/endpoint/node_endpoint.d.ts.map +1 -1
- package/dist/endpoint/node_endpoint.js +27 -11
- package/dist/endpoint/node_endpoint.js.map +1 -1
- package/dist/endpoint/types.d.cts +1 -1
- package/dist/endpoint/types.d.ts +1 -1
- package/dist/endpoint.d.cts +87 -5
- package/dist/endpoint.d.cts.map +1 -1
- package/dist/endpoint.d.ts +87 -5
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/error_sanitization.cjs +26 -0
- package/dist/error_sanitization.d.ts +13 -0
- package/dist/error_sanitization.d.ts.map +1 -0
- package/dist/error_sanitization.js +26 -0
- package/dist/error_sanitization.js.map +1 -0
- package/dist/fetch.cjs +3 -1
- package/dist/fetch.d.cts +5 -3
- package/dist/fetch.d.cts.map +1 -1
- package/dist/fetch.d.ts +5 -3
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +3 -2
- package/dist/fetch.js.map +1 -1
- package/dist/hooks.d.cts +87 -0
- package/dist/hooks.d.cts.map +1 -0
- package/dist/hooks.d.ts +87 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +3 -2
- package/dist/internal.cjs +3 -1
- package/dist/internal.d.cts +186 -2
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +186 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -1
- package/dist/internal.js.map +1 -1
- package/dist/io.d.cts +1 -0
- package/dist/io.d.ts +1 -24
- package/dist/lambda.cjs +3 -1
- package/dist/lambda.d.cts +5 -3
- package/dist/lambda.d.cts.map +1 -1
- package/dist/lambda.d.ts +5 -3
- package/dist/lambda.d.ts.map +1 -1
- package/dist/lambda.js +3 -2
- package/dist/lambda.js.map +1 -1
- package/dist/logging/logger.d.cts +1 -0
- package/dist/logging/logger.d.ts +1 -10
- package/dist/node.cjs +23 -6
- package/dist/node.d.cts +46 -8
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.ts +46 -8
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +23 -7
- package/dist/node.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 +90 -53
- package/dist/promises.d.cts +18 -0
- package/dist/promises.d.cts.map +1 -0
- package/dist/promises.d.ts +15 -108
- package/dist/promises.d.ts.map +1 -1
- package/dist/promises.js +85 -48
- package/dist/promises.js.map +1 -1
- package/dist/types/errors.cjs +13 -0
- package/dist/types/errors.d.cts +11 -5
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +11 -5
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +13 -1
- package/dist/types/errors.js.map +1 -1
- package/dist/types/rpc.cjs +7 -19
- package/dist/types/rpc.d.cts +174 -0
- package/dist/types/rpc.d.cts.map +1 -1
- package/dist/types/rpc.d.ts +174 -0
- package/dist/types/rpc.d.ts.map +1 -1
- package/dist/types/rpc.js +7 -19
- package/dist/types/rpc.js.map +1 -1
- package/package.json +2 -2
package/dist/fetch.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.cjs";
|
|
2
|
+
import { Hooks, HooksProvider, Interceptor } from "./hooks.cjs";
|
|
2
3
|
import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.cjs";
|
|
3
|
-
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions,
|
|
4
|
+
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.cjs";
|
|
5
|
+
import { internal_d_exports } from "./internal.cjs";
|
|
4
6
|
import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.cjs";
|
|
5
7
|
import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.cjs";
|
|
8
|
+
import { isRestatePromise } from "./promises.cjs";
|
|
6
9
|
import { EndpointOptions } from "./endpoint/types.cjs";
|
|
7
|
-
import { internal_d_exports } from "./internal.cjs";
|
|
8
10
|
import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.cjs";
|
|
9
11
|
import { FetchEndpoint } from "./endpoint/fetch_endpoint.cjs";
|
|
10
12
|
|
|
@@ -49,5 +51,5 @@ interface FetchEndpointOptions extends EndpointOptions {
|
|
|
49
51
|
*/
|
|
50
52
|
declare function createEndpointHandler(options: FetchEndpointOptions): (request: Request, ...extraArgs: unknown[]) => Promise<Response>;
|
|
51
53
|
//#endregion
|
|
52
|
-
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient,
|
|
54
|
+
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, service, workflow };
|
|
53
55
|
//# sourceMappingURL=fetch.d.cts.map
|
package/dist/fetch.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.cts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.cts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;;;AAJ9C;AAIA;AAiCA;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
|
package/dist/fetch.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.js";
|
|
2
|
+
import { Hooks, HooksProvider, Interceptor } from "./hooks.js";
|
|
2
3
|
import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
|
|
3
|
-
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions,
|
|
4
|
+
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.js";
|
|
5
|
+
import { internal_d_exports } from "./internal.js";
|
|
4
6
|
import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.js";
|
|
5
7
|
import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.js";
|
|
8
|
+
import { isRestatePromise } from "./promises.js";
|
|
6
9
|
import { EndpointOptions } from "./endpoint/types.js";
|
|
7
|
-
import { internal_d_exports } from "./internal.js";
|
|
8
10
|
import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
|
|
9
11
|
import { FetchEndpoint } from "./endpoint/fetch_endpoint.js";
|
|
10
12
|
|
|
@@ -49,5 +51,5 @@ interface FetchEndpointOptions extends EndpointOptions {
|
|
|
49
51
|
*/
|
|
50
52
|
declare function createEndpointHandler(options: FetchEndpointOptions): (request: Request, ...extraArgs: unknown[]) => Promise<Response>;
|
|
51
53
|
//#endregion
|
|
52
|
-
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient,
|
|
54
|
+
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, service, workflow };
|
|
53
55
|
//# sourceMappingURL=fetch.d.ts.map
|
package/dist/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;;;AAJ9C;AAIA;AAiCA;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
|
package/dist/fetch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, TerminalError, TimeoutError } from "./types/errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isRestatePromise } from "./promises.js";
|
|
3
3
|
import { InvocationIdParser, RestatePromise } from "./context.js";
|
|
4
|
+
import { Opts, SendOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
|
|
4
5
|
import { internal_exports } from "./internal.js";
|
|
5
6
|
import { CombineablePromise, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
|
|
6
7
|
import { FetchEndpointImpl } from "./endpoint/fetch_endpoint.js";
|
|
@@ -41,5 +42,5 @@ function createEndpointHandler(options) {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
//#endregion
|
|
44
|
-
export { CancelledError, CombineablePromise, InvocationIdParser, Opts, RestateError, RestatePromise, RetryableError, SendOpts, TerminalError, TimeoutError, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_exports as internal, object, rpc, serde, service, workflow };
|
|
45
|
+
export { CancelledError, CombineablePromise, InvocationIdParser, Opts, RestateError, RestatePromise, RetryableError, SendOpts, TerminalError, TimeoutError, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_exports as internal, isRestatePromise, object, rpc, serde, service, workflow };
|
|
45
46
|
//# sourceMappingURL=fetch.js.map
|
package/dist/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - 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\nexport * from \"./common_api.js\";\n\nimport {\n type FetchEndpoint,\n FetchEndpointImpl,\n} from \"./endpoint/fetch_endpoint.js\";\nimport type { EndpointOptions } from \"./endpoint/types.js\";\nimport { withOptions } from \"./endpoint/withOptions.js\";\n\n/**\n * Create a new {@link RestateEndpoint} in request response protocol mode.\n * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()\n * @deprecated Please use {@link createEndpointHandler}\n */\nexport function endpoint(): FetchEndpoint {\n return new FetchEndpointImpl(\"REQUEST_RESPONSE\");\n}\n\nexport interface FetchEndpointOptions extends EndpointOptions {\n /**\n * Enables bidirectional communication for the handler.\n *\n * When set to `true`, the handler supports bidirectional streaming (e.g., via HTTP/2 or compatible HTTP/1.1 servers).\n * When `false`, the handler operates in request-response mode only.\n *\n * @default false\n */\n bidirectional?: boolean;\n}\n\n/**\n * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.\n *\n * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.\n * @returns A fetch handler function.\n *\n * @example\n * A typical request-response handler would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService] })\n *\n * @example\n * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })\n *\n */\nexport function createEndpointHandler(options: FetchEndpointOptions) {\n return withOptions<FetchEndpoint>(\n new FetchEndpointImpl(\n options.bidirectional ? \"BIDI_STREAM\" : \"REQUEST_RESPONSE\"\n ),\n options\n ).handler().fetch;\n}\nexport { type FetchEndpoint } from \"./endpoint/fetch_endpoint.js\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - 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\nexport * from \"./common_api.js\";\n\nimport {\n type FetchEndpoint,\n FetchEndpointImpl,\n} from \"./endpoint/fetch_endpoint.js\";\nimport type { EndpointOptions } from \"./endpoint/types.js\";\nimport { withOptions } from \"./endpoint/withOptions.js\";\n\n/**\n * Create a new {@link RestateEndpoint} in request response protocol mode.\n * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()\n * @deprecated Please use {@link createEndpointHandler}\n */\nexport function endpoint(): FetchEndpoint {\n return new FetchEndpointImpl(\"REQUEST_RESPONSE\");\n}\n\nexport interface FetchEndpointOptions extends EndpointOptions {\n /**\n * Enables bidirectional communication for the handler.\n *\n * When set to `true`, the handler supports bidirectional streaming (e.g., via HTTP/2 or compatible HTTP/1.1 servers).\n * When `false`, the handler operates in request-response mode only.\n *\n * @default false\n */\n bidirectional?: boolean;\n}\n\n/**\n * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.\n *\n * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.\n * @returns A fetch handler function.\n *\n * @example\n * A typical request-response handler would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService] })\n *\n * @example\n * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })\n *\n */\nexport function createEndpointHandler(options: FetchEndpointOptions) {\n return withOptions<FetchEndpoint>(\n new FetchEndpointImpl(\n options.bidirectional ? \"BIDI_STREAM\" : \"REQUEST_RESPONSE\"\n ),\n options\n ).handler().fetch;\n}\nexport { type FetchEndpoint } from \"./endpoint/fetch_endpoint.js\";\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,WAA0B;AACxC,QAAO,IAAI,kBAAkB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;AAoClD,SAAgB,sBAAsB,SAA+B;AACnE,QAAO,YACL,IAAI,kBACF,QAAQ,gBAAgB,gBAAgB,mBACzC,EACD,QACD,CAAC,SAAS,CAAC"}
|
package/dist/hooks.d.cts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Request } from "./context.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interceptors wrap handler and ctx.run() execution. They are part of the
|
|
7
|
+
* invocation — anything that happens inside them (including after `next()`)
|
|
8
|
+
* affects the invocation outcome.
|
|
9
|
+
*
|
|
10
|
+
* ## Error behavior
|
|
11
|
+
*
|
|
12
|
+
* Errors thrown at any point (before or after `next()`) affect the invocation:
|
|
13
|
+
*
|
|
14
|
+
* - **{@link TerminalError}** — the invocation **fails immediately**, no retry.
|
|
15
|
+
* - **Any other error** — Restate **retries** the invocation.
|
|
16
|
+
* - On suspension or pause, `next()` also rejects with an error. This does not
|
|
17
|
+
* mean the invocation failed — the attempt is simply ending. Do any cleanup
|
|
18
|
+
* you need and rethrow.
|
|
19
|
+
*
|
|
20
|
+
* ## Output
|
|
21
|
+
*
|
|
22
|
+
* Interceptors **cannot alter the handler's success return value** (the `void`
|
|
23
|
+
* signature means there is no way to replace it), but they **can transform
|
|
24
|
+
* errors** by catching and rethrowing a different error.
|
|
25
|
+
*
|
|
26
|
+
* ## Rules
|
|
27
|
+
*
|
|
28
|
+
* - `next()` must be called exactly once.
|
|
29
|
+
*
|
|
30
|
+
* ## When interceptors fire
|
|
31
|
+
*
|
|
32
|
+
* - `handler` fires on every attempt.
|
|
33
|
+
* - `run` fires when the `ctx.run()` closure executes. If the result is
|
|
34
|
+
* already in the journal, the closure is skipped and so is the interceptor.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* interceptor: {
|
|
39
|
+
* handler: async (next) => {
|
|
40
|
+
* console.log(`before ${ctx.request.target}`);
|
|
41
|
+
* try {
|
|
42
|
+
* await next();
|
|
43
|
+
* console.log(`after ${ctx.request.target}`);
|
|
44
|
+
* } catch (e) {
|
|
45
|
+
* console.log(`error ${ctx.request.target}: ${e}`);
|
|
46
|
+
* // Always rethrow — swallowing the error changes the
|
|
47
|
+
* // invocation outcome. You can also throw a different
|
|
48
|
+
* // error (e.g. TerminalError to fail immediately).
|
|
49
|
+
* throw e;
|
|
50
|
+
* }
|
|
51
|
+
* },
|
|
52
|
+
* run: async (name, next) => {
|
|
53
|
+
* console.log(` before run "${name}"`);
|
|
54
|
+
* try {
|
|
55
|
+
* await next();
|
|
56
|
+
* console.log(` after run "${name}"`);
|
|
57
|
+
* } catch (e) {
|
|
58
|
+
* console.log(` error run "${name}": ${e}`);
|
|
59
|
+
* throw e;
|
|
60
|
+
* }
|
|
61
|
+
* },
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
interface Interceptor {
|
|
66
|
+
/** Wraps the entire handler invocation. Fires on every attempt. */
|
|
67
|
+
handler?: (next: () => Promise<void>) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Wraps each `ctx.run()` call. Only fires for runs that actually execute —
|
|
70
|
+
* replayed runs (already in the journal) are skipped.
|
|
71
|
+
* `name` is the run's label.
|
|
72
|
+
*/
|
|
73
|
+
run?: (name: string, next: () => Promise<void>) => Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
interface Hooks {
|
|
76
|
+
interceptor?: Interceptor;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Factory called on every attempt. Receives the invocation request,
|
|
80
|
+
* returns hooks for that attempt's lifetime. Each attempt gets a fresh call.
|
|
81
|
+
*/
|
|
82
|
+
type HooksProvider = (ctx: {
|
|
83
|
+
request: Request;
|
|
84
|
+
}) => Hooks;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { Hooks, HooksProvider, Interceptor };
|
|
87
|
+
//# sourceMappingURL=hooks.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.cts","names":[],"sources":["../src/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAgEA;;;;;;AAaA;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAvBiB,WAAA;;yBAEQ,kBAAkB;;;;;;mCAMR,kBAAkB;;UAKpC,KAAA;gBACD;;;;;;KASJ,aAAA;WAAiC;MAAc"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Request } from "./context.js";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interceptors wrap handler and ctx.run() execution. They are part of the
|
|
7
|
+
* invocation — anything that happens inside them (including after `next()`)
|
|
8
|
+
* affects the invocation outcome.
|
|
9
|
+
*
|
|
10
|
+
* ## Error behavior
|
|
11
|
+
*
|
|
12
|
+
* Errors thrown at any point (before or after `next()`) affect the invocation:
|
|
13
|
+
*
|
|
14
|
+
* - **{@link TerminalError}** — the invocation **fails immediately**, no retry.
|
|
15
|
+
* - **Any other error** — Restate **retries** the invocation.
|
|
16
|
+
* - On suspension or pause, `next()` also rejects with an error. This does not
|
|
17
|
+
* mean the invocation failed — the attempt is simply ending. Do any cleanup
|
|
18
|
+
* you need and rethrow.
|
|
19
|
+
*
|
|
20
|
+
* ## Output
|
|
21
|
+
*
|
|
22
|
+
* Interceptors **cannot alter the handler's success return value** (the `void`
|
|
23
|
+
* signature means there is no way to replace it), but they **can transform
|
|
24
|
+
* errors** by catching and rethrowing a different error.
|
|
25
|
+
*
|
|
26
|
+
* ## Rules
|
|
27
|
+
*
|
|
28
|
+
* - `next()` must be called exactly once.
|
|
29
|
+
*
|
|
30
|
+
* ## When interceptors fire
|
|
31
|
+
*
|
|
32
|
+
* - `handler` fires on every attempt.
|
|
33
|
+
* - `run` fires when the `ctx.run()` closure executes. If the result is
|
|
34
|
+
* already in the journal, the closure is skipped and so is the interceptor.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* interceptor: {
|
|
39
|
+
* handler: async (next) => {
|
|
40
|
+
* console.log(`before ${ctx.request.target}`);
|
|
41
|
+
* try {
|
|
42
|
+
* await next();
|
|
43
|
+
* console.log(`after ${ctx.request.target}`);
|
|
44
|
+
* } catch (e) {
|
|
45
|
+
* console.log(`error ${ctx.request.target}: ${e}`);
|
|
46
|
+
* // Always rethrow — swallowing the error changes the
|
|
47
|
+
* // invocation outcome. You can also throw a different
|
|
48
|
+
* // error (e.g. TerminalError to fail immediately).
|
|
49
|
+
* throw e;
|
|
50
|
+
* }
|
|
51
|
+
* },
|
|
52
|
+
* run: async (name, next) => {
|
|
53
|
+
* console.log(` before run "${name}"`);
|
|
54
|
+
* try {
|
|
55
|
+
* await next();
|
|
56
|
+
* console.log(` after run "${name}"`);
|
|
57
|
+
* } catch (e) {
|
|
58
|
+
* console.log(` error run "${name}": ${e}`);
|
|
59
|
+
* throw e;
|
|
60
|
+
* }
|
|
61
|
+
* },
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
interface Interceptor {
|
|
66
|
+
/** Wraps the entire handler invocation. Fires on every attempt. */
|
|
67
|
+
handler?: (next: () => Promise<void>) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Wraps each `ctx.run()` call. Only fires for runs that actually execute —
|
|
70
|
+
* replayed runs (already in the journal) are skipped.
|
|
71
|
+
* `name` is the run's label.
|
|
72
|
+
*/
|
|
73
|
+
run?: (name: string, next: () => Promise<void>) => Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
interface Hooks {
|
|
76
|
+
interceptor?: Interceptor;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Factory called on every attempt. Receives the invocation request,
|
|
80
|
+
* returns hooks for that attempt's lifetime. Each attempt gets a fresh call.
|
|
81
|
+
*/
|
|
82
|
+
type HooksProvider = (ctx: {
|
|
83
|
+
request: Request;
|
|
84
|
+
}) => Hooks;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { Hooks, HooksProvider, Interceptor };
|
|
87
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAgEA;;;;;;AAaA;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAvBiB,WAAA;;yBAEQ,kBAAkB;;;;;;mCAMR,kBAAkB;;UAKpC,KAAA;gBACD;;;;;;KASJ,aAAA;WAAiC;MAAc"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":""}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('./types/errors.cjs');
|
|
3
|
-
const
|
|
3
|
+
const require_promises = require('./promises.cjs');
|
|
4
4
|
const require_context = require('./context.cjs');
|
|
5
|
+
const require_rpc = require('./types/rpc.cjs');
|
|
5
6
|
const require_internal = require('./internal.cjs');
|
|
6
7
|
const require_common_api = require('./common_api.cjs');
|
|
7
8
|
const require_node = require('./node.cjs');
|
|
@@ -37,6 +38,7 @@ Object.defineProperty(exports, 'internal', {
|
|
|
37
38
|
return require_internal.internal_exports;
|
|
38
39
|
}
|
|
39
40
|
});
|
|
41
|
+
exports.isRestatePromise = require_promises.isRestatePromise;
|
|
40
42
|
exports.object = require_rpc.object;
|
|
41
43
|
Object.defineProperty(exports, 'rpc', {
|
|
42
44
|
enumerable: true,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.cjs";
|
|
2
|
+
import { Hooks, HooksProvider, Interceptor } from "./hooks.cjs";
|
|
2
3
|
import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.cjs";
|
|
3
|
-
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request, RestatePromise, RunAction, RunOptions,
|
|
4
|
+
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.cjs";
|
|
5
|
+
import { internal_d_exports } from "./internal.cjs";
|
|
4
6
|
import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.cjs";
|
|
5
7
|
import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.cjs";
|
|
8
|
+
import { isRestatePromise } from "./promises.cjs";
|
|
6
9
|
import { EndpointOptions } from "./endpoint/types.cjs";
|
|
7
|
-
import { internal_d_exports } from "./internal.cjs";
|
|
8
10
|
import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.cjs";
|
|
9
|
-
import { ServeOptions, createEndpointHandler, endpoint, serve } from "./node.cjs";
|
|
10
|
-
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient,
|
|
11
|
+
import { NodeEndpointOptions, ServeOptions, createEndpointHandler, endpoint, serve } from "./node.cjs";
|
|
12
|
+
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, NodeEndpointOptions, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, ServeOptions, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, serve, service, workflow };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.js";
|
|
2
|
+
import { Hooks, HooksProvider, Interceptor } from "./hooks.js";
|
|
2
3
|
import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
|
|
3
|
-
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request, RestatePromise, RunAction, RunOptions,
|
|
4
|
+
import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.js";
|
|
5
|
+
import { internal_d_exports } from "./internal.js";
|
|
4
6
|
import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.js";
|
|
5
7
|
import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.js";
|
|
8
|
+
import { isRestatePromise } from "./promises.js";
|
|
6
9
|
import { EndpointOptions } from "./endpoint/types.js";
|
|
7
|
-
import { internal_d_exports } from "./internal.js";
|
|
8
10
|
import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
|
|
9
|
-
import { ServeOptions, createEndpointHandler, endpoint, serve } from "./node.js";
|
|
10
|
-
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient,
|
|
11
|
+
import { NodeEndpointOptions, ServeOptions, createEndpointHandler, endpoint, serve } from "./node.js";
|
|
12
|
+
export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, NodeEndpointOptions, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, ServeOptions, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, serve, service, workflow };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CancelledError, RestateError, RetryableError, TerminalError, TimeoutError } from "./types/errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isRestatePromise } from "./promises.js";
|
|
3
3
|
import { InvocationIdParser, RestatePromise } from "./context.js";
|
|
4
|
+
import { Opts, SendOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
|
|
4
5
|
import { internal_exports } from "./internal.js";
|
|
5
6
|
import { CombineablePromise, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
|
|
6
7
|
import { createEndpointHandler, endpoint, serve } from "./node.js";
|
|
7
8
|
|
|
8
|
-
export { CancelledError, CombineablePromise, InvocationIdParser, Opts, RestateError, RestatePromise, RetryableError, SendOpts, TerminalError, TimeoutError, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_exports as internal, object, rpc, serde, serve, service, workflow };
|
|
9
|
+
export { CancelledError, CombineablePromise, InvocationIdParser, Opts, RestateError, RestatePromise, RetryableError, SendOpts, TerminalError, TimeoutError, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_exports as internal, isRestatePromise, object, rpc, serde, serve, service, workflow };
|
package/dist/internal.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_errors = require('./types/errors.cjs');
|
|
1
3
|
|
|
2
4
|
//#region src/internal.ts
|
|
3
|
-
var internal_exports = {};
|
|
5
|
+
var internal_exports = /* @__PURE__ */ require_rolldown_runtime.__export({ isSuspendedError: () => require_errors.isSuspendedError });
|
|
4
6
|
|
|
5
7
|
//#endregion
|
|
6
8
|
Object.defineProperty(exports, 'internal_exports', {
|
package/dist/internal.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TerminalError, isSuspendedError } from "./types/errors.cjs";
|
|
2
|
+
import { Context, InvocationId, RestatePromise } from "./context.cjs";
|
|
3
|
+
import { Serde } from "@restatedev/restate-sdk-core";
|
|
2
4
|
|
|
3
5
|
//#region src/internal.d.ts
|
|
4
6
|
declare namespace internal_d_exports {
|
|
5
|
-
export { ContextInternal };
|
|
7
|
+
export { ContextInternal, InvocationReference, SignalReference, isSuspendedError };
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Internal {@link Context} interface exposing additional features.
|
|
@@ -21,6 +23,188 @@ interface ContextInternal extends Context {
|
|
|
21
23
|
* @experimental
|
|
22
24
|
*/
|
|
23
25
|
isProcessing(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a {@link RestatePromise} that resolves with `undefined` when Restate signals cancellation
|
|
28
|
+
* of the current invocation.
|
|
29
|
+
*
|
|
30
|
+
* This method **MUST** only be used when the handler (or its parent service/endpoint) is configured
|
|
31
|
+
* with `explicitCancellation: true`. Without configuring this option, cancellations are propagated automatically,
|
|
32
|
+
* and this promise will **NEVER** resolve.
|
|
33
|
+
*
|
|
34
|
+
* **Promise reuse:** calling this method multiple times returns the **same** promise instance as long as
|
|
35
|
+
* the current cancellation signal has not yet arrived. Once the promise resolves (cancellation received),
|
|
36
|
+
* later calls return a **new** promise that will resolve on the next cancellation signal.
|
|
37
|
+
*
|
|
38
|
+
* @example Race a long-running side effect against cancellation
|
|
39
|
+
* ```ts
|
|
40
|
+
* const greeter = restate.service({
|
|
41
|
+
* name: "greeter",
|
|
42
|
+
* handlers: {
|
|
43
|
+
* greet: async (ctx: restate.Context, name: string) => {
|
|
44
|
+
* ctxInternal = ctx as restate.internal.ContextInternal;
|
|
45
|
+
* const result = await RestatePromise.race([
|
|
46
|
+
* ctx.run(() => longRunningTask(name)),
|
|
47
|
+
* ctxInternal.cancellation().map(() => { throw new restate.TerminalError("Cancelled") }),
|
|
48
|
+
* ]);
|
|
49
|
+
* return result;
|
|
50
|
+
* },
|
|
51
|
+
* },
|
|
52
|
+
* options: { explicitCancellation: true },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Use the cancellation promise to create an AbortSignal for ctx.run
|
|
57
|
+
* ```ts
|
|
58
|
+
* const greeter = restate.service({
|
|
59
|
+
* name: "greeter",
|
|
60
|
+
* handlers: {
|
|
61
|
+
* greet: async (ctx: restate.Context, name: string) => {
|
|
62
|
+
* const ctxInternal = ctx as restate.internal.ContextInternal;
|
|
63
|
+
* const controller = new AbortController();
|
|
64
|
+
* const cancellation = ctxInternal.cancellation()
|
|
65
|
+
* .map(() => {
|
|
66
|
+
* controller.abort();
|
|
67
|
+
* throw new restate.TerminalError("Cancelled");
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* return RestatePromise.race([
|
|
71
|
+
* ctx.run(() => fetch(`https://api.example.com/greet/${name}`, { signal: controller.signal })),
|
|
72
|
+
* cancellation,
|
|
73
|
+
* ]);
|
|
74
|
+
* },
|
|
75
|
+
* },
|
|
76
|
+
* options: { explicitCancellation: true },
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Handle cancellation, perform cleanup, then listen for the next cancellation
|
|
81
|
+
* ```ts
|
|
82
|
+
* const greeter = restate.service({
|
|
83
|
+
* name: "greeter",
|
|
84
|
+
* handlers: {
|
|
85
|
+
* greet: async (ctx: restate.Context, name: string) => {
|
|
86
|
+
* const ctxInternal = ctx as restate.internal.ContextInternal;
|
|
87
|
+
* try {
|
|
88
|
+
* return await RestatePromise.race([
|
|
89
|
+
* ctx.run(() => longRunningTask(name)),
|
|
90
|
+
* ctxInternal.cancellation().map(() => { throw new restate.TerminalError("Cancelled") }),
|
|
91
|
+
* ]);
|
|
92
|
+
* } catch (e) {
|
|
93
|
+
* // Perform cleanup
|
|
94
|
+
* await ctx.run(() => cleanupResources(name));
|
|
95
|
+
*
|
|
96
|
+
* // After cancellation is resolved, ctx.cancellation() returns a fresh promise.
|
|
97
|
+
* // Race cleanup confirmation against the next cancellation signal.
|
|
98
|
+
* await RestatePromise.race([
|
|
99
|
+
* ctx.run(() => confirmCleanup(name)),
|
|
100
|
+
* ctxInternal.cancellation().map(() => { throw new restate.TerminalError("Canceled during cleanup") }),
|
|
101
|
+
* ]);
|
|
102
|
+
* }
|
|
103
|
+
* },
|
|
104
|
+
* },
|
|
105
|
+
* options: { explicitCancellation: true },
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @experimental
|
|
110
|
+
*/
|
|
111
|
+
cancellation(): RestatePromise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Cancel all previous calls made from this handler.
|
|
114
|
+
*
|
|
115
|
+
* This method **MUST** only be used when the handler (or its parent service/endpoint) is configured
|
|
116
|
+
* with `explicitCancellation: true`. Without configuring this option, this operation will always be a no-op.
|
|
117
|
+
*
|
|
118
|
+
* @return the invocation id of the canceled calls.
|
|
119
|
+
* @experimental
|
|
120
|
+
*/
|
|
121
|
+
cancelPreviousCalls(): RestatePromise<InvocationId[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Wait for a named signal to arrive on the current invocation.
|
|
124
|
+
*
|
|
125
|
+
* Signals are identified by name and are scoped to the current invocation.
|
|
126
|
+
* Another handler can send a signal to this invocation using
|
|
127
|
+
* {@link InvocationReference.signal}, specifying this invocation's
|
|
128
|
+
* ID (available via `ctx.request().id`) and the same signal name.
|
|
129
|
+
*
|
|
130
|
+
* @param name the name of the signal to wait for.
|
|
131
|
+
* @param serde optional custom serializer/deserializer for the payload.
|
|
132
|
+
* @returns a {@link RestatePromise} that resolves when the signal arrives.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* const ctxInternal = ctx as restate.internal.ContextInternal;
|
|
136
|
+
* const approved = await ctxInternal.signal<boolean>("approved");
|
|
137
|
+
*
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
140
|
+
signal<T>(name: string, serde?: Serde<T>): RestatePromise<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Get a reference to a target invocation, to send signals to it.
|
|
143
|
+
*
|
|
144
|
+
* @param invocationId the invocation ID of the target invocation.
|
|
145
|
+
* @returns an {@link InvocationReference} for the target invocation.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const ctxInternal = ctx as restate.internal.ContextInternal;
|
|
149
|
+
* const target = ctxInternal.invocation(targetInvocationId);
|
|
150
|
+
* target.signal("approved").resolve(true);
|
|
151
|
+
* target.signal("approved").reject("Request denied");
|
|
152
|
+
*
|
|
153
|
+
* @experimental
|
|
154
|
+
*/
|
|
155
|
+
invocation(invocationId: InvocationId): InvocationReference;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A reference to a target invocation, used to send signals.
|
|
159
|
+
*
|
|
160
|
+
* @experimental
|
|
161
|
+
*/
|
|
162
|
+
interface InvocationReference {
|
|
163
|
+
/**
|
|
164
|
+
* Get a handle to a named signal on the target invocation.
|
|
165
|
+
*
|
|
166
|
+
* @param name the name of the signal.
|
|
167
|
+
* @param serde optional custom serializer/deserializer for the payload.
|
|
168
|
+
* @returns a {@link SignalReference} to resolve or reject the signal.
|
|
169
|
+
*
|
|
170
|
+
* @experimental
|
|
171
|
+
*/
|
|
172
|
+
signal<T>(name: string, serde?: Serde<T>): SignalReference<T>;
|
|
173
|
+
/**
|
|
174
|
+
* Cancel the target invocation.
|
|
175
|
+
*/
|
|
176
|
+
cancel(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Attach to the target invocation and wait for its result.
|
|
179
|
+
*
|
|
180
|
+
* @param serde optional custom serializer/deserializer for the result.
|
|
181
|
+
* @returns a {@link RestatePromise} that resolves with the invocation result.
|
|
182
|
+
*/
|
|
183
|
+
attach<T>(serde?: Serde<T>): RestatePromise<T>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* A handle to send a signal value to a target invocation.
|
|
187
|
+
*
|
|
188
|
+
* @experimental
|
|
189
|
+
*/
|
|
190
|
+
interface SignalReference<T> {
|
|
191
|
+
/**
|
|
192
|
+
* Resolve the signal with a value.
|
|
193
|
+
*
|
|
194
|
+
* @param payload the payload to send.
|
|
195
|
+
*
|
|
196
|
+
* @experimental
|
|
197
|
+
*/
|
|
198
|
+
resolve(payload?: T): void;
|
|
199
|
+
/**
|
|
200
|
+
* Reject the signal. The target invocation waiting on this signal will be
|
|
201
|
+
* woken up with a terminal error containing the provided reason.
|
|
202
|
+
*
|
|
203
|
+
* @param reason the reason for rejection, either a string message or a {@link TerminalError}.
|
|
204
|
+
*
|
|
205
|
+
* @experimental
|
|
206
|
+
*/
|
|
207
|
+
reject(reason: string | TerminalError): void;
|
|
24
208
|
}
|
|
25
209
|
//#endregion
|
|
26
210
|
export { internal_d_exports };
|
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":";;;;;;;;;;;;;;;UAaiB,eAAA,SAAwB;EAAxB;;;;;;;;EA+IU,YAAA,EAAA,EAAA,OAAA;EAAe;;;AAQ1C;;;;;;;;;;AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAtFkB;;;;;;;;;;yBAWO,eAAe;;;;;;;;;;;;;;;;;;;kCAoBN,MAAM,KAAK,eAAe;;;;;;;;;;;;;;;2BAgBjC,eAAe;;;;;;;UAQzB,mBAAA;;;;;;;;;;kCAUiB,MAAM,KAAK,gBAAgB;;;;;;;;;;;oBAazC,MAAM,KAAK,eAAe;;;;;;;UAQ7B;;;;;;;;oBAQG;;;;;;;;;0BAUM"}
|