@dxos/functions 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc

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 (63) 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-R4ERZ4GX.mjs → chunk-IXJNRWJP.mjs} +47 -10
  4. package/dist/lib/browser/chunk-IXJNRWJP.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs → chunk-XLM3CJXO.mjs} +2 -2
  6. package/dist/lib/browser/index.mjs +23 -7
  7. package/dist/lib/browser/index.mjs.map +3 -3
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/testing/index.mjs +2 -2
  10. package/dist/lib/browser/types/index.mjs +1 -1
  11. package/dist/lib/node/bundler/index.cjs +261 -0
  12. package/dist/lib/node/bundler/index.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-4WNFTPH7.cjs → chunk-MGCKR53Q.cjs} +47 -12
  14. package/dist/lib/node/chunk-MGCKR53Q.cjs.map +7 -0
  15. package/dist/lib/node/{chunk-NC6L7H5C.cjs → chunk-TLSUCABH.cjs} +15 -15
  16. package/dist/lib/node/index.cjs +36 -19
  17. package/dist/lib/node/index.cjs.map +3 -3
  18. package/dist/lib/node/meta.json +1 -1
  19. package/dist/lib/node/testing/index.cjs +7 -7
  20. package/dist/lib/node/types/index.cjs +10 -10
  21. package/dist/lib/node/types/index.cjs.map +1 -1
  22. package/dist/lib/node-esm/bundler/index.mjs +239 -0
  23. package/dist/lib/node-esm/bundler/index.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs → chunk-CKTHJQ7M.mjs} +2 -2
  25. package/dist/lib/node-esm/{chunk-UOQLFLOW.mjs → chunk-FCZGNRNF.mjs} +47 -10
  26. package/dist/lib/node-esm/chunk-FCZGNRNF.mjs.map +7 -0
  27. package/dist/lib/node-esm/index.mjs +23 -7
  28. package/dist/lib/node-esm/index.mjs.map +3 -3
  29. package/dist/lib/node-esm/meta.json +1 -1
  30. package/dist/lib/node-esm/testing/index.mjs +2 -2
  31. package/dist/lib/node-esm/types/index.mjs +1 -1
  32. package/dist/types/src/bundler/bundler.d.ts +51 -0
  33. package/dist/types/src/bundler/bundler.d.ts.map +1 -0
  34. package/dist/types/src/bundler/bundler.test.d.ts +2 -0
  35. package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
  36. package/dist/types/src/bundler/index.d.ts +2 -0
  37. package/dist/types/src/bundler/index.d.ts.map +1 -0
  38. package/dist/types/src/handler.d.ts +30 -4
  39. package/dist/types/src/handler.d.ts.map +1 -1
  40. package/dist/types/src/testing/types.d.ts +2 -2
  41. package/dist/types/src/types/index.d.ts +1 -0
  42. package/dist/types/src/types/index.d.ts.map +1 -1
  43. package/dist/types/src/types/schema.d.ts +18 -16
  44. package/dist/types/src/types/schema.d.ts.map +1 -1
  45. package/dist/types/src/types/trace.d.ts +103 -0
  46. package/dist/types/src/types/trace.d.ts.map +1 -0
  47. package/dist/types/src/types/types.d.ts +33 -9
  48. package/dist/types/src/types/types.d.ts.map +1 -1
  49. package/package.json +32 -18
  50. package/src/bundler/bundler.test.ts +59 -0
  51. package/src/bundler/bundler.ts +264 -0
  52. package/src/bundler/index.ts +5 -0
  53. package/src/handler.ts +58 -9
  54. package/src/types/index.ts +1 -0
  55. package/src/types/schema.ts +1 -1
  56. package/src/types/trace.ts +49 -0
  57. package/src/types/types.ts +11 -2
  58. package/dist/lib/browser/chunk-R4ERZ4GX.mjs.map +0 -7
  59. package/dist/lib/node/chunk-4WNFTPH7.cjs.map +0 -7
  60. package/dist/lib/node-esm/chunk-UOQLFLOW.mjs.map +0 -7
  61. /package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs.map → chunk-XLM3CJXO.mjs.map} +0 -0
  62. /package/dist/lib/node/{chunk-NC6L7H5C.cjs.map → chunk-TLSUCABH.cjs.map} +0 -0
  63. /package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs.map → chunk-CKTHJQ7M.mjs.map} +0 -0
@@ -8,7 +8,8 @@ export declare enum TriggerKind {
8
8
  Timer = "timer",
9
9
  Webhook = "webhook",
10
10
  Subscription = "subscription",
11
- Email = "email"
11
+ Email = "email",
12
+ Queue = "queue"
12
13
  }
13
14
  /**
14
15
  * Cron timer.
@@ -22,6 +23,11 @@ declare const EmailTriggerSchema: S.mutable<S.Struct<{
22
23
  type: S.Literal<[TriggerKind.Email]>;
23
24
  }>>;
24
25
  export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
26
+ declare const QueueTriggerSchema: S.mutable<S.Struct<{
27
+ type: S.Literal<[TriggerKind.Queue]>;
28
+ queue: S.refine<string, S.Schema<string, string, never>>;
29
+ }>>;
30
+ export type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;
25
31
  /**
26
32
  * Webhook.
27
33
  */
@@ -68,6 +74,9 @@ export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
68
74
  }>>;
69
75
  }>>, S.mutable<S.Struct<{
70
76
  type: S.Literal<[TriggerKind.Email]>;
77
+ }>>, S.mutable<S.Struct<{
78
+ type: S.Literal<[TriggerKind.Queue]>;
79
+ queue: S.refine<string, S.Schema<string, string, never>>;
71
80
  }>>]>;
72
81
  export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
73
82
  /**
@@ -95,11 +104,14 @@ export declare const FunctionTriggerSchema: S.Struct<{
95
104
  }>>;
96
105
  }>>, S.mutable<S.Struct<{
97
106
  type: S.Literal<[TriggerKind.Email]>;
107
+ }>>, S.mutable<S.Struct<{
108
+ type: S.Literal<[TriggerKind.Queue]>;
109
+ queue: S.refine<string, S.Schema<string, string, never>>;
98
110
  }>>]>>;
99
111
  meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
100
112
  }>;
101
113
  export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
102
- declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
114
+ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
103
115
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
104
116
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
105
117
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -121,9 +133,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
121
133
  }>>;
122
134
  }>>, S.mutable<S.Struct<{
123
135
  type: S.Literal<[TriggerKind.Email]>;
136
+ }>>, S.mutable<S.Struct<{
137
+ type: S.Literal<[TriggerKind.Queue]>;
138
+ queue: S.refine<string, S.Schema<string, string, never>>;
124
139
  }>>]>>;
125
140
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
126
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
141
+ }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
127
142
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
128
143
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
129
144
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -145,6 +160,9 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
145
160
  }>>;
146
161
  }>>, S.mutable<S.Struct<{
147
162
  type: S.Literal<[TriggerKind.Email]>;
163
+ }>>, S.mutable<S.Struct<{
164
+ type: S.Literal<[TriggerKind.Queue]>;
165
+ queue: S.refine<string, S.Schema<string, string, never>>;
148
166
  }>>]>>;
149
167
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
150
168
  }>>;
@@ -153,12 +171,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
153
171
  */
154
172
  export declare class FunctionTrigger extends FunctionTrigger_base {
155
173
  }
156
- declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
174
+ declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
157
175
  uri: typeof S.String;
158
176
  description: S.optional<typeof S.String>;
159
177
  route: typeof S.String;
160
178
  handler: typeof S.String;
161
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
179
+ }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
162
180
  uri: typeof S.String;
163
181
  description: S.optional<typeof S.String>;
164
182
  route: typeof S.String;
@@ -174,18 +192,18 @@ export declare class FunctionDef extends FunctionDef_base {
174
192
  * Function manifest file.
175
193
  */
176
194
  export declare const FunctionManifestSchema: S.Struct<{
177
- functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
195
+ functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
178
196
  uri: typeof S.String;
179
197
  description: S.optional<typeof S.String>;
180
198
  route: typeof S.String;
181
199
  handler: typeof S.String;
182
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
200
+ }, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
183
201
  uri: typeof S.String;
184
202
  description: S.optional<typeof S.String>;
185
203
  route: typeof S.String;
186
204
  handler: typeof S.String;
187
205
  }>, never>>>>;
188
- triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
206
+ triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
189
207
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
190
208
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
191
209
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -207,9 +225,12 @@ export declare const FunctionManifestSchema: S.Struct<{
207
225
  }>>;
208
226
  }>>, S.mutable<S.Struct<{
209
227
  type: S.Literal<[TriggerKind.Email]>;
228
+ }>>, S.mutable<S.Struct<{
229
+ type: S.Literal<[TriggerKind.Queue]>;
230
+ queue: S.refine<string, S.Schema<string, string, never>>;
210
231
  }>>]>>;
211
232
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
212
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
233
+ }, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
213
234
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
214
235
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
215
236
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -231,6 +252,9 @@ export declare const FunctionManifestSchema: S.Struct<{
231
252
  }>>;
232
253
  }>>, S.mutable<S.Struct<{
233
254
  type: S.Literal<[TriggerKind.Email]>;
255
+ }>>, S.mutable<S.Struct<{
256
+ type: S.Literal<[TriggerKind.Queue]>;
257
+ queue: S.refine<string, S.Schema<string, string, never>>;
234
258
  }>>]>>;
235
259
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
236
260
  }>, never>>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,E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AC,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;KAQxB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAahC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9E;;GAEG;AACH,qBAAa,eAAgB,SAAQ,oBAGL;CAAG;;;;;;;;;;;;AAEnC;;;GAGG;AAEH,qBAAa,WAAY,SAAQ,gBAQ/B;CAAG;AAEL;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,iDAAiC,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.7.5-labs.e27f9b9",
3
+ "version": "0.7.5-labs.f400bbc",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
7
  "license": "MIT",
8
8
  "author": "info@dxos.org",
9
9
  "sideEffects": true,
10
+ "type": "module",
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": "./dist/lib/node-esm/index.mjs"
15
16
  },
17
+ "./bundler": {
18
+ "types": "./dist/types/src/bundler/index.d.ts",
19
+ "browser": "./dist/lib/browser/bundler/index.mjs",
20
+ "node": "./dist/lib/node-esm/bundler/index.mjs"
21
+ },
16
22
  "./edge": {
17
23
  "types": "./dist/types/src/edge/index.d.ts",
18
24
  "browser": "./dist/lib/browser/edge/index.mjs",
@@ -32,11 +38,17 @@
32
38
  "types": "dist/types/src/index.d.ts",
33
39
  "typesVersions": {
34
40
  "*": {
41
+ "bundler": [
42
+ "dist/types/src/bundler/index.d.ts"
43
+ ],
44
+ "edge": [
45
+ "dist/types/src/edge/index.d.ts"
46
+ ],
35
47
  "testing": [
36
48
  "dist/types/src/testing/index.d.ts"
37
49
  ],
38
50
  "types": [
39
- "dist/types/src/types.d.ts"
51
+ "dist/types/src/types/index.d.ts"
40
52
  ]
41
53
  }
42
54
  },
@@ -50,30 +62,32 @@
50
62
  "@preact/signals-core": "^1.6.0",
51
63
  "cron": "^3.1.6",
52
64
  "effect": "^3.12.3",
65
+ "esbuild-wasm": "^0.16.14",
53
66
  "express": "^4.19.2",
54
67
  "get-port-please": "^3.1.1",
55
68
  "iso-did": "^1.6.0",
56
69
  "ws": "^8.14.2",
57
- "@dxos/async": "0.7.5-labs.e27f9b9",
58
- "@dxos/client": "0.7.5-labs.e27f9b9",
59
- "@dxos/echo-db": "0.7.5-labs.e27f9b9",
60
- "@dxos/context": "0.7.5-labs.e27f9b9",
61
- "@dxos/echo-protocol": "0.7.5-labs.e27f9b9",
62
- "@dxos/echo-schema": "0.7.5-labs.e27f9b9",
63
- "@dxos/invariant": "0.7.5-labs.e27f9b9",
64
- "@dxos/live-object": "0.7.5-labs.e27f9b9",
65
- "@dxos/edge-client": "0.7.5-labs.e27f9b9",
66
- "@dxos/log": "0.7.5-labs.e27f9b9",
67
- "@dxos/node-std": "0.7.5-labs.e27f9b9",
68
- "@dxos/schema": "0.7.5-labs.e27f9b9",
69
- "@dxos/protocols": "0.7.5-labs.e27f9b9",
70
- "@dxos/keys": "0.7.5-labs.e27f9b9",
71
- "@dxos/util": "0.7.5-labs.e27f9b9"
70
+ "@dxos/async": "0.7.5-labs.f400bbc",
71
+ "@dxos/context": "0.7.5-labs.f400bbc",
72
+ "@dxos/client": "0.7.5-labs.f400bbc",
73
+ "@dxos/echo-db": "0.7.5-labs.f400bbc",
74
+ "@dxos/echo-protocol": "0.7.5-labs.f400bbc",
75
+ "@dxos/echo-schema": "0.7.5-labs.f400bbc",
76
+ "@dxos/crypto": "0.7.5-labs.f400bbc",
77
+ "@dxos/edge-client": "0.7.5-labs.f400bbc",
78
+ "@dxos/invariant": "0.7.5-labs.f400bbc",
79
+ "@dxos/keys": "0.7.5-labs.f400bbc",
80
+ "@dxos/live-object": "0.7.5-labs.f400bbc",
81
+ "@dxos/log": "0.7.5-labs.f400bbc",
82
+ "@dxos/node-std": "0.7.5-labs.f400bbc",
83
+ "@dxos/schema": "0.7.5-labs.f400bbc",
84
+ "@dxos/protocols": "0.7.5-labs.f400bbc",
85
+ "@dxos/util": "0.7.5-labs.f400bbc"
72
86
  },
73
87
  "devDependencies": {
74
88
  "@types/express": "^4.17.17",
75
89
  "@types/ws": "^7.4.0",
76
- "@dxos/agent": "0.7.5-labs.e27f9b9"
90
+ "@dxos/agent": "0.7.5-labs.f400bbc"
77
91
  },
78
92
  "publishConfig": {
79
93
  "access": "public"
@@ -0,0 +1,59 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
+ import { 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
+ expect(result.bundle).to.exist;
24
+ expect(result.error).to.not.exist;
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
+ expect(result.bundle).to.exist;
37
+ expect(result.error).to.not.exist;
38
+ });
39
+
40
+ // TODO(dmaretskyi): Flaky on CI: https://cloud.nx.app/runs/Hjcifa8Ccq/task/plugin-script%3Atest
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
+ expect(result.bundle).to.exist;
50
+ expect(result.error).to.not.exist;
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
+ expect(result.bundle).to.not.exist;
57
+ expect(result.error).to.exist;
58
+ });
59
+ });
@@ -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';
package/src/handler.ts CHANGED
@@ -2,13 +2,17 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema as S } from '@effect/schema';
5
+ import { Schema as S } from '@effect/schema';
6
+ import { type Effect } from 'effect';
6
7
 
7
8
  import { type Client, PublicKey } from '@dxos/client';
8
9
  import { type Space, type SpaceId } from '@dxos/client/echo';
9
- import type { CoreDatabase, ReactiveEchoObject } from '@dxos/echo-db';
10
+ import type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';
11
+ import { type HasId } from '@dxos/echo-schema';
12
+ import { type DXN } from '@dxos/keys';
10
13
  import { log } from '@dxos/log';
11
- import { nonNullable } from '@dxos/util';
14
+ import { type QueryResult } from '@dxos/protocols';
15
+ import { isNonNullable } from '@dxos/util';
12
16
 
13
17
  // TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.
14
18
  // https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html
@@ -18,15 +22,14 @@ import { nonNullable } from '@dxos/util';
18
22
  /**
19
23
  * Function handler.
20
24
  */
21
- export type FunctionHandler<TData = {}, TMeta = {}> = (params: {
25
+ export type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {
22
26
  context: FunctionContext;
23
27
  event: FunctionEvent<TData, TMeta>;
24
-
25
28
  /**
26
29
  * @deprecated
27
30
  */
28
31
  response: FunctionResponse;
29
- }) => Promise<Response | FunctionResponse | void>;
32
+ }) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;
30
33
 
31
34
  /**
32
35
  * Function context.
@@ -84,17 +87,61 @@ export type FunctionResponse = {
84
87
  // API.
85
88
  //
86
89
 
90
+ // TODO(dmaretskyi): Temporary API to get the queues working.
91
+ // TODO(dmaretskyi): To be replaced with integrating queues into echo.
92
+ export interface QueuesAPI {
93
+ queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;
94
+ insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;
95
+ }
96
+
87
97
  /**
88
98
  * Space interface available to functions.
89
99
  */
90
100
  export interface SpaceAPI {
91
101
  get id(): SpaceId;
102
+ /**
103
+ * @deprecated
104
+ */
92
105
  get crud(): CoreDatabase;
106
+ get db(): EchoDatabase;
107
+ // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);
108
+ get queues(): QueuesAPI;
93
109
  }
94
110
 
111
+ // TODO(wittjosiah): Fix this.
95
112
  const __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {
96
- // eslint-disable-next-line unused-imports/no-unused-vars
97
- const y: SpaceAPI = {} as Space;
113
+ // const _: SpaceAPI = {} as Space;
114
+ };
115
+
116
+ export type FunctionDefinition = {
117
+ description?: string;
118
+ inputSchema: S.Schema.AnyNoContext;
119
+ outputSchema?: S.Schema.AnyNoContext;
120
+ handler: FunctionHandler<any>;
121
+ };
122
+
123
+ export type DefineFunctionParams<T, O = any> = {
124
+ description?: string;
125
+ inputSchema: S.Schema<T, any>;
126
+ outputSchema?: S.Schema<O, any>;
127
+ handler: FunctionHandler<T, any, O>;
128
+ };
129
+
130
+ // TODO(dmaretskyi): Bind input type to function handler.
131
+ export const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {
132
+ if (!S.isSchema(params.inputSchema)) {
133
+ throw new Error('Input schema must be a valid schema');
134
+ }
135
+ if (typeof params.handler !== 'function') {
136
+ throw new Error('Handler must be a function');
137
+ }
138
+
139
+ return {
140
+ description: params.description,
141
+ inputSchema: params.inputSchema,
142
+ outputSchema: params.outputSchema ?? S.Any,
143
+ handler: params.handler,
144
+ };
98
145
  };
99
146
 
100
147
  //
@@ -136,7 +183,9 @@ export const subscriptionHandler = <TMeta>(
136
183
 
137
184
  registerTypes(space, types);
138
185
  const objects = space
139
- ? data.objects?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable)
186
+ ? data.objects
187
+ ?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id))
188
+ .filter(isNonNullable)
140
189
  : [];
141
190
 
142
191
  if (!!data.spaceKey && !space) {