@contentstack/cli-audit 1.0.0 → 1.2.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 +108 -25
- package/lib/audit-base-command.d.ts +83 -0
- package/lib/audit-base-command.js +263 -0
- package/lib/commands/cm/stacks/audit/fix.d.ts +9 -4
- package/lib/commands/cm/stacks/audit/fix.js +51 -7
- package/lib/commands/cm/stacks/audit/index.d.ts +2 -51
- package/lib/commands/cm/stacks/audit/index.js +5 -201
- package/lib/messages/index.d.ts +12 -6
- package/lib/messages/index.js +17 -10
- package/lib/modules/content-types.d.ts +59 -4
- package/lib/modules/content-types.js +241 -33
- package/lib/modules/entries.d.ts +128 -7
- package/lib/modules/entries.js +376 -60
- package/lib/types/content-types.d.ts +11 -4
- package/lib/types/entries.d.ts +6 -3
- package/oclif.manifest.json +102 -10
- package/package.json +9 -10
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
const find_1 = tslib_1.__importDefault(require("lodash/find"));
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
7
|
+
const path_1 = require("path");
|
|
6
8
|
const fs_1 = require("fs");
|
|
7
9
|
const messages_1 = require("../messages");
|
|
8
10
|
/* The `ContentType` class is responsible for scanning content types, looking for references, and
|
|
9
11
|
generating a report in JSON and CSV formats. */
|
|
10
12
|
class ContentType {
|
|
11
|
-
constructor({ log, config, moduleName, ctSchema, gfSchema }) {
|
|
13
|
+
constructor({ log, fix, config, moduleName, ctSchema, gfSchema }) {
|
|
12
14
|
this.schema = [];
|
|
13
15
|
this.missingRefs = {};
|
|
14
|
-
this.moduleName = 'content-types';
|
|
15
16
|
this.log = log;
|
|
16
17
|
this.config = config;
|
|
18
|
+
this.fix = fix !== null && fix !== void 0 ? fix : false;
|
|
17
19
|
this.ctSchema = ctSchema;
|
|
18
20
|
this.gfSchema = gfSchema;
|
|
19
21
|
this.moduleName = moduleName !== null && moduleName !== void 0 ? moduleName : 'content-types';
|
|
@@ -25,7 +27,7 @@ class ContentType {
|
|
|
25
27
|
* iterates over the schema and looks for references, and returns a list of missing references.
|
|
26
28
|
* @returns the `missingRefs` object.
|
|
27
29
|
*/
|
|
28
|
-
async run() {
|
|
30
|
+
async run(returnFixSchema = false) {
|
|
29
31
|
var _a;
|
|
30
32
|
if (!(0, fs_1.existsSync)(this.folderPath)) {
|
|
31
33
|
throw new Error((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }));
|
|
@@ -39,6 +41,12 @@ class ContentType {
|
|
|
39
41
|
await this.lookForReference([{ uid, name: title }], schema);
|
|
40
42
|
this.log((0, messages_1.$t)(messages_1.auditMsg.SCAN_CT_SUCCESS_MSG, { title, module: this.config.moduleConfig[this.moduleName].name }), 'info');
|
|
41
43
|
}
|
|
44
|
+
if (returnFixSchema) {
|
|
45
|
+
return this.schema;
|
|
46
|
+
}
|
|
47
|
+
if (this.fix) {
|
|
48
|
+
await this.writeFixContent();
|
|
49
|
+
}
|
|
42
50
|
for (let propName in this.missingRefs) {
|
|
43
51
|
if (!this.missingRefs[propName].length) {
|
|
44
52
|
delete this.missingRefs[propName];
|
|
@@ -46,6 +54,19 @@ class ContentType {
|
|
|
46
54
|
}
|
|
47
55
|
return this.missingRefs;
|
|
48
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The function checks if it can write the fix content to a file and if so, it writes the content as
|
|
59
|
+
* JSON to the specified file path.
|
|
60
|
+
*/
|
|
61
|
+
async writeFixContent() {
|
|
62
|
+
let canWrite = true;
|
|
63
|
+
if (this.fix && !this.config.flags['copy-dir']) {
|
|
64
|
+
canWrite = this.config.flags.yes || (await core_1.ux.confirm(messages_1.commonMsg.FIX_CONFIRMATION));
|
|
65
|
+
}
|
|
66
|
+
if (canWrite) {
|
|
67
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.folderPath, this.config.moduleConfig[this.moduleName].fileName), JSON.stringify(this.schema));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
49
70
|
/**
|
|
50
71
|
* The function `lookForReference` iterates through a given schema and performs validation checks
|
|
51
72
|
* based on the data type of each field.
|
|
@@ -57,29 +78,33 @@ class ContentType {
|
|
|
57
78
|
* `tree`: An array of objects representing the tree structure of the content type or field. Each
|
|
58
79
|
* object in the array should have a `uid` and `name` property.
|
|
59
80
|
*/
|
|
60
|
-
async lookForReference(tree,
|
|
61
|
-
|
|
62
|
-
|
|
81
|
+
async lookForReference(tree, field) {
|
|
82
|
+
var _a;
|
|
83
|
+
if (this.fix) {
|
|
84
|
+
field.schema = this.runFixOnSchema(tree, field.schema);
|
|
85
|
+
}
|
|
86
|
+
for (let child of (_a = field.schema) !== null && _a !== void 0 ? _a : []) {
|
|
87
|
+
switch (child.data_type) {
|
|
63
88
|
case 'reference':
|
|
64
|
-
this.missingRefs[this.currentUid].push(...this.validateReferenceField([...tree, { uid: field.uid, name:
|
|
89
|
+
this.missingRefs[this.currentUid].push(...this.validateReferenceField([...tree, { uid: field.uid, name: child.display_name }], child));
|
|
65
90
|
break;
|
|
66
91
|
case 'global_field':
|
|
67
|
-
await this.validateGlobalField([...tree, { uid:
|
|
92
|
+
await this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name }], child);
|
|
68
93
|
break;
|
|
69
94
|
case 'json':
|
|
70
|
-
if (
|
|
95
|
+
if (child.field_metadata.extension) {
|
|
71
96
|
// NOTE Custom field type
|
|
72
97
|
}
|
|
73
|
-
else if (
|
|
98
|
+
else if (child.field_metadata.allow_json_rte) {
|
|
74
99
|
// NOTE JSON RTE field type
|
|
75
|
-
this.missingRefs[this.currentUid].push(...this.validateJsonRTEFields([...tree, { uid:
|
|
100
|
+
this.missingRefs[this.currentUid].push(...this.validateJsonRTEFields([...tree, { uid: child.uid, name: child.display_name }], child));
|
|
76
101
|
}
|
|
77
102
|
break;
|
|
78
103
|
case 'blocks':
|
|
79
|
-
await this.validateModularBlocksField([...tree, { uid:
|
|
104
|
+
await this.validateModularBlocksField([...tree, { uid: child.uid, name: child.display_name }], child);
|
|
80
105
|
break;
|
|
81
106
|
case 'group':
|
|
82
|
-
await this.validateGroupField([...tree, { uid:
|
|
107
|
+
await this.validateGroupField([...tree, { uid: child.uid, name: child.display_name }], child);
|
|
83
108
|
break;
|
|
84
109
|
}
|
|
85
110
|
}
|
|
@@ -106,22 +131,6 @@ class ContentType {
|
|
|
106
131
|
*/
|
|
107
132
|
async validateGlobalField(tree, field) {
|
|
108
133
|
// NOTE Any GlobalField related logic can be added here
|
|
109
|
-
const missingRefs = [];
|
|
110
|
-
const { reference_to, display_name, data_type } = field;
|
|
111
|
-
if (!(0, find_1.default)(this.gfSchema, { uid: reference_to })) {
|
|
112
|
-
missingRefs.push(reference_to);
|
|
113
|
-
}
|
|
114
|
-
if (missingRefs.length) {
|
|
115
|
-
this.missingRefs[this.currentUid].push({
|
|
116
|
-
tree,
|
|
117
|
-
data_type,
|
|
118
|
-
missingRefs,
|
|
119
|
-
display_name,
|
|
120
|
-
ct_uid: this.currentUid,
|
|
121
|
-
name: this.currentTitle,
|
|
122
|
-
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
134
|
await this.lookForReference(tree, field);
|
|
126
135
|
}
|
|
127
136
|
/**
|
|
@@ -149,7 +158,7 @@ class ContentType {
|
|
|
149
158
|
*/
|
|
150
159
|
async validateModularBlocksField(tree, field) {
|
|
151
160
|
const { blocks } = field;
|
|
152
|
-
|
|
161
|
+
this.fixModularBlocksReferences(tree, blocks);
|
|
153
162
|
for (const block of blocks) {
|
|
154
163
|
const { uid, title } = block;
|
|
155
164
|
await this.lookForReference([...tree, { uid, name: title }], block);
|
|
@@ -180,8 +189,10 @@ class ContentType {
|
|
|
180
189
|
* objects.
|
|
181
190
|
*/
|
|
182
191
|
validateReferenceToValues(tree, field) {
|
|
192
|
+
if (this.fix)
|
|
193
|
+
return [];
|
|
183
194
|
const missingRefs = [];
|
|
184
|
-
|
|
195
|
+
let { reference_to, display_name, data_type } = field;
|
|
185
196
|
for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
|
|
186
197
|
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
|
|
187
198
|
if (this.config.skipRefs.includes(reference))
|
|
@@ -200,10 +211,207 @@ class ContentType {
|
|
|
200
211
|
display_name,
|
|
201
212
|
ct_uid: this.currentUid,
|
|
202
213
|
name: this.currentTitle,
|
|
203
|
-
treeStr: tree
|
|
214
|
+
treeStr: tree
|
|
215
|
+
.map(({ name }) => name)
|
|
216
|
+
.filter((val) => val)
|
|
217
|
+
.join(' ➜ '),
|
|
204
218
|
},
|
|
205
219
|
]
|
|
206
220
|
: [];
|
|
207
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* The function `runFixOnSchema` takes in a tree and a schema, and performs various fixes on the
|
|
224
|
+
* schema based on the data types of the fields.
|
|
225
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
|
|
226
|
+
* the schema.
|
|
227
|
+
* @param {ContentTypeSchemaType[]} schema - The `schema` parameter is an array of
|
|
228
|
+
* `ContentTypeSchemaType` objects. Each object represents a field in a content type schema and
|
|
229
|
+
* contains properties such as `data_type`, `field_metadata`, `uid`, `name`, etc.
|
|
230
|
+
* @returns an array of ContentTypeSchemaType objects.
|
|
231
|
+
*/
|
|
232
|
+
runFixOnSchema(tree, schema) {
|
|
233
|
+
// NOTE Global field Fix
|
|
234
|
+
return schema
|
|
235
|
+
.map((field) => {
|
|
236
|
+
const { data_type } = field;
|
|
237
|
+
switch (data_type) {
|
|
238
|
+
case 'global_field':
|
|
239
|
+
return this.fixGlobalFieldReferences(tree, field);
|
|
240
|
+
case 'json':
|
|
241
|
+
case 'reference':
|
|
242
|
+
if (data_type === 'json') {
|
|
243
|
+
if (field.field_metadata.extension) {
|
|
244
|
+
// NOTE Custom field type
|
|
245
|
+
return field;
|
|
246
|
+
}
|
|
247
|
+
else if (field.field_metadata.allow_json_rte) {
|
|
248
|
+
return this.fixMissingReferences(tree, field);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return this.fixMissingReferences(tree, field);
|
|
252
|
+
case 'blocks':
|
|
253
|
+
field.blocks = this.fixModularBlocksReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field.blocks);
|
|
254
|
+
if ((0, isEmpty_1.default)(field.blocks)) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return field;
|
|
258
|
+
case 'group':
|
|
259
|
+
return this.fixGroupField(tree, field);
|
|
260
|
+
default:
|
|
261
|
+
return field;
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
.filter((val) => {
|
|
265
|
+
if ((val === null || val === void 0 ? void 0 : val.schema) && (0, isEmpty_1.default)(val.schema))
|
|
266
|
+
return false;
|
|
267
|
+
if ((val === null || val === void 0 ? void 0 : val.reference_to) && (0, isEmpty_1.default)(val.reference_to))
|
|
268
|
+
return false;
|
|
269
|
+
return !!val;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The function fixes global field references in a tree structure by adding missing references and
|
|
274
|
+
* returning the field if the reference exists, otherwise returning null.
|
|
275
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure.
|
|
276
|
+
* @param {GlobalFieldDataType} field - The `field` parameter is an object that represents a global
|
|
277
|
+
* field. It has the following properties:
|
|
278
|
+
* @returns either the `field` object if `reference_to` exists in `this.gfSchema`, or `null` if it
|
|
279
|
+
* doesn't.
|
|
280
|
+
*/
|
|
281
|
+
fixGlobalFieldReferences(tree, field) {
|
|
282
|
+
const { reference_to, display_name, data_type } = field;
|
|
283
|
+
if (reference_to && data_type === 'global_field') {
|
|
284
|
+
tree = [...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }];
|
|
285
|
+
const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
|
|
286
|
+
if (!refExist) {
|
|
287
|
+
this.missingRefs[this.currentUid].push({
|
|
288
|
+
tree,
|
|
289
|
+
data_type,
|
|
290
|
+
display_name,
|
|
291
|
+
fixStatus: 'Fixed',
|
|
292
|
+
missingRefs: [reference_to],
|
|
293
|
+
ct_uid: this.currentUid,
|
|
294
|
+
name: this.currentTitle,
|
|
295
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return refExist ? field : null;
|
|
299
|
+
}
|
|
300
|
+
return field;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The function `fixModularBlocksReferences` takes in an array of tree objects and an array of
|
|
304
|
+
* modular blocks, and returns an array of modular blocks with fixed references.
|
|
305
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
|
|
306
|
+
* @param {ModularBlockType[]} blocks - An array of objects representing modular blocks. Each object
|
|
307
|
+
* has properties such as "reference_to", "schema", "title", and "uid".
|
|
308
|
+
* @returns an array of `ModularBlockType` objects.
|
|
309
|
+
*/
|
|
310
|
+
fixModularBlocksReferences(tree, blocks) {
|
|
311
|
+
return blocks
|
|
312
|
+
.map((block) => {
|
|
313
|
+
const { reference_to, schema, title: display_name } = block;
|
|
314
|
+
tree = [...tree, { uid: block.uid, name: block.title }];
|
|
315
|
+
const refErrorObj = {
|
|
316
|
+
tree,
|
|
317
|
+
display_name,
|
|
318
|
+
fixStatus: 'Fixed',
|
|
319
|
+
missingRefs: [reference_to],
|
|
320
|
+
ct_uid: this.currentUid,
|
|
321
|
+
name: this.currentTitle,
|
|
322
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
323
|
+
};
|
|
324
|
+
if (!schema) {
|
|
325
|
+
this.missingRefs[this.currentUid].push(refErrorObj);
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
// NOTE Global field section
|
|
329
|
+
if (reference_to) {
|
|
330
|
+
const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
|
|
331
|
+
if (!refExist) {
|
|
332
|
+
this.missingRefs[this.currentUid].push(refErrorObj);
|
|
333
|
+
}
|
|
334
|
+
return refExist;
|
|
335
|
+
}
|
|
336
|
+
block.schema = this.runFixOnSchema(tree, block.schema);
|
|
337
|
+
if ((0, isEmpty_1.default)(block.schema)) {
|
|
338
|
+
this.missingRefs[this.currentUid].push(Object.assign(Object.assign({}, refErrorObj), { missingRefs: 'Empty schema found', treeStr: tree.map(({ name }) => name).join(' ➜ ') }));
|
|
339
|
+
this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return block;
|
|
343
|
+
})
|
|
344
|
+
.filter((val) => val);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The function `fixMissingReferences` checks for missing references in a given tree and field, and
|
|
348
|
+
* attempts to fix them by removing the missing references from the field's `reference_to` array.
|
|
349
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure. Each
|
|
350
|
+
* object in the array should have a "name" property.
|
|
351
|
+
* @param {ReferenceFieldDataType | JsonRTEFieldDataType} field - The `field` parameter is of type
|
|
352
|
+
* `ReferenceFieldDataType` or `JsonRTEFieldDataType`.
|
|
353
|
+
* @returns the `field` object.
|
|
354
|
+
*/
|
|
355
|
+
fixMissingReferences(tree, field) {
|
|
356
|
+
let fixStatus;
|
|
357
|
+
const missingRefs = [];
|
|
358
|
+
const { reference_to, data_type, display_name } = field;
|
|
359
|
+
for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
|
|
360
|
+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
|
|
361
|
+
if (this.config.skipRefs.includes(reference))
|
|
362
|
+
continue;
|
|
363
|
+
const refExist = (0, find_1.default)(this.ctSchema, { uid: reference });
|
|
364
|
+
if (!refExist) {
|
|
365
|
+
missingRefs.push(reference);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
|
|
369
|
+
try {
|
|
370
|
+
field.reference_to = field.reference_to.filter((ref) => !missingRefs.includes(ref));
|
|
371
|
+
fixStatus = 'Fixed';
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
fixStatus = `Not Fixed (${JSON.stringify(error)})`;
|
|
375
|
+
}
|
|
376
|
+
this.missingRefs[this.currentUid].push({
|
|
377
|
+
tree,
|
|
378
|
+
data_type,
|
|
379
|
+
fixStatus,
|
|
380
|
+
missingRefs,
|
|
381
|
+
display_name,
|
|
382
|
+
ct_uid: this.currentUid,
|
|
383
|
+
name: this.currentTitle,
|
|
384
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return field;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* The function `fixGroupField` takes in an array of objects and a field, and performs some
|
|
391
|
+
* operations on the field's schema property.
|
|
392
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure.
|
|
393
|
+
* @param {GroupFieldDataType} field - The `field` parameter is an object that contains the following
|
|
394
|
+
* properties:
|
|
395
|
+
* @returns The function `fixGroupField` returns either `null` or the `field` object.
|
|
396
|
+
*/
|
|
397
|
+
fixGroupField(tree, field) {
|
|
398
|
+
const { data_type, display_name } = field;
|
|
399
|
+
field.schema = this.runFixOnSchema(tree, field.schema);
|
|
400
|
+
if ((0, isEmpty_1.default)(field.schema)) {
|
|
401
|
+
this.missingRefs[this.currentUid].push({
|
|
402
|
+
tree,
|
|
403
|
+
data_type,
|
|
404
|
+
display_name,
|
|
405
|
+
fixStatus: 'Fixed',
|
|
406
|
+
ct_uid: this.currentUid,
|
|
407
|
+
name: this.currentTitle,
|
|
408
|
+
missingRefs: 'Empty schema found',
|
|
409
|
+
treeStr: tree.map(({ name }) => name).join(' ➜ '),
|
|
410
|
+
});
|
|
411
|
+
this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
return field;
|
|
415
|
+
}
|
|
208
416
|
}
|
|
209
417
|
exports.default = ContentType;
|
package/lib/modules/entries.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { LogFn, Locale, ConfigType, EntryStruct, ModularBlockType, ContentTypeStruct, CtConstructorParam, GroupFieldDataType, GlobalFieldDataType, JsonRTEFieldDataType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, EntryRefErrorReturnType, EntryGroupFieldDataType, EntryGlobalFieldDataType, EntryJsonRTEFieldDataType, EntryModularBlocksDataType, EntryReferenceFieldDataType } from '../types';
|
|
2
1
|
import auditConfig from '../config';
|
|
2
|
+
import { LogFn, Locale, ConfigType, EntryStruct, EntryFieldType, ModularBlockType, ContentTypeStruct, CtConstructorParam, GroupFieldDataType, GlobalFieldDataType, JsonRTEFieldDataType, ContentTypeSchemaType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, EntryRefErrorReturnType, EntryGroupFieldDataType, EntryGlobalFieldDataType, EntryJsonRTEFieldDataType, EntryModularBlocksDataType, EntryReferenceFieldDataType } from '../types';
|
|
3
3
|
export default class Entries {
|
|
4
4
|
log: LogFn;
|
|
5
|
+
private fix;
|
|
5
6
|
fileName: string;
|
|
6
7
|
locales: Locale[];
|
|
7
8
|
config: ConfigType;
|
|
@@ -10,16 +11,31 @@ export default class Entries {
|
|
|
10
11
|
currentTitle: string;
|
|
11
12
|
gfSchema: ContentTypeStruct[];
|
|
12
13
|
ctSchema: ContentTypeStruct[];
|
|
14
|
+
private entries;
|
|
13
15
|
protected missingRefs: Record<string, any>;
|
|
14
16
|
entryMetaData: Record<string, any>[];
|
|
15
17
|
moduleName: keyof typeof auditConfig.moduleConfig;
|
|
16
|
-
constructor({ log, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam);
|
|
18
|
+
constructor({ log, fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam);
|
|
17
19
|
/**
|
|
18
20
|
* The `run` function checks if a folder path exists, sets the schema based on the module name,
|
|
19
21
|
* iterates over the schema and looks for references, and returns a list of missing references.
|
|
20
22
|
* @returns the `missingRefs` object.
|
|
21
23
|
*/
|
|
22
24
|
run(): Promise<Record<string, any>>;
|
|
25
|
+
/**
|
|
26
|
+
* The function removes any properties from the `missingRefs` object that have an empty array value.
|
|
27
|
+
*/
|
|
28
|
+
removeEmptyVal(): void;
|
|
29
|
+
/**
|
|
30
|
+
* The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
|
|
31
|
+
* `gfSchema` properties using the `ContentType` class.
|
|
32
|
+
*/
|
|
33
|
+
fixPrerequisiteData(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* The function checks if it can write the fix content to a file and if so, it writes the content as
|
|
36
|
+
* JSON to the specified file path.
|
|
37
|
+
*/
|
|
38
|
+
writeFixContent(filePath: string, schema: Record<string, EntryStruct>): Promise<void>;
|
|
23
39
|
/**
|
|
24
40
|
* The function `lookForReference` iterates over a given schema and validates different field types
|
|
25
41
|
* such as reference, global field, JSON, modular blocks, and group fields.
|
|
@@ -32,7 +48,7 @@ export default class Entries {
|
|
|
32
48
|
* EntryGroupFieldDataType} entry - The `entry` parameter is an object that represents the data of an
|
|
33
49
|
* entry. It can have different types depending on the `schema` parameter.
|
|
34
50
|
*/
|
|
35
|
-
lookForReference(tree: Record<string, unknown>[],
|
|
51
|
+
lookForReference(tree: Record<string, unknown>[], field: ContentTypeStruct | GlobalFieldDataType | ModularBlockType | GroupFieldDataType, entry: EntryFieldType): void;
|
|
36
52
|
/**
|
|
37
53
|
* The function `validateReferenceField` validates the reference values of a given field in a tree
|
|
38
54
|
* structure.
|
|
@@ -59,7 +75,7 @@ export default class Entries {
|
|
|
59
75
|
* @param {EntryGlobalFieldDataType} field - The `field` parameter is of type
|
|
60
76
|
* `EntryGlobalFieldDataType`. It represents a single global field entry.
|
|
61
77
|
*/
|
|
62
|
-
validateGlobalField(tree: Record<string, unknown>[], fieldStructure: GlobalFieldDataType, field: EntryGlobalFieldDataType):
|
|
78
|
+
validateGlobalField(tree: Record<string, unknown>[], fieldStructure: GlobalFieldDataType, field: EntryGlobalFieldDataType): void;
|
|
63
79
|
/**
|
|
64
80
|
* The function `validateJsonRTEFields` is used to validate the JSON RTE fields by checking if the
|
|
65
81
|
* referenced entries exist and adding missing references to a tree structure.
|
|
@@ -72,7 +88,7 @@ export default class Entries {
|
|
|
72
88
|
* `EntryJsonRTEFieldDataType`, which represents a JSON RTE field in an entry. It contains properties
|
|
73
89
|
* such as `uid`, `attrs`, and `children`.
|
|
74
90
|
*/
|
|
75
|
-
validateJsonRTEFields(tree: Record<string, unknown>[], fieldStructure: JsonRTEFieldDataType, field: EntryJsonRTEFieldDataType):
|
|
91
|
+
validateJsonRTEFields(tree: Record<string, unknown>[], fieldStructure: JsonRTEFieldDataType, field: EntryJsonRTEFieldDataType): void;
|
|
76
92
|
/**
|
|
77
93
|
* The function validates the modular blocks field by traversing each module and looking for
|
|
78
94
|
* references.
|
|
@@ -86,7 +102,7 @@ export default class Entries {
|
|
|
86
102
|
* @param {EntryModularBlocksDataType[]} field - The `field` parameter is an array of objects of type
|
|
87
103
|
* `EntryModularBlocksDataType`.
|
|
88
104
|
*/
|
|
89
|
-
validateModularBlocksField(tree: Record<string, unknown>[], fieldStructure: ModularBlocksDataType, field: EntryModularBlocksDataType[]):
|
|
105
|
+
validateModularBlocksField(tree: Record<string, unknown>[], fieldStructure: ModularBlocksDataType, field: EntryModularBlocksDataType[]): void;
|
|
90
106
|
/**
|
|
91
107
|
* The function validates a group field by looking for a reference in a tree structure.
|
|
92
108
|
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
|
|
@@ -96,7 +112,7 @@ export default class Entries {
|
|
|
96
112
|
* @param {EntryGroupFieldDataType} field - The `field` parameter is of type
|
|
97
113
|
* `EntryGroupFieldDataType` and represents a single group field entry.
|
|
98
114
|
*/
|
|
99
|
-
validateGroupField(tree: Record<string, unknown>[], fieldStructure: GroupFieldDataType, field: EntryGroupFieldDataType):
|
|
115
|
+
validateGroupField(tree: Record<string, unknown>[], fieldStructure: GroupFieldDataType, field: EntryGroupFieldDataType | EntryGroupFieldDataType[]): void;
|
|
100
116
|
/**
|
|
101
117
|
* The function `validateReferenceValues` checks if the references in a given field exist in the
|
|
102
118
|
* provided tree and returns any missing references.
|
|
@@ -113,6 +129,111 @@ export default class Entries {
|
|
|
113
129
|
* objects.
|
|
114
130
|
*/
|
|
115
131
|
validateReferenceValues(tree: Record<string, unknown>[], fieldStructure: ReferenceFieldDataType, field: EntryReferenceFieldDataType[]): EntryRefErrorReturnType[];
|
|
132
|
+
/**
|
|
133
|
+
* The function `runFixOnSchema` takes in a tree, schema, and entry, and applies fixes to the entry
|
|
134
|
+
* based on the schema.
|
|
135
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
|
|
136
|
+
* the schema. Each object has the following properties:
|
|
137
|
+
* @param {ContentTypeSchemaType[]} schema - The `schema` parameter is an array of objects
|
|
138
|
+
* representing the content type schema. Each object in the array contains information about a
|
|
139
|
+
* specific field in the schema, such as its unique identifier (`uid`) and data type (`data_type`).
|
|
140
|
+
* @param {EntryFieldType} entry - The `entry` parameter is of type `EntryFieldType`, which
|
|
141
|
+
* represents the data of an entry. It is an object that contains fields as key-value pairs, where
|
|
142
|
+
* the key is the field UID (unique identifier) and the value is the field data.
|
|
143
|
+
* @returns the updated `entry` object after applying fixes to the fields based on the provided
|
|
144
|
+
* `schema`.
|
|
145
|
+
*/
|
|
146
|
+
runFixOnSchema(tree: Record<string, unknown>[], schema: ContentTypeSchemaType[], entry: EntryFieldType): EntryFieldType;
|
|
147
|
+
/**
|
|
148
|
+
* The function `fixGlobalFieldReferences` adds a new entry to a tree data structure and runs a fix
|
|
149
|
+
* on the schema.
|
|
150
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
|
|
151
|
+
* @param {GlobalFieldDataType} field - The `field` parameter is of type `GlobalFieldDataType` and
|
|
152
|
+
* represents a global field object. It contains properties such as `uid` and `display_name`.
|
|
153
|
+
* @param {EntryGlobalFieldDataType} entry - The `entry` parameter is of type
|
|
154
|
+
* `EntryGlobalFieldDataType` and represents the global field entry that needs to be fixed.
|
|
155
|
+
* @returns the result of calling the `runFixOnSchema` method with the updated `tree` array,
|
|
156
|
+
* `field.schema`, and `entry` as arguments.
|
|
157
|
+
*/
|
|
158
|
+
fixGlobalFieldReferences(tree: Record<string, unknown>[], field: GlobalFieldDataType, entry: EntryGlobalFieldDataType): EntryFieldType;
|
|
159
|
+
/**
|
|
160
|
+
* The function `fixModularBlocksReferences` takes in a tree, a list of blocks, and an entry, and
|
|
161
|
+
* performs various operations to fix references within the entry.
|
|
162
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
|
|
163
|
+
* the modular blocks.
|
|
164
|
+
* @param {ModularBlockType[]} blocks - An array of objects representing modular blocks. Each object
|
|
165
|
+
* has properties like `uid` (unique identifier) and `title` (display name).
|
|
166
|
+
* @param {EntryModularBlocksDataType[]} entry - An array of objects representing the modular blocks
|
|
167
|
+
* data in an entry. Each object in the array represents a modular block and contains its unique
|
|
168
|
+
* identifier (uid) and other properties.
|
|
169
|
+
* @returns the updated `entry` array after performing some modifications.
|
|
170
|
+
*/
|
|
171
|
+
fixModularBlocksReferences(tree: Record<string, unknown>[], blocks: ModularBlockType[], entry: EntryModularBlocksDataType[]): EntryModularBlocksDataType[];
|
|
172
|
+
/**
|
|
173
|
+
* The function `fixGroupField` takes in a tree, a field, and an entry, and if the field has a
|
|
174
|
+
* schema, it runs a fix on the schema and returns the updated entry, otherwise it returns the
|
|
175
|
+
* original entry.
|
|
176
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
|
|
177
|
+
* @param {GroupFieldDataType} field - The `field` parameter is of type `GroupFieldDataType` and
|
|
178
|
+
* represents a group field object. It contains properties such as `uid` (unique identifier) and
|
|
179
|
+
* `display_name` (name of the field).
|
|
180
|
+
* @param {EntryGroupFieldDataType} entry - The `entry` parameter is of type
|
|
181
|
+
* `EntryGroupFieldDataType`.
|
|
182
|
+
* @returns If the `field.schema` is not empty, the function will return the result of calling
|
|
183
|
+
* `this.runFixOnSchema` with the updated `tree`, `field.schema`, and `entry` as arguments.
|
|
184
|
+
* Otherwise, it will return the `entry` as is.
|
|
185
|
+
*/
|
|
186
|
+
fixGroupField(tree: Record<string, unknown>[], field: GroupFieldDataType, entry: EntryGroupFieldDataType | EntryGroupFieldDataType[]): EntryGroupFieldDataType | EntryGroupFieldDataType[];
|
|
187
|
+
/**
|
|
188
|
+
* The function fixes missing references in a JSON tree structure.
|
|
189
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure. Each
|
|
190
|
+
* object in the array has a string key and an unknown value.
|
|
191
|
+
* @param {ReferenceFieldDataType | JsonRTEFieldDataType} field - The `field` parameter can be of
|
|
192
|
+
* type `ReferenceFieldDataType` or `JsonRTEFieldDataType`.
|
|
193
|
+
* @param {EntryJsonRTEFieldDataType} entry - The `entry` parameter is of type
|
|
194
|
+
* `EntryJsonRTEFieldDataType`, which represents an entry in a JSON Rich Text Editor (JsonRTE) field.
|
|
195
|
+
* @returns the updated `entry` object with fixed missing references in the `children` property.
|
|
196
|
+
*/
|
|
197
|
+
fixJsonRteMissingReferences(tree: Record<string, unknown>[], field: ReferenceFieldDataType | JsonRTEFieldDataType, entry: EntryJsonRTEFieldDataType | EntryJsonRTEFieldDataType[]): EntryJsonRTEFieldDataType | EntryJsonRTEFieldDataType[];
|
|
198
|
+
/**
|
|
199
|
+
* The `fixMissingReferences` function checks for missing references in an entry and adds them to a
|
|
200
|
+
* list if they are not found.
|
|
201
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure. Each
|
|
202
|
+
* object in the array should have a "name" property and an optional "index" property.
|
|
203
|
+
* @param {ReferenceFieldDataType | JsonRTEFieldDataType} field - The `field` parameter is of type
|
|
204
|
+
* `ReferenceFieldDataType` or `JsonRTEFieldDataType`.
|
|
205
|
+
* @param {EntryReferenceFieldDataType[]} entry - The `entry` parameter is an array of objects that
|
|
206
|
+
* represent references to other entries. Each object in the array has the following properties:
|
|
207
|
+
* @returns the `entry` variable.
|
|
208
|
+
*/
|
|
209
|
+
fixMissingReferences(tree: Record<string, unknown>[], field: ReferenceFieldDataType | JsonRTEFieldDataType, entry: EntryReferenceFieldDataType[]): EntryReferenceFieldDataType[];
|
|
210
|
+
/**
|
|
211
|
+
* The function `modularBlockRefCheck` checks for invalid keys in an entry block and returns the
|
|
212
|
+
* updated entry block.
|
|
213
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
|
|
214
|
+
* the blocks.
|
|
215
|
+
* @param {ModularBlockType[]} blocks - The `blocks` parameter is an array of `ModularBlockType`
|
|
216
|
+
* objects.
|
|
217
|
+
* @param {EntryModularBlocksDataType} entryBlock - The `entryBlock` parameter is an object that
|
|
218
|
+
* represents a modular block entry. It contains key-value pairs where the keys are the UIDs of the
|
|
219
|
+
* modular blocks and the values are the data associated with each modular block.
|
|
220
|
+
* @param {Number} index - The `index` parameter is a number that represents the index of the current
|
|
221
|
+
* block in the `tree` array.
|
|
222
|
+
* @returns the `entryBlock` object.
|
|
223
|
+
*/
|
|
224
|
+
modularBlockRefCheck(tree: Record<string, unknown>[], blocks: ModularBlockType[], entryBlock: EntryModularBlocksDataType, index: number): EntryModularBlocksDataType;
|
|
225
|
+
/**
|
|
226
|
+
* The `jsonRefCheck` function checks if a reference exists in a JSON tree and adds missing
|
|
227
|
+
* references to a list if they are not found.
|
|
228
|
+
* @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
|
|
229
|
+
* @param {JsonRTEFieldDataType} schema - The `schema` parameter is of type `JsonRTEFieldDataType`
|
|
230
|
+
* and represents the schema of a JSON field. It contains properties such as `uid`, `data_type`, and
|
|
231
|
+
* `display_name`.
|
|
232
|
+
* @param {EntryJsonRTEFieldDataType} child - The `child` parameter is an object that represents a
|
|
233
|
+
* child entry in a JSON tree. It has the following properties:
|
|
234
|
+
* @returns The function `jsonRefCheck` returns either `null` or `true`.
|
|
235
|
+
*/
|
|
236
|
+
jsonRefCheck(tree: Record<string, unknown>[], schema: JsonRTEFieldDataType, child: EntryJsonRTEFieldDataType): true | null;
|
|
116
237
|
/**
|
|
117
238
|
* The function prepares entry metadata by reading and processing files from different locales and
|
|
118
239
|
* schemas.
|