@oh-my-pi/omptype 17.3.0 → 17.3.2
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/CHANGELOG.md +6 -0
- package/dist/js/typebox.js +9 -2
- package/package.json +1 -1
- package/src/typebox.ts +7 -2
package/CHANGELOG.md
CHANGED
package/dist/js/typebox.js
CHANGED
|
@@ -76,7 +76,13 @@ function tString(opts) {
|
|
|
76
76
|
const valid = formatPredicate(format);
|
|
77
77
|
schema = schema.narrow((value, ctx) => valid(value) || ctx.mustBe(`a string in ${format} format`));
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
const result = applyMeta(schema, opts);
|
|
80
|
+
const keywords = {};
|
|
81
|
+
if (opts?.pattern !== undefined)
|
|
82
|
+
keywords.pattern = opts.pattern;
|
|
83
|
+
if (opts?.format !== undefined)
|
|
84
|
+
keywords.format = opts.format === "url" ? "uri" : opts.format;
|
|
85
|
+
return opts?.pattern !== undefined || opts?.format !== undefined ? withJsonSchemaKeywords(result, keywords) : result;
|
|
80
86
|
}
|
|
81
87
|
function formatPredicate(format) {
|
|
82
88
|
switch (format) {
|
|
@@ -147,7 +153,8 @@ function tNumber(opts, integer = false) {
|
|
|
147
153
|
ctx.mustBe(`a multiple of ${divisor}`));
|
|
148
154
|
});
|
|
149
155
|
}
|
|
150
|
-
|
|
156
|
+
const result = applyMeta(schema, opts);
|
|
157
|
+
return opts?.multipleOf !== undefined ? withJsonSchemaKeywords(result, { multipleOf: opts.multipleOf }) : result;
|
|
151
158
|
}
|
|
152
159
|
function tLiteral(value, opts) {
|
|
153
160
|
return applyMeta(asRuntime(type.enumerated(value)), opts);
|
package/package.json
CHANGED
package/src/typebox.ts
CHANGED
|
@@ -220,7 +220,11 @@ function tString(opts?: StringOpts): TString {
|
|
|
220
220
|
const valid = formatPredicate(format);
|
|
221
221
|
schema = schema.narrow((value, ctx) => valid(value) || ctx.mustBe(`a string in ${format} format`));
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
const result = applyMeta(schema, opts);
|
|
224
|
+
const keywords: Record<string, unknown> = {};
|
|
225
|
+
if (opts?.pattern !== undefined) keywords.pattern = opts.pattern;
|
|
226
|
+
if (opts?.format !== undefined) keywords.format = opts.format === "url" ? "uri" : opts.format;
|
|
227
|
+
return opts?.pattern !== undefined || opts?.format !== undefined ? withJsonSchemaKeywords(result, keywords) : result;
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
function formatPredicate(format: string): (value: string) => boolean {
|
|
@@ -290,7 +294,8 @@ function tNumber(opts?: NumberOpts, integer = false): TNumber {
|
|
|
290
294
|
);
|
|
291
295
|
});
|
|
292
296
|
}
|
|
293
|
-
|
|
297
|
+
const result = applyMeta(schema, opts);
|
|
298
|
+
return opts?.multipleOf !== undefined ? withJsonSchemaKeywords(result, { multipleOf: opts.multipleOf }) : result;
|
|
294
299
|
}
|
|
295
300
|
|
|
296
301
|
function tLiteral<const V extends string | number | boolean | null>(value: V, opts?: Meta): TLiteral<V> {
|