@immediately-run/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/MDXProvider.cjs +58 -0
- package/dist/MDXProvider.cjs.map +1 -0
- package/dist/MDXProvider.d.cts +6 -0
- package/dist/MDXProvider.d.ts +6 -0
- package/dist/MDXProvider.js +33 -0
- package/dist/MDXProvider.js.map +1 -0
- package/dist/RoutingSpec.cjs +17 -0
- package/dist/RoutingSpec.cjs.map +1 -0
- package/dist/RoutingSpec.d.cts +12 -0
- package/dist/RoutingSpec.d.ts +12 -0
- package/dist/RoutingSpec.js +1 -0
- package/dist/RoutingSpec.js.map +1 -0
- package/dist/TinkerableContext.cjs +30 -0
- package/dist/TinkerableContext.cjs.map +1 -0
- package/dist/TinkerableContext.d.cts +27 -0
- package/dist/TinkerableContext.d.ts +27 -0
- package/dist/TinkerableContext.js +6 -0
- package/dist/TinkerableContext.js.map +1 -0
- package/dist/boot.cjs +119 -0
- package/dist/boot.cjs.map +1 -0
- package/dist/boot.d.cts +15 -0
- package/dist/boot.d.ts +15 -0
- package/dist/boot.js +93 -0
- package/dist/boot.js.map +1 -0
- package/dist/components/FileRouter.cjs +53 -0
- package/dist/components/FileRouter.cjs.map +1 -0
- package/dist/components/FileRouter.d.cts +5 -0
- package/dist/components/FileRouter.d.ts +5 -0
- package/dist/components/FileRouter.js +29 -0
- package/dist/components/FileRouter.js.map +1 -0
- package/dist/components/Include.cjs +57 -0
- package/dist/components/Include.cjs.map +1 -0
- package/dist/components/Include.d.cts +23 -0
- package/dist/components/Include.d.ts +23 -0
- package/dist/components/Include.js +31 -0
- package/dist/components/Include.js.map +1 -0
- package/dist/components/MDXComponents.cjs +75 -0
- package/dist/components/MDXComponents.cjs.map +1 -0
- package/dist/components/MDXComponents.d.cts +10 -0
- package/dist/components/MDXComponents.d.ts +10 -0
- package/dist/components/MDXComponents.js +49 -0
- package/dist/components/MDXComponents.js.map +1 -0
- package/dist/components/MainContent.cjs +74 -0
- package/dist/components/MainContent.cjs.map +1 -0
- package/dist/components/MainContent.d.cts +16 -0
- package/dist/components/MainContent.d.ts +16 -0
- package/dist/components/MainContent.js +48 -0
- package/dist/components/MainContent.js.map +1 -0
- package/dist/components/defaults.cjs +36 -0
- package/dist/components/defaults.cjs.map +1 -0
- package/dist/components/defaults.d.cts +7 -0
- package/dist/components/defaults.d.ts +7 -0
- package/dist/components/defaults.js +11 -0
- package/dist/components/defaults.js.map +1 -0
- package/dist/components/errors.cjs +38 -0
- package/dist/components/errors.cjs.map +1 -0
- package/dist/components/errors.d.cts +5 -0
- package/dist/components/errors.d.ts +5 -0
- package/dist/components/errors.js +14 -0
- package/dist/components/errors.js.map +1 -0
- package/dist/contextUtils.cjs +60 -0
- package/dist/contextUtils.cjs.map +1 -0
- package/dist/contextUtils.d.cts +10 -0
- package/dist/contextUtils.d.ts +10 -0
- package/dist/contextUtils.js +34 -0
- package/dist/contextUtils.js.map +1 -0
- package/dist/hooks.cjs +75 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.cts +6 -0
- package/dist/hooks.d.ts +6 -0
- package/dist/hooks.js +50 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.cjs +35 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/moduleCache.cjs +66 -0
- package/dist/moduleCache.cjs.map +1 -0
- package/dist/moduleCache.d.cts +20 -0
- package/dist/moduleCache.d.ts +20 -0
- package/dist/moduleCache.js +40 -0
- package/dist/moduleCache.js.map +1 -0
- package/dist/pathUtils.cjs +63 -0
- package/dist/pathUtils.cjs.map +1 -0
- package/dist/pathUtils.d.cts +4 -0
- package/dist/pathUtils.d.ts +4 -0
- package/dist/pathUtils.js +38 -0
- package/dist/pathUtils.js.map +1 -0
- package/dist/routing.cjs +84 -0
- package/dist/routing.cjs.map +1 -0
- package/dist/routing.d.cts +15 -0
- package/dist/routing.d.ts +15 -0
- package/dist/routing.js +57 -0
- package/dist/routing.js.map +1 -0
- package/dist/sandboxTypes.cjs +17 -0
- package/dist/sandboxTypes.cjs.map +1 -0
- package/dist/sandboxTypes.d.cts +24 -0
- package/dist/sandboxTypes.d.ts +24 -0
- package/dist/sandboxTypes.js +1 -0
- package/dist/sandboxTypes.js.map +1 -0
- package/dist/sandboxUtils.cjs +46 -0
- package/dist/sandboxUtils.cjs.map +1 -0
- package/dist/sandboxUtils.d.cts +5 -0
- package/dist/sandboxUtils.d.ts +5 -0
- package/dist/sandboxUtils.js +20 -0
- package/dist/sandboxUtils.js.map +1 -0
- package/dist/urlUtils.cjs +159 -0
- package/dist/urlUtils.cjs.map +1 -0
- package/dist/urlUtils.d.cts +24 -0
- package/dist/urlUtils.d.ts +24 -0
- package/dist/urlUtils.js +124 -0
- package/dist/urlUtils.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { EvaluationContext } from './sandboxTypes.js';
|
|
5
|
+
|
|
6
|
+
declare class ModuleCache {
|
|
7
|
+
nameResolutionPromises: Record<string, Promise<string>>;
|
|
8
|
+
evaluationContextPromises: Record<string, Promise<EvaluationContext>>;
|
|
9
|
+
constructor();
|
|
10
|
+
private getCacheKey;
|
|
11
|
+
resolveModuleName(moduleName: string, baseModule?: EvaluationContext): Promise<string>;
|
|
12
|
+
getEvaluationContext(moduleName: string, baseModule?: EvaluationContext): Promise<EvaluationContext>;
|
|
13
|
+
}
|
|
14
|
+
declare const ModuleCacheContext: react.Context<ModuleCache | null>;
|
|
15
|
+
declare const ModuleCacheContextProvider: ({ children, moduleCache }: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
moduleCache: ModuleCache;
|
|
18
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
19
|
+
|
|
20
|
+
export { ModuleCache, ModuleCacheContext, ModuleCacheContextProvider };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
import { addListener } from "./sandboxUtils";
|
|
4
|
+
class ModuleCache {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.nameResolutionPromises = {};
|
|
7
|
+
this.evaluationContextPromises = {};
|
|
8
|
+
addListener("compile", () => {
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
getCacheKey(mod, moduleName) {
|
|
12
|
+
return `${mod.evaluation.module.filepath}|${moduleName}`;
|
|
13
|
+
}
|
|
14
|
+
resolveModuleName(moduleName, baseModule) {
|
|
15
|
+
const mod = baseModule ?? module;
|
|
16
|
+
const cacheKey = this.getCacheKey(mod, moduleName);
|
|
17
|
+
if (!(cacheKey in this.nameResolutionPromises)) {
|
|
18
|
+
this.nameResolutionPromises[cacheKey] = mod.resolve(moduleName);
|
|
19
|
+
}
|
|
20
|
+
return this.nameResolutionPromises[cacheKey];
|
|
21
|
+
}
|
|
22
|
+
getEvaluationContext(moduleName, baseModule) {
|
|
23
|
+
const mod = baseModule ?? module;
|
|
24
|
+
const cacheKey = this.getCacheKey(mod, moduleName);
|
|
25
|
+
if (!(cacheKey in this.evaluationContextPromises)) {
|
|
26
|
+
this.evaluationContextPromises[cacheKey] = mod.getModuleEvaluationContext(moduleName);
|
|
27
|
+
}
|
|
28
|
+
return this.evaluationContextPromises[cacheKey];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const ModuleCacheContext = createContext(null);
|
|
32
|
+
const ModuleCacheContextProvider = ({ children, moduleCache }) => {
|
|
33
|
+
return /* @__PURE__ */ jsx(ModuleCacheContext.Provider, { value: moduleCache, children });
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
ModuleCache,
|
|
37
|
+
ModuleCacheContext,
|
|
38
|
+
ModuleCacheContextProvider
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=moduleCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/moduleCache.tsx"],"sourcesContent":["// based on: https://www.bbss.dev/posts/react-learn-suspense/#fetchcache-provider\n\nimport { createContext, ReactNode, useCallback, useState } from \"react\"\nimport { EvaluationContext } from \"./sandboxTypes\";\nimport { addListener } from \"./sandboxUtils\";\n\nexport class ModuleCache {\n nameResolutionPromises: Record<string, Promise<string>> = {}\n evaluationContextPromises: Record<string, Promise<EvaluationContext>> = {}\n\n constructor() {\n // reset cache on compile\n addListener('compile', () => {\n // NOTE: THIS CAUSES AN UNNECESSARY RELOAD\n // the <Include> component's module evaluation context promise is replaced\n // with a new promise for the same value when a compilation occurs which\n // doesn't affect the current module. Commenting out the following lines\n // eliminates the unnecessary component state loss.\n // this.nameResolutionPromises = {};\n // this.evaluationContextPromises = {};\n })\n }\n\n private getCacheKey(mod:EvaluationContext, moduleName:string):string {\n return `${mod.evaluation.module.filepath}|${moduleName}`;\n }\n\n resolveModuleName(moduleName:string, baseModule?:EvaluationContext):Promise<string> {\n // note: uses current module as base module if none specified by caller\n // @ts-ignore\n const mod = baseModule ?? (module as EvaluationContext);\n const cacheKey = this.getCacheKey(mod, moduleName);\n if (!(cacheKey in this.nameResolutionPromises)) {\n this.nameResolutionPromises[cacheKey] = mod.resolve(moduleName);\n }\n return this.nameResolutionPromises[cacheKey];\n }\n\n getEvaluationContext(moduleName:string, baseModule?:EvaluationContext):Promise<EvaluationContext> {\n // note: uses current module as base module if none specified by caller\n // @ts-ignore\n const mod = baseModule ?? (module as EvaluationContext);\n const cacheKey = this.getCacheKey(mod, moduleName);\n if (!(cacheKey in this.evaluationContextPromises)) {\n this.evaluationContextPromises[cacheKey] = mod.getModuleEvaluationContext(moduleName);\n }\n return this.evaluationContextPromises[cacheKey];\n\n }\n}\n\nexport const ModuleCacheContext = createContext<null|ModuleCache>(null)\n\nexport const ModuleCacheContextProvider = ({ children, moduleCache }:{ children:ReactNode, moduleCache: ModuleCache }) => {\n\n return (\n <ModuleCacheContext.Provider value={moduleCache}>\n {children}\n </ModuleCacheContext.Provider>\n )\n}\n"],"mappings":"AAwDQ;AAtDR,SAAS,qBAAuD;AAEhE,SAAS,mBAAmB;AAErB,MAAM,YAAY;AAAA,EAIvB,cAAc;AAHd,kCAA0D,CAAC;AAC3D,qCAAwE,CAAC;AAIvE,gBAAY,WAAW,MAAM;AAAA,IAQ7B,CAAC;AAAA,EACH;AAAA,EAEQ,YAAY,KAAuB,YAA0B;AACnE,WAAO,GAAG,IAAI,WAAW,OAAO,QAAQ,IAAI,UAAU;AAAA,EACxD;AAAA,EAEA,kBAAkB,YAAmB,YAA+C;AAGlF,UAAM,MAAM,cAAe;AAC3B,UAAM,WAAW,KAAK,YAAY,KAAK,UAAU;AACjD,QAAI,EAAE,YAAY,KAAK,yBAAyB;AAC9C,WAAK,uBAAuB,QAAQ,IAAI,IAAI,QAAQ,UAAU;AAAA,IAChE;AACA,WAAO,KAAK,uBAAuB,QAAQ;AAAA,EAC7C;AAAA,EAEA,qBAAqB,YAAmB,YAA0D;AAGhG,UAAM,MAAM,cAAe;AAC3B,UAAM,WAAW,KAAK,YAAY,KAAK,UAAU;AACjD,QAAI,EAAE,YAAY,KAAK,4BAA4B;AACjD,WAAK,0BAA0B,QAAQ,IAAI,IAAI,2BAA2B,UAAU;AAAA,IACtF;AACA,WAAO,KAAK,0BAA0B,QAAQ;AAAA,EAEhD;AACF;AAEO,MAAM,qBAAqB,cAAgC,IAAI;AAE/D,MAAM,6BAA6B,CAAC,EAAE,UAAU,YAAY,MAAuD;AAEtH,SACI,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,aAC/B,UACL;AAER;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 pathUtils_exports = {};
|
|
20
|
+
__export(pathUtils_exports, {
|
|
21
|
+
absPath: () => absPath,
|
|
22
|
+
joinPaths: () => joinPaths
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(pathUtils_exports);
|
|
25
|
+
const PATH_SEPARATOR = "/";
|
|
26
|
+
const joinPaths = (...pathPart) => pathPart.reduce((acc, part) => {
|
|
27
|
+
const left = acc.endsWith(PATH_SEPARATOR) ? acc.slice(0, -1) : acc;
|
|
28
|
+
const right = part.startsWith(PATH_SEPARATOR) ? part.substring(1) : part;
|
|
29
|
+
if (left || acc === PATH_SEPARATOR) {
|
|
30
|
+
return `${left}${PATH_SEPARATOR}${right}`;
|
|
31
|
+
}
|
|
32
|
+
if (part.startsWith(PATH_SEPARATOR)) {
|
|
33
|
+
return `${PATH_SEPARATOR}${right}`;
|
|
34
|
+
}
|
|
35
|
+
return right;
|
|
36
|
+
}, "");
|
|
37
|
+
const absPath = (rawPath) => {
|
|
38
|
+
const absCandidate = joinPaths.apply(
|
|
39
|
+
null,
|
|
40
|
+
rawPath.split(PATH_SEPARATOR).reduce(
|
|
41
|
+
(partialAbsPath, currentPathPart) => {
|
|
42
|
+
if (currentPathPart == ".") {
|
|
43
|
+
return partialAbsPath;
|
|
44
|
+
}
|
|
45
|
+
if (currentPathPart == "..") {
|
|
46
|
+
return partialAbsPath.slice(0, -1);
|
|
47
|
+
}
|
|
48
|
+
return partialAbsPath.concat(currentPathPart);
|
|
49
|
+
},
|
|
50
|
+
[]
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
if (absCandidate === "" && rawPath.startsWith(PATH_SEPARATOR)) {
|
|
54
|
+
return PATH_SEPARATOR;
|
|
55
|
+
}
|
|
56
|
+
return absCandidate;
|
|
57
|
+
};
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
absPath,
|
|
61
|
+
joinPaths
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=pathUtils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pathUtils.ts"],"sourcesContent":["const PATH_SEPARATOR = \"/\";\n\nexport const joinPaths = (...pathPart: string[]) => pathPart.reduce((acc, part) => {\n const left = (acc.endsWith(PATH_SEPARATOR)) ? acc.slice(0, -1) : acc;\n const right = (part.startsWith(PATH_SEPARATOR)) ? part.substring(1) : part;\n if (left || acc === PATH_SEPARATOR) {\n return `${left}${PATH_SEPARATOR}${right}`;\n }\n if (part.startsWith(PATH_SEPARATOR)) {\n return `${PATH_SEPARATOR}${right}`;\n }\n return right;\n}, \"\");\n\nexport const absPath = (rawPath: string): string => {\n const absCandidate = joinPaths.apply(\n null,\n rawPath.split(PATH_SEPARATOR).reduce(\n (partialAbsPath: string[], currentPathPart: string) => {\n if (currentPathPart == '.') {\n return partialAbsPath;\n }\n if (currentPathPart == '..') {\n return partialAbsPath.slice(0, -1)\n }\n return partialAbsPath.concat(currentPathPart);\n },\n []\n ));\n if (absCandidate === '' && rawPath.startsWith(PATH_SEPARATOR)) {\n return PATH_SEPARATOR;\n }\n return absCandidate;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,iBAAiB;AAEhB,MAAM,YAAY,IAAI,aAAuB,SAAS,OAAO,CAAC,KAAK,SAAS;AACjF,QAAM,OAAQ,IAAI,SAAS,cAAc,IAAK,IAAI,MAAM,GAAG,EAAE,IAAI;AACjE,QAAM,QAAS,KAAK,WAAW,cAAc,IAAK,KAAK,UAAU,CAAC,IAAI;AACtE,MAAI,QAAQ,QAAQ,gBAAgB;AAClC,WAAO,GAAG,IAAI,GAAG,cAAc,GAAG,KAAK;AAAA,EACzC;AACA,MAAI,KAAK,WAAW,cAAc,GAAG;AACnC,WAAO,GAAG,cAAc,GAAG,KAAK;AAAA,EAClC;AACA,SAAO;AACT,GAAG,EAAE;AAEE,MAAM,UAAU,CAAC,YAA4B;AAClD,QAAM,eAAe,UAAU;AAAA,IAC7B;AAAA,IACA,QAAQ,MAAM,cAAc,EAAE;AAAA,MAC5B,CAAC,gBAA0B,oBAA4B;AACrD,YAAI,mBAAmB,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,YAAI,mBAAmB,MAAM;AAC3B,iBAAO,eAAe,MAAM,GAAG,EAAE;AAAA,QACnC;AACA,eAAO,eAAe,OAAO,eAAe;AAAA,MAC9C;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EAAC;AACH,MAAI,iBAAiB,MAAM,QAAQ,WAAW,cAAc,GAAG;AAC7D,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const PATH_SEPARATOR = "/";
|
|
2
|
+
const joinPaths = (...pathPart) => pathPart.reduce((acc, part) => {
|
|
3
|
+
const left = acc.endsWith(PATH_SEPARATOR) ? acc.slice(0, -1) : acc;
|
|
4
|
+
const right = part.startsWith(PATH_SEPARATOR) ? part.substring(1) : part;
|
|
5
|
+
if (left || acc === PATH_SEPARATOR) {
|
|
6
|
+
return `${left}${PATH_SEPARATOR}${right}`;
|
|
7
|
+
}
|
|
8
|
+
if (part.startsWith(PATH_SEPARATOR)) {
|
|
9
|
+
return `${PATH_SEPARATOR}${right}`;
|
|
10
|
+
}
|
|
11
|
+
return right;
|
|
12
|
+
}, "");
|
|
13
|
+
const absPath = (rawPath) => {
|
|
14
|
+
const absCandidate = joinPaths.apply(
|
|
15
|
+
null,
|
|
16
|
+
rawPath.split(PATH_SEPARATOR).reduce(
|
|
17
|
+
(partialAbsPath, currentPathPart) => {
|
|
18
|
+
if (currentPathPart == ".") {
|
|
19
|
+
return partialAbsPath;
|
|
20
|
+
}
|
|
21
|
+
if (currentPathPart == "..") {
|
|
22
|
+
return partialAbsPath.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
return partialAbsPath.concat(currentPathPart);
|
|
25
|
+
},
|
|
26
|
+
[]
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
if (absCandidate === "" && rawPath.startsWith(PATH_SEPARATOR)) {
|
|
30
|
+
return PATH_SEPARATOR;
|
|
31
|
+
}
|
|
32
|
+
return absCandidate;
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
absPath,
|
|
36
|
+
joinPaths
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=pathUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pathUtils.ts"],"sourcesContent":["const PATH_SEPARATOR = \"/\";\n\nexport const joinPaths = (...pathPart: string[]) => pathPart.reduce((acc, part) => {\n const left = (acc.endsWith(PATH_SEPARATOR)) ? acc.slice(0, -1) : acc;\n const right = (part.startsWith(PATH_SEPARATOR)) ? part.substring(1) : part;\n if (left || acc === PATH_SEPARATOR) {\n return `${left}${PATH_SEPARATOR}${right}`;\n }\n if (part.startsWith(PATH_SEPARATOR)) {\n return `${PATH_SEPARATOR}${right}`;\n }\n return right;\n}, \"\");\n\nexport const absPath = (rawPath: string): string => {\n const absCandidate = joinPaths.apply(\n null,\n rawPath.split(PATH_SEPARATOR).reduce(\n (partialAbsPath: string[], currentPathPart: string) => {\n if (currentPathPart == '.') {\n return partialAbsPath;\n }\n if (currentPathPart == '..') {\n return partialAbsPath.slice(0, -1)\n }\n return partialAbsPath.concat(currentPathPart);\n },\n []\n ));\n if (absCandidate === '' && rawPath.startsWith(PATH_SEPARATOR)) {\n return PATH_SEPARATOR;\n }\n return absCandidate;\n}\n"],"mappings":"AAAA,MAAM,iBAAiB;AAEhB,MAAM,YAAY,IAAI,aAAuB,SAAS,OAAO,CAAC,KAAK,SAAS;AACjF,QAAM,OAAQ,IAAI,SAAS,cAAc,IAAK,IAAI,MAAM,GAAG,EAAE,IAAI;AACjE,QAAM,QAAS,KAAK,WAAW,cAAc,IAAK,KAAK,UAAU,CAAC,IAAI;AACtE,MAAI,QAAQ,QAAQ,gBAAgB;AAClC,WAAO,GAAG,IAAI,GAAG,cAAc,GAAG,KAAK;AAAA,EACzC;AACA,MAAI,KAAK,WAAW,cAAc,GAAG;AACnC,WAAO,GAAG,cAAc,GAAG,KAAK;AAAA,EAClC;AACA,SAAO;AACT,GAAG,EAAE;AAEE,MAAM,UAAU,CAAC,YAA4B;AAClD,QAAM,eAAe,UAAU;AAAA,IAC7B;AAAA,IACA,QAAQ,MAAM,cAAc,EAAE;AAAA,MAC5B,CAAC,gBAA0B,oBAA4B;AACrD,YAAI,mBAAmB,KAAK;AAC1B,iBAAO;AAAA,QACT;AACA,YAAI,mBAAmB,MAAM;AAC3B,iBAAO,eAAe,MAAM,GAAG,EAAE;AAAA,QACnC;AACA,eAAO,eAAe,OAAO,eAAe;AAAA,MAC9C;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EAAC;AACH,MAAI,iBAAiB,MAAM,QAAQ,WAAW,cAAc,GAAG;AAC7D,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
|
package/dist/routing.cjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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 routing_exports = {};
|
|
20
|
+
__export(routing_exports, {
|
|
21
|
+
Router: () => Router,
|
|
22
|
+
applyRoutingRule: () => applyRoutingRule,
|
|
23
|
+
navigate: () => navigate,
|
|
24
|
+
useTinkerableLink: () => useTinkerableLink
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(routing_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_sandboxUtils = require("./sandboxUtils");
|
|
29
|
+
var import_TinkerableContext = require("./TinkerableContext");
|
|
30
|
+
var import_urlUtils = require("./urlUtils");
|
|
31
|
+
var import_pathUtils = require("./pathUtils");
|
|
32
|
+
const useTinkerableLink = (newSandboxLocation) => {
|
|
33
|
+
const { outerHref, navigationState: navigation } = (0, import_react.use)(import_TinkerableContext.TinkerableContext);
|
|
34
|
+
let newNavigationState = (0, import_urlUtils.parseTarget)(newSandboxLocation, navigation);
|
|
35
|
+
if (!(0, import_urlUtils.isAbsolutePath)(newSandboxLocation)) {
|
|
36
|
+
newNavigationState.sandboxPath = (0, import_pathUtils.joinPaths)(navigation.sandboxPath, newSandboxLocation);
|
|
37
|
+
} else {
|
|
38
|
+
newNavigationState.sandboxPath = newSandboxLocation;
|
|
39
|
+
}
|
|
40
|
+
return (0, import_urlUtils.constructUrl)(outerHref, newNavigationState);
|
|
41
|
+
};
|
|
42
|
+
const applyRoutingRule = (routingSpec, navigationState) => {
|
|
43
|
+
const { sandboxPath } = navigationState;
|
|
44
|
+
for (const routingRule of routingSpec.routes) {
|
|
45
|
+
if (typeof routingRule.pattern === "string") {
|
|
46
|
+
if (routingRule.pattern === sandboxPath) {
|
|
47
|
+
return { routingRule };
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
const match = sandboxPath.match(routingRule.pattern);
|
|
51
|
+
if (routingRule.pattern.test(sandboxPath)) {
|
|
52
|
+
return {
|
|
53
|
+
routingRule,
|
|
54
|
+
pathParameters: match?.groups
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
60
|
+
};
|
|
61
|
+
const Router = () => {
|
|
62
|
+
const context = (0, import_react.useContext)(import_TinkerableContext.TinkerableContext);
|
|
63
|
+
const { navigationState: { routingRule } } = context;
|
|
64
|
+
if (!routingRule) {
|
|
65
|
+
throw new Error(`No route registered for path ${context.navigationState.sandboxPath}!`);
|
|
66
|
+
}
|
|
67
|
+
return routingRule.reactNode;
|
|
68
|
+
};
|
|
69
|
+
const navigate = (target) => {
|
|
70
|
+
console.log(`[Sandbox] Navigating to ${target}`);
|
|
71
|
+
(0, import_sandboxUtils.sendMessage)("urlchange", {
|
|
72
|
+
url: target,
|
|
73
|
+
back: false,
|
|
74
|
+
forward: false
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
Router,
|
|
80
|
+
applyRoutingRule,
|
|
81
|
+
navigate,
|
|
82
|
+
useTinkerableLink
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=routing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routing.tsx"],"sourcesContent":["import { use, useContext } from 'react';\n\nimport { sendMessage } from './sandboxUtils';\nimport { NavigationState, TinkerableContext } from './TinkerableContext';\nimport { RoutingRule, RoutingSpec } from './RoutingSpec';\nimport { constructUrl, isAbsolutePath, parseTarget } from './urlUtils';\nimport { joinPaths } from './pathUtils';\n\nexport type AppliedRoutingRule = {\n routingRule: RoutingRule,\n pathParameters?: Record<string, string>;\n}\n\nexport const useTinkerableLink = (newSandboxLocation: string) => {\n const { outerHref, navigationState: navigation } = use(TinkerableContext);\n let newNavigationState = parseTarget(newSandboxLocation, navigation);\n if (!isAbsolutePath(newSandboxLocation)) {\n newNavigationState.sandboxPath = joinPaths(navigation.sandboxPath, newSandboxLocation)\n } else {\n newNavigationState.sandboxPath = newSandboxLocation\n }\n return constructUrl(outerHref, newNavigationState);\n}\n\nexport const applyRoutingRule = (routingSpec:RoutingSpec, navigationState: NavigationState): AppliedRoutingRule | undefined => {\n const { sandboxPath } = navigationState;\n for (const routingRule of routingSpec.routes) {\n if (typeof routingRule.pattern === 'string') {\n if (routingRule.pattern === sandboxPath) {\n return {routingRule};\n }\n } else {\n const match = sandboxPath.match(routingRule.pattern);\n if (routingRule.pattern.test(sandboxPath)) {\n return {\n routingRule,\n pathParameters: match?.groups\n }\n }\n }\n }\n return undefined;\n}\n\nexport const Router = () => {\n const context = useContext(TinkerableContext);\n const {navigationState: {routingRule}} = context;\n if (!routingRule) {\n // TODO: better error\n throw new Error(`No route registered for path ${context.navigationState.sandboxPath}!`);\n }\n\n return routingRule.reactNode;\n};\n\n\n// Perform in-site navigation.\n// Top level frame is messaged to updated URL, after which a message will be\n// sent wit the new href, triggering the actual navigation.\nexport const navigate = (target: string) => {\n console.log(`[Sandbox] Navigating to ${target}`)\n sendMessage('urlchange', {\n url: target,\n back: false,\n forward: false,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAEhC,0BAA4B;AAC5B,+BAAmD;AAEnD,sBAA0D;AAC1D,uBAA0B;AAOnB,MAAM,oBAAoB,CAAC,uBAA+B;AAC/D,QAAM,EAAE,WAAW,iBAAiB,WAAW,QAAI,kBAAI,0CAAiB;AACxE,MAAI,yBAAqB,6BAAY,oBAAoB,UAAU;AACnE,MAAI,KAAC,gCAAe,kBAAkB,GAAG;AACvC,uBAAmB,kBAAc,4BAAU,WAAW,aAAa,kBAAkB;AAAA,EACvF,OAAO;AACL,uBAAmB,cAAc;AAAA,EACnC;AACA,aAAO,8BAAa,WAAW,kBAAkB;AACnD;AAEO,MAAM,mBAAmB,CAAC,aAAyB,oBAAqE;AAC7H,QAAM,EAAE,YAAY,IAAI;AACxB,aAAW,eAAe,YAAY,QAAQ;AAC5C,QAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,UAAI,YAAY,YAAY,aAAa;AACvC,eAAO,EAAC,YAAW;AAAA,MACrB;AAAA,IACF,OAAO;AACL,YAAM,QAAQ,YAAY,MAAM,YAAY,OAAO;AACnD,UAAI,YAAY,QAAQ,KAAK,WAAW,GAAG;AACzC,eAAO;AAAA,UACL;AAAA,UACA,gBAAgB,OAAO;AAAA,QACzB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,SAAS,MAAM;AAC1B,QAAM,cAAU,yBAAW,0CAAiB;AAC5C,QAAM,EAAC,iBAAiB,EAAC,YAAW,EAAC,IAAI;AACzC,MAAI,CAAC,aAAa;AAEhB,UAAM,IAAI,MAAM,gCAAgC,QAAQ,gBAAgB,WAAW,GAAG;AAAA,EACxF;AAEA,SAAO,YAAY;AACrB;AAMO,MAAM,WAAW,CAAC,WAAmB;AAC1C,UAAQ,IAAI,2BAA2B,MAAM,EAAE;AAC/C,uCAAY,aAAa;AAAA,IACvB,KAAK;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { NavigationState } from './TinkerableContext.cjs';
|
|
3
|
+
import { RoutingRule, RoutingSpec } from './RoutingSpec.cjs';
|
|
4
|
+
import './sandboxTypes.cjs';
|
|
5
|
+
|
|
6
|
+
type AppliedRoutingRule = {
|
|
7
|
+
routingRule: RoutingRule;
|
|
8
|
+
pathParameters?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
declare const useTinkerableLink: (newSandboxLocation: string) => string;
|
|
11
|
+
declare const applyRoutingRule: (routingSpec: RoutingSpec, navigationState: NavigationState) => AppliedRoutingRule | undefined;
|
|
12
|
+
declare const Router: () => react.ReactNode;
|
|
13
|
+
declare const navigate: (target: string) => void;
|
|
14
|
+
|
|
15
|
+
export { type AppliedRoutingRule, Router, applyRoutingRule, navigate, useTinkerableLink };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { NavigationState } from './TinkerableContext.js';
|
|
3
|
+
import { RoutingRule, RoutingSpec } from './RoutingSpec.js';
|
|
4
|
+
import './sandboxTypes.js';
|
|
5
|
+
|
|
6
|
+
type AppliedRoutingRule = {
|
|
7
|
+
routingRule: RoutingRule;
|
|
8
|
+
pathParameters?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
declare const useTinkerableLink: (newSandboxLocation: string) => string;
|
|
11
|
+
declare const applyRoutingRule: (routingSpec: RoutingSpec, navigationState: NavigationState) => AppliedRoutingRule | undefined;
|
|
12
|
+
declare const Router: () => react.ReactNode;
|
|
13
|
+
declare const navigate: (target: string) => void;
|
|
14
|
+
|
|
15
|
+
export { type AppliedRoutingRule, Router, applyRoutingRule, navigate, useTinkerableLink };
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { use, useContext } from "react";
|
|
2
|
+
import { sendMessage } from "./sandboxUtils";
|
|
3
|
+
import { TinkerableContext } from "./TinkerableContext";
|
|
4
|
+
import { constructUrl, isAbsolutePath, parseTarget } from "./urlUtils";
|
|
5
|
+
import { joinPaths } from "./pathUtils";
|
|
6
|
+
const useTinkerableLink = (newSandboxLocation) => {
|
|
7
|
+
const { outerHref, navigationState: navigation } = use(TinkerableContext);
|
|
8
|
+
let newNavigationState = parseTarget(newSandboxLocation, navigation);
|
|
9
|
+
if (!isAbsolutePath(newSandboxLocation)) {
|
|
10
|
+
newNavigationState.sandboxPath = joinPaths(navigation.sandboxPath, newSandboxLocation);
|
|
11
|
+
} else {
|
|
12
|
+
newNavigationState.sandboxPath = newSandboxLocation;
|
|
13
|
+
}
|
|
14
|
+
return constructUrl(outerHref, newNavigationState);
|
|
15
|
+
};
|
|
16
|
+
const applyRoutingRule = (routingSpec, navigationState) => {
|
|
17
|
+
const { sandboxPath } = navigationState;
|
|
18
|
+
for (const routingRule of routingSpec.routes) {
|
|
19
|
+
if (typeof routingRule.pattern === "string") {
|
|
20
|
+
if (routingRule.pattern === sandboxPath) {
|
|
21
|
+
return { routingRule };
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
const match = sandboxPath.match(routingRule.pattern);
|
|
25
|
+
if (routingRule.pattern.test(sandboxPath)) {
|
|
26
|
+
return {
|
|
27
|
+
routingRule,
|
|
28
|
+
pathParameters: match?.groups
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
};
|
|
35
|
+
const Router = () => {
|
|
36
|
+
const context = useContext(TinkerableContext);
|
|
37
|
+
const { navigationState: { routingRule } } = context;
|
|
38
|
+
if (!routingRule) {
|
|
39
|
+
throw new Error(`No route registered for path ${context.navigationState.sandboxPath}!`);
|
|
40
|
+
}
|
|
41
|
+
return routingRule.reactNode;
|
|
42
|
+
};
|
|
43
|
+
const navigate = (target) => {
|
|
44
|
+
console.log(`[Sandbox] Navigating to ${target}`);
|
|
45
|
+
sendMessage("urlchange", {
|
|
46
|
+
url: target,
|
|
47
|
+
back: false,
|
|
48
|
+
forward: false
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
Router,
|
|
53
|
+
applyRoutingRule,
|
|
54
|
+
navigate,
|
|
55
|
+
useTinkerableLink
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routing.tsx"],"sourcesContent":["import { use, useContext } from 'react';\n\nimport { sendMessage } from './sandboxUtils';\nimport { NavigationState, TinkerableContext } from './TinkerableContext';\nimport { RoutingRule, RoutingSpec } from './RoutingSpec';\nimport { constructUrl, isAbsolutePath, parseTarget } from './urlUtils';\nimport { joinPaths } from './pathUtils';\n\nexport type AppliedRoutingRule = {\n routingRule: RoutingRule,\n pathParameters?: Record<string, string>;\n}\n\nexport const useTinkerableLink = (newSandboxLocation: string) => {\n const { outerHref, navigationState: navigation } = use(TinkerableContext);\n let newNavigationState = parseTarget(newSandboxLocation, navigation);\n if (!isAbsolutePath(newSandboxLocation)) {\n newNavigationState.sandboxPath = joinPaths(navigation.sandboxPath, newSandboxLocation)\n } else {\n newNavigationState.sandboxPath = newSandboxLocation\n }\n return constructUrl(outerHref, newNavigationState);\n}\n\nexport const applyRoutingRule = (routingSpec:RoutingSpec, navigationState: NavigationState): AppliedRoutingRule | undefined => {\n const { sandboxPath } = navigationState;\n for (const routingRule of routingSpec.routes) {\n if (typeof routingRule.pattern === 'string') {\n if (routingRule.pattern === sandboxPath) {\n return {routingRule};\n }\n } else {\n const match = sandboxPath.match(routingRule.pattern);\n if (routingRule.pattern.test(sandboxPath)) {\n return {\n routingRule,\n pathParameters: match?.groups\n }\n }\n }\n }\n return undefined;\n}\n\nexport const Router = () => {\n const context = useContext(TinkerableContext);\n const {navigationState: {routingRule}} = context;\n if (!routingRule) {\n // TODO: better error\n throw new Error(`No route registered for path ${context.navigationState.sandboxPath}!`);\n }\n\n return routingRule.reactNode;\n};\n\n\n// Perform in-site navigation.\n// Top level frame is messaged to updated URL, after which a message will be\n// sent wit the new href, triggering the actual navigation.\nexport const navigate = (target: string) => {\n console.log(`[Sandbox] Navigating to ${target}`)\n sendMessage('urlchange', {\n url: target,\n back: false,\n forward: false,\n });\n};\n"],"mappings":"AAAA,SAAS,KAAK,kBAAkB;AAEhC,SAAS,mBAAmB;AAC5B,SAA0B,yBAAyB;AAEnD,SAAS,cAAc,gBAAgB,mBAAmB;AAC1D,SAAS,iBAAiB;AAOnB,MAAM,oBAAoB,CAAC,uBAA+B;AAC/D,QAAM,EAAE,WAAW,iBAAiB,WAAW,IAAI,IAAI,iBAAiB;AACxE,MAAI,qBAAqB,YAAY,oBAAoB,UAAU;AACnE,MAAI,CAAC,eAAe,kBAAkB,GAAG;AACvC,uBAAmB,cAAc,UAAU,WAAW,aAAa,kBAAkB;AAAA,EACvF,OAAO;AACL,uBAAmB,cAAc;AAAA,EACnC;AACA,SAAO,aAAa,WAAW,kBAAkB;AACnD;AAEO,MAAM,mBAAmB,CAAC,aAAyB,oBAAqE;AAC7H,QAAM,EAAE,YAAY,IAAI;AACxB,aAAW,eAAe,YAAY,QAAQ;AAC5C,QAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,UAAI,YAAY,YAAY,aAAa;AACvC,eAAO,EAAC,YAAW;AAAA,MACrB;AAAA,IACF,OAAO;AACL,YAAM,QAAQ,YAAY,MAAM,YAAY,OAAO;AACnD,UAAI,YAAY,QAAQ,KAAK,WAAW,GAAG;AACzC,eAAO;AAAA,UACL;AAAA,UACA,gBAAgB,OAAO;AAAA,QACzB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,SAAS,MAAM;AAC1B,QAAM,UAAU,WAAW,iBAAiB;AAC5C,QAAM,EAAC,iBAAiB,EAAC,YAAW,EAAC,IAAI;AACzC,MAAI,CAAC,aAAa;AAEhB,UAAM,IAAI,MAAM,gCAAgC,QAAQ,gBAAgB,WAAW,GAAG;AAAA,EACxF;AAEA,SAAO,YAAY;AACrB;AAMO,MAAM,WAAW,CAAC,WAAmB;AAC1C,UAAQ,IAAI,2BAA2B,MAAM,EAAE;AAC/C,cAAY,aAAa;AAAA,IACvB,KAAK;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var sandboxTypes_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(sandboxTypes_exports);
|
|
17
|
+
//# sourceMappingURL=sandboxTypes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sandboxTypes.ts"],"sourcesContent":["export type ModuleExports = any\n\n// The real type is EvaluationContext from src/bundler/module/Evaluation.ts:6\nexport type EvaluationContext = {\n exports: ModuleExports;\n dynamicImport: (moduleToImport: string, symbolToImport:string) => Promise<ModuleExports>;\n getModuleEvaluationContext: (moduleName: string) => Promise<EvaluationContext>;\n resolve: (moduleName: string) => Promise<string>;\n evaluation: {\n module: {\n source: string;\n filepath: string;\n }\n }\n}\n\nexport type Metadata = Record<string, any>;\nexport type FilesMetadata = Record<string, Metadata>;\nexport type FileQueryResult = string[]\nexport type MetadataQueryFunction = (filesMetadata:FilesMetadata) => FileQueryResult;\nexport type MetadataQueryResult = {result: FileQueryResult} | {error: any}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type ModuleExports = any;
|
|
2
|
+
type EvaluationContext = {
|
|
3
|
+
exports: ModuleExports;
|
|
4
|
+
dynamicImport: (moduleToImport: string, symbolToImport: string) => Promise<ModuleExports>;
|
|
5
|
+
getModuleEvaluationContext: (moduleName: string) => Promise<EvaluationContext>;
|
|
6
|
+
resolve: (moduleName: string) => Promise<string>;
|
|
7
|
+
evaluation: {
|
|
8
|
+
module: {
|
|
9
|
+
source: string;
|
|
10
|
+
filepath: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type Metadata = Record<string, any>;
|
|
15
|
+
type FilesMetadata = Record<string, Metadata>;
|
|
16
|
+
type FileQueryResult = string[];
|
|
17
|
+
type MetadataQueryFunction = (filesMetadata: FilesMetadata) => FileQueryResult;
|
|
18
|
+
type MetadataQueryResult = {
|
|
19
|
+
result: FileQueryResult;
|
|
20
|
+
} | {
|
|
21
|
+
error: any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type ModuleExports = any;
|
|
2
|
+
type EvaluationContext = {
|
|
3
|
+
exports: ModuleExports;
|
|
4
|
+
dynamicImport: (moduleToImport: string, symbolToImport: string) => Promise<ModuleExports>;
|
|
5
|
+
getModuleEvaluationContext: (moduleName: string) => Promise<EvaluationContext>;
|
|
6
|
+
resolve: (moduleName: string) => Promise<string>;
|
|
7
|
+
evaluation: {
|
|
8
|
+
module: {
|
|
9
|
+
source: string;
|
|
10
|
+
filepath: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type Metadata = Record<string, any>;
|
|
15
|
+
type FilesMetadata = Record<string, Metadata>;
|
|
16
|
+
type FileQueryResult = string[];
|
|
17
|
+
type MetadataQueryFunction = (filesMetadata: FilesMetadata) => FileQueryResult;
|
|
18
|
+
type MetadataQueryResult = {
|
|
19
|
+
result: FileQueryResult;
|
|
20
|
+
} | {
|
|
21
|
+
error: any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=sandboxTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 sandboxUtils_exports = {};
|
|
20
|
+
__export(sandboxUtils_exports, {
|
|
21
|
+
addListener: () => addListener,
|
|
22
|
+
protocolRequest: () => protocolRequest,
|
|
23
|
+
sendMessage: () => sendMessage
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(sandboxUtils_exports);
|
|
26
|
+
const sendMessage = (type, data = {}) => {
|
|
27
|
+
module.evaluation.module.bundler.messageBus.sendMessage(type, data);
|
|
28
|
+
};
|
|
29
|
+
const protocolRequest = (protocolName, method, params) => {
|
|
30
|
+
return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);
|
|
31
|
+
};
|
|
32
|
+
const addListener = (msgType, handler, event) => {
|
|
33
|
+
const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {
|
|
34
|
+
if (msg.type === msgType) {
|
|
35
|
+
handler(msg);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return () => disposable.dispose();
|
|
39
|
+
};
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
addListener,
|
|
43
|
+
protocolRequest,
|
|
44
|
+
sendMessage
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=sandboxUtils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["export const sendMessage = (type: string, data: Record<string, any> = {}) => {\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n module.evaluation.module.bundler.messageBus.sendMessage(type, data);\n}\n\nexport const protocolRequest = (protocolName: string, method: string, params: Array<any>): Promise<any> => {\n // example usage: const response = await protocolRequest('fs', 'readFile', [path]);\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);\n}\n\nexport const addListener = (msgType: string, handler: (msg:any)=>void, event?:any):(() => void) => {\n // @ts-ignore\n const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAG3E,SAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,MAAM,IAAI;AACpE;AAEO,MAAM,kBAAkB,CAAC,cAAsB,QAAgB,WAAqC;AAIzG,SAAO,OAAO,WAAW,OAAO,QAAQ,WAAW,gBAAgB,cAAc,QAAQ,MAAM;AACjG;AAEO,MAAM,cAAc,CAAC,SAAiB,SAA0B,UAA4B;AAEjG,QAAM,cAAc,SAAS,OAAO,WAAW,OAAO,QAAQ,WAAW,WAAW,CAAC,QAAQ;AAC3F,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const sendMessage: (type: string, data?: Record<string, any>) => void;
|
|
2
|
+
declare const protocolRequest: (protocolName: string, method: string, params: Array<any>) => Promise<any>;
|
|
3
|
+
declare const addListener: (msgType: string, handler: (msg: any) => void, event?: any) => (() => void);
|
|
4
|
+
|
|
5
|
+
export { addListener, protocolRequest, sendMessage };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const sendMessage: (type: string, data?: Record<string, any>) => void;
|
|
2
|
+
declare const protocolRequest: (protocolName: string, method: string, params: Array<any>) => Promise<any>;
|
|
3
|
+
declare const addListener: (msgType: string, handler: (msg: any) => void, event?: any) => (() => void);
|
|
4
|
+
|
|
5
|
+
export { addListener, protocolRequest, sendMessage };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const sendMessage = (type, data = {}) => {
|
|
2
|
+
module.evaluation.module.bundler.messageBus.sendMessage(type, data);
|
|
3
|
+
};
|
|
4
|
+
const protocolRequest = (protocolName, method, params) => {
|
|
5
|
+
return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);
|
|
6
|
+
};
|
|
7
|
+
const addListener = (msgType, handler, event) => {
|
|
8
|
+
const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {
|
|
9
|
+
if (msg.type === msgType) {
|
|
10
|
+
handler(msg);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return () => disposable.dispose();
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
addListener,
|
|
17
|
+
protocolRequest,
|
|
18
|
+
sendMessage
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=sandboxUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["export const sendMessage = (type: string, data: Record<string, any> = {}) => {\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n module.evaluation.module.bundler.messageBus.sendMessage(type, data);\n}\n\nexport const protocolRequest = (protocolName: string, method: string, params: Array<any>): Promise<any> => {\n // example usage: const response = await protocolRequest('fs', 'readFile', [path]);\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);\n}\n\nexport const addListener = (msgType: string, handler: (msg:any)=>void, event?:any):(() => void) => {\n // @ts-ignore\n const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n}\n"],"mappings":"AAAO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAG3E,SAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,MAAM,IAAI;AACpE;AAEO,MAAM,kBAAkB,CAAC,cAAsB,QAAgB,WAAqC;AAIzG,SAAO,OAAO,WAAW,OAAO,QAAQ,WAAW,gBAAgB,cAAc,QAAQ,MAAM;AACjG;AAEO,MAAM,cAAc,CAAC,SAAiB,SAA0B,UAA4B;AAEjG,QAAM,cAAc,SAAS,OAAO,WAAW,OAAO,QAAQ,WAAW,WAAW,CAAC,QAAQ;AAC3F,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
|