@dxos/functions-runtime-cloudflare 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878
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 +135 -315
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +135 -315
- 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 +4 -2
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/service-container.d.ts +5 -5
- 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 +10 -5
- 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 +32 -24
- package/src/internal/service-container.ts +29 -10
- package/src/logger.ts +10 -8
- package/src/queues-api.ts +11 -5
- 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,10 @@ 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
|
+
|
|
8
|
+
// src/internal/service-container.ts
|
|
9
|
+
import { EchoURI } from "@dxos/keys";
|
|
7
10
|
|
|
8
11
|
// src/internal/data-service-impl.ts
|
|
9
12
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
@@ -17,6 +20,7 @@ import { log } from "@dxos/log";
|
|
|
17
20
|
var copyUint8Array = (value) => new Uint8Array(value);
|
|
18
21
|
|
|
19
22
|
// src/internal/data-service-impl.ts
|
|
23
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
20
24
|
function _ts_add_disposable_resource(env, value, async) {
|
|
21
25
|
if (value !== null && value !== void 0) {
|
|
22
26
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -82,7 +86,6 @@ function _ts_dispose_resources(env) {
|
|
|
82
86
|
return next();
|
|
83
87
|
})(env);
|
|
84
88
|
}
|
|
85
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
86
89
|
var DataServiceImpl = class {
|
|
87
90
|
_executionContext;
|
|
88
91
|
_dataService;
|
|
@@ -93,15 +96,7 @@ var DataServiceImpl = class {
|
|
|
93
96
|
}
|
|
94
97
|
subscribe({ subscriptionId, spaceId }) {
|
|
95
98
|
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
|
-
});
|
|
99
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
105
100
|
this.dataSubscriptions.set(subscriptionId, {
|
|
106
101
|
spaceId,
|
|
107
102
|
next
|
|
@@ -121,12 +116,7 @@ var DataServiceImpl = class {
|
|
|
121
116
|
if (addIds) {
|
|
122
117
|
log.info("request documents", {
|
|
123
118
|
count: addIds.length
|
|
124
|
-
}, {
|
|
125
|
-
F: __dxlog_file,
|
|
126
|
-
L: 59,
|
|
127
|
-
S: this,
|
|
128
|
-
C: (f, a) => f(...a)
|
|
129
|
-
});
|
|
119
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 104, S: this });
|
|
130
120
|
for (const documentId of addIds) {
|
|
131
121
|
const env = {
|
|
132
122
|
stack: [],
|
|
@@ -139,21 +129,11 @@ var DataServiceImpl = class {
|
|
|
139
129
|
documentId,
|
|
140
130
|
spaceId: sub.spaceId,
|
|
141
131
|
found: !!document
|
|
142
|
-
}, {
|
|
143
|
-
F: __dxlog_file,
|
|
144
|
-
L: 63,
|
|
145
|
-
S: this,
|
|
146
|
-
C: (f, a) => f(...a)
|
|
147
|
-
});
|
|
132
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 116, S: this });
|
|
148
133
|
if (!document) {
|
|
149
134
|
log.warn("not found", {
|
|
150
135
|
documentId
|
|
151
|
-
}, {
|
|
152
|
-
F: __dxlog_file,
|
|
153
|
-
L: 65,
|
|
154
|
-
S: this,
|
|
155
|
-
C: (f, a) => f(...a)
|
|
156
|
-
});
|
|
136
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 122, S: this });
|
|
157
137
|
continue;
|
|
158
138
|
}
|
|
159
139
|
sub.next({
|
|
@@ -182,10 +162,8 @@ var DataServiceImpl = class {
|
|
|
182
162
|
hasError: false
|
|
183
163
|
};
|
|
184
164
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
initialValue
|
|
188
|
-
}), false);
|
|
165
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 153, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
166
|
+
const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, spaceId, initialValue), false);
|
|
189
167
|
return {
|
|
190
168
|
documentId: response.documentId
|
|
191
169
|
};
|
|
@@ -205,6 +183,9 @@ var DataServiceImpl = class {
|
|
|
205
183
|
}));
|
|
206
184
|
try {
|
|
207
185
|
for (const update of updates ?? []) {
|
|
186
|
+
if (!update.mutation) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
208
189
|
await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
|
|
209
190
|
}
|
|
210
191
|
} catch (error) {
|
|
@@ -235,12 +216,7 @@ var DataServiceImpl = class {
|
|
|
235
216
|
});
|
|
236
217
|
}
|
|
237
218
|
async updateIndexes() {
|
|
238
|
-
log.
|
|
239
|
-
F: __dxlog_file,
|
|
240
|
-
L: 133,
|
|
241
|
-
S: this,
|
|
242
|
-
C: (f, a) => f(...a)
|
|
243
|
-
});
|
|
219
|
+
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
220
|
}
|
|
245
221
|
async waitUntilHeadsReplicated({ heads: _heads }) {
|
|
246
222
|
throw new NotImplementedError({
|
|
@@ -250,83 +226,10 @@ var DataServiceImpl = class {
|
|
|
250
226
|
};
|
|
251
227
|
|
|
252
228
|
// src/internal/query-service-impl.ts
|
|
253
|
-
import * as Schema from "effect/Schema";
|
|
254
229
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
255
|
-
import { QueryAST } from "@dxos/echo-protocol";
|
|
256
230
|
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
231
|
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
|
|
232
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
330
233
|
function _ts_add_disposable_resource2(env, value, async) {
|
|
331
234
|
if (value !== null && value !== void 0) {
|
|
332
235
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -392,7 +295,6 @@ function _ts_dispose_resources2(env) {
|
|
|
392
295
|
return next();
|
|
393
296
|
})(env);
|
|
394
297
|
}
|
|
395
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
396
298
|
var QueryServiceImpl = class {
|
|
397
299
|
_executionContext;
|
|
398
300
|
_dataService;
|
|
@@ -404,24 +306,7 @@ var QueryServiceImpl = class {
|
|
|
404
306
|
execQuery(request) {
|
|
405
307
|
log2.info("execQuery", {
|
|
406
308
|
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];
|
|
309
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
|
|
425
310
|
return Stream2.fromPromise((async () => {
|
|
426
311
|
try {
|
|
427
312
|
const env = {
|
|
@@ -432,37 +317,13 @@ var QueryServiceImpl = class {
|
|
|
432
317
|
try {
|
|
433
318
|
this._queryCount++;
|
|
434
319
|
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);
|
|
320
|
+
request
|
|
321
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 93, S: this });
|
|
322
|
+
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
|
|
443
323
|
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
|
-
};
|
|
324
|
+
resultCount: queryResponse.results?.length
|
|
325
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
|
|
326
|
+
return structuredClone(queryResponse);
|
|
466
327
|
} catch (e) {
|
|
467
328
|
env.error = e;
|
|
468
329
|
env.hasError = true;
|
|
@@ -472,17 +333,10 @@ var QueryServiceImpl = class {
|
|
|
472
333
|
} catch (error) {
|
|
473
334
|
log2.error("query failed", {
|
|
474
335
|
err: error
|
|
475
|
-
}, {
|
|
476
|
-
F: __dxlog_file3,
|
|
477
|
-
L: 66,
|
|
478
|
-
S: this,
|
|
479
|
-
C: (f, a) => f(...a)
|
|
480
|
-
});
|
|
336
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
|
|
481
337
|
throw new RuntimeServiceError2({
|
|
482
338
|
message: `Query execution failed (queryCount=${this._queryCount})`,
|
|
483
339
|
context: {
|
|
484
|
-
spaceId,
|
|
485
|
-
filter: request.filter,
|
|
486
340
|
queryCount: this._queryCount
|
|
487
341
|
},
|
|
488
342
|
cause: error
|
|
@@ -501,26 +355,9 @@ var QueryServiceImpl = class {
|
|
|
501
355
|
});
|
|
502
356
|
}
|
|
503
357
|
};
|
|
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
358
|
|
|
521
359
|
// src/internal/queue-service-impl.ts
|
|
522
|
-
import {
|
|
523
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
360
|
+
import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
|
|
524
361
|
function _ts_add_disposable_resource3(env, value, async) {
|
|
525
362
|
if (value !== null && value !== void 0) {
|
|
526
363
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -586,7 +423,6 @@ function _ts_dispose_resources3(env) {
|
|
|
586
423
|
return next();
|
|
587
424
|
})(env);
|
|
588
425
|
}
|
|
589
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/queue-service-impl.ts";
|
|
590
426
|
var QueueServiceImpl = class {
|
|
591
427
|
_ctx;
|
|
592
428
|
_queueService;
|
|
@@ -595,19 +431,6 @@ var QueueServiceImpl = class {
|
|
|
595
431
|
this._queueService = _queueService;
|
|
596
432
|
}
|
|
597
433
|
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
434
|
try {
|
|
612
435
|
const env = {
|
|
613
436
|
stack: [],
|
|
@@ -615,10 +438,8 @@ var QueueServiceImpl = class {
|
|
|
615
438
|
hasError: false
|
|
616
439
|
};
|
|
617
440
|
try {
|
|
618
|
-
const result = _ts_add_disposable_resource3(env, await this._queueService.
|
|
441
|
+
const result = _ts_add_disposable_resource3(env, await this._queueService.queryQueue(this._ctx, request), false);
|
|
619
442
|
return {
|
|
620
|
-
// Copy returned object to avoid hanging RPC stub
|
|
621
|
-
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
622
443
|
objects: structuredClone(result.objects),
|
|
623
444
|
nextCursor: result.nextCursor,
|
|
624
445
|
prevCursor: result.prevCursor
|
|
@@ -630,22 +451,35 @@ var QueueServiceImpl = class {
|
|
|
630
451
|
_ts_dispose_resources3(env);
|
|
631
452
|
}
|
|
632
453
|
} catch (error) {
|
|
454
|
+
const { query } = request;
|
|
633
455
|
throw RuntimeServiceError3.wrap({
|
|
634
456
|
message: "Queue query failed.",
|
|
635
457
|
context: {
|
|
636
|
-
subspaceTag:
|
|
637
|
-
spaceId,
|
|
638
|
-
queueId
|
|
458
|
+
subspaceTag: query?.queuesNamespace,
|
|
459
|
+
spaceId: query?.spaceId,
|
|
460
|
+
queueId: query?.queueIds?.[0]
|
|
639
461
|
},
|
|
640
462
|
ifTypeDiffers: true
|
|
641
463
|
})(error);
|
|
642
464
|
}
|
|
643
465
|
}
|
|
644
466
|
async insertIntoQueue(request) {
|
|
645
|
-
const { subspaceTag, spaceId, queueId, objects } = request;
|
|
646
467
|
try {
|
|
647
|
-
|
|
468
|
+
const env = {
|
|
469
|
+
stack: [],
|
|
470
|
+
error: void 0,
|
|
471
|
+
hasError: false
|
|
472
|
+
};
|
|
473
|
+
try {
|
|
474
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.insertIntoQueue(this._ctx, request), false);
|
|
475
|
+
} catch (e) {
|
|
476
|
+
env.error = e;
|
|
477
|
+
env.hasError = true;
|
|
478
|
+
} finally {
|
|
479
|
+
_ts_dispose_resources3(env);
|
|
480
|
+
}
|
|
648
481
|
} catch (error) {
|
|
482
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
649
483
|
throw RuntimeServiceError3.wrap({
|
|
650
484
|
message: "Queue append failed.",
|
|
651
485
|
context: {
|
|
@@ -657,16 +491,40 @@ var QueueServiceImpl = class {
|
|
|
657
491
|
})(error);
|
|
658
492
|
}
|
|
659
493
|
}
|
|
660
|
-
deleteFromQueue(request) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
494
|
+
async deleteFromQueue(request) {
|
|
495
|
+
try {
|
|
496
|
+
const env = {
|
|
497
|
+
stack: [],
|
|
498
|
+
error: void 0,
|
|
499
|
+
hasError: false
|
|
500
|
+
};
|
|
501
|
+
try {
|
|
502
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.deleteFromQueue(this._ctx, request), false);
|
|
503
|
+
} catch (e) {
|
|
504
|
+
env.error = e;
|
|
505
|
+
env.hasError = true;
|
|
506
|
+
} finally {
|
|
507
|
+
_ts_dispose_resources3(env);
|
|
668
508
|
}
|
|
669
|
-
})
|
|
509
|
+
} catch (error) {
|
|
510
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
511
|
+
throw RuntimeServiceError3.wrap({
|
|
512
|
+
message: "Queue delete failed.",
|
|
513
|
+
context: {
|
|
514
|
+
subspaceTag,
|
|
515
|
+
spaceId,
|
|
516
|
+
queueId
|
|
517
|
+
},
|
|
518
|
+
ifTypeDiffers: true
|
|
519
|
+
})(error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async syncQueue(_) {
|
|
523
|
+
}
|
|
524
|
+
async getSyncState(_) {
|
|
525
|
+
return {
|
|
526
|
+
namespaces: []
|
|
527
|
+
};
|
|
670
528
|
}
|
|
671
529
|
};
|
|
672
530
|
|
|
@@ -778,37 +636,44 @@ var ServiceContainer = class {
|
|
|
778
636
|
};
|
|
779
637
|
}
|
|
780
638
|
async queryQueue(queue) {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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);
|
|
639
|
+
const spaceId = EchoURI.getSpaceId(queue);
|
|
640
|
+
const queueId = EchoURI.getObjectId(queue);
|
|
641
|
+
if (!spaceId || !queueId) {
|
|
642
|
+
throw new Error("Invalid queue EchoURI");
|
|
801
643
|
}
|
|
644
|
+
const result = await this._queueService.queryQueue(this._executionContext, {
|
|
645
|
+
query: {
|
|
646
|
+
spaceId,
|
|
647
|
+
queueIds: [
|
|
648
|
+
queueId
|
|
649
|
+
]
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
return {
|
|
653
|
+
objects: structuredClone(result.objects),
|
|
654
|
+
nextCursor: result.nextCursor ?? null,
|
|
655
|
+
prevCursor: result.prevCursor ?? null
|
|
656
|
+
};
|
|
802
657
|
}
|
|
803
658
|
async insertIntoQueue(queue, objects) {
|
|
804
|
-
|
|
659
|
+
const spaceId = EchoURI.getSpaceId(queue);
|
|
660
|
+
const queueId = EchoURI.getObjectId(queue);
|
|
661
|
+
if (!spaceId || !queueId) {
|
|
662
|
+
throw new Error("Invalid queue EchoURI");
|
|
663
|
+
}
|
|
664
|
+
await this._queueService.insertIntoQueue(this._executionContext, {
|
|
665
|
+
subspaceTag: "data",
|
|
666
|
+
spaceId,
|
|
667
|
+
queueId,
|
|
668
|
+
objects: objects.map((obj) => JSON.stringify(obj))
|
|
669
|
+
});
|
|
805
670
|
}
|
|
806
671
|
};
|
|
807
672
|
|
|
808
673
|
// src/space-proxy.ts
|
|
809
674
|
import { Resource } from "@dxos/context";
|
|
810
|
-
import { invariant as
|
|
811
|
-
import { PublicKey
|
|
675
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
676
|
+
import { PublicKey } from "@dxos/keys";
|
|
812
677
|
|
|
813
678
|
// src/queues-api.ts
|
|
814
679
|
var QueuesAPIImpl = class {
|
|
@@ -827,7 +692,7 @@ var QueuesAPIImpl = class {
|
|
|
827
692
|
};
|
|
828
693
|
|
|
829
694
|
// src/space-proxy.ts
|
|
830
|
-
var
|
|
695
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
831
696
|
var SpaceProxy = class extends Resource {
|
|
832
697
|
_serviceContainer;
|
|
833
698
|
_echoClient;
|
|
@@ -842,30 +707,14 @@ var SpaceProxy = class extends Resource {
|
|
|
842
707
|
return this._id;
|
|
843
708
|
}
|
|
844
709
|
get db() {
|
|
845
|
-
|
|
846
|
-
F: __dxlog_file5,
|
|
847
|
-
L: 35,
|
|
848
|
-
S: this,
|
|
849
|
-
A: [
|
|
850
|
-
"this._db",
|
|
851
|
-
""
|
|
852
|
-
]
|
|
853
|
-
});
|
|
710
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 24, S: this, A: ["this._db", ""] });
|
|
854
711
|
return this._db;
|
|
855
712
|
}
|
|
856
713
|
/**
|
|
857
714
|
* @deprecated Use db API.
|
|
858
715
|
*/
|
|
859
716
|
get crud() {
|
|
860
|
-
|
|
861
|
-
F: __dxlog_file5,
|
|
862
|
-
L: 43,
|
|
863
|
-
S: this,
|
|
864
|
-
A: [
|
|
865
|
-
"this._db",
|
|
866
|
-
""
|
|
867
|
-
]
|
|
868
|
-
});
|
|
717
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 30, S: this, A: ["this._db", ""] });
|
|
869
718
|
return this._db.coreDatabase;
|
|
870
719
|
}
|
|
871
720
|
get queues() {
|
|
@@ -878,18 +727,18 @@ var SpaceProxy = class extends Resource {
|
|
|
878
727
|
}
|
|
879
728
|
this._db = this._echoClient.constructDatabase({
|
|
880
729
|
spaceId: this._id,
|
|
881
|
-
spaceKey:
|
|
730
|
+
spaceKey: PublicKey.from(meta.spaceKey),
|
|
882
731
|
reactiveSchemaQuery: false,
|
|
883
732
|
owningObject: this
|
|
884
733
|
});
|
|
885
|
-
await this._db.coreDatabase.open({
|
|
734
|
+
await this._db.coreDatabase.open(this._ctx, {
|
|
886
735
|
rootUrl: meta.rootDocumentId
|
|
887
736
|
});
|
|
888
737
|
}
|
|
889
738
|
};
|
|
890
739
|
|
|
891
740
|
// src/functions-client.ts
|
|
892
|
-
var
|
|
741
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
|
|
893
742
|
var FunctionsClient = class extends Resource2 {
|
|
894
743
|
_serviceContainer;
|
|
895
744
|
_echoClient;
|
|
@@ -897,24 +746,8 @@ var FunctionsClient = class extends Resource2 {
|
|
|
897
746
|
_spaces = /* @__PURE__ */ new Map();
|
|
898
747
|
constructor(services) {
|
|
899
748
|
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
|
-
});
|
|
749
|
+
invariant3(typeof services.dataService !== "undefined", "DataService is required", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 19, S: this, A: ["typeof services.dataService !== 'undefined'", "'DataService is required'"] });
|
|
750
|
+
invariant3(typeof services.queueService !== "undefined", "QueueService is required", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 20, S: this, A: ["typeof services.queueService !== 'undefined'", "'QueueService is required'"] });
|
|
918
751
|
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
|
|
919
752
|
this._echoClient = new EchoClient({});
|
|
920
753
|
}
|
|
@@ -964,11 +797,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
964
797
|
})({});
|
|
965
798
|
|
|
966
799
|
// src/wrap-handler-for-cloudflare.ts
|
|
967
|
-
import { invariant as
|
|
968
|
-
import { SpaceId as
|
|
800
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
801
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
969
802
|
import { log as log3 } from "@dxos/log";
|
|
970
803
|
import { EdgeResponse } from "@dxos/protocols";
|
|
971
|
-
var
|
|
804
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
972
805
|
var wrapHandlerForCloudflare = (func) => {
|
|
973
806
|
return async (request, env) => {
|
|
974
807
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
@@ -977,7 +810,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
977
810
|
try {
|
|
978
811
|
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
979
812
|
if (spaceId) {
|
|
980
|
-
if (!
|
|
813
|
+
if (!SpaceId2.isValid(spaceId)) {
|
|
981
814
|
return new Response("Invalid spaceId", {
|
|
982
815
|
status: 400
|
|
983
816
|
});
|
|
@@ -993,12 +826,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
993
826
|
log3.error("error invoking function", {
|
|
994
827
|
error,
|
|
995
828
|
stack: error.stack
|
|
996
|
-
}, {
|
|
997
|
-
F: __dxlog_file7,
|
|
998
|
-
L: 44,
|
|
999
|
-
S: void 0,
|
|
1000
|
-
C: (f, a) => f(...a)
|
|
1001
|
-
});
|
|
829
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 37, S: void 0 });
|
|
1002
830
|
return EdgeResponse.failure({
|
|
1003
831
|
message: error?.message ?? "Internal error",
|
|
1004
832
|
error
|
|
@@ -1031,12 +859,7 @@ var decodeRequest = async (request) => {
|
|
|
1031
859
|
}
|
|
1032
860
|
};
|
|
1033
861
|
} catch (err) {
|
|
1034
|
-
log3.catch(err, void 0, {
|
|
1035
|
-
F: __dxlog_file7,
|
|
1036
|
-
L: 79,
|
|
1037
|
-
S: void 0,
|
|
1038
|
-
C: (f, a) => f(...a)
|
|
1039
|
-
});
|
|
862
|
+
log3.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 76, S: void 0 });
|
|
1040
863
|
return {
|
|
1041
864
|
data: {
|
|
1042
865
|
bodyText,
|
|
@@ -1069,15 +892,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1069
892
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
1070
893
|
}
|
|
1071
894
|
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
|
-
});
|
|
895
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
|
|
1081
896
|
rootUrl = `automerge:${meta.rootDocumentId}`;
|
|
1082
897
|
}
|
|
1083
898
|
return {
|
|
@@ -1103,27 +918,31 @@ var functionLogProcessor = (config, entry) => {
|
|
|
1103
918
|
if (!shouldLog(entry, config.filters)) {
|
|
1104
919
|
return;
|
|
1105
920
|
}
|
|
921
|
+
const context = entry.computedContext;
|
|
922
|
+
const error = entry.computedError;
|
|
923
|
+
const extras = [
|
|
924
|
+
Object.keys(context).length > 0 ? context : void 0,
|
|
925
|
+
error
|
|
926
|
+
].filter((value) => value !== void 0);
|
|
1106
927
|
switch (entry.level) {
|
|
1107
928
|
case LogLevel.DEBUG:
|
|
1108
|
-
console.debug(entry.message, entry.context);
|
|
1109
|
-
break;
|
|
1110
929
|
case LogLevel.TRACE:
|
|
1111
|
-
console.debug(entry.message,
|
|
930
|
+
console.debug(entry.message, ...extras);
|
|
1112
931
|
break;
|
|
1113
932
|
case LogLevel.VERBOSE:
|
|
1114
|
-
console.log(entry.message,
|
|
933
|
+
console.log(entry.message, ...extras);
|
|
1115
934
|
break;
|
|
1116
935
|
case LogLevel.INFO:
|
|
1117
|
-
console.info(entry.message,
|
|
936
|
+
console.info(entry.message, ...extras);
|
|
1118
937
|
break;
|
|
1119
938
|
case LogLevel.WARN:
|
|
1120
|
-
console.warn(entry.message,
|
|
939
|
+
console.warn(entry.message, ...extras);
|
|
1121
940
|
break;
|
|
1122
941
|
case LogLevel.ERROR:
|
|
1123
|
-
console.error(entry.message,
|
|
942
|
+
console.error(entry.message, ...extras);
|
|
1124
943
|
break;
|
|
1125
944
|
default:
|
|
1126
|
-
console.log(entry.message,
|
|
945
|
+
console.log(entry.message, ...extras);
|
|
1127
946
|
break;
|
|
1128
947
|
}
|
|
1129
948
|
};
|
|
@@ -1133,6 +952,7 @@ export {
|
|
|
1133
952
|
FunctionsClient,
|
|
1134
953
|
ServiceContainer,
|
|
1135
954
|
createClientFromEnv,
|
|
955
|
+
createFunctionContext,
|
|
1136
956
|
setupFunctionsLogger,
|
|
1137
957
|
wrapHandlerForCloudflare
|
|
1138
958
|
};
|