@dxos/functions-runtime-cloudflare 0.8.4-main.66e292d → 0.8.4-main.7ace549
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 +167 -11
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +167 -11
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/index.ts +3 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { EdgeResponse } from "@dxos/protocols";
|
|
3
|
+
// src/functions-client.ts
|
|
4
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
5
|
+
import { EchoClient } from "@dxos/echo-db";
|
|
6
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
8
7
|
|
|
9
8
|
// src/internal/data-service-impl.ts
|
|
10
9
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
@@ -336,6 +335,156 @@ var ServiceContainer = class {
|
|
|
336
335
|
}
|
|
337
336
|
};
|
|
338
337
|
|
|
338
|
+
// src/space-proxy.ts
|
|
339
|
+
import { Resource } from "@dxos/context";
|
|
340
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
341
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
342
|
+
|
|
343
|
+
// src/queues-api.ts
|
|
344
|
+
var QueuesAPIImpl = class {
|
|
345
|
+
_serviceContainer;
|
|
346
|
+
_spaceId;
|
|
347
|
+
constructor(_serviceContainer, _spaceId) {
|
|
348
|
+
this._serviceContainer = _serviceContainer;
|
|
349
|
+
this._spaceId = _spaceId;
|
|
350
|
+
}
|
|
351
|
+
queryQueue(queue, options) {
|
|
352
|
+
return this._serviceContainer.queryQueue(queue);
|
|
353
|
+
}
|
|
354
|
+
insertIntoQueue(queue, objects) {
|
|
355
|
+
return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/space-proxy.ts
|
|
360
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
361
|
+
var SpaceProxy = class extends Resource {
|
|
362
|
+
_serviceContainer;
|
|
363
|
+
_echoClient;
|
|
364
|
+
_id;
|
|
365
|
+
_db = void 0;
|
|
366
|
+
_queuesApi;
|
|
367
|
+
constructor(_serviceContainer, _echoClient, _id) {
|
|
368
|
+
super(), this._serviceContainer = _serviceContainer, this._echoClient = _echoClient, this._id = _id;
|
|
369
|
+
this._queuesApi = new QueuesAPIImpl(this._serviceContainer, this._id);
|
|
370
|
+
}
|
|
371
|
+
get id() {
|
|
372
|
+
return this._id;
|
|
373
|
+
}
|
|
374
|
+
get db() {
|
|
375
|
+
invariant4(this._db, void 0, {
|
|
376
|
+
F: __dxlog_file4,
|
|
377
|
+
L: 34,
|
|
378
|
+
S: this,
|
|
379
|
+
A: [
|
|
380
|
+
"this._db",
|
|
381
|
+
""
|
|
382
|
+
]
|
|
383
|
+
});
|
|
384
|
+
return this._db;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* @deprecated Use db API.
|
|
388
|
+
*/
|
|
389
|
+
get crud() {
|
|
390
|
+
invariant4(this._db, void 0, {
|
|
391
|
+
F: __dxlog_file4,
|
|
392
|
+
L: 42,
|
|
393
|
+
S: this,
|
|
394
|
+
A: [
|
|
395
|
+
"this._db",
|
|
396
|
+
""
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
return this._db.coreDatabase;
|
|
400
|
+
}
|
|
401
|
+
get queues() {
|
|
402
|
+
return this._queuesApi;
|
|
403
|
+
}
|
|
404
|
+
async _open() {
|
|
405
|
+
const meta = await this._serviceContainer.getSpaceMeta(this._id);
|
|
406
|
+
if (!meta) {
|
|
407
|
+
throw new Error(`Space not found: ${this._id}`);
|
|
408
|
+
}
|
|
409
|
+
this._db = this._echoClient.constructDatabase({
|
|
410
|
+
spaceId: this._id,
|
|
411
|
+
spaceKey: PublicKey2.from(meta.spaceKey),
|
|
412
|
+
reactiveSchemaQuery: false,
|
|
413
|
+
owningObject: this
|
|
414
|
+
});
|
|
415
|
+
await this._db.coreDatabase.open({
|
|
416
|
+
rootUrl: meta.rootDocumentId
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/functions-client.ts
|
|
422
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/functions-client.ts";
|
|
423
|
+
var FunctionsClient = class extends Resource2 {
|
|
424
|
+
_serviceContainer;
|
|
425
|
+
_echoClient;
|
|
426
|
+
_executionContext = {};
|
|
427
|
+
_spaces = /* @__PURE__ */ new Map();
|
|
428
|
+
constructor(services) {
|
|
429
|
+
super();
|
|
430
|
+
invariant5(typeof services.dataService !== "undefined", "DataService is required", {
|
|
431
|
+
F: __dxlog_file5,
|
|
432
|
+
L: 32,
|
|
433
|
+
S: this,
|
|
434
|
+
A: [
|
|
435
|
+
"typeof services.dataService !== 'undefined'",
|
|
436
|
+
"'DataService is required'"
|
|
437
|
+
]
|
|
438
|
+
});
|
|
439
|
+
invariant5(typeof services.queueService !== "undefined", "QueueService is required", {
|
|
440
|
+
F: __dxlog_file5,
|
|
441
|
+
L: 33,
|
|
442
|
+
S: this,
|
|
443
|
+
A: [
|
|
444
|
+
"typeof services.queueService !== 'undefined'",
|
|
445
|
+
"'QueueService is required'"
|
|
446
|
+
]
|
|
447
|
+
});
|
|
448
|
+
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService);
|
|
449
|
+
this._echoClient = new EchoClient({});
|
|
450
|
+
}
|
|
451
|
+
get echo() {
|
|
452
|
+
return this._echoClient;
|
|
453
|
+
}
|
|
454
|
+
async _open() {
|
|
455
|
+
const { dataService, queryService } = await this._serviceContainer.createServices();
|
|
456
|
+
this._echoClient.connectToService({
|
|
457
|
+
dataService,
|
|
458
|
+
queryService
|
|
459
|
+
});
|
|
460
|
+
await this._echoClient.open();
|
|
461
|
+
}
|
|
462
|
+
async _close() {
|
|
463
|
+
for (const space of this._spaces.values()) {
|
|
464
|
+
await space.close();
|
|
465
|
+
}
|
|
466
|
+
this._spaces.clear();
|
|
467
|
+
await this._echoClient.close();
|
|
468
|
+
}
|
|
469
|
+
async getSpace(spaceId) {
|
|
470
|
+
if (!this._spaces.has(spaceId)) {
|
|
471
|
+
const space2 = new SpaceProxy(this._serviceContainer, this._echoClient, spaceId);
|
|
472
|
+
this._spaces.set(spaceId, space2);
|
|
473
|
+
}
|
|
474
|
+
const space = this._spaces.get(spaceId);
|
|
475
|
+
await space.open();
|
|
476
|
+
return space;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var createClientFromEnv = async (env) => {
|
|
480
|
+
const client = new FunctionsClient({
|
|
481
|
+
dataService: env.DATA_SERVICE,
|
|
482
|
+
queueService: env.QUEUE_SERVICE
|
|
483
|
+
});
|
|
484
|
+
await client.open();
|
|
485
|
+
return client;
|
|
486
|
+
};
|
|
487
|
+
|
|
339
488
|
// src/types.ts
|
|
340
489
|
var FUNCTION_ROUTE_HEADER = "X-DXOS-Function-Route";
|
|
341
490
|
var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
@@ -344,14 +493,18 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
344
493
|
})({});
|
|
345
494
|
|
|
346
495
|
// src/wrap-handler-for-cloudflare.ts
|
|
347
|
-
|
|
496
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
497
|
+
import { SpaceId as SpaceId4 } from "@dxos/keys";
|
|
498
|
+
import { log as log3 } from "@dxos/log";
|
|
499
|
+
import { EdgeResponse } from "@dxos/protocols";
|
|
500
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
348
501
|
var wrapHandlerForCloudflare = (func) => {
|
|
349
502
|
return async (request, env) => {
|
|
350
503
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
351
504
|
log3.info(">>> meta", {
|
|
352
505
|
func
|
|
353
506
|
}, {
|
|
354
|
-
F:
|
|
507
|
+
F: __dxlog_file6,
|
|
355
508
|
L: 25,
|
|
356
509
|
S: void 0,
|
|
357
510
|
C: (f, a) => f(...a)
|
|
@@ -378,7 +531,7 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
378
531
|
error,
|
|
379
532
|
stack: error.stack
|
|
380
533
|
}, {
|
|
381
|
-
F:
|
|
534
|
+
F: __dxlog_file6,
|
|
382
535
|
L: 45,
|
|
383
536
|
S: void 0,
|
|
384
537
|
C: (f, a) => f(...a)
|
|
@@ -416,7 +569,7 @@ var decodeRequest = async (request) => {
|
|
|
416
569
|
};
|
|
417
570
|
} catch (err) {
|
|
418
571
|
log3.catch(err, void 0, {
|
|
419
|
-
F:
|
|
572
|
+
F: __dxlog_file6,
|
|
420
573
|
L: 80,
|
|
421
574
|
S: void 0,
|
|
422
575
|
C: (f, a) => f(...a)
|
|
@@ -453,8 +606,8 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
453
606
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
454
607
|
}
|
|
455
608
|
spaceKey = meta.spaceKey;
|
|
456
|
-
|
|
457
|
-
F:
|
|
609
|
+
invariant6(!meta.rootDocumentId.startsWith("automerge:"), void 0, {
|
|
610
|
+
F: __dxlog_file6,
|
|
458
611
|
L: 118,
|
|
459
612
|
S: void 0,
|
|
460
613
|
A: [
|
|
@@ -478,6 +631,9 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
478
631
|
export {
|
|
479
632
|
FUNCTION_ROUTE_HEADER,
|
|
480
633
|
FunctionRouteValue,
|
|
634
|
+
FunctionsClient,
|
|
635
|
+
ServiceContainer,
|
|
636
|
+
createClientFromEnv,
|
|
481
637
|
wrapHandlerForCloudflare
|
|
482
638
|
};
|
|
483
639
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonSchemaType } from '@dxos/echo/internal';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { EdgeResponse } from '@dxos/protocols';\nimport type { EdgeFunctionEnv, FunctionProtocol } from '@dxos/protocols';\n\nimport { ServiceContainer } from './internal';\nimport { FUNCTION_ROUTE_HEADER, type FunctionMetadata, FunctionRouteValue } from './types';\n\n/**\n * Wraps a user function in a Cloudflare-compatible handler.\n */\nexport const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedHandlerFetchHandler<any> => {\n return async (request: Request, env: EdgeFunctionEnv.Env): Promise<Response> => {\n // TODO(dmaretskyi): Should theÓ scope name reflect the function name?\n // TODO(mykola): Wrap in withCleanAutomergeWasmState;\n // TODO(mykola): Wrap in withNewExecutionContext;\n // Meta route is used to get the input schema of the function by the functions service.\n if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {\n log.info('>>> meta', { func });\n return handleFunctionMetaCall(func, request);\n }\n\n try {\n const spaceId = new URL(request.url).searchParams.get('spaceId');\n if (spaceId) {\n if (!SpaceId.isValid(spaceId)) {\n return new Response('Invalid spaceId', { status: 400 });\n }\n }\n\n const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);\n const context = await createFunctionContext({\n serviceContainer,\n contextSpaceId: spaceId as SpaceId | undefined,\n });\n\n return EdgeResponse.success(await invokeFunction(func, context, request));\n } catch (error: any) {\n log.error('error invoking function', { error, stack: error.stack });\n return EdgeResponse.failure({\n message: error?.message ?? 'Internal error',\n error,\n });\n }\n };\n};\n\nconst invokeFunction = async (func: FunctionProtocol.Func, context: FunctionProtocol.Context, request: Request) => {\n // TODO(dmaretskyi): For some reason requests get wrapped like this.\n const { data } = await decodeRequest(request);\n\n return func.handler({\n context,\n data,\n });\n};\n\nconst decodeRequest = async (request: Request) => {\n const {\n data: { bodyText, ...rest },\n trigger,\n } = (await request.json()) as any;\n\n if (!bodyText) {\n return { data: rest, trigger };\n }\n\n // Webhook passed body as bodyText. Use it as function input if a well-formatted JSON\n // TODO: better trigger input mapping\n try {\n const data = JSON.parse(bodyText);\n return { data, trigger: { ...trigger, ...rest } };\n } catch (err) {\n log.catch(err);\n return { data: { bodyText, ...rest } };\n }\n};\n\nconst handleFunctionMetaCall = (functionDefinition: FunctionProtocol.Func, request: Request): Response => {\n const response: FunctionMetadata = {\n key: functionDefinition.meta.key,\n name: functionDefinition.meta.name,\n description: functionDefinition.meta.description,\n inputSchema: functionDefinition.meta.inputSchema as JsonSchemaType | undefined,\n outputSchema: functionDefinition.meta.outputSchema as JsonSchemaType | undefined,\n };\n\n return new Response(JSON.stringify(response), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n\nconst createFunctionContext = async ({\n serviceContainer,\n contextSpaceId,\n}: {\n serviceContainer: ServiceContainer;\n contextSpaceId: SpaceId | undefined;\n}): Promise<FunctionProtocol.Context> => {\n const { dataService, queryService, queueService } = await serviceContainer.createServices();\n\n let spaceKey: string | undefined;\n let rootUrl: string | undefined;\n if (contextSpaceId) {\n const meta = await serviceContainer.getSpaceMeta(contextSpaceId);\n if (!meta) {\n throw new Error(`Space not found: ${contextSpaceId}`);\n }\n spaceKey = meta.spaceKey;\n invariant(!meta.rootDocumentId.startsWith('automerge:'));\n rootUrl = `automerge:${meta.rootDocumentId}`;\n }\n\n return {\n services: {\n dataService,\n queryService,\n queueService,\n },\n spaceId: contextSpaceId,\n spaceKey,\n spaceRootUrl: rootUrl,\n } as any; // TODO(dmaretskyi): Link and fix before merging\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { RequestOptions } from '@dxos/codec-protobuf';\nimport { Stream } from '@dxos/codec-protobuf/stream';\nimport { raise } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport type {\n BatchedDocumentUpdates,\n DataService as DataServiceProto,\n GetDocumentHeadsRequest,\n GetDocumentHeadsResponse,\n GetSpaceSyncStateRequest,\n ReIndexHeadsRequest,\n SpaceSyncState,\n UpdateRequest,\n UpdateSubscriptionRequest,\n} from '@dxos/protocols/proto/dxos/echo/service';\n\nexport class DataServiceImpl implements DataServiceProto {\n private dataSubscriptions = new Map<string, { spaceId: SpaceId; next: (msg: BatchedDocumentUpdates) => void }>();\n\n constructor(\n private _executionContext: EdgeFunctionEnv.ExecutionContext,\n private _dataService: EdgeFunctionEnv.DataService,\n ) {}\n\n subscribe({ subscriptionId, spaceId }: { subscriptionId: string; spaceId: string }): Stream<BatchedDocumentUpdates> {\n return new Stream(({ next }) => {\n invariant(SpaceId.isValid(spaceId));\n this.dataSubscriptions.set(subscriptionId, { spaceId, next });\n\n return () => {\n this.dataSubscriptions.delete(subscriptionId);\n };\n });\n }\n\n async updateSubscription({ subscriptionId, addIds, removeIds }: UpdateSubscriptionRequest): Promise<void> {\n const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error('Subscription not found'));\n\n if (addIds) {\n log.info('request documents', { count: addIds.length });\n // TODO(dmaretskyi): Batch.\n for (const documentId of addIds) {\n const document = await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId);\n log.info('document loaded', { documentId, spaceId: sub.spaceId, found: !!document });\n if (!document) {\n log.warn('not found', { documentId });\n continue;\n }\n sub.next({ updates: [{ documentId, mutation: document.data }] });\n }\n }\n }\n\n async update({ updates, subscriptionId }: UpdateRequest): Promise<void> {\n const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error('Subscription not found'));\n // TODO(dmaretskyi): Batch.\n for (const update of updates ?? []) {\n await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);\n }\n throw new Error('Method not implemented.');\n }\n\n async flush(): Promise<void> {\n // No-op.\n }\n\n subscribeSpaceSyncState(request: GetSpaceSyncStateRequest, options?: RequestOptions): Stream<SpaceSyncState> {\n throw new Error('Method not implemented.');\n }\n\n async getDocumentHeads({ documentIds }: GetDocumentHeadsRequest): Promise<GetDocumentHeadsResponse> {\n throw new Error('Method not implemented.');\n }\n\n async reIndexHeads({ documentIds }: ReIndexHeadsRequest): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async updateIndexes(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async waitUntilHeadsReplicated({ heads }: { heads: any }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Stream } from '@dxos/codec-protobuf/stream';\nimport { QueryAST } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport {\n type QueryRequest,\n type QueryResponse,\n type QueryResult as QueryResultProto,\n type QueryService as QueryServiceProto,\n} from '@dxos/protocols/proto/dxos/echo/query';\n\nimport { queryToDataServiceRequest } from './adapter';\n\nexport class QueryServiceImpl implements QueryServiceProto {\n constructor(\n private readonly _executionContext: EdgeFunctionEnv.ExecutionContext,\n private readonly _dataService: EdgeFunctionEnv.DataService,\n ) {}\n\n execQuery(request: QueryRequest): Stream<QueryResponse> {\n log.info('execQuery', { request });\n const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));\n const requestedSpaceIds = getTargetSpacesForQuery(query);\n invariant(requestedSpaceIds.length === 1, 'Only one space is supported');\n const spaceId = requestedSpaceIds[0];\n\n return Stream.fromPromise<QueryResponse>(\n (async () => {\n try {\n log.info('begin query', { spaceId });\n const queryResponse = await this._dataService.queryDocuments(\n this._executionContext,\n queryToDataServiceRequest(query),\n );\n log.info('query response', { spaceId, filter: request.filter, resultCount: queryResponse.results.length });\n return {\n results: queryResponse.results.map(\n (object): QueryResultProto => ({\n id: object.objectId,\n spaceId,\n spaceKey: PublicKey.ZERO,\n documentId: object.document.documentId,\n rank: 0,\n documentAutomerge: object.document.data,\n }),\n ),\n } satisfies QueryResponse;\n } catch (err) {\n log.error('query failed', { err });\n throw err;\n }\n })(),\n );\n }\n\n async reindex() {\n throw new Error('Method not implemented.');\n }\n\n async setConfig() {\n throw new Error('Method not implemented.');\n }\n}\n\n/**\n * Lists spaces this query will select from.\n */\nexport const getTargetSpacesForQuery = (query: QueryAST.Query): SpaceId[] => {\n const spaces = new Set<SpaceId>();\n\n const visitor = (node: QueryAST.Query) => {\n if (node.type === 'options') {\n if (node.options.spaceIds) {\n for (const spaceId of node.options.spaceIds) {\n spaces.add(SpaceId.make(spaceId));\n }\n }\n }\n };\n QueryAST.visit(query, visitor);\n return [...spaces];\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { failUndefined } from '@dxos/debug';\nimport { type QueryAST } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\n\nexport const queryToDataServiceRequest = (query: QueryAST.Query): EdgeFunctionEnv.QueryRequest => {\n const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();\n invariant(options?.spaceIds?.length === 1, 'Only one space is supported');\n invariant(filter.type === 'object', 'Only object filters are supported');\n\n const spaceId = options.spaceIds[0];\n invariant(SpaceId.isValid(spaceId));\n\n return {\n spaceId,\n type: filter.typename ?? undefined,\n objectIds: [...(filter.id ?? [])],\n };\n};\n\n/**\n * Extracts the filter and options from a query.\n * Supports Select(...) and Options(Select(...)) queries.\n */\nexport const isSimpleSelectionQuery = (\n query: QueryAST.Query,\n): { filter: QueryAST.Filter; options?: QueryAST.QueryOptions } | null => {\n switch (query.type) {\n case 'options': {\n const maybeFilter = isSimpleSelectionQuery(query.query);\n if (!maybeFilter) {\n return null;\n }\n return { filter: maybeFilter.filter, options: query.options };\n }\n case 'select': {\n return { filter: query.filter, options: undefined };\n }\n default: {\n return null;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ObjectId, SpaceId } from '@dxos/keys';\nimport { type QueueService as QueueServiceProto } from '@dxos/protocols';\nimport type { EdgeFunctionEnv, QueryResult, QueueQuery } from '@dxos/protocols';\n\nexport class QueueServiceImpl implements QueueServiceProto {\n constructor(\n protected _ctx: EdgeFunctionEnv.ExecutionContext,\n private readonly _queueService: EdgeFunctionEnv.QueueService,\n ) {}\n queryQueue(subspaceTag: string, spaceId: SpaceId, { queueId, ...query }: QueueQuery): Promise<QueryResult> {\n return this._queueService.query(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, query);\n }\n insertIntoQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, objects: unknown[]): Promise<void> {\n return this._queueService.append(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, objects);\n }\n deleteFromQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, objectIds: ObjectId[]): Promise<void> {\n throw new Error('Deleting from queue is not supported.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { HasId } from '@dxos/echo/internal';\nimport { type DXN, type SpaceId } from '@dxos/keys';\nimport type { QueryResult } from '@dxos/protocols';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport { type QueueService as QueueServiceProto } from '@dxos/protocols';\nimport { type QueryService as QueryServiceProto } from '@dxos/protocols/proto/dxos/echo/query';\nimport type { DataService as DataServiceProto } from '@dxos/protocols/proto/dxos/echo/service';\n\nimport { DataServiceImpl } from './data-service-impl';\nimport { QueryServiceImpl } from './query-service-impl';\nimport { QueueServiceImpl } from './queue-service-impl';\n\n/**\n * TODO: make this implement DataService and QueryService to unify API over edge and web backend\n */\nexport class ServiceContainer {\n constructor(\n private readonly _executionContext: EdgeFunctionEnv.ExecutionContext,\n private readonly _dataService: EdgeFunctionEnv.DataService,\n private readonly _queueService: EdgeFunctionEnv.QueueService,\n ) {}\n\n async getSpaceMeta(spaceId: SpaceId): Promise<EdgeFunctionEnv.SpaceMeta | undefined> {\n return this._dataService.getSpaceMeta(this._executionContext, spaceId);\n }\n\n async createServices(): Promise<{\n dataService: DataServiceProto;\n queryService: QueryServiceProto;\n queueService: QueueServiceProto;\n }> {\n const dataService = new DataServiceImpl(this._executionContext, this._dataService);\n const queryService = new QueryServiceImpl(this._executionContext, this._dataService);\n const queueService = new QueueServiceImpl(this._executionContext, this._queueService);\n\n return {\n dataService,\n queryService,\n queueService,\n };\n }\n\n queryQueue(queue: DXN): Promise<QueryResult> {\n return this._queueService.query({}, queue.toString(), {});\n }\n\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void> {\n return this._queueService.append({}, queue.toString(), objects);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonSchemaType } from '@dxos/echo/internal';\n\n/**\n * Is used for to route the request to the metadata handler instead of the main handler.\n */\nexport const FUNCTION_ROUTE_HEADER = 'X-DXOS-Function-Route';\n\nexport enum FunctionRouteValue {\n Meta = 'meta',\n}\n\nexport type FunctionMetadata = {\n /**\n * FQN.\n */\n key: string;\n /**\n * Human-readable name.\n */\n name?: string;\n\n /**\n * Description.\n */\n description?: string;\n\n /**\n * Input schema.\n */\n inputSchema?: JsonSchemaType;\n\n /**\n * Output schema.\n */\n outputSchema?: JsonSchemaType;\n};\n"],
|
|
5
|
-
"mappings": ";;;
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/functions-client.ts", "../../../src/internal/data-service-impl.ts", "../../../src/internal/query-service-impl.ts", "../../../src/internal/adapter.ts", "../../../src/internal/queue-service-impl.ts", "../../../src/internal/service-container.ts", "../../../src/space-proxy.ts", "../../../src/queues-api.ts", "../../../src/types.ts", "../../../src/wrap-handler-for-cloudflare.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Resource } from '@dxos/context';\nimport { EchoClient } from '@dxos/echo-db';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId } from '@dxos/keys';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\n\nimport { ServiceContainer } from './internal';\nimport { SpaceProxy } from './space-proxy';\n\ntype Services = {\n dataService: EdgeFunctionEnv.DataService;\n queueService: EdgeFunctionEnv.QueueService;\n};\n\n/**\n * API for functions to integrate with ECHO and HALO.\n * @deprecated\n */\nexport class FunctionsClient extends Resource {\n private readonly _serviceContainer;\n private readonly _echoClient;\n private readonly _executionContext: EdgeFunctionEnv.ExecutionContext = {};\n\n private readonly _spaces = new Map<SpaceId, SpaceProxy>();\n\n constructor(services: Services) {\n super();\n invariant(typeof services.dataService !== 'undefined', 'DataService is required');\n invariant(typeof services.queueService !== 'undefined', 'QueueService is required');\n this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService);\n this._echoClient = new EchoClient({});\n }\n\n get echo(): EchoClient {\n return this._echoClient;\n }\n\n protected override async _open() {\n const { dataService, queryService } = await this._serviceContainer.createServices();\n this._echoClient.connectToService({ dataService, queryService });\n await this._echoClient.open();\n }\n\n protected override async _close() {\n for (const space of this._spaces.values()) {\n await space.close();\n }\n this._spaces.clear();\n\n await this._echoClient.close();\n }\n\n async getSpace(spaceId: SpaceId): Promise<SpaceProxy> {\n if (!this._spaces.has(spaceId)) {\n const space = new SpaceProxy(this._serviceContainer, this._echoClient, spaceId);\n this._spaces.set(spaceId, space);\n }\n const space = this._spaces.get(spaceId)!;\n await space.open(); // No-op if already open.\n return space;\n }\n}\n\nexport const createClientFromEnv = async (env: any): Promise<FunctionsClient> => {\n const client = new FunctionsClient({\n dataService: env.DATA_SERVICE,\n queueService: env.QUEUE_SERVICE,\n });\n await client.open();\n return client;\n};\n\n/**\n - Provides data access capabilities for user functions.\n - No real-time replication or reactive queries -- function receives a snapshot.\n - Function event contains the metadata but doesn't need to include the data.\n */\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { RequestOptions } from '@dxos/codec-protobuf';\nimport { Stream } from '@dxos/codec-protobuf/stream';\nimport { raise } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport type {\n BatchedDocumentUpdates,\n DataService as DataServiceProto,\n GetDocumentHeadsRequest,\n GetDocumentHeadsResponse,\n GetSpaceSyncStateRequest,\n ReIndexHeadsRequest,\n SpaceSyncState,\n UpdateRequest,\n UpdateSubscriptionRequest,\n} from '@dxos/protocols/proto/dxos/echo/service';\n\nexport class DataServiceImpl implements DataServiceProto {\n private dataSubscriptions = new Map<string, { spaceId: SpaceId; next: (msg: BatchedDocumentUpdates) => void }>();\n\n constructor(\n private _executionContext: EdgeFunctionEnv.ExecutionContext,\n private _dataService: EdgeFunctionEnv.DataService,\n ) {}\n\n subscribe({ subscriptionId, spaceId }: { subscriptionId: string; spaceId: string }): Stream<BatchedDocumentUpdates> {\n return new Stream(({ next }) => {\n invariant(SpaceId.isValid(spaceId));\n this.dataSubscriptions.set(subscriptionId, { spaceId, next });\n\n return () => {\n this.dataSubscriptions.delete(subscriptionId);\n };\n });\n }\n\n async updateSubscription({ subscriptionId, addIds, removeIds }: UpdateSubscriptionRequest): Promise<void> {\n const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error('Subscription not found'));\n\n if (addIds) {\n log.info('request documents', { count: addIds.length });\n // TODO(dmaretskyi): Batch.\n for (const documentId of addIds) {\n const document = await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId);\n log.info('document loaded', { documentId, spaceId: sub.spaceId, found: !!document });\n if (!document) {\n log.warn('not found', { documentId });\n continue;\n }\n sub.next({ updates: [{ documentId, mutation: document.data }] });\n }\n }\n }\n\n async update({ updates, subscriptionId }: UpdateRequest): Promise<void> {\n const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error('Subscription not found'));\n // TODO(dmaretskyi): Batch.\n for (const update of updates ?? []) {\n await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);\n }\n throw new Error('Method not implemented.');\n }\n\n async flush(): Promise<void> {\n // No-op.\n }\n\n subscribeSpaceSyncState(request: GetSpaceSyncStateRequest, options?: RequestOptions): Stream<SpaceSyncState> {\n throw new Error('Method not implemented.');\n }\n\n async getDocumentHeads({ documentIds }: GetDocumentHeadsRequest): Promise<GetDocumentHeadsResponse> {\n throw new Error('Method not implemented.');\n }\n\n async reIndexHeads({ documentIds }: ReIndexHeadsRequest): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async updateIndexes(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async waitUntilHeadsReplicated({ heads }: { heads: any }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Stream } from '@dxos/codec-protobuf/stream';\nimport { QueryAST } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport {\n type QueryRequest,\n type QueryResponse,\n type QueryResult as QueryResultProto,\n type QueryService as QueryServiceProto,\n} from '@dxos/protocols/proto/dxos/echo/query';\n\nimport { queryToDataServiceRequest } from './adapter';\n\nexport class QueryServiceImpl implements QueryServiceProto {\n constructor(\n private readonly _executionContext: EdgeFunctionEnv.ExecutionContext,\n private readonly _dataService: EdgeFunctionEnv.DataService,\n ) {}\n\n execQuery(request: QueryRequest): Stream<QueryResponse> {\n log.info('execQuery', { request });\n const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));\n const requestedSpaceIds = getTargetSpacesForQuery(query);\n invariant(requestedSpaceIds.length === 1, 'Only one space is supported');\n const spaceId = requestedSpaceIds[0];\n\n return Stream.fromPromise<QueryResponse>(\n (async () => {\n try {\n log.info('begin query', { spaceId });\n const queryResponse = await this._dataService.queryDocuments(\n this._executionContext,\n queryToDataServiceRequest(query),\n );\n log.info('query response', { spaceId, filter: request.filter, resultCount: queryResponse.results.length });\n return {\n results: queryResponse.results.map(\n (object): QueryResultProto => ({\n id: object.objectId,\n spaceId,\n spaceKey: PublicKey.ZERO,\n documentId: object.document.documentId,\n rank: 0,\n documentAutomerge: object.document.data,\n }),\n ),\n } satisfies QueryResponse;\n } catch (err) {\n log.error('query failed', { err });\n throw err;\n }\n })(),\n );\n }\n\n async reindex() {\n throw new Error('Method not implemented.');\n }\n\n async setConfig() {\n throw new Error('Method not implemented.');\n }\n}\n\n/**\n * Lists spaces this query will select from.\n */\nexport const getTargetSpacesForQuery = (query: QueryAST.Query): SpaceId[] => {\n const spaces = new Set<SpaceId>();\n\n const visitor = (node: QueryAST.Query) => {\n if (node.type === 'options') {\n if (node.options.spaceIds) {\n for (const spaceId of node.options.spaceIds) {\n spaces.add(SpaceId.make(spaceId));\n }\n }\n }\n };\n QueryAST.visit(query, visitor);\n return [...spaces];\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { failUndefined } from '@dxos/debug';\nimport { type QueryAST } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\n\nexport const queryToDataServiceRequest = (query: QueryAST.Query): EdgeFunctionEnv.QueryRequest => {\n const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();\n invariant(options?.spaceIds?.length === 1, 'Only one space is supported');\n invariant(filter.type === 'object', 'Only object filters are supported');\n\n const spaceId = options.spaceIds[0];\n invariant(SpaceId.isValid(spaceId));\n\n return {\n spaceId,\n type: filter.typename ?? undefined,\n objectIds: [...(filter.id ?? [])],\n };\n};\n\n/**\n * Extracts the filter and options from a query.\n * Supports Select(...) and Options(Select(...)) queries.\n */\nexport const isSimpleSelectionQuery = (\n query: QueryAST.Query,\n): { filter: QueryAST.Filter; options?: QueryAST.QueryOptions } | null => {\n switch (query.type) {\n case 'options': {\n const maybeFilter = isSimpleSelectionQuery(query.query);\n if (!maybeFilter) {\n return null;\n }\n return { filter: maybeFilter.filter, options: query.options };\n }\n case 'select': {\n return { filter: query.filter, options: undefined };\n }\n default: {\n return null;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ObjectId, SpaceId } from '@dxos/keys';\nimport { type QueueService as QueueServiceProto } from '@dxos/protocols';\nimport type { EdgeFunctionEnv, QueryResult, QueueQuery } from '@dxos/protocols';\n\nexport class QueueServiceImpl implements QueueServiceProto {\n constructor(\n protected _ctx: EdgeFunctionEnv.ExecutionContext,\n private readonly _queueService: EdgeFunctionEnv.QueueService,\n ) {}\n queryQueue(subspaceTag: string, spaceId: SpaceId, { queueId, ...query }: QueueQuery): Promise<QueryResult> {\n return this._queueService.query(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, query);\n }\n insertIntoQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, objects: unknown[]): Promise<void> {\n return this._queueService.append(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, objects);\n }\n deleteFromQueue(subspaceTag: string, spaceId: SpaceId, queueId: ObjectId, objectIds: ObjectId[]): Promise<void> {\n throw new Error('Deleting from queue is not supported.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { HasId } from '@dxos/echo/internal';\nimport { type DXN, type SpaceId } from '@dxos/keys';\nimport type { QueryResult } from '@dxos/protocols';\nimport { type EdgeFunctionEnv } from '@dxos/protocols';\nimport { type QueueService as QueueServiceProto } from '@dxos/protocols';\nimport { type QueryService as QueryServiceProto } from '@dxos/protocols/proto/dxos/echo/query';\nimport type { DataService as DataServiceProto } from '@dxos/protocols/proto/dxos/echo/service';\n\nimport { DataServiceImpl } from './data-service-impl';\nimport { QueryServiceImpl } from './query-service-impl';\nimport { QueueServiceImpl } from './queue-service-impl';\n\n/**\n * TODO: make this implement DataService and QueryService to unify API over edge and web backend\n */\nexport class ServiceContainer {\n constructor(\n private readonly _executionContext: EdgeFunctionEnv.ExecutionContext,\n private readonly _dataService: EdgeFunctionEnv.DataService,\n private readonly _queueService: EdgeFunctionEnv.QueueService,\n ) {}\n\n async getSpaceMeta(spaceId: SpaceId): Promise<EdgeFunctionEnv.SpaceMeta | undefined> {\n return this._dataService.getSpaceMeta(this._executionContext, spaceId);\n }\n\n async createServices(): Promise<{\n dataService: DataServiceProto;\n queryService: QueryServiceProto;\n queueService: QueueServiceProto;\n }> {\n const dataService = new DataServiceImpl(this._executionContext, this._dataService);\n const queryService = new QueryServiceImpl(this._executionContext, this._dataService);\n const queueService = new QueueServiceImpl(this._executionContext, this._queueService);\n\n return {\n dataService,\n queryService,\n queueService,\n };\n }\n\n queryQueue(queue: DXN): Promise<QueryResult> {\n return this._queueService.query({}, queue.toString(), {});\n }\n\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void> {\n return this._queueService.append({}, queue.toString(), objects);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Resource } from '@dxos/context';\nimport { type CoreDatabase, type EchoClient, type EchoDatabase } from '@dxos/echo-db';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey, type SpaceId } from '@dxos/keys';\n\nimport type { ServiceContainer } from './internal';\nimport { type QueuesAPI, QueuesAPIImpl } from './queues-api';\n\n/**\n * @deprecated\n */\nexport class SpaceProxy extends Resource {\n private _db?: EchoDatabase = undefined;\n private _queuesApi: QueuesAPIImpl;\n\n constructor(\n private readonly _serviceContainer: ServiceContainer,\n private readonly _echoClient: EchoClient,\n private readonly _id: SpaceId,\n ) {\n super();\n this._queuesApi = new QueuesAPIImpl(this._serviceContainer, this._id);\n }\n\n get id(): SpaceId {\n return this._id;\n }\n\n get db(): EchoDatabase {\n invariant(this._db);\n return this._db;\n }\n\n /**\n * @deprecated Use db API.\n */\n get crud(): CoreDatabase {\n invariant(this._db);\n return this._db.coreDatabase;\n }\n\n get queues(): QueuesAPI {\n return this._queuesApi;\n }\n\n protected override async _open() {\n const meta = await this._serviceContainer.getSpaceMeta(this._id);\n if (!meta) {\n throw new Error(`Space not found: ${this._id}`);\n }\n\n this._db = this._echoClient.constructDatabase({\n spaceId: this._id,\n spaceKey: PublicKey.from(meta.spaceKey),\n reactiveSchemaQuery: false,\n owningObject: this,\n });\n\n await this._db.coreDatabase.open({ rootUrl: meta.rootDocumentId });\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { HasId } from '@dxos/echo/internal';\nimport type { DXN, SpaceId } from '@dxos/keys';\nimport type { QueryResult } from '@dxos/protocols';\n\nimport type { ServiceContainer } from './internal';\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\n/**\n * @deprecated\n */\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * @deprecated\n */\nexport class QueuesAPIImpl implements QueuesAPI {\n constructor(\n private readonly _serviceContainer: ServiceContainer,\n private readonly _spaceId: SpaceId,\n ) {}\n\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult> {\n return this._serviceContainer.queryQueue(queue);\n }\n\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void> {\n // TODO(dmaretskyi): Ugly.\n return this._serviceContainer.insertIntoQueue(queue, JSON.parse(JSON.stringify(objects)));\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonSchemaType } from '@dxos/echo/internal';\n\n/**\n * Is used for to route the request to the metadata handler instead of the main handler.\n */\nexport const FUNCTION_ROUTE_HEADER = 'X-DXOS-Function-Route';\n\nexport enum FunctionRouteValue {\n Meta = 'meta',\n}\n\nexport type FunctionMetadata = {\n /**\n * FQN.\n */\n key: string;\n /**\n * Human-readable name.\n */\n name?: string;\n\n /**\n * Description.\n */\n description?: string;\n\n /**\n * Input schema.\n */\n inputSchema?: JsonSchemaType;\n\n /**\n * Output schema.\n */\n outputSchema?: JsonSchemaType;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { JsonSchemaType } from '@dxos/echo/internal';\nimport { invariant } from '@dxos/invariant';\nimport { SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { EdgeResponse } from '@dxos/protocols';\nimport type { EdgeFunctionEnv, FunctionProtocol } from '@dxos/protocols';\n\nimport { ServiceContainer } from './internal';\nimport { FUNCTION_ROUTE_HEADER, type FunctionMetadata, FunctionRouteValue } from './types';\n\n/**\n * Wraps a user function in a Cloudflare-compatible handler.\n */\nexport const wrapHandlerForCloudflare = (func: FunctionProtocol.Func): ExportedHandlerFetchHandler<any> => {\n return async (request: Request, env: EdgeFunctionEnv.Env): Promise<Response> => {\n // TODO(dmaretskyi): Should theÓ scope name reflect the function name?\n // TODO(mykola): Wrap in withCleanAutomergeWasmState;\n // TODO(mykola): Wrap in withNewExecutionContext;\n // Meta route is used to get the input schema of the function by the functions service.\n if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {\n log.info('>>> meta', { func });\n return handleFunctionMetaCall(func, request);\n }\n\n try {\n const spaceId = new URL(request.url).searchParams.get('spaceId');\n if (spaceId) {\n if (!SpaceId.isValid(spaceId)) {\n return new Response('Invalid spaceId', { status: 400 });\n }\n }\n\n const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);\n const context = await createFunctionContext({\n serviceContainer,\n contextSpaceId: spaceId as SpaceId | undefined,\n });\n\n return EdgeResponse.success(await invokeFunction(func, context, request));\n } catch (error: any) {\n log.error('error invoking function', { error, stack: error.stack });\n return EdgeResponse.failure({\n message: error?.message ?? 'Internal error',\n error,\n });\n }\n };\n};\n\nconst invokeFunction = async (func: FunctionProtocol.Func, context: FunctionProtocol.Context, request: Request) => {\n // TODO(dmaretskyi): For some reason requests get wrapped like this.\n const { data } = await decodeRequest(request);\n\n return func.handler({\n context,\n data,\n });\n};\n\nconst decodeRequest = async (request: Request) => {\n const {\n data: { bodyText, ...rest },\n trigger,\n } = (await request.json()) as any;\n\n if (!bodyText) {\n return { data: rest, trigger };\n }\n\n // Webhook passed body as bodyText. Use it as function input if a well-formatted JSON\n // TODO: better trigger input mapping\n try {\n const data = JSON.parse(bodyText);\n return { data, trigger: { ...trigger, ...rest } };\n } catch (err) {\n log.catch(err);\n return { data: { bodyText, ...rest } };\n }\n};\n\nconst handleFunctionMetaCall = (functionDefinition: FunctionProtocol.Func, request: Request): Response => {\n const response: FunctionMetadata = {\n key: functionDefinition.meta.key,\n name: functionDefinition.meta.name,\n description: functionDefinition.meta.description,\n inputSchema: functionDefinition.meta.inputSchema as JsonSchemaType | undefined,\n outputSchema: functionDefinition.meta.outputSchema as JsonSchemaType | undefined,\n };\n\n return new Response(JSON.stringify(response), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n};\n\nconst createFunctionContext = async ({\n serviceContainer,\n contextSpaceId,\n}: {\n serviceContainer: ServiceContainer;\n contextSpaceId: SpaceId | undefined;\n}): Promise<FunctionProtocol.Context> => {\n const { dataService, queryService, queueService } = await serviceContainer.createServices();\n\n let spaceKey: string | undefined;\n let rootUrl: string | undefined;\n if (contextSpaceId) {\n const meta = await serviceContainer.getSpaceMeta(contextSpaceId);\n if (!meta) {\n throw new Error(`Space not found: ${contextSpaceId}`);\n }\n spaceKey = meta.spaceKey;\n invariant(!meta.rootDocumentId.startsWith('automerge:'));\n rootUrl = `automerge:${meta.rootDocumentId}`;\n }\n\n return {\n services: {\n dataService,\n queryService,\n queueService,\n },\n spaceId: contextSpaceId,\n spaceKey,\n spaceRootUrl: rootUrl,\n } as any; // TODO(dmaretskyi): Link and fix before merging\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,YAAAA,iBAAgB;AACzB,SAASC,kBAAkB;AAC3B,SAASC,aAAAA,kBAAiB;;;ACD1B,SAASC,cAAc;AACvB,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,WAAW;;AAcb,IAAMC,kBAAN,MAAMA;;;EACHC,oBAAoB,oBAAIC,IAAAA;EAEhC,YACUC,mBACAC,cACR;SAFQD,oBAAAA;SACAC,eAAAA;EACP;EAEHC,UAAU,EAAEC,gBAAgBC,QAAO,GAAiF;AAClH,WAAO,IAAIZ,OAAO,CAAC,EAAEa,KAAI,MAAE;AACzBX,gBAAUC,QAAQW,QAAQF,OAAAA,GAAAA,QAAAA;;;;;;;;;AAC1B,WAAKN,kBAAkBS,IAAIJ,gBAAgB;QAAEC;QAASC;MAAK,CAAA;AAE3D,aAAO,MAAA;AACL,aAAKP,kBAAkBU,OAAOL,cAAAA;MAChC;IACF,CAAA;EACF;EAEA,MAAMM,mBAAmB,EAAEN,gBAAgBO,QAAQC,UAAS,GAA8C;AACxG,UAAMC,MAAM,KAAKd,kBAAkBe,IAAIV,cAAAA,KAAmBV,MAAM,IAAIqB,MAAM,wBAAA,CAAA;AAE1E,QAAIJ,QAAQ;AACVd,UAAImB,KAAK,qBAAqB;QAAEC,OAAON,OAAOO;MAAO,GAAA;;;;;;AAErD,iBAAWC,cAAcR,QAAQ;AAC/B,cAAMS,WAAW,MAAM,KAAKlB,aAAamB,YAAY,KAAKpB,mBAAmBY,IA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e,cAAc;EAC5C;AAEA,SAAO;IACLE,UAAU;MACRX;MACAC;MACAC;IACF;IACA5C,SAASc;IACTgC;IACAQ,cAAcP;EAChB;AACF;",
|
|
6
|
+
"names": ["Resource", "EchoClient", "invariant", "Stream", "raise", "invariant", "SpaceId", "log", "DataServiceImpl", "dataSubscriptions", "Map", "_executionContext", "_dataService", "subscribe", "subscriptionId", "spaceId", "next", "isValid", "set", "delete", "updateSubscription", "addIds", "removeIds", "sub", "get", "Error", "info", "count", "length", "documentId", "document", "getDocument", "found", "warn", "updates", "mutation", "data", "update", "changeDocument", "flush", "subscribeSpaceSyncState", "request", "options", "getDocumentHeads", "documentIds", "reIndexHeads", "updateIndexes", "waitUntilHeadsReplicated", "heads", "Schema", "Stream", "QueryAST", "invariant", "PublicKey", "SpaceId", "log", "failUndefined", "invariant", "SpaceId", "queryToDataServiceRequest", "query", "filter", "options", "isSimpleSelectionQuery", "spaceIds", "length", "type", "spaceId", "isValid", "typename", "undefined", "objectIds", "id", "maybeFilter", "QueryServiceImpl", "_executionContext", "_dataService", "execQuery", "request", "log", "info", "query", "QueryAST", "Query", "pipe", "decodeUnknownSync", "JSON", "parse", "requestedSpaceIds", "getTargetSpacesForQuery", "invariant", "length", "spaceId", "Stream", "fromPromise", "queryResponse", "queryDocuments", "queryToDataServiceRequest", "filter", "resultCount", "results", "map", "object", "id", "objectId", "spaceKey", "PublicKey", "ZERO", "documentId", "document", "rank", "documentAutomerge", "data", "err", "error", "reindex", "Error", "setConfig", "spaces", "Set", "visitor", "node", "type", "options", "spaceIds", "add", "SpaceId", "make", "visit", "QueueServiceImpl", "_ctx", "_queueService", "queryQueue", "subspaceTag", "spaceId", "queueId", "query", "insertIntoQueue", "objects", "append", "deleteFromQueue", "objectIds", "Error", "ServiceContainer", "_executionContext", "_dataService", "_queueService", "getSpaceMeta", "spaceId", "createServices", "dataService", "DataServiceImpl", "queryService", "QueryServiceImpl", "queueService", "QueueServiceImpl", "queryQueue", "queue", "query", "toString", "insertIntoQueue", "objects", "append", "Resource", "invariant", "PublicKey", "QueuesAPIImpl", "_serviceContainer", "_spaceId", "queryQueue", "queue", "options", "insertIntoQueue", "objects", "JSON", "parse", "stringify", "SpaceProxy", "Resource", "_db", "undefined", "_queuesApi", "_serviceContainer", "_echoClient", "_id", "QueuesAPIImpl", "id", "db", "invariant", "crud", "coreDatabase", "queues", "_open", "meta", "getSpaceMeta", "Error", "constructDatabase", "spaceId", "spaceKey", "PublicKey", "from", "reactiveSchemaQuery", "owningObject", "open", "rootUrl", "rootDocumentId", "FunctionsClient", "Resource", "_serviceContainer", "_echoClient", "_executionContext", "_spaces", "Map", "services", "invariant", "dataService", "queueService", "ServiceContainer", "EchoClient", "echo", "_open", "queryService", "createServices", "connectToService", "open", "_close", "space", "values", "close", "clear", "getSpace", "spaceId", "has", "SpaceProxy", "set", "get", "createClientFromEnv", "env", "client", "DATA_SERVICE", "QUEUE_SERVICE", "FUNCTION_ROUTE_HEADER", "FunctionRouteValue", "invariant", "SpaceId", "log", "EdgeResponse", "wrapHandlerForCloudflare", "func", "request", "env", "headers", "get", "FUNCTION_ROUTE_HEADER", "FunctionRouteValue", "Meta", "log", "info", "handleFunctionMetaCall", "spaceId", "URL", "url", "searchParams", "SpaceId", "isValid", "Response", "status", "serviceContainer", "ServiceContainer", "DATA_SERVICE", "QUEUE_SERVICE", "context", "createFunctionContext", "contextSpaceId", "EdgeResponse", "success", "invokeFunction", "error", "stack", "failure", "message", "data", "decodeRequest", "handler", "bodyText", "rest", "trigger", "json", "JSON", "parse", "err", "catch", "functionDefinition", "response", "key", "meta", "name", "description", "inputSchema", "outputSchema", "stringify", "dataService", "queryService", "queueService", "createServices", "spaceKey", "rootUrl", "getSpaceMeta", "Error", "invariant", "rootDocumentId", "startsWith", "services", "spaceRootUrl"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/internal/data-service-impl.ts":{"bytes":11699,"imports":[{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/internal/adapter.ts":{"bytes":5596,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/internal/query-service-impl.ts":{"bytes":10794,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/internal/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"},"src/internal/queue-service-impl.ts":{"bytes":3509,"imports":[],"format":"esm"},"src/internal/service-container.ts":{"bytes":5889,"imports":[{"path":"src/internal/data-service-impl.ts","kind":"import-statement","original":"./data-service-impl"},{"path":"src/internal/query-service-impl.ts","kind":"import-statement","original":"./query-service-impl"},{"path":"src/internal/queue-service-impl.ts","kind":"import-statement","original":"./queue-service-impl"}],"format":"esm"},"src/internal/index.ts":{"bytes":503,"imports":[{"path":"src/internal/service-container.ts","kind":"import-statement","original":"./service-container"}],"format":"esm"},"src/types.ts":{"bytes":1696,"imports":[],"format":"esm"},"src/wrap-handler-for-cloudflare.ts":{"bytes":15414,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"src/internal/index.ts","kind":"import-statement","original":"./internal"},{"path":"src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/internal/data-service-impl.ts":{"bytes":11699,"imports":[{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/internal/adapter.ts":{"bytes":5596,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/internal/query-service-impl.ts":{"bytes":10794,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/internal/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"},"src/internal/queue-service-impl.ts":{"bytes":3509,"imports":[],"format":"esm"},"src/internal/service-container.ts":{"bytes":5889,"imports":[{"path":"src/internal/data-service-impl.ts","kind":"import-statement","original":"./data-service-impl"},{"path":"src/internal/query-service-impl.ts","kind":"import-statement","original":"./query-service-impl"},{"path":"src/internal/queue-service-impl.ts","kind":"import-statement","original":"./queue-service-impl"}],"format":"esm"},"src/internal/index.ts":{"bytes":503,"imports":[{"path":"src/internal/service-container.ts","kind":"import-statement","original":"./service-container"}],"format":"esm"},"src/queues-api.ts":{"bytes":2953,"imports":[],"format":"esm"},"src/space-proxy.ts":{"bytes":6164,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"src/queues-api.ts","kind":"import-statement","original":"./queues-api"}],"format":"esm"},"src/functions-client.ts":{"bytes":8879,"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/internal/index.ts","kind":"import-statement","original":"./internal"},{"path":"src/space-proxy.ts","kind":"import-statement","original":"./space-proxy"}],"format":"esm"},"src/types.ts":{"bytes":1696,"imports":[],"format":"esm"},"src/wrap-handler-for-cloudflare.ts":{"bytes":15414,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"src/internal/index.ts","kind":"import-statement","original":"./internal"},{"path":"src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"src/index.ts":{"bytes":797,"imports":[{"path":"src/functions-client.ts","kind":"import-statement","original":"./functions-client"},{"path":"src/internal/index.ts","kind":"import-statement","original":"./internal"},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"src/wrap-handler-for-cloudflare.ts","kind":"import-statement","original":"./wrap-handler-for-cloudflare"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":35242},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf/stream","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"exports":["FUNCTION_ROUTE_HEADER","FunctionRouteValue","FunctionsClient","ServiceContainer","createClientFromEnv","wrapHandlerForCloudflare"],"entryPoint":"src/index.ts","inputs":{"src/functions-client.ts":{"bytesInOutput":2084},"src/internal/data-service-impl.ts":{"bytesInOutput":3070},"src/internal/query-service-impl.ts":{"bytesInOutput":2975},"src/internal/adapter.ts":{"bytesInOutput":1609},"src/internal/queue-service-impl.ts":{"bytesInOutput":631},"src/internal/service-container.ts":{"bytesInOutput":970},"src/space-proxy.ts":{"bytesInOutput":1561},"src/queues-api.ts":{"bytesInOutput":414},"src/index.ts":{"bytesInOutput":0},"src/types.ts":{"bytesInOutput":205},"src/wrap-handler-for-cloudflare.ts":{"bytesInOutput":3598}},"bytes":17793}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,+BAA+B,CAAC"}
|