@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
@@ -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/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
  };
@@ -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,86 +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, 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
224
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
331
225
  function _ts_add_disposable_resource2(env, value, async) {
332
226
  if (value !== null && value !== void 0) {
333
227
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -393,7 +287,6 @@ function _ts_dispose_resources2(env) {
393
287
  return next();
394
288
  })(env);
395
289
  }
396
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
397
290
  var QueryServiceImpl = class {
398
291
  _executionContext;
399
292
  _dataService;
@@ -405,24 +298,7 @@ var QueryServiceImpl = class {
405
298
  execQuery(request) {
406
299
  log2.info("execQuery", {
407
300
  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];
301
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 81, S: this });
426
302
  return Stream2.fromPromise((async () => {
427
303
  try {
428
304
  const env = {
@@ -433,37 +309,13 @@ var QueryServiceImpl = class {
433
309
  try {
434
310
  this._queryCount++;
435
311
  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);
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);
444
315
  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
- };
316
+ resultCount: queryResponse.results?.length
317
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 97, S: this });
318
+ return structuredClone(queryResponse);
467
319
  } catch (e) {
468
320
  env.error = e;
469
321
  env.hasError = true;
@@ -473,17 +325,10 @@ var QueryServiceImpl = class {
473
325
  } catch (error) {
474
326
  log2.error("query failed", {
475
327
  err: error
476
- }, {
477
- F: __dxlog_file3,
478
- L: 66,
479
- S: this,
480
- C: (f, a) => f(...a)
481
- });
328
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 108, S: this });
482
329
  throw new RuntimeServiceError2({
483
330
  message: `Query execution failed (queryCount=${this._queryCount})`,
484
331
  context: {
485
- spaceId,
486
- filter: request.filter,
487
332
  queryCount: this._queryCount
488
333
  },
489
334
  cause: error
@@ -502,22 +347,6 @@ var QueryServiceImpl = class {
502
347
  });
503
348
  }
504
349
  };
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
350
 
522
351
  // src/internal/queue-service-impl.ts
523
352
  import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
@@ -824,17 +653,19 @@ var ServiceContainer = class {
824
653
  subspaceTag,
825
654
  spaceId,
826
655
  queueId,
827
- objects
656
+ objects: objects.map((obj) => JSON.stringify(obj))
828
657
  });
829
658
  }
830
659
  };
831
660
 
832
661
  // src/space-proxy.ts
833
662
  import { Resource } from "@dxos/context";
834
- import { invariant as invariant4 } from "@dxos/invariant";
835
- import { PublicKey as PublicKey2 } from "@dxos/keys";
663
+ import { invariant as invariant2 } from "@dxos/invariant";
664
+ import { PublicKey } from "@dxos/keys";
836
665
 
837
666
  // src/queues-api.ts
667
+ import { log as log3 } from "@dxos/log";
668
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/queues-api.ts";
838
669
  var QueuesAPIImpl = class {
839
670
  _serviceContainer;
840
671
  _spaceId;
@@ -842,8 +673,26 @@ var QueuesAPIImpl = class {
842
673
  this._serviceContainer = _serviceContainer;
843
674
  this._spaceId = _spaceId;
844
675
  }
845
- queryQueue(queue, options) {
846
- return this._serviceContainer.queryQueue(queue);
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
+ };
847
696
  }
848
697
  insertIntoQueue(queue, objects) {
849
698
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
@@ -866,30 +715,14 @@ var SpaceProxy = class extends Resource {
866
715
  return this._id;
867
716
  }
868
717
  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
- });
718
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 24, S: this, A: ["this._db", ""] });
878
719
  return this._db;
879
720
  }
880
721
  /**
881
722
  * @deprecated Use db API.
882
723
  */
883
724
  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
- });
725
+ invariant2(this._db, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 30, S: this, A: ["this._db", ""] });
893
726
  return this._db.coreDatabase;
894
727
  }
895
728
  get queues() {
@@ -902,11 +735,11 @@ var SpaceProxy = class extends Resource {
902
735
  }
903
736
  this._db = this._echoClient.constructDatabase({
904
737
  spaceId: this._id,
905
- spaceKey: PublicKey2.from(meta.spaceKey),
738
+ spaceKey: PublicKey.from(meta.spaceKey),
906
739
  reactiveSchemaQuery: false,
907
740
  owningObject: this
908
741
  });
909
- await this._db.coreDatabase.open({
742
+ await this._db.coreDatabase.open(this._ctx, {
910
743
  rootUrl: meta.rootDocumentId
911
744
  });
912
745
  }
@@ -921,24 +754,8 @@ var FunctionsClient = class extends Resource2 {
921
754
  _spaces = /* @__PURE__ */ new Map();
922
755
  constructor(services) {
923
756
  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
- });
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'"] });
942
759
  this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
943
760
  this._echoClient = new EchoClient({});
944
761
  }
@@ -988,9 +805,9 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
988
805
  })({});
989
806
 
990
807
  // 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";
808
+ import { invariant as invariant4 } from "@dxos/invariant";
809
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
810
+ import { log as log4 } from "@dxos/log";
994
811
  import { EdgeResponse } from "@dxos/protocols";
995
812
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
996
813
  var wrapHandlerForCloudflare = (func) => {
@@ -1001,7 +818,7 @@ var wrapHandlerForCloudflare = (func) => {
1001
818
  try {
1002
819
  const spaceId = new URL(request.url).searchParams.get("spaceId");
1003
820
  if (spaceId) {
1004
- if (!SpaceId4.isValid(spaceId)) {
821
+ if (!SpaceId2.isValid(spaceId)) {
1005
822
  return new Response("Invalid spaceId", {
1006
823
  status: 400
1007
824
  });
@@ -1014,15 +831,10 @@ var wrapHandlerForCloudflare = (func) => {
1014
831
  });
1015
832
  return EdgeResponse.success(await invokeFunction(func, context, request));
1016
833
  } catch (error) {
1017
- log3.error("error invoking function", {
834
+ log4.error("error invoking function", {
1018
835
  error,
1019
836
  stack: error.stack
1020
- }, {
1021
- F: __dxlog_file6,
1022
- L: 44,
1023
- S: void 0,
1024
- C: (f, a) => f(...a)
1025
- });
837
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: void 0 });
1026
838
  return EdgeResponse.failure({
1027
839
  message: error?.message ?? "Internal error",
1028
840
  error
@@ -1055,12 +867,7 @@ var decodeRequest = async (request) => {
1055
867
  }
1056
868
  };
1057
869
  } 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
- });
870
+ log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 76, S: void 0 });
1064
871
  return {
1065
872
  data: {
1066
873
  bodyText,
@@ -1093,15 +900,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1093
900
  throw new Error(`Space not found: ${contextSpaceId}`);
1094
901
  }
1095
902
  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
- });
903
+ invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 109, S: void 0, A: ["!meta.rootDocumentId.startsWith('automerge:')", ""] });
1105
904
  rootUrl = `automerge:${meta.rootDocumentId}`;
1106
905
  }
1107
906
  return {
@@ -1118,36 +917,40 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
1118
917
  };
1119
918
 
1120
919
  // src/logger.ts
1121
- import { LogLevel, log as log4, shouldLog } from "@dxos/log";
920
+ import { LogLevel, log as log5, shouldLog } from "@dxos/log";
1122
921
  var setupFunctionsLogger = () => {
1123
- log4.runtimeConfig.processors.length = 0;
1124
- log4.runtimeConfig.processors.push(functionLogProcessor);
922
+ log5.runtimeConfig.processors.length = 0;
923
+ log5.runtimeConfig.processors.push(functionLogProcessor);
1125
924
  };
1126
925
  var functionLogProcessor = (config, entry) => {
1127
926
  if (!shouldLog(entry, config.filters)) {
1128
927
  return;
1129
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);
1130
935
  switch (entry.level) {
1131
936
  case LogLevel.DEBUG:
1132
- console.debug(entry.message, entry.context);
1133
- break;
1134
937
  case LogLevel.TRACE:
1135
- console.debug(entry.message, entry.context);
938
+ console.debug(entry.message, ...extras);
1136
939
  break;
1137
940
  case LogLevel.VERBOSE:
1138
- console.log(entry.message, entry.context);
941
+ console.log(entry.message, ...extras);
1139
942
  break;
1140
943
  case LogLevel.INFO:
1141
- console.info(entry.message, entry.context);
944
+ console.info(entry.message, ...extras);
1142
945
  break;
1143
946
  case LogLevel.WARN:
1144
- console.warn(entry.message, entry.context);
947
+ console.warn(entry.message, ...extras);
1145
948
  break;
1146
949
  case LogLevel.ERROR:
1147
- console.error(entry.message, entry.context);
950
+ console.error(entry.message, ...extras);
1148
951
  break;
1149
952
  default:
1150
- console.log(entry.message, entry.context);
953
+ console.log(entry.message, ...extras);
1151
954
  break;
1152
955
  }
1153
956
  };
@@ -1157,6 +960,7 @@ export {
1157
960
  FunctionsClient,
1158
961
  ServiceContainer,
1159
962
  createClientFromEnv,
963
+ createFunctionContext,
1160
964
  setupFunctionsLogger,
1161
965
  wrapHandlerForCloudflare
1162
966
  };