@postxl/generator 0.0.20 → 0.0.22

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 (31) hide show
  1. package/README.md +2 -2
  2. package/dist/jest.config.js +17 -0
  3. package/dist/src/generator.js +13 -13
  4. package/dist/src/generators/enums/react.generator.js +55 -55
  5. package/dist/src/generators/enums/types.generator.js +8 -8
  6. package/dist/src/generators/indices/datamockmodule.generator.js +46 -46
  7. package/dist/src/generators/indices/datamodule.generator.js +76 -76
  8. package/dist/src/generators/indices/dataservice.generator.js +26 -26
  9. package/dist/src/generators/indices/repositories.generator.js +3 -3
  10. package/dist/src/generators/indices/testdataservice.generator.js +23 -22
  11. package/dist/src/generators/models/react.generator/context.generator.js +47 -47
  12. package/dist/src/generators/models/react.generator/index.js +8 -8
  13. package/dist/src/generators/models/react.generator/library.generator.js +66 -66
  14. package/dist/src/generators/models/react.generator/lookup.generator.js +75 -75
  15. package/dist/src/generators/models/react.generator/modals.generator.js +261 -261
  16. package/dist/src/generators/models/repository.generator.js +239 -239
  17. package/dist/src/generators/models/route.generator.js +45 -45
  18. package/dist/src/generators/models/seed.generator.js +14 -14
  19. package/dist/src/generators/models/stub.generator.js +19 -19
  20. package/dist/src/generators/models/types.generator.js +39 -39
  21. package/dist/src/lib/vfs.js +2 -2
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +8 -2
  24. package/changelog.md +0 -115
  25. package/jest.config.ts +0 -18
  26. package/tests/attributes.test.ts +0 -91
  27. package/tests/file.test.ts +0 -32
  28. package/tests/schemas/la/la.prisma +0 -862
  29. package/tests/schemas/mca/mca.prisma +0 -528
  30. package/tests/utils/random.ts +0 -11
  31. package/tests/vfs.test.ts +0 -92
@@ -14,53 +14,53 @@ function generateModelContext({ model, meta }) {
14
14
  items: [model.typeName, model.brandedIdType],
15
15
  from: meta.types.importPath,
16
16
  });
17
- return `
18
- import React, { useMemo } from 'react'
19
-
20
- import { createUseContext } from '@lib/context'
21
- import { trpc } from '@lib/trpc'
22
- import { filterMap, mapMap } from '@lib/utils'
23
-
24
- ${imports.generate()}
25
-
26
- type Context = {
27
- ready: boolean
28
- map: Map<${model.brandedIdType}, ${model.typeName}>
29
- list: ${model.typeName}[]
30
- }
31
-
32
- const ReactContext = React.createContext<Context | null>(null)
33
-
34
- /**
35
- * Context provider to fetch the ${meta.userFriendlyName} data and use it in componenets.
36
- */
37
- export const ${meta.react.context.contextProviderName} = ({ children }: React.PropsWithChildren<{}>) => {
38
- const ${queryName} = trpc.${meta.trpc.getMap.reactQueryMethod}.useQuery()
39
-
40
- const context = useMemo<Context>(() => {
41
- const data = ${queryName}.data ?? new Map()
42
-
43
- return {
44
- ready: ${queryName}.isLoading === false,
45
- map: data,
46
- list: [...data.values()]
47
- }
48
- }, [${queryName}.isLoading, ${queryName}.data])
49
-
50
- return <ReactContext.Provider value={context}>{children}</ReactContext.Provider>
51
- }
52
-
53
- export const ${meta.react.context.testContextProviderName} = ({
54
- value,
55
- children
56
- }: React.PropsWithChildren<{ value: Context }>) => {
57
- return <ReactContext.Provider value={value}>{children}</ReactContext.Provider>
58
- }
59
-
60
- /**
61
- * A React hook to access the model data.
62
- */
63
- export const ${meta.react.context.hookFnName} = createUseContext(ReactContext, "${contextReferenceName}")
17
+ return `
18
+ import React, { useMemo } from 'react'
19
+
20
+ import { createUseContext } from '@lib/react'
21
+ import { trpc } from '@lib/trpc'
22
+ import { filterMap, mapMap } from '@lib/utils'
23
+
24
+ ${imports.generate()}
25
+
26
+ type Context = {
27
+ ready: boolean
28
+ map: Map<${model.brandedIdType}, ${model.typeName}>
29
+ list: ${model.typeName}[]
30
+ }
31
+
32
+ const ReactContext = React.createContext<Context | null>(null)
33
+
34
+ /**
35
+ * Context provider to fetch the ${meta.userFriendlyName} data and use it in componenets.
36
+ */
37
+ export const ${meta.react.context.contextProviderName} = ({ children }: React.PropsWithChildren<{}>) => {
38
+ const ${queryName} = trpc.${meta.trpc.getMap.reactQueryMethod}.useQuery()
39
+
40
+ const context = useMemo<Context>(() => {
41
+ const data = ${queryName}.data ?? new Map()
42
+
43
+ return {
44
+ ready: ${queryName}.isLoading === false,
45
+ map: data,
46
+ list: [...data.values()]
47
+ }
48
+ }, [${queryName}.isLoading, ${queryName}.data])
49
+
50
+ return <ReactContext.Provider value={context}>{children}</ReactContext.Provider>
51
+ }
52
+
53
+ export const ${meta.react.context.testContextProviderName} = ({
54
+ value,
55
+ children
56
+ }: React.PropsWithChildren<{ value: Context }>) => {
57
+ return <ReactContext.Provider value={value}>{children}</ReactContext.Provider>
58
+ }
59
+
60
+ /**
61
+ * A React hook to access the model data.
62
+ */
63
+ export const ${meta.react.context.hookFnName} = createUseContext(ReactContext, "${contextReferenceName}")
64
64
  `;
65
65
  }
66
66
  exports.generateModelContext = generateModelContext;
@@ -11,14 +11,14 @@ const modals_generator_1 = require("./modals.generator");
11
11
  */
12
12
  function generateReactComponentsForModel({ model, meta }) {
13
13
  const vfs = new vfs_1.VirtualFS({
14
- '/index.ts': `
15
- export * from './CreateModal'
16
- export * from './EditModal'
17
- export * from './DeleteModal'
18
-
19
- export * from './Form'
20
- export * from './context'
21
- export * from './Library'
14
+ '/index.ts': `
15
+ export * from './CreateModal'
16
+ export * from './EditModal'
17
+ export * from './DeleteModal'
18
+
19
+ export * from './Form'
20
+ export * from './context'
21
+ export * from './Library'
22
22
  `,
23
23
  });
24
24
  vfs.write(`/context.tsx`, (0, context_generator_1.generateModelContext)({ model, meta }));
@@ -29,71 +29,71 @@ function generateModelLibraryComponents({ model, meta }) {
29
29
  const depMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
30
30
  return depMeta.react.context.contextProviderName;
31
31
  });
32
- return `
33
- import React, { useState } from 'react'
34
-
35
- import { CardList } from '@components/shared/CardList'
36
- import { CardWithActions } from '@components/shared/CardWithActions'
37
-
38
- ${imports.generate()}
39
-
40
- /**
41
- * Show all ${model.name} entries.
42
- */
43
- export const ${components.libraryComponentName} = () => {
44
- const { ready, list } = ${context.hookFnName}()
45
-
46
- return (
47
- <CardList>
48
- {list.map(item => <${components.cardComponentName} key={item.id} item={item} />)}
49
- </CardList>
50
- )
51
- }
52
-
53
- /**
54
- * Show a single ${model.name} entry.
55
- */
56
- export const ${components.cardComponentName} = ({ item }: { item: ${model.typeName} }) => {
57
- const [isEditModalOpen, setIsEditModalOpen] = useState(false)
58
- const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false)
59
-
60
- return (
61
- <>
62
- <CardWithActions
63
- title={item.name}
64
- actions={[
65
- {
66
- label: 'Edit',
67
- icon: 'pencil-on-paper',
68
- onClick: () => setIsEditModalOpen(true),
69
- },
70
- {
71
- label: 'Delete',
72
- icon: 'trash',
73
- onClick: () => setIsDeleteModalOpen(true),
74
- },
75
- ]}
76
- />
77
-
32
+ return `
33
+ import React, { useState } from 'react'
34
+
35
+ import { CardList } from '@components/shared/CardList'
36
+ import { CardWithActions } from '@components/shared/CardWithActions'
37
+
38
+ ${imports.generate()}
39
+
40
+ /**
41
+ * Show all ${model.name} entries.
42
+ */
43
+ export const ${components.libraryComponentName} = () => {
44
+ const { ready, list } = ${context.hookFnName}()
45
+
46
+ return (
47
+ <CardList>
48
+ {list.map(item => <${components.cardComponentName} key={item.id} item={item} />)}
49
+ </CardList>
50
+ )
51
+ }
52
+
53
+ /**
54
+ * Show a single ${model.name} entry.
55
+ */
56
+ export const ${components.cardComponentName} = ({ item }: { item: ${model.typeName} }) => {
57
+ const [isEditModalOpen, setIsEditModalOpen] = useState(false)
58
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false)
59
+
60
+ return (
61
+ <>
62
+ <CardWithActions
63
+ title={item.name}
64
+ actions={[
65
+ {
66
+ label: 'Edit',
67
+ icon: 'pencil-on-paper',
68
+ onClick: () => setIsEditModalOpen(true),
69
+ },
70
+ {
71
+ label: 'Delete',
72
+ icon: 'trash',
73
+ onClick: () => setIsDeleteModalOpen(true),
74
+ },
75
+ ]}
76
+ />
77
+
78
78
  ${nestInParentComponents({
79
- child: `
80
- <${components.modals.editComponentName}
81
- data={item}
82
- show={isEditModalOpen}
83
- onHide={() => setIsEditModalOpen(false)}
84
- />
79
+ child: `
80
+ <${components.modals.editComponentName}
81
+ data={item}
82
+ show={isEditModalOpen}
83
+ onHide={() => setIsEditModalOpen(false)}
84
+ />
85
85
  `,
86
86
  components: depContexts,
87
- })}
88
-
89
- <${components.modals.deleteComponentName}
90
- id={item.id}
91
- show={isDeleteModalOpen}
92
- onHide={() => setIsDeleteModalOpen(false)}
93
- />
94
- </>
95
- )
96
- }
87
+ })}
88
+
89
+ <${components.modals.deleteComponentName}
90
+ id={item.id}
91
+ show={isDeleteModalOpen}
92
+ onHide={() => setIsDeleteModalOpen(false)}
93
+ />
94
+ </>
95
+ )
96
+ }
97
97
  `;
98
98
  }
99
99
  exports.generateModelLibraryComponents = generateModelLibraryComponents;
@@ -105,9 +105,9 @@ function nestInParentComponents({ child, components }) {
105
105
  return child;
106
106
  }
107
107
  const [parent, ...rest] = components;
108
- return `
109
- <${parent}>
110
- ${nestInParentComponents({ child, components: rest })}
111
- </${parent}>
108
+ return `
109
+ <${parent}>
110
+ ${nestInParentComponents({ child, components: rest })}
111
+ </${parent}>
112
112
  `;
113
113
  }
@@ -17,81 +17,81 @@ function generateModelLookupComponents({ model, meta }) {
17
17
  from: meta.types.importPath,
18
18
  });
19
19
  const typeName = model.typeName;
20
- return `
21
- import React, { useMemo } from 'react'
22
-
23
- import { MenuSelectInput, MenuSelectField } from '@components/atoms/MenuSelect'
24
- import { SelectInput, SelectField } from '@components/atoms/SelectInput'
25
- import { SearchInput, SearchField } from '@components/atoms/SearchInput'
26
- import { TableSelectInput, TableSelectField } from '@components/atoms/TableSelectInput'
27
-
28
-
29
- import { UnionOmit } from '@lib/types'
30
-
31
- ${imports.generate()}
32
-
33
- // Select
34
-
35
- export const ${components.forms.selectInputName} = ({
36
- ...delegated
37
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
38
- const { list, ready } = ${context.hookFnName}()
39
- return <SelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
40
- }
41
-
42
- export const ${components.forms.selectFieldName} = ({
43
- ...delegated
44
- }: Omit<React.ComponentPropsWithoutRef<typeof SelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
45
- const { list, ready } = ${context.hookFnName}()
46
- return <SelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
47
- }
48
-
49
- // Menu Select
50
-
51
- export const ${components.forms.menuSelectInputName} = ({
52
- ...delegated
53
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
54
- const { list, ready } = ${context.hookFnName}()
55
- return <MenuSelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
56
- }
57
-
58
- export const ${components.forms.menuSelectFieldName} = ({
59
- ...delegated
60
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
61
- const { list, ready } = ${context.hookFnName}()
62
- return <MenuSelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
63
- }
64
-
65
- // Search
66
-
67
- export const ${components.forms.searchInputName} = ({
68
- ...delegated
69
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof SearchInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
70
- const { list, ready } = ${context.hookFnName}()
71
- return <SearchInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
72
- }
73
- export const ${components.forms.searchFieldName} = ({
74
- ...delegated
75
- }: Omit<React.ComponentPropsWithoutRef<typeof SearchField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
76
- const { list, ready } = ${context.hookFnName}()
77
- return <SearchField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
78
- }
79
-
80
- // Table
81
-
82
- export const ${components.forms.tableSelectInputName} = ({
83
- ...delegated
84
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
85
- const { list, ready } = ${context.hookFnName}()
86
- return <TableSelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
87
- }
88
-
89
- export const ${components.forms.tableSelectFieldName} = ({
90
- ...delegated
91
- }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
92
- const { list, ready } = ${context.hookFnName}()
93
- return <TableSelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
94
- }
20
+ return `
21
+ import React, { useMemo } from 'react'
22
+
23
+ import { MenuSelectInput, MenuSelectField } from '@components/atoms/MenuSelect'
24
+ import { SelectInput, SelectField } from '@components/atoms/SelectInput'
25
+ import { SearchInput, SearchField } from '@components/atoms/SearchInput'
26
+ import { TableSelectInput, TableSelectField } from '@components/atoms/TableSelectInput'
27
+
28
+
29
+ import { UnionOmit } from '@lib/types'
30
+
31
+ ${imports.generate()}
32
+
33
+ // Select
34
+
35
+ export const ${components.forms.selectInputName} = ({
36
+ ...delegated
37
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
38
+ const { list, ready } = ${context.hookFnName}()
39
+ return <SelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
40
+ }
41
+
42
+ export const ${components.forms.selectFieldName} = ({
43
+ ...delegated
44
+ }: Omit<React.ComponentPropsWithoutRef<typeof SelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
45
+ const { list, ready } = ${context.hookFnName}()
46
+ return <SelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
47
+ }
48
+
49
+ // Menu Select
50
+
51
+ export const ${components.forms.menuSelectInputName} = ({
52
+ ...delegated
53
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
54
+ const { list, ready } = ${context.hookFnName}()
55
+ return <MenuSelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
56
+ }
57
+
58
+ export const ${components.forms.menuSelectFieldName} = ({
59
+ ...delegated
60
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
61
+ const { list, ready } = ${context.hookFnName}()
62
+ return <MenuSelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
63
+ }
64
+
65
+ // Search
66
+
67
+ export const ${components.forms.searchInputName} = ({
68
+ ...delegated
69
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof SearchInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
70
+ const { list, ready } = ${context.hookFnName}()
71
+ return <SearchInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
72
+ }
73
+ export const ${components.forms.searchFieldName} = ({
74
+ ...delegated
75
+ }: Omit<React.ComponentPropsWithoutRef<typeof SearchField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
76
+ const { list, ready } = ${context.hookFnName}()
77
+ return <SearchField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
78
+ }
79
+
80
+ // Table
81
+
82
+ export const ${components.forms.tableSelectInputName} = ({
83
+ ...delegated
84
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectInput<${typeName}>>, 'label' | 'options' | 'loading'>) => {
85
+ const { list, ready } = ${context.hookFnName}()
86
+ return <TableSelectInput<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
87
+ }
88
+
89
+ export const ${components.forms.tableSelectFieldName} = ({
90
+ ...delegated
91
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectField<${typeName}>>, 'label' | 'options' | 'loading'>) => {
92
+ const { list, ready } = ${context.hookFnName}()
93
+ return <TableSelectField<${typeName}> options={list} label={(l) => l.name} loading={!ready} {...delegated} />
94
+ }
95
95
  `;
96
96
  }
97
97
  exports.generateModelLookupComponents = generateModelLookupComponents;