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