nuxt-feathers-zod 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 (95) hide show
  1. package/README.md +283 -0
  2. package/dist/module.d.mts +17 -0
  3. package/dist/module.json +12 -0
  4. package/dist/module.mjs +124 -0
  5. package/dist/runtime/adapters/ofetch.d.ts +5 -0
  6. package/dist/runtime/adapters/ofetch.js +18 -0
  7. package/dist/runtime/composables/feathers.d.ts +5 -0
  8. package/dist/runtime/composables/feathers.js +9 -0
  9. package/dist/runtime/composables/pinia.d.ts +1 -0
  10. package/dist/runtime/composables/pinia.js +11 -0
  11. package/dist/runtime/errors.d.ts +3 -0
  12. package/dist/runtime/errors.js +5 -0
  13. package/dist/runtime/options/authentication/client.d.ts +13 -0
  14. package/dist/runtime/options/authentication/client.js +12 -0
  15. package/dist/runtime/options/authentication/index.d.ts +42 -0
  16. package/dist/runtime/options/authentication/index.js +71 -0
  17. package/dist/runtime/options/authentication/jwt-types.d.ts +29 -0
  18. package/dist/runtime/options/authentication/jwt-types.js +0 -0
  19. package/dist/runtime/options/authentication/jwt.d.ts +7 -0
  20. package/dist/runtime/options/authentication/jwt.js +19 -0
  21. package/dist/runtime/options/authentication/local.d.ts +8 -0
  22. package/dist/runtime/options/authentication/local.js +8 -0
  23. package/dist/runtime/options/client/index.d.ts +14 -0
  24. package/dist/runtime/options/client/index.js +33 -0
  25. package/dist/runtime/options/client/pinia.d.ts +14 -0
  26. package/dist/runtime/options/client/pinia.js +22 -0
  27. package/dist/runtime/options/database/index.d.ts +6 -0
  28. package/dist/runtime/options/database/index.js +8 -0
  29. package/dist/runtime/options/database/mongodb.d.ts +12 -0
  30. package/dist/runtime/options/database/mongodb.js +3 -0
  31. package/dist/runtime/options/index.d.ts +44 -0
  32. package/dist/runtime/options/index.js +63 -0
  33. package/dist/runtime/options/plugins.d.ts +20 -0
  34. package/dist/runtime/options/plugins.js +69 -0
  35. package/dist/runtime/options/server.d.ts +7 -0
  36. package/dist/runtime/options/server.js +11 -0
  37. package/dist/runtime/options/services.d.ts +6 -0
  38. package/dist/runtime/options/services.js +13 -0
  39. package/dist/runtime/options/transports/index.d.ts +23 -0
  40. package/dist/runtime/options/transports/index.js +14 -0
  41. package/dist/runtime/options/transports/rest.d.ts +9 -0
  42. package/dist/runtime/options/transports/rest.js +22 -0
  43. package/dist/runtime/options/transports/utils.d.ts +1 -0
  44. package/dist/runtime/options/transports/utils.js +7 -0
  45. package/dist/runtime/options/transports/websocket.d.ts +8 -0
  46. package/dist/runtime/options/transports/websocket.js +17 -0
  47. package/dist/runtime/options/utils.d.ts +11 -0
  48. package/dist/runtime/options/utils.js +22 -0
  49. package/dist/runtime/options/validator.d.ts +13 -0
  50. package/dist/runtime/options/validator.js +29 -0
  51. package/dist/runtime/plugins/feathers-auth.d.ts +11 -0
  52. package/dist/runtime/plugins/feathers-auth.js +13 -0
  53. package/dist/runtime/server/tsconfig.json +3 -0
  54. package/dist/runtime/services.d.ts +4 -0
  55. package/dist/runtime/services.js +14 -0
  56. package/dist/runtime/stores/auth.d.ts +28 -0
  57. package/dist/runtime/stores/auth.js +47 -0
  58. package/dist/runtime/templates/client/authentication.d.ts +2 -0
  59. package/dist/runtime/templates/client/authentication.js +28 -0
  60. package/dist/runtime/templates/client/client.d.ts +2 -0
  61. package/dist/runtime/templates/client/client.js +50 -0
  62. package/dist/runtime/templates/client/connection.d.ts +3 -0
  63. package/dist/runtime/templates/client/connection.js +39 -0
  64. package/dist/runtime/templates/client/index.d.ts +4 -0
  65. package/dist/runtime/templates/client/index.js +33 -0
  66. package/dist/runtime/templates/client/plugin.d.ts +2 -0
  67. package/dist/runtime/templates/client/plugin.js +81 -0
  68. package/dist/runtime/templates/server/authentication.d.ts +2 -0
  69. package/dist/runtime/templates/server/authentication.js +32 -0
  70. package/dist/runtime/templates/server/index.d.ts +3 -0
  71. package/dist/runtime/templates/server/index.js +33 -0
  72. package/dist/runtime/templates/server/mongodb.d.ts +2 -0
  73. package/dist/runtime/templates/server/mongodb.js +26 -0
  74. package/dist/runtime/templates/server/plugin.d.ts +2 -0
  75. package/dist/runtime/templates/server/plugin.js +110 -0
  76. package/dist/runtime/templates/server/server.d.ts +2 -0
  77. package/dist/runtime/templates/server/server.js +61 -0
  78. package/dist/runtime/templates/server/validators.d.ts +2 -0
  79. package/dist/runtime/templates/server/validators.js +30 -0
  80. package/dist/runtime/templates/types.d.ts +6 -0
  81. package/dist/runtime/templates/types.js +0 -0
  82. package/dist/runtime/templates/utils.d.ts +4 -0
  83. package/dist/runtime/templates/utils.js +6 -0
  84. package/dist/runtime/zod/format.d.ts +10 -0
  85. package/dist/runtime/zod/format.js +7 -0
  86. package/dist/runtime/zod/index.d.ts +4 -0
  87. package/dist/runtime/zod/index.js +4 -0
  88. package/dist/runtime/zod/objectId.d.ts +9 -0
  89. package/dist/runtime/zod/objectId.js +17 -0
  90. package/dist/runtime/zod/query.d.ts +43 -0
  91. package/dist/runtime/zod/query.js +75 -0
  92. package/dist/runtime/zod/validators.d.ts +17 -0
  93. package/dist/runtime/zod/validators.js +46 -0
  94. package/dist/types.d.mts +7 -0
  95. package/package.json +111 -0
@@ -0,0 +1,7 @@
1
+ import type { AuthClientOptions } from './client.js';
2
+ import type { SignOptions } from './jwt-types.js';
3
+ export type AuthJwtOptions = Partial<SignOptions>;
4
+ export declare const authJwtDefaults: AuthJwtOptions;
5
+ export declare function getAuthJwtDefaults(): AuthJwtOptions;
6
+ export declare const authClientJwtDefaults: AuthClientOptions;
7
+ export declare function getAuthClientJwtDefaults(): AuthClientOptions;
@@ -0,0 +1,19 @@
1
+ import { klona } from "klona";
2
+ export const authJwtDefaults = {
3
+ header: {
4
+ alg: "HS256",
5
+ typ: "access"
6
+ },
7
+ audience: "http://localhost",
8
+ algorithm: "HS256",
9
+ expiresIn: "1d"
10
+ };
11
+ export function getAuthJwtDefaults() {
12
+ return klona(authJwtDefaults);
13
+ }
14
+ export const authClientJwtDefaults = {
15
+ storageKey: "feathers-jwt"
16
+ };
17
+ export function getAuthClientJwtDefaults() {
18
+ return klona(authClientJwtDefaults);
19
+ }
@@ -0,0 +1,8 @@
1
+ export interface AuthLocalOptions {
2
+ hashSize?: number | undefined;
3
+ usernameField?: string;
4
+ passwordField?: string;
5
+ errorMessage?: string;
6
+ }
7
+ export declare const authLocalDefaults: AuthLocalOptions;
8
+ export declare function getAuthLocalDefaults(): AuthLocalOptions;
@@ -0,0 +1,8 @@
1
+ import { klona } from "klona";
2
+ export const authLocalDefaults = {
3
+ usernameField: "userId",
4
+ passwordField: "password"
5
+ };
6
+ export function getAuthLocalDefaults() {
7
+ return klona(authLocalDefaults);
8
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModuleOptions } from '..';
2
+ import type { PluginOptions, ResolvedPluginOptions } from '../plugins.js';
3
+ import type { PiniaOptions } from './pinia.js';
4
+ export interface ClientOptions extends PluginOptions {
5
+ pinia?: PiniaOptions | boolean;
6
+ }
7
+ export interface ResolvedClientOptions extends ResolvedPluginOptions {
8
+ pinia: PiniaOptions | false;
9
+ }
10
+ export type ResolvedClientOptionsOrDisabled = ResolvedClientOptions | false;
11
+ export type ResolvedClientOnlyOptions = Omit<ResolvedClientOptions, 'pinia'>;
12
+ export declare const clientDefaults: ResolvedClientOnlyOptions;
13
+ export declare function getClientDefaults(): ResolvedClientOnlyOptions;
14
+ export declare function resolveClientOptions(client: ModuleOptions['client'], mongodb: boolean, rootDir: string, srcDir: string): Promise<ResolvedClientOptionsOrDisabled>;
@@ -0,0 +1,33 @@
1
+ import { createResolver } from "@nuxt/kit";
2
+ import defu from "defu";
3
+ import { klona } from "klona";
4
+ import { NuxtFeathersError } from "../../errors.js";
5
+ import { preparePluginOptions, resolvePluginsOptions } from "../plugins.js";
6
+ import { resolvePiniaOptions } from "./pinia.js";
7
+ export const clientDefaults = {
8
+ plugins: []
9
+ };
10
+ export function getClientDefaults() {
11
+ return klona(clientDefaults);
12
+ }
13
+ export async function resolveClientOptions(client, mongodb, rootDir, srcDir) {
14
+ if (client === false)
15
+ return false;
16
+ let clientOptions;
17
+ const clientDefaults2 = getClientDefaults();
18
+ if (client === true || client === void 0) {
19
+ clientOptions = clientDefaults2;
20
+ } else if (typeof client === "object") {
21
+ clientOptions = defu(clientDefaults2, preparePluginOptions(client));
22
+ } else {
23
+ throw new NuxtFeathersError("Invalid client options");
24
+ }
25
+ const srcResolver = createResolver(srcDir);
26
+ const resolvedPlugins = await resolvePluginsOptions(clientOptions, rootDir, srcResolver.resolve("feathers"));
27
+ const pinia = resolvePiniaOptions(clientOptions.pinia, mongodb);
28
+ const resolvedClient = {
29
+ pinia,
30
+ ...resolvedPlugins
31
+ };
32
+ return resolvedClient;
33
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModuleOptions as PiniaNuxtModuleOptions } from '@pinia/nuxt';
2
+ import type { CreatePiniaClientConfig, PiniaServiceConfig } from 'feathers-pinia';
3
+ export type PiniaModuleOptions = Pick<PiniaNuxtModuleOptions, 'storesDirs'>;
4
+ export type removableServiceOptions = 'customizeStore' | 'handleEvents' | 'setupInstance' | 'customFilters' | 'customSiftOperators';
5
+ export type SerializablePiniaServiceConfig = Omit<PiniaServiceConfig, removableServiceOptions>;
6
+ export interface SerializablePiniaClientOptions extends Partial<Omit<CreatePiniaClientConfig, 'pinia' | 'services' | 'storage' | removableServiceOptions>> {
7
+ services?: Record<string, SerializablePiniaServiceConfig>;
8
+ }
9
+ export type PiniaOptions = SerializablePiniaClientOptions & PiniaModuleOptions;
10
+ export type ResolvedPiniaOptions = Required<Pick<PiniaOptions, 'storesDirs' | 'idField'>> & Omit<PiniaOptions, 'storesDirs' | 'idField'>;
11
+ export type ResolvedPiniaOptionsOrDisabled = ResolvedPiniaOptions | false;
12
+ export declare const piniaDefaults: ResolvedPiniaOptions;
13
+ export declare function getPiniaDefaults(mongodb: boolean): ResolvedPiniaOptions;
14
+ export declare function resolvePiniaOptions(piniaOptions: PiniaOptions | boolean | undefined, mongodb: boolean): ResolvedPiniaOptionsOrDisabled;
@@ -0,0 +1,22 @@
1
+ import { klona } from "klona";
2
+ export const piniaDefaults = {
3
+ storesDirs: ["stores"],
4
+ idField: "id"
5
+ // use _id for mongoDB
6
+ };
7
+ export function getPiniaDefaults(mongodb) {
8
+ const resolvedPiniaDefaults = klona(piniaDefaults);
9
+ if (mongodb) {
10
+ resolvedPiniaDefaults.idField = "_id";
11
+ }
12
+ return resolvedPiniaDefaults;
13
+ }
14
+ export function resolvePiniaOptions(piniaOptions, mongodb) {
15
+ let pinia = false;
16
+ const piniaDefaultOptions = getPiniaDefaults(mongodb);
17
+ if (piniaOptions === true || piniaOptions === void 0)
18
+ pinia = piniaDefaultOptions;
19
+ else if (piniaOptions !== false)
20
+ pinia = { ...piniaDefaultOptions, ...piniaOptions };
21
+ return pinia;
22
+ }
@@ -0,0 +1,6 @@
1
+ import type { MongoOptions } from './mongodb.js';
2
+ export interface DataBaseOptions {
3
+ mongo?: MongoOptions;
4
+ }
5
+ export type ResolvedDataBaseOptions = DataBaseOptions;
6
+ export declare function resolveDataBaseOptions(database: DataBaseOptions): ResolvedDataBaseOptions;
@@ -0,0 +1,8 @@
1
+ import { resolveMongoOptions } from "./mongodb.js";
2
+ export function resolveDataBaseOptions(database) {
3
+ const resolvedDataBaseOptions = {};
4
+ if (database?.mongo) {
5
+ resolvedDataBaseOptions.mongo = resolveMongoOptions(database.mongo);
6
+ }
7
+ return resolvedDataBaseOptions;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { MongoClientOptions } from 'mongodb';
2
+ type PickSerializable<T> = {
3
+ [K in keyof T as NonNullable<T[K]> extends Function ? never : K]: T[K];
4
+ };
5
+ interface MongoUrlOption {
6
+ url: string;
7
+ }
8
+ type SerializableMongoClientOptions = PickSerializable<MongoClientOptions>;
9
+ export type MongoOptions = MongoUrlOption & SerializableMongoClientOptions;
10
+ export type ResolvedMongoOptions = MongoOptions;
11
+ export declare function resolveMongoOptions(mongodb: MongoOptions): ResolvedMongoOptions;
12
+ export {};
@@ -0,0 +1,3 @@
1
+ export function resolveMongoOptions(mongodb) {
2
+ return mongodb;
3
+ }
@@ -0,0 +1,44 @@
1
+ import type { Nuxt } from '@nuxt/schema';
2
+ import type { AuthOptions, PublicAuthOptions, ResolvedAuthOptions, ResolvedAuthOptionsOrDisabled } from './authentication/index.js';
3
+ import type { ClientOptions, ResolvedClientOptionsOrDisabled } from './client/index.js';
4
+ import type { PiniaOptions } from './client/pinia.js';
5
+ import type { DataBaseOptions, ResolvedDataBaseOptions } from './database/index.js';
6
+ import type { ResolvedServerOptions, ServerOptions } from './server.js';
7
+ import type { ServicesDir, ServicesDirs } from './services.js';
8
+ import type { ResolvedTransportsOptions, TransportsOptions } from './transports/index.js';
9
+ import type { ResolvedValidatorOptions, ValidatorOptions } from './validator.js';
10
+ export interface ModuleOptions {
11
+ transports: TransportsOptions;
12
+ database: DataBaseOptions;
13
+ servicesDirs: ServicesDir | ServicesDirs;
14
+ server: ServerOptions;
15
+ auth: AuthOptions | boolean;
16
+ client: ClientOptions | boolean;
17
+ validator: ValidatorOptions;
18
+ loadFeathersConfig: boolean;
19
+ }
20
+ export interface ResolvedOptions {
21
+ templateDir: string;
22
+ transports: ResolvedTransportsOptions;
23
+ database: ResolvedDataBaseOptions;
24
+ servicesDirs: ServicesDirs;
25
+ server: ResolvedServerOptions;
26
+ auth: ResolvedAuthOptionsOrDisabled;
27
+ client: ResolvedClientOptionsOrDisabled;
28
+ validator: ResolvedValidatorOptions;
29
+ loadFeathersConfig: boolean;
30
+ }
31
+ export interface FeathersRuntimeConfig {
32
+ auth?: ResolvedAuthOptions;
33
+ }
34
+ export interface FeathersPublicRuntimeConfig {
35
+ transports: ResolvedTransportsOptions;
36
+ auth?: PublicAuthOptions;
37
+ pinia?: PiniaOptions;
38
+ }
39
+ export type ModuleConfig = Partial<Omit<ModuleOptions, 'auth'> & {
40
+ auth: Omit<AuthOptions, 'entityImport'> | boolean;
41
+ }>;
42
+ export declare function resolveOptions(options: ModuleOptions, nuxt: Nuxt): Promise<ResolvedOptions>;
43
+ export declare function resolveRuntimeConfig(options: ResolvedOptions): FeathersRuntimeConfig;
44
+ export declare function resolvePublicRuntimeConfig(options: ResolvedOptions): FeathersPublicRuntimeConfig;
@@ -0,0 +1,63 @@
1
+ import { createResolver } from "@nuxt/kit";
2
+ import { getServicesImports } from "../services.js";
3
+ import { resolveAuthOptions } from "./authentication/index.js";
4
+ import { resolveClientOptions } from "./client/index.js";
5
+ import { resolveDataBaseOptions } from "./database/index.js";
6
+ import { resolveServerOptions } from "./server.js";
7
+ import { resolveServicesDirs } from "./services.js";
8
+ import { resolveTransportsOptions } from "./transports/index.js";
9
+ import { resolveValidatorOptions } from "./validator.js";
10
+ export async function resolveOptions(options, nuxt) {
11
+ const { rootDir, srcDir, serverDir, appDir, buildDir, ssr } = nuxt.options;
12
+ const resolver = createResolver(import.meta.url);
13
+ const templateDir = /node_modules/.test(buildDir) ? resolver.resolve(rootDir, ".nuxt/feathers") : resolver.resolve(buildDir, "feathers");
14
+ const transports = resolveTransportsOptions(options.transports, ssr);
15
+ const database = resolveDataBaseOptions(options.database);
16
+ const servicesDirs = resolveServicesDirs(options.servicesDirs, rootDir);
17
+ const server = await resolveServerOptions(options.server, rootDir, serverDir);
18
+ const client = await resolveClientOptions(options.client, !!database.mongo, rootDir, srcDir);
19
+ const validator = resolveValidatorOptions(options.validator);
20
+ const servicesImports = await getServicesImports(servicesDirs);
21
+ const auth = resolveAuthOptions(options.auth, !!client, servicesImports, appDir);
22
+ const loadFeathersConfig = options.loadFeathersConfig;
23
+ const resolvedOptions = {
24
+ templateDir,
25
+ transports,
26
+ database,
27
+ servicesDirs,
28
+ server,
29
+ client,
30
+ validator,
31
+ auth,
32
+ loadFeathersConfig
33
+ };
34
+ console.dir(resolvedOptions, { depth: null });
35
+ return resolvedOptions;
36
+ }
37
+ export function resolveRuntimeConfig(options) {
38
+ const runtimeConfig = {};
39
+ if (options.auth) {
40
+ runtimeConfig.auth = options.auth;
41
+ }
42
+ return runtimeConfig;
43
+ }
44
+ export function resolvePublicRuntimeConfig(options) {
45
+ const publicRuntimeConfig = {
46
+ transports: options.transports
47
+ };
48
+ const auth = options.auth;
49
+ if (auth?.client) {
50
+ publicRuntimeConfig.auth = {
51
+ authStrategies: auth.authStrategies,
52
+ servicePath: auth.service,
53
+ entityKey: auth.entity,
54
+ entityClass: auth.entityClass,
55
+ client: auth.client
56
+ };
57
+ }
58
+ const client = options.client;
59
+ if (client?.pinia) {
60
+ publicRuntimeConfig.pinia = client.pinia;
61
+ }
62
+ return publicRuntimeConfig;
63
+ }
@@ -0,0 +1,20 @@
1
+ import type { Import } from 'unimport';
2
+ import type { ModuleImport } from './utils.js';
3
+ export type PluginDir = string;
4
+ export type PluginDirs = Array<PluginDir>;
5
+ export type Plugin = string | Import;
6
+ export type Plugins = Array<Plugin>;
7
+ export type Imports = Array<Import>;
8
+ export type ResolvedPlugins = Array<ModuleImport>;
9
+ export interface PluginOptions {
10
+ pluginDirs?: PluginDir | PluginDirs;
11
+ plugins?: Plugin | Plugins;
12
+ }
13
+ export interface ResolvedPluginOptions {
14
+ plugins: ResolvedPlugins;
15
+ }
16
+ export declare function preparePluginOptions(pluginOptions: PluginOptions): PluginOptions;
17
+ export declare function resolvePluginDirs(pluginDirs: PluginDir | PluginDirs | undefined, rootDir: string, defaultDir: string): PluginDirs;
18
+ export declare function resolvePluginsFromPluginDirs(pluginDirs: PluginDirs): Promise<ResolvedPlugins>;
19
+ export declare function resolvePlugins(plugins: Plugin | Plugins | undefined, rootDir: string): Promise<ResolvedPlugins>;
20
+ export declare function resolvePluginsOptions(pluginOptions: PluginOptions, rootDir: string, defaultDir: string): Promise<ResolvedPluginOptions>;
@@ -0,0 +1,69 @@
1
+ import { createResolver } from "@nuxt/kit";
2
+ import { scanDirExports, scanExports } from "unimport";
3
+ import { filterExports, setImportsMeta } from "./utils.js";
4
+ function forceArray(value) {
5
+ if (!value)
6
+ return [];
7
+ return Array.isArray(value) ? value : [value];
8
+ }
9
+ export function preparePluginOptions(pluginOptions) {
10
+ const { pluginDirs, plugins } = pluginOptions;
11
+ return {
12
+ ...pluginOptions,
13
+ pluginDirs: forceArray(pluginDirs),
14
+ plugins: forceArray(plugins)
15
+ };
16
+ }
17
+ export function resolvePluginDirs(pluginDirs, rootDir, defaultDir) {
18
+ const rootResolver = createResolver(rootDir);
19
+ const resolvedPluginDirs = [];
20
+ if (pluginDirs && typeof pluginDirs === "string") {
21
+ resolvedPluginDirs.push(pluginDirs);
22
+ } else if (pluginDirs?.length) {
23
+ resolvedPluginDirs.push(...pluginDirs);
24
+ } else {
25
+ resolvedPluginDirs.push(defaultDir);
26
+ }
27
+ return resolvedPluginDirs.map((dir) => rootResolver.resolve(dir));
28
+ }
29
+ export async function resolvePluginsFromPluginDirs(pluginDirs) {
30
+ const imports = await scanDirExports(pluginDirs, {
31
+ filePatterns: ["*.ts"],
32
+ types: false
33
+ });
34
+ const filteredImports = imports.filter(filterExports);
35
+ const resolvedPlugins = setImportsMeta(filteredImports);
36
+ return resolvedPlugins;
37
+ }
38
+ export async function resolvePlugins(plugins, rootDir) {
39
+ if (!plugins)
40
+ return [];
41
+ const rootResolver = createResolver(rootDir);
42
+ const filteredImports = [];
43
+ for (const plugin of Array.isArray(plugins) ? plugins : [plugins]) {
44
+ if (typeof plugin === "string") {
45
+ const imports = await scanExports(rootResolver.resolve(plugin), false);
46
+ filteredImports.push(...imports.filter(filterExports));
47
+ } else {
48
+ filteredImports.push(plugin);
49
+ }
50
+ }
51
+ const resolvedPlugins = setImportsMeta(filteredImports);
52
+ return resolvedPlugins;
53
+ }
54
+ function removeDuplicates(plugins) {
55
+ return plugins.filter(
56
+ (plugin, index, self) => index === self.findIndex((p) => p.from === plugin.from)
57
+ );
58
+ }
59
+ export async function resolvePluginsOptions(pluginOptions, rootDir, defaultDir) {
60
+ const pluginDirs = resolvePluginDirs(pluginOptions.pluginDirs, rootDir, defaultDir);
61
+ const resolvedPlugins = [
62
+ ...await resolvePluginsFromPluginDirs(pluginDirs),
63
+ ...await resolvePlugins(pluginOptions.plugins, rootDir)
64
+ ];
65
+ const resolvedPluginOptions = {
66
+ plugins: removeDuplicates(resolvedPlugins)
67
+ };
68
+ return resolvedPluginOptions;
69
+ }
@@ -0,0 +1,7 @@
1
+ import type { ModuleOptions } from '.';
2
+ import type { PluginOptions, ResolvedPluginOptions } from './plugins.js';
3
+ export type ServerOptions = PluginOptions;
4
+ export type ResolvedServerOptions = ResolvedPluginOptions;
5
+ export declare const serverDefaults: ServerOptions;
6
+ export declare const serverDirDefault = "feathers";
7
+ export declare function resolveServerOptions(server: ModuleOptions['server'], rootDir: string, serverDir: string): Promise<ResolvedServerOptions>;
@@ -0,0 +1,11 @@
1
+ import { createResolver } from "@nuxt/kit";
2
+ import { resolvePluginsOptions } from "./plugins.js";
3
+ export const serverDefaults = {
4
+ pluginDirs: [],
5
+ plugins: []
6
+ };
7
+ export const serverDirDefault = "feathers";
8
+ export async function resolveServerOptions(server, rootDir, serverDir) {
9
+ const serverResolver = createResolver(serverDir);
10
+ return resolvePluginsOptions(server, rootDir, serverResolver.resolve(serverDirDefault));
11
+ }
@@ -0,0 +1,6 @@
1
+ import type { ModuleOptions } from '.';
2
+ export type ServicesDir = string;
3
+ export type ServicesDirs = Array<ServicesDir>;
4
+ export type ResolvedServicesDirs = [ServicesDir, ...ServicesDir[]];
5
+ export declare const servicesDirDefault: ServicesDir;
6
+ export declare function resolveServicesDirs(servicesDirs: ModuleOptions['servicesDirs'], rootDir: string): ResolvedServicesDirs;
@@ -0,0 +1,13 @@
1
+ import { createResolver } from "@nuxt/kit";
2
+ export const servicesDirDefault = "services";
3
+ export function resolveServicesDirs(servicesDirs, rootDir) {
4
+ const resolvedServicesDirs = [];
5
+ if (typeof servicesDirs === "string" && servicesDirs)
6
+ resolvedServicesDirs.push(servicesDirs);
7
+ if (Array.isArray(servicesDirs) && servicesDirs.find((v) => v))
8
+ resolvedServicesDirs.push(...servicesDirs.filter((v) => v));
9
+ if (!resolvedServicesDirs.length)
10
+ resolvedServicesDirs.push(servicesDirDefault);
11
+ const rootResolver = createResolver(rootDir);
12
+ return resolvedServicesDirs.map((dir) => rootResolver.resolve(dir));
13
+ }
@@ -0,0 +1,23 @@
1
+ import type { ResolvedRestOptionsOrDisabled, RestOptions } from './rest.js';
2
+ import type { ResolvedWebsocketOptionsOrDisabled, WebsocketOptions } from './websocket.js';
3
+ export interface CommonTransportOptions {
4
+ path?: string;
5
+ }
6
+ export type TransportsOptions = {
7
+ rest: RestOptions | true;
8
+ websocket?: WebsocketOptions | boolean;
9
+ } | {
10
+ rest?: RestOptions | boolean;
11
+ websocket: WebsocketOptions | true;
12
+ } | {
13
+ rest?: never;
14
+ websocket: false;
15
+ } | {
16
+ rest: false;
17
+ websocket?: never;
18
+ };
19
+ export interface ResolvedTransportsOptions {
20
+ rest: ResolvedRestOptionsOrDisabled;
21
+ websocket: ResolvedWebsocketOptionsOrDisabled;
22
+ }
23
+ export declare function resolveTransportsOptions(transports: TransportsOptions, ssr: boolean): ResolvedTransportsOptions;
@@ -0,0 +1,14 @@
1
+ import { NuxtFeathersError } from "../../errors.js";
2
+ import { resolveRestTransportsOptions } from "./rest.js";
3
+ import { resolveWebsocketTransportsOptions } from "./websocket.js";
4
+ export function resolveTransportsOptions(transports, ssr) {
5
+ const rest = resolveRestTransportsOptions(transports.rest, transports.websocket !== false, ssr);
6
+ const websocket = resolveWebsocketTransportsOptions(transports.websocket);
7
+ if (!rest && !websocket)
8
+ throw new NuxtFeathersError("No transport selected. Must be enable one of rest or websocket transport.");
9
+ const resolvedTransportsOptions = {
10
+ rest,
11
+ websocket
12
+ };
13
+ return resolvedTransportsOptions;
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { CommonTransportOptions } from '.';
2
+ export type Framework = 'koa' | 'express';
3
+ export interface RestOptions extends CommonTransportOptions {
4
+ framework?: Framework;
5
+ }
6
+ export type ResolvedRestOptions = Required<RestOptions>;
7
+ export type ResolvedRestOptionsOrDisabled = ResolvedRestOptions | false;
8
+ export declare const restDefaults: ResolvedRestOptions;
9
+ export declare function resolveRestTransportsOptions(rest: RestOptions | boolean | undefined, websocket: boolean, ssr: boolean): ResolvedRestOptionsOrDisabled;
@@ -0,0 +1,22 @@
1
+ import defu from "defu";
2
+ import { checkPath } from "./utils.js";
3
+ export const restDefaults = {
4
+ path: "/feathers",
5
+ framework: "koa"
6
+ };
7
+ function getRestDefaults(rest, websocket, ssr) {
8
+ if (rest === true || !websocket || ssr)
9
+ return restDefaults;
10
+ else
11
+ return false;
12
+ }
13
+ export function resolveRestTransportsOptions(rest, websocket, ssr) {
14
+ let resolvedRest = false;
15
+ if (rest === true || typeof rest === "undefined") {
16
+ resolvedRest = getRestDefaults(rest, websocket, ssr);
17
+ } else if (rest !== false) {
18
+ resolvedRest = defu(rest, restDefaults);
19
+ checkPath(resolvedRest.path);
20
+ }
21
+ return resolvedRest;
22
+ }
@@ -0,0 +1 @@
1
+ export declare function checkPath(path?: string): void;
@@ -0,0 +1,7 @@
1
+ import { NuxtFeathersError } from "../../errors.js";
2
+ export function checkPath(path) {
3
+ if (!path?.startsWith("/"))
4
+ throw new NuxtFeathersError(`transport path option must start with /! Current path: ${path}`);
5
+ if (!/^[\w\-/.]+$/.test(path))
6
+ throw new NuxtFeathersError(`transport path option must be a valid URL path! ${path} is not valid.`);
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { CommonTransportOptions } from '.';
2
+ export interface WebsocketOptions extends CommonTransportOptions {
3
+ connectTimeout?: number;
4
+ }
5
+ export type ResolvedWebsocketOptions = Required<WebsocketOptions>;
6
+ export type ResolvedWebsocketOptionsOrDisabled = ResolvedWebsocketOptions | false;
7
+ export declare const websocketDefaults: ResolvedWebsocketOptions;
8
+ export declare function resolveWebsocketTransportsOptions(websocket: WebsocketOptions | boolean | undefined): ResolvedWebsocketOptionsOrDisabled;
@@ -0,0 +1,17 @@
1
+ import defu from "defu";
2
+ import { checkPath } from "./utils.js";
3
+ export const websocketDefaults = {
4
+ path: "/socket.io",
5
+ connectTimeout: 45e3
6
+ // default settings for socket.io
7
+ };
8
+ export function resolveWebsocketTransportsOptions(websocket) {
9
+ let resolvedWebsocket = false;
10
+ if (websocket === true || websocket === void 0) {
11
+ resolvedWebsocket = websocketDefaults;
12
+ } else if (websocket !== false) {
13
+ resolvedWebsocket = defu(websocket, websocketDefaults);
14
+ checkPath(resolvedWebsocket.path);
15
+ }
16
+ return resolvedWebsocket;
17
+ }
@@ -0,0 +1,11 @@
1
+ import type { Import } from 'unimport';
2
+ export declare function filterExports({ name, from, as }: Import): boolean;
3
+ export interface ModuleImport extends Import {
4
+ meta: {
5
+ importId: string;
6
+ import: string;
7
+ };
8
+ }
9
+ export declare function getImportId(p: string): string;
10
+ export declare function setImportMeta(module: Import): ModuleImport;
11
+ export declare function setImportsMeta(modules: Import[]): ModuleImport[];
@@ -0,0 +1,22 @@
1
+ import path from "node:path";
2
+ import { camelCase } from "change-case";
3
+ import { hash } from "ohash";
4
+ export function filterExports({ name, from, as }) {
5
+ return name === "default" || new RegExp(`^${as}w{0,2}`).test(camelCase(path.basename(from, path.extname(from))));
6
+ }
7
+ export function getImportId(p) {
8
+ return `_${hash(p).replace(/-/g, "").slice(0, 8)}`;
9
+ }
10
+ export function setImportMeta(module) {
11
+ const importId = getImportId(module.from);
12
+ const _import = module.name === "default" ? importId : `{ ${module.as} as ${importId} }`;
13
+ const _from = module.from.replace(/.ts$/, "");
14
+ module.meta = {
15
+ importId,
16
+ import: `import ${_import} from '${_from}'`
17
+ };
18
+ return module;
19
+ }
20
+ export function setImportsMeta(modules) {
21
+ return modules.map(setImportMeta);
22
+ }
@@ -0,0 +1,13 @@
1
+ import type { FormatName } from 'ajv-formats';
2
+ import type { ModuleOptions } from '.';
3
+ export type ValidatorFormatsOptions = Array<FormatName>;
4
+ export interface ValidatorOptions {
5
+ formats: ValidatorFormatsOptions;
6
+ extendDefaults: boolean;
7
+ }
8
+ export interface ResolvedValidatorOptions {
9
+ formats: ValidatorFormatsOptions;
10
+ }
11
+ export declare const validatorFormatsDefaults: ValidatorFormatsOptions;
12
+ export declare function getValidatorDefaults(extendDefaults: boolean): ResolvedValidatorOptions;
13
+ export declare function resolveValidatorOptions(validator: ModuleOptions['validator']): ResolvedValidatorOptions;
@@ -0,0 +1,29 @@
1
+ import { klona } from "klona";
2
+ export const validatorFormatsDefaults = [
3
+ "date-time",
4
+ "time",
5
+ "date",
6
+ "email",
7
+ "hostname",
8
+ "ipv4",
9
+ "ipv6",
10
+ "uri",
11
+ "uri-reference",
12
+ "uuid",
13
+ "uri-template",
14
+ "json-pointer",
15
+ "relative-json-pointer",
16
+ "regex"
17
+ ];
18
+ export function getValidatorDefaults(extendDefaults) {
19
+ return { formats: extendDefaults ? klona(validatorFormatsDefaults) : [] };
20
+ }
21
+ export function resolveValidatorOptions(validator) {
22
+ if (!validator.formats.length)
23
+ return getValidatorDefaults(validator.extendDefaults);
24
+ const formats = validator.extendDefaults ? validator.formats.concat(validatorFormatsDefaults) : validator.formats;
25
+ const resolvedValidator = {
26
+ formats: Array.from(new Set(formats))
27
+ };
28
+ return resolvedValidator;
29
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Client-side authentication bootstrap.
3
+ *
4
+ * Why: In SSR, the Feathers client plugin may not be available yet (or may be
5
+ * intentionally disabled) and calling the auth store would throw.
6
+ *
7
+ * We only attempt to re-authenticate in the browser and only when the Feathers
8
+ * client has been injected.
9
+ */
10
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
11
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { useAuthStore } from "../stores/auth.js";
3
+ export default defineNuxtPlugin(async (nuxtApp) => {
4
+ if (import.meta.server)
5
+ return;
6
+ if (!("$api" in nuxtApp) || !nuxtApp.$api)
7
+ return;
8
+ const auth = useAuthStore();
9
+ try {
10
+ await auth.reAuthenticate();
11
+ } catch {
12
+ }
13
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../.nuxt/tsconfig.server.json"
3
+ }
@@ -0,0 +1,4 @@
1
+ import type { Import } from 'unimport';
2
+ import type { ServicesDirs } from './options/services.js';
3
+ export declare function getServicesImports(servicesDirs: ServicesDirs): Promise<Import[]>;
4
+ export declare function addServicesImports(imports: Import[]): Promise<void>;