@dxos/functions-runtime-cloudflare 0.8.4-main.fcfe5033a5 → 0.9.0

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 (36) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/index.mjs +58 -157
  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 +58 -157
  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 +1 -6
  10. package/dist/types/src/functions-client.d.ts.map +1 -1
  11. package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
  12. package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
  13. package/dist/types/src/internal/queue-service-impl.d.ts +1 -0
  14. package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
  15. package/dist/types/src/internal/service-container.d.ts +5 -5
  16. package/dist/types/src/internal/service-container.d.ts.map +1 -1
  17. package/dist/types/src/internal/utils.d.ts.map +1 -1
  18. package/dist/types/src/queues-api.d.ts +11 -6
  19. package/dist/types/src/queues-api.d.ts.map +1 -1
  20. package/dist/types/src/space-proxy.d.ts +1 -5
  21. package/dist/types/src/space-proxy.d.ts.map +1 -1
  22. package/dist/types/src/types.d.ts +1 -1
  23. package/dist/types/src/types.d.ts.map +1 -1
  24. package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
  25. package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
  26. package/dist/types/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +16 -16
  28. package/src/functions-client.ts +1 -7
  29. package/src/internal/data-service-impl.ts +6 -1
  30. package/src/internal/queue-service-impl.ts +4 -0
  31. package/src/internal/service-container.ts +17 -16
  32. package/src/logger.ts +10 -8
  33. package/src/queues-api.ts +12 -6
  34. package/src/space-proxy.ts +4 -11
  35. package/src/types.ts +1 -1
  36. package/src/wrap-handler-for-cloudflare.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions-runtime-cloudflare",
3
- "version": "0.8.4-main.fcfe5033a5",
3
+ "version": "0.9.0",
4
4
  "description": "Functions runtime for Cloudflare.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "info@dxos.org",
13
13
  "sideEffects": false,
14
14
  "type": "module",
@@ -27,23 +27,23 @@
27
27
  "src"
28
28
  ],
29
29
  "dependencies": {
30
- "effect": "3.20.0",
31
- "@dxos/context": "0.8.4-main.fcfe5033a5",
32
- "@dxos/codec-protobuf": "0.8.4-main.fcfe5033a5",
33
- "@dxos/debug": "0.8.4-main.fcfe5033a5",
34
- "@dxos/echo": "0.8.4-main.fcfe5033a5",
35
- "@dxos/echo-protocol": "0.8.4-main.fcfe5033a5",
36
- "@dxos/invariant": "0.8.4-main.fcfe5033a5",
37
- "@dxos/errors": "0.8.4-main.fcfe5033a5",
38
- "@dxos/keys": "0.8.4-main.fcfe5033a5",
39
- "@dxos/echo-db": "0.8.4-main.fcfe5033a5",
40
- "@dxos/protocols": "0.8.4-main.fcfe5033a5",
41
- "@dxos/util": "0.8.4-main.fcfe5033a5",
42
- "@dxos/log": "0.8.4-main.fcfe5033a5"
30
+ "effect": "3.21.3",
31
+ "@dxos/codec-protobuf": "0.9.0",
32
+ "@dxos/context": "0.9.0",
33
+ "@dxos/debug": "0.9.0",
34
+ "@dxos/errors": "0.9.0",
35
+ "@dxos/echo-protocol": "0.9.0",
36
+ "@dxos/echo-client": "0.9.0",
37
+ "@dxos/invariant": "0.9.0",
38
+ "@dxos/keys": "0.9.0",
39
+ "@dxos/log": "0.9.0",
40
+ "@dxos/protocols": "0.9.0",
41
+ "@dxos/echo": "0.9.0",
42
+ "@dxos/util": "0.9.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@cloudflare/workers-types": "^4.20260302.0",
46
- "@dxos/types": "0.8.4-main.fcfe5033a5"
46
+ "@dxos/types": "0.9.0"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Resource } from '@dxos/context';
6
- import { EchoClient } from '@dxos/echo-db';
6
+ import { EchoClient } from '@dxos/echo-client';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import { type SpaceId } from '@dxos/keys';
9
9
  import { type EdgeFunctionEnv } from '@dxos/protocols';
@@ -80,9 +80,3 @@ export const createClientFromEnv = async (env: any): Promise<FunctionsClient> =>
80
80
  await client.open();
81
81
  return client;
82
82
  };
83
-
84
- /**
85
- - Provides data access capabilities for user functions.
86
- - No real-time replication or reactive queries -- function receives a snapshot.
87
- - Function event contains the metadata but doesn't need to include the data.
88
- */
@@ -97,6 +97,11 @@ export class DataServiceImpl implements DataServiceProto {
97
97
  // TODO(dmaretskyi): Batch.
98
98
  try {
99
99
  for (const update of updates ?? []) {
100
+ // Mutation-less updates (e.g. `requesting: true` transition signals from the worker) carry no
101
+ // bytes to apply; this runtime only forwards real document writes.
102
+ if (!update.mutation) {
103
+ continue;
104
+ }
100
105
  await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
101
106
  }
102
107
  } catch (error) {
@@ -131,7 +136,7 @@ export class DataServiceImpl implements DataServiceProto {
131
136
  }
132
137
 
133
138
  async updateIndexes(): Promise<void> {
134
- log.error('updateIndexes is not available in EDGE env.');
139
+ log.verbose('updateIndexes called, but it is a no-op in EDGE env.');
135
140
  // No-op.
136
141
  }
137
142
 
@@ -63,4 +63,8 @@ export class QueueServiceImpl implements FeedProtocol.QueueService {
63
63
  async syncQueue(_: FeedProtocol.SyncQueueRequest): Promise<void> {
64
64
  // No-op in Cloudflare runtime.
65
65
  }
66
+
67
+ async getSyncState(_: FeedProtocol.GetSyncStateRequest): Promise<FeedProtocol.GetSyncStateResponse> {
68
+ return { namespaces: [] };
69
+ }
66
70
  }
@@ -2,11 +2,11 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type AnyEntity } from '@dxos/echo/internal';
6
- import { type DXN, type SpaceId } from '@dxos/keys';
5
+ import { type AnyEntity } from '@dxos/echo/Type';
6
+ import { EID, type SpaceId } from '@dxos/keys';
7
7
  import { type EdgeFunctionEnv, type FeedProtocol } from '@dxos/protocols';
8
8
  import { type QueryService as QueryServiceProto } from '@dxos/protocols/proto/dxos/echo/query';
9
- import type { DataService as DataServiceProto } from '@dxos/protocols/proto/dxos/echo/service';
9
+ import { type DataService as DataServiceProto } from '@dxos/protocols/proto/dxos/echo/service';
10
10
 
11
11
  import { DataServiceImpl } from './data-service-impl';
12
12
  import { QueryServiceImpl } from './query-service-impl';
@@ -53,19 +53,19 @@ export class ServiceContainer {
53
53
  };
54
54
  }
55
55
 
56
- async queryQueue(queue: DXN): Promise<FeedProtocol.QueryResult> {
57
- const parts = queue.asQueueDXN();
58
- if (!parts) {
59
- throw new Error('Invalid queue DXN');
56
+ async queryQueue(queue: EID.EID): Promise<FeedProtocol.QueryResult> {
57
+ const spaceId = EID.getSpaceId(queue);
58
+ const queueId = EID.getEntityId(queue);
59
+ if (!spaceId || !queueId) {
60
+ throw new Error('Invalid queue EID');
60
61
  }
61
- const { subspaceTag, spaceId, queueId } = parts;
62
62
  const result = await this._queueService.queryQueue(this._executionContext, {
63
63
  query: {
64
64
  spaceId,
65
- queuesNamespace: subspaceTag,
66
65
  queueIds: [queueId],
67
66
  },
68
67
  });
68
+
69
69
  return {
70
70
  objects: structuredClone(result.objects),
71
71
  nextCursor: result.nextCursor ?? null,
@@ -73,17 +73,18 @@ export class ServiceContainer {
73
73
  };
74
74
  }
75
75
 
76
- async insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void> {
77
- const parts = queue.asQueueDXN();
78
- if (!parts) {
79
- throw new Error('Invalid queue DXN');
76
+ async insertIntoQueue(queue: EID.EID, objects: AnyEntity[]): Promise<void> {
77
+ const spaceId = EID.getSpaceId(queue);
78
+ const queueId = EID.getEntityId(queue);
79
+ if (!spaceId || !queueId) {
80
+ throw new Error('Invalid queue EID');
80
81
  }
81
- const { subspaceTag, spaceId, queueId } = parts;
82
+ // TODO(dmaretskyi): EID does not encode the subspaceTag defaulting to 'data'.
82
83
  await this._queueService.insertIntoQueue(this._executionContext, {
83
- subspaceTag,
84
+ subspaceTag: 'data',
84
85
  spaceId,
85
86
  queueId,
86
- objects: objects as FeedProtocol.InsertIntoQueueRequest['objects'],
87
+ objects: objects.map((obj) => JSON.stringify(obj)),
87
88
  });
88
89
  }
89
90
  }
package/src/logger.ts CHANGED
@@ -16,27 +16,29 @@ const functionLogProcessor: LogProcessor = (config, entry) => {
16
16
  return;
17
17
  }
18
18
 
19
+ const context = entry.computedContext;
20
+ const error = entry.computedError;
21
+ const extras = [Object.keys(context).length > 0 ? context : undefined, error].filter((value) => value !== undefined);
22
+
19
23
  switch (entry.level) {
20
24
  case LogLevel.DEBUG:
21
- console.debug(entry.message, entry.context);
22
- break;
23
25
  case LogLevel.TRACE:
24
- console.debug(entry.message, entry.context);
26
+ console.debug(entry.message, ...extras);
25
27
  break;
26
28
  case LogLevel.VERBOSE:
27
- console.log(entry.message, entry.context);
29
+ console.log(entry.message, ...extras);
28
30
  break;
29
31
  case LogLevel.INFO:
30
- console.info(entry.message, entry.context);
32
+ console.info(entry.message, ...extras);
31
33
  break;
32
34
  case LogLevel.WARN:
33
- console.warn(entry.message, entry.context);
35
+ console.warn(entry.message, ...extras);
34
36
  break;
35
37
  case LogLevel.ERROR:
36
- console.error(entry.message, entry.context);
38
+ console.error(entry.message, ...extras);
37
39
  break;
38
40
  default:
39
- console.log(entry.message, entry.context);
41
+ console.log(entry.message, ...extras);
40
42
  break;
41
43
  }
42
44
  };
package/src/queues-api.ts CHANGED
@@ -2,20 +2,26 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type AnyEntity } from '@dxos/echo/internal';
6
- import type { DXN, SpaceId } from '@dxos/keys';
5
+ import { type AnyEntity } from '@dxos/echo/Type';
6
+ import { type EID, type SpaceId } from '@dxos/keys';
7
7
  import { type FeedProtocol } from '@dxos/protocols';
8
8
 
9
9
  import type { ServiceContainer } from './internal';
10
10
 
11
+ export interface QueuesQueryResult {
12
+ objects: AnyEntity[];
13
+ nextCursor: string | null;
14
+ prevCursor: string | null;
15
+ }
16
+
11
17
  // TODO(dmaretskyi): Temporary API to get the queues working.
12
18
  // TODO(dmaretskyi): To be replaced with integrating queues into echo.
13
19
  /**
14
20
  * @deprecated
15
21
  */
16
22
  export interface QueuesAPI {
17
- queryQueue(queue: DXN, options?: {}): Promise<FeedProtocol.QueryResult>;
18
- insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void>;
23
+ queryQueue(queue: EID.EID, options?: {}): Promise<FeedProtocol.QueryResult>;
24
+ insertIntoQueue(queue: EID.EID, objects: AnyEntity[]): Promise<void>;
19
25
  }
20
26
 
21
27
  /**
@@ -27,11 +33,11 @@ export class QueuesAPIImpl implements QueuesAPI {
27
33
  private readonly _spaceId: SpaceId,
28
34
  ) {}
29
35
 
30
- queryQueue(queue: DXN, options?: {}): Promise<FeedProtocol.QueryResult> {
36
+ queryQueue(queue: EID.EID, options?: {}): Promise<FeedProtocol.QueryResult> {
31
37
  return this._serviceContainer.queryQueue(queue);
32
38
  }
33
39
 
34
- insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void> {
40
+ insertIntoQueue(queue: EID.EID, objects: AnyEntity[]): Promise<void> {
35
41
  // TODO(dmaretskyi): Ugly.
36
42
  return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
37
43
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { Resource } from '@dxos/context';
6
6
  import { type Database } from '@dxos/echo';
7
- import { type CoreDatabase, type EchoClient, type EchoDatabaseImpl } from '@dxos/echo-db';
7
+ import { type DatabaseImpl, type EchoClient } from '@dxos/echo-client';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { PublicKey, type SpaceId } from '@dxos/keys';
10
10
 
@@ -15,7 +15,7 @@ import { type QueuesAPI, QueuesAPIImpl } from './queues-api';
15
15
  * @deprecated
16
16
  */
17
17
  export class SpaceProxy extends Resource {
18
- private _db?: EchoDatabaseImpl = undefined;
18
+ private _db?: DatabaseImpl = undefined;
19
19
  private _queuesApi: QueuesAPIImpl;
20
20
 
21
21
  constructor(
@@ -36,14 +36,6 @@ export class SpaceProxy extends Resource {
36
36
  return this._db;
37
37
  }
38
38
 
39
- /**
40
- * @deprecated Use db API.
41
- */
42
- get crud(): CoreDatabase {
43
- invariant(this._db);
44
- return this._db.coreDatabase;
45
- }
46
-
47
39
  get queues(): QueuesAPI {
48
40
  return this._queuesApi;
49
41
  }
@@ -61,6 +53,7 @@ export class SpaceProxy extends Resource {
61
53
  owningObject: this,
62
54
  });
63
55
 
64
- await this._db.coreDatabase.open(this._ctx, { rootUrl: meta.rootDocumentId });
56
+ await this._db.setSpaceRoot(meta.rootDocumentId);
57
+ await this._db.open(this._ctx);
65
58
  }
66
59
  }
package/src/types.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { JsonSchemaType } from '@dxos/echo/internal';
5
+ import type { JsonSchema as JsonSchemaType } from '@dxos/echo/JsonSchema';
6
6
 
7
7
  /**
8
8
  * Is used for to route the request to the metadata handler instead of the main handler.
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { JsonSchemaType } from '@dxos/echo/internal';
5
+ import type { JsonSchema as JsonSchemaType } from '@dxos/echo/JsonSchema';
6
6
  import { invariant } from '@dxos/invariant';
7
7
  import { SpaceId } from '@dxos/keys';
8
8
  import { log } from '@dxos/log';
@@ -97,7 +97,7 @@ const handleFunctionMetaCall = (functionDefinition: FunctionProtocol.Func, reque
97
97
  });
98
98
  };
99
99
 
100
- const createFunctionContext = async ({
100
+ export const createFunctionContext = async ({
101
101
  serviceContainer,
102
102
  contextSpaceId,
103
103
  }: {