@dxos/functions 0.8.2-main.2f9c567 → 0.8.2-main.36232bc

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 (168) hide show
  1. package/dist/lib/browser/bundler/index.mjs +3 -0
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/chunk-2YE6S7XY.mjs +360 -0
  4. package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-7CHDHCV3.mjs +482 -0
  6. package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-LT4LR4VU.mjs +72 -0
  8. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
  10. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +7 -0
  11. package/dist/lib/browser/edge/index.mjs +7 -63
  12. package/dist/lib/browser/edge/index.mjs.map +4 -4
  13. package/dist/lib/browser/index.mjs +99 -367
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/testing/index.mjs +670 -0
  17. package/dist/lib/browser/testing/index.mjs.map +7 -0
  18. package/dist/lib/browser/types/index.mjs +51 -0
  19. package/dist/lib/browser/types/index.mjs.map +7 -0
  20. package/dist/lib/node/bundler/index.cjs +1 -0
  21. package/dist/lib/node/bundler/index.cjs.map +1 -1
  22. package/dist/lib/node/chunk-FBIUZ7SD.cjs +496 -0
  23. package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +7 -0
  24. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
  25. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
  26. package/dist/lib/node/chunk-NXZNXVT3.cjs +94 -0
  27. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
  28. package/dist/lib/node/chunk-SV5NRE5L.cjs +395 -0
  29. package/dist/lib/node/chunk-SV5NRE5L.cjs.map +7 -0
  30. package/dist/lib/node/edge/index.cjs +5 -65
  31. package/dist/lib/node/edge/index.cjs.map +4 -4
  32. package/dist/lib/node/index.cjs +94 -382
  33. package/dist/lib/node/index.cjs.map +4 -4
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/testing/index.cjs +687 -0
  36. package/dist/lib/node/testing/index.cjs.map +7 -0
  37. package/dist/lib/node/types/index.cjs +72 -0
  38. package/dist/lib/node/types/index.cjs.map +7 -0
  39. package/dist/lib/node-esm/bundler/index.mjs +1 -0
  40. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  41. package/dist/lib/node-esm/chunk-3XMJFSID.mjs +360 -0
  42. package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-C6YINTWG.mjs +482 -0
  44. package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
  46. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +72 -0
  48. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
  49. package/dist/lib/node-esm/edge/index.mjs +6 -64
  50. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  51. package/dist/lib/node-esm/index.mjs +97 -367
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/meta.json +1 -1
  54. package/dist/lib/node-esm/testing/index.mjs +670 -0
  55. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  56. package/dist/lib/node-esm/types/index.mjs +51 -0
  57. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  58. package/dist/types/src/browser/index.d.ts +2 -0
  59. package/dist/types/src/browser/index.d.ts.map +1 -0
  60. package/dist/types/src/edge/index.d.ts.map +1 -1
  61. package/dist/types/src/function/function-registry.d.ts +25 -0
  62. package/dist/types/src/function/function-registry.d.ts.map +1 -0
  63. package/dist/types/src/function/function-registry.test.d.ts +2 -0
  64. package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
  65. package/dist/types/src/function/index.d.ts +2 -0
  66. package/dist/types/src/function/index.d.ts.map +1 -0
  67. package/dist/types/src/handler.d.ts +61 -12
  68. package/dist/types/src/handler.d.ts.map +1 -1
  69. package/dist/types/src/index.d.ts +3 -3
  70. package/dist/types/src/index.d.ts.map +1 -1
  71. package/dist/types/src/runtime/dev-server.d.ts +52 -0
  72. package/dist/types/src/runtime/dev-server.d.ts.map +1 -0
  73. package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
  74. package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
  75. package/dist/types/src/runtime/index.d.ts +3 -0
  76. package/dist/types/src/runtime/index.d.ts.map +1 -0
  77. package/dist/types/src/runtime/scheduler.d.ts +34 -0
  78. package/dist/types/src/runtime/scheduler.d.ts.map +1 -0
  79. package/dist/types/src/runtime/scheduler.test.d.ts +2 -0
  80. package/dist/types/src/runtime/scheduler.test.d.ts.map +1 -0
  81. package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
  82. package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
  83. package/dist/types/src/testing/index.d.ts +5 -0
  84. package/dist/types/src/testing/index.d.ts.map +1 -0
  85. package/dist/types/src/testing/manifest.d.ts +3 -0
  86. package/dist/types/src/testing/manifest.d.ts.map +1 -0
  87. package/dist/types/src/testing/plugin-init.d.ts +6 -0
  88. package/dist/types/src/testing/plugin-init.d.ts.map +1 -0
  89. package/dist/types/src/testing/setup.d.ts +15 -0
  90. package/dist/types/src/testing/setup.d.ts.map +1 -0
  91. package/dist/types/src/testing/test/handler.d.ts +4 -0
  92. package/dist/types/src/testing/test/handler.d.ts.map +1 -0
  93. package/dist/types/src/testing/test/index.d.ts +3 -0
  94. package/dist/types/src/testing/test/index.d.ts.map +1 -0
  95. package/dist/types/src/testing/types.d.ts +10 -0
  96. package/dist/types/src/testing/types.d.ts.map +1 -0
  97. package/dist/types/src/testing/util.d.ts +5 -0
  98. package/dist/types/src/testing/util.d.ts.map +1 -0
  99. package/dist/types/src/trigger/index.d.ts +3 -0
  100. package/dist/types/src/trigger/index.d.ts.map +1 -0
  101. package/dist/types/src/trigger/trigger-registry.d.ts +38 -0
  102. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
  103. package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
  104. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
  105. package/dist/types/src/trigger/type/index.d.ts +3 -0
  106. package/dist/types/src/trigger/type/index.d.ts.map +1 -0
  107. package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
  108. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
  109. package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
  110. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
  111. package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
  112. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
  113. package/dist/types/src/types/index.d.ts +5 -0
  114. package/dist/types/src/types/index.d.ts.map +1 -0
  115. package/dist/types/src/types/schema.d.ts +53 -0
  116. package/dist/types/src/types/schema.d.ts.map +1 -0
  117. package/dist/types/src/types/trace.d.ts +146 -0
  118. package/dist/types/src/types/trace.d.ts.map +1 -0
  119. package/dist/types/src/{types.d.ts → types/types.d.ts} +49 -191
  120. package/dist/types/src/types/types.d.ts.map +1 -0
  121. package/dist/types/src/types/url.d.ts.map +1 -0
  122. package/dist/types/tools/schema.d.ts +2 -0
  123. package/dist/types/tools/schema.d.ts.map +1 -0
  124. package/package.json +36 -20
  125. package/schema/functions.json +211 -0
  126. package/src/browser/index.ts +5 -0
  127. package/src/edge/index.ts +0 -4
  128. package/src/function/function-registry.test.ts +118 -0
  129. package/src/function/function-registry.ts +104 -0
  130. package/src/function/index.ts +5 -0
  131. package/src/handler.ts +118 -14
  132. package/src/index.ts +5 -4
  133. package/src/runtime/dev-server.test.ts +79 -0
  134. package/src/runtime/dev-server.ts +240 -0
  135. package/src/runtime/index.ts +6 -0
  136. package/src/runtime/scheduler.test.ts +152 -0
  137. package/src/runtime/scheduler.ts +170 -0
  138. package/src/testing/functions-integration.test.ts +65 -0
  139. package/src/testing/index.ts +8 -0
  140. package/src/testing/manifest.ts +15 -0
  141. package/src/testing/plugin-init.ts +20 -0
  142. package/src/testing/setup.ts +109 -0
  143. package/src/testing/test/handler.ts +15 -0
  144. package/src/testing/test/index.ts +7 -0
  145. package/src/testing/types.ts +9 -0
  146. package/src/testing/util.ts +26 -0
  147. package/src/translations.ts +1 -1
  148. package/src/trigger/index.ts +6 -0
  149. package/src/trigger/trigger-registry.test.ts +278 -0
  150. package/src/trigger/trigger-registry.ts +218 -0
  151. package/src/trigger/type/index.ts +7 -0
  152. package/src/trigger/type/subscription-trigger.ts +84 -0
  153. package/src/trigger/type/timer-trigger.ts +48 -0
  154. package/src/trigger/type/webhook-trigger.ts +48 -0
  155. package/src/types/index.ts +8 -0
  156. package/src/types/schema.ts +46 -0
  157. package/src/{trace.ts → types/trace.ts} +31 -33
  158. package/src/types/types.ts +163 -0
  159. package/dist/types/src/schema.d.ts +0 -57
  160. package/dist/types/src/schema.d.ts.map +0 -1
  161. package/dist/types/src/trace.d.ts +0 -148
  162. package/dist/types/src/trace.d.ts.map +0 -1
  163. package/dist/types/src/types.d.ts.map +0 -1
  164. package/dist/types/src/url.d.ts.map +0 -1
  165. package/src/schema.ts +0 -53
  166. package/src/types.ts +0 -214
  167. /package/dist/types/src/{url.d.ts → types/url.d.ts} +0 -0
  168. /package/src/{url.ts → types/url.ts} +0 -0
package/src/types.ts DELETED
@@ -1,214 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { Schema as S, SchemaAST } from 'effect';
6
-
7
- import { Expando, OptionsAnnotationId, TypedObject, DXN, Ref, RawObject } from '@dxos/echo-schema';
8
-
9
- import { FunctionType } from './schema';
10
-
11
- /**
12
- * Type discriminator for TriggerType.
13
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
14
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
15
- */
16
- export enum TriggerKind {
17
- Timer = 'timer',
18
- Webhook = 'webhook',
19
- Subscription = 'subscription',
20
- Email = 'email',
21
- Queue = 'queue',
22
- }
23
-
24
- // TODO(burdon): Rename prop kind.
25
- const typeLiteralAnnotations = { [SchemaAST.TitleAnnotationId]: 'Type' };
26
-
27
- /**
28
- * Cron timer.
29
- */
30
- const TimerTriggerSchema = S.Struct({
31
- type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),
32
- cron: S.String.annotations({
33
- [SchemaAST.TitleAnnotationId]: 'Cron',
34
- [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
35
- }),
36
- }).pipe(S.mutable);
37
-
38
- export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
39
-
40
- const EmailTriggerSchema = S.Struct({
41
- type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),
42
- }).pipe(S.mutable);
43
-
44
- export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
45
-
46
- const QueueTriggerSchema = S.Struct({
47
- type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),
48
- queue: DXN,
49
- }).pipe(S.mutable);
50
-
51
- export type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;
52
-
53
- /**
54
- * Webhook.
55
- */
56
- const WebhookTriggerSchema = S.Struct({
57
- type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),
58
- method: S.optional(
59
- S.String.annotations({
60
- [SchemaAST.TitleAnnotationId]: 'Method',
61
- [OptionsAnnotationId]: ['GET', 'POST'],
62
- }),
63
- ),
64
- port: S.optional(
65
- S.Number.annotations({
66
- [SchemaAST.TitleAnnotationId]: 'Port',
67
- }),
68
- ),
69
- }).pipe(S.mutable);
70
-
71
- export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
72
-
73
- // TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).
74
- const QuerySchema = S.Struct({
75
- type: S.optional(S.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Type' })),
76
- props: S.optional(S.Record({ key: S.String, value: S.Any })),
77
- }).annotations({ [SchemaAST.TitleAnnotationId]: 'Query' });
78
-
79
- /**
80
- * Subscription.
81
- */
82
- const SubscriptionTriggerSchema = S.Struct({
83
- type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),
84
- // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
85
- filter: QuerySchema,
86
- options: S.optional(
87
- S.Struct({
88
- // Watch changes to object (not just creation).
89
- deep: S.optional(S.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Nested' })),
90
- // Debounce changes (delay in ms).
91
- delay: S.optional(S.Number.annotations({ [SchemaAST.TitleAnnotationId]: 'Delay' })),
92
- }).annotations({ [SchemaAST.TitleAnnotationId]: 'Options' }),
93
- ),
94
- }).pipe(S.mutable);
95
-
96
- export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
97
-
98
- /**
99
- * Trigger schema (discriminated union).
100
- */
101
- export const TriggerSchema = S.Union(
102
- TimerTriggerSchema,
103
- WebhookTriggerSchema,
104
- SubscriptionTriggerSchema,
105
- EmailTriggerSchema,
106
- QueueTriggerSchema,
107
- ).annotations({
108
- [SchemaAST.TitleAnnotationId]: 'Trigger',
109
- });
110
- export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
111
-
112
- export type EventType =
113
- | EmailTriggerOutput
114
- | WebhookTriggerOutput
115
- | QueueTriggerOutput
116
- | SubscriptionTriggerOutput
117
- | TimerTriggerOutput;
118
-
119
- // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
120
- export const EmailTriggerOutput = S.mutable(
121
- S.Struct({
122
- from: S.String,
123
- to: S.String,
124
- subject: S.String,
125
- created: S.String,
126
- body: S.String,
127
- }),
128
- );
129
- export type EmailTriggerOutput = S.Schema.Type<typeof EmailTriggerOutput>;
130
-
131
- export const WebhookTriggerOutput = S.mutable(
132
- S.Struct({
133
- url: S.String,
134
- method: S.Literal('GET', 'POST'),
135
- headers: S.Record({ key: S.String, value: S.String }),
136
- bodyText: S.String,
137
- }),
138
- );
139
- export type WebhookTriggerOutput = S.Schema.Type<typeof WebhookTriggerOutput>;
140
-
141
- export const QueueTriggerOutput = S.mutable(
142
- S.Struct({
143
- queue: DXN,
144
- item: S.Any,
145
- cursor: S.String,
146
- }),
147
- );
148
- export type QueueTriggerOutput = S.Schema.Type<typeof QueueTriggerOutput>;
149
-
150
- export const SubscriptionTriggerOutput = S.mutable(S.Struct({ type: S.String, changedObjectId: S.String }));
151
- export type SubscriptionTriggerOutput = S.Schema.Type<typeof SubscriptionTriggerOutput>;
152
-
153
- export const TimerTriggerOutput = S.mutable(S.Struct({ tick: S.Number }));
154
- export type TimerTriggerOutput = S.Schema.Type<typeof TimerTriggerOutput>;
155
-
156
- /**
157
- * Function trigger.
158
- * Function is invoked with the `payload` passed as input data.
159
- * The event that triggers the function is available in the function context.
160
- */
161
- export const FunctionTriggerSchema = S.Struct({
162
- /**
163
- * Function or workflow to invoke.
164
- */
165
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
166
- function: S.optional(Ref(Expando).annotations({ [SchemaAST.TitleAnnotationId]: 'Function' })),
167
-
168
- /**
169
- * Only used for workflows.
170
- * Specifies the input node in the circuit.
171
- * @deprecated Remove and enforce a single input node in all compute graphs.
172
- */
173
- inputNodeId: S.optional(S.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Input Node ID' })),
174
-
175
- enabled: S.optional(S.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Enabled' })),
176
-
177
- spec: S.optional(TriggerSchema),
178
-
179
- /**
180
- * Passed as the input data to the function.
181
- * Must match the function's input schema.
182
- *
183
- * @example
184
- * {
185
- * item: '{{$.trigger.event}}',
186
- * instructions: 'Summarize and perform entity-extraction'
187
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
188
- * }
189
- */
190
- input: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),
191
- });
192
-
193
- export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
194
-
195
- /**
196
- * Function trigger.
197
- */
198
- export class FunctionTrigger extends TypedObject({
199
- typename: 'dxos.org/type/FunctionTrigger',
200
- version: '0.1.0',
201
- })(FunctionTriggerSchema.fields) {}
202
-
203
- // TODO(wittjosiah): Remove?
204
-
205
- /**
206
- * Function manifest file.
207
- */
208
- export const FunctionManifestSchema = S.Struct({
209
- functions: S.optional(S.mutable(S.Array(RawObject(FunctionType)))),
210
- triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),
211
- });
212
- export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
213
-
214
- export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
File without changes
File without changes