@drzl/validation-core 3.11.0 → 3.12.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.
- package/dist/index.cjs +14 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +14 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -84473,6 +84473,7 @@ module.exports = __toCommonJS(index_exports2);
|
|
|
84473
84473
|
// src/checks.ts
|
|
84474
84474
|
var COMPARISON = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*(>=|<=|<>|!=|>|<|=)\s*(.+?)\s*$/;
|
|
84475
84475
|
var IN_LIST = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s+IN\s*\((.+)\)\s*$/i;
|
|
84476
|
+
var LENGTH_OF = /^\s*(?:length|char_length)\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)\s*(>=|<=|<>|!=|>|<|=)\s*(\d+)\s*$/i;
|
|
84476
84477
|
function splitTopLevelAnd(expr) {
|
|
84477
84478
|
const parts = [];
|
|
84478
84479
|
let depth = 0;
|
|
@@ -84593,6 +84594,7 @@ function parseCheck(expression, name) {
|
|
|
84593
84594
|
const checks = [];
|
|
84594
84595
|
const sets = [];
|
|
84595
84596
|
const rows = [];
|
|
84597
|
+
const lengths = [];
|
|
84596
84598
|
for (const part of parts) {
|
|
84597
84599
|
const parsed = parseCheck(part, name);
|
|
84598
84600
|
if (!parsed.ok)
|
|
@@ -84600,12 +84602,23 @@ function parseCheck(expression, name) {
|
|
|
84600
84602
|
checks.push(...parsed.checks);
|
|
84601
84603
|
if (parsed.sets) sets.push(...parsed.sets);
|
|
84602
84604
|
if (parsed.rows) rows.push(...parsed.rows);
|
|
84605
|
+
if (parsed.lengths) lengths.push(...parsed.lengths);
|
|
84603
84606
|
}
|
|
84604
84607
|
return {
|
|
84605
84608
|
ok: true,
|
|
84606
84609
|
checks,
|
|
84607
84610
|
...sets.length ? { sets } : {},
|
|
84608
|
-
...rows.length ? { rows } : {}
|
|
84611
|
+
...rows.length ? { rows } : {},
|
|
84612
|
+
...lengths.length ? { lengths } : {}
|
|
84613
|
+
};
|
|
84614
|
+
}
|
|
84615
|
+
const lengthOf = expr.match(LENGTH_OF);
|
|
84616
|
+
if (lengthOf) {
|
|
84617
|
+
const op4 = lengthOf[2] === "!=" ? "<>" : lengthOf[2];
|
|
84618
|
+
return {
|
|
84619
|
+
ok: true,
|
|
84620
|
+
checks: [],
|
|
84621
|
+
lengths: [{ column: lengthOf[1], operator: op4, value: lengthOf[3], name }]
|
|
84609
84622
|
};
|
|
84610
84623
|
}
|
|
84611
84624
|
const inList = expr.match(IN_LIST);
|
package/dist/index.d.cts
CHANGED
|
@@ -230,12 +230,27 @@ interface RowCheck {
|
|
|
230
230
|
operator: ColumnCheck['operator'];
|
|
231
231
|
name?: string;
|
|
232
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* A constraint on a column's *character* count, from `CHECK (length(name) > 3)`.
|
|
235
|
+
*
|
|
236
|
+
* Kept apart from `ColumnCheck` because it is not a comparison of the value: it compares a count
|
|
237
|
+
* derived from it, and the count Postgres takes is code points rather than UTF-16 units. See
|
|
238
|
+
* `CODEPOINT_LENGTH` for why that distinction is load bearing.
|
|
239
|
+
*/
|
|
240
|
+
interface LengthCheck {
|
|
241
|
+
column: string;
|
|
242
|
+
operator: ColumnCheck['operator'];
|
|
243
|
+
/** Decimal, as text, matching how the other bounds are carried. */
|
|
244
|
+
value: string;
|
|
245
|
+
name?: string;
|
|
246
|
+
}
|
|
233
247
|
/** A check that was understood, or the reason it was not. */
|
|
234
248
|
type ParsedCheck = {
|
|
235
249
|
ok: true;
|
|
236
250
|
checks: ColumnCheck[];
|
|
237
251
|
sets?: ColumnSet[];
|
|
238
252
|
rows?: RowCheck[];
|
|
253
|
+
lengths?: LengthCheck[];
|
|
239
254
|
} | {
|
|
240
255
|
ok: false;
|
|
241
256
|
reason: string;
|
|
@@ -433,4 +448,4 @@ declare function updateColumns(table: Table): Column[];
|
|
|
433
448
|
declare function selectColumns(table: Table): Column[];
|
|
434
449
|
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
435
450
|
|
|
436
|
-
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, CODEPOINT_LENGTH, COLUMN_FORMATS, type ColumnCheck, type ColumnSet, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ParsedCheck, type ResolvedAffix, type RowCheck, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, describeSet, formatCode, importSpecifier, insertColumns, isGeneratedColumn, isIntegerColumn, moduleFileName, moduleSpecifier, parseCheck, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
|
451
|
+
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, CODEPOINT_LENGTH, COLUMN_FORMATS, type ColumnCheck, type ColumnSet, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, type LengthCheck, NAME_MODES, type NameMode, type ParsedCheck, type ResolvedAffix, type RowCheck, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, describeSet, formatCode, importSpecifier, insertColumns, isGeneratedColumn, isIntegerColumn, moduleFileName, moduleSpecifier, parseCheck, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
package/dist/index.d.ts
CHANGED
|
@@ -230,12 +230,27 @@ interface RowCheck {
|
|
|
230
230
|
operator: ColumnCheck['operator'];
|
|
231
231
|
name?: string;
|
|
232
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* A constraint on a column's *character* count, from `CHECK (length(name) > 3)`.
|
|
235
|
+
*
|
|
236
|
+
* Kept apart from `ColumnCheck` because it is not a comparison of the value: it compares a count
|
|
237
|
+
* derived from it, and the count Postgres takes is code points rather than UTF-16 units. See
|
|
238
|
+
* `CODEPOINT_LENGTH` for why that distinction is load bearing.
|
|
239
|
+
*/
|
|
240
|
+
interface LengthCheck {
|
|
241
|
+
column: string;
|
|
242
|
+
operator: ColumnCheck['operator'];
|
|
243
|
+
/** Decimal, as text, matching how the other bounds are carried. */
|
|
244
|
+
value: string;
|
|
245
|
+
name?: string;
|
|
246
|
+
}
|
|
233
247
|
/** A check that was understood, or the reason it was not. */
|
|
234
248
|
type ParsedCheck = {
|
|
235
249
|
ok: true;
|
|
236
250
|
checks: ColumnCheck[];
|
|
237
251
|
sets?: ColumnSet[];
|
|
238
252
|
rows?: RowCheck[];
|
|
253
|
+
lengths?: LengthCheck[];
|
|
239
254
|
} | {
|
|
240
255
|
ok: false;
|
|
241
256
|
reason: string;
|
|
@@ -433,4 +448,4 @@ declare function updateColumns(table: Table): Column[];
|
|
|
433
448
|
declare function selectColumns(table: Table): Column[];
|
|
434
449
|
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
435
450
|
|
|
436
|
-
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, CODEPOINT_LENGTH, COLUMN_FORMATS, type ColumnCheck, type ColumnSet, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ParsedCheck, type ResolvedAffix, type RowCheck, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, describeSet, formatCode, importSpecifier, insertColumns, isGeneratedColumn, isIntegerColumn, moduleFileName, moduleSpecifier, parseCheck, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
|
451
|
+
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, CODEPOINT_LENGTH, COLUMN_FORMATS, type ColumnCheck, type ColumnSet, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, type LengthCheck, NAME_MODES, type NameMode, type ParsedCheck, type ResolvedAffix, type RowCheck, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, describeSet, formatCode, importSpecifier, insertColumns, isGeneratedColumn, isIntegerColumn, moduleFileName, moduleSpecifier, parseCheck, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import "./chunk-ZZGILH5A.js";
|
|
|
3
3
|
// src/checks.ts
|
|
4
4
|
var COMPARISON = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*(>=|<=|<>|!=|>|<|=)\s*(.+?)\s*$/;
|
|
5
5
|
var IN_LIST = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s+IN\s*\((.+)\)\s*$/i;
|
|
6
|
+
var LENGTH_OF = /^\s*(?:length|char_length)\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)\s*(>=|<=|<>|!=|>|<|=)\s*(\d+)\s*$/i;
|
|
6
7
|
function splitTopLevelAnd(expr) {
|
|
7
8
|
const parts = [];
|
|
8
9
|
let depth = 0;
|
|
@@ -123,6 +124,7 @@ function parseCheck(expression, name) {
|
|
|
123
124
|
const checks = [];
|
|
124
125
|
const sets = [];
|
|
125
126
|
const rows = [];
|
|
127
|
+
const lengths = [];
|
|
126
128
|
for (const part of parts) {
|
|
127
129
|
const parsed = parseCheck(part, name);
|
|
128
130
|
if (!parsed.ok)
|
|
@@ -130,12 +132,23 @@ function parseCheck(expression, name) {
|
|
|
130
132
|
checks.push(...parsed.checks);
|
|
131
133
|
if (parsed.sets) sets.push(...parsed.sets);
|
|
132
134
|
if (parsed.rows) rows.push(...parsed.rows);
|
|
135
|
+
if (parsed.lengths) lengths.push(...parsed.lengths);
|
|
133
136
|
}
|
|
134
137
|
return {
|
|
135
138
|
ok: true,
|
|
136
139
|
checks,
|
|
137
140
|
...sets.length ? { sets } : {},
|
|
138
|
-
...rows.length ? { rows } : {}
|
|
141
|
+
...rows.length ? { rows } : {},
|
|
142
|
+
...lengths.length ? { lengths } : {}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const lengthOf = expr.match(LENGTH_OF);
|
|
146
|
+
if (lengthOf) {
|
|
147
|
+
const op2 = lengthOf[2] === "!=" ? "<>" : lengthOf[2];
|
|
148
|
+
return {
|
|
149
|
+
ok: true,
|
|
150
|
+
checks: [],
|
|
151
|
+
lengths: [{ column: lengthOf[1], operator: op2, value: lengthOf[3], name }]
|
|
139
152
|
};
|
|
140
153
|
}
|
|
141
154
|
const inList = expr.match(IN_LIST);
|