@dxos/functions-runtime-cloudflare 0.8.4-main.70d3990 → 0.8.4-main.765dc60934
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +741 -251
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +741 -251
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/functions-client.d.ts +1 -5
- package/dist/types/src/functions-client.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/data-service-impl.d.ts +8 -7
- package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/query-service-impl.d.ts +4 -9
- package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/queue-service-impl.d.ts +8 -9
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/service-container.d.ts +9 -9
- package/dist/types/src/internal/service-container.d.ts.map +1 -1
- package/dist/types/src/internal/utils.d.ts +2 -0
- package/dist/types/src/internal/utils.d.ts.map +1 -0
- package/dist/types/src/logger.d.ts +2 -0
- package/dist/types/src/logger.d.ts.map +1 -0
- package/dist/types/src/queues-api.d.ts +10 -6
- package/dist/types/src/queues-api.d.ts.map +1 -1
- package/dist/types/src/space-proxy.d.ts +3 -2
- package/dist/types/src/space-proxy.d.ts.map +1 -1
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -16
- package/src/functions-client.ts +9 -8
- package/src/index.ts +2 -0
- package/src/internal/data-service-impl.ts +73 -18
- package/src/internal/query-service-impl.ts +23 -61
- package/src/internal/queue-service-impl.ts +54 -11
- package/src/internal/service-container.ts +50 -12
- package/src/internal/utils.ts +5 -0
- package/src/logger.ts +44 -0
- package/src/queues-api.ts +26 -7
- package/src/space-proxy.ts +5 -4
- package/src/wrap-handler-for-cloudflare.ts +4 -4
- package/dist/types/src/internal/adapter.d.ts +0 -12
- package/dist/types/src/internal/adapter.d.ts.map +0 -1
- package/src/internal/adapter.ts +0 -48
package/src/space-proxy.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Resource } from '@dxos/context';
|
|
6
|
-
import { type
|
|
6
|
+
import { type Database } from '@dxos/echo';
|
|
7
|
+
import { type CoreDatabase, type EchoClient, type EchoDatabaseImpl } from '@dxos/echo-db';
|
|
7
8
|
import { invariant } from '@dxos/invariant';
|
|
8
9
|
import { PublicKey, type SpaceId } from '@dxos/keys';
|
|
9
10
|
|
|
@@ -14,7 +15,7 @@ import { type QueuesAPI, QueuesAPIImpl } from './queues-api';
|
|
|
14
15
|
* @deprecated
|
|
15
16
|
*/
|
|
16
17
|
export class SpaceProxy extends Resource {
|
|
17
|
-
private _db?:
|
|
18
|
+
private _db?: EchoDatabaseImpl = undefined;
|
|
18
19
|
private _queuesApi: QueuesAPIImpl;
|
|
19
20
|
|
|
20
21
|
constructor(
|
|
@@ -30,7 +31,7 @@ export class SpaceProxy extends Resource {
|
|
|
30
31
|
return this._id;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
get db():
|
|
34
|
+
get db(): Database.Database {
|
|
34
35
|
invariant(this._db);
|
|
35
36
|
return this._db;
|
|
36
37
|
}
|
|
@@ -60,6 +61,6 @@ export class SpaceProxy extends Resource {
|
|
|
60
61
|
owningObject: this,
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
await this._db.coreDatabase.open({ rootUrl: meta.rootDocumentId });
|
|
64
|
+
await this._db.coreDatabase.open(this._ctx, { rootUrl: meta.rootDocumentId });
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -22,7 +22,6 @@ export const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedH
|
|
|
22
22
|
// TODO(mykola): Wrap in withNewExecutionContext;
|
|
23
23
|
// Meta route is used to get the input schema of the function by the functions service.
|
|
24
24
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
25
|
-
log.info('>>> meta', { func });
|
|
26
25
|
return handleFunctionMetaCall(func, request);
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -34,7 +33,7 @@ export const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedH
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);
|
|
36
|
+
const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE, env.FUNCTIONS_AI_SERVICE);
|
|
38
37
|
const context = await createFunctionContext({
|
|
39
38
|
serviceContainer,
|
|
40
39
|
contextSpaceId: spaceId as SpaceId | undefined,
|
|
@@ -98,14 +97,14 @@ const handleFunctionMetaCall = (functionDefinition: FunctionProtocol.Func, reque
|
|
|
98
97
|
});
|
|
99
98
|
};
|
|
100
99
|
|
|
101
|
-
const createFunctionContext = async ({
|
|
100
|
+
export const createFunctionContext = async ({
|
|
102
101
|
serviceContainer,
|
|
103
102
|
contextSpaceId,
|
|
104
103
|
}: {
|
|
105
104
|
serviceContainer: ServiceContainer;
|
|
106
105
|
contextSpaceId: SpaceId | undefined;
|
|
107
106
|
}): Promise<FunctionProtocol.Context> => {
|
|
108
|
-
const { dataService, queryService, queueService } = await serviceContainer.createServices();
|
|
107
|
+
const { dataService, queryService, queueService, functionsAiService } = await serviceContainer.createServices();
|
|
109
108
|
|
|
110
109
|
let spaceKey: string | undefined;
|
|
111
110
|
let rootUrl: string | undefined;
|
|
@@ -124,6 +123,7 @@ const createFunctionContext = async ({
|
|
|
124
123
|
dataService,
|
|
125
124
|
queryService,
|
|
126
125
|
queueService,
|
|
126
|
+
functionsAiService,
|
|
127
127
|
},
|
|
128
128
|
spaceId: contextSpaceId,
|
|
129
129
|
spaceKey,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type QueryAST } from '@dxos/echo-protocol';
|
|
2
|
-
import { type EdgeFunctionEnv } from '@dxos/protocols';
|
|
3
|
-
export declare const queryToDataServiceRequest: (query: QueryAST.Query) => EdgeFunctionEnv.QueryRequest;
|
|
4
|
-
/**
|
|
5
|
-
* Extracts the filter and options from a query.
|
|
6
|
-
* Supports Select(...) and Options(Select(...)) queries.
|
|
7
|
-
*/
|
|
8
|
-
export declare const isSimpleSelectionQuery: (query: QueryAST.Query) => {
|
|
9
|
-
filter: QueryAST.Filter;
|
|
10
|
-
options?: QueryAST.QueryOptions;
|
|
11
|
-
} | null;
|
|
12
|
-
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../src/internal/adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,eAAO,MAAM,yBAAyB,GAAI,OAAO,QAAQ,CAAC,KAAK,KAAG,eAAe,CAAC,YAajF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,QAAQ,CAAC,KAAK,KACpB;IAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAA;CAAE,GAAG,IAgBjE,CAAC"}
|
package/src/internal/adapter.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { failUndefined } from '@dxos/debug';
|
|
6
|
-
import { type QueryAST } from '@dxos/echo-protocol';
|
|
7
|
-
import { invariant } from '@dxos/invariant';
|
|
8
|
-
import { SpaceId } from '@dxos/keys';
|
|
9
|
-
import { type EdgeFunctionEnv } from '@dxos/protocols';
|
|
10
|
-
|
|
11
|
-
export const queryToDataServiceRequest = (query: QueryAST.Query): EdgeFunctionEnv.QueryRequest => {
|
|
12
|
-
const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();
|
|
13
|
-
invariant(options?.spaceIds?.length === 1, 'Only one space is supported');
|
|
14
|
-
invariant(filter.type === 'object', 'Only object filters are supported');
|
|
15
|
-
|
|
16
|
-
const spaceId = options.spaceIds[0];
|
|
17
|
-
invariant(SpaceId.isValid(spaceId));
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
spaceId,
|
|
21
|
-
type: filter.typename ?? undefined,
|
|
22
|
-
objectIds: [...(filter.id ?? [])],
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Extracts the filter and options from a query.
|
|
28
|
-
* Supports Select(...) and Options(Select(...)) queries.
|
|
29
|
-
*/
|
|
30
|
-
export const isSimpleSelectionQuery = (
|
|
31
|
-
query: QueryAST.Query,
|
|
32
|
-
): { filter: QueryAST.Filter; options?: QueryAST.QueryOptions } | null => {
|
|
33
|
-
switch (query.type) {
|
|
34
|
-
case 'options': {
|
|
35
|
-
const maybeFilter = isSimpleSelectionQuery(query.query);
|
|
36
|
-
if (!maybeFilter) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return { filter: maybeFilter.filter, options: query.options };
|
|
40
|
-
}
|
|
41
|
-
case 'select': {
|
|
42
|
-
return { filter: query.filter, options: undefined };
|
|
43
|
-
}
|
|
44
|
-
default: {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|