@pgxsinkit/pgwasm 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +111 -0
- package/README.md +56 -0
- package/dist/build/index.d.ts +8 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +21 -0
- package/dist/build/index.js.map +9 -0
- package/dist/build/seam.d.ts +174 -0
- package/dist/build/seam.d.ts.map +1 -0
- package/dist/chunk-0w227vw2.js +233 -0
- package/dist/chunk-0w227vw2.js.map +11 -0
- package/dist/chunk-74gcrk47.js +563 -0
- package/dist/chunk-74gcrk47.js.map +14 -0
- package/dist/chunk-at1py5s5.js +373 -0
- package/dist/chunk-at1py5s5.js.map +12 -0
- package/dist/chunk-cpsnmzrf.js +126 -0
- package/dist/chunk-cpsnmzrf.js.map +10 -0
- package/dist/chunk-d82gg1hx.js +306 -0
- package/dist/chunk-d82gg1hx.js.map +10 -0
- package/dist/chunk-gjf102c9.js +1005 -0
- package/dist/chunk-gjf102c9.js.map +16 -0
- package/dist/chunk-kb3rsr7n.js +19 -0
- package/dist/chunk-kb3rsr7n.js.map +9 -0
- package/dist/chunk-tdvrvgt5.js +83 -0
- package/dist/chunk-tdvrvgt5.js.map +11 -0
- package/dist/chunk-z0c40tja.js +50 -0
- package/dist/chunk-z0c40tja.js.map +10 -0
- package/dist/core/data-dir-archive.d.ts +17 -0
- package/dist/core/data-dir-archive.d.ts.map +1 -0
- package/dist/core/internals.d.ts +59 -0
- package/dist/core/internals.d.ts.map +1 -0
- package/dist/core/marker.d.ts +35 -0
- package/dist/core/marker.d.ts.map +1 -0
- package/dist/core/mutex.d.ts +9 -0
- package/dist/core/mutex.d.ts.map +1 -0
- package/dist/core/names.d.ts +11 -0
- package/dist/core/names.d.ts.map +1 -0
- package/dist/core/parse.d.ts +11 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/core/pgwasm.d.ts +53 -0
- package/dist/core/pgwasm.d.ts.map +1 -0
- package/dist/core/storage.d.ts +14 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/create.d.ts +10 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/drizzle/codecs.d.ts +9 -0
- package/dist/drizzle/codecs.d.ts.map +1 -0
- package/dist/drizzle/driver.d.ts +50 -0
- package/dist/drizzle/driver.d.ts.map +1 -0
- package/dist/drizzle/index.d.ts +4 -0
- package/dist/drizzle/index.d.ts.map +1 -0
- package/dist/drizzle/index.js +261 -0
- package/dist/drizzle/index.js.map +12 -0
- package/dist/drizzle/session.d.ts +39 -0
- package/dist/drizzle/session.d.ts.map +1 -0
- package/dist/errors.d.ts +115 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/fs/base-filesystem.d.ts +118 -0
- package/dist/fs/base-filesystem.d.ts.map +1 -0
- package/dist/fs/index.d.ts +2 -0
- package/dist/fs/index.d.ts.map +1 -0
- package/dist/fs/index.js +11 -0
- package/dist/fs/index.js.map +9 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +9 -0
- package/dist/interface.d.ts +165 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/live/debounce-mutex.d.ts +6 -0
- package/dist/live/debounce-mutex.d.ts.map +1 -0
- package/dist/live/format-query.d.ts +8 -0
- package/dist/live/format-query.d.ts.map +1 -0
- package/dist/live/index.d.ts +9 -0
- package/dist/live/index.d.ts.map +1 -0
- package/dist/live/index.js +601 -0
- package/dist/live/index.js.map +12 -0
- package/dist/live/interface.d.ts +86 -0
- package/dist/live/interface.d.ts.map +1 -0
- package/dist/opfs/broker/client.d.ts +163 -0
- package/dist/opfs/broker/client.d.ts.map +1 -0
- package/dist/opfs/broker/protocol.d.ts +326 -0
- package/dist/opfs/broker/protocol.d.ts.map +1 -0
- package/dist/opfs/broker/server.d.ts +84 -0
- package/dist/opfs/broker/server.d.ts.map +1 -0
- package/dist/opfs/core/checksum.d.ts +3 -0
- package/dist/opfs/core/checksum.d.ts.map +1 -0
- package/dist/opfs/core/codec.d.ts +73 -0
- package/dist/opfs/core/codec.d.ts.map +1 -0
- package/dist/opfs/core/errors.d.ts +80 -0
- package/dist/opfs/core/errors.d.ts.map +1 -0
- package/dist/opfs/core/limits.d.ts +35 -0
- package/dist/opfs/core/limits.d.ts.map +1 -0
- package/dist/opfs/core/memory-port.d.ts +51 -0
- package/dist/opfs/core/memory-port.d.ts.map +1 -0
- package/dist/opfs/core/metadata-store.d.ts +19 -0
- package/dist/opfs/core/metadata-store.d.ts.map +1 -0
- package/dist/opfs/core/mounted-vfs.d.ts +119 -0
- package/dist/opfs/core/mounted-vfs.d.ts.map +1 -0
- package/dist/opfs/core/path.d.ts +14 -0
- package/dist/opfs/core/path.d.ts.map +1 -0
- package/dist/opfs/core/port.d.ts +30 -0
- package/dist/opfs/core/port.d.ts.map +1 -0
- package/dist/opfs/core/repacked-vfs.d.ts +138 -0
- package/dist/opfs/core/repacked-vfs.d.ts.map +1 -0
- package/dist/opfs/core/state-machine.d.ts +296 -0
- package/dist/opfs/core/state-machine.d.ts.map +1 -0
- package/dist/opfs/create.d.ts +50 -0
- package/dist/opfs/create.d.ts.map +1 -0
- package/dist/opfs/file-port.d.ts +14 -0
- package/dist/opfs/file-port.d.ts.map +1 -0
- package/dist/opfs/index.d.ts +37 -0
- package/dist/opfs/index.d.ts.map +1 -0
- package/dist/opfs/index.js +6671 -0
- package/dist/opfs/index.js.map +28 -0
- package/dist/opfs/opfs-port.d.ts +34 -0
- package/dist/opfs/opfs-port.d.ts.map +1 -0
- package/dist/opfs/opfs-repacked-fs.d.ts +55 -0
- package/dist/opfs/opfs-repacked-fs.d.ts.map +1 -0
- package/dist/opfs/wasi/preview1.d.ts +228 -0
- package/dist/opfs/wasi/preview1.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +15 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +23 -0
- package/dist/protocol/index.js.map +10 -0
- package/dist/protocol/wire/buffer-reader.d.ts +13 -0
- package/dist/protocol/wire/buffer-reader.d.ts.map +1 -0
- package/dist/protocol/wire/buffer-writer.d.ts +12 -0
- package/dist/protocol/wire/buffer-writer.d.ts.map +1 -0
- package/dist/protocol/wire/index.d.ts +5 -0
- package/dist/protocol/wire/index.d.ts.map +1 -0
- package/dist/protocol/wire/messages.d.ts +194 -0
- package/dist/protocol/wire/messages.d.ts.map +1 -0
- package/dist/protocol/wire/parser.d.ts +12 -0
- package/dist/protocol/wire/parser.d.ts.map +1 -0
- package/dist/protocol/wire/serializer.d.ts +61 -0
- package/dist/protocol/wire/serializer.d.ts.map +1 -0
- package/dist/protocol/wire/string-utils.d.ts +6 -0
- package/dist/protocol/wire/string-utils.d.ts.map +1 -0
- package/dist/protocol/wire/types.d.ts +7 -0
- package/dist/protocol/wire/types.d.ts.map +1 -0
- package/dist/tar/gzip.d.ts +7 -0
- package/dist/tar/gzip.d.ts.map +1 -0
- package/dist/tar/tar.d.ts +39 -0
- package/dist/tar/tar.d.ts.map +1 -0
- package/dist/templating.d.ts +42 -0
- package/dist/templating.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
- package/skills/opfs/SKILL.md +138 -0
- package/src/build/index.ts +23 -0
- package/src/build/seam.ts +179 -0
- package/src/core/data-dir-archive.ts +68 -0
- package/src/core/internals.ts +87 -0
- package/src/core/marker.ts +94 -0
- package/src/core/mutex.ts +16 -0
- package/src/core/names.ts +26 -0
- package/src/core/parse.ts +79 -0
- package/src/core/pgwasm.ts +876 -0
- package/src/core/storage.ts +70 -0
- package/src/create.ts +134 -0
- package/src/drizzle/codecs.ts +114 -0
- package/src/drizzle/driver.ts +141 -0
- package/src/drizzle/index.ts +15 -0
- package/src/drizzle/session.ts +133 -0
- package/src/errors.ts +201 -0
- package/src/fs/base-filesystem.ts +149 -0
- package/src/fs/index.ts +7 -0
- package/src/index.ts +44 -0
- package/src/interface.ts +186 -0
- package/src/live/debounce-mutex.ts +45 -0
- package/src/live/format-query.ts +47 -0
- package/src/live/index.ts +707 -0
- package/src/live/interface.ts +109 -0
- package/src/opfs/broker/client.ts +482 -0
- package/src/opfs/broker/protocol.ts +624 -0
- package/src/opfs/broker/server.ts +522 -0
- package/src/opfs/core/checksum.ts +85 -0
- package/src/opfs/core/codec.ts +1051 -0
- package/src/opfs/core/errors.ts +134 -0
- package/src/opfs/core/limits.ts +68 -0
- package/src/opfs/core/memory-port.ts +459 -0
- package/src/opfs/core/metadata-store.ts +512 -0
- package/src/opfs/core/mounted-vfs.ts +407 -0
- package/src/opfs/core/path.ts +82 -0
- package/src/opfs/core/port.ts +114 -0
- package/src/opfs/core/repacked-vfs.ts +1464 -0
- package/src/opfs/core/state-machine.ts +1699 -0
- package/src/opfs/create.ts +125 -0
- package/src/opfs/file-port.ts +183 -0
- package/src/opfs/index.ts +113 -0
- package/src/opfs/opfs-port.ts +90 -0
- package/src/opfs/opfs-repacked-fs.ts +210 -0
- package/src/opfs/wasi/preview1.ts +1016 -0
- package/src/protocol/index.ts +24 -0
- package/src/protocol/wire/buffer-reader.ts +60 -0
- package/src/protocol/wire/buffer-writer.ts +93 -0
- package/src/protocol/wire/index.ts +15 -0
- package/src/protocol/wire/messages.ts +332 -0
- package/src/protocol/wire/parser.ts +373 -0
- package/src/protocol/wire/serializer.ts +233 -0
- package/src/protocol/wire/string-utils.ts +18 -0
- package/src/protocol/wire/types.ts +12 -0
- package/src/tar/gzip.ts +36 -0
- package/src/tar/tar.ts +253 -0
- package/src/templating.ts +103 -0
- package/src/types.ts +283 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
parseComplete,
|
|
4
|
+
bindComplete,
|
|
5
|
+
closeComplete,
|
|
6
|
+
noData,
|
|
7
|
+
portalSuspended,
|
|
8
|
+
replicationStart,
|
|
9
|
+
emptyQuery,
|
|
10
|
+
copyDone,
|
|
11
|
+
AuthenticationOk,
|
|
12
|
+
AuthenticationCleartextPassword,
|
|
13
|
+
AuthenticationMD5Password,
|
|
14
|
+
AuthenticationSASL,
|
|
15
|
+
AuthenticationSASLContinue,
|
|
16
|
+
AuthenticationSASLFinal,
|
|
17
|
+
DatabaseError2,
|
|
18
|
+
CopyDataMessage,
|
|
19
|
+
CopyResponse,
|
|
20
|
+
Field,
|
|
21
|
+
RowDescriptionMessage,
|
|
22
|
+
ParameterDescriptionMessage,
|
|
23
|
+
ParameterStatusMessage,
|
|
24
|
+
BackendKeyDataMessage,
|
|
25
|
+
NotificationResponseMessage,
|
|
26
|
+
ReadyForQueryMessage,
|
|
27
|
+
CommandCompleteMessage,
|
|
28
|
+
DataRowMessage,
|
|
29
|
+
NoticeMessage
|
|
30
|
+
} from "./chunk-74gcrk47.js";
|
|
31
|
+
|
|
32
|
+
// packages/pgwasm/src/protocol/wire/types.ts
|
|
33
|
+
var Modes2 = {
|
|
34
|
+
text: 0,
|
|
35
|
+
binary: 1
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// packages/pgwasm/src/protocol/wire/buffer-reader.ts
|
|
39
|
+
var emptyBuffer = new ArrayBuffer(0);
|
|
40
|
+
|
|
41
|
+
class BufferReader {
|
|
42
|
+
#bufferView = new DataView(emptyBuffer);
|
|
43
|
+
#offset;
|
|
44
|
+
#decoder = new TextDecoder("utf-8");
|
|
45
|
+
constructor(offset = 0) {
|
|
46
|
+
this.#offset = offset;
|
|
47
|
+
}
|
|
48
|
+
setBuffer(offset, buffer) {
|
|
49
|
+
this.#offset = offset;
|
|
50
|
+
this.#bufferView = new DataView(buffer);
|
|
51
|
+
}
|
|
52
|
+
int16() {
|
|
53
|
+
const result = this.#bufferView.getInt16(this.#offset, false);
|
|
54
|
+
this.#offset += 2;
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
byte() {
|
|
58
|
+
const result = this.#bufferView.getUint8(this.#offset);
|
|
59
|
+
this.#offset++;
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
int32() {
|
|
63
|
+
const result = this.#bufferView.getInt32(this.#offset, false);
|
|
64
|
+
this.#offset += 4;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
string(length) {
|
|
68
|
+
return this.#decoder.decode(this.bytes(length));
|
|
69
|
+
}
|
|
70
|
+
cstring() {
|
|
71
|
+
const start = this.#offset;
|
|
72
|
+
let end = start;
|
|
73
|
+
while (this.#bufferView.getUint8(end++) !== 0) {}
|
|
74
|
+
const result = this.string(end - start - 1);
|
|
75
|
+
this.#offset = end;
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
bytes(length) {
|
|
79
|
+
const result = this.#bufferView.buffer.slice(this.#offset, this.#offset + length);
|
|
80
|
+
this.#offset += length;
|
|
81
|
+
return new Uint8Array(result);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// packages/pgwasm/src/protocol/wire/parser.ts
|
|
86
|
+
var CODE_LENGTH = 1;
|
|
87
|
+
var LEN_LENGTH = 4;
|
|
88
|
+
var HEADER_LENGTH = CODE_LENGTH + LEN_LENGTH;
|
|
89
|
+
var emptyBuffer2 = new ArrayBuffer(0);
|
|
90
|
+
var MessageCodes = {
|
|
91
|
+
DataRow: 68,
|
|
92
|
+
ParseComplete: 49,
|
|
93
|
+
BindComplete: 50,
|
|
94
|
+
CloseComplete: 51,
|
|
95
|
+
CommandComplete: 67,
|
|
96
|
+
ReadyForQuery: 90,
|
|
97
|
+
NoData: 110,
|
|
98
|
+
NotificationResponse: 65,
|
|
99
|
+
AuthenticationResponse: 82,
|
|
100
|
+
ParameterStatus: 83,
|
|
101
|
+
BackendKeyData: 75,
|
|
102
|
+
ErrorMessage: 69,
|
|
103
|
+
NoticeMessage: 78,
|
|
104
|
+
RowDescriptionMessage: 84,
|
|
105
|
+
ParameterDescriptionMessage: 116,
|
|
106
|
+
PortalSuspended: 115,
|
|
107
|
+
ReplicationStart: 87,
|
|
108
|
+
EmptyQuery: 73,
|
|
109
|
+
CopyIn: 71,
|
|
110
|
+
CopyOut: 72,
|
|
111
|
+
CopyDone: 99,
|
|
112
|
+
CopyData: 100
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
class Parser2 {
|
|
116
|
+
#bufferView = new DataView(emptyBuffer2);
|
|
117
|
+
#bufferRemainingLength = 0;
|
|
118
|
+
#bufferOffset = 0;
|
|
119
|
+
#reader = new BufferReader;
|
|
120
|
+
parse(buffer, callback) {
|
|
121
|
+
this.#mergeBuffer(ArrayBuffer.isView(buffer) ? buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength) : buffer);
|
|
122
|
+
const bufferFullLength = this.#bufferOffset + this.#bufferRemainingLength;
|
|
123
|
+
let offset = this.#bufferOffset;
|
|
124
|
+
while (offset + HEADER_LENGTH <= bufferFullLength) {
|
|
125
|
+
const code = this.#bufferView.getUint8(offset);
|
|
126
|
+
const length = this.#bufferView.getUint32(offset + CODE_LENGTH, false);
|
|
127
|
+
const fullMessageLength = CODE_LENGTH + length;
|
|
128
|
+
if (fullMessageLength + offset <= bufferFullLength && length > 0) {
|
|
129
|
+
let message;
|
|
130
|
+
try {
|
|
131
|
+
message = this.#handlePacket(offset + HEADER_LENGTH, code, length, this.#bufferView.buffer);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
this.#resetBuffer();
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
callback(message);
|
|
137
|
+
offset += fullMessageLength;
|
|
138
|
+
} else {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (offset === bufferFullLength) {
|
|
143
|
+
this.#resetBuffer();
|
|
144
|
+
} else {
|
|
145
|
+
this.#bufferRemainingLength = bufferFullLength - offset;
|
|
146
|
+
this.#bufferOffset = offset;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
#resetBuffer() {
|
|
150
|
+
this.#bufferView = new DataView(emptyBuffer2);
|
|
151
|
+
this.#bufferRemainingLength = 0;
|
|
152
|
+
this.#bufferOffset = 0;
|
|
153
|
+
}
|
|
154
|
+
#mergeBuffer(buffer) {
|
|
155
|
+
if (this.#bufferRemainingLength > 0) {
|
|
156
|
+
const newLength = this.#bufferRemainingLength + buffer.byteLength;
|
|
157
|
+
const newFullLength = newLength + this.#bufferOffset;
|
|
158
|
+
if (newFullLength > this.#bufferView.byteLength) {
|
|
159
|
+
let newBuffer;
|
|
160
|
+
if (newLength <= this.#bufferView.byteLength && this.#bufferOffset >= this.#bufferRemainingLength) {
|
|
161
|
+
newBuffer = this.#bufferView.buffer;
|
|
162
|
+
} else {
|
|
163
|
+
let newBufferLength = this.#bufferView.byteLength * 2;
|
|
164
|
+
while (newLength >= newBufferLength) {
|
|
165
|
+
newBufferLength *= 2;
|
|
166
|
+
}
|
|
167
|
+
newBuffer = new ArrayBuffer(newBufferLength);
|
|
168
|
+
}
|
|
169
|
+
new Uint8Array(newBuffer).set(new Uint8Array(this.#bufferView.buffer, this.#bufferOffset, this.#bufferRemainingLength));
|
|
170
|
+
this.#bufferView = new DataView(newBuffer);
|
|
171
|
+
this.#bufferOffset = 0;
|
|
172
|
+
}
|
|
173
|
+
new Uint8Array(this.#bufferView.buffer).set(new Uint8Array(buffer), this.#bufferOffset + this.#bufferRemainingLength);
|
|
174
|
+
this.#bufferRemainingLength = newLength;
|
|
175
|
+
} else {
|
|
176
|
+
this.#bufferView = new DataView(buffer);
|
|
177
|
+
this.#bufferOffset = 0;
|
|
178
|
+
this.#bufferRemainingLength = buffer.byteLength;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
#handlePacket(offset, code, length, bytes) {
|
|
182
|
+
switch (code) {
|
|
183
|
+
case MessageCodes.BindComplete:
|
|
184
|
+
return bindComplete;
|
|
185
|
+
case MessageCodes.ParseComplete:
|
|
186
|
+
return parseComplete;
|
|
187
|
+
case MessageCodes.CloseComplete:
|
|
188
|
+
return closeComplete;
|
|
189
|
+
case MessageCodes.NoData:
|
|
190
|
+
return noData;
|
|
191
|
+
case MessageCodes.PortalSuspended:
|
|
192
|
+
return portalSuspended;
|
|
193
|
+
case MessageCodes.CopyDone:
|
|
194
|
+
return copyDone;
|
|
195
|
+
case MessageCodes.ReplicationStart:
|
|
196
|
+
return replicationStart;
|
|
197
|
+
case MessageCodes.EmptyQuery:
|
|
198
|
+
return emptyQuery;
|
|
199
|
+
case MessageCodes.DataRow:
|
|
200
|
+
return this.#parseDataRowMessage(offset, length, bytes);
|
|
201
|
+
case MessageCodes.CommandComplete:
|
|
202
|
+
return this.#parseCommandCompleteMessage(offset, length, bytes);
|
|
203
|
+
case MessageCodes.ReadyForQuery:
|
|
204
|
+
return this.#parseReadyForQueryMessage(offset, length, bytes);
|
|
205
|
+
case MessageCodes.NotificationResponse:
|
|
206
|
+
return this.#parseNotificationMessage(offset, length, bytes);
|
|
207
|
+
case MessageCodes.AuthenticationResponse:
|
|
208
|
+
return this.#parseAuthenticationResponse(offset, length, bytes);
|
|
209
|
+
case MessageCodes.ParameterStatus:
|
|
210
|
+
return this.#parseParameterStatusMessage(offset, length, bytes);
|
|
211
|
+
case MessageCodes.BackendKeyData:
|
|
212
|
+
return this.#parseBackendKeyData(offset, length, bytes);
|
|
213
|
+
case MessageCodes.ErrorMessage:
|
|
214
|
+
return this.#parseErrorMessage(offset, length, bytes, "error");
|
|
215
|
+
case MessageCodes.NoticeMessage:
|
|
216
|
+
return this.#parseErrorMessage(offset, length, bytes, "notice");
|
|
217
|
+
case MessageCodes.RowDescriptionMessage:
|
|
218
|
+
return this.#parseRowDescriptionMessage(offset, length, bytes);
|
|
219
|
+
case MessageCodes.ParameterDescriptionMessage:
|
|
220
|
+
return this.#parseParameterDescriptionMessage(offset, length, bytes);
|
|
221
|
+
case MessageCodes.CopyIn:
|
|
222
|
+
return this.#parseCopyMessage(offset, length, bytes, "copyInResponse");
|
|
223
|
+
case MessageCodes.CopyOut:
|
|
224
|
+
return this.#parseCopyMessage(offset, length, bytes, "copyOutResponse");
|
|
225
|
+
case MessageCodes.CopyData:
|
|
226
|
+
return this.#parseCopyData(offset, length, bytes);
|
|
227
|
+
default:
|
|
228
|
+
return new DatabaseError2(`received invalid response: ${code.toString(16)}`, length, "error");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
#setBuffer(offset, bytes) {
|
|
232
|
+
this.#reader.setBuffer(offset, bytes);
|
|
233
|
+
}
|
|
234
|
+
#parseReadyForQueryMessage(offset, length, bytes) {
|
|
235
|
+
this.#setBuffer(offset, bytes);
|
|
236
|
+
return new ReadyForQueryMessage(length, this.#reader.string(1));
|
|
237
|
+
}
|
|
238
|
+
#parseCommandCompleteMessage(offset, length, bytes) {
|
|
239
|
+
this.#setBuffer(offset, bytes);
|
|
240
|
+
return new CommandCompleteMessage(length, this.#reader.cstring());
|
|
241
|
+
}
|
|
242
|
+
#parseCopyData(offset, length, bytes) {
|
|
243
|
+
const chunk = bytes.slice(offset, offset + (length - 4));
|
|
244
|
+
return new CopyDataMessage(length, new Uint8Array(chunk));
|
|
245
|
+
}
|
|
246
|
+
#parseCopyMessage(offset, length, bytes, messageName) {
|
|
247
|
+
this.#setBuffer(offset, bytes);
|
|
248
|
+
const isBinary = this.#reader.byte() !== 0;
|
|
249
|
+
const columnCount = this.#reader.int16();
|
|
250
|
+
const message = new CopyResponse(length, messageName, isBinary, columnCount);
|
|
251
|
+
for (let i = 0;i < columnCount; i++) {
|
|
252
|
+
message.columnTypes[i] = this.#reader.int16();
|
|
253
|
+
}
|
|
254
|
+
return message;
|
|
255
|
+
}
|
|
256
|
+
#parseNotificationMessage(offset, length, bytes) {
|
|
257
|
+
this.#setBuffer(offset, bytes);
|
|
258
|
+
const processId = this.#reader.int32();
|
|
259
|
+
const channel = this.#reader.cstring();
|
|
260
|
+
const payload = this.#reader.cstring();
|
|
261
|
+
return new NotificationResponseMessage(length, processId, channel, payload);
|
|
262
|
+
}
|
|
263
|
+
#parseRowDescriptionMessage(offset, length, bytes) {
|
|
264
|
+
this.#setBuffer(offset, bytes);
|
|
265
|
+
const fieldCount = this.#reader.int16();
|
|
266
|
+
const fields = [];
|
|
267
|
+
for (let i = 0;i < fieldCount; i++) {
|
|
268
|
+
fields.push(this.#parseField());
|
|
269
|
+
}
|
|
270
|
+
return new RowDescriptionMessage(length, fields);
|
|
271
|
+
}
|
|
272
|
+
#parseField() {
|
|
273
|
+
const name = this.#reader.cstring();
|
|
274
|
+
const tableID = this.#reader.int32();
|
|
275
|
+
const columnID = this.#reader.int16();
|
|
276
|
+
const dataTypeID = this.#reader.int32();
|
|
277
|
+
const dataTypeSize = this.#reader.int16();
|
|
278
|
+
const dataTypeModifier = this.#reader.int32();
|
|
279
|
+
const mode = this.#reader.int16() === 0 ? Modes2.text : Modes2.binary;
|
|
280
|
+
return new Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
|
|
281
|
+
}
|
|
282
|
+
#parseParameterDescriptionMessage(offset, length, bytes) {
|
|
283
|
+
this.#setBuffer(offset, bytes);
|
|
284
|
+
const parameterCount = this.#reader.int16();
|
|
285
|
+
const dataTypeIDs = [];
|
|
286
|
+
for (let i = 0;i < parameterCount; i++) {
|
|
287
|
+
dataTypeIDs.push(this.#reader.int32());
|
|
288
|
+
}
|
|
289
|
+
return new ParameterDescriptionMessage(length, dataTypeIDs);
|
|
290
|
+
}
|
|
291
|
+
#parseDataRowMessage(offset, length, bytes) {
|
|
292
|
+
this.#setBuffer(offset, bytes);
|
|
293
|
+
const fieldCount = this.#reader.int16();
|
|
294
|
+
const fields = [];
|
|
295
|
+
for (let i = 0;i < fieldCount; i++) {
|
|
296
|
+
const len = this.#reader.int32();
|
|
297
|
+
fields.push(len === -1 ? null : this.#reader.string(len));
|
|
298
|
+
}
|
|
299
|
+
return new DataRowMessage(length, fields);
|
|
300
|
+
}
|
|
301
|
+
#parseParameterStatusMessage(offset, length, bytes) {
|
|
302
|
+
this.#setBuffer(offset, bytes);
|
|
303
|
+
const name = this.#reader.cstring();
|
|
304
|
+
const value = this.#reader.cstring();
|
|
305
|
+
return new ParameterStatusMessage(length, name, value);
|
|
306
|
+
}
|
|
307
|
+
#parseBackendKeyData(offset, length, bytes) {
|
|
308
|
+
this.#setBuffer(offset, bytes);
|
|
309
|
+
const processID = this.#reader.int32();
|
|
310
|
+
const secretKey = this.#reader.int32();
|
|
311
|
+
return new BackendKeyDataMessage(length, processID, secretKey);
|
|
312
|
+
}
|
|
313
|
+
#parseAuthenticationResponse(offset, length, bytes) {
|
|
314
|
+
this.#setBuffer(offset, bytes);
|
|
315
|
+
const code = this.#reader.int32();
|
|
316
|
+
switch (code) {
|
|
317
|
+
case 0:
|
|
318
|
+
return new AuthenticationOk(length);
|
|
319
|
+
case 3:
|
|
320
|
+
return new AuthenticationCleartextPassword(length);
|
|
321
|
+
case 5:
|
|
322
|
+
return new AuthenticationMD5Password(length, this.#reader.bytes(4));
|
|
323
|
+
case 10: {
|
|
324
|
+
const mechanisms = [];
|
|
325
|
+
for (;; ) {
|
|
326
|
+
const mechanism = this.#reader.cstring();
|
|
327
|
+
if (mechanism.length === 0) {
|
|
328
|
+
return new AuthenticationSASL(length, mechanisms);
|
|
329
|
+
}
|
|
330
|
+
mechanisms.push(mechanism);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
case 11:
|
|
334
|
+
return new AuthenticationSASLContinue(length, this.#reader.string(length - 8));
|
|
335
|
+
case 12:
|
|
336
|
+
return new AuthenticationSASLFinal(length, this.#reader.string(length - 8));
|
|
337
|
+
default:
|
|
338
|
+
throw new Error(`Unknown authenticationOk message type ${code}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
#parseErrorMessage(offset, length, bytes, name) {
|
|
342
|
+
this.#setBuffer(offset, bytes);
|
|
343
|
+
const fields = {};
|
|
344
|
+
let fieldType = this.#reader.string(1);
|
|
345
|
+
while (fieldType !== "\x00") {
|
|
346
|
+
fields[fieldType] = this.#reader.cstring();
|
|
347
|
+
fieldType = this.#reader.string(1);
|
|
348
|
+
}
|
|
349
|
+
const messageValue = fields["M"];
|
|
350
|
+
const message = name === "notice" ? new NoticeMessage(length, messageValue) : new DatabaseError2(messageValue ?? "", length, name);
|
|
351
|
+
message.severity = fields["S"];
|
|
352
|
+
message.code = fields["C"];
|
|
353
|
+
message.detail = fields["D"];
|
|
354
|
+
message.hint = fields["H"];
|
|
355
|
+
message.position = fields["P"];
|
|
356
|
+
message.internalPosition = fields["p"];
|
|
357
|
+
message.internalQuery = fields["q"];
|
|
358
|
+
message.where = fields["W"];
|
|
359
|
+
message.schema = fields["s"];
|
|
360
|
+
message.table = fields["t"];
|
|
361
|
+
message.column = fields["c"];
|
|
362
|
+
message.dataType = fields["d"];
|
|
363
|
+
message.constraint = fields["n"];
|
|
364
|
+
message.file = fields["F"];
|
|
365
|
+
message.line = fields["L"];
|
|
366
|
+
message.routine = fields["R"];
|
|
367
|
+
return message;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export { Modes2, Parser2 };
|
|
372
|
+
|
|
373
|
+
//# debugId=9FFE7FE642E6BBAB64756E2164756E21
|
|
@@ -0,0 +1,12 @@
|
|
|
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,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zB,OAAO;AAAA;AAEX;",
|
|
10
|
+
"debugId": "9FFE7FE642E6BBAB64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/pgwasm/src/errors.ts
|
|
3
|
+
class PgwasmError2 extends Error {
|
|
4
|
+
name = "PgwasmError";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
class UnsupportedDataDirError2 extends PgwasmError2 {
|
|
8
|
+
name = "UnsupportedDataDirError";
|
|
9
|
+
dataDir;
|
|
10
|
+
constructor(dataDir, reason) {
|
|
11
|
+
super(`Unsupported dataDir "${dataDir}": ${reason}`);
|
|
12
|
+
this.dataDir = dataDir;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class OpfsAhpRemovedError2 extends UnsupportedDataDirError2 {
|
|
17
|
+
name = "OpfsAhpRemovedError";
|
|
18
|
+
replacement = "@pgxsinkit/pgwasm/opfs";
|
|
19
|
+
constructor(dataDir) {
|
|
20
|
+
super(dataDir, "the opfs-ahp filesystem has been removed; the OPFS store is @pgxsinkit/pgwasm/opfs, passed in " + "explicitly as the `fs` option");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class UnsupportedFilesystemError2 extends PgwasmError2 {
|
|
25
|
+
name = "UnsupportedFilesystemError";
|
|
26
|
+
kind;
|
|
27
|
+
build;
|
|
28
|
+
constructor(kind, build, supported) {
|
|
29
|
+
super(`The "${build.name}" Postgres build does not support ${kind} storage (it supports: ${supported.join(", ")}).`);
|
|
30
|
+
this.kind = kind;
|
|
31
|
+
this.build = build.name;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class CrossOriginIsolationRequiredError2 extends PgwasmError2 {
|
|
36
|
+
name = "CrossOriginIsolationRequiredError";
|
|
37
|
+
constructor(build) {
|
|
38
|
+
super(`The "${build.name}" Postgres build needs a cross-origin-isolated context (SharedArrayBuffer); serve the ` + "page with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class ExtensionBuildMismatchError2 extends PgwasmError2 {
|
|
43
|
+
name = "ExtensionBuildMismatchError";
|
|
44
|
+
constructor(extension, extensionBuild, build) {
|
|
45
|
+
super(`The "${extension}" extension was compiled for the "${extensionBuild}" Postgres build and cannot load into ` + `the "${build.name}" build.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function describeRecorded(recorded) {
|
|
49
|
+
return recorded === "unmarked" ? "an unmarked data directory (created before builds were recorded, by the C build)" : `the "${recorded.build}" Postgres build (data format ${recorded.dataFormat})`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class BuildMismatchError2 extends PgwasmError2 {
|
|
53
|
+
name = "BuildMismatchError";
|
|
54
|
+
expected;
|
|
55
|
+
found;
|
|
56
|
+
source;
|
|
57
|
+
constructor(build, found, source) {
|
|
58
|
+
const what = source === "backup" ? "This Store backup" : "This data directory";
|
|
59
|
+
super(`${what} was created by ${describeRecorded(found)} and cannot be opened with the "${build.name}" build. A ` + "store's Postgres build is fixed when it is created: open it with that build, or destroy the store and " + "re-sync it.");
|
|
60
|
+
this.expected = { build: build.name, dataFormat: build.dataFormat };
|
|
61
|
+
this.found = found;
|
|
62
|
+
this.source = source;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class DataFormatMismatchError2 extends PgwasmError2 {
|
|
67
|
+
name = "DataFormatMismatchError";
|
|
68
|
+
expected;
|
|
69
|
+
found;
|
|
70
|
+
source;
|
|
71
|
+
constructor(build, found, source) {
|
|
72
|
+
super(`This ${source === "backup" ? "Store backup" : "data directory"} is in data format ${found} of the ` + `"${build.name}" Postgres build; this release of the build reads format ${build.dataFormat}.`);
|
|
73
|
+
this.expected = build.dataFormat;
|
|
74
|
+
this.found = found;
|
|
75
|
+
this.source = source;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class BuildMarkerUnreadableError2 extends PgwasmError2 {
|
|
80
|
+
name = "BuildMarkerUnreadableError";
|
|
81
|
+
raw;
|
|
82
|
+
constructor(raw, reason) {
|
|
83
|
+
super(`The data directory's build marker cannot be read (${reason}): ${JSON.stringify(raw)}`);
|
|
84
|
+
this.raw = raw;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class DataDirExistsError2 extends PgwasmError2 {
|
|
89
|
+
name = "DataDirExistsError";
|
|
90
|
+
constructor() {
|
|
91
|
+
super("The data directory already holds a database; a Store backup restores only into an empty one.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class BackupFormatError2 extends PgwasmError2 {
|
|
96
|
+
name = "BackupFormatError";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class StorageInUseError2 extends PgwasmError2 {
|
|
100
|
+
name = "StorageInUseError";
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super(message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class PgwasmClosedError2 extends PgwasmError2 {
|
|
107
|
+
name = "PgwasmClosedError";
|
|
108
|
+
constructor(state) {
|
|
109
|
+
super(`pgwasm is ${state}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class PgwasmFailedError2 extends PgwasmError2 {
|
|
114
|
+
name = "PgwasmFailedError";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class UnsupportedFeatureError2 extends PgwasmError2 {
|
|
118
|
+
name = "UnsupportedFeatureError";
|
|
119
|
+
}
|
|
120
|
+
function makeQueryError(data) {
|
|
121
|
+
return Object.assign(data.error, { query: data.query, params: data.params, queryOptions: data.options });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { PgwasmError2, UnsupportedDataDirError2, OpfsAhpRemovedError2, UnsupportedFilesystemError2, CrossOriginIsolationRequiredError2, ExtensionBuildMismatchError2, BuildMismatchError2, DataFormatMismatchError2, BuildMarkerUnreadableError2, DataDirExistsError2, BackupFormatError2, StorageInUseError2, PgwasmClosedError2, PgwasmFailedError2, UnsupportedFeatureError2, makeQueryError };
|
|
125
|
+
|
|
126
|
+
//# debugId=36B843FDDE04140364756E2164756E21
|
|
@@ -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 type { DatabaseError } from \"./protocol/wire/messages\";\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,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,EACA;AAAA,EAET,WAAW,CAAC,MAAsB,OAAsB,WAAsC;AAAA,IAC5F,MACE,QAAQ,MAAM,yCAAyC,8BAA8B,UAAU,KAAK,IAAI,KAC1G;AAAA,IACA,KAAK,OAAO;AAAA,IACZ,KAAK,QAAQ,MAAM;AAAA;AAEvB;AAAA;AAGO,MAAM,2CAA0C,aAAY;AAAA,EACxD,OAAO;AAAA,E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