@temporal-contract/contract 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +116 -0
- package/dist/index.d.cts +225 -1
- package/dist/index.d.mts +225 -1
- package/dist/index.mjs +115 -1
- package/package.json +19 -16
- package/.turbo/turbo-build.log +0 -17
- package/CHANGELOG.md +0 -7
- package/src/builder.spec.ts +0 -717
- package/src/builder.ts +0 -286
- package/src/helpers.spec.ts +0 -122
- package/src/index.ts +0 -55
- package/src/types.spec.ts +0 -637
- package/src/types.ts +0 -429
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -12
package/dist/index.mjs
CHANGED
|
@@ -190,4 +190,118 @@ const defineContract = (definition) => {
|
|
|
190
190
|
};
|
|
191
191
|
|
|
192
192
|
//#endregion
|
|
193
|
-
|
|
193
|
+
//#region src/nexus-types.ts
|
|
194
|
+
/**
|
|
195
|
+
* BUILDER FUNCTIONS (Proposed API)
|
|
196
|
+
* These would be added to builder.ts when Nexus support is implemented
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Builder for creating Nexus operation definitions
|
|
200
|
+
*
|
|
201
|
+
* @template TOperation - A NexusOperationDefinition containing input and output schemas
|
|
202
|
+
* @param definition - The Nexus operation definition with typed input/output schemas
|
|
203
|
+
* @returns The same definition with preserved types
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const processPayment = defineNexusOperation({
|
|
208
|
+
* input: z.object({ amount: z.number(), customerId: z.string() }),
|
|
209
|
+
* output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function defineNexusOperation(definition) {
|
|
214
|
+
return definition;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Builder for creating Nexus service definitions
|
|
218
|
+
*
|
|
219
|
+
* @template TService - A NexusServiceDefinition containing a record of operations
|
|
220
|
+
* @param definition - The Nexus service definition with typed operations
|
|
221
|
+
* @returns The same definition with preserved types
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const PaymentService = defineNexusService({
|
|
226
|
+
* operations: {
|
|
227
|
+
* processPayment: defineNexusOperation({ ... }),
|
|
228
|
+
* refundPayment: defineNexusOperation({ ... }),
|
|
229
|
+
* },
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
function defineNexusService(definition) {
|
|
234
|
+
return definition;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* USAGE EXAMPLE
|
|
238
|
+
*
|
|
239
|
+
* This example demonstrates the complete type-safe Nexus workflow:
|
|
240
|
+
*
|
|
241
|
+
* ```typescript
|
|
242
|
+
* import { defineContract, defineNexusService, defineNexusOperation } from '@temporal-contract/contract';
|
|
243
|
+
* import { z } from 'zod';
|
|
244
|
+
*
|
|
245
|
+
* // 1. Define contract with Nexus service
|
|
246
|
+
* const paymentContract = defineContract({
|
|
247
|
+
* taskQueue: 'payments',
|
|
248
|
+
* workflows: { ... },
|
|
249
|
+
* nexusServices: {
|
|
250
|
+
* PaymentService: defineNexusService({
|
|
251
|
+
* operations: {
|
|
252
|
+
* processPayment: defineNexusOperation({
|
|
253
|
+
* input: z.object({
|
|
254
|
+
* amount: z.number().positive(),
|
|
255
|
+
* customerId: z.string().uuid(),
|
|
256
|
+
* }),
|
|
257
|
+
* output: z.object({
|
|
258
|
+
* transactionId: z.string(),
|
|
259
|
+
* status: z.enum(['success', 'failed']),
|
|
260
|
+
* }),
|
|
261
|
+
* }),
|
|
262
|
+
* },
|
|
263
|
+
* }),
|
|
264
|
+
* },
|
|
265
|
+
* });
|
|
266
|
+
*
|
|
267
|
+
* // 2. Worker implementation (type-safe handlers)
|
|
268
|
+
* import { createNexusHandlers } from '@temporal-contract/worker';
|
|
269
|
+
*
|
|
270
|
+
* const nexusHandlers = createNexusHandlers(paymentContract, {
|
|
271
|
+
* PaymentService: {
|
|
272
|
+
* processPayment: async ({ amount, customerId }) => {
|
|
273
|
+
* // ✅ Fully typed parameters
|
|
274
|
+
* // ✅ Input automatically validated
|
|
275
|
+
* const payment = await processPaymentInDatabase(customerId, amount);
|
|
276
|
+
* // ✅ Return value validated against schema
|
|
277
|
+
* return {
|
|
278
|
+
* transactionId: payment.id,
|
|
279
|
+
* status: 'success',
|
|
280
|
+
* };
|
|
281
|
+
* },
|
|
282
|
+
* },
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // 3. Client usage (type-safe invocation)
|
|
286
|
+
* import { createNexusClient } from '@temporal-contract/client';
|
|
287
|
+
*
|
|
288
|
+
* const nexusClient = createNexusClient<typeof paymentContract>(connection, {
|
|
289
|
+
* namespace: 'payments-ns',
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
292
|
+
* // ✅ Fully typed invocation
|
|
293
|
+
* const result = await nexusClient.invoke('PaymentService', 'processPayment', {
|
|
294
|
+
* amount: 100,
|
|
295
|
+
* customerId: 'cust-123',
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* // ❌ TypeScript errors caught at compile time
|
|
299
|
+
* await nexusClient.invoke('PaymentService', 'processPayment', {
|
|
300
|
+
* amount: -50, // Error: amount must be positive
|
|
301
|
+
* customerId: 'invalid', // Error: customerId must be UUID
|
|
302
|
+
* });
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
//#endregion
|
|
307
|
+
export { defineActivity, defineContract, defineNexusOperation, defineNexusService, defineQuery, defineSignal, defineUpdate, defineWorkflow };
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporal-contract/contract",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.4",
|
|
5
4
|
"description": "Contract builder for temporal-contract",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"temporal",
|
|
7
|
+
"typescript",
|
|
8
|
+
"contract"
|
|
9
|
+
],
|
|
6
10
|
"homepage": "https://github.com/btravers/temporal-contract#readme",
|
|
7
11
|
"bugs": {
|
|
8
12
|
"url": "https://github.com/btravers/temporal-contract/issues"
|
|
@@ -12,16 +16,9 @@
|
|
|
12
16
|
"url": "https://github.com/btravers/temporal-contract.git",
|
|
13
17
|
"directory": "packages/contract"
|
|
14
18
|
},
|
|
15
|
-
"author": "Benoit TRAVERS <benoit.travers.frgmail.com>",
|
|
16
19
|
"license": "MIT",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"typescript",
|
|
20
|
-
"contract"
|
|
21
|
-
],
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"module": "./dist/index.mjs",
|
|
24
|
-
"types": "./dist/index.d.mts",
|
|
20
|
+
"author": "Benoit TRAVERS <benoit.travers.frgmail.com>",
|
|
21
|
+
"type": "module",
|
|
25
22
|
"exports": {
|
|
26
23
|
".": {
|
|
27
24
|
"import": {
|
|
@@ -35,6 +32,12 @@
|
|
|
35
32
|
},
|
|
36
33
|
"./package.json": "./package.json"
|
|
37
34
|
},
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"module": "./dist/index.mjs",
|
|
37
|
+
"types": "./dist/index.d.mts",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
38
41
|
"dependencies": {
|
|
39
42
|
"@standard-schema/spec": "1.0.0",
|
|
40
43
|
"zod": "4.1.13"
|
|
@@ -42,17 +45,17 @@
|
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@vitest/coverage-v8": "4.0.15",
|
|
44
47
|
"arktype": "2.1.28",
|
|
45
|
-
"tsdown": "0.17.
|
|
48
|
+
"tsdown": "0.17.3",
|
|
46
49
|
"typescript": "5.9.3",
|
|
47
50
|
"valibot": "1.2.0",
|
|
48
51
|
"vitest": "4.0.15",
|
|
49
|
-
"@temporal-contract/tsconfig": "0.0.
|
|
52
|
+
"@temporal-contract/tsconfig": "0.0.4"
|
|
50
53
|
},
|
|
51
54
|
"scripts": {
|
|
52
|
-
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
53
55
|
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
54
|
-
"
|
|
56
|
+
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
55
57
|
"test": "vitest run",
|
|
56
|
-
"test:watch": "vitest"
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
57
60
|
}
|
|
58
61
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @temporal-contract/contract@0.0.2 build /home/runner/work/temporal-contract/temporal-contract/packages/contract
|
|
3
|
-
> tsdown src/index.ts --format cjs,esm --dts --clean
|
|
4
|
-
|
|
5
|
-
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
6
|
-
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
7
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
8
|
-
[34mℹ[39m Build start
|
|
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
|