@weiliang0121/capix-runtime 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/binding/access.d.ts +24 -0
- package/dist/binding/access.js +2 -0
- package/dist/binding/callable.d.ts +14 -0
- package/dist/binding/callable.js +2 -0
- package/dist/binding/calls.d.ts +41 -0
- package/dist/binding/calls.js +2 -0
- package/dist/binding/checkpoint-list.d.ts +1 -0
- package/dist/binding/checkpoint-list.js +2 -0
- package/dist/binding/checkpoint.d.ts +9 -0
- package/dist/binding/checkpoint.js +2 -0
- package/dist/binding/children/binding.d.ts +34 -0
- package/dist/binding/children/binding.js +2 -0
- package/dist/binding/children/bound.d.ts +19 -0
- package/dist/binding/children/bound.js +2 -0
- package/dist/binding/children/builder.d.ts +18 -0
- package/dist/binding/children/builder.js +2 -0
- package/dist/binding/children/references.d.ts +29 -0
- package/dist/binding/children/references.js +2 -0
- package/dist/binding/contract.d.ts +27 -0
- package/dist/binding/contract.js +1 -0
- package/dist/binding/declarations.d.ts +18 -0
- package/dist/binding/declarations.js +2 -0
- package/dist/binding/hooks.d.ts +32 -0
- package/dist/binding/hooks.js +2 -0
- package/dist/binding/observation.d.ts +27 -0
- package/dist/binding/observation.js +2 -0
- package/dist/binding/receptions.d.ts +9 -0
- package/dist/binding/receptions.js +2 -0
- package/dist/binding/resources.d.ts +18 -0
- package/dist/binding/resources.js +2 -0
- package/dist/binding/snapshot.d.ts +16 -0
- package/dist/binding/snapshot.js +2 -0
- package/dist/binding/work.d.ts +20 -0
- package/dist/binding/work.js +2 -0
- package/dist/construction/calls.d.ts +21 -0
- package/dist/construction/calls.js +2 -0
- package/dist/construction/capabilities.d.ts +11 -0
- package/dist/construction/capabilities.js +2 -0
- package/dist/construction/feedback.d.ts +15 -0
- package/dist/construction/feedback.js +2 -0
- package/dist/construction/invocation.d.ts +38 -0
- package/dist/construction/invocation.js +2 -0
- package/dist/construction.d.ts +25 -0
- package/dist/construction.js +2 -0
- package/dist/definition/observation.d.ts +18 -0
- package/dist/definition/observation.js +2 -0
- package/dist/entry.d.ts +32 -0
- package/dist/entry.js +2 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +2 -0
- package/dist/initializer.d.ts +7 -0
- package/dist/initializer.js +2 -0
- package/dist/legacy/binding.d.ts +14 -0
- package/dist/legacy/binding.js +2 -0
- package/dist/legacy/driver.d.ts +20 -0
- package/dist/legacy/driver.js +2 -0
- package/dist/legacy/sources.d.ts +41 -0
- package/dist/legacy/sources.js +2 -0
- package/dist/observation/driver.d.ts +24 -0
- package/dist/observation/driver.js +1 -0
- package/dist/recording.d.ts +3 -0
- package/dist/recording.js +2 -0
- package/dist/records/observation/declaration.d.ts +18 -0
- package/dist/records/observation/declaration.js +2 -0
- package/dist/records/observation/installation.d.ts +37 -0
- package/dist/records/observation/installation.js +2 -0
- package/dist/records/observation/invocation.d.ts +34 -0
- package/dist/records/observation/invocation.js +2 -0
- package/dist/records/observation/mapping.d.ts +7 -0
- package/dist/records/observation/mapping.js +2 -0
- package/dist/resource/installation.d.ts +9 -0
- package/dist/resource/installation.js +2 -0
- package/dist/resource/resources.d.ts +37 -0
- package/dist/resource/resources.js +2 -0
- package/dist/runner/cancellation.d.ts +9 -0
- package/dist/runner/cancellation.js +2 -0
- package/dist/runner/feedback.d.ts +20 -0
- package/dist/runner/feedback.js +2 -0
- package/dist/runner/observation-contract.d.ts +137 -0
- package/dist/runner/observation-contract.js +1 -0
- package/dist/runner/observation-projection.d.ts +7 -0
- package/dist/runner/observation-projection.js +2 -0
- package/dist/runner/observation.d.ts +14 -0
- package/dist/runner/observation.js +2 -0
- package/dist/runner/output.d.ts +14 -0
- package/dist/runner/output.js +2 -0
- package/dist/runner.d.ts +37 -0
- package/dist/runner.js +2 -0
- package/dist/structure/builder.d.ts +12 -0
- package/dist/structure/builder.js +2 -0
- package/dist/structure/construction.d.ts +22 -0
- package/dist/structure/construction.js +2 -0
- package/dist/structure/install.d.ts +5 -0
- package/dist/structure/install.js +2 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wei.liang (https://github.com/weiliang0121)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weiliang0121/capix-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Structure binding, resource assembly, and Runner for CAPiX.
|
|
4
|
+
|
|
5
|
+
ES modules and TypeScript declarations. Requires Node.js 22.23.2 or newer.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @weiliang0121/capix-runtime
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public entry points
|
|
12
|
+
|
|
13
|
+
- `@weiliang0121/capix-runtime`
|
|
14
|
+
- `@weiliang0121/capix-runtime/construction`
|
|
15
|
+
- `@weiliang0121/capix-runtime/recording`
|
|
16
|
+
|
|
17
|
+
This package is part of CAPiX. The npm distribution contains compiled JavaScript, type declarations, and this package's MIT license. Reference services and client applications are not included in this package or the initial npm release.
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT. Copyright (c) 2026 wei.liang. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CallableContext, Invocation } from '@weiliang0121/capix-invocation';
|
|
2
|
+
import type { ChildContract } from '@weiliang0121/capix-contracts';
|
|
3
|
+
import type { ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
4
|
+
import type { ChildBindingsBuilder } from './children/builder.js';
|
|
5
|
+
import type { InvocationChildReferences } from './children/references.js';
|
|
6
|
+
export type AccessPhase = 'run' | `checkpoint:${string}`;
|
|
7
|
+
export declare class InvocationAccess<Input, Output, Context extends CallableContext<Input, Output>> {
|
|
8
|
+
#private;
|
|
9
|
+
private readonly invocation;
|
|
10
|
+
private readonly childBindingsBuilder;
|
|
11
|
+
readonly references: InvocationChildReferences;
|
|
12
|
+
constructor(invocation: Invocation<Input, Output, Context>, childBindingsBuilder: ChildBindingsBuilder);
|
|
13
|
+
enter(phase: AccessPhase, deps: ResourceRequirements, uses?: readonly ChildContract[]): {
|
|
14
|
+
base: Readonly<{
|
|
15
|
+
input: import("@weiliang0121/capix-contracts").Stable<Input>;
|
|
16
|
+
resources: object;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
observation: (event: import("@weiliang0121/capix-invocation").BusinessEvent) => void;
|
|
19
|
+
}>;
|
|
20
|
+
children: import("@weiliang0121/capix-contracts").ChildCalls<ChildContract> | import("@weiliang0121/capix-contracts").ResumeChildCalls<ChildContract>;
|
|
21
|
+
validate: () => void;
|
|
22
|
+
close: () => void;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});class InvocationAccess{static{__name(this,"InvocationAccess")}invocation;childBindingsBuilder;references;#resources;constructor(invocation,childBindingsBuilder){this.invocation=invocation,this.childBindingsBuilder=childBindingsBuilder,this.#resources=invocation.context.resources,this.references=childBindingsBuilder.references(invocation)}enter(phase,deps,uses){const resourcePhase=phase;this.#resources.activate(resourcePhase,deps);const context=this.invocation.context,round=context.progress.round;let open=!0;const validate=__name(()=>{try{if(this.invocation.requireActive(),!open)throw new Error("Work access window is closed");if(context.progress.round!==round)throw new Error("Work belongs to an inactive declaration round");if(context.progress.phase!=="execute")throw new Error("Work belongs to an inactive declaration phase")}catch(error){throw this.invocation.reject(error),error}},"validate"),children=this.childBindingsBuilder.build(this.invocation,{uses,validate,references:this.references,restoring:phase.startsWith("checkpoint:")}),base={input:context.currentInput,resources:this.#resources.view(deps,resourcePhase),signal:context.signal,observation:__name(event=>{validate(),this.invocation.observeBusiness(event)},"observation")},close=__name(()=>{open=!1,this.#resources.close(resourcePhase)},"close");return{base:Object.freeze(base),children,validate,close}}}export{InvocationAccess};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InvocationCapabilities } from '../construction/capabilities.js';
|
|
2
|
+
import { type ResolvedCallable, type AnyCallable } from './declarations.js';
|
|
3
|
+
import { type CallInstallation, type CallableCallsOptions } from './calls.js';
|
|
4
|
+
import type { Resources } from '../resource/resources.js';
|
|
5
|
+
import type { Interactions } from '@weiliang0121/capix-interaction';
|
|
6
|
+
export interface CallableBuildPlan<Structure extends AnyCallable, Options> {
|
|
7
|
+
readonly root: ResolvedCallable<Structure>;
|
|
8
|
+
readonly calls: CallInstallation<Options>;
|
|
9
|
+
}
|
|
10
|
+
export declare class CallableBinder {
|
|
11
|
+
private readonly capabilities;
|
|
12
|
+
constructor(capabilities?: InvocationCapabilities);
|
|
13
|
+
bind<Structure extends AnyCallable, Options extends object>(structure: Structure, resources: Resources<Options>, interactions?: Interactions, options?: CallableCallsOptions<Options>): CallableBuildPlan<Structure, Options>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{collectObservationProvides}from"./resources.js";import{resolveDeclaration}from"./declarations.js";import{CallableCalls}from"./calls.js";import{bindCallableHooks}from"./hooks.js";import{ResourceInstallation}from"../resource/installation.js";class CallableBinder{static{__name(this,"CallableBinder")}capabilities;constructor(capabilities={}){this.capabilities=capabilities}bind(structure,resources,interactions,options={}){const plan=resources.snapshot(structure),root=resolveDeclaration(structure,{observationProvides:collectObservationProvides(this.capabilities.observations),observations:this.capabilities.observations,childResources:plan.refinements,resourceScopes:new Map(plan.scopes.map(scope=>[scope.structure,scope.registrations.map(entry=>entry.offer)]))}),supply=new ResourceInstallation(root,plan,interactions),hooks=bindCallableHooks(root,options.hooks??[]);return Object.freeze({root,calls:new CallableCalls(supply,hooks,options.validate?.bind(options))})}}export{CallableBinder};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { InvocationOutputReceiver } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { ResourceInstallation } from '../resource/installation.js';
|
|
3
|
+
import type { ResourceSupply } from '@weiliang0121/capix-resources';
|
|
4
|
+
import type { ProgressReceiver } from '@weiliang0121/capix-changes';
|
|
5
|
+
import { type InvocationProgress } from '@weiliang0121/capix-invocation';
|
|
6
|
+
import type { CallableInvocationStarted } from '../construction/invocation.js';
|
|
7
|
+
import type { AnyCallable } from './declarations.js';
|
|
8
|
+
import type { CallableHooks, CallableHookBinding } from './hooks.js';
|
|
9
|
+
import { type CallableFeedback, type CallableFeedbackBinding } from '../construction/feedback.js';
|
|
10
|
+
export interface PreparedCall {
|
|
11
|
+
readonly supply?: ResourceSupply;
|
|
12
|
+
readonly started?: CallableInvocationStarted<any, any, any>;
|
|
13
|
+
readonly progress?: ProgressReceiver<InvocationProgress>;
|
|
14
|
+
readonly output?: InvocationOutputReceiver<any, any>;
|
|
15
|
+
}
|
|
16
|
+
export interface CallInstallation<Options> {
|
|
17
|
+
begin(options: Options, feedback?: CallableFeedback): CallableCallScope<Options>;
|
|
18
|
+
require(value: object | undefined): CallableCallScope<Options>;
|
|
19
|
+
prepare(structure: AnyCallable, input: unknown, options: Options, restoring: boolean, inherited?: ResourceSupply, signal?: AbortSignal): PreparedCall;
|
|
20
|
+
}
|
|
21
|
+
export interface CallableCallsOptions<Options> {
|
|
22
|
+
readonly hooks?: readonly CallableHookBinding<Options>[];
|
|
23
|
+
readonly validate?: (options: Options) => undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare class CallableCallScope<Options = unknown> {
|
|
26
|
+
private readonly owner;
|
|
27
|
+
private readonly options;
|
|
28
|
+
readonly feedback?: CallableFeedbackBinding;
|
|
29
|
+
constructor(owner: CallInstallation<Options>, options: Options, feedback?: CallableFeedback);
|
|
30
|
+
belongsTo(owner: CallInstallation<Options>): boolean;
|
|
31
|
+
prepare(structure: AnyCallable, input: unknown, restoring: boolean, inherited?: ResourceSupply, signal?: AbortSignal): PreparedCall;
|
|
32
|
+
}
|
|
33
|
+
export declare class CallableCalls<Options> implements CallInstallation<Options> {
|
|
34
|
+
private readonly resources;
|
|
35
|
+
private readonly hooks;
|
|
36
|
+
private readonly validate?;
|
|
37
|
+
constructor(resources: ResourceInstallation<Options>, hooks: CallableHooks<Options>, validate?: ((options: Options) => undefined) | undefined);
|
|
38
|
+
begin(options: Options, feedback?: CallableFeedback): CallableCallScope<Options>;
|
|
39
|
+
require(value: object | undefined): CallableCallScope<Options>;
|
|
40
|
+
prepare(structure: AnyCallable, input: unknown, options: Options, restoring: boolean, inherited?: ResourceSupply, signal?: AbortSignal): PreparedCall;
|
|
41
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{requireNotCancelled}from"@weiliang0121/capix-invocation";import{bindCallableFeedback}from"../construction/feedback.js";class CallableCallScope{static{__name(this,"CallableCallScope")}owner;options;feedback;constructor(owner,options,feedback){this.owner=owner,this.options=options,this.feedback=feedback?bindCallableFeedback(feedback):void 0,Object.freeze(this)}belongsTo(owner){return this.owner===owner}prepare(structure,input,restoring,inherited,signal){return this.owner.prepare(structure,input,this.options,restoring,inherited,signal)}}class CallableCalls{static{__name(this,"CallableCalls")}resources;hooks;validate;constructor(resources,hooks,validate){this.resources=resources,this.hooks=hooks,this.validate=validate}begin(options,feedback){const result=this.validate?.(options);if(result!==void 0)throw Promise.resolve(result).catch(()=>{}),new TypeError("Runner validation must return undefined synchronously");return new CallableCallScope(this,options,feedback)}require(value){if(!(value instanceof CallableCallScope)||!value.belongsTo(this))throw new Error("Call construction belongs to another binding installation");return value}prepare(structure,input,options,restoring,inherited,signal){signal&&requireNotCancelled(signal),this.hooks.validate(structure,input,options),signal&&requireNotCancelled(signal);const supply=this.resources.open(structure,input,options,inherited);return signal&&requireNotCancelled(signal),{supply,...this.hooks.open(structure,input,options,restoring,signal)}}}export{CallableCallScope,CallableCalls};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkpointList<Value>(length: () => number, read: (index: number) => Value, validate: () => void): readonly Value[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});function checkpointList(length,read,validate){const index=__name(key=>{if(typeof key!="string"||!/^(0|[1-9]\d*)$/.test(key))return;const value=Number(key);return Number.isSafeInteger(value)&&value<4294967295?value:void 0},"index"),reject=__name(()=>{throw validate(),new TypeError("Checkpoint reference queries are read-only")},"reject");return new Proxy([],{get(target,key,receiver){if(validate(),key==="length")return length();const position=index(key);return position!==void 0?position<length()?read(position):void 0:Reflect.get(target,key,receiver)},has(target,key){validate();const position=index(key);return position===void 0?Reflect.has(target,key):position<length()},ownKeys(){return validate(),[...Array.from({length:length()},(_,position)=>String(position)),"length"]},getOwnPropertyDescriptor(target,key){if(validate(),key==="length")return{...Reflect.getOwnPropertyDescriptor(target,key),value:length()};const position=index(key);return position===void 0?Reflect.getOwnPropertyDescriptor(target,key):position<length()?{configurable:!0,enumerable:!0,writable:!1,value:read(position)}:void 0},set:reject,deleteProperty:reject,defineProperty:reject,setPrototypeOf:reject,preventExtensions:reject})}__name(checkpointList,"checkpointList");export{checkpointList};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CheckpointReferences } from '@weiliang0121/capix-checkpoint';
|
|
2
|
+
import { type DecodedCheckpointFrame } from '@weiliang0121/capix-invocation';
|
|
3
|
+
import type { CheckpointFacts } from '@weiliang0121/capix-contracts';
|
|
4
|
+
import type { BoundChildren } from './children/bound.js';
|
|
5
|
+
import { BoundReceptions } from './receptions.js';
|
|
6
|
+
export declare function savedCheckpointFacts(frame: DecodedCheckpointFrame, references: CheckpointReferences, children: BoundChildren, receptions?: BoundReceptions): {
|
|
7
|
+
readonly facts: CheckpointFacts<unknown>;
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{decodeCheckpointDiagnostic}from"@weiliang0121/capix-invocation";import{BoundReceptions}from"./receptions.js";import{checkpointList}from"./checkpoint-list.js";function savedCheckpointFacts(frame,references,children,receptions=new BoundReceptions([],children)){let active=!0;const requireOpen=__name(()=>{if(!active)throw new Error("Saved fact queries are only valid during the synchronous checkpoint check")},"requireOpen");let fallback;const lookup=__name(id=>(requireOpen(),frame.child?frame.child(id):(fallback??=new Map(frame.children.map(child=>[child.identity.contextId,child])),fallback.get(id))),"lookup"),entries=new WeakMap,byId=new Map,materialize=__name(saved=>{requireOpen();const existing=byId.get(saved.identity.contextId);if(existing)return existing;const definition=children.at(saved.target.position),ref=Object.freeze({}),state=saved.state,returned=state.kind==="waiting"?void 0:state.kind==="returned"?Object.freeze({status:"succeeded",output:state.output}):Object.freeze({status:"failed",diagnostic:decodeCheckpointDiagnostic(state.error),failure:state.failure}),reception=state.kind==="failed"&&state.reception?Object.freeze({status:"handled",value:state.reception.output}):state.kind!=="returned"?Object.freeze({status:"pending"}):state.reception.kind==="accepted"?Object.freeze({status:"accepted",value:state.reception.output}):state.reception.kind==="failed"?Object.freeze({status:"failed",diagnostic:decodeCheckpointDiagnostic(state.reception.error),failure:state.reception.failure}):Object.freeze({status:state.reception.kind}),fact=Object.freeze({ref,...saved.key!==void 0?{key:saved.key}:{},parentRound:round(saved.round),order:saved.order,input:saved.input,returned,reception,...state.kind!=="waiting"?{progress:Object.freeze({...state.progress,round:round(state.progress.round)})}:{}}),entry=Object.freeze({saved,ref,definition,fact});return entries.set(ref,entry),byId.set(saved.identity.contextId,entry),entry},"materialize"),requireEntry=__name(ref=>{requireOpen();const entry=ref&&typeof ref=="object"?entries.get(ref):void 0;if(!entry)throw new Error("Unknown or foreign saved child reference");return entry},"requireEntry"),selected=__name(wire=>{const saved=lookup(wire.contextId),entry=saved?materialize(saved):void 0;if(!entry||!saved||wire.parentContextId!==frame.owner.contextId||wire.parentRound!==saved.round||wire.order!==saved.order||wire.target.position!==saved.target.position)throw new Error("Saved child reference differs from the checked frame");return entry},"selected"),facts=Object.freeze({get:__name(ref=>requireEntry(ref).fact,"get"),accepted:__name((ref,contract)=>{const entry=requireEntry(ref),binding=receptions.require(contract,entry.definition),state=entry.saved.state;if(state.kind!=="returned"||state.reception.kind!=="accepted"||state.reception.contract?.position!==binding.position)throw new Error("Saved child has no accepted value under this reception contract");return state.reception.output},"accepted"),handled:__name((ref,contract)=>{const entry=requireEntry(ref),binding=receptions.require(contract,entry.definition),state=entry.saved.state;if(state.kind!=="failed"||state.reception?.kind!=="handled"||state.reception.contract?.position!==binding.position)throw new Error("Saved child has no handled value under this reception contract");return state.reception.output},"handled"),require:__name((definition,ref)=>{const entry=requireEntry(ref);if(entry.definition!==definition)throw new Error("Saved child reference belongs to a different declaration");return entry.fact},"require"),list:__name((definition,query)=>(requireOpen(),Object.freeze(frame.children.map(materialize).filter(entry=>entry.definition===definition&&(query?.parentRound===void 0||entry.saved.round===query.parentRound)).map(entry=>entry.fact))),"list"),requireUnique:__name((definition,query)=>{const matches=facts.list(definition,query);if(matches.length!==1)throw new Error("Expected exactly one saved direct child fact");return matches[0]},"requireUnique"),values:__name(()=>(requireOpen(),Object.freeze(frame.children.map(saved=>materialize(saved).fact))),"values")}),slots={};for(const[key,value]of Object.entries(references)){const list=Array.isArray(value)?checkpointList(()=>value.length,index=>selected(value[index]).fact,requireOpen):void 0;Object.defineProperty(slots,key,{enumerable:!0,get(){return requireOpen(),list??selected(value).fact}})}Object.freeze(slots);let continuation;if(frame.continuation){const{origin,...accepted}=frame.continuation;continuation=Object.freeze({...accepted,...origin?{origin:origin.kind==="self"?origin:Object.freeze({kind:origin.kind,child:selected(origin.child).ref})}:{}})}return Object.freeze({facts:Object.freeze({initialInput:frame.input,input:frame.currentInput,round:round(frame.round),...continuation?{continuation}:{},references:slots,children:facts}),close(){active=!1}})}__name(savedCheckpointFacts,"savedCheckpointFacts");function round(value){if(value!==1&&value!==2)throw new Error("Invalid saved invocation round");return value}__name(round,"round");export{savedCheckpointFacts};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChildCalls, ChildContract, ResumeChildCalls } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import { type Invocation } from '@weiliang0121/capix-invocation';
|
|
3
|
+
import type { BoundChildren } from './bound.js';
|
|
4
|
+
import type { InvocationChildReferences } from './references.js';
|
|
5
|
+
import type { BoundReceptions } from '../receptions.js';
|
|
6
|
+
export type ChildBindingsParent = Invocation<any, any, any>;
|
|
7
|
+
interface ChildAccessOptions {
|
|
8
|
+
readonly children: BoundChildren;
|
|
9
|
+
readonly names?: ReadonlyMap<string, ChildContract>;
|
|
10
|
+
readonly receptions: BoundReceptions;
|
|
11
|
+
readonly parent: ChildBindingsParent;
|
|
12
|
+
readonly allowed: ReadonlySet<ChildContract>;
|
|
13
|
+
readonly validate: () => void;
|
|
14
|
+
readonly references: InvocationChildReferences;
|
|
15
|
+
readonly restoring: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class InvocationChildBindings {
|
|
18
|
+
private readonly options;
|
|
19
|
+
readonly port: ChildCalls | ResumeChildCalls;
|
|
20
|
+
constructor(options: ChildAccessOptions);
|
|
21
|
+
private invoke;
|
|
22
|
+
private bindReception;
|
|
23
|
+
private receiveTarget;
|
|
24
|
+
private create;
|
|
25
|
+
private open;
|
|
26
|
+
private resume;
|
|
27
|
+
private handle;
|
|
28
|
+
private requireAllowed;
|
|
29
|
+
private checkActive;
|
|
30
|
+
private guard;
|
|
31
|
+
private perform;
|
|
32
|
+
private deliver;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{createCallableInvocation,restoreCallableInvocation}from"../../construction/calls.js";import{InvocationCancelled,ChildCallFailure,combineOutputReceivers}from"@weiliang0121/capix-invocation";class InvocationChildBindings{static{__name(this,"InvocationChildBindings")}options;port;constructor(options){this.options=options,this.port=Object.freeze({...Object.fromEntries([...options.names??[]].filter(([,definition])=>options.allowed.has(definition)).map(([name,definition])=>[name,Object.freeze({invoke:__name((input,reception)=>this.invoke(definition,input,reception??{}),"invoke")})])),invoke:this.invoke.bind(this),create:this.create.bind(this),open:this.open.bind(this),facts:options.references.facts,...options.restoring?{resume:this.resume.bind(this)}:{}})}invoke(definition,input,options={}){return this.perform(()=>this.options.parent.children.accepting(async()=>{if(this.requireAllowed(definition),options.delta!==void 0&&typeof options.delta!="function")throw new TypeError("Delta receiver must be a function");const{succeeded,failed,contract}=this.bindReception(definition,options),delta=options.delta?.bind(options),output=options.output,outputReceive=output?.receive.bind(output),outputFailed=output?.failed?.bind(output),outputReceiver=combineOutputReceivers(delta?{receive:__name(event=>{if(event.kind!=="delta")return;const returned=delta(event.delta);if(returned!==void 0)throw Promise.resolve(returned).catch(()=>{}),new TypeError("Delta receivers must return undefined synchronously")},"receive")}:void 0,outputReceive?{receive:outputReceive,failed:outputFailed}:void 0),child=createCallableInvocation(this.options.children.get(definition),this.options.parent,input,{key:options.key,declarationPosition:this.options.children.position(definition),receiveFailure:!!failed,...outputReceiver?{output:outputReceiver}:{}}),relation=this.options.parent.children.get(child);return this.receiveTarget(relation,succeeded,failed,contract)}))}bindReception(definition,options){const receiver=options.result;if(receiver?.succeeded!==void 0&&typeof receiver.succeeded!="function")throw new TypeError("Success receiver must be a function");if(receiver?.failed!==void 0&&typeof receiver.failed!="function")throw new TypeError("Failure receiver must be a function");const contract=options.reception?this.options.receptions.require(options.reception,definition):void 0;return{succeeded:receiver?.succeeded?.bind(receiver),failed:receiver?.failed?.bind(receiver),contract}}async receiveTarget(relation,succeeded,failed,contract){const child=relation.invocation;try{await child.run()}catch(error){try{this.options.parent.requireActive(),this.checkActive()}catch(windowFailure){const sourceFailure=relation.returned?.status==="failed"?relation.returned.error:error;throw sourceFailure===windowFailure||sourceFailure instanceof InvocationCancelled&&windowFailure instanceof InvocationCancelled?windowFailure:new AggregateError([sourceFailure,windowFailure],"Child operation failed after its reception window became unavailable",{cause:sourceFailure})}if(!failed||relation.returned?.status!=="failed"||!relation.returned.failure?.receptionAllowed||relation.returned.error instanceof InvocationCancelled||child.context.progress.round===0||["setup","control","observation"].includes(relation.returned.failure?.phase??"setup"))throw error;return relation.handle(failure=>(this.checkActive(),failed(failure)),contract)}return relation.accept(output=>(this.checkActive(),succeeded?succeeded(output):output),contract)}create(definition,input,options={}){return this.guard(()=>{this.requireAllowed(definition);const child=createCallableInvocation(this.options.children.get(definition),this.options.parent,input,{...options,declarationPosition:this.options.children.position(definition)});return this.handle(this.options.references.forTarget(definition,child))})}open(ref){return this.guard(()=>this.handle(ref))}resume(ref){return this.guard(()=>{if(!this.options.restoring)throw new Error("Child resume is available only in a checkpoint resume phase");const entry=this.options.references.require(ref);this.requireAllowed(entry.definition);const position=this.options.children.position(entry.definition),contextId=entry.relation.invocation.context.id;return this.options.parent.restoreChild(position,contextId,()=>restoreCallableInvocation(this.options.children.get(entry.definition),this.options.parent,contextId,{declarationPosition:position})),this.handle(ref)})}handle(ref){const entry=this.options.references.require(ref),relation=entry.relation,access=this;function accept(first,receive){return access.perform(()=>{if(first!==void 0&&typeof first!="function"&&(typeof first!="object"||first===null))throw new Error("Invalid child reception contract or callback");const contract=typeof first=="object"&&first!==null?access.options.receptions.require(first,entry.definition):void 0,callback=typeof first=="function"?first:receive;if(contract&&typeof callback!="function")throw new Error("Typed reception requires a callback");return relation.accept(output=>(access.checkActive(),callback?callback(output):output),contract)})}return __name(accept,"accept"),Object.freeze({ref,...relation.key!==void 0?{key:relation.key}:{},run:__name(()=>this.perform(async()=>(relation.returned||this.requireAllowed(entry.definition),await relation.invocation.run())),"run"),invoke:__name((options={})=>this.perform(()=>this.options.parent.children.accepting(async()=>{relation.returned||this.requireAllowed(entry.definition);const{succeeded,failed,contract}=this.bindReception(entry.definition,options);return failed&&!relation.returned&&relation.receiveFailures(),this.receiveTarget(relation,succeeded,failed,contract)})),"invoke"),accept})}requireAllowed(definition){if(!this.options.allowed.has(definition))throw new Error("Child definition is not declared in this phase uses")}checkActive(){this.options.parent.requireHealthy(),this.options.validate(),this.options.parent.context.requireActive()}guard(action){try{return this.checkActive(),action()}catch(error){throw this.options.parent.reject(error),error}}perform(action){const delivery=this.deliver(action);return delivery.catch(()=>{}),delivery}async deliver(action){try{return this.checkActive(),await action()}catch(error){throw error instanceof ChildCallFailure||this.options.parent.reject(error),error}}}export{InvocationChildBindings};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ChildCallable, NamedMembers } from '@weiliang0121/capix-structure';
|
|
2
|
+
import type { ChildContract } from '@weiliang0121/capix-contracts';
|
|
3
|
+
import type { CheckpointBinding } from '@weiliang0121/capix-invocation';
|
|
4
|
+
import type { ResolvedChild } from '../declarations.js';
|
|
5
|
+
export declare class BoundChildren {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(children: readonly ResolvedChild[], names?: NamedMembers);
|
|
8
|
+
names(): ReadonlyMap<string, ChildContract>;
|
|
9
|
+
definitions(): readonly ChildCallable[];
|
|
10
|
+
position(definition: ChildContract): number;
|
|
11
|
+
at(position: number): ChildCallable;
|
|
12
|
+
checkpointLayout(): readonly Readonly<{
|
|
13
|
+
kind: "group" | "node";
|
|
14
|
+
binding: CheckpointBinding | undefined;
|
|
15
|
+
}>[];
|
|
16
|
+
get<Definition extends ChildContract>(definition: Definition): ChildCallable;
|
|
17
|
+
checkpoint(definition: ChildContract): CheckpointBinding | undefined;
|
|
18
|
+
checkUses(definitions: readonly ChildContract[]): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{checkMemberName}from"@weiliang0121/capix-structure/construction";class BoundChildren{static{__name(this,"BoundChildren")}#entries;#definitions;#names;constructor(children,names={}){this.#entries=new Map(children.map(child=>[child.definition,{kind:child.declaration.kind,value:child.definition,checkpoint:child.declaration.checkpoint}])),this.#definitions=Object.freeze([...new Set(children.map(child=>child.definition))]);for(const[name,definition]of Object.entries(names))if(checkMemberName(name),!this.#entries.has(definition))throw new Error("Named member is outside its owner");this.#names=new Map(Object.entries(names))}names(){return this.#names}definitions(){return this.#definitions}position(definition){const position=this.#definitions.findIndex(candidate=>candidate===definition);if(position<0)throw new Error("Child definition is not declared in this binding");return position}at(position){const definition=this.#definitions[position];if(!Number.isSafeInteger(position)||!definition)throw new Error("Child declaration position is not registered");return definition}checkpointLayout(){return Object.freeze([...this.#entries.values()].map(entry=>Object.freeze({kind:entry.kind,binding:entry.checkpoint})))}get(definition){const entry=this.#entries.get(definition);if(!entry)throw new Error("Child definition is not declared in this binding");return entry.value}checkpoint(definition){const entry=this.#entries.get(definition);if(!entry)throw new Error("Child definition is not declared in this binding");return entry.checkpoint}checkUses(definitions){for(const definition of definitions)if(!this.#entries.has(definition))throw new Error("Declaration uses a child outside its owner")}}export{BoundChildren};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChildCalls, ChildContract, ResumeChildCalls } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { BoundChildren } from './bound.js';
|
|
3
|
+
import { type ChildBindingsParent } from './binding.js';
|
|
4
|
+
import { InvocationChildReferences } from './references.js';
|
|
5
|
+
import { BoundReceptions } from '../receptions.js';
|
|
6
|
+
export interface ChildBindingsBuildOptions {
|
|
7
|
+
readonly uses?: readonly ChildContract[];
|
|
8
|
+
readonly validate: () => void;
|
|
9
|
+
readonly references: InvocationChildReferences;
|
|
10
|
+
readonly restoring?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class ChildBindingsBuilder {
|
|
13
|
+
readonly children: BoundChildren;
|
|
14
|
+
readonly receptions: BoundReceptions;
|
|
15
|
+
constructor(children: BoundChildren, receptions?: BoundReceptions);
|
|
16
|
+
references(parent: ChildBindingsParent): InvocationChildReferences;
|
|
17
|
+
build(parent: ChildBindingsParent, options: ChildBindingsBuildOptions): ChildCalls | ResumeChildCalls;
|
|
18
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{InvocationChildBindings}from"./binding.js";import{InvocationChildReferences}from"./references.js";import{BoundReceptions}from"../receptions.js";class ChildBindingsBuilder{static{__name(this,"ChildBindingsBuilder")}children;receptions;constructor(children,receptions=new BoundReceptions([],children)){this.children=children,this.receptions=receptions}references(parent){return new InvocationChildReferences(parent,this.children,this.receptions)}build(parent,options){try{const definitions=options.uses??this.children.definitions();return this.children.checkUses(definitions),new InvocationChildBindings({children:this.children,names:this.children.names(),receptions:this.receptions,parent,allowed:new Set(definitions),validate:options.validate,references:options.references,restoring:options.restoring??!1}).port}catch(error){throw parent.reject(error),error}}}export{ChildBindingsBuilder};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ChildContract, ChildReference, ChildFacts, ExceptionOrigin, ContinuationFact } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import { type Invocation, type InvocationRelation, type InvocationTarget, type InvocationExceptionOrigin, type CheckpointContinuationFact } from '@weiliang0121/capix-invocation';
|
|
3
|
+
import type { CheckpointReference } from '@weiliang0121/capix-checkpoint';
|
|
4
|
+
import type { BoundChildren } from './bound.js';
|
|
5
|
+
import type { BoundReceptions } from '../receptions.js';
|
|
6
|
+
interface ReferenceEntry {
|
|
7
|
+
readonly definition: ChildContract;
|
|
8
|
+
readonly relation: InvocationRelation;
|
|
9
|
+
readonly ref: ChildReference;
|
|
10
|
+
}
|
|
11
|
+
export declare class InvocationChildReferences {
|
|
12
|
+
#private;
|
|
13
|
+
private readonly parent;
|
|
14
|
+
private readonly children;
|
|
15
|
+
private readonly receptions;
|
|
16
|
+
readonly facts: ChildFacts;
|
|
17
|
+
constructor(parent: Invocation<any, any, any>, children: BoundChildren, receptions: BoundReceptions);
|
|
18
|
+
forTarget<D extends ChildContract>(definition: D, target: InvocationTarget): ChildReference<D>;
|
|
19
|
+
require(ref: ChildReference): ReferenceEntry;
|
|
20
|
+
fromSaved(value: CheckpointReference): ChildReference;
|
|
21
|
+
encode(ref: ChildReference): CheckpointReference;
|
|
22
|
+
origin(origin: InvocationExceptionOrigin): ExceptionOrigin;
|
|
23
|
+
continuation(value: CheckpointContinuationFact | undefined): ContinuationFact | undefined;
|
|
24
|
+
private values;
|
|
25
|
+
private entry;
|
|
26
|
+
private fact;
|
|
27
|
+
private reject;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{failureFact,failureDiagnostic,isInvocationCancelled}from"@weiliang0121/capix-invocation";class InvocationChildReferences{static{__name(this,"InvocationChildReferences")}parent;children;receptions;#entries=new WeakMap;#relations=new Map;facts;constructor(parent,children,receptions){this.parent=parent,this.children=children,this.receptions=receptions,this.facts=Object.freeze({get:__name(ref=>this.fact(this.require(ref)),"get"),accepted:__name((ref,contract)=>{try{const entry=this.require(ref),binding=this.receptions.require(contract,entry.definition),reception=entry.relation.reception;if(reception.status!=="accepted"||reception.contract!==binding)throw new Error("Child has no accepted value under this reception contract");return reception.output}catch(error){throw this.parent.reject(error),error}},"accepted"),handled:__name((ref,contract)=>{try{const entry=this.require(ref),binding=this.receptions.require(contract,entry.definition),reception=entry.relation.reception;if(reception.status!=="handled"||reception.contract!==binding)throw new Error("Child has no handled value under this reception contract");return reception.output}catch(error){throw this.parent.reject(error),error}},"handled"),require:__name((definition,ref)=>{const entry=this.require(ref);return entry.definition!==definition?this.reject(new Error("Child reference belongs to a different declaration")):this.fact(entry)},"require"),list:__name((definition,query)=>Object.freeze(this.values().filter(entry=>entry.definition===definition&&(query?.parentRound===void 0||entry.relation.round===query.parentRound)).map(entry=>this.fact(entry))),"list"),requireUnique:__name((definition,query)=>{const matches=this.facts.list(definition,query);return matches.length!==1?this.reject(new Error("Expected exactly one direct child fact")):matches[0]},"requireUnique"),values:__name(()=>Object.freeze(this.values().map(entry=>this.fact(entry))),"values")})}forTarget(definition,target){const relation=this.parent.children.get(target),entry=this.entry(relation);return entry.definition!==definition?this.reject(new Error("Child declaration position differs from its binding")):entry.ref}require(ref){const entry=ref&&typeof ref=="object"?this.#entries.get(ref):void 0;return entry||this.reject(new Error("Unknown or foreign child reference"))}fromSaved(value){const relation=this.parent.children.byContextId(value.contextId);return!relation||value.parentContextId!==this.parent.context.id||relation.round!==value.parentRound||relation.order!==value.order||relation.declarationPosition!==value.target.position?this.reject(new Error("Saved child reference does not match the installed relationship")):this.entry(relation).ref}encode(ref){const entry=this.require(ref),relation=entry.relation;return Object.freeze({contextId:relation.invocation.context.id,parentContextId:this.parent.context.id,parentRound:relation.round,order:relation.order,target:Object.freeze({position:this.children.position(entry.definition)})})}origin(origin){if(origin.kind==="self")return origin;const identity=origin.child,relation=this.parent.children.values().find(item=>item.invocation.context.id===identity.childContextId);return!relation||identity.parentContextId!==this.parent.context.id||identity.parentRound!==relation.round||identity.order!==relation.order?this.reject(new Error("Exception source is not an exact direct child relationship")):Object.freeze({kind:origin.kind,child:this.entry(relation).ref})}continuation(value){return value?Object.freeze({fromRound:value.fromRound,stage:value.stage,reason:value.reason,...value.origin?{origin:this.origin(value.origin)}:{}}):void 0}values(){return this.parent.children.values().map(relation=>this.entry(relation))}entry(relation){const existing=this.#relations.get(relation);if(existing)return existing;const position=relation.declarationPosition;if(position===void 0)return this.reject(new Error("Direct child has no registered declaration position"));const definition=this.children.at(position),ref=Object.freeze({}),entry=Object.freeze({definition,relation,ref});return this.#relations.set(relation,entry),this.#entries.set(ref,entry),entry}fact(entry){const relation=entry.relation,context=relation.invocation.context,returned=relation.returned,signal="signal"in context?context.signal:void 0,result=returned?.status==="succeeded"?Object.freeze({status:"succeeded",output:returned.output}):returned?signal instanceof AbortSignal&&isInvocationCancelled(returned.error,signal)?Object.freeze({status:"cancelled",diagnostic:returned.diagnostic??failureDiagnostic(returned.error)}):Object.freeze({status:"failed",diagnostic:returned.diagnostic??failureDiagnostic(returned.error),...returned.failure?{failure:Object.freeze(failureFact(returned.failure))}:{}}):void 0,reception=relation.reception,received=reception.status==="accepted"||reception.status==="handled"?Object.freeze({status:reception.status,value:reception.output}):reception.status==="failed"?Object.freeze({status:"failed",diagnostic:reception.diagnostic??failureDiagnostic(reception.error),...reception.failure?{failure:Object.freeze(failureFact(reception.failure))}:{}}):Object.freeze({status:reception.status});return Object.freeze({ref:entry.ref,...relation.key?{key:relation.key}:{},parentRound:relation.round,order:relation.order,input:context.input,returned:result,reception:received,...context.progress.round?{progress:Object.freeze({round:context.progress.round,currentInput:context.currentInput,phase:context.progress.phase})}:{}})}reject(error){throw this.parent.reject(error),error}}export{InvocationChildReferences};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CallableContext, InvocationWork } from '@weiliang0121/capix-invocation';
|
|
2
|
+
import type { ResourceRequirements, ResourceRefinement, ResourceIdentity } from '@weiliang0121/capix-resources';
|
|
3
|
+
import type { BoundChildren } from './children/bound.js';
|
|
4
|
+
import type { ObservationInstallation } from './observation.js';
|
|
5
|
+
import type { InvocationObservationDeclaration } from './observation.js';
|
|
6
|
+
import type { ChildResourceBinding } from './resources.js';
|
|
7
|
+
import type { AnyCallable } from './declarations.js';
|
|
8
|
+
import type { CallableSnapshot } from './snapshot.js';
|
|
9
|
+
import type { ChildCallable } from '@weiliang0121/capix-structure';
|
|
10
|
+
export interface ChildBindingOptions {
|
|
11
|
+
readonly observationProvides?: ResourceRequirements;
|
|
12
|
+
readonly observations?: readonly ObservationInstallation[];
|
|
13
|
+
readonly childResources?: readonly ChildResourceBinding[];
|
|
14
|
+
readonly sources?: readonly ChildCallable[];
|
|
15
|
+
readonly resourceScopes?: ReadonlyMap<AnyCallable, readonly ResourceIdentity[]>;
|
|
16
|
+
}
|
|
17
|
+
export interface CallableBinding<Input, Output, Resources extends object> {
|
|
18
|
+
readonly definition: AnyCallable;
|
|
19
|
+
readonly declaration: CallableSnapshot;
|
|
20
|
+
readonly children: BoundChildren;
|
|
21
|
+
readonly composite: boolean;
|
|
22
|
+
readonly deps: ResourceRequirements<Resources>;
|
|
23
|
+
readonly supply: ResourceRequirements;
|
|
24
|
+
readonly refinements?: readonly ResourceRefinement<Input>[];
|
|
25
|
+
readonly work: InvocationWork<Input, Output, CallableContext<Input, Output, Resources>>;
|
|
26
|
+
readonly observations: readonly InvocationObservationDeclaration[];
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChildCallable, CallableStructure, Composite } from '@weiliang0121/capix-structure';
|
|
2
|
+
import { type ResourceRequirements, type ResourceRefinement } from '@weiliang0121/capix-resources';
|
|
3
|
+
import type { ChildBindingOptions } from './contract.js';
|
|
4
|
+
import { type CallableSnapshot } from './snapshot.js';
|
|
5
|
+
import type { InvocationObservationDeclaration } from './observation.js';
|
|
6
|
+
export type AnyCallable = (CallableStructure<'scene'> & Composite) | ChildCallable;
|
|
7
|
+
export interface ResolvedCallable<Definition extends AnyCallable = AnyCallable> {
|
|
8
|
+
readonly kind: Definition['kind'];
|
|
9
|
+
readonly definition: Definition;
|
|
10
|
+
readonly declaration: CallableSnapshot;
|
|
11
|
+
readonly observations: readonly InvocationObservationDeclaration[];
|
|
12
|
+
readonly deps: ResourceRequirements;
|
|
13
|
+
readonly supply: ResourceRequirements;
|
|
14
|
+
readonly members: readonly ResolvedChild[];
|
|
15
|
+
readonly refinements?: readonly ResourceRefinement<any>[];
|
|
16
|
+
}
|
|
17
|
+
export type ResolvedChild = ResolvedCallable<ChildCallable>;
|
|
18
|
+
export declare function resolveDeclaration<Definition extends AnyCallable>(definition: Definition, options?: ChildBindingOptions): ResolvedCallable<Definition>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{resourceRequests,isResourceRefinement}from"@weiliang0121/capix-resources";import{collectDefinitionRequirements,collectResourceSupply}from"./resources.js";import{childKinds}from"@weiliang0121/capix-structure/construction";import{originalReception,snapshotDefinition,snapshotObservation}from"./snapshot.js";function resolveDeclaration(definition,options={}){const refinements=new Map;for(const binding of options.childResources??[]){if(refinements.has(binding.definition))throw new Error("Duplicate child resource binding");refinements.set(binding.definition,Object.freeze([...binding.refinements]))}const captures=new Set(options.sources??[]),encountered=new Set,path=new Set,observations=[],visit=__name((current,parent)=>{if(path.has(current))throw new Error("Cyclic member declaration");const allowed=parent&&childKinds[parent.kind];if(!Object.hasOwn(childKinds,current.kind)||allowed&&!allowed.includes(current.kind))throw new Error("Invalid member definition kind");const declaration=snapshotDefinition(current);observations.push({definition:current,parent:parent?.definition});const selectedObservations=selectObservations(current,options.observations),deps=collectDefinitionRequirements(declaration,options.observationProvides,selectedObservations),declaredMembers="members"in declaration?declaration.members??[]:[];checkCheckpointMembers(declaration,declaredMembers);const selected=refinements.get(current),node={kind:declaration.kind,definition:current,declaration,observations:selectedObservations,deps,refinements:selected};encountered.add(current),path.add(current);const members=declaredMembers.map(member=>visit(member,node));path.delete(current);const supply=collectSubtreeSupply(deps,members,captures,options.resourceScopes);return selected&&checkRefinements(supply,selected),Object.freeze({...node,supply,members:Object.freeze(members)})},"visit"),resolved=visit(definition);for(const binding of options.childResources??[])if(!encountered.has(binding.definition))throw new Error("Resource refinement requires a registered member");for(const target of captures)if(!encountered.has(target))throw new Error("Call source requires a registered member");for(const entry of observations)for(const observation of options.observations??[])observation.check?.(entry.definition,entry.parent);return resolved}__name(resolveDeclaration,"resolveDeclaration");function selectObservations(definition,installations){return Object.freeze((installations??[]).flatMap(installation=>(installation.declarations?.(definition)??[]).map(declaration=>Object.freeze({...snapshotObservation(declaration),installation}))))}__name(selectObservations,"selectObservations");function checkCheckpointMembers(declaration,members){const receptions=new Set;for(const reception of declaration.checkpoint?.receptions??[]){const original=originalReception(reception);if(receptions.has(original))throw new Error("Duplicate parent reception contract");if(receptions.add(original),!members.some(member=>member===reception.child))throw new Error("Reception targets a member outside its owner")}const points=declaration.checkpoint?.points??[],names=new Set;for(const point of points){if(!point.name||names.has(point.name))throw new Error("Checkpoint points need distinct registered names");names.add(point.name);for(const slot of Object.values(point.references))if(!members.some(member=>member===slot.definition))throw new Error("Checkpoint reference targets a member outside its owner")}const checkpointUses=points.flatMap(point=>[...point.resume.uses??[]]);for(const child of checkpointUses)if(!members.some(member=>member===child))throw new Error("Declaration uses a member outside its owner")}__name(checkCheckpointMembers,"checkCheckpointMembers");function collectSubtreeSupply(deps,members,captures,resourceScopes){const inherited=members.filter(member=>!captures.has(member.definition)).map(member=>{const local=new Set(resourceScopes?.get(member.definition)??[]);return Object.fromEntries(Object.entries(member.supply).filter(([,request])=>!local.has(request.offer)))});return collectResourceSupply([deps,...inherited])}__name(collectSubtreeSupply,"collectSubtreeSupply");function checkRefinements(supply,refinements){const offers=new Set(resourceRequests(supply).map(request=>request.offer)),seen=new Set;for(const refinement of refinements){if(!isResourceRefinement(refinement))throw new Error("Resource refinement was not issued by an offer");if(!offers.has(refinement.offer))throw new Error(`Refined resource is not requested: ${refinement.offer.name}`);if(seen.has(refinement.offer))throw new Error(`Duplicate resource refinement: ${refinement.offer.name}`);seen.add(refinement.offer)}}__name(checkRefinements,"checkRefinements");export{resolveDeclaration};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CallableInput, CallableOutput, CallableDelta, InvocationOutputReceiver } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { ProgressReceiver } from '@weiliang0121/capix-changes';
|
|
3
|
+
import { type InvocationProgress } from '@weiliang0121/capix-invocation';
|
|
4
|
+
import type { CallableInvocationStarted } from '../construction/invocation.js';
|
|
5
|
+
import type { AnyCallable, ResolvedCallable } from './declarations.js';
|
|
6
|
+
import type { PreparedCall } from './calls.js';
|
|
7
|
+
export interface CallableHookDeclaration<Structure extends AnyCallable, Options> {
|
|
8
|
+
readonly validate?: (input: CallableInput<Structure>, options: Options) => undefined;
|
|
9
|
+
readonly started?: (input: CallableInput<Structure>, options: Options) => CallableInvocationStarted<CallableInput<Structure>, CallableOutput<Structure>> | undefined;
|
|
10
|
+
readonly progress?: (input: CallableInput<Structure>, options: Options) => ProgressReceiver<InvocationProgress> | undefined;
|
|
11
|
+
readonly output?: (input: CallableInput<Structure>, options: Options) => InvocationOutputReceiver<CallableOutput<Structure>, CallableDelta<Structure>> | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface CallableHookBinding<Options = {}, Structure extends AnyCallable = AnyCallable> {
|
|
14
|
+
readonly structure: Structure;
|
|
15
|
+
readonly hooks: CallableHookDeclaration<Structure, Options>;
|
|
16
|
+
}
|
|
17
|
+
export declare function callableHooks<Structure extends AnyCallable, Options = {}>(structure: Structure, hooks: CallableHookDeclaration<NoInfer<Structure>, Options>): CallableHookBinding<Options, Structure>;
|
|
18
|
+
type HookAccess = Omit<PreparedCall, 'supply'>;
|
|
19
|
+
interface FixedHooks<Options> {
|
|
20
|
+
readonly validate?: (input: unknown, options: Options) => undefined;
|
|
21
|
+
readonly started?: (input: unknown, options: Options) => CallableInvocationStarted<any, any> | undefined;
|
|
22
|
+
readonly progress?: (input: unknown, options: Options) => ProgressReceiver<InvocationProgress> | undefined;
|
|
23
|
+
readonly output?: (input: unknown, options: Options) => InvocationOutputReceiver<any, any> | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare class CallableHooks<Options> {
|
|
26
|
+
private readonly registrations;
|
|
27
|
+
constructor(registrations: ReadonlyMap<AnyCallable, FixedHooks<Options>>);
|
|
28
|
+
validate(structure: AnyCallable, input: unknown, options: Options): void;
|
|
29
|
+
open(structure: AnyCallable, input: unknown, options: Options, restoring: boolean, signal?: AbortSignal): HookAccess;
|
|
30
|
+
}
|
|
31
|
+
export declare function bindCallableHooks<Options>(root: ResolvedCallable, registrations: readonly CallableHookBinding<Options>[]): CallableHooks<Options>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{requireNotCancelled}from"@weiliang0121/capix-invocation";function callableHooks(structure,hooks){return Object.freeze({structure,hooks})}__name(callableHooks,"callableHooks");class CallableHooks{static{__name(this,"CallableHooks")}registrations;constructor(registrations){this.registrations=registrations}validate(structure,input,options){const validated=this.registrations.get(structure)?.validate?.(input,options);if(validated!==void 0)throw Promise.resolve(validated).catch(()=>{}),new TypeError("Callable validation must return undefined synchronously")}open(structure,input,options,restoring,signal){const hooks=this.registrations.get(structure);if(!hooks)return{};const started=restoring?void 0:synchronous(hooks.started?.(input,options),"started");if(started!==void 0&&typeof started!="function")throw new TypeError("Callable started factory must return a callback or undefined");signal&&requireNotCancelled(signal);const progress=synchronous(hooks.progress?.(input,options),"progress");signal&&requireNotCancelled(signal);const output=synchronous(hooks.output?.(input,options),"output");return signal&&requireNotCancelled(signal),{started,progress,output}}}function bindCallableHooks(root,registrations){const members=new Set,visit=__name(current=>{members.add(current.definition);for(const child of current.members)visit(child)},"visit");visit(root);const fixed=new Map;for(const registration of registrations){if(!members.has(registration.structure))throw new Error("Call hooks require a structure in this scene");if(fixed.has(registration.structure))throw new Error("Duplicate callable hooks registration");const hooks=registration.hooks;fixed.set(registration.structure,Object.freeze({validate:hooks.validate?.bind(hooks),started:hooks.started?.bind(hooks),progress:hooks.progress?.bind(hooks),output:hooks.output?.bind(hooks)}))}return new CallableHooks(fixed)}__name(bindCallableHooks,"bindCallableHooks");function synchronous(value,hook){if(value!==null&&(typeof value=="object"||typeof value=="function")&&typeof value.then=="function")throw Promise.resolve(value).catch(()=>{}),new TypeError(`Callable ${hook} factory must be synchronous`);return value}__name(synchronous,"synchronous");export{CallableHooks,bindCallableHooks,callableHooks};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InvocationResources, type InvocationFact, type InvocationIdentity, type InvocationDescription, type InvocationObserver, InvocationObservation } from '@weiliang0121/capix-invocation';
|
|
2
|
+
import type { ObservationDeclaration, ObservationDeclarationScope } from '../definition/observation.js';
|
|
3
|
+
import { type ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
4
|
+
import type { DriverFact, DriverObserver } from '../observation/driver.js';
|
|
5
|
+
import type { EventConsumer } from '@weiliang0121/capix-changes';
|
|
6
|
+
export interface InvocationObservationDeclaration extends ObservationDeclaration<InvocationFact> {
|
|
7
|
+
readonly installation?: ObservationInstallation;
|
|
8
|
+
}
|
|
9
|
+
export interface InvocationObservationSetup {
|
|
10
|
+
readonly identity: InvocationIdentity;
|
|
11
|
+
readonly description?: InvocationDescription;
|
|
12
|
+
readonly declarations?: readonly InvocationObservationDeclaration[];
|
|
13
|
+
readonly resources: InvocationResources;
|
|
14
|
+
}
|
|
15
|
+
export interface ObservationInstallation {
|
|
16
|
+
declarations?(structure: ObservationDeclarationScope): readonly ObservationDeclaration<InvocationFact>[];
|
|
17
|
+
check?(definition: ObservationDeclarationScope, parent?: ObservationDeclarationScope): void;
|
|
18
|
+
readonly failure?: 'isolate' | 'propagate';
|
|
19
|
+
readonly provides?: ResourceRequirements;
|
|
20
|
+
bindDriver?(identity: Readonly<{
|
|
21
|
+
driverId: string;
|
|
22
|
+
}>): DriverObserver;
|
|
23
|
+
bindInvocation(setup: InvocationObservationSetup, parent?: InvocationObserver): InvocationObserver;
|
|
24
|
+
invalidate?(error: unknown): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function bindInvocationObservation(setup: InvocationObservationSetup, installations: readonly ObservationInstallation[] | undefined, parent?: InvocationObservation): InvocationObservation;
|
|
27
|
+
export declare function bindDriverObservation(driverId: string, installations?: readonly ObservationInstallation[]): EventConsumer<DriverFact>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{InvocationObservation,ObserverSession,publishSessions}from"@weiliang0121/capix-invocation";import{ResourceBinding,resourceRequests}from"@weiliang0121/capix-resources";function bindObservation(declaration,resources){const binding=ResourceBinding.fromSupply(declaration.deps,resources.supply);return fact=>{const access=binding.open();try{return declaration.observe(fact,access.endpoints)}finally{access.close()}}}__name(bindObservation,"bindObservation");function bindInvocationObservation(setup,installations,parent){const sessions=[],installed=new Map;if(!installations)return new InvocationObservation(sessions,installed);for(const installation of installations){const previous=parent?.sessionFor(installation);if(parent&&(!previous||!previous.available()))continue;const observer=installation.bindInvocation(setup,previous?.observer),session=new ObserverSession(observer,installation.failure??"isolate",error=>installation.invalidate?.(error),previous);installed.set(installation,session),sessions.push(session)}const suppliers=[...installed.values()],resources=setup.resources.supplement(suppliers.flatMap(session=>session.observer.resources?[session.observer.resources]:[]));for(const declaration of setup.declarations??[]){const owner=declaration.installation?installed.get(declaration.installation):void 0;if(declaration.installation&&!owner)continue;const requests=resourceRequests(declaration.deps);if(requests.some(request=>!resources.provides(request))&&requests.every(request=>resources.provides(request)||installations.some(installation=>resourceRequests(installation.provides??{}).some(provided=>provided.offer===request.offer))))continue;const dependencies=suppliers.filter(session=>session===owner||requests.some(request=>session.observer.resources?.provides(request))),observe=bindObservation(declaration,resources),available=__name(()=>dependencies.every(session=>session.available()),"available"),failure=declaration.failure??owner?.failure??(dependencies.some(session=>session.failure==="propagate")?"propagate":"isolate");sessions.push(new ObserverSession({observe,available},failure,error=>{for(const dependency of dependencies)dependency.stop(error)}))}return new InvocationObservation(sessions,installed)}__name(bindInvocationObservation,"bindInvocationObservation");function bindDriverObservation(driverId,installations=[]){const sessions=installations.flatMap(installation=>{const observer=installation.bindDriver?.(Object.freeze({driverId}));return observer?[new ObserverSession(observer,installation.failure??"isolate",error=>installation.invalidate?.(error))]:[]});return{publish:__name(fact=>publishSessions(sessions,observer=>observer.observe(fact)),"publish")}}__name(bindDriverObservation,"bindDriverObservation");export{bindDriverObservation,bindInvocationObservation};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChildContract, ReceptionDefinition, ReceptionRegistration } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { InvocationReceptionBinding } from '@weiliang0121/capix-invocation';
|
|
3
|
+
import type { BoundChildren } from './children/bound.js';
|
|
4
|
+
export declare class BoundReceptions {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(receptions: readonly ReceptionRegistration[], children: BoundChildren);
|
|
7
|
+
require<Definition extends ChildContract, Value>(reception: ReceptionDefinition<NoInfer<Definition>, Value>, child: Definition): InvocationReceptionBinding;
|
|
8
|
+
bindings(): readonly InvocationReceptionBinding[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{originalReception}from"./snapshot.js";class BoundReceptions{static{__name(this,"BoundReceptions")}#entries=new Map;#bindings;constructor(receptions,children){const bindings=[];for(const reception of receptions){const original=originalReception(reception);if(this.#entries.has(original))throw new Error("Duplicate parent reception contract");const value=reception.value,check=value.check.bind(value),binding=Object.freeze({position:bindings.length,childPosition:children.position(reception.child),check:__name(value2=>{const checked=check(value2);if(checked&&(typeof checked=="object"||typeof checked=="function")&&"then"in checked&&typeof checked.then=="function")throw Promise.resolve(checked).catch(()=>{}),new TypeError("Reception checks must return synchronously")},"check"),codec:Object.freeze({encode:value.encode.bind(value),decode:value.decode.bind(value)})});this.#entries.set(original,Object.freeze({child:reception.child,binding})),bindings.push(binding)}this.#bindings=Object.freeze(bindings)}require(reception,child){const entry=this.#entries.get(originalReception(reception));if(!entry)throw new Error("Reception contract is not registered by this parent");if(entry.child!==child)throw new Error("Reception contract belongs to a different child declaration");return entry.binding}bindings(){return this.#bindings}}export{BoundReceptions};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CallableDependencies } from '@weiliang0121/capix-structure/construction';
|
|
2
|
+
import { type ResourceRefinement, type ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
3
|
+
import type { ObservationDeclaration } from '../definition/observation.js';
|
|
4
|
+
import type { InvocationFact } from '@weiliang0121/capix-invocation';
|
|
5
|
+
import type { ChildCallable } from '@weiliang0121/capix-structure';
|
|
6
|
+
import type { CallableInput } from '@weiliang0121/capix-contracts';
|
|
7
|
+
type RefinableDefinition = ChildCallable;
|
|
8
|
+
export interface ChildResourceBinding {
|
|
9
|
+
readonly definition: RefinableDefinition;
|
|
10
|
+
readonly refinements: readonly ResourceRefinement<any>[];
|
|
11
|
+
}
|
|
12
|
+
export declare function bindChildResources<Definition extends RefinableDefinition>(definition: Definition, refinements: readonly ResourceRefinement<NoInfer<CallableInput<Definition>>>[]): ChildResourceBinding;
|
|
13
|
+
export declare function collectDefinitionRequirements(definition: CallableDependencies, observationProvides?: ResourceRequirements, observations?: readonly ObservationDeclaration<InvocationFact>[]): ResourceRequirements;
|
|
14
|
+
export declare function collectResourceSupply(requirements: readonly ResourceRequirements[]): ResourceRequirements;
|
|
15
|
+
export declare function collectObservationProvides(installations?: readonly {
|
|
16
|
+
readonly provides?: ResourceRequirements;
|
|
17
|
+
}[]): ResourceRequirements | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{callableDependencies}from"@weiliang0121/capix-structure/construction";import{isResourceRefinement,resourceRequests}from"@weiliang0121/capix-resources";function bindChildResources(definition,refinements){const offers=new Set;for(const refinement of refinements){if(!isResourceRefinement(refinement))throw new Error("Resource refinement was not issued by an offer");if(offers.has(refinement.offer))throw new Error(`Duplicate resource refinement: ${refinement.offer.name}`);offers.add(refinement.offer)}return Object.freeze({definition,refinements:Object.freeze([...refinements])})}__name(bindChildResources,"bindChildResources");function collectDefinitionRequirements(definition,observationProvides,observations=[]){const deps={...callableDependencies(definition)},observationOffers=new Set(resourceRequests(observationProvides??{}).map(request=>request.offer));for(const[index,declaration]of(observationProvides?observations:[]).entries())for(const[name,request]of Object.entries(declaration.deps))observationOffers.has(request.offer)||(deps[`observation.${index}.${name}`]=request);return Object.freeze(deps)}__name(collectDefinitionRequirements,"collectDefinitionRequirements");function collectResourceSupply(requirements){const supply={},offers=new Set;for(const deps of requirements)for(const request of resourceRequests(deps))offers.has(request.offer)||(offers.add(request.offer),supply[`supply.${offers.size-1}`]=request);return Object.freeze(supply)}__name(collectResourceSupply,"collectResourceSupply");function collectObservationProvides(installations){if(!installations)return;const provided={};for(const[index,installation]of installations.entries())for(const[name,request]of Object.entries(installation.provides??{}))provided[`${index}.${name}`]=request;return Object.freeze(provided)}__name(collectObservationProvides,"collectObservationProvides");export{bindChildResources,collectDefinitionRequirements,collectObservationProvides,collectResourceSupply};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CallableDescription, CallableRun, ChildCallable, NamedMembers } from '@weiliang0121/capix-structure';
|
|
2
|
+
import type { CallableKind } from '@weiliang0121/capix-contracts';
|
|
3
|
+
import type { ObservationDeclaration } from '../definition/observation.js';
|
|
4
|
+
import type { ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
5
|
+
import type { AnyCallable } from './declarations.js';
|
|
6
|
+
export interface CallableSnapshot<Input = any, Output = any, Kind extends CallableKind = any, Resources extends object = any, Delta = any> extends Omit<CallableDescription<Input, Output, Kind, Delta>, 'kind' | 'members'> {
|
|
7
|
+
readonly kind: Kind;
|
|
8
|
+
readonly deps: ResourceRequirements<Resources>;
|
|
9
|
+
readonly run: CallableRun<Input, Output, Kind, Resources, import('@weiliang0121/capix-structure').ChildContractsOf<Kind>, Delta>;
|
|
10
|
+
readonly members?: readonly ChildCallable[];
|
|
11
|
+
readonly names?: NamedMembers;
|
|
12
|
+
}
|
|
13
|
+
export declare function snapshotDefinition(definition: AnyCallable): CallableSnapshot;
|
|
14
|
+
export declare function originalReception(reception: object): object;
|
|
15
|
+
export declare function snapshotObservation<Fact>(declaration: ObservationDeclaration<Fact>): ObservationDeclaration<Fact>;
|
|
16
|
+
export declare function originalCheckpointPoint(point: object): object;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{checkMemberName}from"@weiliang0121/capix-structure/construction";function snapshotDefinition(definition){const members="members"in definition?definition.members:void 0,names="names"in definition?definition.names:void 0;if(definition.kind==="node"&&names!==void 0)throw new Error("Nodes cannot declare member names");for(const[name,member]of Object.entries(names??{}))if(checkMemberName(name),!members?.includes(member))throw new Error("Named member is outside its owner");if(definition.kind==="node"&&members!==void 0)throw new Error("Nodes cannot declare members");if(definition.kind==="node"&&definition.checkpoint?.receptions!==void 0)throw new Error("Nodes cannot declare checkpoint receptions");for(const field of["setRun","setDefinition","accept","exceptions","raises","maxRounds","uses","observation","callee","receptions"])if(field in definition)throw new Error(`Unsupported callable configuration field: ${field}`);const run=definition.run;if(typeof run!="function")throw new Error("Callable definition needs a run function");const output=definition.output;return Object.freeze({kind:definition.kind,name:definition.name,label:definition.label,source:definition.source,output:output?Object.freeze({result:output.result.bind(output),delta:output.delta?.bind(output)}):void 0,deps:Object.freeze({...definition.deps}),run:run.bind(definition),checkpoint:definition.checkpoint?snapshotCheckpoint(definition.checkpoint):void 0,...members?{members:Object.freeze([...members]),names:Object.freeze({...names})}:{}})}__name(snapshotDefinition,"snapshotDefinition");const receptionOrigins=new WeakMap;function originalReception(reception){return receptionOrigins.get(reception)??reception}__name(originalReception,"originalReception");function snapshotReception(reception){const value=reception.value;if(typeof value?.check!="function"||typeof value.encode!="function"||typeof value.decode!="function")throw new Error("Reception needs check, encode and decode functions");const fixed=Object.freeze({child:reception.child,value:Object.freeze({check:value.check.bind(value),encode:value.encode.bind(value),decode:value.decode.bind(value)})});return receptionOrigins.set(fixed,originalReception(reception)),fixed}__name(snapshotReception,"snapshotReception");function snapshotObservation(declaration){return Object.freeze({deps:Object.freeze({...declaration.deps}),failure:declaration.failure,observe:declaration.observe.bind(declaration)})}__name(snapshotObservation,"snapshotObservation");function snapshotReceptions(receptions){return Object.freeze(receptions.map(snapshotReception))}__name(snapshotReceptions,"snapshotReceptions");function snapshotCodec(codec){return Object.freeze({encode:codec.encode.bind(codec),decode:codec.decode.bind(codec)})}__name(snapshotCodec,"snapshotCodec");function snapshotCheckpoint(checkpoint){return Object.freeze({key:checkpoint.key,version:checkpoint.version,input:snapshotCodec(checkpoint.input),output:snapshotCodec(checkpoint.output),points:Object.freeze(checkpoint.points.map(snapshotCheckpointPoint)),receptions:checkpoint.receptions?snapshotReceptions(checkpoint.receptions):void 0})}__name(snapshotCheckpoint,"snapshotCheckpoint");const pointOrigins=new WeakMap;function originalCheckpointPoint(point){return pointOrigins.get(point)??point}__name(originalCheckpointPoint,"originalCheckpointPoint");function snapshotCheckpointPoint(point){const resume=point.resume,fixed=Object.freeze({name:point.name,state:snapshotCodec(point.state),references:Object.freeze(Object.fromEntries(Object.entries(point.references).map(([name,slot])=>[name,Object.freeze({...slot})]))),check:point.check?.bind(point),resume:Object.freeze({deps:Object.freeze({...resume.deps}),uses:resume.uses?Object.freeze([...resume.uses]):void 0,run:resume.run.bind(resume)})});return pointOrigins.set(fixed,originalCheckpointPoint(point)),fixed}__name(snapshotCheckpointPoint,"snapshotCheckpointPoint");export{originalCheckpointPoint,originalReception,snapshotDefinition,snapshotObservation};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CallableKind, OperationOutcome } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { CallableContext, InvocationCheckpointWork, InvocationWork, Invocation } from '@weiliang0121/capix-invocation';
|
|
3
|
+
import type { BoundChildren } from './children/bound.js';
|
|
4
|
+
import { type CallableSnapshot } from './snapshot.js';
|
|
5
|
+
export declare class InvocationWorkBinding<Input, Output, Context extends CallableContext<Input, Output>, Resources extends object, Kind extends CallableKind> implements InvocationWork<Input, Output, Context> {
|
|
6
|
+
#private;
|
|
7
|
+
private readonly declaration;
|
|
8
|
+
private readonly children;
|
|
9
|
+
private readonly composite;
|
|
10
|
+
readonly output: InvocationWork<Input, Output, Context>['output'];
|
|
11
|
+
readonly checkpoint?: InvocationCheckpointWork<Input, Output, Context>;
|
|
12
|
+
constructor(declaration: CallableSnapshot<Input, Output, Kind, Resources, any>, children: BoundChildren, composite: boolean);
|
|
13
|
+
execute(_context: Context, invocation: Invocation<Input, Output, Context>): Output | import("@weiliang0121/capix-contracts").Stable<Output> | Promise<Output | import("@weiliang0121/capix-contracts").Stable<Output>>;
|
|
14
|
+
close(_context: Context, invocation: Invocation<Input, Output, Context>): OperationOutcome<void>;
|
|
15
|
+
private resume;
|
|
16
|
+
private childPort;
|
|
17
|
+
private executionWork;
|
|
18
|
+
private accessFor;
|
|
19
|
+
private bindCheckpoint;
|
|
20
|
+
}
|