@weiliang0121/capix-structure 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 +19 -2
- package/dist/callable.d.ts +18 -0
- package/dist/callable.js +2 -0
- package/dist/composition/dynamic.d.ts +32 -0
- package/dist/composition/dynamic.js +2 -0
- package/dist/composition/input.d.ts +2 -0
- package/dist/composition/input.js +1 -0
- package/dist/composition/sequence.d.ts +58 -0
- package/dist/composition/sequence.js +2 -0
- package/dist/configuration.d.ts +7 -0
- package/dist/configuration.js +2 -0
- package/dist/construction.d.ts +4 -0
- package/dist/construction.js +2 -0
- package/dist/definition/callable.d.ts +29 -0
- package/dist/definition/callable.js +1 -0
- package/dist/definition/checkpoint.d.ts +38 -0
- package/dist/definition/checkpoint.js +2 -0
- package/dist/definition/children.d.ts +9 -0
- package/dist/definition/children.js +1 -0
- package/dist/definition/composition.d.ts +30 -0
- package/dist/definition/composition.js +1 -0
- package/dist/definition/dependencies.d.ts +13 -0
- package/dist/definition/dependencies.js +2 -0
- package/dist/definition/factory.d.ts +49 -0
- package/dist/definition/factory.js +2 -0
- package/dist/definition/group.d.ts +2 -0
- package/dist/definition/group.js +1 -0
- package/dist/definition/kind.d.ts +7 -0
- package/dist/definition/kind.js +2 -0
- package/dist/definition/node.d.ts +2 -0
- package/dist/definition/node.js +1 -0
- package/dist/definition/reception.d.ts +8 -0
- package/dist/definition/reception.js +2 -0
- package/dist/definition/scene.d.ts +2 -0
- package/dist/definition/scene.js +1 -0
- package/dist/definition/work.d.ts +16 -0
- package/dist/definition/work.js +1 -0
- package/dist/group.d.ts +13 -0
- package/dist/group.js +2 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +2 -0
- package/dist/members.d.ts +13 -0
- package/dist/members.js +2 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.js +2 -0
- package/dist/scene.d.ts +15 -0
- package/dist/scene.js +2 -0
- package/package.json +44 -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,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weiliang0121/capix-structure
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Composable Scene, Group, and Node structures 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-structure
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public entry points
|
|
12
|
+
|
|
13
|
+
- `@weiliang0121/capix-structure`
|
|
14
|
+
- `@weiliang0121/capix-structure/construction`
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT. Copyright (c) 2026 wei.liang. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CallableKind, invocationSignature, InvocationSignature } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { CallableDescription, CallableDefinition, CallableRun, EmptyResources } from './definition/callable.js';
|
|
3
|
+
import type { ChildContractsOf } from './definition/children.js';
|
|
4
|
+
import type { ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
5
|
+
export type CallableStructure<Kind extends CallableKind> = Callable<any, any, Kind, any, any>;
|
|
6
|
+
export declare abstract class Callable<Input, Output, Kind extends CallableKind, Resources extends object = EmptyResources, Delta = never> {
|
|
7
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
8
|
+
readonly kind: Kind;
|
|
9
|
+
readonly [invocationSignature]: InvocationSignature<Input, Output, Delta>;
|
|
10
|
+
name?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
source?: string;
|
|
13
|
+
deps?: ResourceRequirements<Resources>;
|
|
14
|
+
run?: CallableRun<Input, Output, Kind, Resources, ChildContractsOf<Kind>, Delta, this>;
|
|
15
|
+
output?: CallableDescription<Input, Output, Kind, Delta>['output'];
|
|
16
|
+
checkpoint?: CallableDescription<Input, Output, Kind, Delta>['checkpoint'];
|
|
17
|
+
protected constructor(kind: Kind, configuration?: CallableDefinition<Input, Output, Kind, Resources, Delta>);
|
|
18
|
+
}
|
package/dist/callable.js
ADDED
|
@@ -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{randomUUID}from"node:crypto";import{initializeStructureConfiguration}from"./configuration.js";class Callable{static{__name(this,"Callable")}id=randomUUID();kind;name;label;source;deps;run;output;checkpoint;constructor(kind,configuration){if(initializeStructureConfiguration(this),configuration!==void 0&&(!configuration||typeof configuration!="object"))throw new TypeError("Callable configuration must be an object");for(const field of["kind","members","setRun","setDefinition","accept","exceptions","raises","maxRounds","uses","observation","callee","receptions"])if(configuration&&field in configuration)throw new TypeError(`Unsupported callable configuration field: ${field}`);this.kind=kind,this.name=configuration?.name,this.label=configuration?.label,this.source=configuration?.source,this.deps=configuration?.deps,this.run=configuration?.run?.bind(configuration),this.output=configuration?.output,this.checkpoint=configuration?.checkpoint,Object.defineProperty(this,"id",{value:this.id,enumerable:!0,writable:!1,configurable:!1}),Object.defineProperty(this,"kind",{value:kind,enumerable:!0,writable:!1,configurable:!1})}}export{Callable};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Group } from '../group.js';
|
|
2
|
+
import type { MemberInput } from './input.js';
|
|
3
|
+
import type { ChildCallable } from '../definition/children.js';
|
|
4
|
+
import type { CallableInput, CallableOutput, Stable } from '@weiliang0121/capix-contracts';
|
|
5
|
+
import type { MemberRegistration, NamedMembers } from '../definition/composition.js';
|
|
6
|
+
export type DynamicCall<Options extends NamedMembers> = {
|
|
7
|
+
[Name in keyof Options & string]: {
|
|
8
|
+
readonly kind: 'call';
|
|
9
|
+
readonly option: Name;
|
|
10
|
+
readonly input: MemberInput<Options[Name]> | Stable<MemberInput<Options[Name]>>;
|
|
11
|
+
};
|
|
12
|
+
}[keyof Options & string];
|
|
13
|
+
export type DynamicFinish<Output> = {
|
|
14
|
+
readonly kind: 'finish';
|
|
15
|
+
readonly value: Output;
|
|
16
|
+
};
|
|
17
|
+
export type DynamicDecision<Options extends NamedMembers, Output> = DynamicCall<Options> | DynamicFinish<Output>;
|
|
18
|
+
type FinishValue<Value> = Value extends DynamicFinish<infer Output> ? Output : never;
|
|
19
|
+
export type DynamicOutput<Decision extends ChildCallable> = FinishValue<CallableOutput<Decision>>;
|
|
20
|
+
type DecisionCheck<Options extends NamedMembers, Decision extends ChildCallable> = [CallableOutput<Decision>] extends [DynamicDecision<Options, unknown>] ? ([CallableInput<Decision>] extends [MemberInput<Decision>] ? unknown : never) : never;
|
|
21
|
+
export interface DynamicConfiguration<Options extends NamedMembers, Decision extends ChildCallable> {
|
|
22
|
+
readonly options: MemberRegistration<Options>;
|
|
23
|
+
readonly decide: Decision & NoInfer<DecisionCheck<Options, Decision>>;
|
|
24
|
+
readonly maxSteps?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class Dynamic<const Options extends NamedMembers, Decision extends ChildCallable> extends Group<MemberInput<Decision>, DynamicOutput<Decision>> {
|
|
27
|
+
#private;
|
|
28
|
+
readonly run: NonNullable<Group<MemberInput<Decision>, DynamicOutput<Decision>>['run']>;
|
|
29
|
+
constructor(configuration: DynamicConfiguration<Options, Decision>);
|
|
30
|
+
get maxSteps(): number;
|
|
31
|
+
}
|
|
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{types}from"node:util";import{Group}from"../group.js";import{checkMemberName}from"../members.js";class Dynamic extends Group{static{__name(this,"Dynamic")}#maxSteps;constructor(configuration){if(super(),!configuration||typeof configuration!="object"||types.isProxy(configuration))throw new TypeError("Dynamic configuration must be an object");const options=snapshotOptions(configuration.options),decision=configuration.decide,maxSteps=checkMaxSteps(configuration.maxSteps??8);this.add(...options.values(),decision),this.#maxSteps=maxSteps;const run=__name(async work=>{for(let step=0;step<=maxSteps;step++){const next=await work.children.invoke(decision,work.input,{key:`decision:${step}`}),selected=checkDecision(next,options);if(selected.kind==="finish")return selected.value;step<maxSteps&&await work.children.invoke(selected.node,selected.input,{key:`option:${step}:${selected.option}`})}throw new Error(`Dynamic exceeded ${maxSteps} action steps`)},"run");Object.defineProperty(this,"run",{get:__name(()=>run,"get"),enumerable:!0,configurable:!0})}get maxSteps(){return this.#maxSteps}}function checkMaxSteps(value){if(!Number.isSafeInteger(value)||value<0)throw new RangeError("Dynamic maxSteps must be a non-negative safe integer");return value}__name(checkMaxSteps,"checkMaxSteps");function snapshotOptions(options){if(!options||typeof options!="object"||Array.isArray(options)||types.isProxy(options))throw new TypeError("Dynamic options must be an object");if(Object.getOwnPropertySymbols(options).length)throw new TypeError("Dynamic option names must be strings");const entries=[];for(const[name,descriptor]of Object.entries(Object.getOwnPropertyDescriptors(options))){if(checkMemberName(name),!("value"in descriptor))throw new TypeError("Dynamic options must use data properties");entries.push([name,descriptor.value])}return new Map(entries)}__name(snapshotOptions,"snapshotOptions");function checkDecision(value,options){if(!value||typeof value!="object"||Array.isArray(value))throw new TypeError("Dynamic decision must be a call or finish object");const decision=value;if(decision.kind==="finish"&&Object.hasOwn(decision,"value"))return{kind:"finish",value:decision.value};if(decision.kind!=="call"||typeof decision.option!="string"||!Object.hasOwn(decision,"input"))throw new TypeError("Dynamic decision must be a call or finish object");const node=options.get(decision.option);if(!node)throw new Error(`Dynamic option is not registered: ${decision.option}`);return{kind:"call",option:decision.option,node,input:decision.input}}__name(checkDecision,"checkDecision");export{Dynamic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Group } from '../group.js';
|
|
2
|
+
import type { ChildCallable } from '../definition/children.js';
|
|
3
|
+
import type { MemberInput } from './input.js';
|
|
4
|
+
import type { Stable, CallableDelta, CallableOutput, InvocationOutputWriter, OperationResult, OutputDeclaration } from '@weiliang0121/capix-contracts';
|
|
5
|
+
export type SequenceScope<Input, Previous, Delta = never> = {
|
|
6
|
+
readonly input: Stable<Input>;
|
|
7
|
+
readonly previous: Stable<Previous>;
|
|
8
|
+
} & ([Delta] extends [never] ? object : {
|
|
9
|
+
readonly output: InvocationOutputWriter<Delta>;
|
|
10
|
+
});
|
|
11
|
+
export interface SequenceStep<Member extends ChildCallable, Input = MemberInput<Member>, Previous = Input, Delta = never> {
|
|
12
|
+
readonly node: Member;
|
|
13
|
+
readonly key?: string;
|
|
14
|
+
readonly input?: (scope: SequenceScope<Input, Previous, Delta>) => MemberInput<Member> | Stable<MemberInput<Member>>;
|
|
15
|
+
readonly delta?: [CallableDelta<Member>] extends [never] ? never : (delta: Stable<CallableDelta<Member>>, scope: SequenceScope<Input, Previous, Delta>) => void;
|
|
16
|
+
readonly result?: {
|
|
17
|
+
readonly succeeded?: (value: Stable<CallableOutput<Member>>, scope: SequenceScope<Input, Previous, Delta>) => unknown;
|
|
18
|
+
readonly failed?: (failure: unknown, scope: SequenceScope<Input, Previous, Delta>) => unknown;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type SequenceItem = ChildCallable | {
|
|
22
|
+
readonly node: ChildCallable;
|
|
23
|
+
};
|
|
24
|
+
type StepNode<Step> = Step extends ChildCallable ? Step : Step extends {
|
|
25
|
+
readonly node: infer Member extends ChildCallable;
|
|
26
|
+
} ? Member : never;
|
|
27
|
+
type Accepted<Step> = Stable<OperationResult<Stable<CallableOutput<StepNode<Step>>>, Step>>;
|
|
28
|
+
type Initial<Step> = Step extends {
|
|
29
|
+
readonly input: (scope: infer Scope) => unknown;
|
|
30
|
+
} ? (Scope extends {
|
|
31
|
+
readonly input: infer Input;
|
|
32
|
+
} ? Input : unknown) : MemberInput<StepNode<Step>>;
|
|
33
|
+
export type SequenceInput<Steps extends readonly SequenceItem[]> = Steps extends readonly [infer First, ...unknown[]] ? Initial<First> : unknown;
|
|
34
|
+
export type SequenceOutput<Steps extends readonly SequenceItem[]> = Steps extends readonly [...unknown[], infer Last] ? Accepted<Last> : SequenceInput<Steps>;
|
|
35
|
+
type ValidStep<Step, Input, Previous, Delta> = Step extends ChildCallable ? ([Previous] extends [MemberInput<Step> | Stable<MemberInput<Step>>] ? true : false) : Step extends SequenceStep<StepNode<Step>, Input, Previous, Delta> ? (Step extends {
|
|
36
|
+
readonly input: (scope: never) => unknown;
|
|
37
|
+
} ? true : [Previous] extends [MemberInput<StepNode<Step>> | Stable<MemberInput<StepNode<Step>>>] ? true : false) : false;
|
|
38
|
+
type ValidSteps<Steps extends readonly SequenceItem[], Input, Previous, Delta> = Steps extends readonly [infer First extends SequenceItem, ...infer Rest extends readonly SequenceItem[]] ? ([ValidStep<First, Input, Previous, Delta>] extends [true] ? ValidSteps<Rest, Input, Accepted<First>, Delta> : false) : Steps extends readonly [] ? true : false;
|
|
39
|
+
type CheckedSteps<Steps extends readonly SequenceItem[], Delta> = [SequenceInput<Steps>] extends [never] ? never : ValidSteps<Steps, SequenceInput<Steps>, SequenceInput<Steps>, Delta> extends true ? unknown : never;
|
|
40
|
+
type SequenceOptions<Output, Delta> = {
|
|
41
|
+
readonly output?: OutputDeclaration<Output, Delta>;
|
|
42
|
+
} & ([Delta] extends [never] ? object : {
|
|
43
|
+
readonly output: OutputDeclaration<Output, Delta> & {
|
|
44
|
+
readonly delta: (value: unknown) => Delta;
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
type SequenceConfiguration<Output, Delta> = [options: SequenceOptions<Output, Delta>] | ([Delta] extends [never] ? [] : never);
|
|
48
|
+
export declare class Sequence<const Steps extends readonly SequenceItem[], Delta = never> extends Group<SequenceInput<Steps>, SequenceOutput<Steps>, {}, Delta> {
|
|
49
|
+
#private;
|
|
50
|
+
readonly run: NonNullable<Group<SequenceInput<Steps>, SequenceOutput<Steps>, {}, Delta>['run']>;
|
|
51
|
+
readonly output: OutputDeclaration<SequenceOutput<Steps>, Delta> | undefined;
|
|
52
|
+
constructor(steps: Steps & CheckedSteps<NoInfer<Steps>, NoInfer<Delta>>, ...configuration: SequenceConfiguration<NoInfer<SequenceOutput<Steps>>, Delta>);
|
|
53
|
+
get steps(): readonly {
|
|
54
|
+
readonly key: string;
|
|
55
|
+
readonly node: ChildCallable;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
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{types}from"node:util";import{Callable}from"../callable.js";import{Group}from"../group.js";import{requireChildCallable}from"../members.js";class Sequence extends Group{static{__name(this,"Sequence")}#steps;constructor(steps,...configuration){if(super(),!Array.isArray(steps)||types.isProxy(steps))throw new TypeError("Sequence steps must be an array");const entries=[];for(let index=0;index<steps.length;index++){const item=Object.getOwnPropertyDescriptor(steps,String(index));if(!item||!("value"in item))throw new TypeError("Sequence steps must be present data entries");entries.push(prepareStep(item.value,index))}this.#steps=Object.freeze(entries);const outputDeclaration=snapshotOutput(configuration[0]),run=__name(async work=>{let previous=work.input;const output="output"in work?work.output:void 0;for(const step of this.#steps)previous=await step.invoke(work.input,previous,work.children,output);return previous},"run");Object.defineProperty(this,"run",{get:__name(()=>run,"get"),enumerable:!0,configurable:!0}),Object.defineProperty(this,"output",{get:__name(()=>outputDeclaration,"get"),enumerable:!0,configurable:!0}),this.add(...entries.map(entry=>entry.node))}get steps(){return Object.freeze(this.#steps.map(({key,node})=>Object.freeze({key,node})))}}function requireConfiguration(value){if(!value||typeof value!="object"||Array.isArray(value)||types.isProxy(value))throw new TypeError("Sequence configuration must be a data object")}__name(requireConfiguration,"requireConfiguration");function readField(configuration,name){const field=Object.getOwnPropertyDescriptor(configuration,name);if(!field&&name in configuration)throw new TypeError("Sequence configuration must use own data properties");if(field&&!("value"in field))throw new TypeError("Sequence configuration must use data properties");return field?.value}__name(readField,"readField");function snapshotOutput(options){if(options===void 0)return;requireConfiguration(options);const output=readField(options,"output");if(output===void 0)return;requireConfiguration(output);const result=readField(output,"result"),delta=readField(output,"delta");if(typeof result!="function"||delta!==void 0&&typeof delta!="function")throw new TypeError("Sequence output needs result and optional delta functions");return Object.freeze({result:result.bind(output),...delta?{delta:delta.bind(output)}:{}})}__name(snapshotOutput,"snapshotOutput");function prepareStep(value,index){if(types.isProxy(value))throw new TypeError("Sequence steps cannot be proxies");const direct=value instanceof Callable;direct||requireConfiguration(value);const configuration=direct?void 0:value,node=direct?value:readField(configuration,"node");requireChildCallable(node);const key=(configuration?readField(configuration,"key"):void 0)??`step:${index}`;if(typeof key!="string"||!key.trim())throw new TypeError("Sequence step key must be non-blank");const prepare=configuration?readField(configuration,"input"):void 0,delta=configuration?readField(configuration,"delta"):void 0,result=configuration?readField(configuration,"result"):void 0;result!==void 0&&requireConfiguration(result);const succeeded=result?readField(result,"succeeded"):void 0,failed=result?readField(result,"failed"):void 0;for(const callback of[prepare,delta,succeeded,failed])if(callback!==void 0&&typeof callback!="function")throw new TypeError("Sequence step callbacks must be functions");const inputFor=typeof prepare=="function"?prepare.bind(configuration):void 0,emit=typeof delta=="function"?delta.bind(configuration):void 0,receive=typeof succeeded=="function"?succeeded.bind(result):void 0,handle=typeof failed=="function"?failed.bind(result):void 0;return Object.freeze({key,node,async invoke(input,previous,children,output){const scope=Object.freeze({input,previous,...output?{output}:{}}),childInput=inputFor?inputFor(scope):previous;return children.invoke(node,childInput,{key,...emit?{delta:__name(value2=>emit(value2,scope),"delta")}:{},result:{...receive?{succeeded:__name(value2=>receive(value2,scope),"succeeded")}:{},...handle?{failed:__name(failure=>handle(failure,scope),"failed")}:{}}})}})}__name(prepareStep,"prepareStep");export{Sequence};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function initializeStructureConfiguration(structure: object): void;
|
|
2
|
+
export declare function assertStructureConfigurable(structure: object): void;
|
|
3
|
+
export declare function structureParent(structure: object): object | undefined;
|
|
4
|
+
export declare function claimStructureMembers(owner: object, members: readonly object[]): void;
|
|
5
|
+
export declare function beginStructureBuild(structure: object): void;
|
|
6
|
+
export declare function endStructureBuild(structure: object): void;
|
|
7
|
+
export declare function lockStructureConfiguration(structure: object): void;
|
|
@@ -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{types}from"node:util";const configuration=Symbol("callable-configuration");function initializeStructureConfiguration(structure){Object.defineProperty(structure,configuration,{value:{phase:"configuring"}})}__name(initializeStructureConfiguration,"initializeStructureConfiguration");function state(structure){if(types.isProxy(structure))throw new TypeError("Callable structures cannot be proxies");if(!Object.hasOwn(structure,configuration))throw new TypeError("Callable configuration is not initialized");return structure[configuration]}__name(state,"state");function assertStructureConfigurable(structure){const phase=state(structure).phase;if(phase!=="configuring")throw new Error(phase==="building"?"Callable structure configuration is locked while building":"Callable structure configuration is locked after build")}__name(assertStructureConfigurable,"assertStructureConfigurable");function structureParent(structure){return state(structure).parent}__name(structureParent,"structureParent");function claimStructureMembers(owner,members){for(const member of members){const current=state(member);if(assertStructureConfigurable(member),current.parent&¤t.parent!==owner)throw new Error("Callable member already belongs to another parent")}for(const member of members)state(member).parent=owner}__name(claimStructureMembers,"claimStructureMembers");function beginStructureBuild(structure){assertStructureConfigurable(structure),state(structure).phase="building"}__name(beginStructureBuild,"beginStructureBuild");function endStructureBuild(structure){const current=state(structure);current.phase==="building"&&(current.phase="configuring")}__name(endStructureBuild,"endStructureBuild");function lockStructureConfiguration(structure){state(structure).phase="built"}__name(lockStructureConfiguration,"lockStructureConfiguration");export{assertStructureConfigurable,beginStructureBuild,claimStructureMembers,endStructureBuild,initializeStructureConfiguration,lockStructureConfiguration,structureParent};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assertStructureConfigurable, beginStructureBuild, endStructureBuild, lockStructureConfiguration, structureParent } from './configuration.js';
|
|
2
|
+
export { checkMemberName } from './members.js';
|
|
3
|
+
export { childKinds } from './definition/kind.js';
|
|
4
|
+
export { callableDependencies, type CallableDependencies } from './definition/dependencies.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
import{assertStructureConfigurable,beginStructureBuild,endStructureBuild,lockStructureConfiguration,structureParent}from"./configuration.js";import{checkMemberName}from"./members.js";import{childKinds}from"./definition/kind.js";import{callableDependencies}from"./definition/dependencies.js";export{assertStructureConfigurable,beginStructureBuild,callableDependencies,checkMemberName,childKinds,endStructureBuild,lockStructureConfiguration,structureParent};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CallableKind, OutputDeclaration, Stable } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
3
|
+
import type { ChildContractsOf } from './children.js';
|
|
4
|
+
import type { InvocationCheckpointDefinition } from './checkpoint.js';
|
|
5
|
+
import type { CallableWork } from './work.js';
|
|
6
|
+
import type { NamedWork } from './composition.js';
|
|
7
|
+
export type { InvocationCheckpointPoint, InvocationCheckpointDefinition } from './checkpoint.js';
|
|
8
|
+
export type EmptyResources = Readonly<Record<never, never>>;
|
|
9
|
+
export type CallableRun<Input, Output, Kind extends CallableKind, Resources extends object, Allowed extends ChildContractsOf<Kind> = ChildContractsOf<Kind>, Delta = never, Owner = unknown> = (work: NamedWork<CallableWork<Kind, Input, Output, Resources, Allowed, Delta>, Owner, Allowed>) => Output | Stable<Output> | Promise<Output | Stable<Output>>;
|
|
10
|
+
export interface CallableDescription<Input, Output, Kind extends CallableKind, Delta = never> {
|
|
11
|
+
readonly kind?: never;
|
|
12
|
+
readonly members?: never;
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
readonly label?: string;
|
|
15
|
+
readonly source?: string;
|
|
16
|
+
readonly output?: OutputDeclaration<Output, Delta>;
|
|
17
|
+
readonly checkpoint?: InvocationCheckpointDefinition<Input, Output, Kind, Delta>;
|
|
18
|
+
}
|
|
19
|
+
type RequiredDependencies<Resources extends object> = [keyof Resources] extends [never] ? {
|
|
20
|
+
readonly deps?: ResourceRequirements<Resources>;
|
|
21
|
+
} : {
|
|
22
|
+
readonly deps: ResourceRequirements<Resources>;
|
|
23
|
+
};
|
|
24
|
+
export type CallableDefinition<Input, Output, Kind extends CallableKind, Resources extends object = EmptyResources, Delta = never> = CallableDescription<Input, Output, Kind, Delta> & ({
|
|
25
|
+
readonly deps?: ResourceRequirements<Resources>;
|
|
26
|
+
readonly run?: undefined;
|
|
27
|
+
} | (RequiredDependencies<Resources> & {
|
|
28
|
+
readonly run: CallableRun<Input, Output, Kind, Resources, ChildContractsOf<Kind>, Delta>;
|
|
29
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ResourceRequirements, ResourceRequests, ResourcesOf } from '@weiliang0121/capix-resources';
|
|
2
|
+
import type { Stable, CallableKind, CheckpointCodec, CheckpointContract, ChildContract, ChildReferenceSlot, SavedReferences, CheckpointFacts, CheckpointPointOwner } from '@weiliang0121/capix-contracts';
|
|
3
|
+
import type { ChildContractsOf } from './children.js';
|
|
4
|
+
import type { ResumeWork } from './work.js';
|
|
5
|
+
import type { DefinitionReceptions } from './reception.js';
|
|
6
|
+
type CheckpointReferenceSlotsFor<Kind extends CallableKind> = Kind extends 'node' ? Readonly<Record<string, never>> : Readonly<Record<string, ChildReferenceSlot<ChildContractsOf<Kind>>>>;
|
|
7
|
+
export declare function childReference<Definition extends ChildContract>(definition: Definition): ChildReferenceSlot<Definition, false>;
|
|
8
|
+
export declare function childReferences<Definition extends ChildContract>(definition: Definition): ChildReferenceSlot<Definition, true>;
|
|
9
|
+
export interface InvocationCheckpointPoint<Input, Output, Kind extends CallableKind, State, Resources extends object = Record<string, never>, Slots extends CheckpointReferenceSlotsFor<Kind> = CheckpointReferenceSlotsFor<Kind>, Allowed extends ChildContractsOf<Kind> = never, Delta = never> extends CheckpointPointOwner<Kind, Input, Output, Delta> {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly state: CheckpointCodec<State>;
|
|
12
|
+
readonly references: Slots;
|
|
13
|
+
check?(state: Stable<State>, facts: CheckpointFacts<Input, Slots>): void;
|
|
14
|
+
readonly resume: {
|
|
15
|
+
readonly deps: ResourceRequirements<Resources>;
|
|
16
|
+
readonly uses?: readonly Allowed[];
|
|
17
|
+
run(work: ResumeWork<Kind, Input, Output, Resources, Allowed, Delta>, state: Stable<State>, saved: SavedReferences<Slots>): Output | Stable<Output> | Promise<Output | Stable<Output>>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface InvocationCheckpointDefinition<Input, Output, Kind extends CallableKind, Delta = never> extends CheckpointContract {
|
|
21
|
+
readonly input: CheckpointCodec<Input>;
|
|
22
|
+
readonly output: CheckpointCodec<Output>;
|
|
23
|
+
readonly points: readonly InvocationCheckpointPoint<Input, Output, Kind, any, any, any, any, Delta>[];
|
|
24
|
+
readonly receptions?: DefinitionReceptions<Kind>;
|
|
25
|
+
}
|
|
26
|
+
interface PointOptions<Kind extends CallableKind, Input, Output, State, Slots extends CheckpointReferenceSlotsFor<Kind>, Deps extends ResourceRequests, Uses extends readonly ChildContractsOf<Kind>[], Delta> {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly state: CheckpointCodec<State>;
|
|
29
|
+
readonly references: Slots;
|
|
30
|
+
readonly check?: (state: NoInfer<Stable<State>>, facts: CheckpointFacts<Input, NoInfer<Slots>>) => void;
|
|
31
|
+
readonly resume: {
|
|
32
|
+
readonly deps?: Deps;
|
|
33
|
+
readonly uses?: Uses;
|
|
34
|
+
readonly run: (work: ResumeWork<Kind, Input, Output, ResourcesOf<NoInfer<Deps>>, Uses[number], Delta>, state: NoInfer<Stable<State>>, saved: SavedReferences<NoInfer<Slots>>) => Output | Stable<Output> | Promise<Output | Stable<Output>>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare function checkpointPoint<Kind extends CallableKind, Input, Output, Delta = never>(): <State, const Slots extends CheckpointReferenceSlotsFor<Kind>, const Deps extends ResourceRequests = Readonly<Record<never, never>>, const Uses extends readonly ChildContractsOf<Kind>[] = readonly []>(options: PointOptions<Kind, Input, Output, State, Slots, Deps, Uses, Delta>) => InvocationCheckpointPoint<Input, Output, Kind, State, ResourcesOf<Deps>, Slots, Uses[number], Delta>;
|
|
38
|
+
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});function childReference(definition){return Object.freeze({definition,many:!1})}__name(childReference,"childReference");function childReferences(definition){return Object.freeze({definition,many:!0})}__name(childReferences,"childReferences");function checkpointPoint(){return options=>{const deps=options.resume.deps??{};return Object.freeze({name:options.name,state:options.state,references:options.references,check:options.check?.bind(options),resume:{deps,uses:options.resume.uses,run:options.resume.run.bind(options.resume)}})}}__name(checkpointPoint,"checkpointPoint");export{checkpointPoint,childReference,childReferences};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CallableKind, ChildContract } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { CallableStructure } from '../callable.js';
|
|
3
|
+
import type { Composite } from './composition.js';
|
|
4
|
+
import type { ChildKind } from './kind.js';
|
|
5
|
+
export type ChildCallable = (CallableStructure<'group'> & Composite) | (CallableStructure<'node'> & {
|
|
6
|
+
readonly members?: never;
|
|
7
|
+
});
|
|
8
|
+
export type ChildrenOf<Kind extends CallableKind> = [ChildKind<Kind>] extends [never] ? never : ChildCallable;
|
|
9
|
+
export type ChildContractsOf<Kind extends CallableKind> = [ChildKind<Kind>] extends [never] ? never : ChildContract;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChildCallable } from './children.js';
|
|
2
|
+
import type { Stable, ChildContract, ChildOperationOptions, ChildReceptionOptions, CallableInput, CallableOutput, ReceptionDefinition, OperationResult } from '@weiliang0121/capix-contracts';
|
|
3
|
+
export type NamedMembers = Readonly<Record<string, ChildCallable>>;
|
|
4
|
+
type ReservedMemberName = '' | 'invoke' | 'create' | 'open' | 'facts' | 'resume' | '__proto__' | 'prototype' | 'constructor' | 'toString' | 'toLocaleString' | 'valueOf' | 'hasOwnProperty' | 'isPrototypeOf' | 'propertyIsEnumerable' | '__defineGetter__' | '__defineSetter__' | '__lookupGetter__' | '__lookupSetter__';
|
|
5
|
+
export type MemberRegistration<Names extends NamedMembers> = Names & {
|
|
6
|
+
readonly [Name in keyof Names]: Name extends string ? (Name extends ReservedMemberName ? never : Names[Name]) : never;
|
|
7
|
+
};
|
|
8
|
+
declare const memberNames: unique symbol;
|
|
9
|
+
export interface NamedMemberRegistration<Names extends NamedMembers> {
|
|
10
|
+
readonly [memberNames]: Names;
|
|
11
|
+
}
|
|
12
|
+
type MemberNamesOf<Owner> = Owner extends NamedMemberRegistration<infer Names> ? Names : {};
|
|
13
|
+
interface NamedChildOperation<Definition extends ChildContract> {
|
|
14
|
+
invoke(input: CallableInput<Definition> | Stable<CallableInput<Definition>>): Promise<Stable<CallableOutput<Definition>>>;
|
|
15
|
+
invoke<Value, const Options extends NoInfer<ChildReceptionOptions<Definition, Value>>>(input: CallableInput<Definition> | Stable<CallableInput<Definition>>, options: Options & {
|
|
16
|
+
readonly reception: ReceptionDefinition<Definition, Value>;
|
|
17
|
+
}): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
|
|
18
|
+
invoke<const Options extends ChildOperationOptions<Definition>>(input: CallableInput<Definition> | Stable<CallableInput<Definition>>, options: Options & ChildOperationOptions<Definition>): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
|
|
19
|
+
}
|
|
20
|
+
type NamedChildOperations<Owner, Allowed extends ChildContract> = {
|
|
21
|
+
readonly [Name in keyof MemberNamesOf<Owner> as MemberNamesOf<Owner>[Name] extends Allowed ? Name : never]: MemberNamesOf<Owner>[Name] extends ChildContract ? NamedChildOperation<MemberNamesOf<Owner>[Name]> : never;
|
|
22
|
+
};
|
|
23
|
+
export type NamedWork<Work, Owner, Allowed extends ChildContract> = keyof NamedChildOperations<Owner, Allowed> extends never ? Work : Work & {
|
|
24
|
+
readonly children: NamedChildOperations<Owner, Allowed>;
|
|
25
|
+
};
|
|
26
|
+
export interface Composite<Members extends readonly ChildCallable[] = readonly ChildCallable[]> {
|
|
27
|
+
readonly members: Members;
|
|
28
|
+
readonly names?: NamedMembers;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ResourceRequirements } from '@weiliang0121/capix-resources';
|
|
2
|
+
export interface CallableDependencies {
|
|
3
|
+
readonly deps?: ResourceRequirements;
|
|
4
|
+
readonly checkpoint?: {
|
|
5
|
+
readonly points: readonly {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly resume: {
|
|
8
|
+
readonly deps: ResourceRequirements;
|
|
9
|
+
};
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function callableDependencies(definition: CallableDependencies): ResourceRequirements;
|
|
@@ -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 callableDependencies(definition){const deps={};for(const[name,request]of Object.entries(definition.deps??{}))deps[`run.${name}`]=request;for(const point of definition.checkpoint?.points??[])for(const[name,request]of Object.entries(point.resume.deps))deps[`checkpoint.${point.name}.${name}`]=request;return Object.freeze(deps)}__name(callableDependencies,"callableDependencies");export{callableDependencies};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { CallableKind } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { OutputDeclaration } from '@weiliang0121/capix-contracts';
|
|
3
|
+
import type { ChildrenOf } from './children.js';
|
|
4
|
+
import type { InvocationCheckpointDefinition } from './checkpoint.js';
|
|
5
|
+
import { type ResourceRequests, type ResourcesOf } from '@weiliang0121/capix-resources';
|
|
6
|
+
import type { CallableWork } from './work.js';
|
|
7
|
+
import { Scene } from '../scene.js';
|
|
8
|
+
import { Group } from '../group.js';
|
|
9
|
+
import { Node } from '../node.js';
|
|
10
|
+
import type { ReceptionRegistration } from '@weiliang0121/capix-contracts';
|
|
11
|
+
type EmptyDependencies = Readonly<Record<never, never>>;
|
|
12
|
+
type LocalDependencies<Common extends ResourceRequests, Deps extends ResourceRequests> = Deps & {
|
|
13
|
+
readonly [Name in keyof Common]?: never;
|
|
14
|
+
};
|
|
15
|
+
type FactoryMembers<Kind extends CallableKind, Children extends readonly ChildrenOf<Kind>[]> = Kind extends 'node' ? {
|
|
16
|
+
readonly members?: never;
|
|
17
|
+
} : {
|
|
18
|
+
readonly members?: Children;
|
|
19
|
+
};
|
|
20
|
+
interface DefinitionOptions<Kind extends CallableKind, Input, Output, Children extends readonly ChildrenOf<Kind>[], Deps extends ResourceRequests, Delta, Common extends ResourceRequests = EmptyDependencies> {
|
|
21
|
+
readonly name?: string;
|
|
22
|
+
readonly label?: string;
|
|
23
|
+
readonly source?: string;
|
|
24
|
+
readonly checkpoint?: Omit<InvocationCheckpointDefinition<Input, Output, Kind, NoInfer<Delta>>, 'receptions'> & {
|
|
25
|
+
readonly receptions?: Kind extends 'node' ? never : readonly ReceptionRegistration<NoInfer<Children[number]>>[];
|
|
26
|
+
};
|
|
27
|
+
readonly deps?: LocalDependencies<Common, Deps>;
|
|
28
|
+
readonly run: (work: CallableWork<Kind, Input, Output, ResourcesOf<NoInfer<Common & Deps>>, Children[number], Delta>) => Output | Promise<Output>;
|
|
29
|
+
}
|
|
30
|
+
type FactoryDefinition<Kind extends CallableKind, Input, Output, Resources extends object, Delta> = Kind extends 'scene' ? Scene<Input, Output, Resources, Delta> : Kind extends 'group' ? Group<Input, Output, Resources, Delta> : Node<Input, Output, Resources, Delta>;
|
|
31
|
+
interface DefinitionFactory<Kind extends CallableKind, Input, Output, Common extends ResourceRequests = EmptyDependencies> {
|
|
32
|
+
<Delta, const Children extends readonly ChildrenOf<Kind>[] = readonly [], const Deps extends ResourceRequests = Readonly<Record<never, never>>>(options: DefinitionOptions<Kind, Input, Output, Children, Deps, NoInfer<Delta>, Common> & FactoryMembers<Kind, Children> & {
|
|
33
|
+
readonly output: OutputDeclaration<Output, Delta> & {
|
|
34
|
+
readonly delta: (value: unknown) => Delta;
|
|
35
|
+
};
|
|
36
|
+
}): FactoryDefinition<Kind, Input, Output, ResourcesOf<NoInfer<Common & Deps>>, Delta>;
|
|
37
|
+
<const Children extends readonly ChildrenOf<Kind>[] = readonly [], const Deps extends ResourceRequests = Readonly<Record<never, never>>>(options: DefinitionOptions<Kind, Input, Output, Children, Deps, never, Common> & FactoryMembers<Kind, Children> & {
|
|
38
|
+
readonly output?: OutputDeclaration<Output, never>;
|
|
39
|
+
}): FactoryDefinition<Kind, Input, Output, ResourcesOf<NoInfer<Common & Deps>>, never>;
|
|
40
|
+
}
|
|
41
|
+
export declare function defineScene<Input, Output>(): DefinitionFactory<'scene', Input, Output>;
|
|
42
|
+
export declare function defineGroup<Input, Output>(): DefinitionFactory<'group', Input, Output>;
|
|
43
|
+
export declare function defineNode<Input, Output>(): DefinitionFactory<'node', Input, Output>;
|
|
44
|
+
export declare function withDependencies<const Common extends ResourceRequests>(dependencies: Common): Readonly<{
|
|
45
|
+
node<Input, Output>(): DefinitionFactory<"node", Input, Output, Common>;
|
|
46
|
+
group<Input, Output>(): DefinitionFactory<"group", Input, Output, Common>;
|
|
47
|
+
scene<Input, Output>(): DefinitionFactory<"scene", Input, Output, Common>;
|
|
48
|
+
}>;
|
|
49
|
+
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{ResourceRequest}from"@weiliang0121/capix-resources";import{Scene}from"../scene.js";import{Group}from"../group.js";import{Node}from"../node.js";function factory(kind,common){return __name(options=>{if(kind==="node"&&options.members!==void 0)throw new TypeError("Node cannot have members");const members=options.members;for(const field of["setRun","setDefinition","accept","exceptions","raises","maxRounds","uses","observation","callee","receptions"])if(field in options)throw new TypeError(`Unsupported callable configuration field: ${field}`);for(const name of Object.keys(common??{}))if(Object.hasOwn(options.deps??{},name))throw new Error(`Duplicate common dependency alias: ${name}`);const deps=common?Object.freeze({...common,...options.deps}):options.deps,definition={...{name:options.name,label:options.label,source:options.source,deps,run:options.run,output:options.output,checkpoint:options.checkpoint},run:options.run.bind(options)},structure=kind==="scene"?new Scene(definition):kind==="group"?new Group(definition):new Node(definition);return"add"in structure&&structure.add(...members??[]),structure},"create")}__name(factory,"factory");function defineScene(){return factory("scene")}__name(defineScene,"defineScene");function defineGroup(){return factory("group")}__name(defineGroup,"defineGroup");function defineNode(){return factory("node")}__name(defineNode,"defineNode");function withDependencies(dependencies){const common=Object.freeze({...dependencies});for(const request of Object.values(common))if(!(request instanceof ResourceRequest))throw new TypeError("Common dependencies must be resource requests");return Object.freeze({node(){return factory("node",common)},group(){return factory("group",common)},scene(){return factory("scene",common)}})}__name(withDependencies,"withDependencies");export{defineGroup,defineNode,defineScene,withDependencies};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CallableKind } from '@weiliang0121/capix-contracts';
|
|
2
|
+
export declare const childKinds: {
|
|
3
|
+
readonly scene: readonly ["group", "node"];
|
|
4
|
+
readonly group: readonly ["group", "node"];
|
|
5
|
+
readonly node: readonly [];
|
|
6
|
+
};
|
|
7
|
+
export type ChildKind<Kind extends CallableKind> = (typeof childKinds)[Kind][number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CallableKind, ReceptionValue, ReceptionDefinition, ReceptionRegistration, ChildContract } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { ChildContractsOf } from './children.js';
|
|
3
|
+
export type DefinitionReceptions<Kind extends CallableKind> = Kind extends 'node' ? never : readonly ReceptionRegistration<ChildContractsOf<Kind>>[];
|
|
4
|
+
type SynchronousCheck<Check extends (value: unknown) => unknown> = [Extract<ReturnType<Check>, PromiseLike<unknown>>] extends [never] ? unknown : never;
|
|
5
|
+
export declare function reception<Definition extends ChildContract, Check extends (value: unknown) => unknown>(child: Definition, value: {
|
|
6
|
+
readonly check: Check;
|
|
7
|
+
} & NoInfer<Omit<ReceptionValue<ReturnType<Check>>, 'check'>> & SynchronousCheck<Check>): ReceptionDefinition<Definition, ReturnType<Check>>;
|
|
8
|
+
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});function reception(child,value){return Object.freeze({child,value})}__name(reception,"reception");export{reception};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CallableKind, Work, CompositeWork, ChildContract, AuthorCheckpointWriter, ContinuationFact, OutputWork } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import type { ChildContractsOf } from './children.js';
|
|
3
|
+
type Children<Kind extends CallableKind, Allowed extends ChildContractsOf<Kind>, Restoring extends boolean> = Kind extends 'node' ? object : CompositeWork<Allowed, Restoring>;
|
|
4
|
+
export type CallableWork<Kind extends CallableKind, Input, Output, Resources extends object = Record<string, never>, Allowed extends ChildContractsOf<Kind> = ChildContractsOf<Kind>, Delta = never> = Work<Input, Resources> & Children<Kind, Allowed, false> & OutputWork<Delta> & {
|
|
5
|
+
readonly checkpoint?: AuthorCheckpointWriter<Kind, Input, Output, Delta>;
|
|
6
|
+
};
|
|
7
|
+
export type ResumeWork<Kind extends CallableKind, Input, Output, Resources extends object = Record<string, never>, Allowed extends ChildContractsOf<Kind> = ChildContractsOf<Kind>, Delta = never> = Work<Input, Resources> & Children<Kind, Allowed, true> & OutputWork<Delta> & {
|
|
8
|
+
readonly initialInput: Input;
|
|
9
|
+
readonly round: 1 | 2;
|
|
10
|
+
readonly continuation?: ContinuationFact;
|
|
11
|
+
readonly checkpoint?: AuthorCheckpointWriter<Kind, Input, Output, Delta>;
|
|
12
|
+
};
|
|
13
|
+
export type SceneWork<Input, Output, Resources extends object = Record<string, never>, Allowed extends ChildContract = ChildContract, Delta = never> = CallableWork<'scene', Input, Output, Resources, Allowed, Delta>;
|
|
14
|
+
export type GroupWork<Input, Output, Resources extends object = Record<string, never>, Allowed extends ChildContract = ChildContract, Delta = never> = CallableWork<'group', Input, Output, Resources, Allowed, Delta>;
|
|
15
|
+
export type NodeWork<Input, Output, Resources extends object = Record<string, never>, Delta = never> = CallableWork<'node', Input, Output, Resources, never, Delta>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Callable } from './callable.js';
|
|
2
|
+
import type { GroupDefinition } from './definition/group.js';
|
|
3
|
+
import type { Composite, NamedMembers, MemberRegistration, NamedMemberRegistration } from './definition/composition.js';
|
|
4
|
+
import type { ChildCallable } from './definition/children.js';
|
|
5
|
+
import type { EmptyResources } from './definition/callable.js';
|
|
6
|
+
export declare class Group<Input = unknown, Output = unknown, Resources extends object = EmptyResources, Delta = never> extends Callable<Input, Output, 'group', Resources, Delta> implements Composite {
|
|
7
|
+
#private;
|
|
8
|
+
get names(): NamedMembers;
|
|
9
|
+
get members(): readonly ChildCallable[];
|
|
10
|
+
constructor(definition?: GroupDefinition<Input, Output, Resources, Delta>);
|
|
11
|
+
add<const Names extends NamedMembers>(members: MemberRegistration<Names>): this & NamedMemberRegistration<Names>;
|
|
12
|
+
add(...members: readonly ChildCallable[]): this;
|
|
13
|
+
}
|
package/dist/group.js
ADDED
|
@@ -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{Callable}from"./callable.js";import{appendMembers,appendNamedMembers,requireChildCallable}from"./members.js";import{assertStructureConfigurable}from"./configuration.js";class Group extends Callable{static{__name(this,"Group")}#members=Object.freeze([]);#names=Object.freeze({});get names(){return this.#names}get members(){return this.#members}constructor(definition){super("group",definition)}add(...members){if(assertStructureConfigurable(this),members.length===1&&!(members[0]instanceof Callable)){const next=appendNamedMembers(this,this.#members,this.#names,members[0]);this.#members=next.members,this.#names=next.names}else{const additions=[];for(const member of members)requireChildCallable(member),additions.push(member);this.#members=appendMembers(this,this.#members,additions)}return this}}export{Group};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './callable.js';
|
|
2
|
+
export * from './scene.js';
|
|
3
|
+
export * from './group.js';
|
|
4
|
+
export * from './node.js';
|
|
5
|
+
export * from './definition/composition.js';
|
|
6
|
+
export type { ChildKind } from './definition/kind.js';
|
|
7
|
+
export * from './definition/callable.js';
|
|
8
|
+
export * from './definition/scene.js';
|
|
9
|
+
export * from './definition/group.js';
|
|
10
|
+
export * from './definition/node.js';
|
|
11
|
+
export * from './definition/factory.js';
|
|
12
|
+
export * from './definition/work.js';
|
|
13
|
+
export * from './definition/children.js';
|
|
14
|
+
export * from './definition/checkpoint.js';
|
|
15
|
+
export * from './definition/reception.js';
|
|
16
|
+
export * from './composition/sequence.js';
|
|
17
|
+
export type { AuthorCheckpointWriter, BusinessEvent, CallableContract, CallableDelta, CallableInput, CallableKind, CallableOutput, CallableShape, CheckpointCodec, CheckpointContract, CheckpointFacts, CheckpointPointOwner, CheckpointOccurrence, CheckpointReferenceSlots, CheckpointSelection, CheckpointWriteReferences, CheckpointValue, ChildCall, ChildCalls, ChildContract, ChildFact, ChildFacts, ChildInvocationOptions, ChildInvocationReceptionOptions, ChildOperationOptions, ChildOptions, ChildReceptionOptions, ChildReference, ChildReferenceSlot, ChildReturnFact, CompositeWork, ContinuationFact, ExceptionOrigin, InvocationOutputEvent, InvocationOutputReceiver, InvocationOutputWriter, InvocationSignature, OutputDeclaration, ProgressReceiver, ReceptionDefinition, ReceptionRegistration, ReceptionValue, ResumeChildCalls, SavedReferenceFacts, SavedReferences, Work, invocationSignature } from '@weiliang0121/capix-contracts';
|
|
18
|
+
export * from './composition/dynamic.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
export*from"./callable.js";export*from"./scene.js";export*from"./group.js";export*from"./node.js";export*from"./definition/composition.js";export*from"./definition/callable.js";export*from"./definition/scene.js";export*from"./definition/group.js";export*from"./definition/node.js";export*from"./definition/factory.js";export*from"./definition/work.js";export*from"./definition/children.js";export*from"./definition/checkpoint.js";export*from"./definition/reception.js";export*from"./composition/sequence.js";export*from"./composition/dynamic.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChildCallable } from './definition/children.js';
|
|
2
|
+
import type { NamedMembers } from './definition/composition.js';
|
|
3
|
+
export declare function requireChildCallable(value: unknown): asserts value is ChildCallable;
|
|
4
|
+
export declare function appendMembers(owner: {
|
|
5
|
+
readonly kind: 'scene' | 'group';
|
|
6
|
+
}, current: readonly ChildCallable[], additions: readonly ChildCallable[]): readonly ChildCallable[];
|
|
7
|
+
export declare function checkMemberName(name: string): void;
|
|
8
|
+
export declare function appendNamedMembers(owner: {
|
|
9
|
+
readonly kind: 'scene' | 'group';
|
|
10
|
+
}, current: readonly ChildCallable[], names: NamedMembers, additions: unknown): {
|
|
11
|
+
readonly members: readonly ChildCallable[];
|
|
12
|
+
readonly names: NamedMembers;
|
|
13
|
+
};
|
package/dist/members.js
ADDED
|
@@ -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{types}from"node:util";import{Callable}from"./callable.js";import{assertStructureConfigurable,claimStructureMembers}from"./configuration.js";function requireChildCallable(value){if(types.isProxy(value))throw new TypeError("Callable structures cannot be proxies");if(!(value instanceof Callable)||value.kind!=="node"&&!(value.kind==="group"&&"members"in value&&Array.isArray(value.members)))throw new TypeError("Members must be Group or Node objects")}__name(requireChildCallable,"requireChildCallable");function appendMembers(owner,current,additions){for(const member of additions){if(!(member instanceof Callable)||member.kind!=="group"&&member.kind!=="node")throw new TypeError("Members must be Group or Node objects");const visit=__name((candidate,path)=>{if(candidate===owner||path.has(candidate))throw new Error("Cyclic callable membership");if(candidate.kind!=="node"){path.add(candidate);for(const child of candidate.members)visit(child,path);path.delete(candidate)}},"visit");visit(member,new Set)}const next=[...current];for(const member of additions)next.includes(member)||next.push(member);const members=Object.freeze(next);return claimStructureMembers(owner,additions),members}__name(appendMembers,"appendMembers");const reservedNames=new Set(["invoke","create","open","facts","resume","prototype",...Object.getOwnPropertyNames(Object.prototype)]);function checkMemberName(name){if(!name||reservedNames.has(name))throw new TypeError(`Member name is reserved or empty: ${name}`)}__name(checkMemberName,"checkMemberName");function appendNamedMembers(owner,current,names,additions){if(!additions||typeof additions!="object"||Array.isArray(additions)||types.isProxy(additions))throw new TypeError("Named members must be an object");if(Object.getOwnPropertySymbols(additions).length)throw new TypeError("Member names must be strings");const entries=[];for(const[name,descriptor]of Object.entries(Object.getOwnPropertyDescriptors(additions))){if(!("value"in descriptor))throw new TypeError("Named members must use data properties");const member=descriptor.value;if(requireChildCallable(member),entries.push([name,member]),checkMemberName(name),Object.hasOwn(names,name)&&names[name]!==member)throw new Error(`Member name already belongs to another member: ${name}`)}const nextNames=Object.freeze({...names,...Object.fromEntries(entries)});return assertStructureConfigurable(owner),{members:appendMembers(owner,current,entries.map(([,member])=>member)),names:nextNames}}__name(appendNamedMembers,"appendNamedMembers");export{appendMembers,appendNamedMembers,checkMemberName,requireChildCallable};
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Callable } from './callable.js';
|
|
2
|
+
import type { NodeDefinition } from './definition/node.js';
|
|
3
|
+
import type { EmptyResources } from './definition/callable.js';
|
|
4
|
+
export declare class Node<Input = unknown, Output = unknown, Resources extends object = EmptyResources, Delta = never> extends Callable<Input, Output, 'node', Resources, Delta> {
|
|
5
|
+
readonly members?: never;
|
|
6
|
+
constructor(definition?: NodeDefinition<Input, Output, Resources, Delta>);
|
|
7
|
+
}
|
package/dist/node.js
ADDED
|
@@ -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{Callable}from"./callable.js";class Node extends Callable{static{__name(this,"Node")}constructor(definition){super("node",definition)}}export{Node};
|
package/dist/scene.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Callable } from './callable.js';
|
|
2
|
+
import type { SceneDefinition } from './definition/scene.js';
|
|
3
|
+
import type { Composite, NamedMembers, MemberRegistration, NamedMemberRegistration } from './definition/composition.js';
|
|
4
|
+
import type { ChildCallable } from './definition/children.js';
|
|
5
|
+
import type { EmptyResources } from './definition/callable.js';
|
|
6
|
+
import type { CallableContract } from '@weiliang0121/capix-contracts';
|
|
7
|
+
export declare class Scene<Input = unknown, Output = unknown, Resources extends object = EmptyResources, Delta = never> extends Callable<Input, Output, 'scene', Resources, Delta> implements Composite {
|
|
8
|
+
#private;
|
|
9
|
+
get names(): NamedMembers;
|
|
10
|
+
get members(): readonly ChildCallable[];
|
|
11
|
+
constructor(child: ChildCallable & CallableContract<'group' | 'node', Input, Output, unknown>);
|
|
12
|
+
constructor(definition?: SceneDefinition<Input, Output, Resources, Delta>);
|
|
13
|
+
add<const Names extends NamedMembers>(members: MemberRegistration<Names>): this & NamedMemberRegistration<Names>;
|
|
14
|
+
add(...members: readonly ChildCallable[]): this;
|
|
15
|
+
}
|
package/dist/scene.js
ADDED
|
@@ -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{Callable}from"./callable.js";import{appendMembers,appendNamedMembers,requireChildCallable}from"./members.js";import{assertStructureConfigurable}from"./configuration.js";class Scene extends Callable{static{__name(this,"Scene")}#members=Object.freeze([]);#names=Object.freeze({});get names(){return this.#names}get members(){return this.#members}constructor(definition){definition instanceof Callable?(requireChildCallable(definition),super("scene"),this.add(definition),this.run=async work=>await work.children.invoke(definition,work.input)):super("scene",definition)}add(...members){if(assertStructureConfigurable(this),members.length===1&&!(members[0]instanceof Callable)){const next=appendNamedMembers(this,this.#members,this.#names,members[0]);this.#members=next.members,this.#names=next.names}else{const additions=[];for(const member of members)requireChildCallable(member),additions.push(member);this.#members=appendMembers(this,this.#members,additions)}return this}}export{Scene};
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weiliang0121/capix-structure",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./construction": {
|
|
12
|
+
"types": "./dist/construction.d.ts",
|
|
13
|
+
"import": "./dist/construction.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@weiliang0121/capix-resources": "0.1.0",
|
|
18
|
+
"@weiliang0121/capix-contracts": "0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"description": "Composable Scene, Group, and Node structures for CAPiX.",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "wei.liang (https://github.com/weiliang0121)",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/weiliang0121/capix.git",
|
|
26
|
+
"directory": "server/structure"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.23.2"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/**/*.js",
|
|
35
|
+
"dist/**/*.d.ts",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://registry.npmjs.org"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
46
|
+
}
|
|
6
47
|
}
|