kea-typegen 1.2.0 → 1.4.0
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.
- package/CHANGELOG.md +72 -31
- package/dist/package.json +15 -14
- package/dist/src/__tests__/e2e/actions.js +4 -4
- package/dist/src/__tests__/e2e/actions.js.map +1 -1
- package/dist/src/__tests__/e2e/connect.js +6 -6
- package/dist/src/__tests__/e2e/connect.js.map +1 -1
- package/dist/src/__tests__/e2e/loaders.js +3 -3
- package/dist/src/__tests__/e2e/loaders.js.map +1 -1
- package/dist/src/__tests__/e2e/reducers.js +4 -4
- package/dist/src/__tests__/e2e/reducers.js.map +1 -1
- package/dist/src/__tests__/e2e/selectors.js +3 -3
- package/dist/src/__tests__/e2e/selectors.js.map +1 -1
- package/dist/src/__tests__/utils.js +7 -7
- package/dist/src/__tests__/utils.js.map +1 -1
- package/dist/src/cli/typegen.js +5 -3
- package/dist/src/cli/typegen.js.map +1 -1
- package/dist/src/print/print.d.ts +5 -5
- package/dist/src/print/print.js +55 -43
- package/dist/src/print/print.js.map +1 -1
- package/dist/src/print/printActionCreators.d.ts +1 -2
- package/dist/src/print/printActionCreators.js +7 -7
- package/dist/src/print/printActionCreators.js.map +1 -1
- package/dist/src/print/printActionKeys.d.ts +1 -2
- package/dist/src/print/printActionKeys.js +4 -4
- package/dist/src/print/printActionKeys.js.map +1 -1
- package/dist/src/print/printActionTypes.d.ts +1 -2
- package/dist/src/print/printActionTypes.js +4 -4
- package/dist/src/print/printActionTypes.js.map +1 -1
- package/dist/src/print/printActions.d.ts +1 -2
- package/dist/src/print/printActions.js +4 -4
- package/dist/src/print/printActions.js.map +1 -1
- package/dist/src/print/printConstants.d.ts +1 -2
- package/dist/src/print/printConstants.js +2 -2
- package/dist/src/print/printConstants.js.map +1 -1
- package/dist/src/print/printDefaults.d.ts +1 -2
- package/dist/src/print/printDefaults.js +3 -3
- package/dist/src/print/printDefaults.js.map +1 -1
- package/dist/src/print/printEvents.d.ts +1 -2
- package/dist/src/print/printEvents.js +3 -3
- package/dist/src/print/printEvents.js.map +1 -1
- package/dist/src/print/printInternalExtraInput.d.ts +1 -2
- package/dist/src/print/printInternalExtraInput.js +8 -8
- package/dist/src/print/printInternalExtraInput.js.map +1 -1
- package/dist/src/print/printInternalReducerActions.d.ts +1 -2
- package/dist/src/print/printInternalReducerActions.js +3 -4
- package/dist/src/print/printInternalReducerActions.js.map +1 -1
- package/dist/src/print/printInternalSelectorTypes.d.ts +1 -2
- package/dist/src/print/printInternalSelectorTypes.js +3 -3
- package/dist/src/print/printInternalSelectorTypes.js.map +1 -1
- package/dist/src/print/printKey.d.ts +1 -2
- package/dist/src/print/printKey.js +2 -2
- package/dist/src/print/printKey.js.map +1 -1
- package/dist/src/print/printListeners.d.ts +1 -2
- package/dist/src/print/printListeners.js +9 -9
- package/dist/src/print/printListeners.js.map +1 -1
- package/dist/src/print/printProps.d.ts +1 -2
- package/dist/src/print/printProps.js +6 -5
- package/dist/src/print/printProps.js.map +1 -1
- package/dist/src/print/printReducer.d.ts +1 -2
- package/dist/src/print/printReducer.js +6 -6
- package/dist/src/print/printReducer.js.map +1 -1
- package/dist/src/print/printReducerOptions.d.ts +1 -2
- package/dist/src/print/printReducerOptions.js +3 -3
- package/dist/src/print/printReducerOptions.js.map +1 -1
- package/dist/src/print/printReducers.d.ts +1 -2
- package/dist/src/print/printReducers.js +7 -7
- package/dist/src/print/printReducers.js.map +1 -1
- package/dist/src/print/printSelector.d.ts +1 -2
- package/dist/src/print/printSelector.js +4 -4
- package/dist/src/print/printSelector.js.map +1 -1
- package/dist/src/print/printSelectors.d.ts +1 -2
- package/dist/src/print/printSelectors.js +6 -6
- package/dist/src/print/printSelectors.js.map +1 -1
- package/dist/src/print/printSharedListeners.d.ts +1 -2
- package/dist/src/print/printSharedListeners.js +11 -11
- package/dist/src/print/printSharedListeners.js.map +1 -1
- package/dist/src/print/printValues.d.ts +1 -2
- package/dist/src/print/printValues.js +3 -3
- package/dist/src/print/printValues.js.map +1 -1
- package/dist/src/typegen.js +5 -5
- package/dist/src/typegen.js.map +1 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/src/utils.js +15 -15
- package/dist/src/utils.js.map +1 -1
- package/dist/src/visit/__tests__/visit.js +2 -2
- package/dist/src/visit/__tests__/visit.js.map +1 -1
- package/dist/src/visit/visit.js +22 -14
- package/dist/src/visit/visit.js.map +1 -1
- package/dist/src/visit/visitActions.d.ts +2 -2
- package/dist/src/visit/visitActions.js +13 -11
- package/dist/src/visit/visitActions.js.map +1 -1
- package/dist/src/visit/visitConnect.js +4 -4
- package/dist/src/visit/visitConnect.js.map +1 -1
- package/dist/src/visit/visitDefaults.js +1 -1
- package/dist/src/visit/visitDefaults.js.map +1 -1
- package/dist/src/visit/visitKey.js +2 -2
- package/dist/src/visit/visitKey.js.map +1 -1
- package/dist/src/visit/visitListeners.js +5 -5
- package/dist/src/visit/visitListeners.js.map +1 -1
- package/dist/src/visit/visitLoaders.d.ts +2 -2
- package/dist/src/visit/visitLoaders.js +27 -27
- package/dist/src/visit/visitLoaders.js.map +1 -1
- package/dist/src/visit/visitProps.js +1 -1
- package/dist/src/visit/visitProps.js.map +1 -1
- package/dist/src/visit/visitReducers.js +4 -4
- package/dist/src/visit/visitReducers.js.map +1 -1
- package/dist/src/visit/visitSelectors.js +8 -8
- package/dist/src/visit/visitSelectors.js.map +1 -1
- package/dist/src/visit/visitSharedListeners.js +5 -5
- package/dist/src/visit/visitSharedListeners.js.map +1 -1
- package/dist/src/visit/visitWindowValues.js +1 -1
- package/dist/src/visit/visitWindowValues.js.map +1 -1
- package/dist/src/write/write.d.ts +4 -0
- package/dist/src/{import/writeLogicTypeImports.js → write/write.js} +56 -11
- package/dist/src/write/write.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/form-plugin/lib/form-plugin/src/typegen.js +16 -15
- package/form-plugin/lib/src/types.d.ts +4 -1
- package/form-plugin/package.json +1 -1
- package/form-plugin/src/typegen.ts +25 -25
- package/form-plugin/tsconfig.json +0 -1
- package/form-plugin/yarn.lock +10 -10
- package/package.json +15 -14
- package/samples/autoImportLogic.ts +9 -3
- package/samples/autoImportLogicType.ts +1 -1
- package/samples/loadersLogicType.ts +10 -10
- package/samples/logicType.ts +4 -4
- package/src/__tests__/e2e/__snapshots__/loaders.ts.snap +12 -12
- package/src/__tests__/utils.ts +5 -5
- package/src/cli/typegen.ts +2 -0
- package/src/print/print.ts +65 -36
- package/src/print/printActionCreators.ts +12 -15
- package/src/print/printActionKeys.ts +5 -6
- package/src/print/printActionTypes.ts +6 -7
- package/src/print/printActions.ts +6 -13
- package/src/print/printConstants.ts +5 -6
- package/src/print/printDefaults.ts +5 -6
- package/src/print/printEvents.ts +8 -6
- package/src/print/printInternalExtraInput.ts +12 -13
- package/src/print/printInternalReducerActions.ts +5 -12
- package/src/print/printInternalSelectorTypes.ts +7 -8
- package/src/print/printKey.ts +2 -2
- package/src/print/printListeners.ts +16 -17
- package/src/print/printProps.ts +7 -7
- package/src/print/printReducer.ts +14 -15
- package/src/print/printReducerOptions.ts +4 -5
- package/src/print/printReducers.ts +13 -14
- package/src/print/printSelector.ts +8 -9
- package/src/print/printSelectors.ts +12 -13
- package/src/print/printSharedListeners.ts +20 -21
- package/src/print/printValues.ts +5 -6
- package/src/typegen.ts +4 -4
- package/src/types.ts +4 -1
- package/src/utils.ts +14 -14
- package/src/visit/visit.ts +11 -3
- package/src/visit/visitActions.ts +12 -10
- package/src/visit/visitListeners.ts +8 -8
- package/src/visit/visitLoaders.ts +49 -43
- package/src/visit/visitReducers.ts +1 -1
- package/src/visit/visitSelectors.ts +3 -3
- package/src/visit/visitSharedListeners.ts +8 -10
- package/src/{import/writeLogicTypeImports.ts → write/write.ts} +115 -16
- package/dist/src/import/writeLogicTypeImports.d.ts +0 -3
- package/dist/src/import/writeLogicTypeImports.js.map +0 -1
package/form-plugin/yarn.lock
CHANGED
|
@@ -127,11 +127,11 @@ is-fullwidth-code-point@^3.0.0:
|
|
|
127
127
|
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
|
|
128
128
|
|
|
129
129
|
"kea-typegen@file:..":
|
|
130
|
-
version "1.0
|
|
130
|
+
version "1.3.0"
|
|
131
131
|
dependencies:
|
|
132
132
|
"@wessberg/ts-clone-node" "0.3.19"
|
|
133
133
|
diff "^5.0.0"
|
|
134
|
-
prettier "^2.
|
|
134
|
+
prettier "^2.5.1"
|
|
135
135
|
yargs "^16.2.0"
|
|
136
136
|
|
|
137
137
|
kea@^2.4.5:
|
|
@@ -151,10 +151,10 @@ object-assign@^4.1.1:
|
|
|
151
151
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
|
152
152
|
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
|
|
153
153
|
|
|
154
|
-
prettier@^2.
|
|
155
|
-
version "2.
|
|
156
|
-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.
|
|
157
|
-
integrity sha512-
|
|
154
|
+
prettier@^2.5.1:
|
|
155
|
+
version "2.5.1"
|
|
156
|
+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
|
|
157
|
+
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==
|
|
158
158
|
|
|
159
159
|
prop-types@^15.7.2:
|
|
160
160
|
version "15.7.2"
|
|
@@ -228,10 +228,10 @@ strip-ansi@^6.0.0:
|
|
|
228
228
|
dependencies:
|
|
229
229
|
ansi-regex "^5.0.0"
|
|
230
230
|
|
|
231
|
-
typescript@^4.3
|
|
232
|
-
version "4.3
|
|
233
|
-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.
|
|
234
|
-
integrity sha512-
|
|
231
|
+
typescript@^4.5.3:
|
|
232
|
+
version "4.5.3"
|
|
233
|
+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
|
|
234
|
+
integrity sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ==
|
|
235
235
|
|
|
236
236
|
wrap-ansi@^7.0.0:
|
|
237
237
|
version "7.0.0"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kea-typegen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Generate type definitions for kea logic",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "ts-node ./src/cli/typegen.ts",
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"samples:check": "ts-node ./src/cli/typegen.ts check -c ./samples/tsconfig.json",
|
|
13
13
|
"samples:write": "ts-node ./src/cli/typegen.ts write -c ./samples/tsconfig.json",
|
|
14
|
+
"samples:write:paths": "ts-node ./src/cli/typegen.ts write -c ./samples/tsconfig.json --write-paths",
|
|
14
15
|
"samples:watch": "ts-node ./src/cli/typegen.ts watch -c ./samples/tsconfig.json",
|
|
15
16
|
"samples:write:posthog": "ts-node ./src/cli/typegen.ts write -c ../../PostHog/posthog/tsconfig.json",
|
|
16
|
-
"form-plugin:build": "cd form-plugin && yarn build && cd ..",
|
|
17
|
+
"form-plugin:build": "cd form-plugin && yarn && yarn build && cd ..",
|
|
17
18
|
"form-plugin:rebuild": "yarn form-plugin:build && rm -rf node_modules && yarn"
|
|
18
19
|
},
|
|
19
20
|
"main": "dist/src/index.js",
|
|
@@ -25,13 +26,13 @@
|
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@wessberg/ts-clone-node": "0.3.19",
|
|
27
28
|
"diff": "^5.0.0",
|
|
28
|
-
"prettier": "^2.
|
|
29
|
+
"prettier": "^2.5.1",
|
|
29
30
|
"yargs": "^16.2.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"@babel/preset-typescript": "^7.
|
|
33
|
+
"@babel/core": "^7.16.0",
|
|
34
|
+
"@babel/preset-env": "^7.16.4",
|
|
35
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
35
36
|
"@types/jest": "^26.0.20",
|
|
36
37
|
"@types/node": "^14.14.31",
|
|
37
38
|
"@types/yargs": "^16.0.0",
|
|
@@ -40,19 +41,19 @@
|
|
|
40
41
|
"form-plugin": "file:./form-plugin",
|
|
41
42
|
"husky": ">=4",
|
|
42
43
|
"jest": "^27.0.5",
|
|
43
|
-
"kea": "^2.
|
|
44
|
-
"lint-staged": ">=
|
|
44
|
+
"kea": "^2.5.6",
|
|
45
|
+
"lint-staged": ">=12.1.2",
|
|
45
46
|
"react": "^16.13.1",
|
|
46
|
-
"react-redux": "^7.2.
|
|
47
|
-
"redux": "^4.1.
|
|
48
|
-
"reselect": "^4.
|
|
47
|
+
"react-redux": "^7.2.6",
|
|
48
|
+
"redux": "^4.1.2",
|
|
49
|
+
"reselect": "^4.1.5",
|
|
49
50
|
"rimraf": "^3.0.2",
|
|
50
51
|
"ts-jest": "^27.0.3",
|
|
51
|
-
"ts-node": "^10.
|
|
52
|
-
"typescript": "^4.3
|
|
52
|
+
"ts-node": "^10.4.0",
|
|
53
|
+
"typescript": "^4.5.3"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
|
-
"typescript": "
|
|
56
|
+
"typescript": ">=4.5.3"
|
|
56
57
|
},
|
|
57
58
|
"jest": {
|
|
58
59
|
"testPathIgnorePatterns": [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { kea, KeaPlugin } from 'kea'
|
|
2
2
|
|
|
3
|
-
import { autoImportLogicType } from './autoImportLogicType'
|
|
4
3
|
import { A1, A2, A3, A4, A5, A7, D1, D3, D6, EventIndex, ExportedApi, R1, R6, S6 } from './autoImportTypes'
|
|
5
4
|
import { githubLogic } from './githubLogic'
|
|
6
5
|
import { loadersLogic } from './loadersLogic'
|
|
6
|
+
import type { autoImportLogicType } from './autoImportLogicType'
|
|
7
7
|
|
|
8
8
|
type L1 = 'haha'
|
|
9
9
|
type L2 = {
|
|
@@ -40,10 +40,16 @@ export const autoImportLogic = kea<autoImportLogicType<L1, L2, RandomAPI>>({
|
|
|
40
40
|
complexAction: (element: HTMLElement, timeout: NodeJS.Timeout) => ({ element, timeout }),
|
|
41
41
|
combinedA6Action: (filter: A5) => ({ a6: filter.a6, bla: filter.bla }),
|
|
42
42
|
valueAction: [] as A7,
|
|
43
|
-
miscActionWithType: (
|
|
43
|
+
miscActionWithType: (
|
|
44
|
+
randomThing: ExportedApi.RandomThing,
|
|
45
|
+
): {
|
|
46
|
+
randomThing: ExportedApi.RandomThing
|
|
47
|
+
} => ({
|
|
44
48
|
randomThing,
|
|
45
49
|
}),
|
|
46
|
-
miscActionWithTypeConstants: (): {
|
|
50
|
+
miscActionWithTypeConstants: (): {
|
|
51
|
+
color: 'green' | 'blue'
|
|
52
|
+
} => ({
|
|
47
53
|
color: 'blue',
|
|
48
54
|
}),
|
|
49
55
|
miscActionWithoutType: (randomThing: ExportedApi.RandomThing) => ({ randomThing }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by kea-typegen on Thu, 14 Oct 2021 12:
|
|
1
|
+
// Generated by kea-typegen on Thu, 14 Oct 2021 12:36:17 GMT. DO NOT EDIT THIS FILE MANUALLY.
|
|
2
2
|
|
|
3
3
|
import { Logic } from 'kea'
|
|
4
4
|
|
|
@@ -14,14 +14,14 @@ export interface loadersLogicType extends Logic {
|
|
|
14
14
|
}
|
|
15
15
|
addDashboardSuccess: (
|
|
16
16
|
dashboard: Dashboard,
|
|
17
|
-
payload
|
|
17
|
+
payload?: {
|
|
18
18
|
name: string
|
|
19
19
|
},
|
|
20
20
|
) => {
|
|
21
21
|
type: 'add dashboard success (loadersLogic)'
|
|
22
22
|
payload: {
|
|
23
23
|
dashboard: Dashboard
|
|
24
|
-
payload
|
|
24
|
+
payload?: {
|
|
25
25
|
name: string
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -44,14 +44,14 @@ export interface loadersLogicType extends Logic {
|
|
|
44
44
|
}
|
|
45
45
|
addDashboardNoTypeSuccess: (
|
|
46
46
|
dashboard: Dashboard,
|
|
47
|
-
payload
|
|
47
|
+
payload?: {
|
|
48
48
|
name: string
|
|
49
49
|
},
|
|
50
50
|
) => {
|
|
51
51
|
type: 'add dashboard no type success (loadersLogic)'
|
|
52
52
|
payload: {
|
|
53
53
|
dashboard: Dashboard
|
|
54
|
-
payload
|
|
54
|
+
payload?: {
|
|
55
55
|
name: string
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -72,12 +72,12 @@ export interface loadersLogicType extends Logic {
|
|
|
72
72
|
}
|
|
73
73
|
loadItSuccess: (
|
|
74
74
|
misc: { id: number; name: void; pinned: boolean },
|
|
75
|
-
payload
|
|
75
|
+
payload?: any,
|
|
76
76
|
) => {
|
|
77
77
|
type: 'load it success (loadersLogic)'
|
|
78
78
|
payload: {
|
|
79
79
|
misc: { id: number; name: void; pinned: boolean }
|
|
80
|
-
payload
|
|
80
|
+
payload?: any
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
loadItFailure: (
|
|
@@ -117,7 +117,7 @@ export interface loadersLogicType extends Logic {
|
|
|
117
117
|
addDashboard: (name: string) => void
|
|
118
118
|
addDashboardSuccess: (
|
|
119
119
|
dashboard: Dashboard,
|
|
120
|
-
payload
|
|
120
|
+
payload?: {
|
|
121
121
|
name: string
|
|
122
122
|
},
|
|
123
123
|
) => void
|
|
@@ -125,13 +125,13 @@ export interface loadersLogicType extends Logic {
|
|
|
125
125
|
addDashboardNoType: ({ name }: { name: string }) => void
|
|
126
126
|
addDashboardNoTypeSuccess: (
|
|
127
127
|
dashboard: Dashboard,
|
|
128
|
-
payload
|
|
128
|
+
payload?: {
|
|
129
129
|
name: string
|
|
130
130
|
},
|
|
131
131
|
) => void
|
|
132
132
|
addDashboardNoTypeFailure: (error: string, errorObject?: any) => void
|
|
133
133
|
loadIt: () => void
|
|
134
|
-
loadItSuccess: (misc: { id: number; name: void; pinned: boolean }, payload
|
|
134
|
+
loadItSuccess: (misc: { id: number; name: void; pinned: boolean }, payload?: any) => void
|
|
135
135
|
loadItFailure: (error: string, errorObject?: any) => void
|
|
136
136
|
}
|
|
137
137
|
constants: {}
|
package/samples/logicType.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by kea-typegen on Thu, 14 Oct 2021 12:
|
|
1
|
+
// Generated by kea-typegen on Thu, 14 Oct 2021 12:36:17 GMT. DO NOT EDIT THIS FILE MANUALLY.
|
|
2
2
|
|
|
3
3
|
import { Logic, BreakPointFunction } from 'kea'
|
|
4
4
|
|
|
@@ -28,12 +28,12 @@ export interface logicType<Session> extends Logic {
|
|
|
28
28
|
}
|
|
29
29
|
loadSessionsSuccess: (
|
|
30
30
|
sessions: Session[],
|
|
31
|
-
payload
|
|
31
|
+
payload?: string,
|
|
32
32
|
) => {
|
|
33
33
|
type: 'load sessions success (scenes.homepage.index.*)'
|
|
34
34
|
payload: {
|
|
35
35
|
sessions: Session[]
|
|
36
|
-
payload
|
|
36
|
+
payload?: string
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
loadSessionsFailure: (
|
|
@@ -68,7 +68,7 @@ export interface logicType<Session> extends Logic {
|
|
|
68
68
|
updateConst: (name: 'John' | 'Bill') => void
|
|
69
69
|
updateNumber: (number: number) => void
|
|
70
70
|
loadSessions: (selectedDate: string) => void
|
|
71
|
-
loadSessionsSuccess: (sessions: Session[], payload
|
|
71
|
+
loadSessionsSuccess: (sessions: Session[], payload?: string) => void
|
|
72
72
|
loadSessionsFailure: (error: string, errorObject?: any) => void
|
|
73
73
|
}
|
|
74
74
|
constants: {
|
|
@@ -13,11 +13,11 @@ exports[`loaders - with a function 1`] = `
|
|
|
13
13
|
type: \\"load sessions (logic)\\";
|
|
14
14
|
payload: string;
|
|
15
15
|
});
|
|
16
|
-
loadSessionsSuccess: (sessions: Session[], payload
|
|
16
|
+
loadSessionsSuccess: (sessions: Session[], payload?: string) => ({
|
|
17
17
|
type: \\"load sessions success (logic)\\";
|
|
18
18
|
payload: {
|
|
19
19
|
sessions: Session[];
|
|
20
|
-
payload
|
|
20
|
+
payload?: string;
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
loadSessionsFailure: (error: string, errorObject?: any) => ({
|
|
@@ -43,7 +43,7 @@ exports[`loaders - with a function 1`] = `
|
|
|
43
43
|
actions: {
|
|
44
44
|
updateName: (name: string) => void;
|
|
45
45
|
loadSessions: (query: string) => void;
|
|
46
|
-
loadSessionsSuccess: (sessions: Session[], payload
|
|
46
|
+
loadSessionsSuccess: (sessions: Session[], payload?: string) => void;
|
|
47
47
|
loadSessionsFailure: (error: string, errorObject?: any) => void;
|
|
48
48
|
};
|
|
49
49
|
constants: {};
|
|
@@ -99,11 +99,11 @@ exports[`loaders - with an array and default 1`] = `
|
|
|
99
99
|
type: \\"load sessions (logic)\\";
|
|
100
100
|
payload: string;
|
|
101
101
|
});
|
|
102
|
-
loadSessionsSuccess: (sessions: Session[], payload
|
|
102
|
+
loadSessionsSuccess: (sessions: Session[], payload?: string) => ({
|
|
103
103
|
type: \\"load sessions success (logic)\\";
|
|
104
104
|
payload: {
|
|
105
105
|
sessions: Session[];
|
|
106
|
-
payload
|
|
106
|
+
payload?: string;
|
|
107
107
|
};
|
|
108
108
|
});
|
|
109
109
|
loadSessionsFailure: (error: string, errorObject?: any) => ({
|
|
@@ -129,7 +129,7 @@ exports[`loaders - with an array and default 1`] = `
|
|
|
129
129
|
actions: {
|
|
130
130
|
updateName: (name: string) => void;
|
|
131
131
|
loadSessions: (query: string) => void;
|
|
132
|
-
loadSessionsSuccess: (sessions: Session[], payload
|
|
132
|
+
loadSessionsSuccess: (sessions: Session[], payload?: string) => void;
|
|
133
133
|
loadSessionsFailure: (error: string, errorObject?: any) => void;
|
|
134
134
|
};
|
|
135
135
|
constants: {};
|
|
@@ -179,11 +179,11 @@ exports[`loaders - with no param 1`] = `
|
|
|
179
179
|
type: \\"load sessions (logic)\\";
|
|
180
180
|
payload: any;
|
|
181
181
|
});
|
|
182
|
-
loadSessionsSuccess: (sessions: string[], payload
|
|
182
|
+
loadSessionsSuccess: (sessions: string[], payload?: any) => ({
|
|
183
183
|
type: \\"load sessions success (logic)\\";
|
|
184
184
|
payload: {
|
|
185
185
|
sessions: string[];
|
|
186
|
-
payload
|
|
186
|
+
payload?: any;
|
|
187
187
|
};
|
|
188
188
|
});
|
|
189
189
|
loadSessionsFailure: (error: string, errorObject?: any) => ({
|
|
@@ -197,11 +197,11 @@ exports[`loaders - with no param 1`] = `
|
|
|
197
197
|
type: \\"load results (logic)\\";
|
|
198
198
|
payload: any;
|
|
199
199
|
});
|
|
200
|
-
loadResultsSuccess: (sessions: string[], payload
|
|
200
|
+
loadResultsSuccess: (sessions: string[], payload?: any) => ({
|
|
201
201
|
type: \\"load results success (logic)\\";
|
|
202
202
|
payload: {
|
|
203
203
|
sessions: string[];
|
|
204
|
-
payload
|
|
204
|
+
payload?: any;
|
|
205
205
|
};
|
|
206
206
|
});
|
|
207
207
|
loadResultsFailure: (error: string, errorObject?: any) => ({
|
|
@@ -230,10 +230,10 @@ exports[`loaders - with no param 1`] = `
|
|
|
230
230
|
};
|
|
231
231
|
actions: {
|
|
232
232
|
loadSessions: () => void;
|
|
233
|
-
loadSessionsSuccess: (sessions: string[], payload
|
|
233
|
+
loadSessionsSuccess: (sessions: string[], payload?: any) => void;
|
|
234
234
|
loadSessionsFailure: (error: string, errorObject?: any) => void;
|
|
235
235
|
loadResults: () => void;
|
|
236
|
-
loadResultsSuccess: (sessions: string[], payload
|
|
236
|
+
loadResultsSuccess: (sessions: string[], payload?: any) => void;
|
|
237
237
|
loadResultsFailure: (error: string, errorObject?: any) => void;
|
|
238
238
|
};
|
|
239
239
|
constants: {};
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { sourceToSourceFile, programFromSource, logicSourceToLogicType } from '../utils'
|
|
2
|
-
import
|
|
2
|
+
import { SyntaxKind } from 'typescript'
|
|
3
3
|
|
|
4
4
|
test('sourceToSourceFile', () => {
|
|
5
5
|
const source = 'var foo = 5;'
|
|
6
|
-
const sourceFile1 = sourceToSourceFile(source
|
|
6
|
+
const sourceFile1 = sourceToSourceFile(source)
|
|
7
7
|
const sourceFile2 = sourceToSourceFile(source, 'otherLogic.ts')
|
|
8
8
|
expect(sourceFile1.text).toEqual(source)
|
|
9
9
|
expect(sourceFile2.text).toEqual(source)
|
|
10
10
|
expect(sourceFile1.fileName).toEqual('logic.ts')
|
|
11
11
|
expect(sourceFile2.fileName).toEqual('otherLogic.ts')
|
|
12
|
-
expect(
|
|
13
|
-
expect(
|
|
12
|
+
expect(SyntaxKind[sourceFile1.kind]).toEqual('SourceFile')
|
|
13
|
+
expect(SyntaxKind[sourceFile2.kind]).toEqual('SourceFile')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
test('programFromSource', () => {
|
|
@@ -34,4 +34,4 @@ test('logicSourceToLogicType', () => {
|
|
|
34
34
|
const string = logicSourceToLogicType(logicSource)
|
|
35
35
|
|
|
36
36
|
expect(string).toContain('export interface myRandomLogicType extends Logic {')
|
|
37
|
-
})
|
|
37
|
+
})
|
package/src/cli/typegen.ts
CHANGED
|
@@ -46,6 +46,7 @@ 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' })
|
|
49
50
|
.option('verbose', { describe: 'Slightly more verbose output log', type: 'boolean' })
|
|
50
51
|
.demandCommand()
|
|
51
52
|
.help()
|
|
@@ -60,6 +61,7 @@ function parsedToAppOptions(parsedOptions) {
|
|
|
60
61
|
quiet: parsedOptions.quiet,
|
|
61
62
|
verbose: parsedOptions.verbose,
|
|
62
63
|
noImport: parsedOptions.noImport,
|
|
64
|
+
writePaths: parsedOptions.writePaths,
|
|
63
65
|
log: parsedOptions.quiet ? () => null : console.log.bind(console),
|
|
64
66
|
} as AppOptions
|
|
65
67
|
|
package/src/print/print.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
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:
|
|
58
|
+
program: Program,
|
|
47
59
|
appOptions: AppOptions,
|
|
48
60
|
parsedLogics: ParsedLogic[],
|
|
49
|
-
): { filesToWrite: number; writtenFiles: 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,13 @@ export function printToFiles(
|
|
|
56
68
|
}
|
|
57
69
|
groupedByFile[parsedLogic.fileName].push(parsedLogic)
|
|
58
70
|
|
|
59
|
-
// create the
|
|
71
|
+
// create the Nodes and gather referenced types
|
|
60
72
|
printLogicType(parsedLogic, appOptions)
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
let writtenFiles = 0
|
|
64
76
|
let filesToWrite = 0
|
|
65
|
-
let
|
|
77
|
+
let filesToModify = 0
|
|
66
78
|
|
|
67
79
|
Object.entries(groupedByFile).forEach(([fileName, parsedLogics]) => {
|
|
68
80
|
const typeFileName = parsedLogics[0].typeFileName
|
|
@@ -129,19 +141,19 @@ export function printToFiles(
|
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
const parsedLogicNeedsTypeImport = (pl: ParsedLogic) =>
|
|
145
|
+
// reload if logic type not imported
|
|
146
|
+
(pl.logicTypeImported === false ||
|
|
147
|
+
// reload if don't have the right types in arguments
|
|
148
|
+
pl.logicTypeArguments.join(', ') !== [...pl.typeReferencesInLogicInput].sort().join(', ')) &&
|
|
149
|
+
pl.fileName.match(/\.tsx?$/)
|
|
150
|
+
|
|
132
151
|
// 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
|
-
)
|
|
152
|
+
const logicsNeedingImports = parsedLogics.filter(parsedLogicNeedsTypeImport)
|
|
141
153
|
if (logicsNeedingImports.length > 0) {
|
|
142
154
|
if (appOptions.write && !appOptions.noImport) {
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
writeTypeImports(appOptions, program, fileName, logicsNeedingImports, parsedLogics)
|
|
156
|
+
filesToModify += logicsNeedingImports.length
|
|
145
157
|
} else {
|
|
146
158
|
log(
|
|
147
159
|
`❌ Will not write ${logicsNeedingImports.length} logic type import${
|
|
@@ -150,28 +162,43 @@ export function printToFiles(
|
|
|
150
162
|
)
|
|
151
163
|
}
|
|
152
164
|
}
|
|
165
|
+
|
|
166
|
+
const parsedLogicNeedsPath = appOptions.writePaths ? (pl: ParsedLogic) => !pl.hasPathInLogic : () => false
|
|
167
|
+
const logicsNeedingPaths = parsedLogics.filter(parsedLogicNeedsPath)
|
|
168
|
+
if (logicsNeedingPaths.length > 0) {
|
|
169
|
+
if (appOptions.write && !appOptions.noImport) {
|
|
170
|
+
writePaths(appOptions, program, fileName, logicsNeedingPaths)
|
|
171
|
+
filesToModify += logicsNeedingPaths.length
|
|
172
|
+
} else {
|
|
173
|
+
log(
|
|
174
|
+
`❌ Will not write ${logicsNeedingPaths.length} logic path${
|
|
175
|
+
logicsNeedingPaths.length === 1 ? '' : 's'
|
|
176
|
+
}`,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
153
180
|
})
|
|
154
181
|
|
|
155
|
-
if (writtenFiles === 0 &&
|
|
182
|
+
if (writtenFiles === 0 && filesToModify === 0) {
|
|
156
183
|
if (appOptions.write) {
|
|
157
184
|
log(`💚 ${parsedLogics.length} logic type${parsedLogics.length === 1 ? '' : 's'} up to date!`)
|
|
158
185
|
log('')
|
|
159
|
-
} else if (filesToWrite > 0 ||
|
|
186
|
+
} else if (filesToWrite > 0 || filesToModify > 0) {
|
|
160
187
|
log(
|
|
161
|
-
`🚨 Run "kea-typegen write" to save ${filesToWrite +
|
|
188
|
+
`🚨 Run "kea-typegen write" to save ${filesToWrite + filesToModify} file${
|
|
162
189
|
filesToWrite === 1 ? '' : 's'
|
|
163
190
|
} to disk`,
|
|
164
191
|
)
|
|
165
192
|
}
|
|
166
193
|
}
|
|
167
194
|
|
|
168
|
-
return { filesToWrite, writtenFiles,
|
|
195
|
+
return { filesToWrite, writtenFiles, filesToModify }
|
|
169
196
|
}
|
|
170
197
|
|
|
171
|
-
export function nodeToString(node:
|
|
172
|
-
const printer =
|
|
173
|
-
const sourceFile =
|
|
174
|
-
return printer.printNode(
|
|
198
|
+
export function nodeToString(node: Node): string {
|
|
199
|
+
const printer = createPrinter({ newLine: NewLineKind.LineFeed })
|
|
200
|
+
const sourceFile = createSourceFile('logic.ts', '', ScriptTarget.Latest, false, ScriptKind.TS)
|
|
201
|
+
return printer.printNode(EmitHint.Unspecified, node, sourceFile)
|
|
175
202
|
}
|
|
176
203
|
|
|
177
204
|
export function parsedLogicToTypeString(parsedLogic: ParsedLogic, appOptions?: AppOptions): string {
|
|
@@ -179,15 +206,15 @@ export function parsedLogicToTypeString(parsedLogic: ParsedLogic, appOptions?: A
|
|
|
179
206
|
return nodeToString(parsedLogic.interfaceDeclaration)
|
|
180
207
|
}
|
|
181
208
|
|
|
182
|
-
export function getLogicTypeArguments(parsedLogic: ParsedLogic):
|
|
209
|
+
export function getLogicTypeArguments(parsedLogic: ParsedLogic): TypeParameterDeclaration[] {
|
|
183
210
|
return [...parsedLogic.typeReferencesInLogicInput]
|
|
184
211
|
.sort()
|
|
185
|
-
.map((text) =>
|
|
212
|
+
.map((text) => factory.createTypeParameterDeclaration(factory.createIdentifier(text), undefined))
|
|
186
213
|
}
|
|
187
214
|
|
|
188
215
|
export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions): void {
|
|
189
216
|
const printProperty = (name, typeNode) =>
|
|
190
|
-
|
|
217
|
+
factory.createPropertySignature(undefined, factory.createIdentifier(name), undefined, typeNode)
|
|
191
218
|
|
|
192
219
|
const addSelectorTypeHelp = parsedLogic.selectors.filter((s) => s.functionTypes.length > 0).length > 0
|
|
193
220
|
|
|
@@ -203,9 +230,11 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
|
|
|
203
230
|
printProperty('listeners', printListeners(parsedLogic)),
|
|
204
231
|
printProperty(
|
|
205
232
|
'path',
|
|
206
|
-
|
|
233
|
+
factory.createTupleTypeNode(
|
|
234
|
+
parsedLogic.path.map((p) => factory.createLiteralTypeNode(factory.createStringLiteral(p))),
|
|
235
|
+
),
|
|
207
236
|
),
|
|
208
|
-
printProperty('pathString',
|
|
237
|
+
printProperty('pathString', factory.createStringLiteral(parsedLogic.pathString)),
|
|
209
238
|
printProperty('props', printProps(parsedLogic)),
|
|
210
239
|
printProperty('reducer', printReducer(parsedLogic)),
|
|
211
240
|
printProperty('reducerOptions', printReducerOptions(parsedLogic)),
|
|
@@ -214,8 +243,8 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
|
|
|
214
243
|
printProperty('selectors', printSelectors(parsedLogic)),
|
|
215
244
|
printProperty('sharedListeners', printSharedListeners(parsedLogic)),
|
|
216
245
|
printProperty('values', printValues(parsedLogic)),
|
|
217
|
-
printProperty('_isKea',
|
|
218
|
-
printProperty('_isKeaWithKey', parsedLogic.keyType ?
|
|
246
|
+
printProperty('_isKea', factory.createTrue()),
|
|
247
|
+
printProperty('_isKeaWithKey', parsedLogic.keyType ? factory.createTrue() : factory.createFalse()),
|
|
219
248
|
addSelectorTypeHelp
|
|
220
249
|
? printProperty('__keaTypeGenInternalSelectorTypes', printInternalSelectorTypes(parsedLogic))
|
|
221
250
|
: null,
|
|
@@ -229,14 +258,14 @@ export function printLogicType(parsedLogic: ParsedLogic, appOptions?: AppOptions
|
|
|
229
258
|
|
|
230
259
|
const logicTypeArguments = getLogicTypeArguments(parsedLogic)
|
|
231
260
|
|
|
232
|
-
parsedLogic.interfaceDeclaration =
|
|
261
|
+
parsedLogic.interfaceDeclaration = factory.createInterfaceDeclaration(
|
|
233
262
|
undefined,
|
|
234
|
-
[
|
|
235
|
-
|
|
263
|
+
[factory.createModifier(SyntaxKind.ExportKeyword)],
|
|
264
|
+
factory.createIdentifier(`${parsedLogic.logicName}Type`),
|
|
236
265
|
logicTypeArguments,
|
|
237
266
|
[
|
|
238
|
-
|
|
239
|
-
|
|
267
|
+
factory.createHeritageClause(SyntaxKind.ExtendsKeyword, [
|
|
268
|
+
factory.createExpressionWithTypeArguments(factory.createIdentifier('Logic'), undefined),
|
|
240
269
|
]),
|
|
241
270
|
],
|
|
242
271
|
logicProperties,
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
import
|
|
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
|
|
8
|
+
return factory.createTypeLiteralNode(
|
|
9
9
|
parsedLogic.actions.map(({ name, parameters, returnTypeNode }) => {
|
|
10
|
-
return
|
|
10
|
+
return factory.createPropertySignature(
|
|
11
11
|
undefined,
|
|
12
|
-
|
|
12
|
+
factory.createIdentifier(name),
|
|
13
13
|
undefined,
|
|
14
|
-
|
|
14
|
+
factory.createFunctionTypeNode(
|
|
15
15
|
undefined,
|
|
16
16
|
parameters,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
factory.createParenthesizedType(
|
|
18
|
+
factory.createTypeLiteralNode([
|
|
19
|
+
factory.createPropertySignature(
|
|
20
20
|
undefined,
|
|
21
|
-
|
|
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
|
-
|
|
25
|
+
factory.createPropertySignature(
|
|
27
26
|
undefined,
|
|
28
|
-
|
|
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
|
)
|