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

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 (35) hide show
  1. package/dist/lib/browser/index.mjs +73 -269
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +73 -269
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/functions-client.d.ts.map +1 -1
  8. package/dist/types/src/internal/data-service-impl.d.ts +1 -1
  9. package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
  10. package/dist/types/src/internal/query-service-impl.d.ts +3 -9
  11. package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
  12. package/dist/types/src/internal/queue-service-impl.d.ts +2 -2
  13. package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
  14. package/dist/types/src/internal/service-container.d.ts +1 -1
  15. package/dist/types/src/internal/service-container.d.ts.map +1 -1
  16. package/dist/types/src/internal/utils.d.ts.map +1 -1
  17. package/dist/types/src/queues-api.d.ts +7 -3
  18. package/dist/types/src/queues-api.d.ts.map +1 -1
  19. package/dist/types/src/space-proxy.d.ts.map +1 -1
  20. package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
  21. package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
  22. package/dist/types/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +15 -15
  24. package/src/functions-client.ts +1 -1
  25. package/src/internal/data-service-impl.ts +3 -2
  26. package/src/internal/query-service-impl.ts +8 -62
  27. package/src/internal/queue-service-impl.ts +1 -1
  28. package/src/internal/service-container.ts +2 -2
  29. package/src/logger.ts +10 -8
  30. package/src/queues-api.ts +23 -4
  31. package/src/space-proxy.ts +1 -1
  32. package/src/wrap-handler-for-cloudflare.ts +1 -1
  33. package/dist/types/src/internal/adapter.d.ts +0 -4
  34. package/dist/types/src/internal/adapter.d.ts.map +0 -1
  35. 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/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
  };
@@ -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,86 +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, 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
226
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
333
227
  function _ts_add_disposable_resource2(env, value, async) {
334
228
  if (value !== null && value !== void 0) {
335
229
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -395,7 +289,6 @@ function _ts_dispose_resources2(env) {
395
289
  return next();
396
290
  })(env);
397
291
  }
398
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
399
292
  var QueryServiceImpl = class {
400
293
  _executionContext;
401
294
  _dataService;
@@ -407,24 +300,7 @@ var QueryServiceImpl = class {
407
300
  execQuery(request) {
408
301
  log2.info("execQuery", {
409
302
  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];
303
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
428
304
  return Stream2.fromPromise((async () => {
429
305
  try {
430
306
  const env = {
@@ -435,37 +311,13 @@ var QueryServiceImpl = class {
435
311
  try {
436
312
  this._queryCount++;
437
313
  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);
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);
446
317
  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
- };
318
+ resultCount: queryResponse.results?.length
319
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
320
+ return structuredClone(queryResponse);
469
321
  } catch (e) {
470
322
  env.error = e;
471
323
  env.hasError = true;
@@ -475,17 +327,10 @@ var QueryServiceImpl = class {
475
327
  } catch (error) {
476
328
  log2.error("query failed", {
477
329
  err: error
478
- }, {
479
- F: __dxlog_file3,
480
- L: 66,
481
- S: this,
482
- C: (f, a) => f(...a)
483
- });
330
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
484
331
  throw new RuntimeServiceError2({
485
332
  message: `Query execution failed (queryCount=${this._queryCount})`,
486
333
  context: {
487
- spaceId,
488
- filter: request.filter,
489
334
  queryCount: this._queryCount
490
335
  },
491
336
  cause: error
@@ -504,22 +349,6 @@ var QueryServiceImpl = class {
504
349
  });
505
350
  }
506
351
  };
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
352
 
524
353
  // src/internal/queue-service-impl.ts
525
354
  import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
@@ -826,17 +655,19 @@ var ServiceContainer = class {
826
655
  subspaceTag,
827
656
  spaceId,
828
657
  queueId,
829
- objects
658
+ objects: objects.map((obj) => JSON.stringify(obj))
830
659
  });
831
660
  }
832
661
  };
833
662
 
834
663
  // src/space-proxy.ts
835
664
  import { Resource } from "@dxos/context";
836
- import { invariant as invariant4 } from "@dxos/invariant";
837
- import { PublicKey as PublicKey2 } from "@dxos/keys";
665
+ import { invariant as invariant2 } from "@dxos/invariant";
666
+ import { PublicKey } from "@dxos/keys";
838
667
 
839
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";
840
671
  var QueuesAPIImpl = class {
841
672
  _serviceContainer;
842
673
  _spaceId;
@@ -844,8 +675,26 @@ var QueuesAPIImpl = class {
844
675
  this._serviceContainer = _serviceContainer;
845
676
  this._spaceId = _spaceId;
846
677
  }
847
- queryQueue(queue, options) {
848
- return this._serviceContainer.queryQueue(queue);
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
+ };
849
698
  }
850
699
  insertIntoQueue(queue, objects) {
851
700
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
@@ -868,30 +717,14 @@ var SpaceProxy = class extends Resource {
868
717
  return this._id;
869
718
  }
870
719
  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
- });
720
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
880
721
  return this._db;
881
722
  }
882
723
  /**
883
724
  * @deprecated Use db API.
884
725
  */
885
726
  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
- });
727
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
895
728
  return this._db.coreDatabase;
896
729
  }
897
730
  get queues() {
@@ -904,11 +737,11 @@ var SpaceProxy = class extends Resource {
904
737
  }
905
738
  this._db = this._echoClient.constructDatabase({
906
739
  spaceId: this._id,
907
- spaceKey: PublicKey2.from(meta.spaceKey),
740
+ spaceKey: PublicKey.from(meta.spaceKey),
908
741
  reactiveSchemaQuery: false,
909
742
  owningObject: this
910
743
  });
911
- await this._db.coreDatabase.open({
744
+ await this._db.coreDatabase.open(this._ctx, {
912
745
  rootUrl: meta.rootDocumentId
913
746
  });
914
747
  }
@@ -923,24 +756,8 @@ var FunctionsClient = class extends Resource2 {
923
756
  _spaces = /* @__PURE__ */ new Map();
924
757
  constructor(services) {
925
758
  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
- });
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'"] });
944
761
  this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
945
762
  this._echoClient = new EchoClient({});
946
763
  }
@@ -990,9 +807,9 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
990
807
  })({});
991
808
 
992
809
  // 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";
810
+ import { invariant as invariant4 } from "@dxos/invariant";
811
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
812
+ import { log as log4 } from "@dxos/log";
996
813
  import { EdgeResponse } from "@dxos/protocols";
997
814
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
998
815
  var wrapHandlerForCloudflare = (func) => {
@@ -1003,7 +820,7 @@ var wrapHandlerForCloudflare = (func) => {
1003
820
  try {
1004
821
  const spaceId = new URL(request.url).searchParams.get("spaceId");
1005
822
  if (spaceId) {
1006
- if (!SpaceId4.isValid(spaceId)) {
823
+ if (!SpaceId2.isValid(spaceId)) {
1007
824
  return new Response("Invalid spaceId", {
1008
825
  status: 400
1009
826
  });
@@ -1016,15 +833,10 @@ var wrapHandlerForCloudflare = (func) => {
1016
833
  });
1017
834
  return EdgeResponse.success(await invokeFunction(func, context, request));
1018
835
  } catch (error) {
1019
- log3.error("error invoking function", {
836
+ log4.error("error invoking function", {
1020
837
  error,
1021
838
  stack: error.stack
1022
- }, {
1023
- F: __dxlog_file6,
1024
- L: 44,
1025
- S: void 0,
1026
- C: (f, a) => f(...a)
1027
- });
839
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
1028
840
  return EdgeResponse.failure({
1029
841
  message: error?.message ?? "Internal error",
1030
842
  error
@@ -1057,12 +869,7 @@ var decodeRequest = async (request) => {
1057
869
  }
1058
870
  };
1059
871
  } 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
- });
872
+ log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
1066
873
  return {
1067
874
  data: {
1068
875
  bodyText,
@@ -1095,15 +902,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1095
902
  throw new Error(`Space not found: ${contextSpaceId}`);
1096
903
  }
1097
904
  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
- });
905
+ invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
1107
906
  rootUrl = `automerge:${meta.rootDocumentId}`;
1108
907
  }
1109
908
  return {
@@ -1120,36 +919,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1120
919
  };
1121
920
 
1122
921
  // src/logger.ts
1123
- import { LogLevel, log as log4, shouldLog } from "@dxos/log";
922
+ import { LogLevel, log as log5, shouldLog } from "@dxos/log";
1124
923
  var setupFunctionsLogger = () => {
1125
- log4.runtimeConfig.processors.length = 0;
1126
- log4.runtimeConfig.processors.push(functionLogProcessor);
924
+ log5.runtimeConfig.processors.length = 0;
925
+ log5.runtimeConfig.processors.push(functionLogProcessor);
1127
926
  };
1128
927
  var functionLogProcessor = (config, entry) => {
1129
928
  if (!shouldLog(entry, config.filters)) {
1130
929
  return;
1131
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);
1132
937
  switch (entry.level) {
1133
938
  case LogLevel.DEBUG:
1134
- console.debug(entry.message, entry.context);
1135
- break;
1136
939
  case LogLevel.TRACE:
1137
- console.debug(entry.message, entry.context);
940
+ console.debug(entry.message, ...extras);
1138
941
  break;
1139
942
  case LogLevel.VERBOSE:
1140
- console.log(entry.message, entry.context);
943
+ console.log(entry.message, ...extras);
1141
944
  break;
1142
945
  case LogLevel.INFO:
1143
- console.info(entry.message, entry.context);
946
+ console.info(entry.message, ...extras);
1144
947
  break;
1145
948
  case LogLevel.WARN:
1146
- console.warn(entry.message, entry.context);
949
+ console.warn(entry.message, ...extras);
1147
950
  break;
1148
951
  case LogLevel.ERROR:
1149
- console.error(entry.message, entry.context);
952
+ console.error(entry.message, ...extras);
1150
953
  break;
1151
954
  default:
1152
- console.log(entry.message, entry.context);
955
+ console.log(entry.message, ...extras);
1153
956
  break;
1154
957
  }
1155
958
  };
@@ -1159,6 +962,7 @@ export {
1159
962
  FunctionsClient,
1160
963
  ServiceContainer,
1161
964
  createClientFromEnv,
965
+ createFunctionContext,
1162
966
  setupFunctionsLogger,
1163
967
  wrapHandlerForCloudflare
1164
968
  };