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

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 (181) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/index.mjs +475 -0
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/index.d.ts +3 -9
  6. package/dist/types/src/index.d.ts.map +1 -1
  7. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  8. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  9. package/dist/types/src/protocol/index.d.ts +2 -0
  10. package/dist/types/src/protocol/index.d.ts.map +1 -0
  11. package/dist/types/src/protocol/protocol.d.ts +7 -0
  12. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  13. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  14. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  15. package/dist/types/src/sdk.d.ts +10 -0
  16. package/dist/types/src/sdk.d.ts.map +1 -0
  17. package/dist/types/src/services/credentials.d.ts +22 -39
  18. package/dist/types/src/services/credentials.d.ts.map +1 -1
  19. package/dist/types/src/services/function-invocation-service.d.ts +9 -20
  20. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  21. package/dist/types/src/services/index.d.ts +1 -6
  22. package/dist/types/src/services/index.d.ts.map +1 -1
  23. package/dist/types/src/services/queues.d.ts +1 -44
  24. package/dist/types/src/services/queues.d.ts.map +1 -1
  25. package/dist/types/src/services/tracing.d.ts +2 -54
  26. package/dist/types/src/services/tracing.d.ts.map +1 -1
  27. package/dist/types/src/types/index.d.ts +2 -0
  28. package/dist/types/src/types/index.d.ts.map +1 -0
  29. package/dist/types/src/types/url.d.ts +13 -0
  30. package/dist/types/src/types/url.d.ts.map +1 -0
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +25 -72
  33. package/src/index.ts +3 -9
  34. package/src/protocol/functions-ai-http-client.ts +67 -0
  35. package/src/{executor → protocol}/index.ts +1 -1
  36. package/src/protocol/protocol.test.ts +58 -0
  37. package/src/protocol/protocol.ts +292 -0
  38. package/src/sdk.ts +29 -0
  39. package/src/services/credentials.ts +89 -112
  40. package/src/services/function-invocation-service.ts +22 -71
  41. package/src/services/index.ts +1 -6
  42. package/src/services/queues.ts +1 -78
  43. package/src/services/tracing.ts +1 -134
  44. package/src/types/index.ts +5 -0
  45. package/src/types/url.ts +32 -0
  46. package/dist/lib/browser/bundler/index.mjs +0 -265
  47. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  48. package/dist/lib/browser/chunk-C2Z7LCJ2.mjs +0 -649
  49. package/dist/lib/browser/chunk-C2Z7LCJ2.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
  51. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
  52. package/dist/lib/browser/edge/index.mjs +0 -83
  53. package/dist/lib/browser/edge/index.mjs.map +0 -7
  54. package/dist/lib/browser/index.mjs +0 -1366
  55. package/dist/lib/browser/index.mjs.map +0 -7
  56. package/dist/lib/browser/meta.json +0 -1
  57. package/dist/lib/browser/testing/index.mjs +0 -129
  58. package/dist/lib/browser/testing/index.mjs.map +0 -7
  59. package/dist/lib/node-esm/bundler/index.mjs +0 -266
  60. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  61. package/dist/lib/node-esm/chunk-AH3AZM2U.mjs +0 -651
  62. package/dist/lib/node-esm/chunk-AH3AZM2U.mjs.map +0 -7
  63. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  64. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  65. package/dist/lib/node-esm/edge/index.mjs +0 -84
  66. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  67. package/dist/lib/node-esm/index.mjs +0 -1367
  68. package/dist/lib/node-esm/index.mjs.map +0 -7
  69. package/dist/lib/node-esm/meta.json +0 -1
  70. package/dist/lib/node-esm/testing/index.mjs +0 -130
  71. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  72. package/dist/types/src/bundler/bundler.d.ts +0 -49
  73. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  74. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  75. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  76. package/dist/types/src/bundler/index.d.ts +0 -2
  77. package/dist/types/src/bundler/index.d.ts.map +0 -1
  78. package/dist/types/src/edge/functions.d.ts +0 -17
  79. package/dist/types/src/edge/functions.d.ts.map +0 -1
  80. package/dist/types/src/edge/index.d.ts +0 -2
  81. package/dist/types/src/edge/index.d.ts.map +0 -1
  82. package/dist/types/src/errors.d.ts +0 -137
  83. package/dist/types/src/errors.d.ts.map +0 -1
  84. package/dist/types/src/examples/fib.d.ts +0 -7
  85. package/dist/types/src/examples/fib.d.ts.map +0 -1
  86. package/dist/types/src/examples/index.d.ts +0 -4
  87. package/dist/types/src/examples/index.d.ts.map +0 -1
  88. package/dist/types/src/examples/reply.d.ts +0 -3
  89. package/dist/types/src/examples/reply.d.ts.map +0 -1
  90. package/dist/types/src/examples/sleep.d.ts +0 -5
  91. package/dist/types/src/examples/sleep.d.ts.map +0 -1
  92. package/dist/types/src/executor/executor.d.ts +0 -14
  93. package/dist/types/src/executor/executor.d.ts.map +0 -1
  94. package/dist/types/src/executor/index.d.ts +0 -2
  95. package/dist/types/src/executor/index.d.ts.map +0 -1
  96. package/dist/types/src/handler.d.ts +0 -106
  97. package/dist/types/src/handler.d.ts.map +0 -1
  98. package/dist/types/src/schema.d.ts +0 -43
  99. package/dist/types/src/schema.d.ts.map +0 -1
  100. package/dist/types/src/services/database.d.ts +0 -63
  101. package/dist/types/src/services/database.d.ts.map +0 -1
  102. package/dist/types/src/services/event-logger.d.ts +0 -72
  103. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  104. package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
  105. package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
  106. package/dist/types/src/services/local-function-execution.d.ts +0 -32
  107. package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
  108. package/dist/types/src/services/remote-function-execution-service.d.ts +0 -20
  109. package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
  110. package/dist/types/src/services/service-container.d.ts +0 -56
  111. package/dist/types/src/services/service-container.d.ts.map +0 -1
  112. package/dist/types/src/services/service-registry.d.ts +0 -29
  113. package/dist/types/src/services/service-registry.d.ts.map +0 -1
  114. package/dist/types/src/services/service-registry.test.d.ts +0 -2
  115. package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
  116. package/dist/types/src/testing/index.d.ts +0 -3
  117. package/dist/types/src/testing/index.d.ts.map +0 -1
  118. package/dist/types/src/testing/layer.d.ts +0 -17
  119. package/dist/types/src/testing/layer.d.ts.map +0 -1
  120. package/dist/types/src/testing/logger.d.ts +0 -5
  121. package/dist/types/src/testing/logger.d.ts.map +0 -1
  122. package/dist/types/src/testing/persist-database.test.d.ts +0 -2
  123. package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
  124. package/dist/types/src/testing/services.d.ts +0 -59
  125. package/dist/types/src/testing/services.d.ts.map +0 -1
  126. package/dist/types/src/trace.d.ts +0 -122
  127. package/dist/types/src/trace.d.ts.map +0 -1
  128. package/dist/types/src/translations.d.ts +0 -12
  129. package/dist/types/src/translations.d.ts.map +0 -1
  130. package/dist/types/src/triggers/index.d.ts +0 -4
  131. package/dist/types/src/triggers/index.d.ts.map +0 -1
  132. package/dist/types/src/triggers/input-builder.d.ts +0 -3
  133. package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
  134. package/dist/types/src/triggers/invocation-tracer.d.ts +0 -35
  135. package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
  136. package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -74
  137. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
  138. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
  139. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
  140. package/dist/types/src/triggers/trigger-state-store.d.ts +0 -27
  141. package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
  142. package/dist/types/src/types.d.ts +0 -221
  143. package/dist/types/src/types.d.ts.map +0 -1
  144. package/dist/types/src/url.d.ts +0 -21
  145. package/dist/types/src/url.d.ts.map +0 -1
  146. package/src/bundler/bundler.test.ts +0 -58
  147. package/src/bundler/bundler.ts +0 -291
  148. package/src/bundler/index.ts +0 -5
  149. package/src/edge/functions.ts +0 -67
  150. package/src/edge/index.ts +0 -9
  151. package/src/errors.ts +0 -21
  152. package/src/examples/fib.ts +0 -31
  153. package/src/examples/index.ts +0 -7
  154. package/src/examples/reply.ts +0 -19
  155. package/src/examples/sleep.ts +0 -23
  156. package/src/executor/executor.ts +0 -57
  157. package/src/handler.ts +0 -222
  158. package/src/schema.ts +0 -68
  159. package/src/services/database.ts +0 -171
  160. package/src/services/event-logger.ts +0 -118
  161. package/src/services/function-invocation-service.test.ts +0 -79
  162. package/src/services/local-function-execution.ts +0 -150
  163. package/src/services/remote-function-execution-service.ts +0 -61
  164. package/src/services/service-container.ts +0 -114
  165. package/src/services/service-registry.test.ts +0 -42
  166. package/src/services/service-registry.ts +0 -59
  167. package/src/testing/index.ts +0 -6
  168. package/src/testing/layer.ts +0 -112
  169. package/src/testing/logger.ts +0 -16
  170. package/src/testing/persist-database.test.ts +0 -87
  171. package/src/testing/services.ts +0 -115
  172. package/src/trace.ts +0 -178
  173. package/src/translations.ts +0 -20
  174. package/src/triggers/index.ts +0 -7
  175. package/src/triggers/input-builder.ts +0 -35
  176. package/src/triggers/invocation-tracer.ts +0 -99
  177. package/src/triggers/trigger-dispatcher.test.ts +0 -651
  178. package/src/triggers/trigger-dispatcher.ts +0 -522
  179. package/src/triggers/trigger-state-store.ts +0 -60
  180. package/src/types.ts +0 -214
  181. package/src/url.ts +0 -55
@@ -1,221 +0,0 @@
1
- import { Schema } from 'effect';
2
- import { QueryAST, Type } from '@dxos/echo';
3
- import { Expando, Ref } from '@dxos/echo-schema';
4
- /**
5
- * Type discriminator for TriggerType.
6
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
7
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
8
- */
9
- export declare const TriggerKinds: readonly ["timer", "webhook", "subscription", "email", "queue"];
10
- export type TriggerKind = (typeof TriggerKinds)[number];
11
- /**
12
- * Cron timer.
13
- */
14
- declare const TimerTriggerSchema: Schema.mutable<Schema.Struct<{
15
- kind: Schema.Literal<["timer"]>;
16
- cron: Schema.SchemaClass<string, string, never>;
17
- }>>;
18
- export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
19
- declare const EmailTriggerSchema: Schema.mutable<Schema.Struct<{
20
- kind: Schema.Literal<["email"]>;
21
- }>>;
22
- export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
23
- declare const QueueTriggerSchema: Schema.mutable<Schema.Struct<{
24
- kind: Schema.Literal<["queue"]>;
25
- queue: Schema.refine<string, typeof Schema.NonEmptyString>;
26
- }>>;
27
- export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
28
- /**
29
- * Webhook.
30
- */
31
- declare const WebhookTriggerSchema: Schema.mutable<Schema.Struct<{
32
- kind: Schema.Literal<["webhook"]>;
33
- method: Schema.optional<Schema.SchemaClass<string, string, never>>;
34
- port: Schema.optional<Schema.SchemaClass<number, number, never>>;
35
- }>>;
36
- export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
37
- /**
38
- * Subscription.
39
- */
40
- declare const SubscriptionTriggerSchema: Schema.mutable<Schema.Struct<{
41
- kind: Schema.Literal<["subscription"]>;
42
- query: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
43
- options: Schema.optional<Schema.Struct<{
44
- deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
45
- delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
46
- }>>;
47
- }>>;
48
- export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
49
- /**
50
- * Trigger schema (discriminated union).
51
- */
52
- export declare const TriggerSchema: Schema.Union<[Schema.mutable<Schema.Struct<{
53
- kind: Schema.Literal<["timer"]>;
54
- cron: Schema.SchemaClass<string, string, never>;
55
- }>>, Schema.mutable<Schema.Struct<{
56
- kind: Schema.Literal<["webhook"]>;
57
- method: Schema.optional<Schema.SchemaClass<string, string, never>>;
58
- port: Schema.optional<Schema.SchemaClass<number, number, never>>;
59
- }>>, Schema.mutable<Schema.Struct<{
60
- kind: Schema.Literal<["subscription"]>;
61
- query: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
62
- options: Schema.optional<Schema.Struct<{
63
- deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
64
- delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
65
- }>>;
66
- }>>, Schema.mutable<Schema.Struct<{
67
- kind: Schema.Literal<["email"]>;
68
- }>>, Schema.mutable<Schema.Struct<{
69
- kind: Schema.Literal<["queue"]>;
70
- queue: Schema.refine<string, typeof Schema.NonEmptyString>;
71
- }>>]>;
72
- export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
73
- export type EventType = EmailTriggerOutput | WebhookTriggerOutput | QueueTriggerOutput | SubscriptionTriggerOutput | TimerTriggerOutput;
74
- export declare const EmailTriggerOutput: Schema.mutable<Schema.Struct<{
75
- from: typeof Schema.String;
76
- to: typeof Schema.String;
77
- subject: typeof Schema.String;
78
- created: typeof Schema.String;
79
- body: typeof Schema.String;
80
- }>>;
81
- export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
82
- export declare const WebhookTriggerOutput: Schema.mutable<Schema.Struct<{
83
- url: typeof Schema.String;
84
- method: Schema.Literal<["GET", "POST"]>;
85
- headers: Schema.Record$<typeof Schema.String, typeof Schema.String>;
86
- bodyText: typeof Schema.String;
87
- }>>;
88
- export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
89
- export declare const QueueTriggerOutput: Schema.mutable<Schema.Struct<{
90
- queue: Schema.refine<string, typeof Schema.NonEmptyString>;
91
- item: typeof Schema.Any;
92
- cursor: typeof Schema.String;
93
- }>>;
94
- export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
95
- export declare const SubscriptionTriggerOutput: Schema.mutable<Schema.Struct<{
96
- /**
97
- * Type of the mutation.
98
- */
99
- type: typeof Schema.String;
100
- /**
101
- * Reference to the object that was changed or created.
102
- */
103
- subject: Type.ref<Type.obj<Schema.Struct<{}>>>;
104
- /**
105
- * @deprecated
106
- */
107
- changedObjectId: Schema.optional<typeof Schema.String>;
108
- }>>;
109
- export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
110
- export declare const TimerTriggerOutput: Schema.mutable<Schema.Struct<{
111
- tick: typeof Schema.Number;
112
- }>>;
113
- export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
114
- /**
115
- * Function trigger.
116
- * Function is invoked with the `payload` passed as input data.
117
- * The event that triggers the function is available in the function context.
118
- */
119
- declare const FunctionTrigger_: Type.obj<Schema.Struct<{
120
- /**
121
- * Function or workflow to invoke.
122
- */
123
- function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
124
- /**
125
- * Only used for workflowSchema.
126
- * Specifies the input node in the circuit.
127
- * @deprecated Remove and enforce a single input node in all compute graphSchema.
128
- */
129
- inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
130
- enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
131
- spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
132
- kind: Schema.Literal<["timer"]>;
133
- cron: Schema.SchemaClass<string, string, never>;
134
- }>>, Schema.mutable<Schema.Struct<{
135
- kind: Schema.Literal<["webhook"]>;
136
- method: Schema.optional<Schema.SchemaClass<string, string, never>>;
137
- port: Schema.optional<Schema.SchemaClass<number, number, never>>;
138
- }>>, Schema.mutable<Schema.Struct<{
139
- kind: Schema.Literal<["subscription"]>;
140
- query: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
141
- options: Schema.optional<Schema.Struct<{
142
- deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
143
- delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
144
- }>>;
145
- }>>, Schema.mutable<Schema.Struct<{
146
- kind: Schema.Literal<["email"]>;
147
- }>>, Schema.mutable<Schema.Struct<{
148
- kind: Schema.Literal<["queue"]>;
149
- queue: Schema.refine<string, typeof Schema.NonEmptyString>;
150
- }>>]>>;
151
- /**
152
- * Passed as the input data to the function.
153
- * Must match the function's input schema.
154
- *
155
- * @example
156
- * {
157
- * item: '{{$.trigger.event}}',
158
- * instructions: 'Summarize and perform entity-extraction'
159
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
160
- * }
161
- */
162
- input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
163
- }>>;
164
- export interface FunctionTrigger extends Schema.Schema.Type<typeof FunctionTrigger_> {
165
- }
166
- export interface FunctionTriggerEncoded extends Schema.Schema.Encoded<typeof FunctionTrigger_> {
167
- }
168
- export declare const FunctionTrigger: Schema.Schema<FunctionTrigger, FunctionTriggerEncoded>;
169
- /**
170
- * Function manifest file.
171
- */
172
- export declare const FunctionManifestSchema: Schema.Struct<{
173
- functions: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
174
- name: string;
175
- description?: string | undefined;
176
- source?: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
177
- name?: string | undefined;
178
- description?: string | undefined;
179
- changed?: boolean | undefined;
180
- source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
181
- content: string;
182
- }>;
183
- }> | undefined;
184
- version: string;
185
- key?: string | undefined;
186
- inputSchema?: Type.JsonSchema | undefined;
187
- outputSchema?: Type.JsonSchema | undefined;
188
- binding?: string | undefined;
189
- }> & import("@dxos/echo-schema").WithMeta, {
190
- id: string;
191
- name: string;
192
- version: string;
193
- description?: string | undefined;
194
- source?: import("@dxos/echo-protocol").EncodedReference | undefined;
195
- key?: string | undefined;
196
- inputSchema?: Type.JsonSchema | undefined;
197
- outputSchema?: Type.JsonSchema | undefined;
198
- binding?: string | undefined;
199
- }, never>>>>;
200
- triggers: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<FunctionTrigger> & import("@dxos/echo-schema").WithMeta, FunctionTriggerEncoded, never>>>>;
201
- }>;
202
- export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
203
- export declare const FUNCTION_TYPES: (Type.obj<Schema.Struct<{
204
- key: Schema.optional<typeof Schema.String>;
205
- name: typeof Schema.NonEmptyString;
206
- version: typeof Schema.String;
207
- description: Schema.optional<typeof Schema.String>;
208
- source: Schema.optional<import("@dxos/echo-schema").Ref$<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
209
- name?: string | undefined;
210
- description?: string | undefined;
211
- changed?: boolean | undefined;
212
- source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
213
- content: string;
214
- }>;
215
- }>>;
216
- inputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
217
- outputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
218
- binding: Schema.optional<typeof Schema.String>;
219
- }>> | Schema.Schema<FunctionTrigger, FunctionTriggerEncoded, never>)[];
220
- export {};
221
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"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"}
@@ -1,21 +0,0 @@
1
- import { type ObjectMeta } from '@dxos/echo-schema';
2
- import { type SpaceId } from '@dxos/keys';
3
- export declare const FUNCTIONS_META_KEY = "dxos.org/service/function";
4
- export declare const FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
5
- /**
6
- * NOTE: functionId is backend ID, not ECHO object id.
7
- */
8
- export declare const getUserFunctionIdInMetadata: (meta: ObjectMeta) => string | undefined;
9
- /**
10
- * NOTE: functionId is backend ID, not ECHO object id.
11
- */
12
- export declare const setUserFunctionIdInMetadata: (meta: ObjectMeta, functionId: string) => void;
13
- /**
14
- * NOTE: functionId is backend ID, not ECHO object id.
15
- */
16
- export declare const getInvocationUrl: (functionId: string, edgeUrl: string, options?: InvocationOptions) => string;
17
- export type InvocationOptions = {
18
- spaceId?: SpaceId;
19
- subjectId?: string;
20
- };
21
- //# sourceMappingURL=url.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,eAAO,MAAM,yBAAyB,qCAAqC,CAAC;AAM5E;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,UAAU,uBAE3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,UAAU,EAAE,YAAY,MAAM,SAS/E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,EAAE,SAAS,MAAM,EAAE,UAAS,iBAAsB,WASpG,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1,58 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- // @ts-ignore
6
- import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
- import { assert, beforeAll, describe, expect, test } from 'vitest';
8
-
9
- import { isNode } from '@dxos/util';
10
-
11
- import { Bundler, initializeBundler } from './bundler';
12
-
13
- describe('Bundler', () => {
14
- beforeAll(async () => {
15
- if (!isNode()) {
16
- await initializeBundler({ wasmUrl });
17
- }
18
- });
19
-
20
- test('Basic', async () => {
21
- const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
22
- const result = await bundler.bundle({ source: 'const x = 100' }); // TODO(burdon): Test import.
23
- assert(!('error' in result), 'error should not exist');
24
- expect(result.asset).toBeDefined();
25
- });
26
-
27
- test('Import', async () => {
28
- const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
29
- const result = await bundler.bundle({
30
- source: `
31
- import { Filter } from './runtime.js';
32
-
33
- const query = Filter.typename('dxos.org/type/Example');
34
- `,
35
- });
36
- assert(!('error' in result), 'error should not exist');
37
- expect(result.asset).toBeDefined();
38
- });
39
-
40
- // TODO(dmaretskyi): Flaky on CI.
41
- test.skip('HTTPS Import', async () => {
42
- const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
43
- const result = await bundler.bundle({
44
- source: `
45
- import { invariant } from 'https://esm.sh/@dxos/invariant';
46
- invariant(true);
47
- `,
48
- });
49
- assert(!('error' in result), 'error should not exist');
50
- expect(result.asset).toBeDefined();
51
- });
52
-
53
- test('Error', async () => {
54
- const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
55
- const result = await bundler.bundle({ source: "import missing from './module'; missing();" });
56
- assert('error' in result, 'error should exist');
57
- });
58
- });
@@ -1,291 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { FetchHttpClient, HttpClient } from '@effect/platform';
6
- import { Duration, Effect, Schedule, pipe } from 'effect';
7
- import { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';
8
-
9
- import { subtleCrypto } from '@dxos/crypto';
10
- import { runAndForwardErrors } from '@dxos/effect';
11
- import { invariant } from '@dxos/invariant';
12
- import { log } from '@dxos/log';
13
-
14
- export type Import = {
15
- moduleUrl: string;
16
- defaultImport: boolean;
17
- namedImports: string[];
18
- };
19
-
20
- export type BundleOptions = {
21
- /**
22
- * Source code to bundle.
23
- */
24
- source: string;
25
- };
26
-
27
- export type BundleResult =
28
- | {
29
- timestamp: number;
30
- sourceHash: Buffer;
31
- error: unknown;
32
- }
33
- | {
34
- timestamp: number;
35
- sourceHash: Buffer;
36
- imports: Import[];
37
- entryPoint: string;
38
- asset: Uint8Array;
39
- bundle: string;
40
- };
41
-
42
- export type BundlerOptions = {
43
- platform: BuildOptions['platform'];
44
- sandboxedModules: string[];
45
- remoteModules: Record<string, string>;
46
- };
47
-
48
- let initialized: Promise<void>;
49
- export const initializeBundler = async (options: { wasmUrl: string }) => {
50
- await (initialized ??= initialize({
51
- wasmURL: options.wasmUrl,
52
- }));
53
- };
54
-
55
- /**
56
- * ESBuild bundler.
57
- */
58
- export class Bundler {
59
- constructor(private readonly _options: BundlerOptions) {}
60
-
61
- async bundle({ source }: BundleOptions): Promise<BundleResult> {
62
- const { sandboxedModules: providedModules, ...options } = this._options;
63
- const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));
64
-
65
- if (this._options.platform === 'browser') {
66
- invariant(initialized, 'Compiler not initialized.');
67
- await initialized;
68
- }
69
-
70
- const imports = source ? analyzeSourceFileImports(source) : [];
71
-
72
- // https://esbuild.github.io/api/#build
73
- try {
74
- const result = await build({
75
- platform: options.platform,
76
- conditions: ['workerd', 'browser'],
77
- metafile: true,
78
- write: false,
79
- entryPoints: {
80
- // Gets mapped to `userFunc.js` by esbuild.
81
- userFunc: 'memory:main.tsx',
82
- },
83
- bundle: true,
84
- format: 'esm',
85
- plugins: [
86
- {
87
- name: 'memory',
88
- setup: (build) => {
89
- build.onResolve({ filter: /^\.\/runtime\.js$/ }, ({ path }) => {
90
- return { path, external: true };
91
- });
92
-
93
- build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {
94
- return { path: './runtime.js', external: true };
95
- });
96
-
97
- build.onResolve({ filter: /^memory:/ }, ({ path }) => {
98
- return { path: path.split(':')[1], namespace: 'memory' };
99
- });
100
-
101
- build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {
102
- if (path === 'main.tsx') {
103
- return {
104
- contents: source,
105
- loader: 'tsx',
106
- };
107
- }
108
- });
109
-
110
- for (const module of providedModules) {
111
- build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {
112
- return { path, namespace: 'injected-module' };
113
- });
114
- }
115
-
116
- build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {
117
- const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
118
- return {
119
- contents: `
120
- const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
121
- export { ${namedImports.join(',')} };
122
- export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
123
- `,
124
- loader: 'tsx',
125
- };
126
- });
127
- },
128
- },
129
- httpPlugin,
130
- ],
131
- });
132
-
133
- log('compile complete', result.metafile);
134
-
135
- const entryPoint = 'userFunc.js';
136
- return {
137
- timestamp: Date.now(),
138
- sourceHash,
139
- imports: this.analyzeImports(result),
140
- entryPoint,
141
- asset: result.outputFiles![0].contents,
142
- bundle: result.outputFiles![0].text,
143
- };
144
- } catch (err) {
145
- return { timestamp: Date.now(), sourceHash, error: err };
146
- }
147
- }
148
-
149
- // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
150
- analyzeImports(result: BuildResult): Import[] {
151
- invariant(result.outputFiles);
152
-
153
- // TODO(dmaretskyi): Support import aliases and wildcard imports.
154
- const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
155
- return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {
156
- const namedImports: string[] = [];
157
- const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
158
- if (parsedImport?.[2]) {
159
- NAMED_IMPORTS_REGEX.lastIndex = 0;
160
- const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
161
- if (namedImportsMatch) {
162
- namedImportsMatch[1].split(',').forEach((importName) => {
163
- namedImports.push(importName.trim());
164
- });
165
- }
166
- }
167
-
168
- return {
169
- moduleUrl: entry.path,
170
- defaultImport: !!parsedImport?.[1],
171
- namedImports,
172
- };
173
- });
174
- }
175
-
176
- analyzeSourceFileImports(code: string): {
177
- defaultImportName: string;
178
- namedImports: string[];
179
- wildcardImportName: string;
180
- moduleIdentifier: string;
181
- quotes: string;
182
- }[] {
183
- // TODO(dmaretskyi): Support import aliases and wildcard imports.
184
- const parsedImports = allMatches(IMPORT_REGEX, code);
185
- return parsedImports.map((capture) => {
186
- return {
187
- defaultImportName: capture[1],
188
- namedImports: capture[2]?.split(',').map((importName) => importName.trim()),
189
- wildcardImportName: capture[3],
190
- moduleIdentifier: capture[4],
191
- quotes: capture[5],
192
- };
193
- });
194
- }
195
- }
196
-
197
- // https://regex101.com/r/FEN5ks/1
198
- // https://stackoverflow.com/a/73265022
199
- // $1 = default import name (can be non-existent)
200
- // $2 = destructured exports (can be non-existent)
201
- // $3 = wildcard import name (can be non-existent)
202
- // $4 = module identifier
203
- // $5 = quotes used (either ' or ")
204
- const IMPORT_REGEX =
205
- /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
206
-
207
- const NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
208
-
209
- const allMatches = (regex: RegExp, str: string) => {
210
- let match;
211
- const matches = [];
212
- regex.lastIndex = 0;
213
- while ((match = regex.exec(str))) {
214
- matches.push(match);
215
- }
216
-
217
- return matches;
218
- };
219
-
220
- type ParsedImport = {
221
- defaultImportName?: string;
222
- namedImports: string[];
223
- wildcardImportName?: string;
224
- moduleIdentifier: string;
225
- quotes: string;
226
- };
227
-
228
- const analyzeSourceFileImports = (code: string): ParsedImport[] => {
229
- // TODO(dmaretskyi): Support import aliases and wildcard imports.
230
- const parsedImports = allMatches(IMPORT_REGEX, code);
231
- return parsedImports.map((capture) => {
232
- return {
233
- defaultImportName: capture[1],
234
- namedImports: capture[2]
235
- ?.trim()
236
- .slice(1, -1)
237
- .split(',')
238
- .map((importName) => importName.trim()),
239
- wildcardImportName: capture[3],
240
- moduleIdentifier: capture[4],
241
- quotes: capture[5],
242
- };
243
- });
244
- };
245
-
246
- const MAX_RETRIES = 5;
247
- const INITIAL_DELAY = 1_000;
248
-
249
- const httpPlugin: Plugin = {
250
- name: 'http',
251
- setup: (build) => {
252
- // Intercept import paths starting with "http:" and "https:" so esbuild doesn't attempt to map them to a file system location.
253
- // Tag them with the "http-url" namespace to associate them with this plugin.
254
- build.onResolve({ filter: /^https?:\/\// }, (args) => ({
255
- path: args.path,
256
- namespace: 'http-url',
257
- }));
258
-
259
- // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.
260
- // All of these files will be in the "http-url" namespace.
261
- // Make sure to keep the newly resolved URL in the "http-url" namespace so imports inside it will also be resolved as URLs recursively.
262
- build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({
263
- path: new URL(args.path, args.importer).toString(),
264
- namespace: 'http-url',
265
- }));
266
-
267
- // When a URL is loaded, we want to actually download the content from the internet.
268
- // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.
269
- build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {
270
- return Effect.gen(function* () {
271
- const response = yield* HttpClient.get(args.path);
272
- if (response.status !== 200) {
273
- throw new Error(`failed to fetch: ${response.status}`);
274
- }
275
-
276
- const text = yield* response.text;
277
- return { contents: text, loader: 'jsx' as Loader };
278
- }).pipe(
279
- Effect.retry(
280
- pipe(
281
- Schedule.exponential(Duration.millis(INITIAL_DELAY)),
282
- Schedule.jittered,
283
- Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),
284
- ),
285
- ),
286
- Effect.provide(FetchHttpClient.layer),
287
- runAndForwardErrors,
288
- );
289
- });
290
- },
291
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './bundler';
@@ -1,67 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type DID } from 'iso-did/types';
6
-
7
- import { type Client } from '@dxos/client';
8
- import { createEdgeIdentity } from '@dxos/client/edge';
9
- import { EdgeHttpClient } from '@dxos/edge-client';
10
- import { invariant } from '@dxos/invariant';
11
- import { type PublicKey } from '@dxos/keys';
12
- import { log } from '@dxos/log';
13
- import { type UploadFunctionResponseBody } from '@dxos/protocols';
14
-
15
- export type UploadWorkerArgs = {
16
- client: Client;
17
- version: string;
18
- name?: string;
19
- functionId?: string;
20
- ownerPublicKey: PublicKey;
21
- entryPoint: string;
22
- assets: Record<string, Uint8Array>;
23
- };
24
-
25
- export const uploadWorkerFunction = async ({
26
- client,
27
- version,
28
- name,
29
- functionId,
30
- ownerPublicKey,
31
- entryPoint,
32
- assets,
33
- }: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {
34
- log('uploading function', { functionId, name, version, ownerPublicKey });
35
- const edgeUrl = client.config.values.runtime?.services?.edge?.url;
36
- invariant(edgeUrl, 'Edge is not configured.');
37
- const edgeClient = new EdgeHttpClient(edgeUrl);
38
- const edgeIdentity = createEdgeIdentity(client);
39
- edgeClient.setIdentity(edgeIdentity);
40
- const response = await edgeClient.uploadFunction(
41
- { functionId },
42
- { name, version, ownerPublicKey: ownerPublicKey.toHex(), entryPoint, assets },
43
- );
44
-
45
- // TODO(burdon): Edge service log.
46
- log('uploaded', {
47
- identityKey: edgeIdentity.identityKey,
48
- functionId,
49
- name,
50
- version,
51
- response,
52
- });
53
-
54
- return response;
55
- };
56
-
57
- export const incrementSemverPatch = (version: string): string => {
58
- const [major, minor, patch] = version.split('.');
59
- const patchNum = Number(patch);
60
- invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`);
61
- return [major, minor, String(patchNum + 1)].join('.');
62
- };
63
-
64
- // TODO(burdon): Factor out.
65
- export const publicKeyToDid = (key: PublicKey): DID => {
66
- return `did:key:${key.toHex()}`;
67
- };