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