@warlock.js/seal 5.37.1 → 5.38.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/cjs/index.cjs +36 -8
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/{object-Um5Ds4ch.cjs → object-BK6x62QZ.cjs} +27 -4
  5. package/cjs/object-BK6x62QZ.cjs.map +1 -0
  6. package/cjs/object.cjs +2 -2
  7. package/cjs/{required-methods-Bh481cKm.cjs → required-methods-Bt9oNJ5V.cjs} +102 -17
  8. package/cjs/required-methods-Bt9oNJ5V.cjs.map +1 -0
  9. package/cjs/{string-BOKt6UtS.cjs → string-bc4YzeXc.cjs} +2 -2
  10. package/cjs/{string-BOKt6UtS.cjs.map → string-bc4YzeXc.cjs.map} +1 -1
  11. package/cjs/string.cjs +2 -2
  12. package/esm/helpers/humanize-attribute.d.mts +18 -0
  13. package/esm/helpers/humanize-attribute.d.mts.map +1 -0
  14. package/esm/helpers/humanize-attribute.mjs +24 -0
  15. package/esm/helpers/humanize-attribute.mjs.map +1 -0
  16. package/esm/helpers/index.d.mts +2 -1
  17. package/esm/helpers/index.mjs +2 -1
  18. package/esm/helpers/validation-helpers.d.mts.map +1 -1
  19. package/esm/helpers/validation-helpers.mjs +2 -1
  20. package/esm/helpers/validation-helpers.mjs.map +1 -1
  21. package/esm/index.d.mts +3 -2
  22. package/esm/index.mjs +2 -1
  23. package/esm/standard-schema/json-schema.d.mts +12 -3
  24. package/esm/standard-schema/json-schema.d.mts.map +1 -1
  25. package/esm/standard-schema/json-schema.mjs +65 -15
  26. package/esm/standard-schema/json-schema.mjs.map +1 -1
  27. package/esm/types/index.d.mts +2 -2
  28. package/esm/types/inference-types.d.mts +13 -0
  29. package/esm/types/inference-types.d.mts.map +1 -1
  30. package/esm/validators/base-validator.d.mts +30 -0
  31. package/esm/validators/base-validator.d.mts.map +1 -1
  32. package/esm/validators/base-validator.mjs +34 -0
  33. package/esm/validators/base-validator.mjs.map +1 -1
  34. package/esm/validators/object-validator.d.mts +23 -4
  35. package/esm/validators/object-validator.d.mts.map +1 -1
  36. package/esm/validators/object-validator.mjs +25 -2
  37. package/esm/validators/object-validator.mjs.map +1 -1
  38. package/esm/validators/scalar-validator.d.mts +1 -1
  39. package/esm/validators/scalar-validator.d.mts.map +1 -1
  40. package/esm/validators/scalar-validator.mjs +8 -5
  41. package/esm/validators/scalar-validator.mjs.map +1 -1
  42. package/esm/validators/union-validator.mjs +4 -2
  43. package/esm/validators/union-validator.mjs.map +1 -1
  44. package/llms-full.txt +2 -1
  45. package/package.json +1 -1
  46. package/skills/define-structural-shape/SKILL.md +1 -1
  47. package/skills/generate-json-schema/SKILL.md +1 -0
  48. package/cjs/object-Um5Ds4ch.cjs.map +0 -1
  49. package/cjs/required-methods-Bh481cKm.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ All notable changes to `@warlock.js/seal` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
6
 
7
+ ## 5.38.0 - 2026-10-25
8
+
9
+ ### Added
10
+
11
+ - `humanizeAttribute(key)` turns a field key into words (`max_dumbbell_kg` becomes "Max dumbbell kg").
12
+
13
+ ### Changed
14
+
15
+ - `ObjectValidator#partial()` keeps its types: the named keys (all keys when none are named) become optional in the inferred shape.
16
+
17
+ ### Fixed
18
+
19
+ - `toJsonSchema("openai-strict")` keeps an optional `v.enum()`, `v.literal()`, `in()` list or union nullable: `null` is added to an `enum`, a `const` becomes `anyOf: [{ const }, { type: "null" }]`, `anyOf`/`oneOf` gain one `{ type: "null" }` branch, and `allOf`/`$ref` schemas are wrapped in `anyOf`. Before, such fields were listed in `required` with no way to send `null`.
20
+ - `.nullable()` on an enum, a literal, a scalar or a union no longer produces a `type` of `[undefined, "null"]` for `draft-2020-12`; the same shapes as above are used, and `openapi-3.0` adds `null` to the `enum` next to `nullable: true`. A nullable single literal now emits `anyOf: [{ const }, { type: "null" }]` instead of a bare `const`.
21
+ - `.internal()` marks a field as set by the server. It validates and infers like any other field; `ObjectValidator#withoutInternal()` returns the schema without those fields (type included) for request validation, and `internalKeys()` lists them. `BaseValidator#isServerSet()` reads the mark.
22
+ - `translateAttribute` passed to `v.validate(schema, data, options)` now translates the `:input` placeholder too; before, only the global config's translator was used for attribute labels.
23
+
7
24
  ## 5.34.3 - 2026-10-20
8
25
 
9
26
  ### Changed
package/cjs/index.cjs CHANGED
@@ -26,14 +26,36 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  }) : target, mod));
27
27
 
28
28
  //#endregion
29
- const require_required_methods = require("./required-methods-Bh481cKm.cjs");
30
- const require_object = require("./object-Um5Ds4ch.cjs");
31
- const require_string = require("./string-BOKt6UtS.cjs");
29
+ const require_required_methods = require("./required-methods-Bt9oNJ5V.cjs");
30
+ const require_object = require("./object-BK6x62QZ.cjs");
31
+ const require_string = require("./string-bc4YzeXc.cjs");
32
32
  let _mongez_reinforcements = require("@mongez/reinforcements");
33
33
  let _mongez_supportive_is = require("@mongez/supportive-is");
34
34
  let dayjs = require("dayjs");
35
35
  dayjs = __toESM(dayjs, 1);
36
36
 
37
+ //#region ../../packages/seal/src/helpers/humanize-attribute.ts
38
+ /**
39
+ * Turn a field key into readable words for a validation message.
40
+ *
41
+ * Splits on underscores, hyphens, dots and camel-case boundaries, lowercases
42
+ * the words and capitalises the first one. A key without letters (such as an
43
+ * array index) is returned unchanged.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * humanizeAttribute("max_dumbbell_kg"); // "Max dumbbell kg"
48
+ * humanizeAttribute("firstName"); // "First name"
49
+ * humanizeAttribute("userID"); // "User id"
50
+ * ```
51
+ */
52
+ function humanizeAttribute(attribute) {
53
+ if (!/[A-Za-z]/.test(attribute)) return attribute;
54
+ const words = attribute.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[_\-.]+/g, " ").trim().replace(/\s+/g, " ").toLowerCase();
55
+ return words.charAt(0).toUpperCase() + words.slice(1);
56
+ }
57
+
58
+ //#endregion
37
59
  //#region ../../packages/seal/src/validators/any-validator.ts
38
60
  /**
39
61
  * Any validator - accepts any value
@@ -2512,16 +2534,19 @@ var ScalarValidator = class extends require_string.PrimitiveValidator {
2512
2534
  * // → { enum: ["active", "inactive"] }
2513
2535
  * ```
2514
2536
  */
2515
- toJsonSchema(_target = "draft-2020-12") {
2537
+ toJsonSchema(target = "draft-2020-12") {
2538
+ let schema;
2516
2539
  const inOpts = require_required_methods.getRuleOptions(this.rules, "in");
2517
- if (inOpts?.values && Array.isArray(inOpts.values)) return { enum: inOpts.values };
2518
2540
  const enumOpts = require_required_methods.getRuleOptions(this.rules, "enum");
2519
- if (enumOpts?.enum && Array.isArray(enumOpts.enum)) return { enum: enumOpts.enum };
2520
- return { oneOf: [
2541
+ if (inOpts?.values && Array.isArray(inOpts.values)) schema = { enum: [...inOpts.values] };
2542
+ else if (enumOpts?.enum && Array.isArray(enumOpts.enum)) schema = { enum: [...enumOpts.enum] };
2543
+ else schema = { oneOf: [
2521
2544
  { type: "string" },
2522
2545
  { type: "number" },
2523
2546
  { type: "boolean" }
2524
2547
  ] };
2548
+ if (this.isNullable) require_required_methods.applyNullable(schema, target);
2549
+ return schema;
2525
2550
  }
2526
2551
  };
2527
2552
 
@@ -2706,7 +2731,9 @@ var UnionValidator = class extends require_required_methods.BaseValidator {
2706
2731
  * ```
2707
2732
  */
2708
2733
  toJsonSchema(target = "draft-2020-12") {
2709
- return { oneOf: (require_required_methods.getRuleOptions(this.rules, "union")?.validators ?? []).map((v) => v.toJsonSchema(target)) };
2734
+ const schema = { oneOf: (require_required_methods.getRuleOptions(this.rules, "union")?.validators ?? []).map((v) => v.toJsonSchema(target)) };
2735
+ if (this.isNullable) require_required_methods.applyNullable(schema, target);
2736
+ return schema;
2710
2737
  }
2711
2738
  };
2712
2739
 
@@ -2993,6 +3020,7 @@ exports.hasPlugin = hasPlugin;
2993
3020
  exports.hexColorRule = require_required_methods.hexColorRule;
2994
3021
  exports.hslColorRule = require_required_methods.hslColorRule;
2995
3022
  exports.htmlEscapeMutator = require_string.htmlEscapeMutator;
3023
+ exports.humanizeAttribute = humanizeAttribute;
2996
3024
  exports.humanizeSize = require_required_methods.humanizeSize;
2997
3025
  exports.inRule = require_required_methods.inRule;
2998
3026
  exports.instanceofRule = require_required_methods.instanceofRule;