@dxos/functions-runtime-cloudflare 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660
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 +637 -232
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +637 -232
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/functions-client.d.ts +1 -0
- package/dist/types/src/functions-client.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/data-service-impl.d.ts +8 -7
- package/dist/types/src/internal/data-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/query-service-impl.d.ts +4 -9
- package/dist/types/src/internal/query-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/queue-service-impl.d.ts +8 -9
- package/dist/types/src/internal/queue-service-impl.d.ts.map +1 -1
- package/dist/types/src/internal/service-container.d.ts +8 -8
- package/dist/types/src/internal/service-container.d.ts.map +1 -1
- package/dist/types/src/internal/utils.d.ts +2 -0
- package/dist/types/src/internal/utils.d.ts.map +1 -0
- package/dist/types/src/logger.d.ts +2 -0
- package/dist/types/src/logger.d.ts.map +1 -0
- package/dist/types/src/queues-api.d.ts +6 -6
- package/dist/types/src/queues-api.d.ts.map +1 -1
- package/dist/types/src/space-proxy.d.ts +3 -2
- package/dist/types/src/space-proxy.d.ts.map +1 -1
- package/dist/types/src/wrap-handler-for-cloudflare.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -15
- package/src/functions-client.ts +9 -2
- package/src/index.ts +1 -0
- package/src/internal/data-service-impl.ts +67 -18
- package/src/internal/query-service-impl.ts +23 -61
- package/src/internal/queue-service-impl.ts +54 -11
- package/src/internal/service-container.ts +46 -11
- package/src/internal/utils.ts +5 -0
- package/src/logger.ts +42 -0
- package/src/queues-api.ts +6 -6
- package/src/space-proxy.ts +4 -3
- package/src/wrap-handler-for-cloudflare.ts +3 -3
- package/dist/types/src/internal/adapter.d.ts +0 -12
- package/dist/types/src/internal/adapter.d.ts.map +0 -1
- package/src/internal/adapter.ts +0 -48
|
@@ -1,14 +1,85 @@
|
|
|
1
1
|
// src/functions-client.ts
|
|
2
2
|
import { Resource as Resource2 } from "@dxos/context";
|
|
3
3
|
import { EchoClient } from "@dxos/echo-db";
|
|
4
|
-
import { invariant as
|
|
4
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
5
5
|
|
|
6
6
|
// src/internal/data-service-impl.ts
|
|
7
7
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
8
8
|
import { raise } from "@dxos/debug";
|
|
9
|
+
import { NotImplementedError, RuntimeServiceError } from "@dxos/errors";
|
|
9
10
|
import { invariant } from "@dxos/invariant";
|
|
10
11
|
import { SpaceId } from "@dxos/keys";
|
|
11
12
|
import { log } from "@dxos/log";
|
|
13
|
+
|
|
14
|
+
// src/internal/utils.ts
|
|
15
|
+
var copyUint8Array = (value) => new Uint8Array(value);
|
|
16
|
+
|
|
17
|
+
// src/internal/data-service-impl.ts
|
|
18
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
19
|
+
if (value !== null && value !== void 0) {
|
|
20
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
21
|
+
var dispose, inner;
|
|
22
|
+
if (async) {
|
|
23
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
24
|
+
dispose = value[Symbol.asyncDispose];
|
|
25
|
+
}
|
|
26
|
+
if (dispose === void 0) {
|
|
27
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
28
|
+
dispose = value[Symbol.dispose];
|
|
29
|
+
if (async) inner = dispose;
|
|
30
|
+
}
|
|
31
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
32
|
+
if (inner) dispose = function() {
|
|
33
|
+
try {
|
|
34
|
+
inner.call(this);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return Promise.reject(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
env.stack.push({
|
|
40
|
+
value,
|
|
41
|
+
dispose,
|
|
42
|
+
async
|
|
43
|
+
});
|
|
44
|
+
} else if (async) {
|
|
45
|
+
env.stack.push({
|
|
46
|
+
async: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function _ts_dispose_resources(env) {
|
|
52
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
53
|
+
var e = new Error(message);
|
|
54
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
+
};
|
|
56
|
+
return (_ts_dispose_resources = function _ts_dispose_resources5(env2) {
|
|
57
|
+
function fail(e) {
|
|
58
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
59
|
+
env2.hasError = true;
|
|
60
|
+
}
|
|
61
|
+
var r, s = 0;
|
|
62
|
+
function next() {
|
|
63
|
+
while (r = env2.stack.pop()) {
|
|
64
|
+
try {
|
|
65
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
66
|
+
if (r.dispose) {
|
|
67
|
+
var result = r.dispose.call(r.value);
|
|
68
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
69
|
+
fail(e);
|
|
70
|
+
return next();
|
|
71
|
+
});
|
|
72
|
+
} else s |= 1;
|
|
73
|
+
} catch (e) {
|
|
74
|
+
fail(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
78
|
+
if (env2.hasError) throw env2.error;
|
|
79
|
+
}
|
|
80
|
+
return next();
|
|
81
|
+
})(env);
|
|
82
|
+
}
|
|
12
83
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/data-service-impl.ts";
|
|
13
84
|
var DataServiceImpl = class {
|
|
14
85
|
_executionContext;
|
|
@@ -22,7 +93,7 @@ var DataServiceImpl = class {
|
|
|
22
93
|
return new Stream(({ next }) => {
|
|
23
94
|
invariant(SpaceId.isValid(spaceId), void 0, {
|
|
24
95
|
F: __dxlog_file,
|
|
25
|
-
L:
|
|
96
|
+
L: 39,
|
|
26
97
|
S: this,
|
|
27
98
|
A: [
|
|
28
99
|
"SpaceId.isValid(spaceId)",
|
|
@@ -38,158 +109,218 @@ var DataServiceImpl = class {
|
|
|
38
109
|
};
|
|
39
110
|
});
|
|
40
111
|
}
|
|
41
|
-
async updateSubscription({ subscriptionId, addIds
|
|
42
|
-
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new
|
|
112
|
+
async updateSubscription({ subscriptionId, addIds }) {
|
|
113
|
+
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new RuntimeServiceError({
|
|
114
|
+
message: "Subscription not found.",
|
|
115
|
+
context: {
|
|
116
|
+
subscriptionId
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
43
119
|
if (addIds) {
|
|
44
120
|
log.info("request documents", {
|
|
45
121
|
count: addIds.length
|
|
46
122
|
}, {
|
|
47
123
|
F: __dxlog_file,
|
|
48
|
-
L:
|
|
124
|
+
L: 59,
|
|
49
125
|
S: this,
|
|
50
126
|
C: (f, a) => f(...a)
|
|
51
127
|
});
|
|
52
128
|
for (const documentId of addIds) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!document) {
|
|
65
|
-
log.warn("not found", {
|
|
66
|
-
documentId
|
|
129
|
+
const env = {
|
|
130
|
+
stack: [],
|
|
131
|
+
error: void 0,
|
|
132
|
+
hasError: false
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
const document = _ts_add_disposable_resource(env, await this._dataService.getDocument(this._executionContext, sub.spaceId, documentId), false);
|
|
136
|
+
log.info("document loaded", {
|
|
137
|
+
documentId,
|
|
138
|
+
spaceId: sub.spaceId,
|
|
139
|
+
found: !!document
|
|
67
140
|
}, {
|
|
68
141
|
F: __dxlog_file,
|
|
69
|
-
L:
|
|
142
|
+
L: 63,
|
|
70
143
|
S: this,
|
|
71
144
|
C: (f, a) => f(...a)
|
|
72
145
|
});
|
|
73
|
-
|
|
146
|
+
if (!document) {
|
|
147
|
+
log.warn("not found", {
|
|
148
|
+
documentId
|
|
149
|
+
}, {
|
|
150
|
+
F: __dxlog_file,
|
|
151
|
+
L: 65,
|
|
152
|
+
S: this,
|
|
153
|
+
C: (f, a) => f(...a)
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
sub.next({
|
|
158
|
+
updates: [
|
|
159
|
+
{
|
|
160
|
+
documentId,
|
|
161
|
+
// Copy returned object to avoid hanging RPC stub
|
|
162
|
+
// See https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
163
|
+
mutation: copyUint8Array(document.data)
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
} catch (e) {
|
|
168
|
+
env.error = e;
|
|
169
|
+
env.hasError = true;
|
|
170
|
+
} finally {
|
|
171
|
+
_ts_dispose_resources(env);
|
|
74
172
|
}
|
|
75
|
-
sub.next({
|
|
76
|
-
updates: [
|
|
77
|
-
{
|
|
78
|
-
documentId,
|
|
79
|
-
mutation: document.data
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
});
|
|
83
173
|
}
|
|
84
174
|
}
|
|
85
175
|
}
|
|
176
|
+
async createDocument({ spaceId, initialValue }) {
|
|
177
|
+
const env = {
|
|
178
|
+
stack: [],
|
|
179
|
+
error: void 0,
|
|
180
|
+
hasError: false
|
|
181
|
+
};
|
|
182
|
+
try {
|
|
183
|
+
const response = _ts_add_disposable_resource(env, await this._dataService.createDocument(this._executionContext, {
|
|
184
|
+
spaceId,
|
|
185
|
+
initialValue
|
|
186
|
+
}), false);
|
|
187
|
+
return {
|
|
188
|
+
documentId: response.documentId
|
|
189
|
+
};
|
|
190
|
+
} catch (e) {
|
|
191
|
+
env.error = e;
|
|
192
|
+
env.hasError = true;
|
|
193
|
+
} finally {
|
|
194
|
+
_ts_dispose_resources(env);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
86
197
|
async update({ updates, subscriptionId }) {
|
|
87
|
-
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new
|
|
88
|
-
|
|
89
|
-
|
|
198
|
+
const sub = this.dataSubscriptions.get(subscriptionId) ?? raise(new RuntimeServiceError({
|
|
199
|
+
message: "Subscription not found.",
|
|
200
|
+
context: {
|
|
201
|
+
subscriptionId
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
try {
|
|
205
|
+
for (const update of updates ?? []) {
|
|
206
|
+
await this._dataService.changeDocument(this._executionContext, sub.spaceId, update.documentId, update.mutation);
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
209
|
+
throw RuntimeServiceError.wrap({
|
|
210
|
+
message: "Failed to apply document updates.",
|
|
211
|
+
context: {
|
|
212
|
+
subscriptionId
|
|
213
|
+
},
|
|
214
|
+
ifTypeDiffers: true
|
|
215
|
+
})(error);
|
|
90
216
|
}
|
|
91
|
-
throw new Error("Method not implemented.");
|
|
92
217
|
}
|
|
93
218
|
async flush() {
|
|
94
219
|
}
|
|
95
|
-
subscribeSpaceSyncState(
|
|
96
|
-
throw new
|
|
220
|
+
subscribeSpaceSyncState(_request, _options) {
|
|
221
|
+
throw new NotImplementedError({
|
|
222
|
+
message: "subscribeSpaceSyncState is not implemented."
|
|
223
|
+
});
|
|
97
224
|
}
|
|
98
|
-
async getDocumentHeads({ documentIds }) {
|
|
99
|
-
throw new
|
|
225
|
+
async getDocumentHeads({ documentIds: _documentIds }) {
|
|
226
|
+
throw new NotImplementedError({
|
|
227
|
+
message: "getDocumentHeads is not implemented."
|
|
228
|
+
});
|
|
100
229
|
}
|
|
101
|
-
async reIndexHeads({ documentIds }) {
|
|
102
|
-
throw new
|
|
230
|
+
async reIndexHeads({ documentIds: _documentIds }) {
|
|
231
|
+
throw new NotImplementedError({
|
|
232
|
+
message: "reIndexHeads is not implemented."
|
|
233
|
+
});
|
|
103
234
|
}
|
|
104
235
|
async updateIndexes() {
|
|
105
|
-
|
|
236
|
+
log.error("updateIndexes is not available in EDGE env.", void 0, {
|
|
237
|
+
F: __dxlog_file,
|
|
238
|
+
L: 133,
|
|
239
|
+
S: this,
|
|
240
|
+
C: (f, a) => f(...a)
|
|
241
|
+
});
|
|
106
242
|
}
|
|
107
|
-
async waitUntilHeadsReplicated({ heads }) {
|
|
108
|
-
throw new
|
|
243
|
+
async waitUntilHeadsReplicated({ heads: _heads }) {
|
|
244
|
+
throw new NotImplementedError({
|
|
245
|
+
message: "waitUntilHeadsReplicated is not implemented."
|
|
246
|
+
});
|
|
109
247
|
}
|
|
110
248
|
};
|
|
111
249
|
|
|
112
250
|
// src/internal/query-service-impl.ts
|
|
113
|
-
import * as Schema from "effect/Schema";
|
|
114
251
|
import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
|
|
115
|
-
import {
|
|
116
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
117
|
-
import { PublicKey } from "@dxos/keys";
|
|
118
|
-
import { SpaceId as SpaceId3 } from "@dxos/keys";
|
|
252
|
+
import { NotImplementedError as NotImplementedError2, RuntimeServiceError as RuntimeServiceError2 } from "@dxos/errors";
|
|
119
253
|
import { log as log2 } from "@dxos/log";
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const { filter, options } = isSimpleSelectionQuery(query) ?? failUndefined();
|
|
128
|
-
invariant2(options?.spaceIds?.length === 1, "Only one space is supported", {
|
|
129
|
-
F: __dxlog_file2,
|
|
130
|
-
L: 13,
|
|
131
|
-
S: void 0,
|
|
132
|
-
A: [
|
|
133
|
-
"options?.spaceIds?.length === 1",
|
|
134
|
-
"'Only one space is supported'"
|
|
135
|
-
]
|
|
136
|
-
});
|
|
137
|
-
invariant2(filter.type === "object", "Only object filters are supported", {
|
|
138
|
-
F: __dxlog_file2,
|
|
139
|
-
L: 14,
|
|
140
|
-
S: void 0,
|
|
141
|
-
A: [
|
|
142
|
-
"filter.type === 'object'",
|
|
143
|
-
"'Only object filters are supported'"
|
|
144
|
-
]
|
|
145
|
-
});
|
|
146
|
-
const spaceId = options.spaceIds[0];
|
|
147
|
-
invariant2(SpaceId2.isValid(spaceId), void 0, {
|
|
148
|
-
F: __dxlog_file2,
|
|
149
|
-
L: 17,
|
|
150
|
-
S: void 0,
|
|
151
|
-
A: [
|
|
152
|
-
"SpaceId.isValid(spaceId)",
|
|
153
|
-
""
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
spaceId,
|
|
158
|
-
type: filter.typename ?? void 0,
|
|
159
|
-
objectIds: [
|
|
160
|
-
...filter.id ?? []
|
|
161
|
-
]
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
var isSimpleSelectionQuery = (query) => {
|
|
165
|
-
switch (query.type) {
|
|
166
|
-
case "options": {
|
|
167
|
-
const maybeFilter = isSimpleSelectionQuery(query.query);
|
|
168
|
-
if (!maybeFilter) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
filter: maybeFilter.filter,
|
|
173
|
-
options: query.options
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
case "select": {
|
|
177
|
-
return {
|
|
178
|
-
filter: query.filter,
|
|
179
|
-
options: void 0
|
|
180
|
-
};
|
|
254
|
+
function _ts_add_disposable_resource2(env, value, async) {
|
|
255
|
+
if (value !== null && value !== void 0) {
|
|
256
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
257
|
+
var dispose, inner;
|
|
258
|
+
if (async) {
|
|
259
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
260
|
+
dispose = value[Symbol.asyncDispose];
|
|
181
261
|
}
|
|
182
|
-
|
|
183
|
-
|
|
262
|
+
if (dispose === void 0) {
|
|
263
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
264
|
+
dispose = value[Symbol.dispose];
|
|
265
|
+
if (async) inner = dispose;
|
|
184
266
|
}
|
|
267
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
268
|
+
if (inner) dispose = function() {
|
|
269
|
+
try {
|
|
270
|
+
inner.call(this);
|
|
271
|
+
} catch (e) {
|
|
272
|
+
return Promise.reject(e);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
env.stack.push({
|
|
276
|
+
value,
|
|
277
|
+
dispose,
|
|
278
|
+
async
|
|
279
|
+
});
|
|
280
|
+
} else if (async) {
|
|
281
|
+
env.stack.push({
|
|
282
|
+
async: true
|
|
283
|
+
});
|
|
185
284
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
function _ts_dispose_resources2(env) {
|
|
288
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
289
|
+
var e = new Error(message);
|
|
290
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
291
|
+
};
|
|
292
|
+
return (_ts_dispose_resources2 = function _ts_dispose_resources5(env2) {
|
|
293
|
+
function fail(e) {
|
|
294
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
295
|
+
env2.hasError = true;
|
|
296
|
+
}
|
|
297
|
+
var r, s = 0;
|
|
298
|
+
function next() {
|
|
299
|
+
while (r = env2.stack.pop()) {
|
|
300
|
+
try {
|
|
301
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
302
|
+
if (r.dispose) {
|
|
303
|
+
var result = r.dispose.call(r.value);
|
|
304
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
305
|
+
fail(e);
|
|
306
|
+
return next();
|
|
307
|
+
});
|
|
308
|
+
} else s |= 1;
|
|
309
|
+
} catch (e) {
|
|
310
|
+
fail(e);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
314
|
+
if (env2.hasError) throw env2.error;
|
|
315
|
+
}
|
|
316
|
+
return next();
|
|
317
|
+
})(env);
|
|
318
|
+
}
|
|
319
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/internal/query-service-impl.ts";
|
|
190
320
|
var QueryServiceImpl = class {
|
|
191
321
|
_executionContext;
|
|
192
322
|
_dataService;
|
|
323
|
+
_queryCount = 0;
|
|
193
324
|
constructor(_executionContext, _dataService) {
|
|
194
325
|
this._executionContext = _executionContext;
|
|
195
326
|
this._dataService = _dataService;
|
|
@@ -198,92 +329,142 @@ var QueryServiceImpl = class {
|
|
|
198
329
|
log2.info("execQuery", {
|
|
199
330
|
request
|
|
200
331
|
}, {
|
|
201
|
-
F:
|
|
202
|
-
L:
|
|
332
|
+
F: __dxlog_file2,
|
|
333
|
+
L: 20,
|
|
203
334
|
S: this,
|
|
204
335
|
C: (f, a) => f(...a)
|
|
205
336
|
});
|
|
206
|
-
const query = QueryAST.Query.pipe(Schema.decodeUnknownSync)(JSON.parse(request.query));
|
|
207
|
-
const requestedSpaceIds = getTargetSpacesForQuery(query);
|
|
208
|
-
invariant3(requestedSpaceIds.length === 1, "Only one space is supported", {
|
|
209
|
-
F: __dxlog_file3,
|
|
210
|
-
L: 33,
|
|
211
|
-
S: this,
|
|
212
|
-
A: [
|
|
213
|
-
"requestedSpaceIds.length === 1",
|
|
214
|
-
"'Only one space is supported'"
|
|
215
|
-
]
|
|
216
|
-
});
|
|
217
|
-
const spaceId = requestedSpaceIds[0];
|
|
218
337
|
return Stream2.fromPromise((async () => {
|
|
219
338
|
try {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
L: 39,
|
|
225
|
-
S: this,
|
|
226
|
-
C: (f, a) => f(...a)
|
|
227
|
-
});
|
|
228
|
-
const queryResponse = await this._dataService.queryDocuments(this._executionContext, queryToDataServiceRequest(query));
|
|
229
|
-
log2.info("query response", {
|
|
230
|
-
spaceId,
|
|
231
|
-
filter: request.filter,
|
|
232
|
-
resultCount: queryResponse.results.length
|
|
233
|
-
}, {
|
|
234
|
-
F: __dxlog_file3,
|
|
235
|
-
L: 44,
|
|
236
|
-
S: this,
|
|
237
|
-
C: (f, a) => f(...a)
|
|
238
|
-
});
|
|
239
|
-
return {
|
|
240
|
-
results: queryResponse.results.map((object) => ({
|
|
241
|
-
id: object.objectId,
|
|
242
|
-
spaceId,
|
|
243
|
-
spaceKey: PublicKey.ZERO,
|
|
244
|
-
documentId: object.document.documentId,
|
|
245
|
-
rank: 0,
|
|
246
|
-
documentAutomerge: object.document.data
|
|
247
|
-
}))
|
|
339
|
+
const env = {
|
|
340
|
+
stack: [],
|
|
341
|
+
error: void 0,
|
|
342
|
+
hasError: false
|
|
248
343
|
};
|
|
249
|
-
|
|
344
|
+
try {
|
|
345
|
+
this._queryCount++;
|
|
346
|
+
log2.info("begin query", {
|
|
347
|
+
request
|
|
348
|
+
}, {
|
|
349
|
+
F: __dxlog_file2,
|
|
350
|
+
L: 26,
|
|
351
|
+
S: this,
|
|
352
|
+
C: (f, a) => f(...a)
|
|
353
|
+
});
|
|
354
|
+
const queryResponse = _ts_add_disposable_resource2(env, await this._dataService.execQuery(this._executionContext, request), false);
|
|
355
|
+
log2.info("query response", {
|
|
356
|
+
resultCount: queryResponse.results?.length
|
|
357
|
+
}, {
|
|
358
|
+
F: __dxlog_file2,
|
|
359
|
+
L: 28,
|
|
360
|
+
S: this,
|
|
361
|
+
C: (f, a) => f(...a)
|
|
362
|
+
});
|
|
363
|
+
return structuredClone(queryResponse);
|
|
364
|
+
} catch (e) {
|
|
365
|
+
env.error = e;
|
|
366
|
+
env.hasError = true;
|
|
367
|
+
} finally {
|
|
368
|
+
_ts_dispose_resources2(env);
|
|
369
|
+
}
|
|
370
|
+
} catch (error) {
|
|
250
371
|
log2.error("query failed", {
|
|
251
|
-
err
|
|
372
|
+
err: error
|
|
252
373
|
}, {
|
|
253
|
-
F:
|
|
254
|
-
L:
|
|
374
|
+
F: __dxlog_file2,
|
|
375
|
+
L: 31,
|
|
255
376
|
S: this,
|
|
256
377
|
C: (f, a) => f(...a)
|
|
257
378
|
});
|
|
258
|
-
throw
|
|
379
|
+
throw new RuntimeServiceError2({
|
|
380
|
+
message: `Query execution failed (queryCount=${this._queryCount})`,
|
|
381
|
+
context: {
|
|
382
|
+
queryCount: this._queryCount
|
|
383
|
+
},
|
|
384
|
+
cause: error
|
|
385
|
+
});
|
|
259
386
|
}
|
|
260
387
|
})());
|
|
261
388
|
}
|
|
262
389
|
async reindex() {
|
|
263
|
-
throw new
|
|
390
|
+
throw new NotImplementedError2({
|
|
391
|
+
message: "Reindex is not implemented."
|
|
392
|
+
});
|
|
264
393
|
}
|
|
265
394
|
async setConfig() {
|
|
266
|
-
throw new
|
|
395
|
+
throw new NotImplementedError2({
|
|
396
|
+
message: "SetConfig is not implemented."
|
|
397
|
+
});
|
|
267
398
|
}
|
|
268
399
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
400
|
+
|
|
401
|
+
// src/internal/queue-service-impl.ts
|
|
402
|
+
import { RuntimeServiceError as RuntimeServiceError3 } from "@dxos/errors";
|
|
403
|
+
function _ts_add_disposable_resource3(env, value, async) {
|
|
404
|
+
if (value !== null && value !== void 0) {
|
|
405
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
406
|
+
var dispose, inner;
|
|
407
|
+
if (async) {
|
|
408
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
409
|
+
dispose = value[Symbol.asyncDispose];
|
|
410
|
+
}
|
|
411
|
+
if (dispose === void 0) {
|
|
412
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
413
|
+
dispose = value[Symbol.dispose];
|
|
414
|
+
if (async) inner = dispose;
|
|
415
|
+
}
|
|
416
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
417
|
+
if (inner) dispose = function() {
|
|
418
|
+
try {
|
|
419
|
+
inner.call(this);
|
|
420
|
+
} catch (e) {
|
|
421
|
+
return Promise.reject(e);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
env.stack.push({
|
|
425
|
+
value,
|
|
426
|
+
dispose,
|
|
427
|
+
async
|
|
428
|
+
});
|
|
429
|
+
} else if (async) {
|
|
430
|
+
env.stack.push({
|
|
431
|
+
async: true
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
return value;
|
|
435
|
+
}
|
|
436
|
+
function _ts_dispose_resources3(env) {
|
|
437
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
438
|
+
var e = new Error(message);
|
|
439
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
440
|
+
};
|
|
441
|
+
return (_ts_dispose_resources3 = function _ts_dispose_resources5(env2) {
|
|
442
|
+
function fail(e) {
|
|
443
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
444
|
+
env2.hasError = true;
|
|
445
|
+
}
|
|
446
|
+
var r, s = 0;
|
|
447
|
+
function next() {
|
|
448
|
+
while (r = env2.stack.pop()) {
|
|
449
|
+
try {
|
|
450
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
451
|
+
if (r.dispose) {
|
|
452
|
+
var result = r.dispose.call(r.value);
|
|
453
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
454
|
+
fail(e);
|
|
455
|
+
return next();
|
|
456
|
+
});
|
|
457
|
+
} else s |= 1;
|
|
458
|
+
} catch (e) {
|
|
459
|
+
fail(e);
|
|
276
460
|
}
|
|
277
461
|
}
|
|
462
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
463
|
+
if (env2.hasError) throw env2.error;
|
|
278
464
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
...spaces
|
|
283
|
-
];
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
// src/internal/queue-service-impl.ts
|
|
465
|
+
return next();
|
|
466
|
+
})(env);
|
|
467
|
+
}
|
|
287
468
|
var QueueServiceImpl = class {
|
|
288
469
|
_ctx;
|
|
289
470
|
_queueService;
|
|
@@ -291,29 +472,194 @@ var QueueServiceImpl = class {
|
|
|
291
472
|
this._ctx = _ctx;
|
|
292
473
|
this._queueService = _queueService;
|
|
293
474
|
}
|
|
294
|
-
queryQueue(
|
|
295
|
-
|
|
475
|
+
async queryQueue(request) {
|
|
476
|
+
try {
|
|
477
|
+
const env = {
|
|
478
|
+
stack: [],
|
|
479
|
+
error: void 0,
|
|
480
|
+
hasError: false
|
|
481
|
+
};
|
|
482
|
+
try {
|
|
483
|
+
const result = _ts_add_disposable_resource3(env, await this._queueService.queryQueue(this._ctx, request), false);
|
|
484
|
+
return {
|
|
485
|
+
objects: structuredClone(result.objects),
|
|
486
|
+
nextCursor: result.nextCursor,
|
|
487
|
+
prevCursor: result.prevCursor
|
|
488
|
+
};
|
|
489
|
+
} catch (e) {
|
|
490
|
+
env.error = e;
|
|
491
|
+
env.hasError = true;
|
|
492
|
+
} finally {
|
|
493
|
+
_ts_dispose_resources3(env);
|
|
494
|
+
}
|
|
495
|
+
} catch (error) {
|
|
496
|
+
const { query } = request;
|
|
497
|
+
throw RuntimeServiceError3.wrap({
|
|
498
|
+
message: "Queue query failed.",
|
|
499
|
+
context: {
|
|
500
|
+
subspaceTag: query?.queuesNamespace,
|
|
501
|
+
spaceId: query?.spaceId,
|
|
502
|
+
queueId: query?.queueIds?.[0]
|
|
503
|
+
},
|
|
504
|
+
ifTypeDiffers: true
|
|
505
|
+
})(error);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async insertIntoQueue(request) {
|
|
509
|
+
try {
|
|
510
|
+
const env = {
|
|
511
|
+
stack: [],
|
|
512
|
+
error: void 0,
|
|
513
|
+
hasError: false
|
|
514
|
+
};
|
|
515
|
+
try {
|
|
516
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.insertIntoQueue(this._ctx, request), false);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
env.error = e;
|
|
519
|
+
env.hasError = true;
|
|
520
|
+
} finally {
|
|
521
|
+
_ts_dispose_resources3(env);
|
|
522
|
+
}
|
|
523
|
+
} catch (error) {
|
|
524
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
525
|
+
throw RuntimeServiceError3.wrap({
|
|
526
|
+
message: "Queue append failed.",
|
|
527
|
+
context: {
|
|
528
|
+
subspaceTag,
|
|
529
|
+
spaceId,
|
|
530
|
+
queueId
|
|
531
|
+
},
|
|
532
|
+
ifTypeDiffers: true
|
|
533
|
+
})(error);
|
|
534
|
+
}
|
|
296
535
|
}
|
|
297
|
-
|
|
298
|
-
|
|
536
|
+
async deleteFromQueue(request) {
|
|
537
|
+
try {
|
|
538
|
+
const env = {
|
|
539
|
+
stack: [],
|
|
540
|
+
error: void 0,
|
|
541
|
+
hasError: false
|
|
542
|
+
};
|
|
543
|
+
try {
|
|
544
|
+
const _ = _ts_add_disposable_resource3(env, await this._queueService.deleteFromQueue(this._ctx, request), false);
|
|
545
|
+
} catch (e) {
|
|
546
|
+
env.error = e;
|
|
547
|
+
env.hasError = true;
|
|
548
|
+
} finally {
|
|
549
|
+
_ts_dispose_resources3(env);
|
|
550
|
+
}
|
|
551
|
+
} catch (error) {
|
|
552
|
+
const { subspaceTag, spaceId, queueId } = request;
|
|
553
|
+
throw RuntimeServiceError3.wrap({
|
|
554
|
+
message: "Queue delete failed.",
|
|
555
|
+
context: {
|
|
556
|
+
subspaceTag,
|
|
557
|
+
spaceId,
|
|
558
|
+
queueId
|
|
559
|
+
},
|
|
560
|
+
ifTypeDiffers: true
|
|
561
|
+
})(error);
|
|
562
|
+
}
|
|
299
563
|
}
|
|
300
|
-
|
|
301
|
-
throw new Error("Deleting from queue is not supported.");
|
|
564
|
+
async syncQueue(_) {
|
|
302
565
|
}
|
|
303
566
|
};
|
|
304
567
|
|
|
305
568
|
// src/internal/service-container.ts
|
|
569
|
+
function _ts_add_disposable_resource4(env, value, async) {
|
|
570
|
+
if (value !== null && value !== void 0) {
|
|
571
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
572
|
+
var dispose, inner;
|
|
573
|
+
if (async) {
|
|
574
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
575
|
+
dispose = value[Symbol.asyncDispose];
|
|
576
|
+
}
|
|
577
|
+
if (dispose === void 0) {
|
|
578
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
579
|
+
dispose = value[Symbol.dispose];
|
|
580
|
+
if (async) inner = dispose;
|
|
581
|
+
}
|
|
582
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
583
|
+
if (inner) dispose = function() {
|
|
584
|
+
try {
|
|
585
|
+
inner.call(this);
|
|
586
|
+
} catch (e) {
|
|
587
|
+
return Promise.reject(e);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
env.stack.push({
|
|
591
|
+
value,
|
|
592
|
+
dispose,
|
|
593
|
+
async
|
|
594
|
+
});
|
|
595
|
+
} else if (async) {
|
|
596
|
+
env.stack.push({
|
|
597
|
+
async: true
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
602
|
+
function _ts_dispose_resources4(env) {
|
|
603
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
604
|
+
var e = new Error(message);
|
|
605
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
606
|
+
};
|
|
607
|
+
return (_ts_dispose_resources4 = function _ts_dispose_resources5(env2) {
|
|
608
|
+
function fail(e) {
|
|
609
|
+
env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
|
|
610
|
+
env2.hasError = true;
|
|
611
|
+
}
|
|
612
|
+
var r, s = 0;
|
|
613
|
+
function next() {
|
|
614
|
+
while (r = env2.stack.pop()) {
|
|
615
|
+
try {
|
|
616
|
+
if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
|
|
617
|
+
if (r.dispose) {
|
|
618
|
+
var result = r.dispose.call(r.value);
|
|
619
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
620
|
+
fail(e);
|
|
621
|
+
return next();
|
|
622
|
+
});
|
|
623
|
+
} else s |= 1;
|
|
624
|
+
} catch (e) {
|
|
625
|
+
fail(e);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
|
|
629
|
+
if (env2.hasError) throw env2.error;
|
|
630
|
+
}
|
|
631
|
+
return next();
|
|
632
|
+
})(env);
|
|
633
|
+
}
|
|
306
634
|
var ServiceContainer = class {
|
|
307
635
|
_executionContext;
|
|
308
636
|
_dataService;
|
|
309
637
|
_queueService;
|
|
310
|
-
|
|
638
|
+
_functionsService;
|
|
639
|
+
constructor(_executionContext, _dataService, _queueService, _functionsService) {
|
|
311
640
|
this._executionContext = _executionContext;
|
|
312
641
|
this._dataService = _dataService;
|
|
313
642
|
this._queueService = _queueService;
|
|
643
|
+
this._functionsService = _functionsService;
|
|
314
644
|
}
|
|
315
645
|
async getSpaceMeta(spaceId) {
|
|
316
|
-
|
|
646
|
+
const env = {
|
|
647
|
+
stack: [],
|
|
648
|
+
error: void 0,
|
|
649
|
+
hasError: false
|
|
650
|
+
};
|
|
651
|
+
try {
|
|
652
|
+
const result = _ts_add_disposable_resource4(env, await this._dataService.getSpaceMeta(this._executionContext, spaceId), false);
|
|
653
|
+
return result ? {
|
|
654
|
+
spaceKey: result.spaceKey,
|
|
655
|
+
rootDocumentId: result.rootDocumentId
|
|
656
|
+
} : void 0;
|
|
657
|
+
} catch (e) {
|
|
658
|
+
env.error = e;
|
|
659
|
+
env.hasError = true;
|
|
660
|
+
} finally {
|
|
661
|
+
_ts_dispose_resources4(env);
|
|
662
|
+
}
|
|
317
663
|
}
|
|
318
664
|
async createServices() {
|
|
319
665
|
const dataService = new DataServiceImpl(this._executionContext, this._dataService);
|
|
@@ -322,21 +668,50 @@ var ServiceContainer = class {
|
|
|
322
668
|
return {
|
|
323
669
|
dataService,
|
|
324
670
|
queryService,
|
|
325
|
-
queueService
|
|
671
|
+
queueService,
|
|
672
|
+
functionsAiService: this._functionsService
|
|
326
673
|
};
|
|
327
674
|
}
|
|
328
|
-
queryQueue(queue) {
|
|
329
|
-
|
|
675
|
+
async queryQueue(queue) {
|
|
676
|
+
const parts = queue.asQueueDXN();
|
|
677
|
+
if (!parts) {
|
|
678
|
+
throw new Error("Invalid queue DXN");
|
|
679
|
+
}
|
|
680
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
681
|
+
const result = await this._queueService.queryQueue(this._executionContext, {
|
|
682
|
+
query: {
|
|
683
|
+
spaceId,
|
|
684
|
+
queuesNamespace: subspaceTag,
|
|
685
|
+
queueIds: [
|
|
686
|
+
queueId
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
return {
|
|
691
|
+
objects: structuredClone(result.objects),
|
|
692
|
+
nextCursor: result.nextCursor ?? null,
|
|
693
|
+
prevCursor: result.prevCursor ?? null
|
|
694
|
+
};
|
|
330
695
|
}
|
|
331
|
-
insertIntoQueue(queue, objects) {
|
|
332
|
-
|
|
696
|
+
async insertIntoQueue(queue, objects) {
|
|
697
|
+
const parts = queue.asQueueDXN();
|
|
698
|
+
if (!parts) {
|
|
699
|
+
throw new Error("Invalid queue DXN");
|
|
700
|
+
}
|
|
701
|
+
const { subspaceTag, spaceId, queueId } = parts;
|
|
702
|
+
await this._queueService.insertIntoQueue(this._executionContext, {
|
|
703
|
+
subspaceTag,
|
|
704
|
+
spaceId,
|
|
705
|
+
queueId,
|
|
706
|
+
objects
|
|
707
|
+
});
|
|
333
708
|
}
|
|
334
709
|
};
|
|
335
710
|
|
|
336
711
|
// src/space-proxy.ts
|
|
337
712
|
import { Resource } from "@dxos/context";
|
|
338
|
-
import { invariant as
|
|
339
|
-
import { PublicKey
|
|
713
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
714
|
+
import { PublicKey } from "@dxos/keys";
|
|
340
715
|
|
|
341
716
|
// src/queues-api.ts
|
|
342
717
|
var QueuesAPIImpl = class {
|
|
@@ -355,7 +730,7 @@ var QueuesAPIImpl = class {
|
|
|
355
730
|
};
|
|
356
731
|
|
|
357
732
|
// src/space-proxy.ts
|
|
358
|
-
var
|
|
733
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/space-proxy.ts";
|
|
359
734
|
var SpaceProxy = class extends Resource {
|
|
360
735
|
_serviceContainer;
|
|
361
736
|
_echoClient;
|
|
@@ -370,9 +745,9 @@ var SpaceProxy = class extends Resource {
|
|
|
370
745
|
return this._id;
|
|
371
746
|
}
|
|
372
747
|
get db() {
|
|
373
|
-
|
|
374
|
-
F:
|
|
375
|
-
L:
|
|
748
|
+
invariant2(this._db, void 0, {
|
|
749
|
+
F: __dxlog_file3,
|
|
750
|
+
L: 35,
|
|
376
751
|
S: this,
|
|
377
752
|
A: [
|
|
378
753
|
"this._db",
|
|
@@ -385,9 +760,9 @@ var SpaceProxy = class extends Resource {
|
|
|
385
760
|
* @deprecated Use db API.
|
|
386
761
|
*/
|
|
387
762
|
get crud() {
|
|
388
|
-
|
|
389
|
-
F:
|
|
390
|
-
L:
|
|
763
|
+
invariant2(this._db, void 0, {
|
|
764
|
+
F: __dxlog_file3,
|
|
765
|
+
L: 43,
|
|
391
766
|
S: this,
|
|
392
767
|
A: [
|
|
393
768
|
"this._db",
|
|
@@ -406,7 +781,7 @@ var SpaceProxy = class extends Resource {
|
|
|
406
781
|
}
|
|
407
782
|
this._db = this._echoClient.constructDatabase({
|
|
408
783
|
spaceId: this._id,
|
|
409
|
-
spaceKey:
|
|
784
|
+
spaceKey: PublicKey.from(meta.spaceKey),
|
|
410
785
|
reactiveSchemaQuery: false,
|
|
411
786
|
owningObject: this
|
|
412
787
|
});
|
|
@@ -417,7 +792,7 @@ var SpaceProxy = class extends Resource {
|
|
|
417
792
|
};
|
|
418
793
|
|
|
419
794
|
// src/functions-client.ts
|
|
420
|
-
var
|
|
795
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/functions-client.ts";
|
|
421
796
|
var FunctionsClient = class extends Resource2 {
|
|
422
797
|
_serviceContainer;
|
|
423
798
|
_echoClient;
|
|
@@ -425,25 +800,25 @@ var FunctionsClient = class extends Resource2 {
|
|
|
425
800
|
_spaces = /* @__PURE__ */ new Map();
|
|
426
801
|
constructor(services) {
|
|
427
802
|
super();
|
|
428
|
-
|
|
429
|
-
F:
|
|
430
|
-
L:
|
|
803
|
+
invariant3(typeof services.dataService !== "undefined", "DataService is required", {
|
|
804
|
+
F: __dxlog_file4,
|
|
805
|
+
L: 33,
|
|
431
806
|
S: this,
|
|
432
807
|
A: [
|
|
433
808
|
"typeof services.dataService !== 'undefined'",
|
|
434
809
|
"'DataService is required'"
|
|
435
810
|
]
|
|
436
811
|
});
|
|
437
|
-
|
|
438
|
-
F:
|
|
439
|
-
L:
|
|
812
|
+
invariant3(typeof services.queueService !== "undefined", "QueueService is required", {
|
|
813
|
+
F: __dxlog_file4,
|
|
814
|
+
L: 34,
|
|
440
815
|
S: this,
|
|
441
816
|
A: [
|
|
442
817
|
"typeof services.queueService !== 'undefined'",
|
|
443
818
|
"'QueueService is required'"
|
|
444
819
|
]
|
|
445
820
|
});
|
|
446
|
-
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService);
|
|
821
|
+
this._serviceContainer = new ServiceContainer(this._executionContext, services.dataService, services.queueService, services.functionsAiService);
|
|
447
822
|
this._echoClient = new EchoClient({});
|
|
448
823
|
}
|
|
449
824
|
get echo() {
|
|
@@ -477,7 +852,8 @@ var FunctionsClient = class extends Resource2 {
|
|
|
477
852
|
var createClientFromEnv = async (env) => {
|
|
478
853
|
const client = new FunctionsClient({
|
|
479
854
|
dataService: env.DATA_SERVICE,
|
|
480
|
-
queueService: env.QUEUE_SERVICE
|
|
855
|
+
queueService: env.QUEUE_SERVICE,
|
|
856
|
+
functionsAiService: env.FUNCTIONS_AI_SERVICE
|
|
481
857
|
});
|
|
482
858
|
await client.open();
|
|
483
859
|
return client;
|
|
@@ -491,34 +867,26 @@ var FunctionRouteValue = /* @__PURE__ */ (function(FunctionRouteValue2) {
|
|
|
491
867
|
})({});
|
|
492
868
|
|
|
493
869
|
// src/wrap-handler-for-cloudflare.ts
|
|
494
|
-
import { invariant as
|
|
495
|
-
import { SpaceId as
|
|
870
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
871
|
+
import { SpaceId as SpaceId2 } from "@dxos/keys";
|
|
496
872
|
import { log as log3 } from "@dxos/log";
|
|
497
873
|
import { EdgeResponse } from "@dxos/protocols";
|
|
498
|
-
var
|
|
874
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/functions-runtime-cloudflare/src/wrap-handler-for-cloudflare.ts";
|
|
499
875
|
var wrapHandlerForCloudflare = (func) => {
|
|
500
876
|
return async (request, env) => {
|
|
501
877
|
if (request.headers.get(FUNCTION_ROUTE_HEADER) === FunctionRouteValue.Meta) {
|
|
502
|
-
log3.info(">>> meta", {
|
|
503
|
-
func
|
|
504
|
-
}, {
|
|
505
|
-
F: __dxlog_file6,
|
|
506
|
-
L: 25,
|
|
507
|
-
S: void 0,
|
|
508
|
-
C: (f, a) => f(...a)
|
|
509
|
-
});
|
|
510
878
|
return handleFunctionMetaCall(func, request);
|
|
511
879
|
}
|
|
512
880
|
try {
|
|
513
881
|
const spaceId = new URL(request.url).searchParams.get("spaceId");
|
|
514
882
|
if (spaceId) {
|
|
515
|
-
if (!
|
|
883
|
+
if (!SpaceId2.isValid(spaceId)) {
|
|
516
884
|
return new Response("Invalid spaceId", {
|
|
517
885
|
status: 400
|
|
518
886
|
});
|
|
519
887
|
}
|
|
520
888
|
}
|
|
521
|
-
const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE);
|
|
889
|
+
const serviceContainer = new ServiceContainer({}, env.DATA_SERVICE, env.QUEUE_SERVICE, env.FUNCTIONS_AI_SERVICE);
|
|
522
890
|
const context = await createFunctionContext({
|
|
523
891
|
serviceContainer,
|
|
524
892
|
contextSpaceId: spaceId
|
|
@@ -529,8 +897,8 @@ var wrapHandlerForCloudflare = (func) => {
|
|
|
529
897
|
error,
|
|
530
898
|
stack: error.stack
|
|
531
899
|
}, {
|
|
532
|
-
F:
|
|
533
|
-
L:
|
|
900
|
+
F: __dxlog_file5,
|
|
901
|
+
L: 44,
|
|
534
902
|
S: void 0,
|
|
535
903
|
C: (f, a) => f(...a)
|
|
536
904
|
});
|
|
@@ -567,8 +935,8 @@ var decodeRequest = async (request) => {
|
|
|
567
935
|
};
|
|
568
936
|
} catch (err) {
|
|
569
937
|
log3.catch(err, void 0, {
|
|
570
|
-
F:
|
|
571
|
-
L:
|
|
938
|
+
F: __dxlog_file5,
|
|
939
|
+
L: 79,
|
|
572
940
|
S: void 0,
|
|
573
941
|
C: (f, a) => f(...a)
|
|
574
942
|
});
|
|
@@ -595,7 +963,7 @@ var handleFunctionMetaCall = (functionDefinition, request) => {
|
|
|
595
963
|
});
|
|
596
964
|
};
|
|
597
965
|
var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
598
|
-
const { dataService, queryService, queueService } = await serviceContainer.createServices();
|
|
966
|
+
const { dataService, queryService, queueService, functionsAiService } = await serviceContainer.createServices();
|
|
599
967
|
let spaceKey;
|
|
600
968
|
let rootUrl;
|
|
601
969
|
if (contextSpaceId) {
|
|
@@ -604,9 +972,9 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
604
972
|
throw new Error(`Space not found: ${contextSpaceId}`);
|
|
605
973
|
}
|
|
606
974
|
spaceKey = meta.spaceKey;
|
|
607
|
-
|
|
608
|
-
F:
|
|
609
|
-
L:
|
|
975
|
+
invariant4(!meta.rootDocumentId.startsWith("automerge:"), void 0, {
|
|
976
|
+
F: __dxlog_file5,
|
|
977
|
+
L: 117,
|
|
610
978
|
S: void 0,
|
|
611
979
|
A: [
|
|
612
980
|
"!meta.rootDocumentId.startsWith('automerge:')",
|
|
@@ -619,19 +987,56 @@ var createFunctionContext = async ({ serviceContainer, contextSpaceId }) => {
|
|
|
619
987
|
services: {
|
|
620
988
|
dataService,
|
|
621
989
|
queryService,
|
|
622
|
-
queueService
|
|
990
|
+
queueService,
|
|
991
|
+
functionsAiService
|
|
623
992
|
},
|
|
624
993
|
spaceId: contextSpaceId,
|
|
625
994
|
spaceKey,
|
|
626
995
|
spaceRootUrl: rootUrl
|
|
627
996
|
};
|
|
628
997
|
};
|
|
998
|
+
|
|
999
|
+
// src/logger.ts
|
|
1000
|
+
import { LogLevel, log as log4, shouldLog } from "@dxos/log";
|
|
1001
|
+
var setupFunctionsLogger = () => {
|
|
1002
|
+
log4.runtimeConfig.processors.length = 0;
|
|
1003
|
+
log4.runtimeConfig.processors.push(functionLogProcessor);
|
|
1004
|
+
};
|
|
1005
|
+
var functionLogProcessor = (config, entry) => {
|
|
1006
|
+
if (!shouldLog(entry, config.filters)) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
switch (entry.level) {
|
|
1010
|
+
case LogLevel.DEBUG:
|
|
1011
|
+
console.debug(entry.message, entry.context);
|
|
1012
|
+
break;
|
|
1013
|
+
case LogLevel.TRACE:
|
|
1014
|
+
console.debug(entry.message, entry.context);
|
|
1015
|
+
break;
|
|
1016
|
+
case LogLevel.VERBOSE:
|
|
1017
|
+
console.log(entry.message, entry.context);
|
|
1018
|
+
break;
|
|
1019
|
+
case LogLevel.INFO:
|
|
1020
|
+
console.info(entry.message, entry.context);
|
|
1021
|
+
break;
|
|
1022
|
+
case LogLevel.WARN:
|
|
1023
|
+
console.warn(entry.message, entry.context);
|
|
1024
|
+
break;
|
|
1025
|
+
case LogLevel.ERROR:
|
|
1026
|
+
console.error(entry.message, entry.context);
|
|
1027
|
+
break;
|
|
1028
|
+
default:
|
|
1029
|
+
console.log(entry.message, entry.context);
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
629
1033
|
export {
|
|
630
1034
|
FUNCTION_ROUTE_HEADER,
|
|
631
1035
|
FunctionRouteValue,
|
|
632
1036
|
FunctionsClient,
|
|
633
1037
|
ServiceContainer,
|
|
634
1038
|
createClientFromEnv,
|
|
1039
|
+
setupFunctionsLogger,
|
|
635
1040
|
wrapHandlerForCloudflare
|
|
636
1041
|
};
|
|
637
1042
|
//# sourceMappingURL=index.mjs.map
|