kea-typegen 1.2.1 → 1.4.1

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 (175) hide show
  1. package/CHANGELOG.md +75 -32
  2. package/dist/package.json +18 -17
  3. package/dist/src/__tests__/e2e/actions.js +4 -4
  4. package/dist/src/__tests__/e2e/actions.js.map +1 -1
  5. package/dist/src/__tests__/e2e/connect.js +6 -6
  6. package/dist/src/__tests__/e2e/connect.js.map +1 -1
  7. package/dist/src/__tests__/e2e/loaders.js +3 -3
  8. package/dist/src/__tests__/e2e/loaders.js.map +1 -1
  9. package/dist/src/__tests__/e2e/reducers.js +4 -4
  10. package/dist/src/__tests__/e2e/reducers.js.map +1 -1
  11. package/dist/src/__tests__/e2e/selectors.js +3 -3
  12. package/dist/src/__tests__/e2e/selectors.js.map +1 -1
  13. package/dist/src/__tests__/utils.js +7 -7
  14. package/dist/src/__tests__/utils.js.map +1 -1
  15. package/dist/src/cli/typegen.js +35 -9
  16. package/dist/src/cli/typegen.js.map +1 -1
  17. package/dist/src/print/print.d.ts +5 -5
  18. package/dist/src/print/print.js +70 -44
  19. package/dist/src/print/print.js.map +1 -1
  20. package/dist/src/print/printActionCreators.d.ts +1 -2
  21. package/dist/src/print/printActionCreators.js +7 -7
  22. package/dist/src/print/printActionCreators.js.map +1 -1
  23. package/dist/src/print/printActionKeys.d.ts +1 -2
  24. package/dist/src/print/printActionKeys.js +4 -4
  25. package/dist/src/print/printActionKeys.js.map +1 -1
  26. package/dist/src/print/printActionTypes.d.ts +1 -2
  27. package/dist/src/print/printActionTypes.js +4 -4
  28. package/dist/src/print/printActionTypes.js.map +1 -1
  29. package/dist/src/print/printActions.d.ts +1 -2
  30. package/dist/src/print/printActions.js +4 -4
  31. package/dist/src/print/printActions.js.map +1 -1
  32. package/dist/src/print/printConstants.d.ts +1 -2
  33. package/dist/src/print/printConstants.js +2 -2
  34. package/dist/src/print/printConstants.js.map +1 -1
  35. package/dist/src/print/printDefaults.d.ts +1 -2
  36. package/dist/src/print/printDefaults.js +3 -3
  37. package/dist/src/print/printDefaults.js.map +1 -1
  38. package/dist/src/print/printEvents.d.ts +1 -2
  39. package/dist/src/print/printEvents.js +3 -3
  40. package/dist/src/print/printEvents.js.map +1 -1
  41. package/dist/src/print/printInternalExtraInput.d.ts +1 -2
  42. package/dist/src/print/printInternalExtraInput.js +8 -8
  43. package/dist/src/print/printInternalExtraInput.js.map +1 -1
  44. package/dist/src/print/printInternalReducerActions.d.ts +1 -2
  45. package/dist/src/print/printInternalReducerActions.js +3 -4
  46. package/dist/src/print/printInternalReducerActions.js.map +1 -1
  47. package/dist/src/print/printInternalSelectorTypes.d.ts +1 -2
  48. package/dist/src/print/printInternalSelectorTypes.js +3 -3
  49. package/dist/src/print/printInternalSelectorTypes.js.map +1 -1
  50. package/dist/src/print/printKey.d.ts +1 -2
  51. package/dist/src/print/printKey.js +2 -2
  52. package/dist/src/print/printKey.js.map +1 -1
  53. package/dist/src/print/printListeners.d.ts +1 -2
  54. package/dist/src/print/printListeners.js +9 -9
  55. package/dist/src/print/printListeners.js.map +1 -1
  56. package/dist/src/print/printProps.d.ts +1 -2
  57. package/dist/src/print/printProps.js +6 -5
  58. package/dist/src/print/printProps.js.map +1 -1
  59. package/dist/src/print/printReducer.d.ts +1 -2
  60. package/dist/src/print/printReducer.js +6 -6
  61. package/dist/src/print/printReducer.js.map +1 -1
  62. package/dist/src/print/printReducerOptions.d.ts +1 -2
  63. package/dist/src/print/printReducerOptions.js +3 -3
  64. package/dist/src/print/printReducerOptions.js.map +1 -1
  65. package/dist/src/print/printReducers.d.ts +1 -2
  66. package/dist/src/print/printReducers.js +7 -7
  67. package/dist/src/print/printReducers.js.map +1 -1
  68. package/dist/src/print/printSelector.d.ts +1 -2
  69. package/dist/src/print/printSelector.js +4 -4
  70. package/dist/src/print/printSelector.js.map +1 -1
  71. package/dist/src/print/printSelectors.d.ts +1 -2
  72. package/dist/src/print/printSelectors.js +6 -6
  73. package/dist/src/print/printSelectors.js.map +1 -1
  74. package/dist/src/print/printSharedListeners.d.ts +1 -2
  75. package/dist/src/print/printSharedListeners.js +11 -11
  76. package/dist/src/print/printSharedListeners.js.map +1 -1
  77. package/dist/src/print/printValues.d.ts +1 -2
  78. package/dist/src/print/printValues.js +3 -3
  79. package/dist/src/print/printValues.js.map +1 -1
  80. package/dist/src/typegen.js +5 -5
  81. package/dist/src/typegen.js.map +1 -1
  82. package/dist/src/types.d.ts +6 -0
  83. package/dist/src/utils.js +21 -18
  84. package/dist/src/utils.js.map +1 -1
  85. package/dist/src/visit/__tests__/visit.js +2 -2
  86. package/dist/src/visit/__tests__/visit.js.map +1 -1
  87. package/dist/src/visit/visit.js +22 -14
  88. package/dist/src/visit/visit.js.map +1 -1
  89. package/dist/src/visit/visitActions.d.ts +2 -2
  90. package/dist/src/visit/visitActions.js +13 -11
  91. package/dist/src/visit/visitActions.js.map +1 -1
  92. package/dist/src/visit/visitConnect.js +4 -4
  93. package/dist/src/visit/visitConnect.js.map +1 -1
  94. package/dist/src/visit/visitDefaults.js +1 -1
  95. package/dist/src/visit/visitDefaults.js.map +1 -1
  96. package/dist/src/visit/visitKey.js +2 -2
  97. package/dist/src/visit/visitKey.js.map +1 -1
  98. package/dist/src/visit/visitListeners.js +5 -5
  99. package/dist/src/visit/visitListeners.js.map +1 -1
  100. package/dist/src/visit/visitLoaders.d.ts +2 -2
  101. package/dist/src/visit/visitLoaders.js +27 -29
  102. package/dist/src/visit/visitLoaders.js.map +1 -1
  103. package/dist/src/visit/visitProps.js +1 -1
  104. package/dist/src/visit/visitProps.js.map +1 -1
  105. package/dist/src/visit/visitReducers.js +4 -4
  106. package/dist/src/visit/visitReducers.js.map +1 -1
  107. package/dist/src/visit/visitSelectors.js +8 -8
  108. package/dist/src/visit/visitSelectors.js.map +1 -1
  109. package/dist/src/visit/visitSharedListeners.js +5 -5
  110. package/dist/src/visit/visitSharedListeners.js.map +1 -1
  111. package/dist/src/visit/visitWindowValues.js +1 -1
  112. package/dist/src/visit/visitWindowValues.js.map +1 -1
  113. package/dist/src/write/write.d.ts +4 -0
  114. package/dist/src/{import/writeLogicTypeImports.js → write/write.js} +56 -11
  115. package/dist/src/write/write.js.map +1 -0
  116. package/dist/tsconfig.tsbuildinfo +1 -1
  117. package/form-plugin/lib/form-plugin/src/typegen.js +16 -15
  118. package/form-plugin/lib/src/types.d.ts +4 -1
  119. package/form-plugin/package.json +1 -1
  120. package/form-plugin/src/typegen.ts +25 -25
  121. package/form-plugin/tsconfig.json +0 -1
  122. package/form-plugin/yarn.lock +10 -10
  123. package/package.json +18 -17
  124. package/samples/.kearc +3 -0
  125. package/samples/autoImportLogic.ts +12 -3
  126. package/samples/autoImportLogicType.ts +7 -2
  127. package/samples/complexLogic.ts +4 -3
  128. package/samples/donotimport.ts +1 -0
  129. package/samples/githubConnectLogic.ts +1 -0
  130. package/samples/githubImportLogic.ts +1 -0
  131. package/samples/githubLogic.ts +1 -0
  132. package/samples/loadersLogic.ts +1 -0
  133. package/samples/loadersLogicType.ts +9 -9
  134. package/samples/logicType.ts +4 -4
  135. package/samples/pluginLogic.ts +2 -0
  136. package/samples/propsLogic.ts +1 -0
  137. package/samples/propsLogicType.ts +9 -9
  138. package/samples/windowValuesLogic.ts +1 -0
  139. package/src/__tests__/e2e/__snapshots__/loaders.ts.snap +10 -10
  140. package/src/__tests__/utils.ts +5 -5
  141. package/src/cli/typegen.ts +33 -7
  142. package/src/print/print.ts +97 -37
  143. package/src/print/printActionCreators.ts +12 -15
  144. package/src/print/printActionKeys.ts +5 -6
  145. package/src/print/printActionTypes.ts +6 -7
  146. package/src/print/printActions.ts +6 -13
  147. package/src/print/printConstants.ts +5 -6
  148. package/src/print/printDefaults.ts +5 -6
  149. package/src/print/printEvents.ts +8 -6
  150. package/src/print/printInternalExtraInput.ts +12 -13
  151. package/src/print/printInternalReducerActions.ts +5 -12
  152. package/src/print/printInternalSelectorTypes.ts +7 -8
  153. package/src/print/printKey.ts +2 -2
  154. package/src/print/printListeners.ts +16 -17
  155. package/src/print/printProps.ts +7 -7
  156. package/src/print/printReducer.ts +14 -15
  157. package/src/print/printReducerOptions.ts +4 -5
  158. package/src/print/printReducers.ts +13 -14
  159. package/src/print/printSelector.ts +8 -9
  160. package/src/print/printSelectors.ts +12 -13
  161. package/src/print/printSharedListeners.ts +20 -21
  162. package/src/print/printValues.ts +5 -6
  163. package/src/typegen.ts +4 -4
  164. package/src/types.ts +11 -1
  165. package/src/utils.ts +17 -17
  166. package/src/visit/visit.ts +11 -3
  167. package/src/visit/visitActions.ts +12 -10
  168. package/src/visit/visitListeners.ts +8 -8
  169. package/src/visit/visitLoaders.ts +49 -45
  170. package/src/visit/visitReducers.ts +1 -1
  171. package/src/visit/visitSelectors.ts +3 -3
  172. package/src/visit/visitSharedListeners.ts +8 -10
  173. package/src/{import/writeLogicTypeImports.ts → write/write.ts} +115 -16
  174. package/dist/src/import/writeLogicTypeImports.d.ts +0 -3
  175. package/dist/src/import/writeLogicTypeImports.js.map +0 -1
@@ -46,6 +46,15 @@ yargs
46
46
  })
47
47
  .option('quiet', { alias: 'q', describe: 'Write nothing to stdout', type: 'boolean' })
48
48
  .option('no-import', { describe: 'Do not automatically import generated types in logic files', type: 'boolean' })
49
+ .option('write-paths', { describe: 'Write paths into logic files that have none', type: 'boolean' })
50
+ .option('import-global-types', {
51
+ describe: 'Add import statements in logicType.ts files for global types (e.g. @types/node)',
52
+ type: 'boolean',
53
+ })
54
+ .option('ignore-import-paths', {
55
+ describe: 'List of paths we will never import from inside logicType.ts files',
56
+ type: 'array',
57
+ })
49
58
  .option('verbose', { describe: 'Slightly more verbose output log', type: 'boolean' })
50
59
  .demandCommand()
51
60
  .help()
@@ -60,18 +69,21 @@ function parsedToAppOptions(parsedOptions) {
60
69
  quiet: parsedOptions.quiet,
61
70
  verbose: parsedOptions.verbose,
62
71
  noImport: parsedOptions.noImport,
72
+ writePaths: parsedOptions.writePaths,
73
+ importGlobalTypes: parsedOptions.importGlobalTypes,
74
+ ignoreImportPaths: parsedOptions.ignoreImportPaths,
63
75
  log: parsedOptions.quiet ? () => null : console.log.bind(console),
64
76
  } as AppOptions
65
77
 
66
78
  return appOptions
67
79
  }
68
80
 
69
- function findKeaConfig(): string {
70
- return ts.findConfigFile('./', ts.sys.fileExists, '.kearc')
81
+ function findKeaConfig(searchPath): string {
82
+ return ts.findConfigFile(searchPath, ts.sys.fileExists, '.kearc')
71
83
  }
72
84
 
73
85
  function includeKeaConfig(appOptions: AppOptions): AppOptions {
74
- const configFilePath = findKeaConfig()
86
+ const configFilePath = findKeaConfig(appOptions.rootPath)
75
87
  const newOptions = { ...appOptions } as AppOptions
76
88
 
77
89
  let rawData, keaConfig
@@ -105,16 +117,18 @@ function includeKeaConfig(appOptions: AppOptions): AppOptions {
105
117
  // set all paths in .kearc to be relative from where the file is located
106
118
  if (key.endsWith('Path')) {
107
119
  newOptions[key] = path.resolve(process.cwd(), configDirPath, keaConfig[key])
120
+ } else if (key.endsWith('Paths')) {
121
+ if (!Array.isArray(keaConfig[key])) {
122
+ console.error(`Config "${key}" in ".kearc" is not an array`)
123
+ process.exit(1)
124
+ }
125
+ newOptions[key] = keaConfig[key].map((value) => path.resolve(process.cwd(), configDirPath, value))
108
126
  } else {
109
127
  newOptions[key] = keaConfig[key]
110
128
  }
111
129
  })
112
130
  }
113
131
 
114
- if (!newOptions.tsConfigPath) {
115
- newOptions.tsConfigPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json')
116
- }
117
-
118
132
  if (!newOptions.rootPath) {
119
133
  newOptions.rootPath = newOptions.tsConfigPath ? path.dirname(newOptions.tsConfigPath) : process.cwd()
120
134
  }
@@ -123,5 +137,17 @@ function includeKeaConfig(appOptions: AppOptions): AppOptions {
123
137
  newOptions.typesPath = newOptions.rootPath
124
138
  }
125
139
 
140
+ if (!newOptions.tsConfigPath) {
141
+ newOptions.tsConfigPath =
142
+ ts.findConfigFile(newOptions.rootPath, ts.sys.fileExists, 'tsconfig.json') ||
143
+ ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json')
144
+ }
145
+
146
+ if (!newOptions.packageJsonPath) {
147
+ newOptions.packageJsonPath =
148
+ ts.findConfigFile(newOptions.rootPath, ts.sys.fileExists, 'package.json') ||
149
+ ts.findConfigFile('./', ts.sys.fileExists, 'package.json')
150
+ }
151
+
126
152
  return newOptions
127
153
  }
@@ -1,4 +1,16 @@
1
- import * as ts from 'typescript'
1
+ import {
2
+ createPrinter,
3
+ createSourceFile,
4
+ EmitHint,
5
+ factory,
6
+ Node,
7
+ NewLineKind,
8
+ Program,
9
+ ScriptKind,
10
+ ScriptTarget,
11
+ SyntaxKind,
12
+ TypeParameterDeclaration,
13
+ } from 'typescript'
2
14
  import * as fs from 'fs'
3
15
  import * as path from 'path'
4
16
  import * as prettier from 'prettier'
@@ -23,7 +35,7 @@ import { printReducerOptions } from './printReducerOptions'
23
35
  import { printEvents } from './printEvents'
24
36
  import { printSharedListeners } from './printSharedListeners'
25
37
  import { printListeners } from './printListeners'
26
- import { writeLogicTypeImports } from '../import/writeLogicTypeImports'
38
+ import { writePaths, writeTypeImports } from '../write/write'
27
39
  import { printInternalExtraInput } from './printInternalExtraInput'
28
40
 
29
41
  export function runThroughPrettier(sourceText: string, filePath: string): string {
@@ -43,10 +55,10 @@ export function runThroughPrettier(sourceText: string, filePath: string): string
43
55
 
44
56
  // returns files to write
45
57
  export function printToFiles(
46
- program: ts.Program,
58
+ program: Program,
47
59
  appOptions: AppOptions,
48
60
  parsedLogics: ParsedLogic[],
49
- ): { filesToWrite: number; writtenFiles: number; importsToModify: number } {
61
+ ): { filesToWrite: number; writtenFiles: number; filesToModify: number } {
50
62
  const { log } = appOptions
51
63
 
52
64
  const groupedByFile: Record<string, ParsedLogic[]> = {}
@@ -56,13 +68,38 @@ export function printToFiles(
56
68
  }
57
69
  groupedByFile[parsedLogic.fileName].push(parsedLogic)
58
70
 
59
- // create the ts.Nodes and gather referenced types
71
+ // create the Nodes and gather referenced types
60
72
  printLogicType(parsedLogic, appOptions)
61
73
  }
62
74
 
75
+ // Automatically ignore imports from "node_modules/@types/node", if {types: ["node"]} in tsconfig.json
76
+ const defaultGlobalTypePaths = appOptions.importGlobalTypes
77
+ ? []
78
+ : program
79
+ .getCompilerOptions()
80
+ .types.map(
81
+ (type) =>
82
+ path.join(
83
+ appOptions.packageJsonPath ? path.dirname(appOptions.packageJsonPath) : appOptions.rootPath,
84
+ 'node_modules',
85
+ '@types',
86
+ type,
87
+ ) + path.sep,
88
+ )
89
+
90
+ // Manually ignored
91
+ const ignoredImportPaths = (appOptions.ignoreImportPaths || []).map((importPath) =>
92
+ path.resolve(appOptions.rootPath, importPath),
93
+ )
94
+
95
+ const doNotImportFromPaths = [...defaultGlobalTypePaths, ...ignoredImportPaths]
96
+
97
+ const shouldIgnore = (absolutePath: string) =>
98
+ !!doNotImportFromPaths.find((badPath) => absolutePath.startsWith(badPath))
99
+
63
100
  let writtenFiles = 0
64
101
  let filesToWrite = 0
65
- let importsToModify = 0
102
+ let filesToModify = 0
66
103
 
67
104
  Object.entries(groupedByFile).forEach(([fileName, parsedLogics]) => {
68
105
  const typeFileName = parsedLogics[0].typeFileName
@@ -88,8 +125,14 @@ export function printToFiles(
88
125
  if (!relativePath.startsWith('.')) {
89
126
  relativePath = `./${relativePath}`
90
127
  }
91
- return `import { ${[...list].sort().join(', ')} } from '${relativePath}'`
128
+ return {
129
+ list: [...list].sort(),
130
+ fullPath: file,
131
+ relativePath,
132
+ }
92
133
  })
134
+ .filter(({ fullPath }) => !shouldIgnore(fullPath))
135
+ .map(({ list, relativePath }) => `import { ${list.join(', ')} } from '${relativePath}'`)
93
136
  .join('\n')
94
137
 
95
138
  const finalOutput = [
@@ -129,19 +172,19 @@ export function printToFiles(
129
172
  }
130
173
  }
131
174
 
175
+ const parsedLogicNeedsTypeImport = (pl: ParsedLogic) =>
176
+ // reload if logic type not imported
177
+ (pl.logicTypeImported === false ||
178
+ // reload if don't have the right types in arguments
179
+ pl.logicTypeArguments.join(', ') !== [...pl.typeReferencesInLogicInput].sort().join(', ')) &&
180
+ pl.fileName.match(/\.tsx?$/)
181
+
132
182
  // write the type into the logic itself
133
- const logicsNeedingImports = parsedLogics.filter(
134
- (pl) =>
135
- // reload if logic type not imported
136
- (pl.logicTypeImported === false ||
137
- // reload if don't have the right types in arguments
138
- pl.logicTypeArguments.join(', ') !== [...pl.typeReferencesInLogicInput].sort().join(', ')) &&
139
- pl.fileName.match(/\.tsx?$/),
140
- )
183
+ const logicsNeedingImports = parsedLogics.filter(parsedLogicNeedsTypeImport)
141
184
  if (logicsNeedingImports.length > 0) {
142
185
  if (appOptions.write && !appOptions.noImport) {
143
- writeLogicTypeImports(appOptions, program, fileName, logicsNeedingImports, parsedLogics)
144
- importsToModify = logicsNeedingImports.length
186
+ writeTypeImports(appOptions, program, fileName, logicsNeedingImports, parsedLogics)
187
+ filesToModify += logicsNeedingImports.length
145
188
  } else {
146
189
  log(
147
190
  `❌ Will not write ${logicsNeedingImports.length} logic type import${
@@ -150,28 +193,43 @@ export function printToFiles(
150
193
  )
151
194
  }
152
195
  }
196
+
197
+ const parsedLogicNeedsPath = appOptions.writePaths ? (pl: ParsedLogic) => !pl.hasPathInLogic : () => false
198
+ const logicsNeedingPaths = parsedLogics.filter(parsedLogicNeedsPath)
199
+ if (logicsNeedingPaths.length > 0) {
200
+ if (appOptions.write && !appOptions.noImport) {
201
+ writePaths(appOptions, program, fileName, logicsNeedingPaths)
202
+ filesToModify += logicsNeedingPaths.length
203
+ } else {
204
+ log(
205
+ `❌ Will not write ${logicsNeedingPaths.length} logic path${
206
+ logicsNeedingPaths.length === 1 ? '' : 's'
207
+ }`,
208
+ )
209
+ }
210
+ }
153
211
  })
154
212
 
155
- if (writtenFiles === 0 && importsToModify === 0) {
213
+ if (writtenFiles === 0 && filesToModify === 0) {
156
214
  if (appOptions.write) {
157
215
  log(`💚 ${parsedLogics.length} logic type${parsedLogics.length === 1 ? '' : 's'} up to date!`)
158
216
  log('')
159
- } else if (filesToWrite > 0 || importsToModify > 0) {
217
+ } else if (filesToWrite > 0 || filesToModify > 0) {
160
218
  log(
161
- `🚨 Run "kea-typegen write" to save ${filesToWrite + importsToModify} file${
219
+ `🚨 Run "kea-typegen write" to save ${filesToWrite + filesToModify} file${
162
220
  filesToWrite === 1 ? '' : 's'
163
221
  } to disk`,
164
222
  )
165
223
  }
166
224
  }
167
225
 
168
- return { filesToWrite, writtenFiles, importsToModify }
226
+ return { filesToWrite, writtenFiles, filesToModify }
169
227
  }
170
228
 
171
- export function nodeToString(node: ts.Node): string {
172
- const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })
173
- const sourceFile = ts.createSourceFile('logic.ts', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS)
174
- return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile)
229
+ export function nodeToString(node: Node): string {
230
+ const printer = createPrinter({ newLine: NewLineKind.LineFeed })
231
+ const sourceFile = createSourceFile('logic.ts', '', ScriptTarget.Latest, false, ScriptKind.TS)
232
+ return printer.printNode(EmitHint.Unspecified, node, sourceFile)
175
233
  }
176
234
 
177
235
  export function parsedLogicToTypeString(parsedLogic: ParsedLogic, appOptions?: AppOptions): string {
@@ -179,15 +237,15 @@ export function parsedLogicToTypeString(parsedLogic: ParsedLogic, appOptions?: A
179
237
  return nodeToString(parsedLogic.interfaceDeclaration)
180
238
  }
181
239
 
182
- export function getLogicTypeArguments(parsedLogic: ParsedLogic): ts.TypeParameterDeclaration[] {
240
+ export function getLogicTypeArguments(parsedLogic: ParsedLogic): TypeParameterDeclaration[] {
183
241
  return [...parsedLogic.typeReferencesInLogicInput]
184
242
  .sort()
185
- .map((text) => ts.createTypeParameterDeclaration(ts.createIdentifier(text), undefined))
243
+ .map((text) => factory.createTypeParameterDeclaration(factory.createIdentifier(text), undefined))
186
244
  }
187
245
 
188
246
  export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions): void {
189
247
  const printProperty = (name, typeNode) =>
190
- ts.createPropertySignature(undefined, ts.createIdentifier(name), undefined, typeNode, undefined)
248
+ factory.createPropertySignature(undefined, factory.createIdentifier(name), undefined, typeNode)
191
249
 
192
250
  const addSelectorTypeHelp = parsedLogic.selectors.filter((s) => s.functionTypes.length > 0).length > 0
193
251
 
@@ -203,9 +261,11 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
203
261
  printProperty('listeners', printListeners(parsedLogic)),
204
262
  printProperty(
205
263
  'path',
206
- ts.createTupleTypeNode(parsedLogic.path.map((p) => ts.createLiteralTypeNode(ts.createStringLiteral(p)))),
264
+ factory.createTupleTypeNode(
265
+ parsedLogic.path.map((p) => factory.createLiteralTypeNode(factory.createStringLiteral(p))),
266
+ ),
207
267
  ),
208
- printProperty('pathString', ts.createStringLiteral(parsedLogic.pathString)),
268
+ printProperty('pathString', factory.createStringLiteral(parsedLogic.pathString)),
209
269
  printProperty('props', printProps(parsedLogic)),
210
270
  printProperty('reducer', printReducer(parsedLogic)),
211
271
  printProperty('reducerOptions', printReducerOptions(parsedLogic)),
@@ -214,8 +274,8 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
214
274
  printProperty('selectors', printSelectors(parsedLogic)),
215
275
  printProperty('sharedListeners', printSharedListeners(parsedLogic)),
216
276
  printProperty('values', printValues(parsedLogic)),
217
- printProperty('_isKea', ts.createTrue()),
218
- printProperty('_isKeaWithKey', parsedLogic.keyType ? ts.createTrue() : ts.createFalse()),
277
+ printProperty('_isKea', factory.createTrue()),
278
+ printProperty('_isKeaWithKey', parsedLogic.keyType ? factory.createTrue() : factory.createFalse()),
219
279
  addSelectorTypeHelp
220
280
  ? printProperty('__keaTypeGenInternalSelectorTypes', printInternalSelectorTypes(parsedLogic))
221
281
  : null,
@@ -229,14 +289,14 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
229
289
 
230
290
  const logicTypeArguments = getLogicTypeArguments(parsedLogic)
231
291
 
232
- parsedLogic.interfaceDeclaration = ts.createInterfaceDeclaration(
292
+ parsedLogic.interfaceDeclaration = factory.createInterfaceDeclaration(
233
293
  undefined,
234
- [ts.createModifier(ts.SyntaxKind.ExportKeyword)],
235
- ts.createIdentifier(`${parsedLogic.logicName}Type`),
294
+ [factory.createModifier(SyntaxKind.ExportKeyword)],
295
+ factory.createIdentifier(`${parsedLogic.logicName}Type`),
236
296
  logicTypeArguments,
237
297
  [
238
- ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
239
- ts.createExpressionWithTypeArguments(undefined, ts.createIdentifier('Logic')),
298
+ factory.createHeritageClause(SyntaxKind.ExtendsKeyword, [
299
+ factory.createExpressionWithTypeArguments(factory.createIdentifier('Logic'), undefined),
240
300
  ]),
241
301
  ],
242
302
  logicProperties,
@@ -1,39 +1,36 @@
1
- import * as ts from 'typescript'
1
+ import { factory } from 'typescript'
2
2
  import { AppOptions, ParsedLogic } from '../types'
3
3
  import { getActionTypeCreator } from '../utils'
4
4
 
5
5
  export function printActionCreators(parsedLogic: ParsedLogic, appOptions?: AppOptions) {
6
6
  const getActionType = getActionTypeCreator(parsedLogic)
7
7
 
8
- return ts.createTypeLiteralNode(
8
+ return factory.createTypeLiteralNode(
9
9
  parsedLogic.actions.map(({ name, parameters, returnTypeNode }) => {
10
- return ts.createPropertySignature(
10
+ return factory.createPropertySignature(
11
11
  undefined,
12
- ts.createIdentifier(name),
12
+ factory.createIdentifier(name),
13
13
  undefined,
14
- ts.createFunctionTypeNode(
14
+ factory.createFunctionTypeNode(
15
15
  undefined,
16
16
  parameters,
17
- ts.createParenthesizedType(
18
- ts.createTypeLiteralNode([
19
- ts.createPropertySignature(
17
+ factory.createParenthesizedType(
18
+ factory.createTypeLiteralNode([
19
+ factory.createPropertySignature(
20
20
  undefined,
21
- ts.createIdentifier('type'),
22
- undefined,
23
- ts.createLiteralTypeNode(ts.createStringLiteral(getActionType(name))),
21
+ factory.createIdentifier('type'),
24
22
  undefined,
23
+ factory.createLiteralTypeNode(factory.createStringLiteral(getActionType(name))),
25
24
  ),
26
- ts.createPropertySignature(
25
+ factory.createPropertySignature(
27
26
  undefined,
28
- ts.createIdentifier('payload'),
27
+ factory.createIdentifier('payload'),
29
28
  undefined,
30
29
  returnTypeNode,
31
- undefined,
32
30
  ),
33
31
  ]),
34
32
  ),
35
33
  ),
36
- undefined,
37
34
  )
38
35
  }),
39
36
  )
@@ -1,18 +1,17 @@
1
- import * as ts from 'typescript'
1
+ import { factory } from 'typescript'
2
2
  import { AppOptions, ParsedLogic } from '../types'
3
3
  import { getActionTypeCreator } from '../utils'
4
4
 
5
5
  export function printActionKeys(parsedLogic: ParsedLogic, appOptions?: AppOptions) {
6
6
  const getActionType = getActionTypeCreator(parsedLogic)
7
7
 
8
- return ts.createTypeLiteralNode(
8
+ return factory.createTypeLiteralNode(
9
9
  parsedLogic.actions.map(({ name, parameters, returnTypeNode }) => {
10
- return ts.createPropertySignature(
10
+ return factory.createPropertySignature(
11
11
  undefined,
12
- ts.createStringLiteral(getActionType(name)),
13
- undefined,
14
- ts.createLiteralTypeNode(ts.createStringLiteral(name)),
12
+ factory.createStringLiteral(getActionType(name)),
15
13
  undefined,
14
+ factory.createLiteralTypeNode(factory.createStringLiteral(name)),
16
15
  )
17
16
  }),
18
17
  )
@@ -1,18 +1,17 @@
1
- import * as ts from 'typescript'
1
+ import { factory } from 'typescript'
2
2
  import { AppOptions, ParsedLogic } from '../types'
3
3
  import { getActionTypeCreator } from '../utils'
4
4
 
5
5
  export function printActionTypes(parsedLogic: ParsedLogic, appOptions?: AppOptions) {
6
6
  const getActionType = getActionTypeCreator(parsedLogic)
7
7
 
8
- return ts.createTypeLiteralNode(
9
- parsedLogic.actions.map(({ name, parameters, returnTypeNode }) => {
10
- return ts.createPropertySignature(
8
+ return factory.createTypeLiteralNode(
9
+ parsedLogic.actions.map(({ name }) => {
10
+ return factory.createPropertySignature(
11
11
  undefined,
12
- ts.createIdentifier(name),
13
- undefined,
14
- ts.createLiteralTypeNode(ts.createStringLiteral(getActionType(name))),
12
+ factory.createIdentifier(name),
15
13
  undefined,
14
+ factory.createLiteralTypeNode(factory.createStringLiteral(getActionType(name))),
16
15
  )
17
16
  }),
18
17
  )
@@ -1,24 +1,17 @@
1
- import * as ts from 'typescript'
1
+ import { factory, SyntaxKind } from 'typescript'
2
2
  import { AppOptions, ParsedLogic } from '../types'
3
3
  import { getActionTypeCreator } from '../utils'
4
4
 
5
5
  export function printActions(parsedLogic: ParsedLogic, appOptions?: AppOptions) {
6
6
  const getActionType = getActionTypeCreator(parsedLogic)
7
7
 
8
- return ts.createTypeLiteralNode(
9
- parsedLogic.actions.map(({ name, parameters, returnTypeNode }) => {
10
- return ts.createPropertySignature(
8
+ return factory.createTypeLiteralNode(
9
+ parsedLogic.actions.map(({ name, parameters }) => {
10
+ return factory.createPropertySignature(
11
11
  undefined,
12
- ts.createIdentifier(name),
13
- undefined,
14
- ts.createFunctionTypeNode(
15
- undefined,
16
- parameters,
17
- // Please someone tell me what must I do here?
18
- // Just ts.createToken(void), as suggested by ts-ast-viewer.com doesn't work
19
- { ...ts.createToken(ts.SyntaxKind.VoidKeyword), _typeNodeBrand: true }
20
- ),
12
+ factory.createIdentifier(name),
21
13
  undefined,
14
+ factory.createFunctionTypeNode(undefined, parameters, factory.createToken(SyntaxKind.VoidKeyword)),
22
15
  )
23
16
  }),
24
17
  )
@@ -1,15 +1,14 @@
1
- import * as ts from 'typescript'
1
+ import { factory } from 'typescript'
2
2
  import { ParsedLogic } from '../types'
3
3
 
4
4
  export function printConstants(parsedLogic: ParsedLogic) {
5
- return ts.createTypeLiteralNode(
5
+ return factory.createTypeLiteralNode(
6
6
  parsedLogic.constants.map((constant) =>
7
- ts.createPropertySignature(
7
+ factory.createPropertySignature(
8
8
  undefined,
9
- ts.createStringLiteral(constant),
10
- undefined,
11
- ts.createLiteralTypeNode(ts.createStringLiteral(constant)),
9
+ factory.createStringLiteral(constant),
12
10
  undefined,
11
+ factory.createLiteralTypeNode(factory.createStringLiteral(constant)),
13
12
  ),
14
13
  ),
15
14
  )
@@ -1,16 +1,15 @@
1
- import * as ts from 'typescript'
1
+ import { factory } from 'typescript'
2
2
  import { ParsedLogic } from '../types'
3
- import {cleanDuplicateAnyNodes} from "../utils";
3
+ import { cleanDuplicateAnyNodes } from '../utils'
4
4
 
5
5
  export function printDefaults(parsedLogic: ParsedLogic) {
6
- return ts.createTypeLiteralNode(
6
+ return factory.createTypeLiteralNode(
7
7
  cleanDuplicateAnyNodes(parsedLogic.reducers).map((reducer) => {
8
- return ts.createPropertySignature(
8
+ return factory.createPropertySignature(
9
9
  undefined,
10
- ts.createIdentifier(reducer.name),
10
+ factory.createIdentifier(reducer.name),
11
11
  undefined,
12
12
  reducer.typeNode,
13
- undefined,
14
13
  )
15
14
  }),
16
15
  )
@@ -1,15 +1,17 @@
1
- import * as ts from 'typescript'
1
+ import { factory, SyntaxKind } from 'typescript'
2
2
  import { ParsedLogic } from '../types'
3
3
 
4
4
  export function printEvents(parsedLogic: ParsedLogic) {
5
- return ts.createTypeLiteralNode(
5
+ return factory.createTypeLiteralNode(
6
6
  Object.keys(parsedLogic.events).map((name) => {
7
- return ts.createPropertySignature(
7
+ return factory.createPropertySignature(
8
8
  undefined,
9
- ts.createIdentifier(name),
10
- undefined,
11
- ts.createFunctionTypeNode(undefined, [], { ...ts.createToken(ts.SyntaxKind.VoidKeyword), _typeNodeBrand: true }),
9
+ factory.createIdentifier(name),
12
10
  undefined,
11
+ factory.createFunctionTypeNode(undefined, [], {
12
+ ...factory.createToken(SyntaxKind.VoidKeyword),
13
+ _typeNodeBrand: true,
14
+ }),
13
15
  )
14
16
  }),
15
17
  )
@@ -1,32 +1,32 @@
1
1
  import { ParsedLogic } from '../types'
2
- import * as ts from 'typescript'
2
+ import { factory } from 'typescript'
3
3
 
4
4
  export function printInternalExtraInput(parsedLogic: ParsedLogic) {
5
- return ts.createTypeLiteralNode(
5
+ return factory.createTypeLiteralNode(
6
6
  Object.entries(parsedLogic.extraInput).map(([type, { typeNode, withLogicFunction }]) => {
7
7
  if (withLogicFunction) {
8
8
  const logicTypeArguments = [...parsedLogic.typeReferencesInLogicInput]
9
9
  .sort()
10
- .map((text) => ts.createTypeReferenceNode(ts.createIdentifier(text), undefined))
10
+ .map((text) => factory.createTypeReferenceNode(factory.createIdentifier(text), undefined))
11
11
 
12
- return ts.createPropertySignature(
12
+ return factory.createPropertySignature(
13
13
  undefined,
14
- ts.createStringLiteral(type),
14
+ factory.createStringLiteral(type),
15
15
  undefined,
16
16
 
17
- ts.createUnionTypeNode([
17
+ factory.createUnionTypeNode([
18
18
  typeNode,
19
- ts.createFunctionTypeNode(
19
+ factory.createFunctionTypeNode(
20
20
  undefined,
21
21
  [
22
- ts.createParameter(
22
+ factory.createParameterDeclaration(
23
23
  undefined,
24
24
  undefined,
25
25
  undefined,
26
- ts.createIdentifier('logic'),
26
+ factory.createIdentifier('logic'),
27
27
  undefined,
28
- ts.createTypeReferenceNode(
29
- ts.createIdentifier(parsedLogic.logicTypeName),
28
+ factory.createTypeReferenceNode(
29
+ factory.createIdentifier(parsedLogic.logicTypeName),
30
30
  logicTypeArguments.length > 0 ? logicTypeArguments : undefined,
31
31
  ),
32
32
  undefined,
@@ -35,11 +35,10 @@ export function printInternalExtraInput(parsedLogic: ParsedLogic) {
35
35
  typeNode,
36
36
  ),
37
37
  ]),
38
- undefined,
39
38
  )
40
39
  }
41
40
 
42
- return ts.createPropertySignature(undefined, ts.createStringLiteral(type), undefined, typeNode, undefined)
41
+ return factory.createPropertySignature(undefined, factory.createStringLiteral(type), undefined, typeNode)
43
42
  }),
44
43
  )
45
44
  }
@@ -1,17 +1,10 @@
1
1
  import { ParsedLogic } from '../types'
2
- import * as ts from 'typescript'
2
+ import { factory } from 'typescript'
3
3
 
4
4
  export function printInternalReducerActions(parsedLogic: ParsedLogic) {
5
- return ts.createTypeLiteralNode(
6
- Object.entries(parsedLogic.extraActions)
7
- .map(([type, typeNode]) => {
8
- return ts.createPropertySignature(
9
- undefined,
10
- ts.createStringLiteral(type),
11
- undefined,
12
- typeNode,
13
- undefined,
14
- )
15
- }),
5
+ return factory.createTypeLiteralNode(
6
+ Object.entries(parsedLogic.extraActions).map(([type, typeNode]) => {
7
+ return factory.createPropertySignature(undefined, factory.createStringLiteral(type), undefined, typeNode)
8
+ }),
16
9
  )
17
10
  }
@@ -1,24 +1,24 @@
1
1
  import { ParsedLogic } from '../types'
2
- import * as ts from 'typescript'
2
+ import { factory } from 'typescript'
3
3
 
4
4
  export function printInternalSelectorTypes(parsedLogic: ParsedLogic) {
5
- return ts.createTypeLiteralNode(
5
+ return factory.createTypeLiteralNode(
6
6
  parsedLogic.selectors
7
7
  .filter((s) => s.functionTypes.length > 0)
8
8
  .map((selector) => {
9
- return ts.createPropertySignature(
9
+ return factory.createPropertySignature(
10
10
  undefined,
11
- ts.createIdentifier(selector.name),
11
+ factory.createIdentifier(selector.name),
12
12
  undefined,
13
13
 
14
- ts.createFunctionTypeNode(
14
+ factory.createFunctionTypeNode(
15
15
  undefined,
16
16
  selector.functionTypes.map((functionType, index) =>
17
- ts.createParameter(
17
+ factory.createParameterDeclaration(
18
18
  undefined,
19
19
  undefined,
20
20
  undefined,
21
- ts.createIdentifier(functionType.name),
21
+ factory.createIdentifier(functionType.name),
22
22
  undefined,
23
23
  functionType.type,
24
24
  undefined,
@@ -26,7 +26,6 @@ export function printInternalSelectorTypes(parsedLogic: ParsedLogic) {
26
26
  ),
27
27
  selector.typeNode,
28
28
  ),
29
- undefined,
30
29
  )
31
30
  }),
32
31
  )
@@ -1,6 +1,6 @@
1
- import * as ts from 'typescript'
1
+ import { factory, SyntaxKind } from 'typescript'
2
2
  import { ParsedLogic } from '../types'
3
3
 
4
4
  export function printKey(parsedLogic: ParsedLogic) {
5
- return parsedLogic.keyType || ts.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)
5
+ return parsedLogic.keyType || factory.createKeywordTypeNode(SyntaxKind.UndefinedKeyword)
6
6
  }