@alevnyacow/nzmt 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +177 -174
- package/dist/index.d.ts +2 -3
- package/dist/index.js +170 -164
- package/dist/store/index.d.ts +3 -3
- package/dist/store/store.ram.utils.d.ts +358 -70
- package/dist/store/store.shared-models.utils.d.ts +2 -14
- package/dist/store/store.zod.utils.d.ts +62 -50
- package/dist/zod-controller.utils.d.ts +1 -1
- package/dist/zod-module.utils.d.ts +6 -6
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PaginationModel } from './store.pagination.entity';
|
|
2
|
-
export type
|
|
2
|
+
export type CRUD<Models extends {
|
|
3
3
|
list: unknown;
|
|
4
4
|
detail: unknown;
|
|
5
5
|
}, SearchPayload extends {
|
|
@@ -33,18 +33,6 @@ export type CRUDStore<Models extends {
|
|
|
33
33
|
success: boolean;
|
|
34
34
|
}>;
|
|
35
35
|
};
|
|
36
|
-
export type Models<List, Detail> = {
|
|
37
|
-
list: List;
|
|
38
|
-
detail: Detail;
|
|
39
|
-
};
|
|
40
|
-
export type SearchPayload<List, Specific> = {
|
|
41
|
-
list: List;
|
|
42
|
-
specific: Specific;
|
|
43
|
-
};
|
|
44
|
-
export type ActionsPayload<Create, Update> = {
|
|
45
|
-
create: Create;
|
|
46
|
-
update: Update;
|
|
47
|
-
};
|
|
48
36
|
type ExtractCRUDParams<T> = T extends {
|
|
49
37
|
list: (data: {
|
|
50
38
|
filter: infer SList;
|
|
@@ -75,7 +63,7 @@ type ExtractCRUDParams<T> = T extends {
|
|
|
75
63
|
update: AUpdate;
|
|
76
64
|
};
|
|
77
65
|
} : never;
|
|
78
|
-
export type
|
|
66
|
+
export type Types<T> = {
|
|
79
67
|
listModel: ExtractCRUDParams<T>['Models']['list'];
|
|
80
68
|
details: ExtractCRUDParams<T>['Models']['detail'];
|
|
81
69
|
findOnePayload: ExtractCRUDParams<T>['SearchPayload']['specific'];
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import type { ZodArray, ZodBoolean, ZodObject, ZodString, ZodType, ZodUnion } from 'zod';
|
|
2
2
|
import z from 'zod';
|
|
3
3
|
import { Pagination } from './store.pagination.entity';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CRUD } from './store.shared-models.utils';
|
|
5
5
|
type ZodSchema = ZodType;
|
|
6
|
-
|
|
6
|
+
type Models<List, Detail> = {
|
|
7
|
+
list: List;
|
|
8
|
+
detail: Detail;
|
|
9
|
+
};
|
|
10
|
+
type SearchPayload<List, Specific> = {
|
|
11
|
+
list: List;
|
|
12
|
+
specific: Specific;
|
|
13
|
+
};
|
|
14
|
+
type ActionsPayload<Create, Update> = {
|
|
15
|
+
create: Create;
|
|
16
|
+
update: Update;
|
|
17
|
+
};
|
|
18
|
+
export type Metadata = {
|
|
7
19
|
name: string;
|
|
8
20
|
models: {
|
|
9
21
|
list: ZodSchema;
|
|
@@ -22,7 +34,7 @@ export type ZodStoreMetadata = {
|
|
|
22
34
|
response: ZodSchema;
|
|
23
35
|
}>;
|
|
24
36
|
};
|
|
25
|
-
export type
|
|
37
|
+
export type Contract<Schemas extends {
|
|
26
38
|
models: {
|
|
27
39
|
list: unknown;
|
|
28
40
|
details: unknown;
|
|
@@ -39,26 +51,26 @@ export type ZodStore<Schemas extends {
|
|
|
39
51
|
payload: unknown;
|
|
40
52
|
response: unknown;
|
|
41
53
|
}>;
|
|
42
|
-
}> =
|
|
54
|
+
}> = CRUD<Models<z.infer<Schemas['models']['list']>, z.infer<Schemas['models']['details']>>, SearchPayload<z.infer<Schemas['searchPayload']['list']>, z.infer<Schemas['searchPayload']['specific']>>, ActionsPayload<z.infer<Schemas['actionsPayload']['create']>, z.infer<Schemas['actionsPayload']['update']>>> & (Schemas['customOperations'] extends Record<string, {
|
|
43
55
|
payload: ZodSchema;
|
|
44
56
|
response: ZodSchema;
|
|
45
57
|
}> ? {
|
|
46
58
|
[operation in keyof Schemas['customOperations']]: (payload: z.infer<Schemas['customOperations'][operation]['payload']>) => Promise<z.infer<Schemas['customOperations'][operation]['response']>>;
|
|
47
59
|
} : {});
|
|
48
|
-
export declare const
|
|
60
|
+
export declare const methods: <T extends Metadata>(schemas: T) => <Method extends "details" | "list" | "create" | "updateOne" | "deleteOne" | Exclude<keyof (T["customOperations"] extends Record<string, {
|
|
49
61
|
payload: ZodSchema;
|
|
50
62
|
response: ZodSchema;
|
|
51
63
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
52
64
|
payload: T["customOperations"][operation]["payload"];
|
|
53
65
|
response: T["customOperations"][operation]["response"];
|
|
54
|
-
}; } : {}), keyof
|
|
66
|
+
}; } : {}), keyof CRUD<any, any, any>>>(methodName: Method, handler: (payload: z.core.output<(Record<Exclude<keyof (T["customOperations"] extends Record<string, {
|
|
55
67
|
payload: ZodSchema;
|
|
56
68
|
response: ZodSchema;
|
|
57
69
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
58
70
|
payload: T["customOperations"][operation]["payload"];
|
|
59
71
|
response: T["customOperations"][operation]["response"];
|
|
60
|
-
}; } : {}), keyof
|
|
61
|
-
payload: (
|
|
72
|
+
}; } : {}), keyof CRUD<any, any, any>>, {
|
|
73
|
+
payload: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
62
74
|
payload: ZodSchema;
|
|
63
75
|
response: ZodSchema;
|
|
64
76
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -70,8 +82,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
70
82
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
71
83
|
payload: T["customOperations"][operation]["payload"];
|
|
72
84
|
response: T["customOperations"][operation]["response"];
|
|
73
|
-
}; } : {}), keyof
|
|
74
|
-
response: (
|
|
85
|
+
}; } : {}), keyof CRUD<any, any, any>>]["payload"];
|
|
86
|
+
response: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
75
87
|
payload: ZodSchema;
|
|
76
88
|
response: ZodSchema;
|
|
77
89
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -83,10 +95,10 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
83
95
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
84
96
|
payload: T["customOperations"][operation]["payload"];
|
|
85
97
|
response: T["customOperations"][operation]["response"];
|
|
86
|
-
}; } : {}), keyof
|
|
98
|
+
}; } : {}), keyof CRUD<any, any, any>>]["response"];
|
|
87
99
|
}> & {
|
|
88
100
|
list: {
|
|
89
|
-
payload: ZodObject<Parameters<(
|
|
101
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
90
102
|
payload: ZodSchema;
|
|
91
103
|
response: ZodSchema;
|
|
92
104
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -95,7 +107,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
95
107
|
}; } : {}))["list"]>[0] & {
|
|
96
108
|
pagination: ReturnType<typeof Pagination.schema.optional>;
|
|
97
109
|
}, z.core.$strip>;
|
|
98
|
-
response: ZodArray<Awaited<ReturnType<(
|
|
110
|
+
response: ZodArray<Awaited<ReturnType<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
99
111
|
payload: ZodSchema;
|
|
100
112
|
response: ZodSchema;
|
|
101
113
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -104,7 +116,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
104
116
|
}; } : {}))["list"]>>[number]>;
|
|
105
117
|
};
|
|
106
118
|
details: {
|
|
107
|
-
payload: ZodObject<Parameters<(
|
|
119
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
108
120
|
payload: ZodSchema;
|
|
109
121
|
response: ZodSchema;
|
|
110
122
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -114,7 +126,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
114
126
|
response: ZodUnion<[T["models"]["details"], z.ZodNull]>;
|
|
115
127
|
};
|
|
116
128
|
create: {
|
|
117
|
-
payload: ZodObject<Parameters<(
|
|
129
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
118
130
|
payload: ZodSchema;
|
|
119
131
|
response: ZodSchema;
|
|
120
132
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -126,7 +138,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
126
138
|
}, z.core.$strip>;
|
|
127
139
|
};
|
|
128
140
|
updateOne: {
|
|
129
|
-
payload: ZodObject<Parameters<(
|
|
141
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
130
142
|
payload: ZodSchema;
|
|
131
143
|
response: ZodSchema;
|
|
132
144
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -138,7 +150,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
138
150
|
}, z.core.$strip>;
|
|
139
151
|
};
|
|
140
152
|
deleteOne: {
|
|
141
|
-
payload: ZodObject<Parameters<(
|
|
153
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
142
154
|
payload: ZodSchema;
|
|
143
155
|
response: ZodSchema;
|
|
144
156
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -157,8 +169,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
157
169
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
158
170
|
payload: T["customOperations"][operation]["payload"];
|
|
159
171
|
response: T["customOperations"][operation]["response"];
|
|
160
|
-
}; } : {}), keyof
|
|
161
|
-
payload: (
|
|
172
|
+
}; } : {}), keyof CRUD<any, any, any>>, {
|
|
173
|
+
payload: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
162
174
|
payload: ZodSchema;
|
|
163
175
|
response: ZodSchema;
|
|
164
176
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -170,8 +182,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
170
182
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
171
183
|
payload: T["customOperations"][operation]["payload"];
|
|
172
184
|
response: T["customOperations"][operation]["response"];
|
|
173
|
-
}; } : {}), keyof
|
|
174
|
-
response: (
|
|
185
|
+
}; } : {}), keyof CRUD<any, any, any>>]["payload"];
|
|
186
|
+
response: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
175
187
|
payload: ZodSchema;
|
|
176
188
|
response: ZodSchema;
|
|
177
189
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -183,10 +195,10 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
183
195
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
184
196
|
payload: T["customOperations"][operation]["payload"];
|
|
185
197
|
response: T["customOperations"][operation]["response"];
|
|
186
|
-
}; } : {}), keyof
|
|
198
|
+
}; } : {}), keyof CRUD<any, any, any>>]["response"];
|
|
187
199
|
}> & {
|
|
188
200
|
list: {
|
|
189
|
-
payload: ZodObject<Parameters<(
|
|
201
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
190
202
|
payload: ZodSchema;
|
|
191
203
|
response: ZodSchema;
|
|
192
204
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -195,7 +207,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
195
207
|
}; } : {}))["list"]>[0] & {
|
|
196
208
|
pagination: ReturnType<typeof Pagination.schema.optional>;
|
|
197
209
|
}, z.core.$strip>;
|
|
198
|
-
response: ZodArray<Awaited<ReturnType<(
|
|
210
|
+
response: ZodArray<Awaited<ReturnType<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
199
211
|
payload: ZodSchema;
|
|
200
212
|
response: ZodSchema;
|
|
201
213
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -204,7 +216,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
204
216
|
}; } : {}))["list"]>>[number]>;
|
|
205
217
|
};
|
|
206
218
|
details: {
|
|
207
|
-
payload: ZodObject<Parameters<(
|
|
219
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
208
220
|
payload: ZodSchema;
|
|
209
221
|
response: ZodSchema;
|
|
210
222
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -214,7 +226,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
214
226
|
response: ZodUnion<[T["models"]["details"], z.ZodNull]>;
|
|
215
227
|
};
|
|
216
228
|
create: {
|
|
217
|
-
payload: ZodObject<Parameters<(
|
|
229
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
218
230
|
payload: ZodSchema;
|
|
219
231
|
response: ZodSchema;
|
|
220
232
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -226,7 +238,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
226
238
|
}, z.core.$strip>;
|
|
227
239
|
};
|
|
228
240
|
updateOne: {
|
|
229
|
-
payload: ZodObject<Parameters<(
|
|
241
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
230
242
|
payload: ZodSchema;
|
|
231
243
|
response: ZodSchema;
|
|
232
244
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -238,7 +250,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
238
250
|
}, z.core.$strip>;
|
|
239
251
|
};
|
|
240
252
|
deleteOne: {
|
|
241
|
-
payload: ZodObject<Parameters<(
|
|
253
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
242
254
|
payload: ZodSchema;
|
|
243
255
|
response: ZodSchema;
|
|
244
256
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -255,8 +267,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
255
267
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
256
268
|
payload: T["customOperations"][operation]["payload"];
|
|
257
269
|
response: T["customOperations"][operation]["response"];
|
|
258
|
-
}; } : {}), keyof
|
|
259
|
-
payload: (
|
|
270
|
+
}; } : {}), keyof CRUD<any, any, any>>, {
|
|
271
|
+
payload: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
260
272
|
payload: ZodSchema;
|
|
261
273
|
response: ZodSchema;
|
|
262
274
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -268,8 +280,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
268
280
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
269
281
|
payload: T["customOperations"][operation]["payload"];
|
|
270
282
|
response: T["customOperations"][operation]["response"];
|
|
271
|
-
}; } : {}), keyof
|
|
272
|
-
response: (
|
|
283
|
+
}; } : {}), keyof CRUD<any, any, any>>]["payload"];
|
|
284
|
+
response: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
273
285
|
payload: ZodSchema;
|
|
274
286
|
response: ZodSchema;
|
|
275
287
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -281,10 +293,10 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
281
293
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
282
294
|
payload: T["customOperations"][operation]["payload"];
|
|
283
295
|
response: T["customOperations"][operation]["response"];
|
|
284
|
-
}; } : {}), keyof
|
|
296
|
+
}; } : {}), keyof CRUD<any, any, any>>]["response"];
|
|
285
297
|
}> & {
|
|
286
298
|
list: {
|
|
287
|
-
payload: ZodObject<Parameters<(
|
|
299
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
288
300
|
payload: ZodSchema;
|
|
289
301
|
response: ZodSchema;
|
|
290
302
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -293,7 +305,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
293
305
|
}; } : {}))["list"]>[0] & {
|
|
294
306
|
pagination: ReturnType<typeof Pagination.schema.optional>;
|
|
295
307
|
}, z.core.$strip>;
|
|
296
|
-
response: ZodArray<Awaited<ReturnType<(
|
|
308
|
+
response: ZodArray<Awaited<ReturnType<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
297
309
|
payload: ZodSchema;
|
|
298
310
|
response: ZodSchema;
|
|
299
311
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -302,7 +314,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
302
314
|
}; } : {}))["list"]>>[number]>;
|
|
303
315
|
};
|
|
304
316
|
details: {
|
|
305
|
-
payload: ZodObject<Parameters<(
|
|
317
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
306
318
|
payload: ZodSchema;
|
|
307
319
|
response: ZodSchema;
|
|
308
320
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -312,7 +324,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
312
324
|
response: ZodUnion<[T["models"]["details"], z.ZodNull]>;
|
|
313
325
|
};
|
|
314
326
|
create: {
|
|
315
|
-
payload: ZodObject<Parameters<(
|
|
327
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
316
328
|
payload: ZodSchema;
|
|
317
329
|
response: ZodSchema;
|
|
318
330
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -324,7 +336,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
324
336
|
}, z.core.$strip>;
|
|
325
337
|
};
|
|
326
338
|
updateOne: {
|
|
327
|
-
payload: ZodObject<Parameters<(
|
|
339
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
328
340
|
payload: ZodSchema;
|
|
329
341
|
response: ZodSchema;
|
|
330
342
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -336,7 +348,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
336
348
|
}, z.core.$strip>;
|
|
337
349
|
};
|
|
338
350
|
deleteOne: {
|
|
339
|
-
payload: ZodObject<Parameters<(
|
|
351
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
340
352
|
payload: ZodSchema;
|
|
341
353
|
response: ZodSchema;
|
|
342
354
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -353,8 +365,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
353
365
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
354
366
|
payload: T["customOperations"][operation]["payload"];
|
|
355
367
|
response: T["customOperations"][operation]["response"];
|
|
356
|
-
}; } : {}), keyof
|
|
357
|
-
payload: (
|
|
368
|
+
}; } : {}), keyof CRUD<any, any, any>>, {
|
|
369
|
+
payload: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
358
370
|
payload: ZodSchema;
|
|
359
371
|
response: ZodSchema;
|
|
360
372
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -366,8 +378,8 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
366
378
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
367
379
|
payload: T["customOperations"][operation]["payload"];
|
|
368
380
|
response: T["customOperations"][operation]["response"];
|
|
369
|
-
}; } : {}), keyof
|
|
370
|
-
response: (
|
|
381
|
+
}; } : {}), keyof CRUD<any, any, any>>]["payload"];
|
|
382
|
+
response: (CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
371
383
|
payload: ZodSchema;
|
|
372
384
|
response: ZodSchema;
|
|
373
385
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -379,10 +391,10 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
379
391
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
380
392
|
payload: T["customOperations"][operation]["payload"];
|
|
381
393
|
response: T["customOperations"][operation]["response"];
|
|
382
|
-
}; } : {}), keyof
|
|
394
|
+
}; } : {}), keyof CRUD<any, any, any>>]["response"];
|
|
383
395
|
}> & {
|
|
384
396
|
list: {
|
|
385
|
-
payload: ZodObject<Parameters<(
|
|
397
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
386
398
|
payload: ZodSchema;
|
|
387
399
|
response: ZodSchema;
|
|
388
400
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -391,7 +403,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
391
403
|
}; } : {}))["list"]>[0] & {
|
|
392
404
|
pagination: ReturnType<typeof Pagination.schema.optional>;
|
|
393
405
|
}, z.core.$strip>;
|
|
394
|
-
response: ZodArray<Awaited<ReturnType<(
|
|
406
|
+
response: ZodArray<Awaited<ReturnType<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
395
407
|
payload: ZodSchema;
|
|
396
408
|
response: ZodSchema;
|
|
397
409
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -400,7 +412,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
400
412
|
}; } : {}))["list"]>>[number]>;
|
|
401
413
|
};
|
|
402
414
|
details: {
|
|
403
|
-
payload: ZodObject<Parameters<(
|
|
415
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
404
416
|
payload: ZodSchema;
|
|
405
417
|
response: ZodSchema;
|
|
406
418
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -410,7 +422,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
410
422
|
response: ZodUnion<[T["models"]["details"], z.ZodNull]>;
|
|
411
423
|
};
|
|
412
424
|
create: {
|
|
413
|
-
payload: ZodObject<Parameters<(
|
|
425
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
414
426
|
payload: ZodSchema;
|
|
415
427
|
response: ZodSchema;
|
|
416
428
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -422,7 +434,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
422
434
|
}, z.core.$strip>;
|
|
423
435
|
};
|
|
424
436
|
updateOne: {
|
|
425
|
-
payload: ZodObject<Parameters<(
|
|
437
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
426
438
|
payload: ZodSchema;
|
|
427
439
|
response: ZodSchema;
|
|
428
440
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -434,7 +446,7 @@ export declare const zodStoreMethodFactory: <T extends ZodStoreMetadata>(schemas
|
|
|
434
446
|
}, z.core.$strip>;
|
|
435
447
|
};
|
|
436
448
|
deleteOne: {
|
|
437
|
-
payload: ZodObject<Parameters<(
|
|
449
|
+
payload: ZodObject<Parameters<(CRUD<Models<T["models"]["list"], T["models"]["details"]>, SearchPayload<T["searchPayload"]["list"], T["searchPayload"]["specific"]>, ActionsPayload<T["actionsPayload"]["create"], T["actionsPayload"]["update"]>> & (T["customOperations"] extends Record<string, {
|
|
438
450
|
payload: ZodSchema;
|
|
439
451
|
response: ZodSchema;
|
|
440
452
|
}> ? { [operation in keyof T["customOperations"]]: {
|
|
@@ -105,7 +105,7 @@ type ZodAPIMethod<Schemas extends {
|
|
|
105
105
|
response: SuccessResponse<Schemas['response']>;
|
|
106
106
|
error: ErrorResponse;
|
|
107
107
|
};
|
|
108
|
-
export type
|
|
108
|
+
export type Contract<Metadata extends {
|
|
109
109
|
schemas: Record<string, SchemaShape>;
|
|
110
110
|
}, CustomModels extends Record<string, unknown> | undefined = undefined> = {
|
|
111
111
|
endpoints: {
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
2
|
import type { ZodType } from 'zod';
|
|
3
3
|
import { type ErrorBaseCreatingPayload, type ModuleErrorModel } from './errors.utils';
|
|
4
|
-
type
|
|
4
|
+
type Schemas = Record<string, {
|
|
5
5
|
payload: ZodType;
|
|
6
6
|
response: ZodType;
|
|
7
7
|
}>;
|
|
8
|
-
export type
|
|
8
|
+
export type Metadata = {
|
|
9
9
|
name: string;
|
|
10
|
-
schemas:
|
|
10
|
+
schemas: Schemas;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type DTOs<T extends Metadata> = {
|
|
13
13
|
[K in keyof T['schemas'] as `${Extract<K, string>}Payload`]: z.infer<T['schemas'][K]['payload']>;
|
|
14
14
|
} & {
|
|
15
15
|
[K in keyof T['schemas'] as `${Extract<K, string>}Response`]: z.infer<T['schemas'][K]['response']>;
|
|
16
16
|
};
|
|
17
|
-
export type
|
|
17
|
+
export type Methods<T extends Metadata> = {
|
|
18
18
|
[K in keyof T['schemas']]: (payload: z.infer<T['schemas'][K]['payload']>) => Promise<z.infer<T['schemas'][K]['response']>>;
|
|
19
19
|
};
|
|
20
20
|
export type ZodModuleConfig = {
|
|
21
21
|
onError?: (e: ModuleErrorModel) => Promise<void>;
|
|
22
22
|
};
|
|
23
|
-
export declare const zodModuleMethodFactory: <T extends
|
|
23
|
+
export declare const zodModuleMethodFactory: <T extends Schemas>(metadata: {
|
|
24
24
|
schemas: T;
|
|
25
25
|
name: string;
|
|
26
26
|
}, sharedConfig?: ZodModuleConfig) => <Method extends keyof T>(methodName: Method, handler: (payload: z.infer<T[Method]["payload"]>, config: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alevnyacow/nzmt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Next Zod Modules Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "^5.9.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"next": "
|
|
36
|
+
"next": ">=13 <17"
|
|
37
37
|
},
|
|
38
38
|
"private": false,
|
|
39
39
|
"dependencies": {
|