@dxos/functions-runtime-cloudflare 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a

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.
Files changed (38) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/index.mjs +79 -272
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/node-esm/index.mjs +79 -272
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/types/src/functions-client.d.ts +0 -5
  10. package/dist/types/src/functions-client.d.ts.map +1 -1
  11. package/dist/types/src/internal/data-service-impl.d.ts +1 -1
  12. package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
  13. package/dist/types/src/internal/query-service-impl.d.ts +3 -9
  14. package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
  15. package/dist/types/src/internal/queue-service-impl.d.ts +2 -2
  16. package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
  17. package/dist/types/src/internal/service-container.d.ts +2 -2
  18. package/dist/types/src/internal/service-container.d.ts.map +1 -1
  19. package/dist/types/src/internal/utils.d.ts.map +1 -1
  20. package/dist/types/src/queues-api.d.ts +7 -3
  21. package/dist/types/src/queues-api.d.ts.map +1 -1
  22. package/dist/types/src/space-proxy.d.ts.map +1 -1
  23. package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
  24. package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
  25. package/dist/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +16 -16
  27. package/src/functions-client.ts +1 -7
  28. package/src/internal/data-service-impl.ts +9 -3
  29. package/src/internal/query-service-impl.ts +8 -62
  30. package/src/internal/queue-service-impl.ts +1 -1
  31. package/src/internal/service-container.ts +6 -3
  32. package/src/logger.ts +10 -8
  33. package/src/queues-api.ts +23 -4
  34. package/src/space-proxy.ts +1 -1
  35. package/src/wrap-handler-for-cloudflare.ts +1 -1
  36. package/dist/types/src/internal/adapter.d.ts +0 -4
  37. package/dist/types/src/internal/adapter.d.ts.map +0 -1
  38. package/src/internal/adapter.ts +0 -52
@@ -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 invariant5 } from "@dxos/invariant";
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
- const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, {
184
- spaceId,
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.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
- });
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,86 +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, spaceIds } = extractSimpleQuery(query) ?? failUndefined();
267
- invariant2(spaceIds?.length === 1, "Only one space is supported", {
268
- F: __dxlog_file2,
269
- L: 13,
270
- S: void 0,
271
- A: [
272
- "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 = 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 extractSimpleQuery = (query) => {
304
- switch (query.type) {
305
- case "options": {
306
- return extractSimpleQuery(query.query);
307
- }
308
- case "from": {
309
- const inner = extractSimpleQuery(query.query);
310
- if (!inner) {
311
- return null;
312
- }
313
- const spaceIds = query.from._tag === "scope" ? query.from.scope.spaceIds : void 0;
314
- return {
315
- filter: inner.filter,
316
- spaceIds: spaceIds ?? inner.spaceIds
317
- };
318
- }
319
- case "select": {
320
- return {
321
- filter: query.filter
322
- };
323
- }
324
- default: {
325
- return null;
326
- }
327
- }
328
- };
329
-
330
- // 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";
331
228
  function _ts_add_disposable_resource2(env, value, async) {
332
229
  if (value !== null && value !== void 0) {
333
230
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -393,7 +290,6 @@ function _ts_dispose_resources2(env) {
393
290
  return next();
394
291
  })(env);
395
292
  }
396
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
397
293
  var QueryServiceImpl = class {
398
294
  _executionContext;
399
295
  _dataService;
@@ -405,24 +301,7 @@ var QueryServiceImpl = class {
405
301
  execQuery(request) {
406
302
  log2.info("execQuery", {
407
303
  request
408
- }, {
409
- F: __dxlog_file3,
410
- L: 34,
411
- S: this,
412
- C: (f, a) => f(...a)
413
- });
414
- const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));
415
- const requestedSpaceIds = getTargetSpacesForQuery(query);
416
- invariant3(requestedSpaceIds.length === 1, "Only one space is supported", {
417
- F: __dxlog_file3,
418
- L: 37,
419
- S: this,
420
- A: [
421
- "requestedSpaceIds.length === 1",
422
- "'Only one space is supported'"
423
- ]
424
- });
425
- const spaceId = requestedSpaceIds[0];
304
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
426
305
  return Stream2.fromPromise((async () => {
427
306
  try {
428
307
  const env = {
@@ -433,37 +312,13 @@ var QueryServiceImpl = class {
433
312
  try {
434
313
  this._queryCount++;
435
314
  log2.info("begin query", {
436
- spaceId
437
- }, {
438
- F: __dxlog_file3,
439
- L: 44,
440
- S: this,
441
- C: (f, a) => f(...a)
442
- });
443
- 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);
444
318
  log2.info("query response", {
445
- spaceId,
446
- filter: request.filter,
447
- resultCount: queryResponse.results.length
448
- }, {
449
- F: __dxlog_file3,
450
- L: 49,
451
- S: this,
452
- C: (f, a) => f(...a)
453
- });
454
- return {
455
- results: queryResponse.results.map((object) => ({
456
- id: object.objectId,
457
- spaceId,
458
- spaceKey: PublicKey.ZERO,
459
- documentId: object.document.documentId,
460
- // Rank 1 for predicate matches where ranking is not determined.
461
- rank: 1,
462
- // Copy returned object to avoid hanging RPC stub.
463
- // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
464
- documentAutomerge: copyUint8Array(object.document.data)
465
- }))
466
- };
319
+ resultCount: queryResponse.results?.length
320
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
321
+ return structuredClone(queryResponse);
467
322
  } catch (e) {
468
323
  env.error = e;
469
324
  env.hasError = true;
@@ -473,17 +328,10 @@ var QueryServiceImpl = class {
473
328
  } catch (error) {
474
329
  log2.error("query failed", {
475
330
  err: error
476
- }, {
477
- F: __dxlog_file3,
478
- L: 66,
479
- S: this,
480
- C: (f, a) => f(...a)
481
- });
331
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
482
332
  throw new RuntimeServiceError2({
483
333
  message: `Query execution failed (queryCount=${this._queryCount})`,
484
334
  context: {
485
- spaceId,
486
- filter: request.filter,
487
335
  queryCount: this._queryCount
488
336
  },
489
337
  cause: error
@@ -502,22 +350,6 @@ var QueryServiceImpl = class {
502
350
  });
503
351
  }
504
352
  };
505
- var getTargetSpacesForQuery = (query) => {
506
- const spaces = /* @__PURE__ */ new Set();
507
- const visitor = (node) => {
508
- if (node.type === "from" && node.from._tag === "scope") {
509
- if (node.from.scope.spaceIds) {
510
- for (const spaceId of node.from.scope.spaceIds) {
511
- spaces.add(SpaceId3.make(spaceId));
512
- }
513
- }
514
- }
515
- };
516
- QueryAST.visit(query, visitor);
517
- return [
518
- ...spaces
519
- ];
520
- };
521
353
 
522
354
  // src/internal/queue-service-impl.ts
523
355
  import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
@@ -824,17 +656,19 @@ var ServiceContainer = class {
824
656
  subspaceTag,
825
657
  spaceId,
826
658
  queueId,
827
- objects
659
+ objects: objects.map((obj) => JSON.stringify(obj))
828
660
  });
829
661
  }
830
662
  };
831
663
 
832
664
  // src/space-proxy.ts
833
665
  import { Resource } from "@dxos/context";
834
- import { invariant as invariant4 } from "@dxos/invariant";
835
- import { PublicKey as PublicKey2 } from "@dxos/keys";
666
+ import { invariant as invariant2 } from "@dxos/invariant";
667
+ import { PublicKey } from "@dxos/keys";
836
668
 
837
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";
838
672
  var QueuesAPIImpl = class {
839
673
  _serviceContainer;
840
674
  _spaceId;
@@ -842,8 +676,26 @@ var QueuesAPIImpl = class {
842
676
  this._serviceContainer = _serviceContainer;
843
677
  this._spaceId = _spaceId;
844
678
  }
845
- queryQueue(queue, options) {
846
- return this._serviceContainer.queryQueue(queue);
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
+ };
847
699
  }
848
700
  insertIntoQueue(queue, objects) {
849
701
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
@@ -851,7 +703,7 @@ var QueuesAPIImpl = class {
851
703
  };
852
704
 
853
705
  // src/space-proxy.ts
854
- var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/space-proxy.ts";
706
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
855
707
  var SpaceProxy = class extends Resource {
856
708
  _serviceContainer;
857
709
  _echoClient;
@@ -866,30 +718,14 @@ var SpaceProxy = class extends Resource {
866
718
  return this._id;
867
719
  }
868
720
  get db() {
869
- invariant4(this._db, void 0, {
870
- F: __dxlog_file4,
871
- L: 35,
872
- S: this,
873
- A: [
874
- "this._db",
875
- ""
876
- ]
877
- });
721
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
878
722
  return this._db;
879
723
  }
880
724
  /**
881
725
  * @deprecated Use db API.
882
726
  */
883
727
  get crud() {
884
- invariant4(this._db, void 0, {
885
- F: __dxlog_file4,
886
- L: 43,
887
- S: this,
888
- A: [
889
- "this._db",
890
- ""
891
- ]
892
- });
728
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
893
729
  return this._db.coreDatabase;
894
730
  }
895
731
  get queues() {
@@ -902,18 +738,18 @@ var SpaceProxy = class extends Resource {
902
738
  }
903
739
  this._db = this._echoClient.constructDatabase({
904
740
  spaceId: this._id,
905
- spaceKey: PublicKey2.from(meta.spaceKey),
741
+ spaceKey: PublicKey.from(meta.spaceKey),
906
742
  reactiveSchemaQuery: false,
907
743
  owningObject: this
908
744
  });
909
- await this._db.coreDatabase.open({
745
+ await this._db.coreDatabase.open(this._ctx, {
910
746
  rootUrl: meta.rootDocumentId
911
747
  });
912
748
  }
913
749
  };
914
750
 
915
751
  // src/functions-client.ts
916
- var __dxlog_file5 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/functions-client.ts";
752
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
917
753
  var FunctionsClient = class extends Resource2 {
918
754
  _serviceContainer;
919
755
  _echoClient;
@@ -921,24 +757,8 @@ var FunctionsClient = class extends Resource2 {
921
757
  _spaces = /* @__PURE__ */ new Map();
922
758
  constructor(services) {
923
759
  super();
924
- invariant5(typeof services.dataService !== "undefined", "DataService is required", {
925
- F: __dxlog_file5,
926
- L: 33,
927
- S: this,
928
- A: [
929
- "typeof services.dataService !== 'undefined'",
930
- "'DataService is required'"
931
- ]
932
- });
933
- invariant5(typeof services.queueService !== "undefined", "QueueService is required", {
934
- F: __dxlog_file5,
935
- L: 34,
936
- S: this,
937
- A: [
938
- "typeof services.queueService !== 'undefined'",
939
- "'QueueService is required'"
940
- ]
941
- });
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'"] });
942
762
  this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
943
763
  this._echoClient = new EchoClient({});
944
764
  }
@@ -988,11 +808,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
988
808
  })({});
989
809
 
990
810
  // src/wrap-handler-for-cloudflare.ts
991
- import { invariant as invariant6 } from "@dxos/invariant";
992
- import { SpaceId as SpaceId4 } from "@dxos/keys";
993
- import { log as log3 } from "@dxos/log";
811
+ import { invariant as invariant4 } from "@dxos/invariant";
812
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
813
+ import { log as log4 } from "@dxos/log";
994
814
  import { EdgeResponse } from "@dxos/protocols";
995
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
815
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
996
816
  var wrapHandlerForCloudflare = (func) => {
997
817
  return async (request, env) => {
998
818
  if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
@@ -1001,7 +821,7 @@ var wrapHandlerForCloudflare = (func) => {
1001
821
  try {
1002
822
  const spaceId = new URL(request.url).searchParams.get("spaceId");
1003
823
  if (spaceId) {
1004
- if (!SpaceId4.isValid(spaceId)) {
824
+ if (!SpaceId2.isValid(spaceId)) {
1005
825
  return new Response("Invalid spaceId", {
1006
826
  status: 400
1007
827
  });
@@ -1014,15 +834,10 @@ var wrapHandlerForCloudflare = (func) => {
1014
834
  });
1015
835
  return EdgeResponse.success(await invokeFunction(func, context, request));
1016
836
  } catch (error) {
1017
- log3.error("error invoking function", {
837
+ log4.error("error invoking function", {
1018
838
  error,
1019
839
  stack: error.stack
1020
- }, {
1021
- F: __dxlog_file6,
1022
- L: 44,
1023
- S: void 0,
1024
- C: (f, a) => f(...a)
1025
- });
840
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
1026
841
  return EdgeResponse.failure({
1027
842
  message: error?.message ?? "Internal error",
1028
843
  error
@@ -1055,12 +870,7 @@ var decodeRequest = async (request) => {
1055
870
  }
1056
871
  };
1057
872
  } catch (err) {
1058
- log3.catch(err, void 0, {
1059
- F: __dxlog_file6,
1060
- L: 79,
1061
- S: void 0,
1062
- C: (f, a) => f(...a)
1063
- });
873
+ log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
1064
874
  return {
1065
875
  data: {
1066
876
  bodyText,
@@ -1093,15 +903,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1093
903
  throw new Error(`Space not found: ${contextSpaceId}`);
1094
904
  }
1095
905
  spaceKey = meta.spaceKey;
1096
- invariant6(!meta.rootDocumentId.startsWith("automerge:"), void 0, {
1097
- F: __dxlog_file6,
1098
- L: 117,
1099
- S: void 0,
1100
- A: [
1101
- "!meta.rootDocumentId.startsWith('automerge:')",
1102
- ""
1103
- ]
1104
- });
906
+ invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
1105
907
  rootUrl = `automerge:${meta.rootDocumentId}`;
1106
908
  }
1107
909
  return {
@@ -1118,36 +920,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1118
920
  };
1119
921
 
1120
922
  // src/logger.ts
1121
- import { LogLevel, log as log4, shouldLog } from "@dxos/log";
923
+ import { LogLevel, log as log5, shouldLog } from "@dxos/log";
1122
924
  var setupFunctionsLogger = () => {
1123
- log4.runtimeConfig.processors.length = 0;
1124
- log4.runtimeConfig.processors.push(functionLogProcessor);
925
+ log5.runtimeConfig.processors.length = 0;
926
+ log5.runtimeConfig.processors.push(functionLogProcessor);
1125
927
  };
1126
928
  var functionLogProcessor = (config, entry) => {
1127
929
  if (!shouldLog(entry, config.filters)) {
1128
930
  return;
1129
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);
1130
938
  switch (entry.level) {
1131
939
  case LogLevel.DEBUG:
1132
- console.debug(entry.message, entry.context);
1133
- break;
1134
940
  case LogLevel.TRACE:
1135
- console.debug(entry.message, entry.context);
941
+ console.debug(entry.message, ...extras);
1136
942
  break;
1137
943
  case LogLevel.VERBOSE:
1138
- console.log(entry.message, entry.context);
944
+ console.log(entry.message, ...extras);
1139
945
  break;
1140
946
  case LogLevel.INFO:
1141
- console.info(entry.message, entry.context);
947
+ console.info(entry.message, ...extras);
1142
948
  break;
1143
949
  case LogLevel.WARN:
1144
- console.warn(entry.message, entry.context);
950
+ console.warn(entry.message, ...extras);
1145
951
  break;
1146
952
  case LogLevel.ERROR:
1147
- console.error(entry.message, entry.context);
953
+ console.error(entry.message, ...extras);
1148
954
  break;
1149
955
  default:
1150
- console.log(entry.message, entry.context);
956
+ console.log(entry.message, ...extras);
1151
957
  break;
1152
958
  }
1153
959
  };
@@ -1157,6 +963,7 @@ export {
1157
963
  FunctionsClient,
1158
964
  ServiceContainer,
1159
965
  createClientFromEnv,
966
+ createFunctionContext,
1160
967
  setupFunctionsLogger,
1161
968
  wrapHandlerForCloudflare
1162
969
  };