@pgxsinkit/pgwasm 0.5.1 → 0.6.0-rc.1
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 +1 -1
- package/dist/chunk-0w227vw2.js.map +1 -1
- package/dist/{chunk-gjf102c9.js → chunk-8q0zqcbv.js} +66 -66
- package/dist/{chunk-gjf102c9.js.map → chunk-8q0zqcbv.js.map} +4 -4
- package/dist/{chunk-d82gg1hx.js → chunk-jnmd6w7f.js} +1 -1
- package/dist/{chunk-d82gg1hx.js.map → chunk-jnmd6w7f.js.map} +2 -2
- package/dist/{chunk-at1py5s5.js → chunk-s6a029ak.js} +14 -9
- package/dist/chunk-s6a029ak.js.map +12 -0
- package/dist/{chunk-74gcrk47.js → chunk-t3q74nsz.js} +18 -4
- package/dist/{chunk-74gcrk47.js.map → chunk-t3q74nsz.js.map} +4 -4
- package/dist/chunk-z0c40tja.js.map +1 -1
- package/dist/{chunk-tdvrvgt5.js → chunk-zm269na3.js} +2 -2
- package/dist/{chunk-tdvrvgt5.js.map → chunk-zm269na3.js.map} +1 -1
- package/dist/drizzle/codecs.d.ts +5 -2
- package/dist/drizzle/codecs.d.ts.map +1 -1
- package/dist/drizzle/driver.d.ts.map +1 -1
- package/dist/drizzle/index.js +42 -27
- package/dist/drizzle/index.js.map +5 -5
- package/dist/drizzle/session.d.ts +2 -6
- package/dist/drizzle/session.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/live/index.d.ts.map +1 -1
- package/dist/live/index.js +5 -4
- package/dist/live/index.js.map +3 -3
- package/dist/opfs/index.js +2 -2
- package/dist/opfs/index.js.map +1 -1
- package/dist/protocol/index.js +2 -2
- package/dist/protocol/wire/buffer-reader.d.ts +1 -0
- package/dist/protocol/wire/buffer-reader.d.ts.map +1 -1
- package/dist/protocol/wire/buffer-writer.d.ts +1 -0
- package/dist/protocol/wire/buffer-writer.d.ts.map +1 -1
- package/dist/protocol/wire/serializer.d.ts.map +1 -1
- package/package.json +6 -2
- package/skills/opfs/SKILL.md +5 -3
- package/src/drizzle/codecs.ts +43 -25
- package/src/drizzle/driver.ts +1 -0
- package/src/drizzle/session.ts +3 -3
- package/src/live/index.ts +1 -0
- package/src/protocol/wire/buffer-reader.ts +6 -0
- package/src/protocol/wire/buffer-writer.ts +7 -0
- package/src/protocol/wire/parser.ts +1 -1
- package/src/protocol/wire/serializer.ts +12 -6
- package/dist/chunk-at1py5s5.js.map +0 -12
package/dist/protocol/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
Modes2,
|
|
4
4
|
Parser2
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-s6a029ak.js";
|
|
6
6
|
import {
|
|
7
7
|
exports_messages,
|
|
8
8
|
serialize2,
|
|
9
9
|
protocolAccessOf
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-t3q74nsz.js";
|
|
11
11
|
// packages/pgwasm/src/protocol/index.ts
|
|
12
12
|
function protocol(pg) {
|
|
13
13
|
return protocolAccessOf(pg);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-reader.d.ts","sourceRoot":"","sources":["../../../src/protocol/wire/buffer-reader.ts"],"names":[],"mappings":"AAMA,sEAAsE;AACtE,qBAAa,YAAY;;IAKvB,YAAY,MAAM,SAAI,EAErB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAGvD;IAED,KAAK,IAAI,MAAM,CAId;IAED,IAAI,IAAI,MAAM,CAIb;IAED,KAAK,IAAI,MAAM,CAId;IAED,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7B;IAED,OAAO,IAAI,MAAM,CAShB;IAED,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAIhC;CACF"}
|
|
1
|
+
{"version":3,"file":"buffer-reader.d.ts","sourceRoot":"","sources":["../../../src/protocol/wire/buffer-reader.ts"],"names":[],"mappings":"AAMA,sEAAsE;AACtE,qBAAa,YAAY;;IAKvB,YAAY,MAAM,SAAI,EAErB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAGvD;IAED,KAAK,IAAI,MAAM,CAId;IAED,MAAM,IAAI,MAAM,CAIf;IAED,IAAI,IAAI,MAAM,CAIb;IAED,KAAK,IAAI,MAAM,CAId;IAED,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7B;IAED,OAAO,IAAI,MAAM,CAShB;IAED,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAIhC;CACF"}
|
|
@@ -4,6 +4,7 @@ export declare class Writer {
|
|
|
4
4
|
constructor(size?: number);
|
|
5
5
|
addInt32(num: number): Writer;
|
|
6
6
|
addInt16(num: number): Writer;
|
|
7
|
+
addUint16(num: number): Writer;
|
|
7
8
|
addCString(string: string): Writer;
|
|
8
9
|
addString(string?: string): Writer;
|
|
9
10
|
add(otherBuffer: ArrayBuffer | ArrayBufferView): Writer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-writer.d.ts","sourceRoot":"","sources":["../../../src/protocol/wire/buffer-writer.ts"],"names":[],"mappings":"AAMA,2FAA2F;AAC3F,qBAAa,MAAM;;IAOjB,YAAY,IAAI,SAAM,EAGrB;IAiBD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5B;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5B;IAED,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQjC;IAED,SAAS,CAAC,MAAM,SAAK,GAAG,MAAM,CAM7B;IAED,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,GAAG,MAAM,CAQtD;IAYD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAK5C;CACF"}
|
|
1
|
+
{"version":3,"file":"buffer-writer.d.ts","sourceRoot":"","sources":["../../../src/protocol/wire/buffer-writer.ts"],"names":[],"mappings":"AAMA,2FAA2F;AAC3F,qBAAa,MAAM;;IAOjB,YAAY,IAAI,SAAM,EAGrB;IAiBD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5B;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5B;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK7B;IAED,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQjC;IAED,SAAS,CAAC,MAAM,SAAK,GAAG,MAAM,CAM7B;IAED,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,GAAG,MAAM,CAQtD;IAYD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAK5C;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../../src/protocol/wire/serializer.ts"],"names":[],"mappings":"AAyBA,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,CAAC;AAIvE,iBAAS,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAWtE;AAED,iBAAS,UAAU,IAAI,UAAU,CAAC,WAAW,CAAC,CAK7C;AAED,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAExD;AAED,iBAAS,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAG3G;AAED,iBAAS,2BAA2B,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAEpF;AA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AGtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/pgwasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-rc.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"main": "./dist/index.js",
|
|
20
|
+
"browser": {
|
|
21
|
+
"fs": false,
|
|
22
|
+
"node:fs": false
|
|
23
|
+
},
|
|
20
24
|
"types": "./dist/index.d.ts",
|
|
21
25
|
"exports": {
|
|
22
26
|
".": {
|
|
@@ -55,7 +59,7 @@
|
|
|
55
59
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
56
60
|
},
|
|
57
61
|
"peerDependencies": {
|
|
58
|
-
"drizzle-orm": "
|
|
62
|
+
"drizzle-orm": "rc"
|
|
59
63
|
},
|
|
60
64
|
"peerDependenciesMeta": {
|
|
61
65
|
"drizzle-orm": {
|
package/skills/opfs/SKILL.md
CHANGED
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: task
|
|
14
14
|
library: "@pgxsinkit/pgwasm"
|
|
15
|
-
library_version: "0.
|
|
15
|
+
library_version: "0.6.0-rc.1"
|
|
16
16
|
source: https://pgxsinkit.github.io/packages/pgwasm/
|
|
17
17
|
---
|
|
18
18
|
|
|
@@ -28,9 +28,11 @@ shutdown.
|
|
|
28
28
|
Create one otherwise-empty OPFS directory per database and pass its handle to the factory with the build:
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/// <reference lib="webworker" />
|
|
32
|
+
|
|
33
33
|
import { cBuild } from "@pgxsinkit/pgwasm-c";
|
|
34
|
+
import { live } from "@pgxsinkit/pgwasm/live";
|
|
35
|
+
import { createOpfsPgwasm, strictSync } from "@pgxsinkit/pgwasm/opfs";
|
|
34
36
|
|
|
35
37
|
const root = await navigator.storage.getDirectory();
|
|
36
38
|
const directory = await root.getDirectoryHandle("app-database", { create: true });
|
package/src/drizzle/codecs.ts
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its
|
|
3
3
|
// own database. Owned outright (ADR-0062).
|
|
4
4
|
|
|
5
|
+
import type { NormalizeCodec } from "drizzle-orm/codecs";
|
|
5
6
|
import { makePgArray, parsePgArray } from "drizzle-orm/pg-core/array";
|
|
6
7
|
import {
|
|
7
8
|
arrayCompatNormalize,
|
|
8
9
|
castToText,
|
|
9
10
|
castToTextArr,
|
|
10
11
|
genericPgCodecs,
|
|
12
|
+
makeGeometryArray,
|
|
13
|
+
parseGeometryArrayAndNormalize,
|
|
11
14
|
parseGeometryTuple,
|
|
12
15
|
parseGeometryXY,
|
|
13
|
-
parsePgArrayAndNormalize,
|
|
14
16
|
refineGenericPgCodecs,
|
|
15
17
|
textToDate,
|
|
16
18
|
textToDateWithTz,
|
|
@@ -18,25 +20,28 @@ import {
|
|
|
18
20
|
} from "drizzle-orm/pg-core/codecs";
|
|
19
21
|
import { base64ToUint8Array } from "drizzle-orm/utils";
|
|
20
22
|
|
|
21
|
-
import { DATE, INTERVAL, TIMESTAMP, TIMESTAMPTZ } from "../types";
|
|
23
|
+
import { arrayParser, DATE, INTERVAL, TIMESTAMP, TIMESTAMPTZ, type Parser } from "../types";
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* The identity parsers the driver passes with every query: these types reach drizzle as Postgres'
|
|
25
|
-
* text, and drizzle's codecs turn them into values
|
|
27
|
+
* text, and drizzle's codecs turn them into values. Array parsers keep each element's text while
|
|
28
|
+
* preserving PostgreSQL nulls and dimensions; the scalar Date parser must not run before Drizzle's
|
|
29
|
+
* mode-specific normalizer. Numeric arrays use pgwasm's native precision-preserving parser.
|
|
26
30
|
*/
|
|
27
|
-
export const drizzleParsers: Readonly<Record<number,
|
|
31
|
+
export const drizzleParsers: Readonly<Record<number, Parser>> = {
|
|
28
32
|
[TIMESTAMP]: (value) => value,
|
|
29
33
|
[TIMESTAMPTZ]: (value) => value,
|
|
30
34
|
[INTERVAL]: (value) => value,
|
|
31
35
|
[DATE]: (value) => value,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
1182: (value) => value, // date[]
|
|
36
|
+
1115: (value) => arrayParser(value, undefined, 1115), // timestamp[]
|
|
37
|
+
1185: (value) => arrayParser(value, undefined, 1185), // timestamptz[]
|
|
38
|
+
1187: (value) => arrayParser(value, undefined, 1187), // interval[]
|
|
39
|
+
1182: (value) => arrayParser(value, undefined, 1182), // date[]
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
const hasBuffer = typeof Buffer !== "undefined";
|
|
43
|
+
const normalizeNullableArray = (normalize: NormalizeCodec) =>
|
|
44
|
+
arrayCompatNormalize((value) => (value === null ? null : normalize(value)));
|
|
40
45
|
|
|
41
46
|
/** drizzle's codecs for pgwasm's value formats (the text protocol, pgwasm's default parsers). */
|
|
42
47
|
export const pgwasmCodecs: PgCodecs = refineGenericPgCodecs({
|
|
@@ -44,71 +49,84 @@ export const pgwasmCodecs: PgCodecs = refineGenericPgCodecs({
|
|
|
44
49
|
cast: castToText,
|
|
45
50
|
castArray: castToTextArr,
|
|
46
51
|
normalize: BigInt,
|
|
47
|
-
normalizeArray:
|
|
52
|
+
normalizeArray: normalizeNullableArray(BigInt),
|
|
48
53
|
},
|
|
49
54
|
"bigint:string": { cast: castToText, castArray: castToTextArr },
|
|
50
|
-
"bigint:number": {
|
|
55
|
+
"bigint:number": {
|
|
56
|
+
cast: castToText,
|
|
57
|
+
castArray: castToTextArr,
|
|
58
|
+
normalize: Number,
|
|
59
|
+
normalizeArray: normalizeNullableArray(Number),
|
|
60
|
+
},
|
|
51
61
|
bigserial: {
|
|
52
62
|
normalize: BigInt,
|
|
53
|
-
normalizeArray:
|
|
63
|
+
normalizeArray: normalizeNullableArray(BigInt),
|
|
64
|
+
cast: castToText,
|
|
65
|
+
castArray: castToTextArr,
|
|
66
|
+
},
|
|
67
|
+
"bigserial:number": {
|
|
54
68
|
cast: castToText,
|
|
55
69
|
castArray: castToTextArr,
|
|
70
|
+
normalize: Number,
|
|
71
|
+
normalizeArray: normalizeNullableArray(Number),
|
|
56
72
|
},
|
|
57
|
-
"
|
|
73
|
+
"numeric:number": { normalize: Number, normalizeArray: normalizeNullableArray(Number) },
|
|
74
|
+
"numeric:bigint": { normalize: BigInt, normalizeArray: normalizeNullableArray(BigInt) },
|
|
58
75
|
bytea: hasBuffer
|
|
59
76
|
? {
|
|
60
77
|
normalizeInJson: genericPgCodecs.bytea?.normalizeInJson,
|
|
61
78
|
normalizeArrayInJson: genericPgCodecs.bytea?.normalizeArrayInJson,
|
|
62
79
|
normalize: (value: Uint8Array) => Buffer.from(value),
|
|
63
|
-
normalizeArray:
|
|
80
|
+
normalizeArray: normalizeNullableArray((value: Uint8Array) => Buffer.from(value)),
|
|
64
81
|
}
|
|
65
82
|
: {
|
|
66
83
|
normalizeInJson: base64ToUint8Array,
|
|
67
84
|
normalizeArrayInJson: arrayCompatNormalize(base64ToUint8Array),
|
|
68
85
|
},
|
|
69
86
|
interval: { castArray: castToTextArr },
|
|
70
|
-
date: { castArray: castToTextArr, normalize: textToDate, normalizeArray:
|
|
87
|
+
date: { castArray: castToTextArr, normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
71
88
|
"date:string": { castArray: castToTextArr },
|
|
72
89
|
timestamp: {
|
|
73
90
|
castArray: castToTextArr,
|
|
74
91
|
normalize: textToDateWithTz,
|
|
75
|
-
normalizeArray:
|
|
92
|
+
normalizeArray: normalizeNullableArray(textToDateWithTz),
|
|
76
93
|
},
|
|
77
|
-
timestamptz: { castArray: castToTextArr, normalize: textToDate, normalizeArray:
|
|
94
|
+
timestamptz: { castArray: castToTextArr, normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
78
95
|
"timestamp:string": { castArray: castToTextArr },
|
|
79
96
|
"timestamptz:string": { castArray: castToTextArr },
|
|
80
97
|
json: { normalizeParam: (value: unknown) => (typeof value === "object" ? value : JSON.stringify(value)) },
|
|
81
98
|
jsonb: { normalizeParam: (value: unknown) => (typeof value === "object" ? value : JSON.stringify(value)) },
|
|
82
99
|
"geometry(point)": {
|
|
83
|
-
normalizeArray:
|
|
100
|
+
normalizeArray: parseGeometryArrayAndNormalize(parseGeometryXY),
|
|
84
101
|
castParam: (name: string) => `${name}::geometry`,
|
|
85
102
|
castArrayParam: (name: string, _column: unknown, dimensions: number) =>
|
|
86
103
|
`${name}::geometry${"[]".repeat(dimensions)}`,
|
|
87
|
-
normalizeParamArray:
|
|
104
|
+
normalizeParamArray: makeGeometryArray,
|
|
88
105
|
},
|
|
89
106
|
"geometry(point):tuple": {
|
|
90
|
-
normalizeArray:
|
|
107
|
+
normalizeArray: parseGeometryArrayAndNormalize(parseGeometryTuple),
|
|
91
108
|
castParam: (name: string) => `${name}::geometry`,
|
|
92
109
|
castArrayParam: (name: string, _column: unknown, dimensions: number) =>
|
|
93
110
|
`${name}::geometry${"[]".repeat(dimensions)}`,
|
|
94
|
-
normalizeParamArray:
|
|
111
|
+
normalizeParamArray: makeGeometryArray,
|
|
95
112
|
},
|
|
96
113
|
halfvec: {
|
|
97
114
|
castParam: (name: string) => `${name}::halfvec`,
|
|
98
115
|
castArrayParam: (name: string, _column: unknown, dimensions: number) =>
|
|
99
116
|
`${name}::halfvec${"[]".repeat(dimensions)}`,
|
|
100
|
-
|
|
117
|
+
// Codec callbacks receive array dimensions as their second argument, not a text delimiter.
|
|
118
|
+
normalizeParamArray: (value) => makePgArray(value),
|
|
101
119
|
},
|
|
102
120
|
vector: {
|
|
103
121
|
castParam: (name: string) => `${name}::vector`,
|
|
104
122
|
castArrayParam: (name: string, _column: unknown, dimensions: number) => `${name}::vector${"[]".repeat(dimensions)}`,
|
|
105
|
-
normalizeParamArray: makePgArray,
|
|
123
|
+
normalizeParamArray: (value) => makePgArray(value),
|
|
106
124
|
},
|
|
107
125
|
sparsevec: {
|
|
108
|
-
normalizeArray: parsePgArray,
|
|
126
|
+
normalizeArray: (value) => parsePgArray(value),
|
|
109
127
|
castParam: (name: string) => `${name}::sparsevec`,
|
|
110
128
|
castArrayParam: (name: string, _column: unknown, dimensions: number) =>
|
|
111
129
|
`${name}::sparsevec${"[]".repeat(dimensions)}`,
|
|
112
|
-
normalizeParamArray: makePgArray,
|
|
130
|
+
normalizeParamArray: (value) => makePgArray(value),
|
|
113
131
|
},
|
|
114
132
|
});
|
package/src/drizzle/driver.ts
CHANGED
|
@@ -52,6 +52,7 @@ function construct<TRelations extends AnyRelations, TClient extends PgwasmSessio
|
|
|
52
52
|
const session = new PgwasmSession<TRelations>(client, dialect, relations, {
|
|
53
53
|
...(logger ? { logger } : {}),
|
|
54
54
|
...(config.cache ? { cache: config.cache } : {}),
|
|
55
|
+
...(config.paramsInErrors !== undefined ? { paramsInErrors: config.paramsInErrors } : {}),
|
|
55
56
|
});
|
|
56
57
|
const db = new PgwasmDatabase<TRelations>(dialect, session, relations);
|
|
57
58
|
// `db.$cache.invalidate` is the cache's own invalidation; with no cache it stays the no-op it starts as.
|
package/src/drizzle/session.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { Cache } from "drizzle-orm/cache/core/cache";
|
|
6
6
|
import { NoopCache } from "drizzle-orm/cache/core/cache";
|
|
7
|
-
import type { WithCacheConfig } from "drizzle-orm/cache/core/types";
|
|
7
|
+
import type { QueryMetadata, WithCacheConfig } from "drizzle-orm/cache/core/types";
|
|
8
8
|
import { entityKind } from "drizzle-orm/entity";
|
|
9
9
|
import { NoopLogger, type Logger } from "drizzle-orm/logger";
|
|
10
10
|
import { PgAsyncPreparedQuery, PgAsyncSession, PgAsyncTransaction } from "drizzle-orm/pg-core/async/session";
|
|
@@ -23,14 +23,13 @@ export type PgwasmSessionClient = Pick<Pgwasm, "query"> & Partial<Pick<Pgwasm, "
|
|
|
23
23
|
export interface PgwasmSessionOptions {
|
|
24
24
|
logger?: Logger;
|
|
25
25
|
cache?: Cache;
|
|
26
|
+
paramsInErrors?: boolean;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface PgwasmQueryResultHKT extends PgQueryResultHKT {
|
|
29
30
|
type: Results<Assume<this["row"], Row>>;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
type QueryMetadata = { type: "select" | "update" | "delete" | "insert"; tables: string[] };
|
|
33
|
-
|
|
34
33
|
export class PgwasmSession<TRelations extends AnyRelations> extends PgAsyncSession<PgwasmQueryResultHKT, TRelations> {
|
|
35
34
|
static override readonly [entityKind]: string = "PgwasmSession";
|
|
36
35
|
readonly #client: PgwasmSessionClient;
|
|
@@ -77,6 +76,7 @@ export class PgwasmSession<TRelations extends AnyRelations> extends PgAsyncSessi
|
|
|
77
76
|
this.#cache,
|
|
78
77
|
queryMetadata,
|
|
79
78
|
cacheConfig,
|
|
79
|
+
this.#options.paramsInErrors,
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
|
package/src/live/index.ts
CHANGED
|
@@ -25,6 +25,12 @@ export class BufferReader {
|
|
|
25
25
|
return result;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
uint16(): number {
|
|
29
|
+
const result = this.#bufferView.getUint16(this.#offset, false);
|
|
30
|
+
this.#offset += 2;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
byte(): number {
|
|
29
35
|
const result = this.#bufferView.getUint8(this.#offset);
|
|
30
36
|
this.#offset++;
|
|
@@ -46,6 +46,13 @@ export class Writer {
|
|
|
46
46
|
return this;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
addUint16(num: number): Writer {
|
|
50
|
+
this.#ensure(2);
|
|
51
|
+
this.#bufferView.setUint16(this.#offset, num, false);
|
|
52
|
+
this.#offset += 2;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
addCString(string: string): Writer {
|
|
50
57
|
if (string) {
|
|
51
58
|
this.addString(string);
|
|
@@ -271,7 +271,7 @@ export class Parser {
|
|
|
271
271
|
bytes: ArrayBufferLike,
|
|
272
272
|
): ParameterDescriptionMessage {
|
|
273
273
|
this.#setBuffer(offset, bytes);
|
|
274
|
-
const parameterCount = this.#reader.
|
|
274
|
+
const parameterCount = this.#reader.uint16();
|
|
275
275
|
const dataTypeIDs: number[] = [];
|
|
276
276
|
for (let i = 0; i < parameterCount; i++) {
|
|
277
277
|
dataTypeIDs.push(this.#reader.int32());
|
|
@@ -73,15 +73,20 @@ export interface ParseOpts {
|
|
|
73
73
|
|
|
74
74
|
const emptyValueArray: LegalValue[] = [];
|
|
75
75
|
|
|
76
|
+
function assertParameterCount(count: number): void {
|
|
77
|
+
if (count > 65_535) {
|
|
78
|
+
throw new RangeError(`Postgres messages support at most 65535 parameters (received ${count})`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
function parse(opts: ParseOpts): Uint8Array<ArrayBuffer> {
|
|
77
83
|
const name = opts.name ?? "";
|
|
78
84
|
if (name.length > 63) {
|
|
79
85
|
throw new RangeError(`Postgres statement names are at most 63 characters: "${name}" (${name.length})`);
|
|
80
86
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.addInt16(opts.types?.length ?? 0);
|
|
87
|
+
const typeCount = opts.types?.length ?? 0;
|
|
88
|
+
assertParameterCount(typeCount);
|
|
89
|
+
const buffer = writer.addCString(name).addCString(opts.text).addUint16(typeCount);
|
|
85
90
|
opts.types?.forEach((type) => buffer.addInt32(type));
|
|
86
91
|
return writer.flush(code.parse);
|
|
87
92
|
}
|
|
@@ -128,11 +133,12 @@ function bind(config: BindOpts = {}): Uint8Array<ArrayBuffer> {
|
|
|
128
133
|
const binary = config.binary ?? false;
|
|
129
134
|
const values = config.values ?? emptyValueArray;
|
|
130
135
|
const len = values.length;
|
|
136
|
+
assertParameterCount(len);
|
|
131
137
|
|
|
132
138
|
writer.addCString(portal).addCString(statement);
|
|
133
|
-
writer.
|
|
139
|
+
writer.addUint16(len);
|
|
134
140
|
writeValues(values, config.valueMapper);
|
|
135
|
-
writer.
|
|
141
|
+
writer.addUint16(len);
|
|
136
142
|
writer.add(paramWriter.flush());
|
|
137
143
|
// result format code
|
|
138
144
|
writer.addInt16(binary ? ParamType.BINARY : ParamType.STRING);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/protocol/wire/types.ts", "../src/protocol/wire/buffer-reader.ts", "../src/protocol/wire/parser.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"// Began as a copy of `@electric-sql/pg-protocol`, itself adapted from node-postgres' `pg-protocol`\n// (MIT, © Brian Carlson; ElectricSQL's changes taken under the PostgreSQL License — see NOTICE).\n// Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\nexport const Modes = {\n text: 0,\n binary: 1,\n} as const;\n\nexport type Mode = (typeof Modes)[keyof typeof Modes];\n\nexport type BufferParameter = ArrayBuffer | ArrayBufferView;\n",
|
|
6
|
-
"// Began as a copy of `@electric-sql/pg-protocol`, itself adapted from node-postgres' `pg-protocol`\n// (MIT, © Brian Carlson; ElectricSQL's changes taken under the PostgreSQL License — see NOTICE).\n// Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\nconst emptyBuffer = new ArrayBuffer(0);\n\n/** Big-endian reads over one backend message, advancing an offset. */\nexport class BufferReader {\n #bufferView: DataView = new DataView(emptyBuffer);\n #offset: number;\n readonly #decoder = new TextDecoder(\"utf-8\");\n\n constructor(offset = 0) {\n this.#offset = offset;\n }\n\n setBuffer(offset: number, buffer: ArrayBufferLike): void {\n this.#offset = offset;\n this.#bufferView = new DataView(buffer);\n }\n\n int16(): number {\n const result = this.#bufferView.getInt16(this.#offset, false);\n this.#offset += 2;\n return result;\n }\n\n byte(): number {\n const result = this.#bufferView.getUint8(this.#offset);\n this.#offset++;\n return result;\n }\n\n int32(): number {\n const result = this.#bufferView.getInt32(this.#offset, false);\n this.#offset += 4;\n return result;\n }\n\n string(length: number): string {\n return this.#decoder.decode(this.bytes(length));\n }\n\n cstring(): string {\n const start = this.#offset;\n let end = start;\n while (this.#bufferView.getUint8(end++) !== 0) {\n // advance to the terminator\n }\n const result = this.string(end - start - 1);\n this.#offset = end;\n return result;\n }\n\n bytes(length: number): Uint8Array {\n const result = this.#bufferView.buffer.slice(this.#offset, this.#offset + length);\n this.#offset += length;\n return new Uint8Array(result);\n }\n}\n",
|
|
7
|
-
"// Began as a copy of `@electric-sql/pg-protocol`, itself adapted from node-postgres' `pg-protocol`\n// (MIT, © Brian Carlson; ElectricSQL's changes taken under the PostgreSQL License — see NOTICE).\n// Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\nimport { BufferReader } from \"./buffer-reader\";\nimport {\n AuthenticationCleartextPassword,\n AuthenticationMD5Password,\n AuthenticationOk,\n AuthenticationSASL,\n AuthenticationSASLContinue,\n AuthenticationSASLFinal,\n BackendKeyDataMessage,\n bindComplete,\n closeComplete,\n CommandCompleteMessage,\n CopyDataMessage,\n copyDone,\n CopyResponse,\n DatabaseError,\n DataRowMessage,\n emptyQuery,\n Field,\n noData,\n NoticeMessage,\n NotificationResponseMessage,\n ParameterDescriptionMessage,\n ParameterStatusMessage,\n parseComplete,\n portalSuspended,\n ReadyForQueryMessage,\n replicationStart,\n RowDescriptionMessage,\n type AuthenticationMessage,\n type BackendMessage,\n type MessageName,\n} from \"./messages\";\nimport { Modes, type BufferParameter } from \"./types\";\n\n// Every message starts with one type byte and an int32 length that counts itself but not the type.\nconst CODE_LENGTH = 1;\nconst LEN_LENGTH = 4;\nconst HEADER_LENGTH = CODE_LENGTH + LEN_LENGTH;\n\nconst emptyBuffer = new ArrayBuffer(0);\n\nconst MessageCodes = {\n DataRow: 0x44, // D\n ParseComplete: 0x31, // 1\n BindComplete: 0x32, // 2\n CloseComplete: 0x33, // 3\n CommandComplete: 0x43, // C\n ReadyForQuery: 0x5a, // Z\n NoData: 0x6e, // n\n NotificationResponse: 0x41, // A\n AuthenticationResponse: 0x52, // R\n ParameterStatus: 0x53, // S\n BackendKeyData: 0x4b, // K\n ErrorMessage: 0x45, // E\n NoticeMessage: 0x4e, // N\n RowDescriptionMessage: 0x54, // T\n ParameterDescriptionMessage: 0x74, // t\n PortalSuspended: 0x73, // s\n ReplicationStart: 0x57, // W\n EmptyQuery: 0x49, // I\n CopyIn: 0x47, // G\n CopyOut: 0x48, // H\n CopyDone: 0x63, // c\n CopyData: 0x64, // d\n} as const;\n\nexport type MessageCallback = (msg: BackendMessage) => void;\n\n/**\n * Parses backend messages out of a byte stream that may arrive in arbitrary chunks: a message split\n * across calls is buffered until the rest arrives.\n */\nexport class Parser {\n #bufferView: DataView = new DataView(emptyBuffer);\n #bufferRemainingLength = 0;\n #bufferOffset = 0;\n readonly #reader = new BufferReader();\n\n parse(buffer: BufferParameter, callback: MessageCallback): void {\n this.#mergeBuffer(\n ArrayBuffer.isView(buffer)\n ? buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)\n : buffer,\n );\n const bufferFullLength = this.#bufferOffset + this.#bufferRemainingLength;\n let offset = this.#bufferOffset;\n while (offset + HEADER_LENGTH <= bufferFullLength) {\n const code = this.#bufferView.getUint8(offset);\n const length = this.#bufferView.getUint32(offset + CODE_LENGTH, false);\n const fullMessageLength = CODE_LENGTH + length;\n if (fullMessageLength + offset <= bufferFullLength && length > 0) {\n let message: BackendMessage;\n try {\n message = this.#handlePacket(offset + HEADER_LENGTH, code, length, this.#bufferView.buffer);\n } catch (error) {\n this.#resetBuffer();\n throw error;\n }\n callback(message);\n offset += fullMessageLength;\n } else {\n break;\n }\n }\n if (offset === bufferFullLength) {\n this.#resetBuffer();\n } else {\n this.#bufferRemainingLength = bufferFullLength - offset;\n this.#bufferOffset = offset;\n }\n }\n\n #resetBuffer(): void {\n this.#bufferView = new DataView(emptyBuffer);\n this.#bufferRemainingLength = 0;\n this.#bufferOffset = 0;\n }\n\n #mergeBuffer(buffer: ArrayBufferLike): void {\n if (this.#bufferRemainingLength > 0) {\n const newLength = this.#bufferRemainingLength + buffer.byteLength;\n const newFullLength = newLength + this.#bufferOffset;\n if (newFullLength > this.#bufferView.byteLength) {\n let newBuffer: ArrayBufferLike;\n if (newLength <= this.#bufferView.byteLength && this.#bufferOffset >= this.#bufferRemainingLength) {\n // Move the pending bytes to the front instead of allocating.\n newBuffer = this.#bufferView.buffer;\n } else {\n let newBufferLength = this.#bufferView.byteLength * 2;\n while (newLength >= newBufferLength) {\n newBufferLength *= 2;\n }\n newBuffer = new ArrayBuffer(newBufferLength);\n }\n new Uint8Array(newBuffer).set(\n new Uint8Array(this.#bufferView.buffer, this.#bufferOffset, this.#bufferRemainingLength),\n );\n this.#bufferView = new DataView(newBuffer);\n this.#bufferOffset = 0;\n }\n new Uint8Array(this.#bufferView.buffer).set(\n new Uint8Array(buffer),\n this.#bufferOffset + this.#bufferRemainingLength,\n );\n this.#bufferRemainingLength = newLength;\n } else {\n this.#bufferView = new DataView(buffer);\n this.#bufferOffset = 0;\n this.#bufferRemainingLength = buffer.byteLength;\n }\n }\n\n #handlePacket(offset: number, code: number, length: number, bytes: ArrayBufferLike): BackendMessage {\n switch (code) {\n case MessageCodes.BindComplete:\n return bindComplete;\n case MessageCodes.ParseComplete:\n return parseComplete;\n case MessageCodes.CloseComplete:\n return closeComplete;\n case MessageCodes.NoData:\n return noData;\n case MessageCodes.PortalSuspended:\n return portalSuspended;\n case MessageCodes.CopyDone:\n return copyDone;\n case MessageCodes.ReplicationStart:\n return replicationStart;\n case MessageCodes.EmptyQuery:\n return emptyQuery;\n case MessageCodes.DataRow:\n return this.#parseDataRowMessage(offset, length, bytes);\n case MessageCodes.CommandComplete:\n return this.#parseCommandCompleteMessage(offset, length, bytes);\n case MessageCodes.ReadyForQuery:\n return this.#parseReadyForQueryMessage(offset, length, bytes);\n case MessageCodes.NotificationResponse:\n return this.#parseNotificationMessage(offset, length, bytes);\n case MessageCodes.AuthenticationResponse:\n return this.#parseAuthenticationResponse(offset, length, bytes);\n case MessageCodes.ParameterStatus:\n return this.#parseParameterStatusMessage(offset, length, bytes);\n case MessageCodes.BackendKeyData:\n return this.#parseBackendKeyData(offset, length, bytes);\n case MessageCodes.ErrorMessage:\n return this.#parseErrorMessage(offset, length, bytes, \"error\");\n case MessageCodes.NoticeMessage:\n return this.#parseErrorMessage(offset, length, bytes, \"notice\");\n case MessageCodes.RowDescriptionMessage:\n return this.#parseRowDescriptionMessage(offset, length, bytes);\n case MessageCodes.ParameterDescriptionMessage:\n return this.#parseParameterDescriptionMessage(offset, length, bytes);\n case MessageCodes.CopyIn:\n return this.#parseCopyMessage(offset, length, bytes, \"copyInResponse\");\n case MessageCodes.CopyOut:\n return this.#parseCopyMessage(offset, length, bytes, \"copyOutResponse\");\n case MessageCodes.CopyData:\n return this.#parseCopyData(offset, length, bytes);\n default:\n return new DatabaseError(`received invalid response: ${code.toString(16)}`, length, \"error\");\n }\n }\n\n #setBuffer(offset: number, bytes: ArrayBufferLike): void {\n this.#reader.setBuffer(offset, bytes);\n }\n\n #parseReadyForQueryMessage(offset: number, length: number, bytes: ArrayBufferLike): ReadyForQueryMessage {\n this.#setBuffer(offset, bytes);\n return new ReadyForQueryMessage(length, this.#reader.string(1));\n }\n\n #parseCommandCompleteMessage(offset: number, length: number, bytes: ArrayBufferLike): CommandCompleteMessage {\n this.#setBuffer(offset, bytes);\n return new CommandCompleteMessage(length, this.#reader.cstring());\n }\n\n #parseCopyData(offset: number, length: number, bytes: ArrayBufferLike): CopyDataMessage {\n const chunk = bytes.slice(offset, offset + (length - 4));\n return new CopyDataMessage(length, new Uint8Array(chunk));\n }\n\n #parseCopyMessage(offset: number, length: number, bytes: ArrayBufferLike, messageName: MessageName): CopyResponse {\n this.#setBuffer(offset, bytes);\n const isBinary = this.#reader.byte() !== 0;\n const columnCount = this.#reader.int16();\n const message = new CopyResponse(length, messageName, isBinary, columnCount);\n for (let i = 0; i < columnCount; i++) {\n message.columnTypes[i] = this.#reader.int16();\n }\n return message;\n }\n\n #parseNotificationMessage(offset: number, length: number, bytes: ArrayBufferLike): NotificationResponseMessage {\n this.#setBuffer(offset, bytes);\n const processId = this.#reader.int32();\n const channel = this.#reader.cstring();\n const payload = this.#reader.cstring();\n return new NotificationResponseMessage(length, processId, channel, payload);\n }\n\n #parseRowDescriptionMessage(offset: number, length: number, bytes: ArrayBufferLike): RowDescriptionMessage {\n this.#setBuffer(offset, bytes);\n const fieldCount = this.#reader.int16();\n const fields: Field[] = [];\n for (let i = 0; i < fieldCount; i++) {\n fields.push(this.#parseField());\n }\n return new RowDescriptionMessage(length, fields);\n }\n\n #parseField(): Field {\n const name = this.#reader.cstring();\n const tableID = this.#reader.int32();\n const columnID = this.#reader.int16();\n const dataTypeID = this.#reader.int32();\n const dataTypeSize = this.#reader.int16();\n const dataTypeModifier = this.#reader.int32();\n const mode = this.#reader.int16() === 0 ? Modes.text : Modes.binary;\n return new Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);\n }\n\n #parseParameterDescriptionMessage(\n offset: number,\n length: number,\n bytes: ArrayBufferLike,\n ): ParameterDescriptionMessage {\n this.#setBuffer(offset, bytes);\n const parameterCount = this.#reader.int16();\n const dataTypeIDs: number[] = [];\n for (let i = 0; i < parameterCount; i++) {\n dataTypeIDs.push(this.#reader.int32());\n }\n return new ParameterDescriptionMessage(length, dataTypeIDs);\n }\n\n #parseDataRowMessage(offset: number, length: number, bytes: ArrayBufferLike): DataRowMessage {\n this.#setBuffer(offset, bytes);\n const fieldCount = this.#reader.int16();\n const fields: (string | null)[] = [];\n for (let i = 0; i < fieldCount; i++) {\n const len = this.#reader.int32();\n // A length of -1 is SQL NULL.\n fields.push(len === -1 ? null : this.#reader.string(len));\n }\n return new DataRowMessage(length, fields);\n }\n\n #parseParameterStatusMessage(offset: number, length: number, bytes: ArrayBufferLike): ParameterStatusMessage {\n this.#setBuffer(offset, bytes);\n const name = this.#reader.cstring();\n const value = this.#reader.cstring();\n return new ParameterStatusMessage(length, name, value);\n }\n\n #parseBackendKeyData(offset: number, length: number, bytes: ArrayBufferLike): BackendKeyDataMessage {\n this.#setBuffer(offset, bytes);\n const processID = this.#reader.int32();\n const secretKey = this.#reader.int32();\n return new BackendKeyDataMessage(length, processID, secretKey);\n }\n\n #parseAuthenticationResponse(offset: number, length: number, bytes: ArrayBufferLike): AuthenticationMessage {\n this.#setBuffer(offset, bytes);\n const code = this.#reader.int32();\n switch (code) {\n case 0:\n return new AuthenticationOk(length);\n case 3:\n return new AuthenticationCleartextPassword(length);\n case 5:\n return new AuthenticationMD5Password(length, this.#reader.bytes(4));\n case 10: {\n const mechanisms: string[] = [];\n for (;;) {\n const mechanism = this.#reader.cstring();\n if (mechanism.length === 0) {\n return new AuthenticationSASL(length, mechanisms);\n }\n mechanisms.push(mechanism);\n }\n }\n case 11:\n return new AuthenticationSASLContinue(length, this.#reader.string(length - 8));\n case 12:\n return new AuthenticationSASLFinal(length, this.#reader.string(length - 8));\n default:\n throw new Error(`Unknown authenticationOk message type ${code}`);\n }\n }\n\n #parseErrorMessage(\n offset: number,\n length: number,\n bytes: ArrayBufferLike,\n name: MessageName,\n ): DatabaseError | NoticeMessage {\n this.#setBuffer(offset, bytes);\n const fields: Record<string, string> = {};\n let fieldType = this.#reader.string(1);\n while (fieldType !== \"\\0\") {\n fields[fieldType] = this.#reader.cstring();\n fieldType = this.#reader.string(1);\n }\n\n const messageValue = fields[\"M\"];\n const message =\n name === \"notice\" ? new NoticeMessage(length, messageValue) : new DatabaseError(messageValue ?? \"\", length, name);\n\n message.severity = fields[\"S\"];\n message.code = fields[\"C\"];\n message.detail = fields[\"D\"];\n message.hint = fields[\"H\"];\n message.position = fields[\"P\"];\n message.internalPosition = fields[\"p\"];\n message.internalQuery = fields[\"q\"];\n message.where = fields[\"W\"];\n message.schema = fields[\"s\"];\n message.table = fields[\"t\"];\n message.column = fields[\"c\"];\n message.dataType = fields[\"d\"];\n message.constraint = fields[\"n\"];\n message.file = fields[\"F\"];\n message.line = fields[\"L\"];\n message.routine = fields[\"R\"];\n return message;\n }\n}\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,SAAQ;AAAA,EACnB,MAAM;AAAA,EACN,QAAQ;AACV;;;ACHA,IAAM,cAAc,IAAI,YAAY,CAAC;AAAA;AAG9B,MAAM,aAAa;AAAA,EACxB,cAAwB,IAAI,SAAS,WAAW;AAAA,EAChD;AAAA,EACS,WAAW,IAAI,YAAY,OAAO;AAAA,EAE3C,WAAW,CAAC,SAAS,GAAG;AAAA,IACtB,KAAK,UAAU;AAAA;AAAA,EAGjB,SAAS,CAAC,QAAgB,QAA+B;AAAA,IACvD,KAAK,UAAU;AAAA,IACf,KAAK,cAAc,IAAI,SAAS,MAAM;AAAA;AAAA,EAGxC,KAAK,GAAW;AAAA,IACd,MAAM,SAAS,KAAK,YAAY,SAAS,KAAK,SAAS,KAAK;AAAA,IAC5D,KAAK,WAAW;AAAA,IAChB,OAAO;AAAA;AAAA,EAGT,IAAI,GAAW;AAAA,IACb,MAAM,SAAS,KAAK,YAAY,SAAS,KAAK,OAAO;AAAA,IACrD,KAAK;AAAA,IACL,OAAO;AAAA;AAAA,EAGT,KAAK,GAAW;AAAA,IACd,MAAM,SAAS,KAAK,YAAY,SAAS,KAAK,SAAS,KAAK;AAAA,IAC5D,KAAK,WAAW;AAAA,IAChB,OAAO;AAAA;AAAA,EAGT,MAAM,CAAC,QAAwB;AAAA,IAC7B,OAAO,KAAK,SAAS,OAAO,KAAK,MAAM,MAAM,CAAC;AAAA;AAAA,EAGhD,OAAO,GAAW;AAAA,IAChB,MAAM,QAA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