kea-typegen 3.7.1 → 3.8.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 (51) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +33 -0
  3. package/dist/package.json +3 -1
  4. package/dist/src/__tests__/inline.d.ts +1 -0
  5. package/dist/src/__tests__/inline.js +606 -0
  6. package/dist/src/__tests__/inline.js.map +1 -0
  7. package/dist/src/cache.d.ts +1 -0
  8. package/dist/src/cache.js +19 -0
  9. package/dist/src/cache.js.map +1 -1
  10. package/dist/src/cli/typegen.js +9 -0
  11. package/dist/src/cli/typegen.js.map +1 -1
  12. package/dist/src/print/print.d.ts +6 -0
  13. package/dist/src/print/print.js +61 -42
  14. package/dist/src/print/print.js.map +1 -1
  15. package/dist/src/types.d.ts +9 -0
  16. package/dist/src/utils.d.ts +6 -0
  17. package/dist/src/utils.js +82 -1
  18. package/dist/src/utils.js.map +1 -1
  19. package/dist/src/visit/visit.js +7 -0
  20. package/dist/src/visit/visit.js.map +1 -1
  21. package/dist/src/visit/visitConnect.js +40 -0
  22. package/dist/src/visit/visitConnect.js.map +1 -1
  23. package/dist/src/visit/visitSelectors.js +14 -1
  24. package/dist/src/visit/visitSelectors.js.map +1 -1
  25. package/dist/src/write/writeInlineLogicTypes.d.ts +8 -0
  26. package/dist/src/write/writeInlineLogicTypes.js +259 -0
  27. package/dist/src/write/writeInlineLogicTypes.js.map +1 -0
  28. package/dist/src/write/writeTypeImports.d.ts +8 -0
  29. package/dist/src/write/writeTypeImports.js +3 -0
  30. package/dist/src/write/writeTypeImports.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +3 -1
  33. package/samples/manualTypedLogic.ts +20 -0
  34. package/samples-inline/counterLogic.ts +37 -0
  35. package/samples-inline/manualLogic.ts +20 -0
  36. package/samples-inline/profileLogic.ts +31 -0
  37. package/samples-inline/searchLogic.ts +32 -0
  38. package/samples-inline/tsconfig.json +17 -0
  39. package/samples-inline/types.ts +5 -0
  40. package/src/__tests__/inline.ts +747 -0
  41. package/src/cache.ts +19 -0
  42. package/src/cli/typegen.ts +10 -0
  43. package/src/print/print.ts +106 -59
  44. package/src/types.ts +15 -0
  45. package/src/utils.ts +124 -1
  46. package/src/visit/visit.ts +15 -0
  47. package/src/visit/visitConnect.ts +50 -0
  48. package/src/visit/visitSelectors.ts +26 -1
  49. package/src/write/writeInlineLogicTypes.ts +354 -0
  50. package/src/write/writeTypeImports.ts +4 -4
  51. package/tsconfig.json +1 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.8.0 - 2026-07-14
2
+
3
+ - Skip logics that are manually typed, e.g. `kea<MakeLogicType<Values, Actions>>(...)` or any other custom type in `kea<...>()`. Such logics are now left completely alone.
4
+ - Add a new `--inline` mode. Instead of writing `logicType.ts` files, it writes and keeps updated a `// Generated by kea-typegen` block directly above each `kea()` call: one interface per non-empty section (`logicValues`, `logicActions`, `logicProps`), tied together with `export type logicType = MakeLogicType<logicValues, logicActions, logicProps>`. Named props types are referenced directly instead of getting an interface. With `--delete`, obsolete `logicType.ts` files are removed when switching over. See `yarn samples:inline:write` / `yarn samples:inline:check` and the `samples-inline/` folder.
5
+
1
6
  ## 3.7.1 - 2026-06-26
2
7
 
3
8
  Make watch mode incremental. When a watched rebuild can be proven local, regenerate only the changed or affected Kea logic files and keep the existing full-pass fallback for ambiguous changes.
package/README.md CHANGED
@@ -5,3 +5,36 @@ Automatically generate types for `kea()` calls for [Kea 2.2+](https://keajs.org/
5
5
  ## Docs
6
6
 
7
7
  https://keajs.org/docs/intro/typescript
8
+
9
+ ## Inline mode
10
+
11
+ By default kea-typegen writes a `logicType.ts` file next to each logic. In inline mode it instead writes
12
+ a marked block of plain interfaces directly above the `kea()` call, tied together with kea's `MakeLogicType`:
13
+
14
+ ```ts
15
+ // Generated by kea-typegen. DO NOT EDIT THIS BLOCK MANUALLY.
16
+ export interface counterLogicValues {
17
+ counter: number
18
+ }
19
+
20
+ export interface counterLogicActions {
21
+ increment: (amount: number) => { amount: number }
22
+ }
23
+
24
+ export type counterLogicType = MakeLogicType<counterLogicValues, counterLogicActions>
25
+
26
+ export const counterLogic = kea<counterLogicType>({ ... })
27
+ ```
28
+
29
+ - `--inline` (CLI) or `"inline": true` (`.kearc`) — inline mode for every logic.
30
+ - `--inline-paths a b` (CLI) or `"inlinePaths": ["./scenes/foo"]` (`.kearc`) — inline mode only for logic
31
+ files under those paths; everything else keeps its `logicType.ts` file. Relative paths resolve against
32
+ the root path. Use this to migrate a large project directory by directory.
33
+ - A file that already carries a generated inline block stays inline even without either option, so
34
+ conversions never regress and single files can be converted with `kea-typegen write --inline -f <file>`.
35
+ - With `--delete`, the now obsolete `logicType.ts` files are removed on conversion.
36
+ - Untyped selector combiner parameters get their inferred types written into the source
37
+ (`(counter) => ...` becomes `(counter: number) => ...`), since `MakeLogicType` types them as `any`.
38
+ - Values and actions pulled in via `connect` are marked with their source logic, e.g.
39
+ `user: UserType | null // userLogic`.
40
+ - Logics manually typed with `kea<MakeLogicType<...>>()` or a custom type are left alone entirely.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kea-typegen",
3
- "version": "3.7.1",
3
+ "version": "3.8.1",
4
4
  "description": "Generate type definitions for kea logic",
5
5
  "scripts": {
6
6
  "start": "ts-node ./src/cli/typegen.ts",
@@ -13,6 +13,8 @@
13
13
  "samples:write": "ts-node ./src/cli/typegen.ts write -r ./samples --write-paths --delete",
14
14
  "samples:convert": "ts-node ./src/cli/typegen.ts write -r ./samples --convert-to-builders",
15
15
  "samples:watch": "ts-node ./src/cli/typegen.ts watch -r ./samples --delete",
16
+ "samples:inline:check": "ts-node ./src/cli/typegen.ts check -r ./samples-inline --inline",
17
+ "samples:inline:write": "ts-node ./src/cli/typegen.ts write -r ./samples-inline --inline --delete",
16
18
  "samples:write:posthog": "NODE_OPTIONS=\"--max-old-space-size=16384\" ts-node ./src/cli/typegen.ts write --show-ts-errors -c",
17
19
  "form-plugin:build": "cd form-plugin && yarn && yarn build && cd ..",
18
20
  "form-plugin:rebuild": "yarn form-plugin:build && rm -rf node_modules && yarn"
@@ -0,0 +1 @@
1
+ export {};