Skip to content

Commit 41b62dd

Browse files
committed
Clean up model extend options logic
1 parent 37744f0 commit 41b62dd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/model.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface ModelConfiguration {
5353
apiNamespace: string
5454
jsonapiType: string
5555
endpoint: string
56+
credentialStorageBackend: StorageBackend,
5657
jwt: string
5758
jwtStorage: string | false
5859
keyCase: KeyCase
@@ -117,17 +118,30 @@ export const applyModelConfig = <T extends typeof JSORMBase>(
117118
): void => {
118119
let k: keyof ModelConfigurationOptions
119120

120-
for (k in config) {
121-
if (config.hasOwnProperty(k) && k !== 'jwt') {
122-
ModelClass[k] = config[k]
123-
}
121+
config = { ...config } // clone since we're going to mutate it
122+
123+
// Handle all JWT configuration at once since it's run-order dependent
124+
// We'll delete each key we encounter then pass the rest off to
125+
// a loop for assigning other arbitrary options
126+
if (config.credentialStorageBackend) {
127+
ModelClass.credentialStorageBackend = config.credentialStorageBackend
128+
delete config.jwtStorage
129+
}
130+
131+
if (config.jwtStorage) {
132+
ModelClass.jwtStorage = config.jwtStorage
133+
delete config.jwtStorage
124134
}
125135

126-
// Run this one last, since either the Credential Storage strategy
127-
// or the store key could be set in options alongside this, otherwise
128-
// this is dependent on option declaration order
129136
if (config.jwt) {
130137
ModelClass.setJWT(config.jwt)
138+
delete config.jwt
139+
}
140+
141+
for (k in config) {
142+
if (config.hasOwnProperty(k)) {
143+
ModelClass[k] = config[k]
144+
}
131145
}
132146

133147
if (ModelClass.isBaseClass === undefined) {

0 commit comments

Comments
 (0)