@c9up/rune 0.1.7 → 0.1.9

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 (51) hide show
  1. package/dist/MessagesProvider.d.ts +5 -0
  2. package/dist/MessagesProvider.d.ts.map +1 -1
  3. package/dist/MessagesProvider.js +1 -1
  4. package/dist/MessagesProvider.js.map +1 -1
  5. package/dist/Schema.d.ts +831 -35
  6. package/dist/Schema.d.ts.map +1 -1
  7. package/dist/Schema.js +2342 -140
  8. package/dist/Schema.js.map +1 -1
  9. package/dist/date.d.ts +36 -0
  10. package/dist/date.d.ts.map +1 -0
  11. package/dist/date.js +275 -0
  12. package/dist/date.js.map +1 -0
  13. package/dist/errors.d.ts +10 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/errors.js +10 -0
  16. package/dist/errors.js.map +1 -1
  17. package/dist/formats.d.ts +148 -0
  18. package/dist/formats.d.ts.map +1 -0
  19. package/dist/formats.js +671 -0
  20. package/dist/formats.js.map +1 -0
  21. package/dist/index.d.ts +150 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +180 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/magic.d.ts +30 -0
  26. package/dist/magic.d.ts.map +1 -0
  27. package/dist/magic.js +154 -0
  28. package/dist/magic.js.map +1 -0
  29. package/dist/native.d.ts +18 -6
  30. package/dist/native.d.ts.map +1 -1
  31. package/dist/native.js +34 -19
  32. package/dist/native.js.map +1 -1
  33. package/dist/types.d.ts +15 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +12 -0
  36. package/dist/types.js.map +1 -0
  37. package/index.darwin-arm64.node +0 -0
  38. package/index.darwin-x64.node +0 -0
  39. package/index.linux-arm64-gnu.node +0 -0
  40. package/index.linux-x64-gnu.node +0 -0
  41. package/index.win32-x64-msvc.node +0 -0
  42. package/package.json +9 -1
  43. package/src/MessagesProvider.ts +1 -1
  44. package/src/Schema.ts +3389 -177
  45. package/src/date.ts +320 -0
  46. package/src/errors.ts +11 -0
  47. package/src/formats.ts +776 -0
  48. package/src/index.ts +269 -0
  49. package/src/magic.ts +181 -0
  50. package/src/native.ts +36 -21
  51. package/src/types.ts +55 -0
package/dist/native.d.ts CHANGED
@@ -16,12 +16,24 @@ export declare function validateNative(requestJson: string): {
16
16
  data?: Record<string, unknown>;
17
17
  };
18
18
  export declare function isNativeAvailable(): boolean;
19
+ /** Raised when a schema needs the Rust engine and it is not there. */
20
+ export declare class RuneNativeRequiredError extends Error {
21
+ readonly code: "RUNE_NAPI_REQUIRED";
22
+ constructor();
23
+ }
19
24
  /**
20
- * Surface exactly once per process — that the native engine is unavailable so
21
- * the schema is falling back to the TypeScript validator. The two paths can
22
- * differ subtly, so a silent fallback makes validation results depend on whether
23
- * the prebuilt binary loaded (platform-dependent). Callers invoke this only when
24
- * they WOULD have used the native engine (no custom rules / translator).
25
+ * Refuse to validate without the native engine.
26
+ *
27
+ * There is a TypeScript validator, and it used to take over silently with a
28
+ * one-time warning. That made a schema's verdict depend on whether a prebuilt
29
+ * binary happened to load: two deployments of the same code could disagree on
30
+ * whether a payload is valid, and the one that fell back lost the reason to
31
+ * have Rust at all. A schema the engine can run is now run BY the engine or
32
+ * not at all.
33
+ *
34
+ * The TypeScript path stays for what the engine genuinely cannot do — custom
35
+ * rules, a translator, a messages provider — where it is the only
36
+ * implementation, not a second one.
25
37
  */
26
- export declare function warnNativeUnavailableOnce(): void;
38
+ export declare function assertNativeAvailable(): void;
27
39
  //# sourceMappingURL=native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH;;GAEG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG;IACpD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,CAaA;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAID;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAehD"}
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH;;GAEG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG;IACpD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,CAaA;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAaD,sEAAsE;AACtE,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,EAAG,oBAAoB,CAAU;;CAQ9C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
package/dist/native.js CHANGED
@@ -43,26 +43,41 @@ export function validateNative(requestJson) {
43
43
  export function isNativeAvailable() {
44
44
  return native !== undefined;
45
45
  }
46
- let warnedFallback = false;
46
+ /** Why the engine could not be loaded, phrased for whoever has to fix it. */
47
+ function unavailableReason() {
48
+ const target = `${platform}-${arch}`;
49
+ if (loadError !== undefined) {
50
+ return `failed to load (${loadError instanceof Error ? loadError.message : String(loadError)})`;
51
+ }
52
+ return platformMap[target] !== undefined
53
+ ? "binary not found"
54
+ : `no prebuilt binary for ${target}`;
55
+ }
56
+ /** Raised when a schema needs the Rust engine and it is not there. */
57
+ export class RuneNativeRequiredError extends Error {
58
+ code = "RUNE_NAPI_REQUIRED";
59
+ constructor() {
60
+ super(`[RUNE_NAPI_REQUIRED] The Rust validation engine is required but not loaded — ${unavailableReason()}.\n` +
61
+ "Install the prebuilt binary for this platform, or build it with `pnpm build:napi`.");
62
+ this.name = "RuneNativeRequiredError";
63
+ }
64
+ }
47
65
  /**
48
- * Surface exactly once per process — that the native engine is unavailable so
49
- * the schema is falling back to the TypeScript validator. The two paths can
50
- * differ subtly, so a silent fallback makes validation results depend on whether
51
- * the prebuilt binary loaded (platform-dependent). Callers invoke this only when
52
- * they WOULD have used the native engine (no custom rules / translator).
66
+ * Refuse to validate without the native engine.
67
+ *
68
+ * There is a TypeScript validator, and it used to take over silently with a
69
+ * one-time warning. That made a schema's verdict depend on whether a prebuilt
70
+ * binary happened to load: two deployments of the same code could disagree on
71
+ * whether a payload is valid, and the one that fell back lost the reason to
72
+ * have Rust at all. A schema the engine can run is now run BY the engine or
73
+ * not at all.
74
+ *
75
+ * The TypeScript path stays for what the engine genuinely cannot do — custom
76
+ * rules, a translator, a messages provider — where it is the only
77
+ * implementation, not a second one.
53
78
  */
54
- export function warnNativeUnavailableOnce() {
55
- if (warnedFallback)
56
- return;
57
- warnedFallback = true;
58
- const target = `${platform}-${arch}`;
59
- const reason = loadError !== undefined
60
- ? `failed to load (${loadError instanceof Error ? loadError.message : String(loadError)})`
61
- : platformMap[target] !== undefined
62
- ? "binary not found"
63
- : `no prebuilt binary for ${target}`;
64
- console.warn(`[rune] native validation engine unavailable — ${reason}. Falling back to the ` +
65
- "TypeScript validator, whose results can differ subtly from the Rust engine — " +
66
- "validation is platform-dependent for this process.");
79
+ export function assertNativeAvailable() {
80
+ if (native === undefined)
81
+ throw new RuneNativeRequiredError();
67
82
  }
68
83
  //# sourceMappingURL=native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,E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K,SAAS,CAAC;AAC7B,CAAC;AAED,6EAA6E;AAC7E,SAAS,iBAAiB;IACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;IACrC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,mBAAmB,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;IACjG,CAAC;IACD,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,SAAS;QACvC,CAAC,CAAC,kBAAkB;QACpB,CAAC,CAAC,0BAA0B,MAAM,EAAE,CAAC;AACvC,CAAC;AAED,sEAAsE;AACtE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACxC,IAAI,GAAG,oBAA6B,CAAC;IAC9C;QACC,KAAK,CACJ,gFAAgF,iBAAiB,EAAE,KAAK;YACvG,oFAAoF,CACrF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB;IACpC,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,uBAAuB,EAAE,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @module @c9up/rune/types
3
+ * @description
4
+ * Type-only surface, mirroring `@vinejs/vine/types`.
5
+ *
6
+ * A separate subpath so a consumer can `import type { FieldContext } from
7
+ * "@c9up/rune/types"` exactly as it would from Vine — importing types through
8
+ * the value entrypoint pulls the whole module graph into a file that only
9
+ * needed a signature.
10
+ */
11
+ export type { DateFormat } from "./date.js";
12
+ export type { AlphaOptions, EmailOptions, NormalizeEmailOptions, NormalizeUrlOptions, UrlOptions, } from "./formats.js";
13
+ export type { MessageArgs, MessagesProviderContract, ValidationFields, ValidationMessages, } from "./MessagesProvider.js";
14
+ export type { AsyncCompiledRule, AsyncRuleValidator, CompiledRule, ConditionalBranch, ConditionalGroup, CreateRuleOptions, DatabaseLookup, DatabaseResolver, DatabaseRuleOptions, ErrorReporterContract, ErrorReporterFactory, FieldContext, FileLike, HostResolver, Infer, JsonSchemaModifier, ParseContext, RuleChain, RuleDef, RuleValidator, SchemaIntrospection, UnionBranch, ValidateOptions, ValidationError, ValidationMessageParams, ValidationResult, ValidationSchema, ValidationTranslator, } from "./Schema.js";
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,GACV,MAAM,cAAc,CAAC;AACtB,YAAY,EACX,WAAW,EACX,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,aAAa,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module @c9up/rune/types
3
+ * @description
4
+ * Type-only surface, mirroring `@vinejs/vine/types`.
5
+ *
6
+ * A separate subpath so a consumer can `import type { FieldContext } from
7
+ * "@c9up/rune/types"` exactly as it would from Vine — importing types through
8
+ * the value entrypoint pulls the whole module graph into a file that only
9
+ * needed a signature.
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c9up/rune",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Rune — Validation engine for the Ream framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,6 +27,14 @@
27
27
  ".": {
28
28
  "types": "./dist/index.d.ts",
29
29
  "import": "./dist/index.js"
30
+ },
31
+ "./types": {
32
+ "types": "./dist/types.d.ts",
33
+ "import": "./dist/types.js"
34
+ },
35
+ "./errors": {
36
+ "types": "./dist/errors.d.ts",
37
+ "import": "./dist/errors.js"
30
38
  }
31
39
  },
32
40
  "publishConfig": {
@@ -39,7 +39,7 @@ export interface MessagesProviderContract {
39
39
  * Replace a dotted field path's numeric segments with `*` so array items share
40
40
  * a single wildcard message key — `tags.0.name` → `tags.*.name` (VineJS parity).
41
41
  */
42
- function toWildcardPath(field: string): string {
42
+ export function toWildcardPath(field: string): string {
43
43
  return field
44
44
  .split(".")
45
45
  .map((segment) => (/^\d+$/.test(segment) ? "*" : segment))