@dxos/plugin-script 0.6.10-main.e92b5eb → 0.6.10-staging.7621a6e
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.
- package/README.md +45 -0
- package/dist/lib/browser/ScriptEditor-WNCGR5OU.mjs +452 -0
- package/dist/lib/browser/ScriptEditor-WNCGR5OU.mjs.map +7 -0
- package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs → TypescriptEditor-XTGRVCMY.mjs} +2 -2
- package/dist/lib/browser/{chunk-ISMNAD3P.mjs → chunk-DL5XQRQM.mjs} +13 -7
- package/dist/lib/browser/{chunk-ISMNAD3P.mjs.map → chunk-DL5XQRQM.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-D4O723CR.mjs → chunk-DX5CSOBP.mjs} +22 -5
- package/dist/lib/browser/chunk-DX5CSOBP.mjs.map +7 -0
- package/dist/lib/browser/chunk-RHEZ5LUU.mjs +229 -0
- package/dist/lib/browser/chunk-RHEZ5LUU.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +88 -195
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/ScriptEditor-RR7AVOQL.cjs +465 -0
- package/dist/lib/node/ScriptEditor-RR7AVOQL.cjs.map +7 -0
- package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs → TypescriptEditor-CRONCQSI.cjs} +7 -7
- package/dist/lib/node/{TypescriptEditor-OTWJUIWB.cjs.map → TypescriptEditor-CRONCQSI.cjs.map} +2 -2
- package/dist/lib/node/chunk-4GTXIELQ.cjs +252 -0
- package/dist/lib/node/chunk-4GTXIELQ.cjs.map +7 -0
- package/dist/lib/node/{chunk-HN3AVLUL.cjs → chunk-PFH3ROEH.cjs} +16 -10
- package/dist/lib/node/{chunk-HN3AVLUL.cjs.map → chunk-PFH3ROEH.cjs.map} +3 -3
- package/dist/lib/node/{chunk-ITLHJMWP.cjs → chunk-RXI576K3.cjs} +24 -7
- package/dist/lib/node/chunk-RXI576K3.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +8 -8
- package/dist/lib/node/edge/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +85 -194
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/ScriptPlugin.d.ts +1 -4
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/bundler/bundler.d.ts +39 -0
- package/dist/types/src/bundler/bundler.d.ts.map +1 -0
- package/dist/types/src/bundler/bundler.test.d.ts +2 -0
- package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
- package/dist/types/src/bundler/index.d.ts +2 -0
- package/dist/types/src/bundler/index.d.ts.map +1 -0
- package/dist/types/src/compiler/compiler.browser.test.d.ts +2 -0
- package/dist/types/src/compiler/compiler.browser.test.d.ts.map +1 -0
- package/dist/types/src/compiler/compiler.d.ts +9 -34
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/DetailsPanel.d.ts +9 -0
- package/dist/types/src/components/DetailsPanel.d.ts.map +1 -0
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts +2 -2
- package/dist/types/src/components/ScriptBlock/FrameContainer/FrameContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +1 -1
- package/dist/types/src/components/ScriptEditor.d.ts +3 -2
- package/dist/types/src/components/ScriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar.d.ts +9 -7
- package/dist/types/src/components/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar.stories.d.ts +1 -1
- package/dist/types/src/components/TypescriptEditor.d.ts +3 -1
- package/dist/types/src/components/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor.stories.d.ts +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/data/templates.md.d.ts +3 -0
- package/dist/types/src/data/templates.md.d.ts.map +1 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/package.json +38 -33
- package/src/ScriptPlugin.tsx +29 -10
- package/src/bundler/bundler.test.ts +44 -0
- package/src/bundler/bundler.ts +246 -0
- package/src/bundler/index.ts +5 -0
- package/src/compiler/compiler.browser.test.ts +18 -0
- package/src/compiler/compiler.ts +31 -190
- package/src/compiler/index.ts +1 -1
- package/src/components/DetailsPanel.tsx +218 -0
- package/src/components/ScriptBlock/FrameContainer/FrameContainer.tsx +2 -2
- package/src/components/ScriptBlock/ScriptBlock.tsx +10 -7
- package/src/components/ScriptEditor.tsx +71 -13
- package/src/components/Toolbar.tsx +69 -91
- package/src/components/TypescriptEditor.tsx +18 -4
- package/src/data/templates.md.ts +44 -0
- package/src/edge/functions.ts +9 -2
- package/src/index.ts +1 -0
- package/src/translations.ts +4 -3
- package/dist/lib/browser/ScriptEditor-MSQDR6D7.mjs +0 -241
- package/dist/lib/browser/ScriptEditor-MSQDR6D7.mjs.map +0 -7
- package/dist/lib/browser/chunk-D4O723CR.mjs.map +0 -7
- package/dist/lib/node/ScriptEditor-KBSACFYK.cjs +0 -258
- package/dist/lib/node/ScriptEditor-KBSACFYK.cjs.map +0 -7
- package/dist/lib/node/chunk-ITLHJMWP.cjs.map +0 -7
- package/dist/types/src/compiler/compiler.test.d.ts +0 -2
- package/dist/types/src/compiler/compiler.test.d.ts.map +0 -1
- package/src/compiler/compiler.test.ts +0 -17
- /package/dist/lib/browser/{TypescriptEditor-PIRIDDUS.mjs.map → TypescriptEditor-XTGRVCMY.mjs.map} +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var chunk_4GTXIELQ_exports = {};
|
|
20
|
+
__export(chunk_4GTXIELQ_exports, {
|
|
21
|
+
Bundler: () => Bundler,
|
|
22
|
+
initializeBundler: () => initializeBundler
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(chunk_4GTXIELQ_exports);
|
|
25
|
+
var import_esbuild_wasm = require("esbuild-wasm");
|
|
26
|
+
var import_crypto = require("@dxos/crypto");
|
|
27
|
+
var import_invariant = require("@dxos/invariant");
|
|
28
|
+
var import_log = require("@dxos/log");
|
|
29
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/bundler/bundler.ts";
|
|
30
|
+
var initialized;
|
|
31
|
+
var initializeBundler = async (options) => {
|
|
32
|
+
await (initialized ??= (0, import_esbuild_wasm.initialize)({
|
|
33
|
+
wasmURL: options.wasmUrl
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
var Bundler = class {
|
|
37
|
+
constructor(_options) {
|
|
38
|
+
this._options = _options;
|
|
39
|
+
}
|
|
40
|
+
async bundle(source) {
|
|
41
|
+
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
42
|
+
const createResult = async (result) => {
|
|
43
|
+
return {
|
|
44
|
+
timestamp: Date.now(),
|
|
45
|
+
sourceHash: Buffer.from(await import_crypto.subtleCrypto.digest("SHA-256", Buffer.from(source))),
|
|
46
|
+
...result
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
if (this._options.platform === "browser") {
|
|
50
|
+
(0, import_invariant.invariant)(initialized, "Compiler not initialized.", {
|
|
51
|
+
F: __dxlog_file,
|
|
52
|
+
L: 57,
|
|
53
|
+
S: this,
|
|
54
|
+
A: [
|
|
55
|
+
"initialized",
|
|
56
|
+
"'Compiler not initialized.'"
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
await initialized;
|
|
60
|
+
}
|
|
61
|
+
const imports = analyzeSourceFileImports(source);
|
|
62
|
+
try {
|
|
63
|
+
const result = await (0, import_esbuild_wasm.build)({
|
|
64
|
+
platform: options.platform,
|
|
65
|
+
conditions: [
|
|
66
|
+
"workerd",
|
|
67
|
+
"browser"
|
|
68
|
+
],
|
|
69
|
+
metafile: true,
|
|
70
|
+
write: false,
|
|
71
|
+
entryPoints: [
|
|
72
|
+
"memory:main.tsx"
|
|
73
|
+
],
|
|
74
|
+
bundle: true,
|
|
75
|
+
format: "esm",
|
|
76
|
+
plugins: [
|
|
77
|
+
{
|
|
78
|
+
name: "memory",
|
|
79
|
+
setup: (build2) => {
|
|
80
|
+
build2.onResolve({
|
|
81
|
+
filter: /^\.\/runtime\.js$/
|
|
82
|
+
}, ({ path }) => {
|
|
83
|
+
return {
|
|
84
|
+
path,
|
|
85
|
+
external: true
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
build2.onResolve({
|
|
89
|
+
filter: /^memory:/
|
|
90
|
+
}, ({ path }) => {
|
|
91
|
+
return {
|
|
92
|
+
path: path.split(":")[1],
|
|
93
|
+
namespace: "memory"
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
build2.onLoad({
|
|
97
|
+
filter: /.*/,
|
|
98
|
+
namespace: "memory"
|
|
99
|
+
}, ({ path }) => {
|
|
100
|
+
if (path === "main.tsx") {
|
|
101
|
+
return {
|
|
102
|
+
contents: source,
|
|
103
|
+
loader: "tsx"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
for (const module2 of providedModules) {
|
|
108
|
+
build2.onResolve({
|
|
109
|
+
filter: new RegExp(`^${module2}$`)
|
|
110
|
+
}, ({ path }) => {
|
|
111
|
+
return {
|
|
112
|
+
path,
|
|
113
|
+
namespace: "injected-module"
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
build2.onLoad({
|
|
118
|
+
filter: /.*/,
|
|
119
|
+
namespace: "injected-module"
|
|
120
|
+
}, ({ path }) => {
|
|
121
|
+
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
122
|
+
return {
|
|
123
|
+
contents: `
|
|
124
|
+
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
125
|
+
export { ${namedImports.join(",")} };
|
|
126
|
+
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
127
|
+
`,
|
|
128
|
+
loader: "tsx"
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
httpPlugin
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
(0, import_log.log)("compile complete", result.metafile, {
|
|
137
|
+
F: __dxlog_file,
|
|
138
|
+
L: 117,
|
|
139
|
+
S: this,
|
|
140
|
+
C: (f, a) => f(...a)
|
|
141
|
+
});
|
|
142
|
+
return await createResult({
|
|
143
|
+
imports: this.analyzeImports(result),
|
|
144
|
+
bundle: result.outputFiles[0].text
|
|
145
|
+
});
|
|
146
|
+
} catch (err) {
|
|
147
|
+
return await createResult({
|
|
148
|
+
error: err
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
153
|
+
analyzeImports(result) {
|
|
154
|
+
(0, import_invariant.invariant)(result.outputFiles, void 0, {
|
|
155
|
+
F: __dxlog_file,
|
|
156
|
+
L: 130,
|
|
157
|
+
S: this,
|
|
158
|
+
A: [
|
|
159
|
+
"result.outputFiles",
|
|
160
|
+
""
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
164
|
+
return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
|
|
165
|
+
const namedImports = [];
|
|
166
|
+
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
167
|
+
if (parsedImport?.[2]) {
|
|
168
|
+
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
169
|
+
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
170
|
+
if (namedImportsMatch) {
|
|
171
|
+
namedImportsMatch[1].split(",").forEach((importName) => {
|
|
172
|
+
namedImports.push(importName.trim());
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
moduleUrl: entry.path,
|
|
178
|
+
defaultImport: !!parsedImport?.[1],
|
|
179
|
+
namedImports
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
analyzeSourceFileImports(code) {
|
|
184
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
185
|
+
return parsedImports.map((capture) => {
|
|
186
|
+
return {
|
|
187
|
+
defaultImportName: capture[1],
|
|
188
|
+
namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
|
|
189
|
+
wildcardImportName: capture[3],
|
|
190
|
+
moduleIdentifier: capture[4],
|
|
191
|
+
quotes: capture[5]
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
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;
|
|
197
|
+
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
198
|
+
var allMatches = (regex, str) => {
|
|
199
|
+
regex.lastIndex = 0;
|
|
200
|
+
let match;
|
|
201
|
+
const matches = [];
|
|
202
|
+
while (match = regex.exec(str)) {
|
|
203
|
+
matches.push(match);
|
|
204
|
+
}
|
|
205
|
+
return matches;
|
|
206
|
+
};
|
|
207
|
+
var analyzeSourceFileImports = (code) => {
|
|
208
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
209
|
+
return parsedImports.map((capture) => {
|
|
210
|
+
return {
|
|
211
|
+
defaultImportName: capture[1],
|
|
212
|
+
namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
|
|
213
|
+
wildcardImportName: capture[3],
|
|
214
|
+
moduleIdentifier: capture[4],
|
|
215
|
+
quotes: capture[5]
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var httpPlugin = {
|
|
220
|
+
name: "http",
|
|
221
|
+
setup: (build2) => {
|
|
222
|
+
build2.onResolve({
|
|
223
|
+
filter: /^https?:\/\//
|
|
224
|
+
}, (args) => ({
|
|
225
|
+
path: args.path,
|
|
226
|
+
namespace: "http-url"
|
|
227
|
+
}));
|
|
228
|
+
build2.onResolve({
|
|
229
|
+
filter: /.*/,
|
|
230
|
+
namespace: "http-url"
|
|
231
|
+
}, (args) => ({
|
|
232
|
+
path: new URL(args.path, args.importer).toString(),
|
|
233
|
+
namespace: "http-url"
|
|
234
|
+
}));
|
|
235
|
+
build2.onLoad({
|
|
236
|
+
filter: /.*/,
|
|
237
|
+
namespace: "http-url"
|
|
238
|
+
}, async (args) => {
|
|
239
|
+
const response = await fetch(args.path);
|
|
240
|
+
return {
|
|
241
|
+
contents: await response.text(),
|
|
242
|
+
loader: "jsx"
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
248
|
+
0 && (module.exports = {
|
|
249
|
+
Bundler,
|
|
250
|
+
initializeBundler
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=chunk-4GTXIELQ.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/bundler/bundler.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type BuildOptions } from 'esbuild';\nimport { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\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 BundlerResult = {\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(source: string): Promise<BundlerResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n\n const createResult = async (result?: Partial<BundlerResult>) => {\n return {\n timestamp: Date.now(),\n sourceHash: Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))),\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 = 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: ['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: /^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 // 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 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 const response = await fetch(args.path);\n return { contents: await response.text(), loader: 'jsx' };\n });\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAKA,0BAAiE;AAEjE,oBAA6B;AAC7B,uBAA0B;AAC1B,iBAAoB;;AAsBpB,IAAIA;AACG,IAAMC,oBAAoB,OAAOC,YAAAA;AACtC,SAAOF,oBAAgBG,gCAAW;IACh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,MAAM,GAAA,EACN2B,IAAI,CAACQ,eAAeA,WAAWE,KAAI,CAAA;MACtCK,oBAAoBb,QAAQ,CAAA;MAC5BnB,kBAAkBmB,QAAQ,CAAA;MAC1Bc,QAAQd,QAAQ,CAAA;IAClB;EACF,CAAA;AACF;AAEA,IAAMf,aAAqB;EACzBpB,MAAM;EACNC,OAAO,CAACR,WAAAA;AAGNA,WAAMS,UAAU;MAAEC,QAAQ;IAAe,GAAG,CAACoD,UAAU;MACrDnD,MAAMmD,KAAKnD;MACXG,WAAW;IACb,EAAA;AAKAd,WAAMS,UAAU;MAAEC,QAAQ;MAAMI,WAAW;IAAW,GAAG,CAACgD,UAAU;MAClEnD,MAAM,IAAIoD,IAAID,KAAKnD,MAAMmD,KAAKE,QAAQ,EAAEC,SAAQ;MAChDnD,WAAW;IACb,EAAA;AAIAd,WAAMe,OAAO;MAAEL,QAAQ;MAAMI,WAAW;IAAW,GAAG,OAAOgD,SAAAA;AAC3D,YAAMI,WAAW,MAAMC,MAAML,KAAKnD,IAAI;AACtC,aAAO;QAAEK,UAAU,MAAMkD,SAASnC,KAAI;QAAId,QAAQ;MAAM;IAC1D,CAAA;EACF;AACF;",
|
|
6
|
+
"names": ["initialized", "initializeBundler", "options", "initialize", "wasmURL", "wasmUrl", "Bundler", "constructor", "_options", "bundle", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "subtleCrypto", "digest", "platform", "invariant", "imports", "analyzeSourceFileImports", "build", "conditions", "metafile", "write", "entryPoints", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "log", "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", "args", "URL", "importer", "toString", "response", "fetch"]
|
|
7
|
+
}
|
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_PFH3ROEH_exports = {};
|
|
20
|
+
__export(chunk_PFH3ROEH_exports, {
|
|
21
21
|
HeaderCodec: () => HeaderCodec,
|
|
22
22
|
codec: () => codec,
|
|
23
23
|
getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
|
|
@@ -26,7 +26,7 @@ __export(chunk_HN3AVLUL_exports, {
|
|
|
26
26
|
setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata,
|
|
27
27
|
uploadWorkerFunction: () => uploadWorkerFunction
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
29
|
+
module.exports = __toCommonJS(chunk_PFH3ROEH_exports);
|
|
30
30
|
var import_keys = require("@dxos/keys");
|
|
31
31
|
var import_async = require("@dxos/async");
|
|
32
32
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -126,9 +126,15 @@ var publicKeyToDid = (key) => {
|
|
|
126
126
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/edge/functions.ts";
|
|
127
127
|
var USERFUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
128
128
|
var USERFUNCTIONS_CREDENTIAL_CAPABILITY = "composer:beta";
|
|
129
|
-
var defaultUserFunctionsBaseUrl = "https://edge-main.dxos.workers.dev";
|
|
129
|
+
var defaultUserFunctionsBaseUrl = "https://edge-main.dxos.workers.dev/functions";
|
|
130
130
|
var getBaseUrl = (config) => {
|
|
131
|
-
|
|
131
|
+
if (config.values.runtime?.services?.edge?.url) {
|
|
132
|
+
const url = new URL("/functions", config.values.runtime?.services?.edge?.url);
|
|
133
|
+
url.protocol = "https";
|
|
134
|
+
return url.toString();
|
|
135
|
+
} else {
|
|
136
|
+
return defaultUserFunctionsBaseUrl;
|
|
137
|
+
}
|
|
132
138
|
};
|
|
133
139
|
var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid, functionId, credentialLoadTimeout }) => {
|
|
134
140
|
const identity = halo.identity.get();
|
|
@@ -145,7 +151,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
145
151
|
uploadUrl: uploadUrl.toString()
|
|
146
152
|
}, {
|
|
147
153
|
F: __dxlog_file,
|
|
148
|
-
L:
|
|
154
|
+
L: 71,
|
|
149
155
|
S: void 0,
|
|
150
156
|
C: (f, a) => f(...a)
|
|
151
157
|
});
|
|
@@ -169,7 +175,7 @@ var uploadWorkerFunction = async ({ clientConfig, halo, name, source, ownerDid,
|
|
|
169
175
|
res
|
|
170
176
|
}, {
|
|
171
177
|
F: __dxlog_file,
|
|
172
|
-
L:
|
|
178
|
+
L: 82,
|
|
173
179
|
S: void 0,
|
|
174
180
|
C: (f, a) => f(...a)
|
|
175
181
|
});
|
|
@@ -218,13 +224,13 @@ var presentationForIdentity = async ({ halo, timeout }) => {
|
|
|
218
224
|
credential
|
|
219
225
|
}, {
|
|
220
226
|
F: __dxlog_file,
|
|
221
|
-
L:
|
|
227
|
+
L: 128,
|
|
222
228
|
S: void 0,
|
|
223
229
|
C: (f, a) => f(...a)
|
|
224
230
|
});
|
|
225
231
|
(0, import_invariant.invariant)(credential.id, "beta credential missing id", {
|
|
226
232
|
F: __dxlog_file,
|
|
227
|
-
L:
|
|
233
|
+
L: 130,
|
|
228
234
|
S: void 0,
|
|
229
235
|
A: [
|
|
230
236
|
"credential.id",
|
|
@@ -250,4 +256,4 @@ var presentationForIdentity = async ({ halo, timeout }) => {
|
|
|
250
256
|
setUserFunctionUrlInMetadata,
|
|
251
257
|
uploadWorkerFunction
|
|
252
258
|
});
|
|
253
|
-
//# sourceMappingURL=chunk-
|
|
259
|
+
//# sourceMappingURL=chunk-PFH3ROEH.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/edge/codec.ts", "../../../src/edge/header-codec.ts", "../../../src/edge/functions.ts", "../../../src/edge/hub-protocol.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/keys';\n\nimport { HeaderCodec, type EncodedKey } from './header-codec';\n\nexport const codec = new HeaderCodec<PublicKey>({\n isKey: (value: any): value is PublicKey => value instanceof PublicKey,\n encode: (key: PublicKey): EncodedKey => ({ __k: key.toHex() }),\n decode: (value: EncodedKey): PublicKey => PublicKey.fromHex(value.__k),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out from @dxos/hub-protocol\n\nconst ENCODING = 'base64';\n\nexport type EncodedKey = { __k: string };\n\nexport type EncodedBytes = { __b: string };\n\nexport type EncodedTimestamp = { __t: number };\n\nexport interface KeyCodec<KeyType> {\n isKey(value: any): value is KeyType;\n encode(key: KeyType): EncodedKey;\n decode(value: EncodedKey): KeyType;\n}\n\n// TODO(wittjosiah): Use deepMapValues from @dxos/util -- it handles recursion for you.\nexport class HeaderCodec<Key> {\n constructor(private readonly _keyCodec: KeyCodec<Key>) {}\n\n encode(obj: any): string {\n const objectToEncode = this._prepareForEncoding(obj);\n const encoded = Buffer.from(JSON.stringify(objectToEncode));\n return encoded.toString(ENCODING);\n }\n\n decode<Type>(buffer: string): Type {\n const json = JSON.parse(Buffer.from(buffer, ENCODING).toString());\n return this._decodeRecursive(json);\n }\n\n private _decodeRecursive(obj: any): any {\n return this._recurse(obj, (value) => {\n if (isEncodedBytes(value)) {\n return decodeBytes(value.__b);\n }\n if (isEncodedKey(value)) {\n return this._keyCodec.decode(value);\n }\n if (isEncodedDate(value)) {\n return decodeDate(value);\n }\n return null;\n });\n }\n\n private _prepareForEncoding(obj: any): any {\n return this._recurse(obj, (value) => {\n if (value instanceof Uint8Array) {\n return { __b: encodeBytes(value) };\n }\n if (this._keyCodec.isKey(value)) {\n return this._keyCodec.encode(value);\n }\n if (value instanceof Date) {\n return encodeDate(value);\n }\n return null;\n });\n }\n\n private _recurse(obj: any, handler: (obj: object) => any | null): any {\n if (typeof obj !== 'object') {\n return obj;\n }\n const handled = handler(obj);\n if (handled != null) {\n return handled;\n }\n if (Array.isArray(obj)) {\n const result = [];\n for (const elem of obj) {\n result.push(this._recurse(elem, handler));\n }\n return result;\n }\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = this._recurse(value, handler);\n }\n return result;\n }\n}\n\nconst isEncodedKey = (obj: object): obj is EncodedKey => '__k' in obj && typeof obj.__k === 'string';\nconst isEncodedBytes = (obj: object): obj is EncodedBytes => '__b' in obj && typeof obj.__b === 'string';\nconst isEncodedDate = (obj: object): obj is EncodedTimestamp => '__t' in obj && typeof obj.__t === 'number';\n\nconst encodeDate = (date: Date) => ({ __t: date.getTime() });\nconst decodeDate = (timestamp: EncodedTimestamp) => new Date(timestamp.__t);\n\nconst encodeBytes = (bytes: Uint8Array) => Buffer.from(bytes).toString(ENCODING);\nconst decodeBytes = (bytes: string) => Buffer.from(bytes, ENCODING);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { Trigger } from '@dxos/async';\nimport { type Config } from '@dxos/client';\nimport { type Halo } from '@dxos/client-protocol';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { codec } from './codec';\nimport { matchServiceCredential } from './hub-protocol';\n\n// TODO: use URL scheme for source?\nconst USERFUNCTIONS_META_KEY = 'dxos.org/service/function';\nconst USERFUNCTIONS_CREDENTIAL_CAPABILITY = 'composer:beta';\n\n// TODO: Synchronize API types with server\nexport type UserFunctionUploadResult = {\n result: 'success' | 'error';\n errorMessage?: string;\n functionId?: string;\n functionVersionNumber?: number;\n};\n\nexport type UploadWorkerProps = {\n clientConfig: Config;\n halo: Halo;\n name?: string;\n source: string;\n functionId?: string;\n ownerDid: DID;\n credentialLoadTimeout?: number; // ms to wait for credentials to load\n};\n\nconst defaultUserFunctionsBaseUrl = 'https://edge-main.dxos.workers.dev'; // 'http://localhost:8600';\n\nconst getBaseUrl = (config: Config) => {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAA0B;AEE1B,mBAAwB;AAIxB,uBAA0B;AAC1B,iBAAoB;ADLpB,IAAMA,WAAW;AAeV,IAAMC,cAAN,MAAMA;EACXC,YAA6BC,WAA0B;SAA1BA,YAAAA;EAA2B;EAExDC,OAAOC,KAAkB;AACvB,UAAMC,iBAAiB,KAAKC,oBAAoBF,GAAAA;AAChD,UAAMG,UAAUC,OAAOC,KAAKC,KAAKC,UAAUN,cAAAA,CAAAA;AAC3C,WAAOE,QAAQK,SAASb,QAAAA;EAC1B;EAEAc,OAAaC,QAAsB;AACjC,UAAMC,OAAOL,KAAKM,MAAMR,OAAOC,KAAKK,QAAQf,QAAAA,EAAUa,SAAQ,CAAA;AAC9D,WAAO,KAAKK,iBAAiBF,IAAAA;EAC/B;EAEQE,iBAAiBb,KAAe;AACtC,WAAO,KAAKc,SAASd,KAAK,CAACe,UAAAA;AACzB,UAAIC,eAAeD,KAAAA,GAAQ;AACzB,eAAOE,YAAYF,MAAMG,GAAG;MAC9B;AACA,UAAIC,aAAaJ,KAAAA,GAAQ;AACvB,eAAO,KAAKjB,UAAUW,OAAOM,KAAAA;MAC/B;AACA,UAAIK,cAAcL,KAAAA,GAAQ;AACxB,eAAOM,WAAWN,KAAAA;MACpB;AACA,aAAO;IACT,CAAA;EACF;EAEQb,oBAAoBF,KAAe;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KAAKqC,KAAAA,EAAOlC,SAASb,QAAAA;AACvE,IAAMsB,cAAc,CAACyB,UAAkBtC,OAAOC,KAAKqC,OAAO/C,QAAAA;ADxFnD,IAAMgD,QAAQ,IAAI/C,YAAuB;EAC9C4B,OAAO,CAACT,UAAmCA,iBAAiB6B;EAC5D7C,QAAQ,CAACmC,SAAgC;IAAEG,KAAKH,IAAIW,MAAK;EAAG;EAC5DpC,QAAQ,CAACM,UAAiC6B,sBAAUE,QAAQ/B,MAAMsB,GAAG;AACvE,CAAA;AGDO,IAAMU,yBACX,CAACC,eAAyB,CAAA,MAC1B,CAACC,eAAAA;AACC,MAAIA,WAAWC,QAAQC,UAAU,OAAA,MAAa,uCAAuC;AACnF,WAAO;EACT;AAEA,QAAM,EAAEH,cAAcI,uBAAsB,IAAKH,WAAWC,QAAQC;AACpE,SAAOH,aAAaK,MAAM,CAACC,eAAeF,uBAAuBG,SAASD,UAAAA,CAAAA;AAC5E;AAIK,IAAME,iBAAiB,CAACtB,QAAAA;AAC7B,SAAO,WAAWA,IAAIW,MAAK,CAAA;AAC7B;;ADRA,IAAMY,yBAAyB;AAC/B,IAAMC,sCAAsC;
|
|
6
|
-
"names": ["ENCODING", "HeaderCodec", "constructor", "_keyCodec", "encode", "obj", "objectToEncode", "_prepareForEncoding", "encoded", "Buffer", "from", "JSON", "stringify", "toString", "decode", "buffer", "json", "parse", "_decodeRecursive", "_recurse", "value", "isEncodedBytes", "decodeBytes", "__b", "isEncodedKey", "isEncodedDate", "decodeDate", "Uint8Array", "encodeBytes", "isKey", "Date", "encodeDate", "handler", "handled", "Array", "isArray", "result", "elem", "push", "key", "Object", "entries", "__k", "__t", "date", "getTime", "timestamp", "bytes", "codec", "PublicKey", "toHex", "fromHex", "matchServiceCredential", "capabilities", "credential", "subject", "assertion", "credentialCapabilities", "every", "capability", "includes", "publicKeyToDid", "USERFUNCTIONS_META_KEY", "USERFUNCTIONS_CREDENTIAL_CAPABILITY", "defaultUserFunctionsBaseUrl", "getBaseUrl", "config", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/keys';\n\nimport { HeaderCodec, type EncodedKey } from './header-codec';\n\nexport const codec = new HeaderCodec<PublicKey>({\n isKey: (value: any): value is PublicKey => value instanceof PublicKey,\n encode: (key: PublicKey): EncodedKey => ({ __k: key.toHex() }),\n decode: (value: EncodedKey): PublicKey => PublicKey.fromHex(value.__k),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out from @dxos/hub-protocol\n\nconst ENCODING = 'base64';\n\nexport type EncodedKey = { __k: string };\n\nexport type EncodedBytes = { __b: string };\n\nexport type EncodedTimestamp = { __t: number };\n\nexport interface KeyCodec<KeyType> {\n isKey(value: any): value is KeyType;\n encode(key: KeyType): EncodedKey;\n decode(value: EncodedKey): KeyType;\n}\n\n// TODO(wittjosiah): Use deepMapValues from @dxos/util -- it handles recursion for you.\nexport class HeaderCodec<Key> {\n constructor(private readonly _keyCodec: KeyCodec<Key>) {}\n\n encode(obj: any): string {\n const objectToEncode = this._prepareForEncoding(obj);\n const encoded = Buffer.from(JSON.stringify(objectToEncode));\n return encoded.toString(ENCODING);\n }\n\n decode<Type>(buffer: string): Type {\n const json = JSON.parse(Buffer.from(buffer, ENCODING).toString());\n return this._decodeRecursive(json);\n }\n\n private _decodeRecursive(obj: any): any {\n return this._recurse(obj, (value) => {\n if (isEncodedBytes(value)) {\n return decodeBytes(value.__b);\n }\n if (isEncodedKey(value)) {\n return this._keyCodec.decode(value);\n }\n if (isEncodedDate(value)) {\n return decodeDate(value);\n }\n return null;\n });\n }\n\n private _prepareForEncoding(obj: any): any {\n return this._recurse(obj, (value) => {\n if (value instanceof Uint8Array) {\n return { __b: encodeBytes(value) };\n }\n if (this._keyCodec.isKey(value)) {\n return this._keyCodec.encode(value);\n }\n if (value instanceof Date) {\n return encodeDate(value);\n }\n return null;\n });\n }\n\n private _recurse(obj: any, handler: (obj: object) => any | null): any {\n if (typeof obj !== 'object') {\n return obj;\n }\n const handled = handler(obj);\n if (handled != null) {\n return handled;\n }\n if (Array.isArray(obj)) {\n const result = [];\n for (const elem of obj) {\n result.push(this._recurse(elem, handler));\n }\n return result;\n }\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = this._recurse(value, handler);\n }\n return result;\n }\n}\n\nconst isEncodedKey = (obj: object): obj is EncodedKey => '__k' in obj && typeof obj.__k === 'string';\nconst isEncodedBytes = (obj: object): obj is EncodedBytes => '__b' in obj && typeof obj.__b === 'string';\nconst isEncodedDate = (obj: object): obj is EncodedTimestamp => '__t' in obj && typeof obj.__t === 'number';\n\nconst encodeDate = (date: Date) => ({ __t: date.getTime() });\nconst decodeDate = (timestamp: EncodedTimestamp) => new Date(timestamp.__t);\n\nconst encodeBytes = (bytes: Uint8Array) => Buffer.from(bytes).toString(ENCODING);\nconst decodeBytes = (bytes: string) => Buffer.from(bytes, ENCODING);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { Trigger } from '@dxos/async';\nimport { type Config } from '@dxos/client';\nimport { type Halo } from '@dxos/client-protocol';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { codec } from './codec';\nimport { matchServiceCredential } from './hub-protocol';\n\n// TODO: use URL scheme for source?\nconst USERFUNCTIONS_META_KEY = 'dxos.org/service/function';\nconst USERFUNCTIONS_CREDENTIAL_CAPABILITY = 'composer:beta';\n\n// TODO: Synchronize API types with server\nexport type UserFunctionUploadResult = {\n result: 'success' | 'error';\n errorMessage?: string;\n functionId?: string;\n functionVersionNumber?: number;\n};\n\nexport type UploadWorkerProps = {\n clientConfig: Config;\n halo: Halo;\n name?: string;\n source: string;\n functionId?: string;\n ownerDid: DID;\n credentialLoadTimeout?: number; // ms to wait for credentials to load\n};\n\n// TODO(burdon): Config.\nconst defaultUserFunctionsBaseUrl = 'https://edge-main.dxos.workers.dev/functions'; // 'http://localhost:8600';\n\nconst getBaseUrl = (config: Config) => {\n if (config.values.runtime?.services?.edge?.url) {\n const url = new URL('/functions', config.values.runtime?.services?.edge?.url);\n url.protocol = 'https';\n return url.toString();\n } else {\n return defaultUserFunctionsBaseUrl;\n }\n};\n\nexport const uploadWorkerFunction = async ({\n clientConfig,\n halo,\n name,\n source,\n ownerDid,\n functionId,\n credentialLoadTimeout,\n}: UploadWorkerProps) => {\n const identity = halo.identity.get();\n if (!identity) {\n throw new Error('Identity not available');\n }\n const userFunctionsBaseUrl = getBaseUrl(clientConfig);\n\n // TODO: codify naming convention\n const uploadUrl = `${userFunctionsBaseUrl}/${ownerDid}` + (functionId ? `/${functionId}` : '');\n\n log('Upload', { functionId, source, name, identityKey: identity.identityKey, uploadUrl: uploadUrl.toString() });\n const response = await fetch(uploadUrl, {\n method: 'PUT',\n body: JSON.stringify({ script: source, name }),\n headers: await presentationForIdentity({ halo, timeout: credentialLoadTimeout }),\n });\n if (!response.ok) {\n return (await response.json()) as UserFunctionUploadResult;\n }\n\n const res = await response.json();\n log('Upload response', { status: response.status, res });\n\n return res as UserFunctionUploadResult;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: USERFUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\n// TODO: handle team owner\n\nconst presentationForIdentity = async ({ halo, timeout }: { halo: Halo; timeout?: number }) => {\n let credential: Credential | undefined;\n\n if (timeout) {\n const credentialsLoaded = new Trigger();\n halo.credentials.subscribe((c) => {\n credential = c.find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n if (credential) {\n credentialsLoaded.wake();\n }\n });\n await credentialsLoaded.wait({\n timeout,\n });\n } else {\n credential = halo\n .queryCredentials()\n .toSorted((a, b) => b.issuanceDate.getTime() - a.issuanceDate.getTime())\n .find(matchServiceCredential([USERFUNCTIONS_CREDENTIAL_CAPABILITY]));\n }\n\n if (!credential) {\n throw new Error('No credential found');\n }\n log('credential found', { credential });\n // TODO(wittjosiah): If id is required to present credentials, then it should always be present for queried credentials.\n invariant(credential.id, 'beta credential missing id');\n const presentation = await halo.presentCredentials({ ids: [credential.id] });\n\n return { Authorization: `Bearer ${codec.encode(presentation)}` };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Credential } from '@dxos/client/halo';\nimport { type PublicKey } from '@dxos/keys';\n\n// TODO(burdon): Factor out to @dxos/hub-protocol.\n\nexport const matchServiceCredential =\n (capabilities: string[] = []) =>\n (credential: Credential) => {\n if (credential.subject.assertion['@type'] !== 'dxos.halo.credentials.ServiceAccess') {\n return false;\n }\n\n const { capabilities: credentialCapabilities } = credential.subject.assertion;\n return capabilities.every((capability) => credentialCapabilities.includes(capability));\n };\n\n// TODO: reconcile with @dxos/hub-protocol\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAA0B;AEE1B,mBAAwB;AAIxB,uBAA0B;AAC1B,iBAAoB;ADLpB,IAAMA,WAAW;AAeV,IAAMC,cAAN,MAAMA;EACXC,YAA6BC,WAA0B;SAA1BA,YAAAA;EAA2B;EAExDC,OAAOC,KAAkB;AACvB,UAAMC,iBAAiB,KAAKC,oBAAoBF,GAAAA;AAChD,UAAMG,UAAUC,OAAOC,KAAKC,KAAKC,UAAUN,cAAAA,CAAAA;AAC3C,WAAOE,QAAQK,SAASb,QAAAA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ForEncoding", "encoded", "Buffer", "from", "JSON", "stringify", "toString", "decode", "buffer", "json", "parse", "_decodeRecursive", "_recurse", "value", "isEncodedBytes", "decodeBytes", "__b", "isEncodedKey", "isEncodedDate", "decodeDate", "Uint8Array", "encodeBytes", "isKey", "Date", "encodeDate", "handler", "handled", "Array", "isArray", "result", "elem", "push", "key", "Object", "entries", "__k", "__t", "date", "getTime", "timestamp", "bytes", "codec", "PublicKey", "toHex", "fromHex", "matchServiceCredential", "capabilities", "credential", "subject", "assertion", "credentialCapabilities", "every", "capability", "includes", "publicKeyToDid", "USERFUNCTIONS_META_KEY", "USERFUNCTIONS_CREDENTIAL_CAPABILITY", "defaultUserFunctionsBaseUrl", "getBaseUrl", "config", "values", "runtime", "services", "edge", "url", "URL", "protocol", "uploadWorkerFunction", "clientConfig", "halo", "name", "source", "ownerDid", "functionId", "credentialLoadTimeout", "identity", "get", "Error", "userFunctionsBaseUrl", "uploadUrl", "log", "identityKey", "response", "fetch", "method", "body", "script", "headers", "presentationForIdentity", "timeout", "ok", "res", "status", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "id", "setUserFunctionUrlInMetadata", "functionUrl", "credentialsLoaded", "Trigger", "credentials", "subscribe", "c", "wake", "wait", "queryCredentials", "toSorted", "a", "b", "issuanceDate", "invariant", "presentation", "presentCredentials", "ids", "Authorization"]
|
|
7
7
|
}
|
|
@@ -26,20 +26,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_RXI576K3_exports = {};
|
|
30
|
+
__export(chunk_RXI576K3_exports, {
|
|
31
31
|
TypescriptEditor: () => TypescriptEditor,
|
|
32
32
|
TypescriptEditor_default: () => TypescriptEditor_default
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(chunk_RXI576K3_exports);
|
|
35
35
|
var import_lang_javascript = require("@codemirror/lang-javascript");
|
|
36
36
|
var import_language = require("@codemirror/language");
|
|
37
37
|
var import_theme_one_dark = require("@codemirror/theme-one-dark");
|
|
38
|
+
var import_codemirror_ts = require("@valtown/codemirror-ts");
|
|
38
39
|
var import_react = __toESM(require("react"));
|
|
39
40
|
var import_react_ui = require("@dxos/react-ui");
|
|
40
41
|
var import_react_ui_editor = require("@dxos/react-ui-editor");
|
|
41
42
|
var import_util = require("@dxos/util");
|
|
42
|
-
var TypescriptEditor = ({ id, extensions, initialValue, scrollTo, selection, className, scrollPastEnd }) => {
|
|
43
|
+
var TypescriptEditor = ({ id, extensions, env, initialValue, scrollTo, selection, className, scrollPastEnd }) => {
|
|
43
44
|
const { themeMode } = (0, import_react_ui.useThemeContext)();
|
|
44
45
|
const { parentRef, focusAttributes } = (0, import_react_ui_editor.useTextEditor)(() => ({
|
|
45
46
|
id,
|
|
@@ -51,6 +52,7 @@ var TypescriptEditor = ({ id, extensions, initialValue, scrollTo, selection, cla
|
|
|
51
52
|
highlightActiveLine: true,
|
|
52
53
|
indentWithTab: true,
|
|
53
54
|
lineNumbers: true,
|
|
55
|
+
lineWrapping: false,
|
|
54
56
|
scrollPastEnd
|
|
55
57
|
}),
|
|
56
58
|
// TODO(wittjosiah): Factor out syntax highlighting to theme extensions.
|
|
@@ -59,7 +61,7 @@ var TypescriptEditor = ({ id, extensions, initialValue, scrollTo, selection, cla
|
|
|
59
61
|
themeMode,
|
|
60
62
|
slots: {
|
|
61
63
|
content: {
|
|
62
|
-
className: import_react_ui_editor.
|
|
64
|
+
className: import_react_ui_editor.editorFullWidth
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}),
|
|
@@ -68,7 +70,22 @@ var TypescriptEditor = ({ id, extensions, initialValue, scrollTo, selection, cla
|
|
|
68
70
|
(0, import_lang_javascript.javascript)({
|
|
69
71
|
typescript: true
|
|
70
72
|
}),
|
|
71
|
-
|
|
73
|
+
// https://github.com/val-town/codemirror-ts
|
|
74
|
+
env ? [
|
|
75
|
+
import_codemirror_ts.tsFacet.of({
|
|
76
|
+
env,
|
|
77
|
+
path: `/src/${id}.ts`
|
|
78
|
+
}),
|
|
79
|
+
(0, import_codemirror_ts.tsSync)(),
|
|
80
|
+
(0, import_codemirror_ts.tsLinter)(),
|
|
81
|
+
(0, import_codemirror_ts.tsHover)()
|
|
82
|
+
] : [],
|
|
83
|
+
(0, import_react_ui_editor.autocomplete)({
|
|
84
|
+
override: env ? [
|
|
85
|
+
(0, import_codemirror_ts.tsAutocomplete)()
|
|
86
|
+
] : []
|
|
87
|
+
}),
|
|
88
|
+
import_react_ui_editor.InputModeExtensions.vscode
|
|
72
89
|
].filter(import_util.nonNullable),
|
|
73
90
|
selection,
|
|
74
91
|
scrollTo
|
|
@@ -92,4 +109,4 @@ var TypescriptEditor_default = TypescriptEditor;
|
|
|
92
109
|
TypescriptEditor,
|
|
93
110
|
TypescriptEditor_default
|
|
94
111
|
});
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-RXI576K3.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/TypescriptEditor.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { javascript } from '@codemirror/lang-javascript';\nimport { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';\nimport { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';\nimport { type VirtualTypeScriptEnvironment } from '@typescript/vfs';\nimport { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover } from '@valtown/codemirror-ts';\nimport React from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n editorFullWidth,\n editorGutter,\n editorMonospace,\n InputModeExtensions,\n useTextEditor,\n type UseTextEditorProps,\n} from '@dxos/react-ui-editor';\nimport { nonNullable } from '@dxos/util';\n\nexport type TypescriptEditorProps = {\n id: string;\n env?: VirtualTypeScriptEnvironment;\n className?: string;\n scrollPastEnd?: boolean;\n} & Pick<UseTextEditorProps, 'initialValue' | 'extensions' | 'scrollTo' | 'selection'>;\n\nexport const TypescriptEditor = ({\n id,\n extensions,\n env,\n initialValue,\n scrollTo,\n selection,\n className,\n scrollPastEnd,\n}: TypescriptEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n id,\n initialValue,\n extensions: [\n extensions,\n // TODO(wittjosiah): Highlight active line doesn't work.\n createBasicExtensions({\n highlightActiveLine: true,\n indentWithTab: true,\n lineNumbers: true,\n lineWrapping: false,\n scrollPastEnd,\n }),\n // TODO(wittjosiah): Factor out syntax highlighting to theme extensions.\n themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),\n createThemeExtensions({\n themeMode,\n slots: {\n content: { className: editorFullWidth },\n },\n }),\n editorGutter,\n editorMonospace,\n javascript({ typescript: true }),\n // https://github.com/val-town/codemirror-ts\n env ? [tsFacet.of({ env, path: `/src/${id}.ts` }), tsSync(), tsLinter(), tsHover()] : [],\n autocomplete({ override: env ? [tsAutocomplete()] : [] }),\n InputModeExtensions.vscode,\n ].filter(nonNullable),\n selection,\n scrollTo,\n }),\n [id, initialValue, extensions, themeMode, selection, scrollTo],\n );\n\n return <div ref={parentRef} className={className} {...focusAttributes} />;\n};\n\nexport default TypescriptEditor;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,6BAA2B;AAC3B,sBAA0D;AAC1D,4BAAsC;AAEtC,2BAAmE;AACnE,mBAAkB;AAElB,sBAAgC;AAChC,6BAUO;AACP,kBAA4B;AASrB,IAAMA,mBAAmB,CAAC,EAC/BC,IACAC,YACAC,KACAC,cACAC,UACAC,WACAC,WACAC,cAAa,MACS;AACtB,QAAM,EAAEC,UAAS,QAAKC,iCAAAA;AACtB,QAAM,EAAEC,WAAWC,gBAAe,QAAKC,sCACrC,OAAO;IACLZ;IACAG;IACAF,YAAY;MACVA;;UAEAY,8CAAsB;QACpBC,qBAAqB;QACrBC,eAAe;QACfC,aAAa;QACbC,cAAc;QACdV;MACF,CAAA;;MAEAC,cAAc,aAASU,oCAAmBC,2CAAAA,QAAyBD,oCAAmBE,qCAAAA;UACtFC,8CAAsB;QACpBb;QACAc,OAAO;UACLC,SAAS;YAAEjB,WAAWkB;UAAgB;QACxC;MACF,CAAA;MACAC;MACAC;UACAC,mCAAW;QAAEC,YAAY;MAAK,CAAA;;MAE9B1B,MAAM;QAAC2B,6BAAQC,GAAG;UAAE5B;UAAK6B,MAAM,QAAQ/B,EAAAA;QAAQ,CAAA;YAAIgC,6BAAAA;YAAUC,+BAAAA;YAAYC,8BAAAA;UAAa,CAAA;UACtFC,qCAAa;QAAEC,UAAUlC,MAAM;cAACmC,qCAAAA;YAAoB,CAAA;MAAG,CAAA;MACvDC,2CAAoBC;MACpBC,OAAOC,uBAAAA;IACTpC;IACAD;EACF,IACA;IAACJ;IAAIG;IAAcF;IAAYO;IAAWH;IAAWD;GAAS;AAGhE,SAAO,6BAAAsC,QAAA,cAACC,OAAAA;IAAIC,KAAKlC;IAAWJ;IAAuB,GAAGK;;AACxD;AAEA,IAAA,2BAAeZ;",
|
|
6
|
+
"names": ["TypescriptEditor", "id", "extensions", "env", "initialValue", "scrollTo", "selection", "className", "scrollPastEnd", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "highlightActiveLine", "indentWithTab", "lineNumbers", "lineWrapping", "syntaxHighlighting", "oneDarkHighlightStyle", "defaultHighlightStyle", "createThemeExtensions", "slots", "content", "editorFullWidth", "editorGutter", "editorMonospace", "javascript", "typescript", "tsFacet", "of", "path", "tsSync", "tsLinter", "tsHover", "autocomplete", "override", "tsAutocomplete", "InputModeExtensions", "vscode", "filter", "nonNullable", "React", "div", "ref"]
|
|
7
|
+
}
|
|
@@ -18,16 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var edge_exports = {};
|
|
20
20
|
__export(edge_exports, {
|
|
21
|
-
HeaderCodec: () =>
|
|
22
|
-
codec: () =>
|
|
23
|
-
getUserFunctionUrlInMetadata: () =>
|
|
24
|
-
matchServiceCredential: () =>
|
|
25
|
-
publicKeyToDid: () =>
|
|
26
|
-
setUserFunctionUrlInMetadata: () =>
|
|
27
|
-
uploadWorkerFunction: () =>
|
|
21
|
+
HeaderCodec: () => import_chunk_PFH3ROEH.HeaderCodec,
|
|
22
|
+
codec: () => import_chunk_PFH3ROEH.codec,
|
|
23
|
+
getUserFunctionUrlInMetadata: () => import_chunk_PFH3ROEH.getUserFunctionUrlInMetadata,
|
|
24
|
+
matchServiceCredential: () => import_chunk_PFH3ROEH.matchServiceCredential,
|
|
25
|
+
publicKeyToDid: () => import_chunk_PFH3ROEH.publicKeyToDid,
|
|
26
|
+
setUserFunctionUrlInMetadata: () => import_chunk_PFH3ROEH.setUserFunctionUrlInMetadata,
|
|
27
|
+
uploadWorkerFunction: () => import_chunk_PFH3ROEH.uploadWorkerFunction
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(edge_exports);
|
|
30
|
-
var
|
|
30
|
+
var import_chunk_PFH3ROEH = require("../chunk-PFH3ROEH.cjs");
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
33
|
HeaderCodec,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n HeaderCodec,\n codec,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-
|
|
4
|
+
"sourcesContent": ["import {\n HeaderCodec,\n codec,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-PFH3ROEH.cjs\";\nexport {\n HeaderCodec,\n codec,\n getUserFunctionUrlInMetadata,\n matchServiceCredential,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAQO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|