@temporal-contract/contract 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,18 +13,20 @@ pnpm add @temporal-contract/contract zod
13
13
  ## Quick Example
14
14
 
15
15
  ```typescript
16
- import { defineContract } from '@temporal-contract/contract';
17
- import { z } from 'zod';
16
+ import { defineContract } from "@temporal-contract/contract";
17
+ import { z } from "zod";
18
18
 
19
19
  export const myContract = defineContract({
20
- taskQueue: 'orders',
20
+ taskQueue: "orders",
21
21
  workflows: {
22
22
  processOrder: {
23
23
  input: z.object({ orderId: z.string() }),
24
24
  output: z.object({ success: z.boolean() }),
25
- activities: { /* ... */ }
26
- }
27
- }
25
+ activities: {
26
+ /* ... */
27
+ },
28
+ },
29
+ },
28
30
  });
29
31
  ```
30
32
 
package/dist/index.cjs CHANGED
@@ -300,125 +300,9 @@ const contractValidationSchema = zod.z.object({
300
300
  }
301
301
  });
302
302
 
303
- //#endregion
304
- //#region src/nexus-types.ts
305
- /**
306
- * BUILDER FUNCTIONS (Proposed API)
307
- * These would be added to builder.ts when Nexus support is implemented
308
- */
309
- /**
310
- * Builder for creating Nexus operation definitions
311
- *
312
- * @template TOperation - A NexusOperationDefinition containing input and output schemas
313
- * @param definition - The Nexus operation definition with typed input/output schemas
314
- * @returns The same definition with preserved types
315
- *
316
- * @example
317
- * ```typescript
318
- * const processPayment = defineNexusOperation({
319
- * input: z.object({ amount: z.number(), customerId: z.string() }),
320
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
321
- * });
322
- * ```
323
- */
324
- function defineNexusOperation(definition) {
325
- return definition;
326
- }
327
- /**
328
- * Builder for creating Nexus service definitions
329
- *
330
- * @template TService - A NexusServiceDefinition containing a record of operations
331
- * @param definition - The Nexus service definition with typed operations
332
- * @returns The same definition with preserved types
333
- *
334
- * @example
335
- * ```typescript
336
- * const PaymentService = defineNexusService({
337
- * operations: {
338
- * processPayment: defineNexusOperation({ ... }),
339
- * refundPayment: defineNexusOperation({ ... }),
340
- * },
341
- * });
342
- * ```
343
- */
344
- function defineNexusService(definition) {
345
- return definition;
346
- }
347
- /**
348
- * USAGE EXAMPLE
349
- *
350
- * This example demonstrates the complete type-safe Nexus workflow:
351
- *
352
- * ```typescript
353
- * import { defineContract, defineNexusService, defineNexusOperation } from '@temporal-contract/contract';
354
- * import { z } from 'zod';
355
- *
356
- * // 1. Define contract with Nexus service
357
- * const paymentContract = defineContract({
358
- * taskQueue: 'payments',
359
- * workflows: { ... },
360
- * nexusServices: {
361
- * PaymentService: defineNexusService({
362
- * operations: {
363
- * processPayment: defineNexusOperation({
364
- * input: z.object({
365
- * amount: z.number().positive(),
366
- * customerId: z.string().uuid(),
367
- * }),
368
- * output: z.object({
369
- * transactionId: z.string(),
370
- * status: z.enum(['success', 'failed']),
371
- * }),
372
- * }),
373
- * },
374
- * }),
375
- * },
376
- * });
377
- *
378
- * // 2. Worker implementation (type-safe handlers)
379
- * import { createNexusHandlers } from '@temporal-contract/worker';
380
- *
381
- * const nexusHandlers = createNexusHandlers(paymentContract, {
382
- * PaymentService: {
383
- * processPayment: async ({ amount, customerId }) => {
384
- * // ✅ Fully typed parameters
385
- * // ✅ Input automatically validated
386
- * const payment = await processPaymentInDatabase(customerId, amount);
387
- * // ✅ Return value validated against schema
388
- * return {
389
- * transactionId: payment.id,
390
- * status: 'success',
391
- * };
392
- * },
393
- * },
394
- * });
395
- *
396
- * // 3. Client usage (type-safe invocation)
397
- * import { createNexusClient } from '@temporal-contract/client';
398
- *
399
- * const nexusClient = createNexusClient<typeof paymentContract>(connection, {
400
- * namespace: 'payments-ns',
401
- * });
402
- *
403
- * // ✅ Fully typed invocation
404
- * const result = await nexusClient.invoke('PaymentService', 'processPayment', {
405
- * amount: 100,
406
- * customerId: 'cust-123',
407
- * });
408
- *
409
- * // ❌ TypeScript errors caught at compile time
410
- * await nexusClient.invoke('PaymentService', 'processPayment', {
411
- * amount: -50, // Error: amount must be positive
412
- * customerId: 'invalid', // Error: customerId must be UUID
413
- * });
414
- * ```
415
- */
416
-
417
303
  //#endregion
418
304
  exports.defineActivity = defineActivity;
419
305
  exports.defineContract = defineContract;
420
- exports.defineNexusOperation = defineNexusOperation;
421
- exports.defineNexusService = defineNexusService;
422
306
  exports.defineQuery = defineQuery;
423
307
  exports.defineSignal = defineSignal;
424
308
  exports.defineUpdate = defineUpdate;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { StandardSchemaV1 } from "@standard-schema/spec";
2
2
 
3
3
  //#region src/types.d.ts
4
-
5
4
  /**
6
5
  * Base types for validation schemas
7
6
  * Any schema that implements the Standard Schema specification
@@ -283,228 +282,4 @@ declare function defineWorkflow<TWorkflow extends WorkflowDefinition>(definition
283
282
  */
284
283
  declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
285
284
  //#endregion
286
- //#region src/nexus-types.d.ts
287
- /**
288
- * Definition of a Nexus operation
289
- * Similar to ActivityDefinition but for cross-namespace operations
290
- *
291
- * @example
292
- * ```typescript
293
- * const processPayment = {
294
- * input: z.object({ amount: z.number(), customerId: z.string() }),
295
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
296
- * };
297
- * ```
298
- */
299
- interface NexusOperationDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
300
- readonly input: TInput;
301
- readonly output: TOutput;
302
- }
303
- /**
304
- * Definition of a Nexus service containing multiple operations
305
- *
306
- * @example
307
- * ```typescript
308
- * const PaymentService = {
309
- * operations: {
310
- * processPayment: { input: ..., output: ... },
311
- * refundPayment: { input: ..., output: ... },
312
- * },
313
- * };
314
- * ```
315
- */
316
- interface NexusServiceDefinition<TOperations extends Record<string, NexusOperationDefinition> = Record<string, NexusOperationDefinition>> {
317
- readonly operations: TOperations;
318
- }
319
- /**
320
- * Extended ContractDefinition that includes Nexus services
321
- * This would replace the current ContractDefinition when Nexus support is added
322
- *
323
- * @example
324
- * ```typescript
325
- * const contract = defineContract({
326
- * taskQueue: 'payments',
327
- * workflows: { ... },
328
- * activities: { ... },
329
- * nexusServices: {
330
- * PaymentService: {
331
- * operations: {
332
- * processPayment: { input: ..., output: ... },
333
- * },
334
- * },
335
- * },
336
- * });
337
- * ```
338
- */
339
- interface ContractDefinitionWithNexus<TWorkflows extends Record<string, WorkflowDefinition> = Record<string, WorkflowDefinition>, TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>, TNexusServices extends Record<string, NexusServiceDefinition> = Record<string, NexusServiceDefinition>> {
340
- readonly taskQueue: string;
341
- readonly workflows: TWorkflows;
342
- readonly activities?: TActivities;
343
- readonly nexusServices?: TNexusServices;
344
- }
345
- /**
346
- * WORKER PERSPECTIVE - Nexus operation handler type inference
347
- * Worker receives the parsed input and returns the raw output
348
- */
349
- /**
350
- * Infer input type from a Nexus operation definition (worker perspective)
351
- */
352
- type WorkerInferNexusOperationInput<T extends NexusOperationDefinition> = StandardSchemaV1.InferOutput<T["input"]>;
353
- /**
354
- * Infer output type from a Nexus operation definition (worker perspective)
355
- */
356
- type WorkerInferNexusOperationOutput<T extends NexusOperationDefinition> = StandardSchemaV1.InferInput<T["output"]>;
357
- /**
358
- * Infer the handler function signature for a Nexus operation (worker perspective)
359
- *
360
- * @example
361
- * ```typescript
362
- * type ProcessPaymentHandler = WorkerInferNexusOperationHandler<typeof processPaymentOperation>;
363
- * // (args: { amount: number; customerId: string }) => Promise<{ transactionId: string; status: 'success' | 'failed' }>
364
- * ```
365
- */
366
- type WorkerInferNexusOperationHandler<TOperation extends NexusOperationDefinition> = (args: WorkerInferNexusOperationInput<TOperation>) => Promise<WorkerInferNexusOperationOutput<TOperation>>;
367
- /**
368
- * Infer all operation handlers for a Nexus service (worker perspective)
369
- *
370
- * @example
371
- * ```typescript
372
- * type PaymentServiceHandlers = WorkerInferNexusServiceHandlers<typeof PaymentService>;
373
- * // {
374
- * // processPayment: (args: { ... }) => Promise<{ ... }>;
375
- * // refundPayment: (args: { ... }) => Promise<{ ... }>;
376
- * // }
377
- * ```
378
- */
379
- type WorkerInferNexusServiceHandlers<T extends NexusServiceDefinition> = { [K in keyof T["operations"]]: WorkerInferNexusOperationHandler<T["operations"][K]> };
380
- /**
381
- * Infer all Nexus service handlers from a contract (worker perspective)
382
- *
383
- * @example
384
- * ```typescript
385
- * type AllNexusHandlers = WorkerInferNexusServices<typeof myContract>;
386
- * // {
387
- * // PaymentService: { processPayment: ..., refundPayment: ... };
388
- * // InventoryService: { reserveItems: ..., releaseItems: ... };
389
- * // }
390
- * ```
391
- */
392
- type WorkerInferNexusServices<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? { [K in keyof TContract["nexusServices"]]: WorkerInferNexusServiceHandlers<TContract["nexusServices"][K]> } : {};
393
- /**
394
- * CLIENT PERSPECTIVE - Nexus operation client type inference
395
- * Client sends the raw input and receives the parsed output
396
- */
397
- /**
398
- * Infer input type from a Nexus operation definition (client perspective)
399
- */
400
- type ClientInferNexusOperationInput<T extends NexusOperationDefinition> = StandardSchemaV1.InferInput<T["input"]>;
401
- /**
402
- * Infer output type from a Nexus operation definition (client perspective)
403
- */
404
- type ClientInferNexusOperationOutput<T extends NexusOperationDefinition> = StandardSchemaV1.InferOutput<T["output"]>;
405
- /**
406
- * Infer the client function signature for a Nexus operation (client perspective)
407
- *
408
- * @example
409
- * ```typescript
410
- * type ProcessPaymentClient = ClientInferNexusOperationInvoker<typeof processPaymentOperation>;
411
- * // (args: { amount: number; customerId: string }) => Promise<{ transactionId: string; status: 'success' | 'failed' }>
412
- * ```
413
- */
414
- type ClientInferNexusOperationInvoker<TOperation extends NexusOperationDefinition> = (args: ClientInferNexusOperationInput<TOperation>) => Promise<ClientInferNexusOperationOutput<TOperation>>;
415
- /**
416
- * Infer all operation invokers for a Nexus service (client perspective)
417
- */
418
- type ClientInferNexusServiceOperations<T extends NexusServiceDefinition> = { [K in keyof T["operations"]]: ClientInferNexusOperationInvoker<T["operations"][K]> };
419
- /**
420
- * Infer all Nexus service operations from a contract (client perspective)
421
- *
422
- * @example
423
- * ```typescript
424
- * type AllNexusOperations = ClientInferNexusServices<typeof myContract>;
425
- * // {
426
- * // PaymentService: { processPayment: ..., refundPayment: ... };
427
- * // InventoryService: { reserveItems: ..., releaseItems: ... };
428
- * // }
429
- * ```
430
- */
431
- type ClientInferNexusServices<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? { [K in keyof TContract["nexusServices"]]: ClientInferNexusServiceOperations<TContract["nexusServices"][K]> } : {};
432
- /**
433
- * UTILITY TYPES
434
- */
435
- /**
436
- * Extract service names from a contract as a union type
437
- *
438
- * @example
439
- * ```typescript
440
- * type MyServiceNames = InferNexusServiceNames<typeof myContract>;
441
- * // "PaymentService" | "InventoryService"
442
- * ```
443
- */
444
- type InferNexusServiceNames<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? keyof TContract["nexusServices"] & string : never;
445
- /**
446
- * Extract operation names from a service as a union type
447
- *
448
- * @example
449
- * ```typescript
450
- * type PaymentOperations = InferNexusOperationNames<typeof myContract, "PaymentService">;
451
- * // "processPayment" | "refundPayment"
452
- * ```
453
- */
454
- type InferNexusOperationNames<TContract extends ContractDefinitionWithNexus, TServiceName extends InferNexusServiceNames<TContract>> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? keyof TContract["nexusServices"][TServiceName]["operations"] & string : never;
455
- /**
456
- * Infer the handler type for a specific Nexus operation (worker perspective)
457
- *
458
- * @example
459
- * ```typescript
460
- * const processPayment: NexusOperationHandler<
461
- * typeof myContract,
462
- * "PaymentService",
463
- * "processPayment"
464
- * > = async ({ amount, customerId }) => {
465
- * // Implementation
466
- * return { transactionId: 'tx-123', status: 'success' };
467
- * };
468
- * ```
469
- */
470
- type NexusOperationHandler<TContract extends ContractDefinitionWithNexus, TServiceName extends InferNexusServiceNames<TContract>, TOperationName extends InferNexusOperationNames<TContract, TServiceName>> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? (args: WorkerInferNexusOperationInput<TContract["nexusServices"][TServiceName]["operations"][TOperationName]>) => Promise<WorkerInferNexusOperationOutput<TContract["nexusServices"][TServiceName]["operations"][TOperationName]>> : never;
471
- /**
472
- * BUILDER FUNCTIONS (Proposed API)
473
- * These would be added to builder.ts when Nexus support is implemented
474
- */
475
- /**
476
- * Builder for creating Nexus operation definitions
477
- *
478
- * @template TOperation - A NexusOperationDefinition containing input and output schemas
479
- * @param definition - The Nexus operation definition with typed input/output schemas
480
- * @returns The same definition with preserved types
481
- *
482
- * @example
483
- * ```typescript
484
- * const processPayment = defineNexusOperation({
485
- * input: z.object({ amount: z.number(), customerId: z.string() }),
486
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
487
- * });
488
- * ```
489
- */
490
- declare function defineNexusOperation<TOperation extends NexusOperationDefinition>(definition: TOperation): TOperation;
491
- /**
492
- * Builder for creating Nexus service definitions
493
- *
494
- * @template TService - A NexusServiceDefinition containing a record of operations
495
- * @param definition - The Nexus service definition with typed operations
496
- * @returns The same definition with preserved types
497
- *
498
- * @example
499
- * ```typescript
500
- * const PaymentService = defineNexusService({
501
- * operations: {
502
- * processPayment: defineNexusOperation({ ... }),
503
- * refundPayment: defineNexusOperation({ ... }),
504
- * },
505
- * });
506
- * ```
507
- */
508
- declare function defineNexusService<TService extends NexusServiceDefinition>(definition: TService): TService;
509
- //#endregion
510
- export { type ActivityDefinition, type AnySchema, type ClientInferNexusOperationInput, type ClientInferNexusOperationInvoker, type ClientInferNexusOperationOutput, type ClientInferNexusServiceOperations, type ClientInferNexusServices, type ContractDefinition, type ContractDefinitionWithNexus, type InferActivityNames, type InferContractWorkflows, type InferNexusOperationNames, type InferNexusServiceNames, type InferWorkflowNames, type NexusOperationDefinition, type NexusOperationHandler, type NexusServiceDefinition, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkerInferNexusOperationHandler, type WorkerInferNexusOperationInput, type WorkerInferNexusOperationOutput, type WorkerInferNexusServiceHandlers, type WorkerInferNexusServices, type WorkflowDefinition, defineActivity, defineContract, defineNexusOperation, defineNexusService, defineQuery, defineSignal, defineUpdate, defineWorkflow };
285
+ export { type ActivityDefinition, type AnySchema, type ContractDefinition, type InferActivityNames, type InferContractWorkflows, type InferWorkflowNames, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkflowDefinition, defineActivity, defineContract, defineQuery, defineSignal, defineUpdate, defineWorkflow };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { StandardSchemaV1 } from "@standard-schema/spec";
2
2
 
3
3
  //#region src/types.d.ts
4
-
5
4
  /**
6
5
  * Base types for validation schemas
7
6
  * Any schema that implements the Standard Schema specification
@@ -283,228 +282,4 @@ declare function defineWorkflow<TWorkflow extends WorkflowDefinition>(definition
283
282
  */
284
283
  declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
285
284
  //#endregion
286
- //#region src/nexus-types.d.ts
287
- /**
288
- * Definition of a Nexus operation
289
- * Similar to ActivityDefinition but for cross-namespace operations
290
- *
291
- * @example
292
- * ```typescript
293
- * const processPayment = {
294
- * input: z.object({ amount: z.number(), customerId: z.string() }),
295
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
296
- * };
297
- * ```
298
- */
299
- interface NexusOperationDefinition<TInput extends AnySchema = AnySchema, TOutput extends AnySchema = AnySchema> {
300
- readonly input: TInput;
301
- readonly output: TOutput;
302
- }
303
- /**
304
- * Definition of a Nexus service containing multiple operations
305
- *
306
- * @example
307
- * ```typescript
308
- * const PaymentService = {
309
- * operations: {
310
- * processPayment: { input: ..., output: ... },
311
- * refundPayment: { input: ..., output: ... },
312
- * },
313
- * };
314
- * ```
315
- */
316
- interface NexusServiceDefinition<TOperations extends Record<string, NexusOperationDefinition> = Record<string, NexusOperationDefinition>> {
317
- readonly operations: TOperations;
318
- }
319
- /**
320
- * Extended ContractDefinition that includes Nexus services
321
- * This would replace the current ContractDefinition when Nexus support is added
322
- *
323
- * @example
324
- * ```typescript
325
- * const contract = defineContract({
326
- * taskQueue: 'payments',
327
- * workflows: { ... },
328
- * activities: { ... },
329
- * nexusServices: {
330
- * PaymentService: {
331
- * operations: {
332
- * processPayment: { input: ..., output: ... },
333
- * },
334
- * },
335
- * },
336
- * });
337
- * ```
338
- */
339
- interface ContractDefinitionWithNexus<TWorkflows extends Record<string, WorkflowDefinition> = Record<string, WorkflowDefinition>, TActivities extends Record<string, ActivityDefinition> = Record<string, ActivityDefinition>, TNexusServices extends Record<string, NexusServiceDefinition> = Record<string, NexusServiceDefinition>> {
340
- readonly taskQueue: string;
341
- readonly workflows: TWorkflows;
342
- readonly activities?: TActivities;
343
- readonly nexusServices?: TNexusServices;
344
- }
345
- /**
346
- * WORKER PERSPECTIVE - Nexus operation handler type inference
347
- * Worker receives the parsed input and returns the raw output
348
- */
349
- /**
350
- * Infer input type from a Nexus operation definition (worker perspective)
351
- */
352
- type WorkerInferNexusOperationInput<T extends NexusOperationDefinition> = StandardSchemaV1.InferOutput<T["input"]>;
353
- /**
354
- * Infer output type from a Nexus operation definition (worker perspective)
355
- */
356
- type WorkerInferNexusOperationOutput<T extends NexusOperationDefinition> = StandardSchemaV1.InferInput<T["output"]>;
357
- /**
358
- * Infer the handler function signature for a Nexus operation (worker perspective)
359
- *
360
- * @example
361
- * ```typescript
362
- * type ProcessPaymentHandler = WorkerInferNexusOperationHandler<typeof processPaymentOperation>;
363
- * // (args: { amount: number; customerId: string }) => Promise<{ transactionId: string; status: 'success' | 'failed' }>
364
- * ```
365
- */
366
- type WorkerInferNexusOperationHandler<TOperation extends NexusOperationDefinition> = (args: WorkerInferNexusOperationInput<TOperation>) => Promise<WorkerInferNexusOperationOutput<TOperation>>;
367
- /**
368
- * Infer all operation handlers for a Nexus service (worker perspective)
369
- *
370
- * @example
371
- * ```typescript
372
- * type PaymentServiceHandlers = WorkerInferNexusServiceHandlers<typeof PaymentService>;
373
- * // {
374
- * // processPayment: (args: { ... }) => Promise<{ ... }>;
375
- * // refundPayment: (args: { ... }) => Promise<{ ... }>;
376
- * // }
377
- * ```
378
- */
379
- type WorkerInferNexusServiceHandlers<T extends NexusServiceDefinition> = { [K in keyof T["operations"]]: WorkerInferNexusOperationHandler<T["operations"][K]> };
380
- /**
381
- * Infer all Nexus service handlers from a contract (worker perspective)
382
- *
383
- * @example
384
- * ```typescript
385
- * type AllNexusHandlers = WorkerInferNexusServices<typeof myContract>;
386
- * // {
387
- * // PaymentService: { processPayment: ..., refundPayment: ... };
388
- * // InventoryService: { reserveItems: ..., releaseItems: ... };
389
- * // }
390
- * ```
391
- */
392
- type WorkerInferNexusServices<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? { [K in keyof TContract["nexusServices"]]: WorkerInferNexusServiceHandlers<TContract["nexusServices"][K]> } : {};
393
- /**
394
- * CLIENT PERSPECTIVE - Nexus operation client type inference
395
- * Client sends the raw input and receives the parsed output
396
- */
397
- /**
398
- * Infer input type from a Nexus operation definition (client perspective)
399
- */
400
- type ClientInferNexusOperationInput<T extends NexusOperationDefinition> = StandardSchemaV1.InferInput<T["input"]>;
401
- /**
402
- * Infer output type from a Nexus operation definition (client perspective)
403
- */
404
- type ClientInferNexusOperationOutput<T extends NexusOperationDefinition> = StandardSchemaV1.InferOutput<T["output"]>;
405
- /**
406
- * Infer the client function signature for a Nexus operation (client perspective)
407
- *
408
- * @example
409
- * ```typescript
410
- * type ProcessPaymentClient = ClientInferNexusOperationInvoker<typeof processPaymentOperation>;
411
- * // (args: { amount: number; customerId: string }) => Promise<{ transactionId: string; status: 'success' | 'failed' }>
412
- * ```
413
- */
414
- type ClientInferNexusOperationInvoker<TOperation extends NexusOperationDefinition> = (args: ClientInferNexusOperationInput<TOperation>) => Promise<ClientInferNexusOperationOutput<TOperation>>;
415
- /**
416
- * Infer all operation invokers for a Nexus service (client perspective)
417
- */
418
- type ClientInferNexusServiceOperations<T extends NexusServiceDefinition> = { [K in keyof T["operations"]]: ClientInferNexusOperationInvoker<T["operations"][K]> };
419
- /**
420
- * Infer all Nexus service operations from a contract (client perspective)
421
- *
422
- * @example
423
- * ```typescript
424
- * type AllNexusOperations = ClientInferNexusServices<typeof myContract>;
425
- * // {
426
- * // PaymentService: { processPayment: ..., refundPayment: ... };
427
- * // InventoryService: { reserveItems: ..., releaseItems: ... };
428
- * // }
429
- * ```
430
- */
431
- type ClientInferNexusServices<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? { [K in keyof TContract["nexusServices"]]: ClientInferNexusServiceOperations<TContract["nexusServices"][K]> } : {};
432
- /**
433
- * UTILITY TYPES
434
- */
435
- /**
436
- * Extract service names from a contract as a union type
437
- *
438
- * @example
439
- * ```typescript
440
- * type MyServiceNames = InferNexusServiceNames<typeof myContract>;
441
- * // "PaymentService" | "InventoryService"
442
- * ```
443
- */
444
- type InferNexusServiceNames<TContract extends ContractDefinitionWithNexus> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? keyof TContract["nexusServices"] & string : never;
445
- /**
446
- * Extract operation names from a service as a union type
447
- *
448
- * @example
449
- * ```typescript
450
- * type PaymentOperations = InferNexusOperationNames<typeof myContract, "PaymentService">;
451
- * // "processPayment" | "refundPayment"
452
- * ```
453
- */
454
- type InferNexusOperationNames<TContract extends ContractDefinitionWithNexus, TServiceName extends InferNexusServiceNames<TContract>> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? keyof TContract["nexusServices"][TServiceName]["operations"] & string : never;
455
- /**
456
- * Infer the handler type for a specific Nexus operation (worker perspective)
457
- *
458
- * @example
459
- * ```typescript
460
- * const processPayment: NexusOperationHandler<
461
- * typeof myContract,
462
- * "PaymentService",
463
- * "processPayment"
464
- * > = async ({ amount, customerId }) => {
465
- * // Implementation
466
- * return { transactionId: 'tx-123', status: 'success' };
467
- * };
468
- * ```
469
- */
470
- type NexusOperationHandler<TContract extends ContractDefinitionWithNexus, TServiceName extends InferNexusServiceNames<TContract>, TOperationName extends InferNexusOperationNames<TContract, TServiceName>> = TContract["nexusServices"] extends Record<string, NexusServiceDefinition> ? (args: WorkerInferNexusOperationInput<TContract["nexusServices"][TServiceName]["operations"][TOperationName]>) => Promise<WorkerInferNexusOperationOutput<TContract["nexusServices"][TServiceName]["operations"][TOperationName]>> : never;
471
- /**
472
- * BUILDER FUNCTIONS (Proposed API)
473
- * These would be added to builder.ts when Nexus support is implemented
474
- */
475
- /**
476
- * Builder for creating Nexus operation definitions
477
- *
478
- * @template TOperation - A NexusOperationDefinition containing input and output schemas
479
- * @param definition - The Nexus operation definition with typed input/output schemas
480
- * @returns The same definition with preserved types
481
- *
482
- * @example
483
- * ```typescript
484
- * const processPayment = defineNexusOperation({
485
- * input: z.object({ amount: z.number(), customerId: z.string() }),
486
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
487
- * });
488
- * ```
489
- */
490
- declare function defineNexusOperation<TOperation extends NexusOperationDefinition>(definition: TOperation): TOperation;
491
- /**
492
- * Builder for creating Nexus service definitions
493
- *
494
- * @template TService - A NexusServiceDefinition containing a record of operations
495
- * @param definition - The Nexus service definition with typed operations
496
- * @returns The same definition with preserved types
497
- *
498
- * @example
499
- * ```typescript
500
- * const PaymentService = defineNexusService({
501
- * operations: {
502
- * processPayment: defineNexusOperation({ ... }),
503
- * refundPayment: defineNexusOperation({ ... }),
504
- * },
505
- * });
506
- * ```
507
- */
508
- declare function defineNexusService<TService extends NexusServiceDefinition>(definition: TService): TService;
509
- //#endregion
510
- export { type ActivityDefinition, type AnySchema, type ClientInferNexusOperationInput, type ClientInferNexusOperationInvoker, type ClientInferNexusOperationOutput, type ClientInferNexusServiceOperations, type ClientInferNexusServices, type ContractDefinition, type ContractDefinitionWithNexus, type InferActivityNames, type InferContractWorkflows, type InferNexusOperationNames, type InferNexusServiceNames, type InferWorkflowNames, type NexusOperationDefinition, type NexusOperationHandler, type NexusServiceDefinition, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkerInferNexusOperationHandler, type WorkerInferNexusOperationInput, type WorkerInferNexusOperationOutput, type WorkerInferNexusServiceHandlers, type WorkerInferNexusServices, type WorkflowDefinition, defineActivity, defineContract, defineNexusOperation, defineNexusService, defineQuery, defineSignal, defineUpdate, defineWorkflow };
285
+ export { type ActivityDefinition, type AnySchema, type ContractDefinition, type InferActivityNames, type InferContractWorkflows, type InferWorkflowNames, type QueryDefinition, type SignalDefinition, type UpdateDefinition, type WorkflowDefinition, defineActivity, defineContract, defineQuery, defineSignal, defineUpdate, defineWorkflow };
package/dist/index.mjs CHANGED
@@ -301,118 +301,4 @@ const contractValidationSchema = z.object({
301
301
  });
302
302
 
303
303
  //#endregion
304
- //#region src/nexus-types.ts
305
- /**
306
- * BUILDER FUNCTIONS (Proposed API)
307
- * These would be added to builder.ts when Nexus support is implemented
308
- */
309
- /**
310
- * Builder for creating Nexus operation definitions
311
- *
312
- * @template TOperation - A NexusOperationDefinition containing input and output schemas
313
- * @param definition - The Nexus operation definition with typed input/output schemas
314
- * @returns The same definition with preserved types
315
- *
316
- * @example
317
- * ```typescript
318
- * const processPayment = defineNexusOperation({
319
- * input: z.object({ amount: z.number(), customerId: z.string() }),
320
- * output: z.object({ transactionId: z.string(), status: z.enum(['success', 'failed']) }),
321
- * });
322
- * ```
323
- */
324
- function defineNexusOperation(definition) {
325
- return definition;
326
- }
327
- /**
328
- * Builder for creating Nexus service definitions
329
- *
330
- * @template TService - A NexusServiceDefinition containing a record of operations
331
- * @param definition - The Nexus service definition with typed operations
332
- * @returns The same definition with preserved types
333
- *
334
- * @example
335
- * ```typescript
336
- * const PaymentService = defineNexusService({
337
- * operations: {
338
- * processPayment: defineNexusOperation({ ... }),
339
- * refundPayment: defineNexusOperation({ ... }),
340
- * },
341
- * });
342
- * ```
343
- */
344
- function defineNexusService(definition) {
345
- return definition;
346
- }
347
- /**
348
- * USAGE EXAMPLE
349
- *
350
- * This example demonstrates the complete type-safe Nexus workflow:
351
- *
352
- * ```typescript
353
- * import { defineContract, defineNexusService, defineNexusOperation } from '@temporal-contract/contract';
354
- * import { z } from 'zod';
355
- *
356
- * // 1. Define contract with Nexus service
357
- * const paymentContract = defineContract({
358
- * taskQueue: 'payments',
359
- * workflows: { ... },
360
- * nexusServices: {
361
- * PaymentService: defineNexusService({
362
- * operations: {
363
- * processPayment: defineNexusOperation({
364
- * input: z.object({
365
- * amount: z.number().positive(),
366
- * customerId: z.string().uuid(),
367
- * }),
368
- * output: z.object({
369
- * transactionId: z.string(),
370
- * status: z.enum(['success', 'failed']),
371
- * }),
372
- * }),
373
- * },
374
- * }),
375
- * },
376
- * });
377
- *
378
- * // 2. Worker implementation (type-safe handlers)
379
- * import { createNexusHandlers } from '@temporal-contract/worker';
380
- *
381
- * const nexusHandlers = createNexusHandlers(paymentContract, {
382
- * PaymentService: {
383
- * processPayment: async ({ amount, customerId }) => {
384
- * // ✅ Fully typed parameters
385
- * // ✅ Input automatically validated
386
- * const payment = await processPaymentInDatabase(customerId, amount);
387
- * // ✅ Return value validated against schema
388
- * return {
389
- * transactionId: payment.id,
390
- * status: 'success',
391
- * };
392
- * },
393
- * },
394
- * });
395
- *
396
- * // 3. Client usage (type-safe invocation)
397
- * import { createNexusClient } from '@temporal-contract/client';
398
- *
399
- * const nexusClient = createNexusClient<typeof paymentContract>(connection, {
400
- * namespace: 'payments-ns',
401
- * });
402
- *
403
- * // ✅ Fully typed invocation
404
- * const result = await nexusClient.invoke('PaymentService', 'processPayment', {
405
- * amount: 100,
406
- * customerId: 'cust-123',
407
- * });
408
- *
409
- * // ❌ TypeScript errors caught at compile time
410
- * await nexusClient.invoke('PaymentService', 'processPayment', {
411
- * amount: -50, // Error: amount must be positive
412
- * customerId: 'invalid', // Error: customerId must be UUID
413
- * });
414
- * ```
415
- */
416
-
417
- //#endregion
418
- export { defineActivity, defineContract, defineNexusOperation, defineNexusService, defineQuery, defineSignal, defineUpdate, defineWorkflow };
304
+ export { defineActivity, defineContract, defineQuery, defineSignal, defineUpdate, defineWorkflow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporal-contract/contract",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "description": "Contract builder for temporal-contract",
5
5
  "keywords": [
6
6
  "contract",
@@ -40,19 +40,21 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@standard-schema/spec": "1.1.0",
43
- "zod": "4.2.1"
43
+ "zod": "4.3.5"
44
44
  },
45
45
  "devDependencies": {
46
- "@vitest/coverage-v8": "4.0.16",
46
+ "@vitest/coverage-v8": "4.0.17",
47
47
  "arktype": "2.1.29",
48
- "tsdown": "0.18.1",
48
+ "tsdown": "0.20.0-beta.4",
49
49
  "typescript": "5.9.3",
50
50
  "valibot": "1.2.0",
51
- "vitest": "4.0.16",
52
- "@temporal-contract/tsconfig": "0.0.7"
51
+ "vitest": "4.0.17",
52
+ "@temporal-contract/tsconfig": "0.1.0",
53
+ "@temporal-contract/typedoc": "0.1.0"
53
54
  },
54
55
  "scripts": {
55
56
  "build": "tsdown src/index.ts --format cjs,esm --dts --clean",
57
+ "build:docs": "typedoc",
56
58
  "dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
57
59
  "test": "vitest run",
58
60
  "test:watch": "vitest",