Skip to content

Commit 3eba33d

Browse files
committed
fix(typings): add typings to service-state
1 parent dcc1476 commit 3eba33d

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed

src/service-module/service-module.state.ts

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,94 @@ eslint
66

77
import _omit from 'lodash/omit'
88

9-
export default function makeDefaultState(servicePath, options) {
9+
import { MakeServicePluginOptions, PaginationState } from './types'
10+
11+
export interface ServiceStateExclusiveDefaults {
12+
ids: string[]
13+
14+
errorOnFind: any
15+
errorOnGet: any
16+
errorOnCreate: any
17+
errorOnPatch: any
18+
errorOnUpdate: any
19+
errorOnRemove: any
20+
21+
isFindPending: boolean
22+
isGetPending: boolean
23+
isCreatePending: boolean
24+
isPatchPending: boolean
25+
isUpdatePending: boolean
26+
isRemovePending: boolean
27+
28+
keyedById: {}
29+
tempsById: {}
30+
tempsByNewId: {}
31+
copiesById: {}
32+
namespace?: string
33+
pagination?: {
34+
defaultLimit: number
35+
defaultSkip: number
36+
default?: PaginationState
37+
}
38+
modelName?: string
39+
}
40+
41+
export interface ServiceState {
42+
options: {}
43+
ids: string[]
44+
autoRemove: boolean
45+
errorOnFind: any
46+
errorOnGet: any
47+
errorOnCreate: any
48+
errorOnPatch: any
49+
errorOnUpdate: any
50+
errorOnRemove: any
51+
isFindPending: boolean
52+
isGetPending: boolean
53+
isCreatePending: boolean
54+
isPatchPending: boolean
55+
isUpdatePending: boolean
56+
isRemovePending: boolean
57+
idField: string
58+
keyedById: {}
59+
tempsById: {}
60+
tempsByNewId: {}
61+
copiesById: {}
62+
whitelist: string[]
63+
paramsForServer: string[]
64+
namespace: string
65+
nameStyle: string // Should be enum of 'short' or 'path'
66+
pagination?: {
67+
defaultLimit: number
68+
defaultSkip: number
69+
default?: PaginationState
70+
}
71+
modelName?: string
72+
}
73+
74+
export interface PaginationState {
75+
ids: any
76+
limit: number
77+
skip: number
78+
ip: number
79+
total: number
80+
mostRecent: any
81+
}
82+
83+
export default function makeDefaultState(options: MakeServicePluginOptions) {
1084
const nonStateProps = [
11-
'actions',
12-
'getters',
13-
'instanceDefaults',
14-
'handleEvents',
1585
'Model',
16-
'mutations',
1786
'service',
87+
'instanceDefaults',
1888
'setupInstance',
89+
'handleEvents',
1990
'state',
91+
'getters',
92+
'mutations',
2093
'actions'
2194
]
2295

23-
const state = {
96+
const state: ServiceStateExclusiveDefaults = {
2497
ids: [],
2598
keyedById: {},
2699
copiesById: {},
@@ -43,8 +116,7 @@ export default function makeDefaultState(servicePath, options) {
43116
errorOnCreate: null,
44117
errorOnUpdate: null,
45118
errorOnPatch: null,
46-
errorOnRemove: null,
47-
modelName: null as string | null
119+
errorOnRemove: null
48120
}
49121

50122
if (options.Model) {

test/service-module/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ eslint
33
@typescript-eslint/explicit-function-return-type: 0,
44
@typescript-eslint/no-explicit-any: 0
55
*/
6-
// TODO: use this in the src
76
export interface ServiceState {
87
options: {}
98
ids: string[]
@@ -23,13 +22,15 @@ export interface ServiceState {
2322
idField: string
2423
keyedById: {}
2524
tempsById: {}
25+
tempsByNewId: {}
2626
whitelist: string[]
2727
paramsForServer: string[]
2828
namespace: string
2929
nameStyle: string // Should be enum of 'short' or 'path'
3030
pagination?: {
3131
default: PaginationState
3232
}
33+
modelName: string
3334
}
3435

3536
export interface PaginationState {

0 commit comments

Comments
 (0)