@proventuslabs/nestjs-zod 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -306,13 +306,20 @@ Builder class for creating configurable modules with Zod validation.
306
306
  ```typescript
307
307
  class ZodConfigurableModuleBuilder<
308
308
  ModuleOptions,
309
- ModuleOptionsInput = unknown,
309
+ ModuleOptionsInput,
310
310
  StaticMethodKey extends string = string,
311
311
  FactoryClassMethodKey extends string = string,
312
312
  ExtraModuleDefinitionOptions = object
313
313
  >
314
314
  ```
315
315
 
316
+ ```typescript
317
+ export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, OPTIONS_INPUT_TYPE } =
318
+ new ZodConfigurableModuleBuilder(z.object({ timeout: z.number().default(100) }))
319
+ ```
320
+
321
+ Offers identical API to the standard NestJS `ConfigurableModuleBuilder`, consult [their docs](https://docs.nestjs.com/fundamentals/dynamic-modules#configurable-module-builder) for usage.
322
+
316
323
  ## Error Handling
317
324
 
318
325
  The package provides enhanced error messages that include:
@@ -1,75 +1,62 @@
1
- import { type ConfigurableModuleAsyncOptions, ConfigurableModuleBuilder, type ConfigurableModuleBuilderOptions, type DynamicModule } from "@nestjs/common";
2
- import type { DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from "@nestjs/common/module-utils/constants";
1
+ import { type ConfigurableModuleBuilderOptions, type DynamicModule, Logger } from "@nestjs/common";
2
+ import { DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from "@nestjs/common/module-utils/constants";
3
3
  import { type ZodType, type ZodTypeDef } from "zod";
4
- export declare class ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput = unknown, StaticMethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = object> {
4
+ import type { ZodConfigurableModuleHost } from "./module.interfaces";
5
+ export declare class ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = object> {
5
6
  protected readonly schema: ZodType<ModuleOptions, ZodTypeDef, ModuleOptionsInput>;
6
7
  protected readonly options: ConfigurableModuleBuilderOptions;
7
- protected base: ConfigurableModuleBuilder<ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
8
- private transformSet;
9
- constructor(schema: ZodType<ModuleOptions, ZodTypeDef, ModuleOptionsInput>, options?: ConfigurableModuleBuilderOptions, parentBuilder?: ConfigurableModuleBuilder<ModuleOptionsInput>);
10
- setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition?: (definition: DynamicModule, extras: ExtraModuleDefinitionOptions) => DynamicModule): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
11
- private patchTransform;
12
- setClassMethodName<StaticMethodKey extends string>(key: StaticMethodKey): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
13
- setFactoryMethodName<FactoryClassMethodKey extends string>(key: FactoryClassMethodKey): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
14
- build(): ZodConfigurableModuleHost<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
15
- private transformModuleDefinitionWithSchema;
16
- }
17
- type ZodConfigurableModuleCls<ModuleOptions, ModuleOptionsInput = unknown, MethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = object> = {
18
- new (): any;
19
- } & Record<`${MethodKey}`, (options: ModuleOptionsInput & Partial<ExtraModuleDefinitionOptions>) => DynamicModule> & Record<`${MethodKey}Async`, (options: ConfigurableModuleAsyncOptions<ModuleOptionsInput, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>) => DynamicModule>;
20
- interface ZodConfigurableModuleHost<ModuleOptions = Record<string, unknown>, ModuleOptionsInput = unknown, MethodKey extends string = string, FactoryClassMethodKey extends string = string, ExtraModuleDefinitionOptions = object> {
8
+ protected staticMethodKey: StaticMethodKey;
9
+ protected factoryClassMethodKey: FactoryClassMethodKey;
10
+ protected extras: ExtraModuleDefinitionOptions;
11
+ protected transformModuleDefinition: (definition: DynamicModule, extraOptions: ExtraModuleDefinitionOptions) => DynamicModule;
12
+ protected readonly logger: Logger;
13
+ constructor(schema: ZodType<ModuleOptions, ZodTypeDef, ModuleOptionsInput>, options?: ConfigurableModuleBuilderOptions, parentBuilder?: ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput>);
21
14
  /**
22
- * Class that represents a blueprint/prototype for a configurable Nest module.
23
- * This class provides static methods for constructing dynamic modules. Their names
24
- * can be controlled through the "MethodKey" type argument.
15
+ * Registers the "extras" object (a set of extra options that can be used to modify the dynamic module definition).
16
+ * Values you specify within the "extras" object will be used as default values (that can be overridden by module consumers).
25
17
  *
26
- * Your module class should inherit from this class to make the static methods available.
18
+ * This method also applies the so-called "module definition transform function" that takes the auto-generated
19
+ * dynamic module object ("DynamicModule") and the actual consumer "extras" object as input parameters.
20
+ * The "extras" object consists of values explicitly specified by module consumers and default values.
27
21
  *
28
22
  * @example
29
23
  * ```typescript
30
- * @Module({})
31
- * class IntegrationModule extends ConfigurableModuleCls {
32
- * // ...
33
- * }
24
+ * .setExtras<{ isGlobal?: boolean }>({ isGlobal: false }, (definition, extras) =>
25
+ * ({ ...definition, global: extras.isGlobal })
26
+ * )
34
27
  * ```
35
28
  */
36
- ConfigurableModuleClass: ZodConfigurableModuleCls<ModuleOptions, ModuleOptionsInput, MethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
37
- /**
38
- * Module options provider token. Can be used to inject the "options object" to
39
- * providers registered within the host module.
40
- */
41
- MODULE_OPTIONS_TOKEN: string | symbol;
29
+ setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition?: (definition: DynamicModule, extras: ExtraModuleDefinitionOptions) => DynamicModule): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
42
30
  /**
43
- * Can be used to auto-infer the compound "async module options" type.
44
- * Note: this property is not supposed to be used as a value.
31
+ * Dynamic modules must expose public static methods that let you pass in
32
+ * configuration parameters (control the module's behavior from the outside).
33
+ * Some frequently used names that you may have seen in other modules are:
34
+ * "forRoot", "forFeature", "register", "configure".
45
35
  *
46
- * @example
47
- * ```typescript
48
- * @Module({})
49
- * class IntegrationModule extends ConfigurableModuleCls {
50
- * static module = initializer(IntegrationModule);
36
+ * This method "setClassMethodName" lets you specify the name of the
37
+ * method that will be auto-generated.
51
38
  *
52
- * static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {
53
- * return super.registerAsync(options);
54
- * }
55
- * ```
39
+ * @param key name of the method
56
40
  */
57
- OPTIONS_TYPE: ModuleOptions & Partial<ExtraModuleDefinitionOptions>;
41
+ setClassMethodName<StaticMethodKey extends string>(key: StaticMethodKey): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
58
42
  /**
59
- * Can be used to auto-infer the compound "module options" type (options interface + extra module definition options).
60
- * Note: this property is not supposed to be used as a value.
43
+ * Asynchronously configured modules (that rely on other modules, i.e. "ConfigModule")
44
+ * let you pass the configuration factory class that will be registered and instantiated as a provider.
45
+ * This provider then will be used to retrieve the module's configuration. To provide the configuration,
46
+ * the corresponding factory method must be implemented.
61
47
  *
62
- * @example
63
- * ```typescript
64
- * @Module({})
65
- * class IntegrationModule extends ConfigurableModuleCls {
66
- * static module = initializer(IntegrationModule);
48
+ * This method ("setFactoryMethodName") lets you control what method name will have to be
49
+ * implemented by the config factory (default is "create").
67
50
  *
68
- * static register(options: typeof OPTIONS_TYPE): DynamicModule {
69
- * return super.register(options);
70
- * }
71
- * ```
51
+ * @param key name of the method
72
52
  */
73
- ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>;
53
+ setFactoryMethodName<FactoryClassMethodKey extends string>(key: FactoryClassMethodKey): ZodConfigurableModuleBuilder<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
54
+ /**
55
+ * Returns an object consisting of multiple properties that lets you
56
+ * easily construct dynamic configurable modules. See "ConfigurableModuleHost" interface for more details.
57
+ */
58
+ build(): ZodConfigurableModuleHost<ModuleOptions, ModuleOptionsInput, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
59
+ private constructInjectionTokenString;
60
+ private createConfigurableModuleCls;
61
+ private createTypeProxy;
74
62
  }
75
- export {};
@@ -0,0 +1,97 @@
1
+ import type { ConfigurableModuleAsyncOptions, DynamicModule } from "@nestjs/common";
2
+ import type { DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from "@nestjs/common/module-utils/constants";
3
+ /**
4
+ * Class that represents a blueprint/prototype for a configurable Nest module.
5
+ * This class provides static methods for constructing dynamic modules. Their names
6
+ * can be controlled through the "MethodKey" type argument.
7
+ *
8
+ * @publicApi
9
+ */
10
+ export type ZodConfigurableModuleCls<ModuleOptions, ModuleOptionsInput, MethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = {}> = {
11
+ new (): any;
12
+ } & Record<`${MethodKey}`, (options: ModuleOptionsInput & Partial<ExtraModuleDefinitionOptions>) => DynamicModule> & Record<`${MethodKey}Async`, (options: ConfigurableModuleAsyncOptions<ModuleOptionsInput, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>) => DynamicModule>;
13
+ /**
14
+ * Configurable module host. See properties for more details
15
+ *
16
+ * @publicApi
17
+ */
18
+ export interface ZodConfigurableModuleHost<ModuleOptions = Record<string, unknown>, ModuleOptionsInput = Record<string, unknown>, MethodKey extends string = string, FactoryClassMethodKey extends string = string, ExtraModuleDefinitionOptions = {}> {
19
+ /**
20
+ * Class that represents a blueprint/prototype for a configurable Nest module.
21
+ * This class provides static methods for constructing dynamic modules. Their names
22
+ * can be controlled through the "MethodKey" type argument.
23
+ *
24
+ * Your module class should inherit from this class to make the static methods available.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * @Module({})
29
+ * class IntegrationModule extends ConfigurableModuleCls {
30
+ * // ...
31
+ * }
32
+ * ```
33
+ */
34
+ ConfigurableModuleClass: ZodConfigurableModuleCls<ModuleOptions, ModuleOptionsInput, MethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
35
+ /**
36
+ * Module options provider token. Can be used to inject the "options object" to
37
+ * providers registered within the host module.
38
+ */
39
+ MODULE_OPTIONS_TOKEN: string | symbol;
40
+ /**
41
+ * @deprecated Use {@link ASYNC_OPTIONS_INPUT_TYPE} instead.
42
+ */
43
+ ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey>;
44
+ /**
45
+ * Can be used to auto-infer the compound "async module options" input type.
46
+ * This is the equivalent of `z.input<OPTIONS SCHEMA>` + the extra module definition options.
47
+ * Note: this property is not supposed to be used as a value.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * @Module({})
52
+ * class IntegrationModule extends ConfigurableModuleCls {
53
+ * static module = initializer(IntegrationModule);
54
+ *
55
+ * static registerAsync(options: typeof ASYNC_OPTIONS_INPUT_TYPE): DynamicModule {
56
+ * return super.registerAsync(options);
57
+ * }
58
+ * ```
59
+ */
60
+ ASYNC_OPTIONS_INPUT_TYPE: ConfigurableModuleAsyncOptions<ModuleOptionsInput, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>;
61
+ /**
62
+ * Can be used to auto-infer the "module options" output type.
63
+ * This is the equivalent of `z.input<OPTIONS SCHEMA>`.
64
+ * Note: this property is not supposed to be used as a value.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * export class MyService {
69
+ * constructor(
70
+ * @Inject(MyModule.MODULE_OPTIONS_TOKEN)
71
+ * private readonly options: typeof OPTIONS_TYPE,
72
+ * ) {}
73
+ * }
74
+ *
75
+ * // Or in bootstrap code:
76
+ * const options = app.get<typeof OPTIONS_TYPE>(MyModule.MODULE_OPTIONS_TOKEN);
77
+ * ```
78
+ */
79
+ OPTIONS_TYPE: ModuleOptions;
80
+ /**
81
+ * Can be used to auto-infer the **compound** "module options" input type.
82
+ * This is the equivalent of `z.input<OPTIONS SCHEMA>` + the extra module definition options.
83
+ * Note: this property is not supposed to be used as a value.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * @Module({})
88
+ * class IntegrationModule extends ConfigurableModuleCls {
89
+ * static module = initializer(IntegrationModule);
90
+ *
91
+ * static register(options: typeof OPTIONS_INPUT_TYPE): DynamicModule {
92
+ * return super.register(options);
93
+ * }
94
+ * ```
95
+ */
96
+ OPTIONS_INPUT_TYPE: ModuleOptionsInput & Partial<ExtraModuleDefinitionOptions>;
97
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=module.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.interfaces.js","sourceRoot":"","sources":["../../src/module/module.interfaces.ts"],"names":[],"mappings":""}
@@ -1,93 +1,246 @@
1
1
  "use strict";
2
+ // biome-ignore-all lint/complexity/noThisInStatic: NestJS monkey types compat
3
+ // biome-ignore-all lint/style/noNonNullAssertion: NestJS monkey types compat
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
5
  exports.ZodConfigurableModuleBuilder = void 0;
4
6
  const common_1 = require("@nestjs/common");
5
- const lodash_1 = require("lodash");
7
+ const constants_1 = require("@nestjs/common/module-utils/constants");
6
8
  const zod_1 = require("zod");
7
9
  const internal_1 = require("../internal");
10
+ const utils_1 = require("./utils");
8
11
  class ZodConfigurableModuleBuilder {
9
12
  schema;
10
13
  options;
11
- base;
12
- transformSet = false;
14
+ staticMethodKey;
15
+ factoryClassMethodKey;
16
+ extras;
17
+ transformModuleDefinition;
18
+ logger = new common_1.Logger(ZodConfigurableModuleBuilder.name);
13
19
  constructor(schema, options = {}, parentBuilder) {
14
20
  this.schema = schema;
15
21
  this.options = options;
16
- this.base = new common_1.ConfigurableModuleBuilder(options, parentBuilder);
22
+ if (parentBuilder) {
23
+ this.staticMethodKey = parentBuilder.staticMethodKey;
24
+ this.factoryClassMethodKey = parentBuilder.factoryClassMethodKey;
25
+ this.transformModuleDefinition = parentBuilder.transformModuleDefinition;
26
+ this.extras = parentBuilder.extras;
27
+ }
17
28
  }
29
+ /**
30
+ * Registers the "extras" object (a set of extra options that can be used to modify the dynamic module definition).
31
+ * Values you specify within the "extras" object will be used as default values (that can be overridden by module consumers).
32
+ *
33
+ * This method also applies the so-called "module definition transform function" that takes the auto-generated
34
+ * dynamic module object ("DynamicModule") and the actual consumer "extras" object as input parameters.
35
+ * The "extras" object consists of values explicitly specified by module consumers and default values.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * .setExtras<{ isGlobal?: boolean }>({ isGlobal: false }, (definition, extras) =>
40
+ * ({ ...definition, global: extras.isGlobal })
41
+ * )
42
+ * ```
43
+ */
18
44
  setExtras(extras, transformDefinition = (def) => def) {
19
45
  const builder = new ZodConfigurableModuleBuilder(this.schema, this.options, this);
20
- // this was called and we patched
21
- this.transformSet = true;
22
- builder.base = this.patchTransform(extras, transformDefinition);
46
+ builder.extras = extras;
47
+ builder.transformModuleDefinition = transformDefinition;
23
48
  return builder;
24
49
  }
25
- patchTransform(extras, transformDefinition = (def) => def) {
26
- transformDefinition ??= (definition) => definition;
27
- const existingTransform = transformDefinition;
28
- transformDefinition = (definition, extraOptions) => {
29
- const result = existingTransform(definition, extraOptions);
30
- return this.transformModuleDefinitionWithSchema(result, extraOptions, extras);
31
- };
32
- return this.base.setExtras(extras, transformDefinition);
33
- }
50
+ /**
51
+ * Dynamic modules must expose public static methods that let you pass in
52
+ * configuration parameters (control the module's behavior from the outside).
53
+ * Some frequently used names that you may have seen in other modules are:
54
+ * "forRoot", "forFeature", "register", "configure".
55
+ *
56
+ * This method "setClassMethodName" lets you specify the name of the
57
+ * method that will be auto-generated.
58
+ *
59
+ * @param key name of the method
60
+ */
34
61
  setClassMethodName(key) {
35
62
  const builder = new ZodConfigurableModuleBuilder(this.schema, this.options, this);
36
- builder.base = builder.base.setClassMethodName(key);
63
+ builder.staticMethodKey = key;
37
64
  return builder;
38
65
  }
66
+ /**
67
+ * Asynchronously configured modules (that rely on other modules, i.e. "ConfigModule")
68
+ * let you pass the configuration factory class that will be registered and instantiated as a provider.
69
+ * This provider then will be used to retrieve the module's configuration. To provide the configuration,
70
+ * the corresponding factory method must be implemented.
71
+ *
72
+ * This method ("setFactoryMethodName") lets you control what method name will have to be
73
+ * implemented by the config factory (default is "create").
74
+ *
75
+ * @param key name of the method
76
+ */
39
77
  setFactoryMethodName(key) {
40
78
  const builder = new ZodConfigurableModuleBuilder(this.schema, this.options, this);
41
- builder.base = builder.base.setFactoryMethodName(key);
79
+ builder.factoryClassMethodKey = key;
42
80
  return builder;
43
81
  }
82
+ /**
83
+ * Returns an object consisting of multiple properties that lets you
84
+ * easily construct dynamic configurable modules. See "ConfigurableModuleHost" interface for more details.
85
+ */
44
86
  build() {
45
- if (!this.transformSet)
46
- this.base = this.patchTransform({});
47
- return this.base.build();
87
+ this.staticMethodKey ??= constants_1.DEFAULT_METHOD_KEY;
88
+ this.factoryClassMethodKey ??= constants_1.DEFAULT_FACTORY_CLASS_METHOD_KEY;
89
+ this.options.optionsInjectionToken ??= this.options.moduleName
90
+ ? this.constructInjectionTokenString()
91
+ : (0, utils_1.generateOptionsInjectionToken)();
92
+ this.transformModuleDefinition ??= (definition) => definition;
93
+ return {
94
+ ConfigurableModuleClass: this.createConfigurableModuleCls(),
95
+ MODULE_OPTIONS_TOKEN: this.options.optionsInjectionToken,
96
+ ASYNC_OPTIONS_TYPE: this.createTypeProxy("ASYNC_OPTIONS_TYPE"),
97
+ ASYNC_OPTIONS_INPUT_TYPE: this.createTypeProxy("ASYNC_OPTIONS_INPUT_TYPE"),
98
+ OPTIONS_TYPE: this.createTypeProxy("OPTIONS_TYPE"),
99
+ OPTIONS_INPUT_TYPE: this.createTypeProxy("OPTIONS_INPUT_TYPE"),
100
+ };
48
101
  }
49
- transformModuleDefinitionWithSchema(definition, extraOptions, extras) {
50
- const isOptionProvider = (provider) => "provide" in provider && provider.provide === this.options.optionsInjectionToken;
51
- definition.providers = definition.providers?.map((provider) => {
52
- if (isOptionProvider(provider)) {
53
- if ("useFactory" in provider) {
54
- const existingFactory = provider.useFactory;
55
- provider.useFactory = async (...args) => {
56
- try {
57
- return await this.schema.parseAsync(existingFactory(...args));
58
- }
59
- catch (err) {
60
- if (err instanceof zod_1.ZodError) {
61
- throw (0, internal_1.zodErrorToTypeError)(err, this.schema, definition.module.name, new Map(), false);
102
+ constructInjectionTokenString() {
103
+ const moduleNameInSnakeCase = this.options
104
+ .moduleName.trim()
105
+ .split(/(?=[A-Z])/)
106
+ .join("_")
107
+ .toUpperCase();
108
+ return `${moduleNameInSnakeCase}_MODULE_OPTIONS`;
109
+ }
110
+ createConfigurableModuleCls() {
111
+ const self = this;
112
+ const asyncMethodKey = this.staticMethodKey + constants_1.ASYNC_METHOD_SUFFIX;
113
+ class InternalModuleClass {
114
+ static [self.staticMethodKey](options) {
115
+ const providers = [
116
+ {
117
+ provide: self.options.optionsInjectionToken,
118
+ // NOTE: instead of useValue: this.omitExtras(options, self.extras),
119
+ useFactory: async () => {
120
+ const finalOptions = this.omitExtras(options, self.extras);
121
+ try {
122
+ return await self.schema.parseAsync(finalOptions);
62
123
  }
63
- throw err;
64
- }
65
- };
124
+ catch (err) {
125
+ if (err instanceof zod_1.ZodError) {
126
+ throw (0, internal_1.zodErrorToTypeError)(err, self.schema, this.name, new Map(), false);
127
+ }
128
+ throw err;
129
+ }
130
+ },
131
+ },
132
+ ];
133
+ if (self.options.alwaysTransient) {
134
+ providers.push({
135
+ provide: constants_1.CONFIGURABLE_MODULE_ID,
136
+ useValue: (0, utils_1.randomStringGenerator)(),
137
+ });
138
+ }
139
+ return self.transformModuleDefinition({
140
+ module: this,
141
+ providers,
142
+ }, {
143
+ ...self.extras,
144
+ ...options,
145
+ });
146
+ }
147
+ static [asyncMethodKey](options) {
148
+ const providers = this.createAsyncProviders(options);
149
+ if (self.options.alwaysTransient) {
150
+ providers.push({
151
+ provide: constants_1.CONFIGURABLE_MODULE_ID,
152
+ useValue: (0, utils_1.randomStringGenerator)(),
153
+ });
154
+ }
155
+ return self.transformModuleDefinition({
156
+ module: this,
157
+ imports: options.imports || [],
158
+ providers,
159
+ }, {
160
+ ...self.extras,
161
+ ...options,
162
+ });
163
+ }
164
+ static omitExtras(input, extras) {
165
+ if (!extras) {
166
+ return input;
66
167
  }
67
- else {
168
+ const moduleOptions = {};
169
+ const extrasKeys = Object.keys(extras);
170
+ Object.keys(input)
171
+ .filter((key) => !extrasKeys.includes(key))
172
+ .forEach((key) => {
173
+ // @ts-expect-error: NestJS monkey types compat
174
+ moduleOptions[key] = input[key];
175
+ });
176
+ return moduleOptions;
177
+ }
178
+ static createAsyncProviders(options) {
179
+ if (options.useExisting || options.useFactory) {
180
+ if (options.inject && options.provideInjectionTokensFrom) {
181
+ return [
182
+ this.createAsyncOptionsProvider(options),
183
+ ...(0, utils_1.getInjectionProviders)(options.provideInjectionTokensFrom, options.inject),
184
+ ];
185
+ }
186
+ return [this.createAsyncOptionsProvider(options)];
187
+ }
188
+ return [
189
+ this.createAsyncOptionsProvider(options),
190
+ {
191
+ provide: options.useClass,
192
+ useClass: options.useClass,
193
+ },
194
+ ];
195
+ }
196
+ static createAsyncOptionsProvider(options) {
197
+ if (options.useFactory) {
68
198
  return {
69
- // biome-ignore lint/style/noNonNullAssertion: the token is guaranteed to be set
70
- provide: this.options.optionsInjectionToken,
71
- useFactory: async () => {
72
- const finalOptions = (0, lodash_1.isObject)(extraOptions)
73
- ? (0, lodash_1.omit)(extraOptions, (0, lodash_1.keys)(extras))
74
- : extraOptions;
199
+ provide: self.options.optionsInjectionToken,
200
+ // NOTE: instead of useFactory: options.useFactory,
201
+ useFactory: async (...args) => {
202
+ const finalOptions = await options.useFactory(...args);
75
203
  try {
76
- return await this.schema.parseAsync(finalOptions);
204
+ return await self.schema.parseAsync(finalOptions);
77
205
  }
78
206
  catch (err) {
79
207
  if (err instanceof zod_1.ZodError) {
80
- throw (0, internal_1.zodErrorToTypeError)(err, this.schema, definition.module.name, new Map(), false);
208
+ throw (0, internal_1.zodErrorToTypeError)(err, self.schema, this.name, new Map(), false);
81
209
  }
82
210
  throw err;
83
211
  }
84
212
  },
213
+ inject: options.inject || [],
85
214
  };
86
215
  }
216
+ return {
217
+ provide: self.options.optionsInjectionToken,
218
+ useFactory: async (optionsFactory) => {
219
+ const finalOptions = await optionsFactory[self.factoryClassMethodKey]();
220
+ try {
221
+ return await self.schema.parseAsync(finalOptions);
222
+ }
223
+ catch (err) {
224
+ if (err instanceof zod_1.ZodError) {
225
+ throw (0, internal_1.zodErrorToTypeError)(err, self.schema, this.name, new Map(), false);
226
+ }
227
+ throw err;
228
+ }
229
+ },
230
+ inject: [options.useExisting || options.useClass],
231
+ };
87
232
  }
88
- return provider;
233
+ }
234
+ return InternalModuleClass;
235
+ }
236
+ createTypeProxy(typeName) {
237
+ const proxy = new Proxy({}, {
238
+ get: () => {
239
+ throw new Error(`"${typeName}" is not supposed to be used as a value.`);
240
+ },
89
241
  });
90
- return definition;
242
+ // biome-ignore lint/suspicious/noExplicitAny: NestJS monkey types compat
243
+ return proxy;
91
244
  }
92
245
  }
93
246
  exports.ZodConfigurableModuleBuilder = ZodConfigurableModuleBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module/module.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;AAMxB,mCAA8C;AAC9C,6BAA8D;AAE9D,0CAAkD;AAElD,MAAa,4BAA4B;IAiBpB;IACA;IAXV,IAAI,CAKZ;IAEM,YAAY,GAAG,KAAK,CAAC;IAE7B,YACoB,MAA8D,EAC9D,UAA4C,EAAE,EACjE,aAA6D;QAF1C,WAAM,GAAN,MAAM,CAAwD;QAC9D,YAAO,GAAP,OAAO,CAAuC;QAGjE,IAAI,CAAC,IAAI,GAAG,IAAI,kCAAyB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACnE,CAAC;IAEM,SAAS,CACf,MAAoC,EACpC,sBAGqB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG;QAEjC,MAAM,OAAO,GAAG,IAAI,4BAA4B,CAO9C,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAW,CAAC,CAAC;QAE1C,iCAAiC;QACjC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAEzB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;QAEhE,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,cAAc,CACrB,MAAoC,EACpC,sBAGqB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG;QAEjC,mBAAmB,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;QAEnD,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;QAE9C,mBAAmB,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,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O,KAAY,CAAC;IACrB,CAAC;CACD;AA7UD,oEA6UC"}
@@ -0,0 +1,10 @@
1
+ import type { FactoryProvider, Provider } from "@nestjs/common";
2
+ export declare const randomStringGenerator: () => string;
3
+ /**
4
+ *
5
+ * @param providers List of a module's providers
6
+ * @param tokens Injection tokens needed for a useFactory function (usually the module's options' token)
7
+ * @returns All the providers needed for the tokens' injection (searched recursively)
8
+ */
9
+ export declare function getInjectionProviders(providers: Provider[], tokens: FactoryProvider["inject"]): Provider[];
10
+ export declare function generateOptionsInjectionToken(): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // biome-ignore-all lint/suspicious/noExplicitAny: NestJS monkey types compat
3
+ // biome-ignore-all lint/style/noNonNullAssertion: NestJS monkey types compat
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.randomStringGenerator = void 0;
6
+ exports.getInjectionProviders = getInjectionProviders;
7
+ exports.generateOptionsInjectionToken = generateOptionsInjectionToken;
8
+ const uid_1 = require("uid");
9
+ const randomStringGenerator = () => (0, uid_1.uid)(21);
10
+ exports.randomStringGenerator = randomStringGenerator;
11
+ /**
12
+ * @param value
13
+ * @returns `true` if value is `OptionalFactoryDependency`
14
+ */
15
+ function isOptionalFactoryDependency(value) {
16
+ return (undefined !== value.token &&
17
+ undefined !== value.optional &&
18
+ !value.prototype);
19
+ }
20
+ const mapInjectToTokens = (t) => isOptionalFactoryDependency(t) ? t.token : t;
21
+ /**
22
+ *
23
+ * @param providers List of a module's providers
24
+ * @param tokens Injection tokens needed for a useFactory function (usually the module's options' token)
25
+ * @returns All the providers needed for the tokens' injection (searched recursively)
26
+ */
27
+ function getInjectionProviders(providers, tokens) {
28
+ const result = [];
29
+ let search = tokens.map(mapInjectToTokens);
30
+ while (search.length > 0) {
31
+ const match = (providers ?? []).filter((p) => !result.includes(p) && // this prevents circular loops and duplication
32
+ (search.includes(p) || search.includes(p?.provide)));
33
+ result.push(...match);
34
+ // get injection tokens of the matched providers, if any
35
+ search = match
36
+ .filter((p) => p?.inject)
37
+ .flatMap((p) => p.inject)
38
+ .map(mapInjectToTokens);
39
+ }
40
+ return result;
41
+ }
42
+ function generateOptionsInjectionToken() {
43
+ const hash = (0, exports.randomStringGenerator)();
44
+ return `CONFIGURABLE_MODULE_OPTIONS[${hash}]`;
45
+ }
46
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/module/utils.ts"],"names":[],"mappings":";AAAA,6EAA6E;AAC7E,6EAA6E;;;AAoC7E,sDAoBC;AAED,sEAGC;AApDD,6BAA0B;AAEnB,MAAM,qBAAqB,GAAG,GAAG,EAAE,CAAC,IAAA,SAAG,EAAC,EAAE,CAAC,CAAC;AAAtC,QAAA,qBAAqB,yBAAiB;AAEnD;;;GAGG;AACH,SAAS,2BAA2B,CACnC,KAAiD;IAEjD,OAAO,CACN,SAAS,KAAM,KAAmC,CAAC,KAAK;QACxD,SAAS,KAAM,KAAmC,CAAC,QAAQ;QAC3D,CAAE,KAAa,CAAC,SAAS,CACzB,CAAC;AACH,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,CAA6C,EAAE,EAAE,CAC3E,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9C;;;;;GAKG;AACH,SAAgB,qBAAqB,CACpC,SAAqB,EACrB,MAAiC;IAEjC,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,IAAI,MAAM,GAAqB,MAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,CACrC,CAAC,CAAC,EAAE,EAAE,CACL,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,+CAA+C;YACtE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAE,CAAS,EAAE,OAAO,CAAC,CAAC,CACpE,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QACtB,wDAAwD;QACxD,MAAM,GAAG,KAAK;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAAS,EAAE,MAAM,CAAC;aACjC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAAqB,CAAC,MAAO,CAAC;aAC9C,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAgB,6BAA6B;IAC5C,MAAM,IAAI,GAAG,IAAA,6BAAqB,GAAE,CAAC;IACrC,OAAO,+BAA+B,IAAI,GAAG,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proventuslabs/nestjs-zod",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "license": "MIT",
5
5
  "description": "A collection of NestJS modules to integrate Zod into your application.",
6
6
  "keywords": [