@vibeorm/schema 2.3.0 → 2.4.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.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +301 -15
- package/dist/index.js.map +7 -6
- package/dist/physical-names.d.ts +119 -0
- package/dist/physical-names.d.ts.map +1 -0
- package/dist/prisma-literal.d.ts +13 -0
- package/dist/prisma-literal.d.ts.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default PHYSICAL identifier conventions (Prisma-compatible) — the names
|
|
3
|
+
* migrate mints when the schema does not declare one explicitly.
|
|
4
|
+
*
|
|
5
|
+
* ONE shared rule for every consumer (the m2m.ts precedent): the migration
|
|
6
|
+
* normalizer and the DDL renderers mint through these helpers, and
|
|
7
|
+
* identifier-length validation predicts the exact same names — so a name that
|
|
8
|
+
* validates is the name the database will actually be asked to create, and the
|
|
9
|
+
* formulas can never drift apart per consumer.
|
|
10
|
+
*
|
|
11
|
+
* Minted defaults are SHORTENED to the dialect's identifier limit with
|
|
12
|
+
* Prisma's own formula (`ConstraintNames`: keep the suffix, cut the
|
|
13
|
+
* `table_columns` prefix): a schema Prisma accepts must not be refused here,
|
|
14
|
+
* and a database Prisma migrated must upgrade with zero DDL. Only EXPLICIT
|
|
15
|
+
* names are refused when over the limit (validate.ts) — the author chose them
|
|
16
|
+
* and can shorten them, whereas PostgreSQL would silently truncate.
|
|
17
|
+
*/
|
|
18
|
+
import type { Dialect } from "./ir.ts";
|
|
19
|
+
/** How a dialect measures an identifier and where it stops honouring it. */
|
|
20
|
+
export type IdentifierLimit = {
|
|
21
|
+
/** Longest identifier the server keeps intact. */
|
|
22
|
+
readonly max: number;
|
|
23
|
+
/** postgres counts BYTES (NAMEDATALEN - 1); mysql counts CHARACTERS. */
|
|
24
|
+
readonly unit: "bytes" | "characters";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Per-dialect identifier limits. postgres silently TRUNCATES past 63 bytes (a
|
|
28
|
+
* NOTICE, not an error); mysql refuses past 64 characters (ER_TOO_LONG_IDENT);
|
|
29
|
+
* sqlite has no meaningful limit.
|
|
30
|
+
*/
|
|
31
|
+
export declare const IDENTIFIER_LIMITS: Readonly<Record<Dialect, IdentifierLimit | undefined>>;
|
|
32
|
+
/** The length of `name` in the dialect's unit (bytes on postgres, characters on mysql). */
|
|
33
|
+
export declare function identifierLength(params: {
|
|
34
|
+
name: string;
|
|
35
|
+
dialect: Dialect;
|
|
36
|
+
}): number;
|
|
37
|
+
/**
|
|
38
|
+
* Prisma's default-name shortening: the suffix (`_key`, `_idx`, `_fkey`,
|
|
39
|
+
* `_pkey`) always survives and the prefix is cut to fit the dialect's limit.
|
|
40
|
+
* Below the limit the name is exactly `prefix + suffix`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fitDefaultName(params: {
|
|
43
|
+
prefix: string;
|
|
44
|
+
suffix: string;
|
|
45
|
+
dialect: Dialect;
|
|
46
|
+
}): string;
|
|
47
|
+
/**
|
|
48
|
+
* Refuse an EXPLICIT physical identifier the dialect would corrupt or reject
|
|
49
|
+
* (`VIBE_SCHEMA_INVALID`) — for names minted outside IR validation, such as
|
|
50
|
+
* an extension's `columnName:` / `indexName:` overrides. Minted defaults go
|
|
51
|
+
* through {@link fitDefaultName} instead and never need this.
|
|
52
|
+
*/
|
|
53
|
+
export declare function assertIdentifierFits(params: {
|
|
54
|
+
name: string;
|
|
55
|
+
dialect: Dialect;
|
|
56
|
+
what: string;
|
|
57
|
+
remedy: string;
|
|
58
|
+
}): void;
|
|
59
|
+
/**
|
|
60
|
+
* Default index name: `Table_col1_col2_key` for a unique index,
|
|
61
|
+
* `Table_col1_col2_idx` otherwise, shortened to the dialect's limit.
|
|
62
|
+
* `columns` are PHYSICAL column names (`@map` already applied), in index order.
|
|
63
|
+
*/
|
|
64
|
+
export declare function defaultIndexName(params: {
|
|
65
|
+
table: string;
|
|
66
|
+
columns: readonly string[];
|
|
67
|
+
unique: boolean;
|
|
68
|
+
dialect: Dialect;
|
|
69
|
+
}): string;
|
|
70
|
+
/**
|
|
71
|
+
* Default foreign-key constraint name: `Table_col1_col2_fkey`, shortened to the
|
|
72
|
+
* dialect's limit. `columns` are the PHYSICAL FK column names on the owning
|
|
73
|
+
* table.
|
|
74
|
+
*/
|
|
75
|
+
export declare function defaultForeignKeyName(params: {
|
|
76
|
+
table: string;
|
|
77
|
+
columns: readonly string[];
|
|
78
|
+
dialect: Dialect;
|
|
79
|
+
}): string;
|
|
80
|
+
/** Default primary-key constraint name (postgres): `Table_pkey`, shortened to the limit. */
|
|
81
|
+
export declare function defaultPrimaryKeyName(params: {
|
|
82
|
+
table: string;
|
|
83
|
+
dialect: Dialect;
|
|
84
|
+
}): string;
|
|
85
|
+
/** The derived objects an implicit join table (`m2m.ts`) always carries. */
|
|
86
|
+
export type ImplicitJoinTableObjectNames = {
|
|
87
|
+
/** `_AToB_AB_unique` — the unique index over ("A", "B"). */
|
|
88
|
+
readonly uniqueIndex: string;
|
|
89
|
+
/** `_AToB_B_index` — the plain index over ("B"). */
|
|
90
|
+
readonly indexB: string;
|
|
91
|
+
/** `_AToB_A_fkey` — the FK from "A" to the first model's primary key. */
|
|
92
|
+
readonly foreignKeyA: string;
|
|
93
|
+
/** `_AToB_B_fkey` — the FK from "B" to the second model's primary key. */
|
|
94
|
+
readonly foreignKeyB: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Names of every derived object an implicit join table carries. `table` is the
|
|
98
|
+
* join-table name from `implicitJoinTable` (leading underscore included).
|
|
99
|
+
* These are Prisma's fixed spellings and are NOT shortened: the join table
|
|
100
|
+
* name is derived from the relation, and validation refuses an over-limit one
|
|
101
|
+
* with the relation name as the remedy.
|
|
102
|
+
*/
|
|
103
|
+
export declare function implicitJoinTableObjectNames(params: {
|
|
104
|
+
table: string;
|
|
105
|
+
}): ImplicitJoinTableObjectNames;
|
|
106
|
+
/**
|
|
107
|
+
* The name PostgreSQL itself picks for an object it creates implicitly — the
|
|
108
|
+
* identity/serial sequence `Table_column_seq` — mirroring `makeObjectName`:
|
|
109
|
+
* when `name1_name2_label` exceeds the limit, the LONGER of the two names is
|
|
110
|
+
* shortened first, one character at a time, until it fits. Used to address
|
|
111
|
+
* the real sequence when verifying or removing a column's identity; a naive
|
|
112
|
+
* concatenation mis-keys the object for any long table/column pair.
|
|
113
|
+
*/
|
|
114
|
+
export declare function postgresGeneratedObjectName(params: {
|
|
115
|
+
name1: string;
|
|
116
|
+
name2: string;
|
|
117
|
+
label: string;
|
|
118
|
+
}): string;
|
|
119
|
+
//# sourceMappingURL=physical-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"physical-names.d.ts","sourceRoot":"","sources":["../src/physical-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIvC,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GAAG;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAAC,CAInF,CAAC;AAIH,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAGnF;AAkBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC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2BAA2B,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAW3G"}
|
package/dist/prisma-literal.d.ts
CHANGED
|
@@ -56,4 +56,17 @@ export declare function encodePrismaString(params: {
|
|
|
56
56
|
export declare function exactIntegerLiteral(params: {
|
|
57
57
|
text: string;
|
|
58
58
|
}): number | string;
|
|
59
|
+
/**
|
|
60
|
+
* The IR value for a decimal literal default, exactly as written.
|
|
61
|
+
*
|
|
62
|
+
* A double carries 15 significant decimal digits exactly; a `Decimal(38, 28)`
|
|
63
|
+
* default such as `0.1234567890123456789012345678` lost eleven of them before
|
|
64
|
+
* any SQL was rendered. Literals with more significant digits than a double
|
|
65
|
+
* holds keep their text (the `literal` variant's existing string slot, which
|
|
66
|
+
* every renderer already quotes and the database casts exactly); the rest stay
|
|
67
|
+
* the JavaScript number they have always been.
|
|
68
|
+
*/
|
|
69
|
+
export declare function exactDecimalLiteral(params: {
|
|
70
|
+
text: string;
|
|
71
|
+
}): number | string;
|
|
59
72
|
//# sourceMappingURL=prisma-literal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-literal.d.ts","sourceRoot":"","sources":["../src/prisma-literal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA+BH;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA8BlE;AAOD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAapE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,MAAM,CAY7E"}
|
|
1
|
+
{"version":3,"file":"prisma-literal.d.ts","sourceRoot":"","sources":["../src/prisma-literal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA+BH;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA8BlE;AAOD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAapE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,MAAM,CAY7E;AAMD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,MAAM,CAY7E"}
|
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;AAMH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAmB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAW9E,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,EAqFhD,CAAC;AA2FF,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GAAG,eAAe,EAAE,CAwOhF;AAgiBD,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"}
|