@dxos/functions 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea

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 (142) hide show
  1. package/dist/lib/browser/bundler/index.mjs +16 -25
  2. package/dist/lib/browser/bundler/index.mjs.map +3 -3
  3. package/dist/lib/browser/chunk-M6EXIREF.mjs +610 -0
  4. package/dist/lib/browser/chunk-M6EXIREF.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +957 -977
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +8 -6
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/node-esm/bundler/index.mjs +16 -25
  11. package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +612 -0
  13. package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +7 -0
  14. package/dist/lib/node-esm/index.mjs +957 -977
  15. package/dist/lib/node-esm/index.mjs.map +4 -4
  16. package/dist/lib/node-esm/meta.json +1 -1
  17. package/dist/lib/node-esm/testing/index.mjs +8 -6
  18. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  19. package/dist/types/src/bundler/bundler.d.ts.map +1 -1
  20. package/dist/types/src/e2e/deploy.test.d.ts +2 -0
  21. package/dist/types/src/e2e/deploy.test.d.ts.map +1 -0
  22. package/dist/types/src/example/fib.d.ts.map +1 -0
  23. package/dist/types/src/example/forex-effect.d.ts +3 -0
  24. package/dist/types/src/example/forex-effect.d.ts.map +1 -0
  25. package/dist/types/src/example/index.d.ts +12 -0
  26. package/dist/types/src/example/index.d.ts.map +1 -0
  27. package/dist/types/src/example/reply.d.ts.map +1 -0
  28. package/dist/types/src/example/sleep.d.ts.map +1 -0
  29. package/dist/types/src/executor/executor.d.ts.map +1 -1
  30. package/dist/types/src/handler.d.ts +20 -24
  31. package/dist/types/src/handler.d.ts.map +1 -1
  32. package/dist/types/src/index.d.ts +4 -5
  33. package/dist/types/src/index.d.ts.map +1 -1
  34. package/dist/types/src/services/credentials.d.ts +6 -2
  35. package/dist/types/src/services/credentials.d.ts.map +1 -1
  36. package/dist/types/src/services/database.d.ts +6 -2
  37. package/dist/types/src/services/database.d.ts.map +1 -1
  38. package/dist/types/src/services/event-logger.d.ts +4 -1
  39. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  40. package/dist/types/src/services/function-invocation-service.d.ts +5 -3
  41. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  42. package/dist/types/src/services/local-function-execution.d.ts +5 -3
  43. package/dist/types/src/services/local-function-execution.d.ts.map +1 -1
  44. package/dist/types/src/services/queues.d.ts +3 -1
  45. package/dist/types/src/services/queues.d.ts.map +1 -1
  46. package/dist/types/src/services/remote-function-execution-service.d.ts +3 -1
  47. package/dist/types/src/services/remote-function-execution-service.d.ts.map +1 -1
  48. package/dist/types/src/services/service-container.d.ts +2 -1
  49. package/dist/types/src/services/service-container.d.ts.map +1 -1
  50. package/dist/types/src/services/service-registry.d.ts +3 -1
  51. package/dist/types/src/services/service-registry.d.ts.map +1 -1
  52. package/dist/types/src/services/tracing.d.ts +4 -2
  53. package/dist/types/src/services/tracing.d.ts.map +1 -1
  54. package/dist/types/src/testing/layer.d.ts +3 -2
  55. package/dist/types/src/testing/layer.d.ts.map +1 -1
  56. package/dist/types/src/testing/logger.d.ts +1 -1
  57. package/dist/types/src/testing/logger.d.ts.map +1 -1
  58. package/dist/types/src/testing/services.d.ts +1 -1
  59. package/dist/types/src/testing/services.d.ts.map +1 -1
  60. package/dist/types/src/trace.d.ts +4 -4
  61. package/dist/types/src/trace.d.ts.map +1 -1
  62. package/dist/types/src/translations.d.ts +2 -2
  63. package/dist/types/src/translations.d.ts.map +1 -1
  64. package/dist/types/src/triggers/input-builder.d.ts +2 -2
  65. package/dist/types/src/triggers/input-builder.d.ts.map +1 -1
  66. package/dist/types/src/triggers/invocation-tracer.d.ts +5 -3
  67. package/dist/types/src/triggers/invocation-tracer.d.ts.map +1 -1
  68. package/dist/types/src/triggers/trigger-dispatcher.d.ts +10 -6
  69. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +1 -1
  70. package/dist/types/src/triggers/trigger-state-store.d.ts +5 -4
  71. package/dist/types/src/triggers/trigger-state-store.d.ts.map +1 -1
  72. package/dist/types/src/types/Function.d.ts +47 -0
  73. package/dist/types/src/types/Function.d.ts.map +1 -0
  74. package/dist/types/src/types/Script.d.ts +28 -0
  75. package/dist/types/src/types/Script.d.ts.map +1 -0
  76. package/dist/types/src/types/Trigger.d.ts +139 -0
  77. package/dist/types/src/types/Trigger.d.ts.map +1 -0
  78. package/dist/types/src/types/TriggerEvent.d.ts +44 -0
  79. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
  80. package/dist/types/src/types/index.d.ts +5 -0
  81. package/dist/types/src/types/index.d.ts.map +1 -0
  82. package/dist/types/src/url.d.ts +1 -1
  83. package/dist/types/src/url.d.ts.map +1 -1
  84. package/dist/types/tsconfig.tsbuildinfo +1 -1
  85. package/package.json +24 -36
  86. package/src/bundler/bundler.ts +7 -3
  87. package/src/e2e/deploy.test.ts +69 -0
  88. package/src/{examples → example}/fib.ts +2 -1
  89. package/src/example/forex-effect.ts +40 -0
  90. package/src/example/index.ts +13 -0
  91. package/src/{examples → example}/reply.ts +3 -1
  92. package/src/{examples → example}/sleep.ts +2 -1
  93. package/src/executor/executor.ts +2 -1
  94. package/src/handler.ts +23 -19
  95. package/src/index.ts +4 -5
  96. package/src/services/credentials.ts +7 -2
  97. package/src/services/database.ts +6 -2
  98. package/src/services/event-logger.ts +4 -1
  99. package/src/services/function-invocation-service.test.ts +3 -1
  100. package/src/services/function-invocation-service.ts +5 -3
  101. package/src/services/local-function-execution.ts +10 -7
  102. package/src/services/queues.ts +3 -1
  103. package/src/services/remote-function-execution-service.ts +3 -1
  104. package/src/services/service-container.ts +2 -1
  105. package/src/services/service-registry.test.ts +4 -1
  106. package/src/services/service-registry.ts +7 -3
  107. package/src/services/tracing.ts +4 -2
  108. package/src/testing/layer.ts +6 -4
  109. package/src/testing/logger.ts +2 -1
  110. package/src/testing/persist-database.test.ts +1 -1
  111. package/src/testing/services.ts +1 -1
  112. package/src/trace.ts +5 -5
  113. package/src/translations.ts +2 -2
  114. package/src/triggers/input-builder.ts +2 -2
  115. package/src/triggers/invocation-tracer.ts +5 -3
  116. package/src/triggers/trigger-dispatcher.test.ts +57 -44
  117. package/src/triggers/trigger-dispatcher.ts +26 -27
  118. package/src/triggers/trigger-state-store.ts +6 -5
  119. package/src/{schema.ts → types/Function.ts} +9 -26
  120. package/src/types/Script.ts +33 -0
  121. package/src/types/Trigger.ts +139 -0
  122. package/src/types/TriggerEvent.ts +62 -0
  123. package/src/types/index.ts +8 -0
  124. package/src/url.ts +1 -1
  125. package/dist/lib/browser/chunk-C2Z7LCJ2.mjs +0 -649
  126. package/dist/lib/browser/chunk-C2Z7LCJ2.mjs.map +0 -7
  127. package/dist/lib/node-esm/chunk-AH3AZM2U.mjs +0 -651
  128. package/dist/lib/node-esm/chunk-AH3AZM2U.mjs.map +0 -7
  129. package/dist/types/src/examples/fib.d.ts.map +0 -1
  130. package/dist/types/src/examples/index.d.ts +0 -4
  131. package/dist/types/src/examples/index.d.ts.map +0 -1
  132. package/dist/types/src/examples/reply.d.ts.map +0 -1
  133. package/dist/types/src/examples/sleep.d.ts.map +0 -1
  134. package/dist/types/src/schema.d.ts +0 -43
  135. package/dist/types/src/schema.d.ts.map +0 -1
  136. package/dist/types/src/types.d.ts +0 -221
  137. package/dist/types/src/types.d.ts.map +0 -1
  138. package/src/examples/index.ts +0 -7
  139. package/src/types.ts +0 -214
  140. /package/dist/types/src/{examples → example}/fib.d.ts +0 -0
  141. /package/dist/types/src/{examples → example}/reply.d.ts +0 -0
  142. /package/dist/types/src/{examples → example}/sleep.d.ts +0 -0
@@ -2,36 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { Type } from '@dxos/echo';
8
- import { JsonSchemaType, LabelAnnotation, Ref } from '@dxos/echo-schema';
9
- import { DataType } from '@dxos/schema';
7
+ import { Obj, Type } from '@dxos/echo';
8
+ import { JsonSchemaType, LabelAnnotation, Ref } from '@dxos/echo/internal';
10
9
 
11
- /**
12
- * Source script.
13
- */
14
- export const ScriptType = Schema.Struct({
15
- name: Schema.optional(Schema.String),
16
- description: Schema.optional(Schema.String),
17
- // TODO(burdon): Change to hash of deployed content.
18
- // Whether source has changed since last deploy.
19
- changed: Schema.optional(Schema.Boolean),
20
- source: Ref(DataType.Text),
21
- }).pipe(
22
- Type.Obj({
23
- typename: 'dxos.org/type/Script',
24
- version: '0.1.0',
25
- }),
26
- LabelAnnotation.set(['name']),
27
- );
28
-
29
- export interface ScriptType extends Schema.Schema.Type<typeof ScriptType> {}
10
+ import { Script } from './Script';
30
11
 
31
12
  /**
32
13
  * Function deployment.
33
14
  */
34
- export const FunctionType = Schema.Struct({
15
+ export const Function = Schema.Struct({
35
16
  /**
36
17
  * Global registry ID.
37
18
  * NOTE: The `key` property refers to the original registry entry.
@@ -51,7 +32,7 @@ export const FunctionType = Schema.Struct({
51
32
 
52
33
  // Reference to a source script if it exists within ECHO.
53
34
  // TODO(burdon): Don't ref ScriptType directly (core).
54
- source: Schema.optional(Ref(ScriptType)),
35
+ source: Schema.optional(Ref(Script)),
55
36
 
56
37
  inputSchema: Schema.optional(JsonSchemaType),
57
38
  outputSchema: Schema.optional(JsonSchemaType),
@@ -65,4 +46,6 @@ export const FunctionType = Schema.Struct({
65
46
  }),
66
47
  LabelAnnotation.set(['name']),
67
48
  );
68
- export interface FunctionType extends Schema.Schema.Type<typeof FunctionType> {}
49
+ export interface Function extends Schema.Schema.Type<typeof Function> {}
50
+
51
+ export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Obj, Ref, Type } from '@dxos/echo';
8
+ import { FormAnnotation, LabelAnnotation } from '@dxos/echo/internal';
9
+ import { DataType } from '@dxos/schema';
10
+
11
+ /**
12
+ * Source script.
13
+ */
14
+ export const Script = Schema.Struct({
15
+ name: Schema.String.pipe(Schema.optional),
16
+ description: Schema.String.pipe(Schema.optional),
17
+ // TODO(burdon): Change to hash of deployed content.
18
+ // Whether source has changed since last deploy.
19
+ changed: Schema.Boolean.pipe(FormAnnotation.set(false), Schema.optional),
20
+ source: Type.Ref(DataType.Text).pipe(FormAnnotation.set(false)),
21
+ }).pipe(
22
+ Type.Obj({
23
+ typename: 'dxos.org/type/Script',
24
+ version: '0.1.0',
25
+ }),
26
+ LabelAnnotation.set(['name']),
27
+ );
28
+ export interface Script extends Schema.Schema.Type<typeof Script> {}
29
+
30
+ type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
31
+
32
+ export const make = ({ source = '', ...props }: Props = {}) =>
33
+ Obj.make(Script, { ...props, source: Ref.make(DataType.makeText(source)) });
@@ -0,0 +1,139 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+
8
+ import { Obj, QueryAST, Type } from '@dxos/echo';
9
+ import { Expando, OptionsAnnotationId, Ref } from '@dxos/echo/internal';
10
+ import { DXN } from '@dxos/keys';
11
+
12
+ /**
13
+ * Type discriminator for TriggerType.
14
+ * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
15
+ * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
16
+ */
17
+ export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
18
+ export type Kind = (typeof Kinds)[number];
19
+
20
+ const kindLiteralAnnotations = { title: 'Kind' };
21
+
22
+ export const EmailSpec = Schema.Struct({
23
+ kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
24
+ }).pipe(Schema.mutable);
25
+ export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
26
+
27
+ export const QueueSpec = Schema.Struct({
28
+ kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
29
+
30
+ // TODO(dmaretskyi): Change to a reference.
31
+ queue: DXN.Schema,
32
+ }).pipe(Schema.mutable);
33
+ export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
34
+
35
+ /**
36
+ * Subscription.
37
+ */
38
+ export const SubscriptionSpec = Schema.Struct({
39
+ kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
40
+ query: Schema.Struct({
41
+ raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
42
+ ast: QueryAST.Query,
43
+ }).pipe(Schema.mutable),
44
+ options: Schema.optional(
45
+ Schema.Struct({
46
+ // Watch changes to object (not just creation).
47
+ deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
48
+ // Debounce changes (delay in ms).
49
+ delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
50
+ }).annotations({ title: 'Options' }),
51
+ ),
52
+ }).pipe(Schema.mutable);
53
+ export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
54
+
55
+ /**
56
+ * Cron timer.
57
+ */
58
+ export const TimerSpec = Schema.Struct({
59
+ kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
60
+ cron: Schema.String.annotations({
61
+ title: 'Cron',
62
+ [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
63
+ }),
64
+ }).pipe(Schema.mutable);
65
+ export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
66
+
67
+ /**
68
+ * Webhook.
69
+ */
70
+ export const WebhookSpec = Schema.Struct({
71
+ kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
72
+ method: Schema.optional(
73
+ Schema.String.annotations({
74
+ title: 'Method',
75
+ [OptionsAnnotationId]: ['GET', 'POST'],
76
+ }),
77
+ ),
78
+ port: Schema.optional(
79
+ Schema.Number.annotations({
80
+ title: 'Port',
81
+ }),
82
+ ),
83
+ }).pipe(Schema.mutable);
84
+ export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
85
+
86
+ /**
87
+ * Trigger schema.
88
+ */
89
+ export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
90
+ title: 'Trigger',
91
+ });
92
+ export type Spec = Schema.Schema.Type<typeof Spec>;
93
+
94
+ /**
95
+ * Function trigger.
96
+ * Function is invoked with the `payload` passed as input data.
97
+ * The event that triggers the function is available in the function context.
98
+ */
99
+ const Trigger_ = Schema.Struct({
100
+ /**
101
+ * Function or workflow to invoke.
102
+ */
103
+ // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
104
+ function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
105
+
106
+ /**
107
+ * Only used for workflowSchema.
108
+ * Specifies the input node in the circuit.
109
+ * @deprecated Remove and enforce a single input node in all compute graphSchema.
110
+ */
111
+ inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
112
+
113
+ enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
114
+
115
+ spec: Schema.optional(Spec),
116
+
117
+ /**
118
+ * Passed as the input data to the function.
119
+ * Must match the function's input schema.
120
+ *
121
+ * @example
122
+ * {
123
+ * item: '{{$.trigger.event}}',
124
+ * instructions: 'Summarize and perform entity-extraction'
125
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
126
+ * }
127
+ */
128
+ input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
129
+ }).pipe(
130
+ Type.Obj({
131
+ typename: 'dxos.org/type/Trigger',
132
+ version: '0.1.0',
133
+ }),
134
+ );
135
+ export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {}
136
+ export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {}
137
+ export const Trigger: Schema.Schema<Trigger, TriggerEncoded> = Trigger_;
138
+
139
+ export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
@@ -0,0 +1,62 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { DXN, Obj, Type } from '@dxos/echo';
8
+
9
+ export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
10
+
11
+ // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
12
+ export const EmailEvent = Schema.mutable(
13
+ Schema.Struct({
14
+ from: Schema.String,
15
+ to: Schema.String,
16
+ subject: Schema.String,
17
+ created: Schema.String,
18
+ body: Schema.String,
19
+ }),
20
+ );
21
+ export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
22
+
23
+ export const QueueEvent = Schema.mutable(
24
+ Schema.Struct({
25
+ queue: DXN.Schema,
26
+ item: Schema.Any,
27
+ cursor: Schema.String,
28
+ }),
29
+ );
30
+ export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
31
+
32
+ export const SubscriptionEvent = Schema.Struct({
33
+ /**
34
+ * Type of the mutation.
35
+ */
36
+ // TODO(dmaretskyi): Specify enum.
37
+ type: Schema.String,
38
+
39
+ /**
40
+ * Reference to the object that was changed or created.
41
+ */
42
+ subject: Type.Ref(Obj.Any),
43
+
44
+ /**
45
+ * @deprecated
46
+ */
47
+ changedObjectId: Schema.optional(Schema.String),
48
+ }).pipe(Schema.mutable);
49
+ export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
50
+
51
+ export const TimerEvent = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
52
+ export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
53
+
54
+ export const WebhookEvent = Schema.mutable(
55
+ Schema.Struct({
56
+ url: Schema.String,
57
+ method: Schema.Literal('GET', 'POST'),
58
+ headers: Schema.Record({ key: Schema.String, value: Schema.String }),
59
+ bodyText: Schema.String,
60
+ }),
61
+ );
62
+ export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * as Function from './Function';
6
+ export * as Script from './Script';
7
+ export * as Trigger from './Trigger';
8
+ export * as TriggerEvent from './TriggerEvent';
package/src/url.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type ObjectMeta } from '@dxos/echo-schema';
5
+ import { type ObjectMeta } from '@dxos/echo/internal';
6
6
  import { type SpaceId } from '@dxos/keys';
7
7
 
8
8
  // TODO: use URL scheme for source?