@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
@@ -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 invariant5 } from "@dxos/invariant";
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/compute/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
- const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, {
186
- spaceId,
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
  };
@@ -205,6 +180,9 @@ var DataServiceImpl = class {
205
180
  }));
206
181
  try {
207
182
  for (const update of updates ?? []) {
183
+ if (!update.mutation) {
184
+ continue;
185
+ }
208
186
  await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
209
187
  }
210
188
  } catch (error) {
@@ -235,12 +213,7 @@ var DataServiceImpl = class {
235
213
  });
236
214
  }
237
215
  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
- });
216
+ log.verbose("updateIndexes called, but it is a no-op in EDGE env.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 211, S: this });
244
217
  }
245
218
  async waitUntilHeadsReplicated({ heads: _heads }) {
246
219
  throw new NotImplementedError({
@@ -250,86 +223,10 @@ var DataServiceImpl = class {
250
223
  };
251
224
 
252
225
  // src/internal/query-service-impl.ts
253
- import * as Schema from "effect/Schema";
254
226
  import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
255
- import { QueryAST } from "@dxos/echo-protocol";
256
227
  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
228
  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, spaceIds } = extractSimpleQuery(query) ?? failUndefined();
269
- invariant2(spaceIds?.length === 1, "Only one space is supported", {
270
- F: __dxlog_file2,
271
- L: 13,
272
- S: void 0,
273
- A: [
274
- "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 = 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 extractSimpleQuery = (query) => {
306
- switch (query.type) {
307
- case "options": {
308
- return extractSimpleQuery(query.query);
309
- }
310
- case "from": {
311
- const inner = extractSimpleQuery(query.query);
312
- if (!inner) {
313
- return null;
314
- }
315
- const spaceIds = query.from._tag === "scope" ? query.from.scope.spaceIds : void 0;
316
- return {
317
- filter: inner.filter,
318
- spaceIds: spaceIds ?? inner.spaceIds
319
- };
320
- }
321
- case "select": {
322
- return {
323
- filter: query.filter
324
- };
325
- }
326
- default: {
327
- return null;
328
- }
329
- }
330
- };
331
-
332
- // src/internal/query-service-impl.ts
229
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
333
230
  function _ts_add_disposable_resource2(env, value, async) {
334
231
  if (value !== null && value !== void 0) {
335
232
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -395,7 +292,6 @@ function _ts_dispose_resources2(env) {
395
292
  return next();
396
293
  })(env);
397
294
  }
398
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
399
295
  var QueryServiceImpl = class {
400
296
  _executionContext;
401
297
  _dataService;
@@ -407,24 +303,7 @@ var QueryServiceImpl = class {
407
303
  execQuery(request) {
408
304
  log2.info("execQuery", {
409
305
  request
410
- }, {
411
- F: __dxlog_file3,
412
- L: 34,
413
- S: this,
414
- C: (f, a) => f(...a)
415
- });
416
- const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));
417
- const requestedSpaceIds = getTargetSpacesForQuery(query);
418
- invariant3(requestedSpaceIds.length === 1, "Only one space is supported", {
419
- F: __dxlog_file3,
420
- L: 37,
421
- S: this,
422
- A: [
423
- "requestedSpaceIds.length === 1",
424
- "'Only one space is supported'"
425
- ]
426
- });
427
- const spaceId = requestedSpaceIds[0];
306
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
428
307
  return Stream2.fromPromise((async () => {
429
308
  try {
430
309
  const env = {
@@ -435,37 +314,13 @@ var QueryServiceImpl = class {
435
314
  try {
436
315
  this._queryCount++;
437
316
  log2.info("begin query", {
438
- spaceId
439
- }, {
440
- F: __dxlog_file3,
441
- L: 44,
442
- S: this,
443
- C: (f, a) => f(...a)
444
- });
445
- const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.queryDocuments(this._executionContext, queryToDataServiceRequest(query)), false);
317
+ request
318
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 93, S: this });
319
+ const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
446
320
  log2.info("query response", {
447
- spaceId,
448
- filter: request.filter,
449
- resultCount: queryResponse.results.length
450
- }, {
451
- F: __dxlog_file3,
452
- L: 49,
453
- S: this,
454
- C: (f, a) => f(...a)
455
- });
456
- return {
457
- results: queryResponse.results.map((object) => ({
458
- id: object.objectId,
459
- spaceId,
460
- spaceKey: PublicKey.ZERO,
461
- documentId: object.document.documentId,
462
- // Rank 1 for predicate matches where ranking is not determined.
463
- rank: 1,
464
- // Copy returned object to avoid hanging RPC stub.
465
- // See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
466
- documentAutomerge: copyUint8Array(object.document.data)
467
- }))
468
- };
321
+ resultCount: queryResponse.results?.length
322
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
323
+ return structuredClone(queryResponse);
469
324
  } catch (e) {
470
325
  env.error = e;
471
326
  env.hasError = true;
@@ -475,17 +330,10 @@ var QueryServiceImpl = class {
475
330
  } catch (error) {
476
331
  log2.error("query failed", {
477
332
  err: error
478
- }, {
479
- F: __dxlog_file3,
480
- L: 66,
481
- S: this,
482
- C: (f, a) => f(...a)
483
- });
333
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
484
334
  throw new RuntimeServiceError2({
485
335
  message: `Query execution failed (queryCount=${this._queryCount})`,
486
336
  context: {
487
- spaceId,
488
- filter: request.filter,
489
337
  queryCount: this._queryCount
490
338
  },
491
339
  cause: error
@@ -504,22 +352,6 @@ var QueryServiceImpl = class {
504
352
  });
505
353
  }
506
354
  };
507
- var getTargetSpacesForQuery = (query) => {
508
- const spaces = /* @__PURE__ */ new Set();
509
- const visitor = (node) => {
510
- if (node.type === "from" && node.from._tag === "scope") {
511
- if (node.from.scope.spaceIds) {
512
- for (const spaceId of node.from.scope.spaceIds) {
513
- spaces.add(SpaceId3.make(spaceId));
514
- }
515
- }
516
- }
517
- };
518
- QueryAST.visit(query, visitor);
519
- return [
520
- ...spaces
521
- ];
522
- };
523
355
 
524
356
  // src/internal/queue-service-impl.ts
525
357
  import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
@@ -826,17 +658,19 @@ var ServiceContainer = class {
826
658
  subspaceTag,
827
659
  spaceId,
828
660
  queueId,
829
- objects
661
+ objects: objects.map((obj) => JSON.stringify(obj))
830
662
  });
831
663
  }
832
664
  };
833
665
 
834
666
  // src/space-proxy.ts
835
667
  import { Resource } from "@dxos/context";
836
- import { invariant as invariant4 } from "@dxos/invariant";
837
- import { PublicKey as PublicKey2 } from "@dxos/keys";
668
+ import { invariant as invariant2 } from "@dxos/invariant";
669
+ import { PublicKey } from "@dxos/keys";
838
670
 
839
671
  // src/queues-api.ts
672
+ import { log as log3 } from "@dxos/log";
673
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/queues-api.ts";
840
674
  var QueuesAPIImpl = class {
841
675
  _serviceContainer;
842
676
  _spaceId;
@@ -844,8 +678,26 @@ var QueuesAPIImpl = class {
844
678
  this._serviceContainer = _serviceContainer;
845
679
  this._spaceId = _spaceId;
846
680
  }
847
- queryQueue(queue, options) {
848
- return this._serviceContainer.queryQueue(queue);
681
+ async queryQueue(queue, options) {
682
+ const result = await this._serviceContainer.queryQueue(queue);
683
+ const objects = (result.objects ?? []).flatMap((encoded) => {
684
+ try {
685
+ return [
686
+ JSON.parse(encoded)
687
+ ];
688
+ } catch (err) {
689
+ log3.verbose("queue object JSON parse failed; object ignored", {
690
+ encoded,
691
+ error: err
692
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 22, S: this });
693
+ return [];
694
+ }
695
+ });
696
+ return {
697
+ objects,
698
+ nextCursor: result.nextCursor ?? null,
699
+ prevCursor: result.prevCursor ?? null
700
+ };
849
701
  }
850
702
  insertIntoQueue(queue, objects) {
851
703
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
@@ -853,7 +705,7 @@ var QueuesAPIImpl = class {
853
705
  };
854
706
 
855
707
  // src/space-proxy.ts
856
- var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/space-proxy.ts";
708
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/space-proxy.ts";
857
709
  var SpaceProxy = class extends Resource {
858
710
  _serviceContainer;
859
711
  _echoClient;
@@ -868,30 +720,14 @@ var SpaceProxy = class extends Resource {
868
720
  return this._id;
869
721
  }
870
722
  get db() {
871
- invariant4(this._db, void 0, {
872
- F: __dxlog_file4,
873
- L: 35,
874
- S: this,
875
- A: [
876
- "this._db",
877
- ""
878
- ]
879
- });
723
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
880
724
  return this._db;
881
725
  }
882
726
  /**
883
727
  * @deprecated Use db API.
884
728
  */
885
729
  get crud() {
886
- invariant4(this._db, void 0, {
887
- F: __dxlog_file4,
888
- L: 43,
889
- S: this,
890
- A: [
891
- "this._db",
892
- ""
893
- ]
894
- });
730
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
895
731
  return this._db.coreDatabase;
896
732
  }
897
733
  get queues() {
@@ -904,18 +740,18 @@ var SpaceProxy = class extends Resource {
904
740
  }
905
741
  this._db = this._echoClient.constructDatabase({
906
742
  spaceId: this._id,
907
- spaceKey: PublicKey2.from(meta.spaceKey),
743
+ spaceKey: PublicKey.from(meta.spaceKey),
908
744
  reactiveSchemaQuery: false,
909
745
  owningObject: this
910
746
  });
911
- await this._db.coreDatabase.open({
747
+ await this._db.coreDatabase.open(this._ctx, {
912
748
  rootUrl: meta.rootDocumentId
913
749
  });
914
750
  }
915
751
  };
916
752
 
917
753
  // src/functions-client.ts
918
- var __dxlog_file5 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/functions-client.ts";
754
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/functions-client.ts";
919
755
  var FunctionsClient = class extends Resource2 {
920
756
  _serviceContainer;
921
757
  _echoClient;
@@ -923,24 +759,8 @@ var FunctionsClient = class extends Resource2 {
923
759
  _spaces = /* @__PURE__ */ new Map();
924
760
  constructor(services) {
925
761
  super();
926
- invariant5(typeof services.dataService !== "undefined", "DataService is required", {
927
- F: __dxlog_file5,
928
- L: 33,
929
- S: this,
930
- A: [
931
- "typeof services.dataService !== 'undefined'",
932
- "'DataService is required'"
933
- ]
934
- });
935
- invariant5(typeof services.queueService !== "undefined", "QueueService is required", {
936
- F: __dxlog_file5,
937
- L: 34,
938
- S: this,
939
- A: [
940
- "typeof services.queueService !== 'undefined'",
941
- "'QueueService is required'"
942
- ]
943
- });
762
+ 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'"] });
763
+ 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'"] });
944
764
  this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
945
765
  this._echoClient = new EchoClient({});
946
766
  }
@@ -990,11 +810,11 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
990
810
  })({});
991
811
 
992
812
  // src/wrap-handler-for-cloudflare.ts
993
- import { invariant as invariant6 } from "@dxos/invariant";
994
- import { SpaceId as SpaceId4 } from "@dxos/keys";
995
- import { log as log3 } from "@dxos/log";
813
+ import { invariant as invariant4 } from "@dxos/invariant";
814
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
815
+ import { log as log4 } from "@dxos/log";
996
816
  import { EdgeResponse } from "@dxos/protocols";
997
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
817
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
998
818
  var wrapHandlerForCloudflare = (func) => {
999
819
  return async (request, env) => {
1000
820
  if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
@@ -1003,7 +823,7 @@ var wrapHandlerForCloudflare = (func) => {
1003
823
  try {
1004
824
  const spaceId = new URL(request.url).searchParams.get("spaceId");
1005
825
  if (spaceId) {
1006
- if (!SpaceId4.isValid(spaceId)) {
826
+ if (!SpaceId2.isValid(spaceId)) {
1007
827
  return new Response("Invalid spaceId", {
1008
828
  status: 400
1009
829
  });
@@ -1016,15 +836,10 @@ var wrapHandlerForCloudflare = (func) => {
1016
836
  });
1017
837
  return EdgeResponse.success(await invokeFunction(func, context, request));
1018
838
  } catch (error) {
1019
- log3.error("error invoking function", {
839
+ log4.error("error invoking function", {
1020
840
  error,
1021
841
  stack: error.stack
1022
- }, {
1023
- F: __dxlog_file6,
1024
- L: 44,
1025
- S: void 0,
1026
- C: (f, a) => f(...a)
1027
- });
842
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
1028
843
  return EdgeResponse.failure({
1029
844
  message: error?.message ?? "Internal error",
1030
845
  error
@@ -1057,12 +872,7 @@ var decodeRequest = async (request) => {
1057
872
  }
1058
873
  };
1059
874
  } catch (err) {
1060
- log3.catch(err, void 0, {
1061
- F: __dxlog_file6,
1062
- L: 79,
1063
- S: void 0,
1064
- C: (f, a) => f(...a)
1065
- });
875
+ log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
1066
876
  return {
1067
877
  data: {
1068
878
  bodyText,
@@ -1095,15 +905,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1095
905
  throw new Error(`Space not found: ${contextSpaceId}`);
1096
906
  }
1097
907
  spaceKey = meta.spaceKey;
1098
- invariant6(!meta.rootDocumentId.startsWith("automerge:"), void 0, {
1099
- F: __dxlog_file6,
1100
- L: 117,
1101
- S: void 0,
1102
- A: [
1103
- "!meta.rootDocumentId.startsWith('automerge:')",
1104
- ""
1105
- ]
1106
- });
908
+ invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
1107
909
  rootUrl = `automerge:${meta.rootDocumentId}`;
1108
910
  }
1109
911
  return {
@@ -1120,36 +922,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1120
922
  };
1121
923
 
1122
924
  // src/logger.ts
1123
- import { LogLevel, log as log4, shouldLog } from "@dxos/log";
925
+ import { LogLevel, log as log5, shouldLog } from "@dxos/log";
1124
926
  var setupFunctionsLogger = () => {
1125
- log4.runtimeConfig.processors.length = 0;
1126
- log4.runtimeConfig.processors.push(functionLogProcessor);
927
+ log5.runtimeConfig.processors.length = 0;
928
+ log5.runtimeConfig.processors.push(functionLogProcessor);
1127
929
  };
1128
930
  var functionLogProcessor = (config, entry) => {
1129
931
  if (!shouldLog(entry, config.filters)) {
1130
932
  return;
1131
933
  }
934
+ const context = entry.computedContext;
935
+ const error = entry.computedError;
936
+ const extras = [
937
+ Object.keys(context).length > 0 ? context : void 0,
938
+ error
939
+ ].filter((value) => value !== void 0);
1132
940
  switch (entry.level) {
1133
941
  case LogLevel.DEBUG:
1134
- console.debug(entry.message, entry.context);
1135
- break;
1136
942
  case LogLevel.TRACE:
1137
- console.debug(entry.message, entry.context);
943
+ console.debug(entry.message, ...extras);
1138
944
  break;
1139
945
  case LogLevel.VERBOSE:
1140
- console.log(entry.message, entry.context);
946
+ console.log(entry.message, ...extras);
1141
947
  break;
1142
948
  case LogLevel.INFO:
1143
- console.info(entry.message, entry.context);
949
+ console.info(entry.message, ...extras);
1144
950
  break;
1145
951
  case LogLevel.WARN:
1146
- console.warn(entry.message, entry.context);
952
+ console.warn(entry.message, ...extras);
1147
953
  break;
1148
954
  case LogLevel.ERROR:
1149
- console.error(entry.message, entry.context);
955
+ console.error(entry.message, ...extras);
1150
956
  break;
1151
957
  default:
1152
- console.log(entry.message, entry.context);
958
+ console.log(entry.message, ...extras);
1153
959
  break;
1154
960
  }
1155
961
  };
@@ -1159,6 +965,7 @@ export {
1159
965
  FunctionsClient,
1160
966
  ServiceContainer,
1161
967
  createClientFromEnv,
968
+ createFunctionContext,
1162
969
  setupFunctionsLogger,
1163
970
  wrapHandlerForCloudflare
1164
971
  };