@temporal-contract/contract 0.0.1 → 0.0.2
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +7 -0
- package/README.md +14 -80
- package/dist/index.cjs +18 -10
- package/dist/index.d.cts +23 -22
- package/dist/index.d.mts +23 -22
- package/dist/index.mjs +18 -10
- package/package.json +9 -6
- package/src/builder.spec.ts +92 -0
- package/src/builder.ts +43 -19
- package/src/index.ts +1 -1
- package/src/types.ts +29 -20
- package/vitest.config.ts +12 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @temporal-contract/contract@0.0.
|
|
2
|
+
> @temporal-contract/contract@0.0.2 build /home/runner/work/temporal-contract/temporal-contract/packages/contract
|
|
3
3
|
> tsdown src/index.ts --format cjs,esm --dts --clean
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
6
6
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
7
7
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
8
8
|
[34mℹ[39m Build start
|
|
9
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [
|
|
10
|
-
[34mℹ[39m [33m[CJS][39m 1 files, total:
|
|
11
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m15.
|
|
12
|
-
[34mℹ[39m [33m[CJS][39m 1 files, total: 15.
|
|
13
|
-
[
|
|
14
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[
|
|
15
|
-
[34mℹ[39m [34m[ESM][39m
|
|
16
|
-
[
|
|
17
|
-
[32m✔[39m Build complete in [
|
|
9
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m6.97 kB[22m [2m│ gzip: 1.69 kB[22m
|
|
10
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 6.97 kB
|
|
11
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m15.66 kB[22m [2m│ gzip: 2.56 kB[22m
|
|
12
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 15.66 kB
|
|
13
|
+
[32m✔[39m Build complete in [32m1491ms[39m
|
|
14
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 6.74 kB[22m [2m│ gzip: 1.67 kB[22m
|
|
15
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m15.66 kB[22m [2m│ gzip: 2.56 kB[22m
|
|
16
|
+
[34mℹ[39m [34m[ESM][39m 2 files, total: 22.40 kB
|
|
17
|
+
[32m✔[39m Build complete in [32m1492ms[39m
|
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Contract builder and type definitions for Temporal workflows and activities
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@temporal-contract/contract)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -10,98 +10,32 @@
|
|
|
10
10
|
pnpm add @temporal-contract/contract zod
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
- **Contract builder** — `defineContract()` for creating type-safe contracts
|
|
16
|
-
- **Type utilities** — Helper types for cleaner implementations
|
|
17
|
-
- **Helper functions** — Optional helpers for standalone definitions
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { z } from 'zod';
|
|
23
|
-
import { defineContract } from '@temporal-contract/contract';
|
|
24
|
-
|
|
25
|
-
export const myContract = defineContract({
|
|
26
|
-
taskQueue: 'my-service',
|
|
27
|
-
workflows: {
|
|
28
|
-
processOrder: {
|
|
29
|
-
input: z.object({
|
|
30
|
-
orderId: z.string(),
|
|
31
|
-
items: z.array(z.object({
|
|
32
|
-
productId: z.string(),
|
|
33
|
-
quantity: z.number(),
|
|
34
|
-
})),
|
|
35
|
-
}),
|
|
36
|
-
output: z.object({
|
|
37
|
-
status: z.enum(['success', 'failed']),
|
|
38
|
-
totalAmount: z.number(),
|
|
39
|
-
}),
|
|
40
|
-
activities: {
|
|
41
|
-
processPayment: {
|
|
42
|
-
input: z.object({ amount: z.number() }),
|
|
43
|
-
output: z.object({ transactionId: z.string() }),
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Quick Start
|
|
52
|
-
|
|
53
|
-
### Define a Contract
|
|
13
|
+
## Quick Example
|
|
54
14
|
|
|
55
15
|
```typescript
|
|
56
16
|
import { defineContract } from '@temporal-contract/contract';
|
|
57
17
|
import { z } from 'zod';
|
|
58
18
|
|
|
59
19
|
export const myContract = defineContract({
|
|
60
|
-
taskQueue: '
|
|
61
|
-
|
|
62
|
-
// Global activities (available in all workflows)
|
|
63
|
-
activities: {
|
|
64
|
-
sendEmail: {
|
|
65
|
-
input: z.object({ to: z.string(), subject: z.string() }),
|
|
66
|
-
output: z.object({ sent: z.boolean() }),
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
// Workflows
|
|
20
|
+
taskQueue: 'orders',
|
|
71
21
|
workflows: {
|
|
72
22
|
processOrder: {
|
|
73
23
|
input: z.object({ orderId: z.string() }),
|
|
74
|
-
output: z.object({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
processPayment: {
|
|
79
|
-
input: z.object({ amount: z.number() }),
|
|
80
|
-
output: z.object({ transactionId: z.string() }),
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
24
|
+
output: z.object({ success: z.boolean() }),
|
|
25
|
+
activities: { /* ... */ }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
85
28
|
});
|
|
86
29
|
```
|
|
87
30
|
|
|
88
|
-
|
|
31
|
+
## Documentation
|
|
89
32
|
|
|
90
|
-
|
|
33
|
+
📖 **[Read the full documentation →](https://btravers.github.io/temporal-contract)**
|
|
91
34
|
|
|
92
|
-
|
|
93
|
-
|
|
35
|
+
- [API Reference](https://btravers.github.io/temporal-contract/api/contract)
|
|
36
|
+
- [Getting Started](https://btravers.github.io/temporal-contract/guide/getting-started)
|
|
37
|
+
- [Core Concepts](https://btravers.github.io/temporal-contract/guide/core-concepts)
|
|
94
38
|
|
|
95
|
-
|
|
96
|
-
const sendEmail = defineActivity({
|
|
97
|
-
input: z.object({ to: z.string() }),
|
|
98
|
-
output: z.object({ sent: z.boolean() }),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// Signal, query, update
|
|
102
|
-
const cancelOrder = defineSignal({ input: z.object({ reason: z.string() }) });
|
|
103
|
-
const getStatus = defineQuery({ input: z.void(), output: z.object({ status: z.string() }) });
|
|
104
|
-
const updateAmount = defineUpdate({ input: z.number(), output: z.boolean() });
|
|
105
|
-
```
|
|
39
|
+
## License
|
|
106
40
|
|
|
107
|
-
|
|
41
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,14 @@ let zod = require("zod");
|
|
|
2
2
|
|
|
3
3
|
//#region src/builder.ts
|
|
4
4
|
/**
|
|
5
|
+
* Check if a value is a Standard Schema compatible schema
|
|
6
|
+
*/
|
|
7
|
+
function isStandardSchema(value) {
|
|
8
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null || !("~standard" in value)) return false;
|
|
9
|
+
const standard = value["~standard"];
|
|
10
|
+
return typeof standard === "object" && standard !== null && standard["version"] === 1 && typeof standard["validate"] === "function";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
5
13
|
* Schema for validating JavaScript identifiers (workflow names, activity names, etc.)
|
|
6
14
|
* Allows: letters, digits, underscore, dollar sign
|
|
7
15
|
* Must start with: letter, underscore, or dollar sign
|
|
@@ -26,36 +34,36 @@ const getCleanErrorMessage = (error) => {
|
|
|
26
34
|
};
|
|
27
35
|
/**
|
|
28
36
|
* Schema for validating activity definitions
|
|
29
|
-
* Checks that input and output are
|
|
37
|
+
* Checks that input and output are Standard Schema compatible schemas
|
|
30
38
|
*/
|
|
31
39
|
const activityDefinitionSchema = zod.z.object({
|
|
32
|
-
input: zod.z.
|
|
33
|
-
output: zod.z.
|
|
40
|
+
input: zod.z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
41
|
+
output: zod.z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
34
42
|
});
|
|
35
43
|
/**
|
|
36
44
|
* Schema for validating signal definitions
|
|
37
45
|
*/
|
|
38
|
-
const signalDefinitionSchema = zod.z.object({ input: zod.z.
|
|
46
|
+
const signalDefinitionSchema = zod.z.object({ input: zod.z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }) });
|
|
39
47
|
/**
|
|
40
48
|
* Schema for validating query definitions
|
|
41
49
|
*/
|
|
42
50
|
const queryDefinitionSchema = zod.z.object({
|
|
43
|
-
input: zod.z.
|
|
44
|
-
output: zod.z.
|
|
51
|
+
input: zod.z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
52
|
+
output: zod.z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
45
53
|
});
|
|
46
54
|
/**
|
|
47
55
|
* Schema for validating update definitions
|
|
48
56
|
*/
|
|
49
57
|
const updateDefinitionSchema = zod.z.object({
|
|
50
|
-
input: zod.z.
|
|
51
|
-
output: zod.z.
|
|
58
|
+
input: zod.z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
59
|
+
output: zod.z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
52
60
|
});
|
|
53
61
|
/**
|
|
54
62
|
* Schema for validating workflow definitions
|
|
55
63
|
*/
|
|
56
64
|
const workflowDefinitionSchema = zod.z.object({
|
|
57
|
-
input: zod.z.
|
|
58
|
-
output: zod.z.
|
|
65
|
+
input: zod.z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
66
|
+
output: zod.z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
59
67
|
activities: zod.z.record(identifierSchema, activityDefinitionSchema).optional(),
|
|
60
68
|
signals: zod.z.record(identifierSchema, signalDefinitionSchema).optional(),
|
|
61
69
|
queries: zod.z.record(identifierSchema, queryDefinitionSchema).optional(),
|
package/dist/index.d.cts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Base types for validation schemas
|
|
7
|
-
*
|
|
7
|
+
* Any schema that implements the Standard Schema specification
|
|
8
|
+
* This includes Zod, Valibot, ArkType, and other compatible libraries
|
|
8
9
|
*/
|
|
9
|
-
type
|
|
10
|
+
type AnySchema = StandardSchemaV1;
|
|
10
11
|
/**
|
|
11
12
|
* Definition of an activity
|
|
12
13
|
*/
|
|
13
|
-
interface ActivityDefinition<TInput extends
|
|
14
|
+
interface ActivityDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
14
15
|
readonly input: TInput;
|
|
15
16
|
readonly output: TOutput;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Definition of a signal
|
|
19
20
|
*/
|
|
20
|
-
interface SignalDefinition<TInput extends
|
|
21
|
+
interface SignalDefinition<TInput extends AnySchema = AnySchema> {
|
|
21
22
|
readonly input: TInput;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Definition of a query
|
|
25
26
|
*/
|
|
26
|
-
interface QueryDefinition<TInput extends
|
|
27
|
+
interface QueryDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
27
28
|
readonly input: TInput;
|
|
28
29
|
readonly output: TOutput;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Definition of an update
|
|
32
33
|
*/
|
|
33
|
-
interface UpdateDefinition<TInput extends
|
|
34
|
+
interface UpdateDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
34
35
|
readonly input: TInput;
|
|
35
36
|
readonly output: TOutput;
|
|
36
37
|
}
|
|
@@ -38,8 +39,8 @@ interface UpdateDefinition<TInput extends AnyZodSchema = AnyZodSchema, TOutput e
|
|
|
38
39
|
* Definition of a workflow
|
|
39
40
|
*/
|
|
40
41
|
interface WorkflowDefinition<TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>, TSignals extends Record<string, SignalDefinition> = Record<string, SignalDefinition>, TQueries extends Record<string, QueryDefinition> = Record<string, QueryDefinition>, TUpdates extends Record<string, UpdateDefinition> = Record<string, UpdateDefinition>> {
|
|
41
|
-
readonly input:
|
|
42
|
-
readonly output:
|
|
42
|
+
readonly input: AnySchema;
|
|
43
|
+
readonly output: AnySchema;
|
|
43
44
|
readonly activities?: TActivities;
|
|
44
45
|
readonly signals?: TSignals;
|
|
45
46
|
readonly queries?: TQueries;
|
|
@@ -55,32 +56,32 @@ interface ContractDefinition<TWorkflows extends Record<string, WorkflowDefinitio
|
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Infer input type from a definition (worker perspective)
|
|
58
|
-
* Worker receives
|
|
59
|
+
* Worker receives the output type (after input schema parsing/transformation)
|
|
59
60
|
*/
|
|
60
61
|
type WorkerInferInput<T extends {
|
|
61
|
-
input:
|
|
62
|
-
}> =
|
|
62
|
+
input: AnySchema;
|
|
63
|
+
}> = StandardSchemaV1.InferOutput<T["input"]>;
|
|
63
64
|
/**
|
|
64
65
|
* Infer output type from a definition (worker perspective)
|
|
65
|
-
* Worker returns
|
|
66
|
+
* Worker returns the input type (before output schema parsing/transformation)
|
|
66
67
|
*/
|
|
67
68
|
type WorkerInferOutput<T extends {
|
|
68
|
-
output:
|
|
69
|
-
}> =
|
|
69
|
+
output: AnySchema;
|
|
70
|
+
}> = StandardSchemaV1.InferInput<T["output"]>;
|
|
70
71
|
/**
|
|
71
72
|
* Infer input type from a definition (client perspective)
|
|
72
|
-
* Client sends
|
|
73
|
+
* Client sends the input type (before input schema parsing/transformation)
|
|
73
74
|
*/
|
|
74
75
|
type ClientInferInput<T extends {
|
|
75
|
-
input:
|
|
76
|
-
}> =
|
|
76
|
+
input: AnySchema;
|
|
77
|
+
}> = StandardSchemaV1.InferInput<T["input"]>;
|
|
77
78
|
/**
|
|
78
79
|
* Infer output type from a definition (client perspective)
|
|
79
|
-
* Client receives
|
|
80
|
+
* Client receives the output type (after output schema parsing/transformation)
|
|
80
81
|
*/
|
|
81
82
|
type ClientInferOutput<T extends {
|
|
82
|
-
output:
|
|
83
|
-
}> =
|
|
83
|
+
output: AnySchema;
|
|
84
|
+
}> = StandardSchemaV1.InferOutput<T["output"]>;
|
|
84
85
|
/**
|
|
85
86
|
* WORKER PERSPECTIVE
|
|
86
87
|
* Worker receives z.output of input (parsed data) and returns z.input of output (raw data)
|
|
@@ -348,4 +349,4 @@ declare const defineWorkflow: <TWorkflow extends WorkflowDefinition>(definition:
|
|
|
348
349
|
*/
|
|
349
350
|
declare const defineContract: <TContract extends ContractDefinition>(definition: TContract) => TContract;
|
|
350
351
|
//#endregion
|
|
351
|
-
export { type ActivityDefinition, type ActivityHandler, type
|
|
352
|
+
export { type ActivityDefinition, type ActivityHandler, type AnySchema, type ClientInferActivities, type ClientInferActivity, type ClientInferInput, type ClientInferOutput, type ClientInferQuery, type ClientInferSignal, type ClientInferUpdate, type ClientInferWorkflow, type ClientInferWorkflowActivities, type ClientInferWorkflowContextActivities, type ClientInferWorkflowQueries, type ClientInferWorkflowSignals, type ClientInferWorkflowUpdates, type ClientInferWorkflows, type ContractDefinition, type InferActivityNames, type InferContractWorkflows, type InferWorkflowNames, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkerInferActivities, type WorkerInferActivity, type WorkerInferInput, type WorkerInferOutput, type WorkerInferQuery, type WorkerInferSignal, type WorkerInferUpdate, type WorkerInferWorkflow, type WorkerInferWorkflowActivities, type WorkerInferWorkflowContextActivities, type WorkerInferWorkflowQueries, type WorkerInferWorkflowSignals, type WorkerInferWorkflowUpdates, type WorkerInferWorkflows, type WorkflowActivityHandler, type WorkflowDefinition, defineActivity, defineContract, defineQuery, defineSignal, defineUpdate, defineWorkflow };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Base types for validation schemas
|
|
7
|
-
*
|
|
7
|
+
* Any schema that implements the Standard Schema specification
|
|
8
|
+
* This includes Zod, Valibot, ArkType, and other compatible libraries
|
|
8
9
|
*/
|
|
9
|
-
type
|
|
10
|
+
type AnySchema = StandardSchemaV1;
|
|
10
11
|
/**
|
|
11
12
|
* Definition of an activity
|
|
12
13
|
*/
|
|
13
|
-
interface ActivityDefinition<TInput extends
|
|
14
|
+
interface ActivityDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
14
15
|
readonly input: TInput;
|
|
15
16
|
readonly output: TOutput;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Definition of a signal
|
|
19
20
|
*/
|
|
20
|
-
interface SignalDefinition<TInput extends
|
|
21
|
+
interface SignalDefinition<TInput extends AnySchema = AnySchema> {
|
|
21
22
|
readonly input: TInput;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Definition of a query
|
|
25
26
|
*/
|
|
26
|
-
interface QueryDefinition<TInput extends
|
|
27
|
+
interface QueryDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
27
28
|
readonly input: TInput;
|
|
28
29
|
readonly output: TOutput;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Definition of an update
|
|
32
33
|
*/
|
|
33
|
-
interface UpdateDefinition<TInput extends
|
|
34
|
+
interface UpdateDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
|
|
34
35
|
readonly input: TInput;
|
|
35
36
|
readonly output: TOutput;
|
|
36
37
|
}
|
|
@@ -38,8 +39,8 @@ interface UpdateDefinition<TInput extends AnyZodSchema = AnyZodSchema, TOutput e
|
|
|
38
39
|
* Definition of a workflow
|
|
39
40
|
*/
|
|
40
41
|
interface WorkflowDefinition<TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>, TSignals extends Record<string, SignalDefinition> = Record<string, SignalDefinition>, TQueries extends Record<string, QueryDefinition> = Record<string, QueryDefinition>, TUpdates extends Record<string, UpdateDefinition> = Record<string, UpdateDefinition>> {
|
|
41
|
-
readonly input:
|
|
42
|
-
readonly output:
|
|
42
|
+
readonly input: AnySchema;
|
|
43
|
+
readonly output: AnySchema;
|
|
43
44
|
readonly activities?: TActivities;
|
|
44
45
|
readonly signals?: TSignals;
|
|
45
46
|
readonly queries?: TQueries;
|
|
@@ -55,32 +56,32 @@ interface ContractDefinition<TWorkflows extends Record<string, WorkflowDefinitio
|
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Infer input type from a definition (worker perspective)
|
|
58
|
-
* Worker receives
|
|
59
|
+
* Worker receives the output type (after input schema parsing/transformation)
|
|
59
60
|
*/
|
|
60
61
|
type WorkerInferInput<T extends {
|
|
61
|
-
input:
|
|
62
|
-
}> =
|
|
62
|
+
input: AnySchema;
|
|
63
|
+
}> = StandardSchemaV1.InferOutput<T["input"]>;
|
|
63
64
|
/**
|
|
64
65
|
* Infer output type from a definition (worker perspective)
|
|
65
|
-
* Worker returns
|
|
66
|
+
* Worker returns the input type (before output schema parsing/transformation)
|
|
66
67
|
*/
|
|
67
68
|
type WorkerInferOutput<T extends {
|
|
68
|
-
output:
|
|
69
|
-
}> =
|
|
69
|
+
output: AnySchema;
|
|
70
|
+
}> = StandardSchemaV1.InferInput<T["output"]>;
|
|
70
71
|
/**
|
|
71
72
|
* Infer input type from a definition (client perspective)
|
|
72
|
-
* Client sends
|
|
73
|
+
* Client sends the input type (before input schema parsing/transformation)
|
|
73
74
|
*/
|
|
74
75
|
type ClientInferInput<T extends {
|
|
75
|
-
input:
|
|
76
|
-
}> =
|
|
76
|
+
input: AnySchema;
|
|
77
|
+
}> = StandardSchemaV1.InferInput<T["input"]>;
|
|
77
78
|
/**
|
|
78
79
|
* Infer output type from a definition (client perspective)
|
|
79
|
-
* Client receives
|
|
80
|
+
* Client receives the output type (after output schema parsing/transformation)
|
|
80
81
|
*/
|
|
81
82
|
type ClientInferOutput<T extends {
|
|
82
|
-
output:
|
|
83
|
-
}> =
|
|
83
|
+
output: AnySchema;
|
|
84
|
+
}> = StandardSchemaV1.InferOutput<T["output"]>;
|
|
84
85
|
/**
|
|
85
86
|
* WORKER PERSPECTIVE
|
|
86
87
|
* Worker receives z.output of input (parsed data) and returns z.input of output (raw data)
|
|
@@ -348,4 +349,4 @@ declare const defineWorkflow: <TWorkflow extends WorkflowDefinition>(definition:
|
|
|
348
349
|
*/
|
|
349
350
|
declare const defineContract: <TContract extends ContractDefinition>(definition: TContract) => TContract;
|
|
350
351
|
//#endregion
|
|
351
|
-
export { type ActivityDefinition, type ActivityHandler, type
|
|
352
|
+
export { type ActivityDefinition, type ActivityHandler, type AnySchema, type ClientInferActivities, type ClientInferActivity, type ClientInferInput, type ClientInferOutput, type ClientInferQuery, type ClientInferSignal, type ClientInferUpdate, type ClientInferWorkflow, type ClientInferWorkflowActivities, type ClientInferWorkflowContextActivities, type ClientInferWorkflowQueries, type ClientInferWorkflowSignals, type ClientInferWorkflowUpdates, type ClientInferWorkflows, type ContractDefinition, type InferActivityNames, type InferContractWorkflows, type InferWorkflowNames, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkerInferActivities, type WorkerInferActivity, type WorkerInferInput, type WorkerInferOutput, type WorkerInferQuery, type WorkerInferSignal, type WorkerInferUpdate, type WorkerInferWorkflow, type WorkerInferWorkflowActivities, type WorkerInferWorkflowContextActivities, type WorkerInferWorkflowQueries, type WorkerInferWorkflowSignals, type WorkerInferWorkflowUpdates, type WorkerInferWorkflows, type WorkflowActivityHandler, type WorkflowDefinition, defineActivity, defineContract, defineQuery, defineSignal, defineUpdate, defineWorkflow };
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,14 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
//#region src/builder.ts
|
|
4
4
|
/**
|
|
5
|
+
* Check if a value is a Standard Schema compatible schema
|
|
6
|
+
*/
|
|
7
|
+
function isStandardSchema(value) {
|
|
8
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null || !("~standard" in value)) return false;
|
|
9
|
+
const standard = value["~standard"];
|
|
10
|
+
return typeof standard === "object" && standard !== null && standard["version"] === 1 && typeof standard["validate"] === "function";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
5
13
|
* Schema for validating JavaScript identifiers (workflow names, activity names, etc.)
|
|
6
14
|
* Allows: letters, digits, underscore, dollar sign
|
|
7
15
|
* Must start with: letter, underscore, or dollar sign
|
|
@@ -26,36 +34,36 @@ const getCleanErrorMessage = (error) => {
|
|
|
26
34
|
};
|
|
27
35
|
/**
|
|
28
36
|
* Schema for validating activity definitions
|
|
29
|
-
* Checks that input and output are
|
|
37
|
+
* Checks that input and output are Standard Schema compatible schemas
|
|
30
38
|
*/
|
|
31
39
|
const activityDefinitionSchema = z.object({
|
|
32
|
-
input: z.
|
|
33
|
-
output: z.
|
|
40
|
+
input: z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
41
|
+
output: z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
34
42
|
});
|
|
35
43
|
/**
|
|
36
44
|
* Schema for validating signal definitions
|
|
37
45
|
*/
|
|
38
|
-
const signalDefinitionSchema = z.object({ input: z.
|
|
46
|
+
const signalDefinitionSchema = z.object({ input: z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }) });
|
|
39
47
|
/**
|
|
40
48
|
* Schema for validating query definitions
|
|
41
49
|
*/
|
|
42
50
|
const queryDefinitionSchema = z.object({
|
|
43
|
-
input: z.
|
|
44
|
-
output: z.
|
|
51
|
+
input: z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
52
|
+
output: z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
45
53
|
});
|
|
46
54
|
/**
|
|
47
55
|
* Schema for validating update definitions
|
|
48
56
|
*/
|
|
49
57
|
const updateDefinitionSchema = z.object({
|
|
50
|
-
input: z.
|
|
51
|
-
output: z.
|
|
58
|
+
input: z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
59
|
+
output: z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" })
|
|
52
60
|
});
|
|
53
61
|
/**
|
|
54
62
|
* Schema for validating workflow definitions
|
|
55
63
|
*/
|
|
56
64
|
const workflowDefinitionSchema = z.object({
|
|
57
|
-
input: z.
|
|
58
|
-
output: z.
|
|
65
|
+
input: z.custom((val) => isStandardSchema(val), { message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
66
|
+
output: z.custom((val) => isStandardSchema(val), { message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)" }),
|
|
59
67
|
activities: z.record(identifierSchema, activityDefinitionSchema).optional(),
|
|
60
68
|
signals: z.record(identifierSchema, signalDefinitionSchema).optional(),
|
|
61
69
|
queries: z.record(identifierSchema, queryDefinitionSchema).optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporal-contract/contract",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Contract builder for temporal-contract",
|
|
6
6
|
"homepage": "https://github.com/btravers/temporal-contract#readme",
|
|
@@ -35,15 +35,18 @@
|
|
|
35
35
|
},
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@standard-schema/spec": "1.0.0",
|
|
40
|
+
"zod": "4.1.13"
|
|
41
|
+
},
|
|
38
42
|
"devDependencies": {
|
|
43
|
+
"@vitest/coverage-v8": "4.0.15",
|
|
44
|
+
"arktype": "2.1.28",
|
|
39
45
|
"tsdown": "0.17.2",
|
|
40
46
|
"typescript": "5.9.3",
|
|
47
|
+
"valibot": "1.2.0",
|
|
41
48
|
"vitest": "4.0.15",
|
|
42
|
-
"
|
|
43
|
-
"@temporal-contract/tsconfig": "0.0.1"
|
|
44
|
-
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"zod": "^4.0.0"
|
|
49
|
+
"@temporal-contract/tsconfig": "0.0.2"
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|
|
49
52
|
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
package/src/builder.spec.ts
CHANGED
|
@@ -622,4 +622,96 @@ describe("Contract Builder", () => {
|
|
|
622
622
|
).toThrow("Contract error");
|
|
623
623
|
});
|
|
624
624
|
});
|
|
625
|
+
|
|
626
|
+
describe("Standard Schema compatibility", () => {
|
|
627
|
+
it("should work with Valibot schemas", async () => {
|
|
628
|
+
const v = await import("valibot");
|
|
629
|
+
|
|
630
|
+
const contract = defineContract({
|
|
631
|
+
taskQueue: "test-queue",
|
|
632
|
+
workflows: {
|
|
633
|
+
processOrder: {
|
|
634
|
+
input: v.object({ orderId: v.string() }),
|
|
635
|
+
output: v.object({ status: v.string() }),
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
activities: {
|
|
639
|
+
sendEmail: {
|
|
640
|
+
input: v.object({ to: v.string(), subject: v.string() }),
|
|
641
|
+
output: v.object({ sent: v.boolean() }),
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
expect(contract.taskQueue).toBe("test-queue");
|
|
647
|
+
expect(contract.workflows.processOrder).toBeDefined();
|
|
648
|
+
expect(contract.activities?.sendEmail).toBeDefined();
|
|
649
|
+
|
|
650
|
+
// Verify Standard Schema properties exist
|
|
651
|
+
expect(contract.workflows.processOrder.input["~standard"]).toBeDefined();
|
|
652
|
+
expect(contract.workflows.processOrder.input["~standard"].version).toBe(1);
|
|
653
|
+
expect(contract.workflows.processOrder.input["~standard"].vendor).toBe("valibot");
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it("should work with ArkType schemas", async () => {
|
|
657
|
+
const { type } = await import("arktype");
|
|
658
|
+
|
|
659
|
+
const contract = defineContract({
|
|
660
|
+
taskQueue: "test-queue",
|
|
661
|
+
workflows: {
|
|
662
|
+
processOrder: {
|
|
663
|
+
input: type({ orderId: "string" }),
|
|
664
|
+
output: type({ status: "string" }),
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
activities: {
|
|
668
|
+
validatePayment: {
|
|
669
|
+
input: type({ amount: "number" }),
|
|
670
|
+
output: type({ valid: "boolean" }),
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
expect(contract.taskQueue).toBe("test-queue");
|
|
676
|
+
expect(contract.workflows.processOrder).toBeDefined();
|
|
677
|
+
expect(contract.activities?.validatePayment).toBeDefined();
|
|
678
|
+
|
|
679
|
+
// Verify Standard Schema properties exist
|
|
680
|
+
expect(contract.workflows.processOrder.input["~standard"]).toBeDefined();
|
|
681
|
+
expect(contract.workflows.processOrder.input["~standard"].version).toBe(1);
|
|
682
|
+
expect(contract.workflows.processOrder.input["~standard"].vendor).toBe("arktype");
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it("should work with mixed validation libraries", async () => {
|
|
686
|
+
const v = await import("valibot");
|
|
687
|
+
const { type } = await import("arktype");
|
|
688
|
+
|
|
689
|
+
const contract = defineContract({
|
|
690
|
+
taskQueue: "test-queue",
|
|
691
|
+
workflows: {
|
|
692
|
+
processZod: {
|
|
693
|
+
input: z.object({ id: z.string() }),
|
|
694
|
+
output: z.object({ result: z.string() }),
|
|
695
|
+
},
|
|
696
|
+
processValibot: {
|
|
697
|
+
input: v.object({ id: v.string() }),
|
|
698
|
+
output: v.object({ result: v.string() }),
|
|
699
|
+
},
|
|
700
|
+
processArkType: {
|
|
701
|
+
input: type({ id: "string" }),
|
|
702
|
+
output: type({ result: "string" }),
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
expect(contract.workflows.processZod).toBeDefined();
|
|
708
|
+
expect(contract.workflows.processValibot).toBeDefined();
|
|
709
|
+
expect(contract.workflows.processArkType).toBeDefined();
|
|
710
|
+
|
|
711
|
+
// Verify each has correct vendor
|
|
712
|
+
expect(contract.workflows.processZod.input["~standard"].vendor).toBe("zod");
|
|
713
|
+
expect(contract.workflows.processValibot.input["~standard"].vendor).toBe("valibot");
|
|
714
|
+
expect(contract.workflows.processArkType.input["~standard"].vendor).toBe("arktype");
|
|
715
|
+
});
|
|
716
|
+
});
|
|
625
717
|
});
|
package/src/builder.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
3
|
import type {
|
|
3
4
|
ActivityDefinition,
|
|
4
5
|
ContractDefinition,
|
|
@@ -8,6 +9,29 @@ import type {
|
|
|
8
9
|
WorkflowDefinition,
|
|
9
10
|
} from "./types.js";
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Check if a value is a Standard Schema compatible schema
|
|
14
|
+
*/
|
|
15
|
+
function isStandardSchema(value: unknown): value is StandardSchemaV1 {
|
|
16
|
+
// Standard Schema can be either an object or a function (e.g., ArkType)
|
|
17
|
+
if (
|
|
18
|
+
(typeof value !== "object" && typeof value !== "function") ||
|
|
19
|
+
value === null ||
|
|
20
|
+
!("~standard" in value)
|
|
21
|
+
) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const standard = (value as Record<string, unknown>)["~standard"];
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
typeof standard === "object" &&
|
|
29
|
+
standard !== null &&
|
|
30
|
+
(standard as Record<string, unknown>)["version"] === 1 &&
|
|
31
|
+
typeof (standard as Record<string, unknown>)["validate"] === "function"
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
11
35
|
/**
|
|
12
36
|
* Schema for validating JavaScript identifiers (workflow names, activity names, etc.)
|
|
13
37
|
* Allows: letters, digits, underscore, dollar sign
|
|
@@ -52,14 +76,14 @@ const getCleanErrorMessage = (error: z.ZodError): string => {
|
|
|
52
76
|
|
|
53
77
|
/**
|
|
54
78
|
* Schema for validating activity definitions
|
|
55
|
-
* Checks that input and output are
|
|
79
|
+
* Checks that input and output are Standard Schema compatible schemas
|
|
56
80
|
*/
|
|
57
81
|
const activityDefinitionSchema = z.object({
|
|
58
|
-
input: z.
|
|
59
|
-
message: "input must be a Zod
|
|
82
|
+
input: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
83
|
+
message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
60
84
|
}),
|
|
61
|
-
output: z.
|
|
62
|
-
message: "output must be a Zod
|
|
85
|
+
output: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
86
|
+
message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
63
87
|
}),
|
|
64
88
|
});
|
|
65
89
|
|
|
@@ -67,8 +91,8 @@ const activityDefinitionSchema = z.object({
|
|
|
67
91
|
* Schema for validating signal definitions
|
|
68
92
|
*/
|
|
69
93
|
const signalDefinitionSchema = z.object({
|
|
70
|
-
input: z.
|
|
71
|
-
message: "input must be a Zod
|
|
94
|
+
input: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
95
|
+
message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
72
96
|
}),
|
|
73
97
|
});
|
|
74
98
|
|
|
@@ -76,11 +100,11 @@ const signalDefinitionSchema = z.object({
|
|
|
76
100
|
* Schema for validating query definitions
|
|
77
101
|
*/
|
|
78
102
|
const queryDefinitionSchema = z.object({
|
|
79
|
-
input: z.
|
|
80
|
-
message: "input must be a Zod
|
|
103
|
+
input: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
104
|
+
message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
81
105
|
}),
|
|
82
|
-
output: z.
|
|
83
|
-
message: "output must be a Zod
|
|
106
|
+
output: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
107
|
+
message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
84
108
|
}),
|
|
85
109
|
});
|
|
86
110
|
|
|
@@ -88,11 +112,11 @@ const queryDefinitionSchema = z.object({
|
|
|
88
112
|
* Schema for validating update definitions
|
|
89
113
|
*/
|
|
90
114
|
const updateDefinitionSchema = z.object({
|
|
91
|
-
input: z.
|
|
92
|
-
message: "input must be a Zod
|
|
115
|
+
input: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
116
|
+
message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
93
117
|
}),
|
|
94
|
-
output: z.
|
|
95
|
-
message: "output must be a Zod
|
|
118
|
+
output: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
119
|
+
message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
96
120
|
}),
|
|
97
121
|
});
|
|
98
122
|
|
|
@@ -100,11 +124,11 @@ const updateDefinitionSchema = z.object({
|
|
|
100
124
|
* Schema for validating workflow definitions
|
|
101
125
|
*/
|
|
102
126
|
const workflowDefinitionSchema = z.object({
|
|
103
|
-
input: z.
|
|
104
|
-
message: "input must be a Zod
|
|
127
|
+
input: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
128
|
+
message: "input must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
105
129
|
}),
|
|
106
|
-
output: z.
|
|
107
|
-
message: "output must be a Zod
|
|
130
|
+
output: z.custom<StandardSchemaV1>((val) => isStandardSchema(val), {
|
|
131
|
+
message: "output must be a Standard Schema compatible schema (e.g., Zod, Valibot, ArkType)",
|
|
108
132
|
}),
|
|
109
133
|
activities: z.record(identifierSchema, activityDefinitionSchema).optional(),
|
|
110
134
|
signals: z.record(identifierSchema, signalDefinitionSchema).optional(),
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base types for validation schemas
|
|
5
|
-
*
|
|
5
|
+
* Any schema that implements the Standard Schema specification
|
|
6
|
+
* This includes Zod, Valibot, ArkType, and other compatible libraries
|
|
6
7
|
*/
|
|
7
|
-
export type
|
|
8
|
+
export type AnySchema = StandardSchemaV1;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Definition of an activity
|
|
11
12
|
*/
|
|
12
13
|
export interface ActivityDefinition<
|
|
13
|
-
TInput extends
|
|
14
|
-
TOutput extends
|
|
14
|
+
TInput extends AnySchema = AnySchema,
|
|
15
|
+
TOutput extends AnySchema = AnySchema,
|
|
15
16
|
> {
|
|
16
17
|
readonly input: TInput;
|
|
17
18
|
readonly output: TOutput;
|
|
@@ -20,7 +21,7 @@ export interface ActivityDefinition<
|
|
|
20
21
|
/**
|
|
21
22
|
* Definition of a signal
|
|
22
23
|
*/
|
|
23
|
-
export interface SignalDefinition<TInput extends
|
|
24
|
+
export interface SignalDefinition<TInput extends AnySchema = AnySchema> {
|
|
24
25
|
readonly input: TInput;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -28,8 +29,8 @@ export interface SignalDefinition<TInput extends AnyZodSchema = AnyZodSchema> {
|
|
|
28
29
|
* Definition of a query
|
|
29
30
|
*/
|
|
30
31
|
export interface QueryDefinition<
|
|
31
|
-
TInput extends
|
|
32
|
-
TOutput extends
|
|
32
|
+
TInput extends AnySchema = AnySchema,
|
|
33
|
+
TOutput extends AnySchema = AnySchema,
|
|
33
34
|
> {
|
|
34
35
|
readonly input: TInput;
|
|
35
36
|
readonly output: TOutput;
|
|
@@ -39,8 +40,8 @@ export interface QueryDefinition<
|
|
|
39
40
|
* Definition of an update
|
|
40
41
|
*/
|
|
41
42
|
export interface UpdateDefinition<
|
|
42
|
-
TInput extends
|
|
43
|
-
TOutput extends
|
|
43
|
+
TInput extends AnySchema = AnySchema,
|
|
44
|
+
TOutput extends AnySchema = AnySchema,
|
|
44
45
|
> {
|
|
45
46
|
readonly input: TInput;
|
|
46
47
|
readonly output: TOutput;
|
|
@@ -55,8 +56,8 @@ export interface WorkflowDefinition<
|
|
|
55
56
|
TQueries extends Record<string, QueryDefinition> = Record<string, QueryDefinition>,
|
|
56
57
|
TUpdates extends Record<string, UpdateDefinition> = Record<string, UpdateDefinition>,
|
|
57
58
|
> {
|
|
58
|
-
readonly input:
|
|
59
|
-
readonly output:
|
|
59
|
+
readonly input: AnySchema;
|
|
60
|
+
readonly output: AnySchema;
|
|
60
61
|
readonly activities?: TActivities;
|
|
61
62
|
readonly signals?: TSignals;
|
|
62
63
|
readonly queries?: TQueries;
|
|
@@ -77,27 +78,35 @@ export interface ContractDefinition<
|
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* Infer input type from a definition (worker perspective)
|
|
80
|
-
* Worker receives
|
|
81
|
+
* Worker receives the output type (after input schema parsing/transformation)
|
|
81
82
|
*/
|
|
82
|
-
export type WorkerInferInput<T extends { input:
|
|
83
|
+
export type WorkerInferInput<T extends { input: AnySchema }> = StandardSchemaV1.InferOutput<
|
|
84
|
+
T["input"]
|
|
85
|
+
>;
|
|
83
86
|
|
|
84
87
|
/**
|
|
85
88
|
* Infer output type from a definition (worker perspective)
|
|
86
|
-
* Worker returns
|
|
89
|
+
* Worker returns the input type (before output schema parsing/transformation)
|
|
87
90
|
*/
|
|
88
|
-
export type WorkerInferOutput<T extends { output:
|
|
91
|
+
export type WorkerInferOutput<T extends { output: AnySchema }> = StandardSchemaV1.InferInput<
|
|
92
|
+
T["output"]
|
|
93
|
+
>;
|
|
89
94
|
|
|
90
95
|
/**
|
|
91
96
|
* Infer input type from a definition (client perspective)
|
|
92
|
-
* Client sends
|
|
97
|
+
* Client sends the input type (before input schema parsing/transformation)
|
|
93
98
|
*/
|
|
94
|
-
export type ClientInferInput<T extends { input:
|
|
99
|
+
export type ClientInferInput<T extends { input: AnySchema }> = StandardSchemaV1.InferInput<
|
|
100
|
+
T["input"]
|
|
101
|
+
>;
|
|
95
102
|
|
|
96
103
|
/**
|
|
97
104
|
* Infer output type from a definition (client perspective)
|
|
98
|
-
* Client receives
|
|
105
|
+
* Client receives the output type (after output schema parsing/transformation)
|
|
99
106
|
*/
|
|
100
|
-
export type ClientInferOutput<T extends { output:
|
|
107
|
+
export type ClientInferOutput<T extends { output: AnySchema }> = StandardSchemaV1.InferOutput<
|
|
108
|
+
T["output"]
|
|
109
|
+
>;
|
|
101
110
|
|
|
102
111
|
/**
|
|
103
112
|
* WORKER PERSPECTIVE
|
package/vitest.config.ts
ADDED