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