@pgxsinkit/pgwasm 0.6.1 → 0.6.3
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 -0
- package/dist/{chunk-jnmd6w7f.js → chunk-4eb2pcfr.js} +18 -3
- package/dist/chunk-4eb2pcfr.js.map +10 -0
- package/dist/{chunk-garmxqte.js → chunk-82r7js5b.js} +101 -21
- package/dist/chunk-82r7js5b.js.map +16 -0
- package/dist/{chunk-c06zjbcj.js → chunk-cgt5pdan.js} +2 -290
- package/dist/chunk-cgt5pdan.js.map +13 -0
- package/dist/{chunk-cpsnmzrf.js → chunk-jwz46twh.js} +14 -2
- package/dist/chunk-jwz46twh.js.map +10 -0
- package/dist/{chunk-d2kpv98r.js → chunk-rqykg4gj.js} +1 -1
- package/dist/{chunk-d2kpv98r.js.map → chunk-rqykg4gj.js.map} +1 -1
- package/dist/{chunk-10ebj4re.js → chunk-rsenqaz0.js} +2 -2
- package/dist/{chunk-10ebj4re.js.map → chunk-rsenqaz0.js.map} +1 -1
- package/dist/chunk-ryjxx1c8.js +303 -0
- package/dist/chunk-ryjxx1c8.js.map +10 -0
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/pgwasm.d.ts.map +1 -1
- package/dist/drizzle/codecs.d.ts.map +1 -1
- package/dist/drizzle/driver.d.ts.map +1 -1
- package/dist/drizzle/index.js +2 -2
- package/dist/drizzle/index.js.map +3 -3
- package/dist/drizzle/session.d.ts.map +1 -1
- package/dist/errors.d.ts +5 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/interface.d.ts +4 -1
- package/dist/interface.d.ts.map +1 -1
- package/dist/live/format-query.d.ts.map +1 -1
- package/dist/live/index.js +5 -5
- package/dist/live/index.js.map +3 -3
- package/dist/opfs/core/mounted-vfs.d.ts +1 -1
- package/dist/opfs/core/mounted-vfs.d.ts.map +1 -1
- package/dist/opfs/index.js +3 -3
- package/dist/opfs/index.js.map +8 -8
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +6 -4
- package/dist/protocol/index.js.map +3 -3
- package/dist/protocol/wire/parser.d.ts.map +1 -1
- package/dist/templating.d.ts.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/opfs/SKILL.md +1 -1
- package/src/core/data-dir-archive.ts +1 -1
- package/src/core/parse.ts +2 -2
- package/src/core/pgwasm.ts +104 -17
- package/src/drizzle/codecs.ts +2 -2
- package/src/drizzle/driver.ts +1 -1
- package/src/drizzle/session.ts +2 -2
- package/src/errors.ts +10 -1
- package/src/index.ts +1 -0
- package/src/interface.ts +4 -1
- package/src/live/format-query.ts +2 -1
- package/src/opfs/broker/client.ts +4 -4
- package/src/opfs/broker/server.ts +3 -3
- package/src/opfs/core/codec.ts +2 -2
- package/src/opfs/core/metadata-store.ts +6 -6
- package/src/opfs/core/mounted-vfs.ts +1 -1
- package/src/opfs/core/port.ts +1 -1
- package/src/opfs/core/repacked-vfs.ts +6 -6
- package/src/opfs/core/state-machine.ts +3 -3
- package/src/protocol/index.ts +1 -1
- package/src/protocol/wire/parser.ts +4 -4
- package/src/templating.ts +3 -1
- package/src/types.ts +15 -1
- package/dist/chunk-c06zjbcj.js.map +0 -14
- package/dist/chunk-cpsnmzrf.js.map +0 -10
- package/dist/chunk-garmxqte.js.map +0 -16
- package/dist/chunk-jnmd6w7f.js.map +0 -10
- package/dist/chunk-kb3rsr7n.js +0 -19
- package/dist/chunk-kb3rsr7n.js.map +0 -9
|
@@ -1,292 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import {
|
|
3
|
-
__export
|
|
4
|
-
} from "./chunk-kb3rsr7n.js";
|
|
5
|
-
|
|
6
|
-
// packages/pgwasm/src/protocol/wire/messages.ts
|
|
7
|
-
var exports_messages = {};
|
|
8
|
-
__export(exports_messages, {
|
|
9
|
-
AuthenticationCleartextPassword: () => AuthenticationCleartextPassword,
|
|
10
|
-
AuthenticationMD5Password: () => AuthenticationMD5Password,
|
|
11
|
-
AuthenticationOk: () => AuthenticationOk,
|
|
12
|
-
AuthenticationSASL: () => AuthenticationSASL,
|
|
13
|
-
AuthenticationSASLContinue: () => AuthenticationSASLContinue,
|
|
14
|
-
AuthenticationSASLFinal: () => AuthenticationSASLFinal,
|
|
15
|
-
BackendKeyDataMessage: () => BackendKeyDataMessage,
|
|
16
|
-
CommandCompleteMessage: () => CommandCompleteMessage,
|
|
17
|
-
CopyDataMessage: () => CopyDataMessage,
|
|
18
|
-
CopyResponse: () => CopyResponse,
|
|
19
|
-
DataRowMessage: () => DataRowMessage,
|
|
20
|
-
DatabaseError: () => DatabaseError2,
|
|
21
|
-
Field: () => Field,
|
|
22
|
-
NoticeMessage: () => NoticeMessage,
|
|
23
|
-
NotificationResponseMessage: () => NotificationResponseMessage,
|
|
24
|
-
ParameterDescriptionMessage: () => ParameterDescriptionMessage,
|
|
25
|
-
ParameterStatusMessage: () => ParameterStatusMessage,
|
|
26
|
-
ReadyForQueryMessage: () => ReadyForQueryMessage,
|
|
27
|
-
RowDescriptionMessage: () => RowDescriptionMessage,
|
|
28
|
-
bindComplete: () => bindComplete,
|
|
29
|
-
closeComplete: () => closeComplete,
|
|
30
|
-
copyDone: () => copyDone,
|
|
31
|
-
emptyQuery: () => emptyQuery,
|
|
32
|
-
noData: () => noData,
|
|
33
|
-
parseComplete: () => parseComplete,
|
|
34
|
-
portalSuspended: () => portalSuspended,
|
|
35
|
-
replicationStart: () => replicationStart
|
|
36
|
-
});
|
|
37
|
-
var parseComplete = { name: "parseComplete", length: 5 };
|
|
38
|
-
var bindComplete = { name: "bindComplete", length: 5 };
|
|
39
|
-
var closeComplete = { name: "closeComplete", length: 5 };
|
|
40
|
-
var noData = { name: "noData", length: 5 };
|
|
41
|
-
var portalSuspended = { name: "portalSuspended", length: 5 };
|
|
42
|
-
var replicationStart = { name: "replicationStart", length: 4 };
|
|
43
|
-
var emptyQuery = { name: "emptyQuery", length: 4 };
|
|
44
|
-
var copyDone = { name: "copyDone", length: 4 };
|
|
45
|
-
|
|
46
|
-
class AuthenticationOk {
|
|
47
|
-
name = "authenticationOk";
|
|
48
|
-
length;
|
|
49
|
-
constructor(length) {
|
|
50
|
-
this.length = length;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
class AuthenticationCleartextPassword {
|
|
55
|
-
name = "authenticationCleartextPassword";
|
|
56
|
-
length;
|
|
57
|
-
constructor(length) {
|
|
58
|
-
this.length = length;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class AuthenticationMD5Password {
|
|
63
|
-
name = "authenticationMD5Password";
|
|
64
|
-
length;
|
|
65
|
-
salt;
|
|
66
|
-
constructor(length, salt) {
|
|
67
|
-
this.length = length;
|
|
68
|
-
this.salt = salt;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class AuthenticationSASL {
|
|
73
|
-
name = "authenticationSASL";
|
|
74
|
-
length;
|
|
75
|
-
mechanisms;
|
|
76
|
-
constructor(length, mechanisms) {
|
|
77
|
-
this.length = length;
|
|
78
|
-
this.mechanisms = mechanisms;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
class AuthenticationSASLContinue {
|
|
83
|
-
name = "authenticationSASLContinue";
|
|
84
|
-
length;
|
|
85
|
-
data;
|
|
86
|
-
constructor(length, data) {
|
|
87
|
-
this.length = length;
|
|
88
|
-
this.data = data;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
class AuthenticationSASLFinal {
|
|
93
|
-
name = "authenticationSASLFinal";
|
|
94
|
-
length;
|
|
95
|
-
data;
|
|
96
|
-
constructor(length, data) {
|
|
97
|
-
this.length = length;
|
|
98
|
-
this.data = data;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
class DatabaseError2 extends Error {
|
|
103
|
-
severity;
|
|
104
|
-
code;
|
|
105
|
-
detail;
|
|
106
|
-
hint;
|
|
107
|
-
position;
|
|
108
|
-
internalPosition;
|
|
109
|
-
internalQuery;
|
|
110
|
-
where;
|
|
111
|
-
schema;
|
|
112
|
-
table;
|
|
113
|
-
column;
|
|
114
|
-
dataType;
|
|
115
|
-
constraint;
|
|
116
|
-
file;
|
|
117
|
-
line;
|
|
118
|
-
routine;
|
|
119
|
-
length;
|
|
120
|
-
name;
|
|
121
|
-
constructor(message, length, name) {
|
|
122
|
-
super(message);
|
|
123
|
-
this.length = length;
|
|
124
|
-
this.name = name;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
class CopyDataMessage {
|
|
129
|
-
name = "copyData";
|
|
130
|
-
length;
|
|
131
|
-
chunk;
|
|
132
|
-
constructor(length, chunk) {
|
|
133
|
-
this.length = length;
|
|
134
|
-
this.chunk = chunk;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class CopyResponse {
|
|
139
|
-
length;
|
|
140
|
-
name;
|
|
141
|
-
binary;
|
|
142
|
-
columnTypes;
|
|
143
|
-
constructor(length, name, binary, columnCount) {
|
|
144
|
-
this.length = length;
|
|
145
|
-
this.name = name;
|
|
146
|
-
this.binary = binary;
|
|
147
|
-
this.columnTypes = Array.from({ length: columnCount }, () => 0);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
class Field {
|
|
152
|
-
name;
|
|
153
|
-
tableID;
|
|
154
|
-
columnID;
|
|
155
|
-
dataTypeID;
|
|
156
|
-
dataTypeSize;
|
|
157
|
-
dataTypeModifier;
|
|
158
|
-
format;
|
|
159
|
-
constructor(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, format) {
|
|
160
|
-
this.name = name;
|
|
161
|
-
this.tableID = tableID;
|
|
162
|
-
this.columnID = columnID;
|
|
163
|
-
this.dataTypeID = dataTypeID;
|
|
164
|
-
this.dataTypeSize = dataTypeSize;
|
|
165
|
-
this.dataTypeModifier = dataTypeModifier;
|
|
166
|
-
this.format = format;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
class RowDescriptionMessage {
|
|
171
|
-
name = "rowDescription";
|
|
172
|
-
length;
|
|
173
|
-
fieldCount;
|
|
174
|
-
fields;
|
|
175
|
-
constructor(length, fields) {
|
|
176
|
-
this.length = length;
|
|
177
|
-
this.fieldCount = fields.length;
|
|
178
|
-
this.fields = fields;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
class ParameterDescriptionMessage {
|
|
183
|
-
name = "parameterDescription";
|
|
184
|
-
length;
|
|
185
|
-
parameterCount;
|
|
186
|
-
dataTypeIDs;
|
|
187
|
-
constructor(length, dataTypeIDs) {
|
|
188
|
-
this.length = length;
|
|
189
|
-
this.parameterCount = dataTypeIDs.length;
|
|
190
|
-
this.dataTypeIDs = dataTypeIDs;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
class ParameterStatusMessage {
|
|
195
|
-
name = "parameterStatus";
|
|
196
|
-
length;
|
|
197
|
-
parameterName;
|
|
198
|
-
parameterValue;
|
|
199
|
-
constructor(length, parameterName, parameterValue) {
|
|
200
|
-
this.length = length;
|
|
201
|
-
this.parameterName = parameterName;
|
|
202
|
-
this.parameterValue = parameterValue;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
class BackendKeyDataMessage {
|
|
207
|
-
name = "backendKeyData";
|
|
208
|
-
length;
|
|
209
|
-
processID;
|
|
210
|
-
secretKey;
|
|
211
|
-
constructor(length, processID, secretKey) {
|
|
212
|
-
this.length = length;
|
|
213
|
-
this.processID = processID;
|
|
214
|
-
this.secretKey = secretKey;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class NotificationResponseMessage {
|
|
219
|
-
name = "notification";
|
|
220
|
-
length;
|
|
221
|
-
processId;
|
|
222
|
-
channel;
|
|
223
|
-
payload;
|
|
224
|
-
constructor(length, processId, channel, payload) {
|
|
225
|
-
this.length = length;
|
|
226
|
-
this.processId = processId;
|
|
227
|
-
this.channel = channel;
|
|
228
|
-
this.payload = payload;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
class ReadyForQueryMessage {
|
|
233
|
-
name = "readyForQuery";
|
|
234
|
-
length;
|
|
235
|
-
status;
|
|
236
|
-
constructor(length, status) {
|
|
237
|
-
this.length = length;
|
|
238
|
-
this.status = status;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
class CommandCompleteMessage {
|
|
243
|
-
name = "commandComplete";
|
|
244
|
-
length;
|
|
245
|
-
text;
|
|
246
|
-
constructor(length, text) {
|
|
247
|
-
this.length = length;
|
|
248
|
-
this.text = text;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
class DataRowMessage {
|
|
253
|
-
name = "dataRow";
|
|
254
|
-
length;
|
|
255
|
-
fieldCount;
|
|
256
|
-
fields;
|
|
257
|
-
constructor(length, fields) {
|
|
258
|
-
this.length = length;
|
|
259
|
-
this.fields = fields;
|
|
260
|
-
this.fieldCount = fields.length;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
class NoticeMessage {
|
|
265
|
-
name = "notice";
|
|
266
|
-
length;
|
|
267
|
-
message;
|
|
268
|
-
severity;
|
|
269
|
-
code;
|
|
270
|
-
detail;
|
|
271
|
-
hint;
|
|
272
|
-
position;
|
|
273
|
-
internalPosition;
|
|
274
|
-
internalQuery;
|
|
275
|
-
where;
|
|
276
|
-
schema;
|
|
277
|
-
table;
|
|
278
|
-
column;
|
|
279
|
-
dataType;
|
|
280
|
-
constraint;
|
|
281
|
-
file;
|
|
282
|
-
line;
|
|
283
|
-
routine;
|
|
284
|
-
constructor(length, message) {
|
|
285
|
-
this.length = length;
|
|
286
|
-
this.message = message;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
2
|
// packages/pgwasm/src/protocol/wire/string-utils.ts
|
|
291
3
|
function byteLengthUtf8(str) {
|
|
292
4
|
let byteLength = str.length;
|
|
@@ -575,6 +287,6 @@ function strictSyncOf(pg) {
|
|
|
575
287
|
return strictSyncs.get(pg);
|
|
576
288
|
}
|
|
577
289
|
|
|
578
|
-
export {
|
|
290
|
+
export { serialize2, registerProtocolAccess, protocolAccessOf, registerStrictSync, strictSyncOf };
|
|
579
291
|
|
|
580
|
-
//# debugId=
|
|
292
|
+
//# debugId=7E0D86EE8810921364756E2164756E21
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/protocol/wire/string-utils.ts", "../src/protocol/wire/buffer-writer.ts", "../src/protocol/wire/serializer.ts", "../src/core/internals.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\n/**\n * The byte length of a string once UTF-8 encoded.\n * Adapted from https://stackoverflow.com/a/23329386\n */\nexport function byteLengthUtf8(str: string): number {\n let byteLength = str.length;\n for (let i = str.length - 1; i >= 0; i--) {\n const code = str.charCodeAt(i);\n if (code > 0x7f && code <= 0x7ff) byteLength++;\n else if (code > 0x7ff && code <= 0xffff) byteLength += 2;\n if (code >= 0xdc00 && code <= 0xdfff) {\n const previous = str.charCodeAt(i - 1);\n // Only a valid pair shares four bytes; an unpaired surrogate encodes as U+FFFD.\n if (previous >= 0xd800 && previous <= 0xdbff) i--;\n }\n }\n return byteLength;\n}\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\nimport { byteLengthUtf8 } from \"./string-utils\";\n\n/** Builds frontend messages: a 5-byte header slot (code + length) followed by the body. */\nexport class Writer {\n readonly #size: number;\n #bufferView: DataView<ArrayBuffer>;\n #offset = 5;\n readonly #encoder = new TextEncoder();\n readonly #headerPosition = 0;\n\n constructor(size = 256) {\n this.#size = size;\n this.#bufferView = this.#allocateBuffer(size);\n }\n\n #allocateBuffer(size: number): DataView<ArrayBuffer> {\n return new DataView(new ArrayBuffer(size));\n }\n\n #ensure(size: number): void {\n const remaining = this.#bufferView.byteLength - this.#offset;\n if (remaining < size) {\n const oldBuffer = this.#bufferView.buffer;\n // Grow by ~1.5x (https://stackoverflow.com/questions/2269063/buffer-growth-strategy).\n const newSize = oldBuffer.byteLength + (oldBuffer.byteLength >> 1) + size;\n this.#bufferView = this.#allocateBuffer(newSize);\n new Uint8Array(this.#bufferView.buffer).set(new Uint8Array(oldBuffer));\n }\n }\n\n addInt32(num: number): Writer {\n this.#ensure(4);\n this.#bufferView.setInt32(this.#offset, num, false);\n this.#offset += 4;\n return this;\n }\n\n addInt16(num: number): Writer {\n this.#ensure(2);\n this.#bufferView.setInt16(this.#offset, num, false);\n this.#offset += 2;\n return this;\n }\n\n addUint16(num: number): Writer {\n this.#ensure(2);\n this.#bufferView.setUint16(this.#offset, num, false);\n this.#offset += 2;\n return this;\n }\n\n addCString(string: string): Writer {\n if (string) {\n this.addString(string);\n }\n this.#ensure(1);\n this.#bufferView.setUint8(this.#offset, 0);\n this.#offset++;\n return this;\n }\n\n addString(string = \"\"): Writer {\n const length = byteLengthUtf8(string);\n this.#ensure(length);\n this.#encoder.encodeInto(string, new Uint8Array(this.#bufferView.buffer, this.#offset));\n this.#offset += length;\n return this;\n }\n\n add(otherBuffer: ArrayBuffer | ArrayBufferView): Writer {\n const bytes = ArrayBuffer.isView(otherBuffer)\n ? new Uint8Array(otherBuffer.buffer, otherBuffer.byteOffset, otherBuffer.byteLength)\n : new Uint8Array(otherBuffer);\n this.#ensure(bytes.byteLength);\n new Uint8Array(this.#bufferView.buffer).set(bytes, this.#offset);\n this.#offset += bytes.byteLength;\n return this;\n }\n\n #join(code?: number): ArrayBuffer {\n if (code) {\n this.#bufferView.setUint8(this.#headerPosition, code);\n // The length counts everything in the message but the code byte.\n const length = this.#offset - (this.#headerPosition + 1);\n this.#bufferView.setInt32(this.#headerPosition + 1, length, false);\n }\n return this.#bufferView.buffer.slice(code ? 0 : 5, this.#offset);\n }\n\n flush(code?: number): Uint8Array<ArrayBuffer> {\n const result = this.#join(code);\n this.#offset = 5;\n this.#bufferView = this.#allocateBuffer(this.#size);\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 { Writer } from \"./buffer-writer\";\nimport { byteLengthUtf8 } from \"./string-utils\";\n\nconst code = {\n startup: 0x70,\n query: 0x51,\n parse: 0x50,\n bind: 0x42,\n execute: 0x45,\n flush: 0x48,\n sync: 0x53,\n end: 0x58,\n close: 0x43,\n describe: 0x44,\n copyFromChunk: 0x64,\n copyDone: 0x63,\n copyFail: 0x66,\n} as const;\n\ntype Code = (typeof code)[keyof typeof code];\n\n/** A bind parameter: text, raw bytes (sent as binary), or SQL NULL. */\nexport type LegalValue = string | ArrayBuffer | ArrayBufferView | null;\n\nconst writer = new Writer();\n\nfunction startup(opts: Record<string, string>): Uint8Array<ArrayBuffer> {\n // protocol version 3.0\n writer.addInt16(3).addInt16(0);\n for (const [key, value] of Object.entries(opts)) {\n writer.addCString(key).addCString(value);\n }\n writer.addCString(\"client_encoding\").addCString(\"UTF8\");\n // The startup message is sent without a type byte.\n const bodyBuffer = writer.addCString(\"\").flush();\n const length = bodyBuffer.byteLength + 4;\n return new Writer().addInt32(length).add(bodyBuffer).flush();\n}\n\nfunction requestSsl(): Uint8Array<ArrayBuffer> {\n const bufferView = new DataView(new ArrayBuffer(8));\n bufferView.setInt32(0, 8, false);\n bufferView.setInt32(4, 80877103, false);\n return new Uint8Array(bufferView.buffer);\n}\n\nfunction password(value: string): Uint8Array<ArrayBuffer> {\n return writer.addCString(value).flush(code.startup);\n}\n\nfunction sendSASLInitialResponseMessage(mechanism: string, initialResponse: string): Uint8Array<ArrayBuffer> {\n writer.addCString(mechanism).addInt32(byteLengthUtf8(initialResponse)).addString(initialResponse);\n return writer.flush(code.startup);\n}\n\nfunction sendSCRAMClientFinalMessage(additionalData: string): Uint8Array<ArrayBuffer> {\n return writer.addString(additionalData).flush(code.startup);\n}\n\nfunction query(text: string): Uint8Array<ArrayBuffer> {\n return writer.addCString(text).flush(code.query);\n}\n\nexport interface ParseOpts {\n name?: string;\n types?: readonly number[];\n text: string;\n}\n\nconst emptyValueArray: LegalValue[] = [];\n\nfunction assertParameterCount(count: number): void {\n if (count > 65_535) {\n throw new RangeError(`Postgres messages support at most 65535 parameters (received ${count})`);\n }\n}\n\nfunction parse(opts: ParseOpts): Uint8Array<ArrayBuffer> {\n const name = opts.name ?? \"\";\n if (name.length > 63) {\n throw new RangeError(`Postgres statement names are at most 63 characters: \"${name}\" (${name.length})`);\n }\n const typeCount = opts.types?.length ?? 0;\n assertParameterCount(typeCount);\n const buffer = writer.addCString(name).addCString(opts.text).addUint16(typeCount);\n opts.types?.forEach((type) => buffer.addInt32(type));\n return writer.flush(code.parse);\n}\n\ntype ValueMapper = (param: unknown, index: number) => LegalValue;\n\nexport interface BindOpts {\n portal?: string;\n binary?: boolean;\n statement?: string;\n values?: readonly LegalValue[];\n /** Optional map from a JS value to the value sent, per parameter. */\n valueMapper?: ValueMapper;\n}\n\nconst paramWriter = new Writer();\n\nconst ParamType = { STRING: 0, BINARY: 1 } as const;\n\nfunction writeValues(values: readonly LegalValue[], valueMapper?: ValueMapper): void {\n for (let i = 0; i < values.length; i++) {\n const value = values[i] ?? null;\n const mappedVal = valueMapper ? valueMapper(value, i) : value;\n if (mappedVal === null) {\n writer.addInt16(ParamType.STRING);\n // -1 is SQL NULL.\n paramWriter.addInt32(-1);\n } else if (mappedVal instanceof ArrayBuffer || ArrayBuffer.isView(mappedVal)) {\n const byteLength = mappedVal.byteLength;\n writer.addInt16(ParamType.BINARY);\n paramWriter.addInt32(byteLength);\n paramWriter.add(mappedVal);\n } else {\n writer.addInt16(ParamType.STRING);\n paramWriter.addInt32(byteLengthUtf8(mappedVal));\n paramWriter.addString(mappedVal);\n }\n }\n}\n\nfunction bind(config: BindOpts = {}): Uint8Array<ArrayBuffer> {\n const portal = config.portal ?? \"\";\n const statement = config.statement ?? \"\";\n const binary = config.binary ?? false;\n const values = config.values ?? emptyValueArray;\n const len = values.length;\n assertParameterCount(len);\n\n writer.addCString(portal).addCString(statement);\n writer.addUint16(len);\n writeValues(values, config.valueMapper);\n writer.addUint16(len);\n writer.add(paramWriter.flush());\n // result format code\n writer.addInt16(binary ? ParamType.BINARY : ParamType.STRING);\n return writer.flush(code.bind);\n}\n\nexport interface ExecOpts {\n portal?: string;\n rows?: number;\n}\n\nconst emptyExecute = new Uint8Array([code.execute, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00]);\n\nfunction execute(config?: ExecOpts): Uint8Array<ArrayBuffer> {\n if (!config || (!config.portal && !config.rows)) {\n return emptyExecute;\n }\n const portal = config.portal ?? \"\";\n const rows = config.rows ?? 0;\n const portalLength = byteLengthUtf8(portal);\n const len = 4 + portalLength + 1 + 4;\n const bufferView = new DataView(new ArrayBuffer(1 + len));\n bufferView.setUint8(0, code.execute);\n bufferView.setInt32(1, len, false);\n new TextEncoder().encodeInto(portal, new Uint8Array(bufferView.buffer, 5));\n bufferView.setUint8(portalLength + 5, 0); // the portal name's terminator\n bufferView.setUint32(bufferView.byteLength - 4, rows, false);\n return new Uint8Array(bufferView.buffer);\n}\n\nfunction cancel(processID: number, secretKey: number): Uint8Array<ArrayBuffer> {\n const bufferView = new DataView(new ArrayBuffer(16));\n bufferView.setInt32(0, 16, false);\n bufferView.setInt16(4, 1234, false);\n bufferView.setInt16(6, 5678, false);\n bufferView.setInt32(8, processID, false);\n bufferView.setInt32(12, secretKey, false);\n return new Uint8Array(bufferView.buffer);\n}\n\nexport interface PortalOpts {\n type: \"S\" | \"P\";\n name?: string;\n}\n\nfunction cstringMessage(messageCode: Code, string: string): Uint8Array<ArrayBuffer> {\n return new Writer().addCString(string).flush(messageCode);\n}\n\nconst emptyDescribePortal = writer.addCString(\"P\").flush(code.describe);\nconst emptyDescribeStatement = writer.addCString(\"S\").flush(code.describe);\n\nfunction describe(msg: PortalOpts): Uint8Array<ArrayBuffer> {\n if (msg.name) return cstringMessage(code.describe, `${msg.type}${msg.name}`);\n return msg.type === \"P\" ? emptyDescribePortal : emptyDescribeStatement;\n}\n\nfunction close(msg: PortalOpts): Uint8Array<ArrayBuffer> {\n return cstringMessage(code.close, `${msg.type}${msg.name ?? \"\"}`);\n}\n\nfunction copyData(chunk: ArrayBuffer | ArrayBufferView): Uint8Array<ArrayBuffer> {\n return writer.add(chunk).flush(code.copyFromChunk);\n}\n\nfunction copyFail(message: string): Uint8Array<ArrayBuffer> {\n return cstringMessage(code.copyFail, message);\n}\n\nconst codeOnlyBuffer = (messageCode: Code): Uint8Array<ArrayBuffer> =>\n new Uint8Array([messageCode, 0x00, 0x00, 0x00, 0x04]);\n\nconst flushBuffer = codeOnlyBuffer(code.flush);\nconst syncBuffer = codeOnlyBuffer(code.sync);\nconst endBuffer = codeOnlyBuffer(code.end);\nconst copyDoneBuffer = codeOnlyBuffer(code.copyDone);\n\n/** Frontend message builders. */\nexport const serialize = {\n startup,\n password,\n requestSsl,\n sendSASLInitialResponseMessage,\n sendSCRAMClientFinalMessage,\n query,\n parse,\n bind,\n execute,\n describe,\n close,\n flush: (): Uint8Array<ArrayBuffer> => flushBuffer,\n sync: (): Uint8Array<ArrayBuffer> => syncBuffer,\n end: (): Uint8Array<ArrayBuffer> => endBuffer,\n copyData,\n copyDone: (): Uint8Array<ArrayBuffer> => copyDoneBuffer,\n copyFail,\n cancel,\n};\n",
|
|
8
|
+
"/**\n * Wire-level access to a pgwasm instance, kept off its public type. `@pgxsinkit/pgwasm/protocol` and the\n * `live` extension reach it through this registry; pgwasm is bundled with code splitting, so every\n * entry point shares this one module and its map.\n */\n\nimport type { BuildCapabilities } from \"../build/seam\";\nimport type { BackendMessage, NoticeMessage } from \"../protocol/wire/messages\";\n\nexport interface ExecProtocolOptions {\n /** Persist storage after the message, as a statement does. Defaults to `true`. */\n readonly persist?: boolean;\n /** Throw the first ErrorResponse. Defaults to `true`. */\n readonly throwOnError?: boolean;\n readonly onNotice?: (notice: NoticeMessage) => void;\n}\n\nexport interface ExecProtocolStreamOptions {\n /** Persist storage after the message. Defaults to `true`. */\n readonly persist?: boolean;\n /** Every backend byte, as it arrives. A chunk is only valid during the call: copy it to keep it. */\n readonly onRawData: (data: Uint8Array) => void;\n}\n\nexport interface ExecProtocolResult {\n readonly messages: BackendMessage[];\n readonly data: Uint8Array;\n}\n\n/** What `protocol(pg)` returns. */\nexport interface PgwasmProtocol {\n /** Run frontend message bytes; the parsed backend messages and the raw reply. */\n execProtocol(message: Uint8Array, options?: ExecProtocolOptions): Promise<ExecProtocolResult>;\n /** Run frontend message bytes; the parsed backend messages only. */\n execProtocolStream(message: Uint8Array, options?: ExecProtocolOptions): Promise<BackendMessage[]>;\n /** Run frontend message bytes; the raw reply. Notifications and errors are still dispatched. */\n execProtocolRaw(message: Uint8Array, options?: Pick<ExecProtocolOptions, \"persist\">): Promise<Uint8Array>;\n /**\n * Run frontend message bytes and stream the raw reply. When nothing is pending and the build has\n * `synchronousExchange`, the whole reply is delivered before this call returns its promise — what a\n * tool driving it from inside a blocking wasm callback (pg_dump) needs.\n */\n execProtocolRawStream(message: Uint8Array, options: ExecProtocolStreamOptions): Promise<void>;\n /**\n * Run `fn` with the database's session to itself, for a tool whose exchanges must not interleave with\n * anything else (pg_dump). It waits for, then holds, the locks a `transaction()` holds, and the query\n * lock: no query, exec, transaction, listen, live-query refresh or Store backup of this database runs\n * until `fn` settles.\n *\n * What `fn` sends with the `execProtocol*` methods is its own responsibility: no transaction is begun\n * or ended around it, and a message is persisted only as its options say. Inside `fn`, use only these\n * wire methods: the database's query methods wait for the locks `fn` holds, so awaiting one deadlocks.\n */\n runExclusiveSession<T>(fn: () => Promise<T>): Promise<T>;\n /** The build's capabilities, e.g. to check `synchronousExchange` before relying on it. */\n readonly capabilities: BuildCapabilities;\n}\n\nconst registry = new WeakMap<object, PgwasmProtocol>();\n\nexport function registerProtocolAccess(pg: object, access: PgwasmProtocol): void {\n registry.set(pg, access);\n}\n\n/** The wire-level access of a pgwasm instance. Throws for anything else. */\nexport function protocolAccessOf(pg: object): PgwasmProtocol {\n const access = registry.get(pg);\n if (access === undefined) {\n throw new TypeError(\"Not a pgwasm instance (created by createPgwasm).\");\n }\n return access;\n}\n\n/**\n * The strict sync of a database whose data directory is an OPFS-repacked store, registered by\n * `createOpfsPgwasm` and run by `strictSync(pg)` from `@pgxsinkit/pgwasm/opfs`.\n */\nconst strictSyncs = new WeakMap<object, () => void>();\n\nexport function registerStrictSync(pg: object, strictSync: () => void): void {\n strictSyncs.set(pg, strictSync);\n}\n\n/** The registered strict sync of `pg`, or `undefined` when it has none (not an OPFS-repacked store). */\nexport function strictSyncOf(pg: object): (() => void) | undefined {\n return strictSyncs.get(pg);\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"mappings": ";;AAQO,SAAS,cAAc,CAAC,KAAqB;AAAA,EAClD,IAAI,aAAa,IAAI;AAAA,EACrB,SAAS,IAAI,IAAI,SAAS,EAAG,KAAK,GAAG,KAAK;AAAA,IACxC,MAAM,OAAO,IAAI,WAAW,CAAC;AAAA,IAC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AAA;AAOT,IAAM,cAAc,IAAI;AAEjB,SAAS,kBAAkB,CAAC,IAAY,YAA8B;AAAA,EAC3E,YAAY,IAAI,IAAI,UAAU;AAAA;AAIzB,SAAS,YAAY,CAAC,IAAsC;AAAA,EACjE,OAAO,YAAY,IAAI,EAAE;AAAA;",
|
|
11
|
+
"debugId": "7E0D86EE8810921364756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
DatabaseError2
|
|
4
|
+
} from "./chunk-ryjxx1c8.js";
|
|
5
|
+
|
|
2
6
|
// packages/pgwasm/src/errors.ts
|
|
7
|
+
class TransactionAbortedError2 extends DatabaseError2 {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("Transaction was rolled back instead of committed", 0, "error");
|
|
10
|
+
this.severity = "ERROR";
|
|
11
|
+
this.code = "25P02";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
3
15
|
class PgwasmError2 extends Error {
|
|
4
16
|
name = "PgwasmError";
|
|
5
17
|
}
|
|
@@ -121,6 +133,6 @@ function makeQueryError(data) {
|
|
|
121
133
|
return Object.assign(data.error, { query: data.query, params: data.params, queryOptions: data.options });
|
|
122
134
|
}
|
|
123
135
|
|
|
124
|
-
export { PgwasmError2, UnsupportedDataDirError2, OpfsAhpRemovedError2, UnsupportedFilesystemError2, CrossOriginIsolationRequiredError2, ExtensionBuildMismatchError2, BuildMismatchError2, DataFormatMismatchError2, BuildMarkerUnreadableError2, DataDirExistsError2, BackupFormatError2, StorageInUseError2, PgwasmClosedError2, PgwasmFailedError2, UnsupportedFeatureError2, makeQueryError };
|
|
136
|
+
export { TransactionAbortedError2, PgwasmError2, UnsupportedDataDirError2, OpfsAhpRemovedError2, UnsupportedFilesystemError2, CrossOriginIsolationRequiredError2, ExtensionBuildMismatchError2, BuildMismatchError2, DataFormatMismatchError2, BuildMarkerUnreadableError2, DataDirExistsError2, BackupFormatError2, StorageInUseError2, PgwasmClosedError2, PgwasmFailedError2, UnsupportedFeatureError2, makeQueryError };
|
|
125
137
|
|
|
126
|
-
//# debugId=
|
|
138
|
+
//# debugId=DD5A44BC9B659C3864756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Began as a copy of `@electric-sql/pglite` (taken under its PostgreSQL License option, © ElectricSQL\n// — see NOTICE): `makeQueryError` began as its `makePGliteError`. Owned outright (ADR-0062);\n// compatibility with PGlite is an anti-goal — evolve freely.\n\nimport type { BuildIdentity, FilesystemKind } from \"./build/seam\";\nimport type { QueryOptions } from \"./interface\";\nimport { DatabaseError } from \"./protocol/wire/messages\";\n\n/** COMMIT ended an aborted transaction with ROLLBACK instead of committing its writes. */\nexport class TransactionAbortedError extends DatabaseError {\n constructor() {\n super(\"Transaction was rolled back instead of committed\", 0, \"error\");\n this.severity = \"ERROR\";\n this.code = \"25P02\";\n }\n}\n\n/** The base of every error pgwasm itself raises (SQL errors are {@link DatabaseError}). */\nexport class PgwasmError extends Error {\n override name = \"PgwasmError\";\n}\n\n/** A `dataDir` pgwasm does not accept: an unknown scheme, a bare path, or `dataDir` with `fs`. */\nexport class UnsupportedDataDirError extends PgwasmError {\n override name = \"UnsupportedDataDirError\";\n readonly dataDir: string;\n\n constructor(dataDir: string, reason: string) {\n super(`Unsupported dataDir \"${dataDir}\": ${reason}`);\n this.dataDir = dataDir;\n }\n}\n\n/** An `opfs-ahp://` dataDir: that filesystem is gone (ADR-0062 decision 6). */\nexport class OpfsAhpRemovedError extends UnsupportedDataDirError {\n override name = \"OpfsAhpRemovedError\";\n /** Where the OPFS store lives now. */\n readonly replacement = \"@pgxsinkit/pgwasm/opfs\";\n\n constructor(dataDir: string) {\n super(\n dataDir,\n \"the opfs-ahp filesystem has been removed; the OPFS store is @pgxsinkit/pgwasm/opfs, passed in \" +\n \"explicitly as the `fs` option\",\n );\n }\n}\n\n/** The build does not mount the requested kind of storage. */\nexport class UnsupportedFilesystemError extends PgwasmError {\n override name = \"UnsupportedFilesystemError\";\n readonly kind: FilesystemKind;\n readonly build: string;\n\n constructor(kind: FilesystemKind, build: BuildIdentity, supported: readonly FilesystemKind[]) {\n super(\n `The \"${build.name}\" Postgres build does not support ${kind} storage (it supports: ${supported.join(\", \")}).`,\n );\n this.kind = kind;\n this.build = build.name;\n }\n}\n\n/** The build needs a cross-origin-isolated context, and this one is not. */\nexport class CrossOriginIsolationRequiredError extends PgwasmError {\n override name = \"CrossOriginIsolationRequiredError\";\n\n constructor(build: BuildIdentity) {\n super(\n `The \"${build.name}\" Postgres build needs a cross-origin-isolated context (SharedArrayBuffer); serve the ` +\n \"page with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp.\",\n );\n }\n}\n\n/** A server extension compiled for another build. */\nexport class ExtensionBuildMismatchError extends PgwasmError {\n override name = \"ExtensionBuildMismatchError\";\n\n constructor(extension: string, extensionBuild: string, build: BuildIdentity) {\n super(\n `The \"${extension}\" extension was compiled for the \"${extensionBuild}\" Postgres build and cannot load into ` +\n `the \"${build.name}\" build.`,\n );\n }\n}\n\n/** The build a data directory (or a Store backup) records. `\"unmarked\"` predates build markers. */\nexport type RecordedBuild = { readonly build: string; readonly dataFormat: number } | \"unmarked\";\n\nfunction describeRecorded(recorded: RecordedBuild): string {\n return recorded === \"unmarked\"\n ? \"an unmarked data directory (created before builds were recorded, by the C build)\"\n : `the \"${recorded.build}\" Postgres build (data format ${recorded.dataFormat})`;\n}\n\n/**\n * A data directory or Store backup made by another Postgres build. A store's build is fixed when it is\n * created (ADR-0063 build permanence); nothing was written.\n */\nexport class BuildMismatchError extends PgwasmError {\n override name = \"BuildMismatchError\";\n readonly expected: { readonly build: string; readonly dataFormat: number };\n readonly found: RecordedBuild;\n readonly source: \"data-directory\" | \"backup\";\n\n constructor(build: BuildIdentity, found: RecordedBuild, source: \"data-directory\" | \"backup\") {\n const what = source === \"backup\" ? \"This Store backup\" : \"This data directory\";\n super(\n `${what} was created by ${describeRecorded(found)} and cannot be opened with the \"${build.name}\" build. A ` +\n \"store's Postgres build is fixed when it is created: open it with that build, or destroy the store and \" +\n \"re-sync it.\",\n );\n this.expected = { build: build.name, dataFormat: build.dataFormat };\n this.found = found;\n this.source = source;\n }\n}\n\n/** A data directory or backup of the same build in a data format this release does not read. */\nexport class DataFormatMismatchError extends PgwasmError {\n override name = \"DataFormatMismatchError\";\n readonly expected: number;\n readonly found: number;\n readonly source: \"data-directory\" | \"backup\";\n\n constructor(build: BuildIdentity, found: number, source: \"data-directory\" | \"backup\") {\n super(\n `This ${source === \"backup\" ? \"Store backup\" : \"data directory\"} is in data format ${found} of the ` +\n `\"${build.name}\" Postgres build; this release of the build reads format ${build.dataFormat}.`,\n );\n this.expected = build.dataFormat;\n this.found = found;\n this.source = source;\n }\n}\n\n/** A build marker that cannot be read: corrupt, or written by a newer pgwasm. Nothing was written. */\nexport class BuildMarkerUnreadableError extends PgwasmError {\n override name = \"BuildMarkerUnreadableError\";\n readonly raw: string;\n\n constructor(raw: string, reason: string) {\n super(`The data directory's build marker cannot be read (${reason}): ${JSON.stringify(raw)}`);\n this.raw = raw;\n }\n}\n\n/** `loadDataDir` was given for a data directory that already holds a database. */\nexport class DataDirExistsError extends PgwasmError {\n override name = \"DataDirExistsError\";\n\n constructor() {\n super(\"The data directory already holds a database; a Store backup restores only into an empty one.\");\n }\n}\n\n/** A Store backup that cannot be restored: not a tarball, or a member outside the data directory. */\nexport class BackupFormatError extends PgwasmError {\n override name = \"BackupFormatError\";\n}\n\n/** The storage is held by another open database (an IndexedDB store open in another context). */\nexport class StorageInUseError extends PgwasmError {\n override name = \"StorageInUseError\";\n\n constructor(message: string) {\n super(message);\n }\n}\n\n/** The database is closing or closed. */\nexport class PgwasmClosedError extends PgwasmError {\n override name = \"PgwasmClosedError\";\n\n constructor(state: \"closing\" | \"closed\") {\n super(`pgwasm is ${state}`);\n }\n}\n\n/**\n * The Postgres build failed underneath a statement (an exception that is not an SQL error: a storage\n * failure thrown into the engine, a PANIC's abort). The instance is failed: every later statement\n * throws this same error, and `close()` releases resources and rejects with it.\n */\nexport class PgwasmFailedError extends PgwasmError {\n override name = \"PgwasmFailedError\";\n}\n\n/** A feature the build does not have (see its capabilities). */\nexport class UnsupportedFeatureError extends PgwasmError {\n override name = \"UnsupportedFeatureError\";\n}\n\n/** An SQL error from a query, with the query that raised it. */\nexport interface QueryError extends DatabaseError {\n query: string | undefined;\n params: readonly unknown[] | undefined;\n queryOptions: QueryOptions | undefined;\n}\n\n/** Attach the query to the SQL error it raised. */\nexport function makeQueryError(data: {\n error: DatabaseError;\n query: string;\n params: readonly unknown[] | undefined;\n options: QueryOptions | undefined;\n}): QueryError {\n return Object.assign(data.error, { query: data.query, params: data.params, queryOptions: data.options });\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;AASO,MAAM,iCAAgC,eAAc;AAAA,EACzD,WAAW,GAAG;AAAA,IACZ,MAAM,oDAAoD,GAAG,OAAO;AAAA,IACpE,KAAK,WAAW;AAAA,IAChB,KAAK,OAAO;AAAA;AAEhB;AAAA;AAGO,MAAM,qBAAoB,MAAM;AAAA,EAC5B,OAAO;AAClB;AAAA;AAGO,MAAM,iCAAgC,aAAY;AAAA,EAC9C,OAAO;AAAA,EACP;AAAA,EAET,WAAW,CAAC,SAAiB,QAAgB;AAAA,IAC3C,MAAM,wBAAwB,aAAa,QAAQ;AAAA,IACnD,KAAK,UAAU;AAAA;AAEnB;AAAA;AAGO,MAAM,6BAA4B,yBAAwB;AAAA,EACtD,OAAO;AAAA,EAEP,cAAc;AAAA,EAEvB,WAAW,CAAC,SAAiB;AAAA,IAC3B,MACE,SACA,mGACE,+BACJ;AAAA;AAEJ;AAAA;AAGO,MAAM,oCAAmC,aAAY;AAAA,EACjD,OAAO;AAAA,EACP;AAAA,E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;AAAA,IACtB,KAAK,QAAQ;AAAA,IACb,KAAK,SAAS;AAAA;AAElB;AAAA;AAGO,MAAM,oCAAmC,aAAY;AAAA,EACjD,OAAO;AAAA,EACP;AAAA,EAET,WAAW,CAAC,KAAa,QAAgB;AAAA,IACvC,MAAM,qDAAqD,YAAY,KAAK,UAAU,GAAG,GAAG;AAAA,IAC5F,KAAK,MAAM;AAAA;AAEf;AAAA;AAGO,MAAM,4BAA2B,aAAY;AAAA,EACzC,OAAO;AAAA,EAEhB,WAAW,GAAG;AAAA,IACZ,MAAM,8FAA8F;AAAA;AAExG;AAAA;AAGO,MAAM,2BAA0B,aAAY;AAAA,EACxC,OAAO;AAClB;AAAA;AAGO,MAAM,2BAA0B,aAAY;AAAA,EACxC,OAAO;AAAA,EAEhB,WAAW,CAAC,SAAiB;AAAA,IAC3B,MAAM,OAAO;AAAA;AAEjB;AAAA;AAGO,MAAM,2BAA0B,aAAY;AAAA,EACxC,OAAO;AAAA,EAEhB,WAAW,CAAC,OAA6B;AAAA,IACvC,MAAM,aAAa,OAAO;AAAA;AAE9B;AAAA;AAOO,MAAM,2BAA0B,aAAY;AAAA,EACxC,OAAO;AAClB;AAAA;AAGO,MAAM,iCAAgC,aAAY;AAAA,EAC9C,OAAO;AAClB;AAUO,SAAS,cAAc,CAAC,MAKhB;AAAA,EACb,OAAO,OAAO,OAAO,KAAK,OAAO,EAAE,OAAO,KAAK,OAAO,QAAQ,KAAK,QAAQ,cAAc,KAAK,QAAQ,CAAC;AAAA;",
|
|
8
|
+
"debugId": "DD5A44BC9B659C3864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
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\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 uint16(): number {\n const result = this.#bufferView.getUint16(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 const offset = this.#offset;\n if (\n Number.isInteger(offset) &&\n offset >= 0 &&\n Number.isInteger(length) &&\n length >= 0 &&\n length <= this.#bufferView.byteLength - offset\n ) {\n // Decode while the view is borrowed; only the resulting string escapes. Binary bytes() still owns its data.\n const bytes = new Uint8Array(this.#bufferView.buffer, offset, length);\n this.#offset += length;\n return this.#decoder.decode(bytes);\n }\n // Keep slice's clipping/coercion and offset advancement for malformed input.\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",
|
|
6
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\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",
|
|
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.uint16();\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"
|
|
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 type AuthenticationMessage,\n AuthenticationOk,\n AuthenticationSASL,\n AuthenticationSASLContinue,\n AuthenticationSASLFinal,\n BackendKeyDataMessage,\n type BackendMessage,\n bindComplete,\n closeComplete,\n CommandCompleteMessage,\n CopyDataMessage,\n copyDone,\n CopyResponse,\n DatabaseError,\n DataRowMessage,\n emptyQuery,\n Field,\n type MessageName,\n noData,\n NoticeMessage,\n NotificationResponseMessage,\n ParameterDescriptionMessage,\n ParameterStatusMessage,\n parseComplete,\n portalSuspended,\n ReadyForQueryMessage,\n replicationStart,\n RowDescriptionMessage,\n} from \"./messages\";\nimport { type BufferParameter, Modes } 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.uint16();\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
8
|
],
|
|
9
9
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,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+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/B,KAAK,WAAW,QAAQ,KAAK;AAAA,IAC7B,MAAM,SAAiC,CAAC;AAAA,IACxC,IAAI,YAAY,KAAK,QAAQ,OAAO,CAAC;AAAA,IACrC,OAAO,cAAc,QAAM;AAAA,MACzB,OAAO,aAAa,KAAK,QAAQ,QAAQ;AAAA,MACzC,YAAY,KAAK,QAAQ,OAAO,CAAC;AAAA,IACnC;AAAA,IAEA,MAAM,eAAe,OAAO;AAAA,IAC5B,MAAM,UACJ,SAAS,WAAW,IAAI,cAAc,QAAQ,YAAY,IAAI,IAAI,eAAc,gBAAgB,IAAI,QAAQ,IAAI;AAAA,IAElH,QAAQ,WAAW,OAAO;AAAA,IAC1B,QAAQ,OAAO,OAAO;AAAA,IACtB,QAAQ,SAAS,OAAO;AAAA,IACxB,QAAQ,OAAO,OAAO;AAAA,IACtB,QAAQ,WAAW,OAAO;AAAA,IAC1B,QAAQ,mBAAmB,OAAO;AAAA,IAClC,QAAQ,gBAAgB,OAAO;AAAA,IAC/B,QAAQ,QAAQ,OAAO;AAAA,IACvB,QAAQ,SAAS,OAAO;AAAA,IACxB,QAAQ,QAAQ,OAAO;AAAA,IACvB,QAAQ,SAAS,OAAO;AAAA,IACxB,QAAQ,WAAW,OAAO;AAAA,IAC1B,QAAQ,aAAa,OAAO;AAAA,IAC5B,QAAQ,OAAO,OAAO;AAAA,IACtB,QAAQ,OAAO,OAAO;AAAA,IACtB,QAAQ,UAAU,OAAO;AAAA,IACzB,OAAO;AAAA;AAEX;",
|
|
10
10
|
"debugId": "224E80D76BE533DA64756E2164756E21",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
parseType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4eb2pcfr.js";
|
|
5
5
|
import {
|
|
6
6
|
RowDescriptionMessage,
|
|
7
7
|
ParameterDescriptionMessage,
|
|
8
8
|
CommandCompleteMessage,
|
|
9
9
|
DataRowMessage
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ryjxx1c8.js";
|
|
11
11
|
|
|
12
12
|
// packages/pgwasm/src/core/names.ts
|
|
13
13
|
function toPostgresName(input) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"sources": ["../src/core/names.ts", "../src/core/parse.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// Began as a copy of `@electric-sql/pglite` (taken under its PostgreSQL License option, © ElectricSQL\n// — see NOTICE). Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\n/**\n * The name Postgres stores for an identifier: a quoted one keeps its case (quotes removed), an\n * unquoted one is folded to lower case. Used to key notification listeners the way Postgres names\n * the channel.\n */\nexport function toPostgresName(input: string): string {\n if (input.startsWith('\"') && input.endsWith('\"') && input.length >= 2) {\n return input.slice(1, -1);\n }\n return input.toLowerCase();\n}\n\n/** Quote an identifier for SQL: wrap in double quotes, doubling any inside. */\nexport function quoteIdentifier(name: string): string {\n return `\"${name.replaceAll('\"', '\"\"')}\"`;\n}\n\n/** A random 32-character hex id, for the names of temporary objects. */\nexport function randomId(): string {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n",
|
|
6
|
-
"// Began as a copy of `@electric-sql/pglite` (taken under its PostgreSQL License option, © ElectricSQL\n// — see NOTICE). Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\nimport type { QueryOptions, Results, Row } from \"../interface\";\nimport {\n CommandCompleteMessage,\n DataRowMessage,\n ParameterDescriptionMessage,\n RowDescriptionMessage,\n
|
|
6
|
+
"// Began as a copy of `@electric-sql/pglite` (taken under its PostgreSQL License option, © ElectricSQL\n// — see NOTICE). Owned outright (ADR-0062); compatibility with PGlite is an anti-goal — evolve freely.\n\nimport type { QueryOptions, Results, Row } from \"../interface\";\nimport {\n type BackendMessage,\n CommandCompleteMessage,\n DataRowMessage,\n ParameterDescriptionMessage,\n RowDescriptionMessage,\n} from \"../protocol/wire/messages\";\nimport { type Parser, parseType } from \"../types\";\n\n/**\n * Turn the backend messages of a simple or extended query into result sets, one per statement\n * (https://www.postgresql.org/docs/current/protocol-flow.html).\n */\nexport function parseResults(\n messages: readonly BackendMessage[],\n defaultParsers: Readonly<Record<number | string, Parser>>,\n options?: QueryOptions,\n blob?: Blob,\n): Results<unknown>[] {\n const resultSets: Results<unknown>[] = [];\n let current: Results<unknown> = { rows: [], fields: [] };\n let affectedRows = 0;\n // Instance parsers are already normalized; only per-query overrides need another map.\n const parsers = options?.parsers === undefined ? defaultParsers : { ...defaultParsers, ...options.parsers };\n\n for (const message of messages) {\n if (message instanceof RowDescriptionMessage) {\n current.fields = message.fields.map((field) => ({ name: field.name, dataTypeID: field.dataTypeID }));\n } else if (message instanceof DataRowMessage) {\n const fields = current.fields;\n const values = message.fields;\n if (options?.rowMode === \"array\") {\n const row = new Array<unknown>(values.length);\n for (let index = 0; index < values.length; index++) {\n row[index] = parseType(values[index]!, fields[index]?.dataTypeID ?? 0, parsers);\n }\n current.rows.push(row);\n } else {\n const row: Row = {};\n for (let index = 0; index < values.length; index++) {\n const field = fields[index];\n const name = field?.name ?? String(index);\n const value = parseType(values[index]!, field?.dataTypeID ?? 0, parsers);\n // SQL column names are data: assigning __proto__ on {} would invoke its inherited setter.\n if (name === \"__proto__\") {\n Object.defineProperty(row, name, { value, enumerable: true, writable: true, configurable: true });\n } else {\n row[name] = value;\n }\n }\n current.rows.push(row);\n }\n } else if (message instanceof CommandCompleteMessage) {\n // A tag that carries a row count ends in it (\"SELECT 2\", \"UPDATE 3\", \"INSERT 0 5\"); the rest end\n // in a word (\"CREATE TABLE\").\n const parts = message.text.split(\" \");\n const command = parts[0] ?? \"\";\n const rowCount = Number.parseInt(parts[parts.length - 1] ?? \"\", 10);\n switch (command) {\n case \"INSERT\":\n case \"UPDATE\":\n case \"DELETE\":\n case \"COPY\":\n case \"MERGE\":\n affectedRows += rowCount;\n break;\n }\n const result: Results<unknown> = { ...current, command, affectedRows };\n if (!Number.isNaN(rowCount)) result.rowCount = rowCount;\n if (blob) result.blob = blob;\n resultSets.push(result);\n current = { rows: [], fields: [] };\n }\n }\n\n if (resultSets.length === 0) {\n resultSets.push({ affectedRows: 0, rows: [], fields: [] });\n }\n return resultSets;\n}\n\n/** The parameter type OIDs from a Describe(statement) reply, when it has them. */\nexport function parseDescribeStatementResults(messages: readonly BackendMessage[]): number[] {\n const message = messages.find(\n (msg): msg is ParameterDescriptionMessage => msg instanceof ParameterDescriptionMessage,\n );\n return message ? message.dataTypeIDs : [];\n}\n"
|
|
7
7
|
],
|
|
8
8
|
"mappings": ";;;;;;;;;;;;AAQO,SAAS,cAAc,CAAC,OAAuB;AAAA,EACpD,IAAI,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,KAAK,MAAM,UAAU,GAAG;AAAA,IACrE,OAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AAAA,EACA,OAAO,MAAM,YAAY;AAAA;AAIpB,SAAS,eAAe,CAAC,MAAsB;AAAA,EACpD,OAAO,IAAI,KAAK,WAAW,KAAK,IAAI;AAAA;AAI/B,SAAS,QAAQ,GAAW;AAAA,EACjC,MAAM,QAAQ,IAAI,WAAW,EAAE;AAAA,EAC/B,OAAO,gBAAgB,KAAK;AAAA,EAC5B,OAAO,MAAM,KAAK,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAAA;;;ACPzE,SAAS,YAAY,CAC1B,UACA,gBACA,SACA,MACoB;AAAA,EACpB,MAAM,aAAiC,CAAC;AAAA,EACxC,IAAI,UAA4B,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE;AAAA,EACvD,IAAI,eAAe;AAAA,EAEnB,MAAM,UAAU,SAAS,YAAY,YAAY,iBAAiB,KAAK,mBAAmB,QAAQ,QAAQ;AAAA,EAE1G,WAAW,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