@dxos/functions 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe

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 (189) hide show
  1. package/dist/lib/browser/index.mjs +714 -1062
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +714 -1062
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/errors.d.ts +28 -36
  8. package/dist/types/src/errors.d.ts.map +1 -1
  9. package/dist/types/src/{examples → example}/fib.d.ts +1 -1
  10. package/dist/types/src/example/fib.d.ts.map +1 -0
  11. package/dist/types/src/example/forex-effect.d.ts +3 -0
  12. package/dist/types/src/example/forex-effect.d.ts.map +1 -0
  13. package/dist/types/src/example/index.d.ts +12 -0
  14. package/dist/types/src/example/index.d.ts.map +1 -0
  15. package/dist/types/src/{examples → example}/reply.d.ts +1 -1
  16. package/dist/types/src/example/reply.d.ts.map +1 -0
  17. package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
  18. package/dist/types/src/example/sleep.d.ts.map +1 -0
  19. package/dist/types/src/index.d.ts +4 -8
  20. package/dist/types/src/index.d.ts.map +1 -1
  21. package/dist/types/src/protocol/index.d.ts +2 -0
  22. package/dist/types/src/protocol/index.d.ts.map +1 -0
  23. package/dist/types/src/protocol/protocol.d.ts +7 -0
  24. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  25. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  26. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  27. package/dist/types/src/sdk.d.ts +89 -0
  28. package/dist/types/src/sdk.d.ts.map +1 -0
  29. package/dist/types/src/services/credentials.d.ts +7 -3
  30. package/dist/types/src/services/credentials.d.ts.map +1 -1
  31. package/dist/types/src/services/event-logger.d.ts +20 -5
  32. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  33. package/dist/types/src/services/function-invocation-service.d.ts +11 -0
  34. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  35. package/dist/types/src/services/index.d.ts +6 -6
  36. package/dist/types/src/services/index.d.ts.map +1 -1
  37. package/dist/types/src/services/queues.d.ts +3 -1
  38. package/dist/types/src/services/queues.d.ts.map +1 -1
  39. package/dist/types/src/services/tracing.d.ts +9 -12
  40. package/dist/types/src/services/tracing.d.ts.map +1 -1
  41. package/dist/types/src/types/Function.d.ts +58 -0
  42. package/dist/types/src/types/Function.d.ts.map +1 -0
  43. package/dist/types/src/types/Script.d.ts +28 -0
  44. package/dist/types/src/types/Script.d.ts.map +1 -0
  45. package/dist/types/src/types/Trigger.d.ts +139 -0
  46. package/dist/types/src/types/Trigger.d.ts.map +1 -0
  47. package/dist/types/src/types/TriggerEvent.d.ts +44 -0
  48. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
  49. package/dist/types/src/types/index.d.ts +6 -0
  50. package/dist/types/src/types/index.d.ts.map +1 -0
  51. package/dist/types/src/{url.d.ts → types/url.d.ts} +1 -10
  52. package/dist/types/src/types/url.d.ts.map +1 -0
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +16 -70
  55. package/src/{examples → example}/fib.ts +5 -3
  56. package/src/example/forex-effect.ts +40 -0
  57. package/src/example/index.ts +13 -0
  58. package/src/{examples → example}/reply.ts +6 -3
  59. package/src/{examples → example}/sleep.ts +5 -3
  60. package/src/index.ts +4 -8
  61. package/src/{executor → protocol}/index.ts +1 -1
  62. package/src/protocol/protocol.test.ts +59 -0
  63. package/src/protocol/protocol.ts +145 -0
  64. package/src/sdk.ts +226 -0
  65. package/src/services/credentials.ts +12 -6
  66. package/src/services/event-logger.ts +12 -3
  67. package/src/services/function-invocation-service.ts +23 -0
  68. package/src/services/index.ts +7 -6
  69. package/src/services/queues.ts +3 -1
  70. package/src/services/tracing.ts +24 -56
  71. package/src/{schema.ts → types/Function.ts} +20 -26
  72. package/src/types/Script.ts +33 -0
  73. package/src/types/Trigger.ts +139 -0
  74. package/src/types/TriggerEvent.ts +62 -0
  75. package/src/types/index.ts +9 -0
  76. package/src/types/url.ts +31 -0
  77. package/dist/lib/browser/bundler/index.mjs +0 -265
  78. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  79. package/dist/lib/browser/chunk-D2XO7XXY.mjs +0 -611
  80. package/dist/lib/browser/chunk-D2XO7XXY.mjs.map +0 -7
  81. package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
  82. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
  83. package/dist/lib/browser/edge/index.mjs +0 -83
  84. package/dist/lib/browser/edge/index.mjs.map +0 -7
  85. package/dist/lib/browser/testing/index.mjs +0 -129
  86. package/dist/lib/browser/testing/index.mjs.map +0 -7
  87. package/dist/lib/node-esm/bundler/index.mjs +0 -266
  88. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  89. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  90. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  91. package/dist/lib/node-esm/chunk-Z4CJ62WS.mjs +0 -613
  92. package/dist/lib/node-esm/chunk-Z4CJ62WS.mjs.map +0 -7
  93. package/dist/lib/node-esm/edge/index.mjs +0 -84
  94. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  95. package/dist/lib/node-esm/testing/index.mjs +0 -130
  96. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  97. package/dist/types/src/bundler/bundler.d.ts +0 -49
  98. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  99. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  100. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  101. package/dist/types/src/bundler/index.d.ts +0 -2
  102. package/dist/types/src/bundler/index.d.ts.map +0 -1
  103. package/dist/types/src/edge/functions.d.ts +0 -17
  104. package/dist/types/src/edge/functions.d.ts.map +0 -1
  105. package/dist/types/src/edge/index.d.ts +0 -2
  106. package/dist/types/src/edge/index.d.ts.map +0 -1
  107. package/dist/types/src/examples/fib.d.ts.map +0 -1
  108. package/dist/types/src/examples/index.d.ts +0 -4
  109. package/dist/types/src/examples/index.d.ts.map +0 -1
  110. package/dist/types/src/examples/reply.d.ts.map +0 -1
  111. package/dist/types/src/examples/sleep.d.ts.map +0 -1
  112. package/dist/types/src/executor/executor.d.ts +0 -11
  113. package/dist/types/src/executor/executor.d.ts.map +0 -1
  114. package/dist/types/src/executor/index.d.ts +0 -2
  115. package/dist/types/src/executor/index.d.ts.map +0 -1
  116. package/dist/types/src/handler.d.ts +0 -94
  117. package/dist/types/src/handler.d.ts.map +0 -1
  118. package/dist/types/src/schema.d.ts +0 -43
  119. package/dist/types/src/schema.d.ts.map +0 -1
  120. package/dist/types/src/services/database.d.ts +0 -63
  121. package/dist/types/src/services/database.d.ts.map +0 -1
  122. package/dist/types/src/services/local-function-execution.d.ts +0 -25
  123. package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
  124. package/dist/types/src/services/remote-function-execution-service.d.ts +0 -15
  125. package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
  126. package/dist/types/src/services/service-container.d.ts +0 -56
  127. package/dist/types/src/services/service-container.d.ts.map +0 -1
  128. package/dist/types/src/services/service-registry.d.ts +0 -29
  129. package/dist/types/src/services/service-registry.d.ts.map +0 -1
  130. package/dist/types/src/services/service-registry.test.d.ts +0 -2
  131. package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
  132. package/dist/types/src/testing/index.d.ts +0 -3
  133. package/dist/types/src/testing/index.d.ts.map +0 -1
  134. package/dist/types/src/testing/layer.d.ts +0 -15
  135. package/dist/types/src/testing/layer.d.ts.map +0 -1
  136. package/dist/types/src/testing/logger.d.ts +0 -5
  137. package/dist/types/src/testing/logger.d.ts.map +0 -1
  138. package/dist/types/src/testing/persist-database.test.d.ts +0 -2
  139. package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
  140. package/dist/types/src/testing/services.d.ts +0 -59
  141. package/dist/types/src/testing/services.d.ts.map +0 -1
  142. package/dist/types/src/trace.d.ts +0 -122
  143. package/dist/types/src/trace.d.ts.map +0 -1
  144. package/dist/types/src/translations.d.ts +0 -12
  145. package/dist/types/src/translations.d.ts.map +0 -1
  146. package/dist/types/src/triggers/index.d.ts +0 -4
  147. package/dist/types/src/triggers/index.d.ts.map +0 -1
  148. package/dist/types/src/triggers/input-builder.d.ts +0 -3
  149. package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
  150. package/dist/types/src/triggers/invocation-tracer.d.ts +0 -35
  151. package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
  152. package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -75
  153. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
  154. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
  155. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
  156. package/dist/types/src/triggers/trigger-state-store.d.ts +0 -27
  157. package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
  158. package/dist/types/src/types.d.ts +0 -211
  159. package/dist/types/src/types.d.ts.map +0 -1
  160. package/dist/types/src/url.d.ts.map +0 -1
  161. package/src/bundler/bundler.test.ts +0 -58
  162. package/src/bundler/bundler.ts +0 -291
  163. package/src/bundler/index.ts +0 -5
  164. package/src/edge/functions.ts +0 -67
  165. package/src/edge/index.ts +0 -9
  166. package/src/examples/index.ts +0 -7
  167. package/src/executor/executor.ts +0 -54
  168. package/src/handler.ts +0 -201
  169. package/src/services/database.ts +0 -171
  170. package/src/services/local-function-execution.ts +0 -114
  171. package/src/services/remote-function-execution-service.ts +0 -46
  172. package/src/services/service-container.ts +0 -114
  173. package/src/services/service-registry.test.ts +0 -42
  174. package/src/services/service-registry.ts +0 -59
  175. package/src/testing/index.ts +0 -6
  176. package/src/testing/layer.ts +0 -111
  177. package/src/testing/logger.ts +0 -16
  178. package/src/testing/persist-database.test.ts +0 -87
  179. package/src/testing/services.ts +0 -115
  180. package/src/trace.ts +0 -178
  181. package/src/translations.ts +0 -20
  182. package/src/triggers/index.ts +0 -7
  183. package/src/triggers/input-builder.ts +0 -35
  184. package/src/triggers/invocation-tracer.ts +0 -99
  185. package/src/triggers/trigger-dispatcher.test.ts +0 -652
  186. package/src/triggers/trigger-dispatcher.ts +0 -512
  187. package/src/triggers/trigger-state-store.ts +0 -60
  188. package/src/types.ts +0 -200
  189. package/src/url.ts +0 -55
package/src/types.ts DELETED
@@ -1,200 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { Schema, SchemaAST } from 'effect';
6
-
7
- import { QueryAST, Type } from '@dxos/echo';
8
- import { Expando, OptionsAnnotationId, RawObject, Ref } from '@dxos/echo-schema';
9
- import { DXN } from '@dxos/keys';
10
-
11
- import { FunctionType } from './schema';
12
-
13
- /**
14
- * Type discriminator for TriggerType.
15
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
16
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
17
- */
18
- export const TriggerKinds = ['timer', 'webhook', 'subscription', 'email', 'queue'] as const;
19
- export type TriggerKind = (typeof TriggerKinds)[number];
20
-
21
- const kindLiteralAnnotations = { title: 'Kind' };
22
-
23
- /**
24
- * Cron timer.
25
- */
26
- const TimerTriggerSchema = Schema.Struct({
27
- kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
28
- cron: Schema.String.annotations({
29
- title: 'Cron',
30
- [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
31
- }),
32
- }).pipe(Schema.mutable);
33
- export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
34
-
35
- const EmailTriggerSchema = Schema.Struct({
36
- kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
37
- }).pipe(Schema.mutable);
38
- export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
39
-
40
- const QueueTriggerSchema = Schema.Struct({
41
- kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
42
-
43
- // TODO(dmaretskyi): Change to a reference.
44
- queue: DXN.Schema,
45
- }).pipe(Schema.mutable);
46
- export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
47
-
48
- /**
49
- * Webhook.
50
- */
51
- const WebhookTriggerSchema = Schema.Struct({
52
- kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
53
- method: Schema.optional(
54
- Schema.String.annotations({
55
- title: 'Method',
56
- [OptionsAnnotationId]: ['GET', 'POST'],
57
- }),
58
- ),
59
- port: Schema.optional(
60
- Schema.Number.annotations({
61
- title: 'Port',
62
- }),
63
- ),
64
- }).pipe(Schema.mutable);
65
- export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
66
-
67
- /**
68
- * Subscription.
69
- */
70
- const SubscriptionTriggerSchema = Schema.Struct({
71
- kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
72
- query: QueryAST.Query.annotations({ title: 'Query' }),
73
- options: Schema.optional(
74
- Schema.Struct({
75
- // Watch changes to object (not just creation).
76
- deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
77
- // Debounce changes (delay in ms).
78
- delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
79
- }).annotations({ title: 'Options' }),
80
- ),
81
- }).pipe(Schema.mutable);
82
- export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
83
-
84
- /**
85
- * Trigger schema (discriminated union).
86
- */
87
- export const TriggerSchema = Schema.Union(
88
- TimerTriggerSchema,
89
- WebhookTriggerSchema,
90
- SubscriptionTriggerSchema,
91
- EmailTriggerSchema,
92
- QueueTriggerSchema,
93
- ).annotations({
94
- title: 'Trigger',
95
- });
96
- export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
97
-
98
- export type EventType =
99
- | EmailTriggerOutput
100
- | WebhookTriggerOutput
101
- | QueueTriggerOutput
102
- | SubscriptionTriggerOutput
103
- | TimerTriggerOutput;
104
-
105
- // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
106
- export const EmailTriggerOutput = Schema.mutable(
107
- Schema.Struct({
108
- from: Schema.String,
109
- to: Schema.String,
110
- subject: Schema.String,
111
- created: Schema.String,
112
- body: Schema.String,
113
- }),
114
- );
115
- export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
116
-
117
- export const WebhookTriggerOutput = Schema.mutable(
118
- Schema.Struct({
119
- url: Schema.String,
120
- method: Schema.Literal('GET', 'POST'),
121
- headers: Schema.Record({ key: Schema.String, value: Schema.String }),
122
- bodyText: Schema.String,
123
- }),
124
- );
125
- export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
126
-
127
- export const QueueTriggerOutput = Schema.mutable(
128
- Schema.Struct({
129
- queue: DXN.Schema,
130
- item: Schema.Any,
131
- cursor: Schema.String,
132
- }),
133
- );
134
- export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
135
-
136
- export const SubscriptionTriggerOutput = Schema.mutable(
137
- Schema.Struct({ type: Schema.String, changedObjectId: Schema.String }),
138
- );
139
- export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
140
-
141
- export const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
142
- export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
143
-
144
- /**
145
- * Function trigger.
146
- * Function is invoked with the `payload` passed as input data.
147
- * The event that triggers the function is available in the function context.
148
- */
149
- const FunctionTrigger_ = Schema.Struct({
150
- /**
151
- * Function or workflow to invoke.
152
- */
153
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
154
- function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
155
-
156
- /**
157
- * Only used for workflowSchema.
158
- * Specifies the input node in the circuit.
159
- * @deprecated Remove and enforce a single input node in all compute graphSchema.
160
- */
161
- inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
162
-
163
- enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
164
-
165
- spec: Schema.optional(TriggerSchema),
166
-
167
- /**
168
- * Passed as the input data to the function.
169
- * Must match the function's input schema.
170
- *
171
- * @example
172
- * {
173
- * item: '{{$.trigger.event}}',
174
- * instructions: 'Summarize and perform entity-extraction'
175
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
176
- * }
177
- */
178
- input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
179
- }).pipe(
180
- Type.Obj({
181
- typename: 'dxos.org/type/FunctionTrigger',
182
- version: '0.2.0',
183
- }),
184
- );
185
- export interface FunctionTrigger extends Schema.Schema.Type<typeof FunctionTrigger_> {}
186
- export interface FunctionTriggerEncoded extends Schema.Schema.Encoded<typeof FunctionTrigger_> {}
187
- export const FunctionTrigger: Schema.Schema<FunctionTrigger, FunctionTriggerEncoded> = FunctionTrigger_;
188
-
189
- // TODO(wittjosiah): Remove?
190
-
191
- /**
192
- * Function manifest file.
193
- */
194
- export const FunctionManifestSchema = Schema.Struct({
195
- functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),
196
- triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),
197
- });
198
- export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
199
-
200
- export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
package/src/url.ts DELETED
@@ -1,55 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type ObjectMeta } from '@dxos/echo-schema';
6
- import { type SpaceId } from '@dxos/keys';
7
-
8
- // TODO: use URL scheme for source?
9
- export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
10
-
11
- export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
12
-
13
- const isSecure = (protocol: string) => {
14
- return protocol === 'https:' || protocol === 'wss:';
15
- };
16
-
17
- /**
18
- * NOTE: functionId is backend ID, not ECHO object id.
19
- */
20
- export const getUserFunctionIdInMetadata = (meta: ObjectMeta) => {
21
- return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
22
- };
23
-
24
- /**
25
- * NOTE: functionId is backend ID, not ECHO object id.
26
- */
27
- export const setUserFunctionIdInMetadata = (meta: ObjectMeta, functionId: string) => {
28
- const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
29
- if (key) {
30
- if (key.id !== functionId) {
31
- throw new Error('Metadata mismatch');
32
- }
33
- } else {
34
- meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
35
- }
36
- };
37
-
38
- /**
39
- * NOTE: functionId is backend ID, not ECHO object id.
40
- */
41
- export const getInvocationUrl = (functionId: string, edgeUrl: string, options: InvocationOptions = {}) => {
42
- const baseUrl = new URL('functions/', edgeUrl);
43
-
44
- // Leading slashes cause the URL to be treated as an absolute path.
45
- const url = new URL(`./${functionId}`, baseUrl.toString());
46
- options.spaceId && url.searchParams.set('spaceId', options.spaceId);
47
- options.subjectId && url.searchParams.set('subjectId', options.subjectId);
48
- url.protocol = isSecure(url.protocol) ? 'https' : 'http';
49
- return url.toString();
50
- };
51
-
52
- export type InvocationOptions = {
53
- spaceId?: SpaceId;
54
- subjectId?: string;
55
- };