@restatedev/restate-sdk-core 1.17.2 → 1.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/interface.js CHANGED
@@ -1,85 +1,79 @@
1
- /*
2
- * Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH
3
- *
4
- * This file is part of the Restate SDK for Node.js/TypeScript,
5
- * which is released under the MIT license.
6
- *
7
- * You can find a copy of the license in file LICENSE in the root
8
- * directory of this repository or package, or at
9
- * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
10
- */
11
- /* eslint-disable @typescript-eslint/no-explicit-any */
12
1
  import { serde } from "./serde_api.js";
13
- export function makeHandlerDescriptor(inputSerde, outputSerde, shared, opts) {
14
- return {
15
- _inputSerde: inputSerde,
16
- _outputSerde: outputSerde,
17
- _shared: shared,
18
- _description: opts?.description,
19
- _metadata: opts?.metadata,
20
- };
2
+
3
+ //#region src/interface.ts
4
+ function makeHandlerDescriptor(inputSerde, outputSerde, shared, opts) {
5
+ return {
6
+ _inputSerde: inputSerde,
7
+ _outputSerde: outputSerde,
8
+ _shared: shared,
9
+ _description: opts?.description,
10
+ _metadata: opts?.metadata
11
+ };
21
12
  }
22
13
  /**
23
- * Declare a service interface (contract) as a runtime value carrying handler
24
- * names + input/output serdes, without an implementation. Place it in a shared
25
- * package that both the server (via `implement()`) and callers (via
26
- * `ctx.serviceClient(iface)` / `connect().serviceClient(iface)`) import.
27
- *
28
- * @example
29
- * ```ts
30
- * const greeter = iface.service("greeter", {
31
- * greet: iface.schemas({ input: GreetReq, output: GreetRes }),
32
- * ping: iface.json<void, string>(),
33
- * });
34
- * ```
35
- */
36
- export const iface = {
37
- service: function (name, handlers, opts) {
38
- return {
39
- name,
40
- _kind: "service",
41
- _handlers: handlers,
42
- _description: opts?.description,
43
- _metadata: opts?.metadata,
44
- };
45
- },
46
- object: function (name, handlers, opts) {
47
- return {
48
- name,
49
- _kind: "object",
50
- _handlers: handlers,
51
- _description: opts?.description,
52
- _metadata: opts?.metadata,
53
- };
54
- },
55
- workflow: function (name, handlers, opts) {
56
- return {
57
- name,
58
- _kind: "workflow",
59
- _handlers: handlers,
60
- _description: opts?.description,
61
- _metadata: opts?.metadata,
62
- };
63
- },
64
- json: function (opts) {
65
- return makeHandlerDescriptor(undefined, undefined, false, opts);
66
- },
67
- serdes: function (opts) {
68
- return makeHandlerDescriptor(opts.input, opts.output, false, opts);
69
- },
70
- schemas: function (opts) {
71
- return makeHandlerDescriptor(opts.input ? serde.schema(opts.input) : undefined, opts.output ? serde.schema(opts.output) : undefined, false, opts);
72
- },
73
- shared: {
74
- json: function (opts) {
75
- return makeHandlerDescriptor(undefined, undefined, true, opts);
76
- },
77
- serdes: function (opts) {
78
- return makeHandlerDescriptor(opts.input, opts.output, true, opts);
79
- },
80
- schemas: function (opts) {
81
- return makeHandlerDescriptor(opts.input ? serde.schema(opts.input) : undefined, opts.output ? serde.schema(opts.output) : undefined, true, opts);
82
- },
83
- },
14
+ * Declare a service interface (contract) as a runtime value carrying handler
15
+ * names + input/output serdes, without an implementation. Place it in a shared
16
+ * package that both the server (via `implement()`) and callers (via
17
+ * `ctx.serviceClient(iface)` / `connect().serviceClient(iface)`) import.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const greeter = iface.service("greeter", {
22
+ * greet: iface.schemas({ input: GreetReq, output: GreetRes }),
23
+ * ping: iface.json<void, string>(),
24
+ * });
25
+ * ```
26
+ */
27
+ const iface = {
28
+ service: function(name, handlers, opts) {
29
+ return {
30
+ name,
31
+ _kind: "service",
32
+ _handlers: handlers,
33
+ _description: opts?.description,
34
+ _metadata: opts?.metadata
35
+ };
36
+ },
37
+ object: function(name, handlers, opts) {
38
+ return {
39
+ name,
40
+ _kind: "object",
41
+ _handlers: handlers,
42
+ _description: opts?.description,
43
+ _metadata: opts?.metadata
44
+ };
45
+ },
46
+ workflow: function(name, handlers, opts) {
47
+ return {
48
+ name,
49
+ _kind: "workflow",
50
+ _handlers: handlers,
51
+ _description: opts?.description,
52
+ _metadata: opts?.metadata
53
+ };
54
+ },
55
+ json: function(opts) {
56
+ return makeHandlerDescriptor(void 0, void 0, false, opts);
57
+ },
58
+ serdes: function(opts) {
59
+ return makeHandlerDescriptor(opts.input, opts.output, false, opts);
60
+ },
61
+ schemas: function(opts) {
62
+ return makeHandlerDescriptor(opts.input ? serde.schema(opts.input) : void 0, opts.output ? serde.schema(opts.output) : void 0, false, opts);
63
+ },
64
+ shared: {
65
+ json: function(opts) {
66
+ return makeHandlerDescriptor(void 0, void 0, true, opts);
67
+ },
68
+ serdes: function(opts) {
69
+ return makeHandlerDescriptor(opts.input, opts.output, true, opts);
70
+ },
71
+ schemas: function(opts) {
72
+ return makeHandlerDescriptor(opts.input ? serde.schema(opts.input) : void 0, opts.output ? serde.schema(opts.output) : void 0, true, opts);
73
+ }
74
+ }
84
75
  };
76
+
77
+ //#endregion
78
+ export { iface, makeHandlerDescriptor };
85
79
  //# sourceMappingURL=interface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,uDAAuD;AAGvD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AA6CvC,MAAM,UAAU,qBAAqB,CACnC,UAAqB,EACrB,WAAsB,EACtB,MAAe,EACf,IAAqB;IAErB,OAAO;QACL,WAAW,EAAE,UAAU;QACvB,YAAY,EAAE,WAAW;QACzB,OAAO,EAAE,MAAM;QACf,YAAY,EAAE,IAAI,EAAE,WAAW;QAC/B,SAAS,EAAE,IAAI,EAAE,QAAQ;KAC1B,CAAC;AACJ,CAAC;AAyJD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,KAAK,GAAqB;IACrC,OAAO,EAAE,UAGP,IAAO,EAAE,QAAW,EAAE,IAAqB;QAC3C,OAAO;YACL,IAAI;YACJ,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,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EACT,SAAS,EACT,IAAI,EACJ,IAAI,CACL,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,UACN,IAGkB;YAElB,OAAO,qBAAqB,CAC1B,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,IAAI,EACJ,IAAI,CACL,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,UAIP,IAGkB;YAMlB,OAAO,qBAAqB,CAC1B,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EACjD,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,EACnD,IAAI,EACJ,IAAI,CACL,CAAC;QACJ,CAAC;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"interface.js","names":["iface: ServiceInterface"],"sources":["../src/interface.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2026 - 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/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Serde } from \"./serde_api.js\";\nimport { serde } from \"./serde_api.js\";\nimport type { StandardSchemaV1 } from \"./standard_schema.js\";\nimport type {\n ServiceDefinition,\n VirtualObjectDefinition,\n WorkflowDefinition,\n} from \"./core.js\";\n\n/**\n * Documentation and metadata that can be attached to a service/object/workflow\n * contract or to a single handler declared with {@link iface}.\n *\n * These values are advisory: they are folded into the service definition when the\n * contract is implemented (see `implement()`), and surface in the discovery manifest\n * as `documentation` (from {@link description}) and `metadata`.\n */\nexport type DescriptorOpts = {\n /**\n * Human-readable description, shown in documentation/admin tools.\n */\n description?: string;\n /**\n * Arbitrary key/value metadata, exposed via the Admin API.\n */\n metadata?: Record<string, string>;\n};\n\n/**\n * Minimal descriptor stored in {@link Descriptor}._handlers per handler.\n */\nexport type HandlerDescriptor<\n I = any,\n O = any,\n Shared extends boolean = boolean,\n> = {\n readonly _inputSerde?: Serde<I>;\n readonly _outputSerde?: Serde<O>;\n /** @internal virtual-object handler shared/exclusive marker (phantom + runtime) */\n readonly _shared?: Shared;\n /** @internal handler description declared on the contract */\n readonly _description?: string;\n /** @internal handler metadata declared on the contract */\n readonly _metadata?: Record<string, string>;\n};\n\nexport function makeHandlerDescriptor<I, O, Shared extends boolean = false>(\n inputSerde?: Serde<I>,\n outputSerde?: Serde<O>,\n shared?: Shared,\n opts?: DescriptorOpts\n): HandlerDescriptor<I, O, Shared> {\n return {\n _inputSerde: inputSerde,\n _outputSerde: outputSerde,\n _shared: shared,\n _description: opts?.description,\n _metadata: opts?.metadata,\n };\n}\n\n/** Recover the input type declared by a {@link HandlerDescriptor}. */\nexport type InferInput<D> =\n D extends HandlerDescriptor<infer I, any, any> ? I : any;\n/** Recover the output type declared by a {@link HandlerDescriptor}. */\nexport type InferOutput<D> =\n D extends HandlerDescriptor<any, infer O, any> ? O : any;\n/** Recover the value type carried by a {@link Serde}. */\nexport type SerdeType<S> = S extends Serde<infer T> ? T : never;\n\n// =============================================================================\n// Descriptor — the client-facing definition value carrying `_handlers`.\n//\n// - `iface.service/object/workflow(...)` return a pure Descriptor (no fn), safe\n// to place in a shared package imported by both server and callers.\n// - the SDKs' `implement()` / `service()` factories return an\n// `Implemented*Definition`, which is a Descriptor that is ALSO bindable.\n// =============================================================================\n\nexport type Descriptor<\n P extends string = string,\n H extends Record<string, HandlerDescriptor> = Record<\n string,\n HandlerDescriptor\n >,\n Kind extends \"service\" | \"object\" | \"workflow\" =\n | \"service\"\n | \"object\"\n | \"workflow\",\n> = {\n readonly name: P;\n readonly _kind: Kind;\n readonly _handlers: H;\n /** @internal service description declared on the contract */\n readonly _description?: string;\n /** @internal service metadata declared on the contract */\n readonly _metadata?: Record<string, string>;\n};\n\nexport type ServiceDescriptor<\n P extends string = string,\n H extends Record<string, HandlerDescriptor> = Record<\n string,\n HandlerDescriptor\n >,\n> = Descriptor<P, H, \"service\">;\n\nexport type ObjectDescriptor<\n P extends string = string,\n H extends Record<string, HandlerDescriptor> = Record<\n string,\n HandlerDescriptor\n >,\n> = Descriptor<P, H, \"object\">;\n\nexport type WorkflowDescriptor<\n P extends string = string,\n H extends Record<string, HandlerDescriptor> = Record<\n string,\n HandlerDescriptor\n >,\n> = Descriptor<P, H, \"workflow\">;\n\n/** Implemented definition — a Descriptor that is also bindable to an endpoint. */\nexport type ImplementedServiceDefinition<\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n> = ServiceDefinition<P, any> & ServiceDescriptor<P, H>;\n\nexport type ImplementedObjectDefinition<\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n> = VirtualObjectDefinition<P, any> & ObjectDescriptor<P, H>;\n\nexport type ImplementedWorkflowDefinition<\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n> = WorkflowDefinition<P, any> & WorkflowDescriptor<P, H>;\n\nexport type ImplementedDefinition<\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n Kind extends \"service\" | \"object\" | \"workflow\",\n> = Kind extends \"service\"\n ? ImplementedServiceDefinition<P, H>\n : Kind extends \"object\"\n ? ImplementedObjectDefinition<P, H>\n : ImplementedWorkflowDefinition<P, H>;\n\n/** The shape of the {@link iface} service-interface declaration API. */\nexport interface ServiceInterface {\n service<P extends string, H extends Record<string, HandlerDescriptor>>(\n name: P,\n handlers: H,\n opts?: DescriptorOpts\n ): ServiceDescriptor<P, H>;\n object<P extends string, H extends Record<string, HandlerDescriptor>>(\n name: P,\n handlers: H,\n opts?: DescriptorOpts\n ): ObjectDescriptor<P, H>;\n workflow<P extends string, H extends Record<string, HandlerDescriptor>>(\n name: P,\n handlers: H,\n opts?: DescriptorOpts\n ): WorkflowDescriptor<P, H>;\n /** `json<I, O>()` — type params, default JSON serde. */\n json<I = void, O = void>(\n opts?: DescriptorOpts\n ): HandlerDescriptor<I, O, false>;\n /** `serdes({ input, output })` — explicit Serde per direction. */\n serdes<SI extends Serde<any>, SO extends Serde<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<SerdeType<SI>, SerdeType<SO>, false>;\n /** `schemas({ input, output })` — Standard Schema per direction. */\n schemas<SI extends StandardSchemaV1<any>, SO extends StandardSchemaV1<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<\n StandardSchemaV1.InferOutput<NonNullable<SI>>,\n StandardSchemaV1.InferOutput<NonNullable<SO>>,\n false\n >;\n /** Shared (read-only) virtual-object / non-`run` workflow handler declarators. */\n shared: {\n json<I = void, O = void>(\n opts?: DescriptorOpts\n ): HandlerDescriptor<I, O, true>;\n serdes<SI extends Serde<any>, SO extends Serde<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<SerdeType<SI>, SerdeType<SO>, true>;\n schemas<SI extends StandardSchemaV1<any>, SO extends StandardSchemaV1<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<\n StandardSchemaV1.InferOutput<NonNullable<SI>>,\n StandardSchemaV1.InferOutput<NonNullable<SO>>,\n true\n >;\n };\n}\n\n/**\n * Declare a service interface (contract) as a runtime value carrying handler\n * names + input/output serdes, without an implementation. Place it in a shared\n * package that both the server (via `implement()`) and callers (via\n * `ctx.serviceClient(iface)` / `connect().serviceClient(iface)`) import.\n *\n * @example\n * ```ts\n * const greeter = iface.service(\"greeter\", {\n * greet: iface.schemas({ input: GreetReq, output: GreetRes }),\n * ping: iface.json<void, string>(),\n * });\n * ```\n */\nexport const iface: ServiceInterface = {\n service: function <\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n >(name: P, handlers: H, opts?: DescriptorOpts): ServiceDescriptor<P, H> {\n return {\n name,\n _kind: \"service\",\n _handlers: handlers,\n _description: opts?.description,\n _metadata: opts?.metadata,\n };\n },\n object: function <\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n >(name: P, handlers: H, opts?: DescriptorOpts): ObjectDescriptor<P, H> {\n return {\n name,\n _kind: \"object\",\n _handlers: handlers,\n _description: opts?.description,\n _metadata: opts?.metadata,\n };\n },\n workflow: function <\n P extends string,\n H extends Record<string, HandlerDescriptor>,\n >(name: P, handlers: H, opts?: DescriptorOpts): WorkflowDescriptor<P, H> {\n return {\n name,\n _kind: \"workflow\",\n _handlers: handlers,\n _description: opts?.description,\n _metadata: opts?.metadata,\n };\n },\n json: function <I = void, O = void>(\n opts?: DescriptorOpts\n ): HandlerDescriptor<I, O, false> {\n return makeHandlerDescriptor<I, O, false>(\n undefined,\n undefined,\n false,\n opts\n );\n },\n serdes: function <SI extends Serde<any>, SO extends Serde<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<SerdeType<SI>, SerdeType<SO>, false> {\n return makeHandlerDescriptor<any, any, false>(\n opts.input,\n opts.output,\n false,\n opts\n );\n },\n schemas: function <\n SI extends StandardSchemaV1<any>,\n SO extends StandardSchemaV1<any>,\n >(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<\n StandardSchemaV1.InferOutput<NonNullable<SI>>,\n StandardSchemaV1.InferOutput<NonNullable<SO>>,\n false\n > {\n return makeHandlerDescriptor<any, any, false>(\n opts.input ? serde.schema(opts.input) : undefined,\n opts.output ? serde.schema(opts.output) : undefined,\n false,\n opts\n );\n },\n shared: {\n json: function <I = void, O = void>(\n opts?: DescriptorOpts\n ): HandlerDescriptor<I, O, true> {\n return makeHandlerDescriptor<I, O, true>(\n undefined,\n undefined,\n true,\n opts\n );\n },\n serdes: function <SI extends Serde<any>, SO extends Serde<any>>(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<SerdeType<SI>, SerdeType<SO>, true> {\n return makeHandlerDescriptor<any, any, true>(\n opts.input,\n opts.output,\n true,\n opts\n );\n },\n schemas: function <\n SI extends StandardSchemaV1<any>,\n SO extends StandardSchemaV1<any>,\n >(\n opts: {\n input?: SI;\n output?: SO;\n } & DescriptorOpts\n ): HandlerDescriptor<\n StandardSchemaV1.InferOutput<NonNullable<SI>>,\n StandardSchemaV1.InferOutput<NonNullable<SO>>,\n true\n > {\n return makeHandlerDescriptor<any, any, true>(\n opts.input ? serde.schema(opts.input) : undefined,\n opts.output ? serde.schema(opts.output) : undefined,\n true,\n opts\n );\n },\n },\n};\n"],"mappings":";;;AA0DA,SAAgB,sBACd,YACA,aACA,QACA,MACiC;AACjC,QAAO;EACL,aAAa;EACb,cAAc;EACd,SAAS;EACT,cAAc,MAAM;EACpB,WAAW,MAAM;EAClB;;;;;;;;;;;;;;;;AAwKH,MAAaA,QAA0B;CACrC,SAAS,SAGP,MAAS,UAAa,MAAgD;AACtE,SAAO;GACL;GACA,OAAO;GACP,WAAW;GACX,cAAc,MAAM;GACpB,WAAW,MAAM;GAClB;;CAEH,QAAQ,SAGN,MAAS,UAAa,MAA+C;AACrE,SAAO;GACL;GACA,OAAO;GACP,WAAW;GACX,cAAc,MAAM;GACpB,WAAW,MAAM;GAClB;;CAEH,UAAU,SAGR,MAAS,UAAa,MAAiD;AACvE,SAAO;GACL;GACA,OAAO;GACP,WAAW;GACX,cAAc,MAAM;GACpB,WAAW,MAAM;GAClB;;CAEH,MAAM,SACJ,MACgC;AAChC,SAAO,sBACL,QACA,QACA,OACA,KACD;;CAEH,QAAQ,SACN,MAIwD;AACxD,SAAO,sBACL,KAAK,OACL,KAAK,QACL,OACA,KACD;;CAEH,SAAS,SAIP,MAQA;AACA,SAAO,sBACL,KAAK,QAAQ,MAAM,OAAO,KAAK,MAAM,GAAG,QACxC,KAAK,SAAS,MAAM,OAAO,KAAK,OAAO,GAAG,QAC1C,OACA,KACD;;CAEH,QAAQ;EACN,MAAM,SACJ,MAC+B;AAC/B,UAAO,sBACL,QACA,QACA,MACA,KACD;;EAEH,QAAQ,SACN,MAIuD;AACvD,UAAO,sBACL,KAAK,OACL,KAAK,QACL,MACA,KACD;;EAEH,SAAS,SAIP,MAQA;AACA,UAAO,sBACL,KAAK,QAAQ,MAAM,OAAO,KAAK,MAAM,GAAG,QACxC,KAAK,SAAS,MAAM,OAAO,KAAK,OAAO,GAAG,QAC1C,MACA,KACD;;EAEJ;CACF"}
@@ -1,4 +1,7 @@
1
- import type { StandardSchemaV1 } from "./standard_schema.js";
1
+ import { StandardSchemaV1 } from "./standard_schema.js";
2
+
3
+ //#region src/serde_api.d.ts
4
+
2
5
  /**
3
6
  * Serializer/deserializer pair for any Restate-managed value of type `T` —
4
7
  * handler inputs and outputs, service state, side-effect results,
@@ -16,116 +19,118 @@ import type { StandardSchemaV1 } from "./standard_schema.js";
16
19
  * It also advertises metadata (`contentType`, `jsonSchema`) that surfaces in
17
20
  * service discovery.
18
21
  */
19
- export interface Serde<T> {
22
+ interface Serde<T> {
23
+ /**
24
+ * MIME type of the bytes produced by `serialize` (and accepted by
25
+ * `deserialize`).
26
+ */
27
+ contentType?: string;
28
+ /**
29
+ * Optional JSON Schema describing the logical shape of `T`. Surfaced in
30
+ * discovery so that tooling can generate forms, auto-complete payloads,
31
+ * etc. Has no effect on serialization at runtime.
32
+ */
33
+ jsonSchema?: object;
34
+ /**
35
+ * Optional bridge between the serde's wire format and a JSON
36
+ * representation that humans (and tooling like the Restate UI) can read
37
+ * and edit.
38
+ *
39
+ * Only useful for serdes whose wire format isn't already plain JSON —
40
+ * protobuf, MessagePack, length-prefixed binary, JSON variants that need
41
+ * post-processing for bigints/dates, etc. Both methods may be async if the
42
+ * conversion needs I/O.
43
+ *
44
+ * ### Preview flow
45
+ *
46
+ * Together with `serialize` / `deserialize`, the four functions chain in
47
+ * both directions between a JSON string and on-the-wire bytes:
48
+ *
49
+ * ```text
50
+ * JSON string ──fromJsonString──► T ──serialize──► wire bytes
51
+ * wire bytes ──deserialize────► T ──toJsonString──► JSON string
52
+ * ```
53
+ *
54
+ * The split keeps `serialize` / `deserialize` responsible for the full
55
+ * on-the-wire format; `preview` only handles the JSON ↔ `T` bridge.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Wire format is protobuf; the protobuf-es runtime already ships
60
+ * // `toJsonString` / `fromJsonString`, so preview is a direct pass-through.
61
+ * import {
62
+ * fromBinary,
63
+ * fromJsonString,
64
+ * toBinary,
65
+ * toJsonString,
66
+ * } from "@bufbuild/protobuf";
67
+ * import { PersonSchema, type Person } from "./person_pb.js";
68
+ *
69
+ * const personSerde: Serde<Person> = {
70
+ * contentType: "application/protobuf",
71
+ * serialize(message) { return toBinary(PersonSchema, message); },
72
+ * deserialize(bytes) { return fromBinary(PersonSchema, bytes); },
73
+ * preview: {
74
+ * toJsonString: (v) => toJsonString(PersonSchema, v),
75
+ * fromJsonString: (j) => fromJsonString(PersonSchema, j),
76
+ * },
77
+ * };
78
+ * ```
79
+ */
80
+ preview?: {
20
81
  /**
21
- * MIME type of the bytes produced by `serialize` (and accepted by
22
- * `deserialize`).
82
+ * Convert a value into a JSON string for display or editing by humans.
83
+ * The returned string must round-trip through `fromJsonString` back to
84
+ * the same logical value.
23
85
  */
24
- contentType?: string;
86
+ toJsonString(value: T): Promise<string> | string;
25
87
  /**
26
- * Optional JSON Schema describing the logical shape of `T`. Surfaced in
27
- * discovery so that tooling can generate forms, auto-complete payloads,
28
- * etc. Has no effect on serialization at runtime.
29
- */
30
- jsonSchema?: object;
31
- /**
32
- * Optional bridge between the serde's wire format and a JSON
33
- * representation that humans (and tooling like the Restate UI) can read
34
- * and edit.
35
- *
36
- * Only useful for serdes whose wire format isn't already plain JSON —
37
- * protobuf, MessagePack, length-prefixed binary, JSON variants that need
38
- * post-processing for bigints/dates, etc. Both methods may be async if the
39
- * conversion needs I/O.
40
- *
41
- * ### Preview flow
42
- *
43
- * Together with `serialize` / `deserialize`, the four functions chain in
44
- * both directions between a JSON string and on-the-wire bytes:
45
- *
46
- * ```text
47
- * JSON string ──fromJsonString──► T ──serialize──► wire bytes
48
- * wire bytes ──deserialize────► T ──toJsonString──► JSON string
49
- * ```
50
- *
51
- * The split keeps `serialize` / `deserialize` responsible for the full
52
- * on-the-wire format; `preview` only handles the JSON ↔ `T` bridge.
53
- *
54
- * @example
55
- * ```ts
56
- * // Wire format is protobuf; the protobuf-es runtime already ships
57
- * // `toJsonString` / `fromJsonString`, so preview is a direct pass-through.
58
- * import {
59
- * fromBinary,
60
- * fromJsonString,
61
- * toBinary,
62
- * toJsonString,
63
- * } from "@bufbuild/protobuf";
64
- * import { PersonSchema, type Person } from "./person_pb.js";
65
- *
66
- * const personSerde: Serde<Person> = {
67
- * contentType: "application/protobuf",
68
- * serialize(message) { return toBinary(PersonSchema, message); },
69
- * deserialize(bytes) { return fromBinary(PersonSchema, bytes); },
70
- * preview: {
71
- * toJsonString: (v) => toJsonString(PersonSchema, v),
72
- * fromJsonString: (j) => fromJsonString(PersonSchema, j),
73
- * },
74
- * };
75
- * ```
76
- */
77
- preview?: {
78
- /**
79
- * Convert a value into a JSON string for display or editing by humans.
80
- * The returned string must round-trip through `fromJsonString` back to
81
- * the same logical value.
82
- */
83
- toJsonString(value: T): Promise<string> | string;
84
- /**
85
- * Parse a human-supplied JSON string back into a value of type `T`.
86
- * Should throw (or reject) if `json` is invalid for this serde.
87
- */
88
- fromJsonString(json: string): Promise<T> | T;
89
- };
90
- /**
91
- * Convert a value of type `T` into its on-the-wire bytes. This is the
92
- * format Restate sends between services and persists in the journal.
93
- *
94
- * Must be the inverse of `deserialize` — `deserialize(serialize(v))`
95
- * should produce a value equivalent to `v`.
88
+ * Parse a human-supplied JSON string back into a value of type `T`.
89
+ * Should throw (or reject) if `json` is invalid for this serde.
96
90
  */
91
+ fromJsonString(json: string): Promise<T> | T;
92
+ };
93
+ /**
94
+ * Convert a value of type `T` into its on-the-wire bytes. This is the
95
+ * format Restate sends between services and persists in the journal.
96
+ *
97
+ * Must be the inverse of `deserialize` — `deserialize(serialize(v))`
98
+ * should produce a value equivalent to `v`.
99
+ */
100
+ serialize(value: T): Uint8Array;
101
+ /**
102
+ * Convert on-the-wire bytes back into a value of type `T`. Must be the
103
+ * inverse of `serialize`.
104
+ *
105
+ * May throw if `data` doesn't conform to the expected wire format.
106
+ */
107
+ deserialize(data: Uint8Array): T;
108
+ }
109
+ declare namespace serde {
110
+ class JsonSerde<T> implements Serde<T> {
111
+ readonly jsonSchema?: object | undefined;
112
+ contentType: string;
113
+ constructor(jsonSchema?: object | undefined);
97
114
  serialize(value: T): Uint8Array;
98
- /**
99
- * Convert on-the-wire bytes back into a value of type `T`. Must be the
100
- * inverse of `serialize`.
101
- *
102
- * May throw if `data` doesn't conform to the expected wire format.
103
- */
104
115
  deserialize(data: Uint8Array): T;
116
+ /** @deprecated **/
117
+ schema<U>(schema: object): Serde<U>;
118
+ }
119
+ const json: JsonSerde<any>;
120
+ const binary: Serde<Uint8Array>;
121
+ const empty: Serde<void>;
122
+ /**
123
+ * A Standard Schema-based serde.
124
+ *
125
+ * @param schema the standard schema
126
+ * @param validateOptions options passed to `StandardSchemaV1.Options.libraryOptions` when validating
127
+ * @param jsonSchemaOptions options passed to `StandardJsonSchemaV1.Options.libraryOptions` for code generation
128
+ * @returns a serde that will validate the data with the standard schema
129
+ */
130
+ const schema: <T extends {
131
+ "~standard": StandardSchemaV1.Props;
132
+ }>(schema: T, validateOptions?: Record<string, unknown>, jsonSchemaOptions?: Record<string, unknown>) => Serde<StandardSchemaV1.InferOutput<T>>;
105
133
  }
106
- export declare namespace serde {
107
- class JsonSerde<T> implements Serde<T> {
108
- readonly jsonSchema?: object | undefined;
109
- contentType: string;
110
- constructor(jsonSchema?: object | undefined);
111
- serialize(value: T): Uint8Array;
112
- deserialize(data: Uint8Array): T;
113
- /** @deprecated **/
114
- schema<U>(schema: object): Serde<U>;
115
- }
116
- const json: JsonSerde<any>;
117
- const binary: Serde<Uint8Array>;
118
- const empty: Serde<void>;
119
- /**
120
- * A Standard Schema-based serde.
121
- *
122
- * @param schema the standard schema
123
- * @param validateOptions options passed to `StandardSchemaV1.Options.libraryOptions` when validating
124
- * @param jsonSchemaOptions options passed to `StandardJsonSchemaV1.Options.libraryOptions` for code generation
125
- * @returns a serde that will validate the data with the standard schema
126
- */
127
- const schema: <T extends {
128
- "~standard": StandardSchemaV1.Props;
129
- }>(schema: T, validateOptions?: Record<string, unknown>, jsonSchemaOptions?: Record<string, unknown>) => Serde<StandardSchemaV1.InferOutput<T>>;
130
- }
134
+ //#endregion
135
+ export { Serde, serde };
131
136
  //# sourceMappingURL=serde_api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serde_api.d.ts","sourceRoot":"","sources":["../src/serde_api.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;QAEjD;;;WAGG;QACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;KAC9C,CAAC;IAEF;;;;;;OAMG;IACH,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC;IAEhC;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,CAAC;CAClC;AAsID,yBAAiB,KAAK,CAAC;IACrB,MAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK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