@dxos/functions 0.5.3-main.bbd33a9 → 0.5.3-main.bfb5bca

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 (37) hide show
  1. package/dist/lib/browser/{chunk-P3HPDHNI.mjs → chunk-4D4I3YMJ.mjs} +4 -4
  2. package/dist/lib/browser/{chunk-P3HPDHNI.mjs.map → chunk-4D4I3YMJ.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +145 -108
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types.mjs +1 -1
  7. package/dist/lib/node/{chunk-KTLM3JNV.cjs → chunk-3UYUR5N5.cjs} +7 -7
  8. package/dist/lib/node/{chunk-KTLM3JNV.cjs.map → chunk-3UYUR5N5.cjs.map} +3 -3
  9. package/dist/lib/node/index.cjs +156 -119
  10. package/dist/lib/node/index.cjs.map +3 -3
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/types.cjs +5 -5
  13. package/dist/lib/node/types.cjs.map +1 -1
  14. package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
  15. package/dist/types/src/testing/setup.d.ts.map +1 -1
  16. package/dist/types/src/trigger/trigger-registry.d.ts +2 -5
  17. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
  18. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -1
  19. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -1
  20. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -1
  21. package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -1
  22. package/dist/types/src/types.d.ts +15 -3
  23. package/dist/types/src/types.d.ts.map +1 -1
  24. package/package.json +14 -14
  25. package/schema/functions.json +5 -0
  26. package/src/runtime/dev-server.ts +3 -3
  27. package/src/runtime/scheduler.test.ts +14 -9
  28. package/src/runtime/scheduler.ts +7 -7
  29. package/src/testing/functions-integration.test.ts +1 -0
  30. package/src/testing/setup.ts +8 -10
  31. package/src/trigger/trigger-registry.test.ts +30 -13
  32. package/src/trigger/trigger-registry.ts +49 -39
  33. package/src/trigger/type/subscription-trigger.ts +13 -7
  34. package/src/trigger/type/timer-trigger.ts +4 -3
  35. package/src/trigger/type/webhook-trigger.ts +3 -2
  36. package/src/trigger/type/websocket-trigger.ts +4 -3
  37. package/src/types.ts +6 -3
@@ -53,7 +53,6 @@ var FunctionDef = class extends TypedObject({
53
53
  uri: S.string,
54
54
  description: S.optional(S.string),
55
55
  route: S.string,
56
- // TODO(burdon): NPM/GitHub/Docker/CF URL?
57
56
  handler: S.string
58
57
  }) {
59
58
  };
@@ -61,9 +60,10 @@ var FunctionTrigger = class extends TypedObject({
61
60
  typename: "dxos.org/type/FunctionTrigger",
62
61
  version: "0.1.0"
63
62
  })({
63
+ enabled: S.optional(S.boolean),
64
64
  function: S.string.pipe(S.description("Function URI.")),
65
- // Context is merged into the event data passed to the function.
66
- meta: S.optional(S.object),
65
+ // The `meta` property is merged into the event data passed to the function.
66
+ meta: S.optional(S.mutable(S.any)),
67
67
  spec: TriggerSpecSchema
68
68
  }) {
69
69
  };
@@ -83,4 +83,4 @@ export {
83
83
  FunctionManifestSchema,
84
84
  FUNCTION_SCHEMA
85
85
  };
86
- //# sourceMappingURL=chunk-P3HPDHNI.mjs.map
86
+ //# sourceMappingURL=chunk-4D4I3YMJ.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerSpec.\n * Every spec has a type field of type FunctionTriggerType that we can use to understand which\n * type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';\n\nconst SubscriptionTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('subscription'),\n // TODO(burdon): Define query DSL (from ECHO).\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);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\nconst TimerTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('timer'),\n cron: S.string,\n }),\n);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst WebhookTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('webhook'),\n method: S.string,\n // Assigned port.\n port: S.optional(S.number),\n }),\n);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\nconst WebsocketTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('websocket'),\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n }),\n);\n\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\n\nconst TriggerSpecSchema = S.union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n WebsocketTriggerSchema,\n SubscriptionTriggerSchema,\n);\n\nexport type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;\n\n/**\n * Function definition.\n */\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.string,\n description: S.optional(S.string),\n route: S.string,\n // TODO(burdon): NPM/GitHub/Docker/CF URL?\n handler: S.string,\n}) {}\n\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})({\n function: S.string.pipe(S.description('Function URI.')),\n // Context is merged into the event data passed to the function.\n meta: S.optional(S.object),\n spec: TriggerSpecSchema,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.optional(S.mutable(S.array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\n// TODO(burdon): Standards?\nexport const FUNCTION_SCHEMA = [FunctionDef, FunctionTrigger];\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAIA,SAASA,WAAWC,GAAGC,mBAAmB;AAU1C,IAAMC,4BAA4BC,EAAEC,QAClCD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,cAAA;;EAEhBC,QAAQL,EAAEM,MACRN,EAAEE,OAAO;IACPC,MAAMH,EAAEO;IACRC,OAAOR,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;EAC5C,CAAA,CAAA;EAEFC,SAASZ,EAAES,SACTT,EAAEE,OAAO;;IAEPW,MAAMb,EAAES,SAAST,EAAEc,OAAO;;IAE1BC,OAAOf,EAAES,SAAST,EAAEgB,MAAM;EAC5B,CAAA,CAAA;AAEJ,CAAA,CAAA;AAKF,IAAMC,qBAAqBjB,EAAEC,QAC3BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,OAAA;EAChBc,MAAMlB,EAAEO;AACV,CAAA,CAAA;AAKF,IAAMY,uBAAuBnB,EAAEC,QAC7BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,SAAA;EAChBgB,QAAQpB,EAAEO;;EAEVc,MAAMrB,EAAES,SAAST,EAAEgB,MAAM;AAC3B,CAAA,CAAA;AAKF,IAAMM,yBAAyBtB,EAAEC,QAC/BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,WAAA;EAChBmB,KAAKvB,EAAEO;EACPiB,MAAMxB,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;AAC3C,CAAA,CAAA;AAKF,IAAMc,oBAAoBzB,EAAE0B,MAC1BT,oBACAE,sBACAG,wBACAvB,yBAAAA;AAQK,IAAM4B,cAAN,cAA0BC,YAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,KAAK/B,EAAEO;EACPyB,aAAahC,EAAES,SAAST,EAAEO,MAAM;EAChC0B,OAAOjC,EAAEO;;EAET2B,SAASlC,EAAEO;AACb,CAAA,EAAA;AAAI;AAEG,IAAM4B,kBAAN,cAA8BP,YAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDM,UAAUpC,EAAEO,OAAO8B,KAAKrC,EAAEgC,YAAY,eAAA,CAAA;;EAEtCM,MAAMtC,EAAES,SAAST,EAAEuC,MAAM;EACzBC,MAAMf;AACR,CAAA,EAAA;AAAI;AAKG,IAAMgB,yBAAyBzC,EAAEE,OAAO;EAC7CwC,WAAW1C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUhB,WAAAA,CAAAA,CAAAA,CAAAA;EAClDiB,UAAU5C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUR,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAKO,IAAMU,kBAAkB;EAAClB;EAAaQ;;",
6
- "names": ["RawObject", "S", "TypedObject", "SubscriptionTriggerSchema", "S", "mutable", "struct", "type", "literal", "filter", "array", "string", "props", "optional", "record", "any", "options", "deep", "boolean", "delay", "number", "TimerTriggerSchema", "cron", "WebhookTriggerSchema", "method", "port", "WebsocketTriggerSchema", "url", "init", "TriggerSpecSchema", "union", "FunctionDef", "TypedObject", "typename", "version", "uri", "description", "route", "handler", "FunctionTrigger", "function", "pipe", "meta", "object", "spec", "FunctionManifestSchema", "functions", "RawObject", "triggers", "FUNCTION_SCHEMA"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerSpec.\n * Every spec has a type field of type FunctionTriggerType that we can use to understand which\n * type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';\n\nconst SubscriptionTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('subscription'),\n // TODO(burdon): Define query DSL (from ECHO).\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);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\nconst TimerTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('timer'),\n cron: S.string,\n }),\n);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst WebhookTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('webhook'),\n method: S.string,\n // Assigned port.\n port: S.optional(S.number),\n }),\n);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\nconst WebsocketTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('websocket'),\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n }),\n);\n\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\n\nconst TriggerSpecSchema = S.union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n WebsocketTriggerSchema,\n SubscriptionTriggerSchema,\n);\n\nexport type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;\n\n/**\n * Function definition.\n */\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.string,\n description: S.optional(S.string),\n route: S.string,\n handler: S.string,\n}) {}\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})({\n enabled: S.optional(S.boolean),\n function: S.string.pipe(S.description('Function URI.')),\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.any)),\n spec: TriggerSpecSchema,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.optional(S.mutable(S.array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\n// TODO(burdon): Standards?\nexport const FUNCTION_SCHEMA = [FunctionDef, FunctionTrigger];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAIA,SAASA,WAAWC,GAAGC,mBAAmB;AAU1C,IAAMC,4BAA4BC,EAAEC,QAClCD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,cAAA;;EAEhBC,QAAQL,EAAEM,MACRN,EAAEE,OAAO;IACPC,MAAMH,EAAEO;IACRC,OAAOR,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;EAC5C,CAAA,CAAA;EAEFC,SAASZ,EAAES,SACTT,EAAEE,OAAO;;IAEPW,MAAMb,EAAES,SAAST,EAAEc,OAAO;;IAE1BC,OAAOf,EAAES,SAAST,EAAEgB,MAAM;EAC5B,CAAA,CAAA;AAEJ,CAAA,CAAA;AAKF,IAAMC,qBAAqBjB,EAAEC,QAC3BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,OAAA;EAChBc,MAAMlB,EAAEO;AACV,CAAA,CAAA;AAKF,IAAMY,uBAAuBnB,EAAEC,QAC7BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,SAAA;EAChBgB,QAAQpB,EAAEO;;EAEVc,MAAMrB,EAAES,SAAST,EAAEgB,MAAM;AAC3B,CAAA,CAAA;AAKF,IAAMM,yBAAyBtB,EAAEC,QAC/BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,WAAA;EAChBmB,KAAKvB,EAAEO;EACPiB,MAAMxB,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;AAC3C,CAAA,CAAA;AAKF,IAAMc,oBAAoBzB,EAAE0B,MAC1BT,oBACAE,sBACAG,wBACAvB,yBAAAA;AAQK,IAAM4B,cAAN,cAA0BC,YAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,KAAK/B,EAAEO;EACPyB,aAAahC,EAAES,SAAST,EAAEO,MAAM;EAChC0B,OAAOjC,EAAEO;EACT2B,SAASlC,EAAEO;AACb,CAAA,EAAA;AAAI;AAKG,IAAM4B,kBAAN,cAA8BP,YAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDM,SAASpC,EAAES,SAAST,EAAEc,OAAO;EAC7BuB,UAAUrC,EAAEO,OAAO+B,KAAKtC,EAAEgC,YAAY,eAAA,CAAA;;EAEtCO,MAAMvC,EAAES,SAAST,EAAEC,QAAQD,EAAEW,GAAG,CAAA;EAChC6B,MAAMf;AACR,CAAA,EAAA;AAAI;AAKG,IAAMgB,yBAAyBzC,EAAEE,OAAO;EAC7CwC,WAAW1C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUhB,WAAAA,CAAAA,CAAAA,CAAAA;EAClDiB,UAAU5C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUR,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAKO,IAAMU,kBAAkB;EAAClB;EAAaQ;;",
6
+ "names": ["RawObject", "S", "TypedObject", "SubscriptionTriggerSchema", "S", "mutable", "struct", "type", "literal", "filter", "array", "string", "props", "optional", "record", "any", "options", "deep", "boolean", "delay", "number", "TimerTriggerSchema", "cron", "WebhookTriggerSchema", "method", "port", "WebsocketTriggerSchema", "url", "init", "TriggerSpecSchema", "union", "FunctionDef", "TypedObject", "typename", "version", "uri", "description", "route", "handler", "FunctionTrigger", "enabled", "function", "pipe", "meta", "spec", "FunctionManifestSchema", "functions", "RawObject", "triggers", "FUNCTION_SCHEMA"]
7
7
  }