@dxos/functions-runtime-cloudflare 0.8.4-main.3eb6e50203 → 0.8.4-main.3fbcb4aa9b
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 +78 -269
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +78 -269
- 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 +5 -1
- package/src/internal/service-container.ts +2 -2
- 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
|
};
|
|
@@ -233,12 +208,7 @@ var DataServiceImpl = class {
|
|
|
233
208
|
});
|
|
234
209
|
}
|
|
235
210
|
async updateIndexes() {
|
|
236
|
-
log.error("updateIndexes is not available in EDGE env.", void 0, {
|
|
237
|
-
F: __dxlog_file,
|
|
238
|
-
L: 133,
|
|
239
|
-
S: this,
|
|
240
|
-
C: (f, a) => f(...a)
|
|
241
|
-
});
|
|
211
|
+
log.error("updateIndexes is not available in EDGE env.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 206, S: this });
|
|
242
212
|
}
|
|
243
213
|
async waitUntilHeadsReplicated({ heads: _heads }) {
|
|
244
214
|
throw new NotImplementedError({
|
|
@@ -248,83 +218,10 @@ var DataServiceImpl = class {
|
|
|
248
218
|
};
|
|
249
219
|
|
|
250
220
|
// src/internal/query-service-impl.ts
|
|
251
|
-
import * as Schema from "effect/Schema";
|
|
252
221
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
253
|
-
import { QueryAST } from "@dxos/echo-protocol";
|
|
254
222
|
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
223
|
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
|
|
224
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
328
225
|
function _ts_add_disposable_resource2(env, value, async) {
|
|
329
226
|
if (value !== null && value !== void 0) {
|
|
330
227
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
@@ -390,7 +287,6 @@ function _ts_dispose_resources2(env) {
|
|
|
390
287
|
return next();
|
|
391
288
|
})(env);
|
|
392
289
|
}
|
|
393
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
394
290
|
var QueryServiceImpl = class {
|
|
395
291
|
_executionContext;
|
|
396
292
|
_dataService;
|
|
@@ -402,24 +298,7 @@ var QueryServiceImpl = class {
|
|
|
402
298
|
execQuery(request) {
|
|
403
299
|
log2.info("execQuery", {
|
|
404
300
|
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];
|
|
301
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
|
|
423
302
|
return Stream2.fromPromise((async () => {
|
|
424
303
|
try {
|
|
425
304
|
const env = {
|
|
@@ -430,37 +309,13 @@ var QueryServiceImpl = class {
|
|
|
430
309
|
try {
|
|
431
310
|
this._queryCount++;
|
|
432
311
|
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);
|
|
312
|
+
request
|
|
313
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 93, S: this });
|
|
314
|
+
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
|
|
441
315
|
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
|
-
};
|
|
316
|
+
resultCount: queryResponse.results?.length
|
|
317
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
|
|
318
|
+
return structuredClone(queryResponse);
|
|
464
319
|
} catch (e) {
|
|
465
320
|
env.error = e;
|
|
466
321
|
env.hasError = true;
|
|
@@ -470,17 +325,10 @@ var QueryServiceImpl = class {
|
|
|
470
325
|
} catch (error) {
|
|
471
326
|
log2.error("query failed", {
|
|
472
327
|
err: error
|
|
473
|
-
}, {
|
|
474
|
-
F: __dxlog_file3,
|
|
475
|
-
L: 66,
|
|
476
|
-
S: this,
|
|
477
|
-
C: (f, a) => f(...a)
|
|
478
|
-
});
|
|
328
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
|
|
479
329
|
throw new RuntimeServiceError2({
|
|
480
330
|
message: `Query execution failed (queryCount=${this._queryCount})`,
|
|
481
331
|
context: {
|
|
482
|
-
spaceId,
|
|
483
|
-
filter: request.filter,
|
|
484
332
|
queryCount: this._queryCount
|
|
485
333
|
},
|
|
486
334
|
cause: error
|
|
@@ -499,22 +347,6 @@ var QueryServiceImpl = class {
|
|
|
499
347
|
});
|
|
500
348
|
}
|
|
501
349
|
};
|
|
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
350
|
|
|
519
351
|
// src/internal/queue-service-impl.ts
|
|
520
352
|
import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
|
|
@@ -679,6 +511,8 @@ var QueueServiceImpl = class {
|
|
|
679
511
|
})(error);
|
|
680
512
|
}
|
|
681
513
|
}
|
|
514
|
+
async syncQueue(_) {
|
|
515
|
+
}
|
|
682
516
|
};
|
|
683
517
|
|
|
684
518
|
// src/internal/service-container.ts
|
|
@@ -819,17 +653,19 @@ var ServiceContainer = class {
|
|
|
819
653
|
subspaceTag,
|
|
820
654
|
spaceId,
|
|
821
655
|
queueId,
|
|
822
|
-
objects
|
|
656
|
+
objects: objects.map((obj) => JSON.stringify(obj))
|
|
823
657
|
});
|
|
824
658
|
}
|
|
825
659
|
};
|
|
826
660
|
|
|
827
661
|
// src/space-proxy.ts
|
|
828
662
|
import { Resource } from "@dxos/context";
|
|
829
|
-
import { invariant as
|
|
830
|
-
import { PublicKey
|
|
663
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
664
|
+
import { PublicKey } from "@dxos/keys";
|
|
831
665
|
|
|
832
666
|
// src/queues-api.ts
|
|
667
|
+
import { log as log3 } from "@dxos/log";
|
|
668
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/queues-api.ts";
|
|
833
669
|
var QueuesAPIImpl = class {
|
|
834
670
|
_serviceContainer;
|
|
835
671
|
_spaceId;
|
|
@@ -837,8 +673,26 @@ var QueuesAPIImpl = class {
|
|
|
837
673
|
this._serviceContainer = _serviceContainer;
|
|
838
674
|
this._spaceId = _spaceId;
|
|
839
675
|
}
|
|
840
|
-
queryQueue(queue, options) {
|
|
841
|
-
|
|
676
|
+
async queryQueue(queue, options) {
|
|
677
|
+
const result = await this._serviceContainer.queryQueue(queue);
|
|
678
|
+
const objects = (result.objects ?? []).flatMap((encoded) => {
|
|
679
|
+
try {
|
|
680
|
+
return [
|
|
681
|
+
JSON.parse(encoded)
|
|
682
|
+
];
|
|
683
|
+
} catch (err) {
|
|
684
|
+
log3.verbose("queue object JSON parse failed; object ignored", {
|
|
685
|
+
encoded,
|
|
686
|
+
error: err
|
|
687
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 22, S: this });
|
|
688
|
+
return [];
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
return {
|
|
692
|
+
objects,
|
|
693
|
+
nextCursor: result.nextCursor ?? null,
|
|
694
|
+
prevCursor: result.prevCursor ?? null
|
|
695
|
+
};
|
|
842
696
|
}
|
|
843
697
|
insertIntoQueue(queue, objects) {
|
|
844
698
|
return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
|
|
@@ -846,7 +700,7 @@ var QueuesAPIImpl = class {
|
|
|
846
700
|
};
|
|
847
701
|
|
|
848
702
|
// src/space-proxy.ts
|
|
849
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
703
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
850
704
|
var SpaceProxy = class extends Resource {
|
|
851
705
|
_serviceContainer;
|
|
852
706
|
_echoClient;
|
|
@@ -861,30 +715,14 @@ var SpaceProxy = class extends Resource {
|
|
|
861
715
|
return this._id;
|
|
862
716
|
}
|
|
863
717
|
get db() {
|
|
864
|
-
|
|
865
|
-
F: __dxlog_file4,
|
|
866
|
-
L: 35,
|
|
867
|
-
S: this,
|
|
868
|
-
A: [
|
|
869
|
-
"this._db",
|
|
870
|
-
""
|
|
871
|
-
]
|
|
872
|
-
});
|
|
718
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
|
|
873
719
|
return this._db;
|
|
874
720
|
}
|
|
875
721
|
/**
|
|
876
722
|
* @deprecated Use db API.
|
|
877
723
|
*/
|
|
878
724
|
get crud() {
|
|
879
|
-
|
|
880
|
-
F: __dxlog_file4,
|
|
881
|
-
L: 43,
|
|
882
|
-
S: this,
|
|
883
|
-
A: [
|
|
884
|
-
"this._db",
|
|
885
|
-
""
|
|
886
|
-
]
|
|
887
|
-
});
|
|
725
|
+
invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
|
|
888
726
|
return this._db.coreDatabase;
|
|
889
727
|
}
|
|
890
728
|
get queues() {
|
|
@@ -897,18 +735,18 @@ var SpaceProxy = class extends Resource {
|
|
|
897
735
|
}
|
|
898
736
|
this._db = this._echoClient.constructDatabase({
|
|
899
737
|
spaceId: this._id,
|
|
900
|
-
spaceKey:
|
|
738
|
+
spaceKey: PublicKey.from(meta.spaceKey),
|
|
901
739
|
reactiveSchemaQuery: false,
|
|
902
740
|
owningObject: this
|
|
903
741
|
});
|
|
904
|
-
await this._db.coreDatabase.open({
|
|
742
|
+
await this._db.coreDatabase.open(this._ctx, {
|
|
905
743
|
rootUrl: meta.rootDocumentId
|
|
906
744
|
});
|
|
907
745
|
}
|
|
908
746
|
};
|
|
909
747
|
|
|
910
748
|
// src/functions-client.ts
|
|
911
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/functions-client.ts";
|
|
749
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
|
|
912
750
|
var FunctionsClient = class extends Resource2 {
|
|
913
751
|
_serviceContainer;
|
|
914
752
|
_echoClient;
|
|
@@ -916,24 +754,8 @@ var FunctionsClient = class extends Resource2 {
|
|
|
916
754
|
_spaces = /* @__PURE__ */ new Map();
|
|
917
755
|
constructor(services) {
|
|
918
756
|
super();
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
L: 33,
|
|
922
|
-
S: this,
|
|
923
|
-
A: [
|
|
924
|
-
"typeof services.dataService !== 'undefined'",
|
|
925
|
-
"'DataService is required'"
|
|
926
|
-
]
|
|
927
|
-
});
|
|
928
|
-
invariant5(typeof services.queueService !== "undefined", "QueueService is required", {
|
|
929
|
-
F: __dxlog_file5,
|
|
930
|
-
L: 34,
|
|
931
|
-
S: this,
|
|
932
|
-
A: [
|
|
933
|
-
"typeof services.queueService !== 'undefined'",
|
|
934
|
-
"'QueueService is required'"
|
|
935
|
-
]
|
|
936
|
-
});
|
|
757
|
+
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'"] });
|
|
758
|
+
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'"] });
|
|
937
759
|
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
|
|
938
760
|
this._echoClient = new EchoClient({});
|
|
939
761
|
}
|
|
@@ -983,11 +805,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
983
805
|
})({});
|
|
984
806
|
|
|
985
807
|
// src/wrap-handler-for-cloudflare.ts
|
|
986
|
-
import { invariant as
|
|
987
|
-
import { SpaceId as
|
|
988
|
-
import { log as
|
|
808
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
809
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
810
|
+
import { log as log4 } from "@dxos/log";
|
|
989
811
|
import { EdgeResponse } from "@dxos/protocols";
|
|
990
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
812
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
991
813
|
var wrapHandlerForCloudflare = (func) => {
|
|
992
814
|
return async (request, env) => {
|
|
993
815
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
@@ -996,7 +818,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
996
818
|
try {
|
|
997
819
|
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
998
820
|
if (spaceId) {
|
|
999
|
-
if (!
|
|
821
|
+
if (!SpaceId2.isValid(spaceId)) {
|
|
1000
822
|
return new Response("Invalid spaceId", {
|
|
1001
823
|
status: 400
|
|
1002
824
|
});
|
|
@@ -1009,15 +831,10 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
1009
831
|
});
|
|
1010
832
|
return EdgeResponse.success(await invokeFunction(func, context, request));
|
|
1011
833
|
} catch (error) {
|
|
1012
|
-
|
|
834
|
+
log4.error("error invoking function", {
|
|
1013
835
|
error,
|
|
1014
836
|
stack: error.stack
|
|
1015
|
-
}, {
|
|
1016
|
-
F: __dxlog_file6,
|
|
1017
|
-
L: 44,
|
|
1018
|
-
S: void 0,
|
|
1019
|
-
C: (f, a) => f(...a)
|
|
1020
|
-
});
|
|
837
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
|
|
1021
838
|
return EdgeResponse.failure({
|
|
1022
839
|
message: error?.message ?? "Internal error",
|
|
1023
840
|
error
|
|
@@ -1050,12 +867,7 @@ var decodeRequest = async (request) => {
|
|
|
1050
867
|
}
|
|
1051
868
|
};
|
|
1052
869
|
} catch (err) {
|
|
1053
|
-
|
|
1054
|
-
F: __dxlog_file6,
|
|
1055
|
-
L: 79,
|
|
1056
|
-
S: void 0,
|
|
1057
|
-
C: (f, a) => f(...a)
|
|
1058
|
-
});
|
|
870
|
+
log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
|
|
1059
871
|
return {
|
|
1060
872
|
data: {
|
|
1061
873
|
bodyText,
|
|
@@ -1088,15 +900,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1088
900
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
1089
901
|
}
|
|
1090
902
|
spaceKey = meta.spaceKey;
|
|
1091
|
-
|
|
1092
|
-
F: __dxlog_file6,
|
|
1093
|
-
L: 117,
|
|
1094
|
-
S: void 0,
|
|
1095
|
-
A: [
|
|
1096
|
-
"!meta.rootDocumentId.startsWith('automerge:')",
|
|
1097
|
-
""
|
|
1098
|
-
]
|
|
1099
|
-
});
|
|
903
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
|
|
1100
904
|
rootUrl = `automerge:${meta.rootDocumentId}`;
|
|
1101
905
|
}
|
|
1102
906
|
return {
|
|
@@ -1113,36 +917,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
1113
917
|
};
|
|
1114
918
|
|
|
1115
919
|
// src/logger.ts
|
|
1116
|
-
import { LogLevel, log as
|
|
920
|
+
import { LogLevel, log as log5, shouldLog } from "@dxos/log";
|
|
1117
921
|
var setupFunctionsLogger = () => {
|
|
1118
|
-
|
|
1119
|
-
|
|
922
|
+
log5.runtimeConfig.processors.length = 0;
|
|
923
|
+
log5.runtimeConfig.processors.push(functionLogProcessor);
|
|
1120
924
|
};
|
|
1121
925
|
var functionLogProcessor = (config, entry) => {
|
|
1122
926
|
if (!shouldLog(entry, config.filters)) {
|
|
1123
927
|
return;
|
|
1124
928
|
}
|
|
929
|
+
const context = entry.computedContext;
|
|
930
|
+
const error = entry.computedError;
|
|
931
|
+
const extras = [
|
|
932
|
+
Object.keys(context).length > 0 ? context : void 0,
|
|
933
|
+
error
|
|
934
|
+
].filter((value) => value !== void 0);
|
|
1125
935
|
switch (entry.level) {
|
|
1126
936
|
case LogLevel.DEBUG:
|
|
1127
|
-
console.debug(entry.message, entry.context);
|
|
1128
|
-
break;
|
|
1129
937
|
case LogLevel.TRACE:
|
|
1130
|
-
console.debug(entry.message,
|
|
938
|
+
console.debug(entry.message, ...extras);
|
|
1131
939
|
break;
|
|
1132
940
|
case LogLevel.VERBOSE:
|
|
1133
|
-
console.log(entry.message,
|
|
941
|
+
console.log(entry.message, ...extras);
|
|
1134
942
|
break;
|
|
1135
943
|
case LogLevel.INFO:
|
|
1136
|
-
console.info(entry.message,
|
|
944
|
+
console.info(entry.message, ...extras);
|
|
1137
945
|
break;
|
|
1138
946
|
case LogLevel.WARN:
|
|
1139
|
-
console.warn(entry.message,
|
|
947
|
+
console.warn(entry.message, ...extras);
|
|
1140
948
|
break;
|
|
1141
949
|
case LogLevel.ERROR:
|
|
1142
|
-
console.error(entry.message,
|
|
950
|
+
console.error(entry.message, ...extras);
|
|
1143
951
|
break;
|
|
1144
952
|
default:
|
|
1145
|
-
console.log(entry.message,
|
|
953
|
+
console.log(entry.message, ...extras);
|
|
1146
954
|
break;
|
|
1147
955
|
}
|
|
1148
956
|
};
|
|
@@ -1152,6 +960,7 @@ export {
|
|
|
1152
960
|
FunctionsClient,
|
|
1153
961
|
ServiceContainer,
|
|
1154
962
|
createClientFromEnv,
|
|
963
|
+
createFunctionContext,
|
|
1155
964
|
setupFunctionsLogger,
|
|
1156
965
|
wrapHandlerForCloudflare
|
|
1157
966
|
};
|