@vibeorm/sql 5.7.0 → 5.9.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/README.md +1 -0
- package/dist/ast.d.ts +174 -6
- package/dist/dialect.d.ts +6 -1
- package/dist/dialects/diagnostics.d.ts +1 -1
- package/dist/dialects/migration-shadow-marker.d.ts +65 -0
- package/dist/dialects/postgres-index-expressions.d.ts +3 -1
- package/dist/dialects/sqlite-index-expressions.d.ts +3 -1
- package/dist/index-expressions.d.ts +8 -2
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1095 -389
- package/dist/index.js.map +18 -14
- package/dist/json-patch.d.ts +96 -0
- package/dist/json-path.d.ts +3 -0
- package/dist/native-types.d.ts +70 -0
- package/dist/render.d.ts +9 -0
- package/dist/result-decoder.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import type { SqlDialect } from "./dialect.ts";
|
|
23
|
+
import type { ParamCollector } from "./params.ts";
|
|
24
|
+
/** One step of a JSON patch; `value` is the JSON text the Json codec wrote. */
|
|
25
|
+
export type JsonPatchStep = {
|
|
26
|
+
readonly set: readonly string[];
|
|
27
|
+
readonly value: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly remove: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* An UPDATE set value that patches a Json column in place. Recognised
|
|
33
|
+
* structurally inside `UpdateStatement.set` and conflict updates, with the
|
|
34
|
+
* same discipline as the other set markers: the Json codec stringifies JSON
|
|
35
|
+
* payloads before they reach the AST, so a document is never mistaken for it.
|
|
36
|
+
*/
|
|
37
|
+
export type JsonPatchOperation = {
|
|
38
|
+
readonly __jsonPatch: true;
|
|
39
|
+
readonly steps: readonly JsonPatchStep[];
|
|
40
|
+
/** Per-call value bound into the refusal marker; the client maps only the markers it issued. */
|
|
41
|
+
readonly nonce: string;
|
|
42
|
+
/** `json` for a postgres `json` column (`Json @db.Json`): patched through jsonb, stored as json. */
|
|
43
|
+
readonly storage?: "json";
|
|
44
|
+
};
|
|
45
|
+
/** Narrow an UPDATE set value to a {@link JsonPatchOperation}. */
|
|
46
|
+
export declare function isJsonPatchOperation(value: unknown): value is JsonPatchOperation;
|
|
47
|
+
/** JSON types a container can hold instead of an object. */
|
|
48
|
+
export type JsonPatchFoundType = "array" | "string" | "number" | "boolean" | "null";
|
|
49
|
+
/** A container of the ORIGINAL document that must be an object or absent; `step` is the first step that passes through it. */
|
|
50
|
+
export type JsonPatchCheck = {
|
|
51
|
+
readonly path: readonly string[];
|
|
52
|
+
readonly step: number;
|
|
53
|
+
};
|
|
54
|
+
/** A step that passes through a non-object value an earlier `set` of the same patch wrote. */
|
|
55
|
+
export type JsonPatchConflict = {
|
|
56
|
+
readonly step: number;
|
|
57
|
+
readonly path: readonly string[];
|
|
58
|
+
readonly found: JsonPatchFoundType;
|
|
59
|
+
};
|
|
60
|
+
/** {@link planJsonPatch}: the in-statement checks in render order, or the conflict known before any SQL. */
|
|
61
|
+
export type JsonPatchPlan = {
|
|
62
|
+
readonly checks: readonly JsonPatchCheck[];
|
|
63
|
+
} | {
|
|
64
|
+
readonly conflict: JsonPatchConflict;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Fold a patch's steps: the checks the statement runs on the original
|
|
68
|
+
* document (index = the check index its refusal marker carries), or the
|
|
69
|
+
* conflict an earlier `set` of the same patch makes certain.
|
|
70
|
+
*/
|
|
71
|
+
export declare function planJsonPatch(params: {
|
|
72
|
+
steps: readonly JsonPatchStep[];
|
|
73
|
+
}): JsonPatchPlan;
|
|
74
|
+
/**
|
|
75
|
+
* The patched value of one Json column — `CASE WHEN <a container is not an
|
|
76
|
+
* object> THEN <fail on purpose> … ELSE <patched document> END` — where `read`
|
|
77
|
+
* is the column as the assignment reads it (qualified in a conflict update).
|
|
78
|
+
* Every placeholder is collected in text order.
|
|
79
|
+
*/
|
|
80
|
+
export declare function renderJsonPatch(params: {
|
|
81
|
+
dialect: SqlDialect;
|
|
82
|
+
patch: JsonPatchOperation;
|
|
83
|
+
read: string;
|
|
84
|
+
collector: ParamCollector;
|
|
85
|
+
}): string;
|
|
86
|
+
/** A refusal marker found in a database error message: the nonce, the check index, and the container's type as the database spelled it. */
|
|
87
|
+
export type JsonPatchVeto = {
|
|
88
|
+
readonly nonce: string;
|
|
89
|
+
readonly check: number;
|
|
90
|
+
readonly found: string;
|
|
91
|
+
};
|
|
92
|
+
/** The JSON patch refusal a database error message quotes, or `undefined`. */
|
|
93
|
+
export declare function jsonPatchVetoOf(params: {
|
|
94
|
+
message: string;
|
|
95
|
+
}): JsonPatchVeto | undefined;
|
|
96
|
+
//# sourceMappingURL=json-patch.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
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.
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeMysqlNativeType(params: {
|
|
46
|
+
readonly raw: string;
|
|
47
|
+
}): string;
|
|
48
|
+
/**
|
|
49
|
+
* The column type migrate creates for a scalar field on `dialect`, in the
|
|
50
|
+
* spelling it compares types by (an explicit declaration's exact comparison):
|
|
51
|
+
* the same answer for two fields means the same column type. `nativeType` is
|
|
52
|
+
* the field's declared `@db.*` text; for a list field the answer is the
|
|
53
|
+
* element type.
|
|
54
|
+
*
|
|
55
|
+
* - PostgreSQL: `String` and `String @db.Text` are `"text"`; `Int`,
|
|
56
|
+
* `@db.Int4` and `@db.Integer` are `"integer"`; `Float` and
|
|
57
|
+
* `@db.DoublePrecision` are `"doubleprecision"`; `DateTime` and
|
|
58
|
+
* `@db.Timestamptz(6)` are `"timestamptz"`, while `@db.Timestamptz(3)` is
|
|
59
|
+
* `"timestamptz(3)"`.
|
|
60
|
+
* - MySQL: `String` is `"varchar(191)"`, `Boolean` `"tinyint(1)"`, display
|
|
61
|
+
* widths dropped (`int(11)` is `"int"`).
|
|
62
|
+
* - SQLite: the storage class (`"TEXT"`, `"INTEGER"`, `"REAL"`, `"BLOB"`);
|
|
63
|
+
* a native type changes nothing there.
|
|
64
|
+
*/
|
|
65
|
+
export declare function canonicalColumnType(params: {
|
|
66
|
+
readonly dialect: Dialect;
|
|
67
|
+
readonly scalar: ScalarType;
|
|
68
|
+
readonly nativeType?: string | undefined;
|
|
69
|
+
}): string;
|
|
70
|
+
//# sourceMappingURL=native-types.d.ts.map
|
package/dist/render.d.ts
CHANGED
|
@@ -26,6 +26,15 @@ export declare function renderProjection(params: {
|
|
|
26
26
|
dialect: SqlDialect;
|
|
27
27
|
columns: readonly ColRef[];
|
|
28
28
|
}): string;
|
|
29
|
+
/**
|
|
30
|
+
* Are `sets` (indexes into `count` grouping keys) exactly the rollup chain
|
|
31
|
+
* `[0..n-1], [0..n-2], …, []`, in any order and with members in any order?
|
|
32
|
+
* The one shape a `rollup` dialect can group by (`GROUP BY … WITH ROLLUP`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function isRollupChain(params: {
|
|
35
|
+
count: number;
|
|
36
|
+
sets: readonly (readonly number[])[];
|
|
37
|
+
}): boolean;
|
|
29
38
|
/**
|
|
30
39
|
* Render one boolean expression into SQL text, collecting parameters into the
|
|
31
40
|
* shared collector. Public so extension delegates can AND user `where` trees
|
package/dist/result-decoder.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export declare const decode: {
|
|
|
53
53
|
readonly int: ResultDecoder<number>;
|
|
54
54
|
readonly float: ResultDecoder<number>;
|
|
55
55
|
readonly bigInt: ResultDecoder<bigint>;
|
|
56
|
+
/** A BigInt column as a safe `number`; a value beyond `Number.MAX_SAFE_INTEGER` refuses (`VIBE_DATA_INVALID` read, `VIBE_VALIDATION` write). */
|
|
57
|
+
readonly bigIntNumber: ResultDecoder<number>;
|
|
56
58
|
readonly decimal: ResultDecoder<string>;
|
|
57
59
|
readonly dateTime: ResultDecoder<Date>;
|
|
58
60
|
readonly extendedDateTime: ResultDecoder<ExtendedDateTime>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/sql",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"description": "Dialect-aware SQL layer for VibeORM v2 — SQL AST, renderers and capability tables for postgres, sqlite and mysql",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"bun": ">=1.2.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@vibeorm/schema": "^5.
|
|
53
|
+
"@vibeorm/schema": "^5.9.0"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|