@cratis/arc.react 18.0.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.
Files changed (311) hide show
  1. package/Arc.tsx +44 -0
  2. package/ArcContext.ts +23 -0
  3. package/Bindings.ts +15 -0
  4. package/README.md +65 -0
  5. package/WellKnownBindings.ts +9 -0
  6. package/commands/CommandScope.tsx +57 -0
  7. package/commands/CommandScopeImplementation.ts +68 -0
  8. package/commands/ICommandScope.ts +31 -0
  9. package/commands/for_CommandScopeImplementation/FakeCommand.ts +59 -0
  10. package/commands/for_CommandScopeImplementation/when_executing_with_three_commands_were_two_having_changes.ts +25 -0
  11. package/commands/for_CommandScopeImplementation/when_none_of_the_added_commands_has_changes.ts +19 -0
  12. package/commands/for_CommandScopeImplementation/when_one_of_the_added_commands_has_changes.ts +19 -0
  13. package/commands/for_CommandScopeImplementation/when_property_changes_on_added_command.ts +26 -0
  14. package/commands/for_CommandScopeImplementation/when_reverting_with_three_commands_were_two_having_changes.ts +25 -0
  15. package/commands/for_CommandScopeImplementation/when_there_are_no_commands.ts +10 -0
  16. package/commands/for_useCommand/FakeCommand.ts +31 -0
  17. package/commands/for_useCommand/when_creating_instance.ts +41 -0
  18. package/commands/for_useCommand/when_creating_instance_with_initial_values.ts +38 -0
  19. package/commands/for_useCommand/when_creating_instance_without_optional_context_values.ts +37 -0
  20. package/commands/index.ts +8 -0
  21. package/commands/useCommand.ts +70 -0
  22. package/commands/useCommandScope.ts +9 -0
  23. package/dialogs/BusyIndicatorDialogRequest.ts +18 -0
  24. package/dialogs/CloseDialog.ts +9 -0
  25. package/dialogs/ConfirmationDialogRequest.ts +22 -0
  26. package/dialogs/DialogButtons.ts +28 -0
  27. package/dialogs/DialogComponents.tsx +113 -0
  28. package/dialogs/DialogContext.ts +33 -0
  29. package/dialogs/DialogProps.ts +14 -0
  30. package/dialogs/DialogResponse.ts +9 -0
  31. package/dialogs/DialogResult.ts +32 -0
  32. package/dialogs/ShowDialog.ts +9 -0
  33. package/dialogs/index.ts +16 -0
  34. package/dialogs/useBusyIndicator.ts +41 -0
  35. package/dialogs/useConfirmationDialog.ts +39 -0
  36. package/dialogs/useDialog.tsx +55 -0
  37. package/dist/cjs/Arc.d.ts +12 -0
  38. package/dist/cjs/Arc.d.ts.map +1 -0
  39. package/dist/cjs/Arc.js +25 -0
  40. package/dist/cjs/Arc.js.map +1 -0
  41. package/dist/cjs/ArcContext.d.ts +12 -0
  42. package/dist/cjs/ArcContext.d.ts.map +1 -0
  43. package/dist/cjs/ArcContext.js +16 -0
  44. package/dist/cjs/ArcContext.js.map +1 -0
  45. package/dist/cjs/Bindings.d.ts +5 -0
  46. package/dist/cjs/Bindings.d.ts.map +1 -0
  47. package/dist/cjs/Bindings.js +15 -0
  48. package/dist/cjs/Bindings.js.map +1 -0
  49. package/dist/cjs/WellKnownBindings.d.ts +4 -0
  50. package/dist/cjs/WellKnownBindings.d.ts.map +1 -0
  51. package/dist/cjs/WellKnownBindings.js +8 -0
  52. package/dist/cjs/WellKnownBindings.js.map +1 -0
  53. package/dist/cjs/commands/CommandScope.d.ts +13 -0
  54. package/dist/cjs/commands/CommandScope.d.ts.map +1 -0
  55. package/dist/cjs/commands/CommandScope.js +39 -0
  56. package/dist/cjs/commands/CommandScope.js.map +1 -0
  57. package/dist/cjs/commands/CommandScopeImplementation.d.ts +16 -0
  58. package/dist/cjs/commands/CommandScopeImplementation.d.ts.map +1 -0
  59. package/dist/cjs/commands/CommandScopeImplementation.js +52 -0
  60. package/dist/cjs/commands/CommandScopeImplementation.js.map +1 -0
  61. package/dist/cjs/commands/ICommandScope.d.ts +8 -0
  62. package/dist/cjs/commands/ICommandScope.d.ts.map +1 -0
  63. package/dist/cjs/commands/index.d.ts +6 -0
  64. package/dist/cjs/commands/index.d.ts.map +1 -0
  65. package/dist/cjs/commands/index.js +15 -0
  66. package/dist/cjs/commands/index.js.map +1 -0
  67. package/dist/cjs/commands/useCommand.d.ts +6 -0
  68. package/dist/cjs/commands/useCommand.d.ts.map +1 -0
  69. package/dist/cjs/commands/useCommand.js +47 -0
  70. package/dist/cjs/commands/useCommand.js.map +1 -0
  71. package/dist/cjs/commands/useCommandScope.d.ts +2 -0
  72. package/dist/cjs/commands/useCommandScope.d.ts.map +1 -0
  73. package/dist/cjs/commands/useCommandScope.js +11 -0
  74. package/dist/cjs/commands/useCommandScope.js.map +1 -0
  75. package/dist/cjs/dialogs/BusyIndicatorDialogRequest.d.ts +6 -0
  76. package/dist/cjs/dialogs/BusyIndicatorDialogRequest.d.ts.map +1 -0
  77. package/dist/cjs/dialogs/BusyIndicatorDialogRequest.js +13 -0
  78. package/dist/cjs/dialogs/BusyIndicatorDialogRequest.js.map +1 -0
  79. package/dist/cjs/dialogs/CloseDialog.d.ts +3 -0
  80. package/dist/cjs/dialogs/CloseDialog.d.ts.map +1 -0
  81. package/dist/cjs/dialogs/ConfirmationDialogRequest.d.ts +8 -0
  82. package/dist/cjs/dialogs/ConfirmationDialogRequest.d.ts.map +1 -0
  83. package/dist/cjs/dialogs/ConfirmationDialogRequest.js +15 -0
  84. package/dist/cjs/dialogs/ConfirmationDialogRequest.js.map +1 -0
  85. package/dist/cjs/dialogs/DialogButtons.d.ts +7 -0
  86. package/dist/cjs/dialogs/DialogButtons.d.ts.map +1 -0
  87. package/dist/cjs/dialogs/DialogButtons.js +10 -0
  88. package/dist/cjs/dialogs/DialogButtons.js.map +1 -0
  89. package/dist/cjs/dialogs/DialogComponents.d.ts +20 -0
  90. package/dist/cjs/dialogs/DialogComponents.d.ts.map +1 -0
  91. package/dist/cjs/dialogs/DialogComponents.js +34 -0
  92. package/dist/cjs/dialogs/DialogComponents.js.map +1 -0
  93. package/dist/cjs/dialogs/DialogContext.d.ts +10 -0
  94. package/dist/cjs/dialogs/DialogContext.d.ts.map +1 -0
  95. package/dist/cjs/dialogs/DialogContext.js +40 -0
  96. package/dist/cjs/dialogs/DialogContext.js.map +1 -0
  97. package/dist/cjs/dialogs/DialogProps.d.ts +5 -0
  98. package/dist/cjs/dialogs/DialogProps.d.ts.map +1 -0
  99. package/dist/cjs/dialogs/DialogResponse.d.ts +3 -0
  100. package/dist/cjs/dialogs/DialogResponse.d.ts.map +1 -0
  101. package/dist/cjs/dialogs/DialogResult.d.ts +8 -0
  102. package/dist/cjs/dialogs/DialogResult.d.ts.map +1 -0
  103. package/dist/cjs/dialogs/DialogResult.js +11 -0
  104. package/dist/cjs/dialogs/DialogResult.js.map +1 -0
  105. package/dist/cjs/dialogs/ShowDialog.d.ts +3 -0
  106. package/dist/cjs/dialogs/ShowDialog.d.ts.map +1 -0
  107. package/dist/cjs/dialogs/index.d.ts +14 -0
  108. package/dist/cjs/dialogs/index.d.ts.map +1 -0
  109. package/dist/cjs/dialogs/index.js +33 -0
  110. package/dist/cjs/dialogs/index.js.map +1 -0
  111. package/dist/cjs/dialogs/useBusyIndicator.d.ts +5 -0
  112. package/dist/cjs/dialogs/useBusyIndicator.d.ts.map +1 -0
  113. package/dist/cjs/dialogs/useBusyIndicator.js +21 -0
  114. package/dist/cjs/dialogs/useBusyIndicator.js.map +1 -0
  115. package/dist/cjs/dialogs/useConfirmationDialog.d.ts +5 -0
  116. package/dist/cjs/dialogs/useConfirmationDialog.d.ts.map +1 -0
  117. package/dist/cjs/dialogs/useConfirmationDialog.js +20 -0
  118. package/dist/cjs/dialogs/useConfirmationDialog.js.map +1 -0
  119. package/dist/cjs/dialogs/useDialog.d.ts +5 -0
  120. package/dist/cjs/dialogs/useDialog.d.ts.map +1 -0
  121. package/dist/cjs/dialogs/useDialog.js +34 -0
  122. package/dist/cjs/dialogs/useDialog.js.map +1 -0
  123. package/dist/cjs/identity/IdentityProvider.d.ts +10 -0
  124. package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -0
  125. package/dist/cjs/identity/IdentityProvider.js +48 -0
  126. package/dist/cjs/identity/IdentityProvider.js.map +1 -0
  127. package/dist/cjs/identity/index.d.ts +3 -0
  128. package/dist/cjs/identity/index.d.ts.map +1 -0
  129. package/dist/cjs/identity/index.js +11 -0
  130. package/dist/cjs/identity/index.js.map +1 -0
  131. package/dist/cjs/identity/useIdentity.d.ts +3 -0
  132. package/dist/cjs/identity/useIdentity.d.ts.map +1 -0
  133. package/dist/cjs/identity/useIdentity.js +15 -0
  134. package/dist/cjs/identity/useIdentity.js.map +1 -0
  135. package/dist/cjs/index.d.ts +9 -0
  136. package/dist/cjs/index.d.ts.map +1 -0
  137. package/dist/cjs/index.js +20 -0
  138. package/dist/cjs/index.js.map +1 -0
  139. package/dist/cjs/queries/SetPage.d.ts +2 -0
  140. package/dist/cjs/queries/SetPage.d.ts.map +1 -0
  141. package/dist/cjs/queries/SetPageSize.d.ts +2 -0
  142. package/dist/cjs/queries/SetPageSize.d.ts.map +1 -0
  143. package/dist/cjs/queries/SetSorting.d.ts +3 -0
  144. package/dist/cjs/queries/SetSorting.d.ts.map +1 -0
  145. package/dist/cjs/queries/index.d.ts +6 -0
  146. package/dist/cjs/queries/index.d.ts.map +1 -0
  147. package/dist/cjs/queries/index.js +12 -0
  148. package/dist/cjs/queries/index.js.map +1 -0
  149. package/dist/cjs/queries/useObservableQuery.d.ts +16 -0
  150. package/dist/cjs/queries/useObservableQuery.d.ts.map +1 -0
  151. package/dist/cjs/queries/useObservableQuery.js +54 -0
  152. package/dist/cjs/queries/useObservableQuery.js.map +1 -0
  153. package/dist/cjs/queries/useQuery.d.ts +19 -0
  154. package/dist/cjs/queries/useQuery.d.ts.map +1 -0
  155. package/dist/cjs/queries/useQuery.js +76 -0
  156. package/dist/cjs/queries/useQuery.js.map +1 -0
  157. package/dist/esm/Arc.d.ts +12 -0
  158. package/dist/esm/Arc.d.ts.map +1 -0
  159. package/dist/esm/Arc.js +23 -0
  160. package/dist/esm/Arc.js.map +1 -0
  161. package/dist/esm/ArcContext.d.ts +12 -0
  162. package/dist/esm/ArcContext.d.ts.map +1 -0
  163. package/dist/esm/ArcContext.js +14 -0
  164. package/dist/esm/ArcContext.js.map +1 -0
  165. package/dist/esm/Bindings.d.ts +5 -0
  166. package/dist/esm/Bindings.d.ts.map +1 -0
  167. package/dist/esm/Bindings.js +13 -0
  168. package/dist/esm/Bindings.js.map +1 -0
  169. package/dist/esm/WellKnownBindings.d.ts +4 -0
  170. package/dist/esm/WellKnownBindings.d.ts.map +1 -0
  171. package/dist/esm/WellKnownBindings.js +6 -0
  172. package/dist/esm/WellKnownBindings.js.map +1 -0
  173. package/dist/esm/commands/CommandScope.d.ts +13 -0
  174. package/dist/esm/commands/CommandScope.d.ts.map +1 -0
  175. package/dist/esm/commands/CommandScope.js +36 -0
  176. package/dist/esm/commands/CommandScope.js.map +1 -0
  177. package/dist/esm/commands/CommandScopeImplementation.d.ts +16 -0
  178. package/dist/esm/commands/CommandScopeImplementation.d.ts.map +1 -0
  179. package/dist/esm/commands/CommandScopeImplementation.js +50 -0
  180. package/dist/esm/commands/CommandScopeImplementation.js.map +1 -0
  181. package/dist/esm/commands/ICommandScope.d.ts +8 -0
  182. package/dist/esm/commands/ICommandScope.d.ts.map +1 -0
  183. package/dist/esm/commands/ICommandScope.js +2 -0
  184. package/dist/esm/commands/ICommandScope.js.map +1 -0
  185. package/dist/esm/commands/index.d.ts +6 -0
  186. package/dist/esm/commands/index.d.ts.map +1 -0
  187. package/dist/esm/commands/index.js +5 -0
  188. package/dist/esm/commands/index.js.map +1 -0
  189. package/dist/esm/commands/useCommand.d.ts +6 -0
  190. package/dist/esm/commands/useCommand.d.ts.map +1 -0
  191. package/dist/esm/commands/useCommand.js +45 -0
  192. package/dist/esm/commands/useCommand.js.map +1 -0
  193. package/dist/esm/commands/useCommandScope.d.ts +2 -0
  194. package/dist/esm/commands/useCommandScope.d.ts.map +1 -0
  195. package/dist/esm/commands/useCommandScope.js +9 -0
  196. package/dist/esm/commands/useCommandScope.js.map +1 -0
  197. package/dist/esm/dialogs/BusyIndicatorDialogRequest.d.ts +6 -0
  198. package/dist/esm/dialogs/BusyIndicatorDialogRequest.d.ts.map +1 -0
  199. package/dist/esm/dialogs/BusyIndicatorDialogRequest.js +11 -0
  200. package/dist/esm/dialogs/BusyIndicatorDialogRequest.js.map +1 -0
  201. package/dist/esm/dialogs/CloseDialog.d.ts +3 -0
  202. package/dist/esm/dialogs/CloseDialog.d.ts.map +1 -0
  203. package/dist/esm/dialogs/CloseDialog.js +2 -0
  204. package/dist/esm/dialogs/CloseDialog.js.map +1 -0
  205. package/dist/esm/dialogs/ConfirmationDialogRequest.d.ts +8 -0
  206. package/dist/esm/dialogs/ConfirmationDialogRequest.d.ts.map +1 -0
  207. package/dist/esm/dialogs/ConfirmationDialogRequest.js +13 -0
  208. package/dist/esm/dialogs/ConfirmationDialogRequest.js.map +1 -0
  209. package/dist/esm/dialogs/DialogButtons.d.ts +7 -0
  210. package/dist/esm/dialogs/DialogButtons.d.ts.map +1 -0
  211. package/dist/esm/dialogs/DialogButtons.js +10 -0
  212. package/dist/esm/dialogs/DialogButtons.js.map +1 -0
  213. package/dist/esm/dialogs/DialogComponents.d.ts +20 -0
  214. package/dist/esm/dialogs/DialogComponents.d.ts.map +1 -0
  215. package/dist/esm/dialogs/DialogComponents.js +31 -0
  216. package/dist/esm/dialogs/DialogComponents.js.map +1 -0
  217. package/dist/esm/dialogs/DialogContext.d.ts +10 -0
  218. package/dist/esm/dialogs/DialogContext.d.ts.map +1 -0
  219. package/dist/esm/dialogs/DialogContext.js +18 -0
  220. package/dist/esm/dialogs/DialogContext.js.map +1 -0
  221. package/dist/esm/dialogs/DialogProps.d.ts +5 -0
  222. package/dist/esm/dialogs/DialogProps.d.ts.map +1 -0
  223. package/dist/esm/dialogs/DialogProps.js +2 -0
  224. package/dist/esm/dialogs/DialogProps.js.map +1 -0
  225. package/dist/esm/dialogs/DialogResponse.d.ts +3 -0
  226. package/dist/esm/dialogs/DialogResponse.d.ts.map +1 -0
  227. package/dist/esm/dialogs/DialogResponse.js +2 -0
  228. package/dist/esm/dialogs/DialogResponse.js.map +1 -0
  229. package/dist/esm/dialogs/DialogResult.d.ts +8 -0
  230. package/dist/esm/dialogs/DialogResult.d.ts.map +1 -0
  231. package/dist/esm/dialogs/DialogResult.js +11 -0
  232. package/dist/esm/dialogs/DialogResult.js.map +1 -0
  233. package/dist/esm/dialogs/ShowDialog.d.ts +3 -0
  234. package/dist/esm/dialogs/ShowDialog.d.ts.map +1 -0
  235. package/dist/esm/dialogs/ShowDialog.js +2 -0
  236. package/dist/esm/dialogs/ShowDialog.js.map +1 -0
  237. package/dist/esm/dialogs/index.d.ts +14 -0
  238. package/dist/esm/dialogs/index.d.ts.map +1 -0
  239. package/dist/esm/dialogs/index.js +10 -0
  240. package/dist/esm/dialogs/index.js.map +1 -0
  241. package/dist/esm/dialogs/useBusyIndicator.d.ts +5 -0
  242. package/dist/esm/dialogs/useBusyIndicator.d.ts.map +1 -0
  243. package/dist/esm/dialogs/useBusyIndicator.js +19 -0
  244. package/dist/esm/dialogs/useBusyIndicator.js.map +1 -0
  245. package/dist/esm/dialogs/useConfirmationDialog.d.ts +5 -0
  246. package/dist/esm/dialogs/useConfirmationDialog.d.ts.map +1 -0
  247. package/dist/esm/dialogs/useConfirmationDialog.js +18 -0
  248. package/dist/esm/dialogs/useConfirmationDialog.js.map +1 -0
  249. package/dist/esm/dialogs/useDialog.d.ts +5 -0
  250. package/dist/esm/dialogs/useDialog.d.ts.map +1 -0
  251. package/dist/esm/dialogs/useDialog.js +32 -0
  252. package/dist/esm/dialogs/useDialog.js.map +1 -0
  253. package/dist/esm/identity/IdentityProvider.d.ts +10 -0
  254. package/dist/esm/identity/IdentityProvider.d.ts.map +1 -0
  255. package/dist/esm/identity/IdentityProvider.js +45 -0
  256. package/dist/esm/identity/IdentityProvider.js.map +1 -0
  257. package/dist/esm/identity/index.d.ts +3 -0
  258. package/dist/esm/identity/index.d.ts.map +1 -0
  259. package/dist/esm/identity/index.js +3 -0
  260. package/dist/esm/identity/index.js.map +1 -0
  261. package/dist/esm/identity/useIdentity.d.ts +3 -0
  262. package/dist/esm/identity/useIdentity.d.ts.map +1 -0
  263. package/dist/esm/identity/useIdentity.js +13 -0
  264. package/dist/esm/identity/useIdentity.js.map +1 -0
  265. package/dist/esm/index.d.ts +9 -0
  266. package/dist/esm/index.d.ts.map +1 -0
  267. package/dist/esm/index.js +12 -0
  268. package/dist/esm/index.js.map +1 -0
  269. package/dist/esm/queries/SetPage.d.ts +2 -0
  270. package/dist/esm/queries/SetPage.d.ts.map +1 -0
  271. package/dist/esm/queries/SetPage.js +2 -0
  272. package/dist/esm/queries/SetPage.js.map +1 -0
  273. package/dist/esm/queries/SetPageSize.d.ts +2 -0
  274. package/dist/esm/queries/SetPageSize.d.ts.map +1 -0
  275. package/dist/esm/queries/SetPageSize.js +2 -0
  276. package/dist/esm/queries/SetPageSize.js.map +1 -0
  277. package/dist/esm/queries/SetSorting.d.ts +3 -0
  278. package/dist/esm/queries/SetSorting.d.ts.map +1 -0
  279. package/dist/esm/queries/SetSorting.js +2 -0
  280. package/dist/esm/queries/SetSorting.js.map +1 -0
  281. package/dist/esm/queries/index.d.ts +6 -0
  282. package/dist/esm/queries/index.d.ts.map +1 -0
  283. package/dist/esm/queries/index.js +3 -0
  284. package/dist/esm/queries/index.js.map +1 -0
  285. package/dist/esm/queries/useObservableQuery.d.ts +16 -0
  286. package/dist/esm/queries/useObservableQuery.d.ts.map +1 -0
  287. package/dist/esm/queries/useObservableQuery.js +51 -0
  288. package/dist/esm/queries/useObservableQuery.js.map +1 -0
  289. package/dist/esm/queries/useQuery.d.ts +19 -0
  290. package/dist/esm/queries/useQuery.d.ts.map +1 -0
  291. package/dist/esm/queries/useQuery.js +73 -0
  292. package/dist/esm/queries/useQuery.js.map +1 -0
  293. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  294. package/global.d.ts +11 -0
  295. package/identity/IdentityProvider.tsx +61 -0
  296. package/identity/for_IdentityProvider/when_refreshing_identity.ts +59 -0
  297. package/identity/index.ts +5 -0
  298. package/identity/useIdentity.ts +19 -0
  299. package/index.ts +18 -0
  300. package/package.json +69 -0
  301. package/queries/SetPage.ts +7 -0
  302. package/queries/SetPageSize.ts +7 -0
  303. package/queries/SetSorting.ts +9 -0
  304. package/queries/for_useQuery/FakeQuery.ts +25 -0
  305. package/queries/for_useQuery/when_creating_instance.ts +63 -0
  306. package/queries/for_useQuery/when_creating_instance_with_sorting.ts +55 -0
  307. package/queries/for_useQuery/when_creating_instance_without_optional_context_values.ts +59 -0
  308. package/queries/for_useQueryWithPaging/when_creating_instance_with_paging.ts +67 -0
  309. package/queries/index.ts +8 -0
  310. package/queries/useObservableQuery.ts +83 -0
  311. package/queries/useQuery.ts +113 -0
package/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import * as commands from './commands';
5
+ import * as dialogs from './dialogs';
6
+ import * as identity from './identity';
7
+ import * as queries from './queries';
8
+
9
+ export * from './Arc';
10
+ export * from './ArcContext';
11
+ export * from './WellKnownBindings';
12
+
13
+ export {
14
+ commands,
15
+ dialogs,
16
+ identity,
17
+ queries
18
+ };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@cratis/arc.react",
3
+ "version": "18.0.0",
4
+ "description": "",
5
+ "author": "Cratis",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/cratis/arc.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "**/*.ts",
17
+ "**/*.tsx"
18
+ ],
19
+ "type": "module",
20
+ "main": "dist/cjs/index.js",
21
+ "module": "dist/esm/index.js",
22
+ "types": "dist/esm/index.d.ts",
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "types": "./dist/esm/index.d.ts",
27
+ "require": "./dist/cjs/index.js",
28
+ "import": "./dist/esm/index.js"
29
+ },
30
+ "./commands": {
31
+ "types": "./dist/esm/commands/index.d.ts",
32
+ "require": "./dist/cjs/commands/index.js",
33
+ "import": "./dist/esm/commands/index.js"
34
+ },
35
+ "./queries": {
36
+ "types": "./dist/esm/queries/index.d.ts",
37
+ "require": "./dist/cjs/queries/index.js",
38
+ "import": "./dist/esm/queries/index.js"
39
+ },
40
+ "./dialogs": {
41
+ "types": "./dist/esm/dialogs/index.js",
42
+ "require": "./dist/cjs/dialogs/index.js",
43
+ "import": "./dist/esm/dialogs/index.js"
44
+ },
45
+ "./identity": {
46
+ "types": "./dist/esm/identity/index.d.ts",
47
+ "require": "./dist/cjs/identity/index.js",
48
+ "import": "./dist/esm/identity/index.js"
49
+ }
50
+ },
51
+ "scripts": {
52
+ "prepare": "yarn g:build",
53
+ "clean": "yarn g:clean",
54
+ "build": "yarn g:build",
55
+ "lint": "yarn g:lint",
56
+ "lint:ci": "yarn g:lint:ci",
57
+ "test": "yarn g:test",
58
+ "ci": "yarn g:ci",
59
+ "up": "yarn g:up"
60
+ },
61
+ "dependencies": {
62
+ "@cratis/arc": "18.0.0",
63
+ "@cratis/fundamentals": "^7.2.3",
64
+ "tsyringe": "^4.10.0"
65
+ },
66
+ "peerDependencies": {
67
+ "react": "^18.0.0 || ^19.0.0"
68
+ }
69
+ }
@@ -0,0 +1,7 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /**
5
+ * Delegate type for setting the page in the context of the {@link useQueryWithPaging} or {@link useObservableQueryWithPaging} hooks.
6
+ */
7
+ export type SetPage = (page: number) => Promise<void>;
@@ -0,0 +1,7 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /**
5
+ * Delegate type for setting the page size in the context of the {@link useQueryWithPaging} or {@link useObservableQueryWithPaging} hooks.
6
+ */
7
+ export type SetPageSize = (pageSize: number) => Promise<void>;
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { Sorting } from '@cratis/arc/queries';
5
+
6
+ /**
7
+ * Delegate type for setting the sorting in the context of the {@link useQuery}, {@link useQueryWithPaging}, {@link useObservableQuery} or {@link useObservableQueryWithPaging} hooks.
8
+ */
9
+ export type SetSorting = (sorting: Sorting) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { QueryFor } from '@cratis/applications/queries';
5
+ import { ParameterDescriptor } from '@cratis/applications/reflection';
6
+
7
+ export interface FakeQueryResult {
8
+ id: string;
9
+ name: string;
10
+ }
11
+
12
+ export class FakeQuery extends QueryFor<FakeQueryResult[]> {
13
+ readonly route = '/api/fake-query';
14
+ readonly parameterDescriptors: ParameterDescriptor[] = [];
15
+
16
+ get requiredRequestParameters(): string[] {
17
+ return [];
18
+ }
19
+
20
+ defaultValue: FakeQueryResult[] = [];
21
+
22
+ constructor() {
23
+ super(Object, true);
24
+ }
25
+ }
@@ -0,0 +1,63 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import React from 'react';
5
+ import { render } from '@testing-library/react';
6
+ import sinon from 'sinon';
7
+ import { useQuery } from '../useQuery';
8
+ import { FakeQuery } from './FakeQuery';
9
+ import { ArcContext, ArcConfiguration } from '../../ArcContext';
10
+
11
+ /* eslint-disable @typescript-eslint/no-explicit-any */
12
+
13
+ describe('when creating instance', () => {
14
+ let fetchStub: sinon.SinonStub;
15
+ let queryInstance: FakeQuery | null = null;
16
+
17
+ const captureInstance = (instance: FakeQuery) => {
18
+ queryInstance = instance;
19
+ };
20
+
21
+ beforeEach(() => {
22
+ fetchStub = sinon.stub(global, 'fetch').resolves({
23
+ json: async () => ({ data: [], isSuccess: true, isAuthorized: true, isValid: true, hasExceptions: false, validationResults: [], exceptionMessages: [], exceptionStackTrace: '' })
24
+ } as Response);
25
+ });
26
+
27
+ afterEach(() => {
28
+ fetchStub.restore();
29
+ });
30
+
31
+ const config: ArcConfiguration = {
32
+ microservice: 'test-microservice',
33
+ apiBasePath: '/api',
34
+ origin: 'https://example.com',
35
+ httpHeadersCallback: () => ({ 'X-Custom-Header': 'custom-value' })
36
+ };
37
+
38
+ class SpyQuery extends FakeQuery {
39
+ constructor() {
40
+ super();
41
+ captureInstance(this);
42
+ }
43
+ }
44
+
45
+ render(
46
+ React.createElement(
47
+ ArcContext.Provider,
48
+ { value: config },
49
+ React.createElement(() => {
50
+ useQuery(SpyQuery);
51
+ return React.createElement('div', null, 'Test');
52
+ })
53
+ )
54
+ );
55
+
56
+ it('should set microservice from context', () => ((queryInstance as any)._microservice).should.equal('test-microservice'));
57
+ it('should set api base path from context', () => ((queryInstance as any)._apiBasePath).should.equal('/api'));
58
+ it('should set origin from context', () => ((queryInstance as any)._origin).should.equal('https://example.com'));
59
+ it('should set http headers callback from context', () => {
60
+ const headers = (queryInstance as any)._httpHeadersCallback();
61
+ headers.should.deep.equal({ 'X-Custom-Header': 'custom-value' });
62
+ });
63
+ });
@@ -0,0 +1,55 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import React from 'react';
5
+ import { render } from '@testing-library/react';
6
+ import sinon from 'sinon';
7
+ import { useQuery } from '../useQuery';
8
+ import { FakeQuery } from './FakeQuery';
9
+ import { ArcContext, ArcConfiguration } from '../../ArcContext';
10
+ import { Sorting } from '@cratis/applications/queries';
11
+
12
+ describe('when creating instance with sorting', () => {
13
+ let fetchStub: sinon.SinonStub;
14
+ let queryInstance: FakeQuery | null = null;
15
+
16
+ const captureInstance = (instance: FakeQuery) => {
17
+ queryInstance = instance;
18
+ };
19
+
20
+ beforeEach(() => {
21
+ fetchStub = sinon.stub(global, 'fetch').resolves({
22
+ json: async () => ({ data: [], isSuccess: true, isAuthorized: true, isValid: true, hasExceptions: false, validationResults: [], exceptionMessages: [], exceptionStackTrace: '' })
23
+ } as Response);
24
+ });
25
+
26
+ afterEach(() => {
27
+ fetchStub.restore();
28
+ });
29
+
30
+ const config: ArcConfiguration = {
31
+ microservice: 'test-microservice'
32
+ };
33
+
34
+ const sorting = new Sorting('name', 1);
35
+
36
+ class SpyQuery extends FakeQuery {
37
+ constructor() {
38
+ super();
39
+ captureInstance(this);
40
+ }
41
+ }
42
+
43
+ render(
44
+ React.createElement(
45
+ ArcContext.Provider,
46
+ { value: config },
47
+ React.createElement(() => {
48
+ useQuery(SpyQuery, undefined, sorting);
49
+ return React.createElement('div', null, 'Test');
50
+ })
51
+ )
52
+ );
53
+
54
+ it('should set sorting on the query', () => queryInstance!.sorting.should.equal(sorting));
55
+ });
@@ -0,0 +1,59 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import React from 'react';
5
+ import { render } from '@testing-library/react';
6
+ import sinon from 'sinon';
7
+ import { useQuery } from '../useQuery';
8
+ import { FakeQuery } from './FakeQuery';
9
+ import { ArcContext, ArcConfiguration } from '../../ArcContext';
10
+
11
+ /* eslint-disable @typescript-eslint/no-explicit-any */
12
+
13
+ describe('when creating instance without optional context values', () => {
14
+ let fetchStub: sinon.SinonStub;
15
+ let queryInstance: FakeQuery | null = null;
16
+
17
+ const captureInstance = (instance: FakeQuery) => {
18
+ queryInstance = instance;
19
+ };
20
+
21
+ beforeEach(() => {
22
+ fetchStub = sinon.stub(global, 'fetch').resolves({
23
+ json: async () => ({ data: [], isSuccess: true, isAuthorized: true, isValid: true, hasExceptions: false, validationResults: [], exceptionMessages: [], exceptionStackTrace: '' })
24
+ } as Response);
25
+ });
26
+
27
+ afterEach(() => {
28
+ fetchStub.restore();
29
+ });
30
+
31
+ const config: ArcConfiguration = {
32
+ microservice: 'test-microservice'
33
+ };
34
+
35
+ class SpyQuery extends FakeQuery {
36
+ constructor() {
37
+ super();
38
+ captureInstance(this);
39
+ }
40
+ }
41
+
42
+ render(
43
+ React.createElement(
44
+ ArcContext.Provider,
45
+ { value: config },
46
+ React.createElement(() => {
47
+ useQuery(SpyQuery);
48
+ return React.createElement('div', null, 'Test');
49
+ })
50
+ )
51
+ );
52
+
53
+ it('should set api base path to empty string', () => ((queryInstance as any)._apiBasePath).should.equal(''));
54
+ it('should set origin to empty string', () => ((queryInstance as any)._origin).should.equal(''));
55
+ it('should set http headers callback to return empty object', () => {
56
+ const headers = (queryInstance as any)._httpHeadersCallback();
57
+ headers.should.deep.equal({});
58
+ });
59
+ });
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import React from 'react';
5
+ import { render } from '@testing-library/react';
6
+ import sinon from 'sinon';
7
+ import { useQueryWithPaging } from '../useQuery';
8
+ import { FakeQuery } from '../for_useQuery/FakeQuery';
9
+ import { ArcContext, ArcConfiguration } from '../../ArcContext';
10
+ import { Paging } from '@cratis/applications/queries';
11
+
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+
14
+ describe('when creating instance with paging', () => {
15
+ let fetchStub: sinon.SinonStub;
16
+ let queryInstance: FakeQuery | null = null;
17
+
18
+ const captureInstance = (instance: FakeQuery) => {
19
+ queryInstance = instance;
20
+ };
21
+
22
+ beforeEach(() => {
23
+ fetchStub = sinon.stub(global, 'fetch').resolves({
24
+ json: async () => ({ data: [], isSuccess: true, isAuthorized: true, isValid: true, hasExceptions: false, validationResults: [], exceptionMessages: [], exceptionStackTrace: '' })
25
+ } as Response);
26
+ });
27
+
28
+ afterEach(() => {
29
+ fetchStub.restore();
30
+ });
31
+
32
+ const config: ArcConfiguration = {
33
+ microservice: 'test-microservice',
34
+ apiBasePath: '/api',
35
+ origin: 'https://example.com',
36
+ httpHeadersCallback: () => ({ 'X-Custom-Header': 'custom-value' })
37
+ };
38
+
39
+ const paging = new Paging(1, 10);
40
+
41
+ class SpyQuery extends FakeQuery {
42
+ constructor() {
43
+ super();
44
+ captureInstance(this);
45
+ }
46
+ }
47
+
48
+ render(
49
+ React.createElement(
50
+ ArcContext.Provider,
51
+ { value: config },
52
+ React.createElement(() => {
53
+ useQueryWithPaging(SpyQuery, paging);
54
+ return React.createElement('div', null, 'Test');
55
+ })
56
+ )
57
+ );
58
+
59
+ it('should set paging on the query', () => queryInstance!.paging.should.equal(paging));
60
+ it('should set microservice from context', () => ((queryInstance as any)._microservice).should.equal('test-microservice'));
61
+ it('should set api base path from context', () => ((queryInstance as any)._apiBasePath).should.equal('/api'));
62
+ it('should set origin from context', () => ((queryInstance as any)._origin).should.equal('https://example.com'));
63
+ it('should set http headers callback from context', () => {
64
+ const headers = (queryInstance as any)._httpHeadersCallback();
65
+ headers.should.deep.equal({ 'X-Custom-Header': 'custom-value' });
66
+ });
67
+ });
@@ -0,0 +1,8 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ export * from './SetPage';
5
+ export * from './SetPageSize';
6
+ export * from './SetSorting';
7
+ export * from './useObservableQuery';
8
+ export * from './useQuery';
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { QueryResultWithState, IObservableQueryFor, Sorting, Paging } from '@cratis/arc/queries';
5
+ import { Constructor } from '@cratis/fundamentals';
6
+ import { useState, useEffect, useContext, useRef, useMemo } from 'react';
7
+ import { SetSorting } from './SetSorting';
8
+ import { SetPage } from './SetPage';
9
+ import { SetPageSize } from './SetPageSize';
10
+ import { ArcContext } from '../ArcContext';
11
+
12
+ function useObservableQueryInternal<TDataType, TQuery extends IObservableQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, sorting?: Sorting, paging?: Paging, args?: TArguments):
13
+ [QueryResultWithState<TDataType>, SetSorting, SetPage, SetPageSize] {
14
+ const [currentPaging, setCurrentPaging] = useState<Paging>(paging ?? Paging.noPaging);
15
+ const [currentSorting, setCurrentSorting] = useState<Sorting>(sorting ?? Sorting.none);
16
+ const arc = useContext(ArcContext);
17
+ const queryInstance = useRef<TQuery | null>(null);
18
+
19
+ queryInstance.current = useMemo(() => {
20
+ const instance = new query() as TQuery;
21
+ instance.paging = currentPaging;
22
+ instance.sorting = currentSorting;
23
+ instance.setMicroservice(arc.microservice);
24
+ instance.setApiBasePath(arc.apiBasePath ?? '');
25
+ instance.setOrigin(arc.origin ?? '');
26
+ return instance;
27
+ }, [currentPaging, currentSorting]);
28
+
29
+ const [result, setResult] = useState<QueryResultWithState<TDataType>>(QueryResultWithState.empty(queryInstance.current.defaultValue));
30
+ const argumentsDependency = queryInstance.current.requiredRequestParameters.map(_ => args?.[_]);
31
+
32
+ useEffect(() => {
33
+ const subscription = queryInstance.current!.subscribe(response => {
34
+ setResult(QueryResultWithState.fromQueryResult(response, false));
35
+ }, args as object);
36
+
37
+ return () => {
38
+ subscription.unsubscribe();
39
+ };
40
+ }, [...argumentsDependency, ...[currentPaging, currentSorting]]);
41
+
42
+ return [
43
+ result,
44
+ async (sorting: Sorting) => {
45
+ setCurrentSorting(sorting);
46
+ },
47
+ async (page: number) => {
48
+ setCurrentPaging(new Paging(page, currentPaging.pageSize));
49
+ },
50
+ async (pageSize: number) => {
51
+ setCurrentPaging(new Paging(currentPaging.page, pageSize));
52
+ }];
53
+ }
54
+
55
+ /**
56
+ * React hook for working with {@link IObservableQueryFor} within the state management of React.
57
+ * @template TDataType Type of model the query is for.
58
+ * @template TQuery Type of observable query to use.
59
+ * @template TArguments Optional: Arguments for the query, if any
60
+ * @param query Query type constructor.
61
+ * @param args Optional: Arguments for the query, if any
62
+ * @returns Tuple of {@link QueryResultWithState} and a {@link PerformQuery} delegate.
63
+ */
64
+ export function useObservableQuery<TDataType, TQuery extends IObservableQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, args?: TArguments, sorting?: Sorting):
65
+ [QueryResultWithState<TDataType>, SetSorting] {
66
+ const [result, setSorting] = useObservableQueryInternal<TDataType, TQuery, TArguments>(query, sorting, Paging.noPaging, args);
67
+ return [result, setSorting];
68
+ }
69
+
70
+ /**
71
+ * React hook for working with {@link IObservableQueryFor} within the state management of React for queries with paging.
72
+ * @template TDataType Type of model the query is for.
73
+ * @template TQuery Type of observable query to use.
74
+ * @template TArguments Optional: Arguments for the query, if any
75
+ * @param query Query type constructor.
76
+ * @param args Optional: Arguments for the query, if any
77
+ * @param paging Paging information.
78
+ * @returns Tuple of {@link QueryResultWithState} and a {@link PerformQuery} delegate.
79
+ */
80
+ export function useObservableQueryWithPaging<TDataType, TQuery extends IObservableQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, paging: Paging, args?: TArguments, sorting?: Sorting):
81
+ [QueryResultWithState<TDataType>, SetSorting, SetPage, SetPageSize] {
82
+ return useObservableQueryInternal<TDataType, TQuery, TArguments>(query, sorting, paging, args);
83
+ }
@@ -0,0 +1,113 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { IQueryFor, QueryResultWithState, QueryResult, Paging, Sorting } from '@cratis/arc/queries';
5
+ import { Constructor } from '@cratis/fundamentals';
6
+ import { useState, useEffect, useContext, useRef, useMemo } from 'react';
7
+ import { SetSorting } from './SetSorting';
8
+ import { SetPage } from './SetPage';
9
+ import { SetPageSize } from './SetPageSize';
10
+ import { ArcContext } from '../ArcContext';
11
+
12
+ /**
13
+ * Delegate type for performing a {@link IQueryFor} in the context of the {@link useQuery} hook.
14
+ */
15
+ export type PerformQuery<TArguments = object> = (args?: TArguments) => Promise<void>;
16
+
17
+ type QueryPerformer<TQuery extends IQueryFor<TDataType>, TDataType, TArguments = object> = (performer: TQuery, args?: TArguments) => Promise<QueryResult<TDataType>>;
18
+
19
+ function useQueryInternal<TDataType, TQuery extends IQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, performer: QueryPerformer<TQuery, TDataType, TArguments>, sorting?: Sorting, paging?: Paging, args?: TArguments):
20
+ [QueryResultWithState<TDataType>, PerformQuery<TArguments>, SetSorting, SetPage, SetPageSize] {
21
+ paging ??= Paging.noPaging;
22
+ sorting ??= Sorting.none;
23
+ const arc = useContext(ArcContext);
24
+ const queryInstance = useRef<TQuery | null>(null);
25
+ const [renderCounter, setRenderCounter] = useState(0);
26
+
27
+ queryInstance.current = useMemo(() => {
28
+ const instance = new query() as TQuery;
29
+ instance.paging = paging;
30
+ instance.sorting = sorting;
31
+ instance.setMicroservice(arc.microservice);
32
+ instance.setApiBasePath(arc.apiBasePath ?? '');
33
+ instance.setOrigin(arc.origin ?? '');
34
+ instance.setHttpHeadersCallback(arc.httpHeadersCallback ?? (() => ({})));
35
+ return instance;
36
+ }, []);
37
+
38
+ const [result, setResult] = useState<QueryResultWithState<TDataType>>(QueryResultWithState.initial(queryInstance.current!.defaultValue));
39
+
40
+ const queryExecutor = (async (args?: TArguments) => {
41
+ if (queryInstance) {
42
+ try {
43
+ const queryResult = await performer(queryInstance.current!, args);
44
+ setResult(QueryResultWithState.fromQueryResult(queryResult, false));
45
+ } catch {
46
+ // Ignore
47
+ }
48
+ }
49
+ });
50
+
51
+ useEffect(() => {
52
+ queryExecutor(args);
53
+ }, []);
54
+
55
+ const invalidate = () => {
56
+ setRenderCounter(renderCounter + 1);
57
+ };
58
+
59
+ return [
60
+ result!,
61
+ async (args?: TArguments) => {
62
+ setResult(QueryResultWithState.fromQueryResult(result!, true));
63
+ await queryExecutor(args);
64
+ },
65
+ async (sorting: Sorting) => {
66
+ setResult(QueryResultWithState.fromQueryResult(result!, true));
67
+ queryInstance.current!.sorting = sorting;
68
+ invalidate();
69
+ await queryExecutor(args);
70
+ },
71
+ async (page: number) => {
72
+ setResult(QueryResultWithState.fromQueryResult(result!, true));
73
+ queryInstance.current!.paging = new Paging(page, queryInstance.current!.paging?.pageSize ?? 0);
74
+ invalidate();
75
+ await queryExecutor(args);
76
+ },
77
+ async (pageSize: number) => {
78
+ setResult(QueryResultWithState.fromQueryResult(result!, true));
79
+ queryInstance.current!.paging = new Paging(queryInstance.current!.paging?.page ?? 0, pageSize);
80
+ invalidate();
81
+ await queryExecutor(args);
82
+ }];
83
+ }
84
+
85
+ /**
86
+ * React hook for working with {@link IQueryFor} within the state management of React.
87
+ * @template TDataType Type of model the query is for.
88
+ * @template TQuery Type of query to use.
89
+ * @template TArguments Optional: Arguments for the query, if any
90
+ * @param query Query type constructor.
91
+ * @param args Optional: Arguments for the query, if any
92
+ * @returns Tuple of {@link QueryResult} and a {@link PerformQuery} delegate.
93
+ */
94
+ export function useQuery<TDataType, TQuery extends IQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, args?: TArguments, sorting?: Sorting):
95
+ [QueryResultWithState<TDataType>, PerformQuery<TArguments>, SetSorting] {
96
+ const [result, perform, setSorting] = useQueryInternal(query, async (queryInstance: TQuery, actualArgs?: TArguments) => await queryInstance.perform(actualArgs!), sorting, undefined, args);
97
+ return [result, perform, setSorting];
98
+ }
99
+
100
+ /**
101
+ * React hook for working with {@link IQueryFor} within the state management of React for queries with paging.
102
+ * @template TDataType Type of model the query is for.
103
+ * @template TQuery Type of query to use.
104
+ * @template TArguments Optional: Arguments for the query, if any
105
+ * @param query Query type constructor.
106
+ * @param paging Paging information.
107
+ * @param args Optional: Arguments for the query, if any
108
+ * @returns Tuple of {@link QueryResult} and a {@link PerformQuery} delegate.
109
+ */
110
+ export function useQueryWithPaging<TDataType, TQuery extends IQueryFor<TDataType>, TArguments = object>(query: Constructor<TQuery>, paging: Paging, args?: TArguments, sorting?: Sorting):
111
+ [QueryResultWithState<TDataType>, PerformQuery<TArguments>, SetSorting, SetPage, SetPageSize] {
112
+ return useQueryInternal(query, async (queryInstance: TQuery, actualArgs?: TArguments) => await queryInstance.perform(actualArgs!), sorting, paging, args);
113
+ }