@temporal-contract/contract 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Contract builder and type definitions for Temporal workflows and activities
4
4
 
5
- **Core package** for defining type-safe contracts with Zod schemas.
5
+ [![npm version](https://img.shields.io/npm/v/@temporal-contract/contract.svg?logo=npm)](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
- ## What's Included
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: 'my-service',
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({ status: z.string() }),
75
-
76
- // Workflow-specific activities
77
- activities: {
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
- ### Helper Functions (Optional)
31
+ ## Documentation
89
32
 
90
- For standalone definitions outside a contract:
33
+ 📖 **[Read the full documentation →](https://btravers.github.io/temporal-contract)**
91
34
 
92
- ```typescript
93
- import { defineActivity, defineSignal, defineQuery, defineUpdate } from '@temporal-contract/contract';
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
- // Standalone activity
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
- ## Type Utilities\n\nHelper types for implementing activities with full type inference:\n\n### Activity Handlers\n\n`typescript\nimport type { ActivityHandler, WorkflowActivityHandler } from '@temporal-contract/contract';\n\n// Global activity\nconst sendEmail: ActivityHandler<typeof myContract, 'sendEmail'> = \n async ({ to, subject }) => {\n await emailService.send({ to, subject });\n return { sent: true };\n };\n\n// Workflow-specific activity\nconst processPayment: WorkflowActivityHandler<typeof myContract, 'processOrder', 'processPayment'> = \n async ({ amount }) => {\n const txId = await paymentGateway.charge(amount);\n return { transactionId: txId };\n };\n`\n\n### Contract Introspection\n\n`typescript\nimport type { InferWorkflowNames, InferActivityNames } from '@temporal-contract/contract';\n\ntype Workflows = InferWorkflowNames<typeof myContract>; // \"processOrder\" | ...\ntype Activities = InferActivityNames<typeof myContract>; // \"sendEmail\" | ...\n`\n\nSee [Activity Handlers documentation](../../docs/ACTIVITY_HANDLERS.md) for details.\n\n---\n\n## Learn More\n\n- [Main README](../../README.md) \u2014 Quick start guide\n- [Worker Implementation](../../docs/CONTRACT_HANDLER.md) \u2014 Implementing workers\n- [Activity Handlers](../../docs/ACTIVITY_HANDLERS.md) \u2014 Type utility details\n\n## License\n\nMIT
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 Zod schemas
37
+ * Checks that input and output are Standard Schema compatible schemas
30
38
  */
31
39
  const activityDefinitionSchema = zod.z.object({
32
- input: zod.z.instanceof(zod.z.ZodType, { message: "input must be a Zod schema" }),
33
- output: zod.z.instanceof(zod.z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(zod.z.ZodType, { message: "input must be a Zod schema" }) });
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.instanceof(zod.z.ZodType, { message: "input must be a Zod schema" }),
44
- output: zod.z.instanceof(zod.z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(zod.z.ZodType, { message: "input must be a Zod schema" }),
51
- output: zod.z.instanceof(zod.z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(zod.z.ZodType, { message: "input must be a Zod schema" }),
58
- output: zod.z.instanceof(zod.z.ZodType, { message: "output must be a Zod schema" }),
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 { z } from "zod";
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
- * Constrained to avoid implicit any types
7
+ * Any schema that implements the Standard Schema specification
8
+ * This includes Zod, Valibot, ArkType, and other compatible libraries
8
9
  */
9
- type AnyZodSchema = z.ZodType<unknown, unknown>;
10
+ type AnySchema = StandardSchemaV1;
10
11
  /**
11
12
  * Definition of an activity
12
13
  */
13
- interface ActivityDefinition<TInput extends AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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: AnyZodSchema;
42
- readonly output: AnyZodSchema;
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 z.output (after input schema parsing/transformation)
59
+ * Worker receives the output type (after input schema parsing/transformation)
59
60
  */
60
61
  type WorkerInferInput<T extends {
61
- input: AnyZodSchema;
62
- }> = z.output<T["input"]>;
62
+ input: AnySchema;
63
+ }> = StandardSchemaV1.InferOutput<T["input"]>;
63
64
  /**
64
65
  * Infer output type from a definition (worker perspective)
65
- * Worker returns z.input (before output schema parsing/transformation)
66
+ * Worker returns the input type (before output schema parsing/transformation)
66
67
  */
67
68
  type WorkerInferOutput<T extends {
68
- output: AnyZodSchema;
69
- }> = z.input<T["output"]>;
69
+ output: AnySchema;
70
+ }> = StandardSchemaV1.InferInput<T["output"]>;
70
71
  /**
71
72
  * Infer input type from a definition (client perspective)
72
- * Client sends z.input (before input schema parsing/transformation)
73
+ * Client sends the input type (before input schema parsing/transformation)
73
74
  */
74
75
  type ClientInferInput<T extends {
75
- input: AnyZodSchema;
76
- }> = z.input<T["input"]>;
76
+ input: AnySchema;
77
+ }> = StandardSchemaV1.InferInput<T["input"]>;
77
78
  /**
78
79
  * Infer output type from a definition (client perspective)
79
- * Client receives z.output (after output schema parsing/transformation)
80
+ * Client receives the output type (after output schema parsing/transformation)
80
81
  */
81
82
  type ClientInferOutput<T extends {
82
- output: AnyZodSchema;
83
- }> = z.output<T["output"]>;
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 AnyZodSchema, 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 };
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 { z } from "zod";
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
- * Constrained to avoid implicit any types
7
+ * Any schema that implements the Standard Schema specification
8
+ * This includes Zod, Valibot, ArkType, and other compatible libraries
8
9
  */
9
- type AnyZodSchema = z.ZodType<unknown, unknown>;
10
+ type AnySchema = StandardSchemaV1;
10
11
  /**
11
12
  * Definition of an activity
12
13
  */
13
- interface ActivityDefinition<TInput extends AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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 AnyZodSchema = AnyZodSchema, TOutput extends AnyZodSchema = AnyZodSchema> {
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: AnyZodSchema;
42
- readonly output: AnyZodSchema;
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 z.output (after input schema parsing/transformation)
59
+ * Worker receives the output type (after input schema parsing/transformation)
59
60
  */
60
61
  type WorkerInferInput<T extends {
61
- input: AnyZodSchema;
62
- }> = z.output<T["input"]>;
62
+ input: AnySchema;
63
+ }> = StandardSchemaV1.InferOutput<T["input"]>;
63
64
  /**
64
65
  * Infer output type from a definition (worker perspective)
65
- * Worker returns z.input (before output schema parsing/transformation)
66
+ * Worker returns the input type (before output schema parsing/transformation)
66
67
  */
67
68
  type WorkerInferOutput<T extends {
68
- output: AnyZodSchema;
69
- }> = z.input<T["output"]>;
69
+ output: AnySchema;
70
+ }> = StandardSchemaV1.InferInput<T["output"]>;
70
71
  /**
71
72
  * Infer input type from a definition (client perspective)
72
- * Client sends z.input (before input schema parsing/transformation)
73
+ * Client sends the input type (before input schema parsing/transformation)
73
74
  */
74
75
  type ClientInferInput<T extends {
75
- input: AnyZodSchema;
76
- }> = z.input<T["input"]>;
76
+ input: AnySchema;
77
+ }> = StandardSchemaV1.InferInput<T["input"]>;
77
78
  /**
78
79
  * Infer output type from a definition (client perspective)
79
- * Client receives z.output (after output schema parsing/transformation)
80
+ * Client receives the output type (after output schema parsing/transformation)
80
81
  */
81
82
  type ClientInferOutput<T extends {
82
- output: AnyZodSchema;
83
- }> = z.output<T["output"]>;
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 AnyZodSchema, 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 };
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 Zod schemas
37
+ * Checks that input and output are Standard Schema compatible schemas
30
38
  */
31
39
  const activityDefinitionSchema = z.object({
32
- input: z.instanceof(z.ZodType, { message: "input must be a Zod schema" }),
33
- output: z.instanceof(z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(z.ZodType, { message: "input must be a Zod schema" }) });
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.instanceof(z.ZodType, { message: "input must be a Zod schema" }),
44
- output: z.instanceof(z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(z.ZodType, { message: "input must be a Zod schema" }),
51
- output: z.instanceof(z.ZodType, { message: "output must be a Zod schema" })
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.instanceof(z.ZodType, { message: "input must be a Zod schema" }),
58
- output: z.instanceof(z.ZodType, { message: "output must be a Zod schema" }),
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.1",
3
+ "version": "0.0.3",
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,21 @@
35
35
  },
36
36
  "./package.json": "./package.json"
37
37
  },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "dependencies": {
42
+ "@standard-schema/spec": "1.0.0",
43
+ "zod": "4.1.13"
44
+ },
38
45
  "devDependencies": {
46
+ "@vitest/coverage-v8": "4.0.15",
47
+ "arktype": "2.1.28",
39
48
  "tsdown": "0.17.2",
40
49
  "typescript": "5.9.3",
50
+ "valibot": "1.2.0",
41
51
  "vitest": "4.0.15",
42
- "zod": "4.1.13",
43
- "@temporal-contract/tsconfig": "0.0.1"
44
- },
45
- "peerDependencies": {
46
- "zod": "^4.0.0"
52
+ "@temporal-contract/tsconfig": "0.0.3"
47
53
  },
48
54
  "scripts": {
49
55
  "dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
@@ -1,17 +0,0 @@
1
-
2
- > @temporal-contract/contract@0.0.1 build /home/runner/work/temporal-contract/temporal-contract/packages/contract
3
- > tsdown src/index.ts --format cjs,esm --dts --clean
4
-
5
- ℹ tsdown v0.17.2 powered by rolldown v1.0.0-beta.53
6
- ℹ entry: src/index.ts
7
- ℹ tsconfig: tsconfig.json
8
- ℹ Build start
9
- ℹ [CJS] dist/index.cjs 5.96 kB │ gzip: 1.51 kB
10
- ℹ [CJS] 1 files, total: 5.96 kB
11
- ℹ [CJS] dist/index.d.cts 15.50 kB │ gzip: 2.50 kB
12
- ℹ [CJS] 1 files, total: 15.50 kB
13
- ℹ [ESM] dist/index.mjs  5.69 kB │ gzip: 1.49 kB
14
- ℹ [ESM] dist/index.d.mts 15.50 kB │ gzip: 2.50 kB
15
- ℹ [ESM] 2 files, total: 21.19 kB
16
- ✔ Build complete in 2205ms
17
- ✔ Build complete in 2206ms