@elizaos/plugin-matrix 2.0.3-beta.5 → 2.0.3-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts.d.ts +14 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/connector-account-provider.d.ts +22 -0
- package/dist/connector-account-provider.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4888 -0
- package/dist/index.js.map +56 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/service.d.ts +205 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/types.d.ts +241 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow-credential-provider.d.ts +21 -0
- package/dist/workflow-credential-provider.d.ts.map +1 -0
- package/package.json +3 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,4888 @@
|
|
|
1
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/errors.js
|
|
4
|
+
var messages, setErrorCode = (error, value) => {
|
|
5
|
+
Object.defineProperty(error, "code", {
|
|
6
|
+
value,
|
|
7
|
+
writable: false,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: false
|
|
10
|
+
});
|
|
11
|
+
}, AbortError, ConstraintError, DataError, InvalidAccessError, InvalidStateError, NotFoundError, ReadOnlyError, SyntaxError, TransactionInactiveError, VersionError;
|
|
12
|
+
var init_errors = __esm(() => {
|
|
13
|
+
messages = {
|
|
14
|
+
AbortError: "A request was aborted, for example through a call to IDBTransaction.abort.",
|
|
15
|
+
ConstraintError: "A mutation operation in the transaction failed because a constraint was not satisfied. For example, an object such as an object store or index already exists and a request attempted to create a new one.",
|
|
16
|
+
DataCloneError: "The data being stored could not be cloned by the internal structured cloning algorithm.",
|
|
17
|
+
DataError: "Data provided to an operation does not meet requirements.",
|
|
18
|
+
InvalidAccessError: "An invalid operation was performed on an object. For example transaction creation attempt was made, but an empty scope was provided.",
|
|
19
|
+
InvalidStateError: "An operation was called on an object on which it is not allowed or at a time when it is not allowed. Also occurs if a request is made on a source object that has been deleted or removed. Use TransactionInactiveError or ReadOnlyError when possible, as they are more specific variations of InvalidStateError.",
|
|
20
|
+
NotFoundError: "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.",
|
|
21
|
+
ReadOnlyError: 'The mutating operation was attempted in a "readonly" transaction.',
|
|
22
|
+
TransactionInactiveError: "A request was placed against a transaction which is currently not active, or which is finished.",
|
|
23
|
+
SyntaxError: "The keypath argument contains an invalid key path",
|
|
24
|
+
VersionError: "An attempt was made to open a database using a lower version than the existing version."
|
|
25
|
+
};
|
|
26
|
+
AbortError = class AbortError extends DOMException {
|
|
27
|
+
constructor(message = messages.AbortError) {
|
|
28
|
+
super(message, "AbortError");
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
ConstraintError = class ConstraintError extends DOMException {
|
|
32
|
+
constructor(message = messages.ConstraintError) {
|
|
33
|
+
super(message, "ConstraintError");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
DataError = class DataError extends DOMException {
|
|
37
|
+
constructor(message = messages.DataError) {
|
|
38
|
+
super(message, "DataError");
|
|
39
|
+
setErrorCode(this, 0);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
InvalidAccessError = class InvalidAccessError extends DOMException {
|
|
43
|
+
constructor(message = messages.InvalidAccessError) {
|
|
44
|
+
super(message, "InvalidAccessError");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
InvalidStateError = class InvalidStateError extends DOMException {
|
|
48
|
+
constructor(message = messages.InvalidStateError) {
|
|
49
|
+
super(message, "InvalidStateError");
|
|
50
|
+
setErrorCode(this, 11);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
NotFoundError = class NotFoundError extends DOMException {
|
|
54
|
+
constructor(message = messages.NotFoundError) {
|
|
55
|
+
super(message, "NotFoundError");
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
ReadOnlyError = class ReadOnlyError extends DOMException {
|
|
59
|
+
constructor(message = messages.ReadOnlyError) {
|
|
60
|
+
super(message, "ReadOnlyError");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
SyntaxError = class SyntaxError extends DOMException {
|
|
64
|
+
constructor(message = messages.VersionError) {
|
|
65
|
+
super(message, "SyntaxError");
|
|
66
|
+
setErrorCode(this, 12);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
TransactionInactiveError = class TransactionInactiveError extends DOMException {
|
|
70
|
+
constructor(message = messages.TransactionInactiveError) {
|
|
71
|
+
super(message, "TransactionInactiveError");
|
|
72
|
+
setErrorCode(this, 0);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
VersionError = class VersionError extends DOMException {
|
|
76
|
+
constructor(message = messages.VersionError) {
|
|
77
|
+
super(message, "VersionError");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/isSharedArrayBuffer.js
|
|
83
|
+
function isSharedArrayBuffer(input) {
|
|
84
|
+
return typeof SharedArrayBuffer !== "undefined" && input instanceof SharedArrayBuffer;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/valueToKeyWithoutThrowing.js
|
|
88
|
+
var INVALID_TYPE, INVALID_VALUE, valueToKeyWithoutThrowing = (input, seen) => {
|
|
89
|
+
if (typeof input === "number") {
|
|
90
|
+
if (isNaN(input)) {
|
|
91
|
+
return INVALID_VALUE;
|
|
92
|
+
}
|
|
93
|
+
return input;
|
|
94
|
+
} else if (Object.prototype.toString.call(input) === "[object Date]") {
|
|
95
|
+
const ms = input.valueOf();
|
|
96
|
+
if (isNaN(ms)) {
|
|
97
|
+
return INVALID_VALUE;
|
|
98
|
+
}
|
|
99
|
+
return new Date(ms);
|
|
100
|
+
} else if (typeof input === "string") {
|
|
101
|
+
return input;
|
|
102
|
+
} else if (input instanceof ArrayBuffer || isSharedArrayBuffer(input) || typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView && ArrayBuffer.isView(input)) {
|
|
103
|
+
if ("detached" in input ? input.detached : input.byteLength === 0) {
|
|
104
|
+
return INVALID_VALUE;
|
|
105
|
+
}
|
|
106
|
+
let arrayBuffer;
|
|
107
|
+
let offset = 0;
|
|
108
|
+
let length = 0;
|
|
109
|
+
if (input instanceof ArrayBuffer || isSharedArrayBuffer(input)) {
|
|
110
|
+
arrayBuffer = input;
|
|
111
|
+
length = input.byteLength;
|
|
112
|
+
} else {
|
|
113
|
+
arrayBuffer = input.buffer;
|
|
114
|
+
offset = input.byteOffset;
|
|
115
|
+
length = input.byteLength;
|
|
116
|
+
}
|
|
117
|
+
return arrayBuffer.slice(offset, offset + length);
|
|
118
|
+
} else if (Array.isArray(input)) {
|
|
119
|
+
if (seen === undefined) {
|
|
120
|
+
seen = new Set;
|
|
121
|
+
} else if (seen.has(input)) {
|
|
122
|
+
return INVALID_VALUE;
|
|
123
|
+
}
|
|
124
|
+
seen.add(input);
|
|
125
|
+
let hasInvalid = false;
|
|
126
|
+
const keys = Array.from({
|
|
127
|
+
length: input.length
|
|
128
|
+
}, (_, i) => {
|
|
129
|
+
if (hasInvalid) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const hop = Object.hasOwn(input, i);
|
|
133
|
+
if (!hop) {
|
|
134
|
+
hasInvalid = true;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const entry = input[i];
|
|
138
|
+
const key = valueToKeyWithoutThrowing(entry, seen);
|
|
139
|
+
if (key === INVALID_VALUE || key === INVALID_TYPE) {
|
|
140
|
+
hasInvalid = true;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
return key;
|
|
144
|
+
});
|
|
145
|
+
if (hasInvalid) {
|
|
146
|
+
return INVALID_VALUE;
|
|
147
|
+
}
|
|
148
|
+
return keys;
|
|
149
|
+
} else {
|
|
150
|
+
return INVALID_TYPE;
|
|
151
|
+
}
|
|
152
|
+
}, valueToKeyWithoutThrowing_default;
|
|
153
|
+
var init_valueToKeyWithoutThrowing = __esm(() => {
|
|
154
|
+
INVALID_TYPE = Symbol("INVALID_TYPE");
|
|
155
|
+
INVALID_VALUE = Symbol("INVALID_VALUE");
|
|
156
|
+
valueToKeyWithoutThrowing_default = valueToKeyWithoutThrowing;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/valueToKey.js
|
|
160
|
+
var valueToKey = (input, seen) => {
|
|
161
|
+
const result = valueToKeyWithoutThrowing_default(input, seen);
|
|
162
|
+
if (result === INVALID_VALUE || result === INVALID_TYPE) {
|
|
163
|
+
throw new DataError;
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}, valueToKey_default;
|
|
167
|
+
var init_valueToKey = __esm(() => {
|
|
168
|
+
init_errors();
|
|
169
|
+
init_valueToKeyWithoutThrowing();
|
|
170
|
+
valueToKey_default = valueToKey;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/cmp.js
|
|
174
|
+
var getType = (x) => {
|
|
175
|
+
if (typeof x === "number") {
|
|
176
|
+
return "Number";
|
|
177
|
+
}
|
|
178
|
+
if (Object.prototype.toString.call(x) === "[object Date]") {
|
|
179
|
+
return "Date";
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(x)) {
|
|
182
|
+
return "Array";
|
|
183
|
+
}
|
|
184
|
+
if (typeof x === "string") {
|
|
185
|
+
return "String";
|
|
186
|
+
}
|
|
187
|
+
if (x instanceof ArrayBuffer) {
|
|
188
|
+
return "Binary";
|
|
189
|
+
}
|
|
190
|
+
throw new DataError;
|
|
191
|
+
}, cmp = (first, second) => {
|
|
192
|
+
if (second === undefined) {
|
|
193
|
+
throw new TypeError;
|
|
194
|
+
}
|
|
195
|
+
first = valueToKey_default(first);
|
|
196
|
+
second = valueToKey_default(second);
|
|
197
|
+
const t1 = getType(first);
|
|
198
|
+
const t2 = getType(second);
|
|
199
|
+
if (t1 !== t2) {
|
|
200
|
+
if (t1 === "Array") {
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
if (t1 === "Binary" && (t2 === "String" || t2 === "Date" || t2 === "Number")) {
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
206
|
+
if (t1 === "String" && (t2 === "Date" || t2 === "Number")) {
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
if (t1 === "Date" && t2 === "Number") {
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
return -1;
|
|
213
|
+
}
|
|
214
|
+
if (t1 === "Binary") {
|
|
215
|
+
first = new Uint8Array(first);
|
|
216
|
+
second = new Uint8Array(second);
|
|
217
|
+
}
|
|
218
|
+
if (t1 === "Array" || t1 === "Binary") {
|
|
219
|
+
const length = Math.min(first.length, second.length);
|
|
220
|
+
for (let i = 0;i < length; i++) {
|
|
221
|
+
const result = cmp(first[i], second[i]);
|
|
222
|
+
if (result !== 0) {
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (first.length > second.length) {
|
|
227
|
+
return 1;
|
|
228
|
+
}
|
|
229
|
+
if (first.length < second.length) {
|
|
230
|
+
return -1;
|
|
231
|
+
}
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
if (t1 === "Date") {
|
|
235
|
+
if (first.getTime() === second.getTime()) {
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
if (first === second) {
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return first > second ? 1 : -1;
|
|
244
|
+
}, cmp_default;
|
|
245
|
+
var init_cmp = __esm(() => {
|
|
246
|
+
init_errors();
|
|
247
|
+
init_valueToKey();
|
|
248
|
+
cmp_default = cmp;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBKeyRange.js
|
|
252
|
+
var FDBKeyRange, FDBKeyRange_default;
|
|
253
|
+
var init_FDBKeyRange = __esm(() => {
|
|
254
|
+
init_cmp();
|
|
255
|
+
init_errors();
|
|
256
|
+
init_valueToKey();
|
|
257
|
+
FDBKeyRange = class FDBKeyRange {
|
|
258
|
+
static only(value) {
|
|
259
|
+
if (arguments.length === 0) {
|
|
260
|
+
throw new TypeError;
|
|
261
|
+
}
|
|
262
|
+
value = valueToKey_default(value);
|
|
263
|
+
return new FDBKeyRange(value, value, false, false);
|
|
264
|
+
}
|
|
265
|
+
static lowerBound(lower, open = false) {
|
|
266
|
+
if (arguments.length === 0) {
|
|
267
|
+
throw new TypeError;
|
|
268
|
+
}
|
|
269
|
+
lower = valueToKey_default(lower);
|
|
270
|
+
return new FDBKeyRange(lower, undefined, open, true);
|
|
271
|
+
}
|
|
272
|
+
static upperBound(upper, open = false) {
|
|
273
|
+
if (arguments.length === 0) {
|
|
274
|
+
throw new TypeError;
|
|
275
|
+
}
|
|
276
|
+
upper = valueToKey_default(upper);
|
|
277
|
+
return new FDBKeyRange(undefined, upper, true, open);
|
|
278
|
+
}
|
|
279
|
+
static bound(lower, upper, lowerOpen = false, upperOpen = false) {
|
|
280
|
+
if (arguments.length < 2) {
|
|
281
|
+
throw new TypeError;
|
|
282
|
+
}
|
|
283
|
+
const cmpResult = cmp_default(lower, upper);
|
|
284
|
+
if (cmpResult === 1 || cmpResult === 0 && (lowerOpen || upperOpen)) {
|
|
285
|
+
throw new DataError;
|
|
286
|
+
}
|
|
287
|
+
lower = valueToKey_default(lower);
|
|
288
|
+
upper = valueToKey_default(upper);
|
|
289
|
+
return new FDBKeyRange(lower, upper, lowerOpen, upperOpen);
|
|
290
|
+
}
|
|
291
|
+
constructor(lower, upper, lowerOpen, upperOpen) {
|
|
292
|
+
this.lower = lower;
|
|
293
|
+
this.upper = upper;
|
|
294
|
+
this.lowerOpen = lowerOpen;
|
|
295
|
+
this.upperOpen = upperOpen;
|
|
296
|
+
}
|
|
297
|
+
includes(key) {
|
|
298
|
+
if (arguments.length === 0) {
|
|
299
|
+
throw new TypeError;
|
|
300
|
+
}
|
|
301
|
+
key = valueToKey_default(key);
|
|
302
|
+
if (this.lower !== undefined) {
|
|
303
|
+
const cmpResult = cmp_default(this.lower, key);
|
|
304
|
+
if (cmpResult === 1 || cmpResult === 0 && this.lowerOpen) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (this.upper !== undefined) {
|
|
309
|
+
const cmpResult = cmp_default(this.upper, key);
|
|
310
|
+
if (cmpResult === -1 || cmpResult === 0 && this.upperOpen) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
get [Symbol.toStringTag]() {
|
|
317
|
+
return "IDBKeyRange";
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
FDBKeyRange_default = FDBKeyRange;
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/extractKey.js
|
|
324
|
+
var extractKey = (keyPath, value) => {
|
|
325
|
+
if (Array.isArray(keyPath)) {
|
|
326
|
+
const result = [];
|
|
327
|
+
for (let item of keyPath) {
|
|
328
|
+
if (item !== undefined && item !== null && typeof item !== "string" && item.toString) {
|
|
329
|
+
item = item.toString();
|
|
330
|
+
}
|
|
331
|
+
const key = extractKey(item, value).key;
|
|
332
|
+
result.push(valueToKey_default(key));
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
type: "found",
|
|
336
|
+
key: result
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (keyPath === "") {
|
|
340
|
+
return {
|
|
341
|
+
type: "found",
|
|
342
|
+
key: value
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
let remainingKeyPath = keyPath;
|
|
346
|
+
let object = value;
|
|
347
|
+
while (remainingKeyPath !== null) {
|
|
348
|
+
let identifier;
|
|
349
|
+
const i = remainingKeyPath.indexOf(".");
|
|
350
|
+
if (i >= 0) {
|
|
351
|
+
identifier = remainingKeyPath.slice(0, i);
|
|
352
|
+
remainingKeyPath = remainingKeyPath.slice(i + 1);
|
|
353
|
+
} else {
|
|
354
|
+
identifier = remainingKeyPath;
|
|
355
|
+
remainingKeyPath = null;
|
|
356
|
+
}
|
|
357
|
+
const isSpecialIdentifier = identifier === "length" && (typeof object === "string" || Array.isArray(object)) || (identifier === "size" || identifier === "type") && typeof Blob !== "undefined" && object instanceof Blob || (identifier === "name" || identifier === "lastModified") && typeof File !== "undefined" && object instanceof File;
|
|
358
|
+
if (!isSpecialIdentifier && (typeof object !== "object" || object === null || !Object.hasOwn(object, identifier))) {
|
|
359
|
+
return {
|
|
360
|
+
type: "notFound"
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
object = object[identifier];
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
type: "found",
|
|
367
|
+
key: object
|
|
368
|
+
};
|
|
369
|
+
}, extractKey_default;
|
|
370
|
+
var init_extractKey = __esm(() => {
|
|
371
|
+
init_valueToKey();
|
|
372
|
+
extractKey_default = extractKey;
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/cloneValueForInsertion.js
|
|
376
|
+
function cloneValueForInsertion(value, transaction) {
|
|
377
|
+
if (transaction._state !== "active") {
|
|
378
|
+
throw new Error("Assert: transaction state is active");
|
|
379
|
+
}
|
|
380
|
+
transaction._state = "inactive";
|
|
381
|
+
try {
|
|
382
|
+
return structuredClone(value);
|
|
383
|
+
} finally {
|
|
384
|
+
transaction._state = "active";
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBCursor.js
|
|
389
|
+
var getEffectiveObjectStore = (cursor) => {
|
|
390
|
+
if (cursor.source instanceof FDBObjectStore_default) {
|
|
391
|
+
return cursor.source;
|
|
392
|
+
}
|
|
393
|
+
return cursor.source.objectStore;
|
|
394
|
+
}, makeKeyRange = (range, lowers, uppers) => {
|
|
395
|
+
let lower = range !== undefined ? range.lower : undefined;
|
|
396
|
+
let upper = range !== undefined ? range.upper : undefined;
|
|
397
|
+
for (const lowerTemp of lowers) {
|
|
398
|
+
if (lowerTemp === undefined) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (lower === undefined || cmp_default(lower, lowerTemp) === 1) {
|
|
402
|
+
lower = lowerTemp;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
for (const upperTemp of uppers) {
|
|
406
|
+
if (upperTemp === undefined) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (upper === undefined || cmp_default(upper, upperTemp) === -1) {
|
|
410
|
+
upper = upperTemp;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (lower !== undefined && upper !== undefined) {
|
|
414
|
+
return FDBKeyRange_default.bound(lower, upper);
|
|
415
|
+
}
|
|
416
|
+
if (lower !== undefined) {
|
|
417
|
+
return FDBKeyRange_default.lowerBound(lower);
|
|
418
|
+
}
|
|
419
|
+
if (upper !== undefined) {
|
|
420
|
+
return FDBKeyRange_default.upperBound(upper);
|
|
421
|
+
}
|
|
422
|
+
}, FDBCursor, FDBCursor_default;
|
|
423
|
+
var init_FDBCursor = __esm(() => {
|
|
424
|
+
init_FDBKeyRange();
|
|
425
|
+
init_FDBObjectStore();
|
|
426
|
+
init_cmp();
|
|
427
|
+
init_errors();
|
|
428
|
+
init_extractKey();
|
|
429
|
+
init_valueToKey();
|
|
430
|
+
FDBCursor = class FDBCursor {
|
|
431
|
+
_gotValue = false;
|
|
432
|
+
_position = undefined;
|
|
433
|
+
_objectStorePosition = undefined;
|
|
434
|
+
_keyOnly = false;
|
|
435
|
+
_key = undefined;
|
|
436
|
+
_primaryKey = undefined;
|
|
437
|
+
constructor(source, range, direction = "next", request, keyOnly = false) {
|
|
438
|
+
this._range = range;
|
|
439
|
+
this._source = source;
|
|
440
|
+
this._direction = direction;
|
|
441
|
+
this._request = request;
|
|
442
|
+
this._keyOnly = keyOnly;
|
|
443
|
+
}
|
|
444
|
+
get source() {
|
|
445
|
+
return this._source;
|
|
446
|
+
}
|
|
447
|
+
set source(val) {}
|
|
448
|
+
get request() {
|
|
449
|
+
return this._request;
|
|
450
|
+
}
|
|
451
|
+
set request(val) {}
|
|
452
|
+
get direction() {
|
|
453
|
+
return this._direction;
|
|
454
|
+
}
|
|
455
|
+
set direction(val) {}
|
|
456
|
+
get key() {
|
|
457
|
+
return this._key;
|
|
458
|
+
}
|
|
459
|
+
set key(val) {}
|
|
460
|
+
get primaryKey() {
|
|
461
|
+
return this._primaryKey;
|
|
462
|
+
}
|
|
463
|
+
set primaryKey(val) {}
|
|
464
|
+
_iterate(key, primaryKey) {
|
|
465
|
+
const sourceIsObjectStore = this.source instanceof FDBObjectStore_default;
|
|
466
|
+
const records = this.source instanceof FDBObjectStore_default ? this.source._rawObjectStore.records : this.source._rawIndex.records;
|
|
467
|
+
let foundRecord;
|
|
468
|
+
if (this.direction === "next") {
|
|
469
|
+
const range = makeKeyRange(this._range, [key, this._position], []);
|
|
470
|
+
for (const record of records.values(range)) {
|
|
471
|
+
const cmpResultKey = key !== undefined ? cmp_default(record.key, key) : undefined;
|
|
472
|
+
const cmpResultPosition = this._position !== undefined ? cmp_default(record.key, this._position) : undefined;
|
|
473
|
+
if (key !== undefined) {
|
|
474
|
+
if (cmpResultKey === -1) {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (primaryKey !== undefined) {
|
|
479
|
+
if (cmpResultKey === -1) {
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const cmpResultPrimaryKey = cmp_default(record.value, primaryKey);
|
|
483
|
+
if (cmpResultKey === 0 && cmpResultPrimaryKey === -1) {
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (this._position !== undefined && sourceIsObjectStore) {
|
|
488
|
+
if (cmpResultPosition !== 1) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (this._position !== undefined && !sourceIsObjectStore) {
|
|
493
|
+
if (cmpResultPosition === -1) {
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (cmpResultPosition === 0 && cmp_default(record.value, this._objectStorePosition) !== 1) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (this._range !== undefined) {
|
|
501
|
+
if (!this._range.includes(record.key)) {
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
foundRecord = record;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
} else if (this.direction === "nextunique") {
|
|
509
|
+
const range = makeKeyRange(this._range, [key, this._position], []);
|
|
510
|
+
for (const record of records.values(range)) {
|
|
511
|
+
if (key !== undefined) {
|
|
512
|
+
if (cmp_default(record.key, key) === -1) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (this._position !== undefined) {
|
|
517
|
+
if (cmp_default(record.key, this._position) !== 1) {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (this._range !== undefined) {
|
|
522
|
+
if (!this._range.includes(record.key)) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
foundRecord = record;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
} else if (this.direction === "prev") {
|
|
530
|
+
const range = makeKeyRange(this._range, [], [key, this._position]);
|
|
531
|
+
for (const record of records.values(range, "prev")) {
|
|
532
|
+
const cmpResultKey = key !== undefined ? cmp_default(record.key, key) : undefined;
|
|
533
|
+
const cmpResultPosition = this._position !== undefined ? cmp_default(record.key, this._position) : undefined;
|
|
534
|
+
if (key !== undefined) {
|
|
535
|
+
if (cmpResultKey === 1) {
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (primaryKey !== undefined) {
|
|
540
|
+
if (cmpResultKey === 1) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const cmpResultPrimaryKey = cmp_default(record.value, primaryKey);
|
|
544
|
+
if (cmpResultKey === 0 && cmpResultPrimaryKey === 1) {
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (this._position !== undefined && sourceIsObjectStore) {
|
|
549
|
+
if (cmpResultPosition !== -1) {
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (this._position !== undefined && !sourceIsObjectStore) {
|
|
554
|
+
if (cmpResultPosition === 1) {
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (cmpResultPosition === 0 && cmp_default(record.value, this._objectStorePosition) !== -1) {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (this._range !== undefined) {
|
|
562
|
+
if (!this._range.includes(record.key)) {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
foundRecord = record;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
} else if (this.direction === "prevunique") {
|
|
570
|
+
let tempRecord;
|
|
571
|
+
const range = makeKeyRange(this._range, [], [key, this._position]);
|
|
572
|
+
for (const record of records.values(range, "prev")) {
|
|
573
|
+
if (key !== undefined) {
|
|
574
|
+
if (cmp_default(record.key, key) === 1) {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (this._position !== undefined) {
|
|
579
|
+
if (cmp_default(record.key, this._position) !== -1) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (this._range !== undefined) {
|
|
584
|
+
if (!this._range.includes(record.key)) {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
tempRecord = record;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
if (tempRecord) {
|
|
592
|
+
foundRecord = records.get(tempRecord.key);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
let result;
|
|
596
|
+
if (!foundRecord) {
|
|
597
|
+
this._key = undefined;
|
|
598
|
+
if (!sourceIsObjectStore) {
|
|
599
|
+
this._objectStorePosition = undefined;
|
|
600
|
+
}
|
|
601
|
+
if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
|
|
602
|
+
this.value = undefined;
|
|
603
|
+
}
|
|
604
|
+
result = null;
|
|
605
|
+
} else {
|
|
606
|
+
this._position = foundRecord.key;
|
|
607
|
+
if (!sourceIsObjectStore) {
|
|
608
|
+
this._objectStorePosition = foundRecord.value;
|
|
609
|
+
}
|
|
610
|
+
this._key = foundRecord.key;
|
|
611
|
+
if (sourceIsObjectStore) {
|
|
612
|
+
this._primaryKey = structuredClone(foundRecord.key);
|
|
613
|
+
if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
|
|
614
|
+
this.value = structuredClone(foundRecord.value);
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
this._primaryKey = structuredClone(foundRecord.value);
|
|
618
|
+
if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
|
|
619
|
+
if (this.source instanceof FDBObjectStore_default) {
|
|
620
|
+
throw new Error("This should never happen");
|
|
621
|
+
}
|
|
622
|
+
const value = this.source.objectStore._rawObjectStore.getValue(foundRecord.value);
|
|
623
|
+
this.value = structuredClone(value);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
this._gotValue = true;
|
|
627
|
+
result = this;
|
|
628
|
+
}
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
update(value) {
|
|
632
|
+
if (value === undefined) {
|
|
633
|
+
throw new TypeError;
|
|
634
|
+
}
|
|
635
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
636
|
+
const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position;
|
|
637
|
+
const transaction = effectiveObjectStore.transaction;
|
|
638
|
+
if (transaction._state !== "active") {
|
|
639
|
+
throw new TransactionInactiveError;
|
|
640
|
+
}
|
|
641
|
+
if (transaction.mode === "readonly") {
|
|
642
|
+
throw new ReadOnlyError;
|
|
643
|
+
}
|
|
644
|
+
if (effectiveObjectStore._rawObjectStore.deleted) {
|
|
645
|
+
throw new InvalidStateError;
|
|
646
|
+
}
|
|
647
|
+
if (!(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted) {
|
|
648
|
+
throw new InvalidStateError;
|
|
649
|
+
}
|
|
650
|
+
if (!this._gotValue || !Object.hasOwn(this, "value")) {
|
|
651
|
+
throw new InvalidStateError;
|
|
652
|
+
}
|
|
653
|
+
const clone = cloneValueForInsertion(value, transaction);
|
|
654
|
+
if (effectiveObjectStore.keyPath !== null) {
|
|
655
|
+
let tempKey;
|
|
656
|
+
try {
|
|
657
|
+
tempKey = extractKey_default(effectiveObjectStore.keyPath, clone).key;
|
|
658
|
+
} catch (err) {}
|
|
659
|
+
if (cmp_default(tempKey, effectiveKey) !== 0) {
|
|
660
|
+
throw new DataError;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
const record = {
|
|
664
|
+
key: effectiveKey,
|
|
665
|
+
value: clone
|
|
666
|
+
};
|
|
667
|
+
return transaction._execRequestAsync({
|
|
668
|
+
operation: effectiveObjectStore._rawObjectStore.storeRecord.bind(effectiveObjectStore._rawObjectStore, record, false, transaction._rollbackLog),
|
|
669
|
+
source: this
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
advance(count) {
|
|
673
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
674
|
+
throw new TypeError;
|
|
675
|
+
}
|
|
676
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
677
|
+
const transaction = effectiveObjectStore.transaction;
|
|
678
|
+
if (transaction._state !== "active") {
|
|
679
|
+
throw new TransactionInactiveError;
|
|
680
|
+
}
|
|
681
|
+
if (effectiveObjectStore._rawObjectStore.deleted) {
|
|
682
|
+
throw new InvalidStateError;
|
|
683
|
+
}
|
|
684
|
+
if (!(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted) {
|
|
685
|
+
throw new InvalidStateError;
|
|
686
|
+
}
|
|
687
|
+
if (!this._gotValue) {
|
|
688
|
+
throw new InvalidStateError;
|
|
689
|
+
}
|
|
690
|
+
if (this._request) {
|
|
691
|
+
this._request.readyState = "pending";
|
|
692
|
+
}
|
|
693
|
+
transaction._execRequestAsync({
|
|
694
|
+
operation: () => {
|
|
695
|
+
let result;
|
|
696
|
+
for (let i = 0;i < count; i++) {
|
|
697
|
+
result = this._iterate();
|
|
698
|
+
if (!result) {
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return result;
|
|
703
|
+
},
|
|
704
|
+
request: this._request,
|
|
705
|
+
source: this.source
|
|
706
|
+
});
|
|
707
|
+
this._gotValue = false;
|
|
708
|
+
}
|
|
709
|
+
continue(key) {
|
|
710
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
711
|
+
const transaction = effectiveObjectStore.transaction;
|
|
712
|
+
if (transaction._state !== "active") {
|
|
713
|
+
throw new TransactionInactiveError;
|
|
714
|
+
}
|
|
715
|
+
if (effectiveObjectStore._rawObjectStore.deleted) {
|
|
716
|
+
throw new InvalidStateError;
|
|
717
|
+
}
|
|
718
|
+
if (!(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted) {
|
|
719
|
+
throw new InvalidStateError;
|
|
720
|
+
}
|
|
721
|
+
if (!this._gotValue) {
|
|
722
|
+
throw new InvalidStateError;
|
|
723
|
+
}
|
|
724
|
+
if (key !== undefined) {
|
|
725
|
+
key = valueToKey_default(key);
|
|
726
|
+
const cmpResult = cmp_default(key, this._position);
|
|
727
|
+
if (cmpResult <= 0 && (this.direction === "next" || this.direction === "nextunique") || cmpResult >= 0 && (this.direction === "prev" || this.direction === "prevunique")) {
|
|
728
|
+
throw new DataError;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (this._request) {
|
|
732
|
+
this._request.readyState = "pending";
|
|
733
|
+
}
|
|
734
|
+
transaction._execRequestAsync({
|
|
735
|
+
operation: this._iterate.bind(this, key),
|
|
736
|
+
request: this._request,
|
|
737
|
+
source: this.source
|
|
738
|
+
});
|
|
739
|
+
this._gotValue = false;
|
|
740
|
+
}
|
|
741
|
+
continuePrimaryKey(key, primaryKey) {
|
|
742
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
743
|
+
const transaction = effectiveObjectStore.transaction;
|
|
744
|
+
if (transaction._state !== "active") {
|
|
745
|
+
throw new TransactionInactiveError;
|
|
746
|
+
}
|
|
747
|
+
if (effectiveObjectStore._rawObjectStore.deleted) {
|
|
748
|
+
throw new InvalidStateError;
|
|
749
|
+
}
|
|
750
|
+
if (!(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted) {
|
|
751
|
+
throw new InvalidStateError;
|
|
752
|
+
}
|
|
753
|
+
if (this.source instanceof FDBObjectStore_default || this.direction !== "next" && this.direction !== "prev") {
|
|
754
|
+
throw new InvalidAccessError;
|
|
755
|
+
}
|
|
756
|
+
if (!this._gotValue) {
|
|
757
|
+
throw new InvalidStateError;
|
|
758
|
+
}
|
|
759
|
+
if (key === undefined || primaryKey === undefined) {
|
|
760
|
+
throw new DataError;
|
|
761
|
+
}
|
|
762
|
+
key = valueToKey_default(key);
|
|
763
|
+
const cmpResult = cmp_default(key, this._position);
|
|
764
|
+
if (cmpResult === -1 && this.direction === "next" || cmpResult === 1 && this.direction === "prev") {
|
|
765
|
+
throw new DataError;
|
|
766
|
+
}
|
|
767
|
+
const cmpResult2 = cmp_default(primaryKey, this._objectStorePosition);
|
|
768
|
+
if (cmpResult === 0) {
|
|
769
|
+
if (cmpResult2 <= 0 && this.direction === "next" || cmpResult2 >= 0 && this.direction === "prev") {
|
|
770
|
+
throw new DataError;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (this._request) {
|
|
774
|
+
this._request.readyState = "pending";
|
|
775
|
+
}
|
|
776
|
+
transaction._execRequestAsync({
|
|
777
|
+
operation: this._iterate.bind(this, key, primaryKey),
|
|
778
|
+
request: this._request,
|
|
779
|
+
source: this.source
|
|
780
|
+
});
|
|
781
|
+
this._gotValue = false;
|
|
782
|
+
}
|
|
783
|
+
delete() {
|
|
784
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
785
|
+
const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position;
|
|
786
|
+
const transaction = effectiveObjectStore.transaction;
|
|
787
|
+
if (transaction._state !== "active") {
|
|
788
|
+
throw new TransactionInactiveError;
|
|
789
|
+
}
|
|
790
|
+
if (transaction.mode === "readonly") {
|
|
791
|
+
throw new ReadOnlyError;
|
|
792
|
+
}
|
|
793
|
+
if (effectiveObjectStore._rawObjectStore.deleted) {
|
|
794
|
+
throw new InvalidStateError;
|
|
795
|
+
}
|
|
796
|
+
if (!(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted) {
|
|
797
|
+
throw new InvalidStateError;
|
|
798
|
+
}
|
|
799
|
+
if (!this._gotValue || !Object.hasOwn(this, "value")) {
|
|
800
|
+
throw new InvalidStateError;
|
|
801
|
+
}
|
|
802
|
+
return transaction._execRequestAsync({
|
|
803
|
+
operation: effectiveObjectStore._rawObjectStore.deleteRecord.bind(effectiveObjectStore._rawObjectStore, effectiveKey, transaction._rollbackLog),
|
|
804
|
+
source: this
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
get [Symbol.toStringTag]() {
|
|
808
|
+
return "IDBCursor";
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
FDBCursor_default = FDBCursor;
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBCursorWithValue.js
|
|
815
|
+
var FDBCursorWithValue, FDBCursorWithValue_default;
|
|
816
|
+
var init_FDBCursorWithValue = __esm(() => {
|
|
817
|
+
init_FDBCursor();
|
|
818
|
+
FDBCursorWithValue = class FDBCursorWithValue extends FDBCursor_default {
|
|
819
|
+
value = undefined;
|
|
820
|
+
constructor(source, range, direction, request) {
|
|
821
|
+
super(source, range, direction, request);
|
|
822
|
+
}
|
|
823
|
+
get [Symbol.toStringTag]() {
|
|
824
|
+
return "IDBCursorWithValue";
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
FDBCursorWithValue_default = FDBCursorWithValue;
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/FakeEventTarget.js
|
|
831
|
+
class FakeEventTarget {
|
|
832
|
+
listeners = [];
|
|
833
|
+
addEventListener(type, callback, options) {
|
|
834
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
835
|
+
this.listeners.push({
|
|
836
|
+
callback,
|
|
837
|
+
capture,
|
|
838
|
+
type
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
removeEventListener(type, callback, options) {
|
|
842
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
843
|
+
const i = this.listeners.findIndex((listener) => {
|
|
844
|
+
return listener.type === type && listener.callback === callback && listener.capture === capture;
|
|
845
|
+
});
|
|
846
|
+
this.listeners.splice(i, 1);
|
|
847
|
+
}
|
|
848
|
+
dispatchEvent(event) {
|
|
849
|
+
if (event.dispatched || !event.initialized) {
|
|
850
|
+
throw new InvalidStateError("The object is in an invalid state.");
|
|
851
|
+
}
|
|
852
|
+
event.isTrusted = false;
|
|
853
|
+
event.dispatched = true;
|
|
854
|
+
event.target = this;
|
|
855
|
+
event.eventPhase = event.CAPTURING_PHASE;
|
|
856
|
+
for (const obj of event.eventPath) {
|
|
857
|
+
if (!event.propagationStopped) {
|
|
858
|
+
invokeEventListeners(event, obj);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
event.eventPhase = event.AT_TARGET;
|
|
862
|
+
if (!event.propagationStopped) {
|
|
863
|
+
invokeEventListeners(event, event.target);
|
|
864
|
+
}
|
|
865
|
+
if (event.bubbles) {
|
|
866
|
+
event.eventPath.reverse();
|
|
867
|
+
event.eventPhase = event.BUBBLING_PHASE;
|
|
868
|
+
for (const obj of event.eventPath) {
|
|
869
|
+
if (!event.propagationStopped) {
|
|
870
|
+
invokeEventListeners(event, obj);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
event.dispatched = false;
|
|
875
|
+
event.eventPhase = event.NONE;
|
|
876
|
+
event.currentTarget = null;
|
|
877
|
+
if (event.canceled) {
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
var stopped = (event, listener) => {
|
|
884
|
+
return event.immediatePropagationStopped || event.eventPhase === event.CAPTURING_PHASE && listener.capture === false || event.eventPhase === event.BUBBLING_PHASE && listener.capture === true;
|
|
885
|
+
}, invokeEventListeners = (event, obj) => {
|
|
886
|
+
event.currentTarget = obj;
|
|
887
|
+
const errors = [];
|
|
888
|
+
const invoke = (callbackOrObject) => {
|
|
889
|
+
try {
|
|
890
|
+
const callback2 = typeof callbackOrObject === "function" ? callbackOrObject : callbackOrObject.handleEvent;
|
|
891
|
+
callback2.call(event.currentTarget, event);
|
|
892
|
+
} catch (err) {
|
|
893
|
+
errors.push(err);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
for (const listener of obj.listeners.slice()) {
|
|
897
|
+
if (event.type !== listener.type || stopped(event, listener)) {
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
invoke(listener.callback);
|
|
901
|
+
}
|
|
902
|
+
const typeToProp = {
|
|
903
|
+
abort: "onabort",
|
|
904
|
+
blocked: "onblocked",
|
|
905
|
+
close: "onclose",
|
|
906
|
+
complete: "oncomplete",
|
|
907
|
+
error: "onerror",
|
|
908
|
+
success: "onsuccess",
|
|
909
|
+
upgradeneeded: "onupgradeneeded",
|
|
910
|
+
versionchange: "onversionchange"
|
|
911
|
+
};
|
|
912
|
+
const prop = typeToProp[event.type];
|
|
913
|
+
if (prop === undefined) {
|
|
914
|
+
throw new Error(`Unknown event type: "${event.type}"`);
|
|
915
|
+
}
|
|
916
|
+
const callback = event.currentTarget[prop];
|
|
917
|
+
if (callback) {
|
|
918
|
+
const listener = {
|
|
919
|
+
callback,
|
|
920
|
+
capture: false,
|
|
921
|
+
type: event.type
|
|
922
|
+
};
|
|
923
|
+
if (!stopped(event, listener)) {
|
|
924
|
+
invoke(listener.callback);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (errors.length) {
|
|
928
|
+
throw new AggregateError(errors);
|
|
929
|
+
}
|
|
930
|
+
}, FakeEventTarget_default;
|
|
931
|
+
var init_FakeEventTarget = __esm(() => {
|
|
932
|
+
init_errors();
|
|
933
|
+
FakeEventTarget_default = FakeEventTarget;
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBRequest.js
|
|
937
|
+
var FDBRequest, FDBRequest_default;
|
|
938
|
+
var init_FDBRequest = __esm(() => {
|
|
939
|
+
init_errors();
|
|
940
|
+
init_FakeEventTarget();
|
|
941
|
+
FDBRequest = class FDBRequest extends FakeEventTarget_default {
|
|
942
|
+
_result = null;
|
|
943
|
+
_error = null;
|
|
944
|
+
source = null;
|
|
945
|
+
transaction = null;
|
|
946
|
+
readyState = "pending";
|
|
947
|
+
onsuccess = null;
|
|
948
|
+
onerror = null;
|
|
949
|
+
get error() {
|
|
950
|
+
if (this.readyState === "pending") {
|
|
951
|
+
throw new InvalidStateError;
|
|
952
|
+
}
|
|
953
|
+
return this._error;
|
|
954
|
+
}
|
|
955
|
+
set error(value) {
|
|
956
|
+
this._error = value;
|
|
957
|
+
}
|
|
958
|
+
get result() {
|
|
959
|
+
if (this.readyState === "pending") {
|
|
960
|
+
throw new InvalidStateError;
|
|
961
|
+
}
|
|
962
|
+
return this._result;
|
|
963
|
+
}
|
|
964
|
+
set result(value) {
|
|
965
|
+
this._result = value;
|
|
966
|
+
}
|
|
967
|
+
get [Symbol.toStringTag]() {
|
|
968
|
+
return "IDBRequest";
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
FDBRequest_default = FDBRequest;
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/FakeDOMStringList.js
|
|
975
|
+
var FakeDOMStringList, FakeDOMStringList_default;
|
|
976
|
+
var init_FakeDOMStringList = __esm(() => {
|
|
977
|
+
FakeDOMStringList = class FakeDOMStringList {
|
|
978
|
+
constructor(...values) {
|
|
979
|
+
this._values = values;
|
|
980
|
+
for (let i = 0;i < values.length; i++) {
|
|
981
|
+
this[i] = values[i];
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
contains(value) {
|
|
985
|
+
return this._values.includes(value);
|
|
986
|
+
}
|
|
987
|
+
item(i) {
|
|
988
|
+
if (i < 0 || i >= this._values.length) {
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
return this._values[i];
|
|
992
|
+
}
|
|
993
|
+
get length() {
|
|
994
|
+
return this._values.length;
|
|
995
|
+
}
|
|
996
|
+
[Symbol.iterator]() {
|
|
997
|
+
return this._values[Symbol.iterator]();
|
|
998
|
+
}
|
|
999
|
+
_push(...values) {
|
|
1000
|
+
for (let i = 0;i < values.length; i++) {
|
|
1001
|
+
this[this._values.length + i] = values[i];
|
|
1002
|
+
}
|
|
1003
|
+
this._values.push(...values);
|
|
1004
|
+
}
|
|
1005
|
+
_sort(...values) {
|
|
1006
|
+
this._values.sort(...values);
|
|
1007
|
+
for (let i = 0;i < this._values.length; i++) {
|
|
1008
|
+
this[i] = this._values[i];
|
|
1009
|
+
}
|
|
1010
|
+
return this;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
FakeDOMStringList_default = FakeDOMStringList;
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/valueToKeyRange.js
|
|
1017
|
+
var valueToKeyRange = (value, nullDisallowedFlag = false) => {
|
|
1018
|
+
if (value instanceof FDBKeyRange_default) {
|
|
1019
|
+
return value;
|
|
1020
|
+
}
|
|
1021
|
+
if (value === null || value === undefined) {
|
|
1022
|
+
if (nullDisallowedFlag) {
|
|
1023
|
+
throw new DataError;
|
|
1024
|
+
}
|
|
1025
|
+
return new FDBKeyRange_default(undefined, undefined, false, false);
|
|
1026
|
+
}
|
|
1027
|
+
const key = valueToKey_default(value);
|
|
1028
|
+
return FDBKeyRange_default.only(key);
|
|
1029
|
+
}, valueToKeyRange_default;
|
|
1030
|
+
var init_valueToKeyRange = __esm(() => {
|
|
1031
|
+
init_FDBKeyRange();
|
|
1032
|
+
init_errors();
|
|
1033
|
+
init_valueToKey();
|
|
1034
|
+
valueToKeyRange_default = valueToKeyRange;
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/getKeyPath.js
|
|
1038
|
+
function getKeyPath(keyPath) {
|
|
1039
|
+
return Array.isArray(keyPath) ? keyPath.map(convertKey) : convertKey(keyPath);
|
|
1040
|
+
}
|
|
1041
|
+
var convertKey = (key) => typeof key === "object" && key ? key + "" : key;
|
|
1042
|
+
|
|
1043
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/isPotentiallyValidKeyRange.js
|
|
1044
|
+
var isPotentiallyValidKeyRange = (value) => {
|
|
1045
|
+
if (value instanceof FDBKeyRange_default) {
|
|
1046
|
+
return true;
|
|
1047
|
+
}
|
|
1048
|
+
const key = valueToKeyWithoutThrowing_default(value);
|
|
1049
|
+
return key !== INVALID_TYPE;
|
|
1050
|
+
}, isPotentiallyValidKeyRange_default;
|
|
1051
|
+
var init_isPotentiallyValidKeyRange = __esm(() => {
|
|
1052
|
+
init_FDBKeyRange();
|
|
1053
|
+
init_valueToKeyWithoutThrowing();
|
|
1054
|
+
isPotentiallyValidKeyRange_default = isPotentiallyValidKeyRange;
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/enforceRange.js
|
|
1058
|
+
var enforceRange = (num, type) => {
|
|
1059
|
+
const min = 0;
|
|
1060
|
+
const max = type === "unsigned long" ? 4294967295 : 9007199254740991;
|
|
1061
|
+
if (isNaN(num) || num < min || num > max) {
|
|
1062
|
+
throw new TypeError;
|
|
1063
|
+
}
|
|
1064
|
+
if (num >= 0) {
|
|
1065
|
+
return Math.floor(num);
|
|
1066
|
+
}
|
|
1067
|
+
}, enforceRange_default;
|
|
1068
|
+
var init_enforceRange = __esm(() => {
|
|
1069
|
+
enforceRange_default = enforceRange;
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/extractGetAllOptions.js
|
|
1073
|
+
var extractGetAllOptions = (queryOrOptions, count, numArguments) => {
|
|
1074
|
+
let query;
|
|
1075
|
+
let direction;
|
|
1076
|
+
if (queryOrOptions === undefined || queryOrOptions === null || isPotentiallyValidKeyRange_default(queryOrOptions)) {
|
|
1077
|
+
query = queryOrOptions;
|
|
1078
|
+
if (numArguments > 1 && count !== undefined) {
|
|
1079
|
+
count = enforceRange_default(count, "unsigned long");
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
const getAllOptions = queryOrOptions;
|
|
1083
|
+
if (getAllOptions.query !== undefined) {
|
|
1084
|
+
query = getAllOptions.query;
|
|
1085
|
+
}
|
|
1086
|
+
if (getAllOptions.count !== undefined) {
|
|
1087
|
+
count = enforceRange_default(getAllOptions.count, "unsigned long");
|
|
1088
|
+
}
|
|
1089
|
+
if (getAllOptions.direction !== undefined) {
|
|
1090
|
+
direction = getAllOptions.direction;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return {
|
|
1094
|
+
query,
|
|
1095
|
+
count,
|
|
1096
|
+
direction
|
|
1097
|
+
};
|
|
1098
|
+
}, extractGetAllOptions_default;
|
|
1099
|
+
var init_extractGetAllOptions = __esm(() => {
|
|
1100
|
+
init_isPotentiallyValidKeyRange();
|
|
1101
|
+
init_enforceRange();
|
|
1102
|
+
extractGetAllOptions_default = extractGetAllOptions;
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBIndex.js
|
|
1106
|
+
var confirmActiveTransaction = (index) => {
|
|
1107
|
+
if (index._rawIndex.deleted || index.objectStore._rawObjectStore.deleted) {
|
|
1108
|
+
throw new InvalidStateError;
|
|
1109
|
+
}
|
|
1110
|
+
if (index.objectStore.transaction._state !== "active") {
|
|
1111
|
+
throw new TransactionInactiveError;
|
|
1112
|
+
}
|
|
1113
|
+
}, FDBIndex, FDBIndex_default;
|
|
1114
|
+
var init_FDBIndex = __esm(() => {
|
|
1115
|
+
init_FDBCursor();
|
|
1116
|
+
init_FDBCursorWithValue();
|
|
1117
|
+
init_FDBKeyRange();
|
|
1118
|
+
init_FDBRequest();
|
|
1119
|
+
init_errors();
|
|
1120
|
+
init_FakeDOMStringList();
|
|
1121
|
+
init_valueToKey();
|
|
1122
|
+
init_valueToKeyRange();
|
|
1123
|
+
init_extractGetAllOptions();
|
|
1124
|
+
init_enforceRange();
|
|
1125
|
+
FDBIndex = class FDBIndex {
|
|
1126
|
+
constructor(objectStore, rawIndex) {
|
|
1127
|
+
this._rawIndex = rawIndex;
|
|
1128
|
+
this._name = rawIndex.name;
|
|
1129
|
+
this.objectStore = objectStore;
|
|
1130
|
+
this.keyPath = getKeyPath(rawIndex.keyPath);
|
|
1131
|
+
this.multiEntry = rawIndex.multiEntry;
|
|
1132
|
+
this.unique = rawIndex.unique;
|
|
1133
|
+
}
|
|
1134
|
+
get name() {
|
|
1135
|
+
return this._name;
|
|
1136
|
+
}
|
|
1137
|
+
set name(name) {
|
|
1138
|
+
const transaction = this.objectStore.transaction;
|
|
1139
|
+
if (!transaction.db._runningVersionchangeTransaction) {
|
|
1140
|
+
throw transaction._state === "active" ? new InvalidStateError : new TransactionInactiveError;
|
|
1141
|
+
}
|
|
1142
|
+
if (transaction._state !== "active") {
|
|
1143
|
+
throw new TransactionInactiveError;
|
|
1144
|
+
}
|
|
1145
|
+
if (this._rawIndex.deleted || this.objectStore._rawObjectStore.deleted) {
|
|
1146
|
+
throw new InvalidStateError;
|
|
1147
|
+
}
|
|
1148
|
+
name = String(name);
|
|
1149
|
+
if (name === this._name) {
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
if (this.objectStore.indexNames.contains(name)) {
|
|
1153
|
+
throw new ConstraintError;
|
|
1154
|
+
}
|
|
1155
|
+
const oldName = this._name;
|
|
1156
|
+
const oldIndexNames = [...this.objectStore.indexNames];
|
|
1157
|
+
this._name = name;
|
|
1158
|
+
this._rawIndex.name = name;
|
|
1159
|
+
this.objectStore._indexesCache.delete(oldName);
|
|
1160
|
+
this.objectStore._indexesCache.set(name, this);
|
|
1161
|
+
this.objectStore._rawObjectStore.rawIndexes.delete(oldName);
|
|
1162
|
+
this.objectStore._rawObjectStore.rawIndexes.set(name, this._rawIndex);
|
|
1163
|
+
this.objectStore.indexNames = new FakeDOMStringList_default(...Array.from(this.objectStore._rawObjectStore.rawIndexes.keys()).filter((indexName) => {
|
|
1164
|
+
const index = this.objectStore._rawObjectStore.rawIndexes.get(indexName);
|
|
1165
|
+
return index && !index.deleted;
|
|
1166
|
+
}).sort());
|
|
1167
|
+
if (!this.objectStore.transaction._createdIndexes.has(this._rawIndex)) {
|
|
1168
|
+
transaction._rollbackLog.push(() => {
|
|
1169
|
+
this._name = oldName;
|
|
1170
|
+
this._rawIndex.name = oldName;
|
|
1171
|
+
this.objectStore._indexesCache.delete(name);
|
|
1172
|
+
this.objectStore._indexesCache.set(oldName, this);
|
|
1173
|
+
this.objectStore._rawObjectStore.rawIndexes.delete(name);
|
|
1174
|
+
this.objectStore._rawObjectStore.rawIndexes.set(oldName, this._rawIndex);
|
|
1175
|
+
this.objectStore.indexNames = new FakeDOMStringList_default(...oldIndexNames);
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
openCursor(range, direction) {
|
|
1180
|
+
confirmActiveTransaction(this);
|
|
1181
|
+
if (range === null) {
|
|
1182
|
+
range = undefined;
|
|
1183
|
+
}
|
|
1184
|
+
if (range !== undefined && !(range instanceof FDBKeyRange_default)) {
|
|
1185
|
+
range = FDBKeyRange_default.only(valueToKey_default(range));
|
|
1186
|
+
}
|
|
1187
|
+
const request = new FDBRequest_default;
|
|
1188
|
+
request.source = this;
|
|
1189
|
+
request.transaction = this.objectStore.transaction;
|
|
1190
|
+
const cursor = new FDBCursorWithValue_default(this, range, direction, request);
|
|
1191
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1192
|
+
operation: cursor._iterate.bind(cursor),
|
|
1193
|
+
request,
|
|
1194
|
+
source: this
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
openKeyCursor(range, direction) {
|
|
1198
|
+
confirmActiveTransaction(this);
|
|
1199
|
+
if (range === null) {
|
|
1200
|
+
range = undefined;
|
|
1201
|
+
}
|
|
1202
|
+
if (range !== undefined && !(range instanceof FDBKeyRange_default)) {
|
|
1203
|
+
range = FDBKeyRange_default.only(valueToKey_default(range));
|
|
1204
|
+
}
|
|
1205
|
+
const request = new FDBRequest_default;
|
|
1206
|
+
request.source = this;
|
|
1207
|
+
request.transaction = this.objectStore.transaction;
|
|
1208
|
+
const cursor = new FDBCursor_default(this, range, direction, request, true);
|
|
1209
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1210
|
+
operation: cursor._iterate.bind(cursor),
|
|
1211
|
+
request,
|
|
1212
|
+
source: this
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
get(key) {
|
|
1216
|
+
confirmActiveTransaction(this);
|
|
1217
|
+
if (!(key instanceof FDBKeyRange_default)) {
|
|
1218
|
+
key = valueToKey_default(key);
|
|
1219
|
+
}
|
|
1220
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1221
|
+
operation: this._rawIndex.getValue.bind(this._rawIndex, key),
|
|
1222
|
+
source: this
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
getAll(queryOrOptions, count) {
|
|
1226
|
+
const options = extractGetAllOptions_default(queryOrOptions, count, arguments.length);
|
|
1227
|
+
confirmActiveTransaction(this);
|
|
1228
|
+
const range = valueToKeyRange_default(options.query);
|
|
1229
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1230
|
+
operation: this._rawIndex.getAllValues.bind(this._rawIndex, range, options.count, options.direction),
|
|
1231
|
+
source: this
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
getKey(key) {
|
|
1235
|
+
confirmActiveTransaction(this);
|
|
1236
|
+
if (!(key instanceof FDBKeyRange_default)) {
|
|
1237
|
+
key = valueToKey_default(key);
|
|
1238
|
+
}
|
|
1239
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1240
|
+
operation: this._rawIndex.getKey.bind(this._rawIndex, key),
|
|
1241
|
+
source: this
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
getAllKeys(queryOrOptions, count) {
|
|
1245
|
+
const options = extractGetAllOptions_default(queryOrOptions, count, arguments.length);
|
|
1246
|
+
confirmActiveTransaction(this);
|
|
1247
|
+
const range = valueToKeyRange_default(options.query);
|
|
1248
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1249
|
+
operation: this._rawIndex.getAllKeys.bind(this._rawIndex, range, options.count, options.direction),
|
|
1250
|
+
source: this
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
getAllRecords(options) {
|
|
1254
|
+
let query;
|
|
1255
|
+
let count;
|
|
1256
|
+
let direction;
|
|
1257
|
+
if (options !== undefined) {
|
|
1258
|
+
if (options.query !== undefined) {
|
|
1259
|
+
query = options.query;
|
|
1260
|
+
}
|
|
1261
|
+
if (options.count !== undefined) {
|
|
1262
|
+
count = enforceRange_default(options.count, "unsigned long");
|
|
1263
|
+
}
|
|
1264
|
+
if (options.direction !== undefined) {
|
|
1265
|
+
direction = options.direction;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
confirmActiveTransaction(this);
|
|
1269
|
+
const range = valueToKeyRange_default(query);
|
|
1270
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1271
|
+
operation: this._rawIndex.getAllRecords.bind(this._rawIndex, range, count, direction),
|
|
1272
|
+
source: this
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
count(key) {
|
|
1276
|
+
confirmActiveTransaction(this);
|
|
1277
|
+
if (key === null) {
|
|
1278
|
+
key = undefined;
|
|
1279
|
+
}
|
|
1280
|
+
if (key !== undefined && !(key instanceof FDBKeyRange_default)) {
|
|
1281
|
+
key = FDBKeyRange_default.only(valueToKey_default(key));
|
|
1282
|
+
}
|
|
1283
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
1284
|
+
operation: () => {
|
|
1285
|
+
return this._rawIndex.count(key);
|
|
1286
|
+
},
|
|
1287
|
+
source: this
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
get [Symbol.toStringTag]() {
|
|
1291
|
+
return "IDBIndex";
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
FDBIndex_default = FDBIndex;
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/canInjectKey.js
|
|
1298
|
+
var canInjectKey = (keyPath, value) => {
|
|
1299
|
+
if (Array.isArray(keyPath)) {
|
|
1300
|
+
throw new Error("The key paths used in this section are always strings and never sequences, since it is not possible to create a object store which has a key generator and also has a key path that is a sequence.");
|
|
1301
|
+
}
|
|
1302
|
+
const identifiers = keyPath.split(".");
|
|
1303
|
+
if (identifiers.length === 0) {
|
|
1304
|
+
throw new Error("Assert: identifiers is not empty");
|
|
1305
|
+
}
|
|
1306
|
+
identifiers.pop();
|
|
1307
|
+
for (const identifier of identifiers) {
|
|
1308
|
+
if (typeof value !== "object" && !Array.isArray(value)) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
const hop = Object.hasOwn(value, identifier);
|
|
1312
|
+
if (!hop) {
|
|
1313
|
+
return true;
|
|
1314
|
+
}
|
|
1315
|
+
value = value[identifier];
|
|
1316
|
+
}
|
|
1317
|
+
return typeof value === "object" || Array.isArray(value);
|
|
1318
|
+
}, canInjectKey_default;
|
|
1319
|
+
var init_canInjectKey = __esm(() => {
|
|
1320
|
+
canInjectKey_default = canInjectKey;
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBRecord.js
|
|
1324
|
+
var FDBRecord, FDBRecord_default;
|
|
1325
|
+
var init_FDBRecord = __esm(() => {
|
|
1326
|
+
FDBRecord = class FDBRecord {
|
|
1327
|
+
constructor(key, primaryKey, value) {
|
|
1328
|
+
this._key = key;
|
|
1329
|
+
this._primaryKey = primaryKey;
|
|
1330
|
+
this._value = value;
|
|
1331
|
+
}
|
|
1332
|
+
get key() {
|
|
1333
|
+
return this._key;
|
|
1334
|
+
}
|
|
1335
|
+
set key(_) {}
|
|
1336
|
+
get primaryKey() {
|
|
1337
|
+
return this._primaryKey;
|
|
1338
|
+
}
|
|
1339
|
+
set primaryKey(_) {}
|
|
1340
|
+
get value() {
|
|
1341
|
+
return this._value;
|
|
1342
|
+
}
|
|
1343
|
+
set value(_) {}
|
|
1344
|
+
get [Symbol.toStringTag]() {
|
|
1345
|
+
return "IDBRecord";
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
FDBRecord_default = FDBRecord;
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/binarySearchTree.js
|
|
1352
|
+
class BinarySearchTree {
|
|
1353
|
+
_numTombstones = 0;
|
|
1354
|
+
_numNodes = 0;
|
|
1355
|
+
constructor(keysAreUnique) {
|
|
1356
|
+
this._keysAreUnique = !!keysAreUnique;
|
|
1357
|
+
}
|
|
1358
|
+
size() {
|
|
1359
|
+
return this._numNodes - this._numTombstones;
|
|
1360
|
+
}
|
|
1361
|
+
get(record) {
|
|
1362
|
+
return this._getByComparator(this._root, (otherRecord) => this._compare(record, otherRecord));
|
|
1363
|
+
}
|
|
1364
|
+
contains(record) {
|
|
1365
|
+
return !!this.get(record);
|
|
1366
|
+
}
|
|
1367
|
+
_compare(a, b) {
|
|
1368
|
+
const keyComparison = cmp_default(a.key, b.key);
|
|
1369
|
+
if (keyComparison !== 0) {
|
|
1370
|
+
return keyComparison;
|
|
1371
|
+
}
|
|
1372
|
+
return this._keysAreUnique ? 0 : cmp_default(a.value, b.value);
|
|
1373
|
+
}
|
|
1374
|
+
_getByComparator(node, comparator) {
|
|
1375
|
+
let current = node;
|
|
1376
|
+
while (current) {
|
|
1377
|
+
const comparison = comparator(current.record);
|
|
1378
|
+
if (comparison < 0) {
|
|
1379
|
+
current = current.left;
|
|
1380
|
+
} else if (comparison > 0) {
|
|
1381
|
+
current = current.right;
|
|
1382
|
+
} else {
|
|
1383
|
+
return current.record;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
put(record, noOverwrite = false) {
|
|
1388
|
+
if (!this._root) {
|
|
1389
|
+
this._root = {
|
|
1390
|
+
record,
|
|
1391
|
+
left: undefined,
|
|
1392
|
+
right: undefined,
|
|
1393
|
+
parent: undefined,
|
|
1394
|
+
deleted: false,
|
|
1395
|
+
red: false
|
|
1396
|
+
};
|
|
1397
|
+
this._numNodes++;
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
return this._put(this._root, record, noOverwrite);
|
|
1401
|
+
}
|
|
1402
|
+
_put(node, record, noOverwrite) {
|
|
1403
|
+
const comparison = this._compare(record, node.record);
|
|
1404
|
+
if (comparison < 0) {
|
|
1405
|
+
if (node.left) {
|
|
1406
|
+
return this._put(node.left, record, noOverwrite);
|
|
1407
|
+
} else {
|
|
1408
|
+
node.left = {
|
|
1409
|
+
record,
|
|
1410
|
+
left: undefined,
|
|
1411
|
+
right: undefined,
|
|
1412
|
+
parent: node,
|
|
1413
|
+
deleted: false,
|
|
1414
|
+
red: true
|
|
1415
|
+
};
|
|
1416
|
+
this._onNewNodeInserted(node.left);
|
|
1417
|
+
}
|
|
1418
|
+
} else if (comparison > 0) {
|
|
1419
|
+
if (node.right) {
|
|
1420
|
+
return this._put(node.right, record, noOverwrite);
|
|
1421
|
+
} else {
|
|
1422
|
+
node.right = {
|
|
1423
|
+
record,
|
|
1424
|
+
left: undefined,
|
|
1425
|
+
right: undefined,
|
|
1426
|
+
parent: node,
|
|
1427
|
+
deleted: false,
|
|
1428
|
+
red: true
|
|
1429
|
+
};
|
|
1430
|
+
this._onNewNodeInserted(node.right);
|
|
1431
|
+
}
|
|
1432
|
+
} else if (node.deleted) {
|
|
1433
|
+
node.deleted = false;
|
|
1434
|
+
node.record = record;
|
|
1435
|
+
this._numTombstones--;
|
|
1436
|
+
} else if (noOverwrite) {
|
|
1437
|
+
throw new ConstraintError;
|
|
1438
|
+
} else {
|
|
1439
|
+
const overwrittenRecord = node.record;
|
|
1440
|
+
node.record = record;
|
|
1441
|
+
return overwrittenRecord;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
delete(record) {
|
|
1445
|
+
if (!this._root) {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
this._delete(this._root, record);
|
|
1449
|
+
if (this._numTombstones > this._numNodes * MAX_TOMBSTONE_FACTOR) {
|
|
1450
|
+
const records = [...this.getAllRecords()];
|
|
1451
|
+
this._root = this._rebuild(records, undefined, false);
|
|
1452
|
+
this._numNodes = records.length;
|
|
1453
|
+
this._numTombstones = 0;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
_delete(node, record) {
|
|
1457
|
+
if (!node) {
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const comparison = this._compare(record, node.record);
|
|
1461
|
+
if (comparison < 0) {
|
|
1462
|
+
this._delete(node.left, record);
|
|
1463
|
+
} else if (comparison > 0) {
|
|
1464
|
+
this._delete(node.right, record);
|
|
1465
|
+
} else if (!node.deleted) {
|
|
1466
|
+
this._numTombstones++;
|
|
1467
|
+
node.deleted = true;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
*getAllRecords(descending = false) {
|
|
1471
|
+
yield* this.getRecords(EVERYTHING_KEY_RANGE, descending);
|
|
1472
|
+
}
|
|
1473
|
+
*getRecords(keyRange, descending = false) {
|
|
1474
|
+
yield* this._getRecordsForNode(this._root, keyRange, descending);
|
|
1475
|
+
}
|
|
1476
|
+
*_getRecordsForNode(node, keyRange, descending = false) {
|
|
1477
|
+
if (!node) {
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
yield* this._findRecords(node, keyRange, descending);
|
|
1481
|
+
}
|
|
1482
|
+
*_findRecords(node, keyRange, descending = false) {
|
|
1483
|
+
const {
|
|
1484
|
+
lower,
|
|
1485
|
+
upper,
|
|
1486
|
+
lowerOpen,
|
|
1487
|
+
upperOpen
|
|
1488
|
+
} = keyRange;
|
|
1489
|
+
const {
|
|
1490
|
+
record: {
|
|
1491
|
+
key
|
|
1492
|
+
}
|
|
1493
|
+
} = node;
|
|
1494
|
+
const lowerComparison = lower === undefined ? -1 : cmp_default(lower, key);
|
|
1495
|
+
const upperComparison = upper === undefined ? 1 : cmp_default(upper, key);
|
|
1496
|
+
const moreLeft = this._keysAreUnique ? lowerComparison < 0 : lowerComparison <= 0;
|
|
1497
|
+
const moreRight = this._keysAreUnique ? upperComparison > 0 : upperComparison >= 0;
|
|
1498
|
+
const moreStart = descending ? moreRight : moreLeft;
|
|
1499
|
+
const moreEnd = descending ? moreLeft : moreRight;
|
|
1500
|
+
const start = descending ? "right" : "left";
|
|
1501
|
+
const end = descending ? "left" : "right";
|
|
1502
|
+
const lowerMatches = lowerOpen ? lowerComparison < 0 : lowerComparison <= 0;
|
|
1503
|
+
const upperMatches = upperOpen ? upperComparison > 0 : upperComparison >= 0;
|
|
1504
|
+
if (moreStart && node[start]) {
|
|
1505
|
+
yield* this._findRecords(node[start], keyRange, descending);
|
|
1506
|
+
}
|
|
1507
|
+
if (lowerMatches && upperMatches && !node.deleted) {
|
|
1508
|
+
yield node.record;
|
|
1509
|
+
}
|
|
1510
|
+
if (moreEnd && node[end]) {
|
|
1511
|
+
yield* this._findRecords(node[end], keyRange, descending);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
_onNewNodeInserted(newNode) {
|
|
1515
|
+
this._numNodes++;
|
|
1516
|
+
this._rebalanceTree(newNode);
|
|
1517
|
+
}
|
|
1518
|
+
_rebalanceTree(node) {
|
|
1519
|
+
let parent = node.parent;
|
|
1520
|
+
do {
|
|
1521
|
+
if (!parent.red) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const grandparent = parent.parent;
|
|
1525
|
+
if (!grandparent) {
|
|
1526
|
+
parent.red = false;
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
const parentIsRightChild = parent === grandparent.right;
|
|
1530
|
+
const uncle = parentIsRightChild ? grandparent.left : grandparent.right;
|
|
1531
|
+
if (!uncle || !uncle.red) {
|
|
1532
|
+
if (node === (parentIsRightChild ? parent.left : parent.right)) {
|
|
1533
|
+
this._rotateSubtree(parent, parentIsRightChild);
|
|
1534
|
+
node = parent;
|
|
1535
|
+
parent = parentIsRightChild ? grandparent.right : grandparent.left;
|
|
1536
|
+
}
|
|
1537
|
+
this._rotateSubtree(grandparent, !parentIsRightChild);
|
|
1538
|
+
parent.red = false;
|
|
1539
|
+
grandparent.red = true;
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
parent.red = false;
|
|
1543
|
+
uncle.red = false;
|
|
1544
|
+
grandparent.red = true;
|
|
1545
|
+
node = grandparent;
|
|
1546
|
+
} while (node.parent ? parent = node.parent : false);
|
|
1547
|
+
}
|
|
1548
|
+
_rotateSubtree(node, right) {
|
|
1549
|
+
const parent = node.parent;
|
|
1550
|
+
const newRoot = right ? node.left : node.right;
|
|
1551
|
+
const newChild = right ? newRoot.right : newRoot.left;
|
|
1552
|
+
node[right ? "left" : "right"] = newChild;
|
|
1553
|
+
if (newChild) {
|
|
1554
|
+
newChild.parent = node;
|
|
1555
|
+
}
|
|
1556
|
+
newRoot[right ? "right" : "left"] = node;
|
|
1557
|
+
newRoot.parent = parent;
|
|
1558
|
+
node.parent = newRoot;
|
|
1559
|
+
if (parent) {
|
|
1560
|
+
parent[node === parent.right ? "right" : "left"] = newRoot;
|
|
1561
|
+
} else {
|
|
1562
|
+
this._root = newRoot;
|
|
1563
|
+
}
|
|
1564
|
+
return newRoot;
|
|
1565
|
+
}
|
|
1566
|
+
_rebuild(records, parent, red) {
|
|
1567
|
+
const {
|
|
1568
|
+
length
|
|
1569
|
+
} = records;
|
|
1570
|
+
if (!length) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
const mid = length >>> 1;
|
|
1574
|
+
const node = {
|
|
1575
|
+
record: records[mid],
|
|
1576
|
+
left: undefined,
|
|
1577
|
+
right: undefined,
|
|
1578
|
+
parent,
|
|
1579
|
+
deleted: false,
|
|
1580
|
+
red
|
|
1581
|
+
};
|
|
1582
|
+
const left = this._rebuild(records.slice(0, mid), node, !red);
|
|
1583
|
+
const right = this._rebuild(records.slice(mid + 1), node, !red);
|
|
1584
|
+
node.left = left;
|
|
1585
|
+
node.right = right;
|
|
1586
|
+
return node;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
var MAX_TOMBSTONE_FACTOR, EVERYTHING_KEY_RANGE;
|
|
1590
|
+
var init_binarySearchTree = __esm(() => {
|
|
1591
|
+
init_FDBKeyRange();
|
|
1592
|
+
init_cmp();
|
|
1593
|
+
init_errors();
|
|
1594
|
+
MAX_TOMBSTONE_FACTOR = 2 / 3;
|
|
1595
|
+
EVERYTHING_KEY_RANGE = new FDBKeyRange_default(undefined, undefined, false, false);
|
|
1596
|
+
});
|
|
1597
|
+
|
|
1598
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/RecordStore.js
|
|
1599
|
+
class RecordStore {
|
|
1600
|
+
constructor(keysAreUnique) {
|
|
1601
|
+
this.keysAreUnique = keysAreUnique;
|
|
1602
|
+
this.records = new BinarySearchTree(this.keysAreUnique);
|
|
1603
|
+
}
|
|
1604
|
+
get(key) {
|
|
1605
|
+
const range = key instanceof FDBKeyRange_default ? key : FDBKeyRange_default.only(key);
|
|
1606
|
+
return this.records.getRecords(range).next().value;
|
|
1607
|
+
}
|
|
1608
|
+
put(newRecord, noOverwrite = false) {
|
|
1609
|
+
return this.records.put(newRecord, noOverwrite);
|
|
1610
|
+
}
|
|
1611
|
+
delete(key) {
|
|
1612
|
+
const range = key instanceof FDBKeyRange_default ? key : FDBKeyRange_default.only(key);
|
|
1613
|
+
const deletedRecords = [...this.records.getRecords(range)];
|
|
1614
|
+
for (const record of deletedRecords) {
|
|
1615
|
+
this.records.delete(record);
|
|
1616
|
+
}
|
|
1617
|
+
return deletedRecords;
|
|
1618
|
+
}
|
|
1619
|
+
deleteByValue(key) {
|
|
1620
|
+
const range = key instanceof FDBKeyRange_default ? key : FDBKeyRange_default.only(key);
|
|
1621
|
+
const deletedRecords = [];
|
|
1622
|
+
for (const record of this.records.getAllRecords()) {
|
|
1623
|
+
if (range.includes(record.value)) {
|
|
1624
|
+
this.records.delete(record);
|
|
1625
|
+
deletedRecords.push(record);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
return deletedRecords;
|
|
1629
|
+
}
|
|
1630
|
+
clear() {
|
|
1631
|
+
const deletedRecords = [...this.records.getAllRecords()];
|
|
1632
|
+
this.records = new BinarySearchTree(this.keysAreUnique);
|
|
1633
|
+
return deletedRecords;
|
|
1634
|
+
}
|
|
1635
|
+
values(range, direction = "next") {
|
|
1636
|
+
const descending = direction === "prev" || direction === "prevunique";
|
|
1637
|
+
const records = range ? this.records.getRecords(range, descending) : this.records.getAllRecords(descending);
|
|
1638
|
+
return {
|
|
1639
|
+
[Symbol.iterator]: () => {
|
|
1640
|
+
const next = () => {
|
|
1641
|
+
return records.next();
|
|
1642
|
+
};
|
|
1643
|
+
if (direction === "next" || direction === "prev") {
|
|
1644
|
+
return {
|
|
1645
|
+
next
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
if (direction === "nextunique") {
|
|
1649
|
+
let previousValue = undefined;
|
|
1650
|
+
return {
|
|
1651
|
+
next: () => {
|
|
1652
|
+
let current2 = next();
|
|
1653
|
+
while (!current2.done && previousValue !== undefined && cmp_default(previousValue.key, current2.value.key) === 0) {
|
|
1654
|
+
current2 = next();
|
|
1655
|
+
}
|
|
1656
|
+
previousValue = current2.value;
|
|
1657
|
+
return current2;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
let current = next();
|
|
1662
|
+
let nextResult = next();
|
|
1663
|
+
return {
|
|
1664
|
+
next: () => {
|
|
1665
|
+
while (!nextResult.done && cmp_default(current.value.key, nextResult.value.key) === 0) {
|
|
1666
|
+
current = nextResult;
|
|
1667
|
+
nextResult = next();
|
|
1668
|
+
}
|
|
1669
|
+
const result = current;
|
|
1670
|
+
current = nextResult;
|
|
1671
|
+
nextResult = next();
|
|
1672
|
+
return result;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
size() {
|
|
1679
|
+
return this.records.size();
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
var RecordStore_default;
|
|
1683
|
+
var init_RecordStore = __esm(() => {
|
|
1684
|
+
init_FDBKeyRange();
|
|
1685
|
+
init_cmp();
|
|
1686
|
+
init_binarySearchTree();
|
|
1687
|
+
RecordStore_default = RecordStore;
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/Index.js
|
|
1691
|
+
class Index {
|
|
1692
|
+
deleted = false;
|
|
1693
|
+
initialized = false;
|
|
1694
|
+
constructor(rawObjectStore, name, keyPath, multiEntry, unique) {
|
|
1695
|
+
this.rawObjectStore = rawObjectStore;
|
|
1696
|
+
this.name = name;
|
|
1697
|
+
this.keyPath = keyPath;
|
|
1698
|
+
this.multiEntry = multiEntry;
|
|
1699
|
+
this.unique = unique;
|
|
1700
|
+
this.records = new RecordStore_default(unique);
|
|
1701
|
+
}
|
|
1702
|
+
getKey(key) {
|
|
1703
|
+
const record = this.records.get(key);
|
|
1704
|
+
return record !== undefined ? record.value : undefined;
|
|
1705
|
+
}
|
|
1706
|
+
getAllKeys(range, count, direction) {
|
|
1707
|
+
if (count === undefined || count === 0) {
|
|
1708
|
+
count = Infinity;
|
|
1709
|
+
}
|
|
1710
|
+
const records = [];
|
|
1711
|
+
for (const record of this.records.values(range, direction)) {
|
|
1712
|
+
records.push(structuredClone(record.value));
|
|
1713
|
+
if (records.length >= count) {
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
return records;
|
|
1718
|
+
}
|
|
1719
|
+
getValue(key) {
|
|
1720
|
+
const record = this.records.get(key);
|
|
1721
|
+
return record !== undefined ? this.rawObjectStore.getValue(record.value) : undefined;
|
|
1722
|
+
}
|
|
1723
|
+
getAllValues(range, count, direction) {
|
|
1724
|
+
if (count === undefined || count === 0) {
|
|
1725
|
+
count = Infinity;
|
|
1726
|
+
}
|
|
1727
|
+
const records = [];
|
|
1728
|
+
for (const record of this.records.values(range, direction)) {
|
|
1729
|
+
records.push(this.rawObjectStore.getValue(record.value));
|
|
1730
|
+
if (records.length >= count) {
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
return records;
|
|
1735
|
+
}
|
|
1736
|
+
getAllRecords(range, count, direction) {
|
|
1737
|
+
if (count === undefined || count === 0) {
|
|
1738
|
+
count = Infinity;
|
|
1739
|
+
}
|
|
1740
|
+
const records = [];
|
|
1741
|
+
for (const record of this.records.values(range, direction)) {
|
|
1742
|
+
records.push(new FDBRecord_default(structuredClone(record.key), structuredClone(this.rawObjectStore.getKey(record.value)), this.rawObjectStore.getValue(record.value)));
|
|
1743
|
+
if (records.length >= count) {
|
|
1744
|
+
break;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
return records;
|
|
1748
|
+
}
|
|
1749
|
+
storeRecord(newRecord) {
|
|
1750
|
+
let indexKey;
|
|
1751
|
+
try {
|
|
1752
|
+
indexKey = extractKey_default(this.keyPath, newRecord.value).key;
|
|
1753
|
+
} catch (err) {
|
|
1754
|
+
if (err.name === "DataError") {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
throw err;
|
|
1758
|
+
}
|
|
1759
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
1760
|
+
try {
|
|
1761
|
+
valueToKey_default(indexKey);
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
} else {
|
|
1766
|
+
const keep = [];
|
|
1767
|
+
for (const part of indexKey) {
|
|
1768
|
+
if (keep.indexOf(part) < 0) {
|
|
1769
|
+
try {
|
|
1770
|
+
keep.push(valueToKey_default(part));
|
|
1771
|
+
} catch (err) {}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
indexKey = keep;
|
|
1775
|
+
}
|
|
1776
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
1777
|
+
if (this.unique) {
|
|
1778
|
+
const existingRecord = this.records.get(indexKey);
|
|
1779
|
+
if (existingRecord) {
|
|
1780
|
+
throw new ConstraintError;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
} else {
|
|
1784
|
+
if (this.unique) {
|
|
1785
|
+
for (const individualIndexKey of indexKey) {
|
|
1786
|
+
const existingRecord = this.records.get(individualIndexKey);
|
|
1787
|
+
if (existingRecord) {
|
|
1788
|
+
throw new ConstraintError;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
1794
|
+
this.records.put({
|
|
1795
|
+
key: indexKey,
|
|
1796
|
+
value: newRecord.key
|
|
1797
|
+
});
|
|
1798
|
+
} else {
|
|
1799
|
+
for (const individualIndexKey of indexKey) {
|
|
1800
|
+
this.records.put({
|
|
1801
|
+
key: individualIndexKey,
|
|
1802
|
+
value: newRecord.key
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
initialize(transaction) {
|
|
1808
|
+
if (this.initialized) {
|
|
1809
|
+
throw new Error("Index already initialized");
|
|
1810
|
+
}
|
|
1811
|
+
transaction._execRequestAsync({
|
|
1812
|
+
operation: () => {
|
|
1813
|
+
try {
|
|
1814
|
+
for (const record of this.rawObjectStore.records.values()) {
|
|
1815
|
+
this.storeRecord(record);
|
|
1816
|
+
}
|
|
1817
|
+
this.initialized = true;
|
|
1818
|
+
} catch (err) {
|
|
1819
|
+
transaction._abort(err.name);
|
|
1820
|
+
}
|
|
1821
|
+
},
|
|
1822
|
+
source: null
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
count(range) {
|
|
1826
|
+
let count = 0;
|
|
1827
|
+
for (const record of this.records.values(range)) {
|
|
1828
|
+
count += 1;
|
|
1829
|
+
}
|
|
1830
|
+
return count;
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
var Index_default;
|
|
1834
|
+
var init_Index = __esm(() => {
|
|
1835
|
+
init_FDBRecord();
|
|
1836
|
+
init_errors();
|
|
1837
|
+
init_extractKey();
|
|
1838
|
+
init_RecordStore();
|
|
1839
|
+
init_valueToKey();
|
|
1840
|
+
Index_default = Index;
|
|
1841
|
+
});
|
|
1842
|
+
|
|
1843
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/validateKeyPath.js
|
|
1844
|
+
var validateKeyPath = (keyPath, parent) => {
|
|
1845
|
+
if (keyPath !== undefined && keyPath !== null && typeof keyPath !== "string" && keyPath.toString && (parent === "array" || !Array.isArray(keyPath))) {
|
|
1846
|
+
keyPath = keyPath.toString();
|
|
1847
|
+
}
|
|
1848
|
+
if (typeof keyPath === "string") {
|
|
1849
|
+
if (keyPath === "" && parent !== "string") {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
try {
|
|
1853
|
+
const validIdentifierRegex = /^(?:[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC])(?:[$0-9A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC])*$/;
|
|
1854
|
+
if (keyPath.length >= 1 && validIdentifierRegex.test(keyPath)) {
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
} catch (err) {
|
|
1858
|
+
throw new SyntaxError(err.message);
|
|
1859
|
+
}
|
|
1860
|
+
if (keyPath.indexOf(" ") >= 0) {
|
|
1861
|
+
throw new SyntaxError("The keypath argument contains an invalid key path (no spaces allowed).");
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (Array.isArray(keyPath) && keyPath.length > 0) {
|
|
1865
|
+
if (parent) {
|
|
1866
|
+
throw new SyntaxError("The keypath argument contains an invalid key path (nested arrays).");
|
|
1867
|
+
}
|
|
1868
|
+
for (const part of keyPath) {
|
|
1869
|
+
validateKeyPath(part, "array");
|
|
1870
|
+
}
|
|
1871
|
+
return;
|
|
1872
|
+
} else if (typeof keyPath === "string" && keyPath.indexOf(".") >= 0) {
|
|
1873
|
+
keyPath = keyPath.split(".");
|
|
1874
|
+
for (const part of keyPath) {
|
|
1875
|
+
validateKeyPath(part, "string");
|
|
1876
|
+
}
|
|
1877
|
+
return;
|
|
1878
|
+
}
|
|
1879
|
+
throw new SyntaxError;
|
|
1880
|
+
}, validateKeyPath_default;
|
|
1881
|
+
var init_validateKeyPath = __esm(() => {
|
|
1882
|
+
init_errors();
|
|
1883
|
+
validateKeyPath_default = validateKeyPath;
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBObjectStore.js
|
|
1887
|
+
var confirmActiveTransaction2 = (objectStore) => {
|
|
1888
|
+
if (objectStore._rawObjectStore.deleted) {
|
|
1889
|
+
throw new InvalidStateError;
|
|
1890
|
+
}
|
|
1891
|
+
if (objectStore.transaction._state !== "active") {
|
|
1892
|
+
throw new TransactionInactiveError;
|
|
1893
|
+
}
|
|
1894
|
+
}, buildRecordAddPut = (objectStore, value, key) => {
|
|
1895
|
+
confirmActiveTransaction2(objectStore);
|
|
1896
|
+
if (objectStore.transaction.mode === "readonly") {
|
|
1897
|
+
throw new ReadOnlyError;
|
|
1898
|
+
}
|
|
1899
|
+
if (objectStore.keyPath !== null) {
|
|
1900
|
+
if (key !== undefined) {
|
|
1901
|
+
throw new DataError;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
const clone = cloneValueForInsertion(value, objectStore.transaction);
|
|
1905
|
+
if (objectStore.keyPath !== null) {
|
|
1906
|
+
const tempKey = extractKey_default(objectStore.keyPath, clone);
|
|
1907
|
+
if (tempKey.type === "found") {
|
|
1908
|
+
valueToKey_default(tempKey.key);
|
|
1909
|
+
} else {
|
|
1910
|
+
if (!objectStore._rawObjectStore.keyGenerator) {
|
|
1911
|
+
throw new DataError;
|
|
1912
|
+
} else if (!canInjectKey_default(objectStore.keyPath, clone)) {
|
|
1913
|
+
throw new DataError;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
if (objectStore.keyPath === null && objectStore._rawObjectStore.keyGenerator === null && key === undefined) {
|
|
1918
|
+
throw new DataError;
|
|
1919
|
+
}
|
|
1920
|
+
if (key !== undefined) {
|
|
1921
|
+
key = valueToKey_default(key);
|
|
1922
|
+
}
|
|
1923
|
+
return {
|
|
1924
|
+
key,
|
|
1925
|
+
value: clone
|
|
1926
|
+
};
|
|
1927
|
+
}, FDBObjectStore, FDBObjectStore_default;
|
|
1928
|
+
var init_FDBObjectStore = __esm(() => {
|
|
1929
|
+
init_FDBCursor();
|
|
1930
|
+
init_FDBCursorWithValue();
|
|
1931
|
+
init_FDBIndex();
|
|
1932
|
+
init_FDBKeyRange();
|
|
1933
|
+
init_FDBRequest();
|
|
1934
|
+
init_canInjectKey();
|
|
1935
|
+
init_errors();
|
|
1936
|
+
init_extractKey();
|
|
1937
|
+
init_FakeDOMStringList();
|
|
1938
|
+
init_Index();
|
|
1939
|
+
init_validateKeyPath();
|
|
1940
|
+
init_valueToKey();
|
|
1941
|
+
init_valueToKeyRange();
|
|
1942
|
+
init_extractGetAllOptions();
|
|
1943
|
+
init_enforceRange();
|
|
1944
|
+
FDBObjectStore = class FDBObjectStore {
|
|
1945
|
+
_indexesCache = new Map;
|
|
1946
|
+
constructor(transaction, rawObjectStore) {
|
|
1947
|
+
this._rawObjectStore = rawObjectStore;
|
|
1948
|
+
this._name = rawObjectStore.name;
|
|
1949
|
+
this.keyPath = getKeyPath(rawObjectStore.keyPath);
|
|
1950
|
+
this.autoIncrement = rawObjectStore.autoIncrement;
|
|
1951
|
+
this.transaction = transaction;
|
|
1952
|
+
this.indexNames = new FakeDOMStringList_default(...Array.from(rawObjectStore.rawIndexes.keys()).sort());
|
|
1953
|
+
}
|
|
1954
|
+
get name() {
|
|
1955
|
+
return this._name;
|
|
1956
|
+
}
|
|
1957
|
+
set name(name) {
|
|
1958
|
+
const transaction = this.transaction;
|
|
1959
|
+
if (!transaction.db._runningVersionchangeTransaction) {
|
|
1960
|
+
throw transaction._state === "active" ? new InvalidStateError : new TransactionInactiveError;
|
|
1961
|
+
}
|
|
1962
|
+
confirmActiveTransaction2(this);
|
|
1963
|
+
name = String(name);
|
|
1964
|
+
if (name === this._name) {
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
if (this._rawObjectStore.rawDatabase.rawObjectStores.has(name)) {
|
|
1968
|
+
throw new ConstraintError;
|
|
1969
|
+
}
|
|
1970
|
+
const oldName = this._name;
|
|
1971
|
+
const oldObjectStoreNames = [...transaction.db.objectStoreNames];
|
|
1972
|
+
this._name = name;
|
|
1973
|
+
this._rawObjectStore.name = name;
|
|
1974
|
+
this.transaction._objectStoresCache.delete(oldName);
|
|
1975
|
+
this.transaction._objectStoresCache.set(name, this);
|
|
1976
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.delete(oldName);
|
|
1977
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.set(name, this._rawObjectStore);
|
|
1978
|
+
transaction.db.objectStoreNames = new FakeDOMStringList_default(...Array.from(this._rawObjectStore.rawDatabase.rawObjectStores.keys()).filter((objectStoreName) => {
|
|
1979
|
+
const objectStore = this._rawObjectStore.rawDatabase.rawObjectStores.get(objectStoreName);
|
|
1980
|
+
return objectStore && !objectStore.deleted;
|
|
1981
|
+
}).sort());
|
|
1982
|
+
const oldScope = new Set(transaction._scope);
|
|
1983
|
+
const oldTransactionObjectStoreNames = [...transaction.objectStoreNames];
|
|
1984
|
+
this.transaction._scope.delete(oldName);
|
|
1985
|
+
transaction._scope.add(name);
|
|
1986
|
+
transaction.objectStoreNames = new FakeDOMStringList_default(...Array.from(transaction._scope).sort());
|
|
1987
|
+
if (!this.transaction._createdObjectStores.has(this._rawObjectStore)) {
|
|
1988
|
+
transaction._rollbackLog.push(() => {
|
|
1989
|
+
this._name = oldName;
|
|
1990
|
+
this._rawObjectStore.name = oldName;
|
|
1991
|
+
this.transaction._objectStoresCache.delete(name);
|
|
1992
|
+
this.transaction._objectStoresCache.set(oldName, this);
|
|
1993
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.delete(name);
|
|
1994
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.set(oldName, this._rawObjectStore);
|
|
1995
|
+
transaction.db.objectStoreNames = new FakeDOMStringList_default(...oldObjectStoreNames);
|
|
1996
|
+
transaction._scope = oldScope;
|
|
1997
|
+
transaction.objectStoreNames = new FakeDOMStringList_default(...oldTransactionObjectStoreNames);
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
put(value, key) {
|
|
2002
|
+
if (arguments.length === 0) {
|
|
2003
|
+
throw new TypeError;
|
|
2004
|
+
}
|
|
2005
|
+
const record = buildRecordAddPut(this, value, key);
|
|
2006
|
+
return this.transaction._execRequestAsync({
|
|
2007
|
+
operation: this._rawObjectStore.storeRecord.bind(this._rawObjectStore, record, false, this.transaction._rollbackLog),
|
|
2008
|
+
source: this
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
add(value, key) {
|
|
2012
|
+
if (arguments.length === 0) {
|
|
2013
|
+
throw new TypeError;
|
|
2014
|
+
}
|
|
2015
|
+
const record = buildRecordAddPut(this, value, key);
|
|
2016
|
+
return this.transaction._execRequestAsync({
|
|
2017
|
+
operation: this._rawObjectStore.storeRecord.bind(this._rawObjectStore, record, true, this.transaction._rollbackLog),
|
|
2018
|
+
source: this
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
delete(key) {
|
|
2022
|
+
if (arguments.length === 0) {
|
|
2023
|
+
throw new TypeError;
|
|
2024
|
+
}
|
|
2025
|
+
confirmActiveTransaction2(this);
|
|
2026
|
+
if (this.transaction.mode === "readonly") {
|
|
2027
|
+
throw new ReadOnlyError;
|
|
2028
|
+
}
|
|
2029
|
+
if (!(key instanceof FDBKeyRange_default)) {
|
|
2030
|
+
key = valueToKey_default(key);
|
|
2031
|
+
}
|
|
2032
|
+
return this.transaction._execRequestAsync({
|
|
2033
|
+
operation: this._rawObjectStore.deleteRecord.bind(this._rawObjectStore, key, this.transaction._rollbackLog),
|
|
2034
|
+
source: this
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
get(key) {
|
|
2038
|
+
if (arguments.length === 0) {
|
|
2039
|
+
throw new TypeError;
|
|
2040
|
+
}
|
|
2041
|
+
confirmActiveTransaction2(this);
|
|
2042
|
+
if (!(key instanceof FDBKeyRange_default)) {
|
|
2043
|
+
key = valueToKey_default(key);
|
|
2044
|
+
}
|
|
2045
|
+
return this.transaction._execRequestAsync({
|
|
2046
|
+
operation: this._rawObjectStore.getValue.bind(this._rawObjectStore, key),
|
|
2047
|
+
source: this
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
getAll(queryOrOptions, count) {
|
|
2051
|
+
const options = extractGetAllOptions_default(queryOrOptions, count, arguments.length);
|
|
2052
|
+
confirmActiveTransaction2(this);
|
|
2053
|
+
const range = valueToKeyRange_default(options.query);
|
|
2054
|
+
return this.transaction._execRequestAsync({
|
|
2055
|
+
operation: this._rawObjectStore.getAllValues.bind(this._rawObjectStore, range, options.count, options.direction),
|
|
2056
|
+
source: this
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
getKey(key) {
|
|
2060
|
+
if (arguments.length === 0) {
|
|
2061
|
+
throw new TypeError;
|
|
2062
|
+
}
|
|
2063
|
+
confirmActiveTransaction2(this);
|
|
2064
|
+
if (!(key instanceof FDBKeyRange_default)) {
|
|
2065
|
+
key = valueToKey_default(key);
|
|
2066
|
+
}
|
|
2067
|
+
return this.transaction._execRequestAsync({
|
|
2068
|
+
operation: this._rawObjectStore.getKey.bind(this._rawObjectStore, key),
|
|
2069
|
+
source: this
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
getAllKeys(queryOrOptions, count) {
|
|
2073
|
+
const options = extractGetAllOptions_default(queryOrOptions, count, arguments.length);
|
|
2074
|
+
confirmActiveTransaction2(this);
|
|
2075
|
+
const range = valueToKeyRange_default(options.query);
|
|
2076
|
+
return this.transaction._execRequestAsync({
|
|
2077
|
+
operation: this._rawObjectStore.getAllKeys.bind(this._rawObjectStore, range, options.count, options.direction),
|
|
2078
|
+
source: this
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
getAllRecords(options) {
|
|
2082
|
+
let query;
|
|
2083
|
+
let count;
|
|
2084
|
+
let direction;
|
|
2085
|
+
if (options !== undefined) {
|
|
2086
|
+
if (options.query !== undefined) {
|
|
2087
|
+
query = options.query;
|
|
2088
|
+
}
|
|
2089
|
+
if (options.count !== undefined) {
|
|
2090
|
+
count = enforceRange_default(options.count, "unsigned long");
|
|
2091
|
+
}
|
|
2092
|
+
if (options.direction !== undefined) {
|
|
2093
|
+
direction = options.direction;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
confirmActiveTransaction2(this);
|
|
2097
|
+
const range = valueToKeyRange_default(query);
|
|
2098
|
+
return this.transaction._execRequestAsync({
|
|
2099
|
+
operation: this._rawObjectStore.getAllRecords.bind(this._rawObjectStore, range, count, direction),
|
|
2100
|
+
source: this
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
clear() {
|
|
2104
|
+
confirmActiveTransaction2(this);
|
|
2105
|
+
if (this.transaction.mode === "readonly") {
|
|
2106
|
+
throw new ReadOnlyError;
|
|
2107
|
+
}
|
|
2108
|
+
return this.transaction._execRequestAsync({
|
|
2109
|
+
operation: this._rawObjectStore.clear.bind(this._rawObjectStore, this.transaction._rollbackLog),
|
|
2110
|
+
source: this
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
openCursor(range, direction) {
|
|
2114
|
+
confirmActiveTransaction2(this);
|
|
2115
|
+
if (range === null) {
|
|
2116
|
+
range = undefined;
|
|
2117
|
+
}
|
|
2118
|
+
if (range !== undefined && !(range instanceof FDBKeyRange_default)) {
|
|
2119
|
+
range = FDBKeyRange_default.only(valueToKey_default(range));
|
|
2120
|
+
}
|
|
2121
|
+
const request = new FDBRequest_default;
|
|
2122
|
+
request.source = this;
|
|
2123
|
+
request.transaction = this.transaction;
|
|
2124
|
+
const cursor = new FDBCursorWithValue_default(this, range, direction, request);
|
|
2125
|
+
return this.transaction._execRequestAsync({
|
|
2126
|
+
operation: cursor._iterate.bind(cursor),
|
|
2127
|
+
request,
|
|
2128
|
+
source: this
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
openKeyCursor(range, direction) {
|
|
2132
|
+
confirmActiveTransaction2(this);
|
|
2133
|
+
if (range === null) {
|
|
2134
|
+
range = undefined;
|
|
2135
|
+
}
|
|
2136
|
+
if (range !== undefined && !(range instanceof FDBKeyRange_default)) {
|
|
2137
|
+
range = FDBKeyRange_default.only(valueToKey_default(range));
|
|
2138
|
+
}
|
|
2139
|
+
const request = new FDBRequest_default;
|
|
2140
|
+
request.source = this;
|
|
2141
|
+
request.transaction = this.transaction;
|
|
2142
|
+
const cursor = new FDBCursor_default(this, range, direction, request, true);
|
|
2143
|
+
return this.transaction._execRequestAsync({
|
|
2144
|
+
operation: cursor._iterate.bind(cursor),
|
|
2145
|
+
request,
|
|
2146
|
+
source: this
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
createIndex(name, keyPath, optionalParameters = {}) {
|
|
2150
|
+
if (arguments.length < 2) {
|
|
2151
|
+
throw new TypeError;
|
|
2152
|
+
}
|
|
2153
|
+
const multiEntry = optionalParameters.multiEntry !== undefined ? optionalParameters.multiEntry : false;
|
|
2154
|
+
const unique = optionalParameters.unique !== undefined ? optionalParameters.unique : false;
|
|
2155
|
+
if (this.transaction.mode !== "versionchange") {
|
|
2156
|
+
throw new InvalidStateError;
|
|
2157
|
+
}
|
|
2158
|
+
confirmActiveTransaction2(this);
|
|
2159
|
+
if (this.indexNames.contains(name)) {
|
|
2160
|
+
throw new ConstraintError;
|
|
2161
|
+
}
|
|
2162
|
+
validateKeyPath_default(keyPath);
|
|
2163
|
+
if (Array.isArray(keyPath) && multiEntry) {
|
|
2164
|
+
throw new InvalidAccessError;
|
|
2165
|
+
}
|
|
2166
|
+
const indexNames = [...this.indexNames];
|
|
2167
|
+
const index = new Index_default(this._rawObjectStore, name, keyPath, multiEntry, unique);
|
|
2168
|
+
this.indexNames._push(name);
|
|
2169
|
+
this.indexNames._sort();
|
|
2170
|
+
this.transaction._createdIndexes.add(index);
|
|
2171
|
+
this._rawObjectStore.rawIndexes.set(name, index);
|
|
2172
|
+
index.initialize(this.transaction);
|
|
2173
|
+
this.transaction._rollbackLog.push(() => {
|
|
2174
|
+
index.deleted = true;
|
|
2175
|
+
this.indexNames = new FakeDOMStringList_default(...indexNames);
|
|
2176
|
+
this._rawObjectStore.rawIndexes.delete(index.name);
|
|
2177
|
+
});
|
|
2178
|
+
return new FDBIndex_default(this, index);
|
|
2179
|
+
}
|
|
2180
|
+
index(name) {
|
|
2181
|
+
if (arguments.length === 0) {
|
|
2182
|
+
throw new TypeError;
|
|
2183
|
+
}
|
|
2184
|
+
if (this._rawObjectStore.deleted || this.transaction._state === "finished") {
|
|
2185
|
+
throw new InvalidStateError;
|
|
2186
|
+
}
|
|
2187
|
+
const index = this._indexesCache.get(name);
|
|
2188
|
+
if (index !== undefined) {
|
|
2189
|
+
return index;
|
|
2190
|
+
}
|
|
2191
|
+
const rawIndex = this._rawObjectStore.rawIndexes.get(name);
|
|
2192
|
+
if (!this.indexNames.contains(name) || rawIndex === undefined) {
|
|
2193
|
+
throw new NotFoundError;
|
|
2194
|
+
}
|
|
2195
|
+
const index2 = new FDBIndex_default(this, rawIndex);
|
|
2196
|
+
this._indexesCache.set(name, index2);
|
|
2197
|
+
return index2;
|
|
2198
|
+
}
|
|
2199
|
+
deleteIndex(name) {
|
|
2200
|
+
if (arguments.length === 0) {
|
|
2201
|
+
throw new TypeError;
|
|
2202
|
+
}
|
|
2203
|
+
if (this.transaction.mode !== "versionchange") {
|
|
2204
|
+
throw new InvalidStateError;
|
|
2205
|
+
}
|
|
2206
|
+
confirmActiveTransaction2(this);
|
|
2207
|
+
const rawIndex = this._rawObjectStore.rawIndexes.get(name);
|
|
2208
|
+
if (rawIndex === undefined) {
|
|
2209
|
+
throw new NotFoundError;
|
|
2210
|
+
}
|
|
2211
|
+
this.transaction._rollbackLog.push(() => {
|
|
2212
|
+
rawIndex.deleted = false;
|
|
2213
|
+
this._rawObjectStore.rawIndexes.set(rawIndex.name, rawIndex);
|
|
2214
|
+
this.indexNames._push(rawIndex.name);
|
|
2215
|
+
this.indexNames._sort();
|
|
2216
|
+
});
|
|
2217
|
+
this.indexNames = new FakeDOMStringList_default(...Array.from(this.indexNames).filter((indexName) => {
|
|
2218
|
+
return indexName !== name;
|
|
2219
|
+
}));
|
|
2220
|
+
rawIndex.deleted = true;
|
|
2221
|
+
this.transaction._execRequestAsync({
|
|
2222
|
+
operation: () => {
|
|
2223
|
+
const rawIndex2 = this._rawObjectStore.rawIndexes.get(name);
|
|
2224
|
+
if (rawIndex === rawIndex2) {
|
|
2225
|
+
this._rawObjectStore.rawIndexes.delete(name);
|
|
2226
|
+
}
|
|
2227
|
+
},
|
|
2228
|
+
source: this
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
count(key) {
|
|
2232
|
+
confirmActiveTransaction2(this);
|
|
2233
|
+
if (key === null) {
|
|
2234
|
+
key = undefined;
|
|
2235
|
+
}
|
|
2236
|
+
if (key !== undefined && !(key instanceof FDBKeyRange_default)) {
|
|
2237
|
+
key = FDBKeyRange_default.only(valueToKey_default(key));
|
|
2238
|
+
}
|
|
2239
|
+
return this.transaction._execRequestAsync({
|
|
2240
|
+
operation: () => {
|
|
2241
|
+
return this._rawObjectStore.count(key);
|
|
2242
|
+
},
|
|
2243
|
+
source: this
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
get [Symbol.toStringTag]() {
|
|
2247
|
+
return "IDBObjectStore";
|
|
2248
|
+
}
|
|
2249
|
+
};
|
|
2250
|
+
FDBObjectStore_default = FDBObjectStore;
|
|
2251
|
+
});
|
|
2252
|
+
|
|
2253
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/FakeEvent.js
|
|
2254
|
+
class Event {
|
|
2255
|
+
eventPath = [];
|
|
2256
|
+
NONE = 0;
|
|
2257
|
+
CAPTURING_PHASE = 1;
|
|
2258
|
+
AT_TARGET = 2;
|
|
2259
|
+
BUBBLING_PHASE = 3;
|
|
2260
|
+
propagationStopped = false;
|
|
2261
|
+
immediatePropagationStopped = false;
|
|
2262
|
+
canceled = false;
|
|
2263
|
+
initialized = true;
|
|
2264
|
+
dispatched = false;
|
|
2265
|
+
target = null;
|
|
2266
|
+
currentTarget = null;
|
|
2267
|
+
eventPhase = 0;
|
|
2268
|
+
defaultPrevented = false;
|
|
2269
|
+
isTrusted = false;
|
|
2270
|
+
timeStamp = Date.now();
|
|
2271
|
+
constructor(type, eventInitDict = {}) {
|
|
2272
|
+
this.type = type;
|
|
2273
|
+
this.bubbles = eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
|
|
2274
|
+
this.cancelable = eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
|
|
2275
|
+
}
|
|
2276
|
+
preventDefault() {
|
|
2277
|
+
if (this.cancelable) {
|
|
2278
|
+
this.canceled = true;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
stopPropagation() {
|
|
2282
|
+
this.propagationStopped = true;
|
|
2283
|
+
}
|
|
2284
|
+
stopImmediatePropagation() {
|
|
2285
|
+
this.propagationStopped = true;
|
|
2286
|
+
this.immediatePropagationStopped = true;
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
var FakeEvent_default;
|
|
2290
|
+
var init_FakeEvent = __esm(() => {
|
|
2291
|
+
FakeEvent_default = Event;
|
|
2292
|
+
});
|
|
2293
|
+
|
|
2294
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/scheduling.js
|
|
2295
|
+
function getSetImmediateFromJsdom() {
|
|
2296
|
+
if (typeof navigator !== "undefined" && /jsdom/.test(navigator.userAgent)) {
|
|
2297
|
+
const outerRealmFunctionConstructor = Node.constructor;
|
|
2298
|
+
return new outerRealmFunctionConstructor("return setImmediate")();
|
|
2299
|
+
} else {
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
var schedulerPostTask, doSetTimeout = (fn) => setTimeout(fn, 0), queueTask = (fn) => {
|
|
2304
|
+
const setImmediate = globalThis.setImmediate || getSetImmediateFromJsdom() || schedulerPostTask || doSetTimeout;
|
|
2305
|
+
setImmediate(fn);
|
|
2306
|
+
};
|
|
2307
|
+
var init_scheduling = __esm(() => {
|
|
2308
|
+
schedulerPostTask = typeof scheduler !== "undefined" && ((fn) => scheduler.postTask(fn));
|
|
2309
|
+
});
|
|
2310
|
+
|
|
2311
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBTransaction.js
|
|
2312
|
+
var prioritizedListenerTypes, FDBTransaction, FDBTransaction_default;
|
|
2313
|
+
var init_FDBTransaction = __esm(() => {
|
|
2314
|
+
init_FDBObjectStore();
|
|
2315
|
+
init_FDBRequest();
|
|
2316
|
+
init_errors();
|
|
2317
|
+
init_FakeDOMStringList();
|
|
2318
|
+
init_FakeEvent();
|
|
2319
|
+
init_FakeEventTarget();
|
|
2320
|
+
init_scheduling();
|
|
2321
|
+
prioritizedListenerTypes = ["error", "abort", "complete"];
|
|
2322
|
+
FDBTransaction = class FDBTransaction extends FakeEventTarget_default {
|
|
2323
|
+
_state = "active";
|
|
2324
|
+
_started = false;
|
|
2325
|
+
_rollbackLog = [];
|
|
2326
|
+
_objectStoresCache = new Map;
|
|
2327
|
+
_openRequest = null;
|
|
2328
|
+
error = null;
|
|
2329
|
+
onabort = null;
|
|
2330
|
+
oncomplete = null;
|
|
2331
|
+
onerror = null;
|
|
2332
|
+
_prioritizedListeners = new Map;
|
|
2333
|
+
_requests = [];
|
|
2334
|
+
_createdIndexes = new Set;
|
|
2335
|
+
_createdObjectStores = new Set;
|
|
2336
|
+
constructor(storeNames, mode, durability, db) {
|
|
2337
|
+
super();
|
|
2338
|
+
this._scope = new Set(storeNames);
|
|
2339
|
+
this.mode = mode;
|
|
2340
|
+
this.durability = durability;
|
|
2341
|
+
this.db = db;
|
|
2342
|
+
this.objectStoreNames = new FakeDOMStringList_default(...Array.from(this._scope).sort());
|
|
2343
|
+
for (const type of prioritizedListenerTypes) {
|
|
2344
|
+
this.addEventListener(type, () => {
|
|
2345
|
+
this._prioritizedListeners.get(type)?.();
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
_abort(errName) {
|
|
2350
|
+
for (const f of this._rollbackLog.reverse()) {
|
|
2351
|
+
f();
|
|
2352
|
+
}
|
|
2353
|
+
if (errName !== null) {
|
|
2354
|
+
const e = new DOMException(undefined, errName);
|
|
2355
|
+
this.error = e;
|
|
2356
|
+
}
|
|
2357
|
+
for (const {
|
|
2358
|
+
request
|
|
2359
|
+
} of this._requests) {
|
|
2360
|
+
if (request.readyState !== "done") {
|
|
2361
|
+
request.readyState = "done";
|
|
2362
|
+
if (request.source) {
|
|
2363
|
+
queueTask(() => {
|
|
2364
|
+
request.result = undefined;
|
|
2365
|
+
request.error = new AbortError;
|
|
2366
|
+
const event = new FakeEvent_default("error", {
|
|
2367
|
+
bubbles: true,
|
|
2368
|
+
cancelable: true
|
|
2369
|
+
});
|
|
2370
|
+
event.eventPath = [this.db, this];
|
|
2371
|
+
try {
|
|
2372
|
+
request.dispatchEvent(event);
|
|
2373
|
+
} catch (_err) {
|
|
2374
|
+
if (this._state === "active") {
|
|
2375
|
+
this._abort("AbortError");
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
queueTask(() => {
|
|
2383
|
+
const isUpgradeTransaction = this.mode === "versionchange";
|
|
2384
|
+
if (isUpgradeTransaction) {
|
|
2385
|
+
this.db._rawDatabase.connections = this.db._rawDatabase.connections.filter((connection) => !connection._rawDatabase.transactions.includes(this));
|
|
2386
|
+
}
|
|
2387
|
+
const event = new FakeEvent_default("abort", {
|
|
2388
|
+
bubbles: true,
|
|
2389
|
+
cancelable: false
|
|
2390
|
+
});
|
|
2391
|
+
event.eventPath = [this.db];
|
|
2392
|
+
this.dispatchEvent(event);
|
|
2393
|
+
if (isUpgradeTransaction) {
|
|
2394
|
+
const request = this._openRequest;
|
|
2395
|
+
request.transaction = null;
|
|
2396
|
+
request.result = undefined;
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
this._state = "finished";
|
|
2400
|
+
}
|
|
2401
|
+
abort() {
|
|
2402
|
+
if (this._state === "committing" || this._state === "finished") {
|
|
2403
|
+
throw new InvalidStateError;
|
|
2404
|
+
}
|
|
2405
|
+
this._state = "active";
|
|
2406
|
+
this._abort(null);
|
|
2407
|
+
}
|
|
2408
|
+
objectStore(name) {
|
|
2409
|
+
if (this._state !== "active") {
|
|
2410
|
+
throw new InvalidStateError;
|
|
2411
|
+
}
|
|
2412
|
+
const objectStore = this._objectStoresCache.get(name);
|
|
2413
|
+
if (objectStore !== undefined) {
|
|
2414
|
+
return objectStore;
|
|
2415
|
+
}
|
|
2416
|
+
const rawObjectStore = this.db._rawDatabase.rawObjectStores.get(name);
|
|
2417
|
+
if (!this._scope.has(name) || rawObjectStore === undefined) {
|
|
2418
|
+
throw new NotFoundError;
|
|
2419
|
+
}
|
|
2420
|
+
const objectStore2 = new FDBObjectStore_default(this, rawObjectStore);
|
|
2421
|
+
this._objectStoresCache.set(name, objectStore2);
|
|
2422
|
+
return objectStore2;
|
|
2423
|
+
}
|
|
2424
|
+
_execRequestAsync(obj) {
|
|
2425
|
+
const source = obj.source;
|
|
2426
|
+
const operation = obj.operation;
|
|
2427
|
+
let request = Object.hasOwn(obj, "request") ? obj.request : null;
|
|
2428
|
+
if (this._state !== "active") {
|
|
2429
|
+
throw new TransactionInactiveError;
|
|
2430
|
+
}
|
|
2431
|
+
if (!request) {
|
|
2432
|
+
if (!source) {
|
|
2433
|
+
request = new FDBRequest_default;
|
|
2434
|
+
} else {
|
|
2435
|
+
request = new FDBRequest_default;
|
|
2436
|
+
request.source = source;
|
|
2437
|
+
request.transaction = source.transaction;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
this._requests.push({
|
|
2441
|
+
operation,
|
|
2442
|
+
request
|
|
2443
|
+
});
|
|
2444
|
+
return request;
|
|
2445
|
+
}
|
|
2446
|
+
_start() {
|
|
2447
|
+
this._started = true;
|
|
2448
|
+
let operation;
|
|
2449
|
+
let request;
|
|
2450
|
+
while (this._requests.length > 0) {
|
|
2451
|
+
const r = this._requests.shift();
|
|
2452
|
+
if (r && r.request.readyState !== "done") {
|
|
2453
|
+
request = r.request;
|
|
2454
|
+
operation = r.operation;
|
|
2455
|
+
break;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
if (request && operation) {
|
|
2459
|
+
if (!request.source) {
|
|
2460
|
+
operation();
|
|
2461
|
+
} else {
|
|
2462
|
+
let defaultAction;
|
|
2463
|
+
let event;
|
|
2464
|
+
try {
|
|
2465
|
+
const result = operation();
|
|
2466
|
+
request.readyState = "done";
|
|
2467
|
+
request.result = result;
|
|
2468
|
+
request.error = undefined;
|
|
2469
|
+
if (this._state === "inactive") {
|
|
2470
|
+
this._state = "active";
|
|
2471
|
+
}
|
|
2472
|
+
event = new FakeEvent_default("success", {
|
|
2473
|
+
bubbles: false,
|
|
2474
|
+
cancelable: false
|
|
2475
|
+
});
|
|
2476
|
+
} catch (err) {
|
|
2477
|
+
request.readyState = "done";
|
|
2478
|
+
request.result = undefined;
|
|
2479
|
+
request.error = err;
|
|
2480
|
+
if (this._state === "inactive") {
|
|
2481
|
+
this._state = "active";
|
|
2482
|
+
}
|
|
2483
|
+
event = new FakeEvent_default("error", {
|
|
2484
|
+
bubbles: true,
|
|
2485
|
+
cancelable: true
|
|
2486
|
+
});
|
|
2487
|
+
defaultAction = this._abort.bind(this, err.name);
|
|
2488
|
+
}
|
|
2489
|
+
try {
|
|
2490
|
+
event.eventPath = [this.db, this];
|
|
2491
|
+
request.dispatchEvent(event);
|
|
2492
|
+
} catch (_err) {
|
|
2493
|
+
if (this._state === "active") {
|
|
2494
|
+
this._abort("AbortError");
|
|
2495
|
+
defaultAction = undefined;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
if (!event.canceled) {
|
|
2499
|
+
if (defaultAction) {
|
|
2500
|
+
defaultAction();
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
queueTask(this._start.bind(this));
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
if (this._state !== "finished") {
|
|
2508
|
+
this._state = "finished";
|
|
2509
|
+
if (!this.error) {
|
|
2510
|
+
const event = new FakeEvent_default("complete");
|
|
2511
|
+
this.dispatchEvent(event);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
commit() {
|
|
2516
|
+
if (this._state !== "active") {
|
|
2517
|
+
throw new InvalidStateError;
|
|
2518
|
+
}
|
|
2519
|
+
this._state = "committing";
|
|
2520
|
+
}
|
|
2521
|
+
get [Symbol.toStringTag]() {
|
|
2522
|
+
return "IDBTransaction";
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
FDBTransaction_default = FDBTransaction;
|
|
2526
|
+
});
|
|
2527
|
+
|
|
2528
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/KeyGenerator.js
|
|
2529
|
+
class KeyGenerator {
|
|
2530
|
+
num = 0;
|
|
2531
|
+
next() {
|
|
2532
|
+
if (this.num >= MAX_KEY) {
|
|
2533
|
+
throw new ConstraintError;
|
|
2534
|
+
}
|
|
2535
|
+
this.num += 1;
|
|
2536
|
+
return this.num;
|
|
2537
|
+
}
|
|
2538
|
+
setIfLarger(num) {
|
|
2539
|
+
const value = Math.floor(Math.min(num, MAX_KEY)) - 1;
|
|
2540
|
+
if (value >= this.num) {
|
|
2541
|
+
this.num = value + 1;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
var MAX_KEY = 9007199254740992, KeyGenerator_default;
|
|
2546
|
+
var init_KeyGenerator = __esm(() => {
|
|
2547
|
+
init_errors();
|
|
2548
|
+
KeyGenerator_default = KeyGenerator;
|
|
2549
|
+
});
|
|
2550
|
+
|
|
2551
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/ObjectStore.js
|
|
2552
|
+
class ObjectStore {
|
|
2553
|
+
deleted = false;
|
|
2554
|
+
records = new RecordStore_default(true);
|
|
2555
|
+
rawIndexes = new Map;
|
|
2556
|
+
constructor(rawDatabase, name, keyPath, autoIncrement) {
|
|
2557
|
+
this.rawDatabase = rawDatabase;
|
|
2558
|
+
this.keyGenerator = autoIncrement === true ? new KeyGenerator_default : null;
|
|
2559
|
+
this.deleted = false;
|
|
2560
|
+
this.name = name;
|
|
2561
|
+
this.keyPath = keyPath;
|
|
2562
|
+
this.autoIncrement = autoIncrement;
|
|
2563
|
+
}
|
|
2564
|
+
getKey(key) {
|
|
2565
|
+
const record = this.records.get(key);
|
|
2566
|
+
return record !== undefined ? structuredClone(record.key) : undefined;
|
|
2567
|
+
}
|
|
2568
|
+
getAllKeys(range, count, direction) {
|
|
2569
|
+
if (count === undefined || count === 0) {
|
|
2570
|
+
count = Infinity;
|
|
2571
|
+
}
|
|
2572
|
+
const records = [];
|
|
2573
|
+
for (const record of this.records.values(range, direction)) {
|
|
2574
|
+
records.push(structuredClone(record.key));
|
|
2575
|
+
if (records.length >= count) {
|
|
2576
|
+
break;
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
return records;
|
|
2580
|
+
}
|
|
2581
|
+
getValue(key) {
|
|
2582
|
+
const record = this.records.get(key);
|
|
2583
|
+
return record !== undefined ? structuredClone(record.value) : undefined;
|
|
2584
|
+
}
|
|
2585
|
+
getAllValues(range, count, direction) {
|
|
2586
|
+
if (count === undefined || count === 0) {
|
|
2587
|
+
count = Infinity;
|
|
2588
|
+
}
|
|
2589
|
+
const records = [];
|
|
2590
|
+
for (const record of this.records.values(range, direction)) {
|
|
2591
|
+
records.push(structuredClone(record.value));
|
|
2592
|
+
if (records.length >= count) {
|
|
2593
|
+
break;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
return records;
|
|
2597
|
+
}
|
|
2598
|
+
getAllRecords(range, count, direction) {
|
|
2599
|
+
if (count === undefined || count === 0) {
|
|
2600
|
+
count = Infinity;
|
|
2601
|
+
}
|
|
2602
|
+
const records = [];
|
|
2603
|
+
for (const record of this.records.values(range, direction)) {
|
|
2604
|
+
records.push(new FDBRecord_default(structuredClone(record.key), structuredClone(record.key), structuredClone(record.value)));
|
|
2605
|
+
if (records.length >= count) {
|
|
2606
|
+
break;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
return records;
|
|
2610
|
+
}
|
|
2611
|
+
storeRecord(newRecord, noOverwrite, rollbackLog) {
|
|
2612
|
+
if (this.keyPath !== null) {
|
|
2613
|
+
const key = extractKey_default(this.keyPath, newRecord.value).key;
|
|
2614
|
+
if (key !== undefined) {
|
|
2615
|
+
newRecord.key = key;
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
const rollbackLogForThisOperation = [];
|
|
2619
|
+
if (this.keyGenerator !== null && newRecord.key === undefined) {
|
|
2620
|
+
let rolledBack2 = false;
|
|
2621
|
+
const keyGeneratorBefore = this.keyGenerator.num;
|
|
2622
|
+
const rollbackKeyGenerator = () => {
|
|
2623
|
+
if (rolledBack2) {
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
rolledBack2 = true;
|
|
2627
|
+
if (this.keyGenerator) {
|
|
2628
|
+
this.keyGenerator.num = keyGeneratorBefore;
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
rollbackLogForThisOperation.push(rollbackKeyGenerator);
|
|
2632
|
+
if (rollbackLog) {
|
|
2633
|
+
rollbackLog.push(rollbackKeyGenerator);
|
|
2634
|
+
}
|
|
2635
|
+
newRecord.key = this.keyGenerator.next();
|
|
2636
|
+
if (this.keyPath !== null) {
|
|
2637
|
+
if (Array.isArray(this.keyPath)) {
|
|
2638
|
+
throw new Error("Cannot have an array key path in an object store with a key generator");
|
|
2639
|
+
}
|
|
2640
|
+
let remainingKeyPath = this.keyPath;
|
|
2641
|
+
let object = newRecord.value;
|
|
2642
|
+
let identifier;
|
|
2643
|
+
let i = 0;
|
|
2644
|
+
while (i >= 0) {
|
|
2645
|
+
if (typeof object !== "object") {
|
|
2646
|
+
throw new DataError;
|
|
2647
|
+
}
|
|
2648
|
+
i = remainingKeyPath.indexOf(".");
|
|
2649
|
+
if (i >= 0) {
|
|
2650
|
+
identifier = remainingKeyPath.slice(0, i);
|
|
2651
|
+
remainingKeyPath = remainingKeyPath.slice(i + 1);
|
|
2652
|
+
if (!Object.hasOwn(object, identifier)) {
|
|
2653
|
+
Object.defineProperty(object, identifier, {
|
|
2654
|
+
configurable: true,
|
|
2655
|
+
enumerable: true,
|
|
2656
|
+
writable: true,
|
|
2657
|
+
value: {}
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
object = object[identifier];
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
identifier = remainingKeyPath;
|
|
2664
|
+
Object.defineProperty(object, identifier, {
|
|
2665
|
+
configurable: true,
|
|
2666
|
+
enumerable: true,
|
|
2667
|
+
writable: true,
|
|
2668
|
+
value: newRecord.key
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
} else if (this.keyGenerator !== null && typeof newRecord.key === "number") {
|
|
2672
|
+
this.keyGenerator.setIfLarger(newRecord.key);
|
|
2673
|
+
}
|
|
2674
|
+
const existingRecord = this.records.put(newRecord, noOverwrite);
|
|
2675
|
+
let rolledBack = false;
|
|
2676
|
+
const rollbackStoreRecord = () => {
|
|
2677
|
+
if (rolledBack) {
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
rolledBack = true;
|
|
2681
|
+
if (existingRecord) {
|
|
2682
|
+
this.storeRecord(existingRecord, false);
|
|
2683
|
+
} else {
|
|
2684
|
+
this.deleteRecord(newRecord.key);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
rollbackLogForThisOperation.push(rollbackStoreRecord);
|
|
2688
|
+
if (rollbackLog) {
|
|
2689
|
+
rollbackLog.push(rollbackStoreRecord);
|
|
2690
|
+
}
|
|
2691
|
+
if (existingRecord) {
|
|
2692
|
+
for (const rawIndex of this.rawIndexes.values()) {
|
|
2693
|
+
rawIndex.records.deleteByValue(newRecord.key);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
try {
|
|
2697
|
+
for (const rawIndex of this.rawIndexes.values()) {
|
|
2698
|
+
if (rawIndex.initialized) {
|
|
2699
|
+
rawIndex.storeRecord(newRecord);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
} catch (err) {
|
|
2703
|
+
if (err.name === "ConstraintError") {
|
|
2704
|
+
for (const rollback of rollbackLogForThisOperation) {
|
|
2705
|
+
rollback();
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
throw err;
|
|
2709
|
+
}
|
|
2710
|
+
return newRecord.key;
|
|
2711
|
+
}
|
|
2712
|
+
deleteRecord(key, rollbackLog) {
|
|
2713
|
+
const deletedRecords = this.records.delete(key);
|
|
2714
|
+
if (rollbackLog) {
|
|
2715
|
+
for (const record of deletedRecords) {
|
|
2716
|
+
rollbackLog.push(() => {
|
|
2717
|
+
this.storeRecord(record, true);
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
for (const rawIndex of this.rawIndexes.values()) {
|
|
2722
|
+
rawIndex.records.deleteByValue(key);
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
clear(rollbackLog) {
|
|
2726
|
+
const deletedRecords = this.records.clear();
|
|
2727
|
+
if (rollbackLog) {
|
|
2728
|
+
for (const record of deletedRecords) {
|
|
2729
|
+
rollbackLog.push(() => {
|
|
2730
|
+
this.storeRecord(record, true);
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
for (const rawIndex of this.rawIndexes.values()) {
|
|
2735
|
+
rawIndex.records.clear();
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
count(range) {
|
|
2739
|
+
if (range === undefined || range.lower === undefined && range.upper === undefined) {
|
|
2740
|
+
return this.records.size();
|
|
2741
|
+
}
|
|
2742
|
+
let count = 0;
|
|
2743
|
+
for (const record of this.records.values(range)) {
|
|
2744
|
+
count += 1;
|
|
2745
|
+
}
|
|
2746
|
+
return count;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
var ObjectStore_default;
|
|
2750
|
+
var init_ObjectStore = __esm(() => {
|
|
2751
|
+
init_FDBRecord();
|
|
2752
|
+
init_errors();
|
|
2753
|
+
init_extractKey();
|
|
2754
|
+
init_KeyGenerator();
|
|
2755
|
+
init_RecordStore();
|
|
2756
|
+
ObjectStore_default = ObjectStore;
|
|
2757
|
+
});
|
|
2758
|
+
|
|
2759
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/closeConnection.js
|
|
2760
|
+
var closeConnection = (connection, forced = false) => {
|
|
2761
|
+
connection._closePending = true;
|
|
2762
|
+
const transactionsComplete = connection._rawDatabase.transactions.every((transaction) => {
|
|
2763
|
+
return transaction._state === "finished";
|
|
2764
|
+
});
|
|
2765
|
+
if (transactionsComplete) {
|
|
2766
|
+
connection._closed = true;
|
|
2767
|
+
connection._rawDatabase.connections = connection._rawDatabase.connections.filter((otherConnection) => {
|
|
2768
|
+
return connection !== otherConnection;
|
|
2769
|
+
});
|
|
2770
|
+
if (forced) {
|
|
2771
|
+
const event = new FakeEvent_default("close", {
|
|
2772
|
+
bubbles: false,
|
|
2773
|
+
cancelable: false
|
|
2774
|
+
});
|
|
2775
|
+
event.eventPath = [];
|
|
2776
|
+
connection.dispatchEvent(event);
|
|
2777
|
+
}
|
|
2778
|
+
} else {
|
|
2779
|
+
queueTask(() => {
|
|
2780
|
+
closeConnection(connection, forced);
|
|
2781
|
+
});
|
|
2782
|
+
}
|
|
2783
|
+
}, closeConnection_default;
|
|
2784
|
+
var init_closeConnection = __esm(() => {
|
|
2785
|
+
init_FakeEvent();
|
|
2786
|
+
init_scheduling();
|
|
2787
|
+
closeConnection_default = closeConnection;
|
|
2788
|
+
});
|
|
2789
|
+
|
|
2790
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBDatabase.js
|
|
2791
|
+
var confirmActiveVersionchangeTransaction = (database) => {
|
|
2792
|
+
let transaction;
|
|
2793
|
+
if (database._runningVersionchangeTransaction) {
|
|
2794
|
+
transaction = database._rawDatabase.transactions.findLast((tx) => {
|
|
2795
|
+
return tx.mode === "versionchange";
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
if (!transaction) {
|
|
2799
|
+
throw new InvalidStateError;
|
|
2800
|
+
}
|
|
2801
|
+
if (transaction._state !== "active") {
|
|
2802
|
+
throw new TransactionInactiveError;
|
|
2803
|
+
}
|
|
2804
|
+
return transaction;
|
|
2805
|
+
}, FDBDatabase, FDBDatabase_default;
|
|
2806
|
+
var init_FDBDatabase = __esm(() => {
|
|
2807
|
+
init_FDBTransaction();
|
|
2808
|
+
init_errors();
|
|
2809
|
+
init_FakeDOMStringList();
|
|
2810
|
+
init_FakeEventTarget();
|
|
2811
|
+
init_ObjectStore();
|
|
2812
|
+
init_validateKeyPath();
|
|
2813
|
+
init_closeConnection();
|
|
2814
|
+
FDBDatabase = class FDBDatabase extends FakeEventTarget_default {
|
|
2815
|
+
_closePending = false;
|
|
2816
|
+
_closed = false;
|
|
2817
|
+
_runningVersionchangeTransaction = false;
|
|
2818
|
+
constructor(rawDatabase) {
|
|
2819
|
+
super();
|
|
2820
|
+
this._rawDatabase = rawDatabase;
|
|
2821
|
+
this._rawDatabase.connections.push(this);
|
|
2822
|
+
this.name = rawDatabase.name;
|
|
2823
|
+
this.version = rawDatabase.version;
|
|
2824
|
+
this.objectStoreNames = new FakeDOMStringList_default(...Array.from(rawDatabase.rawObjectStores.keys()).sort());
|
|
2825
|
+
}
|
|
2826
|
+
createObjectStore(name, options = {}) {
|
|
2827
|
+
if (name === undefined) {
|
|
2828
|
+
throw new TypeError;
|
|
2829
|
+
}
|
|
2830
|
+
const transaction = confirmActiveVersionchangeTransaction(this);
|
|
2831
|
+
const keyPath = options !== null && options.keyPath !== undefined ? options.keyPath : null;
|
|
2832
|
+
const autoIncrement = options !== null && options.autoIncrement !== undefined ? options.autoIncrement : false;
|
|
2833
|
+
if (keyPath !== null) {
|
|
2834
|
+
validateKeyPath_default(keyPath);
|
|
2835
|
+
}
|
|
2836
|
+
if (this._rawDatabase.rawObjectStores.has(name)) {
|
|
2837
|
+
throw new ConstraintError;
|
|
2838
|
+
}
|
|
2839
|
+
if (autoIncrement && (keyPath === "" || Array.isArray(keyPath))) {
|
|
2840
|
+
throw new InvalidAccessError;
|
|
2841
|
+
}
|
|
2842
|
+
const objectStoreNames = [...this.objectStoreNames];
|
|
2843
|
+
const transactionObjectStoreNames = [...transaction.objectStoreNames];
|
|
2844
|
+
const rawObjectStore = new ObjectStore_default(this._rawDatabase, name, keyPath, autoIncrement);
|
|
2845
|
+
this.objectStoreNames._push(name);
|
|
2846
|
+
this.objectStoreNames._sort();
|
|
2847
|
+
transaction._scope.add(name);
|
|
2848
|
+
transaction._createdObjectStores.add(rawObjectStore);
|
|
2849
|
+
this._rawDatabase.rawObjectStores.set(name, rawObjectStore);
|
|
2850
|
+
transaction.objectStoreNames = new FakeDOMStringList_default(...this.objectStoreNames);
|
|
2851
|
+
transaction._rollbackLog.push(() => {
|
|
2852
|
+
rawObjectStore.deleted = true;
|
|
2853
|
+
this.objectStoreNames = new FakeDOMStringList_default(...objectStoreNames);
|
|
2854
|
+
transaction.objectStoreNames = new FakeDOMStringList_default(...transactionObjectStoreNames);
|
|
2855
|
+
transaction._scope.delete(rawObjectStore.name);
|
|
2856
|
+
this._rawDatabase.rawObjectStores.delete(rawObjectStore.name);
|
|
2857
|
+
});
|
|
2858
|
+
return transaction.objectStore(name);
|
|
2859
|
+
}
|
|
2860
|
+
deleteObjectStore(name) {
|
|
2861
|
+
if (name === undefined) {
|
|
2862
|
+
throw new TypeError;
|
|
2863
|
+
}
|
|
2864
|
+
const transaction = confirmActiveVersionchangeTransaction(this);
|
|
2865
|
+
const store = this._rawDatabase.rawObjectStores.get(name);
|
|
2866
|
+
if (store === undefined) {
|
|
2867
|
+
throw new NotFoundError;
|
|
2868
|
+
}
|
|
2869
|
+
this.objectStoreNames = new FakeDOMStringList_default(...Array.from(this.objectStoreNames).filter((objectStoreName) => {
|
|
2870
|
+
return objectStoreName !== name;
|
|
2871
|
+
}));
|
|
2872
|
+
transaction.objectStoreNames = new FakeDOMStringList_default(...this.objectStoreNames);
|
|
2873
|
+
const objectStore = transaction._objectStoresCache.get(name);
|
|
2874
|
+
let prevIndexNames;
|
|
2875
|
+
if (objectStore) {
|
|
2876
|
+
prevIndexNames = [...objectStore.indexNames];
|
|
2877
|
+
objectStore.indexNames = new FakeDOMStringList_default;
|
|
2878
|
+
}
|
|
2879
|
+
transaction._rollbackLog.push(() => {
|
|
2880
|
+
store.deleted = false;
|
|
2881
|
+
this._rawDatabase.rawObjectStores.set(store.name, store);
|
|
2882
|
+
this.objectStoreNames._push(store.name);
|
|
2883
|
+
transaction.objectStoreNames._push(store.name);
|
|
2884
|
+
this.objectStoreNames._sort();
|
|
2885
|
+
if (objectStore && prevIndexNames) {
|
|
2886
|
+
objectStore.indexNames = new FakeDOMStringList_default(...prevIndexNames);
|
|
2887
|
+
}
|
|
2888
|
+
});
|
|
2889
|
+
store.deleted = true;
|
|
2890
|
+
this._rawDatabase.rawObjectStores.delete(name);
|
|
2891
|
+
transaction._objectStoresCache.delete(name);
|
|
2892
|
+
}
|
|
2893
|
+
transaction(storeNames, mode, options) {
|
|
2894
|
+
mode = mode !== undefined ? mode : "readonly";
|
|
2895
|
+
if (mode !== "readonly" && mode !== "readwrite" && mode !== "versionchange") {
|
|
2896
|
+
throw new TypeError("Invalid mode: " + mode);
|
|
2897
|
+
}
|
|
2898
|
+
const hasActiveVersionchange = this._rawDatabase.transactions.some((transaction) => {
|
|
2899
|
+
return transaction._state === "active" && transaction.mode === "versionchange" && transaction.db === this;
|
|
2900
|
+
});
|
|
2901
|
+
if (hasActiveVersionchange) {
|
|
2902
|
+
throw new InvalidStateError;
|
|
2903
|
+
}
|
|
2904
|
+
if (this._closePending) {
|
|
2905
|
+
throw new InvalidStateError;
|
|
2906
|
+
}
|
|
2907
|
+
if (!Array.isArray(storeNames)) {
|
|
2908
|
+
storeNames = [storeNames];
|
|
2909
|
+
}
|
|
2910
|
+
if (storeNames.length === 0 && mode !== "versionchange") {
|
|
2911
|
+
throw new InvalidAccessError;
|
|
2912
|
+
}
|
|
2913
|
+
for (const storeName of storeNames) {
|
|
2914
|
+
if (!this.objectStoreNames.contains(storeName)) {
|
|
2915
|
+
throw new NotFoundError("No objectStore named " + storeName + " in this database");
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
const durability = options?.durability ?? "default";
|
|
2919
|
+
if (durability !== "default" && durability !== "strict" && durability !== "relaxed") {
|
|
2920
|
+
throw new TypeError(`'${durability}' (value of 'durability' member of IDBTransactionOptions) ` + `is not a valid value for enumeration IDBTransactionDurability`);
|
|
2921
|
+
}
|
|
2922
|
+
const tx = new FDBTransaction_default(storeNames, mode, durability, this);
|
|
2923
|
+
this._rawDatabase.transactions.push(tx);
|
|
2924
|
+
this._rawDatabase.processTransactions();
|
|
2925
|
+
return tx;
|
|
2926
|
+
}
|
|
2927
|
+
close() {
|
|
2928
|
+
closeConnection_default(this);
|
|
2929
|
+
}
|
|
2930
|
+
get [Symbol.toStringTag]() {
|
|
2931
|
+
return "IDBDatabase";
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
FDBDatabase_default = FDBDatabase;
|
|
2935
|
+
});
|
|
2936
|
+
|
|
2937
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBOpenDBRequest.js
|
|
2938
|
+
var FDBOpenDBRequest, FDBOpenDBRequest_default;
|
|
2939
|
+
var init_FDBOpenDBRequest = __esm(() => {
|
|
2940
|
+
init_FDBRequest();
|
|
2941
|
+
FDBOpenDBRequest = class FDBOpenDBRequest extends FDBRequest_default {
|
|
2942
|
+
onupgradeneeded = null;
|
|
2943
|
+
onblocked = null;
|
|
2944
|
+
get [Symbol.toStringTag]() {
|
|
2945
|
+
return "IDBOpenDBRequest";
|
|
2946
|
+
}
|
|
2947
|
+
};
|
|
2948
|
+
FDBOpenDBRequest_default = FDBOpenDBRequest;
|
|
2949
|
+
});
|
|
2950
|
+
|
|
2951
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBVersionChangeEvent.js
|
|
2952
|
+
var FDBVersionChangeEvent, FDBVersionChangeEvent_default;
|
|
2953
|
+
var init_FDBVersionChangeEvent = __esm(() => {
|
|
2954
|
+
init_FakeEvent();
|
|
2955
|
+
FDBVersionChangeEvent = class FDBVersionChangeEvent extends FakeEvent_default {
|
|
2956
|
+
constructor(type, parameters = {}) {
|
|
2957
|
+
super(type);
|
|
2958
|
+
this.newVersion = parameters.newVersion !== undefined ? parameters.newVersion : null;
|
|
2959
|
+
this.oldVersion = parameters.oldVersion !== undefined ? parameters.oldVersion : 0;
|
|
2960
|
+
}
|
|
2961
|
+
get [Symbol.toStringTag]() {
|
|
2962
|
+
return "IDBVersionChangeEvent";
|
|
2963
|
+
}
|
|
2964
|
+
};
|
|
2965
|
+
FDBVersionChangeEvent_default = FDBVersionChangeEvent;
|
|
2966
|
+
});
|
|
2967
|
+
|
|
2968
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/intersection.js
|
|
2969
|
+
function intersection(set1, set2) {
|
|
2970
|
+
if ("intersection" in set1) {
|
|
2971
|
+
return set1.intersection(set2);
|
|
2972
|
+
}
|
|
2973
|
+
return new Set([...set1].filter((item) => set2.has(item)));
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/Database.js
|
|
2977
|
+
class Database {
|
|
2978
|
+
transactions = [];
|
|
2979
|
+
rawObjectStores = new Map;
|
|
2980
|
+
connections = [];
|
|
2981
|
+
constructor(name, version) {
|
|
2982
|
+
this.name = name;
|
|
2983
|
+
this.version = version;
|
|
2984
|
+
this.processTransactions = this.processTransactions.bind(this);
|
|
2985
|
+
}
|
|
2986
|
+
processTransactions() {
|
|
2987
|
+
queueTask(() => {
|
|
2988
|
+
const running = this.transactions.filter((transaction) => transaction._started && transaction._state !== "finished");
|
|
2989
|
+
const waiting = this.transactions.filter((transaction) => !transaction._started && transaction._state !== "finished");
|
|
2990
|
+
const next = waiting.find((transaction, i) => {
|
|
2991
|
+
const anyRunning = running.some((other) => !(transaction.mode === "readonly" && other.mode === "readonly") && intersection(other._scope, transaction._scope).size > 0);
|
|
2992
|
+
if (anyRunning) {
|
|
2993
|
+
return false;
|
|
2994
|
+
}
|
|
2995
|
+
const anyWaiting = waiting.slice(0, i).some((other) => intersection(other._scope, transaction._scope).size > 0);
|
|
2996
|
+
return !anyWaiting;
|
|
2997
|
+
});
|
|
2998
|
+
if (next) {
|
|
2999
|
+
next.addEventListener("complete", this.processTransactions);
|
|
3000
|
+
next.addEventListener("abort", this.processTransactions);
|
|
3001
|
+
next._start();
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
var Database_default;
|
|
3007
|
+
var init_Database = __esm(() => {
|
|
3008
|
+
init_scheduling();
|
|
3009
|
+
Database_default = Database;
|
|
3010
|
+
});
|
|
3011
|
+
|
|
3012
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/lib/validateRequiredArguments.js
|
|
3013
|
+
function validateRequiredArguments(numArguments, expectedNumArguments, methodName) {
|
|
3014
|
+
if (numArguments < expectedNumArguments) {
|
|
3015
|
+
throw new TypeError(`${methodName}: At least ${expectedNumArguments} ${expectedNumArguments === 1 ? "argument" : "arguments"} ` + `required, but only ${arguments.length} passed`);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/FDBFactory.js
|
|
3020
|
+
var runTaskInConnectionQueue = (connectionQueues, name, task) => {
|
|
3021
|
+
const queue = connectionQueues.get(name) ?? Promise.resolve();
|
|
3022
|
+
connectionQueues.set(name, queue.then(task));
|
|
3023
|
+
}, waitForOthersClosedDelete = (databases, name, openDatabases, cb) => {
|
|
3024
|
+
const anyOpen = openDatabases.some((openDatabase2) => {
|
|
3025
|
+
return !openDatabase2._closed && !openDatabase2._closePending;
|
|
3026
|
+
});
|
|
3027
|
+
if (anyOpen) {
|
|
3028
|
+
queueTask(() => waitForOthersClosedDelete(databases, name, openDatabases, cb));
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
databases.delete(name);
|
|
3032
|
+
cb(null);
|
|
3033
|
+
}, deleteDatabase = (databases, connectionQueues, name, request, cb) => {
|
|
3034
|
+
const deleteDBTask = () => {
|
|
3035
|
+
return new Promise((resolve) => {
|
|
3036
|
+
const db = databases.get(name);
|
|
3037
|
+
const oldVersion = db !== undefined ? db.version : 0;
|
|
3038
|
+
const onComplete = (err) => {
|
|
3039
|
+
try {
|
|
3040
|
+
if (err) {
|
|
3041
|
+
cb(err);
|
|
3042
|
+
} else {
|
|
3043
|
+
cb(null, oldVersion);
|
|
3044
|
+
}
|
|
3045
|
+
} finally {
|
|
3046
|
+
resolve();
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
try {
|
|
3050
|
+
const db2 = databases.get(name);
|
|
3051
|
+
if (db2 === undefined) {
|
|
3052
|
+
onComplete(null);
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
const openConnections = db2.connections.filter((connection) => {
|
|
3056
|
+
return !connection._closed;
|
|
3057
|
+
});
|
|
3058
|
+
for (const openDatabase2 of openConnections) {
|
|
3059
|
+
if (!openDatabase2._closePending) {
|
|
3060
|
+
queueTask(() => {
|
|
3061
|
+
const event = new FDBVersionChangeEvent_default("versionchange", {
|
|
3062
|
+
newVersion: null,
|
|
3063
|
+
oldVersion: db2.version
|
|
3064
|
+
});
|
|
3065
|
+
openDatabase2.dispatchEvent(event);
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
queueTask(() => {
|
|
3070
|
+
const anyOpen = openConnections.some((openDatabase3) => {
|
|
3071
|
+
return !openDatabase3._closed && !openDatabase3._closePending;
|
|
3072
|
+
});
|
|
3073
|
+
if (anyOpen) {
|
|
3074
|
+
queueTask(() => {
|
|
3075
|
+
const event = new FDBVersionChangeEvent_default("blocked", {
|
|
3076
|
+
newVersion: null,
|
|
3077
|
+
oldVersion: db2.version
|
|
3078
|
+
});
|
|
3079
|
+
request.dispatchEvent(event);
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
waitForOthersClosedDelete(databases, name, openConnections, onComplete);
|
|
3083
|
+
});
|
|
3084
|
+
} catch (err) {
|
|
3085
|
+
onComplete(err);
|
|
3086
|
+
}
|
|
3087
|
+
});
|
|
3088
|
+
};
|
|
3089
|
+
runTaskInConnectionQueue(connectionQueues, name, deleteDBTask);
|
|
3090
|
+
}, runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
3091
|
+
connection._runningVersionchangeTransaction = true;
|
|
3092
|
+
const oldVersion = connection._oldVersion = connection.version;
|
|
3093
|
+
const openConnections = connection._rawDatabase.connections.filter((otherDatabase) => {
|
|
3094
|
+
return connection !== otherDatabase;
|
|
3095
|
+
});
|
|
3096
|
+
for (const openDatabase2 of openConnections) {
|
|
3097
|
+
if (!openDatabase2._closed && !openDatabase2._closePending) {
|
|
3098
|
+
queueTask(() => {
|
|
3099
|
+
const event = new FDBVersionChangeEvent_default("versionchange", {
|
|
3100
|
+
newVersion: version,
|
|
3101
|
+
oldVersion
|
|
3102
|
+
});
|
|
3103
|
+
openDatabase2.dispatchEvent(event);
|
|
3104
|
+
});
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
queueTask(() => {
|
|
3108
|
+
const anyOpen = openConnections.some((openDatabase3) => {
|
|
3109
|
+
return !openDatabase3._closed && !openDatabase3._closePending;
|
|
3110
|
+
});
|
|
3111
|
+
if (anyOpen) {
|
|
3112
|
+
queueTask(() => {
|
|
3113
|
+
const event = new FDBVersionChangeEvent_default("blocked", {
|
|
3114
|
+
newVersion: version,
|
|
3115
|
+
oldVersion
|
|
3116
|
+
});
|
|
3117
|
+
request.dispatchEvent(event);
|
|
3118
|
+
});
|
|
3119
|
+
}
|
|
3120
|
+
const waitForOthersClosed = () => {
|
|
3121
|
+
const anyOpen2 = openConnections.some((openDatabase2) => {
|
|
3122
|
+
return !openDatabase2._closed && !openDatabase2._closePending;
|
|
3123
|
+
});
|
|
3124
|
+
if (anyOpen2) {
|
|
3125
|
+
queueTask(waitForOthersClosed);
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
connection._rawDatabase.version = version;
|
|
3129
|
+
connection.version = version;
|
|
3130
|
+
const transaction = connection.transaction(Array.from(connection.objectStoreNames), "versionchange");
|
|
3131
|
+
transaction._openRequest = request;
|
|
3132
|
+
request.result = connection;
|
|
3133
|
+
request.readyState = "done";
|
|
3134
|
+
request.transaction = transaction;
|
|
3135
|
+
transaction._rollbackLog.push(() => {
|
|
3136
|
+
connection._rawDatabase.version = oldVersion;
|
|
3137
|
+
connection.version = oldVersion;
|
|
3138
|
+
});
|
|
3139
|
+
transaction._state = "active";
|
|
3140
|
+
const event = new FDBVersionChangeEvent_default("upgradeneeded", {
|
|
3141
|
+
newVersion: version,
|
|
3142
|
+
oldVersion
|
|
3143
|
+
});
|
|
3144
|
+
let didThrow = false;
|
|
3145
|
+
try {
|
|
3146
|
+
request.dispatchEvent(event);
|
|
3147
|
+
} catch (_err) {
|
|
3148
|
+
didThrow = true;
|
|
3149
|
+
}
|
|
3150
|
+
const concludeUpgrade = () => {
|
|
3151
|
+
if (transaction._state === "active") {
|
|
3152
|
+
transaction._state = "inactive";
|
|
3153
|
+
if (didThrow) {
|
|
3154
|
+
transaction._abort("AbortError");
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
};
|
|
3158
|
+
if (didThrow) {
|
|
3159
|
+
concludeUpgrade();
|
|
3160
|
+
} else {
|
|
3161
|
+
queueTask(concludeUpgrade);
|
|
3162
|
+
}
|
|
3163
|
+
transaction._prioritizedListeners.set("error", () => {
|
|
3164
|
+
connection._runningVersionchangeTransaction = false;
|
|
3165
|
+
connection._oldVersion = undefined;
|
|
3166
|
+
});
|
|
3167
|
+
transaction._prioritizedListeners.set("abort", () => {
|
|
3168
|
+
connection._runningVersionchangeTransaction = false;
|
|
3169
|
+
connection._oldVersion = undefined;
|
|
3170
|
+
queueTask(() => {
|
|
3171
|
+
request.transaction = null;
|
|
3172
|
+
cb(new AbortError);
|
|
3173
|
+
});
|
|
3174
|
+
});
|
|
3175
|
+
transaction._prioritizedListeners.set("complete", () => {
|
|
3176
|
+
connection._runningVersionchangeTransaction = false;
|
|
3177
|
+
connection._oldVersion = undefined;
|
|
3178
|
+
queueTask(() => {
|
|
3179
|
+
request.transaction = null;
|
|
3180
|
+
if (connection._closePending) {
|
|
3181
|
+
cb(new AbortError);
|
|
3182
|
+
} else {
|
|
3183
|
+
cb(null);
|
|
3184
|
+
}
|
|
3185
|
+
});
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
waitForOthersClosed();
|
|
3189
|
+
});
|
|
3190
|
+
}, openDatabase = (databases, connectionQueues, name, version, request, cb) => {
|
|
3191
|
+
const openDBTask = () => {
|
|
3192
|
+
return new Promise((resolve) => {
|
|
3193
|
+
const onComplete = (err) => {
|
|
3194
|
+
try {
|
|
3195
|
+
if (err) {
|
|
3196
|
+
cb(err);
|
|
3197
|
+
} else {
|
|
3198
|
+
cb(null, connection);
|
|
3199
|
+
}
|
|
3200
|
+
} finally {
|
|
3201
|
+
resolve();
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
let db = databases.get(name);
|
|
3205
|
+
if (db === undefined) {
|
|
3206
|
+
db = new Database_default(name, 0);
|
|
3207
|
+
databases.set(name, db);
|
|
3208
|
+
}
|
|
3209
|
+
if (version === undefined) {
|
|
3210
|
+
version = db.version !== 0 ? db.version : 1;
|
|
3211
|
+
}
|
|
3212
|
+
if (db.version > version) {
|
|
3213
|
+
return onComplete(new VersionError);
|
|
3214
|
+
}
|
|
3215
|
+
const connection = new FDBDatabase_default(db);
|
|
3216
|
+
if (db.version < version) {
|
|
3217
|
+
runVersionchangeTransaction(connection, version, request, (err) => {
|
|
3218
|
+
onComplete(err);
|
|
3219
|
+
});
|
|
3220
|
+
} else {
|
|
3221
|
+
onComplete(null);
|
|
3222
|
+
}
|
|
3223
|
+
});
|
|
3224
|
+
};
|
|
3225
|
+
runTaskInConnectionQueue(connectionQueues, name, openDBTask);
|
|
3226
|
+
}, FDBFactory, FDBFactory_default;
|
|
3227
|
+
var init_FDBFactory = __esm(() => {
|
|
3228
|
+
init_FDBDatabase();
|
|
3229
|
+
init_FDBOpenDBRequest();
|
|
3230
|
+
init_FDBVersionChangeEvent();
|
|
3231
|
+
init_cmp();
|
|
3232
|
+
init_Database();
|
|
3233
|
+
init_enforceRange();
|
|
3234
|
+
init_errors();
|
|
3235
|
+
init_FakeEvent();
|
|
3236
|
+
init_scheduling();
|
|
3237
|
+
FDBFactory = class FDBFactory {
|
|
3238
|
+
_databases = new Map;
|
|
3239
|
+
_connectionQueues = new Map;
|
|
3240
|
+
cmp(first, second) {
|
|
3241
|
+
validateRequiredArguments(arguments.length, 2, "IDBFactory.cmp");
|
|
3242
|
+
return cmp_default(first, second);
|
|
3243
|
+
}
|
|
3244
|
+
deleteDatabase(name) {
|
|
3245
|
+
validateRequiredArguments(arguments.length, 1, "IDBFactory.deleteDatabase");
|
|
3246
|
+
const request = new FDBOpenDBRequest_default;
|
|
3247
|
+
request.source = null;
|
|
3248
|
+
queueTask(() => {
|
|
3249
|
+
deleteDatabase(this._databases, this._connectionQueues, name, request, (err, oldVersion) => {
|
|
3250
|
+
if (err) {
|
|
3251
|
+
request.error = new DOMException(err.message, err.name);
|
|
3252
|
+
request.readyState = "done";
|
|
3253
|
+
const event = new FakeEvent_default("error", {
|
|
3254
|
+
bubbles: true,
|
|
3255
|
+
cancelable: true
|
|
3256
|
+
});
|
|
3257
|
+
event.eventPath = [];
|
|
3258
|
+
request.dispatchEvent(event);
|
|
3259
|
+
return;
|
|
3260
|
+
}
|
|
3261
|
+
request.result = undefined;
|
|
3262
|
+
request.readyState = "done";
|
|
3263
|
+
const event2 = new FDBVersionChangeEvent_default("success", {
|
|
3264
|
+
newVersion: null,
|
|
3265
|
+
oldVersion
|
|
3266
|
+
});
|
|
3267
|
+
request.dispatchEvent(event2);
|
|
3268
|
+
});
|
|
3269
|
+
});
|
|
3270
|
+
return request;
|
|
3271
|
+
}
|
|
3272
|
+
open(name, version) {
|
|
3273
|
+
validateRequiredArguments(arguments.length, 1, "IDBFactory.open");
|
|
3274
|
+
if (arguments.length > 1 && version !== undefined) {
|
|
3275
|
+
version = enforceRange_default(version, "MAX_SAFE_INTEGER");
|
|
3276
|
+
}
|
|
3277
|
+
if (version === 0) {
|
|
3278
|
+
throw new TypeError("Database version cannot be 0");
|
|
3279
|
+
}
|
|
3280
|
+
const request = new FDBOpenDBRequest_default;
|
|
3281
|
+
request.source = null;
|
|
3282
|
+
queueTask(() => {
|
|
3283
|
+
openDatabase(this._databases, this._connectionQueues, name, version, request, (err, connection) => {
|
|
3284
|
+
if (err) {
|
|
3285
|
+
request.result = undefined;
|
|
3286
|
+
request.readyState = "done";
|
|
3287
|
+
request.error = new DOMException(err.message, err.name);
|
|
3288
|
+
const event = new FakeEvent_default("error", {
|
|
3289
|
+
bubbles: true,
|
|
3290
|
+
cancelable: true
|
|
3291
|
+
});
|
|
3292
|
+
event.eventPath = [];
|
|
3293
|
+
request.dispatchEvent(event);
|
|
3294
|
+
return;
|
|
3295
|
+
}
|
|
3296
|
+
request.result = connection;
|
|
3297
|
+
request.readyState = "done";
|
|
3298
|
+
const event2 = new FakeEvent_default("success");
|
|
3299
|
+
event2.eventPath = [];
|
|
3300
|
+
request.dispatchEvent(event2);
|
|
3301
|
+
});
|
|
3302
|
+
});
|
|
3303
|
+
return request;
|
|
3304
|
+
}
|
|
3305
|
+
databases() {
|
|
3306
|
+
return Promise.resolve(Array.from(this._databases.entries(), ([name, database]) => {
|
|
3307
|
+
const activeVersionChangeConnection = database.connections.find((connection) => connection._runningVersionchangeTransaction);
|
|
3308
|
+
const version = activeVersionChangeConnection ? activeVersionChangeConnection._oldVersion : database.version;
|
|
3309
|
+
return {
|
|
3310
|
+
name,
|
|
3311
|
+
version
|
|
3312
|
+
};
|
|
3313
|
+
}).filter(({
|
|
3314
|
+
version
|
|
3315
|
+
}) => {
|
|
3316
|
+
return version > 0;
|
|
3317
|
+
}));
|
|
3318
|
+
}
|
|
3319
|
+
get [Symbol.toStringTag]() {
|
|
3320
|
+
return "IDBFactory";
|
|
3321
|
+
}
|
|
3322
|
+
};
|
|
3323
|
+
FDBFactory_default = FDBFactory;
|
|
3324
|
+
});
|
|
3325
|
+
|
|
3326
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/build/esm/fakeIndexedDB.js
|
|
3327
|
+
var fakeIndexedDB, fakeIndexedDB_default;
|
|
3328
|
+
var init_fakeIndexedDB = __esm(() => {
|
|
3329
|
+
init_FDBFactory();
|
|
3330
|
+
fakeIndexedDB = new FDBFactory_default;
|
|
3331
|
+
fakeIndexedDB_default = fakeIndexedDB;
|
|
3332
|
+
});
|
|
3333
|
+
|
|
3334
|
+
// ../../node_modules/.bun/fake-indexeddb@6.2.5/node_modules/fake-indexeddb/auto/index.mjs
|
|
3335
|
+
var exports_auto = {};
|
|
3336
|
+
var globalVar, createPropertyDescriptor = (value) => {
|
|
3337
|
+
return {
|
|
3338
|
+
value,
|
|
3339
|
+
enumerable: false,
|
|
3340
|
+
configurable: true,
|
|
3341
|
+
writable: true
|
|
3342
|
+
};
|
|
3343
|
+
};
|
|
3344
|
+
var init_auto = __esm(() => {
|
|
3345
|
+
init_fakeIndexedDB();
|
|
3346
|
+
init_FDBCursor();
|
|
3347
|
+
init_FDBCursorWithValue();
|
|
3348
|
+
init_FDBDatabase();
|
|
3349
|
+
init_FDBFactory();
|
|
3350
|
+
init_FDBIndex();
|
|
3351
|
+
init_FDBKeyRange();
|
|
3352
|
+
init_FDBObjectStore();
|
|
3353
|
+
init_FDBOpenDBRequest();
|
|
3354
|
+
init_FDBRecord();
|
|
3355
|
+
init_FDBRequest();
|
|
3356
|
+
init_FDBTransaction();
|
|
3357
|
+
init_FDBVersionChangeEvent();
|
|
3358
|
+
globalVar = typeof window !== "undefined" ? window : typeof WorkerGlobalScope !== "undefined" ? self : typeof global !== "undefined" ? global : Function("return this;")();
|
|
3359
|
+
Object.defineProperties(globalVar, {
|
|
3360
|
+
indexedDB: createPropertyDescriptor(fakeIndexedDB_default),
|
|
3361
|
+
IDBCursor: createPropertyDescriptor(FDBCursor_default),
|
|
3362
|
+
IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue_default),
|
|
3363
|
+
IDBDatabase: createPropertyDescriptor(FDBDatabase_default),
|
|
3364
|
+
IDBFactory: createPropertyDescriptor(FDBFactory_default),
|
|
3365
|
+
IDBIndex: createPropertyDescriptor(FDBIndex_default),
|
|
3366
|
+
IDBKeyRange: createPropertyDescriptor(FDBKeyRange_default),
|
|
3367
|
+
IDBObjectStore: createPropertyDescriptor(FDBObjectStore_default),
|
|
3368
|
+
IDBOpenDBRequest: createPropertyDescriptor(FDBOpenDBRequest_default),
|
|
3369
|
+
IDBRecord: createPropertyDescriptor(FDBRecord_default),
|
|
3370
|
+
IDBRequest: createPropertyDescriptor(FDBRequest_default),
|
|
3371
|
+
IDBTransaction: createPropertyDescriptor(FDBTransaction_default),
|
|
3372
|
+
IDBVersionChangeEvent: createPropertyDescriptor(FDBVersionChangeEvent_default)
|
|
3373
|
+
});
|
|
3374
|
+
});
|
|
3375
|
+
|
|
3376
|
+
// src/index.ts
|
|
3377
|
+
import { getConnectorAccountManager, logger as logger2 } from "@elizaos/core";
|
|
3378
|
+
|
|
3379
|
+
// src/accounts.ts
|
|
3380
|
+
var DEFAULT_MATRIX_ACCOUNT_ID = "default";
|
|
3381
|
+
function stringSetting(runtime, key) {
|
|
3382
|
+
const value = runtime.getSetting(key);
|
|
3383
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
3384
|
+
}
|
|
3385
|
+
function characterConfig(runtime) {
|
|
3386
|
+
const settings = runtime.character?.settings;
|
|
3387
|
+
const raw = settings?.matrix;
|
|
3388
|
+
return raw && typeof raw === "object" ? raw : {};
|
|
3389
|
+
}
|
|
3390
|
+
function parseAccountsJson(runtime) {
|
|
3391
|
+
const raw = stringSetting(runtime, "MATRIX_ACCOUNTS");
|
|
3392
|
+
if (!raw)
|
|
3393
|
+
return {};
|
|
3394
|
+
try {
|
|
3395
|
+
const parsed = JSON.parse(raw);
|
|
3396
|
+
if (Array.isArray(parsed)) {
|
|
3397
|
+
return Object.fromEntries(parsed.filter((item) => Boolean(item) && typeof item === "object").map((item) => [normalizeMatrixAccountId(item.accountId ?? item.id), item]));
|
|
3398
|
+
}
|
|
3399
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
3400
|
+
} catch {
|
|
3401
|
+
return {};
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
function allAccountConfigs(runtime) {
|
|
3405
|
+
return {
|
|
3406
|
+
...characterConfig(runtime).accounts ?? {},
|
|
3407
|
+
...parseAccountsJson(runtime)
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
function accountConfig(runtime, accountId) {
|
|
3411
|
+
const accounts = allAccountConfigs(runtime);
|
|
3412
|
+
return accounts[accountId] ?? accounts[normalizeMatrixAccountId(accountId)] ?? {};
|
|
3413
|
+
}
|
|
3414
|
+
function boolValue(value, fallback = false) {
|
|
3415
|
+
if (typeof value === "boolean")
|
|
3416
|
+
return value;
|
|
3417
|
+
if (typeof value === "string")
|
|
3418
|
+
return value.trim().toLowerCase() === "true";
|
|
3419
|
+
return fallback;
|
|
3420
|
+
}
|
|
3421
|
+
function roomsValue(value) {
|
|
3422
|
+
if (Array.isArray(value)) {
|
|
3423
|
+
return value.map((room) => String(room).trim()).filter(Boolean);
|
|
3424
|
+
}
|
|
3425
|
+
if (typeof value === "string") {
|
|
3426
|
+
return value.split(",").map((room) => room.trim()).filter(Boolean);
|
|
3427
|
+
}
|
|
3428
|
+
return [];
|
|
3429
|
+
}
|
|
3430
|
+
function normalizeMatrixAccountId(accountId) {
|
|
3431
|
+
if (typeof accountId !== "string")
|
|
3432
|
+
return DEFAULT_MATRIX_ACCOUNT_ID;
|
|
3433
|
+
const trimmed = accountId.trim();
|
|
3434
|
+
return trimmed || DEFAULT_MATRIX_ACCOUNT_ID;
|
|
3435
|
+
}
|
|
3436
|
+
function listMatrixAccountIds(runtime) {
|
|
3437
|
+
const ids = new Set;
|
|
3438
|
+
const config = characterConfig(runtime);
|
|
3439
|
+
if (stringSetting(runtime, "MATRIX_ACCESS_TOKEN") || config.homeserver && config.userId && config.accessToken) {
|
|
3440
|
+
ids.add(DEFAULT_MATRIX_ACCOUNT_ID);
|
|
3441
|
+
}
|
|
3442
|
+
for (const id of Object.keys(allAccountConfigs(runtime))) {
|
|
3443
|
+
ids.add(normalizeMatrixAccountId(id));
|
|
3444
|
+
}
|
|
3445
|
+
return Array.from(ids.size ? ids : new Set([DEFAULT_MATRIX_ACCOUNT_ID])).sort((a, b) => a.localeCompare(b));
|
|
3446
|
+
}
|
|
3447
|
+
function resolveDefaultMatrixAccountId(runtime) {
|
|
3448
|
+
const requested = stringSetting(runtime, "MATRIX_DEFAULT_ACCOUNT_ID") ?? stringSetting(runtime, "MATRIX_ACCOUNT_ID");
|
|
3449
|
+
if (requested)
|
|
3450
|
+
return normalizeMatrixAccountId(requested);
|
|
3451
|
+
const ids = listMatrixAccountIds(runtime);
|
|
3452
|
+
return ids.includes(DEFAULT_MATRIX_ACCOUNT_ID) ? DEFAULT_MATRIX_ACCOUNT_ID : ids[0];
|
|
3453
|
+
}
|
|
3454
|
+
function readMatrixAccountId(...sources) {
|
|
3455
|
+
for (const source of sources) {
|
|
3456
|
+
if (!source || typeof source !== "object")
|
|
3457
|
+
continue;
|
|
3458
|
+
const record = source;
|
|
3459
|
+
const parameters = record.parameters && typeof record.parameters === "object" ? record.parameters : {};
|
|
3460
|
+
const data = record.data && typeof record.data === "object" ? record.data : {};
|
|
3461
|
+
const metadata = record.metadata && typeof record.metadata === "object" ? record.metadata : {};
|
|
3462
|
+
const matrix = data.matrix && typeof data.matrix === "object" ? data.matrix : {};
|
|
3463
|
+
const value = record.accountId ?? parameters.accountId ?? data.accountId ?? matrix.accountId ?? metadata.accountId;
|
|
3464
|
+
if (typeof value === "string" && value.trim())
|
|
3465
|
+
return normalizeMatrixAccountId(value);
|
|
3466
|
+
}
|
|
3467
|
+
return;
|
|
3468
|
+
}
|
|
3469
|
+
function resolveMatrixAccountSettings(runtime, requestedAccountId) {
|
|
3470
|
+
const accountId = normalizeMatrixAccountId(requestedAccountId ?? resolveDefaultMatrixAccountId(runtime));
|
|
3471
|
+
const base = characterConfig(runtime);
|
|
3472
|
+
const account = accountConfig(runtime, accountId);
|
|
3473
|
+
const allowEnv = accountId === DEFAULT_MATRIX_ACCOUNT_ID;
|
|
3474
|
+
return {
|
|
3475
|
+
accountId,
|
|
3476
|
+
homeserver: account.homeserver ?? base.homeserver ?? (allowEnv ? stringSetting(runtime, "MATRIX_HOMESERVER") : undefined) ?? "",
|
|
3477
|
+
userId: account.userId ?? base.userId ?? (allowEnv ? stringSetting(runtime, "MATRIX_USER_ID") : undefined) ?? "",
|
|
3478
|
+
accessToken: account.accessToken ?? base.accessToken ?? (allowEnv ? stringSetting(runtime, "MATRIX_ACCESS_TOKEN") : undefined) ?? "",
|
|
3479
|
+
password: account.password ?? base.password ?? (allowEnv ? stringSetting(runtime, "MATRIX_PASSWORD") : undefined),
|
|
3480
|
+
deviceId: account.deviceId ?? base.deviceId ?? (allowEnv ? stringSetting(runtime, "MATRIX_DEVICE_ID") : undefined),
|
|
3481
|
+
rooms: roomsValue(account.rooms ?? base.rooms ?? (allowEnv ? stringSetting(runtime, "MATRIX_ROOMS") : undefined)),
|
|
3482
|
+
verifyAllowlist: roomsValue(account.verifyAllowlist ?? base.verifyAllowlist ?? (allowEnv ? stringSetting(runtime, "MATRIX_VERIFY_ALLOWLIST") : undefined)),
|
|
3483
|
+
autoJoin: boolValue(account.autoJoin ?? base.autoJoin ?? (allowEnv ? runtime.getSetting("MATRIX_AUTO_JOIN") : undefined)),
|
|
3484
|
+
encryption: boolValue(account.encryption ?? base.encryption ?? (allowEnv ? runtime.getSetting("MATRIX_ENCRYPTION") : undefined)),
|
|
3485
|
+
requireMention: boolValue(account.requireMention ?? base.requireMention ?? (allowEnv ? runtime.getSetting("MATRIX_REQUIRE_MENTION") : undefined)),
|
|
3486
|
+
personal: boolValue(account.personal ?? base.personal ?? (allowEnv ? runtime.getSetting("MATRIX_PERSONAL") : undefined)),
|
|
3487
|
+
enabled: boolValue(account.enabled ?? base.enabled, true)
|
|
3488
|
+
};
|
|
3489
|
+
}
|
|
3490
|
+
// src/service.ts
|
|
3491
|
+
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
|
|
3492
|
+
import { existsSync } from "node:fs";
|
|
3493
|
+
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3494
|
+
import { homedir } from "node:os";
|
|
3495
|
+
import { join } from "node:path";
|
|
3496
|
+
import { deserialize as v8Deserialize, serialize as v8Serialize } from "node:v8";
|
|
3497
|
+
import {
|
|
3498
|
+
ChannelType,
|
|
3499
|
+
createUniqueUuid,
|
|
3500
|
+
EventType,
|
|
3501
|
+
lifeOpsPassiveConnectorsEnabled,
|
|
3502
|
+
logger,
|
|
3503
|
+
Service
|
|
3504
|
+
} from "@elizaos/core";
|
|
3505
|
+
import * as sdk from "matrix-js-sdk";
|
|
3506
|
+
import {
|
|
3507
|
+
CryptoEvent,
|
|
3508
|
+
canAcceptVerificationRequest,
|
|
3509
|
+
VerificationPhase,
|
|
3510
|
+
VerificationRequestEvent,
|
|
3511
|
+
VerifierEvent
|
|
3512
|
+
} from "matrix-js-sdk/lib/crypto-api";
|
|
3513
|
+
|
|
3514
|
+
// src/types.ts
|
|
3515
|
+
var MAX_MATRIX_MESSAGE_LENGTH = 4000;
|
|
3516
|
+
var MATRIX_SERVICE_NAME = "matrix";
|
|
3517
|
+
var MatrixEventTypes;
|
|
3518
|
+
((MatrixEventTypes2) => {
|
|
3519
|
+
MatrixEventTypes2["MESSAGE_RECEIVED"] = "MATRIX_MESSAGE_RECEIVED";
|
|
3520
|
+
MatrixEventTypes2["MESSAGE_SENT"] = "MATRIX_MESSAGE_SENT";
|
|
3521
|
+
MatrixEventTypes2["ROOM_JOINED"] = "MATRIX_ROOM_JOINED";
|
|
3522
|
+
MatrixEventTypes2["ROOM_LEFT"] = "MATRIX_ROOM_LEFT";
|
|
3523
|
+
MatrixEventTypes2["INVITE_RECEIVED"] = "MATRIX_INVITE_RECEIVED";
|
|
3524
|
+
MatrixEventTypes2["REACTION_RECEIVED"] = "MATRIX_REACTION_RECEIVED";
|
|
3525
|
+
MatrixEventTypes2["TYPING_RECEIVED"] = "MATRIX_TYPING_RECEIVED";
|
|
3526
|
+
MatrixEventTypes2["SYNC_COMPLETE"] = "MATRIX_SYNC_COMPLETE";
|
|
3527
|
+
MatrixEventTypes2["CONNECTION_READY"] = "MATRIX_CONNECTION_READY";
|
|
3528
|
+
MatrixEventTypes2["CONNECTION_LOST"] = "MATRIX_CONNECTION_LOST";
|
|
3529
|
+
})(MatrixEventTypes ||= {});
|
|
3530
|
+
function isValidMatrixUserId(userId) {
|
|
3531
|
+
return /^@[^:]+:.+$/.test(userId);
|
|
3532
|
+
}
|
|
3533
|
+
function isValidMatrixRoomId(roomId) {
|
|
3534
|
+
return /^![^:]+:.+$/.test(roomId);
|
|
3535
|
+
}
|
|
3536
|
+
function isValidMatrixRoomAlias(alias) {
|
|
3537
|
+
return /^#[^:]+:.+$/.test(alias);
|
|
3538
|
+
}
|
|
3539
|
+
function getMatrixLocalpart(matrixId) {
|
|
3540
|
+
const match = matrixId.match(/^[@#!]([^:]+):/);
|
|
3541
|
+
return match ? match[1] : matrixId;
|
|
3542
|
+
}
|
|
3543
|
+
function getMatrixServerpart(matrixId) {
|
|
3544
|
+
const match = matrixId.match(/:(.+)$/);
|
|
3545
|
+
return match ? match[1] : "";
|
|
3546
|
+
}
|
|
3547
|
+
function getMatrixUserDisplayName(user) {
|
|
3548
|
+
return user.displayName || getMatrixLocalpart(user.userId);
|
|
3549
|
+
}
|
|
3550
|
+
function matrixMxcToHttp(mxcUrl, homeserver) {
|
|
3551
|
+
if (!mxcUrl.startsWith("mxc://")) {
|
|
3552
|
+
return;
|
|
3553
|
+
}
|
|
3554
|
+
const [serverName, mediaId] = mxcUrl.slice(6).split("/");
|
|
3555
|
+
if (!serverName || !mediaId) {
|
|
3556
|
+
return;
|
|
3557
|
+
}
|
|
3558
|
+
const base = homeserver.replace(/\/$/, "");
|
|
3559
|
+
return `${base}/_matrix/media/v3/download/${serverName}/${mediaId}`;
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
class MatrixPluginError extends Error {
|
|
3563
|
+
constructor(message) {
|
|
3564
|
+
super(message);
|
|
3565
|
+
this.name = "MatrixPluginError";
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
class MatrixServiceNotInitializedError extends MatrixPluginError {
|
|
3570
|
+
constructor(message = "Matrix service is not initialized") {
|
|
3571
|
+
super(message);
|
|
3572
|
+
this.name = "MatrixServiceNotInitializedError";
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
class MatrixNotConnectedError extends MatrixPluginError {
|
|
3577
|
+
constructor(message = "Matrix client is not connected") {
|
|
3578
|
+
super(message);
|
|
3579
|
+
this.name = "MatrixNotConnectedError";
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
class MatrixConfigurationError extends MatrixPluginError {
|
|
3584
|
+
settingName;
|
|
3585
|
+
constructor(message, settingName) {
|
|
3586
|
+
super(message);
|
|
3587
|
+
this.name = "MatrixConfigurationError";
|
|
3588
|
+
this.settingName = settingName;
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
class MatrixApiError extends MatrixPluginError {
|
|
3593
|
+
errcode;
|
|
3594
|
+
constructor(message, errcode) {
|
|
3595
|
+
super(message);
|
|
3596
|
+
this.name = "MatrixApiError";
|
|
3597
|
+
this.errcode = errcode;
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
// src/service.ts
|
|
3602
|
+
function normalizeSearchQuery(query) {
|
|
3603
|
+
return query.trim().toLowerCase();
|
|
3604
|
+
}
|
|
3605
|
+
function escapeRegExp(value) {
|
|
3606
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3607
|
+
}
|
|
3608
|
+
function matrixRoomSearchText(room) {
|
|
3609
|
+
return [room.roomId, room.name, room.topic, room.canonicalAlias].filter((value) => typeof value === "string" && value.length > 0).join(" ").toLowerCase();
|
|
3610
|
+
}
|
|
3611
|
+
function scoreMatrixRoom(room, query) {
|
|
3612
|
+
const normalized = normalizeSearchQuery(query);
|
|
3613
|
+
if (!normalized) {
|
|
3614
|
+
return 0.4;
|
|
3615
|
+
}
|
|
3616
|
+
const candidates = [room.roomId, room.canonicalAlias, room.name].filter((value) => typeof value === "string" && value.length > 0);
|
|
3617
|
+
if (candidates.some((candidate) => candidate.toLowerCase() === normalized)) {
|
|
3618
|
+
return 1;
|
|
3619
|
+
}
|
|
3620
|
+
if (candidates.some((candidate) => candidate.toLowerCase().includes(normalized))) {
|
|
3621
|
+
return 0.85;
|
|
3622
|
+
}
|
|
3623
|
+
return matrixRoomSearchText(room).includes(normalized) ? 0.65 : 0;
|
|
3624
|
+
}
|
|
3625
|
+
function matrixRoomToConnectorTarget(room, score = 0.5, accountId = DEFAULT_MATRIX_ACCOUNT_ID) {
|
|
3626
|
+
const label = room.name || room.canonicalAlias || room.roomId;
|
|
3627
|
+
return {
|
|
3628
|
+
target: {
|
|
3629
|
+
source: MATRIX_SERVICE_NAME,
|
|
3630
|
+
accountId,
|
|
3631
|
+
channelId: room.roomId
|
|
3632
|
+
},
|
|
3633
|
+
label,
|
|
3634
|
+
kind: room.isDirect ? "user" : "room",
|
|
3635
|
+
description: room.topic || `${room.memberCount} Matrix member${room.memberCount === 1 ? "" : "s"}`,
|
|
3636
|
+
score,
|
|
3637
|
+
contexts: ["social", "connectors"],
|
|
3638
|
+
metadata: {
|
|
3639
|
+
accountId,
|
|
3640
|
+
roomId: room.roomId,
|
|
3641
|
+
canonicalAlias: room.canonicalAlias,
|
|
3642
|
+
isEncrypted: room.isEncrypted,
|
|
3643
|
+
isDirect: room.isDirect,
|
|
3644
|
+
memberCount: room.memberCount
|
|
3645
|
+
}
|
|
3646
|
+
};
|
|
3647
|
+
}
|
|
3648
|
+
var DEFAULT_CRYPTO_DB_PREFIX = "matrix-js-sdk";
|
|
3649
|
+
function cryptoDbPrefix(accountId) {
|
|
3650
|
+
if (!accountId || accountId === DEFAULT_MATRIX_ACCOUNT_ID) {
|
|
3651
|
+
return DEFAULT_CRYPTO_DB_PREFIX;
|
|
3652
|
+
}
|
|
3653
|
+
const safeId = accountId.replace(/[^a-zA-Z0-9._-]/g, "_") || "account";
|
|
3654
|
+
return `${DEFAULT_CRYPTO_DB_PREFIX}-${safeId}`;
|
|
3655
|
+
}
|
|
3656
|
+
function cryptoDbName(accountId) {
|
|
3657
|
+
return `${cryptoDbPrefix(accountId)}::matrix-sdk-crypto`;
|
|
3658
|
+
}
|
|
3659
|
+
var CRYPTO_SNAPSHOT_INTERVAL_MS = 60 * 1000;
|
|
3660
|
+
var VERIFICATION_START_FALLBACK_MS = 4000;
|
|
3661
|
+
var ROOM_KEY_SCRYPT_SALT = "matrix.roomKeys.v1";
|
|
3662
|
+
var ROOM_KEY_BYTES = 32;
|
|
3663
|
+
var ROOM_KEY_NONCE_BYTES = 12;
|
|
3664
|
+
function resolveStateDir() {
|
|
3665
|
+
return process.env.ELIZA_STATE_DIR || join(homedir(), ".local/state/eliza");
|
|
3666
|
+
}
|
|
3667
|
+
function cryptoStoreFilePath(accountId) {
|
|
3668
|
+
const safeId = accountId.replace(/[^a-zA-Z0-9._-]/g, "_") || "default";
|
|
3669
|
+
return join(resolveStateDir(), "matrix-keys", `${safeId}.enc`);
|
|
3670
|
+
}
|
|
3671
|
+
function encryptCryptoStore(accessToken, plaintext) {
|
|
3672
|
+
const key = scryptSync(accessToken, ROOM_KEY_SCRYPT_SALT, ROOM_KEY_BYTES);
|
|
3673
|
+
const nonce = randomBytes(ROOM_KEY_NONCE_BYTES);
|
|
3674
|
+
const cipher = createCipheriv("aes-256-gcm", key, nonce);
|
|
3675
|
+
const ct = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
3676
|
+
const tag = cipher.getAuthTag();
|
|
3677
|
+
return `v1:${nonce.toString("base64")}:${tag.toString("base64")}:${ct.toString("base64")}`;
|
|
3678
|
+
}
|
|
3679
|
+
function decryptCryptoStore(accessToken, ciphertext) {
|
|
3680
|
+
const parts = ciphertext.split(":");
|
|
3681
|
+
if (parts.length !== 4 || parts[0] !== "v1") {
|
|
3682
|
+
throw new Error("malformed crypto-store ciphertext");
|
|
3683
|
+
}
|
|
3684
|
+
const key = scryptSync(accessToken, ROOM_KEY_SCRYPT_SALT, ROOM_KEY_BYTES);
|
|
3685
|
+
const nonce = Buffer.from(parts[1], "base64");
|
|
3686
|
+
const tag = Buffer.from(parts[2], "base64");
|
|
3687
|
+
const ct = Buffer.from(parts[3], "base64");
|
|
3688
|
+
const decipher = createDecipheriv("aes-256-gcm", key, nonce);
|
|
3689
|
+
decipher.setAuthTag(tag);
|
|
3690
|
+
return Buffer.concat([decipher.update(ct), decipher.final()]);
|
|
3691
|
+
}
|
|
3692
|
+
function openIndexedDb(name, version, upgrade) {
|
|
3693
|
+
return new Promise((resolve, reject) => {
|
|
3694
|
+
const request = version ? indexedDB.open(name, version) : indexedDB.open(name);
|
|
3695
|
+
if (upgrade) {
|
|
3696
|
+
request.onupgradeneeded = (event) => upgrade(event.target.result);
|
|
3697
|
+
}
|
|
3698
|
+
request.onsuccess = () => resolve(request.result);
|
|
3699
|
+
request.onerror = () => reject(request.error);
|
|
3700
|
+
});
|
|
3701
|
+
}
|
|
3702
|
+
function transactionDone(tx) {
|
|
3703
|
+
return new Promise((resolve, reject) => {
|
|
3704
|
+
tx.oncomplete = () => resolve();
|
|
3705
|
+
tx.onerror = () => reject(tx.error);
|
|
3706
|
+
tx.onabort = () => reject(tx.error);
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
async function snapshotDb(name) {
|
|
3710
|
+
const db = await openIndexedDb(name);
|
|
3711
|
+
const snapshot = { version: db.version, stores: {} };
|
|
3712
|
+
for (const storeName of [...db.objectStoreNames]) {
|
|
3713
|
+
const store = db.transaction(storeName, "readonly").objectStore(storeName);
|
|
3714
|
+
const records = [];
|
|
3715
|
+
await new Promise((resolve, reject) => {
|
|
3716
|
+
const cursorRequest = store.openCursor();
|
|
3717
|
+
cursorRequest.onsuccess = () => {
|
|
3718
|
+
const cursor = cursorRequest.result;
|
|
3719
|
+
if (cursor) {
|
|
3720
|
+
records.push({ key: cursor.primaryKey, value: cursor.value });
|
|
3721
|
+
cursor.continue();
|
|
3722
|
+
} else {
|
|
3723
|
+
resolve();
|
|
3724
|
+
}
|
|
3725
|
+
};
|
|
3726
|
+
cursorRequest.onerror = () => reject(cursorRequest.error);
|
|
3727
|
+
});
|
|
3728
|
+
snapshot.stores[storeName] = {
|
|
3729
|
+
schema: {
|
|
3730
|
+
keyPath: store.keyPath,
|
|
3731
|
+
autoIncrement: store.autoIncrement,
|
|
3732
|
+
indexes: [...store.indexNames].map((indexName) => {
|
|
3733
|
+
const index = store.index(indexName);
|
|
3734
|
+
return {
|
|
3735
|
+
name: indexName,
|
|
3736
|
+
keyPath: index.keyPath,
|
|
3737
|
+
unique: index.unique,
|
|
3738
|
+
multiEntry: index.multiEntry
|
|
3739
|
+
};
|
|
3740
|
+
})
|
|
3741
|
+
},
|
|
3742
|
+
records
|
|
3743
|
+
};
|
|
3744
|
+
}
|
|
3745
|
+
db.close();
|
|
3746
|
+
return snapshot;
|
|
3747
|
+
}
|
|
3748
|
+
async function restoreDb(name, snapshot) {
|
|
3749
|
+
await new Promise((resolve) => {
|
|
3750
|
+
const request = indexedDB.deleteDatabase(name);
|
|
3751
|
+
request.onsuccess = () => resolve();
|
|
3752
|
+
request.onerror = () => resolve();
|
|
3753
|
+
request.onblocked = () => resolve();
|
|
3754
|
+
});
|
|
3755
|
+
const db = await openIndexedDb(name, snapshot.version, (upgradeDb) => {
|
|
3756
|
+
for (const [storeName, { schema }] of Object.entries(snapshot.stores)) {
|
|
3757
|
+
const store = upgradeDb.createObjectStore(storeName, {
|
|
3758
|
+
keyPath: schema.keyPath ?? undefined,
|
|
3759
|
+
autoIncrement: schema.autoIncrement
|
|
3760
|
+
});
|
|
3761
|
+
for (const index of schema.indexes) {
|
|
3762
|
+
store.createIndex(index.name, index.keyPath, {
|
|
3763
|
+
unique: index.unique,
|
|
3764
|
+
multiEntry: index.multiEntry
|
|
3765
|
+
});
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
});
|
|
3769
|
+
for (const [storeName, { schema, records }] of Object.entries(snapshot.stores)) {
|
|
3770
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
3771
|
+
const store = tx.objectStore(storeName);
|
|
3772
|
+
for (const { key, value } of records) {
|
|
3773
|
+
if (schema.keyPath) {
|
|
3774
|
+
store.put(value);
|
|
3775
|
+
} else {
|
|
3776
|
+
store.put(value, key);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
await transactionDone(tx);
|
|
3780
|
+
}
|
|
3781
|
+
db.close();
|
|
3782
|
+
}
|
|
3783
|
+
function normalizeConnectorLimit(limit, fallback = 50) {
|
|
3784
|
+
if (!Number.isFinite(limit) || !limit || limit <= 0) {
|
|
3785
|
+
return fallback;
|
|
3786
|
+
}
|
|
3787
|
+
return Math.min(Math.floor(limit), 200);
|
|
3788
|
+
}
|
|
3789
|
+
function buildMatrixMessage(event, room) {
|
|
3790
|
+
const content = event.getContent();
|
|
3791
|
+
const msgType = content.msgtype;
|
|
3792
|
+
if (msgType !== "m.text")
|
|
3793
|
+
return null;
|
|
3794
|
+
if (typeof content.body !== "string")
|
|
3795
|
+
return null;
|
|
3796
|
+
const roomId = event.getRoomId();
|
|
3797
|
+
if (!roomId)
|
|
3798
|
+
return null;
|
|
3799
|
+
const sender = event.getSender();
|
|
3800
|
+
const senderMember = room.getMember(sender || "");
|
|
3801
|
+
const senderInfo = {
|
|
3802
|
+
userId: sender || "",
|
|
3803
|
+
displayName: senderMember?.name,
|
|
3804
|
+
avatarUrl: senderMember?.getMxcAvatarUrl() || undefined
|
|
3805
|
+
};
|
|
3806
|
+
const relatesTo = content["m.relates_to"];
|
|
3807
|
+
const isEdit = relatesTo?.rel_type === "m.replace";
|
|
3808
|
+
const threadId = relatesTo?.rel_type === "m.thread" ? relatesTo.event_id : undefined;
|
|
3809
|
+
const replyTo = relatesTo?.["m.in_reply_to"]?.event_id;
|
|
3810
|
+
return {
|
|
3811
|
+
eventId: event.getId() || "",
|
|
3812
|
+
roomId,
|
|
3813
|
+
sender: sender || "",
|
|
3814
|
+
senderInfo,
|
|
3815
|
+
content: content.body,
|
|
3816
|
+
msgType,
|
|
3817
|
+
formattedBody: typeof content.formatted_body === "string" ? content.formatted_body : undefined,
|
|
3818
|
+
timestamp: event.getTs(),
|
|
3819
|
+
threadId,
|
|
3820
|
+
replyTo,
|
|
3821
|
+
isEdit,
|
|
3822
|
+
replacesEventId: isEdit ? relatesTo?.event_id : undefined
|
|
3823
|
+
};
|
|
3824
|
+
}
|
|
3825
|
+
function matrixMessageToMemory(runtime, message, channelType) {
|
|
3826
|
+
const roomId = message.roomId;
|
|
3827
|
+
return {
|
|
3828
|
+
id: createUniqueUuid(runtime, message.eventId || `${roomId}:${message.timestamp}`),
|
|
3829
|
+
entityId: createUniqueUuid(runtime, message.sender || roomId),
|
|
3830
|
+
agentId: runtime.agentId,
|
|
3831
|
+
roomId: createUniqueUuid(runtime, message.roomId),
|
|
3832
|
+
content: {
|
|
3833
|
+
text: message.content,
|
|
3834
|
+
source: MATRIX_SERVICE_NAME,
|
|
3835
|
+
channelType,
|
|
3836
|
+
...message.replyTo ? { inReplyTo: createUniqueUuid(runtime, message.replyTo) } : {}
|
|
3837
|
+
},
|
|
3838
|
+
createdAt: message.timestamp
|
|
3839
|
+
};
|
|
3840
|
+
}
|
|
3841
|
+
async function readStoredMessageMemories(runtime, roomId, limit) {
|
|
3842
|
+
return runtime.getMemories({
|
|
3843
|
+
tableName: "messages",
|
|
3844
|
+
roomId,
|
|
3845
|
+
limit,
|
|
3846
|
+
orderBy: "createdAt",
|
|
3847
|
+
orderDirection: "desc"
|
|
3848
|
+
});
|
|
3849
|
+
}
|
|
3850
|
+
async function resolveMatrixRoomId(runtime, target) {
|
|
3851
|
+
return String(target?.channelId ?? (target?.roomId ? (await runtime.getRoom(target.roomId))?.channelId : "") ?? "").trim();
|
|
3852
|
+
}
|
|
3853
|
+
async function readJoinedRoomMessages(service, accountId, limit) {
|
|
3854
|
+
const rooms = (await service.getJoinedRooms(accountId)).slice(0, 10);
|
|
3855
|
+
const chunks = await Promise.all(rooms.map((room) => service.getRoomMessages(room.roomId, limit, accountId)));
|
|
3856
|
+
return chunks.flat().sort((left, right) => (right.createdAt ?? 0) - (left.createdAt ?? 0)).slice(0, limit);
|
|
3857
|
+
}
|
|
3858
|
+
async function readMessagesForTarget(service, runtime, accountId, target, limit) {
|
|
3859
|
+
const matrixRoomId = await resolveMatrixRoomId(runtime, target);
|
|
3860
|
+
if (!matrixRoomId) {
|
|
3861
|
+
return readJoinedRoomMessages(service, accountId, limit);
|
|
3862
|
+
}
|
|
3863
|
+
const live = await service.getRoomMessages(matrixRoomId, limit, accountId);
|
|
3864
|
+
if (live.length > 0) {
|
|
3865
|
+
return live;
|
|
3866
|
+
}
|
|
3867
|
+
return readStoredMessageMemories(runtime, createUniqueUuid(runtime, matrixRoomId), limit);
|
|
3868
|
+
}
|
|
3869
|
+
function filterMemoriesByQuery(memories, query, limit) {
|
|
3870
|
+
const normalized = query.trim().toLowerCase();
|
|
3871
|
+
if (!normalized) {
|
|
3872
|
+
return memories.slice(0, limit);
|
|
3873
|
+
}
|
|
3874
|
+
return memories.filter((memory) => {
|
|
3875
|
+
const text = typeof memory.content?.text === "string" ? memory.content.text : "";
|
|
3876
|
+
return text.toLowerCase().includes(normalized);
|
|
3877
|
+
}).slice(0, limit);
|
|
3878
|
+
}
|
|
3879
|
+
function extractMatrixSendOptions(content, target) {
|
|
3880
|
+
const data = content.data;
|
|
3881
|
+
const matrixData = data?.matrix && typeof data.matrix === "object" ? data.matrix : data;
|
|
3882
|
+
return {
|
|
3883
|
+
threadId: target.threadId || (typeof matrixData?.threadId === "string" ? matrixData.threadId : undefined),
|
|
3884
|
+
replyTo: typeof matrixData?.replyTo === "string" ? matrixData.replyTo : undefined,
|
|
3885
|
+
formatted: matrixData?.formatted === true
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3888
|
+
|
|
3889
|
+
class MatrixService extends Service {
|
|
3890
|
+
static serviceType = MATRIX_SERVICE_NAME;
|
|
3891
|
+
capabilityDescription = "Matrix messaging service for chat communication";
|
|
3892
|
+
states = new Map;
|
|
3893
|
+
defaultAccountId = DEFAULT_MATRIX_ACCOUNT_ID;
|
|
3894
|
+
static async start(runtime) {
|
|
3895
|
+
const service = new MatrixService;
|
|
3896
|
+
await service.initialize(runtime);
|
|
3897
|
+
return service;
|
|
3898
|
+
}
|
|
3899
|
+
static async stopRuntime(runtime) {
|
|
3900
|
+
const service = runtime.getService(MATRIX_SERVICE_NAME);
|
|
3901
|
+
if (service) {
|
|
3902
|
+
await service.stop();
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
static registerSendHandlers(runtime, service, accountId = service.getAccountId(runtime)) {
|
|
3906
|
+
accountId = normalizeMatrixAccountId(accountId);
|
|
3907
|
+
const sendHandler = async (handlerRuntime, target, content) => {
|
|
3908
|
+
await service.handleSendMessage(handlerRuntime, target, content);
|
|
3909
|
+
return;
|
|
3910
|
+
};
|
|
3911
|
+
if (typeof runtime.registerMessageConnector === "function") {
|
|
3912
|
+
const registration = {
|
|
3913
|
+
source: MATRIX_SERVICE_NAME,
|
|
3914
|
+
accountId,
|
|
3915
|
+
label: "Matrix",
|
|
3916
|
+
capabilities: [
|
|
3917
|
+
"send_message",
|
|
3918
|
+
"send_thread_reply",
|
|
3919
|
+
"send_formatted_message",
|
|
3920
|
+
"react_to_message",
|
|
3921
|
+
"list_rooms",
|
|
3922
|
+
"join_room"
|
|
3923
|
+
],
|
|
3924
|
+
supportedTargetKinds: ["room", "channel", "thread", "user"],
|
|
3925
|
+
contexts: ["social", "connectors"],
|
|
3926
|
+
description: "Send messages to joined Matrix rooms, aliases, encrypted rooms, and known direct-message rooms.",
|
|
3927
|
+
metadata: {
|
|
3928
|
+
accountId,
|
|
3929
|
+
service: MATRIX_SERVICE_NAME
|
|
3930
|
+
},
|
|
3931
|
+
sendHandler,
|
|
3932
|
+
resolveTargets: async (query) => {
|
|
3933
|
+
const rooms = await service.getJoinedRooms(accountId);
|
|
3934
|
+
return rooms.map((room) => ({ room, score: scoreMatrixRoom(room, query) })).filter(({ score }) => score > 0).sort((left, right) => right.score - left.score).slice(0, 10).map(({ room, score }) => matrixRoomToConnectorTarget(room, score, accountId));
|
|
3935
|
+
},
|
|
3936
|
+
listRecentTargets: async () => (await service.getJoinedRooms(accountId)).slice(0, 10).map((room) => matrixRoomToConnectorTarget(room, 0.5, accountId)),
|
|
3937
|
+
listRooms: async () => (await service.getJoinedRooms(accountId)).map((room) => matrixRoomToConnectorTarget(room, 0.5, accountId)),
|
|
3938
|
+
fetchMessages: async (context, params) => {
|
|
3939
|
+
const limit = normalizeConnectorLimit(params?.limit);
|
|
3940
|
+
const target = params?.target ?? context.target;
|
|
3941
|
+
return readMessagesForTarget(service, context.runtime, accountId, target, limit);
|
|
3942
|
+
},
|
|
3943
|
+
searchMessages: async (context, params) => {
|
|
3944
|
+
const limit = normalizeConnectorLimit(params?.limit);
|
|
3945
|
+
const target = params?.target ?? context.target;
|
|
3946
|
+
const messages2 = await readMessagesForTarget(service, context.runtime, accountId, target, Math.max(limit, 100));
|
|
3947
|
+
return filterMemoriesByQuery(messages2, params.query, limit);
|
|
3948
|
+
},
|
|
3949
|
+
reactHandler: async (handlerRuntime, params) => {
|
|
3950
|
+
const target = params.target ?? { source: MATRIX_SERVICE_NAME };
|
|
3951
|
+
const room = target.roomId ? await handlerRuntime.getRoom(target.roomId) : null;
|
|
3952
|
+
const roomId = String(target.channelId ?? room?.channelId ?? "").trim();
|
|
3953
|
+
const mutationParams = params;
|
|
3954
|
+
const eventId = String(mutationParams.eventId ?? params.messageId ?? "").trim();
|
|
3955
|
+
const emoji = String(params.emoji ?? "").trim();
|
|
3956
|
+
if (!roomId || !eventId || !emoji) {
|
|
3957
|
+
throw new Error("Matrix reactHandler requires room, event id, and emoji");
|
|
3958
|
+
}
|
|
3959
|
+
const result = await service.sendReaction(roomId, eventId, emoji, accountId);
|
|
3960
|
+
if (!result.success) {
|
|
3961
|
+
throw new Error(result.error || "Matrix reaction failed");
|
|
3962
|
+
}
|
|
3963
|
+
},
|
|
3964
|
+
joinHandler: async (_handlerRuntime, params) => {
|
|
3965
|
+
const membershipParams = params;
|
|
3966
|
+
const roomIdOrAlias = String(membershipParams.roomIdOrAlias ?? params.alias ?? params.invite ?? params.channelId ?? params.roomId ?? "").trim();
|
|
3967
|
+
if (!roomIdOrAlias) {
|
|
3968
|
+
throw new Error("Matrix joinHandler requires a room ID or alias");
|
|
3969
|
+
}
|
|
3970
|
+
await service.joinRoom(roomIdOrAlias, accountId);
|
|
3971
|
+
},
|
|
3972
|
+
leaveHandler: async (handlerRuntime, params) => {
|
|
3973
|
+
const target = params.target ?? { source: MATRIX_SERVICE_NAME };
|
|
3974
|
+
const room = target.roomId ? await handlerRuntime.getRoom(target.roomId) : null;
|
|
3975
|
+
const roomId = String(params?.roomId ?? params?.channelId ?? target.channelId ?? room?.channelId ?? "");
|
|
3976
|
+
if (!roomId) {
|
|
3977
|
+
throw new Error("Matrix leaveHandler requires a room ID");
|
|
3978
|
+
}
|
|
3979
|
+
await service.leaveRoom(roomId, accountId);
|
|
3980
|
+
},
|
|
3981
|
+
getChatContext: async (target, context) => {
|
|
3982
|
+
const room = target.roomId ? await context.runtime.getRoom(target.roomId) : null;
|
|
3983
|
+
const channelId = String(target.channelId ?? room?.channelId ?? "").trim();
|
|
3984
|
+
const joinedRoom = (await service.getJoinedRooms(accountId)).find((candidate) => candidate.roomId === channelId || candidate.canonicalAlias === channelId);
|
|
3985
|
+
if (!joinedRoom) {
|
|
3986
|
+
return null;
|
|
3987
|
+
}
|
|
3988
|
+
return {
|
|
3989
|
+
target: {
|
|
3990
|
+
source: MATRIX_SERVICE_NAME,
|
|
3991
|
+
accountId,
|
|
3992
|
+
channelId: joinedRoom.roomId,
|
|
3993
|
+
roomId: target.roomId
|
|
3994
|
+
},
|
|
3995
|
+
label: joinedRoom.name || joinedRoom.canonicalAlias || joinedRoom.roomId,
|
|
3996
|
+
summary: joinedRoom.topic,
|
|
3997
|
+
metadata: {
|
|
3998
|
+
accountId,
|
|
3999
|
+
roomId: joinedRoom.roomId,
|
|
4000
|
+
canonicalAlias: joinedRoom.canonicalAlias,
|
|
4001
|
+
isEncrypted: joinedRoom.isEncrypted,
|
|
4002
|
+
isDirect: joinedRoom.isDirect,
|
|
4003
|
+
memberCount: joinedRoom.memberCount
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
4006
|
+
},
|
|
4007
|
+
getUserContext: async (entityId, context) => {
|
|
4008
|
+
if (typeof context.runtime.getEntityById !== "function") {
|
|
4009
|
+
return null;
|
|
4010
|
+
}
|
|
4011
|
+
const entity = await context.runtime.getEntityById(String(entityId));
|
|
4012
|
+
if (!entity) {
|
|
4013
|
+
return null;
|
|
4014
|
+
}
|
|
4015
|
+
return {
|
|
4016
|
+
entityId,
|
|
4017
|
+
label: entity.names?.[0],
|
|
4018
|
+
aliases: entity.names,
|
|
4019
|
+
handles: {},
|
|
4020
|
+
metadata: entity.metadata
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
runtime.registerMessageConnector(registration);
|
|
4025
|
+
return;
|
|
4026
|
+
}
|
|
4027
|
+
runtime.registerSendHandler(MATRIX_SERVICE_NAME, sendHandler);
|
|
4028
|
+
}
|
|
4029
|
+
async initialize(runtime) {
|
|
4030
|
+
this.runtime = runtime;
|
|
4031
|
+
this.defaultAccountId = normalizeMatrixAccountId(resolveDefaultMatrixAccountId(runtime));
|
|
4032
|
+
const accountIds = listMatrixAccountIds(runtime);
|
|
4033
|
+
for (const accountId of accountIds) {
|
|
4034
|
+
const settings = this.loadSettings(accountId);
|
|
4035
|
+
if (settings.enabled === false) {
|
|
4036
|
+
continue;
|
|
4037
|
+
}
|
|
4038
|
+
this.validateSettings(settings);
|
|
4039
|
+
const state = {
|
|
4040
|
+
accountId: normalizeMatrixAccountId(settings.accountId),
|
|
4041
|
+
settings,
|
|
4042
|
+
client: sdk.createClient({
|
|
4043
|
+
baseUrl: settings.homeserver,
|
|
4044
|
+
userId: settings.userId,
|
|
4045
|
+
accessToken: settings.accessToken,
|
|
4046
|
+
deviceId: settings.deviceId,
|
|
4047
|
+
verificationMethods: ["m.sas.v1"]
|
|
4048
|
+
}),
|
|
4049
|
+
connected: false,
|
|
4050
|
+
syncing: false
|
|
4051
|
+
};
|
|
4052
|
+
this.states.set(state.accountId, state);
|
|
4053
|
+
await this.initCrypto(state);
|
|
4054
|
+
this.startCryptoSnapshot(state);
|
|
4055
|
+
this.setupEventHandlers(state);
|
|
4056
|
+
await this.connect(state);
|
|
4057
|
+
MatrixService.registerSendHandlers(runtime, this, state.accountId);
|
|
4058
|
+
logger.info(`Matrix service initialized for ${settings.userId} on ${settings.homeserver}`);
|
|
4059
|
+
}
|
|
4060
|
+
if (this.states.size === 0) {
|
|
4061
|
+
const settings = this.loadSettings(this.defaultAccountId);
|
|
4062
|
+
this.validateSettings(settings);
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
loadSettings(accountId) {
|
|
4066
|
+
return resolveMatrixAccountSettings(this.runtime, accountId);
|
|
4067
|
+
}
|
|
4068
|
+
validateSettings(settings) {
|
|
4069
|
+
if (!settings.homeserver) {
|
|
4070
|
+
throw new MatrixConfigurationError("MATRIX_HOMESERVER is required", "MATRIX_HOMESERVER");
|
|
4071
|
+
}
|
|
4072
|
+
if (!settings.userId) {
|
|
4073
|
+
throw new MatrixConfigurationError("MATRIX_USER_ID is required", "MATRIX_USER_ID");
|
|
4074
|
+
}
|
|
4075
|
+
if (!settings.accessToken) {
|
|
4076
|
+
throw new MatrixConfigurationError("MATRIX_ACCESS_TOKEN is required", "MATRIX_ACCESS_TOKEN");
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
async initCrypto(state) {
|
|
4080
|
+
if (!state.settings.encryption) {
|
|
4081
|
+
return;
|
|
4082
|
+
}
|
|
4083
|
+
if (typeof state.client.initRustCrypto !== "function") {
|
|
4084
|
+
logger.warn("Matrix encryption requested but initRustCrypto is unavailable in this matrix-js-sdk build; messages in encrypted rooms will be unreadable.");
|
|
4085
|
+
return;
|
|
4086
|
+
}
|
|
4087
|
+
let cryptoUp = false;
|
|
4088
|
+
try {
|
|
4089
|
+
await Promise.resolve().then(() => (init_auto(), exports_auto));
|
|
4090
|
+
await this.restoreCryptoStore(state);
|
|
4091
|
+
await state.client.initRustCrypto({
|
|
4092
|
+
useIndexedDB: true,
|
|
4093
|
+
cryptoDatabasePrefix: cryptoDbPrefix(state.accountId)
|
|
4094
|
+
});
|
|
4095
|
+
logger.info(`Matrix E2EE initialized (persistent rust-crypto via IndexedDB) for ${state.settings.userId}`);
|
|
4096
|
+
cryptoUp = true;
|
|
4097
|
+
} catch (err) {
|
|
4098
|
+
logger.warn(`Matrix persistent crypto init failed (${err instanceof Error ? err.message : String(err)}); falling back to in-memory crypto (device will re-key on restart).`);
|
|
4099
|
+
}
|
|
4100
|
+
if (!cryptoUp) {
|
|
4101
|
+
try {
|
|
4102
|
+
await state.client.initRustCrypto({ useIndexedDB: false });
|
|
4103
|
+
logger.info(`Matrix E2EE initialized (in-memory rust-crypto) for ${state.settings.userId}`);
|
|
4104
|
+
cryptoUp = true;
|
|
4105
|
+
} catch (err) {
|
|
4106
|
+
logger.warn(`Matrix encryption failed to initialize (${err instanceof Error ? err.message : String(err)}); encrypted rooms will be unreadable, but the Matrix connection will continue.`);
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
if (cryptoUp) {
|
|
4110
|
+
await this.ensureCrossSigning(state);
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
async ensureCrossSigning(state) {
|
|
4114
|
+
const crypto = typeof state.client.getCrypto === "function" ? state.client.getCrypto() : undefined;
|
|
4115
|
+
if (!crypto) {
|
|
4116
|
+
return;
|
|
4117
|
+
}
|
|
4118
|
+
try {
|
|
4119
|
+
crypto.globalBlacklistUnverifiedDevices = false;
|
|
4120
|
+
crypto.setTrustCrossSignedDevices(true);
|
|
4121
|
+
if (await crypto.isCrossSigningReady()) {
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
await crypto.bootstrapCrossSigning({
|
|
4125
|
+
authUploadDeviceSigningKeys: async (makeRequest) => {
|
|
4126
|
+
try {
|
|
4127
|
+
return await makeRequest(null);
|
|
4128
|
+
} catch (err) {
|
|
4129
|
+
const data = err?.data;
|
|
4130
|
+
if (!data?.flows) {
|
|
4131
|
+
throw err;
|
|
4132
|
+
}
|
|
4133
|
+
if (!state.settings.password || !data.session) {
|
|
4134
|
+
logger.warn(`Matrix cross-signing upload for ${state.settings.userId} needs password UIA but ${state.settings.password ? "the server returned no challenge session" : "no MATRIX_PASSWORD is set"}; device ${state.settings.deviceId ?? "?"} stays uncross-signed, so exclude-insecure-devices senders will withhold keys.`);
|
|
4135
|
+
throw err;
|
|
4136
|
+
}
|
|
4137
|
+
return await makeRequest({
|
|
4138
|
+
type: "m.login.password",
|
|
4139
|
+
identifier: { type: "m.id.user", user: state.settings.userId },
|
|
4140
|
+
password: state.settings.password,
|
|
4141
|
+
session: data.session
|
|
4142
|
+
});
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
});
|
|
4146
|
+
logger.info(`Matrix cross-signing bootstrapped for ${state.settings.userId}; senders should now share megolm keys to this device.`);
|
|
4147
|
+
await crypto.checkKeyBackupAndEnable().catch(() => {});
|
|
4148
|
+
} catch (err) {
|
|
4149
|
+
logger.warn(`Matrix cross-signing bootstrap skipped (${err instanceof Error ? err.message : String(err)}); cohort senders in exclude-insecure-devices mode may withhold keys until this device is verified once from an operator's Matrix client.`);
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
async restoreCryptoStore(state) {
|
|
4153
|
+
try {
|
|
4154
|
+
const filePath = cryptoStoreFilePath(state.accountId);
|
|
4155
|
+
if (!existsSync(filePath)) {
|
|
4156
|
+
return;
|
|
4157
|
+
}
|
|
4158
|
+
const ciphertext = await readFile(filePath, "utf8");
|
|
4159
|
+
let snapshot;
|
|
4160
|
+
try {
|
|
4161
|
+
snapshot = v8Deserialize(decryptCryptoStore(state.settings.accessToken, ciphertext));
|
|
4162
|
+
} catch {
|
|
4163
|
+
logger.warn(`Matrix crypto-store restore skipped for ${state.accountId}: stored state could not be decrypted (token may have rotated).`);
|
|
4164
|
+
return;
|
|
4165
|
+
}
|
|
4166
|
+
await restoreDb(cryptoDbName(state.accountId), snapshot);
|
|
4167
|
+
logger.info(`Matrix restored persisted crypto store for ${state.accountId}`);
|
|
4168
|
+
} catch (err) {
|
|
4169
|
+
logger.warn(`Matrix crypto-store restore failed for ${state.accountId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
async saveCryptoStore(state) {
|
|
4173
|
+
if (typeof indexedDB === "undefined") {
|
|
4174
|
+
return;
|
|
4175
|
+
}
|
|
4176
|
+
try {
|
|
4177
|
+
const snapshot = await snapshotDb(cryptoDbName(state.accountId));
|
|
4178
|
+
const ciphertext = encryptCryptoStore(state.settings.accessToken, v8Serialize(snapshot));
|
|
4179
|
+
const filePath = cryptoStoreFilePath(state.accountId);
|
|
4180
|
+
const tmpPath = `${filePath}.${randomBytes(6).toString("hex")}.tmp`;
|
|
4181
|
+
await mkdir(join(resolveStateDir(), "matrix-keys"), { recursive: true, mode: 448 });
|
|
4182
|
+
await writeFile(tmpPath, ciphertext, { mode: 384 });
|
|
4183
|
+
await chmod(tmpPath, 384);
|
|
4184
|
+
await rename(tmpPath, filePath);
|
|
4185
|
+
} catch (err) {
|
|
4186
|
+
logger.warn(`Matrix crypto-store save failed for ${state.accountId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
startCryptoSnapshot(state) {
|
|
4190
|
+
if (!state.settings.encryption) {
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
const timer = setInterval(() => {
|
|
4194
|
+
this.saveCryptoStore(state);
|
|
4195
|
+
}, CRYPTO_SNAPSHOT_INTERVAL_MS);
|
|
4196
|
+
timer.unref?.();
|
|
4197
|
+
state.cryptoSnapshotTimer = timer;
|
|
4198
|
+
}
|
|
4199
|
+
setupEventHandlers(state) {
|
|
4200
|
+
state.client.on(sdk.ClientEvent.Sync, (syncState) => {
|
|
4201
|
+
if (syncState === "PREPARED") {
|
|
4202
|
+
state.syncing = true;
|
|
4203
|
+
logger.info("Matrix sync complete");
|
|
4204
|
+
this.runtime.emitEvent("MATRIX_SYNC_COMPLETE" /* SYNC_COMPLETE */, {
|
|
4205
|
+
runtime: this.runtime,
|
|
4206
|
+
accountId: state.accountId
|
|
4207
|
+
});
|
|
4208
|
+
}
|
|
4209
|
+
});
|
|
4210
|
+
state.client.on(sdk.RoomEvent.Timeline, (event, room, toStartOfTimeline) => {
|
|
4211
|
+
if (toStartOfTimeline)
|
|
4212
|
+
return;
|
|
4213
|
+
if (event.getSender() === state.settings.userId)
|
|
4214
|
+
return;
|
|
4215
|
+
if (event.isEncrypted() && event.getType() === "m.room.encrypted") {
|
|
4216
|
+
event.once(sdk.MatrixEventEvent.Decrypted, () => {
|
|
4217
|
+
if (event.getType() === "m.room.message") {
|
|
4218
|
+
this.handleRoomMessage(state, event, room);
|
|
4219
|
+
} else if (event.isDecryptionFailure()) {
|
|
4220
|
+
logger.warn(`Matrix could not decrypt event ${event.getId()} in ${event.getRoomId()} — the sender has not shared the megolm key with this device yet.`);
|
|
4221
|
+
}
|
|
4222
|
+
});
|
|
4223
|
+
return;
|
|
4224
|
+
}
|
|
4225
|
+
if (event.getType() !== "m.room.message")
|
|
4226
|
+
return;
|
|
4227
|
+
this.handleRoomMessage(state, event, room);
|
|
4228
|
+
});
|
|
4229
|
+
state.client.on(sdk.RoomMemberEvent.Membership, (event, member) => {
|
|
4230
|
+
if (member.userId !== state.settings.userId)
|
|
4231
|
+
return;
|
|
4232
|
+
if (member.membership === "invite" && state.settings.autoJoin) {
|
|
4233
|
+
const roomId = event.getRoomId();
|
|
4234
|
+
if (roomId) {
|
|
4235
|
+
logger.info(`Auto-joining room ${roomId}`);
|
|
4236
|
+
state.client.joinRoom(roomId).catch((err) => {
|
|
4237
|
+
logger.error(`Failed to auto-join room: ${err.message}`);
|
|
4238
|
+
});
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
});
|
|
4242
|
+
this.setupVerificationAutoAccept(state);
|
|
4243
|
+
}
|
|
4244
|
+
setupVerificationAutoAccept(state) {
|
|
4245
|
+
const crypto = state.client.getCrypto();
|
|
4246
|
+
if (!crypto || state.settings.verifyAllowlist.length === 0) {
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
state.client.on(CryptoEvent.VerificationRequestReceived, (request) => {
|
|
4250
|
+
this.handleVerificationRequest(state, request);
|
|
4251
|
+
});
|
|
4252
|
+
}
|
|
4253
|
+
async handleVerificationRequest(state, request) {
|
|
4254
|
+
const other = request.otherUserId;
|
|
4255
|
+
if (!state.settings.verifyAllowlist.includes(other)) {
|
|
4256
|
+
logger.warn(`Matrix rejecting verification request from non-allowlisted ${other}`);
|
|
4257
|
+
await request.cancel().catch(() => {});
|
|
4258
|
+
return;
|
|
4259
|
+
}
|
|
4260
|
+
logger.info(`Matrix auto-accepting SAS verification from ${other}`);
|
|
4261
|
+
try {
|
|
4262
|
+
if (canAcceptVerificationRequest(request)) {
|
|
4263
|
+
await request.accept();
|
|
4264
|
+
}
|
|
4265
|
+
const verifier = request.verifier ?? await this.awaitVerifier(request);
|
|
4266
|
+
if (!verifier) {
|
|
4267
|
+
await request.cancel().catch(() => {});
|
|
4268
|
+
return;
|
|
4269
|
+
}
|
|
4270
|
+
verifier.on(VerifierEvent.ShowSas, (callbacks) => {
|
|
4271
|
+
logger.info(`Matrix auto-confirming SAS with ${other}`);
|
|
4272
|
+
callbacks.confirm().catch(() => {});
|
|
4273
|
+
});
|
|
4274
|
+
await verifier.verify();
|
|
4275
|
+
logger.info(`Matrix device verification with ${other} complete; megolm keys should now flow.`);
|
|
4276
|
+
} catch (err) {
|
|
4277
|
+
logger.warn(`Matrix verification with ${other} failed or was cancelled (${err instanceof Error ? err.message : String(err)}).`);
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
awaitVerifier(request) {
|
|
4281
|
+
return new Promise((resolve) => {
|
|
4282
|
+
let fallbackTimer;
|
|
4283
|
+
const settle = (value) => {
|
|
4284
|
+
if (fallbackTimer)
|
|
4285
|
+
clearTimeout(fallbackTimer);
|
|
4286
|
+
request.off(VerificationRequestEvent.Change, onChange);
|
|
4287
|
+
resolve(value);
|
|
4288
|
+
};
|
|
4289
|
+
const onChange = () => {
|
|
4290
|
+
if (request.verifier) {
|
|
4291
|
+
settle(request.verifier);
|
|
4292
|
+
} else if (request.phase === VerificationPhase.Cancelled || request.phase === VerificationPhase.Done) {
|
|
4293
|
+
settle(undefined);
|
|
4294
|
+
} else if (request.phase === VerificationPhase.Ready && !fallbackTimer) {
|
|
4295
|
+
fallbackTimer = setTimeout(() => {
|
|
4296
|
+
if (!request.verifier) {
|
|
4297
|
+
request.startVerification("m.sas.v1").then(settle, () => settle(undefined));
|
|
4298
|
+
}
|
|
4299
|
+
}, VERIFICATION_START_FALLBACK_MS);
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
request.on(VerificationRequestEvent.Change, onChange);
|
|
4303
|
+
onChange();
|
|
4304
|
+
});
|
|
4305
|
+
}
|
|
4306
|
+
handleRoomMessage(state, event, room) {
|
|
4307
|
+
if (!room)
|
|
4308
|
+
return;
|
|
4309
|
+
const message = buildMatrixMessage(event, room);
|
|
4310
|
+
if (!message)
|
|
4311
|
+
return;
|
|
4312
|
+
const roomId = message.roomId;
|
|
4313
|
+
const isDirectRoom = room.getJoinedMemberCount() <= 2;
|
|
4314
|
+
if (state.settings.requireMention && !isDirectRoom) {
|
|
4315
|
+
const localpart = getMatrixLocalpart(state.settings.userId);
|
|
4316
|
+
const mentionPattern = new RegExp(`@?${escapeRegExp(localpart)}`, "i");
|
|
4317
|
+
if (!mentionPattern.test(message.content)) {
|
|
4318
|
+
return;
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
const matrixRoom = {
|
|
4322
|
+
roomId,
|
|
4323
|
+
name: room.name,
|
|
4324
|
+
topic: room.currentState.getStateEvents("m.room.topic", "")?.getContent()?.topic,
|
|
4325
|
+
canonicalAlias: room.getCanonicalAlias() || undefined,
|
|
4326
|
+
isEncrypted: room.hasEncryptionStateEvent(),
|
|
4327
|
+
isDirect: state.client.getAccountData(sdk.EventType.Direct)?.getContent()?.[message.sender || ""]?.includes(roomId) || false,
|
|
4328
|
+
memberCount: room.getJoinedMemberCount()
|
|
4329
|
+
};
|
|
4330
|
+
logger.debug(`Matrix message from ${message.senderInfo.displayName || message.sender} in ${room.name || roomId}: ${message.content.slice(0, 50)}...`);
|
|
4331
|
+
this.runtime.emitEvent("MATRIX_MESSAGE_RECEIVED" /* MESSAGE_RECEIVED */, {
|
|
4332
|
+
message,
|
|
4333
|
+
room: matrixRoom,
|
|
4334
|
+
runtime: this.runtime,
|
|
4335
|
+
accountId: state.accountId
|
|
4336
|
+
});
|
|
4337
|
+
this.dispatchToAgent(state, message, matrixRoom).catch((err) => logger.error(`Matrix dispatchToAgent failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
4338
|
+
}
|
|
4339
|
+
async dispatchToAgent(state, message, room) {
|
|
4340
|
+
const roomId = room.roomId;
|
|
4341
|
+
const entityId = createUniqueUuid(this.runtime, message.sender || roomId);
|
|
4342
|
+
const coreRoomId = createUniqueUuid(this.runtime, roomId);
|
|
4343
|
+
const worldId = createUniqueUuid(this.runtime, roomId);
|
|
4344
|
+
const channelType = room.memberCount <= 2 ? ChannelType.DM : ChannelType.GROUP;
|
|
4345
|
+
const displayName = message.senderInfo.displayName || message.sender || "Matrix user";
|
|
4346
|
+
await this.runtime.ensureConnection({
|
|
4347
|
+
entityId,
|
|
4348
|
+
roomId: coreRoomId,
|
|
4349
|
+
roomName: room.name || roomId,
|
|
4350
|
+
userName: displayName,
|
|
4351
|
+
name: displayName,
|
|
4352
|
+
source: MATRIX_SERVICE_NAME,
|
|
4353
|
+
channelId: roomId,
|
|
4354
|
+
type: channelType,
|
|
4355
|
+
worldId,
|
|
4356
|
+
worldName: room.name,
|
|
4357
|
+
userId: message.sender || roomId,
|
|
4358
|
+
metadata: { accountId: state.accountId }
|
|
4359
|
+
});
|
|
4360
|
+
const coreMessage = matrixMessageToMemory(this.runtime, message, channelType);
|
|
4361
|
+
const autoReplyRaw = this.runtime.getSetting("MATRIX_AUTO_REPLY");
|
|
4362
|
+
const autoReply = !lifeOpsPassiveConnectorsEnabled(this.runtime) && (autoReplyRaw === true || autoReplyRaw === "true");
|
|
4363
|
+
if (!autoReply) {
|
|
4364
|
+
try {
|
|
4365
|
+
await this.runtime.createMemory(coreMessage, "messages");
|
|
4366
|
+
} catch (err) {
|
|
4367
|
+
logger.warn(`Matrix inbound memory persist failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4368
|
+
}
|
|
4369
|
+
try {
|
|
4370
|
+
await this.runtime.emitEvent(EventType.MESSAGE_RECEIVED, {
|
|
4371
|
+
runtime: this.runtime,
|
|
4372
|
+
message: coreMessage,
|
|
4373
|
+
source: MATRIX_SERVICE_NAME
|
|
4374
|
+
});
|
|
4375
|
+
} catch (err) {
|
|
4376
|
+
logger.warn(`Matrix inbound event emit failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4377
|
+
}
|
|
4378
|
+
return;
|
|
4379
|
+
}
|
|
4380
|
+
if (!this.runtime.messageService) {
|
|
4381
|
+
logger.error("Matrix: runtime.messageService is unavailable; cannot process inbound message");
|
|
4382
|
+
return;
|
|
4383
|
+
}
|
|
4384
|
+
const callback = async (responseContent) => {
|
|
4385
|
+
const text = typeof responseContent.text === "string" ? responseContent.text.trim() : "";
|
|
4386
|
+
if (!text) {
|
|
4387
|
+
return [];
|
|
4388
|
+
}
|
|
4389
|
+
const result = await this.sendMessage(text, {
|
|
4390
|
+
accountId: state.accountId,
|
|
4391
|
+
roomId,
|
|
4392
|
+
threadId: message.threadId,
|
|
4393
|
+
replyTo: message.eventId
|
|
4394
|
+
});
|
|
4395
|
+
if (!result.success) {
|
|
4396
|
+
logger.warn(`Matrix reply send failed in ${roomId}: ${result.error}`);
|
|
4397
|
+
return [];
|
|
4398
|
+
}
|
|
4399
|
+
const outbound = {
|
|
4400
|
+
id: createUniqueUuid(this.runtime, result.eventId ?? `${roomId}:reply:${Date.now()}`),
|
|
4401
|
+
entityId: this.runtime.agentId,
|
|
4402
|
+
agentId: this.runtime.agentId,
|
|
4403
|
+
roomId: coreRoomId,
|
|
4404
|
+
content: {
|
|
4405
|
+
text,
|
|
4406
|
+
source: MATRIX_SERVICE_NAME,
|
|
4407
|
+
channelType,
|
|
4408
|
+
inReplyTo: coreMessage.id
|
|
4409
|
+
},
|
|
4410
|
+
createdAt: Date.now()
|
|
4411
|
+
};
|
|
4412
|
+
try {
|
|
4413
|
+
await this.runtime.createMemory(outbound, "messages");
|
|
4414
|
+
} catch (err) {
|
|
4415
|
+
logger.warn(`Matrix outbound memory persist failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4416
|
+
}
|
|
4417
|
+
return [outbound];
|
|
4418
|
+
};
|
|
4419
|
+
await this.runtime.messageService.handleMessage(this.runtime, coreMessage, callback);
|
|
4420
|
+
}
|
|
4421
|
+
async connect(state) {
|
|
4422
|
+
await state.client.startClient({ initialSyncLimit: 10 });
|
|
4423
|
+
state.connected = true;
|
|
4424
|
+
await new Promise((resolve) => {
|
|
4425
|
+
const listener = (syncState) => {
|
|
4426
|
+
if (syncState === "PREPARED") {
|
|
4427
|
+
state.client.removeListener(sdk.ClientEvent.Sync, listener);
|
|
4428
|
+
resolve();
|
|
4429
|
+
}
|
|
4430
|
+
};
|
|
4431
|
+
state.client.on(sdk.ClientEvent.Sync, listener);
|
|
4432
|
+
});
|
|
4433
|
+
for (const room of state.settings.rooms) {
|
|
4434
|
+
try {
|
|
4435
|
+
await this.joinRoom(room, state.accountId);
|
|
4436
|
+
} catch (err) {
|
|
4437
|
+
logger.warn(`Failed to join room ${room}: ${err}`);
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
async stop() {
|
|
4442
|
+
for (const state of this.states.values()) {
|
|
4443
|
+
if (state.cryptoSnapshotTimer) {
|
|
4444
|
+
clearInterval(state.cryptoSnapshotTimer);
|
|
4445
|
+
state.cryptoSnapshotTimer = undefined;
|
|
4446
|
+
}
|
|
4447
|
+
if (state.settings.encryption) {
|
|
4448
|
+
await this.saveCryptoStore(state);
|
|
4449
|
+
}
|
|
4450
|
+
state.client.stopClient();
|
|
4451
|
+
state.connected = false;
|
|
4452
|
+
state.syncing = false;
|
|
4453
|
+
}
|
|
4454
|
+
logger.info("Matrix service stopped");
|
|
4455
|
+
}
|
|
4456
|
+
isConnected() {
|
|
4457
|
+
const legacy = this;
|
|
4458
|
+
const states = this.states ?? new Map;
|
|
4459
|
+
if (states.size === 0 && typeof legacy.connected === "boolean") {
|
|
4460
|
+
return legacy.connected && (legacy.syncing ?? true);
|
|
4461
|
+
}
|
|
4462
|
+
return Array.from(states.values()).some((state) => state.connected && state.syncing);
|
|
4463
|
+
}
|
|
4464
|
+
getAccountId(runtime) {
|
|
4465
|
+
const legacy = this;
|
|
4466
|
+
const states = this.states ?? new Map;
|
|
4467
|
+
if (states.size === 0 && legacy.settings?.accountId) {
|
|
4468
|
+
return normalizeMatrixAccountId(legacy.settings.accountId);
|
|
4469
|
+
}
|
|
4470
|
+
return normalizeMatrixAccountId(this.defaultAccountId !== DEFAULT_MATRIX_ACCOUNT_ID ? this.defaultAccountId : runtime ? resolveDefaultMatrixAccountId(runtime) : this.defaultAccountId);
|
|
4471
|
+
}
|
|
4472
|
+
getUserId() {
|
|
4473
|
+
return this.getState().settings.userId;
|
|
4474
|
+
}
|
|
4475
|
+
getHomeserver() {
|
|
4476
|
+
return this.getState().settings.homeserver;
|
|
4477
|
+
}
|
|
4478
|
+
async getJoinedRooms(accountId) {
|
|
4479
|
+
const state = this.getState(accountId);
|
|
4480
|
+
const rooms = state.client.getRooms();
|
|
4481
|
+
return rooms.filter((room) => room.getMyMembership() === "join").map((room) => ({
|
|
4482
|
+
roomId: room.roomId,
|
|
4483
|
+
name: room.name,
|
|
4484
|
+
topic: room.currentState.getStateEvents("m.room.topic", "")?.getContent()?.topic,
|
|
4485
|
+
canonicalAlias: room.getCanonicalAlias() || undefined,
|
|
4486
|
+
isEncrypted: room.hasEncryptionStateEvent(),
|
|
4487
|
+
isDirect: false,
|
|
4488
|
+
memberCount: room.getJoinedMemberCount()
|
|
4489
|
+
}));
|
|
4490
|
+
}
|
|
4491
|
+
async getRoomMessages(matrixRoomId, limit, accountId) {
|
|
4492
|
+
const state = this.getState(accountId);
|
|
4493
|
+
const room = state.client.getRoom(matrixRoomId);
|
|
4494
|
+
if (!room) {
|
|
4495
|
+
return [];
|
|
4496
|
+
}
|
|
4497
|
+
const channelType = room.getJoinedMemberCount() <= 2 ? ChannelType.DM : ChannelType.GROUP;
|
|
4498
|
+
const events = room.getLiveTimeline().getEvents();
|
|
4499
|
+
const out = [];
|
|
4500
|
+
for (let i = events.length - 1;i >= 0 && out.length < limit; i -= 1) {
|
|
4501
|
+
const event = events[i];
|
|
4502
|
+
const message = buildMatrixMessage(event, room);
|
|
4503
|
+
if (message) {
|
|
4504
|
+
const memory = matrixMessageToMemory(this.runtime, message, channelType);
|
|
4505
|
+
memory.content.name = message.senderInfo.displayName || message.sender;
|
|
4506
|
+
out.push(memory);
|
|
4507
|
+
continue;
|
|
4508
|
+
}
|
|
4509
|
+
if (event.getType() === "m.room.encrypted" || event.isDecryptionFailure()) {
|
|
4510
|
+
const sender = event.getSender() || "unknown";
|
|
4511
|
+
const placeholder = matrixMessageToMemory(this.runtime, {
|
|
4512
|
+
eventId: event.getId() || "",
|
|
4513
|
+
roomId: matrixRoomId,
|
|
4514
|
+
sender,
|
|
4515
|
+
content: "\uD83D\uDD12 [end-to-end encrypted message this device can't read — its device isn't cross-signed, so senders withhold the decryption keys. This needs a one-time device verification (or the account password) to unblock; it is NOT a sync or pagination issue.]",
|
|
4516
|
+
timestamp: event.getTs()
|
|
4517
|
+
}, channelType);
|
|
4518
|
+
placeholder.content.name = room.getMember(sender)?.name || sender;
|
|
4519
|
+
out.push(placeholder);
|
|
4520
|
+
}
|
|
4521
|
+
}
|
|
4522
|
+
return out;
|
|
4523
|
+
}
|
|
4524
|
+
async sendMessage(text, options) {
|
|
4525
|
+
const state = this.getState(options?.accountId);
|
|
4526
|
+
if (!state.connected || !state.syncing) {
|
|
4527
|
+
throw new MatrixNotConnectedError;
|
|
4528
|
+
}
|
|
4529
|
+
const roomId = options?.roomId;
|
|
4530
|
+
if (!roomId?.trim()) {
|
|
4531
|
+
return { success: false, error: "Room ID is required" };
|
|
4532
|
+
}
|
|
4533
|
+
let resolvedRoomId = roomId.trim();
|
|
4534
|
+
if (isValidMatrixRoomAlias(resolvedRoomId)) {
|
|
4535
|
+
const resolved = await state.client.getRoomIdForAlias(resolvedRoomId);
|
|
4536
|
+
resolvedRoomId = resolved.room_id;
|
|
4537
|
+
}
|
|
4538
|
+
const content = {
|
|
4539
|
+
msgtype: sdk.MsgType.Text,
|
|
4540
|
+
body: text
|
|
4541
|
+
};
|
|
4542
|
+
if (options?.formatted) {
|
|
4543
|
+
content.format = "org.matrix.custom.html";
|
|
4544
|
+
content.formatted_body = text;
|
|
4545
|
+
}
|
|
4546
|
+
if (options?.threadId || options?.replyTo) {
|
|
4547
|
+
content["m.relates_to"] = {};
|
|
4548
|
+
if (options.threadId) {
|
|
4549
|
+
content["m.relates_to"].rel_type = sdk.RelationType.Thread;
|
|
4550
|
+
content["m.relates_to"].event_id = options.threadId;
|
|
4551
|
+
}
|
|
4552
|
+
if (options.replyTo) {
|
|
4553
|
+
content["m.relates_to"]["m.in_reply_to"] = {
|
|
4554
|
+
event_id: options.replyTo
|
|
4555
|
+
};
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
const response = await state.client.sendMessage(resolvedRoomId, content);
|
|
4559
|
+
const eventId = response.event_id;
|
|
4560
|
+
this.runtime.emitEvent("MATRIX_MESSAGE_SENT" /* MESSAGE_SENT */, {
|
|
4561
|
+
roomId: resolvedRoomId,
|
|
4562
|
+
eventId,
|
|
4563
|
+
content: text,
|
|
4564
|
+
runtime: this.runtime,
|
|
4565
|
+
accountId: state.accountId
|
|
4566
|
+
});
|
|
4567
|
+
return {
|
|
4568
|
+
success: true,
|
|
4569
|
+
eventId,
|
|
4570
|
+
roomId: resolvedRoomId
|
|
4571
|
+
};
|
|
4572
|
+
}
|
|
4573
|
+
async sendReaction(roomId, eventId, emoji, accountId) {
|
|
4574
|
+
const state = this.getState(accountId);
|
|
4575
|
+
if (!state.connected || !state.syncing) {
|
|
4576
|
+
throw new MatrixNotConnectedError;
|
|
4577
|
+
}
|
|
4578
|
+
const normalizedRoomId = roomId.trim();
|
|
4579
|
+
const normalizedEventId = eventId.trim();
|
|
4580
|
+
const normalizedEmoji = emoji.trim();
|
|
4581
|
+
if (!normalizedRoomId || !normalizedEventId || !normalizedEmoji) {
|
|
4582
|
+
return { success: false, error: "Room ID, event ID, and emoji are required" };
|
|
4583
|
+
}
|
|
4584
|
+
const content = {
|
|
4585
|
+
"m.relates_to": {
|
|
4586
|
+
rel_type: sdk.RelationType.Annotation,
|
|
4587
|
+
event_id: normalizedEventId,
|
|
4588
|
+
key: normalizedEmoji
|
|
4589
|
+
}
|
|
4590
|
+
};
|
|
4591
|
+
const response = await state.client.sendEvent(normalizedRoomId, sdk.EventType.Reaction, content);
|
|
4592
|
+
return {
|
|
4593
|
+
success: true,
|
|
4594
|
+
eventId: response.event_id,
|
|
4595
|
+
roomId: normalizedRoomId
|
|
4596
|
+
};
|
|
4597
|
+
}
|
|
4598
|
+
async joinRoom(roomIdOrAlias, accountId) {
|
|
4599
|
+
const state = this.getState(accountId);
|
|
4600
|
+
if (!state.connected || !state.syncing) {
|
|
4601
|
+
throw new MatrixNotConnectedError;
|
|
4602
|
+
}
|
|
4603
|
+
const normalizedRoomIdOrAlias = roomIdOrAlias.trim();
|
|
4604
|
+
if (!normalizedRoomIdOrAlias) {
|
|
4605
|
+
throw new Error("Matrix room ID or alias is required");
|
|
4606
|
+
}
|
|
4607
|
+
const response = await state.client.joinRoom(normalizedRoomIdOrAlias);
|
|
4608
|
+
const roomId = response.roomId;
|
|
4609
|
+
logger.info(`Joined room ${roomId}`);
|
|
4610
|
+
this.runtime.emitEvent("MATRIX_ROOM_JOINED" /* ROOM_JOINED */, {
|
|
4611
|
+
room: { roomId },
|
|
4612
|
+
runtime: this.runtime,
|
|
4613
|
+
accountId: state.accountId
|
|
4614
|
+
});
|
|
4615
|
+
return roomId;
|
|
4616
|
+
}
|
|
4617
|
+
async leaveRoom(roomId, accountId) {
|
|
4618
|
+
const state = this.getState(accountId);
|
|
4619
|
+
if (!state.connected || !state.syncing) {
|
|
4620
|
+
throw new MatrixNotConnectedError;
|
|
4621
|
+
}
|
|
4622
|
+
const normalizedRoomId = roomId.trim();
|
|
4623
|
+
if (!normalizedRoomId) {
|
|
4624
|
+
throw new Error("Matrix room ID is required");
|
|
4625
|
+
}
|
|
4626
|
+
await state.client.leave(normalizedRoomId);
|
|
4627
|
+
logger.info(`Left room ${normalizedRoomId}`);
|
|
4628
|
+
this.runtime.emitEvent("MATRIX_ROOM_LEFT" /* ROOM_LEFT */, {
|
|
4629
|
+
roomId: normalizedRoomId,
|
|
4630
|
+
runtime: this.runtime,
|
|
4631
|
+
accountId: state.accountId
|
|
4632
|
+
});
|
|
4633
|
+
}
|
|
4634
|
+
async sendTyping(roomId, typing, timeout = 30000, accountId) {
|
|
4635
|
+
const state = this.getState(accountId);
|
|
4636
|
+
if (!state.connected || !state.syncing) {
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4639
|
+
await state.client.sendTyping(roomId, typing, timeout);
|
|
4640
|
+
}
|
|
4641
|
+
async sendReadReceipt(roomId, eventId, accountId) {
|
|
4642
|
+
const state = this.getState(accountId);
|
|
4643
|
+
if (!state.connected || !state.syncing) {
|
|
4644
|
+
return;
|
|
4645
|
+
}
|
|
4646
|
+
await state.client.sendReadReceipt(new sdk.MatrixEvent({ event_id: eventId, room_id: roomId }));
|
|
4647
|
+
}
|
|
4648
|
+
async sendRoomMessage(roomIdOrAlias, content) {
|
|
4649
|
+
const text = typeof content.text === "string" ? content.text.trim() : "";
|
|
4650
|
+
if (!text) {
|
|
4651
|
+
return;
|
|
4652
|
+
}
|
|
4653
|
+
await this.sendMessage(text, {
|
|
4654
|
+
accountId: readMatrixAccountId(content) ?? this.getAccountId(),
|
|
4655
|
+
roomId: roomIdOrAlias
|
|
4656
|
+
});
|
|
4657
|
+
}
|
|
4658
|
+
async sendDirectMessage(roomIdOrAlias, content) {
|
|
4659
|
+
await this.sendRoomMessage(roomIdOrAlias, content);
|
|
4660
|
+
}
|
|
4661
|
+
async handleSendMessage(runtime, target, content) {
|
|
4662
|
+
const requestedAccountId = normalizeMatrixAccountId(target.accountId ?? readMatrixAccountId(content, target) ?? this.getAccountId());
|
|
4663
|
+
this.getState(requestedAccountId);
|
|
4664
|
+
const text = typeof content.text === "string" ? content.text.trim() : "";
|
|
4665
|
+
if (!text) {
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4668
|
+
const room = target.roomId ? await runtime.getRoom(target.roomId) : null;
|
|
4669
|
+
const roomIdOrAlias = String(target.channelId || room?.channelId || (typeof target.roomId === "string" && (isValidMatrixRoomId(target.roomId) || isValidMatrixRoomAlias(target.roomId)) ? target.roomId : "")).trim();
|
|
4670
|
+
if (!roomIdOrAlias) {
|
|
4671
|
+
throw new Error("Matrix target is missing a room ID or alias");
|
|
4672
|
+
}
|
|
4673
|
+
await this.sendMessage(text, {
|
|
4674
|
+
accountId: requestedAccountId,
|
|
4675
|
+
roomId: roomIdOrAlias,
|
|
4676
|
+
...extractMatrixSendOptions(content, target)
|
|
4677
|
+
});
|
|
4678
|
+
}
|
|
4679
|
+
getState(accountId = this.defaultAccountId) {
|
|
4680
|
+
const normalized = normalizeMatrixAccountId(accountId);
|
|
4681
|
+
const states = this.states ?? new Map;
|
|
4682
|
+
const state = states.get(normalized);
|
|
4683
|
+
if (state) {
|
|
4684
|
+
return state;
|
|
4685
|
+
}
|
|
4686
|
+
const legacy = this;
|
|
4687
|
+
if (legacy.settings) {
|
|
4688
|
+
return {
|
|
4689
|
+
accountId: normalizeMatrixAccountId(legacy.settings.accountId ?? normalized),
|
|
4690
|
+
settings: legacy.settings,
|
|
4691
|
+
client: legacy.client ?? {},
|
|
4692
|
+
connected: legacy.connected ?? true,
|
|
4693
|
+
syncing: legacy.syncing ?? true
|
|
4694
|
+
};
|
|
4695
|
+
}
|
|
4696
|
+
throw new Error(`Matrix account '${normalized}' is not available in this service instance`);
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
// src/connector-account-provider.ts
|
|
4700
|
+
var MATRIX_PROVIDER_ID = "matrix";
|
|
4701
|
+
function accountKey(settings) {
|
|
4702
|
+
if (settings.homeserver && settings.userId) {
|
|
4703
|
+
return `${settings.homeserver}/${settings.userId}`;
|
|
4704
|
+
}
|
|
4705
|
+
return normalizeMatrixAccountId(settings.accountId);
|
|
4706
|
+
}
|
|
4707
|
+
function toConnectorAccount(settings) {
|
|
4708
|
+
const now = Date.now();
|
|
4709
|
+
const configured = Boolean(settings.homeserver && settings.userId && settings.accessToken);
|
|
4710
|
+
const personal = settings.personal === true;
|
|
4711
|
+
return {
|
|
4712
|
+
id: normalizeMatrixAccountId(settings.accountId),
|
|
4713
|
+
provider: MATRIX_PROVIDER_ID,
|
|
4714
|
+
label: settings.userId || settings.accountId,
|
|
4715
|
+
role: personal ? "OWNER" : "AGENT",
|
|
4716
|
+
purpose: personal ? ["messaging", "reading"] : ["messaging"],
|
|
4717
|
+
accessGate: personal ? "owner_binding" : "open",
|
|
4718
|
+
status: settings.enabled !== false && configured ? "connected" : "disabled",
|
|
4719
|
+
externalId: accountKey(settings),
|
|
4720
|
+
displayHandle: settings.userId || undefined,
|
|
4721
|
+
createdAt: now,
|
|
4722
|
+
updatedAt: now,
|
|
4723
|
+
metadata: {
|
|
4724
|
+
homeserver: settings.homeserver ?? "",
|
|
4725
|
+
userId: settings.userId ?? "",
|
|
4726
|
+
deviceId: settings.deviceId ?? "",
|
|
4727
|
+
encryption: settings.encryption ?? false,
|
|
4728
|
+
autoJoin: settings.autoJoin ?? false,
|
|
4729
|
+
personal
|
|
4730
|
+
}
|
|
4731
|
+
};
|
|
4732
|
+
}
|
|
4733
|
+
function createMatrixConnectorAccountProvider(runtime) {
|
|
4734
|
+
return {
|
|
4735
|
+
provider: MATRIX_PROVIDER_ID,
|
|
4736
|
+
label: "Matrix",
|
|
4737
|
+
listAccounts: async (_manager) => {
|
|
4738
|
+
const ids = listMatrixAccountIds(runtime);
|
|
4739
|
+
if (ids.length === 0) {
|
|
4740
|
+
return [
|
|
4741
|
+
toConnectorAccount(resolveMatrixAccountSettings(runtime, DEFAULT_MATRIX_ACCOUNT_ID))
|
|
4742
|
+
];
|
|
4743
|
+
}
|
|
4744
|
+
return ids.map((id) => toConnectorAccount(resolveMatrixAccountSettings(runtime, id)));
|
|
4745
|
+
},
|
|
4746
|
+
createAccount: async (input, _manager) => {
|
|
4747
|
+
return {
|
|
4748
|
+
...input,
|
|
4749
|
+
provider: MATRIX_PROVIDER_ID,
|
|
4750
|
+
role: input.role ?? "AGENT",
|
|
4751
|
+
purpose: input.purpose ?? ["messaging"],
|
|
4752
|
+
accessGate: input.accessGate ?? "open",
|
|
4753
|
+
status: input.status ?? "pending"
|
|
4754
|
+
};
|
|
4755
|
+
},
|
|
4756
|
+
patchAccount: async (_accountId, patch, _manager) => {
|
|
4757
|
+
return { ...patch, provider: MATRIX_PROVIDER_ID };
|
|
4758
|
+
},
|
|
4759
|
+
deleteAccount: async (_accountId, _manager) => {}
|
|
4760
|
+
};
|
|
4761
|
+
}
|
|
4762
|
+
|
|
4763
|
+
// src/workflow-credential-provider.ts
|
|
4764
|
+
import { Service as Service2 } from "@elizaos/core";
|
|
4765
|
+
var WORKFLOW_CREDENTIAL_PROVIDER_TYPE = "workflow_credential_provider";
|
|
4766
|
+
var SUPPORTED = ["matrixApi"];
|
|
4767
|
+
|
|
4768
|
+
class MatrixWorkflowCredentialProvider extends Service2 {
|
|
4769
|
+
static serviceType = WORKFLOW_CREDENTIAL_PROVIDER_TYPE;
|
|
4770
|
+
capabilityDescription = "Supplies Matrix credentials to the workflow plugin.";
|
|
4771
|
+
static async start(runtime) {
|
|
4772
|
+
return new MatrixWorkflowCredentialProvider(runtime);
|
|
4773
|
+
}
|
|
4774
|
+
async stop() {}
|
|
4775
|
+
async resolve(_userId, credType) {
|
|
4776
|
+
if (credType !== "matrixApi")
|
|
4777
|
+
return null;
|
|
4778
|
+
const accessToken = this.runtime.getSetting("MATRIX_ACCESS_TOKEN");
|
|
4779
|
+
const homeserver = this.runtime.getSetting("MATRIX_HOMESERVER");
|
|
4780
|
+
if (!accessToken?.trim() || !homeserver?.trim())
|
|
4781
|
+
return null;
|
|
4782
|
+
return {
|
|
4783
|
+
status: "credential_data",
|
|
4784
|
+
data: { accessToken: accessToken.trim(), homeserverUrl: homeserver.trim() }
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
checkCredentialTypes(credTypes) {
|
|
4788
|
+
return {
|
|
4789
|
+
supported: credTypes.filter((t) => SUPPORTED.includes(t)),
|
|
4790
|
+
unsupported: credTypes.filter((t) => !SUPPORTED.includes(t))
|
|
4791
|
+
};
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
|
|
4795
|
+
// src/index.ts
|
|
4796
|
+
var matrixPlugin = {
|
|
4797
|
+
name: "matrix",
|
|
4798
|
+
description: "Matrix messaging integration plugin for ElizaOS with E2EE support",
|
|
4799
|
+
services: [MatrixService, MatrixWorkflowCredentialProvider],
|
|
4800
|
+
actions: [],
|
|
4801
|
+
providers: [],
|
|
4802
|
+
tests: [],
|
|
4803
|
+
autoEnable: {
|
|
4804
|
+
connectorKeys: ["matrix"]
|
|
4805
|
+
},
|
|
4806
|
+
init: async (_config, runtime) => {
|
|
4807
|
+
try {
|
|
4808
|
+
const manager = getConnectorAccountManager(runtime);
|
|
4809
|
+
manager.registerProvider(createMatrixConnectorAccountProvider(runtime));
|
|
4810
|
+
} catch (err) {
|
|
4811
|
+
logger2.warn({
|
|
4812
|
+
src: "plugin:matrix",
|
|
4813
|
+
err: err instanceof Error ? err.message : String(err)
|
|
4814
|
+
}, "Failed to register Matrix provider with ConnectorAccountManager");
|
|
4815
|
+
}
|
|
4816
|
+
const homeserver = runtime.getSetting("MATRIX_HOMESERVER");
|
|
4817
|
+
const userId = runtime.getSetting("MATRIX_USER_ID");
|
|
4818
|
+
const accessToken = runtime.getSetting("MATRIX_ACCESS_TOKEN");
|
|
4819
|
+
logger2.info("=".repeat(60));
|
|
4820
|
+
logger2.info("Matrix Plugin Configuration");
|
|
4821
|
+
logger2.info("=".repeat(60));
|
|
4822
|
+
logger2.info(` Homeserver: ${homeserver ? `✓ ${homeserver}` : "✗ Missing (required)"}`);
|
|
4823
|
+
logger2.info(` User ID: ${userId ? `✓ ${userId}` : "✗ Missing (required)"}`);
|
|
4824
|
+
logger2.info(` Access Token: ${accessToken ? "✓ Set" : "✗ Missing (required)"}`);
|
|
4825
|
+
logger2.info("=".repeat(60));
|
|
4826
|
+
const missing = [];
|
|
4827
|
+
if (!homeserver)
|
|
4828
|
+
missing.push("MATRIX_HOMESERVER");
|
|
4829
|
+
if (!userId)
|
|
4830
|
+
missing.push("MATRIX_USER_ID");
|
|
4831
|
+
if (!accessToken)
|
|
4832
|
+
missing.push("MATRIX_ACCESS_TOKEN");
|
|
4833
|
+
if (missing.length > 0) {
|
|
4834
|
+
logger2.warn(`Matrix plugin: Missing required configuration: ${missing.join(", ")}`);
|
|
4835
|
+
}
|
|
4836
|
+
const deviceId = runtime.getSetting("MATRIX_DEVICE_ID");
|
|
4837
|
+
const rooms = runtime.getSetting("MATRIX_ROOMS");
|
|
4838
|
+
const autoJoin = runtime.getSetting("MATRIX_AUTO_JOIN");
|
|
4839
|
+
const encryption = runtime.getSetting("MATRIX_ENCRYPTION");
|
|
4840
|
+
const requireMention = runtime.getSetting("MATRIX_REQUIRE_MENTION");
|
|
4841
|
+
if (deviceId) {
|
|
4842
|
+
logger2.info(` Device ID: ${deviceId}`);
|
|
4843
|
+
}
|
|
4844
|
+
if (rooms) {
|
|
4845
|
+
logger2.info(` Auto-join Rooms: ${rooms}`);
|
|
4846
|
+
}
|
|
4847
|
+
if (autoJoin === "true") {
|
|
4848
|
+
logger2.info(" Auto-join Invites: ✓ Enabled");
|
|
4849
|
+
}
|
|
4850
|
+
if (encryption === "true") {
|
|
4851
|
+
logger2.info(" End-to-End Encryption: ✓ Enabled");
|
|
4852
|
+
}
|
|
4853
|
+
if (requireMention === "true") {
|
|
4854
|
+
logger2.info(" Require Mention: ✓ Enabled (will only respond to mentions in rooms)");
|
|
4855
|
+
}
|
|
4856
|
+
},
|
|
4857
|
+
async dispose(runtime) {
|
|
4858
|
+
await MatrixService.stopRuntime(runtime);
|
|
4859
|
+
}
|
|
4860
|
+
};
|
|
4861
|
+
var src_default = matrixPlugin;
|
|
4862
|
+
export {
|
|
4863
|
+
resolveMatrixAccountSettings,
|
|
4864
|
+
resolveDefaultMatrixAccountId,
|
|
4865
|
+
readMatrixAccountId,
|
|
4866
|
+
normalizeMatrixAccountId,
|
|
4867
|
+
matrixMxcToHttp,
|
|
4868
|
+
listMatrixAccountIds,
|
|
4869
|
+
isValidMatrixUserId,
|
|
4870
|
+
isValidMatrixRoomId,
|
|
4871
|
+
isValidMatrixRoomAlias,
|
|
4872
|
+
getMatrixUserDisplayName,
|
|
4873
|
+
getMatrixServerpart,
|
|
4874
|
+
getMatrixLocalpart,
|
|
4875
|
+
src_default as default,
|
|
4876
|
+
MatrixServiceNotInitializedError,
|
|
4877
|
+
MatrixService,
|
|
4878
|
+
MatrixPluginError,
|
|
4879
|
+
MatrixNotConnectedError,
|
|
4880
|
+
MatrixEventTypes,
|
|
4881
|
+
MatrixConfigurationError,
|
|
4882
|
+
MatrixApiError,
|
|
4883
|
+
MAX_MATRIX_MESSAGE_LENGTH,
|
|
4884
|
+
MATRIX_SERVICE_NAME,
|
|
4885
|
+
DEFAULT_MATRIX_ACCOUNT_ID
|
|
4886
|
+
};
|
|
4887
|
+
|
|
4888
|
+
//# debugId=FBDBF44969C9B46A64756E2164756E21
|