@astrale-os/shell-react 0.2.8 → 0.2.10-beta.2

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 (342) hide show
  1. package/dist/application/apps/app-host.d.ts +7 -15
  2. package/dist/application/apps/app-host.d.ts.map +1 -1
  3. package/dist/application/apps/app-host.js +3 -2
  4. package/dist/application/apps/apps.hook.d.ts +7 -4
  5. package/dist/application/apps/apps.hook.d.ts.map +1 -1
  6. package/dist/application/apps/apps.hook.js +10 -2
  7. package/dist/application/apps/domains.hook.d.ts +1 -1
  8. package/dist/application/apps/domains.hook.d.ts.map +1 -1
  9. package/dist/application/apps/domains.hook.js +1 -1
  10. package/dist/application/apps/open-app.hook.d.ts +2 -3
  11. package/dist/application/apps/open-app.hook.d.ts.map +1 -1
  12. package/dist/application/index.d.ts +2 -4
  13. package/dist/application/index.d.ts.map +1 -1
  14. package/dist/application/index.js +2 -3
  15. package/dist/application/spaces/space.hook.d.ts +2 -2
  16. package/dist/application/spaces/space.hook.d.ts.map +1 -1
  17. package/dist/application/spaces/space.hook.js +2 -2
  18. package/dist/application/spaces/spaces.hook.d.ts +2 -3
  19. package/dist/application/spaces/spaces.hook.d.ts.map +1 -1
  20. package/dist/application/spaces/spaces.hook.js +10 -3
  21. package/dist/auth/act-as.context.d.ts +15 -32
  22. package/dist/auth/act-as.context.d.ts.map +1 -1
  23. package/dist/auth/act-as.context.js +22 -66
  24. package/dist/auth/auth.hook.d.ts +1 -0
  25. package/dist/auth/auth.hook.d.ts.map +1 -1
  26. package/dist/auth/auth.hook.js +2 -22
  27. package/dist/auth/can.hook.d.ts +10 -38
  28. package/dist/auth/can.hook.d.ts.map +1 -1
  29. package/dist/auth/can.hook.js +35 -110
  30. package/dist/auth/index.d.ts +1 -0
  31. package/dist/auth/index.d.ts.map +1 -1
  32. package/dist/auth/self.hook.d.ts +2 -2
  33. package/dist/auth/self.hook.d.ts.map +1 -1
  34. package/dist/auth/self.hook.js +0 -7
  35. package/dist/auth/session-kernel.d.ts +2 -3
  36. package/dist/auth/session-kernel.d.ts.map +1 -1
  37. package/dist/auth/session-kernel.js +4 -13
  38. package/dist/components/boundaries.d.ts +47 -0
  39. package/dist/components/boundaries.d.ts.map +1 -0
  40. package/dist/components/boundaries.js +55 -0
  41. package/dist/components/can.d.ts +11 -0
  42. package/dist/components/can.d.ts.map +1 -0
  43. package/dist/components/can.js +5 -0
  44. package/dist/components/index.d.ts +7 -0
  45. package/dist/components/index.d.ts.map +1 -0
  46. package/dist/components/index.js +4 -0
  47. package/dist/components/mount-domain-frontend.d.ts +22 -0
  48. package/dist/components/mount-domain-frontend.d.ts.map +1 -0
  49. package/dist/components/mount-domain-frontend.js +85 -0
  50. package/dist/components/view-app.d.ts +16 -0
  51. package/dist/components/view-app.d.ts.map +1 -0
  52. package/dist/components/view-app.js +16 -0
  53. package/dist/graph/call/call.hook.d.ts +8 -18
  54. package/dist/graph/call/call.hook.d.ts.map +1 -1
  55. package/dist/graph/call/call.hook.js +7 -13
  56. package/dist/graph/call/stream.hook.d.ts +12 -20
  57. package/dist/graph/call/stream.hook.d.ts.map +1 -1
  58. package/dist/graph/call/stream.hook.js +55 -111
  59. package/dist/graph/graph.context.d.ts +4 -3
  60. package/dist/graph/graph.context.d.ts.map +1 -1
  61. package/dist/graph/graph.context.js +2 -8
  62. package/dist/graph/guards.error.d.ts +7 -8
  63. package/dist/graph/guards.error.d.ts.map +1 -1
  64. package/dist/graph/guards.error.js +11 -7
  65. package/dist/graph/index.d.ts +8 -16
  66. package/dist/graph/index.d.ts.map +1 -1
  67. package/dist/graph/index.js +3 -7
  68. package/dist/graph/memory/read/envelope.d.ts +22 -54
  69. package/dist/graph/memory/read/envelope.d.ts.map +1 -1
  70. package/dist/graph/memory/read/envelope.js +26 -20
  71. package/dist/graph/memory/read/idle.d.ts +1 -15
  72. package/dist/graph/memory/read/idle.d.ts.map +1 -1
  73. package/dist/graph/memory/read/idle.js +4 -13
  74. package/dist/graph/query-definition.hook.d.ts +11 -0
  75. package/dist/graph/query-definition.hook.d.ts.map +1 -0
  76. package/dist/graph/query-definition.hook.js +205 -0
  77. package/dist/graph/resource.d.ts +34 -0
  78. package/dist/graph/resource.d.ts.map +1 -0
  79. package/dist/graph/resource.js +244 -0
  80. package/dist/graph/store.d.ts +25 -0
  81. package/dist/graph/store.d.ts.map +1 -0
  82. package/dist/graph/store.js +69 -0
  83. package/dist/host/actions.hook.d.ts +34 -0
  84. package/dist/host/actions.hook.d.ts.map +1 -0
  85. package/dist/host/actions.hook.js +125 -0
  86. package/dist/host/components.d.ts +15 -0
  87. package/dist/host/components.d.ts.map +1 -0
  88. package/dist/host/components.js +14 -0
  89. package/dist/host/index.d.ts +5 -0
  90. package/dist/host/index.d.ts.map +1 -0
  91. package/dist/host/index.js +3 -0
  92. package/dist/index.d.ts +26 -37
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +20 -31
  95. package/dist/intents/envelope.d.ts +7 -19
  96. package/dist/intents/envelope.d.ts.map +1 -1
  97. package/dist/intents/envelope.js +2 -3
  98. package/dist/intents/send-intent.hook.d.ts +5 -7
  99. package/dist/intents/send-intent.hook.d.ts.map +1 -1
  100. package/dist/intents/send-intent.hook.js +17 -75
  101. package/dist/navigation/adapters/adapter.d.ts +5 -0
  102. package/dist/navigation/adapters/adapter.d.ts.map +1 -1
  103. package/dist/navigation/adapters/memory.adapter.d.ts.map +1 -1
  104. package/dist/navigation/adapters/memory.adapter.js +4 -0
  105. package/dist/navigation/adapters/url.adapter.d.ts.map +1 -1
  106. package/dist/navigation/adapters/url.adapter.js +57 -10
  107. package/dist/navigation/codec.d.ts +60 -0
  108. package/dist/navigation/codec.d.ts.map +1 -0
  109. package/dist/navigation/codec.js +121 -0
  110. package/dist/navigation/history.d.ts +11 -9
  111. package/dist/navigation/history.d.ts.map +1 -1
  112. package/dist/navigation/history.js +6 -8
  113. package/dist/navigation/hooks/ancestors.hook.d.ts +5 -7
  114. package/dist/navigation/hooks/ancestors.hook.d.ts.map +1 -1
  115. package/dist/navigation/hooks/ancestors.hook.js +7 -51
  116. package/dist/navigation/hooks/location.hook.d.ts.map +1 -1
  117. package/dist/navigation/hooks/location.hook.js +4 -6
  118. package/dist/navigation/hooks/scope.hook.d.ts.map +1 -1
  119. package/dist/navigation/hooks/scope.hook.js +4 -6
  120. package/dist/navigation/index.d.ts +4 -2
  121. package/dist/navigation/index.d.ts.map +1 -1
  122. package/dist/navigation/index.js +2 -1
  123. package/dist/navigation/link.d.ts +12 -0
  124. package/dist/navigation/link.d.ts.map +1 -1
  125. package/dist/navigation/link.js +13 -2
  126. package/dist/navigation/location.d.ts +13 -40
  127. package/dist/navigation/location.d.ts.map +1 -1
  128. package/dist/navigation/location.js +14 -76
  129. package/dist/navigation/scope.context.d.ts +17 -26
  130. package/dist/navigation/scope.context.d.ts.map +1 -1
  131. package/dist/navigation/scope.context.js +140 -108
  132. package/dist/navigation/snapshot.d.ts +14 -19
  133. package/dist/navigation/snapshot.d.ts.map +1 -1
  134. package/dist/navigation/snapshot.js +48 -44
  135. package/dist/schema/action.hook.d.ts +44 -0
  136. package/dist/schema/action.hook.d.ts.map +1 -0
  137. package/dist/schema/action.hook.js +72 -0
  138. package/dist/schema/domain.hook.d.ts +12 -7
  139. package/dist/schema/domain.hook.d.ts.map +1 -1
  140. package/dist/schema/domain.hook.js +101 -4
  141. package/dist/schema/index.d.ts +9 -8
  142. package/dist/schema/index.d.ts.map +1 -1
  143. package/dist/schema/index.js +5 -7
  144. package/dist/schema/kernel.hook.d.ts +4 -9
  145. package/dist/schema/kernel.hook.d.ts.map +1 -1
  146. package/dist/schema/kernel.hook.js +4 -6
  147. package/dist/schema/mutation.hook.d.ts +9 -0
  148. package/dist/schema/mutation.hook.d.ts.map +1 -0
  149. package/dist/schema/mutation.hook.js +41 -0
  150. package/dist/schema/object.hook.d.ts +16 -0
  151. package/dist/schema/object.hook.d.ts.map +1 -0
  152. package/dist/schema/object.hook.js +46 -0
  153. package/dist/schema/relation.hook.d.ts +46 -0
  154. package/dist/schema/relation.hook.d.ts.map +1 -0
  155. package/dist/schema/relation.hook.js +136 -0
  156. package/dist/selection/live.d.ts +9 -17
  157. package/dist/selection/live.d.ts.map +1 -1
  158. package/dist/selection/live.js +65 -112
  159. package/dist/selection/scope.context.js +5 -4
  160. package/dist/session/boot/boot.d.ts +1 -13
  161. package/dist/session/boot/boot.d.ts.map +1 -1
  162. package/dist/session/boot/boot.js +9 -27
  163. package/dist/session/index.d.ts +1 -0
  164. package/dist/session/index.d.ts.map +1 -1
  165. package/dist/session/kernel-instance.hook.d.ts +1 -4
  166. package/dist/session/kernel-instance.hook.d.ts.map +1 -1
  167. package/dist/session/kernel-instance.hook.js +1 -5
  168. package/dist/session/provider.d.ts +9 -23
  169. package/dist/session/provider.d.ts.map +1 -1
  170. package/dist/session/provider.js +29 -75
  171. package/dist/session/session.context.d.ts +5 -0
  172. package/dist/session/session.context.d.ts.map +1 -1
  173. package/dist/window/adopt.d.ts +0 -1
  174. package/dist/window/adopt.d.ts.map +1 -1
  175. package/dist/window/hooks/target-node.hook.d.ts +10 -6
  176. package/dist/window/hooks/target-node.hook.d.ts.map +1 -1
  177. package/dist/window/hooks/target-node.hook.js +14 -72
  178. package/dist/window/hooks/views-for.hook.d.ts +4 -3
  179. package/dist/window/hooks/views-for.hook.d.ts.map +1 -1
  180. package/dist/window/hooks/views-for.hook.js +6 -22
  181. package/dist/window/hooks/windows.hook.d.ts.map +1 -1
  182. package/dist/window/hooks/windows.hook.js +3 -4
  183. package/dist/window/host.d.ts +11 -11
  184. package/dist/window/host.d.ts.map +1 -1
  185. package/dist/window/host.js +38 -54
  186. package/dist/window/hub.d.ts +2 -0
  187. package/dist/window/hub.d.ts.map +1 -1
  188. package/dist/window/hub.js +33 -0
  189. package/dist/window/index.d.ts +3 -3
  190. package/dist/window/index.d.ts.map +1 -1
  191. package/dist/window/index.js +2 -2
  192. package/dist/window/lifecycle/mount.d.ts +5 -44
  193. package/dist/window/lifecycle/mount.d.ts.map +1 -1
  194. package/dist/window/lifecycle/mount.js +14 -120
  195. package/dist/window/lifecycle/states.d.ts +0 -5
  196. package/dist/window/lifecycle/states.d.ts.map +1 -1
  197. package/dist/window/stage.d.ts.map +1 -1
  198. package/dist/window/stage.js +1 -0
  199. package/package.json +9 -8
  200. package/src/application/apps/app-host.tsx +17 -18
  201. package/src/application/apps/apps.hook.ts +13 -6
  202. package/src/application/apps/domains.hook.ts +1 -1
  203. package/src/application/apps/open-app.hook.ts +3 -4
  204. package/src/application/index.ts +4 -6
  205. package/src/application/spaces/space.hook.ts +5 -6
  206. package/src/application/spaces/spaces.hook.ts +14 -9
  207. package/src/auth/act-as.context.tsx +37 -91
  208. package/src/auth/auth.hook.ts +2 -30
  209. package/src/auth/can.hook.ts +44 -135
  210. package/src/auth/index.ts +1 -0
  211. package/src/auth/self.hook.ts +2 -9
  212. package/src/auth/session-kernel.ts +6 -16
  213. package/src/components/boundaries.tsx +113 -0
  214. package/src/components/can.tsx +16 -0
  215. package/src/components/index.ts +14 -0
  216. package/src/components/mount-domain-frontend.tsx +158 -0
  217. package/src/components/view-app.tsx +49 -0
  218. package/src/graph/call/call.hook.ts +22 -27
  219. package/src/graph/call/stream.hook.ts +66 -143
  220. package/src/graph/graph.context.ts +6 -11
  221. package/src/graph/guards.error.ts +17 -55
  222. package/src/graph/index.ts +23 -17
  223. package/src/graph/memory/read/envelope.ts +40 -65
  224. package/src/graph/memory/read/idle.ts +5 -18
  225. package/src/graph/query-definition.hook.ts +270 -0
  226. package/src/graph/resource.ts +358 -0
  227. package/src/graph/store.ts +97 -0
  228. package/src/host/actions.hook.ts +165 -0
  229. package/src/host/components.tsx +29 -0
  230. package/src/host/index.ts +17 -0
  231. package/src/index.ts +137 -123
  232. package/src/intents/envelope.ts +7 -23
  233. package/src/intents/send-intent.hook.ts +24 -79
  234. package/src/navigation/adapters/adapter.ts +3 -0
  235. package/src/navigation/adapters/memory.adapter.ts +4 -0
  236. package/src/navigation/adapters/url.adapter.ts +48 -8
  237. package/src/navigation/codec.ts +190 -0
  238. package/src/navigation/history.ts +20 -11
  239. package/src/navigation/hooks/ancestors.hook.ts +10 -60
  240. package/src/navigation/hooks/location.hook.ts +4 -6
  241. package/src/navigation/hooks/scope.hook.ts +4 -6
  242. package/src/navigation/index.ts +18 -2
  243. package/src/navigation/link.tsx +27 -2
  244. package/src/navigation/location.ts +26 -93
  245. package/src/navigation/scope.context.tsx +151 -136
  246. package/src/navigation/snapshot.ts +69 -50
  247. package/src/schema/action.hook.ts +146 -0
  248. package/src/schema/domain.hook.ts +127 -11
  249. package/src/schema/index.ts +9 -30
  250. package/src/schema/kernel.hook.ts +6 -13
  251. package/src/schema/mutation.hook.ts +63 -0
  252. package/src/schema/object.hook.ts +85 -0
  253. package/src/schema/relation.hook.ts +253 -0
  254. package/src/selection/live.ts +75 -125
  255. package/src/selection/scope.context.tsx +4 -4
  256. package/src/session/boot/boot.ts +8 -33
  257. package/src/session/index.ts +1 -0
  258. package/src/session/kernel-instance.hook.ts +2 -11
  259. package/src/session/provider.tsx +34 -103
  260. package/src/session/session.context.ts +6 -0
  261. package/src/window/adopt.ts +0 -1
  262. package/src/window/hooks/target-node.hook.ts +20 -85
  263. package/src/window/hooks/views-for.hook.ts +12 -25
  264. package/src/window/hooks/windows.hook.ts +3 -4
  265. package/src/window/host.tsx +51 -68
  266. package/src/window/hub.ts +33 -0
  267. package/src/window/index.ts +4 -4
  268. package/src/window/lifecycle/mount.ts +15 -160
  269. package/src/window/lifecycle/states.ts +1 -5
  270. package/src/window/stage.tsx +1 -0
  271. package/dist/application/roles.hook.d.ts +0 -7
  272. package/dist/application/roles.hook.d.ts.map +0 -1
  273. package/dist/application/roles.hook.js +0 -23
  274. package/dist/graph/memory/base.d.ts +0 -21
  275. package/dist/graph/memory/base.d.ts.map +0 -1
  276. package/dist/graph/memory/base.js +0 -33
  277. package/dist/graph/memory/read/read.d.ts +0 -9
  278. package/dist/graph/memory/read/read.d.ts.map +0 -1
  279. package/dist/graph/memory/read/read.js +0 -87
  280. package/dist/graph/memory/scope.d.ts +0 -7
  281. package/dist/graph/memory/scope.d.ts.map +0 -1
  282. package/dist/graph/memory/scope.js +0 -25
  283. package/dist/graph/mutate/move.hook.d.ts +0 -7
  284. package/dist/graph/mutate/move.hook.d.ts.map +0 -1
  285. package/dist/graph/mutate/move.hook.js +0 -49
  286. package/dist/graph/mutate/mutate.hook.d.ts +0 -17
  287. package/dist/graph/mutate/mutate.hook.d.ts.map +0 -1
  288. package/dist/graph/mutate/mutate.hook.js +0 -45
  289. package/dist/graph/query/children.hook.d.ts +0 -29
  290. package/dist/graph/query/children.hook.d.ts.map +0 -1
  291. package/dist/graph/query/children.hook.js +0 -64
  292. package/dist/graph/query/graph.hook.d.ts +0 -9
  293. package/dist/graph/query/graph.hook.d.ts.map +0 -1
  294. package/dist/graph/query/graph.hook.js +0 -5
  295. package/dist/graph/query/neighbors.hook.d.ts +0 -7
  296. package/dist/graph/query/neighbors.hook.d.ts.map +0 -1
  297. package/dist/graph/query/neighbors.hook.js +0 -104
  298. package/dist/graph/query/node.hook.d.ts +0 -14
  299. package/dist/graph/query/node.hook.d.ts.map +0 -1
  300. package/dist/graph/query/node.hook.js +0 -43
  301. package/dist/graph/query/query.hook.d.ts +0 -14
  302. package/dist/graph/query/query.hook.d.ts.map +0 -1
  303. package/dist/graph/query/query.hook.js +0 -23
  304. package/dist/schema/bind-read.d.ts +0 -37
  305. package/dist/schema/bind-read.d.ts.map +0 -1
  306. package/dist/schema/bind-read.js +0 -205
  307. package/dist/schema/binding.d.ts +0 -21
  308. package/dist/schema/binding.d.ts.map +0 -1
  309. package/dist/schema/binding.js +0 -99
  310. package/dist/schema/function.hook.d.ts +0 -9
  311. package/dist/schema/function.hook.d.ts.map +0 -1
  312. package/dist/schema/function.hook.js +0 -40
  313. package/dist/schema/method.hook.d.ts +0 -14
  314. package/dist/schema/method.hook.d.ts.map +0 -1
  315. package/dist/schema/method.hook.js +0 -49
  316. package/dist/schema/tag.d.ts +0 -11
  317. package/dist/schema/tag.d.ts.map +0 -1
  318. package/dist/schema/tag.js +0 -11
  319. package/dist/schema/types.d.ts +0 -73
  320. package/dist/schema/types.d.ts.map +0 -1
  321. package/dist/schema/types.js +0 -1
  322. package/dist/schema/write.d.ts +0 -16
  323. package/dist/schema/write.d.ts.map +0 -1
  324. package/dist/schema/write.js +0 -56
  325. package/src/application/roles.hook.ts +0 -41
  326. package/src/graph/memory/base.ts +0 -50
  327. package/src/graph/memory/read/read.ts +0 -103
  328. package/src/graph/memory/scope.ts +0 -29
  329. package/src/graph/mutate/move.hook.ts +0 -70
  330. package/src/graph/mutate/mutate.hook.ts +0 -69
  331. package/src/graph/query/children.hook.ts +0 -136
  332. package/src/graph/query/graph.hook.ts +0 -13
  333. package/src/graph/query/neighbors.hook.ts +0 -159
  334. package/src/graph/query/node.hook.ts +0 -83
  335. package/src/graph/query/query.hook.ts +0 -42
  336. package/src/schema/bind-read.ts +0 -319
  337. package/src/schema/binding.ts +0 -146
  338. package/src/schema/function.hook.ts +0 -68
  339. package/src/schema/method.hook.ts +0 -103
  340. package/src/schema/tag.ts +0 -19
  341. package/src/schema/types.ts +0 -150
  342. package/src/schema/write.ts +0 -96
@@ -0,0 +1,97 @@
1
+ import type { GraphApi } from '@astrale-os/kernel-client/graph'
2
+ import type { GraphStore as GraphStoreValue } from '@astrale-os/kernel-client/store'
3
+ import type { Shell } from '@astrale-os/shell'
4
+
5
+ import { GraphStore } from '@astrale-os/kernel-client/store'
6
+ import { useContext } from 'react'
7
+
8
+ import { GraphContext } from './graph.context.js'
9
+
10
+ interface StoreEntry {
11
+ readonly shell: Shell
12
+ readonly graph: GraphApi
13
+ readonly scope: string
14
+ readonly store: GraphStoreValue
15
+ readonly owned: boolean
16
+ retained: number
17
+ generation: number
18
+ }
19
+
20
+ const entries = new WeakMap<Shell, StoreEntry>()
21
+
22
+ /** Authority/schema identity. Session ids and Publication ETags are deliberately absent. */
23
+ export interface GraphStoreScope {
24
+ readonly authority: string
25
+ readonly schemaRevision: string
26
+ }
27
+
28
+ type StoreIdentity = Awaited<ReturnType<Shell['kernel']['auth']['whoami']>>
29
+
30
+ export async function resolveGraphStoreScope(
31
+ shell: Shell,
32
+ knownIdentity?: StoreIdentity | null,
33
+ ): Promise<GraphStoreScope> {
34
+ const [identity, snapshot] = await Promise.all([
35
+ knownIdentity === undefined
36
+ ? shell.kernel.auth.whoami().catch(() => null)
37
+ : Promise.resolve(knownIdentity),
38
+ shell.kernel.snapshot(),
39
+ ])
40
+ return Object.freeze({
41
+ authority:
42
+ identity === null
43
+ ? 'anonymous'
44
+ : `${identity.issuer}\u0000${identity.subject}\u0000${identity.id}`,
45
+ schemaRevision: snapshot.publication.schema.revision,
46
+ })
47
+ }
48
+
49
+ export function storeFor(shell: Shell, scope: GraphStoreScope): StoreEntry {
50
+ const current = entries.get(shell)
51
+ const scopeKey = `${scope.authority}\u0000${scope.schemaRevision}`
52
+ if (current !== undefined && current.graph === shell.kernel.graph && current.scope === scopeKey) {
53
+ return current
54
+ }
55
+ const supplied = shell.kernel.store
56
+ const created: StoreEntry = {
57
+ shell,
58
+ graph: shell.kernel.graph,
59
+ scope: scopeKey,
60
+ // A supplied Store is trusted only for the KernelClient's first declared scope. A later
61
+ // authority/revision/GraphApi replacement gets a new Store and cannot inherit old memory.
62
+ store:
63
+ current === undefined && supplied !== undefined
64
+ ? supplied
65
+ : new GraphStore({ graph: shell.kernel.graph }),
66
+ owned: current !== undefined || supplied === undefined,
67
+ retained: 0,
68
+ generation: 0,
69
+ }
70
+ entries.set(shell, created)
71
+ if (current !== undefined && current.retained === 0 && current.owned) current.store.close()
72
+ return created
73
+ }
74
+
75
+ export function retainStore(entry: StoreEntry): () => void {
76
+ entry.generation += 1
77
+ entry.retained += 1
78
+ let released = false
79
+ return () => {
80
+ if (released) return
81
+ released = true
82
+ entry.retained -= 1
83
+ const generation = ++entry.generation
84
+ queueMicrotask(() => {
85
+ if (entry.retained !== 0 || entry.generation !== generation || !entry.owned) return
86
+ if (entries.get(entry.shell) === entry) entries.delete(entry.shell)
87
+ entry.store.close()
88
+ })
89
+ }
90
+ }
91
+
92
+ /** The exact caller/schema-scoped GraphStore for the current View subtree. */
93
+ export function useGraphStore(): GraphStoreValue {
94
+ const store = useContext(GraphContext)
95
+ if (store === null) throw new Error('useGraphStore must be used within a <ShellProvider>')
96
+ return store
97
+ }
@@ -0,0 +1,165 @@
1
+ import type {
2
+ AccessRequest,
3
+ AccessResult,
4
+ ExternalOpenRequest,
5
+ ExternalOpenResult,
6
+ HostCapabilities,
7
+ ModalRequest,
8
+ ModalResult,
9
+ NotificationRequest,
10
+ NotificationResult,
11
+ OpenViewRequest,
12
+ OpenViewResult,
13
+ } from '@astrale-os/shell'
14
+
15
+ import { useMemo } from 'react'
16
+
17
+ import { useSendIntent } from '../intents/send-intent.hook.js'
18
+ import { useShell } from '../session/shell.hook.js'
19
+
20
+ export function useHostCapabilities(): HostCapabilities {
21
+ return useShell().hostCapabilities
22
+ }
23
+
24
+ export class HostCapabilityUnavailableError extends Error {
25
+ readonly code = 'SHELL_REACT_HOST_CAPABILITY_UNAVAILABLE' as const
26
+ constructor(readonly capability: string) {
27
+ super(`Host capability '${capability}' is unavailable.`)
28
+ this.name = 'HostCapabilityUnavailableError'
29
+ }
30
+ }
31
+
32
+ export interface HostDialogApi {
33
+ readonly supported: boolean
34
+ open(request: ModalRequest): Promise<ModalResult>
35
+ confirm(request: Omit<ModalRequest, 'nested'>): Promise<boolean>
36
+ }
37
+
38
+ export function useHostDialog(): HostDialogApi {
39
+ const capabilities = useHostCapabilities()
40
+ const send = useSendIntent()
41
+ return useMemo(
42
+ () => ({
43
+ supported: capabilities.actions.modal !== undefined,
44
+ open: (request: ModalRequest) => {
45
+ if (capabilities.actions.modal === undefined) return unsupported('actions.modal')
46
+ portable(request)
47
+ return send('actions.modal', request)
48
+ },
49
+ confirm: async (request: Omit<ModalRequest, 'nested'>) => {
50
+ if (capabilities.actions.modal === undefined) return unsupported('actions.modal')
51
+ portable(request)
52
+ return (await send('actions.modal', request)).outcome === 'confirmed'
53
+ },
54
+ }),
55
+ [capabilities, send],
56
+ )
57
+ }
58
+
59
+ export interface NotifyApi {
60
+ (request: NotificationRequest): Promise<NotificationResult>
61
+ readonly supported: boolean
62
+ }
63
+
64
+ export function useNotify(): NotifyApi {
65
+ const capabilities = useHostCapabilities()
66
+ const send = useSendIntent()
67
+ return useMemo(() => {
68
+ const notify = ((request: NotificationRequest) => {
69
+ if (capabilities.actions.notify === undefined) return unsupported('actions.notify')
70
+ portable(request)
71
+ return send('actions.notify', request)
72
+ }) as NotifyApi
73
+ Object.defineProperty(notify, 'supported', {
74
+ enumerable: true,
75
+ value: capabilities.actions.notify !== undefined,
76
+ })
77
+ return notify
78
+ }, [capabilities, send])
79
+ }
80
+
81
+ export interface OpenViewApi {
82
+ (request: OpenViewRequest): Promise<OpenViewResult>
83
+ readonly supported: boolean
84
+ }
85
+
86
+ export function useOpenView(): OpenViewApi {
87
+ const capabilities = useHostCapabilities()
88
+ const send = useSendIntent()
89
+ return useMemo(() => {
90
+ const open = ((request: OpenViewRequest) => {
91
+ if (capabilities.navigation.openView === undefined) return unsupported('view.open')
92
+ portable(request)
93
+ return send('view.open', request)
94
+ }) as OpenViewApi
95
+ Object.defineProperty(open, 'supported', {
96
+ enumerable: true,
97
+ value: capabilities.navigation.openView !== undefined,
98
+ })
99
+ return open
100
+ }, [capabilities, send])
101
+ }
102
+
103
+ export interface ExternalOpenApi {
104
+ (request: ExternalOpenRequest): Promise<ExternalOpenResult>
105
+ readonly supported: boolean
106
+ }
107
+
108
+ export function useExternalOpen(): ExternalOpenApi {
109
+ const capabilities = useHostCapabilities()
110
+ const send = useSendIntent()
111
+ return useMemo(() => {
112
+ const open = ((request: ExternalOpenRequest) => {
113
+ if (capabilities.navigation.external === undefined) return unsupported('browser.openExternal')
114
+ portable(request)
115
+ return send('browser.openExternal', request)
116
+ }) as ExternalOpenApi
117
+ Object.defineProperty(open, 'supported', {
118
+ enumerable: true,
119
+ value: capabilities.navigation.external !== undefined,
120
+ })
121
+ return open
122
+ }, [capabilities, send])
123
+ }
124
+
125
+ export interface RequestAccessApi {
126
+ (request: AccessRequest): Promise<AccessResult>
127
+ readonly supported: boolean
128
+ }
129
+
130
+ export function useRequestAccess(): RequestAccessApi {
131
+ const capabilities = useHostCapabilities()
132
+ const send = useSendIntent()
133
+ return useMemo(() => {
134
+ const request = ((input: AccessRequest) => {
135
+ if (capabilities.access.request === undefined) return unsupported('access.request')
136
+ portable(input)
137
+ return send('access.request', input)
138
+ }) as RequestAccessApi
139
+ Object.defineProperty(request, 'supported', {
140
+ enumerable: true,
141
+ value: capabilities.access.request !== undefined,
142
+ })
143
+ return request
144
+ }, [capabilities, send])
145
+ }
146
+
147
+ function unsupported<Result>(capability: string): Promise<Result> {
148
+ return Promise.reject(new HostCapabilityUnavailableError(capability))
149
+ }
150
+
151
+ function portable(input: unknown): void {
152
+ const seen = new WeakSet<object>()
153
+ const visit = (value: unknown): void => {
154
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return
155
+ if (typeof value === 'number' && Number.isFinite(value)) return
156
+ if (typeof value !== 'object' || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
157
+ throw new TypeError('Host action payload must be serializable data.')
158
+ }
159
+ if (seen.has(value)) throw new TypeError('Host action payload cannot contain cycles.')
160
+ seen.add(value)
161
+ if (Array.isArray(value)) value.forEach(visit)
162
+ else Object.values(value).forEach(visit)
163
+ }
164
+ visit(input)
165
+ }
@@ -0,0 +1,29 @@
1
+ import type { ReactElement, ReactNode } from 'react'
2
+
3
+ import type { HostDialogApi, NotifyApi, OpenViewApi, RequestAccessApi } from './actions.hook.js'
4
+
5
+ import { useHostDialog, useNotify, useOpenView, useRequestAccess } from './actions.hook.js'
6
+
7
+ export function HostDialog(props: {
8
+ readonly children: (dialog: HostDialogApi) => ReactNode
9
+ }): ReactElement {
10
+ return <>{props.children(useHostDialog())}</>
11
+ }
12
+
13
+ export function Notify(props: {
14
+ readonly children: (notify: NotifyApi) => ReactNode
15
+ }): ReactElement {
16
+ return <>{props.children(useNotify())}</>
17
+ }
18
+
19
+ export function NestedView(props: {
20
+ readonly children: (open: OpenViewApi) => ReactNode
21
+ }): ReactElement {
22
+ return <>{props.children(useOpenView())}</>
23
+ }
24
+
25
+ export function RequestAccess(props: {
26
+ readonly children: (request: RequestAccessApi) => ReactNode
27
+ }): ReactElement {
28
+ return <>{props.children(useRequestAccess())}</>
29
+ }
@@ -0,0 +1,17 @@
1
+ export {
2
+ useExternalOpen,
3
+ useHostCapabilities,
4
+ useHostDialog,
5
+ useNotify,
6
+ useOpenView,
7
+ useRequestAccess,
8
+ } from './actions.hook.js'
9
+ export type {
10
+ ExternalOpenApi,
11
+ HostDialogApi,
12
+ NotifyApi,
13
+ OpenViewApi,
14
+ RequestAccessApi,
15
+ } from './actions.hook.js'
16
+ export { HostDialog, NestedView, Notify, RequestAccess } from './components.js'
17
+ export { HostCapabilityUnavailableError } from './actions.hook.js'
package/src/index.ts CHANGED
@@ -1,82 +1,90 @@
1
- /**
2
- * @astrale-os/shell-react — the React face of the shell (SHELL_REACT_API.md §0).
3
- * One package, one import surface (SPEC §4.2); the bounded-context directories are
4
- * the module structure, not subpaths. This public barrel composes the context
5
- * barrels. Settled naming (§0): useKernelClient = the raw handle (session);
6
- * useKernel() = the TYPED kernel (schema, no arg); useDomain(schema) = a typed
7
- * domain binding. `useNode`/`useChildren` are single overloaded symbols (untyped
8
- * floor + typed overloads) exported from the graph plane.
9
- */
1
+ /** @astrale-os/shell-react — curated React runtime over Shell and Kernel Client Store. */
10
2
 
11
- // ─── session (§2 provider + §3) ──────────────────────────────────────────────
12
- export { ShellProvider } from './session/index.js'
13
- export type { ShellError, ShellProviderProps } from './session/index.js'
14
- export { useConnection, useKernelClient, useKernelInstance, useShell } from './session/index.js'
15
- export type { KernelInstance } from './session/index.js'
16
-
17
- // ─── auth (§4) ───────────────────────────────────────────────────────────────
3
+ // Root/provider and authenticated caller.
4
+ export {
5
+ ShellProvider,
6
+ useConnection,
7
+ useKernelClient,
8
+ useKernelInstance,
9
+ useShell,
10
+ } from './session/index.js'
11
+ export type { KernelInstance, ShellError, ShellProviderProps } from './session/index.js'
18
12
  export { ActAs, useAuth, useCan, useSelf } from './auth/index.js'
19
- export type { ActAsProps } from './auth/index.js'
13
+ export type { ActAsProps, PolicyObject } from './auth/index.js'
20
14
 
21
- // ─── graph — the untyped floor + writes + dispatch (§5, §7) ──────────────────
22
- // `useNode`/`useChildren` are single symbols merging the untyped floor + typed
23
- // overloads.
15
+ // One Store path and named SDK definitions. Raw Query/Mutation builders are intentionally absent.
24
16
  export {
17
+ ClientError,
18
+ NodeUnavailableError,
19
+ ProtocolError,
20
+ ResponseError,
21
+ StaleRouteError,
22
+ TransportError,
23
+ isClientError,
24
+ isNodeUnavailableError,
25
25
  useCall,
26
- useChildren,
27
- useGraph,
28
- useMove,
29
- useMutate,
30
- useNode,
26
+ useGraphStore,
31
27
  useQuery,
32
28
  useStream,
33
29
  } from './graph/index.js'
34
30
  export type {
35
- ChildrenOptions,
36
- ChildrenResult,
37
- GraphMemory,
38
- MoveAction,
39
- Node,
40
- NodeResult,
41
- QueryResult,
42
- ShapeInput,
43
- UseMutateOptions,
31
+ CallOptions,
32
+ GraphResource,
33
+ GraphResourceState,
34
+ GraphStore,
35
+ QueryResourceOptions,
36
+ StreamHandle,
37
+ StreamOptions,
44
38
  } from './graph/index.js'
45
- export type { CallOptions, StreamHandle, StreamOptions } from './graph/index.js'
46
39
 
47
- // ─── schema — the typed substrate (§6) ───────────────────────────────────────
48
- export { useDomain, useFunction, useIn, useKernel, useMethod, useOut } from './schema/index.js'
49
- export type { FunctionOptions } from './schema/index.js'
50
- export type { MethodOptions } from './schema/index.js'
40
+ // Rich exact Domain bindings.
41
+ export {
42
+ RelationUnavailableError,
43
+ queryRefresh,
44
+ useAction,
45
+ useDomain,
46
+ useDomains,
47
+ useDynamicDomain,
48
+ useDynamicObject,
49
+ useKernel,
50
+ useMutation,
51
+ useObject,
52
+ useRelation,
53
+ } from './schema/index.js'
51
54
  export type {
52
- AutoMethodAction,
53
- BoundMethodAction,
54
- EndpointResult,
55
- FunctionNames,
56
- FunctionParams,
57
- FunctionResult,
58
- MethodIsStatic,
59
- MethodNames,
60
- MethodParams,
61
- MethodResult,
62
- TargetedMethodAction,
63
- TypedChildrenResult,
64
- TypedNodeResult,
55
+ ActionOptions,
56
+ ActionRefresh,
57
+ DomainAction,
58
+ MutationOptions,
59
+ QueryRefresh,
60
+ RelationOptions,
61
+ RelationResource,
62
+ RelationUnavailable,
63
+ RichReadOptions,
65
64
  } from './schema/index.js'
66
65
 
67
- // ─── navigation (§8) ─────────────────────────────────────────────────────────
66
+ // Typed navigation and selection.
68
67
  export {
69
68
  Link,
69
+ NavigationScope,
70
70
  NavScope,
71
+ NodeLink,
72
+ pathParam,
73
+ ViewLink,
74
+ defineNavigation,
75
+ enumParam,
76
+ location,
71
77
  memoryAdapter,
72
78
  urlAdapter,
73
79
  useAncestors,
74
80
  useLocation,
75
- useNavScope,
76
81
  useNavigate,
82
+ useNavigation,
83
+ useNavScope,
77
84
  } from './navigation/index.js'
78
85
  export type {
79
86
  LinkProps,
87
+ LocationDefinition,
80
88
  MissingPolicy,
81
89
  NavAdapter,
82
90
  NavLocation,
@@ -84,39 +92,63 @@ export type {
84
92
  NavScopeProps,
85
93
  NavSnapshot,
86
94
  NavTarget,
95
+ NavigationDefinition,
96
+ NavigationParam,
97
+ NavigationParams,
98
+ NavigationRoutes,
99
+ NavigationTarget,
100
+ NodeLinkProps,
87
101
  Navigate,
88
102
  SerializedLocation,
103
+ ViewLinkProps,
89
104
  } from './navigation/index.js'
90
-
91
- // ─── selection (§9) ──────────────────────────────────────────────────────────
92
105
  export { SelectionScope, useSelection } from './selection/index.js'
93
106
  export type { Selection, SelectionScopeProps } from './selection/index.js'
94
107
 
95
- // ─── window (§10) ────────────────────────────────────────────────────────────
108
+ // View/window lifecycle and host effects.
96
109
  export {
110
+ ViewHost,
111
+ ViewStage,
97
112
  useCloseGuard,
98
113
  useTargetNode,
114
+ useTargetPath,
99
115
  useViewsFor,
100
116
  useWindow,
101
117
  useWindowList,
102
118
  useWindows,
103
- ViewHost,
104
- ViewStage,
105
119
  } from './window/index.js'
106
120
  export type {
107
121
  CloseGuard,
108
122
  CloseVerdict,
109
- ViewDescriptor,
110
- ViewHostProps,
111
- ViewSource,
123
+ ResolvedView,
124
+ SandboxPolicy,
112
125
  ViewHostHandle,
126
+ ViewHostProps,
113
127
  ViewsForResult,
114
128
  WindowListEntry,
115
129
  WindowState,
116
130
  WindowView,
117
131
  } from './window/index.js'
118
-
119
- // ─── intents (§11) ───────────────────────────────────────────────────────────
132
+ export {
133
+ HostDialog,
134
+ NestedView,
135
+ Notify,
136
+ RequestAccess,
137
+ useExternalOpen,
138
+ useHostCapabilities,
139
+ useHostDialog,
140
+ useNotify,
141
+ useOpenView,
142
+ useRequestAccess,
143
+ } from './host/index.js'
144
+ export type {
145
+ ExternalOpenApi,
146
+ HostDialogApi,
147
+ NotifyApi,
148
+ OpenViewApi,
149
+ RequestAccessApi,
150
+ } from './host/index.js'
151
+ export { HostCapabilityUnavailableError } from './host/index.js'
120
152
  export { useEmitIntent, useIntent, useSendIntent } from './intents/index.js'
121
153
  export type {
122
154
  EmitIntent,
@@ -126,15 +158,33 @@ export type {
126
158
  SendIntent,
127
159
  } from './intents/index.js'
128
160
 
129
- // ─── application — the OS plane (§12) ────────────────────────────────────────
161
+ // Headless composition kit.
162
+ export {
163
+ Can,
164
+ ConnectionBoundary,
165
+ CredentialBoundary,
166
+ defaultViewError,
167
+ defaultViewLoading,
168
+ GraphBoundary,
169
+ mountDomainFrontend,
170
+ ViewApp,
171
+ ViewBoundary,
172
+ ViewErrorBoundary,
173
+ } from './components/index.js'
174
+ export type {
175
+ MountedDomainFrontend,
176
+ MountDomainFrontendOptions,
177
+ ViewErrorBoundaryProps,
178
+ } from './components/index.js'
179
+
180
+ // Shell application conveniences.
130
181
  export {
131
182
  AppHost,
132
183
  AppLogo,
133
184
  useApps,
134
185
  useCurrentSpace,
186
+ useInstalledDomains,
135
187
  useOpenApp,
136
- useRoles,
137
- useDomains,
138
188
  useSpace,
139
189
  useSpaces,
140
190
  useUser,
@@ -145,73 +195,37 @@ export type {
145
195
  AppLogoProps,
146
196
  AppsResult,
147
197
  CurrentSpaceResult,
148
- RolesResult,
149
198
  DomainsResult,
150
199
  SpaceResult,
151
200
  SpacesResult,
152
201
  } from './application/index.js'
153
- // OS node/session types (from the shell package, single import surface).
154
- export type {
155
- ApplicationNode,
156
- AppSession,
157
- DomainSearchResult,
158
- RoleNode,
159
- SpaceNode,
160
- UserNode,
161
- } from '@astrale-os/shell'
162
-
163
- // ─── shared envelopes (§1) ───────────────────────────────────────────────────
164
- export type { Action, ReadState, ReadOptions, Windowed } from './graph/index.js'
165
202
 
166
- // ─── error taxonomy (§1.4) — guards + classes, re-exported from kernel-client ─
167
- export * from './graph/guards.error.js'
203
+ // Canonical identity carriers used by View props and rich hooks.
204
+ export { NodeId } from '@astrale-os/sdk/graph/node'
205
+ export { NodePath, Path } from '@astrale-os/sdk/graph/path'
206
+ export type { Node } from '@astrale-os/sdk/graph/node'
207
+ export type { PathLike } from '@astrale-os/sdk/graph/path'
208
+ export type { AuthApi, Identity, PolicyDecisionInput } from '@astrale-os/kernel-client/auth'
209
+ export type { DomainBinding, DomainInvokeOptions } from '@astrale-os/shell'
168
210
 
169
- // ─── re-exported kernel-client types (one import surface, §0 preamble) ───────
170
- export {
171
- DESCRIPTION_KEY,
172
- NAME_KEY,
173
- STATUS_KEY,
174
- descriptionOf,
175
- nameOf,
176
- normalizeRef,
177
- statusOf,
178
- } from '@astrale-os/kernel-client'
179
- export type {
180
- AnyBoundNode,
181
- BoundNode,
182
- CreatableClassNames,
183
- CreateProps,
184
- CredentialInput,
185
- DefOf,
186
- EdgeNames,
187
- EndpointsOf,
188
- FnMap,
189
- NamedNodeLike,
190
- NodeRefInput,
191
- SchemaBoundView,
192
- TypeNames,
193
- } from '@astrale-os/kernel-client'
194
- export type {
195
- EdgeIdentity,
196
- GatherBuilder,
197
- OrderInput,
198
- PatchBuilder,
199
- PatchInput,
200
- PathLike,
201
- Properties,
202
- QueryASTInput,
203
- QuerySource,
204
- } from '@astrale-os/kernel-client/graph'
205
- export type { AuthApi, Perms } from '@astrale-os/kernel-client/auth'
206
- export type { Schema } from '@astrale-os/kernel-dsl'
207
-
208
- // ─── re-exported shell types (one import surface, SPEC §4.2) ──────────────────
211
+ // Shell contracts retained at the package root for custom full-app composition.
209
212
  export type {
213
+ ApplicationNode,
214
+ AppSession,
210
215
  CloseResult,
216
+ CredentialSnapshot,
217
+ DomainSearchResult,
218
+ HostCapabilities,
219
+ IntentRegistry,
211
220
  KernelClient,
212
221
  MountCredential,
222
+ NodeTarget,
213
223
  Shell,
214
224
  ShellConfig,
225
+ SpaceNode,
226
+ UserNode,
227
+ ViewLocation,
228
+ ViewPresentation,
229
+ ViewPresentationRequest,
215
230
  Window,
216
231
  } from '@astrale-os/shell'
217
- export type { IntentRegistry } from '@astrale-os/shell'