@dxos/functions-runtime-cloudflare 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +155 -322
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +155 -322
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/functions-client.d.ts +0 -5
- package/dist/types/src/functions-client.d.ts.map +1 -1
- package/dist/types/src/internal/data-service-impl.d.ts +1 -1
- package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/query-service-impl.d.ts +3 -9
- package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/queue-service-impl.d.ts +3 -2
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/service-container.d.ts +2 -2
- package/dist/types/src/internal/service-container.d.ts.map +1 -1
- package/dist/types/src/internal/utils.d.ts.map +1 -1
- package/dist/types/src/queues-api.d.ts +7 -3
- package/dist/types/src/queues-api.d.ts.map +1 -1
- package/dist/types/src/space-proxy.d.ts.map +1 -1
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/functions-client.ts +1 -7
- package/src/internal/data-service-impl.ts +9 -3
- package/src/internal/query-service-impl.ts +8 -62
- package/src/internal/queue-service-impl.ts +28 -24
- package/src/internal/service-container.ts +28 -7
- package/src/logger.ts +10 -8
- package/src/queues-api.ts +23 -4
- package/src/space-proxy.ts +1 -1
- package/src/wrap-handler-for-cloudflare.ts +1 -1
- package/dist/types/src/internal/adapter.d.ts +0 -12
- package/dist/types/src/internal/adapter.d.ts.map +0 -1
- package/src/internal/adapter.ts +0 -48
|
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module';const require = createRequire(import
|
|
|
3
3
|
// src/functions-client.ts
|
|
4
4
|
import { Resource as Resource2 } from "@dxos/context";
|
|
5
5
|
import { EchoClient } from "@dxos/echo-db";
|
|
6
|
-
import { invariant as
|
|
6
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
7
7
|
|
|
8
8
|
// src/internal/data-service-impl.ts
|
|
9
9
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
@@ -17,6 +17,7 @@ import { log } from "@dxos/log";
|
|
|
17
17
|
var copyUint8Array = (value) => new Uint8Array(value);
|
|
18
18
|
|
|
19
19
|
// src/internal/data-service-impl.ts
|
|
20
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
20
21
|
function _ts_add_disposable_resource(env, value, async) {
|
|
21
22
|
if (value !== null && value !== void 0) {
|
|
22
23
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -82,7 +83,6 @@ function _ts_dispose_resources(env) {
|
|
|
82
83
|
return next();
|
|
83
84
|
})(env);
|
|
84
85
|
}
|
|
85
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
86
86
|
var DataServiceImpl = class {
|
|
87
87
|
_executionContext;
|
|
88
88
|
_dataService;
|
|
@@ -93,15 +93,7 @@ var DataServiceImpl = class {
|
|
|
93
93
|
}
|
|
94
94
|
subscribe({ subscriptionId, spaceId }) {
|
|
95
95
|
return new Stream(({ next }) => {
|
|
96
|
-
invariant(SpaceId.isValid(spaceId), void 0, {
|
|
97
|
-
F: __dxlog_file,
|
|
98
|
-
L: 39,
|
|
99
|
-
S: this,
|
|
100
|
-
A: [
|
|
101
|
-
"SpaceId.isValid(spaceId)",
|
|
102
|
-
""
|
|
103
|
-
]
|
|
104
|
-
});
|
|
96
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
105
97
|
this.dataSubscriptions.set(subscriptionId, {
|
|
106
98
|
spaceId,
|
|
107
99
|
next
|
|
@@ -121,12 +113,7 @@ var DataServiceImpl = class {
|
|
|
121
113
|
if (addIds) {
|
|
122
114
|
log.info("request documents", {
|
|
123
115
|
count: addIds.length
|
|
124
|
-
}, {
|
|
125
|
-
F: __dxlog_file,
|
|
126
|
-
L: 59,
|
|
127
|
-
S: this,
|
|
128
|
-
C: (f, a) => f(...a)
|
|
129
|
-
});
|
|
116
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 104, S: this });
|
|
130
117
|
for (const documentId of addIds) {
|
|
131
118
|
const env = {
|
|
132
119
|
stack: [],
|
|
@@ -139,21 +126,11 @@ var DataServiceImpl = class {
|
|
|
139
126
|
documentId,
|
|
140
127
|
spaceId: sub.spaceId,
|
|
141
128
|
found: !!document
|
|
142
|
-
}, {
|
|
143
|
-
F: __dxlog_file,
|
|
144
|
-
L: 63,
|
|
145
|
-
S: this,
|
|
146
|
-
C: (f, a) => f(...a)
|
|
147
|
-
});
|
|
129
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 116, S: this });
|
|
148
130
|
if (!document) {
|
|
149
131
|
log.warn("not found", {
|
|
150
132
|
documentId
|
|
151
|
-
}, {
|
|
152
|
-
F: __dxlog_file,
|
|
153
|
-
L: 65,
|
|
154
|
-
S: this,
|
|
155
|
-
C: (f, a) => f(...a)
|
|
156
|
-
});
|
|
133
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 122, S: this });
|
|
157
134
|
continue;
|
|
158
135
|
}
|
|
159
136
|
sub.next({
|
|
@@ -182,10 +159,8 @@ var DataServiceImpl = class {
|
|
|
182
159
|
hasError: false
|
|
183
160
|
};
|
|
184
161
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
initialValue
|
|
188
|
-
}), false);
|
|
162
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 153, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
163
|
+
const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, spaceId, initialValue), false);
|
|
189
164
|
return {
|
|
190
165
|
documentId: response.documentId
|
|
191
166
|
};
|
|
@@ -205,6 +180,9 @@ var DataServiceImpl = class {
|
|
|
205
180
|
}));
|
|
206
181
|
try {
|
|
207
182
|
for (const update of updates ?? []) {
|
|
183
|
+
if (!update.mutation) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
208
186
|
await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
|
|
209
187
|
}
|
|
210
188
|
} catch (error) {
|
|
@@ -235,12 +213,7 @@ var DataServiceImpl = class {
|
|
|
235
213
|
});
|
|
236
214
|
}
|
|
237
215
|
async updateIndexes() {
|
|
238
|
-
log.
|
|
239
|
-
F: __dxlog_file,
|
|
240
|
-
L: 133,
|
|
241
|
-
S: this,
|
|
242
|
-
C: (f, a) => f(...a)
|
|
243
|
-
});
|
|
216
|
+
log.verbose("updateIndexes called, but it is a no-op in EDGE env.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 211, S: this });
|
|
244
217
|
}
|
|
245
218
|
async waitUntilHeadsReplicated({ heads: _heads }) {
|
|
246
219
|
throw new NotImplementedError({
|
|
@@ -250,83 +223,10 @@ var DataServiceImpl = class {
|
|
|
250
223
|
};
|
|
251
224
|
|
|
252
225
|
// src/internal/query-service-impl.ts
|
|
253
|
-
import * as Schema from "effect/Schema";
|
|
254
226
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
255
|
-
import { QueryAST } from "@dxos/echo-protocol";
|
|
256
227
|
import { NotImplementedError as NotImplementedError2, RuntimeServiceError as RuntimeServiceError2 } from "@dxos/errors";
|
|
257
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
258
|
-
import { PublicKey } from "@dxos/keys";
|
|
259
|
-
import { SpaceId as SpaceId3 } from "@dxos/keys";
|
|
260
228
|
import { log as log2 } from "@dxos/log";
|
|
261
|
-
|
|
262
|
-
// src/internal/adapter.ts
|
|
263
|
-
import { failUndefined } from "@dxos/debug";
|
|
264
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
265
|
-
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
266
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/adapter.ts";
|
|
267
|
-
var queryToDataServiceRequest = (query) => {
|
|
268
|
-
const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();
|
|
269
|
-
invariant2(options?.spaceIds?.length === 1, "Only one space is supported", {
|
|
270
|
-
F: __dxlog_file2,
|
|
271
|
-
L: 13,
|
|
272
|
-
S: void 0,
|
|
273
|
-
A: [
|
|
274
|
-
"options?.spaceIds?.length === 1",
|
|
275
|
-
"'Only one space is supported'"
|
|
276
|
-
]
|
|
277
|
-
});
|
|
278
|
-
invariant2(filter.type === "object", "Only object filters are supported", {
|
|
279
|
-
F: __dxlog_file2,
|
|
280
|
-
L: 14,
|
|
281
|
-
S: void 0,
|
|
282
|
-
A: [
|
|
283
|
-
"filter.type === 'object'",
|
|
284
|
-
"'Only object filters are supported'"
|
|
285
|
-
]
|
|
286
|
-
});
|
|
287
|
-
const spaceId = options.spaceIds[0];
|
|
288
|
-
invariant2(SpaceId2.isValid(spaceId), void 0, {
|
|
289
|
-
F: __dxlog_file2,
|
|
290
|
-
L: 17,
|
|
291
|
-
S: void 0,
|
|
292
|
-
A: [
|
|
293
|
-
"SpaceId.isValid(spaceId)",
|
|
294
|
-
""
|
|
295
|
-
]
|
|
296
|
-
});
|
|
297
|
-
return {
|
|
298
|
-
spaceId,
|
|
299
|
-
type: filter.typename ?? void 0,
|
|
300
|
-
objectIds: [
|
|
301
|
-
...filter.id ?? []
|
|
302
|
-
]
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
var isSimpleSelectionQuery = (query) => {
|
|
306
|
-
switch (query.type) {
|
|
307
|
-
case "options": {
|
|
308
|
-
const maybeFilter = isSimpleSelectionQuery(query.query);
|
|
309
|
-
if (!maybeFilter) {
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
return {
|
|
313
|
-
filter: maybeFilter.filter,
|
|
314
|
-
options: query.options
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
case "select": {
|
|
318
|
-
return {
|
|
319
|
-
filter: query.filter,
|
|
320
|
-
options: void 0
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
default: {
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
// src/internal/query-service-impl.ts
|
|
229
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
330
230
|
function _ts_add_disposable_resource2(env, value, async) {
|
|
331
231
|
if (value !== null && value !== void 0) {
|
|
332
232
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -392,7 +292,6 @@ function _ts_dispose_resources2(env) {
|
|
|
392
292
|
return next();
|
|
393
293
|
})(env);
|
|
394
294
|
}
|
|
395
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
396
295
|
var QueryServiceImpl = class {
|
|
397
296
|
_executionContext;
|
|
398
297
|
_dataService;
|
|
@@ -404,24 +303,7 @@ var QueryServiceImpl = class {
|
|
|
404
303
|
execQuery(request) {
|
|
405
304
|
log2.info("execQuery", {
|
|
406
305
|
request
|
|
407
|
-
}, {
|
|
408
|
-
F: __dxlog_file3,
|
|
409
|
-
L: 34,
|
|
410
|
-
S: this,
|
|
411
|
-
C: (f, a) => f(...a)
|
|
412
|
-
});
|
|
413
|
-
const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));
|
|
414
|
-
const requestedSpaceIds = getTargetSpacesForQuery(query);
|
|
415
|
-
invariant3(requestedSpaceIds.length === 1, "Only one space is supported", {
|
|
416
|
-
F: __dxlog_file3,
|
|
417
|
-
L: 37,
|
|
418
|
-
S: this,
|
|
419
|
-
A: [
|
|
420
|
-
"requestedSpaceIds.length === 1",
|
|
421
|
-
"'Only one space is supported'"
|
|
422
|
-
]
|
|
423
|
-
});
|
|
424
|
-
const spaceId = requestedSpaceIds[0];
|
|
306
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
|
|
425
307
|
return Stream2.fromPromise((async () => {
|
|
426
308
|
try {
|
|
427
309
|
const env = {
|
|
@@ -432,37 +314,13 @@ var QueryServiceImpl = class {
|
|
|
432
314
|
try {
|
|
433
315
|
this._queryCount++;
|
|
434
316
|
log2.info("begin query", {
|
|
435
|
-
|
|
436
|
-
}, {
|
|
437
|
-
|
|
438
|
-
L: 44,
|
|
439
|
-
S: this,
|
|
440
|
-
C: (f, a) => f(...a)
|
|
441
|
-
});
|
|
442
|
-
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.queryDocuments(this._executionContext, queryToDataServiceRequest(query)), false);
|
|
317
|
+
request
|
|
318
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 93, S: this });
|
|
319
|
+
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
|
|
443
320
|
log2.info("query response", {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}, {
|
|
448
|
-
F: __dxlog_file3,
|
|
449
|
-
L: 49,
|
|
450
|
-
S: this,
|
|
451
|
-
C: (f, a) => f(...a)
|
|
452
|
-
});
|
|
453
|
-
return {
|
|
454
|
-
results: queryResponse.results.map((object) => ({
|
|
455
|
-
id: object.objectId,
|
|
456
|
-
spaceId,
|
|
457
|
-
spaceKey: PublicKey.ZERO,
|
|
458
|
-
documentId: object.document.documentId,
|
|
459
|
-
// Rank 1 for predicate matches where ranking is not determined.
|
|
460
|
-
rank: 1,
|
|
461
|
-
// Copy returned object to avoid hanging RPC stub.
|
|
462
|
-
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
463
|
-
documentAutomerge: copyUint8Array(object.document.data)
|
|
464
|
-
}))
|
|
465
|
-
};
|
|
321
|
+
resultCount: queryResponse.results?.length
|
|
322
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
|
|
323
|
+
return structuredClone(queryResponse);
|
|
466
324
|
} catch (e) {
|
|
467
325
|
env.error = e;
|
|
468
326
|
env.hasError = true;
|
|
@@ -472,17 +330,10 @@ var QueryServiceImpl = class {
|
|
|
472
330
|
} catch (error) {
|
|
473
331
|
log2.error("query failed", {
|
|
474
332
|
err: error
|
|
475
|
-
}, {
|
|
476
|
-
F: __dxlog_file3,
|
|
477
|
-
L: 66,
|
|
478
|
-
S: this,
|
|
479
|
-
C: (f, a) => f(...a)
|
|
480
|
-
});
|
|
333
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
|
|
481
334
|
throw new RuntimeServiceError2({
|
|
482
335
|
message: `Query execution failed (queryCount=${this._queryCount})`,
|
|
483
336
|
context: {
|
|
484
|
-
spaceId,
|
|
485
|
-
filter: request.filter,
|
|
486
337
|
queryCount: this._queryCount
|
|
487
338
|
},
|
|
488
339
|
cause: error
|
|
@@ -501,26 +352,9 @@ var QueryServiceImpl = class {
|
|
|
501
352
|
});
|
|
502
353
|
}
|
|
503
354
|
};
|
|
504
|
-
var getTargetSpacesForQuery = (query) => {
|
|
505
|
-
const spaces = /* @__PURE__ */ new Set();
|
|
506
|
-
const visitor = (node) => {
|
|
507
|
-
if (node.type === "options") {
|
|
508
|
-
if (node.options.spaceIds) {
|
|
509
|
-
for (const spaceId of node.options.spaceIds) {
|
|
510
|
-
spaces.add(SpaceId3.make(spaceId));
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
QueryAST.visit(query, visitor);
|
|
516
|
-
return [
|
|
517
|
-
...spaces
|
|
518
|
-
];
|
|
519
|
-
};
|
|
520
355
|
|
|
521
356
|
// src/internal/queue-service-impl.ts
|
|
522
|
-
import {
|
|
523
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
357
|
+
import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
|
|
524
358
|
function _ts_add_disposable_resource3(env, value, async) {
|
|
525
359
|
if (value !== null && value !== void 0) {
|
|
526
360
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -586,7 +420,6 @@ function _ts_dispose_resources3(env) {
|
|
|
586
420
|
return next();
|
|
587
421
|
})(env);
|
|
588
422
|
}
|
|
589
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/queue-service-impl.ts";
|
|
590
423
|
var QueueServiceImpl = class {
|
|
591
424
|
_ctx;
|
|
592
425
|
_queueService;
|
|
@@ -595,19 +428,6 @@ var QueueServiceImpl = class {
|
|
|
595
428
|
this._queueService = _queueService;
|
|
596
429
|
}
|
|
597
430
|
async queryQueue(request) {
|
|
598
|
-
const { query } = request;
|
|
599
|
-
const { queueIds, ...filter } = query;
|
|
600
|
-
const spaceId = query.spaceId;
|
|
601
|
-
const queueId = queueIds?.[0];
|
|
602
|
-
invariant4(request.query.queuesNamespace, void 0, {
|
|
603
|
-
F: __dxlog_file4,
|
|
604
|
-
L: 19,
|
|
605
|
-
S: this,
|
|
606
|
-
A: [
|
|
607
|
-
"request.query.queuesNamespace",
|
|
608
|
-
""
|
|
609
|
-
]
|
|
610
|
-
});
|
|
611
431
|
try {
|
|
612
432
|
const env = {
|
|
613
433
|
stack: [],
|
|
@@ -615,10 +435,8 @@ var QueueServiceImpl = class {
|
|
|
615
435
|
hasError: false
|
|
616
436
|
};
|
|
617
437
|
try {
|
|
618
|
-
const result = _ts_add_disposable_resource3(env, await this._queueService.
|
|
438
|
+
const result = _ts_add_disposable_resource3(env, await this._queueService.queryQueue(this._ctx, request), false);
|
|
619
439
|
return {
|
|
620
|
-
// Copy returned object to avoid hanging RPC stub
|
|
621
|
-
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
622
440
|
objects: structuredClone(result.objects),
|
|
623
441
|
nextCursor: result.nextCursor,
|
|
624
442
|
prevCursor: result.prevCursor
|
|
@@ -630,22 +448,35 @@ var QueueServiceImpl = class {
|
|
|
630
448
|
_ts_dispose_resources3(env);
|
|
631
449
|
}
|
|
632
450
|
} catch (error) {
|
|
451
|
+
const { query } = request;
|
|
633
452
|
throw RuntimeServiceError3.wrap({
|
|
634
453
|
message: "Queue query failed.",
|
|
635
454
|
context: {
|
|
636
|
-
subspaceTag:
|
|
637
|
-
spaceId,
|
|
638
|
-
queueId
|
|
455
|
+
subspaceTag: query?.queuesNamespace,
|
|
456
|
+
spaceId: query?.spaceId,
|
|
457
|
+
queueId: query?.queueIds?.[0]
|
|
639
458
|
},
|
|
640
459
|
ifTypeDiffers: true
|
|
641
460
|
})(error);
|
|
642
461
|
}
|
|
643
462
|
}
|
|
644
463
|
async insertIntoQueue(request) {
|
|
645
|
-
const { subspaceTag, spaceId, queueId, objects } = request;
|
|
646
464
|
try {
|
|
647
|
-
|
|
465
|
+
const env = {
|
|
466
|
+
stack: [],
|
|
467
|
+
error: void 0,
|
|
468
|
+
hasError: false
|
|
469
|
+
};
|
|
470
|
+
try {
|
|
471
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.insertIntoQueue(this._ctx, request), false);
|
|
472
|
+
} catch (e) {
|
|
473
|
+
env.error = e;
|
|
474
|
+
env.hasError = true;
|
|
475
|
+
} finally {
|
|
476
|
+
_ts_dispose_resources3(env);
|
|
477
|
+
}
|
|
648
478
|
} catch (error) {
|
|
479
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
649
480
|
throw RuntimeServiceError3.wrap({
|
|
650
481
|
message: "Queue append failed.",
|
|
651
482
|
context: {
|
|
@@ -657,16 +488,35 @@ var QueueServiceImpl = class {
|
|
|
657
488
|
})(error);
|
|
658
489
|
}
|
|
659
490
|
}
|
|
660
|
-
deleteFromQueue(request) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
491
|
+
async deleteFromQueue(request) {
|
|
492
|
+
try {
|
|
493
|
+
const env = {
|
|
494
|
+
stack: [],
|
|
495
|
+
error: void 0,
|
|
496
|
+
hasError: false
|
|
497
|
+
};
|
|
498
|
+
try {
|
|
499
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.deleteFromQueue(this._ctx, request), false);
|
|
500
|
+
} catch (e) {
|
|
501
|
+
env.error = e;
|
|
502
|
+
env.hasError = true;
|
|
503
|
+
} finally {
|
|
504
|
+
_ts_dispose_resources3(env);
|
|
668
505
|
}
|
|
669
|
-
})
|
|
506
|
+
} catch (error) {
|
|
507
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
508
|
+
throw RuntimeServiceError3.wrap({
|
|
509
|
+
message: "Queue delete failed.",
|
|
510
|
+
context: {
|
|
511
|
+
subspaceTag,
|
|
512
|
+
spaceId,
|
|
513
|
+
queueId
|
|
514
|
+
},
|
|
515
|
+
ifTypeDiffers: true
|
|
516
|
+
})(error);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
async syncQueue(_) {
|
|
670
520
|
}
|
|
671
521
|
};
|
|
672
522
|
|
|
@@ -778,39 +628,49 @@ var ServiceContainer = class {
|
|
|
778
628
|
};
|
|
779
629
|
}
|
|
780
630
|
async queryQueue(queue) {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
hasError: false
|
|
785
|
-
};
|
|
786
|
-
try {
|
|
787
|
-
const { spaceId } = queue.asQueueDXN() ?? {};
|
|
788
|
-
const result = _ts_add_disposable_resource4(env, await this._queueService.query({}, queue.toString(), {
|
|
789
|
-
spaceId
|
|
790
|
-
}), false);
|
|
791
|
-
return {
|
|
792
|
-
objects: structuredClone(result.objects),
|
|
793
|
-
nextCursor: result.nextCursor ?? null,
|
|
794
|
-
prevCursor: result.prevCursor ?? null
|
|
795
|
-
};
|
|
796
|
-
} catch (e) {
|
|
797
|
-
env.error = e;
|
|
798
|
-
env.hasError = true;
|
|
799
|
-
} finally {
|
|
800
|
-
_ts_dispose_resources4(env);
|
|
631
|
+
const parts = queue.asQueueDXN();
|
|
632
|
+
if (!parts) {
|
|
633
|
+
throw new Error("Invalid queue DXN");
|
|
801
634
|
}
|
|
635
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
636
|
+
const result = await this._queueService.queryQueue(this._executionContext, {
|
|
637
|
+
query: {
|
|
638
|
+
spaceId,
|
|
639
|
+
queuesNamespace: subspaceTag,
|
|
640
|
+
queueIds: [
|
|
641
|
+
queueId
|
|
642
|
+
]
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
return {
|
|
646
|
+
objects: structuredClone(result.objects),
|
|
647
|
+
nextCursor: result.nextCursor ?? null,
|
|
648
|
+
prevCursor: result.prevCursor ?? null
|
|
649
|
+
};
|
|
802
650
|
}
|
|
803
651
|
async insertIntoQueue(queue, objects) {
|
|
804
|
-
|
|
652
|
+
const parts = queue.asQueueDXN();
|
|
653
|
+
if (!parts) {
|
|
654
|
+
throw new Error("Invalid queue DXN");
|
|
655
|
+
}
|
|
656
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
657
|
+
await this._queueService.insertIntoQueue(this._executionContext, {
|
|
658
|
+
subspaceTag,
|
|
659
|
+
spaceId,
|
|
660
|
+
queueId,
|
|
661
|
+
objects: objects.map((obj) => JSON.stringify(obj))
|
|
662
|
+
});
|
|
805
663
|
}
|
|
806
664
|
};
|
|
807
665
|
|
|
808
666
|
// src/space-proxy.ts
|
|
809
667
|
import { Resource } from "@dxos/context";
|
|
810
|
-
import { invariant as
|
|
811
|
-
import { PublicKey
|
|
668
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
669
|
+
import { PublicKey } from "@dxos/keys";
|
|
812
670
|
|
|
813
671
|
// src/queues-api.ts
|
|
672
|
+
import { log as log3 } from "@dxos/log";
|
|
673
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/queues-api.ts";
|
|
814
674
|
var QueuesAPIImpl = class {
|
|
815
675
|
_serviceContainer;
|
|
816
676
|
_spaceId;
|
|
@@ -818,8 +678,26 @@ var QueuesAPIImpl = class {
|
|
|
818
678
|
this._serviceContainer = _serviceContainer;
|
|
819
679
|
this._spaceId = _spaceId;
|
|
820
680
|
}
|
|
821
|
-
queryQueue(queue, options) {
|
|
822
|
-
|
|
681
|
+
async queryQueue(queue, options) {
|
|
682
|
+
const result = await this._serviceContainer.queryQueue(queue);
|
|
683
|
+
const objects = (result.objects ?? []).flatMap((encoded) => {
|
|
684
|
+
try {
|
|
685
|
+
return [
|
|
686
|
+
JSON.parse(encoded)
|
|
687
|
+
];
|
|
688
|
+
} catch (err) {
|
|
689
|
+
log3.verbose("queue object JSON parse failed; object ignored", {
|
|
690
|
+
encoded,
|
|
691
|
+
error: err
|
|
692
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 22, S: this });
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
return {
|
|
697
|
+
objects,
|
|
698
|
+
nextCursor: result.nextCursor ?? null,
|
|
699
|
+
prevCursor: result.prevCursor ?? null
|
|
700
|
+
};
|
|
823
701
|
}
|
|
824
702
|
insertIntoQueue(queue, objects) {
|
|
825
703
|
return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
|
|
@@ -827,7 +705,7 @@ var QueuesAPIImpl = class {
|
|
|
827
705
|
};
|
|
828
706
|
|
|
829
707
|
// src/space-proxy.ts
|
|
830
|
-
var
|
|
708
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
831
709
|
var SpaceProxy = class extends Resource {
|
|
832
710
|
_serviceContainer;
|
|
833
711
|
_echoClient;
|
|
@@ -842,30 +720,14 @@ var SpaceProxy = class extends Resource {
|
|
|
842
720
|
return this._id;
|
|
843
721
|
}
|
|
844
722
|
get db() {
|
|
845
|
-
|
|
846
|
-
F: __dxlog_file5,
|
|
847
|
-
L: 35,
|
|
848
|
-
S: this,
|
|
849
|
-
A: [
|
|
850
|
-
"this._db",
|
|
851
|
-
""
|
|
852
|
-
]
|
|
853
|
-
});
|
|
723
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
|
|
854
724
|
return this._db;
|
|
855
725
|
}
|
|
856
726
|
/**
|
|
857
727
|
* @deprecated Use db API.
|
|
858
728
|
*/
|
|
859
729
|
get crud() {
|
|
860
|
-
|
|
861
|
-
F: __dxlog_file5,
|
|
862
|
-
L: 43,
|
|
863
|
-
S: this,
|
|
864
|
-
A: [
|
|
865
|
-
"this._db",
|
|
866
|
-
""
|
|
867
|
-
]
|
|
868
|
-
});
|
|
730
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
|
|
869
731
|
return this._db.coreDatabase;
|
|
870
732
|
}
|
|
871
733
|
get queues() {
|
|
@@ -878,18 +740,18 @@ var SpaceProxy = class extends Resource {
|
|
|
878
740
|
}
|
|
879
741
|
this._db = this._echoClient.constructDatabase({
|
|
880
742
|
spaceId: this._id,
|
|
881
|
-
spaceKey:
|
|
743
|
+
spaceKey: PublicKey.from(meta.spaceKey),
|
|
882
744
|
reactiveSchemaQuery: false,
|
|
883
745
|
owningObject: this
|
|
884
746
|
});
|
|
885
|
-
await this._db.coreDatabase.open({
|
|
747
|
+
await this._db.coreDatabase.open(this._ctx, {
|
|
886
748
|
rootUrl: meta.rootDocumentId
|
|
887
749
|
});
|
|
888
750
|
}
|
|
889
751
|
};
|
|
890
752
|
|
|
891
753
|
// src/functions-client.ts
|
|
892
|
-
var
|
|
754
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
|
|
893
755
|
var FunctionsClient = class extends Resource2 {
|
|
894
756
|
_serviceContainer;
|
|
895
757
|
_echoClient;
|
|
@@ -897,24 +759,8 @@ var FunctionsClient = class extends Resource2 {
|
|
|
897
759
|
_spaces = /* @__PURE__ */ new Map();
|
|
898
760
|
constructor(services) {
|
|
899
761
|
super();
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
L: 33,
|
|
903
|
-
S: this,
|
|
904
|
-
A: [
|
|
905
|
-
"typeof services.dataService !== 'undefined'",
|
|
906
|
-
"'DataService is required'"
|
|
907
|
-
]
|
|
908
|
-
});
|
|
909
|
-
invariant6(typeof services.queueService !== "undefined", "QueueService is required", {
|
|
910
|
-
F: __dxlog_file6,
|
|
911
|
-
L: 34,
|
|
912
|
-
S: this,
|
|
913
|
-
A: [
|
|
914
|
-
"typeof services.queueService !== 'undefined'",
|
|
915
|
-
"'QueueService is required'"
|
|
916
|
-
]
|
|
917
|
-
});
|
|
762
|
+
invariant3(typeof services.dataService !== "undefined", "DataService is required", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 19, S: this, A: ["typeof services.dataService !== 'undefined'", "'DataService is required'"] });
|
|
763
|
+
invariant3(typeof services.queueService !== "undefined", "QueueService is required", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 20, S: this, A: ["typeof services.queueService !== 'undefined'", "'QueueService is required'"] });
|
|
918
764
|
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
|
|
919
765
|
this._echoClient = new EchoClient({});
|
|
920
766
|
}
|
|
@@ -964,11 +810,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
964
810
|
})({});
|
|
965
811
|
|
|
966
812
|
// src/wrap-handler-for-cloudflare.ts
|
|
967
|
-
import { invariant as
|
|
968
|
-
import { SpaceId as
|
|
969
|
-
import { log as
|
|
813
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
814
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
815
|
+
import { log as log4 } from "@dxos/log";
|
|
970
816
|
import { EdgeResponse } from "@dxos/protocols";
|
|
971
|
-
var
|
|
817
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
972
818
|
var wrapHandlerForCloudflare = (func) => {
|
|
973
819
|
return async (request, env) => {
|
|
974
820
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
@@ -977,7 +823,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
977
823
|
try {
|
|
978
824
|
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
979
825
|
if (spaceId) {
|
|
980
|
-
if (!
|
|
826
|
+
if (!SpaceId2.isValid(spaceId)) {
|
|
981
827
|
return new Response("Invalid spaceId", {
|
|
982
828
|
status: 400
|
|
983
829
|
});
|
|
@@ -990,15 +836,10 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
990
836
|
});
|
|
991
837
|
return EdgeResponse.success(await invokeFunction(func, context, request));
|
|
992
838
|
} catch (error) {
|
|
993
|
-
|
|
839
|
+
log4.error("error invoking function", {
|
|
994
840
|
error,
|
|
995
841
|
stack: error.stack
|
|
996
|
-
}, {
|
|
997
|
-
F: __dxlog_file7,
|
|
998
|
-
L: 44,
|
|
999
|
-
S: void 0,
|
|
1000
|
-
C: (f, a) => f(...a)
|
|
1001
|
-
});
|
|
842
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
|
|
1002
843
|
return EdgeResponse.failure({
|
|
1003
844
|
message: error?.message ?? "Internal error",
|
|
1004
845
|
error
|
|
@@ -1031,12 +872,7 @@ var decodeRequest = async (request) => {
|
|
|
1031
872
|
}
|
|
1032
873
|
};
|
|
1033
874
|
} catch (err) {
|
|
1034
|
-
|
|
1035
|
-
F: __dxlog_file7,
|
|
1036
|
-
L: 79,
|
|
1037
|
-
S: void 0,
|
|
1038
|
-
C: (f, a) => f(...a)
|
|
1039
|
-
});
|
|
875
|
+
log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
|
|
1040
876
|
return {
|
|
1041
877
|
data: {
|
|
1042
878
|
bodyText,
|
|
@@ -1069,15 +905,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1069
905
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
1070
906
|
}
|
|
1071
907
|
spaceKey = meta.spaceKey;
|
|
1072
|
-
|
|
1073
|
-
F: __dxlog_file7,
|
|
1074
|
-
L: 117,
|
|
1075
|
-
S: void 0,
|
|
1076
|
-
A: [
|
|
1077
|
-
"!meta.rootDocumentId.startsWith('automerge:')",
|
|
1078
|
-
""
|
|
1079
|
-
]
|
|
1080
|
-
});
|
|
908
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
|
|
1081
909
|
rootUrl = `automerge:${meta.rootDocumentId}`;
|
|
1082
910
|
}
|
|
1083
911
|
return {
|
|
@@ -1094,36 +922,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1094
922
|
};
|
|
1095
923
|
|
|
1096
924
|
// src/logger.ts
|
|
1097
|
-
import { LogLevel, log as
|
|
925
|
+
import { LogLevel, log as log5, shouldLog } from "@dxos/log";
|
|
1098
926
|
var setupFunctionsLogger = () => {
|
|
1099
|
-
|
|
1100
|
-
|
|
927
|
+
log5.runtimeConfig.processors.length = 0;
|
|
928
|
+
log5.runtimeConfig.processors.push(functionLogProcessor);
|
|
1101
929
|
};
|
|
1102
930
|
var functionLogProcessor = (config, entry) => {
|
|
1103
931
|
if (!shouldLog(entry, config.filters)) {
|
|
1104
932
|
return;
|
|
1105
933
|
}
|
|
934
|
+
const context = entry.computedContext;
|
|
935
|
+
const error = entry.computedError;
|
|
936
|
+
const extras = [
|
|
937
|
+
Object.keys(context).length > 0 ? context : void 0,
|
|
938
|
+
error
|
|
939
|
+
].filter((value) => value !== void 0);
|
|
1106
940
|
switch (entry.level) {
|
|
1107
941
|
case LogLevel.DEBUG:
|
|
1108
|
-
console.debug(entry.message, entry.context);
|
|
1109
|
-
break;
|
|
1110
942
|
case LogLevel.TRACE:
|
|
1111
|
-
console.debug(entry.message,
|
|
943
|
+
console.debug(entry.message, ...extras);
|
|
1112
944
|
break;
|
|
1113
945
|
case LogLevel.VERBOSE:
|
|
1114
|
-
console.log(entry.message,
|
|
946
|
+
console.log(entry.message, ...extras);
|
|
1115
947
|
break;
|
|
1116
948
|
case LogLevel.INFO:
|
|
1117
|
-
console.info(entry.message,
|
|
949
|
+
console.info(entry.message, ...extras);
|
|
1118
950
|
break;
|
|
1119
951
|
case LogLevel.WARN:
|
|
1120
|
-
console.warn(entry.message,
|
|
952
|
+
console.warn(entry.message, ...extras);
|
|
1121
953
|
break;
|
|
1122
954
|
case LogLevel.ERROR:
|
|
1123
|
-
console.error(entry.message,
|
|
955
|
+
console.error(entry.message, ...extras);
|
|
1124
956
|
break;
|
|
1125
957
|
default:
|
|
1126
|
-
console.log(entry.message,
|
|
958
|
+
console.log(entry.message, ...extras);
|
|
1127
959
|
break;
|
|
1128
960
|
}
|
|
1129
961
|
};
|
|
@@ -1133,6 +965,7 @@ export {
|
|
|
1133
965
|
FunctionsClient,
|
|
1134
966
|
ServiceContainer,
|
|
1135
967
|
createClientFromEnv,
|
|
968
|
+
createFunctionContext,
|
|
1136
969
|
setupFunctionsLogger,
|
|
1137
970
|
wrapHandlerForCloudflare
|
|
1138
971
|
};
|