@opetope/react 0.2.0 → 0.5.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 +60 -0
- package/README.md +65 -7
- package/README.ru.md +65 -7
- package/dist/contribution-frame-B1PnpOaP.js +2 -0
- package/dist/contribution-frame-B1PnpOaP.js.map +1 -0
- package/dist/contribution-frame.d.ts +14 -6
- package/dist/contribution-isolation-Bzfbt4iM.js +2 -0
- package/dist/contribution-isolation-Bzfbt4iM.js.map +1 -0
- package/dist/contribution-isolation.d.ts +64 -0
- package/dist/errors.d.ts +20 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +2 -0
- package/dist/integration.js +1 -1
- package/dist/integration.js.map +1 -1
- package/dist/scenario-slot.d.ts +5 -0
- package/dist/testing-call.d.ts +8 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +2 -2
- package/dist/testing.js.map +1 -1
- package/package.json +5 -5
- package/dist/contribution-frame-1td5XTES.js +0 -2
- package/dist/contribution-frame-1td5XTES.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as S,useInsertionEffect as h,useLayoutEffect as f,useMemo as g,useSyncExternalStore as b,useRef as m,useCallback as w,useEffect as
|
|
1
|
+
import{useState as S,useInsertionEffect as h,useLayoutEffect as f,useMemo as g,useSyncExternalStore as b,useRef as m,useCallback as w,useEffect as P,createElement as E,Fragment as K}from"react";import{CallError as x,declarationId as $}from"@opetope/core";import{compatibleAbortReason as H,isCancellation as T,reportDetachedError as v,isCallTarget as G,isReadable as U,createAggregateError as D,createContributionTarget as L}from"@opetope/core/internal";import{C as d}from"./contribution-isolation-Bzfbt4iM.js";import{u as p,a as O,M as W,c as B}from"./contribution-frame-B1PnpOaP.js";import{b as ze}from"./contribution-frame-B1PnpOaP.js";function C(n,e){var t;if(T(e))return{reason:e,status:"cancelled"};try{const s=(t=n==null?void 0:n.onFailure)==null?void 0:t.call(n,e);s!==void 0&&Promise.resolve(s).catch(v)}catch(s){v(s)}return{error:e,status:"failed"}}function J(n){const e=n==null?void 0:n.onSuccess,t=n==null?void 0:n.signal;return e===void 0?t===void 0?void 0:{signal:t}:t===void 0?{onSuccess:e}:{onSuccess:e,signal:t}}function N(n,e){let t;const s=new Promise(r=>{t=r});return{input:n,options:e===void 0?void 0:{...e},promise:s,resolve:t}}function Q(n,e){const t=n.resolve;n.input=void 0,n.options=void 0,n.resolve=void 0,t==null||t(e)}class j{invoker;run=((e,t)=>{if(this.notify===void 0)return Promise.resolve({reason:new d("inactive","Command consumer is not mounted."),status:"cancelled"});const s=this.cancelledInput(t);if(s!==void 0)return Promise.resolve(s);const r=N(e,t);return this.start(r),r.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 x("cancelled","Command input was cancelled.",H(e)),status:"cancelled"}}cancelledInput(e){var t;return((t=e==null?void 0:e.signal)==null?void 0:t.aborted)===!0?this.aborted(e.signal):void 0}finish(e,t){var s;e.resolve!==void 0&&(this.inFlight-=1,Q(e,t),(s=this.notify)==null||s.call(this,this.inFlight>0,t))}invoke(e){let t;try{t=this.invoker.run(e.input,J(e.options)),e.input=void 0}catch(s){this.finish(e,C(e.options,s));return}t.then(s=>this.finish(e,{status:"ok",value:s}),s=>this.finish(e,C(e.options,s)))}start(e){var t;this.inFlight+=1,(t=this.notify)==null||t.call(this,!0),this.invoke(e)}}const V={inFlight:!1,lastError:null,result:void 0};function X(n,e,t,s){return s===void 0&&n.slot===e&&n.inFlight===t}function Y(n,e,t,s){if(X(n,e,t,s))return n;const{lastError:r,result:i}=n.slot===e?n:{lastError:null,result:void 0};return(s==null?void 0:s.status)==="ok"?{inFlight:t,lastError:null,result:s.value,slot:e}:(s==null?void 0:s.status)==="failed"?{inFlight:t,lastError:s.error,result:i,slot:e}:{inFlight:t,lastError:r,result:i,slot:e}}function Z(n){const[e]=S(()=>new WeakMap);let t=e.get(n);return t===void 0&&(t=new j(n),e.set(n,t)),t}function _(n){const t=p().commandRecords.get(n);if(t===void 0)throw new d("missing",`Command ${n.id} is not bound in this contribution.`);const s=Z(t.invoker),[r,i]=S(()=>({inFlight:!1,lastError:null,result:void 0,slot:s}));h(()=>s.attach((u,A)=>i(I=>Y(I,s,u,A))),[s]),f(()=>s.synchronize(),[s]);const{inFlight:o,lastError:l,result:c}=r.slot===s?r:V,a=s.run;return g(()=>({inFlight:o,lastError:l,result:c,run:a}),[o,l,c,a])}const q=()=>{},M=()=>q,ee=()=>0,te=Object.freeze({});function ne(n){const e=new j(n);return{detach:void 0,hook:{inFlight:!1,lastError:null,result:void 0,run:e.run},invoker:n,slot:e}}function se(n,e){return n.inFlight===e.inFlight&&Object.is(n.result,e.result)&&Object.is(n.lastError,e.lastError)}function re(n,e){return(e==null?void 0:e.status)==="ok"?{lastError:null,result:e.value}:(e==null?void 0:e.status)==="failed"?{lastError:e.error,result:n.result}:n}function ie(n,e,t){const s=n.hook;if(t===void 0&&s.inFlight===e)return!1;const{lastError:r,result:i}=re(s,t),o={inFlight:e,lastError:r,result:i,run:s.run};return se(s,o)?!1:(n.hook=o,!0)}function oe(n,e){return(n==null?void 0:n.invoker)===e?n:ne(e)}class ce{entries=new Map;listeners=new Set;revision=0;close(){var e;for(const t of this.entries.values())(e=t.detach)==null||e.call(t),t.detach=void 0;this.entries.clear()}commit(e){var t;for(const[s,r]of this.entries)e.get(s)!==r&&((t=r.detach)==null||t.call(r),r.detach=void 0);this.entries=e;for(const s of e.values())s.detach??(s.detach=s.slot.attach((r,i)=>{if(ie(s,r,i)){this.revision+=1;for(const o of this.listeners)o()}}))}getSnapshot=()=>this.revision;prepare(e,t){const s=new Map;for(const r of Reflect.ownKeys(e)){if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;const i=e[r],o=i===void 0?void 0:t.commandRecords.get(i);if(o===void 0)throw new d("missing",`Command at ${String(r)} is not bound in this contribution.`);s.set(r,oe(this.entries.get(r),o.invoker))}return s}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)})}function le(n){const e=m(void 0);return Reflect.ownKeys(n).some(s=>Object.prototype.propertyIsEnumerable.call(n,s))?e.current??(e.current=new ce):void 0}function k(n){const e=p(),t=le(n),s=(t==null?void 0:t.getSnapshot)??ee;b((t==null?void 0:t.subscribe)??M,s,s);const r=t==null?void 0:t.prepare(n,e);return h(()=>()=>t==null?void 0:t.close(),[t]),h(()=>{r!==void 0&&(t==null||t.commit(r))}),f(()=>{if(r!==void 0)for(const i of r.values())i.slot.synchronize()}),r===void 0?te:Object.fromEntries([...r].map(([i,o])=>[i,o.hook]))}function ae(n,e){if(!U(n))throw new d("binding-invalid","Model selection read requires a Readable.");if(e.has(n))return e.get(n);const t=n.getSnapshot();return e.set(n,t),t}function ue(n,e){const s=n({read:(r,i)=>{const o=ae(r,e);return i===void 0?o:i(o)}});if(typeof s!="object"||s===null||Array.isArray(s))throw new d("binding-invalid","Model selection requires a record.");return Object.fromEntries(Reflect.ownKeys(s).filter(r=>Object.prototype.propertyIsEnumerable.call(s,r)).map(r=>[r,s[r]]))}function de(n,e,t){const s=Reflect.ownKeys(e),r=Reflect.ownKeys(n.values);if(s.length!==r.length||t.size!==n.sources.size)return!1;for(const i of t)if(!n.sources.has(i))return!1;return s.every((i,o)=>r[o]===i&&Object.is(n.values[i],e[i]))}const y={commands:{},sources:new Set,values:{}};function fe(n){return Object.fromEntries(Reflect.ownKeys(n).filter(e=>G(n[e])).map(e=>[e,n[e]]))}function he(n,e){let t,s,r=y;return()=>{const i=e.current;if(i===void 0)return y;if(t!==void 0&&s===i&&[...t].every(([a,u])=>Object.is(a.getSnapshot(),u)))return r;const o=new Map,l=ue(a=>i(n,a),o),c=new Set(o.keys());return(t===void 0||!de(r,l,c))&&(r={commands:fe(l),sources:c,values:l}),t=o,s=i,r}}function R(n,e=[]){for(const t of n){const s=t.dispose;t.dispose=void 0;try{s==null||s()}catch(r){e.push(r)}}if(e.length===1)throw e[0];if(e.length>1)throw D(e,"Model selection sources failed to release.")}class be{enabled=!1;listeners=new Set;sources=new Set;subscriptions=new Map;close(){this.enabled=!1,this.sources=new Set,this.releaseAll()}commit(e){this.sources=e,this.enabled=!0;try{this.synchronize()}catch(t){this.releaseAll([t])}}subscribe=e=>{const t={notify:e};this.listeners.add(t);try{this.synchronize()}catch(s){this.listeners.delete(t),this.releaseAll([s])}return()=>{this.listeners.delete(t),this.listeners.size===0&&this.releaseAll()}};add(e){const t={dispose:void 0};this.subscriptions.set(e,t);const s=e.subscribe(this.notify);if(typeof s!="function")throw new TypeError("Model selection source must return a disposer.");this.subscriptions.get(e)===t?t.dispose=s:s()}notify=()=>{for(const e of[...this.listeners])this.listeners.has(e)&&e.notify()};releaseAll(e){const t=[...this.subscriptions.values()];this.subscriptions.clear(),R(t,e)}removeUnselected(){const e=[];for(const[t,s]of this.subscriptions)this.sources.has(t)||(this.subscriptions.delete(t),e.push(s));R(e)}synchronize(){this.removeUnselected();for(const e of this.sources){if(!this.enabled||this.listeners.size===0)return;this.sources.has(e)&&!this.subscriptions.has(e)&&this.add(e)}}}const me=()=>y;function pe(n){const e=m(void 0);return n?e.current??(e.current=new be):void 0}function ye(n,e){const t=p();if(!t.models.has(n))throw new d("missing",`Model ${n.id} is not granted to this contribution.`);const s=t.models.get(n),r=pe(e!==void 0),i=m(void 0);i.current=e;const o=e!==void 0,l=g(()=>o?he(s,i):me,[s,o]),c=b((r==null?void 0:r.subscribe)??M,l,l),a=k(c.commands);return f(()=>()=>r==null?void 0:r.close(),[r]),f(()=>r==null?void 0:r.commit(c.sources),[c,r]),e===void 0?s:Object.fromEntries(Reflect.ownKeys(c.values).map(u=>[u,Object.prototype.hasOwnProperty.call(a,u)?a[u]:c.values[u]]))}function Se(n){const e=Object.freeze([...n]);return t=>{if(t.requires!==void 0)throw new d("duplicate","Component already declares the models it requires.");return Object.defineProperty(t,"requires",{enumerable:!1,value:e}),t}}function ge(n){const e=w(r=>n.subscribe(r),[n]),t=w(()=>n.getSnapshot(),[n]),s=b(e,t,t);return P(()=>n.retain(),[n]),s}const z=Object.freeze({});function F(n){return L(n)}function we(n){const e=$(n.id),t=new Map,s=r=>{const i=t.get(r);if(i!==void 0)return i;const o=F({id:`${e}/${r}`});return t.set(r,o),o};return Object.defineProperty(s,"id",{enumerable:!0,value:e}),Object.freeze(s)}function Ee(n){const e=O(n.target.entries),t="props"in n?n.props??z:z;return e.length===0?null:e.map(s=>E(K,{key:s.id},E(W,{authority:B(s),contribution:s.value,contributionId:s.id,slotProps:t,targetId:n.target.id})))}export{d as ContributionError,Ee as Slot,F as defineSlot,we as defineSwitchSlot,Se as requiresModels,_ as useCommand,k as useCommands,ye as useModel,O as useReadable,ge as useResource,ze 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/commands-hook.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 { CallError } from '@opetope/core';\nimport { compatibleAbortReason, isCancellation, reportDetachedError } from '@opetope/core/internal';\nimport type { 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> = [Input] extends [void]\n ? (input?: Input, options?: CommandRunOptions<Output>) => Promise<CommandOutcome<Output>>\n : (input: Input, options?: CommandRunOptions<Output>) => Promise<CommandOutcome<Output>>;\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, status: '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, status: '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 call, and the policy the call was\n * created with — `queue`, `latest`, `parallel`, `once`, `singleFlight` — 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 status: '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 CallError('cancelled', 'Command input was cancelled.', compatibleAbortReason(signal)),\n status: '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, { status: '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 { Call } 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\ninterface CommandHookStatus<Output> {\n readonly inFlight: boolean;\n readonly lastError: unknown | null;\n readonly result: Output | undefined;\n}\n\nconst emptyStatus: CommandHookStatus<never> = { inFlight: false, lastError: null, result: undefined };\n\ntype CommandHook<Input, Output> = CommandHookStatus<Output> & { readonly run: CommandRun<Input, Output> };\n\ntype CommandHookState<Input, Output> = CommandHookStatus<Output> & {\n readonly slot: CommandHookController<Input, Output>;\n};\n\nfunction unchangedState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n outcome: CommandOutcome<Output> | undefined,\n): boolean {\n return outcome === 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 if (unchangedState(current, slot, inFlight, outcome)) return current;\n\n const { lastError, result } = current.slot === slot ? current : { lastError: null, result: undefined };\n\n if (outcome?.status === 'ok') return { inFlight, lastError: null, result: outcome.value, slot };\n\n if (outcome?.status === 'failed') return { inFlight, lastError: outcome.error, result, slot };\n\n return { inFlight, lastError, result, 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\nfunction useCommand<Input, Output>(command: Call<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 const currentSlot = useCommandSlot<Input, Output>(record.invoker);\n const [hookState, setHookState] = useState<CommandHookState<Input, Output>>(() => ({\n inFlight: false,\n lastError: null,\n result: 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, lastError, result } = hookState.slot === currentSlot ? hookState : emptyStatus;\n const run = currentSlot.run;\n\n return useMemo(() => ({ inFlight, lastError, result, run }), [inFlight, lastError, result, run]);\n}\n\nexport { useCommand };\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 { Call } 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 { useFrame } from './mount-context';\nimport type { Frame } from './mount-frame';\n\ntype CommandSelection = Readonly<Record<string, Call<never, unknown>>>;\ntype HookOf<Command> = Command extends Call<infer Input, infer Output> ? CommandHook<Input, Output> : never;\ntype CommandsHook<Commands> = {\n readonly [Key in keyof Commands]: HookOf<Commands[Key]>;\n};\nconst emptyHooks = 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\nfunction createEntry(invoker: CommandInvoker): CommandEntry {\n const slot = new CommandHookController<never, unknown>(invoker);\n\n return {\n detach: undefined,\n hook: { inFlight: false, lastError: null, result: undefined, run: slot.run },\n invoker,\n slot,\n };\n}\n\nfunction unchangedHook(previous: CommandHook<never, unknown>, next: CommandHook<never, unknown>): boolean {\n return (\n previous.inFlight === next.inFlight &&\n Object.is(previous.result, next.result) &&\n Object.is(previous.lastError, next.lastError)\n );\n}\n\nfunction outcomeStatus(previous: CommandHook<never, unknown>, outcome: CommandOutcome<unknown> | undefined) {\n if (outcome?.status === 'ok') return { lastError: null, result: outcome.value };\n\n if (outcome?.status === 'failed') return { lastError: outcome.error, result: previous.result };\n\n return previous;\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 const { lastError, result } = outcomeStatus(previous, outcome);\n const next = { inFlight, lastError, result, 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: CommandEntry | undefined, invoker: CommandInvoker): CommandEntry {\n return previous?.invoker === invoker ? previous : createEntry(invoker);\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, CommandEntry>();\n private readonly listeners = new Set<() => void>();\n private revision = 0;\n\n close(): void {\n for (const entry of this.entries.values()) {\n entry.detach?.();\n entry.detach = undefined;\n }\n\n this.entries.clear();\n }\n\n commit(selected: Map<PropertyKey, CommandEntry>): void {\n for (const [key, entry] of this.entries) {\n if (selected.get(key) === entry) continue;\n\n entry.detach?.();\n entry.detach = undefined;\n }\n\n this.entries = selected;\n\n for (const entry of selected.values()) {\n entry.detach ??= entry.slot.attach((inFlight, outcome) => {\n if (!updateEntry(entry, inFlight, outcome)) return;\n\n this.revision += 1;\n\n for (const listener of this.listeners) listener();\n });\n }\n }\n\n getSnapshot = (): number => this.revision;\n\n prepare(commands: CommandSelection, frame: Frame): Map<PropertyKey, CommandEntry> {\n const selected = new Map<PropertyKey, CommandEntry>();\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, Call<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 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): CommandGroup | undefined {\n const groupRef = useRef<CommandGroup | undefined>(undefined);\n const populated = Reflect.ownKeys(commands).some(key => Object.prototype.propertyIsEnumerable.call(commands, key));\n\n return populated ? (groupRef.current ??= new CommandGroup()) : undefined;\n}\n\nfunction useCommands<Commands extends { readonly [Key in keyof Commands]: Call<never, unknown> }>(\n commands: Commands,\n): CommandsHook<Commands> {\n const frame = useFrame();\n const group = useCommandGroup(commands);\n const getSnapshot = group?.getSnapshot ?? idleRevision;\n useSyncExternalStore(group?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const selected = group?.prepare(commands, 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 for (const entry of selected.values()) entry.slot.synchronize();\n });\n\n return (\n selected === undefined ? emptyHooks : Object.fromEntries([...selected].map(([key, entry]) => [key, entry.hook]))\n ) as CommandsHook<Commands>;\n}\n\nexport { useCommands };\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';\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>>;\ntype SelectionSnapshot = Readonly<{\n commands: Readonly<Record<PropertyKey, AnyCommand>>;\n sources: ReadonlySet<Readable<unknown>>;\n values: SelectionRecord;\n}>;\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 const value = source.getSnapshot();\n sources.set(source, value);\n\n return value;\n}\n\nfunction collectSelection(\n select: (context: SelectionContext) => object,\n sources: Map<Readable<unknown>, unknown>,\n): SelectionRecord {\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 return Object.fromEntries(\n Reflect.ownKeys(selected)\n .filter(key => Object.prototype.propertyIsEnumerable.call(selected, key))\n .map(key => [key, (selected as SelectionRecord)[key]]),\n );\n}\n\nfunction equalSelection(previous: SelectionSnapshot, values: SelectionRecord, sources: ReadonlySet<Readable<unknown>>) {\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 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 = { commands: {}, sources: new Set(), values: {} };\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 * 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 */\nfunction createSelectionSnapshot<Model>(model: Model, selectRef: SelectionReaderRef<Model>): () => SelectionSnapshot {\n let observed: Map<Readable<unknown>, unknown> | undefined;\n let observedSelect: ModelSelector<Model> | undefined;\n let snapshot: SelectionSnapshot = emptySelectionSnapshot;\n\n return () => {\n const select = selectRef.current;\n\n if (select === undefined) return emptySelectionSnapshot;\n\n if (\n observed !== undefined &&\n observedSelect === select &&\n [...observed].every(([source, value]) => Object.is(source.getSnapshot(), value))\n ) {\n return snapshot;\n }\n\n const nextObserved = new Map<Readable<unknown>, unknown>();\n const values = collectSelection(context => select(model, context), nextObserved);\n const sources = new Set(nextObserved.keys());\n\n if (observed === undefined || !equalSelection(snapshot, values, sources)) {\n snapshot = { commands: selectionCommands(values), sources, values };\n }\n\n observed = nextObserved;\n observedSelect = select;\n\n return snapshot;\n };\n}\n\nexport { createSelectionSnapshot, emptySelectionSnapshot };\nexport type { ModelSelector, SelectionContext, SelectionShape };\n","import type { Readable } from '@opetope/core';\nimport { createAggregateError } from '@opetope/core/internal';\n\ntype Subscription = { dispose: (() => void) | undefined };\ntype Listener = Readonly<{ notify: () => void }>;\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 private readonly listeners = new Set<Listener>();\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.releaseAll();\n }\n\n commit(sources: ReadonlySet<Readable<unknown>>): void {\n this.sources = sources;\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 subscriptions = [...this.subscriptions.values()];\n this.subscriptions.clear();\n releaseSubscriptions(subscriptions, 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 releaseSubscriptions(removed);\n }\n\n private synchronize(): void {\n this.removeUnselected();\n\n for (const source of this.sources) {\n if (!this.enabled || this.listeners.size === 0) return;\n\n if (this.sources.has(source) && !this.subscriptions.has(source)) this.add(source);\n }\n }\n}\n\nexport { ModelSelectionStore };\n","import { useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Call, ModelOf } from '@opetope/core';\n\nimport type { CommandHook } from './command-hook';\nimport { useCommands } from './commands-hook';\nimport { ContributionError } from './errors';\nimport { subscribeIdle } from './idle-subscription';\nimport type { AnyModel } from './model-binding';\nimport { createSelectionSnapshot, emptySelectionSnapshot } from './model-selection-snapshot';\nimport type { ModelSelector, SelectionContext, SelectionShape } from './model-selection-snapshot';\nimport { ModelSelectionStore } from './model-selection-store';\nimport { useFrame } from './mount-context';\n\ntype SelectedValue<Value> = Value extends Call<infer Input, infer Output> ? CommandHook<Input, Output> : 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/** 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 const getSnapshot = useMemo(\n () => (selected ? createSelectionSnapshot(model, selectRef) : readEmptySnapshot),\n [model, selected],\n );\n const snapshot = useSyncExternalStore(store?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const commands = useCommands(snapshot.commands);\n useLayoutEffect(() => () => store?.close(), [store]);\n useLayoutEffect(() => store?.commit(snapshot.sources), [snapshot, store]);\n\n if (select === undefined) return model;\n\n return Object.fromEntries(\n Reflect.ownKeys(snapshot.values).map(key => [\n key,\n Object.prototype.hasOwnProperty.call(commands, key) ? commands[key] : snapshot.values[key],\n ]),\n );\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, useSyncExternalStore } from 'react';\n\nimport type { Resource, ResourceSnapshot } from '@opetope/runtime';\nimport type { ResourceRequestKey } from '@opetope/runtime/internal';\n\nfunction useResource<Data, Key extends ResourceRequestKey>(resource: Resource<Data, Key>): ResourceSnapshot<Data, Key> {\n const subscribe = useCallback((listener: () => void) => resource.subscribe(listener), [resource]);\n // D199: a resource is a structural contract, so it may be an object with methods. Reading through it keeps the\n // receiver the adapter expects; handing `resource.getSnapshot` to React would call it with none.\n const getSnapshot = useCallback(() => resource.getSnapshot(), [resource]);\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n useEffect(() => resource.retain(), [resource]);\n\n return snapshot;\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\nfunction defineSlot<Props extends SlotProperties = undefined>(options: { readonly id: string }): SlotTarget<Props> {\n return createContributionTarget<SlotContribution<Props>>(options);\n}\n\nfunction defineSwitchSlot<Route extends string, Props extends SlotProperties = undefined>(options: {\n readonly id: string;\n}): SwitchSlotTarget<Route, Props> {\n const id = declarationId(options.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>({ id: `${id}/${route}` });\n targets.set(route, target);\n\n return target;\n };\n\n Object.defineProperty(switchSlot, 'id', { enumerable: true, value: id });\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 slotProps,\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","CallError","compatibleAbortReason","invocation","value","emptyStatus","unchangedState","current","slot","inFlight","nextState","lastError","result","useCommandSlot","slots","useState","useCommand","command","record","useFrame","currentSlot","hookState","setHookState","useInsertionEffect","useLayoutEffect","run","useMemo","idleRelease","subscribeIdle","idleRevision","emptyHooks","createEntry","unchangedHook","previous","next","outcomeStatus","updateEntry","entry","selectEntry","CommandGroup","selected","key","listener","commands","frame","useCommandGroup","groupRef","useRef","useCommands","group","getSnapshot","useSyncExternalStore","readSource","source","sources","isReadable","collectSelection","select","project","equalSelection","values","keys","previousKeys","index","emptySelectionSnapshot","selectionCommands","isCallTarget","createSelectionSnapshot","model","selectRef","observed","observedSelect","snapshot","nextObserved","context","releaseSubscriptions","subscriptions","failures","subscription","dispose","createAggregateError","ModelSelectionStore","removed","readEmptySnapshot","useSelectionStore","storeRef","useModel","declaration","store","requiresModels","models","declared","component","useResource","resource","subscribe","useCallback","useEffect","emptySlotProperties","defineSlot","createContributionTarget","defineSwitchSlot","id","declarationId","targets","switchSlot","route","existing","target","Slot","entries","useReadable","slotProps","createElement","Fragment","ContributionMount","contributionAuthority"],"mappings":"4kBA8BA,SAASA,EAAuBC,EAAgDC,EAAc,OAC5F,GAAIC,EAAeD,CAAK,EAAG,MAAO,CAAE,OAAQA,EAAO,OAAQ,WAAW,EAEtE,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,OAAQ,QAAQ,CAClC,CAEA,SAASM,EAAmBP,EAA8C,CACxE,MAAMQ,EAAYR,GAAA,YAAAA,EAAS,UACrBS,E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zE,GACjB4E,EACEC,EACA,CAAE,IAAK7E,EAAM,IACb4E,EAAcE,EAAmB,CAC/B,UAAWC,EAAsB/E,CAAK,EACtC,aAAcA,EAAM,MACpB,UAAA2E,EACD,CAAC,CACH,CAEL"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/command-hook-controller.ts","../src/command-hook.ts","../src/idle-subscription.ts","../src/commands-hook.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 { CallError } from '@opetope/core';\nimport { compatibleAbortReason, isCancellation, reportDetachedError } from '@opetope/core/internal';\nimport type { 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> = [Input] extends [void]\n ? (input?: Input, options?: CommandRunOptions<Output>) => Promise<CommandOutcome<Output>>\n : (input: Input, options?: CommandRunOptions<Output>) => Promise<CommandOutcome<Output>>;\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, status: '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, status: '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 call, and the policy the call was\n * created with — `queue`, `latest`, `parallel`, `once`, `singleFlight` — 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 status: '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 CallError('cancelled', 'Command input was cancelled.', compatibleAbortReason(signal)),\n status: '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, { status: '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 { Call } 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\ninterface CommandHookStatus<Output> {\n readonly inFlight: boolean;\n readonly lastError: unknown | null;\n readonly result: Output | undefined;\n}\n\nconst emptyStatus: CommandHookStatus<never> = { inFlight: false, lastError: null, result: undefined };\n\ntype CommandHook<Input, Output> = CommandHookStatus<Output> & { readonly run: CommandRun<Input, Output> };\n\ntype CommandHookState<Input, Output> = CommandHookStatus<Output> & {\n readonly slot: CommandHookController<Input, Output>;\n};\n\nfunction unchangedState<Input, Output>(\n current: CommandHookState<Input, Output>,\n slot: CommandHookController<Input, Output>,\n inFlight: boolean,\n outcome: CommandOutcome<Output> | undefined,\n): boolean {\n return outcome === 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 if (unchangedState(current, slot, inFlight, outcome)) return current;\n\n const { lastError, result } = current.slot === slot ? current : { lastError: null, result: undefined };\n\n if (outcome?.status === 'ok') return { inFlight, lastError: null, result: outcome.value, slot };\n\n if (outcome?.status === 'failed') return { inFlight, lastError: outcome.error, result, slot };\n\n return { inFlight, lastError, result, 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\nfunction useCommand<Input, Output>(command: Call<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 const currentSlot = useCommandSlot<Input, Output>(record.invoker);\n const [hookState, setHookState] = useState<CommandHookState<Input, Output>>(() => ({\n inFlight: false,\n lastError: null,\n result: 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, lastError, result } = hookState.slot === currentSlot ? hookState : emptyStatus;\n const run = currentSlot.run;\n\n return useMemo(() => ({ inFlight, lastError, result, run }), [inFlight, lastError, result, run]);\n}\n\nexport { useCommand };\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 { Call } 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 { useFrame } from './mount-context';\nimport type { Frame } from './mount-frame';\n\ntype CommandSelection = Readonly<Record<string, Call<never, unknown>>>;\ntype HookOf<Command> = Command extends Call<infer Input, infer Output> ? CommandHook<Input, Output> : never;\ntype CommandsHook<Commands> = {\n readonly [Key in keyof Commands]: HookOf<Commands[Key]>;\n};\nconst emptyHooks = 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\nfunction createEntry(invoker: CommandInvoker): CommandEntry {\n const slot = new CommandHookController<never, unknown>(invoker);\n\n return {\n detach: undefined,\n hook: { inFlight: false, lastError: null, result: undefined, run: slot.run },\n invoker,\n slot,\n };\n}\n\nfunction unchangedHook(previous: CommandHook<never, unknown>, next: CommandHook<never, unknown>): boolean {\n return (\n previous.inFlight === next.inFlight &&\n Object.is(previous.result, next.result) &&\n Object.is(previous.lastError, next.lastError)\n );\n}\n\nfunction outcomeStatus(previous: CommandHook<never, unknown>, outcome: CommandOutcome<unknown> | undefined) {\n if (outcome?.status === 'ok') return { lastError: null, result: outcome.value };\n\n if (outcome?.status === 'failed') return { lastError: outcome.error, result: previous.result };\n\n return previous;\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 const { lastError, result } = outcomeStatus(previous, outcome);\n const next = { inFlight, lastError, result, 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: CommandEntry | undefined, invoker: CommandInvoker): CommandEntry {\n return previous?.invoker === invoker ? previous : createEntry(invoker);\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, CommandEntry>();\n private readonly listeners = new Set<() => void>();\n private revision = 0;\n\n close(): void {\n for (const entry of this.entries.values()) {\n entry.detach?.();\n entry.detach = undefined;\n }\n\n this.entries.clear();\n }\n\n commit(selected: Map<PropertyKey, CommandEntry>): void {\n for (const [key, entry] of this.entries) {\n if (selected.get(key) === entry) continue;\n\n entry.detach?.();\n entry.detach = undefined;\n }\n\n this.entries = selected;\n\n for (const entry of selected.values()) {\n entry.detach ??= entry.slot.attach((inFlight, outcome) => {\n if (!updateEntry(entry, inFlight, outcome)) return;\n\n this.revision += 1;\n\n for (const listener of this.listeners) listener();\n });\n }\n }\n\n getSnapshot = (): number => this.revision;\n\n prepare(commands: CommandSelection, frame: Frame): Map<PropertyKey, CommandEntry> {\n const selected = new Map<PropertyKey, CommandEntry>();\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, Call<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 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): CommandGroup | undefined {\n const groupRef = useRef<CommandGroup | undefined>(undefined);\n const populated = Reflect.ownKeys(commands).some(key => Object.prototype.propertyIsEnumerable.call(commands, key));\n\n return populated ? (groupRef.current ??= new CommandGroup()) : undefined;\n}\n\nfunction useCommands<Commands extends { readonly [Key in keyof Commands]: Call<never, unknown> }>(\n commands: Commands,\n): CommandsHook<Commands> {\n const frame = useFrame();\n const group = useCommandGroup(commands);\n const getSnapshot = group?.getSnapshot ?? idleRevision;\n useSyncExternalStore(group?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const selected = group?.prepare(commands, 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 for (const entry of selected.values()) entry.slot.synchronize();\n });\n\n return (\n selected === undefined ? emptyHooks : Object.fromEntries([...selected].map(([key, entry]) => [key, entry.hook]))\n ) as CommandsHook<Commands>;\n}\n\nexport { useCommands };\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';\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>>;\ntype SelectionSnapshot = Readonly<{\n commands: Readonly<Record<PropertyKey, AnyCommand>>;\n sources: ReadonlySet<Readable<unknown>>;\n values: SelectionRecord;\n}>;\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 const value = source.getSnapshot();\n sources.set(source, value);\n\n return value;\n}\n\nfunction collectSelection(\n select: (context: SelectionContext) => object,\n sources: Map<Readable<unknown>, unknown>,\n): SelectionRecord {\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 return Object.fromEntries(\n Reflect.ownKeys(selected)\n .filter(key => Object.prototype.propertyIsEnumerable.call(selected, key))\n .map(key => [key, (selected as SelectionRecord)[key]]),\n );\n}\n\nfunction equalSelection(previous: SelectionSnapshot, values: SelectionRecord, sources: ReadonlySet<Readable<unknown>>) {\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 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 = { commands: {}, sources: new Set(), values: {} };\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 * 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 */\nfunction createSelectionSnapshot<Model>(model: Model, selectRef: SelectionReaderRef<Model>): () => SelectionSnapshot {\n let observed: Map<Readable<unknown>, unknown> | undefined;\n let observedSelect: ModelSelector<Model> | undefined;\n let snapshot: SelectionSnapshot = emptySelectionSnapshot;\n\n return () => {\n const select = selectRef.current;\n\n if (select === undefined) return emptySelectionSnapshot;\n\n if (\n observed !== undefined &&\n observedSelect === select &&\n [...observed].every(([source, value]) => Object.is(source.getSnapshot(), value))\n ) {\n return snapshot;\n }\n\n const nextObserved = new Map<Readable<unknown>, unknown>();\n const values = collectSelection(context => select(model, context), nextObserved);\n const sources = new Set(nextObserved.keys());\n\n if (observed === undefined || !equalSelection(snapshot, values, sources)) {\n snapshot = { commands: selectionCommands(values), sources, values };\n }\n\n observed = nextObserved;\n observedSelect = select;\n\n return snapshot;\n };\n}\n\nexport { createSelectionSnapshot, emptySelectionSnapshot };\nexport type { ModelSelector, SelectionContext, SelectionShape };\n","import type { Readable } from '@opetope/core';\nimport { createAggregateError } from '@opetope/core/internal';\n\ntype Subscription = { dispose: (() => void) | undefined };\ntype Listener = Readonly<{ notify: () => void }>;\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 private readonly listeners = new Set<Listener>();\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.releaseAll();\n }\n\n commit(sources: ReadonlySet<Readable<unknown>>): void {\n this.sources = sources;\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 subscriptions = [...this.subscriptions.values()];\n this.subscriptions.clear();\n releaseSubscriptions(subscriptions, 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 releaseSubscriptions(removed);\n }\n\n private synchronize(): void {\n this.removeUnselected();\n\n for (const source of this.sources) {\n if (!this.enabled || this.listeners.size === 0) return;\n\n if (this.sources.has(source) && !this.subscriptions.has(source)) this.add(source);\n }\n }\n}\n\nexport { ModelSelectionStore };\n","import { useLayoutEffect, useMemo, useRef, useSyncExternalStore } from 'react';\n\nimport type { Call, ModelOf } from '@opetope/core';\n\nimport type { CommandHook } from './command-hook';\nimport { useCommands } from './commands-hook';\nimport { ContributionError } from './errors';\nimport { subscribeIdle } from './idle-subscription';\nimport type { AnyModel } from './model-binding';\nimport { createSelectionSnapshot, emptySelectionSnapshot } from './model-selection-snapshot';\nimport type { ModelSelector, SelectionContext, SelectionShape } from './model-selection-snapshot';\nimport { ModelSelectionStore } from './model-selection-store';\nimport { useFrame } from './mount-context';\n\ntype SelectedValue<Value> = Value extends Call<infer Input, infer Output> ? CommandHook<Input, Output> : 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/** 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 const getSnapshot = useMemo(\n () => (selected ? createSelectionSnapshot(model, selectRef) : readEmptySnapshot),\n [model, selected],\n );\n const snapshot = useSyncExternalStore(store?.subscribe ?? subscribeIdle, getSnapshot, getSnapshot);\n const commands = useCommands(snapshot.commands);\n useLayoutEffect(() => () => store?.close(), [store]);\n useLayoutEffect(() => store?.commit(snapshot.sources), [snapshot, store]);\n\n if (select === undefined) return model;\n\n return Object.fromEntries(\n Reflect.ownKeys(snapshot.values).map(key => [\n key,\n Object.prototype.hasOwnProperty.call(commands, key) ? commands[key] : snapshot.values[key],\n ]),\n );\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, useSyncExternalStore } from 'react';\n\nimport type { Resource, ResourceSnapshot } from '@opetope/runtime';\nimport type { ResourceRequestKey } from '@opetope/runtime/internal';\n\nfunction useResource<Data, Key extends ResourceRequestKey>(resource: Resource<Data, Key>): ResourceSnapshot<Data, Key> {\n const subscribe = useCallback((listener: () => void) => resource.subscribe(listener), [resource]);\n // D199: a resource is a structural contract, so it may be an object with methods. Reading through it keeps the\n // receiver the adapter expects; handing `resource.getSnapshot` to React would call it with none.\n const getSnapshot = useCallback(() => resource.getSnapshot(), [resource]);\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n useEffect(() => resource.retain(), [resource]);\n\n return snapshot;\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\nfunction defineSlot<Props extends SlotProperties = undefined>(options: { readonly id: string }): SlotTarget<Props> {\n return createContributionTarget<SlotContribution<Props>>(options);\n}\n\nfunction defineSwitchSlot<Route extends string, Props extends SlotProperties = undefined>(options: {\n readonly id: string;\n}): SwitchSlotTarget<Route, Props> {\n const id = declarationId(options.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>({ id: `${id}/${route}` });\n targets.set(route, target);\n\n return target;\n };\n\n Object.defineProperty(switchSlot, 'id', { enumerable: true, value: id });\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","CallError","compatibleAbortReason","invocation","value","emptyStatus","unchangedState","current","slot","inFlight","nextState","lastError","result","useCommandSlot","slots","useState","useCommand","command","record","useFrame","currentSlot","hookState","setHookState","useInsertionEffect","useLayoutEffect","run","useMemo","idleRelease","subscribeIdle","idleRevision","emptyHooks","createEntry","unchangedHook","previous","next","outcomeStatus","updateEntry","entry","selectEntry","CommandGroup","selected","key","listener","commands","frame","useCommandGroup","groupRef","useRef","useCommands","group","getSnapshot","useSyncExternalStore","readSource","source","sources","isReadable","collectSelection","select","project","equalSelection","values","keys","previousKeys","index","emptySelectionSnapshot","selectionCommands","isCallTarget","createSelectionSnapshot","model","selectRef","observed","observedSelect","snapshot","nextObserved","context","releaseSubscriptions","subscriptions","failures","subscription","dispose","createAggregateError","ModelSelectionStore","removed","readEmptySnapshot","useSelectionStore","storeRef","useModel","declaration","store","requiresModels","models","declared","component","useResource","resource","subscribe","useCallback","useEffect","emptySlotProperties","defineSlot","createContributionTarget","defineSwitchSlot","id","declarationId","targets","switchSlot","route","existing","target","Slot","entries","useReadable","slotProps","createElement","Fragment","ContributionMount","contributionAuthority"],"mappings":"8nBA8BA,SAASA,EAAuBC,EAAgDC,EAAc,OAC5F,GAAIC,EAAeD,CAAK,EAAG,MAAO,CAAE,OAAQA,EAAO,OAAQ,WAAW,EAEtE,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,OAAQ,QAAQ,CAClC,CAEA,SAASM,EAAmBP,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,EACPC,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,EAAsBC,EAAwCC,EAA+B,CACpG,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,CAAW,EAEzE,OAAA+C,EAAU,IAAMH,EAAS,OAAM,EAAI,CAACA,CAAQ,CAAC,EAEtCtB,CACT,CC+BA,MAAM0B,EAA2C,OAAO,OAAO,EAAE,EAEjE,SAASC,EAAqDxH,EAAgC,CAC5F,OAAOyH,EAAkDzH,CAAO,CAClE,CAEA,SAAS0H,GAAiF1H,EAEzF,CACC,MAAM2H,EAAKC,EAAc5H,EAAQ,EAAE,EAC7B6H,EAAU,IAAI,IAEdC,EAAcC,GAAmC,CACrD,MAAMC,EAAWH,EAAQ,IAAIE,CAAK,EAElC,GAAIC,IAAa,OAAW,OAAOA,EAEnC,MAAMC,EAAST,EAAkB,CAAE,GAAI,GAAGG,CAAE,IAAII,CAAK,GAAI,EACzD,OAAAF,EAAQ,IAAIE,EAAOE,CAAM,EAElBA,CACT,EAEA,cAAO,eAAeH,EAAY,KAAM,CAAE,WAAY,GAAM,MAAOH,EAAI,EAEhE,OAAO,OAAOG,CAAU,CACjC,CAMA,SAASI,GAAmClI,EAA+B,CACzE,MAAMmI,EAAUC,EAAYpI,EAAQ,OAAO,OAAO,EAC5CqI,EAAoB,UAAWrI,EAAWA,EAAQ,OAASuH,EAAuBA,EAExF,OAAIY,EAAQ,SAAW,EAAU,KAE1BA,EAAQ,IAAIzE,GACjB4E,EACEC,EACA,CAAE,IAAK7E,EAAM,IACb4E,EAAcE,EAAmB,CAC/B,UAAWC,EAAsB/E,CAAK,EACtC,aAAcA,EAAM,MACpB,eAAgBA,EAAM,GACtB,UAAA2E,EACA,SAAUrI,EAAQ,OAAO,GAC1B,CAAC,CACH,CAEL"}
|
package/dist/integration.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type { Command, CommandOutcome } from './command.js';
|
|
2
|
+
export { ContributionBoundary } from './contribution-isolation.js';
|
|
3
|
+
export type { ContributionBoundaryProps, ContributionErrorContent, ContributionFailure, } from './contribution-isolation.js';
|
|
2
4
|
export { FeatureBoundary, FeatureBoundaryError, useFeatureRetry } from './feature-boundary.js';
|
|
3
5
|
export type { FeatureBoundaryProps } from './feature-boundary.js';
|
|
4
6
|
export { useFeature } from './feature-demand.js';
|
package/dist/integration.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{a as M}from"./contribution-isolation-Bzfbt4iM.js";import{jsx as C}from"react/jsx-runtime";import{useCallback as f,useSyncExternalStore as E,useMemo as h,useEffect as x,useState as S,createContext as B,useContext as g}from"react";const y=()=>{};function b(e){const r=f(t=>e.subscribe(t),[e]),u=f(()=>e.getState(),[e]),d=E(r,u,u),n=h(()=>({current:null,source:e}),[e]);x(()=>{const t=e.acquire();return t.settled.catch(y),()=>{t.release().catch(y)}},[e]);const o=f(()=>{if(n.current!==null)return n.current.settled;let t=()=>{};const s={lease:null,settled:new Promise(p=>{t=p})},c=()=>{n.current===s&&(n.current=null),t()};n.current=s;let i;try{i=n.source.acquire()}catch{return c(),s.settled}return s.lease=i,i.settled.catch(y).finally(c),i.release().catch(y),s.settled},[n]);return h(()=>Object.freeze({retry:o,state:d}),[o,d])}const F=B(void 0);class v extends Error{code;name="FeatureBoundaryError";constructor(r,u){super(u),this.code=r}}function w(){const e=g(F);if(e===void 0)throw new v("missing","Feature error hooks may only be used by the error subtree of a FeatureBoundary.");return e}function q(){return w().retry}function j({children:e,demand:r,error:u,fallback:d}){const{retry:n,state:o}=b(r),[t,s]=S(),c=f(()=>{const a={},m=()=>s(l=>(l==null?void 0:l.attempt)===a?void 0:l);s({attempt:a,demand:r});try{n().finally(m)}catch(l){throw m(),l}},[r,n]),i=h(()=>({retry:c}),[c]),p=(t==null?void 0:t.demand)===r;if(x(()=>{s(a=>a===void 0||a.demand===r&&o.instance===null?a:void 0)},[r,o.instance]),o.instance!==null)return typeof e=="function"?e(o.instance):e;if(o.error!==null&&!p){const a=typeof u=="function"?u({error:o.error,retry:c}):u;return C(F,{value:i,children:a})}return d}export{M as ContributionBoundary,j as FeatureBoundary,v as FeatureBoundaryError,b as useFeature,q as useFeatureRetry};
|
|
2
2
|
//# sourceMappingURL=integration.js.map
|
package/dist/integration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","sources":["../src/feature-demand.ts","../src/feature-boundary.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';\n\ninterface FeatureDemandLease {\n readonly release: () => Promise<void>;\n readonly settled: Promise<void>;\n}\n\ninterface FeatureDemandState<Ready> {\n readonly error: unknown | null;\n readonly instance: Ready | null;\n}\n\ninterface FeatureDemandSource<Ready> {\n acquire(): FeatureDemandLease;\n getState(): FeatureDemandState<Ready>;\n subscribe(listener: () => void): () => void;\n}\n\ninterface FeatureDemandResult<Ready> {\n /** Resolves when the attempt it started has settled, in success and in failure alike (D198). */\n readonly retry: () => Promise<void>;\n readonly state: FeatureDemandState<Ready>;\n}\n\nconst ignoreFailure = (): void => undefined;\n\nfunction useFeature<Ready>(source: FeatureDemandSource<Ready>): FeatureDemandResult<Ready> {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source]);\n const getSnapshot = useCallback(() => source.getState(), [source]);\n const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const retrying = useMemo<{\n current: { lease: FeatureDemandLease | null; readonly settled: Promise<void> } | null;\n readonly source: FeatureDemandSource<Ready>;\n }>(() => ({ current: null, source }), [source]);\n\n useEffect(() => {\n const demand = source.acquire();\n void demand.settled.catch(ignoreFailure);\n\n return () => void demand.release().catch(ignoreFailure);\n }, [source]);\n\n const retry = useCallback((): Promise<void> => {\n // Single-flight per source: a second call joins the attempt already running instead of starting another.\n if (retrying.current !== null) return retrying.current.settled;\n\n // D198: `acquire` runs foreign code, and a host that answers it synchronously may call `retry` again. The\n // attempt is reserved with its own promise before that call, so the reentrant caller joins this attempt\n // instead of taking a second lease of its own.\n let settle = (): void => undefined;\n const attempt = {\n lease: null as FeatureDemandLease | null,\n settled: new Promise<void>(resolve => {\n settle = resolve;\n }),\n };\n const finish = (): void => {\n if (retrying.current === attempt) retrying.current = null;\n\n settle();\n };\n retrying.current = attempt;\n\n let lease: FeatureDemandLease;\n\n try {\n lease = retrying.source.acquire();\n } catch {\n // D198: `retry` answers with the promise of the attempt it started, and an acquisition that refused is an\n // attempt that is over. The refusal belongs to the state the source publishes, which is where the caller\n // reads it; throwing it back here would leave every caller of `retry` waiting for an attempt that ended.\n finish();\n\n return attempt.settled;\n }\n\n attempt.lease = lease;\n void lease.settled.catch(ignoreFailure).finally(finish);\n void lease.release().catch(ignoreFailure);\n\n return attempt.settled;\n }, [retrying]);\n\n return useMemo(() => Object.freeze({ retry, state }), [retry, state]);\n}\n\nexport { useFeature };\nexport type { FeatureDemandLease, FeatureDemandResult, FeatureDemandSource, FeatureDemandState };\n","import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { useFeature } from './feature-demand';\nimport type { FeatureDemandSource } from './feature-demand';\n\n/**\n * D177: a branch may be a node or a render callback. The callback receives what only the boundary knows — the ready\n * instance, or the failure with the retry that belongs to this demand — so a ready consumer needs no second\n * `useFeature` and no second lease. A function is never a `ReactNode`, so the two forms cannot be confused.\n */\ntype FeatureBoundaryChildren<Ready> = ((instance: Ready) => ReactNode) | ReactNode;\ntype FeatureBoundaryErrorContent =\n | ((context: { readonly error: unknown; readonly retry: () => void }) => ReactNode)\n | ReactNode;\n\n/** The boundary keeps the feature open while it is mounted; its UI enters the host through slots (D85). */\ntype FeatureBoundaryProps<Ready = unknown> = {\n readonly children: FeatureBoundaryChildren<Ready>;\n readonly demand: FeatureDemandSource<Ready>;\n readonly error: FeatureBoundaryErrorContent;\n readonly fallback: ReactNode;\n};\n\n/** Only `retry` is read: the error itself belongs to the `error` subtree a host already renders (D142). */\ntype FeatureBoundaryErrorContext = {\n readonly retry: () => void;\n};\n\n/** D198: the error is hidden for the life of the attempt that was started, not until the error object changes. */\ntype SuppressedError = {\n readonly attempt: object;\n readonly demand: object;\n};\n\nconst ErrorContext = createContext<FeatureBoundaryErrorContext | undefined>(undefined);\n\n/** One class per subject with the state in `code` (D69): the boundary is its own subject, not a feature failure. */\nclass FeatureBoundaryError extends Error {\n override readonly name = 'FeatureBoundaryError';\n\n constructor(\n readonly code: 'missing',\n message: string,\n ) {\n super(message);\n }\n}\n\nfunction useBoundaryErrorContext(): FeatureBoundaryErrorContext {\n const context = useContext(ErrorContext);\n\n if (context === undefined) {\n throw new FeatureBoundaryError(\n 'missing',\n 'Feature error hooks may only be used by the error subtree of a FeatureBoundary.',\n );\n }\n\n return context;\n}\n\nfunction useFeatureRetry(): () => void {\n return useBoundaryErrorContext().retry;\n}\n\nfunction FeatureBoundary<Ready>({ children, demand, error, fallback }: FeatureBoundaryProps<Ready>): ReactNode {\n const { retry: requestRetry, state } = useFeature(demand);\n const [suppressed, setSuppressed] = useState<SuppressedError>();\n const retry = useCallback(() => {\n const attempt = {};\n // The attempt is over: whatever it ended with, including the very same error object, is the answer to show.\n const reveal = (): void => setSuppressed(current => (current?.attempt === attempt ? undefined : current));\n setSuppressed({ attempt, demand });\n\n try {\n void requestRetry().finally(reveal);\n } catch (error) {\n // A retry that refuses synchronously has no promise to settle, and an error hidden by it would never be\n // shown again: the suppression is lifted here before the refusal goes back to whoever asked (D198).\n reveal();\n\n throw error;\n }\n }, [demand, requestRetry]);\n const errorContext = useMemo(() => ({ retry }), [retry]);\n const errorIsSuppressed = suppressed?.demand === demand;\n\n useEffect(() => {\n // A suppression outlives neither its source nor a ready feature: only the attempt of this demand may hide it.\n setSuppressed(current =>\n current === undefined || (current.demand === demand && state.instance === null) ? current : undefined,\n );\n }, [demand, state.instance]);\n\n // Only the branch that is shown runs its callback: an abandoned branch renders nothing and computes nothing.\n if (state.instance !== null) return typeof children === 'function' ? children(state.instance) : children;\n\n if (state.error !== null && !errorIsSuppressed) {\n const content = typeof error === 'function' ? error({ error: state.error, retry }) : error;\n\n return <ErrorContext value={errorContext}>{content}</ErrorContext>;\n }\n\n return fallback;\n}\n\nexport { FeatureBoundary, FeatureBoundaryError, useFeatureRetry };\nexport type { FeatureBoundaryProps };\n"],"names":["ignoreFailure","useFeature","source","subscribe","useCallback","listener","getSnapshot","state","useSyncExternalStore","retrying","useMemo","useEffect","demand","retry","settle","attempt","resolve","finish","lease","ErrorContext","createContext","FeatureBoundaryError","code","message","useBoundaryErrorContext","context","useContext","useFeatureRetry","FeatureBoundary","children","error","fallback","requestRetry","suppressed","setSuppressed","useState","reveal","current","errorContext","errorIsSuppressed","content","_jsx"],"mappings":"mLAwBA,MAAMA,EAAgB,IAAA,GAEtB,SAASC,EAAkBC,EAAkC,CAC3D,MAAMC,EAAYC,EAAaC,GAAyBH,EAAO,UAAUG,CAAQ,EAAG,CAACH,CAAM,CAAC,EACtFI,EAAcF,EAAY,IAAMF,EAAO,SAAQ,EAAI,CAACA,CAAM,CAAC,EAC3DK,EAAQC,EAAqBL,EAAWG,EAAaA,CAAW,EAChEG,EAAWC,EAGd,KAAO,CAAE,QAAS,KAAM,OAAAR,CAAM,GAAK,CAACA,CAAM,CAAC,EAE9CS,EAAU,IAAK,CACb,MAAMC,EAASV,EAAO,QAAO,EAC7B,OAAKU,EAAO,QAAQ,MAAMZ,CAAa,EAEhC,IAAA,CAAWY,EAAO,QAAO,EAAG,MAAMZ,CAAa,EACxD,EAAG,CAACE,CAAM,CAAC,EAEX,MAAMW,EAAQT,EAAY,IAAoB,CAE5C,GAAIK,EAAS,UAAY,KAAM,OAAOA,EAAS,QAAQ,QAKvD,IAAIK,EAAS,IAAA,GACb,MAAMC,EAAU,CACd,MAAO,KACP,QAAS,IAAI,QAAcC,GAAU,CACnCF,EAASE,CACX,CAAC,GAEGC,EAAS,IAAW,CACpBR,EAAS,UAAYM,IAASN,EAAS,QAAU,MAErDK,EAAM,CACR,EACAL,EAAS,QAAUM,EAEnB,IAAIG,EAEJ,GAAI,CACFA,EAAQT,EAAS,OAAO,QAAO,CACjC,MAAQ,CAIN,OAAAQ,EA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D0B,GAAoBN,GAAA,YAAAA,EAAY,UAAWrB,EAUjD,GARAD,EAAU,IAAK,CAEbuB,EAAcG,GACZA,IAAY,QAAcA,EAAQ,SAAWzB,GAAUL,EAAM,WAAa,KAAQ8B,EAAU,MAAS,CAEzG,EAAG,CAACzB,EAAQL,EAAM,QAAQ,CAAC,EAGvBA,EAAM,WAAa,KAAM,OAAO,OAAOsB,GAAa,WAAaA,EAAStB,EAAM,QAAQ,EAAIsB,EAEhG,GAAItB,EAAM,QAAU,MAAQ,CAACgC,EAAmB,CAC9C,MAAMC,EAAU,OAAOV,GAAU,WAAaA,EAAM,CAAE,MAAOvB,EAAM,MAAO,MAAAM,CAAK,CAAE,EAAIiB,EAErF,OAAOW,EAACtB,EAAY,CAAC,MAAOmB,EAAY,SAAGE,EAAO,CACpD,CAEA,OAAOT,CACT"}
|
|
1
|
+
{"version":3,"file":"integration.js","sources":["../src/feature-demand.ts","../src/feature-boundary.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';\n\ninterface FeatureDemandLease {\n readonly release: () => Promise<void>;\n readonly settled: Promise<void>;\n}\n\ninterface FeatureDemandState<Ready> {\n readonly error: unknown | null;\n readonly instance: Ready | null;\n}\n\ninterface FeatureDemandSource<Ready> {\n acquire(): FeatureDemandLease;\n getState(): FeatureDemandState<Ready>;\n subscribe(listener: () => void): () => void;\n}\n\ninterface FeatureDemandResult<Ready> {\n /** Resolves when the attempt it started has settled, in success and in failure alike (D198). */\n readonly retry: () => Promise<void>;\n readonly state: FeatureDemandState<Ready>;\n}\n\nconst ignoreFailure = (): void => undefined;\n\nfunction useFeature<Ready>(source: FeatureDemandSource<Ready>): FeatureDemandResult<Ready> {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source]);\n const getSnapshot = useCallback(() => source.getState(), [source]);\n const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const retrying = useMemo<{\n current: { lease: FeatureDemandLease | null; readonly settled: Promise<void> } | null;\n readonly source: FeatureDemandSource<Ready>;\n }>(() => ({ current: null, source }), [source]);\n\n useEffect(() => {\n const demand = source.acquire();\n void demand.settled.catch(ignoreFailure);\n\n return () => void demand.release().catch(ignoreFailure);\n }, [source]);\n\n const retry = useCallback((): Promise<void> => {\n // Single-flight per source: a second call joins the attempt already running instead of starting another.\n if (retrying.current !== null) return retrying.current.settled;\n\n // D198: `acquire` runs foreign code, and a host that answers it synchronously may call `retry` again. The\n // attempt is reserved with its own promise before that call, so the reentrant caller joins this attempt\n // instead of taking a second lease of its own.\n let settle = (): void => undefined;\n const attempt = {\n lease: null as FeatureDemandLease | null,\n settled: new Promise<void>(resolve => {\n settle = resolve;\n }),\n };\n const finish = (): void => {\n if (retrying.current === attempt) retrying.current = null;\n\n settle();\n };\n retrying.current = attempt;\n\n let lease: FeatureDemandLease;\n\n try {\n lease = retrying.source.acquire();\n } catch {\n // D198: `retry` answers with the promise of the attempt it started, and an acquisition that refused is an\n // attempt that is over. The refusal belongs to the state the source publishes, which is where the caller\n // reads it; throwing it back here would leave every caller of `retry` waiting for an attempt that ended.\n finish();\n\n return attempt.settled;\n }\n\n attempt.lease = lease;\n void lease.settled.catch(ignoreFailure).finally(finish);\n void lease.release().catch(ignoreFailure);\n\n return attempt.settled;\n }, [retrying]);\n\n return useMemo(() => Object.freeze({ retry, state }), [retry, state]);\n}\n\nexport { useFeature };\nexport type { FeatureDemandLease, FeatureDemandResult, FeatureDemandSource, FeatureDemandState };\n","import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { useFeature } from './feature-demand';\nimport type { FeatureDemandSource } from './feature-demand';\n\n/**\n * D177: a branch may be a node or a render callback. The callback receives what only the boundary knows — the ready\n * instance, or the failure with the retry that belongs to this demand — so a ready consumer needs no second\n * `useFeature` and no second lease. A function is never a `ReactNode`, so the two forms cannot be confused.\n */\ntype FeatureBoundaryChildren<Ready> = ((instance: Ready) => ReactNode) | ReactNode;\ntype FeatureBoundaryErrorContent =\n | ((context: { readonly error: unknown; readonly retry: () => void }) => ReactNode)\n | ReactNode;\n\n/** The boundary keeps the feature open while it is mounted; its UI enters the host through slots (D85). */\ntype FeatureBoundaryProps<Ready = unknown> = {\n readonly children: FeatureBoundaryChildren<Ready>;\n readonly demand: FeatureDemandSource<Ready>;\n readonly error: FeatureBoundaryErrorContent;\n readonly fallback: ReactNode;\n};\n\n/** Only `retry` is read: the error itself belongs to the `error` subtree a host already renders (D142). */\ntype FeatureBoundaryErrorContext = {\n readonly retry: () => void;\n};\n\n/** D198: the error is hidden for the life of the attempt that was started, not until the error object changes. */\ntype SuppressedError = {\n readonly attempt: object;\n readonly demand: object;\n};\n\nconst ErrorContext = createContext<FeatureBoundaryErrorContext | undefined>(undefined);\n\n/** One class per subject with the state in `code` (D69): the boundary is its own subject, not a feature failure. */\nclass FeatureBoundaryError extends Error {\n override readonly name = 'FeatureBoundaryError';\n\n constructor(\n readonly code: 'missing',\n message: string,\n ) {\n super(message);\n }\n}\n\nfunction useBoundaryErrorContext(): FeatureBoundaryErrorContext {\n const context = useContext(ErrorContext);\n\n if (context === undefined) {\n throw new FeatureBoundaryError(\n 'missing',\n 'Feature error hooks may only be used by the error subtree of a FeatureBoundary.',\n );\n }\n\n return context;\n}\n\nfunction useFeatureRetry(): () => void {\n return useBoundaryErrorContext().retry;\n}\n\nfunction FeatureBoundary<Ready>({ children, demand, error, fallback }: FeatureBoundaryProps<Ready>): ReactNode {\n const { retry: requestRetry, state } = useFeature(demand);\n const [suppressed, setSuppressed] = useState<SuppressedError>();\n const retry = useCallback(() => {\n const attempt = {};\n // The attempt is over: whatever it ended with, including the very same error object, is the answer to show.\n const reveal = (): void => setSuppressed(current => (current?.attempt === attempt ? undefined : current));\n setSuppressed({ attempt, demand });\n\n try {\n void requestRetry().finally(reveal);\n } catch (error) {\n // A retry that refuses synchronously has no promise to settle, and an error hidden by it would never be\n // shown again: the suppression is lifted here before the refusal goes back to whoever asked (D198).\n reveal();\n\n throw error;\n }\n }, [demand, requestRetry]);\n const errorContext = useMemo(() => ({ retry }), [retry]);\n const errorIsSuppressed = suppressed?.demand === demand;\n\n useEffect(() => {\n // A suppression outlives neither its source nor a ready feature: only the attempt of this demand may hide it.\n setSuppressed(current =>\n current === undefined || (current.demand === demand && state.instance === null) ? current : undefined,\n );\n }, [demand, state.instance]);\n\n // Only the branch that is shown runs its callback: an abandoned branch renders nothing and computes nothing.\n if (state.instance !== null) return typeof children === 'function' ? children(state.instance) : children;\n\n if (state.error !== null && !errorIsSuppressed) {\n const content = typeof error === 'function' ? error({ error: state.error, retry }) : error;\n\n return <ErrorContext value={errorContext}>{content}</ErrorContext>;\n }\n\n return fallback;\n}\n\nexport { FeatureBoundary, FeatureBoundaryError, useFeatureRetry };\nexport type { FeatureBoundaryProps };\n"],"names":["ignoreFailure","useFeature","source","subscribe","useCallback","listener","getSnapshot","state","useSyncExternalStore","retrying","useMemo","useEffect","demand","retry","settle","attempt","resolve","finish","lease","ErrorContext","createContext","FeatureBoundaryError","code","message","useBoundaryErrorContext","context","useContext","useFeatureRetry","FeatureBoundary","children","error","fallback","requestRetry","suppressed","setSuppressed","useState","reveal","current","errorContext","errorIsSuppressed","content","_jsx"],"mappings":"4OAwBA,MAAMA,EAAgB,IAAA,GAEtB,SAASC,EAAkBC,EAAkC,CAC3D,MAAMC,EAAYC,EAAaC,GAAyBH,EAAO,UAAUG,CAAQ,EAAG,CAACH,CAAM,CAAC,EACtFI,EAAcF,EAAY,IAAMF,EAAO,SAAQ,EAAI,CAACA,CAAM,CAAC,EAC3DK,EAAQC,EAAqBL,EAAWG,EAAaA,CAAW,EAChEG,EAAWC,EAGd,KAAO,CAAE,QAAS,KAAM,OAAAR,CAAM,GAAK,CAACA,CAAM,CAAC,EAE9CS,EAAU,IAAK,CACb,MAAMC,EAASV,EAAO,QAAO,EAC7B,OAAKU,EAAO,QAAQ,MAAMZ,CAAa,EAEhC,IAAA,CAAWY,EAAO,QAAO,EAAG,MAAMZ,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AAa,EAAIC,EAAQ,EACtCtB,EAAQT,EAAY,IAAK,CAC7B,MAAMW,EAAU,CAAA,EAEVqB,EAAS,IAAYF,EAAcG,IAAYA,GAAA,YAAAA,EAAS,WAAYtB,EAAU,OAAYsB,CAAQ,EACxGH,EAAc,CAAE,QAAAnB,EAAS,OAAAH,EAAQ,EAEjC,GAAI,CACGoB,EAAY,EAAG,QAAQI,CAAM,CACpC,OAASN,EAAO,CAGd,MAAAM,EAAM,EAEAN,CACR,CACF,EAAG,CAAClB,EAAQoB,CAAY,CAAC,EACnBM,EAAe5B,EAAQ,KAAO,CAAE,MAAAG,CAAK,GAAK,CAACA,CAAK,CAAC,EACjD0B,GAAoBN,GAAA,YAAAA,EAAY,UAAWrB,EAUjD,GARAD,EAAU,IAAK,CAEbuB,EAAcG,GACZA,IAAY,QAAcA,EAAQ,SAAWzB,GAAUL,EAAM,WAAa,KAAQ8B,EAAU,MAAS,CAEzG,EAAG,CAACzB,EAAQL,EAAM,QAAQ,CAAC,EAGvBA,EAAM,WAAa,KAAM,OAAO,OAAOsB,GAAa,WAAaA,EAAStB,EAAM,QAAQ,EAAIsB,EAEhG,GAAItB,EAAM,QAAU,MAAQ,CAACgC,EAAmB,CAC9C,MAAMC,EAAU,OAAOV,GAAU,WAAaA,EAAM,CAAE,MAAOvB,EAAM,MAAO,MAAAM,CAAK,CAAE,EAAIiB,EAErF,OAAOW,EAACtB,EAAY,CAAC,MAAOmB,EAAY,SAAGE,EAAO,CACpD,CAEA,OAAOT,CACT"}
|
package/dist/scenario-slot.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ type SlotTestFixture<Props extends SlotProperties> = {
|
|
|
10
10
|
readonly contribution?: SlotContribution<Props>;
|
|
11
11
|
readonly models?: readonly ModelFixture[];
|
|
12
12
|
readonly props?: SlotComponentProperties<Props>;
|
|
13
|
+
/**
|
|
14
|
+
* Where a contained mount failure is reported (D256). A component test has no feature to report to, so without it
|
|
15
|
+
* the failure is detached and the assertion has nothing to read.
|
|
16
|
+
*/
|
|
17
|
+
readonly reporter?: (error: unknown) => void;
|
|
13
18
|
};
|
|
14
19
|
interface SlotTestHarness<Props extends SlotProperties> {
|
|
15
20
|
readonly Slot: FC;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Call } from '@opetope/core';
|
|
2
|
+
interface RunCallOptions {
|
|
3
|
+
readonly signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
/** Runs an authentic Call in a test; its existing owner still controls scheduling, retirement and cleanup. */
|
|
6
|
+
declare function runCall<Input, Output>(target: Call<Input, Output>, ...args: [Input] extends [void] ? [input?: NoInfer<Input>, options?: RunCallOptions] : [input: NoInfer<Input>, options?: RunCallOptions]): Promise<Output>;
|
|
7
|
+
export { runCall };
|
|
8
|
+
export type { RunCallOptions };
|
package/dist/testing.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { createScenario } from './scenario.js';
|
|
|
2
2
|
export { ScenarioTimeoutError } from './scenario-diagnostics.js';
|
|
3
3
|
export { command, renderSlot } from './scenario-slot.js';
|
|
4
4
|
export type { SlotTestFixture, SlotTestHarness } from './scenario-slot.js';
|
|
5
|
+
export { runCall } from './testing-call.js';
|
|
6
|
+
export type { RunCallOptions } from './testing-call.js';
|
|
5
7
|
export type { Scenario, ScenarioHost, ScenarioHostMount, ScenarioMount, ScenarioOptions, ScenarioOwnership, ScenarioWaitOptions, } from './scenario-types.js';
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{defineCallTarget as x,createAggregateError as _}from"@opetope/core/internal";import{openApplication as
|
|
1
|
+
import{defineCallTarget as x,createAggregateError as _,invokeCallTarget as N}from"@opetope/core/internal";import{openApplication as q}from"@opetope/runtime";import{createInspectionSession as B}from"@opetope/runtime/internal";import{createElement as H}from"react";import{declarationId as D}from"@opetope/core";import{d as L,a as F,c as U,M as W}from"./contribution-frame-B1PnpOaP.js";function G(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 J(e){if(e.lane===null)return`Call ${e.declaration}: ${e.state}; lane parallel; blockers none (parallel).`;const t=e.lane.blockedBy==="unknown"?"unknown":e.lane.blockedBy.join(", ");return`Call ${e.declaration}: ${e.state}; lane ${e.lane.declaration}; blockers ${t}.`}function K(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(J),...e.resources.map(n=>`Resource ${n.id}: ${n.state}; retainers ${String(n.retainers)}.`)]}function Q(e){const t=[...e.runtime.conditions.flatMap(n=>n.state.kind==="true"?[]:[`Condition ${n.label}: ${n.state.kind}.`]),...e.runtime.instances.flatMap(G),...K(e.activity)];return t.length===0?"No registered runtime blocker observed; external UI and host work are unknown.":t.join(`
|
|
2
2
|
`)}class E extends Error{label;timeoutMs;snapshot;history;code="timeout";constructor(t,n,r,o){super(`Scenario timed out after ${String(n)}ms: ${t}.
|
|
3
|
-
${
|
|
3
|
+
${Q(r)}`),this.label=t,this.timeoutMs=n,this.snapshot=r,this.history=o,this.name="ScenarioTimeoutError"}}function V(e,t){return!t||e===void 0?!1:e.closed&&!e.truncated}function X(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 Y(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 Z(e,t){const n=e.activity,r=V(n,t);return Object.freeze({...Y(n,r),closed:t,reasons:X(n,r,t),scope:"registered-runtime",status:r?"complete":"unknown"})}class ee{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 te=D("testing.contribution");let T=0;function ne(e){return T+=1,L(x({id:`testing.command.${String(T)}`,run:e}))}function A(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,u=s===void 0?void 0:{models:[],reporter:s};return Object.freeze({close:()=>{r={},o.clear()},Slot:()=>{const i=F(e.entries),d=F(w);return(c===void 0?i.map(p=>[p.id,p.value,U(p)??u]):[[te,c,u]]).map(([p,f,k])=>H(W,{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 re(e,t={}){const n=A(e,t);return Object.freeze({Slot:n.Slot,updateProps:n.updateProps})}function M(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 oe{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 M(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=M(n.timeoutMs??this.source.timeoutMs,"Scenario timeoutMs"),o=M(n.pollIntervalMs??10,"Scenario pollIntervalMs");return new Promise((w,c)=>{let s=!1,u=()=>{};const g=(f,k=f!==void 0)=>{s||(s=!0,u(),k?c(f):w())},i=()=>{if(!s)try{t(this.source.getSnapshot())&&g()}catch(f){g(f,!0)}},d=f=>g(f),v=setTimeout(()=>g(this.timeout(n.label??"waitFor",r)),r),p=setInterval(i,o);u=()=>{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 E(t,n,this.source.getSnapshot(),this.source.history())}}function I(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 se(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 ie(e,t){const n=M(t.timeoutMs??1e3,"Scenario timeoutMs"),r=I(t.historyCapacity??64,"Scenario historyCapacity"),o=I(t.activityCapacity??256,"Scenario activityCapacity");let w=t.host;se(w);let c=q(e,{...t.cleanupFailure===void 0?{}:{cleanupFailure:t.cleanupFailure},conditions:t.conditions,imports:t.imports}),s;try{s=B(c,{activityCapacity:o,ringCapacity:r})}catch(l){throw c.ready.catch(()=>{}),c.close().catch(()=>{}),l}let u="open",g=!1,i=!1;const d=[],v=new Set,p=[],f=()=>s.getSnapshot(),k=()=>Object.freeze([...d]),$=new oe({getSnapshot:f,history:k,timeoutMs:n}),j=()=>{if(!i){i=!0;try{const l=f(),m=d[d.length-1];((m==null?void 0:m.stateRevision)!==l.stateRevision||m.activity!==l.activity)&&(d.push(l),d.length>r&&d.shift())}finally{i=!1}$.notify()}},R=s.subscribe(j);j();const P=$.deadline(c.ready,"application ready");P.catch(()=>{});let C,y;const z=()=>{if(C!==void 0)return C;let l,m;C=new Promise((a,h)=>{l=a,m=h}),u="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,u="closed";try{j()}catch(b){h.push(b)}finally{R(),s.close(),v.clear(),c=void 0,w=void 0}g=h.length===0,h.length===0?l():m(_(h,"Scenario cleanup failed."))}),C};return Object.freeze({close:()=>{if(y!==void 0)return y;const l=z();return y!==void 0||(y=$.deadline(l,"scenario close"),y.catch(()=>{u==="closing"&&(y=void 0)})),y},getSnapshot:f,history:k,mount:(l,m={})=>{if(u!=="open")throw new Error("Scenario is closing.");const S=A(l,m),a=new ee((b,O)=>{v.delete(a),S.close(),b&&p.push(O)});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(u!=="open"||a.closed)throw new Error("Scenario mount is closed.");S.updateProps(b),$.notify()}})},notify:()=>{u==="open"&&$.notify()},ownership:()=>Z(f(),g),ready:P,waitFor:(l,m={})=>u!=="open"?Promise.reject(new Error("Scenario is closing.")):$.waitFor(l,m)})}async function ae(e,...t){var n;return N(e,t[0],{signal:((n=t[1])==null?void 0:n.signal)??new AbortController().signal})}export{E as ScenarioTimeoutError,ne as command,ie as createScenario,re as renderSlot,ae as runCall};
|
|
4
4
|
//# sourceMappingURL=testing.js.map
|