@vibeorm/adapter-bun 2.4.0 → 3.0.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/params.d.ts CHANGED
@@ -1,21 +1,24 @@
1
1
  /**
2
- * Parameter serialization for bun:sql.
2
+ * Parameter serialization for bun:sql: the values node-postgres would send.
3
3
  *
4
- * Verified against Bun 1.3 (re-verified on 1.3.14; `tests/live.test.ts` and
5
- * the notes below):
6
- * - a plain object or array bound to a `json`/`jsonb` column is JSON-encoded by
7
- * bun:sql itself — encoding it here as well double-encodes it and stores a
8
- * JSON *string* (`jsonb_typeof` = `"string"`), so the ORM path must not touch it;
4
+ * Live-verified on Bun 1.4.1 and 1.4.3 (`tests/node-postgres-parity.live.test.ts`):
5
+ * - bun:sql types a JS number itself (int32 → `int4`, anything else →
6
+ * `float8`) and lets the SERVER cast from that type, so numbers, bigints and
7
+ * booleans go out as text and the server reads them as the slot's own type;
9
8
  * - a plain JS array bound to a scalar-list column (`text[]`, `int[]`) is NOT
10
9
  * turned into a PostgreSQL array literal by bun:sql — it arrives as `a,b` and
11
10
  * the server rejects it with `malformed array literal`. Scalar lists therefore
12
11
  * have to be pre-rendered with {@link toPgArrayLiteral}, which is exactly what
13
- * the adapter's `formatArrayParam` returns.
12
+ * the adapter's `formatArrayParam` returns;
13
+ * - with NAMED statements (`preparedStatements: true`) bun:sql learns each
14
+ * slot's type first and JSON-encodes whatever is bound to a `json`/`jsonb`
15
+ * slot, a string included; with unnamed statements (the default) a string is
16
+ * sent as text and the server parses it, like node-postgres.
14
17
  *
15
- * Hence the split (LEARNINGS.md): the ORM path passes values through (scalar
16
- * lists already arrived as literal strings), while the raw path renders plain JS
17
- * arrays as array literals so `db.$queryRawUnsafe('… = ANY($1)', [1, 2, 3])`
18
- * matches rows.
18
+ * Hence the split (LEARNINGS.md): the ORM path only respells scalars (scalar
19
+ * lists already arrived as literal strings, Json values as JSON text bound
20
+ * through `::text::jsonb`), while the raw path renders plain JS arrays as array
21
+ * literals so `db.$queryRawUnsafe('… = ANY($1)', [1, 2, 3])` matches rows.
19
22
  */
20
23
  /**
21
24
  * Render a JS array as a PostgreSQL array literal string.
@@ -29,9 +32,10 @@
29
32
  * - any other object, **including a nested array** → quoted `JSON.stringify`,
30
33
  * which is what a `Json[]` scalar list needs (PostgreSQL scalar lists are
31
34
  * one-dimensional, so a nested array is a JSON value, not a matrix)
32
- * - binary (`Uint8Array` / `ArrayBuffer`) → unsupported, throws
35
+ * - `Uint8Array` (including `Buffer`) → quoted PostgreSQL bytea hex
36
+ * - other binary views / `ArrayBuffer` → unsupported, throws
33
37
  *
34
- * @throws VibeError `VIBE_VALIDATION` for binary elements.
38
+ * @throws VibeError `VIBE_VALIDATION` for unsupported binary elements.
35
39
  */
36
40
  export declare function toPgArrayLiteral(values: readonly unknown[]): string;
37
41
  /**
@@ -52,26 +56,36 @@ export declare function serializeDate(params: {
52
56
  value: Date;
53
57
  }): unknown;
54
58
  /**
55
- * ORM hot path: pass every value straight to bun:sql, except `Date`
56
- * ({@link serializeDate}).
59
+ * ORM hot path, node-postgres's rules (`@vibeorm/adapter-pg` `serializeParams`):
60
+ * scalars as text ({@link serializeScalar}), `Date` as UTC ISO text
61
+ * ({@link serializeDate}), any other object or array as `JSON.stringify` text,
62
+ * binary untouched.
57
63
  *
58
- * Scalar lists already arrived as array-literal strings from
59
- * `formatArrayParam`, and bun:sql JSON-encodes objects and arrays for
60
- * `json`/`jsonb` columns by itself — re-encoding here would store a
61
- * double-encoded JSON string.
64
+ * The runtime itself binds no objects here — scalar lists arrive as
65
+ * array-literal strings from `formatArrayParam`, Json values as JSON text bound
66
+ * through `::text::jsonb`, Bytes as `Uint8Array` — but a direct
67
+ * `adapter.execute` caller binding a document gets the same result as on
68
+ * adapter-pg. With `namedStatements` (the adapter's `preparedStatements: true`)
69
+ * objects stay objects: bun:sql JSON-encodes them for a `json`/`jsonb` slot
70
+ * itself, and would encode pre-stringified text a second time.
62
71
  */
63
72
  export declare function serializeParams(params: {
64
73
  values: readonly unknown[];
74
+ namedStatements?: boolean;
65
75
  }): unknown[];
66
76
  /**
67
- * Raw path: render plain JS arrays as PostgreSQL array literals so
68
- * `db.$queryRawUnsafe('… WHERE "id" = ANY($1)', [1, 2, 3])` matches rows;
69
- * everything else (objects included) goes to bun:sql untouched.
77
+ * Raw path: the node-postgres rules (`prepareValue`), so a raw statement binds
78
+ * the same text on both postgres adapters — plain JS arrays as PostgreSQL
79
+ * array literals (`db.$queryRawUnsafe('… WHERE "id" = ANY($1)', [1, 2, 3])`
80
+ * matches rows), any other object except binary as `JSON.stringify` text,
81
+ * scalars as text ({@link serializeScalar}). `namedStatements` keeps objects as
82
+ * objects, for the reason given at {@link serializeParams}.
70
83
  *
71
84
  * Trade-off (v1 lesson): binding a JS array **into** a `jsonb` column from a raw
72
85
  * query means calling `JSON.stringify` yourself.
73
86
  */
74
87
  export declare function serializeParamsRaw(params: {
75
88
  values: readonly unknown[];
89
+ namedStatements?: boolean;
76
90
  }): unknown[];
77
91
  //# sourceMappingURL=params.d.ts.map
@@ -27,6 +27,8 @@ export type PreparedTemplate = {
27
27
  readonly template: TemplateStringsArray;
28
28
  /** 1-based `$n` for each gap, in TEXT order (`SELECT $2, $1` → `[2, 1]`). */
29
29
  readonly indices: readonly number[];
30
+ /** Every gap is $1, $2, ... exactly once, with no reordering. */
31
+ readonly identityOrder: boolean;
30
32
  };
31
33
  /** LRU map from SQL text to the synthetic template used to execute it. */
32
34
  export type TemplateCache = {
@@ -8,10 +8,37 @@
8
8
  import type { IsolationLevel } from "@vibeorm/runtime";
9
9
  /** VibeORM isolation level → PostgreSQL isolation level keyword. */
10
10
  export declare const ISOLATION_LEVEL_SQL: Readonly<Record<IsolationLevel, string>>;
11
- /** `BEGIN`, with an `ISOLATION LEVEL` clause when the caller asked for one. */
11
+ /**
12
+ * `BEGIN`, with an `ISOLATION LEVEL` clause and/or `READ ONLY` when the caller
13
+ * asked for them (`BEGIN ISOLATION LEVEL SERIALIZABLE, READ ONLY`).
14
+ */
12
15
  export declare function beginStatement(params: {
13
16
  isolationLevel?: IsolationLevel;
17
+ readOnly?: boolean;
14
18
  }): string;
19
+ /**
20
+ * The whole opening of a reserved-path transaction as ONE simple-protocol
21
+ * message (round-trip EPIC 3, A-05): `BEGIN …` alone, or `BEGIN …; SET LOCAL
22
+ * statement_timeout = N` when a timeout is requested — one wait instead of
23
+ * two. Parameterless text from validated values; PostgreSQL stops at the first
24
+ * failing statement and the driver rejects with that error, so the caller sees
25
+ * BEGIN's or the SET's own error exactly as when they were two messages.
26
+ *
27
+ * @throws VibeError `VIBE_VALIDATION` for an invalid timeout (before anything
28
+ * is sent).
29
+ */
30
+ export declare function openTransactionStatement(params: {
31
+ isolationLevel?: IsolationLevel;
32
+ readOnly?: boolean;
33
+ timeout?: number;
34
+ }): string;
35
+ /**
36
+ * The cancel deadline's per-statement bound (round-trip EPIC 6): a CONSTANT
37
+ * extended-protocol text, with the milliseconds bound as a string `$1`, so
38
+ * bun:sql keeps it prepared and pipelines it with the statement it bounds.
39
+ * `is_local = true` makes it transaction-scoped, like `SET LOCAL`.
40
+ */
41
+ export declare const STATEMENT_BOUND_TEXT: string;
15
42
  /**
16
43
  * `SET LOCAL statement_timeout = <ms>` — transaction-scoped, so PostgreSQL
17
44
  * cancels an over-long statement with SQLSTATE 57014 (mapped to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeorm/adapter-bun",
3
- "version": "2.4.0",
3
+ "version": "3.0.0",
4
4
  "description": "bun:sql (Postgres) adapter for VibeORM v2",
5
5
  "keywords": [
6
6
  "orm",
@@ -35,15 +35,17 @@
35
35
  },
36
36
  "files": [
37
37
  "dist",
38
- "README.md"
38
+ "!dist/**/*.d.ts.map",
39
+ "README.md",
40
+ "LICENSE"
39
41
  ],
40
42
  "engines": {
41
- "bun": ">=1.2.0"
43
+ "bun": ">=1.4.1"
42
44
  },
43
45
  "dependencies": {
44
- "@vibeorm/runtime": "2.5.0",
45
- "@vibeorm/schema": "2.5.0",
46
- "@vibeorm/sql": "2.5.0"
46
+ "@vibeorm/runtime": "3.0.0",
47
+ "@vibeorm/schema": "3.0.0",
48
+ "@vibeorm/sql": "3.0.0"
47
49
  },
48
50
  "publishConfig": {
49
51
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAKlF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-url.d.ts","sourceRoot":"","sources":["../src/connection-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAEhF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,aAAa,EAAE,aAAa,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,GAAG,SAAS,CAerB;AAED,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAS3F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,GAAG,CAE5F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhE;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAyC3E,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMhE,CAAC;AAYH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAS/E;AAID;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CA8BvE;AAED,wEAAwE;AACxE,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAMnE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAEV,eAAe,EAMhB,MAAM,kBAAkB,CAAC;AAsB1B,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAyEnG,sCAAsC;AACtC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,oGAAoG;IACpG,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAA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EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1 +0,0 @@
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;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAM9D;AAED;;;;;;;;GAQG;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,CAMpF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"template-cache.d.ts","sourceRoot":"","sources":["../src/template-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,gFAAgF;AAChF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG;IAC1B,4EAA4E;IAC5E,WAAW,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,gBAAgB,CAAC;IACxD,8DAA8D;IAC9D,IAAI,IAAI,MAAM,CAAC;CAChB,CAAC;AA0EF;;;GAGG;AACH,w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