@dxos/functions 0.5.3-main.f1ddd61 → 0.5.3-main.f752aaa

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.
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var node_exports = {};
30
30
  __export(node_exports, {
31
31
  DevServer: () => DevServer,
32
+ FunctionManifestSchema: () => FunctionManifestSchema,
32
33
  Scheduler: () => Scheduler,
33
34
  subscriptionHandler: () => subscriptionHandler
34
35
  });
@@ -43,6 +44,8 @@ var import_async = require("@dxos/async");
43
44
  var import_invariant = require("@dxos/invariant");
44
45
  var import_log2 = require("@dxos/log");
45
46
  var import_cron = require("cron");
47
+ var import_node_http = __toESM(require("node:http"));
48
+ var import_ws = __toESM(require("ws"));
46
49
  var import_types = require("@braneframe/types");
47
50
  var import_async2 = require("@dxos/async");
48
51
  var import_echo = require("@dxos/client/echo");
@@ -50,6 +53,7 @@ var import_context = require("@dxos/context");
50
53
  var import_invariant2 = require("@dxos/invariant");
51
54
  var import_log3 = require("@dxos/log");
52
55
  var import_util2 = require("@dxos/util");
56
+ var S = __toESM(require("@effect/schema/Schema"));
53
57
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
54
58
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
55
59
  }) : x)(function(x) {
@@ -68,7 +72,7 @@ var subscriptionHandler = (handler) => {
68
72
  event
69
73
  }, {
70
74
  F: __dxlog_file,
71
- L: 61,
75
+ L: 68,
72
76
  S: void 0,
73
77
  C: (f, a) => f(...a)
74
78
  });
@@ -78,7 +82,7 @@ var subscriptionHandler = (handler) => {
78
82
  objects: objects?.length
79
83
  }, {
80
84
  F: __dxlog_file,
81
- L: 63,
85
+ L: 70,
82
86
  S: void 0,
83
87
  C: (f, a) => f(...a)
84
88
  });
@@ -324,7 +328,7 @@ var Scheduler = class {
324
328
  const def = this._manifest.functions.find((config) => config.id === trigger.function);
325
329
  (0, import_invariant2.invariant)(def, `Function not found: ${trigger.function}`, {
326
330
  F: __dxlog_file3,
327
- L: 63,
331
+ L: 72,
328
332
  S: this,
329
333
  A: [
330
334
  "def",
@@ -342,18 +346,24 @@ var Scheduler = class {
342
346
  trigger
343
347
  }, {
344
348
  F: __dxlog_file3,
345
- L: 69,
349
+ L: 78,
346
350
  S: this,
347
351
  C: (f, a) => f(...a)
348
352
  });
349
353
  if (ctx.disposed) {
350
354
  return;
351
355
  }
352
- if (trigger.schedule) {
353
- this._createTimer(ctx, space, def, trigger);
356
+ if (trigger.timer) {
357
+ await this._createTimer(ctx, space, def, trigger.timer);
354
358
  }
355
- for (const triggerSubscription of trigger.subscriptions ?? []) {
356
- this._createSubscription(ctx, space, def, triggerSubscription);
359
+ if (trigger.webhook) {
360
+ await this._createWebhook(ctx, space, def, trigger.webhook);
361
+ }
362
+ if (trigger.websocket) {
363
+ await this._createWebsocket(ctx, space, def, trigger.websocket);
364
+ }
365
+ if (trigger.subscription) {
366
+ await this._createSubscription(ctx, space, def, trigger.subscription);
357
367
  }
358
368
  }
359
369
  }
@@ -368,25 +378,75 @@ var Scheduler = class {
368
378
  await ctx.dispose();
369
379
  }
370
380
  }
371
- _createTimer(ctx, space, def, trigger) {
381
+ // TODO(burdon): Pass in Space key (common context).
382
+ async _execFunction(def, data) {
383
+ try {
384
+ import_log3.log.info("exec", {
385
+ function: def.id
386
+ }, {
387
+ F: __dxlog_file3,
388
+ L: 117,
389
+ S: this,
390
+ C: (f, a) => f(...a)
391
+ });
392
+ const { endpoint, callback } = this._options;
393
+ if (endpoint) {
394
+ await fetch(`${this._options.endpoint}/${def.name}`, {
395
+ method: "POST",
396
+ headers: {
397
+ "Content-Type": "application/json"
398
+ },
399
+ body: JSON.stringify(data)
400
+ });
401
+ } else if (callback) {
402
+ await callback(data);
403
+ }
404
+ import_log3.log.info("done", {
405
+ function: def.id
406
+ }, {
407
+ F: __dxlog_file3,
408
+ L: 133,
409
+ S: this,
410
+ C: (f, a) => f(...a)
411
+ });
412
+ } catch (err) {
413
+ import_log3.log.error("error", {
414
+ function: def.id,
415
+ error: err.message
416
+ }, {
417
+ F: __dxlog_file3,
418
+ L: 135,
419
+ S: this,
420
+ C: (f, a) => f(...a)
421
+ });
422
+ }
423
+ }
424
+ //
425
+ // Triggers
426
+ //
427
+ /**
428
+ * Cron timer.
429
+ */
430
+ async _createTimer(ctx, space, def, trigger) {
431
+ import_log3.log.info("timer", {
432
+ space: space.key,
433
+ trigger
434
+ }, {
435
+ F: __dxlog_file3,
436
+ L: 147,
437
+ S: this,
438
+ C: (f, a) => f(...a)
439
+ });
440
+ const { cron } = trigger;
372
441
  const task = new import_async2.DeferredTask(ctx, async () => {
373
442
  await this._execFunction(def, {
374
443
  space: space.key
375
444
  });
376
445
  });
377
- (0, import_invariant2.invariant)(trigger.schedule, void 0, {
378
- F: __dxlog_file3,
379
- L: 102,
380
- S: this,
381
- A: [
382
- "trigger.schedule",
383
- ""
384
- ]
385
- });
386
446
  let last = 0;
387
447
  let run = 0;
388
448
  const job = import_cron.CronJob.from({
389
- cronTime: trigger.schedule,
449
+ cronTime: cron,
390
450
  runOnInit: false,
391
451
  onTick: () => {
392
452
  const now = Date.now();
@@ -399,7 +459,7 @@ var Scheduler = class {
399
459
  delta
400
460
  }, {
401
461
  F: __dxlog_file3,
402
- L: 116,
462
+ L: 167,
403
463
  S: this,
404
464
  C: (f, a) => f(...a)
405
465
  });
@@ -409,13 +469,147 @@ var Scheduler = class {
409
469
  job.start();
410
470
  ctx.onDispose(() => job.stop());
411
471
  }
412
- _createSubscription(ctx, space, def, triggerSubscription) {
472
+ /**
473
+ * Webhook.
474
+ */
475
+ async _createWebhook(ctx, space, def, trigger) {
476
+ import_log3.log.info("webhook", {
477
+ space: space.key,
478
+ trigger
479
+ }, {
480
+ F: __dxlog_file3,
481
+ L: 180,
482
+ S: this,
483
+ C: (f, a) => f(...a)
484
+ });
485
+ const { port } = trigger;
486
+ const server = import_node_http.default.createServer(async (req, res) => {
487
+ await this._execFunction(def, {
488
+ space: space.key
489
+ });
490
+ });
491
+ server.listen(port, () => {
492
+ import_log3.log.info("started webhook", {
493
+ port
494
+ }, {
495
+ F: __dxlog_file3,
496
+ L: 189,
497
+ S: this,
498
+ C: (f, a) => f(...a)
499
+ });
500
+ });
501
+ ctx.onDispose(() => {
502
+ server.close();
503
+ });
504
+ }
505
+ /**
506
+ * Websocket.
507
+ */
508
+ async _createWebsocket(ctx, space, def, trigger, options = {
509
+ retryDelay: 2,
510
+ maxAttempts: 5
511
+ }) {
512
+ import_log3.log.info("websocket", {
513
+ space: space.key,
514
+ trigger
515
+ }, {
516
+ F: __dxlog_file3,
517
+ L: 213,
518
+ S: this,
519
+ C: (f, a) => f(...a)
520
+ });
521
+ const { url } = trigger;
522
+ let ws;
523
+ for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {
524
+ const open = new import_async2.Trigger();
525
+ ws = new import_ws.default(url);
526
+ Object.assign(ws, {
527
+ onopen: () => {
528
+ import_log3.log.info("opened", {
529
+ url
530
+ }, {
531
+ F: __dxlog_file3,
532
+ L: 223,
533
+ S: this,
534
+ C: (f, a) => f(...a)
535
+ });
536
+ if (trigger.init) {
537
+ ws.send(new TextEncoder().encode(JSON.stringify(trigger.init)));
538
+ }
539
+ open.wake(true);
540
+ },
541
+ onclose: () => {
542
+ import_log3.log.info("closed", {
543
+ url
544
+ }, {
545
+ F: __dxlog_file3,
546
+ L: 232,
547
+ S: this,
548
+ C: (f, a) => f(...a)
549
+ });
550
+ open.wake(false);
551
+ },
552
+ onerror: (event) => {
553
+ import_log3.log.catch(event.error, {
554
+ url
555
+ }, {
556
+ F: __dxlog_file3,
557
+ L: 237,
558
+ S: this,
559
+ C: (f, a) => f(...a)
560
+ });
561
+ },
562
+ onmessage: async (event) => {
563
+ try {
564
+ const data = JSON.parse(new TextDecoder().decode(event.data));
565
+ await this._execFunction(def, {
566
+ space: space.key,
567
+ data
568
+ });
569
+ } catch (err) {
570
+ import_log3.log.catch(err, {
571
+ url
572
+ }, {
573
+ F: __dxlog_file3,
574
+ L: 245,
575
+ S: this,
576
+ C: (f, a) => f(...a)
577
+ });
578
+ }
579
+ }
580
+ });
581
+ const isOpen = await open.wait();
582
+ if (isOpen) {
583
+ break;
584
+ } else {
585
+ const wait = Math.pow(attempt, 2) * options.retryDelay;
586
+ if (attempt < options.maxAttempts) {
587
+ import_log3.log.warn(`failed to connect; trying again in ${wait}s`, {
588
+ attempt
589
+ }, {
590
+ F: __dxlog_file3,
591
+ L: 256,
592
+ S: this,
593
+ C: (f, a) => f(...a)
594
+ });
595
+ await (0, import_async2.sleep)(wait * 1e3);
596
+ }
597
+ }
598
+ }
599
+ ctx.onDispose(() => {
600
+ ws?.close();
601
+ });
602
+ }
603
+ /**
604
+ * ECHO subscription.
605
+ */
606
+ async _createSubscription(ctx, space, def, trigger) {
413
607
  import_log3.log.info("subscription", {
414
608
  space: space.key,
415
- triggerSubscription
609
+ trigger
416
610
  }, {
417
611
  F: __dxlog_file3,
418
- L: 126,
612
+ L: 271,
419
613
  S: this,
420
614
  C: (f, a) => f(...a)
421
615
  });
@@ -433,7 +627,7 @@ var Scheduler = class {
433
627
  updated: updated.length
434
628
  }, {
435
629
  F: __dxlog_file3,
436
- L: 139,
630
+ L: 281,
437
631
  S: this,
438
632
  C: (f, a) => f(...a)
439
633
  });
@@ -446,17 +640,15 @@ var Scheduler = class {
446
640
  task.schedule();
447
641
  });
448
642
  subscriptions.push(() => subscription.unsubscribe());
449
- const { type, props, deep, delay } = triggerSubscription;
643
+ const { filter, options: { deep, delay } = {} } = trigger;
450
644
  const update = ({ objects }) => {
451
645
  subscription.update(objects);
452
646
  if (deep) {
453
647
  import_log3.log.info("update", {
454
- type,
455
- deep,
456
648
  objects: objects.length
457
649
  }, {
458
650
  F: __dxlog_file3,
459
- L: 159,
651
+ L: 301,
460
652
  S: this,
461
653
  C: (f, a) => f(...a)
462
654
  });
@@ -470,61 +662,59 @@ var Scheduler = class {
470
662
  }
471
663
  }
472
664
  };
473
- const query = space.db.query(import_echo.Filter.typename(type, props));
474
- subscriptions.push(query.subscribe(delay ? (0, import_async2.debounce)(update, delay * 1e3) : update));
665
+ const query = space.db.query(import_echo.Filter.or(filter.map(({ type, props }) => import_echo.Filter.typename(type, props))));
666
+ subscriptions.push(query.subscribe(delay ? (0, import_async2.debounce)(update, delay) : update));
475
667
  ctx.onDispose(() => {
476
668
  subscriptions.forEach((unsubscribe) => unsubscribe());
477
669
  });
478
670
  }
479
- async _execFunction(def, data) {
480
- try {
481
- (0, import_log3.log)("request", {
482
- function: def.id
483
- }, {
484
- F: __dxlog_file3,
485
- L: 183,
486
- S: this,
487
- C: (f, a) => f(...a)
488
- });
489
- const { endpoint, callback } = this._options;
490
- let status = 0;
491
- if (endpoint) {
492
- const response = await fetch(`${this._options.endpoint}/${def.name}`, {
493
- method: "POST",
494
- headers: {
495
- "Content-Type": "application/json"
496
- },
497
- body: JSON.stringify(data)
498
- });
499
- status = response.status;
500
- } else if (callback) {
501
- status = await callback(data);
502
- }
503
- (0, import_log3.log)("result", {
504
- function: def.id,
505
- result: status
506
- }, {
507
- F: __dxlog_file3,
508
- L: 202,
509
- S: this,
510
- C: (f, a) => f(...a)
511
- });
512
- } catch (err) {
513
- import_log3.log.error("error", {
514
- function: def.id,
515
- error: err.message
516
- }, {
517
- F: __dxlog_file3,
518
- L: 204,
519
- S: this,
520
- C: (f, a) => f(...a)
521
- });
522
- }
523
- }
524
671
  };
672
+ var TimerTriggerSchema = S.struct({
673
+ cron: S.string
674
+ });
675
+ var WebhookTriggerSchema = S.struct({
676
+ port: S.number
677
+ });
678
+ var WebsocketTriggerSchema = S.struct({
679
+ url: S.string,
680
+ init: S.optional(S.record(S.string, S.any))
681
+ });
682
+ var SubscriptionTriggerSchema = S.struct({
683
+ spaceKey: S.optional(S.string),
684
+ // TODO(burdon): Define query DSL.
685
+ filter: S.array(S.struct({
686
+ type: S.string,
687
+ props: S.optional(S.record(S.string, S.any))
688
+ })),
689
+ options: S.optional(S.struct({
690
+ // Watch changes to object (not just creation).
691
+ deep: S.optional(S.boolean),
692
+ // Debounce changes (delay in ms).
693
+ delay: S.optional(S.number)
694
+ }))
695
+ });
696
+ var FunctionTriggerSchema = S.struct({
697
+ function: S.string.pipe(S.description("Function ID/URI.")),
698
+ timer: S.optional(TimerTriggerSchema),
699
+ webhook: S.optional(WebhookTriggerSchema),
700
+ websocket: S.optional(WebsocketTriggerSchema),
701
+ subscription: S.optional(SubscriptionTriggerSchema)
702
+ });
703
+ var FunctionDefSchema = S.struct({
704
+ id: S.string,
705
+ description: S.optional(S.string),
706
+ name: S.string,
707
+ // TODO(burdon): NPM/GitHub URL?
708
+ handler: S.string
709
+ });
710
+ var FunctionManifestSchema = S.struct({
711
+ functions: S.mutable(S.array(FunctionDefSchema)),
712
+ triggers: S.mutable(S.array(FunctionTriggerSchema))
713
+ });
525
714
  // Annotate the CommonJS export names for ESM import in node:
526
715
  0 && (module.exports = {
527
716
  DevServer,
717
+ FunctionManifestSchema,
528
718
  Scheduler,
529
719
  subscriptionHandler
530
720
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 { type EchoReactiveObject } 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?: 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 */\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?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable);\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 log.info('calling', { name });\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({ 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 { TextV0Type } from '@braneframe/types';\nimport { debounce, DeferredTask } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { type Space, Filter, createSubscription, type Query, getAutomergeObjectCore } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\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 invariant(trigger.schedule);\n let last = 0;\n let run = 0;\n // https://www.npmjs.com/package/cron#constructor\n const job = CronJob.from({\n cronTime: trigger.schedule,\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 private _createSubscription(ctx: Context, space: Space, def: FunctionDef, triggerSubscription: TriggerSubscription) {\n log.info('subscription', { space: space.key, 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 log.info('updated', { added: added.length, updated: updated.length });\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 TextV0Type) {\n subscriptions.push(\n getAutomergeObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)),\n );\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;AAGvC,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AAI;UACpEiH,QAAQ;UACRC,SAAS;YACP,gBAAgB;UAClB;UACA7G,MAAM8G,KAAKC,UAAUN,IAAAA;QACvB,CAAA;AAEAnE,iBAASD,SAASC;MACpB,WAAWoE,UAAU;AACnBpE,iBAAS,MAAMoE,SAASD,IAAAA;MAC1B;AAGAhJ,sBAAAA,KAAI,UAAU;QAAE6F,UAAUxE,IAAI1B;QAAI4J,QAAQ1E;MAAO,GAAA;;;;;;IACnD,SAASrD,KAAU;AACjBxB,kBAAAA,IAAIyB,MAAM,SAAS;QAAEoE,UAAUxE,IAAI1B;QAAI8B,OAAOD,IAAIgI;MAAQ,GAAA;;;;;;IAC5D;EACF;AACF;",
6
- "names": ["import_log", "import_async", "import_invariant", "import_util", "subscriptionHandler", "handler", "event", "context", "rest", "client", "space", "spaces", "get", "PublicKey", "from", "undefined", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "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", "catch", "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", "last", "run", "job", "CronJob", "cronTime", "runOnInit", "onTick", "delta", "count", "onDispose", "objectIds", "Set", "Array", "subscription", "createSubscription", "added", "updated", "object", "add", "push", "unsubscribe", "type", "props", "deep", "delay", "update", "content", "TextV0Type", "getAutomergeObjectCore", "updates", "on", "debounce", "query", "Filter", "typename", "data", "callback", "fetch", "method", "headers", "JSON", "stringify", "result", "message"]
3
+ "sources": ["../../../src/handler.ts", "../../../src/runtime/dev-server.ts", "../../../src/runtime/scheduler.ts", "../../../src/types.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 { type EchoReactiveObject } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\n// TODO(burdon): Context?\n// Lambda-like function definitions.\n// See: https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\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\n// TODO(burdon): ???\nexport type FunctionSubscriptionEvent2 = {\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 */\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?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable);\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 '../types';\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 log.info('calling', { name });\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({ 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';\nimport http from 'node:http';\nimport WebSocket from 'ws';\n\nimport { TextV0Type } from '@braneframe/types';\nimport { debounce, DeferredTask, sleep, Trigger } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { createSubscription, Filter, getAutomergeObjectCore, type Query, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type FunctionSubscriptionEvent } from '../handler';\nimport {\n type FunctionDef,\n type FunctionManifest,\n type FunctionTrigger,\n type SubscriptionTrigger,\n type TimerTrigger,\n type WebhookTrigger,\n type WebsocketTrigger,\n} from '../types';\n\ntype Callback = (data: FunctionSubscriptionEvent) => Promise<void>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function exectuion based on various triggers.\n */\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 // TODO(burdon): 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 //\n // Triggers types.\n //\n\n if (trigger.timer) {\n await this._createTimer(ctx, space, def, trigger.timer);\n }\n\n if (trigger.webhook) {\n await this._createWebhook(ctx, space, def, trigger.webhook);\n }\n\n if (trigger.websocket) {\n await this._createWebsocket(ctx, space, def, trigger.websocket);\n }\n\n if (trigger.subscription) {\n await this._createSubscription(ctx, space, def, trigger.subscription);\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 // TODO(burdon): Pass in Space key (common context).\n private async _execFunction(def: FunctionDef, data: any) {\n try {\n log.info('exec', { function: def.id });\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n 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 } else if (callback) {\n await callback(data);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.id });\n } catch (err: any) {\n log.error('error', { function: def.id, error: err.message });\n }\n }\n\n //\n // Triggers\n //\n\n /**\n * Cron timer.\n */\n private async _createTimer(ctx: Context, space: Space, def: FunctionDef, trigger: TimerTrigger) {\n log.info('timer', { space: space.key, trigger });\n const { cron } = trigger;\n\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { space: space.key });\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: 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 /**\n * Webhook.\n */\n private async _createWebhook(ctx: Context, space: Space, def: FunctionDef, trigger: WebhookTrigger) {\n log.info('webhook', { space: space.key, trigger });\n const { port } = trigger;\n\n // TODO(burdon): POST JSON.\n const server = http.createServer(async (req, res) => {\n await this._execFunction(def, { space: space.key });\n });\n\n server.listen(port, () => {\n log.info('started webhook', { port });\n });\n\n ctx.onDispose(() => {\n server.close();\n });\n }\n\n /**\n * Websocket.\n */\n private async _createWebsocket(\n ctx: Context,\n space: Space,\n def: FunctionDef,\n trigger: WebsocketTrigger,\n options: {\n retryDelay: number;\n maxAttempts: number;\n } = {\n retryDelay: 2,\n maxAttempts: 5,\n },\n ) {\n log.info('websocket', { space: space.key, trigger });\n const { url } = trigger;\n\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = new WebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (trigger.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(trigger.init)));\n }\n\n open.wake(true);\n },\n\n onclose: () => {\n log.info('closed', { url });\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch(event.error, { url });\n },\n\n onmessage: async (event) => {\n try {\n const data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n await this._execFunction(def, { space: space.key, data });\n } catch (err) {\n log.catch(err, { url });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (isOpen) {\n break;\n } else {\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\n ctx.onDispose(() => {\n ws?.close();\n });\n }\n\n /**\n * ECHO subscription.\n */\n private async _createSubscription(ctx: Context, space: Space, def: FunctionDef, trigger: SubscriptionTrigger) {\n log.info('subscription', { space: space.key, trigger });\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { space: space.key, objects: Array.from(objectIds) });\n });\n\n // TODO(burdon): Don't fire initially.\n // TODO(burdon): Subscription is called THREE times.\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n log.info('updated', { added: added.length, updated: updated.length });\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 { filter, options: { deep, delay } = {} } = trigger;\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', { objects: objects.length });\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextV0Type) {\n subscriptions.push(\n getAutomergeObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)),\n );\n }\n }\n }\n };\n\n // TODO(burdon): Is Filter.or implemented?\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.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport * as S from '@effect/schema/Schema';\n\nconst TimerTriggerSchema = S.struct({\n cron: S.string,\n});\n\nconst WebhookTriggerSchema = S.struct({\n port: S.number,\n});\n\nconst WebsocketTriggerSchema = S.struct({\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n});\n\nconst SubscriptionTriggerSchema = S.struct({\n spaceKey: S.optional(S.string),\n // TODO(burdon): Define query DSL.\n filter: S.array(\n S.struct({\n type: S.string,\n props: S.optional(S.record(S.string, S.any)),\n }),\n ),\n options: S.optional(\n S.struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.boolean),\n // Debounce changes (delay in ms).\n delay: S.optional(S.number),\n }),\n ),\n});\n\nconst FunctionTriggerSchema = S.struct({\n function: S.string.pipe(S.description('Function ID/URI.')),\n\n timer: S.optional(TimerTriggerSchema),\n webhook: S.optional(WebhookTriggerSchema),\n websocket: S.optional(WebsocketTriggerSchema),\n subscription: S.optional(SubscriptionTriggerSchema),\n});\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\nexport type FunctionTrigger = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function definition.\n */\n// TODO(burdon): Name vs. path?\nconst FunctionDefSchema = S.struct({\n id: S.string,\n description: S.optional(S.string),\n name: S.string,\n // TODO(burdon): NPM/GitHub URL?\n handler: S.string,\n});\n\nexport type FunctionDef = S.Schema.Type<typeof FunctionDefSchema>;\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.mutable(S.array(FunctionDefSchema)),\n triggers: S.mutable(S.array(FunctionTriggerSchema)),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuC;AAGvC,iBAAoB;AACpB,kBAA4B;ACJ5B,qBAAoB;AACpB,6BAAwB;AAExB,uBAAqB;AAErB,mBAAwB;AAExB,uBAA0B;AAC1B,IAAAA,cAAoB;ACRpB,kBAAwB;AACxB,uBAAiB;AACjB,gBAAsB;AAEtB,mBAA2B;AAC3B,IAAAC,gBAAuD;AAEvD,kBAA2F;AAC3F,qBAAwB;AACxB,IAAAC,oBAA0B;AAC1B,IAAAF,cAAoB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CAAA;AAOO,IAAMc,yBAA2Bf,EAAAA,OAAO;EAC7CzK,WAAayL,EAAAA,QAAUP,EAAAA,MAAMK,iBAAAA,CAAAA;EAC7BhH,UAAYkH,EAAAA,QAAUP,EAAAA,MAAME,qBAAAA,CAAAA;AAC9B,CAAA;",
6
+ "names": ["import_log", "import_async", "import_invariant", "import_util", "subscriptionHandler", "handler", "event", "context", "rest", "client", "space", "spaces", "get", "PublicKey", "from", "undefined", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "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", "catch", "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", "timer", "_createTimer", "webhook", "_createWebhook", "websocket", "_createWebsocket", "subscription", "_createSubscription", "delete", "dispose", "_execFunction", "data", "callback", "fetch", "method", "headers", "JSON", "stringify", "message", "cron", "task", "DeferredTask", "last", "run", "job", "CronJob", "cronTime", "runOnInit", "onTick", "delta", "count", "schedule", "onDispose", "server", "http", "createServer", "options", "retryDelay", "maxAttempts", "url", "ws", "attempt", "open", "WebSocket", "assign", "onopen", "init", "send", "TextEncoder", "encode", "onclose", "onerror", "onmessage", "parse", "TextDecoder", "decode", "isOpen", "Math", "pow", "sleep", "objectIds", "Set", "Array", "subscriptions", "createSubscription", "added", "updated", "object", "add", "push", "unsubscribe", "deep", "delay", "update", "content", "TextV0Type", "getAutomergeObjectCore", "updates", "on", "debounce", "query", "Filter", "or", "type", "props", "typename", "TimerTriggerSchema", "struct", "string", "WebhookTriggerSchema", "number", "WebsocketTriggerSchema", "optional", "record", "any", "SubscriptionTriggerSchema", "array", "boolean", "FunctionTriggerSchema", "pipe", "description", "FunctionDefSchema", "FunctionManifestSchema", "mutable"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/functions/src/handler.ts":{"bytes":5873,"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/manifest.ts":{"bytes":1910,"imports":[],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":19229,"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":25793,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@braneframe/types","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/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":24099},"packages/core/functions/dist/lib/node/index.cjs":{"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},{"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":"@braneframe/types","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/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":1057},"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4983},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":6345}},"bytes":12999}}}
1
+ {"inputs":{"packages/core/functions/src/handler.ts":{"bytes":6277,"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/runtime/dev-server.ts":{"bytes":19225,"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":37601,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/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/types.ts":{"bytes":6957,"imports":[{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":630,"imports":[{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33210},"packages/core/functions/dist/lib/node/index.cjs":{"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},{"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":"node:http","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"exports":["DevServer","FunctionManifestSchema","Scheduler","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/handler.ts":{"bytesInOutput":1057},"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4983},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":9707},"packages/core/functions/src/types.ts":{"bytesInOutput":1294}},"bytes":17722}}}
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CAChC;AAGD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MA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AAE/B,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAGF,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,gBAAgB,0BAA0B,CAAC,KACnD,gBAAgB,yBAAyB,CAgB3C,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export * from './handler';
2
- export * from './manifest';
3
2
  export * from './runtime';
3
+ export * from './types';
4
4
  //# sourceMappingURL=index.d.ts.map