Skip to content

Feature nested global fields #1772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a71bce5
Feature nested global fields (#1771)
sunil-lakshman Feb 18, 2025
fb39bb6
Merge pull request #1773 from contentstack/development
sunil-lakshman Feb 18, 2025
a95078b
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman Mar 19, 2025
f983b3e
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman Mar 20, 2025
f8f0c01
Fix false flagging of global fields
cs-raj Mar 21, 2025
71a7fd0
Merge pull request #1826 from contentstack/fix/DX-2354
cs-raj Mar 27, 2025
7681037
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman Apr 11, 2025
b2afac6
Fixed merge conflits
sunil-lakshman Apr 11, 2025
7320c58
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman Apr 14, 2025
4eaa258
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman May 15, 2025
5aa1c5c
Fixed PR comments
sunil-lakshman May 15, 2025
d22619c
Merge branch 'development' into feat/nested-global-fields
cs-raj May 26, 2025
5473f4c
Lock file update
cs-raj May 26, 2025
b87021b
Handling nested global field in modular blocks
cs-raj May 26, 2025
9bc4fa0
talisman rc update
cs-raj May 26, 2025
f829c08
Fix and Version bump
cs-raj May 27, 2025
3ec207a
Fixed Audit check for global fields
cs-raj May 27, 2025
4472cc2
Fix test case
cs-raj May 27, 2025
fa32a33
Merge pull request #1937 from contentstack/fix/DX-3073
cs-raj May 28, 2025
7f61cb4
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman May 28, 2025
cc630cf
Fixed uid issue
sunil-lakshman May 28, 2025
4d319e7
Fixed global field update error
sunil-lakshman May 28, 2025
e784194
Removed console log
sunil-lakshman May 28, 2025
aaab042
Fixed Nested Global Field
cs-raj May 28, 2025
f950ef3
PR fixes
cs-raj May 28, 2025
e4101ae
Merge pull request #1940 from contentstack/fix/nested
cs-raj May 28, 2025
3ce10fc
Fixed merge conflits
sunil-lakshman May 30, 2025
e09d991
Fixed NGF update issue in import setup
sunil-lakshman May 30, 2025
8916bdb
Merge branch 'development' into feat/nested-global-fields
sunil-lakshman May 30, 2025
133d695
Fixed merge conflits
sunil-lakshman May 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ fileignoreconfig:
- filename: packages/contentstack/package.json
checksum: 9b0fdd100effcdbb5ee3809f7f102bfd11c88dd76e49db5103434f3aa29473dd
- filename: pnpm-lock.yaml
checksum: d1ac3746440f92fdf23f07fcbe3266ee7ac5ad5ce1b7d16108b593b352e5e719
- filename: packages/contentstack-audit/src/audit-base-command.ts
checksum: bd99d269c0b6694577f4751fa96b3d85856e41bbef624b4ec1196630d6c1d168
- filename: package-lock.json
checksum: c085555b2afd1b5c22e20b3b5217aa009af5b1801e8de120179b50201a948c0a
- filename: packages/contentstack-migrate-rte/test/commands/json-migration.test.js
checksum: 1f5ee5b39119667bd4830f9dbbbf757fb922f4ec3b7f6fad06bbfbf214fe7f73
version: '1.0'
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
checksum: 0b0af505ce1a74eb8df519f106291e319eb3ea74003ca63e03527f59a8821d39
- filename: packages/contentstack-bootstrap/test/bootstrap.test.js
checksum: 5f0355a5048183d61b605cbc160e6727a9de32832d9159e903fee49f9ab751d5
- filename: package-lock.json
checksum: a42087c2e6c587487f58fd300f6899e70c5484fa1c0707e29cedfc674129c27b
version: "1.0"
953 changes: 484 additions & 469 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.12.1 darwin-arm64 node-v22.14.0
@contentstack/cli-audit/1.12.2 darwin-arm64 node-v22.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.12.1",
"version": "1.12.2",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@oclif/plugin-help": "^6.2.27",
"@oclif/plugin-help": "^6.2.28",
"@contentstack/cli-utilities": "~1.11.2",
"@oclif/plugin-plugins": "^5.4.36",
"chalk": "^4.1.2",
Expand All @@ -30,19 +30,19 @@
"winston": "^3.17.0"
},
"devDependencies": {
"@oclif/test": "^4.1.12",
"@oclif/test": "^4.1.13",
"@types/chai": "^4.3.20",
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.10",
"@types/node": "^20.17.30",
"@types/node": "^20.17.50",
"@types/uuid": "^9.0.8",
"chai": "^4.5.0",
"eslint": "^8.57.1",
"eslint-config-oclif": "^6.0.42",
"eslint-config-oclif": "^6.0.62",
"eslint-config-oclif-typescript": "^3.1.14",
"mocha": "^10.8.2",
"nyc": "^15.1.0",
"oclif": "^4.17.43",
"oclif": "^4.17.46",
"shx": "^0.4.0",
"sinon": "^19.0.5",
"ts-node": "^10.9.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

break;
case 'field-rules':
// NOTE: We are using the fixed content-type for validation of field rules
const data = this.getCtAndGfSchema();
constructorParam.ctSchema = data.ctSchema;
constructorParam.gfSchema = data.gfSchema;
missingFieldRules = await new FieldRule(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingFieldRules);
this.getAffectedData('field-rules', dataModuleWise['content-types'], missingFieldRules);
Expand Down Expand Up @@ -456,7 +460,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
key === 'missingCTSelectFieldValues' ||
key === 'missingFieldUid' ||
key === 'action' ||
key === 'Non-Fixable' ||
key === 'Non-Fixable' ||
key === 'Not-Fixed'
) {
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
Expand Down
77 changes: 58 additions & 19 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class ContentType {
*/
async writeFixContent() {
let canWrite = true;

if (!this.inMemoryFix && this.fix) {
if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) {
canWrite = this.config.flags.yes ?? (await cliux.confirm(commonMsg.FIX_CONFIRMATION));
Expand Down Expand Up @@ -301,18 +301,35 @@ export default class ContentType {
*/
async validateGlobalField(tree: Record<string, unknown>[], field: GlobalFieldDataType): Promise<void> {
// NOTE Any GlobalField related logic can be added here
if (!field.schema && !this.fix) {
this.missingRefs[this.currentUid].push({
tree,
ct_uid: this.currentUid,
name: this.currentTitle,
data_type: field.data_type,
display_name: field.display_name,
missingRefs: 'Empty schema found',
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});
if (this.moduleName === 'global-fields') {
let { reference_to } = field;
const refExist = find(this.schema, { uid: reference_to });
if (!refExist) {
this.missingRefs[this.currentUid].push({
tree,
ct: this.currentUid,
name: this.currentTitle,
data_type: field.data_type,
display_name: field.display_name,
missingRefs: 'Referred Global Field Does not Exist',
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});
return void 0;
}
} else if (this.moduleName === 'content-types') {
if (!field.schema && !this.fix) {
this.missingRefs[this.currentUid].push({
tree,
ct_uid: this.currentUid,
name: this.currentTitle,
data_type: field.data_type,
display_name: field.display_name,
missingRefs: 'Empty schema found',
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});

return void 0;
return void 0;
}
}

await this.lookForReference(tree, field);
Expand Down Expand Up @@ -443,7 +460,7 @@ export default class ContentType {
runFixOnSchema(tree: Record<string, unknown>[], schema: ContentTypeSchemaType[]) {
// NOTE Global field Fix
return schema
.map((field) => {
?.map((field) => {
const { data_type } = field;
const fixTypes = this.config.flags['fix-only'] ?? this.config['fix-fields'];

Expand Down Expand Up @@ -524,12 +541,11 @@ export default class ContentType {
missingRefs: [reference_to],
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});
} else if (!field.schema) {
} else if (!field.schema && this.moduleName === 'content-types') {
const gfSchema = find(this.gfSchema, { uid: field.reference_to })?.schema;

if (gfSchema) {
field.schema = gfSchema as GlobalFieldSchemaTypes[];

} else {
this.missingRefs[this.currentUid].push({
tree,
data_type,
Expand All @@ -541,8 +557,27 @@ export default class ContentType {
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});
}
} else if (!field.schema && this.moduleName === 'global-fields') {
const gfSchema = find(this.gfSchema, { uid: field.reference_to })?.schema;
if (gfSchema) {
field.schema = gfSchema as GlobalFieldSchemaTypes[];
} else {
this.missingRefs[this.currentUid].push({
tree,
data_type,
display_name,
fixStatus: 'Fixed',
ct_uid: this.currentUid,
name: this.currentTitle,
missingRefs: 'Referred Global Field Does not exist',
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});
}
}

if(field.schema && !isEmpty(field.schema)){
field.schema = this.runFixOnSchema(tree, field.schema as ContentTypeSchemaType[]);
}
return refExist ? field : null;
}

Expand All @@ -559,7 +594,7 @@ export default class ContentType {
*/
fixModularBlocksReferences(tree: Record<string, unknown>[], blocks: ModularBlockType[]) {
return blocks
.map((block) => {
?.map((block) => {
const { reference_to, schema, title: display_name } = block;
tree = [...tree, { uid: block.uid, name: block.title }];
const refErrorObj = {
Expand All @@ -572,7 +607,7 @@ export default class ContentType {
treeStr: tree.map(({ name }) => name).join(' ➜ '),
};

if (!schema) {
if (!schema && this.moduleName === 'content-types') {
this.missingRefs[this.currentUid].push(refErrorObj);

return false;
Expand All @@ -581,7 +616,11 @@ export default class ContentType {
// NOTE Global field section
if (reference_to) {
const refExist = find(this.gfSchema, { uid: reference_to });
if (!refExist) {
this.missingRefs[this.currentUid].push(refErrorObj);

return false;
}
if (!refExist) {
this.missingRefs[this.currentUid].push(refErrorObj);

Expand All @@ -591,7 +630,7 @@ export default class ContentType {

block.schema = this.runFixOnSchema(tree, block.schema as ContentTypeSchemaType[]);

if (isEmpty(block.schema)) {
if (isEmpty(block.schema) && this.moduleName === 'content-types') {
this.missingRefs[this.currentUid].push({
...refErrorObj,
missingRefs: 'Empty schema found',
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/src/modules/field_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class FieldRule {
}

this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;

await this.prerequisiteData();
await this.prepareEntryMetaData();
for (const schema of this.schema ?? []) {
Expand Down
Loading
Loading