Skip to content

Commit c825c9a

Browse files
authored
Merge pull request #73 from Contentstack-Solutions/staging
Merge staging to main
2 parents a6bbf20 + d45d075 commit c825c9a

18 files changed

+438
-370
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ master, development, staging ]
99
pull_request:
10-
branches: [ master ]
10+
branches: [ master, development, staging ]
1111

1212
jobs:
1313
build:

package-lock.json

Lines changed: 158 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "contentstack-cli-tsgen",
33
"description": "Generate TypeScript typings from a Stack.",
4-
"version": "2.2.0",
4+
"version": "2.2.1",
55
"author": "Michael Davis",
66
"bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues",
77
"dependencies": {

src/lib/stack/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type FieldOptions = {
1616
multiple: boolean;
1717
non_localizable: boolean;
1818
max_instance: boolean | undefined;
19+
display_type: string;
1920
} & Identifier;
2021

2122
export type Block = {

src/lib/tsgen/factory.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ export default function (userOptions: TSGenOptions) {
216216
fieldType += "[]";
217217
}
218218
}
219-
220219
return [
221220
field.uid + op_required(field.mandatory) + ':',
222-
fieldType || visit_field_type(field) + ';',
221+
fieldType || visit_field_type(field), (['isodate','file','number'].includes(field.data_type) || ['radio','dropdown'].includes(field.display_type))?field.mandatory?'':'| null':'', ';'
223222
].join(' ')
224223
}
225224

@@ -272,7 +271,7 @@ export default function (userOptions: TSGenOptions) {
272271
}
273272

274273
function type_text() {
275-
return 'string'
274+
return 'string'
276275
}
277276

278277
function type_number() {

tests/tsgen/boolean.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
const testData = require('./boolean.ct')
1+
const testData = require("./boolean.ct");
22

3-
import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
4-
import tsgenFactory from '../../src/lib/tsgen/factory'
3+
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
4+
import tsgenFactory from "../../src/lib/tsgen/factory";
55

66
const tsgen = tsgenFactory({
77
docgen: new NullDocumentationGenerator(),
88
naming: {
9-
prefix: 'I',
9+
prefix: "I",
1010
},
11-
})
11+
});
1212

13-
describe('builtin boolean field', () => {
14-
const result = tsgen(testData.builtinBoolean)
13+
describe("builtin boolean field", () => {
14+
const result = tsgen(testData.builtinBoolean);
1515

16-
test('metadata', () => {
17-
const types = result.metadata.types
18-
expect([...types.contentstack]).toHaveLength(0)
19-
expect([...types.globalFields]).toHaveLength(0)
20-
expect(types.javascript).toContain('boolean')
21-
})
16+
test("metadata", () => {
17+
const types = result.metadata.types;
18+
expect([...types.contentstack]).toHaveLength(0);
19+
expect([...types.globalFields]).toHaveLength(0);
20+
expect(types.javascript).toContain("boolean");
21+
});
2222

23-
test('definition', () => {
23+
test("definition", () => {
2424
expect(result.definition).toMatchInlineSnapshot(`
2525
"export interface IBoolean
2626
{
2727
/** Version */
2828
version: 2 ;
29-
title: string;
30-
boolean?: boolean;
29+
title: string ;
30+
boolean?: boolean ;
3131
}"
32-
`)
33-
})
34-
})
32+
`);
33+
});
34+
});

tests/tsgen/defaults.test.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
const testData = require('./defaults.ct')
1+
const testData = require("./defaults.ct");
22

3-
import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
4-
import tsgenFactory from '../../src/lib/tsgen/factory'
3+
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
4+
import tsgenFactory from "../../src/lib/tsgen/factory";
55

66
const tsgen = tsgenFactory({
77
docgen: new NullDocumentationGenerator(),
88
naming: {
9-
prefix: 'I',
9+
prefix: "I",
1010
},
11-
})
11+
});
1212

13-
describe('default single content block', () => {
14-
const result = tsgen(testData.defaultSingleContentBlock)
13+
describe("default single content block", () => {
14+
const result = tsgen(testData.defaultSingleContentBlock);
1515

16-
test('definition', () => {
16+
test("definition", () => {
1717
expect(result.definition).toMatchInlineSnapshot(`
1818
"export interface IMetadataSingleContentBlock
1919
{
2020
/** Version */
2121
version: 2 ;
22-
title: string;
22+
title: string ;
2323
}"
24-
`)
25-
})
26-
})
24+
`);
25+
});
26+
});
2727

28-
describe('default single webpage', () => {
29-
const result = tsgen(testData.defaultSingleWebpage)
28+
describe("default single webpage", () => {
29+
const result = tsgen(testData.defaultSingleWebpage);
3030

31-
test('types', () => {
32-
const types = result.metadata.types
33-
expect([...types.contentstack]).toHaveLength(0)
34-
expect([...types.globalFields]).toHaveLength(0)
35-
expect(types.javascript).toContain('string')
36-
})
31+
test("types", () => {
32+
const types = result.metadata.types;
33+
expect([...types.contentstack]).toHaveLength(0);
34+
expect([...types.globalFields]).toHaveLength(0);
35+
expect(types.javascript).toContain("string");
36+
});
3737

38-
test('dependencies', () => {
39-
expect(result.metadata.dependencies.globalFields).toEqual({})
40-
})
38+
test("dependencies", () => {
39+
expect(result.metadata.dependencies.globalFields).toEqual({});
40+
});
4141

42-
test('definition', () => {
42+
test("definition", () => {
4343
expect(result.definition).toMatchInlineSnapshot(`
4444
"export interface IMetadataSingleWebpage
4545
{
4646
/** Version */
4747
version: 2 ;
48-
title: string;
49-
url: string;
48+
title: string ;
49+
url: string ;
5050
}"
51-
`)
52-
})
53-
})
51+
`);
52+
});
53+
});

tests/tsgen/global.fields.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
const testData = require('./global.fields.ct')
1+
const testData = require("./global.fields.ct");
22

3-
import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
4-
import tsgenFactory from '../../src/lib/tsgen/factory'
3+
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
4+
import tsgenFactory from "../../src/lib/tsgen/factory";
55

66
const tsgen = tsgenFactory({
77
docgen: new NullDocumentationGenerator(),
88
naming: {
9-
prefix: 'I',
9+
prefix: "I",
1010
},
11-
})
11+
});
1212

13-
describe('global fields', () => {
14-
const result = tsgen(testData.globalFields)
13+
describe("global fields", () => {
14+
const result = tsgen(testData.globalFields);
1515

16-
test('metadata', () => {
17-
const types = result.metadata.types
16+
test("metadata", () => {
17+
const types = result.metadata.types;
1818

19-
expect([...types.globalFields]).toEqual(expect.arrayContaining(['ISeo']))
20-
})
19+
expect([...types.globalFields]).toEqual(expect.arrayContaining(["ISeo"]));
20+
});
2121

22-
test('global field definition', () => {
23-
const globalField = result.metadata.dependencies.globalFields.ISeo
22+
test("global field definition", () => {
23+
const globalField = result.metadata.dependencies.globalFields.ISeo;
2424
expect(globalField.definition).toMatchInlineSnapshot(`
2525
"export interface ISeo
2626
{
2727
/** Version */
2828
version: ;
29-
keywords?: string;
30-
description?: string;
29+
keywords?: string ;
30+
description?: string ;
3131
}"
32-
`)
33-
})
32+
`);
33+
});
3434

35-
test('content type definition', () => {
35+
test("content type definition", () => {
3636
expect(result.definition).toMatchInlineSnapshot(`
3737
"export interface IGlobalFields
3838
{
3939
/** Version */
4040
version: 2 ;
41-
title: string;
42-
seo?: ISeo;
41+
title: string ;
42+
seo?: ISeo ;
4343
}"
44-
`)
45-
})
46-
})
44+
`);
45+
});
46+
});

tests/tsgen/group.test.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
const testData = require('./group.ct')
1+
const testData = require("./group.ct");
22

3-
import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
4-
import tsgenFactory from '../../src/lib/tsgen/factory'
3+
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
4+
import tsgenFactory from "../../src/lib/tsgen/factory";
55

66
const tsgen = tsgenFactory({
77
docgen: new NullDocumentationGenerator(),
8-
})
8+
});
99

10-
describe('group', () => {
11-
const result = tsgen(testData.group)
10+
describe("group", () => {
11+
const result = tsgen(testData.group);
1212

13-
test('metadata', () => {
14-
const types = result.metadata.types
15-
expect([...types.contentstack]).toHaveLength(0)
16-
expect([...types.globalFields]).toHaveLength(0)
13+
test("metadata", () => {
14+
const types = result.metadata.types;
15+
expect([...types.contentstack]).toHaveLength(0);
16+
expect([...types.globalFields]).toHaveLength(0);
1717
expect([...types.javascript]).toEqual(
18-
expect.arrayContaining(['string', 'number', 'boolean'])
19-
)
20-
})
18+
expect.arrayContaining(["string", "number", "boolean"])
19+
);
20+
});
2121

22-
test('definition', () => {
22+
test("definition", () => {
2323
expect(result.definition).toMatchInlineSnapshot(`
2424
"export interface Group
2525
{
2626
/** Version */
2727
version: 3 ;
28-
title: string;
28+
title: string ;
2929
multiple_group_max_limit?: [{
30-
number?: number;
30+
number?: number | null ;
3131
}, {
32-
number?: number;
32+
number?: number | null ;
3333
}, {
34-
number?: number;
34+
number?: number | null ;
3535
}, {
36-
number?: number;
36+
number?: number | null ;
3737
}, {
38-
number?: number;
39-
}];
38+
number?: number | null ;
39+
}] ;
4040
multiple_group?: {
41-
single_line?: string;
42-
}[];
41+
single_line?: string ;
42+
}[] ;
4343
parent_group?: {
44-
rich_text_editor?: string;
45-
multi_line?: string;
46-
single_line?: string;
44+
rich_text_editor?: string ;
45+
multi_line?: string ;
46+
single_line?: string ;
4747
child_group?: {
48-
number?: number;
49-
boolean?: boolean;
50-
date?: string;
51-
};
52-
};
48+
number?: number | null ;
49+
boolean?: boolean ;
50+
date?: string | null ;
51+
} ;
52+
} ;
5353
}"
54-
`)
55-
})
56-
})
54+
`);
55+
});
56+
});

0 commit comments

Comments
 (0)