nuxt-files-sdk 0.1.1 → 0.2.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/dist/config/evaluate.js +149 -0
- package/dist/config/load.js +22 -40
- package/dist/config/merge.d.ts +1 -2
- package/dist/config/merge.js +0 -2
- package/dist/config/prepare.js +58 -0
- package/dist/config/prune.js +8 -9
- package/dist/config.d.ts +11 -6
- package/dist/config.js +0 -2
- package/dist/devtools/auth.js +0 -2
- package/dist/devtools/client/app.js +2 -2
- package/dist/devtools/client/index.html +4 -0
- package/dist/devtools/devframe.js +1 -3
- package/dist/devtools/diagnostics.d.ts +1 -2
- package/dist/devtools/diagnostics.js +0 -2
- package/dist/devtools/enabled.d.ts +1 -2
- package/dist/devtools/enabled.js +0 -2
- package/dist/devtools/files-read.d.ts +2 -3
- package/dist/devtools/files-read.js +0 -2
- package/dist/devtools/files-write.d.ts +2 -3
- package/dist/devtools/files-write.js +0 -2
- package/dist/devtools/files.js +7 -10
- package/dist/devtools/index.js +24 -26
- package/dist/devtools/nuxt-v3-handler.d.ts +1 -2
- package/dist/devtools/nuxt-v3-handler.js +0 -2
- package/dist/devtools/nuxt-v3.js +1 -3
- package/dist/devtools/nuxt-v4.js +4 -7
- package/dist/devtools/paths.js +8 -0
- package/dist/devtools/snapshot.d.ts +5 -14
- package/dist/devtools/snapshot.js +2 -9
- package/dist/devtools/token.d.ts +1 -2
- package/dist/devtools/token.js +0 -2
- package/dist/integration/capabilities.js +17 -0
- package/dist/integration/dependencies.d.ts +12 -0
- package/dist/integration/dependencies.js +67 -0
- package/dist/integration/diagnostics.d.ts +9 -0
- package/dist/integration/diagnostics.js +80 -0
- package/dist/integration/imports.js +83 -0
- package/dist/integration/nitro-dev-close.js +13 -0
- package/dist/integration/nitro-event.d.ts +7 -0
- package/dist/integration/nitro-event.js +24 -0
- package/dist/integration/nitro.d.ts +9 -2
- package/dist/integration/nitro.js +170 -91
- package/dist/integration/nuxt-diagnostics.js +23 -0
- package/dist/integration/nuxt.js +235 -0
- package/dist/integration/resolve.d.ts +1 -0
- package/dist/integration/resolve.js +113 -0
- package/dist/integration/terminal.js +20 -0
- package/dist/integration/update.js +59 -0
- package/dist/meta.js +8 -0
- package/dist/module.d.ts +1 -8
- package/dist/module.js +74 -59
- package/dist/module.json +8 -0
- package/dist/nitro.d.ts +1 -2
- package/dist/nitro.js +7 -7
- package/dist/package.js +1 -3
- package/dist/runtime/development.d.ts +5 -0
- package/dist/runtime/development.js +14 -0
- package/dist/runtime/gateway-secret.d.ts +4 -0
- package/dist/runtime/gateway-secret.js +10 -0
- package/dist/runtime/internal.d.ts +1 -2
- package/dist/runtime/internal.js +1 -2
- package/dist/runtime/normalize.d.ts +1 -0
- package/dist/runtime/normalize.js +0 -2
- package/dist/runtime/provider-types.d.ts +1 -2
- package/dist/runtime/registry.d.ts +9 -22
- package/dist/runtime/registry.js +23 -28
- package/dist/runtime.d.ts +1 -2
- package/dist/runtime.js +0 -2
- package/package.json +247 -13
- package/dist/config/load.js.map +0 -1
- package/dist/config/merge.js.map +0 -1
- package/dist/config/prune.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/devtools/auth.js.map +0 -1
- package/dist/devtools/devframe.js.map +0 -1
- package/dist/devtools/diagnostics.js.map +0 -1
- package/dist/devtools/enabled.js.map +0 -1
- package/dist/devtools/files-read.js.map +0 -1
- package/dist/devtools/files-write.js.map +0 -1
- package/dist/devtools/files.js.map +0 -1
- package/dist/devtools/index.js.map +0 -1
- package/dist/devtools/nuxt-v3-handler.js.map +0 -1
- package/dist/devtools/nuxt-v3.js.map +0 -1
- package/dist/devtools/nuxt-v4.js.map +0 -1
- package/dist/devtools/snapshot.js.map +0 -1
- package/dist/devtools/token.js.map +0 -1
- package/dist/integration/nitro.js.map +0 -1
- package/dist/module.js.map +0 -1
- package/dist/nitro.js.map +0 -1
- package/dist/package.js.map +0 -1
- package/dist/runtime/internal.js.map +0 -1
- package/dist/runtime/normalize.js.map +0 -1
- package/dist/runtime/registry.js.map +0 -1
- package/dist/runtime.js.map +0 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { extname, isAbsolute } from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
//#region src/config/evaluate.ts
|
|
5
|
+
const normalize = (path) => {
|
|
6
|
+
const normalized = path.replaceAll("\\", "/").replace(/\/$/u, "");
|
|
7
|
+
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
8
|
+
};
|
|
9
|
+
/** Create one fresh source graph per c12 load, retaining Jiti's resolver and compiler. */
|
|
10
|
+
const createFilesConfigEvaluator = async ({ alias, nativeRoots }) => {
|
|
11
|
+
const { createJiti } = await import("jiti");
|
|
12
|
+
const cache = Object.create(null);
|
|
13
|
+
const virtualModules = Object.create(null);
|
|
14
|
+
const instances = /* @__PURE__ */ new Map();
|
|
15
|
+
const requires = /* @__PURE__ */ new Map();
|
|
16
|
+
const pending = /* @__PURE__ */ new Map();
|
|
17
|
+
const results = /* @__PURE__ */ new Map();
|
|
18
|
+
const failures = /* @__PURE__ */ new Map();
|
|
19
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
20
|
+
const bridgeId = "nuxt-files-sdk:config-source-bridge";
|
|
21
|
+
const roots = nativeRoots.map(normalize);
|
|
22
|
+
const sourceSpecifier = (id) => id.startsWith(".") || isAbsolute(id) || id.startsWith("file:") || Object.keys(alias).some((key) => id === key || id.startsWith(`${key}/`));
|
|
23
|
+
const sourceFile = (id, filename) => sourceSpecifier(id) && /^\.[cm]?[jt]sx?$/u.test(extname(filename)) && !roots.some((root) => normalize(filename) === root || normalize(filename).startsWith(`${root}/`));
|
|
24
|
+
const callBridge = (types, method, args) => types.callExpression(types.memberExpression(types.callExpression(types.identifier("require"), [types.stringLiteral(bridgeId)]), types.identifier(method)), args);
|
|
25
|
+
const rewriteImports = (opts) => ({ types }) => ({ visitor: { Program: { enter(path) {
|
|
26
|
+
const origin = opts.filename;
|
|
27
|
+
if (!origin) throw new Error("[nuxt-files-sdk:config-source] Missing source filename.");
|
|
28
|
+
const rewriteStatic = ({ node }) => {
|
|
29
|
+
if (typeof node.source?.value === "string" && node.importKind !== "type" && node.exportKind !== "type") node.source.value = virtualize(node.source.value, origin, !!opts.async);
|
|
30
|
+
};
|
|
31
|
+
path.traverse({
|
|
32
|
+
ImportDeclaration: rewriteStatic,
|
|
33
|
+
ExportNamedDeclaration: rewriteStatic,
|
|
34
|
+
ExportAllDeclaration: rewriteStatic,
|
|
35
|
+
CallExpression(reference) {
|
|
36
|
+
const argument = reference.node.arguments?.[0];
|
|
37
|
+
if (reference.node.callee?.type === "Import" && argument) reference.replaceWith(callBridge(types, "importFrom", [argument, types.stringLiteral(origin)]));
|
|
38
|
+
},
|
|
39
|
+
ReferencedIdentifier(reference) {
|
|
40
|
+
if (reference.node.name !== "require" || reference.scope.getBinding("require")) return;
|
|
41
|
+
const parent = reference.parentPath?.node;
|
|
42
|
+
if (parent?.type === "CallExpression" && parent.callee === reference.node && parent.arguments?.[0]?.value === bridgeId) return;
|
|
43
|
+
reference.replaceWith(callBridge(types, "requireFor", [types.stringLiteral(origin)]));
|
|
44
|
+
reference.skip();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
} } } });
|
|
48
|
+
function instance(filename) {
|
|
49
|
+
const existing = instances.get(filename);
|
|
50
|
+
if (existing) return existing;
|
|
51
|
+
const jiti = createJiti(filename, {
|
|
52
|
+
alias,
|
|
53
|
+
virtualModules,
|
|
54
|
+
interopDefault: true,
|
|
55
|
+
moduleCache: false,
|
|
56
|
+
tryNative: false,
|
|
57
|
+
nativeModules: ["files-sdk"],
|
|
58
|
+
fsCache: false
|
|
59
|
+
});
|
|
60
|
+
const transform = jiti.options.transform;
|
|
61
|
+
if (!transform) throw new Error("[nuxt-files-sdk:config-source] Jiti has no source transformer.");
|
|
62
|
+
jiti.options.transform = (opts) => transform({
|
|
63
|
+
...opts,
|
|
64
|
+
babel: {
|
|
65
|
+
...opts.babel,
|
|
66
|
+
plugins: [...opts.babel?.plugins ?? [], rewriteImports(opts)]
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
instances.set(filename, jiti);
|
|
70
|
+
return jiti;
|
|
71
|
+
}
|
|
72
|
+
function virtualize(id, origin, async) {
|
|
73
|
+
if (!sourceSpecifier(id)) return id;
|
|
74
|
+
const key = `${bridgeId}:${async}:${JSON.stringify([origin, id])}`;
|
|
75
|
+
if (!(key in virtualModules)) Object.defineProperty(virtualModules, key, {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: () => async ? importFrom(id, origin) : requireFrom(id, origin)
|
|
78
|
+
});
|
|
79
|
+
return key;
|
|
80
|
+
}
|
|
81
|
+
function reaches(from, target, visited = /* @__PURE__ */ new Set()) {
|
|
82
|
+
if (from === target) return true;
|
|
83
|
+
if (visited.has(from)) return false;
|
|
84
|
+
visited.add(from);
|
|
85
|
+
return [...dependencies.get(from) ?? []].some((next) => reaches(next, target, visited));
|
|
86
|
+
}
|
|
87
|
+
function evaluate(filename, async, source) {
|
|
88
|
+
if (failures.has(filename)) throw failures.get(filename);
|
|
89
|
+
if (results.has(filename)) return results.get(filename);
|
|
90
|
+
if (cache[filename]) return cache[filename].exports;
|
|
91
|
+
try {
|
|
92
|
+
const result = instance(filename).evalModule(source ?? readFileSync(filename, "utf8"), {
|
|
93
|
+
filename,
|
|
94
|
+
async,
|
|
95
|
+
forceTranspile: true,
|
|
96
|
+
cache
|
|
97
|
+
});
|
|
98
|
+
if (!async) {
|
|
99
|
+
results.set(filename, result);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
const completion = Promise.resolve(result).then((value) => {
|
|
103
|
+
results.set(filename, value);
|
|
104
|
+
pending.delete(filename);
|
|
105
|
+
return value;
|
|
106
|
+
}, (error) => {
|
|
107
|
+
failures.set(filename, error);
|
|
108
|
+
pending.delete(filename);
|
|
109
|
+
throw error;
|
|
110
|
+
});
|
|
111
|
+
pending.set(filename, completion);
|
|
112
|
+
return completion;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
failures.set(filename, error);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function importFrom(id, origin) {
|
|
119
|
+
const jiti = instance(origin);
|
|
120
|
+
const url = jiti.esmResolve(id);
|
|
121
|
+
if (!url.startsWith("file:")) return jiti.import(id);
|
|
122
|
+
const filename = fileURLToPath(url);
|
|
123
|
+
if (!sourceFile(id, filename)) return jiti.import(id);
|
|
124
|
+
const circular = reaches(filename, origin);
|
|
125
|
+
const edges = dependencies.get(origin) ?? /* @__PURE__ */ new Set();
|
|
126
|
+
edges.add(filename);
|
|
127
|
+
dependencies.set(origin, edges);
|
|
128
|
+
return !circular && pending.get(filename) || evaluate(filename, true);
|
|
129
|
+
}
|
|
130
|
+
function requireFrom(id, origin) {
|
|
131
|
+
const jiti = instance(origin);
|
|
132
|
+
const filename = jiti.resolve(id);
|
|
133
|
+
return sourceFile(id, filename) ? evaluate(filename, false) : jiti(id);
|
|
134
|
+
}
|
|
135
|
+
function requireFor(origin) {
|
|
136
|
+
const existing = requires.get(origin);
|
|
137
|
+
if (existing) return existing;
|
|
138
|
+
const wrapped = new Proxy(instance(origin), { apply: (_target, _this, args) => requireFrom(args[0], origin) });
|
|
139
|
+
requires.set(origin, wrapped);
|
|
140
|
+
return wrapped;
|
|
141
|
+
}
|
|
142
|
+
virtualModules[bridgeId] = {
|
|
143
|
+
importFrom,
|
|
144
|
+
requireFor
|
|
145
|
+
};
|
|
146
|
+
return async (filename, source) => evaluate(filename, true, source);
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
export { createFilesConfigEvaluator };
|
package/dist/config/load.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { normalizeFilesConfig } from "../runtime/normalize.js";
|
|
2
2
|
import { mergeFilesConfig } from "./merge.js";
|
|
3
|
+
import { registerSdkAliases, resolveOwnedSdk } from "../integration/resolve.js";
|
|
4
|
+
import { createFilesConfigEvaluator } from "./evaluate.js";
|
|
3
5
|
import { basename, dirname } from "node:path";
|
|
4
6
|
import { readFile } from "node:fs/promises";
|
|
5
7
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { loadConfig } from "c12";
|
|
7
|
-
import { createJiti } from "jiti";
|
|
8
8
|
//#region src/config/load.ts
|
|
9
9
|
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
10
|
-
const isResolvedFilesConfig = (value) => {
|
|
11
|
-
normalizeFilesConfig(value);
|
|
12
|
-
return true;
|
|
13
|
-
};
|
|
14
10
|
const hasEnvironmentStorage = (config) => [
|
|
15
11
|
config.$development,
|
|
16
12
|
config.$production,
|
|
@@ -18,50 +14,36 @@ const hasEnvironmentStorage = (config) => [
|
|
|
18
14
|
config.$prerender,
|
|
19
15
|
...isObject(config.$env) ? Object.values(config.$env) : []
|
|
20
16
|
].some((branch) => isObject(branch) && branch.storage !== void 0);
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
17
|
+
const loadFilesConfig = async ({ configPath, environments, alias, injectImports, source }) => {
|
|
18
|
+
const { loadConfig } = await import("c12");
|
|
19
|
+
const sdk = resolveOwnedSdk();
|
|
20
|
+
const evaluate = await createFilesConfigEvaluator({
|
|
24
21
|
alias: {
|
|
25
|
-
...alias,
|
|
22
|
+
...registerSdkAliases(alias ?? {}, sdk),
|
|
26
23
|
"nuxt-files-sdk/config": fileURLToPath(new URL("../config.js", import.meta.url))
|
|
27
24
|
},
|
|
28
|
-
|
|
29
|
-
moduleCache: false
|
|
25
|
+
nativeRoots: [sdk.root]
|
|
30
26
|
});
|
|
31
|
-
const
|
|
32
|
-
const source = await readFile(id, "utf8");
|
|
33
|
-
const code = injectImports ? (await injectImports(source, id)).code : source;
|
|
34
|
-
const loaded = await jiti.evalModule(code, {
|
|
35
|
-
filename: id,
|
|
36
|
-
async: true
|
|
37
|
-
});
|
|
38
|
-
return loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
39
|
-
} });
|
|
40
|
-
const { config } = await loadConfig({
|
|
27
|
+
const { config, layers } = await loadConfig({
|
|
41
28
|
cwd: dirname(configPath),
|
|
42
29
|
configFile: basename(configPath),
|
|
43
30
|
configFileRequired: true,
|
|
44
31
|
rcFile: false,
|
|
45
32
|
extend: false,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
dotenv: false,
|
|
34
|
+
envName: [...environments],
|
|
35
|
+
omit$Keys: true,
|
|
36
|
+
merger: mergeFilesConfig,
|
|
37
|
+
envMerger: mergeFilesConfig,
|
|
38
|
+
import: async (id) => {
|
|
39
|
+
const input = source ?? await readFile(id, "utf8");
|
|
40
|
+
const code = injectImports ? (await injectImports(input, id)).code : input;
|
|
41
|
+
return evaluate(id, code);
|
|
42
|
+
}
|
|
49
43
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const named = isObject(resolved.$env) ? resolved.$env[environment] : void 0;
|
|
54
|
-
resolved = mergeFilesConfig({
|
|
55
|
-
...isObject(direct) ? direct : {},
|
|
56
|
-
...isObject(named) ? named : {}
|
|
57
|
-
}, resolved);
|
|
58
|
-
}
|
|
59
|
-
const result = Object.fromEntries(Object.entries(resolved).filter(([key]) => !key.startsWith("$")));
|
|
60
|
-
if (isObject(result) && result.storage === void 0 && hasEnvironmentStorage(resolved)) return void 0;
|
|
61
|
-
if (!isResolvedFilesConfig(result)) throw new Error("[nuxt-files-sdk:invalid-config] Invalid resolved configuration.");
|
|
62
|
-
return result;
|
|
44
|
+
if (config.storage === void 0 && layers?.some(({ config: layer }) => layer && hasEnvironmentStorage(layer))) return void 0;
|
|
45
|
+
normalizeFilesConfig(config);
|
|
46
|
+
return config;
|
|
63
47
|
};
|
|
64
48
|
//#endregion
|
|
65
49
|
export { loadFilesConfig };
|
|
66
|
-
|
|
67
|
-
//# sourceMappingURL=load.js.map
|
package/dist/config/merge.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/config/merge.d.ts
|
|
2
2
|
/** c12 merger with Files provider boundaries and replacement arrays. Sources are highest priority first. */
|
|
3
3
|
export declare const mergeFilesConfig: (...sources: Array<Record<string, unknown> | null | undefined>) => Record<string, unknown>;
|
|
4
|
-
//#endregion
|
|
5
|
-
//# sourceMappingURL=merge.d.ts.map
|
|
4
|
+
//#endregion
|
package/dist/config/merge.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { normalizeFilesConfig } from "../runtime/normalize.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { getProvider, listEnvVars } from "files-sdk/providers";
|
|
4
|
+
//#region src/config/prepare.ts
|
|
5
|
+
const selectedAdapters = (config, entries = normalizeFilesConfig(config)) => {
|
|
6
|
+
const adapters = [...new Set([...entries.values()].map(({ storage }) => storage.adapter).filter((adapter) => typeof adapter === "string"))].toSorted();
|
|
7
|
+
for (const adapter of adapters) if (!getProvider(adapter)) throw new Error(`[nuxt-files-sdk:unknown-adapter] Unknown adapter "${adapter}".`);
|
|
8
|
+
return adapters;
|
|
9
|
+
};
|
|
10
|
+
const gatewayRoutes = (config, storages = normalizeFilesConfig(config)) => {
|
|
11
|
+
const routes = config && typeof config === "object" && "routes" in config ? config.routes : void 0;
|
|
12
|
+
if (routes === void 0) return [];
|
|
13
|
+
if (!Array.isArray(routes)) throw new Error("[nuxt-files-sdk:invalid-route] routes must be an array.");
|
|
14
|
+
const paths = /* @__PURE__ */ new Set();
|
|
15
|
+
const selected = [];
|
|
16
|
+
for (const route of routes) {
|
|
17
|
+
if (!route || typeof route !== "object" || !("path" in route) || typeof route.path !== "string" || !/^\/(?:[\w.~-]+(?:\/[\w.~-]+)*)?$/u.test(route.path)) throw new Error("[nuxt-files-sdk:invalid-route] Each route needs a static absolute path.");
|
|
18
|
+
if (paths.has(route.path)) throw new Error(`[nuxt-files-sdk:duplicate-route] Duplicate route "${route.path}".`);
|
|
19
|
+
paths.add(route.path);
|
|
20
|
+
if ("authorize" in route && route.authorize !== void 0 && typeof route.authorize !== "function") throw new Error("[nuxt-files-sdk:invalid-route] authorize must be a function.");
|
|
21
|
+
const name = "storage" in route ? route.storage : void 0;
|
|
22
|
+
if (storages.has(void 0) ? name !== void 0 : typeof name !== "string" || !storages.has(name)) throw new Error(`[nuxt-files-sdk:unknown-storage] Invalid storage for route "${route.path}".`);
|
|
23
|
+
selected.push(typeof name === "string" ? {
|
|
24
|
+
path: route.path,
|
|
25
|
+
storage: name
|
|
26
|
+
} : { path: route.path });
|
|
27
|
+
}
|
|
28
|
+
return selected;
|
|
29
|
+
};
|
|
30
|
+
const factoryName = (adapter) => adapter === "cloudinary" ? "cloudinaryAdapter" : adapter.replaceAll(/-([a-z0-9])/gu, (_, character) => character.toUpperCase());
|
|
31
|
+
const providerCode = (adapters) => ({
|
|
32
|
+
imports: adapters.map((adapter, index) => `import { ${factoryName(adapter)} as provider${index} } from ${JSON.stringify(`#files-sdk/${adapter}`)}`).join("\n"),
|
|
33
|
+
factories: adapters.map((adapter, index) => `${JSON.stringify(adapter)}: provider${index}`).join(", ")
|
|
34
|
+
});
|
|
35
|
+
const prepareFilesConfig = async (options) => {
|
|
36
|
+
const { loadFilesConfig } = await import("./load.js");
|
|
37
|
+
const { pruneFilesConfigSource } = await import("./prune.js");
|
|
38
|
+
const original = await readFile(options.configPath, "utf8");
|
|
39
|
+
const source = options.injectImports ? (await options.injectImports(original, options.configPath)).code : original;
|
|
40
|
+
const config = await loadFilesConfig({
|
|
41
|
+
...options,
|
|
42
|
+
source,
|
|
43
|
+
injectImports: void 0
|
|
44
|
+
});
|
|
45
|
+
if (!config) return void 0;
|
|
46
|
+
const entries = normalizeFilesConfig(config);
|
|
47
|
+
const adapters = selectedAdapters(config, entries);
|
|
48
|
+
return {
|
|
49
|
+
entries,
|
|
50
|
+
adapters,
|
|
51
|
+
routes: gatewayRoutes(config, entries),
|
|
52
|
+
providers: providerCode(adapters),
|
|
53
|
+
source: pruneFilesConfigSource(source, options.configPath, options.environments),
|
|
54
|
+
environment: Object.fromEntries(adapters.map((adapter) => [adapter, listEnvVars(adapter).filter((variable) => variable.readBy === "files-sdk").map((variable) => [variable.key, ...variable.aliases ?? []])]))
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { gatewayRoutes, prepareFilesConfig, providerCode, selectedAdapters };
|
package/dist/config/prune.js
CHANGED
|
@@ -2,7 +2,7 @@ import { dirname, resolve } from "node:path";
|
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
//#region src/config/prune.ts
|
|
4
4
|
const unwrap = (node) => node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "ParenthesizedExpression" ? unwrap(node.expression) : node;
|
|
5
|
-
const keyOf = (node) => node.key
|
|
5
|
+
const keyOf = (node) => node.type !== "Property" ? void 0 : node.key.type === "Identifier" && !node.computed ? node.key.name : node.key.type === "Literal" && typeof node.key.value === "string" ? node.key.value : void 0;
|
|
6
6
|
/** Remove inactive environment literals before bundling the user config. */
|
|
7
7
|
const pruneFilesConfigSource = (source, configPath, environments) => {
|
|
8
8
|
const parsed = parseSync(configPath, source, {
|
|
@@ -14,21 +14,22 @@ const pruneFilesConfigSource = (source, configPath, environments) => {
|
|
|
14
14
|
const exported = body.find((node) => node.type === "ExportDefaultDeclaration")?.declaration;
|
|
15
15
|
if (!exported) throw new Error("[nuxt-files-sdk:invalid-config] files.config.ts needs a default export.");
|
|
16
16
|
let root = unwrap(exported);
|
|
17
|
-
if (root.type === "CallExpression") root = unwrap(root.arguments
|
|
17
|
+
if (root.type === "CallExpression") root = unwrap(root.arguments[0] ?? root);
|
|
18
18
|
if (root.type === "Identifier") {
|
|
19
|
-
const
|
|
19
|
+
const name = root.name;
|
|
20
|
+
const declaration = body.flatMap((node) => node.type === "VariableDeclaration" ? node.declarations : []).find((node) => node.id.type === "Identifier" && node.id.name === name);
|
|
20
21
|
if (declaration?.init) root = unwrap(declaration.init);
|
|
21
22
|
}
|
|
22
23
|
if (root.type !== "ObjectExpression") throw new Error("[nuxt-files-sdk:invalid-config] The default Files config must be a static object literal.");
|
|
23
24
|
const edits = [];
|
|
24
25
|
const active = new Set(environments);
|
|
25
|
-
for (const property of root.properties
|
|
26
|
+
for (const property of root.properties) {
|
|
26
27
|
const key = keyOf(property);
|
|
27
28
|
if (!key?.startsWith("$")) continue;
|
|
28
|
-
if (key === "$env" && property.
|
|
29
|
+
if (key === "$env" && property.type === "Property") {
|
|
29
30
|
const env = unwrap(property.value);
|
|
30
31
|
if (env.type !== "ObjectExpression") throw new Error("[nuxt-files-sdk:invalid-config] $env must be an object.");
|
|
31
|
-
for (const entry of env.properties
|
|
32
|
+
for (const entry of env.properties) if (!active.has(keyOf(entry) ?? "")) edits.push({
|
|
32
33
|
start: entry.start,
|
|
33
34
|
end: entry.end,
|
|
34
35
|
text: "...{}"
|
|
@@ -40,7 +41,7 @@ const pruneFilesConfigSource = (source, configPath, environments) => {
|
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
for (const node of body) {
|
|
43
|
-
if (!
|
|
44
|
+
if (!("source" in node) || !node.source || !node.source.value.startsWith(".")) continue;
|
|
44
45
|
edits.push({
|
|
45
46
|
start: node.source.start,
|
|
46
47
|
end: node.source.end,
|
|
@@ -53,5 +54,3 @@ const pruneFilesConfigSource = (source, configPath, environments) => {
|
|
|
53
54
|
};
|
|
54
55
|
//#endregion
|
|
55
56
|
export { pruneFilesConfigSource };
|
|
56
|
-
|
|
57
|
-
//# sourceMappingURL=prune.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderFactories } from "./runtime/provider-types.js";
|
|
2
2
|
import { Adapter, FilesHooks, FilesOptions, FilesPlugin, ProviderSlug } from "files-sdk";
|
|
3
3
|
import { AuthorizeContext, AuthorizeResult, CreateFilesRouterOptions } from "files-sdk/api";
|
|
4
|
-
import {
|
|
4
|
+
import { RequestEvent } from "@nuxt/schema";
|
|
5
5
|
//#region src/config.d.ts
|
|
6
6
|
export type AdapterFactory = (...args: never[]) => Adapter;
|
|
7
7
|
type StorageAdapter = ProviderSlug | AdapterFactory;
|
|
@@ -28,7 +28,7 @@ export type FilesRoute = Omit<CreateFilesRouterOptions, 'files' | 'authorize'> &
|
|
|
28
28
|
path: string;
|
|
29
29
|
storage?: string;
|
|
30
30
|
authorize?: (context: AuthorizeContext & {
|
|
31
|
-
event:
|
|
31
|
+
event: RequestEvent;
|
|
32
32
|
}) => AuthorizeResult | Promise<AuthorizeResult>;
|
|
33
33
|
};
|
|
34
34
|
export type StorageSet = StorageConfig | Record<string, StorageConfig>;
|
|
@@ -66,7 +66,7 @@ type StorageCheck<T> = T extends {
|
|
|
66
66
|
type StorageOf<T> = T extends {
|
|
67
67
|
storage: infer S;
|
|
68
68
|
} ? S : never;
|
|
69
|
-
type
|
|
69
|
+
type EnvironmentStorage<T> = StorageOf<T extends {
|
|
70
70
|
$development: infer E;
|
|
71
71
|
} ? E : never> | StorageOf<T extends {
|
|
72
72
|
$production: infer E;
|
|
@@ -77,7 +77,13 @@ type StorageBranches<T> = StorageOf<T> | StorageOf<T extends {
|
|
|
77
77
|
} ? E : never> | StorageOf<T extends {
|
|
78
78
|
$env: infer E;
|
|
79
79
|
} ? E[keyof E] : never>;
|
|
80
|
-
type
|
|
80
|
+
type OverrideEntry<Base, Override> = Omit<Base, keyof Override> & Override;
|
|
81
|
+
type OverrideStorage<Base, Override> = Override extends {
|
|
82
|
+
adapter: unknown;
|
|
83
|
+
} ? OverrideEntry<Base, Override> : Override extends object ? { [K in keyof Base | keyof Override]: K extends keyof Override ? OverrideEntry<K extends keyof Base ? Base[K] : {}, Override[K]> : K extends keyof Base ? Base[K] : never; } : never;
|
|
84
|
+
/** Possible storage shapes after inheriting common options into each environment. */
|
|
85
|
+
export type StorageBranches<T> = StorageOf<T> | OverrideStorage<[StorageOf<T>] extends [never] ? {} : StorageOf<T>, EnvironmentStorage<T>>;
|
|
86
|
+
export type StorageNames<T> = StorageBranches<T> extends (infer S) ? S extends {
|
|
81
87
|
adapter: unknown;
|
|
82
88
|
} ? never : S extends object ? Extract<keyof S, string> : never : never;
|
|
83
89
|
type RouteCheck<T> = FilesRoute & ([StorageNames<T>] extends [never] ? {
|
|
@@ -109,5 +115,4 @@ type InputCheck<T> = Record<Exclude<keyof T, 'storage' | 'routes' | '$developmen
|
|
|
109
115
|
} : unknown);
|
|
110
116
|
/** Preserve storage names, adapters, and plugin literals without resolving an environment. */
|
|
111
117
|
export declare function defineFilesConfig<const C extends object>(config: C & FilesConfigInput & InputCheck<NoInfer<C>>): C;
|
|
112
|
-
//#endregion
|
|
113
|
-
//# sourceMappingURL=config.d.ts.map
|
|
118
|
+
//#endregion
|
package/dist/config.js
CHANGED
package/dist/devtools/auth.js
CHANGED