@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
|
@@ -1,7 +1,7 @@
|
|
|
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
5
|
|
|
6
6
|
// src/internal/data-service-impl.ts
|
|
7
7
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
@@ -15,6 +15,7 @@ import { log } from "@dxos/log";
|
|
|
15
15
|
var copyUint8Array = (value) => new Uint8Array(value);
|
|
16
16
|
|
|
17
17
|
// src/internal/data-service-impl.ts
|
|
18
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
18
19
|
function _ts_add_disposable_resource(env, value, async) {
|
|
19
20
|
if (value !== null && value !== void 0) {
|
|
20
21
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -80,7 +81,6 @@ function _ts_dispose_resources(env) {
|
|
|
80
81
|
return next();
|
|
81
82
|
})(env);
|
|
82
83
|
}
|
|
83
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
84
84
|
var DataServiceImpl = class {
|
|
85
85
|
_executionContext;
|
|
86
86
|
_dataService;
|
|
@@ -91,15 +91,7 @@ var DataServiceImpl = class {
|
|
|
91
91
|
}
|
|
92
92
|
subscribe({ subscriptionId, spaceId }) {
|
|
93
93
|
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
|
-
});
|
|
94
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
103
95
|
this.dataSubscriptions.set(subscriptionId, {
|
|
104
96
|
spaceId,
|
|
105
97
|
next
|
|
@@ -119,12 +111,7 @@ var DataServiceImpl = class {
|
|
|
119
111
|
if (addIds) {
|
|
120
112
|
log.info("request documents", {
|
|
121
113
|
count: addIds.length
|
|
122
|
-
}, {
|
|
123
|
-
F: __dxlog_file,
|
|
124
|
-
L: 59,
|
|
125
|
-
S: this,
|
|
126
|
-
C: (f, a) => f(...a)
|
|
127
|
-
});
|
|
114
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 104, S: this });
|
|
128
115
|
for (const documentId of addIds) {
|
|
129
116
|
const env = {
|
|
130
117
|
stack: [],
|
|
@@ -137,21 +124,11 @@ var DataServiceImpl = class {
|
|
|
137
124
|
documentId,
|
|
138
125
|
spaceId: sub.spaceId,
|
|
139
126
|
found: !!document
|
|
140
|
-
}, {
|
|
141
|
-
F: __dxlog_file,
|
|
142
|
-
L: 63,
|
|
143
|
-
S: this,
|
|
144
|
-
C: (f, a) => f(...a)
|
|
145
|
-
});
|
|
127
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 116, S: this });
|
|
146
128
|
if (!document) {
|
|
147
129
|
log.warn("not found", {
|
|
148
130
|
documentId
|
|
149
|
-
}, {
|
|
150
|
-
F: __dxlog_file,
|
|
151
|
-
L: 65,
|
|
152
|
-
S: this,
|
|
153
|
-
C: (f, a) => f(...a)
|
|
154
|
-
});
|
|
131
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 122, S: this });
|
|
155
132
|
continue;
|
|
156
133
|
}
|
|
157
134
|
sub.next({
|
|
@@ -180,10 +157,8 @@ var DataServiceImpl = class {
|
|
|
180
157
|
hasError: false
|
|
181
158
|
};
|
|
182
159
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
initialValue
|
|
186
|
-
}), false);
|
|
160
|
+
invariant(SpaceId.isValid(spaceId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 153, S: this, A: ["SpaceId.isValid(spaceId)", ""] });
|
|
161
|
+
const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, spaceId, initialValue), false);
|
|
187
162
|
return {
|
|
188
163
|
documentId: response.documentId
|
|
189
164
|
};
|
|
@@ -203,6 +178,9 @@ var DataServiceImpl = class {
|
|
|
203
178
|
}));
|
|
204
179
|
try {
|
|
205
180
|
for (const update of updates ?? []) {
|
|
181
|
+
if (!update.mutation) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
206
184
|
await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
|
|
207
185
|
}
|
|
208
186
|
} catch (error) {
|
|
@@ -233,12 +211,7 @@ var DataServiceImpl = class {
|
|
|
233
211
|
});
|
|
234
212
|
}
|
|
235
213
|
async updateIndexes() {
|
|
236
|
-
log.
|
|
237
|
-
F: __dxlog_file,
|
|
238
|
-
L: 133,
|
|
239
|
-
S: this,
|
|
240
|
-
C: (f, a) => f(...a)
|
|
241
|
-
});
|
|
214
|
+
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
215
|
}
|
|
243
216
|
async waitUntilHeadsReplicated({ heads: _heads }) {
|
|
244
217
|
throw new NotImplementedError({
|
|
@@ -248,83 +221,10 @@ var DataServiceImpl = class {
|
|
|
248
221
|
};
|
|
249
222
|
|
|
250
223
|
// src/internal/query-service-impl.ts
|
|
251
|
-
import * as Schema from "effect/Schema";
|
|
252
224
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
253
|
-
import { QueryAST } from "@dxos/echo-protocol";
|
|
254
225
|
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
226
|
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
|
|
227
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
328
228
|
function _ts_add_disposable_resource2(env, value, async) {
|
|
329
229
|
if (value !== null && value !== void 0) {
|
|
330
230
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -390,7 +290,6 @@ function _ts_dispose_resources2(env) {
|
|
|
390
290
|
return next();
|
|
391
291
|
})(env);
|
|
392
292
|
}
|
|
393
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
394
293
|
var QueryServiceImpl = class {
|
|
395
294
|
_executionContext;
|
|
396
295
|
_dataService;
|
|
@@ -402,24 +301,7 @@ var QueryServiceImpl = class {
|
|
|
402
301
|
execQuery(request) {
|
|
403
302
|
log2.info("execQuery", {
|
|
404
303
|
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];
|
|
304
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
|
|
423
305
|
return Stream2.fromPromise((async () => {
|
|
424
306
|
try {
|
|
425
307
|
const env = {
|
|
@@ -430,37 +312,13 @@ var QueryServiceImpl = class {
|
|
|
430
312
|
try {
|
|
431
313
|
this._queryCount++;
|
|
432
314
|
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);
|
|
315
|
+
request
|
|
316
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 93, S: this });
|
|
317
|
+
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
|
|
441
318
|
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
|
-
};
|
|
319
|
+
resultCount: queryResponse.results?.length
|
|
320
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
|
|
321
|
+
return structuredClone(queryResponse);
|
|
464
322
|
} catch (e) {
|
|
465
323
|
env.error = e;
|
|
466
324
|
env.hasError = true;
|
|
@@ -470,17 +328,10 @@ var QueryServiceImpl = class {
|
|
|
470
328
|
} catch (error) {
|
|
471
329
|
log2.error("query failed", {
|
|
472
330
|
err: error
|
|
473
|
-
}, {
|
|
474
|
-
F: __dxlog_file3,
|
|
475
|
-
L: 66,
|
|
476
|
-
S: this,
|
|
477
|
-
C: (f, a) => f(...a)
|
|
478
|
-
});
|
|
331
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
|
|
479
332
|
throw new RuntimeServiceError2({
|
|
480
333
|
message: `Query execution failed (queryCount=${this._queryCount})`,
|
|
481
334
|
context: {
|
|
482
|
-
spaceId,
|
|
483
|
-
filter: request.filter,
|
|
484
335
|
queryCount: this._queryCount
|
|
485
336
|
},
|
|
486
337
|
cause: error
|
|
@@ -499,26 +350,9 @@ var QueryServiceImpl = class {
|
|
|
499
350
|
});
|
|
500
351
|
}
|
|
501
352
|
};
|
|
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
353
|
|
|
519
354
|
// src/internal/queue-service-impl.ts
|
|
520
|
-
import {
|
|
521
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
355
|
+
import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
|
|
522
356
|
function _ts_add_disposable_resource3(env, value, async) {
|
|
523
357
|
if (value !== null && value !== void 0) {
|
|
524
358
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -584,7 +418,6 @@ function _ts_dispose_resources3(env) {
|
|
|
584
418
|
return next();
|
|
585
419
|
})(env);
|
|
586
420
|
}
|
|
587
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/queue-service-impl.ts";
|
|
588
421
|
var QueueServiceImpl = class {
|
|
589
422
|
_ctx;
|
|
590
423
|
_queueService;
|
|
@@ -593,19 +426,6 @@ var QueueServiceImpl = class {
|
|
|
593
426
|
this._queueService = _queueService;
|
|
594
427
|
}
|
|
595
428
|
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
429
|
try {
|
|
610
430
|
const env = {
|
|
611
431
|
stack: [],
|
|
@@ -613,10 +433,8 @@ var QueueServiceImpl = class {
|
|
|
613
433
|
hasError: false
|
|
614
434
|
};
|
|
615
435
|
try {
|
|
616
|
-
const result = _ts_add_disposable_resource3(env, await this._queueService.
|
|
436
|
+
const result = _ts_add_disposable_resource3(env, await this._queueService.queryQueue(this._ctx, request), false);
|
|
617
437
|
return {
|
|
618
|
-
// Copy returned object to avoid hanging RPC stub
|
|
619
|
-
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
620
438
|
objects: structuredClone(result.objects),
|
|
621
439
|
nextCursor: result.nextCursor,
|
|
622
440
|
prevCursor: result.prevCursor
|
|
@@ -628,22 +446,35 @@ var QueueServiceImpl = class {
|
|
|
628
446
|
_ts_dispose_resources3(env);
|
|
629
447
|
}
|
|
630
448
|
} catch (error) {
|
|
449
|
+
const { query } = request;
|
|
631
450
|
throw RuntimeServiceError3.wrap({
|
|
632
451
|
message: "Queue query failed.",
|
|
633
452
|
context: {
|
|
634
|
-
subspaceTag:
|
|
635
|
-
spaceId,
|
|
636
|
-
queueId
|
|
453
|
+
subspaceTag: query?.queuesNamespace,
|
|
454
|
+
spaceId: query?.spaceId,
|
|
455
|
+
queueId: query?.queueIds?.[0]
|
|
637
456
|
},
|
|
638
457
|
ifTypeDiffers: true
|
|
639
458
|
})(error);
|
|
640
459
|
}
|
|
641
460
|
}
|
|
642
461
|
async insertIntoQueue(request) {
|
|
643
|
-
const { subspaceTag, spaceId, queueId, objects } = request;
|
|
644
462
|
try {
|
|
645
|
-
|
|
463
|
+
const env = {
|
|
464
|
+
stack: [],
|
|
465
|
+
error: void 0,
|
|
466
|
+
hasError: false
|
|
467
|
+
};
|
|
468
|
+
try {
|
|
469
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.insertIntoQueue(this._ctx, request), false);
|
|
470
|
+
} catch (e) {
|
|
471
|
+
env.error = e;
|
|
472
|
+
env.hasError = true;
|
|
473
|
+
} finally {
|
|
474
|
+
_ts_dispose_resources3(env);
|
|
475
|
+
}
|
|
646
476
|
} catch (error) {
|
|
477
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
647
478
|
throw RuntimeServiceError3.wrap({
|
|
648
479
|
message: "Queue append failed.",
|
|
649
480
|
context: {
|
|
@@ -655,16 +486,35 @@ var QueueServiceImpl = class {
|
|
|
655
486
|
})(error);
|
|
656
487
|
}
|
|
657
488
|
}
|
|
658
|
-
deleteFromQueue(request) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
489
|
+
async deleteFromQueue(request) {
|
|
490
|
+
try {
|
|
491
|
+
const env = {
|
|
492
|
+
stack: [],
|
|
493
|
+
error: void 0,
|
|
494
|
+
hasError: false
|
|
495
|
+
};
|
|
496
|
+
try {
|
|
497
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.deleteFromQueue(this._ctx, request), false);
|
|
498
|
+
} catch (e) {
|
|
499
|
+
env.error = e;
|
|
500
|
+
env.hasError = true;
|
|
501
|
+
} finally {
|
|
502
|
+
_ts_dispose_resources3(env);
|
|
666
503
|
}
|
|
667
|
-
})
|
|
504
|
+
} catch (error) {
|
|
505
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
506
|
+
throw RuntimeServiceError3.wrap({
|
|
507
|
+
message: "Queue delete failed.",
|
|
508
|
+
context: {
|
|
509
|
+
subspaceTag,
|
|
510
|
+
spaceId,
|
|
511
|
+
queueId
|
|
512
|
+
},
|
|
513
|
+
ifTypeDiffers: true
|
|
514
|
+
})(error);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async syncQueue(_) {
|
|
668
518
|
}
|
|
669
519
|
};
|
|
670
520
|
|
|
@@ -776,39 +626,49 @@ var ServiceContainer = class {
|
|
|
776
626
|
};
|
|
777
627
|
}
|
|
778
628
|
async queryQueue(queue) {
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
hasError: false
|
|
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);
|
|
629
|
+
const parts = queue.asQueueDXN();
|
|
630
|
+
if (!parts) {
|
|
631
|
+
throw new Error("Invalid queue DXN");
|
|
799
632
|
}
|
|
633
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
634
|
+
const result = await this._queueService.queryQueue(this._executionContext, {
|
|
635
|
+
query: {
|
|
636
|
+
spaceId,
|
|
637
|
+
queuesNamespace: subspaceTag,
|
|
638
|
+
queueIds: [
|
|
639
|
+
queueId
|
|
640
|
+
]
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
return {
|
|
644
|
+
objects: structuredClone(result.objects),
|
|
645
|
+
nextCursor: result.nextCursor ?? null,
|
|
646
|
+
prevCursor: result.prevCursor ?? null
|
|
647
|
+
};
|
|
800
648
|
}
|
|
801
649
|
async insertIntoQueue(queue, objects) {
|
|
802
|
-
|
|
650
|
+
const parts = queue.asQueueDXN();
|
|
651
|
+
if (!parts) {
|
|
652
|
+
throw new Error("Invalid queue DXN");
|
|
653
|
+
}
|
|
654
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
655
|
+
await this._queueService.insertIntoQueue(this._executionContext, {
|
|
656
|
+
subspaceTag,
|
|
657
|
+
spaceId,
|
|
658
|
+
queueId,
|
|
659
|
+
objects: objects.map((obj) => JSON.stringify(obj))
|
|
660
|
+
});
|
|
803
661
|
}
|
|
804
662
|
};
|
|
805
663
|
|
|
806
664
|
// src/space-proxy.ts
|
|
807
665
|
import { Resource } from "@dxos/context";
|
|
808
|
-
import { invariant as
|
|
809
|
-
import { PublicKey
|
|
666
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
667
|
+
import { PublicKey } from "@dxos/keys";
|
|
810
668
|
|
|
811
669
|
// src/queues-api.ts
|
|
670
|
+
import { log as log3 } from "@dxos/log";
|
|
671
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/queues-api.ts";
|
|
812
672
|
var QueuesAPIImpl = class {
|
|
813
673
|
_serviceContainer;
|
|
814
674
|
_spaceId;
|
|
@@ -816,8 +676,26 @@ var QueuesAPIImpl = class {
|
|
|
816
676
|
this._serviceContainer = _serviceContainer;
|
|
817
677
|
this._spaceId = _spaceId;
|
|
818
678
|
}
|
|
819
|
-
queryQueue(queue, options) {
|
|
820
|
-
|
|
679
|
+
async queryQueue(queue, options) {
|
|
680
|
+
const result = await this._serviceContainer.queryQueue(queue);
|
|
681
|
+
const objects = (result.objects ?? []).flatMap((encoded) => {
|
|
682
|
+
try {
|
|
683
|
+
return [
|
|
684
|
+
JSON.parse(encoded)
|
|
685
|
+
];
|
|
686
|
+
} catch (err) {
|
|
687
|
+
log3.verbose("queue object JSON parse failed; object ignored", {
|
|
688
|
+
encoded,
|
|
689
|
+
error: err
|
|
690
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 22, S: this });
|
|
691
|
+
return [];
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
return {
|
|
695
|
+
objects,
|
|
696
|
+
nextCursor: result.nextCursor ?? null,
|
|
697
|
+
prevCursor: result.prevCursor ?? null
|
|
698
|
+
};
|
|
821
699
|
}
|
|
822
700
|
insertIntoQueue(queue, objects) {
|
|
823
701
|
return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
|
|
@@ -825,7 +703,7 @@ var QueuesAPIImpl = class {
|
|
|
825
703
|
};
|
|
826
704
|
|
|
827
705
|
// src/space-proxy.ts
|
|
828
|
-
var
|
|
706
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
829
707
|
var SpaceProxy = class extends Resource {
|
|
830
708
|
_serviceContainer;
|
|
831
709
|
_echoClient;
|
|
@@ -840,30 +718,14 @@ var SpaceProxy = class extends Resource {
|
|
|
840
718
|
return this._id;
|
|
841
719
|
}
|
|
842
720
|
get db() {
|
|
843
|
-
|
|
844
|
-
F: __dxlog_file5,
|
|
845
|
-
L: 35,
|
|
846
|
-
S: this,
|
|
847
|
-
A: [
|
|
848
|
-
"this._db",
|
|
849
|
-
""
|
|
850
|
-
]
|
|
851
|
-
});
|
|
721
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
|
|
852
722
|
return this._db;
|
|
853
723
|
}
|
|
854
724
|
/**
|
|
855
725
|
* @deprecated Use db API.
|
|
856
726
|
*/
|
|
857
727
|
get crud() {
|
|
858
|
-
|
|
859
|
-
F: __dxlog_file5,
|
|
860
|
-
L: 43,
|
|
861
|
-
S: this,
|
|
862
|
-
A: [
|
|
863
|
-
"this._db",
|
|
864
|
-
""
|
|
865
|
-
]
|
|
866
|
-
});
|
|
728
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
|
|
867
729
|
return this._db.coreDatabase;
|
|
868
730
|
}
|
|
869
731
|
get queues() {
|
|
@@ -876,18 +738,18 @@ var SpaceProxy = class extends Resource {
|
|
|
876
738
|
}
|
|
877
739
|
this._db = this._echoClient.constructDatabase({
|
|
878
740
|
spaceId: this._id,
|
|
879
|
-
spaceKey:
|
|
741
|
+
spaceKey: PublicKey.from(meta.spaceKey),
|
|
880
742
|
reactiveSchemaQuery: false,
|
|
881
743
|
owningObject: this
|
|
882
744
|
});
|
|
883
|
-
await this._db.coreDatabase.open({
|
|
745
|
+
await this._db.coreDatabase.open(this._ctx, {
|
|
884
746
|
rootUrl: meta.rootDocumentId
|
|
885
747
|
});
|
|
886
748
|
}
|
|
887
749
|
};
|
|
888
750
|
|
|
889
751
|
// src/functions-client.ts
|
|
890
|
-
var
|
|
752
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
|
|
891
753
|
var FunctionsClient = class extends Resource2 {
|
|
892
754
|
_serviceContainer;
|
|
893
755
|
_echoClient;
|
|
@@ -895,24 +757,8 @@ var FunctionsClient = class extends Resource2 {
|
|
|
895
757
|
_spaces = /* @__PURE__ */ new Map();
|
|
896
758
|
constructor(services) {
|
|
897
759
|
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
|
-
});
|
|
760
|
+
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'"] });
|
|
761
|
+
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'"] });
|
|
916
762
|
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
|
|
917
763
|
this._echoClient = new EchoClient({});
|
|
918
764
|
}
|
|
@@ -962,11 +808,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
962
808
|
})({});
|
|
963
809
|
|
|
964
810
|
// src/wrap-handler-for-cloudflare.ts
|
|
965
|
-
import { invariant as
|
|
966
|
-
import { SpaceId as
|
|
967
|
-
import { log as
|
|
811
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
812
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
813
|
+
import { log as log4 } from "@dxos/log";
|
|
968
814
|
import { EdgeResponse } from "@dxos/protocols";
|
|
969
|
-
var
|
|
815
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
970
816
|
var wrapHandlerForCloudflare = (func) => {
|
|
971
817
|
return async (request, env) => {
|
|
972
818
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
@@ -975,7 +821,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
975
821
|
try {
|
|
976
822
|
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
977
823
|
if (spaceId) {
|
|
978
|
-
if (!
|
|
824
|
+
if (!SpaceId2.isValid(spaceId)) {
|
|
979
825
|
return new Response("Invalid spaceId", {
|
|
980
826
|
status: 400
|
|
981
827
|
});
|
|
@@ -988,15 +834,10 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
988
834
|
});
|
|
989
835
|
return EdgeResponse.success(await invokeFunction(func, context, request));
|
|
990
836
|
} catch (error) {
|
|
991
|
-
|
|
837
|
+
log4.error("error invoking function", {
|
|
992
838
|
error,
|
|
993
839
|
stack: error.stack
|
|
994
|
-
}, {
|
|
995
|
-
F: __dxlog_file7,
|
|
996
|
-
L: 44,
|
|
997
|
-
S: void 0,
|
|
998
|
-
C: (f, a) => f(...a)
|
|
999
|
-
});
|
|
840
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
|
|
1000
841
|
return EdgeResponse.failure({
|
|
1001
842
|
message: error?.message ?? "Internal error",
|
|
1002
843
|
error
|
|
@@ -1029,12 +870,7 @@ var decodeRequest = async (request) => {
|
|
|
1029
870
|
}
|
|
1030
871
|
};
|
|
1031
872
|
} catch (err) {
|
|
1032
|
-
|
|
1033
|
-
F: __dxlog_file7,
|
|
1034
|
-
L: 79,
|
|
1035
|
-
S: void 0,
|
|
1036
|
-
C: (f, a) => f(...a)
|
|
1037
|
-
});
|
|
873
|
+
log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
|
|
1038
874
|
return {
|
|
1039
875
|
data: {
|
|
1040
876
|
bodyText,
|
|
@@ -1067,15 +903,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1067
903
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
1068
904
|
}
|
|
1069
905
|
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
|
-
});
|
|
906
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
|
|
1079
907
|
rootUrl = `automerge:${meta.rootDocumentId}`;
|
|
1080
908
|
}
|
|
1081
909
|
return {
|
|
@@ -1092,36 +920,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1092
920
|
};
|
|
1093
921
|
|
|
1094
922
|
// src/logger.ts
|
|
1095
|
-
import { LogLevel, log as
|
|
923
|
+
import { LogLevel, log as log5, shouldLog } from "@dxos/log";
|
|
1096
924
|
var setupFunctionsLogger = () => {
|
|
1097
|
-
|
|
1098
|
-
|
|
925
|
+
log5.runtimeConfig.processors.length = 0;
|
|
926
|
+
log5.runtimeConfig.processors.push(functionLogProcessor);
|
|
1099
927
|
};
|
|
1100
928
|
var functionLogProcessor = (config, entry) => {
|
|
1101
929
|
if (!shouldLog(entry, config.filters)) {
|
|
1102
930
|
return;
|
|
1103
931
|
}
|
|
932
|
+
const context = entry.computedContext;
|
|
933
|
+
const error = entry.computedError;
|
|
934
|
+
const extras = [
|
|
935
|
+
Object.keys(context).length > 0 ? context : void 0,
|
|
936
|
+
error
|
|
937
|
+
].filter((value) => value !== void 0);
|
|
1104
938
|
switch (entry.level) {
|
|
1105
939
|
case LogLevel.DEBUG:
|
|
1106
|
-
console.debug(entry.message, entry.context);
|
|
1107
|
-
break;
|
|
1108
940
|
case LogLevel.TRACE:
|
|
1109
|
-
console.debug(entry.message,
|
|
941
|
+
console.debug(entry.message, ...extras);
|
|
1110
942
|
break;
|
|
1111
943
|
case LogLevel.VERBOSE:
|
|
1112
|
-
console.log(entry.message,
|
|
944
|
+
console.log(entry.message, ...extras);
|
|
1113
945
|
break;
|
|
1114
946
|
case LogLevel.INFO:
|
|
1115
|
-
console.info(entry.message,
|
|
947
|
+
console.info(entry.message, ...extras);
|
|
1116
948
|
break;
|
|
1117
949
|
case LogLevel.WARN:
|
|
1118
|
-
console.warn(entry.message,
|
|
950
|
+
console.warn(entry.message, ...extras);
|
|
1119
951
|
break;
|
|
1120
952
|
case LogLevel.ERROR:
|
|
1121
|
-
console.error(entry.message,
|
|
953
|
+
console.error(entry.message, ...extras);
|
|
1122
954
|
break;
|
|
1123
955
|
default:
|
|
1124
|
-
console.log(entry.message,
|
|
956
|
+
console.log(entry.message, ...extras);
|
|
1125
957
|
break;
|
|
1126
958
|
}
|
|
1127
959
|
};
|
|
@@ -1131,6 +963,7 @@ export {
|
|
|
1131
963
|
FunctionsClient,
|
|
1132
964
|
ServiceContainer,
|
|
1133
965
|
createClientFromEnv,
|
|
966
|
+
createFunctionContext,
|
|
1134
967
|
setupFunctionsLogger,
|
|
1135
968
|
wrapHandlerForCloudflare
|
|
1136
969
|
};
|