@alevnyacow/nzmt 0.0.6 → 0.0.8
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 +176 -174
- package/dist/index.d.ts +2 -3
- package/dist/index.js +169 -164
- package/dist/store/index.d.ts +3 -3
- package/dist/store/store.ram.utils.d.ts +356 -68
- 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 +1 -2
package/dist/index.cjs
CHANGED
|
@@ -33,10 +33,9 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
|
|
37
|
-
zodStoreMethodFactory: ()=>zodStoreMethodFactory,
|
|
36
|
+
Store: ()=>store_namespaceObject,
|
|
38
37
|
zodModuleMethodFactory: ()=>zodModuleMethodFactory,
|
|
39
|
-
|
|
38
|
+
API: ()=>zod_controller_utils_namespaceObject
|
|
40
39
|
});
|
|
41
40
|
var zod_controller_utils_namespaceObject = {};
|
|
42
41
|
__webpack_require__.r(zod_controller_utils_namespaceObject);
|
|
@@ -44,40 +43,12 @@ __webpack_require__.d(zod_controller_utils_namespaceObject, {
|
|
|
44
43
|
DefaultErrorCodes: ()=>zod_controller_utils_DefaultErrorCodes,
|
|
45
44
|
endpoints: ()=>endpoints
|
|
46
45
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
zeroBasedIndex: external_zod_default().coerce.number().int().nonnegative(),
|
|
54
|
-
pageSize: external_zod_default().coerce.number().int().positive()
|
|
55
|
-
});
|
|
56
|
-
constructor(data){
|
|
57
|
-
this.data = data;
|
|
58
|
-
}
|
|
59
|
-
static create = (data)=>{
|
|
60
|
-
const parsedModel = Pagination.schema.parse(data);
|
|
61
|
-
return new Pagination(parsedModel);
|
|
62
|
-
};
|
|
63
|
-
get model() {
|
|
64
|
-
return this.data;
|
|
65
|
-
}
|
|
66
|
-
same = (pagination)=>pagination.model.pageSize === this.model.pageSize && pagination.model.zeroBasedIndex === this.model.zeroBasedIndex;
|
|
67
|
-
get nextPage() {
|
|
68
|
-
return Pagination.create({
|
|
69
|
-
pageSize: this.data.pageSize,
|
|
70
|
-
zeroBasedIndex: this.data.zeroBasedIndex + 1
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
get previousPage() {
|
|
74
|
-
if (0 === this.model.zeroBasedIndex) return Pagination.create(this.model);
|
|
75
|
-
return Pagination.create({
|
|
76
|
-
pageSize: this.model.pageSize,
|
|
77
|
-
zeroBasedIndex: this.model.zeroBasedIndex - 1
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
46
|
+
var store_namespaceObject = {};
|
|
47
|
+
__webpack_require__.r(store_namespaceObject);
|
|
48
|
+
__webpack_require__.d(store_namespaceObject, {
|
|
49
|
+
InRAM: ()=>InRAM,
|
|
50
|
+
methods: ()=>methods
|
|
51
|
+
});
|
|
81
52
|
class ErrorFactory {
|
|
82
53
|
static isControllerError = (error)=>{
|
|
83
54
|
if (!error || 'object' != typeof error) return false;
|
|
@@ -200,137 +171,9 @@ const zodModuleMethodFactory = (metadata, sharedConfig = {})=>(methodName, handl
|
|
|
200
171
|
}
|
|
201
172
|
};
|
|
202
173
|
};
|
|
203
|
-
const mapStoreSchemasToModuleMetadata = (schemas, name)=>({
|
|
204
|
-
name,
|
|
205
|
-
schemas: {
|
|
206
|
-
...schemas.customOperations ?? {},
|
|
207
|
-
list: {
|
|
208
|
-
payload: external_zod_default().object({
|
|
209
|
-
filter: schemas.searchPayload.list,
|
|
210
|
-
pagination: Pagination.schema.optional()
|
|
211
|
-
}),
|
|
212
|
-
response: external_zod_default().array(schemas.models.list)
|
|
213
|
-
},
|
|
214
|
-
details: {
|
|
215
|
-
payload: external_zod_default().object({
|
|
216
|
-
filter: schemas.searchPayload.specific
|
|
217
|
-
}),
|
|
218
|
-
response: schemas.models.details.nullable()
|
|
219
|
-
},
|
|
220
|
-
create: {
|
|
221
|
-
payload: external_zod_default().object({
|
|
222
|
-
payload: schemas.actionsPayload.create
|
|
223
|
-
}),
|
|
224
|
-
response: external_zod_default().object({
|
|
225
|
-
id: external_zod_default().string()
|
|
226
|
-
})
|
|
227
|
-
},
|
|
228
|
-
updateOne: {
|
|
229
|
-
payload: external_zod_default().object({
|
|
230
|
-
filter: schemas.searchPayload.specific,
|
|
231
|
-
payload: schemas.actionsPayload.update
|
|
232
|
-
}),
|
|
233
|
-
response: external_zod_default().object({
|
|
234
|
-
success: external_zod_default().boolean()
|
|
235
|
-
})
|
|
236
|
-
},
|
|
237
|
-
deleteOne: {
|
|
238
|
-
payload: external_zod_default().object({
|
|
239
|
-
filter: schemas.searchPayload.specific
|
|
240
|
-
}),
|
|
241
|
-
response: external_zod_default().object({
|
|
242
|
-
success: external_zod_default().boolean()
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
const zodStoreMethodFactory = (schemas)=>{
|
|
248
|
-
const data = mapStoreSchemasToModuleMetadata(schemas, schemas.name);
|
|
249
|
-
return zodModuleMethodFactory(data);
|
|
250
|
-
};
|
|
251
|
-
const store_ram_utils_RAMStore = (schemas, options)=>{
|
|
252
|
-
class RAMStore {
|
|
253
|
-
___data = [];
|
|
254
|
-
method = zodStoreMethodFactory(schemas);
|
|
255
|
-
___listSearchLogic = (entity, pattern)=>{
|
|
256
|
-
const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
|
|
257
|
-
const entityAsObject = entity;
|
|
258
|
-
return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
|
|
259
|
-
};
|
|
260
|
-
___specificSearchLogic = (entity, pattern)=>{
|
|
261
|
-
const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
|
|
262
|
-
const entityAsObject = entity;
|
|
263
|
-
return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
|
|
264
|
-
};
|
|
265
|
-
___mapDetailToList = (entity)=>entity;
|
|
266
|
-
___mapCreatePayloadToDetail = (payload)=>({
|
|
267
|
-
...payload,
|
|
268
|
-
id: (0, external_uuid_namespaceObject.v4)()
|
|
269
|
-
});
|
|
270
|
-
___mapUpdatePayloadToDetail = (prevValue, update)=>({
|
|
271
|
-
...prevValue,
|
|
272
|
-
...update
|
|
273
|
-
});
|
|
274
|
-
constructor(){
|
|
275
|
-
if (!options) return;
|
|
276
|
-
if (options.searchLogic) {
|
|
277
|
-
if (options.searchLogic.list) this.___listSearchLogic = options.searchLogic.list;
|
|
278
|
-
if (options.searchLogic.specific) this.___specificSearchLogic = options.searchLogic.specific;
|
|
279
|
-
}
|
|
280
|
-
if (options.mappers) {
|
|
281
|
-
if (options.mappers.detailToList) this.___mapDetailToList = options.mappers.detailToList;
|
|
282
|
-
if (options.mappers.createPayloadToDetail) this.___mapCreatePayloadToDetail = options.mappers.createPayloadToDetail;
|
|
283
|
-
if (options.mappers.updatePayloadToDetail) this.___mapUpdatePayloadToDetail = options.mappers.updatePayloadToDetail;
|
|
284
|
-
}
|
|
285
|
-
if (options.initialData) this.___data = [
|
|
286
|
-
...options.initialData
|
|
287
|
-
];
|
|
288
|
-
}
|
|
289
|
-
list = this.method('list', async ({ filter, pagination = {
|
|
290
|
-
pageSize: 1000,
|
|
291
|
-
zeroBasedIndex: 0
|
|
292
|
-
} })=>{
|
|
293
|
-
schemas.searchPayload.list.parse(filter);
|
|
294
|
-
Pagination.schema.parse(pagination);
|
|
295
|
-
const afterFiltration = this.___data.filter((x)=>this.___listSearchLogic(x, filter));
|
|
296
|
-
const afterPagination = afterFiltration.filter((_, i)=>i >= pagination.pageSize * pagination.zeroBasedIndex && i < (pagination.zeroBasedIndex + 1) * pagination.pageSize);
|
|
297
|
-
const result = afterPagination.map((x)=>this.___mapDetailToList(x));
|
|
298
|
-
external_zod_default().array(schemas.models.list).parse(result);
|
|
299
|
-
return result;
|
|
300
|
-
});
|
|
301
|
-
details = this.method('details', async ({ filter })=>{
|
|
302
|
-
const details = this.___data.find((x)=>this.___specificSearchLogic(x, filter));
|
|
303
|
-
if (!details) return null;
|
|
304
|
-
return details;
|
|
305
|
-
});
|
|
306
|
-
create = this.method('create', async ({ payload })=>{
|
|
307
|
-
const newItem = this.___mapCreatePayloadToDetail(payload);
|
|
308
|
-
this.___data = this.___data.concat(newItem);
|
|
309
|
-
return {
|
|
310
|
-
id: newItem.id
|
|
311
|
-
};
|
|
312
|
-
});
|
|
313
|
-
updateOne = this.method('updateOne', async ({ filter, payload })=>{
|
|
314
|
-
const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
|
|
315
|
-
this.___data = this.___data.map((x, i)=>{
|
|
316
|
-
if (i !== index) return x;
|
|
317
|
-
return this.___mapUpdatePayloadToDetail(x, payload);
|
|
318
|
-
});
|
|
319
|
-
return {
|
|
320
|
-
success: index > -1
|
|
321
|
-
};
|
|
322
|
-
});
|
|
323
|
-
deleteOne = this.method('deleteOne', async ({ filter })=>{
|
|
324
|
-
const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
|
|
325
|
-
this.___data = this.___data.filter((_x, i)=>i !== index);
|
|
326
|
-
return {
|
|
327
|
-
success: index > -1
|
|
328
|
-
};
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
return RAMStore;
|
|
332
|
-
};
|
|
333
174
|
const server_namespaceObject = require("next/server");
|
|
175
|
+
const external_zod_namespaceObject = require("zod");
|
|
176
|
+
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
334
177
|
var zod_controller_utils_DefaultErrorCodes = /*#__PURE__*/ function(DefaultErrorCodes) {
|
|
335
178
|
DefaultErrorCodes["REQUEST_PARSING"] = "ZOD-CONTROLLER___REQUEST-PARSING";
|
|
336
179
|
DefaultErrorCodes["RESPONSE_PARSING"] = "ZOD-CONTROLLER___RESPONSE-PARSING";
|
|
@@ -496,15 +339,174 @@ const endpoints = (metadata, sharedConfig = {})=>{
|
|
|
496
339
|
};
|
|
497
340
|
return endpointLogic;
|
|
498
341
|
};
|
|
499
|
-
|
|
500
|
-
|
|
342
|
+
class Pagination {
|
|
343
|
+
data;
|
|
344
|
+
static schema = external_zod_default().object({
|
|
345
|
+
zeroBasedIndex: external_zod_default().coerce.number().int().nonnegative(),
|
|
346
|
+
pageSize: external_zod_default().coerce.number().int().positive()
|
|
347
|
+
});
|
|
348
|
+
constructor(data){
|
|
349
|
+
this.data = data;
|
|
350
|
+
}
|
|
351
|
+
static create = (data)=>{
|
|
352
|
+
const parsedModel = Pagination.schema.parse(data);
|
|
353
|
+
return new Pagination(parsedModel);
|
|
354
|
+
};
|
|
355
|
+
get model() {
|
|
356
|
+
return this.data;
|
|
357
|
+
}
|
|
358
|
+
same = (pagination)=>pagination.model.pageSize === this.model.pageSize && pagination.model.zeroBasedIndex === this.model.zeroBasedIndex;
|
|
359
|
+
get nextPage() {
|
|
360
|
+
return Pagination.create({
|
|
361
|
+
pageSize: this.data.pageSize,
|
|
362
|
+
zeroBasedIndex: this.data.zeroBasedIndex + 1
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
get previousPage() {
|
|
366
|
+
if (0 === this.model.zeroBasedIndex) return Pagination.create(this.model);
|
|
367
|
+
return Pagination.create({
|
|
368
|
+
pageSize: this.model.pageSize,
|
|
369
|
+
zeroBasedIndex: this.model.zeroBasedIndex - 1
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const mapStoreSchemasToModuleMetadata = (schemas, name)=>({
|
|
374
|
+
name,
|
|
375
|
+
schemas: {
|
|
376
|
+
...schemas.customOperations ?? {},
|
|
377
|
+
list: {
|
|
378
|
+
payload: external_zod_default().object({
|
|
379
|
+
filter: schemas.searchPayload.list,
|
|
380
|
+
pagination: Pagination.schema.optional()
|
|
381
|
+
}),
|
|
382
|
+
response: external_zod_default().array(schemas.models.list)
|
|
383
|
+
},
|
|
384
|
+
details: {
|
|
385
|
+
payload: external_zod_default().object({
|
|
386
|
+
filter: schemas.searchPayload.specific
|
|
387
|
+
}),
|
|
388
|
+
response: schemas.models.details.nullable()
|
|
389
|
+
},
|
|
390
|
+
create: {
|
|
391
|
+
payload: external_zod_default().object({
|
|
392
|
+
payload: schemas.actionsPayload.create
|
|
393
|
+
}),
|
|
394
|
+
response: external_zod_default().object({
|
|
395
|
+
id: external_zod_default().string()
|
|
396
|
+
})
|
|
397
|
+
},
|
|
398
|
+
updateOne: {
|
|
399
|
+
payload: external_zod_default().object({
|
|
400
|
+
filter: schemas.searchPayload.specific,
|
|
401
|
+
payload: schemas.actionsPayload.update
|
|
402
|
+
}),
|
|
403
|
+
response: external_zod_default().object({
|
|
404
|
+
success: external_zod_default().boolean()
|
|
405
|
+
})
|
|
406
|
+
},
|
|
407
|
+
deleteOne: {
|
|
408
|
+
payload: external_zod_default().object({
|
|
409
|
+
filter: schemas.searchPayload.specific
|
|
410
|
+
}),
|
|
411
|
+
response: external_zod_default().object({
|
|
412
|
+
success: external_zod_default().boolean()
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
const methods = (schemas)=>{
|
|
418
|
+
const data = mapStoreSchemasToModuleMetadata(schemas, schemas.name);
|
|
419
|
+
return zodModuleMethodFactory(data);
|
|
420
|
+
};
|
|
421
|
+
const InRAM = (schemas, options)=>{
|
|
422
|
+
class RAMStore {
|
|
423
|
+
___data = [];
|
|
424
|
+
method = methods(schemas);
|
|
425
|
+
___listSearchLogic = (entity, pattern)=>{
|
|
426
|
+
const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
|
|
427
|
+
const entityAsObject = entity;
|
|
428
|
+
return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
|
|
429
|
+
};
|
|
430
|
+
___specificSearchLogic = (entity, pattern)=>{
|
|
431
|
+
const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
|
|
432
|
+
const entityAsObject = entity;
|
|
433
|
+
return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
|
|
434
|
+
};
|
|
435
|
+
___mapDetailToList = (entity)=>entity;
|
|
436
|
+
___mapCreatePayloadToDetail = (payload)=>({
|
|
437
|
+
...payload,
|
|
438
|
+
id: Math.random().toString()
|
|
439
|
+
});
|
|
440
|
+
___mapUpdatePayloadToDetail = (prevValue, update)=>({
|
|
441
|
+
...prevValue,
|
|
442
|
+
...update
|
|
443
|
+
});
|
|
444
|
+
constructor(){
|
|
445
|
+
if (!options) return;
|
|
446
|
+
if (options.searchLogic) {
|
|
447
|
+
if (options.searchLogic.list) this.___listSearchLogic = options.searchLogic.list;
|
|
448
|
+
if (options.searchLogic.specific) this.___specificSearchLogic = options.searchLogic.specific;
|
|
449
|
+
}
|
|
450
|
+
if (options.mappers) {
|
|
451
|
+
if (options.mappers.detailToList) this.___mapDetailToList = options.mappers.detailToList;
|
|
452
|
+
if (options.mappers.createPayloadToDetail) this.___mapCreatePayloadToDetail = options.mappers.createPayloadToDetail;
|
|
453
|
+
if (options.mappers.updatePayloadToDetail) this.___mapUpdatePayloadToDetail = options.mappers.updatePayloadToDetail;
|
|
454
|
+
}
|
|
455
|
+
if (options.initialData) this.___data = [
|
|
456
|
+
...options.initialData
|
|
457
|
+
];
|
|
458
|
+
}
|
|
459
|
+
list = this.method('list', async ({ filter, pagination = {
|
|
460
|
+
pageSize: 1000,
|
|
461
|
+
zeroBasedIndex: 0
|
|
462
|
+
} })=>{
|
|
463
|
+
schemas.searchPayload.list.parse(filter);
|
|
464
|
+
Pagination.schema.parse(pagination);
|
|
465
|
+
const afterFiltration = this.___data.filter((x)=>this.___listSearchLogic(x, filter));
|
|
466
|
+
const afterPagination = afterFiltration.filter((_, i)=>i >= pagination.pageSize * pagination.zeroBasedIndex && i < (pagination.zeroBasedIndex + 1) * pagination.pageSize);
|
|
467
|
+
const result = afterPagination.map((x)=>this.___mapDetailToList(x));
|
|
468
|
+
external_zod_default().array(schemas.models.list).parse(result);
|
|
469
|
+
return result;
|
|
470
|
+
});
|
|
471
|
+
details = this.method('details', async ({ filter })=>{
|
|
472
|
+
const details = this.___data.find((x)=>this.___specificSearchLogic(x, filter));
|
|
473
|
+
if (!details) return null;
|
|
474
|
+
return details;
|
|
475
|
+
});
|
|
476
|
+
create = this.method('create', async ({ payload })=>{
|
|
477
|
+
const newItem = this.___mapCreatePayloadToDetail(payload);
|
|
478
|
+
this.___data = this.___data.concat(newItem);
|
|
479
|
+
return {
|
|
480
|
+
id: newItem.id
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
updateOne = this.method('updateOne', async ({ filter, payload })=>{
|
|
484
|
+
const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
|
|
485
|
+
this.___data = this.___data.map((x, i)=>{
|
|
486
|
+
if (i !== index) return x;
|
|
487
|
+
return this.___mapUpdatePayloadToDetail(x, payload);
|
|
488
|
+
});
|
|
489
|
+
return {
|
|
490
|
+
success: index > -1
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
deleteOne = this.method('deleteOne', async ({ filter })=>{
|
|
494
|
+
const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
|
|
495
|
+
this.___data = this.___data.filter((_x, i)=>i !== index);
|
|
496
|
+
return {
|
|
497
|
+
success: index > -1
|
|
498
|
+
};
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
return RAMStore;
|
|
502
|
+
};
|
|
503
|
+
exports.API = __webpack_exports__.API;
|
|
504
|
+
exports.Store = __webpack_exports__.Store;
|
|
501
505
|
exports.zodModuleMethodFactory = __webpack_exports__.zodModuleMethodFactory;
|
|
502
|
-
exports.zodStoreMethodFactory = __webpack_exports__.zodStoreMethodFactory;
|
|
503
506
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
504
|
-
"
|
|
505
|
-
"
|
|
506
|
-
"zodModuleMethodFactory"
|
|
507
|
-
"zodStoreMethodFactory"
|
|
507
|
+
"API",
|
|
508
|
+
"Store",
|
|
509
|
+
"zodModuleMethodFactory"
|
|
508
510
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
509
511
|
Object.defineProperty(exports, '__esModule', {
|
|
510
512
|
value: true
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { RAMStore } from './store/store.ram.utils';
|
|
2
|
-
export { zodStoreMethodFactory, type ZodStore, type ZodStoreMetadata } from './store/store.zod.utils';
|
|
3
1
|
export { zodModuleMethodFactory } from './zod-module.utils';
|
|
4
|
-
export * as
|
|
2
|
+
export * as API from './zod-controller.utils';
|
|
3
|
+
export * as Store from './store';
|