@drzl/validation-core 3.9.0 → 3.11.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 CHANGED
@@ -84441,6 +84441,7 @@ ${codeblock}`, options7);
84441
84441
  var index_exports2 = {};
84442
84442
  __export(index_exports2, {
84443
84443
  AFFIX_PROBE_TABLE: () => AFFIX_PROBE_TABLE,
84444
+ CODEPOINT_LENGTH: () => CODEPOINT_LENGTH,
84444
84445
  COLUMN_FORMATS: () => COLUMN_FORMATS,
84445
84446
  DEFAULT_IMPORT_EXTENSION: () => DEFAULT_IMPORT_EXTENSION,
84446
84447
  DEFAULT_MODE_PREFIX: () => DEFAULT_MODE_PREFIX,
@@ -84825,6 +84826,7 @@ var COLUMN_FORMATS = {
84825
84826
  // probes, `1_000` and `0xDEAD_beef` through to `1__0`, `_1`, `0x` and `1e+`.
84826
84827
  numeric: "^\\s*([+-]?(0[xX][0-9a-fA-F](_?[0-9a-fA-F])*|0[oO][0-7](_?[0-7])*|0[bB][01](_?[01])*)|[+-]?(\\d(_?\\d)*(\\.(\\d(_?\\d)*)?)?|\\.\\d(_?\\d)*)([eE][+-]?\\d(_?\\d)*)?|[+-]?(NaN|Infinity))\\s*$"
84827
84828
  };
84829
+ var CODEPOINT_LENGTH = "[...v].length";
84828
84830
  function isIntegerColumn(c5) {
84829
84831
  if (typeof c5.integer === "boolean") return c5.integer;
84830
84832
  return c5.dbType === "INTEGER" || c5.min !== void 0 && c5.max !== void 0;
@@ -84867,6 +84869,7 @@ async function formatCode(code, filePath, fmt) {
84867
84869
  // Annotate the CommonJS export names for ESM import in node:
84868
84870
  0 && (module.exports = {
84869
84871
  AFFIX_PROBE_TABLE,
84872
+ CODEPOINT_LENGTH,
84870
84873
  COLUMN_FORMATS,
84871
84874
  DEFAULT_IMPORT_EXTENSION,
84872
84875
  DEFAULT_MODE_PREFIX,
package/dist/index.d.cts CHANGED
@@ -314,6 +314,21 @@ interface ValidationGenerateOptions {
314
314
  * `.pipe()` to every field, which is noise unless you use `.$type<T>()`.
315
315
  */
316
316
  typedColumns?: boolean;
317
+ /**
318
+ * Reproduce literal column defaults in the insert schema, so parsing fills them in.
319
+ *
320
+ * Off by default because it changes what parsing *returns*: `parse({})` on a table with
321
+ * `country: text().default('GB')` yields `{ country: 'GB' }` rather than `{}`. That is usually
322
+ * what you want from a schema that models the row, but it is a change in behaviour rather than
323
+ * only in strictness, so it is asked for rather than assumed.
324
+ *
325
+ * Only literal defaults are reproduced. `defaultNow()`, `defaultRandom()` and any `sql` default
326
+ * are evaluated by the database, and `$defaultFn` is called by Drizzle at insert time; a schema
327
+ * that guessed at any of them would produce a different value than the one actually stored.
328
+ *
329
+ * `drizzle-orm/zod` reproduces none of them, literal or otherwise.
330
+ */
331
+ applyDefaults?: boolean;
317
332
  format?: FormatOptions;
318
333
  /**
319
334
  * What every generated file is called after the Drizzle export name, e.g. `.zod.ts`
@@ -390,10 +405,32 @@ declare function isGeneratedColumn(c: Column, _primaryKeyColumns?: string[]): bo
390
405
  * cidr parses as `inet` and then demands zero host bits, which no regex can state
391
406
  */
392
407
  declare const COLUMN_FORMATS: Record<string, string>;
408
+ /**
409
+ * Why a character limit is not `.max(n)`.
410
+ *
411
+ * Postgres and MySQL count `varchar(n)` in **characters**; every JavaScript validator counts
412
+ * `.length`, which is UTF-16 code units. They agree until the text leaves the basic plane, and
413
+ * then they do not: `varchar(10)` accepts ten emoji, and `.max(10)` refuses eight of them.
414
+ *
415
+ * Verified against Postgres through PGlite, for `varchar(10)`:
416
+ *
417
+ * 3 emoji db accepts .max(10) accepts
418
+ * 8 emoji db accepts .max(10) REFUSES
419
+ * 10 emoji db accepts .max(10) REFUSES
420
+ * 11 emoji db refuses .max(10) refuses
421
+ *
422
+ * `[...v].length` counts code points, which is what the database counts, and matches on all four.
423
+ * Refusing a user's emoji is the failure mode this avoids, and it is the same rule applied
424
+ * everywhere else here: never reject what the database accepts.
425
+ *
426
+ * `@sinclair/typebox` and ArkType cannot express it. Both state a length declaratively with no
427
+ * predicate to hook, so they keep the UTF-16 form and are documented as approximate.
428
+ */
429
+ declare const CODEPOINT_LENGTH = "[...v].length";
393
430
  declare function isIntegerColumn(c: Column): boolean;
394
431
  declare function insertColumns(table: Table): Column[];
395
432
  declare function updateColumns(table: Table): Column[];
396
433
  declare function selectColumns(table: Table): Column[];
397
434
  declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
398
435
 
399
- export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -314,6 +314,21 @@ interface ValidationGenerateOptions {
314
314
  * `.pipe()` to every field, which is noise unless you use `.$type<T>()`.
315
315
  */
316
316
  typedColumns?: boolean;
317
+ /**
318
+ * Reproduce literal column defaults in the insert schema, so parsing fills them in.
319
+ *
320
+ * Off by default because it changes what parsing *returns*: `parse({})` on a table with
321
+ * `country: text().default('GB')` yields `{ country: 'GB' }` rather than `{}`. That is usually
322
+ * what you want from a schema that models the row, but it is a change in behaviour rather than
323
+ * only in strictness, so it is asked for rather than assumed.
324
+ *
325
+ * Only literal defaults are reproduced. `defaultNow()`, `defaultRandom()` and any `sql` default
326
+ * are evaluated by the database, and `$defaultFn` is called by Drizzle at insert time; a schema
327
+ * that guessed at any of them would produce a different value than the one actually stored.
328
+ *
329
+ * `drizzle-orm/zod` reproduces none of them, literal or otherwise.
330
+ */
331
+ applyDefaults?: boolean;
317
332
  format?: FormatOptions;
318
333
  /**
319
334
  * What every generated file is called after the Drizzle export name, e.g. `.zod.ts`
@@ -390,10 +405,32 @@ declare function isGeneratedColumn(c: Column, _primaryKeyColumns?: string[]): bo
390
405
  * cidr parses as `inet` and then demands zero host bits, which no regex can state
391
406
  */
392
407
  declare const COLUMN_FORMATS: Record<string, string>;
408
+ /**
409
+ * Why a character limit is not `.max(n)`.
410
+ *
411
+ * Postgres and MySQL count `varchar(n)` in **characters**; every JavaScript validator counts
412
+ * `.length`, which is UTF-16 code units. They agree until the text leaves the basic plane, and
413
+ * then they do not: `varchar(10)` accepts ten emoji, and `.max(10)` refuses eight of them.
414
+ *
415
+ * Verified against Postgres through PGlite, for `varchar(10)`:
416
+ *
417
+ * 3 emoji db accepts .max(10) accepts
418
+ * 8 emoji db accepts .max(10) REFUSES
419
+ * 10 emoji db accepts .max(10) REFUSES
420
+ * 11 emoji db refuses .max(10) refuses
421
+ *
422
+ * `[...v].length` counts code points, which is what the database counts, and matches on all four.
423
+ * Refusing a user's emoji is the failure mode this avoids, and it is the same rule applied
424
+ * everywhere else here: never reject what the database accepts.
425
+ *
426
+ * `@sinclair/typebox` and ArkType cannot express it. Both state a length declaratively with no
427
+ * predicate to hook, so they keep the UTF-16 form and are documented as approximate.
428
+ */
429
+ declare const CODEPOINT_LENGTH = "[...v].length";
393
430
  declare function isIntegerColumn(c: Column): boolean;
394
431
  declare function insertColumns(table: Table): Column[];
395
432
  declare function updateColumns(table: Table): Column[];
396
433
  declare function selectColumns(table: Table): Column[];
397
434
  declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
398
435
 
399
- export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, 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 };
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 };
package/dist/index.js CHANGED
@@ -356,6 +356,7 @@ var COLUMN_FORMATS = {
356
356
  // probes, `1_000` and `0xDEAD_beef` through to `1__0`, `_1`, `0x` and `1e+`.
357
357
  numeric: "^\\s*([+-]?(0[xX][0-9a-fA-F](_?[0-9a-fA-F])*|0[oO][0-7](_?[0-7])*|0[bB][01](_?[01])*)|[+-]?(\\d(_?\\d)*(\\.(\\d(_?\\d)*)?)?|\\.\\d(_?\\d)*)([eE][+-]?\\d(_?\\d)*)?|[+-]?(NaN|Infinity))\\s*$"
358
358
  };
359
+ var CODEPOINT_LENGTH = "[...v].length";
359
360
  function isIntegerColumn(c) {
360
361
  if (typeof c.integer === "boolean") return c.integer;
361
362
  return c.dbType === "INTEGER" || c.min !== void 0 && c.max !== void 0;
@@ -397,6 +398,7 @@ async function formatCode(code, filePath, fmt) {
397
398
  }
398
399
  export {
399
400
  AFFIX_PROBE_TABLE,
401
+ CODEPOINT_LENGTH,
400
402
  COLUMN_FORMATS,
401
403
  DEFAULT_IMPORT_EXTENSION,
402
404
  DEFAULT_MODE_PREFIX,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drzl/validation-core",
3
- "version": "3.9.0",
3
+ "version": "3.11.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "sideEffects": false,
13
13
  "dependencies": {
14
- "@drzl/analyzer": "^1.10.0"
14
+ "@drzl/analyzer": "^1.11.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "tsup": "^8.5.1",