@weiliang0121/capix-contracts 0.0.0-stage → 0.2.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -2
  3. package/dist/callable/kind.d.ts +2 -0
  4. package/dist/callable/kind.js +2 -0
  5. package/dist/callable/signature.d.ts +26 -0
  6. package/dist/callable/signature.js +1 -0
  7. package/dist/checkpoint/codec.d.ts +12 -0
  8. package/dist/checkpoint/codec.js +1 -0
  9. package/dist/checkpoint/facts.d.ts +12 -0
  10. package/dist/checkpoint/facts.js +1 -0
  11. package/dist/checkpoint/history.d.ts +14 -0
  12. package/dist/checkpoint/history.js +1 -0
  13. package/dist/checkpoint/index.d.ts +6 -0
  14. package/dist/checkpoint/index.js +1 -0
  15. package/dist/checkpoint/reception.d.ts +23 -0
  16. package/dist/checkpoint/reception.js +1 -0
  17. package/dist/checkpoint/references.d.ts +31 -0
  18. package/dist/checkpoint/references.js +1 -0
  19. package/dist/checkpoint/writer.d.ts +33 -0
  20. package/dist/checkpoint/writer.js +1 -0
  21. package/dist/children/call.d.ts +34 -0
  22. package/dist/children/call.js +1 -0
  23. package/dist/children/contract.d.ts +2 -0
  24. package/dist/children/contract.js +1 -0
  25. package/dist/children/facts.d.ts +53 -0
  26. package/dist/children/facts.js +1 -0
  27. package/dist/children/index.d.ts +5 -0
  28. package/dist/children/index.js +1 -0
  29. package/dist/children/options.d.ts +32 -0
  30. package/dist/children/options.js +1 -0
  31. package/dist/children/reference.d.ts +5 -0
  32. package/dist/children/reference.js +1 -0
  33. package/dist/diagnostic.d.ts +18 -0
  34. package/dist/diagnostic.js +1 -0
  35. package/dist/errors.d.ts +5 -0
  36. package/dist/errors.js +2 -0
  37. package/dist/index.d.ts +14 -0
  38. package/dist/index.js +2 -0
  39. package/dist/invocation.d.ts +15 -0
  40. package/dist/invocation.js +1 -0
  41. package/dist/observation.d.ts +4 -0
  42. package/dist/observation.js +1 -0
  43. package/dist/operation.d.ts +22 -0
  44. package/dist/operation.js +1 -0
  45. package/dist/output.d.ts +30 -0
  46. package/dist/output.js +1 -0
  47. package/dist/value.d.ts +18 -0
  48. package/dist/value.js +2 -0
  49. package/dist/work.d.ts +16 -0
  50. package/dist/work.js +1 -0
  51. package/package.json +37 -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,19 @@
1
- # Temporary Holding Version
1
+ # @weiliang0121/capix-contracts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared contracts, stable data values, and runtime errors 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-contracts
9
+ ```
10
+
11
+ ## Public entry points
12
+
13
+ - `@weiliang0121/capix-contracts`
14
+
15
+ 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.
16
+
17
+ ## License
18
+
19
+ MIT. Copyright (c) 2026 wei.liang. See [LICENSE](LICENSE).
@@ -0,0 +1,2 @@
1
+ export declare const callableKinds: readonly ["scene", "group", "node"];
2
+ export type CallableKind = (typeof callableKinds)[number];
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ const callableKinds=["scene","group","node"];export{callableKinds};
@@ -0,0 +1,26 @@
1
+ import type { CallableKind } from './kind.js';
2
+ export declare const invocationSignature: unique symbol;
3
+ export interface InvocationSignature<Input, Output, Delta = never> {
4
+ readonly input: Input;
5
+ readonly acceptsInput: (input: Input) => void;
6
+ readonly output: Output;
7
+ readonly delta: Delta;
8
+ }
9
+ export interface CallableContract<Kind extends CallableKind = CallableKind, Input = unknown, Output = unknown, Delta = unknown> {
10
+ readonly kind: Kind;
11
+ readonly [invocationSignature]: InvocationSignature<Input, Output, Delta>;
12
+ }
13
+ type Signature<Definition> = Definition extends {
14
+ readonly [invocationSignature]?: infer S;
15
+ } ? NonNullable<S> : InvocationSignature<unknown, unknown, unknown>;
16
+ export type CallableInput<Callable> = Signature<Callable> extends {
17
+ readonly input: infer Input;
18
+ } ? Input : unknown;
19
+ export type CallableOutput<Callable> = Signature<Callable> extends {
20
+ readonly output: infer Output;
21
+ } ? Output : unknown;
22
+ export type CallableDelta<Callable> = Signature<Callable> extends {
23
+ readonly delta: infer Delta;
24
+ } ? Delta : never;
25
+ export type CallableShape<Structure> = Structure extends CallableContract<infer Kind, infer Input, infer Output, infer Delta> ? CallableContract<Kind, Input, Output, Delta> : never;
26
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,12 @@
1
+ import type { Stable } from '../value.js';
2
+ export type CheckpointValue = null | boolean | number | string | readonly CheckpointValue[] | {
3
+ readonly [key: string]: CheckpointValue;
4
+ };
5
+ export interface CheckpointCodec<Value> {
6
+ encode(value: Stable<Value>): CheckpointValue;
7
+ decode(value: CheckpointValue): Value | Stable<Value>;
8
+ }
9
+ export interface CheckpointContract {
10
+ readonly key: string;
11
+ readonly version: number;
12
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,12 @@
1
+ import type { Stable } from '../value.js';
2
+ import type { ChildFacts } from '../children/facts.js';
3
+ import type { ContinuationFact } from './history.js';
4
+ import type { CheckpointReferenceSlots, SavedReferenceFacts } from './references.js';
5
+ export interface CheckpointFacts<Input, Slots extends CheckpointReferenceSlots = CheckpointReferenceSlots> {
6
+ readonly initialInput: Stable<Input>;
7
+ readonly input: Stable<Input>;
8
+ readonly round: 1 | 2;
9
+ readonly continuation?: ContinuationFact;
10
+ readonly references: SavedReferenceFacts<Slots>;
11
+ readonly children: ChildFacts;
12
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,14 @@
1
+ import type { ChildReference } from '../children/reference.js';
2
+ export type ExceptionOrigin = {
3
+ readonly kind: 'self';
4
+ readonly phase: 'execute' | 'accept';
5
+ } | {
6
+ readonly kind: 'child-return' | 'child-reception';
7
+ readonly child: ChildReference;
8
+ };
9
+ export interface ContinuationFact {
10
+ readonly fromRound: 1;
11
+ readonly stage: 'accept' | 'handling';
12
+ readonly reason: string;
13
+ readonly origin?: ExceptionOrigin;
14
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,6 @@
1
+ export type * from './codec.js';
2
+ export type * from './history.js';
3
+ export type * from './references.js';
4
+ export type * from './facts.js';
5
+ export type * from './writer.js';
6
+ export type * from './reception.js';
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,23 @@
1
+ import type { Stable } from '../value.js';
2
+ import type { CheckpointValue } from './codec.js';
3
+ import type { ChildContract } from '../children/contract.js';
4
+ import type { CallableShape } from '../callable/signature.js';
5
+ export interface ReceptionValue<Value> {
6
+ readonly check: (value: unknown) => Value | Stable<Value>;
7
+ readonly encode: (value: NoInfer<Stable<Value>>) => CheckpointValue;
8
+ readonly decode: (value: CheckpointValue) => NoInfer<Value> | NoInfer<Stable<Value>>;
9
+ }
10
+ declare const receptionSignature: unique symbol;
11
+ interface ReceptionContract<Definition extends ChildContract, Value> {
12
+ readonly child: Definition;
13
+ readonly value: ReceptionValue<Value>;
14
+ readonly [receptionSignature]: (child: Definition, value: Value) => {
15
+ readonly child: Definition;
16
+ readonly value: Value;
17
+ };
18
+ }
19
+ export type ReceptionDefinition<Definition extends ChildContract, Value> = ReceptionContract<CallableShape<Definition>, Value>;
20
+ export type ReceptionRegistration<Definition extends ChildContract = ChildContract> = ReceptionContract<any, any> & {
21
+ readonly child: CallableShape<Definition>;
22
+ };
23
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,31 @@
1
+ import type { ChildContract } from '../children/contract.js';
2
+ import type { ChildReference } from '../children/reference.js';
3
+ import type { ChildFact } from '../children/facts.js';
4
+ export interface ChildReferenceSlot<Definition extends ChildContract = ChildContract, Many extends boolean = boolean> {
5
+ readonly definition: Definition;
6
+ readonly many: Many;
7
+ }
8
+ export type CheckpointReferenceSlots = Readonly<Record<string, ChildReferenceSlot>>;
9
+ declare const occurrenceDefinition: unique symbol;
10
+ declare const selectionDefinition: unique symbol;
11
+ export interface CheckpointOccurrence<Definition extends ChildContract = ChildContract> {
12
+ readonly [occurrenceDefinition]: Definition;
13
+ }
14
+ export interface CheckpointSelection<Definition extends ChildContract = ChildContract> extends Iterable<ChildReference<Definition>> {
15
+ readonly [selectionDefinition]: Definition;
16
+ readonly length: number;
17
+ at(index: number): ChildReference<Definition> | undefined;
18
+ occurrenceAt(index: number): CheckpointOccurrence<Definition> | undefined;
19
+ add(reference: ChildReference<Definition>): CheckpointOccurrence<Definition>;
20
+ remove(occurrence: CheckpointOccurrence<Definition>): void;
21
+ }
22
+ export type SavedReferences<Slots extends CheckpointReferenceSlots> = {
23
+ readonly [Key in keyof Slots]: Slots[Key] extends ChildReferenceSlot<infer Definition, infer Many> ? (Many extends true ? readonly ChildReference<Definition>[] : ChildReference<Definition>) : never;
24
+ };
25
+ export type CheckpointWriteReferences<Slots extends CheckpointReferenceSlots> = {
26
+ readonly [Key in keyof Slots]: Slots[Key] extends ChildReferenceSlot<infer Definition, infer Many> ? (Many extends true ? readonly ChildReference<Definition>[] | CheckpointSelection<Definition> : ChildReference<Definition>) : never;
27
+ };
28
+ export type SavedReferenceFacts<Slots extends CheckpointReferenceSlots> = {
29
+ readonly [Key in keyof Slots]: Slots[Key] extends ChildReferenceSlot<infer Definition, infer Many> ? (Many extends true ? readonly ChildFact<Definition>[] : ChildFact<Definition>) : never;
30
+ };
31
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,33 @@
1
+ import type { CallableKind } from '../callable/kind.js';
2
+ import type { CheckpointCodec } from './codec.js';
3
+ import type { CheckpointReferenceSlots, CheckpointWriteReferences, CheckpointSelection } from './references.js';
4
+ import type { ChildContract } from '../children/contract.js';
5
+ import type { ChildReference } from '../children/reference.js';
6
+ declare const checkpointOwner: unique symbol;
7
+ export interface CheckpointPointOwner<Kind extends CallableKind, Input, Output, Delta> {
8
+ readonly [checkpointOwner]?: (owner: {
9
+ readonly kind: Kind;
10
+ readonly input: Input;
11
+ readonly output: Output;
12
+ }) => {
13
+ readonly kind: Kind;
14
+ readonly input: Input;
15
+ readonly output: Output;
16
+ readonly delta: Delta;
17
+ };
18
+ }
19
+ export interface AuthorCheckpointWriter<Kind extends CallableKind, Input, Output, Delta = never> {
20
+ <Point extends CheckpointPointOwner<Kind, Input, Output, Delta> & {
21
+ readonly state: CheckpointCodec<any>;
22
+ readonly references: CheckpointReferenceSlots;
23
+ }>(options: {
24
+ readonly point: Point;
25
+ readonly state: NoInfer<ReturnType<Point['state']['decode']>>;
26
+ } & (keyof Point['references'] extends never ? {
27
+ readonly refs?: NoInfer<CheckpointWriteReferences<Point['references']>>;
28
+ } : {
29
+ readonly refs: NoInfer<CheckpointWriteReferences<Point['references']>>;
30
+ })): void;
31
+ select<Definition extends ChildContract>(definition: Kind extends 'node' ? never : Definition, initial?: readonly ChildReference<NoInfer<Definition>>[]): CheckpointSelection<Definition>;
32
+ }
33
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,34 @@
1
+ import type { Stable } from '../value.js';
2
+ import type { CallableInput, CallableOutput, CallableShape } from '../callable/signature.js';
3
+ import type { OperationResult } from '../operation.js';
4
+ import type { ReceptionDefinition } from '../checkpoint/reception.js';
5
+ import type { ChildReference } from './reference.js';
6
+ import type { ChildContract } from './contract.js';
7
+ import type { ChildFacts } from './facts.js';
8
+ import type { ChildOptions, ChildOperationOptions, ChildReceptionOptions, ChildInvocationOptions, ChildInvocationReceptionOptions } from './options.js';
9
+ export interface ChildCall<Definition extends ChildContract> {
10
+ readonly ref: ChildReference<Definition>;
11
+ readonly key?: string;
12
+ invoke(): Promise<Stable<CallableOutput<Definition>>>;
13
+ invoke<Value, const Options extends NoInfer<ChildInvocationReceptionOptions<Definition, Value>>>(options: Options & {
14
+ readonly reception: ReceptionDefinition<Definition, Value>;
15
+ }): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
16
+ invoke<const Options extends ChildInvocationOptions<Definition>>(options: Options & ChildInvocationOptions<Definition>): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
17
+ run(): Promise<Stable<CallableOutput<Definition>>>;
18
+ accept(): Promise<Stable<CallableOutput<Definition>>>;
19
+ accept<Value>(receive: (output: Stable<CallableOutput<Definition>>) => Value | Stable<Value> | Promise<Value | Stable<Value>>): Promise<Stable<Value>>;
20
+ accept<Value>(reception: ReceptionDefinition<Definition, Value>, receive: (output: Stable<CallableOutput<Definition>>) => NoInfer<Value> | NoInfer<Stable<Value>> | Promise<NoInfer<Value> | NoInfer<Stable<Value>>>): Promise<Stable<Value>>;
21
+ }
22
+ export interface ChildCalls<Allowed extends ChildContract = ChildContract> {
23
+ invoke<Definition extends Allowed | CallableShape<Allowed>>(definition: Definition, input: NoInfer<CallableInput<Definition> | Stable<CallableInput<Definition>>>): Promise<Stable<CallableOutput<Definition>>>;
24
+ invoke<Definition extends Allowed | CallableShape<Allowed>, Value, const Options extends NoInfer<ChildReceptionOptions<Definition, Value>>>(definition: Definition, input: NoInfer<CallableInput<Definition> | Stable<CallableInput<Definition>>>, options: Options & {
25
+ readonly reception: ReceptionDefinition<NoInfer<Definition>, Value>;
26
+ }): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
27
+ invoke<Definition extends Allowed | CallableShape<Allowed>, const Options extends ChildOperationOptions<NoInfer<Definition>>>(definition: Definition, input: NoInfer<CallableInput<Definition> | Stable<CallableInput<Definition>>>, options: Options & ChildOperationOptions<NoInfer<Definition>>): Promise<Stable<OperationResult<Stable<CallableOutput<Definition>>, Options>>>;
28
+ create<Definition extends Allowed | CallableShape<Allowed>>(definition: Definition, input: NoInfer<CallableInput<Definition> | Stable<CallableInput<Definition>>>, options?: ChildOptions<Definition>): ChildCall<Definition>;
29
+ open<Definition extends ChildContract>(reference: ChildReference<Definition>): ChildCall<Definition>;
30
+ readonly facts: ChildFacts;
31
+ }
32
+ export interface ResumeChildCalls<Allowed extends ChildContract = ChildContract> extends ChildCalls<Allowed> {
33
+ resume<Definition extends Allowed | CallableShape<Allowed>>(reference: ChildReference<Definition>): ChildCall<Definition>;
34
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,2 @@
1
+ import type { CallableContract } from '../callable/signature.js';
2
+ export type ChildContract = CallableContract<'group', any> | CallableContract<'node', any>;
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,53 @@
1
+ import type { Stable } from '../value.js';
2
+ import type { CallableInput, CallableOutput } from '../callable/signature.js';
3
+ import type { InvocationFailureFact, RuntimeErrorValue } from '../diagnostic.js';
4
+ import type { ReceptionDefinition } from '../checkpoint/reception.js';
5
+ import type { ChildReference } from './reference.js';
6
+ import type { ChildContract } from './contract.js';
7
+ export type ChildReturnFact<Output> = {
8
+ readonly status: 'succeeded';
9
+ readonly output: Stable<Output>;
10
+ } | {
11
+ readonly status: 'failed';
12
+ readonly diagnostic: Stable<RuntimeErrorValue>;
13
+ readonly failure?: InvocationFailureFact;
14
+ } | {
15
+ readonly status: 'cancelled';
16
+ readonly diagnostic: Stable<RuntimeErrorValue>;
17
+ };
18
+ export interface ChildFact<Definition = unknown> {
19
+ readonly ref: ChildReference<Definition>;
20
+ readonly key?: string;
21
+ readonly parentRound: 1 | 2;
22
+ readonly order: number;
23
+ readonly input: Stable<CallableInput<Definition>>;
24
+ readonly returned: ChildReturnFact<CallableOutput<Definition>> | undefined;
25
+ readonly reception: {
26
+ readonly status: 'pending' | 'receiving';
27
+ } | {
28
+ readonly status: 'accepted' | 'handled';
29
+ readonly value: unknown;
30
+ } | {
31
+ readonly status: 'failed';
32
+ readonly diagnostic: Stable<RuntimeErrorValue>;
33
+ readonly failure?: InvocationFailureFact;
34
+ };
35
+ readonly progress?: {
36
+ readonly round: 1 | 2;
37
+ readonly currentInput: Stable<CallableInput<Definition>>;
38
+ readonly phase: 'execute' | 'receive' | 'handling';
39
+ };
40
+ }
41
+ export interface ChildFacts {
42
+ accepted<Definition extends ChildContract, Value>(reference: ChildReference<Definition>, reception: ReceptionDefinition<NoInfer<Definition>, Value>): Stable<Value>;
43
+ handled<Definition extends ChildContract, Value>(reference: ChildReference<Definition>, reception: ReceptionDefinition<NoInfer<Definition>, Value>): Stable<Value>;
44
+ get<Definition extends ChildContract>(reference: ChildReference<Definition>): ChildFact<Definition>;
45
+ require<Definition extends ChildContract>(definition: Definition, reference: ChildReference): ChildFact<Definition>;
46
+ list<Definition extends ChildContract>(definition: Definition, query?: {
47
+ readonly parentRound?: 1 | 2;
48
+ }): readonly ChildFact<Definition>[];
49
+ requireUnique<Definition extends ChildContract>(definition: Definition, query: {
50
+ readonly parentRound: 1 | 2;
51
+ }): ChildFact<Definition>;
52
+ values(): readonly ChildFact[];
53
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,5 @@
1
+ export type * from './contract.js';
2
+ export type * from './reference.js';
3
+ export type * from './call.js';
4
+ export type * from './facts.js';
5
+ export type * from './options.js';
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,32 @@
1
+ import type { Stable } from '../value.js';
2
+ import type { CallableDelta, CallableOutput } from '../callable/signature.js';
3
+ import type { InvocationOutputReceiver } from '../output.js';
4
+ import type { OperationOptions, Reception } from '../operation.js';
5
+ import type { ReceptionDefinition } from '../checkpoint/reception.js';
6
+ import type { ChildContract } from './contract.js';
7
+ export interface ChildOptions<Definition extends ChildContract> {
8
+ readonly key?: string;
9
+ readonly output?: InvocationOutputReceiver<CallableOutput<Definition>, CallableDelta<Definition>>;
10
+ }
11
+ export type ChildOperationOptions<Definition extends ChildContract> = ChildOptions<Definition> & OperationOptions<Stable<CallableOutput<Definition>>, unknown, unknown, Stable<CallableDelta<Definition>>> & {
12
+ readonly reception?: never;
13
+ };
14
+ export type ChildReceptionOptions<Definition extends ChildContract, Value> = ChildOptions<Definition> & Pick<OperationOptions<Stable<CallableOutput<Definition>>, unknown, unknown, Stable<CallableDelta<Definition>>>, 'delta'> & {
15
+ readonly reception: ReceptionDefinition<Definition, Value>;
16
+ } & ([Stable<CallableOutput<Definition>>] extends [Value | Stable<Value>] ? {
17
+ readonly result?: Reception<Stable<CallableOutput<Definition>>, unknown, NoInfer<Value> | NoInfer<Stable<Value>>>;
18
+ } : {
19
+ readonly result: Reception<Stable<CallableOutput<Definition>>, unknown, NoInfer<Value> | NoInfer<Stable<Value>>> & {
20
+ readonly succeeded: (value: Stable<CallableOutput<Definition>>) => NoInfer<Value> | NoInfer<Stable<Value>> | PromiseLike<NoInfer<Value> | NoInfer<Stable<Value>>>;
21
+ };
22
+ });
23
+ export type ChildInvocationOptions<Definition extends ChildContract> = Pick<ChildOperationOptions<Definition>, 'result' | 'reception'> & {
24
+ readonly delta?: never;
25
+ readonly output?: never;
26
+ readonly key?: never;
27
+ };
28
+ export type ChildInvocationReceptionOptions<Definition extends ChildContract, Value> = Omit<ChildReceptionOptions<Definition, Value>, 'delta' | 'output' | 'key'> & {
29
+ readonly delta?: never;
30
+ readonly output?: never;
31
+ readonly key?: never;
32
+ };
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,5 @@
1
+ declare const childReferenceSignature: unique symbol;
2
+ export interface ChildReference<Definition = unknown> {
3
+ readonly [childReferenceSignature]: Definition;
4
+ }
5
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,18 @@
1
+ export type RuntimeErrorDetail = null | boolean | number | string | RuntimeErrorDetail[] | {
2
+ [key: string]: RuntimeErrorDetail;
3
+ };
4
+ export interface RuntimeErrorValue {
5
+ code: string;
6
+ message: string;
7
+ name?: string;
8
+ stack?: string;
9
+ detail?: RuntimeErrorDetail;
10
+ cause?: RuntimeErrorValue;
11
+ errors?: RuntimeErrorValue[];
12
+ }
13
+ export interface InvocationFailureFact {
14
+ readonly kind: 'exception' | 'error';
15
+ readonly phase: 'setup' | 'execute' | 'receive' | 'handling' | 'control' | 'observation';
16
+ readonly contextId: string;
17
+ readonly contract?: string;
18
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,5 @@
1
+ export declare class RuntimeError extends Error {
2
+ readonly code: string;
3
+ readonly detail?: unknown | undefined;
4
+ constructor(code: string, message: string, detail?: unknown | undefined, options?: ErrorOptions);
5
+ }
package/dist/errors.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});class RuntimeError extends Error{static{__name(this,"RuntimeError")}code;detail;constructor(code,message,detail,options){super(message,options),this.code=code,this.detail=detail,this.name=new.target.name}}export{RuntimeError};
@@ -0,0 +1,14 @@
1
+ export { callableKinds } from './callable/kind.js';
2
+ export type { CallableKind } from './callable/kind.js';
3
+ export type * from './callable/signature.js';
4
+ export type { InvocationIdentity, InvocationOrigin, InvocationRelationIdentity } from './invocation.js';
5
+ export { stableValue, stableValueLimits, StableValueError } from './value.js';
6
+ export type { Stable, StableArray, StableValueErrorCode } from './value.js';
7
+ export type * from './operation.js';
8
+ export type * from './children/index.js';
9
+ export type * from './work.js';
10
+ export type * from './output.js';
11
+ export type * from './observation.js';
12
+ export type * from './checkpoint/index.js';
13
+ export type * from './diagnostic.js';
14
+ export { RuntimeError } from './errors.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ import{callableKinds}from"./callable/kind.js";import{stableValue,stableValueLimits,StableValueError}from"./value.js";import{RuntimeError}from"./errors.js";export{RuntimeError,StableValueError,callableKinds,stableValue,stableValueLimits};
@@ -0,0 +1,15 @@
1
+ import type { CallableKind } from './callable/kind.js';
2
+ export interface InvocationIdentity {
3
+ readonly contextId: string;
4
+ readonly kind: CallableKind;
5
+ readonly parentContextId?: string;
6
+ }
7
+ export interface InvocationOrigin {
8
+ readonly contextId: string;
9
+ }
10
+ export interface InvocationRelationIdentity {
11
+ readonly parentContextId: string;
12
+ readonly childContextId: string;
13
+ readonly parentRound: number;
14
+ readonly key?: string;
15
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,4 @@
1
+ export interface BusinessEvent {
2
+ readonly event: string;
3
+ readonly [field: string]: unknown;
4
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,22 @@
1
+ export type OperationOutcome<Value, Failure = unknown> = {
2
+ readonly status: 'succeeded';
3
+ readonly value: Value;
4
+ } | {
5
+ readonly status: 'failed';
6
+ readonly failure: Failure;
7
+ };
8
+ export interface Reception<Value, Failure = unknown, Result = Value> {
9
+ readonly succeeded?: (value: Value) => Result | PromiseLike<Result>;
10
+ readonly failed?: (failure: Failure) => Result | PromiseLike<Result>;
11
+ }
12
+ export interface OperationOptions<Value, Failure = unknown, Result = Value, Delta = never> {
13
+ readonly delta?: [Delta] extends [never] ? never : (delta: Delta) => void;
14
+ readonly result?: Reception<Value, Failure, Result>;
15
+ }
16
+ type CallbackResult<Callback, Fallback = never> = Callback extends (...args: never[]) => infer Result ? Awaited<Result> : Fallback;
17
+ type PropertyValue<Owner, Key extends PropertyKey> = Owner extends unknown ? (Key extends keyof Owner ? Owner[Key] : undefined) : never;
18
+ type ResultReception<Options> = PropertyValue<Options, 'result'>;
19
+ type SuccessfulResult<Value, Handler> = [Handler] extends [never] ? Value : CallbackResult<PropertyValue<Handler, 'succeeded'>, Value>;
20
+ type FailedResult<Handler> = CallbackResult<PropertyValue<Handler, 'failed'>>;
21
+ export type OperationResult<Value, Options> = SuccessfulResult<Value, ResultReception<Options>> | FailedResult<ResultReception<Options>>;
22
+ export {};
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,30 @@
1
+ import type { Stable } from './value.js';
2
+ export interface OutputDeclaration<Result, Delta = never> {
3
+ result(value: unknown): Result | Stable<Result>;
4
+ delta?(value: unknown): Delta | Stable<Delta>;
5
+ }
6
+ export interface InvocationOutputWriter<Delta> {
7
+ emit(delta: Delta | Stable<Delta>): void;
8
+ }
9
+ export type InvocationOutputEvent<Result = unknown, Delta = unknown> = Readonly<{
10
+ contextId: string;
11
+ round: number;
12
+ sequence: number;
13
+ } & ({
14
+ kind: 'started' | 'sealed';
15
+ } | {
16
+ kind: 'delta';
17
+ delta: Stable<Delta>;
18
+ } | {
19
+ kind: 'discarded';
20
+ reason: 'exception' | 'continue' | 'failed';
21
+ } | {
22
+ kind: 'completed';
23
+ result: Stable<Result>;
24
+ discarded: boolean;
25
+ })>;
26
+ export interface ProgressReceiver<Fact> {
27
+ receive(fact: Readonly<Fact>): undefined;
28
+ failed?(error: unknown): undefined;
29
+ }
30
+ export type InvocationOutputReceiver<Result = unknown, Delta = unknown> = ProgressReceiver<InvocationOutputEvent<Result, Delta>>;
package/dist/output.js ADDED
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,18 @@
1
+ export type Stable<T> = T extends (...args: never[]) => unknown ? never : T extends readonly unknown[] ? (number extends T['length'] ? StableArray<Stable<T[number]>> : {
2
+ readonly [Key in keyof T]: Stable<T[Key]>;
3
+ }) : T extends object ? {
4
+ readonly [Key in keyof T]: Stable<T[Key]>;
5
+ } : T;
6
+ export interface StableArray<T> extends ReadonlyArray<T> {
7
+ }
8
+ export declare const stableValueLimits: Readonly<{
9
+ maxDepth: 64;
10
+ maxExpandedValues: 1000000;
11
+ maxTextUnits: number;
12
+ }>;
13
+ export type StableValueErrorCode = 'UNSUPPORTED_VALUE' | 'CYCLIC_VALUE' | 'DEPTH_LIMIT' | 'VALUE_LIMIT' | 'TEXT_LIMIT' | 'INSPECTION_FAILED';
14
+ export declare class StableValueError extends Error {
15
+ readonly code: StableValueErrorCode;
16
+ constructor(code: StableValueErrorCode);
17
+ }
18
+ export declare function stableValue<T>(value: T | Stable<T>): Stable<T>;
package/dist/value.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});const stableValueLimits=Object.freeze({maxDepth:64,maxExpandedValues:1e6,maxTextUnits:67108864}),messages=Object.freeze({UNSUPPORTED_VALUE:"Stable values require ordinary data records, dense arrays and supported scalar values",CYCLIC_VALUE:"Stable values cannot contain cycles",DEPTH_LIMIT:"Stable value exceeds its depth limit",VALUE_LIMIT:"Stable value exceeds its expanded value limit",TEXT_LIMIT:"Stable value exceeds its expanded text limit",INSPECTION_FAILED:"Stable value could not be inspected"}),errors=new WeakSet;class StableValueError extends Error{static{__name(this,"StableValueError")}code;constructor(code){const safeCode=typeof code=="string"&&Object.hasOwn(messages,code)?code:"INSPECTION_FAILED";super(messages[safeCode]),this.name="StableValueError",this.code=safeCode}}const trusted=new WeakMap;function fail(code){const error=Object.freeze(new StableValueError(code));throw errors.add(error),error}__name(fail,"fail");function depthWithin(depth){depth>stableValueLimits.maxDepth&&fail("DEPTH_LIMIT")}__name(depthWithin,"depthWithin");function textWithin(text){text>stableValueLimits.maxTextUnits&&fail("TEXT_LIMIT")}__name(textWithin,"textWithin");function stableValue(value){try{const memo=new WeakMap,ancestors=new Set,completed=[],visit=__name((source,depth)=>{if(depthWithin(depth),source==null||typeof source=="boolean"||typeof source=="string"||typeof source=="number"&&Number.isFinite(source)){const text2=typeof source=="string"?source.length:0;return textWithin(text2),{value:source,proof:{height:0,values:1,text:text2}}}typeof source!="object"&&fail("UNSUPPORTED_VALUE"),ancestors.has(source)&&fail("CYCLIC_VALUE");const prior=memo.get(source);if(prior)return depthWithin(depth+prior.proof.height),prior;const evidence=trusted.get(source);if(evidence)return depthWithin(depth+evidence.height),{value:source,proof:evidence};const array=Array.isArray(source),prototype=Object.getPrototypeOf(source);(array?prototype!==Array.prototype:prototype!==Object.prototype&&prototype!==null)&&fail("UNSUPPORTED_VALUE");const keys=Reflect.ownKeys(source),entries=keys.length-(array?1:0);if(entries+1>stableValueLimits.maxExpandedValues&&fail("VALUE_LIMIT"),array){const length=Object.getOwnPropertyDescriptor(source,"length");(!length||!Object.hasOwn(length,"value")||length.value!==entries)&&fail("UNSUPPORTED_VALUE")}const owned=array?[]:Object.create(prototype===null?null:Object.prototype);let height=0,values=1,text=0,index=0;ancestors.add(source);try{for(const key of keys){if(typeof key!="string"&&fail("UNSUPPORTED_VALUE"),array&&key==="length")continue;array&&key!==String(index++)&&fail("UNSUPPORTED_VALUE");const descriptor=Object.getOwnPropertyDescriptor(source,key);(!descriptor||!descriptor.enumerable||!Object.hasOwn(descriptor,"value"))&&fail("UNSUPPORTED_VALUE");const child=visit(descriptor.value,depth+1);height=Math.max(height,child.proof.height+1),values+=child.proof.values,values>stableValueLimits.maxExpandedValues&&fail("VALUE_LIMIT"),text+=child.proof.text+(array?0:key.length),textWithin(text),Object.defineProperty(owned,key,{value:child.value,enumerable:!0})}Object.freeze(owned);const proof=Object.freeze({height,values,text}),fixed=Object.freeze({value:owned,proof});return memo.set(source,fixed),completed.push({value:owned,proof}),fixed}finally{ancestors.delete(source)}},"visit"),result=visit(value,0);for(const entry of completed)trusted.set(entry.value,entry.proof);return result.value}catch(cause){throw cause!==null&&(typeof cause=="object"||typeof cause=="function")&&errors.has(cause)?cause:new StableValueError("INSPECTION_FAILED")}}__name(stableValue,"stableValue");export{StableValueError,stableValue,stableValueLimits};
package/dist/work.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { Stable } from './value.js';
2
+ import type { ChildCalls, ChildContract, ResumeChildCalls } from './children/index.js';
3
+ import type { BusinessEvent } from './observation.js';
4
+ import type { InvocationOutputWriter } from './output.js';
5
+ export interface Work<Input, Resources extends object> {
6
+ readonly input: Stable<Input>;
7
+ readonly resources: Readonly<Resources>;
8
+ readonly signal: AbortSignal;
9
+ observation(event: BusinessEvent): void;
10
+ }
11
+ export interface CompositeWork<Allowed extends ChildContract = ChildContract, Restoring extends boolean = false> {
12
+ readonly children: Restoring extends true ? ResumeChildCalls<Allowed> : ChildCalls<Allowed>;
13
+ }
14
+ export type OutputWork<Delta> = [Delta] extends [never] ? object : {
15
+ readonly output: InvocationOutputWriter<Delta>;
16
+ };
package/dist/work.js ADDED
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@weiliang0121/capix-contracts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "description": "Shared contracts, stable data values, and runtime errors for CAPiX.",
13
+ "license": "MIT",
14
+ "author": "wei.liang (https://github.com/weiliang0121)",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/weiliang0121/capix.git",
18
+ "directory": "packages/contracts"
19
+ },
20
+ "engines": {
21
+ "node": ">=22.23.2"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist/**/*.js",
27
+ "dist/**/*.d.ts",
28
+ "LICENSE",
29
+ "README.md"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "registry": "https://registry.npmjs.org"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -p tsconfig.json",
37
+ "typecheck": "tsc -p tsconfig.json --noEmit",
38
+ "test": "node ../../scripts/test/run.mjs --package ."
39
+ }
6
40
  }