@dxos/functions 0.5.3-main.f752aaa → 0.5.3-next.57eca40

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 (95) hide show
  1. package/dist/lib/browser/chunk-366QG6IX.mjs +81 -0
  2. package/dist/lib/browser/chunk-366QG6IX.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +825 -471
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types.mjs +12 -0
  7. package/dist/lib/browser/types.mjs.map +7 -0
  8. package/dist/lib/node/chunk-3VSJ57ZZ.cjs +97 -0
  9. package/dist/lib/node/chunk-3VSJ57ZZ.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +805 -461
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/types.cjs +33 -0
  14. package/dist/lib/node/types.cjs.map +7 -0
  15. package/dist/types/src/function/function-registry.d.ts +24 -0
  16. package/dist/types/src/function/function-registry.d.ts.map +1 -0
  17. package/dist/types/src/function/function-registry.test.d.ts +2 -0
  18. package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
  19. package/dist/types/src/function/index.d.ts +2 -0
  20. package/dist/types/src/function/index.d.ts.map +1 -0
  21. package/dist/types/src/handler.d.ts +33 -12
  22. package/dist/types/src/handler.d.ts.map +1 -1
  23. package/dist/types/src/index.d.ts +2 -0
  24. package/dist/types/src/index.d.ts.map +1 -1
  25. package/dist/types/src/runtime/dev-server.d.ts +16 -13
  26. package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
  27. package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
  28. package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
  29. package/dist/types/src/runtime/scheduler.d.ts +13 -27
  30. package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
  31. package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
  32. package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
  33. package/dist/types/src/testing/index.d.ts +4 -0
  34. package/dist/types/src/testing/index.d.ts.map +1 -0
  35. package/dist/types/src/testing/setup.d.ts +5 -0
  36. package/dist/types/src/testing/setup.d.ts.map +1 -0
  37. package/dist/types/src/testing/test/handler.d.ts +4 -0
  38. package/dist/types/src/testing/test/handler.d.ts.map +1 -0
  39. package/dist/types/src/testing/test/index.d.ts +3 -0
  40. package/dist/types/src/testing/test/index.d.ts.map +1 -0
  41. package/dist/types/src/testing/types.d.ts +9 -0
  42. package/dist/types/src/testing/types.d.ts.map +1 -0
  43. package/dist/types/src/testing/util.d.ts +3 -0
  44. package/dist/types/src/testing/util.d.ts.map +1 -0
  45. package/dist/types/src/trigger/index.d.ts +2 -0
  46. package/dist/types/src/trigger/index.d.ts.map +1 -0
  47. package/dist/types/src/trigger/trigger-registry.d.ts +40 -0
  48. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
  49. package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
  50. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
  51. package/dist/types/src/trigger/type/index.d.ts +5 -0
  52. package/dist/types/src/trigger/type/index.d.ts.map +1 -0
  53. package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
  54. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
  55. package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
  56. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
  57. package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
  58. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
  59. package/dist/types/src/trigger/type/websocket-trigger.d.ts +13 -0
  60. package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -0
  61. package/dist/types/src/types.d.ts +143 -101
  62. package/dist/types/src/types.d.ts.map +1 -1
  63. package/dist/types/src/util.d.ts +15 -0
  64. package/dist/types/src/util.d.ts.map +1 -0
  65. package/dist/types/src/util.test.d.ts +2 -0
  66. package/dist/types/src/util.test.d.ts.map +1 -0
  67. package/package.json +33 -15
  68. package/schema/functions.json +140 -104
  69. package/src/function/function-registry.test.ts +105 -0
  70. package/src/function/function-registry.ts +90 -0
  71. package/src/function/index.ts +5 -0
  72. package/src/handler.ts +54 -31
  73. package/src/index.ts +2 -0
  74. package/src/runtime/dev-server.test.ts +60 -0
  75. package/src/runtime/dev-server.ts +104 -53
  76. package/src/runtime/scheduler.test.ts +56 -73
  77. package/src/runtime/scheduler.ts +87 -271
  78. package/src/testing/functions-integration.test.ts +99 -0
  79. package/src/testing/index.ts +7 -0
  80. package/src/testing/setup.ts +45 -0
  81. package/src/testing/test/handler.ts +15 -0
  82. package/src/testing/test/index.ts +7 -0
  83. package/src/testing/types.ts +9 -0
  84. package/src/testing/util.ts +16 -0
  85. package/src/trigger/index.ts +5 -0
  86. package/src/trigger/trigger-registry.test.ts +255 -0
  87. package/src/trigger/trigger-registry.ts +189 -0
  88. package/src/trigger/type/index.ts +8 -0
  89. package/src/trigger/type/subscription-trigger.ts +80 -0
  90. package/src/trigger/type/timer-trigger.ts +44 -0
  91. package/src/trigger/type/webhook-trigger.ts +47 -0
  92. package/src/trigger/type/websocket-trigger.ts +91 -0
  93. package/src/types.ts +59 -32
  94. package/src/util.test.ts +43 -0
  95. package/src/util.ts +48 -0
@@ -1,41 +1,27 @@
1
- import { type Client } from '@dxos/client';
2
- import { type FunctionSubscriptionEvent } from '../handler';
1
+ import { type Space } from '@dxos/client/echo';
2
+ import { type FunctionRegistry } from '../function';
3
+ import { type TriggerRegistry } from '../trigger';
3
4
  import { type FunctionManifest } from '../types';
4
- type Callback = (data: FunctionSubscriptionEvent) => Promise<void>;
5
+ export type Callback = (data: any) => Promise<void | number>;
5
6
  export type SchedulerOptions = {
6
7
  endpoint?: string;
7
8
  callback?: Callback;
8
9
  };
9
10
  /**
10
- * The scheduler triggers function exectuion based on various triggers.
11
+ * The scheduler triggers function execution based on various triggers.
11
12
  */
12
13
  export declare class Scheduler {
13
- private readonly _client;
14
- private readonly _manifest;
14
+ readonly functions: FunctionRegistry;
15
+ readonly triggers: TriggerRegistry;
15
16
  private readonly _options;
16
- private readonly _mounts;
17
- constructor(_client: Client, _manifest: FunctionManifest, _options?: SchedulerOptions);
17
+ private _ctx;
18
+ private readonly _callMutex;
19
+ constructor(functions: FunctionRegistry, triggers: TriggerRegistry, _options?: SchedulerOptions);
18
20
  start(): Promise<void>;
19
21
  stop(): Promise<void>;
20
- private mount;
21
- private unmount;
22
+ register(space: Space, manifest: FunctionManifest): Promise<void>;
23
+ private _safeActivateTriggers;
24
+ private activate;
22
25
  private _execFunction;
23
- /**
24
- * Cron timer.
25
- */
26
- private _createTimer;
27
- /**
28
- * Webhook.
29
- */
30
- private _createWebhook;
31
- /**
32
- * Websocket.
33
- */
34
- private _createWebsocket;
35
- /**
36
- * ECHO subscription.
37
- */
38
- private _createSubscription;
39
26
  }
40
- export {};
41
27
  //# sourceMappingURL=scheduler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../../src/runtime/scheduler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,cAAc,CAAC;AAO3D,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAEL,KAAK,gBAAgB,EAMtB,MAAM,UAAU,CAAC;AAElB,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;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EAAE,QAAQ,EAAE,gBAAgB;YAKhD,qBAAqB;YAWrB,QAAQ;YAmBR,aAAa;CA2C5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=functions-integration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions-integration.test.d.ts","sourceRoot":"","sources":["../../../../src/testing/functions-integration.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from './setup';
2
+ export * from './types';
3
+ export * from './util';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Client, Config } from '@dxos/client';
2
+ import { type TestBuilder } from '@dxos/client/testing';
3
+ export declare const createInitializedClients: (testBuilder: TestBuilder, count?: number, config?: Config) => Promise<Client[]>;
4
+ export declare const createFunctionRuntime: (testBuilder: TestBuilder) => Promise<Client>;
5
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/testing/setup.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAQxD,eAAO,MAAM,wBAAwB,gBAAuB,WAAW,UAAS,MAAM,WAAe,MAAM,sBAW1G,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBAAuB,WAAW,KAAG,QAAQ,MAAM,CAiBpF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type FunctionHandler } from '../../handler';
2
+ export declare const setTestCallHandler: (handler: FunctionHandler<any>) => void;
3
+ export declare const handler: FunctionHandler<any>;
4
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../../src/testing/test/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD,eAAO,MAAM,kBAAkB,YAAa,gBAAgB,GAAG,CAAC,SAE/D,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,eAAe,CAAC,GAAG,CAExC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { handler } from './handler';
2
+ export default handler;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/testing/test/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,eAAe,OAAO,CAAC"}
@@ -0,0 +1,9 @@
1
+ declare const TestType_base: import("@dxos/echo-schema").EchoSchemaClass<{
2
+ title: string;
3
+ } & {
4
+ id: string;
5
+ }>;
6
+ export declare class TestType extends TestType_base {
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/testing/types.ts"],"names":[],"mappings":";;;;;AAMA,qBAAa,QAAS,SAAQ,aAE5B;CAAG"}
@@ -0,0 +1,3 @@
1
+ import { type Space } from '@dxos/client/echo';
2
+ export declare const triggerWebhook: (space: Space, uri: string) => Promise<void>;
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAKvD,eAAO,MAAM,cAAc,UAAiB,KAAK,OAAO,MAAM,kBAM7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './trigger-registry';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/trigger/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Event } from '@dxos/async';
2
+ import { type Client } from '@dxos/client';
3
+ import { type Space } from '@dxos/client/echo';
4
+ import { Context, Resource } from '@dxos/context';
5
+ import { type FunctionManifest, FunctionTrigger, type FunctionTriggerType, type TriggerSpec } from '../types';
6
+ type ResponseCode = number;
7
+ export type TriggerCallback = (args: object) => Promise<ResponseCode>;
8
+ export type TriggerContext = {
9
+ space: Space;
10
+ };
11
+ export type TriggerFactory<Spec extends TriggerSpec, Options = any> = (ctx: Context, context: TriggerContext, spec: Spec, callback: TriggerCallback, options?: Options) => Promise<void>;
12
+ export type TriggerHandlerMap = {
13
+ [type in FunctionTriggerType]: TriggerFactory<any>;
14
+ };
15
+ export type TriggerEvent = {
16
+ space: Space;
17
+ triggers: FunctionTrigger[];
18
+ };
19
+ export declare class TriggerRegistry extends Resource {
20
+ private readonly _client;
21
+ private readonly _options?;
22
+ private readonly _triggersBySpaceKey;
23
+ readonly registered: Event<TriggerEvent>;
24
+ readonly removed: Event<TriggerEvent>;
25
+ constructor(_client: Client, _options?: TriggerHandlerMap | undefined);
26
+ getActiveTriggers(space: Space): FunctionTrigger[];
27
+ getInactiveTriggers(space: Space): FunctionTrigger[];
28
+ activate(triggerCtx: TriggerContext, trigger: FunctionTrigger, callback: TriggerCallback): Promise<void>;
29
+ /**
30
+ * Loads triggers from the manifest into the space.
31
+ */
32
+ register(space: Space, manifest: FunctionManifest): Promise<void>;
33
+ protected _open(): Promise<void>;
34
+ protected _close(_: Context): Promise<void>;
35
+ private _handleNewTriggers;
36
+ private _handleRemovedTriggers;
37
+ private _getTriggers;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=trigger-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-registry.d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BAA6B;IACvD,SAAgB,OAAO,sBAA6B;gBAGjC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,+BAAmB;IAKxC,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,EAAE;IAIlD,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,EAAE;IAIrD,QAAQ,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB9G;;OAEG;IACU,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cA0BrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;cAyBtB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,OAAO,CAAC,kBAAkB;YAaZ,sBAAsB;IAqBpC,OAAO,CAAC,YAAY;CAIrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=trigger-registry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-registry.test.d.ts","sourceRoot":"","sources":["../../../../src/trigger/trigger-registry.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './subscription-trigger';
2
+ export * from './timer-trigger';
3
+ export * from './webhook-trigger';
4
+ export * from './websocket-trigger';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { SubscriptionTrigger } from '../../types';
2
+ import { type TriggerFactory } from '../trigger-registry';
3
+ export declare const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger>;
4
+ //# sourceMappingURL=subscription-trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-trigger.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/subscription-trigger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErG,eAAO,MAAM,yBAAyB,EAAE,cAAc,CAAC,mBAAmB,CAkEzE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { TimerTrigger } from '../../types';
2
+ import { type TriggerFactory } from '../trigger-registry';
3
+ export declare const createTimerTrigger: TriggerFactory<TimerTrigger>;
4
+ //# sourceMappingURL=timer-trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer-trigger.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/timer-trigger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErG,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,YAAY,CA8B3D,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { WebhookTrigger } from '../../types';
2
+ import { type TriggerFactory } from '../trigger-registry';
3
+ export declare const createWebhookTrigger: TriggerFactory<WebhookTrigger>;
4
+ //# sourceMappingURL=webhook-trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-trigger.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/webhook-trigger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErG,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAiC/D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type WebsocketTrigger } from '../../types';
2
+ import { type TriggerFactory } from '../trigger-registry';
3
+ interface WebsocketTriggerOptions {
4
+ retryDelay: number;
5
+ maxAttempts: number;
6
+ }
7
+ /**
8
+ * Websocket.
9
+ * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.
10
+ */
11
+ export declare const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketTriggerOptions>;
12
+ export {};
13
+ //# sourceMappingURL=websocket-trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-trigger.d.ts","sourceRoot":"","sources":["../../../../../src/trigger/type/websocket-trigger.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErG,UAAU,uBAAuB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,gBAAgB,EAAE,uBAAuB,CAoE5F,CAAC"}
@@ -1,20 +1,13 @@
1
- import * as S from '@effect/schema/Schema';
2
- declare const TimerTriggerSchema: S.struct<{
3
- cron: S.$string;
4
- }>;
5
- declare const WebhookTriggerSchema: S.struct<{
6
- port: S.$number;
7
- }>;
8
- declare const WebsocketTriggerSchema: S.struct<{
9
- url: S.$string;
10
- init: S.PropertySignature<"?:", {
11
- readonly [x: string]: any;
12
- } | undefined, never, "?:", {
13
- readonly [x: string]: any;
14
- } | undefined, never>;
15
- }>;
1
+ import { S } from '@dxos/echo-schema';
2
+ /**
3
+ * Type discriminator for TriggerSpec.
4
+ * Every spec has a type field of type FunctionTriggerType that we can use to understand which
5
+ * type we're working with.
6
+ * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
7
+ */
8
+ export type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';
16
9
  declare const SubscriptionTriggerSchema: S.struct<{
17
- spaceKey: S.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>;
10
+ type: S.literal<["subscription"]>;
18
11
  filter: S.array<S.struct<{
19
12
  type: S.$string;
20
13
  props: S.PropertySignature<"?:", {
@@ -31,129 +24,178 @@ declare const SubscriptionTriggerSchema: S.struct<{
31
24
  readonly delay?: number | undefined;
32
25
  } | undefined, never>;
33
26
  }>;
34
- declare const FunctionTriggerSchema: S.struct<{
35
- function: S.$string;
36
- timer: S.PropertySignature<"?:", {
37
- readonly cron: string;
38
- } | undefined, never, "?:", {
39
- readonly cron: string;
40
- } | undefined, never>;
41
- webhook: S.PropertySignature<"?:", {
42
- readonly port: number;
43
- } | undefined, never, "?:", {
44
- readonly port: number;
45
- } | undefined, never>;
46
- websocket: S.PropertySignature<"?:", {
47
- readonly url: string;
48
- readonly init?: {
49
- readonly [x: string]: any;
50
- } | undefined;
27
+ export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
28
+ declare const TimerTriggerSchema: S.struct<{
29
+ type: S.literal<["timer"]>;
30
+ cron: S.$string;
31
+ }>;
32
+ export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
33
+ declare const WebhookTriggerSchema: S.mutable<S.struct<{
34
+ type: S.literal<["webhook"]>;
35
+ method: S.$string;
36
+ port: S.PropertySignature<"?:", number | undefined, never, "?:", number | undefined, never>;
37
+ }>>;
38
+ export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
39
+ declare const WebsocketTriggerSchema: S.struct<{
40
+ type: S.literal<["websocket"]>;
41
+ url: S.$string;
42
+ init: S.PropertySignature<"?:", {
43
+ readonly [x: string]: any;
51
44
  } | undefined, never, "?:", {
52
- readonly url: string;
53
- readonly init?: {
54
- readonly [x: string]: any;
55
- } | undefined;
45
+ readonly [x: string]: any;
56
46
  } | undefined, never>;
57
- subscription: S.PropertySignature<"?:", {
47
+ }>;
48
+ export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
49
+ export type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;
50
+ declare const FunctionDef_base: import("@dxos/echo-schema").EchoSchemaClass<{
51
+ handler: string;
52
+ uri: string;
53
+ description?: string | undefined;
54
+ route: string;
55
+ } & {
56
+ id: string;
57
+ }>;
58
+ /**
59
+ * Function definition.
60
+ */
61
+ export declare class FunctionDef extends FunctionDef_base {
62
+ }
63
+ declare const FunctionTrigger_base: import("@dxos/echo-schema").EchoSchemaClass<{
64
+ function: string;
65
+ meta?: object | undefined;
66
+ spec: {
58
67
  readonly filter: readonly {
59
68
  readonly type: string;
60
69
  readonly props?: {
61
70
  readonly [x: string]: any;
62
71
  } | undefined;
63
72
  }[];
64
- readonly spaceKey?: string | undefined;
73
+ readonly type: "subscription";
65
74
  readonly options?: {
66
75
  readonly deep?: boolean | undefined;
67
76
  readonly delay?: number | undefined;
68
77
  } | undefined;
69
- } | undefined, never, "?:", {
70
- readonly filter: readonly {
71
- readonly type: string;
72
- readonly props?: {
73
- readonly [x: string]: any;
74
- } | undefined;
75
- }[];
76
- readonly spaceKey?: string | undefined;
77
- readonly options?: {
78
- readonly deep?: boolean | undefined;
79
- readonly delay?: number | undefined;
78
+ } | {
79
+ readonly type: "timer";
80
+ readonly cron: string;
81
+ } | {
82
+ port?: number | undefined;
83
+ type: "webhook";
84
+ method: string;
85
+ } | {
86
+ readonly type: "websocket";
87
+ readonly url: string;
88
+ readonly init?: {
89
+ readonly [x: string]: any;
80
90
  } | undefined;
81
- } | undefined, never>;
82
- }>;
83
- export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
84
- export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
85
- export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
86
- export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
87
- export type FunctionTrigger = S.Schema.Type<typeof FunctionTriggerSchema>;
88
- /**
89
- * Function definition.
90
- */
91
- declare const FunctionDefSchema: S.struct<{
92
- id: S.$string;
93
- description: S.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>;
94
- name: S.$string;
95
- handler: S.$string;
91
+ };
92
+ } & {
93
+ id: string;
96
94
  }>;
97
- export type FunctionDef = S.Schema.Type<typeof FunctionDefSchema>;
95
+ export declare class FunctionTrigger extends FunctionTrigger_base {
96
+ }
98
97
  /**
99
98
  * Function manifest file.
100
99
  */
101
100
  export declare const FunctionManifestSchema: S.struct<{
102
- functions: S.mutable<S.array<S.struct<{
103
- id: S.$string;
104
- description: S.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>;
105
- name: S.$string;
106
- handler: S.$string;
107
- }>>>;
108
- triggers: S.mutable<S.array<S.struct<{
109
- function: S.$string;
110
- timer: S.PropertySignature<"?:", {
111
- readonly cron: string;
112
- } | undefined, never, "?:", {
113
- readonly cron: string;
114
- } | undefined, never>;
115
- webhook: S.PropertySignature<"?:", {
116
- readonly port: number;
117
- } | undefined, never, "?:", {
118
- readonly port: number;
119
- } | undefined, never>;
120
- websocket: S.PropertySignature<"?:", {
121
- readonly url: string;
122
- readonly init?: {
123
- readonly [x: string]: any;
124
- } | undefined;
125
- } | undefined, never, "?:", {
126
- readonly url: string;
127
- readonly init?: {
128
- readonly [x: string]: any;
129
- } | undefined;
130
- } | undefined, never>;
131
- subscription: S.PropertySignature<"?:", {
101
+ functions: S.PropertySignature<"?:", ({
102
+ handler: string;
103
+ uri: string;
104
+ description?: string | undefined;
105
+ route: string;
106
+ } & {
107
+ "@meta"?: {
108
+ readonly keys: {
109
+ readonly id: string;
110
+ readonly source: string;
111
+ }[];
112
+ } | undefined;
113
+ })[] | undefined, never, "?:", ({
114
+ handler: string;
115
+ uri: string;
116
+ description?: string | undefined;
117
+ route: string;
118
+ } & {
119
+ "@meta"?: {
120
+ readonly keys: {
121
+ readonly id: string;
122
+ readonly source: string;
123
+ }[];
124
+ } | undefined;
125
+ })[] | undefined, never>;
126
+ triggers: S.PropertySignature<"?:", ({
127
+ function: string;
128
+ meta?: object | undefined;
129
+ spec: {
132
130
  readonly filter: readonly {
133
131
  readonly type: string;
134
132
  readonly props?: {
135
133
  readonly [x: string]: any;
136
134
  } | undefined;
137
135
  }[];
138
- readonly spaceKey?: string | undefined;
136
+ readonly type: "subscription";
139
137
  readonly options?: {
140
138
  readonly deep?: boolean | undefined;
141
139
  readonly delay?: number | undefined;
142
140
  } | undefined;
143
- } | undefined, never, "?:", {
141
+ } | {
142
+ readonly type: "timer";
143
+ readonly cron: string;
144
+ } | {
145
+ port?: number | undefined;
146
+ type: "webhook";
147
+ method: string;
148
+ } | {
149
+ readonly type: "websocket";
150
+ readonly url: string;
151
+ readonly init?: {
152
+ readonly [x: string]: any;
153
+ } | undefined;
154
+ };
155
+ } & {
156
+ "@meta"?: {
157
+ readonly keys: {
158
+ readonly id: string;
159
+ readonly source: string;
160
+ }[];
161
+ } | undefined;
162
+ })[] | undefined, never, "?:", ({
163
+ function: string;
164
+ meta?: object | undefined;
165
+ spec: {
144
166
  readonly filter: readonly {
145
167
  readonly type: string;
146
168
  readonly props?: {
147
169
  readonly [x: string]: any;
148
170
  } | undefined;
149
171
  }[];
150
- readonly spaceKey?: string | undefined;
172
+ readonly type: "subscription";
151
173
  readonly options?: {
152
174
  readonly deep?: boolean | undefined;
153
175
  readonly delay?: number | undefined;
154
176
  } | undefined;
155
- } | undefined, never>;
156
- }>>>;
177
+ } | {
178
+ readonly type: "timer";
179
+ readonly cron: string;
180
+ } | {
181
+ port?: number | undefined;
182
+ type: "webhook";
183
+ method: string;
184
+ } | {
185
+ readonly type: "websocket";
186
+ readonly url: string;
187
+ readonly init?: {
188
+ readonly [x: string]: any;
189
+ } | undefined;
190
+ };
191
+ } & {
192
+ "@meta"?: {
193
+ readonly keys: {
194
+ readonly id: string;
195
+ readonly source: string;
196
+ }[];
197
+ } | undefined;
198
+ })[] | undefined, never>;
157
199
  }>;
158
200
  export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
159
201
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAE3C,QAAA,MAAM,kBAAkB;;EAEtB,CAAC;AAEH,QAAA,MAAM,oBAAoB;;EAExB,CAAC;AAEH,QAAA,MAAM,sBAAsB;;;;;;;EAG1B,CAAC;AAEH,QAAA,MAAM,yBAAyB;;;;;;;;;;;;;;;;;EAiB7B,CAAC;AAEH,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOzB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAC5E,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E;;GAEG;AAEH,QAAA,MAAM,iBAAiB;;;;;EAMrB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type Comparator<A, B = A> = (a: A, b: B) => boolean;
2
+ export type DiffResult<A, B = A> = {
3
+ added: B[];
4
+ updated: A[];
5
+ removed: A[];
6
+ };
7
+ /**
8
+ *
9
+ * @param previous
10
+ * @param next
11
+ * @param comparator
12
+ */
13
+ export declare const diff: <A, B = A>(previous: readonly A[], next: readonly B[], comparator: Comparator<A, B>) => DiffResult<A, B>;
14
+ export declare const intersection: <A, B = A>(a: A[], b: B[], comparator: Comparator<A, B>) => A[];
15
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE3D,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI;IACjC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,IAAI,0GAwBhB,CAAC;AAGF,eAAO,MAAM,YAAY,iEACuC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=util.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.test.d.ts","sourceRoot":"","sources":["../../../src/util.test.ts"],"names":[],"mappings":""}