nuxt-files-sdk 0.0.1 → 0.0.2
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.d.ts +13 -7
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/integration/nitro.d.ts +8 -0
- package/dist/integration/nitro.js +4 -0
- package/dist/integration/nitro.js.map +1 -1
- package/dist/module.d.ts +4 -2
- package/dist/module.js +1 -0
- package/dist/module.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/runtime/registry.d.ts +17 -1
- package/dist/runtime/registry.js +7 -1
- package/dist/runtime/registry.js.map +1 -1
- package/dist/runtime.d.ts +6 -2
- package/dist/runtime.js +3 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +3 -3
package/dist/config.d.ts
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import { FilesHooks, FilesPlugin, ProviderSlug } from "files-sdk";
|
|
2
2
|
import { LoadFilesOptions } from "files-sdk/loader";
|
|
3
3
|
//#region src/config.d.ts
|
|
4
|
+
/** Configuration for one named Files SDK storage. */
|
|
4
5
|
export type StorageConfig<Plugins extends readonly FilesPlugin[] = readonly FilesPlugin[]> = Omit<LoadFilesOptions, 'provider'> & {
|
|
5
|
-
/** Files SDK provider
|
|
6
|
+
/** Files SDK provider slug, for example `r2`, `s3`, or `fs`. */
|
|
6
7
|
adapter: ProviderSlug;
|
|
7
|
-
/** Native Files SDK plugins
|
|
8
|
+
/** Native Files SDK plugins applied in array order. Their extensions are reflected in the storage type. */
|
|
8
9
|
plugins?: Plugins;
|
|
9
|
-
/** Native Files SDK hooks. They run before the integration
|
|
10
|
+
/** Native Files SDK lifecycle hooks. They run before the Nuxt/Nitro integration hooks. */
|
|
10
11
|
hooks?: FilesHooks;
|
|
11
12
|
};
|
|
13
|
+
/** Development-only connection settings for a storage declared in {@link FilesConfig.storage}. */
|
|
12
14
|
export type DevStorageConfig = Omit<StorageConfig, 'plugins' | 'hooks'> & {
|
|
13
15
|
/** Plugins belong to the logical storage and cannot be replaced in development. */
|
|
14
16
|
plugins?: never;
|
|
15
17
|
/** Hooks belong to the logical storage and cannot be replaced in development. */
|
|
16
18
|
hooks?: never;
|
|
17
19
|
};
|
|
20
|
+
/** Files SDK storages and development overrides used by the Nuxt/Nitro integration. */
|
|
18
21
|
export interface FilesConfig<Storage extends Record<string, StorageConfig> = Record<string, StorageConfig>> {
|
|
19
|
-
/** Storage used
|
|
22
|
+
/** Storage used by `useServerFiles()` and `FilesRegistry.get()` when no name is passed. */
|
|
20
23
|
default?: keyof Storage & string;
|
|
21
|
-
/**
|
|
24
|
+
/** Development-only connection overrides keyed by a name in {@link storage}; never used as failure fallbacks. */
|
|
22
25
|
devStorage?: Partial<{ [Name in keyof Storage]: DevStorageConfig; }>;
|
|
26
|
+
/** Named storages, each initialized lazily on first access. */
|
|
23
27
|
storage: Storage;
|
|
24
28
|
}
|
|
25
|
-
/**
|
|
26
|
-
export declare const defineFilesConfig: <const Config extends FilesConfig
|
|
29
|
+
/** Define a Files SDK configuration while preserving storage names and plugin tuples for generated types. */
|
|
30
|
+
export declare const defineFilesConfig: <const Storage extends Record<string, StorageConfig>, const Config extends FilesConfig<Storage>>(config: Config & FilesConfig<Storage> & {
|
|
31
|
+
storage: Storage;
|
|
32
|
+
}) => Config;
|
|
27
33
|
//#endregion
|
|
28
34
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/config.ts
|
|
2
|
-
/**
|
|
2
|
+
/** Define a Files SDK configuration while preserving storage names and plugin tuples for generated types. */
|
|
3
3
|
const defineFilesConfig = (config) => config;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { defineFilesConfig };
|
package/dist/config.js.map
CHANGED
|
@@ -1 +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
|
|
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\n/** Configuration for one named Files SDK storage. */\nexport type StorageConfig<Plugins extends readonly FilesPlugin[] = readonly FilesPlugin[]> = Omit<\n LoadFilesOptions,\n 'provider'\n> & {\n /** Files SDK provider slug, for example `r2`, `s3`, or `fs`. */\n adapter: ProviderSlug\n /** Native Files SDK plugins applied in array order. Their extensions are reflected in the storage type. */\n plugins?: Plugins\n /** Native Files SDK lifecycle hooks. They run before the Nuxt/Nitro integration hooks. */\n hooks?: FilesHooks\n}\n\n/** Development-only connection settings for a storage declared in {@link FilesConfig.storage}. */\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\n/** Files SDK storages and development overrides used by the Nuxt/Nitro integration. */\nexport interface FilesConfig<Storage extends Record<string, StorageConfig> = Record<string, StorageConfig>> {\n /** Storage used by `useServerFiles()` and `FilesRegistry.get()` when no name is passed. */\n default?: keyof Storage & string\n /** Development-only connection overrides keyed by a name in {@link storage}; never used as failure fallbacks. */\n devStorage?: Partial<{ [Name in keyof Storage]: DevStorageConfig }>\n /** Named storages, each initialized lazily on first access. */\n storage: Storage\n}\n\n/** Define a Files SDK configuration while preserving storage names and plugin tuples for generated types. */\nexport const defineFilesConfig = <\n const Storage extends Record<string, StorageConfig>,\n const Config extends FilesConfig<Storage>,\n>(\n config: Config & FilesConfig<Storage> & { storage: Storage },\n): Config => config\n"],"mappings":";;AAmCA,MAAa,qBAIT,WACS"}
|
|
@@ -12,6 +12,14 @@ export interface NitroIntegration {
|
|
|
12
12
|
inline?: unknown[];
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
unimport?: {
|
|
16
|
+
getInternalContext(): {
|
|
17
|
+
addons: {
|
|
18
|
+
name?: string;
|
|
19
|
+
declaration?: (declarations: string) => string;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
15
23
|
hooks: {
|
|
16
24
|
hook(name: 'types:extend', callback: (types: {
|
|
17
25
|
tsConfig?: {
|
|
@@ -22,6 +22,10 @@ export {}
|
|
|
22
22
|
`;
|
|
23
23
|
const setupNitroFilesIntegration = async (nitro, options) => {
|
|
24
24
|
const configPath = options.configPath.replaceAll("\\", "/");
|
|
25
|
+
nitro.unimport?.getInternalContext().addons.push({
|
|
26
|
+
name: "nuxt-files-sdk-jsdoc",
|
|
27
|
+
declaration: (declarations) => declarations.replace(/^(\s*)(const useServerFiles: typeof .*\.useServerFiles)$/mu, "$1/** Return the project's default Files client, including its configured plugin extensions. */\n$1$2")
|
|
28
|
+
});
|
|
25
29
|
const externals = nitro.options.externals ??= {};
|
|
26
30
|
(externals.inline ??= []).push("nuxt-files-sdk");
|
|
27
31
|
if (!nitro.options.dev) externals.inline.push("files-sdk");
|
|
@@ -1 +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":";;;
|
|
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 unimport?: {\n getInternalContext(): {\n addons: {\n name?: string\n declaration?: (declarations: string) => string\n }[]\n }\n }\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 nitro.unimport?.getInternalContext().addons.push({\n name: 'nuxt-files-sdk-jsdoc',\n declaration: (declarations) =>\n declarations.replace(\n /^(\\s*)(const useServerFiles: typeof .*\\.useServerFiles)$/mu,\n \"$1/** Return the project's default Files client, including its configured plugin extensions. */\\n$1$2\",\n ),\n })\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)\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@ -8,12 +8,14 @@ declare module '@nuxt/schema' {
|
|
|
8
8
|
'nitro:init': (nitro: NitroIntegration) => void | Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
/** Options for the Nuxt Files SDK module. */
|
|
11
12
|
export interface ModuleOptions {
|
|
12
|
-
/** Files configuration
|
|
13
|
+
/** Path to the Files configuration module, relative to the Nuxt root directory. */
|
|
13
14
|
config: string;
|
|
14
|
-
/** Enable development diagnostics
|
|
15
|
+
/** Enable Files SDK development diagnostics when Nuxt DevTools is available. */
|
|
15
16
|
devtools: boolean;
|
|
16
17
|
}
|
|
18
|
+
/** Install Files SDK storage configuration, server utilities, Vue composables, and development diagnostics in Nuxt. */
|
|
17
19
|
declare const _default: import("@nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
18
20
|
//#endregion
|
|
19
21
|
export { type DefaultStorage, type DefaultStorageName, type FilesForStorage, FilesRegistry, type FilesRuntimeHooks, NuxtFilesDefaultStorage, NuxtFilesStorageRegistry, type StorageRegistry, configureFiles, _default as default, inspectFiles, useServerFiles };
|
package/dist/module.js
CHANGED
|
@@ -6,6 +6,7 @@ import { resolve } from "node:path";
|
|
|
6
6
|
import { addImports, addServerImports, defineNuxtModule, getNuxtModuleVersion } from "@nuxt/kit";
|
|
7
7
|
export * from "files-sdk";
|
|
8
8
|
//#region src/module.ts
|
|
9
|
+
/** Install Files SDK storage configuration, server utilities, Vue composables, and development diagnostics in Nuxt. */
|
|
9
10
|
var module_default = defineNuxtModule({
|
|
10
11
|
meta: {
|
|
11
12
|
name: "nuxt-files-sdk",
|
package/dist/module.js.map
CHANGED
|
@@ -1 +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
|
|
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\n/** Options for the Nuxt Files SDK module. */\nexport interface ModuleOptions {\n /** Path to the Files configuration module, relative to the Nuxt root directory. */\n config: string\n /** Enable Files SDK development diagnostics when Nuxt DevTools is available. */\n devtools: boolean\n}\n\n/** Install Files SDK storage configuration, server utilities, Vue composables, and development diagnostics in Nuxt. */\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":";;;;;;;;;AAuBA,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/package.js
CHANGED
|
@@ -2,25 +2,41 @@ import { FilesConfig, StorageConfig } from "../config.js";
|
|
|
2
2
|
import { FilesDevtoolsSnapshot } from "../devtools/snapshot.js";
|
|
3
3
|
import { ExtensionsOf, Files, FilesActionEvent, FilesErrorEvent, FilesRetryEvent, ProviderSlug } from "files-sdk";
|
|
4
4
|
//#region src/runtime/registry.d.ts
|
|
5
|
+
/** Native Files client plus the methods contributed by a storage's plugins. */
|
|
5
6
|
export type FilesForStorage<T extends StorageConfig> = Files & ExtensionsOf<NonNullable<T['plugins']>>;
|
|
7
|
+
/** Map each configured storage name to its native Files client and plugin extensions. */
|
|
6
8
|
export type StorageRegistry<C extends FilesConfig> = { [Name in keyof C['storage']]: FilesForStorage<C['storage'][Name]>; };
|
|
7
9
|
type IsUnion<T, C = T> = T extends C ? ([C] extends [T] ? false : true) : never;
|
|
10
|
+
/** Resolve the explicit, conventional, or only storage name used by an unnamed access. */
|
|
8
11
|
export type DefaultStorageName<C extends FilesConfig> = C extends {
|
|
9
12
|
default: infer Name extends Extract<keyof C['storage'], string>;
|
|
10
13
|
} ? Name : 'default' extends keyof C['storage'] ? 'default' : IsUnion<Extract<keyof C['storage'], string>> extends false ? Extract<keyof C['storage'], string> : never;
|
|
14
|
+
/** Files client and plugin extensions returned for a configuration's default storage. */
|
|
11
15
|
export type DefaultStorage<C extends FilesConfig> = StorageRegistry<C>[DefaultStorageName<C>];
|
|
16
|
+
/** Hooks emitted by the Nuxt/Nitro bridge after the storage's native hooks. */
|
|
12
17
|
export interface FilesRuntimeHooks {
|
|
18
|
+
/** Observe a failed native Files operation. */
|
|
13
19
|
onError?: (event: FilesErrorEvent, storage: string) => void | Promise<void>;
|
|
20
|
+
/** Observe a completed native Files operation. */
|
|
14
21
|
onAction?: (event: FilesActionEvent, storage: string) => void | Promise<void>;
|
|
22
|
+
/** Observe a native Files retry. */
|
|
15
23
|
onRetry?: (event: FilesRetryEvent, storage: string) => void | Promise<void>;
|
|
16
24
|
}
|
|
25
|
+
/** Lazily initialize and memoize native Files clients for a validated project configuration. */
|
|
17
26
|
export declare class FilesRegistry<const C extends FilesConfig = FilesConfig> {
|
|
18
27
|
#private;
|
|
28
|
+
/**
|
|
29
|
+
* Create a registry and validate storage references without initializing or connecting to a provider.
|
|
30
|
+
*/
|
|
19
31
|
constructor(config: C, options?: {
|
|
20
32
|
development?: boolean;
|
|
21
33
|
hooks?: FilesRuntimeHooks;
|
|
22
34
|
});
|
|
23
|
-
|
|
35
|
+
/** Return the default storage, sharing its in-flight initialization Promise. */
|
|
36
|
+
get(name?: undefined): Promise<DefaultStorage<C>>;
|
|
37
|
+
/** Return a named storage with its plugin extensions, sharing its in-flight initialization Promise. */
|
|
38
|
+
get<Name extends keyof C['storage'] & string>(name: Name): Promise<StorageRegistry<C>[Name]>;
|
|
39
|
+
/** Return secret-free storage metadata and initialization state for development diagnostics. */
|
|
24
40
|
inspect(): FilesDevtoolsSnapshot;
|
|
25
41
|
}
|
|
26
42
|
//#endregion
|
package/dist/runtime/registry.js
CHANGED
|
@@ -7,13 +7,18 @@ const runHooks = async (...hooks) => {
|
|
|
7
7
|
await hook();
|
|
8
8
|
} catch {}
|
|
9
9
|
};
|
|
10
|
+
/** Lazily initialize and memoize native Files clients for a validated project configuration. */
|
|
10
11
|
var FilesRegistry = class {
|
|
11
12
|
#config;
|
|
12
13
|
#development;
|
|
13
14
|
#hooks;
|
|
14
15
|
#instances = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Create a registry and validate storage references without initializing or connecting to a provider.
|
|
18
|
+
*/
|
|
15
19
|
constructor(config, options = {}) {
|
|
16
20
|
if (!config.storage || Object.keys(config.storage).length === 0) throw new Error("[nuxt-files-sdk:invalid-config] At least one storage is required.");
|
|
21
|
+
for (const name of [config.default, ...Object.keys(config.devStorage ?? {})]) if (name !== void 0 && !Object.hasOwn(config.storage, name)) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${name}".`);
|
|
17
22
|
this.#config = config;
|
|
18
23
|
this.#development = options.development ?? false;
|
|
19
24
|
this.#hooks = options.hooks ?? {};
|
|
@@ -29,6 +34,7 @@ var FilesRegistry = class {
|
|
|
29
34
|
}
|
|
30
35
|
return instance;
|
|
31
36
|
}
|
|
37
|
+
/** Return secret-free storage metadata and initialization state for development diagnostics. */
|
|
32
38
|
inspect() {
|
|
33
39
|
return {
|
|
34
40
|
storages: Object.entries(this.#config.storage).map(([name, storage]) => {
|
|
@@ -45,7 +51,7 @@ var FilesRegistry = class {
|
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
#defaultName() {
|
|
48
|
-
if (this.#config.default) return this.#config.default;
|
|
54
|
+
if (this.#config.default !== void 0) return this.#config.default;
|
|
49
55
|
const names = Object.keys(this.#config.storage);
|
|
50
56
|
if (names.length === 1 && names[0]) return names[0];
|
|
51
57
|
if (Object.hasOwn(this.#config.storage, "default")) return "default";
|
|
@@ -1 +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":";;;;AAyCA,MAAM,WAAW,OAAO,GAAG,UAAqE;CAC5F,KAAK,MAAM,QAAQ,OACf,IAAI;EAGA,MAAM,KAAK;CACf,QAAQ,CAAC;AAEjB;AAEA,IAAa,gBAAb,MAAsE;CAClE;CACA;CACA;CACA,6BAAsB,IAAI,IAA4B;CAEtD,YAAY,QAAW,UAAgE,CAAC,GAAG;EACvF,IAAI,CAAC,OAAO,WAAW,OAAO,KAAK,OAAO,OAAO,CAAC,CAAC,WAAW,GAC1D,MAAM,IAAI,MAAM,mEAAmE;EAEvF,KAAK,UAAU;EACf,KAAK,eAAe,QAAQ,eAAe;EAC3C,KAAK,SAAS,QAAQ,SAAS,CAAC;CACpC;CAEA,IAA8C,MAAgD;EAC1F,MAAM,eAAe,QAAQ,KAAK,aAAa;EAC/C,IAAI,CAAC,OAAO,OAAO,KAAK,QAAQ,SAAS,YAAY,GACjD,MAAM,IAAI,MAAM,qDAAqD,aAAa,GAAG;EAEzF,IAAI,WAAW,KAAK,WAAW,IAAI,YAAY;EAC/C,IAAI,CAAC,UAAU;GACX,WAAW,KAAK,QAAQ,YAAY;GACpC,KAAK,WAAW,IAAI,cAAc,QAAQ;GAC1C,SAAc,YAAY,KAAK,WAAW,OAAO,YAAY,CAAC;EAClE;EAGA,OAAO;CACX;CAEA,UAAiC;EAC7B,OAAO;GACH,UAAU,OAAO,QAAQ,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa;IACpE,MAAM,WAAW,KAAK,eAAe,KAAK,QAAQ,aAAa,QAAQ,KAAA;IACvE,OAAO;KACH;KACA,SAAS,UAAU,WAAW,QAAQ;KACtC,SAAS,QAAQ,SAAS,KAAK,WAAW,OAAO,IAAI,KAAK,C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ACR;GACA,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;GAC7B,GAAI,QAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;GACjE,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;GACpE,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;EACxE,CAAC;CACL;AACJ;AAEA,IAAI,kBAAkB,QAAQ,QAAQ;;AAGtC,MAAa,sBAAsB,OAAU,UAAwB,SAAuC;CAExG,IAAI,CADa,YAAY,QACjB,GAAG,OAAO,KAAK;CAC3B,MAAM,YAAY,YAAY,QAAQ;CACtC,IAAI,UAAU,WAAW,GAAG,OAAO,KAAK;CAExC,MAAM,WAAW;CACjB,IAAI;CACJ,kBAAkB,IAAI,SAAe,gBAAiB,UAAU,WAAY;CAC5E,MAAM;CACN,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,YAAY,WAAW;EAC9B,MAAM,OAAO,CAAC,SAAS,KAAK,GAAI,SAAS,WAAW,CAAC,CAAE;EACvD,IAAI,KAAK,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAA,CAAS,GAAG;EACxD,KAAK,MAAM,OAAO,MAAM;GACpB,MAAM,QAAQ,QAAQ,IAAI,QAAQ;GAClC,IAAI,UAAU,KAAA,KAAa,QAAQ,IAAI,SAAS,KAAA,GAAW;IACvD,QAAQ,IAAI,OAAO;IACnB,SAAS,KAAK,GAAG;GACrB;EACJ;CACJ;CACA,IAAI;EACA,OAAO,MAAM,KAAK;CACtB,UAAU;EACN,KAAK,MAAM,OAAO,UAAU,OAAO,QAAQ,IAAI;EAC/C,QAAQ;CACZ;AACJ"}
|
|
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\n/** Native Files client plus the methods contributed by a storage's plugins. */\nexport type FilesForStorage<T extends StorageConfig> = Files & ExtensionsOf<NonNullable<T['plugins']>>\n\n/** Map each configured storage name to its native Files client and plugin extensions. */\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\n/** Resolve the explicit, conventional, or only storage name used by an unnamed access. */\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\n/** Files client and plugin extensions returned for a configuration's default storage. */\nexport type DefaultStorage<C extends FilesConfig> = StorageRegistry<C>[DefaultStorageName<C>]\n\n/** Hooks emitted by the Nuxt/Nitro bridge after the storage's native hooks. */\nexport interface FilesRuntimeHooks {\n /** Observe a failed native Files operation. */\n onError?: (event: FilesErrorEvent, storage: string) => void | Promise<void>\n /** Observe a completed native Files operation. */\n onAction?: (event: FilesActionEvent, storage: string) => void | Promise<void>\n /** Observe a native Files retry. */\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\n/** Lazily initialize and memoize native Files clients for a validated project configuration. */\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 /**\n * Create a registry and validate storage references without initializing or connecting to a provider.\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 for (const name of [config.default, ...Object.keys(config.devStorage ?? {})]) {\n if (name !== undefined && !Object.hasOwn(config.storage, name)) {\n throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n }\n }\n this.#config = config\n this.#development = options.development ?? false\n this.#hooks = options.hooks ?? {}\n }\n\n /** Return the default storage, sharing its in-flight initialization Promise. */\n get(name?: undefined): Promise<DefaultStorage<C>>\n /** Return a named storage with its plugin extensions, sharing its in-flight initialization Promise. */\n get<Name extends keyof C['storage'] & string>(name: Name): Promise<StorageRegistry<C>[Name]>\n get(name?: string): Promise<Files> {\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 return instance\n }\n\n /** Return secret-free storage metadata and initialization state for development diagnostics. */\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 !== undefined) 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":";;;;AAiDA,MAAM,WAAW,OAAO,GAAG,UAAqE;CAC5F,KAAK,MAAM,QAAQ,OACf,IAAI;EAGA,MAAM,KAAK;CACf,QAAQ,CAAC;AAEjB;;AAGA,IAAa,gBAAb,MAAsE;CAClE;CACA;CACA;CACA,6BAAsB,IAAI,IAA4B;;;;CAKtD,YAAY,QAAW,UAAgE,CAAC,GAAG;EACvF,IAAI,CAAC,OAAO,WAAW,OAAO,KAAK,OAAO,OAAO,CAAC,CAAC,WAAW,GAC1D,MAAM,IAAI,MAAM,mEAAmE;EAEvF,KAAK,MAAM,QAAQ,CAAC,OAAO,SAAS,GAAG,OAAO,KAAK,OAAO,cAAc,CAAC,CAAC,CAAC,GACvE,IAAI,SAAS,KAAA,KAAa,CAAC,OAAO,OAAO,OAAO,SAAS,IAAI,GACzD,MAAM,IAAI,MAAM,qDAAqD,KAAK,GAAG;EAGrF,KAAK,UAAU;EACf,KAAK,eAAe,QAAQ,eAAe;EAC3C,KAAK,SAAS,QAAQ,SAAS,CAAC;CACpC;CAMA,IAAI,MAA+B;EAC/B,MAAM,eAAe,QAAQ,KAAK,aAAa;EAC/C,IAAI,CAAC,OAAO,OAAO,KAAK,QAAQ,SAAS,YAAY,GACjD,MAAM,IAAI,MAAM,qDAAqD,aAAa,GAAG;EAEzF,IAAI,WAAW,KAAK,WAAW,IAAI,YAAY;EAC/C,IAAI,CAAC,UAAU;GACX,WAAW,KAAK,QAAQ,YAAY;GACpC,KAAK,WAAW,IAAI,cAAc,QAAQ;GAC1C,SAAc,YAAY,KAAK,WAAW,OAAO,YAAY,CAAC;EAClE;EACA,OAAO;CACX;;CAGA,UAAiC;EAC7B,OAAO;GACH,UAA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AAI;EACA,OAAO,MAAM,KAAK;CACtB,UAAU;EACN,KAAK,MAAM,OAAO,UAAU,OAAO,QAAQ,IAAI;EAC/C,QAAQ;CACZ;AACJ"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -3,15 +3,19 @@ import { FilesDevtoolsSnapshot } from "./devtools/snapshot.js";
|
|
|
3
3
|
import { DefaultStorage, DefaultStorageName, FilesForStorage, FilesRegistry, FilesRuntimeHooks, StorageRegistry } from "./runtime/registry.js";
|
|
4
4
|
import { Files } from "files-sdk";
|
|
5
5
|
//#region src/runtime.d.ts
|
|
6
|
-
/** Project storage names
|
|
6
|
+
/** Project storage names and plugin-extended Files clients supplied by generated declarations. */
|
|
7
7
|
export interface NuxtFilesStorageRegistry {}
|
|
8
|
-
/**
|
|
8
|
+
/** Project default Files client supplied by generated declarations. */
|
|
9
9
|
export interface NuxtFilesDefaultStorage {}
|
|
10
|
+
/** Configure the process-local Files registry used by {@link useServerFiles}. */
|
|
10
11
|
export declare const configureFiles: <const C extends FilesConfig>(config: C, options?: ConstructorParameters<typeof FilesRegistry<C>>[1]) => FilesRegistry<C>;
|
|
12
|
+
/** Return secret-free diagnostics for the configured process-local Files registry. */
|
|
11
13
|
export declare const inspectFiles: () => FilesDevtoolsSnapshot;
|
|
14
|
+
/** Return the project's default Files client, including its configured plugin extensions. */
|
|
12
15
|
export declare function useServerFiles(): Promise<NuxtFilesDefaultStorage extends {
|
|
13
16
|
value: infer Default;
|
|
14
17
|
} ? Default : Files>;
|
|
18
|
+
/** Return a named project Files client, including that storage's configured plugin extensions. */
|
|
15
19
|
export declare function useServerFiles<Name extends Extract<keyof NuxtFilesStorageRegistry, string>>(name: Name): Promise<NuxtFilesStorageRegistry[Name]>;
|
|
16
20
|
//#endregion
|
|
17
21
|
export { type DefaultStorage, type DefaultStorageName, type FilesForStorage, FilesRegistry, type FilesRuntimeHooks, type StorageRegistry };
|
package/dist/runtime.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { FilesRegistry } from "./runtime/registry.js";
|
|
2
2
|
//#region src/runtime.ts
|
|
3
3
|
let registry;
|
|
4
|
+
/** Configure the process-local Files registry used by {@link useServerFiles}. */
|
|
4
5
|
const configureFiles = (config, options) => {
|
|
5
6
|
const value = new FilesRegistry(config, options);
|
|
6
7
|
registry = value;
|
|
7
8
|
return value;
|
|
8
9
|
};
|
|
10
|
+
/** Return secret-free diagnostics for the configured process-local Files registry. */
|
|
9
11
|
const inspectFiles = () => registry?.inspect() ?? {
|
|
10
12
|
storages: [],
|
|
11
13
|
diagnostics: [{
|
|
@@ -16,7 +18,7 @@ const inspectFiles = () => registry?.inspect() ?? {
|
|
|
16
18
|
};
|
|
17
19
|
function useServerFiles(name) {
|
|
18
20
|
if (!registry) throw new Error("[nuxt-files-sdk:not-configured] The Files registry has not been configured.");
|
|
19
|
-
return registry.get(name);
|
|
21
|
+
return name === void 0 ? registry.get() : registry.get(name);
|
|
20
22
|
}
|
|
21
23
|
//#endregion
|
|
22
24
|
export { FilesRegistry, configureFiles, inspectFiles, useServerFiles };
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +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
|
|
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 and plugin-extended Files clients supplied by generated declarations. */\nexport interface NuxtFilesStorageRegistry {}\n/** Project default Files client supplied by generated declarations. */\nexport interface NuxtFilesDefaultStorage {}\n\nlet registry: FilesRegistry | undefined\n\n/** Configure the process-local Files registry used by {@link useServerFiles}. */\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\n/** Return secret-free diagnostics for the configured process-local Files registry. */\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\n/** Return the project's default Files client, including its configured plugin extensions. */\nexport function useServerFiles(): Promise<NuxtFilesDefaultStorage extends { value: infer Default } ? Default : Files>\n/** Return a named project Files client, including that storage's configured plugin extensions. */\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 name === undefined ? registry.get() : registry.get(name)\n}\n"],"mappings":";;AAoBA,IAAI;;AAGJ,MAAa,kBACT,QACA,YACmB;CACnB,MAAM,QAAQ,IAAI,cAAc,QAAQ,OAAO;CAC/C,WAAW;CACX,OAAO;AACX;;AAGA,MAAa,qBACT,UAAU,QAAQ,KAAK;CACnB,UAAU,CAAC;CACX,aAAa,CACT;EACI,MAAM;EACN,OAAO;EACP,SAAS;CACb,CACJ;AACJ;AAQJ,SAAgB,eAAe,MAA+B;CAC1D,IAAI,CAAC,UACD,MAAM,IAAI,MAAM,6EAA6E;CAEjG,OAAO,SAAS,KAAA,IAAY,SAAS,IAAI,IAAI,SAAS,IAAI,IAAI;AAClE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-files-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Native-first Files SDK integration for Nuxt and Nitro",
|
|
5
5
|
"homepage": "https://github.com/liria24/nuxt-files-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@nuxt/kit": "^4.5.2",
|
|
53
53
|
"devframe": "^0.9.12",
|
|
54
|
-
"files-sdk": "^2.
|
|
54
|
+
"files-sdk": "^2.4.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
58
58
|
"@nuxt/schema": "^4.5.2",
|
|
59
|
-
"@types/node": "^26.
|
|
59
|
+
"@types/node": "^26.5.0",
|
|
60
60
|
"publint": "^0.3.24",
|
|
61
61
|
"tsdown": "^0.23.0",
|
|
62
62
|
"typescript": "^7.0.2",
|