@vibeorm/adapter-bun 5.0.1 → 5.0.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 +8 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +106 -12
- package/dist/index.js.map +7 -6
- package/dist/params.d.ts +3 -1
- package/dist/raw-json-text.d.ts +55 -0
- package/dist/template-cache.d.ts +5 -0
- package/package.json +4 -4
package/dist/params.d.ts
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
* - with NAMED statements (`preparedStatements: true`) bun:sql learns each
|
|
14
14
|
* slot's type first and JSON-encodes whatever is bound to a `json`/`jsonb`
|
|
15
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.
|
|
16
|
+
* sent as text and the server parses it, like node-postgres. The raw path
|
|
17
|
+
* respells a slot the text casts to json/jsonb as `$n::text::…` when its
|
|
18
|
+
* value is an original JS string (`raw-json-text.ts`).
|
|
17
19
|
*
|
|
18
20
|
* Hence the split (LEARNINGS.md): the ORM path only respells scalars (scalar
|
|
19
21
|
* lists already arrived as literal strings, Json values as JSON text bound
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw path with NAMED statements (`preparedStatements: true`): JSON text bound
|
|
3
|
+
* to a `json` / `jsonb` slot reaches the server as the document text, as it
|
|
4
|
+
* does with unnamed statements and on adapter-pg.
|
|
5
|
+
*
|
|
6
|
+
* bun:sql learns each slot's type from the server before it binds, and
|
|
7
|
+
* JSON-encodes WHATEVER JavaScript value it binds to a `json` / `jsonb` slot —
|
|
8
|
+
* a string too, so `'{"a":1}'` bound to `$1::jsonb` was stored as the jsonb
|
|
9
|
+
* STRING `"{\"a\":1}"` (live on Bun 1.4.4: `jsonb_to_recordset($1::jsonb)`
|
|
10
|
+
* then fails with "cannot call jsonb_to_recordset on a non-array"). No
|
|
11
|
+
* JavaScript value is sent as raw text into such a slot: a `Buffer` makes the
|
|
12
|
+
* slot `bytea`, and `JSON.rawJSON` refuses objects and arrays.
|
|
13
|
+
*
|
|
14
|
+
* So the slot itself is respelled: a placeholder whose EVERY reference in the
|
|
15
|
+
* text is a direct cast to the same type, `json` or `jsonb` (`$1::jsonb`,
|
|
16
|
+
* `CAST($1 AS json)`), and whose ORIGINAL value is a JS string goes out as
|
|
17
|
+
* `$1::text::jsonb` / `CAST($1::text AS json)`. The slot is then `text`,
|
|
18
|
+
* bun:sql sends the string as it is, and the server parses it with the same
|
|
19
|
+
* input function as before — byte-exact for `json`, numbers of any precision,
|
|
20
|
+
* and an invalid document refused by the SERVER (SQLSTATE 22P02), exactly as
|
|
21
|
+
* with unnamed statements. Every non-string input keeps its prior behavior,
|
|
22
|
+
* including values the raw serializer converts to text (arrays and scalars).
|
|
23
|
+
*
|
|
24
|
+
* Out of reach, and documented: a slot whose type the server infers from
|
|
25
|
+
* context (`INSERT … VALUES ($1)` into a jsonb column, a function argument)
|
|
26
|
+
* cannot be seen in the text, so bun:sql still JSON-encodes a string bound
|
|
27
|
+
* there. Spell `$n::jsonb` (or `$n::text::jsonb`).
|
|
28
|
+
*/
|
|
29
|
+
/** One raw text split at its placeholders, with the slots that are certainly `json` / `jsonb`. */
|
|
30
|
+
export type JsonSlotPlan = {
|
|
31
|
+
readonly chunks: readonly string[];
|
|
32
|
+
readonly indices: readonly number[];
|
|
33
|
+
/** 1-based placeholders whose every reference is a direct cast to the SAME json type. */
|
|
34
|
+
readonly slots: ReadonlySet<number>;
|
|
35
|
+
};
|
|
36
|
+
/** Respells raw texts for named statements; bounded LRU of the per-text scan. */
|
|
37
|
+
export type JsonTextRespeller = {
|
|
38
|
+
/**
|
|
39
|
+
* The text to send for the ORIGINAL values, before serialization: `text`
|
|
40
|
+
* itself unless a certain json/jsonb slot was given a JS string.
|
|
41
|
+
*/
|
|
42
|
+
readonly respell: (params: {
|
|
43
|
+
readonly text: string;
|
|
44
|
+
readonly values: readonly unknown[];
|
|
45
|
+
}) => string;
|
|
46
|
+
};
|
|
47
|
+
/** Scan `text` once: which placeholders are certainly `json` / `jsonb` slots. `null` = none. */
|
|
48
|
+
export declare function planJsonSlots(params: {
|
|
49
|
+
text: string;
|
|
50
|
+
}): JsonSlotPlan | null;
|
|
51
|
+
/** Build a respeller whose scan cache holds at most `max` texts. */
|
|
52
|
+
export declare function createJsonTextRespeller(params: {
|
|
53
|
+
max: number;
|
|
54
|
+
}): JsonTextRespeller;
|
|
55
|
+
//# sourceMappingURL=raw-json-text.d.ts.map
|
package/dist/template-cache.d.ts
CHANGED
|
@@ -44,6 +44,11 @@ export type TemplateCache = {
|
|
|
44
44
|
/** Number of texts currently held — diagnostics and tests. */
|
|
45
45
|
size(): number;
|
|
46
46
|
};
|
|
47
|
+
/** Skip PostgreSQL whitespace and comments, including nested block comments and CR line endings. */
|
|
48
|
+
export declare function skipSqlTrivia(params: {
|
|
49
|
+
text: string;
|
|
50
|
+
start: number;
|
|
51
|
+
}): number;
|
|
47
52
|
/**
|
|
48
53
|
* Split `text` at its real `$n` placeholders. `chunks.length` is always
|
|
49
54
|
* `indices.length + 1`, which is exactly the shape a tagged template needs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/adapter-bun",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "bun:sql (Postgres) adapter for VibeORM v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"bun": ">=1.4.1"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@vibeorm/runtime": "5.
|
|
47
|
-
"@vibeorm/schema": "5.
|
|
48
|
-
"@vibeorm/sql": "5.0
|
|
46
|
+
"@vibeorm/runtime": "5.2.0",
|
|
47
|
+
"@vibeorm/schema": "5.1.0",
|
|
48
|
+
"@vibeorm/sql": "5.1.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|