@restatedev/restate-sdk 0.7.3-worker → 0.8.1
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/LICENSE +1 -1
- package/README.md +29 -51
- package/dist/clients/workflow_client.d.ts +77 -0
- package/dist/clients/workflow_client.d.ts.map +1 -0
- package/dist/clients/workflow_client.js +172 -0
- package/dist/clients/workflow_client.js.map +1 -0
- package/dist/connection/buffered_connection.js +44 -0
- package/dist/connection/buffered_connection.js.map +1 -0
- package/dist/connection/connection.js +13 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/embedded_connection.js +59 -0
- package/dist/connection/embedded_connection.js.map +1 -0
- package/dist/connection/http_connection.js +203 -0
- package/dist/connection/http_connection.js.map +1 -0
- package/dist/connection/lambda_connection.js +58 -0
- package/dist/connection/lambda_connection.js.map +1 -0
- package/dist/{restate_context.d.ts → context.d.ts} +239 -170
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +113 -0
- package/dist/context.js.map +1 -0
- package/dist/{restate_context_impl.d.ts → context_impl.d.ts} +26 -30
- package/dist/context_impl.d.ts.map +1 -0
- package/dist/context_impl.js +439 -0
- package/dist/context_impl.js.map +1 -0
- package/dist/embedded/api.d.ts +2 -2
- package/dist/embedded/api.d.ts.map +1 -1
- package/dist/embedded/api.js +35 -0
- package/dist/embedded/api.js.map +1 -0
- package/dist/embedded/handler.d.ts +2 -2
- package/dist/embedded/handler.d.ts.map +1 -1
- package/dist/embedded/handler.js +26 -0
- package/dist/embedded/handler.js.map +1 -0
- package/dist/embedded/http2_remote.js +91 -0
- package/dist/embedded/http2_remote.js.map +1 -0
- package/dist/embedded/invocation.d.ts.map +1 -1
- package/dist/embedded/invocation.js +94 -0
- package/dist/embedded/invocation.js.map +1 -0
- package/dist/endpoint/endpoint_impl.d.ts +35 -0
- package/dist/endpoint/endpoint_impl.d.ts.map +1 -0
- package/dist/endpoint/endpoint_impl.js +405 -0
- package/dist/endpoint/endpoint_impl.js.map +1 -0
- package/dist/endpoint/http2_handler.d.ts +11 -0
- package/dist/endpoint/http2_handler.d.ts.map +1 -0
- package/dist/endpoint/http2_handler.js +119 -0
- package/dist/endpoint/http2_handler.js.map +1 -0
- package/dist/endpoint/lambda_handler.d.ts +15 -0
- package/dist/endpoint/lambda_handler.d.ts.map +1 -0
- package/dist/endpoint/lambda_handler.js +144 -0
- package/dist/endpoint/lambda_handler.js.map +1 -0
- package/dist/endpoint.d.ts +161 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/endpoint.js +22 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/generated/dev/restate/events.js +371 -0
- package/dist/generated/dev/restate/events.js.map +1 -0
- package/dist/generated/dev/restate/ext.js +215 -0
- package/dist/generated/dev/restate/ext.js.map +1 -0
- package/dist/generated/google/protobuf/descriptor.js +6676 -0
- package/dist/generated/google/protobuf/descriptor.js.map +1 -0
- package/dist/generated/google/protobuf/empty.js +107 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/struct.js +754 -0
- package/dist/generated/google/protobuf/struct.js.map +1 -0
- package/dist/generated/proto/discovery.js +364 -0
- package/dist/generated/proto/discovery.js.map +1 -0
- package/dist/generated/proto/dynrpc.js +668 -0
- package/dist/generated/proto/dynrpc.js.map +1 -0
- package/dist/generated/proto/javascript.d.ts +13 -0
- package/dist/generated/proto/javascript.d.ts.map +1 -1
- package/dist/generated/proto/javascript.js +416 -0
- package/dist/generated/proto/javascript.js.map +1 -0
- package/dist/generated/proto/protocol.d.ts +43 -0
- package/dist/generated/proto/protocol.d.ts.map +1 -1
- package/dist/generated/proto/protocol.js +2641 -0
- package/dist/generated/proto/protocol.js.map +1 -0
- package/dist/generated/proto/services.js +1535 -0
- package/dist/generated/proto/services.js.map +1 -0
- package/dist/generated/proto/test.js +321 -0
- package/dist/generated/proto/test.js.map +1 -0
- package/dist/invocation.d.ts +4 -1
- package/dist/invocation.d.ts.map +1 -1
- package/dist/invocation.js +157 -0
- package/dist/invocation.js.map +1 -0
- package/dist/io/decoder.d.ts +1 -0
- package/dist/io/decoder.d.ts.map +1 -1
- package/dist/io/decoder.js +140 -0
- package/dist/io/decoder.js.map +1 -0
- package/dist/io/encoder.d.ts +1 -2
- package/dist/io/encoder.d.ts.map +1 -1
- package/dist/io/encoder.js +68 -0
- package/dist/io/encoder.js.map +1 -0
- package/dist/journal.d.ts +13 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +405 -0
- package/dist/journal.js.map +1 -0
- package/dist/local_state_store.d.ts +5 -3
- package/dist/local_state_store.d.ts.map +1 -1
- package/dist/local_state_store.js +82 -0
- package/dist/local_state_store.js.map +1 -0
- package/dist/logger.d.ts +19 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +90 -0
- package/dist/logger.js.map +1 -0
- package/dist/promise_combinator_tracker.d.ts +29 -0
- package/dist/promise_combinator_tracker.d.ts.map +1 -0
- package/dist/promise_combinator_tracker.js +128 -0
- package/dist/promise_combinator_tracker.js.map +1 -0
- package/dist/public_api.d.ts +5 -5
- package/dist/public_api.d.ts.map +1 -1
- package/dist/public_api.js +60 -0
- package/dist/public_api.js.map +1 -0
- package/dist/state_machine.d.ts +19 -12
- package/dist/state_machine.d.ts.map +1 -1
- package/dist/state_machine.js +437 -0
- package/dist/state_machine.js.map +1 -0
- package/dist/types/errors.d.ts +12 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +273 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/grpc.d.ts +6 -4
- package/dist/types/grpc.d.ts.map +1 -1
- package/dist/types/grpc.js +81 -0
- package/dist/types/grpc.js.map +1 -0
- package/dist/types/protocol.d.ts +9 -5
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +147 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/router.d.ts +8 -8
- package/dist/types/router.d.ts.map +1 -1
- package/dist/types/router.js +36 -0
- package/dist/types/router.js.map +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +138 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/{assumpsions.d.ts → assumptions.d.ts} +1 -1
- package/dist/utils/{assumpsions.d.ts.map → assumptions.d.ts.map} +1 -1
- package/dist/utils/assumptions.js +101 -0
- package/dist/utils/assumptions.js.map +1 -0
- package/dist/utils/message_logger.d.ts +28 -0
- package/dist/utils/message_logger.d.ts.map +1 -0
- package/dist/utils/message_logger.js +88 -0
- package/dist/utils/message_logger.js.map +1 -0
- package/dist/utils/promises.d.ts +15 -0
- package/dist/utils/promises.d.ts.map +1 -0
- package/dist/utils/promises.js +67 -0
- package/dist/utils/promises.js.map +1 -0
- package/dist/utils/public_utils.js +49 -0
- package/dist/utils/public_utils.js.map +1 -0
- package/dist/utils/rand.d.ts +1 -1
- package/dist/utils/rand.d.ts.map +1 -1
- package/dist/utils/rand.js +114 -0
- package/dist/utils/rand.js.map +1 -0
- package/dist/utils/utils.d.ts +1 -10
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +122 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/workflows/workflow.d.ts +101 -0
- package/dist/workflows/workflow.d.ts.map +1 -0
- package/dist/workflows/workflow.js +80 -0
- package/dist/workflows/workflow.js.map +1 -0
- package/dist/workflows/workflow_state_service.d.ts +35 -0
- package/dist/workflows/workflow_state_service.d.ts.map +1 -0
- package/dist/workflows/workflow_state_service.js +201 -0
- package/dist/workflows/workflow_state_service.js.map +1 -0
- package/dist/workflows/workflow_wrapper_service.d.ts +10 -0
- package/dist/workflows/workflow_wrapper_service.d.ts.map +1 -0
- package/dist/workflows/workflow_wrapper_service.js +264 -0
- package/dist/workflows/workflow_wrapper_service.js.map +1 -0
- package/package.json +38 -39
- package/src/clients/workflow_client.ts +290 -0
- package/src/connection/buffered_connection.ts +47 -0
- package/src/connection/connection.ts +34 -0
- package/src/connection/embedded_connection.ts +62 -0
- package/src/connection/http_connection.ts +228 -0
- package/src/connection/lambda_connection.ts +69 -0
- package/src/context.ts +633 -0
- package/src/context_impl.ts +721 -0
- package/src/embedded/api.ts +57 -0
- package/src/embedded/handler.ts +36 -0
- package/src/embedded/http2_remote.ts +103 -0
- package/src/embedded/invocation.ts +126 -0
- package/src/endpoint/endpoint_impl.ts +623 -0
- package/src/endpoint/http2_handler.ts +151 -0
- package/src/endpoint/lambda_handler.ts +181 -0
- package/src/endpoint.ts +187 -0
- package/src/generated/dev/restate/events.ts +430 -0
- package/src/generated/dev/restate/ext.ts +238 -0
- package/src/generated/google/protobuf/descriptor.ts +7889 -0
- package/src/generated/google/protobuf/empty.ts +150 -0
- package/src/generated/google/protobuf/struct.ts +878 -0
- package/src/generated/proto/discovery.ts +423 -0
- package/src/generated/proto/dynrpc.ts +768 -0
- package/src/generated/proto/javascript.ts +488 -0
- package/src/generated/proto/protocol.ts +3091 -0
- package/src/generated/proto/services.ts +1834 -0
- package/src/generated/proto/test.ts +387 -0
- package/src/invocation.ts +212 -0
- package/src/io/decoder.ts +171 -0
- package/src/io/encoder.ts +72 -0
- package/src/journal.ts +537 -0
- package/src/local_state_store.ts +94 -0
- package/src/logger.ts +121 -0
- package/src/promise_combinator_tracker.ts +191 -0
- package/src/public_api.ts +53 -0
- package/src/state_machine.ts +635 -0
- package/src/types/errors.ts +297 -0
- package/src/types/grpc.ts +97 -0
- package/src/types/protocol.ts +201 -0
- package/src/types/router.ts +118 -0
- package/src/types/types.ts +160 -0
- package/src/utils/assumptions.ts +131 -0
- package/src/utils/message_logger.ts +112 -0
- package/src/utils/promises.ts +118 -0
- package/src/utils/public_utils.ts +91 -0
- package/src/utils/rand.ts +142 -0
- package/src/utils/utils.ts +178 -0
- package/src/workflows/workflow.ts +178 -0
- package/src/workflows/workflow_state_service.ts +299 -0
- package/src/workflows/workflow_wrapper_service.ts +314 -0
- package/dist/cloudflare_bundle.js +0 -27387
- package/dist/restate_context.d.ts.map +0 -1
- package/dist/restate_context_impl.d.ts.map +0 -1
- package/dist/server/base_restate_server.d.ts +0 -32
- package/dist/server/base_restate_server.d.ts.map +0 -1
- package/dist/server/restate_lambda_handler.d.ts +0 -104
- package/dist/server/restate_lambda_handler.d.ts.map +0 -1
- package/dist/server/restate_server.d.ts +0 -97
- package/dist/server/restate_server.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -60
- package/dist/utils/logger.d.ts.map +0 -1
package/dist/types/router.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Event } from "
|
|
1
|
+
import { CombineablePromise, Context, KeyedContext } from "../context";
|
|
2
|
+
import { Event } from "./types";
|
|
3
3
|
type WithKeyArgument<F> = F extends () => infer R ? (key: string) => R : F;
|
|
4
|
-
type WithoutRpcContext<F> = F extends (ctx:
|
|
4
|
+
type WithoutRpcContext<F> = F extends (ctx: infer C extends Context, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
5
5
|
export type Client<M> = {
|
|
6
|
-
[K in keyof M as M[K] extends never ? never : K]: M[K];
|
|
6
|
+
[K in keyof M as M[K] extends never ? never : K]: M[K] extends (...args: infer P) => PromiseLike<infer O> ? (...args: P) => CombineablePromise<O> : never;
|
|
7
7
|
};
|
|
8
8
|
export type SendClient<M> = {
|
|
9
9
|
[K in keyof M as M[K] extends never ? never : K]: M[K] extends (...args: infer P) => any ? (...args: P) => void : never;
|
|
10
10
|
};
|
|
11
|
-
export type UnKeyedHandler<F> = F extends (ctx:
|
|
11
|
+
export type UnKeyedHandler<F> = F extends (ctx: Context) => Promise<any> ? F : F extends (ctx: Context, input: any) => Promise<any> ? F : never;
|
|
12
12
|
export type UnKeyedRouterOpts<U> = {
|
|
13
13
|
[K in keyof U]: U[K] extends UnKeyedHandler<any> ? U[K] : never;
|
|
14
14
|
};
|
|
@@ -16,7 +16,7 @@ export type UnKeyedRouter<U> = {
|
|
|
16
16
|
[K in keyof U]: U[K] extends UnKeyedHandler<infer F> ? WithoutRpcContext<F> : never;
|
|
17
17
|
};
|
|
18
18
|
export declare const router: <M>(opts: UnKeyedRouterOpts<M>) => UnKeyedRouter<M>;
|
|
19
|
-
export type KeyedHandler<F> = F extends (ctx:
|
|
19
|
+
export type KeyedHandler<F> = F extends (ctx: KeyedContext) => Promise<any> ? F : F extends (ctx: KeyedContext, key: string, value: any) => Promise<any> ? F : never;
|
|
20
20
|
export type KeyedRouterOpts<U> = {
|
|
21
21
|
[K in keyof U]: U[K] extends KeyedHandler<U[K]> | KeyedEventHandler<U[K]> ? U[K] : never;
|
|
22
22
|
};
|
|
@@ -24,10 +24,10 @@ export type KeyedRouter<U> = {
|
|
|
24
24
|
[K in keyof U]: U[K] extends KeyedEventHandler<U[K]> ? never : U[K] extends KeyedHandler<infer F> ? WithKeyArgument<WithoutRpcContext<F>> : never;
|
|
25
25
|
};
|
|
26
26
|
export declare const keyedRouter: <M>(opts: KeyedRouterOpts<M>) => KeyedRouter<M>;
|
|
27
|
-
export type KeyedEventHandler<U> = U extends () => Promise<void> ? never : U extends (ctx:
|
|
27
|
+
export type KeyedEventHandler<U> = U extends () => Promise<void> ? never : U extends (ctx: KeyedContext) => Promise<void> ? never : U extends (ctx: KeyedContext, event: Event) => Promise<void> ? U : never;
|
|
28
28
|
export declare const keyedEventHandler: <H>(handler: KeyedEventHandler<H>) => H;
|
|
29
29
|
export declare const isEventHandler: (handler: any) => handler is {
|
|
30
|
-
handler: (ctx:
|
|
30
|
+
handler: (ctx: KeyedContext, event: Event) => Promise<void>;
|
|
31
31
|
};
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/types/router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/types/router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,E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CAAC,MAAM,CAAC,CAAC,GAClC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GACrC,KAAK;CACV,CAAC;AAEF,eAAO,MAAM,WAAW,iDAKvB,CAAC;AAIF,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,OAAO,CAAC,IAAI,CAAC,GAC5D,KAAK,GACL,CAAC,SAAS,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAC9C,KAAK,GACL,CAAC,SAAS,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,GAC5D,CAAC,GACD,KAAK,CAAC;AAEV,eAAO,MAAM,iBAAiB,yCAE7B,CAAC;AAEF,eAAO,MAAM,cAAc,YAChB,GAAG;mBAEG,YAAY,SAAS,KAAK,KAAK,QAAQ,IAAI,CAAC;CAG5D,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isEventHandler = exports.keyedEventHandler = exports.keyedRouter = exports.router = void 0;
|
|
14
|
+
const router = (opts) => {
|
|
15
|
+
if (opts === undefined || opts === null) {
|
|
16
|
+
throw new Error("router must be defined");
|
|
17
|
+
}
|
|
18
|
+
return opts;
|
|
19
|
+
};
|
|
20
|
+
exports.router = router;
|
|
21
|
+
const keyedRouter = (opts) => {
|
|
22
|
+
if (opts === undefined || opts === null) {
|
|
23
|
+
throw new Error("router must be defined");
|
|
24
|
+
}
|
|
25
|
+
return opts;
|
|
26
|
+
};
|
|
27
|
+
exports.keyedRouter = keyedRouter;
|
|
28
|
+
const keyedEventHandler = (handler) => {
|
|
29
|
+
return { eventHandler: true, handler: handler };
|
|
30
|
+
};
|
|
31
|
+
exports.keyedEventHandler = keyedEventHandler;
|
|
32
|
+
const isEventHandler = (handler) => {
|
|
33
|
+
return typeof handler === "object" && handler["eventHandler"];
|
|
34
|
+
};
|
|
35
|
+
exports.isEventHandler = isEventHandler;
|
|
36
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/types/router.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAoDI,MAAM,MAAM,GAAG,CAAI,IAA0B,EAAoB,EAAE;IACxE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC3C;IACD,OAAO,IAAwB,CAAC;AAClC,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB;AAwBK,MAAM,WAAW,GAAG,CAAI,IAAwB,EAAkB,EAAE;IACzE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC3C;IACD,OAAO,IAAsB,CAAC;AAChC,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB;AAYK,MAAM,iBAAiB,GAAG,CAAI,OAA6B,EAAK,EAAE;IACvE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAO,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,cAAc,GAAG,CAC5B,OAAY,EAGZ,EAAE;IACF,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;AAChE,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Message {
|
|
|
7
7
|
readonly protocolVersion?: number | undefined;
|
|
8
8
|
readonly requiresAck?: boolean | undefined;
|
|
9
9
|
constructor(messageType: bigint, message: ProtocolMessage, completed?: boolean | undefined, protocolVersion?: number | undefined, requiresAck?: boolean | undefined);
|
|
10
|
+
toJSON(): unknown;
|
|
10
11
|
}
|
|
11
12
|
export declare class Header {
|
|
12
13
|
readonly messageType: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":";AAWA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":";AAWA,OAAO,EAWL,eAAe,EAIhB,MAAM,YAAY,CAAC;AAEpB,qBAAa,OAAO;IAEhB,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,QAAQ,CAAC,OAAO,EAAE,eAAe;IACjC,QAAQ,CAAC,SAAS,CAAC;IACnB,QAAQ,CAAC,eAAe,CAAC;IACzB,QAAQ,CAAC,WAAW,CAAC;gBAJZ,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,eAAe,EACxB,SAAS,CAAC,qBAAS,EACnB,eAAe,CAAC,oBAAQ,EACxB,WAAW,CAAC,qBAAS;IAIhC,MAAM,IAAI,OAAO;CAUlB;AA4CD,qBAAa,MAAM;IAEf,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,QAAQ,CAAC,aAAa,CAAC;IACvB,QAAQ,CAAC,eAAe,CAAC;IACzB,QAAQ,CAAC,eAAe,CAAC;IACzB,QAAQ,CAAC,gBAAgB,CAAC;gBALjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,aAAa,CAAC,qBAAS,EACvB,eAAe,CAAC,oBAAQ,EACxB,eAAe,CAAC,qBAAS,EACzB,gBAAgB,CAAC,qBAAS;WAGvB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IA4BvC,OAAO,IAAI,MAAM;CAazB;AAED,qBAAa,KAAK;IAEd,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;gBAFlC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAGtC,IAAI,CAAC,CAAC,KAAK,CAAC;IAIZ,IAAI,IAAI,UAAU;CAG1B"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Event = exports.Header = exports.Message = void 0;
|
|
14
|
+
const protocol_1 = require("./protocol");
|
|
15
|
+
class Message {
|
|
16
|
+
messageType;
|
|
17
|
+
message;
|
|
18
|
+
completed;
|
|
19
|
+
protocolVersion;
|
|
20
|
+
requiresAck;
|
|
21
|
+
constructor(messageType, message, completed, protocolVersion, requiresAck) {
|
|
22
|
+
this.messageType = messageType;
|
|
23
|
+
this.message = message;
|
|
24
|
+
this.completed = completed;
|
|
25
|
+
this.protocolVersion = protocolVersion;
|
|
26
|
+
this.requiresAck = requiresAck;
|
|
27
|
+
}
|
|
28
|
+
// For debugging purposes
|
|
29
|
+
toJSON() {
|
|
30
|
+
const pbType = protocol_1.PROTOBUF_MESSAGE_BY_TYPE.get(this.messageType);
|
|
31
|
+
if (pbType === undefined) {
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
messageType: (0, protocol_1.formatMessageType)(this.messageType),
|
|
36
|
+
message: pbType.toJSON(this.message),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Message = Message;
|
|
41
|
+
class MessageType {
|
|
42
|
+
static assertValid(messageTypeId) {
|
|
43
|
+
if (protocol_1.KNOWN_MESSAGE_TYPES.has(messageTypeId)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if ((messageTypeId & CUSTOM_MESSAGE_MASK) !== 0n) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Unknown message type ${messageTypeId}`);
|
|
50
|
+
}
|
|
51
|
+
static hasCompletedFlag(messageType) {
|
|
52
|
+
return (messageType === protocol_1.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE ||
|
|
53
|
+
messageType === protocol_1.GET_STATE_ENTRY_MESSAGE_TYPE ||
|
|
54
|
+
messageType === protocol_1.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE ||
|
|
55
|
+
messageType === protocol_1.SLEEP_ENTRY_MESSAGE_TYPE ||
|
|
56
|
+
messageType === protocol_1.AWAKEABLE_ENTRY_MESSAGE_TYPE);
|
|
57
|
+
}
|
|
58
|
+
static hasProtocolVersion(messageType) {
|
|
59
|
+
return messageType == protocol_1.START_MESSAGE_TYPE;
|
|
60
|
+
}
|
|
61
|
+
static hasRequiresAckFlag(messageType) {
|
|
62
|
+
return (messageType !== protocol_1.START_MESSAGE_TYPE &&
|
|
63
|
+
messageType !== protocol_1.ERROR_MESSAGE_TYPE &&
|
|
64
|
+
messageType !== protocol_1.SUSPENSION_MESSAGE_TYPE &&
|
|
65
|
+
messageType !== protocol_1.ENTRY_ACK_MESSAGE_TYPE &&
|
|
66
|
+
messageType !== protocol_1.COMPLETION_MESSAGE_TYPE);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const CUSTOM_MESSAGE_MASK = BigInt(0xfc00);
|
|
70
|
+
const COMPLETED_MASK = BigInt(0x0001_0000_0000);
|
|
71
|
+
const VERSION_MASK = BigInt(0x03ff_0000_0000);
|
|
72
|
+
const REQUIRES_ACK_MASK = BigInt(0x8000_0000_0000);
|
|
73
|
+
// The header is exported but only for tests.
|
|
74
|
+
class Header {
|
|
75
|
+
messageType;
|
|
76
|
+
frameLength;
|
|
77
|
+
completedFlag;
|
|
78
|
+
protocolVersion;
|
|
79
|
+
requiresAckFlag;
|
|
80
|
+
partialStateFlag;
|
|
81
|
+
constructor(messageType, frameLength, completedFlag, protocolVersion, requiresAckFlag, partialStateFlag) {
|
|
82
|
+
this.messageType = messageType;
|
|
83
|
+
this.frameLength = frameLength;
|
|
84
|
+
this.completedFlag = completedFlag;
|
|
85
|
+
this.protocolVersion = protocolVersion;
|
|
86
|
+
this.requiresAckFlag = requiresAckFlag;
|
|
87
|
+
this.partialStateFlag = partialStateFlag;
|
|
88
|
+
}
|
|
89
|
+
static fromU64be(value) {
|
|
90
|
+
const messageType = (value >> 48n) & 0xffffn;
|
|
91
|
+
MessageType.assertValid(messageType);
|
|
92
|
+
const completedFlag = MessageType.hasCompletedFlag(messageType) &&
|
|
93
|
+
(value & COMPLETED_MASK) !== 0n
|
|
94
|
+
? true
|
|
95
|
+
: undefined;
|
|
96
|
+
const protocolVersion = MessageType.hasProtocolVersion(messageType)
|
|
97
|
+
? Number(((value & VERSION_MASK) >> 32n) & 0xffffn)
|
|
98
|
+
: undefined;
|
|
99
|
+
const requiresAckFlag = MessageType.hasRequiresAckFlag(messageType) &&
|
|
100
|
+
(value & REQUIRES_ACK_MASK) !== 0n
|
|
101
|
+
? true
|
|
102
|
+
: undefined;
|
|
103
|
+
const frameLength = Number(value & 0xffffffffn);
|
|
104
|
+
return new Header(messageType, frameLength, completedFlag, protocolVersion, requiresAckFlag);
|
|
105
|
+
}
|
|
106
|
+
toU64be() {
|
|
107
|
+
let res = (this.messageType << 48n) | BigInt(this.frameLength);
|
|
108
|
+
if (this.completedFlag) {
|
|
109
|
+
res = res | COMPLETED_MASK;
|
|
110
|
+
}
|
|
111
|
+
if (this.protocolVersion !== undefined) {
|
|
112
|
+
res = res | (BigInt(this.protocolVersion) << 32n);
|
|
113
|
+
}
|
|
114
|
+
if (this.requiresAckFlag) {
|
|
115
|
+
res = res | REQUIRES_ACK_MASK;
|
|
116
|
+
}
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.Header = Header;
|
|
121
|
+
class Event {
|
|
122
|
+
key;
|
|
123
|
+
payload;
|
|
124
|
+
attributes;
|
|
125
|
+
constructor(key, payload, attributes) {
|
|
126
|
+
this.key = key;
|
|
127
|
+
this.payload = payload;
|
|
128
|
+
this.attributes = attributes;
|
|
129
|
+
}
|
|
130
|
+
json() {
|
|
131
|
+
return JSON.parse(this.payload.toString("utf-8"));
|
|
132
|
+
}
|
|
133
|
+
body() {
|
|
134
|
+
return this.payload;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.Event = Event;
|
|
138
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,yCAeoB;AAEpB,MAAa,OAAO;IAEP;IACA;IACA;IACA;IACA;IALX,YACW,WAAmB,EACnB,OAAwB,EACxB,SAAmB,EACnB,eAAwB,EACxB,WAAqB;QAJrB,gBAAW,GAAX,WAAW,CAAQ;QACnB,YAAO,GAAP,OAAO,CAAiB;QACxB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ings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAQvD,eAAO,MAAM,eAAe,SAAU,OAAO,EAAE,KAAG,UAoCjD,CAAC;AAGF,MAAM,MAAM,MAAM,GACd,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,IAAI,GACJ,KAAK,CAAC,GAAG,CAAC,GACV,SAAS,CAAC;AASd,eAAO,MAAM,iBAAiB,YACnB,OAAO,WACP,UAAU;;cACQ,MAAM;CAqDlC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.verifyAssumptions = exports.requestFromArgs = void 0;
|
|
14
|
+
const dynrpc_1 = require("../generated/proto/dynrpc");
|
|
15
|
+
const errors_1 = require("../types/errors");
|
|
16
|
+
const ASSUME_UNKEYED_SINCE_FIRST_PARAM_NOT_STRING = 1;
|
|
17
|
+
const ASSUME_UNKEYED_SINCE_ZERO_ARGS = 2;
|
|
18
|
+
const ASSUME_KEYED_SINCE_TWO_ARGS_STR_AND_ANY = 3;
|
|
19
|
+
const ASSUME_EITHER_KEYED_OR_UNKEYED_ONE_STR_ARG = 4;
|
|
20
|
+
const requestFromArgs = (args) => {
|
|
21
|
+
switch (args.length) {
|
|
22
|
+
case 0: {
|
|
23
|
+
return dynrpc_1.RpcRequest.create({
|
|
24
|
+
senderAssumes: ASSUME_UNKEYED_SINCE_ZERO_ARGS,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
case 1: {
|
|
28
|
+
if (typeof args[0] === "string") {
|
|
29
|
+
return dynrpc_1.RpcRequest.create({
|
|
30
|
+
key: args[0],
|
|
31
|
+
senderAssumes: ASSUME_EITHER_KEYED_OR_UNKEYED_ONE_STR_ARG,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return dynrpc_1.RpcRequest.create({
|
|
36
|
+
request: args[0],
|
|
37
|
+
senderAssumes: ASSUME_UNKEYED_SINCE_FIRST_PARAM_NOT_STRING,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
case 2: {
|
|
42
|
+
if (typeof args[0] !== "string") {
|
|
43
|
+
throw new errors_1.TerminalError(`Two argument handlers are only possible for keyed handlers. Where the first argument must be of type 'string'.`);
|
|
44
|
+
}
|
|
45
|
+
return dynrpc_1.RpcRequest.create({
|
|
46
|
+
key: args[0],
|
|
47
|
+
request: args[1],
|
|
48
|
+
senderAssumes: ASSUME_KEYED_SINCE_TWO_ARGS_STR_AND_ANY,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
default: {
|
|
52
|
+
throw new errors_1.TerminalError("wrong number of arguments " + args.length);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.requestFromArgs = requestFromArgs;
|
|
57
|
+
/* eslint-enable @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any */
|
|
58
|
+
const requireThat = (condition, errorMessage) => {
|
|
59
|
+
if (!condition) {
|
|
60
|
+
throw new errors_1.TerminalError(errorMessage);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const verifyAssumptions = (isKeyed, request) => {
|
|
64
|
+
const assumption = request.senderAssumes ?? 0;
|
|
65
|
+
switch (assumption) {
|
|
66
|
+
case 0: {
|
|
67
|
+
// no assumption: this comes from an ingress.
|
|
68
|
+
const hasKeyProperty = typeof request.key === "string" && request.key.length > 0;
|
|
69
|
+
if (isKeyed) {
|
|
70
|
+
requireThat(hasKeyProperty, "Trying to call a keyed handler with a missing or empty 'key' property.");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
requireThat(!hasKeyProperty, "Trying to call a an unkeyed handler with a 'key' property. Did you mean using the 'request' property instead?");
|
|
74
|
+
}
|
|
75
|
+
return { key: request.key, request: request.request };
|
|
76
|
+
}
|
|
77
|
+
case ASSUME_UNKEYED_SINCE_FIRST_PARAM_NOT_STRING: {
|
|
78
|
+
requireThat(!isKeyed, "Trying to call a keyed handler with a missing key. This could happen if the first argument passed is not a 'string'.");
|
|
79
|
+
return { request: request.request };
|
|
80
|
+
}
|
|
81
|
+
case ASSUME_UNKEYED_SINCE_ZERO_ARGS: {
|
|
82
|
+
requireThat(!isKeyed, "A keyed handler must at least be invoked with a single non empty string argument, that represents the key. 0 arguments given.");
|
|
83
|
+
return { request: request.request };
|
|
84
|
+
}
|
|
85
|
+
case ASSUME_KEYED_SINCE_TWO_ARGS_STR_AND_ANY: {
|
|
86
|
+
requireThat(isKeyed, "An unkeyed handler must have at most 1 argument. two given.");
|
|
87
|
+
return { key: request.key, request: request.request };
|
|
88
|
+
}
|
|
89
|
+
case ASSUME_EITHER_KEYED_OR_UNKEYED_ONE_STR_ARG: {
|
|
90
|
+
if (isKeyed) {
|
|
91
|
+
return { key: request.key };
|
|
92
|
+
}
|
|
93
|
+
return { request: request.key };
|
|
94
|
+
}
|
|
95
|
+
default: {
|
|
96
|
+
throw new errors_1.TerminalError(`Unknown assumption id ${assumption}. This indicates an incorrect (or involuntary) setting of the assumption property at the ingress request, or an SDK bug.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
exports.verifyAssumptions = verifyAssumptions;
|
|
101
|
+
//# sourceMappingURL=assumptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assumptions.js","sourceRoot":"","sources":["../../src/utils/assumptions.ts"],"names":[],"mapp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OAAO,EAAE,CAAC;SACvD;QACD,KAAK,0CAA0C,CAAC,CAAC;YAC/C,IAAI,OAAO,EAAE;gBACX,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;aAC7B;YACD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;SACjC;QACD,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,sBAAa,CACrB,yBAAyB,UAAU,0HAA0H,CAC9J,CAAC;SACH;KACF;AACH,CAAC,CAAC;AAxDW,QAAA,iBAAiB,qBAwD5B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LoggerContext } from "../logger";
|
|
3
|
+
/**
|
|
4
|
+
* The environment variable which is read to determine the debug log settings.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEBUG_LOGGING_ENV = "RESTATE_DEBUG_LOGGING";
|
|
7
|
+
/**
|
|
8
|
+
* The values for the {@link DEBUG_LOGGING_ENV} variable.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum RestateDebugLogLevel {
|
|
11
|
+
/** No debug logging at all. Good for performance and avoid per-invocation log volume */
|
|
12
|
+
OFF = 0,
|
|
13
|
+
/** Logs debug information for every Restate function invocation. */
|
|
14
|
+
INVOKE = 1,
|
|
15
|
+
/** Logs debug information for every Restate effect (=journal event) inside an invocation,
|
|
16
|
+
* like RPC, state access, sideEffect, ... */
|
|
17
|
+
JOURNAL = 2,
|
|
18
|
+
/** Logs debug information for every Restate effect (=journal event) inside an invocation,
|
|
19
|
+
* like RPC, state access, sideEffect, ... Additionally, this adds a JSON representation
|
|
20
|
+
* of the journal message to the log. */
|
|
21
|
+
JOURNAL_VERBOSE = 3
|
|
22
|
+
}
|
|
23
|
+
export type StateMachineConsole = Console & {
|
|
24
|
+
debugInvokeMessage: (msg: string) => void;
|
|
25
|
+
debugJournalMessage: (logMessage: string, messageType?: bigint, message?: any) => void;
|
|
26
|
+
};
|
|
27
|
+
export declare function createStateMachineConsole(context: LoggerContext): StateMachineConsole;
|
|
28
|
+
//# sourceMappingURL=message_logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_logger.d.ts","sourceRoot":"","sources":["../../src/utils/message_logger.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAwB,aAAa,EAAE,MAAM,WAAW,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,wFAAwF;IACxF,GAAG,IAAA;IAEH,oEAAoE;IACpE,MAAM,IAAA;IAEN;kDAC8C;IAC9C,OAAO,IAAA;IAEP;;6CAEyC;IACzC,eAAe,IAAA;CAChB;AA4BD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG;IAC1C,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C,mBAAmB,EAAE,CACnB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,GAAG,KACV,IAAI,CAAC;CACX,CAAC;AAEF,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,aAAa,GACrB,mBAAmB,CA8BrB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createStateMachineConsole = exports.RestateDebugLogLevel = exports.DEBUG_LOGGING_ENV = void 0;
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
15
|
+
/* eslint-disable no-console */
|
|
16
|
+
const protocol_1 = require("../types/protocol");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const logger_1 = require("../logger");
|
|
19
|
+
/**
|
|
20
|
+
* The environment variable which is read to determine the debug log settings.
|
|
21
|
+
*/
|
|
22
|
+
exports.DEBUG_LOGGING_ENV = "RESTATE_DEBUG_LOGGING";
|
|
23
|
+
/**
|
|
24
|
+
* The values for the {@link DEBUG_LOGGING_ENV} variable.
|
|
25
|
+
*/
|
|
26
|
+
var RestateDebugLogLevel;
|
|
27
|
+
(function (RestateDebugLogLevel) {
|
|
28
|
+
/** No debug logging at all. Good for performance and avoid per-invocation log volume */
|
|
29
|
+
RestateDebugLogLevel[RestateDebugLogLevel["OFF"] = 0] = "OFF";
|
|
30
|
+
/** Logs debug information for every Restate function invocation. */
|
|
31
|
+
RestateDebugLogLevel[RestateDebugLogLevel["INVOKE"] = 1] = "INVOKE";
|
|
32
|
+
/** Logs debug information for every Restate effect (=journal event) inside an invocation,
|
|
33
|
+
* like RPC, state access, sideEffect, ... */
|
|
34
|
+
RestateDebugLogLevel[RestateDebugLogLevel["JOURNAL"] = 2] = "JOURNAL";
|
|
35
|
+
/** Logs debug information for every Restate effect (=journal event) inside an invocation,
|
|
36
|
+
* like RPC, state access, sideEffect, ... Additionally, this adds a JSON representation
|
|
37
|
+
* of the journal message to the log. */
|
|
38
|
+
RestateDebugLogLevel[RestateDebugLogLevel["JOURNAL_VERBOSE"] = 3] = "JOURNAL_VERBOSE";
|
|
39
|
+
})(RestateDebugLogLevel = exports.RestateDebugLogLevel || (exports.RestateDebugLogLevel = {}));
|
|
40
|
+
const DEFAULT_DEBUG_LOG_LEVEL = process.env["NODE_ENV"]?.toUpperCase() === "PRODUCTION"
|
|
41
|
+
? RestateDebugLogLevel.OFF
|
|
42
|
+
: RestateDebugLogLevel.INVOKE;
|
|
43
|
+
function readLogLevel() {
|
|
44
|
+
const env = process.env[exports.DEBUG_LOGGING_ENV]?.toUpperCase();
|
|
45
|
+
if (env == undefined) {
|
|
46
|
+
return DEFAULT_DEBUG_LOG_LEVEL;
|
|
47
|
+
}
|
|
48
|
+
const idx = Object.keys(RestateDebugLogLevel)
|
|
49
|
+
.filter((t) =>
|
|
50
|
+
// Object.keys contains the numbers as well
|
|
51
|
+
// https://stackoverflow.com/questions/48768774/how-to-get-all-the-values-of-an-enum-with-typescript
|
|
52
|
+
isNaN(Number(t)))
|
|
53
|
+
.findIndex((level) => level == env);
|
|
54
|
+
if (idx < 0) {
|
|
55
|
+
return DEFAULT_DEBUG_LOG_LEVEL;
|
|
56
|
+
}
|
|
57
|
+
return idx;
|
|
58
|
+
}
|
|
59
|
+
const log_level = readLogLevel();
|
|
60
|
+
function createStateMachineConsole(context) {
|
|
61
|
+
const console = (0, logger_1.createRestateConsole)(context);
|
|
62
|
+
Object.defineProperties(console, {
|
|
63
|
+
debugInvokeMessage: {
|
|
64
|
+
value: (msg) => {
|
|
65
|
+
if (log_level >= RestateDebugLogLevel.INVOKE) {
|
|
66
|
+
console.debug(msg);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
debugJournalMessage: {
|
|
71
|
+
value: (logMessage, messageType, message) => {
|
|
72
|
+
if (log_level >= RestateDebugLogLevel.JOURNAL) {
|
|
73
|
+
const type = messageType !== undefined
|
|
74
|
+
? " ; " + (0, protocol_1.formatMessageType)(messageType)
|
|
75
|
+
: "";
|
|
76
|
+
const journalEvent = log_level >= RestateDebugLogLevel.JOURNAL_VERBOSE &&
|
|
77
|
+
message !== undefined
|
|
78
|
+
? " : " + (0, utils_1.formatMessageAsJson)(message)
|
|
79
|
+
: "";
|
|
80
|
+
console.debug(`${logMessage}${type}${journalEvent}`);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
return console;
|
|
86
|
+
}
|
|
87
|
+
exports.createStateMachineConsole = createStateMachineConsole;
|
|
88
|
+
//# sourceMappingURL=message_logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_logger.js","sourceRoot":"","sources":["../../src/utils/message_logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,uDAAuD;AACvD,+BAA+B;AAE/B,gDAAsD;AACtD,mCAA8C;AAC9C,sCAAgE;AAEhE;;GAEG;AACU,QAAA,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;GAEG;AACH,IAAY,oBAeX;AAfD,WAAY,oBAAoB;IAC9B,wFAAwF;IACxF,6DAAG,CAAA;IAEH,oEAAoE;IACpE,mEAAM,CAAA;IAEN;kDAC8C;IAC9C,qEAAO,CAAA;IAEP;;6CAEyC;IACzC,qFAAe,CAAA;AACjB,CAAC,EAfW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAe/B;AAED,MAAM,uBAAuB,GAC3B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,KAAK,YAAY;IACrD,CAAC,CAAC,oBAAoB,CAAC,GAAG;IAC1B,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC;AAElC,SAAS,YAAY;IACnB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1D,IAAI,GAAG,IAAI,SAAS,EAAE;QACpB,OAAO,uBAAuB,CAAC;KAChC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;SAC1C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;IACZ,2CAA2C;IAC3C,oGAAoG;IACpG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CACjB;SACA,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;IACtC,IAAI,GAAG,GAAG,CAAC,EAAE;QACX,OAAO,uBAAuB,CAAC;KAChC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;AAYjC,SAAgB,yBAAyB,CACvC,OAAsB;IAEtB,MAAM,OAAO,GAAG,IAAA,6BAAoB,EAAC,OAAO,CAAC,CAAC;IAE9C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE;QAC/B,kBAAkB,EAAE;YAClB,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE;gBACrB,IAAI,SAAS,IAAI,oBAAoB,CAAC,MAAM,EAAE;oBAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBACpB;YACH,CAAC;SACF;QACD,mBAAmB,EAAE;YACnB,KAAK,EAAE,CAAC,UAAkB,EAAE,WAAoB,EAAE,OAAa,EAAE,EAAE;gBACjE,IAAI,SAAS,IAAI,oBAAoB,CAAC,OAAO,EAAE;oBAC7C,MAAM,IAAI,GACR,WAAW,KAAK,SAAS;wBACvB,CAAC,CAAC,KAAK,GAAG,IAAA,4BAAiB,EAAC,WAAW,CAAC;wBACxC,CAAC,CAAC,EAAE,CAAC;oBACT,MAAM,YAAY,GAChB,SAAS,IAAI,oBAAoB,CAAC,eAAe;wBACjD,OAAO,KAAK,SAAS;wBACnB,CAAC,CAAC,KAAK,GAAG,IAAA,2BAAmB,EAAC,OAAO,CAAC;wBACtC,CAAC,CAAC,EAAE,CAAC;oBACT,OAAO,CAAC,KAAK,CAAC,GAAG,UAAU,GAAG,IAAI,GAAG,YAAY,EAAE,CAAC,CAAC;iBACtD;YACH,CAAC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,OAA8B,CAAC;AACxC,CAAC;AAhCD,8DAgCC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type WrappedPromise<T> = Promise<T> & {
|
|
2
|
+
transform: <TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => WrappedPromise<TResult1 | TResult2>;
|
|
3
|
+
};
|
|
4
|
+
export declare function wrapDeeply<T>(promise: Promise<T>, onThen?: () => void): WrappedPromise<T>;
|
|
5
|
+
export declare class CompletablePromise<T> {
|
|
6
|
+
private success;
|
|
7
|
+
private failure;
|
|
8
|
+
readonly promise: Promise<T>;
|
|
9
|
+
constructor();
|
|
10
|
+
resolve(value: T): void;
|
|
11
|
+
reject(reason?: any): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const PROMISE_PENDING: Promise<any>;
|
|
14
|
+
export declare const WRAPPED_PROMISE_PENDING: Promise<any>;
|
|
15
|
+
//# sourceMappingURL=promises.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/utils/promises.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG;IAG3C,SAAS,EAAE,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EACxC,WAAW,CAAC,EACR,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAChD,IAAI,GACJ,SAAS,EACb,UAAU,CAAC,EACP,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GACnD,IAAI,GACJ,SAAS,KACV,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,EAC1B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,cAAc,CAAC,CAAC,CAAC,CAuDnB;AAID,qBAAa,kBAAkB,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,OAAO,CAA0B;IAEzC,SAAgB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;;IAS7B,OAAO,CAAC,KAAK,EAAE,CAAC;IAIhB,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG;CAG3B;AAID,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,GAAG,CAA8B,CAAC;AACxE,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAAC,GAAG,CACpB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.WRAPPED_PROMISE_PENDING = exports.PROMISE_PENDING = exports.CompletablePromise = exports.wrapDeeply = void 0;
|
|
14
|
+
function wrapDeeply(promise, onThen) {
|
|
15
|
+
// We need this to support nesting of WrappedPromise
|
|
16
|
+
let transform;
|
|
17
|
+
if (Object.hasOwn(promise, "transform")) {
|
|
18
|
+
const wrappedPromise = promise;
|
|
19
|
+
transform = (onfulfilled, onrejected) => wrapDeeply(wrappedPromise.transform(onfulfilled, onrejected), onThen);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
transform = (onfulfilled, onrejected) => wrapDeeply(promise.then(onfulfilled, onrejected), onThen);
|
|
23
|
+
}
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
|
+
return {
|
|
26
|
+
transform,
|
|
27
|
+
then: function (onfulfilled, onrejected) {
|
|
28
|
+
if (onThen !== undefined) {
|
|
29
|
+
onThen();
|
|
30
|
+
}
|
|
31
|
+
return promise.then(onfulfilled, onrejected);
|
|
32
|
+
},
|
|
33
|
+
catch: function (onrejected) {
|
|
34
|
+
return wrapDeeply(promise.catch(onrejected), onThen);
|
|
35
|
+
},
|
|
36
|
+
finally: function (onfinally) {
|
|
37
|
+
return wrapDeeply(promise.finally(onfinally), onThen);
|
|
38
|
+
},
|
|
39
|
+
[Symbol.toStringTag]: "",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.wrapDeeply = wrapDeeply;
|
|
43
|
+
// Like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
44
|
+
// (not yet available in node)
|
|
45
|
+
class CompletablePromise {
|
|
46
|
+
success;
|
|
47
|
+
failure;
|
|
48
|
+
promise;
|
|
49
|
+
constructor() {
|
|
50
|
+
this.promise = new Promise((resolve, reject) => {
|
|
51
|
+
this.success = resolve;
|
|
52
|
+
this.failure = reject;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
resolve(value) {
|
|
56
|
+
this.success(value);
|
|
57
|
+
}
|
|
58
|
+
reject(reason) {
|
|
59
|
+
this.failure(reason);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CompletablePromise = CompletablePromise;
|
|
63
|
+
// A promise that is never completed
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
65
|
+
exports.PROMISE_PENDING = new Promise(() => { });
|
|
66
|
+
exports.WRAPPED_PROMISE_PENDING = wrapDeeply(exports.PROMISE_PENDING);
|
|
67
|
+
//# sourceMappingURL=promises.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../../src/utils/promises.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAoBH,SAAgB,UAAU,CACxB,OAAmB,EACnB,MAAmB;IAEnB,oDAAoD;I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