@dxos/functions 0.7.5-main.9d26e3a → 0.7.5-main.b19bfc8

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 (71) 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-BCNGUHHW.mjs → chunk-JNWHUD6Z.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-PKOLPTSC.mjs → chunk-PI2DP37S.mjs} +17 -11
  5. package/dist/lib/browser/chunk-PI2DP37S.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-B3FGASHJ.mjs → chunk-YJEIETRB.mjs} +6 -3
  7. package/dist/lib/browser/{chunk-B3FGASHJ.mjs.map → chunk-YJEIETRB.mjs.map} +3 -3
  8. package/dist/lib/browser/edge/index.mjs +1 -1
  9. package/dist/lib/browser/index.mjs +24 -10
  10. package/dist/lib/browser/index.mjs.map +3 -3
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/testing/index.mjs +2 -2
  13. package/dist/lib/browser/types/index.mjs +1 -3
  14. package/dist/lib/node/bundler/index.cjs +261 -0
  15. package/dist/lib/node/bundler/index.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-UHWSNERM.cjs → chunk-2ASAZ4AS.cjs} +15 -15
  17. package/dist/lib/node/{chunk-ZDG466QT.cjs → chunk-MZMHE4DC.cjs} +9 -6
  18. package/dist/lib/node/{chunk-ZDG466QT.cjs.map → chunk-MZMHE4DC.cjs.map} +3 -3
  19. package/dist/lib/node/{chunk-RYEY2RR2.cjs → chunk-PGFJYL6Q.cjs} +20 -15
  20. package/dist/lib/node/chunk-PGFJYL6Q.cjs.map +7 -0
  21. package/dist/lib/node/edge/index.cjs +8 -8
  22. package/dist/lib/node/edge/index.cjs.map +1 -1
  23. package/dist/lib/node/index.cjs +44 -29
  24. package/dist/lib/node/index.cjs.map +3 -3
  25. package/dist/lib/node/meta.json +1 -1
  26. package/dist/lib/node/testing/index.cjs +7 -7
  27. package/dist/lib/node/types/index.cjs +10 -12
  28. package/dist/lib/node/types/index.cjs.map +2 -2
  29. package/dist/lib/node-esm/bundler/index.mjs +239 -0
  30. package/dist/lib/node-esm/bundler/index.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-2UWB6JYW.mjs → chunk-IOAKDIT3.mjs} +17 -11
  32. package/dist/lib/node-esm/chunk-IOAKDIT3.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-TPGS4PIH.mjs → chunk-LNBGGB6Z.mjs} +2 -2
  34. package/dist/lib/node-esm/{chunk-CN74WOTT.mjs → chunk-T2KBXTMR.mjs} +6 -3
  35. package/dist/lib/node-esm/{chunk-CN74WOTT.mjs.map → chunk-T2KBXTMR.mjs.map} +3 -3
  36. package/dist/lib/node-esm/edge/index.mjs +1 -1
  37. package/dist/lib/node-esm/index.mjs +24 -10
  38. package/dist/lib/node-esm/index.mjs.map +3 -3
  39. package/dist/lib/node-esm/meta.json +1 -1
  40. package/dist/lib/node-esm/testing/index.mjs +2 -2
  41. package/dist/lib/node-esm/types/index.mjs +1 -3
  42. package/dist/types/src/bundler/bundler.d.ts +51 -0
  43. package/dist/types/src/bundler/bundler.d.ts.map +1 -0
  44. package/dist/types/src/bundler/bundler.test.d.ts +2 -0
  45. package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
  46. package/dist/types/src/bundler/index.d.ts +2 -0
  47. package/dist/types/src/bundler/index.d.ts.map +1 -0
  48. package/dist/types/src/edge/functions.d.ts.map +1 -1
  49. package/dist/types/src/handler.d.ts +29 -4
  50. package/dist/types/src/handler.d.ts.map +1 -1
  51. package/dist/types/src/testing/types.d.ts +2 -2
  52. package/dist/types/src/types/schema.d.ts +20 -23
  53. package/dist/types/src/types/schema.d.ts.map +1 -1
  54. package/dist/types/src/types/types.d.ts +50 -9
  55. package/dist/types/src/types/types.d.ts.map +1 -1
  56. package/dist/types/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +33 -19
  58. package/src/bundler/bundler.test.ts +59 -0
  59. package/src/bundler/bundler.ts +264 -0
  60. package/src/bundler/index.ts +5 -0
  61. package/src/edge/functions.ts +5 -1
  62. package/src/handler.ts +58 -9
  63. package/src/trigger/trigger-registry.test.ts +3 -1
  64. package/src/types/schema.ts +4 -5
  65. package/src/types/types.ts +18 -1
  66. package/dist/lib/browser/chunk-PKOLPTSC.mjs.map +0 -7
  67. package/dist/lib/node/chunk-RYEY2RR2.cjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-2UWB6JYW.mjs.map +0 -7
  69. /package/dist/lib/browser/{chunk-BCNGUHHW.mjs.map → chunk-JNWHUD6Z.mjs.map} +0 -0
  70. /package/dist/lib/node/{chunk-UHWSNERM.cjs.map → chunk-2ASAZ4AS.cjs.map} +0 -0
  71. /package/dist/lib/node-esm/{chunk-TPGS4PIH.mjs.map → chunk-LNBGGB6Z.mjs.map} +0 -0
@@ -7,7 +7,9 @@ import { S } from '@dxos/echo-schema';
7
7
  export declare enum TriggerKind {
8
8
  Timer = "timer",
9
9
  Webhook = "webhook",
10
- Subscription = "subscription"
10
+ Subscription = "subscription",
11
+ Email = "email",
12
+ Queue = "queue"
11
13
  }
12
14
  /**
13
15
  * Cron timer.
@@ -17,6 +19,15 @@ declare const TimerTriggerSchema: S.mutable<S.Struct<{
17
19
  cron: S.SchemaClass<string, string, never>;
18
20
  }>>;
19
21
  export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
22
+ declare const EmailTriggerSchema: S.mutable<S.Struct<{
23
+ type: S.Literal<[TriggerKind.Email]>;
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>;
20
31
  /**
21
32
  * Webhook.
22
33
  */
@@ -61,6 +72,11 @@ export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
61
72
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
62
73
  delay: S.optional<S.SchemaClass<number, number, never>>;
63
74
  }>>;
75
+ }>>, S.mutable<S.Struct<{
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>>;
64
80
  }>>]>;
65
81
  export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
66
82
  /**
@@ -86,11 +102,16 @@ export declare const FunctionTriggerSchema: S.Struct<{
86
102
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
87
103
  delay: S.optional<S.SchemaClass<number, number, never>>;
88
104
  }>>;
105
+ }>>, S.mutable<S.Struct<{
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>>;
89
110
  }>>]>>;
90
111
  meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
91
112
  }>;
92
113
  export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
93
- 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<{
94
115
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
95
116
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
96
117
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -110,9 +131,14 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
110
131
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
111
132
  delay: S.optional<S.SchemaClass<number, number, never>>;
112
133
  }>>;
134
+ }>>, S.mutable<S.Struct<{
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>>;
113
139
  }>>]>>;
114
140
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
115
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
141
+ }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
116
142
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
117
143
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
118
144
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -132,6 +158,11 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
132
158
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
133
159
  delay: S.optional<S.SchemaClass<number, number, never>>;
134
160
  }>>;
161
+ }>>, S.mutable<S.Struct<{
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>>;
135
166
  }>>]>>;
136
167
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
137
168
  }>>;
@@ -140,12 +171,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
140
171
  */
141
172
  export declare class FunctionTrigger extends FunctionTrigger_base {
142
173
  }
143
- 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<{
144
175
  uri: typeof S.String;
145
176
  description: S.optional<typeof S.String>;
146
177
  route: typeof S.String;
147
178
  handler: typeof S.String;
148
- }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
179
+ }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
149
180
  uri: typeof S.String;
150
181
  description: S.optional<typeof S.String>;
151
182
  route: typeof S.String;
@@ -161,18 +192,18 @@ export declare class FunctionDef extends FunctionDef_base {
161
192
  * Function manifest file.
162
193
  */
163
194
  export declare const FunctionManifestSchema: S.Struct<{
164
- 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<{
165
196
  uri: typeof S.String;
166
197
  description: S.optional<typeof S.String>;
167
198
  route: typeof S.String;
168
199
  handler: typeof S.String;
169
- }, 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<{
170
201
  uri: typeof S.String;
171
202
  description: S.optional<typeof S.String>;
172
203
  route: typeof S.String;
173
204
  handler: typeof S.String;
174
205
  }>, never>>>>;
175
- 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<{
176
207
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
177
208
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
178
209
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -192,9 +223,14 @@ export declare const FunctionManifestSchema: S.Struct<{
192
223
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
193
224
  delay: S.optional<S.SchemaClass<number, number, never>>;
194
225
  }>>;
226
+ }>>, S.mutable<S.Struct<{
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>>;
195
231
  }>>]>>;
196
232
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
197
- }, 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<{
198
234
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
199
235
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
200
236
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -214,6 +250,11 @@ export declare const FunctionManifestSchema: S.Struct<{
214
250
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
215
251
  delay: S.optional<S.SchemaClass<number, number, never>>;
216
252
  }>>;
253
+ }>>, S.mutable<S.Struct<{
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>>;
217
258
  }>>]>>;
218
259
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
219
260
  }>, never>>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAuC,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAExF;;;;GAIG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,YAAY,iBA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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"}
@@ -1 +1 @@
1
- {"version":"5.7.2"}
1
+ {"version":"5.7.3"}
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.7.5-main.9d26e3a",
3
+ "version": "0.7.5-main.b19bfc8",
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
  },
@@ -49,31 +61,33 @@
49
61
  "@effect/schema": "^0.75.5",
50
62
  "@preact/signals-core": "^1.6.0",
51
63
  "cron": "^3.1.6",
52
- "effect": "^3.12.1",
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-main.9d26e3a",
58
- "@dxos/client": "0.7.5-main.9d26e3a",
59
- "@dxos/echo-db": "0.7.5-main.9d26e3a",
60
- "@dxos/echo-protocol": "0.7.5-main.9d26e3a",
61
- "@dxos/edge-client": "0.7.5-main.9d26e3a",
62
- "@dxos/echo-schema": "0.7.5-main.9d26e3a",
63
- "@dxos/context": "0.7.5-main.9d26e3a",
64
- "@dxos/invariant": "0.7.5-main.9d26e3a",
65
- "@dxos/keys": "0.7.5-main.9d26e3a",
66
- "@dxos/live-object": "0.7.5-main.9d26e3a",
67
- "@dxos/node-std": "0.7.5-main.9d26e3a",
68
- "@dxos/log": "0.7.5-main.9d26e3a",
69
- "@dxos/protocols": "0.7.5-main.9d26e3a",
70
- "@dxos/schema": "0.7.5-main.9d26e3a",
71
- "@dxos/util": "0.7.5-main.9d26e3a"
70
+ "@dxos/async": "0.7.5-main.b19bfc8",
71
+ "@dxos/context": "0.7.5-main.b19bfc8",
72
+ "@dxos/client": "0.7.5-main.b19bfc8",
73
+ "@dxos/crypto": "0.7.5-main.b19bfc8",
74
+ "@dxos/echo-protocol": "0.7.5-main.b19bfc8",
75
+ "@dxos/echo-schema": "0.7.5-main.b19bfc8",
76
+ "@dxos/echo-db": "0.7.5-main.b19bfc8",
77
+ "@dxos/edge-client": "0.7.5-main.b19bfc8",
78
+ "@dxos/invariant": "0.7.5-main.b19bfc8",
79
+ "@dxos/live-object": "0.7.5-main.b19bfc8",
80
+ "@dxos/log": "0.7.5-main.b19bfc8",
81
+ "@dxos/keys": "0.7.5-main.b19bfc8",
82
+ "@dxos/node-std": "0.7.5-main.b19bfc8",
83
+ "@dxos/protocols": "0.7.5-main.b19bfc8",
84
+ "@dxos/schema": "0.7.5-main.b19bfc8",
85
+ "@dxos/util": "0.7.5-main.b19bfc8"
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-main.9d26e3a"
90
+ "@dxos/agent": "0.7.5-main.b19bfc8"
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';
@@ -75,10 +75,14 @@ export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options:
75
75
  const url = new URL(`./${relativeUrl}`, baseUrl.toString());
76
76
  options.spaceId && url.searchParams.set('spaceId', options.spaceId);
77
77
  options.subjectId && url.searchParams.set('subjectId', options.subjectId);
78
- url.protocol = 'https';
78
+ url.protocol = isSecure(url.protocol) ? 'https' : 'http';
79
79
  return url.toString();
80
80
  };
81
81
 
82
+ const isSecure = (protocol: string) => {
83
+ return protocol === 'https:' || protocol === 'wss:';
84
+ };
85
+
82
86
  const createEdgeIdentity = (client: Client): EdgeIdentity => {
83
87
  const identity = client.halo.identity.get();
84
88
  const device = client.halo.device;