@vibeorm/adapter-bun 1.3.0 → 2.0.0-alpha.2
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 +62 -49
- package/dist/connection-url.d.ts +37 -0
- package/dist/connection-url.d.ts.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +485 -0
- package/dist/index.js.map +16 -0
- package/dist/params.d.ts +59 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/savepoints.d.ts +22 -0
- package/dist/savepoints.d.ts.map +1 -0
- package/dist/template-cache.d.ts +33 -0
- package/dist/template-cache.d.ts.map +1 -0
- package/dist/transaction-sql.d.ts +62 -0
- package/dist/transaction-sql.d.ts.map +1 -0
- package/package.json +28 -19
- package/src/index.ts +0 -621
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAmBnE;AAID;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,GAAG,OAAO,EAAE,CAEjF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,GAAG,OAAO,EAAE,CAEpF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Savepoint naming for nested transactions.
|
|
3
|
+
*
|
|
4
|
+
* v1 lesson (LEARNINGS.md): the counter is shared **by reference** across every
|
|
5
|
+
* adapter created for one top-level transaction, so sibling and deeply nested
|
|
6
|
+
* savepoints can never collide on a name.
|
|
7
|
+
*/
|
|
8
|
+
/** Mutable counter shared by reference across one top-level transaction. */
|
|
9
|
+
export type SavepointCounter = {
|
|
10
|
+
n: number;
|
|
11
|
+
};
|
|
12
|
+
/** Fresh counter — one per top-level transaction. */
|
|
13
|
+
export declare function createSavepointCounter(): SavepointCounter;
|
|
14
|
+
/**
|
|
15
|
+
* Allocate the next savepoint name (`vibeorm_sp_0`, `vibeorm_sp_1`, …) and
|
|
16
|
+
* advance the shared counter. The name is an identifier by construction, so it
|
|
17
|
+
* is safe to interpolate into `SAVEPOINT` / `RELEASE` / `ROLLBACK TO` SQL.
|
|
18
|
+
*/
|
|
19
|
+
export declare function nextSavepointName(params: {
|
|
20
|
+
counter: SavepointCounter;
|
|
21
|
+
}): string;
|
|
22
|
+
//# sourceMappingURL=savepoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"savepoints.d.ts","sourceRoot":"","sources":["../src/savepoints.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C,qDAAqD;AACrD,wBAAgB,sBAAsB,IAAI,gBAAgB,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,gBAAgB,CAAA;CAAE,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic tagged-template cache — bun:sql's prepared-statement path.
|
|
3
|
+
*
|
|
4
|
+
* bun:sql only creates a *named* prepared statement (one PostgreSQL keeps a
|
|
5
|
+
* plan for) when the query arrives as a tagged template. Generated SQL is a
|
|
6
|
+
* plain string, so with `preparedStatements: true` the adapter turns each SQL
|
|
7
|
+
* text into a synthetic `TemplateStringsArray` — split on the `$1`, `$2`, …
|
|
8
|
+
* placeholders — and reuses that same object identity for every execution.
|
|
9
|
+
*
|
|
10
|
+
* The cache is LRU-bounded so a long-running process never grows it without
|
|
11
|
+
* limit.
|
|
12
|
+
*/
|
|
13
|
+
/** LRU map from SQL text to the synthetic template used to execute it. */
|
|
14
|
+
export type TemplateCache = {
|
|
15
|
+
/** Template for `text`, creating one on first sight. Stable by identity. */
|
|
16
|
+
getTemplate(params: {
|
|
17
|
+
text: string;
|
|
18
|
+
}): TemplateStringsArray;
|
|
19
|
+
/** Number of texts currently held — diagnostics and tests. */
|
|
20
|
+
size(): number;
|
|
21
|
+
};
|
|
22
|
+
/** Split a SQL text on `$n` placeholders into the literal chunks around them. */
|
|
23
|
+
export declare function templateChunks(params: {
|
|
24
|
+
text: string;
|
|
25
|
+
}): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Create a template cache holding at most `max` texts (least recently used
|
|
28
|
+
* evicted first).
|
|
29
|
+
*/
|
|
30
|
+
export declare function createTemplateCache(params: {
|
|
31
|
+
max: number;
|
|
32
|
+
}): TemplateCache;
|
|
33
|
+
//# sourceMappingURL=template-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-cache.d.ts","sourceRoot":"","sources":["../src/template-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG;IAC1B,4EAA4E;IAC5E,WAAW,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,oBAAoB,CAAC;IAC5D,8DAA8D;IAC9D,IAAI,IAAI,MAAM,CAAC;CAChB,CAAC;AAEF,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,EAAE,CAEjE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CA4B1E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction-control SQL text (postgres dialect, bun:sql flavour).
|
|
3
|
+
*
|
|
4
|
+
* Used by the reserved-connection path, which issues `BEGIN` itself so that
|
|
5
|
+
* isolation level and statement timeout can be applied — bun:sql's
|
|
6
|
+
* `sql.begin(fn)` fast path takes no such options.
|
|
7
|
+
*/
|
|
8
|
+
import type { IsolationLevel, TransactionOptions } from "@vibeorm/runtime";
|
|
9
|
+
/** VibeORM isolation level → PostgreSQL isolation level keyword. */
|
|
10
|
+
export declare const ISOLATION_LEVEL_SQL: Readonly<Record<IsolationLevel, string>>;
|
|
11
|
+
/** `BEGIN`, with an `ISOLATION LEVEL` clause when the caller asked for one. */
|
|
12
|
+
export declare function beginStatement(params: {
|
|
13
|
+
isolationLevel?: IsolationLevel;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* `SET LOCAL statement_timeout = <ms>` — transaction-scoped, so PostgreSQL
|
|
17
|
+
* cancels an over-long statement with SQLSTATE 57014 (mapped to
|
|
18
|
+
* `VIBE_TRANSACTION` with `meta.reason = "timeout"`).
|
|
19
|
+
*
|
|
20
|
+
* @throws VibeError `VIBE_VALIDATION` when the timeout is not a non-negative
|
|
21
|
+
* integer — the value is interpolated into SQL, so it is never trusted blindly.
|
|
22
|
+
*/
|
|
23
|
+
export declare function statementTimeoutStatement(params: {
|
|
24
|
+
timeout: number;
|
|
25
|
+
}): string;
|
|
26
|
+
/** How a raw statement steers the adapter's session-affine raw transaction. */
|
|
27
|
+
export type RawTransactionControl = "open" | "close" | null;
|
|
28
|
+
/**
|
|
29
|
+
* Classify a raw statement as transaction control.
|
|
30
|
+
*
|
|
31
|
+
* @vibeorm/migrate drives transactional DDL by sending literal `BEGIN` /
|
|
32
|
+
* `COMMIT` / `ROLLBACK` through its stateless `SqlExecutor` — sound only when
|
|
33
|
+
* every statement in between rides the SAME connection. The adapter uses this
|
|
34
|
+
* to pin one connection for the whole raw transaction ("open" reserves,
|
|
35
|
+
* "close" releases). On a pooled bun:sql instance an unpinned `BEGIN` is
|
|
36
|
+
* refused outright by the driver (`ERR_POSTGRES_UNSAFE_TRANSACTION`); other
|
|
37
|
+
* pool drivers would only work by checkout luck.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately strict: only PURE single-statement control text matches
|
|
40
|
+
* (`BEGIN`, `BEGIN ISOLATION LEVEL …;`, `COMMIT`, `ROLLBACK WORK`, `END`,
|
|
41
|
+
* `ABORT`). Compound scripts, `ROLLBACK TO SAVEPOINT`, two-phase
|
|
42
|
+
* `COMMIT PREPARED` and `COMMIT AND CHAIN` (which keeps a transaction open)
|
|
43
|
+
* never engage the pinning.
|
|
44
|
+
*/
|
|
45
|
+
export declare function classifyRawTransactionControl(params: {
|
|
46
|
+
text: string;
|
|
47
|
+
}): RawTransactionControl;
|
|
48
|
+
/**
|
|
49
|
+
* Refuse options on a NESTED `transaction()` call — the same contract on every
|
|
50
|
+
* adapter (see the `DatabaseAdapter.transaction` JSDoc in @vibeorm/runtime):
|
|
51
|
+
* a nested transaction is a SAVEPOINT, and a savepoint can neither change the
|
|
52
|
+
* isolation level of the transaction it joins nor enforce its own timeout.
|
|
53
|
+
* Silently dropping the option (the pre-#3 behaviour) hid exactly that.
|
|
54
|
+
*
|
|
55
|
+
* @throws VibeError `VIBE_VALIDATION` when `isolationLevel` or `timeout` is
|
|
56
|
+
* present (an `undefined` or empty options object is accepted).
|
|
57
|
+
*/
|
|
58
|
+
export declare function refuseNestedTransactionOptions(params: {
|
|
59
|
+
options?: TransactionOptions;
|
|
60
|
+
provider: string;
|
|
61
|
+
}): void;
|
|
62
|
+
//# sourceMappingURL=transaction-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sql.d.ts","sourceRoot":"","sources":["../src/transaction-sql.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAIvE,CAAC;AAEH,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,GAAG,MAAM,CAKlF;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAU7E;AAID,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAK5D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CAI7F;AAID;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE;IACrD,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAkBP"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/adapter-bun",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
|
+
"description": "bun:sql (Postgres) adapter for VibeORM v2",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"orm",
|
|
8
|
-
"
|
|
7
|
+
"typescript",
|
|
8
|
+
"sql",
|
|
9
|
+
"database",
|
|
9
10
|
"bun",
|
|
11
|
+
"type-safe",
|
|
12
|
+
"postgres",
|
|
10
13
|
"postgresql",
|
|
11
|
-
"
|
|
14
|
+
"bun-sql",
|
|
15
|
+
"adapter",
|
|
16
|
+
"driver"
|
|
12
17
|
],
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"default": "./src/index.ts",
|
|
17
|
-
"types": "./src/index.ts"
|
|
18
|
-
}
|
|
18
|
+
"homepage": "https://github.com/vibeorm/vibeorm/tree/master/packages/adapter-bun#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/vibeorm/vibeorm/issues"
|
|
19
21
|
},
|
|
20
|
-
"files": [
|
|
21
|
-
"src"
|
|
22
|
-
],
|
|
23
22
|
"repository": {
|
|
24
23
|
"type": "git",
|
|
25
24
|
"url": "https://github.com/vibeorm/vibeorm.git",
|
|
26
25
|
"directory": "packages/adapter-bun"
|
|
27
26
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "VibeORM contributors",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
31
35
|
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
32
40
|
"engines": {
|
|
33
|
-
"bun": ">=1.
|
|
41
|
+
"bun": ">=1.2.0"
|
|
34
42
|
},
|
|
35
43
|
"dependencies": {
|
|
36
|
-
"@vibeorm/runtime": "
|
|
44
|
+
"@vibeorm/runtime": "2.0.0-alpha.2",
|
|
45
|
+
"@vibeorm/schema": "2.0.0-alpha.2"
|
|
37
46
|
},
|
|
38
47
|
"publishConfig": {
|
|
39
48
|
"access": "public"
|