@astrale-os/shell-react 0.2.9 → 0.2.10-beta.3
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.
- package/dist/application/apps/app-host.d.ts +4 -15
- package/dist/application/apps/app-host.d.ts.map +1 -1
- package/dist/application/apps/app-host.js +1 -1
- package/dist/application/apps/apps.hook.d.ts +7 -4
- package/dist/application/apps/apps.hook.d.ts.map +1 -1
- package/dist/application/apps/apps.hook.js +10 -2
- package/dist/application/apps/domains.hook.d.ts +1 -1
- package/dist/application/apps/domains.hook.d.ts.map +1 -1
- package/dist/application/apps/domains.hook.js +1 -1
- package/dist/application/apps/open-app.hook.d.ts +2 -3
- package/dist/application/apps/open-app.hook.d.ts.map +1 -1
- package/dist/application/index.d.ts +2 -4
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +2 -3
- package/dist/application/spaces/space.hook.d.ts +2 -2
- package/dist/application/spaces/space.hook.d.ts.map +1 -1
- package/dist/application/spaces/space.hook.js +2 -2
- package/dist/application/spaces/spaces.hook.d.ts +2 -3
- package/dist/application/spaces/spaces.hook.d.ts.map +1 -1
- package/dist/application/spaces/spaces.hook.js +10 -3
- package/dist/auth/act-as.context.d.ts +15 -32
- package/dist/auth/act-as.context.d.ts.map +1 -1
- package/dist/auth/act-as.context.js +22 -66
- package/dist/auth/auth.hook.d.ts +1 -0
- package/dist/auth/auth.hook.d.ts.map +1 -1
- package/dist/auth/auth.hook.js +2 -22
- package/dist/auth/can.hook.d.ts +10 -38
- package/dist/auth/can.hook.d.ts.map +1 -1
- package/dist/auth/can.hook.js +35 -110
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/self.hook.d.ts +2 -2
- package/dist/auth/self.hook.d.ts.map +1 -1
- package/dist/auth/self.hook.js +0 -7
- package/dist/auth/session-kernel.d.ts +2 -3
- package/dist/auth/session-kernel.d.ts.map +1 -1
- package/dist/auth/session-kernel.js +4 -13
- package/dist/components/astrale.d.ts +14 -0
- package/dist/components/astrale.d.ts.map +1 -0
- package/dist/components/astrale.js +12 -0
- package/dist/components/boundaries.d.ts +47 -0
- package/dist/components/boundaries.d.ts.map +1 -0
- package/dist/components/boundaries.js +55 -0
- package/dist/components/can.d.ts +11 -0
- package/dist/components/can.d.ts.map +1 -0
- package/dist/components/can.js +5 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +3 -0
- package/dist/graph/call/call.hook.d.ts +8 -18
- package/dist/graph/call/call.hook.d.ts.map +1 -1
- package/dist/graph/call/call.hook.js +7 -13
- package/dist/graph/call/stream.hook.d.ts +12 -20
- package/dist/graph/call/stream.hook.d.ts.map +1 -1
- package/dist/graph/call/stream.hook.js +55 -111
- package/dist/graph/graph.context.d.ts +4 -3
- package/dist/graph/graph.context.d.ts.map +1 -1
- package/dist/graph/graph.context.js +2 -8
- package/dist/graph/guards.error.d.ts +7 -8
- package/dist/graph/guards.error.d.ts.map +1 -1
- package/dist/graph/guards.error.js +11 -7
- package/dist/graph/index.d.ts +8 -16
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +3 -7
- package/dist/graph/memory/read/envelope.d.ts +22 -54
- package/dist/graph/memory/read/envelope.d.ts.map +1 -1
- package/dist/graph/memory/read/envelope.js +26 -20
- package/dist/graph/memory/read/idle.d.ts +1 -15
- package/dist/graph/memory/read/idle.d.ts.map +1 -1
- package/dist/graph/memory/read/idle.js +4 -13
- package/dist/graph/query-definition.hook.d.ts +11 -0
- package/dist/graph/query-definition.hook.d.ts.map +1 -0
- package/dist/graph/query-definition.hook.js +205 -0
- package/dist/graph/resource.d.ts +34 -0
- package/dist/graph/resource.d.ts.map +1 -0
- package/dist/graph/resource.js +244 -0
- package/dist/graph/store.d.ts +25 -0
- package/dist/graph/store.d.ts.map +1 -0
- package/dist/graph/store.js +69 -0
- package/dist/host/actions.hook.d.ts +34 -0
- package/dist/host/actions.hook.d.ts.map +1 -0
- package/dist/host/actions.hook.js +125 -0
- package/dist/host/components.d.ts +15 -0
- package/dist/host/components.d.ts.map +1 -0
- package/dist/host/components.js +14 -0
- package/dist/host/index.d.ts +5 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +3 -0
- package/dist/index.d.ts +26 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -31
- package/dist/intents/envelope.d.ts +7 -19
- package/dist/intents/envelope.d.ts.map +1 -1
- package/dist/intents/envelope.js +2 -3
- package/dist/intents/send-intent.hook.d.ts +5 -7
- package/dist/intents/send-intent.hook.d.ts.map +1 -1
- package/dist/intents/send-intent.hook.js +17 -75
- package/dist/navigation/adapters/adapter.d.ts +5 -0
- package/dist/navigation/adapters/adapter.d.ts.map +1 -1
- package/dist/navigation/adapters/memory.adapter.d.ts.map +1 -1
- package/dist/navigation/adapters/memory.adapter.js +4 -0
- package/dist/navigation/adapters/url.adapter.d.ts.map +1 -1
- package/dist/navigation/adapters/url.adapter.js +57 -10
- package/dist/navigation/codec.d.ts +60 -0
- package/dist/navigation/codec.d.ts.map +1 -0
- package/dist/navigation/codec.js +121 -0
- package/dist/navigation/history.d.ts +11 -9
- package/dist/navigation/history.d.ts.map +1 -1
- package/dist/navigation/history.js +6 -8
- package/dist/navigation/hooks/ancestors.hook.d.ts +5 -7
- package/dist/navigation/hooks/ancestors.hook.d.ts.map +1 -1
- package/dist/navigation/hooks/ancestors.hook.js +7 -51
- package/dist/navigation/hooks/location.hook.d.ts.map +1 -1
- package/dist/navigation/hooks/location.hook.js +4 -6
- package/dist/navigation/hooks/scope.hook.d.ts.map +1 -1
- package/dist/navigation/hooks/scope.hook.js +4 -6
- package/dist/navigation/index.d.ts +4 -2
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +2 -1
- package/dist/navigation/link.d.ts +12 -0
- package/dist/navigation/link.d.ts.map +1 -1
- package/dist/navigation/link.js +13 -2
- package/dist/navigation/location.d.ts +13 -40
- package/dist/navigation/location.d.ts.map +1 -1
- package/dist/navigation/location.js +14 -76
- package/dist/navigation/scope.context.d.ts +17 -26
- package/dist/navigation/scope.context.d.ts.map +1 -1
- package/dist/navigation/scope.context.js +140 -108
- package/dist/navigation/snapshot.d.ts +14 -19
- package/dist/navigation/snapshot.d.ts.map +1 -1
- package/dist/navigation/snapshot.js +48 -44
- package/dist/schema/action.hook.d.ts +44 -0
- package/dist/schema/action.hook.d.ts.map +1 -0
- package/dist/schema/action.hook.js +72 -0
- package/dist/schema/domain.hook.d.ts +12 -7
- package/dist/schema/domain.hook.d.ts.map +1 -1
- package/dist/schema/domain.hook.js +101 -4
- package/dist/schema/index.d.ts +9 -8
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +5 -7
- package/dist/schema/kernel.hook.d.ts +4 -9
- package/dist/schema/kernel.hook.d.ts.map +1 -1
- package/dist/schema/kernel.hook.js +4 -6
- package/dist/schema/mutation.hook.d.ts +9 -0
- package/dist/schema/mutation.hook.d.ts.map +1 -0
- package/dist/schema/mutation.hook.js +41 -0
- package/dist/schema/object.hook.d.ts +16 -0
- package/dist/schema/object.hook.d.ts.map +1 -0
- package/dist/schema/object.hook.js +46 -0
- package/dist/schema/relation.hook.d.ts +46 -0
- package/dist/schema/relation.hook.d.ts.map +1 -0
- package/dist/schema/relation.hook.js +136 -0
- package/dist/selection/live.d.ts +9 -17
- package/dist/selection/live.d.ts.map +1 -1
- package/dist/selection/live.js +65 -112
- package/dist/selection/scope.context.js +5 -4
- package/dist/session/boot/boot.d.ts +1 -13
- package/dist/session/boot/boot.d.ts.map +1 -1
- package/dist/session/boot/boot.js +9 -27
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/kernel-instance.hook.d.ts +1 -4
- package/dist/session/kernel-instance.hook.d.ts.map +1 -1
- package/dist/session/kernel-instance.hook.js +1 -5
- package/dist/session/provider.d.ts +9 -23
- package/dist/session/provider.d.ts.map +1 -1
- package/dist/session/provider.js +29 -75
- package/dist/session/session.context.d.ts +5 -0
- package/dist/session/session.context.d.ts.map +1 -1
- package/dist/window/adopt.d.ts +0 -1
- package/dist/window/adopt.d.ts.map +1 -1
- package/dist/window/hooks/target-node.hook.d.ts +10 -6
- package/dist/window/hooks/target-node.hook.d.ts.map +1 -1
- package/dist/window/hooks/target-node.hook.js +14 -72
- package/dist/window/hooks/views-for.hook.d.ts +4 -3
- package/dist/window/hooks/views-for.hook.d.ts.map +1 -1
- package/dist/window/hooks/views-for.hook.js +6 -22
- package/dist/window/hooks/windows.hook.d.ts.map +1 -1
- package/dist/window/hooks/windows.hook.js +3 -4
- package/dist/window/host.d.ts +9 -11
- package/dist/window/host.d.ts.map +1 -1
- package/dist/window/host.js +26 -62
- package/dist/window/hub.d.ts +2 -0
- package/dist/window/hub.d.ts.map +1 -1
- package/dist/window/hub.js +33 -0
- package/dist/window/index.d.ts +2 -2
- package/dist/window/index.d.ts.map +1 -1
- package/dist/window/index.js +2 -2
- package/dist/window/lifecycle/mount.d.ts +5 -44
- package/dist/window/lifecycle/mount.d.ts.map +1 -1
- package/dist/window/lifecycle/mount.js +14 -120
- package/dist/window/lifecycle/states.d.ts +0 -5
- package/dist/window/lifecycle/states.d.ts.map +1 -1
- package/package.json +20 -8
- package/src/application/apps/app-host.tsx +11 -15
- package/src/application/apps/apps.hook.ts +13 -6
- package/src/application/apps/domains.hook.ts +1 -1
- package/src/application/apps/open-app.hook.ts +3 -4
- package/src/application/index.ts +4 -6
- package/src/application/spaces/space.hook.ts +5 -6
- package/src/application/spaces/spaces.hook.ts +14 -9
- package/src/auth/act-as.context.tsx +37 -91
- package/src/auth/auth.hook.ts +2 -30
- package/src/auth/can.hook.ts +44 -135
- package/src/auth/index.ts +1 -0
- package/src/auth/self.hook.ts +2 -9
- package/src/auth/session-kernel.ts +6 -16
- package/src/components/astrale.tsx +40 -0
- package/src/components/boundaries.tsx +113 -0
- package/src/components/can.tsx +16 -0
- package/src/components/index.ts +13 -0
- package/src/graph/call/call.hook.ts +22 -27
- package/src/graph/call/stream.hook.ts +66 -143
- package/src/graph/graph.context.ts +6 -11
- package/src/graph/guards.error.ts +17 -55
- package/src/graph/index.ts +23 -17
- package/src/graph/memory/read/envelope.ts +40 -65
- package/src/graph/memory/read/idle.ts +5 -18
- package/src/graph/query-definition.hook.ts +270 -0
- package/src/graph/resource.ts +358 -0
- package/src/graph/store.ts +97 -0
- package/src/host/actions.hook.ts +165 -0
- package/src/host/components.tsx +29 -0
- package/src/host/index.ts +17 -0
- package/src/index.ts +131 -124
- package/src/intents/envelope.ts +7 -23
- package/src/intents/send-intent.hook.ts +24 -79
- package/src/navigation/adapters/adapter.ts +3 -0
- package/src/navigation/adapters/memory.adapter.ts +4 -0
- package/src/navigation/adapters/url.adapter.ts +48 -8
- package/src/navigation/codec.ts +190 -0
- package/src/navigation/history.ts +20 -11
- package/src/navigation/hooks/ancestors.hook.ts +10 -60
- package/src/navigation/hooks/location.hook.ts +4 -6
- package/src/navigation/hooks/scope.hook.ts +4 -6
- package/src/navigation/index.ts +18 -2
- package/src/navigation/link.tsx +27 -2
- package/src/navigation/location.ts +26 -93
- package/src/navigation/scope.context.tsx +151 -136
- package/src/navigation/snapshot.ts +69 -50
- package/src/schema/action.hook.ts +146 -0
- package/src/schema/domain.hook.ts +127 -11
- package/src/schema/index.ts +9 -30
- package/src/schema/kernel.hook.ts +6 -13
- package/src/schema/mutation.hook.ts +63 -0
- package/src/schema/object.hook.ts +85 -0
- package/src/schema/relation.hook.ts +253 -0
- package/src/selection/live.ts +75 -125
- package/src/selection/scope.context.tsx +4 -4
- package/src/session/boot/boot.ts +8 -33
- package/src/session/index.ts +1 -0
- package/src/session/kernel-instance.hook.ts +2 -11
- package/src/session/provider.tsx +34 -103
- package/src/session/session.context.ts +6 -0
- package/src/window/adopt.ts +0 -1
- package/src/window/hooks/target-node.hook.ts +20 -85
- package/src/window/hooks/views-for.hook.ts +12 -25
- package/src/window/hooks/windows.hook.ts +3 -4
- package/src/window/host.tsx +35 -77
- package/src/window/hub.ts +33 -0
- package/src/window/index.ts +3 -3
- package/src/window/lifecycle/mount.ts +15 -160
- package/src/window/lifecycle/states.ts +1 -5
- package/dist/application/roles.hook.d.ts +0 -7
- package/dist/application/roles.hook.d.ts.map +0 -1
- package/dist/application/roles.hook.js +0 -23
- package/dist/graph/memory/base.d.ts +0 -21
- package/dist/graph/memory/base.d.ts.map +0 -1
- package/dist/graph/memory/base.js +0 -33
- package/dist/graph/memory/read/read.d.ts +0 -9
- package/dist/graph/memory/read/read.d.ts.map +0 -1
- package/dist/graph/memory/read/read.js +0 -87
- package/dist/graph/memory/scope.d.ts +0 -7
- package/dist/graph/memory/scope.d.ts.map +0 -1
- package/dist/graph/memory/scope.js +0 -25
- package/dist/graph/mutate/move.hook.d.ts +0 -7
- package/dist/graph/mutate/move.hook.d.ts.map +0 -1
- package/dist/graph/mutate/move.hook.js +0 -49
- package/dist/graph/mutate/mutate.hook.d.ts +0 -17
- package/dist/graph/mutate/mutate.hook.d.ts.map +0 -1
- package/dist/graph/mutate/mutate.hook.js +0 -45
- package/dist/graph/query/children.hook.d.ts +0 -29
- package/dist/graph/query/children.hook.d.ts.map +0 -1
- package/dist/graph/query/children.hook.js +0 -64
- package/dist/graph/query/graph.hook.d.ts +0 -9
- package/dist/graph/query/graph.hook.d.ts.map +0 -1
- package/dist/graph/query/graph.hook.js +0 -5
- package/dist/graph/query/neighbors.hook.d.ts +0 -7
- package/dist/graph/query/neighbors.hook.d.ts.map +0 -1
- package/dist/graph/query/neighbors.hook.js +0 -104
- package/dist/graph/query/node.hook.d.ts +0 -14
- package/dist/graph/query/node.hook.d.ts.map +0 -1
- package/dist/graph/query/node.hook.js +0 -43
- package/dist/graph/query/query.hook.d.ts +0 -14
- package/dist/graph/query/query.hook.d.ts.map +0 -1
- package/dist/graph/query/query.hook.js +0 -23
- package/dist/schema/bind-read.d.ts +0 -37
- package/dist/schema/bind-read.d.ts.map +0 -1
- package/dist/schema/bind-read.js +0 -205
- package/dist/schema/binding.d.ts +0 -21
- package/dist/schema/binding.d.ts.map +0 -1
- package/dist/schema/binding.js +0 -99
- package/dist/schema/function.hook.d.ts +0 -9
- package/dist/schema/function.hook.d.ts.map +0 -1
- package/dist/schema/function.hook.js +0 -40
- package/dist/schema/method.hook.d.ts +0 -14
- package/dist/schema/method.hook.d.ts.map +0 -1
- package/dist/schema/method.hook.js +0 -49
- package/dist/schema/tag.d.ts +0 -11
- package/dist/schema/tag.d.ts.map +0 -1
- package/dist/schema/tag.js +0 -11
- package/dist/schema/types.d.ts +0 -73
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js +0 -1
- package/dist/schema/write.d.ts +0 -16
- package/dist/schema/write.d.ts.map +0 -1
- package/dist/schema/write.js +0 -56
- package/src/application/roles.hook.ts +0 -41
- package/src/graph/memory/base.ts +0 -50
- package/src/graph/memory/read/read.ts +0 -103
- package/src/graph/memory/scope.ts +0 -29
- package/src/graph/mutate/move.hook.ts +0 -70
- package/src/graph/mutate/mutate.hook.ts +0 -69
- package/src/graph/query/children.hook.ts +0 -136
- package/src/graph/query/graph.hook.ts +0 -13
- package/src/graph/query/neighbors.hook.ts +0 -159
- package/src/graph/query/node.hook.ts +0 -83
- package/src/graph/query/query.hook.ts +0 -42
- package/src/schema/bind-read.ts +0 -319
- package/src/schema/binding.ts +0 -146
- package/src/schema/function.hook.ts +0 -68
- package/src/schema/method.hook.ts +0 -103
- package/src/schema/tag.ts +0 -19
- package/src/schema/types.ts +0 -150
- package/src/schema/write.ts +0 -96
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { canonicalizeAST, shapeInputToAST, stableStringify } from '@astrale-os/kernel-client/store';
|
|
2
|
-
/**
|
|
3
|
-
* The shared read substrate (API §1, §5). One `useSyncExternalStore` binding over
|
|
4
|
-
* a memory shape — the substrate every graph read hook narrows. Handles the four
|
|
5
|
-
* cross-cutting concerns once: idle inputs (§1.3), suspense-first on a cold shape
|
|
6
|
-
* (§1.4), stale-while-revalidate + `keepPrevious` (§1.5), and referential
|
|
7
|
-
* stability (§1.7 — an unchanged shape returns the store's own stable snapshot).
|
|
8
|
-
*/
|
|
9
|
-
import { useCallback, useRef, useSyncExternalStore } from 'react';
|
|
10
|
-
import { useMemory } from '../scope.js';
|
|
11
|
-
import { EMPTY_PENDING, IDLE_READ, withPending } from './envelope.js';
|
|
12
|
-
import { isIdleInput } from './idle.js';
|
|
13
|
-
const NOOP_UNSUB = () => { };
|
|
14
|
-
const IDLE_TOKEN = ' idle';
|
|
15
|
-
/** Project shell-react read options onto the store's — `with`/`window`/`live` key the shape. */
|
|
16
|
-
function storeReadOptions(opts) {
|
|
17
|
-
if (opts === undefined)
|
|
18
|
-
return undefined;
|
|
19
|
-
const out = {};
|
|
20
|
-
if (opts.live !== undefined)
|
|
21
|
-
out.live = opts.live;
|
|
22
|
-
if (opts.window !== undefined)
|
|
23
|
-
out.window = opts.window;
|
|
24
|
-
// `with` is a PermName at the store/kernel (READ lit-up today); the public
|
|
25
|
-
// `PermMask` typing reconciles with the grant epoch (API §14 G7).
|
|
26
|
-
if (opts.with !== undefined)
|
|
27
|
-
out.with = opts.with;
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A stable per-render key for a shape input + its keying options, so the
|
|
32
|
-
* subscription/snapshot closures only re-bind when the LOGICAL read changes
|
|
33
|
-
* (not when an inline builder closure is re-created each render).
|
|
34
|
-
*/
|
|
35
|
-
function shapeToken(shape, opts) {
|
|
36
|
-
const canon = stableStringify(canonicalizeAST(shapeInputToAST(shape)));
|
|
37
|
-
return `${canon}#w=${String(opts?.with ?? '')}#win=${opts?.window ?? ''}#live=${opts?.live === false ? '0' : '1'}`;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Subscribe to a memory shape and project it. `null`/`undefined` shape → idle.
|
|
41
|
-
* Cold + `suspend` (default) throws the cold-shape promise; `suspend:false`
|
|
42
|
-
* returns empty-pending; `keepPrevious` returns the last data while confirming.
|
|
43
|
-
*/
|
|
44
|
-
export function useRead(shape, opts) {
|
|
45
|
-
const memory = useMemory();
|
|
46
|
-
const idle = isIdleInput(shape);
|
|
47
|
-
const shapeRef = useRef(shape);
|
|
48
|
-
shapeRef.current = shape;
|
|
49
|
-
const optsRef = useRef(opts);
|
|
50
|
-
optsRef.current = opts;
|
|
51
|
-
const token = idle ? IDLE_TOKEN : shapeToken(shape, opts);
|
|
52
|
-
const subscribe = useCallback((onStoreChange) => {
|
|
53
|
-
const s = shapeRef.current;
|
|
54
|
-
if (token === IDLE_TOKEN || s === null || s === undefined)
|
|
55
|
-
return NOOP_UNSUB;
|
|
56
|
-
return memory.subscribe(s, onStoreChange, storeReadOptions(optsRef.current));
|
|
57
|
-
}, [memory, token]);
|
|
58
|
-
const getSnapshot = useCallback(() => {
|
|
59
|
-
const s = shapeRef.current;
|
|
60
|
-
if (token === IDLE_TOKEN || s === null || s === undefined)
|
|
61
|
-
return null;
|
|
62
|
-
return memory.getSnapshot(s, storeReadOptions(optsRef.current));
|
|
63
|
-
}, [memory, token]);
|
|
64
|
-
const snap = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
65
|
-
const prevRef = useRef(null);
|
|
66
|
-
if (idle)
|
|
67
|
-
return IDLE_READ;
|
|
68
|
-
const warm = memory.peek(shape, storeReadOptions(opts)) !== null;
|
|
69
|
-
if (warm && snap !== null) {
|
|
70
|
-
prevRef.current = snap;
|
|
71
|
-
return snap;
|
|
72
|
-
}
|
|
73
|
-
if (opts?.keepPrevious === true && prevRef.current !== null) {
|
|
74
|
-
return withPending(prevRef.current);
|
|
75
|
-
}
|
|
76
|
-
if (opts?.suspend !== false) {
|
|
77
|
-
// Cold FAILURE (§1.4): the shape fetched and rejected with no data to show —
|
|
78
|
-
// throw the error to the nearest boundary. Re-throwing the promise here would
|
|
79
|
-
// re-arm a fresh fetch every retry (the entry's inflight was cleared on
|
|
80
|
-
// failure), looping render→fetch→reject forever. This breaks that loop.
|
|
81
|
-
if (snap !== null && snap.error !== undefined)
|
|
82
|
-
throw snap.error;
|
|
83
|
-
// Cold shape: suspend on the first-confirmed-data promise (§1.4).
|
|
84
|
-
throw memory.promise(shape, storeReadOptions(opts));
|
|
85
|
-
}
|
|
86
|
-
return EMPTY_PENDING;
|
|
87
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { GraphMemory } from '@astrale-os/kernel-client/store';
|
|
2
|
-
/**
|
|
3
|
-
* The memory for this subtree. Throws outside a `<ShellProvider>`. Above any
|
|
4
|
-
* `<ActAs>` it is the base memory; inside one it is scoped by the binding.
|
|
5
|
-
*/
|
|
6
|
-
export declare function useMemory(): GraphMemory;
|
|
7
|
-
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/graph/memory/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAclE;;;GAGG;AACH,wBAAgB,SAAS,IAAI,WAAW,CASvC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory scope resolution (API §5.4). `useMemory` returns the memory for this
|
|
3
|
-
* subtree: the base memory derived from the provider's Shell, re-scoped (and
|
|
4
|
-
* re-api'd) to the `<ActAs>` principal via `forScope` when an identity binding is
|
|
5
|
-
* present — so a principal never shares cached results with another.
|
|
6
|
-
*/
|
|
7
|
-
import { useContext, useMemo } from 'react';
|
|
8
|
-
import { IdentityContext } from '../../auth/act-as.context.js';
|
|
9
|
-
import { ShellContext } from '../../session/session.context.js';
|
|
10
|
-
import { baseMemoryFor } from './base.js';
|
|
11
|
-
/**
|
|
12
|
-
* The memory for this subtree. Throws outside a `<ShellProvider>`. Above any
|
|
13
|
-
* `<ActAs>` it is the base memory; inside one it is scoped by the binding.
|
|
14
|
-
*/
|
|
15
|
-
export function useMemory() {
|
|
16
|
-
const runtime = useContext(ShellContext);
|
|
17
|
-
const binding = useContext(IdentityContext);
|
|
18
|
-
const shell = runtime?.shell ?? null;
|
|
19
|
-
return useMemo(() => {
|
|
20
|
-
if (shell === null)
|
|
21
|
-
throw new Error('graph hooks must be used within a <ShellProvider>');
|
|
22
|
-
const base = baseMemoryFor(shell);
|
|
23
|
-
return binding === null ? base : base.forScope(binding.scope, binding.kernel);
|
|
24
|
-
}, [shell, binding]);
|
|
25
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { NodeRefInput } from '@astrale-os/kernel-client';
|
|
2
|
-
import type { PathLike } from '@astrale-os/kernel-client/graph';
|
|
3
|
-
import type { Action } from '../action.js';
|
|
4
|
-
import type { Node } from '../memory/read/envelope.js';
|
|
5
|
-
export type MoveAction = Action<[node: Node | NodeRefInput, to: PathLike], void>;
|
|
6
|
-
export declare function useMove(): MoveAction;
|
|
7
|
-
//# sourceMappingURL=move.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"move.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/mutate/move.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAY/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AAMtD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,YAAY,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;AAEhF,wBAAgB,OAAO,IAAI,UAAU,CAYpC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { rawOf } from '@astrale-os/kernel-client/graph';
|
|
2
|
-
/**
|
|
3
|
-
* useMove (API §5, the G1 seam) — dispatch the sealed `node::move` method (the one
|
|
4
|
-
* tree op no patch arm can express). PESSIMISTIC today (honest `pending`); affected
|
|
5
|
-
* container shapes revalidate on settlement. Turns optimistic when the `nodes.move`
|
|
6
|
-
* patch arm lands, with zero consumer change.
|
|
7
|
-
*/
|
|
8
|
-
import { useCallback } from 'react';
|
|
9
|
-
import { useSessionKernel } from '../../auth/session-kernel.js';
|
|
10
|
-
import { useAction } from '../action.js';
|
|
11
|
-
import { useMemory } from '../memory/scope.js';
|
|
12
|
-
export function useMove() {
|
|
13
|
-
const kernel = useSessionKernel();
|
|
14
|
-
const memory = useMemory();
|
|
15
|
-
const run = useCallback(async (node, to) => {
|
|
16
|
-
const method = isNode(node) ? `@${node.id}::move` : `${rawOf(node)}::move`;
|
|
17
|
-
await kernel.call(method, { to: rawOf(to) });
|
|
18
|
-
await reconcileMove(memory, node, to);
|
|
19
|
-
}, [kernel, memory]);
|
|
20
|
-
return useAction(run);
|
|
21
|
-
}
|
|
22
|
-
function isNode(x) {
|
|
23
|
-
return typeof x === 'object' && x !== null && 'id' in x && 'class' in x && 'path' in x;
|
|
24
|
-
}
|
|
25
|
-
/** Root-first parent of a raw absolute path, or `null` at the root. */
|
|
26
|
-
function parentPathOf(raw) {
|
|
27
|
-
const trimmed = raw.replace(/\/+$/, '');
|
|
28
|
-
const i = trimmed.lastIndexOf('/');
|
|
29
|
-
if (i < 0)
|
|
30
|
-
return null;
|
|
31
|
-
return i === 0 ? '/' : trimmed.slice(0, i);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Best-effort settlement reconciliation (Tier 0): refetch the source and
|
|
35
|
-
* destination container's default `children` shapes when they are observed. A
|
|
36
|
-
* custom-ordered/filtered children shape is keyed distinctly and is not reached
|
|
37
|
-
* here — consumers get honest `pending` and reconcile on G1.
|
|
38
|
-
*/
|
|
39
|
-
async function reconcileMove(memory, node, to) {
|
|
40
|
-
const path = isNode(node) ? rawOf(node.path) : rawOf(node);
|
|
41
|
-
const containers = new Set([rawOf(to)]);
|
|
42
|
-
const old = parentPathOf(path);
|
|
43
|
-
if (old !== null)
|
|
44
|
-
containers.add(old);
|
|
45
|
-
await Promise.allSettled([...containers].map((c) => {
|
|
46
|
-
const snap = memory.peek((q) => q.from(c).children());
|
|
47
|
-
return snap !== null ? snap.refetch() : Promise.resolve();
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PatchBuilder } from '@astrale-os/kernel-client/graph';
|
|
2
|
-
import type { GraphMemory } from '@astrale-os/kernel-client/store';
|
|
3
|
-
import type { Action } from '../action.js';
|
|
4
|
-
export interface UseMutateOptions<A extends unknown[], R> {
|
|
5
|
-
/**
|
|
6
|
-
* `'auto'` (default) / `false`: the write's own overlay governs optimism - the
|
|
7
|
-
* callback's graph writes apply the authored patch. A function opens a
|
|
8
|
-
* MANUAL overlay decoupled from what the callback dispatches.
|
|
9
|
-
*/
|
|
10
|
-
optimistic?: 'auto' | false | ((overlay: PatchBuilder, ...args: A) => void);
|
|
11
|
-
/** default 'auto'. false = keep the manual overlay on failure (caller reconciles). */
|
|
12
|
-
rollback?: 'auto' | false;
|
|
13
|
-
onCommit?: (result: R) => void;
|
|
14
|
-
onError?: (error: unknown) => void;
|
|
15
|
-
}
|
|
16
|
-
export declare function useMutate<A extends unknown[], R>(fn: (graph: GraphMemory, ...args: A) => Promise<R>, opts?: UseMutateOptions<A, R>): Action<A, R>;
|
|
17
|
-
//# sourceMappingURL=mutate.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutate.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/mutate/mutate.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAUlE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAK1C,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC;IACtD;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,CAAA;IAC3E,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACzB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAA;IAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnC;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC9C,EAAE,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAClD,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC5B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAoCd"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useMutate (API 5/1.6) - build a graph-scoped Action. The callback receives
|
|
3
|
-
* this subtree's GraphMemory, so callers do not need a separate useGraph() just
|
|
4
|
-
* to author the mutation. Patch-shaped writes are optimistic via their own
|
|
5
|
-
* overlay; pass a function `optimistic` to preview an opaque dispatch effect.
|
|
6
|
-
*/
|
|
7
|
-
import { useCallback, useRef } from 'react';
|
|
8
|
-
import { useAction } from '../action.js';
|
|
9
|
-
import { useMemory } from '../memory/scope.js';
|
|
10
|
-
export function useMutate(fn, opts) {
|
|
11
|
-
const memory = useMemory();
|
|
12
|
-
const fnRef = useRef(fn);
|
|
13
|
-
fnRef.current = fn;
|
|
14
|
-
const optsRef = useRef(opts);
|
|
15
|
-
optsRef.current = opts;
|
|
16
|
-
const run = useCallback(async (...args) => {
|
|
17
|
-
const o = optsRef.current;
|
|
18
|
-
const optimistic = o?.optimistic;
|
|
19
|
-
if (typeof optimistic === 'function') {
|
|
20
|
-
const overlay = memory.overlay((m) => optimistic(m, ...args));
|
|
21
|
-
try {
|
|
22
|
-
const result = await fnRef.current(memory, ...args);
|
|
23
|
-
overlay.commit();
|
|
24
|
-
o?.onCommit?.(result);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
if (o?.rollback !== false)
|
|
29
|
-
overlay.rollback();
|
|
30
|
-
o?.onError?.(error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
const result = await fnRef.current(memory, ...args);
|
|
36
|
-
o?.onCommit?.(result);
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
o?.onError?.(error);
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}, [memory]);
|
|
44
|
-
return useAction(run);
|
|
45
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { AnyBoundNode, TypeNames } from '@astrale-os/kernel-client';
|
|
2
|
-
import type { OrderInput, PathLike } from '@astrale-os/kernel-client/graph';
|
|
3
|
-
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
4
|
-
import type { TypedChildrenResult } from '../../schema/types.js';
|
|
5
|
-
import type { ReadState, Node, ReadOptions, Windowed } from '../memory/read/envelope.js';
|
|
6
|
-
export interface ChildrenOptions extends ReadOptions {
|
|
7
|
-
/** Restrict to these classes (dual-path descent filter). */
|
|
8
|
-
classes?: PathLike[];
|
|
9
|
-
/** Server-ordered by a node prop / `id`. */
|
|
10
|
-
order?: OrderInput;
|
|
11
|
-
/** Page size; `more.load()` extends. */
|
|
12
|
-
limit?: number;
|
|
13
|
-
/** `append` (default, infinite) vs `paged` (replace). */
|
|
14
|
-
window?: 'append' | 'paged';
|
|
15
|
-
}
|
|
16
|
-
export interface ChildrenResult extends ReadState, Windowed {
|
|
17
|
-
/** Ordered, all loaded pages, parent excluded. */
|
|
18
|
-
readonly children: readonly Node[];
|
|
19
|
-
}
|
|
20
|
-
/** Typed: a bound node's children of `opts.type`. */
|
|
21
|
-
export declare function useChildren<S extends Schema, T extends TypeNames<S>>(parent: AnyBoundNode<S> | null | undefined, opts: ReadOptions & {
|
|
22
|
-
type: T;
|
|
23
|
-
order?: OrderInput;
|
|
24
|
-
limit?: number;
|
|
25
|
-
window?: 'append' | 'paged';
|
|
26
|
-
}): TypedChildrenResult<S, T>;
|
|
27
|
-
/** Untyped: a node's direct children — windowed, live; `null` parent is idle (§1.3). */
|
|
28
|
-
export declare function useChildren(parent: Node | PathLike | null | undefined, opts?: ChildrenOptions): ChildrenResult;
|
|
29
|
-
//# sourceMappingURL=children.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"children.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/query/children.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,KAAK,EAEV,UAAU,EACV,QAAQ,EAGT,MAAM,iCAAiC,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAWpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAKxF,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,4DAA4D;IAC5D,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAA;IACpB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yDAAyD;IACzD,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,cAAe,SAAQ,SAAS,EAAE,QAAQ;IACzD,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,SAAS,IAAI,EAAE,CAAA;CACnC;AAuBD,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAClE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC1C,IAAI,EAAE,WAAW,GAAG;IAClB,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;CAC5B,GACA,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC5B,wFAAwF;AACxF,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,EAC1C,IAAI,CAAC,EAAE,eAAe,GACrB,cAAc,CAAA"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { rawOf } from '@astrale-os/kernel-client/graph';
|
|
2
|
-
/**
|
|
3
|
-
* useChildren (API §5 + §6) — ONE public symbol, overloaded: pass `opts.type`
|
|
4
|
-
* (over a `BoundNode` parent) for the typed children, or a bare parent for the
|
|
5
|
-
* untyped children. Both ride the SAME windowed memory shape. The untyped floor
|
|
6
|
-
* is a windowed, live read of a node's direct children; the typed twin binds them.
|
|
7
|
-
*/
|
|
8
|
-
import { useMemo } from 'react';
|
|
9
|
-
import { useChildren as useChildrenTyped } from '../../schema/bind-read.js';
|
|
10
|
-
import { useRead } from '../memory/read/read.js';
|
|
11
|
-
/** A node's direct children — windowed, live; `null` parent is idle (§1.3). */
|
|
12
|
-
function useChildrenUntyped(parent, opts) {
|
|
13
|
-
const shape = isIdle(parent) ? null : childrenShape(parent, opts);
|
|
14
|
-
const r = useRead(shape, opts);
|
|
15
|
-
return useMemo(() => ({
|
|
16
|
-
pending: r.pending,
|
|
17
|
-
error: r.error,
|
|
18
|
-
live: r.live,
|
|
19
|
-
seq: r.seq,
|
|
20
|
-
refetch: r.refetch,
|
|
21
|
-
children: r.children,
|
|
22
|
-
more: r.more,
|
|
23
|
-
}), [r]);
|
|
24
|
-
}
|
|
25
|
-
export function useChildren(parent, opts) {
|
|
26
|
-
if (hasType(opts)) {
|
|
27
|
-
return useChildrenTyped(parent, opts);
|
|
28
|
-
}
|
|
29
|
-
return useChildrenUntyped(parent, opts);
|
|
30
|
-
}
|
|
31
|
-
function hasType(opts) {
|
|
32
|
-
return (typeof opts === 'object' &&
|
|
33
|
-
opts !== null &&
|
|
34
|
-
'type' in opts &&
|
|
35
|
-
opts.type !== undefined);
|
|
36
|
-
}
|
|
37
|
-
// ── internals ────────────────────────────────────────────────────────────────
|
|
38
|
-
function isIdle(x) {
|
|
39
|
-
return x === null || x === undefined;
|
|
40
|
-
}
|
|
41
|
-
function isNode(x) {
|
|
42
|
-
return typeof x === 'object' && x !== null && 'id' in x && 'class' in x && 'path' in x;
|
|
43
|
-
}
|
|
44
|
-
/** A parent ref anchored on the node id (stable across rename) or the raw path. */
|
|
45
|
-
function refOf(parent) {
|
|
46
|
-
return isNode(parent) ? `@${parent.id}` : parent;
|
|
47
|
-
}
|
|
48
|
-
function walkOptsOf(opts) {
|
|
49
|
-
if (opts === undefined)
|
|
50
|
-
return undefined;
|
|
51
|
-
const { classes, order, limit } = opts;
|
|
52
|
-
if (classes === undefined && order === undefined && limit === undefined)
|
|
53
|
-
return undefined;
|
|
54
|
-
return {
|
|
55
|
-
...(classes !== undefined ? { classes: classes.map((c) => rawOf(c)) } : {}),
|
|
56
|
-
...(order !== undefined ? { order } : {}),
|
|
57
|
-
...(limit !== undefined ? { limit } : {}),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function childrenShape(parent, opts) {
|
|
61
|
-
const ref = refOf(parent);
|
|
62
|
-
const walk = walkOptsOf(opts);
|
|
63
|
-
return (q) => q.from(ref).children(walk);
|
|
64
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useGraph (API §5) — the memory handle for this subtree (the raw floor plus the
|
|
3
|
-
* memory's optimistic-auto write shorthands). The same scoped memory every
|
|
4
|
-
* graph/schema/nav hook reads.
|
|
5
|
-
*/
|
|
6
|
-
import type { GraphMemory } from '@astrale-os/kernel-client/store';
|
|
7
|
-
/** The memory for this subtree — the raw floor plus optimistic-auto shorthands (§5). */
|
|
8
|
-
export declare function useGraph(): GraphMemory;
|
|
9
|
-
//# sourceMappingURL=graph.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/query/graph.hook.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAIlE,wFAAwF;AACxF,wBAAgB,QAAQ,IAAI,WAAW,CAEtC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AnyBoundNode, EdgeNames } from '@astrale-os/kernel-client';
|
|
2
|
-
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
3
|
-
import type { EndpointResult } from '../../schema/types.js';
|
|
4
|
-
import type { ReadOptions } from '../memory/read/envelope.js';
|
|
5
|
-
export declare function useOut<S extends Schema, E extends EdgeNames<S>>(node: AnyBoundNode<S> | null | undefined, edge: E, opts?: ReadOptions): EndpointResult<S, E, 'to'>;
|
|
6
|
-
export declare function useIn<S extends Schema, E extends EdgeNames<S>>(node: AnyBoundNode<S> | null | undefined, edge: E, opts?: ReadOptions): EndpointResult<S, E, 'from'>;
|
|
7
|
-
//# sourceMappingURL=neighbors.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"neighbors.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/query/neighbors.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AASpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAKxE,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAC7D,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACxC,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EAAE,WAAW,GACjB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAE5B;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAC5D,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACxC,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EAAE,WAAW,GACjB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAE9B"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useOut / useIn (API §6) — the public typed traversal read hooks. Resolve
|
|
3
|
-
* endpoints one-shot through `BoundNode.links.out/in` (`live: false`); become live with
|
|
4
|
-
* no surface change once edge-endpoint ids land. Deviations tracked in API §6/G6.
|
|
5
|
-
*/
|
|
6
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import { schemaOf, tagSchema } from '../../schema/tag.js';
|
|
8
|
-
import { isIdleInput } from '../memory/read/idle.js';
|
|
9
|
-
export function useOut(node, edge, opts) {
|
|
10
|
-
return useEndpoint(node, edge, 'out', opts);
|
|
11
|
-
}
|
|
12
|
-
export function useIn(node, edge, opts) {
|
|
13
|
-
return useEndpoint(node, edge, 'in', opts);
|
|
14
|
-
}
|
|
15
|
-
function useEndpoint(node, edge, side, opts) {
|
|
16
|
-
const schema = isIdleInput(node) ? undefined : schemaOf(node);
|
|
17
|
-
const single = schema !== undefined && isSingleEndpoint(schema, edge, side);
|
|
18
|
-
const key = `${node?.id ?? ''}\u0000${edge}\u0000${side}`;
|
|
19
|
-
const run = useCallback(async () => {
|
|
20
|
-
if (isIdleInput(node))
|
|
21
|
-
return null;
|
|
22
|
-
const result = await (side === 'out' ? node.links.out(edge) : node.links.in(edge));
|
|
23
|
-
if (schema !== undefined)
|
|
24
|
-
tagEndpoints(result, schema);
|
|
25
|
-
return result;
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
}, [node?.id, edge, side]);
|
|
28
|
-
const { data, pending, error, refetch } = useAsyncRead(isIdleInput(node) ? null : run, key, opts?.keepPrevious === true);
|
|
29
|
-
return useMemo(() => {
|
|
30
|
-
const live = { pending, error, live: false, seq: 0, refetch };
|
|
31
|
-
if (isIdleInput(node))
|
|
32
|
-
return { ...live, node: null, nodes: EMPTY };
|
|
33
|
-
if (single) {
|
|
34
|
-
const value = Array.isArray(data) ? data[0] : data;
|
|
35
|
-
return { ...live, node: (value ?? null) };
|
|
36
|
-
}
|
|
37
|
-
const values = Array.isArray(data) ? data : data === null || data === undefined ? EMPTY : [data];
|
|
38
|
-
return { ...live, nodes: values };
|
|
39
|
-
}, [node, data, pending, error, refetch, single]);
|
|
40
|
-
}
|
|
41
|
-
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
42
|
-
const EMPTY = Object.freeze([]);
|
|
43
|
-
function isSingleEndpoint(schema, edge, side) {
|
|
44
|
-
const definition = schema.classes[edge];
|
|
45
|
-
const cardinality = (side === 'out' ? definition?.to : definition?.from)?.cardinality;
|
|
46
|
-
return cardinality === '1' || cardinality === '0..1';
|
|
47
|
-
}
|
|
48
|
-
function tagEndpoints(result, schema) {
|
|
49
|
-
if (Array.isArray(result))
|
|
50
|
-
for (const r of result)
|
|
51
|
-
tagSchema(r, schema);
|
|
52
|
-
else if (result !== null && result !== undefined)
|
|
53
|
-
tagSchema(result, schema);
|
|
54
|
-
}
|
|
55
|
-
/** One-shot async read with pending/error/refetch and stale-response guarding. */
|
|
56
|
-
function useAsyncRead(run, key, keepPrevious) {
|
|
57
|
-
const [state, setState] = useState({
|
|
58
|
-
pending: run !== null,
|
|
59
|
-
error: undefined,
|
|
60
|
-
key: run === null ? null : key,
|
|
61
|
-
});
|
|
62
|
-
const runRef = useRef(run);
|
|
63
|
-
runRef.current = run;
|
|
64
|
-
const keyRef = useRef(key);
|
|
65
|
-
keyRef.current = key;
|
|
66
|
-
const keepPreviousRef = useRef(keepPrevious);
|
|
67
|
-
keepPreviousRef.current = keepPrevious;
|
|
68
|
-
const seq = useRef(0);
|
|
69
|
-
const refetch = useCallback(() => {
|
|
70
|
-
const current = runRef.current;
|
|
71
|
-
const currentKey = keyRef.current;
|
|
72
|
-
if (current === null) {
|
|
73
|
-
setState({ pending: false, error: undefined, data: undefined, key: null });
|
|
74
|
-
return Promise.resolve();
|
|
75
|
-
}
|
|
76
|
-
const my = ++seq.current;
|
|
77
|
-
setState((s) => ({
|
|
78
|
-
data: s.key === currentKey || keepPreviousRef.current === true ? s.data : undefined,
|
|
79
|
-
pending: true,
|
|
80
|
-
error: undefined,
|
|
81
|
-
key: currentKey,
|
|
82
|
-
}));
|
|
83
|
-
return current().then((data) => {
|
|
84
|
-
if (my === seq.current) {
|
|
85
|
-
setState({ data, pending: false, error: undefined, key: currentKey });
|
|
86
|
-
}
|
|
87
|
-
}, (error) => {
|
|
88
|
-
if (my === seq.current) {
|
|
89
|
-
setState((s) => ({ data: s.data, pending: false, error, key: currentKey }));
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}, []);
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
void refetch();
|
|
95
|
-
}, [key, refetch]);
|
|
96
|
-
const current = state.key === key;
|
|
97
|
-
return {
|
|
98
|
-
data: current || keepPrevious ? state.data : undefined,
|
|
99
|
-
pending: run !== null && (!current || state.pending),
|
|
100
|
-
error: current ? state.error : undefined,
|
|
101
|
-
key: current ? state.key : null,
|
|
102
|
-
refetch,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NodeRefInput, TypeNames } from '@astrale-os/kernel-client';
|
|
2
|
-
import type { PathLike } from '@astrale-os/kernel-client/graph';
|
|
3
|
-
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
4
|
-
import type { TypedNodeResult } from '../../schema/types.js';
|
|
5
|
-
import type { ReadState, Node, ReadOptions } from '../memory/read/envelope.js';
|
|
6
|
-
export interface NodeResult extends ReadState {
|
|
7
|
-
/** The node, or `null` when missing ≡ masked (never throws NOT_FOUND). */
|
|
8
|
-
readonly node: Node | null;
|
|
9
|
-
}
|
|
10
|
-
/** Typed: one node bound under `schema` as `type`. */
|
|
11
|
-
export declare function useNode<S extends Schema, T extends TypeNames<S>>(schema: S, type: T, ref: NodeRefInput | null | undefined, opts?: ReadOptions): TypedNodeResult<S, T>;
|
|
12
|
-
/** Untyped: one node by ref — `null` ref is idle (§1.3). */
|
|
13
|
-
export declare function useNode(ref: PathLike | null | undefined, opts?: ReadOptions): NodeResult;
|
|
14
|
-
//# sourceMappingURL=node.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/query/node.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAWpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAK9E,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAC3B;AAiCD,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAC9D,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,EACpC,IAAI,CAAC,EAAE,WAAW,GACjB,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACxB,4DAA4D;AAC5D,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAA"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useNode (API §5 + §6) — ONE public symbol, overloaded: pass a `Schema` (+ type)
|
|
3
|
-
* for the typed `BoundNode` result, or a bare ref for the untyped `Node` result.
|
|
4
|
-
* Both forms ride the SAME memory shape — a typed read and its untyped twin are
|
|
5
|
-
* one cache entry, one liveness, one overlay. The runtime dispatches on the first
|
|
6
|
-
* argument; a given call site is always one form, so hook order is stable.
|
|
7
|
-
*/
|
|
8
|
-
import { useMemo } from 'react';
|
|
9
|
-
import { useNode as useNodeTyped } from '../../schema/bind-read.js';
|
|
10
|
-
import { useRead } from '../memory/read/read.js';
|
|
11
|
-
/**
|
|
12
|
-
* A `Schema` (from `defineSchema`) — its shape (`domain`/`classes`/`interfaces`)
|
|
13
|
-
* is disjoint from a `PathLike` (`string | Path`), so this cleanly routes the
|
|
14
|
-
* typed vs untyped overload at runtime.
|
|
15
|
-
*/
|
|
16
|
-
function isSchema(value) {
|
|
17
|
-
return (typeof value === 'object' &&
|
|
18
|
-
value !== null &&
|
|
19
|
-
'domain' in value &&
|
|
20
|
-
'classes' in value &&
|
|
21
|
-
'interfaces' in value);
|
|
22
|
-
}
|
|
23
|
-
/** One node by path — live, suspense-first; `null` ref is idle (§1.3). */
|
|
24
|
-
function useNodeUntyped(ref, opts) {
|
|
25
|
-
const r = useRead(ref, opts);
|
|
26
|
-
return useMemo(() => ({
|
|
27
|
-
pending: r.pending,
|
|
28
|
-
error: r.error,
|
|
29
|
-
live: r.live,
|
|
30
|
-
seq: r.seq,
|
|
31
|
-
refetch: r.refetch,
|
|
32
|
-
node: r.first,
|
|
33
|
-
}), [r]);
|
|
34
|
-
}
|
|
35
|
-
// The implementation signature returns an erased supertype of both result
|
|
36
|
-
// shapes — every overload above is assignable to it regardless of `BoundNode`
|
|
37
|
-
// variance; callers only ever see the precise overload return types.
|
|
38
|
-
export function useNode(a, b, c, d) {
|
|
39
|
-
if (isSchema(a)) {
|
|
40
|
-
return useNodeTyped(a, b, c, d);
|
|
41
|
-
}
|
|
42
|
-
return useNodeUntyped(a, b);
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { GatherBuilder, QueryASTInput, QuerySource } from '@astrale-os/kernel-client/graph';
|
|
2
|
-
import type { ReadState, Node, ReadOptions, Windowed } from '../memory/read/envelope.js';
|
|
3
|
-
export interface QueryResult extends ReadState, Windowed {
|
|
4
|
-
readonly nodes: readonly Node[];
|
|
5
|
-
readonly roots: readonly Node[];
|
|
6
|
-
readonly first: Node | null;
|
|
7
|
-
gathered(alias: string): {
|
|
8
|
-
readonly nodes: readonly Node[];
|
|
9
|
-
readonly first: Node | null;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/** A structured read — builder callback or AST value; `null` is idle (§1.3). */
|
|
13
|
-
export declare function useQuery(build: ((q: QuerySource) => GatherBuilder) | QueryASTInput | null | undefined, opts?: ReadOptions): QueryResult;
|
|
14
|
-
//# sourceMappingURL=query.hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.hook.d.ts","sourceRoot":"","sources":["../../../src/graph/query/query.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAShG,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAIxF,MAAM,WAAW,WAAY,SAAQ,SAAS,EAAE,QAAQ;IACtD,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,CAAA;CAC1F;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,GAAG,SAAS,EAC7E,IAAI,CAAC,EAAE,WAAW,GACjB,WAAW,CAiBb"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useQuery (API §5) — a structured read: a builder callback or an AST value;
|
|
3
|
-
* `null` is idle (§1.3). Rides the §1 envelope over the shared memory, projecting
|
|
4
|
-
* roots/first/nodes and the gathered-alias arms.
|
|
5
|
-
*/
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
import { useRead } from '../memory/read/read.js';
|
|
8
|
-
/** A structured read — builder callback or AST value; `null` is idle (§1.3). */
|
|
9
|
-
export function useQuery(build, opts) {
|
|
10
|
-
const r = useRead(build ?? null, opts);
|
|
11
|
-
return useMemo(() => ({
|
|
12
|
-
pending: r.pending,
|
|
13
|
-
error: r.error,
|
|
14
|
-
live: r.live,
|
|
15
|
-
seq: r.seq,
|
|
16
|
-
refetch: r.refetch,
|
|
17
|
-
nodes: r.nodes,
|
|
18
|
-
roots: r.roots,
|
|
19
|
-
first: r.first,
|
|
20
|
-
gathered: r.gathered,
|
|
21
|
-
more: r.more,
|
|
22
|
-
}), [r]);
|
|
23
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { OrderInput } from '@astrale-os/kernel-client/graph';
|
|
2
|
-
import type { LiveResult, ShapeInput } from '@astrale-os/kernel-client/store';
|
|
3
|
-
import type { Node } from '@astrale-os/kernel-core';
|
|
4
|
-
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
5
|
-
import { type AnyBoundNode, type BoundNode, type DefOf, type NodeRefInput, type SchemaBoundView, type TypeNames } from '@astrale-os/kernel-client';
|
|
6
|
-
import type { ReadOptions } from '../graph/memory/read/envelope.js';
|
|
7
|
-
import type { TypedChildrenResult, TypedNodeResult } from './types.js';
|
|
8
|
-
/** Bind one wire node as `type`; stable while the wire node, binding, and type hold. */
|
|
9
|
-
export declare function useBoundNode<S extends Schema, T extends TypeNames<S>>(binding: SchemaBoundView<S>, type: T, wire: Node | null | undefined): BoundNode<DefOf<S, T>, S> | null;
|
|
10
|
-
/**
|
|
11
|
-
* Bind many wire nodes as `type`; per-node identity + a stable array on no
|
|
12
|
-
* change. `skipMismatch` drops nodes whose class is not `type` (a mixed-class
|
|
13
|
-
* child set) instead of throwing.
|
|
14
|
-
*/
|
|
15
|
-
export declare function useBoundNodes<S extends Schema, T extends TypeNames<S>>(binding: SchemaBoundView<S>, type: T, wires: readonly Node[], skipMismatch?: boolean): readonly BoundNode<DefOf<S, T>, S>[];
|
|
16
|
-
/** Bind many wire nodes classlessly (traversal endpoints); per-node + stable array. */
|
|
17
|
-
export declare function useBoundEndpoints<S extends Schema>(binding: SchemaBoundView<S>, wires: readonly Node[]): readonly AnyBoundNode<S>[];
|
|
18
|
-
/** Base read options plus the window growth mode (a `useChildren`-specific extra). */
|
|
19
|
-
export type ShapeOptions = ReadOptions & {
|
|
20
|
-
window?: 'append' | 'paged';
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Subscribe to a memory shape. `null` shape → idle (`null`, no I/O). A cold
|
|
24
|
-
* shape suspends unless `suspend: false`. The returned `LiveResult` is the
|
|
25
|
-
* unified read envelope — callers project `node`/`children`/`nodes`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function useShape(shape: ShapeInput | null | undefined, opts?: ShapeOptions): LiveResult | null;
|
|
28
|
-
export declare function useNode<S extends Schema, T extends TypeNames<S>>(schema: S, type: T, ref: NodeRefInput | null | undefined, opts?: ReadOptions): TypedNodeResult<S, T>;
|
|
29
|
-
export declare function useChildren<S extends Schema, T extends TypeNames<S>>(parent: AnyBoundNode<S> | null | undefined, opts: ReadOptions & {
|
|
30
|
-
type: T;
|
|
31
|
-
order?: OrderInput;
|
|
32
|
-
limit?: number;
|
|
33
|
-
window?: 'append' | 'paged';
|
|
34
|
-
}): TypedChildrenResult<S, T>;
|
|
35
|
-
/** Recover the schema a BoundNode was bound under; a clear error if it is untagged. */
|
|
36
|
-
export declare function requireSchema(node: object): Schema;
|
|
37
|
-
//# sourceMappingURL=bind-read.d.ts.map
|