@expofp/loader 1.0.56 → 1.0.58
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/dist/bundle/bundle.js +829 -0
- package/dist/bundle/bundle.js.map +1 -0
- package/dist/{downloadZip-D1Leqczj.js → bundle/downloadZip-BbVnryS9.js} +332 -335
- package/dist/bundle/downloadZip-BbVnryS9.js.map +1 -0
- package/dist/{makeOffline-DdJq2uGI.js → bundle/makeOffline-DuRXI_Dd.js} +2 -2
- package/dist/bundle/makeOffline-DuRXI_Dd.js.map +1 -0
- package/dist/{makeOfflineBundle-CdE5LdlF.js → bundle/makeOfflineBundle-XjvmvDQE.js} +3 -3
- package/dist/bundle/makeOfflineBundle-XjvmvDQE.js.map +1 -0
- package/dist/{importJson.d.ts → esm/importJson.d.ts} +1 -1
- package/dist/esm/importJson.js +52 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/loadAndWaitGlobal.js +157 -0
- package/dist/esm/logger.d.ts +2 -0
- package/dist/esm/logger.js +2 -0
- package/dist/{mutateManifest.d.ts → esm/mutateManifest.d.ts} +1 -1
- package/dist/esm/mutateManifest.js +10 -0
- package/dist/esm/offline/downloadZip copy.js +89 -0
- package/dist/esm/offline/downloadZip.js +18 -0
- package/dist/esm/offline/hashString.js +16 -0
- package/dist/esm/offline/index.js +29 -0
- package/dist/{offline → esm/offline}/makeOffline.d.ts +1 -1
- package/dist/esm/offline/makeOffline.js +134 -0
- package/dist/esm/offline/makeOfflineBundle copy.js +92 -0
- package/dist/esm/offline/makeOfflineBundle.js +64 -0
- package/dist/esm/offline/slugify.js +61 -0
- package/dist/esm/offline/tools.js +69 -0
- package/dist/{resolve.d.ts → esm/resolve.d.ts} +1 -1
- package/dist/esm/resolve.js +331 -0
- package/dist/esm/resolvers/_OLD_expoResolver.js +49 -0
- package/dist/esm/resolvers/assetResolver.js +26 -0
- package/dist/{resolvers → esm/resolvers}/bundleAssetsResolver.d.ts +1 -1
- package/dist/esm/resolvers/bundleAssetsResolver.js +20 -0
- package/dist/{resolvers → esm/resolvers}/expoRuntimeBranchResolver.d.ts +1 -1
- package/dist/esm/resolvers/expoRuntimeBranchResolver.js +20 -0
- package/dist/{resolvers → esm/resolvers}/expoRuntimeGetBranchResolver.d.ts +1 -1
- package/dist/esm/resolvers/expoRuntimeGetBranchResolver.js +14 -0
- package/dist/{resolvers → esm/resolvers}/expoRuntimeResolver.d.ts +1 -1
- package/dist/esm/resolvers/expoRuntimeResolver.js +38 -0
- package/dist/{resolvers → esm/resolvers}/httpResolver.d.ts +1 -1
- package/dist/esm/resolvers/httpResolver.js +14 -0
- package/dist/{resolvers → esm/resolvers}/index.d.ts +1 -1
- package/dist/esm/resolvers/index.js +18 -0
- package/dist/{resolvers → esm/resolvers}/legacyAssetUrlsResolver.d.ts +1 -1
- package/dist/esm/resolvers/legacyAssetUrlsResolver.js +103 -0
- package/dist/{resolvers → esm/resolvers}/legacyDataResolver.d.ts +1 -1
- package/dist/esm/resolvers/legacyDataResolver.js +17 -0
- package/dist/esm/returnCachedRef.js +12 -0
- package/dist/esm/shared.js +271 -0
- package/dist/{types.d.ts → esm/types.d.ts} +1 -1
- package/dist/esm/types.js +1 -0
- package/package.json +15 -11
- package/dist/downloadZip-D1Leqczj.js.map +0 -1
- package/dist/index.js +0 -502
- package/dist/index.js.map +0 -1
- package/dist/makeOffline-DdJq2uGI.js.map +0 -1
- package/dist/makeOfflineBundle-CdE5LdlF.js.map +0 -1
- /package/dist/{index.d.ts → esm/index.d.ts} +0 -0
- /package/dist/{loadAndWaitGlobal.d.ts → esm/loadAndWaitGlobal.d.ts} +0 -0
- /package/dist/{offline → esm/offline}/downloadZip copy.d.ts +0 -0
- /package/dist/{offline → esm/offline}/downloadZip.d.ts +0 -0
- /package/dist/{offline → esm/offline}/hashString.d.ts +0 -0
- /package/dist/{offline → esm/offline}/index.d.ts +0 -0
- /package/dist/{offline → esm/offline}/makeOfflineBundle copy.d.ts +0 -0
- /package/dist/{offline → esm/offline}/makeOfflineBundle.d.ts +0 -0
- /package/dist/{offline → esm/offline}/slugify.d.ts +0 -0
- /package/dist/{offline → esm/offline}/tools.d.ts +0 -0
- /package/dist/{resolvers → esm/resolvers}/_OLD_expoResolver.d.ts +0 -0
- /package/dist/{resolvers → esm/resolvers}/assetResolver.d.ts +0 -0
- /package/dist/{returnCachedRef.d.ts → esm/returnCachedRef.d.ts} +0 -0
- /package/dist/{shared.d.ts → esm/shared.d.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseRefValue } from '../resolve';
|
|
2
|
+
import { log } from '../shared';
|
|
3
|
+
export function resolveAssetRefSync(ref) {
|
|
4
|
+
log('assetResolver resolveRef:', ref);
|
|
5
|
+
// if (!assetResolver.canResolve(ref)) throw new Error(`Unexpected ref: ${ref}`);
|
|
6
|
+
return parseRefValue(ref);
|
|
7
|
+
}
|
|
8
|
+
export const assetResolver = {
|
|
9
|
+
schema: 'asset',
|
|
10
|
+
resolveRef: async (ref) => resolveAssetRefSync(ref),
|
|
11
|
+
offlineMethod: 'localizeRef',
|
|
12
|
+
};
|
|
13
|
+
// async *makeOfflineRef(ref: string) {
|
|
14
|
+
// log('assetResolver makeOfflineRef:', ref);
|
|
15
|
+
// if (!this.canResolve(ref)) throw new Error(`Unexpected ref: ${ref}`);
|
|
16
|
+
// const url = parseRefValue(ref);
|
|
17
|
+
// const targetFilePath = makeTargetPathFromUrl(url);
|
|
18
|
+
// yield { url, targetFilePath };
|
|
19
|
+
// return { $ref: `asset:${targetFilePath}`, [STOP_RESOLVING]: true };
|
|
20
|
+
// },
|
|
21
|
+
// async *makeOfflineRef2(ref: string) {
|
|
22
|
+
// const url = parseRefValue(ref);
|
|
23
|
+
// const targetFilePath = makeTargetPathFromUrl(url);
|
|
24
|
+
// yield { url, targetFilePath };
|
|
25
|
+
// return `asset:${targetFilePath}`;
|
|
26
|
+
// },
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from '../types';
|
|
1
|
+
import type { Resolver } from '../types';
|
|
2
2
|
export declare const bundleAssetsResolver: Resolver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { importJson } from '../importJson';
|
|
2
|
+
import { parseRefValue } from '../resolve';
|
|
3
|
+
import { returnCachedRef } from '../returnCachedRef';
|
|
4
|
+
import { log } from '../shared';
|
|
5
|
+
export const bundleAssetsResolver = {
|
|
6
|
+
schema: 'bundle-assets',
|
|
7
|
+
async resolveRef(ref, context) {
|
|
8
|
+
log('bundleAssetsResolver resolveRef:', ref);
|
|
9
|
+
const url = parseRefValue(ref);
|
|
10
|
+
return returnCachedRef(ref, context.refCache, async () => {
|
|
11
|
+
const files = await importJson(url, context);
|
|
12
|
+
const baseUrl = url.substring(0, url.lastIndexOf('/') + 1);
|
|
13
|
+
const assets = files.map((file) => ({
|
|
14
|
+
$ref: `asset+${baseUrl}${file}`,
|
|
15
|
+
}));
|
|
16
|
+
return assets;
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
offlineMethod: 'localizeRef',
|
|
20
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from '../types';
|
|
1
|
+
import type { Resolver } from '../types';
|
|
2
2
|
export declare const expoRuntimeBranchResolver: Resolver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { importJson } from '../importJson';
|
|
2
|
+
import { parseRefValue } from '../resolve';
|
|
3
|
+
import { returnCachedRef } from '../returnCachedRef';
|
|
4
|
+
import { log } from '../shared';
|
|
5
|
+
const BASE_URL = 'https://efp-runtime.expofp.com/';
|
|
6
|
+
export const expoRuntimeBranchResolver = {
|
|
7
|
+
schema: 'expo-runtime-branch',
|
|
8
|
+
async resolveRef(ref, context) {
|
|
9
|
+
log('expoRuntimeBranchResolver resolveRef:', ref);
|
|
10
|
+
const branch = parseRefValue(ref);
|
|
11
|
+
const branchUrl = `${BASE_URL}branches/${branch}.json`;
|
|
12
|
+
return returnCachedRef(ref, context.refCache, async () => {
|
|
13
|
+
const release = await importJson(branchUrl, context);
|
|
14
|
+
return {
|
|
15
|
+
$ref: `expo-runtime+https://efp-runtime.expofp.com/releases/${release}/`,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
offlineMethod: 'resolveRef',
|
|
20
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from '../types';
|
|
1
|
+
import type { Resolver } from '../types';
|
|
2
2
|
export declare const expoRuntimeGetBranchResolver: Resolver;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { importJson } from '../importJson';
|
|
2
|
+
import { parseRefValue } from '../resolve';
|
|
3
|
+
import { log } from '../shared';
|
|
4
|
+
// const SCHEMA = 'expo-runtime-get-branch';
|
|
5
|
+
export const expoRuntimeGetBranchResolver = {
|
|
6
|
+
schema: 'expo-runtime-get-branch',
|
|
7
|
+
async resolveRef(ref, context) {
|
|
8
|
+
log('expoRuntimeGetBranchResolver resolveRef:', ref);
|
|
9
|
+
const expo = parseRefValue(ref);
|
|
10
|
+
const url = `https://${expo}.expofp.com/get-branch`;
|
|
11
|
+
return importJson(url, context);
|
|
12
|
+
},
|
|
13
|
+
offlineMethod: 'resolveRef',
|
|
14
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from '../types';
|
|
1
|
+
import type { Resolver } from '../types';
|
|
2
2
|
export declare const expoRuntimeResolver: Resolver;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parseRefValue } from '../resolve';
|
|
2
|
+
import { deepFreeze, log } from '../shared';
|
|
3
|
+
// const SCHEMA = 'expo-runtime';
|
|
4
|
+
export const expoRuntimeResolver = {
|
|
5
|
+
schema: 'expo-runtime',
|
|
6
|
+
// canResolve(ref: string) {
|
|
7
|
+
// return canResolveRefSchema(ref, SCHEMA);
|
|
8
|
+
// },
|
|
9
|
+
async resolveRef(ref) {
|
|
10
|
+
log('expoRuntimeResolver resolveRef:', ref);
|
|
11
|
+
// if (!this.canResolve(ref)) throw new Error(`Unexpected ref: ${ref}`);
|
|
12
|
+
const url = parseRefValue(ref);
|
|
13
|
+
const data = {
|
|
14
|
+
entry: { $ref: `asset+${url}expofp.js` },
|
|
15
|
+
assets: { $ref: `bundle-assets+${url}bundle.json` },
|
|
16
|
+
};
|
|
17
|
+
deepFreeze(data);
|
|
18
|
+
return data;
|
|
19
|
+
},
|
|
20
|
+
// async *makeOfflineRef(ref: string) {
|
|
21
|
+
// log('expoRuntimeResolver makeOfflineRef:', ref);
|
|
22
|
+
// if (!this.canResolve(ref)) throw new Error(`Unexpected ref: ${ref}`);
|
|
23
|
+
// const url = parseRefValue(ref);
|
|
24
|
+
// const refData = deepClone(await this.resolveRef(ref));
|
|
25
|
+
// const targetFilePath = makeUniqueJsonTargetPathFromString(url, SCHEMA_PREFIX_BASE);
|
|
26
|
+
// const data = yield* makeOfflineInternal(refData);
|
|
27
|
+
// yield { data: data, targetFilePath };
|
|
28
|
+
// return { $ref: targetFilePath, [STOP_RESOLVING]: true };
|
|
29
|
+
// },
|
|
30
|
+
// async *makeOfflineRef2(ref: string) {
|
|
31
|
+
// const refData = deepClone(await this.resolveRef(ref));
|
|
32
|
+
// const targetFilePath = makeUniqueJsonTargetPathFromString(ref);
|
|
33
|
+
// const data = yield* makeOfflineInternal(refData);
|
|
34
|
+
// yield { data, targetFilePath };
|
|
35
|
+
// return targetFilePath;
|
|
36
|
+
// },
|
|
37
|
+
offlineMethod: 'resolveRef',
|
|
38
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const httpResolver: {
|
|
2
2
|
canResolve(ref: string): boolean;
|
|
3
|
-
resolveRef(ref: string, context: import(
|
|
3
|
+
resolveRef(ref: string, context: import("../resolve").ResolveContextInternal): Promise<any>;
|
|
4
4
|
offlineMethod: "resolveRef";
|
|
5
5
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { importJson } from '../importJson';
|
|
2
|
+
import { log } from '../shared';
|
|
3
|
+
export const httpResolver = {
|
|
4
|
+
canResolve(ref) {
|
|
5
|
+
return ref.startsWith('http://') || ref.startsWith('https://') || ref.startsWith('./');
|
|
6
|
+
},
|
|
7
|
+
resolveRef(ref, context) {
|
|
8
|
+
log('httpResolver resolveRef:', ref);
|
|
9
|
+
if (!this.canResolve(ref))
|
|
10
|
+
throw new Error(`Unexpected ref in httpResolver: ${ref}`);
|
|
11
|
+
return importJson(ref, context);
|
|
12
|
+
},
|
|
13
|
+
offlineMethod: 'resolveRef',
|
|
14
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from '../types';
|
|
1
|
+
import type { Resolver } from '../types';
|
|
2
2
|
export declare const resolvers: Resolver[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { assetResolver } from './assetResolver';
|
|
2
|
+
import { bundleAssetsResolver } from './bundleAssetsResolver';
|
|
3
|
+
import { expoRuntimeBranchResolver } from './expoRuntimeBranchResolver';
|
|
4
|
+
import { expoRuntimeGetBranchResolver } from './expoRuntimeGetBranchResolver';
|
|
5
|
+
import { expoRuntimeResolver } from './expoRuntimeResolver';
|
|
6
|
+
import { httpResolver } from './httpResolver';
|
|
7
|
+
import { legacyAssetUrlsResolver } from './legacyAssetUrlsResolver';
|
|
8
|
+
import { legacyDataResolver } from './legacyDataResolver';
|
|
9
|
+
export const resolvers = [
|
|
10
|
+
httpResolver,
|
|
11
|
+
bundleAssetsResolver,
|
|
12
|
+
assetResolver,
|
|
13
|
+
expoRuntimeResolver,
|
|
14
|
+
expoRuntimeBranchResolver,
|
|
15
|
+
expoRuntimeGetBranchResolver,
|
|
16
|
+
legacyDataResolver,
|
|
17
|
+
legacyAssetUrlsResolver,
|
|
18
|
+
];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { importJson } from '../importJson';
|
|
2
|
+
import { loadAndWaitGlobal } from '../loadAndWaitGlobal';
|
|
3
|
+
import { parseRefValue } from '../resolve';
|
|
4
|
+
import { returnCachedRef } from '../returnCachedRef';
|
|
5
|
+
import { log } from '../shared';
|
|
6
|
+
export const legacyAssetUrlsResolver = {
|
|
7
|
+
schema: 'legacy-asset-urls',
|
|
8
|
+
resolveRef(ref, context) {
|
|
9
|
+
log('legacyAssetUrlsResolver resolveRef:', ref);
|
|
10
|
+
const signal = context.signal;
|
|
11
|
+
return returnCachedRef(ref, context.refCache, async () => {
|
|
12
|
+
const dataUrlBase = parseRefValue(ref);
|
|
13
|
+
// load version.js - it will contain "window.__fpDataVersion = "20251129003330106";"
|
|
14
|
+
const versionUrl = `${dataUrlBase}version.js`;
|
|
15
|
+
try {
|
|
16
|
+
await loadAndWaitGlobal(versionUrl, {
|
|
17
|
+
globalVar: '__fpDataVersion',
|
|
18
|
+
timeoutMs: 30_000,
|
|
19
|
+
signal,
|
|
20
|
+
});
|
|
21
|
+
context.importCallback?.(versionUrl, 'script');
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
console.warn(`Could not load version.js at ${versionUrl}, proceeding without it`);
|
|
25
|
+
}
|
|
26
|
+
const version = globalThis.__fpDataVersion || (+new Date()).toString();
|
|
27
|
+
const filesUrl = `${dataUrlBase}files.json?v=${version}`;
|
|
28
|
+
const dataUrl = `${dataUrlBase}data.js?v=${version}`;
|
|
29
|
+
const filesPromise = importJson(filesUrl, context).catch(() => {
|
|
30
|
+
console.warn(`Could not load files.json at ${filesUrl}, proceeding without it`);
|
|
31
|
+
return [];
|
|
32
|
+
});
|
|
33
|
+
// data.js
|
|
34
|
+
const dataLoadPromise = loadAndWaitGlobal(dataUrl, {
|
|
35
|
+
globalVar: '__data',
|
|
36
|
+
signal,
|
|
37
|
+
});
|
|
38
|
+
context.importCallback?.(dataUrl, 'script');
|
|
39
|
+
// wf.data.js
|
|
40
|
+
const wfDataUrl = `${dataUrlBase}wf.data.js?v=${version}`;
|
|
41
|
+
const wfDataLoadPromise = loadAndWaitGlobal(wfDataUrl, {
|
|
42
|
+
globalVar: '__wfData',
|
|
43
|
+
signal,
|
|
44
|
+
})
|
|
45
|
+
.then(() => {
|
|
46
|
+
context.importCallback?.(wfDataUrl, 'script');
|
|
47
|
+
})
|
|
48
|
+
.catch(() => {
|
|
49
|
+
console.warn(`Could not load wf.data.js at ${wfDataUrl}, proceeding without it`);
|
|
50
|
+
});
|
|
51
|
+
// fp.svg.js
|
|
52
|
+
delete globalThis.__fpLayers;
|
|
53
|
+
const fpSvgUrl = `${dataUrlBase}fp.svg.js?v=${version}`;
|
|
54
|
+
const fpSvgLoadPromise = loadAndWaitGlobal(fpSvgUrl, {
|
|
55
|
+
globalVar: '__fp',
|
|
56
|
+
signal,
|
|
57
|
+
});
|
|
58
|
+
context.importCallback?.(fpSvgUrl, 'script');
|
|
59
|
+
await Promise.all([filesPromise, dataLoadPromise, wfDataLoadPromise, fpSvgLoadPromise]);
|
|
60
|
+
const __fpLayers = (globalThis.__fpLayers ?? []);
|
|
61
|
+
const fpLayerFiles = __fpLayers.map((x) => `fp.svg.${x.name}.js`);
|
|
62
|
+
for (const layerFile of fpLayerFiles) {
|
|
63
|
+
const layerUrl = `${dataUrlBase}${layerFile}?v=${version}`;
|
|
64
|
+
context.importCallback?.(layerUrl, 'script');
|
|
65
|
+
}
|
|
66
|
+
const files = await filesPromise;
|
|
67
|
+
const data = globalThis.__data || {};
|
|
68
|
+
const dataFiles = [...files, 'data.js', 'wf.data.js', 'fp.svg.js', ...fpLayerFiles];
|
|
69
|
+
const dataFilesAssets = dataFiles.reduce((map, file) => {
|
|
70
|
+
map[file] = { $ref: `asset+${dataUrlBase}${file}?v=${version}` };
|
|
71
|
+
return map;
|
|
72
|
+
}, {});
|
|
73
|
+
return { ...dataFilesAssets, ...populateDataJsAssetsMap(dataUrlBase, data) };
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
offlineMethod: 'resolveRef',
|
|
77
|
+
};
|
|
78
|
+
function populateDataJsAssetsMap(dataUrlBase, data) {
|
|
79
|
+
const links = new Set();
|
|
80
|
+
function addLink(link) {
|
|
81
|
+
if (typeof link === 'string' && link.length > 0) {
|
|
82
|
+
// if (!link.startsWith('http://') && !link.startsWith('https://')) {
|
|
83
|
+
// link = dataUrlBase + link;
|
|
84
|
+
// }
|
|
85
|
+
links.add(link);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
addLink(data.logo);
|
|
89
|
+
data.exhibitors?.forEach((e) => {
|
|
90
|
+
addLink(e.logo);
|
|
91
|
+
e.gallery?.forEach((img) => addLink(img));
|
|
92
|
+
});
|
|
93
|
+
data.events?.forEach((e) => {
|
|
94
|
+
addLink(e.logoFile);
|
|
95
|
+
e.speakers?.forEach((s) => {
|
|
96
|
+
addLink(s.photoFile);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return Array.from(links).reduce((map, link) => {
|
|
100
|
+
map[link] = { $ref: `asset+${dataUrlBase}${link}` };
|
|
101
|
+
return map;
|
|
102
|
+
}, {});
|
|
103
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const legacyDataResolver: {
|
|
2
2
|
schema: string;
|
|
3
|
-
resolveRef(ref: string, context: import(
|
|
3
|
+
resolveRef(ref: string, context: import("../resolve").ResolveContextInternal): Promise<any>;
|
|
4
4
|
offlineMethod: "resolveRef";
|
|
5
5
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseRefValue } from '../resolve';
|
|
2
|
+
import { returnCachedRef } from '../returnCachedRef';
|
|
3
|
+
import { log } from '../shared';
|
|
4
|
+
export const legacyDataResolver = {
|
|
5
|
+
schema: 'legacy-data',
|
|
6
|
+
resolveRef(ref, context) {
|
|
7
|
+
log('legacyDataResolver resolveRef:', ref);
|
|
8
|
+
return returnCachedRef(ref, context.refCache, async () => {
|
|
9
|
+
const dataUrlBase = parseRefValue(ref);
|
|
10
|
+
return {
|
|
11
|
+
_to_remove_for_offline_to_work_dataUrlBase: dataUrlBase,
|
|
12
|
+
legacyAssetUrls: { $ref: `legacy-asset-urls+${dataUrlBase}` },
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
offlineMethod: 'resolveRef',
|
|
17
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { deepFreeze } from './shared';
|
|
2
|
+
export async function returnCachedRef(ref, refCache, factory) {
|
|
3
|
+
if (refCache.has(ref)) {
|
|
4
|
+
return refCache.get(ref);
|
|
5
|
+
}
|
|
6
|
+
const promise = factory().then((data) => {
|
|
7
|
+
deepFreeze(data);
|
|
8
|
+
return data;
|
|
9
|
+
});
|
|
10
|
+
refCache.set(ref, promise);
|
|
11
|
+
return promise;
|
|
12
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { logger } from './logger';
|
|
2
|
+
import { resolve } from './resolve';
|
|
3
|
+
// export const NOT_APPLICABLE = Symbol('not-applicable');
|
|
4
|
+
// export const STOP_RESOLVING = Symbol('STOP_RESOLVING');
|
|
5
|
+
export function createFunction(name) {
|
|
6
|
+
return async (manifest, ...args) => {
|
|
7
|
+
try {
|
|
8
|
+
const runtimeEntryPoint = await resolve(manifest, '/runtime/entry');
|
|
9
|
+
const moduleExports = await import(/* @vite-ignore */ runtimeEntryPoint);
|
|
10
|
+
const functionToCall = moduleExports[name];
|
|
11
|
+
return functionToCall(manifest, ...args);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error('efp-loader', `Error when trying to import and call "${name}":`, error);
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function log(...args) {
|
|
20
|
+
// if (!(globalThis as any).__EFP_LOADER_DEBUG__ && !import.meta.env.DEV) return;
|
|
21
|
+
// console.debug('efp-loader', ...args);
|
|
22
|
+
logger(...args);
|
|
23
|
+
}
|
|
24
|
+
export function deepFreeze(obj) {
|
|
25
|
+
if (obj === null || typeof obj !== 'object')
|
|
26
|
+
return obj;
|
|
27
|
+
Object.freeze(obj);
|
|
28
|
+
for (const key of Object.keys(obj)) {
|
|
29
|
+
const val = obj[key];
|
|
30
|
+
if (typeof val === 'object' && val !== null && !Object.isFrozen(val)) {
|
|
31
|
+
deepFreeze(val);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
export function deepClone(obj) {
|
|
37
|
+
if ('structuredClone' in globalThis) {
|
|
38
|
+
return globalThis.structuredClone(obj);
|
|
39
|
+
}
|
|
40
|
+
return JSON.parse(JSON.stringify(obj));
|
|
41
|
+
}
|
|
42
|
+
export function preloadJson(url) {
|
|
43
|
+
if (typeof document === 'undefined')
|
|
44
|
+
return; // SSR / Node
|
|
45
|
+
const link = document.createElement('link');
|
|
46
|
+
link.rel = 'preload';
|
|
47
|
+
link.as = 'fetch';
|
|
48
|
+
link.href = url;
|
|
49
|
+
link.crossOrigin = 'anonymous';
|
|
50
|
+
document.head.appendChild(link);
|
|
51
|
+
}
|
|
52
|
+
export function preconnectUrl(url) {
|
|
53
|
+
if (typeof document === 'undefined')
|
|
54
|
+
return; // SSR / Node
|
|
55
|
+
const link = document.createElement('link');
|
|
56
|
+
link.rel = 'preconnect';
|
|
57
|
+
link.href = url;
|
|
58
|
+
link.crossOrigin = 'anonymous';
|
|
59
|
+
document.head.appendChild(link);
|
|
60
|
+
}
|
|
61
|
+
// export function hashString(str: string): string {
|
|
62
|
+
// let hash = 0;
|
|
63
|
+
// for (let i = 0; i < str.length; i++) {
|
|
64
|
+
// const chr = str.charCodeAt(i);
|
|
65
|
+
// hash = (hash << 5) - hash + chr;
|
|
66
|
+
// hash |= 0; // force 32-bit int
|
|
67
|
+
// }
|
|
68
|
+
// // >>> 0 makes it unsigned (no '-' in front)
|
|
69
|
+
// return (hash >>> 0).toString(16); // hex, [0-9a-f]
|
|
70
|
+
// }
|
|
71
|
+
// Deterministic ID
|
|
72
|
+
// export async function hashString(str: string): Promise<string> {
|
|
73
|
+
// const encoder = new TextEncoder();
|
|
74
|
+
// const data = encoder.encode(str);
|
|
75
|
+
// const digest = await crypto.subtle.digest('SHA-1', data);
|
|
76
|
+
// return bufferToHex(digest);
|
|
77
|
+
// }
|
|
78
|
+
// murmur32
|
|
79
|
+
// export function hashString(str: string): string {
|
|
80
|
+
// let h = 0x811c9dc5;
|
|
81
|
+
// for (let i = 0; i < str.length; i++) {
|
|
82
|
+
// h ^= str.charCodeAt(i);
|
|
83
|
+
// h = Math.imul(h, 0x01000193);
|
|
84
|
+
// }
|
|
85
|
+
// return (h >>> 0).toString(16).padStart(24, '0');
|
|
86
|
+
// }
|
|
87
|
+
// function bufferToHex(buffer: ArrayBuffer): string {
|
|
88
|
+
// const bytes = new Uint8Array(buffer);
|
|
89
|
+
// let hex = '';
|
|
90
|
+
// for (let i = 0; i < bytes.length; i++) {
|
|
91
|
+
// const byteHex = bytes[i].toString(16).padStart(2, '0');
|
|
92
|
+
// hex += byteHex;
|
|
93
|
+
// }
|
|
94
|
+
// return hex;
|
|
95
|
+
// }
|
|
96
|
+
// export function mergeNonRefFields(target: any, source: any) {
|
|
97
|
+
// if (target === source) throw new Error('Cannot merge object with itself');
|
|
98
|
+
// // if source is primitive, throw
|
|
99
|
+
// if (source === null || typeof source !== 'object')
|
|
100
|
+
// throw new Error('Cannot merge non-object source');
|
|
101
|
+
// if (Array.isArray(source)) {
|
|
102
|
+
// throw new Error('mergeNonRefFields does not support merging arrays');
|
|
103
|
+
// }
|
|
104
|
+
// const nonRefKeys = Object.keys(source).filter((key) => key !== '$ref');
|
|
105
|
+
// if (nonRefKeys.length === 0) return;
|
|
106
|
+
// // throw if any is array
|
|
107
|
+
// if (Array.isArray(target)) {
|
|
108
|
+
// throw new Error('mergeNonRefFields does not support merging into arrays');
|
|
109
|
+
// }
|
|
110
|
+
// for (const key of nonRefKeys) {
|
|
111
|
+
// // if target is primitive, throw
|
|
112
|
+
// if (target === null || typeof target !== 'object')
|
|
113
|
+
// throw new Error('Cannot merge into non-object target');
|
|
114
|
+
// target[key] = source[key];
|
|
115
|
+
// }
|
|
116
|
+
// }
|
|
117
|
+
// export function mergeNonExitingFields(target: any, source: any) {
|
|
118
|
+
// if (target === source) throw new Error('Cannot merge object with itself');
|
|
119
|
+
// // if source is primitive, throw
|
|
120
|
+
// if (source === null || typeof source !== 'object')
|
|
121
|
+
// throw new Error('Cannot merge non-object source');
|
|
122
|
+
// if (Array.isArray(source)) {
|
|
123
|
+
// throw new Error('mergeNonExitingFields does not support merging arrays');
|
|
124
|
+
// }
|
|
125
|
+
// const keys = Object.keys(source);
|
|
126
|
+
// if (keys.length === 0) return;
|
|
127
|
+
// // throw if any is array
|
|
128
|
+
// if (Array.isArray(target)) {
|
|
129
|
+
// throw new Error('mergeNonExitingFields does not support merging into arrays');
|
|
130
|
+
// }
|
|
131
|
+
// for (const key of Object.keys(source)) {
|
|
132
|
+
// // if target is primitive, throw
|
|
133
|
+
// if (target === null || typeof target !== 'object')
|
|
134
|
+
// throw new Error('Cannot merge into non-object target');
|
|
135
|
+
// if (!(key in target)) {
|
|
136
|
+
// target[key] = source[key];
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
|
+
// }
|
|
140
|
+
// export function replaceObjectFields(target: any, source: any) {
|
|
141
|
+
// if (target === source) {
|
|
142
|
+
// throw new Error('Cannot replace object with itself');
|
|
143
|
+
// }
|
|
144
|
+
// // if source is primitive, throw
|
|
145
|
+
// if (source === null || typeof source !== 'object') {
|
|
146
|
+
// throw new Error('Cannot replace with non-object source');
|
|
147
|
+
// }
|
|
148
|
+
// // throw if any is array
|
|
149
|
+
// if (Array.isArray(target) || Array.isArray(source)) {
|
|
150
|
+
// throw new Error('replaceObjectFields does not support arrays');
|
|
151
|
+
// }
|
|
152
|
+
// // delete keys in target that are not in source
|
|
153
|
+
// for (const key of Object.keys(target)) {
|
|
154
|
+
// if (!(key in source)) {
|
|
155
|
+
// delete target[key];
|
|
156
|
+
// }
|
|
157
|
+
// }
|
|
158
|
+
// // copy keys from source to target
|
|
159
|
+
// for (const key of Object.keys(source)) {
|
|
160
|
+
// target[key] = source[key];
|
|
161
|
+
// }
|
|
162
|
+
// }
|
|
163
|
+
// export function isObject(v: any): boolean {
|
|
164
|
+
// return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
165
|
+
// }
|
|
166
|
+
// export function mergeOriginalFieldsIntoResolvedObject(target: any, source: any) {
|
|
167
|
+
// if (target === source) throw new Error('Cannot merge object with itself');
|
|
168
|
+
// // if source is primitive, throw
|
|
169
|
+
// if (source === null || typeof source !== 'object')
|
|
170
|
+
// throw new Error('Cannot merge non-object source');
|
|
171
|
+
// if (Array.isArray(source)) {
|
|
172
|
+
// throw new Error('Cannot merge arrays');
|
|
173
|
+
// }
|
|
174
|
+
// const nonRefKeys = Object.keys(source).filter((key) => key !== '$ref');
|
|
175
|
+
// if (nonRefKeys.length === 0) return;
|
|
176
|
+
// // throw if any is array
|
|
177
|
+
// if (Array.isArray(target)) {
|
|
178
|
+
// throw new Error('Cannot merge into arrays');
|
|
179
|
+
// }
|
|
180
|
+
// for (const key of nonRefKeys) {
|
|
181
|
+
// // if target is primitive, throw
|
|
182
|
+
// if (target === null || typeof target !== 'object')
|
|
183
|
+
// throw new Error('Cannot merge into non-object target');
|
|
184
|
+
// target[key] = source[key];
|
|
185
|
+
// }
|
|
186
|
+
// }
|
|
187
|
+
// export function createMergedObject(target: any, source: any) {
|
|
188
|
+
// if (target === source) return; //throw new Error('Cannot merge object with itself');
|
|
189
|
+
// // if source is primitive, throw
|
|
190
|
+
// if (source === null || typeof source !== 'object')
|
|
191
|
+
// throw new Error('Cannot merge non-object source');
|
|
192
|
+
// if (Array.isArray(source)) {
|
|
193
|
+
// throw new Error('Cannot merge arrays');
|
|
194
|
+
// }
|
|
195
|
+
// const nonRefKeys = Object.keys(source).filter((key) => key !== '$ref');
|
|
196
|
+
// if (nonRefKeys.length === 0) return target;
|
|
197
|
+
// // throw if any is array
|
|
198
|
+
// if (Array.isArray(target)) {
|
|
199
|
+
// throw new Error('Cannot merge into arrays');
|
|
200
|
+
// }
|
|
201
|
+
// if (target === null || typeof target !== 'object') {
|
|
202
|
+
// throw new Error('Cannot merge into non-object target');
|
|
203
|
+
// }
|
|
204
|
+
// const result = { ...target };
|
|
205
|
+
// for (const key of nonRefKeys) {
|
|
206
|
+
// result[key] = source[key];
|
|
207
|
+
// }
|
|
208
|
+
// deepFreeze(result);
|
|
209
|
+
// return result;
|
|
210
|
+
// }
|
|
211
|
+
export function createMergedObjectWithOverridenNonRefProps(target, source) {
|
|
212
|
+
if (target === source)
|
|
213
|
+
return; //throw new Error('Cannot merge object with itself');
|
|
214
|
+
// if source is primitive, throw
|
|
215
|
+
if (source === null || typeof source !== 'object')
|
|
216
|
+
throw new Error('Cannot merge non-object source');
|
|
217
|
+
if (Array.isArray(source)) {
|
|
218
|
+
throw new Error('Cannot merge arrays');
|
|
219
|
+
}
|
|
220
|
+
const nonRefKeys = Object.keys(source).filter((key) => key !== '$ref');
|
|
221
|
+
if (nonRefKeys.length === 0)
|
|
222
|
+
return deepClone(target);
|
|
223
|
+
// throw if any is array
|
|
224
|
+
if (Array.isArray(target)) {
|
|
225
|
+
throw new Error('Cannot merge into arrays');
|
|
226
|
+
}
|
|
227
|
+
if (target === null || typeof target !== 'object') {
|
|
228
|
+
throw new Error('Cannot merge into non-object target');
|
|
229
|
+
}
|
|
230
|
+
const result = deepClone({ ...target });
|
|
231
|
+
for (const key of nonRefKeys) {
|
|
232
|
+
result[key] = source[key];
|
|
233
|
+
}
|
|
234
|
+
// deepFreeze(result);
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
export function replaceObjectFields(target, source) {
|
|
238
|
+
if (target === source) {
|
|
239
|
+
return;
|
|
240
|
+
// throw new Error('Cannot replace object with itself');
|
|
241
|
+
}
|
|
242
|
+
// if source is primitive, throw
|
|
243
|
+
if (source === null || typeof source !== 'object') {
|
|
244
|
+
throw new Error('Cannot replace with non-object source');
|
|
245
|
+
}
|
|
246
|
+
// if target is primitive, throw
|
|
247
|
+
if (target === null || typeof target !== 'object') {
|
|
248
|
+
throw new Error('Cannot replace non-object target');
|
|
249
|
+
}
|
|
250
|
+
if (Array.isArray(target)) {
|
|
251
|
+
if (!Array.isArray(source)) {
|
|
252
|
+
throw new Error('replaceObjectFields does not support mixing arrays and objects');
|
|
253
|
+
}
|
|
254
|
+
// both are arrays - replace contents
|
|
255
|
+
target.length = 0;
|
|
256
|
+
for (const item of source) {
|
|
257
|
+
target.push(item);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
// delete keys in target that are not in source
|
|
262
|
+
for (const key of Object.keys(target)) {
|
|
263
|
+
if (!(key in source)) {
|
|
264
|
+
delete target[key];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// copy keys from source to target
|
|
268
|
+
for (const key of Object.keys(source)) {
|
|
269
|
+
target[key] = source[key];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|