@contentstack/cli-audit 1.0.0 → 1.2.0

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.
@@ -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, { schema }) {
61
- for (const field of schema !== null && schema !== void 0 ? schema : []) {
62
- switch (field.data_type) {
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: field.display_name }], field));
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: field.uid, name: field.display_name }], field);
92
+ await this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name }], child);
68
93
  break;
69
94
  case 'json':
70
- if (field.field_metadata.extension) {
95
+ if (child.field_metadata.extension) {
71
96
  // NOTE Custom field type
72
97
  }
73
- else if (field.field_metadata.allow_json_rte) {
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: field.uid, name: field.display_name }], field));
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: field.uid, name: field.display_name }], field);
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: field.uid, name: field.display_name }], field);
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
- // NOTE Traverse each and every module and look for reference
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
- const { reference_to, display_name, data_type } = field;
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.map(({ name }) => name).join(' ➜ '),
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;
@@ -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,22 @@ 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 checks if it can write the fix content to a file and if so, it writes the content as
27
+ * JSON to the specified file path.
28
+ */
29
+ writeFixContent(filePath: string, schema: Record<string, EntryStruct>): Promise<void>;
23
30
  /**
24
31
  * The function `lookForReference` iterates over a given schema and validates different field types
25
32
  * such as reference, global field, JSON, modular blocks, and group fields.
@@ -32,7 +39,7 @@ export default class Entries {
32
39
  * EntryGroupFieldDataType} entry - The `entry` parameter is an object that represents the data of an
33
40
  * entry. It can have different types depending on the `schema` parameter.
34
41
  */
35
- lookForReference(tree: Record<string, unknown>[], { schema }: ContentTypeStruct | GlobalFieldDataType | ModularBlockType | GroupFieldDataType, entry: EntryStruct | EntryGlobalFieldDataType | EntryModularBlocksDataType | EntryGroupFieldDataType): Promise<void>;
42
+ lookForReference(tree: Record<string, unknown>[], field: ContentTypeStruct | GlobalFieldDataType | ModularBlockType | GroupFieldDataType, entry: EntryFieldType): void;
36
43
  /**
37
44
  * The function `validateReferenceField` validates the reference values of a given field in a tree
38
45
  * structure.
@@ -59,7 +66,7 @@ export default class Entries {
59
66
  * @param {EntryGlobalFieldDataType} field - The `field` parameter is of type
60
67
  * `EntryGlobalFieldDataType`. It represents a single global field entry.
61
68
  */
62
- validateGlobalField(tree: Record<string, unknown>[], fieldStructure: GlobalFieldDataType, field: EntryGlobalFieldDataType): Promise<void>;
69
+ validateGlobalField(tree: Record<string, unknown>[], fieldStructure: GlobalFieldDataType, field: EntryGlobalFieldDataType): void;
63
70
  /**
64
71
  * The function `validateJsonRTEFields` is used to validate the JSON RTE fields by checking if the
65
72
  * referenced entries exist and adding missing references to a tree structure.
@@ -72,7 +79,7 @@ export default class Entries {
72
79
  * `EntryJsonRTEFieldDataType`, which represents a JSON RTE field in an entry. It contains properties
73
80
  * such as `uid`, `attrs`, and `children`.
74
81
  */
75
- validateJsonRTEFields(tree: Record<string, unknown>[], fieldStructure: JsonRTEFieldDataType, field: EntryJsonRTEFieldDataType): Promise<void>;
82
+ validateJsonRTEFields(tree: Record<string, unknown>[], fieldStructure: JsonRTEFieldDataType, field: EntryJsonRTEFieldDataType): void;
76
83
  /**
77
84
  * The function validates the modular blocks field by traversing each module and looking for
78
85
  * references.
@@ -86,7 +93,7 @@ export default class Entries {
86
93
  * @param {EntryModularBlocksDataType[]} field - The `field` parameter is an array of objects of type
87
94
  * `EntryModularBlocksDataType`.
88
95
  */
89
- validateModularBlocksField(tree: Record<string, unknown>[], fieldStructure: ModularBlocksDataType, field: EntryModularBlocksDataType[]): Promise<void>;
96
+ validateModularBlocksField(tree: Record<string, unknown>[], fieldStructure: ModularBlocksDataType, field: EntryModularBlocksDataType[]): void;
90
97
  /**
91
98
  * The function validates a group field by looking for a reference in a tree structure.
92
99
  * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
@@ -96,7 +103,7 @@ export default class Entries {
96
103
  * @param {EntryGroupFieldDataType} field - The `field` parameter is of type
97
104
  * `EntryGroupFieldDataType` and represents a single group field entry.
98
105
  */
99
- validateGroupField(tree: Record<string, unknown>[], fieldStructure: GroupFieldDataType, field: EntryGroupFieldDataType): Promise<void>;
106
+ validateGroupField(tree: Record<string, unknown>[], fieldStructure: GroupFieldDataType, field: EntryGroupFieldDataType | EntryGroupFieldDataType[]): void;
100
107
  /**
101
108
  * The function `validateReferenceValues` checks if the references in a given field exist in the
102
109
  * provided tree and returns any missing references.
@@ -113,6 +120,111 @@ export default class Entries {
113
120
  * objects.
114
121
  */
115
122
  validateReferenceValues(tree: Record<string, unknown>[], fieldStructure: ReferenceFieldDataType, field: EntryReferenceFieldDataType[]): EntryRefErrorReturnType[];
123
+ /**
124
+ * The function `runFixOnSchema` takes in a tree, schema, and entry, and applies fixes to the entry
125
+ * based on the schema.
126
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
127
+ * the schema. Each object has the following properties:
128
+ * @param {ContentTypeSchemaType[]} schema - The `schema` parameter is an array of objects
129
+ * representing the content type schema. Each object in the array contains information about a
130
+ * specific field in the schema, such as its unique identifier (`uid`) and data type (`data_type`).
131
+ * @param {EntryFieldType} entry - The `entry` parameter is of type `EntryFieldType`, which
132
+ * represents the data of an entry. It is an object that contains fields as key-value pairs, where
133
+ * the key is the field UID (unique identifier) and the value is the field data.
134
+ * @returns the updated `entry` object after applying fixes to the fields based on the provided
135
+ * `schema`.
136
+ */
137
+ runFixOnSchema(tree: Record<string, unknown>[], schema: ContentTypeSchemaType[], entry: EntryFieldType): EntryFieldType;
138
+ /**
139
+ * The function `fixGlobalFieldReferences` adds a new entry to a tree data structure and runs a fix
140
+ * on the schema.
141
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
142
+ * @param {GlobalFieldDataType} field - The `field` parameter is of type `GlobalFieldDataType` and
143
+ * represents a global field object. It contains properties such as `uid` and `display_name`.
144
+ * @param {EntryGlobalFieldDataType} entry - The `entry` parameter is of type
145
+ * `EntryGlobalFieldDataType` and represents the global field entry that needs to be fixed.
146
+ * @returns the result of calling the `runFixOnSchema` method with the updated `tree` array,
147
+ * `field.schema`, and `entry` as arguments.
148
+ */
149
+ fixGlobalFieldReferences(tree: Record<string, unknown>[], field: GlobalFieldDataType, entry: EntryGlobalFieldDataType): EntryFieldType;
150
+ /**
151
+ * The function `fixModularBlocksReferences` takes in a tree, a list of blocks, and an entry, and
152
+ * performs various operations to fix references within the entry.
153
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
154
+ * the modular blocks.
155
+ * @param {ModularBlockType[]} blocks - An array of objects representing modular blocks. Each object
156
+ * has properties like `uid` (unique identifier) and `title` (display name).
157
+ * @param {EntryModularBlocksDataType[]} entry - An array of objects representing the modular blocks
158
+ * data in an entry. Each object in the array represents a modular block and contains its unique
159
+ * identifier (uid) and other properties.
160
+ * @returns the updated `entry` array after performing some modifications.
161
+ */
162
+ fixModularBlocksReferences(tree: Record<string, unknown>[], blocks: ModularBlockType[], entry: EntryModularBlocksDataType[]): EntryModularBlocksDataType[];
163
+ /**
164
+ * The function `fixGroupField` takes in a tree, a field, and an entry, and if the field has a
165
+ * schema, it runs a fix on the schema and returns the updated entry, otherwise it returns the
166
+ * original entry.
167
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
168
+ * @param {GroupFieldDataType} field - The `field` parameter is of type `GroupFieldDataType` and
169
+ * represents a group field object. It contains properties such as `uid` (unique identifier) and
170
+ * `display_name` (name of the field).
171
+ * @param {EntryGroupFieldDataType} entry - The `entry` parameter is of type
172
+ * `EntryGroupFieldDataType`.
173
+ * @returns If the `field.schema` is not empty, the function will return the result of calling
174
+ * `this.runFixOnSchema` with the updated `tree`, `field.schema`, and `entry` as arguments.
175
+ * Otherwise, it will return the `entry` as is.
176
+ */
177
+ fixGroupField(tree: Record<string, unknown>[], field: GroupFieldDataType, entry: EntryGroupFieldDataType | EntryGroupFieldDataType[]): EntryGroupFieldDataType | EntryGroupFieldDataType[];
178
+ /**
179
+ * The function fixes missing references in a JSON tree structure.
180
+ * @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure. Each
181
+ * object in the array has a string key and an unknown value.
182
+ * @param {ReferenceFieldDataType | JsonRTEFieldDataType} field - The `field` parameter can be of
183
+ * type `ReferenceFieldDataType` or `JsonRTEFieldDataType`.
184
+ * @param {EntryJsonRTEFieldDataType} entry - The `entry` parameter is of type
185
+ * `EntryJsonRTEFieldDataType`, which represents an entry in a JSON Rich Text Editor (JsonRTE) field.
186
+ * @returns the updated `entry` object with fixed missing references in the `children` property.
187
+ */
188
+ fixJsonRteMissingReferences(tree: Record<string, unknown>[], field: ReferenceFieldDataType | JsonRTEFieldDataType, entry: EntryJsonRTEFieldDataType | EntryJsonRTEFieldDataType[]): EntryJsonRTEFieldDataType | EntryJsonRTEFieldDataType[];
189
+ /**
190
+ * The `fixMissingReferences` function checks for missing references in an entry and adds them to a
191
+ * list if they are not found.
192
+ * @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure. Each
193
+ * object in the array should have a "name" property and an optional "index" property.
194
+ * @param {ReferenceFieldDataType | JsonRTEFieldDataType} field - The `field` parameter is of type
195
+ * `ReferenceFieldDataType` or `JsonRTEFieldDataType`.
196
+ * @param {EntryReferenceFieldDataType[]} entry - The `entry` parameter is an array of objects that
197
+ * represent references to other entries. Each object in the array has the following properties:
198
+ * @returns the `entry` variable.
199
+ */
200
+ fixMissingReferences(tree: Record<string, unknown>[], field: ReferenceFieldDataType | JsonRTEFieldDataType, entry: EntryReferenceFieldDataType[]): EntryReferenceFieldDataType[];
201
+ /**
202
+ * The function `modularBlockRefCheck` checks for invalid keys in an entry block and returns the
203
+ * updated entry block.
204
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure of
205
+ * the blocks.
206
+ * @param {ModularBlockType[]} blocks - The `blocks` parameter is an array of `ModularBlockType`
207
+ * objects.
208
+ * @param {EntryModularBlocksDataType} entryBlock - The `entryBlock` parameter is an object that
209
+ * represents a modular block entry. It contains key-value pairs where the keys are the UIDs of the
210
+ * modular blocks and the values are the data associated with each modular block.
211
+ * @param {Number} index - The `index` parameter is a number that represents the index of the current
212
+ * block in the `tree` array.
213
+ * @returns the `entryBlock` object.
214
+ */
215
+ modularBlockRefCheck(tree: Record<string, unknown>[], blocks: ModularBlockType[], entryBlock: EntryModularBlocksDataType, index: Number): EntryModularBlocksDataType;
216
+ /**
217
+ * The `jsonRefCheck` function checks if a reference exists in a JSON tree and adds missing
218
+ * references to a list if they are not found.
219
+ * @param {Record<string, unknown>[]} tree - An array of objects representing the tree structure.
220
+ * @param {JsonRTEFieldDataType} schema - The `schema` parameter is of type `JsonRTEFieldDataType`
221
+ * and represents the schema of a JSON field. It contains properties such as `uid`, `data_type`, and
222
+ * `display_name`.
223
+ * @param {EntryJsonRTEFieldDataType} child - The `child` parameter is an object that represents a
224
+ * child entry in a JSON tree. It has the following properties:
225
+ * @returns The function `jsonRefCheck` returns either `null` or `true`.
226
+ */
227
+ jsonRefCheck(tree: Record<string, unknown>[], schema: JsonRTEFieldDataType, child: EntryJsonRTEFieldDataType): true | null;
116
228
  /**
117
229
  * The function prepares entry metadata by reading and processing files from different locales and
118
230
  * schemas.