@alevnyacow/nzmt 0.0.6 → 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 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
- Controller: ()=>zod_controller_utils_namespaceObject,
37
- zodStoreMethodFactory: ()=>zodStoreMethodFactory,
36
+ Store: ()=>store_namespaceObject,
38
37
  zodModuleMethodFactory: ()=>zodModuleMethodFactory,
39
- RAMStore: ()=>store_ram_utils_RAMStore
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
- const external_uuid_namespaceObject = require("uuid");
48
- const external_zod_namespaceObject = require("zod");
49
- var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
50
- class Pagination {
51
- data;
52
- static schema = external_zod_default().object({
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,175 @@ const endpoints = (metadata, sharedConfig = {})=>{
496
339
  };
497
340
  return endpointLogic;
498
341
  };
499
- exports.Controller = __webpack_exports__.Controller;
500
- exports.RAMStore = __webpack_exports__.RAMStore;
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 external_uuid_namespaceObject = require("uuid");
422
+ const InRAM = (schemas, options)=>{
423
+ class RAMStore {
424
+ ___data = [];
425
+ method = methods(schemas);
426
+ ___listSearchLogic = (entity, pattern)=>{
427
+ const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
428
+ const entityAsObject = entity;
429
+ return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
430
+ };
431
+ ___specificSearchLogic = (entity, pattern)=>{
432
+ const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
433
+ const entityAsObject = entity;
434
+ return Object.entries(entityAsObject).filter(([key])=>patternKeys.includes(key)).every(([key, value])=>value === pattern[key] || value?.toString()?.includes(pattern[key]?.toString()));
435
+ };
436
+ ___mapDetailToList = (entity)=>entity;
437
+ ___mapCreatePayloadToDetail = (payload)=>({
438
+ ...payload,
439
+ id: (0, external_uuid_namespaceObject.v4)()
440
+ });
441
+ ___mapUpdatePayloadToDetail = (prevValue, update)=>({
442
+ ...prevValue,
443
+ ...update
444
+ });
445
+ constructor(){
446
+ if (!options) return;
447
+ if (options.searchLogic) {
448
+ if (options.searchLogic.list) this.___listSearchLogic = options.searchLogic.list;
449
+ if (options.searchLogic.specific) this.___specificSearchLogic = options.searchLogic.specific;
450
+ }
451
+ if (options.mappers) {
452
+ if (options.mappers.detailToList) this.___mapDetailToList = options.mappers.detailToList;
453
+ if (options.mappers.createPayloadToDetail) this.___mapCreatePayloadToDetail = options.mappers.createPayloadToDetail;
454
+ if (options.mappers.updatePayloadToDetail) this.___mapUpdatePayloadToDetail = options.mappers.updatePayloadToDetail;
455
+ }
456
+ if (options.initialData) this.___data = [
457
+ ...options.initialData
458
+ ];
459
+ }
460
+ list = this.method('list', async ({ filter, pagination = {
461
+ pageSize: 1000,
462
+ zeroBasedIndex: 0
463
+ } })=>{
464
+ schemas.searchPayload.list.parse(filter);
465
+ Pagination.schema.parse(pagination);
466
+ const afterFiltration = this.___data.filter((x)=>this.___listSearchLogic(x, filter));
467
+ const afterPagination = afterFiltration.filter((_, i)=>i >= pagination.pageSize * pagination.zeroBasedIndex && i < (pagination.zeroBasedIndex + 1) * pagination.pageSize);
468
+ const result = afterPagination.map((x)=>this.___mapDetailToList(x));
469
+ external_zod_default().array(schemas.models.list).parse(result);
470
+ return result;
471
+ });
472
+ details = this.method('details', async ({ filter })=>{
473
+ const details = this.___data.find((x)=>this.___specificSearchLogic(x, filter));
474
+ if (!details) return null;
475
+ return details;
476
+ });
477
+ create = this.method('create', async ({ payload })=>{
478
+ const newItem = this.___mapCreatePayloadToDetail(payload);
479
+ this.___data = this.___data.concat(newItem);
480
+ return {
481
+ id: newItem.id
482
+ };
483
+ });
484
+ updateOne = this.method('updateOne', async ({ filter, payload })=>{
485
+ const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
486
+ this.___data = this.___data.map((x, i)=>{
487
+ if (i !== index) return x;
488
+ return this.___mapUpdatePayloadToDetail(x, payload);
489
+ });
490
+ return {
491
+ success: index > -1
492
+ };
493
+ });
494
+ deleteOne = this.method('deleteOne', async ({ filter })=>{
495
+ const index = this.___data.findIndex((x)=>this.___specificSearchLogic(x, filter));
496
+ this.___data = this.___data.filter((_x, i)=>i !== index);
497
+ return {
498
+ success: index > -1
499
+ };
500
+ });
501
+ }
502
+ return RAMStore;
503
+ };
504
+ exports.API = __webpack_exports__.API;
505
+ exports.Store = __webpack_exports__.Store;
501
506
  exports.zodModuleMethodFactory = __webpack_exports__.zodModuleMethodFactory;
502
- exports.zodStoreMethodFactory = __webpack_exports__.zodStoreMethodFactory;
503
507
  for(var __rspack_i in __webpack_exports__)if (-1 === [
504
- "Controller",
505
- "RAMStore",
506
- "zodModuleMethodFactory",
507
- "zodStoreMethodFactory"
508
+ "API",
509
+ "Store",
510
+ "zodModuleMethodFactory"
508
511
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
509
512
  Object.defineProperty(exports, '__esModule', {
510
513
  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 Controller from './zod-controller.utils';
2
+ export * as API from './zod-controller.utils';
3
+ export * as Store from './store';