@dxos/functions 0.7.5-labs.f5080a1 → 0.7.5-labs.ff2ff30

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 (50) hide show
  1. package/dist/lib/browser/bundler/index.mjs +239 -0
  2. package/dist/lib/browser/bundler/index.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs → chunk-JNWHUD6Z.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-R4ERZ4GX.mjs → chunk-PI2DP37S.mjs} +10 -3
  5. package/dist/lib/browser/chunk-PI2DP37S.mjs.map +7 -0
  6. package/dist/lib/browser/index.mjs +2 -2
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +2 -2
  9. package/dist/lib/browser/types/index.mjs +1 -1
  10. package/dist/lib/node/bundler/index.cjs +261 -0
  11. package/dist/lib/node/bundler/index.cjs.map +7 -0
  12. package/dist/lib/node/{chunk-NC6L7H5C.cjs → chunk-2ASAZ4AS.cjs} +15 -15
  13. package/dist/lib/node/{chunk-4WNFTPH7.cjs → chunk-PGFJYL6Q.cjs} +12 -5
  14. package/dist/lib/node/chunk-PGFJYL6Q.cjs.map +7 -0
  15. package/dist/lib/node/index.cjs +15 -15
  16. package/dist/lib/node/meta.json +1 -1
  17. package/dist/lib/node/testing/index.cjs +7 -7
  18. package/dist/lib/node/types/index.cjs +10 -10
  19. package/dist/lib/node/types/index.cjs.map +1 -1
  20. package/dist/lib/node-esm/bundler/index.mjs +239 -0
  21. package/dist/lib/node-esm/bundler/index.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-UOQLFLOW.mjs → chunk-IOAKDIT3.mjs} +10 -3
  23. package/dist/lib/node-esm/chunk-IOAKDIT3.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs → chunk-LNBGGB6Z.mjs} +2 -2
  25. package/dist/lib/node-esm/index.mjs +2 -2
  26. package/dist/lib/node-esm/meta.json +1 -1
  27. package/dist/lib/node-esm/testing/index.mjs +2 -2
  28. package/dist/lib/node-esm/types/index.mjs +1 -1
  29. package/dist/types/src/bundler/bundler.d.ts +51 -0
  30. package/dist/types/src/bundler/bundler.d.ts.map +1 -0
  31. package/dist/types/src/bundler/bundler.test.d.ts +2 -0
  32. package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
  33. package/dist/types/src/bundler/index.d.ts +2 -0
  34. package/dist/types/src/bundler/index.d.ts.map +1 -0
  35. package/dist/types/src/types/schema.d.ts +2 -0
  36. package/dist/types/src/types/schema.d.ts.map +1 -1
  37. package/dist/types/src/types/types.d.ts +25 -1
  38. package/dist/types/src/types/types.d.ts.map +1 -1
  39. package/package.json +30 -17
  40. package/src/bundler/bundler.test.ts +59 -0
  41. package/src/bundler/bundler.ts +264 -0
  42. package/src/bundler/index.ts +5 -0
  43. package/src/types/schema.ts +1 -0
  44. package/src/types/types.ts +10 -1
  45. package/dist/lib/browser/chunk-R4ERZ4GX.mjs.map +0 -7
  46. package/dist/lib/node/chunk-4WNFTPH7.cjs.map +0 -7
  47. package/dist/lib/node-esm/chunk-UOQLFLOW.mjs.map +0 -7
  48. /package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs.map → chunk-JNWHUD6Z.mjs.map} +0 -0
  49. /package/dist/lib/node/{chunk-NC6L7H5C.cjs.map → chunk-2ASAZ4AS.cjs.map} +0 -0
  50. /package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs.map → chunk-LNBGGB6Z.mjs.map} +0 -0
@@ -0,0 +1,264 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type BuildOptions } from 'esbuild';
6
+ import { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';
7
+
8
+ import { subtleCrypto } from '@dxos/crypto';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { log } from '@dxos/log';
11
+
12
+ export type Import = {
13
+ moduleUrl: string;
14
+ defaultImport: boolean;
15
+ namedImports: string[];
16
+ };
17
+
18
+ export type BundleOptions = {
19
+ /**
20
+ * Path to the source file on the local file system.
21
+ * If provided, the path will be used instead of the `source` code.
22
+ */
23
+ path?: string;
24
+
25
+ /**
26
+ * Source code to bundle.
27
+ * Required if `path` is not provided.
28
+ */
29
+ source?: string;
30
+ };
31
+
32
+ export type BundleResult = {
33
+ timestamp: number;
34
+ sourceHash?: Buffer;
35
+ imports?: Import[];
36
+ bundle?: string;
37
+ error?: any;
38
+ };
39
+
40
+ export type BundlerOptions = {
41
+ platform: BuildOptions['platform'];
42
+ sandboxedModules: string[];
43
+ remoteModules: Record<string, string>;
44
+ };
45
+
46
+ let initialized: Promise<void>;
47
+ export const initializeBundler = async (options: { wasmUrl: string }) => {
48
+ await (initialized ??= initialize({
49
+ wasmURL: options.wasmUrl,
50
+ }));
51
+ };
52
+
53
+ /**
54
+ * ESBuild bundler.
55
+ */
56
+ export class Bundler {
57
+ constructor(private readonly _options: BundlerOptions) {}
58
+
59
+ async bundle({ path, source }: BundleOptions): Promise<BundleResult> {
60
+ const { sandboxedModules: providedModules, ...options } = this._options;
61
+
62
+ const createResult = async (result?: Partial<BundleResult>) => {
63
+ return {
64
+ timestamp: Date.now(),
65
+ sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,
66
+ ...result,
67
+ };
68
+ };
69
+
70
+ if (this._options.platform === 'browser') {
71
+ invariant(initialized, 'Compiler not initialized.');
72
+ await initialized;
73
+ }
74
+
75
+ const imports = source ? analyzeSourceFileImports(source) : [];
76
+
77
+ // https://esbuild.github.io/api/#build
78
+ try {
79
+ const result = await build({
80
+ platform: options.platform,
81
+ conditions: ['workerd', 'browser'],
82
+ metafile: true,
83
+ write: false,
84
+ entryPoints: [path ?? 'memory:main.tsx'],
85
+ bundle: true,
86
+ format: 'esm',
87
+ plugins: [
88
+ {
89
+ name: 'memory',
90
+ setup: (build) => {
91
+ build.onResolve({ filter: /^\.\/runtime\.js$/ }, ({ path }) => {
92
+ return { path, external: true };
93
+ });
94
+
95
+ build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {
96
+ return { path: './runtime.js', external: true };
97
+ });
98
+
99
+ build.onResolve({ filter: /^memory:/ }, ({ path }) => {
100
+ return { path: path.split(':')[1], namespace: 'memory' };
101
+ });
102
+
103
+ build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {
104
+ if (path === 'main.tsx') {
105
+ return {
106
+ contents: source,
107
+ loader: 'tsx',
108
+ };
109
+ }
110
+ });
111
+
112
+ for (const module of providedModules) {
113
+ build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {
114
+ return { path, namespace: 'injected-module' };
115
+ });
116
+ }
117
+
118
+ build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {
119
+ const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
120
+ return {
121
+ contents: `
122
+ const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
123
+ export { ${namedImports.join(',')} };
124
+ export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
125
+ `,
126
+ loader: 'tsx',
127
+ };
128
+ });
129
+ },
130
+ },
131
+ httpPlugin,
132
+ ],
133
+ });
134
+
135
+ log('compile complete', result.metafile);
136
+
137
+ return await createResult({
138
+ imports: this.analyzeImports(result),
139
+ bundle: result.outputFiles![0].text,
140
+ });
141
+ } catch (err) {
142
+ return await createResult({ error: err });
143
+ }
144
+ }
145
+
146
+ // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
147
+ analyzeImports(result: BuildResult): Import[] {
148
+ invariant(result.outputFiles);
149
+
150
+ // TODO(dmaretskyi): Support import aliases and wildcard imports.
151
+ const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
152
+ return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {
153
+ const namedImports: string[] = [];
154
+
155
+ const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
156
+ if (parsedImport?.[2]) {
157
+ NAMED_IMPORTS_REGEX.lastIndex = 0;
158
+ const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
159
+ if (namedImportsMatch) {
160
+ namedImportsMatch[1].split(',').forEach((importName) => {
161
+ namedImports.push(importName.trim());
162
+ });
163
+ }
164
+ }
165
+
166
+ return {
167
+ moduleUrl: entry.path,
168
+ defaultImport: !!parsedImport?.[1],
169
+ namedImports,
170
+ };
171
+ });
172
+ }
173
+
174
+ analyzeSourceFileImports(code: string) {
175
+ // TODO(dmaretskyi): Support import aliases and wildcard imports.
176
+ const parsedImports = allMatches(IMPORT_REGEX, code);
177
+ return parsedImports.map((capture) => {
178
+ return {
179
+ defaultImportName: capture[1],
180
+ namedImports: capture[2]?.split(',').map((importName) => importName.trim()),
181
+ wildcardImportName: capture[3],
182
+ moduleIdentifier: capture[4],
183
+ quotes: capture[5],
184
+ };
185
+ });
186
+ }
187
+ }
188
+
189
+ // https://regex101.com/r/FEN5ks/1
190
+ // https://stackoverflow.com/a/73265022
191
+ // $1 = default import name (can be non-existent)
192
+ // $2 = destructured exports (can be non-existent)
193
+ // $3 = wildcard import name (can be non-existent)
194
+ // $4 = module identifier
195
+ // $5 = quotes used (either ' or ")
196
+ const IMPORT_REGEX =
197
+ /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;
198
+
199
+ const NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
200
+
201
+ const allMatches = (regex: RegExp, str: string) => {
202
+ regex.lastIndex = 0;
203
+
204
+ let match;
205
+ const matches = [];
206
+ while ((match = regex.exec(str))) {
207
+ matches.push(match);
208
+ }
209
+
210
+ return matches;
211
+ };
212
+
213
+ type ParsedImport = {
214
+ defaultImportName?: string;
215
+ namedImports: string[];
216
+ wildcardImportName?: string;
217
+ moduleIdentifier: string;
218
+ quotes: string;
219
+ };
220
+
221
+ const analyzeSourceFileImports = (code: string): ParsedImport[] => {
222
+ // TODO(dmaretskyi): Support import aliases and wildcard imports.
223
+ const parsedImports = allMatches(IMPORT_REGEX, code);
224
+ return parsedImports.map((capture) => {
225
+ return {
226
+ defaultImportName: capture[1],
227
+ namedImports: capture[2]
228
+ ?.trim()
229
+ .slice(1, -1)
230
+ .split(',')
231
+ .map((importName) => importName.trim()),
232
+ wildcardImportName: capture[3],
233
+ moduleIdentifier: capture[4],
234
+ quotes: capture[5],
235
+ };
236
+ });
237
+ };
238
+
239
+ const httpPlugin: Plugin = {
240
+ name: 'http',
241
+ setup: (build) => {
242
+ // Intercept import paths starting with "http:" and "https:" so esbuild doesn't attempt to map them to a file system location.
243
+ // Tag them with the "http-url" namespace to associate them with this plugin.
244
+ build.onResolve({ filter: /^https?:\/\// }, (args) => ({
245
+ path: args.path,
246
+ namespace: 'http-url',
247
+ }));
248
+
249
+ // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.
250
+ // All of these files will be in the "http-url" namespace.
251
+ // Make sure to keep the newly resolved URL in the "http-url" namespace so imports inside it will also be resolved as URLs recursively.
252
+ build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({
253
+ path: new URL(args.path, args.importer).toString(),
254
+ namespace: 'http-url',
255
+ }));
256
+
257
+ // When a URL is loaded, we want to actually download the content from the internet.
258
+ // 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.
259
+ build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {
260
+ const response = await fetch(args.path);
261
+ return { contents: await response.text(), loader: 'jsx' };
262
+ });
263
+ },
264
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './bundler';
@@ -40,6 +40,7 @@ export class FunctionType extends TypedObject({
40
40
  source: S.optional(Ref(ScriptType)),
41
41
 
42
42
  inputSchema: S.optional(JsonSchemaType),
43
+ outputSchema: S.optional(JsonSchemaType),
43
44
 
44
45
  // Local binding to a function name.
45
46
  binding: S.optional(S.String),
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';
5
+ import { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-schema';
6
6
 
7
7
  /**
8
8
  * Type discriminator for TriggerType.
@@ -14,6 +14,7 @@ export enum TriggerKind {
14
14
  Webhook = 'webhook',
15
15
  Subscription = 'subscription',
16
16
  Email = 'email',
17
+ Queue = 'queue',
17
18
  }
18
19
 
19
20
  // TODO(burdon): Rename prop kind.
@@ -38,6 +39,13 @@ const EmailTriggerSchema = S.Struct({
38
39
 
39
40
  export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
40
41
 
42
+ const QueueTriggerSchema = S.Struct({
43
+ type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),
44
+ queue: DXN,
45
+ }).pipe(S.mutable);
46
+
47
+ export type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;
48
+
41
49
  /**
42
50
  * Webhook.
43
51
  */
@@ -92,6 +100,7 @@ export const TriggerSchema = S.Union(
92
100
  WebhookTriggerSchema,
93
101
  SubscriptionTriggerSchema,
94
102
  EmailTriggerSchema,
103
+ QueueTriggerSchema,
95
104
  ).annotations({
96
105
  [AST.TitleAnnotationId]: 'Trigger',
97
106
  });
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n"],
5
- "mappings": ";;;AAIA,SAASA,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAI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AAIC,iBAAiB,GAAG;EAAU,CAAA,CAAA;;EAG/EoC,MAAMlC,GAAEa,SAASgB,aAAAA;;;EAIjBM,MAAMnC,GAAEa,SAASb,GAAES,QAAQT,GAAEmB,OAAO;IAAEC,KAAKpB,GAAEM;IAAQe,OAAOrB,GAAEsB;EAAI,CAAA,CAAA,CAAA;AACpE,CAAA;AAOO,IAAMc,kBAAN,cAA8BC,aAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAGR,sBAAsBS,MAAM,EAAA;AAAG;AAO3B,IAAMC,cAAN,cAA0BJ,aAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDG,KAAK1C,GAAEM;EACPqC,aAAa3C,GAAEa,SAASb,GAAEM,MAAM;EAChCsC,OAAO5C,GAAEM;EACTuC,SAAS7C,GAAEM;AACb,CAAA,EAAA;AAAI;AAKG,IAAMwC,yBAAyB9C,GAAEC,OAAO;EAC7C8C,WAAW/C,GAAEa,SAASb,GAAES,QAAQT,GAAEgD,MAAMC,UAAUR,WAAAA,CAAAA,CAAAA,CAAAA;EAClDS,UAAUlD,GAAEa,SAASb,GAAES,QAAQT,GAAEgD,MAAMC,UAAUb,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMe,iBAAiB;EAACV;EAAaL;;",
6
- "names": ["JsonSchemaType", "Ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "binding", "AST", "OptionsAnnotationId", "RawObject", "S", "TypedObject", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport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C,SAASD,oBAAAA,EAAEE,MAAM;EAChCqD,OAAOvD,oBAAAA,EAAEE;EACTsD,SAASxD,oBAAAA,EAAEE;AACb,CAAA,EAAA;AAAI;AAKG,IAAMuD,yBAAyBzD,oBAAAA,EAAEmB,OAAO;EAC7CuC,WAAW1D,oBAAAA,EAAEC,SAASD,oBAAAA,EAAE0B,QAAQ1B,oBAAAA,EAAE2D,UAAMC,+BAAUP,WAAAA,CAAAA,CAAAA,CAAAA;EAClDQ,UAAU7D,oBAAAA,EAAEC,SAASD,oBAAAA,EAAE0B,QAAQ1B,oBAAAA,EAAE2D,UAAMC,+BAAUT,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMW,iBAAiB;EAACT;EAAaF;;",
6
- "names": ["import_echo_schema", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "Struct", "type", "Literal", "annotations", "cron", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n"],
5
- "mappings": ";;;AAIA,SAASA,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,cAA2Bb,YAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG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b,GAAES,QAAQT,GAAEmB,OAAO;IAAEC,KAAKpB,GAAEM;IAAQe,OAAOrB,GAAEsB;EAAI,CAAA,CAAA,CAAA;AACpE,CAAA;AAOO,IAAMc,kBAAN,cAA8BC,aAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAGR,sBAAsBS,MAAM,EAAA;AAAG;AAO3B,IAAMC,cAAN,cAA0BJ,aAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDG,KAAK1C,GAAEM;EACPqC,aAAa3C,GAAEa,SAASb,GAAEM,MAAM;EAChCsC,OAAO5C,GAAEM;EACTuC,SAAS7C,GAAEM;AACb,CAAA,EAAA;AAAI;AAKG,IAAMwC,yBAAyB9C,GAAEC,OAAO;EAC7C8C,WAAW/C,GAAEa,SAASb,GAAES,QAAQT,GAAEgD,MAAMC,UAAUR,WAAAA,CAAAA,CAAAA,CAAAA;EAClDS,UAAUlD,GAAEa,SAASb,GAAES,QAAQT,GAAEgD,MAAMC,UAAUb,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMe,iBAAiB;EAACV;EAAaL;;",
6
- "names": ["JsonSchemaType", "Ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "binding", "AST", "OptionsAnnotationId", "RawObject", "S", "TypedObject", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
7
- }