@dxos/functions 0.7.1 → 0.7.2-staging.6d26b2a

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.
Files changed (53) hide show
  1. package/dist/lib/browser/{chunk-QX2SGAWR.mjs → chunk-2WV7BKNM.mjs} +28 -159
  2. package/dist/lib/browser/chunk-2WV7BKNM.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-FWIFI2MH.mjs → chunk-MKVZCFKN.mjs} +28 -15
  4. package/dist/lib/browser/chunk-MKVZCFKN.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +5 -7
  6. package/dist/lib/browser/index.mjs.map +2 -2
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +5 -3
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types.mjs +3 -1
  11. package/dist/lib/node/{chunk-OKV7IWWB.cjs → chunk-G2EVL5ME.cjs} +45 -176
  12. package/dist/lib/node/chunk-G2EVL5ME.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-GKDHAWCP.cjs → chunk-XRSOYOZ5.cjs} +31 -17
  14. package/dist/lib/node/chunk-XRSOYOZ5.cjs.map +7 -0
  15. package/dist/lib/node/index.cjs +14 -16
  16. package/dist/lib/node/index.cjs.map +2 -2
  17. package/dist/lib/node/meta.json +1 -1
  18. package/dist/lib/node/testing/index.cjs +13 -11
  19. package/dist/lib/node/testing/index.cjs.map +3 -3
  20. package/dist/lib/node/types.cjs +9 -7
  21. package/dist/lib/node/types.cjs.map +2 -2
  22. package/dist/lib/node-esm/{chunk-SPHZ5SOR.mjs → chunk-PCEHXPSI.mjs} +28 -159
  23. package/dist/lib/node-esm/chunk-PCEHXPSI.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-YSKH6PBN.mjs → chunk-UZVXZLDV.mjs} +28 -15
  25. package/dist/lib/node-esm/chunk-UZVXZLDV.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +5 -7
  27. package/dist/lib/node-esm/index.mjs.map +2 -2
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/testing/index.mjs +5 -3
  30. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  31. package/dist/lib/node-esm/types.mjs +3 -1
  32. package/dist/types/src/handler.d.ts +2 -2
  33. package/dist/types/src/trigger/type/index.d.ts +0 -1
  34. package/dist/types/src/trigger/type/index.d.ts.map +1 -1
  35. package/dist/types/src/types.d.ts +43 -77
  36. package/dist/types/src/types.d.ts.map +1 -1
  37. package/package.json +15 -15
  38. package/src/handler.ts +3 -3
  39. package/src/runtime/scheduler.test.ts +4 -55
  40. package/src/runtime/scheduler.ts +1 -1
  41. package/src/testing/functions-integration.test.ts +2 -2
  42. package/src/trigger/trigger-registry.test.ts +4 -4
  43. package/src/trigger/type/index.ts +0 -1
  44. package/src/types.ts +26 -24
  45. package/dist/lib/browser/chunk-FWIFI2MH.mjs.map +0 -7
  46. package/dist/lib/browser/chunk-QX2SGAWR.mjs.map +0 -7
  47. package/dist/lib/node/chunk-GKDHAWCP.cjs.map +0 -7
  48. package/dist/lib/node/chunk-OKV7IWWB.cjs.map +0 -7
  49. package/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map +0 -7
  51. package/dist/types/src/trigger/type/websocket-trigger.d.ts +0 -14
  52. package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +0 -1
  53. package/src/trigger/type/websocket-trigger.ts +0 -112
@@ -1 +1 @@
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-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5753},"packages/core/functions/dist/lib/node-esm/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-SPHZ5SOR.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs","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":2416},"packages/core/functions/dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32246},"packages/core/functions/dist/lib/node-esm/testing/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-SPHZ5SOR.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs","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":18164},"packages/core/functions/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32980},"packages/core/functions/dist/lib/node-esm/chunk-SPHZ5SOR.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs","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":17655},"packages/core/functions/dist/lib/node-esm/types.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/node-esm/types.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs","kind":"import-statement"}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionTrigger","FunctionTriggerSchema","TriggerSchema"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":417},"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7793},"packages/core/functions/dist/lib/node-esm/chunk-YSKH6PBN.mjs":{"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":3658}}}
1
+ {"inputs":{"packages/core/functions/src/types.ts":{"bytes":14838,"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/index.ts":{"bytes":751,"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"}],"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":21200,"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-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5752},"packages/core/functions/dist/lib/node-esm/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-PCEHXPSI.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs","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","TriggerKind","TriggerRegistry","TriggerSchema","createSubscriptionTrigger","createTimerTrigger","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":2356},"packages/core/functions/dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32288},"packages/core/functions/dist/lib/node-esm/testing/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-PCEHXPSI.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs","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":5364},"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":18197},"packages/core/functions/dist/lib/node-esm/chunk-PCEHXPSI.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":26827},"packages/core/functions/dist/lib/node-esm/chunk-PCEHXPSI.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs","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/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"],"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/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":14053},"packages/core/functions/dist/lib/node-esm/types.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/node-esm/types.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs","kind":"import-statement"}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionTrigger","FunctionTriggerSchema","TriggerKind","TriggerSchema"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":447},"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7683},"packages/core/functions/dist/lib/node-esm/chunk-UZVXZLDV.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_TYPES","FunctionDef","FunctionManifestSchema","FunctionTrigger","FunctionTriggerSchema","TriggerKind","TriggerSchema","__require"],"inputs":{"packages/core/functions/src/types.ts":{"bytesInOutput":3141}},"bytes":3843}}}
@@ -2,12 +2,12 @@ import { createRequire } from 'node:module';const require = createRequire(import
2
2
  import {
3
3
  FunctionRegistry,
4
4
  TriggerRegistry
5
- } from "../chunk-SPHZ5SOR.mjs";
5
+ } from "../chunk-PCEHXPSI.mjs";
6
6
  import {
7
7
  FunctionDef,
8
8
  FunctionTrigger,
9
9
  __require
10
- } from "../chunk-YSKH6PBN.mjs";
10
+ } from "../chunk-UZVXZLDV.mjs";
11
11
 
12
12
  // packages/core/functions/src/testing/setup.ts
13
13
  import { getRandomPort } from "get-port-please";
@@ -435,7 +435,9 @@ var Scheduler = class {
435
435
  const meta = {};
436
436
  for (const [key, value] of Object.entries(trigger.meta ?? {})) {
437
437
  if (value instanceof Reference) {
438
- const object = await space.db.loadObjectById(value.objectId);
438
+ const object = await space.db.query({
439
+ id: value.objectId
440
+ }).first();
439
441
  if (object) {
440
442
  meta[key] = object;
441
443
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/testing/setup.ts", "../../../../src/testing/types.ts", "../../../../src/runtime/dev-server.ts", "../../../../src/runtime/scheduler.ts", "../../../../src/testing/util.ts", "../../../../src/testing/manifest.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { getRandomPort } from 'get-port-please';\nimport path from 'node:path';\n\nimport { waitForCondition } from '@dxos/async';\nimport { Client, Config } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type TestBuilder } from '@dxos/client/testing';\nimport { range } from '@dxos/util';\n\nimport { TestType } from './types';\nimport { FunctionRegistry } from '../function';\nimport { DevServer, type DevServerOptions, Scheduler } from '../runtime';\nimport { TriggerRegistry } from '../trigger';\nimport { FunctionDef, FunctionTrigger } from '../types';\n\nexport type FunctionsPluginInitializer = (client: Client) => Promise<{ close: () => Promise<void> }>;\n\n// TODO(burdon): Extend/wrap TestBuilder.\n\nexport const createInitializedClients = async (testBuilder: TestBuilder, count: number = 1, config?: Config) => {\n const clients = range(count).map(\n () =>\n new Client({\n config,\n services: testBuilder.createLocalClientServices(),\n types: [FunctionDef, FunctionTrigger, TestType],\n }),\n );\n\n testBuilder.ctx.onDispose(() => Promise.all(clients.map((client) => client.destroy())));\n return Promise.all(\n clients.map(async (client, index) => {\n await client.initialize();\n await client.halo.createIdentity({ displayName: `Peer ${index}` });\n await client.spaces.waitUntilReady();\n return client;\n }),\n );\n};\n\nexport const createFunctionRuntime = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n): Promise<Client> => {\n const functionsPort = await getRandomPort('127.0.0.1');\n const config = new Config({\n runtime: {\n agent: {\n plugins: [{ id: 'dxos.org/agent/plugin/functions', config: { port: functionsPort } }],\n },\n },\n });\n\n const [client] = await createInitializedClients(testBuilder, 1, config);\n const plugin = await pluginInitializer(client);\n testBuilder.ctx.onDispose(() => plugin.close());\n return client;\n};\n\nexport const startFunctionsHost = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n options?: DevServerOptions,\n) => {\n const functionRuntime = await createFunctionRuntime(testBuilder, pluginInitializer);\n const functionsRegistry = new FunctionRegistry(functionRuntime);\n const devServer = await startDevServer(testBuilder, functionRuntime, functionsRegistry, options);\n const scheduler = await startScheduler(testBuilder, functionRuntime, devServer, functionsRegistry);\n return {\n scheduler,\n client: functionRuntime,\n waitForActiveTriggers: async (space: Space) => {\n await waitForCondition({ condition: () => scheduler.triggers.getActiveTriggers(space).length > 0 });\n },\n };\n};\n\nconst startScheduler = async (\n testBuilder: TestBuilder,\n client: Client,\n devServer: DevServer,\n functionRegistry: FunctionRegistry,\n) => {\n const triggerRegistry = new TriggerRegistry(client);\n const scheduler = new Scheduler(functionRegistry, triggerRegistry, { endpoint: devServer.endpoint });\n await scheduler.start();\n testBuilder.ctx.onDispose(() => scheduler.stop());\n return scheduler;\n};\n\nconst startDevServer = async (\n testBuilder: TestBuilder,\n client: Client,\n functionRegistry: FunctionRegistry,\n options?: { baseDir?: string },\n) => {\n const server = new DevServer(client, functionRegistry, {\n baseDir: path.join(__dirname, '../testing'),\n port: await getRandomPort('127.0.0.1'),\n ...options,\n });\n await server.start();\n testBuilder.ctx.onDispose(() => server.stop());\n return server;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S, TypedObject } from '@dxos/echo-schema';\n\nexport class TestType extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({\n title: S.String,\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 { asyncTimeout, Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionContext, type FunctionEvent, type FunctionHandler, type FunctionResponse } from '../handler';\nimport { type FunctionDef } from '../types';\n\nconst FN_TIMEOUT = 20_000;\n\nexport type DevServerOptions = {\n baseDir: string;\n port?: number;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for loading and invoking functions.\n * Functions are executed in the context of an authenticated client.\n */\nexport class DevServer {\n private _ctx = createContext();\n\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 _functionServiceRegistration?: string;\n private _proxy?: string;\n private _seq = 0;\n\n public readonly update = new Event<number>();\n\n constructor(\n private readonly _client: Client,\n private readonly _functionsRegistry: FunctionRegistry,\n private readonly _options: DevServerOptions,\n ) {}\n\n get stats() {\n return {\n seq: this._seq,\n };\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 start() {\n invariant(!this._server);\n log.info('starting...');\n this._ctx = createContext();\n\n // TODO(burdon): Change to hono.\n const app = express();\n app.use(express.json());\n\n app.post('/:path', async (req, res) => {\n const { path } = req.params;\n try {\n log.info('calling', { path });\n if (this._options.reload) {\n const { def } = this._handlers['/' + path];\n await this._load(def, true);\n }\n\n // TODO(burdon): Get function context.\n res.statusCode = await asyncTimeout(this.invoke('/' + path, req.body), FN_TIMEOUT);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = this._options.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 });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\n\n // Open after registration, so that it can be updated with the list of function definitions.\n await this._handleNewFunctions(this._functionsRegistry.getUniqueByUri());\n this._ctx.onDispose(this._functionsRegistry.registered.on(({ added }) => this._handleNewFunctions(added)));\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n\n log.info('started', { port: this._port });\n }\n\n async stop() {\n if (!this._server) {\n return;\n }\n\n log.info('stopping...');\n await this._ctx.dispose();\n\n const trigger = new Trigger();\n this._server.close(async () => {\n log.info('server stopped');\n try {\n if (this._functionServiceRegistration) {\n invariant(this._client.services.services.FunctionRegistryService);\n await this._client.services.services.FunctionRegistryService.unregister({\n registrationId: this._functionServiceRegistration,\n });\n\n log.info('unregistered', { registrationId: this._functionServiceRegistration });\n this._functionServiceRegistration = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n } catch (err) {\n trigger.throw(err as Error);\n }\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n log.info('stopped');\n }\n\n private async _handleNewFunctions(newFunctions: FunctionDef[]) {\n newFunctions.forEach((def) => this._load(def));\n await this._safeUpdateRegistration();\n log('new functions loaded', { newFunctions });\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, force?: boolean | undefined) {\n const { uri, route, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { uri, force });\n\n // Remove from cache.\n if (force) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(filePath))\n .forEach((key) => {\n delete require.cache[key];\n });\n }\n\n // TODO(burdon): Import types.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(filePath);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${uri}`);\n }\n\n this._handlers[route] = { def, handler: module.default };\n }\n\n private async _safeUpdateRegistration(): Promise<void> {\n invariant(this._functionServiceRegistration);\n try {\n await this._client.services.services.FunctionRegistryService!.updateRegistration({\n registrationId: this._functionServiceRegistration,\n functions: this.functions.map(({ def: { id, route } }) => ({ id, route })),\n });\n } catch (err) {\n log.catch(err);\n }\n }\n\n /**\n * Invoke function.\n */\n public async invoke(path: string, data: any): Promise<number> {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, path });\n const statusCode = await this._invoke(path, { data });\n\n log.info('res', { seq, path, statusCode, duration: Date.now() - now });\n this.update.emit(statusCode);\n return statusCode;\n }\n\n private async _invoke(path: string, event: FunctionEvent) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n } as any;\n\n let statusCode = 200;\n const response: FunctionResponse = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n return statusCode;\n }\n}\n\nconst createContext = () => new Context({ name: 'DevServer' });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport path from 'node:path';\n\nimport { Mutex } from '@dxos/async';\nimport { loadObjectReferences, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Reference } from '@dxos/echo-protocol';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionEventMeta } from '../handler';\nimport { type TriggerCallback, type TriggerRegistry } from '../trigger';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../types';\n\nexport type Callback = (data: any) => Promise<void | number>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function execution based on various trigger configurations.\n * Functions are scheduled within the context of a specific space.\n */\nexport class Scheduler {\n private _ctx = createContext();\n\n private readonly _functionUriToCallMutex = new Map<string, Mutex>();\n\n constructor(\n public readonly functions: FunctionRegistry,\n public readonly triggers: TriggerRegistry,\n private readonly _options: SchedulerOptions = {},\n ) {\n this.functions.registered.on(async ({ space, added }) => {\n await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);\n });\n this.triggers.registered.on(async ({ space, triggers }) => {\n await this._safeActivateTriggers(space, triggers, this.functions.getFunctions(space));\n });\n }\n\n async start() {\n await this._ctx.dispose();\n this._ctx = createContext();\n await this.functions.open(this._ctx);\n await this.triggers.open(this._ctx);\n }\n\n async stop() {\n await this._ctx.dispose();\n await this.functions.close();\n await this.triggers.close();\n }\n\n // TODO(burdon): Remove and update registries directly?\n public async register(space: Space, manifest: FunctionManifest) {\n await this.functions.register(space, manifest.functions);\n await this.triggers.register(space, manifest);\n }\n\n private async _safeActivateTriggers(\n space: Space,\n triggers: FunctionTrigger[],\n functions: FunctionDef[],\n ): Promise<void> {\n const mountTasks = triggers.map((trigger) => {\n return this.activate(space, functions, trigger);\n });\n\n await Promise.all(mountTasks).catch(log.catch);\n }\n\n /**\n * Activate trigger.\n */\n // TODO(burdon): How are triggers deactivated?\n private async activate(space: Space, functions: FunctionDef[], trigger: FunctionTrigger) {\n const definition = functions.find((def) => def.uri === trigger.function);\n if (!definition) {\n log.info('function is not found for trigger', { trigger });\n return;\n }\n\n const execFunction: TriggerCallback = async (args) => {\n const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();\n this._functionUriToCallMutex.set(definition.uri, mutex);\n\n log.info('function triggered, waiting for mutex', { uri: definition.uri });\n return mutex.executeSynchronized(async () => {\n log.info('mutex acquired', { uri: definition.uri });\n\n // Load potential references in meta properties to serialize.\n await loadObjectReferences(trigger, (t) => Object.values(t.meta ?? {}));\n const meta: FunctionTrigger['meta'] = {};\n for (const [key, value] of Object.entries(trigger.meta ?? {})) {\n if (value instanceof Reference) {\n const object = await space.db.loadObjectById(value.objectId);\n if (object) {\n meta[key] = object;\n }\n } else {\n meta[key] = value;\n }\n }\n\n return this._execFunction(definition, trigger, {\n meta,\n data: { ...args, spaceKey: space.key },\n });\n });\n };\n\n await this.triggers.activate(space, trigger, execFunction);\n log('activated trigger', { space: space.key, trigger });\n }\n\n /**\n * Invoke function RPC.\n */\n private async _execFunction<TData, TMeta>(\n def: FunctionDef,\n trigger: FunctionTrigger,\n { meta, data }: { meta?: TMeta; data: TData },\n ): Promise<number> {\n let status = 0;\n try {\n // TODO(burdon): Pass in Space key (common context)?\n const payload = Object.assign({}, meta && ({ meta } satisfies FunctionEventMeta<TMeta>), data);\n\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const url = path.join(endpoint, def.route);\n log.info('exec', { function: def.uri, url, triggerType: trigger.spec?.type });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(payload),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.uri });\n status = (await callback(payload)) ?? 200;\n }\n\n // Check errors.\n if (status && status >= 400) {\n throw new Error(`Response: ${status}`);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.uri, status });\n } catch (err: any) {\n log.error('error', { function: def.uri, error: err.message });\n status = 500;\n }\n\n return status;\n }\n}\n\nconst createContext = () => new Context({ name: 'FunctionScheduler' });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Client } from '@dxos/client';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { performInvitation } from '@dxos/client/testing';\nimport { invariant } from '@dxos/invariant';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { FunctionTrigger } from '../types';\n\nexport const triggerWebhook = async (space: Space, uri: string) => {\n const trigger = (\n await space.db.query(Filter.schema(FunctionTrigger, (trigger: FunctionTrigger) => trigger.function === uri)).run()\n ).objects[0];\n invariant(trigger.spec?.type === 'webhook');\n void fetch(`http://localhost:${trigger.spec.port}`);\n};\n\nexport const inviteMember = async (host: Space, guest: Client) => {\n const [{ invitation: hostInvitation }] = await Promise.all(performInvitation({ host, guest: guest.spaces }));\n if (hostInvitation?.state !== Invitation.State.SUCCESS) {\n throw new Error(`Expected ${hostInvitation?.state} to be ${Invitation.State.SUCCESS}.`);\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { FunctionManifest } from '../types';\n\nexport const testFunctionManifest: FunctionManifest = {\n functions: [\n {\n uri: 'example.com/function/test',\n route: 'test',\n handler: 'test',\n },\n ],\n};\n"],
5
- "mappings": ";;;;;;;;;;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,WAAU;AAEjB,SAASC,wBAAwB;AACjC,SAASC,QAAQC,cAAc;AAG/B,SAASC,aAAa;;;ACPtB,SAASC,GAAGC,mBAAmB;AAExB,IAAMC,WAAN,cAAuBC,YAAY;EAAEC,UAAU;EAAyBC,SAAS;AAAQ,CAAA,EAAG;EACjGC,OAAOC,EAAEC;AACX,CAAA,EAAA;AAAI;;;ACJJ,OAAOC,aAAa;AACpB,SAASC,eAAe;AAExB,SAASC,YAAY;AAErB,SAASC,cAAcC,OAAOC,eAAe;AAE7C,SAASC,eAAe;AACxB,SAASC,iB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AE;AACpD;AAEO,IAAMC,eAAe,OAAOC,MAAaC,UAAAA;AAC9C,QAAM,CAAC,EAAEC,YAAYC,eAAc,CAAE,IAAI,MAAMC,QAAQC,IAAIC,kBAAkB;IAAEN;IAAMC,OAAOA,MAAMM;EAAO,CAAA,CAAA;AACzG,MAAIJ,gBAAgBK,UAAUC,WAAWC,MAAMC,SAAS;AACtD,UAAM,IAAIC,MAAM,YAAYT,gBAAgBK,KAAAA,UAAeC,WAAWC,MAAMC,OAAO,GAAG;EACxF;AACF;;;ACnBO,IAAME,uBAAyC;EACpDC,WAAW;IACT;MACEC,KAAK;MACLC,OAAO;MACPC,SAAS;IACX;;AAEJ;",
6
- "names": ["getRandomPort", "path", "waitForCondition", "Client", "Config", "range", "S", "TypedObject", "TestType", "TypedObject", "typename", "version", "title", "S", "String", "express", "getPort", "join", "asyncTimeout", "Event", "Trigger", "Context", "invariant", "log", "FN_TIMEOUT", "DevServer", "constructor", "_client", "_functionsRegistry", "_options", "_ctx", "createContext", "_handlers", "_seq", "update", "Event", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "start", "_server", "log", "info", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "def", "_load", "statusCode", "asyncTimeout", "invoke", "body", "end", "err", "catch", "port", "getPort", "host", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_functionServiceRegistration", "_handleNewFunctions", "getUniqueByUri", "onDispose", "registered", "on", "added", "stop", "Error", "dispose", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "throw", "wait", "newFunctions", "forEach", "_safeUpdateRegistration", "force", "uri", "route", "handler", "filePath", "join", "baseDir", "keys", "require", "cache", "filter", "key", "startsWith", "module", "default", "updateRegistration", "map", "id", "data", "now", "Date", "_invoke", "duration", "emit", "event", "context", "client", "dataDir", "response", "status", "code", "Context", "name", "path", "Mutex", "loadObjectReferences", "Context", "Reference", "log", "Scheduler", "constructor", "functions", "triggers", "_options", "_ctx", "createContext", "_functionUriToCallMutex", "Map", "registered", "on", "space", "added", "_safeActivateTriggers", "getInactiveTriggers", "getFunctions", "start", "dispose", "open", "stop", "close", "register", "manifest", "mountTasks", "map", "trigger", "activate", "Promise", "all", "catch", "definition", "find", "def", "uri", "function", "info", "execFunction", "args", "mutex", "get", "set", "executeSynchronized", "t", "Object", "values", "meta", "key", "value", "entries", "object", "db", "loadObjectById", "objectId", "_execFunction", "data", "spaceKey", "status", "payload", "assign", "endpoint", "callback", "url", "join", "route", "triggerType", "spec", "type", "response", "fetch", "method", "headers", "body", "JSON", "stringify", "Error", "err", "error", "message", "name", "createInitializedClients", "testBuilder", "count", "config", "clients", "range", "map", "Client", "services", "createLocalClientServices", "types", "FunctionDef", "FunctionTrigger", "TestType", "ctx", "onDispose", "Promise", "all", "client", "destroy", "index", "initialize", "halo", "createIdentity", "displayName", "spaces", "waitUntilReady", "createFunctionRuntime", "pluginInitializer", "functionsPort", "getRandomPort", "Config", "runtime", "agent", "plugins", "id", "port", "plugin", "close", "startFunctionsHost", "options", "functionRuntime", "functionsRegistry", "FunctionRegistry", "devServer", "startDevServer", "scheduler", "startScheduler", "waitForActiveTriggers", "space", "waitForCondition", "condition", "triggers", "getActiveTriggers", "length", "functionRegistry", "triggerRegistry", "TriggerRegistry", "Scheduler", "endpoint", "start", "stop", "server", "DevServer", "baseDir", "path", "join", "__dirname", "Filter", "performInvitation", "invariant", "Invitation", "triggerWebhook", "space", "uri", "trigger", "db", "query", "Filter", "schema", "FunctionTrigger", "function", "run", "objects", "invariant", "spec", "type", "fetch", "port", "inviteMember", "host", "guest", "invitation", "hostInvitation", "Promise", "all", "performInvitation", "spaces", "state", "Invitation", "State", "SUCCESS", "Error", "testFunctionManifest", "functions", "uri", "route", "handler"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { getRandomPort } from 'get-port-please';\nimport path from 'node:path';\n\nimport { waitForCondition } from '@dxos/async';\nimport { Client, Config } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type TestBuilder } from '@dxos/client/testing';\nimport { range } from '@dxos/util';\n\nimport { TestType } from './types';\nimport { FunctionRegistry } from '../function';\nimport { DevServer, type DevServerOptions, Scheduler } from '../runtime';\nimport { TriggerRegistry } from '../trigger';\nimport { FunctionDef, FunctionTrigger } from '../types';\n\nexport type FunctionsPluginInitializer = (client: Client) => Promise<{ close: () => Promise<void> }>;\n\n// TODO(burdon): Extend/wrap TestBuilder.\n\nexport const createInitializedClients = async (testBuilder: TestBuilder, count: number = 1, config?: Config) => {\n const clients = range(count).map(\n () =>\n new Client({\n config,\n services: testBuilder.createLocalClientServices(),\n types: [FunctionDef, FunctionTrigger, TestType],\n }),\n );\n\n testBuilder.ctx.onDispose(() => Promise.all(clients.map((client) => client.destroy())));\n return Promise.all(\n clients.map(async (client, index) => {\n await client.initialize();\n await client.halo.createIdentity({ displayName: `Peer ${index}` });\n await client.spaces.waitUntilReady();\n return client;\n }),\n );\n};\n\nexport const createFunctionRuntime = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n): Promise<Client> => {\n const functionsPort = await getRandomPort('127.0.0.1');\n const config = new Config({\n runtime: {\n agent: {\n plugins: [{ id: 'dxos.org/agent/plugin/functions', config: { port: functionsPort } }],\n },\n },\n });\n\n const [client] = await createInitializedClients(testBuilder, 1, config);\n const plugin = await pluginInitializer(client);\n testBuilder.ctx.onDispose(() => plugin.close());\n return client;\n};\n\nexport const startFunctionsHost = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n options?: DevServerOptions,\n) => {\n const functionRuntime = await createFunctionRuntime(testBuilder, pluginInitializer);\n const functionsRegistry = new FunctionRegistry(functionRuntime);\n const devServer = await startDevServer(testBuilder, functionRuntime, functionsRegistry, options);\n const scheduler = await startScheduler(testBuilder, functionRuntime, devServer, functionsRegistry);\n return {\n scheduler,\n client: functionRuntime,\n waitForActiveTriggers: async (space: Space) => {\n await waitForCondition({ condition: () => scheduler.triggers.getActiveTriggers(space).length > 0 });\n },\n };\n};\n\nconst startScheduler = async (\n testBuilder: TestBuilder,\n client: Client,\n devServer: DevServer,\n functionRegistry: FunctionRegistry,\n) => {\n const triggerRegistry = new TriggerRegistry(client);\n const scheduler = new Scheduler(functionRegistry, triggerRegistry, { endpoint: devServer.endpoint });\n await scheduler.start();\n testBuilder.ctx.onDispose(() => scheduler.stop());\n return scheduler;\n};\n\nconst startDevServer = async (\n testBuilder: TestBuilder,\n client: Client,\n functionRegistry: FunctionRegistry,\n options?: { baseDir?: string },\n) => {\n const server = new DevServer(client, functionRegistry, {\n baseDir: path.join(__dirname, '../testing'),\n port: await getRandomPort('127.0.0.1'),\n ...options,\n });\n await server.start();\n testBuilder.ctx.onDispose(() => server.stop());\n return server;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S, TypedObject } from '@dxos/echo-schema';\n\nexport class TestType extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({\n title: S.String,\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 { asyncTimeout, Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionContext, type FunctionEvent, type FunctionHandler, type FunctionResponse } from '../handler';\nimport { type FunctionDef } from '../types';\n\nconst FN_TIMEOUT = 20_000;\n\nexport type DevServerOptions = {\n baseDir: string;\n port?: number;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for loading and invoking functions.\n * Functions are executed in the context of an authenticated client.\n */\nexport class DevServer {\n private _ctx = createContext();\n\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 _functionServiceRegistration?: string;\n private _proxy?: string;\n private _seq = 0;\n\n public readonly update = new Event<number>();\n\n constructor(\n private readonly _client: Client,\n private readonly _functionsRegistry: FunctionRegistry,\n private readonly _options: DevServerOptions,\n ) {}\n\n get stats() {\n return {\n seq: this._seq,\n };\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 start() {\n invariant(!this._server);\n log.info('starting...');\n this._ctx = createContext();\n\n // TODO(burdon): Change to hono.\n const app = express();\n app.use(express.json());\n\n app.post('/:path', async (req, res) => {\n const { path } = req.params;\n try {\n log.info('calling', { path });\n if (this._options.reload) {\n const { def } = this._handlers['/' + path];\n await this._load(def, true);\n }\n\n // TODO(burdon): Get function context.\n res.statusCode = await asyncTimeout(this.invoke('/' + path, req.body), FN_TIMEOUT);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = this._options.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 });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\n\n // Open after registration, so that it can be updated with the list of function definitions.\n await this._handleNewFunctions(this._functionsRegistry.getUniqueByUri());\n this._ctx.onDispose(this._functionsRegistry.registered.on(({ added }) => this._handleNewFunctions(added)));\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n\n log.info('started', { port: this._port });\n }\n\n async stop() {\n if (!this._server) {\n return;\n }\n\n log.info('stopping...');\n await this._ctx.dispose();\n\n const trigger = new Trigger();\n this._server.close(async () => {\n log.info('server stopped');\n try {\n if (this._functionServiceRegistration) {\n invariant(this._client.services.services.FunctionRegistryService);\n await this._client.services.services.FunctionRegistryService.unregister({\n registrationId: this._functionServiceRegistration,\n });\n\n log.info('unregistered', { registrationId: this._functionServiceRegistration });\n this._functionServiceRegistration = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n } catch (err) {\n trigger.throw(err as Error);\n }\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n log.info('stopped');\n }\n\n private async _handleNewFunctions(newFunctions: FunctionDef[]) {\n newFunctions.forEach((def) => this._load(def));\n await this._safeUpdateRegistration();\n log('new functions loaded', { newFunctions });\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, force?: boolean | undefined) {\n const { uri, route, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { uri, force });\n\n // Remove from cache.\n if (force) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(filePath))\n .forEach((key) => {\n delete require.cache[key];\n });\n }\n\n // TODO(burdon): Import types.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(filePath);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${uri}`);\n }\n\n this._handlers[route] = { def, handler: module.default };\n }\n\n private async _safeUpdateRegistration(): Promise<void> {\n invariant(this._functionServiceRegistration);\n try {\n await this._client.services.services.FunctionRegistryService!.updateRegistration({\n registrationId: this._functionServiceRegistration,\n functions: this.functions.map(({ def: { id, route } }) => ({ id, route })),\n });\n } catch (err) {\n log.catch(err);\n }\n }\n\n /**\n * Invoke function.\n */\n public async invoke(path: string, data: any): Promise<number> {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, path });\n const statusCode = await this._invoke(path, { data });\n\n log.info('res', { seq, path, statusCode, duration: Date.now() - now });\n this.update.emit(statusCode);\n return statusCode;\n }\n\n private async _invoke(path: string, event: FunctionEvent) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n } as any;\n\n let statusCode = 200;\n const response: FunctionResponse = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n return statusCode;\n }\n}\n\nconst createContext = () => new Context({ name: 'DevServer' });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport path from 'node:path';\n\nimport { Mutex } from '@dxos/async';\nimport { loadObjectReferences, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Reference } from '@dxos/echo-protocol';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionEventMeta } from '../handler';\nimport { type TriggerCallback, type TriggerRegistry } from '../trigger';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../types';\n\nexport type Callback = (data: any) => Promise<void | number>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function execution based on various trigger configurations.\n * Functions are scheduled within the context of a specific space.\n */\nexport class Scheduler {\n private _ctx = createContext();\n\n private readonly _functionUriToCallMutex = new Map<string, Mutex>();\n\n constructor(\n public readonly functions: FunctionRegistry,\n public readonly triggers: TriggerRegistry,\n private readonly _options: SchedulerOptions = {},\n ) {\n this.functions.registered.on(async ({ space, added }) => {\n await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);\n });\n this.triggers.registered.on(async ({ space, triggers }) => {\n await this._safeActivateTriggers(space, triggers, this.functions.getFunctions(space));\n });\n }\n\n async start() {\n await this._ctx.dispose();\n this._ctx = createContext();\n await this.functions.open(this._ctx);\n await this.triggers.open(this._ctx);\n }\n\n async stop() {\n await this._ctx.dispose();\n await this.functions.close();\n await this.triggers.close();\n }\n\n // TODO(burdon): Remove and update registries directly?\n public async register(space: Space, manifest: FunctionManifest) {\n await this.functions.register(space, manifest.functions);\n await this.triggers.register(space, manifest);\n }\n\n private async _safeActivateTriggers(\n space: Space,\n triggers: FunctionTrigger[],\n functions: FunctionDef[],\n ): Promise<void> {\n const mountTasks = triggers.map((trigger) => {\n return this.activate(space, functions, trigger);\n });\n\n await Promise.all(mountTasks).catch(log.catch);\n }\n\n /**\n * Activate trigger.\n */\n // TODO(burdon): How are triggers deactivated?\n private async activate(space: Space, functions: FunctionDef[], trigger: FunctionTrigger) {\n const definition = functions.find((def) => def.uri === trigger.function);\n if (!definition) {\n log.info('function is not found for trigger', { trigger });\n return;\n }\n\n const execFunction: TriggerCallback = async (args) => {\n const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();\n this._functionUriToCallMutex.set(definition.uri, mutex);\n\n log.info('function triggered, waiting for mutex', { uri: definition.uri });\n return mutex.executeSynchronized(async () => {\n log.info('mutex acquired', { uri: definition.uri });\n\n // Load potential references in meta properties to serialize.\n await loadObjectReferences(trigger, (t) => Object.values(t.meta ?? {}));\n const meta: FunctionTrigger['meta'] = {};\n for (const [key, value] of Object.entries(trigger.meta ?? {})) {\n if (value instanceof Reference) {\n const object = await space.db.query({ id: value.objectId }).first();\n if (object) {\n meta[key] = object;\n }\n } else {\n meta[key] = value;\n }\n }\n\n return this._execFunction(definition, trigger, {\n meta,\n data: { ...args, spaceKey: space.key },\n });\n });\n };\n\n await this.triggers.activate(space, trigger, execFunction);\n log('activated trigger', { space: space.key, trigger });\n }\n\n /**\n * Invoke function RPC.\n */\n private async _execFunction<TData, TMeta>(\n def: FunctionDef,\n trigger: FunctionTrigger,\n { meta, data }: { meta?: TMeta; data: TData },\n ): Promise<number> {\n let status = 0;\n try {\n // TODO(burdon): Pass in Space key (common context)?\n const payload = Object.assign({}, meta && ({ meta } satisfies FunctionEventMeta<TMeta>), data);\n\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const url = path.join(endpoint, def.route);\n log.info('exec', { function: def.uri, url, triggerType: trigger.spec?.type });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(payload),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.uri });\n status = (await callback(payload)) ?? 200;\n }\n\n // Check errors.\n if (status && status >= 400) {\n throw new Error(`Response: ${status}`);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.uri, status });\n } catch (err: any) {\n log.error('error', { function: def.uri, error: err.message });\n status = 500;\n }\n\n return status;\n }\n}\n\nconst createContext = () => new Context({ name: 'FunctionScheduler' });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Client } from '@dxos/client';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { performInvitation } from '@dxos/client/testing';\nimport { invariant } from '@dxos/invariant';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { FunctionTrigger } from '../types';\n\nexport const triggerWebhook = async (space: Space, uri: string) => {\n const trigger = (\n await space.db.query(Filter.schema(FunctionTrigger, (trigger: FunctionTrigger) => trigger.function === uri)).run()\n ).objects[0];\n invariant(trigger.spec?.type === 'webhook');\n void fetch(`http://localhost:${trigger.spec.port}`);\n};\n\nexport const inviteMember = async (host: Space, guest: Client) => {\n const [{ invitation: hostInvitation }] = await Promise.all(performInvitation({ host, guest: guest.spaces }));\n if (hostInvitation?.state !== Invitation.State.SUCCESS) {\n throw new Error(`Expected ${hostInvitation?.state} to be ${Invitation.State.SUCCESS}.`);\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { FunctionManifest } from '../types';\n\nexport const testFunctionManifest: FunctionManifest = {\n functions: [\n {\n uri: 'example.com/function/test',\n route: 'test',\n handler: 'test',\n },\n ],\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,WAAU;AAEjB,SAASC,wBAAwB;AACjC,SAASC,QAAQC,cAAc;AAG/B,SAASC,aAAa;;;ACPtB,SAASC,GAAGC,mBAAmB;AAExB,IAAMC,WAAN,cAAuBC,YAAY;EAAEC,UAAU;EAAyBC,SAAS;AAAQ,CAAA,EAAG;EACjGC,OAAOC,EAAEC;AACX,CAAA,EAAA;AAAI;;;ACJJ,OAAOC,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AAG,GAChHC,QAAQ,CAAA;AACVC,EAAAA,WAAUT,QAAQU,MAAMC,SAAS,WAAA,QAAA;;;;;;;;;AACjC,OAAKC,MAAM,oBAAoBZ,QAAQU,KAAKG,IAAI,EAAE;AACpD;AAEO,IAAMC,eAAe,OAAOC,MAAaC,UAAAA;AAC9C,QAAM,CAAC,EAAEC,YAAYC,eAAc,CAAE,IAAI,MAAMC,QAAQC,IAAIC,kBAAkB;IAAEN;IAAMC,OAAOA,MAAMM;EAAO,CAAA,CAAA;AACzG,MAAIJ,gBAAgBK,UAAUC,WAAWC,MAAMC,SAAS;AACtD,UAAM,IAAIC,MAAM,YAAYT,gBAAgBK,KAAAA,UAAeC,WAAWC,MAAMC,OAAO,GAAG;EACxF;AACF;;;ACnBO,IAAME,uBAAyC;EACpDC,WAAW;IACT;MACEC,KAAK;MACLC,OAAO;MACPC,SAAS;IACX;;AAEJ;",
6
+ "names": ["getRandomPort", "path", "waitForCondition", "Client", "Config", "range", "S", "TypedObject", "TestType", "TypedObject", "typename", "version", "title", "S", "String", "express", "getPort", "join", "asyncTimeout", "Event", "Trigger", "Context", "invariant", "log", "FN_TIMEOUT", "DevServer", "constructor", "_client", "_functionsRegistry", "_options", "_ctx", "createContext", "_handlers", "_seq", "update", "Event", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "start", "_server", "log", "info", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "def", "_load", "statusCode", "asyncTimeout", "invoke", "body", "end", "err", "catch", "port", "getPort", "host", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_functionServiceRegistration", "_handleNewFunctions", "getUniqueByUri", "onDispose", "registered", "on", "added", "stop", "Error", "dispose", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "throw", "wait", "newFunctions", "forEach", "_safeUpdateRegistration", "force", "uri", "route", "handler", "filePath", "join", "baseDir", "keys", "require", "cache", "filter", "key", "startsWith", "module", "default", "updateRegistration", "map", "id", "data", "now", "Date", "_invoke", "duration", "emit", "event", "context", "client", "dataDir", "response", "status", "code", "Context", "name", "path", "Mutex", "loadObjectReferences", "Context", "Reference", "log", "Scheduler", "constructor", "functions", "triggers", "_options", "_ctx", "createContext", "_functionUriToCallMutex", "Map", "registered", "on", "space", "added", "_safeActivateTriggers", "getInactiveTriggers", "getFunctions", "start", "dispose", "open", "stop", "close", "register", "manifest", "mountTasks", "map", "trigger", "activate", "Promise", "all", "catch", "definition", "find", "def", "uri", "function", "info", "execFunction", "args", "mutex", "get", "set", "executeSynchronized", "t", "Object", "values", "meta", "key", "value", "entries", "object", "db", "query", "id", "objectId", "first", "_execFunction", "data", "spaceKey", "status", "payload", "assign", "endpoint", "callback", "url", "join", "route", "triggerType", "spec", "type", "response", "fetch", "method", "headers", "body", "JSON", "stringify", "Error", "err", "error", "message", "name", "createInitializedClients", "testBuilder", "count", "config", "clients", "range", "map", "Client", "services", "createLocalClientServices", "types", "FunctionDef", "FunctionTrigger", "TestType", "ctx", "onDispose", "Promise", "all", "client", "destroy", "index", "initialize", "halo", "createIdentity", "displayName", "spaces", "waitUntilReady", "createFunctionRuntime", "pluginInitializer", "functionsPort", "getRandomPort", "Config", "runtime", "agent", "plugins", "id", "port", "plugin", "close", "startFunctionsHost", "options", "functionRuntime", "functionsRegistry", "FunctionRegistry", "devServer", "startDevServer", "scheduler", "startScheduler", "waitForActiveTriggers", "space", "waitForCondition", "condition", "triggers", "getActiveTriggers", "length", "functionRegistry", "triggerRegistry", "TriggerRegistry", "Scheduler", "endpoint", "start", "stop", "server", "DevServer", "baseDir", "path", "join", "__dirname", "Filter", "performInvitation", "invariant", "Invitation", "triggerWebhook", "space", "uri", "trigger", "db", "query", "Filter", "schema", "FunctionTrigger", "function", "run", "objects", "invariant", "spec", "type", "fetch", "port", "inviteMember", "host", "guest", "invitation", "hostInvitation", "Promise", "all", "performInvitation", "spaces", "state", "Invitation", "State", "SUCCESS", "Error", "testFunctionManifest", "functions", "uri", "route", "handler"]
7
7
  }
@@ -5,14 +5,16 @@ import {
5
5
  FunctionManifestSchema,
6
6
  FunctionTrigger,
7
7
  FunctionTriggerSchema,
8
+ TriggerKind,
8
9
  TriggerSchema
9
- } from "./chunk-YSKH6PBN.mjs";
10
+ } from "./chunk-UZVXZLDV.mjs";
10
11
  export {
11
12
  FUNCTION_TYPES,
12
13
  FunctionDef,
13
14
  FunctionManifestSchema,
14
15
  FunctionTrigger,
15
16
  FunctionTriggerSchema,
17
+ TriggerKind,
16
18
  TriggerSchema
17
19
  };
18
20
  //# sourceMappingURL=types.mjs.map
@@ -1,7 +1,7 @@
1
1
  import { type Schema as S } from '@effect/schema';
2
2
  import { type Client } from '@dxos/client';
3
3
  import { type Space, type SpaceId } from '@dxos/client/echo';
4
- import type { CoreDatabase, EchoReactiveObject } from '@dxos/echo-db';
4
+ import type { CoreDatabase, ReactiveEchoObject } from '@dxos/echo-db';
5
5
  /**
6
6
  * Function handler.
7
7
  */
@@ -66,7 +66,7 @@ export type RawSubscriptionData = {
66
66
  };
67
67
  export type SubscriptionData = {
68
68
  space?: Space;
69
- objects?: EchoReactiveObject<any>[];
69
+ objects?: ReactiveEchoObject<any>[];
70
70
  };
71
71
  /**
72
72
  * Handler wrapper for subscription events; extracts space and objects.
@@ -1,4 +1,3 @@
1
1
  export * from './subscription-trigger';
2
2
  export * from './timer-trigger';
3
- export * from './websocket-trigger';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/index.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/index.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
@@ -4,39 +4,33 @@ import { S } from '@dxos/echo-schema';
4
4
  * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
5
5
  * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
6
6
  */
7
- export type TriggerKind = 'timer' | 'webhook' | 'websocket' | 'subscription';
7
+ export declare enum TriggerKind {
8
+ Timer = "timer",
9
+ Webhook = "webhook",
10
+ Subscription = "subscription"
11
+ }
8
12
  /**
9
13
  * Cron timer.
10
14
  */
11
15
  declare const TimerTriggerSchema: S.mutable<S.Struct<{
12
- type: S.Literal<["timer"]>;
13
- cron: S.refine<string, S.Schema<string, string, never>>;
16
+ type: S.Literal<[TriggerKind.Timer]>;
17
+ cron: S.SchemaClass<string, string, never>;
14
18
  }>>;
15
19
  export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
16
20
  /**
17
21
  * Webhook.
18
22
  */
19
23
  declare const WebhookTriggerSchema: S.mutable<S.Struct<{
20
- type: S.Literal<["webhook"]>;
21
- method: typeof S.String;
22
- port: S.optional<typeof S.Number>;
24
+ type: S.Literal<[TriggerKind.Webhook]>;
25
+ method: S.optional<S.SchemaClass<string, string, never>>;
26
+ port: S.optional<S.SchemaClass<number, number, never>>;
23
27
  }>>;
24
28
  export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
25
- /**
26
- * Websocket.
27
- * @deprecated
28
- */
29
- declare const WebsocketTriggerSchema: S.mutable<S.Struct<{
30
- type: S.Literal<["websocket"]>;
31
- url: typeof S.String;
32
- init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
33
- }>>;
34
- export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
35
29
  /**
36
30
  * Subscription.
37
31
  */
38
32
  declare const SubscriptionTriggerSchema: S.mutable<S.Struct<{
39
- type: S.Literal<["subscription"]>;
33
+ type: S.Literal<[TriggerKind.Subscription]>;
40
34
  filter: S.Struct<{
41
35
  type: S.optional<S.SchemaClass<string, string, never>>;
42
36
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
@@ -51,18 +45,14 @@ export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema
51
45
  * Trigger schema (discriminated union).
52
46
  */
53
47
  export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
54
- type: S.Literal<["timer"]>;
55
- cron: S.refine<string, S.Schema<string, string, never>>;
48
+ type: S.Literal<[TriggerKind.Timer]>;
49
+ cron: S.SchemaClass<string, string, never>;
56
50
  }>>, S.mutable<S.Struct<{
57
- type: S.Literal<["webhook"]>;
58
- method: typeof S.String;
59
- port: S.optional<typeof S.Number>;
51
+ type: S.Literal<[TriggerKind.Webhook]>;
52
+ method: S.optional<S.SchemaClass<string, string, never>>;
53
+ port: S.optional<S.SchemaClass<number, number, never>>;
60
54
  }>>, S.mutable<S.Struct<{
61
- type: S.Literal<["websocket"]>;
62
- url: typeof S.String;
63
- init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
64
- }>>, S.mutable<S.Struct<{
65
- type: S.Literal<["subscription"]>;
55
+ type: S.Literal<[TriggerKind.Subscription]>;
66
56
  filter: S.Struct<{
67
57
  type: S.optional<S.SchemaClass<string, string, never>>;
68
58
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
@@ -80,18 +70,14 @@ export declare const FunctionTriggerSchema: S.Struct<{
80
70
  function: S.optional<S.SchemaClass<string, string, never>>;
81
71
  enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
82
72
  spec: S.optional<S.Union<[S.mutable<S.Struct<{
83
- type: S.Literal<["timer"]>;
84
- cron: S.refine<string, S.Schema<string, string, never>>;
85
- }>>, S.mutable<S.Struct<{
86
- type: S.Literal<["webhook"]>;
87
- method: typeof S.String;
88
- port: S.optional<typeof S.Number>;
73
+ type: S.Literal<[TriggerKind.Timer]>;
74
+ cron: S.SchemaClass<string, string, never>;
89
75
  }>>, S.mutable<S.Struct<{
90
- type: S.Literal<["websocket"]>;
91
- url: typeof S.String;
92
- init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
76
+ type: S.Literal<[TriggerKind.Webhook]>;
77
+ method: S.optional<S.SchemaClass<string, string, never>>;
78
+ port: S.optional<S.SchemaClass<number, number, never>>;
93
79
  }>>, S.mutable<S.Struct<{
94
- type: S.Literal<["subscription"]>;
80
+ type: S.Literal<[TriggerKind.Subscription]>;
95
81
  filter: S.Struct<{
96
82
  type: S.optional<S.SchemaClass<string, string, never>>;
97
83
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
@@ -108,18 +94,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
108
94
  function?: string | undefined;
109
95
  enabled?: boolean | undefined;
110
96
  spec?: {
111
- type: "timer";
97
+ type: TriggerKind.Timer;
112
98
  cron: string;
113
99
  } | {
114
- type: "webhook";
115
- method: string;
100
+ type: TriggerKind.Webhook;
101
+ method?: string | undefined;
116
102
  port?: number | undefined;
117
- } | {
118
- type: "websocket";
119
- url: string;
120
- init?: {
121
- readonly [x: string]: any;
122
- } | undefined;
123
103
  } | {
124
104
  filter: {
125
105
  readonly type?: string | undefined;
@@ -127,7 +107,7 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
127
107
  readonly [x: string]: any;
128
108
  } | undefined;
129
109
  };
130
- type: "subscription";
110
+ type: TriggerKind.Subscription;
131
111
  options?: {
132
112
  readonly deep?: boolean | undefined;
133
113
  readonly delay?: number | undefined;
@@ -142,18 +122,14 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
142
122
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
143
123
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
144
124
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
145
- type: S.Literal<["timer"]>;
146
- cron: S.refine<string, S.Schema<string, string, never>>;
147
- }>>, S.mutable<S.Struct<{
148
- type: S.Literal<["webhook"]>;
149
- method: typeof S.String;
150
- port: S.optional<typeof S.Number>;
125
+ type: S.Literal<[TriggerKind.Timer]>;
126
+ cron: S.SchemaClass<string, string, never>;
151
127
  }>>, S.mutable<S.Struct<{
152
- type: S.Literal<["websocket"]>;
153
- url: typeof S.String;
154
- init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
128
+ type: S.Literal<[TriggerKind.Webhook]>;
129
+ method: S.optional<S.SchemaClass<string, string, never>>;
130
+ port: S.optional<S.SchemaClass<number, number, never>>;
155
131
  }>>, S.mutable<S.Struct<{
156
- type: S.Literal<["subscription"]>;
132
+ type: S.Literal<[TriggerKind.Subscription]>;
157
133
  filter: S.Struct<{
158
134
  type: S.optional<S.SchemaClass<string, string, never>>;
159
135
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
@@ -210,18 +186,12 @@ export declare const FunctionManifestSchema: S.Struct<{
210
186
  function?: string | undefined;
211
187
  enabled?: boolean | undefined;
212
188
  spec?: {
213
- type: "timer";
189
+ type: TriggerKind.Timer;
214
190
  cron: string;
215
191
  } | {
216
- type: "webhook";
217
- method: string;
192
+ type: TriggerKind.Webhook;
193
+ method?: string | undefined;
218
194
  port?: number | undefined;
219
- } | {
220
- type: "websocket";
221
- url: string;
222
- init?: {
223
- readonly [x: string]: any;
224
- } | undefined;
225
195
  } | {
226
196
  filter: {
227
197
  readonly type?: string | undefined;
@@ -229,7 +199,7 @@ export declare const FunctionManifestSchema: S.Struct<{
229
199
  readonly [x: string]: any;
230
200
  } | undefined;
231
201
  };
232
- type: "subscription";
202
+ type: TriggerKind.Subscription;
233
203
  options?: {
234
204
  readonly deep?: boolean | undefined;
235
205
  readonly delay?: number | undefined;
@@ -244,18 +214,14 @@ export declare const FunctionManifestSchema: S.Struct<{
244
214
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
245
215
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
246
216
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
247
- type: S.Literal<["timer"]>;
248
- cron: S.refine<string, S.Schema<string, string, never>>;
249
- }>>, S.mutable<S.Struct<{
250
- type: S.Literal<["webhook"]>;
251
- method: typeof S.String;
252
- port: S.optional<typeof S.Number>;
217
+ type: S.Literal<[TriggerKind.Timer]>;
218
+ cron: S.SchemaClass<string, string, never>;
253
219
  }>>, S.mutable<S.Struct<{
254
- type: S.Literal<["websocket"]>;
255
- url: typeof S.String;
256
- init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
220
+ type: S.Literal<[TriggerKind.Webhook]>;
221
+ method: S.optional<S.SchemaClass<string, string, never>>;
222
+ port: S.optional<S.SchemaClass<number, number, never>>;
257
223
  }>>, S.mutable<S.Struct<{
258
- type: S.Literal<["subscription"]>;
224
+ type: S.Literal<[TriggerKind.Subscription]>;
259
225
  filter: S.Struct<{
260
226
  type: S.optional<S.SchemaClass<string, string, never>>;
261
227
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc,CAAC;AAK7E;;GAEG;AACH,QAAA,MAAM,kBAAkB;;;GAMN,CAAC;AAEnB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;GAEG;AACH,QAAA,MAAM,oBAAoB;;;;GAKR,CAAC;AAEnB,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;GAGG;AACH,QAAA,MAAM,sBAAsB;;;;GAIV,CAAC;AAEnB,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAQ5E;;GAEG;AACH,QAAA,MAAM,yBAAyB;;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