@vibeorm/sql 5.8.0 → 5.10.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 (51) hide show
  1. package/README.md +1 -0
  2. package/dist/ast.d.ts +293 -9
  3. package/dist/codecs.d.ts +106 -12
  4. package/dist/composable.d.ts +44 -4
  5. package/dist/dialect.d.ts +30 -2
  6. package/dist/dialects/diagnostics.d.ts +1 -1
  7. package/dist/dialects/migration-inventory.d.ts +0 -11
  8. package/dist/dialects/migration-shadow-marker.d.ts +65 -0
  9. package/dist/dialects/mysql-generated-columns.d.ts +1 -5
  10. package/dist/dialects/mysql-index-expressions.d.ts +1 -19
  11. package/dist/dialects/mysql-row-rules.d.ts +1 -7
  12. package/dist/dialects/postgres-generated-columns.d.ts +0 -5
  13. package/dist/dialects/postgres-index-expressions.d.ts +1 -9
  14. package/dist/dialects/postgres-rls-readiness.d.ts +0 -2
  15. package/dist/dialects/postgres-rls.d.ts +7 -1
  16. package/dist/dialects/postgres-row-rules.d.ts +1 -24
  17. package/dist/dialects/sqlite-fts.d.ts +2 -2
  18. package/dist/dialects/sqlite-generated-columns.d.ts +1 -12
  19. package/dist/dialects/sqlite-index-expressions.d.ts +1 -22
  20. package/dist/dialects/sqlite-json-equality.d.ts +1 -14
  21. package/dist/dialects/sqlite-row-rules.d.ts +1 -7
  22. package/dist/dialects/sqlite-table-definition.d.ts +0 -19
  23. package/dist/dialects/test-databases.d.ts +96 -0
  24. package/dist/expr-fragment.d.ts +13 -0
  25. package/dist/identifiers.d.ts +1 -4
  26. package/dist/index-expressions.d.ts +8 -2
  27. package/dist/index.d.ts +16 -7
  28. package/dist/index.js +4148 -2762
  29. package/dist/index.js.map +49 -42
  30. package/dist/json-patch.d.ts +82 -0
  31. package/dist/json-path.d.ts +2 -0
  32. package/dist/key-list.d.ts +0 -21
  33. package/dist/native-types.d.ts +72 -0
  34. package/dist/params.d.ts +0 -2
  35. package/dist/query/expressions.d.ts +1 -33
  36. package/dist/query/index.js.map +7 -7
  37. package/dist/query/mutations.d.ts +1 -14
  38. package/dist/query/reusable.d.ts +1 -16
  39. package/dist/query/select.d.ts +1 -10
  40. package/dist/query/sources.d.ts +1 -36
  41. package/dist/query/state.d.ts +1 -77
  42. package/dist/query-plan.d.ts +2 -2
  43. package/dist/render.d.ts +9 -0
  44. package/dist/result-decoder.d.ts +21 -1
  45. package/dist/row-rules.d.ts +1 -19
  46. package/dist/sql-bindings.d.ts +7 -43
  47. package/dist/sql-handles.d.ts +1 -3
  48. package/dist/sql-input.d.ts +8 -24
  49. package/dist/timestamp-identity.d.ts +6 -12
  50. package/dist/timestamp-text.d.ts +36 -0
  51. package/package.json +2 -2
@@ -0,0 +1,82 @@
1
+ /**
2
+ * JSON key-level update: an ordered list of `set` / `remove` steps applied to
3
+ * ONE Json column in ONE assignment, without reading the document first.
4
+ *
5
+ * Semantics (identical on every dialect):
6
+ * - `set` replaces or adds the member at its path and creates missing
7
+ * intermediate objects; a SQL NULL column starts from `{}`.
8
+ * - `remove` deletes the member; an absent member (or an absent container on
9
+ * the way) is a no-op, and a SQL NULL column stays NULL.
10
+ * - Every container a step passes through must be an object or absent. An
11
+ * array, a scalar or JSON `null` there refuses the write.
12
+ *
13
+ * The steps are folded at build time into one write tree, so the SQL reads
14
+ * only the ORIGINAL column, never an earlier step's result: its text grows
15
+ * linearly with the steps. A container whose value an earlier `set` wrote is
16
+ * known here and checked in JavaScript ({@link planJsonPatch} reports the
17
+ * conflict before any SQL); every other container is checked in the statement
18
+ * against the original document, and a failed check fails the statement on
19
+ * purpose with a marker the client maps back to a typed error:
20
+ * `__vibe_veto:json_patch:<nonce>:<check index>:<found type>`.
21
+ */
22
+ /** One step of a JSON patch; `value` is the JSON text the Json codec wrote. */
23
+ export type JsonPatchStep = {
24
+ readonly set: readonly string[];
25
+ readonly value: string;
26
+ } | {
27
+ readonly remove: readonly string[];
28
+ };
29
+ /**
30
+ * An UPDATE set value that patches a Json column in place. Recognised
31
+ * structurally inside `UpdateStatement.set` and conflict updates, with the
32
+ * same discipline as the other set markers: the Json codec stringifies JSON
33
+ * payloads before they reach the AST, so a document is never mistaken for it.
34
+ */
35
+ export type JsonPatchOperation = {
36
+ readonly __jsonPatch: true;
37
+ readonly steps: readonly JsonPatchStep[];
38
+ /** Per-call value bound into the refusal marker; the client maps only the markers it issued. */
39
+ readonly nonce: string;
40
+ /** `json` for a postgres `json` column (`Json @db.Json`): patched through jsonb, stored as json. */
41
+ readonly storage?: "json";
42
+ };
43
+ /** Narrow an UPDATE set value to a {@link JsonPatchOperation}. */
44
+ export declare function isJsonPatchOperation(value: unknown): value is JsonPatchOperation;
45
+ /** JSON types a container can hold instead of an object. */
46
+ export type JsonPatchFoundType = "array" | "string" | "number" | "boolean" | "null";
47
+ /** A container of the ORIGINAL document that must be an object or absent; `step` is the first step that passes through it. */
48
+ export type JsonPatchCheck = {
49
+ readonly path: readonly string[];
50
+ readonly step: number;
51
+ };
52
+ /** A step that passes through a non-object value an earlier `set` of the same patch wrote. */
53
+ export type JsonPatchConflict = {
54
+ readonly step: number;
55
+ readonly path: readonly string[];
56
+ readonly found: JsonPatchFoundType;
57
+ };
58
+ /** {@link planJsonPatch}: the in-statement checks in render order, or the conflict known before any SQL. */
59
+ export type JsonPatchPlan = {
60
+ readonly checks: readonly JsonPatchCheck[];
61
+ } | {
62
+ readonly conflict: JsonPatchConflict;
63
+ };
64
+ /**
65
+ * Fold a patch's steps: the checks the statement runs on the original
66
+ * document (index = the check index its refusal marker carries), or the
67
+ * conflict an earlier `set` of the same patch makes certain.
68
+ */
69
+ export declare function planJsonPatch(params: {
70
+ steps: readonly JsonPatchStep[];
71
+ }): JsonPatchPlan;
72
+ /** A refusal marker found in a database error message: the nonce, the check index, and the container's type as the database spelled it. */
73
+ export type JsonPatchVeto = {
74
+ readonly nonce: string;
75
+ readonly check: number;
76
+ readonly found: string;
77
+ };
78
+ /** The JSON patch refusal a database error message quotes, or `undefined`. */
79
+ export declare function jsonPatchVetoOf(params: {
80
+ message: string;
81
+ }): JsonPatchVeto | undefined;
82
+ //# sourceMappingURL=json-patch.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json-path.d.ts.map
@@ -26,17 +26,6 @@ export declare function postgresKeyListElementTypeOf(params: {
26
26
  dialect: SqlDialect;
27
27
  member: KeyListMember;
28
28
  }): string | undefined;
29
- /**
30
- * The postgres element type a key-list member's array binds as
31
- * (`$n::<type>[]`), derived from the column's declared type facts.
32
- *
33
- * @throws VibeError `VIBE_UNSUPPORTED_CAPABILITY` for a member whose type has
34
- * no equality a key can use (Json) or a native type this list does not know.
35
- */
36
- export declare function postgresKeyListElementType(params: {
37
- dialect: SqlDialect;
38
- member: KeyListMember;
39
- }): string;
40
29
  /**
41
30
  * Whether a key list must bind its rows as a row-value list of UNTYPED
42
31
  * parameters, `(a, b) IN (($1, $2), …)`, instead of typed arrays on the
@@ -70,14 +59,4 @@ export declare function postgresBulkInsertArrayCastOf(params: {
70
59
  dialect: SqlDialect;
71
60
  member: KeyListMember;
72
61
  }): string | undefined;
73
- /**
74
- * The throwing form of {@link postgresBulkInsertArrayCastOf}, for the renderer.
75
- *
76
- * @throws VibeError `VIBE_UNSUPPORTED_CAPABILITY` for a native type the
77
- * bulk-insert form does not know.
78
- */
79
- export declare function postgresBulkInsertArrayCast(params: {
80
- dialect: SqlDialect;
81
- member: KeyListMember;
82
- }): string;
83
62
  //# sourceMappingURL=key-list.d.ts.map
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Column types per dialect: the type migrate creates for a scalar field, in
3
+ * the spelling it compares types by. ONE rule, read by migrate's differ and by
4
+ * the runtime's `describeSchema`, so two fields that describe the same type
5
+ * are two columns migrate would never ALTER into each other.
6
+ *
7
+ * A field without a native type gets its scalar's column type
8
+ * (dialect-matrix §2). A declared `@db.*` type replaces it on PostgreSQL and
9
+ * MySQL unless it IS that type spelled another way. SQLite stores every column
10
+ * by its scalar's storage class and ignores native types.
11
+ */
12
+ import type { Dialect, ScalarType } from "@vibeorm/schema";
13
+ /** IR scalar → the PostgreSQL column type migrate creates. */
14
+ export declare const POSTGRES_SCALAR_COLUMN_TYPES: Readonly<Record<ScalarType, string>>;
15
+ /** IR scalar → the MySQL column type migrate creates (information_schema spelling). */
16
+ export declare const MYSQL_SCALAR_COLUMN_TYPES: Readonly<Record<ScalarType, string>>;
17
+ /** IR scalar → the SQLite storage class migrate declares. */
18
+ export declare const SQLITE_SCALAR_STORAGE_CLASSES: Readonly<Record<ScalarType, string>>;
19
+ /**
20
+ * Alias map applied to the base name of a native type (everything before the
21
+ * parenthesized modifier) so that schema-declared `@db.*` spellings and
22
+ * catalog-reported names compare equal.
23
+ */
24
+ export declare const POSTGRES_NATIVE_ALIASES: Readonly<Record<string, string>>;
25
+ /**
26
+ * Normalize a PostgreSQL type string for comparison: lowercase, whitespace
27
+ * stripped, base name de-aliased. `"VarChar(191)"` and `"character
28
+ * varying(191)"` both become `"varchar(191)"`.
29
+ */
30
+ export declare function normalizePostgresNativeType(params: {
31
+ readonly raw: string;
32
+ }): string;
33
+ /**
34
+ * Native spellings an explicit declaration compares EQUAL to its scalar's
35
+ * column type without being it: `@db.Timestamptz(6)` is bare `timestamptz`
36
+ * spelled out. Nothing grandfathered: `timestamptz(3)` stays its own type.
37
+ */
38
+ export declare const POSTGRES_EXACT_EQUIVALENTS: Readonly<Partial<Record<ScalarType, readonly string[]>>>;
39
+ /**
40
+ * Normalize a MySQL type string for comparison: lowercase, whitespace
41
+ * stripped, base de-aliased, integer display widths dropped (MySQL 8.0.19+
42
+ * omits them; older catalogs report `int(11)`) — EXCEPT `tinyint(1)`, which is
43
+ * the Boolean marker and must survive normalization. A zero fractional
44
+ * precision on a temporal type is dropped: the catalog reports
45
+ * `datetime(0)` as `datetime`.
46
+ */
47
+ export declare function normalizeMysqlNativeType(params: {
48
+ readonly raw: string;
49
+ }): string;
50
+ /**
51
+ * The column type migrate creates for a scalar field on `dialect`, in the
52
+ * spelling it compares types by (an explicit declaration's exact comparison):
53
+ * the same answer for two fields means the same column type. `nativeType` is
54
+ * the field's declared `@db.*` text; for a list field the answer is the
55
+ * element type.
56
+ *
57
+ * - PostgreSQL: `String` and `String @db.Text` are `"text"`; `Int`,
58
+ * `@db.Int4` and `@db.Integer` are `"integer"`; `Float` and
59
+ * `@db.DoublePrecision` are `"doubleprecision"`; `DateTime` and
60
+ * `@db.Timestamptz(6)` are `"timestamptz"`, while `@db.Timestamptz(3)` is
61
+ * `"timestamptz(3)"`.
62
+ * - MySQL: `String` is `"varchar(191)"`, `Boolean` `"tinyint(1)"`, display
63
+ * widths dropped (`int(11)` is `"int"`).
64
+ * - SQLite: the storage class (`"TEXT"`, `"INTEGER"`, `"REAL"`, `"BLOB"`);
65
+ * a native type changes nothing there.
66
+ */
67
+ export declare function canonicalColumnType(params: {
68
+ readonly dialect: Dialect;
69
+ readonly scalar: ScalarType;
70
+ readonly nativeType?: string | undefined;
71
+ }): string;
72
+ //# sourceMappingURL=native-types.d.ts.map
package/dist/params.d.ts CHANGED
@@ -4,8 +4,6 @@ export declare class ParamCollector {
4
4
  private reserved;
5
5
  readonly values: unknown[];
6
6
  constructor(dialect: SqlDialect);
7
- /** @internal Allocate recorded positions without inserting sample values. */
8
- reserve(): string;
9
7
  /** Actual positional slots, including repeats of a named input. */
10
8
  count(): number;
11
9
  /** Register one value; ordinary and reusable paths share transport spelling. */
@@ -1,36 +1,4 @@
1
- import type { ResultDecoder, ResultReadDecoder, SqlFragment, SqlInputContract } from "@vibeorm/sql";
2
- import type { ColumnDefinition, Expression, Expressions } from "./types.ts";
3
- import type { RenderContext } from "./state.ts";
4
- export declare function nullableDecoder<T>(decoder: ResultReadDecoder<T>): ResultReadDecoder<T | null>;
5
- export declare function assertDecoder(decoder: ResultReadDecoder<unknown>): void;
6
- /** Keep physical native refinements in the central codec implementations. */
7
- export declare function nativeColumnDefinition(definition: ColumnDefinition<unknown>): ColumnDefinition<unknown>;
8
- /** Transport conversion belongs only at the final result boundary. */
9
- export declare function transportProjection(params: {
10
- context: RenderContext;
11
- expression: string;
12
- definition: ColumnDefinition<unknown>;
13
- }): string;
14
- /** Write contracts carry encoding identity independently from projection output. */
15
- export declare function columnInputContract(definition: ColumnDefinition<unknown>): SqlInputContract;
16
- export declare function bindColumnValue(params: {
17
- context: RenderContext;
18
- definition: ColumnDefinition<unknown>;
19
- value: unknown;
20
- encoder?: ResultDecoder<unknown>;
21
- rejectNull?: boolean;
22
- }): string;
23
- /** Construct a typed value for the public qb.value contract. */
24
- export declare function literal<T>(params: {
25
- value: T;
26
- decoder: ResultDecoder<T>;
27
- }): Expression<T>;
28
- /** Construct an explicit fragment projection for the public qb.raw contract. */
29
- export declare function rawExpression<T>(params: {
30
- sql: SqlFragment;
31
- decoder: ResultReadDecoder<T>;
32
- references?: readonly Expression<unknown>[];
33
- }): Expression<T>;
1
+ import type { Expressions } from "./types.ts";
34
2
  /** Compare typed operands for equality, preserving SQL NULL propagation. */
35
3
  export declare const eq: Expressions["eq"];
36
4
  /** Compare typed operands for inequality. */