typed-bridge 2.1.2 → 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.
- package/dist/demo/bridge/order/index.d.ts +8 -8
- package/dist/demo/bridge/order/index.js +3 -1
- package/dist/demo/bridge/order/types.d.ts +155 -155
- package/dist/demo/bridge/order/types.js +94 -94
- package/dist/demo/bridge/product/index.d.ts +3 -3
- package/dist/demo/bridge/product/types.d.ts +20 -20
- package/dist/demo/bridge/product/types.js +15 -15
- package/dist/demo/bridge/user/index.d.ts +3 -3
- package/dist/demo/bridge/user/types.d.ts +19 -19
- package/dist/demo/bridge/user/types.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/readme.md +25 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from '../../..';
|
|
2
2
|
import * as types from './types';
|
|
3
3
|
export interface OrderItem {
|
|
4
4
|
productId: number;
|
|
@@ -31,12 +31,12 @@ type Context = {
|
|
|
31
31
|
requestedAt: number;
|
|
32
32
|
userId: number;
|
|
33
33
|
};
|
|
34
|
-
export declare const create: (args:
|
|
35
|
-
export declare const fetch: (args:
|
|
36
|
-
export declare const update: (args:
|
|
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 resolve: (args:
|
|
39
|
-
export declare const statusFilter: (args:
|
|
40
|
-
export declare const tag: (args:
|
|
41
|
-
export declare const primitives: (args:
|
|
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>>;
|
|
42
42
|
export {};
|
|
@@ -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
|
|
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(),
|
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from '../../..';
|
|
2
2
|
export declare const create: {
|
|
3
|
-
args:
|
|
4
|
-
customerId:
|
|
5
|
-
items:
|
|
6
|
-
productId:
|
|
7
|
-
quantity:
|
|
8
|
-
price:
|
|
9
|
-
notes:
|
|
10
|
-
discount:
|
|
11
|
-
},
|
|
12
|
-
shippingAddress:
|
|
13
|
-
street:
|
|
14
|
-
city:
|
|
15
|
-
state:
|
|
16
|
-
zip:
|
|
17
|
-
country:
|
|
18
|
-
},
|
|
19
|
-
billingAddress:
|
|
20
|
-
street:
|
|
21
|
-
city:
|
|
22
|
-
state:
|
|
23
|
-
zip:
|
|
24
|
-
country:
|
|
25
|
-
},
|
|
26
|
-
couponCode:
|
|
27
|
-
scheduledDate:
|
|
28
|
-
isGift:
|
|
29
|
-
giftMessage:
|
|
30
|
-
},
|
|
31
|
-
res:
|
|
32
|
-
id:
|
|
33
|
-
status:
|
|
34
|
-
total:
|
|
35
|
-
items:
|
|
36
|
-
productId:
|
|
37
|
-
quantity:
|
|
38
|
-
price:
|
|
39
|
-
notes:
|
|
40
|
-
discount:
|
|
41
|
-
},
|
|
42
|
-
createdAt:
|
|
43
|
-
},
|
|
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:
|
|
47
|
-
id:
|
|
48
|
-
},
|
|
49
|
-
res:
|
|
50
|
-
id:
|
|
51
|
-
customerId:
|
|
52
|
-
status:
|
|
53
|
-
total:
|
|
54
|
-
items:
|
|
55
|
-
productId:
|
|
56
|
-
quantity:
|
|
57
|
-
price:
|
|
58
|
-
notes:
|
|
59
|
-
discount:
|
|
60
|
-
},
|
|
61
|
-
shippingAddress:
|
|
62
|
-
street:
|
|
63
|
-
city:
|
|
64
|
-
state:
|
|
65
|
-
zip:
|
|
66
|
-
country:
|
|
67
|
-
},
|
|
68
|
-
billingAddress:
|
|
69
|
-
street:
|
|
70
|
-
city:
|
|
71
|
-
state:
|
|
72
|
-
zip:
|
|
73
|
-
country:
|
|
74
|
-
},
|
|
75
|
-
isGift:
|
|
76
|
-
giftMessage:
|
|
77
|
-
createdAt:
|
|
78
|
-
updatedAt:
|
|
79
|
-
},
|
|
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:
|
|
83
|
-
id:
|
|
84
|
-
status:
|
|
85
|
-
shippingAddress:
|
|
86
|
-
street:
|
|
87
|
-
city:
|
|
88
|
-
state:
|
|
89
|
-
zip:
|
|
90
|
-
country:
|
|
91
|
-
},
|
|
92
|
-
giftMessage:
|
|
93
|
-
},
|
|
94
|
-
res:
|
|
95
|
-
id:
|
|
96
|
-
status:
|
|
97
|
-
updatedAt:
|
|
98
|
-
},
|
|
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
99
|
};
|
|
100
100
|
export declare const resolve: {
|
|
101
|
-
args:
|
|
102
|
-
id:
|
|
103
|
-
},
|
|
104
|
-
res:
|
|
105
|
-
status:
|
|
106
|
-
order:
|
|
107
|
-
id:
|
|
108
|
-
customerName:
|
|
109
|
-
orderStatus:
|
|
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
110
|
pending: "pending";
|
|
111
111
|
confirmed: "confirmed";
|
|
112
112
|
shipped: "shipped";
|
|
113
113
|
delivered: "delivered";
|
|
114
114
|
cancelled: "cancelled";
|
|
115
115
|
}>;
|
|
116
|
-
total:
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
status:
|
|
120
|
-
},
|
|
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
121
|
};
|
|
122
122
|
export declare const statusFilter: {
|
|
123
|
-
args:
|
|
124
|
-
status:
|
|
123
|
+
args: z.ZodObject<{
|
|
124
|
+
status: z.ZodEnum<{
|
|
125
125
|
pending: "pending";
|
|
126
126
|
confirmed: "confirmed";
|
|
127
127
|
shipped: "shipped";
|
|
128
128
|
delivered: "delivered";
|
|
129
129
|
cancelled: "cancelled";
|
|
130
130
|
}>;
|
|
131
|
-
},
|
|
132
|
-
res:
|
|
133
|
-
orders:
|
|
134
|
-
id:
|
|
135
|
-
status:
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
res: z.ZodObject<{
|
|
133
|
+
orders: z.ZodArray<z.ZodObject<{
|
|
134
|
+
id: z.ZodNumber;
|
|
135
|
+
status: z.ZodEnum<{
|
|
136
136
|
pending: "pending";
|
|
137
137
|
confirmed: "confirmed";
|
|
138
138
|
shipped: "shipped";
|
|
139
139
|
delivered: "delivered";
|
|
140
140
|
cancelled: "cancelled";
|
|
141
141
|
}>;
|
|
142
|
-
total:
|
|
143
|
-
},
|
|
144
|
-
},
|
|
142
|
+
total: z.ZodNumber;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
145
|
};
|
|
146
146
|
export declare const tag: {
|
|
147
|
-
args:
|
|
148
|
-
orderId:
|
|
149
|
-
tag:
|
|
150
|
-
},
|
|
151
|
-
res:
|
|
152
|
-
orderId:
|
|
153
|
-
tag:
|
|
154
|
-
appliedAt:
|
|
155
|
-
},
|
|
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>;
|
|
156
156
|
};
|
|
157
157
|
export declare const primitives: {
|
|
158
|
-
args:
|
|
159
|
-
key:
|
|
160
|
-
},
|
|
161
|
-
res:
|
|
162
|
-
str:
|
|
163
|
-
num:
|
|
164
|
-
bool:
|
|
165
|
-
date:
|
|
166
|
-
nul:
|
|
167
|
-
undef:
|
|
168
|
-
unk:
|
|
169
|
-
whatever:
|
|
170
|
-
optStr:
|
|
171
|
-
nullStr:
|
|
172
|
-
defStr:
|
|
173
|
-
optNullStr:
|
|
174
|
-
nullOptStr:
|
|
175
|
-
tags:
|
|
176
|
-
scores:
|
|
177
|
-
optDates:
|
|
178
|
-
nested:
|
|
179
|
-
a:
|
|
180
|
-
b:
|
|
181
|
-
c:
|
|
182
|
-
d:
|
|
183
|
-
e:
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
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>;
|
|
187
187
|
};
|
|
@@ -3,147 +3,147 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
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
|
|
7
|
-
street: __1
|
|
8
|
-
city: __1
|
|
9
|
-
state: __1
|
|
10
|
-
zip: __1
|
|
11
|
-
country: __1
|
|
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
|
|
14
|
-
productId: __1
|
|
15
|
-
quantity: __1
|
|
16
|
-
price: __1
|
|
17
|
-
notes: __1
|
|
18
|
-
discount: __1
|
|
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
|
|
23
|
-
customerId: __1
|
|
24
|
-
items: __1
|
|
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
|
|
28
|
-
scheduledDate: __1
|
|
29
|
-
isGift: __1
|
|
30
|
-
giftMessage: __1
|
|
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
|
|
33
|
-
id: __1
|
|
34
|
-
status: __1
|
|
35
|
-
total: __1
|
|
36
|
-
items: __1
|
|
37
|
-
createdAt: __1
|
|
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
|
|
43
|
-
id: __1
|
|
42
|
+
args: __1.z.object({
|
|
43
|
+
id: __1.z.number().min(1)
|
|
44
44
|
}),
|
|
45
|
-
res: __1
|
|
46
|
-
id: __1
|
|
47
|
-
customerId: __1
|
|
48
|
-
status: __1
|
|
49
|
-
total: __1
|
|
50
|
-
items: __1
|
|
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
|
|
54
|
-
giftMessage: __1
|
|
55
|
-
createdAt: __1
|
|
56
|
-
updatedAt: __1
|
|
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
|
|
62
|
-
id: __1
|
|
63
|
-
status: __1
|
|
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
|
|
65
|
+
giftMessage: __1.z.string().nullable().optional()
|
|
66
66
|
}),
|
|
67
|
-
res: __1
|
|
68
|
-
id: __1
|
|
69
|
-
status: __1
|
|
70
|
-
updatedAt: __1
|
|
67
|
+
res: __1.z.object({
|
|
68
|
+
id: __1.z.number(),
|
|
69
|
+
status: __1.z.string(),
|
|
70
|
+
updatedAt: __1.z.date()
|
|
71
71
|
})
|
|
72
72
|
};
|
|
73
73
|
// --- resolve: exercises ZodDiscriminatedUnion + ZodLiteral + ZodEnum ---
|
|
74
|
-
const orderStatusEnum = __1
|
|
74
|
+
const orderStatusEnum = __1.z.enum(['pending', 'confirmed', 'shipped', 'delivered', 'cancelled']);
|
|
75
75
|
exports.resolve = {
|
|
76
|
-
args: __1
|
|
77
|
-
id: __1
|
|
76
|
+
args: __1.z.object({
|
|
77
|
+
id: __1.z.number().min(1)
|
|
78
78
|
}),
|
|
79
|
-
res: __1
|
|
80
|
-
__1
|
|
81
|
-
status: __1
|
|
82
|
-
order: __1
|
|
83
|
-
id: __1
|
|
84
|
-
customerName: __1
|
|
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
85
|
orderStatus: orderStatusEnum,
|
|
86
|
-
total: __1
|
|
86
|
+
total: __1.z.number()
|
|
87
87
|
})
|
|
88
88
|
}),
|
|
89
|
-
__1
|
|
90
|
-
status: __1
|
|
89
|
+
__1.z.object({
|
|
90
|
+
status: __1.z.literal('not_found')
|
|
91
91
|
})
|
|
92
92
|
])
|
|
93
93
|
};
|
|
94
94
|
// --- statusFilter: exercises ZodEnum in args and response ---
|
|
95
95
|
exports.statusFilter = {
|
|
96
|
-
args: __1
|
|
96
|
+
args: __1.z.object({
|
|
97
97
|
status: orderStatusEnum
|
|
98
98
|
}),
|
|
99
|
-
res: __1
|
|
100
|
-
orders: __1
|
|
101
|
-
id: __1
|
|
99
|
+
res: __1.z.object({
|
|
100
|
+
orders: __1.z.array(__1.z.object({
|
|
101
|
+
id: __1.z.number(),
|
|
102
102
|
status: orderStatusEnum,
|
|
103
|
-
total: __1
|
|
103
|
+
total: __1.z.number()
|
|
104
104
|
}))
|
|
105
105
|
})
|
|
106
106
|
};
|
|
107
107
|
// --- tag: exercises ZodUnion ---
|
|
108
108
|
exports.tag = {
|
|
109
|
-
args: __1
|
|
110
|
-
orderId: __1
|
|
111
|
-
tag: __1
|
|
109
|
+
args: __1.z.object({
|
|
110
|
+
orderId: __1.z.number().min(1),
|
|
111
|
+
tag: __1.z.union([__1.z.string(), __1.z.number()])
|
|
112
112
|
}),
|
|
113
|
-
res: __1
|
|
114
|
-
orderId: __1
|
|
115
|
-
tag: __1
|
|
116
|
-
appliedAt: __1
|
|
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()
|
|
117
117
|
})
|
|
118
118
|
};
|
|
119
119
|
// --- primitives: exercises all remaining keyword types ---
|
|
120
120
|
exports.primitives = {
|
|
121
|
-
args: __1
|
|
122
|
-
key: __1
|
|
121
|
+
args: __1.z.object({
|
|
122
|
+
key: __1.z.string()
|
|
123
123
|
}),
|
|
124
|
-
res: __1
|
|
125
|
-
str: __1
|
|
126
|
-
num: __1
|
|
127
|
-
bool: __1
|
|
128
|
-
date: __1
|
|
129
|
-
nul: __1
|
|
130
|
-
undef: __1
|
|
131
|
-
unk: __1
|
|
132
|
-
whatever: __1
|
|
133
|
-
optStr: __1
|
|
134
|
-
nullStr: __1
|
|
135
|
-
defStr: __1
|
|
136
|
-
optNullStr: __1
|
|
137
|
-
nullOptStr: __1
|
|
138
|
-
tags: __1
|
|
139
|
-
scores: __1
|
|
140
|
-
optDates: __1
|
|
141
|
-
nested: __1
|
|
142
|
-
a: __1
|
|
143
|
-
b: __1
|
|
144
|
-
c: __1
|
|
145
|
-
d: __1
|
|
146
|
-
e: __1
|
|
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()
|
|
147
147
|
})
|
|
148
148
|
})
|
|
149
149
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
14
|
-
export declare const create: (args:
|
|
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 {
|
|
1
|
+
import { z } from '../../..';
|
|
2
2
|
export declare const fetch: {
|
|
3
|
-
args:
|
|
4
|
-
id:
|
|
5
|
-
},
|
|
6
|
-
res:
|
|
7
|
-
id:
|
|
8
|
-
name:
|
|
9
|
-
price:
|
|
10
|
-
createdAt:
|
|
11
|
-
},
|
|
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:
|
|
15
|
-
name:
|
|
16
|
-
price:
|
|
17
|
-
},
|
|
18
|
-
res:
|
|
19
|
-
id:
|
|
20
|
-
name:
|
|
21
|
-
price:
|
|
22
|
-
createdAt:
|
|
23
|
-
},
|
|
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
|
|
7
|
-
id: __1
|
|
6
|
+
args: __1.z.object({
|
|
7
|
+
id: __1.z.number().min(1)
|
|
8
8
|
}),
|
|
9
|
-
res: __1
|
|
10
|
-
id: __1
|
|
11
|
-
name: __1
|
|
12
|
-
price: __1
|
|
13
|
-
createdAt: __1
|
|
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
|
|
18
|
-
name: __1
|
|
19
|
-
price: __1
|
|
17
|
+
args: __1.z.object({
|
|
18
|
+
name: __1.z.string().min(1),
|
|
19
|
+
price: __1.z.number().min(0)
|
|
20
20
|
}),
|
|
21
|
-
res: __1
|
|
22
|
-
id: __1
|
|
23
|
-
name: __1
|
|
24
|
-
price: __1
|
|
25
|
-
createdAt: __1
|
|
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 {
|
|
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:
|
|
14
|
-
export declare const create: (args:
|
|
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 {
|
|
1
|
+
import { z } from '../../..';
|
|
2
2
|
export declare const fetch: {
|
|
3
|
-
args:
|
|
4
|
-
id:
|
|
5
|
-
},
|
|
6
|
-
res:
|
|
7
|
-
id:
|
|
8
|
-
name:
|
|
9
|
-
email:
|
|
10
|
-
},
|
|
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:
|
|
14
|
-
name:
|
|
15
|
-
email:
|
|
16
|
-
},
|
|
17
|
-
res:
|
|
18
|
-
id:
|
|
19
|
-
name:
|
|
20
|
-
email:
|
|
21
|
-
createdAt:
|
|
22
|
-
},
|
|
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
|
|
7
|
-
id: __1
|
|
6
|
+
args: __1.z.object({
|
|
7
|
+
id: __1.z.number().min(1)
|
|
8
8
|
}),
|
|
9
|
-
res: __1
|
|
10
|
-
id: __1
|
|
11
|
-
name: __1
|
|
12
|
-
email: __1
|
|
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
|
|
17
|
-
name: __1
|
|
18
|
-
email: __1
|
|
16
|
+
args: __1.z.object({
|
|
17
|
+
name: __1.z.string().min(1),
|
|
18
|
+
email: __1.z.string().email()
|
|
19
19
|
}),
|
|
20
|
-
res: __1
|
|
21
|
-
id: __1
|
|
22
|
-
name: __1
|
|
23
|
-
email: __1
|
|
24
|
-
createdAt: __1
|
|
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
|
|
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
|
|
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, "
|
|
17
|
+
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
|
package/package.json
CHANGED
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
|
|
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 {
|
|
227
|
+
import { z } from 'typed-bridge'
|
|
228
228
|
|
|
229
229
|
export const fetch = {
|
|
230
|
-
args:
|
|
231
|
-
id:
|
|
230
|
+
args: z.object({
|
|
231
|
+
id: z.number().min(1)
|
|
232
232
|
}),
|
|
233
|
-
res:
|
|
234
|
-
id:
|
|
235
|
-
name:
|
|
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 {
|
|
243
|
+
import { z } from 'typed-bridge'
|
|
244
244
|
import * as types from './types'
|
|
245
245
|
|
|
246
246
|
export const fetch = async (
|
|
247
|
-
args:
|
|
247
|
+
args: z.infer<typeof types.fetch.args>,
|
|
248
248
|
context: { id: number }
|
|
249
|
-
): Promise
|
|
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
|
-
|
|
|
314
|
-
|
|
315
|
-
| **Setup**
|
|
316
|
-
| **Monorepo required?** | No, generated client is a standalone file
|
|
317
|
-
| **Frontend framework** | Any (React, Vue, Angular, RN, etc.)
|
|
318
|
-
| **Learning curve**
|
|
319
|
-
| **Runtime validation** | Zod (built-in)
|
|
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
|
-
|
|
|
324
|
-
|
|
325
|
-
| **Setup**
|
|
326
|
-
| **Type safety**
|
|
327
|
-
| **Overfetching**
|
|
328
|
-
| **Learning curve** | Minimal, plain TypeScript
|
|
329
|
-
| **Best for**
|
|
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
|
|
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
|
-
|