@dxos/functions-runtime-cloudflare 0.8.4-main.66e292d → 0.8.4-main.70d3990
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 +5 -6
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +5 -6
- 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 +2 -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 +2 -1
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
// src/wrap-handler-for-cloudflare.ts
|
|
2
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
3
|
-
import { SpaceId as SpaceId4 } from "@dxos/keys";
|
|
4
|
-
import { log as log3 } from "@dxos/log";
|
|
5
|
-
import { EdgeResponse } from "@dxos/protocols";
|
|
6
|
-
|
|
7
1
|
// src/internal/data-service-impl.ts
|
|
8
2
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
9
3
|
import { raise } from "@dxos/debug";
|
|
@@ -342,6 +336,10 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
342
336
|
})({});
|
|
343
337
|
|
|
344
338
|
// src/wrap-handler-for-cloudflare.ts
|
|
339
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
340
|
+
import { SpaceId as SpaceId4 } from "@dxos/keys";
|
|
341
|
+
import { log as log3 } from "@dxos/log";
|
|
342
|
+
import { EdgeResponse } from "@dxos/protocols";
|
|
345
343
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
346
344
|
var wrapHandlerForCloudflare = (func) => {
|
|
347
345
|
return async (request, env) => {
|
|
@@ -476,6 +474,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
476
474
|
export {
|
|
477
475
|
FUNCTION_ROUTE_HEADER,
|
|
478
476
|
FunctionRouteValue,
|
|
477
|
+
ServiceContainer,
|
|
479
478
|
wrapHandlerForCloudflare
|
|
480
479
|
};
|
|
481
480
|
//# 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": ";AAKA,SAASA,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../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/types.ts", "../../../src/wrap-handler-for-cloudflare.ts"],
|
|
4
|
+
"sourcesContent": ["//\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", "//\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": ";AAKA,SAASA,cAAc;AACvB,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,WAAW;;AAcb,IAAMC,kBAAN,MAAMA;;;EACHC,oBAAoB,oBAAIC,IAAAA;EA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AAmBG,KAAKI;EACxC;AAEA,SAAO,IAAIlC,SAASuB,KAAKY,UAAUP,QAAAA,GAAW;IAC5C1C,SAAS;MACP,gBAAgB;IAClB;EACF,CAAA;AACF;AAEA,IAAMqB,wBAAwB,OAAO,EACnCL,kBACAM,eAAc,MAIf;AACC,QAAM,EAAE4B,aAAaC,cAAcC,aAAY,IAAK,MAAMpC,iBAAiBqC,eAAc;AAEzF,MAAIC;AACJ,MAAIC;AACJ,MAAIjC,gBAAgB;AAClB,UAAMsB,OAAO,MAAM5B,iBAAiBwC,aAAalC,cAAAA;AACjD,QAAI,CAACsB,MAAM;AACT,YAAM,IAAIa,MAAM,oBAAoBnC,cAAAA,EAAgB;IACtD;AACAgC,eAAWV,KAAKU;AAChBI,IAAAA,WAAU,CAACd,KAAKe,eAAeC,WAAW,YAAA,GAAA,QAAA;;;;;;;;;AAC1CL,cAAU,aAAaX,KAAKe,cAAc;EAC5C;AAEA,SAAO;IACLE,UAAU;MACRX;MACAC;MACAC;IACF;IACA5C,SAASc;IACTgC;IACAQ,cAAcP;EAChB;AACF;",
|
|
6
|
+
"names": ["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", "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/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":685,"imports":[{"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/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26484},"dist/lib/browser/index.mjs":{"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},{"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/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","ServiceContainer","wrapHandlerForCloudflare"],"entryPoint":"src/index.ts","inputs":{"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/index.ts":{"bytesInOutput":0},"src/types.ts":{"bytesInOutput":205},"src/wrap-handler-for-cloudflare.ts":{"bytesInOutput":3598}},"bytes":13475}}}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
-
// src/wrap-handler-for-cloudflare.ts
|
|
4
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
5
|
-
import { SpaceId as SpaceId4 } from "@dxos/keys";
|
|
6
|
-
import { log as log3 } from "@dxos/log";
|
|
7
|
-
import { EdgeResponse } from "@dxos/protocols";
|
|
8
|
-
|
|
9
3
|
// src/internal/data-service-impl.ts
|
|
10
4
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
11
5
|
import { raise } from "@dxos/debug";
|
|
@@ -344,6 +338,10 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
344
338
|
})({});
|
|
345
339
|
|
|
346
340
|
// src/wrap-handler-for-cloudflare.ts
|
|
341
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
342
|
+
import { SpaceId as SpaceId4 } from "@dxos/keys";
|
|
343
|
+
import { log as log3 } from "@dxos/log";
|
|
344
|
+
import { EdgeResponse } from "@dxos/protocols";
|
|
347
345
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
348
346
|
var wrapHandlerForCloudflare = (func) => {
|
|
349
347
|
return async (request, env) => {
|
|
@@ -478,6 +476,7 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
478
476
|
export {
|
|
479
477
|
FUNCTION_ROUTE_HEADER,
|
|
480
478
|
FunctionRouteValue,
|
|
479
|
+
ServiceContainer,
|
|
481
480
|
wrapHandlerForCloudflare
|
|
482
481
|
};
|
|
483
482
|
//# 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": ";;;AAKA,SAASA,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../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/types.ts", "../../../src/wrap-handler-for-cloudflare.ts"],
|
|
4
|
+
"sourcesContent": ["//\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", "//\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": ";;;AAKA,SAASA,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,aA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AIjC,gBAAgB;AAClB,UAAMsB,OAAO,MAAM5B,iBAAiBwC,aAAalC,cAAAA;AACjD,QAAI,CAACsB,MAAM;AACT,YAAM,IAAIa,MAAM,oBAAoBnC,cAAAA,EAAgB;IACtD;AACAgC,eAAWV,KAAKU;AAChBI,IAAAA,WAAU,CAACd,KAAKe,eAAeC,WAAW,YAAA,GAAA,QAAA;;;;;;;;;AAC1CL,cAAU,aAAaX,KAAKe,cAAc;EAC5C;AAEA,SAAO;IACLE,UAAU;MACRX;MACAC;MACAC;IACF;IACA5C,SAASc;IACTgC;IACAQ,cAAcP;EAChB;AACF;",
|
|
6
|
+
"names": ["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", "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/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":685,"imports":[{"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":26486},"dist/lib/node-esm/index.mjs":{"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},{"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/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","ServiceContainer","wrapHandlerForCloudflare"],"entryPoint":"src/index.ts","inputs":{"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/index.ts":{"bytesInOutput":0},"src/types.ts":{"bytesInOutput":205},"src/wrap-handler-for-cloudflare.ts":{"bytesInOutput":3598}},"bytes":13568}}}
|
|
@@ -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,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,+BAA+B,CAAC"}
|