dynamo-bao 0.2.7 → 0.2.8
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/package.json +1 -1
- package/src/config.js +1 -0
- package/src/index.js +47 -2
- package/src/model-manager.js +4 -0
package/package.json
CHANGED
package/src/config.js
CHANGED
package/src/index.js
CHANGED
|
@@ -56,9 +56,14 @@ function _registerModelsFromManifest(manager, manifestPath) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function _registerModelsFromDirectory(manager, modelsDir) {
|
|
59
|
-
if (!modelsDir
|
|
59
|
+
if (!modelsDir) {
|
|
60
60
|
throw new ConfigurationError(
|
|
61
|
-
|
|
61
|
+
"modelsDir is required when no direct models are provided. Either specify a modelsDir or provide models directly in the config.",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (!fs.existsSync(modelsDir)) {
|
|
65
|
+
throw new ConfigurationError(
|
|
66
|
+
`modelsDir does not exist: ${modelsDir}`,
|
|
62
67
|
);
|
|
63
68
|
}
|
|
64
69
|
const modelFiles = findModelFiles(modelsDir);
|
|
@@ -75,7 +80,46 @@ function _registerModelsFromDirectory(manager, modelsDir) {
|
|
|
75
80
|
return models;
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
function _registerModelsFromDirectImports(manager, modelsObject) {
|
|
84
|
+
if (!modelsObject || typeof modelsObject !== 'object') {
|
|
85
|
+
throw new ConfigurationError(
|
|
86
|
+
"models must be an object containing model classes",
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const models = {};
|
|
91
|
+
Object.entries(modelsObject).forEach(([name, ModelClass]) => {
|
|
92
|
+
if (!ModelClass || typeof ModelClass !== 'function') {
|
|
93
|
+
throw new ConfigurationError(
|
|
94
|
+
`Invalid model "${name}": must be a constructor function`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (!(ModelClass.prototype instanceof BaoModel)) {
|
|
98
|
+
throw new ConfigurationError(
|
|
99
|
+
`Model "${name}" must extend BaoModel`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
manager.registerModel(ModelClass);
|
|
103
|
+
models[name] = ModelClass;
|
|
104
|
+
});
|
|
105
|
+
return models;
|
|
106
|
+
}
|
|
107
|
+
|
|
78
108
|
function _registerModels(manager, config) {
|
|
109
|
+
// If models are provided directly, use them
|
|
110
|
+
if (config.models) {
|
|
111
|
+
return _registerModelsFromDirectImports(manager, config.models);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Check if filesystem is available
|
|
115
|
+
const fsAvailable = typeof fs !== 'undefined' && fs.existsSync;
|
|
116
|
+
|
|
117
|
+
if (!fsAvailable) {
|
|
118
|
+
throw new ConfigurationError(
|
|
119
|
+
"Filesystem not available. Please provide models directly using the 'models' config option.",
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
79
123
|
const manifestPath = config.paths.generatedModelsManifest;
|
|
80
124
|
|
|
81
125
|
// Try loading from manifest first
|
|
@@ -122,6 +166,7 @@ function initModels(userConfig = {}) {
|
|
|
122
166
|
...config.tenancy,
|
|
123
167
|
...(userConfig.tenancy || {}),
|
|
124
168
|
},
|
|
169
|
+
models: userConfig.models || config.models || null,
|
|
125
170
|
};
|
|
126
171
|
|
|
127
172
|
// Validate tenant context if tenancy enabled
|
package/src/model-manager.js
CHANGED