@oyinlola141/lattice-schema 0.1.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 (143) hide show
  1. package/README.md +19 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/index.d.ts +40 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +37 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/schemaBase/index.d.ts +10 -0
  8. package/dist/schemaBase/index.d.ts.map +1 -0
  9. package/dist/schemaBase/index.js +9 -0
  10. package/dist/schemaBase/index.js.map +1 -0
  11. package/dist/schemaBase/schemaBase.context.d.ts +17 -0
  12. package/dist/schemaBase/schemaBase.context.d.ts.map +1 -0
  13. package/dist/schemaBase/schemaBase.context.js +44 -0
  14. package/dist/schemaBase/schemaBase.context.js.map +1 -0
  15. package/dist/schemaBase/schemaBase.core.d.ts +52 -0
  16. package/dist/schemaBase/schemaBase.core.d.ts.map +1 -0
  17. package/dist/schemaBase/schemaBase.core.js +99 -0
  18. package/dist/schemaBase/schemaBase.core.js.map +1 -0
  19. package/dist/schemaBase/schemaBase.result.d.ts +17 -0
  20. package/dist/schemaBase/schemaBase.result.d.ts.map +1 -0
  21. package/dist/schemaBase/schemaBase.result.js +29 -0
  22. package/dist/schemaBase/schemaBase.result.js.map +1 -0
  23. package/dist/schemaBase/schemaBase.type.d.ts +57 -0
  24. package/dist/schemaBase/schemaBase.type.d.ts.map +1 -0
  25. package/dist/schemaBase/schemaBase.type.js +7 -0
  26. package/dist/schemaBase/schemaBase.type.js.map +1 -0
  27. package/dist/schemaCoerce/index.d.ts +7 -0
  28. package/dist/schemaCoerce/index.d.ts.map +1 -0
  29. package/dist/schemaCoerce/index.js +7 -0
  30. package/dist/schemaCoerce/index.js.map +1 -0
  31. package/dist/schemaCoerce/schemaCoerce.core.d.ts +48 -0
  32. package/dist/schemaCoerce/schemaCoerce.core.d.ts.map +1 -0
  33. package/dist/schemaCoerce/schemaCoerce.core.js +126 -0
  34. package/dist/schemaCoerce/schemaCoerce.core.js.map +1 -0
  35. package/dist/schemaComposition/index.d.ts +10 -0
  36. package/dist/schemaComposition/index.d.ts.map +1 -0
  37. package/dist/schemaComposition/index.js +10 -0
  38. package/dist/schemaComposition/index.js.map +1 -0
  39. package/dist/schemaComposition/schemaEnum.core.d.ts +21 -0
  40. package/dist/schemaComposition/schemaEnum.core.d.ts.map +1 -0
  41. package/dist/schemaComposition/schemaEnum.core.js +41 -0
  42. package/dist/schemaComposition/schemaEnum.core.js.map +1 -0
  43. package/dist/schemaComposition/schemaIntersection.core.d.ts +21 -0
  44. package/dist/schemaComposition/schemaIntersection.core.d.ts.map +1 -0
  45. package/dist/schemaComposition/schemaIntersection.core.js +54 -0
  46. package/dist/schemaComposition/schemaIntersection.core.js.map +1 -0
  47. package/dist/schemaComposition/schemaLazy.core.d.ts +22 -0
  48. package/dist/schemaComposition/schemaLazy.core.d.ts.map +1 -0
  49. package/dist/schemaComposition/schemaLazy.core.js +33 -0
  50. package/dist/schemaComposition/schemaLazy.core.js.map +1 -0
  51. package/dist/schemaComposition/schemaUnion.core.d.ts +32 -0
  52. package/dist/schemaComposition/schemaUnion.core.d.ts.map +1 -0
  53. package/dist/schemaComposition/schemaUnion.core.js +89 -0
  54. package/dist/schemaComposition/schemaUnion.core.js.map +1 -0
  55. package/dist/schemaInference/index.d.ts +7 -0
  56. package/dist/schemaInference/index.d.ts.map +1 -0
  57. package/dist/schemaInference/index.js +7 -0
  58. package/dist/schemaInference/index.js.map +1 -0
  59. package/dist/schemaInference/schemaInfer.type.d.ts +27 -0
  60. package/dist/schemaInference/schemaInfer.type.d.ts.map +1 -0
  61. package/dist/schemaInference/schemaInfer.type.js +7 -0
  62. package/dist/schemaInference/schemaInfer.type.js.map +1 -0
  63. package/dist/schemaModifiers/index.d.ts +10 -0
  64. package/dist/schemaModifiers/index.d.ts.map +1 -0
  65. package/dist/schemaModifiers/index.js +10 -0
  66. package/dist/schemaModifiers/index.js.map +1 -0
  67. package/dist/schemaModifiers/schemaDefault.core.d.ts +20 -0
  68. package/dist/schemaModifiers/schemaDefault.core.d.ts.map +1 -0
  69. package/dist/schemaModifiers/schemaDefault.core.js +33 -0
  70. package/dist/schemaModifiers/schemaDefault.core.js.map +1 -0
  71. package/dist/schemaModifiers/schemaOptionalNullable.core.d.ts +30 -0
  72. package/dist/schemaModifiers/schemaOptionalNullable.core.d.ts.map +1 -0
  73. package/dist/schemaModifiers/schemaOptionalNullable.core.js +47 -0
  74. package/dist/schemaModifiers/schemaOptionalNullable.core.js.map +1 -0
  75. package/dist/schemaModifiers/schemaRefine.core.d.ts +21 -0
  76. package/dist/schemaModifiers/schemaRefine.core.d.ts.map +1 -0
  77. package/dist/schemaModifiers/schemaRefine.core.js +40 -0
  78. package/dist/schemaModifiers/schemaRefine.core.js.map +1 -0
  79. package/dist/schemaModifiers/schemaTransform.core.d.ts +20 -0
  80. package/dist/schemaModifiers/schemaTransform.core.d.ts.map +1 -0
  81. package/dist/schemaModifiers/schemaTransform.core.js +40 -0
  82. package/dist/schemaModifiers/schemaTransform.core.js.map +1 -0
  83. package/dist/schemaPrimitives/index.d.ts +12 -0
  84. package/dist/schemaPrimitives/index.d.ts.map +1 -0
  85. package/dist/schemaPrimitives/index.js +12 -0
  86. package/dist/schemaPrimitives/index.js.map +1 -0
  87. package/dist/schemaPrimitives/schemaBoolean.core.d.ts +26 -0
  88. package/dist/schemaPrimitives/schemaBoolean.core.d.ts.map +1 -0
  89. package/dist/schemaPrimitives/schemaBoolean.core.js +47 -0
  90. package/dist/schemaPrimitives/schemaBoolean.core.js.map +1 -0
  91. package/dist/schemaPrimitives/schemaLiteral.core.d.ts +19 -0
  92. package/dist/schemaPrimitives/schemaLiteral.core.d.ts.map +1 -0
  93. package/dist/schemaPrimitives/schemaLiteral.core.js +37 -0
  94. package/dist/schemaPrimitives/schemaLiteral.core.js.map +1 -0
  95. package/dist/schemaPrimitives/schemaNumber.core.d.ts +62 -0
  96. package/dist/schemaPrimitives/schemaNumber.core.d.ts.map +1 -0
  97. package/dist/schemaPrimitives/schemaNumber.core.js +191 -0
  98. package/dist/schemaPrimitives/schemaNumber.core.js.map +1 -0
  99. package/dist/schemaPrimitives/schemaSentinel.core.d.ts +53 -0
  100. package/dist/schemaPrimitives/schemaSentinel.core.d.ts.map +1 -0
  101. package/dist/schemaPrimitives/schemaSentinel.core.js +101 -0
  102. package/dist/schemaPrimitives/schemaSentinel.core.js.map +1 -0
  103. package/dist/schemaPrimitives/schemaString.core.d.ts +74 -0
  104. package/dist/schemaPrimitives/schemaString.core.d.ts.map +1 -0
  105. package/dist/schemaPrimitives/schemaString.core.js +208 -0
  106. package/dist/schemaPrimitives/schemaString.core.js.map +1 -0
  107. package/dist/schemaPrimitives/schemaTransform.core.d.ts +13 -0
  108. package/dist/schemaPrimitives/schemaTransform.core.d.ts.map +1 -0
  109. package/dist/schemaPrimitives/schemaTransform.core.js +31 -0
  110. package/dist/schemaPrimitives/schemaTransform.core.js.map +1 -0
  111. package/dist/schemaRoot/index.d.ts +7 -0
  112. package/dist/schemaRoot/index.d.ts.map +1 -0
  113. package/dist/schemaRoot/index.js +7 -0
  114. package/dist/schemaRoot/index.js.map +1 -0
  115. package/dist/schemaRoot/schemaRoot.namespace.d.ts +72 -0
  116. package/dist/schemaRoot/schemaRoot.namespace.d.ts.map +1 -0
  117. package/dist/schemaRoot/schemaRoot.namespace.js +79 -0
  118. package/dist/schemaRoot/schemaRoot.namespace.js.map +1 -0
  119. package/dist/schemaStructures/index.d.ts +12 -0
  120. package/dist/schemaStructures/index.d.ts.map +1 -0
  121. package/dist/schemaStructures/index.js +11 -0
  122. package/dist/schemaStructures/index.js.map +1 -0
  123. package/dist/schemaStructures/schemaArray.core.d.ts +36 -0
  124. package/dist/schemaStructures/schemaArray.core.d.ts.map +1 -0
  125. package/dist/schemaStructures/schemaArray.core.js +105 -0
  126. package/dist/schemaStructures/schemaArray.core.js.map +1 -0
  127. package/dist/schemaStructures/schemaMapSet.core.d.ts +31 -0
  128. package/dist/schemaStructures/schemaMapSet.core.d.ts.map +1 -0
  129. package/dist/schemaStructures/schemaMapSet.core.js +77 -0
  130. package/dist/schemaStructures/schemaMapSet.core.js.map +1 -0
  131. package/dist/schemaStructures/schemaObject.core.d.ts +66 -0
  132. package/dist/schemaStructures/schemaObject.core.d.ts.map +1 -0
  133. package/dist/schemaStructures/schemaObject.core.js +184 -0
  134. package/dist/schemaStructures/schemaObject.core.js.map +1 -0
  135. package/dist/schemaStructures/schemaRecord.core.d.ts +20 -0
  136. package/dist/schemaStructures/schemaRecord.core.d.ts.map +1 -0
  137. package/dist/schemaStructures/schemaRecord.core.js +66 -0
  138. package/dist/schemaStructures/schemaRecord.core.js.map +1 -0
  139. package/dist/schemaStructures/schemaTuple.core.d.ts +24 -0
  140. package/dist/schemaStructures/schemaTuple.core.d.ts.map +1 -0
  141. package/dist/schemaStructures/schemaTuple.core.js +60 -0
  142. package/dist/schemaStructures/schemaTuple.core.js.map +1 -0
  143. package/package.json +42 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/base
3
+ *
4
+ * Abstract base class for all Lattice schemas.
5
+ * Defines the core parsing pipeline: Input → validate → Output.
6
+ */
7
+ import type { SchemaParseContext, SchemaParseOptions, SchemaResult, SchemaMetadata } from "./schemaBase.type.js";
8
+ /**
9
+ * Base schema class. All schema types extend this.
10
+ *
11
+ * @typeParam TOutput - The output type after parsing/transforms.
12
+ * @typeParam TInput - The input type (defaults to TOutput).
13
+ */
14
+ export declare abstract class Schema<TOutput, TInput = TOutput> {
15
+ /** The schema type name for debugging. */
16
+ abstract readonly _type: string;
17
+ /** Optional metadata (description, example, etc.). */
18
+ protected _metadata: SchemaMetadata | undefined;
19
+ /**
20
+ * Internal parse implementation — subclasses implement this.
21
+ */
22
+ abstract _parse(ctx: SchemaParseContext, input: unknown): TOutput;
23
+ /**
24
+ * Parses input and returns the output value.
25
+ * Throws SchemaError on failure.
26
+ */
27
+ parse(input: TInput, options?: SchemaParseOptions): TOutput;
28
+ /**
29
+ * Parses input and returns a discriminated result.
30
+ * Never throws.
31
+ */
32
+ safeParse(input: TInput, options?: SchemaParseOptions): SchemaResult<TOutput>;
33
+ /**
34
+ * Returns the output type TOutput. Runtime no-op, purely for type inference.
35
+ */
36
+ _output(): TOutput;
37
+ /**
38
+ * Returns the input type TInput. Runtime no-op, purely for type inference.
39
+ */
40
+ _input(): TInput;
41
+ /** Attaches metadata to the schema. */
42
+ describe(description: string): this;
43
+ /** Attaches example metadata. */
44
+ example(value: unknown): this;
45
+ /** Attaches title metadata. */
46
+ title(title: string): this;
47
+ /** Marks the schema as deprecated. */
48
+ deprecated(): this;
49
+ /** Returns the current metadata. */
50
+ getMetadata(): SchemaMetadata | undefined;
51
+ }
52
+ //# sourceMappingURL=schemaBase.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.core.d.ts","sourceRoot":"","sources":["../../src/schemaBase/schemaBase.core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACf,MAAM,sBAAsB,CAAC;AAK9B;;;;;GAKG;AACH,8BAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IACpD,0CAA0C;IAC1C,kBAAyB,KAAK,EAAE,MAAM,CAAC;IAEvC,sDAAsD;IACtD,SAAS,CAAC,SAAS,EAAE,cAAc,GAAG,SAAS,CAAC;IAEhD;;OAEG;IACH,SAAgB,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAEzE;;;OAGG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAajE;IAED;;;OAGG;IACI,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,YAAY,CAAC,OAAO,CAAC,CAkBnF;IAED;;OAEG;IACI,OAAO,IAAI,OAAO,CAExB;IAED;;OAEG;IACI,MAAM,IAAI,MAAM,CAEtB;IAED,uCAAuC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAGzC;IAED,iCAAiC;IAC1B,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,+BAA+B;IACxB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGhC;IAED,sCAAsC;IAC/B,UAAU,IAAI,IAAI,CAGxB;IAED,oCAAoC;IAC7B,WAAW,IAAI,cAAc,GAAG,SAAS,CAE/C;CACF"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @latticejs/schema/base
3
+ *
4
+ * Abstract base class for all Lattice schemas.
5
+ * Defines the core parsing pipeline: Input → validate → Output.
6
+ */
7
+ import { createParseContext } from "./schemaBase.context.js";
8
+ import { schemaSuccess, schemaFailure } from "./schemaBase.result.js";
9
+ import { SchemaError } from "@latticejs/errors";
10
+ /**
11
+ * Base schema class. All schema types extend this.
12
+ *
13
+ * @typeParam TOutput - The output type after parsing/transforms.
14
+ * @typeParam TInput - The input type (defaults to TOutput).
15
+ */
16
+ export class Schema {
17
+ /** Optional metadata (description, example, etc.). */
18
+ _metadata;
19
+ /**
20
+ * Parses input and returns the output value.
21
+ * Throws SchemaError on failure.
22
+ */
23
+ parse(input, options) {
24
+ const ctx = createParseContext(options);
25
+ try {
26
+ return this._parse(ctx, input);
27
+ }
28
+ catch (error) {
29
+ if (error instanceof SchemaError) {
30
+ throw error;
31
+ }
32
+ throw new SchemaError(String(error), {
33
+ issues: ctx.issues.length > 0 ? ctx.issues : undefined,
34
+ cause: error,
35
+ });
36
+ }
37
+ }
38
+ /**
39
+ * Parses input and returns a discriminated result.
40
+ * Never throws.
41
+ */
42
+ safeParse(input, options) {
43
+ const ctx = createParseContext(options);
44
+ try {
45
+ const data = this._parse(ctx, input);
46
+ if (ctx.issues.length > 0) {
47
+ return schemaFailure([...ctx.issues]);
48
+ }
49
+ return schemaSuccess(data);
50
+ }
51
+ catch {
52
+ if (ctx.issues.length > 0) {
53
+ return schemaFailure([...ctx.issues]);
54
+ }
55
+ return schemaFailure([{
56
+ code: "custom",
57
+ path: [],
58
+ message: "Unknown validation error",
59
+ }]);
60
+ }
61
+ }
62
+ /**
63
+ * Returns the output type TOutput. Runtime no-op, purely for type inference.
64
+ */
65
+ _output() {
66
+ return undefined;
67
+ }
68
+ /**
69
+ * Returns the input type TInput. Runtime no-op, purely for type inference.
70
+ */
71
+ _input() {
72
+ return undefined;
73
+ }
74
+ /** Attaches metadata to the schema. */
75
+ describe(description) {
76
+ this._metadata = { ...this._metadata, description };
77
+ return this;
78
+ }
79
+ /** Attaches example metadata. */
80
+ example(value) {
81
+ this._metadata = { ...this._metadata, example: value };
82
+ return this;
83
+ }
84
+ /** Attaches title metadata. */
85
+ title(title) {
86
+ this._metadata = { ...this._metadata, title };
87
+ return this;
88
+ }
89
+ /** Marks the schema as deprecated. */
90
+ deprecated() {
91
+ this._metadata = { ...this._metadata, deprecated: true };
92
+ return this;
93
+ }
94
+ /** Returns the current metadata. */
95
+ getMetadata() {
96
+ return this._metadata;
97
+ }
98
+ }
99
+ //# sourceMappingURL=schemaBase.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.core.js","sourceRoot":"","sources":["../../src/schemaBase/schemaBase.core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,OAAgB,MAAM;IAI1B,sDAAsD;IAC5C,SAAS,CAA6B;IAOhD;;;OAGG;IACI,KAAK,CAAC,KAAa,EAA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;IACH,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,OAAO,SAA+B,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,MAAM;QACX,OAAO,SAA8B,CAAC;IACxC,CAAC;IAED,uCAAuC;IAChC,QAAQ,CAAC,WAAmB;QACjC,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iCAAiC;IAC1B,OAAO,CAAC,KAAc;QAC3B,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+BAA+B;IACxB,KAAK,CAAC,KAAa;QACxB,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sCAAsC;IAC/B,UAAU;QACf,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oCAAoC;IAC7B,WAAW;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/result
3
+ *
4
+ * Result constructors and type guards for schema outcomes.
5
+ */
6
+ import type { SchemaResult, SchemaSuccess, SchemaFailure, SchemaIssue } from "./schemaBase.type.js";
7
+ /** Creates a successful result. */
8
+ export declare function schemaSuccess<T>(data: T): SchemaSuccess<T>;
9
+ /** Creates a failure result. */
10
+ export declare function schemaFailure(issues: readonly SchemaIssue[]): SchemaFailure;
11
+ /** Type guard for successful results. */
12
+ export declare function isSchemaSuccess<T>(result: SchemaResult<T>): result is SchemaSuccess<T>;
13
+ /** Type guard for failure results. */
14
+ export declare function isSchemaFailure<T>(result: SchemaResult<T>): result is SchemaFailure;
15
+ /** Unwraps a result, throwing on failure. */
16
+ export declare function unwrapSchemaResult<T>(result: SchemaResult<T>): T;
17
+ //# sourceMappingURL=schemaBase.result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.result.d.ts","sourceRoot":"","sources":["../../src/schemaBase/schemaBase.result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEpG,mCAAmC;AACnC,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAE1D;AAED,gCAAgC;AAChC,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,aAAa,CAE3E;AAED,yCAAyC;AACzC,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,CAEtF;AAED,sCAAsC;AACtC,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,aAAa,CAEnF;AAED,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAShE"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @latticejs/schema/result
3
+ *
4
+ * Result constructors and type guards for schema outcomes.
5
+ */
6
+ /** Creates a successful result. */
7
+ export function schemaSuccess(data) {
8
+ return { success: true, data };
9
+ }
10
+ /** Creates a failure result. */
11
+ export function schemaFailure(issues) {
12
+ return { success: false, issues };
13
+ }
14
+ /** Type guard for successful results. */
15
+ export function isSchemaSuccess(result) {
16
+ return result.success === true;
17
+ }
18
+ /** Type guard for failure results. */
19
+ export function isSchemaFailure(result) {
20
+ return result.success === false;
21
+ }
22
+ /** Unwraps a result, throwing on failure. */
23
+ export function unwrapSchemaResult(result) {
24
+ if (result.success) {
25
+ return result.data;
26
+ }
27
+ throw new Error(`Schema validation failed with ${result.issues.length} issue(s): ${result.issues.map((i) => i.message).join("; ")}`);
28
+ }
29
+ //# sourceMappingURL=schemaBase.result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.result.js","sourceRoot":"","sources":["../../src/schemaBase/schemaBase.result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,mCAAmC;AACnC,MAAM,UAAU,aAAa,CAAI,IAAO;IACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAW,CAAC;AAC1C,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,aAAa,CAAC,MAA8B;IAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAW,CAAC;AAC7C,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,eAAe,CAAI,MAAuB;IACxD,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AACjC,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,eAAe,CAAI,MAAuB;IACxD,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC;AAClC,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,kBAAkB,CAAI,MAAuB;IAC3D,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CACb,iCAAiC,MAAM,CAAC,MAAM,CAAC,MAAM,cACnD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAC/C,EAAE,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/types
3
+ *
4
+ * Core types for the Lattice schema system.
5
+ */
6
+ import type { SchemaIssueCode } from "@oyinlola141/lattice-constants";
7
+ /** A single segment in a validation path. */
8
+ export type SchemaPathSegment = string | number;
9
+ /** A structured validation issue with machine-readable code. */
10
+ export interface SchemaIssue {
11
+ readonly code: SchemaIssueCode | string;
12
+ readonly path: readonly SchemaPathSegment[];
13
+ readonly message: string;
14
+ readonly expected?: string;
15
+ readonly received?: string;
16
+ readonly input?: unknown;
17
+ readonly details?: Record<string, unknown>;
18
+ }
19
+ /** Successful validation result. */
20
+ export interface SchemaSuccess<T> {
21
+ readonly success: true;
22
+ readonly data: T;
23
+ }
24
+ /** Failed validation result. */
25
+ export interface SchemaFailure {
26
+ readonly success: false;
27
+ readonly issues: readonly SchemaIssue[];
28
+ }
29
+ /** Discriminated union result type. */
30
+ export type SchemaResult<T> = SchemaSuccess<T> | SchemaFailure;
31
+ /** Options for schema parsing. */
32
+ export interface SchemaParseOptions {
33
+ /** Whether to stop at the first error. */
34
+ readonly abortEarly?: boolean;
35
+ /** Maximum nesting depth. */
36
+ readonly maxDepth?: number;
37
+ /** Maximum number of issues to collect. */
38
+ readonly maxIssues?: number;
39
+ /** Current path in the data tree. */
40
+ readonly path?: readonly SchemaPathSegment[];
41
+ }
42
+ /** Internal parsing context passed through recursive validation. */
43
+ export interface SchemaParseContext {
44
+ readonly issues: SchemaIssue[];
45
+ readonly options: SchemaParseOptions;
46
+ readonly seen: WeakSet<object>;
47
+ readonly depth: number;
48
+ readonly path: SchemaPathSegment[];
49
+ }
50
+ /** Schema metadata for OpenAPI/JSON Schema generation. */
51
+ export interface SchemaMetadata {
52
+ readonly description?: string;
53
+ readonly example?: unknown;
54
+ readonly deprecated?: boolean;
55
+ readonly title?: string;
56
+ }
57
+ //# sourceMappingURL=schemaBase.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.type.d.ts","sourceRoot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CAAC,EAAE,MAAM,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC9C;AAED,oEAAoE;AACpE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,iBAAiB,EAAE,CAAC;CACpC;AAED,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @latticejs/schema/types
3
+ *
4
+ * Core types for the Lattice schema system.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=schemaBase.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBase.type.js","sourceRoot":"","sources":["../../src/schemaBase/schemaBase.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/coerce
3
+ *
4
+ * Explicit coercion schemas for type conversion.
5
+ */
6
+ export { CoerceNumberSchema, CoerceBooleanSchema, CoerceStringSchema, CoerceBigIntSchema, coerceNumberSchema, coerceBooleanSchema, coerceStringSchema, coerceBigIntSchema, } from "./schemaCoerce.core.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemaCoerce/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @latticejs/schema/coerce
3
+ *
4
+ * Explicit coercion schemas for type conversion.
5
+ */
6
+ export { CoerceNumberSchema, CoerceBooleanSchema, CoerceStringSchema, CoerceBigIntSchema, coerceNumberSchema, coerceBooleanSchema, coerceStringSchema, coerceBigIntSchema, } from "./schemaCoerce.core.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemaCoerce/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/coerce
3
+ *
4
+ * Explicit coercion schemas — convert string/number inputs to the expected type.
5
+ * Useful for HTTP query parameters and form data.
6
+ */
7
+ import { Schema } from "../schemaBase/index.js";
8
+ import type { SchemaParseContext } from "../schemaBase/index.js";
9
+ /**
10
+ * Coerces input to a number before validating.
11
+ */
12
+ export declare class CoerceNumberSchema extends Schema<number> {
13
+ readonly _type = "coerce.number";
14
+ _parse(ctx: SchemaParseContext, input: unknown): number;
15
+ }
16
+ /**
17
+ * Coerces input to a boolean before validating.
18
+ *
19
+ * Truthy: `"true"`, `"1"`, `1`, `true`
20
+ * Falsy: `"false"`, `"0"`, `0`, `false`
21
+ */
22
+ export declare class CoerceBooleanSchema extends Schema<boolean> {
23
+ readonly _type = "coerce.boolean";
24
+ _parse(ctx: SchemaParseContext, input: unknown): boolean;
25
+ }
26
+ /**
27
+ * Coerces input to a string before validating.
28
+ */
29
+ export declare class CoerceStringSchema extends Schema<string> {
30
+ readonly _type = "coerce.string";
31
+ _parse(ctx: SchemaParseContext, input: unknown): string;
32
+ }
33
+ /**
34
+ * Coerces input to a BigInt before validating.
35
+ */
36
+ export declare class CoerceBigIntSchema extends Schema<bigint> {
37
+ readonly _type = "coerce.bigint";
38
+ _parse(ctx: SchemaParseContext, input: unknown): bigint;
39
+ }
40
+ /** Creates a coercion number schema. */
41
+ export declare function coerceNumberSchema(): CoerceNumberSchema;
42
+ /** Creates a coercion boolean schema. */
43
+ export declare function coerceBooleanSchema(): CoerceBooleanSchema;
44
+ /** Creates a coercion string schema. */
45
+ export declare function coerceStringSchema(): CoerceStringSchema;
46
+ /** Creates a coercion bigint schema. */
47
+ export declare function coerceBigIntSchema(): CoerceBigIntSchema;
48
+ //# sourceMappingURL=schemaCoerce.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaCoerce.core.d.ts","sourceRoot":"","sources":["../../src/schemaCoerce/schemaCoerce.core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAIjE;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,MAAM,CAAC,MAAM,CAAC;IACpD,SAAgB,KAAK,mBAAmB;IAEjC,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAoB7D;CACF;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,MAAM,CAAC,OAAO,CAAC;IACtD,SAAgB,KAAK,oBAAoB;IAElC,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAc9D;CACF;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,MAAM,CAAC,MAAM,CAAC;IACpD,SAAgB,KAAK,mBAAmB;IAEjC,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAe7D;CACF;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,MAAM,CAAC,MAAM,CAAC;IACpD,SAAgB,KAAK,mBAAmB;IAEjC,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAuB7D;CACF;AAED,wCAAwC;AACxC,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED,yCAAyC;AACzC,wBAAgB,mBAAmB,IAAI,mBAAmB,CAEzD;AAED,wCAAwC;AACxC,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED,wCAAwC;AACxC,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @latticejs/schema/coerce
3
+ *
4
+ * Explicit coercion schemas — convert string/number inputs to the expected type.
5
+ * Useful for HTTP query parameters and form data.
6
+ */
7
+ import { Schema } from "../schemaBase/index.js";
8
+ import { addIssue } from "../schemaBase/index.js";
9
+ import { SchemaIssueCode } from "@latticejs/constants";
10
+ /**
11
+ * Coerces input to a number before validating.
12
+ */
13
+ export class CoerceNumberSchema extends Schema {
14
+ _type = "coerce.number";
15
+ _parse(ctx, input) {
16
+ if (typeof input === "number" && !Number.isNaN(input)) {
17
+ return input;
18
+ }
19
+ if (typeof input === "string") {
20
+ const num = Number(input);
21
+ if (!Number.isNaN(num)) {
22
+ return num;
23
+ }
24
+ }
25
+ addIssue(ctx, {
26
+ code: SchemaIssueCode.COERCION_FAILED,
27
+ path: [...ctx.path],
28
+ message: `Cannot coerce ${typeof input} to number`,
29
+ expected: "number",
30
+ received: typeof input,
31
+ });
32
+ throw new Error("Validation failed");
33
+ }
34
+ }
35
+ /**
36
+ * Coerces input to a boolean before validating.
37
+ *
38
+ * Truthy: `"true"`, `"1"`, `1`, `true`
39
+ * Falsy: `"false"`, `"0"`, `0`, `false`
40
+ */
41
+ export class CoerceBooleanSchema extends Schema {
42
+ _type = "coerce.boolean";
43
+ _parse(ctx, input) {
44
+ if (typeof input === "boolean")
45
+ return input;
46
+ if (input === "true" || input === 1 || input === true)
47
+ return true;
48
+ if (input === "false" || input === 0 || input === false)
49
+ return false;
50
+ addIssue(ctx, {
51
+ code: SchemaIssueCode.COERCION_FAILED,
52
+ path: [...ctx.path],
53
+ message: `Cannot coerce ${typeof input} to boolean`,
54
+ expected: "boolean",
55
+ received: typeof input,
56
+ });
57
+ throw new Error("Validation failed");
58
+ }
59
+ }
60
+ /**
61
+ * Coerces input to a string before validating.
62
+ */
63
+ export class CoerceStringSchema extends Schema {
64
+ _type = "coerce.string";
65
+ _parse(ctx, input) {
66
+ if (typeof input === "string")
67
+ return input;
68
+ if (input !== null && input !== undefined) {
69
+ return String(input);
70
+ }
71
+ addIssue(ctx, {
72
+ code: SchemaIssueCode.COERCION_FAILED,
73
+ path: [...ctx.path],
74
+ message: `Cannot coerce ${typeof input} to string`,
75
+ expected: "string",
76
+ received: typeof input,
77
+ });
78
+ throw new Error("Validation failed");
79
+ }
80
+ }
81
+ /**
82
+ * Coerces input to a BigInt before validating.
83
+ */
84
+ export class CoerceBigIntSchema extends Schema {
85
+ _type = "coerce.bigint";
86
+ _parse(ctx, input) {
87
+ if (typeof input === "bigint")
88
+ return input;
89
+ if (typeof input === "number" && Number.isInteger(input)) {
90
+ return BigInt(input);
91
+ }
92
+ if (typeof input === "string") {
93
+ try {
94
+ return BigInt(input);
95
+ }
96
+ catch {
97
+ // Fall through
98
+ }
99
+ }
100
+ addIssue(ctx, {
101
+ code: SchemaIssueCode.COERCION_FAILED,
102
+ path: [...ctx.path],
103
+ message: `Cannot coerce ${typeof input} to bigint`,
104
+ expected: "bigint",
105
+ received: typeof input,
106
+ });
107
+ throw new Error("Validation failed");
108
+ }
109
+ }
110
+ /** Creates a coercion number schema. */
111
+ export function coerceNumberSchema() {
112
+ return new CoerceNumberSchema();
113
+ }
114
+ /** Creates a coercion boolean schema. */
115
+ export function coerceBooleanSchema() {
116
+ return new CoerceBooleanSchema();
117
+ }
118
+ /** Creates a coercion string schema. */
119
+ export function coerceStringSchema() {
120
+ return new CoerceStringSchema();
121
+ }
122
+ /** Creates a coercion bigint schema. */
123
+ export function coerceBigIntSchema() {
124
+ return new CoerceBigIntSchema();
125
+ }
126
+ //# sourceMappingURL=schemaCoerce.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaCoerce.core.js","sourceRoot":"","sources":["../../src/schemaCoerce/schemaCoerce.core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,MAAc;IACpC,KAAK,GAAG,eAAe,CAAC;IAEjC,MAAM,CAAC,GAAuB,EAAE,KAAc;QACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACtD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,GAAG,CAAC;YACb,CAAC;QACH,CAAC;QAED,QAAQ,CAAC,GAAG,EAAE;YACZ,IAAI,EAAE,eAAe,CAAC,eAAe;YACrC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC;YACnB,OAAO,EAAE,iBAAiB,OAAO,K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ACxC,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/composition
3
+ *
4
+ * Schema composition: union, discriminated union, intersection, lazy, enum.
5
+ */
6
+ export { UnionSchema, DiscriminatedUnionSchema, unionSchema } from "./schemaUnion.core.js";
7
+ export { IntersectionSchema, intersectionSchema } from "./schemaIntersection.core.js";
8
+ export { LazySchema, lazySchema } from "./schemaLazy.core.js";
9
+ export { EnumSchema, enumSchema } from "./schemaEnum.core.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemaComposition/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @latticejs/schema/composition
3
+ *
4
+ * Schema composition: union, discriminated union, intersection, lazy, enum.
5
+ */
6
+ export { UnionSchema, DiscriminatedUnionSchema, unionSchema } from "./schemaUnion.core.js";
7
+ export { IntersectionSchema, intersectionSchema } from "./schemaIntersection.core.js";
8
+ export { LazySchema, lazySchema } from "./schemaLazy.core.js";
9
+ export { EnumSchema, enumSchema } from "./schemaEnum.core.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemaComposition/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/composition/enum
3
+ *
4
+ * Enum schema for constrained value sets.
5
+ */
6
+ import { Schema } from "../schemaBase/index.js";
7
+ import type { SchemaParseContext } from "../schemaBase/index.js";
8
+ /**
9
+ * Schema for a fixed set of allowed values.
10
+ */
11
+ export declare class EnumSchema<T extends string | number> extends Schema<T> {
12
+ private readonly _values;
13
+ readonly _type = "enum";
14
+ constructor(_values: readonly T[]);
15
+ _parse(ctx: SchemaParseContext, input: unknown): T;
16
+ /** Returns the allowed values. */
17
+ getValues(): readonly T[];
18
+ }
19
+ /** Creates an enum schema from an array of allowed values. */
20
+ export declare function enumSchema<T extends string | number>(values: readonly T[]): EnumSchema<T>;
21
+ //# sourceMappingURL=schemaEnum.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEnum.core.d.ts","sourceRoot":"","sources":["../../src/schemaComposition/schemaEnum.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAIjE;;GAEG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IAGtD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,SAAgB,KAAK,UAAU;IAE/B,YAA6B,OAAO,EAAE,SAAS,CAAC,EAAE,EAEjD;IAEM,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAYxD;IAED,kCAAkC;IAC3B,SAAS,IAAI,SAAS,CAAC,EAAE,CAE/B;CACF;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAEzF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @latticejs/schema/composition/enum
3
+ *
4
+ * Enum schema for constrained value sets.
5
+ */
6
+ import { Schema } from "../schemaBase/index.js";
7
+ import { addIssue } from "../schemaBase/index.js";
8
+ import { SchemaIssueCode } from "@latticejs/constants";
9
+ /**
10
+ * Schema for a fixed set of allowed values.
11
+ */
12
+ export class EnumSchema extends Schema {
13
+ _values;
14
+ _type = "enum";
15
+ constructor(_values) {
16
+ super();
17
+ this._values = _values;
18
+ }
19
+ _parse(ctx, input) {
20
+ if (!this._values.includes(input)) {
21
+ addIssue(ctx, {
22
+ code: SchemaIssueCode.INVALID_ENUM,
23
+ path: [...ctx.path],
24
+ message: `Expected one of ${this._values.map((v) => JSON.stringify(v)).join(", ")}`,
25
+ expected: this._values.map((v) => JSON.stringify(v)).join(", "),
26
+ received: JSON.stringify(input),
27
+ });
28
+ throw new Error("Validation failed");
29
+ }
30
+ return input;
31
+ }
32
+ /** Returns the allowed values. */
33
+ getValues() {
34
+ return this._values;
35
+ }
36
+ }
37
+ /** Creates an enum schema from an array of allowed values. */
38
+ export function enumSchema(values) {
39
+ return new EnumSchema(values);
40
+ }
41
+ //# sourceMappingURL=schemaEnum.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaEnum.core.js","sourceRoot":"","sources":["../../src/schemaComposition/schemaEnum.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EA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AChC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @oyinlola141/lattice-schema/composition/intersection
3
+ *
4
+ * Intersection schema — validates against all schemas, merging results.
5
+ */
6
+ import { Schema } from "../schemaBase/index.js";
7
+ import type { SchemaParseContext } from "../schemaBase/index.js";
8
+ /**
9
+ * Schema that accepts values matching all provided schemas.
10
+ * Results are merged left to right.
11
+ */
12
+ export declare class IntersectionSchema<TLeft, TRight> extends Schema<TLeft & TRight> {
13
+ private readonly _left;
14
+ private readonly _right;
15
+ readonly _type = "intersection";
16
+ constructor(_left: Schema<TLeft>, _right: Schema<TRight>);
17
+ _parse(ctx: SchemaParseContext, input: unknown): TLeft & TRight;
18
+ }
19
+ /** Creates an intersection schema from two schemas. */
20
+ export declare function intersectionSchema<TLeft, TRight>(left: Schema<TLeft>, right: Schema<TRight>): IntersectionSchema<TLeft, TRight>;
21
+ //# sourceMappingURL=schemaIntersection.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaIntersection.core.d.ts","sourceRoot":"","sources":["../../src/schemaComposition/schemaIntersection.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAIjE;;;GAGG;AACH,qBAAa,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAE,SAAQ,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC;IAIzE,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,SAAgB,KAAK,kBAAkB;IAEvC,YACmB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAGxC;IAEM,MAAM,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CA0BrE;CACF;AAED,uDAAuD;AACvD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAC9C,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,GACpB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAEnC"}