@holo-js/adapter-nuxt 0.1.2 → 0.1.4

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/module.d.mts CHANGED
@@ -1,8 +1,34 @@
1
1
  import { LoadedHoloConfig, HoloConfigMap } from '@holo-js/config';
2
- import { ModuleOptions as ModuleOptions$1 } from '@holo-js/storage';
3
2
 
4
3
  type ModuleOptions = Record<string, never>;
5
- declare function toStorageModuleOptions(loaded: LoadedHoloConfig<HoloConfigMap>): ModuleOptions$1;
4
+ type StorageDriver = 'local' | 'public' | 's3';
5
+ type StorageVisibility = 'private' | 'public';
6
+ type StorageDiskConfig = {
7
+ driver: StorageDriver;
8
+ visibility?: StorageVisibility;
9
+ root?: string;
10
+ url?: string;
11
+ bucket?: string;
12
+ region?: string;
13
+ endpoint?: string;
14
+ accessKeyId?: string;
15
+ secretAccessKey?: string;
16
+ sessionToken?: string;
17
+ forcePathStyleEndpoint?: boolean;
18
+ [key: string]: unknown;
19
+ };
20
+ type StorageModuleOptions = {
21
+ defaultDisk?: string;
22
+ routePrefix?: string;
23
+ disks?: Record<string, StorageDiskConfig>;
24
+ };
25
+ type StorageS3Module = {
26
+ default: unknown;
27
+ };
28
+ declare function hasModuleNotFoundCode(error: unknown, expectedSpecifier: string): boolean;
29
+ declare function importOptionalStorageS3Module(): Promise<StorageS3Module | undefined>;
30
+ declare function hasLoadedConfigFile(loaded: LoadedHoloConfig<HoloConfigMap>, configName: string): boolean;
31
+ declare function toStorageModuleOptions(loaded: LoadedHoloConfig<HoloConfigMap>): StorageModuleOptions;
6
32
  declare const _default: {
7
33
  meta?: {
8
34
  name?: string;
@@ -11,9 +37,14 @@ declare const _default: {
11
37
  setup: (options: ModuleOptions, nuxt: unknown) => void | Promise<void>;
12
38
  };
13
39
 
40
+ declare const moduleInternals: {
41
+ hasModuleNotFoundCode: typeof hasModuleNotFoundCode;
42
+ hasLoadedConfigFile: typeof hasLoadedConfigFile;
43
+ importOptionalStorageS3Module: typeof importOptionalStorageS3Module;
44
+ };
14
45
  declare const adapterNuxtInternals: {
15
46
  toStorageModuleOptions: typeof toStorageModuleOptions;
16
47
  };
17
48
 
18
- export { adapterNuxtInternals, _default as default };
49
+ export { adapterNuxtInternals, _default as default, moduleInternals };
19
50
  export type { ModuleOptions };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@holo-js/adapter-nuxt",
3
3
  "configKey": "@holo-js/adapter-nuxt",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,8 +1,60 @@
1
- import { resolve } from 'node:path';
1
+ import { readdir, mkdir, writeFile } from 'node:fs/promises';
2
+ import { resolve, extname, basename, relative } from 'node:path';
2
3
  import { defineNuxtModule, createResolver, addServerPlugin, addImports, addServerImportsDir, addServerHandler } from '@nuxt/kit';
3
4
  import { loadConfigDirectory } from '@holo-js/config';
4
- import { mergeModuleOptions, normalizeModuleOptions, applyNitroStorageConfig, hasPublicLocalDisk } from '@holo-js/storage';
5
5
 
6
+ const MODEL_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"]);
7
+ function escapeRegExp(value) {
8
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
+ }
10
+ function hasModuleNotFoundCode(error, expectedSpecifier) {
11
+ if (!error || typeof error !== "object") {
12
+ return false;
13
+ }
14
+ if ("code" in error && error.code === "ERR_MODULE_NOT_FOUND") {
15
+ const message = "message" in error && typeof error.message === "string" ? error.message : "";
16
+ const escapedSpecifier = escapeRegExp(expectedSpecifier);
17
+ if ([
18
+ new RegExp(`Cannot find package ['"]${escapedSpecifier}['"]`),
19
+ new RegExp(`Cannot find module ['"]${escapedSpecifier}['"]`),
20
+ new RegExp(`Could not resolve ['"]${escapedSpecifier}['"]`),
21
+ new RegExp(`Failed to load url\\s+(?:['"\`]${escapedSpecifier}['"\`]|${escapedSpecifier}(?=[\\s(]|$))`)
22
+ ].some((pattern) => pattern.test(message))) {
23
+ return true;
24
+ }
25
+ }
26
+ if ("cause" in error) {
27
+ return hasModuleNotFoundCode(error.cause, expectedSpecifier);
28
+ }
29
+ return false;
30
+ }
31
+ async function importOptionalStorageModule() {
32
+ try {
33
+ return await import('@holo-js/storage');
34
+ } catch (error) {
35
+ if (hasModuleNotFoundCode(error, "@holo-js/storage")) {
36
+ return void 0;
37
+ }
38
+ throw error;
39
+ }
40
+ }
41
+ async function importOptionalStorageS3Module() {
42
+ try {
43
+ const storageS3 = await import('@holo-js/storage-s3');
44
+ return typeof storageS3.default === "undefined" ? void 0 : storageS3;
45
+ } catch (error) {
46
+ if (hasModuleNotFoundCode(error, "@holo-js/storage-s3")) {
47
+ return void 0;
48
+ }
49
+ throw error;
50
+ }
51
+ }
52
+ function hasLoadedConfigFile(loaded, configName) {
53
+ return loaded.loadedFiles.some((filePath) => {
54
+ const normalizedPath = filePath.replaceAll("\\", "/");
55
+ return normalizedPath.endsWith(`/config/${configName}.ts`) || normalizedPath.endsWith(`/config/${configName}.mts`) || normalizedPath.endsWith(`/config/${configName}.js`) || normalizedPath.endsWith(`/config/${configName}.mjs`) || normalizedPath.endsWith(`/config/${configName}.cts`) || normalizedPath.endsWith(`/config/${configName}.cjs`);
56
+ });
57
+ }
6
58
  function toStorageModuleOptions(loaded) {
7
59
  return {
8
60
  defaultDisk: loaded.storage.defaultDisk,
@@ -10,6 +62,31 @@ function toStorageModuleOptions(loaded) {
10
62
  disks: { ...loaded.storage.disks }
11
63
  };
12
64
  }
65
+ async function createServerModelImports(sourceDir) {
66
+ const modelsDir = resolve(sourceDir, "server/models");
67
+ const modelImportDir = resolve(sourceDir, ".holo-js/generated/nuxt-server-imports");
68
+ const modelImportFile = resolve(modelImportDir, "models.ts");
69
+ let modelFiles;
70
+ try {
71
+ modelFiles = (await readdir(modelsDir)).filter((fileName) => MODEL_FILE_EXTENSIONS.has(extname(fileName))).sort((left, right) => left.localeCompare(right));
72
+ } catch {
73
+ return null;
74
+ }
75
+ if (modelFiles.length === 0) {
76
+ return null;
77
+ }
78
+ const lines = modelFiles.map((fileName) => {
79
+ const modelName = basename(fileName, extname(fileName));
80
+ const importPath = relative(modelImportDir, resolve(modelsDir, fileName)).replaceAll("\\", "/");
81
+ const normalizedImportPath = importPath.replace(/^(?!\.)/, "./");
82
+ const extension = extname(normalizedImportPath);
83
+ return `export { default as ${modelName} } from '${normalizedImportPath.slice(0, -extension.length)}'`;
84
+ });
85
+ await mkdir(modelImportDir, { recursive: true });
86
+ await writeFile(modelImportFile, `${lines.join("\n")}
87
+ `, "utf8");
88
+ return modelImportDir;
89
+ }
13
90
  const module$1 = defineNuxtModule({
14
91
  meta: {
15
92
  name: "@holo-js/adapter-nuxt"
@@ -24,6 +101,7 @@ const module$1 = defineNuxtModule({
24
101
  preferCache: process.env.NODE_ENV === "production",
25
102
  processEnv: process.env
26
103
  });
104
+ const storageModule = await importOptionalStorageModule();
27
105
  const loadedStorageOptions = toStorageModuleOptions(loaded);
28
106
  const s3Driver = resolver.resolve("./runtime/drivers/s3.js");
29
107
  opts.nitro = opts.nitro || { storage: {} };
@@ -36,43 +114,62 @@ const module$1 = defineNuxtModule({
36
114
  projectRoot: rootDir
37
115
  };
38
116
  opts.runtimeConfig.db = loaded.database;
39
- const mergedStorageOptions = mergeModuleOptions(void 0, loadedStorageOptions);
40
- const normalizedStorage = normalizeModuleOptions(mergedStorageOptions);
117
+ const storageConfigured = hasLoadedConfigFile(loaded, "storage");
118
+ if (!storageModule && storageConfigured) {
119
+ throw new Error("[@holo-js/adapter-nuxt] Storage config requires @holo-js/storage to be installed.");
120
+ }
121
+ const mergedStorageOptions = storageModule?.mergeModuleOptions(void 0, loadedStorageOptions);
122
+ const normalizedStorage = mergedStorageOptions ? storageModule?.normalizeModuleOptions(mergedStorageOptions) : void 0;
41
123
  opts._holoStorageModuleOptions = mergedStorageOptions;
42
- opts.runtimeConfig.holoStorage = normalizedStorage;
124
+ if (normalizedStorage && Object.values(normalizedStorage.disks).some((disk) => disk.driver === "s3")) {
125
+ if (!await importOptionalStorageS3Module()) {
126
+ throw new Error("[@holo-js/adapter-nuxt] S3 storage disks require @holo-js/storage-s3 to be installed.");
127
+ }
128
+ }
129
+ if (normalizedStorage) {
130
+ opts.runtimeConfig.holoStorage = normalizedStorage;
131
+ }
43
132
  if (!opts._holoCoreRuntimeRegistered) {
44
- addServerPlugin(resolver.resolve("./runtime/plugins/init"));
45
- addImports([
133
+ const imports = [
46
134
  { name: "holo", as: "holo", from: resolver.resolve("./runtime/composables") },
47
135
  { name: "useHoloDb", as: "useHoloDb", from: resolver.resolve("./runtime/composables") },
48
136
  { name: "useHoloEnv", as: "useHoloEnv", from: resolver.resolve("./runtime/composables") },
49
- { name: "useHoloDebug", as: "useHoloDebug", from: resolver.resolve("./runtime/composables") },
50
- { name: "useStorage", as: "useStorage", from: resolver.resolve("./runtime/composables") },
51
- { name: "Storage", as: "Storage", from: resolver.resolve("./runtime/composables") }
52
- ]);
137
+ { name: "useHoloDebug", as: "useHoloDebug", from: resolver.resolve("./runtime/composables") }
138
+ ];
139
+ if (storageModule) {
140
+ imports.push(
141
+ { name: "useStorage", as: "useStorage", from: resolver.resolve("./runtime/composables/storage") },
142
+ { name: "Storage", as: "Storage", from: resolver.resolve("./runtime/composables/storage") }
143
+ );
144
+ }
145
+ addServerPlugin(resolver.resolve("./runtime/plugins/init"));
146
+ addImports(imports);
53
147
  addServerImportsDir(resolver.resolve("./runtime/server/imports"));
54
- addServerImportsDir(resolve(sourceDir, "server/models"));
148
+ const serverModelImports = await createServerModelImports(sourceDir);
149
+ if (serverModelImports) {
150
+ addServerImportsDir(serverModelImports);
151
+ }
55
152
  opts._holoCoreRuntimeRegistered = true;
56
153
  }
57
- if (!opts._holoStorageRuntimeRegistered) {
154
+ if (storageModule && !opts._holoStorageRuntimeRegistered) {
58
155
  addServerPlugin(resolver.resolve("./runtime/plugins/storage"));
59
156
  opts._holoStorageRuntimeRegistered = true;
60
157
  }
61
- if (!opts.nitro.storage || Object.keys(opts.nitro.storage).every((key) => !key.startsWith("holo:"))) {
62
- applyNitroStorageConfig(opts, normalizedStorage, s3Driver);
158
+ if (storageModule && normalizedStorage && (!opts.nitro.storage || Object.keys(opts.nitro.storage).every((key) => !key.startsWith("holo:")))) {
159
+ storageModule.applyNitroStorageConfig(opts, normalizedStorage, s3Driver);
63
160
  }
64
161
  const runtimePath = resolver.resolve("./runtime");
65
162
  if (!opts.build.transpile.includes(runtimePath)) {
66
163
  opts.build.transpile.push(runtimePath);
67
164
  }
68
- if (!opts._holoStorageFinalizeRegistered) {
165
+ if (storageModule && !opts._holoStorageFinalizeRegistered) {
69
166
  opts._holoStorageFinalizeRegistered = true;
70
167
  nuxt.hook("modules:done", () => {
71
- const finalNormalized = normalizeModuleOptions(opts._holoStorageModuleOptions);
168
+ const finalNormalized = storageModule.normalizeModuleOptions(opts._holoStorageModuleOptions);
72
169
  opts.runtimeConfig = opts.runtimeConfig || {};
73
170
  opts.runtimeConfig.holoStorage = finalNormalized;
74
- applyNitroStorageConfig(opts, finalNormalized, s3Driver);
75
- if (hasPublicLocalDisk(finalNormalized)) {
171
+ storageModule.applyNitroStorageConfig(opts, finalNormalized, s3Driver);
172
+ if (storageModule.hasPublicLocalDisk(finalNormalized)) {
76
173
  addServerHandler({
77
174
  route: `${finalNormalized.routePrefix}/**`,
78
175
  handler: resolver.resolve("./runtime/server/routes/storage.get")
@@ -88,8 +185,13 @@ const module$1 = defineNuxtModule({
88
185
  }
89
186
  }
90
187
  });
188
+ const moduleInternals = {
189
+ hasModuleNotFoundCode,
190
+ hasLoadedConfigFile,
191
+ importOptionalStorageS3Module
192
+ };
91
193
  const adapterNuxtInternals = {
92
194
  toStorageModuleOptions
93
195
  };
94
196
 
95
- export { adapterNuxtInternals, module$1 as default };
197
+ export { adapterNuxtInternals, module$1 as default, moduleInternals };
@@ -1,16 +1,3 @@
1
- export {
2
- Storage,
3
- configureStorageRuntime,
4
- resetStorageRuntime,
5
- useStorage,
6
- type StorageBackend,
7
- type StorageContent,
8
- type StorageDisk,
9
- type StorageInstance,
10
- type StorageRuntimeBindings,
11
- type TemporaryUrlOptions,
12
- } from '@holo-js/storage/runtime'
13
-
14
1
  export interface HoloRuntimeConnection {
15
2
  driver?: 'sqlite' | 'postgres' | 'mysql'
16
3
  url?: string
@@ -1,9 +1,3 @@
1
- export {
2
- Storage,
3
- configureStorageRuntime,
4
- resetStorageRuntime,
5
- useStorage
6
- } from "@holo-js/storage/runtime";
7
1
  import {
8
2
  createHoloProjectAccessors,
9
3
  initializeHoloAdapterProject
@@ -0,0 +1,12 @@
1
+ export {
2
+ Storage,
3
+ configureStorageRuntime,
4
+ resetStorageRuntime,
5
+ useStorage,
6
+ type StorageBackend,
7
+ type StorageContent,
8
+ type StorageDisk,
9
+ type StorageInstance,
10
+ type StorageRuntimeBindings,
11
+ type TemporaryUrlOptions,
12
+ } from '@holo-js/storage/runtime'
@@ -0,0 +1,6 @@
1
+ export {
2
+ Storage,
3
+ configureStorageRuntime,
4
+ resetStorageRuntime,
5
+ useStorage
6
+ } from "@holo-js/storage/runtime";
@@ -1 +1 @@
1
- export { default } from "@holo-js/storage/runtime/drivers/s3";
1
+ export { default } from "@holo-js/storage-s3";
@@ -2,6 +2,8 @@ import {
2
2
  configureHoloRuntimeConfig
3
3
  } from "../composables/index.js";
4
4
  import { initializeHoloAdapterProject } from "@holo-js/core";
5
+ import { useRuntimeConfig } from "nitropack/runtime/config";
6
+ import { defineNitroPlugin } from "nitropack/runtime/plugin";
5
7
  export default defineNitroPlugin(async (nitroApp) => {
6
8
  const config = useRuntimeConfig();
7
9
  configureHoloRuntimeConfig(config);
@@ -1,5 +1,7 @@
1
1
  import { configureStorageRuntime } from "@holo-js/storage/runtime";
2
- import { useRuntimeConfig, useStorage as useNitroStorage } from "#imports";
2
+ import { useRuntimeConfig } from "nitropack/runtime/config";
3
+ import { defineNitroPlugin } from "nitropack/runtime/plugin";
4
+ import { useStorage as useNitroStorage } from "nitropack/runtime/storage";
3
5
  export default defineNitroPlugin(() => {
4
6
  configureStorageRuntime({
5
7
  getRuntimeConfig: () => useRuntimeConfig(),
@@ -43,6 +43,18 @@ declare module '#imports' {
43
43
  export function useStorage(base: string): unknown
44
44
  }
45
45
 
46
+ declare module 'nitropack/runtime/config' {
47
+ export function useRuntimeConfig(): HoloRuntimeConfig
48
+ }
49
+
50
+ declare module 'nitropack/runtime/plugin' {
51
+ export function defineNitroPlugin<T>(plugin: T): T
52
+ }
53
+
54
+ declare module 'nitropack/runtime/storage' {
55
+ export function useStorage(base: string): unknown
56
+ }
57
+
46
58
  declare global {
47
59
  function createError(input: { statusCode: number, statusMessage: string }): Error
48
60
  function defineNitroPlugin<T>(plugin: T): T
package/dist/types.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- export { type adapterNuxtInternals, default } from './module.mjs'
1
+ export { type adapterNuxtInternals, default, type moduleInternals } from './module.mjs'
2
2
 
3
3
  export { type ModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/adapter-nuxt",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Holo-JS Framework - Nuxt adapter",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,6 +16,10 @@
16
16
  "./runtime": {
17
17
  "types": "./dist/runtime/composables/index.d.ts",
18
18
  "import": "./dist/runtime/composables/index.js"
19
+ },
20
+ "./storage": {
21
+ "types": "./dist/runtime/composables/storage.d.ts",
22
+ "import": "./dist/runtime/composables/storage.js"
19
23
  }
20
24
  },
21
25
  "main": "./dist/module.mjs",
@@ -31,13 +35,28 @@
31
35
  },
32
36
  "dependencies": {
33
37
  "@nuxt/kit": "^4.0.0",
34
- "@holo-js/config": "^0.1.2",
35
- "@holo-js/core": "^0.1.2",
36
- "@holo-js/db": "^0.1.2",
37
- "@holo-js/forms": "^0.1.2",
38
- "@holo-js/storage": "^0.1.2"
38
+ "@holo-js/config": "^0.1.4",
39
+ "@holo-js/core": "^0.1.4",
40
+ "@holo-js/db": "^0.1.4"
41
+ },
42
+ "peerDependencies": {
43
+ "@holo-js/forms": "^0.1.4",
44
+ "@holo-js/storage": "^0.1.4",
45
+ "@holo-js/storage-s3": "^0.1.4"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@holo-js/forms": {
49
+ "optional": true
50
+ },
51
+ "@holo-js/storage": {
52
+ "optional": true
53
+ },
54
+ "@holo-js/storage-s3": {
55
+ "optional": true
56
+ }
39
57
  },
40
58
  "devDependencies": {
59
+ "@holo-js/storage-s3": "workspace:*",
41
60
  "@nuxt/module-builder": "^1.0.2",
42
61
  "@types/node": "^22.10.2",
43
62
  "nuxt": "^4.0.0",