kea-typegen 3.4.0 → 3.4.2

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 (101) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/dist/package.json +23 -20
  3. package/dist/src/cli/typegen.js.map +1 -1
  4. package/dist/src/print/print.js +6 -5
  5. package/dist/src/print/print.js.map +1 -1
  6. package/dist/src/print/printActionCreators.js +2 -1
  7. package/dist/src/print/printActionCreators.js.map +1 -1
  8. package/dist/src/print/printActionKeys.js +2 -1
  9. package/dist/src/print/printActionKeys.js.map +1 -1
  10. package/dist/src/print/printActionTypes.js +2 -1
  11. package/dist/src/print/printActionTypes.js.map +1 -1
  12. package/dist/src/print/printActions.js +2 -1
  13. package/dist/src/print/printActions.js.map +1 -1
  14. package/dist/src/print/printAsyncActions.js +2 -1
  15. package/dist/src/print/printAsyncActions.js.map +1 -1
  16. package/dist/src/print/printDefaults.js +2 -1
  17. package/dist/src/print/printDefaults.js.map +1 -1
  18. package/dist/src/print/printEvents.js +2 -1
  19. package/dist/src/print/printEvents.js.map +1 -1
  20. package/dist/src/print/printInternalExtraInput.js +2 -1
  21. package/dist/src/print/printInternalExtraInput.js.map +1 -1
  22. package/dist/src/print/printInternalReducerActions.js +2 -1
  23. package/dist/src/print/printInternalReducerActions.js.map +1 -1
  24. package/dist/src/print/printInternalSelectorTypes.js +2 -1
  25. package/dist/src/print/printInternalSelectorTypes.js.map +1 -1
  26. package/dist/src/print/printKey.js +2 -1
  27. package/dist/src/print/printKey.js.map +1 -1
  28. package/dist/src/print/printListeners.js +2 -1
  29. package/dist/src/print/printListeners.js.map +1 -1
  30. package/dist/src/print/printProps.js +2 -1
  31. package/dist/src/print/printProps.js.map +1 -1
  32. package/dist/src/print/printReducer.js +2 -1
  33. package/dist/src/print/printReducer.js.map +1 -1
  34. package/dist/src/print/printReducers.js +2 -1
  35. package/dist/src/print/printReducers.js.map +1 -1
  36. package/dist/src/print/printSelector.js +2 -1
  37. package/dist/src/print/printSelector.js.map +1 -1
  38. package/dist/src/print/printSelectors.js +2 -1
  39. package/dist/src/print/printSelectors.js.map +1 -1
  40. package/dist/src/print/printSharedListeners.js +2 -1
  41. package/dist/src/print/printSharedListeners.js.map +1 -1
  42. package/dist/src/print/printValues.js +2 -1
  43. package/dist/src/print/printValues.js.map +1 -1
  44. package/dist/src/typegen.js +2 -1
  45. package/dist/src/typegen.js.map +1 -1
  46. package/dist/src/utils.js +21 -21
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/visit/visit.js +9 -6
  49. package/dist/src/visit/visit.js.map +1 -1
  50. package/dist/src/visit/visitActions.js +2 -1
  51. package/dist/src/visit/visitActions.js.map +1 -1
  52. package/dist/src/visit/visitConnect.js +2 -1
  53. package/dist/src/visit/visitConnect.js.map +1 -1
  54. package/dist/src/visit/visitDefaults.js +2 -1
  55. package/dist/src/visit/visitDefaults.js.map +1 -1
  56. package/dist/src/visit/visitEvents.js +2 -1
  57. package/dist/src/visit/visitEvents.js.map +1 -1
  58. package/dist/src/visit/visitKey.js +4 -2
  59. package/dist/src/visit/visitKey.js.map +1 -1
  60. package/dist/src/visit/visitListeners.js +2 -1
  61. package/dist/src/visit/visitListeners.js.map +1 -1
  62. package/dist/src/visit/visitLoaders.js +2 -1
  63. package/dist/src/visit/visitLoaders.js.map +1 -1
  64. package/dist/src/visit/visitPath.js +2 -1
  65. package/dist/src/visit/visitPath.js.map +1 -1
  66. package/dist/src/visit/visitProps.js +2 -1
  67. package/dist/src/visit/visitProps.js.map +1 -1
  68. package/dist/src/visit/visitReducers.js +2 -1
  69. package/dist/src/visit/visitReducers.js.map +1 -1
  70. package/dist/src/visit/visitSelectors.js +2 -1
  71. package/dist/src/visit/visitSelectors.js.map +1 -1
  72. package/dist/src/visit/visitSharedListeners.js +4 -2
  73. package/dist/src/visit/visitSharedListeners.js.map +1 -1
  74. package/dist/src/visit/visitWindowValues.js +4 -2
  75. package/dist/src/visit/visitWindowValues.js.map +1 -1
  76. package/dist/src/write/convertToBuilders.js +8 -2
  77. package/dist/src/write/convertToBuilders.js.map +1 -1
  78. package/dist/src/write/utils.js +5 -5
  79. package/dist/src/write/utils.js.map +1 -1
  80. package/dist/src/write/writePaths.js +2 -1
  81. package/dist/src/write/writePaths.js.map +1 -1
  82. package/dist/src/write/writeTypeImports.js +2 -1
  83. package/dist/src/write/writeTypeImports.js.map +1 -1
  84. package/dist/tsconfig.tsbuildinfo +1 -1
  85. package/form-plugin/lib/form-plugin/src/typegen.js +7 -17
  86. package/form-plugin/yarn.lock +661 -696
  87. package/package.json +23 -20
  88. package/samples/builderLogic.ts +56 -1
  89. package/samples/builderLogicType.ts +1334 -1
  90. package/samples/complexLogic.ts +20 -0
  91. package/samples/complexLogicType.ts +67 -10
  92. package/samples/inline-plugin/typegen.ts +9 -8
  93. package/samples/pluginLogic.ts +1 -1
  94. package/samples/pluginLogicType.ts +6 -6
  95. package/samples/typed-builder/typedForm.typegen.ts +1 -1
  96. package/src/utils.ts +1 -1
  97. package/src/visit/visit.ts +5 -3
  98. package/src/visit/visitKey.ts +2 -2
  99. package/src/visit/visitSharedListeners.ts +2 -2
  100. package/src/visit/visitWindowValues.ts +2 -2
  101. package/src/write/convertToBuilders.ts +10 -8
@@ -34,6 +34,26 @@ export type DashboardItemType = {
34
34
  key17: string
35
35
  key18: string
36
36
  key19: string
37
+ key20: string
38
+ key21: string
39
+ key22: string
40
+ key23: string
41
+ key24: string
42
+ key25: string
43
+ key26: string
44
+ key27: string
45
+ key28: string
46
+ key29: string
47
+ key30: string
48
+ key31: string
49
+ key32: string
50
+ key33: string
51
+ key34: string
52
+ key35: string
53
+ key36: string
54
+ key37: string
55
+ key38: string
56
+ key39: string
37
57
  }
38
58
  function newAction(element: HTMLElement | null): Partial<ActionType> {
39
59
  return {
@@ -1,4 +1,4 @@
1
- // Generated by kea-typegen on Wed, 19 Mar 2025 16:25:33 GMT. DO NOT EDIT THIS FILE MANUALLY.
1
+ // Generated by kea-typegen on Fri, 13 Jun 2025 10:53:30 GMT. DO NOT EDIT THIS FILE MANUALLY.
2
2
 
3
3
  import type { Logic } from 'kea'
4
4
 
@@ -101,7 +101,27 @@ export interface complexLogicType extends Logic {
101
101
  key18: string
102
102
  key19: string
103
103
  key2: string
104
+ key20: string
105
+ key21: string
106
+ key22: string
107
+ key23: string
108
+ key24: string
109
+ key25: string
110
+ key26: string
111
+ key27: string
112
+ key28: string
113
+ key29: string
104
114
  key3: string
115
+ key30: string
116
+ key31: string
117
+ key32: string
118
+ key33: string
119
+ key34: string
120
+ key35: string
121
+ key36: string
122
+ key37: string
123
+ key38: string
124
+ key39: string
105
125
  key4: string
106
126
  key5: string
107
127
  key6: string
@@ -269,7 +289,27 @@ export interface complexLogicType extends Logic {
269
289
  key18: string
270
290
  key19: string
271
291
  key2: string
292
+ key20: string
293
+ key21: string
294
+ key22: string
295
+ key23: string
296
+ key24: string
297
+ key25: string
298
+ key26: string
299
+ key27: string
300
+ key28: string
301
+ key29: string
272
302
  key3: string
303
+ key30: string
304
+ key31: string
305
+ key32: string
306
+ key33: string
307
+ key34: string
308
+ key35: string
309
+ key36: string
310
+ key37: string
311
+ key38: string
312
+ key39: string
273
313
  key4: string
274
314
  key5: string
275
315
  key6: string
@@ -305,7 +345,27 @@ export interface complexLogicType extends Logic {
305
345
  key18: string
306
346
  key19: string
307
347
  key2: string
348
+ key20: string
349
+ key21: string
350
+ key22: string
351
+ key23: string
352
+ key24: string
353
+ key25: string
354
+ key26: string
355
+ key27: string
356
+ key28: string
357
+ key29: string
308
358
  key3: string
359
+ key30: string
360
+ key31: string
361
+ key32: string
362
+ key33: string
363
+ key34: string
364
+ key35: string
365
+ key36: string
366
+ key37: string
367
+ key38: string
368
+ key39: string
309
369
  key4: string
310
370
  key5: string
311
371
  key6: string
@@ -317,17 +377,14 @@ export interface complexLogicType extends Logic {
317
377
  _isKea: true
318
378
  _isKeaWithKey: false
319
379
  __keaTypeGenInternalSelectorTypes: {
320
- selectedAction: (
321
- selectedActionId: number | 'new' | null,
322
- newActionForElement: HTMLElement | null,
323
- ) => ActionType | null
324
- initialValuesForForm: (selectedAction: ActionType | null) => ActionForm
380
+ selectedAction: (selectedActionId: number | 'new', newActionForElement: HTMLElement) => ActionType | null
381
+ initialValuesForForm: (selectedAction: ActionType) => ActionForm
325
382
  selectedEditedAction: (
326
- selectedAction: ActionType | null,
383
+ selectedAction: ActionType,
327
384
  initialValuesForForm: ActionForm,
328
- form: FormInstance | null,
329
- editingFields: AntdFieldData[] | null,
330
- inspectingElement: number | null,
385
+ form: FormInstance,
386
+ editingFields: AntdFieldData[],
387
+ inspectingElement: number,
331
388
  counter: number,
332
389
  ) => ActionForm
333
390
  }
@@ -1,5 +1,6 @@
1
1
  import { Plugin } from '../../src/types'
2
2
  import * as ts from 'typescript'
3
+ import { factory } from 'typescript'
3
4
 
4
5
  export default {
5
6
  visitKeaProperty({ name, parsedLogic, type }) {
@@ -10,12 +11,12 @@ export default {
10
11
  parsedLogic.actions.push({
11
12
  name: 'inlineAction',
12
13
  parameters: [],
13
- returnTypeNode: ts.factory.createTypeLiteralNode([
14
- ts.factory.createPropertySignature(
14
+ returnTypeNode: factory.createTypeLiteralNode([
15
+ factory.createPropertySignature(
15
16
  undefined,
16
- ts.factory.createIdentifier('value'),
17
+ factory.createIdentifier('value'),
17
18
  undefined,
18
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
19
+ factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
19
20
  ),
20
21
  ]),
21
22
  })
@@ -23,12 +24,12 @@ export default {
23
24
  // add reducer "form" to parsedLogic
24
25
  parsedLogic.reducers.push({
25
26
  name: 'inlineReducer',
26
- typeNode: ts.factory.createTypeLiteralNode([
27
- ts.factory.createPropertySignature(
27
+ typeNode: factory.createTypeLiteralNode([
28
+ factory.createPropertySignature(
28
29
  undefined,
29
- ts.factory.createIdentifier('asd'),
30
+ factory.createIdentifier('asd'),
30
31
  undefined,
31
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
32
+ factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
32
33
  ),
33
34
  ]),
34
35
  })
@@ -20,7 +20,7 @@ export const pluginLogic = kea<pluginLogicType>({
20
20
  })
21
21
 
22
22
  export const anotherPluginLogic = kea<anotherPluginLogicType>({
23
- path: ['pluginLogic'],
23
+ path: ['anotherPluginLogic'],
24
24
  form: ({ values }) => ({
25
25
  default: {
26
26
  name: 'john',
@@ -1,4 +1,4 @@
1
- // Generated by kea-typegen on Fri, 10 Jan 2025 11:14:06 GMT. DO NOT EDIT THIS FILE MANUALLY.
1
+ // Generated by kea-typegen on Thu, 19 Jun 2025 09:28:06 GMT. DO NOT EDIT THIS FILE MANUALLY.
2
2
 
3
3
  import type { Logic, NotReallyHereButImportedBecausePlugin } from 'kea'
4
4
 
@@ -136,17 +136,17 @@ export interface pluginLogicType extends Logic {
136
136
  export interface anotherPluginLogicType extends Logic {
137
137
  actionCreators: {
138
138
  submitForm: () => {
139
- type: 'submit form (pluginLogic)'
139
+ type: 'submit form (anotherPluginLogic)'
140
140
  payload: {
141
141
  value: boolean
142
142
  }
143
143
  }
144
144
  }
145
145
  actionKeys: {
146
- 'submit form (pluginLogic)': 'submitForm'
146
+ 'submit form (anotherPluginLogic)': 'submitForm'
147
147
  }
148
148
  actionTypes: {
149
- submitForm: 'submit form (pluginLogic)'
149
+ submitForm: 'submit form (anotherPluginLogic)'
150
150
  }
151
151
  actions: {
152
152
  submitForm: () => void
@@ -163,8 +163,8 @@ export interface anotherPluginLogicType extends Logic {
163
163
  events: {}
164
164
  key: undefined
165
165
  listeners: {}
166
- path: ['pluginLogic']
167
- pathString: 'pluginLogic'
166
+ path: ['anotherPluginLogic']
167
+ pathString: 'anotherPluginLogic'
168
168
  props: Record<string, unknown>
169
169
  reducer: (
170
170
  state: any,
@@ -74,7 +74,7 @@ export function typedForm({ parsedLogic, node, getTypeNodeForNode, prepareForPri
74
74
  undefined,
75
75
  [
76
76
  factory.createParameterDeclaration(
77
- undefined,
77
+ [],
78
78
  undefined,
79
79
  factory.createIdentifier('form'),
80
80
  undefined,
package/src/utils.ts CHANGED
@@ -70,7 +70,7 @@ export function getTypeNodeForNode(node: ts.Node, checker: ts.TypeChecker): ts.T
70
70
  } else if (ts.isArrayLiteralExpression(node) && node.elements.length === 0) {
71
71
  typeNode = factory.createArrayTypeNode(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword))
72
72
  } else {
73
- typeNode = checker.typeToTypeNode(checker.getTypeAtLocation(node), undefined, undefined)
73
+ typeNode = checker.typeToTypeNode(checker.getTypeAtLocation(node), undefined, NodeBuilderFlags.NoTruncation)
74
74
  }
75
75
  } else {
76
76
  typeNode = factory.createKeywordTypeNode(SyntaxKind.AnyKeyword)
@@ -25,6 +25,7 @@ import { visitEvents } from './visitEvents'
25
25
  import { visitDefaults } from './visitDefaults'
26
26
  import { visitSharedListeners } from './visitSharedListeners'
27
27
  import { cloneNode } from 'ts-clone-node'
28
+ import {NodeBuilderFlags} from "typescript";
28
29
 
29
30
  const visitFunctions = {
30
31
  actions: visitActions,
@@ -34,6 +35,7 @@ const visitFunctions = {
34
35
  key: visitKey,
35
36
  listeners: visitListeners,
36
37
  loaders: visitLoaders,
38
+ lazyLoaders: visitLoaders,
37
39
  path: visitPath,
38
40
  props: visitProps,
39
41
  reducers: visitReducers,
@@ -259,7 +261,7 @@ export function visitKeaCalls(
259
261
  }
260
262
  const name = symbol.getName()
261
263
  const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration)
262
- const typeNode = type ? checker.typeToTypeNode(type, undefined, undefined) : null
264
+ const typeNode = type ? checker.typeToTypeNode(type, undefined, NodeBuilderFlags.NoTruncation) : null
263
265
  calls.push({ name, type, typeNode, expression: inputProperty.initializer, typeBuilders: [] })
264
266
  }
265
267
  } else if (ts.isArrayLiteralExpression(input)) {
@@ -271,7 +273,7 @@ export function visitKeaCalls(
271
273
  const builderName = callExpression.expression.getText()
272
274
  const argument = callExpression.arguments[0]
273
275
  const type = checker.getTypeAtLocation(argument)
274
- const typeNode = type ? checker.typeToTypeNode(type, undefined, undefined) : null
276
+ const typeNode = type ? checker.typeToTypeNode(type, undefined, NodeBuilderFlags.NoTruncation) : null
275
277
 
276
278
  const identifier = callExpression.expression
277
279
  const symbol = checker.getSymbolAtLocation(identifier)
@@ -363,7 +365,7 @@ export function visitKeaCalls(
363
365
 
364
366
  if (typeNode && ts.isFunctionTypeNode(typeNode)) {
365
367
  type = type.getCallSignatures()[0].getReturnType()
366
- typeNode = type ? checker.typeToTypeNode(type, undefined, undefined) : null
368
+ typeNode = type ? checker.typeToTypeNode(type, undefined, NodeBuilderFlags.NoTruncation) : null
367
369
  }
368
370
 
369
371
  visitFunctions[name]?.(parsedLogic, type, expression)
@@ -1,10 +1,10 @@
1
1
  import { ParsedLogic } from '../types'
2
2
  import { cloneNodeSorted, gatherImports } from '../utils'
3
- import { Expression, Type } from 'typescript'
3
+ import {Expression, NodeBuilderFlags, Type} from 'typescript'
4
4
 
5
5
  export function visitKey(parsedLogic: ParsedLogic, type: Type, expression: Expression) {
6
6
  const { checker } = parsedLogic
7
- const typeNode = checker.typeToTypeNode(type, undefined, undefined)
7
+ const typeNode = checker.typeToTypeNode(type, undefined, NodeBuilderFlags.NoTruncation)
8
8
  gatherImports(typeNode, checker, parsedLogic)
9
9
 
10
10
  parsedLogic.keyType = cloneNodeSorted(typeNode)
@@ -1,7 +1,7 @@
1
1
  import { ParsedLogic } from '../types'
2
2
  import * as ts from 'typescript'
3
3
  import { cloneNodeSorted, gatherImports } from '../utils'
4
- import { Expression, Type } from 'typescript'
4
+ import {Expression, NodeBuilderFlags, Type} from 'typescript'
5
5
 
6
6
  export function visitSharedListeners(parsedLogic: ParsedLogic, type: Type, expression: Expression) {
7
7
  const { checker } = parsedLogic
@@ -15,7 +15,7 @@ export function visitSharedListeners(parsedLogic: ParsedLogic, type: Type, expre
15
15
  const firstParameter = value.parameters[0]
16
16
  if (firstParameter) {
17
17
  typeNode = cloneNodeSorted(
18
- checker.typeToTypeNode(checker.getTypeAtLocation(firstParameter), undefined, undefined),
18
+ checker.typeToTypeNode(checker.getTypeAtLocation(firstParameter), undefined, NodeBuilderFlags.NoTruncation),
19
19
  )
20
20
  gatherImports(typeNode, checker, parsedLogic)
21
21
  }
@@ -1,7 +1,7 @@
1
1
  import { ParsedLogic } from '../types'
2
2
  import * as ts from 'typescript'
3
3
  import { gatherImports } from '../utils'
4
- import { Expression, Type } from 'typescript'
4
+ import {Expression, NodeBuilderFlags, Type} from 'typescript'
5
5
 
6
6
  export function visitWindowValues(parsedLogic: ParsedLogic, type: Type, expression: Expression) {
7
7
  const { checker } = parsedLogic
@@ -14,7 +14,7 @@ export function visitWindowValues(parsedLogic: ParsedLogic, type: Type, expressi
14
14
  if (value && ts.isFunctionLike(value)) {
15
15
  const type = checker.getTypeOfSymbolAtLocation(property, value)
16
16
  const signature = type.getCallSignatures()[0]
17
- const typeNode = checker.typeToTypeNode(signature.getReturnType(), undefined, undefined)
17
+ const typeNode = checker.typeToTypeNode(signature.getReturnType(), undefined, NodeBuilderFlags.NoTruncation)
18
18
  gatherImports(typeNode, checker, parsedLogic)
19
19
 
20
20
  parsedLogic.reducers.push({ name, typeNode })
@@ -69,7 +69,7 @@ export function convertToBuilders(
69
69
  const arg = stmt.arguments[0]
70
70
 
71
71
  if (t.ObjectExpression.check(arg)) {
72
- const propertiesMap: Record<string, typeof t.ObjectProperty> = Object.fromEntries(
72
+ const propertiesMap = Object.fromEntries(
73
73
  arg.properties
74
74
  .map((p) => [t.ObjectProperty.check(p) && t.Identifier.check(p.key) ? p.key.name : null, p])
75
75
  .filter(([key]) => key !== null),
@@ -84,7 +84,7 @@ export function convertToBuilders(
84
84
  const renameTo =
85
85
  Array.isArray(importFromOrArray) && importFromOrArray.length > 1 ? importFromOrArray[1] : key
86
86
 
87
- newEntries.push(b.callExpression(b.identifier(renameTo), [propertiesMap[key].value as any]))
87
+ newEntries.push(b.callExpression(b.identifier(renameTo), [propertiesMap[key].value]))
88
88
  neededImports[importFrom] ??= []
89
89
  if (!neededImports[importFrom].find(([l]) => l === renameTo)) {
90
90
  neededImports[importFrom].push([renameTo, renameTo])
@@ -95,14 +95,16 @@ export function convertToBuilders(
95
95
  const unsupported = propertyKeys.filter((p) => !supportedProperties[p])
96
96
  if (unsupported.length > 0) {
97
97
  console.warn(
98
- `❗ Logic "${parsedLogic.logicName}", has unsupported keys: ${unsupported.join(', ')}`,
98
+ `❗ Logic "${parsedLogic.logicName}", converted unsupported keys (${unsupported.join(
99
+ ', ',
100
+ )}) to builders without imports`,
99
101
  )
100
102
  }
101
- // for (const key of unsupported) {
102
- // if (propertiesMap[key] && t.ObjectProperty.check(propertiesMap[key])) {
103
- // newEntries.push(b.callExpression(b.identifier(key), [propertiesMap[key]]))
104
- // }
105
- // }
103
+ for (const key of unsupported) {
104
+ if (propertiesMap[key] && t.ObjectProperty.check(propertiesMap[key])) {
105
+ newEntries.push(b.callExpression(b.identifier(key), [propertiesMap[key].value]))
106
+ }
107
+ }
106
108
 
107
109
  stmt.arguments[0] = b.arrayExpression(newEntries)
108
110
  }