@dxos/functions 0.1.52 → 0.1.53-main.032dce6
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 +68 -3
- package/dist/lib/browser/index.mjs +252 -75
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +253 -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 +30 -0
- package/dist/types/src/function.d.ts.map +1 -0
- package/dist/types/src/function.test.d.ts +2 -0
- package/dist/types/src/function.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts +25 -0
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -0
- package/dist/types/src/runtime/index.d.ts +2 -6
- package/dist/types/src/runtime/index.d.ts.map +1 -1
- package/dist/types/src/runtime/trigger-manager.d.ts +19 -0
- package/dist/types/src/runtime/trigger-manager.d.ts.map +1 -0
- package/package.json +9 -5
- package/src/function.ts +40 -0
- package/src/index.ts +1 -1
- package/src/runtime/dev-server.ts +131 -0
- package/src/runtime/index.ts +2 -90
- package/src/runtime/trigger-manager.ts +143 -0
- package/dist/types/src/functions.test.d.ts +0 -2
- package/dist/types/src/functions.test.d.ts.map +0 -1
- package/dist/types/src/interface.d.ts +0 -13
- package/dist/types/src/interface.d.ts.map +0 -1
- package/src/interface.ts +0 -20
- /package/src/{functions.test.ts → function.test.ts} +0 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -30,96 +30,274 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// packages/core/functions/src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
33
|
+
DevServer: () => DevServer,
|
|
34
|
+
TriggerManager: () => TriggerManager
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(src_exports);
|
|
36
37
|
|
|
37
|
-
// packages/core/functions/src/runtime/
|
|
38
|
+
// packages/core/functions/src/runtime/dev-server.ts
|
|
38
39
|
var import_express = __toESM(require("express"));
|
|
39
|
-
var import_promises = require("node:fs/promises");
|
|
40
40
|
var import_node_path = require("node:path");
|
|
41
41
|
var import_portfinder = require("portfinder");
|
|
42
|
+
var import_async = require("@dxos/async");
|
|
42
43
|
var import_log = require("@dxos/log");
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
var DEFAULT_PORT = 7e3;
|
|
45
|
+
var DevServer = class {
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
constructor(_client, _options) {
|
|
48
|
+
this._client = _client;
|
|
49
|
+
this._options = _options;
|
|
50
|
+
this._functionHandlers = {};
|
|
51
|
+
}
|
|
52
|
+
get port() {
|
|
53
|
+
return this._port;
|
|
54
|
+
}
|
|
55
|
+
get endpoint() {
|
|
56
|
+
return this._port ? `http://localhost:${this._port}` : void 0;
|
|
57
|
+
}
|
|
58
|
+
get functions() {
|
|
59
|
+
return Object.keys(this._functionHandlers);
|
|
60
|
+
}
|
|
61
|
+
async initialize() {
|
|
62
|
+
for (const [name, _] of Object.entries(this._options.manifest.functions)) {
|
|
63
|
+
try {
|
|
64
|
+
const module2 = require((0, import_node_path.join)(this._options.directory, name));
|
|
65
|
+
const handler = module2.default;
|
|
66
|
+
if (typeof handler !== "function") {
|
|
67
|
+
throw new Error(`Handler must export default function: ${name}`);
|
|
68
|
+
}
|
|
69
|
+
this._functionHandlers[name] = handler;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
import_log.log.error("parsing function (check functions.yml manifest)", err, {
|
|
72
|
+
file: "dev-server.ts",
|
|
73
|
+
line: 63,
|
|
74
|
+
scope: this,
|
|
75
|
+
callSite: (f, a) => f(...a)
|
|
76
|
+
});
|
|
59
77
|
}
|
|
60
|
-
const functionName = file.slice(0, -(0, import_node_path.extname)(file).length);
|
|
61
|
-
functionHandlers[functionName] = handler;
|
|
62
|
-
} catch (e) {
|
|
63
|
-
console.error(e);
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
async start() {
|
|
81
|
+
const app = (0, import_express.default)();
|
|
82
|
+
app.use(import_express.default.json());
|
|
83
|
+
app.post("/:functionName", async (req, res) => {
|
|
84
|
+
const functionName = req.params.functionName;
|
|
85
|
+
(0, import_log.log)("invoke", {
|
|
86
|
+
function: functionName,
|
|
87
|
+
data: req.body
|
|
88
|
+
}, {
|
|
89
|
+
file: "dev-server.ts",
|
|
90
|
+
line: 74,
|
|
91
|
+
scope: this,
|
|
92
|
+
callSite: (f, a) => f(...a)
|
|
93
|
+
});
|
|
94
|
+
const builder = {
|
|
95
|
+
status: (code) => {
|
|
96
|
+
res.statusCode = code;
|
|
97
|
+
return builder;
|
|
98
|
+
},
|
|
99
|
+
succeed: (result = {}) => {
|
|
100
|
+
res.end(JSON.stringify(result));
|
|
101
|
+
return builder;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const context = {
|
|
105
|
+
client: this._client,
|
|
106
|
+
status: builder.status.bind(builder)
|
|
107
|
+
};
|
|
108
|
+
void (async () => {
|
|
109
|
+
try {
|
|
110
|
+
await this._functionHandlers[functionName](req.body, context);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
res.statusCode = 500;
|
|
113
|
+
res.end(err.message);
|
|
114
|
+
}
|
|
115
|
+
})();
|
|
116
|
+
});
|
|
117
|
+
this._port = await (0, import_portfinder.getPortPromise)({
|
|
118
|
+
startPort: DEFAULT_PORT
|
|
119
|
+
});
|
|
120
|
+
this._server = app.listen(this._port);
|
|
121
|
+
const { registrationId } = await this._client.services.services.FunctionRegistryService.register({
|
|
122
|
+
endpoint: this.endpoint,
|
|
123
|
+
functions: this.functions.map((name) => ({
|
|
124
|
+
name
|
|
125
|
+
}))
|
|
126
|
+
});
|
|
127
|
+
this._registrationId = registrationId;
|
|
128
|
+
}
|
|
129
|
+
async stop() {
|
|
130
|
+
var _a;
|
|
131
|
+
const trigger = new import_async.Trigger();
|
|
132
|
+
(_a = this._server) == null ? void 0 : _a.close(async () => {
|
|
133
|
+
if (this._registrationId) {
|
|
134
|
+
await this._client.services.services.FunctionRegistryService.unregister({
|
|
135
|
+
registrationId: this._registrationId
|
|
136
|
+
});
|
|
137
|
+
this._registrationId = void 0;
|
|
81
138
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
139
|
+
trigger.wake();
|
|
140
|
+
});
|
|
141
|
+
await trigger.wait();
|
|
142
|
+
this._server = void 0;
|
|
143
|
+
this._port = void 0;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// packages/core/functions/src/runtime/trigger-manager.ts
|
|
148
|
+
var import_node_assert = __toESM(require("node:assert"));
|
|
149
|
+
var import_async2 = require("@dxos/async");
|
|
150
|
+
var import_context = require("@dxos/context");
|
|
151
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
152
|
+
var import_log2 = require("@dxos/log");
|
|
153
|
+
var import_util = require("@dxos/util");
|
|
154
|
+
var TriggerManager = class {
|
|
155
|
+
constructor(_client, _triggers, _invokeOptions) {
|
|
156
|
+
this._client = _client;
|
|
157
|
+
this._triggers = _triggers;
|
|
158
|
+
this._invokeOptions = _invokeOptions;
|
|
159
|
+
this._mounts = new import_util.ComplexMap(({ name, spaceKey }) => `${spaceKey.toHex()}:${name}`);
|
|
160
|
+
}
|
|
161
|
+
async start() {
|
|
162
|
+
this._client.spaces.subscribe(async (spaces) => {
|
|
163
|
+
for (const space of spaces) {
|
|
164
|
+
await space.waitUntilReady();
|
|
165
|
+
for (const trigger of this._triggers) {
|
|
166
|
+
await this.mount(new import_context.Context(), trigger, space);
|
|
167
|
+
}
|
|
93
168
|
}
|
|
94
|
-
})();
|
|
95
|
-
});
|
|
96
|
-
app.listen(port);
|
|
97
|
-
const functionNames = Object.keys(functionHandlers);
|
|
98
|
-
const { registrationId } = await options.client.services.services.FunctionRegistryService.register({
|
|
99
|
-
endpoint: `http://localhost:${port}`,
|
|
100
|
-
functions: functionNames.map((name) => ({
|
|
101
|
-
name
|
|
102
|
-
}))
|
|
103
|
-
});
|
|
104
|
-
process.on("SIGINT", async () => {
|
|
105
|
-
await options.client.services.services.FunctionRegistryService.unregister({
|
|
106
|
-
registrationId
|
|
107
169
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
170
|
+
}
|
|
171
|
+
async stop() {
|
|
172
|
+
for (const { name, spaceKey } of this._mounts.keys()) {
|
|
173
|
+
await this.unmount(name, spaceKey);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async mount(ctx, trigger, space) {
|
|
177
|
+
const key = {
|
|
178
|
+
name: trigger.function,
|
|
179
|
+
spaceKey: space.key
|
|
180
|
+
};
|
|
181
|
+
const exists = this._mounts.get(key);
|
|
182
|
+
if (!exists) {
|
|
183
|
+
this._mounts.set(key, {
|
|
184
|
+
ctx,
|
|
185
|
+
trigger
|
|
186
|
+
});
|
|
187
|
+
if (ctx.disposed) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
let count = 0;
|
|
191
|
+
const objectIds = /* @__PURE__ */ new Set();
|
|
192
|
+
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
193
|
+
const updatedObjects = Array.from(objectIds);
|
|
194
|
+
objectIds.clear();
|
|
195
|
+
await this.invokeFunction(this._invokeOptions, trigger.function, {
|
|
196
|
+
space: space.key,
|
|
197
|
+
objects: updatedObjects
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
const selection = (0, import_echo_schema.createSubscription)(({ added, updated }) => {
|
|
201
|
+
for (const object of added) {
|
|
202
|
+
objectIds.add(object.id);
|
|
203
|
+
}
|
|
204
|
+
for (const object1 of updated) {
|
|
205
|
+
objectIds.add(object1.id);
|
|
206
|
+
}
|
|
207
|
+
import_log2.log.info("updated", {
|
|
208
|
+
space: space.key,
|
|
209
|
+
objects: objectIds.size,
|
|
210
|
+
added: added.length,
|
|
211
|
+
updated: updated.length,
|
|
212
|
+
count
|
|
213
|
+
}, {
|
|
214
|
+
file: "trigger-manager.ts",
|
|
215
|
+
line: 85,
|
|
216
|
+
scope: this,
|
|
217
|
+
callSite: (f, a) => f(...a)
|
|
218
|
+
});
|
|
219
|
+
if (count++) {
|
|
220
|
+
task.schedule();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
ctx.onDispose(() => selection.unsubscribe());
|
|
224
|
+
const query = space.db.query({
|
|
225
|
+
...trigger.subscription.props,
|
|
226
|
+
"@type": trigger.subscription.type
|
|
227
|
+
});
|
|
228
|
+
const unsubscribe = query.subscribe(({ objects }) => {
|
|
229
|
+
selection.update(objects);
|
|
230
|
+
});
|
|
231
|
+
ctx.onDispose(unsubscribe);
|
|
232
|
+
import_log2.log.info("mounted", {
|
|
233
|
+
space: space.key,
|
|
234
|
+
trigger
|
|
235
|
+
}, {
|
|
236
|
+
file: "trigger-manager.ts",
|
|
237
|
+
line: 109,
|
|
238
|
+
scope: this,
|
|
239
|
+
callSite: (f, a) => f(...a)
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async unmount(name, spaceKey) {
|
|
244
|
+
var _a;
|
|
245
|
+
const key = {
|
|
246
|
+
name,
|
|
247
|
+
spaceKey
|
|
248
|
+
};
|
|
249
|
+
const { ctx } = (_a = this._mounts.get(key)) != null ? _a : {};
|
|
250
|
+
if (ctx) {
|
|
251
|
+
this._mounts.delete(key);
|
|
252
|
+
await ctx.dispose();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async invokeFunction(options, functionName, data) {
|
|
256
|
+
const { endpoint, runtime } = options;
|
|
257
|
+
(0, import_node_assert.default)(endpoint, "Missing endpoint");
|
|
258
|
+
(0, import_node_assert.default)(runtime, "Missing runtime");
|
|
259
|
+
try {
|
|
260
|
+
(0, import_log2.log)("invoke", {
|
|
261
|
+
function: functionName
|
|
262
|
+
}, {
|
|
263
|
+
file: "trigger-manager.ts",
|
|
264
|
+
line: 128,
|
|
265
|
+
scope: this,
|
|
266
|
+
callSite: (f, a) => f(...a)
|
|
267
|
+
});
|
|
268
|
+
const url = `${endpoint}/${runtime}/${functionName}`;
|
|
269
|
+
const res = await fetch(url, {
|
|
270
|
+
method: "POST",
|
|
271
|
+
body: JSON.stringify(data),
|
|
272
|
+
headers: {
|
|
273
|
+
"Content-Type": "application/json"
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
(0, import_log2.log)("result", {
|
|
277
|
+
function: functionName,
|
|
278
|
+
result: await res.json()
|
|
279
|
+
}, {
|
|
280
|
+
file: "trigger-manager.ts",
|
|
281
|
+
line: 138,
|
|
282
|
+
scope: this,
|
|
283
|
+
callSite: (f, a) => f(...a)
|
|
284
|
+
});
|
|
285
|
+
} catch (err) {
|
|
286
|
+
import_log2.log.error("error", {
|
|
287
|
+
function: functionName,
|
|
288
|
+
error: err.message
|
|
289
|
+
}, {
|
|
290
|
+
file: "trigger-manager.ts",
|
|
291
|
+
line: 140,
|
|
292
|
+
scope: this,
|
|
293
|
+
callSite: (f, a) => f(...a)
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
120
297
|
};
|
|
121
298
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
299
|
0 && (module.exports = {
|
|
123
|
-
|
|
300
|
+
DevServer,
|
|
301
|
+
TriggerManager
|
|
124
302
|
});
|
|
125
303
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/runtime/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/runtime/dev-server.ts", "../../../src/runtime/trigger-manager.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './function';\nexport * from './runtime';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport express from 'express';\nimport http from 'http';\nimport { join } from 'node:path';\nimport { getPortPromise } from 'portfinder';\n\nimport { Trigger } from '@dxos/async';\nimport { Client } from '@dxos/client';\nimport { log } from '@dxos/log';\n\nimport { FunctionContext, FunctionHandler, FunctionsManifest, Response } from '../function';\n\nconst DEFAULT_PORT = 7000;\n\nexport type DevServerOptions = {\n directory: string;\n manifest: FunctionsManifest;\n};\n\n/**\n * Functions dev server provides a local HTTP server for testing functions.\n */\nexport class DevServer {\n private readonly _functionHandlers: Record<string, FunctionHandler> = {};\n\n private _server?: http.Server;\n private _port?: number;\n private _registrationId?: string;\n\n // prettier-ignore\n constructor(\n private readonly _client: Client,\n private readonly _options: DevServerOptions\n ) {}\n\n get port() {\n return this._port;\n }\n\n get endpoint() {\n return this._port ? `http://localhost:${this._port}` : undefined;\n }\n\n get functions() {\n return Object.keys(this._functionHandlers);\n }\n\n async initialize() {\n for (const [name, _] of Object.entries(this._options.manifest.functions)) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(join(this._options.directory, name));\n const handler = module.default;\n if (typeof handler !== 'function') {\n throw new Error(`Handler must export default function: ${name}`);\n }\n\n this._functionHandlers[name] = handler;\n } catch (err) {\n log.error('parsing function (check functions.yml manifest)', err);\n }\n }\n }\n\n async start() {\n const app = express();\n app.use(express.json());\n\n app.post('/:functionName', async (req, res) => {\n const functionName = req.params.functionName;\n log('invoke', { function: functionName, data: req.body });\n\n const builder: Response = {\n status: (code: number) => {\n res.statusCode = code;\n return builder;\n },\n succeed: (result = {}) => {\n res.end(JSON.stringify(result));\n return builder;\n },\n };\n\n const context: FunctionContext = {\n client: this._client,\n status: builder.status.bind(builder),\n };\n\n void (async () => {\n try {\n await this._functionHandlers[functionName](req.body, context);\n } catch (err: any) {\n res.statusCode = 500;\n res.end(err.message);\n }\n })();\n });\n\n this._port = await getPortPromise({ startPort: DEFAULT_PORT });\n this._server = app.listen(this._port);\n\n // TODO(burdon): Check plugin is registered.\n // TypeError: Cannot read properties of undefined (reading 'register')\n const { registrationId } = await this._client.services.services.FunctionRegistryService!.register({\n endpoint: this.endpoint!,\n functions: this.functions.map((name) => ({ name })),\n });\n this._registrationId = registrationId;\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 this._registrationId = undefined;\n }\n\n trigger.wake();\n });\n\n await trigger.wait();\n this._server = undefined;\n this._port = undefined;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport assert from 'node:assert';\n\nimport { DeferredTask } from '@dxos/async';\nimport { Client, PublicKey, Space } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { createSubscription } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { FunctionTrigger } from '../function';\n\n// TODO(burdon): Rename.\nexport type InvokeOptions = {\n endpoint: string;\n runtime: 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 constructor(\n private readonly _client: Client,\n private readonly _triggers: FunctionTrigger[],\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._triggers) {\n // TODO(burdon): New context? Shared?\n await this.mount(new Context(), trigger, space);\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, trigger: FunctionTrigger, space: Space) {\n const key = { name: trigger.function, spaceKey: space.key };\n const exists = this._mounts.get(key);\n if (!exists) {\n this._mounts.set(key, { ctx, trigger });\n if (ctx.disposed) {\n return;\n }\n\n // TODO(burdon): Factor out subscription/result delta.\n\n let count = 0;\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n const updatedObjects = Array.from(objectIds);\n objectIds.clear();\n\n await this.invokeFunction(this._invokeOptions, trigger.function, {\n space: space.key,\n objects: updatedObjects,\n });\n });\n\n // TODO(burdon): Removed?\n const selection = 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.info('updated', {\n space: space.key,\n objects: objectIds.size,\n added: added.length,\n updated: updated.length,\n count,\n });\n if (count++) {\n task.schedule();\n }\n });\n\n ctx.onDispose(() => selection.unsubscribe());\n\n const query = space.db.query({ ...trigger.subscription.props, '@type': trigger.subscription.type });\n const unsubscribe = query.subscribe(({ objects }) => {\n selection.update(objects);\n });\n\n // Trigger first update, but don't schedule task.\n // selection.update(query.objects);\n\n ctx.onDispose(unsubscribe);\n\n log.info('mounted', { space: space.key, trigger });\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 invokeFunction(options: InvokeOptions, functionName: string, data: any) {\n const { endpoint, runtime } = options;\n assert(endpoint, 'Missing endpoint');\n assert(runtime, 'Missing runtime');\n\n try {\n log('invoke', { function: functionName });\n const url = `${endpoint}/${runtime}/${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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACIA,qBAAoB;AAEpB,uBAAqB;AACrB,wBAA+B;AAE/B,mBAAwB;AAExB,iBAAoB;AAIpB,IAAMA,eAAe;AAUd,IAAMC,YAAN,MAAMA;;EAQXC,YACmBC,SACAC,UACjB;mBAFiBD;oBACAC;SATFC,oBAAqD,CAAC;EAUpE;EAEH,IAAIC,OAAO;AACT,WAAO,KAAKC;EACd;EAEA,IAAIC,WAAW;AACb,WAAO,KAAKD,QAAQ,oBAAoB,KAAKA,UAAUE;EACzD;EAEA,IAAIC,YAAY;AACd,WAAOC,OAAOC,KAAK,KAAKP,iBAAiB;EAC3C;EAEA,MAAMQ,aAAa;AACjB,eAAW,CAACC,MAAMC,CAAAA,KAAMJ,OAAOK,QAAQ,KAAKZ,SAASa,SAASP,SAAS,GAAG;AACxE,UAAI;AAEF,cAAMQ,UAASC,YAAQC,uBAAK,KAAKhB,SAASiB,WAAWP,IAAAA,CAAAA;AACrD,cAAMQ,UAAUJ,QAAOK;AACvB,YAAI,OAAOD,YAAY,YAAY;AACjC,gBAAM,IAAI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,MAAM;MAAEf;MAAMC;IAAS;AAC7B,UAAM,EAAEa,IAAG,KAAK,UAAKhB,QAAQoB,IAAIH,GAAAA,MAAjB,YAAyB,CAAC;AAC1C,QAAID,KAAK;AACP,WAAKhB,QAAQsD,OAAOrC,GAAAA;AACpB,YAAMD,IAAIuC,QAAO;IACnB;EACF;EAEA,MAAcvB,eAAewB,SAAwBC,cAAsBC,MAAW;AACpF,UAAM,EAAEC,UAAUC,QAAO,IAAKJ;AAC9BK,2BAAAA,SAAOF,UAAU,kBAAA;AACjBE,2BAAAA,SAAOD,SAAS,iBAAA;AAEhB,QAAI;AACFnB,2BAAI,UAAU;QAAEvB,UAAUuC;MAAa,GAAA;;;;;;AACvC,YAAMK,MAAM,GAAGH,YAAYC,WAAWH;AACtC,YAAMM,MAAM,MAAMC,MAAMF,KAAK;QAC3BG,QAAQ;QACRC,MAAMC,KAAKC,UAAUV,IAAAA;QACrBW,SAAS;UACP,gBAAgB;QAClB;MACF,CAAA;AAEA5B,2BAAI,UAAU;QAAEvB,UAAUuC;QAAca,QAAQ,MAAMP,IAAIQ,KAAI;MAAG,GAAA;;;;;;IACnE,SAASC,KAAP;AACA/B,sBAAIgC,MAAM,SAAS;QAAEvD,UAAUuC;QAAcgB,OAAOD,IAAIE;MAAQ,GAAA;;;;;;IAClE;EACF;AACF;",
|
|
6
|
+
"names": ["DEFAULT_PORT", "DevServer", "constructor", "_client", "_options", "_functionHandlers", "port", "_port", "endpoint", "undefined", "functions", "Object", "keys", "initialize", "name", "_", "entries", "manifest", "module", "require", "join", "directory", "handler", "default", "Error", "err", "log", "error", "start", "app", "express", "use", "json", "post", "req", "res", "functionName", "params", "function", "data", "body", "builder", "status", "code", "statusCode", "succeed", "result", "end", "JSON", "stringify", "context", "client", "bind", "message", "getPortPromise", "startPort", "_server", "listen", "registrationId", "services", "FunctionRegistryService", "register", "map", "_registrationId", "stop", "trigger", "Trigger", "close", "unregister", "wake", "wait", "import_async", "import_log", "TriggerManager", "constructor", "_client", "_triggers", "_invokeOptions", "_mounts", "ComplexMap", "name", "spaceKey", "toHex", "start", "spaces", "subscribe", "space", "waitUntilReady", "trigger", "mount", "Context", "stop", "keys", "unmount", "ctx", "key", "function", "exists", "get", "set", "disposed", "count", "objectIds", "Set", "task", "DeferredTask", "updatedObjects", "Array", "from", "clear", "invokeFunction", "objects", "selection", "createSubscription", "added", "updated", "object", "add", "id", "log", "info", "size", "length", "schedule", "onDispose", "unsubscribe", "query", "db", "subscription", "props", "type", "update", "delete", "dispose", "options", "functionName", "data", "endpoint", "runtime", "assert", "url", "res", "fetch", "method", "body", "JSON", "stringify", "headers", "result", "json", "err", "error", "message"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/functions/src/
|
|
1
|
+
{"inputs":{"packages/core/functions/src/function.ts":{"bytes":1332,"imports":[]},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":13165,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"portfinder","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}]},"packages/core/functions/src/runtime/trigger-manager.ts":{"bytes":16131,"imports":[{"path":"node:assert","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/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}]},"packages/core/functions/src/runtime/index.ts":{"bytes":489,"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"}]},"packages/core/functions/src/index.ts":{"bytes":463,"imports":[{"path":"packages/core/functions/src/function.ts","kind":"import-statement","original":"./function"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"}]}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":14250},"packages/core/functions/dist/lib/node/index.cjs":{"imports":[{"path":"express","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"portfinder","kind":"require-call","external":true},{"path":"@dxos/async","kind":"require-call","external":true},{"path":"@dxos/log","kind":"require-call","external":true},{"path":"node:assert","kind":"require-call","external":true},{"path":"@dxos/async","kind":"require-call","external":true},{"path":"@dxos/context","kind":"require-call","external":true},{"path":"@dxos/echo-schema","kind":"require-call","external":true},{"path":"@dxos/log","kind":"require-call","external":true},{"path":"@dxos/util","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":163},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":3211},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/trigger-manager.ts":{"bytesInOutput":4326}},"bytes":9406}}}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Client } from '@dxos/client';
|
|
2
|
+
export interface Response {
|
|
3
|
+
status(code: number): Response;
|
|
4
|
+
succeed(data?: object): Response;
|
|
5
|
+
}
|
|
6
|
+
export interface FunctionContext {
|
|
7
|
+
client: Client;
|
|
8
|
+
status(code: number): Response;
|
|
9
|
+
}
|
|
10
|
+
export interface FunctionHandler {
|
|
11
|
+
(event: any, context: FunctionContext): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export type FunctionsManifest = {
|
|
14
|
+
functions: Record<string, FunctionConfig>;
|
|
15
|
+
triggers: FunctionTrigger[];
|
|
16
|
+
};
|
|
17
|
+
export type FunctionConfig = {
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
export type FunctionTrigger = {
|
|
21
|
+
function: string;
|
|
22
|
+
subscription: TriggerSubscription;
|
|
23
|
+
};
|
|
24
|
+
export type TriggerSubscription = {
|
|
25
|
+
type: string;
|
|
26
|
+
spaceKey: string;
|
|
27
|
+
props?: Record<string, any>;
|
|
28
|
+
nested?: string[];
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../src/function.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,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,MAAM,WAAW,eAAe;IAC9B,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3D;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,mBAAmB,CAAC;CACnC,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.test.d.ts","sourceRoot":"","sources":["../../../src/function.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client } from '@dxos/client';
|
|
2
|
+
import { FunctionsManifest } from '../function';
|
|
3
|
+
export type DevServerOptions = {
|
|
4
|
+
directory: string;
|
|
5
|
+
manifest: FunctionsManifest;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Functions dev server provides a local HTTP server for testing functions.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DevServer {
|
|
11
|
+
private readonly _client;
|
|
12
|
+
private readonly _options;
|
|
13
|
+
private readonly _functionHandlers;
|
|
14
|
+
private _server?;
|
|
15
|
+
private _port?;
|
|
16
|
+
private _registrationId?;
|
|
17
|
+
constructor(_client: Client, _options: DevServerOptions);
|
|
18
|
+
get port(): number | undefined;
|
|
19
|
+
get endpoint(): string | undefined;
|
|
20
|
+
get functions(): string[];
|
|
21
|
+
initialize(): Promise<void>;
|
|
22
|
+
start(): Promise<void>;
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dev-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/dev-server.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAoC,iBAAiB,EAAY,MAAM,aAAa,CAAC;AAI5F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IASlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAT3B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuC;IAEzE,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,eAAe,CAAC,CAAS;gBAId,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,gBAAgB;IAG7C,IAAI,IAAI,uBAEP;IAED,IAAI,QAAQ,uBAEX;IAED,IAAI,SAAS,aAEZ;IAEK,UAAU;IAiBV,KAAK;IA8CL,IAAI;CAiBX"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
client: Client;
|
|
4
|
-
functionsDirectory: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const runFunctions: (options: FunctionsRuntimeParams) => Promise<void>;
|
|
1
|
+
export * from './dev-server';
|
|
2
|
+
export * from './trigger-manager';
|
|
7
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from '@dxos/client';
|
|
2
|
+
import { FunctionTrigger } from '../function';
|
|
3
|
+
export type InvokeOptions = {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
runtime: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class TriggerManager {
|
|
8
|
+
private readonly _client;
|
|
9
|
+
private readonly _triggers;
|
|
10
|
+
private readonly _invokeOptions;
|
|
11
|
+
private readonly _mounts;
|
|
12
|
+
constructor(_client: Client, _triggers: FunctionTrigger[], _invokeOptions: InvokeOptions);
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
private mount;
|
|
16
|
+
private unmount;
|
|
17
|
+
private invokeFunction;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=trigger-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-manager.d.ts","sourceRoot":"","sources":["../../../../src/runtime/trigger-manager.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAoB,MAAM,cAAc,CAAC;AAMxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,cAAc;IAOvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IARjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGiC;gBAGtC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,eAAe,EAAE,EAC5B,cAAc,EAAE,aAAa;IAG1C,KAAK;IAaL,IAAI;YAMI,KAAK;YA4DL,OAAO;YASP,cAAc;CAqB7B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Functions SDK.",
|
|
3
|
+
"version": "0.1.53-main.032dce6",
|
|
4
|
+
"description": "Functions SDK and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,9 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"express": "4.17.1",
|
|
23
23
|
"portfinder": "^1.0.32",
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/
|
|
26
|
-
"@dxos/
|
|
24
|
+
"@dxos/async": "0.1.53-main.032dce6",
|
|
25
|
+
"@dxos/client": "0.1.53-main.032dce6",
|
|
26
|
+
"@dxos/context": "0.1.53-main.032dce6",
|
|
27
|
+
"@dxos/echo-schema": "0.1.53-main.032dce6",
|
|
28
|
+
"@dxos/log": "0.1.53-main.032dce6",
|
|
29
|
+
"@dxos/node-std": "0.1.53-main.032dce6",
|
|
30
|
+
"@dxos/util": "0.1.53-main.032dce6"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"@types/express": "^4.17.17"
|
package/src/function.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Client } from '@dxos/client';
|
|
6
|
+
|
|
7
|
+
export interface Response {
|
|
8
|
+
status(code: number): Response;
|
|
9
|
+
succeed(data?: object): Response;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface FunctionContext {
|
|
13
|
+
client: Client;
|
|
14
|
+
status(code: number): Response;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FunctionHandler {
|
|
18
|
+
(event: any, context: FunctionContext): Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type FunctionsManifest = {
|
|
22
|
+
functions: Record<string, FunctionConfig>;
|
|
23
|
+
triggers: FunctionTrigger[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type FunctionConfig = {
|
|
27
|
+
description?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type FunctionTrigger = {
|
|
31
|
+
function: string;
|
|
32
|
+
subscription: TriggerSubscription;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type TriggerSubscription = {
|
|
36
|
+
type: string;
|
|
37
|
+
spaceKey: string;
|
|
38
|
+
props?: Record<string, any>;
|
|
39
|
+
nested?: string[];
|
|
40
|
+
};
|
package/src/index.ts
CHANGED