yuppi 1.3.2 → 1.3.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.
package/README.md CHANGED
@@ -8,17 +8,17 @@
8
8
  [Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
9
9
  [Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
10
10
  [Void]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined
11
- [YuppiOptionsDefault]: ./src/defaults/YuppiOptions.default.ts
12
11
  [Domain]: ./src/patterns/Domain.pattern.ts
13
12
  [Email]: ./src/patterns/Email.pattern.ts
14
13
  [HTTP]: ./src/patterns/HTTP.pattern.ts
15
14
  [PhoneNumber]: ./src/patterns/PhoneNumber.pattern.ts
16
15
  [URI]: ./src/patterns/URI.pattern.ts
17
16
  [Username]: ./src/patterns/Username.pattern.ts
17
+ [YuppiOptionsDefault]: ./src/defaults/YuppiOptions.default.ts
18
18
  [AnyObject]: https://github.com/jquense/yup/blob/master/src/util/objectTypes.ts#L7
19
19
  [JSONSchema]: https://github.com/sinclairzx81/typebox/blob/master/src/type/object/object.ts#L78
20
20
  [Schema]: ./src/types/Schema.type.ts
21
- [ValidateOptions]: https://github.com/jquense/yup/blob/master/src/types.ts#L47
21
+ [ValidateOptions]: https://github.com/jquense/yup/blob/master/src/types.ts#L48
22
22
  [ValidationError]: https://github.com/jquense/yup/blob/master/src/ValidationError.ts#L53
23
23
  [YuppiOptions]: ./src/types/YuppiOptions.type.ts
24
24
 
package/dist/main.js CHANGED
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(main_exports);
37
37
 
38
38
  // src/Yuppi.class.ts
39
39
  var import_json_schema_to_typescript = require("json-schema-to-typescript");
40
- var import_lodash = __toESM(require("lodash"));
40
+ var import_lodash = __toESM(require("lodash.merge"));
41
41
  var import_fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
 
@@ -56,7 +56,9 @@ var convertToJSONSchema = (schema) => {
56
56
  schema2 = base(schema2, key, config);
57
57
  return schema2;
58
58
  } else if (config.type === "number") {
59
- schema2 = config.integer === true ? import_typebox.Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default }) : import_typebox.Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default });
59
+ if (config.positive) config.min = 1;
60
+ if (config.negative) config.max = -1;
61
+ schema2 = config.integer === true ? import_typebox.Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, positive: config.positive, negative: config.negative, default: config.default }) : import_typebox.Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, positive: config.positive, negative: config.negative, default: config.default });
60
62
  schema2 = base(schema2, key, config);
61
63
  return schema2;
62
64
  } else if (config.type === "boolean") {
@@ -70,7 +72,7 @@ var convertToJSONSchema = (schema) => {
70
72
  } else if (config.type === "object") {
71
73
  const nested_properties = {};
72
74
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
73
- schema2 = import_typebox.Type.Object(nested_properties, { additionalProperties: false });
75
+ schema2 = import_typebox.Type.Object(nested_properties, { default: config.default, additionalProperties: false });
74
76
  schema2 = base(schema2, key, config);
75
77
  return schema2;
76
78
  } else if (config.type === "array") {
@@ -89,6 +91,7 @@ var Yup = __toESM(require("yup"));
89
91
  var convertToYup = (schema, error_messages) => {
90
92
  const base = (schema2, key, config) => {
91
93
  schema2 = schema2.nullable();
94
+ schema2 = schema2.optional();
92
95
  if (config.default) schema2 = schema2.default(config.default);
93
96
  if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
94
97
  if (config.required)
@@ -98,7 +101,6 @@ var convertToYup = (schema, error_messages) => {
98
101
  (property) => {
99
102
  if (property === void 0) return false;
100
103
  if (typeof property === "string" && property.trim() === "") return false;
101
- if (Array.isArray(property) && property.length === 0) return false;
102
104
  return true;
103
105
  }
104
106
  );
@@ -108,7 +110,6 @@ var convertToYup = (schema, error_messages) => {
108
110
  let schema2;
109
111
  if (config.type === "string") {
110
112
  schema2 = Yup.string().typeError(({ path: path2 }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path2));
111
- schema2 = base(schema2, key, config);
112
113
  schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
113
114
  if (config.enum)
114
115
  schema2 = schema2.oneOf(
@@ -128,16 +129,17 @@ var convertToYup = (schema, error_messages) => {
128
129
  );
129
130
  if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
130
131
  if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
132
+ schema2 = base(schema2, key, config);
131
133
  return schema2;
132
134
  } else if (config.type === "number") {
133
135
  schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
134
- schema2 = base(schema2, key, config);
135
136
  if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
136
137
  if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
137
138
  if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
138
139
  if (config.integer) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
139
140
  if (config.positive) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
140
141
  if (config.negative) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
142
+ schema2 = base(schema2, key, config);
141
143
  return schema2;
142
144
  } else if (config.type === "boolean") {
143
145
  schema2 = Yup.boolean().typeError(({ path: path2 }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
@@ -145,20 +147,19 @@ var convertToYup = (schema, error_messages) => {
145
147
  return schema2;
146
148
  } else if (config.type === "date") {
147
149
  schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
148
- schema2 = base(schema2, key, config);
149
150
  if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
150
151
  if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
152
+ schema2 = base(schema2, key, config);
151
153
  return schema2;
152
154
  } else if (config.type === "object") {
153
155
  schema2 = Yup.object().typeError(({ path: path2 }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path2));
154
- schema2 = base(schema2, key, config);
155
156
  const nested_properties = {};
156
157
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
157
158
  schema2 = schema2.shape(nested_properties);
159
+ schema2 = base(schema2, key, config);
158
160
  return schema2;
159
161
  } else if (config.type === "array") {
160
162
  schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
161
- schema2 = base(schema2, key, config);
162
163
  if (config.min)
163
164
  schema2 = schema2.min(
164
165
  config.min,
@@ -170,6 +171,7 @@ var convertToYup = (schema, error_messages) => {
170
171
  ({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
171
172
  );
172
173
  schema2 = schema2.of(build(key, config.items));
174
+ schema2 = base(schema2, key, config);
173
175
  return schema2;
174
176
  } else throw new Error(`Unsupported schema type for ${key}`);
175
177
  };
@@ -234,7 +236,7 @@ var YuppiOptionsDefault = {
234
236
  var Yuppi = class {
235
237
  options;
236
238
  constructor(options = YuppiOptionsDefault) {
237
- this.options = import_lodash.default.merge({}, YuppiOptionsDefault, options);
239
+ this.options = (0, import_lodash.default)({}, YuppiOptionsDefault, options);
238
240
  }
239
241
  validate(schema, properties) {
240
242
  const yup_schema = this.convertToYup(schema);
package/dist/main.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/Yuppi.class.ts
8
8
  import { compile } from "json-schema-to-typescript";
9
- import _ from "lodash";
9
+ import merge from "lodash.merge";
10
10
  import fs from "fs";
11
11
  import path from "path";
12
12
 
@@ -25,7 +25,9 @@ var convertToJSONSchema = (schema) => {
25
25
  schema2 = base(schema2, key, config);
26
26
  return schema2;
27
27
  } else if (config.type === "number") {
28
- schema2 = config.integer === true ? Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default }) : Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, default: config.default });
28
+ if (config.positive) config.min = 1;
29
+ if (config.negative) config.max = -1;
30
+ schema2 = config.integer === true ? Type.Integer({ enum: config.enum, minimum: config.min, maximum: config.max, positive: config.positive, negative: config.negative, default: config.default }) : Type.Number({ enum: config.enum, minimum: config.min, maximum: config.max, positive: config.positive, negative: config.negative, default: config.default });
29
31
  schema2 = base(schema2, key, config);
30
32
  return schema2;
31
33
  } else if (config.type === "boolean") {
@@ -39,7 +41,7 @@ var convertToJSONSchema = (schema) => {
39
41
  } else if (config.type === "object") {
40
42
  const nested_properties = {};
41
43
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
42
- schema2 = Type.Object(nested_properties, { additionalProperties: false });
44
+ schema2 = Type.Object(nested_properties, { default: config.default, additionalProperties: false });
43
45
  schema2 = base(schema2, key, config);
44
46
  return schema2;
45
47
  } else if (config.type === "array") {
@@ -58,6 +60,7 @@ import * as Yup from "yup";
58
60
  var convertToYup = (schema, error_messages) => {
59
61
  const base = (schema2, key, config) => {
60
62
  schema2 = schema2.nullable();
63
+ schema2 = schema2.optional();
61
64
  if (config.default) schema2 = schema2.default(config.default);
62
65
  if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
63
66
  if (config.required)
@@ -67,7 +70,6 @@ var convertToYup = (schema, error_messages) => {
67
70
  (property) => {
68
71
  if (property === void 0) return false;
69
72
  if (typeof property === "string" && property.trim() === "") return false;
70
- if (Array.isArray(property) && property.length === 0) return false;
71
73
  return true;
72
74
  }
73
75
  );
@@ -77,7 +79,6 @@ var convertToYup = (schema, error_messages) => {
77
79
  let schema2;
78
80
  if (config.type === "string") {
79
81
  schema2 = Yup.string().typeError(({ path: path2 }) => (error_messages?.string?.type ?? "").replaceAll("{path}", path2));
80
- schema2 = base(schema2, key, config);
81
82
  schema2 = schema2.transform((property) => typeof property === "string" ? property.trim() : property);
82
83
  if (config.enum)
83
84
  schema2 = schema2.oneOf(
@@ -97,16 +98,17 @@ var convertToYup = (schema, error_messages) => {
97
98
  );
98
99
  if (config.lowercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toLowerCase() : property);
99
100
  if (config.uppercase) schema2 = schema2.transform((property) => typeof property === "string" ? property.toUpperCase() : property);
101
+ schema2 = base(schema2, key, config);
100
102
  return schema2;
101
103
  } else if (config.type === "number") {
102
104
  schema2 = Yup.number().typeError(({ path: path2 }) => (error_messages?.number?.type ?? "").replaceAll("{path}", path2));
103
- schema2 = base(schema2, key, config);
104
105
  if (config.enum) schema2 = schema2.oneOf(config.enum, ({ path: path2 }) => (error_messages?.number?.enum ?? "").replaceAll("{path}", path2));
105
106
  if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.number?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", min.toString()));
106
107
  if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.number?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()));
107
108
  if (config.integer) schema2 = schema2.integer(({ path: path2 }) => (error_messages?.number?.integer ?? "").replaceAll("{path}", path2));
108
109
  if (config.positive) schema2 = schema2.positive(({ path: path2 }) => (error_messages?.number?.positive ?? "").replaceAll("{path}", path2));
109
110
  if (config.negative) schema2 = schema2.negative(({ path: path2 }) => (error_messages?.number?.negative ?? "").replaceAll("{path}", path2));
111
+ schema2 = base(schema2, key, config);
110
112
  return schema2;
111
113
  } else if (config.type === "boolean") {
112
114
  schema2 = Yup.boolean().typeError(({ path: path2 }) => (error_messages?.boolean?.type ?? "").replaceAll("{path}", path2));
@@ -114,20 +116,19 @@ var convertToYup = (schema, error_messages) => {
114
116
  return schema2;
115
117
  } else if (config.type === "date") {
116
118
  schema2 = Yup.date().typeError(({ path: path2 }) => (error_messages?.date?.type ?? "").replaceAll("{path}", path2));
117
- schema2 = base(schema2, key, config);
118
119
  if (config.min) schema2 = schema2.min(config.min, ({ path: path2, min }) => (error_messages?.date?.min ?? "").replaceAll("{path}", path2).replaceAll("{min}", new Date(min).toISOString()));
119
120
  if (config.max) schema2 = schema2.max(config.max, ({ path: path2, max }) => (error_messages?.date?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", new Date(max).toISOString()));
121
+ schema2 = base(schema2, key, config);
120
122
  return schema2;
121
123
  } else if (config.type === "object") {
122
124
  schema2 = Yup.object().typeError(({ path: path2 }) => (error_messages?.object?.type ?? "").replaceAll("{path}", path2));
123
- schema2 = base(schema2, key, config);
124
125
  const nested_properties = {};
125
126
  for (const [nested_key, nested_config] of Object.entries(config.properties)) nested_properties[nested_key] = build(nested_key, nested_config);
126
127
  schema2 = schema2.shape(nested_properties);
128
+ schema2 = base(schema2, key, config);
127
129
  return schema2;
128
130
  } else if (config.type === "array") {
129
131
  schema2 = Yup.array().typeError(({ path: path2 }) => (error_messages?.array?.type ?? "").replaceAll("{path}", path2));
130
- schema2 = base(schema2, key, config);
131
132
  if (config.min)
132
133
  schema2 = schema2.min(
133
134
  config.min,
@@ -139,6 +140,7 @@ var convertToYup = (schema, error_messages) => {
139
140
  ({ path: path2, max }) => (error_messages?.array?.max ?? "").replaceAll("{path}", path2).replaceAll("{max}", max.toString()).replaceAll("{plural_suffix}", max > 1 ? "s" : "")
140
141
  );
141
142
  schema2 = schema2.of(build(key, config.items));
143
+ schema2 = base(schema2, key, config);
142
144
  return schema2;
143
145
  } else throw new Error(`Unsupported schema type for ${key}`);
144
146
  };
@@ -203,7 +205,7 @@ var YuppiOptionsDefault = {
203
205
  var Yuppi = class {
204
206
  options;
205
207
  constructor(options = YuppiOptionsDefault) {
206
- this.options = _.merge({}, YuppiOptionsDefault, options);
208
+ this.options = merge({}, YuppiOptionsDefault, options);
207
209
  }
208
210
  validate(schema, properties) {
209
211
  const yup_schema = this.convertToYup(schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuppi",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Schemas that can be converted to Yup and JSON Schema.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/keift/yuppi",
@@ -16,14 +16,14 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@sinclair/typebox": "^0.34.41",
19
- "@types/lodash": "^4.17.20",
20
- "@types/node": "^24.5.2",
19
+ "@types/lodash.merge": "^4.6.9",
20
+ "@types/node": "^24.6.2",
21
21
  "json-schema-to-typescript": "^15.0.4",
22
- "lodash": "^4.17.21",
22
+ "lodash.merge": "^4.6.2",
23
23
  "yup": "^1.7.1"
24
24
  },
25
25
  "devDependencies": {
26
- "neatlint": "^1.1.16",
26
+ "neatlint": "^1.1.18",
27
27
  "prettier": "^3.6.2",
28
28
  "tsup": "^8.5.0"
29
29
  },