inanis 0.0.7-beta.3 → 0.0.7-beta.4

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.
@@ -1,40 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.Method = void 0;
37
- const Yup = __importStar(require("yup"));
4
+ const zod_1 = require("zod");
38
5
  const power_helper_1 = require("power-helper");
39
6
  const json_schema_js_1 = require("../utils/json-schema.js");
40
7
  const context_js_1 = require("./context.js");
@@ -339,18 +306,19 @@ class Method {
339
306
  });
340
307
  }
341
308
  if (this.verify.query) {
342
- const attrs = this.verify.query(Yup);
309
+ const attrs = this.verify.query(zod_1.z);
343
310
  for (let key in attrs) {
344
311
  const doc = docs.query?.[key] || {};
345
- const { spec, type } = attrs[key];
312
+ const schema = attrs[key];
313
+ const isOptional = schema.isOptional();
346
314
  output.parameters.push({
347
315
  in: 'query',
348
316
  name: key,
349
317
  description: doc.desc,
350
318
  example: doc.example,
351
- required: !spec.nullable,
319
+ required: !isOptional,
352
320
  schema: {
353
- type: type
321
+ type: 'string'
354
322
  }
355
323
  });
356
324
  }
@@ -374,7 +342,7 @@ class Method {
374
342
  }
375
343
  else {
376
344
  const doc = docs.body;
377
- const schema = bodySchemaBindDoc((0, json_schema_js_1.yupToJsonSchema)(this.verify.body), doc);
345
+ const schema = bodySchemaBindDoc((0, json_schema_js_1.zodToJsonSchema)(this.verify.body), doc);
378
346
  output.requestBody = {
379
347
  content: {
380
348
  [this.contentType]: {
@@ -424,11 +392,12 @@ class Method {
424
392
  }
425
393
  if (this.verify.response) {
426
394
  const doc = docs.response;
427
- const schema = bodySchemaBindDoc((0, json_schema_js_1.yupToJsonSchema)(yup => {
395
+ const jsonSchema = (0, json_schema_js_1.zodToJsonSchema)(z => {
428
396
  return {
429
- data: yup.object(this.verify.response(yup)).required()
397
+ data: z.object(this.verify.response(z)).required()
430
398
  };
431
- }), doc);
399
+ });
400
+ const schema = bodySchemaBindDoc(jsonSchema, doc);
432
401
  output.responses[200] = {
433
402
  description: 'Success',
434
403
  content: {
@@ -1,4 +1,4 @@
1
- import * as Yup from 'yup';
1
+ import { z } from 'zod';
2
2
  import { Hook } from 'power-helper';
3
3
  import { TableManager, TableParams, Index } from './table.js';
4
4
  import type { MongoClient, Db } from 'mongodb';
@@ -30,9 +30,9 @@ export declare class DocumentDbManager<M extends Modes> extends Hook<Channels> {
30
30
  mongoClientDB?: Db;
31
31
  dynamoDbOptions: DynamoDbConfig | null;
32
32
  constructor(params: Params<M>);
33
- static defineSchema<T extends Yup.AnyObjectSchema>(schema: (_yup: typeof Yup) => T): () => T;
33
+ static defineSchema<T extends z.ZodObject<any>>(schema: (_z: typeof z) => T): () => T;
34
34
  _install(): Promise<void>;
35
- defineTable<T extends Yup.AnyObjectSchema, P extends T['__outputType'], EP extends P & {
35
+ defineTable<T extends z.ZodObject<any>, P extends z.infer<T>, EP extends P & {
36
36
  createdAt: number;
37
37
  updatedAt: number;
38
38
  expiredAt: number;
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.DocumentDbManager = void 0;
37
- const Yup = __importStar(require("yup"));
37
+ const zod_1 = require("zod");
38
38
  const change_case_1 = require("change-case");
39
39
  const power_helper_1 = require("power-helper");
40
40
  const output_js_1 = require("../utils/output.js");
@@ -53,7 +53,7 @@ class DocumentDbManager extends power_helper_1.Hook {
53
53
  this.params = params;
54
54
  }
55
55
  static defineSchema(schema) {
56
- return () => schema(Yup);
56
+ return () => schema(zod_1.z);
57
57
  }
58
58
  async _install() {
59
59
  const { mode, config } = await this.params.install();
@@ -126,10 +126,11 @@ class DocumentDbManager extends power_helper_1.Hook {
126
126
  continue;
127
127
  }
128
128
  const keys = [table.params.primaryKey];
129
- const schema = table.yupSchema;
129
+ const schema = table.zodSchema;
130
130
  const getKeyType = (key) => {
131
- if (schema.fields[key]) {
132
- return schema.fields[key].type === 'string' ? 'S' : 'N';
131
+ const field = schema.shape[key];
132
+ if (field) {
133
+ return field._def.typeName === 'ZodString' ? 'S' : 'N';
133
134
  }
134
135
  else {
135
136
  throw exception.create(`key ${key} not found in schema.`);
@@ -1,4 +1,4 @@
1
- import * as Yup from 'yup';
1
+ import { z } from 'zod';
2
2
  import { DynamoDbTable } from './table-dynamo.js';
3
3
  import { MongoCollection } from './table-mongo.js';
4
4
  import { TPick } from 'power-helper';
@@ -23,9 +23,9 @@ export type TableParams<T = any, ID = any, PK = any, SK = any> = {
23
23
  tableName: string;
24
24
  primaryKey: PK;
25
25
  secondaryKey: SK;
26
- schema: (_yup: typeof Yup) => T;
26
+ schema: (_z: typeof z) => T;
27
27
  };
28
- export declare class TableManager<T extends Yup.AnyObjectSchema, OP extends T['__outputType'], OEP extends P & {
28
+ export declare class TableManager<T extends z.ZodObject<any>, OP extends z.infer<T>, OEP extends OP & {
29
29
  createdAt: number;
30
30
  updatedAt: number;
31
31
  expiredAt: number;
@@ -38,7 +38,7 @@ export declare class TableManager<T extends Yup.AnyObjectSchema, OP extends T['_
38
38
  constructor(manager: DocumentDbManager<'dynamo' | 'mongo'>, params: TableParams<T, ID, PK, SK>);
39
39
  get _type(): EP;
40
40
  get _putType(): P;
41
- get yupSchema(): T;
41
+ get zodSchema(): T;
42
42
  _connect(): void;
43
43
  get(primary: Key, secondary: Key): Promise<EP>;
44
44
  scan(options: Omit<ListOptions, 'forward'>): Promise<{
@@ -1,40 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.TableManager = void 0;
37
- const Yup = __importStar(require("yup"));
4
+ const zod_1 = require("zod");
38
5
  const exception_js_1 = require("../exception.js");
39
6
  const table_dynamo_js_1 = require("./table-dynamo.js");
40
7
  const table_mongo_js_1 = require("./table-mongo.js");
@@ -47,7 +14,7 @@ class TableManager {
47
14
  mongoDbCollection;
48
15
  constructor(manager, params) {
49
16
  this.params = params;
50
- this.schema = params.schema(Yup);
17
+ this.schema = params.schema(zod_1.z);
51
18
  this.manager = manager;
52
19
  }
53
20
  get _type() {
@@ -56,8 +23,8 @@ class TableManager {
56
23
  get _putType() {
57
24
  return null;
58
25
  }
59
- get yupSchema() {
60
- return this.params.schema(Yup);
26
+ get zodSchema() {
27
+ return this.params.schema(zod_1.z);
61
28
  }
62
29
  _connect() {
63
30
  if (this.manager.mode === 'mongo') {
@@ -127,7 +94,8 @@ class TableManager {
127
94
  }
128
95
  async update(primary, secondary, data) {
129
96
  for (let key in data) {
130
- this.schema.validateSyncAt(key, data);
97
+ const partialSchema = this.schema.pick({ [key]: true });
98
+ partialSchema.parse({ [key]: data[key] });
131
99
  }
132
100
  if (this.manager.mode === 'mongo') {
133
101
  await this.mongoDbCollection.update(primary, secondary, data);
@@ -137,8 +105,7 @@ class TableManager {
137
105
  }
138
106
  }
139
107
  async replace(primary, secondary, data) {
140
- let cast = this.schema.cast(data);
141
- this.schema.validateSync(cast);
108
+ let cast = this.schema.parse(data);
142
109
  if (this.manager.mode === 'mongo') {
143
110
  let result = await this.mongoDbCollection.replace(primary, secondary, cast);
144
111
  return result;
@@ -149,8 +116,7 @@ class TableManager {
149
116
  }
150
117
  }
151
118
  async put(data) {
152
- let cast = this.schema.cast(data);
153
- this.schema.validateSync(cast);
119
+ let cast = this.schema.parse(data);
154
120
  if (this.manager.mode === 'mongo') {
155
121
  let result = await this.mongoDbCollection.put(cast);
156
122
  return result;
@@ -161,8 +127,7 @@ class TableManager {
161
127
  }
162
128
  }
163
129
  async putForce(data) {
164
- let cast = this.schema.cast(data);
165
- this.schema.validateSync(cast);
130
+ let cast = this.schema.parse(data);
166
131
  if (this.manager.mode === 'mongo') {
167
132
  await this.mongoDbCollection.putForce(cast);
168
133
  }
@@ -1,4 +1,4 @@
1
- import { convertSchema } from '@sodaru/yup-to-json-schema';
1
+ import { z } from 'zod';
2
2
  import { ValidateCallback } from './validate.js';
3
- export type JsonSchema = ReturnType<typeof convertSchema>;
4
- export declare const yupToJsonSchema: (cb: ValidateCallback<any>) => import("json-schema").JSONSchema7;
3
+ export declare const zodToJsonSchema: (cb: ValidateCallback<any>) => z.core.JSONSchema.JSONSchema;
4
+ export type JsonSchema = ReturnType<typeof zodToJsonSchema>;
@@ -1,42 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.yupToJsonSchema = void 0;
37
- const Yup = __importStar(require("yup"));
38
- const yup_to_json_schema_1 = require("@sodaru/yup-to-json-schema");
39
- const yupToJsonSchema = (cb) => {
40
- return (0, yup_to_json_schema_1.convertSchema)(Yup.object(cb(Yup)));
3
+ exports.zodToJsonSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const zodToJsonSchema = (cb) => {
6
+ return (0, zod_1.toJSONSchema)(zod_1.z.object(cb(zod_1.z)));
41
7
  };
42
- exports.yupToJsonSchema = yupToJsonSchema;
8
+ exports.zodToJsonSchema = zodToJsonSchema;
@@ -1,11 +1,11 @@
1
- import * as Yup from 'yup';
1
+ import { z } from 'zod';
2
2
  import { DeepRequired } from '../types.js';
3
- import type { Schema, InferType } from 'yup';
4
- export type ValidateCallback<T extends Record<string, Schema>> = (_yup: typeof Yup) => {
3
+ import type { ZodAny } from 'zod';
4
+ export type ValidateCallback<T extends Record<string, ZodAny>> = (_z: typeof z) => {
5
5
  [K in keyof T]: T[K];
6
6
  };
7
7
  export type ValidateCallbackOutputs<T extends ValidateCallback<any>, R = ReturnType<T>> = {
8
- [K in keyof R]: R[K] extends Schema ? DeepRequired<InferType<R[K]>> : unknown;
8
+ [K in keyof R]: R[K] extends ZodAny ? DeepRequired<z.infer<R[K]>> : unknown;
9
9
  };
10
10
  export declare function definedValidateSchema<T extends ValidateCallback<any>>(cb: T): T;
11
- export declare function validate<T extends ValidateCallback<any>, R = ReturnType<T>>(target: any, schemaCallback: T): { [K in keyof R]: R[K] extends Schema ? DeepRequired<InferType<R[K]>> : unknown; };
11
+ export declare function validate<T extends ValidateCallback<any>, R = ReturnType<T>>(target: any, schemaCallback: T): { [K in keyof R]: R[K] extends ZodAny ? DeepRequired<z.infer<R[K]>> : unknown; };
@@ -1,44 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.definedValidateSchema = definedValidateSchema;
37
4
  exports.validate = validate;
38
- const Yup = __importStar(require("yup"));
5
+ const zod_1 = require("zod");
39
6
  function definedValidateSchema(cb) {
40
7
  return cb;
41
8
  }
42
9
  function validate(target, schemaCallback) {
43
- return Yup.object(schemaCallback(Yup)).required().validateSync(target || {});
10
+ return zod_1.z.object(schemaCallback(zod_1.z)).required().parse(target || {});
44
11
  }
@@ -31,7 +31,7 @@ export declare class WebsocketManager<M extends Modes> {
31
31
  mode: Modes;
32
32
  params: Params<M>;
33
33
  inanis: Inanis | null;
34
- emiters: Emitter<any, any>[];
34
+ emitters: Emitter<any, any>[];
35
35
  nodeWebsocket: WebSocketServer | null;
36
36
  nodeWebsocketClientPool: Map<string, WebSocketServerRequest>;
37
37
  constructor(params: Params<M>);
@@ -43,7 +43,7 @@ class WebsocketManager {
43
43
  mode;
44
44
  params;
45
45
  inanis = null;
46
- emiters = [];
46
+ emitters = [];
47
47
  nodeWebsocket = null;
48
48
  nodeWebsocketClientPool = new Map();
49
49
  constructor(params) {
@@ -116,9 +116,9 @@ class WebsocketManager {
116
116
  }
117
117
  }
118
118
  createEmitter(name, params) {
119
- const emiter = new emitter_js_1.Emitter(this, name, params);
120
- this.emiters.push(emiter);
121
- return emiter;
119
+ const emitter = new emitter_js_1.Emitter(this, name, params);
120
+ this.emitters.push(emitter);
121
+ return emitter;
122
122
  }
123
123
  // =================
124
124
  //
@@ -132,11 +132,11 @@ class WebsocketManager {
132
132
  required: [],
133
133
  properties: {}
134
134
  };
135
- for (let emiter of this.emiters) {
135
+ for (let emitter of this.emitters) {
136
136
  if (Array.isArray(tsData.required)) {
137
- tsData.required.push(emiter.name);
137
+ tsData.required.push(emitter.name);
138
138
  }
139
- tsData.properties[emiter.name] = (0, json_schema_js_1.yupToJsonSchema)(emiter.params.sendSchema);
139
+ tsData.properties[emitter.name] = (0, json_schema_js_1.zodToJsonSchema)(emitter.params.sendSchema);
140
140
  }
141
141
  try {
142
142
  const { js: jsBeautify } = await Promise.resolve().then(() => __importStar(require('js-beautify')));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inanis",
3
- "version": "0.0.7-beta.3",
3
+ "version": "0.0.7-beta.4",
4
4
  "description": "Micro Service Best Tools.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -53,7 +53,6 @@
53
53
  "@aws-sdk/credential-provider-node": "^3.848.0",
54
54
  "@aws-sdk/lib-dynamodb": "^3.850.0",
55
55
  "@aws-sdk/s3-request-presigner": "^3.850.0",
56
- "@sodaru/yup-to-json-schema": "^2.0.1",
57
56
  "amqplib": "^0.10.8",
58
57
  "axios": "^1.11.0",
59
58
  "change-case": "^5.4.4",
@@ -74,7 +73,7 @@
74
73
  "redis": "^5.6.1",
75
74
  "websocket": "^1.0.35",
76
75
  "yaml": "^2.8.0",
77
- "yup": "^1.6.1"
76
+ "zod": "^4.1.12"
78
77
  },
79
78
  "packageManager": "yarn@4.1.1"
80
79
  }