typed-bridge 2.1.1 → 2.1.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.
@@ -166,6 +166,63 @@ declare const _default: {
166
166
  updatedAt: import("zod").ZodDate;
167
167
  }, import("zod/v4/core").$strip>>>;
168
168
  'order.list': () => Promise<order.Order[]>;
169
+ 'order.resolve': (args: import("zod").infer<import("zod").ZodObject<{
170
+ id: import("zod").ZodNumber;
171
+ }, import("zod/v4/core").$strip>>, context: {
172
+ requestedAt: number;
173
+ userId: number;
174
+ }) => Promise<import("zod").infer<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
175
+ status: import("zod").ZodLiteral<"found">;
176
+ order: import("zod").ZodObject<{
177
+ id: import("zod").ZodNumber;
178
+ customerName: import("zod").ZodString;
179
+ orderStatus: import("zod").ZodEnum<{
180
+ pending: "pending";
181
+ confirmed: "confirmed";
182
+ shipped: "shipped";
183
+ delivered: "delivered";
184
+ cancelled: "cancelled";
185
+ }>;
186
+ total: import("zod").ZodNumber;
187
+ }, import("zod/v4/core").$strip>;
188
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
189
+ status: import("zod").ZodLiteral<"not_found">;
190
+ }, import("zod/v4/core").$strip>], "status">>>;
191
+ 'order.statusFilter': (args: import("zod").infer<import("zod").ZodObject<{
192
+ status: import("zod").ZodEnum<{
193
+ pending: "pending";
194
+ confirmed: "confirmed";
195
+ shipped: "shipped";
196
+ delivered: "delivered";
197
+ cancelled: "cancelled";
198
+ }>;
199
+ }, import("zod/v4/core").$strip>>, context: {
200
+ requestedAt: number;
201
+ userId: number;
202
+ }) => Promise<import("zod").infer<import("zod").ZodObject<{
203
+ orders: import("zod").ZodArray<import("zod").ZodObject<{
204
+ id: import("zod").ZodNumber;
205
+ status: import("zod").ZodEnum<{
206
+ pending: "pending";
207
+ confirmed: "confirmed";
208
+ shipped: "shipped";
209
+ delivered: "delivered";
210
+ cancelled: "cancelled";
211
+ }>;
212
+ total: import("zod").ZodNumber;
213
+ }, import("zod/v4/core").$strip>>;
214
+ }, import("zod/v4/core").$strip>>>;
215
+ 'order.tag': (args: import("zod").infer<import("zod").ZodObject<{
216
+ orderId: import("zod").ZodNumber;
217
+ tag: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
218
+ }, import("zod/v4/core").$strip>>, context: {
219
+ requestedAt: number;
220
+ userId: number;
221
+ }) => Promise<import("zod").infer<import("zod").ZodObject<{
222
+ orderId: import("zod").ZodNumber;
223
+ tag: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
224
+ appliedAt: import("zod").ZodDate;
225
+ }, import("zod/v4/core").$strip>>>;
169
226
  'order.primitives': (args: import("zod").infer<import("zod").ZodObject<{
170
227
  key: import("zod").ZodString;
171
228
  }, import("zod/v4/core").$strip>>) => Promise<import("zod").infer<import("zod").ZodObject<{
@@ -49,5 +49,8 @@ exports.default = {
49
49
  'order.fetch': order.fetch,
50
50
  'order.update': order.update,
51
51
  'order.list': order.list,
52
+ 'order.resolve': order.resolve,
53
+ 'order.statusFilter': order.statusFilter,
54
+ 'order.tag': order.tag,
52
55
  'order.primitives': order.primitives
53
56
  };
@@ -1,4 +1,4 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  import * as types from './types';
3
3
  export interface OrderItem {
4
4
  productId: number;
@@ -31,9 +31,12 @@ type Context = {
31
31
  requestedAt: number;
32
32
  userId: number;
33
33
  };
34
- export declare const create: (args: $z.infer<typeof types.create.args>, context: Context) => Promise<$z.infer<typeof types.create.res>>;
35
- export declare const fetch: (args: $z.infer<typeof types.fetch.args>, context: Context) => Promise<$z.infer<typeof types.fetch.res>>;
36
- export declare const update: (args: $z.infer<typeof types.update.args>, context: Context) => Promise<$z.infer<typeof types.update.res>>;
34
+ export declare const create: (args: z.infer<typeof types.create.args>, context: Context) => Promise<z.infer<typeof types.create.res>>;
35
+ export declare const fetch: (args: z.infer<typeof types.fetch.args>, context: Context) => Promise<z.infer<typeof types.fetch.res>>;
36
+ export declare const update: (args: z.infer<typeof types.update.args>, context: Context) => Promise<z.infer<typeof types.update.res>>;
37
37
  export declare const list: () => Promise<Order[]>;
38
- export declare const primitives: (args: $z.infer<typeof types.primitives.args>) => Promise<$z.infer<typeof types.primitives.res>>;
38
+ export declare const resolve: (args: z.infer<typeof types.resolve.args>, context: Context) => Promise<z.infer<typeof types.resolve.res>>;
39
+ export declare const statusFilter: (args: z.infer<typeof types.statusFilter.args>, context: Context) => Promise<z.infer<typeof types.statusFilter.res>>;
40
+ export declare const tag: (args: z.infer<typeof types.tag.args>, context: Context) => Promise<z.infer<typeof types.tag.res>>;
41
+ export declare const primitives: (args: z.infer<typeof types.primitives.args>) => Promise<z.infer<typeof types.primitives.res>>;
39
42
  export {};
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.primitives = exports.list = exports.update = exports.fetch = exports.create = void 0;
36
+ exports.primitives = exports.tag = exports.statusFilter = exports.resolve = exports.list = exports.update = exports.fetch = exports.create = void 0;
37
37
  const types = __importStar(require("./types"));
38
38
  let nextId = 1;
39
39
  const orders = [];
@@ -51,7 +51,9 @@ const create = async (args, context) => {
51
51
  total: items.reduce((sum, i) => sum + i.price * i.quantity, 0),
52
52
  items,
53
53
  shippingAddress: { ...args.shippingAddress, country: args.shippingAddress.country ?? 'US' },
54
- billingAddress: args.billingAddress ? { ...args.billingAddress, country: args.billingAddress.country ?? 'US' } : null,
54
+ billingAddress: args.billingAddress
55
+ ? { ...args.billingAddress, country: args.billingAddress.country ?? 'US' }
56
+ : null,
55
57
  isGift: args.isGift,
56
58
  giftMessage: args.giftMessage,
57
59
  createdAt: new Date(),
@@ -94,6 +96,43 @@ const list = async () => {
94
96
  return orders;
95
97
  };
96
98
  exports.list = list;
99
+ const resolve = async (args, context) => {
100
+ args = types.resolve.args.parse(args);
101
+ const order = orders.find(o => o.id === args.id);
102
+ if (!order)
103
+ return { status: 'not_found' };
104
+ return {
105
+ status: 'found',
106
+ order: {
107
+ id: order.id,
108
+ customerName: `Customer #${order.customerId}`,
109
+ orderStatus: order.status,
110
+ total: order.total
111
+ }
112
+ };
113
+ };
114
+ exports.resolve = resolve;
115
+ const statusFilter = async (args, context) => {
116
+ args = types.statusFilter.args.parse(args);
117
+ return {
118
+ orders: orders
119
+ .filter(o => o.status === args.status)
120
+ .map(o => ({ id: o.id, status: o.status, total: o.total }))
121
+ };
122
+ };
123
+ exports.statusFilter = statusFilter;
124
+ const orderTags = new Map();
125
+ const tag = async (args, context) => {
126
+ args = types.tag.args.parse(args);
127
+ const order = orders.find(o => o.id === args.orderId);
128
+ if (!order)
129
+ throw new Error(`Order with ID ${args.orderId} not found`);
130
+ const tags = orderTags.get(args.orderId) || [];
131
+ tags.push(args.tag);
132
+ orderTags.set(args.orderId, tags);
133
+ return { orderId: args.orderId, tag: args.tag, appliedAt: new Date() };
134
+ };
135
+ exports.tag = tag;
97
136
  const primitives = async (args) => {
98
137
  args = types.primitives.args.parse(args);
99
138
  return {
@@ -1,130 +1,187 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  export declare const create: {
3
- args: $z.ZodObject<{
4
- customerId: $z.ZodNumber;
5
- items: $z.ZodArray<$z.ZodObject<{
6
- productId: $z.ZodNumber;
7
- quantity: $z.ZodNumber;
8
- price: $z.ZodNumber;
9
- notes: $z.ZodOptional<$z.ZodString>;
10
- discount: $z.ZodNullable<$z.ZodNumber>;
11
- }, $z.core.$strip>>;
12
- shippingAddress: $z.ZodObject<{
13
- street: $z.ZodString;
14
- city: $z.ZodString;
15
- state: $z.ZodString;
16
- zip: $z.ZodString;
17
- country: $z.ZodDefault<$z.ZodString>;
18
- }, $z.core.$strip>;
19
- billingAddress: $z.ZodNullable<$z.ZodObject<{
20
- street: $z.ZodString;
21
- city: $z.ZodString;
22
- state: $z.ZodString;
23
- zip: $z.ZodString;
24
- country: $z.ZodDefault<$z.ZodString>;
25
- }, $z.core.$strip>>;
26
- couponCode: $z.ZodOptional<$z.ZodNullable<$z.ZodString>>;
27
- scheduledDate: $z.ZodOptional<$z.ZodDate>;
28
- isGift: $z.ZodBoolean;
29
- giftMessage: $z.ZodNullable<$z.ZodString>;
30
- }, $z.core.$strip>;
31
- res: $z.ZodObject<{
32
- id: $z.ZodNumber;
33
- status: $z.ZodString;
34
- total: $z.ZodNumber;
35
- items: $z.ZodArray<$z.ZodObject<{
36
- productId: $z.ZodNumber;
37
- quantity: $z.ZodNumber;
38
- price: $z.ZodNumber;
39
- notes: $z.ZodOptional<$z.ZodString>;
40
- discount: $z.ZodNullable<$z.ZodNumber>;
41
- }, $z.core.$strip>>;
42
- createdAt: $z.ZodDate;
43
- }, $z.core.$strip>;
3
+ args: z.ZodObject<{
4
+ customerId: z.ZodNumber;
5
+ items: z.ZodArray<z.ZodObject<{
6
+ productId: z.ZodNumber;
7
+ quantity: z.ZodNumber;
8
+ price: z.ZodNumber;
9
+ notes: z.ZodOptional<z.ZodString>;
10
+ discount: z.ZodNullable<z.ZodNumber>;
11
+ }, z.core.$strip>>;
12
+ shippingAddress: z.ZodObject<{
13
+ street: z.ZodString;
14
+ city: z.ZodString;
15
+ state: z.ZodString;
16
+ zip: z.ZodString;
17
+ country: z.ZodDefault<z.ZodString>;
18
+ }, z.core.$strip>;
19
+ billingAddress: z.ZodNullable<z.ZodObject<{
20
+ street: z.ZodString;
21
+ city: z.ZodString;
22
+ state: z.ZodString;
23
+ zip: z.ZodString;
24
+ country: z.ZodDefault<z.ZodString>;
25
+ }, z.core.$strip>>;
26
+ couponCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
+ scheduledDate: z.ZodOptional<z.ZodDate>;
28
+ isGift: z.ZodBoolean;
29
+ giftMessage: z.ZodNullable<z.ZodString>;
30
+ }, z.core.$strip>;
31
+ res: z.ZodObject<{
32
+ id: z.ZodNumber;
33
+ status: z.ZodString;
34
+ total: z.ZodNumber;
35
+ items: z.ZodArray<z.ZodObject<{
36
+ productId: z.ZodNumber;
37
+ quantity: z.ZodNumber;
38
+ price: z.ZodNumber;
39
+ notes: z.ZodOptional<z.ZodString>;
40
+ discount: z.ZodNullable<z.ZodNumber>;
41
+ }, z.core.$strip>>;
42
+ createdAt: z.ZodDate;
43
+ }, z.core.$strip>;
44
44
  };
45
45
  export declare const fetch: {
46
- args: $z.ZodObject<{
47
- id: $z.ZodNumber;
48
- }, $z.core.$strip>;
49
- res: $z.ZodObject<{
50
- id: $z.ZodNumber;
51
- customerId: $z.ZodNumber;
52
- status: $z.ZodString;
53
- total: $z.ZodNumber;
54
- items: $z.ZodArray<$z.ZodObject<{
55
- productId: $z.ZodNumber;
56
- quantity: $z.ZodNumber;
57
- price: $z.ZodNumber;
58
- notes: $z.ZodOptional<$z.ZodString>;
59
- discount: $z.ZodNullable<$z.ZodNumber>;
60
- }, $z.core.$strip>>;
61
- shippingAddress: $z.ZodObject<{
62
- street: $z.ZodString;
63
- city: $z.ZodString;
64
- state: $z.ZodString;
65
- zip: $z.ZodString;
66
- country: $z.ZodDefault<$z.ZodString>;
67
- }, $z.core.$strip>;
68
- billingAddress: $z.ZodNullable<$z.ZodObject<{
69
- street: $z.ZodString;
70
- city: $z.ZodString;
71
- state: $z.ZodString;
72
- zip: $z.ZodString;
73
- country: $z.ZodDefault<$z.ZodString>;
74
- }, $z.core.$strip>>;
75
- isGift: $z.ZodBoolean;
76
- giftMessage: $z.ZodNullable<$z.ZodString>;
77
- createdAt: $z.ZodDate;
78
- updatedAt: $z.ZodNullable<$z.ZodDate>;
79
- }, $z.core.$strip>;
46
+ args: z.ZodObject<{
47
+ id: z.ZodNumber;
48
+ }, z.core.$strip>;
49
+ res: z.ZodObject<{
50
+ id: z.ZodNumber;
51
+ customerId: z.ZodNumber;
52
+ status: z.ZodString;
53
+ total: z.ZodNumber;
54
+ items: z.ZodArray<z.ZodObject<{
55
+ productId: z.ZodNumber;
56
+ quantity: z.ZodNumber;
57
+ price: z.ZodNumber;
58
+ notes: z.ZodOptional<z.ZodString>;
59
+ discount: z.ZodNullable<z.ZodNumber>;
60
+ }, z.core.$strip>>;
61
+ shippingAddress: z.ZodObject<{
62
+ street: z.ZodString;
63
+ city: z.ZodString;
64
+ state: z.ZodString;
65
+ zip: z.ZodString;
66
+ country: z.ZodDefault<z.ZodString>;
67
+ }, z.core.$strip>;
68
+ billingAddress: z.ZodNullable<z.ZodObject<{
69
+ street: z.ZodString;
70
+ city: z.ZodString;
71
+ state: z.ZodString;
72
+ zip: z.ZodString;
73
+ country: z.ZodDefault<z.ZodString>;
74
+ }, z.core.$strip>>;
75
+ isGift: z.ZodBoolean;
76
+ giftMessage: z.ZodNullable<z.ZodString>;
77
+ createdAt: z.ZodDate;
78
+ updatedAt: z.ZodNullable<z.ZodDate>;
79
+ }, z.core.$strip>;
80
80
  };
81
81
  export declare const update: {
82
- args: $z.ZodObject<{
83
- id: $z.ZodNumber;
84
- status: $z.ZodOptional<$z.ZodString>;
85
- shippingAddress: $z.ZodOptional<$z.ZodObject<{
86
- street: $z.ZodString;
87
- city: $z.ZodString;
88
- state: $z.ZodString;
89
- zip: $z.ZodString;
90
- country: $z.ZodDefault<$z.ZodString>;
91
- }, $z.core.$strip>>;
92
- giftMessage: $z.ZodOptional<$z.ZodNullable<$z.ZodString>>;
93
- }, $z.core.$strip>;
94
- res: $z.ZodObject<{
95
- id: $z.ZodNumber;
96
- status: $z.ZodString;
97
- updatedAt: $z.ZodDate;
98
- }, $z.core.$strip>;
82
+ args: z.ZodObject<{
83
+ id: z.ZodNumber;
84
+ status: z.ZodOptional<z.ZodString>;
85
+ shippingAddress: z.ZodOptional<z.ZodObject<{
86
+ street: z.ZodString;
87
+ city: z.ZodString;
88
+ state: z.ZodString;
89
+ zip: z.ZodString;
90
+ country: z.ZodDefault<z.ZodString>;
91
+ }, z.core.$strip>>;
92
+ giftMessage: z.ZodOptional<z.ZodNullable<z.ZodString>>;
93
+ }, z.core.$strip>;
94
+ res: z.ZodObject<{
95
+ id: z.ZodNumber;
96
+ status: z.ZodString;
97
+ updatedAt: z.ZodDate;
98
+ }, z.core.$strip>;
99
+ };
100
+ export declare const resolve: {
101
+ args: z.ZodObject<{
102
+ id: z.ZodNumber;
103
+ }, z.core.$strip>;
104
+ res: z.ZodDiscriminatedUnion<[z.ZodObject<{
105
+ status: z.ZodLiteral<"found">;
106
+ order: z.ZodObject<{
107
+ id: z.ZodNumber;
108
+ customerName: z.ZodString;
109
+ orderStatus: z.ZodEnum<{
110
+ pending: "pending";
111
+ confirmed: "confirmed";
112
+ shipped: "shipped";
113
+ delivered: "delivered";
114
+ cancelled: "cancelled";
115
+ }>;
116
+ total: z.ZodNumber;
117
+ }, z.core.$strip>;
118
+ }, z.core.$strip>, z.ZodObject<{
119
+ status: z.ZodLiteral<"not_found">;
120
+ }, z.core.$strip>], "status">;
121
+ };
122
+ export declare const statusFilter: {
123
+ args: z.ZodObject<{
124
+ status: z.ZodEnum<{
125
+ pending: "pending";
126
+ confirmed: "confirmed";
127
+ shipped: "shipped";
128
+ delivered: "delivered";
129
+ cancelled: "cancelled";
130
+ }>;
131
+ }, z.core.$strip>;
132
+ res: z.ZodObject<{
133
+ orders: z.ZodArray<z.ZodObject<{
134
+ id: z.ZodNumber;
135
+ status: z.ZodEnum<{
136
+ pending: "pending";
137
+ confirmed: "confirmed";
138
+ shipped: "shipped";
139
+ delivered: "delivered";
140
+ cancelled: "cancelled";
141
+ }>;
142
+ total: z.ZodNumber;
143
+ }, z.core.$strip>>;
144
+ }, z.core.$strip>;
145
+ };
146
+ export declare const tag: {
147
+ args: z.ZodObject<{
148
+ orderId: z.ZodNumber;
149
+ tag: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
150
+ }, z.core.$strip>;
151
+ res: z.ZodObject<{
152
+ orderId: z.ZodNumber;
153
+ tag: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
154
+ appliedAt: z.ZodDate;
155
+ }, z.core.$strip>;
99
156
  };
100
157
  export declare const primitives: {
101
- args: $z.ZodObject<{
102
- key: $z.ZodString;
103
- }, $z.core.$strip>;
104
- res: $z.ZodObject<{
105
- str: $z.ZodString;
106
- num: $z.ZodNumber;
107
- bool: $z.ZodBoolean;
108
- date: $z.ZodDate;
109
- nul: $z.ZodNull;
110
- undef: $z.ZodUndefined;
111
- unk: $z.ZodUnknown;
112
- whatever: $z.ZodAny;
113
- optStr: $z.ZodOptional<$z.ZodString>;
114
- nullStr: $z.ZodNullable<$z.ZodString>;
115
- defStr: $z.ZodDefault<$z.ZodString>;
116
- optNullStr: $z.ZodOptional<$z.ZodNullable<$z.ZodString>>;
117
- nullOptStr: $z.ZodNullable<$z.ZodOptional<$z.ZodString>>;
118
- tags: $z.ZodArray<$z.ZodString>;
119
- scores: $z.ZodNullable<$z.ZodArray<$z.ZodNumber>>;
120
- optDates: $z.ZodOptional<$z.ZodArray<$z.ZodDate>>;
121
- nested: $z.ZodObject<{
122
- a: $z.ZodNumber;
123
- b: $z.ZodOptional<$z.ZodString>;
124
- c: $z.ZodObject<{
125
- d: $z.ZodBoolean;
126
- e: $z.ZodNullable<$z.ZodArray<$z.ZodString>>;
127
- }, $z.core.$strip>;
128
- }, $z.core.$strip>;
129
- }, $z.core.$strip>;
158
+ args: z.ZodObject<{
159
+ key: z.ZodString;
160
+ }, z.core.$strip>;
161
+ res: z.ZodObject<{
162
+ str: z.ZodString;
163
+ num: z.ZodNumber;
164
+ bool: z.ZodBoolean;
165
+ date: z.ZodDate;
166
+ nul: z.ZodNull;
167
+ undef: z.ZodUndefined;
168
+ unk: z.ZodUnknown;
169
+ whatever: z.ZodAny;
170
+ optStr: z.ZodOptional<z.ZodString>;
171
+ nullStr: z.ZodNullable<z.ZodString>;
172
+ defStr: z.ZodDefault<z.ZodString>;
173
+ optNullStr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
174
+ nullOptStr: z.ZodNullable<z.ZodOptional<z.ZodString>>;
175
+ tags: z.ZodArray<z.ZodString>;
176
+ scores: z.ZodNullable<z.ZodArray<z.ZodNumber>>;
177
+ optDates: z.ZodOptional<z.ZodArray<z.ZodDate>>;
178
+ nested: z.ZodObject<{
179
+ a: z.ZodNumber;
180
+ b: z.ZodOptional<z.ZodString>;
181
+ c: z.ZodObject<{
182
+ d: z.ZodBoolean;
183
+ e: z.ZodNullable<z.ZodArray<z.ZodString>>;
184
+ }, z.core.$strip>;
185
+ }, z.core.$strip>;
186
+ }, z.core.$strip>;
130
187
  };
@@ -1,103 +1,149 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.primitives = exports.update = exports.fetch = exports.create = void 0;
3
+ exports.primitives = exports.tag = exports.statusFilter = exports.resolve = exports.update = exports.fetch = exports.create = void 0;
4
4
  const __1 = require("../../..");
5
5
  // --- Reusable schemas ---
6
- const addressSchema = __1.$z.object({
7
- street: __1.$z.string(),
8
- city: __1.$z.string(),
9
- state: __1.$z.string(),
10
- zip: __1.$z.string(),
11
- country: __1.$z.string().default('US') // ZodDefault<ZodString> → string
6
+ const addressSchema = __1.z.object({
7
+ street: __1.z.string(),
8
+ city: __1.z.string(),
9
+ state: __1.z.string(),
10
+ zip: __1.z.string(),
11
+ country: __1.z.string().default('US') // ZodDefault<ZodString> → string
12
12
  });
13
- const orderItemSchema = __1.$z.object({
14
- productId: __1.$z.number(),
15
- quantity: __1.$z.number().min(1),
16
- price: __1.$z.number(),
17
- notes: __1.$z.string().optional(), // ZodOptional<ZodString> → string?
18
- discount: __1.$z.number().nullable() // ZodNullable<ZodNumber> → number | null
13
+ const orderItemSchema = __1.z.object({
14
+ productId: __1.z.number(),
15
+ quantity: __1.z.number().min(1),
16
+ price: __1.z.number(),
17
+ notes: __1.z.string().optional(), // ZodOptional<ZodString> → string?
18
+ discount: __1.z.number().nullable() // ZodNullable<ZodNumber> → number | null
19
19
  });
20
20
  // --- create ---
21
21
  exports.create = {
22
- args: __1.$z.object({
23
- customerId: __1.$z.number().min(1),
24
- items: __1.$z.array(orderItemSchema), // ZodArray<ZodObject> → {...}[]
22
+ args: __1.z.object({
23
+ customerId: __1.z.number().min(1),
24
+ items: __1.z.array(orderItemSchema), // ZodArray<ZodObject> → {...}[]
25
25
  shippingAddress: addressSchema, // nested ZodObject
26
26
  billingAddress: addressSchema.nullable(), // ZodNullable<ZodObject> → {...} | null
27
- couponCode: __1.$z.string().nullable().optional(), // ZodOptional<ZodNullable<ZodString>> → (string | null)?
28
- scheduledDate: __1.$z.date().optional(), // ZodOptional<ZodDate> → Date?
29
- isGift: __1.$z.boolean(), // ZodBoolean → boolean
30
- giftMessage: __1.$z.string().nullable() // ZodNullable<ZodString> → string | null
27
+ couponCode: __1.z.string().nullable().optional(), // ZodOptional<ZodNullable<ZodString>> → (string | null)?
28
+ scheduledDate: __1.z.date().optional(), // ZodOptional<ZodDate> → Date?
29
+ isGift: __1.z.boolean(), // ZodBoolean → boolean
30
+ giftMessage: __1.z.string().nullable() // ZodNullable<ZodString> → string | null
31
31
  }),
32
- res: __1.$z.object({
33
- id: __1.$z.number(),
34
- status: __1.$z.string(),
35
- total: __1.$z.number(),
36
- items: __1.$z.array(orderItemSchema),
37
- createdAt: __1.$z.date() // ZodDate → Date
32
+ res: __1.z.object({
33
+ id: __1.z.number(),
34
+ status: __1.z.string(),
35
+ total: __1.z.number(),
36
+ items: __1.z.array(orderItemSchema),
37
+ createdAt: __1.z.date() // ZodDate → Date
38
38
  })
39
39
  };
40
40
  // --- fetch ---
41
41
  exports.fetch = {
42
- args: __1.$z.object({
43
- id: __1.$z.number().min(1)
42
+ args: __1.z.object({
43
+ id: __1.z.number().min(1)
44
44
  }),
45
- res: __1.$z.object({
46
- id: __1.$z.number(),
47
- customerId: __1.$z.number(),
48
- status: __1.$z.string(),
49
- total: __1.$z.number(),
50
- items: __1.$z.array(orderItemSchema),
45
+ res: __1.z.object({
46
+ id: __1.z.number(),
47
+ customerId: __1.z.number(),
48
+ status: __1.z.string(),
49
+ total: __1.z.number(),
50
+ items: __1.z.array(orderItemSchema),
51
51
  shippingAddress: addressSchema,
52
52
  billingAddress: addressSchema.nullable(),
53
- isGift: __1.$z.boolean(),
54
- giftMessage: __1.$z.string().nullable(),
55
- createdAt: __1.$z.date(),
56
- updatedAt: __1.$z.date().nullable() // ZodNullable<ZodDate> → Date | null
53
+ isGift: __1.z.boolean(),
54
+ giftMessage: __1.z.string().nullable(),
55
+ createdAt: __1.z.date(),
56
+ updatedAt: __1.z.date().nullable() // ZodNullable<ZodDate> → Date | null
57
57
  })
58
58
  };
59
59
  // --- update ---
60
60
  exports.update = {
61
- args: __1.$z.object({
62
- id: __1.$z.number().min(1),
63
- status: __1.$z.string().optional(),
61
+ args: __1.z.object({
62
+ id: __1.z.number().min(1),
63
+ status: __1.z.string().optional(),
64
64
  shippingAddress: addressSchema.optional(), // ZodOptional<ZodObject> → {...}?
65
- giftMessage: __1.$z.string().nullable().optional()
65
+ giftMessage: __1.z.string().nullable().optional()
66
66
  }),
67
- res: __1.$z.object({
68
- id: __1.$z.number(),
69
- status: __1.$z.string(),
70
- updatedAt: __1.$z.date()
67
+ res: __1.z.object({
68
+ id: __1.z.number(),
69
+ status: __1.z.string(),
70
+ updatedAt: __1.z.date()
71
+ })
72
+ };
73
+ // --- resolve: exercises ZodDiscriminatedUnion + ZodLiteral + ZodEnum ---
74
+ const orderStatusEnum = __1.z.enum(['pending', 'confirmed', 'shipped', 'delivered', 'cancelled']);
75
+ exports.resolve = {
76
+ args: __1.z.object({
77
+ id: __1.z.number().min(1)
78
+ }),
79
+ res: __1.z.discriminatedUnion('status', [
80
+ __1.z.object({
81
+ status: __1.z.literal('found'),
82
+ order: __1.z.object({
83
+ id: __1.z.number(),
84
+ customerName: __1.z.string(),
85
+ orderStatus: orderStatusEnum,
86
+ total: __1.z.number()
87
+ })
88
+ }),
89
+ __1.z.object({
90
+ status: __1.z.literal('not_found')
91
+ })
92
+ ])
93
+ };
94
+ // --- statusFilter: exercises ZodEnum in args and response ---
95
+ exports.statusFilter = {
96
+ args: __1.z.object({
97
+ status: orderStatusEnum
98
+ }),
99
+ res: __1.z.object({
100
+ orders: __1.z.array(__1.z.object({
101
+ id: __1.z.number(),
102
+ status: orderStatusEnum,
103
+ total: __1.z.number()
104
+ }))
105
+ })
106
+ };
107
+ // --- tag: exercises ZodUnion ---
108
+ exports.tag = {
109
+ args: __1.z.object({
110
+ orderId: __1.z.number().min(1),
111
+ tag: __1.z.union([__1.z.string(), __1.z.number()])
112
+ }),
113
+ res: __1.z.object({
114
+ orderId: __1.z.number(),
115
+ tag: __1.z.union([__1.z.string(), __1.z.number()]),
116
+ appliedAt: __1.z.date()
71
117
  })
72
118
  };
73
119
  // --- primitives: exercises all remaining keyword types ---
74
120
  exports.primitives = {
75
- args: __1.$z.object({
76
- key: __1.$z.string()
121
+ args: __1.z.object({
122
+ key: __1.z.string()
77
123
  }),
78
- res: __1.$z.object({
79
- str: __1.$z.string(), // ZodString → string
80
- num: __1.$z.number(), // ZodNumber → number
81
- bool: __1.$z.boolean(), // ZodBoolean → boolean
82
- date: __1.$z.date(), // ZodDate → Date
83
- nul: __1.$z.null(), // ZodNull → null
84
- undef: __1.$z.undefined(), // ZodUndefined → undefined
85
- unk: __1.$z.unknown(), // ZodUnknown → unknown
86
- whatever: __1.$z.any(), // ZodAny → any
87
- optStr: __1.$z.string().optional(), // ZodOptional<ZodString> → string?
88
- nullStr: __1.$z.string().nullable(), // ZodNullable<ZodString> → string | null
89
- defStr: __1.$z.string().default('hello'), // ZodDefault<ZodString> → string
90
- optNullStr: __1.$z.string().nullable().optional(), // ZodOptional<ZodNullable> → (string | null)?
91
- nullOptStr: __1.$z.string().optional().nullable(), // ZodNullable<ZodOptional> → (string | undefined) | null
92
- tags: __1.$z.array(__1.$z.string()), // ZodArray<ZodString> → string[]
93
- scores: __1.$z.array(__1.$z.number()).nullable(), // ZodNullable<ZodArray<ZodNumber>> → number[] | null
94
- optDates: __1.$z.array(__1.$z.date()).optional(), // ZodOptional<ZodArray<ZodDate>> → Date[]?
95
- nested: __1.$z.object({
96
- a: __1.$z.number(),
97
- b: __1.$z.string().optional(),
98
- c: __1.$z.object({
99
- d: __1.$z.boolean(),
100
- e: __1.$z.array(__1.$z.string()).nullable()
124
+ res: __1.z.object({
125
+ str: __1.z.string(), // ZodString → string
126
+ num: __1.z.number(), // ZodNumber → number
127
+ bool: __1.z.boolean(), // ZodBoolean → boolean
128
+ date: __1.z.date(), // ZodDate → Date
129
+ nul: __1.z.null(), // ZodNull → null
130
+ undef: __1.z.undefined(), // ZodUndefined → undefined
131
+ unk: __1.z.unknown(), // ZodUnknown → unknown
132
+ whatever: __1.z.any(), // ZodAny → any
133
+ optStr: __1.z.string().optional(), // ZodOptional<ZodString> → string?
134
+ nullStr: __1.z.string().nullable(), // ZodNullable<ZodString> → string | null
135
+ defStr: __1.z.string().default('hello'), // ZodDefault<ZodString> → string
136
+ optNullStr: __1.z.string().nullable().optional(), // ZodOptional<ZodNullable> → (string | null)?
137
+ nullOptStr: __1.z.string().optional().nullable(), // ZodNullable<ZodOptional> → (string | undefined) | null
138
+ tags: __1.z.array(__1.z.string()), // ZodArray<ZodString> → string[]
139
+ scores: __1.z.array(__1.z.number()).nullable(), // ZodNullable<ZodArray<ZodNumber>> → number[] | null
140
+ optDates: __1.z.array(__1.z.date()).optional(), // ZodOptional<ZodArray<ZodDate>> → Date[]?
141
+ nested: __1.z.object({
142
+ a: __1.z.number(),
143
+ b: __1.z.string().optional(),
144
+ c: __1.z.object({
145
+ d: __1.z.boolean(),
146
+ e: __1.z.array(__1.z.string()).nullable()
101
147
  })
102
148
  })
103
149
  })
@@ -1,4 +1,4 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  import * as types from './types';
3
3
  export interface Product {
4
4
  id: number;
@@ -10,7 +10,7 @@ type Context = {
10
10
  requestedAt: number;
11
11
  userId: number;
12
12
  };
13
- export declare const fetch: (args: $z.infer<typeof types.fetch.args>, context: Context) => Promise<$z.infer<typeof types.fetch.res>>;
14
- export declare const create: (args: $z.infer<typeof types.create.args>, context: Context) => Promise<$z.infer<typeof types.create.res>>;
13
+ export declare const fetch: (args: z.infer<typeof types.fetch.args>, context: Context) => Promise<z.infer<typeof types.fetch.res>>;
14
+ export declare const create: (args: z.infer<typeof types.create.args>, context: Context) => Promise<z.infer<typeof types.create.res>>;
15
15
  export declare const list: () => Promise<Product[]>;
16
16
  export {};
@@ -1,24 +1,24 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  export declare const fetch: {
3
- args: $z.ZodObject<{
4
- id: $z.ZodNumber;
5
- }, $z.core.$strip>;
6
- res: $z.ZodObject<{
7
- id: $z.ZodNumber;
8
- name: $z.ZodString;
9
- price: $z.ZodNumber;
10
- createdAt: $z.ZodDate;
11
- }, $z.core.$strip>;
3
+ args: z.ZodObject<{
4
+ id: z.ZodNumber;
5
+ }, z.core.$strip>;
6
+ res: z.ZodObject<{
7
+ id: z.ZodNumber;
8
+ name: z.ZodString;
9
+ price: z.ZodNumber;
10
+ createdAt: z.ZodDate;
11
+ }, z.core.$strip>;
12
12
  };
13
13
  export declare const create: {
14
- args: $z.ZodObject<{
15
- name: $z.ZodString;
16
- price: $z.ZodNumber;
17
- }, $z.core.$strip>;
18
- res: $z.ZodObject<{
19
- id: $z.ZodNumber;
20
- name: $z.ZodString;
21
- price: $z.ZodNumber;
22
- createdAt: $z.ZodDate;
23
- }, $z.core.$strip>;
14
+ args: z.ZodObject<{
15
+ name: z.ZodString;
16
+ price: z.ZodNumber;
17
+ }, z.core.$strip>;
18
+ res: z.ZodObject<{
19
+ id: z.ZodNumber;
20
+ name: z.ZodString;
21
+ price: z.ZodNumber;
22
+ createdAt: z.ZodDate;
23
+ }, z.core.$strip>;
24
24
  };
@@ -3,25 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = exports.fetch = void 0;
4
4
  const __1 = require("../../..");
5
5
  exports.fetch = {
6
- args: __1.$z.object({
7
- id: __1.$z.number().min(1)
6
+ args: __1.z.object({
7
+ id: __1.z.number().min(1)
8
8
  }),
9
- res: __1.$z.object({
10
- id: __1.$z.number(),
11
- name: __1.$z.string(),
12
- price: __1.$z.number(),
13
- createdAt: __1.$z.date()
9
+ res: __1.z.object({
10
+ id: __1.z.number(),
11
+ name: __1.z.string(),
12
+ price: __1.z.number(),
13
+ createdAt: __1.z.date()
14
14
  })
15
15
  };
16
16
  exports.create = {
17
- args: __1.$z.object({
18
- name: __1.$z.string().min(1),
19
- price: __1.$z.number().min(0)
17
+ args: __1.z.object({
18
+ name: __1.z.string().min(1),
19
+ price: __1.z.number().min(0)
20
20
  }),
21
- res: __1.$z.object({
22
- id: __1.$z.number(),
23
- name: __1.$z.string(),
24
- price: __1.$z.number(),
25
- createdAt: __1.$z.date()
21
+ res: __1.z.object({
22
+ id: __1.z.number(),
23
+ name: __1.z.string(),
24
+ price: __1.z.number(),
25
+ createdAt: __1.z.date()
26
26
  })
27
27
  };
@@ -1,4 +1,4 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  import * as types from './types';
3
3
  export interface User {
4
4
  id: number;
@@ -10,8 +10,8 @@ type Context = {
10
10
  requestedAt: number;
11
11
  userId: number;
12
12
  };
13
- export declare const fetch: (args: $z.infer<typeof types.fetch.args>, context: Context) => Promise<$z.infer<typeof types.fetch.res>>;
14
- export declare const create: (args: $z.infer<typeof types.create.args>, context: Context) => Promise<$z.infer<typeof types.create.res>>;
13
+ export declare const fetch: (args: z.infer<typeof types.fetch.args>, context: Context) => Promise<z.infer<typeof types.fetch.res>>;
14
+ export declare const create: (args: z.infer<typeof types.create.args>, context: Context) => Promise<z.infer<typeof types.create.res>>;
15
15
  export declare const update: (args: {
16
16
  id: number;
17
17
  name?: string;
@@ -1,23 +1,23 @@
1
- import { $z } from '../../..';
1
+ import { z } from '../../..';
2
2
  export declare const fetch: {
3
- args: $z.ZodObject<{
4
- id: $z.ZodNumber;
5
- }, $z.core.$strip>;
6
- res: $z.ZodObject<{
7
- id: $z.ZodNumber;
8
- name: $z.ZodString;
9
- email: $z.ZodString;
10
- }, $z.core.$strip>;
3
+ args: z.ZodObject<{
4
+ id: z.ZodNumber;
5
+ }, z.core.$strip>;
6
+ res: z.ZodObject<{
7
+ id: z.ZodNumber;
8
+ name: z.ZodString;
9
+ email: z.ZodString;
10
+ }, z.core.$strip>;
11
11
  };
12
12
  export declare const create: {
13
- args: $z.ZodObject<{
14
- name: $z.ZodString;
15
- email: $z.ZodString;
16
- }, $z.core.$strip>;
17
- res: $z.ZodObject<{
18
- id: $z.ZodNumber;
19
- name: $z.ZodString;
20
- email: $z.ZodString;
21
- createdAt: $z.ZodDate;
22
- }, $z.core.$strip>;
13
+ args: z.ZodObject<{
14
+ name: z.ZodString;
15
+ email: z.ZodString;
16
+ }, z.core.$strip>;
17
+ res: z.ZodObject<{
18
+ id: z.ZodNumber;
19
+ name: z.ZodString;
20
+ email: z.ZodString;
21
+ createdAt: z.ZodDate;
22
+ }, z.core.$strip>;
23
23
  };
@@ -3,24 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = exports.fetch = void 0;
4
4
  const __1 = require("../../..");
5
5
  exports.fetch = {
6
- args: __1.$z.object({
7
- id: __1.$z.number().min(1)
6
+ args: __1.z.object({
7
+ id: __1.z.number().min(1)
8
8
  }),
9
- res: __1.$z.object({
10
- id: __1.$z.number(),
11
- name: __1.$z.string(),
12
- email: __1.$z.string()
9
+ res: __1.z.object({
10
+ id: __1.z.number(),
11
+ name: __1.z.string(),
12
+ email: __1.z.string()
13
13
  })
14
14
  };
15
15
  exports.create = {
16
- args: __1.$z.object({
17
- name: __1.$z.string().min(1),
18
- email: __1.$z.string().email()
16
+ args: __1.z.object({
17
+ name: __1.z.string().min(1),
18
+ email: __1.z.string().email()
19
19
  }),
20
- res: __1.$z.object({
21
- id: __1.$z.number(),
22
- name: __1.$z.string(),
23
- email: __1.$z.string(),
24
- createdAt: __1.$z.date()
20
+ res: __1.z.object({
21
+ id: __1.z.number(),
22
+ name: __1.z.string(),
23
+ email: __1.z.string(),
24
+ createdAt: __1.z.date()
25
25
  })
26
26
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Application, default as express, Express, NextFunction, Request, Response, Router } from 'express';
2
2
  export { createBridge, createMiddleware, onShutdown } from './bridge';
3
3
  export { config as tbConfig } from './config';
4
- export { z as $z } from 'zod';
4
+ export { z } from 'zod';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.$z = exports.tbConfig = exports.onShutdown = exports.createMiddleware = exports.createBridge = exports.Router = exports.express = void 0;
6
+ exports.z = exports.tbConfig = exports.onShutdown = exports.createMiddleware = exports.createBridge = exports.Router = exports.express = void 0;
7
7
  var express_1 = require("express");
8
8
  Object.defineProperty(exports, "express", { enumerable: true, get: function () { return __importDefault(express_1).default; } });
9
9
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
@@ -14,4 +14,4 @@ Object.defineProperty(exports, "onShutdown", { enumerable: true, get: function (
14
14
  var config_1 = require("./config");
15
15
  Object.defineProperty(exports, "tbConfig", { enumerable: true, get: function () { return config_1.config; } });
16
16
  var zod_1 = require("zod");
17
- Object.defineProperty(exports, "$z", { enumerable: true, get: function () { return zod_1.z; } });
17
+ Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
@@ -59,9 +59,7 @@ export default typedBridge
59
59
  `;
60
60
  /**
61
61
  * Transformer #1:
62
- * Resolve zod types to plain TypeScript types, and remove zod imports.
63
- * Handles both Zod 3 (zod.TypeOf<ZodObject<S,UK,CA,Output,Input>>) and
64
- * Zod 4 (zod.infer<ZodObject<Shape, UK>>) patterns.
62
+ * Resolve Zod 4 types to plain TypeScript types, and remove zod imports.
65
63
  */
66
64
  const resolveZodTypesTransformer = context => {
67
65
  return sourceFile => {
@@ -74,23 +72,32 @@ const resolveZodTypesTransformer = context => {
74
72
  ZodVoid: typescript_1.default.SyntaxKind.VoidKeyword,
75
73
  ZodAny: typescript_1.default.SyntaxKind.AnyKeyword,
76
74
  ZodUnknown: typescript_1.default.SyntaxKind.UnknownKeyword,
77
- ZodNever: typescript_1.default.SyntaxKind.NeverKeyword,
75
+ ZodNever: typescript_1.default.SyntaxKind.NeverKeyword
78
76
  };
79
77
  function getZodRef(node) {
80
78
  if (typescript_1.default.isTypeReferenceNode(node) &&
81
79
  typescript_1.default.isQualifiedName(node.typeName) &&
82
80
  typescript_1.default.isIdentifier(node.typeName.left) &&
83
- (node.typeName.left.text === 'zod' || node.typeName.left.text.startsWith('zod_'))) {
81
+ (node.typeName.left.text === 'z' ||
82
+ node.typeName.left.text === 'zod' ||
83
+ node.typeName.left.text.startsWith('zod_'))) {
84
84
  return { name: node.typeName.right.text, typeArgs: node.typeArguments };
85
85
  }
86
86
  return null;
87
87
  }
88
+ function unwrapReadonlyTuple(node) {
89
+ if (typescript_1.default.isTupleTypeNode(node))
90
+ return node;
91
+ if (typescript_1.default.isTypeOperatorNode(node) && node.operator === typescript_1.default.SyntaxKind.ReadonlyKeyword && typescript_1.default.isTupleTypeNode(node.type))
92
+ return node.type;
93
+ return null;
94
+ }
88
95
  function resolveZodType(node) {
89
96
  const ref = getZodRef(node);
90
97
  if (!ref)
91
98
  return node;
92
99
  const { name, typeArgs } = ref;
93
- if ((name === 'infer' || name === 'TypeOf') && typeArgs?.length === 1)
100
+ if (name === 'infer' && typeArgs?.length === 1)
94
101
  return resolveZodType(typeArgs[0]);
95
102
  const keyword = zodKeywordMap[name];
96
103
  if (keyword !== undefined)
@@ -99,12 +106,8 @@ const resolveZodTypesTransformer = context => {
99
106
  return typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNull());
100
107
  if (name === 'ZodDate')
101
108
  return typescript_1.default.factory.createTypeReferenceNode('Date');
102
- if (name === 'ZodObject' && typeArgs) {
103
- if (typeArgs.length >= 4)
104
- return resolveZodType(typeArgs[3]);
105
- if (typeArgs.length >= 1 && typescript_1.default.isTypeLiteralNode(typeArgs[0]))
106
- return resolveShape(typeArgs[0]);
107
- }
109
+ if (name === 'ZodObject' && typeArgs && typeArgs.length >= 1 && typescript_1.default.isTypeLiteralNode(typeArgs[0]))
110
+ return resolveShape(typeArgs[0]);
108
111
  if (name === 'ZodArray' && typeArgs && typeArgs.length >= 1)
109
112
  return typescript_1.default.factory.createArrayTypeNode(resolveZodType(typeArgs[0]));
110
113
  if (name === 'ZodOptional' && typeArgs && typeArgs.length >= 1)
@@ -119,6 +122,30 @@ const resolveZodTypesTransformer = context => {
119
122
  ]);
120
123
  if (name === 'ZodDefault' && typeArgs && typeArgs.length >= 1)
121
124
  return resolveZodType(typeArgs[0]);
125
+ if (name === 'ZodLiteral' && typeArgs && typeArgs.length >= 1)
126
+ return typeArgs[0];
127
+ // v4: ZodEnum<{pending: "pending", confirmed: "confirmed", ...}>
128
+ if (name === 'ZodEnum' && typeArgs && typeArgs.length >= 1 && typescript_1.default.isTypeLiteralNode(typeArgs[0])) {
129
+ const types = [];
130
+ for (const member of typeArgs[0].members) {
131
+ if (typescript_1.default.isPropertySignature(member) && member.type)
132
+ types.push(member.type);
133
+ }
134
+ if (types.length > 0)
135
+ return typescript_1.default.factory.createUnionTypeNode(types);
136
+ }
137
+ // v4: ZodDiscriminatedUnion<[ZodObject<...>, ...], "disc">
138
+ if (name === 'ZodDiscriminatedUnion' && typeArgs && typeArgs.length >= 1) {
139
+ const tuple = unwrapReadonlyTuple(typeArgs[0]);
140
+ if (tuple)
141
+ return typescript_1.default.factory.createUnionTypeNode(tuple.elements.map(e => resolveZodType(e)));
142
+ }
143
+ // v4: ZodUnion<readonly [ZodString, ZodNumber]>
144
+ if (name === 'ZodUnion' && typeArgs && typeArgs.length >= 1) {
145
+ const tuple = unwrapReadonlyTuple(typeArgs[0]);
146
+ if (tuple)
147
+ return typescript_1.default.factory.createUnionTypeNode(tuple.elements.map(e => resolveZodType(e)));
148
+ }
122
149
  return node;
123
150
  }
124
151
  function resolveShape(shape) {
@@ -137,7 +164,7 @@ const resolveZodTypesTransformer = context => {
137
164
  function typeVisitor(node) {
138
165
  if (typescript_1.default.isTypeNode(node)) {
139
166
  const ref = getZodRef(node);
140
- if (ref && (ref.name === 'infer' || ref.name === 'TypeOf'))
167
+ if (ref)
141
168
  return resolveZodType(node);
142
169
  }
143
170
  return typescript_1.default.visitEachChild(node, typeVisitor, context);
@@ -205,11 +232,15 @@ const removeDefaultExportTransformer = context => {
205
232
  * 3. Writes the final file output.
206
233
  */
207
234
  function cleanTsFile(src) {
208
- let sourceCode = fs_1.default.readFileSync(src, 'utf-8');
235
+ const sourceCode = fs_1.default.readFileSync(src, 'utf-8');
209
236
  // Parse the source
210
237
  const sourceFile = typescript_1.default.createSourceFile(path_1.default.basename(src), sourceCode, typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.ScriptKind.TS);
211
238
  // Run the transformers
212
- const result = typescript_1.default.transform(sourceFile, [resolveZodTypesTransformer, removeSecondParamTransformer, removeDefaultExportTransformer]);
239
+ const result = typescript_1.default.transform(sourceFile, [
240
+ resolveZodTypesTransformer,
241
+ removeSecondParamTransformer,
242
+ removeDefaultExportTransformer
243
+ ]);
213
244
  // Print final code
214
245
  const eslintDisable = `/* eslint-disable */`;
215
246
  const printer = typescript_1.default.createPrinter();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-bridge",
3
3
  "description": "Strictly typed server functions for typescript apps",
4
- "version": "2.1.1",
4
+ "version": "2.1.3",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "neilveil",
package/readme.md CHANGED
@@ -217,22 +217,22 @@ createMiddleware('user.*', async (req, res) => {
217
217
 
218
218
  ## Zod Validation
219
219
 
220
- Typed Bridge ships with Zod and re-exports it as `$z`. Define schemas and use them in handlers:
220
+ Typed Bridge ships with Zod and re-exports it as `z`. Define schemas and use them in handlers:
221
221
 
222
222
  ### 1. Declare Schemas
223
223
 
224
224
  `types.ts`:
225
225
 
226
226
  ```ts
227
- import { $z } from 'typed-bridge'
227
+ import { z } from 'typed-bridge'
228
228
 
229
229
  export const fetch = {
230
- args: $z.object({
231
- id: $z.number().min(1)
230
+ args: z.object({
231
+ id: z.number().min(1)
232
232
  }),
233
- res: $z.object({
234
- id: $z.number(),
235
- name: $z.string()
233
+ res: z.object({
234
+ id: z.number(),
235
+ name: z.string()
236
236
  })
237
237
  }
238
238
  ```
@@ -240,13 +240,13 @@ export const fetch = {
240
240
  ### 2. Use in Handler
241
241
 
242
242
  ```ts
243
- import { $z } from 'typed-bridge'
243
+ import { z } from 'typed-bridge'
244
244
  import * as types from './types'
245
245
 
246
246
  export const fetch = async (
247
- args: $z.infer<typeof types.fetch.args>,
247
+ args: z.infer<typeof types.fetch.args>,
248
248
  context: { id: number }
249
- ): Promise<$z.infer<typeof types.fetch.res>> => {
249
+ ): Promise<z.infer<typeof types.fetch.res>> => {
250
250
  args = types.fetch.args.parse(args)
251
251
 
252
252
  const user = users.find(user => user.id === args.id)
@@ -310,23 +310,23 @@ onShutdown(() => {
310
310
 
311
311
  ### vs tRPC
312
312
 
313
- | | **Typed Bridge** | **tRPC** |
314
- |---|---|---|
315
- | **Setup** | Define functions, generate typed client, done | Routers, procedures, adapters |
316
- | **Monorepo required?** | No, generated client is a standalone file | Practically yes, for type inference |
317
- | **Frontend framework** | Any (React, Vue, Angular, RN, etc.) | React-first, adapters for others |
318
- | **Learning curve** | Minimal, plain async functions | Moderate, procedures, context, middleware patterns |
319
- | **Runtime validation** | Zod (built-in) | Zod or others via `.input()` |
313
+ | | **Typed Bridge** | **tRPC** |
314
+ | ---------------------- | --------------------------------------------- | -------------------------------------------------- |
315
+ | **Setup** | Define functions, generate typed client, done | Routers, procedures, adapters |
316
+ | **Monorepo required?** | No, generated client is a standalone file | Practically yes, for type inference |
317
+ | **Frontend framework** | Any (React, Vue, Angular, RN, etc.) | React-first, adapters for others |
318
+ | **Learning curve** | Minimal, plain async functions | Moderate, procedures, context, middleware patterns |
319
+ | **Runtime validation** | Zod (built-in) | Zod or others via `.input()` |
320
320
 
321
321
  ### vs GraphQL
322
322
 
323
- | | **Typed Bridge** | **GraphQL** |
324
- |---|---|---|
325
- | **Setup** | Define functions, generate typed client, done | Schema definition, resolvers, codegen |
326
- | **Type safety** | Automatic from function signatures | Requires codegen toolchain (e.g. GraphQL Code Generator) |
327
- | **Overfetching** | Not applicable, you control what each function returns | Solved by design with field selection |
328
- | **Learning curve** | Minimal, plain TypeScript | Significant: SDL, resolvers, fragments, queries, mutations |
329
- | **Best for** | App-specific backends, internal APIs | Public APIs, multi-client data graphs |
323
+ | | **Typed Bridge** | **GraphQL** |
324
+ | ------------------ | ------------------------------------------------------ | ---------------------------------------------------------- |
325
+ | **Setup** | Define functions, generate typed client, done | Schema definition, resolvers, codegen |
326
+ | **Type safety** | Automatic from function signatures | Requires codegen toolchain (e.g. GraphQL Code Generator) |
327
+ | **Overfetching** | Not applicable, you control what each function returns | Solved by design with field selection |
328
+ | **Learning curve** | Minimal, plain TypeScript | Significant: SDL, resolvers, fragments, queries, mutations |
329
+ | **Best for** | App-specific backends, internal APIs | Public APIs, multi-client data graphs |
330
330
 
331
331
  Typed Bridge is for teams that want **type-safe RPCs without the architecture overhead**. You write normal TypeScript functions on the server, and the client just works.
332
332
 
@@ -351,7 +351,7 @@ src/
351
351
  ### Adding a new route
352
352
 
353
353
  1. Create handler in `bridge/<module>/index.ts`
354
- 2. If using Zod, add schemas in `<module>/types.ts` using `$z` from `typed-bridge`
354
+ 2. If using Zod, add schemas in `<module>/types.ts` using `z` from `typed-bridge`
355
355
  3. Register route in `bridge/index.ts` as `'module.action': module.action`
356
356
  4. If middleware needed, add `createMiddleware(...)` and import the file in server entry
357
357
  5. Run `gen:typed-bridge-client` to regenerate the typed client
@@ -361,4 +361,3 @@ src/
361
361
  ## Developer
362
362
 
363
363
  Developed & maintained by [neilveil](https://github.com/neilveil). Give a star to support this project!
364
-
package/test/bridge.ts CHANGED
@@ -174,6 +174,36 @@ declare const _default: {
174
174
  updatedAt: Date;
175
175
  }>;
176
176
  'order.list': () => Promise<Order[]>;
177
+ 'order.resolve': (args: {
178
+ id: number;
179
+ }) => Promise<{
180
+ status: "found";
181
+ order: {
182
+ id: number;
183
+ customerName: string;
184
+ orderStatus: "pending" | "confirmed" | "shipped" | "delivered" | "cancelled";
185
+ total: number;
186
+ };
187
+ } | {
188
+ status: "not_found";
189
+ }>;
190
+ 'order.statusFilter': (args: {
191
+ status: "pending" | "confirmed" | "shipped" | "delivered" | "cancelled";
192
+ }) => Promise<{
193
+ orders: {
194
+ id: number;
195
+ status: "pending" | "confirmed" | "shipped" | "delivered" | "cancelled";
196
+ total: number;
197
+ }[];
198
+ }>;
199
+ 'order.tag': (args: {
200
+ orderId: number;
201
+ tag: string | number;
202
+ }) => Promise<{
203
+ orderId: number;
204
+ tag: string | number;
205
+ appliedAt: Date;
206
+ }>;
177
207
  'order.primitives': (args: {
178
208
  key: string;
179
209
  }) => Promise<{