@opetope/react 0.12.3 → 0.14.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.
- package/CHANGELOG.md +28 -0
- package/dist/contribution-frame-Bh104T5Z.js +2 -0
- package/dist/contribution-frame-Bh104T5Z.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model-hook.d.ts +1 -1
- package/dist/model-selection-snapshot.d.ts +6 -4
- package/dist/model-selection-store.d.ts +2 -2
- package/dist/resource-command.d.ts +4 -4
- package/dist/resource-hook.d.ts +2 -2
- package/dist/testing.js +1 -1
- package/package.json +5 -5
- package/dist/contribution-frame-CCKnOxZR.js +0 -2
- package/dist/contribution-frame-CCKnOxZR.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @opetope/react
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 712352a: Use one model-selection `read` for ordinary readables and resource views. Reading a view carries its demand until the committed selection changes or unmounts; `read(view.observe())` remains passive. Remove the former selection `acquire` method.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 712352a: Keep the whole `useModel` selection result referentially stable across committed renders when its exposed fields and ordered keys are unchanged. Inline selectors can pass the result directly to memoized children and effects; source subscriptions and resource demand still follow the committed selection.
|
|
12
|
+
- @opetope/core@0.14.0
|
|
13
|
+
- @opetope/runtime@0.14.0
|
|
14
|
+
|
|
15
|
+
## 0.13.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 6666ec4: Make Resource demand explicit through `ResourceView`: consumer-lifetime resources and their derived values expose
|
|
20
|
+
passive `observe()` and leased `acquire()`, while owner-lifetime resources remain ordinary readable state. Add
|
|
21
|
+
scope-bound model and commit-bound React acquisition, stateful resource projections, lazy consumer sources, and the
|
|
22
|
+
matching inspection protocol update. Replace the retired `lease` lifetime with `consumers` and publish
|
|
23
|
+
`ConsumerResource` for declarations that follow consumer demand.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [6666ec4]
|
|
28
|
+
- @opetope/core@0.13.0
|
|
29
|
+
- @opetope/runtime@0.13.0
|
|
30
|
+
|
|
3
31
|
## 0.12.3
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as m}from"react/jsx-runtime";import{useContext as V,createContext as D,useCallback as S,useRef as O,useMemo as p,useSyncExternalStore as k,useEffect as N,useInsertionEffect as A,useLayoutEffect as w,memo as W,useState as K}from"react";import{reportDetachedError as C,compatibleAbortReason as _,isCallTarget as G,isModel as H,isReadable as j,isResourceView as F,createLifetimeController as J,createCallController as Q,getContributionOwner as U,createState as X,createAggregateError as Y}from"@opetope/core/internal";import{isResourceValue as Z,reportRuntimeFailure as ee,requireContributionModelPlans as te,openContributionModels as ne}from"@opetope/runtime/internal";import{C as u,u as re,b as ie}from"./contribution-isolation-Bzfbt4iM.js";import{CommandError as oe}from"@opetope/core";const x=D(void 0);function se(){const t=V(x);if(t===void 0)throw new u("missing","Opetope hook was called outside a contribution mount.");return t}function y(t){return Z(t)}function ae(t,e){return new Promise((n,r)=>{const i=()=>{r(new oe("cancelled","Resource operation wait was cancelled.",_(e)))};if(e.aborted){i();return}e.addEventListener("abort",i,{once:!0}),t.then(o=>{e.removeEventListener("abort",i),n(o)},o=>{e.removeEventListener("abort",i),r(o)})})}function ce(t,e){var r;const n=(r=e==null?void 0:e.onSuccess)==null?void 0:r.call(e,t);return n!==void 0&&Promise.resolve(n).catch(C),t}function v(t){return{run:(e,n)=>{let r;try{r=Promise.resolve(t())}catch(o){return Promise.reject(o)}const i=n==null?void 0:n.signal;return(i===void 0?r:ae(r,i)).then(o=>ce(o,n))}}}const de=Object.freeze({kind:"skipped",reason:"resource-not-ready"});function ue(t){const e=t.pagination;if(!(typeof e!="object"||e===null))return e}function E(t){return{loadNext:v(()=>{const e=t.pagination;return e===void 0?Promise.resolve(de):e.loadNext()}),refresh:v(()=>t.refresh()),reset:v(()=>t.reset()),retry:v(()=>t.retry())}}function le(t,e){const n=e.get(t);if(n!==void 0)return n;const r=E(t);return e.set(t,r),r}const fe=t=>t;function z(t,e,n){const r=e,i=(n==null?void 0:n.equals)??Object.is,o=S(d=>t.subscribe(d),[t]),c=O(void 0);let s=c.current;s===void 0&&(s={hasValue:!1,value:void 0},c.current=s);const a=p(()=>{let d=!1,h,f;return()=>{const b=t.getSnapshot();if(d&&Object.is(h,b))return f;const g=r(b);if(!d){let R=g;return s.hasValue&&i(s.value,g)&&(R=s.value),d=!0,h=b,f=R,f}return i(f,g)?(h=b,f):(h=b,f=g,f)}},[s,i,t,r]),l=k(o,a,a);return N(()=>{s.hasValue=!0,s.value=l},[s,l]),l}function I(t){return z(t,fe)}const M=new WeakMap;function $(t){if(arguments.length>1)throw new u("binding-invalid","Command follows the target it binds; binding options are forbidden.");if(!G(t))throw new u("binding-invalid","Command target is not authentic.");return M.set(t,{target:t}),t}function he(t){const e=M.get(t);if(e===void 0)throw new u("binding-invalid","Command binding is not authentic.");return e}function L(t){return typeof t=="object"&&t!==null&&M.has(t)}const me=Symbol("opetope.model-binding"),be=Symbol("opetope.model-binding-identity"),pe=Object.freeze({}),q=new WeakMap;function ge(t,e,n){if(typeof n!="string")throw new u("binding-invalid",`Model ${t.id} accepts only string fields.`);const r=Object.getOwnPropertyDescriptor(e,n);if((r==null?void 0:r.enumerable)!==!0||!("value"in r))throw new u("binding-invalid",`Model ${t.id}.${n} requires an enumerable data binding.`);return r.value}function we(t){return j(t)||y(t)||F(t)||typeof t=="function"}function Ce(t,e){const n=[],r=Reflect.ownKeys(e);if(r.length===0)throw new u("binding-invalid",`Model ${t.id} requires at least one field.`);for(const i of r){const o=ge(t,e,i);if(!we(o)){if(!L(o))throw new u("binding-invalid",`Model ${t.id}.${String(i)} requires a Readable, a Resource, a ResourceView or a bound command.`);n.push(o)}}return Object.freeze(n)}function B(t,e){if(!H(t))throw new u("binding-invalid","Model declaration is not authentic.");if(typeof e!="object"||e===null)throw new u("binding-invalid",`Model ${t.id} requires a record binding.`);const n=Ce(t,e),r=Object.freeze({[me]:pe,[be]:!0});return q.set(r,{commands:n,declaration:t,model:e}),r}function ve(t){const e=q.get(t);if(e===void 0)throw new u("binding-invalid","Model binding is not authentic.");return e}let ye=0;function Me(t){const e=new Map,n=[],r=new Set;for(const i of t){const o=ve(i);if(e.has(o.declaration))throw new u("duplicate",`Model ${o.declaration.id} is bound twice in one mount.`);e.set(o.declaration,o.model);for(const c of o.commands)r.has(c)||(r.add(c),n.push(c))}return{commands:Object.freeze(n),frame:{commandRecords:new Map,models:e}}}class Re{frame;authority;boundCommands;closeTicket=0;isActive;lifetime;onClose;released=!1;rendererAttached=!1;renderListeners=new Set;state="detached";constructor(e,n){const r=++ye;this.lifetime=J({id:`contribution.${String(r)}`}),this.isActive=n==null?void 0:n.isActive,this.onClose=n==null?void 0:n.onClose;const{commands:i,frame:o}=Me(e);this.frame=o,this.boundCommands=i,this.buildCommandRecords(r)}attach(){if(this.state==="closing")return this.closeTicket+=1,this.state="active",this.rendererAttached=!0,!0;if(this.state==="closed")return!1;if(this.state==="active")throw new u("duplicate","One contribution mount cannot mount twice.");const e=this.createAuthority(this.lifetime.open());try{for(const n of this.frame.commandRecords.values())n.controller.activate()}catch(n){throw this.authority=e,this.state="active",this.close(),n}return this.authority=e,this.rendererAttached=!0,this.state="active",!0}close(){if(this.state==="closed")return;this.state="closed",this.closeTicket+=1,this.lifetime.close(),this.authority=void 0;for(const n of this.frame.commandRecords.values())n.controller.close();const e=this.onClose;this.onClose=void 0,e==null||e(),this.publishRenderable(),this.rendererAttached||this.releaseFrame()}detach(){if(!this.rendererAttached)return;if(this.rendererAttached=!1,this.state==="closed"){this.releaseFrame();return}if(this.state!=="active")return;this.state="closing";const e=++this.closeTicket;queueMicrotask(()=>{this.state==="closing"&&e===this.closeTicket&&this.close()})}diagnostics(){const e=[...this.frame.commandRecords.values()].map(n=>n.controller.diagnostics());return Object.freeze({active:this.state==="active",calls:Object.freeze(e),commandRecords:this.frame.commandRecords.size,models:this.frame.models.size})}getRenderableSnapshot=()=>this.state!=="closed"&&(this.isActive===void 0||this.isActive());releaseClosedFrame(){this.state==="closed"&&this.releaseFrame()}subscribeRenderable=e=>{if(this.state==="closed")return()=>{};const n={listener:e};this.renderListeners.add(n);let r=!0;return()=>{r&&(r=!1,this.renderListeners.delete(n))}};buildCommandRecords(e){let n=0;for(const r of this.boundCommands){he(r);const i=Q(r,{captureAuthority:this.captureAuthority,id:`contributionCommand.${String(e)}.${String(++n)}`,scheduling:{policy:"parallel"}});this.frame.commandRecords.set(r,{controller:i,invoker:Object.freeze({run:i.run})})}}captureAuthority=()=>{const e=this.authority;if(this.state!=="active"||e===void 0)throw new u("inactive","Contribution mount is not active.");return e.assertCurrent(),e};createAuthority(e){return Object.freeze({assertCurrent:()=>{if(this.state!=="active")throw new u("inactive","Contribution mount is not active.");e.assertCurrent()},isCurrent:()=>this.state==="active"&&e.isCurrent()})}publishRenderable(){for(const{listener:e}of[...this.renderListeners])try{e()}catch(n){C(n)}}releaseFrame(){this.released||(this.released=!0,this.frame.commandRecords.clear(),this.frame.models.clear(),this.boundCommands=[],this.renderListeners.clear())}}function Se({children:t,mount:e}){const n=k(e.subscribeRenderable,e.getRenderableSnapshot,e.getRenderableSnapshot);return A(()=>{if(e.attach())return()=>e.detach()},[e]),w(()=>{n||e.releaseClosedFrame()},[e,n]),n?m(x,{value:e.frame,children:t}):null}function P(t){const e=t.bundle;t.bundle=void 0,e==null||e.frame.close()}function Oe(t,e){if(typeof e!="object"||e===null)return B(t,e);const n=i=>j(i)||y(i)||F(i)||typeof i=="function"||L(i),r=Object.entries(e).map(([i,o])=>[i,n(o)?o:$(o)]);return B(t,Object.fromEntries(r))}function ke(t){return U(t)}const Ae={models:[]};function T(t,e){try{t()}catch(n){throw Y([e,n],"Contribution mount setup and cleanup failed.",{cause:e})}throw e}function je(t,e,n,r){const i=X(e),{models:o,reporter:c}=r??Ae;try{const s=te(t.models),a=s.length===0?void 0:ne(s,i,c);return{bundle:a,models:[...o,...(a==null?void 0:a.models)??[],...n],props:i}}catch(s){return T(i.close,s)}}function Fe(t,e,n,r){const{bundle:i,models:o,props:c}=je(t,e,n,r);let s=!1;const a=()=>{if(!s){s=!0;try{i==null||i.close().catch(C)}finally{c.close()}}};try{return{frame:new Re(o.map(([d,h])=>Oe(d,h)),{isActive:()=>!s,onClose:a}),isOpen:()=>!s,props:c}}catch(l){return T(a,l)}}function xe(t,e){return m(t,{...e})}function Ee({bundle:t,contribution:e}){const n=I(t.props),r=p(()=>e.props===void 0?n:e.props(n),[n,e]);return m(Se,{mount:t.frame,children:xe(e.Component,r)})}function ze({authority:t,contribution:e,fixtures:n,slotProps:r}){const i=p(()=>({authority:t,bundle:void 0,contribution:e,fixtures:n,retired:!1}),[t,e,n]),[o,c]=K(void 0),s=(o==null?void 0:o.owner)===i?o.bundle:void 0,a=O(r);return w(()=>{a.current=r}),A(()=>()=>{i.retired=!0,queueMicrotask(()=>{try{P(i)}catch(l){C(l)}})},[i]),w(()=>{const l=i.bundle??(i.bundle=Fe(i.contribution,a.current,i.fixtures??[],i.authority));return c(d=>(d==null?void 0:d.owner)===i?d:{bundle:l,owner:i}),()=>{i.retired&&P(i)}},[i]),w(()=>{(s==null?void 0:s.isOpen())===!0&&s.props.set(r)},[s,r]),s===void 0?null:m(Ee,{bundle:s,contribution:e})}function Ie(t){const{authority:e,contribution:n,contributionId:r,fixtures:i,targetId:o}=t,c=re(),s=p(()=>({authority:e,contribution:n,fixtures:i}),[e,n,i]),a=e==null?void 0:e.feature,l=p(()=>({contribution:r,feature:a,target:o}),[r,a,o]),d=e==null?void 0:e.reporter,h=S(f=>ee(f,d),[d]);return m(ie,{content:c,identity:s,report:h,source:l,children:m(ze,{...t})})}const $e=W(Ie);export{$e as M,I as a,ke as b,E as c,z as d,$ as e,y as i,ue as p,le as r,se as u};
|
|
2
|
+
//# sourceMappingURL=contribution-frame-Bh104T5Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contribution-frame-Bh104T5Z.js","sources":["../src/mount-context.tsx","../src/resource-command.ts","../src/readable-hooks.ts","../src/command.ts","../src/model-binding.ts","../src/mount-frame.ts","../src/mount-provider.tsx","../src/contribution-frame.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport { ContributionError } from './errors';\nimport type { Frame } from './mount-frame';\n\nconst FrameContext = createContext<Frame | undefined>(undefined);\n\nfunction useFrame(): Frame {\n const frame = useContext(FrameContext);\n\n if (frame === undefined) {\n throw new ContributionError('missing', 'Opetope hook was called outside a contribution mount.');\n }\n\n return frame;\n}\n\nexport { FrameContext, useFrame };\n","/**\n * D359: the verbs of a Resource, dressed as the commands a button already knows, and the recognition that answers\n * «is this selected field a Resource». A consumer keeps a status — `inFlight` until the operation settles, the\n * settled `outcome` — while the Resource stays owned by the model that declared it: cancelling this wait cancels the\n * wait and not the load.\n */\n\nimport { CommandError } from '@opetope/core';\nimport type {\n PaginationOutcome,\n PaginationState,\n Resource,\n ResourceOperationOutcome,\n ResourcePagination,\n ResourceState,\n} from '@opetope/core';\nimport { compatibleAbortReason, reportDetachedError } from '@opetope/core/internal';\nimport type { CallRunOptions, ResourceKey } from '@opetope/core/internal';\nimport { isResourceValue } from '@opetope/runtime/internal';\n\nimport type { CommandHook } from './command-hook';\nimport type { CommandInvoker } from './command-hook-controller';\n\n/**\n * D439: the widest Resource, and the name says so. `Resource<never, ResourceKey>` said the opposite in both\n * arguments — `never` is the narrowest `Data` a reader can be handed and a named `Key` *requires* `state.key`, so\n * hardly any member of the family fitted it. Nothing was refused, because every value reaches this name through a\n * cast, which is exactly why the name could drift. `ResourceKeyField<never>` requires no field, so\n * `Resource<unknown, never, 'consumers' | 'owner'>` is the one form every Resource satisfies — keyed or not, paginated or not.\n */\ntype AnyResource = Resource<unknown, never, 'consumers' | 'owner'>;\n\n/**\n * D349, D359: a Resource is a structural contract a host may implement with an ordinary object, so the question the\n * type of a selected field asked is answered by the runtime that owns it — the registry of the materializations it\n * built, and the structural contract for everything else. Asking it here a second time would let the two answers\n * drift, and a host adapter typed as a hook reaches the render where `state` is `undefined` and `refresh.run()`\n * throws.\n */\nfunction isResource(value: unknown): boolean {\n return isResourceValue(value);\n}\n\n/** D356: the nested capability, with `loadNext` as a command and the projected pagination state beside it. */\ntype ResourcePaginationHook<Cursor extends ResourceKey> = Readonly<{\n loadNext: CommandHook<void, PaginationOutcome<Cursor>>;\n state: PaginationState<Cursor>;\n}>;\n\n/**\n * D359: what `useResource` answers, and what a field of a `useModel` selection whose value is a Resource answers.\n * The verbs never reject (a Resource answers an outcome), so the ordinary path of `outcome` is\n * `{ kind: 'ok', value }`; `failed` stays in the type because the controller turns a synchronous throw of an\n * invoker into it, and the wrapper below carries its own test that it never throws synchronously.\n */\ntype ResourceHook<Data, Key extends ResourceKey = never> = Readonly<{\n /** Present when the declaration carried `pagination`; `undefined` for every other Resource. */\n pagination: ResourcePaginationHook<ResourceKey> | undefined;\n refresh: CommandHook<void, ResourceOperationOutcome>;\n reset: CommandHook<void, ResourceOperationOutcome>;\n retry: CommandHook<void, ResourceOperationOutcome>;\n state: ResourceState<Data, Key>;\n}>;\n\ntype PaginatedResourceHook<Data, Key extends ResourceKey, Cursor extends ResourceKey> = Omit<\n ResourceHook<Data, Key>,\n 'pagination'\n> &\n Readonly<{ pagination: ResourcePaginationHook<Cursor> }>;\n\ntype ResourceInvokers = Readonly<{\n loadNext: CommandInvoker;\n refresh: CommandInvoker;\n reset: CommandInvoker;\n retry: CommandInvoker;\n}>;\n\n/** The consumer's own cancellation: it ends this wait, and the work the model owns keeps running. */\nfunction awaitCancellable(operation: Promise<unknown>, signal: AbortSignal): Promise<unknown> {\n return new Promise<unknown>((resolve, reject) => {\n const cancel = (): void => {\n reject(new CommandError('cancelled', 'Resource operation wait was cancelled.', compatibleAbortReason(signal)));\n };\n\n if (signal.aborted) {\n cancel();\n\n return;\n }\n\n signal.addEventListener('abort', cancel, { once: true });\n operation.then(\n value => {\n signal.removeEventListener('abort', cancel);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', cancel);\n reject(error);\n },\n );\n });\n}\n\nfunction notifySuccess(value: unknown, options: CallRunOptions<unknown> | undefined): unknown {\n const notification = options?.onSuccess?.(value);\n\n // The failure of a consumer's own callback is detached from the operation it watched, as it is for a command.\n if (notification !== undefined) void Promise.resolve(notification).catch(reportDetachedError);\n\n return value;\n}\n\n/**\n * The invariant of this wrapper: it never throws synchronously, so the `failed` outcome a consumer can see is the one\n * the verb itself produced and never one this layer invented in the middle of a render commit.\n */\nfunction operationInvoker(start: () => Promise<unknown>): CommandInvoker {\n return {\n run: (_input: never, options?: CallRunOptions<unknown>): Promise<unknown> => {\n let operation: Promise<unknown>;\n\n try {\n operation = Promise.resolve(start());\n } catch (error) {\n return Promise.reject(error);\n }\n\n const signal = options?.signal;\n\n return (signal === undefined ? operation : awaitCancellable(operation, signal)).then(value =>\n notifySuccess(value, options),\n );\n },\n };\n}\n\n/** A Resource without the capability still answers a `loadNext` invoker, so the hook count never moves. */\nconst unavailablePage: PaginationOutcome<ResourceKey> = Object.freeze({\n kind: 'skipped',\n reason: 'resource-not-ready',\n});\n\nfunction paginationOf(resource: AnyResource): ResourcePagination<ResourceKey, 'consumers' | 'owner'> | undefined {\n const capability = (resource as { readonly pagination?: unknown }).pagination;\n\n if (typeof capability !== 'object' || capability === null) return undefined;\n\n return capability as ResourcePagination<ResourceKey, 'consumers' | 'owner'>;\n}\n\n/**\n * One set per Resource identity. `selectEntry` and `useCommandSlot` both pick their controller by the identity of the\n * invoker, so a set rebuilt on every render would reset `inFlight`, drop `outcome` and change `run` — which is why it\n * is memoised against the Resource itself and never assembled during a render.\n */\nfunction createResourceInvokers(resource: AnyResource): ResourceInvokers {\n // D349: a Resource is a structural contract, so every verb is called through it and never as a detached function.\n return {\n loadNext: operationInvoker(() => {\n const capability = (resource as { readonly pagination?: { loadNext(): Promise<unknown> } }).pagination;\n\n return capability === undefined ? Promise.resolve(unavailablePage) : capability.loadNext();\n }),\n refresh: operationInvoker(() => resource.refresh()),\n reset: operationInvoker(() => resource.reset()),\n retry: operationInvoker(() => resource.retry()),\n };\n}\n\nfunction resourceInvokers(resource: AnyResource, cache: WeakMap<object, ResourceInvokers>): ResourceInvokers {\n const existing = cache.get(resource);\n\n if (existing !== undefined) return existing;\n\n const invokers = createResourceInvokers(resource);\n cache.set(resource, invokers);\n\n return invokers;\n}\n\n/**\n * The one module of this package that talks to the runtime about a materialization, so the rest of React reads the\n * recognition and the key type from here instead of routing to `@opetope/runtime/internal` of its own.\n */\nexport { createResourceInvokers, isResource, paginationOf, resourceInvokers };\nexport type { AnyResource, PaginatedResourceHook, ResourceHook, ResourceInvokers, ResourceKey, ResourcePaginationHook };\n","import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Readable } from '@opetope/core';\nimport type { EqualityOption } from '@opetope/core/internal';\n\nconst identity = <Value>(value: Value): Value => value;\n\n/**\n * D364: what this mount answered last, and nothing about closes. A source whose owner retired stops instead of\n * refusing — it keeps answering its last value — so a render that races a retirement shows its last frame and\n * unmounts (G13) without the reader having to remember anything for it.\n */\ninterface SelectionInstance<Selected> {\n hasValue: boolean;\n value: Selected | undefined;\n}\n\n/**\n * D279: the source and the selection are positional; `equals` is the one modifier, spelled as in Core — including\n * D348's rule for where the comparator is read, so a named non-generic one compiles here as it does in `derive`.\n */\nexport function useSelector<Value, Selected>(\n readable: Readable<Value>,\n select: (value: NoInfer<Value>) => Selected,\n options?: { readonly equals?: EqualityOption<NoInfer<Selected>> },\n): Selected {\n const selector = select;\n const isEqual = options?.equals ?? Object.is;\n const subscribe = useCallback((listener: () => void) => readable.subscribe(listener), [readable]);\n const instanceRef = useRef<SelectionInstance<Selected> | undefined>(undefined);\n let instance = instanceRef.current;\n\n if (instance === undefined) {\n instance = { hasValue: false, value: undefined };\n instanceRef.current = instance;\n }\n\n const getSelectedSnapshot = useMemo(() => {\n let initialized = false;\n let sourceSnapshot: Value;\n let selectedSnapshot: Selected;\n\n return (): Selected => {\n const nextSource = readable.getSnapshot();\n\n if (initialized && Object.is(sourceSnapshot, nextSource)) return selectedSnapshot;\n\n const nextSelected = selector(nextSource);\n\n if (!initialized) {\n let nextSelectedSnapshot = nextSelected;\n\n if (instance.hasValue && isEqual(instance.value, nextSelected)) {\n nextSelectedSnapshot = instance.value as Selected;\n }\n\n initialized = true;\n sourceSnapshot = nextSource;\n selectedSnapshot = nextSelectedSnapshot;\n\n return selectedSnapshot;\n }\n\n if (isEqual(selectedSnapshot, nextSelected)) {\n sourceSnapshot = nextSource;\n\n return selectedSnapshot;\n }\n\n sourceSnapshot = nextSource;\n selectedSnapshot = nextSelected;\n\n return selectedSnapshot;\n };\n }, [instance, isEqual, readable, selector]);\n\n const selected = useSyncExternalStore(subscribe, getSelectedSnapshot, getSelectedSnapshot);\n\n useEffect(() => {\n instance.hasValue = true;\n instance.value = selected;\n }, [instance, selected]);\n\n return selected;\n}\n\nexport function useReadable<Value>(readable: Readable<Value>): Value {\n return useSelector(readable, identity);\n}\n","import type { Command } from '@opetope/core';\nimport { isCallTarget } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\n\n/**\n * A bound command is the authentic `Command` the model field declares, so the common path adds no wrapper. Observable\n * call state belongs to the model as a `Readable` field (D71), so a binding carries no mode.\n */\ntype CommandBindingIdentity = Command<never, unknown>;\ntype CommandBinding<Input, Output> = Command<Input, Output>;\n\ntype CommandOutcome<Output> =\n | { readonly error: unknown; readonly kind: 'failed' }\n | { readonly reason: unknown; readonly kind: 'cancelled' }\n | { readonly kind: 'ok'; readonly value: Output };\n\ntype AnyCommandBinding = CommandBinding<never, unknown>;\n\ntype CommandBindingDefinition<Input, Output> = {\n readonly target: Command<Input, Output>;\n};\n\nconst bindingDefinitions = new WeakMap<CommandBindingIdentity, CommandBindingDefinition<never, unknown>>();\n\nfunction bindCommand<Input, Output>(target: Command<Input, Output>): CommandBinding<Input, Output> {\n if (arguments.length > 1) {\n throw new ContributionError(\n 'binding-invalid',\n 'Command follows the target it binds; binding options are forbidden.',\n );\n }\n\n if (!isCallTarget(target)) throw new ContributionError('binding-invalid', 'Command target is not authentic.');\n\n bindingDefinitions.set(target, { target });\n\n return target;\n}\n\nfunction getCommandBindingDefinition<Input, Output>(\n binding: Command<Input, Output>,\n): CommandBindingDefinition<Input, Output> {\n const definition = bindingDefinitions.get(binding);\n\n if (definition === undefined) throw new ContributionError('binding-invalid', 'Command binding is not authentic.');\n\n return definition as CommandBindingDefinition<Input, Output>;\n}\n\nfunction isCommandBinding(value: unknown): value is AnyCommandBinding {\n return typeof value === 'object' && value !== null && bindingDefinitions.has(value as CommandBindingIdentity);\n}\n\nexport { bindCommand, getCommandBindingDefinition, isCommandBinding };\nexport type { CommandOutcome };\n","import type { Command, ModelOf } from '@opetope/core';\nimport { isModel, isReadable, isResourceView } from '@opetope/core/internal';\nimport type { ExactKeys, ModelIdentity } from '@opetope/core/internal';\n\nimport { isCommandBinding } from './command';\nimport { ContributionError } from './errors';\nimport { isResource } from './resource-command';\n\nconst modelBindingBrand = Symbol('opetope.model-binding');\nconst modelBindingIdentityBrand = Symbol('opetope.model-binding-identity');\nconst modelBindingMarker = Object.freeze({});\n\ntype AnyModel = ModelIdentity;\ntype AnyCommand = Command<never, unknown>;\n\ninterface ModelBindingIdentity {\n readonly [modelBindingIdentityBrand]: true;\n}\n\ninterface ModelBinding<Declaration extends AnyModel> extends ModelBindingIdentity {\n readonly [modelBindingBrand]: (declaration: Declaration) => Declaration;\n}\n\ntype ModelBindingMetadata = {\n readonly commands: readonly AnyCommand[];\n readonly declaration: AnyModel;\n readonly model: object;\n};\n\nconst registry = new WeakMap<ModelBindingIdentity, ModelBindingMetadata>();\n\n/**\n * The declaration carries the field shape in its type; binding also validates fields supplied by host code.\n * ResourceViews travel unchanged, so observing a model never acquires its dependencies.\n */\nfunction modelFieldValue(declaration: AnyModel, model: object, field: PropertyKey): unknown {\n if (typeof field !== 'string') {\n throw new ContributionError('binding-invalid', `Model ${declaration.id} accepts only string fields.`);\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(model, field);\n\n if (descriptor?.enumerable !== true || !('value' in descriptor)) {\n throw new ContributionError(\n 'binding-invalid',\n `Model ${declaration.id}.${field} requires an enumerable data binding.`,\n );\n }\n\n return descriptor.value;\n}\n\nfunction isObservedField(value: unknown): boolean {\n return isReadable(value) || isResource(value) || isResourceView(value) || typeof value === 'function';\n}\n\nfunction snapshotModelFields(declaration: AnyModel, model: object): readonly AnyCommand[] {\n const commands: AnyCommand[] = [];\n const fields = Reflect.ownKeys(model);\n\n if (fields.length === 0)\n throw new ContributionError('binding-invalid', `Model ${declaration.id} requires at least one field.`);\n\n for (const field of fields) {\n const value = modelFieldValue(declaration, model, field);\n\n // D349: a Resource is a field a model publishes, and it is not a `Readable`, so it is recognised by name.\n if (isObservedField(value)) continue;\n\n if (!isCommandBinding(value)) {\n throw new ContributionError(\n 'binding-invalid',\n `Model ${declaration.id}.${String(field)} requires a Readable, a Resource, a ResourceView or a bound command.`,\n );\n }\n\n commands.push(value);\n }\n\n return Object.freeze(commands);\n}\n\nfunction bindModel<Declaration extends AnyModel, const Keys extends PropertyKey = never>(\n declaration: Declaration,\n model: ExactKeys<Keys, ModelOf<Declaration>> & ModelOf<Declaration>,\n): ModelBinding<Declaration> {\n if (!isModel(declaration)) throw new ContributionError('binding-invalid', 'Model declaration is not authentic.');\n\n if (typeof model !== 'object' || model === null) {\n throw new ContributionError('binding-invalid', `Model ${declaration.id} requires a record binding.`);\n }\n\n const commands = snapshotModelFields(declaration, model);\n const binding = Object.freeze({\n [modelBindingBrand]: modelBindingMarker as unknown as (value: Declaration) => Declaration,\n [modelBindingIdentityBrand]: true as const,\n });\n registry.set(binding, { commands, declaration, model });\n\n return binding;\n}\n\nfunction getModelBindingMetadata(binding: ModelBindingIdentity): ModelBindingMetadata {\n const metadata = registry.get(binding);\n\n if (metadata === undefined) throw new ContributionError('binding-invalid', 'Model binding is not authentic.');\n\n return metadata;\n}\n\nexport { bindModel, getModelBindingMetadata };\nexport type { AnyCommand, AnyModel, ModelBindingIdentity };\n","import type {\n CallAuthority,\n CallController,\n CallDiagnostics,\n CallRunOptions,\n LifetimeLease,\n} from '@opetope/core/internal';\nimport { createCallController, createLifetimeController, reportDetachedError } from '@opetope/core/internal';\n\nimport { getCommandBindingDefinition } from './command';\nimport { ContributionError } from './errors';\nimport { getModelBindingMetadata } from './model-binding';\nimport type { AnyCommand, AnyModel, ModelBindingIdentity } from './model-binding';\n\ntype RuntimeCommandInvoker = {\n readonly run: (input: never, options?: CallRunOptions<unknown>) => Promise<unknown>;\n};\n\ntype CommandRecord = {\n readonly controller: CallController<never, unknown>;\n readonly invoker: RuntimeCommandInvoker;\n};\n\n/** What a mounted contribution grants its components: the models it may read and the commands it may invoke. */\ntype Frame = {\n readonly commandRecords: Map<AnyCommand, CommandRecord>;\n readonly models: Map<AnyModel, unknown>;\n};\n\ntype MountFrameLifecycle = {\n readonly isActive: () => boolean;\n readonly onClose: () => void;\n};\n\ntype MountFrameDiagnostics = {\n readonly active: boolean;\n readonly calls: readonly CallDiagnostics[];\n readonly commandRecords: number;\n readonly models: number;\n};\n\nlet nextMountId = 0;\n\nfunction buildFrame(supplied: readonly ModelBindingIdentity[]): {\n readonly commands: readonly AnyCommand[];\n readonly frame: Frame;\n} {\n const models = new Map<AnyModel, unknown>();\n const commands: AnyCommand[] = [];\n const bound = new Set<AnyCommand>();\n\n for (const candidate of supplied) {\n const binding = getModelBindingMetadata(candidate);\n\n if (models.has(binding.declaration)) {\n throw new ContributionError('duplicate', `Model ${binding.declaration.id} is bound twice in one mount.`);\n }\n\n models.set(binding.declaration, binding.model);\n\n for (const command of binding.commands) {\n // D197: one Command is one command of the mount, however many fields of the models name it. A second name is an\n // alias, not a second command, so it shares the record, the activation and the fence.\n if (bound.has(command)) continue;\n\n bound.add(command);\n commands.push(command);\n }\n }\n\n return { commands: Object.freeze(commands), frame: { commandRecords: new Map(), models } };\n}\n\n/**\n * The lifetime of one mounted contribution. `attach` claims it for the renderer, `detach` schedules the close on the\n * next microtask so a StrictMode remount reuses the same mount, and `close` fences every command it granted (D85).\n */\nclass MountFrameImpl {\n readonly frame: Frame;\n private authority: CallAuthority | undefined;\n private boundCommands: readonly AnyCommand[];\n private closeTicket = 0;\n private readonly isActive: (() => boolean) | undefined;\n private readonly lifetime: ReturnType<typeof createLifetimeController>;\n private onClose: (() => void) | undefined;\n private released = false;\n private rendererAttached = false;\n private readonly renderListeners = new Set<{ readonly listener: () => void }>();\n private state: 'active' | 'closed' | 'closing' | 'detached' = 'detached';\n\n constructor(models: readonly ModelBindingIdentity[], lifecycle?: MountFrameLifecycle) {\n const mountId = ++nextMountId;\n this.lifetime = createLifetimeController({ id: `contribution.${String(mountId)}` });\n this.isActive = lifecycle?.isActive;\n this.onClose = lifecycle?.onClose;\n const { commands, frame } = buildFrame(models);\n this.frame = frame;\n this.boundCommands = commands;\n this.buildCommandRecords(mountId);\n }\n\n attach(): boolean {\n if (this.state === 'closing') {\n this.closeTicket += 1;\n this.state = 'active';\n this.rendererAttached = true;\n\n return true;\n }\n\n if (this.state === 'closed') return false;\n\n if (this.state === 'active') throw new ContributionError('duplicate', 'One contribution mount cannot mount twice.');\n\n const authority = this.createAuthority(this.lifetime.open());\n\n try {\n for (const record of this.frame.commandRecords.values()) record.controller.activate();\n } catch (error) {\n this.authority = authority;\n this.state = 'active';\n this.close();\n\n throw error;\n }\n\n this.authority = authority;\n this.rendererAttached = true;\n this.state = 'active';\n\n return true;\n }\n\n close(): void {\n if (this.state === 'closed') return;\n\n this.state = 'closed';\n this.closeTicket += 1;\n this.lifetime.close();\n this.authority = undefined;\n\n for (const record of this.frame.commandRecords.values()) record.controller.close();\n\n const onClose = this.onClose;\n this.onClose = undefined;\n onClose?.();\n this.publishRenderable();\n\n if (!this.rendererAttached) this.releaseFrame();\n }\n\n detach(): void {\n if (!this.rendererAttached) return;\n\n this.rendererAttached = false;\n\n if (this.state === 'closed') {\n this.releaseFrame();\n\n return;\n }\n\n if (this.state !== 'active') return;\n\n this.state = 'closing';\n const ticket = ++this.closeTicket;\n\n queueMicrotask(() => {\n if (this.state === 'closing' && ticket === this.closeTicket) this.close();\n });\n }\n\n diagnostics(): MountFrameDiagnostics {\n const calls = [...this.frame.commandRecords.values()].map(record => record.controller.diagnostics());\n\n return Object.freeze({\n active: this.state === 'active',\n calls: Object.freeze(calls),\n commandRecords: this.frame.commandRecords.size,\n models: this.frame.models.size,\n });\n }\n\n getRenderableSnapshot = (): boolean => this.state !== 'closed' && (this.isActive === undefined || this.isActive());\n\n releaseClosedFrame(): void {\n if (this.state === 'closed') this.releaseFrame();\n }\n\n subscribeRenderable = (listener: () => void): (() => void) => {\n if (this.state === 'closed') return (): void => undefined;\n\n const registration = { listener };\n this.renderListeners.add(registration);\n let subscribed = true;\n\n return (): void => {\n if (!subscribed) return;\n\n subscribed = false;\n this.renderListeners.delete(registration);\n };\n };\n\n private buildCommandRecords(mountId: number): void {\n let commandIndex = 0;\n\n // `buildFrame` already reduced the models to their distinct Commands, so every command here gets its own record.\n for (const command of this.boundCommands) {\n // Authenticity check only: the binding carries no mode since observe was removed (D71).\n getCommandBindingDefinition(command);\n const controller = createCallController(command, {\n captureAuthority: this.captureAuthority,\n id: `contributionCommand.${String(mountId)}.${String(++commandIndex)}`,\n scheduling: { policy: 'parallel' },\n });\n this.frame.commandRecords.set(command, { controller, invoker: Object.freeze({ run: controller.run }) });\n }\n }\n\n private captureAuthority = (): CallAuthority => {\n const authority = this.authority;\n\n if (this.state !== 'active' || authority === undefined) {\n throw new ContributionError('inactive', 'Contribution mount is not active.');\n }\n\n authority.assertCurrent();\n\n return authority;\n };\n\n private createAuthority(lease: LifetimeLease): CallAuthority {\n return Object.freeze({\n assertCurrent: (): void => {\n if (this.state !== 'active') throw new ContributionError('inactive', 'Contribution mount is not active.');\n\n lease.assertCurrent();\n },\n isCurrent: (): boolean => this.state === 'active' && lease.isCurrent(),\n });\n }\n\n private publishRenderable(): void {\n for (const { listener } of [...this.renderListeners]) {\n try {\n listener();\n } catch (error) {\n reportDetachedError(error);\n }\n }\n }\n\n private releaseFrame(): void {\n if (this.released) return;\n\n this.released = true;\n this.frame.commandRecords.clear();\n this.frame.models.clear();\n this.boundCommands = [];\n this.renderListeners.clear();\n }\n}\n\nexport { MountFrameImpl };\nexport type { Frame };\n","import { useInsertionEffect, useLayoutEffect, useSyncExternalStore } from 'react';\nimport type { PropsWithChildren, ReactElement } from 'react';\n\nimport { FrameContext } from './mount-context';\nimport type { MountFrameImpl } from './mount-frame';\n\nfunction MountProvider({\n children,\n mount,\n}: PropsWithChildren<{ readonly mount: MountFrameImpl }>): ReactElement | null {\n const renderable = useSyncExternalStore(\n mount.subscribeRenderable,\n mount.getRenderableSnapshot,\n mount.getRenderableSnapshot,\n );\n\n useInsertionEffect(() => {\n const attached = mount.attach();\n\n if (!attached) return undefined;\n\n return () => mount.detach();\n }, [mount]);\n\n useLayoutEffect(() => {\n if (!renderable) mount.releaseClosedFrame();\n }, [mount, renderable]);\n\n return renderable ? <FrameContext value={mount.frame}>{children}</FrameContext> : null;\n}\n\nexport { MountProvider };\n","import { memo, useCallback, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport type { ComponentType, ReactElement } from 'react';\n\nimport type { DeclarationId, State } from '@opetope/core';\nimport {\n createAggregateError,\n createState,\n getContributionOwner,\n isReadable,\n isResourceView,\n reportDetachedError,\n} from '@opetope/core/internal';\nimport type { ModelIdentity } from '@opetope/core/internal';\nimport { openContributionModels, reportRuntimeFailure, requireContributionModelPlans } from '@opetope/runtime/internal';\nimport type { ContributionModelBundle, RuntimeErrorReporter } from '@opetope/runtime/internal';\n\nimport { bindCommand, isCommandBinding } from './command';\nimport { ContributionIsolation, useContributionErrorContent } from './contribution-isolation';\nimport { bindModel } from './model-binding';\nimport { isResource } from './resource-command';\nimport type { ModelBindingIdentity } from './model-binding';\nimport { MountFrameImpl } from './mount-frame';\nimport { MountProvider } from './mount-provider';\nimport { useReadable } from './readable-hooks';\n\ntype AnyModel = ModelIdentity;\ntype ContributionAuthority = {\n /** The feature whose generation published this contribution (D257). */\n readonly feature?: DeclarationId;\n readonly models: readonly (readonly [AnyModel, unknown])[];\n /** The reporter of the feature that published this contribution: a contained failure is its diagnostic, not ours. */\n readonly reporter?: RuntimeErrorReporter;\n};\ntype ModelFixture = readonly [declaration: AnyModel, model: unknown];\n\ntype ContributionValue = {\n readonly Component: ComponentType<never>;\n readonly models?: readonly object[] | undefined;\n readonly props?: ((slotProps: never) => object) | undefined;\n};\n\ntype ContributionMountProps = {\n readonly authority?: ContributionAuthority | undefined;\n readonly contribution: ContributionValue;\n /** The published entry this mount renders, and the slot it renders in: the identity of a contained failure (D257). */\n readonly contributionId: DeclarationId;\n readonly fixtures?: readonly ModelFixture[];\n readonly slotProps: object;\n readonly targetId: DeclarationId;\n};\n\ntype MountBundle = {\n readonly frame: MountFrameImpl;\n readonly isOpen: () => boolean;\n readonly props: State<object>;\n};\n\ntype MountOwner = {\n readonly authority: ContributionAuthority | undefined;\n bundle: MountBundle | undefined;\n readonly contribution: ContributionValue;\n readonly fixtures: readonly ModelFixture[] | undefined;\n retired: boolean;\n};\n\ntype CommittedMount = {\n readonly bundle: MountBundle;\n readonly owner: MountOwner;\n};\n\nfunction closeOwnedMount(owner: MountOwner): void {\n const bundle = owner.bundle;\n owner.bundle = undefined;\n bundle?.frame.close();\n}\n\n/**\n * Model fields arrive as authentic kernel calls; binding them registers the command records the frame needs. D349: a\n * Resource is none of those and needs none of it — it is a field the selection reads on its own terms, so it travels\n * to the frame unchanged instead of being offered to `bindCommand`, which would refuse it as inauthentic.\n */\nfunction bindFrameModel(declaration: AnyModel, model: unknown): ModelBindingIdentity {\n if (typeof model !== 'object' || model === null) return bindModel(declaration as never, model as never);\n\n const passesThrough = (value: unknown): boolean =>\n isReadable(value) ||\n isResource(value) ||\n isResourceView(value) ||\n typeof value === 'function' ||\n isCommandBinding(value);\n const fields = Object.entries(model).map(([key, value]): readonly [string, unknown] => [\n key,\n passesThrough(value) ? value : bindCommand(value as never),\n ]);\n\n return bindModel(declaration as never, Object.fromEntries(fields) as never);\n}\n\n/**\n * D70: the authority of a contribution belongs to the entry a feature published, not to the value it wrote. One\n * static contribution object may be published by two features, and each mount must read the models of its own.\n */\nfunction contributionAuthority(entry: unknown): ContributionAuthority | undefined {\n return getContributionOwner(entry) as ContributionAuthority | undefined;\n}\n\n/** A mount with no publishing generation behind it: a fixture of a component test grants nothing and reports nowhere. */\nconst unownedContribution: ContributionAuthority = { models: [] };\n\nfunction cleanupFailedMount(close: () => void, cause: unknown): never {\n try {\n close();\n } catch (error) {\n throw createAggregateError([cause, error], 'Contribution mount setup and cleanup failed.', { cause });\n }\n\n throw cause;\n}\n\nfunction contributionModels(\n contribution: ContributionValue,\n slotProps: object,\n fixtures: readonly ModelFixture[],\n owner: ContributionAuthority | undefined,\n): {\n readonly bundle: ContributionModelBundle | undefined;\n readonly models: readonly ModelFixture[];\n readonly props: State<object>;\n} {\n const props = createState(slotProps);\n const { models: granted, reporter } = owner ?? unownedContribution;\n\n try {\n const plans = requireContributionModelPlans(contribution.models);\n const bundle = plans.length === 0 ? undefined : openContributionModels(plans, props, reporter);\n\n return {\n bundle,\n models: [...granted, ...(bundle?.models ?? []), ...fixtures],\n props,\n };\n } catch (error) {\n return cleanupFailedMount(props.close, error);\n }\n}\n\nfunction createMountBundle(\n contribution: ContributionValue,\n slotProps: object,\n fixtures: readonly ModelFixture[],\n authority: ContributionAuthority | undefined,\n): MountBundle {\n const { bundle, models, props } = contributionModels(contribution, slotProps, fixtures, authority);\n let closed = false;\n const close = (): void => {\n if (closed) return;\n\n closed = true;\n\n try {\n void bundle?.close().catch(reportDetachedError);\n } finally {\n props.close();\n }\n };\n try {\n const frame = new MountFrameImpl(\n models.map(([declaration, model]) => bindFrameModel(declaration, model)),\n { isActive: () => !closed, onClose: close },\n );\n\n return { frame, isOpen: () => !closed, props };\n } catch (error) {\n return cleanupFailedMount(close, error);\n }\n}\n\nfunction createComponentElement(Component: ComponentType<never>, props: object): ReactElement {\n const Rendered = Component as ComponentType<object>;\n\n return <Rendered {...props} />;\n}\n\ntype MountedContributionProps = {\n readonly bundle: MountBundle;\n readonly contribution: ContributionValue;\n};\n\n/** Reads the committed props of one live mount: every hook here sees a bundle that already exists. */\nfunction MountedContribution({ bundle, contribution }: MountedContributionProps): ReactElement {\n const committedProps = useReadable(bundle.props);\n const componentProps = useMemo(\n () => (contribution.props === undefined ? committedProps : contribution.props(committedProps as never)),\n [committedProps, contribution],\n );\n\n return (\n <MountProvider mount={bundle.frame}>{createComponentElement(contribution.Component, componentProps)}</MountProvider>\n );\n}\n\n/**\n * D188: a mount is created in commit, never in render. The first pass renders nothing, the layout effect builds the\n * bundle from the props that committed and publishes it, and React flushes that update before paint. A render that\n * is thrown away — StrictMode's double invoke, an abandoned concurrent pass, a suspended sibling — therefore\n * creates no models at all, so there is nothing to sweep, adopt or replace.\n */\nfunction ContributionMount({\n authority,\n contribution,\n fixtures,\n slotProps,\n}: ContributionMountProps): ReactElement | null {\n const owner = useMemo<MountOwner>(\n () => ({ authority, bundle: undefined, contribution, fixtures, retired: false }),\n [authority, contribution, fixtures],\n );\n const [committed, setCommitted] = useState<CommittedMount | undefined>(undefined);\n const bundle = committed?.owner === owner ? committed.bundle : undefined;\n const committedSlotProps = useRef(slotProps);\n\n useLayoutEffect(() => {\n committedSlotProps.current = slotProps;\n });\n\n // Suspense disconnects layout effects while hiding, but insertion cleanup only retires an actual identity.\n // Do not close Readables in insertion: their listeners may update React. A hidden tree has no layout cleanup\n // left to run on unmount, so the microtask also releases a mount that never becomes visible again.\n useInsertionEffect(\n () => () => {\n owner.retired = true;\n queueMicrotask(() => {\n try {\n closeOwnedMount(owner);\n } catch (error) {\n reportDetachedError(error);\n }\n });\n },\n [owner],\n );\n\n // The identity of the contribution owns the mount; a reveal and StrictMode reuse what its first commit created.\n useLayoutEffect(() => {\n const created = (owner.bundle ??= createMountBundle(\n owner.contribution,\n committedSlotProps.current,\n owner.fixtures ?? [],\n owner.authority,\n ));\n setCommitted(current => (current?.owner === owner ? current : { bundle: created, owner }));\n\n return () => {\n if (owner.retired) closeOwnedMount(owner);\n };\n }, [owner]);\n\n // Both the component and its models read the same committed snapshot, published before paint.\n useLayoutEffect(() => {\n if (bundle?.isOpen() === true) bundle.props.set(slotProps);\n }, [bundle, slotProps]);\n\n if (bundle === undefined) return null;\n\n return <MountedContribution bundle={bundle} contribution={contribution} />;\n}\n\n/**\n * D256: every mount is a boundary. The isolation sits above `ContributionMount`, so it contains the render of the\n * component and the commit that builds the mount alike, and a retry rebuilds the mount instead of reusing the bundle\n * that failed. Containment is unconditional; the content a failure shows is the host policy of `ContributionBoundary`.\n */\nfunction IsolatedContributionMount(props: ContributionMountProps): ReactElement {\n const { authority, contribution, contributionId, fixtures, targetId } = props;\n const content = useContributionErrorContent();\n const identity = useMemo(() => ({ authority, contribution, fixtures }), [authority, contribution, fixtures]);\n const feature = authority?.feature;\n const source = useMemo(\n () => ({ contribution: contributionId, feature, target: targetId }),\n [contributionId, feature, targetId],\n );\n const reporter = authority?.reporter;\n const report = useCallback((error: unknown) => reportRuntimeFailure(error, reporter), [reporter]);\n\n return (\n <ContributionIsolation content={content} identity={identity} report={report} source={source}>\n <ContributionMount {...props} />\n </ContributionIsolation>\n );\n}\n\n/**\n * One mount, one memo: `Slot` recreates its children whenever `entries` changes, so publishing or withholding one\n * contribution used to re-render every other mount of that target. The props are the contribution, the slot props\n * and the fixtures, all of which are stable while nothing about that mount changed.\n */\nconst MemoizedContributionMount = memo(IsolatedContributionMount);\n\nexport { contributionAuthority, MemoizedContributionMount as ContributionMount };\nexport type { ContributionValue, ModelFixture };\n"],"names":["FrameContext","createContext","useFrame","frame","useContext","ContributionError","isResource","value","isResourceValue","awaitCancellable","operation","signal","resolve","reject","cancel","CommandError","compatibleAbortReason","error","notifySuccess","options","notification","_a","reportDetachedError","operationInvoker","start","_input","unavailablePage","paginationOf","resource","capability","createResourceInvokers","resourceInvokers","cache","existing","invokers","identity","useSelector","readable","select","selector","isEqual","subscribe","useCallback","listener","instanceRef","useRef","instance","getSelectedSnapshot","useMemo","initialized","sourceSnapshot","selectedSnapshot","nextSource","nextSelected","nextSelectedSnapshot","selected","useSyncExternalStore","useEffect","useReadable","bindingDefinitions","bindCommand","target","isCallTarget","getCommandBindingDefinition","binding","definition","isCommandBinding","modelBindingBrand","modelBindingIdentityBrand","modelBindingMarker","registry","modelFieldValue","declaration","model","field","descriptor","isObservedField","isReadable","isResourceView","snapshotModelFields","commands","fields","bindModel","isModel","getModelBindingMetadata","metadata","nextMountId","buildFrame","supplied","models","bound","candidate","command","MountFrameImpl","lifecycle","mountId","createLifetimeController","authority","record","onClose","ticket","calls","registration","subscribed","commandIndex","controller","createCallController","lease","MountProvider","children","mount","renderable","useInsertionEffect","useLayoutEffect","_jsx","closeOwnedMount","owner","bundle","bindFrameModel","passesThrough","key","contributionAuthority","entry","getContributionOwner","unownedContribution","cleanupFailedMount","close","cause","createAggregateError","contributionModels","contribution","slotProps","fixtures","props","createState","granted","reporter","plans","requireContributionModelPlans","openContributionModels","createMountBundle","closed","createComponentElement","Component","MountedContribution","committedProps","componentProps","ContributionMount","committed","setCommitted","useState","committedSlotProps","created","current","IsolatedContributionMount","contributionId","targetId","content","useContributionErrorContent","feature","source","report","reportRuntimeFailure","ContributionIsolation","MemoizedContributionMount","memo"],"mappings":"6xBAKA,MAAMA,EAAeC,EAAiC,MAAS,EAE/D,SAASC,IAAQ,CACf,MAAMC,EAAQC,EAAWJ,CAAY,EAErC,GAAIG,IAAU,OACZ,MAAM,IAAIE,EAAkB,UAAW,uDAAuD,EAGhG,OAAOF,CACT,CC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,SAAU1H,EAAU,OAAQ8H,EAAQ,OAAQD,EAAM,SACzF9C,EAACiC,GAAiB,CAAA,GAAKd,CAAK,CAAA,EAAI,CAGtC,CAOA,MAAM+B,GAA4BC,EAAKX,EAAyB"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as O,useInsertionEffect as E,useLayoutEffect as w,useMemo as l,useSyncExternalStore as y,useRef as S,useCallback as F,useEffect as D,createElement as P,Fragment as B}from"react";import{CommandError as J,declarationId as Q}from"@opetope/core";import{compatibleAbortReason as V,isCancellation as X,reportDetachedError as N,isCallTarget as Y,isReadable as Z,createAggregateError as _,createContributionTarget as ee}from"@opetope/core/internal";import{C as d}from"./contribution-isolation-Bzfbt4iM.js";import{u as C,r as te,i as ne,p as se,c as ie,a as I,M as oe,b as re}from"./contribution-frame-CCKnOxZR.js";import{d as at}from"./contribution-frame-CCKnOxZR.js";function A(t,e){var n;if(X(e))return{reason:e,kind:"cancelled"};try{const s=(n=t==null?void 0:t.onFailure)==null?void 0:n.call(t,e);s!==void 0&&Promise.resolve(s).catch(N)}catch(s){N(s)}return{error:e,kind:"failed"}}function ce(t){const e=t==null?void 0:t.onSuccess,n=t==null?void 0:t.signal;return e===void 0?n===void 0?void 0:{signal:n}:n===void 0?{onSuccess:e}:{onSuccess:e,signal:n}}function ae(t,e){let n;const s=new Promise(i=>{n=i});return{input:t,options:e===void 0?void 0:{...e},promise:s,resolve:n}}function ue(t,e){const n=t.resolve;t.input=void 0,t.options=void 0,t.resolve=void 0,n==null||n(e)}class h{invoker;run=((e,n)=>{if(this.notify===void 0)return Promise.resolve({reason:new d("inactive","Command consumer is not mounted."),kind:"cancelled"});const s=this.cancelledInput(n);if(s!==void 0)return Promise.resolve(s);const i=ae(e,n);return this.start(i),i.promise});inFlight=0;notify;constructor(e){this.invoker=e}attach(e){return this.notify=e,()=>{this.notify===e&&(this.notify=void 0)}}synchronize(){var e;(e=this.notify)==null||e.call(this,this.inFlight>0)}aborted(e){return{reason:new J("cancelled","Command input was cancelled.",V(e)),kind:"cancelled"}}cancelledInput(e){var n;return((n=e==null?void 0:e.signal)==null?void 0:n.aborted)===!0?this.aborted(e.signal):void 0}finish(e,n){var s;e.resolve!==void 0&&(this.inFlight-=1,ue(e,n),(s=this.notify)==null||s.call(this,this.inFlight>0,n))}invoke(e){let n;try{n=this.invoker.run(e.input,ce(e.options)),e.input=void 0}catch(s){this.finish(e,A(e.options,s));return}n.then(s=>this.finish(e,{kind:"ok",value:s}),s=>this.finish(e,A(e.options,s)))}start(e){var n;this.inFlight+=1,(n=this.notify)==null||n.call(this,!0),this.invoke(e)}}const de={inFlight:!1,outcome:void 0};function fe(t){return t===void 0||t.kind==="cancelled"?void 0:t}function le(t,e,n,s){return s===void 0&&t.slot===e&&t.inFlight===n}function he(t,e,n,s){const i=fe(s);if(le(t,e,n,i))return t;const o=t.slot===e?t.outcome:void 0;return{inFlight:n,outcome:i??o,slot:e}}function be(t){const[e]=O(()=>new WeakMap);let n=e.get(t);return n===void 0&&(n=new h(t),e.set(t,n)),n}function b(t){const[e,n]=O(()=>({inFlight:!1,outcome:void 0,slot:t}));E(()=>t.attach((r,c)=>n(a=>he(a,t,r,c))),[t]),w(()=>t.synchronize(),[t]);const{inFlight:s,outcome:i}=e.slot===t?e:de,o=t.run;return l(()=>({inFlight:s,outcome:i,run:o}),[s,i,o])}function pe(t){const n=C().commandRecords.get(t);if(n===void 0)throw new d("missing",`Command ${t.id} is not bound in this contribution.`);return b(be(n.invoker))}const ge=()=>{},K=()=>ge,me=()=>0,we=Object.freeze({});function p(t){return"kind"in t}function g(t){const e=new h(t);return{detach:void 0,hook:{inFlight:!1,outcome:void 0,run:e.run},invoker:t,slot:e}}function ye(t,e){return t.inFlight===e.inFlight&&Object.is(t.outcome,e.outcome)}function Se(t,e,n){const s=t.hook;if(n===void 0&&s.inFlight===e)return!1;const i=n===void 0||n.kind==="cancelled"?void 0:n,o={inFlight:e,outcome:i??s.outcome,run:s.run};return ye(s,o)?!1:(t.hook=o,!0)}function ke(t,e){return t!==void 0&&!p(t)&&t.invoker===e?t:g(e)}function H(t,e){return{pagination:t.paginated?{loadNext:t.loadNext.hook,state:e.pagination}:void 0,refresh:t.refresh.hook,reset:t.reset.hook,retry:t.retry.hook,state:e.state}}function ve(t,e){const n={kind:"resource",loadNext:g(t.loadNext),paginated:e.pagination!==void 0,refresh:g(t.refresh),reset:g(t.reset),retry:g(t.retry)};return{...n,hook:H(n,e)}}function Oe(t){var n;const{hook:e}=t;return e.refresh===t.refresh.hook&&e.reset===t.reset.hook&&e.retry===t.retry.hook&&(!t.paginated||((n=e.pagination)==null?void 0:n.loadNext)===t.loadNext.hook)}function Ee(t,e){var n;return Object.is(t.hook.state,e.state)&&Object.is((n=t.hook.pagination)==null?void 0:n.state,e.pagination)}function Ce(t,e){return Oe(t)&&Ee(t,e)}function Re(t,e,n){return t===void 0||!p(t)||t.refresh.invoker!==e.refresh?ve(e,n):(Ce(t,n)||(t.hook=H(t,n)),t)}function ze(t){return p(t)?[t.refresh,t.reset,t.retry,t.loadNext]:[t]}function $(t){var e;for(const n of ze(t))(e=n.detach)==null||e.call(n),n.detach=void 0}function Me(t){return t.hook}class je{entries=new Map;invokers=new WeakMap;listeners=new Set;revision=0;close(){for(const e of this.entries.values())$(e);this.entries.clear()}commit(e){for(const[n,s]of this.entries)e.get(n)!==s&&$(s);this.entries=e;for(const n of e.values())this.attachEntry(n)}attachEntry(e){if(p(e)){this.attachCommand(e.refresh),this.attachCommand(e.retry),this.attachCommand(e.reset),this.attachCommand(e.loadNext);return}this.attachCommand(e)}attachCommand(e){e.detach??(e.detach=e.slot.attach((n,s)=>{if(Se(e,n,s)){this.revision+=1;for(const i of this.listeners)i()}}))}getSnapshot=()=>this.revision;prepare(e,n,s){const i=new Map;for(const o of Reflect.ownKeys(e)){if(!Object.prototype.propertyIsEnumerable.call(e,o))continue;const r=e[o],c=r===void 0?void 0:s.commandRecords.get(r);if(c===void 0)throw new d("missing",`Command at ${String(o)} is not bound in this contribution.`);i.set(o,ke(this.entries.get(o),c.invoker))}for(const[o,r]of n){const c=te(r.resource,this.invokers);i.set(o,Re(this.entries.get(o),c,r))}return i}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)})}function xe(t,e){const n=S(void 0);return e.size>0||Reflect.ownKeys(t).some(i=>Object.prototype.propertyIsEnumerable.call(t,i))?n.current??(n.current=new je):void 0}function Fe(t,e){const n=C(),s=xe(t,e),i=(s==null?void 0:s.getSnapshot)??me;y((s==null?void 0:s.subscribe)??K,i,i);const o=s==null?void 0:s.prepare(t,e,n);return E(()=>()=>s==null?void 0:s.close(),[s]),E(()=>{o!==void 0&&(s==null||s.commit(o))}),w(()=>{if(o!==void 0)for(const r of o.values())p(r)?(r.refresh.slot.synchronize(),r.retry.slot.synchronize(),r.reset.slot.synchronize(),r.loadNext.slot.synchronize()):r.slot.synchronize()}),o===void 0?we:Object.fromEntries([...o].map(([r,c])=>[r,Me(c)]))}const L=new Map,T=new Set;function Pe(t,e){if(!Z(t))throw new d("binding-invalid","Model selection read requires a Readable.");if(e.has(t))return e.get(t);const n=t.getSnapshot();return e.set(t,n),n}function U(t,e){if(e.has(t))return e.get(t);const n=t.getSnapshot();return e.set(t,n),n}function Ne(t,e,n,s){if(!ne(e))return;const i=e,o=i.pagination;n.set(t,{pagination:o===void 0?void 0:U(o.state,s),resource:i,state:U(i.state,s)})}function Ie(t){return t.size===0?L:t}function Ae(t,e){const s=t({read:(r,c)=>{const a=Pe(r,e);return c===void 0?a:c(a)}});if(typeof s!="object"||s===null||Array.isArray(s))throw new d("binding-invalid","Model selection requires a record.");const i=[],o=new Map;for(const r of Reflect.ownKeys(s)){if(!Object.prototype.propertyIsEnumerable.call(s,r))continue;const c=s[r];i.push([r,c]),Ne(r,c,o,e)}return{resources:Ie(o),values:Object.fromEntries(i)}}function Ke(t,e){if(t.size!==e.size)return!1;for(const[n,s]of e){const i=t.get(n);if((i==null?void 0:i.resource)!==s.resource||!Object.is(i.state,s.state)||!Object.is(i.pagination,s.pagination))return!1}return!0}function He(t,e,n,s){const i=Reflect.ownKeys(e),o=Reflect.ownKeys(t.values);if(i.length!==o.length||n.size!==t.sources.size)return!1;for(const r of n)if(!t.sources.has(r))return!1;return Ke(t.resources,s)?i.every((r,c)=>o[c]===r&&Object.is(t.values[r],e[r])):!1}const k={commands:{},leases:T,resources:L,sources:new Set,values:{}};function $e(t){return Object.fromEntries(Reflect.ownKeys(t).filter(e=>Y(t[e])).map(e=>[e,t[e]]))}function Le(t){if(t.size===0)return T;const e=new Set;for(const n of t.values())e.add(n.resource);return e}function Te(t){for(const[e,n]of t)if(!Object.is(e.getSnapshot(),n))return!1;return!0}function Ue(){return{model:void 0,observed:void 0,select:void 0,snapshot:k}}function We(t,e,n){return n.model!==t&&(n.model=t,n.observed=void 0,n.select=void 0,n.snapshot=k),()=>{const s=e.current;if(s===void 0)return k;const i=n.observed;if(i!==void 0&&n.select===s&&Te(i))return n.snapshot;const o=new Map,{resources:r,values:c}=Ae(f=>s(t,f),o),a=new Set(o.keys());return(i===void 0||!He(n.snapshot,c,a,r))&&(n.snapshot={commands:$e(c),leases:Le(r),resources:r,sources:a,values:c}),n.observed=o,n.select=s,n.snapshot}}const R=new Set;function W(t,e=[]){for(const n of t){const s=n.dispose;n.dispose=void 0;try{s==null||s()}catch(i){e.push(i)}}if(e.length===1)throw e[0];if(e.length>1)throw _(e,"Model selection sources failed to release.")}class Ge{enabled=!1;leases=new Map;listeners=new Set;retained=R;sources=new Set;subscriptions=new Map;close(){this.enabled=!1,this.sources=new Set,this.retained=R,this.releaseAll()}commit(e,n=R){this.sources=e,this.retained=n,this.enabled=!0;try{this.synchronize()}catch(s){this.releaseAll([s])}}subscribe=e=>{const n={notify:e};this.listeners.add(n);try{this.synchronize()}catch(s){this.listeners.delete(n),this.releaseAll([s])}return()=>{this.listeners.delete(n),this.listeners.size===0&&this.releaseAll()}};add(e){const n={dispose:void 0};this.subscriptions.set(e,n);const s=e.subscribe(this.notify);if(typeof s!="function")throw new TypeError("Model selection source must return a disposer.");this.subscriptions.get(e)===n?n.dispose=s:s()}notify=()=>{for(const e of[...this.listeners])this.listeners.has(e)&&e.notify()};releaseAll(e){const n=[...this.subscriptions.values(),...this.leases.values()];this.subscriptions.clear(),this.leases.clear(),W(n,e)}removeUnselected(){const e=[];for(const[n,s]of this.subscriptions)this.sources.has(n)||(this.subscriptions.delete(n),e.push(s));for(const[n,s]of this.leases)this.retained.has(n)||(this.leases.delete(n),e.push(s));W(e)}retain(e){const n={dispose:void 0};this.leases.set(e,n);const s=e.acquire();if(typeof s!="function")throw new TypeError("Model selection resource must answer a release disposer.");this.leases.get(e)===n?n.dispose=s:s()}ready(){return this.enabled&&this.listeners.size>0}retainSelected(){for(const e of this.retained){if(!this.ready())return;this.retained.has(e)&&!this.leases.has(e)&&this.retain(e)}}subscribeSources(){for(const e of this.sources){if(!this.ready())return;this.sources.has(e)&&!this.subscriptions.has(e)&&this.add(e)}}synchronize(){this.removeUnselected(),this.subscribeSources(),this.retainSelected()}}const qe=()=>k;function De(t){const e=S(void 0);return t?e.current??(e.current=new Ge):void 0}function Be(t,e){return Object.fromEntries(Reflect.ownKeys(t.values).map(n=>[n,Object.prototype.hasOwnProperty.call(e,n)?e[n]:t.values[n]]))}function Je(t,e){const n=C();if(!n.models.has(t))throw new d("missing",`Model ${t.id} is not granted to this contribution.`);const s=n.models.get(t),i=De(e!==void 0),o=S(void 0);o.current=e;const r=e!==void 0,c=S(void 0),a=c.current??(c.current=Ue()),f=l(()=>r?We(s,o,a):qe,[a,s,r]),u=y((i==null?void 0:i.subscribe)??K,f,f),m=Fe(u.commands,u.resources);return w(()=>()=>i==null?void 0:i.close(),[i]),w(()=>i==null?void 0:i.commit(u.sources,u.leases),[u,i]),e===void 0?s:Be(u,m)}function Qe(t){const e=Object.freeze([...t]);return n=>{if(n.requires!==void 0)throw new d("duplicate","Component already declares the models it requires.");return Object.defineProperty(n,"requires",{enumerable:!1,value:e}),n}}function Ve(t){const[e]=O(()=>new WeakMap),n=e.get(t);if(n!==void 0)return n;const s=ie(t),i={loadNext:new h(s.loadNext),refresh:new h(s.refresh),reset:new h(s.reset),retry:new h(s.retry)};return e.set(t,i),i}const Xe=Object.freeze({kind:"unavailable",reason:"resource-not-ready"}),Ye=Object.freeze({getSnapshot:()=>Xe,subscribe:()=>()=>{}});function Ze(t){const e=t,n=se(e),s=F(v=>t.state.subscribe(v),[t]),i=l(()=>()=>t.state.getSnapshot(),[t]),o=y(s,i,i),r=(n==null?void 0:n.state)??Ye,c=F(v=>r.subscribe(v),[r]),a=l(()=>()=>r.getSnapshot(),[r]),f=y(c,a,a);D(()=>t.acquire(),[t]);const u=Ve(e),m=b(u.refresh),z=b(u.retry),M=b(u.reset),j=b(u.loadNext),x=l(()=>n===void 0?void 0:{loadNext:j,state:f},[n,j,f]);return l(()=>({pagination:x,refresh:m,reset:M,retry:z,state:o}),[x,m,M,z,o])}const G=Object.freeze({});function q(t){return ee(t,"slot")}function _e(t){const e=Q(t),n=new Map,s=i=>{const o=n.get(i);if(o!==void 0)return o;const r=q(`${e}/${i}`);return n.set(i,r),r};return Object.defineProperty(s,"id",{enumerable:!0,value:e}),Object.freeze(s)}function et(t){const e=I(t.target.entries),n="props"in t?t.props??G:G;return e.length===0?null:e.map(s=>P(B,{key:s.id},P(oe,{authority:re(s),contribution:s.value,contributionId:s.id,slotProps:n,targetId:t.target.id})))}export{d as ContributionError,et as Slot,q as defineSlot,_e as defineSwitchSlot,Qe as requiresModels,pe as useCommand,Je as useModel,I as useReadable,Ze as useResource,at as useSelector};
|
|
1
|
+
import{useState as E,useInsertionEffect as M,useLayoutEffect as w,useMemo as b,useSyncExternalStore as R,useRef as y,useCallback as F,useEffect as Q,createElement as P,Fragment as X}from"react";import{CommandError as Y,declarationId as Z}from"@opetope/core";import{compatibleAbortReason as _,isCancellation as ee,reportDetachedError as I,isCallTarget as te,isResourceView as A,resourceViewDemands as K,resourceViewReadable as S,isReadable as ne,createAggregateError as se,acquireResourceDemand as ie,createContributionTarget as re}from"@opetope/core/internal";import{C as f}from"./contribution-isolation-Bzfbt4iM.js";import{u as z,r as oe,i as ce,p as ae,c as ue,a as H,M as de,b as fe}from"./contribution-frame-Bh104T5Z.js";import{d as gt}from"./contribution-frame-Bh104T5Z.js";function $(t,e){var n;if(ee(e))return{reason:e,kind:"cancelled"};try{const s=(n=t==null?void 0:t.onFailure)==null?void 0:n.call(t,e);s!==void 0&&Promise.resolve(s).catch(I)}catch(s){I(s)}return{error:e,kind:"failed"}}function le(t){const e=t==null?void 0:t.onSuccess,n=t==null?void 0:t.signal;return e===void 0?n===void 0?void 0:{signal:n}:n===void 0?{onSuccess:e}:{onSuccess:e,signal:n}}function he(t,e){let n;const s=new Promise(i=>{n=i});return{input:t,options:e===void 0?void 0:{...e},promise:s,resolve:n}}function be(t,e){const n=t.resolve;t.input=void 0,t.options=void 0,t.resolve=void 0,n==null||n(e)}class p{invoker;run=((e,n)=>{if(this.notify===void 0)return Promise.resolve({reason:new f("inactive","Command consumer is not mounted."),kind:"cancelled"});const s=this.cancelledInput(n);if(s!==void 0)return Promise.resolve(s);const i=he(e,n);return this.start(i),i.promise});inFlight=0;notify;constructor(e){this.invoker=e}attach(e){return this.notify=e,()=>{this.notify===e&&(this.notify=void 0)}}synchronize(){var e;(e=this.notify)==null||e.call(this,this.inFlight>0)}aborted(e){return{reason:new Y("cancelled","Command input was cancelled.",_(e)),kind:"cancelled"}}cancelledInput(e){var n;return((n=e==null?void 0:e.signal)==null?void 0:n.aborted)===!0?this.aborted(e.signal):void 0}finish(e,n){var s;e.resolve!==void 0&&(this.inFlight-=1,be(e,n),(s=this.notify)==null||s.call(this,this.inFlight>0,n))}invoke(e){let n;try{n=this.invoker.run(e.input,le(e.options)),e.input=void 0}catch(s){this.finish(e,$(e.options,s));return}n.then(s=>this.finish(e,{kind:"ok",value:s}),s=>this.finish(e,$(e.options,s)))}start(e){var n;this.inFlight+=1,(n=this.notify)==null||n.call(this,!0),this.invoke(e)}}const pe={inFlight:!1,outcome:void 0};function ge(t){return t===void 0||t.kind==="cancelled"?void 0:t}function me(t,e,n,s){return s===void 0&&t.slot===e&&t.inFlight===n}function we(t,e,n,s){const i=ge(s);if(me(t,e,n,i))return t;const r=t.slot===e?t.outcome:void 0;return{inFlight:n,outcome:i??r,slot:e}}function ye(t){const[e]=E(()=>new WeakMap);let n=e.get(t);return n===void 0&&(n=new p(t),e.set(t,n)),n}function k(t){const[e,n]=E(()=>({inFlight:!1,outcome:void 0,slot:t}));M(()=>t.attach((o,c)=>n(a=>we(a,t,o,c))),[t]),w(()=>t.synchronize(),[t]);const{inFlight:s,outcome:i}=e.slot===t?e:pe,r=t.run;return b(()=>({inFlight:s,outcome:i,run:r}),[s,i,r])}function Se(t){const n=z().commandRecords.get(t);if(n===void 0)throw new f("missing",`Command ${t.id} is not bound in this contribution.`);return k(ye(n.invoker))}const ke=()=>{},V=()=>ke,ve=()=>0,Re=Object.freeze({});function l(t){return"kind"in t}function v(t){const e=new p(t);return{detach:void 0,hook:{inFlight:!1,outcome:void 0,run:e.run},invoker:t,slot:e}}function Oe(t,e){return t.inFlight===e.inFlight&&Object.is(t.outcome,e.outcome)}function Ce(t,e,n){const s=t.hook;if(n===void 0&&s.inFlight===e)return!1;const i=n===void 0||n.kind==="cancelled"?void 0:n,r={inFlight:e,outcome:i??s.outcome,run:s.run};return Oe(s,r)?!1:(t.hook=r,!0)}function Ee(t,e){return t!==void 0&&!l(t)&&t.invoker===e?t:v(e)}function D(t,e){return{pagination:t.paginated?{loadNext:t.loadNext.hook,state:e.pagination}:void 0,refresh:t.refresh.hook,reset:t.reset.hook,retry:t.retry.hook,state:e.state}}function Me(t,e){const n={kind:"resource",loadNext:v(t.loadNext),paginated:e.pagination!==void 0,refresh:v(t.refresh),reset:v(t.reset),retry:v(t.retry)};return{...n,hook:D(n,e)}}function ze(t){var n;const{hook:e}=t;return e.refresh===t.refresh.hook&&e.reset===t.reset.hook&&e.retry===t.retry.hook&&(!t.paginated||((n=e.pagination)==null?void 0:n.loadNext)===t.loadNext.hook)}function je(t,e){var n;return Object.is(t.hook.state,e.state)&&Object.is((n=t.hook.pagination)==null?void 0:n.state,e.pagination)}function xe(t,e){return ze(t)&&je(t,e)}function Ne(t,e,n){return t===void 0||!l(t)||t.refresh.invoker!==e.refresh?Me(e,n):xe(t,n)?t:{...t,hook:D(t,n)}}function Fe(t){return l(t)?[t.refresh,t.reset,t.retry,t.loadNext]:[t]}function T(t){var e;for(const n of Fe(t))(e=n.detach)==null||e.call(n),n.detach=void 0}function Pe(t,e){return t.refresh===e.refresh&&t.reset===e.reset&&t.retry===e.retry&&t.loadNext===e.loadNext}function Ie(t,e){return t===e?!0:e===void 0||!l(t)||!l(e)?!1:Pe(t,e)}function Ae(t){return t.hook}class Ke{entries=new Map;invokers=new WeakMap;listeners=new Set;revision=0;close(){for(const e of this.entries.values())T(e);this.entries.clear()}commit(e){for(const[n,s]of this.entries)Ie(s,e.get(n))||T(s);this.entries=e;for(const n of e.values())this.attachEntry(n)}attachEntry(e){if(l(e)){this.attachCommand(e.refresh),this.attachCommand(e.retry),this.attachCommand(e.reset),this.attachCommand(e.loadNext);return}this.attachCommand(e)}attachCommand(e){e.detach??(e.detach=e.slot.attach((n,s)=>{if(Ce(e,n,s)){this.revision+=1;for(const i of this.listeners)i()}}))}getSnapshot=()=>this.revision;prepare(e,n,s){const i=new Map;for(const r of Reflect.ownKeys(e)){if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;const o=e[r],c=o===void 0?void 0:s.commandRecords.get(o);if(c===void 0)throw new f("missing",`Command at ${String(r)} is not bound in this contribution.`);i.set(r,Ee(this.entries.get(r),c.invoker))}for(const[r,o]of n){const c=oe(o.resource,this.invokers);i.set(r,Ne(this.entries.get(r),c,o))}return i}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)})}function He(t,e){const n=y(void 0);return e.size>0||Reflect.ownKeys(t).some(i=>Object.prototype.propertyIsEnumerable.call(t,i))?n.current??(n.current=new Ke):void 0}function $e(t,e){const n=z(),s=He(t,e),i=(s==null?void 0:s.getSnapshot)??ve;R((s==null?void 0:s.subscribe)??V,i,i);const r=s==null?void 0:s.prepare(t,e,n);return M(()=>()=>s==null?void 0:s.close(),[s]),M(()=>{r!==void 0&&(s==null||s.commit(r))}),w(()=>{if(r!==void 0)for(const o of r.values())l(o)?(o.refresh.slot.synchronize(),o.retry.slot.synchronize(),o.reset.slot.synchronize(),o.loadNext.slot.synchronize()):o.slot.synchronize()}),r===void 0?Re:Object.fromEntries([...r].map(([o,c])=>[o,Ae(c)]))}const L=new Map,Ve=new Set;function De(t,e){if(!ne(t))throw new f("binding-invalid","Model selection read requires a Readable or ResourceView.");if(e.has(t))return e.get(t);const n=t.getSnapshot();return e.set(t,n),n}function U(t,e){if(e.has(t))return e.get(t);const n=t.getSnapshot();return e.set(t,n),n}function Te(t,e,n,s){if(!ce(e))return;const i=e,r=i.pagination;n.set(t,{pagination:r===void 0?void 0:U(S(r),s),resource:i,state:U(S(i),s)})}function Le(t){return t.size===0?L:t}function Ue(t,e){for(const{resource:n}of t.values())if(A(n))for(const s of K(n))e.add(s);else e.add(n)}function We(t,e){const n=new Set,i=t({read:(c,a)=>{let d;if(A(c)){for(const h of K(c))n.add(h);d=c.observe()}else d=c;const u=De(d,e);return a===void 0?u:a(u)}});if(typeof i!="object"||i===null||Array.isArray(i))throw new f("binding-invalid","Model selection requires a record.");const r=[],o=new Map;for(const c of Reflect.ownKeys(i)){if(!Object.prototype.propertyIsEnumerable.call(i,c))continue;const a=i[c];r.push([c,a]),Te(c,a,o,e)}return Ue(o,n),{leases:n,resources:Le(o),values:Object.fromEntries(r)}}function qe(t,e){if(t.size!==e.size)return!1;for(const[n,s]of e){const i=t.get(n);if((i==null?void 0:i.resource)!==s.resource||!Object.is(i.state,s.state)||!Object.is(i.pagination,s.pagination))return!1}return!0}function W(t,e){if(t.size!==e.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Ge(t,e,n,s,i){const r=Reflect.ownKeys(e),o=Reflect.ownKeys(t.values);return r.length!==o.length||!W(t.sources,n)||!W(t.leases,i)||!qe(t.resources,s)?!1:r.every((c,a)=>o[a]===c&&Object.is(t.values[c],e[c]))}const O={commands:{},leases:Ve,resources:L,sources:new Set,values:{}};function Be(t){return Object.fromEntries(Reflect.ownKeys(t).filter(e=>te(t[e])).map(e=>[e,t[e]]))}function Je(t){for(const[e,n]of t)if(!Object.is(e.getSnapshot(),n))return!1;return!0}function Qe(){return{model:void 0,observed:void 0,select:void 0,snapshot:O}}function Xe(t,e,n){return n.model!==t&&(n.model=t,n.observed=void 0,n.select=void 0,n.snapshot=O),()=>{const s=e.current;if(s===void 0)return O;const i=n.observed;if(i!==void 0&&n.select===s&&Je(i))return n.snapshot;const r=new Map,{leases:o,resources:c,values:a}=We(u=>s(t,u),r),d=new Set(r.keys());return(i===void 0||!Ge(n.snapshot,a,d,c,o))&&(n.snapshot={commands:Be(a),leases:o,resources:c,sources:d,values:a}),n.observed=r,n.select=s,n.snapshot}}const j=new Set;function q(t,e=[]){for(const n of t){const s=n.dispose;n.dispose=void 0;try{s==null||s()}catch(i){e.push(i)}}if(e.length===1)throw e[0];if(e.length>1)throw se(e,"Model selection sources failed to release.")}class Ye{enabled=!1;leases=new Map;listeners=new Set;retained=j;sources=new Set;subscriptions=new Map;close(){this.enabled=!1,this.sources=new Set,this.retained=j,this.releaseAll()}commit(e,n=j){this.sources=e,this.retained=n,this.enabled=!0;try{this.synchronize()}catch(s){this.releaseAll([s])}}subscribe=e=>{const n={notify:e};this.listeners.add(n);try{this.synchronize()}catch(s){this.listeners.delete(n),this.releaseAll([s])}return()=>{this.listeners.delete(n),this.listeners.size===0&&this.releaseAll()}};add(e){const n={dispose:void 0};this.subscriptions.set(e,n);const s=e.subscribe(this.notify);if(typeof s!="function")throw new TypeError("Model selection source must return a disposer.");this.subscriptions.get(e)===n?n.dispose=s:s()}notify=()=>{for(const e of[...this.listeners])this.listeners.has(e)&&e.notify()};releaseAll(e){const n=[...this.subscriptions.values(),...this.leases.values()];this.subscriptions.clear(),this.leases.clear(),q(n,e)}removeUnselected(){const e=[];for(const[n,s]of this.subscriptions)this.sources.has(n)||(this.subscriptions.delete(n),e.push(s));for(const[n,s]of this.leases)this.retained.has(n)||(this.leases.delete(n),e.push(s));q(e)}retain(e){const n={dispose:void 0};this.leases.set(e,n);const s=e.acquire();if(typeof s!="function")throw new TypeError("Model selection resource must answer a release disposer.");this.leases.get(e)===n?n.dispose=s:s()}ready(){return this.enabled&&this.listeners.size>0}retainSelected(){for(const e of this.retained){if(!this.ready())return;this.retained.has(e)&&!this.leases.has(e)&&this.retain(e)}}subscribeSources(){for(const e of this.sources){if(!this.ready())return;this.sources.has(e)&&!this.subscriptions.has(e)&&this.add(e)}}synchronize(){this.removeUnselected(),this.subscribeSources(),this.retainSelected()}}const Ze=()=>O;function _e(t){const e=y(void 0);return t?e.current??(e.current=new Ye):void 0}function G(t,e,n){return Object.prototype.hasOwnProperty.call(e,n)?e[n]:t.values[n]}function et(t,e,n){const s=Reflect.ownKeys(t.values);if(n!==void 0){const i=Reflect.ownKeys(n);if(s.length===i.length&&s.every((r,o)=>r===i[o]&&Object.is(n[r],G(t,e,r))))return n}return Object.fromEntries(s.map(i=>[i,G(t,e,i)]))}function tt(t,e){const n=z();if(!n.models.has(t))throw new f("missing",`Model ${t.id} is not granted to this contribution.`);const s=n.models.get(t),i=_e(e!==void 0),r=y(void 0);r.current=e;const o=e!==void 0,c=y(void 0),a=c.current??(c.current=Qe()),d=b(()=>o?Xe(s,r,a):Ze,[a,s,o]),u=R((i==null?void 0:i.subscribe)??V,d,d),h=$e(u.commands,u.resources);w(()=>()=>i==null?void 0:i.close(),[i]),w(()=>i==null?void 0:i.commit(u.sources,u.leases),[u,i]);const g=y(void 0),m=o?et(u,h,g.current):void 0;return w(()=>{g.current=m}),e===void 0?s:m}function nt(t){const e=Object.freeze([...t]);return n=>{if(n.requires!==void 0)throw new f("duplicate","Component already declares the models it requires.");return Object.defineProperty(n,"requires",{enumerable:!1,value:e}),n}}function st(t){const[e]=E(()=>new WeakMap),n=e.get(t);if(n!==void 0)return n;const s=ue(t),i={loadNext:new p(s.loadNext),refresh:new p(s.refresh),reset:new p(s.reset),retry:new p(s.retry)};return e.set(t,i),i}const it=Object.freeze({kind:"unavailable",reason:"resource-not-ready"}),rt=Object.freeze({getSnapshot:()=>it,subscribe:()=>()=>{}});function ot(t){const e=t,n=ae(e),s=F(C=>S(t).subscribe(C),[t]),i=b(()=>()=>S(t).getSnapshot(),[t]),r=R(s,i,i),o=n===void 0?rt:S(n),c=F(C=>o.subscribe(C),[o]),a=b(()=>()=>o.getSnapshot(),[o]),d=R(c,a,a);Q(()=>ie(t),[t]);const u=st(e),h=k(u.refresh),g=k(u.retry),m=k(u.reset),x=k(u.loadNext),N=b(()=>n===void 0?void 0:{loadNext:x,state:d},[n,x,d]);return b(()=>({pagination:N,refresh:h,reset:m,retry:g,state:r}),[N,h,m,g,r])}const B=Object.freeze({});function J(t){return re(t,"slot")}function ct(t){const e=Z(t),n=new Map,s=i=>{const r=n.get(i);if(r!==void 0)return r;const o=J(`${e}/${i}`);return n.set(i,o),o};return Object.defineProperty(s,"id",{enumerable:!0,value:e}),Object.freeze(s)}function at(t){const e=H(t.target.entries),n="props"in t?t.props??B:B;return e.length===0?null:e.map(s=>P(X,{key:s.id},P(de,{authority:fe(s),contribution:s.value,contributionId:s.id,slotProps:n,targetId:t.target.id})))}export{f as ContributionError,at as Slot,J as defineSlot,ct as defineSwitchSlot,nt as requiresModels,Se as useCommand,tt as useModel,H as useReadable,ot as useResource,gt as useSelector};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/command-hook-controller.ts","../src/command-hook.ts","../src/idle-subscription.ts","../src/selection-hooks.ts","../src/model-selection-snapshot.ts","../src/model-selection-store.ts","../src/model-hook.ts","../src/requires-models.ts","../src/resource-hook.ts","../src/slot.tsx"],"sourcesContent":["import { CommandError } from '@opetope/core';\nimport { compatibleAbortReason, isCancellation, reportDetachedError } from '@opetope/core/internal';\nimport type { CommandInputArgs, CallRunOptions } from '@opetope/core/internal';\n\nimport type { CommandOutcome } from './command';\nimport { ContributionError } from './errors';\n\ntype CommandRunOptions<Output> = Readonly<{\n onFailure?: (error: unknown) => PromiseLike<void> | void;\n onSuccess?: (value: Output) => PromiseLike<void> | void;\n signal?: AbortSignal;\n}>;\n\ntype CommandRun<Input, Output> = {\n (input: Input, options?: CommandRunOptions<Output>): Promise<CommandOutcome<Output>>;\n (...args: [...CommandInputArgs<Input>, options?: CommandRunOptions<Output>]): Promise<CommandOutcome<Output>>;\n};\n\ntype CommandInvoker = Readonly<{\n run: (input: never, options?: CallRunOptions<unknown>) => Promise<unknown>;\n}>;\n\ntype CommandNotification<Output> = (inFlight: boolean, outcome?: CommandOutcome<Output>) => void;\n\ntype CommandRequest<Input, Output> = {\n input: Input | undefined;\n options: CommandRunOptions<Output> | undefined;\n readonly promise: Promise<CommandOutcome<Output>>;\n resolve: ((outcome: CommandOutcome<Output>) => void) | undefined;\n};\n\nfunction failureOutcome<Output>(options: CommandRunOptions<Output> | undefined, error: unknown): CommandOutcome<never> {\n if (isCancellation(error)) return { reason: error, kind: 'cancelled' };\n\n try {\n const notification = options?.onFailure?.(error);\n\n if (notification !== undefined) void Promise.resolve(notification).catch(reportDetachedError);\n } catch (callbackError) {\n reportDetachedError(callbackError);\n }\n\n return { error, kind: 'failed' };\n}\n\nfunction runOptions<Output>(options: CommandRunOptions<Output> | undefined): CallRunOptions<Output> | undefined {\n const onSuccess = options?.onSuccess;\n const signal = options?.signal;\n\n if (onSuccess === undefined) return signal === undefined ? undefined : { signal };\n\n return signal === undefined ? { onSuccess } : { onSuccess, signal };\n}\n\nfunction requestOf<Input, Output>(\n input: Input,\n options: CommandRunOptions<Output> | undefined,\n): CommandRequest<Input, Output> {\n let resolve!: (outcome: CommandOutcome<Output>) => void;\n const promise = new Promise<CommandOutcome<Output>>(settle => {\n resolve = settle;\n });\n\n return { input, options: options === undefined ? undefined : { ...options }, promise, resolve };\n}\n\nfunction settle<Input, Output>(request: CommandRequest<Input, Output>, outcome: CommandOutcome<Output>): void {\n const resolve = request.resolve;\n request.input = undefined;\n request.options = undefined;\n request.resolve = undefined;\n resolve?.(outcome);\n}\n\n/**\n * D203: the consumer keeps a status, not a schedule. Every `run` reaches the command, and what the command was\n * declared with — `concurrency`, `memoize`, `dedupe` — decides what happens to it. What stays\n * local is what only this consumer knows: whether it is mounted, its own input signal, and the outcome it shows.\n */\nclass CommandHookController<Input, Output> {\n readonly run: CommandRun<Input, Output> = ((input: Input, options?: CommandRunOptions<Output>) => {\n if (this.notify === undefined) {\n return Promise.resolve({\n reason: new ContributionError('inactive', 'Command consumer is not mounted.'),\n kind: 'cancelled' as const,\n });\n }\n\n const aborted = this.cancelledInput(options);\n\n if (aborted !== undefined) return Promise.resolve(aborted);\n\n const request = requestOf(input, options);\n this.start(request);\n\n return request.promise;\n }) as CommandRun<Input, Output>;\n private inFlight = 0;\n private notify: CommandNotification<Output> | undefined;\n\n constructor(private readonly invoker: CommandInvoker) {}\n\n attach(notify: CommandNotification<Output>): () => void {\n this.notify = notify;\n\n return () => {\n if (this.notify !== notify) return;\n\n this.notify = undefined;\n };\n }\n\n synchronize(): void {\n this.notify?.(this.inFlight > 0);\n }\n\n private aborted(signal: AbortSignal): CommandOutcome<never> {\n return {\n reason: new CommandError('cancelled', 'Command input was cancelled.', compatibleAbortReason(signal)),\n kind: 'cancelled',\n };\n }\n\n private cancelledInput(options: CommandRunOptions<Output> | undefined): CommandOutcome<never> | undefined {\n return options?.signal?.aborted === true ? this.aborted(options.signal) : undefined;\n }\n\n private finish(request: CommandRequest<Input, Output>, outcome: CommandOutcome<Output>): void {\n if (request.resolve === undefined) return;\n\n this.inFlight -= 1;\n settle(request, outcome);\n this.notify?.(this.inFlight > 0, outcome);\n }\n\n private invoke(request: CommandRequest<Input, Output>): void {\n let invocation: Promise<Output>;\n\n try {\n invocation = this.invoker.run(request.input as never, runOptions(request.options) as never) as Promise<Output>;\n request.input = undefined;\n } catch (error) {\n this.finish(request, failureOutcome(request.options, error));\n\n return;\n }\n\n void invocation.then(\n value => this.finish(request, { kind: 'ok', value }),\n (error: unknown) => this.finish(request, failureOutcome(request.options, error)),\n );\n }\n\n private start(request: CommandRequest<Input, Output>): void {\n this.inFlight += 1;\n // Reserve the flight before publishing: a reentrant run must already see this consumer as busy.\n this.notify?.(true);\n this.invoke(request);\n }\n}\n\nexport { CommandHookController };\nexport type { CommandInvoker, CommandRun };\n","import { useInsertionEffect, useLayoutEffect, useMemo, useState } from 'react';\n\nimport type { Command } from '@opetope/core';\n\nimport type { CommandOutcome } from './command';\nimport { CommandHookController } from './command-hook-controller';\nimport type { CommandInvoker, CommandRun } from './command-hook-controller';\nimport { ContributionError } from './errors';\nimport { useFrame } from './mount-context';\n\n/** D292: a cancellation is not an answer of the product, so it never settles into the outcome this hook shows. */\ntype SettledOutcome<Output> = Exclude<CommandOutcome<Output>, { readonly kind: 'cancelled' }>;\n\ninterface CommandHookStatus<Output> {\n readonly inFlight: boolean;\n readonly outcome: SettledOutcome<Output> | undefined;\n}\n\nconst emptyStatus: CommandHookStatus<never> = { inFlight: false, outcome: undefined };\n\ntype CommandHook<Input, Output> = CommandHookStatus<Output> & {\n readonly run: CommandRun<Input, Output>;\n};\n\ntype CommandHookState<Input, Output> = CommandHookStatus<Output> & {\n readonly slot: CommandHookController<Input, Output>;\n};\n\n/** D292: a cancellation moves nothing, so it is the same non-event as a notification without an outcome at all. */\nfunction settledOutcome<Output>(outcome: CommandOutcome<Output> | undefined): SettledOutcome<Output> | undefined {\n return outcome === undefined || outcome.kind === 'cancelled' ? undefined : outcome;\n}\n\nfunction unchangedState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n settled: SettledOutcome<Output> | undefined,\n): boolean {\n return settled === undefined && current.slot === slot && current.inFlight === inFlight;\n}\n\nfunction nextState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n outcome?: CommandOutcome<Output>,\n): CommandHookState<Input, Output> {\n const settled = settledOutcome(outcome);\n\n if (unchangedState(current, slot, inFlight, settled)) return current;\n\n // A new run clears nothing: the previous answer stays readable while its retry is in flight.\n const previous = current.slot === slot ? current.outcome : undefined;\n\n return { inFlight, outcome: settled ?? previous, slot };\n}\n\nfunction useCommandSlot<Input, Output>(invoker: CommandInvoker): CommandHookController<Input, Output> {\n // Slots are inert until commit. An interrupted render cannot fence the committed source or admit its own work.\n const [slots] = useState(() => new WeakMap<object, CommandHookController<Input, Output>>());\n let slot = slots.get(invoker);\n\n if (slot === undefined) {\n slot = new CommandHookController(invoker);\n slots.set(invoker, slot);\n }\n\n return slot;\n}\n\n/**\n * The status half of a consumer, apart from what it is a consumer of. D321 gives a resource the same two verbs a\n * command has, so the same three React hooks answer for them: the state of this consumer, the attachment that moves\n * it, and the synchronisation of a slot that was already busy when this mount arrived.\n */\nfunction useCommandStatus<Input, Output>(\n currentSlot: CommandHookController<Input, Output>,\n): CommandHook<Input, Output> {\n const [hookState, setHookState] = useState<CommandHookState<Input, Output>>(() => ({\n inFlight: false,\n outcome: undefined,\n slot: currentSlot,\n }));\n useInsertionEffect(\n () =>\n currentSlot.attach((inFlight, outcome) =>\n setHookState(current => nextState(current, currentSlot, inFlight, outcome)),\n ),\n [currentSlot],\n );\n useLayoutEffect(() => currentSlot.synchronize(), [currentSlot]);\n const { inFlight, outcome } = hookState.slot === currentSlot ? hookState : emptyStatus;\n const run = currentSlot.run;\n\n return useMemo(() => ({ inFlight, outcome, run }), [inFlight, outcome, run]);\n}\n\nfunction useCommand<Input, Output>(command: Command<Input, Output>): CommandHook<Input, Output> {\n const frame = useFrame();\n const record = frame.commandRecords.get(command);\n\n if (record === undefined) {\n throw new ContributionError('missing', `Command ${command.id} is not bound in this contribution.`);\n }\n\n return useCommandStatus(useCommandSlot<Input, Output>(record.invoker));\n}\n\nexport { useCommand, useCommandStatus };\nexport type { CommandHook };\n","const idleRelease = (): void => undefined;\nconst subscribeIdle = (): (() => void) => idleRelease;\nconst idleRevision = (): number => 0;\n\nexport { idleRevision, subscribeIdle };\n","import { useInsertionEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';\n\nimport type { Command } from '@opetope/core';\n\nimport type { CommandOutcome } from './command';\nimport type { CommandHook } from './command-hook';\nimport { CommandHookController } from './command-hook-controller';\nimport type { CommandInvoker } from './command-hook-controller';\nimport { ContributionError } from './errors';\nimport { idleRevision, subscribeIdle } from './idle-subscription';\nimport type { SelectedResource } from './model-selection-snapshot';\nimport { useFrame } from './mount-context';\nimport type { Frame } from './mount-frame';\nimport { resourceInvokers } from './resource-command';\nimport type { ResourceInvokers } from './resource-command';\n\ntype CommandSelection = Readonly<Record<string, Command<never, unknown>>>;\ntype ResourceSelection = ReadonlyMap<PropertyKey, SelectedResource>;\n/** D359: what one selected Resource answers — its three verbs, its state, and the pagination capability if it has one. */\ntype SelectedResourceHook = Readonly<{\n pagination: Readonly<{ loadNext: CommandHook<never, unknown>; state: unknown }> | undefined;\n refresh: CommandHook<never, unknown>;\n reset: CommandHook<never, unknown>;\n retry: CommandHook<never, unknown>;\n state: unknown;\n}>;\ntype SelectionHooks = Readonly<Record<PropertyKey, CommandHook<never, unknown> | SelectedResourceHook>>;\n\nconst emptyHooks: SelectionHooks = Object.freeze({});\n\ntype CommandEntry = {\n detach: (() => void) | undefined;\n hook: CommandHook<never, unknown>;\n readonly invoker: CommandInvoker;\n readonly slot: CommandHookController<never, unknown>;\n};\n\n/** D359: one key of a selection, four consumers. The record is the value; `entries` still holds one entry per key. */\ntype ResourceEntry = {\n /** D359: the value this key hands the render, kept on the record so a still frame is the same object again. */\n hook: SelectedResourceHook;\n readonly kind: 'resource';\n readonly loadNext: CommandEntry;\n /** Whether the declaration carried the pagination capability at all. */\n readonly paginated: boolean;\n readonly refresh: CommandEntry;\n readonly reset: CommandEntry;\n readonly retry: CommandEntry;\n};\n\ntype SelectionEntry = CommandEntry | ResourceEntry;\n\nfunction isResourceEntry(entry: SelectionEntry): entry is ResourceEntry {\n return 'kind' in entry;\n}\n\nfunction createEntry(invoker: CommandInvoker): CommandEntry {\n const slot = new CommandHookController<never, unknown>(invoker);\n\n return { detach: undefined, hook: { inFlight: false, outcome: undefined, run: slot.run }, invoker, slot };\n}\n\nfunction unchangedHook(previous: CommandHook<never, unknown>, next: CommandHook<never, unknown>): boolean {\n return previous.inFlight === next.inFlight && Object.is(previous.outcome, next.outcome);\n}\n\nfunction updateEntry(entry: CommandEntry, inFlight: boolean, outcome?: CommandOutcome<unknown>): boolean {\n const previous = entry.hook;\n\n if (outcome === undefined && previous.inFlight === inFlight) return false;\n\n // D292: only a settled non-cancelled outcome replaces the one this key shows; a retry keeps the previous answer.\n const settled = outcome === undefined || outcome.kind === 'cancelled' ? undefined : outcome;\n const next = { inFlight, outcome: settled ?? previous.outcome, run: previous.run };\n\n if (unchangedHook(previous, next)) return false;\n\n entry.hook = next;\n\n return true;\n}\n\nfunction selectEntry(previous: SelectionEntry | undefined, invoker: CommandInvoker): CommandEntry {\n return previous !== undefined && !isResourceEntry(previous) && previous.invoker === invoker\n ? previous\n : createEntry(invoker);\n}\n\nfunction resourceHook(entry: Omit<ResourceEntry, 'hook'>, selected: SelectedResource): SelectedResourceHook {\n return {\n pagination: entry.paginated ? { loadNext: entry.loadNext.hook, state: selected.pagination } : undefined,\n refresh: entry.refresh.hook,\n reset: entry.reset.hook,\n retry: entry.retry.hook,\n state: selected.state,\n };\n}\n\nfunction createResourceEntry(invokers: ResourceInvokers, selected: SelectedResource): ResourceEntry {\n const parts = {\n kind: 'resource' as const,\n loadNext: createEntry(invokers.loadNext),\n paginated: selected.pagination !== undefined,\n refresh: createEntry(invokers.refresh),\n reset: createEntry(invokers.reset),\n retry: createEntry(invokers.retry),\n };\n\n return { ...parts, hook: resourceHook(parts, selected) };\n}\n\n/** The four commands of a Resource: the three verbs every one has, and `loadNext` only where one was declared. */\nfunction unchangedResourceCommands(entry: ResourceEntry): boolean {\n const { hook } = entry;\n\n return (\n hook.refresh === entry.refresh.hook &&\n hook.reset === entry.reset.hook &&\n hook.retry === entry.retry.hook &&\n (!entry.paginated || hook.pagination?.loadNext === entry.loadNext.hook)\n );\n}\n\n/** What this selection read: the state of the Resource, and the state of its capability where it has one. */\nfunction unchangedResourceState(entry: ResourceEntry, selected: SelectedResource): boolean {\n return Object.is(entry.hook.state, selected.state) && Object.is(entry.hook.pagination?.state, selected.pagination);\n}\n\nfunction unchangedResourceHook(entry: ResourceEntry, selected: SelectedResource): boolean {\n return unchangedResourceCommands(entry) && unchangedResourceState(entry, selected);\n}\n\n/**\n * S6/D359: the same Resource that did not move answers the same object, so a child under `memo` is not re-rendered by\n * the mere act of reading it. Every part is a render input, so this is a memo and not a piece of state.\n */\nfunction selectResourceEntry(\n previous: SelectionEntry | undefined,\n invokers: ResourceInvokers,\n selected: SelectedResource,\n): ResourceEntry {\n if (previous === undefined || !isResourceEntry(previous) || previous.refresh.invoker !== invokers.refresh) {\n return createResourceEntry(invokers, selected);\n }\n\n if (!unchangedResourceHook(previous, selected)) previous.hook = resourceHook(previous, selected);\n\n return previous;\n}\n\nfunction commandEntries(entry: SelectionEntry): readonly CommandEntry[] {\n return isResourceEntry(entry) ? [entry.refresh, entry.reset, entry.retry, entry.loadNext] : [entry];\n}\n\nfunction detachEntry(entry: SelectionEntry): void {\n for (const command of commandEntries(entry)) {\n command.detach?.();\n command.detach = undefined;\n }\n}\n\nfunction hookOf(entry: SelectionEntry): CommandHook<never, unknown> | SelectedResourceHook {\n return entry.hook;\n}\n\n/** Selection is inert during render; only a committed selection can admit work or discard an old queue. */\nclass CommandGroup {\n private entries = new Map<PropertyKey, SelectionEntry>();\n /** One set of invokers per Resource identity, so `run` keeps its reference across renders (D359). */\n private readonly invokers = new WeakMap<object, ResourceInvokers>();\n private readonly listeners = new Set<() => void>();\n private revision = 0;\n\n close(): void {\n for (const entry of this.entries.values()) detachEntry(entry);\n\n this.entries.clear();\n }\n\n commit(selected: Map<PropertyKey, SelectionEntry>): void {\n for (const [key, entry] of this.entries) {\n if (selected.get(key) !== entry) detachEntry(entry);\n }\n\n this.entries = selected;\n\n for (const entry of selected.values()) this.attachEntry(entry);\n }\n\n /** S7: the attach runs on every commit, so the verbs are named rather than gathered into an array. */\n private attachEntry(entry: SelectionEntry): void {\n if (isResourceEntry(entry)) {\n this.attachCommand(entry.refresh);\n this.attachCommand(entry.retry);\n this.attachCommand(entry.reset);\n this.attachCommand(entry.loadNext);\n\n return;\n }\n\n this.attachCommand(entry);\n }\n\n private attachCommand(command: CommandEntry): void {\n command.detach ??= command.slot.attach((inFlight, outcome) => {\n if (!updateEntry(command, inFlight, outcome)) return;\n\n this.revision += 1;\n\n for (const listener of this.listeners) listener();\n });\n }\n\n getSnapshot = (): number => this.revision;\n\n /**\n * D321: two outcomes no longer, but two kinds. A command that is not bound is still a `ContributionError`; a\n * resource never appears in `frame.commandRecords`, so it is prepared from its own identity instead.\n */\n prepare(commands: CommandSelection, resources: ResourceSelection, frame: Frame): Map<PropertyKey, SelectionEntry> {\n const selected = new Map<PropertyKey, SelectionEntry>();\n\n for (const key of Reflect.ownKeys(commands)) {\n if (!Object.prototype.propertyIsEnumerable.call(commands, key)) continue;\n\n const command = (commands as Readonly<Record<PropertyKey, Command<never, unknown>>>)[key];\n const record = command === undefined ? undefined : frame.commandRecords.get(command);\n\n if (record === undefined) {\n throw new ContributionError('missing', `Command at ${String(key)} is not bound in this contribution.`);\n }\n\n selected.set(key, selectEntry(this.entries.get(key), record.invoker));\n }\n\n for (const [key, resource] of resources) {\n const invokers = resourceInvokers(resource.resource, this.invokers);\n\n selected.set(key, selectResourceEntry(this.entries.get(key), invokers, resource));\n }\n\n return selected;\n }\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n}\n\nfunction useCommandGroup(commands: CommandSelection, resources: ResourceSelection): CommandGroup | undefined {\n const groupRef = useRef<CommandGroup | undefined>(undefined);\n const populated =\n resources.size > 0 ||\n Reflect.ownKeys(commands).some(key => Object.prototype.propertyIsEnumerable.call(commands, key));\n\n return populated ? (groupRef.current ??= new CommandGroup()) : undefined;\n}\n\n/** The consumers of one selection: a command per key, and the two verbs of a resource per key (D321). */\nfunction useSelectionHooks(commands: CommandSelection, resources: ResourceSelection): SelectionHooks {\n const frame = useFrame();\n const group = useCommandGroup(commands, resources);\n const getSnapshot = group?.getSnapshot ?? idleRevision;\n useSyncExternalStore(group?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const selected = group?.prepare(commands, resources, frame);\n useInsertionEffect(() => () => group?.close(), [group]);\n useInsertionEffect(() => {\n if (selected !== undefined) group?.commit(selected);\n });\n useLayoutEffect(() => {\n if (selected === undefined) return;\n\n // S7: the same branch as the attach — this runs after every commit, and the arrays were pure allocation.\n for (const entry of selected.values()) {\n if (isResourceEntry(entry)) {\n entry.refresh.slot.synchronize();\n entry.retry.slot.synchronize();\n entry.reset.slot.synchronize();\n entry.loadNext.slot.synchronize();\n } else entry.slot.synchronize();\n }\n });\n\n return selected === undefined\n ? emptyHooks\n : Object.fromEntries([...selected].map(([key, entry]) => [key, hookOf(entry)]));\n}\n\nexport { useSelectionHooks };\nexport type { SelectionHooks };\n","import type { Readable } from '@opetope/core';\nimport { isCallTarget, isReadable } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\nimport type { AnyCommand } from './model-binding';\nimport { isResource } from './resource-command';\nimport type { AnyResource } from './resource-command';\n\ninterface SelectionRead {\n <Value>(source: Readable<Value>): Value;\n <Value, Selected>(source: Readable<Value>, select: (value: Value) => Selected): Selected;\n}\n\ntype SelectionContext = Readonly<{ read: SelectionRead }>;\ntype NonSelectionRecord =\n | readonly unknown[]\n | ((...arguments_: never[]) => unknown)\n | (abstract new (...arguments_: never[]) => unknown)\n | Date\n | PromiseLike<unknown>\n | ReadonlyMap<unknown, unknown>\n | ReadonlySet<unknown>\n | RegExp\n | WeakMap<object, unknown>\n | WeakSet<object>;\n/** A named interface needs no open index signature; container and callable results are not field selections. */\ntype SelectionShape<Selected extends object> = Selected extends NonSelectionRecord ? never : Selected;\ntype SelectionRecord = Readonly<Record<PropertyKey, unknown>>;\n/**\n * D359: the Resource a field selected, and what this selection read from it — its state, and the state of its\n * pagination capability when it has one. Both are read passively: a selection takes no lease by reading.\n */\ntype SelectedResource = Readonly<{ pagination: unknown; resource: AnyResource; state: unknown }>;\ntype SelectionSnapshot = Readonly<{\n commands: Readonly<Record<PropertyKey, AnyCommand>>;\n /** The set the mount leases; two keys naming one resource are one lease. */\n leases: ReadonlySet<AnyResource>;\n resources: ReadonlyMap<PropertyKey, SelectedResource>;\n sources: ReadonlySet<Readable<unknown>>;\n values: SelectionRecord;\n}>;\n\nconst noResources: ReadonlyMap<PropertyKey, SelectedResource> = new Map();\n\n/**\n * D363: what this mount read last and the snapshot it answered with. It belongs to the mount and not to the reader:\n * React may discard the `useMemo` that builds the reader, and a memory kept there would be empty exactly when it is\n * needed. D364: it no longer remembers which sources ended — a source whose owner retired stops instead of refusing,\n * so it answers its last value on every read and there is nothing to remember or to step around.\n */\ntype SelectionMemory = {\n model: unknown;\n observed: Map<Readable<unknown>, unknown> | undefined;\n select: unknown;\n snapshot: SelectionSnapshot;\n};\n\nconst noLeases: ReadonlySet<AnyResource> = new Set();\n\nfunction readSource<Value>(source: Readable<Value>, sources: Map<Readable<unknown>, unknown>): Value {\n if (!isReadable(source)) {\n throw new ContributionError('binding-invalid', 'Model selection read requires a Readable.');\n }\n\n if (sources.has(source)) return sources.get(source) as Value;\n\n // D364: a refusal here is the source's own failure and belongs to the render, because no lifetime ends in one.\n const value: unknown = source.getSnapshot();\n sources.set(source, value);\n\n return value as Value;\n}\n\nfunction readPassively(source: Readable<unknown>, sources: Map<Readable<unknown>, unknown>): unknown {\n if (sources.has(source)) return sources.get(source);\n\n const value: unknown = source.getSnapshot();\n sources.set(source, value);\n\n return value;\n}\n\n/** D359: the predicate that answers the question the type of the field asked, and the read that leases nothing. */\nfunction classifyResource(\n key: PropertyKey,\n value: unknown,\n resources: Map<PropertyKey, SelectedResource>,\n sources: Map<Readable<unknown>, unknown>,\n): void {\n if (!isResource(value)) return;\n\n const resource = value as AnyResource;\n const capability = (resource as { readonly pagination?: { readonly state: Readable<unknown> } }).pagination;\n\n resources.set(key, {\n pagination: capability === undefined ? undefined : readPassively(capability.state, sources),\n resource,\n state: readPassively(resource.state, sources),\n });\n}\n\nfunction selectedResources(resources: Map<PropertyKey, SelectedResource>): ReadonlyMap<PropertyKey, SelectedResource> {\n return resources.size === 0 ? noResources : resources;\n}\n\ntype CollectedSelection = Readonly<{\n resources: ReadonlyMap<PropertyKey, SelectedResource>;\n values: SelectionRecord;\n}>;\n\n/**\n * D359: recognition happens in the one pass that already walks the selection. `Resource` is a structural contract\n * (D199) and the type of a selected field promises `ResourceHook` for anything that satisfies it, so the predicate\n * this uses answers the same question the type asked. Reading the state here also puts it among `sources`, so its\n * publication invalidates the fast path of this reader exactly as a read source does.\n */\nfunction collectSelection(\n select: (context: SelectionContext) => object,\n sources: Map<Readable<unknown>, unknown>,\n): CollectedSelection {\n const read = <Value, Selected>(source: Readable<Value>, project?: (value: Value) => Selected) => {\n const value = readSource(source, sources);\n\n return project === undefined ? value : project(value);\n };\n const selected = select({ read });\n\n if (typeof selected !== 'object' || selected === null || Array.isArray(selected)) {\n throw new ContributionError('binding-invalid', 'Model selection requires a record.');\n }\n\n const entries: (readonly [PropertyKey, unknown])[] = [];\n const resources = new Map<PropertyKey, SelectedResource>();\n\n for (const key of Reflect.ownKeys(selected)) {\n if (!Object.prototype.propertyIsEnumerable.call(selected, key)) continue;\n\n const value = (selected as SelectionRecord)[key];\n\n entries.push([key, value]);\n classifyResource(key, value, resources, sources);\n }\n\n // `__proto__` is a key like any other here, and only a defined property keeps it one (D214).\n return { resources: selectedResources(resources), values: Object.fromEntries(entries) };\n}\n\n/**\n * D359: `values` keeps the Resource itself — a stable reference — so a selection that holds one is compared by\n * `Object.is` exactly as before. What moves is the state behind it, and that is compared here: without this the\n * selection would be «equal», the previous state would be kept, and a published Resource would reach no render.\n */\nfunction equalResources(\n previous: ReadonlyMap<PropertyKey, SelectedResource>,\n next: ReadonlyMap<PropertyKey, SelectedResource>,\n): boolean {\n if (previous.size !== next.size) return false;\n\n for (const [key, selected] of next) {\n const before = previous.get(key);\n\n if (\n before?.resource !== selected.resource ||\n !Object.is(before.state, selected.state) ||\n !Object.is(before.pagination, selected.pagination)\n ) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction equalSelection(\n previous: SelectionSnapshot,\n values: SelectionRecord,\n sources: ReadonlySet<Readable<unknown>>,\n resources: ReadonlyMap<PropertyKey, SelectedResource>,\n) {\n const keys = Reflect.ownKeys(values);\n const previousKeys = Reflect.ownKeys(previous.values);\n\n if (keys.length !== previousKeys.length || sources.size !== previous.sources.size) return false;\n\n for (const source of sources) if (!previous.sources.has(source)) return false;\n\n if (!equalResources(previous.resources, resources)) return false;\n\n return keys.every((key, index) => previousKeys[index] === key && Object.is(previous.values[key], values[key]));\n}\n\ntype ModelSelector<Model> = (model: Model, context: SelectionContext) => object;\ntype SelectionReaderRef<Model> = { readonly current: ModelSelector<Model> | undefined };\n\nconst emptySelectionSnapshot: SelectionSnapshot = {\n commands: {},\n leases: noLeases,\n resources: noResources,\n sources: new Set(),\n values: {},\n};\n\nfunction selectionCommands(values: SelectionRecord): Readonly<Record<PropertyKey, AnyCommand>> {\n return Object.fromEntries(\n Reflect.ownKeys(values)\n .filter(key => isCallTarget(values[key]))\n .map(key => [key, values[key]]),\n ) as Readonly<Record<PropertyKey, AnyCommand>>;\n}\n\nfunction selectionLeases(resources: ReadonlyMap<PropertyKey, SelectedResource>): ReadonlySet<AnyResource> {\n if (resources.size === 0) return noLeases;\n\n const leased = new Set<AnyResource>();\n\n for (const selected of resources.values()) leased.add(selected.resource);\n\n return leased;\n}\n\n/**\n * The fast path re-reads what it observed. D364: a source that stopped answers the same value it answered last, so\n * it compares equal and costs one read — there is no terminal source to record and step around any more.\n */\nfunction observedUnchanged(observed: Map<Readable<unknown>, unknown>): boolean {\n for (const [source, value] of observed) {\n if (!Object.is(source.getSnapshot(), value)) return false;\n }\n\n return true;\n}\n\n/** D363: the memory of one mount, empty until its first read and reset when the reader is built for another model. */\nfunction createSelectionMemory(): SelectionMemory {\n return { model: undefined, observed: undefined, select: undefined, snapshot: emptySelectionSnapshot };\n}\n\n/**\n * D214: one reader per model, not per render. The author's selector arrives through a ref, so an inline arrow does not\n * rebuild the reader; the fast path — nothing observed has moved — belongs to the selector that computed the snapshot,\n * so a new selector is always called again, its result compared field by field, and an equal selection keeps the\n * previous snapshot. A rejected or abandoned render still changes nothing: only a committed selection subscribes.\n *\n * D363: what the reader remembers lives in the mount's memory, so a reader React rebuilt — because it discarded the\n * memo — still knows what this selection read last.\n */\nfunction createSelectionSnapshot<Model>(\n model: Model,\n selectRef: SelectionReaderRef<Model>,\n memory: SelectionMemory,\n): () => SelectionSnapshot {\n if (memory.model !== model) {\n memory.model = model;\n memory.observed = undefined;\n memory.select = undefined;\n memory.snapshot = emptySelectionSnapshot;\n }\n\n return () => {\n const select = selectRef.current;\n\n if (select === undefined) return emptySelectionSnapshot;\n\n const observed = memory.observed;\n\n if (observed !== undefined && memory.select === select && observedUnchanged(observed)) {\n return memory.snapshot;\n }\n\n const nextObserved = new Map<Readable<unknown>, unknown>();\n const { resources, values } = collectSelection(context => select(model, context), nextObserved);\n const sources = new Set(nextObserved.keys());\n\n if (observed === undefined || !equalSelection(memory.snapshot, values, sources, resources)) {\n memory.snapshot = {\n commands: selectionCommands(values),\n leases: selectionLeases(resources),\n resources,\n sources,\n values,\n };\n }\n\n memory.observed = nextObserved;\n memory.select = select;\n\n return memory.snapshot;\n };\n}\n\nexport { createSelectionMemory, createSelectionSnapshot, emptySelectionSnapshot };\nexport type { ModelSelector, SelectedResource, SelectionContext, SelectionMemory, SelectionShape, SelectionSnapshot };\n","import type { Readable } from '@opetope/core';\nimport { createAggregateError } from '@opetope/core/internal';\n\nimport type { AnyResource } from './resource-command';\n\ntype Subscription = { dispose: (() => void) | undefined };\ntype Listener = Readonly<{ notify: () => void }>;\n\nconst noLeases: ReadonlySet<AnyResource> = new Set();\n\nfunction releaseSubscriptions(subscriptions: Iterable<Subscription>, failures: unknown[] = []): void {\n for (const subscription of subscriptions) {\n const dispose = subscription.dispose;\n subscription.dispose = undefined;\n\n try {\n dispose?.();\n } catch (error) {\n failures.push(error);\n }\n }\n\n if (failures.length === 1) throw failures[0];\n\n if (failures.length > 1) throw createAggregateError(failures, 'Model selection sources failed to release.');\n}\n\n/** A subscription set, not a scheduler: source notifications use React's snapshot consistency check. */\nclass ModelSelectionStore {\n private enabled = false;\n /** D359: one lease per Resource identity, diffed like a subscription, so an unchanged selection takes none. */\n private readonly leases = new Map<AnyResource, Subscription>();\n private readonly listeners = new Set<Listener>();\n private retained: ReadonlySet<AnyResource> = noLeases;\n private sources: ReadonlySet<Readable<unknown>> = new Set();\n private readonly subscriptions = new Map<Readable<unknown>, Subscription>();\n\n close(): void {\n this.enabled = false;\n this.sources = new Set();\n this.retained = noLeases;\n this.releaseAll();\n }\n\n commit(sources: ReadonlySet<Readable<unknown>>, retained: ReadonlySet<AnyResource> = noLeases): void {\n this.sources = sources;\n this.retained = retained;\n this.enabled = true;\n\n try {\n this.synchronize();\n } catch (error) {\n this.releaseAll([error]);\n }\n }\n\n subscribe = (notify: () => void): (() => void) => {\n const listener = { notify };\n this.listeners.add(listener);\n\n try {\n this.synchronize();\n } catch (error) {\n this.listeners.delete(listener);\n this.releaseAll([error]);\n }\n\n return () => {\n this.listeners.delete(listener);\n\n if (this.listeners.size === 0) this.releaseAll();\n };\n };\n\n private add(source: Readable<unknown>): void {\n const subscription: Subscription = { dispose: undefined };\n // Reserve before foreign code: a synchronous notification may replace or close this selection.\n this.subscriptions.set(source, subscription);\n const dispose = source.subscribe(this.notify);\n\n if (typeof dispose !== 'function') throw new TypeError('Model selection source must return a disposer.');\n\n if (this.subscriptions.get(source) === subscription) subscription.dispose = dispose;\n else dispose();\n }\n\n private notify = (): void => {\n for (const listener of [...this.listeners]) {\n if (this.listeners.has(listener)) listener.notify();\n }\n };\n\n private releaseAll(failures?: unknown[]): void {\n const held = [...this.subscriptions.values(), ...this.leases.values()];\n this.subscriptions.clear();\n this.leases.clear();\n releaseSubscriptions(held, failures);\n }\n\n private removeUnselected(): void {\n const removed: Subscription[] = [];\n\n for (const [source, subscription] of this.subscriptions) {\n if (this.sources.has(source)) continue;\n\n this.subscriptions.delete(source);\n removed.push(subscription);\n }\n\n for (const [resource, lease] of this.leases) {\n if (this.retained.has(resource)) continue;\n\n this.leases.delete(resource);\n removed.push(lease);\n }\n\n releaseSubscriptions(removed);\n }\n\n /**\n * D321: `retain()` is reentrant — it reaches `activate()`, the target subscription, the first read and the\n * publication that follows, all synchronously — and a listener woken there may rebuild or close this selection.\n * The record is reserved first, the lease is taken second, and it is kept only if the record is still this one.\n */\n private retain(resource: AnyResource): void {\n const lease: Subscription = { dispose: undefined };\n this.leases.set(resource, lease);\n const release = resource.acquire();\n\n if (typeof release !== 'function') throw new TypeError('Model selection resource must answer a release disposer.');\n\n if (this.leases.get(resource) === lease) lease.dispose = release;\n else release();\n }\n\n /** Foreign code inside a subscription or a lease may replace this selection, so both loops ask again. */\n private ready(): boolean {\n return this.enabled && this.listeners.size > 0;\n }\n\n private retainSelected(): void {\n for (const resource of this.retained) {\n if (!this.ready()) return;\n\n if (this.retained.has(resource) && !this.leases.has(resource)) this.retain(resource);\n }\n }\n\n private subscribeSources(): void {\n for (const source of this.sources) {\n if (!this.ready()) return;\n\n if (this.sources.has(source) && !this.subscriptions.has(source)) this.add(source);\n }\n }\n\n private synchronize(): void {\n this.removeUnselected();\n this.subscribeSources();\n this.retainSelected();\n }\n}\n\nexport { ModelSelectionStore };\n","import { useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Command, ModelOf, PaginatedResource, Resource } from '@opetope/core';\n\nimport type { CommandHook } from './command-hook';\nimport { useSelectionHooks } from './selection-hooks';\nimport type { SelectionHooks } from './selection-hooks';\nimport { ContributionError } from './errors';\nimport { subscribeIdle } from './idle-subscription';\nimport type { AnyModel } from './model-binding';\nimport { createSelectionMemory, createSelectionSnapshot, emptySelectionSnapshot } from './model-selection-snapshot';\nimport type {\n ModelSelector,\n SelectionContext,\n SelectionMemory,\n SelectionShape,\n SelectionSnapshot,\n} from './model-selection-snapshot';\nimport { ModelSelectionStore } from './model-selection-store';\nimport { useFrame } from './mount-context';\nimport type { PaginatedResourceHook, ResourceHook, ResourceKey } from './resource-command';\n\n/**\n * D359: a field whose value is a Resource answers the hook `useResource` answers, and the mount leases it exactly as\n * `useResource` does. `read(resource.state)` is unchanged — it hands out the state and leases nothing — so naming one\n * Resource both ways registers it twice: the subscription and the lease are independent.\n */\ntype SelectedValue<Value> =\n Value extends Command<infer Input, infer Output>\n ? CommandHook<Input, Output>\n : Value extends PaginatedResource<infer Data, infer Key extends ResourceKey, infer Cursor extends ResourceKey>\n ? PaginatedResourceHook<Data, Key, Cursor>\n : Value extends Resource<infer Data, infer Key extends ResourceKey>\n ? ResourceHook<Data, Key>\n : Value;\ntype ModelSelection<Selected> = { readonly [Key in keyof Selected]: SelectedValue<Selected[Key]> };\n\nconst readEmptySnapshot = () => emptySelectionSnapshot;\n\nfunction useSelectionStore(selected: boolean): ModelSelectionStore | undefined {\n const storeRef = useRef<ModelSelectionStore | undefined>(undefined);\n\n return selected ? (storeRef.current ??= new ModelSelectionStore()) : undefined;\n}\n\n/**\n * Two branches of one key: the consumer this selection prepared — a bound command, or the verbs, the state and the\n * capability of a selected Resource — and otherwise the value the selector wrote. S6/D359: the Resource branch is\n * assembled on the record and not here, so a key whose state did not move hands back the very same object.\n */\nfunction mergeSelection(snapshot: SelectionSnapshot, hooks: SelectionHooks): unknown {\n return Object.fromEntries(\n Reflect.ownKeys(snapshot.values).map(key => [\n key,\n Object.prototype.hasOwnProperty.call(hooks, key) ? hooks[key] : snapshot.values[key],\n ]),\n );\n}\n\n/** D205: resolve only a granted model, explicitly read data, and reuse the ordinary per-key command consumers. */\nfunction useModel<Declaration extends AnyModel>(declaration: Declaration): ModelOf<Declaration>;\nfunction useModel<Declaration extends AnyModel, const Selected extends object>(\n declaration: Declaration,\n select: (model: ModelOf<Declaration>, context: SelectionContext) => Selected & SelectionShape<Selected>,\n): ModelSelection<Selected>;\nfunction useModel<Declaration extends AnyModel>(\n declaration: Declaration,\n select?: (model: ModelOf<Declaration>, context: SelectionContext) => object,\n): unknown {\n const frame = useFrame();\n\n if (!frame.models.has(declaration)) {\n throw new ContributionError('missing', `Model ${declaration.id} is not granted to this contribution.`);\n }\n\n const model = frame.models.get(declaration) as ModelOf<Declaration>;\n const store = useSelectionStore(select !== undefined);\n // D214: the selector of this render, read by a reader that belongs to the model. Writing the latest callback into\n // a ref is what `useSyncExternalStoreWithSelector` does: the reader only reads it, and never writes to it.\n const selectRef = useRef<ModelSelector<ModelOf<Declaration>> | undefined>(undefined);\n selectRef.current = select;\n const selected = select !== undefined;\n // D363: the memory of this selection belongs to the mount, so a reader React rebuilt keeps what it read last.\n const memoryRef = useRef<SelectionMemory | undefined>(undefined);\n const memory = (memoryRef.current ??= createSelectionMemory());\n const getSnapshot = useMemo(\n () => (selected ? createSelectionSnapshot(model, selectRef, memory) : readEmptySnapshot),\n [memory, model, selected],\n );\n const snapshot = useSyncExternalStore(store?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const hooks = useSelectionHooks(snapshot.commands, snapshot.resources);\n useLayoutEffect(() => () => store?.close(), [store]);\n // D359: a lease is taken in commit and never in a render, and the store diffs the set by identity.\n useLayoutEffect(() => store?.commit(snapshot.sources, snapshot.leases), [snapshot, store]);\n\n if (select === undefined) return model;\n\n return mergeSelection(snapshot, hooks);\n}\n\nexport { useModel };\n","import type { FunctionComponent } from 'react';\n\nimport type { ModelIdentity } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\n\ntype AnyModel = ModelIdentity;\n\n/**\n * The marker a component uses to state which UI models of its contribution it reads. `slot` checks by type that the\n * contribution grants every model of this list — it may grant more, because the mount serves its whole instance.\n *\n * The runtime authority is the mount frame, not this marker: `useModel` resolves against what the mount was given\n * and refuses anything else. The lint rule `opetope/require-declared-models` checks visible contribution sites and\n * each reader of a per-mount model within the same module. Imported implementations and dynamic declaration lists\n * remain unknown to this syntactic check (D85, D158, D250).\n */\ntype ComponentRequiringModels<Props, Models extends readonly AnyModel[]> = FunctionComponent<Props> & {\n readonly requires: Models;\n};\n\nfunction requiresModels<const Models extends readonly AnyModel[]>(\n models: Models,\n): <Props>(component: FunctionComponent<Props>) => ComponentRequiringModels<Props, Models> {\n const declared = Object.freeze([...models]) as unknown as Models;\n\n return <Props>(component: FunctionComponent<Props>): ComponentRequiringModels<Props, Models> => {\n const existing = (component as { readonly requires?: readonly AnyModel[] }).requires;\n\n if (existing !== undefined) {\n throw new ContributionError('duplicate', 'Component already declares the models it requires.');\n }\n\n Object.defineProperty(component, 'requires', { enumerable: false, value: declared });\n\n return component as ComponentRequiringModels<Props, Models>;\n };\n}\n\nexport { requiresModels };\n","import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react';\n\nimport type { PaginatedResource, PaginationState, Readable, Resource } from '@opetope/core';\nimport type { ResourceKey } from '@opetope/core/internal';\n\nimport { useCommandStatus } from './command-hook';\nimport { CommandHookController } from './command-hook-controller';\nimport { createResourceInvokers, paginationOf } from './resource-command';\nimport type { AnyResource, PaginatedResourceHook, ResourceHook, ResourcePaginationHook } from './resource-command';\n\ntype ResourceSlots = Readonly<{\n loadNext: CommandHookController<void, unknown>;\n refresh: CommandHookController<void, unknown>;\n reset: CommandHookController<void, unknown>;\n retry: CommandHookController<void, unknown>;\n}>;\n\n/**\n * D359: one set of controllers per Resource identity, exactly as `useCommandSlot` keeps one per invoker. The slots are\n * what the set of invokers is kept alive by, so one map answers for all four. Slots are inert until commit, so an\n * interrupted render neither admits work nor resets the status of the committed one.\n */\nfunction useResourceSlots(resource: AnyResource): ResourceSlots {\n const [cache] = useState(() => new WeakMap<object, ResourceSlots>());\n const existing = cache.get(resource);\n\n if (existing !== undefined) return existing;\n\n const invokers = createResourceInvokers(resource);\n const slots: ResourceSlots = {\n loadNext: new CommandHookController<void, unknown>(invokers.loadNext),\n refresh: new CommandHookController<void, unknown>(invokers.refresh),\n reset: new CommandHookController<void, unknown>(invokers.reset),\n retry: new CommandHookController<void, unknown>(invokers.retry),\n };\n cache.set(resource, slots);\n\n return slots;\n}\n\nconst unavailablePagination: PaginationState<ResourceKey> = Object.freeze({\n kind: 'unavailable',\n reason: 'resource-not-ready',\n});\nconst noPaginationSource: Readable<PaginationState<ResourceKey>> = Object.freeze({\n getSnapshot: () => unavailablePagination,\n subscribe: () => () => undefined,\n});\n\n/**\n * D359: the state of a Resource, the lease that keeps it open for as long as this component is mounted, and its verbs\n * as commands. The number of React hooks here does not depend on the Resource: a declaration without `pagination`\n * subscribes to a constant source and keeps a `loadNext` that answers `skipped`.\n */\nfunction useResource<Data, Key extends ResourceKey, Cursor extends ResourceKey>(\n resource: PaginatedResource<Data, Key, Cursor>,\n): PaginatedResourceHook<Data, Key, Cursor>;\nfunction useResource<Data, Key extends ResourceKey>(resource: Resource<Data, Key>): ResourceHook<Data, Key>;\nfunction useResource<Data, Key extends ResourceKey>(resource: Resource<Data, Key>): ResourceHook<Data, Key> {\n const handle = resource as unknown as AnyResource;\n const capability = paginationOf(handle);\n const subscribe = useCallback((listener: () => void) => resource.state.subscribe(listener), [resource]);\n /*\n * D364: `resource.state` is a total `Readable` for the life of the object this hook holds — a retired one answers\n * `idle('retired')` — so the read needs no memory of its own. What it can still refuse is a producer failure, a\n * broken `nextCursor` among them (D356), and that belongs to the render (G13).\n */\n const getState = useMemo(() => () => resource.state.getSnapshot(), [resource]);\n const state = useSyncExternalStore(subscribe, getState, getState);\n const paginationSource: Readable<PaginationState<ResourceKey>> =\n (capability?.state as Readable<PaginationState<ResourceKey>> | undefined) ?? noPaginationSource;\n const subscribePagination = useCallback(\n (listener: () => void) => paginationSource.subscribe(listener),\n [paginationSource],\n );\n const getPaginationState = useMemo(() => () => paginationSource.getSnapshot(), [paginationSource]);\n const paginationState = useSyncExternalStore(subscribePagination, getPaginationState, getPaginationState);\n\n // D349: the lease is taken in a commit effect, so an interrupted render opens nothing.\n useEffect(() => resource.acquire(), [resource]);\n\n const slots = useResourceSlots(handle);\n const refresh = useCommandStatus(slots.refresh);\n const retry = useCommandStatus(slots.retry);\n const reset = useCommandStatus(slots.reset);\n const loadNext = useCommandStatus(slots.loadNext);\n const pagination = useMemo(\n () =>\n capability === undefined\n ? undefined\n : ({ loadNext, state: paginationState } as unknown as ResourcePaginationHook<ResourceKey>),\n [capability, loadNext, paginationState],\n );\n\n return useMemo(\n () => ({ pagination, refresh, reset, retry, state }) as ResourceHook<Data, Key>,\n [pagination, refresh, reset, retry, state],\n );\n}\n\nexport { useResource };\n","import type { ComponentType, ReactNode } from 'react';\nimport { createElement, Fragment } from 'react';\n\nimport type { DeclarationId } from '@opetope/core';\nimport { declarationId } from '@opetope/core';\nimport type { ContributionTarget } from '@opetope/core/internal';\nimport { createContributionTarget } from '@opetope/core/internal';\nimport type { ContributionModel } from '@opetope/runtime/internal';\n\nimport { contributionAuthority, ContributionMount } from './contribution-frame';\nimport { useReadable } from './readable-hooks';\n\ntype SlotProperties = object | undefined;\ntype EmptySlotProperties = Readonly<Record<string, never>>;\ntype SlotComponentProperties<Props extends SlotProperties> = [Props] extends [undefined]\n ? EmptySlotProperties\n : Extract<Props, object>;\n\n/**\n * What a contribution publishes: the component, the optional props adapter and the optional UI models the mount\n * creates. Without an adapter the component takes the slot props; with one it takes exactly the adapter result (D85).\n */\ntype SlotContribution<Props extends SlotProperties = undefined> = {\n readonly Component: ComponentType<never>;\n readonly models?: readonly ContributionModel[];\n readonly props?: (slotProps: SlotComponentProperties<Props>) => object;\n};\n\ntype SlotTarget<Props extends SlotProperties = undefined> = ContributionTarget<SlotContribution<Props>>;\n\ntype SwitchSlotTarget<Route extends string, Props extends SlotProperties = undefined> = ((\n route: Route,\n) => SlotTarget<Props>) & {\n readonly id: DeclarationId;\n};\n\ntype SlotRenderProps<Props extends SlotProperties> = [Props] extends [undefined]\n ? {\n readonly props?: never;\n readonly target: SlotTarget<Props>;\n }\n : {\n readonly props: SlotComponentProperties<Props>;\n readonly target: SlotTarget<Props>;\n };\n\nconst emptySlotProperties: EmptySlotProperties = Object.freeze({});\n\n/** D280: a slot is a name, so it takes its id as the first argument. */\nfunction defineSlot<Props extends SlotProperties = undefined>(id: string): SlotTarget<Props> {\n return createContributionTarget<SlotContribution<Props>>(id, 'slot');\n}\n\nfunction defineSwitchSlot<Route extends string, Props extends SlotProperties = undefined>(\n id: string,\n): SwitchSlotTarget<Route, Props> {\n const declared = declarationId(id);\n const targets = new Map<Route, SlotTarget<Props>>();\n\n const switchSlot = (route: Route): SlotTarget<Props> => {\n const existing = targets.get(route);\n\n if (existing !== undefined) return existing;\n\n const target = defineSlot<Props>(`${declared}/${route}`);\n targets.set(route, target);\n\n return target;\n };\n\n Object.defineProperty(switchSlot, 'id', { enumerable: true, value: declared });\n\n return Object.freeze(switchSlot) as SwitchSlotTarget<Route, Props>;\n}\n\n/**\n * Every contribution renders inside its own mount: the models its generation owns plus the UI models it declared,\n * created on mount and closed on unmount (D70, D85).\n */\nfunction Slot<Props extends SlotProperties>(options: SlotRenderProps<Props>): ReactNode {\n const entries = useReadable(options.target.entries);\n const slotProps: object = 'props' in options ? (options.props ?? emptySlotProperties) : emptySlotProperties;\n\n if (entries.length === 0) return null;\n\n return entries.map(entry =>\n createElement(\n Fragment,\n { key: entry.id },\n createElement(ContributionMount, {\n authority: contributionAuthority(entry),\n contribution: entry.value,\n contributionId: entry.id,\n slotProps,\n targetId: options.target.id,\n }),\n ),\n );\n}\n\nexport { defineSlot, defineSwitchSlot, Slot };\nexport type { SlotComponentProperties, SlotContribution, SlotProperties, SlotTarget, SwitchSlotTarget };\n"],"names":["failureOutcome","options","error","isCancellation","notification","_a","reportDetachedError","callbackError","runOptions","onSuccess","signal","requestOf","input","resolve","promise","settle","request","outcome","CommandHookController","ContributionError","aborted","invoker","notify","CommandError","compatibleAbortReason","invocation","value","emptyStatus","settledOutcome","unchangedState","current","slot","inFlight","settled","nextState","previous","useCommandSlot","slots","useState","useCommandStatus","currentSlot","hookState","setHookState","useInsertionEffect","useLayoutEffect","run","useMemo","useCommand","command","record","useFrame","idleRelease","subscribeIdle","idleRevision","emptyHooks","isResourceEntry","entry","createEntry","unchangedHook","next","updateEntry","selectEntry","resourceHook","selected","createResourceEntry","invokers","parts","unchangedResourceCommands","hook","unchangedResourceState","unchangedResourceHook","selectResourceEntry","commandEntries","detachEntry","hookOf","CommandGroup","key","listener","commands","resources","frame","resource","resourceInvokers","useCommandGroup","groupRef","useRef","useSelectionHooks","group","getSnapshot","useSyncExternalStore","noResources","noLeases","readSource","source","sources","isReadable","readPassively","classifyResource","isResource","capability","selectedResources","collectSelection","select","project","entries","equalResources","before","equalSelection","values","keys","previousKeys","index","emptySelectionSnapshot","selectionCommands","isCallTarget","selectionLeases","leased","observedUnchanged","observed","createSelectionMemory","createSelectionSnapshot","model","selectRef","memory","nextObserved","context","releaseSubscriptions","subscriptions","failures","subscription","dispose","createAggregateError","ModelSelectionStore","retained","held","removed","lease","release","readEmptySnapshot","useSelectionStore","storeRef","mergeSelection","snapshot","hooks","useModel","declaration","store","memoryRef","requiresModels","models","declared","component","useResourceSlots","cache","existing","createResourceInvokers","unavailablePagination","noPaginationSource","useResource","handle","paginationOf","subscribe","useCallback","getState","state","paginationSource","subscribePagination","getPaginationState","paginationState","useEffect","refresh","retry","reset","loadNext","pagination","emptySlotProperties","defineSlot","id","createContributionTarget","defineSwitchSlot","declarationId","targets","switchSlot","route","target","Slot","useReadable","slotProps","createElement","Fragment","ContributionMount","contributionAuthority"],"mappings":"oqBA+BA,SAASA,EAAuBC,EAAgDC,EAAc,OAC5F,GAAIC,EAAeD,CAAK,EAAG,MAAO,CAAE,OAAQA,EAAO,KAAM,WAAW,EAEpE,GAAI,CACF,MAAME,GAAeC,EAAAJ,GAAA,YAAAA,EAAS,YAAT,YAAAI,EAAA,KAAAJ,EAAqBC,GAEtCE,IAAiB,QAAgB,QAAQ,QAAQA,CAAY,EAAE,MAAME,CAAmB,CAC9F,OAASC,EAAe,CACtBD,EAAoBC,CAAa,CACnC,CAEA,MAAO,CAAE,MAAAL,EAAO,KAAM,QAAQ,CAChC,CAEA,SAASM,GAAmBP,EAA8C,CACxE,MAAMQ,EAAYR,GAAA,YAAAA,EAAS,UACrBS,EAAST,GAAA,YAAAA,EAAS,OAExB,OAAIQ,IAAc,OAAkBC,IAAW,OAAY,OAAY,CAAE,OAAAA,CAAM,EAExEA,IAAW,OAAY,CAAE,UAAAD,CAAS,EAAK,CAAE,UAAAA,EAAW,OAAAC,CAAM,CACnE,CAEA,SAASC,GACPC,EACAX,EAA8C,CAE9C,IAAIY,EACJ,MAAMC,EAAU,IAAI,QAAgCC,GAAS,CAC3DF,EAAUE,CACZ,CAAC,EAED,MAAO,CAAE,MAAAH,EAAO,QAASX,IAAY,OAAY,OAAY,CAAE,GAAGA,CAAO,EAAI,QAAAa,EAAS,QAAAD,CAAO,CAC/F,CAEA,SAASE,GAAsBC,EAAwCC,EAA+B,CACpG,MAAMJ,EAAUG,EAAQ,QACxBA,EAAQ,MAAQ,OAChBA,EAAQ,QAAU,OAClBA,EAAQ,QAAU,OAClBH,GAAA,MAAAA,EAAUI,EACZ,CAOA,MAAMC,CAAqB,CAqBI,QApBpB,KAAkC,CAACN,EAAcX,IAAuC,CAC/F,GAAI,KAAK,SAAW,OAClB,OAAO,QAAQ,QAAQ,CACrB,OAAQ,IAAIkB,EAAkB,WAAY,kC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M,CACrE,CAEA,SAASE,GACPF,EAAU,CAEV,MAAM3B,EAAW8B,EAAcH,CAAE,EAC3BI,EAAU,IAAI,IAEdC,EAAcC,GAAmC,CACrD,MAAM7B,EAAW2B,EAAQ,IAAIE,CAAK,EAElC,GAAI7B,IAAa,OAAW,OAAOA,EAEnC,MAAM8B,EAASR,EAAkB,GAAG1B,CAAQ,IAAIiC,CAAK,EAAE,EACvD,OAAAF,EAAQ,IAAIE,EAAOC,CAAM,EAElBA,CACT,EAEA,cAAO,eAAeF,EAAY,KAAM,CAAE,WAAY,GAAM,MAAOhC,EAAU,EAEtE,OAAO,OAAOgC,CAAU,CACjC,CAMA,SAASG,GAAmCxL,EAA+B,CACzE,MAAMuG,EAAUkF,EAAYzL,EAAQ,OAAO,OAAO,EAC5C0L,EAAoB,UAAW1L,EAAWA,EAAQ,OAAS8K,EAAuBA,EAExF,OAAIvE,EAAQ,SAAW,EAAU,KAE1BA,EAAQ,IAAIhD,GACjBoI,EACEC,EACA,CAAE,IAAKrI,EAAM,IACboI,EAAcE,GAAmB,CAC/B,UAAWC,GAAsBvI,CAAK,EACtC,aAAcA,EAAM,MACpB,eAAgBA,EAAM,GACtB,UAAAmI,EACA,SAAU1L,EAAQ,OAAO,GAC1B,CAAC,CACH,CAEL"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/command-hook-controller.ts","../src/command-hook.ts","../src/idle-subscription.ts","../src/selection-hooks.ts","../src/model-selection-snapshot.ts","../src/model-selection-store.ts","../src/model-hook.ts","../src/requires-models.ts","../src/resource-hook.ts","../src/slot.tsx"],"sourcesContent":["import { CommandError } from '@opetope/core';\nimport { compatibleAbortReason, isCancellation, reportDetachedError } from '@opetope/core/internal';\nimport type { CommandInputArgs, CallRunOptions } from '@opetope/core/internal';\n\nimport type { CommandOutcome } from './command';\nimport { ContributionError } from './errors';\n\ntype CommandRunOptions<Output> = Readonly<{\n onFailure?: (error: unknown) => PromiseLike<void> | void;\n onSuccess?: (value: Output) => PromiseLike<void> | void;\n signal?: AbortSignal;\n}>;\n\ntype CommandRun<Input, Output> = {\n (input: Input, options?: CommandRunOptions<Output>): Promise<CommandOutcome<Output>>;\n (...args: [...CommandInputArgs<Input>, options?: CommandRunOptions<Output>]): Promise<CommandOutcome<Output>>;\n};\n\ntype CommandInvoker = Readonly<{\n run: (input: never, options?: CallRunOptions<unknown>) => Promise<unknown>;\n}>;\n\ntype CommandNotification<Output> = (inFlight: boolean, outcome?: CommandOutcome<Output>) => void;\n\ntype CommandRequest<Input, Output> = {\n input: Input | undefined;\n options: CommandRunOptions<Output> | undefined;\n readonly promise: Promise<CommandOutcome<Output>>;\n resolve: ((outcome: CommandOutcome<Output>) => void) | undefined;\n};\n\nfunction failureOutcome<Output>(options: CommandRunOptions<Output> | undefined, error: unknown): CommandOutcome<never> {\n if (isCancellation(error)) return { reason: error, kind: 'cancelled' };\n\n try {\n const notification = options?.onFailure?.(error);\n\n if (notification !== undefined) void Promise.resolve(notification).catch(reportDetachedError);\n } catch (callbackError) {\n reportDetachedError(callbackError);\n }\n\n return { error, kind: 'failed' };\n}\n\nfunction runOptions<Output>(options: CommandRunOptions<Output> | undefined): CallRunOptions<Output> | undefined {\n const onSuccess = options?.onSuccess;\n const signal = options?.signal;\n\n if (onSuccess === undefined) return signal === undefined ? undefined : { signal };\n\n return signal === undefined ? { onSuccess } : { onSuccess, signal };\n}\n\nfunction requestOf<Input, Output>(\n input: Input,\n options: CommandRunOptions<Output> | undefined,\n): CommandRequest<Input, Output> {\n let resolve!: (outcome: CommandOutcome<Output>) => void;\n const promise = new Promise<CommandOutcome<Output>>(settle => {\n resolve = settle;\n });\n\n return { input, options: options === undefined ? undefined : { ...options }, promise, resolve };\n}\n\nfunction settle<Input, Output>(request: CommandRequest<Input, Output>, outcome: CommandOutcome<Output>): void {\n const resolve = request.resolve;\n request.input = undefined;\n request.options = undefined;\n request.resolve = undefined;\n resolve?.(outcome);\n}\n\n/**\n * D203: the consumer keeps a status, not a schedule. Every `run` reaches the command, and what the command was\n * declared with — `concurrency`, `memoize`, `dedupe` — decides what happens to it. What stays\n * local is what only this consumer knows: whether it is mounted, its own input signal, and the outcome it shows.\n */\nclass CommandHookController<Input, Output> {\n readonly run: CommandRun<Input, Output> = ((input: Input, options?: CommandRunOptions<Output>) => {\n if (this.notify === undefined) {\n return Promise.resolve({\n reason: new ContributionError('inactive', 'Command consumer is not mounted.'),\n kind: 'cancelled' as const,\n });\n }\n\n const aborted = this.cancelledInput(options);\n\n if (aborted !== undefined) return Promise.resolve(aborted);\n\n const request = requestOf(input, options);\n this.start(request);\n\n return request.promise;\n }) as CommandRun<Input, Output>;\n private inFlight = 0;\n private notify: CommandNotification<Output> | undefined;\n\n constructor(private readonly invoker: CommandInvoker) {}\n\n attach(notify: CommandNotification<Output>): () => void {\n this.notify = notify;\n\n return () => {\n if (this.notify !== notify) return;\n\n this.notify = undefined;\n };\n }\n\n synchronize(): void {\n this.notify?.(this.inFlight > 0);\n }\n\n private aborted(signal: AbortSignal): CommandOutcome<never> {\n return {\n reason: new CommandError('cancelled', 'Command input was cancelled.', compatibleAbortReason(signal)),\n kind: 'cancelled',\n };\n }\n\n private cancelledInput(options: CommandRunOptions<Output> | undefined): CommandOutcome<never> | undefined {\n return options?.signal?.aborted === true ? this.aborted(options.signal) : undefined;\n }\n\n private finish(request: CommandRequest<Input, Output>, outcome: CommandOutcome<Output>): void {\n if (request.resolve === undefined) return;\n\n this.inFlight -= 1;\n settle(request, outcome);\n this.notify?.(this.inFlight > 0, outcome);\n }\n\n private invoke(request: CommandRequest<Input, Output>): void {\n let invocation: Promise<Output>;\n\n try {\n invocation = this.invoker.run(request.input as never, runOptions(request.options) as never) as Promise<Output>;\n request.input = undefined;\n } catch (error) {\n this.finish(request, failureOutcome(request.options, error));\n\n return;\n }\n\n void invocation.then(\n value => this.finish(request, { kind: 'ok', value }),\n (error: unknown) => this.finish(request, failureOutcome(request.options, error)),\n );\n }\n\n private start(request: CommandRequest<Input, Output>): void {\n this.inFlight += 1;\n // Reserve the flight before publishing: a reentrant run must already see this consumer as busy.\n this.notify?.(true);\n this.invoke(request);\n }\n}\n\nexport { CommandHookController };\nexport type { CommandInvoker, CommandRun };\n","import { useInsertionEffect, useLayoutEffect, useMemo, useState } from 'react';\n\nimport type { Command } from '@opetope/core';\n\nimport type { CommandOutcome } from './command';\nimport { CommandHookController } from './command-hook-controller';\nimport type { CommandInvoker, CommandRun } from './command-hook-controller';\nimport { ContributionError } from './errors';\nimport { useFrame } from './mount-context';\n\n/** D292: a cancellation is not an answer of the product, so it never settles into the outcome this hook shows. */\ntype SettledOutcome<Output> = Exclude<CommandOutcome<Output>, { readonly kind: 'cancelled' }>;\n\ninterface CommandHookStatus<Output> {\n readonly inFlight: boolean;\n readonly outcome: SettledOutcome<Output> | undefined;\n}\n\nconst emptyStatus: CommandHookStatus<never> = { inFlight: false, outcome: undefined };\n\ntype CommandHook<Input, Output> = CommandHookStatus<Output> & {\n readonly run: CommandRun<Input, Output>;\n};\n\ntype CommandHookState<Input, Output> = CommandHookStatus<Output> & {\n readonly slot: CommandHookController<Input, Output>;\n};\n\n/** D292: a cancellation moves nothing, so it is the same non-event as a notification without an outcome at all. */\nfunction settledOutcome<Output>(outcome: CommandOutcome<Output> | undefined): SettledOutcome<Output> | undefined {\n return outcome === undefined || outcome.kind === 'cancelled' ? undefined : outcome;\n}\n\nfunction unchangedState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n settled: SettledOutcome<Output> | undefined,\n): boolean {\n return settled === undefined && current.slot === slot && current.inFlight === inFlight;\n}\n\nfunction nextState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n outcome?: CommandOutcome<Output>,\n): CommandHookState<Input, Output> {\n const settled = settledOutcome(outcome);\n\n if (unchangedState(current, slot, inFlight, settled)) return current;\n\n // A new run clears nothing: the previous answer stays readable while its retry is in flight.\n const previous = current.slot === slot ? current.outcome : undefined;\n\n return { inFlight, outcome: settled ?? previous, slot };\n}\n\nfunction useCommandSlot<Input, Output>(invoker: CommandInvoker): CommandHookController<Input, Output> {\n // Slots are inert until commit. An interrupted render cannot fence the committed source or admit its own work.\n const [slots] = useState(() => new WeakMap<object, CommandHookController<Input, Output>>());\n let slot = slots.get(invoker);\n\n if (slot === undefined) {\n slot = new CommandHookController(invoker);\n slots.set(invoker, slot);\n }\n\n return slot;\n}\n\n/**\n * The status half of a consumer, apart from what it is a consumer of. D321 gives a resource the same two verbs a\n * command has, so the same three React hooks answer for them: the state of this consumer, the attachment that moves\n * it, and the synchronisation of a slot that was already busy when this mount arrived.\n */\nfunction useCommandStatus<Input, Output>(\n currentSlot: CommandHookController<Input, Output>,\n): CommandHook<Input, Output> {\n const [hookState, setHookState] = useState<CommandHookState<Input, Output>>(() => ({\n inFlight: false,\n outcome: undefined,\n slot: currentSlot,\n }));\n useInsertionEffect(\n () =>\n currentSlot.attach((inFlight, outcome) =>\n setHookState(current => nextState(current, currentSlot, inFlight, outcome)),\n ),\n [currentSlot],\n );\n useLayoutEffect(() => currentSlot.synchronize(), [currentSlot]);\n const { inFlight, outcome } = hookState.slot === currentSlot ? hookState : emptyStatus;\n const run = currentSlot.run;\n\n return useMemo(() => ({ inFlight, outcome, run }), [inFlight, outcome, run]);\n}\n\nfunction useCommand<Input, Output>(command: Command<Input, Output>): CommandHook<Input, Output> {\n const frame = useFrame();\n const record = frame.commandRecords.get(command);\n\n if (record === undefined) {\n throw new ContributionError('missing', `Command ${command.id} is not bound in this contribution.`);\n }\n\n return useCommandStatus(useCommandSlot<Input, Output>(record.invoker));\n}\n\nexport { useCommand, useCommandStatus };\nexport type { CommandHook };\n","const idleRelease = (): void => undefined;\nconst subscribeIdle = (): (() => void) => idleRelease;\nconst idleRevision = (): number => 0;\n\nexport { idleRevision, subscribeIdle };\n","import { useInsertionEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';\n\nimport type { Command } from '@opetope/core';\n\nimport type { CommandOutcome } from './command';\nimport type { CommandHook } from './command-hook';\nimport { CommandHookController } from './command-hook-controller';\nimport type { CommandInvoker } from './command-hook-controller';\nimport { ContributionError } from './errors';\nimport { idleRevision, subscribeIdle } from './idle-subscription';\nimport type { SelectedResource } from './model-selection-snapshot';\nimport { useFrame } from './mount-context';\nimport type { Frame } from './mount-frame';\nimport { resourceInvokers } from './resource-command';\nimport type { ResourceInvokers } from './resource-command';\n\ntype CommandSelection = Readonly<Record<string, Command<never, unknown>>>;\ntype ResourceSelection = ReadonlyMap<PropertyKey, SelectedResource>;\n/** D359: what one selected Resource answers — its three verbs, its state, and the pagination capability if it has one. */\ntype SelectedResourceHook = Readonly<{\n pagination: Readonly<{ loadNext: CommandHook<never, unknown>; state: unknown }> | undefined;\n refresh: CommandHook<never, unknown>;\n reset: CommandHook<never, unknown>;\n retry: CommandHook<never, unknown>;\n state: unknown;\n}>;\ntype SelectionHooks = Readonly<Record<PropertyKey, CommandHook<never, unknown> | SelectedResourceHook>>;\n\nconst emptyHooks: SelectionHooks = Object.freeze({});\n\ntype CommandEntry = {\n detach: (() => void) | undefined;\n hook: CommandHook<never, unknown>;\n readonly invoker: CommandInvoker;\n readonly slot: CommandHookController<never, unknown>;\n};\n\n/** D359: one key of a selection, four consumers. The record is the value; `entries` still holds one entry per key. */\ntype ResourceEntry = {\n /** D359: the value this key hands the render, kept on the record so a still frame is the same object again. */\n readonly hook: SelectedResourceHook;\n readonly kind: 'resource';\n readonly loadNext: CommandEntry;\n /** Whether the declaration carried the pagination capability at all. */\n readonly paginated: boolean;\n readonly refresh: CommandEntry;\n readonly reset: CommandEntry;\n readonly retry: CommandEntry;\n};\n\ntype SelectionEntry = CommandEntry | ResourceEntry;\n\nfunction isResourceEntry(entry: SelectionEntry): entry is ResourceEntry {\n return 'kind' in entry;\n}\n\nfunction createEntry(invoker: CommandInvoker): CommandEntry {\n const slot = new CommandHookController<never, unknown>(invoker);\n\n return { detach: undefined, hook: { inFlight: false, outcome: undefined, run: slot.run }, invoker, slot };\n}\n\nfunction unchangedHook(previous: CommandHook<never, unknown>, next: CommandHook<never, unknown>): boolean {\n return previous.inFlight === next.inFlight && Object.is(previous.outcome, next.outcome);\n}\n\nfunction updateEntry(entry: CommandEntry, inFlight: boolean, outcome?: CommandOutcome<unknown>): boolean {\n const previous = entry.hook;\n\n if (outcome === undefined && previous.inFlight === inFlight) return false;\n\n // D292: only a settled non-cancelled outcome replaces the one this key shows; a retry keeps the previous answer.\n const settled = outcome === undefined || outcome.kind === 'cancelled' ? undefined : outcome;\n const next = { inFlight, outcome: settled ?? previous.outcome, run: previous.run };\n\n if (unchangedHook(previous, next)) return false;\n\n entry.hook = next;\n\n return true;\n}\n\nfunction selectEntry(previous: SelectionEntry | undefined, invoker: CommandInvoker): CommandEntry {\n return previous !== undefined && !isResourceEntry(previous) && previous.invoker === invoker\n ? previous\n : createEntry(invoker);\n}\n\nfunction resourceHook(entry: Omit<ResourceEntry, 'hook'>, selected: SelectedResource): SelectedResourceHook {\n return {\n pagination: entry.paginated ? { loadNext: entry.loadNext.hook, state: selected.pagination } : undefined,\n refresh: entry.refresh.hook,\n reset: entry.reset.hook,\n retry: entry.retry.hook,\n state: selected.state,\n };\n}\n\nfunction createResourceEntry(invokers: ResourceInvokers, selected: SelectedResource): ResourceEntry {\n const parts = {\n kind: 'resource' as const,\n loadNext: createEntry(invokers.loadNext),\n paginated: selected.pagination !== undefined,\n refresh: createEntry(invokers.refresh),\n reset: createEntry(invokers.reset),\n retry: createEntry(invokers.retry),\n };\n\n return { ...parts, hook: resourceHook(parts, selected) };\n}\n\n/** The four commands of a Resource: the three verbs every one has, and `loadNext` only where one was declared. */\nfunction unchangedResourceCommands(entry: ResourceEntry): boolean {\n const { hook } = entry;\n\n return (\n hook.refresh === entry.refresh.hook &&\n hook.reset === entry.reset.hook &&\n hook.retry === entry.retry.hook &&\n (!entry.paginated || hook.pagination?.loadNext === entry.loadNext.hook)\n );\n}\n\n/** What this selection read: the state of the Resource, and the state of its capability where it has one. */\nfunction unchangedResourceState(entry: ResourceEntry, selected: SelectedResource): boolean {\n return Object.is(entry.hook.state, selected.state) && Object.is(entry.hook.pagination?.state, selected.pagination);\n}\n\nfunction unchangedResourceHook(entry: ResourceEntry, selected: SelectedResource): boolean {\n return unchangedResourceCommands(entry) && unchangedResourceState(entry, selected);\n}\n\n/**\n * S6/D359: the same Resource that did not move answers the same object, so a child under `memo` is not re-rendered by\n * the mere act of reading it. Every part is a render input, so this is a memo and not a piece of state.\n */\nfunction selectResourceEntry(\n previous: SelectionEntry | undefined,\n invokers: ResourceInvokers,\n selected: SelectedResource,\n): ResourceEntry {\n if (previous === undefined || !isResourceEntry(previous) || previous.refresh.invoker !== invokers.refresh) {\n return createResourceEntry(invokers, selected);\n }\n\n // Preparing a suspended render must not replace the hook on the committed entry. The four command consumers are\n // still the same logical consumers; only the selected Resource wrapper is new until commit.\n return unchangedResourceHook(previous, selected) ? previous : { ...previous, hook: resourceHook(previous, selected) };\n}\n\nfunction commandEntries(entry: SelectionEntry): readonly CommandEntry[] {\n return isResourceEntry(entry) ? [entry.refresh, entry.reset, entry.retry, entry.loadNext] : [entry];\n}\n\nfunction detachEntry(entry: SelectionEntry): void {\n for (const command of commandEntries(entry)) {\n command.detach?.();\n command.detach = undefined;\n }\n}\n\nfunction sameResourceConsumers(previous: ResourceEntry, next: ResourceEntry): boolean {\n return (\n previous.refresh === next.refresh &&\n previous.reset === next.reset &&\n previous.retry === next.retry &&\n previous.loadNext === next.loadNext\n );\n}\n\nfunction sameConsumers(previous: SelectionEntry, next: SelectionEntry | undefined): boolean {\n if (previous === next) return true;\n if (next === undefined || !isResourceEntry(previous) || !isResourceEntry(next)) return false;\n\n return sameResourceConsumers(previous, next);\n}\n\nfunction hookOf(entry: SelectionEntry): CommandHook<never, unknown> | SelectedResourceHook {\n return entry.hook;\n}\n\n/** Selection is inert during render; only a committed selection can admit work or discard an old queue. */\nclass CommandGroup {\n private entries = new Map<PropertyKey, SelectionEntry>();\n /** One set of invokers per Resource identity, so `run` keeps its reference across renders (D359). */\n private readonly invokers = new WeakMap<object, ResourceInvokers>();\n private readonly listeners = new Set<() => void>();\n private revision = 0;\n\n close(): void {\n for (const entry of this.entries.values()) detachEntry(entry);\n\n this.entries.clear();\n }\n\n commit(selected: Map<PropertyKey, SelectionEntry>): void {\n for (const [key, entry] of this.entries) {\n if (!sameConsumers(entry, selected.get(key))) detachEntry(entry);\n }\n\n this.entries = selected;\n\n for (const entry of selected.values()) this.attachEntry(entry);\n }\n\n /** S7: the attach runs on every commit, so the verbs are named rather than gathered into an array. */\n private attachEntry(entry: SelectionEntry): void {\n if (isResourceEntry(entry)) {\n this.attachCommand(entry.refresh);\n this.attachCommand(entry.retry);\n this.attachCommand(entry.reset);\n this.attachCommand(entry.loadNext);\n\n return;\n }\n\n this.attachCommand(entry);\n }\n\n private attachCommand(command: CommandEntry): void {\n command.detach ??= command.slot.attach((inFlight, outcome) => {\n if (!updateEntry(command, inFlight, outcome)) return;\n\n this.revision += 1;\n\n for (const listener of this.listeners) listener();\n });\n }\n\n getSnapshot = (): number => this.revision;\n\n /**\n * D321: two outcomes no longer, but two kinds. A command that is not bound is still a `ContributionError`; a\n * resource never appears in `frame.commandRecords`, so it is prepared from its own identity instead.\n */\n prepare(commands: CommandSelection, resources: ResourceSelection, frame: Frame): Map<PropertyKey, SelectionEntry> {\n const selected = new Map<PropertyKey, SelectionEntry>();\n\n for (const key of Reflect.ownKeys(commands)) {\n if (!Object.prototype.propertyIsEnumerable.call(commands, key)) continue;\n\n const command = (commands as Readonly<Record<PropertyKey, Command<never, unknown>>>)[key];\n const record = command === undefined ? undefined : frame.commandRecords.get(command);\n\n if (record === undefined) {\n throw new ContributionError('missing', `Command at ${String(key)} is not bound in this contribution.`);\n }\n\n selected.set(key, selectEntry(this.entries.get(key), record.invoker));\n }\n\n for (const [key, resource] of resources) {\n const invokers = resourceInvokers(resource.resource, this.invokers);\n\n selected.set(key, selectResourceEntry(this.entries.get(key), invokers, resource));\n }\n\n return selected;\n }\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n };\n}\n\nfunction useCommandGroup(commands: CommandSelection, resources: ResourceSelection): CommandGroup | undefined {\n const groupRef = useRef<CommandGroup | undefined>(undefined);\n const populated =\n resources.size > 0 ||\n Reflect.ownKeys(commands).some(key => Object.prototype.propertyIsEnumerable.call(commands, key));\n\n return populated ? (groupRef.current ??= new CommandGroup()) : undefined;\n}\n\n/** The consumers of one selection: a command per key, and the two verbs of a resource per key (D321). */\nfunction useSelectionHooks(commands: CommandSelection, resources: ResourceSelection): SelectionHooks {\n const frame = useFrame();\n const group = useCommandGroup(commands, resources);\n const getSnapshot = group?.getSnapshot ?? idleRevision;\n useSyncExternalStore(group?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const selected = group?.prepare(commands, resources, frame);\n useInsertionEffect(() => () => group?.close(), [group]);\n useInsertionEffect(() => {\n if (selected !== undefined) group?.commit(selected);\n });\n useLayoutEffect(() => {\n if (selected === undefined) return;\n\n // S7: the same branch as the attach — this runs after every commit, and the arrays were pure allocation.\n for (const entry of selected.values()) {\n if (isResourceEntry(entry)) {\n entry.refresh.slot.synchronize();\n entry.retry.slot.synchronize();\n entry.reset.slot.synchronize();\n entry.loadNext.slot.synchronize();\n } else entry.slot.synchronize();\n }\n });\n\n return selected === undefined\n ? emptyHooks\n : Object.fromEntries([...selected].map(([key, entry]) => [key, hookOf(entry)]));\n}\n\nexport { useSelectionHooks };\nexport type { SelectionHooks };\n","import type { Readable, ResourceView } from '@opetope/core';\nimport {\n isCallTarget,\n isReadable,\n isResourceView,\n resourceViewDemands,\n resourceViewReadable,\n} from '@opetope/core/internal';\nimport type { ResourceDemand } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\nimport type { AnyCommand } from './model-binding';\nimport { isResource } from './resource-command';\nimport type { AnyResource } from './resource-command';\n\ntype SelectionValue<Source> =\n Source extends ResourceView<infer Value> ? Value : Source extends Readable<infer Value> ? Value : never;\n\ninterface SelectionRead {\n <Source extends Readable<unknown> | ResourceView<unknown>>(source: Source): SelectionValue<Source>;\n <Source extends Readable<unknown> | ResourceView<unknown>, Selected>(\n source: Source,\n select: (value: SelectionValue<Source>) => Selected,\n ): Selected;\n}\n\ntype SelectionContext = Readonly<{ read: SelectionRead }>;\ntype NonSelectionRecord =\n | readonly unknown[]\n | ((...arguments_: never[]) => unknown)\n | (abstract new (...arguments_: never[]) => unknown)\n | Date\n | PromiseLike<unknown>\n | ReadonlyMap<unknown, unknown>\n | ReadonlySet<unknown>\n | RegExp\n | WeakMap<object, unknown>\n | WeakSet<object>;\n/** A named interface needs no open index signature; container and callable results are not field selections. */\ntype SelectionShape<Selected extends object> = Selected extends NonSelectionRecord ? never : Selected;\ntype SelectionRecord = Readonly<Record<PropertyKey, unknown>>;\n/**\n * D359: the Resource a field selected, and what this selection read from it — its state, and the state of its\n * pagination capability when it has one. Both are read passively: a selection takes no lease by reading.\n */\ntype SelectedResource = Readonly<{ pagination: unknown; resource: AnyResource; state: unknown }>;\ntype SelectionSnapshot = Readonly<{\n commands: Readonly<Record<PropertyKey, AnyCommand>>;\n /** The set the mount leases; two keys naming one resource are one lease. */\n leases: ReadonlySet<ResourceDemand>;\n resources: ReadonlyMap<PropertyKey, SelectedResource>;\n sources: ReadonlySet<Readable<unknown>>;\n values: SelectionRecord;\n}>;\n\nconst noResources: ReadonlyMap<PropertyKey, SelectedResource> = new Map();\n\n/**\n * D363: what this mount read last and the snapshot it answered with. It belongs to the mount and not to the reader:\n * React may discard the `useMemo` that builds the reader, and a memory kept there would be empty exactly when it is\n * needed. D364: it no longer remembers which sources ended — a source whose owner retired stops instead of refusing,\n * so it answers its last value on every read and there is nothing to remember or to step around.\n */\ntype SelectionMemory = {\n model: unknown;\n observed: Map<Readable<unknown>, unknown> | undefined;\n select: unknown;\n snapshot: SelectionSnapshot;\n};\n\nconst noLeases: ReadonlySet<ResourceDemand> = new Set();\n\nfunction readSource<Value>(source: Readable<Value>, sources: Map<Readable<unknown>, unknown>): Value {\n if (!isReadable(source)) {\n throw new ContributionError('binding-invalid', 'Model selection read requires a Readable or ResourceView.');\n }\n\n if (sources.has(source)) return sources.get(source) as Value;\n\n // D364: a refusal here is the source's own failure and belongs to the render, because no lifetime ends in one.\n const value: unknown = source.getSnapshot();\n sources.set(source, value);\n\n return value as Value;\n}\n\nfunction readPassively(source: Readable<unknown>, sources: Map<Readable<unknown>, unknown>): unknown {\n if (sources.has(source)) return sources.get(source);\n\n const value: unknown = source.getSnapshot();\n sources.set(source, value);\n\n return value;\n}\n\n/** D359: the predicate that answers the question the type of the field asked, and the read that leases nothing. */\nfunction classifyResource(\n key: PropertyKey,\n value: unknown,\n resources: Map<PropertyKey, SelectedResource>,\n sources: Map<Readable<unknown>, unknown>,\n): void {\n if (!isResource(value)) return;\n\n const resource = value as AnyResource;\n const capability = (\n resource as { readonly pagination?: { readonly state: Readable<unknown> } | ResourceView<unknown> }\n ).pagination;\n\n resources.set(key, {\n pagination: capability === undefined ? undefined : readPassively(resourceViewReadable(capability), sources),\n resource,\n state: readPassively(resourceViewReadable(resource), sources),\n });\n}\n\nfunction selectedResources(resources: Map<PropertyKey, SelectedResource>): ReadonlyMap<PropertyKey, SelectedResource> {\n return resources.size === 0 ? noResources : resources;\n}\n\ntype CollectedSelection = Readonly<{\n leases: ReadonlySet<ResourceDemand>;\n resources: ReadonlyMap<PropertyKey, SelectedResource>;\n values: SelectionRecord;\n}>;\n\nfunction collectResourceDemands(\n resources: ReadonlyMap<PropertyKey, SelectedResource>,\n leases: Set<ResourceDemand>,\n): void {\n for (const { resource } of resources.values()) {\n if (isResourceView(resource)) {\n for (const demand of resourceViewDemands(resource)) leases.add(demand);\n } else {\n leases.add(resource);\n }\n }\n}\n\n/**\n * D359: recognition happens in the one pass that already walks the selection. `Resource` is a structural contract\n * (D199) and the type of a selected field promises `ResourceHook` for anything that satisfies it, so the predicate\n * this uses answers the same question the type asked. Reading the state here also puts it among `sources`, so its\n * publication invalidates the fast path of this reader exactly as a read source does.\n */\nfunction collectSelection(\n select: (context: SelectionContext) => object,\n sources: Map<Readable<unknown>, unknown>,\n): CollectedSelection {\n const leases = new Set<ResourceDemand>();\n const read = <Value, Selected>(\n source: Readable<Value> | ResourceView<Value>,\n project?: (value: Value) => Selected,\n ) => {\n let readable: Readable<Value>;\n if (isResourceView(source)) {\n for (const demand of resourceViewDemands(source)) leases.add(demand);\n readable = source.observe();\n } else {\n readable = source;\n }\n const value = readSource(readable, sources);\n\n return project === undefined ? value : project(value);\n };\n const selected = select({ read });\n\n if (typeof selected !== 'object' || selected === null || Array.isArray(selected)) {\n throw new ContributionError('binding-invalid', 'Model selection requires a record.');\n }\n\n const entries: (readonly [PropertyKey, unknown])[] = [];\n const resources = new Map<PropertyKey, SelectedResource>();\n\n for (const key of Reflect.ownKeys(selected)) {\n if (!Object.prototype.propertyIsEnumerable.call(selected, key)) continue;\n\n const value = (selected as SelectionRecord)[key];\n\n entries.push([key, value]);\n classifyResource(key, value, resources, sources);\n }\n\n // `__proto__` is a key like any other here, and only a defined property keeps it one (D214).\n collectResourceDemands(resources, leases);\n return { leases, resources: selectedResources(resources), values: Object.fromEntries(entries) };\n}\n\n/**\n * D359: `values` keeps the Resource itself — a stable reference — so a selection that holds one is compared by\n * `Object.is` exactly as before. What moves is the state behind it, and that is compared here: without this the\n * selection would be «equal», the previous state would be kept, and a published Resource would reach no render.\n */\nfunction equalResources(\n previous: ReadonlyMap<PropertyKey, SelectedResource>,\n next: ReadonlyMap<PropertyKey, SelectedResource>,\n): boolean {\n if (previous.size !== next.size) return false;\n\n for (const [key, selected] of next) {\n const before = previous.get(key);\n\n if (\n before?.resource !== selected.resource ||\n !Object.is(before.state, selected.state) ||\n !Object.is(before.pagination, selected.pagination)\n ) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction equalMembers<Value>(previous: ReadonlySet<Value>, next: ReadonlySet<Value>): boolean {\n if (previous.size !== next.size) return false;\n for (const value of next) if (!previous.has(value)) return false;\n return true;\n}\n\nfunction equalSelection(\n previous: SelectionSnapshot,\n values: SelectionRecord,\n sources: ReadonlySet<Readable<unknown>>,\n resources: ReadonlyMap<PropertyKey, SelectedResource>,\n leases: ReadonlySet<ResourceDemand>,\n) {\n const keys = Reflect.ownKeys(values);\n const previousKeys = Reflect.ownKeys(previous.values);\n\n if (keys.length !== previousKeys.length) return false;\n if (!equalMembers(previous.sources, sources)) return false;\n if (!equalMembers(previous.leases, leases)) return false;\n\n if (!equalResources(previous.resources, resources)) return false;\n\n return keys.every((key, index) => previousKeys[index] === key && Object.is(previous.values[key], values[key]));\n}\n\ntype ModelSelector<Model> = (model: Model, context: SelectionContext) => object;\ntype SelectionReaderRef<Model> = { readonly current: ModelSelector<Model> | undefined };\n\nconst emptySelectionSnapshot: SelectionSnapshot = {\n commands: {},\n leases: noLeases,\n resources: noResources,\n sources: new Set(),\n values: {},\n};\n\nfunction selectionCommands(values: SelectionRecord): Readonly<Record<PropertyKey, AnyCommand>> {\n return Object.fromEntries(\n Reflect.ownKeys(values)\n .filter(key => isCallTarget(values[key]))\n .map(key => [key, values[key]]),\n ) as Readonly<Record<PropertyKey, AnyCommand>>;\n}\n\n/**\n * The fast path re-reads what it observed. D364: a source that stopped answers the same value it answered last, so\n * it compares equal and costs one read — there is no terminal source to record and step around any more.\n */\nfunction observedUnchanged(observed: Map<Readable<unknown>, unknown>): boolean {\n for (const [source, value] of observed) {\n if (!Object.is(source.getSnapshot(), value)) return false;\n }\n\n return true;\n}\n\n/** D363: the memory of one mount, empty until its first read and reset when the reader is built for another model. */\nfunction createSelectionMemory(): SelectionMemory {\n return { model: undefined, observed: undefined, select: undefined, snapshot: emptySelectionSnapshot };\n}\n\n/**\n * D214: one reader per model, not per render. The author's selector arrives through a ref, so an inline arrow does not\n * rebuild the reader; the fast path — nothing observed has moved — belongs to the selector that computed the snapshot,\n * so a new selector is always called again, its result compared field by field, and an equal selection keeps the\n * previous snapshot. A rejected or abandoned render still changes nothing: only a committed selection subscribes.\n *\n * D363: what the reader remembers lives in the mount's memory, so a reader React rebuilt — because it discarded the\n * memo — still knows what this selection read last.\n */\nfunction createSelectionSnapshot<Model>(\n model: Model,\n selectRef: SelectionReaderRef<Model>,\n memory: SelectionMemory,\n): () => SelectionSnapshot {\n if (memory.model !== model) {\n memory.model = model;\n memory.observed = undefined;\n memory.select = undefined;\n memory.snapshot = emptySelectionSnapshot;\n }\n\n return () => {\n const select = selectRef.current;\n\n if (select === undefined) return emptySelectionSnapshot;\n\n const observed = memory.observed;\n\n if (observed !== undefined && memory.select === select && observedUnchanged(observed)) {\n return memory.snapshot;\n }\n\n const nextObserved = new Map<Readable<unknown>, unknown>();\n const { leases, resources, values } = collectSelection(context => select(model, context), nextObserved);\n const sources = new Set(nextObserved.keys());\n\n if (observed === undefined || !equalSelection(memory.snapshot, values, sources, resources, leases)) {\n memory.snapshot = {\n commands: selectionCommands(values),\n leases,\n resources,\n sources,\n values,\n };\n }\n\n memory.observed = nextObserved;\n memory.select = select;\n\n return memory.snapshot;\n };\n}\n\nexport { createSelectionMemory, createSelectionSnapshot, emptySelectionSnapshot };\nexport type { ModelSelector, SelectedResource, SelectionContext, SelectionMemory, SelectionShape, SelectionSnapshot };\n","import type { Readable } from '@opetope/core';\nimport { createAggregateError } from '@opetope/core/internal';\n\nimport type { ResourceDemand } from '@opetope/core/internal';\n\ntype Subscription = { dispose: (() => void) | undefined };\ntype Listener = Readonly<{ notify: () => void }>;\n\nconst noLeases: ReadonlySet<ResourceDemand> = new Set();\n\nfunction releaseSubscriptions(subscriptions: Iterable<Subscription>, failures: unknown[] = []): void {\n for (const subscription of subscriptions) {\n const dispose = subscription.dispose;\n subscription.dispose = undefined;\n\n try {\n dispose?.();\n } catch (error) {\n failures.push(error);\n }\n }\n\n if (failures.length === 1) throw failures[0];\n\n if (failures.length > 1) throw createAggregateError(failures, 'Model selection sources failed to release.');\n}\n\n/** A subscription set, not a scheduler: source notifications use React's snapshot consistency check. */\nclass ModelSelectionStore {\n private enabled = false;\n /** D359: one lease per Resource identity, diffed like a subscription, so an unchanged selection takes none. */\n private readonly leases = new Map<ResourceDemand, Subscription>();\n private readonly listeners = new Set<Listener>();\n private retained: ReadonlySet<ResourceDemand> = noLeases;\n private sources: ReadonlySet<Readable<unknown>> = new Set();\n private readonly subscriptions = new Map<Readable<unknown>, Subscription>();\n\n close(): void {\n this.enabled = false;\n this.sources = new Set();\n this.retained = noLeases;\n this.releaseAll();\n }\n\n commit(sources: ReadonlySet<Readable<unknown>>, retained: ReadonlySet<ResourceDemand> = noLeases): void {\n this.sources = sources;\n this.retained = retained;\n this.enabled = true;\n\n try {\n this.synchronize();\n } catch (error) {\n this.releaseAll([error]);\n }\n }\n\n subscribe = (notify: () => void): (() => void) => {\n const listener = { notify };\n this.listeners.add(listener);\n\n try {\n this.synchronize();\n } catch (error) {\n this.listeners.delete(listener);\n this.releaseAll([error]);\n }\n\n return () => {\n this.listeners.delete(listener);\n\n if (this.listeners.size === 0) this.releaseAll();\n };\n };\n\n private add(source: Readable<unknown>): void {\n const subscription: Subscription = { dispose: undefined };\n // Reserve before foreign code: a synchronous notification may replace or close this selection.\n this.subscriptions.set(source, subscription);\n const dispose = source.subscribe(this.notify);\n\n if (typeof dispose !== 'function') throw new TypeError('Model selection source must return a disposer.');\n\n if (this.subscriptions.get(source) === subscription) subscription.dispose = dispose;\n else dispose();\n }\n\n private notify = (): void => {\n for (const listener of [...this.listeners]) {\n if (this.listeners.has(listener)) listener.notify();\n }\n };\n\n private releaseAll(failures?: unknown[]): void {\n const held = [...this.subscriptions.values(), ...this.leases.values()];\n this.subscriptions.clear();\n this.leases.clear();\n releaseSubscriptions(held, failures);\n }\n\n private removeUnselected(): void {\n const removed: Subscription[] = [];\n\n for (const [source, subscription] of this.subscriptions) {\n if (this.sources.has(source)) continue;\n\n this.subscriptions.delete(source);\n removed.push(subscription);\n }\n\n for (const [resource, lease] of this.leases) {\n if (this.retained.has(resource)) continue;\n\n this.leases.delete(resource);\n removed.push(lease);\n }\n\n releaseSubscriptions(removed);\n }\n\n /**\n * D321: `retain()` is reentrant — it reaches `activate()`, the target subscription, the first read and the\n * publication that follows, all synchronously — and a listener woken there may rebuild or close this selection.\n * The record is reserved first, the lease is taken second, and it is kept only if the record is still this one.\n */\n private retain(resource: ResourceDemand): void {\n const lease: Subscription = { dispose: undefined };\n this.leases.set(resource, lease);\n const release = resource.acquire();\n\n if (typeof release !== 'function') throw new TypeError('Model selection resource must answer a release disposer.');\n\n if (this.leases.get(resource) === lease) lease.dispose = release;\n else release();\n }\n\n /** Foreign code inside a subscription or a lease may replace this selection, so both loops ask again. */\n private ready(): boolean {\n return this.enabled && this.listeners.size > 0;\n }\n\n private retainSelected(): void {\n for (const resource of this.retained) {\n if (!this.ready()) return;\n\n if (this.retained.has(resource) && !this.leases.has(resource)) this.retain(resource);\n }\n }\n\n private subscribeSources(): void {\n for (const source of this.sources) {\n if (!this.ready()) return;\n\n if (this.sources.has(source) && !this.subscriptions.has(source)) this.add(source);\n }\n }\n\n private synchronize(): void {\n this.removeUnselected();\n this.subscribeSources();\n this.retainSelected();\n }\n}\n\nexport { ModelSelectionStore };\n","import { useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Command, ModelOf, PaginatedResource, Resource } from '@opetope/core';\n\nimport type { CommandHook } from './command-hook';\nimport { useSelectionHooks } from './selection-hooks';\nimport type { SelectionHooks } from './selection-hooks';\nimport { ContributionError } from './errors';\nimport { subscribeIdle } from './idle-subscription';\nimport type { AnyModel } from './model-binding';\nimport { createSelectionMemory, createSelectionSnapshot, emptySelectionSnapshot } from './model-selection-snapshot';\nimport type {\n ModelSelector,\n SelectionContext,\n SelectionMemory,\n SelectionShape,\n SelectionSnapshot,\n} from './model-selection-snapshot';\nimport { ModelSelectionStore } from './model-selection-store';\nimport { useFrame } from './mount-context';\nimport type { PaginatedResourceHook, ResourceHook, ResourceKey } from './resource-command';\n\n/**\n * D359: a field whose value is a Resource answers the hook `useResource` answers, and the mount leases it exactly as\n * `useResource` does. `read(resource.state)` is unchanged — it hands out the state and leases nothing — so naming one\n * Resource both ways registers it twice: the subscription and the lease are independent.\n */\ntype SelectedValue<Value> =\n Value extends Command<infer Input, infer Output>\n ? CommandHook<Input, Output>\n : Value extends PaginatedResource<\n infer Data,\n infer Key extends ResourceKey,\n infer Cursor extends ResourceKey,\n 'consumers' | 'owner'\n >\n ? PaginatedResourceHook<Data, Key, Cursor>\n : Value extends Resource<infer Data, infer Key extends ResourceKey, 'consumers' | 'owner'>\n ? ResourceHook<Data, Key>\n : Value;\ntype ModelSelection<Selected> = { readonly [Key in keyof Selected]: SelectedValue<Selected[Key]> };\n\nconst readEmptySnapshot = () => emptySelectionSnapshot;\n\nfunction useSelectionStore(selected: boolean): ModelSelectionStore | undefined {\n const storeRef = useRef<ModelSelectionStore | undefined>(undefined);\n\n return selected ? (storeRef.current ??= new ModelSelectionStore()) : undefined;\n}\n\n/**\n * Two branches of one key: the consumer this selection prepared — a bound command, or the verbs, the state and the\n * capability of a selected Resource — and otherwise the value the selector wrote. S6/D359: the Resource branch is\n * assembled on the record and not here, so a key whose state did not move hands back the very same object.\n */\ntype SelectionResult = Readonly<Record<PropertyKey, unknown>>;\n\nfunction selectedValue(snapshot: SelectionSnapshot, hooks: SelectionHooks, key: PropertyKey): unknown {\n return Object.prototype.hasOwnProperty.call(hooks, key) ? hooks[key] : snapshot.values[key];\n}\n\nfunction mergeSelection(\n snapshot: SelectionSnapshot,\n hooks: SelectionHooks,\n committed: SelectionResult | undefined,\n): SelectionResult {\n const keys = Reflect.ownKeys(snapshot.values);\n\n if (committed !== undefined) {\n const oldKeys = Reflect.ownKeys(committed);\n\n if (\n keys.length === oldKeys.length &&\n keys.every(\n (key, index) => key === oldKeys[index] && Object.is(committed[key], selectedValue(snapshot, hooks, key)),\n )\n ) {\n return committed;\n }\n }\n\n return Object.fromEntries(keys.map(key => [key, selectedValue(snapshot, hooks, key)]));\n}\n\n/** D205: resolve only a granted model, explicitly read data, and reuse the ordinary per-key command consumers. */\nfunction useModel<Declaration extends AnyModel>(declaration: Declaration): ModelOf<Declaration>;\nfunction useModel<Declaration extends AnyModel, const Selected extends object>(\n declaration: Declaration,\n select: (model: ModelOf<Declaration>, context: SelectionContext) => Selected & SelectionShape<Selected>,\n): ModelSelection<Selected>;\nfunction useModel<Declaration extends AnyModel>(\n declaration: Declaration,\n select?: (model: ModelOf<Declaration>, context: SelectionContext) => object,\n): unknown {\n const frame = useFrame();\n\n if (!frame.models.has(declaration)) {\n throw new ContributionError('missing', `Model ${declaration.id} is not granted to this contribution.`);\n }\n\n const model = frame.models.get(declaration) as ModelOf<Declaration>;\n const store = useSelectionStore(select !== undefined);\n // D214: the selector of this render, read by a reader that belongs to the model. Writing the latest callback into\n // a ref is what `useSyncExternalStoreWithSelector` does: the reader only reads it, and never writes to it.\n const selectRef = useRef<ModelSelector<ModelOf<Declaration>> | undefined>(undefined);\n selectRef.current = select;\n const selected = select !== undefined;\n // D363: the memory of this selection belongs to the mount, so a reader React rebuilt keeps what it read last.\n const memoryRef = useRef<SelectionMemory | undefined>(undefined);\n const memory = (memoryRef.current ??= createSelectionMemory());\n const getSnapshot = useMemo(\n () => (selected ? createSelectionSnapshot(model, selectRef, memory) : readEmptySnapshot),\n [memory, model, selected],\n );\n const snapshot = useSyncExternalStore(store?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const hooks = useSelectionHooks(snapshot.commands, snapshot.resources);\n useLayoutEffect(() => () => store?.close(), [store]);\n // D359: a lease is taken in commit and never in a render, and the store diffs the set by identity.\n useLayoutEffect(() => store?.commit(snapshot.sources, snapshot.leases), [snapshot, store]);\n\n // An abandoned render may prepare another record, but only a committed render replaces the comparison baseline.\n const committedResult = useRef<SelectionResult | undefined>(undefined);\n const result = selected ? mergeSelection(snapshot, hooks, committedResult.current) : undefined;\n useLayoutEffect(() => {\n committedResult.current = result;\n });\n\n if (select === undefined) return model;\n\n return result;\n}\n\nexport { useModel };\n","import type { FunctionComponent } from 'react';\n\nimport type { ModelIdentity } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\n\ntype AnyModel = ModelIdentity;\n\n/**\n * The marker a component uses to state which UI models of its contribution it reads. `slot` checks by type that the\n * contribution grants every model of this list — it may grant more, because the mount serves its whole instance.\n *\n * The runtime authority is the mount frame, not this marker: `useModel` resolves against what the mount was given\n * and refuses anything else. The lint rule `opetope/require-declared-models` checks visible contribution sites and\n * each reader of a per-mount model within the same module. Imported implementations and dynamic declaration lists\n * remain unknown to this syntactic check (D85, D158, D250).\n */\ntype ComponentRequiringModels<Props, Models extends readonly AnyModel[]> = FunctionComponent<Props> & {\n readonly requires: Models;\n};\n\nfunction requiresModels<const Models extends readonly AnyModel[]>(\n models: Models,\n): <Props>(component: FunctionComponent<Props>) => ComponentRequiringModels<Props, Models> {\n const declared = Object.freeze([...models]) as unknown as Models;\n\n return <Props>(component: FunctionComponent<Props>): ComponentRequiringModels<Props, Models> => {\n const existing = (component as { readonly requires?: readonly AnyModel[] }).requires;\n\n if (existing !== undefined) {\n throw new ContributionError('duplicate', 'Component already declares the models it requires.');\n }\n\n Object.defineProperty(component, 'requires', { enumerable: false, value: declared });\n\n return component as ComponentRequiringModels<Props, Models>;\n };\n}\n\nexport { requiresModels };\n","import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react';\n\nimport type { PaginatedResource, PaginationState, Readable, Resource } from '@opetope/core';\nimport type { ResourceKey } from '@opetope/core/internal';\nimport { acquireResourceDemand, resourceViewReadable } from '@opetope/core/internal';\n\nimport { useCommandStatus } from './command-hook';\nimport { CommandHookController } from './command-hook-controller';\nimport { createResourceInvokers, paginationOf } from './resource-command';\nimport type { AnyResource, PaginatedResourceHook, ResourceHook, ResourcePaginationHook } from './resource-command';\n\ntype ResourceSlots = Readonly<{\n loadNext: CommandHookController<void, unknown>;\n refresh: CommandHookController<void, unknown>;\n reset: CommandHookController<void, unknown>;\n retry: CommandHookController<void, unknown>;\n}>;\n\n/**\n * D359: one set of controllers per Resource identity, exactly as `useCommandSlot` keeps one per invoker. The slots are\n * what the set of invokers is kept alive by, so one map answers for all four. Slots are inert until commit, so an\n * interrupted render neither admits work nor resets the status of the committed one.\n */\nfunction useResourceSlots(resource: AnyResource): ResourceSlots {\n const [cache] = useState(() => new WeakMap<object, ResourceSlots>());\n const existing = cache.get(resource);\n\n if (existing !== undefined) return existing;\n\n const invokers = createResourceInvokers(resource);\n const slots: ResourceSlots = {\n loadNext: new CommandHookController<void, unknown>(invokers.loadNext),\n refresh: new CommandHookController<void, unknown>(invokers.refresh),\n reset: new CommandHookController<void, unknown>(invokers.reset),\n retry: new CommandHookController<void, unknown>(invokers.retry),\n };\n cache.set(resource, slots);\n\n return slots;\n}\n\nconst unavailablePagination: PaginationState<ResourceKey> = Object.freeze({\n kind: 'unavailable',\n reason: 'resource-not-ready',\n});\nconst noPaginationSource: Readable<PaginationState<ResourceKey>> = Object.freeze({\n getSnapshot: () => unavailablePagination,\n subscribe: () => () => undefined,\n});\n\n/**\n * D359: the state of a Resource, the lease that keeps it open for as long as this component is mounted, and its verbs\n * as commands. The number of React hooks here does not depend on the Resource: a declaration without `pagination`\n * subscribes to a constant source and keeps a `loadNext` that answers `skipped`.\n */\nfunction useResource<Data, Key extends ResourceKey, Cursor extends ResourceKey>(\n resource: PaginatedResource<Data, Key, Cursor, 'consumers' | 'owner'>,\n): PaginatedResourceHook<Data, Key, Cursor>;\nfunction useResource<Data, Key extends ResourceKey>(\n resource: Resource<Data, Key, 'consumers' | 'owner'>,\n): ResourceHook<Data, Key>;\nfunction useResource<Data, Key extends ResourceKey>(\n resource: Resource<Data, Key, 'consumers' | 'owner'>,\n): ResourceHook<Data, Key> {\n const handle = resource as unknown as AnyResource;\n const capability = paginationOf(handle);\n const subscribe = useCallback(\n (listener: () => void) => resourceViewReadable(resource).subscribe(listener),\n [resource],\n );\n /*\n * D364: `resource.state` is a total `Readable` for the life of the object this hook holds — a retired one answers\n * `idle('retired')` — so the read needs no memory of its own. What it can still refuse is a producer failure, a\n * broken `nextCursor` among them (D356), and that belongs to the render (G13).\n */\n const getState = useMemo(() => () => resourceViewReadable(resource).getSnapshot(), [resource]);\n const state = useSyncExternalStore(subscribe, getState, getState);\n const paginationSource: Readable<PaginationState<ResourceKey>> =\n capability === undefined ? noPaginationSource : resourceViewReadable(capability);\n const subscribePagination = useCallback(\n (listener: () => void) => paginationSource.subscribe(listener),\n [paginationSource],\n );\n const getPaginationState = useMemo(() => () => paginationSource.getSnapshot(), [paginationSource]);\n const paginationState = useSyncExternalStore(subscribePagination, getPaginationState, getPaginationState);\n\n // D349: the lease is taken in a commit effect, so an interrupted render opens nothing.\n useEffect(() => acquireResourceDemand(resource), [resource]);\n\n const slots = useResourceSlots(handle);\n const refresh = useCommandStatus(slots.refresh);\n const retry = useCommandStatus(slots.retry);\n const reset = useCommandStatus(slots.reset);\n const loadNext = useCommandStatus(slots.loadNext);\n const pagination = useMemo(\n () =>\n capability === undefined\n ? undefined\n : ({ loadNext, state: paginationState } as unknown as ResourcePaginationHook<ResourceKey>),\n [capability, loadNext, paginationState],\n );\n\n return useMemo(\n () => ({ pagination, refresh, reset, retry, state }) as ResourceHook<Data, Key>,\n [pagination, refresh, reset, retry, state],\n );\n}\n\nexport { useResource };\n","import type { ComponentType, ReactNode } from 'react';\nimport { createElement, Fragment } from 'react';\n\nimport type { DeclarationId } from '@opetope/core';\nimport { declarationId } from '@opetope/core';\nimport type { ContributionTarget } from '@opetope/core/internal';\nimport { createContributionTarget } from '@opetope/core/internal';\nimport type { ContributionModel } from '@opetope/runtime/internal';\n\nimport { contributionAuthority, ContributionMount } from './contribution-frame';\nimport { useReadable } from './readable-hooks';\n\ntype SlotProperties = object | undefined;\ntype EmptySlotProperties = Readonly<Record<string, never>>;\ntype SlotComponentProperties<Props extends SlotProperties> = [Props] extends [undefined]\n ? EmptySlotProperties\n : Extract<Props, object>;\n\n/**\n * What a contribution publishes: the component, the optional props adapter and the optional UI models the mount\n * creates. Without an adapter the component takes the slot props; with one it takes exactly the adapter result (D85).\n */\ntype SlotContribution<Props extends SlotProperties = undefined> = {\n readonly Component: ComponentType<never>;\n readonly models?: readonly ContributionModel[];\n readonly props?: (slotProps: SlotComponentProperties<Props>) => object;\n};\n\ntype SlotTarget<Props extends SlotProperties = undefined> = ContributionTarget<SlotContribution<Props>>;\n\ntype SwitchSlotTarget<Route extends string, Props extends SlotProperties = undefined> = ((\n route: Route,\n) => SlotTarget<Props>) & {\n readonly id: DeclarationId;\n};\n\ntype SlotRenderProps<Props extends SlotProperties> = [Props] extends [undefined]\n ? {\n readonly props?: never;\n readonly target: SlotTarget<Props>;\n }\n : {\n readonly props: SlotComponentProperties<Props>;\n readonly target: SlotTarget<Props>;\n };\n\nconst emptySlotProperties: EmptySlotProperties = Object.freeze({});\n\n/** D280: a slot is a name, so it takes its id as the first argument. */\nfunction defineSlot<Props extends SlotProperties = undefined>(id: string): SlotTarget<Props> {\n return createContributionTarget<SlotContribution<Props>>(id, 'slot');\n}\n\nfunction defineSwitchSlot<Route extends string, Props extends SlotProperties = undefined>(\n id: string,\n): SwitchSlotTarget<Route, Props> {\n const declared = declarationId(id);\n const targets = new Map<Route, SlotTarget<Props>>();\n\n const switchSlot = (route: Route): SlotTarget<Props> => {\n const existing = targets.get(route);\n\n if (existing !== undefined) return existing;\n\n const target = defineSlot<Props>(`${declared}/${route}`);\n targets.set(route, target);\n\n return target;\n };\n\n Object.defineProperty(switchSlot, 'id', { enumerable: true, value: declared });\n\n return Object.freeze(switchSlot) as SwitchSlotTarget<Route, Props>;\n}\n\n/**\n * Every contribution renders inside its own mount: the models its generation owns plus the UI models it declared,\n * created on mount and closed on unmount (D70, D85).\n */\nfunction Slot<Props extends SlotProperties>(options: SlotRenderProps<Props>): ReactNode {\n const entries = useReadable(options.target.entries);\n const slotProps: object = 'props' in options ? (options.props ?? emptySlotProperties) : emptySlotProperties;\n\n if (entries.length === 0) return null;\n\n return entries.map(entry =>\n createElement(\n Fragment,\n { key: entry.id },\n createElement(ContributionMount, {\n authority: contributionAuthority(entry),\n contribution: entry.value,\n contributionId: entry.id,\n slotProps,\n targetId: options.target.id,\n }),\n ),\n );\n}\n\nexport { defineSlot, defineSwitchSlot, Slot };\nexport type { SlotComponentProperties, SlotContribution, SlotProperties, SlotTarget, SwitchSlotTarget };\n"],"names":["failureOutcome","options","error","isCancellation","notification","_a","reportDetachedError","callbackError","runOptions","onSuccess","signal","requestOf","input","resolve","promise","settle","request","outcome","CommandHookController","ContributionError","aborted","invoker","notify","CommandError","compatibleAbortReason","invocation","value","emptyStatus","settledOutcome","unchangedState","current","slot","inFlight","settled","nextState","previous","useCommandSlot","slots","useState","useCommandStatus","currentSlot","hookState","setHookState","useInsertionEffect","useLayoutEffect","run","useMemo","useCommand","command","record","useFrame","idleRelease","subscribeIdle","idleRevision","emptyHooks","isResourceEntry","entry","createEntry","unchangedHook","next","updateEntry","selectEntry","resourceHook","selected","createResourceEntry","invokers","parts","unchangedResourceCommands","hook","unchangedResourceState","unchangedResourceHook","selectResourceEntry","commandEntries","detachEntry","sameResourceConsumers","sameConsumers","hookOf","CommandGroup","key","listener","commands","resources","frame","resource","resourceInvokers","useCommandGroup","groupRef","useRef","useSelectionHooks","group","getSnapshot","useSyncExternalStore","noResources","noLeases","readSource","source","sources","isReadable","readPassively","classifyResource","isResource","capability","resourceViewReadable","selectedResources","collectResourceDemands","leases","isResourceView","demand","resourceViewDemands","collectSelection","select","project","readable","entries","equalResources","before","equalMembers","equalSelection","values","keys","previousKeys","index","emptySelectionSnapshot","selectionCommands","isCallTarget","observedUnchanged","observed","createSelectionMemory","createSelectionSnapshot","model","selectRef","memory","nextObserved","context","releaseSubscriptions","subscriptions","failures","subscription","dispose","createAggregateError","ModelSelectionStore","retained","held","removed","lease","release","readEmptySnapshot","useSelectionStore","storeRef","selectedValue","snapshot","hooks","mergeSelection","committed","oldKeys","useModel","declaration","store","memoryRef","committedResult","result","requiresModels","models","declared","component","useResourceSlots","cache","existing","createResourceInvokers","unavailablePagination","noPaginationSource","useResource","handle","paginationOf","subscribe","useCallback","getState","state","paginationSource","subscribePagination","getPaginationState","paginationState","useEffect","acquireResourceDemand","refresh","retry","reset","loadNext","pagination","emptySlotProperties","defineSlot","id","createContributionTarget","defineSwitchSlot","declarationId","targets","switchSlot","route","target","Slot","useReadable","slotProps","createElement","Fragment","ContributionMount","contributionAuthority"],"mappings":"2wBA+BA,SAASA,EAAuBC,EAAgDC,EAAc,OAC5F,GAAIC,GAAeD,CAAK,EAAG,MAAO,CAAE,OAAQA,EAAO,KAAM,WAAW,EAEpE,GAAI,CACF,MAAME,GAAeC,EAAAJ,GAAA,YAAAA,EAAS,YAAT,YAAAI,EAAA,KAAAJ,EAAqBC,GAEtCE,IAAiB,QAAgB,QAAQ,QAAQA,CAAY,EAAE,MAAME,CAAmB,CAC9F,OAASC,EAAe,CACtBD,EAAoBC,CAAa,CACnC,CAEA,MAAO,CAAE,MAAAL,EAAO,KAAM,QAAQ,CAChC,CAEA,SAASM,GAAmBP,EAA8C,CACxE,MAAMQ,EAAYR,GAAA,YAAAA,EAAS,UACrBS,EAAST,GAAA,YAAAA,EAAS,OAExB,OAAIQ,IAAc,OAAkBC,IAAW,OAAY,OAAY,CAAE,OAAAA,CAAM,EAExEA,IAAW,OAAY,CAAE,UAAAD,CAAS,EAAK,CAAE,UAAAA,EAAW,OAAAC,CAAM,CACnE,CAEA,SAASC,GACPC,EACAX,EAA8C,CAE9C,IAAIY,EACJ,MAAMC,EAAU,IAAI,QAAgCC,GAAS,CAC3DF,EAAUE,CACZ,CAAC,EAED,MAAO,CAAE,MAAAH,EAAO,QAASX,IAAY,OAAY,OAAY,CAAE,GAAGA,CAAO,EAAI,QAAAa,EAAS,QAAAD,CAAO,CAC/F,CAEA,SAASE,GAAsBC,EAAwCC,EAA+B,CACpG,MAAMJ,EAAUG,EAAQ,QACxBA,EAAQ,MAAQ,OAChBA,EAAQ,QAAU,OAClBA,EAAQ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
|
* `useResource` does. `read(resource.state)` is unchanged — it hands out the state and leases nothing — so naming one
|
|
9
9
|
* Resource both ways registers it twice: the subscription and the lease are independent.
|
|
10
10
|
*/
|
|
11
|
-
type SelectedValue<Value> = Value extends Command<infer Input, infer Output> ? CommandHook<Input, Output> : Value extends PaginatedResource<infer Data, infer Key extends ResourceKey, infer Cursor extends ResourceKey> ? PaginatedResourceHook<Data, Key, Cursor> : Value extends Resource<infer Data, infer Key extends ResourceKey> ? ResourceHook<Data, Key> : Value;
|
|
11
|
+
type SelectedValue<Value> = Value extends Command<infer Input, infer Output> ? CommandHook<Input, Output> : Value extends PaginatedResource<infer Data, infer Key extends ResourceKey, infer Cursor extends ResourceKey, 'consumers' | 'owner'> ? PaginatedResourceHook<Data, Key, Cursor> : Value extends Resource<infer Data, infer Key extends ResourceKey, 'consumers' | 'owner'> ? ResourceHook<Data, Key> : Value;
|
|
12
12
|
type ModelSelection<Selected> = {
|
|
13
13
|
readonly [Key in keyof Selected]: SelectedValue<Selected[Key]>;
|
|
14
14
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { Readable } from '@opetope/core';
|
|
1
|
+
import type { Readable, ResourceView } from '@opetope/core';
|
|
2
|
+
import type { ResourceDemand } from '@opetope/core/internal';
|
|
2
3
|
import type { AnyCommand } from './model-binding.js';
|
|
3
4
|
import type { AnyResource } from './resource-command.js';
|
|
5
|
+
type SelectionValue<Source> = Source extends ResourceView<infer Value> ? Value : Source extends Readable<infer Value> ? Value : never;
|
|
4
6
|
interface SelectionRead {
|
|
5
|
-
<
|
|
6
|
-
<
|
|
7
|
+
<Source extends Readable<unknown> | ResourceView<unknown>>(source: Source): SelectionValue<Source>;
|
|
8
|
+
<Source extends Readable<unknown> | ResourceView<unknown>, Selected>(source: Source, select: (value: SelectionValue<Source>) => Selected): Selected;
|
|
7
9
|
}
|
|
8
10
|
type SelectionContext = Readonly<{
|
|
9
11
|
read: SelectionRead;
|
|
@@ -24,7 +26,7 @@ type SelectedResource = Readonly<{
|
|
|
24
26
|
type SelectionSnapshot = Readonly<{
|
|
25
27
|
commands: Readonly<Record<PropertyKey, AnyCommand>>;
|
|
26
28
|
/** The set the mount leases; two keys naming one resource are one lease. */
|
|
27
|
-
leases: ReadonlySet<
|
|
29
|
+
leases: ReadonlySet<ResourceDemand>;
|
|
28
30
|
resources: ReadonlyMap<PropertyKey, SelectedResource>;
|
|
29
31
|
sources: ReadonlySet<Readable<unknown>>;
|
|
30
32
|
values: SelectionRecord;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable } from '@opetope/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ResourceDemand } from '@opetope/core/internal';
|
|
3
3
|
/** A subscription set, not a scheduler: source notifications use React's snapshot consistency check. */
|
|
4
4
|
declare class ModelSelectionStore {
|
|
5
5
|
private enabled;
|
|
@@ -10,7 +10,7 @@ declare class ModelSelectionStore {
|
|
|
10
10
|
private sources;
|
|
11
11
|
private readonly subscriptions;
|
|
12
12
|
close(): void;
|
|
13
|
-
commit(sources: ReadonlySet<Readable<unknown>>, retained?: ReadonlySet<
|
|
13
|
+
commit(sources: ReadonlySet<Readable<unknown>>, retained?: ReadonlySet<ResourceDemand>): void;
|
|
14
14
|
subscribe: (notify: () => void) => (() => void);
|
|
15
15
|
private add;
|
|
16
16
|
private notify;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* settled `outcome` — while the Resource stays owned by the model that declared it: cancelling this wait cancels the
|
|
5
5
|
* wait and not the load.
|
|
6
6
|
*/
|
|
7
|
-
import type { PaginationOutcome, PaginationState, Resource, ResourceOperationOutcome, ResourceState } from '@opetope/core';
|
|
7
|
+
import type { PaginationOutcome, PaginationState, Resource, ResourceOperationOutcome, ResourcePagination, ResourceState } from '@opetope/core';
|
|
8
8
|
import type { ResourceKey } from '@opetope/core/internal';
|
|
9
9
|
import type { CommandHook } from './command-hook.js';
|
|
10
10
|
import type { CommandInvoker } from './command-hook-controller.js';
|
|
@@ -13,9 +13,9 @@ import type { CommandInvoker } from './command-hook-controller.js';
|
|
|
13
13
|
* arguments — `never` is the narrowest `Data` a reader can be handed and a named `Key` *requires* `state.key`, so
|
|
14
14
|
* hardly any member of the family fitted it. Nothing was refused, because every value reaches this name through a
|
|
15
15
|
* cast, which is exactly why the name could drift. `ResourceKeyField<never>` requires no field, so
|
|
16
|
-
* `Resource<unknown, never>` is the one form every Resource satisfies — keyed or not, paginated or not.
|
|
16
|
+
* `Resource<unknown, never, 'consumers' | 'owner'>` is the one form every Resource satisfies — keyed or not, paginated or not.
|
|
17
17
|
*/
|
|
18
|
-
type AnyResource = Resource<unknown, never>;
|
|
18
|
+
type AnyResource = Resource<unknown, never, 'consumers' | 'owner'>;
|
|
19
19
|
/**
|
|
20
20
|
* D349, D359: a Resource is a structural contract a host may implement with an ordinary object, so the question the
|
|
21
21
|
* type of a selected field asked is answered by the runtime that owns it — the registry of the materializations it
|
|
@@ -52,7 +52,7 @@ type ResourceInvokers = Readonly<{
|
|
|
52
52
|
reset: CommandInvoker;
|
|
53
53
|
retry: CommandInvoker;
|
|
54
54
|
}>;
|
|
55
|
-
declare function paginationOf(resource: AnyResource):
|
|
55
|
+
declare function paginationOf(resource: AnyResource): ResourcePagination<ResourceKey, 'consumers' | 'owner'> | undefined;
|
|
56
56
|
/**
|
|
57
57
|
* One set per Resource identity. `selectEntry` and `useCommandSlot` both pick their controller by the identity of the
|
|
58
58
|
* invoker, so a set rebuilt on every render would reset `inFlight`, drop `outcome` and change `run` — which is why it
|
package/dist/resource-hook.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ import type { PaginatedResourceHook, ResourceHook } from './resource-command.js'
|
|
|
6
6
|
* as commands. The number of React hooks here does not depend on the Resource: a declaration without `pagination`
|
|
7
7
|
* subscribes to a constant source and keeps a `loadNext` that answers `skipped`.
|
|
8
8
|
*/
|
|
9
|
-
declare function useResource<Data, Key extends ResourceKey, Cursor extends ResourceKey>(resource: PaginatedResource<Data, Key, Cursor>): PaginatedResourceHook<Data, Key, Cursor>;
|
|
10
|
-
declare function useResource<Data, Key extends ResourceKey>(resource: Resource<Data, Key>): ResourceHook<Data, Key>;
|
|
9
|
+
declare function useResource<Data, Key extends ResourceKey, Cursor extends ResourceKey>(resource: PaginatedResource<Data, Key, Cursor, 'consumers' | 'owner'>): PaginatedResourceHook<Data, Key, Cursor>;
|
|
10
|
+
declare function useResource<Data, Key extends ResourceKey>(resource: Resource<Data, Key, 'consumers' | 'owner'>): ResourceHook<Data, Key>;
|
|
11
11
|
export { useResource };
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CommandTimeoutError as ye,WaitTimeoutError as ge,eventually as Se,openModel as ve,runCommand as $e,settled as ke,testReadable as Me,testResourceEpoch as Ce,waitFor as je,yieldTurn as Ee}from"@opetope/runtime/testing";import{hasOwn as E,createAggregateError as x}from"@opetope/core/internal";import{openApplication as _}from"@opetope/runtime";import{createInspectionSession as N}from"@opetope/runtime/internal";import{createElement as B}from"react";import{declarationId as H}from"@opetope/core";import{command as W}from"@opetope/core/testing";import{e as q,a as P,b as D,M as L}from"./contribution-frame-
|
|
1
|
+
import{CommandTimeoutError as ye,WaitTimeoutError as ge,eventually as Se,openModel as ve,runCommand as $e,settled as ke,testReadable as Me,testResourceEpoch as Ce,waitFor as je,yieldTurn as Ee}from"@opetope/runtime/testing";import{hasOwn as E,createAggregateError as x}from"@opetope/core/internal";import{openApplication as _}from"@opetope/runtime";import{createInspectionSession as N}from"@opetope/runtime/internal";import{createElement as B}from"react";import{declarationId as H}from"@opetope/core";import{command as W}from"@opetope/core/testing";import{e as q,a as P,b as D,M as L}from"./contribution-frame-Bh104T5Z.js";function U(e){if(e.state.kind==="ready")return[];const t=e.state.kind==="waiting"?` (${e.state.reason})`:"";return[`Feature ${e.label}: ${e.state.kind}${t}.`]}function G(e){if(e.lane===null)return`Command ${e.declaration}: ${e.state}; lane parallel; blockers none (parallel).`;const t=e.lane.blockedBy==="unknown"?"unknown":e.lane.blockedBy.join(", ");return`Command ${e.declaration}: ${e.state}; lane ${e.lane.declaration}; blockers ${t}.`}function J(e){if(e===void 0)return["Runtime activity: unknown."];const t=[];return(e.freshness==="stale"||e.truncated)&&t.push(`Activity: ${e.freshness}${e.truncated?", truncated":""}; completeness unknown.`),[...t,...e.features.map(n=>`Feature ${n.feature}: ${n.phase}; body ${n.body}; host demand unknown.`),...e.calls.map(G),...e.resources.map(n=>`Resource ${n.id}: ${n.state}; leases ${String(n.leases)}.`)]}function K(e){const t=[...e.runtime.conditions.flatMap(n=>n.state.kind==="true"?[]:[`Condition ${n.label}: ${n.state.kind}.`]),...e.runtime.instances.flatMap(U),...J(e.activity)];return t.length===0?"No registered runtime blocker observed; external UI and host work are unknown.":t.join(`
|
|
2
2
|
`)}class T extends Error{label;timeoutMs;snapshot;history;code="timeout";constructor(t,n,r,o){super(`Scenario timed out after ${String(n)}ms: ${t}.
|
|
3
3
|
${K(r)}`),this.label=t,this.timeoutMs=n,this.snapshot=r,this.history=o,this.name="ScenarioTimeoutError"}}function Q(e,t){return!t||e===void 0?!1:e.closed&&!e.truncated}function V(e,t,n){if(e===void 0)return["Runtime activity is unavailable."];const r=[];return e.truncated&&r.push("The activity snapshot is truncated."),e.freshness==="stale"&&!t&&r.push("The activity snapshot is stale."),n||r.push("Successful application and mount cleanup has not been observed."),Object.freeze(r)}function X(e,t){return e===void 0||e.truncated||e.freshness==="stale"&&!t?{calls:"unknown",features:"unknown",resources:"unknown"}:{calls:e.calls.length,features:e.features.length,resources:e.resources.length}}function Y(e,t){const n=e.activity,r=Q(n,t);return Object.freeze({...X(n,r),closed:t,reasons:V(n,r,t),scope:"registered-runtime",status:r?"complete":"unknown"})}class Z{released;get closed(){return this.completion!==void 0}available=!1;completion;handle;reject;resolve;constructor(t){this.released=t}close=()=>this.completion!==void 0?this.completion:(this.completion=new Promise((t,n)=>{this.resolve=t,this.reject=n}),this.available&&this.releaseAvailable(),this.completion);provide(t){this.available=!0,this.handle=t,this.closed&&this.releaseAvailable()}finish(t,n){const r=this.resolve,o=this.reject;this.resolve=void 0,this.reject=void 0,this.released(t,n),t?o==null||o(n):r==null||r()}releaseAvailable(){const t=this.handle;this.handle=void 0,this.available=!1;try{Promise.resolve(t==null?void 0:t.unmount()).then(()=>this.finish(!1),n=>this.finish(!0,n))}catch(n){this.finish(!0,n)}}}const ee=H("testing.contribution");function te(e){return q(W(e))}function O(e,t={}){const n=t.models??[];let r=t.props??{};const o=new Set,w={getSnapshot:()=>r,subscribe:i=>(o.add(i),()=>o.delete(i))},c=t.contribution,s=t.reporter,l=s===void 0?void 0:{models:[],reporter:s};return Object.freeze({close:()=>{r={},o.clear()},Slot:()=>{const i=P(e.entries),d=P(w);return(c===void 0?i.map(p=>[p.id,p.value,D(p)??l]):[[ee,c,l]]).map(([p,f,k])=>B(L,{authority:k,contribution:f,contributionId:p,fixtures:n,key:p,slotProps:d,targetId:e.id}))},updateProps:i=>{r=i;for(const d of[...o])d()}})}function ne(e,t={}){const n=O(e,t);return Object.freeze({Slot:n.Slot,updateProps:n.updateProps})}function C(e,t){if(!Number.isFinite(e)||e<=0||e>2147483647)throw new RangeError(`${t} must be a finite duration from 0 (exclusive) to 2147483647ms.`);return e}class re{source;listeners=new Set;pending=new Set;constructor(t){this.source=t}cancel(){for(const t of[...this.pending])t(new Error("Scenario is closing."))}deadline(t,n,r=this.source.timeoutMs){return C(r,"Scenario timeoutMs"),new Promise((o,w)=>{const c=setTimeout(()=>w(this.timeout(n,r)),r);Promise.resolve(t).then(s=>{clearTimeout(c),o(s)},s=>{clearTimeout(c),w(s)})})}notify=()=>{for(const t of[...this.listeners])t()};waitFor(t,n){const r=C(n.timeoutMs??this.source.timeoutMs,"Scenario timeoutMs"),o=C(n.pollIntervalMs??10,"Scenario pollIntervalMs");return new Promise((w,c)=>{let s=!1,l=()=>{};const y=(f,k=f!==void 0)=>{s||(s=!0,l(),k?c(f):w())},i=()=>{if(!s)try{t(this.source.getSnapshot())&&y()}catch(f){y(f,!0)}},d=f=>y(f),v=setTimeout(()=>y(this.timeout(n.label??"waitFor",r)),r),p=setInterval(i,o);l=()=>{clearTimeout(v),clearInterval(p),this.listeners.delete(i),this.pending.delete(d)},this.listeners.add(i),this.pending.add(d),i()})}timeout(t,n){return new T(t,n,this.source.getSnapshot(),this.source.history())}}function R(e,t){if(!Number.isSafeInteger(e)||e<1||e>1e4)throw new RangeError(`${t} must be an integer from 1 to 10000.`);return e}function oe(e){if(e===null||typeof e!="object"||!("mount"in e)||typeof e.mount!="function")throw new TypeError("Scenario requires a host.mount(Component) adapter.")}function se(e){return{...e.cleanupFailure===void 0?{}:{cleanupFailure:e.cleanupFailure},...E(e,"conditions")?{conditions:e.conditions}:{},...E(e,"grace")?{grace:e.grace}:{},...E(e,"imports")?{imports:e.imports}:{},reporter:e.reporter}}function ie(e,t){const n=C(t.timeoutMs??1e3,"Scenario timeoutMs"),r=R(t.historyCapacity??64,"Scenario historyCapacity"),o=R(t.activityCapacity??256,"Scenario activityCapacity");let w=t.host;oe(w);let c=_(e,se(t)),s;try{s=N(c,{activityCapacity:o,ringCapacity:r})}catch(u){throw c.ready.catch(()=>{}),c.close().catch(()=>{}),u}let l="open",y=!1,i=!1;const d=[],v=new Set,p=[],f=()=>s.getSnapshot(),k=()=>Object.freeze([...d]),$=new re({getSnapshot:f,history:k,timeoutMs:n}),j=()=>{if(!i){i=!0;try{const u=f(),m=d[d.length-1];((m==null?void 0:m.stateRevision)!==u.stateRevision||m.activity!==u.activity)&&(d.push(u),d.length>r&&d.shift())}finally{i=!1}$.notify()}},I=s.subscribe(j);j();const F=$.deadline(c.ready,"application ready");F.catch(()=>{});let M,g;const A=()=>{if(M!==void 0)return M;let u,m;M=new Promise((a,h)=>{u=a,m=h}),l="closing",$.cancel();const S=[];try{S.push(c.close())}catch(a){S.push(Promise.reject(a))}return S.push(...[...v].map(a=>a.close())),Promise.allSettled(S).then(a=>{const h=[...new Set([...p,...a.flatMap(b=>b.status==="rejected"?[b.reason]:[])])];p.length=0,l="closed";try{j()}catch(b){h.push(b)}finally{I(),s.close(),v.clear(),c=void 0,w=void 0}y=h.length===0,h.length===0?u():m(x(h,"Scenario cleanup failed."))}),M};return Object.freeze({close:()=>{if(g!==void 0)return g;const u=A();return g!==void 0||(g=$.deadline(u,"scenario close"),g.catch(()=>{l==="closing"&&(g=void 0)})),g},getSnapshot:f,history:k,mount:(u,m={})=>{if(l!=="open")throw new Error("Scenario is closing.");const S=O(u,m),a=new Z((b,z)=>{v.delete(a),S.close(),b&&p.push(z)});v.add(a);let h;try{if(h=w.mount(S.Slot),h===null||typeof h!="object"||typeof h.unmount!="function")throw new TypeError("Scenario host.mount must return an unmount() handle.");a.provide(h)}catch(b){throw a.provide(void 0),a.close().catch(()=>{}),b}return Object.freeze({host:h,unmount:a.close,updateProps:b=>{if(l!=="open"||a.closed)throw new Error("Scenario mount is closed.");S.updateProps(b),$.notify()}})},notify:()=>{l==="open"&&$.notify()},ownership:()=>Y(f(),y),ready:F,waitFor:(u,m={})=>l!=="open"?Promise.reject(new Error("Scenario is closing.")):$.waitFor(u,m)})}export{ye as CommandTimeoutError,T as ScenarioTimeoutError,ge as WaitTimeoutError,te as command,ie as createScenario,Se as eventually,ve as openModel,ne as renderSlot,$e as runCommand,ke as settled,Me as testReadable,Ce as testResourceEpoch,je as waitFor,Ee as yieldTurn};
|
|
4
4
|
//# sourceMappingURL=testing.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opetope/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20.19.0"
|
|
6
6
|
},
|
|
@@ -49,16 +49,16 @@
|
|
|
49
49
|
}
|
|
50
50
|
],
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@opetope/core": "0.
|
|
53
|
-
"@opetope/runtime": "0.
|
|
52
|
+
"@opetope/core": "0.14.0",
|
|
53
|
+
"@opetope/runtime": "0.14.0",
|
|
54
54
|
"@testing-library/react": "16.3.3",
|
|
55
55
|
"@types/react": "19.2.18",
|
|
56
56
|
"react": "19.2.8",
|
|
57
57
|
"react-dom": "19.2.8"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@opetope/core": "0.
|
|
61
|
-
"@opetope/runtime": "0.
|
|
60
|
+
"@opetope/core": "0.14.0",
|
|
61
|
+
"@opetope/runtime": "0.14.0",
|
|
62
62
|
"react": ">=19.0.0 <20"
|
|
63
63
|
},
|
|
64
64
|
"sideEffects": false,
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as m}from"react/jsx-runtime";import{useContext as T,createContext as V,useCallback as S,useRef as O,useMemo as p,useSyncExternalStore as k,useEffect as D,useInsertionEffect as A,useLayoutEffect as w,memo as N,useState as W}from"react";import{reportDetachedError as C,compatibleAbortReason as K,isCallTarget as _,isModel as G,isReadable as j,createLifetimeController as H,createCallController as J,getContributionOwner as Q,createState as U,createAggregateError as X}from"@opetope/core/internal";import{isResourceValue as Y,reportRuntimeFailure as Z,requireContributionModelPlans as ee,openContributionModels as te}from"@opetope/runtime/internal";import{C as u,u as ne,b as re}from"./contribution-isolation-Bzfbt4iM.js";import{CommandError as ie}from"@opetope/core";const x=V(void 0);function oe(){const t=T(x);if(t===void 0)throw new u("missing","Opetope hook was called outside a contribution mount.");return t}function y(t){return Y(t)}function se(t,e){return new Promise((n,r)=>{const i=()=>{r(new ie("cancelled","Resource operation wait was cancelled.",K(e)))};if(e.aborted){i();return}e.addEventListener("abort",i,{once:!0}),t.then(o=>{e.removeEventListener("abort",i),n(o)},o=>{e.removeEventListener("abort",i),r(o)})})}function ae(t,e){var r;const n=(r=e==null?void 0:e.onSuccess)==null?void 0:r.call(e,t);return n!==void 0&&Promise.resolve(n).catch(C),t}function v(t){return{run:(e,n)=>{let r;try{r=Promise.resolve(t())}catch(o){return Promise.reject(o)}const i=n==null?void 0:n.signal;return(i===void 0?r:se(r,i)).then(o=>ae(o,n))}}}const ce=Object.freeze({kind:"skipped",reason:"resource-not-ready"});function de(t){const e=t.pagination;if(!(typeof e!="object"||e===null))return e}function E(t){return{loadNext:v(()=>{const e=t.pagination;return e===void 0?Promise.resolve(ce):e.loadNext()}),refresh:v(()=>t.refresh()),reset:v(()=>t.reset()),retry:v(()=>t.retry())}}function ue(t,e){const n=e.get(t);if(n!==void 0)return n;const r=E(t);return e.set(t,r),r}const le=t=>t;function F(t,e,n){const r=e,i=(n==null?void 0:n.equals)??Object.is,o=S(d=>t.subscribe(d),[t]),c=O(void 0);let s=c.current;s===void 0&&(s={hasValue:!1,value:void 0},c.current=s);const a=p(()=>{let d=!1,h,f;return()=>{const b=t.getSnapshot();if(d&&Object.is(h,b))return f;const g=r(b);if(!d){let R=g;return s.hasValue&&i(s.value,g)&&(R=s.value),d=!0,h=b,f=R,f}return i(f,g)?(h=b,f):(h=b,f=g,f)}},[s,i,t,r]),l=k(o,a,a);return D(()=>{s.hasValue=!0,s.value=l},[s,l]),l}function z(t){return F(t,le)}const M=new WeakMap;function I(t){if(arguments.length>1)throw new u("binding-invalid","Command follows the target it binds; binding options are forbidden.");if(!_(t))throw new u("binding-invalid","Command target is not authentic.");return M.set(t,{target:t}),t}function fe(t){const e=M.get(t);if(e===void 0)throw new u("binding-invalid","Command binding is not authentic.");return e}function $(t){return typeof t=="object"&&t!==null&&M.has(t)}const he=Symbol("opetope.model-binding"),me=Symbol("opetope.model-binding-identity"),be=Object.freeze({}),L=new WeakMap;function pe(t,e,n){if(typeof n!="string")throw new u("binding-invalid",`Model ${t.id} accepts only string fields.`);const r=Object.getOwnPropertyDescriptor(e,n);if((r==null?void 0:r.enumerable)!==!0||!("value"in r))throw new u("binding-invalid",`Model ${t.id}.${n} requires an enumerable data binding.`);return r.value}function ge(t,e){const n=[],r=Reflect.ownKeys(e);if(r.length===0)throw new u("binding-invalid",`Model ${t.id} requires at least one field.`);for(const i of r){const o=pe(t,e,i);if(!(j(o)||y(o)||typeof o=="function")){if(!$(o))throw new u("binding-invalid",`Model ${t.id}.${String(i)} requires a Readable, a Resource or a bound command.`);n.push(o)}}return Object.freeze(n)}function q(t,e){if(!G(t))throw new u("binding-invalid","Model declaration is not authentic.");if(typeof e!="object"||e===null)throw new u("binding-invalid",`Model ${t.id} requires a record binding.`);const n=ge(t,e),r=Object.freeze({[he]:be,[me]:!0});return L.set(r,{commands:n,declaration:t,model:e}),r}function we(t){const e=L.get(t);if(e===void 0)throw new u("binding-invalid","Model binding is not authentic.");return e}let Ce=0;function ve(t){const e=new Map,n=[],r=new Set;for(const i of t){const o=we(i);if(e.has(o.declaration))throw new u("duplicate",`Model ${o.declaration.id} is bound twice in one mount.`);e.set(o.declaration,o.model);for(const c of o.commands)r.has(c)||(r.add(c),n.push(c))}return{commands:Object.freeze(n),frame:{commandRecords:new Map,models:e}}}class ye{frame;authority;boundCommands;closeTicket=0;isActive;lifetime;onClose;released=!1;rendererAttached=!1;renderListeners=new Set;state="detached";constructor(e,n){const r=++Ce;this.lifetime=H({id:`contribution.${String(r)}`}),this.isActive=n==null?void 0:n.isActive,this.onClose=n==null?void 0:n.onClose;const{commands:i,frame:o}=ve(e);this.frame=o,this.boundCommands=i,this.buildCommandRecords(r)}attach(){if(this.state==="closing")return this.closeTicket+=1,this.state="active",this.rendererAttached=!0,!0;if(this.state==="closed")return!1;if(this.state==="active")throw new u("duplicate","One contribution mount cannot mount twice.");const e=this.createAuthority(this.lifetime.open());try{for(const n of this.frame.commandRecords.values())n.controller.activate()}catch(n){throw this.authority=e,this.state="active",this.close(),n}return this.authority=e,this.rendererAttached=!0,this.state="active",!0}close(){if(this.state==="closed")return;this.state="closed",this.closeTicket+=1,this.lifetime.close(),this.authority=void 0;for(const n of this.frame.commandRecords.values())n.controller.close();const e=this.onClose;this.onClose=void 0,e==null||e(),this.publishRenderable(),this.rendererAttached||this.releaseFrame()}detach(){if(!this.rendererAttached)return;if(this.rendererAttached=!1,this.state==="closed"){this.releaseFrame();return}if(this.state!=="active")return;this.state="closing";const e=++this.closeTicket;queueMicrotask(()=>{this.state==="closing"&&e===this.closeTicket&&this.close()})}diagnostics(){const e=[...this.frame.commandRecords.values()].map(n=>n.controller.diagnostics());return Object.freeze({active:this.state==="active",calls:Object.freeze(e),commandRecords:this.frame.commandRecords.size,models:this.frame.models.size})}getRenderableSnapshot=()=>this.state!=="closed"&&(this.isActive===void 0||this.isActive());releaseClosedFrame(){this.state==="closed"&&this.releaseFrame()}subscribeRenderable=e=>{if(this.state==="closed")return()=>{};const n={listener:e};this.renderListeners.add(n);let r=!0;return()=>{r&&(r=!1,this.renderListeners.delete(n))}};buildCommandRecords(e){let n=0;for(const r of this.boundCommands){fe(r);const i=J(r,{captureAuthority:this.captureAuthority,id:`contributionCommand.${String(e)}.${String(++n)}`,scheduling:{policy:"parallel"}});this.frame.commandRecords.set(r,{controller:i,invoker:Object.freeze({run:i.run})})}}captureAuthority=()=>{const e=this.authority;if(this.state!=="active"||e===void 0)throw new u("inactive","Contribution mount is not active.");return e.assertCurrent(),e};createAuthority(e){return Object.freeze({assertCurrent:()=>{if(this.state!=="active")throw new u("inactive","Contribution mount is not active.");e.assertCurrent()},isCurrent:()=>this.state==="active"&&e.isCurrent()})}publishRenderable(){for(const{listener:e}of[...this.renderListeners])try{e()}catch(n){C(n)}}releaseFrame(){this.released||(this.released=!0,this.frame.commandRecords.clear(),this.frame.models.clear(),this.boundCommands=[],this.renderListeners.clear())}}function Me({children:t,mount:e}){const n=k(e.subscribeRenderable,e.getRenderableSnapshot,e.getRenderableSnapshot);return A(()=>{if(e.attach())return()=>e.detach()},[e]),w(()=>{n||e.releaseClosedFrame()},[e,n]),n?m(x,{value:e.frame,children:t}):null}function B(t){const e=t.bundle;t.bundle=void 0,e==null||e.frame.close()}function Re(t,e){if(typeof e!="object"||e===null)return q(t,e);const n=i=>j(i)||y(i)||typeof i=="function"||$(i),r=Object.entries(e).map(([i,o])=>[i,n(o)?o:I(o)]);return q(t,Object.fromEntries(r))}function Se(t){return Q(t)}const Oe={models:[]};function P(t,e){try{t()}catch(n){throw X([e,n],"Contribution mount setup and cleanup failed.",{cause:e})}throw e}function ke(t,e,n,r){const i=U(e),{models:o,reporter:c}=r??Oe;try{const s=ee(t.models),a=s.length===0?void 0:te(s,i,c);return{bundle:a,models:[...o,...(a==null?void 0:a.models)??[],...n],props:i}}catch(s){return P(i.close,s)}}function Ae(t,e,n,r){const{bundle:i,models:o,props:c}=ke(t,e,n,r);let s=!1;const a=()=>{if(!s){s=!0;try{i==null||i.close().catch(C)}finally{c.close()}}};try{return{frame:new ye(o.map(([d,h])=>Re(d,h)),{isActive:()=>!s,onClose:a}),isOpen:()=>!s,props:c}}catch(l){return P(a,l)}}function je(t,e){return m(t,{...e})}function xe({bundle:t,contribution:e}){const n=z(t.props),r=p(()=>e.props===void 0?n:e.props(n),[n,e]);return m(Me,{mount:t.frame,children:je(e.Component,r)})}function Ee({authority:t,contribution:e,fixtures:n,slotProps:r}){const i=p(()=>({authority:t,bundle:void 0,contribution:e,fixtures:n,retired:!1}),[t,e,n]),[o,c]=W(void 0),s=(o==null?void 0:o.owner)===i?o.bundle:void 0,a=O(r);return w(()=>{a.current=r}),A(()=>()=>{i.retired=!0,queueMicrotask(()=>{try{B(i)}catch(l){C(l)}})},[i]),w(()=>{const l=i.bundle??(i.bundle=Ae(i.contribution,a.current,i.fixtures??[],i.authority));return c(d=>(d==null?void 0:d.owner)===i?d:{bundle:l,owner:i}),()=>{i.retired&&B(i)}},[i]),w(()=>{(s==null?void 0:s.isOpen())===!0&&s.props.set(r)},[s,r]),s===void 0?null:m(xe,{bundle:s,contribution:e})}function Fe(t){const{authority:e,contribution:n,contributionId:r,fixtures:i,targetId:o}=t,c=ne(),s=p(()=>({authority:e,contribution:n,fixtures:i}),[e,n,i]),a=e==null?void 0:e.feature,l=p(()=>({contribution:r,feature:a,target:o}),[r,a,o]),d=e==null?void 0:e.reporter,h=S(f=>Z(f,d),[d]);return m(re,{content:c,identity:s,report:h,source:l,children:m(Ee,{...t})})}const ze=N(Fe);export{ze as M,z as a,Se as b,E as c,F as d,I as e,y as i,de as p,ue as r,oe as u};
|
|
2
|
-
//# sourceMappingURL=contribution-frame-CCKnOxZR.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contribution-frame-CCKnOxZR.js","sources":["../src/mount-context.tsx","../src/resource-command.ts","../src/readable-hooks.ts","../src/command.ts","../src/model-binding.ts","../src/mount-frame.ts","../src/mount-provider.tsx","../src/contribution-frame.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport { ContributionError } from './errors';\nimport type { Frame } from './mount-frame';\n\nconst FrameContext = createContext<Frame | undefined>(undefined);\n\nfunction useFrame(): Frame {\n const frame = useContext(FrameContext);\n\n if (frame === undefined) {\n throw new ContributionError('missing', 'Opetope hook was called outside a contribution mount.');\n }\n\n return frame;\n}\n\nexport { FrameContext, useFrame };\n","/**\n * D359: the verbs of a Resource, dressed as the commands a button already knows, and the recognition that answers\n * «is this selected field a Resource». A consumer keeps a status — `inFlight` until the operation settles, the\n * settled `outcome` — while the Resource stays owned by the model that declared it: cancelling this wait cancels the\n * wait and not the load.\n */\n\nimport { CommandError } from '@opetope/core';\nimport type {\n PaginationOutcome,\n PaginationState,\n Resource,\n ResourceOperationOutcome,\n ResourceState,\n} from '@opetope/core';\nimport { compatibleAbortReason, reportDetachedError } from '@opetope/core/internal';\nimport type { CallRunOptions, ResourceKey } from '@opetope/core/internal';\nimport { isResourceValue } from '@opetope/runtime/internal';\n\nimport type { CommandHook } from './command-hook';\nimport type { CommandInvoker } from './command-hook-controller';\n\n/**\n * D439: the widest Resource, and the name says so. `Resource<never, ResourceKey>` said the opposite in both\n * arguments — `never` is the narrowest `Data` a reader can be handed and a named `Key` *requires* `state.key`, so\n * hardly any member of the family fitted it. Nothing was refused, because every value reaches this name through a\n * cast, which is exactly why the name could drift. `ResourceKeyField<never>` requires no field, so\n * `Resource<unknown, never>` is the one form every Resource satisfies — keyed or not, paginated or not.\n */\ntype AnyResource = Resource<unknown, never>;\n\n/**\n * D349, D359: a Resource is a structural contract a host may implement with an ordinary object, so the question the\n * type of a selected field asked is answered by the runtime that owns it — the registry of the materializations it\n * built, and the structural contract for everything else. Asking it here a second time would let the two answers\n * drift, and a host adapter typed as a hook reaches the render where `state` is `undefined` and `refresh.run()`\n * throws.\n */\nfunction isResource(value: unknown): boolean {\n return isResourceValue(value);\n}\n\n/** D356: the nested capability, with `loadNext` as a command and the projected pagination state beside it. */\ntype ResourcePaginationHook<Cursor extends ResourceKey> = Readonly<{\n loadNext: CommandHook<void, PaginationOutcome<Cursor>>;\n state: PaginationState<Cursor>;\n}>;\n\n/**\n * D359: what `useResource` answers, and what a field of a `useModel` selection whose value is a Resource answers.\n * The verbs never reject (a Resource answers an outcome), so the ordinary path of `outcome` is\n * `{ kind: 'ok', value }`; `failed` stays in the type because the controller turns a synchronous throw of an\n * invoker into it, and the wrapper below carries its own test that it never throws synchronously.\n */\ntype ResourceHook<Data, Key extends ResourceKey = never> = Readonly<{\n /** Present when the declaration carried `pagination`; `undefined` for every other Resource. */\n pagination: ResourcePaginationHook<ResourceKey> | undefined;\n refresh: CommandHook<void, ResourceOperationOutcome>;\n reset: CommandHook<void, ResourceOperationOutcome>;\n retry: CommandHook<void, ResourceOperationOutcome>;\n state: ResourceState<Data, Key>;\n}>;\n\ntype PaginatedResourceHook<Data, Key extends ResourceKey, Cursor extends ResourceKey> = Omit<\n ResourceHook<Data, Key>,\n 'pagination'\n> &\n Readonly<{ pagination: ResourcePaginationHook<Cursor> }>;\n\ntype ResourceInvokers = Readonly<{\n loadNext: CommandInvoker;\n refresh: CommandInvoker;\n reset: CommandInvoker;\n retry: CommandInvoker;\n}>;\n\n/** The consumer's own cancellation: it ends this wait, and the work the model owns keeps running. */\nfunction awaitCancellable(operation: Promise<unknown>, signal: AbortSignal): Promise<unknown> {\n return new Promise<unknown>((resolve, reject) => {\n const cancel = (): void => {\n reject(new CommandError('cancelled', 'Resource operation wait was cancelled.', compatibleAbortReason(signal)));\n };\n\n if (signal.aborted) {\n cancel();\n\n return;\n }\n\n signal.addEventListener('abort', cancel, { once: true });\n operation.then(\n value => {\n signal.removeEventListener('abort', cancel);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', cancel);\n reject(error);\n },\n );\n });\n}\n\nfunction notifySuccess(value: unknown, options: CallRunOptions<unknown> | undefined): unknown {\n const notification = options?.onSuccess?.(value);\n\n // The failure of a consumer's own callback is detached from the operation it watched, as it is for a command.\n if (notification !== undefined) void Promise.resolve(notification).catch(reportDetachedError);\n\n return value;\n}\n\n/**\n * The invariant of this wrapper: it never throws synchronously, so the `failed` outcome a consumer can see is the one\n * the verb itself produced and never one this layer invented in the middle of a render commit.\n */\nfunction operationInvoker(start: () => Promise<unknown>): CommandInvoker {\n return {\n run: (_input: never, options?: CallRunOptions<unknown>): Promise<unknown> => {\n let operation: Promise<unknown>;\n\n try {\n operation = Promise.resolve(start());\n } catch (error) {\n return Promise.reject(error);\n }\n\n const signal = options?.signal;\n\n return (signal === undefined ? operation : awaitCancellable(operation, signal)).then(value =>\n notifySuccess(value, options),\n );\n },\n };\n}\n\n/** A Resource without the capability still answers a `loadNext` invoker, so the hook count never moves. */\nconst unavailablePage: PaginationOutcome<ResourceKey> = Object.freeze({\n kind: 'skipped',\n reason: 'resource-not-ready',\n});\n\nfunction paginationOf(resource: AnyResource): ResourcePaginationHook<ResourceKey> | undefined {\n const capability = (resource as { readonly pagination?: unknown }).pagination;\n\n if (typeof capability !== 'object' || capability === null) return undefined;\n\n return capability as unknown as ResourcePaginationHook<ResourceKey>;\n}\n\n/**\n * One set per Resource identity. `selectEntry` and `useCommandSlot` both pick their controller by the identity of the\n * invoker, so a set rebuilt on every render would reset `inFlight`, drop `outcome` and change `run` — which is why it\n * is memoised against the Resource itself and never assembled during a render.\n */\nfunction createResourceInvokers(resource: AnyResource): ResourceInvokers {\n // D349: a Resource is a structural contract, so every verb is called through it and never as a detached function.\n return {\n loadNext: operationInvoker(() => {\n const capability = (resource as { readonly pagination?: { loadNext(): Promise<unknown> } }).pagination;\n\n return capability === undefined ? Promise.resolve(unavailablePage) : capability.loadNext();\n }),\n refresh: operationInvoker(() => resource.refresh()),\n reset: operationInvoker(() => resource.reset()),\n retry: operationInvoker(() => resource.retry()),\n };\n}\n\nfunction resourceInvokers(resource: AnyResource, cache: WeakMap<object, ResourceInvokers>): ResourceInvokers {\n const existing = cache.get(resource);\n\n if (existing !== undefined) return existing;\n\n const invokers = createResourceInvokers(resource);\n cache.set(resource, invokers);\n\n return invokers;\n}\n\n/**\n * The one module of this package that talks to the runtime about a materialization, so the rest of React reads the\n * recognition and the key type from here instead of routing to `@opetope/runtime/internal` of its own.\n */\nexport { createResourceInvokers, isResource, paginationOf, resourceInvokers };\nexport type { AnyResource, PaginatedResourceHook, ResourceHook, ResourceInvokers, ResourceKey, ResourcePaginationHook };\n","import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Readable } from '@opetope/core';\nimport type { EqualityOption } from '@opetope/core/internal';\n\nconst identity = <Value>(value: Value): Value => value;\n\n/**\n * D364: what this mount answered last, and nothing about closes. A source whose owner retired stops instead of\n * refusing — it keeps answering its last value — so a render that races a retirement shows its last frame and\n * unmounts (G13) without the reader having to remember anything for it.\n */\ninterface SelectionInstance<Selected> {\n hasValue: boolean;\n value: Selected | undefined;\n}\n\n/**\n * D279: the source and the selection are positional; `equals` is the one modifier, spelled as in Core — including\n * D348's rule for where the comparator is read, so a named non-generic one compiles here as it does in `derive`.\n */\nexport function useSelector<Value, Selected>(\n readable: Readable<Value>,\n select: (value: NoInfer<Value>) => Selected,\n options?: { readonly equals?: EqualityOption<NoInfer<Selected>> },\n): Selected {\n const selector = select;\n const isEqual = options?.equals ?? Object.is;\n const subscribe = useCallback((listener: () => void) => readable.subscribe(listener), [readable]);\n const instanceRef = useRef<SelectionInstance<Selected> | undefined>(undefined);\n let instance = instanceRef.current;\n\n if (instance === undefined) {\n instance = { hasValue: false, value: undefined };\n instanceRef.current = instance;\n }\n\n const getSelectedSnapshot = useMemo(() => {\n let initialized = false;\n let sourceSnapshot: Value;\n let selectedSnapshot: Selected;\n\n return (): Selected => {\n const nextSource = readable.getSnapshot();\n\n if (initialized && Object.is(sourceSnapshot, nextSource)) return selectedSnapshot;\n\n const nextSelected = selector(nextSource);\n\n if (!initialized) {\n let nextSelectedSnapshot = nextSelected;\n\n if (instance.hasValue && isEqual(instance.value, nextSelected)) {\n nextSelectedSnapshot = instance.value as Selected;\n }\n\n initialized = true;\n sourceSnapshot = nextSource;\n selectedSnapshot = nextSelectedSnapshot;\n\n return selectedSnapshot;\n }\n\n if (isEqual(selectedSnapshot, nextSelected)) {\n sourceSnapshot = nextSource;\n\n return selectedSnapshot;\n }\n\n sourceSnapshot = nextSource;\n selectedSnapshot = nextSelected;\n\n return selectedSnapshot;\n };\n }, [instance, isEqual, readable, selector]);\n\n const selected = useSyncExternalStore(subscribe, getSelectedSnapshot, getSelectedSnapshot);\n\n useEffect(() => {\n instance.hasValue = true;\n instance.value = selected;\n }, [instance, selected]);\n\n return selected;\n}\n\nexport function useReadable<Value>(readable: Readable<Value>): Value {\n return useSelector(readable, identity);\n}\n","import type { Command } from '@opetope/core';\nimport { isCallTarget } from '@opetope/core/internal';\n\nimport { ContributionError } from './errors';\n\n/**\n * A bound command is the authentic `Command` the model field declares, so the common path adds no wrapper. Observable\n * call state belongs to the model as a `Readable` field (D71), so a binding carries no mode.\n */\ntype CommandBindingIdentity = Command<never, unknown>;\ntype CommandBinding<Input, Output> = Command<Input, Output>;\n\ntype CommandOutcome<Output> =\n | { readonly error: unknown; readonly kind: 'failed' }\n | { readonly reason: unknown; readonly kind: 'cancelled' }\n | { readonly kind: 'ok'; readonly value: Output };\n\ntype AnyCommandBinding = CommandBinding<never, unknown>;\n\ntype CommandBindingDefinition<Input, Output> = {\n readonly target: Command<Input, Output>;\n};\n\nconst bindingDefinitions = new WeakMap<CommandBindingIdentity, CommandBindingDefinition<never, unknown>>();\n\nfunction bindCommand<Input, Output>(target: Command<Input, Output>): CommandBinding<Input, Output> {\n if (arguments.length > 1) {\n throw new ContributionError(\n 'binding-invalid',\n 'Command follows the target it binds; binding options are forbidden.',\n );\n }\n\n if (!isCallTarget(target)) throw new ContributionError('binding-invalid', 'Command target is not authentic.');\n\n bindingDefinitions.set(target, { target });\n\n return target;\n}\n\nfunction getCommandBindingDefinition<Input, Output>(\n binding: Command<Input, Output>,\n): CommandBindingDefinition<Input, Output> {\n const definition = bindingDefinitions.get(binding);\n\n if (definition === undefined) throw new ContributionError('binding-invalid', 'Command binding is not authentic.');\n\n return definition as CommandBindingDefinition<Input, Output>;\n}\n\nfunction isCommandBinding(value: unknown): value is AnyCommandBinding {\n return typeof value === 'object' && value !== null && bindingDefinitions.has(value as CommandBindingIdentity);\n}\n\nexport { bindCommand, getCommandBindingDefinition, isCommandBinding };\nexport type { CommandOutcome };\n","import type { Command, ModelOf } from '@opetope/core';\nimport { isModel, isReadable } from '@opetope/core/internal';\nimport type { ExactKeys, ModelIdentity } from '@opetope/core/internal';\n\nimport { isCommandBinding } from './command';\nimport { ContributionError } from './errors';\nimport { isResource } from './resource-command';\n\nconst modelBindingBrand = Symbol('opetope.model-binding');\nconst modelBindingIdentityBrand = Symbol('opetope.model-binding-identity');\nconst modelBindingMarker = Object.freeze({});\n\ntype AnyModel = ModelIdentity;\ntype AnyCommand = Command<never, unknown>;\n\ninterface ModelBindingIdentity {\n readonly [modelBindingIdentityBrand]: true;\n}\n\ninterface ModelBinding<Declaration extends AnyModel> extends ModelBindingIdentity {\n readonly [modelBindingBrand]: (declaration: Declaration) => Declaration;\n}\n\ntype ModelBindingMetadata = {\n readonly commands: readonly AnyCommand[];\n readonly declaration: AnyModel;\n readonly model: object;\n};\n\nconst registry = new WeakMap<ModelBindingIdentity, ModelBindingMetadata>();\n\n/**\n * A model field is either a stable Readable or a bound command. The declaration carries the shape in its type, so\n * binding authority is the runtime check that every published field is one of those two authentic kinds.\n */\nfunction modelFieldValue(declaration: AnyModel, model: object, field: PropertyKey): unknown {\n if (typeof field !== 'string') {\n throw new ContributionError('binding-invalid', `Model ${declaration.id} accepts only string fields.`);\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(model, field);\n\n if (descriptor?.enumerable !== true || !('value' in descriptor)) {\n throw new ContributionError(\n 'binding-invalid',\n `Model ${declaration.id}.${field} requires an enumerable data binding.`,\n );\n }\n\n return descriptor.value;\n}\n\nfunction snapshotModelFields(declaration: AnyModel, model: object): readonly AnyCommand[] {\n const commands: AnyCommand[] = [];\n const fields = Reflect.ownKeys(model);\n\n if (fields.length === 0)\n throw new ContributionError('binding-invalid', `Model ${declaration.id} requires at least one field.`);\n\n for (const field of fields) {\n const value = modelFieldValue(declaration, model, field);\n\n // D349: a Resource is a field a model publishes, and it is not a `Readable`, so it is recognised by name.\n if (isReadable(value) || isResource(value) || typeof value === 'function') continue;\n\n if (!isCommandBinding(value)) {\n throw new ContributionError(\n 'binding-invalid',\n `Model ${declaration.id}.${String(field)} requires a Readable, a Resource or a bound command.`,\n );\n }\n\n commands.push(value);\n }\n\n return Object.freeze(commands);\n}\n\nfunction bindModel<Declaration extends AnyModel, const Keys extends PropertyKey = never>(\n declaration: Declaration,\n model: ExactKeys<Keys, ModelOf<Declaration>> & ModelOf<Declaration>,\n): ModelBinding<Declaration> {\n if (!isModel(declaration)) throw new ContributionError('binding-invalid', 'Model declaration is not authentic.');\n\n if (typeof model !== 'object' || model === null) {\n throw new ContributionError('binding-invalid', `Model ${declaration.id} requires a record binding.`);\n }\n\n const commands = snapshotModelFields(declaration, model);\n const binding = Object.freeze({\n [modelBindingBrand]: modelBindingMarker as unknown as (value: Declaration) => Declaration,\n [modelBindingIdentityBrand]: true as const,\n });\n registry.set(binding, { commands, declaration, model });\n\n return binding;\n}\n\nfunction getModelBindingMetadata(binding: ModelBindingIdentity): ModelBindingMetadata {\n const metadata = registry.get(binding);\n\n if (metadata === undefined) throw new ContributionError('binding-invalid', 'Model binding is not authentic.');\n\n return metadata;\n}\n\nexport { bindModel, getModelBindingMetadata };\nexport type { AnyCommand, AnyModel, ModelBindingIdentity };\n","import type {\n CallAuthority,\n CallController,\n CallDiagnostics,\n CallRunOptions,\n LifetimeLease,\n} from '@opetope/core/internal';\nimport { createCallController, createLifetimeController, reportDetachedError } from '@opetope/core/internal';\n\nimport { getCommandBindingDefinition } from './command';\nimport { ContributionError } from './errors';\nimport { getModelBindingMetadata } from './model-binding';\nimport type { AnyCommand, AnyModel, ModelBindingIdentity } from './model-binding';\n\ntype RuntimeCommandInvoker = {\n readonly run: (input: never, options?: CallRunOptions<unknown>) => Promise<unknown>;\n};\n\ntype CommandRecord = {\n readonly controller: CallController<never, unknown>;\n readonly invoker: RuntimeCommandInvoker;\n};\n\n/** What a mounted contribution grants its components: the models it may read and the commands it may invoke. */\ntype Frame = {\n readonly commandRecords: Map<AnyCommand, CommandRecord>;\n readonly models: Map<AnyModel, unknown>;\n};\n\ntype MountFrameLifecycle = {\n readonly isActive: () => boolean;\n readonly onClose: () => void;\n};\n\ntype MountFrameDiagnostics = {\n readonly active: boolean;\n readonly calls: readonly CallDiagnostics[];\n readonly commandRecords: number;\n readonly models: number;\n};\n\nlet nextMountId = 0;\n\nfunction buildFrame(supplied: readonly ModelBindingIdentity[]): {\n readonly commands: readonly AnyCommand[];\n readonly frame: Frame;\n} {\n const models = new Map<AnyModel, unknown>();\n const commands: AnyCommand[] = [];\n const bound = new Set<AnyCommand>();\n\n for (const candidate of supplied) {\n const binding = getModelBindingMetadata(candidate);\n\n if (models.has(binding.declaration)) {\n throw new ContributionError('duplicate', `Model ${binding.declaration.id} is bound twice in one mount.`);\n }\n\n models.set(binding.declaration, binding.model);\n\n for (const command of binding.commands) {\n // D197: one Command is one command of the mount, however many fields of the models name it. A second name is an\n // alias, not a second command, so it shares the record, the activation and the fence.\n if (bound.has(command)) continue;\n\n bound.add(command);\n commands.push(command);\n }\n }\n\n return { commands: Object.freeze(commands), frame: { commandRecords: new Map(), models } };\n}\n\n/**\n * The lifetime of one mounted contribution. `attach` claims it for the renderer, `detach` schedules the close on the\n * next microtask so a StrictMode remount reuses the same mount, and `close` fences every command it granted (D85).\n */\nclass MountFrameImpl {\n readonly frame: Frame;\n private authority: CallAuthority | undefined;\n private boundCommands: readonly AnyCommand[];\n private closeTicket = 0;\n private readonly isActive: (() => boolean) | undefined;\n private readonly lifetime: ReturnType<typeof createLifetimeController>;\n private onClose: (() => void) | undefined;\n private released = false;\n private rendererAttached = false;\n private readonly renderListeners = new Set<{ readonly listener: () => void }>();\n private state: 'active' | 'closed' | 'closing' | 'detached' = 'detached';\n\n constructor(models: readonly ModelBindingIdentity[], lifecycle?: MountFrameLifecycle) {\n const mountId = ++nextMountId;\n this.lifetime = createLifetimeController({ id: `contribution.${String(mountId)}` });\n this.isActive = lifecycle?.isActive;\n this.onClose = lifecycle?.onClose;\n const { commands, frame } = buildFrame(models);\n this.frame = frame;\n this.boundCommands = commands;\n this.buildCommandRecords(mountId);\n }\n\n attach(): boolean {\n if (this.state === 'closing') {\n this.closeTicket += 1;\n this.state = 'active';\n this.rendererAttached = true;\n\n return true;\n }\n\n if (this.state === 'closed') return false;\n\n if (this.state === 'active') throw new ContributionError('duplicate', 'One contribution mount cannot mount twice.');\n\n const authority = this.createAuthority(this.lifetime.open());\n\n try {\n for (const record of this.frame.commandRecords.values()) record.controller.activate();\n } catch (error) {\n this.authority = authority;\n this.state = 'active';\n this.close();\n\n throw error;\n }\n\n this.authority = authority;\n this.rendererAttached = true;\n this.state = 'active';\n\n return true;\n }\n\n close(): void {\n if (this.state === 'closed') return;\n\n this.state = 'closed';\n this.closeTicket += 1;\n this.lifetime.close();\n this.authority = undefined;\n\n for (const record of this.frame.commandRecords.values()) record.controller.close();\n\n const onClose = this.onClose;\n this.onClose = undefined;\n onClose?.();\n this.publishRenderable();\n\n if (!this.rendererAttached) this.releaseFrame();\n }\n\n detach(): void {\n if (!this.rendererAttached) return;\n\n this.rendererAttached = false;\n\n if (this.state === 'closed') {\n this.releaseFrame();\n\n return;\n }\n\n if (this.state !== 'active') return;\n\n this.state = 'closing';\n const ticket = ++this.closeTicket;\n\n queueMicrotask(() => {\n if (this.state === 'closing' && ticket === this.closeTicket) this.close();\n });\n }\n\n diagnostics(): MountFrameDiagnostics {\n const calls = [...this.frame.commandRecords.values()].map(record => record.controller.diagnostics());\n\n return Object.freeze({\n active: this.state === 'active',\n calls: Object.freeze(calls),\n commandRecords: this.frame.commandRecords.size,\n models: this.frame.models.size,\n });\n }\n\n getRenderableSnapshot = (): boolean => this.state !== 'closed' && (this.isActive === undefined || this.isActive());\n\n releaseClosedFrame(): void {\n if (this.state === 'closed') this.releaseFrame();\n }\n\n subscribeRenderable = (listener: () => void): (() => void) => {\n if (this.state === 'closed') return (): void => undefined;\n\n const registration = { listener };\n this.renderListeners.add(registration);\n let subscribed = true;\n\n return (): void => {\n if (!subscribed) return;\n\n subscribed = false;\n this.renderListeners.delete(registration);\n };\n };\n\n private buildCommandRecords(mountId: number): void {\n let commandIndex = 0;\n\n // `buildFrame` already reduced the models to their distinct Commands, so every command here gets its own record.\n for (const command of this.boundCommands) {\n // Authenticity check only: the binding carries no mode since observe was removed (D71).\n getCommandBindingDefinition(command);\n const controller = createCallController(command, {\n captureAuthority: this.captureAuthority,\n id: `contributionCommand.${String(mountId)}.${String(++commandIndex)}`,\n scheduling: { policy: 'parallel' },\n });\n this.frame.commandRecords.set(command, { controller, invoker: Object.freeze({ run: controller.run }) });\n }\n }\n\n private captureAuthority = (): CallAuthority => {\n const authority = this.authority;\n\n if (this.state !== 'active' || authority === undefined) {\n throw new ContributionError('inactive', 'Contribution mount is not active.');\n }\n\n authority.assertCurrent();\n\n return authority;\n };\n\n private createAuthority(lease: LifetimeLease): CallAuthority {\n return Object.freeze({\n assertCurrent: (): void => {\n if (this.state !== 'active') throw new ContributionError('inactive', 'Contribution mount is not active.');\n\n lease.assertCurrent();\n },\n isCurrent: (): boolean => this.state === 'active' && lease.isCurrent(),\n });\n }\n\n private publishRenderable(): void {\n for (const { listener } of [...this.renderListeners]) {\n try {\n listener();\n } catch (error) {\n reportDetachedError(error);\n }\n }\n }\n\n private releaseFrame(): void {\n if (this.released) return;\n\n this.released = true;\n this.frame.commandRecords.clear();\n this.frame.models.clear();\n this.boundCommands = [];\n this.renderListeners.clear();\n }\n}\n\nexport { MountFrameImpl };\nexport type { Frame };\n","import { useInsertionEffect, useLayoutEffect, useSyncExternalStore } from 'react';\nimport type { PropsWithChildren, ReactElement } from 'react';\n\nimport { FrameContext } from './mount-context';\nimport type { MountFrameImpl } from './mount-frame';\n\nfunction MountProvider({\n children,\n mount,\n}: PropsWithChildren<{ readonly mount: MountFrameImpl }>): ReactElement | null {\n const renderable = useSyncExternalStore(\n mount.subscribeRenderable,\n mount.getRenderableSnapshot,\n mount.getRenderableSnapshot,\n );\n\n useInsertionEffect(() => {\n const attached = mount.attach();\n\n if (!attached) return undefined;\n\n return () => mount.detach();\n }, [mount]);\n\n useLayoutEffect(() => {\n if (!renderable) mount.releaseClosedFrame();\n }, [mount, renderable]);\n\n return renderable ? <FrameContext value={mount.frame}>{children}</FrameContext> : null;\n}\n\nexport { MountProvider };\n","import { memo, useCallback, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport type { ComponentType, ReactElement } from 'react';\n\nimport type { DeclarationId, State } from '@opetope/core';\nimport {\n createAggregateError,\n createState,\n getContributionOwner,\n isReadable,\n reportDetachedError,\n} from '@opetope/core/internal';\nimport type { ModelIdentity } from '@opetope/core/internal';\nimport { openContributionModels, reportRuntimeFailure, requireContributionModelPlans } from '@opetope/runtime/internal';\nimport type { ContributionModelBundle, RuntimeErrorReporter } from '@opetope/runtime/internal';\n\nimport { bindCommand, isCommandBinding } from './command';\nimport { ContributionIsolation, useContributionErrorContent } from './contribution-isolation';\nimport { bindModel } from './model-binding';\nimport { isResource } from './resource-command';\nimport type { ModelBindingIdentity } from './model-binding';\nimport { MountFrameImpl } from './mount-frame';\nimport { MountProvider } from './mount-provider';\nimport { useReadable } from './readable-hooks';\n\ntype AnyModel = ModelIdentity;\ntype ContributionAuthority = {\n /** The feature whose generation published this contribution (D257). */\n readonly feature?: DeclarationId;\n readonly models: readonly (readonly [AnyModel, unknown])[];\n /** The reporter of the feature that published this contribution: a contained failure is its diagnostic, not ours. */\n readonly reporter?: RuntimeErrorReporter;\n};\ntype ModelFixture = readonly [declaration: AnyModel, model: unknown];\n\ntype ContributionValue = {\n readonly Component: ComponentType<never>;\n readonly models?: readonly object[] | undefined;\n readonly props?: ((slotProps: never) => object) | undefined;\n};\n\ntype ContributionMountProps = {\n readonly authority?: ContributionAuthority | undefined;\n readonly contribution: ContributionValue;\n /** The published entry this mount renders, and the slot it renders in: the identity of a contained failure (D257). */\n readonly contributionId: DeclarationId;\n readonly fixtures?: readonly ModelFixture[];\n readonly slotProps: object;\n readonly targetId: DeclarationId;\n};\n\ntype MountBundle = {\n readonly frame: MountFrameImpl;\n readonly isOpen: () => boolean;\n readonly props: State<object>;\n};\n\ntype MountOwner = {\n readonly authority: ContributionAuthority | undefined;\n bundle: MountBundle | undefined;\n readonly contribution: ContributionValue;\n readonly fixtures: readonly ModelFixture[] | undefined;\n retired: boolean;\n};\n\ntype CommittedMount = {\n readonly bundle: MountBundle;\n readonly owner: MountOwner;\n};\n\nfunction closeOwnedMount(owner: MountOwner): void {\n const bundle = owner.bundle;\n owner.bundle = undefined;\n bundle?.frame.close();\n}\n\n/**\n * Model fields arrive as authentic kernel calls; binding them registers the command records the frame needs. D349: a\n * Resource is none of those and needs none of it — it is a field the selection reads on its own terms, so it travels\n * to the frame unchanged instead of being offered to `bindCommand`, which would refuse it as inauthentic.\n */\nfunction bindFrameModel(declaration: AnyModel, model: unknown): ModelBindingIdentity {\n if (typeof model !== 'object' || model === null) return bindModel(declaration as never, model as never);\n\n const passesThrough = (value: unknown): boolean =>\n isReadable(value) || isResource(value) || typeof value === 'function' || isCommandBinding(value);\n const fields = Object.entries(model).map(([key, value]): readonly [string, unknown] => [\n key,\n passesThrough(value) ? value : bindCommand(value as never),\n ]);\n\n return bindModel(declaration as never, Object.fromEntries(fields) as never);\n}\n\n/**\n * D70: the authority of a contribution belongs to the entry a feature published, not to the value it wrote. One\n * static contribution object may be published by two features, and each mount must read the models of its own.\n */\nfunction contributionAuthority(entry: unknown): ContributionAuthority | undefined {\n return getContributionOwner(entry) as ContributionAuthority | undefined;\n}\n\n/** A mount with no publishing generation behind it: a fixture of a component test grants nothing and reports nowhere. */\nconst unownedContribution: ContributionAuthority = { models: [] };\n\nfunction cleanupFailedMount(close: () => void, cause: unknown): never {\n try {\n close();\n } catch (error) {\n throw createAggregateError([cause, error], 'Contribution mount setup and cleanup failed.', { cause });\n }\n\n throw cause;\n}\n\nfunction contributionModels(\n contribution: ContributionValue,\n slotProps: object,\n fixtures: readonly ModelFixture[],\n owner: ContributionAuthority | undefined,\n): {\n readonly bundle: ContributionModelBundle | undefined;\n readonly models: readonly ModelFixture[];\n readonly props: State<object>;\n} {\n const props = createState(slotProps);\n const { models: granted, reporter } = owner ?? unownedContribution;\n\n try {\n const plans = requireContributionModelPlans(contribution.models);\n const bundle = plans.length === 0 ? undefined : openContributionModels(plans, props, reporter);\n\n return {\n bundle,\n models: [...granted, ...(bundle?.models ?? []), ...fixtures],\n props,\n };\n } catch (error) {\n return cleanupFailedMount(props.close, error);\n }\n}\n\nfunction createMountBundle(\n contribution: ContributionValue,\n slotProps: object,\n fixtures: readonly ModelFixture[],\n authority: ContributionAuthority | undefined,\n): MountBundle {\n const { bundle, models, props } = contributionModels(contribution, slotProps, fixtures, authority);\n let closed = false;\n const close = (): void => {\n if (closed) return;\n\n closed = true;\n\n try {\n void bundle?.close().catch(reportDetachedError);\n } finally {\n props.close();\n }\n };\n try {\n const frame = new MountFrameImpl(\n models.map(([declaration, model]) => bindFrameModel(declaration, model)),\n { isActive: () => !closed, onClose: close },\n );\n\n return { frame, isOpen: () => !closed, props };\n } catch (error) {\n return cleanupFailedMount(close, error);\n }\n}\n\nfunction createComponentElement(Component: ComponentType<never>, props: object): ReactElement {\n const Rendered = Component as ComponentType<object>;\n\n return <Rendered {...props} />;\n}\n\ntype MountedContributionProps = {\n readonly bundle: MountBundle;\n readonly contribution: ContributionValue;\n};\n\n/** Reads the committed props of one live mount: every hook here sees a bundle that already exists. */\nfunction MountedContribution({ bundle, contribution }: MountedContributionProps): ReactElement {\n const committedProps = useReadable(bundle.props);\n const componentProps = useMemo(\n () => (contribution.props === undefined ? committedProps : contribution.props(committedProps as never)),\n [committedProps, contribution],\n );\n\n return (\n <MountProvider mount={bundle.frame}>{createComponentElement(contribution.Component, componentProps)}</MountProvider>\n );\n}\n\n/**\n * D188: a mount is created in commit, never in render. The first pass renders nothing, the layout effect builds the\n * bundle from the props that committed and publishes it, and React flushes that update before paint. A render that\n * is thrown away — StrictMode's double invoke, an abandoned concurrent pass, a suspended sibling — therefore\n * creates no models at all, so there is nothing to sweep, adopt or replace.\n */\nfunction ContributionMount({\n authority,\n contribution,\n fixtures,\n slotProps,\n}: ContributionMountProps): ReactElement | null {\n const owner = useMemo<MountOwner>(\n () => ({ authority, bundle: undefined, contribution, fixtures, retired: false }),\n [authority, contribution, fixtures],\n );\n const [committed, setCommitted] = useState<CommittedMount | undefined>(undefined);\n const bundle = committed?.owner === owner ? committed.bundle : undefined;\n const committedSlotProps = useRef(slotProps);\n\n useLayoutEffect(() => {\n committedSlotProps.current = slotProps;\n });\n\n // Suspense disconnects layout effects while hiding, but insertion cleanup only retires an actual identity.\n // Do not close Readables in insertion: their listeners may update React. A hidden tree has no layout cleanup\n // left to run on unmount, so the microtask also releases a mount that never becomes visible again.\n useInsertionEffect(\n () => () => {\n owner.retired = true;\n queueMicrotask(() => {\n try {\n closeOwnedMount(owner);\n } catch (error) {\n reportDetachedError(error);\n }\n });\n },\n [owner],\n );\n\n // The identity of the contribution owns the mount; a reveal and StrictMode reuse what its first commit created.\n useLayoutEffect(() => {\n const created = (owner.bundle ??= createMountBundle(\n owner.contribution,\n committedSlotProps.current,\n owner.fixtures ?? [],\n owner.authority,\n ));\n setCommitted(current => (current?.owner === owner ? current : { bundle: created, owner }));\n\n return () => {\n if (owner.retired) closeOwnedMount(owner);\n };\n }, [owner]);\n\n // Both the component and its models read the same committed snapshot, published before paint.\n useLayoutEffect(() => {\n if (bundle?.isOpen() === true) bundle.props.set(slotProps);\n }, [bundle, slotProps]);\n\n if (bundle === undefined) return null;\n\n return <MountedContribution bundle={bundle} contribution={contribution} />;\n}\n\n/**\n * D256: every mount is a boundary. The isolation sits above `ContributionMount`, so it contains the render of the\n * component and the commit that builds the mount alike, and a retry rebuilds the mount instead of reusing the bundle\n * that failed. Containment is unconditional; the content a failure shows is the host policy of `ContributionBoundary`.\n */\nfunction IsolatedContributionMount(props: ContributionMountProps): ReactElement {\n const { authority, contribution, contributionId, fixtures, targetId } = props;\n const content = useContributionErrorContent();\n const identity = useMemo(() => ({ authority, contribution, fixtures }), [authority, contribution, fixtures]);\n const feature = authority?.feature;\n const source = useMemo(\n () => ({ contribution: contributionId, feature, target: targetId }),\n [contributionId, feature, targetId],\n );\n const reporter = authority?.reporter;\n const report = useCallback((error: unknown) => reportRuntimeFailure(error, reporter), [reporter]);\n\n return (\n <ContributionIsolation content={content} identity={identity} report={report} source={source}>\n <ContributionMount {...props} />\n </ContributionIsolation>\n );\n}\n\n/**\n * One mount, one memo: `Slot` recreates its children whenever `entries` changes, so publishing or withholding one\n * contribution used to re-render every other mount of that target. The props are the contribution, the slot props\n * and the fixtures, all of which are stable while nothing about that mount changed.\n */\nconst MemoizedContributionMount = memo(IsolatedContributionMount);\n\nexport { contributionAuthority, MemoizedContributionMount as ContributionMount };\nexport type { ContributionValue, ModelFixture };\n"],"names":["FrameContext","createContext","useFrame","frame","useContext","ContributionError","isResource","value","isResourceValue","awaitCancellable","operation","signal","resolve","reject","cancel","CommandError","compatibleAbortReason","error","notifySuccess","options","notification","_a","reportDetachedError","operationInvoker","start","_input","unavailablePage","paginationOf","resource","capability","createResourceInvokers","resourceInvokers","cache","existing","invokers","identity","useSelector","readable","select","selector","isEqual","subscribe","useCallback","listener","instanceRef","useRef","instance","getSelectedSnapshot","useMemo","initialized","sourceSnapshot","selectedSnapshot","nextSource","nextSelected","nextSelectedSnapshot","selected","useSyncExternalStore","useEffect","useReadable","bindingDefinitions","bindCommand","target","isCallTarget","getCommandBindingDefinition","binding","definition","isCommandBinding","modelBindingBrand","modelBindingIdentityBrand","modelBindingMarker","registry","modelFieldValue","declaration","model","field","descriptor","snapshotModelFields","commands","fields","isReadable","bindModel","isModel","getModelBindingMetadata","metadata","nextMountId","buildFrame","supplied","models","bound","candidate","command","MountFrameImpl","lifecycle","mountId","createLifetimeController","authority","record","onClose","ticket","calls","registration","subscribed","commandIndex","controller","createCallController","lease","MountProvider","children","mount","renderable","useInsertionEffect","useLayoutEffect","_jsx","closeOwnedMount","owner","bundle","bindFrameModel","passesThrough","key","contributionAuthority","entry","getContributionOwner","unownedContribution","cleanupFailedMount","close","cause","createAggregateError","contributionModels","contribution","slotProps","fixtures","props","createState","granted","reporter","plans","requireContributionModelPlans","openContributionModels","createMountBundle","closed","createComponentElement","Component","MountedContribution","committedProps","componentProps","ContributionMount","committed","setCommitted","useState","committedSlotProps","created","current","IsolatedContributionMount","contributionId","targetId","content","useContributionErrorContent","feature","source","report","reportRuntimeFailure","ContributionIsolation","MemoizedContributionMount","memo"],"mappings":"wwBAKA,MAAMA,EAAeC,EAAiC,MAAS,EAE/D,SAASC,IAAQ,CACf,MAAMC,EAAQC,EAAWJ,CAAY,EAErC,GAAIG,IAAU,OACZ,MAAM,IAAIE,EAAkB,UAAW,uDAAuD,EAGhG,OAAOF,CACT,CCuBA,SAASG,EAAWC,EAAc,CAChC,OAAOC,EAAgBD,CAAK,CAC9B,CAqCA,SAASE,GAAiBC,EAA6BC,EAAmB,CACxE,OAAO,IAAI,QAAiB,CAACC,EAASC,IAAU,CAC9C,MAA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