@dxos/functions 0.7.0 → 0.7.1-staging.7f6f91c
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/{chunk-7QJNOQ6N.mjs → chunk-FWIFI2MH.mjs} +57 -32
- package/dist/lib/browser/chunk-FWIFI2MH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-L7H5DE53.mjs → chunk-QX2SGAWR.mjs} +28 -21
- package/dist/lib/browser/chunk-QX2SGAWR.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +9 -5
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +6 -6
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types.mjs +9 -5
- package/dist/lib/node/{chunk-TNG3Z74V.cjs → chunk-GKDHAWCP.cjs} +61 -34
- package/dist/lib/node/chunk-GKDHAWCP.cjs.map +7 -0
- package/dist/lib/node/{chunk-3KJEM5VR.cjs → chunk-OKV7IWWB.cjs} +41 -34
- package/dist/lib/node/chunk-OKV7IWWB.cjs.map +7 -0
- package/dist/lib/node/index.cjs +17 -13
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -13
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node/types.cjs +11 -7
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/{chunk-DMTGUST2.mjs → chunk-SPHZ5SOR.mjs} +28 -21
- package/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLC6ICH2.mjs → chunk-YSKH6PBN.mjs} +57 -32
- package/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +9 -5
- package/dist/lib/node-esm/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +6 -6
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types.mjs +9 -5
- package/dist/types/src/trigger/trigger-registry.d.ts +3 -3
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +137 -72
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +17 -16
- package/schema/functions.json +2 -2
- package/src/runtime/scheduler.test.ts +1 -1
- package/src/runtime/scheduler.ts +1 -1
- package/src/testing/functions-integration.test.ts +1 -1
- package/src/testing/util.ts +2 -2
- package/src/trigger/trigger-registry.test.ts +7 -9
- package/src/trigger/trigger-registry.ts +7 -8
- package/src/trigger/type/subscription-trigger.ts +2 -2
- package/src/types.ts +70 -36
- package/dist/lib/browser/chunk-7QJNOQ6N.mjs.map +0 -7
- package/dist/lib/browser/chunk-L7H5DE53.mjs.map +0 -7
- package/dist/lib/node/chunk-3KJEM5VR.cjs.map +0 -7
- package/dist/lib/node/chunk-TNG3Z74V.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DMTGUST2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLC6ICH2.mjs.map +0 -7
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_OKV7IWWB_exports = {};
|
|
20
|
+
__export(chunk_OKV7IWWB_exports, {
|
|
21
21
|
FunctionRegistry: () => FunctionRegistry,
|
|
22
22
|
TriggerRegistry: () => TriggerRegistry,
|
|
23
23
|
createSubscriptionTrigger: () => createSubscriptionTrigger,
|
|
@@ -25,8 +25,8 @@ __export(chunk_3KJEM5VR_exports, {
|
|
|
25
25
|
createWebSocket: () => createWebSocket,
|
|
26
26
|
createWebsocketTrigger: () => createWebsocketTrigger
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
29
|
-
var
|
|
28
|
+
module.exports = __toCommonJS(chunk_OKV7IWWB_exports);
|
|
29
|
+
var import_chunk_GKDHAWCP = require("./chunk-GKDHAWCP.cjs");
|
|
30
30
|
var import_async = require("@dxos/async");
|
|
31
31
|
var import_echo = require("@dxos/client/echo");
|
|
32
32
|
var import_context = require("@dxos/context");
|
|
@@ -89,14 +89,14 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
89
89
|
if (!functions?.length) {
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
92
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_GKDHAWCP.FunctionDef)) {
|
|
93
93
|
space.db.graph.schemaRegistry.addSchema([
|
|
94
|
-
|
|
94
|
+
import_chunk_GKDHAWCP.FunctionDef
|
|
95
95
|
]);
|
|
96
96
|
}
|
|
97
|
-
const { objects: existing } = await space.db.query(import_echo.Filter.schema(
|
|
97
|
+
const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_GKDHAWCP.FunctionDef)).run();
|
|
98
98
|
const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
|
|
99
|
-
added.forEach((def) => space.db.add((0, import_echo.create)(
|
|
99
|
+
added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_GKDHAWCP.FunctionDef, def)));
|
|
100
100
|
if (added.length > 0) {
|
|
101
101
|
await space.db.flush({
|
|
102
102
|
indexes: true,
|
|
@@ -122,7 +122,7 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
122
122
|
if (this._ctx.disposed) {
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
|
-
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(
|
|
125
|
+
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_GKDHAWCP.FunctionDef)).subscribe(({ objects }) => {
|
|
126
126
|
const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
|
|
127
127
|
if (added.length > 0) {
|
|
128
128
|
registered.push(...added);
|
|
@@ -205,8 +205,8 @@ var createSubscriptionTrigger = async (ctx, space, spec, callback) => {
|
|
|
205
205
|
S: void 0,
|
|
206
206
|
C: (f, a) => f(...a)
|
|
207
207
|
});
|
|
208
|
-
if (filter) {
|
|
209
|
-
const query = space.db.query(import_echo2.Filter.typename(filter
|
|
208
|
+
if (filter.type) {
|
|
209
|
+
const query = space.db.query(import_echo2.Filter.typename(filter.type, filter.props));
|
|
210
210
|
subscriptions.push(query.subscribe(delay ? (0, import_async2.debounce)(update, delay) : update));
|
|
211
211
|
}
|
|
212
212
|
ctx.onDispose(() => {
|
|
@@ -371,12 +371,10 @@ var createWebSocket = async (url) => {
|
|
|
371
371
|
};
|
|
372
372
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/trigger-registry.ts";
|
|
373
373
|
var triggerFactory = {
|
|
374
|
-
subscription: createSubscriptionTrigger,
|
|
375
374
|
timer: createTimerTrigger,
|
|
376
375
|
// TODO(burdon): Cannot use in browser.
|
|
377
376
|
// webhook: createWebhookTrigger,
|
|
378
|
-
|
|
379
|
-
websocket: createWebsocketTrigger
|
|
377
|
+
subscription: createSubscriptionTrigger
|
|
380
378
|
};
|
|
381
379
|
var TriggerRegistry = class extends import_context2.Resource {
|
|
382
380
|
constructor(_client, _options) {
|
|
@@ -402,7 +400,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
402
400
|
trigger
|
|
403
401
|
}, {
|
|
404
402
|
F: __dxlog_file5,
|
|
405
|
-
L:
|
|
403
|
+
L: 75,
|
|
406
404
|
S: this,
|
|
407
405
|
C: (f, a) => f(...a)
|
|
408
406
|
});
|
|
@@ -410,13 +408,13 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
410
408
|
name: `FunctionTrigger-${trigger.function}`
|
|
411
409
|
}, {
|
|
412
410
|
F: __dxlog_file5,
|
|
413
|
-
L:
|
|
411
|
+
L: 77
|
|
414
412
|
});
|
|
415
413
|
this._ctx.onDispose(() => activationCtx.dispose());
|
|
416
414
|
const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);
|
|
417
415
|
(0, import_invariant.invariant)(registeredTrigger, `Trigger is not registered: ${trigger.function}`, {
|
|
418
416
|
F: __dxlog_file5,
|
|
419
|
-
L:
|
|
417
|
+
L: 80,
|
|
420
418
|
S: this,
|
|
421
419
|
A: [
|
|
422
420
|
"registeredTrigger",
|
|
@@ -425,11 +423,20 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
425
423
|
});
|
|
426
424
|
registeredTrigger.activationCtx = activationCtx;
|
|
427
425
|
try {
|
|
426
|
+
(0, import_invariant.invariant)(trigger.spec, void 0, {
|
|
427
|
+
F: __dxlog_file5,
|
|
428
|
+
L: 85,
|
|
429
|
+
S: this,
|
|
430
|
+
A: [
|
|
431
|
+
"trigger.spec",
|
|
432
|
+
""
|
|
433
|
+
]
|
|
434
|
+
});
|
|
428
435
|
const options = this._options?.[trigger.spec.type];
|
|
429
436
|
const createTrigger = triggerFactory[trigger.spec.type];
|
|
430
437
|
(0, import_invariant.invariant)(createTrigger, `Trigger factory not found: ${trigger.spec.type}`, {
|
|
431
438
|
F: __dxlog_file5,
|
|
432
|
-
L:
|
|
439
|
+
L: 88,
|
|
433
440
|
S: this,
|
|
434
441
|
A: [
|
|
435
442
|
"createTrigger",
|
|
@@ -450,16 +457,16 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
450
457
|
space: space.key
|
|
451
458
|
}, {
|
|
452
459
|
F: __dxlog_file5,
|
|
453
|
-
L:
|
|
460
|
+
L: 100,
|
|
454
461
|
S: this,
|
|
455
462
|
C: (f, a) => f(...a)
|
|
456
463
|
});
|
|
457
464
|
if (!manifest.triggers?.length) {
|
|
458
465
|
return;
|
|
459
466
|
}
|
|
460
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
467
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_GKDHAWCP.FunctionTrigger)) {
|
|
461
468
|
space.db.graph.schemaRegistry.addSchema([
|
|
462
|
-
|
|
469
|
+
import_chunk_GKDHAWCP.FunctionTrigger
|
|
463
470
|
]);
|
|
464
471
|
}
|
|
465
472
|
const manifestTriggers = manifest.triggers.map((trigger) => {
|
|
@@ -469,15 +476,15 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
469
476
|
keys = [
|
|
470
477
|
(0, import_echo_schema.foreignKey)("manifest", [
|
|
471
478
|
trigger.function,
|
|
472
|
-
trigger.spec
|
|
479
|
+
trigger.spec?.type
|
|
473
480
|
].join(":"))
|
|
474
481
|
];
|
|
475
482
|
}
|
|
476
|
-
return (0, import_echo3.create)(
|
|
483
|
+
return (0, import_echo3.create)(import_chunk_GKDHAWCP.FunctionTrigger, trigger, {
|
|
477
484
|
keys
|
|
478
485
|
});
|
|
479
486
|
});
|
|
480
|
-
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(
|
|
487
|
+
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_GKDHAWCP.FunctionTrigger)).run();
|
|
481
488
|
const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo_schema.compareForeignKeys);
|
|
482
489
|
added.forEach((trigger) => {
|
|
483
490
|
space.db.add(trigger);
|
|
@@ -485,7 +492,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
485
492
|
meta: (0, import_echo3.getMeta)(trigger)
|
|
486
493
|
}, {
|
|
487
494
|
F: __dxlog_file5,
|
|
488
|
-
L:
|
|
495
|
+
L: 127,
|
|
489
496
|
S: this,
|
|
490
497
|
C: (f, a) => f(...a)
|
|
491
498
|
});
|
|
@@ -497,7 +504,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
497
504
|
async _open() {
|
|
498
505
|
import_log5.log.info("open...", void 0, {
|
|
499
506
|
F: __dxlog_file5,
|
|
500
|
-
L:
|
|
507
|
+
L: 136,
|
|
501
508
|
S: this,
|
|
502
509
|
C: (f, a) => f(...a)
|
|
503
510
|
});
|
|
@@ -512,14 +519,14 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
512
519
|
if (this._ctx.disposed) {
|
|
513
520
|
break;
|
|
514
521
|
}
|
|
515
|
-
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(
|
|
522
|
+
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_GKDHAWCP.FunctionTrigger)).subscribe(async ({ objects: current }) => {
|
|
516
523
|
import_log5.log.info("update", {
|
|
517
524
|
space: space.key,
|
|
518
525
|
registered: registered.length,
|
|
519
526
|
current: current.length
|
|
520
527
|
}, {
|
|
521
528
|
F: __dxlog_file5,
|
|
522
|
-
L:
|
|
529
|
+
L: 153,
|
|
523
530
|
S: this,
|
|
524
531
|
C: (f, a) => f(...a)
|
|
525
532
|
});
|
|
@@ -531,7 +538,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
531
538
|
this._ctx.onDispose(() => spaceListSubscription.unsubscribe());
|
|
532
539
|
import_log5.log.info("opened", void 0, {
|
|
533
540
|
F: __dxlog_file5,
|
|
534
|
-
L:
|
|
541
|
+
L: 162,
|
|
535
542
|
S: this,
|
|
536
543
|
C: (f, a) => f(...a)
|
|
537
544
|
});
|
|
@@ -539,14 +546,14 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
539
546
|
async _close(_) {
|
|
540
547
|
import_log5.log.info("close...", void 0, {
|
|
541
548
|
F: __dxlog_file5,
|
|
542
|
-
L:
|
|
549
|
+
L: 166,
|
|
543
550
|
S: this,
|
|
544
551
|
C: (f, a) => f(...a)
|
|
545
552
|
});
|
|
546
553
|
this._triggersBySpaceKey.clear();
|
|
547
554
|
import_log5.log.info("closed", void 0, {
|
|
548
555
|
F: __dxlog_file5,
|
|
549
|
-
L:
|
|
556
|
+
L: 168,
|
|
550
557
|
S: this,
|
|
551
558
|
C: (f, a) => f(...a)
|
|
552
559
|
});
|
|
@@ -565,7 +572,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
565
572
|
triggers: added.map((trigger) => trigger.function)
|
|
566
573
|
}), {
|
|
567
574
|
F: __dxlog_file5,
|
|
568
|
-
L:
|
|
575
|
+
L: 179,
|
|
569
576
|
S: this,
|
|
570
577
|
C: (f, a) => f(...a)
|
|
571
578
|
});
|
|
@@ -591,7 +598,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
591
598
|
triggers: removed.map((trigger) => trigger.function)
|
|
592
599
|
}), {
|
|
593
600
|
F: __dxlog_file5,
|
|
594
|
-
L:
|
|
601
|
+
L: 205,
|
|
595
602
|
S: this,
|
|
596
603
|
C: (f, a) => f(...a)
|
|
597
604
|
});
|
|
@@ -615,4 +622,4 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
615
622
|
createWebSocket,
|
|
616
623
|
createWebsocketTrigger
|
|
617
624
|
});
|
|
618
|
-
//# sourceMappingURL=chunk-
|
|
625
|
+
//# sourceMappingURL=chunk-OKV7IWWB.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/function/function-registry.ts", "../../../src/trigger/type/subscription-trigger.ts", "../../../src/trigger/type/timer-trigger.ts", "../../../src/trigger/type/websocket-trigger.ts", "../../../src/trigger/trigger-registry.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, type Space } from '@dxos/client/echo';\nimport { type Context, Resource } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { FunctionDef, type FunctionManifest } from '../types';\n\nexport type FunctionsRegisteredEvent = {\n space: Space;\n added: FunctionDef[];\n};\n\nexport class FunctionRegistry extends Resource {\n private readonly _functionBySpaceKey = new ComplexMap<PublicKey, FunctionDef[]>(PublicKey.hash);\n\n public readonly registered = new Event<FunctionsRegisteredEvent>();\n\n constructor(private readonly _client: Client) {\n super();\n }\n\n public getFunctions(space: Space): FunctionDef[] {\n return this._functionBySpaceKey.get(space.key) ?? [];\n }\n\n public getUniqueByUri(): FunctionDef[] {\n const uniqueByUri = [...this._functionBySpaceKey.values()]\n .flatMap((defs) => defs)\n .reduce((acc, v) => {\n acc.set(v.uri, v);\n return acc;\n }, new Map<string, FunctionDef>());\n return [...uniqueByUri.values()];\n }\n\n /**\n * Loads function definitions from the manifest into the space.\n * We first load all the definitions from the space to deduplicate by functionId.\n */\n public async register(space: Space, functions: FunctionManifest['functions']): Promise<void> {\n log('register', { space: space.key, functions: functions?.length ?? 0 });\n if (!functions?.length) {\n return;\n }\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {\n space.db.graph.schemaRegistry.addSchema([FunctionDef]);\n }\n\n // Sync definitions.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();\n const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update existing templates.\n added.forEach((def) => space.db.add(create(FunctionDef, def)));\n\n if (added.length > 0) {\n await space.db.flush({ indexes: true, updates: true });\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('opening...');\n const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._functionBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: FunctionDef[] = [];\n this._functionBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {\n const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update and remove.\n if (added.length > 0) {\n registered.push(...added);\n this.registered.emit({ space, added });\n }\n }),\n );\n }\n });\n\n // TODO(burdon): API: Normalize unsubscribe methods.\n this._ctx.onDispose(() => spacesSubscription.unsubscribe());\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('closing...');\n this._functionBySpaceKey.clear();\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { debounce, UpdateScheduler } from '@dxos/async';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { createSubscription, type Query } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\n\nimport type { SubscriptionTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = async (\n ctx: Context,\n space: Space,\n spec: SubscriptionTrigger,\n callback: TriggerCallback,\n) => {\n const objectIds = new Set<string>();\n const task = new UpdateScheduler(\n ctx,\n async () => {\n if (objectIds.size > 0) {\n const objects = Array.from(objectIds);\n objectIds.clear();\n await callback({ objects });\n }\n },\n { maxFrequency: 4 },\n );\n\n // TODO(burdon): Factor out diff.\n // TODO(burdon): Don't fire initially?\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n const sizeBefore = objectIds.size;\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 if (objectIds.size > sizeBefore) {\n log.info('updated', { added: added.length, updated: updated.length });\n task.trigger();\n }\n });\n\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = spec;\n const update = ({ objects }: Query) => {\n log.info('update', { objects: objects.length });\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n // TODO(dmaretskyi): Removed to not have dependency on markdown-plugin.\n // for (const object of objects) {\n // const content = object.content;\n // if (content instanceof TextType) {\n // subscriptions.push(getObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)));\n // }\n // }\n }\n };\n\n // TODO(burdon): OR not working.\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 log.info('subscription', { filter });\n // const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n if (filter.type) {\n const query = space.db.query(Filter.typename(filter.type, filter.props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n }\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { DeferredTask } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport type { TimerTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createTimerTrigger: TriggerFactory<TimerTrigger> = async (\n ctx: Context,\n space: Space,\n spec: TimerTrigger,\n callback: TriggerCallback,\n) => {\n const task = new DeferredTask(ctx, async () => {\n await callback({});\n });\n\n let last = 0;\n let run = 0;\n // https://www.npmjs.com/package/cron#constructor\n const job = CronJob.from({\n cronTime: spec.cron,\n runOnInit: false,\n onTick: () => {\n // TODO(burdon): Check greater than 30s (use cron-parser).\n const now = Date.now();\n const delta = last ? now - last : 0;\n last = now;\n\n run++;\n log.info('tick', { space: space.key.truncate(), count: run, delta });\n task.schedule();\n },\n });\n\n job.start();\n ctx.onDispose(() => job.stop());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { sleep, Trigger } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport { type WebsocketTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\ninterface WebsocketTriggerOptions {\n retryDelay: number;\n maxAttempts: number;\n}\n\n/**\n * Websocket.\n * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.\n */\nexport const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketTriggerOptions> = async (\n ctx: Context,\n space: Space,\n spec: WebsocketTrigger,\n callback: TriggerCallback,\n options: WebsocketTriggerOptions = { retryDelay: 2, maxAttempts: 5 },\n) => {\n const { url, init } = spec;\n\n let wasOpen = false;\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = await createWebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (spec.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(init)));\n }\n\n open.wake(true);\n },\n\n onclose: (event) => {\n log.info('closed', { url, code: event.code });\n // Reconnect if server closes (e.g., CF restart).\n // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code\n if (event.code === 1006 && wasOpen && !ctx.disposed) {\n setTimeout(async () => {\n log.info(`reconnecting in ${options.retryDelay}s...`, { url });\n await createWebsocketTrigger(ctx, space, spec, callback, options);\n }, options.retryDelay * 1_000);\n }\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch((event as any).error ?? new Error('Unspecified ws error.'), { url });\n open.wake(false);\n },\n\n onmessage: async (event) => {\n try {\n log.info('message');\n let data;\n if (event.data && 'text' in event.data) {\n data = JSON.parse(await (event.data as Blob).text());\n } else {\n data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n }\n await callback({ data });\n } catch (err) {\n log.catch(err, { url, data: event.data });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (ctx.disposed) {\n break;\n }\n if (isOpen) {\n wasOpen = true;\n break;\n }\n const wait = Math.pow(attempt, 2) * options.retryDelay;\n if (attempt < options.maxAttempts) {\n log.warn(`failed to connect; trying again in ${wait}s`, { attempt });\n await sleep(wait * 1_000);\n }\n }\n\n ctx.onDispose(() => {\n ws?.close();\n });\n};\n\nconst createNodeWebSocket = async (url: string) => {\n // eslint-disable-next-line no-new-func\n const importESM = Function('path', 'return import(path)');\n const {\n default: { WebSocket },\n } = await importESM('ws');\n return new WebSocket(url);\n};\n\nexport const createWebSocket = async (url: string): Promise<WebSocket> => {\n return typeof (globalThis as any).WebSocket === 'undefined' ? await createNodeWebSocket(url) : new WebSocket(url);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, getMeta, type Space } from '@dxos/client/echo';\nimport { Context, Resource } from '@dxos/context';\nimport { compareForeignKeys, ECHO_ATTR_META, foreignKey } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { createSubscriptionTrigger, createTimerTrigger } from './type';\nimport { type FunctionManifest, FunctionTrigger, type TriggerKind, type TriggerType } from '../types';\n\ntype ResponseCode = number;\n\nexport type TriggerCallback = (args: object) => Promise<ResponseCode>;\n\n// TODO(burdon): Make object?\nexport type TriggerFactory<Spec extends TriggerType, Options = any> = (\n ctx: Context,\n space: Space,\n spec: Spec,\n callback: TriggerCallback,\n options?: Options,\n) => Promise<void>;\n\nexport type TriggerFactoryMap = Partial<Record<TriggerKind, TriggerFactory<any>>>;\n\nconst triggerFactory: TriggerFactoryMap = {\n timer: createTimerTrigger,\n // TODO(burdon): Cannot use in browser.\n // webhook: createWebhookTrigger,\n subscription: createSubscriptionTrigger,\n};\n\nexport type TriggerEvent = {\n space: Space;\n triggers: FunctionTrigger[];\n};\n\ntype RegisteredTrigger = {\n activationCtx?: Context;\n trigger: FunctionTrigger;\n};\n\nexport class TriggerRegistry extends Resource {\n private readonly _triggersBySpaceKey = new ComplexMap<PublicKey, RegisteredTrigger[]>(PublicKey.hash);\n\n public readonly registered = new Event<TriggerEvent>();\n public readonly removed = new Event<TriggerEvent>();\n\n constructor(\n private readonly _client: Client,\n private readonly _options?: TriggerFactoryMap,\n ) {\n super();\n }\n\n public getActiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx != null);\n }\n\n public getInactiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx == null);\n }\n\n /**\n * Set callback for trigger.\n */\n public async activate(space: Space, trigger: FunctionTrigger, callback: TriggerCallback): Promise<void> {\n log('activate', { space: space.key, trigger });\n\n const activationCtx = new Context({ name: `FunctionTrigger-${trigger.function}` });\n this._ctx.onDispose(() => activationCtx.dispose());\n const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);\n invariant(registeredTrigger, `Trigger is not registered: ${trigger.function}`);\n registeredTrigger.activationCtx = activationCtx;\n\n try {\n // Create trigger.\n invariant(trigger.spec);\n const options = this._options?.[trigger.spec.type];\n const createTrigger = triggerFactory[trigger.spec.type];\n invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`);\n await createTrigger(activationCtx, space, trigger.spec, callback, options);\n } catch (err) {\n delete registeredTrigger.activationCtx;\n throw err;\n }\n }\n\n /**\n * Loads triggers from the manifest into the space.\n */\n public async register(space: Space, manifest: FunctionManifest): Promise<void> {\n log('register', { space: space.key });\n if (!manifest.triggers?.length) {\n return;\n }\n\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionTrigger)) {\n space.db.graph.schemaRegistry.addSchema([FunctionTrigger]);\n }\n\n // Create FK to enable syncing if none are set (NOTE: Possible collision).\n const manifestTriggers = manifest.triggers.map((trigger) => {\n let keys = trigger[ECHO_ATTR_META]?.keys;\n delete trigger[ECHO_ATTR_META];\n if (!keys?.length) {\n keys = [foreignKey('manifest', [trigger.function, trigger.spec?.type].join(':'))];\n }\n\n return create(FunctionTrigger, trigger, { keys });\n });\n\n // Sync triggers.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionTrigger)).run();\n const { added } = diff(existing, manifestTriggers, compareForeignKeys);\n\n // TODO(burdon): Update existing.\n added.forEach((trigger) => {\n space.db.add(trigger);\n log.info('added', { meta: getMeta(trigger) });\n });\n\n if (added.length > 0) {\n await space.db.flush();\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('open...');\n const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._triggersBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: RegisteredTrigger[] = [];\n this._triggersBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionTrigger)).subscribe(async ({ objects: current }) => {\n log.info('update', { space: space.key, registered: registered.length, current: current.length });\n await this._handleRemovedTriggers(space, current, registered);\n this._handleNewTriggers(space, current, registered);\n }),\n );\n }\n });\n\n this._ctx.onDispose(() => spaceListSubscription.unsubscribe());\n log.info('opened');\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('close...');\n this._triggersBySpaceKey.clear();\n log.info('closed');\n }\n\n private _handleNewTriggers(space: Space, current: FunctionTrigger[], registered: RegisteredTrigger[]) {\n const added = current.filter((candidate) => {\n return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;\n });\n\n if (added.length > 0) {\n const newRegisteredTriggers: RegisteredTrigger[] = added.map((trigger) => ({ trigger }));\n registered.push(...newRegisteredTriggers);\n log.info('added', () => ({\n spaceKey: space.key,\n triggers: added.map((trigger) => trigger.function),\n }));\n\n this.registered.emit({ space, triggers: added });\n }\n }\n\n private async _handleRemovedTriggers(\n space: Space,\n current: FunctionTrigger[],\n registered: RegisteredTrigger[],\n ): Promise<void> {\n const removed: FunctionTrigger[] = [];\n for (let i = registered.length - 1; i >= 0; i--) {\n const wasRemoved =\n current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;\n if (wasRemoved) {\n const unregistered = registered.splice(i, 1)[0];\n await unregistered.activationCtx?.dispose();\n removed.push(unregistered.trigger);\n }\n }\n\n if (removed.length > 0) {\n log.info('removed', () => ({\n spaceKey: space.key,\n triggers: removed.map((trigger) => trigger.function),\n }));\n\n this.removed.emit({ space, triggers: removed });\n }\n }\n\n private _getTriggers(space: Space, predicate: (trigger: RegisteredTrigger) => boolean): FunctionTrigger[] {\n const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];\n return allSpaceTriggers.filter(predicate).map((trigger) => trigger.trigger);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAsB;AAEtB,kBAA2C;AAC3C,qBAAuC;AACvC,kBAA0B;AAC1B,iBAAoB;AACpB,kBAAiC;ACNjC,IAAAA,gBAA0C;AAC1C,IAAAC,eAAmC;AAEnC,qBAA+C;AAC/C,IAAAC,cAAoB;ACJpB,kBAAwB;AAExB,IAAAF,gBAA6B;AAG7B,IAAAE,cAAoB;ACLpB,IAAAF,gBAA+B;AAG/B,IAAAE,cAAoB;ACHpB,IAAAF,gBAAsB;AAEtB,IAAAC,eAAoD;AACpD,IAAAE,kBAAkC;AAClC,yBAA+D;AAC/D,uBAA0B;AAC1B,IAAAC,eAA0B;AAC1B,IAAAF,cAAoB;AACpB,IAAAG,eAAiC;;AJO1B,IAAMC,mBAAN,cAA+BC,wBAAAA;EAKpCC,YAA6BC,SAAiB;AAC5C,UAAK;SADsBA,UAAAA;SAJZC,sBAAsB,IAAIC,uBAAqCC,sBAAUC,IAAI;SAE9EC,aAAa,IAAIC,mBAAAA;EAIjC;EAEOC,aAAaC,OAA6B;AAC/C,WAAO,KAAKP,oBAAoBQ,IAAID,MAAME,GAAG,KAAK,CAAA;EACpD;EAEOC,iBAAgC;AACrC,UAAMC,cAAc;SAAI,KAAKX,oBAAoBY,OAAM;MACpDC,QAAQ,CAACC,SAASA,IAAAA,EAClBC,OAAO,CAACC,KAAKC,MAAAA;AACZD,UAAIE,IAAID,EAAEE,KAAKF,CAAAA;AACf,aAAOD;IACT,G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AQyF,QAAQ;MACrD,IAAA;;;;;;AAEA,WAAKT,QAAQxG,KAAK;QAAEpD;QAAO6K,UAAUjB;MAAQ,CAAA;IAC/C;EACF;EAEQE,aAAa9J,OAAcoM,WAAuE;AACxG,UAAMC,mBAAmB,KAAK1C,oBAAoB1J,IAAID,MAAME,GAAG,KAAK,CAAA;AACpE,WAAOmM,iBAAiBxH,OAAOuH,SAAAA,EAAWpB,IAAI,CAACpG,YAAYA,QAAQA,OAAO;EAC5E;AACF;",
|
|
6
|
+
"names": ["import_async", "import_echo", "import_log", "import_context", "import_keys", "import_util", "FunctionRegistry", "Resource", "constructor", "_client", "_functionBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "getFunctions", "space", "get", "key", "getUniqueByUri", "uniqueByUri", "values", "flatMap", "defs", "reduce", "acc", "v", "set", "uri", "Map", "register", "functions", "log", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionDef", "addSchema", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "a", "b", "forEach", "def", "add", "create", "flush", "indexes", "updates", "_open", "info", "spacesSubscription", "spaces", "subscribe", "has", "waitUntilReady", "_ctx", "disposed", "onDispose", "push", "emit", "unsubscribe", "_close", "_", "clear", "createSubscriptionTrigger", "ctx", "spec", "callback", "objectIds", "Set", "task", "UpdateScheduler", "size", "Array", "from", "maxFrequency", "subscriptions", "subscription", "createSubscription", "updated", "sizeBefore", "object", "id", "trigger", "filter", "options", "deep", "delay", "update", "type", "typename", "props", "debounce", "createTimerTrigger", "DeferredTask", "last", "job", "CronJob", "cronTime", "cron", "runOnInit", "onTick", "now", "Date", "delta", "truncate", "count", "schedule", "start", "stop", "createWebsocketTrigger", "retryDelay", "maxAttempts", "url", "init", "wasOpen", "ws", "attempt", "open", "Trigger", "createWebSocket", "Object", "assign", "onopen", "send", "TextEncoder", "encode", "JSON", "stringify", "wake", "onclose", "event", "code", "setTimeout", "onerror", "catch", "error", "Error", "onmessage", "data", "parse", "text", "TextDecoder", "decode", "err", "isOpen", "wait", "Math", "pow", "warn", "sleep", "close", "createNodeWebSocket", "importESM", "Function", "default", "WebSocket", "globalThis", "triggerFactory", "timer", "TriggerRegistry", "_options", "_triggersBySpaceKey", "removed", "getActiveTriggers", "_getTriggers", "t", "activationCtx", "getInactiveTriggers", "activate", "Context", "name", "function", "dispose", "registeredTrigger", "find", "reg", "invariant", "createTrigger", "manifest", "triggers", "FunctionTrigger", "manifestTriggers", "map", "keys", "ECHO_ATTR_META", "foreignKey", "join", "compareForeignKeys", "meta", "getMeta", "spaceListSubscription", "current", "_handleRemovedTriggers", "_handleNewTriggers", "candidate", "enabled", "newRegisteredTriggers", "spaceKey", "i", "wasRemoved", "unregistered", "splice", "predicate", "allSpaceTriggers"]
|
|
7
|
+
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,21 +18,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
|
|
22
|
-
FunctionDef: () =>
|
|
23
|
-
FunctionManifestSchema: () =>
|
|
24
|
-
FunctionRegistry: () =>
|
|
25
|
-
FunctionTrigger: () =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
FUNCTION_TYPES: () => import_chunk_GKDHAWCP.FUNCTION_TYPES,
|
|
22
|
+
FunctionDef: () => import_chunk_GKDHAWCP.FunctionDef,
|
|
23
|
+
FunctionManifestSchema: () => import_chunk_GKDHAWCP.FunctionManifestSchema,
|
|
24
|
+
FunctionRegistry: () => import_chunk_OKV7IWWB.FunctionRegistry,
|
|
25
|
+
FunctionTrigger: () => import_chunk_GKDHAWCP.FunctionTrigger,
|
|
26
|
+
FunctionTriggerSchema: () => import_chunk_GKDHAWCP.FunctionTriggerSchema,
|
|
27
|
+
TriggerRegistry: () => import_chunk_OKV7IWWB.TriggerRegistry,
|
|
28
|
+
TriggerSchema: () => import_chunk_GKDHAWCP.TriggerSchema,
|
|
29
|
+
createSubscriptionTrigger: () => import_chunk_OKV7IWWB.createSubscriptionTrigger,
|
|
30
|
+
createTimerTrigger: () => import_chunk_OKV7IWWB.createTimerTrigger,
|
|
31
|
+
createWebSocket: () => import_chunk_OKV7IWWB.createWebSocket,
|
|
32
|
+
createWebsocketTrigger: () => import_chunk_OKV7IWWB.createWebsocketTrigger,
|
|
31
33
|
subscriptionHandler: () => subscriptionHandler
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(node_exports);
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
+
var import_chunk_OKV7IWWB = require("./chunk-OKV7IWWB.cjs");
|
|
37
|
+
var import_chunk_GKDHAWCP = require("./chunk-GKDHAWCP.cjs");
|
|
36
38
|
var import_client = require("@dxos/client");
|
|
37
39
|
var import_log = require("@dxos/log");
|
|
38
40
|
var import_util = require("@dxos/util");
|
|
@@ -98,12 +100,14 @@ var registerTypes = (space, types = []) => {
|
|
|
98
100
|
};
|
|
99
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
102
|
0 && (module.exports = {
|
|
101
|
-
|
|
103
|
+
FUNCTION_TYPES,
|
|
102
104
|
FunctionDef,
|
|
103
105
|
FunctionManifestSchema,
|
|
104
106
|
FunctionRegistry,
|
|
105
107
|
FunctionTrigger,
|
|
108
|
+
FunctionTriggerSchema,
|
|
106
109
|
TriggerRegistry,
|
|
110
|
+
TriggerSchema,
|
|
107
111
|
createSubscriptionTrigger,
|
|
108
112
|
createTimerTrigger,
|
|
109
113
|
createWebSocket,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/handler.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema as S } from '@effect/schema';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoReactiveObject } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TMeta = {}> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => Promise<Response | FunctionResponse | void>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: FunctionContextAi;\n\n /**\n * @deprecated\n */\n // TODO(burdon): Limit access to individual space.\n client: Client;\n /**\n * @deprecated\n */\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n/**\n * Event payload.\n */\nexport type FunctionEvent<TData = {}, TMeta = {}> = {\n data: FunctionEventMeta<TMeta> & TData;\n};\n\n/**\n * Metadata from trigger.\n */\nexport type FunctionEventMeta<TMeta = {}> = {\n meta: TMeta;\n};\n\n/**\n * Function response.\n */\nexport type FunctionResponse = {\n status(code: number): FunctionResponse;\n};\n\n//\n// API.\n//\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n get crud(): CoreDatabase;\n}\n\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // eslint-disable-next-line unused-imports/no-unused-vars\n const y: SpaceAPI = {} as Space;\n};\n\n//\n// Subscription utils.\n//\n\nexport type RawSubscriptionData = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionData = {\n space?: Space;\n objects?: EchoReactiveObject<any>[];\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 */\n// TODO(burdon): Evolve into plugin definition like Composer.\nexport const subscriptionHandler = <TMeta>(\n handler: FunctionHandler<SubscriptionData, TMeta>,\n types?: S.Schema<any>[],\n): FunctionHandler<RawSubscriptionData, TMeta> => {\n return async ({ event: { data }, context, response, ...rest }) => {\n const { client } = context;\n const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : undefined;\n if (!space) {\n log.error('Invalid space');\n return response.status(500);\n }\n\n registerTypes(space, types);\n const objects = space\n ? data.objects?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable)\n : [];\n\n if (!!data.spaceKey && !space) {\n log.warn('invalid space', { data });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { data: { ...data, space, objects } }, context, response, ...rest });\n };\n};\n\n// TODO(burdon): Evolve types as part of function metadata.\nconst registerTypes = (space: Space, types: S.Schema<any>[] = []) => {\n const registry = space.db.graph.schemaRegistry;\n for (const type of types) {\n if (!registry.hasSchema(type)) {\n registry.addSchema([type]);\n }\n }\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,oBAAuC;AAGvC,iBAAoB;AACpB,kBAA4B;;AAiHrB,IAAMA,sBAAsB,CACjCC,SACAC,UAAAA;AAEA,SAAO,OAAO,EAAEC,OAAO,EAAEC,KAAI,GAAIC,SAASC,UAAU,GAAGC,KAAAA,MAAM;AAC3D,UAAM,EAAEC,OAAM,IAAKH;AACnB,UAAMI,QAAQL,KAAKM,WAAWF,OAAOG,OAAOC,IAAIC,wBAAUC,KAAKV,KAAKM,QAAQ,CAAA,IAAKK;AACjF,QAAI,CAACN,OAAO;AACVO,qBAAIC,MAAM,iBAAA,QAAA;;;;;;AACV,aAAOX,SAASY,OAAO,GAAA;IACzB;AAEAC,kBAAcV,OAAOP,KAAAA;AACrB,UAAMkB,UAAUX,QACZL,KAAKgB,SAASC,IAAyC,CAACC,OAAOb,MAAOc,GAAGC,cAAcF,EAAAA,CAAAA,EAAKG,OAAOC,uBAAAA,IACnG,CAAA;AAEJ,QAAI,CAAC,CAACtB,KAAKM,YAAY,CAACD,OAAO;AAC7BO,qBAAIW,KAAK,iBAAiB;QAAEvB;MAAK,GAAA;;;;;;IACnC,OAAO;AACLY,qBAAIY,KAAK,WAAW;QAAEnB,OAAOA,OAAOoB,IAAIC,SAAAA;QAAYV,SAASA,SAASW;MAAO,GAAA;;;;;;IAC/E;AAEA,WAAO9B,QAAQ;MAAEE,OAAO;QAAEC,MAAM;UAAE,GAAGA;UAAMK;UAAOW;QAAQ;MAAE;MAAGf;MAASC;MAAU,GAAGC;IAAK,CAAA;EAC5F;AACF;AAGA,IAAMY,gBAAgB,CAACV,OAAcP,QAAyB,CAAA,MAAE;AAC9D,QAAM8B,WAAWvB,MAAMc,GAAGU,MAAMC;AAChC,aAAWC,QAAQjC,OAAO;AACxB,QAAI,CAAC8B,SAASI,UAAUD,IAAAA,GAAO;AAC7BH,eAASK,UAAU;QAACF;OAAK;IAC3B;EACF;AACF;",
|
|
6
6
|
"names": ["subscriptionHandler", "handler", "types", "event", "data", "context", "response", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "log", "error", "status", "registerTypes", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "warn", "info", "key", "truncate", "length", "registry", "graph", "schemaRegistry", "type", "hasSchema", "addSchema"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/functions/src/types.ts":{"bytes":10493,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/function/function-registry.ts":{"bytes":13004,"imports":[{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/function/index.ts":{"bytes":529,"imports":[{"path":"packages/core/functions/src/function/function-registry.ts","kind":"import-statement","original":"./function-registry"}],"format":"esm"},"packages/core/functions/src/handler.ts":{"bytes":10610,"imports":[{"path":"@dxos/client","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/trigger/type/subscription-trigger.ts":{"bytes":10343,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytes":4173,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytes":13341,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/index.ts":{"bytes":864,"imports":[{"path":"packages/core/functions/src/trigger/type/subscription-trigger.ts","kind":"import-statement","original":"./subscription-trigger"},{"path":"packages/core/functions/src/trigger/type/timer-trigger.ts","kind":"import-statement","original":"./timer-trigger"},{"path":"packages/core/functions/src/trigger/type/websocket-trigger.ts","kind":"import-statement","original":"./websocket-trigger"}],"format":"esm"},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytes":28453,"imports":[{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/trigger/index.ts":{"bytes":603,"imports":[{"path":"packages/core/functions/src/trigger/trigger-registry.ts","kind":"import-statement","original":"./trigger-registry"},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":840,"imports":[{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"./function"},{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"./trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/core/functions/src/testing/types.ts":{"bytes":1131,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":28958,"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/context","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":21084,"imports":[{"path":"node:path","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-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":598,"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/testing/setup.ts":{"bytes":12707,"imports":[{"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/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"../function"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"../runtime"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"../trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/util.ts":{"bytes":4292,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/manifest.ts":{"bytes":1139,"imports":[],"format":"esm"},"packages/core/functions/src/testing/index.ts":{"bytes":749,"imports":[{"path":"packages/core/functions/src/testing/setup.ts","kind":"import-statement","original":"./setup"},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/testing/util.ts","kind":"import-statement","original":"./util"},{"path":"packages/core/functions/src/testing/manifest.ts","kind":"import-statement","original":"./manifest"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5750},"packages/core/functions/dist/lib/node/index.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-3KJEM5VR.cjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs","kind":"import-statement"},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionRegistry","FunctionTrigger","TriggerRegistry","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/handler.ts":{"bytesInOutput":1624}},"bytes":2242},"packages/core/functions/dist/lib/node/testing/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32236},"packages/core/functions/dist/lib/node/testing/index.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-3KJEM5VR.cjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs","kind":"import-statement"},{"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/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","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/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"node:path","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-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true}],"exports":["TestType","createFunctionRuntime","createInitializedClients","inviteMember","startFunctionsHost","testFunctionManifest","triggerWebhook"],"entryPoint":"packages/core/functions/src/testing/index.ts","inputs":{"packages/core/functions/src/testing/setup.ts":{"bytesInOutput":2775},"packages/core/functions/src/testing/types.ts":{"bytesInOutput":182},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":7860},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5330},"packages/core/functions/src/testing/index.ts":{"bytesInOutput":0},"packages/core/functions/src/testing/util.ts":{"bytesInOutput":1051},"packages/core/functions/src/testing/manifest.ts":{"bytesInOutput":146}},"bytes":18055},"packages/core/functions/dist/lib/node/chunk-3KJEM5VR.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33088},"packages/core/functions/dist/lib/node/chunk-3KJEM5VR.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs","kind":"import-statement"},{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","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/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FunctionRegistry","TriggerRegistry","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger"],"inputs":{"packages/core/functions/src/function/function-registry.ts":{"bytesInOutput":3046},"packages/core/functions/src/function/index.ts":{"bytesInOutput":0},"packages/core/functions/src/trigger/type/subscription-trigger.ts":{"bytesInOutput":2008},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytesInOutput":898},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytesInOutput":3491},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytesInOutput":7421},"packages/core/functions/src/trigger/type/index.ts":{"bytesInOutput":0},"packages/core/functions/src/trigger/index.ts":{"bytesInOutput":0}},"bytes":17447},"packages/core/functions/dist/lib/node/types.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/node/types.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs","kind":"import-statement"}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":243},"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5742},"packages/core/functions/dist/lib/node/chunk-TNG3Z74V.cjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger","__require"],"inputs":{"packages/core/functions/src/types.ts":{"bytesInOutput":2072}},"bytes":2626}}}
|
|
1
|
+
{"inputs":{"packages/core/functions/src/types.ts":{"bytes":14928,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/function/function-registry.ts":{"bytes":13004,"imports":[{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/function/index.ts":{"bytes":529,"imports":[{"path":"packages/core/functions/src/function/function-registry.ts","kind":"import-statement","original":"./function-registry"}],"format":"esm"},"packages/core/functions/src/handler.ts":{"bytes":10610,"imports":[{"path":"@dxos/client","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/trigger/type/subscription-trigger.ts":{"bytes":10314,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytes":4173,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytes":13341,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/index.ts":{"bytes":864,"imports":[{"path":"packages/core/functions/src/trigger/type/subscription-trigger.ts","kind":"import-statement","original":"./subscription-trigger"},{"path":"packages/core/functions/src/trigger/type/timer-trigger.ts","kind":"import-statement","original":"./timer-trigger"},{"path":"packages/core/functions/src/trigger/type/websocket-trigger.ts","kind":"import-statement","original":"./websocket-trigger"}],"format":"esm"},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytes":28469,"imports":[{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/trigger/index.ts":{"bytes":603,"imports":[{"path":"packages/core/functions/src/trigger/trigger-registry.ts","kind":"import-statement","original":"./trigger-registry"},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":840,"imports":[{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"./function"},{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"./trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/core/functions/src/testing/types.ts":{"bytes":1131,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":28958,"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/context","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":21081,"imports":[{"path":"node:path","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-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":598,"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/testing/setup.ts":{"bytes":12707,"imports":[{"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/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"../function"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"../runtime"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"../trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/util.ts":{"bytes":4310,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/manifest.ts":{"bytes":1139,"imports":[],"format":"esm"},"packages/core/functions/src/testing/index.ts":{"bytes":749,"imports":[{"path":"packages/core/functions/src/testing/setup.ts","kind":"import-statement","original":"./setup"},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/testing/util.ts","kind":"import-statement","original":"./util"},{"path":"packages/core/functions/src/testing/manifest.ts","kind":"import-statement","original":"./manifest"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5752},"packages/core/functions/dist/lib/node/index.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-OKV7IWWB.cjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs","kind":"import-statement"},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionRegistry","FunctionTrigger","FunctionTriggerSchema","TriggerRegistry","TriggerSchema","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/handler.ts":{"bytesInOutput":1624}},"bytes":2324},"packages/core/functions/dist/lib/node/testing/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32245},"packages/core/functions/dist/lib/node/testing/index.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-OKV7IWWB.cjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs","kind":"import-statement"},{"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/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","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/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"node:path","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-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true}],"exports":["TestType","createFunctionRuntime","createInitializedClients","inviteMember","startFunctionsHost","testFunctionManifest","triggerWebhook"],"entryPoint":"packages/core/functions/src/testing/index.ts","inputs":{"packages/core/functions/src/testing/setup.ts":{"bytesInOutput":2775},"packages/core/functions/src/testing/types.ts":{"bytesInOutput":182},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":7860},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5331},"packages/core/functions/src/testing/index.ts":{"bytesInOutput":0},"packages/core/functions/src/testing/util.ts":{"bytesInOutput":1067},"packages/core/functions/src/testing/manifest.ts":{"bytesInOutput":146}},"bytes":18072},"packages/core/functions/dist/lib/node/chunk-OKV7IWWB.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32979},"packages/core/functions/dist/lib/node/chunk-OKV7IWWB.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs","kind":"import-statement"},{"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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","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/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","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/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FunctionRegistry","TriggerRegistry","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger"],"inputs":{"packages/core/functions/src/function/function-registry.ts":{"bytesInOutput":3046},"packages/core/functions/src/function/index.ts":{"bytesInOutput":0},"packages/core/functions/src/trigger/type/subscription-trigger.ts":{"bytesInOutput":2007},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytesInOutput":898},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytesInOutput":3491},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytesInOutput":7538},"packages/core/functions/src/trigger/type/index.ts":{"bytesInOutput":0},"packages/core/functions/src/trigger/index.ts":{"bytesInOutput":0}},"bytes":17563},"packages/core/functions/dist/lib/node/types.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/node/types.cjs":{"imports":[{"path":"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs","kind":"import-statement"}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionTrigger","FunctionTriggerSchema","TriggerSchema"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":325},"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7792},"packages/core/functions/dist/lib/node/chunk-GKDHAWCP.cjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionTrigger","FunctionTriggerSchema","TriggerSchema","__require"],"inputs":{"packages/core/functions/src/types.ts":{"bytesInOutput":2971}},"bytes":3566}}}
|
|
@@ -37,8 +37,8 @@ __export(testing_exports, {
|
|
|
37
37
|
triggerWebhook: () => triggerWebhook
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(testing_exports);
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var import_chunk_OKV7IWWB = require("../chunk-OKV7IWWB.cjs");
|
|
41
|
+
var import_chunk_GKDHAWCP = require("../chunk-GKDHAWCP.cjs");
|
|
42
42
|
var import_get_port_please = require("get-port-please");
|
|
43
43
|
var import_node_path = __toESM(require("node:path"));
|
|
44
44
|
var import_async = require("@dxos/async");
|
|
@@ -276,11 +276,11 @@ var DevServer = class {
|
|
|
276
276
|
C: (f, a) => f(...a)
|
|
277
277
|
});
|
|
278
278
|
if (force) {
|
|
279
|
-
Object.keys(
|
|
280
|
-
delete
|
|
279
|
+
Object.keys(import_chunk_GKDHAWCP.__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
|
|
280
|
+
delete import_chunk_GKDHAWCP.__require.cache[key];
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
|
-
const module2 = (0,
|
|
283
|
+
const module2 = (0, import_chunk_GKDHAWCP.__require)(filePath);
|
|
284
284
|
if (typeof module2.default !== "function") {
|
|
285
285
|
throw new Error(`Handler must export default function: ${uri}`);
|
|
286
286
|
}
|
|
@@ -505,7 +505,7 @@ var Scheduler = class {
|
|
|
505
505
|
import_log2.log.info("exec", {
|
|
506
506
|
function: def.uri,
|
|
507
507
|
url,
|
|
508
|
-
triggerType: trigger.spec
|
|
508
|
+
triggerType: trigger.spec?.type
|
|
509
509
|
}, {
|
|
510
510
|
F: __dxlog_file2,
|
|
511
511
|
L: 139,
|
|
@@ -569,8 +569,8 @@ var createInitializedClients = async (testBuilder, count = 1, config) => {
|
|
|
569
569
|
config,
|
|
570
570
|
services: testBuilder.createLocalClientServices(),
|
|
571
571
|
types: [
|
|
572
|
-
|
|
573
|
-
|
|
572
|
+
import_chunk_GKDHAWCP.FunctionDef,
|
|
573
|
+
import_chunk_GKDHAWCP.FunctionTrigger,
|
|
574
574
|
TestType
|
|
575
575
|
]
|
|
576
576
|
}));
|
|
@@ -607,7 +607,7 @@ var createFunctionRuntime = async (testBuilder, pluginInitializer) => {
|
|
|
607
607
|
};
|
|
608
608
|
var startFunctionsHost = async (testBuilder, pluginInitializer, options) => {
|
|
609
609
|
const functionRuntime = await createFunctionRuntime(testBuilder, pluginInitializer);
|
|
610
|
-
const functionsRegistry = new
|
|
610
|
+
const functionsRegistry = new import_chunk_OKV7IWWB.FunctionRegistry(functionRuntime);
|
|
611
611
|
const devServer = await startDevServer(testBuilder, functionRuntime, functionsRegistry, options);
|
|
612
612
|
const scheduler = await startScheduler(testBuilder, functionRuntime, devServer, functionsRegistry);
|
|
613
613
|
return {
|
|
@@ -621,7 +621,7 @@ var startFunctionsHost = async (testBuilder, pluginInitializer, options) => {
|
|
|
621
621
|
};
|
|
622
622
|
};
|
|
623
623
|
var startScheduler = async (testBuilder, client, devServer, functionRegistry) => {
|
|
624
|
-
const triggerRegistry = new
|
|
624
|
+
const triggerRegistry = new import_chunk_OKV7IWWB.TriggerRegistry(client);
|
|
625
625
|
const scheduler = new Scheduler(functionRegistry, triggerRegistry, {
|
|
626
626
|
endpoint: devServer.endpoint
|
|
627
627
|
});
|
|
@@ -641,13 +641,13 @@ var startDevServer = async (testBuilder, client, functionRegistry, options) => {
|
|
|
641
641
|
};
|
|
642
642
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/functions/src/testing/util.ts";
|
|
643
643
|
var triggerWebhook = async (space, uri) => {
|
|
644
|
-
const trigger = (await space.db.query(import_echo2.Filter.schema(
|
|
645
|
-
(0, import_invariant2.invariant)(trigger.spec
|
|
644
|
+
const trigger = (await space.db.query(import_echo2.Filter.schema(import_chunk_GKDHAWCP.FunctionTrigger, (trigger2) => trigger2.function === uri)).run()).objects[0];
|
|
645
|
+
(0, import_invariant2.invariant)(trigger.spec?.type === "webhook", void 0, {
|
|
646
646
|
F: __dxlog_file3,
|
|
647
647
|
L: 17,
|
|
648
648
|
S: void 0,
|
|
649
649
|
A: [
|
|
650
|
-
"trigger.spec
|
|
650
|
+
"trigger.spec?.type === 'webhook'",
|
|
651
651
|
""
|
|
652
652
|
]
|
|
653
653
|
});
|