@dxos/functions-runtime-cloudflare 0.8.4-main.66e292d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +47 -0
- package/dist/lib/browser/index.mjs +481 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +483 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/functions-client.d.ts +32 -0
- package/dist/types/src/functions-client.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/internal/adapter.d.ts +12 -0
- package/dist/types/src/internal/adapter.d.ts.map +1 -0
- package/dist/types/src/internal/data-service-impl.d.ts +25 -0
- package/dist/types/src/internal/data-service-impl.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +2 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/query-service-impl.d.ts +18 -0
- package/dist/types/src/internal/query-service-impl.d.ts.map +1 -0
- package/dist/types/src/internal/queue-service-impl.d.ts +12 -0
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -0
- package/dist/types/src/internal/service-container.d.ts +25 -0
- package/dist/types/src/internal/service-container.d.ts.map +1 -0
- package/dist/types/src/queues-api.d.ts +22 -0
- package/dist/types/src/queues-api.d.ts.map +1 -0
- package/dist/types/src/space-proxy.d.ts +25 -0
- package/dist/types/src/space-proxy.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +31 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts +6 -0
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -0
- package/src/functions-client.ts +81 -0
- package/src/index.ts +6 -0
- package/src/internal/adapter.ts +48 -0
- package/src/internal/data-service-impl.ts +93 -0
- package/src/internal/index.ts +5 -0
- package/src/internal/query-service-impl.ts +91 -0
- package/src/internal/queue-service-impl.ts +23 -0
- package/src/internal/service-container.ts +54 -0
- package/src/queues-api.ts +38 -0
- package/src/space-proxy.ts +65 -0
- package/src/types.ts +40 -0
- package/src/wrap-handler-for-cloudflare.ts +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @dxos/functions-runtime-cloudflare
|
|
2
|
+
|
|
3
|
+
Functions Runtime for Cloudflare Workers.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a runtime adapter for executing DXOS functions on Cloudflare Workers. It wraps user-defined function code and provides a standardized execution context with access to DXOS services.
|
|
8
|
+
|
|
9
|
+
### Key Responsibilities
|
|
10
|
+
|
|
11
|
+
- **Function Wrapping**: The `wrapHandlerForCloudflare` function wraps user code into a Cloudflare-compatible fetch handler, managing request parsing, error handling, and response formatting.
|
|
12
|
+
- **Service Bridging**: Provides protobuf-based service implementations (`DataService`, `QueryService`, `QueueService`) that bridge the edge environment services to the function context.
|
|
13
|
+
- **Context Creation**: Constructs a `FunctionProtocol.Context` with access to space metadata, document operations, and queue management.
|
|
14
|
+
|
|
15
|
+
### Architecture
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
User Function Code
|
|
19
|
+
↓
|
|
20
|
+
wrapHandlerForCloudflare()
|
|
21
|
+
↓
|
|
22
|
+
ServiceContainer (bridges edge bindings → protobuf services)
|
|
23
|
+
↓
|
|
24
|
+
FunctionProtocol.Context { dataService, queryService, queueService }
|
|
25
|
+
↓
|
|
26
|
+
Cloudflare Worker Ready Function Handler
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The edge environment provides low-level service bindings (`EdgeFunctionEnv.DataService`, `EdgeFunctionEnv.QueueService`). This package adapts those bindings into protobuf-defined service interfaces that user functions can consume uniformly.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm i @dxos/functions-runtime-cloudflare
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## DXOS Resources
|
|
38
|
+
|
|
39
|
+
- [Website](https://dxos.org)
|
|
40
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
41
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
42
|
+
|
|
43
|
+
## Contributions
|
|
44
|
+
|
|
45
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
46
|
+
|
|
47
|
+
License: [MIT](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -0,0 +1,481 @@
|
|
|
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
|
+
// src/internal/data-service-impl.ts
|
|
8
|
+
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
9
|
+
import { raise } from "@dxos/debug";
|
|
10
|
+
import { invariant } from "@dxos/invariant";
|
|
11
|
+
import { SpaceId } from "@dxos/keys";
|
|
12
|
+
import { log } from "@dxos/log";
|
|
13
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
14
|
+
var DataServiceImpl = class {
|
|
15
|
+
_executionContext;
|
|
16
|
+
_dataService;
|
|
17
|
+
dataSubscriptions = /* @__PURE__ */ new Map();
|
|
18
|
+
constructor(_executionContext, _dataService) {
|
|
19
|
+
this._executionContext = _executionContext;
|
|
20
|
+
this._dataService = _dataService;
|
|
21
|
+
}
|
|
22
|
+
subscribe({ subscriptionId, spaceId }) {
|
|
23
|
+
return new Stream(({ next }) => {
|
|
24
|
+
invariant(SpaceId.isValid(spaceId), void 0, {
|
|
25
|
+
F: __dxlog_file,
|
|
26
|
+
L: 34,
|
|
27
|
+
S: this,
|
|
28
|
+
A: [
|
|
29
|
+
"SpaceId.isValid(spaceId)",
|
|
30
|
+
""
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
this.dataSubscriptions.set(subscriptionId, {
|
|
34
|
+
spaceId,
|
|
35
|
+
next
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
this.dataSubscriptions.delete(subscriptionId);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async updateSubscription({ subscriptionId, addIds, removeIds }) {
|
|
43
|
+
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error("Subscription not found"));
|
|
44
|
+
if (addIds) {
|
|
45
|
+
log.info("request documents", {
|
|
46
|
+
count: addIds.length
|
|
47
|
+
}, {
|
|
48
|
+
F: __dxlog_file,
|
|
49
|
+
L: 47,
|
|
50
|
+
S: this,
|
|
51
|
+
C: (f, a) => f(...a)
|
|
52
|
+
});
|
|
53
|
+
for (const documentId of addIds) {
|
|
54
|
+
const document = await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId);
|
|
55
|
+
log.info("document loaded", {
|
|
56
|
+
documentId,
|
|
57
|
+
spaceId: sub.spaceId,
|
|
58
|
+
found: !!document
|
|
59
|
+
}, {
|
|
60
|
+
F: __dxlog_file,
|
|
61
|
+
L: 51,
|
|
62
|
+
S: this,
|
|
63
|
+
C: (f, a) => f(...a)
|
|
64
|
+
});
|
|
65
|
+
if (!document) {
|
|
66
|
+
log.warn("not found", {
|
|
67
|
+
documentId
|
|
68
|
+
}, {
|
|
69
|
+
F: __dxlog_file,
|
|
70
|
+
L: 53,
|
|
71
|
+
S: this,
|
|
72
|
+
C: (f, a) => f(...a)
|
|
73
|
+
});
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
sub.next({
|
|
77
|
+
updates: [
|
|
78
|
+
{
|
|
79
|
+
documentId,
|
|
80
|
+
mutation: document.data
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async update({ updates, subscriptionId }) {
|
|
88
|
+
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new Error("Subscription not found"));
|
|
89
|
+
for (const update of updates ?? []) {
|
|
90
|
+
await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
|
|
91
|
+
}
|
|
92
|
+
throw new Error("Method not implemented.");
|
|
93
|
+
}
|
|
94
|
+
async flush() {
|
|
95
|
+
}
|
|
96
|
+
subscribeSpaceSyncState(request, options) {
|
|
97
|
+
throw new Error("Method not implemented.");
|
|
98
|
+
}
|
|
99
|
+
async getDocumentHeads({ documentIds }) {
|
|
100
|
+
throw new Error("Method not implemented.");
|
|
101
|
+
}
|
|
102
|
+
async reIndexHeads({ documentIds }) {
|
|
103
|
+
throw new Error("Method not implemented.");
|
|
104
|
+
}
|
|
105
|
+
async updateIndexes() {
|
|
106
|
+
throw new Error("Method not implemented.");
|
|
107
|
+
}
|
|
108
|
+
async waitUntilHeadsReplicated({ heads }) {
|
|
109
|
+
throw new Error("Method not implemented.");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/internal/query-service-impl.ts
|
|
114
|
+
import * as Schema from "effect/Schema";
|
|
115
|
+
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
116
|
+
import { QueryAST } from "@dxos/echo-protocol";
|
|
117
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
118
|
+
import { PublicKey } from "@dxos/keys";
|
|
119
|
+
import { SpaceId as SpaceId3 } from "@dxos/keys";
|
|
120
|
+
import { log as log2 } from "@dxos/log";
|
|
121
|
+
|
|
122
|
+
// src/internal/adapter.ts
|
|
123
|
+
import { failUndefined } from "@dxos/debug";
|
|
124
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
125
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
126
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/adapter.ts";
|
|
127
|
+
var queryToDataServiceRequest = (query) => {
|
|
128
|
+
const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();
|
|
129
|
+
invariant2(options?.spaceIds?.length === 1, "Only one space is supported", {
|
|
130
|
+
F: __dxlog_file2,
|
|
131
|
+
L: 13,
|
|
132
|
+
S: void 0,
|
|
133
|
+
A: [
|
|
134
|
+
"options?.spaceIds?.length === 1",
|
|
135
|
+
"'Only one space is supported'"
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
invariant2(filter.type === "object", "Only object filters are supported", {
|
|
139
|
+
F: __dxlog_file2,
|
|
140
|
+
L: 14,
|
|
141
|
+
S: void 0,
|
|
142
|
+
A: [
|
|
143
|
+
"filter.type === 'object'",
|
|
144
|
+
"'Only object filters are supported'"
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
const spaceId = options.spaceIds[0];
|
|
148
|
+
invariant2(SpaceId2.isValid(spaceId), void 0, {
|
|
149
|
+
F: __dxlog_file2,
|
|
150
|
+
L: 17,
|
|
151
|
+
S: void 0,
|
|
152
|
+
A: [
|
|
153
|
+
"SpaceId.isValid(spaceId)",
|
|
154
|
+
""
|
|
155
|
+
]
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
spaceId,
|
|
159
|
+
type: filter.typename ?? void 0,
|
|
160
|
+
objectIds: [
|
|
161
|
+
...filter.id ?? []
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
var isSimpleSelectionQuery = (query) => {
|
|
166
|
+
switch (query.type) {
|
|
167
|
+
case "options": {
|
|
168
|
+
const maybeFilter = isSimpleSelectionQuery(query.query);
|
|
169
|
+
if (!maybeFilter) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
filter: maybeFilter.filter,
|
|
174
|
+
options: query.options
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
case "select": {
|
|
178
|
+
return {
|
|
179
|
+
filter: query.filter,
|
|
180
|
+
options: void 0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
default: {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/internal/query-service-impl.ts
|
|
190
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
191
|
+
var QueryServiceImpl = class {
|
|
192
|
+
_executionContext;
|
|
193
|
+
_dataService;
|
|
194
|
+
constructor(_executionContext, _dataService) {
|
|
195
|
+
this._executionContext = _executionContext;
|
|
196
|
+
this._dataService = _dataService;
|
|
197
|
+
}
|
|
198
|
+
execQuery(request) {
|
|
199
|
+
log2.info("execQuery", {
|
|
200
|
+
request
|
|
201
|
+
}, {
|
|
202
|
+
F: __dxlog_file3,
|
|
203
|
+
L: 30,
|
|
204
|
+
S: this,
|
|
205
|
+
C: (f, a) => f(...a)
|
|
206
|
+
});
|
|
207
|
+
const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));
|
|
208
|
+
const requestedSpaceIds = getTargetSpacesForQuery(query);
|
|
209
|
+
invariant3(requestedSpaceIds.length === 1, "Only one space is supported", {
|
|
210
|
+
F: __dxlog_file3,
|
|
211
|
+
L: 33,
|
|
212
|
+
S: this,
|
|
213
|
+
A: [
|
|
214
|
+
"requestedSpaceIds.length === 1",
|
|
215
|
+
"'Only one space is supported'"
|
|
216
|
+
]
|
|
217
|
+
});
|
|
218
|
+
const spaceId = requestedSpaceIds[0];
|
|
219
|
+
return Stream2.fromPromise((async () => {
|
|
220
|
+
try {
|
|
221
|
+
log2.info("begin query", {
|
|
222
|
+
spaceId
|
|
223
|
+
}, {
|
|
224
|
+
F: __dxlog_file3,
|
|
225
|
+
L: 39,
|
|
226
|
+
S: this,
|
|
227
|
+
C: (f, a) => f(...a)
|
|
228
|
+
});
|
|
229
|
+
const queryResponse = await this._dataService.queryDocuments(this._executionContext, queryToDataServiceRequest(query));
|
|
230
|
+
log2.info("query response", {
|
|
231
|
+
spaceId,
|
|
232
|
+
filter: request.filter,
|
|
233
|
+
resultCount: queryResponse.results.length
|
|
234
|
+
}, {
|
|
235
|
+
F: __dxlog_file3,
|
|
236
|
+
L: 44,
|
|
237
|
+
S: this,
|
|
238
|
+
C: (f, a) => f(...a)
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
results: queryResponse.results.map((object) => ({
|
|
242
|
+
id: object.objectId,
|
|
243
|
+
spaceId,
|
|
244
|
+
spaceKey: PublicKey.ZERO,
|
|
245
|
+
documentId: object.document.documentId,
|
|
246
|
+
rank: 0,
|
|
247
|
+
documentAutomerge: object.document.data
|
|
248
|
+
}))
|
|
249
|
+
};
|
|
250
|
+
} catch (err) {
|
|
251
|
+
log2.error("query failed", {
|
|
252
|
+
err
|
|
253
|
+
}, {
|
|
254
|
+
F: __dxlog_file3,
|
|
255
|
+
L: 58,
|
|
256
|
+
S: this,
|
|
257
|
+
C: (f, a) => f(...a)
|
|
258
|
+
});
|
|
259
|
+
throw err;
|
|
260
|
+
}
|
|
261
|
+
})());
|
|
262
|
+
}
|
|
263
|
+
async reindex() {
|
|
264
|
+
throw new Error("Method not implemented.");
|
|
265
|
+
}
|
|
266
|
+
async setConfig() {
|
|
267
|
+
throw new Error("Method not implemented.");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
var getTargetSpacesForQuery = (query) => {
|
|
271
|
+
const spaces = /* @__PURE__ */ new Set();
|
|
272
|
+
const visitor = (node) => {
|
|
273
|
+
if (node.type === "options") {
|
|
274
|
+
if (node.options.spaceIds) {
|
|
275
|
+
for (const spaceId of node.options.spaceIds) {
|
|
276
|
+
spaces.add(SpaceId3.make(spaceId));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
QueryAST.visit(query, visitor);
|
|
282
|
+
return [
|
|
283
|
+
...spaces
|
|
284
|
+
];
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/internal/queue-service-impl.ts
|
|
288
|
+
var QueueServiceImpl = class {
|
|
289
|
+
_ctx;
|
|
290
|
+
_queueService;
|
|
291
|
+
constructor(_ctx, _queueService) {
|
|
292
|
+
this._ctx = _ctx;
|
|
293
|
+
this._queueService = _queueService;
|
|
294
|
+
}
|
|
295
|
+
queryQueue(subspaceTag, spaceId, { queueId, ...query }) {
|
|
296
|
+
return this._queueService.query(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, query);
|
|
297
|
+
}
|
|
298
|
+
insertIntoQueue(subspaceTag, spaceId, queueId, objects) {
|
|
299
|
+
return this._queueService.append(this._ctx, `dxn:queue:${subspaceTag}:${spaceId}:${queueId}`, objects);
|
|
300
|
+
}
|
|
301
|
+
deleteFromQueue(subspaceTag, spaceId, queueId, objectIds) {
|
|
302
|
+
throw new Error("Deleting from queue is not supported.");
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/internal/service-container.ts
|
|
307
|
+
var ServiceContainer = class {
|
|
308
|
+
_executionContext;
|
|
309
|
+
_dataService;
|
|
310
|
+
_queueService;
|
|
311
|
+
constructor(_executionContext, _dataService, _queueService) {
|
|
312
|
+
this._executionContext = _executionContext;
|
|
313
|
+
this._dataService = _dataService;
|
|
314
|
+
this._queueService = _queueService;
|
|
315
|
+
}
|
|
316
|
+
async getSpaceMeta(spaceId) {
|
|
317
|
+
return this._dataService.getSpaceMeta(this._executionContext, spaceId);
|
|
318
|
+
}
|
|
319
|
+
async createServices() {
|
|
320
|
+
const dataService = new DataServiceImpl(this._executionContext, this._dataService);
|
|
321
|
+
const queryService = new QueryServiceImpl(this._executionContext, this._dataService);
|
|
322
|
+
const queueService = new QueueServiceImpl(this._executionContext, this._queueService);
|
|
323
|
+
return {
|
|
324
|
+
dataService,
|
|
325
|
+
queryService,
|
|
326
|
+
queueService
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
queryQueue(queue) {
|
|
330
|
+
return this._queueService.query({}, queue.toString(), {});
|
|
331
|
+
}
|
|
332
|
+
insertIntoQueue(queue, objects) {
|
|
333
|
+
return this._queueService.append({}, queue.toString(), objects);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/types.ts
|
|
338
|
+
var FUNCTION_ROUTE_HEADER = "X-DXOS-Function-Route";
|
|
339
|
+
var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
340
|
+
FunctionRouteValue2["Meta"] = "meta";
|
|
341
|
+
return FunctionRouteValue2;
|
|
342
|
+
})({});
|
|
343
|
+
|
|
344
|
+
// src/wrap-handler-for-cloudflare.ts
|
|
345
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
346
|
+
var wrapHandlerForCloudflare = (func) => {
|
|
347
|
+
return async (request, env) => {
|
|
348
|
+
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
349
|
+
log3.info(">>> meta", {
|
|
350
|
+
func
|
|
351
|
+
}, {
|
|
352
|
+
F: __dxlog_file4,
|
|
353
|
+
L: 25,
|
|
354
|
+
S: void 0,
|
|
355
|
+
C: (f, a) => f(...a)
|
|
356
|
+
});
|
|
357
|
+
return handleFunctionMetaCall(func, request);
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
361
|
+
if (spaceId) {
|
|
362
|
+
if (!SpaceId4.isValid(spaceId)) {
|
|
363
|
+
return new Response("Invalid spaceId", {
|
|
364
|
+
status: 400
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);
|
|
369
|
+
const context = await createFunctionContext({
|
|
370
|
+
serviceContainer,
|
|
371
|
+
contextSpaceId: spaceId
|
|
372
|
+
});
|
|
373
|
+
return EdgeResponse.success(await invokeFunction(func, context, request));
|
|
374
|
+
} catch (error) {
|
|
375
|
+
log3.error("error invoking function", {
|
|
376
|
+
error,
|
|
377
|
+
stack: error.stack
|
|
378
|
+
}, {
|
|
379
|
+
F: __dxlog_file4,
|
|
380
|
+
L: 45,
|
|
381
|
+
S: void 0,
|
|
382
|
+
C: (f, a) => f(...a)
|
|
383
|
+
});
|
|
384
|
+
return EdgeResponse.failure({
|
|
385
|
+
message: error?.message ?? "Internal error",
|
|
386
|
+
error
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
var invokeFunction = async (func, context, request) => {
|
|
392
|
+
const { data } = await decodeRequest(request);
|
|
393
|
+
return func.handler({
|
|
394
|
+
context,
|
|
395
|
+
data
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
var decodeRequest = async (request) => {
|
|
399
|
+
const { data: { bodyText, ...rest }, trigger } = await request.json();
|
|
400
|
+
if (!bodyText) {
|
|
401
|
+
return {
|
|
402
|
+
data: rest,
|
|
403
|
+
trigger
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
const data = JSON.parse(bodyText);
|
|
408
|
+
return {
|
|
409
|
+
data,
|
|
410
|
+
trigger: {
|
|
411
|
+
...trigger,
|
|
412
|
+
...rest
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
} catch (err) {
|
|
416
|
+
log3.catch(err, void 0, {
|
|
417
|
+
F: __dxlog_file4,
|
|
418
|
+
L: 80,
|
|
419
|
+
S: void 0,
|
|
420
|
+
C: (f, a) => f(...a)
|
|
421
|
+
});
|
|
422
|
+
return {
|
|
423
|
+
data: {
|
|
424
|
+
bodyText,
|
|
425
|
+
...rest
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var handleFunctionMetaCall = (functionDefinition, request) => {
|
|
431
|
+
const response = {
|
|
432
|
+
key: functionDefinition.meta.key,
|
|
433
|
+
name: functionDefinition.meta.name,
|
|
434
|
+
description: functionDefinition.meta.description,
|
|
435
|
+
inputSchema: functionDefinition.meta.inputSchema,
|
|
436
|
+
outputSchema: functionDefinition.meta.outputSchema
|
|
437
|
+
};
|
|
438
|
+
return new Response(JSON.stringify(response), {
|
|
439
|
+
headers: {
|
|
440
|
+
"Content-Type": "application/json"
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
445
|
+
const { dataService, queryService, queueService } = await serviceContainer.createServices();
|
|
446
|
+
let spaceKey;
|
|
447
|
+
let rootUrl;
|
|
448
|
+
if (contextSpaceId) {
|
|
449
|
+
const meta = await serviceContainer.getSpaceMeta(contextSpaceId);
|
|
450
|
+
if (!meta) {
|
|
451
|
+
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
452
|
+
}
|
|
453
|
+
spaceKey = meta.spaceKey;
|
|
454
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, {
|
|
455
|
+
F: __dxlog_file4,
|
|
456
|
+
L: 118,
|
|
457
|
+
S: void 0,
|
|
458
|
+
A: [
|
|
459
|
+
"!meta.rootDocumentId.startsWith('automerge:')",
|
|
460
|
+
""
|
|
461
|
+
]
|
|
462
|
+
});
|
|
463
|
+
rootUrl = `automerge:${meta.rootDocumentId}`;
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
services: {
|
|
467
|
+
dataService,
|
|
468
|
+
queryService,
|
|
469
|
+
queueService
|
|
470
|
+
},
|
|
471
|
+
spaceId: contextSpaceId,
|
|
472
|
+
spaceKey,
|
|
473
|
+
spaceRootUrl: rootUrl
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
export {
|
|
477
|
+
FUNCTION_ROUTE_HEADER,
|
|
478
|
+
FunctionRouteValue,
|
|
479
|
+
wrapHandlerForCloudflare
|
|
480
|
+
};
|
|
481
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/wrap-handler-for-cloudflare.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/types.ts"],
|
|
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,aAAAA,kBAAiB;AAC1B,SAASC,WAAAA,gBAAe;AACxB,SAASC,OAAAA,YAAW;AACpB,SAASC,oBAAoB;;;ACH7B,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,oBAA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B,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": ["invariant", "SpaceId", "log", "EdgeResponse", "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", "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
|
+
}
|
|
@@ -0,0 +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":712,"imports":[{"path":"src/wrap-handler-for-cloudflare.ts","kind":"import-statement","original":"./wrap-handler-for-cloudflare"},{"path":"src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26486},"dist/lib/browser/index.mjs":{"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":"@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}],"exports":["FUNCTION_ROUTE_HEADER","FunctionRouteValue","wrapHandlerForCloudflare"],"entryPoint":"src/index.ts","inputs":{"src/wrap-handler-for-cloudflare.ts":{"bytesInOutput":3598},"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/types.ts":{"bytesInOutput":205},"src/index.ts":{"bytesInOutput":0}},"bytes":13494}}}
|