@temporal-contract/contract 0.0.5 → 0.0.6

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/index.cjs CHANGED
@@ -1,6 +1,29 @@
1
1
  let zod = require("zod");
2
2
 
3
3
  //#region src/builder.ts
4
+ function defineActivity(definition) {
5
+ return definition;
6
+ }
7
+ function defineSignal(definition) {
8
+ return definition;
9
+ }
10
+ function defineQuery(definition) {
11
+ return definition;
12
+ }
13
+ function defineUpdate(definition) {
14
+ return definition;
15
+ }
16
+ function defineWorkflow(definition) {
17
+ return definition;
18
+ }
19
+ function defineContract(definition) {
20
+ const validationResult = contractValidationSchema.safeParse(definition);
21
+ if (!validationResult.success) {
22
+ const cleanMessage = getCleanErrorMessage(validationResult.error);
23
+ throw new Error(`Contract error: ${cleanMessage}`);
24
+ }
25
+ return definition;
26
+ }
4
27
  /**
5
28
  * Check if a value is a Standard Schema compatible schema
6
29
  */
@@ -18,7 +41,7 @@ const identifierSchema = zod.z.string().min(1).regex(/^[a-zA-Z_$][a-zA-Z0-9_$]*$
18
41
  /**
19
42
  * Extract clean error message from Zod validation error
20
43
  */
21
- const getCleanErrorMessage = (error) => {
44
+ function getCleanErrorMessage(error) {
22
45
  try {
23
46
  const parsed = JSON.parse(error.message);
24
47
  if (Array.isArray(parsed) && parsed.length > 0) {
@@ -31,7 +54,7 @@ const getCleanErrorMessage = (error) => {
31
54
  }
32
55
  } catch {}
33
56
  return error.message;
34
- };
57
+ }
35
58
  /**
36
59
  * Schema for validating activity definitions
37
60
  * Checks that input and output are Standard Schema compatible schemas
@@ -88,106 +111,6 @@ const contractValidationSchema = zod.z.object({
88
111
  }
89
112
  }
90
113
  });
91
- /**
92
- * Builder for creating activity definitions
93
- *
94
- * @example
95
- * ```ts
96
- * const myActivity = defineActivity({
97
- * input: z.tuple([z.object({ name: z.string() })]),
98
- * output: z.object({ greeting: z.string() }),
99
- * });
100
- * ```
101
- */
102
- const defineActivity = (definition) => {
103
- return definition;
104
- };
105
- /**
106
- * Builder for creating signal definitions
107
- *
108
- * @example
109
- * ```ts
110
- * const mySignal = defineSignal({
111
- * input: z.object({ message: z.string() }),
112
- * });
113
- * ```
114
- */
115
- const defineSignal = (definition) => {
116
- return definition;
117
- };
118
- /**
119
- * Builder for creating query definitions
120
- *
121
- * @example
122
- * ```ts
123
- * const myQuery = defineQuery({
124
- * input: z.object({ id: z.string() }),
125
- * output: z.object({ status: z.string() }),
126
- * });
127
- * ```
128
- */
129
- const defineQuery = (definition) => {
130
- return definition;
131
- };
132
- /**
133
- * Builder for creating update definitions
134
- *
135
- * @example
136
- * ```ts
137
- * const myUpdate = defineUpdate({
138
- * input: z.object({ value: z.number() }),
139
- * output: z.object({ newValue: z.number() }),
140
- * });
141
- * ```
142
- */
143
- const defineUpdate = (definition) => {
144
- return definition;
145
- };
146
- /**
147
- * Builder for creating workflow definitions
148
- *
149
- * @example
150
- * ```ts
151
- * const myWorkflow = defineWorkflow({
152
- * input: z.tuple([z.object({ orderId: z.string() })]),
153
- * output: z.object({ status: z.string() }),
154
- * activities: {
155
- * processPayment: defineActivity({
156
- * input: z.tuple([z.object({ amount: z.number() })]),
157
- * output: z.object({ success: z.boolean() }),
158
- * }),
159
- * },
160
- * });
161
- * ```
162
- */
163
- const defineWorkflow = (definition) => {
164
- return definition;
165
- };
166
- /**
167
- * Builder for creating a complete contract
168
- *
169
- * @example
170
- * ```ts
171
- * const myContract = defineContract({
172
- * taskQueue: 'my-service',
173
- * workflows: {
174
- * processOrder: defineWorkflow({ ... }),
175
- * sendNotification: defineWorkflow({ ... }),
176
- * },
177
- * activities: {
178
- * sendEmail: defineActivity({ ... }),
179
- * },
180
- * });
181
- * ```
182
- */
183
- const defineContract = (definition) => {
184
- const validationResult = contractValidationSchema.safeParse(definition);
185
- if (!validationResult.success) {
186
- const cleanMessage = getCleanErrorMessage(validationResult.error);
187
- throw new Error(`Contract error: ${cleanMessage}`);
188
- }
189
- return definition;
190
- };
191
114
 
192
115
  //#endregion
193
116
  //#region src/nexus-types.ts
package/dist/index.d.cts CHANGED
@@ -88,89 +88,12 @@ type InferActivityNames<TContract extends ContractDefinition> = TContract["activ
88
88
  type InferContractWorkflows<TContract extends ContractDefinition> = TContract["workflows"];
89
89
  //#endregion
90
90
  //#region src/builder.d.ts
91
- /**
92
- * Builder for creating activity definitions
93
- *
94
- * @example
95
- * ```ts
96
- * const myActivity = defineActivity({
97
- * input: z.tuple([z.object({ name: z.string() })]),
98
- * output: z.object({ greeting: z.string() }),
99
- * });
100
- * ```
101
- */
102
- declare const defineActivity: <TActivity extends ActivityDefinition>(definition: TActivity) => TActivity;
103
- /**
104
- * Builder for creating signal definitions
105
- *
106
- * @example
107
- * ```ts
108
- * const mySignal = defineSignal({
109
- * input: z.object({ message: z.string() }),
110
- * });
111
- * ```
112
- */
113
- declare const defineSignal: <TSignal extends SignalDefinition>(definition: TSignal) => TSignal;
114
- /**
115
- * Builder for creating query definitions
116
- *
117
- * @example
118
- * ```ts
119
- * const myQuery = defineQuery({
120
- * input: z.object({ id: z.string() }),
121
- * output: z.object({ status: z.string() }),
122
- * });
123
- * ```
124
- */
125
- declare const defineQuery: <TQuery extends QueryDefinition>(definition: TQuery) => TQuery;
126
- /**
127
- * Builder for creating update definitions
128
- *
129
- * @example
130
- * ```ts
131
- * const myUpdate = defineUpdate({
132
- * input: z.object({ value: z.number() }),
133
- * output: z.object({ newValue: z.number() }),
134
- * });
135
- * ```
136
- */
137
- declare const defineUpdate: <TUpdate extends UpdateDefinition>(definition: TUpdate) => TUpdate;
138
- /**
139
- * Builder for creating workflow definitions
140
- *
141
- * @example
142
- * ```ts
143
- * const myWorkflow = defineWorkflow({
144
- * input: z.tuple([z.object({ orderId: z.string() })]),
145
- * output: z.object({ status: z.string() }),
146
- * activities: {
147
- * processPayment: defineActivity({
148
- * input: z.tuple([z.object({ amount: z.number() })]),
149
- * output: z.object({ success: z.boolean() }),
150
- * }),
151
- * },
152
- * });
153
- * ```
154
- */
155
- declare const defineWorkflow: <TWorkflow extends WorkflowDefinition>(definition: TWorkflow) => TWorkflow;
156
- /**
157
- * Builder for creating a complete contract
158
- *
159
- * @example
160
- * ```ts
161
- * const myContract = defineContract({
162
- * taskQueue: 'my-service',
163
- * workflows: {
164
- * processOrder: defineWorkflow({ ... }),
165
- * sendNotification: defineWorkflow({ ... }),
166
- * },
167
- * activities: {
168
- * sendEmail: defineActivity({ ... }),
169
- * },
170
- * });
171
- * ```
172
- */
173
- declare const defineContract: <TContract extends ContractDefinition>(definition: TContract) => TContract;
91
+ declare function defineActivity<TActivity extends ActivityDefinition>(definition: TActivity): TActivity;
92
+ declare function defineSignal<TSignal extends SignalDefinition>(definition: TSignal): TSignal;
93
+ declare function defineQuery<TQuery extends QueryDefinition>(definition: TQuery): TQuery;
94
+ declare function defineUpdate<TUpdate extends UpdateDefinition>(definition: TUpdate): TUpdate;
95
+ declare function defineWorkflow<TWorkflow extends WorkflowDefinition>(definition: TWorkflow): TWorkflow;
96
+ declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
174
97
  //#endregion
175
98
  //#region src/nexus-types.d.ts
176
99
  /**
package/dist/index.d.mts CHANGED
@@ -88,89 +88,12 @@ type InferActivityNames<TContract extends ContractDefinition> = TContract["activ
88
88
  type InferContractWorkflows<TContract extends ContractDefinition> = TContract["workflows"];
89
89
  //#endregion
90
90
  //#region src/builder.d.ts
91
- /**
92
- * Builder for creating activity definitions
93
- *
94
- * @example
95
- * ```ts
96
- * const myActivity = defineActivity({
97
- * input: z.tuple([z.object({ name: z.string() })]),
98
- * output: z.object({ greeting: z.string() }),
99
- * });
100
- * ```
101
- */
102
- declare const defineActivity: <TActivity extends ActivityDefinition>(definition: TActivity) => TActivity;
103
- /**
104
- * Builder for creating signal definitions
105
- *
106
- * @example
107
- * ```ts
108
- * const mySignal = defineSignal({
109
- * input: z.object({ message: z.string() }),
110
- * });
111
- * ```
112
- */
113
- declare const defineSignal: <TSignal extends SignalDefinition>(definition: TSignal) => TSignal;
114
- /**
115
- * Builder for creating query definitions
116
- *
117
- * @example
118
- * ```ts
119
- * const myQuery = defineQuery({
120
- * input: z.object({ id: z.string() }),
121
- * output: z.object({ status: z.string() }),
122
- * });
123
- * ```
124
- */
125
- declare const defineQuery: <TQuery extends QueryDefinition>(definition: TQuery) => TQuery;
126
- /**
127
- * Builder for creating update definitions
128
- *
129
- * @example
130
- * ```ts
131
- * const myUpdate = defineUpdate({
132
- * input: z.object({ value: z.number() }),
133
- * output: z.object({ newValue: z.number() }),
134
- * });
135
- * ```
136
- */
137
- declare const defineUpdate: <TUpdate extends UpdateDefinition>(definition: TUpdate) => TUpdate;
138
- /**
139
- * Builder for creating workflow definitions
140
- *
141
- * @example
142
- * ```ts
143
- * const myWorkflow = defineWorkflow({
144
- * input: z.tuple([z.object({ orderId: z.string() })]),
145
- * output: z.object({ status: z.string() }),
146
- * activities: {
147
- * processPayment: defineActivity({
148
- * input: z.tuple([z.object({ amount: z.number() })]),
149
- * output: z.object({ success: z.boolean() }),
150
- * }),
151
- * },
152
- * });
153
- * ```
154
- */
155
- declare const defineWorkflow: <TWorkflow extends WorkflowDefinition>(definition: TWorkflow) => TWorkflow;
156
- /**
157
- * Builder for creating a complete contract
158
- *
159
- * @example
160
- * ```ts
161
- * const myContract = defineContract({
162
- * taskQueue: 'my-service',
163
- * workflows: {
164
- * processOrder: defineWorkflow({ ... }),
165
- * sendNotification: defineWorkflow({ ... }),
166
- * },
167
- * activities: {
168
- * sendEmail: defineActivity({ ... }),
169
- * },
170
- * });
171
- * ```
172
- */
173
- declare const defineContract: <TContract extends ContractDefinition>(definition: TContract) => TContract;
91
+ declare function defineActivity<TActivity extends ActivityDefinition>(definition: TActivity): TActivity;
92
+ declare function defineSignal<TSignal extends SignalDefinition>(definition: TSignal): TSignal;
93
+ declare function defineQuery<TQuery extends QueryDefinition>(definition: TQuery): TQuery;
94
+ declare function defineUpdate<TUpdate extends UpdateDefinition>(definition: TUpdate): TUpdate;
95
+ declare function defineWorkflow<TWorkflow extends WorkflowDefinition>(definition: TWorkflow): TWorkflow;
96
+ declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
174
97
  //#endregion
175
98
  //#region src/nexus-types.d.ts
176
99
  /**
package/dist/index.mjs CHANGED
@@ -1,6 +1,29 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/builder.ts
4
+ function defineActivity(definition) {
5
+ return definition;
6
+ }
7
+ function defineSignal(definition) {
8
+ return definition;
9
+ }
10
+ function defineQuery(definition) {
11
+ return definition;
12
+ }
13
+ function defineUpdate(definition) {
14
+ return definition;
15
+ }
16
+ function defineWorkflow(definition) {
17
+ return definition;
18
+ }
19
+ function defineContract(definition) {
20
+ const validationResult = contractValidationSchema.safeParse(definition);
21
+ if (!validationResult.success) {
22
+ const cleanMessage = getCleanErrorMessage(validationResult.error);
23
+ throw new Error(`Contract error: ${cleanMessage}`);
24
+ }
25
+ return definition;
26
+ }
4
27
  /**
5
28
  * Check if a value is a Standard Schema compatible schema
6
29
  */
@@ -18,7 +41,7 @@ const identifierSchema = z.string().min(1).regex(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/, "
18
41
  /**
19
42
  * Extract clean error message from Zod validation error
20
43
  */
21
- const getCleanErrorMessage = (error) => {
44
+ function getCleanErrorMessage(error) {
22
45
  try {
23
46
  const parsed = JSON.parse(error.message);
24
47
  if (Array.isArray(parsed) && parsed.length > 0) {
@@ -31,7 +54,7 @@ const getCleanErrorMessage = (error) => {
31
54
  }
32
55
  } catch {}
33
56
  return error.message;
34
- };
57
+ }
35
58
  /**
36
59
  * Schema for validating activity definitions
37
60
  * Checks that input and output are Standard Schema compatible schemas
@@ -88,106 +111,6 @@ const contractValidationSchema = z.object({
88
111
  }
89
112
  }
90
113
  });
91
- /**
92
- * Builder for creating activity definitions
93
- *
94
- * @example
95
- * ```ts
96
- * const myActivity = defineActivity({
97
- * input: z.tuple([z.object({ name: z.string() })]),
98
- * output: z.object({ greeting: z.string() }),
99
- * });
100
- * ```
101
- */
102
- const defineActivity = (definition) => {
103
- return definition;
104
- };
105
- /**
106
- * Builder for creating signal definitions
107
- *
108
- * @example
109
- * ```ts
110
- * const mySignal = defineSignal({
111
- * input: z.object({ message: z.string() }),
112
- * });
113
- * ```
114
- */
115
- const defineSignal = (definition) => {
116
- return definition;
117
- };
118
- /**
119
- * Builder for creating query definitions
120
- *
121
- * @example
122
- * ```ts
123
- * const myQuery = defineQuery({
124
- * input: z.object({ id: z.string() }),
125
- * output: z.object({ status: z.string() }),
126
- * });
127
- * ```
128
- */
129
- const defineQuery = (definition) => {
130
- return definition;
131
- };
132
- /**
133
- * Builder for creating update definitions
134
- *
135
- * @example
136
- * ```ts
137
- * const myUpdate = defineUpdate({
138
- * input: z.object({ value: z.number() }),
139
- * output: z.object({ newValue: z.number() }),
140
- * });
141
- * ```
142
- */
143
- const defineUpdate = (definition) => {
144
- return definition;
145
- };
146
- /**
147
- * Builder for creating workflow definitions
148
- *
149
- * @example
150
- * ```ts
151
- * const myWorkflow = defineWorkflow({
152
- * input: z.tuple([z.object({ orderId: z.string() })]),
153
- * output: z.object({ status: z.string() }),
154
- * activities: {
155
- * processPayment: defineActivity({
156
- * input: z.tuple([z.object({ amount: z.number() })]),
157
- * output: z.object({ success: z.boolean() }),
158
- * }),
159
- * },
160
- * });
161
- * ```
162
- */
163
- const defineWorkflow = (definition) => {
164
- return definition;
165
- };
166
- /**
167
- * Builder for creating a complete contract
168
- *
169
- * @example
170
- * ```ts
171
- * const myContract = defineContract({
172
- * taskQueue: 'my-service',
173
- * workflows: {
174
- * processOrder: defineWorkflow({ ... }),
175
- * sendNotification: defineWorkflow({ ... }),
176
- * },
177
- * activities: {
178
- * sendEmail: defineActivity({ ... }),
179
- * },
180
- * });
181
- * ```
182
- */
183
- const defineContract = (definition) => {
184
- const validationResult = contractValidationSchema.safeParse(definition);
185
- if (!validationResult.success) {
186
- const cleanMessage = getCleanErrorMessage(validationResult.error);
187
- throw new Error(`Contract error: ${cleanMessage}`);
188
- }
189
- return definition;
190
- };
191
114
 
192
115
  //#endregion
193
116
  //#region src/nexus-types.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporal-contract/contract",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Contract builder for temporal-contract",
5
5
  "keywords": [
6
6
  "contract",
@@ -17,7 +17,7 @@
17
17
  "directory": "packages/contract"
18
18
  },
19
19
  "license": "MIT",
20
- "author": "Benoit TRAVERS <benoit.travers.frgmail.com>",
20
+ "author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
@@ -45,11 +45,11 @@
45
45
  "devDependencies": {
46
46
  "@vitest/coverage-v8": "4.0.16",
47
47
  "arktype": "2.1.29",
48
- "tsdown": "0.18.0",
48
+ "tsdown": "0.18.1",
49
49
  "typescript": "5.9.3",
50
50
  "valibot": "1.2.0",
51
51
  "vitest": "4.0.16",
52
- "@temporal-contract/tsconfig": "0.0.5"
52
+ "@temporal-contract/tsconfig": "0.0.6"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown src/index.ts --format cjs,esm --dts --clean",