@dxos/functions 0.3.9-main.b7e6a67 → 0.3.9-main.c7cd0ec
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 +183 -109
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +179 -113
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/handler.d.ts +20 -2
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/manifest.d.ts +1 -1
- package/dist/types/src/manifest.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts +1 -0
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/scheduler.d.ts +8 -3
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
- package/dist/types/src/runtime/scheduler.test.d.ts +2 -0
- package/dist/types/src/runtime/scheduler.test.d.ts.map +1 -0
- package/package.json +9 -9
- package/src/handler.ts +46 -3
- package/src/manifest.ts +2 -2
- package/src/runtime/dev-server.ts +4 -2
- package/src/runtime/scheduler.test.ts +57 -0
- package/src/runtime/scheduler.ts +99 -73
- package/dist/types/src/function.test.d.ts +0 -2
- package/dist/types/src/function.test.d.ts.map +0 -1
- package/src/function.test.ts +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,23 +29,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
DevServer: () => DevServer,
|
|
32
|
-
Scheduler: () => Scheduler
|
|
32
|
+
Scheduler: () => Scheduler,
|
|
33
|
+
subscriptionHandler: () => subscriptionHandler
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(node_exports);
|
|
36
|
+
var import_client = require("@dxos/client");
|
|
37
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
38
|
+
var import_log = require("@dxos/log");
|
|
39
|
+
var import_util = require("@dxos/util");
|
|
35
40
|
var import_express = __toESM(require("express"));
|
|
36
41
|
var import_get_port_please = require("get-port-please");
|
|
37
42
|
var import_node_path = require("node:path");
|
|
38
43
|
var import_async = require("@dxos/async");
|
|
39
44
|
var import_invariant = require("@dxos/invariant");
|
|
40
|
-
var
|
|
45
|
+
var import_log2 = require("@dxos/log");
|
|
41
46
|
var import_cron = require("cron");
|
|
42
47
|
var import_async2 = require("@dxos/async");
|
|
43
48
|
var import_echo = require("@dxos/client/echo");
|
|
44
49
|
var import_context = require("@dxos/context");
|
|
45
|
-
var
|
|
50
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
46
51
|
var import_invariant2 = require("@dxos/invariant");
|
|
47
|
-
var
|
|
48
|
-
var
|
|
52
|
+
var import_log3 = require("@dxos/log");
|
|
53
|
+
var import_util2 = require("@dxos/util");
|
|
49
54
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
50
55
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
51
56
|
}) : x)(function(x) {
|
|
@@ -53,7 +58,43 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
53
58
|
return require.apply(this, arguments);
|
|
54
59
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
55
60
|
});
|
|
56
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/
|
|
61
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
|
|
62
|
+
var subscriptionHandler = (handler) => {
|
|
63
|
+
return ({ event, context, ...rest }) => {
|
|
64
|
+
const { client } = context;
|
|
65
|
+
const space = event.space ? client.spaces.get(import_client.PublicKey.from(event.space)) : void 0;
|
|
66
|
+
const objects = space && event.objects?.map((id) => space.db.getObjectById(id)).filter(import_util.nonNullable).filter(import_echo_schema.isTypedObject);
|
|
67
|
+
if (!!event.space && !space) {
|
|
68
|
+
import_log.log.warn("invalid space", {
|
|
69
|
+
event
|
|
70
|
+
}, {
|
|
71
|
+
F: __dxlog_file,
|
|
72
|
+
L: 64,
|
|
73
|
+
S: void 0,
|
|
74
|
+
C: (f, a) => f(...a)
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
import_log.log.info("handler", {
|
|
78
|
+
space: space?.key.truncate(),
|
|
79
|
+
objects: objects?.length
|
|
80
|
+
}, {
|
|
81
|
+
F: __dxlog_file,
|
|
82
|
+
L: 66,
|
|
83
|
+
S: void 0,
|
|
84
|
+
C: (f, a) => f(...a)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return handler({
|
|
88
|
+
event: {
|
|
89
|
+
space,
|
|
90
|
+
objects
|
|
91
|
+
},
|
|
92
|
+
context,
|
|
93
|
+
...rest
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/dev-server.ts";
|
|
57
98
|
var DevServer = class {
|
|
58
99
|
// prettier-ignore
|
|
59
100
|
constructor(_client, _options) {
|
|
@@ -64,8 +105,8 @@ var DevServer = class {
|
|
|
64
105
|
}
|
|
65
106
|
get endpoint() {
|
|
66
107
|
(0, import_invariant.invariant)(this._port, void 0, {
|
|
67
|
-
F:
|
|
68
|
-
L:
|
|
108
|
+
F: __dxlog_file2,
|
|
109
|
+
L: 46,
|
|
69
110
|
S: this,
|
|
70
111
|
A: [
|
|
71
112
|
"this._port",
|
|
@@ -85,9 +126,9 @@ var DevServer = class {
|
|
|
85
126
|
try {
|
|
86
127
|
await this._load(def);
|
|
87
128
|
} catch (err) {
|
|
88
|
-
|
|
89
|
-
F:
|
|
90
|
-
L:
|
|
129
|
+
import_log2.log.error("parsing function (check manifest)", err, {
|
|
130
|
+
F: __dxlog_file2,
|
|
131
|
+
L: 63,
|
|
91
132
|
S: this,
|
|
92
133
|
C: (f, a) => f(...a)
|
|
93
134
|
});
|
|
@@ -107,9 +148,9 @@ var DevServer = class {
|
|
|
107
148
|
res.statusCode = await this._invoke(name, req.body);
|
|
108
149
|
res.end();
|
|
109
150
|
} catch (err) {
|
|
110
|
-
|
|
111
|
-
F:
|
|
112
|
-
L:
|
|
151
|
+
import_log2.log.error(`Function failed: ${name}`, err, {
|
|
152
|
+
F: __dxlog_file2,
|
|
153
|
+
L: 83,
|
|
113
154
|
S: this,
|
|
114
155
|
C: (f, a) => f(...a)
|
|
115
156
|
});
|
|
@@ -118,6 +159,7 @@ var DevServer = class {
|
|
|
118
159
|
}
|
|
119
160
|
});
|
|
120
161
|
this._port = await (0, import_get_port_please.getPort)({
|
|
162
|
+
host: "localhost",
|
|
121
163
|
port: 7200,
|
|
122
164
|
portRange: [
|
|
123
165
|
7200,
|
|
@@ -132,12 +174,12 @@ var DevServer = class {
|
|
|
132
174
|
name
|
|
133
175
|
}))
|
|
134
176
|
});
|
|
135
|
-
|
|
177
|
+
import_log2.log.info("registered", {
|
|
136
178
|
registrationId,
|
|
137
179
|
endpoint
|
|
138
180
|
}, {
|
|
139
|
-
F:
|
|
140
|
-
L:
|
|
181
|
+
F: __dxlog_file2,
|
|
182
|
+
L: 99,
|
|
141
183
|
S: this,
|
|
142
184
|
C: (f, a) => f(...a)
|
|
143
185
|
});
|
|
@@ -155,11 +197,11 @@ var DevServer = class {
|
|
|
155
197
|
await this._client.services.services.FunctionRegistryService.unregister({
|
|
156
198
|
registrationId: this._registrationId
|
|
157
199
|
});
|
|
158
|
-
|
|
200
|
+
import_log2.log.info("unregistered", {
|
|
159
201
|
registrationId: this._registrationId
|
|
160
202
|
}, {
|
|
161
|
-
F:
|
|
162
|
-
L:
|
|
203
|
+
F: __dxlog_file2,
|
|
204
|
+
L: 116,
|
|
163
205
|
S: this,
|
|
164
206
|
C: (f, a) => f(...a)
|
|
165
207
|
});
|
|
@@ -178,11 +220,11 @@ var DevServer = class {
|
|
|
178
220
|
async _load(def, flush = false) {
|
|
179
221
|
const { id, name, handler } = def;
|
|
180
222
|
const path = (0, import_node_path.join)(this._options.directory, handler);
|
|
181
|
-
|
|
223
|
+
import_log2.log.info("loading", {
|
|
182
224
|
id
|
|
183
225
|
}, {
|
|
184
|
-
F:
|
|
185
|
-
L:
|
|
226
|
+
F: __dxlog_file2,
|
|
227
|
+
L: 135,
|
|
186
228
|
S: this,
|
|
187
229
|
C: (f, a) => f(...a)
|
|
188
230
|
});
|
|
@@ -204,18 +246,19 @@ var DevServer = class {
|
|
|
204
246
|
async _invoke(name, event) {
|
|
205
247
|
const seq = ++this._seq;
|
|
206
248
|
const now = Date.now();
|
|
207
|
-
|
|
249
|
+
import_log2.log.info("req", {
|
|
208
250
|
seq,
|
|
209
251
|
name
|
|
210
252
|
}, {
|
|
211
|
-
F:
|
|
212
|
-
L:
|
|
253
|
+
F: __dxlog_file2,
|
|
254
|
+
L: 160,
|
|
213
255
|
S: this,
|
|
214
256
|
C: (f, a) => f(...a)
|
|
215
257
|
});
|
|
216
258
|
const { handler } = this._handlers[name];
|
|
217
259
|
const context = {
|
|
218
|
-
client: this._client
|
|
260
|
+
client: this._client,
|
|
261
|
+
dataDir: this._options.dataDir
|
|
219
262
|
};
|
|
220
263
|
let statusCode = 200;
|
|
221
264
|
const response = {
|
|
@@ -229,27 +272,27 @@ var DevServer = class {
|
|
|
229
272
|
event,
|
|
230
273
|
response
|
|
231
274
|
});
|
|
232
|
-
|
|
275
|
+
import_log2.log.info("res", {
|
|
233
276
|
seq,
|
|
234
277
|
name,
|
|
235
278
|
statusCode,
|
|
236
279
|
duration: Date.now() - now
|
|
237
280
|
}, {
|
|
238
|
-
F:
|
|
239
|
-
L:
|
|
281
|
+
F: __dxlog_file2,
|
|
282
|
+
L: 177,
|
|
240
283
|
S: this,
|
|
241
284
|
C: (f, a) => f(...a)
|
|
242
285
|
});
|
|
243
286
|
return statusCode;
|
|
244
287
|
}
|
|
245
288
|
};
|
|
246
|
-
var
|
|
289
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/scheduler.ts";
|
|
247
290
|
var Scheduler = class {
|
|
248
|
-
constructor(_client, _manifest, _options) {
|
|
291
|
+
constructor(_client, _manifest, _options = {}) {
|
|
249
292
|
this._client = _client;
|
|
250
293
|
this._manifest = _manifest;
|
|
251
294
|
this._options = _options;
|
|
252
|
-
this._mounts = new
|
|
295
|
+
this._mounts = new import_util2.ComplexMap(({ id, spaceKey }) => `${spaceKey.toHex()}:${id}`);
|
|
253
296
|
}
|
|
254
297
|
async start() {
|
|
255
298
|
this._client.spaces.subscribe(async (spaces) => {
|
|
@@ -273,8 +316,8 @@ var Scheduler = class {
|
|
|
273
316
|
};
|
|
274
317
|
const def = this._manifest.functions.find((config) => config.id === trigger.function);
|
|
275
318
|
(0, import_invariant2.invariant)(def, `Function not found: ${trigger.function}`, {
|
|
276
|
-
F:
|
|
277
|
-
L:
|
|
319
|
+
F: __dxlog_file3,
|
|
320
|
+
L: 63,
|
|
278
321
|
S: this,
|
|
279
322
|
A: [
|
|
280
323
|
"def",
|
|
@@ -287,12 +330,12 @@ var Scheduler = class {
|
|
|
287
330
|
ctx,
|
|
288
331
|
trigger
|
|
289
332
|
});
|
|
290
|
-
|
|
333
|
+
(0, import_log3.log)("mount", {
|
|
291
334
|
space: space.key,
|
|
292
335
|
trigger
|
|
293
336
|
}, {
|
|
294
|
-
F:
|
|
295
|
-
L:
|
|
337
|
+
F: __dxlog_file3,
|
|
338
|
+
L: 69,
|
|
296
339
|
S: this,
|
|
297
340
|
C: (f, a) => f(...a)
|
|
298
341
|
});
|
|
@@ -300,63 +343,10 @@ var Scheduler = class {
|
|
|
300
343
|
return;
|
|
301
344
|
}
|
|
302
345
|
if (trigger.schedule) {
|
|
303
|
-
|
|
304
|
-
await this.execFunction(def, {
|
|
305
|
-
space: space.key
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
const job = new import_cron.CronJob(trigger.schedule, () => task.schedule());
|
|
309
|
-
job.start();
|
|
310
|
-
ctx.onDispose(() => job.stop());
|
|
346
|
+
this._createTimer(ctx, space, def, trigger);
|
|
311
347
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
315
|
-
await this.execFunction(def, {
|
|
316
|
-
space: space.key,
|
|
317
|
-
objects: Array.from(objectIds)
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
const subscriptions = [];
|
|
321
|
-
const subscription = (0, import_echo_schema.createSubscription)(({ added, updated }) => {
|
|
322
|
-
for (const object of added) {
|
|
323
|
-
objectIds.add(object.id);
|
|
324
|
-
}
|
|
325
|
-
for (const object of updated) {
|
|
326
|
-
objectIds.add(object.id);
|
|
327
|
-
}
|
|
328
|
-
task.schedule();
|
|
329
|
-
});
|
|
330
|
-
subscriptions.push(() => subscription.unsubscribe());
|
|
331
|
-
const { type, props, deep, delay } = trigger.subscription;
|
|
332
|
-
const update = ({ objects }) => {
|
|
333
|
-
subscription.update(objects);
|
|
334
|
-
if (deep) {
|
|
335
|
-
import_log2.log.info("update", {
|
|
336
|
-
type,
|
|
337
|
-
deep,
|
|
338
|
-
objects: objects.length
|
|
339
|
-
}, {
|
|
340
|
-
F: __dxlog_file2,
|
|
341
|
-
L: 114,
|
|
342
|
-
S: this,
|
|
343
|
-
C: (f, a) => f(...a)
|
|
344
|
-
});
|
|
345
|
-
for (const object of objects) {
|
|
346
|
-
const content = object.content;
|
|
347
|
-
if (content instanceof import_echo.TextObject) {
|
|
348
|
-
subscriptions.push(content[import_echo_schema.subscribe]((0, import_async2.debounce)(() => subscription.update([
|
|
349
|
-
object
|
|
350
|
-
]), 1e3)));
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
const query = space.db.query(import_echo_schema.Filter.typename(type, props));
|
|
356
|
-
subscriptions.push(query.subscribe(delay ? (0, import_async2.debounce)(update, delay * 1e3) : update));
|
|
357
|
-
ctx.onDispose(() => {
|
|
358
|
-
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
359
|
-
});
|
|
348
|
+
for (const triggerSubscription of trigger.subscriptions ?? []) {
|
|
349
|
+
this._createSubscription(ctx, space, def, triggerSubscription);
|
|
360
350
|
}
|
|
361
351
|
}
|
|
362
352
|
}
|
|
@@ -371,39 +361,114 @@ var Scheduler = class {
|
|
|
371
361
|
await ctx.dispose();
|
|
372
362
|
}
|
|
373
363
|
}
|
|
374
|
-
|
|
364
|
+
_createTimer(ctx, space, def, trigger) {
|
|
365
|
+
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
366
|
+
await this._execFunction(def, {
|
|
367
|
+
space: space.key
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
(0, import_invariant2.invariant)(trigger.schedule, void 0, {
|
|
371
|
+
F: __dxlog_file3,
|
|
372
|
+
L: 103,
|
|
373
|
+
S: this,
|
|
374
|
+
A: [
|
|
375
|
+
"trigger.schedule",
|
|
376
|
+
""
|
|
377
|
+
]
|
|
378
|
+
});
|
|
379
|
+
const job = new import_cron.CronJob(trigger.schedule, () => task.schedule());
|
|
380
|
+
job.start();
|
|
381
|
+
ctx.onDispose(() => job.stop());
|
|
382
|
+
}
|
|
383
|
+
_createSubscription(ctx, space, def, triggerSubscription) {
|
|
384
|
+
const objectIds = /* @__PURE__ */ new Set();
|
|
385
|
+
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
386
|
+
await this._execFunction(def, {
|
|
387
|
+
space: space.key,
|
|
388
|
+
objects: Array.from(objectIds)
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
const subscriptions = [];
|
|
392
|
+
const subscription = (0, import_echo_schema2.createSubscription)(({ added, updated }) => {
|
|
393
|
+
for (const object of added) {
|
|
394
|
+
objectIds.add(object.id);
|
|
395
|
+
}
|
|
396
|
+
for (const object of updated) {
|
|
397
|
+
objectIds.add(object.id);
|
|
398
|
+
}
|
|
399
|
+
task.schedule();
|
|
400
|
+
});
|
|
401
|
+
subscriptions.push(() => subscription.unsubscribe());
|
|
402
|
+
const { type, props, deep, delay } = triggerSubscription;
|
|
403
|
+
const update = ({ objects }) => {
|
|
404
|
+
subscription.update(objects);
|
|
405
|
+
if (deep) {
|
|
406
|
+
import_log3.log.info("update", {
|
|
407
|
+
type,
|
|
408
|
+
deep,
|
|
409
|
+
objects: objects.length
|
|
410
|
+
}, {
|
|
411
|
+
F: __dxlog_file3,
|
|
412
|
+
L: 142,
|
|
413
|
+
S: this,
|
|
414
|
+
C: (f, a) => f(...a)
|
|
415
|
+
});
|
|
416
|
+
for (const object of objects) {
|
|
417
|
+
const content = object.content;
|
|
418
|
+
if (content instanceof import_echo.TextObject) {
|
|
419
|
+
subscriptions.push(content[import_echo_schema2.subscribe]((0, import_async2.debounce)(() => subscription.update([
|
|
420
|
+
object
|
|
421
|
+
]), 1e3)));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const query = space.db.query(import_echo_schema2.Filter.typename(type, props));
|
|
427
|
+
subscriptions.push(query.subscribe(delay ? (0, import_async2.debounce)(update, delay * 1e3) : update));
|
|
428
|
+
ctx.onDispose(() => {
|
|
429
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async _execFunction(def, data) {
|
|
375
433
|
try {
|
|
376
|
-
(0,
|
|
434
|
+
(0, import_log3.log)("request", {
|
|
377
435
|
function: def.id
|
|
378
436
|
}, {
|
|
379
|
-
F:
|
|
380
|
-
L:
|
|
437
|
+
F: __dxlog_file3,
|
|
438
|
+
L: 164,
|
|
381
439
|
S: this,
|
|
382
440
|
C: (f, a) => f(...a)
|
|
383
441
|
});
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
442
|
+
const { endpoint, callback } = this._options;
|
|
443
|
+
let status = 0;
|
|
444
|
+
if (endpoint) {
|
|
445
|
+
const response = await fetch(`${this._options.endpoint}/${def.name}`, {
|
|
446
|
+
method: "POST",
|
|
447
|
+
headers: {
|
|
448
|
+
"Content-Type": "application/json"
|
|
449
|
+
},
|
|
450
|
+
body: JSON.stringify(data)
|
|
451
|
+
});
|
|
452
|
+
status = response.status;
|
|
453
|
+
} else if (callback) {
|
|
454
|
+
status = await callback(data);
|
|
455
|
+
}
|
|
456
|
+
(0, import_log3.log)("result", {
|
|
392
457
|
function: def.id,
|
|
393
|
-
result:
|
|
458
|
+
result: status
|
|
394
459
|
}, {
|
|
395
|
-
F:
|
|
396
|
-
L:
|
|
460
|
+
F: __dxlog_file3,
|
|
461
|
+
L: 183,
|
|
397
462
|
S: this,
|
|
398
463
|
C: (f, a) => f(...a)
|
|
399
464
|
});
|
|
400
465
|
} catch (err) {
|
|
401
|
-
|
|
466
|
+
import_log3.log.error("error", {
|
|
402
467
|
function: def.id,
|
|
403
468
|
error: err.message
|
|
404
469
|
}, {
|
|
405
|
-
F:
|
|
406
|
-
L:
|
|
470
|
+
F: __dxlog_file3,
|
|
471
|
+
L: 185,
|
|
407
472
|
S: this,
|
|
408
473
|
C: (f, a) => f(...a)
|
|
409
474
|
});
|
|
@@ -413,6 +478,7 @@ var Scheduler = class {
|
|
|
413
478
|
// Annotate the CommonJS export names for ESM import in node:
|
|
414
479
|
0 && (module.exports = {
|
|
415
480
|
DevServer,
|
|
416
|
-
Scheduler
|
|
481
|
+
Scheduler,
|
|
482
|
+
subscriptionHandler
|
|
417
483
|
});
|
|
418
484
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/runtime/dev-server.ts", "../../../src/runtime/scheduler.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 reload?: boolean;\n};\n\n/**\n * Functions dev server provides a local HTTP server for testing functions.\n */\nexport class DevServer {\n // Function handlers indexed by name (URL path).\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 private _seq = 0;\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 try {\n await this._load(def);\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 try {\n if (this._options.reload) {\n const { def } = this._handlers[name];\n await this._load(def, true);\n }\n\n res.statusCode = await this._invoke(name, req.body);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = await getPort({ port: 7200, portRange: [7200, 7299] });\n this._server = app.listen(this._port);\n\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: { name } }) => ({ name })),\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 * Load function.\n */\n private async _load(def: FunctionDef, flush = false) {\n const { id, name, handler } = def;\n const path = join(this._options.directory, handler);\n log.info('loading', { id });\n\n // Remove from cache.\n if (flush) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(path))\n .forEach((key) => delete require.cache[key]);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(path);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${id}`);\n }\n\n this._handlers[name] = { def, handler: module.default };\n }\n\n /**\n * Invoke function handler.\n */\n private async _invoke(name: string, event: any) {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, name });\n const { handler } = this._handlers[name];\n\n const context: FunctionContext = {\n client: this._client,\n };\n\n let statusCode = 200;\n const response: Response = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n log.info('res', { seq, name, statusCode, duration: Date.now() - now });\n\n return statusCode;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { debounce, DeferredTask } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { type Space, TextObject } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Filter, createSubscription, type Query, subscribe } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../manifest';\n\ntype SchedulerOptions = {\n endpoint: string;\n};\n\n/**\n * Functions scheduler.\n */\n// TODO(burdon): Create tests.\nexport class Scheduler {\n // Map of mounted functions.\n private readonly _mounts = new ComplexMap<\n { id: string; spaceKey: PublicKey },\n { ctx: Context; trigger: FunctionTrigger }\n >(({ id, spaceKey }) => `${spaceKey.toHex()}:${id}`);\n\n constructor(\n private readonly _client: Client,\n private readonly _manifest: FunctionManifest,\n private readonly _options: SchedulerOptions,\n ) {}\n\n async start() {\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 await this.mount(new Context(), space, trigger);\n }\n }\n });\n }\n\n async stop() {\n for (const { id, spaceKey } of this._mounts.keys()) {\n await this.unmount(id, spaceKey);\n }\n }\n\n private async mount(ctx: Context, space: Space, trigger: FunctionTrigger) {\n const key = { id: trigger.function, spaceKey: space.key };\n const def = this._manifest.functions.find((config) => config.id === trigger.function);\n invariant(def, `Function not found: ${trigger.function}`);\n\n const exists = this._mounts.get(key);\n if (!exists) {\n this._mounts.set(key, { ctx, trigger });\n log.info('mount', { space: space.key, trigger });\n if (ctx.disposed) {\n return;\n }\n\n // Cron schedule.\n if (trigger.schedule) {\n const task = new DeferredTask(ctx, async () => {\n await this.execFunction(def, {\n space: space.key,\n });\n });\n\n // TODO(burdon): Check greater than 30s min (use cron-parser).\n const job = new CronJob(trigger.schedule, () => task.schedule());\n\n job.start();\n ctx.onDispose(() => job.stop());\n }\n\n // ECHO subscription.\n if (trigger.subscription) {\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this.execFunction(def, {\n space: space.key,\n objects: Array.from(objectIds),\n });\n });\n\n // TODO(burdon): Standardize subscription handles.\n const subscriptions: (() => void)[] = [];\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 task.schedule();\n });\n subscriptions.push(() => subscription.unsubscribe());\n\n const { type, props, deep, delay } = trigger.subscription;\n const update = ({ objects }: Query) => {\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n log.info('update', { type, deep, objects: objects.length });\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextObject) {\n subscriptions.push(content[subscribe](debounce(() => subscription.update([object]), 1_000)));\n }\n }\n }\n };\n\n // TODO(burdon): [Bug]: all callbacks are fired on the first mutation.\n // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).\n const query = space.db.query(Filter.typename(type, props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay * 1_000) : update));\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n }\n }\n }\n\n private async unmount(id: string, spaceKey: PublicKey) {\n const key = { id, 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(def: FunctionDef, data: any) {\n try {\n log('request', { function: def.id });\n const response = await fetch(`${this._options.endpoint}/${def.name}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(data),\n });\n\n // const result = await response.json();\n log('result', { function: def.id, result: response.status });\n } catch (err: any) {\n log.error('error', { function: def.id, error: err.message });\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_async", "import_invariant", "
|
|
3
|
+
"sources": ["../../../src/handler.ts", "../../../src/runtime/dev-server.ts", "../../../src/runtime/scheduler.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { isTypedObject, type TypedObject } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\n// TODO(burdon): No response?\nexport interface Response {\n status(code: number): Response;\n}\n\n// TODO(burdon): Limit access to individual space?\nexport interface FunctionContext {\n client: Client;\n dataDir?: string;\n}\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\nexport type FunctionHandler<T extends {}> = (params: {\n event: T;\n context: FunctionContext;\n response: Response;\n}) => Promise<Response | void>;\n\nexport type FunctionSubscriptionEvent = {\n space?: string; // TODO(burdon): Convert to PublicKey.\n objects?: string[];\n};\n\nexport type FunctionSubscriptionEvent2 = {\n space?: Space;\n objects?: TypedObject[];\n};\n\n/**\n * Handler wrapper for subscription events; extracts space and objects.\n *\n * To test:\n * ```\n * curl -s -X POST -H \"Content-Type: application/json\" --data '{\"space\": \"0446...1cbb\"}' http://localhost:7100/dev/email-extractor\n * ```\n *\n * NOTE: Get space key from devtools or `dx space list --json`\n */\nexport const subscriptionHandler = (\n handler: FunctionHandler<FunctionSubscriptionEvent2>,\n): FunctionHandler<FunctionSubscriptionEvent> => {\n return ({ event, context, ...rest }) => {\n const { client } = context;\n const space = event.space ? client.spaces.get(PublicKey.from(event.space)) : undefined;\n const objects =\n space &&\n event.objects\n ?.map<TypedObject | undefined>((id) => space!.db.getObjectById(id))\n .filter(nonNullable)\n .filter(isTypedObject);\n\n if (!!event.space && !space) {\n log.warn('invalid space', { event });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { space, objects }, context, ...rest });\n };\n};\n", "//\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 reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for testing functions.\n */\nexport class DevServer {\n // Function handlers indexed by name (URL path).\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 private _seq = 0;\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 try {\n await this._load(def);\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 try {\n if (this._options.reload) {\n const { def } = this._handlers[name];\n await this._load(def, true);\n }\n\n res.statusCode = await this._invoke(name, req.body);\n res.end();\n } catch (err: any) {\n log.error(`Function failed: ${name}`, err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = await getPort({ host: 'localhost', port: 7200, portRange: [7200, 7299] });\n this._server = app.listen(this._port);\n\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: { name } }) => ({ name })),\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 * Load function.\n */\n private async _load(def: FunctionDef, flush = false) {\n const { id, name, handler } = def;\n const path = join(this._options.directory, handler);\n log.info('loading', { id });\n\n // Remove from cache.\n if (flush) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(path))\n .forEach((key) => delete require.cache[key]);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(path);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${id}`);\n }\n\n this._handlers[name] = { def, handler: module.default };\n }\n\n /**\n * Invoke function handler.\n */\n private async _invoke(name: string, event: any) {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, name });\n const { handler } = this._handlers[name];\n\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n };\n\n let statusCode = 200;\n const response: Response = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n log.info('res', { seq, name, statusCode, duration: Date.now() - now });\n\n return statusCode;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { debounce, DeferredTask } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { type Space, TextObject } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Filter, createSubscription, type Query, subscribe } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type FunctionSubscriptionEvent } from '../handler';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger, type TriggerSubscription } from '../manifest';\n\ntype Callback = (data: FunctionSubscriptionEvent) => Promise<number>;\n\ntype SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * Functions scheduler.\n */\n// TODO(burdon): Create tests.\nexport class Scheduler {\n // Map of mounted functions.\n private readonly _mounts = new ComplexMap<\n { id: string; spaceKey: PublicKey },\n { ctx: Context; trigger: FunctionTrigger }\n >(({ id, spaceKey }) => `${spaceKey.toHex()}:${id}`);\n\n constructor(\n private readonly _client: Client,\n private readonly _manifest: FunctionManifest,\n private readonly _options: SchedulerOptions = {},\n ) {}\n\n async start() {\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 await this.mount(new Context(), space, trigger);\n }\n }\n });\n }\n\n async stop() {\n for (const { id, spaceKey } of this._mounts.keys()) {\n await this.unmount(id, spaceKey);\n }\n }\n\n private async mount(ctx: Context, space: Space, trigger: FunctionTrigger) {\n const key = { id: trigger.function, spaceKey: space.key };\n const def = this._manifest.functions.find((config) => config.id === trigger.function);\n invariant(def, `Function not found: ${trigger.function}`);\n\n // Currently supports only one trigger declaration per 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 // Timer.\n if (trigger.schedule) {\n this._createTimer(ctx, space, def, trigger);\n }\n\n // Subscription.\n for (const triggerSubscription of trigger.subscriptions ?? []) {\n this._createSubscription(ctx, space, def, triggerSubscription);\n }\n }\n }\n\n private async unmount(id: string, spaceKey: PublicKey) {\n const key = { id, 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 _createTimer(ctx: Context, space: Space, def: FunctionDef, trigger: FunctionTrigger) {\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, {\n space: space.key,\n });\n });\n\n // TODO(burdon): Check greater than 30s min (use cron-parser).\n invariant(trigger.schedule);\n const job = new CronJob(trigger.schedule, () => task.schedule());\n\n job.start();\n ctx.onDispose(() => job.stop());\n }\n\n private _createSubscription(ctx: Context, space: Space, def: FunctionDef, triggerSubscription: TriggerSubscription) {\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, {\n space: space.key,\n objects: Array.from(objectIds),\n });\n });\n\n // TODO(burdon): Don't fire initially.\n // TODO(burdon): Standardize subscription handles.\n const subscriptions: (() => void)[] = [];\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 task.schedule();\n });\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n // TODO(burdon): Disable trigger if keeps failing.\n const { type, props, deep, delay } = triggerSubscription;\n const update = ({ objects }: Query) => {\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n log.info('update', { type, deep, objects: objects.length });\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextObject) {\n subscriptions.push(content[subscribe](debounce(() => subscription.update([object]), 1_000)));\n }\n }\n }\n };\n\n // TODO(burdon): [Bug]: all callbacks are fired on the first mutation.\n // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).\n const query = space.db.query(Filter.typename(type, props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay * 1_000) : update));\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n }\n\n private async _execFunction(def: FunctionDef, data: any) {\n try {\n log('request', { function: def.id });\n const { endpoint, callback } = this._options;\n let status = 0;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const response = await fetch(`${this._options.endpoint}/${def.name}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(data),\n });\n\n status = response.status;\n } else if (callback) {\n status = await callback(data);\n }\n\n // const result = await response.json();\n log('result', { function: def.id, result: status });\n } catch (err: any) {\n log.error('error', { function: def.id, error: err.message });\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuC;AAEvC,yBAAgD;AAChD,iBAAoB;AACpB,kBAA4B;ACJ5B,qBAAoB;AACpB,6BAAwB;AAExB,uBAAqB;AAErB,mBAAwB;AAExB,uBAA0B;AAC1B,IAAAA,cAAoB;ACRpB,kBAAwB;AAExB,IA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V,MAAMC,KAAAA,CAAAA;AACnDtB,kBAAcmB,KAAKU,MAAM7C,UAAUwC,YAAQI,wBAASH,QAAQD,QAAQ,GAAA,IAASC,MAAAA,CAAAA;AAE7EnC,QAAImB,UAAU,MAAA;AACZT,oBAAcjC,QAAQ,CAACqD,gBAAgBA,YAAAA,CAAAA;IACzC,CAAA;EACF;EAEA,MAAcd,cAActF,KAAkBgH,MAAW;AACvD,QAAI;AACFrI,sBAAAA,KAAI,WAAW;QAAE4F,UAAUvE,IAAI3B;MAAG,GAAA;;;;;;AAClC,YAAM,EAAEkB,UAAU0H,SAAQ,IAAK,KAAK7H;AACpC,UAAImE,SAAS;AACb,UAAIhE,UAAU;AAEZ,cAAM+D,WAAW,MAAM4D,MAAM,GAAG,KAAK9H,SAASG,QAAQ,IAAIS,IAAIa,IAAI,IAAI;UACpEsG,QAAQ;UACRC,SAAS;YACP,gBAAgB;UAClB;UACAlG,MAAMmG,KAAKC,UAAUN,IAAAA;QACvB,CAAA;AAEAzD,iBAASD,SAASC;MACpB,WAAW0D,UAAU;AACnB1D,iBAAS,MAAM0D,SAASD,IAAAA;MAC1B;AAGArI,sBAAAA,KAAI,UAAU;QAAE4F,UAAUvE,IAAI3B;QAAIkJ,QAAQhE;MAAO,GAAA;;;;;;IACnD,SAASpD,KAAU;AACjBxB,kBAAAA,IAAIyB,MAAM,SAAS;QAAEmE,UAAUvE,IAAI3B;QAAI+B,OAAOD,IAAIqH;MAAQ,GAAA;;;;;;IAC5D;EACF;AACF;",
|
|
6
|
+
"names": ["import_log", "import_async", "import_echo_schema", "import_invariant", "import_util", "subscriptionHandler", "handler", "event", "context", "rest", "client", "space", "spaces", "get", "PublicKey", "from", "undefined", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "isTypedObject", "log", "warn", "info", "key", "truncate", "length", "DevServer", "constructor", "_client", "_options", "_handlers", "_seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "initialize", "def", "manifest", "_load", "err", "error", "start", "app", "express", "use", "json", "post", "req", "res", "name", "params", "reload", "statusCode", "_invoke", "body", "end", "getPort", "host", "port", "portRange", "_server", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_registrationId", "stop", "Error", "trigger", "Trigger", "close", "unregister", "wake", "wait", "flush", "path", "join", "directory", "keys", "require", "cache", "startsWith", "forEach", "module", "default", "seq", "now", "Date", "dataDir", "response", "status", "code", "duration", "Scheduler", "_manifest", "_mounts", "ComplexMap", "spaceKey", "toHex", "subscribe", "waitUntilReady", "triggers", "mount", "Context", "unmount", "ctx", "function", "find", "config", "exists", "set", "disposed", "schedule", "_createTimer", "triggerSubscription", "subscriptions", "_createSubscription", "delete", "dispose", "task", "DeferredTask", "_execFunction", "job", "CronJob", "onDispose", "objectIds", "Set", "Array", "subscription", "createSubscription", "added", "updated", "object", "add", "push", "unsubscribe", "type", "props", "deep", "delay", "update", "content", "TextObject", "debounce", "query", "Filter", "typename", "data", "callback", "fetch", "method", "headers", "JSON", "stringify", "result", "message"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/functions/src/handler.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/functions/src/handler.ts":{"bytes":6074,"imports":[{"path":"@dxos/client","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}],"format":"esm"},"packages/core/functions/src/manifest.ts":{"bytes":1863,"imports":[],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":18932,"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/scheduler.ts":{"bytes":22961,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","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":566,"imports":[{"path":"packages/core/functions/src/runtime/dev-server.ts","kind":"import-statement","original":"./dev-server"},{"path":"packages/core/functions/src/runtime/scheduler.ts","kind":"import-statement","original":"./scheduler"}],"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":22942},"packages/core/functions/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/client","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},{"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":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","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","Scheduler","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/handler.ts":{"bytesInOutput":1130},"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4836},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5475}},"bytes":12055}}}
|