@dxos/functions 0.3.7 → 0.3.8-main.0ae9c21
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/README.md +2 -2
- package/dist/lib/browser/index.mjs +112 -61
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +127 -75
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/{function.d.ts → handler.d.ts} +8 -23
- package/dist/types/src/handler.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/manifest.d.ts +24 -0
- package/dist/types/src/manifest.d.ts.map +1 -0
- package/dist/types/src/runtime/dev-server.d.ts +11 -5
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/trigger-manager.d.ts +4 -5
- package/dist/types/src/runtime/trigger-manager.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/handler.ts +29 -0
- package/src/index.ts +2 -1
- package/src/manifest.ts +36 -0
- package/src/runtime/dev-server.ts +50 -32
- package/src/runtime/trigger-manager.ts +9 -10
- package/dist/types/src/function.d.ts.map +0 -1
- package/src/function.ts +0 -51
package/dist/lib/node/index.cjs
CHANGED
|
@@ -26,23 +26,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
33
31
|
DevServer: () => DevServer,
|
|
34
32
|
TriggerManager: () => TriggerManager
|
|
35
33
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
37
|
-
|
|
38
|
-
// packages/core/functions/src/runtime/dev-server.ts
|
|
34
|
+
module.exports = __toCommonJS(node_exports);
|
|
39
35
|
var import_express = __toESM(require("express"));
|
|
36
|
+
var import_get_port_please = require("get-port-please");
|
|
40
37
|
var import_node_path = require("node:path");
|
|
41
|
-
var import_portfinder = require("portfinder");
|
|
42
38
|
var import_async = require("@dxos/async");
|
|
39
|
+
var import_invariant = require("@dxos/invariant");
|
|
43
40
|
var import_log = require("@dxos/log");
|
|
44
|
-
var
|
|
45
|
-
var
|
|
41
|
+
var import_async2 = require("@dxos/async");
|
|
42
|
+
var import_context = require("@dxos/context");
|
|
43
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
44
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
45
|
+
var import_log2 = require("@dxos/log");
|
|
46
|
+
var import_util = require("@dxos/util");
|
|
47
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
48
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
49
|
+
}) : x)(function(x) {
|
|
50
|
+
if (typeof require !== "undefined")
|
|
51
|
+
return require.apply(this, arguments);
|
|
52
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
53
|
+
});
|
|
54
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/dev-server.ts";
|
|
46
55
|
var DevServer = class {
|
|
47
56
|
// prettier-ignore
|
|
48
57
|
constructor(_client, _options) {
|
|
@@ -50,28 +59,49 @@ var DevServer = class {
|
|
|
50
59
|
this._options = _options;
|
|
51
60
|
this._handlers = {};
|
|
52
61
|
}
|
|
53
|
-
get port() {
|
|
54
|
-
return this._port;
|
|
55
|
-
}
|
|
56
62
|
get endpoint() {
|
|
57
|
-
|
|
63
|
+
(0, import_invariant.invariant)(this._port, void 0, {
|
|
64
|
+
F: __dxlog_file,
|
|
65
|
+
L: 43,
|
|
66
|
+
S: this,
|
|
67
|
+
A: [
|
|
68
|
+
"this._port",
|
|
69
|
+
""
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
return `http://localhost:${this._port}`;
|
|
73
|
+
}
|
|
74
|
+
get proxy() {
|
|
75
|
+
return this._proxy;
|
|
58
76
|
}
|
|
59
77
|
get functions() {
|
|
60
|
-
return Object.
|
|
78
|
+
return Object.values(this._handlers);
|
|
61
79
|
}
|
|
62
80
|
async initialize() {
|
|
63
|
-
for (const
|
|
81
|
+
for (const def of this._options.manifest.functions) {
|
|
82
|
+
const { id, path, handler: dir } = def;
|
|
64
83
|
try {
|
|
65
|
-
const module2 =
|
|
84
|
+
const module2 = __require((0, import_node_path.join)(this._options.directory, dir));
|
|
66
85
|
const handler = module2.default;
|
|
67
86
|
if (typeof handler !== "function") {
|
|
68
87
|
throw new Error(`Handler must export default function: ${id}`);
|
|
69
88
|
}
|
|
70
|
-
this._handlers[
|
|
89
|
+
if (this._handlers[path]) {
|
|
90
|
+
import_log.log.warn(`Function already registered: ${id}`, void 0, {
|
|
91
|
+
F: __dxlog_file,
|
|
92
|
+
L: 67,
|
|
93
|
+
S: this,
|
|
94
|
+
C: (f, a) => f(...a)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
this._handlers[path] = {
|
|
98
|
+
def,
|
|
99
|
+
handler
|
|
100
|
+
};
|
|
71
101
|
} catch (err) {
|
|
72
|
-
import_log.log.error("parsing function (check
|
|
102
|
+
import_log.log.error("parsing function (check manifest)", err, {
|
|
73
103
|
F: __dxlog_file,
|
|
74
|
-
L:
|
|
104
|
+
L: 72,
|
|
75
105
|
S: this,
|
|
76
106
|
C: (f, a) => f(...a)
|
|
77
107
|
});
|
|
@@ -81,36 +111,42 @@ var DevServer = class {
|
|
|
81
111
|
async start() {
|
|
82
112
|
const app = (0, import_express.default)();
|
|
83
113
|
app.use(import_express.default.json());
|
|
84
|
-
app.post("/:
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
function: functionName,
|
|
88
|
-
data: req.body
|
|
89
|
-
}, {
|
|
90
|
-
F: __dxlog_file,
|
|
91
|
-
L: 74,
|
|
92
|
-
S: this,
|
|
93
|
-
C: (f, a) => f(...a)
|
|
94
|
-
});
|
|
95
|
-
const builder = {
|
|
114
|
+
app.post("/:name", async (req, res) => {
|
|
115
|
+
const { name } = req.params;
|
|
116
|
+
const response = {
|
|
96
117
|
status: (code) => {
|
|
97
118
|
res.statusCode = code;
|
|
98
|
-
return
|
|
119
|
+
return response;
|
|
99
120
|
},
|
|
100
121
|
succeed: (result = {}) => {
|
|
101
122
|
res.end(JSON.stringify(result));
|
|
102
|
-
return
|
|
123
|
+
return response;
|
|
103
124
|
}
|
|
104
125
|
};
|
|
105
126
|
const context = {
|
|
106
127
|
client: this._client,
|
|
107
|
-
status:
|
|
128
|
+
status: response.status.bind(response)
|
|
108
129
|
};
|
|
109
130
|
void (async () => {
|
|
110
131
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
132
|
+
(0, import_log.log)(`invoking: ${name}`, void 0, {
|
|
133
|
+
F: __dxlog_file,
|
|
134
|
+
L: 103,
|
|
135
|
+
S: this,
|
|
136
|
+
C: (f, a) => f(...a)
|
|
137
|
+
});
|
|
138
|
+
const { handler } = this._handlers[name];
|
|
139
|
+
const response2 = await handler({
|
|
140
|
+
context,
|
|
141
|
+
event: req.body
|
|
142
|
+
});
|
|
143
|
+
(0, import_log.log)("done", {
|
|
144
|
+
response: response2
|
|
145
|
+
}, {
|
|
146
|
+
F: __dxlog_file,
|
|
147
|
+
L: 106,
|
|
148
|
+
S: this,
|
|
149
|
+
C: (f, a) => f(...a)
|
|
114
150
|
});
|
|
115
151
|
} catch (err) {
|
|
116
152
|
res.statusCode = 500;
|
|
@@ -118,21 +154,35 @@ var DevServer = class {
|
|
|
118
154
|
}
|
|
119
155
|
})();
|
|
120
156
|
});
|
|
121
|
-
this._port = await (0,
|
|
122
|
-
|
|
157
|
+
this._port = await (0, import_get_port_please.getPort)({
|
|
158
|
+
port: 7200,
|
|
159
|
+
portRange: [
|
|
160
|
+
7200,
|
|
161
|
+
7299
|
|
162
|
+
]
|
|
123
163
|
});
|
|
124
164
|
this._server = app.listen(this._port);
|
|
125
165
|
try {
|
|
126
|
-
const { registrationId } = await this._client.services.services.FunctionRegistryService.register({
|
|
166
|
+
const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService.register({
|
|
127
167
|
endpoint: this.endpoint,
|
|
128
|
-
functions: this.functions.map((
|
|
129
|
-
name
|
|
168
|
+
functions: this.functions.map(({ def: { path } }) => ({
|
|
169
|
+
name: path
|
|
130
170
|
}))
|
|
131
171
|
});
|
|
172
|
+
import_log.log.info("registered", {
|
|
173
|
+
registrationId,
|
|
174
|
+
endpoint
|
|
175
|
+
}, {
|
|
176
|
+
F: __dxlog_file,
|
|
177
|
+
L: 126,
|
|
178
|
+
S: this,
|
|
179
|
+
C: (f, a) => f(...a)
|
|
180
|
+
});
|
|
132
181
|
this._registrationId = registrationId;
|
|
182
|
+
this._proxy = endpoint;
|
|
133
183
|
} catch (err) {
|
|
134
184
|
await this.stop();
|
|
135
|
-
throw new Error("FunctionRegistryService not available
|
|
185
|
+
throw new Error("FunctionRegistryService not available (check plugin is configured).");
|
|
136
186
|
}
|
|
137
187
|
}
|
|
138
188
|
async stop() {
|
|
@@ -142,28 +192,29 @@ var DevServer = class {
|
|
|
142
192
|
await this._client.services.services.FunctionRegistryService.unregister({
|
|
143
193
|
registrationId: this._registrationId
|
|
144
194
|
});
|
|
195
|
+
import_log.log.info("unregistered", {
|
|
196
|
+
registrationId: this._registrationId
|
|
197
|
+
}, {
|
|
198
|
+
F: __dxlog_file,
|
|
199
|
+
L: 143,
|
|
200
|
+
S: this,
|
|
201
|
+
C: (f, a) => f(...a)
|
|
202
|
+
});
|
|
145
203
|
this._registrationId = void 0;
|
|
204
|
+
this._proxy = void 0;
|
|
146
205
|
}
|
|
147
206
|
trigger.wake();
|
|
148
207
|
});
|
|
149
208
|
await trigger.wait();
|
|
150
|
-
this._server = void 0;
|
|
151
209
|
this._port = void 0;
|
|
210
|
+
this._server = void 0;
|
|
152
211
|
}
|
|
153
212
|
};
|
|
154
|
-
|
|
155
|
-
// packages/core/functions/src/runtime/trigger-manager.ts
|
|
156
|
-
var import_async2 = require("@dxos/async");
|
|
157
|
-
var import_context = require("@dxos/context");
|
|
158
|
-
var import_echo_schema = require("@dxos/echo-schema");
|
|
159
|
-
var import_invariant = require("@dxos/invariant");
|
|
160
|
-
var import_log2 = require("@dxos/log");
|
|
161
|
-
var import_util = require("@dxos/util");
|
|
162
|
-
var __dxlog_file2 = "/home/circleci/project/packages/core/functions/src/runtime/trigger-manager.ts";
|
|
213
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/trigger-manager.ts";
|
|
163
214
|
var TriggerManager = class {
|
|
164
|
-
constructor(_client,
|
|
215
|
+
constructor(_client, _manifest, _invokeOptions) {
|
|
165
216
|
this._client = _client;
|
|
166
|
-
this.
|
|
217
|
+
this._manifest = _manifest;
|
|
167
218
|
this._invokeOptions = _invokeOptions;
|
|
168
219
|
this._mounts = new import_util.ComplexMap(({ name, spaceKey }) => `${spaceKey.toHex()}:${name}`);
|
|
169
220
|
this._queries = /* @__PURE__ */ new Set();
|
|
@@ -172,7 +223,7 @@ var TriggerManager = class {
|
|
|
172
223
|
this._client.spaces.subscribe(async (spaces) => {
|
|
173
224
|
for (const space of spaces) {
|
|
174
225
|
await space.waitUntilReady();
|
|
175
|
-
for (const trigger of this.
|
|
226
|
+
for (const trigger of this._manifest.triggers ?? []) {
|
|
176
227
|
await this.mount(new import_context.Context(), space, trigger);
|
|
177
228
|
}
|
|
178
229
|
}
|
|
@@ -188,6 +239,16 @@ var TriggerManager = class {
|
|
|
188
239
|
name: trigger.function,
|
|
189
240
|
spaceKey: space.key
|
|
190
241
|
};
|
|
242
|
+
const config = this._manifest.functions.find((config2) => config2.id === trigger.function);
|
|
243
|
+
(0, import_invariant2.invariant)(config, `Function not found: ${trigger.function}`, {
|
|
244
|
+
F: __dxlog_file2,
|
|
245
|
+
L: 57,
|
|
246
|
+
S: this,
|
|
247
|
+
A: [
|
|
248
|
+
"config",
|
|
249
|
+
"`Function not found: ${trigger.function}`"
|
|
250
|
+
]
|
|
251
|
+
});
|
|
191
252
|
const exists = this._mounts.get(key);
|
|
192
253
|
if (!exists) {
|
|
193
254
|
this._mounts.set(key, {
|
|
@@ -199,7 +260,7 @@ var TriggerManager = class {
|
|
|
199
260
|
trigger
|
|
200
261
|
}, {
|
|
201
262
|
F: __dxlog_file2,
|
|
202
|
-
L:
|
|
263
|
+
L: 61,
|
|
203
264
|
S: this,
|
|
204
265
|
C: (f, a) => f(...a)
|
|
205
266
|
});
|
|
@@ -208,7 +269,7 @@ var TriggerManager = class {
|
|
|
208
269
|
}
|
|
209
270
|
const objectIds = /* @__PURE__ */ new Set();
|
|
210
271
|
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
211
|
-
await this.
|
|
272
|
+
await this.execFunction(this._invokeOptions, config.path, {
|
|
212
273
|
space: space.key,
|
|
213
274
|
objects: Array.from(objectIds)
|
|
214
275
|
});
|
|
@@ -258,9 +319,9 @@ var TriggerManager = class {
|
|
|
258
319
|
await ctx.dispose();
|
|
259
320
|
}
|
|
260
321
|
}
|
|
261
|
-
async
|
|
262
|
-
const { endpoint
|
|
263
|
-
(0,
|
|
322
|
+
async execFunction(options, functionName, data) {
|
|
323
|
+
const { endpoint } = options;
|
|
324
|
+
(0, import_invariant2.invariant)(endpoint, "Missing endpoint", {
|
|
264
325
|
F: __dxlog_file2,
|
|
265
326
|
L: 120,
|
|
266
327
|
S: this,
|
|
@@ -269,25 +330,16 @@ var TriggerManager = class {
|
|
|
269
330
|
"'Missing endpoint'"
|
|
270
331
|
]
|
|
271
332
|
});
|
|
272
|
-
(0, import_invariant.invariant)(runtime, "Missing runtime", {
|
|
273
|
-
F: __dxlog_file2,
|
|
274
|
-
L: 121,
|
|
275
|
-
S: this,
|
|
276
|
-
A: [
|
|
277
|
-
"runtime",
|
|
278
|
-
"'Missing runtime'"
|
|
279
|
-
]
|
|
280
|
-
});
|
|
281
333
|
try {
|
|
282
334
|
(0, import_log2.log)("invoke", {
|
|
283
335
|
function: functionName
|
|
284
336
|
}, {
|
|
285
337
|
F: __dxlog_file2,
|
|
286
|
-
L:
|
|
338
|
+
L: 123,
|
|
287
339
|
S: this,
|
|
288
340
|
C: (f, a) => f(...a)
|
|
289
341
|
});
|
|
290
|
-
const url = `${endpoint}/${
|
|
342
|
+
const url = `${endpoint}/${functionName}`;
|
|
291
343
|
const res = await fetch(url, {
|
|
292
344
|
method: "POST",
|
|
293
345
|
body: JSON.stringify(data),
|
|
@@ -300,7 +352,7 @@ var TriggerManager = class {
|
|
|
300
352
|
result: await res.json()
|
|
301
353
|
}, {
|
|
302
354
|
F: __dxlog_file2,
|
|
303
|
-
L:
|
|
355
|
+
L: 133,
|
|
304
356
|
S: this,
|
|
305
357
|
C: (f, a) => f(...a)
|
|
306
358
|
});
|
|
@@ -310,7 +362,7 @@ var TriggerManager = class {
|
|
|
310
362
|
error: err.message
|
|
311
363
|
}, {
|
|
312
364
|
F: __dxlog_file2,
|
|
313
|
-
L:
|
|
365
|
+
L: 135,
|
|
314
366
|
S: this,
|
|
315
367
|
C: (f, a) => f(...a)
|
|
316
368
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/runtime/dev-server.ts", "../../../src/runtime/trigger-manager.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport express from 'express';\nimport { getPort } from 'get-port-please';\nimport type http from 'http';\nimport { join } from 'node:path';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionContext, type FunctionHandler, type Response } from '../handler';\nimport { type FunctionDef, type FunctionManifest } from '../manifest';\n\nexport type DevServerOptions = {\n port?: number;\n directory: string;\n manifest: FunctionManifest;\n};\n\n/**\n * Functions dev server provides a local HTTP server for testing functions.\n */\n// TODO(burdon): Reconcile with agent/functions dev dispatcher.\nexport class DevServer {\n private readonly _handlers: Record<string, { def: FunctionDef; handler: FunctionHandler<any> }> = {};\n\n private _server?: http.Server;\n private _port?: number;\n private _registrationId?: string;\n private _proxy?: string;\n\n // prettier-ignore\n constructor(\n private readonly _client: Client,\n private readonly _options: DevServerOptions,\n ) {}\n\n get endpoint() {\n invariant(this._port);\n return `http://localhost:${this._port}`;\n }\n\n get proxy() {\n return this._proxy;\n }\n\n get functions() {\n return Object.values(this._handlers);\n }\n\n async initialize() {\n for (const def of this._options.manifest.functions) {\n const { id, path, handler: dir } = def;\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(join(this._options.directory, dir));\n const handler = module.default;\n if (typeof handler !== 'function') {\n throw new Error(`Handler must export default function: ${id}`);\n }\n\n if (this._handlers[path]) {\n log.warn(`Function already registered: ${id}`);\n }\n\n this._handlers[path] = { def, handler };\n } catch (err) {\n log.error('parsing function (check manifest)', err);\n }\n }\n }\n\n async start() {\n const app = express();\n app.use(express.json());\n\n app.post('/:name', async (req, res) => {\n const { name } = req.params;\n\n const response: Response = {\n status: (code: number) => {\n res.statusCode = code;\n return response;\n },\n\n succeed: (result = {}) => {\n res.end(JSON.stringify(result));\n return response;\n },\n };\n\n const context: FunctionContext = {\n client: this._client,\n status: response.status.bind(response),\n };\n\n void (async () => {\n try {\n log(`invoking: ${name}`);\n const { handler } = this._handlers[name];\n const response = await handler({ context, event: req.body });\n log('done', { response });\n } catch (err: any) {\n res.statusCode = 500;\n res.end(err.message);\n }\n })();\n });\n\n // TODO(burdon): Push down port management to agent.\n this._port = await getPort({ port: 7200, portRange: [7200, 7299] });\n this._server = app.listen(this._port);\n\n // TODO(burdon): Test during initialization.\n try {\n // Register functions.\n const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService!.register({\n endpoint: this.endpoint,\n functions: this.functions.map(({ def: { path } }) => ({ name: path })),\n });\n\n log.info('registered', { registrationId, endpoint });\n this._registrationId = registrationId;\n this._proxy = endpoint;\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n }\n\n async stop() {\n const trigger = new Trigger();\n this._server?.close(async () => {\n if (this._registrationId) {\n await this._client.services.services.FunctionRegistryService!.unregister({\n registrationId: this._registrationId,\n });\n\n log.info('unregistered', { registrationId: this._registrationId });\n this._registrationId = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { DeferredTask } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport type { Query, Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Filter, createSubscription } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type FunctionManifest, type FunctionTrigger } from '../manifest';\n\n// TODO(burdon): Rename.\nexport type InvokeOptions = {\n endpoint: string;\n};\n\nexport class TriggerManager {\n private readonly _mounts = new ComplexMap<\n { name: string; spaceKey: PublicKey },\n { ctx: Context; trigger: FunctionTrigger }\n >(({ name, spaceKey }) => `${spaceKey.toHex()}:${name}`);\n\n private readonly _queries = new Set<Query>();\n\n constructor(\n private readonly _client: Client,\n private readonly _manifest: FunctionManifest,\n private readonly _invokeOptions: InvokeOptions,\n ) {}\n\n async start() {\n // TODO(burdon): Make runtime configurable (via CLI)?\n this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n await space.waitUntilReady();\n for (const trigger of this._manifest.triggers ?? []) {\n // TODO(burdon): New context? Shared?\n await this.mount(new Context(), space, trigger);\n }\n }\n });\n }\n\n async stop() {\n for (const { name, spaceKey } of this._mounts.keys()) {\n await this.unmount(name, spaceKey);\n }\n }\n\n private async mount(ctx: Context, space: Space, trigger: FunctionTrigger) {\n const key = { name: trigger.function, spaceKey: space.key };\n const config = this._manifest.functions.find((config) => config.id === trigger.function);\n invariant(config, `Function not found: ${trigger.function}`);\n const exists = this._mounts.get(key);\n if (!exists) {\n this._mounts.set(key, { ctx, trigger });\n log('mount', { space: space.key, trigger });\n if (ctx.disposed) {\n return;\n }\n\n // TODO(burdon): Why DeferredTask? How to pass objectIds to function?\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this.execFunction(this._invokeOptions, config.path, {\n space: space.key,\n objects: Array.from(objectIds),\n });\n });\n\n let count = 0;\n const subscription = createSubscription(({ added, updated }) => {\n for (const object of added) {\n objectIds.add(object.id);\n }\n for (const object of updated) {\n objectIds.add(object.id);\n }\n\n log('updated', {\n trigger,\n space: space.key,\n objects: objectIds.size,\n count,\n });\n\n task.schedule();\n count++;\n });\n // TODO(burdon): DSL for query (replace props).\n const query = space.db.query(Filter.typename(trigger.subscription.type, trigger.subscription.props));\n this._queries.add(query);\n const unsubscribe = query.subscribe(({ objects }) => {\n subscription.update(objects);\n }, true);\n\n ctx.onDispose(() => {\n subscription.unsubscribe();\n unsubscribe();\n this._queries.delete(query);\n });\n }\n }\n\n private async unmount(name: string, spaceKey: PublicKey) {\n const key = { name, spaceKey };\n const { ctx } = this._mounts.get(key) ?? {};\n if (ctx) {\n this._mounts.delete(key);\n await ctx.dispose();\n }\n }\n\n private async execFunction(options: InvokeOptions, functionName: string, data: any) {\n const { endpoint } = options;\n invariant(endpoint, 'Missing endpoint');\n\n try {\n log('invoke', { function: functionName });\n const url = `${endpoint}/${functionName}`;\n const res = await fetch(url, {\n method: 'POST',\n body: JSON.stringify(data),\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n log('result', { function: functionName, result: await res.json() });\n } catch (err: any) {\n log.error('error', { function: functionName, error: err.message });\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,qBAAoB;AACpB,6BAAwB;AAExB,uBAAqB;AAErB,mBAAwB;AAExB,uBAA0B;AAC1B,iBAAoB;ACRpB,IAAAA,gBAA6B;AAG7B,qBAAwB;AACxB,yBAA2C;AAC3C,IAAAC,oBAA0B;AAC1B,IAAAC,cAAoB;AACpB,kBAA2B;;;;;;;;;ADgBpB,IAAMC,YAAN,MAAMA;;EASXC,YACmBC,SACAC,UACjB;mBAFiBD;oBACAC;SAVFC,YAAiF,CAAC;EAWhG;EAEH,IAAIC,WAAW;AACbC,oCAAU,KAAKC,OAAK,QAAA;;;;;;;;;AACpB,WAAO,oBAAoB,KAAKA,KAAK;EACvC;EAEA,IAAIC,QAAQ;AACV,WAAO,KAAKC;EACd;EAEA,IAAIC,YAAY;AACd,WAAOC,OAAOC,OAAO,KAAKR,SAAS;EACrC;EAEA,MAAMS,aAAa;AACjB,eAAWC,OAAO,KAAKX,SAASY,SAASL,WAAW;AAClD,YAAM,EAAEM,IAAIC,MAAMC,SAASC,IAAG,IAAKL;AACnC,UAAI;AAEF,cAAMM,UAASC,cAAQC,uBAAK,KAAKnB,SAASoB,WAAWJ,GAAAA,CAAAA;AACrD,cAAMD,UAAUE,QAAOI;AACvB,YAAI,OAAON,YAAY,YAAY;AACjC,gBAAM,IAAIO,MAAM,yCAAyCT,EAAAA,EAAI;QAC/D;AAEA,YAAI,KAAKZ,UAAUa,IAAAA,GAAO;AACxBS,yBAAIC,KAAK,gCAAgCX,EAAAA,IAAI,QAAA;;;;;;QAC/C;AAEA,aAAKZ,UAAUa,IAAAA,IAAQ;UAAEH;UAAKI;QAAQ;MACxC,SAASU,KAAK;AACZF,uBAAIG,MAAM,qCAAqCD,KAAAA;;;;;;MACjD;IACF;EACF;EAEA,MAAME,QAAQ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|
6
|
+
"names": ["import_async", "import_invariant", "import_log", "DevServer", "constructor", "_client", "_options", "_handlers", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "initialize", "def", "manifest", "id", "path", "handler", "dir", "module", "require", "join", "directory", "default", "Error", "log", "warn", "err", "error", "start", "app", "express", "use", "json", "post", "req", "res", "name", "params", "response", "status", "code", "statusCode", "succeed", "result", "end", "JSON", "stringify", "context", "client", "bind", "event", "body", "message", "getPort", "port", "portRange", "_server", "listen", "registrationId", "services", "FunctionRegistryService", "register", "map", "info", "_registrationId", "stop", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "wait", "TriggerManager", "_manifest", "_invokeOptions", "_mounts", "ComplexMap", "spaceKey", "toHex", "_queries", "Set", "spaces", "subscribe", "space", "waitUntilReady", "triggers", "mount", "Context", "keys", "unmount", "ctx", "key", "function", "config", "find", "exists", "get", "set", "disposed", "objectIds", "task", "DeferredTask", "execFunction", "objects", "Array", "from", "count", "subscription", "createSubscription", "added", "updated", "object", "add", "size", "schedule", "query", "db", "Filter", "typename", "type", "props", "unsubscribe", "update", "onDispose", "delete", "dispose", "options", "functionName", "data", "url", "fetch", "method", "headers"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/functions/src/
|
|
1
|
+
{"inputs":{"packages/core/functions/src/handler.ts":{"bytes":1109,"imports":[],"format":"esm"},"packages/core/functions/src/manifest.ts":{"bytes":1346,"imports":[],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":17196,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/trigger-manager.ts":{"bytes":16867,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":584,"imports":[{"path":"packages/core/functions/src/runtime/dev-server.ts","kind":"import-statement","original":"./dev-server"},{"path":"packages/core/functions/src/runtime/trigger-manager.ts","kind":"import-statement","original":"./trigger-manager"}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":637,"imports":[{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/manifest.ts","kind":"import-statement","original":"./manifest"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15787},"packages/core/functions/dist/lib/node/index.cjs":{"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["DevServer","TriggerManager"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4373},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/trigger-manager.ts":{"bytesInOutput":4463}},"bytes":9395}}}
|
|
@@ -7,30 +7,15 @@ export interface FunctionContext {
|
|
|
7
7
|
client: Client;
|
|
8
8
|
status(code: number): Response;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
10
|
+
/**
|
|
11
|
+
* Function handler.
|
|
12
|
+
*/
|
|
14
13
|
export type FunctionHandler<T extends {}> = (params: {
|
|
15
|
-
event: T;
|
|
16
14
|
context: FunctionContext;
|
|
15
|
+
event: T;
|
|
17
16
|
}) => Promise<Response | void>;
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
export type FunctionConfig = {
|
|
23
|
-
id: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
};
|
|
26
|
-
export type FunctionTrigger = {
|
|
27
|
-
function: string;
|
|
28
|
-
subscription: TriggerSubscription;
|
|
29
|
-
};
|
|
30
|
-
export type TriggerSubscription = {
|
|
31
|
-
type: string;
|
|
32
|
-
spaceKey: string;
|
|
33
|
-
props?: Record<string, any>;
|
|
34
|
-
nested?: string[];
|
|
17
|
+
export type FunctionSubscriptionEvent = {
|
|
18
|
+
space: string;
|
|
19
|
+
objects: string[];
|
|
35
20
|
};
|
|
36
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE;IACnD,OAAO,EAAE,eAAe,CAAC;IACzB,KAAK,EAAE,CAAC,CAAC;CACV,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAG/B,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type FunctionDef = {
|
|
2
|
+
id: string;
|
|
3
|
+
path: string;
|
|
4
|
+
handler: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
};
|
|
7
|
+
export type TriggerSubscription = {
|
|
8
|
+
type: string;
|
|
9
|
+
spaceKey: string;
|
|
10
|
+
props?: Record<string, any>;
|
|
11
|
+
nested?: string[];
|
|
12
|
+
};
|
|
13
|
+
export type FunctionTrigger = {
|
|
14
|
+
function: string;
|
|
15
|
+
subscription: TriggerSubscription;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Function manifest file.
|
|
19
|
+
*/
|
|
20
|
+
export type FunctionManifest = {
|
|
21
|
+
functions: FunctionDef[];
|
|
22
|
+
triggers: FunctionTrigger[];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/manifest.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG;IAExB,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAKF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,mBAAmB,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type Client } from '@dxos/client';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FunctionHandler } from '../handler';
|
|
3
|
+
import { type FunctionDef, type FunctionManifest } from '../manifest';
|
|
3
4
|
export type DevServerOptions = {
|
|
5
|
+
port?: number;
|
|
4
6
|
directory: string;
|
|
5
|
-
manifest:
|
|
7
|
+
manifest: FunctionManifest;
|
|
6
8
|
};
|
|
7
9
|
/**
|
|
8
10
|
* Functions dev server provides a local HTTP server for testing functions.
|
|
@@ -14,10 +16,14 @@ export declare class DevServer {
|
|
|
14
16
|
private _server?;
|
|
15
17
|
private _port?;
|
|
16
18
|
private _registrationId?;
|
|
19
|
+
private _proxy?;
|
|
17
20
|
constructor(_client: Client, _options: DevServerOptions);
|
|
18
|
-
get
|
|
19
|
-
get
|
|
20
|
-
get functions():
|
|
21
|
+
get endpoint(): string;
|
|
22
|
+
get proxy(): string | undefined;
|
|
23
|
+
get functions(): {
|
|
24
|
+
def: FunctionDef;
|
|
25
|
+
handler: FunctionHandler<any>;
|
|
26
|
+
}[];
|
|
21
27
|
initialize(): Promise<void>;
|
|
22
28
|
start(): Promise<void>;
|
|
23
29
|
stop(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/dev-server.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/dev-server.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EAAwB,KAAK,eAAe,EAAiB,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEF;;GAEG;AAEH,qBAAa,SAAS;IAUlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAV3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2E;IAErG,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,MAAM,CAAC,CAAS;gBAIL,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,gBAAgB;IAG7C,IAAI,QAAQ,WAGX;IAED,IAAI,KAAK,uBAER;IAED,IAAI,SAAS;;;QAEZ;IAEK,UAAU;IAsBV,KAAK;IA0DL,IAAI;CAoBX"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { type Client } from '@dxos/client';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FunctionManifest } from '../manifest';
|
|
3
3
|
export type InvokeOptions = {
|
|
4
4
|
endpoint: string;
|
|
5
|
-
runtime: string;
|
|
6
5
|
};
|
|
7
6
|
export declare class TriggerManager {
|
|
8
7
|
private readonly _client;
|
|
9
|
-
private readonly
|
|
8
|
+
private readonly _manifest;
|
|
10
9
|
private readonly _invokeOptions;
|
|
11
10
|
private readonly _mounts;
|
|
12
11
|
private readonly _queries;
|
|
13
|
-
constructor(_client: Client,
|
|
12
|
+
constructor(_client: Client, _manifest: FunctionManifest, _invokeOptions: InvokeOptions);
|
|
14
13
|
start(): Promise<void>;
|
|
15
14
|
stop(): Promise<void>;
|
|
16
15
|
private mount;
|
|
17
16
|
private unmount;
|
|
18
|
-
private
|
|
17
|
+
private execFunction;
|
|
19
18
|
}
|
|
20
19
|
//# sourceMappingURL=trigger-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-manager.d.ts","sourceRoot":"","sources":["../../../../src/runtime/trigger-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,cAAc,CAAC;AAQ3D,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"trigger-manager.d.ts","sourceRoot":"","sources":["../../../../src/runtime/trigger-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,cAAc,CAAC;AAQ3D,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAG1E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qBAAa,cAAc;IASvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAVjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGiC;IAEzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;gBAG1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,gBAAgB,EAC3B,cAAc,EAAE,aAAa;IAG1C,KAAK;IAaL,IAAI;YAMI,KAAK;YAuDL,OAAO;YASP,YAAY;CAoB3B"}
|