@dxos/functions-runtime-cloudflare 0.8.4-main.bc674ce → 0.8.4-main.c85a9c8dae
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.
- package/dist/lib/browser/index.mjs +112 -86
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +112 -86
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/internal/adapter.d.ts +0 -8
- package/dist/types/src/internal/adapter.d.ts.map +1 -1
- package/dist/types/src/internal/queue-service-impl.d.ts +6 -6
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/service-container.d.ts +3 -5
- package/dist/types/src/internal/service-container.d.ts.map +1 -1
- package/dist/types/src/queues-api.d.ts +3 -3
- package/dist/types/src/queues-api.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/src/internal/adapter.ts +15 -11
- package/src/internal/query-service-impl.ts +3 -3
- package/src/internal/queue-service-impl.ts +31 -34
- package/src/internal/service-container.ts +26 -10
- package/src/queues-api.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions-runtime-cloudflare",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.c85a9c8dae",
|
|
4
4
|
"description": "Functions runtime for Cloudflare.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -27,23 +27,23 @@
|
|
|
27
27
|
"src"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"effect": "3.19.
|
|
31
|
-
"@dxos/codec-protobuf": "0.8.4-main.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/echo": "0.8.4-main.
|
|
35
|
-
"@dxos/echo-
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/log": "0.8.4-main.
|
|
41
|
-
"@dxos/protocols": "0.8.4-main.
|
|
42
|
-
"@dxos/util": "0.8.4-main.
|
|
30
|
+
"effect": "3.19.16",
|
|
31
|
+
"@dxos/codec-protobuf": "0.8.4-main.c85a9c8dae",
|
|
32
|
+
"@dxos/debug": "0.8.4-main.c85a9c8dae",
|
|
33
|
+
"@dxos/context": "0.8.4-main.c85a9c8dae",
|
|
34
|
+
"@dxos/echo": "0.8.4-main.c85a9c8dae",
|
|
35
|
+
"@dxos/echo-db": "0.8.4-main.c85a9c8dae",
|
|
36
|
+
"@dxos/echo-protocol": "0.8.4-main.c85a9c8dae",
|
|
37
|
+
"@dxos/errors": "0.8.4-main.c85a9c8dae",
|
|
38
|
+
"@dxos/invariant": "0.8.4-main.c85a9c8dae",
|
|
39
|
+
"@dxos/keys": "0.8.4-main.c85a9c8dae",
|
|
40
|
+
"@dxos/log": "0.8.4-main.c85a9c8dae",
|
|
41
|
+
"@dxos/protocols": "0.8.4-main.c85a9c8dae",
|
|
42
|
+
"@dxos/util": "0.8.4-main.c85a9c8dae"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@cloudflare/workers-types": "^4.
|
|
46
|
-
"@dxos/types": "0.8.4-main.
|
|
45
|
+
"@cloudflare/workers-types": "^4.20260302.0",
|
|
46
|
+
"@dxos/types": "0.8.4-main.c85a9c8dae"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
package/src/internal/adapter.ts
CHANGED
|
@@ -9,11 +9,11 @@ import { SpaceId } from '@dxos/keys';
|
|
|
9
9
|
import { type EdgeFunctionEnv } from '@dxos/protocols';
|
|
10
10
|
|
|
11
11
|
export const queryToDataServiceRequest = (query: QueryAST.Query): EdgeFunctionEnv.QueryRequest => {
|
|
12
|
-
const { filter,
|
|
13
|
-
invariant(
|
|
12
|
+
const { filter, spaceIds } = extractSimpleQuery(query) ?? failUndefined();
|
|
13
|
+
invariant(spaceIds?.length === 1, 'Only one space is supported');
|
|
14
14
|
invariant(filter.type === 'object', 'Only object filters are supported');
|
|
15
15
|
|
|
16
|
-
const spaceId =
|
|
16
|
+
const spaceId = spaceIds[0];
|
|
17
17
|
invariant(SpaceId.isValid(spaceId));
|
|
18
18
|
|
|
19
19
|
return {
|
|
@@ -24,22 +24,26 @@ export const queryToDataServiceRequest = (query: QueryAST.Query): EdgeFunctionEn
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Extracts the filter and
|
|
28
|
-
* Supports Select(...) and
|
|
27
|
+
* Extracts the filter and space IDs from a query.
|
|
28
|
+
* Supports Select(...), Options(Select(...)), and From(Select(...)) queries.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
const extractSimpleQuery = (
|
|
31
31
|
query: QueryAST.Query,
|
|
32
|
-
): { filter: QueryAST.Filter;
|
|
32
|
+
): { filter: QueryAST.Filter; spaceIds?: readonly string[] } | null => {
|
|
33
33
|
switch (query.type) {
|
|
34
34
|
case 'options': {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
return extractSimpleQuery(query.query);
|
|
36
|
+
}
|
|
37
|
+
case 'from': {
|
|
38
|
+
const inner = extractSimpleQuery(query.query);
|
|
39
|
+
if (!inner) {
|
|
37
40
|
return null;
|
|
38
41
|
}
|
|
39
|
-
|
|
42
|
+
const spaceIds = query.from._tag === 'scope' ? query.from.scope.spaceIds : undefined;
|
|
43
|
+
return { filter: inner.filter, spaceIds: spaceIds ?? inner.spaceIds };
|
|
40
44
|
}
|
|
41
45
|
case 'select': {
|
|
42
|
-
return { filter: query.filter
|
|
46
|
+
return { filter: query.filter };
|
|
43
47
|
}
|
|
44
48
|
default: {
|
|
45
49
|
return null;
|
|
@@ -94,9 +94,9 @@ export const getTargetSpacesForQuery = (query: QueryAST.Query): SpaceId[] => {
|
|
|
94
94
|
const spaces = new Set<SpaceId>();
|
|
95
95
|
|
|
96
96
|
const visitor = (node: QueryAST.Query) => {
|
|
97
|
-
if (node.type === '
|
|
98
|
-
if (node.
|
|
99
|
-
for (const spaceId of node.
|
|
97
|
+
if (node.type === 'from' && node.from._tag === 'scope') {
|
|
98
|
+
if (node.from.scope.spaceIds) {
|
|
99
|
+
for (const spaceId of node.from.scope.spaceIds) {
|
|
100
100
|
spaces.add(SpaceId.make(spaceId));
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -2,55 +2,43 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { type QueueService as QueueServiceProto } from '@dxos/protocols';
|
|
8
|
-
import type {
|
|
9
|
-
DeleteFromQueueRequest,
|
|
10
|
-
EdgeFunctionEnv,
|
|
11
|
-
InsertIntoQueueRequest,
|
|
12
|
-
QueryQueueRequest,
|
|
13
|
-
QueryResult,
|
|
14
|
-
} from '@dxos/protocols';
|
|
5
|
+
import { RuntimeServiceError } from '@dxos/errors';
|
|
6
|
+
import { type EdgeFunctionEnv, type FeedProtocol } from '@dxos/protocols';
|
|
15
7
|
|
|
16
|
-
export class QueueServiceImpl implements
|
|
8
|
+
export class QueueServiceImpl implements FeedProtocol.QueueService {
|
|
17
9
|
constructor(
|
|
18
10
|
protected _ctx: EdgeFunctionEnv.ExecutionContext,
|
|
19
11
|
private readonly _queueService: EdgeFunctionEnv.QueueService,
|
|
20
12
|
) {}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { queueIds, ...filter } = query!;
|
|
24
|
-
const spaceId = query!.spaceId;
|
|
25
|
-
const queueId = queueIds?.[0];
|
|
26
|
-
invariant(request.query.queuesNamespace);
|
|
13
|
+
|
|
14
|
+
async queryQueue(request: FeedProtocol.QueryQueueRequest): Promise<FeedProtocol.QueryResult> {
|
|
27
15
|
try {
|
|
28
|
-
using result = await this._queueService.
|
|
29
|
-
|
|
30
|
-
`dxn:queue:${request.query.queuesNamespace}:${spaceId}:${queueId}`,
|
|
31
|
-
filter,
|
|
32
|
-
);
|
|
16
|
+
using result = await this._queueService.queryQueue(this._ctx, request);
|
|
17
|
+
// Copy to avoid hanging RPC stub (Workers RPC lifecycle).
|
|
33
18
|
return {
|
|
34
|
-
// Copy returned object to avoid hanging RPC stub
|
|
35
|
-
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
36
19
|
objects: structuredClone(result.objects),
|
|
37
20
|
nextCursor: result.nextCursor,
|
|
38
21
|
prevCursor: result.prevCursor,
|
|
39
22
|
};
|
|
40
23
|
} catch (error) {
|
|
24
|
+
const { query } = request;
|
|
41
25
|
throw RuntimeServiceError.wrap({
|
|
42
26
|
message: 'Queue query failed.',
|
|
43
|
-
context: {
|
|
27
|
+
context: {
|
|
28
|
+
subspaceTag: query?.queuesNamespace,
|
|
29
|
+
spaceId: query?.spaceId,
|
|
30
|
+
queueId: query?.queueIds?.[0],
|
|
31
|
+
},
|
|
44
32
|
ifTypeDiffers: true,
|
|
45
33
|
})(error);
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
async insertIntoQueue(request: InsertIntoQueueRequest): Promise<void> {
|
|
50
|
-
const { subspaceTag, spaceId, queueId, objects } = request;
|
|
37
|
+
async insertIntoQueue(request: FeedProtocol.InsertIntoQueueRequest): Promise<void> {
|
|
51
38
|
try {
|
|
52
|
-
await this._queueService.
|
|
39
|
+
using _ = await this._queueService.insertIntoQueue(this._ctx, request);
|
|
53
40
|
} catch (error) {
|
|
41
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
54
42
|
throw RuntimeServiceError.wrap({
|
|
55
43
|
message: 'Queue append failed.',
|
|
56
44
|
context: { subspaceTag, spaceId, queueId },
|
|
@@ -59,11 +47,20 @@ export class QueueServiceImpl implements QueueServiceProto {
|
|
|
59
47
|
}
|
|
60
48
|
}
|
|
61
49
|
|
|
62
|
-
deleteFromQueue(request: DeleteFromQueueRequest): Promise<void> {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
async deleteFromQueue(request: FeedProtocol.DeleteFromQueueRequest): Promise<void> {
|
|
51
|
+
try {
|
|
52
|
+
using _ = await this._queueService.deleteFromQueue(this._ctx, request);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
55
|
+
throw RuntimeServiceError.wrap({
|
|
56
|
+
message: 'Queue delete failed.',
|
|
57
|
+
context: { subspaceTag, spaceId, queueId },
|
|
58
|
+
ifTypeDiffers: true,
|
|
59
|
+
})(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async syncQueue(_: FeedProtocol.SyncQueueRequest): Promise<void> {
|
|
64
|
+
// No-op in Cloudflare runtime.
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type AnyEntity } from '@dxos/echo/internal';
|
|
6
6
|
import { type DXN, type SpaceId } from '@dxos/keys';
|
|
7
|
-
import type
|
|
8
|
-
import { type EdgeFunctionEnv } from '@dxos/protocols';
|
|
9
|
-
import { type QueueService as QueueServiceProto } from '@dxos/protocols';
|
|
7
|
+
import { type EdgeFunctionEnv, type FeedProtocol } from '@dxos/protocols';
|
|
10
8
|
import { type QueryService as QueryServiceProto } from '@dxos/protocols/proto/dxos/echo/query';
|
|
11
9
|
import type { DataService as DataServiceProto } from '@dxos/protocols/proto/dxos/echo/service';
|
|
12
10
|
|
|
@@ -40,7 +38,7 @@ export class ServiceContainer {
|
|
|
40
38
|
async createServices(): Promise<{
|
|
41
39
|
dataService: DataServiceProto;
|
|
42
40
|
queryService: QueryServiceProto;
|
|
43
|
-
queueService:
|
|
41
|
+
queueService: FeedProtocol.QueueService;
|
|
44
42
|
functionsAiService: EdgeFunctionEnv.FunctionsAiService;
|
|
45
43
|
}> {
|
|
46
44
|
const dataService = new DataServiceImpl(this._executionContext, this._dataService);
|
|
@@ -55,11 +53,19 @@ export class ServiceContainer {
|
|
|
55
53
|
};
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
async queryQueue(queue: DXN): Promise<QueryResult> {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
async queryQueue(queue: DXN): Promise<FeedProtocol.QueryResult> {
|
|
57
|
+
const parts = queue.asQueueDXN();
|
|
58
|
+
if (!parts) {
|
|
59
|
+
throw new Error('Invalid queue DXN');
|
|
60
|
+
}
|
|
61
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
62
|
+
const result = await this._queueService.queryQueue(this._executionContext, {
|
|
63
|
+
query: {
|
|
64
|
+
spaceId,
|
|
65
|
+
queuesNamespace: subspaceTag,
|
|
66
|
+
queueIds: [queueId],
|
|
67
|
+
},
|
|
68
|
+
});
|
|
63
69
|
return {
|
|
64
70
|
objects: structuredClone(result.objects),
|
|
65
71
|
nextCursor: result.nextCursor ?? null,
|
|
@@ -68,6 +74,16 @@ export class ServiceContainer {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
async insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void> {
|
|
71
|
-
|
|
77
|
+
const parts = queue.asQueueDXN();
|
|
78
|
+
if (!parts) {
|
|
79
|
+
throw new Error('Invalid queue DXN');
|
|
80
|
+
}
|
|
81
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
82
|
+
await this._queueService.insertIntoQueue(this._executionContext, {
|
|
83
|
+
subspaceTag,
|
|
84
|
+
spaceId,
|
|
85
|
+
queueId,
|
|
86
|
+
objects: objects as FeedProtocol.InsertIntoQueueRequest['objects'],
|
|
87
|
+
});
|
|
72
88
|
}
|
|
73
89
|
}
|
package/src/queues-api.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type AnyEntity } from '@dxos/echo/internal';
|
|
6
6
|
import type { DXN, SpaceId } from '@dxos/keys';
|
|
7
|
-
import type
|
|
7
|
+
import { type FeedProtocol } from '@dxos/protocols';
|
|
8
8
|
|
|
9
9
|
import type { ServiceContainer } from './internal';
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ import type { ServiceContainer } from './internal';
|
|
|
14
14
|
* @deprecated
|
|
15
15
|
*/
|
|
16
16
|
export interface QueuesAPI {
|
|
17
|
-
queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;
|
|
17
|
+
queryQueue(queue: DXN, options?: {}): Promise<FeedProtocol.QueryResult>;
|
|
18
18
|
insertIntoQueue(queue: DXN, objects: AnyEntity[]): Promise<void>;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -27,7 +27,7 @@ export class QueuesAPIImpl implements QueuesAPI {
|
|
|
27
27
|
private readonly _spaceId: SpaceId,
|
|
28
28
|
) {}
|
|
29
29
|
|
|
30
|
-
queryQueue(queue: DXN, options?: {}): Promise<QueryResult> {
|
|
30
|
+
queryQueue(queue: DXN, options?: {}): Promise<FeedProtocol.QueryResult> {
|
|
31
31
|
return this._serviceContainer.queryQueue(queue);
|
|
32
32
|
}
|
|
33
33
|
|