@vibeorm/schema 2.0.0 → 2.1.1
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/dist/capabilities.d.ts +48 -0
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/errors.d.ts +59 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/exclusion.d.ts +40 -0
- package/dist/exclusion.d.ts.map +1 -0
- package/dist/extension.d.ts +12 -0
- package/dist/extension.d.ts.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +301 -27
- package/dist/index.js.map +11 -9
- package/dist/ir.d.ts +46 -4
- package/dist/ir.d.ts.map +1 -1
- package/dist/migration-objects.d.ts +63 -0
- package/dist/migration-objects.d.ts.map +1 -0
- package/dist/predicate.d.ts +105 -0
- package/dist/predicate.d.ts.map +1 -0
- package/dist/reserved.d.ts.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ir.d.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* compile to this IR. Everything downstream (generator, runtime, migrate,
|
|
6
6
|
* extensions) consumes ONLY this — nothing else ever parses schema text.
|
|
7
7
|
*/
|
|
8
|
+
import type { ExclusionIR } from "./exclusion.ts";
|
|
9
|
+
import type { MigrationObjectIR } from "./migration-objects.ts";
|
|
10
|
+
import type { PredicateIR } from "./predicate.ts";
|
|
8
11
|
/** Datasource providers a schema may declare. */
|
|
9
12
|
export type Provider = "postgresql" | "pglite" | "sqlite" | "mysql";
|
|
10
13
|
/**
|
|
@@ -28,6 +31,17 @@ export type FieldType = ScalarType | {
|
|
|
28
31
|
export declare function isEnumType(fieldType: FieldType): fieldType is {
|
|
29
32
|
readonly enum: string;
|
|
30
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* A comparable spelling of a field type — `"String"`, `"Int"`, `"enum:Status"`.
|
|
36
|
+
*
|
|
37
|
+
* The ONE place a `FieldType` becomes a comparison key. Foreign-key pairing
|
|
38
|
+
* (`@vibeorm/dsl`'s `fieldTypeKey`) and schema-predicate operand checking
|
|
39
|
+
* (`@vibeorm/sql`'s `renderPredicate`) both ask the same question — "are these
|
|
40
|
+
* two the same scalar?" — so they read the same answer.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fieldTypeIdentity(params: {
|
|
43
|
+
type: FieldType;
|
|
44
|
+
}): string;
|
|
31
45
|
/** Default value declarations, normalized across schema sources. */
|
|
32
46
|
export type DefaultValueIR = {
|
|
33
47
|
readonly kind: "autoincrement";
|
|
@@ -106,6 +120,8 @@ export type RelationIR = {
|
|
|
106
120
|
readonly type: RelationType;
|
|
107
121
|
/** Explicit @relation name — disambiguates multiple relations between the same pair. */
|
|
108
122
|
readonly relationName?: string;
|
|
123
|
+
/** Physical FK identity, independent of the client relation alias. */
|
|
124
|
+
readonly constraintName?: string;
|
|
109
125
|
/** FK columns on the owning model (FK side only). */
|
|
110
126
|
readonly fields?: readonly string[];
|
|
111
127
|
/** Referenced columns on the target model (FK side only). */
|
|
@@ -126,6 +142,8 @@ export type IndexFieldIR = {
|
|
|
126
142
|
};
|
|
127
143
|
export type IndexIR = {
|
|
128
144
|
readonly name?: string;
|
|
145
|
+
/** Physical unique constraint owning this index, when catalog-backed. */
|
|
146
|
+
readonly constraintName?: string;
|
|
129
147
|
/**
|
|
130
148
|
* CLIENT selector name for a compound unique (`@@unique(..., name:)`) —
|
|
131
149
|
* names the generated `…WhereUniqueInput` property (and the runtime where
|
|
@@ -138,6 +156,12 @@ export type IndexIR = {
|
|
|
138
156
|
readonly fields: readonly IndexFieldIR[];
|
|
139
157
|
/** Partial index predicate (raw SQL), postgres/sqlite only (capability-gated). */
|
|
140
158
|
readonly where?: string;
|
|
159
|
+
/**
|
|
160
|
+
* The typed expression `where` was rendered from, when the predicate was
|
|
161
|
+
* authored as one. Same contract as {@link CheckIR.predicate}: `where` stays
|
|
162
|
+
* the text every consumer reads, this is the structured source.
|
|
163
|
+
*/
|
|
164
|
+
readonly wherePredicate?: PredicateIR;
|
|
141
165
|
/**
|
|
142
166
|
* `UNIQUE NULLS NOT DISTINCT` — NULLs collide instead of always passing.
|
|
143
167
|
* Unique indexes only; postgres 15+ (pglite included), capability-gated.
|
|
@@ -169,22 +193,38 @@ export type NativeRlsIR = {
|
|
|
169
193
|
};
|
|
170
194
|
/**
|
|
171
195
|
* A named CHECK constraint on a model. The expression is RAW SQL, rendered
|
|
172
|
-
* verbatim into DDL
|
|
173
|
-
*
|
|
174
|
-
*
|
|
196
|
+
* verbatim into DDL. Authored same-name changes replace the constraint;
|
|
197
|
+
* live comparisons require normalized definition evidence or an explicit
|
|
198
|
+
* replacement when expression equivalence cannot be established.
|
|
175
199
|
*/
|
|
176
200
|
export type CheckIR = {
|
|
201
|
+
/** Introspection marks raw catalog text so pure diffs cannot guess equivalence. */
|
|
202
|
+
readonly catalogExpression?: true;
|
|
177
203
|
readonly name: string;
|
|
178
204
|
readonly expression: string;
|
|
205
|
+
/**
|
|
206
|
+
* The typed expression `expression` was rendered from, when the check was
|
|
207
|
+
* authored as one. Serializable data, never a callback. Absent for raw
|
|
208
|
+
* authored strings and for introspected catalog text — those two are carried
|
|
209
|
+
* verbatim and never parsed back into a predicate.
|
|
210
|
+
*
|
|
211
|
+
* `expression` stays the single currency for everything downstream (diffing,
|
|
212
|
+
* DDL, desired-state evidence); this field is the authoring source of truth
|
|
213
|
+
* and the reference EPIC 4's exclusion constraints reuse.
|
|
214
|
+
*/
|
|
215
|
+
readonly predicate?: PredicateIR;
|
|
179
216
|
};
|
|
180
217
|
export type ModelIR = {
|
|
181
218
|
readonly name: string;
|
|
219
|
+
/** Physical primary-key constraint name, independent of the client selector. */
|
|
220
|
+
readonly primaryKeyConstraintName?: string;
|
|
182
221
|
/** Table name in the database when it differs from `name` (@@map). */
|
|
183
222
|
readonly dbName?: string;
|
|
184
223
|
readonly fields: readonly FieldIR[];
|
|
185
224
|
readonly relations: readonly RelationIR[];
|
|
186
225
|
readonly indexes: readonly IndexIR[];
|
|
187
|
-
/** Named CHECK constraints (@@check)
|
|
226
|
+
/** Named CHECK constraints (@@check), including authored expression changes. */
|
|
227
|
+
readonly exclusions?: readonly ExclusionIR[];
|
|
188
228
|
readonly checks?: readonly CheckIR[];
|
|
189
229
|
/**
|
|
190
230
|
* Row-scoping policy (`@@policy([field], context: "key")`): the runtime
|
|
@@ -253,6 +293,8 @@ export type DatasourceIR = {
|
|
|
253
293
|
readonly url?: string;
|
|
254
294
|
};
|
|
255
295
|
export type SchemaIR = {
|
|
296
|
+
/** Database-maintenance declarations, excluded from runtime extension registration. */
|
|
297
|
+
readonly migrationObjects?: readonly MigrationObjectIR[];
|
|
256
298
|
/** Native RLS context declaration; absent preserves existing client behavior. */
|
|
257
299
|
readonly rls?: NativeRlsIR;
|
|
258
300
|
readonly datasource: DatasourceIR;
|
package/dist/ir.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../src/ir.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../src/ir.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,iDAAiD;AACjD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD,qEAAqE;AACrE,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAAoC,CAAC;AAE5E,8DAA8D;AAC9D,wBAAgB,iBAAiB,C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
export type QualifiedSqlName = {
|
|
4
|
+
readonly namespace: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
};
|
|
7
|
+
/** Portable catalog identity. PostgreSQL object identifiers must not be persisted. */
|
|
8
|
+
export type SqlObjectIdentity = {
|
|
9
|
+
readonly kind: "table" | "view" | "sequence" | "postgresExtension";
|
|
10
|
+
readonly name: QualifiedSqlName;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "function";
|
|
13
|
+
readonly name: QualifiedSqlName;
|
|
14
|
+
readonly argumentTypes: readonly QualifiedSqlName[];
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "index" | "trigger";
|
|
17
|
+
readonly table: QualifiedSqlName;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "constraint";
|
|
21
|
+
readonly table: QualifiedSqlName;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly constraintType: "check" | "foreignKey" | "exclusion" | "unique" | "primaryKey";
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "column" | "columnDefault" | "generatedColumn";
|
|
26
|
+
readonly table: QualifiedSqlName;
|
|
27
|
+
readonly column: string;
|
|
28
|
+
};
|
|
29
|
+
/** Catalog facts are serialized, not executable verification callbacks. */
|
|
30
|
+
export type SqlObjectFacts = Readonly<Record<string, string | number | boolean | null | readonly string[]>>;
|
|
31
|
+
/** An independently authored expectation, or one deparsed from an independent reference. */
|
|
32
|
+
export type SqlObjectDefinition = {
|
|
33
|
+
readonly identity: SqlObjectIdentity;
|
|
34
|
+
readonly facts: SqlObjectFacts;
|
|
35
|
+
readonly dependencies: readonly SqlObjectIdentity[];
|
|
36
|
+
readonly format: "catalog-v1";
|
|
37
|
+
};
|
|
38
|
+
/** Migration-only declaration. It contributes no generated runtime extension manifest. */
|
|
39
|
+
export type MigrationObjectIR = {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly dialect: Dialect;
|
|
42
|
+
readonly identity: SqlObjectIdentity;
|
|
43
|
+
readonly create: readonly string[];
|
|
44
|
+
readonly drop: readonly string[];
|
|
45
|
+
readonly dependsOn: readonly SqlObjectIdentity[];
|
|
46
|
+
/** Absence preserves ownership but must be reported as inspection unavailable. */
|
|
47
|
+
readonly expected?: SqlObjectDefinition;
|
|
48
|
+
};
|
|
49
|
+
/** Stable, unambiguous identifier also accepted by named removal authorization. */
|
|
50
|
+
export declare function sqlObjectKey(params: {
|
|
51
|
+
identity: SqlObjectIdentity;
|
|
52
|
+
}): string;
|
|
53
|
+
/** Validate identities read from JSON or untyped config before any database access. */
|
|
54
|
+
export declare function isSqlObjectIdentity(value: unknown): value is SqlObjectIdentity;
|
|
55
|
+
/** Reject malformed expected catalog facts rather than degrading to presence-only verification. */
|
|
56
|
+
export declare function isSqlObjectDefinition(value: unknown): value is SqlObjectDefinition;
|
|
57
|
+
/** Runtime validation for serializable migration-only schema contributions. */
|
|
58
|
+
export declare function assertMigrationObjects(params: {
|
|
59
|
+
objects: unknown;
|
|
60
|
+
}): asserts params is {
|
|
61
|
+
objects: readonly MigrationObjectIR[];
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=migration-objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-objects.d.ts","sourceRoot":"","sources":["../src/migration-objects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,mBAAmB,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACvG;IAAE,QAAQ,CAA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AAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACjD,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;CACzC,CAAC;AAEF,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,iBAAiB,CAAA;CAAE,GAAG,MAAM,CAc5E;AAUD,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAW9E;AAED,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAMlF;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,IAAI;IAAE,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,CAmBhI"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed schema predicates — the serializable expression a CHECK constraint or a
|
|
3
|
+
* partial-index `WHERE` is authored as.
|
|
4
|
+
*
|
|
5
|
+
* This module holds the DATA only. It contains no SQL text and no dialect
|
|
6
|
+
* knowledge: rendering a predicate is `renderPredicate` in @vibeorm/sql (rule 4
|
|
7
|
+
* — every SQL-text decision lives in one place), and authoring one is the `c`
|
|
8
|
+
* builder in @vibeorm/dsl.
|
|
9
|
+
*
|
|
10
|
+
* Three properties are load-bearing:
|
|
11
|
+
*
|
|
12
|
+
* 1. **It is data, never a callback.** Nothing downstream carries an executable
|
|
13
|
+
* JavaScript function, so a predicate survives JSON (`desired-state.json`,
|
|
14
|
+
* migration metadata) unchanged.
|
|
15
|
+
* 2. **Fields are LOGICAL names.** `@map`ped physical column names are resolved
|
|
16
|
+
* at render time against the model, so renaming a mapped column cannot leave
|
|
17
|
+
* a CHECK pointing at a column that no longer exists.
|
|
18
|
+
* 3. **Numeric literals keep every digit.** BigInt and Decimal values ride as
|
|
19
|
+
* exact decimal TEXT — `Number(9007199254740993n)` is a different number, the
|
|
20
|
+
* same trap column defaults already guard against.
|
|
21
|
+
*
|
|
22
|
+
* A raw SQL string stays the documented escape hatch for anything this cannot
|
|
23
|
+
* express; raw text is carried verbatim and never parsed back into a predicate.
|
|
24
|
+
*/
|
|
25
|
+
/** Comparison operators a schema predicate may use. Deliberately closed. */
|
|
26
|
+
export type PredicateComparisonOp = "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
|
|
27
|
+
/** All comparison operators, for matrix-style iteration in tests and tooling. */
|
|
28
|
+
export declare const PREDICATE_COMPARISON_OPS: readonly PredicateComparisonOp[];
|
|
29
|
+
/**
|
|
30
|
+
* A reference to one of the model's own fields, by LOGICAL name. The mapped
|
|
31
|
+
* physical column is resolved when the predicate is rendered.
|
|
32
|
+
*/
|
|
33
|
+
export type PredicateFieldRef = {
|
|
34
|
+
readonly kind: "field";
|
|
35
|
+
readonly name: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A literal operand in JSON-safe carrier form. BigInt and Decimal values are
|
|
39
|
+
* carried as exact decimal text; Int/Float as numbers; String/enum as strings.
|
|
40
|
+
*/
|
|
41
|
+
export type PredicateValue = {
|
|
42
|
+
readonly kind: "value";
|
|
43
|
+
readonly value: string | number | boolean;
|
|
44
|
+
};
|
|
45
|
+
/** Either side of a comparison: another field, or a literal. */
|
|
46
|
+
export type PredicateOperand = PredicateFieldRef | PredicateValue;
|
|
47
|
+
/**
|
|
48
|
+
* A boolean expression over one model's fields.
|
|
49
|
+
*
|
|
50
|
+
* SQL three-valued logic applies unchanged: a comparison against NULL is
|
|
51
|
+
* UNKNOWN, and a CHECK constraint passes on TRUE **or** UNKNOWN. Nothing here
|
|
52
|
+
* adds an implicit null guard — where all-or-none is the invariant, the author
|
|
53
|
+
* writes it out with `isNull`/`isNotNull`.
|
|
54
|
+
*/
|
|
55
|
+
export type PredicateIR = {
|
|
56
|
+
readonly kind: "compare";
|
|
57
|
+
readonly op: PredicateComparisonOp;
|
|
58
|
+
readonly left: PredicateFieldRef;
|
|
59
|
+
readonly right: PredicateOperand;
|
|
60
|
+
} | {
|
|
61
|
+
readonly kind: "inList";
|
|
62
|
+
readonly field: PredicateFieldRef;
|
|
63
|
+
readonly values: readonly PredicateValue[];
|
|
64
|
+
readonly negate?: true;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "isNull";
|
|
67
|
+
readonly field: PredicateFieldRef;
|
|
68
|
+
readonly negate?: true;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "and";
|
|
71
|
+
readonly operands: readonly PredicateIR[];
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: "or";
|
|
74
|
+
readonly operands: readonly PredicateIR[];
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "not";
|
|
77
|
+
readonly operand: PredicateIR;
|
|
78
|
+
};
|
|
79
|
+
/** Narrow a predicate operand to a field reference. */
|
|
80
|
+
export declare function isPredicateFieldRef(operand: PredicateOperand): operand is PredicateFieldRef;
|
|
81
|
+
/**
|
|
82
|
+
* Every LOGICAL field name the predicate reads, in first-seen order.
|
|
83
|
+
*
|
|
84
|
+
* Used by validation ("does the model declare these?") and by any consumer that
|
|
85
|
+
* needs to know which columns an expression depends on without rendering it.
|
|
86
|
+
*/
|
|
87
|
+
export declare function predicateFieldNames(params: {
|
|
88
|
+
predicate: PredicateIR;
|
|
89
|
+
}): readonly string[];
|
|
90
|
+
/**
|
|
91
|
+
* A stable, DIALECT-FREE key for a predicate.
|
|
92
|
+
*
|
|
93
|
+
* Two predicates share a key exactly when they are structurally identical. The
|
|
94
|
+
* DSL uses it to tell a partial index from a total one over the same columns —
|
|
95
|
+
* which are different database objects — without rendering SQL, because index
|
|
96
|
+
* planning happens before a provider is known.
|
|
97
|
+
*
|
|
98
|
+
* It is NOT a semantic equivalence test: `a AND b` and `b AND a` get different
|
|
99
|
+
* keys, deliberately. Guessing SQL equivalence is what constitution rule 4
|
|
100
|
+
* forbids and what EPIC 1's live normalization exists for.
|
|
101
|
+
*/
|
|
102
|
+
export declare function predicateKey(params: {
|
|
103
|
+
predicate: PredicateIR;
|
|
104
|
+
}): string;
|
|
105
|
+
//# sourceMappingURL=predicate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../src/predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,4EAA4E;AAC5E,MAAM,MAAM,qBAAqB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9E,iFAAiF;AACjF,eAAO,MAAM,wBAAwB,EAAE,SAAS,qBAAqB,EAOpE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC3C,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAIlE;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GACnB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CA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.ts","sourceRoot":"","sources":["../src/reserved.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAmBpD,CAAC;AAIF,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"reserved.d.ts","sourceRoot":"","sources":["../src/reserved.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAmBpD,CAAC;AAIF,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAiBlD,CAAC;AAIF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAkB,CAAC;AAIxD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAExE;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAGtE"}
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAU,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASrE,MAAM,MAAM,eAAe,GAAG;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAMF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAkFhD,CAAC;AAmEF,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GAAG,eAAe,EAAE,CAsOhF;AAwSD,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GAAG,IAAI,CAsDtE;AAkBD,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,eAAe,EAAE,CAepF;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CAC5B,GAAG,OAAO,CAQV"}
|