@swell/cli 2.3.3 → 2.3.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.
|
@@ -16,7 +16,7 @@ export default class Models extends SwellCommand {
|
|
|
16
16
|
private showStandardModels;
|
|
17
17
|
private showAppModels;
|
|
18
18
|
private showModels;
|
|
19
|
-
private
|
|
19
|
+
private getModelPath;
|
|
20
20
|
private getCurrentAppSlugId;
|
|
21
21
|
private getAppSlugId;
|
|
22
22
|
private showModelDetail;
|
|
@@ -31,6 +31,7 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
31
31
|
static examples = [
|
|
32
32
|
'swell inspect models',
|
|
33
33
|
'swell inspect models /products',
|
|
34
|
+
'swell inspect models /content/blogs',
|
|
34
35
|
'swell inspect models /apps/myapp/orders',
|
|
35
36
|
'swell inspect models /orders --live',
|
|
36
37
|
];
|
|
@@ -69,7 +70,6 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
69
70
|
adminPath: '/data/:models',
|
|
70
71
|
}, {
|
|
71
72
|
query: {
|
|
72
|
-
content_id: { $exists: false },
|
|
73
73
|
deprecated: { $ne: true },
|
|
74
74
|
development: { $ne: true },
|
|
75
75
|
abstract: { $ne: true },
|
|
@@ -102,6 +102,7 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
102
102
|
this.log();
|
|
103
103
|
this.log('Examples:');
|
|
104
104
|
this.log(' swell inspect models /products');
|
|
105
|
+
this.log(' swell inspect models /content/blogs');
|
|
105
106
|
this.log(' swell inspect models /apps/myapp/orders');
|
|
106
107
|
}
|
|
107
108
|
showStandardModels(models) {
|
|
@@ -123,20 +124,34 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
123
124
|
showModels(models, label, options) {
|
|
124
125
|
this.log(label);
|
|
125
126
|
this.log();
|
|
126
|
-
const sortedModels = [...models].sort((a, b) =>
|
|
127
|
+
const sortedModels = [...models].sort((a, b) => {
|
|
128
|
+
const pathA = this.getModelPath(a, options?.pathPrefix);
|
|
129
|
+
const pathB = this.getModelPath(b, options?.pathPrefix);
|
|
130
|
+
return pathA.localeCompare(pathB);
|
|
131
|
+
});
|
|
127
132
|
for (const model of sortedModels) {
|
|
128
|
-
this.
|
|
133
|
+
const modelPath = this.getModelPath(model, options?.pathPrefix);
|
|
134
|
+
this.log(` ${modelPath}`);
|
|
129
135
|
const sortedSubModels = Object.values(model.fields)
|
|
130
136
|
.filter((field) => field.type === 'collection')
|
|
131
137
|
.map((field) => field.name)
|
|
132
138
|
.sort((a, b) => a.localeCompare(b));
|
|
133
139
|
for (const sub of sortedSubModels) {
|
|
134
|
-
|
|
140
|
+
const subPath = options?.pathPrefix
|
|
141
|
+
? `${options.pathPrefix}/${sub}`
|
|
142
|
+
: `/${sub}`;
|
|
143
|
+
this.log(` ${subPath}`);
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
}
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
getModelPath(model, pathPrefix) {
|
|
148
|
+
if (pathPrefix) {
|
|
149
|
+
return `${pathPrefix}/${model.name}`;
|
|
150
|
+
}
|
|
151
|
+
if (model.namespace) {
|
|
152
|
+
return `/${model.namespace}/${model.name}`;
|
|
153
|
+
}
|
|
154
|
+
return `/${model.name}`;
|
|
140
155
|
}
|
|
141
156
|
async getCurrentAppSlugId() {
|
|
142
157
|
const hasAppContext = fs.existsSync('swell.json');
|
|
@@ -155,15 +170,32 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
155
170
|
return app.public_id || app.private_id.replace(/^_/, '');
|
|
156
171
|
}
|
|
157
172
|
async showModelDetail(path) {
|
|
158
|
-
const [modelPath, subModelKey] = await this.resolveModelPath(path);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
const [modelPath, subModelKey, namespace] = await this.resolveModelPath(path);
|
|
174
|
+
let model = null;
|
|
175
|
+
if (namespace) {
|
|
176
|
+
// For namespaced models, fetch by name and namespace filter
|
|
177
|
+
// since the API may return a different model with the same name
|
|
178
|
+
const modelName = modelPath.slice(1); // Remove leading /
|
|
179
|
+
const { results } = await this.api.get({ adminPath: '/data/:models' }, {
|
|
180
|
+
query: {
|
|
181
|
+
name: modelName,
|
|
182
|
+
namespace,
|
|
183
|
+
$app: true,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
model = results?.[0] ?? null;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
model = await this.api.get({
|
|
190
|
+
adminPath: `/data/:models${modelPath}`,
|
|
191
|
+
}, { query: { $app: true } });
|
|
192
|
+
}
|
|
162
193
|
if (!model) {
|
|
163
194
|
this.throwModelNotFound(path);
|
|
164
195
|
}
|
|
165
196
|
if (!subModelKey) {
|
|
166
|
-
|
|
197
|
+
this.showModel(model);
|
|
198
|
+
return;
|
|
167
199
|
}
|
|
168
200
|
const subModel = model.fields[subModelKey];
|
|
169
201
|
if (!subModel) {
|
|
@@ -176,6 +208,13 @@ With a collection path, it retrieves the model for that specific collection in J
|
|
|
176
208
|
return this.resolveAppModelPath(path);
|
|
177
209
|
}
|
|
178
210
|
const [modelPath, subModelKey] = path.split(':');
|
|
211
|
+
// Check if this is a namespaced path (e.g., /content/blogs)
|
|
212
|
+
const pathParts = modelPath.slice(1).split('/');
|
|
213
|
+
if (pathParts.length === 2) {
|
|
214
|
+
const [namespace, modelName] = pathParts;
|
|
215
|
+
// Return model name and namespace for filtering
|
|
216
|
+
return [`/${modelName}`, subModelKey, namespace];
|
|
217
|
+
}
|
|
179
218
|
return [modelPath, subModelKey];
|
|
180
219
|
}
|
|
181
220
|
async resolveAppModelPath(path) {
|
package/dist/lib/api.js
CHANGED
package/oclif.manifest.json
CHANGED
|
@@ -2326,6 +2326,7 @@
|
|
|
2326
2326
|
"examples": [
|
|
2327
2327
|
"swell inspect models",
|
|
2328
2328
|
"swell inspect models /products",
|
|
2329
|
+
"swell inspect models /content/blogs",
|
|
2329
2330
|
"swell inspect models /apps/myapp/orders",
|
|
2330
2331
|
"swell inspect models /orders --live"
|
|
2331
2332
|
],
|
|
@@ -2875,5 +2876,5 @@
|
|
|
2875
2876
|
]
|
|
2876
2877
|
}
|
|
2877
2878
|
},
|
|
2878
|
-
"version": "2.3.
|
|
2879
|
+
"version": "2.3.4"
|
|
2879
2880
|
}
|