nuxt-files-sdk 0.0.0 → 0.0.1
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 +3 -1
- package/dist/config.d.ts +28 -0
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -0
- package/dist/devtools/client/index.html +113 -0
- package/dist/devtools/devframe.js +24 -0
- package/dist/devtools/devframe.js.map +1 -0
- package/dist/devtools/enabled.js +6 -0
- package/dist/devtools/enabled.js.map +1 -0
- package/dist/devtools/index.js +25 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/devtools/nuxt-v3-handler.d.ts +12 -0
- package/dist/devtools/nuxt-v3-handler.js +12 -0
- package/dist/devtools/nuxt-v3-handler.js.map +1 -0
- package/dist/devtools/nuxt-v3.js +19 -0
- package/dist/devtools/nuxt-v3.js.map +1 -0
- package/dist/devtools/nuxt-v4.js +21 -0
- package/dist/devtools/nuxt-v4.js.map +1 -0
- package/dist/devtools/snapshot.d.ts +21 -0
- package/dist/devtools/snapshot.js +9 -0
- package/dist/devtools/snapshot.js.map +1 -0
- package/dist/integration/nitro.d.ts +24 -0
- package/dist/integration/nitro.js +53 -0
- package/dist/integration/nitro.js.map +1 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.js +51 -0
- package/dist/module.js.map +1 -0
- package/dist/nitro.d.ts +15 -0
- package/dist/nitro.js +20 -0
- package/dist/nitro.js.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/plugins.d.ts +31 -0
- package/dist/plugins.js +16 -0
- package/dist/runtime/registry.d.ts +27 -0
- package/dist/runtime/registry.js +116 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.js +24 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +71 -13
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Liry24
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
# nuxt-files-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native-first integration of [Files SDK](https://github.com/haydenbleasel/files-sdk) with Nuxt and Nitro.
|
|
4
|
+
|
|
5
|
+
> This repository is under initial development.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FilesHooks, FilesPlugin, ProviderSlug } from "files-sdk";
|
|
2
|
+
import { LoadFilesOptions } from "files-sdk/loader";
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
export type StorageConfig<Plugins extends readonly FilesPlugin[] = readonly FilesPlugin[]> = Omit<LoadFilesOptions, 'provider'> & {
|
|
5
|
+
/** Files SDK provider subpath, for example `r2`, `s3`, or `fs`. */
|
|
6
|
+
adapter: ProviderSlug;
|
|
7
|
+
/** Native Files SDK plugins, applied in array order. */
|
|
8
|
+
plugins?: Plugins;
|
|
9
|
+
/** Native Files SDK hooks. They run before the integration hook bridge. */
|
|
10
|
+
hooks?: FilesHooks;
|
|
11
|
+
};
|
|
12
|
+
export type DevStorageConfig = Omit<StorageConfig, 'plugins' | 'hooks'> & {
|
|
13
|
+
/** Plugins belong to the logical storage and cannot be replaced in development. */
|
|
14
|
+
plugins?: never;
|
|
15
|
+
/** Hooks belong to the logical storage and cannot be replaced in development. */
|
|
16
|
+
hooks?: never;
|
|
17
|
+
};
|
|
18
|
+
export interface FilesConfig<Storage extends Record<string, StorageConfig> = Record<string, StorageConfig>> {
|
|
19
|
+
/** Storage used when useServerFiles() is called without a name. */
|
|
20
|
+
default?: keyof Storage & string;
|
|
21
|
+
/** Explicit development overrides. These never act as failure fallbacks. */
|
|
22
|
+
devStorage?: Partial<{ [Name in keyof Storage]: DevStorageConfig; }>;
|
|
23
|
+
storage: Storage;
|
|
24
|
+
}
|
|
25
|
+
/** Preserve storage names and plugin tuples for generated/project types. */
|
|
26
|
+
export declare const defineFilesConfig: <const Config extends FilesConfig>(config: Config) => Config;
|
|
27
|
+
//#endregion
|
|
28
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import type { FilesHooks, FilesPlugin, ProviderSlug } from 'files-sdk'\nimport type { LoadFilesOptions } from 'files-sdk/loader'\n\nexport type StorageConfig<Plugins extends readonly FilesPlugin[] = readonly FilesPlugin[]> = Omit<\n LoadFilesOptions,\n 'provider'\n> & {\n /** Files SDK provider subpath, for example `r2`, `s3`, or `fs`. */\n adapter: ProviderSlug\n /** Native Files SDK plugins, applied in array order. */\n plugins?: Plugins\n /** Native Files SDK hooks. They run before the integration hook bridge. */\n hooks?: FilesHooks\n}\n\nexport type DevStorageConfig = Omit<StorageConfig, 'plugins' | 'hooks'> & {\n /** Plugins belong to the logical storage and cannot be replaced in development. */\n plugins?: never\n /** Hooks belong to the logical storage and cannot be replaced in development. */\n hooks?: never\n}\n\nexport interface FilesConfig<Storage extends Record<string, StorageConfig> = Record<string, StorageConfig>> {\n /** Storage used when useServerFiles() is called without a name. */\n default?: keyof Storage & string\n /** Explicit development overrides. These never act as failure fallbacks. */\n devStorage?: Partial<{ [Name in keyof Storage]: DevStorageConfig }>\n storage: Storage\n}\n\n/** Preserve storage names and plugin tuples for generated/project types. */\nexport const defineFilesConfig = <const Config extends FilesConfig>(config: Config): Config => config\n"],"mappings":";;AA+BA,MAAa,qBAAuD,WAA2B"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Files</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
font-family: system-ui, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 20px;
|
|
15
|
+
background: Canvas;
|
|
16
|
+
color: CanvasText;
|
|
17
|
+
}
|
|
18
|
+
h1 {
|
|
19
|
+
margin: 0 0 4px;
|
|
20
|
+
font-size: 20px;
|
|
21
|
+
}
|
|
22
|
+
#summary {
|
|
23
|
+
margin: 0 0 20px;
|
|
24
|
+
color: GrayText;
|
|
25
|
+
}
|
|
26
|
+
table {
|
|
27
|
+
width: 100%;
|
|
28
|
+
border-collapse: collapse;
|
|
29
|
+
}
|
|
30
|
+
th,
|
|
31
|
+
td {
|
|
32
|
+
padding: 10px;
|
|
33
|
+
border-bottom: 1px solid color-mix(in srgb, CanvasText 18%, transparent);
|
|
34
|
+
text-align: left;
|
|
35
|
+
}
|
|
36
|
+
th {
|
|
37
|
+
font-size: 12px;
|
|
38
|
+
color: GrayText;
|
|
39
|
+
text-transform: uppercase;
|
|
40
|
+
}
|
|
41
|
+
code {
|
|
42
|
+
font-family: ui-monospace, monospace;
|
|
43
|
+
}
|
|
44
|
+
.warning,
|
|
45
|
+
.error {
|
|
46
|
+
padding: 10px;
|
|
47
|
+
border-radius: 6px;
|
|
48
|
+
background: color-mix(in srgb, orange 16%, Canvas);
|
|
49
|
+
}
|
|
50
|
+
.error {
|
|
51
|
+
background: color-mix(in srgb, red 16%, Canvas);
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<main>
|
|
57
|
+
<h1>Files</h1>
|
|
58
|
+
<p id="summary" aria-live="polite">Loading resolved configuration…</p>
|
|
59
|
+
<section aria-labelledby="storages-heading">
|
|
60
|
+
<h2 id="storages-heading">Storages</h2>
|
|
61
|
+
<table>
|
|
62
|
+
<thead>
|
|
63
|
+
<tr>
|
|
64
|
+
<th>Name</th>
|
|
65
|
+
<th>Adapter</th>
|
|
66
|
+
<th>Plugins</th>
|
|
67
|
+
<th>Source</th>
|
|
68
|
+
<th>Status</th>
|
|
69
|
+
</tr>
|
|
70
|
+
</thead>
|
|
71
|
+
<tbody id="storages"></tbody>
|
|
72
|
+
</table>
|
|
73
|
+
</section>
|
|
74
|
+
<section aria-labelledby="diagnostics-heading">
|
|
75
|
+
<h2 id="diagnostics-heading">Diagnostics</h2>
|
|
76
|
+
<div id="diagnostics"></div>
|
|
77
|
+
</section>
|
|
78
|
+
</main>
|
|
79
|
+
<script type="module">
|
|
80
|
+
const snapshot = await fetch('./snapshot').then((response) => response.json())
|
|
81
|
+
document.querySelector('#summary').textContent =
|
|
82
|
+
`${snapshot.storages.length} configured storage${snapshot.storages.length === 1 ? '' : 's'}`
|
|
83
|
+
document.querySelector('#storages').replaceChildren(
|
|
84
|
+
...snapshot.storages.map((storage) => {
|
|
85
|
+
const row = document.createElement('tr')
|
|
86
|
+
for (const value of [
|
|
87
|
+
storage.name,
|
|
88
|
+
storage.adapter,
|
|
89
|
+
storage.plugins.join(', ') || '—',
|
|
90
|
+
storage.source,
|
|
91
|
+
storage.initialized ? 'Initialized' : 'Not initialized',
|
|
92
|
+
]) {
|
|
93
|
+
const cell = document.createElement('td')
|
|
94
|
+
cell.textContent = value
|
|
95
|
+
row.append(cell)
|
|
96
|
+
}
|
|
97
|
+
return row
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
const diagnostics = document.querySelector('#diagnostics')
|
|
101
|
+
if (!snapshot.diagnostics.length) diagnostics.textContent = 'No integration diagnostics.'
|
|
102
|
+
else
|
|
103
|
+
diagnostics.replaceChildren(
|
|
104
|
+
...snapshot.diagnostics.map((item) => {
|
|
105
|
+
const message = document.createElement('p')
|
|
106
|
+
message.className = item.level
|
|
107
|
+
message.textContent = `${item.code}: ${item.message}`
|
|
108
|
+
return message
|
|
109
|
+
}),
|
|
110
|
+
)
|
|
111
|
+
</script>
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FILES_DEVTOOLS_PATH } from "./snapshot.js";
|
|
2
|
+
import { version } from "../package.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { defineDevframe } from "devframe";
|
|
5
|
+
//#region src/devtools/devframe.ts
|
|
6
|
+
var devframe_default = defineDevframe({
|
|
7
|
+
id: "nuxt-files-sdk",
|
|
8
|
+
name: "Files",
|
|
9
|
+
version,
|
|
10
|
+
packageName: "nuxt-files-sdk",
|
|
11
|
+
importMetaUrl: import.meta.url,
|
|
12
|
+
homepage: "https://github.com/liria24/nuxt-files-sdk",
|
|
13
|
+
description: "Files SDK storage and integration diagnostics for Nuxt.",
|
|
14
|
+
icon: "ph:files-duotone",
|
|
15
|
+
basePath: FILES_DEVTOOLS_PATH,
|
|
16
|
+
cli: { distDir: fileURLToPath(new URL("./client", import.meta.url)) },
|
|
17
|
+
setup(context) {
|
|
18
|
+
context.views.hostStatic(FILES_DEVTOOLS_PATH, fileURLToPath(new URL("./client", import.meta.url)));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
//#endregion
|
|
22
|
+
export { devframe_default as default };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=devframe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devframe.js","names":[],"sources":["../../src/devtools/devframe.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url'\n\nimport { defineDevframe } from 'devframe'\n\nimport { version } from '../../package.json'\nimport { FILES_DEVTOOLS_PATH } from './snapshot'\n\nexport default defineDevframe({\n id: 'nuxt-files-sdk',\n name: 'Files',\n version,\n packageName: 'nuxt-files-sdk',\n importMetaUrl: import.meta.url,\n homepage: 'https://github.com/liria24/nuxt-files-sdk',\n description: 'Files SDK storage and integration diagnostics for Nuxt.',\n icon: 'ph:files-duotone',\n basePath: FILES_DEVTOOLS_PATH,\n cli: { distDir: fileURLToPath(new URL('./client', import.meta.url)) },\n setup(context) {\n context.views.hostStatic(FILES_DEVTOOLS_PATH, fileURLToPath(new URL('./client', import.meta.url)))\n },\n})\n"],"mappings":";;;;;AAOA,IAAA,mBAAe,eAAe;CAC1B,IAAI;CACJ,MAAM;CACN;CACA,aAAa;CACb,eAAe,YAAY;CAC3B,UAAU;CACV,aAAa;CACb,MAAM;CACN,UAAU;CACV,KAAK,EAAE,SAAS,cAAc,IAAI,IAAI,YAAY,YAAY,GAAG,CAAC,EAAE;CACpE,MAAM,SAAS;EACX,QAAQ,MAAM,WAAW,qBAAqB,cAAc,IAAI,IAAI,YAAY,YAAY,GAAG,CAAC,CAAC;CACrG;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/devtools/enabled.ts
|
|
2
|
+
const shouldEnableFilesDevtools = (development, moduleEnabled, nuxtDevtools) => development && moduleEnabled && (typeof nuxtDevtools === "boolean" ? nuxtDevtools : nuxtDevtools.enabled);
|
|
3
|
+
//#endregion
|
|
4
|
+
export { shouldEnableFilesDevtools };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=enabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enabled.js","names":[],"sources":["../../src/devtools/enabled.ts"],"sourcesContent":["export const shouldEnableFilesDevtools = (\n development: boolean,\n moduleEnabled: boolean,\n nuxtDevtools: boolean | { enabled: boolean },\n): boolean => development && moduleEnabled && (typeof nuxtDevtools === 'boolean' ? nuxtDevtools : nuxtDevtools.enabled)\n"],"mappings":";AAAA,MAAa,6BACT,aACA,eACA,iBACU,eAAe,kBAAkB,OAAO,iBAAiB,YAAY,eAAe,aAAa"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import nuxt_v3_handler_default from "./nuxt-v3-handler.js";
|
|
2
|
+
import { FILES_DEVTOOLS_PATH, FILES_SNAPSHOT_PATH } from "./snapshot.js";
|
|
3
|
+
import { setupNuxtV3Devtools } from "./nuxt-v3.js";
|
|
4
|
+
import { setupNuxtV4Devtools } from "./nuxt-v4.js";
|
|
5
|
+
import { addDevServerHandler, addServerHandler } from "@nuxt/kit";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
//#region src/devtools/index.ts
|
|
8
|
+
const setupFilesDevtools = (nuxt, version) => {
|
|
9
|
+
addServerHandler({
|
|
10
|
+
route: FILES_SNAPSHOT_PATH,
|
|
11
|
+
handler: fileURLToPath(new URL("./snapshot.js", import.meta.url))
|
|
12
|
+
});
|
|
13
|
+
if (Number.parseInt(version) >= 4) setupNuxtV4Devtools(nuxt);
|
|
14
|
+
else {
|
|
15
|
+
addDevServerHandler({
|
|
16
|
+
route: FILES_DEVTOOLS_PATH,
|
|
17
|
+
handler: nuxt_v3_handler_default
|
|
18
|
+
});
|
|
19
|
+
setupNuxtV3Devtools(nuxt);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { setupFilesDevtools };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["uiHandler"],"sources":["../../src/devtools/index.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url'\n\nimport { addDevServerHandler, addServerHandler } from '@nuxt/kit'\nimport type { Nuxt } from '@nuxt/schema'\n\nimport { setupNuxtV3Devtools } from './nuxt-v3'\nimport uiHandler from './nuxt-v3-handler'\nimport { setupNuxtV4Devtools } from './nuxt-v4'\nimport { FILES_DEVTOOLS_PATH, FILES_SNAPSHOT_PATH } from './snapshot'\n\nexport const setupFilesDevtools = (nuxt: Nuxt, version: string): void => {\n // Snapshot must run inside Nitro's worker, where the runtime registry lives.\n addServerHandler({\n route: FILES_SNAPSHOT_PATH,\n handler: fileURLToPath(new URL('./snapshot.js', import.meta.url)),\n })\n if (Number.parseInt(version) >= 4) {\n setupNuxtV4Devtools(nuxt)\n } else {\n addDevServerHandler({\n route: FILES_DEVTOOLS_PATH,\n handler: uiHandler,\n })\n setupNuxtV3Devtools(nuxt)\n }\n}\n"],"mappings":";;;;;;;AAUA,MAAa,sBAAsB,MAAY,YAA0B;CAErE,iBAAiB;EACb,OAAO;EACP,SAAS,cAAc,IAAI,IAAI,iBAAiB,YAAY,GAAG,CAAC;CACpE,CAAC;CACD,IAAI,OAAO,SAAS,OAAO,KAAK,GAC5B,oBAAoB,IAAI;MACrB;EACH,oBAAoB;GAChB,OAAO;GACP,SAASA;EACb,CAAC;EACD,oBAAoB,IAAI;CAC5B;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/devtools/nuxt-v3-handler.d.ts
|
|
2
|
+
declare function _default(event: {
|
|
3
|
+
path: string;
|
|
4
|
+
node: {
|
|
5
|
+
res: {
|
|
6
|
+
setHeader(name: string, value: string): void;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
}): Promise<string | undefined>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { _default as default };
|
|
12
|
+
//# sourceMappingURL=nuxt-v3-handler.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
//#region src/devtools/nuxt-v3-handler.ts
|
|
3
|
+
const html = readFile(new URL("./client/index.html", import.meta.url), "utf8");
|
|
4
|
+
var nuxt_v3_handler_default = async (event) => {
|
|
5
|
+
if (event.path !== "/" && event.path !== "/index.html") return void 0;
|
|
6
|
+
event.node.res.setHeader("content-type", "text/html; charset=utf-8");
|
|
7
|
+
return html;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { nuxt_v3_handler_default as default };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=nuxt-v3-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nuxt-v3-handler.js","names":[],"sources":["../../src/devtools/nuxt-v3-handler.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises'\n\nconst html = readFile(new URL('./client/index.html', import.meta.url), 'utf8')\n\nexport default async (event: { path: string; node: { res: { setHeader(name: string, value: string): void } } }) => {\n if (event.path !== '/' && event.path !== '/index.html') return undefined\n event.node.res.setHeader('content-type', 'text/html; charset=utf-8')\n return html\n}\n"],"mappings":";;AAEA,MAAM,OAAO,SAAS,IAAI,IAAI,uBAAuB,YAAY,GAAG,GAAG,MAAM;AAE7E,IAAA,0BAAe,OAAO,UAA6F;CAC/G,IAAI,MAAM,SAAS,OAAO,MAAM,SAAS,eAAe,OAAO,KAAA;CAC/D,MAAM,KAAK,IAAI,UAAU,gBAAgB,0BAA0B;CACnE,OAAO;AACX"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FILES_DEVTOOLS_PATH } from "./snapshot.js";
|
|
2
|
+
//#region src/devtools/nuxt-v3.ts
|
|
3
|
+
const setupNuxtV3Devtools = (nuxt) => {
|
|
4
|
+
nuxt.hook("devtools:customTabs", (tabs) => {
|
|
5
|
+
tabs.push({
|
|
6
|
+
name: "nuxt-files-sdk",
|
|
7
|
+
title: "Files",
|
|
8
|
+
icon: "ph:files-duotone",
|
|
9
|
+
view: {
|
|
10
|
+
type: "iframe",
|
|
11
|
+
src: FILES_DEVTOOLS_PATH
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { setupNuxtV3Devtools };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=nuxt-v3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nuxt-v3.js","names":[],"sources":["../../src/devtools/nuxt-v3.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema'\n\nimport { FILES_DEVTOOLS_PATH } from './snapshot'\n\ninterface CustomTab {\n name: string\n title: string\n icon: string\n view: { type: 'iframe'; src: string }\n}\n\ndeclare module '@nuxt/schema' {\n interface NuxtHooks {\n 'devtools:customTabs': (tabs: CustomTab[]) => void\n }\n}\n\nexport const setupNuxtV3Devtools = (nuxt: Nuxt): void => {\n nuxt.hook('devtools:customTabs', (tabs) => {\n tabs.push({\n name: 'nuxt-files-sdk',\n title: 'Files',\n icon: 'ph:files-duotone',\n view: { type: 'iframe', src: FILES_DEVTOOLS_PATH },\n })\n })\n}\n"],"mappings":";;AAiBA,MAAa,uBAAuB,SAAqB;CACrD,KAAK,KAAK,wBAAwB,SAAS;EACvC,KAAK,KAAK;GACN,MAAM;GACN,OAAO;GACP,MAAM;GACN,MAAM;IAAE,MAAM;IAAU,KAAK;GAAoB;EACrD,CAAC;CACL,CAAC;AACL"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FILES_DEVTOOLS_PATH } from "./snapshot.js";
|
|
2
|
+
import devframe_default from "./devframe.js";
|
|
3
|
+
import { createEmbedded } from "devframe/adapters/embedded";
|
|
4
|
+
//#region src/devtools/nuxt-v4.ts
|
|
5
|
+
const setupNuxtV4Devtools = (nuxt) => {
|
|
6
|
+
nuxt.hook("devtools:ready", async (context) => {
|
|
7
|
+
await createEmbedded(devframe_default, { ctx: context });
|
|
8
|
+
context.docks.register({
|
|
9
|
+
id: "nuxt-files-sdk",
|
|
10
|
+
title: "Files",
|
|
11
|
+
icon: "ph:files-duotone",
|
|
12
|
+
type: "iframe",
|
|
13
|
+
url: FILES_DEVTOOLS_PATH,
|
|
14
|
+
groupId: "nuxt"
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { setupNuxtV4Devtools };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=nuxt-v4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nuxt-v4.js","names":["filesDevframe"],"sources":["../../src/devtools/nuxt-v4.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema'\nimport { createEmbedded } from 'devframe/adapters/embedded'\n\nimport filesDevframe from './devframe'\nimport { FILES_DEVTOOLS_PATH } from './snapshot'\n\ntype DevtoolsContext = Parameters<typeof createEmbedded>[1]['ctx'] & {\n docks: {\n register(entry: {\n id: string\n title: string\n icon: string\n type: 'iframe'\n url: string\n groupId: string\n }): unknown\n }\n}\n\ndeclare module '@nuxt/schema' {\n interface NuxtHooks {\n 'devtools:ready': (context: DevtoolsContext) => void | Promise<void>\n }\n}\n\nexport const setupNuxtV4Devtools = (nuxt: Nuxt): void => {\n nuxt.hook('devtools:ready', async (context) => {\n await createEmbedded(filesDevframe, { ctx: context })\n context.docks.register({\n id: 'nuxt-files-sdk',\n title: 'Files',\n icon: 'ph:files-duotone',\n type: 'iframe',\n url: FILES_DEVTOOLS_PATH,\n groupId: 'nuxt',\n })\n })\n}\n"],"mappings":";;;;AAyBA,MAAa,uBAAuB,SAAqB;CACrD,KAAK,KAAK,kBAAkB,OAAO,YAAY;EAC3C,MAAM,eAAeA,kBAAe,EAAE,KAAK,QAAQ,CAAC;EACpD,QAAQ,MAAM,SAAS;GACnB,IAAI;GACJ,OAAO;GACP,MAAM;GACN,MAAM;GACN,KAAK;GACL,SAAS;EACb,CAAC;CACL,CAAC;AACL"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/devtools/snapshot.d.ts
|
|
2
|
+
export interface FilesDevtoolsSnapshot {
|
|
3
|
+
storages: Array<{
|
|
4
|
+
name: string;
|
|
5
|
+
adapter: string;
|
|
6
|
+
plugins: string[];
|
|
7
|
+
source: 'storage' | 'devStorage';
|
|
8
|
+
initialized: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
diagnostics: Array<{
|
|
11
|
+
code: string;
|
|
12
|
+
level: 'info' | 'warning' | 'error';
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare const FILES_DEVTOOLS_PATH = "/__nuxt-files-sdk/";
|
|
17
|
+
export declare const FILES_SNAPSHOT_PATH = "/__nuxt-files-sdk/snapshot";
|
|
18
|
+
declare function _default(): FilesDevtoolsSnapshot;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { _default as default };
|
|
21
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { inspectFiles } from "../runtime.js";
|
|
2
|
+
//#region src/devtools/snapshot.ts
|
|
3
|
+
const FILES_DEVTOOLS_PATH = "/__nuxt-files-sdk/";
|
|
4
|
+
const FILES_SNAPSHOT_PATH = `${FILES_DEVTOOLS_PATH}snapshot`;
|
|
5
|
+
var snapshot_default = () => inspectFiles();
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FILES_DEVTOOLS_PATH, FILES_SNAPSHOT_PATH, snapshot_default as default };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","names":[],"sources":["../../src/devtools/snapshot.ts"],"sourcesContent":["import { inspectFiles } from '../runtime'\n\nexport interface FilesDevtoolsSnapshot {\n storages: Array<{\n name: string\n adapter: string\n plugins: string[]\n source: 'storage' | 'devStorage'\n initialized: boolean\n }>\n diagnostics: Array<{\n code: string\n level: 'info' | 'warning' | 'error'\n message: string\n }>\n}\n\nexport const FILES_DEVTOOLS_PATH = '/__nuxt-files-sdk/'\nexport const FILES_SNAPSHOT_PATH = `${FILES_DEVTOOLS_PATH}snapshot`\n\nexport default () => inspectFiles()\n"],"mappings":";;AAiBA,MAAa,sBAAsB;AACnC,MAAa,sBAAsB,GAAG,oBAAoB;AAE1D,IAAA,yBAAqB,aAAa"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/integration/nitro.d.ts
|
|
2
|
+
export interface NitroIntegration {
|
|
3
|
+
meta?: {
|
|
4
|
+
majorVersion?: number;
|
|
5
|
+
};
|
|
6
|
+
options: {
|
|
7
|
+
rootDir: string;
|
|
8
|
+
buildDir: string;
|
|
9
|
+
dev?: boolean;
|
|
10
|
+
plugins: string[];
|
|
11
|
+
externals?: {
|
|
12
|
+
inline?: unknown[];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
hooks: {
|
|
16
|
+
hook(name: 'types:extend', callback: (types: {
|
|
17
|
+
tsConfig?: {
|
|
18
|
+
include?: string[];
|
|
19
|
+
};
|
|
20
|
+
}) => void | Promise<void>): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=nitro.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
//#region src/integration/nitro.ts
|
|
4
|
+
const hookTypes = (moduleName) => `
|
|
5
|
+
declare module ${JSON.stringify(moduleName)} {
|
|
6
|
+
interface NitroRuntimeHooks {
|
|
7
|
+
'files:action': (payload: { event: import('files-sdk').FilesActionEvent; storage: string }) => void | Promise<void>
|
|
8
|
+
'files:error': (payload: { event: import('files-sdk').FilesErrorEvent; storage: string }) => void | Promise<void>
|
|
9
|
+
'files:retry': (payload: { event: import('files-sdk').FilesRetryEvent; storage: string }) => void | Promise<void>
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
const storageTypes = (configPath, nitroMajor) => `import type config from ${JSON.stringify(configPath)}
|
|
14
|
+
import type { DefaultStorage, StorageRegistry } from 'nuxt-files-sdk/runtime'
|
|
15
|
+
|
|
16
|
+
declare module 'nuxt-files-sdk/runtime' {
|
|
17
|
+
interface NuxtFilesStorageRegistry extends StorageRegistry<typeof config> {}
|
|
18
|
+
interface NuxtFilesDefaultStorage { value: DefaultStorage<typeof config> }
|
|
19
|
+
}
|
|
20
|
+
${hookTypes(nitroMajor >= 3 ? "nitro/types" : "nitropack/types")}
|
|
21
|
+
export {}
|
|
22
|
+
`;
|
|
23
|
+
const setupNitroFilesIntegration = async (nitro, options) => {
|
|
24
|
+
const configPath = options.configPath.replaceAll("\\", "/");
|
|
25
|
+
const externals = nitro.options.externals ??= {};
|
|
26
|
+
(externals.inline ??= []).push("nuxt-files-sdk");
|
|
27
|
+
if (!nitro.options.dev) externals.inline.push("files-sdk");
|
|
28
|
+
const directory = resolve(nitro.options.buildDir, "nuxt-files-sdk");
|
|
29
|
+
const pluginPath = resolve(directory, "plugin.mjs");
|
|
30
|
+
const typesPath = resolve(directory, "storage-registry.d.ts");
|
|
31
|
+
externals.inline.push(pluginPath.replaceAll("\\", "/"), configPath);
|
|
32
|
+
nitro.options.plugins.push(pluginPath.replaceAll("\\", "/"));
|
|
33
|
+
nitro.hooks.hook("types:extend", async (types) => {
|
|
34
|
+
await mkdir(directory, { recursive: true });
|
|
35
|
+
await Promise.all([writeFile(pluginPath, `import config from ${JSON.stringify(configPath)}
|
|
36
|
+
import { configureFiles } from 'nuxt-files-sdk/runtime'
|
|
37
|
+
|
|
38
|
+
export default (nitroApp) => configureFiles(config, {
|
|
39
|
+
development: ${JSON.stringify(options.development)},
|
|
40
|
+
hooks: {
|
|
41
|
+
onAction: (event, storage) => nitroApp.hooks.callHook('files:action', { event, storage }),
|
|
42
|
+
onError: (event, storage) => nitroApp.hooks.callHook('files:error', { event, storage }),
|
|
43
|
+
onRetry: (event, storage) => nitroApp.hooks.callHook('files:retry', { event, storage }),
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
`), writeFile(typesPath, storageTypes(configPath, nitro.meta?.majorVersion ?? ("routing" in nitro ? 3 : 2)))]);
|
|
47
|
+
types.tsConfig?.include?.push(typesPath);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { setupNitroFilesIntegration, storageTypes };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=nitro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro.js","names":[],"sources":["../../src/integration/nitro.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises'\nimport { resolve } from 'node:path'\n\nexport interface NitroIntegration {\n meta?: { majorVersion?: number }\n options: { rootDir: string; buildDir: string; dev?: boolean; plugins: string[]; externals?: { inline?: unknown[] } }\n hooks: {\n hook(\n name: 'types:extend',\n callback: (types: { tsConfig?: { include?: string[] } }) => void | Promise<void>,\n ): void\n }\n}\n\nexport interface NitroFilesIntegrationOptions {\n configPath: string\n development: boolean\n}\n\nconst hookTypes = (moduleName: 'nitropack/types' | 'nitro/types'): string => `\ndeclare module ${JSON.stringify(moduleName)} {\n interface NitroRuntimeHooks {\n 'files:action': (payload: { event: import('files-sdk').FilesActionEvent; storage: string }) => void | Promise<void>\n 'files:error': (payload: { event: import('files-sdk').FilesErrorEvent; storage: string }) => void | Promise<void>\n 'files:retry': (payload: { event: import('files-sdk').FilesRetryEvent; storage: string }) => void | Promise<void>\n }\n}\n`\n\nexport const storageTypes = (\n configPath: string,\n nitroMajor: number,\n): string => `import type config from ${JSON.stringify(configPath)}\nimport type { DefaultStorage, StorageRegistry } from 'nuxt-files-sdk/runtime'\n\ndeclare module 'nuxt-files-sdk/runtime' {\n interface NuxtFilesStorageRegistry extends StorageRegistry<typeof config> {}\n interface NuxtFilesDefaultStorage { value: DefaultStorage<typeof config> }\n}\n${hookTypes(nitroMajor >= 3 ? 'nitro/types' : 'nitropack/types')}\nexport {}\n`\n\nexport const setupNitroFilesIntegration = async (\n nitro: NitroIntegration,\n options: NitroFilesIntegrationOptions,\n): Promise<void> => {\n const configPath = options.configPath.replaceAll('\\\\', '/')\n // Inline both packages so installed consumers also tree-shake the plugin barrel.\n const externals = (nitro.options.externals ??= {})\n ;(externals.inline ??= []).push('nuxt-files-sdk')\n // Nitro's single-file dev build would eagerly import every native provider SDK.\n if (!nitro.options.dev) externals.inline.push('files-sdk')\n const directory = resolve(nitro.options.buildDir, 'nuxt-files-sdk')\n const pluginPath = resolve(directory, 'plugin.mjs')\n const typesPath = resolve(directory, 'storage-registry.d.ts')\n // Development also externalizes local .mjs files unless explicitly inlined.\n externals.inline.push(pluginPath.replaceAll('\\\\', '/'), configPath)\n nitro.options.plugins.push(pluginPath.replaceAll('\\\\', '/'))\n nitro.hooks.hook('types:extend', async (types) => {\n await mkdir(directory, { recursive: true })\n await Promise.all([\n writeFile(\n pluginPath,\n `import config from ${JSON.stringify(configPath)}\nimport { configureFiles } from 'nuxt-files-sdk/runtime'\n\nexport default (nitroApp) => configureFiles(config, {\n development: ${JSON.stringify(options.development)},\n hooks: {\n onAction: (event, storage) => nitroApp.hooks.callHook('files:action', { event, storage }),\n onError: (event, storage) => nitroApp.hooks.callHook('files:error', { event, storage }),\n onRetry: (event, storage) => nitroApp.hooks.callHook('files:retry', { event, storage }),\n },\n})\n`,\n ),\n // Older v2 and current v3 omit meta; only v3 exposes the routing API.\n writeFile(typesPath, storageTypes(configPath, nitro.meta?.majorVersion ?? ('routing' in nitro ? 3 : 2))),\n ])\n types.tsConfig?.include?.push(typesPath)\n })\n}\n"],"mappings":";;;AAmBA,MAAM,aAAa,eAA0D;iBAC5D,KAAK,UAAU,UAAU,EAAE;;;;;;;;AAS5C,MAAa,gBACT,YACA,eACS,2BAA2B,KAAK,UAAU,UAAU,EAAE;;;;;;;EAOjE,UAAU,cAAc,IAAI,gBAAgB,iBAAiB,EAAE;;;AAIjE,MAAa,6BAA6B,OACtC,OACA,YACgB;CAChB,MAAM,aAAa,QAAQ,WAAW,WAAW,MAAM,GAAG;CAE1D,MAAM,YAAa,MAAM,QAAQ,cAAc,CAAC;CAC/C,CAAC,UAAU,WAAW,CAAC,EAAA,CAAG,KAAK,gBAAgB;CAEhD,IAAI,CAAC,MAAM,QAAQ,KAAK,UAAU,OAAO,KAAK,WAAW;CACzD,MAAM,YAAY,QAAQ,MAAM,QAAQ,UAAU,gBAAgB;CAClE,MAAM,aAAa,QAAQ,WAAW,YAAY;CAClD,MAAM,YAAY,QAAQ,WAAW,uBAAuB;CAE5D,UAAU,OAAO,KAAK,WAAW,WAAW,MAAM,GAAG,GAAG,UAAU;CAClE,MAAM,QAAQ,QAAQ,KAAK,WAAW,WAAW,MAAM,GAAG,CAAC;CAC3D,MAAM,MAAM,KAAK,gBAAgB,OAAO,UAAU;EAC9C,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;EAC1C,MAAM,QAAQ,IAAI,CACd,UACI,YACA,sBAAsB,KAAK,UAAU,UAAU,EAAE;;;;iBAIhD,KAAK,UAAU,QAAQ,WAAW,EAAE;;;;;;;CAQzC,GAEA,UAAU,WAAW,aAAa,YAAY,MAAM,MAAM,iBAAiB,aAAa,QAAQ,IAAI,EAAE,CAAC,CAC3G,CAAC;EACD,MAAM,UAAU,SAAS,KAAK,SAAS;CAC3C,CAAC;AACL"}
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NitroIntegration } from "./integration/nitro.js";
|
|
2
|
+
import { DefaultStorage, DefaultStorageName, FilesForStorage, FilesRegistry, FilesRuntimeHooks, StorageRegistry } from "./runtime/registry.js";
|
|
3
|
+
import { NuxtFilesDefaultStorage, NuxtFilesStorageRegistry, configureFiles, inspectFiles, useServerFiles } from "./runtime.js";
|
|
4
|
+
export * from "files-sdk";
|
|
5
|
+
//#region src/module.d.ts
|
|
6
|
+
declare module '@nuxt/schema' {
|
|
7
|
+
interface NuxtHooks {
|
|
8
|
+
'nitro:init': (nitro: NitroIntegration) => void | Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export interface ModuleOptions {
|
|
12
|
+
/** Files configuration path, relative to the Nuxt root. */
|
|
13
|
+
config: string;
|
|
14
|
+
/** Enable development diagnostics integrations. */
|
|
15
|
+
devtools: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const _default: import("@nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { type DefaultStorage, type DefaultStorageName, type FilesForStorage, FilesRegistry, type FilesRuntimeHooks, NuxtFilesDefaultStorage, NuxtFilesStorageRegistry, type StorageRegistry, configureFiles, _default as default, inspectFiles, useServerFiles };
|
|
20
|
+
//# sourceMappingURL=module.d.ts.map
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { shouldEnableFilesDevtools } from "./devtools/enabled.js";
|
|
2
|
+
import { setupNitroFilesIntegration } from "./integration/nitro.js";
|
|
3
|
+
import { FilesRegistry } from "./runtime/registry.js";
|
|
4
|
+
import { configureFiles, inspectFiles, useServerFiles } from "./runtime.js";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { addImports, addServerImports, defineNuxtModule, getNuxtModuleVersion } from "@nuxt/kit";
|
|
7
|
+
export * from "files-sdk";
|
|
8
|
+
//#region src/module.ts
|
|
9
|
+
var module_default = defineNuxtModule({
|
|
10
|
+
meta: {
|
|
11
|
+
name: "nuxt-files-sdk",
|
|
12
|
+
configKey: "files",
|
|
13
|
+
compatibility: { nuxt: "^4.0.0 || ^5.0.0" }
|
|
14
|
+
},
|
|
15
|
+
defaults: {
|
|
16
|
+
config: "files.config.ts",
|
|
17
|
+
devtools: true
|
|
18
|
+
},
|
|
19
|
+
async setup(options, nuxt) {
|
|
20
|
+
const configPath = resolve(nuxt.options.rootDir, options.config);
|
|
21
|
+
nuxt.hook("nitro:init", (nitro) => setupNitroFilesIntegration(nitro, {
|
|
22
|
+
configPath,
|
|
23
|
+
development: nuxt.options.dev
|
|
24
|
+
}));
|
|
25
|
+
nuxt.hook("prepare:types", ({ references }) => {
|
|
26
|
+
references.push({ path: resolve(nuxt.options.buildDir, "nuxt-files-sdk/storage-registry.d.ts") });
|
|
27
|
+
});
|
|
28
|
+
addServerImports({
|
|
29
|
+
name: "useServerFiles",
|
|
30
|
+
from: "nuxt-files-sdk/runtime"
|
|
31
|
+
});
|
|
32
|
+
for (const name of [
|
|
33
|
+
"useFiles",
|
|
34
|
+
"useFile",
|
|
35
|
+
"useList",
|
|
36
|
+
"useSearch"
|
|
37
|
+
]) addImports({
|
|
38
|
+
name,
|
|
39
|
+
from: "files-sdk/vue"
|
|
40
|
+
});
|
|
41
|
+
if (shouldEnableFilesDevtools(nuxt.options.dev, options.devtools, nuxt.options.devtools)) {
|
|
42
|
+
const version = await getNuxtModuleVersion("@nuxt/devtools", nuxt);
|
|
43
|
+
const { setupFilesDevtools } = await import("./devtools/index.js");
|
|
44
|
+
setupFilesDevtools(nuxt, version || "3");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
//#endregion
|
|
49
|
+
export { FilesRegistry, configureFiles, module_default as default, inspectFiles, useServerFiles };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport { addImports, addServerImports, defineNuxtModule, getNuxtModuleVersion } from '@nuxt/kit'\nimport type { Nuxt } from '@nuxt/schema'\n\nimport { shouldEnableFilesDevtools } from './devtools/enabled'\nimport { setupNitroFilesIntegration, type NitroIntegration } from './integration/nitro'\n\ndeclare module '@nuxt/schema' {\n interface NuxtHooks {\n 'nitro:init': (nitro: NitroIntegration) => void | Promise<void>\n }\n}\n\nexport interface ModuleOptions {\n /** Files configuration path, relative to the Nuxt root. */\n config: string\n /** Enable development diagnostics integrations. */\n devtools: boolean\n}\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: 'nuxt-files-sdk',\n configKey: 'files',\n compatibility: { nuxt: '^4.0.0 || ^5.0.0' },\n },\n defaults: {\n config: 'files.config.ts',\n devtools: true,\n },\n async setup(options, nuxt: Nuxt) {\n const configPath = resolve(nuxt.options.rootDir, options.config)\n nuxt.hook('nitro:init', (nitro) =>\n setupNitroFilesIntegration(nitro, {\n configPath,\n development: nuxt.options.dev,\n }),\n )\n nuxt.hook('prepare:types', ({ references }) => {\n references.push({ path: resolve(nuxt.options.buildDir, 'nuxt-files-sdk/storage-registry.d.ts') })\n })\n\n addServerImports({ name: 'useServerFiles', from: 'nuxt-files-sdk/runtime' })\n for (const name of ['useFiles', 'useFile', 'useList', 'useSearch']) {\n addImports({ name, from: 'files-sdk/vue' })\n }\n\n if (shouldEnableFilesDevtools(nuxt.options.dev, options.devtools, nuxt.options.devtools)) {\n const version = await getNuxtModuleVersion('@nuxt/devtools', nuxt)\n const { setupFilesDevtools } = await import('./devtools')\n setupFilesDevtools(nuxt, version || '3')\n }\n },\n})\n\nexport * from 'files-sdk'\nexport * from './runtime'\n"],"mappings":";;;;;;;;AAqBA,IAAA,iBAAe,iBAAgC;CAC3C,MAAM;EACF,MAAM;EACN,WAAW;EACX,eAAe,EAAE,MAAM,mBAAmB;CAC9C;CACA,UAAU;EACN,QAAQ;EACR,UAAU;CACd;CACA,MAAM,MAAM,SAAS,MAAY;EAC7B,MAAM,aAAa,QAAQ,KAAK,QAAQ,SAAS,QAAQ,MAAM;EAC/D,KAAK,KAAK,eAAe,UACrB,2BAA2B,OAAO;GAC9B;GACA,aAAa,KAAK,QAAQ;EAC9B,CAAC,CACL;EACA,KAAK,KAAK,kBAAkB,EAAE,iBAAiB;GAC3C,WAAW,KAAK,EAAE,MAAM,QAAQ,KAAK,QAAQ,UAAU,sCAAsC,EAAE,CAAC;EACpG,CAAC;EAED,iBAAiB;GAAE,MAAM;GAAkB,MAAM;EAAyB,CAAC;EAC3E,KAAK,MAAM,QAAQ;GAAC;GAAY;GAAW;GAAW;EAAW,GAC7D,WAAW;GAAE;GAAM,MAAM;EAAgB,CAAC;EAG9C,IAAI,0BAA0B,KAAK,QAAQ,KAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,GAAG;GACtF,MAAM,UAAU,MAAM,qBAAqB,kBAAkB,IAAI;GACjE,MAAM,EAAE,uBAAuB,MAAM,OAAO;GAC5C,mBAAmB,MAAM,WAAW,GAAG;EAC3C;CACJ;AACJ,CAAC"}
|
package/dist/nitro.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NitroIntegration } from "./integration/nitro.js";
|
|
2
|
+
import { DefaultStorage, DefaultStorageName, FilesForStorage, FilesRegistry, FilesRuntimeHooks, StorageRegistry } from "./runtime/registry.js";
|
|
3
|
+
import { NuxtFilesDefaultStorage, NuxtFilesStorageRegistry, configureFiles, inspectFiles, useServerFiles } from "./runtime.js";
|
|
4
|
+
//#region src/nitro.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A structurally compatible Nitro v2/v3 module. Nitro loads this export
|
|
7
|
+
* directly from `modules: ['nuxt-files-sdk/nitro']`.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: {
|
|
10
|
+
name: string;
|
|
11
|
+
setup: (nitro: NitroIntegration) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { type DefaultStorage, type DefaultStorageName, type FilesForStorage, FilesRegistry, type FilesRuntimeHooks, NuxtFilesDefaultStorage, NuxtFilesStorageRegistry, type StorageRegistry, configureFiles, _default as default, inspectFiles, useServerFiles };
|
|
15
|
+
//# sourceMappingURL=nitro.d.ts.map
|
package/dist/nitro.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { setupNitroFilesIntegration } from "./integration/nitro.js";
|
|
2
|
+
import { FilesRegistry } from "./runtime/registry.js";
|
|
3
|
+
import { configureFiles, inspectFiles, useServerFiles } from "./runtime.js";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
//#region src/nitro.ts
|
|
6
|
+
/**
|
|
7
|
+
* A structurally compatible Nitro v2/v3 module. Nitro loads this export
|
|
8
|
+
* directly from `modules: ['nuxt-files-sdk/nitro']`.
|
|
9
|
+
*/
|
|
10
|
+
var nitro_default = {
|
|
11
|
+
name: "nuxt-files-sdk",
|
|
12
|
+
setup: (nitro) => setupNitroFilesIntegration(nitro, {
|
|
13
|
+
configPath: resolve(nitro.options.rootDir, "files.config.ts"),
|
|
14
|
+
development: Boolean(nitro.options.dev)
|
|
15
|
+
})
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FilesRegistry, configureFiles, nitro_default as default, inspectFiles, useServerFiles };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=nitro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro.js","names":[],"sources":["../src/nitro.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport { setupNitroFilesIntegration, type NitroIntegration } from './integration/nitro'\n\n/**\n * A structurally compatible Nitro v2/v3 module. Nitro loads this export\n * directly from `modules: ['nuxt-files-sdk/nitro']`.\n */\nexport default {\n name: 'nuxt-files-sdk',\n setup: (nitro: NitroIntegration) =>\n setupNitroFilesIntegration(nitro, {\n configPath: resolve(nitro.options.rootDir, 'files.config.ts'),\n development: Boolean(nitro.options.dev),\n }),\n}\n\nexport * from './runtime'\n"],"mappings":";;;;;;;;;AAQA,IAAA,gBAAe;CACX,MAAM;CACN,QAAQ,UACJ,2BAA2B,OAAO;EAC9B,YAAY,QAAQ,MAAM,QAAQ,SAAS,iBAAiB;EAC5D,aAAa,QAAQ,MAAM,QAAQ,GAAG;CAC1C,CAAC;AACT"}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { audit } from "files-sdk/audit";
|
|
2
|
+
import { cache } from "files-sdk/cache";
|
|
3
|
+
import { compression } from "files-sdk/compression";
|
|
4
|
+
import { contentType, detectContentType } from "files-sdk/content-type";
|
|
5
|
+
import { dedup } from "files-sdk/dedup";
|
|
6
|
+
import { encryption, generateEncryptionKey } from "files-sdk/encryption";
|
|
7
|
+
import { failover } from "files-sdk/failover";
|
|
8
|
+
import { signedUrlPolicy } from "files-sdk/signed-url-policy";
|
|
9
|
+
import { softDelete } from "files-sdk/soft-delete";
|
|
10
|
+
import { tiering } from "files-sdk/tiering";
|
|
11
|
+
import { tracing } from "files-sdk/tracing";
|
|
12
|
+
import { usage } from "files-sdk/usage";
|
|
13
|
+
import { ValidationError, validation } from "files-sdk/validation";
|
|
14
|
+
import { versioning } from "files-sdk/versioning";
|
|
15
|
+
import { zip } from "files-sdk/zip";
|
|
16
|
+
export type * from "files-sdk/audit";
|
|
17
|
+
export type * from "files-sdk/cache";
|
|
18
|
+
export type * from "files-sdk/compression";
|
|
19
|
+
export type * from "files-sdk/content-type";
|
|
20
|
+
export type * from "files-sdk/dedup";
|
|
21
|
+
export type * from "files-sdk/encryption";
|
|
22
|
+
export type * from "files-sdk/failover";
|
|
23
|
+
export type * from "files-sdk/signed-url-policy";
|
|
24
|
+
export type * from "files-sdk/soft-delete";
|
|
25
|
+
export type * from "files-sdk/tiering";
|
|
26
|
+
export type * from "files-sdk/tracing";
|
|
27
|
+
export type * from "files-sdk/usage";
|
|
28
|
+
export type * from "files-sdk/validation";
|
|
29
|
+
export type * from "files-sdk/versioning";
|
|
30
|
+
export type * from "files-sdk/zip";
|
|
31
|
+
export { ValidationError, audit, cache, compression, contentType, dedup, detectContentType, encryption, failover, generateEncryptionKey, signedUrlPolicy, softDelete, tiering, tracing, usage, validation, versioning, zip };
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { audit } from "files-sdk/audit";
|
|
2
|
+
import { cache } from "files-sdk/cache";
|
|
3
|
+
import { compression } from "files-sdk/compression";
|
|
4
|
+
import { contentType, detectContentType } from "files-sdk/content-type";
|
|
5
|
+
import { dedup } from "files-sdk/dedup";
|
|
6
|
+
import { encryption, generateEncryptionKey } from "files-sdk/encryption";
|
|
7
|
+
import { failover } from "files-sdk/failover";
|
|
8
|
+
import { signedUrlPolicy } from "files-sdk/signed-url-policy";
|
|
9
|
+
import { softDelete } from "files-sdk/soft-delete";
|
|
10
|
+
import { tiering } from "files-sdk/tiering";
|
|
11
|
+
import { tracing } from "files-sdk/tracing";
|
|
12
|
+
import { usage } from "files-sdk/usage";
|
|
13
|
+
import { ValidationError, validation } from "files-sdk/validation";
|
|
14
|
+
import { versioning } from "files-sdk/versioning";
|
|
15
|
+
import { zip } from "files-sdk/zip";
|
|
16
|
+
export { ValidationError, audit, cache, compression, contentType, dedup, detectContentType, encryption, failover, generateEncryptionKey, signedUrlPolicy, softDelete, tiering, tracing, usage, validation, versioning, zip };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FilesConfig, StorageConfig } from "../config.js";
|
|
2
|
+
import { FilesDevtoolsSnapshot } from "../devtools/snapshot.js";
|
|
3
|
+
import { ExtensionsOf, Files, FilesActionEvent, FilesErrorEvent, FilesRetryEvent, ProviderSlug } from "files-sdk";
|
|
4
|
+
//#region src/runtime/registry.d.ts
|
|
5
|
+
export type FilesForStorage<T extends StorageConfig> = Files & ExtensionsOf<NonNullable<T['plugins']>>;
|
|
6
|
+
export type StorageRegistry<C extends FilesConfig> = { [Name in keyof C['storage']]: FilesForStorage<C['storage'][Name]>; };
|
|
7
|
+
type IsUnion<T, C = T> = T extends C ? ([C] extends [T] ? false : true) : never;
|
|
8
|
+
export type DefaultStorageName<C extends FilesConfig> = C extends {
|
|
9
|
+
default: infer Name extends Extract<keyof C['storage'], string>;
|
|
10
|
+
} ? Name : 'default' extends keyof C['storage'] ? 'default' : IsUnion<Extract<keyof C['storage'], string>> extends false ? Extract<keyof C['storage'], string> : never;
|
|
11
|
+
export type DefaultStorage<C extends FilesConfig> = StorageRegistry<C>[DefaultStorageName<C>];
|
|
12
|
+
export interface FilesRuntimeHooks {
|
|
13
|
+
onError?: (event: FilesErrorEvent, storage: string) => void | Promise<void>;
|
|
14
|
+
onAction?: (event: FilesActionEvent, storage: string) => void | Promise<void>;
|
|
15
|
+
onRetry?: (event: FilesRetryEvent, storage: string) => void | Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class FilesRegistry<const C extends FilesConfig = FilesConfig> {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(config: C, options?: {
|
|
20
|
+
development?: boolean;
|
|
21
|
+
hooks?: FilesRuntimeHooks;
|
|
22
|
+
});
|
|
23
|
+
get<Name extends keyof C['storage'] & string>(name?: Name): Promise<StorageRegistry<C>[Name]>;
|
|
24
|
+
inspect(): FilesDevtoolsSnapshot;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createFiles } from "files-sdk";
|
|
2
|
+
import { loadFiles } from "files-sdk/loader";
|
|
3
|
+
import { getProvider, listEnvVars } from "files-sdk/providers";
|
|
4
|
+
//#region src/runtime/registry.ts
|
|
5
|
+
const runHooks = async (...hooks) => {
|
|
6
|
+
for (const hook of hooks) try {
|
|
7
|
+
await hook();
|
|
8
|
+
} catch {}
|
|
9
|
+
};
|
|
10
|
+
var FilesRegistry = class {
|
|
11
|
+
#config;
|
|
12
|
+
#development;
|
|
13
|
+
#hooks;
|
|
14
|
+
#instances = /* @__PURE__ */ new Map();
|
|
15
|
+
constructor(config, options = {}) {
|
|
16
|
+
if (!config.storage || Object.keys(config.storage).length === 0) throw new Error("[nuxt-files-sdk:invalid-config] At least one storage is required.");
|
|
17
|
+
this.#config = config;
|
|
18
|
+
this.#development = options.development ?? false;
|
|
19
|
+
this.#hooks = options.hooks ?? {};
|
|
20
|
+
}
|
|
21
|
+
get(name) {
|
|
22
|
+
const resolvedName = name ?? this.#defaultName();
|
|
23
|
+
if (!Object.hasOwn(this.#config.storage, resolvedName)) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${resolvedName}".`);
|
|
24
|
+
let instance = this.#instances.get(resolvedName);
|
|
25
|
+
if (!instance) {
|
|
26
|
+
instance = this.#create(resolvedName);
|
|
27
|
+
this.#instances.set(resolvedName, instance);
|
|
28
|
+
instance.catch(() => this.#instances.delete(resolvedName));
|
|
29
|
+
}
|
|
30
|
+
return instance;
|
|
31
|
+
}
|
|
32
|
+
inspect() {
|
|
33
|
+
return {
|
|
34
|
+
storages: Object.entries(this.#config.storage).map(([name, storage]) => {
|
|
35
|
+
const override = this.#development ? this.#config.devStorage?.[name] : void 0;
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
adapter: override?.adapter ?? storage.adapter,
|
|
39
|
+
plugins: storage.plugins?.map((plugin) => plugin.name) ?? [],
|
|
40
|
+
source: override ? "devStorage" : "storage",
|
|
41
|
+
initialized: this.#instances.has(name)
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
diagnostics: []
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
#defaultName() {
|
|
48
|
+
if (this.#config.default) return this.#config.default;
|
|
49
|
+
const names = Object.keys(this.#config.storage);
|
|
50
|
+
if (names.length === 1 && names[0]) return names[0];
|
|
51
|
+
if (Object.hasOwn(this.#config.storage, "default")) return "default";
|
|
52
|
+
throw new Error("[nuxt-files-sdk:storage-name-required] A storage name is required.");
|
|
53
|
+
}
|
|
54
|
+
async #create(name) {
|
|
55
|
+
const base = this.#config.storage[name];
|
|
56
|
+
const override = this.#development ? this.#config.devStorage?.[name] : void 0;
|
|
57
|
+
const selected = override ? {
|
|
58
|
+
...base,
|
|
59
|
+
...override,
|
|
60
|
+
plugins: base?.plugins,
|
|
61
|
+
hooks: base?.hooks
|
|
62
|
+
} : base;
|
|
63
|
+
if (!selected) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${name}".`);
|
|
64
|
+
const { adapter, plugins, hooks: userHooks, ...options } = selected;
|
|
65
|
+
const loaded = await withNuxtEnvironment(adapter, () => loadFiles({
|
|
66
|
+
...options,
|
|
67
|
+
provider: adapter
|
|
68
|
+
}));
|
|
69
|
+
if (!plugins && !userHooks && !Object.values(this.#hooks).some(Boolean)) return loaded.files;
|
|
70
|
+
return createFiles({
|
|
71
|
+
adapter: loaded.files.adapter,
|
|
72
|
+
hooks: {
|
|
73
|
+
onAction: (event) => runHooks(() => userHooks?.onAction?.(event), () => this.#hooks.onAction?.(event, name)),
|
|
74
|
+
onError: (event) => runHooks(() => userHooks?.onError?.(event), () => this.#hooks.onError?.(event, name)),
|
|
75
|
+
onRetry: (event) => runHooks(() => userHooks?.onRetry?.(event), () => this.#hooks.onRetry?.(event, name))
|
|
76
|
+
},
|
|
77
|
+
...plugins ? { plugins } : {},
|
|
78
|
+
...options.prefix === void 0 ? {} : { prefix: options.prefix },
|
|
79
|
+
...options.retries === void 0 ? {} : { retries: options.retries },
|
|
80
|
+
...options.timeout === void 0 ? {} : { timeout: options.timeout }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let environmentLock = Promise.resolve();
|
|
85
|
+
/** Bridge only NUXT_ aliases declared by the configured native provider. */
|
|
86
|
+
const withNuxtEnvironment = async (provider, load) => {
|
|
87
|
+
if (!getProvider(provider)) return load();
|
|
88
|
+
const variables = listEnvVars(provider);
|
|
89
|
+
if (variables.length === 0) return load();
|
|
90
|
+
const previous = environmentLock;
|
|
91
|
+
let release;
|
|
92
|
+
environmentLock = new Promise((resolveLock) => release = resolveLock);
|
|
93
|
+
await previous;
|
|
94
|
+
const injected = [];
|
|
95
|
+
for (const variable of variables) {
|
|
96
|
+
const keys = [variable.key, ...variable.aliases ?? []];
|
|
97
|
+
if (keys.some((key) => process.env[key] !== void 0)) continue;
|
|
98
|
+
for (const key of keys) {
|
|
99
|
+
const value = process.env[`NUXT_${key}`];
|
|
100
|
+
if (value !== void 0 && process.env[key] === void 0) {
|
|
101
|
+
process.env[key] = value;
|
|
102
|
+
injected.push(key);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
return await load();
|
|
108
|
+
} finally {
|
|
109
|
+
for (const key of injected) delete process.env[key];
|
|
110
|
+
release();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
export { FilesRegistry, withNuxtEnvironment };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/runtime/registry.ts"],"sourcesContent":["import {\n createFiles,\n type ExtensionsOf,\n type Files,\n type FilesActionEvent,\n type FilesErrorEvent,\n type FilesRetryEvent,\n type ProviderSlug,\n} from 'files-sdk'\nimport { loadFiles } from 'files-sdk/loader'\nimport { getProvider, listEnvVars } from 'files-sdk/providers'\n\nimport type { FilesConfig, StorageConfig } from '../config'\nimport type { FilesDevtoolsSnapshot } from '../devtools/snapshot'\n\nexport type FilesForStorage<T extends StorageConfig> = Files & ExtensionsOf<NonNullable<T['plugins']>>\n\nexport type StorageRegistry<C extends FilesConfig> = {\n [Name in keyof C['storage']]: FilesForStorage<C['storage'][Name]>\n}\n\ntype IsUnion<T, C = T> = T extends C ? ([C] extends [T] ? false : true) : never\n\nexport type DefaultStorageName<C extends FilesConfig> = C extends {\n default: infer Name extends Extract<keyof C['storage'], string>\n}\n ? Name\n : 'default' extends keyof C['storage']\n ? 'default'\n : IsUnion<Extract<keyof C['storage'], string>> extends false\n ? Extract<keyof C['storage'], string>\n : never\n\nexport type DefaultStorage<C extends FilesConfig> = StorageRegistry<C>[DefaultStorageName<C>]\n\nexport interface FilesRuntimeHooks {\n onError?: (event: FilesErrorEvent, storage: string) => void | Promise<void>\n onAction?: (event: FilesActionEvent, storage: string) => void | Promise<void>\n onRetry?: (event: FilesRetryEvent, storage: string) => void | Promise<void>\n}\n\nconst runHooks = async (...hooks: (() => void | Promise<void> | undefined)[]): Promise<void> => {\n for (const hook of hooks) {\n try {\n // Preserve user-before-bridge ordering without exposing hook failures to native operations.\n // oxlint-disable-next-line no-await-in-loop\n await hook()\n } catch {}\n }\n}\n\nexport class FilesRegistry<const C extends FilesConfig = FilesConfig> {\n readonly #config: C\n readonly #development: boolean\n readonly #hooks: FilesRuntimeHooks\n readonly #instances = new Map<string, Promise<Files>>()\n\n constructor(config: C, options: { development?: boolean; hooks?: FilesRuntimeHooks } = {}) {\n if (!config.storage || Object.keys(config.storage).length === 0) {\n throw new Error('[nuxt-files-sdk:invalid-config] At least one storage is required.')\n }\n this.#config = config\n this.#development = options.development ?? false\n this.#hooks = options.hooks ?? {}\n }\n\n get<Name extends keyof C['storage'] & string>(name?: Name): Promise<StorageRegistry<C>[Name]> {\n const resolvedName = name ?? this.#defaultName()\n if (!Object.hasOwn(this.#config.storage, resolvedName)) {\n throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${resolvedName}\".`)\n }\n let instance = this.#instances.get(resolvedName)\n if (!instance) {\n instance = this.#create(resolvedName)\n this.#instances.set(resolvedName, instance)\n void instance.catch(() => this.#instances.delete(resolvedName))\n }\n // The instance is created from the same named config; the loader cannot express that link.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return instance as Promise<StorageRegistry<C>[Name]>\n }\n\n inspect(): FilesDevtoolsSnapshot {\n return {\n storages: Object.entries(this.#config.storage).map(([name, storage]) => {\n const override = this.#development ? this.#config.devStorage?.[name] : undefined\n return {\n name,\n adapter: override?.adapter ?? storage.adapter,\n plugins: storage.plugins?.map((plugin) => plugin.name) ?? [],\n source: override ? 'devStorage' : 'storage',\n initialized: this.#instances.has(name),\n }\n }),\n diagnostics: [],\n }\n }\n\n #defaultName(): string {\n if (this.#config.default) return this.#config.default\n const names = Object.keys(this.#config.storage)\n if (names.length === 1 && names[0]) return names[0]\n if (Object.hasOwn(this.#config.storage, 'default')) return 'default'\n throw new Error('[nuxt-files-sdk:storage-name-required] A storage name is required.')\n }\n\n async #create(name: string): Promise<Files> {\n const base = this.#config.storage[name]\n const override = this.#development ? this.#config.devStorage?.[name] : undefined\n const selected = override ? { ...base, ...override, plugins: base?.plugins, hooks: base?.hooks } : base\n if (!selected) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n const { adapter, plugins, hooks: userHooks, ...options } = selected\n const loaded = await withNuxtEnvironment(adapter, () => loadFiles({ ...options, provider: adapter }))\n // The upstream loader has no hooks/plugins input. Avoid rebuilding the\n // native instance unless those native capabilities are actually used.\n if (!plugins && !userHooks && !Object.values(this.#hooks).some(Boolean)) return loaded.files\n return createFiles({\n adapter: loaded.files.adapter,\n hooks: {\n onAction: (event) =>\n runHooks(\n () => userHooks?.onAction?.(event),\n () => this.#hooks.onAction?.(event, name),\n ),\n onError: (event) =>\n runHooks(\n () => userHooks?.onError?.(event),\n () => this.#hooks.onError?.(event, name),\n ),\n onRetry: (event) =>\n runHooks(\n () => userHooks?.onRetry?.(event),\n () => this.#hooks.onRetry?.(event, name),\n ),\n },\n ...(plugins ? { plugins } : {}),\n ...(options.prefix === undefined ? {} : { prefix: options.prefix }),\n ...(options.retries === undefined ? {} : { retries: options.retries }),\n ...(options.timeout === undefined ? {} : { timeout: options.timeout }),\n })\n }\n}\n\nlet environmentLock = Promise.resolve()\n\n/** Bridge only NUXT_ aliases declared by the configured native provider. */\nexport const withNuxtEnvironment = async <T>(provider: ProviderSlug, load: () => Promise<T>): Promise<T> => {\n const metadata = getProvider(provider)\n if (!metadata) return load()\n const variables = listEnvVars(provider)\n if (variables.length === 0) return load()\n // ponytail: module-local env lock; use native env keys to avoid temporary aliases.\n const previous = environmentLock\n let release!: () => void\n environmentLock = new Promise<void>((resolveLock) => (release = resolveLock))\n await previous\n const injected: string[] = []\n for (const variable of variables) {\n const keys = [variable.key, ...(variable.aliases ?? [])]\n if (keys.some((key) => process.env[key] !== undefined)) continue\n for (const key of keys) {\n const value = process.env[`NUXT_${key}`]\n if (value !== undefined && process.env[key] === undefined) {\n process.env[key] = value\n injected.push(key)\n }\n }\n }\n try {\n return await load()\n } finally {\n for (const key of injected) delete process.env[key]\n release()\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FilesConfig } from "./config.js";
|
|
2
|
+
import { FilesDevtoolsSnapshot } from "./devtools/snapshot.js";
|
|
3
|
+
import { DefaultStorage, DefaultStorageName, FilesForStorage, FilesRegistry, FilesRuntimeHooks, StorageRegistry } from "./runtime/registry.js";
|
|
4
|
+
import { Files } from "files-sdk";
|
|
5
|
+
//#region src/runtime.d.ts
|
|
6
|
+
/** Project storage names are merged into this interface by the generated declaration. */
|
|
7
|
+
export interface NuxtFilesStorageRegistry {}
|
|
8
|
+
/** Generated from the project's default-storage selection. */
|
|
9
|
+
export interface NuxtFilesDefaultStorage {}
|
|
10
|
+
export declare const configureFiles: <const C extends FilesConfig>(config: C, options?: ConstructorParameters<typeof FilesRegistry<C>>[1]) => FilesRegistry<C>;
|
|
11
|
+
export declare const inspectFiles: () => FilesDevtoolsSnapshot;
|
|
12
|
+
export declare function useServerFiles(): Promise<NuxtFilesDefaultStorage extends {
|
|
13
|
+
value: infer Default;
|
|
14
|
+
} ? Default : Files>;
|
|
15
|
+
export declare function useServerFiles<Name extends Extract<keyof NuxtFilesStorageRegistry, string>>(name: Name): Promise<NuxtFilesStorageRegistry[Name]>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type DefaultStorage, type DefaultStorageName, type FilesForStorage, FilesRegistry, type FilesRuntimeHooks, type StorageRegistry };
|
|
18
|
+
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FilesRegistry } from "./runtime/registry.js";
|
|
2
|
+
//#region src/runtime.ts
|
|
3
|
+
let registry;
|
|
4
|
+
const configureFiles = (config, options) => {
|
|
5
|
+
const value = new FilesRegistry(config, options);
|
|
6
|
+
registry = value;
|
|
7
|
+
return value;
|
|
8
|
+
};
|
|
9
|
+
const inspectFiles = () => registry?.inspect() ?? {
|
|
10
|
+
storages: [],
|
|
11
|
+
diagnostics: [{
|
|
12
|
+
code: "NUXT_FILES_NOT_CONFIGURED",
|
|
13
|
+
level: "warning",
|
|
14
|
+
message: "The Files registry has not been configured."
|
|
15
|
+
}]
|
|
16
|
+
};
|
|
17
|
+
function useServerFiles(name) {
|
|
18
|
+
if (!registry) throw new Error("[nuxt-files-sdk:not-configured] The Files registry has not been configured.");
|
|
19
|
+
return registry.get(name);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { FilesRegistry, configureFiles, inspectFiles, useServerFiles };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import type { Files } from 'files-sdk'\n\nimport type { FilesConfig } from './config'\nimport type { FilesDevtoolsSnapshot } from './devtools/snapshot'\nimport { FilesRegistry } from './runtime/registry'\n\nexport { FilesRegistry } from './runtime/registry'\nexport type {\n DefaultStorage,\n DefaultStorageName,\n FilesForStorage,\n FilesRuntimeHooks,\n StorageRegistry,\n} from './runtime/registry'\n\n/** Project storage names are merged into this interface by the generated declaration. */\nexport interface NuxtFilesStorageRegistry {}\n/** Generated from the project's default-storage selection. */\nexport interface NuxtFilesDefaultStorage {}\n\nlet registry: FilesRegistry | undefined\n\nexport const configureFiles = <const C extends FilesConfig>(\n config: C,\n options?: ConstructorParameters<typeof FilesRegistry<C>>[1],\n): FilesRegistry<C> => {\n const value = new FilesRegistry(config, options)\n registry = value\n return value\n}\n\nexport const inspectFiles = (): FilesDevtoolsSnapshot =>\n registry?.inspect() ?? {\n storages: [],\n diagnostics: [\n {\n code: 'NUXT_FILES_NOT_CONFIGURED',\n level: 'warning',\n message: 'The Files registry has not been configured.',\n },\n ],\n }\n\nexport function useServerFiles(): Promise<NuxtFilesDefaultStorage extends { value: infer Default } ? Default : Files>\nexport function useServerFiles<Name extends Extract<keyof NuxtFilesStorageRegistry, string>>(\n name: Name,\n): Promise<NuxtFilesStorageRegistry[Name]>\nexport function useServerFiles(name?: string): Promise<Files> {\n if (!registry) {\n throw new Error('[nuxt-files-sdk:not-configured] The Files registry has not been configured.')\n }\n return registry.get(name)\n}\n"],"mappings":";;AAoBA,IAAI;AAEJ,MAAa,kBACT,QACA,YACmB;CACnB,MAAM,QAAQ,IAAI,cAAc,QAAQ,OAAO;CAC/C,WAAW;CACX,OAAO;AACX;AAEA,MAAa,qBACT,UAAU,QAAQ,KAAK;CACnB,UAAU,CAAC;CACX,aAAa,CACT;EACI,MAAM;EACN,OAAO;EACP,SAAS;CACb,CACJ;AACJ;AAMJ,SAAgB,eAAe,MAA+B;CAC1D,IAAI,CAAC,UACD,MAAM,IAAI,MAAM,6EAA6E;CAEjG,OAAO,SAAS,IAAI,IAAI;AAC5B"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,73 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
"name": "nuxt-files-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Native-first Files SDK integration for Nuxt and Nitro",
|
|
5
|
+
"homepage": "https://github.com/liria24/nuxt-files-sdk#readme",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/liria24/nuxt-files-sdk.git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"main": "./dist/module.js",
|
|
17
|
+
"types": "./dist/module.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/module.d.ts",
|
|
21
|
+
"import": "./dist/module.js"
|
|
22
|
+
},
|
|
23
|
+
"./config": {
|
|
24
|
+
"types": "./dist/config.d.ts",
|
|
25
|
+
"import": "./dist/config.js"
|
|
26
|
+
},
|
|
27
|
+
"./nitro": {
|
|
28
|
+
"types": "./dist/nitro.d.ts",
|
|
29
|
+
"import": "./dist/nitro.js"
|
|
30
|
+
},
|
|
31
|
+
"./plugins": {
|
|
32
|
+
"types": "./dist/plugins.d.ts",
|
|
33
|
+
"import": "./dist/plugins.js"
|
|
34
|
+
},
|
|
35
|
+
"./runtime": {
|
|
36
|
+
"types": "./dist/runtime.d.ts",
|
|
37
|
+
"import": "./dist/runtime.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"dev": "tsdown --watch",
|
|
48
|
+
"prepack": "bun run build",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@nuxt/kit": "^4.5.2",
|
|
53
|
+
"devframe": "^0.9.12",
|
|
54
|
+
"files-sdk": "^2.3.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
58
|
+
"@nuxt/schema": "^4.5.2",
|
|
59
|
+
"@types/node": "^26.4.1",
|
|
60
|
+
"publint": "^0.3.24",
|
|
61
|
+
"tsdown": "^0.23.0",
|
|
62
|
+
"typescript": "^7.0.2",
|
|
63
|
+
"vue": "^3.5.42"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"nuxt": "^4.0.0 || ^5.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"nuxt": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
}
|
|
15
73
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|