@vibeorm/runtime 1.3.0 → 2.0.0-alpha.10
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 +50 -107
- package/dist/adapter.d.ts +250 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/bulk-upsert.d.ts +282 -0
- package/dist/bulk-upsert.d.ts.map +1 -0
- package/dist/client.d.ts +200 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/codecs.d.ts +170 -0
- package/dist/codecs.d.ts.map +1 -0
- package/dist/computed.d.ts +43 -0
- package/dist/computed.d.ts.map +1 -0
- package/dist/db-now.d.ts +41 -0
- package/dist/db-now.d.ts.map +1 -0
- package/dist/diagnostics/index.d.ts +12 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/insight.d.ts +63 -0
- package/dist/diagnostics/insight.d.ts.map +1 -0
- package/dist/diagnostics/plan.d.ts +88 -0
- package/dist/diagnostics/plan.d.ts.map +1 -0
- package/dist/diagnostics/preview.d.ts +43 -0
- package/dist/diagnostics/preview.d.ts.map +1 -0
- package/dist/diagnostics/types.d.ts +223 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/workload.d.ts +32 -0
- package/dist/diagnostics/workload.d.ts.map +1 -0
- package/dist/extensions.d.ts +102 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13070 -0
- package/dist/index.js.map +43 -0
- package/dist/keyset-iterator.d.ts +73 -0
- package/dist/keyset-iterator.d.ts.map +1 -0
- package/dist/keyset.d.ts +121 -0
- package/dist/keyset.d.ts.map +1 -0
- package/dist/model-meta.d.ts +200 -0
- package/dist/model-meta.d.ts.map +1 -0
- package/dist/nested-writes.d.ts +67 -0
- package/dist/nested-writes.d.ts.map +1 -0
- package/dist/policy-operation.d.ts +14 -0
- package/dist/policy-operation.d.ts.map +1 -0
- package/dist/policy.d.ts +17 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/query-builder.d.ts +271 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/relation-key.d.ts +23 -0
- package/dist/relation-key.d.ts.map +1 -0
- package/dist/relation-loader.d.ts +46 -0
- package/dist/relation-loader.d.ts.map +1 -0
- package/dist/relation-plan.d.ts +141 -0
- package/dist/relation-plan.d.ts.map +1 -0
- package/dist/render-cache.d.ts +48 -0
- package/dist/render-cache.d.ts.map +1 -0
- package/dist/rls-context.d.ts +14 -0
- package/dist/rls-context.d.ts.map +1 -0
- package/dist/rls-readiness.d.ts +114 -0
- package/dist/rls-readiness.d.ts.map +1 -0
- package/dist/scoped.d.ts +104 -0
- package/dist/scoped.d.ts.map +1 -0
- package/dist/strict-args.d.ts +47 -0
- package/dist/strict-args.d.ts.map +1 -0
- package/dist/telemetry/collector.d.ts +53 -0
- package/dist/telemetry/collector.d.ts.map +1 -0
- package/dist/telemetry/config.d.ts +53 -0
- package/dist/telemetry/config.d.ts.map +1 -0
- package/dist/telemetry/fingerprint.d.ts +38 -0
- package/dist/telemetry/fingerprint.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +18 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/recorder.d.ts +93 -0
- package/dist/telemetry/recorder.d.ts.map +1 -0
- package/dist/telemetry/statement.d.ts +53 -0
- package/dist/telemetry/statement.d.ts.map +1 -0
- package/dist/telemetry/types.d.ts +265 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/validators.d.ts +61 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/views.d.ts +97 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/write-scope.d.ts +14 -0
- package/dist/write-scope.d.ts.map +1 -0
- package/package.json +33 -26
- package/src/adapter.ts +0 -146
- package/src/client.ts +0 -2172
- package/src/coerce.ts +0 -184
- package/src/count-loader.ts +0 -152
- package/src/errors.ts +0 -492
- package/src/id-generators.ts +0 -151
- package/src/index.ts +0 -55
- package/src/lateral-join-builder.ts +0 -1053
- package/src/query-builder.ts +0 -1832
- package/src/relation-loader.ts +0 -534
- package/src/retry.ts +0 -183
- package/src/types.ts +0 -317
- package/src/view.ts +0 -629
- package/src/where-builder.ts +0 -772
package/src/adapter.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database adapter interface for VibeORM.
|
|
3
|
-
*
|
|
4
|
-
* Each adapter implementation (bun:sql, pg, etc.) provides a concrete
|
|
5
|
-
* implementation of this interface. The runtime is completely driver-agnostic
|
|
6
|
-
* and interacts with the database exclusively through this contract.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// ─── Transaction Options ──────────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Options for controlling transaction behavior.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* await db.$transaction(async (tx) => {
|
|
17
|
-
* await tx.account.update({ where: { id: 1 }, data: { balance: { decrement: 100 } } });
|
|
18
|
-
* await tx.account.update({ where: { id: 2 }, data: { balance: { increment: 100 } } });
|
|
19
|
-
* }, { isolationLevel: "Serializable", timeout: 5000 });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export type TransactionOptions = {
|
|
23
|
-
/**
|
|
24
|
-
* PostgreSQL isolation level for the transaction.
|
|
25
|
-
* - "ReadCommitted" (default): Standard PostgreSQL default.
|
|
26
|
-
* - "RepeatableRead": Prevents non-repeatable reads.
|
|
27
|
-
* - "Serializable": Full serializability — conflicts throw serialization_failure.
|
|
28
|
-
*/
|
|
29
|
-
isolationLevel?: "ReadCommitted" | "RepeatableRead" | "Serializable";
|
|
30
|
-
/**
|
|
31
|
-
* Maximum time in milliseconds the transaction may run before being cancelled.
|
|
32
|
-
* Implemented via `SET LOCAL statement_timeout = N` inside the transaction,
|
|
33
|
-
* so it is scoped to the transaction and does not affect other connections.
|
|
34
|
-
*/
|
|
35
|
-
timeout?: number;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// ─── Core Adapter Interface ───────────────────────────────────────
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The primary interface that every database adapter must implement.
|
|
42
|
-
* Adapters own connection management, query execution, statement caching,
|
|
43
|
-
* transactions, and driver-specific parameter formatting.
|
|
44
|
-
*/
|
|
45
|
-
export type DatabaseAdapter = {
|
|
46
|
-
/**
|
|
47
|
-
* Execute a parameterized query and return rows.
|
|
48
|
-
* The adapter owns statement caching and driver-specific optimizations.
|
|
49
|
-
*
|
|
50
|
-
* For bun:sql this means synthetic tagged template caching.
|
|
51
|
-
* For pg this means named prepared statement caching.
|
|
52
|
-
*/
|
|
53
|
-
execute(params: { text: string; values: unknown[] }): Promise<Record<string, unknown>[]>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Execute a raw/unsafe query without prepared statement caching.
|
|
57
|
-
* Used for `$queryRawUnsafe`, `$executeRawUnsafe`, and dynamic DDL.
|
|
58
|
-
*
|
|
59
|
-
* Returns both rows and affected row count (for INSERT/UPDATE/DELETE).
|
|
60
|
-
*/
|
|
61
|
-
executeUnsafe(params: {
|
|
62
|
-
text: string;
|
|
63
|
-
values?: unknown[];
|
|
64
|
-
}): Promise<QueryResult>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Run a function inside a database transaction.
|
|
68
|
-
* The callback receives a transactional adapter with the same interface.
|
|
69
|
-
* If the callback throws, the transaction is automatically rolled back.
|
|
70
|
-
*
|
|
71
|
-
* @param fn - The transactional callback.
|
|
72
|
-
* @param options - Optional isolation level and timeout.
|
|
73
|
-
*/
|
|
74
|
-
transaction<T>(fn: (txAdapter: DatabaseAdapter) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Eagerly warm up the connection pool.
|
|
78
|
-
* Forces at least one TCP handshake + auth so subsequent queries start instantly.
|
|
79
|
-
*/
|
|
80
|
-
connect(): Promise<void>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Gracefully close all connections in the pool.
|
|
84
|
-
*/
|
|
85
|
-
disconnect(): Promise<void>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Convert a JS array to the driver's preferred format for `= ANY($N)` queries.
|
|
89
|
-
*
|
|
90
|
-
* - **bun:sql**: Returns a PG array literal string `"{val1,val2,val3}"` because
|
|
91
|
-
* bun:sql's extended query protocol sends values as strings.
|
|
92
|
-
* - **pg**: Returns the raw JS array (pg driver handles native array serialization).
|
|
93
|
-
*/
|
|
94
|
-
formatArrayParam(values: unknown[]): unknown;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// ─── Query Result ─────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Result from an unsafe query execution.
|
|
101
|
-
* Contains both the rows returned and the number of affected rows
|
|
102
|
-
* (parsed from the PostgreSQL CommandComplete tag).
|
|
103
|
-
*/
|
|
104
|
-
export type QueryResult = {
|
|
105
|
-
rows: Record<string, unknown>[];
|
|
106
|
-
affectedRows: number;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// ─── SQL Executor (Migration Compatibility) ───────────────────────
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Minimal SQL execution interface compatible with `@vibeorm/migrate`.
|
|
113
|
-
* Adapters expose this via a helper function so migrations can run
|
|
114
|
-
* without knowing which adapter is in use.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* import { bunAdapter } from "@vibeorm/adapter-bun";
|
|
119
|
-
* import { toSqlExecutor } from "@vibeorm/runtime";
|
|
120
|
-
*
|
|
121
|
-
* const adapter = bunAdapter({ url: "postgres://..." });
|
|
122
|
-
* const executor = toSqlExecutor({ adapter });
|
|
123
|
-
* await applyMigration({ executor, migrationName: "init", sql, checksum });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
export type SqlExecutor = (params: {
|
|
127
|
-
text: string;
|
|
128
|
-
values?: unknown[];
|
|
129
|
-
}) => Promise<Record<string, unknown>[]>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Create an SqlExecutor from a DatabaseAdapter.
|
|
133
|
-
* Bridges the adapter pattern with the migrate package's SqlExecutor interface.
|
|
134
|
-
*/
|
|
135
|
-
export function toSqlExecutor(params: {
|
|
136
|
-
adapter: DatabaseAdapter;
|
|
137
|
-
}): SqlExecutor {
|
|
138
|
-
const { adapter } = params;
|
|
139
|
-
return async (queryParams) => {
|
|
140
|
-
const result = await adapter.executeUnsafe({
|
|
141
|
-
text: queryParams.text,
|
|
142
|
-
values: queryParams.values,
|
|
143
|
-
});
|
|
144
|
-
return result.rows;
|
|
145
|
-
};
|
|
146
|
-
}
|