@postxl/generator 0.0.19 → 0.0.21

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +2 -2
  3. package/changelog.md +6 -0
  4. package/dist/src/generator.js +13 -13
  5. package/dist/src/generators/enums/react.generator.js +55 -55
  6. package/dist/src/generators/enums/types.generator.js +8 -8
  7. package/dist/src/generators/indices/datamockmodule.generator.js +46 -46
  8. package/dist/src/generators/indices/datamodule.generator.js +76 -76
  9. package/dist/src/generators/indices/dataservice.generator.js +26 -26
  10. package/dist/src/generators/indices/repositories.generator.js +3 -3
  11. package/dist/src/generators/indices/testdataservice.generator.js +22 -22
  12. package/dist/src/generators/models/react.generator/context.generator.js +47 -47
  13. package/dist/src/generators/models/react.generator/index.js +8 -8
  14. package/dist/src/generators/models/react.generator/library.generator.js +66 -66
  15. package/dist/src/generators/models/react.generator/lookup.generator.js +75 -75
  16. package/dist/src/generators/models/react.generator/modals.generator.js +261 -261
  17. package/dist/src/generators/models/repository.generator.js +239 -239
  18. package/dist/src/generators/models/route.generator.js +45 -45
  19. package/dist/src/generators/models/seed.generator.js +14 -14
  20. package/dist/src/generators/models/stub.generator.js +19 -19
  21. package/dist/src/generators/models/types.generator.js +39 -39
  22. package/dist/src/lib/meta.d.ts +7 -7
  23. package/dist/src/lib/meta.js +4 -4
  24. package/dist/src/lib/vfs.js +2 -2
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/jest.config.ts +18 -18
  27. package/package.json +1 -1
  28. package/tests/attributes.test.ts +91 -91
  29. package/tests/file.test.ts +32 -32
  30. package/tests/schemas/la/la.prisma +862 -862
  31. package/tests/schemas/mca/mca.prisma +528 -528
  32. package/tests/utils/random.ts +11 -11
  33. package/tests/vfs.test.ts +92 -92
package/jest.config.ts CHANGED
@@ -1,18 +1,18 @@
1
- import type { Config } from 'jest'
2
- // import { pathsToModuleNameMapper } from 'ts-jest'
3
- // import { compilerOptions } from './tsconfig.json'
4
-
5
- const config: Config = {
6
- verbose: true,
7
- // roots: ['<rootDir>/tests', '<rootDir>/src'],
8
- testEnvironment: 'node',
9
- transform: {
10
- '^.+\\.tsx?$': 'ts-jest',
11
- },
12
- testRegex: '(\\.|/)test\\.tsx?$',
13
- testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'],
14
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
15
- // moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' }),
16
- }
17
-
18
- export default config
1
+ import type { Config } from 'jest'
2
+ // import { pathsToModuleNameMapper } from 'ts-jest'
3
+ // import { compilerOptions } from './tsconfig.json'
4
+
5
+ const config: Config = {
6
+ verbose: true,
7
+ // roots: ['<rootDir>/tests', '<rootDir>/src'],
8
+ testEnvironment: 'node',
9
+ transform: {
10
+ '^.+\\.tsx?$': 'ts-jest',
11
+ },
12
+ testRegex: '(\\.|/)test\\.tsx?$',
13
+ testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'],
14
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
15
+ // moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' }),
16
+ }
17
+
18
+ export default config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "main": "./dist/src/generator.js",
5
5
  "bin": "./dist/src/generator.js",
6
6
  "repository": {
@@ -1,91 +1,91 @@
1
- import {
2
- getFieldAttributes,
3
- getModelAttributes,
4
- parseArgumentToStringOrStringArray,
5
- parseAttributesFromDocumentation,
6
- } from '../src/prisma/attributes'
7
-
8
- describe('argument parser', () => {
9
- test('Blank argument should return blank string', () => {
10
- expect(parseArgumentToStringOrStringArray('')).toEqual('')
11
- })
12
-
13
- test('Argument without quotes should return as is', () => {
14
- expect(parseArgumentToStringOrStringArray('example')).toEqual('example')
15
- })
16
-
17
- test('Argument with quotes should return without quotes', () => {
18
- expect(parseArgumentToStringOrStringArray('"example"')).toEqual('example')
19
- })
20
-
21
- test('Argument with escaped quotes should return without quotes', () => {
22
- expect(parseArgumentToStringOrStringArray('"example \\"with quotes\\""')).toEqual('example "with quotes"')
23
- })
24
-
25
- test('Argument with array of strings should convert to array', () => {
26
- expect(parseArgumentToStringOrStringArray('["example1", "example2"]')).toEqual(['example1', 'example2'])
27
- })
28
- })
29
-
30
- describe('attribute parser', () => {
31
- test('Missing documentation should return blank object', () => {
32
- expect(parseAttributesFromDocumentation({})).toEqual({})
33
- })
34
-
35
- test('Entries without "@@" should be ignored', () => {
36
- expect(parseAttributesFromDocumentation({ documentation: 'Some documentation' })).toEqual({})
37
- })
38
-
39
- test('Entries with "@@" should be parsed', () => {
40
- expect(parseAttributesFromDocumentation({ documentation: '@@ignore()' })).toEqual({ ignore: '' })
41
- })
42
-
43
- test('Attributes should be converted to camelCase', () => {
44
- expect(parseAttributesFromDocumentation({ documentation: '@@IGNORE()' })).toEqual({ iGNORE: '' })
45
- })
46
- })
47
-
48
- describe('model attribute: ignore', () => {
49
- test('should default to false', () => {
50
- expect(getModelAttributes({} as any).ignore).toBe(false)
51
- expect(getModelAttributes({ documentation: '' } as any).ignore).toBe(false)
52
- expect(getModelAttributes({ documentation: '@@test()' } as any).ignore).toBe(false)
53
- })
54
- test('should be true if @@ignore attribute is provided', () => {
55
- expect(getModelAttributes({ documentation: '@@ignore()' } as any).ignore).toBe(true)
56
- })
57
- })
58
-
59
- describe('field attribute: ignore', () => {
60
- test('should default to false', () => {
61
- expect(getFieldAttributes({} as any).ignore).toBe(false)
62
- expect(getFieldAttributes({ documentation: '' } as any).ignore).toBe(false)
63
- expect(getFieldAttributes({ documentation: '@@test()' } as any).ignore).toBe(false)
64
- })
65
- test('should be true if @@ignore attribute is provided', () => {
66
- expect(getFieldAttributes({ documentation: '@@ignore()' } as any).ignore).toBe(true)
67
- })
68
- test('should be true if Prisma field has isIgnored flag set to true', () => {
69
- expect(getFieldAttributes({ isIgnored: true } as any).ignore).toBe(true)
70
- })
71
- })
72
-
73
- describe('field attributes: example and examples', () => {
74
- test('should default to undefined', () => {
75
- expect(getFieldAttributes({} as any).examples).toBe(undefined)
76
- })
77
- test('should parse "@@examples" attribute', () => {
78
- expect(getFieldAttributes({ documentation: '@@examples("test")' } as any).examples).toStrictEqual(['test'])
79
- })
80
- test('should parse "@@example" attribute', () => {
81
- expect(getFieldAttributes({ documentation: '@@example("test")' } as any).examples).toStrictEqual(['test'])
82
- })
83
- test('should give precedence to "@@examples" over "@@example" attribute', () => {
84
- expect(getFieldAttributes({ documentation: '@@example("B")\n@@examples("A")' } as any).examples).toStrictEqual([
85
- 'A',
86
- ])
87
- })
88
- test('should parse "@@example" attribute with an array of examples', () => {
89
- expect(getFieldAttributes({ documentation: '@@example("A", "B")' } as any).examples).toStrictEqual(['A', 'B'])
90
- })
91
- })
1
+ import {
2
+ getFieldAttributes,
3
+ getModelAttributes,
4
+ parseArgumentToStringOrStringArray,
5
+ parseAttributesFromDocumentation,
6
+ } from '../src/prisma/attributes'
7
+
8
+ describe('argument parser', () => {
9
+ test('Blank argument should return blank string', () => {
10
+ expect(parseArgumentToStringOrStringArray('')).toEqual('')
11
+ })
12
+
13
+ test('Argument without quotes should return as is', () => {
14
+ expect(parseArgumentToStringOrStringArray('example')).toEqual('example')
15
+ })
16
+
17
+ test('Argument with quotes should return without quotes', () => {
18
+ expect(parseArgumentToStringOrStringArray('"example"')).toEqual('example')
19
+ })
20
+
21
+ test('Argument with escaped quotes should return without quotes', () => {
22
+ expect(parseArgumentToStringOrStringArray('"example \\"with quotes\\""')).toEqual('example "with quotes"')
23
+ })
24
+
25
+ test('Argument with array of strings should convert to array', () => {
26
+ expect(parseArgumentToStringOrStringArray('["example1", "example2"]')).toEqual(['example1', 'example2'])
27
+ })
28
+ })
29
+
30
+ describe('attribute parser', () => {
31
+ test('Missing documentation should return blank object', () => {
32
+ expect(parseAttributesFromDocumentation({})).toEqual({})
33
+ })
34
+
35
+ test('Entries without "@@" should be ignored', () => {
36
+ expect(parseAttributesFromDocumentation({ documentation: 'Some documentation' })).toEqual({})
37
+ })
38
+
39
+ test('Entries with "@@" should be parsed', () => {
40
+ expect(parseAttributesFromDocumentation({ documentation: '@@ignore()' })).toEqual({ ignore: '' })
41
+ })
42
+
43
+ test('Attributes should be converted to camelCase', () => {
44
+ expect(parseAttributesFromDocumentation({ documentation: '@@IGNORE()' })).toEqual({ iGNORE: '' })
45
+ })
46
+ })
47
+
48
+ describe('model attribute: ignore', () => {
49
+ test('should default to false', () => {
50
+ expect(getModelAttributes({} as any).ignore).toBe(false)
51
+ expect(getModelAttributes({ documentation: '' } as any).ignore).toBe(false)
52
+ expect(getModelAttributes({ documentation: '@@test()' } as any).ignore).toBe(false)
53
+ })
54
+ test('should be true if @@ignore attribute is provided', () => {
55
+ expect(getModelAttributes({ documentation: '@@ignore()' } as any).ignore).toBe(true)
56
+ })
57
+ })
58
+
59
+ describe('field attribute: ignore', () => {
60
+ test('should default to false', () => {
61
+ expect(getFieldAttributes({} as any).ignore).toBe(false)
62
+ expect(getFieldAttributes({ documentation: '' } as any).ignore).toBe(false)
63
+ expect(getFieldAttributes({ documentation: '@@test()' } as any).ignore).toBe(false)
64
+ })
65
+ test('should be true if @@ignore attribute is provided', () => {
66
+ expect(getFieldAttributes({ documentation: '@@ignore()' } as any).ignore).toBe(true)
67
+ })
68
+ test('should be true if Prisma field has isIgnored flag set to true', () => {
69
+ expect(getFieldAttributes({ isIgnored: true } as any).ignore).toBe(true)
70
+ })
71
+ })
72
+
73
+ describe('field attributes: example and examples', () => {
74
+ test('should default to undefined', () => {
75
+ expect(getFieldAttributes({} as any).examples).toBe(undefined)
76
+ })
77
+ test('should parse "@@examples" attribute', () => {
78
+ expect(getFieldAttributes({ documentation: '@@examples("test")' } as any).examples).toStrictEqual(['test'])
79
+ })
80
+ test('should parse "@@example" attribute', () => {
81
+ expect(getFieldAttributes({ documentation: '@@example("test")' } as any).examples).toStrictEqual(['test'])
82
+ })
83
+ test('should give precedence to "@@examples" over "@@example" attribute', () => {
84
+ expect(getFieldAttributes({ documentation: '@@example("B")\n@@examples("A")' } as any).examples).toStrictEqual([
85
+ 'A',
86
+ ])
87
+ })
88
+ test('should parse "@@example" attribute with an array of examples', () => {
89
+ expect(getFieldAttributes({ documentation: '@@example("A", "B")' } as any).examples).toStrictEqual(['A', 'B'])
90
+ })
91
+ })
@@ -1,32 +1,32 @@
1
- import { getRelativePath } from '../src/lib/utils/file'
2
-
3
- describe('virtual file system', () => {
4
- test('correctly resolves path to the same file', () => {
5
- expect(getRelativePath({ from: 'a/b/c', to: 'a/b/c' })).toEqual('./c')
6
- })
7
-
8
- test('correctly resolves path to a file in the same folder', () => {
9
- expect(getRelativePath({ from: 'a/b/c', to: 'a/b/d' })).toEqual('./d')
10
- })
11
-
12
- test('correclty, resolves path to a file in a parent folder', () => {
13
- expect(getRelativePath({ from: 'a/b/c', to: 'a/d' })).toEqual('../d')
14
- })
15
-
16
- test('correctly resolves completely different paths', () => {
17
- expect(getRelativePath({ from: 'a/b/c', to: 'd/e/f' })).toEqual('../../d/e/f')
18
- })
19
-
20
- test('correctly resolves path to a package', () => {
21
- expect(getRelativePath({ from: 'a/b/c', to: '@lib/package' })).toEqual('@lib/package')
22
- })
23
-
24
- test('correctly resolves relative paths', () => {
25
- expect(
26
- getRelativePath({
27
- from: './backend/libs/data/src/services/data.module',
28
- to: './backend/libs/data/src/repositories/country.repository',
29
- }),
30
- ).toEqual('../repositories/country.repository')
31
- })
32
- })
1
+ import { getRelativePath } from '../src/lib/utils/file'
2
+
3
+ describe('virtual file system', () => {
4
+ test('correctly resolves path to the same file', () => {
5
+ expect(getRelativePath({ from: 'a/b/c', to: 'a/b/c' })).toEqual('./c')
6
+ })
7
+
8
+ test('correctly resolves path to a file in the same folder', () => {
9
+ expect(getRelativePath({ from: 'a/b/c', to: 'a/b/d' })).toEqual('./d')
10
+ })
11
+
12
+ test('correclty, resolves path to a file in a parent folder', () => {
13
+ expect(getRelativePath({ from: 'a/b/c', to: 'a/d' })).toEqual('../d')
14
+ })
15
+
16
+ test('correctly resolves completely different paths', () => {
17
+ expect(getRelativePath({ from: 'a/b/c', to: 'd/e/f' })).toEqual('../../d/e/f')
18
+ })
19
+
20
+ test('correctly resolves path to a package', () => {
21
+ expect(getRelativePath({ from: 'a/b/c', to: '@lib/package' })).toEqual('@lib/package')
22
+ })
23
+
24
+ test('correctly resolves relative paths', () => {
25
+ expect(
26
+ getRelativePath({
27
+ from: './backend/libs/data/src/services/data.module',
28
+ to: './backend/libs/data/src/repositories/country.repository',
29
+ }),
30
+ ).toEqual('../repositories/country.repository')
31
+ })
32
+ })