nuxt-files-sdk 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +44 -3
  3. package/dist/config/load.js +67 -0
  4. package/dist/config/load.js.map +1 -0
  5. package/dist/config/merge.d.ts +5 -0
  6. package/dist/config/merge.js +22 -0
  7. package/dist/config/merge.js.map +1 -0
  8. package/dist/config/prune.js +55 -0
  9. package/dist/config/prune.js.map +1 -0
  10. package/dist/config.d.ts +103 -91
  11. package/dist/config.js +1 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/devtools/auth.js +49 -0
  14. package/dist/devtools/auth.js.map +1 -0
  15. package/dist/devtools/client/app.js +8 -0
  16. package/dist/devtools/client/browser-agent-rpc-BXhoSh1z-DRoP5jHQ.js +1 -0
  17. package/dist/devtools/client/index.html +392 -72
  18. package/dist/devtools/devframe.js +66 -7
  19. package/dist/devtools/devframe.js.map +1 -1
  20. package/dist/devtools/diagnostics.d.ts +37 -0
  21. package/dist/devtools/diagnostics.js +39 -0
  22. package/dist/devtools/diagnostics.js.map +1 -0
  23. package/dist/devtools/enabled.d.ts +9 -0
  24. package/dist/devtools/enabled.js +3 -2
  25. package/dist/devtools/enabled.js.map +1 -1
  26. package/dist/devtools/files-read.d.ts +5 -0
  27. package/dist/devtools/files-read.js +7 -0
  28. package/dist/devtools/files-read.js.map +1 -0
  29. package/dist/devtools/files-write.d.ts +5 -0
  30. package/dist/devtools/files-write.js +7 -0
  31. package/dist/devtools/files-write.js.map +1 -0
  32. package/dist/devtools/files.js +51 -0
  33. package/dist/devtools/files.js.map +1 -0
  34. package/dist/devtools/index.js +30 -5
  35. package/dist/devtools/index.js.map +1 -1
  36. package/dist/devtools/nuxt-v3-handler.js +16 -4
  37. package/dist/devtools/nuxt-v3-handler.js.map +1 -1
  38. package/dist/devtools/nuxt-v3.js +1 -1
  39. package/dist/devtools/nuxt-v3.js.map +1 -1
  40. package/dist/devtools/nuxt-v4.js +37 -6
  41. package/dist/devtools/nuxt-v4.js.map +1 -1
  42. package/dist/devtools/snapshot.d.ts +12 -7
  43. package/dist/devtools/snapshot.js +15 -3
  44. package/dist/devtools/snapshot.js.map +1 -1
  45. package/dist/devtools/token.d.ts +14 -0
  46. package/dist/devtools/token.js +17 -0
  47. package/dist/devtools/token.js.map +1 -0
  48. package/dist/integration/nitro.d.ts +12 -1
  49. package/dist/integration/nitro.js +162 -41
  50. package/dist/integration/nitro.js.map +1 -1
  51. package/dist/module.d.ts +4 -6
  52. package/dist/module.js +37 -14
  53. package/dist/module.js.map +1 -1
  54. package/dist/nitro.d.ts +2 -4
  55. package/dist/nitro.js +2 -4
  56. package/dist/nitro.js.map +1 -1
  57. package/dist/package.js +1 -1
  58. package/dist/runtime/internal.d.ts +11 -0
  59. package/dist/runtime/internal.js +30 -0
  60. package/dist/runtime/internal.js.map +1 -0
  61. package/dist/runtime/normalize.js +29 -0
  62. package/dist/runtime/normalize.js.map +1 -0
  63. package/dist/runtime/provider-types.d.ts +53 -0
  64. package/dist/runtime/registry.d.ts +55 -8
  65. package/dist/runtime/registry.js +130 -63
  66. package/dist/runtime/registry.js.map +1 -1
  67. package/dist/runtime.d.ts +8 -9
  68. package/dist/runtime.js +8 -20
  69. package/dist/runtime.js.map +1 -1
  70. package/package.json +25 -19
  71. package/dist/plugins/versioning.d.ts +0 -3
  72. package/dist/plugins/versioning.js +0 -2
  73. package/dist/plugins.d.ts +0 -31
  74. package/dist/plugins.js +0 -16
@@ -0,0 +1,53 @@
1
+ //#region src/runtime/provider-types.d.ts
2
+ export interface ProviderFactories {
3
+ akamai: typeof import('files-sdk/akamai').akamai;
4
+ alibaba: typeof import('files-sdk/alibaba').alibaba;
5
+ appwrite: typeof import('files-sdk/appwrite').appwrite;
6
+ archil: typeof import('files-sdk/archil').archil;
7
+ azure: typeof import('files-sdk/azure').azure;
8
+ 'backblaze-b2': typeof import('files-sdk/backblaze-b2').backblazeB2;
9
+ box: typeof import('files-sdk/box').box;
10
+ 'bun-s3': typeof import('files-sdk/bun-s3').bunS3;
11
+ 'bunny-storage': typeof import('files-sdk/bunny-storage').bunnyStorage;
12
+ cloudinary: typeof import('files-sdk/cloudinary').cloudinaryAdapter;
13
+ convex: typeof import('files-sdk/convex').convex;
14
+ 'digitalocean-spaces': typeof import('files-sdk/digitalocean-spaces').digitaloceanSpaces;
15
+ dropbox: typeof import('files-sdk/dropbox').dropbox;
16
+ exoscale: typeof import('files-sdk/exoscale').exoscale;
17
+ filebase: typeof import('files-sdk/filebase').filebase;
18
+ 'firebase-storage': typeof import('files-sdk/firebase-storage').firebaseStorage;
19
+ fs: typeof import('files-sdk/fs').fs;
20
+ ftp: typeof import('files-sdk/ftp').ftp;
21
+ gcs: typeof import('files-sdk/gcs').gcs;
22
+ 'google-drive': typeof import('files-sdk/google-drive').googleDrive;
23
+ hetzner: typeof import('files-sdk/hetzner').hetzner;
24
+ 'ibm-cos': typeof import('files-sdk/ibm-cos').ibmCos;
25
+ 'idrive-e2': typeof import('files-sdk/idrive-e2').idriveE2;
26
+ memory: typeof import('files-sdk/memory').memory;
27
+ minio: typeof import('files-sdk/minio').minio;
28
+ neon: typeof import('files-sdk/neon').neon;
29
+ 'netlify-blobs': typeof import('files-sdk/netlify-blobs').netlifyBlobs;
30
+ onedrive: typeof import('files-sdk/onedrive').onedrive;
31
+ 'oracle-cloud': typeof import('files-sdk/oracle-cloud').oracleCloud;
32
+ ovhcloud: typeof import('files-sdk/ovhcloud').ovhcloud;
33
+ pocketbase: typeof import('files-sdk/pocketbase').pocketbase;
34
+ r2: typeof import('files-sdk/r2').r2;
35
+ rustfs: typeof import('files-sdk/rustfs').rustfs;
36
+ s3: typeof import('files-sdk/s3').s3;
37
+ 's3-fetch': typeof import('files-sdk/s3-fetch').s3Fetch;
38
+ scaleway: typeof import('files-sdk/scaleway').scaleway;
39
+ sftp: typeof import('files-sdk/sftp').sftp;
40
+ sharepoint: typeof import('files-sdk/sharepoint').sharepoint;
41
+ storj: typeof import('files-sdk/storj').storj;
42
+ supabase: typeof import('files-sdk/supabase').supabase;
43
+ tencent: typeof import('files-sdk/tencent').tencent;
44
+ tigris: typeof import('files-sdk/tigris').tigris;
45
+ uploadthing: typeof import('files-sdk/uploadthing').uploadthing;
46
+ 'vercel-blob': typeof import('files-sdk/vercel-blob').vercelBlob;
47
+ vultr: typeof import('files-sdk/vultr').vultr;
48
+ wasabi: typeof import('files-sdk/wasabi').wasabi;
49
+ webdav: typeof import('files-sdk/webdav').webdav;
50
+ yandex: typeof import('files-sdk/yandex').yandex;
51
+ }
52
+ //#endregion
53
+ //# sourceMappingURL=provider-types.d.ts.map
@@ -1,13 +1,44 @@
1
- import { FilesConfig, NamedFilesConfig, SingleFilesConfig, StorageConfig } from "../config.js";
2
- import { FilesDevtoolsSnapshot } from "../devtools/snapshot.js";
1
+ import { ProviderFactories } from "./provider-types.js";
2
+ import { FilesConfig, FilesConfigInput } from "../config.js";
3
+ import { FilesDevtoolsDiagnosticCode } from "../devtools/diagnostics.js";
3
4
  import { Adapter, ExtensionsOf, Files, FilesActionEvent, FilesErrorEvent, FilesRetryEvent, ProviderSlug } from "files-sdk";
4
5
  //#region src/runtime/registry.d.ts
5
6
  /** Native Files client plus the methods contributed by a storage's plugins. */
6
- export type FilesForStorage<T extends StorageConfig> = Files & ExtensionsOf<NonNullable<T['plugins']>>;
7
+ type AdapterFor<A> = A extends ProviderSlug ? ReturnType<ProviderFactories[A]> : A extends ((...args: never[]) => Adapter) ? ReturnType<A> : never;
8
+ type PluginsFor<T> = T extends {
9
+ plugins: infer V;
10
+ } ? V extends ((...args: never[]) => infer P) ? P extends readonly import('files-sdk').FilesPlugin[] ? P : never : V extends readonly import('files-sdk').FilesPlugin[] ? V : never : never;
11
+ export type FilesForStorage<T extends {
12
+ adapter: ProviderSlug | ((...args: never[]) => Adapter);
13
+ }> = Files<AdapterFor<T['adapter']>> & ExtensionsOf<PluginsFor<T>>;
14
+ type StorageOf<C> = C extends {
15
+ storage: infer S;
16
+ } ? S : never;
17
+ type StorageBranch<C> = StorageOf<C> | StorageOf<C extends {
18
+ $development: infer E;
19
+ } ? E : never> | StorageOf<C extends {
20
+ $production: infer E;
21
+ } ? E : never> | StorageOf<C extends {
22
+ $test: infer E;
23
+ } ? E : never> | StorageOf<C extends {
24
+ $prerender: infer E;
25
+ } ? E : never> | StorageOf<C extends {
26
+ $env: infer E;
27
+ } ? E[keyof E] : never>;
28
+ type SingleEntry<C> = Extract<StorageBranch<C>, {
29
+ adapter: ProviderSlug | ((...args: never[]) => Adapter);
30
+ }>;
31
+ type NamedSet<C> = Exclude<StorageBranch<C>, {
32
+ adapter: unknown;
33
+ }>;
34
+ type StorageNames<C> = NamedSet<C> extends (infer S) ? (S extends object ? keyof S : never) : never;
35
+ type NamedEntry<C, Name extends PropertyKey> = NamedSet<C> extends (infer S) ? (S extends object ? (Name extends keyof S ? S[Name] : never) : never) : never;
7
36
  /** Map each configured storage name to its native Files client and plugin extensions. */
8
- export type StorageRegistry<C extends FilesConfig> = C extends NamedFilesConfig<infer Storages> ? { [Name in keyof Storages]: FilesForStorage<Storages[Name]>; } : Record<never, never>;
37
+ export type StorageRegistry<C extends FilesConfigInput> = { [Name in StorageNames<C>]: FilesForStorage<Extract<NamedEntry<C, Name>, {
38
+ adapter: ProviderSlug | ((...args: never[]) => Adapter);
39
+ }>>; };
9
40
  /** Files client returned by an unnamed single-storage configuration. */
10
- export type SingleStorage<C extends FilesConfig> = C extends SingleFilesConfig<infer Storage> ? FilesForStorage<Storage> : never;
41
+ export type SingleStorage<C extends FilesConfigInput> = FilesForStorage<SingleEntry<C>>;
11
42
  /** Hooks emitted by the Nuxt/Nitro bridge after the storage's native hooks. */
12
43
  export interface FilesRuntimeHooks {
13
44
  /** Observe a failed native Files operation. */
@@ -21,21 +52,37 @@ export interface FilesRuntimeHooks {
21
52
  export type FilesProviderFactory = (config: never) => Adapter;
22
53
  /** Provider factories available in the current build. */
23
54
  export type FilesProviderFactories = Partial<Record<ProviderSlug, FilesProviderFactory>>;
55
+ export type ProviderEnvironment = Partial<Record<ProviderSlug, readonly (readonly string[])[]>>;
56
+ export interface RegistryDiagnostic {
57
+ code: FilesDevtoolsDiagnosticCode;
58
+ name?: string;
59
+ adapter?: string;
60
+ }
24
61
  /** Lazily construct and memoize native Files clients for a validated project configuration. */
25
62
  export declare class FilesRegistry<const C extends FilesConfig = FilesConfig> {
26
63
  #private;
27
64
  /** Create a registry without constructing a provider. */
28
65
  constructor(config: C, options: {
29
- development?: boolean;
66
+ environment?: ProviderEnvironment;
30
67
  factories: FilesProviderFactories;
31
68
  hooks?: FilesRuntimeHooks;
32
69
  });
33
70
  /** Return the client from an unnamed single-storage configuration. */
34
- get(...args: C extends SingleFilesConfig ? [] : [name: never]): SingleStorage<C>;
71
+ get(...args: SingleEntry<C> extends never ? [name: never] : []): SingleStorage<C>;
35
72
  /** Return one named storage client. */
36
73
  get<Name extends Extract<keyof StorageRegistry<C>, string>>(name: Name): StorageRegistry<C>[Name];
37
74
  /** Return secret-free storage metadata and initialization state for development diagnostics. */
38
- inspect(): FilesDevtoolsSnapshot;
75
+ inspect(): {
76
+ storages: {
77
+ name?: string;
78
+ adapter: string;
79
+ plugins: any[];
80
+ initialized: boolean;
81
+ }[];
82
+ diagnostics: RegistryDiagnostic[];
83
+ };
84
+ /** Resolve one selected adapter without constructing its Files client. */
85
+ resolveAdapter(name?: string): Adapter;
39
86
  }
40
87
  //#endregion
41
88
  //# sourceMappingURL=registry.d.ts.map
@@ -1,4 +1,4 @@
1
- import { getProvider, listEnvVars } from "files-sdk/providers";
1
+ import { normalizeFilesConfig } from "./normalize.js";
2
2
  import { createFiles } from "files-sdk";
3
3
  //#region src/runtime/registry.ts
4
4
  const runHooks = async (...hooks) => {
@@ -6,113 +6,180 @@ const runHooks = async (...hooks) => {
6
6
  await hook();
7
7
  } catch {}
8
8
  };
9
- const isStorageConfig = (value) => Boolean(value && typeof value === "object" && "adapter" in value && typeof value.adapter === "string");
10
- const isStorageRecord = (value) => Boolean(value && typeof value === "object" && Object.values(value).every(isStorageConfig));
9
+ const nativeFilesOptions = ({ adapter: _adapter, config: _config, hooks: _hooks, plugins: _plugins, ...options }) => options;
11
10
  /** Lazily construct and memoize native Files clients for a validated project configuration. */
12
11
  var FilesRegistry = class {
13
- #config;
14
- #development;
12
+ #entries;
13
+ #environment;
15
14
  #factories;
16
15
  #hooks;
16
+ #adapters = /* @__PURE__ */ new Map();
17
+ #adapterInitializing = /* @__PURE__ */ new Set();
17
18
  #instances = /* @__PURE__ */ new Map();
18
- #initializing = /* @__PURE__ */ new Set();
19
+ #filesInitializing = /* @__PURE__ */ new Set();
20
+ #pluginNames = /* @__PURE__ */ new Map();
21
+ #diagnostics = /* @__PURE__ */ new Map();
19
22
  /** Create a registry without constructing a provider. */
20
23
  constructor(config, options) {
21
- if ("default" in config) throw new Error("[nuxt-files-sdk:invalid-config] The default option has been removed.");
22
- if (!config.storage || !isStorageConfig(config.storage) && (!isStorageRecord(config.storage) || Object.keys(config.storage).length === 0)) throw new Error("[nuxt-files-sdk:invalid-config] At least one storage is required.");
23
- if (!isStorageConfig(config.storage)) {
24
- if (config.devStorage && !isStorageRecord(config.devStorage)) throw new Error("[nuxt-files-sdk:invalid-config] Named storage requires named devStorage overrides.");
25
- for (const name of Object.keys(config.devStorage ?? {})) if (!Object.hasOwn(config.storage, name)) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${name}".`);
26
- }
27
- this.#config = config;
28
- this.#development = options.development ?? false;
24
+ this.#entries = normalizeFilesConfig(config);
25
+ if (!this.#entries.size) throw new Error("[nuxt-files-sdk:invalid-config] At least one storage is required.");
26
+ this.#environment = options.environment ?? {};
29
27
  this.#factories = options.factories;
30
28
  this.#hooks = options.hooks ?? {};
31
29
  }
32
- get(name) {
30
+ get(...args) {
31
+ const name = args[0];
33
32
  const entry = this.#entry(name);
34
- const key = entry.name ?? "";
33
+ const key = entry.name;
35
34
  const cached = this.#instances.get(key);
36
35
  if (cached) return cached;
37
- if (this.#initializing.has(key)) throw new Error("[nuxt-files-sdk:circular-initialization] Storage configuration cannot access itself.");
38
- this.#initializing.add(key);
36
+ if (this.#filesInitializing.has(key)) throw this.#circular(key);
37
+ this.#filesInitializing.add(key);
39
38
  try {
40
39
  const files = this.#create(entry);
41
40
  this.#instances.set(key, files);
41
+ this.#diagnostics.delete(key);
42
42
  return files;
43
+ } catch (error) {
44
+ this.#diagnostics.set(key, {
45
+ code: "NUXT_FILES_ADAPTER_INIT_FAILED",
46
+ ...entry.name === void 0 ? {} : { name: entry.name },
47
+ adapter: typeof entry.storage.adapter === "string" ? entry.storage.adapter : "custom"
48
+ });
49
+ throw error;
43
50
  } finally {
44
- this.#initializing.delete(key);
51
+ this.#filesInitializing.delete(key);
45
52
  }
46
53
  }
47
54
  /** Return secret-free storage metadata and initialization state for development diagnostics. */
48
55
  inspect() {
49
56
  return {
50
- storages: this.#entries().map(({ name, storage, override }) => ({
57
+ storages: [...this.#entries.values()].map(({ name, storage }) => ({
51
58
  ...name === void 0 ? {} : { name },
52
- adapter: override?.adapter ?? storage.adapter,
53
- plugins: storage.plugins?.map((plugin) => plugin.name) ?? [],
54
- source: override ? "devStorage" : "storage",
55
- initialized: this.#instances.has(name ?? "")
59
+ adapter: typeof storage.adapter === "string" ? storage.adapter : "custom",
60
+ plugins: this.#pluginNames.get(name) ?? (Array.isArray(storage.plugins) ? storage.plugins.map((plugin) => plugin.name) : []),
61
+ initialized: this.#instances.has(name)
56
62
  })),
57
- diagnostics: []
63
+ diagnostics: [...this.#diagnostics.values()]
58
64
  };
59
65
  }
60
- #entries() {
61
- const storage = this.#config.storage;
62
- const devStorage = this.#config.devStorage;
63
- if (isStorageConfig(storage)) return [{
64
- name: void 0,
65
- storage,
66
- override: this.#development && isStorageConfig(devStorage) ? devStorage : void 0
67
- }];
68
- const overrides = this.#development && isStorageRecord(devStorage) ? devStorage : void 0;
69
- return Object.entries(storage).map(([name, namedStorage]) => ({
70
- name,
71
- storage: namedStorage,
72
- override: overrides?.[name]
73
- }));
74
- }
75
66
  #entry(name) {
76
- if (isStorageConfig(this.#config.storage)) {
77
- if (name !== void 0) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${name}".`);
78
- return this.#entries()[0];
79
- }
80
- if (name === void 0) throw new Error("[nuxt-files-sdk:storage-name-required] A storage name is required.");
81
- const entry = this.#entries().find((candidate) => candidate.name === name);
67
+ if (name === void 0 && !this.#entries.has(void 0)) throw new Error("[nuxt-files-sdk:storage-name-required] A storage name is required.");
68
+ const entry = this.#entries.get(name);
82
69
  if (!entry) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage "${name}".`);
83
70
  return entry;
84
71
  }
85
- #create({ name, storage, override }) {
86
- const selected = override ?? storage;
87
- const factory = this.#factories[selected.adapter];
88
- if (!factory) throw new Error(`[nuxt-files-sdk:adapter-not-generated] Adapter "${selected.adapter}" is not available in this build.`);
89
- const adapter = withNuxtEnvironment(selected.adapter, () => {
72
+ /** Resolve one selected adapter without constructing its Files client. */
73
+ resolveAdapter(name) {
74
+ const entry = this.#entry(name);
75
+ const key = entry.name;
76
+ const cached = this.#adapters.get(key);
77
+ if (cached) return cached;
78
+ if (this.#adapterInitializing.has(key)) throw this.#circular(key);
79
+ this.#adapterInitializing.add(key);
80
+ try {
81
+ const adapter = this.#createAdapter(entry);
82
+ this.#adapters.set(key, adapter);
83
+ return adapter;
84
+ } finally {
85
+ this.#adapterInitializing.delete(key);
86
+ }
87
+ }
88
+ #circular(name) {
89
+ return /* @__PURE__ */ new Error(`[nuxt-files-sdk:circular-initialization] Circular storage dependency${name ? ` at "${name}"` : ""}.`);
90
+ }
91
+ #createAdapter({ storage: selected }) {
92
+ const factory = typeof selected.adapter === "string" ? this.#factories[selected.adapter] : selected.adapter;
93
+ if (!factory) throw new Error(`[nuxt-files-sdk:adapter-not-generated] Adapter "${typeof selected.adapter === "string" ? selected.adapter : "custom"}" is not available in this build.`);
94
+ const environment = typeof selected.adapter === "string" ? this.#environment[selected.adapter] ?? [] : [];
95
+ return withNuxtEnvironment(environment, () => {
90
96
  const input = typeof selected.config === "function" ? selected.config() : selected.config;
91
97
  if (input && typeof input === "object" && "then" in input) throw new Error("[nuxt-files-sdk:async-config] Storage config functions must be synchronous.");
92
- return factory(input);
98
+ const value = selected.adapter === "s3" ? withS3NuxtCredentials(input) : selected.adapter === "bun-s3" ? withBunS3NuxtOptions(input) : input;
99
+ return factory(value);
93
100
  });
94
- return createFiles({
101
+ }
102
+ #create({ name, storage }) {
103
+ const adapter = this.resolveAdapter(name);
104
+ const plugins = typeof storage.plugins === "function" ? storage.plugins({ storage: (storageName) => this.resolveAdapter(storageName) }) : storage.plugins;
105
+ const files = createFiles({
95
106
  adapter,
107
+ ...nativeFilesOptions(storage),
96
108
  hooks: {
97
109
  onAction: (event) => runHooks(() => storage.hooks?.onAction?.(event), () => this.#hooks.onAction?.(event, name)),
98
110
  onError: (event) => runHooks(() => storage.hooks?.onError?.(event), () => this.#hooks.onError?.(event, name)),
99
111
  onRetry: (event) => runHooks(() => storage.hooks?.onRetry?.(event), () => this.#hooks.onRetry?.(event, name))
100
112
  },
101
- ...storage.plugins ? { plugins: storage.plugins } : {},
102
- ...storage.prefix === void 0 ? {} : { prefix: storage.prefix },
103
- ...storage.retries === void 0 ? {} : { retries: storage.retries },
104
- ...storage.timeout === void 0 ? {} : { timeout: storage.timeout }
113
+ ...plugins ? { plugins } : {}
105
114
  });
115
+ if (plugins) this.#pluginNames.set(name, plugins.map((plugin) => plugin.name));
116
+ return files;
117
+ }
118
+ };
119
+ /** Pass NUXT_ credentials explicitly because the AWS SDK resolves its chain after construction. */
120
+ const withS3NuxtCredentials = (input) => {
121
+ if (!input || typeof input !== "object" || "credentials" in input) return input;
122
+ if ([
123
+ "AWS_ACCESS_KEY_ID",
124
+ "AWS_SECRET_ACCESS_KEY",
125
+ "AWS_PROFILE",
126
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
127
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
128
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI"
129
+ ].some((key) => process.env[key] !== void 0)) return input;
130
+ const accessKeyId = process.env.NUXT_AWS_ACCESS_KEY_ID;
131
+ const secretAccessKey = process.env.NUXT_AWS_SECRET_ACCESS_KEY;
132
+ if (!accessKeyId || !secretAccessKey) return input;
133
+ return {
134
+ ...input,
135
+ credentials: {
136
+ accessKeyId,
137
+ secretAccessKey,
138
+ ...(process.env.AWS_SESSION_TOKEN ?? process.env.NUXT_AWS_SESSION_TOKEN) && { sessionToken: process.env.AWS_SESSION_TOKEN ?? process.env.NUXT_AWS_SESSION_TOKEN }
139
+ }
140
+ };
141
+ };
142
+ /** Bun resolves these environment keys in its own client; pass NUXT_ aliases as explicit options. */
143
+ const withBunS3NuxtOptions = (input) => {
144
+ if (input && (typeof input !== "object" || "client" in input)) return input;
145
+ const options = { ...typeof input === "object" && input ? input : {} };
146
+ for (const [field, key, alias] of [
147
+ [
148
+ "accessKeyId",
149
+ "AWS_ACCESS_KEY_ID",
150
+ "S3_ACCESS_KEY_ID"
151
+ ],
152
+ [
153
+ "secretAccessKey",
154
+ "AWS_SECRET_ACCESS_KEY",
155
+ "S3_SECRET_ACCESS_KEY"
156
+ ],
157
+ [
158
+ "sessionToken",
159
+ "AWS_SESSION_TOKEN",
160
+ "S3_SESSION_TOKEN"
161
+ ],
162
+ [
163
+ "region",
164
+ "AWS_REGION",
165
+ "S3_REGION"
166
+ ],
167
+ [
168
+ "bucket",
169
+ "AWS_BUCKET",
170
+ "S3_BUCKET"
171
+ ]
172
+ ]) {
173
+ if (Object.hasOwn(options, field) || process.env[key] !== void 0 || process.env[alias] !== void 0) continue;
174
+ const value = process.env[`NUXT_${key}`] ?? process.env[`NUXT_${alias}`];
175
+ if (value !== void 0) options[field] = value;
106
176
  }
177
+ return options;
107
178
  };
108
179
  /** Bridge only NUXT_ aliases declared by the configured native provider during synchronous construction. */
109
- const withNuxtEnvironment = (provider, load) => {
110
- if (!getProvider(provider)) return load();
111
- const variables = listEnvVars(provider);
112
- if (variables.length === 0) return load();
180
+ const withNuxtEnvironment = (variables, load) => {
113
181
  const injected = [];
114
- for (const variable of variables) {
115
- const keys = [variable.key, ...variable.aliases ?? []];
182
+ for (const keys of variables) {
116
183
  if (keys.some((key) => process.env[key] !== void 0)) continue;
117
184
  for (const key of keys) {
118
185
  const value = process.env[`NUXT_${key}`];
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../src/runtime/registry.ts"],"sourcesContent":["import {\n createFiles,\n type Adapter,\n type ExtensionsOf,\n type Files,\n type FilesActionEvent,\n type FilesErrorEvent,\n type FilesRetryEvent,\n type ProviderSlug,\n} from 'files-sdk'\nimport { getProvider, listEnvVars } from 'files-sdk/providers'\n\nimport type { FilesConfig, NamedFilesConfig, SingleFilesConfig, 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 C extends NamedFilesConfig<infer Storages>\n ? { [Name in keyof Storages]: FilesForStorage<Storages[Name]> }\n : Record<never, never>\n\n/** Files client returned by an unnamed single-storage configuration. */\nexport type SingleStorage<C extends FilesConfig> =\n C extends SingleFilesConfig<infer Storage> ? FilesForStorage<Storage> : never\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\n/** One provider factory statically supplied by the generated Nitro plugin. */\nexport type FilesProviderFactory = (config: never) => Adapter\n/** Provider factories available in the current build. */\nexport type FilesProviderFactories = Partial<Record<ProviderSlug, FilesProviderFactory>>\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\nconst isStorageConfig = (value: unknown): value is StorageConfig =>\n Boolean(value && typeof value === 'object' && 'adapter' in value && typeof value.adapter === 'string')\nconst isStorageRecord = (value: unknown): value is Record<string, StorageConfig> =>\n Boolean(value && typeof value === 'object' && Object.values(value).every(isStorageConfig))\n\ntype StorageEntry = { name: string | undefined; storage: StorageConfig; override: StorageConfig | undefined }\n\n/** Lazily construct 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 #factories: FilesProviderFactories\n readonly #hooks: FilesRuntimeHooks\n readonly #instances = new Map<string, Files>()\n readonly #initializing = new Set<string>()\n\n /** Create a registry without constructing a provider. */\n constructor(\n config: C,\n options: {\n development?: boolean\n factories: FilesProviderFactories\n hooks?: FilesRuntimeHooks\n },\n ) {\n if ('default' in config) {\n throw new Error('[nuxt-files-sdk:invalid-config] The default option has been removed.')\n }\n if (\n !config.storage ||\n (!isStorageConfig(config.storage) &&\n (!isStorageRecord(config.storage) || Object.keys(config.storage).length === 0))\n ) {\n throw new Error('[nuxt-files-sdk:invalid-config] At least one storage is required.')\n }\n if (!isStorageConfig(config.storage)) {\n if (config.devStorage && !isStorageRecord(config.devStorage)) {\n throw new Error('[nuxt-files-sdk:invalid-config] Named storage requires named devStorage overrides.')\n }\n for (const name of Object.keys(config.devStorage ?? {})) {\n if (!Object.hasOwn(config.storage, name)) {\n throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n }\n }\n }\n this.#config = config\n this.#development = options.development ?? false\n this.#factories = options.factories\n this.#hooks = options.hooks ?? {}\n }\n\n /** Return the client from an unnamed single-storage configuration. */\n get(...args: C extends SingleFilesConfig ? [] : [name: never]): SingleStorage<C>\n /** Return one named storage client. */\n get<Name extends Extract<keyof StorageRegistry<C>, string>>(name: Name): StorageRegistry<C>[Name]\n get(name?: string): Files {\n const entry = this.#entry(name)\n const key = entry.name ?? ''\n const cached = this.#instances.get(key)\n if (cached) return cached\n if (this.#initializing.has(key)) {\n throw new Error('[nuxt-files-sdk:circular-initialization] Storage configuration cannot access itself.')\n }\n this.#initializing.add(key)\n try {\n const files = this.#create(entry)\n this.#instances.set(key, files)\n return files\n } finally {\n this.#initializing.delete(key)\n }\n }\n\n /** Return secret-free storage metadata and initialization state for development diagnostics. */\n inspect(): FilesDevtoolsSnapshot {\n return {\n storages: this.#entries().map(({ name, storage, override }) => ({\n ...(name === undefined ? {} : { 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 diagnostics: [],\n }\n }\n\n #entries(): StorageEntry[] {\n const storage = this.#config.storage\n const devStorage = this.#config.devStorage\n if (isStorageConfig(storage)) {\n const override = this.#development && isStorageConfig(devStorage) ? devStorage : undefined\n return [{ name: undefined, storage, override }]\n }\n const overrides = this.#development && isStorageRecord(devStorage) ? devStorage : undefined\n return Object.entries(storage).map(([name, namedStorage]) => ({\n name,\n storage: namedStorage,\n override: overrides?.[name],\n }))\n }\n\n #entry(name?: string): StorageEntry {\n if (isStorageConfig(this.#config.storage)) {\n if (name !== undefined) {\n throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n }\n return this.#entries()[0]!\n }\n if (name === undefined) {\n throw new Error('[nuxt-files-sdk:storage-name-required] A storage name is required.')\n }\n const entry = this.#entries().find((candidate) => candidate.name === name)\n if (!entry) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n return entry\n }\n\n #create({ name, storage, override }: StorageEntry): Files {\n const selected = override ?? storage\n const factory = this.#factories[selected.adapter]\n if (!factory) {\n throw new Error(\n `[nuxt-files-sdk:adapter-not-generated] Adapter \"${selected.adapter}\" is not available in this build.`,\n )\n }\n const adapter = withNuxtEnvironment(selected.adapter, () => {\n const input = typeof selected.config === 'function' ? selected.config() : selected.config\n if (input && typeof input === 'object' && 'then' in input) {\n throw new Error('[nuxt-files-sdk:async-config] Storage config functions must be synchronous.')\n }\n // Generated factories and configs share an adapter key; the broad registry type erases that correlation.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return factory(input as never)\n })\n return createFiles({\n adapter,\n hooks: {\n onAction: (event) =>\n runHooks(\n () => storage.hooks?.onAction?.(event),\n () => this.#hooks.onAction?.(event, name),\n ),\n onError: (event) =>\n runHooks(\n () => storage.hooks?.onError?.(event),\n () => this.#hooks.onError?.(event, name),\n ),\n onRetry: (event) =>\n runHooks(\n () => storage.hooks?.onRetry?.(event),\n () => this.#hooks.onRetry?.(event, name),\n ),\n },\n ...(storage.plugins ? { plugins: storage.plugins } : {}),\n ...(storage.prefix === undefined ? {} : { prefix: storage.prefix }),\n ...(storage.retries === undefined ? {} : { retries: storage.retries }),\n ...(storage.timeout === undefined ? {} : { timeout: storage.timeout }),\n })\n }\n}\n\n/** Bridge only NUXT_ aliases declared by the configured native provider during synchronous construction. */\nexport const withNuxtEnvironment = <T>(provider: ProviderSlug, load: () => T): T => {\n const metadata = getProvider(provider)\n if (!metadata) return load()\n const variables = listEnvVars(provider)\n if (variables.length === 0) return load()\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 load()\n } finally {\n for (const key of injected) del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wB,SAAqB;CAEhF,IAAI,CADa,YAAY,QACjB,GAAG,OAAO,KAAK;CAC3B,MAAM,YAAY,YAAY,QAAQ;CACtC,IAAI,UAAU,WAAW,GAAG,OAAO,KAAK;CACxC,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,KAAK;CAChB,UAAU;EACN,KAAK,MAAM,OAAO,UAAU,OAAO,QAAQ,IAAI;CACnD;AACJ"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../src/runtime/registry.ts"],"sourcesContent":["import {\n createFiles,\n type Adapter,\n type ExtensionsOf,\n type Files,\n type FilesActionEvent,\n type FilesErrorEvent,\n type FilesRetryEvent,\n type ProviderSlug,\n} from 'files-sdk'\n\nimport type { FilesConfig, FilesConfigInput, StorageConfig } from '../config'\nimport type { FilesDevtoolsDiagnosticCode } from '../devtools/diagnostics'\nimport { normalizeFilesConfig, type StorageEntry } from './normalize'\nimport type { ProviderFactories } from './provider-types'\n\n/** Native Files client plus the methods contributed by a storage's plugins. */\ntype AdapterFor<A> = A extends ProviderSlug\n ? ReturnType<ProviderFactories[A]>\n : A extends (...args: never[]) => Adapter\n ? ReturnType<A>\n : never\ntype PluginsFor<T> = T extends { plugins: infer V }\n ? V extends (...args: never[]) => infer P\n ? P extends readonly import('files-sdk').FilesPlugin[]\n ? P\n : never\n : V extends readonly import('files-sdk').FilesPlugin[]\n ? V\n : never\n : never\nexport type FilesForStorage<T extends { adapter: ProviderSlug | ((...args: never[]) => Adapter) }> = Files<\n AdapterFor<T['adapter']>\n> &\n ExtensionsOf<PluginsFor<T>>\n\ntype StorageOf<C> = C extends { storage: infer S } ? S : never\ntype StorageBranch<C> =\n | StorageOf<C>\n | StorageOf<C extends { $development: infer E } ? E : never>\n | StorageOf<C extends { $production: infer E } ? E : never>\n | StorageOf<C extends { $test: infer E } ? E : never>\n | StorageOf<C extends { $prerender: infer E } ? E : never>\n | StorageOf<C extends { $env: infer E } ? E[keyof E] : never>\ntype SingleEntry<C> = Extract<StorageBranch<C>, { adapter: ProviderSlug | ((...args: never[]) => Adapter) }>\ntype NamedSet<C> = Exclude<StorageBranch<C>, { adapter: unknown }>\ntype StorageNames<C> = NamedSet<C> extends infer S ? (S extends object ? keyof S : never) : never\ntype NamedEntry<C, Name extends PropertyKey> =\n NamedSet<C> extends infer S ? (S extends object ? (Name extends keyof S ? S[Name] : never) : never) : never\n/** Map each configured storage name to its native Files client and plugin extensions. */\nexport type StorageRegistry<C extends FilesConfigInput> = {\n [Name in StorageNames<C>]: FilesForStorage<\n Extract<NamedEntry<C, Name>, { adapter: ProviderSlug | ((...args: never[]) => Adapter) }>\n >\n}\n\n/** Files client returned by an unnamed single-storage configuration. */\nexport type SingleStorage<C extends FilesConfigInput> = FilesForStorage<SingleEntry<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\n/** One provider factory statically supplied by the generated Nitro plugin. */\nexport type FilesProviderFactory = (config: never) => Adapter\n/** Provider factories available in the current build. */\nexport type FilesProviderFactories = Partial<Record<ProviderSlug, FilesProviderFactory>>\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\nconst nativeFilesOptions = ({\n adapter: _adapter,\n config: _config,\n hooks: _hooks,\n plugins: _plugins,\n ...options\n}: StorageConfig) => options\n\nexport type ProviderEnvironment = Partial<Record<ProviderSlug, readonly (readonly string[])[]>>\nexport interface RegistryDiagnostic {\n code: FilesDevtoolsDiagnosticCode\n name?: string\n adapter?: string\n}\n\n/** Lazily construct and memoize native Files clients for a validated project configuration. */\nexport class FilesRegistry<const C extends FilesConfig = FilesConfig> {\n readonly #entries: Map<string | undefined, StorageEntry>\n readonly #environment: ProviderEnvironment\n readonly #factories: FilesProviderFactories\n readonly #hooks: FilesRuntimeHooks\n readonly #adapters = new Map<string | undefined, Adapter>()\n readonly #adapterInitializing = new Set<string | undefined>()\n readonly #instances = new Map<string | undefined, Files>()\n readonly #filesInitializing = new Set<string | undefined>()\n readonly #pluginNames = new Map<string | undefined, string[]>()\n readonly #diagnostics = new Map<string | undefined, RegistryDiagnostic>()\n\n /** Create a registry without constructing a provider. */\n constructor(\n config: C,\n options: {\n environment?: ProviderEnvironment\n factories: FilesProviderFactories\n hooks?: FilesRuntimeHooks\n },\n ) {\n this.#entries = normalizeFilesConfig(config)\n if (!this.#entries.size) throw new Error('[nuxt-files-sdk:invalid-config] At least one storage is required.')\n this.#environment = options.environment ?? {}\n this.#factories = options.factories\n this.#hooks = options.hooks ?? {}\n }\n\n /** Return the client from an unnamed single-storage configuration. */\n get(...args: SingleEntry<C> extends never ? [name: never] : []): SingleStorage<C>\n /** Return one named storage client. */\n get<Name extends Extract<keyof StorageRegistry<C>, string>>(name: Name): StorageRegistry<C>[Name]\n get(...args: [] | [string]): unknown {\n const name = args[0]\n const entry = this.#entry(name)\n const key = entry.name\n const cached = this.#instances.get(key)\n if (cached) return cached\n if (this.#filesInitializing.has(key)) throw this.#circular(key)\n this.#filesInitializing.add(key)\n try {\n const files = this.#create(entry)\n this.#instances.set(key, files)\n this.#diagnostics.delete(key)\n return files\n } catch (error) {\n this.#diagnostics.set(key, {\n code: 'NUXT_FILES_ADAPTER_INIT_FAILED',\n ...(entry.name === undefined ? {} : { name: entry.name }),\n adapter: typeof entry.storage.adapter === 'string' ? entry.storage.adapter : 'custom',\n })\n throw error\n } finally {\n this.#filesInitializing.delete(key)\n }\n }\n\n /** Return secret-free storage metadata and initialization state for development diagnostics. */\n inspect() {\n return {\n storages: [...this.#entries.values()].map(({ name, storage }) => ({\n ...(name === undefined ? {} : { name }),\n adapter: typeof storage.adapter === 'string' ? storage.adapter : 'custom',\n plugins:\n this.#pluginNames.get(name) ??\n (Array.isArray(storage.plugins) ? storage.plugins.map((plugin) => plugin.name) : []),\n initialized: this.#instances.has(name),\n })),\n diagnostics: [...this.#diagnostics.values()],\n }\n }\n\n #entry(name?: string): StorageEntry {\n if (name === undefined && !this.#entries.has(undefined)) {\n throw new Error('[nuxt-files-sdk:storage-name-required] A storage name is required.')\n }\n const entry = this.#entries.get(name)\n if (!entry) throw new Error(`[nuxt-files-sdk:unknown-storage] Unknown storage \"${name}\".`)\n return entry\n }\n\n /** Resolve one selected adapter without constructing its Files client. */\n resolveAdapter(name?: string): Adapter {\n const entry = this.#entry(name)\n const key = entry.name\n const cached = this.#adapters.get(key)\n if (cached) return cached\n if (this.#adapterInitializing.has(key)) throw this.#circular(key)\n this.#adapterInitializing.add(key)\n try {\n const adapter = this.#createAdapter(entry)\n this.#adapters.set(key, adapter)\n return adapter\n } finally {\n this.#adapterInitializing.delete(key)\n }\n }\n\n #circular(name?: string): Error {\n return new Error(\n `[nuxt-files-sdk:circular-initialization] Circular storage dependency${name ? ` at \"${name}\"` : ''}.`,\n )\n }\n\n #createAdapter({ storage: selected }: StorageEntry): Adapter {\n const factory = typeof selected.adapter === 'string' ? this.#factories[selected.adapter] : selected.adapter\n if (!factory) {\n throw new Error(\n `[nuxt-files-sdk:adapter-not-generated] Adapter \"${typeof selected.adapter === 'string' ? selected.adapter : 'custom'}\" is not available in this build.`,\n )\n }\n const environment = typeof selected.adapter === 'string' ? (this.#environment[selected.adapter] ?? []) : []\n return withNuxtEnvironment(environment, () => {\n const input = typeof selected.config === 'function' ? selected.config() : selected.config\n if (input && typeof input === 'object' && 'then' in input) {\n throw new Error('[nuxt-files-sdk:async-config] Storage config functions must be synchronous.')\n }\n const value =\n selected.adapter === 's3'\n ? withS3NuxtCredentials(input)\n : selected.adapter === 'bun-s3'\n ? withBunS3NuxtOptions(input)\n : input\n // Generated factories and configs share an adapter key; the broad registry type erases that correlation.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return factory(value as never)\n })\n }\n\n #create({ name, storage }: StorageEntry): Files {\n const adapter = this.resolveAdapter(name)\n const plugins =\n typeof storage.plugins === 'function'\n ? storage.plugins({ storage: (storageName) => this.resolveAdapter(storageName) })\n : storage.plugins\n const files = createFiles({\n adapter,\n ...nativeFilesOptions(storage),\n hooks: {\n onAction: (event) =>\n runHooks(\n () => storage.hooks?.onAction?.(event),\n () => this.#hooks.onAction?.(event, name),\n ),\n onError: (event) =>\n runHooks(\n () => storage.hooks?.onError?.(event),\n () => this.#hooks.onError?.(event, name),\n ),\n onRetry: (event) =>\n runHooks(\n () => storage.hooks?.onRetry?.(event),\n () => this.#hooks.onRetry?.(event, name),\n ),\n },\n ...(plugins ? { plugins } : {}),\n })\n if (plugins)\n this.#pluginNames.set(\n name,\n plugins.map((plugin) => plugin.name),\n )\n return files\n }\n}\n\n/** Pass NUXT_ credentials explicitly because the AWS SDK resolves its chain after construction. */\nconst withS3NuxtCredentials = (input: unknown): unknown => {\n if (!input || typeof input !== 'object' || 'credentials' in input) return input\n if (\n [\n 'AWS_ACCESS_KEY_ID',\n 'AWS_SECRET_ACCESS_KEY',\n 'AWS_PROFILE',\n 'AWS_WEB_IDENTITY_TOKEN_FILE',\n 'AWS_CONTAINER_CREDENTIALS_RELATIVE_URI',\n 'AWS_CONTAINER_CREDENTIALS_FULL_URI',\n ].some((key) => process.env[key] !== undefined)\n )\n return input\n const accessKeyId = process.env.NUXT_AWS_ACCESS_KEY_ID\n const secretAccessKey = process.env.NUXT_AWS_SECRET_ACCESS_KEY\n if (!accessKeyId || !secretAccessKey) return input\n return {\n ...input,\n credentials: {\n accessKeyId,\n secretAccessKey,\n ...((process.env.AWS_SESSION_TOKEN ?? process.env.NUXT_AWS_SESSION_TOKEN) && {\n sessionToken: process.env.AWS_SESSION_TOKEN ?? process.env.NUXT_AWS_SESSION_TOKEN,\n }),\n },\n }\n}\n\n/** Bun resolves these environment keys in its own client; pass NUXT_ aliases as explicit options. */\nconst withBunS3NuxtOptions = (input: unknown): unknown => {\n if (input && (typeof input !== 'object' || 'client' in input)) return input\n const options: Record<string, unknown> = { ...(typeof input === 'object' && input ? input : {}) }\n for (const [field, key, alias] of [\n ['accessKeyId', 'AWS_ACCESS_KEY_ID', 'S3_ACCESS_KEY_ID'],\n ['secretAccessKey', 'AWS_SECRET_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY'],\n ['sessionToken', 'AWS_SESSION_TOKEN', 'S3_SESSION_TOKEN'],\n ['region', 'AWS_REGION', 'S3_REGION'],\n ['bucket', 'AWS_BUCKET', 'S3_BUCKET'],\n ] as const) {\n if (Object.hasOwn(options, field) || process.env[key] !== undefined || process.env[alias] !== undefined)\n continue\n const value = process.env[`NUXT_${key}`] ?? process.env[`NUXT_${alias}`]\n if (value !== undefined) options[field] = value\n }\n return options\n}\n\n/** Bridge only NUXT_ aliases declared by the configured native provider during synchronous construction. */\nexport const withNuxtEnvironment = <T>(variables: readonly (readonly string[])[], load: () => T): T => {\n const injected: string[] = []\n for (const keys of variables) {\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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AAW,QAAQ,SAAS;CAC9C;CACA,OAAO;AACX;;AAGA,MAAa,uBAA0B,WAA2C,SAAqB;CACnG,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,QAAQ,WAAW;EAC1B,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,KAAK;CAChB,UAAU;EACN,KAAK,MAAM,OAAO,UAAU,OAAO,QAAQ,IAAI;CACnD;AACJ"}
package/dist/runtime.d.ts CHANGED
@@ -1,22 +1,21 @@
1
- import { FilesConfig } from "./config.js";
2
- import { FilesDevtoolsSnapshot } from "./devtools/snapshot.js";
3
- import { FilesForStorage, FilesProviderFactories, FilesProviderFactory, FilesRegistry, FilesRuntimeHooks, SingleStorage, StorageRegistry } from "./runtime/registry.js";
4
- import { Files } from "files-sdk";
1
+ import { FilesForStorage, SingleStorage, StorageRegistry } from "./runtime/registry.js";
2
+ import { Files, SyncOptions, TransferOptions } from "files-sdk";
5
3
  //#region src/runtime.d.ts
6
4
  /** Project storage names and plugin-extended Files clients supplied by generated declarations. */
7
5
  export interface NuxtFilesStorageRegistry {}
8
6
  /** Project single Files client supplied by generated declarations. */
9
7
  export interface NuxtFilesSingleStorage {}
10
- /** Configure the process-local Files registry used by {@link useServerFiles}. */
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. */
13
- export declare const inspectFiles: () => FilesDevtoolsSnapshot;
14
8
  /** Return the project's unnamed Files client, including its configured plugin extensions. */
15
9
  export declare function useServerFiles(...args: keyof NuxtFilesStorageRegistry extends never ? [] : [name: never]): NuxtFilesSingleStorage extends {
16
10
  value: infer Single;
17
11
  } ? Single : Files;
18
12
  /** Return a named project Files client, including that storage's configured plugin extensions. */
19
13
  export declare function useServerFiles<Name extends Extract<keyof NuxtFilesStorageRegistry, string>>(name: Name): NuxtFilesStorageRegistry[Name];
14
+ type FilesInput<Name extends string = Extract<keyof NuxtFilesStorageRegistry, string>> = Files | Name;
15
+ /** Delegate a mirror operation to the native Files SDK. */
16
+ export declare const syncFiles: (source: FilesInput, destination: FilesInput, options?: SyncOptions) => Promise<import("files-sdk").SyncResult>;
17
+ /** Delegate a transfer operation to the native Files SDK. */
18
+ export declare const transferFiles: (source: FilesInput, destination: FilesInput, options?: TransferOptions) => Promise<import("files-sdk").TransferResult>;
20
19
  //#endregion
21
- export { type FilesForStorage, type FilesProviderFactories, type FilesProviderFactory, FilesRegistry, type FilesRuntimeHooks, type SingleStorage, type StorageRegistry };
20
+ export type { FilesForStorage, SingleStorage, StorageRegistry };
22
21
  //# sourceMappingURL=runtime.d.ts.map
package/dist/runtime.js CHANGED
@@ -1,26 +1,14 @@
1
- import { FilesRegistry } from "./runtime/registry.js";
1
+ import { getFiles } from "./runtime/internal.js";
2
+ import { sync, transfer } from "files-sdk";
2
3
  //#region src/runtime.ts
3
- let registry;
4
- /** Configure the process-local Files registry used by {@link useServerFiles}. */
5
- const configureFiles = (config, options) => {
6
- const value = new FilesRegistry(config, options);
7
- registry = value;
8
- return value;
9
- };
10
- /** Return secret-free diagnostics for the configured process-local Files registry. */
11
- const inspectFiles = () => registry?.inspect() ?? {
12
- storages: [],
13
- diagnostics: [{
14
- code: "NUXT_FILES_NOT_CONFIGURED",
15
- level: "warning",
16
- message: "The Files registry has not been configured."
17
- }]
18
- };
19
4
  function useServerFiles(name) {
20
- if (!registry) throw new Error("[nuxt-files-sdk:not-configured] The Files registry has not been configured.");
21
- return name === void 0 ? registry.get() : registry.get(name);
5
+ return getFiles(name);
22
6
  }
7
+ /** Delegate a mirror operation to the native Files SDK. */
8
+ const syncFiles = (source, destination, options) => sync(typeof source === "string" ? getFiles(source) : source, typeof destination === "string" ? getFiles(destination) : destination, options);
9
+ /** Delegate a transfer operation to the native Files SDK. */
10
+ const transferFiles = (source, destination, options) => transfer(typeof source === "string" ? getFiles(source) : source, typeof destination === "string" ? getFiles(destination) : destination, options);
23
11
  //#endregion
24
- export { FilesRegistry, configureFiles, inspectFiles, useServerFiles };
12
+ export { syncFiles, transferFiles, useServerFiles };
25
13
 
26
14
  //# sourceMappingURL=runtime.js.map
@@ -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 FilesForStorage,\n FilesProviderFactories,\n FilesProviderFactory,\n FilesRuntimeHooks,\n SingleStorage,\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 single Files client supplied by generated declarations. */\nexport interface NuxtFilesSingleStorage {}\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 unnamed Files client, including its configured plugin extensions. */\nexport function useServerFiles(\n ...args: keyof NuxtFilesStorageRegistry extends never ? [] : [name: never]\n): NuxtFilesSingleStorage extends { value: infer Single } ? Single : 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): NuxtFilesStorageRegistry[Name]\nexport function useServerFiles(name?: string): 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 as (storage: string) => Files)(name)\n}\n"],"mappings":";;AAqBA,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;AAUJ,SAAgB,eAAe,MAAsB;CACjD,IAAI,CAAC,UACD,MAAM,IAAI,MAAM,6EAA6E;CAEjG,OAAO,SAAS,KAAA,IAAY,SAAS,IAAI,IAAK,SAAS,IAAmC,IAAI;AAClG"}
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import { sync, transfer, type Files, type SyncOptions, type TransferOptions } from 'files-sdk'\n\nimport { getFiles } from './runtime/internal'\n\nexport type { FilesForStorage, SingleStorage, StorageRegistry } from './runtime/registry'\n\n/** Project storage names and plugin-extended Files clients supplied by generated declarations. */\nexport interface NuxtFilesStorageRegistry {}\n/** Project single Files client supplied by generated declarations. */\nexport interface NuxtFilesSingleStorage {}\n\n/** Return the project's unnamed Files client, including its configured plugin extensions. */\nexport function useServerFiles(\n ...args: keyof NuxtFilesStorageRegistry extends never ? [] : [name: never]\n): NuxtFilesSingleStorage extends { value: infer Single } ? Single : 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): NuxtFilesStorageRegistry[Name]\nexport function useServerFiles(name?: string): Files {\n return getFiles(name)\n}\n\ntype FilesInput<Name extends string = Extract<keyof NuxtFilesStorageRegistry, string>> = Files | Name\n\n/** Delegate a mirror operation to the native Files SDK. */\nexport const syncFiles = (source: FilesInput, destination: FilesInput, options?: SyncOptions) =>\n sync(\n typeof source === 'string' ? getFiles(source) : source,\n typeof destination === 'string' ? getFiles(destination) : destination,\n options,\n )\n\n/** Delegate a transfer operation to the native Files SDK. */\nexport const transferFiles = (source: FilesInput, destination: FilesInput, options?: TransferOptions) =>\n transfer(\n typeof source === 'string' ? getFiles(source) : source,\n typeof destination === 'string' ? getFiles(destination) : destination,\n options,\n )\n"],"mappings":";;;AAmBA,SAAgB,eAAe,MAAsB;CACjD,OAAO,SAAS,IAAI;AACxB;;AAKA,MAAa,aAAa,QAAoB,aAAyB,YACnE,KACI,OAAO,WAAW,WAAW,SAAS,MAAM,IAAI,QAChD,OAAO,gBAAgB,WAAW,SAAS,WAAW,IAAI,aAC1D,OACJ;;AAGJ,MAAa,iBAAiB,QAAoB,aAAyB,YACvE,SACI,OAAO,WAAW,WAAW,SAAS,MAAM,IAAI,QAChD,OAAO,gBAAgB,WAAW,SAAS,WAAW,IAAI,aAC1D,OACJ"}