@restatedev/restate-sdk-core 1.12.0 → 1.14.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/core.d.ts +29 -27
- package/dist/core.d.ts.map +1 -1
- package/dist/duration.d.ts +8 -11
- package/dist/duration.d.ts.map +1 -1
- package/dist/duration.js +23 -9
- package/dist/duration.js.map +1 -1
- package/dist/entry_codec.d.ts +19 -22
- package/dist/entry_codec.d.ts.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +13 -4
- package/dist/serde_api.d.cts +99 -0
- package/dist/serde_api.d.cts.map +1 -1
- package/dist/serde_api.d.ts +127 -33
- package/dist/serde_api.d.ts.map +1 -1
- package/dist/serde_api.js +151 -87
- package/dist/serde_api.js.map +1 -1
- package/dist/standard_schema.d.ts +108 -109
- package/dist/standard_schema.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
interface RestateObjectContext {
|
|
4
|
-
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export interface RestateContext {
|
|
2
|
+
}
|
|
3
|
+
export interface RestateObjectContext {
|
|
4
|
+
}
|
|
5
|
+
export interface RestateObjectSharedContext {
|
|
6
|
+
}
|
|
7
|
+
export interface RestateWorkflowSharedContext extends RestateObjectSharedContext {
|
|
8
|
+
}
|
|
9
|
+
export interface RestateWorkflowContext extends RestateObjectContext, RestateWorkflowSharedContext {
|
|
10
|
+
}
|
|
11
|
+
export type ArgType<T> = T extends (ctx: any) => any ? void : T extends (ctx: any, input: infer I) => any ? I : never;
|
|
12
|
+
export type HandlerReturnType<T> = T extends (ctx: any, input: any) => Promise<infer R> ? R : never;
|
|
13
|
+
export type ServiceHandler<F, C = RestateContext> = F extends (ctx: C) => Promise<any> ? F : F extends (ctx: C, input: any) => Promise<any> ? F : (ctx: C, input?: any) => Promise<any>;
|
|
14
|
+
export type ServiceDefinition<P extends string, M> = {
|
|
15
|
+
name: P;
|
|
12
16
|
};
|
|
13
|
-
type Service<M> = M extends ServiceDefinition<string, infer S> ? S : M;
|
|
14
|
-
type ServiceDefinitionFrom<M> = M extends ServiceDefinition<string, unknown> ? M : ServiceDefinition<string, M>;
|
|
15
|
-
type ObjectSharedHandler<F, SC = RestateObjectSharedContext> = F extends (
|
|
16
|
-
type ObjectHandler<F, C = RestateObjectContext> = F extends (
|
|
17
|
-
type VirtualObjectDefinition<P extends string, M> = {
|
|
18
|
-
|
|
17
|
+
export type Service<M> = M extends ServiceDefinition<string, infer S> ? S : M;
|
|
18
|
+
export type ServiceDefinitionFrom<M> = M extends ServiceDefinition<string, unknown> ? M : ServiceDefinition<string, M>;
|
|
19
|
+
export type ObjectSharedHandler<F, SC = RestateObjectSharedContext> = F extends (ctx: SC, param: any) => Promise<any> ? F : F extends (ctx: SC) => Promise<any> ? F : (ctx: SC, param?: any) => Promise<any>;
|
|
20
|
+
export type ObjectHandler<F, C = RestateObjectContext> = F extends (ctx: C, param: any) => Promise<any> ? F : F extends (ctx: C) => Promise<any> ? F : (ctx: C, param?: any) => Promise<any>;
|
|
21
|
+
export type VirtualObjectDefinition<P extends string, M> = {
|
|
22
|
+
name: P;
|
|
19
23
|
};
|
|
20
|
-
type VirtualObject<M> = M extends VirtualObjectDefinition<string, infer O> ? O : M;
|
|
21
|
-
type VirtualObjectDefinitionFrom<M> = M extends VirtualObjectDefinition<string, unknown> ? M : VirtualObjectDefinition<string, M>;
|
|
22
|
-
type WorkflowSharedHandler<F, SC = RestateWorkflowSharedContext> = F extends (
|
|
23
|
-
type WorkflowHandler<F, C = RestateWorkflowContext> = F extends (
|
|
24
|
-
type WorkflowDefinition<P extends string, M> = {
|
|
25
|
-
|
|
24
|
+
export type VirtualObject<M> = M extends VirtualObjectDefinition<string, infer O> ? O : M;
|
|
25
|
+
export type VirtualObjectDefinitionFrom<M> = M extends VirtualObjectDefinition<string, unknown> ? M : VirtualObjectDefinition<string, M>;
|
|
26
|
+
export type WorkflowSharedHandler<F, SC = RestateWorkflowSharedContext> = F extends (ctx: SC, param: any) => Promise<any> ? F : F extends (ctx: SC) => Promise<any> ? F : (ctx: SC, param?: any) => Promise<any>;
|
|
27
|
+
export type WorkflowHandler<F, C = RestateWorkflowContext> = F extends (ctx: C, param: any) => Promise<any> ? F : F extends (ctx: C) => Promise<any> ? F : (ctx: C, param?: any) => Promise<any>;
|
|
28
|
+
export type WorkflowDefinition<P extends string, M> = {
|
|
29
|
+
name: P;
|
|
26
30
|
};
|
|
27
|
-
type Workflow<M> = M extends WorkflowDefinition<string, infer W> ? W : M;
|
|
28
|
-
type WorkflowDefinitionFrom<M> = M extends WorkflowDefinition<string, unknown> ? M : WorkflowDefinition<string, M>;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { ArgType, HandlerReturnType, ObjectHandler, ObjectSharedHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler };
|
|
31
|
+
export type Workflow<M> = M extends WorkflowDefinition<string, infer W> ? W : M;
|
|
32
|
+
export type WorkflowDefinitionFrom<M> = M extends WorkflowDefinition<string, unknown> ? M : WorkflowDefinition<string, M>;
|
|
31
33
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,cAAc;CAAG;AAClC,MAAM,WAAW,oBAAoB;CAAG;AACxC,MAAM,WAAW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AAE,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GAC/C,CAAC,GACD,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GACjC,CAAC,GACD,CAAC,GAAG,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE7C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,sBAAsB,IAAI,CAAC,SAAS,CACrE,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,GAAG,KACP,OAAO,CAAC,GAAG,CAAC,GACb,CAAC,GACD,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,GAChC,CAAC,GACD,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAG5C,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI;IACpD,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEhF,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAClC,CAAC,SAAS,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GACzC,CAAC,GACD,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC"}
|
package/dist/duration.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
//#region src/duration.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Duration type. Note that fields are additive.
|
|
4
3
|
*/
|
|
5
|
-
type Duration = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export type Duration = {
|
|
5
|
+
days?: number;
|
|
6
|
+
hours?: number;
|
|
7
|
+
minutes?: number;
|
|
8
|
+
seconds?: number;
|
|
9
|
+
milliseconds?: number;
|
|
11
10
|
};
|
|
12
|
-
declare function millisOrDurationToMillis(duration: number | Duration): number;
|
|
13
|
-
declare function durationToMillis(duration: Duration): number;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { Duration, durationToMillis, millisOrDurationToMillis };
|
|
11
|
+
export declare function millisOrDurationToMillis(duration: number | Duration): number;
|
|
12
|
+
export declare function durationToMillis(duration: Duration): number;
|
|
16
13
|
//# sourceMappingURL=duration.d.ts.map
|
package/dist/duration.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.d.ts","
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAM5E;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAQ3D"}
|
package/dist/duration.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 - 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
|
+
export function millisOrDurationToMillis(duration) {
|
|
12
|
+
if (typeof duration === "number") {
|
|
13
|
+
return Math.trunc(duration);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return Math.trunc(durationToMillis(duration));
|
|
17
|
+
}
|
|
5
18
|
}
|
|
6
|
-
function durationToMillis(duration) {
|
|
7
|
-
|
|
19
|
+
export function durationToMillis(duration) {
|
|
20
|
+
return ((duration.milliseconds ?? 0) +
|
|
21
|
+
1000 * (duration.seconds ?? 0) +
|
|
22
|
+
1000 * 60 * (duration.minutes ?? 0) +
|
|
23
|
+
1000 * 60 * 60 * (duration.hours ?? 0) +
|
|
24
|
+
1000 * 60 * 60 * 24 * (duration.days ?? 0));
|
|
8
25
|
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
export { durationToMillis, millisOrDurationToMillis };
|
|
12
26
|
//# sourceMappingURL=duration.js.map
|
package/dist/duration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.js","
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,MAAM,UAAU,wBAAwB,CAAC,QAA2B;IAClE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,OAAO,CACL,CAAC,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;QAC5B,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;QAC9B,IAAI,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;QACnC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;QACtC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC,CAC3C,CAAC;AACJ,CAAC"}
|
package/dist/entry_codec.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/entry_codec.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Journal values codec.
|
|
4
3
|
*
|
|
@@ -13,26 +12,24 @@
|
|
|
13
12
|
*
|
|
14
13
|
* @experimental
|
|
15
14
|
*/
|
|
16
|
-
type JournalValueCodec = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
export type JournalValueCodec = {
|
|
16
|
+
/**
|
|
17
|
+
* Encodes the given buffer.
|
|
18
|
+
*
|
|
19
|
+
* This will be applied *after* serialization.
|
|
20
|
+
*
|
|
21
|
+
* @param buf The buffer to encode. Empty byte buffers should be appropriately handled as well.
|
|
22
|
+
* @returns The encoded buffer
|
|
23
|
+
*/
|
|
24
|
+
encode(buf: Uint8Array): Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* Decodes the given buffer.
|
|
27
|
+
*
|
|
28
|
+
* This will be applied *before* deserialization.
|
|
29
|
+
*
|
|
30
|
+
* @param buf The buffer to decode.
|
|
31
|
+
* @returns A promise that resolves to the decoded buffer.
|
|
32
|
+
*/
|
|
33
|
+
decode(buf: Uint8Array): Promise<Uint8Array>;
|
|
35
34
|
};
|
|
36
|
-
//#endregion
|
|
37
|
-
export { JournalValueCodec };
|
|
38
35
|
//# sourceMappingURL=entry_codec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry_codec.d.ts","
|
|
1
|
+
{"version":3,"file":"entry_codec.d.ts","sourceRoot":"","sources":["../src/entry_codec.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAAC;IAEpC;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC9C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
export type { RestateContext, ServiceHandler, ServiceDefinition, Service, ServiceDefinitionFrom, RestateObjectContext, RestateObjectSharedContext, ObjectHandler, ObjectSharedHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, WorkflowDefinition, WorkflowHandler, WorkflowSharedHandler, RestateWorkflowContext, RestateWorkflowSharedContext, Workflow, WorkflowDefinitionFrom, ArgType, HandlerReturnType, } from "./core.js";
|
|
2
|
+
export type { Serde } from "./serde_api.js";
|
|
3
|
+
export { serde } from "./serde_api.js";
|
|
4
|
+
export type { Duration } from "./duration.js";
|
|
5
|
+
export { durationToMillis, millisOrDurationToMillis } from "./duration.js";
|
|
6
|
+
export type { JournalValueCodec } from "./entry_codec.js";
|
|
7
|
+
export type { StandardTypedV1, StandardSchemaV1, StandardJSONSchemaV1, } from "./standard_schema.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2024 - 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
|
+
export { serde } from "./serde_api.js";
|
|
12
|
+
export { durationToMillis, millisOrDurationToMillis } from "./duration.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/dist/serde_api.d.cts
CHANGED
|
@@ -1,10 +1,109 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./standard_schema.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/serde_api.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serializer/deserializer pair for any Restate-managed value of type `T` —
|
|
7
|
+
* handler inputs and outputs, service state, side-effect results,
|
|
8
|
+
* awakeables, durable promises, and so on.
|
|
9
|
+
*
|
|
10
|
+
* A `Serde<T>` is responsible for two conversions:
|
|
11
|
+
*
|
|
12
|
+
* - **Wire format**: `serialize` / `deserialize` convert a value `T` to and
|
|
13
|
+
* from the raw bytes that flow over the network and get stored in the
|
|
14
|
+
* journal.
|
|
15
|
+
* - **JSON preview (optional)**: `preview.toJsonString` /
|
|
16
|
+
* `preview.fromJsonString` convert a value `T` to and from a JSON string,
|
|
17
|
+
* used by tooling to render and edit values that humans can read.
|
|
18
|
+
*
|
|
19
|
+
* It also advertises metadata (`contentType`, `jsonSchema`) that surfaces in
|
|
20
|
+
* service discovery.
|
|
21
|
+
*/
|
|
4
22
|
interface Serde<T> {
|
|
23
|
+
/**
|
|
24
|
+
* MIME type of the bytes produced by `serialize` (and accepted by
|
|
25
|
+
* `deserialize`).
|
|
26
|
+
*/
|
|
5
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
|
+
*/
|
|
6
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?: {
|
|
81
|
+
/**
|
|
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.
|
|
85
|
+
*/
|
|
86
|
+
toJsonString(value: T): Promise<string> | string;
|
|
87
|
+
/**
|
|
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.
|
|
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
|
+
*/
|
|
7
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
|
+
*/
|
|
8
107
|
deserialize(data: Uint8Array): T;
|
|
9
108
|
}
|
|
10
109
|
declare namespace serde {
|
package/dist/serde_api.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde_api.d.cts","names":[],"sources":["../src/serde_api.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serde_api.d.cts","names":[],"sources":["../src/serde_api.ts"],"sourcesContent":[],"mappings":";;;;;;AAoCA;;;;;;;;;;;AAiOA;;;;AAasB,UA9OL,KA8OK,CAAA,CAAA,CAAA,CAAA;EAAa;;;;EAYd,WAAA,CAAA,EAAA,MAAA;EACQ;;;;;EAaP,UAAA,CAAA,EAAA,MAAA;EACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAvMA,IAAI;;;;;kCAMM,QAAQ,KAAK;;;;;;;;;mBAU5B,IAAI;;;;;;;oBAQH,aAAa;;kBAuIhB,KAAA;gCACsB,MAAM;;;;qBAKxB,IAAI;sBAOH,aAAa;+BAOJ,MAAM;;cAKhB;gBACE,MAAM;eACP;;;;;;;;;;iBAU4B,gBAAA,CAAiB;aACvD,qBACU,6CACE,4BACnB,MAAM,gBAAA,CAAiB,YAAY"}
|
package/dist/serde_api.d.ts
CHANGED
|
@@ -1,36 +1,130 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from "./standard_schema.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import type { StandardSchemaV1 } from "./standard_schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Serializer/deserializer pair for any Restate-managed value of type `T` —
|
|
4
|
+
* handler inputs and outputs, service state, side-effect results,
|
|
5
|
+
* awakeables, durable promises, and so on.
|
|
6
|
+
*
|
|
7
|
+
* A `Serde<T>` is responsible for two conversions:
|
|
8
|
+
*
|
|
9
|
+
* - **Wire format**: `serialize` / `deserialize` convert a value `T` to and
|
|
10
|
+
* from the raw bytes that flow over the network and get stored in the
|
|
11
|
+
* journal.
|
|
12
|
+
* - **JSON preview (optional)**: `preview.toJsonString` /
|
|
13
|
+
* `preview.fromJsonString` convert a value `T` to and from a JSON string,
|
|
14
|
+
* used by tooling to render and edit values that humans can read.
|
|
15
|
+
*
|
|
16
|
+
* It also advertises metadata (`contentType`, `jsonSchema`) that surfaces in
|
|
17
|
+
* service discovery.
|
|
18
|
+
*/
|
|
19
|
+
export interface Serde<T> {
|
|
20
|
+
/**
|
|
21
|
+
* MIME type of the bytes produced by `serialize` (and accepted by
|
|
22
|
+
* `deserialize`).
|
|
23
|
+
*/
|
|
24
|
+
contentType?: string;
|
|
25
|
+
/**
|
|
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`.
|
|
96
|
+
*/
|
|
15
97
|
serialize(value: T): Uint8Array;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
deserialize(data: Uint8Array): T;
|
|
105
|
+
}
|
|
106
|
+
export declare namespace serde {
|
|
107
|
+
class JsonSerde<T> implements Serde<T | undefined> {
|
|
108
|
+
readonly jsonSchema?: object | undefined;
|
|
109
|
+
contentType: string;
|
|
110
|
+
constructor(jsonSchema?: object | undefined);
|
|
111
|
+
serialize(value: T): Uint8Array;
|
|
112
|
+
deserialize(data: Uint8Array): T | undefined;
|
|
113
|
+
schema<U>(schema: object): Serde<U>;
|
|
114
|
+
}
|
|
115
|
+
const json: JsonSerde<any>;
|
|
116
|
+
const binary: Serde<Uint8Array>;
|
|
117
|
+
const empty: Serde<void>;
|
|
118
|
+
/**
|
|
119
|
+
* A Standard Schema-based serde.
|
|
120
|
+
*
|
|
121
|
+
* @param schema the standard schema
|
|
122
|
+
* @param validateOptions options passed to `StandardSchemaV1.Options.libraryOptions` when validating
|
|
123
|
+
* @param jsonSchemaOptions options passed to `StandardJsonSchemaV1.Options.libraryOptions` for code generation
|
|
124
|
+
* @returns a serde that will validate the data with the standard schema
|
|
125
|
+
*/
|
|
126
|
+
const schema: <T extends {
|
|
127
|
+
"~standard": StandardSchemaV1.Props;
|
|
128
|
+
}>(schema: T, validateOptions?: Record<string, unknown>, jsonSchemaOptions?: Record<string, unknown>) => Serde<StandardSchemaV1.InferOutput<T>>;
|
|
33
129
|
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { Serde, serde };
|
|
36
130
|
//# sourceMappingURL=serde_api.d.ts.map
|
package/dist/serde_api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde_api.d.ts","
|
|
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,CAAC,CAAC,GAAG,SAAS,CAAC;QAG3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;QAFxC,WAAW,SAAsB;oBAEZ,UAAU,CAAC,EAAE,MAAM,YAAA;QAExC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,UAAU;QAO/B,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,GAAG,SAAS;QAO5C,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GA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, 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
|
+
class BinarySerde {
|
|
12
|
+
contentType = "application/octet-stream";
|
|
13
|
+
serialize(value) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
deserialize(data) {
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class VoidSerde {
|
|
21
|
+
serialize(value) {
|
|
22
|
+
if (value !== undefined) {
|
|
23
|
+
throw new Error("Expected undefined value");
|
|
24
|
+
}
|
|
25
|
+
return new Uint8Array(0);
|
|
26
|
+
}
|
|
27
|
+
deserialize(data) {
|
|
28
|
+
if (data.length !== 0) {
|
|
29
|
+
throw new Error("Expected empty data");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class StandardSchemaSerde {
|
|
34
|
+
schema;
|
|
35
|
+
validateOptions;
|
|
36
|
+
contentType = "application/json";
|
|
37
|
+
jsonSchema;
|
|
38
|
+
constructor(schema, validateOptions, jsonSchemaOptions) {
|
|
39
|
+
this.schema = schema;
|
|
40
|
+
this.validateOptions = validateOptions;
|
|
41
|
+
// Extract JSON schema if available
|
|
42
|
+
const standard = schema["~standard"];
|
|
43
|
+
if (isStandardJSONSchemaV1(standard)) {
|
|
44
|
+
try {
|
|
45
|
+
this.jsonSchema = standard.jsonSchema.output({
|
|
46
|
+
target: "draft-2020-12",
|
|
47
|
+
libraryOptions: jsonSchemaOptions,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// If JSON schema generation fails, leave it undefined
|
|
52
|
+
this.jsonSchema = undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Check if schema is for void/undefined type
|
|
56
|
+
// Standard Schema doesn't have a direct way to detect void types,
|
|
57
|
+
// so we serialize undefined and check if validation succeeds
|
|
58
|
+
const testResult = standard.validate(undefined);
|
|
59
|
+
// Handle both sync and async validation results
|
|
60
|
+
if (testResult && typeof testResult === "object" && "then" in testResult) {
|
|
61
|
+
// If it's a Promise, we can't determine contentType synchronously
|
|
62
|
+
// Keep contentType as "application/json"
|
|
63
|
+
}
|
|
64
|
+
else if (!testResult.issues) {
|
|
65
|
+
this.contentType = undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
serialize(value) {
|
|
69
|
+
if (value === undefined) {
|
|
70
|
+
return new Uint8Array(0);
|
|
71
|
+
}
|
|
72
|
+
return new TextEncoder().encode(JSON.stringify(value));
|
|
73
|
+
}
|
|
74
|
+
deserialize(data) {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
76
|
+
const js = data.length === 0
|
|
77
|
+
? undefined
|
|
78
|
+
: JSON.parse(new TextDecoder().decode(data));
|
|
79
|
+
const result = this.schema["~standard"].validate(js, this.validateOptions);
|
|
80
|
+
// Standard Schema validate can return a Promise, but Serde must be synchronous
|
|
81
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
82
|
+
throw new TypeError("Async validation is not supported in Serde. Restate SDK supports only synchronous validation.");
|
|
83
|
+
}
|
|
84
|
+
if (result.issues) {
|
|
85
|
+
const errorMessages = result.issues
|
|
86
|
+
.map(formatStandardSchemaIssue)
|
|
87
|
+
.join("\n");
|
|
88
|
+
throw new TypeError(`Standard schema validation failed:\n${errorMessages}`);
|
|
89
|
+
}
|
|
90
|
+
return result.value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
53
93
|
function formatStandardSchemaIssue(issue) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
94
|
+
if (issue.path && issue.path.length > 0) {
|
|
95
|
+
const jsonPointer = "/" +
|
|
96
|
+
issue.path
|
|
97
|
+
.map((p) => {
|
|
98
|
+
// Handle both PathSegment objects and primitive PropertyKey values
|
|
99
|
+
if (typeof p === "object" && p !== null && "key" in p) {
|
|
100
|
+
return String(p.key);
|
|
101
|
+
}
|
|
102
|
+
return String(p);
|
|
103
|
+
})
|
|
104
|
+
.join("/");
|
|
105
|
+
return `* (at ${jsonPointer}) ${issue.message}`;
|
|
106
|
+
}
|
|
107
|
+
return `* ${issue.message}`;
|
|
59
108
|
}
|
|
60
109
|
function isStandardJSONSchemaV1(standard) {
|
|
61
|
-
|
|
110
|
+
return (standard != undefined &&
|
|
111
|
+
"jsonSchema" in standard &&
|
|
112
|
+
typeof standard.jsonSchema === "object" &&
|
|
113
|
+
standard.jsonSchema !== null &&
|
|
114
|
+
"output" in standard.jsonSchema &&
|
|
115
|
+
typeof standard.jsonSchema.output === "function");
|
|
62
116
|
}
|
|
63
|
-
|
|
64
|
-
(function(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
117
|
+
export var serde;
|
|
118
|
+
(function (serde) {
|
|
119
|
+
class JsonSerde {
|
|
120
|
+
jsonSchema;
|
|
121
|
+
contentType = "application/json";
|
|
122
|
+
constructor(jsonSchema) {
|
|
123
|
+
this.jsonSchema = jsonSchema;
|
|
124
|
+
}
|
|
125
|
+
serialize(value) {
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
return new Uint8Array(0);
|
|
128
|
+
}
|
|
129
|
+
return new TextEncoder().encode(JSON.stringify(value));
|
|
130
|
+
}
|
|
131
|
+
deserialize(data) {
|
|
132
|
+
if (data.length === 0) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
return JSON.parse(new TextDecoder().decode(data));
|
|
136
|
+
}
|
|
137
|
+
schema(schema) {
|
|
138
|
+
return new JsonSerde(schema);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
serde.JsonSerde = JsonSerde;
|
|
142
|
+
serde.json = new JsonSerde();
|
|
143
|
+
serde.binary = new BinarySerde();
|
|
144
|
+
serde.empty = new VoidSerde();
|
|
145
|
+
/**
|
|
146
|
+
* A Standard Schema-based serde.
|
|
147
|
+
*
|
|
148
|
+
* @param schema the standard schema
|
|
149
|
+
* @param validateOptions options passed to `StandardSchemaV1.Options.libraryOptions` when validating
|
|
150
|
+
* @param jsonSchemaOptions options passed to `StandardJsonSchemaV1.Options.libraryOptions` for code generation
|
|
151
|
+
* @returns a serde that will validate the data with the standard schema
|
|
152
|
+
*/
|
|
153
|
+
serde.schema = (schema, validateOptions, jsonSchemaOptions) => {
|
|
154
|
+
return new StandardSchemaSerde(schema, validateOptions, jsonSchemaOptions);
|
|
155
|
+
};
|
|
89
156
|
})(serde || (serde = {}));
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
export { serde };
|
|
93
157
|
//# sourceMappingURL=serde_api.js.map
|
package/dist/serde_api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde_api.js","
|
|
1
|
+
{"version":3,"file":"serde_api.js","sourceRoot":"","sources":["../src/serde_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAwHH,MAAM,WAAW;IACf,WAAW,GAAG,0BAA0B,CAAC;IAEzC,SAAS,CAAC,KAAiB;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,IAAgB;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,SAAS;IACb,SAAS,CAAC,KAAU;QAClB,IAAI,KAAK,KAAK,SA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AO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAM,CAAC;QACzD,CAAC;QAED,MAAM,CAAI,MAAc;YACtB,OAAO,IAAI,SAAS,CAAI,MAAM,CAAa,CAAC;QAC9C,CAAC;KACF;IAtBY,eAAS,YAsBrB,CAAA;IAEY,UAAI,GAAmB,IAAI,SAAS,EAAO,CAAC;IAC5C,YAAM,GAAsB,IAAI,WAAW,EAAE,CAAC;IAC9C,WAAK,GAAgB,IAAI,SAAS,EAAE,CAAC;IAElD;;;;;;;OAOG;IACU,YAAM,GAAG,CACpB,MAAS,EACT,eAAyC,EACzC,iBAA2C,EACH,EAAE;QAC1C,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC,EA5CgB,KAAK,KAAL,KAAK,QA4CrB"}
|
|
@@ -1,122 +1,121 @@
|
|
|
1
|
-
//#region src/standard_schema.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* This file is copy pasted as is from https://standardschema.dev/
|
|
4
3
|
*/
|
|
5
4
|
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
6
|
-
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
6
|
+
/** The Standard properties. */
|
|
7
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
9
8
|
}
|
|
10
|
-
declare namespace StandardTypedV1 {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
export declare namespace StandardTypedV1 {
|
|
10
|
+
/** The Standard Typed properties interface. */
|
|
11
|
+
interface Props<Input = unknown, Output = Input> {
|
|
12
|
+
/** The version number of the standard. */
|
|
13
|
+
readonly version: 1;
|
|
14
|
+
/** The vendor name of the schema library. */
|
|
15
|
+
readonly vendor: string;
|
|
16
|
+
/** Inferred types associated with the schema. */
|
|
17
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The Standard Typed types interface. */
|
|
20
|
+
interface Types<Input = unknown, Output = Input> {
|
|
21
|
+
/** The input type of the schema. */
|
|
22
|
+
readonly input: Input;
|
|
23
|
+
/** The output type of the schema. */
|
|
24
|
+
readonly output: Output;
|
|
25
|
+
}
|
|
26
|
+
/** Infers the input type of a Standard Typed. */
|
|
27
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
28
|
+
/** Infers the output type of a Standard Typed. */
|
|
29
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
31
30
|
}
|
|
32
31
|
/** The Standard Schema interface. */
|
|
33
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
33
|
+
/** The Standard Schema properties. */
|
|
34
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
36
35
|
}
|
|
37
|
-
declare namespace StandardSchemaV1 {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
36
|
+
export declare namespace StandardSchemaV1 {
|
|
37
|
+
/** The Standard Schema properties interface. */
|
|
38
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
39
|
+
/** Validates unknown input values. */
|
|
40
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
41
|
+
}
|
|
42
|
+
/** The result interface of the validate function. */
|
|
43
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
44
|
+
/** The result interface if validation succeeds. */
|
|
45
|
+
interface SuccessResult<Output> {
|
|
46
|
+
/** The typed output value. */
|
|
47
|
+
readonly value: Output;
|
|
48
|
+
/** A falsy value for `issues` indicates success. */
|
|
49
|
+
readonly issues?: undefined;
|
|
50
|
+
}
|
|
51
|
+
interface Options {
|
|
52
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
53
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
54
|
+
}
|
|
55
|
+
/** The result interface if validation fails. */
|
|
56
|
+
interface FailureResult {
|
|
57
|
+
/** The issues of failed validation. */
|
|
58
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
59
|
+
}
|
|
60
|
+
/** The issue interface of the failure output. */
|
|
61
|
+
interface Issue {
|
|
62
|
+
/** The error message of the issue. */
|
|
63
|
+
readonly message: string;
|
|
64
|
+
/** The path of the issue, if any. */
|
|
65
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
66
|
+
}
|
|
67
|
+
/** The path segment interface of the issue. */
|
|
68
|
+
interface PathSegment {
|
|
69
|
+
/** The key representing a path segment. */
|
|
70
|
+
readonly key: PropertyKey;
|
|
71
|
+
}
|
|
72
|
+
/** The Standard types interface. */
|
|
73
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
74
|
+
}
|
|
75
|
+
/** Infers the input type of a Standard. */
|
|
76
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
77
|
+
/** Infers the output type of a Standard. */
|
|
78
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
79
79
|
}
|
|
80
80
|
/** The Standard JSON Schema interface. */
|
|
81
|
-
interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
82
|
+
/** The Standard JSON Schema properties. */
|
|
83
|
+
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
84
84
|
}
|
|
85
|
-
declare namespace StandardJSONSchemaV1 {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
export declare namespace StandardJSONSchemaV1 {
|
|
86
|
+
/** The Standard JSON Schema properties interface. */
|
|
87
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
88
|
+
/** Methods for generating the input/output JSON Schema. */
|
|
89
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
90
|
+
}
|
|
91
|
+
/** The Standard JSON Schema converter interface. */
|
|
92
|
+
interface Converter {
|
|
93
|
+
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
94
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
95
|
+
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
96
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The target version of the generated JSON Schema.
|
|
100
|
+
*
|
|
101
|
+
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
102
|
+
*
|
|
103
|
+
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
104
|
+
*/
|
|
105
|
+
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
106
|
+
/** The options for the input/output methods. */
|
|
107
|
+
interface Options {
|
|
108
|
+
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
109
|
+
readonly target: Target;
|
|
110
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
111
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
112
|
+
}
|
|
113
|
+
/** The Standard types interface. */
|
|
114
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
115
|
+
}
|
|
116
|
+
/** Infers the input type of a Standard. */
|
|
117
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
118
|
+
/** Infers the output type of a Standard. */
|
|
119
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
119
120
|
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 };
|
|
122
121
|
//# sourceMappingURL=standard_schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_schema.d.ts","
|
|
1
|
+
{"version":3,"file":"standard_schema.d.ts","sourceRoot":"","sources":["../src/standard_schema.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,iFAAiF;AACjF,MAAM,WAAW,eAAe,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC9D,+BAA+B;IAC/B,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CAC5D;AAED,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC;IACvC,+CAA+C;IAC/C,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,0CAA0C;QAC1C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,6CAA6C;QAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,iDAAiD;QACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;KACnD;IAED,0CAA0C;IAC1C,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,oCAAoC;QACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;QACtB,qCAAqC;QACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB;IAED,iDAAiD;IACjD,KAAY,UAAU,CAAC,MAAM,SAAS,eAAe,IAAI,WAAW,CAClE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,OAAO,CAAC,CAAC;IAEX,kDAAkD;IAClD,KAAY,WAAW,CAAC,MAAM,SAAS,eAAe,IAAI,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