studiokit-scaffolding-js 4.3.21 → 4.3.22

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 (334) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +127 -127
  3. package/lib/components/ActionList.d.ts +20 -20
  4. package/lib/components/ActionList.js +94 -94
  5. package/lib/components/AlertDialog.d.ts +18 -18
  6. package/lib/components/AlertDialog.js +21 -21
  7. package/lib/components/AlertWithIcon.d.ts +7 -7
  8. package/lib/components/AlertWithIcon.js +57 -57
  9. package/lib/components/Blots/CustomImageSpec.d.ts +14 -14
  10. package/lib/components/Blots/CustomImageSpec.js +45 -45
  11. package/lib/components/Blots/CustomVideoSpec.d.ts +16 -16
  12. package/lib/components/Blots/CustomVideoSpec.js +47 -47
  13. package/lib/components/ConnectedModal.d.ts +6 -6
  14. package/lib/components/ConnectedModal.js +11 -11
  15. package/lib/components/Dropdowns/GroupsDropdown.d.ts +18 -18
  16. package/lib/components/Dropdowns/GroupsDropdown.js +90 -90
  17. package/lib/components/Dropdowns/ManagedNavDropdown.d.ts +32 -32
  18. package/lib/components/Dropdowns/ManagedNavDropdown.js +118 -118
  19. package/lib/components/Dropdowns/UserDropdown.d.ts +6 -6
  20. package/lib/components/Dropdowns/UserDropdown.js +76 -76
  21. package/lib/components/Dropdowns/index.d.ts +3 -3
  22. package/lib/components/Dropdowns/index.js +12 -12
  23. package/lib/components/EntityOwnerList.d.ts +11 -11
  24. package/lib/components/EntityOwnerList.js +63 -63
  25. package/lib/components/ErrorBoundary.d.ts +11 -11
  26. package/lib/components/ErrorBoundary.js +74 -74
  27. package/lib/components/Forms/DateField.d.ts +13 -13
  28. package/lib/components/Forms/DateField.js +99 -99
  29. package/lib/components/Forms/TimeField.d.ts +11 -11
  30. package/lib/components/Forms/TimeField.js +112 -112
  31. package/lib/components/Forms/index.d.ts +2 -2
  32. package/lib/components/Forms/index.js +14 -14
  33. package/lib/components/Groups/CreateEditCopySaveButtons.d.ts +10 -10
  34. package/lib/components/Groups/CreateEditCopySaveButtons.js +18 -18
  35. package/lib/components/Groups/GroupCreateOrEditCommonProps.d.ts +6 -6
  36. package/lib/components/Groups/GroupCreateOrEditCommonProps.js +2 -2
  37. package/lib/components/Groups/RosterSyncInfo.d.ts +5 -5
  38. package/lib/components/Groups/RosterSyncInfo.js +54 -54
  39. package/lib/components/HOC/AccessibleAppComponent.d.ts +15 -15
  40. package/lib/components/HOC/AccessibleAppComponent.js +135 -135
  41. package/lib/components/HOC/ActivityRequiredComponent.d.ts +105 -105
  42. package/lib/components/HOC/ActivityRequiredComponent.js +101 -101
  43. package/lib/components/HOC/AsyncComponent.d.ts +37 -37
  44. package/lib/components/HOC/AsyncComponent.js +136 -136
  45. package/lib/components/HOC/AuthenticatedComponent.d.ts +10 -10
  46. package/lib/components/HOC/AuthenticatedComponent.js +104 -104
  47. package/lib/components/HOC/CollectionComponent.d.ts +61 -61
  48. package/lib/components/HOC/CollectionComponent.js +175 -175
  49. package/lib/components/HOC/CollectionFirstItemComponent.d.ts +67 -67
  50. package/lib/components/HOC/CollectionFirstItemComponent.js +94 -94
  51. package/lib/components/HOC/CollectionItemComponent.d.ts +61 -61
  52. package/lib/components/HOC/CollectionItemComponent.js +172 -172
  53. package/lib/components/HOC/ConnectedModalComponent.d.ts +26 -26
  54. package/lib/components/HOC/ConnectedModalComponent.js +110 -110
  55. package/lib/components/HOC/DataDependentComponent.d.ts +61 -61
  56. package/lib/components/HOC/DataDependentComponent.js +90 -90
  57. package/lib/components/HOC/EntityComponent.d.ts +83 -83
  58. package/lib/components/HOC/EntityComponent.js +120 -120
  59. package/lib/components/HOC/FullscreenModalComponent.d.ts +74 -74
  60. package/lib/components/HOC/FullscreenModalComponent.js +173 -173
  61. package/lib/components/HOC/GroupActivityRequiredComponent.d.ts +29 -29
  62. package/lib/components/HOC/GroupActivityRequiredComponent.js +49 -49
  63. package/lib/components/HOC/GuidComponent.d.ts +14 -14
  64. package/lib/components/HOC/GuidComponent.js +72 -72
  65. package/lib/components/HOC/ModelContextDependencyVerifyComponent.d.ts +172 -172
  66. package/lib/components/HOC/ModelContextDependencyVerifyComponent.js +72 -72
  67. package/lib/components/HOC/ModelErrorRedirectComponent.d.ts +69 -69
  68. package/lib/components/HOC/ModelErrorRedirectComponent.js +101 -101
  69. package/lib/components/HOC/SearchPersistorComponent.d.ts +85 -85
  70. package/lib/components/HOC/SearchPersistorComponent.js +198 -198
  71. package/lib/components/HOC/UnauthenticatedComponent.d.ts +62 -62
  72. package/lib/components/HOC/UnauthenticatedComponent.js +90 -90
  73. package/lib/components/HOC/UserComponent.d.ts +3 -3
  74. package/lib/components/HOC/UserComponent.js +12 -12
  75. package/lib/components/Icons/IconExternalUser.d.ts +3 -3
  76. package/lib/components/Icons/IconExternalUser.js +24 -24
  77. package/lib/components/Icons/IconImpersonation.d.ts +3 -3
  78. package/lib/components/Icons/IconImpersonation.js +24 -24
  79. package/lib/components/Icons/IconStopImpersonating.d.ts +3 -3
  80. package/lib/components/Icons/IconStopImpersonating.js +24 -24
  81. package/lib/components/Impersonation/Button.d.ts +7 -7
  82. package/lib/components/Impersonation/Button.js +61 -61
  83. package/lib/components/Impersonation/Link.d.ts +7 -7
  84. package/lib/components/Impersonation/Link.js +58 -58
  85. package/lib/components/Impersonation/UserDetail.css +22 -22
  86. package/lib/components/Impersonation/UserDetail.d.ts +22 -22
  87. package/lib/components/Impersonation/UserDetail.js +23 -23
  88. package/lib/components/Loading.d.ts +4 -4
  89. package/lib/components/Loading.js +24 -24
  90. package/lib/components/Lti/Confirm.d.ts +8 -8
  91. package/lib/components/Lti/Confirm.js +37 -37
  92. package/lib/components/Lti/CreateNonLtiGroupAlertDialog.d.ts +15 -15
  93. package/lib/components/Lti/CreateNonLtiGroupAlertDialog.js +83 -83
  94. package/lib/components/Lti/Launch.d.ts +21 -21
  95. package/lib/components/Lti/Launch.js +52 -52
  96. package/lib/components/Lti/LaunchGroup.d.ts +9 -9
  97. package/lib/components/Lti/LaunchGroup.js +45 -45
  98. package/lib/components/NewVersionAlert.d.ts +18 -18
  99. package/lib/components/NewVersionAlert.js +97 -97
  100. package/lib/components/NotFound.d.ts +3 -3
  101. package/lib/components/NotFound.js +30 -28
  102. package/lib/components/Notifications.d.ts +39 -39
  103. package/lib/components/Notifications.js +175 -175
  104. package/lib/components/RefreshIndicator/Bordered.d.ts +7 -7
  105. package/lib/components/RefreshIndicator/Bordered.js +35 -35
  106. package/lib/components/RefreshIndicator/Inline.d.ts +4 -4
  107. package/lib/components/RefreshIndicator/Inline.js +36 -36
  108. package/lib/components/RefreshIndicator/index.d.ts +21 -21
  109. package/lib/components/RefreshIndicator/index.js +116 -116
  110. package/lib/components/SearchControls.d.ts +14 -14
  111. package/lib/components/SearchControls.js +34 -34
  112. package/lib/components/SentryRoute.d.ts +3 -3
  113. package/lib/components/SentryRoute.js +25 -25
  114. package/lib/components/Tables/RoleFilter.d.ts +14 -14
  115. package/lib/components/Tables/RoleFilter.js +53 -53
  116. package/lib/components/Tables/TextFilter.d.ts +7 -7
  117. package/lib/components/Tables/TextFilter.js +26 -26
  118. package/lib/components/UserRoles/Add.d.ts +31 -31
  119. package/lib/components/UserRoles/Add.js +165 -165
  120. package/lib/components/UserRoles/RoleCell.d.ts +21 -21
  121. package/lib/components/UserRoles/RoleCell.js +53 -53
  122. package/lib/components/UserRoles/Select.d.ts +27 -27
  123. package/lib/components/UserRoles/Select.js +44 -44
  124. package/lib/components/UserRoles/Table.d.ts +16 -16
  125. package/lib/components/UserRoles/Table.js +99 -99
  126. package/lib/components/UserRoles/index.d.ts +76 -76
  127. package/lib/components/UserRoles/index.js +361 -361
  128. package/lib/constants/baseActivity.d.ts +25 -25
  129. package/lib/constants/baseActivity.js +29 -29
  130. package/lib/constants/baseRole.d.ts +9 -9
  131. package/lib/constants/baseRole.js +13 -13
  132. package/lib/constants/configuration.d.ts +8 -8
  133. package/lib/constants/configuration.js +39 -39
  134. package/lib/constants/externalProviderType.d.ts +5 -5
  135. package/lib/constants/externalProviderType.js +9 -9
  136. package/lib/constants/index.d.ts +8 -8
  137. package/lib/constants/index.js +20 -20
  138. package/lib/constants/mockData.d.ts +84 -82
  139. package/lib/constants/mockData.js +379 -379
  140. package/lib/constants/modelStatus.d.ts +10 -10
  141. package/lib/constants/modelStatus.js +14 -14
  142. package/lib/constants/notificationType.d.ts +7 -7
  143. package/lib/constants/notificationType.js +11 -11
  144. package/lib/constants/shard.d.ts +6 -6
  145. package/lib/constants/shard.js +10 -10
  146. package/lib/constants/tier.d.ts +6 -6
  147. package/lib/constants/tier.js +10 -10
  148. package/lib/constants/userRole.d.ts +2 -2
  149. package/lib/constants/userRole.js +21 -21
  150. package/lib/css/base/_base.css +98 -98
  151. package/lib/css/base/_typography.css +130 -130
  152. package/lib/css/components/_alert.css +85 -85
  153. package/lib/css/components/_bootstrap-grid.css +28 -28
  154. package/lib/css/components/_buttons.css +325 -325
  155. package/lib/css/components/_forms.css +91 -91
  156. package/lib/css/components/_menu.css +56 -56
  157. package/lib/css/components/_modals.css +41 -41
  158. package/lib/css/components/_tables.css +426 -426
  159. package/lib/css/components/_tags.css +12 -12
  160. package/lib/css/index-with-variables.css +14 -14
  161. package/lib/css/index.css +13 -13
  162. package/lib/css/utils/_border.css +463 -463
  163. package/lib/css/utils/_color.css +271 -271
  164. package/lib/css/utils/_display.css +312 -312
  165. package/lib/css/utils/_general.css +48 -48
  166. package/lib/css/utils/_icon.css +16 -16
  167. package/lib/css/utils/_text.css +24 -24
  168. package/lib/css/utils/_width.css +60 -60
  169. package/lib/css/variables.css +70 -70
  170. package/lib/endpointMappings.d.ts +4 -4
  171. package/lib/endpointMappings.js +173 -173
  172. package/lib/hooks/useCollection.d.ts +6 -6
  173. package/lib/hooks/useCollection.js +61 -61
  174. package/lib/hooks/useCollectionConfiguration.d.ts +27 -27
  175. package/lib/hooks/useCollectionConfiguration.js +67 -67
  176. package/lib/hooks/useCollectionItem.d.ts +6 -6
  177. package/lib/hooks/useCollectionItem.js +54 -54
  178. package/lib/hooks/useGuid.d.ts +4 -4
  179. package/lib/hooks/useGuid.js +14 -14
  180. package/lib/hooks/usePrevious.d.ts +5 -5
  181. package/lib/hooks/usePrevious.js +18 -18
  182. package/lib/index.d.ts +8 -8
  183. package/lib/index.js +30 -30
  184. package/lib/redux/actionCreator.d.ts +5 -5
  185. package/lib/redux/actionCreator.js +16 -16
  186. package/lib/redux/actions.d.ts +12 -12
  187. package/lib/redux/actions.js +30 -30
  188. package/lib/redux/configureReducers.d.ts +22 -22
  189. package/lib/redux/configureReducers.js +94 -94
  190. package/lib/redux/configureStore.d.ts +14 -14
  191. package/lib/redux/configureStore.js +118 -118
  192. package/lib/redux/helpers.d.ts +2 -2
  193. package/lib/redux/helpers.js +7 -7
  194. package/lib/redux/reducers/index.d.ts +4 -4
  195. package/lib/redux/reducers/index.js +12 -12
  196. package/lib/redux/reducers/modalsReducer.d.ts +8 -8
  197. package/lib/redux/reducers/modalsReducer.js +54 -54
  198. package/lib/redux/reducers/notificationsReducer.d.ts +9 -9
  199. package/lib/redux/reducers/notificationsReducer.js +27 -27
  200. package/lib/redux/reducers/searchReducer.d.ts +17 -17
  201. package/lib/redux/reducers/searchReducer.js +26 -26
  202. package/lib/redux/sagas/caliperSaga.d.ts +2 -2
  203. package/lib/redux/sagas/caliperSaga.js +296 -296
  204. package/lib/redux/sagas/clockOffsetSaga.d.ts +10 -10
  205. package/lib/redux/sagas/clockOffsetSaga.js +81 -81
  206. package/lib/redux/sagas/configurationSaga.d.ts +1 -1
  207. package/lib/redux/sagas/configurationSaga.js +48 -48
  208. package/lib/redux/sagas/errorSaga.d.ts +2 -2
  209. package/lib/redux/sagas/errorSaga.js +66 -66
  210. package/lib/redux/sagas/identityProviderSaga.d.ts +2 -2
  211. package/lib/redux/sagas/identityProviderSaga.js +91 -91
  212. package/lib/redux/sagas/initialDataLoadSaga.d.ts +1 -1
  213. package/lib/redux/sagas/initialDataLoadSaga.js +33 -33
  214. package/lib/redux/sagas/postLoginDataSaga.d.ts +9 -9
  215. package/lib/redux/sagas/postLoginDataSaga.js +87 -87
  216. package/lib/redux/sagas/postLoginRedirectSaga.d.ts +6 -6
  217. package/lib/redux/sagas/postLoginRedirectSaga.js +96 -96
  218. package/lib/redux/sagas/rootSaga.d.ts +5 -5
  219. package/lib/redux/sagas/rootSaga.js +144 -144
  220. package/lib/redux/sagas/sentrySaga.d.ts +1 -1
  221. package/lib/redux/sagas/sentrySaga.js +103 -103
  222. package/lib/services/codeProviderService.d.ts +3 -3
  223. package/lib/services/codeProviderService.js +36 -36
  224. package/lib/services/documentService.d.ts +10 -10
  225. package/lib/services/documentService.js +17 -17
  226. package/lib/services/persistenceService.d.ts +13 -13
  227. package/lib/services/persistenceService.js +45 -45
  228. package/lib/services/ticketProviderService.d.ts +3 -3
  229. package/lib/services/ticketProviderService.js +40 -40
  230. package/lib/services/windowService.d.ts +9 -9
  231. package/lib/services/windowService.js +15 -15
  232. package/lib/setupTests.d.ts +1 -1
  233. package/lib/setupTests.js +25 -25
  234. package/lib/startup.d.ts +29 -29
  235. package/lib/startup.js +128 -128
  236. package/lib/types/AppConfiguration.d.ts +32 -32
  237. package/lib/types/AppConfiguration.js +2 -2
  238. package/lib/types/Artifact.d.ts +14 -14
  239. package/lib/types/Artifact.js +9 -9
  240. package/lib/types/BaseReduxState.d.ts +57 -57
  241. package/lib/types/BaseReduxState.js +2 -2
  242. package/lib/types/Client.d.ts +6 -6
  243. package/lib/types/Client.js +2 -2
  244. package/lib/types/Collection.d.ts +175 -175
  245. package/lib/types/Collection.js +2 -2
  246. package/lib/types/Configuration.d.ts +12 -12
  247. package/lib/types/Configuration.js +2 -2
  248. package/lib/types/DeepLinkingResponseRequest.d.ts +4 -4
  249. package/lib/types/DeepLinkingResponseRequest.js +2 -2
  250. package/lib/types/DeletableModel.d.ts +4 -4
  251. package/lib/types/DeletableModel.js +2 -2
  252. package/lib/types/External.d.ts +31 -31
  253. package/lib/types/External.js +2 -2
  254. package/lib/types/Group.d.ts +19 -19
  255. package/lib/types/Group.js +2 -2
  256. package/lib/types/IdentityProvider.d.ts +11 -11
  257. package/lib/types/IdentityProvider.js +2 -2
  258. package/lib/types/LtiLaunch.d.ts +20 -20
  259. package/lib/types/LtiLaunch.js +2 -2
  260. package/lib/types/NameOnlyEntity.d.ts +3 -3
  261. package/lib/types/NameOnlyEntity.js +2 -2
  262. package/lib/types/Notification.d.ts +15 -15
  263. package/lib/types/Notification.js +2 -2
  264. package/lib/types/OptionalRecord.d.ts +4 -4
  265. package/lib/types/OptionalRecord.js +2 -2
  266. package/lib/types/OwnerSchedule.d.ts +9 -9
  267. package/lib/types/OwnerSchedule.js +2 -2
  268. package/lib/types/PropertyOfType.d.ts +12 -12
  269. package/lib/types/PropertyOfType.js +2 -2
  270. package/lib/types/RoleDescription.d.ts +4 -4
  271. package/lib/types/RoleDescription.js +2 -2
  272. package/lib/types/Search.d.ts +11 -11
  273. package/lib/types/Search.js +2 -2
  274. package/lib/types/SimpleLocation.d.ts +46 -46
  275. package/lib/types/SimpleLocation.js +2 -2
  276. package/lib/types/UniTime.d.ts +17 -17
  277. package/lib/types/UniTime.js +2 -2
  278. package/lib/types/User.d.ts +68 -68
  279. package/lib/types/User.js +2 -2
  280. package/lib/types/UserRole.d.ts +19 -19
  281. package/lib/types/UserRole.js +2 -2
  282. package/lib/types/index.d.ts +21 -21
  283. package/lib/types/index.js +33 -33
  284. package/lib/utils/baseActivity.d.ts +63 -63
  285. package/lib/utils/baseActivity.js +155 -155
  286. package/lib/utils/baseRole.d.ts +2 -2
  287. package/lib/utils/baseRole.js +38 -38
  288. package/lib/utils/collection.d.ts +43 -43
  289. package/lib/utils/collection.js +337 -337
  290. package/lib/utils/date.d.ts +162 -162
  291. package/lib/utils/date.js +401 -401
  292. package/lib/utils/domainIdentifier.d.ts +2 -2
  293. package/lib/utils/domainIdentifier.js +12 -12
  294. package/lib/utils/entityUserRole.d.ts +3 -3
  295. package/lib/utils/entityUserRole.js +7 -7
  296. package/lib/utils/externalGroup.d.ts +4 -4
  297. package/lib/utils/externalGroup.js +32 -32
  298. package/lib/utils/externalProviders.d.ts +2 -2
  299. package/lib/utils/externalProviders.js +11 -11
  300. package/lib/utils/externalTerms.d.ts +2 -2
  301. package/lib/utils/externalTerms.js +10 -10
  302. package/lib/utils/group.d.ts +15 -15
  303. package/lib/utils/group.js +15 -15
  304. package/lib/utils/groupDates.d.ts +9 -9
  305. package/lib/utils/groupDates.js +52 -52
  306. package/lib/utils/groupRoles.d.ts +8 -8
  307. package/lib/utils/groupRoles.js +42 -42
  308. package/lib/utils/logger.d.ts +10 -10
  309. package/lib/utils/logger.js +34 -34
  310. package/lib/utils/lti.d.ts +3 -3
  311. package/lib/utils/lti.js +9 -9
  312. package/lib/utils/model.d.ts +15 -15
  313. package/lib/utils/model.js +58 -58
  314. package/lib/utils/number.d.ts +13 -13
  315. package/lib/utils/number.js +32 -32
  316. package/lib/utils/promise.d.ts +5 -5
  317. package/lib/utils/promise.js +17 -17
  318. package/lib/utils/route.d.ts +5 -5
  319. package/lib/utils/route.js +69 -69
  320. package/lib/utils/shard.d.ts +3 -3
  321. package/lib/utils/shard.js +45 -45
  322. package/lib/utils/sort.d.ts +11 -11
  323. package/lib/utils/sort.js +69 -69
  324. package/lib/utils/string.d.ts +2 -2
  325. package/lib/utils/string.js +16 -16
  326. package/lib/utils/timezone.d.ts +2 -2
  327. package/lib/utils/timezone.js +32 -32
  328. package/lib/utils/url.d.ts +23 -23
  329. package/lib/utils/url.js +163 -163
  330. package/lib/utils/user.d.ts +8 -8
  331. package/lib/utils/user.js +73 -73
  332. package/lib/utils/userRole.d.ts +21 -21
  333. package/lib/utils/userRole.js +48 -48
  334. package/package.json +192 -192
@@ -1,337 +1,337 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanupCollectionGuidKey = exports.handleCollectionParamsChange = exports.handleCollectionItemParamsChange = exports.initializeCollection = exports.initializeCollectionItem = exports.deleteCollectionItem = exports.deleteItemFromCollection = exports.updateCollectionItem = exports.updateItemInCollection = exports.createCollectionItem = exports.createItemInCollection = exports.loadCollectionItem = exports.loadCollection = exports.stopCollectionPeriodicLoad = exports.selectCollectionFromState = exports.selectCollectionItemFromState = void 0;
4
- var lodash_1 = require("lodash");
5
- var studiokit_net_js_1 = require("studiokit-net-js");
6
- var constants_1 = require("../constants");
7
- var actionCreator_1 = require("../redux/actionCreator");
8
- var model_1 = require("./model");
9
- var route_1 = require("./route");
10
- //#region Redux Methods
11
- function selectCollectionItemFromState(params) {
12
- var guid = params.guid, modelName = params.modelName, pathParams = params.pathParams, routeMatchParams = params.routeMatchParams, state = params.state;
13
- var modelNameLevelCount = route_1.getMinRequiredPathParamsCount(modelName);
14
- var p = pathParams || route_1.getPathParamsFromRouteMatchParams(routeMatchParams, modelName);
15
- var reduxModelName = route_1.getReduxModelName(p, modelName);
16
- var model = {};
17
- // find `model` using `guid` as its key, to match new item created in `create()`
18
- if (p.length === modelNameLevelCount) {
19
- var collection = (lodash_1.get(state.models, reduxModelName) || {});
20
- if (Object.prototype.hasOwnProperty.call(collection, guid)) {
21
- model = collection[guid];
22
- }
23
- else {
24
- var modelByGuid = lodash_1.find(lodash_1.values(collection), function (m) { return m && m.guid && m.guid === guid; });
25
- model = modelByGuid || model;
26
- }
27
- }
28
- else {
29
- // find `model` using pathParams
30
- var reduxModel = (lodash_1.get(state.models, reduxModelName) || {});
31
- model = (Object.keys(reduxModel).length > 0 ? lodash_1.merge({}, reduxModel) : {});
32
- }
33
- // convenient way to access model without relations, for use in PUT requests
34
- var modelMinusRelations = model_1.getModelMinusRelations(model);
35
- return {
36
- modelName: modelName,
37
- pathParams: p,
38
- model: model,
39
- modelMinusRelations: modelMinusRelations
40
- };
41
- }
42
- exports.selectCollectionItemFromState = selectCollectionItemFromState;
43
- function selectCollectionFromState(params) {
44
- var guid = params.guid, modelName = params.modelName, pathParams = params.pathParams, routeMatchParams = params.routeMatchParams, state = params.state;
45
- var p = pathParams || route_1.getPathParamsFromRouteMatchParams(routeMatchParams, modelName);
46
- var reduxModelName = route_1.getReduxModelName(p, modelName);
47
- var model = lodash_1.get(state.models, reduxModelName);
48
- model = model && Object.keys(model).length > 0 ? lodash_1.merge({}, model) : {};
49
- // convenient way to access collection as an array
50
- var modelArray = model_1.getModelArray(model, guid);
51
- return {
52
- modelName: modelName,
53
- pathParams: p,
54
- model: model,
55
- modelArray: modelArray
56
- };
57
- }
58
- exports.selectCollectionFromState = selectCollectionFromState;
59
- //#endregion Redux Methods
60
- //#region Collection/Item CRUD Methods
61
- //#region Load
62
- function stopCollectionPeriodicLoad(modelName, taskId) {
63
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_TERMINATION_REQUESTED, {
64
- modelName: modelName,
65
- taskId: taskId
66
- });
67
- }
68
- exports.stopCollectionPeriodicLoad = stopCollectionPeriodicLoad;
69
- function loadCollection(config, params) {
70
- if (params === void 0) { params = {}; }
71
- var modelName = config.modelName, modelStatus = config.modelStatus, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
72
- var id = params.id, pathParams = params.pathParams, queryParams = params.queryParams, period = params.period, taskId = params.taskId;
73
- var p = lodash_1.concat([], pathParams || configPathParams, id ? [id] : []);
74
- if (p.length !== route_1.getMinRequiredPathParamsCount(modelName) + (id ? 1 : 0)) {
75
- throw new Error('pathParams length does not match length of path components');
76
- }
77
- if (modelStatus !== constants_1.MODEL_STATUS.UNINITIALIZED) {
78
- changeModelStatus(constants_1.MODEL_STATUS.LOADING, id);
79
- }
80
- if (!period) {
81
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
82
- modelName: modelName,
83
- method: 'GET',
84
- pathParams: p,
85
- queryParams: queryParams || configQueryParams
86
- });
87
- }
88
- else {
89
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_DATA_REQUESTED, {
90
- modelName: modelName,
91
- method: 'GET',
92
- pathParams: p,
93
- queryParams: queryParams || configQueryParams,
94
- period: period,
95
- taskId: taskId
96
- });
97
- }
98
- }
99
- exports.loadCollection = loadCollection;
100
- function loadCollectionItem(config, params) {
101
- if (params === void 0) { params = {}; }
102
- var modelName = config.modelName, modelStatus = config.modelStatus, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
103
- var pathParams = params.pathParams, queryParams = params.queryParams, period = params.period, taskId = params.taskId;
104
- var p = pathParams || configPathParams;
105
- if (p && p.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
106
- throw new Error('pathParams length does not match length of path components');
107
- }
108
- if (modelStatus !== constants_1.MODEL_STATUS.UNINITIALIZED) {
109
- changeModelStatus(constants_1.MODEL_STATUS.LOADING);
110
- }
111
- if (!period) {
112
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
113
- modelName: modelName,
114
- method: 'GET',
115
- pathParams: p,
116
- queryParams: queryParams || configQueryParams
117
- });
118
- }
119
- else {
120
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_DATA_REQUESTED, {
121
- modelName: modelName,
122
- method: 'GET',
123
- pathParams: p,
124
- queryParams: queryParams || configQueryParams,
125
- period: period,
126
- taskId: taskId
127
- });
128
- }
129
- }
130
- exports.loadCollectionItem = loadCollectionItem;
131
- //#endregion Load
132
- //#region Create
133
- function createItemInCollection(config, params) {
134
- var guid = config.guid, modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
135
- var body = params.body, contentType = params.contentType, queryParams = params.queryParams;
136
- if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName)) {
137
- throw new Error('pathParams length does not match length of path components');
138
- }
139
- changeModelStatus(constants_1.MODEL_STATUS.CREATING, guid);
140
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
141
- modelName: modelName,
142
- guid: guid,
143
- method: 'POST',
144
- body: body,
145
- pathParams: pathParams,
146
- contentType: contentType,
147
- queryParams: queryParams || configQueryParams
148
- });
149
- }
150
- exports.createItemInCollection = createItemInCollection;
151
- function createCollectionItem(model, config, params) {
152
- if (model.id) {
153
- throw new Error('model already exists');
154
- }
155
- createItemInCollection(config, params);
156
- }
157
- exports.createCollectionItem = createCollectionItem;
158
- //#endregion Create
159
- //#region Update
160
- function updateItemInCollection(config, params) {
161
- var id = params.id, body = params.body, contentType = params.contentType, method = params.method, queryParams = params.queryParams;
162
- if (!id) {
163
- throw new Error("'id' is required");
164
- }
165
- if (!body) {
166
- throw new Error("'body' is required");
167
- }
168
- var modelName = config.modelName, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
169
- var pathParams = lodash_1.concat([], configPathParams, [id]);
170
- if (pathParams.length !== route_1.getMinRequiredPathParamsCount(modelName) + 1) {
171
- throw new Error('pathParams+id length does not match length of path components');
172
- }
173
- var m = method || 'PUT';
174
- changeModelStatus(constants_1.MODEL_STATUS.UPDATING, id);
175
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
176
- modelName: modelName,
177
- method: m,
178
- pathParams: pathParams,
179
- queryParams: queryParams || configQueryParams,
180
- body: body,
181
- contentType: contentType
182
- });
183
- }
184
- exports.updateItemInCollection = updateItemInCollection;
185
- function updateCollectionItem(model, config, params) {
186
- if (!model.id) {
187
- throw new Error('model does not exist');
188
- }
189
- var body = params.body, contentType = params.contentType, method = params.method, queryParams = params.queryParams;
190
- if (!body) {
191
- throw new Error("'body' is required");
192
- }
193
- var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
194
- if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
195
- throw new Error('pathParams length does not match length of path components');
196
- }
197
- var m = method || 'PUT';
198
- changeModelStatus(constants_1.MODEL_STATUS.UPDATING);
199
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
200
- modelName: modelName,
201
- method: m,
202
- pathParams: pathParams,
203
- body: body,
204
- contentType: contentType,
205
- queryParams: queryParams || configQueryParams
206
- });
207
- }
208
- exports.updateCollectionItem = updateCollectionItem;
209
- //#endregion Update
210
- //#region Delete
211
- function deleteItemFromCollection(config, params) {
212
- var id = params.id, body = params.body, queryParams = params.queryParams;
213
- if (!id) {
214
- throw new Error("'id' is required");
215
- }
216
- var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
217
- var p = lodash_1.concat([], pathParams, [id]);
218
- if (p.length !== route_1.getMinRequiredPathParamsCount(modelName) + 1) {
219
- throw new Error('pathParams+id length does not match length of path components');
220
- }
221
- changeModelStatus(constants_1.MODEL_STATUS.DELETING, id);
222
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
223
- modelName: modelName,
224
- method: 'DELETE',
225
- pathParams: p,
226
- queryParams: queryParams || configQueryParams,
227
- body: body
228
- });
229
- }
230
- exports.deleteItemFromCollection = deleteItemFromCollection;
231
- function deleteCollectionItem(model, config, params) {
232
- if (params === void 0) { params = {}; }
233
- if (!model.id) {
234
- throw new Error('model does not exist');
235
- }
236
- var body = params.body, queryParams = params.queryParams;
237
- var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
238
- if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
239
- throw new Error('pathParams length does not match length of path components');
240
- }
241
- changeModelStatus(constants_1.MODEL_STATUS.DELETING);
242
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
243
- modelName: modelName,
244
- method: 'DELETE',
245
- pathParams: pathParams,
246
- body: body,
247
- queryParams: queryParams || configQueryParams
248
- });
249
- }
250
- exports.deleteCollectionItem = deleteCollectionItem;
251
- //#endregion Delete
252
- //#endregion Collection/Item CRUD Methods
253
- //#region Helper Methods
254
- /**
255
- * Automatically call `load`, or `changeModelStatus` to `READY`.
256
- *
257
- * Does NOT automatically load if:
258
- * * pathParams does not contain enough items.
259
- * * model is already fetching.
260
- * * auto load is disabled.
261
- */
262
- function initializeCollectionItem(model, load, config) {
263
- var modelName = config.modelName, pathParams = config.pathParams, disableAutoLoad = config.disableAutoLoad, changeModelStatus = config.changeModelStatus;
264
- if (pathParams.length === route_1.getMinRequiredPathParamsCount(modelName) + 1 &&
265
- !disableAutoLoad &&
266
- (!model._metadata || model._metadata.isFetching === false)) {
267
- load();
268
- }
269
- else {
270
- changeModelStatus(constants_1.MODEL_STATUS.READY);
271
- }
272
- }
273
- exports.initializeCollectionItem = initializeCollectionItem;
274
- /**
275
- * Automatically call `load`, or `changeModelStatus` to `READY`.
276
- *
277
- * Does NOT automatically load if:
278
- * * model is already fetching.
279
- * * auto load is disabled.
280
- */
281
- function initializeCollection(model, load, config) {
282
- var disableAutoLoad = config.disableAutoLoad, changeModelStatus = config.changeModelStatus;
283
- if (!disableAutoLoad && (!model._metadata || !model._metadata.isFetching)) {
284
- load();
285
- }
286
- else if (disableAutoLoad) {
287
- changeModelStatus(constants_1.MODEL_STATUS.READY);
288
- }
289
- }
290
- exports.initializeCollection = initializeCollection;
291
- /**
292
- * When `pathParams` or `queryParams` change, call `load`
293
- */
294
- function handleCollectionItemParamsChange(modelName, pathParams, prevPathParams, queryParams, prevQueryParams, load) {
295
- if ((pathParams.length === route_1.getMinRequiredPathParamsCount(modelName) + 1 && !lodash_1.isEqual(prevPathParams, pathParams)) ||
296
- !lodash_1.isEqual(prevQueryParams, queryParams)) {
297
- load({ pathParams: pathParams, queryParams: queryParams });
298
- }
299
- }
300
- exports.handleCollectionItemParamsChange = handleCollectionItemParamsChange;
301
- /**
302
- * When `pathParams` or `queryParams` change, call `load`
303
- */
304
- function handleCollectionParamsChange(pathParams, prevPathParams, queryParams, prevQueryParams, load) {
305
- if ((pathParams.length > 0 && !lodash_1.isEqual(prevPathParams, pathParams)) || !lodash_1.isEqual(prevQueryParams, queryParams)) {
306
- load({ pathParams: pathParams, queryParams: queryParams });
307
- }
308
- }
309
- exports.handleCollectionParamsChange = handleCollectionParamsChange;
310
- /**
311
- * Delete the guid in the model
312
- */
313
- function cleanupCollectionGuidKey(model, config) {
314
- var guid = config.guid, modelName = config.modelName, pathParams = config.pathParams;
315
- if (lodash_1.includes(Object.keys(model), guid)) {
316
- var modelNames = modelName.split('.');
317
- var tempPathParams_1 = pathParams.slice();
318
- // should include the guid at the end
319
- tempPathParams_1.push(guid);
320
- if (modelNames.length === tempPathParams_1.length) {
321
- var path_1 = '';
322
- modelNames.forEach(function (m, i) {
323
- if (i === 0) {
324
- path_1 += m + "." + tempPathParams_1[i];
325
- }
326
- else {
327
- path_1 += "." + m + "." + tempPathParams_1[i];
328
- }
329
- });
330
- actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.KEY_REMOVAL_REQUESTED, {
331
- modelName: path_1
332
- });
333
- }
334
- }
335
- }
336
- exports.cleanupCollectionGuidKey = cleanupCollectionGuidKey;
337
- //#endregion Helper Methods
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanupCollectionGuidKey = exports.handleCollectionParamsChange = exports.handleCollectionItemParamsChange = exports.initializeCollection = exports.initializeCollectionItem = exports.deleteCollectionItem = exports.deleteItemFromCollection = exports.updateCollectionItem = exports.updateItemInCollection = exports.createCollectionItem = exports.createItemInCollection = exports.loadCollectionItem = exports.loadCollection = exports.stopCollectionPeriodicLoad = exports.selectCollectionFromState = exports.selectCollectionItemFromState = void 0;
4
+ var lodash_1 = require("lodash");
5
+ var studiokit_net_js_1 = require("studiokit-net-js");
6
+ var constants_1 = require("../constants");
7
+ var actionCreator_1 = require("../redux/actionCreator");
8
+ var model_1 = require("./model");
9
+ var route_1 = require("./route");
10
+ //#region Redux Methods
11
+ function selectCollectionItemFromState(params) {
12
+ var guid = params.guid, modelName = params.modelName, pathParams = params.pathParams, routeMatchParams = params.routeMatchParams, state = params.state;
13
+ var modelNameLevelCount = route_1.getMinRequiredPathParamsCount(modelName);
14
+ var p = pathParams || route_1.getPathParamsFromRouteMatchParams(routeMatchParams, modelName);
15
+ var reduxModelName = route_1.getReduxModelName(p, modelName);
16
+ var model = {};
17
+ // find `model` using `guid` as its key, to match new item created in `create()`
18
+ if (p.length === modelNameLevelCount) {
19
+ var collection = (lodash_1.get(state.models, reduxModelName) || {});
20
+ if (Object.prototype.hasOwnProperty.call(collection, guid)) {
21
+ model = collection[guid];
22
+ }
23
+ else {
24
+ var modelByGuid = lodash_1.find(lodash_1.values(collection), function (m) { return m && m.guid && m.guid === guid; });
25
+ model = modelByGuid || model;
26
+ }
27
+ }
28
+ else {
29
+ // find `model` using pathParams
30
+ var reduxModel = (lodash_1.get(state.models, reduxModelName) || {});
31
+ model = (Object.keys(reduxModel).length > 0 ? lodash_1.merge({}, reduxModel) : {});
32
+ }
33
+ // convenient way to access model without relations, for use in PUT requests
34
+ var modelMinusRelations = model_1.getModelMinusRelations(model);
35
+ return {
36
+ modelName: modelName,
37
+ pathParams: p,
38
+ model: model,
39
+ modelMinusRelations: modelMinusRelations
40
+ };
41
+ }
42
+ exports.selectCollectionItemFromState = selectCollectionItemFromState;
43
+ function selectCollectionFromState(params) {
44
+ var guid = params.guid, modelName = params.modelName, pathParams = params.pathParams, routeMatchParams = params.routeMatchParams, state = params.state;
45
+ var p = pathParams || route_1.getPathParamsFromRouteMatchParams(routeMatchParams, modelName);
46
+ var reduxModelName = route_1.getReduxModelName(p, modelName);
47
+ var model = lodash_1.get(state.models, reduxModelName);
48
+ model = model && Object.keys(model).length > 0 ? lodash_1.merge({}, model) : {};
49
+ // convenient way to access collection as an array
50
+ var modelArray = model_1.getModelArray(model, guid);
51
+ return {
52
+ modelName: modelName,
53
+ pathParams: p,
54
+ model: model,
55
+ modelArray: modelArray
56
+ };
57
+ }
58
+ exports.selectCollectionFromState = selectCollectionFromState;
59
+ //#endregion Redux Methods
60
+ //#region Collection/Item CRUD Methods
61
+ //#region Load
62
+ function stopCollectionPeriodicLoad(modelName, taskId) {
63
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_TERMINATION_REQUESTED, {
64
+ modelName: modelName,
65
+ taskId: taskId
66
+ });
67
+ }
68
+ exports.stopCollectionPeriodicLoad = stopCollectionPeriodicLoad;
69
+ function loadCollection(config, params) {
70
+ if (params === void 0) { params = {}; }
71
+ var modelName = config.modelName, modelStatus = config.modelStatus, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
72
+ var id = params.id, pathParams = params.pathParams, queryParams = params.queryParams, period = params.period, taskId = params.taskId;
73
+ var p = lodash_1.concat([], pathParams || configPathParams, id ? [id] : []);
74
+ if (p.length !== route_1.getMinRequiredPathParamsCount(modelName) + (id ? 1 : 0)) {
75
+ throw new Error('pathParams length does not match length of path components');
76
+ }
77
+ if (modelStatus !== constants_1.MODEL_STATUS.UNINITIALIZED) {
78
+ changeModelStatus(constants_1.MODEL_STATUS.LOADING, id);
79
+ }
80
+ if (!period) {
81
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
82
+ modelName: modelName,
83
+ method: 'GET',
84
+ pathParams: p,
85
+ queryParams: queryParams || configQueryParams
86
+ });
87
+ }
88
+ else {
89
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_DATA_REQUESTED, {
90
+ modelName: modelName,
91
+ method: 'GET',
92
+ pathParams: p,
93
+ queryParams: queryParams || configQueryParams,
94
+ period: period,
95
+ taskId: taskId
96
+ });
97
+ }
98
+ }
99
+ exports.loadCollection = loadCollection;
100
+ function loadCollectionItem(config, params) {
101
+ if (params === void 0) { params = {}; }
102
+ var modelName = config.modelName, modelStatus = config.modelStatus, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
103
+ var pathParams = params.pathParams, queryParams = params.queryParams, period = params.period, taskId = params.taskId;
104
+ var p = pathParams || configPathParams;
105
+ if (p && p.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
106
+ throw new Error('pathParams length does not match length of path components');
107
+ }
108
+ if (modelStatus !== constants_1.MODEL_STATUS.UNINITIALIZED) {
109
+ changeModelStatus(constants_1.MODEL_STATUS.LOADING);
110
+ }
111
+ if (!period) {
112
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
113
+ modelName: modelName,
114
+ method: 'GET',
115
+ pathParams: p,
116
+ queryParams: queryParams || configQueryParams
117
+ });
118
+ }
119
+ else {
120
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.PERIODIC_DATA_REQUESTED, {
121
+ modelName: modelName,
122
+ method: 'GET',
123
+ pathParams: p,
124
+ queryParams: queryParams || configQueryParams,
125
+ period: period,
126
+ taskId: taskId
127
+ });
128
+ }
129
+ }
130
+ exports.loadCollectionItem = loadCollectionItem;
131
+ //#endregion Load
132
+ //#region Create
133
+ function createItemInCollection(config, params) {
134
+ var guid = config.guid, modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
135
+ var body = params.body, contentType = params.contentType, queryParams = params.queryParams;
136
+ if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName)) {
137
+ throw new Error('pathParams length does not match length of path components');
138
+ }
139
+ changeModelStatus(constants_1.MODEL_STATUS.CREATING, guid);
140
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
141
+ modelName: modelName,
142
+ guid: guid,
143
+ method: 'POST',
144
+ body: body,
145
+ pathParams: pathParams,
146
+ contentType: contentType,
147
+ queryParams: queryParams || configQueryParams
148
+ });
149
+ }
150
+ exports.createItemInCollection = createItemInCollection;
151
+ function createCollectionItem(model, config, params) {
152
+ if (model.id) {
153
+ throw new Error('model already exists');
154
+ }
155
+ createItemInCollection(config, params);
156
+ }
157
+ exports.createCollectionItem = createCollectionItem;
158
+ //#endregion Create
159
+ //#region Update
160
+ function updateItemInCollection(config, params) {
161
+ var id = params.id, body = params.body, contentType = params.contentType, method = params.method, queryParams = params.queryParams;
162
+ if (!id) {
163
+ throw new Error("'id' is required");
164
+ }
165
+ if (!body) {
166
+ throw new Error("'body' is required");
167
+ }
168
+ var modelName = config.modelName, configPathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
169
+ var pathParams = lodash_1.concat([], configPathParams, [id]);
170
+ if (pathParams.length !== route_1.getMinRequiredPathParamsCount(modelName) + 1) {
171
+ throw new Error('pathParams+id length does not match length of path components');
172
+ }
173
+ var m = method || 'PUT';
174
+ changeModelStatus(constants_1.MODEL_STATUS.UPDATING, id);
175
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
176
+ modelName: modelName,
177
+ method: m,
178
+ pathParams: pathParams,
179
+ queryParams: queryParams || configQueryParams,
180
+ body: body,
181
+ contentType: contentType
182
+ });
183
+ }
184
+ exports.updateItemInCollection = updateItemInCollection;
185
+ function updateCollectionItem(model, config, params) {
186
+ if (!model.id) {
187
+ throw new Error('model does not exist');
188
+ }
189
+ var body = params.body, contentType = params.contentType, method = params.method, queryParams = params.queryParams;
190
+ if (!body) {
191
+ throw new Error("'body' is required");
192
+ }
193
+ var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
194
+ if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
195
+ throw new Error('pathParams length does not match length of path components');
196
+ }
197
+ var m = method || 'PUT';
198
+ changeModelStatus(constants_1.MODEL_STATUS.UPDATING);
199
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
200
+ modelName: modelName,
201
+ method: m,
202
+ pathParams: pathParams,
203
+ body: body,
204
+ contentType: contentType,
205
+ queryParams: queryParams || configQueryParams
206
+ });
207
+ }
208
+ exports.updateCollectionItem = updateCollectionItem;
209
+ //#endregion Update
210
+ //#region Delete
211
+ function deleteItemFromCollection(config, params) {
212
+ var id = params.id, body = params.body, queryParams = params.queryParams;
213
+ if (!id) {
214
+ throw new Error("'id' is required");
215
+ }
216
+ var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
217
+ var p = lodash_1.concat([], pathParams, [id]);
218
+ if (p.length !== route_1.getMinRequiredPathParamsCount(modelName) + 1) {
219
+ throw new Error('pathParams+id length does not match length of path components');
220
+ }
221
+ changeModelStatus(constants_1.MODEL_STATUS.DELETING, id);
222
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
223
+ modelName: modelName,
224
+ method: 'DELETE',
225
+ pathParams: p,
226
+ queryParams: queryParams || configQueryParams,
227
+ body: body
228
+ });
229
+ }
230
+ exports.deleteItemFromCollection = deleteItemFromCollection;
231
+ function deleteCollectionItem(model, config, params) {
232
+ if (params === void 0) { params = {}; }
233
+ if (!model.id) {
234
+ throw new Error('model does not exist');
235
+ }
236
+ var body = params.body, queryParams = params.queryParams;
237
+ var modelName = config.modelName, pathParams = config.pathParams, configQueryParams = config.queryParams, changeModelStatus = config.changeModelStatus;
238
+ if (pathParams && pathParams.length < route_1.getMinRequiredPathParamsCount(modelName) + 1) {
239
+ throw new Error('pathParams length does not match length of path components');
240
+ }
241
+ changeModelStatus(constants_1.MODEL_STATUS.DELETING);
242
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.DATA_REQUESTED, {
243
+ modelName: modelName,
244
+ method: 'DELETE',
245
+ pathParams: pathParams,
246
+ body: body,
247
+ queryParams: queryParams || configQueryParams
248
+ });
249
+ }
250
+ exports.deleteCollectionItem = deleteCollectionItem;
251
+ //#endregion Delete
252
+ //#endregion Collection/Item CRUD Methods
253
+ //#region Helper Methods
254
+ /**
255
+ * Automatically call `load`, or `changeModelStatus` to `READY`.
256
+ *
257
+ * Does NOT automatically load if:
258
+ * * pathParams does not contain enough items.
259
+ * * model is already fetching.
260
+ * * auto load is disabled.
261
+ */
262
+ function initializeCollectionItem(model, load, config) {
263
+ var modelName = config.modelName, pathParams = config.pathParams, disableAutoLoad = config.disableAutoLoad, changeModelStatus = config.changeModelStatus;
264
+ if (pathParams.length === route_1.getMinRequiredPathParamsCount(modelName) + 1 &&
265
+ !disableAutoLoad &&
266
+ (!model._metadata || model._metadata.isFetching === false)) {
267
+ load();
268
+ }
269
+ else {
270
+ changeModelStatus(constants_1.MODEL_STATUS.READY);
271
+ }
272
+ }
273
+ exports.initializeCollectionItem = initializeCollectionItem;
274
+ /**
275
+ * Automatically call `load`, or `changeModelStatus` to `READY`.
276
+ *
277
+ * Does NOT automatically load if:
278
+ * * model is already fetching.
279
+ * * auto load is disabled.
280
+ */
281
+ function initializeCollection(model, load, config) {
282
+ var disableAutoLoad = config.disableAutoLoad, changeModelStatus = config.changeModelStatus;
283
+ if (!disableAutoLoad && (!model._metadata || !model._metadata.isFetching)) {
284
+ load();
285
+ }
286
+ else if (disableAutoLoad) {
287
+ changeModelStatus(constants_1.MODEL_STATUS.READY);
288
+ }
289
+ }
290
+ exports.initializeCollection = initializeCollection;
291
+ /**
292
+ * When `pathParams` or `queryParams` change, call `load`
293
+ */
294
+ function handleCollectionItemParamsChange(modelName, pathParams, prevPathParams, queryParams, prevQueryParams, load) {
295
+ if ((pathParams.length === route_1.getMinRequiredPathParamsCount(modelName) + 1 && !lodash_1.isEqual(prevPathParams, pathParams)) ||
296
+ !lodash_1.isEqual(prevQueryParams, queryParams)) {
297
+ load({ pathParams: pathParams, queryParams: queryParams });
298
+ }
299
+ }
300
+ exports.handleCollectionItemParamsChange = handleCollectionItemParamsChange;
301
+ /**
302
+ * When `pathParams` or `queryParams` change, call `load`
303
+ */
304
+ function handleCollectionParamsChange(pathParams, prevPathParams, queryParams, prevQueryParams, load) {
305
+ if ((pathParams.length > 0 && !lodash_1.isEqual(prevPathParams, pathParams)) || !lodash_1.isEqual(prevQueryParams, queryParams)) {
306
+ load({ pathParams: pathParams, queryParams: queryParams });
307
+ }
308
+ }
309
+ exports.handleCollectionParamsChange = handleCollectionParamsChange;
310
+ /**
311
+ * Delete the guid in the model
312
+ */
313
+ function cleanupCollectionGuidKey(model, config) {
314
+ var guid = config.guid, modelName = config.modelName, pathParams = config.pathParams;
315
+ if (lodash_1.includes(Object.keys(model), guid)) {
316
+ var modelNames = modelName.split('.');
317
+ var tempPathParams_1 = pathParams.slice();
318
+ // should include the guid at the end
319
+ tempPathParams_1.push(guid);
320
+ if (modelNames.length === tempPathParams_1.length) {
321
+ var path_1 = '';
322
+ modelNames.forEach(function (m, i) {
323
+ if (i === 0) {
324
+ path_1 += m + "." + tempPathParams_1[i];
325
+ }
326
+ else {
327
+ path_1 += "." + m + "." + tempPathParams_1[i];
328
+ }
329
+ });
330
+ actionCreator_1.dispatchAction(studiokit_net_js_1.NET_ACTION.KEY_REMOVAL_REQUESTED, {
331
+ modelName: path_1
332
+ });
333
+ }
334
+ }
335
+ }
336
+ exports.cleanupCollectionGuidKey = cleanupCollectionGuidKey;
337
+ //#endregion Helper Methods