adminizer 4.4.0-build.160 → 4.4.0-build.161

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.
@@ -21,7 +21,7 @@ export declare class ConfigHelper {
21
21
  * Get configured `identifierField` from adminpanel configuration.
22
22
  *
23
23
  * If not configured and model passed try to guess it using `primaryKey` field in model.
24
- * If system couldn't guess will return 'id`.
24
+ * If system couldn't guess will return 'id'.
25
25
  * Model could be object or just name (string).
26
26
  *
27
27
  * **Warning** If you will pass record - method will return 'id'
@@ -46,4 +46,12 @@ export declare class ConfigHelper {
46
46
  * @returns Normalized field configuration or `false` if the field should be hidden
47
47
  */
48
48
  normalizeFieldConfig(adminizer: Adminizer, config: string | boolean | BaseFieldConfig, key: string, modelField: Attribute): false | BaseFieldConfig;
49
+ /**
50
+ * Normalizes the entire adminpanel configuration.
51
+ * Merges custom config with default config and handles normalization.
52
+ *
53
+ * @param config The custom config object
54
+ * @returns The normalized and merged config
55
+ */
56
+ static normalizeConfig(config: AdminpanelConfig): AdminpanelConfig;
49
57
  }
@@ -1,3 +1,4 @@
1
+ import { getDefaultConfig } from "../system/defaults.js";
1
2
  export class ConfigHelper {
2
3
  adminizer;
3
4
  constructor(adminizer) {
@@ -20,7 +21,7 @@ export class ConfigHelper {
20
21
  * Get configured `identifierField` from adminpanel configuration.
21
22
  *
22
23
  * If not configured and model passed try to guess it using `primaryKey` field in model.
23
- * If system couldn't guess will return 'id`.
24
+ * If system couldn't guess will return 'id'.
24
25
  * Model could be object or just name (string).
25
26
  *
26
27
  * **Warning** If you will pass record - method will return 'id'
@@ -115,6 +116,40 @@ export class ConfigHelper {
115
116
  }
116
117
  return false;
117
118
  }
119
+ /**
120
+ * Normalizes the entire adminpanel configuration.
121
+ * Merges custom config with default config and handles normalization.
122
+ *
123
+ * @param config The custom config object
124
+ * @returns The normalized and merged config
125
+ */
126
+ static normalizeConfig(config) {
127
+ const defaultConfig = getDefaultConfig();
128
+ const { forms: configForms = {}, ...restConfig } = config;
129
+ const { forms: defaultForms = {}, } = defaultConfig;
130
+ const mergedConfig = {
131
+ ...defaultConfig,
132
+ ...restConfig,
133
+ models: {
134
+ ...defaultConfig.models,
135
+ ...config.models
136
+ },
137
+ forms: {
138
+ path: configForms.path ?? defaultForms.path,
139
+ data: {
140
+ ...defaultForms.data,
141
+ ...configForms.data
142
+ },
143
+ get: configForms.get ?? defaultForms.get,
144
+ set: configForms.set ?? defaultForms.set
145
+ }
146
+ };
147
+ // Normalize auth config if it's a boolean
148
+ if (typeof mergedConfig.auth === 'boolean') {
149
+ mergedConfig.auth = { enable: mergedConfig.auth };
150
+ }
151
+ return mergedConfig;
152
+ }
118
153
  }
119
154
  /**
120
155
  * function to determine the display field for associations.
package/lib/Adminizer.js CHANGED
@@ -157,27 +157,8 @@ export class Adminizer {
157
157
  if (this.config && Object.keys(this.config).length > 0) {
158
158
  throw new Error("Config has already been initialized");
159
159
  }
160
- // Merge custom config with default, additionally merge models
161
- const defaultConfig = getDefaultConfig();
162
- const { forms: configForms = {}, ...restConfig } = config;
163
- const { forms: defaultForms = {}, } = defaultConfig;
164
- this.config = {
165
- ...defaultConfig,
166
- ...restConfig,
167
- models: {
168
- ...defaultConfig.models,
169
- ...config.models
170
- },
171
- forms: {
172
- path: configForms.path ?? defaultForms.path,
173
- data: {
174
- ...defaultForms.data,
175
- ...configForms.data
176
- },
177
- get: configForms.get ?? defaultForms.get,
178
- set: configForms.set ?? defaultForms.set
179
- }
180
- };
160
+ // Normalize and merge config
161
+ this.config = ConfigHelper.normalizeConfig(config);
181
162
  // Bind cors
182
163
  bindCors(this);
183
164
  // set cookie parser
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.4.0-build.160",
4
+ "version": "4.4.0-build.161",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",