turbine-orm 0.81.0 → 0.90.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 +26 -25
- package/dist/checkout.d.ts +27 -2
- package/dist/checkout.js +75 -4
- package/dist/cjs/checkout.d.ts +27 -2
- package/dist/cjs/checkout.js +76 -3
- package/dist/cjs/cli/code-first-tags.d.ts +62 -0
- package/dist/cjs/cli/code-first-tags.js +124 -0
- package/dist/cjs/cli/compile-query.js +9 -0
- package/dist/cjs/cli/config.d.ts +35 -6
- package/dist/cjs/cli/config.js +17 -1
- package/dist/cjs/cli/destructive.d.ts +7 -4
- package/dist/cjs/cli/destructive.js +224 -20
- package/dist/cjs/cli/error-catalog.js +36 -0
- package/dist/cjs/cli/error-text.d.ts +15 -0
- package/dist/cjs/cli/error-text.js +40 -0
- package/dist/cjs/cli/index.d.ts +62 -4
- package/dist/cjs/cli/index.js +568 -108
- package/dist/cjs/cli/local-server-guard.d.ts +53 -0
- package/dist/cjs/cli/local-server-guard.js +119 -0
- package/dist/cjs/cli/local-server-output.d.ts +41 -0
- package/dist/cjs/cli/local-server-output.js +103 -0
- package/dist/cjs/cli/mcp.d.ts +8 -0
- package/dist/cjs/cli/mcp.js +121 -32
- package/dist/cjs/cli/migrate.d.ts +113 -5
- package/dist/cjs/cli/migrate.js +270 -21
- package/dist/cjs/cli/observe.d.ts +6 -1
- package/dist/cjs/cli/observe.js +85 -55
- package/dist/cjs/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cjs/cli/pii-predicate-guard.js +98 -37
- package/dist/cjs/cli/prisma-resolve.js +17 -13
- package/dist/cjs/cli/prisma-schema.js +12 -4
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/studio.d.ts +14 -2
- package/dist/cjs/cli/studio.js +244 -69
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/client.d.ts +558 -85
- package/dist/cjs/client.js +1270 -395
- package/dist/cjs/connection-guard.d.ts +13 -0
- package/dist/cjs/connection-guard.js +28 -0
- package/dist/cjs/connection-url.d.ts +51 -16
- package/dist/cjs/connection-url.js +67 -34
- package/dist/cjs/diagnostics.d.ts +81 -0
- package/dist/cjs/diagnostics.js +147 -0
- package/dist/cjs/dialect.d.ts +449 -20
- package/dist/cjs/dialect.js +117 -76
- package/dist/cjs/engine-config.d.ts +7 -6
- package/dist/cjs/errors.d.ts +126 -6
- package/dist/cjs/errors.js +256 -13
- package/dist/cjs/generate.d.ts +57 -7
- package/dist/cjs/generate.js +635 -279
- package/dist/cjs/global-filters-config.d.ts +59 -0
- package/dist/cjs/global-filters-config.js +367 -0
- package/dist/cjs/index.d.ts +9 -4
- package/dist/cjs/index.js +10 -2
- package/dist/cjs/introspect.d.ts +31 -6
- package/dist/cjs/introspect.js +108 -50
- package/dist/cjs/log-codes.d.ts +12 -0
- package/dist/cjs/log-codes.js +77 -0
- package/dist/cjs/logger.d.ts +87 -0
- package/dist/cjs/logger.js +98 -0
- package/dist/cjs/mssql.d.ts +8 -5
- package/dist/cjs/mssql.js +352 -65
- package/dist/cjs/mysql.d.ts +3 -5
- package/dist/cjs/mysql.js +420 -70
- package/dist/cjs/nested-write.d.ts +3 -0
- package/dist/cjs/nested-write.js +179 -114
- package/dist/cjs/pipeline-submittable.d.ts +12 -0
- package/dist/cjs/pipeline-submittable.js +118 -44
- package/dist/cjs/pipeline.js +21 -26
- package/dist/cjs/powdb-introspect.d.ts +5 -2
- package/dist/cjs/powdb-introspect.js +20 -15
- package/dist/cjs/powdb-shared.d.ts +36 -5
- package/dist/cjs/powdb-shared.js +67 -8
- package/dist/cjs/powdb.d.ts +4 -0
- package/dist/cjs/powdb.js +183 -51
- package/dist/cjs/powql.d.ts +394 -51
- package/dist/cjs/powql.js +1829 -284
- package/dist/cjs/prisma-compat.d.ts +23 -15
- package/dist/cjs/prisma-compat.js +507 -372
- package/dist/cjs/query/aggregates.d.ts +17 -1
- package/dist/cjs/query/aggregates.js +261 -29
- package/dist/cjs/query/batched-loader.d.ts +25 -6
- package/dist/cjs/query/batched-loader.js +103 -20
- package/dist/cjs/query/builder.d.ts +325 -184
- package/dist/cjs/query/builder.js +1452 -490
- package/dist/cjs/query/column-ref.d.ts +61 -0
- package/dist/cjs/query/column-ref.js +73 -0
- package/dist/cjs/query/compound-unique.d.ts +21 -0
- package/dist/cjs/query/compound-unique.js +98 -18
- package/dist/cjs/query/deferred.d.ts +53 -16
- package/dist/cjs/query/expr.d.ts +217 -0
- package/dist/cjs/query/expr.js +859 -0
- package/dist/cjs/query/filters.d.ts +155 -53
- package/dist/cjs/query/filters.js +613 -76
- package/dist/cjs/query/index.d.ts +2 -0
- package/dist/cjs/query/index.js +7 -1
- package/dist/cjs/query/json-value.d.ts +43 -0
- package/dist/cjs/query/json-value.js +59 -0
- package/dist/cjs/query/normalize-args.d.ts +87 -0
- package/dist/cjs/query/normalize-args.js +527 -0
- package/dist/cjs/query/option-surface.d.ts +16 -4
- package/dist/cjs/query/option-surface.js +57 -14
- package/dist/cjs/query/relation-names.d.ts +14 -0
- package/dist/cjs/query/relation-names.js +77 -18
- package/dist/cjs/query/relations.d.ts +30 -3
- package/dist/cjs/query/relations.js +219 -63
- package/dist/cjs/query/row-lock.d.ts +49 -0
- package/dist/cjs/query/row-lock.js +138 -0
- package/dist/cjs/query/sql-comment.d.ts +161 -0
- package/dist/cjs/query/sql-comment.js +381 -0
- package/dist/cjs/query/stream-idle.d.ts +132 -0
- package/dist/cjs/query/stream-idle.js +212 -0
- package/dist/cjs/query/table-client.d.ts +101 -0
- package/dist/cjs/query/table-client.js +74 -0
- package/dist/cjs/query/types.d.ts +677 -298
- package/dist/cjs/query/utils.d.ts +105 -6
- package/dist/cjs/query/utils.js +426 -19
- package/dist/cjs/query/warn-registry.d.ts +18 -0
- package/dist/cjs/query/warn-registry.js +18 -0
- package/dist/cjs/query/where-compile.d.ts +138 -14
- package/dist/cjs/query/where-compile.js +513 -29
- package/dist/cjs/query/where.d.ts +159 -59
- package/dist/cjs/query/where.js +716 -246
- package/dist/cjs/query/writes.d.ts +112 -50
- package/dist/cjs/query/writes.js +1498 -200
- package/dist/cjs/query-events.d.ts +4 -2
- package/dist/cjs/query-events.js +3 -1
- package/dist/cjs/realtime.d.ts +7 -3
- package/dist/cjs/realtime.js +13 -2
- package/dist/cjs/schema-builder.d.ts +55 -4
- package/dist/cjs/schema-builder.js +382 -18
- package/dist/cjs/schema-metadata.d.ts +21 -1
- package/dist/cjs/schema-metadata.js +29 -7
- package/dist/cjs/schema-sql.d.ts +75 -5
- package/dist/cjs/schema-sql.js +497 -45
- package/dist/cjs/schema.d.ts +26 -5
- package/dist/cjs/schema.js +110 -13
- package/dist/cjs/sql-placeholders.d.ts +56 -0
- package/dist/cjs/sql-placeholders.js +204 -0
- package/dist/cjs/sqlite.d.ts +75 -20
- package/dist/cjs/sqlite.js +593 -95
- package/dist/cjs/supplied-pool-types.d.ts +48 -0
- package/dist/cjs/supplied-pool-types.js +256 -0
- package/dist/cjs/transaction-control.d.ts +51 -0
- package/dist/cjs/transaction-control.js +316 -0
- package/dist/cjs/transaction-state.d.ts +342 -0
- package/dist/cjs/transaction-state.js +707 -0
- package/dist/cjs/typed-sql.d.ts +37 -3
- package/dist/cjs/typed-sql.js +102 -8
- package/dist/cli/code-first-tags.d.ts +62 -0
- package/dist/cli/code-first-tags.js +120 -0
- package/dist/cli/compile-query.js +9 -0
- package/dist/cli/config.d.ts +35 -6
- package/dist/cli/config.js +16 -1
- package/dist/cli/destructive.d.ts +7 -4
- package/dist/cli/destructive.js +224 -20
- package/dist/cli/error-catalog.js +36 -0
- package/dist/cli/error-text.d.ts +15 -0
- package/dist/cli/error-text.js +37 -0
- package/dist/cli/index.d.ts +62 -4
- package/dist/cli/index.js +569 -112
- package/dist/cli/local-server-guard.d.ts +53 -0
- package/dist/cli/local-server-guard.js +113 -0
- package/dist/cli/local-server-output.d.ts +41 -0
- package/dist/cli/local-server-output.js +98 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +121 -34
- package/dist/cli/migrate.d.ts +113 -5
- package/dist/cli/migrate.js +261 -21
- package/dist/cli/observe.d.ts +6 -1
- package/dist/cli/observe.js +84 -54
- package/dist/cli/pii-predicate-guard.d.ts +43 -23
- package/dist/cli/pii-predicate-guard.js +100 -35
- package/dist/cli/prisma-resolve.js +15 -11
- package/dist/cli/prisma-schema.js +12 -4
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/studio.d.ts +14 -2
- package/dist/cli/studio.js +246 -71
- package/dist/cli/ui.d.ts +1 -1
- package/dist/client.d.ts +558 -85
- package/dist/client.js +1275 -400
- package/dist/connection-guard.d.ts +13 -0
- package/dist/connection-guard.js +27 -0
- package/dist/connection-url.d.ts +51 -16
- package/dist/connection-url.js +63 -34
- package/dist/diagnostics.d.ts +81 -0
- package/dist/diagnostics.js +144 -0
- package/dist/dialect.d.ts +449 -20
- package/dist/dialect.js +115 -43
- package/dist/engine-config.d.ts +7 -6
- package/dist/errors.d.ts +126 -6
- package/dist/errors.js +252 -12
- package/dist/generate.d.ts +57 -7
- package/dist/generate.js +635 -281
- package/dist/global-filters-config.d.ts +59 -0
- package/dist/global-filters-config.js +361 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +4 -2
- package/dist/introspect.d.ts +31 -6
- package/dist/introspect.js +106 -50
- package/dist/log-codes.d.ts +12 -0
- package/dist/log-codes.js +74 -0
- package/dist/logger.d.ts +87 -0
- package/dist/logger.js +93 -0
- package/dist/mssql.d.ts +8 -5
- package/dist/mssql.js +354 -67
- package/dist/mysql.d.ts +3 -5
- package/dist/mysql.js +423 -73
- package/dist/nested-write.d.ts +3 -0
- package/dist/nested-write.js +177 -112
- package/dist/pipeline-submittable.d.ts +12 -0
- package/dist/pipeline-submittable.js +117 -44
- package/dist/pipeline.js +21 -26
- package/dist/powdb-introspect.d.ts +5 -2
- package/dist/powdb-introspect.js +21 -16
- package/dist/powdb-shared.d.ts +36 -5
- package/dist/powdb-shared.js +65 -8
- package/dist/powdb.d.ts +4 -0
- package/dist/powdb.js +183 -51
- package/dist/powql.d.ts +394 -51
- package/dist/powql.js +1836 -291
- package/dist/prisma-compat.d.ts +23 -15
- package/dist/prisma-compat.js +508 -373
- package/dist/query/aggregates.d.ts +17 -1
- package/dist/query/aggregates.js +263 -32
- package/dist/query/batched-loader.d.ts +25 -6
- package/dist/query/batched-loader.js +101 -21
- package/dist/query/builder.d.ts +325 -184
- package/dist/query/builder.js +1458 -495
- package/dist/query/column-ref.d.ts +61 -0
- package/dist/query/column-ref.js +66 -0
- package/dist/query/compound-unique.d.ts +21 -0
- package/dist/query/compound-unique.js +97 -19
- package/dist/query/deferred.d.ts +53 -16
- package/dist/query/expr.d.ts +217 -0
- package/dist/query/expr.js +848 -0
- package/dist/query/filters.d.ts +155 -53
- package/dist/query/filters.js +597 -72
- package/dist/query/index.d.ts +2 -0
- package/dist/query/index.js +4 -0
- package/dist/query/json-value.d.ts +43 -0
- package/dist/query/json-value.js +54 -0
- package/dist/query/normalize-args.d.ts +87 -0
- package/dist/query/normalize-args.js +517 -0
- package/dist/query/option-surface.d.ts +16 -4
- package/dist/query/option-surface.js +56 -13
- package/dist/query/relation-names.d.ts +14 -0
- package/dist/query/relation-names.js +77 -19
- package/dist/query/relations.d.ts +30 -3
- package/dist/query/relations.js +220 -67
- package/dist/query/row-lock.d.ts +49 -0
- package/dist/query/row-lock.js +131 -0
- package/dist/query/sql-comment.d.ts +161 -0
- package/dist/query/sql-comment.js +374 -0
- package/dist/query/stream-idle.d.ts +132 -0
- package/dist/query/stream-idle.js +203 -0
- package/dist/query/table-client.d.ts +101 -0
- package/dist/query/table-client.js +70 -0
- package/dist/query/types.d.ts +677 -298
- package/dist/query/utils.d.ts +105 -6
- package/dist/query/utils.js +414 -18
- package/dist/query/warn-registry.d.ts +18 -0
- package/dist/query/warn-registry.js +18 -0
- package/dist/query/where-compile.d.ts +138 -14
- package/dist/query/where-compile.js +508 -31
- package/dist/query/where.d.ts +159 -59
- package/dist/query/where.js +711 -248
- package/dist/query/writes.d.ts +112 -50
- package/dist/query/writes.js +1496 -202
- package/dist/query-events.d.ts +4 -2
- package/dist/query-events.js +3 -1
- package/dist/realtime.d.ts +7 -3
- package/dist/realtime.js +13 -2
- package/dist/schema-builder.d.ts +55 -4
- package/dist/schema-builder.js +381 -18
- package/dist/schema-metadata.d.ts +21 -1
- package/dist/schema-metadata.js +28 -7
- package/dist/schema-sql.d.ts +75 -5
- package/dist/schema-sql.js +494 -44
- package/dist/schema.d.ts +26 -5
- package/dist/schema.js +109 -13
- package/dist/sql-placeholders.d.ts +56 -0
- package/dist/sql-placeholders.js +200 -0
- package/dist/sqlite.d.ts +75 -20
- package/dist/sqlite.js +597 -99
- package/dist/supplied-pool-types.d.ts +48 -0
- package/dist/supplied-pool-types.js +247 -0
- package/dist/transaction-control.d.ts +51 -0
- package/dist/transaction-control.js +311 -0
- package/dist/transaction-state.d.ts +342 -0
- package/dist/transaction-state.js +696 -0
- package/dist/typed-sql.d.ts +37 -3
- package/dist/typed-sql.js +100 -8
- package/package.json +7 -4
- package/skills/turbine-orm/SKILL.md +56 -6
package/dist/query-events.d.ts
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
* package ships ESM and CJS, and a mixed graph loading both copies must still
|
|
23
23
|
* see the tag a caller set through either copy.
|
|
24
24
|
*
|
|
25
|
-
* The tag
|
|
25
|
+
* The tag reaches SQL only when the client asks for it: `sqlComment: { tag:
|
|
26
|
+
* true }` (query/sql-comment.ts) appends it to each statement as a comment,
|
|
27
|
+
* URL-encoded. Otherwise it is metadata on the in-process event only, and what
|
|
26
28
|
* a listener does with it (log it, forward it to a collector) is the
|
|
27
29
|
* listener's business.
|
|
28
30
|
*/
|
|
@@ -83,7 +85,7 @@ export declare function deferredIdentity(tag: string): {
|
|
|
83
85
|
export declare function runReportedStatement<R extends {
|
|
84
86
|
rowCount?: number | null;
|
|
85
87
|
rows?: unknown[];
|
|
86
|
-
}>(sink: QueryEventSink, identity: Pick<QueryEvent, 'model' | 'action' | 'batch'>, sql: string, params: unknown[], run: () => Promise<R>, wrap: (err: unknown) => unknown): Promise<R>;
|
|
88
|
+
}>(sink: QueryEventSink, identity: Pick<QueryEvent, 'model' | 'action' | 'batch' | 'comment'>, sql: string, params: unknown[], run: () => Promise<R>, wrap: (err: unknown) => unknown): Promise<R>;
|
|
87
89
|
/** The identity of a raw statement run through `action`. */
|
|
88
90
|
export declare const rawIdentity: (action: string) => Pick<QueryEvent, "model" | "action">;
|
|
89
91
|
export {};
|
package/dist/query-events.js
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
* package ships ESM and CJS, and a mixed graph loading both copies must still
|
|
23
23
|
* see the tag a caller set through either copy.
|
|
24
24
|
*
|
|
25
|
-
* The tag
|
|
25
|
+
* The tag reaches SQL only when the client asks for it: `sqlComment: { tag:
|
|
26
|
+
* true }` (query/sql-comment.ts) appends it to each statement as a comment,
|
|
27
|
+
* URL-encoded. Otherwise it is metadata on the in-process event only, and what
|
|
26
28
|
* a listener does with it (log it, forward it to a collector) is the
|
|
27
29
|
* listener's business.
|
|
28
30
|
*/
|
package/dist/realtime.d.ts
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
* caller's cue to resynchronise from the source of truth.
|
|
39
39
|
*/
|
|
40
40
|
import type { PgCompatPool } from './client.js';
|
|
41
|
+
import { type TurbineLogger } from './logger.js';
|
|
41
42
|
/**
|
|
42
43
|
* Validate a LISTEN/NOTIFY channel name. Throws ValidationError on anything
|
|
43
44
|
* that isn't a plain, reasonable-length SQL identifier. This is enforced for
|
|
@@ -65,8 +66,10 @@ export interface ListenOptions {
|
|
|
65
66
|
reconnect?: boolean | ListenReconnectOptions;
|
|
66
67
|
/**
|
|
67
68
|
* Called when the connection is lost and after each failed reconnect
|
|
68
|
-
* attempt. Defaults to one
|
|
69
|
-
*
|
|
69
|
+
* attempt. Defaults to one line per event through the client's `logger`: a
|
|
70
|
+
* `warn` (code `'listen-reconnecting'`) while the subscription retries, an
|
|
71
|
+
* `error` (code `'listen-lost'`) when it does not. The subscription keeps
|
|
72
|
+
* retrying unless `reconnect` is `false`; call `unsubscribe()` to stop.
|
|
70
73
|
*/
|
|
71
74
|
onError?: (err: Error) => void;
|
|
72
75
|
/**
|
|
@@ -110,5 +113,6 @@ export interface ActiveSubscription extends Subscription {
|
|
|
110
113
|
* @param onClosed invoked when the subscription ends, so the client can
|
|
111
114
|
* drop it from its active-subscription registry
|
|
112
115
|
* @param options reconnect policy and loss/reconnect callbacks
|
|
116
|
+
* @param logger where a loss is reported when `options.onError` is unset
|
|
113
117
|
*/
|
|
114
|
-
export declare function createSubscription(pool: PgCompatPool, channel: string, quotedChannel: string, handler: NotificationHandler, onClosed: (sub: ActiveSubscription) => void, options?: ListenOptions): Promise<ActiveSubscription>;
|
|
118
|
+
export declare function createSubscription(pool: PgCompatPool, channel: string, quotedChannel: string, handler: NotificationHandler, onClosed: (sub: ActiveSubscription) => void, options?: ListenOptions, logger?: TurbineLogger): Promise<ActiveSubscription>;
|
package/dist/realtime.js
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
*/
|
|
40
40
|
import { guardCheckout } from './connection-guard.js';
|
|
41
41
|
import { ConnectionError, ValidationError, wrapPgError } from './errors.js';
|
|
42
|
+
import { consoleLogger, logTo } from './logger.js';
|
|
42
43
|
// ---------------------------------------------------------------------------
|
|
43
44
|
// Identifier validation
|
|
44
45
|
// ---------------------------------------------------------------------------
|
|
@@ -125,14 +126,24 @@ async function openListenConnection(pool, channel, quotedChannel, handler, onLos
|
|
|
125
126
|
* @param onClosed invoked when the subscription ends, so the client can
|
|
126
127
|
* drop it from its active-subscription registry
|
|
127
128
|
* @param options reconnect policy and loss/reconnect callbacks
|
|
129
|
+
* @param logger where a loss is reported when `options.onError` is unset
|
|
128
130
|
*/
|
|
129
|
-
export async function createSubscription(pool, channel, quotedChannel, handler, onClosed, options = {}) {
|
|
131
|
+
export async function createSubscription(pool, channel, quotedChannel, handler, onClosed, options = {}, logger = consoleLogger) {
|
|
130
132
|
const backoff = options.reconnect === false
|
|
131
133
|
? undefined
|
|
132
134
|
: { ...DEFAULT_RECONNECT, ...(typeof options.reconnect === 'object' ? options.reconnect : {}) };
|
|
133
135
|
const reportError = options.onError ??
|
|
134
136
|
((err) => {
|
|
135
|
-
|
|
137
|
+
if (backoff && !closed) {
|
|
138
|
+
logTo(logger, 'warn', `$listen "${channel}": ${err.message}, reconnecting`, {
|
|
139
|
+
code: 'listen-reconnecting',
|
|
140
|
+
channel,
|
|
141
|
+
error: err,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
logTo(logger, 'error', `$listen "${channel}": ${err.message}`, { code: 'listen-lost', channel, error: err });
|
|
146
|
+
}
|
|
136
147
|
});
|
|
137
148
|
let closed = false;
|
|
138
149
|
let current;
|
package/dist/schema-builder.d.ts
CHANGED
|
@@ -47,8 +47,12 @@ export interface ColumnDef {
|
|
|
47
47
|
nullable?: boolean;
|
|
48
48
|
/** UNIQUE constraint */
|
|
49
49
|
unique?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* DEFAULT expression (raw SQL, e.g. `'now()'` or `"'active'"`). A finite number
|
|
52
|
+
* or a boolean is written as the literal it is (`5`, `true`). Anything else is
|
|
53
|
+
* refused (E003).
|
|
54
|
+
*/
|
|
55
|
+
default?: string | number | boolean;
|
|
52
56
|
/**
|
|
53
57
|
* REFERENCES target. Either the "table.column" string form or an object with
|
|
54
58
|
* referential actions ({@link ReferenceDef}).
|
|
@@ -81,6 +85,15 @@ export interface ColumnDef {
|
|
|
81
85
|
* {@link import('./schema.js').ColumnMetadata.updatedAt}.
|
|
82
86
|
*/
|
|
83
87
|
updatedAt?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The TypeScript type `turbine generate` emits for this column, replacing
|
|
90
|
+
* the one derived from `type`. Mainly for `json` / `jsonb`, which otherwise
|
|
91
|
+
* generate as `unknown`: `{ type: 'jsonb', tsType: '{ theme: string }' }`.
|
|
92
|
+
* Emitted verbatim (nullability is still added), so it may name any type
|
|
93
|
+
* the generated file can see. The same override as the generator's
|
|
94
|
+
* `columnTypes` option, declared next to the column.
|
|
95
|
+
*/
|
|
96
|
+
tsType?: string;
|
|
84
97
|
}
|
|
85
98
|
/** Postgres-level column type (uppercase, as used in DDL) */
|
|
86
99
|
export type ColumnType = 'SERIAL' | 'BIGSERIAL' | 'BIGINT' | 'INTEGER' | 'SMALLINT' | 'TEXT' | 'BOOLEAN' | 'TIMESTAMPTZ' | 'JSONB' | 'UUID' | 'REAL' | 'DOUBLE PRECISION' | 'NUMERIC' | 'BYTEA' | 'DATE' | 'VARCHAR' | 'ENUM' | 'VECTOR';
|
|
@@ -109,7 +122,21 @@ export interface ColumnConfig {
|
|
|
109
122
|
pii: boolean;
|
|
110
123
|
/** Whether this column is auto-set to the current time on update. */
|
|
111
124
|
updatedAt: boolean;
|
|
125
|
+
/** Generated TypeScript type override ({@link ColumnDef.tsType}), or null / absent. */
|
|
126
|
+
tsType?: string | null;
|
|
112
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Why `text` cannot be written into a generated file as a TypeScript type, or
|
|
130
|
+
* null when it can. The text lands verbatim as a member type or an alias body,
|
|
131
|
+
* so what has to hold is that it stays ONE type: brackets balance, nothing at
|
|
132
|
+
* the top level ends the member (`;` or `,`), and it holds no comment, template
|
|
133
|
+
* literal or character a type does not use. A `//` would swallow the rest of the
|
|
134
|
+
* line and a stray `}` would close the interface and start a statement.
|
|
135
|
+
*
|
|
136
|
+
* It does not check that the type is well formed or that its names exist; the
|
|
137
|
+
* compiler of the generated file does that.
|
|
138
|
+
*/
|
|
139
|
+
export declare function tsTypeTextProblem(text: string): string | null;
|
|
113
140
|
/**
|
|
114
141
|
* Explicit many-to-many relation declaration for the code-first schema.
|
|
115
142
|
*
|
|
@@ -269,6 +296,28 @@ export interface DefineSchemaOptions {
|
|
|
269
296
|
}
|
|
270
297
|
/** Input format: table name -> column defs (object format) or TableDef (legacy builder) */
|
|
271
298
|
type SchemaInput = Record<string, Record<string, ColumnDef> | TableDef | TableInput>;
|
|
299
|
+
/** The table-level options of {@link TableInput}; every other key is a column. */
|
|
300
|
+
type TableOptionKey = 'primaryKey' | 'manyToMany' | 'checks' | 'indexes';
|
|
301
|
+
/** The expected type an unknown key is given, so the compile error names it. */
|
|
302
|
+
type UnknownKey<Where extends string, K> = `unknown key "${K & string}" in ${Where}`;
|
|
303
|
+
/** Every key of every member of a union (`keyof` of a union is only the shared keys). */
|
|
304
|
+
type AllKeys<T> = T extends unknown ? keyof T : never;
|
|
305
|
+
type KnownKeys<T, Allowed, Where extends string> = T extends readonly unknown[] ? unknown : T extends object ? {
|
|
306
|
+
[K in AllKeys<T>]?: K extends Allowed ? unknown : UnknownKey<Where, K>;
|
|
307
|
+
} : unknown;
|
|
308
|
+
type KnownElementKeys<A, Allowed, Where extends string> = A extends readonly (infer E)[] ? readonly KnownKeys<E, Allowed, Where>[] : unknown;
|
|
309
|
+
type ColumnKeyCheck<C> = KnownKeys<C, keyof ColumnDef, 'a column'> & (C extends {
|
|
310
|
+
references: infer R;
|
|
311
|
+
} ? {
|
|
312
|
+
references?: KnownKeys<R, keyof ReferenceDef, 'references'>;
|
|
313
|
+
} : unknown);
|
|
314
|
+
type TableKeyCheck<T> = T extends TableDef ? unknown : string extends keyof T ? unknown : {
|
|
315
|
+
[K in keyof T]: K extends 'indexes' ? KnownElementKeys<T[K], keyof ColumnIndexDef | keyof DocFieldIndexDef, 'an index'> : K extends 'checks' ? KnownElementKeys<T[K], keyof CheckDef, 'a check'> : K extends 'manyToMany' ? KnownElementKeys<T[K], keyof ManyToManyDef, 'a manyToMany relation'> : K extends TableOptionKey ? unknown : T[K] extends readonly unknown[] ? UnknownKey<'a table (not a table option, and an array is not a column)', K> : ColumnKeyCheck<T[K]>;
|
|
316
|
+
};
|
|
317
|
+
/** Rejects, in a literal, every key {@link defineSchema} would refuse at runtime. */
|
|
318
|
+
export type SchemaKeyCheck<S> = {
|
|
319
|
+
[A in keyof S]: TableKeyCheck<S[A]>;
|
|
320
|
+
};
|
|
272
321
|
/**
|
|
273
322
|
* Define the full database schema using plain objects.
|
|
274
323
|
*
|
|
@@ -288,7 +337,7 @@ type SchemaInput = Record<string, Record<string, ColumnDef> | TableDef | TableIn
|
|
|
288
337
|
* });
|
|
289
338
|
* ```
|
|
290
339
|
*/
|
|
291
|
-
export declare function defineSchema(input:
|
|
340
|
+
export declare function defineSchema<S extends SchemaInput>(input: S & SchemaKeyCheck<S>, options?: DefineSchemaOptions): SchemaDef;
|
|
292
341
|
export declare class ColumnBuilder {
|
|
293
342
|
private _config;
|
|
294
343
|
constructor();
|
|
@@ -314,7 +363,7 @@ export declare class ColumnBuilder {
|
|
|
314
363
|
notNull(): this;
|
|
315
364
|
nullable(): this;
|
|
316
365
|
unique(): this;
|
|
317
|
-
default(val: string): this;
|
|
366
|
+
default(val: string | number | boolean): this;
|
|
318
367
|
references(target: string, opts?: {
|
|
319
368
|
onDelete?: ReferentialAction;
|
|
320
369
|
onUpdate?: ReferentialAction;
|
|
@@ -323,6 +372,8 @@ export declare class ColumnBuilder {
|
|
|
323
372
|
pii(): this;
|
|
324
373
|
/** Auto-set this column to the current time on every update. Prisma's `@updatedAt`. */
|
|
325
374
|
updatedAt(): this;
|
|
375
|
+
/** The TypeScript type `turbine generate` emits for this column. See {@link ColumnDef.tsType}. */
|
|
376
|
+
tsType(type: string): this;
|
|
326
377
|
array(): this;
|
|
327
378
|
build(): ColumnConfig;
|
|
328
379
|
}
|