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