@dxos/functions 0.8.4-main.84f28bd → 0.8.4-main.ae835ea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/lib/browser/bundler/index.mjs +43 -34
  2. package/dist/lib/browser/bundler/index.mjs.map +3 -3
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-M6EXIREF.mjs +610 -0
  6. package/dist/lib/browser/chunk-M6EXIREF.mjs.map +7 -0
  7. package/dist/lib/browser/edge/index.mjs +22 -8
  8. package/dist/lib/browser/edge/index.mjs.map +3 -3
  9. package/dist/lib/browser/index.mjs +1106 -252
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/testing/index.mjs +94 -42
  13. package/dist/lib/browser/testing/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/bundler/index.mjs +42 -34
  15. package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
  16. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  17. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  18. package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +612 -0
  19. package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +7 -0
  20. package/dist/lib/node-esm/edge/index.mjs +21 -8
  21. package/dist/lib/node-esm/edge/index.mjs.map +3 -3
  22. package/dist/lib/node-esm/index.mjs +1106 -252
  23. package/dist/lib/node-esm/index.mjs.map +4 -4
  24. package/dist/lib/node-esm/meta.json +1 -1
  25. package/dist/lib/node-esm/testing/index.mjs +94 -42
  26. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  27. package/dist/types/src/bundler/bundler.d.ts +11 -12
  28. package/dist/types/src/bundler/bundler.d.ts.map +1 -1
  29. package/dist/types/src/e2e/deploy.test.d.ts +2 -0
  30. package/dist/types/src/e2e/deploy.test.d.ts.map +1 -0
  31. package/dist/types/src/edge/functions.d.ts +4 -3
  32. package/dist/types/src/edge/functions.d.ts.map +1 -1
  33. package/dist/types/src/errors.d.ts +137 -0
  34. package/dist/types/src/errors.d.ts.map +1 -0
  35. package/dist/types/src/example/fib.d.ts +7 -0
  36. package/dist/types/src/example/fib.d.ts.map +1 -0
  37. package/dist/types/src/example/forex-effect.d.ts +3 -0
  38. package/dist/types/src/example/forex-effect.d.ts.map +1 -0
  39. package/dist/types/src/example/index.d.ts +12 -0
  40. package/dist/types/src/example/index.d.ts.map +1 -0
  41. package/dist/types/src/example/reply.d.ts +3 -0
  42. package/dist/types/src/example/reply.d.ts.map +1 -0
  43. package/dist/types/src/example/sleep.d.ts +5 -0
  44. package/dist/types/src/example/sleep.d.ts.map +1 -0
  45. package/dist/types/src/executor/executor.d.ts +7 -1
  46. package/dist/types/src/executor/executor.d.ts.map +1 -1
  47. package/dist/types/src/handler.d.ts +54 -13
  48. package/dist/types/src/handler.d.ts.map +1 -1
  49. package/dist/types/src/index.d.ts +5 -3
  50. package/dist/types/src/index.d.ts.map +1 -1
  51. package/dist/types/src/services/credentials.d.ts +21 -3
  52. package/dist/types/src/services/credentials.d.ts.map +1 -1
  53. package/dist/types/src/services/database.d.ts +58 -6
  54. package/dist/types/src/services/database.d.ts.map +1 -1
  55. package/dist/types/src/services/event-logger.d.ts +68 -30
  56. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  57. package/dist/types/src/services/function-invocation-service.d.ts +28 -0
  58. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  59. package/dist/types/src/services/function-invocation-service.test.d.ts +2 -0
  60. package/dist/types/src/services/function-invocation-service.test.d.ts.map +1 -0
  61. package/dist/types/src/services/index.d.ts +5 -5
  62. package/dist/types/src/services/index.d.ts.map +1 -1
  63. package/dist/types/src/services/local-function-execution.d.ts +34 -0
  64. package/dist/types/src/services/local-function-execution.d.ts.map +1 -0
  65. package/dist/types/src/services/queues.d.ts +33 -4
  66. package/dist/types/src/services/queues.d.ts.map +1 -1
  67. package/dist/types/src/services/remote-function-execution-service.d.ts +22 -0
  68. package/dist/types/src/services/remote-function-execution-service.d.ts.map +1 -0
  69. package/dist/types/src/services/service-container.d.ts +29 -18
  70. package/dist/types/src/services/service-container.d.ts.map +1 -1
  71. package/dist/types/src/services/service-registry.d.ts +31 -0
  72. package/dist/types/src/services/service-registry.d.ts.map +1 -0
  73. package/dist/types/src/services/service-registry.test.d.ts +2 -0
  74. package/dist/types/src/services/service-registry.test.d.ts.map +1 -0
  75. package/dist/types/src/services/tracing.d.ts +48 -4
  76. package/dist/types/src/services/tracing.d.ts.map +1 -1
  77. package/dist/types/src/testing/index.d.ts +1 -0
  78. package/dist/types/src/testing/index.d.ts.map +1 -1
  79. package/dist/types/src/testing/layer.d.ts +18 -0
  80. package/dist/types/src/testing/layer.d.ts.map +1 -0
  81. package/dist/types/src/testing/logger.d.ts +4 -4
  82. package/dist/types/src/testing/logger.d.ts.map +1 -1
  83. package/dist/types/src/testing/persist-database.test.d.ts +2 -0
  84. package/dist/types/src/testing/persist-database.test.d.ts.map +1 -0
  85. package/dist/types/src/testing/services.d.ts +8 -20
  86. package/dist/types/src/testing/services.d.ts.map +1 -1
  87. package/dist/types/src/trace.d.ts +21 -23
  88. package/dist/types/src/trace.d.ts.map +1 -1
  89. package/dist/types/src/translations.d.ts +2 -2
  90. package/dist/types/src/translations.d.ts.map +1 -1
  91. package/dist/types/src/triggers/index.d.ts +4 -0
  92. package/dist/types/src/triggers/index.d.ts.map +1 -0
  93. package/dist/types/src/triggers/input-builder.d.ts +3 -0
  94. package/dist/types/src/triggers/input-builder.d.ts.map +1 -0
  95. package/dist/types/src/triggers/invocation-tracer.d.ts +37 -0
  96. package/dist/types/src/triggers/invocation-tracer.d.ts.map +1 -0
  97. package/dist/types/src/triggers/trigger-dispatcher.d.ts +78 -0
  98. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +1 -0
  99. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +2 -0
  100. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +1 -0
  101. package/dist/types/src/triggers/trigger-state-store.d.ts +28 -0
  102. package/dist/types/src/triggers/trigger-state-store.d.ts.map +1 -0
  103. package/dist/types/src/types/Function.d.ts +47 -0
  104. package/dist/types/src/types/Function.d.ts.map +1 -0
  105. package/dist/types/src/types/Script.d.ts +28 -0
  106. package/dist/types/src/types/Script.d.ts.map +1 -0
  107. package/dist/types/src/types/Trigger.d.ts +139 -0
  108. package/dist/types/src/types/Trigger.d.ts.map +1 -0
  109. package/dist/types/src/types/TriggerEvent.d.ts +44 -0
  110. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
  111. package/dist/types/src/types/index.d.ts +5 -0
  112. package/dist/types/src/types/index.d.ts.map +1 -0
  113. package/dist/types/src/url.d.ts +11 -7
  114. package/dist/types/src/url.d.ts.map +1 -1
  115. package/dist/types/tsconfig.tsbuildinfo +1 -1
  116. package/package.json +37 -42
  117. package/src/bundler/bundler.test.ts +8 -9
  118. package/src/bundler/bundler.ts +38 -35
  119. package/src/e2e/deploy.test.ts +69 -0
  120. package/src/edge/functions.ts +9 -6
  121. package/src/errors.ts +21 -0
  122. package/src/example/fib.ts +32 -0
  123. package/src/example/forex-effect.ts +40 -0
  124. package/src/example/index.ts +13 -0
  125. package/src/example/reply.ts +21 -0
  126. package/src/example/sleep.ts +24 -0
  127. package/src/executor/executor.ts +14 -10
  128. package/src/handler.ts +139 -26
  129. package/src/index.ts +5 -5
  130. package/src/services/credentials.ts +93 -4
  131. package/src/services/database.ts +145 -20
  132. package/src/services/event-logger.ts +71 -37
  133. package/src/services/function-invocation-service.test.ts +81 -0
  134. package/src/services/function-invocation-service.ts +84 -0
  135. package/src/services/index.ts +5 -5
  136. package/src/services/local-function-execution.ts +153 -0
  137. package/src/services/queues.ts +50 -8
  138. package/src/services/remote-function-execution-service.ts +63 -0
  139. package/src/services/service-container.ts +46 -58
  140. package/src/services/service-registry.test.ts +45 -0
  141. package/src/services/service-registry.ts +63 -0
  142. package/src/services/tracing.ts +122 -6
  143. package/src/testing/index.ts +1 -0
  144. package/src/testing/layer.ts +114 -0
  145. package/src/testing/logger.ts +5 -4
  146. package/src/testing/persist-database.test.ts +87 -0
  147. package/src/testing/services.ts +12 -71
  148. package/src/trace.ts +20 -22
  149. package/src/translations.ts +2 -2
  150. package/src/triggers/index.ts +7 -0
  151. package/src/triggers/input-builder.ts +35 -0
  152. package/src/triggers/invocation-tracer.ts +101 -0
  153. package/src/triggers/trigger-dispatcher.test.ts +664 -0
  154. package/src/triggers/trigger-dispatcher.ts +521 -0
  155. package/src/triggers/trigger-state-store.ts +61 -0
  156. package/src/types/Function.ts +51 -0
  157. package/src/types/Script.ts +33 -0
  158. package/src/types/Trigger.ts +139 -0
  159. package/src/types/TriggerEvent.ts +62 -0
  160. package/src/types/index.ts +8 -0
  161. package/src/url.ts +14 -11
  162. package/dist/lib/browser/chunk-54U464M4.mjs +0 -360
  163. package/dist/lib/browser/chunk-54U464M4.mjs.map +0 -7
  164. package/dist/lib/node-esm/chunk-XDSX35BS.mjs +0 -362
  165. package/dist/lib/node-esm/chunk-XDSX35BS.mjs.map +0 -7
  166. package/dist/types/src/schema.d.ts +0 -38
  167. package/dist/types/src/schema.d.ts.map +0 -1
  168. package/dist/types/src/services/ai.d.ts +0 -12
  169. package/dist/types/src/services/ai.d.ts.map +0 -1
  170. package/dist/types/src/services/function-call-service.d.ts +0 -16
  171. package/dist/types/src/services/function-call-service.d.ts.map +0 -1
  172. package/dist/types/src/services/tool-resolver.d.ts +0 -14
  173. package/dist/types/src/services/tool-resolver.d.ts.map +0 -1
  174. package/dist/types/src/types.d.ts +0 -411
  175. package/dist/types/src/types.d.ts.map +0 -1
  176. package/src/schema.ts +0 -57
  177. package/src/services/ai.ts +0 -32
  178. package/src/services/function-call-service.ts +0 -64
  179. package/src/services/tool-resolver.ts +0 -31
  180. package/src/types.ts +0 -211
@@ -1,6 +1,12 @@
1
+ import "../chunk-J5LGTIGS.mjs";
2
+
1
3
  // src/bundler/bundler.ts
2
- import { FetchHttpClient, HttpClient } from "@effect/platform";
3
- import { Duration, Effect, pipe, Schedule } from "effect";
4
+ import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
5
+ import * as HttpClient from "@effect/platform/HttpClient";
6
+ import * as Duration from "effect/Duration";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Function from "effect/Function";
9
+ import * as Schedule from "effect/Schedule";
4
10
  import { build, initialize } from "esbuild-wasm";
5
11
  import { subtleCrypto } from "@dxos/crypto";
6
12
  import { runAndForwardErrors } from "@dxos/effect";
@@ -14,22 +20,17 @@ var initializeBundler = async (options) => {
14
20
  }));
15
21
  };
16
22
  var Bundler = class {
23
+ _options;
17
24
  constructor(_options) {
18
25
  this._options = _options;
19
26
  }
20
- async bundle({ path, source }) {
27
+ async bundle({ source }) {
21
28
  const { sandboxedModules: providedModules, ...options } = this._options;
22
- const createResult = async (result) => {
23
- return {
24
- timestamp: Date.now(),
25
- sourceHash: source ? Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source))) : void 0,
26
- ...result
27
- };
28
- };
29
+ const sourceHash = Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source)));
29
30
  if (this._options.platform === "browser") {
30
31
  invariant(initialized, "Compiler not initialized.", {
31
32
  F: __dxlog_file,
32
- L: 73,
33
+ L: 70,
33
34
  S: this,
34
35
  A: [
35
36
  "initialized",
@@ -48,9 +49,10 @@ var Bundler = class {
48
49
  ],
49
50
  metafile: true,
50
51
  write: false,
51
- entryPoints: [
52
- path ?? "memory:main.tsx"
53
- ],
52
+ entryPoints: {
53
+ // Gets mapped to `userFunc.js` by esbuild.
54
+ userFunc: "memory:main.tsx"
55
+ },
54
56
  bundle: true,
55
57
  format: "esm",
56
58
  plugins: [
@@ -59,15 +61,15 @@ var Bundler = class {
59
61
  setup: (build2) => {
60
62
  build2.onResolve({
61
63
  filter: /^\.\/runtime\.js$/
62
- }, ({ path: path2 }) => {
64
+ }, ({ path }) => {
63
65
  return {
64
- path: path2,
66
+ path,
65
67
  external: true
66
68
  };
67
69
  });
68
70
  build2.onResolve({
69
71
  filter: /^dxos:functions$/
70
- }, ({ path: path2 }) => {
72
+ }, ({ path }) => {
71
73
  return {
72
74
  path: "./runtime.js",
73
75
  external: true
@@ -75,17 +77,17 @@ var Bundler = class {
75
77
  });
76
78
  build2.onResolve({
77
79
  filter: /^memory:/
78
- }, ({ path: path2 }) => {
80
+ }, ({ path }) => {
79
81
  return {
80
- path: path2.split(":")[1],
82
+ path: path.split(":")[1],
81
83
  namespace: "memory"
82
84
  };
83
85
  });
84
86
  build2.onLoad({
85
87
  filter: /.*/,
86
88
  namespace: "memory"
87
- }, ({ path: path2 }) => {
88
- if (path2 === "main.tsx") {
89
+ }, ({ path }) => {
90
+ if (path === "main.tsx") {
89
91
  return {
90
92
  contents: source,
91
93
  loader: "tsx"
@@ -95,9 +97,9 @@ var Bundler = class {
95
97
  for (const module of providedModules) {
96
98
  build2.onResolve({
97
99
  filter: new RegExp(`^${module}$`)
98
- }, ({ path: path2 }) => {
100
+ }, ({ path }) => {
99
101
  return {
100
- path: path2,
102
+ path,
101
103
  namespace: "injected-module"
102
104
  };
103
105
  });
@@ -105,13 +107,13 @@ var Bundler = class {
105
107
  build2.onLoad({
106
108
  filter: /.*/,
107
109
  namespace: "injected-module"
108
- }, ({ path: path2 }) => {
109
- const namedImports = imports.find((entry) => entry.moduleIdentifier === path2)?.namedImports ?? [];
110
+ }, ({ path }) => {
111
+ const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
110
112
  return {
111
113
  contents: `
112
- const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}];
114
+ const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
113
115
  export { ${namedImports.join(",")} };
114
- export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}].default;
116
+ export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
115
117
  `,
116
118
  loader: "tsx"
117
119
  };
@@ -127,21 +129,28 @@ var Bundler = class {
127
129
  S: this,
128
130
  C: (f, a) => f(...a)
129
131
  });
130
- return await createResult({
132
+ const entryPoint = "userFunc.js";
133
+ return {
134
+ timestamp: Date.now(),
135
+ sourceHash,
131
136
  imports: this.analyzeImports(result),
137
+ entryPoint,
138
+ asset: result.outputFiles[0].contents,
132
139
  bundle: result.outputFiles[0].text
133
- });
140
+ };
134
141
  } catch (err) {
135
- return await createResult({
142
+ return {
143
+ timestamp: Date.now(),
144
+ sourceHash,
136
145
  error: err
137
- });
146
+ };
138
147
  }
139
148
  }
140
149
  // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
141
150
  analyzeImports(result) {
142
151
  invariant(result.outputFiles, void 0, {
143
152
  F: __dxlog_file,
144
- L: 150,
153
+ L: 155,
145
154
  S: this,
146
155
  A: [
147
156
  "result.outputFiles",
@@ -184,9 +193,9 @@ var Bundler = class {
184
193
  var IMPORT_REGEX = /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;
185
194
  var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
186
195
  var allMatches = (regex, str) => {
187
- regex.lastIndex = 0;
188
196
  let match;
189
197
  const matches = [];
198
+ regex.lastIndex = 0;
190
199
  while (match = regex.exec(str)) {
191
200
  matches.push(match);
192
201
  }
@@ -236,7 +245,7 @@ var httpPlugin = {
236
245
  contents: text,
237
246
  loader: "jsx"
238
247
  };
239
- }).pipe(Effect.retry(pipe(Schedule.exponential(Duration.millis(INITIAL_DELAY)), Schedule.jittered, Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)))), Effect.provide(FetchHttpClient.layer), runAndForwardErrors);
248
+ }).pipe(Effect.retry(Function.pipe(Schedule.exponential(Duration.millis(INITIAL_DELAY)), Schedule.jittered, Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)))), Effect.provide(FetchHttpClient.layer), runAndForwardErrors);
240
249
  });
241
250
  }
242
251
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/bundler/bundler.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { FetchHttpClient, HttpClient } from '@effect/platform';\nimport { Duration, Effect, pipe, Schedule } from 'effect';\nimport { type BuildOptions, type Loader, build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Path to the source file on the local file system.\n * If provided, the path will be used instead of the `source` code.\n */\n path?: string;\n\n /**\n * Source code to bundle.\n * Required if `path` is not provided.\n */\n source?: string;\n};\n\nexport type BundleResult = {\n timestamp: number;\n sourceHash?: Buffer;\n imports?: Import[];\n bundle?: string;\n error?: any;\n};\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ path, source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n\n const createResult = async (result?: Partial<BundleResult>) => {\n return {\n timestamp: Date.now(),\n sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,\n ...result,\n };\n };\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: [path ?? 'memory:main.tsx'],\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n return await createResult({\n imports: this.analyzeImports(result),\n bundle: result.outputFiles![0].text,\n });\n } catch (err) {\n return await createResult({ error: err });\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string): {\n defaultImportName: string;\n namedImports: string[];\n wildcardImportName: string;\n moduleIdentifier: string;\n quotes: string;\n }[] {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /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;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n regex.lastIndex = 0;\n\n let match;\n const matches = [];\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst MAX_RETRIES = 5;\nconst INITIAL_DELAY = 1_000;\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // 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.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n return Effect.gen(function* () {\n const response = yield* HttpClient.get(args.path);\n if (response.status !== 200) {\n throw new Error(`failed to fetch: ${response.status}`);\n }\n\n const text = yield* response.text;\n return { contents: text, loader: 'jsx' as Loader };\n }).pipe(\n Effect.retry(\n pipe(\n Schedule.exponential(Duration.millis(INITIAL_DELAY)),\n Schedule.jittered,\n Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),\n ),\n ),\n Effect.provide(FetchHttpClient.layer),\n runAndForwardErrors,\n );\n });\n },\n};\n"],
5
- "mappings": ";AAIA,SAASA,iBAAiBC,kBAAkB;AAC5C,SAASC,UAAUC,QAAQC,MAAMC,gBAAgB;AACjD,SAAyCC,OAAOC,kBAAiD;AAEjG,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAoCpB,IAAIC;AACG,IAAMC,oBAAoB,OAAOC,YAAAA;AACtC,SAAOF,gBAAgBL,WAAW;IAChCQ,SAASD,QAAQE;EACnB,CAAA;AACF;AAKO,IAAMC,UAAN,MAAMA;EACX,YAA6BC,UAA0B;SAA1BA,WAAAA;EAA2B;EAExD,MAAMC,OAAO,EAAEC,MAAMC,OAAM,GAA0C;AACnE,UAAM,EAAEC,kBAAkBC,iBAAiB,GAAGT,QAAAA,IAAY,KAAKI;AAE/D,UAAMM,eAAe,OAAOC,WAAAA;AAC1B,aAAO;QACLC,WAAWC,KAAKC,IAAG;QACnBC,YAAYR,SAASS,OAAOC,KAAK,MAAMvB,aAAawB,OAAO,WAAWF,OAAOC,KAAKV,MAAAA,CAAAA,CAAAA,IAAYY;QAC9F,GAAGR;MACL;IACF;AAEA,QAAI,KAAKP,SAASgB,aAAa,WAAW;AACxCxB,gBAAUE,aAAa,6BAAA;;;;;;;;;AACvB,YAAMA;IACR;AAEA,UAAMuB,UAAUd,SAASe,yBAAyBf,MAAAA,IAAU,CAAA;AAG5D,QAAI;AACF,YAAMI,SA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ACtC,WAAAA;AAGNA,IAAAA,OAAMuC,UAAU;MAAEC,QAAQ;IAAe,GAAG,CAACoD,UAAU;MACrD9E,MAAM8E,KAAK9E;MACX6B,WAAW;IACb,EAAA;AAKA3C,IAAAA,OAAMuC,UAAU;MAAEC,QAAQ;MAAMG,WAAW;IAAW,GAAG,CAACiD,UAAU;MAClE9E,MAAM,IAAI+E,IAAID,KAAK9E,MAAM8E,KAAKE,QAAQ,EAAEC,SAAQ;MAChDpD,WAAW;IACb,EAAA;AAIA3C,IAAAA,OAAM4C,OAAO;MAAEJ,QAAQ;MAAMG,WAAW;IAAW,GAAG,OAAOiD,SAAAA;AAC3D,aAAO/F,OAAOmG,IAAI,aAAA;AAChB,cAAMC,WAAW,OAAOtG,WAAWuG,IAAIN,KAAK9E,IAAI;AAChD,YAAImF,SAASE,WAAW,KAAK;AAC3B,gBAAM,IAAIC,MAAM,oBAAoBH,SAASE,MAAM,EAAE;QACvD;AAEA,cAAMxC,OAAO,OAAOsC,SAAStC;AAC7B,eAAO;UAAEd,UAAUc;UAAMb,QAAQ;QAAgB;MACnD,CAAA,EAAGhD,KACDD,OAAOwG,MACLvG,KACEC,SAASuG,YAAY1G,SAAS2G,OAAOZ,aAAAA,CAAAA,GACrC5F,SAASyG,UACTzG,SAAS0G,UAAU1G,SAAS2G,OAAOhB,cAAc,CAAA,CAAA,CAAA,CAAA,GAGrD7F,OAAO8G,QAAQjH,gBAAgBkH,KAAK,GACpCzG,mBAAAA;IAEJ,CAAA;EACF;AACF;",
6
- "names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "pipe", "Schedule", "build", "initialize", "subtleCrypto", "runAndForwardErrors", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "_options", "bundle", "path", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "digest", "undefined", "platform", "imports", "analyzeSourceFileImports", "conditions", "metafile", "write", "entryPoints", "format", "plugins", "name", "setup", "onResolve", "filter", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "analyzeImports", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "MAX_RETRIES", "INITIAL_DELAY", "args", "URL", "importer", "toString", "gen", "response", "get", "status", "Error", "retry", "exponential", "millis", "jittered", "intersect", "recurs", "provide", "layer"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport * as FetchHttpClient from '@effect/platform/FetchHttpClient';\nimport * as HttpClient from '@effect/platform/HttpClient';\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Schedule from 'effect/Schedule';\nimport { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Source code to bundle.\n */\n source: string;\n};\n\nexport type BundleResult =\n | {\n timestamp: number;\n sourceHash: Buffer;\n error: unknown;\n }\n | {\n timestamp: number;\n sourceHash: Buffer;\n imports: Import[];\n entryPoint: string;\n asset: Uint8Array;\n bundle: string;\n };\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: {\n // Gets mapped to `userFunc.js` by esbuild.\n userFunc: 'memory:main.tsx',\n },\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n const entryPoint = 'userFunc.js';\n return {\n timestamp: Date.now(),\n sourceHash,\n imports: this.analyzeImports(result),\n entryPoint,\n asset: result.outputFiles![0].contents,\n bundle: result.outputFiles![0].text,\n };\n } catch (err) {\n return { timestamp: Date.now(), sourceHash, error: err };\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string): {\n defaultImportName: string;\n namedImports: string[];\n wildcardImportName: string;\n moduleIdentifier: string;\n quotes: string;\n }[] {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /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;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n let match;\n const matches = [];\n regex.lastIndex = 0;\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst MAX_RETRIES = 5;\nconst INITIAL_DELAY = 1_000;\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // 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.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n return Effect.gen(function* () {\n const response = yield* HttpClient.get(args.path);\n if (response.status !== 200) {\n throw new Error(`failed to fetch: ${response.status}`);\n }\n\n const text = yield* response.text;\n return { contents: text, loader: 'jsx' as Loader };\n }).pipe(\n Effect.retry(\n Function.pipe(\n Schedule.exponential(Duration.millis(INITIAL_DELAY)),\n Schedule.jittered,\n Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),\n ),\n ),\n Effect.provide(FetchHttpClient.layer),\n runAndForwardErrors,\n );\n });\n },\n};\n"],
5
+ "mappings": ";;;AAIA,YAAYA,qBAAqB;AACjC,YAAYC,gBAAgB;AAC5B,YAAYC,cAAc;AAC1B,YAAYC,YAAY;AACxB,YAAYC,cAAc;AAC1B,YAAYC,cAAc;AAC1B,SAAwEC,OAAOC,kBAAkB;AAEjG,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAoCpB,IAAIC;AACG,IAAMC,oBAAoB,OAAOC,YAAAA;AACtC,SAAOF,gBAAgBL,WAAW;IAChCQ,SAASD,QAAQE;EACnB,CAAA;AACF;AAKO,IAAMC,UAAN,MAAMA;;EACX,YAA6BC,UAA0B;SAA1BA,WAAAA;EAA2B;EAExD,MAAMC,OAAO,EAAEC,OAAM,GAA0C;AAC7D,UAAM,EAAEC,kBAAkBC,iBAAiB,GAAGR,QAAAA,IAAY,KAAKI;AAC/D,UAAMK,aAAaC,OAAOC,KAAK,MAAMjB,aAAakB,OAAO,WAAWF,OAAOC,KAAKL,MAAAA,CAAAA,CAAAA;AAEhF,QAAI,KAAKF,SAASS,aAAa,WAAW;AACxCjB,gBAAUE,aAAa,6BAAA;;;;;;;;;AACvB,YAAMA;IACR;A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,CAAA;AACF;AAEA,IAAMoB,cAAc;AACpB,IAAMC,gBAAgB;AAEtB,IAAMxC,aAAqB;EACzBpB,MAAM;EACNC,OAAO,CAACjC,WAAAA;AAGNA,IAAAA,OAAMkC,UAAU;MAAEC,QAAQ;IAAe,GAAG,CAAC0D,UAAU;MACrDzD,MAAMyD,KAAKzD;MACXG,WAAW;IACb,EAAA;AAKAvC,IAAAA,OAAMkC,UAAU;MAAEC,QAAQ;MAAMI,WAAW;IAAW,GAAG,CAACsD,UAAU;MAClEzD,MAAM,IAAI0D,IAAID,KAAKzD,MAAMyD,KAAKE,QAAQ,EAAEC,SAAQ;MAChDzD,WAAW;IACb,EAAA;AAIAvC,IAAAA,OAAMwC,OAAO;MAAEL,QAAQ;MAAMI,WAAW;IAAW,GAAG,OAAOsD,SAAAA;AAC3D,aAAcI,WAAI,aAAA;AAChB,cAAMC,WAAW,OAAkBC,eAAIN,KAAKzD,IAAI;AAChD,YAAI8D,SAASE,WAAW,KAAK;AAC3B,gBAAM,IAAIC,MAAM,oBAAoBH,SAASE,MAAM,EAAE;QACvD;AAEA,cAAMxC,OAAO,OAAOsC,SAAStC;AAC7B,eAAO;UAAEnB,UAAUmB;UAAMlB,QAAQ;QAAgB;MACnD,CAAA,EAAG4D,KACMC,aACID,cACEE,qBAAqBC,gBAAOb,aAAAA,CAAAA,GAC5Bc,mBACAC,mBAAmBC,gBAAOjB,cAAc,CAAA,CAAA,CAAA,CAAA,GAG9CkB,eAAwBC,qBAAK,GACpC3G,mBAAAA;IAEJ,CAAA;EACF;AACF;",
6
+ "names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "Function", "Schedule", "build", "initialize", "subtleCrypto", "runAndForwardErrors", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "_options", "bundle", "source", "sandboxedModules", "providedModules", "sourceHash", "Buffer", "from", "digest", "platform", "imports", "analyzeSourceFileImports", "result", "conditions", "metafile", "write", "entryPoints", "userFunc", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "entryPoint", "timestamp", "Date", "now", "analyzeImports", "asset", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "MAX_RETRIES", "INITIAL_DELAY", "args", "URL", "importer", "toString", "gen", "response", "get", "status", "Error", "pipe", "retry", "exponential", "millis", "jittered", "intersect", "recurs", "provide", "layer"]
7
7
  }
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
10
+ //# sourceMappingURL=chunk-J5LGTIGS.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }