@aitoroses/telar 0.0.0 → 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/README.md +453 -3
- package/dist/compile.d.ts +48 -0
- package/dist/compile.js +1238 -0
- package/dist/contract.d.ts +109 -0
- package/dist/contract.js +497 -0
- package/dist/evaluator.d.ts +23 -0
- package/dist/evaluator.js +40 -0
- package/dist/guide.d.ts +8 -0
- package/dist/guide.js +16 -0
- package/dist/install.d.ts +104 -0
- package/dist/install.js +402 -0
- package/dist/iso.d.ts +8 -0
- package/dist/iso.js +68 -0
- package/dist/node/build.d.ts +1 -0
- package/dist/node/build.js +34 -0
- package/dist/node/telar-module.d.ts +2 -0
- package/dist/node/telar-module.js +28 -0
- package/dist/observer.d.ts +47 -0
- package/dist/observer.js +53 -0
- package/dist/pieces.d.ts +230 -0
- package/dist/pieces.js +178 -0
- package/dist/powers.d.ts +46 -0
- package/dist/powers.js +126 -0
- package/dist/protocol.d.ts +212 -0
- package/dist/protocol.js +236 -0
- package/dist/query.d.ts +67 -0
- package/dist/query.js +102 -0
- package/dist/read.d.ts +37 -0
- package/dist/read.js +27 -0
- package/dist/runner.d.ts +112 -0
- package/dist/runner.js +134 -0
- package/dist/scenario/builder.d.ts +25 -0
- package/dist/scenario/builder.js +603 -0
- package/dist/scenario/templates.d.ts +35 -0
- package/dist/scenario/templates.js +64 -0
- package/dist/scenario/types.d.ts +441 -0
- package/dist/scenario/types.js +10 -0
- package/dist/scenario/validate.d.ts +7 -0
- package/dist/scenario/validate.js +19 -0
- package/dist/scenario.d.ts +4 -0
- package/dist/scenario.js +4 -0
- package/dist/schema.d.ts +219 -0
- package/dist/schema.js +221 -0
- package/dist/seating.d.ts +49 -0
- package/dist/seating.js +26 -0
- package/dist/send-hook.d.ts +46 -0
- package/dist/send-hook.js +123 -0
- package/dist/show.d.ts +34 -0
- package/dist/show.js +1 -0
- package/dist/source.d.ts +85 -0
- package/dist/source.js +104 -0
- package/dist/spec.d.ts +20 -0
- package/dist/spec.js +17 -0
- package/dist/standard-schema.d.ts +21 -0
- package/dist/standard-schema.js +1 -0
- package/dist/std/accuracy.d.ts +12 -0
- package/dist/std/accuracy.js +122 -0
- package/dist/std/ack.d.ts +14 -0
- package/dist/std/ack.js +43 -0
- package/dist/std/actions.d.ts +106 -0
- package/dist/std/actions.js +154 -0
- package/dist/std/brief.d.ts +36 -0
- package/dist/std/brief.js +78 -0
- package/dist/std/claude-code.d.ts +9 -0
- package/dist/std/claude-code.js +106 -0
- package/dist/std/compare.d.ts +29 -0
- package/dist/std/compare.js +36 -0
- package/dist/std/git-workspace.d.ts +44 -0
- package/dist/std/git-workspace.js +184 -0
- package/dist/std/judgment.d.ts +85 -0
- package/dist/std/judgment.js +462 -0
- package/dist/std/observe-command.d.ts +23 -0
- package/dist/std/observe-command.js +151 -0
- package/dist/std/observe-github-checks.d.ts +26 -0
- package/dist/std/observe-github-checks.js +299 -0
- package/dist/std/observe-http-status.d.ts +27 -0
- package/dist/std/observe-http-status.js +181 -0
- package/dist/std/plan.d.ts +7 -0
- package/dist/std/plan.js +28 -0
- package/dist/std/queries.d.ts +31 -0
- package/dist/std/queries.js +318 -0
- package/dist/std/reading.d.ts +17 -0
- package/dist/std/reading.js +88 -0
- package/dist/std/schedule.d.ts +19 -0
- package/dist/std/schedule.js +122 -0
- package/dist/std.d.ts +15 -0
- package/dist/std.js +15 -0
- package/dist/types.d.ts +366 -0
- package/dist/types.js +1 -0
- package/dist/values.d.ts +81 -0
- package/dist/values.js +129 -0
- package/package.json +62 -5
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import type { RunnerReport } from "../runner.js";
|
|
2
|
+
import type { Installation, JsonObject, NonEmpty, TelarSpecV1 } from "../spec.js";
|
|
3
|
+
type Rec<V = unknown> = Readonly<Record<string, V>>;
|
|
4
|
+
type StrRec = Record<string, string>;
|
|
5
|
+
type PRec<K extends string, V> = Readonly<Partial<Record<K, V>>>;
|
|
6
|
+
export interface ScenarioIssue {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ScenarioCompileError extends Error {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly issues: NonEmpty<ScenarioIssue>;
|
|
14
|
+
constructor(path: string, message: string, issues?: NonEmpty<ScenarioIssue>);
|
|
15
|
+
}
|
|
16
|
+
export interface NamedProtocolRef<P extends string = string> {
|
|
17
|
+
readonly kind: "protocol" | "protocol-ref";
|
|
18
|
+
readonly name: P;
|
|
19
|
+
}
|
|
20
|
+
export type ProtocolInput<P extends string = string> = P | NamedProtocolRef<P>;
|
|
21
|
+
export interface NamedRoleRef<R extends string = string> {
|
|
22
|
+
readonly kind: "role";
|
|
23
|
+
readonly name: R;
|
|
24
|
+
}
|
|
25
|
+
export type RoleInput<R extends string = string> = R | NamedRoleRef<R>;
|
|
26
|
+
export interface NamedMessageRef<M extends string = string> {
|
|
27
|
+
readonly kind: "message-kind";
|
|
28
|
+
readonly name: M;
|
|
29
|
+
}
|
|
30
|
+
export type MessageKindInput<M extends string = string> = M | NamedMessageRef<M>;
|
|
31
|
+
export interface NamedCheckRef<Id extends string = string> {
|
|
32
|
+
readonly kind: "check";
|
|
33
|
+
readonly id: Id;
|
|
34
|
+
}
|
|
35
|
+
export type CheckInput<Id extends string = string> = Id | NamedCheckRef<Id>;
|
|
36
|
+
export interface NamedContractRef<N extends string = string> {
|
|
37
|
+
readonly kind: "contract";
|
|
38
|
+
readonly name: N;
|
|
39
|
+
}
|
|
40
|
+
export type ShapeInput<N extends string = string> = N | NamedContractRef<N>;
|
|
41
|
+
export type SpecInput = string | TelarSpecV1 | Installation;
|
|
42
|
+
export type ConfigInput = string | JsonObject;
|
|
43
|
+
declare const EMPTY_BINDINGS: unique symbol;
|
|
44
|
+
export type EmptyBindings = {
|
|
45
|
+
readonly [EMPTY_BINDINGS]?: never;
|
|
46
|
+
};
|
|
47
|
+
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
|
|
48
|
+
type IsSingleLiteral<S extends string> = [S] extends [never] ? false : {} extends Record<S, true> ? false : IsUnion<S> extends true ? false : true;
|
|
49
|
+
type IsValidAlias<S extends string> = S extends `$${infer R}` ? R extends "" | `$${string}` ? false : true : false;
|
|
50
|
+
type AllValidAliases<K extends string> = [K] extends [never] ? false : false extends (K extends unknown ? IsValidAlias<K> : never) ? false : true;
|
|
51
|
+
export type LiteralAlias<A extends string, Existing extends string = never> = IsSingleLiteral<A> extends true ? IsValidAlias<A> extends true ? A extends Existing ? never : A : never : never;
|
|
52
|
+
type RequiredLiteralKeys<T> = {
|
|
53
|
+
[K in keyof T]-?: K extends string ? {} extends Pick<T, K> ? never : {} extends Record<K, true> ? never : K : never;
|
|
54
|
+
}[keyof T];
|
|
55
|
+
type HasNonLiteralOrOptionalKey<T> = [Exclude<keyof T, RequiredLiteralKeys<T>>] extends [never] ? false : true;
|
|
56
|
+
type ProtocolNameOf<T> = T extends NamedProtocolRef<infer P> ? P : T extends string ? T : never;
|
|
57
|
+
type RoleNameOf<T> = T extends NamedRoleRef<infer R> ? R : T extends string ? T : never;
|
|
58
|
+
type MessageNameOf<T> = T extends NamedMessageRef<infer M> ? M : T extends string ? T : never;
|
|
59
|
+
export type AllAliases<C extends StrRec, S extends StrRec, M extends StrRec = EmptyBindings> = (keyof C & string) | (keyof S & string) | (keyof M & string);
|
|
60
|
+
export interface CaseBindingDescriptor<C extends StrRec = StrRec, P extends string = string> {
|
|
61
|
+
readonly kind: "case";
|
|
62
|
+
readonly protocol: ProtocolInput<P>;
|
|
63
|
+
readonly parent?: (keyof C & string) | undefined;
|
|
64
|
+
readonly forRole?: RoleInput | undefined;
|
|
65
|
+
readonly scope?: string | undefined;
|
|
66
|
+
readonly index?: number | undefined;
|
|
67
|
+
}
|
|
68
|
+
export interface SeatBindingDescriptor<C extends StrRec = StrRec, R extends string = string> {
|
|
69
|
+
readonly kind: "seat";
|
|
70
|
+
readonly role: RoleInput<R>;
|
|
71
|
+
readonly case?: (keyof C & string) | undefined;
|
|
72
|
+
readonly scope?: string | undefined;
|
|
73
|
+
readonly index?: number | undefined;
|
|
74
|
+
}
|
|
75
|
+
export interface MessageBindingDescriptor<C extends StrRec = StrRec, MK extends string = string> {
|
|
76
|
+
readonly kind: "message";
|
|
77
|
+
readonly messageKind: MessageKindInput<MK>;
|
|
78
|
+
readonly case?: (keyof C & string) | undefined;
|
|
79
|
+
readonly index?: number | undefined;
|
|
80
|
+
}
|
|
81
|
+
export type StepBindingDescriptor<C extends StrRec = StrRec> = CaseBindingDescriptor<C> | SeatBindingDescriptor<C> | MessageBindingDescriptor<C>;
|
|
82
|
+
export type StepBindMap<C extends StrRec = StrRec> = Rec<StepBindingDescriptor<C>>;
|
|
83
|
+
export type LiteralBindMap<Cases extends StrRec, Bind extends StepBindMap<Cases>, Seats extends StrRec = EmptyBindings, Messages extends StrRec = EmptyBindings> = HasNonLiteralOrOptionalKey<Bind> extends true ? never : AllValidAliases<RequiredLiteralKeys<Bind>> extends false ? never : [Extract<RequiredLiteralKeys<Bind>, AllAliases<Cases, Seats, Messages>>] extends [never] ? Bind : never;
|
|
84
|
+
export type BoundCasesFrom<Bind extends Rec<{
|
|
85
|
+
readonly kind: string;
|
|
86
|
+
}>> = {
|
|
87
|
+
readonly [K in RequiredLiteralKeys<Bind> as Bind[K] extends {
|
|
88
|
+
readonly kind: "case";
|
|
89
|
+
} ? K : never]: Bind[K] extends {
|
|
90
|
+
readonly kind: "case";
|
|
91
|
+
readonly protocol: infer P;
|
|
92
|
+
} ? ProtocolNameOf<P> : never;
|
|
93
|
+
};
|
|
94
|
+
export type BoundSeatsFrom<Bind extends Rec<{
|
|
95
|
+
readonly kind: string;
|
|
96
|
+
}>> = {
|
|
97
|
+
readonly [K in RequiredLiteralKeys<Bind> as Bind[K] extends {
|
|
98
|
+
readonly kind: "seat";
|
|
99
|
+
} ? K : never]: Bind[K] extends {
|
|
100
|
+
readonly kind: "seat";
|
|
101
|
+
readonly role: infer R;
|
|
102
|
+
} ? RoleNameOf<R> : never;
|
|
103
|
+
};
|
|
104
|
+
export type BoundMessagesFrom<Bind extends Rec<{
|
|
105
|
+
readonly kind: string;
|
|
106
|
+
}>> = {
|
|
107
|
+
readonly [K in RequiredLiteralKeys<Bind> as Bind[K] extends {
|
|
108
|
+
readonly kind: "message";
|
|
109
|
+
} ? K : never]: Bind[K] extends {
|
|
110
|
+
readonly kind: "message";
|
|
111
|
+
readonly messageKind: infer MK;
|
|
112
|
+
} ? MessageNameOf<MK> : never;
|
|
113
|
+
};
|
|
114
|
+
export interface CheckStub {
|
|
115
|
+
readonly default?: boolean | undefined;
|
|
116
|
+
readonly byArgs?: readonly {
|
|
117
|
+
readonly match: Rec;
|
|
118
|
+
readonly ok: boolean;
|
|
119
|
+
readonly hint?: string | undefined;
|
|
120
|
+
}[] | undefined;
|
|
121
|
+
}
|
|
122
|
+
export interface ActionStub {
|
|
123
|
+
readonly returns?: Rec | undefined;
|
|
124
|
+
readonly returnsSequence?: readonly Rec[] | undefined;
|
|
125
|
+
readonly byArgs?: readonly {
|
|
126
|
+
readonly match: Rec;
|
|
127
|
+
readonly returns: Rec;
|
|
128
|
+
}[] | undefined;
|
|
129
|
+
}
|
|
130
|
+
export interface NetworkStub {
|
|
131
|
+
readonly scheme?: "http" | "https" | undefined;
|
|
132
|
+
readonly authority?: string | undefined;
|
|
133
|
+
readonly method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
134
|
+
readonly path: string;
|
|
135
|
+
readonly status: number;
|
|
136
|
+
readonly body: unknown;
|
|
137
|
+
}
|
|
138
|
+
/** A process stub: answers `powers.process` for the installation's pieces in a scenario (ADR 0045 point 6). */
|
|
139
|
+
export interface ProcessStub {
|
|
140
|
+
readonly executable: string;
|
|
141
|
+
readonly args?: readonly string[] | undefined;
|
|
142
|
+
readonly stdin?: string | undefined;
|
|
143
|
+
readonly exitCode?: number | undefined;
|
|
144
|
+
readonly stdout: string;
|
|
145
|
+
readonly stderr?: string | undefined;
|
|
146
|
+
}
|
|
147
|
+
export interface ScriptedSeatReply {
|
|
148
|
+
readonly onCase?: string | undefined;
|
|
149
|
+
readonly onShape?: ShapeInput | undefined;
|
|
150
|
+
readonly payload: Rec;
|
|
151
|
+
}
|
|
152
|
+
export interface WorldConfig {
|
|
153
|
+
readonly clockStart?: string | undefined;
|
|
154
|
+
readonly checks?: Rec<CheckStub> | undefined;
|
|
155
|
+
readonly actions?: Rec<ActionStub> | undefined;
|
|
156
|
+
readonly network?: readonly NetworkStub[] | undefined;
|
|
157
|
+
/** When present, awaited checks run the installation's observers after each step, under these stubs. */
|
|
158
|
+
readonly process?: readonly ProcessStub[] | undefined;
|
|
159
|
+
readonly seats?: Rec<readonly ScriptedSeatReply[]> | undefined;
|
|
160
|
+
readonly extensions?: Rec | undefined;
|
|
161
|
+
}
|
|
162
|
+
export type CasePhase = "open" | "final-pending-effects" | "closed" | "cancelled";
|
|
163
|
+
export type DebtReason = "bound-reached";
|
|
164
|
+
export interface FieldProblemExpect {
|
|
165
|
+
readonly path: string;
|
|
166
|
+
readonly code: string;
|
|
167
|
+
readonly fix?: string | undefined;
|
|
168
|
+
}
|
|
169
|
+
export interface ResultExpect {
|
|
170
|
+
readonly ok?: boolean | undefined;
|
|
171
|
+
readonly code?: string | undefined;
|
|
172
|
+
readonly reasonContains?: string | undefined;
|
|
173
|
+
readonly fields?: readonly FieldProblemExpect[] | undefined;
|
|
174
|
+
}
|
|
175
|
+
export interface FieldInstructionExpect {
|
|
176
|
+
readonly path: string;
|
|
177
|
+
readonly description?: string | undefined;
|
|
178
|
+
readonly kind?: string | undefined;
|
|
179
|
+
readonly required?: boolean | undefined;
|
|
180
|
+
readonly audience?: "person" | "agent" | undefined;
|
|
181
|
+
}
|
|
182
|
+
export interface DebtExpect<M extends string = string> {
|
|
183
|
+
readonly message?: M | undefined;
|
|
184
|
+
readonly shape: ShapeInput;
|
|
185
|
+
readonly scope?: string | undefined;
|
|
186
|
+
readonly variants?: readonly string[] | undefined;
|
|
187
|
+
readonly reason?: DebtReason | undefined;
|
|
188
|
+
readonly instructions?: {
|
|
189
|
+
readonly fields?: readonly FieldInstructionExpect[] | undefined;
|
|
190
|
+
} | undefined;
|
|
191
|
+
}
|
|
192
|
+
export type RoleDebtExpect<M extends string = string> = DebtExpect<M> | readonly DebtExpect<M>[];
|
|
193
|
+
export interface SeatDebtExpect<C extends string = string> {
|
|
194
|
+
readonly case: C;
|
|
195
|
+
readonly shape: ShapeInput;
|
|
196
|
+
readonly reason?: DebtReason | undefined;
|
|
197
|
+
}
|
|
198
|
+
export interface ViewExpect<C extends string = string> {
|
|
199
|
+
readonly visibleCases?: readonly C[] | undefined;
|
|
200
|
+
readonly hiddenCases?: readonly C[] | undefined;
|
|
201
|
+
readonly caseData?: PRec<C, Rec> | undefined;
|
|
202
|
+
readonly guides?: PRec<C, readonly string[]> | undefined;
|
|
203
|
+
}
|
|
204
|
+
export interface TrailMatcher<C extends string = string, S extends string = string> {
|
|
205
|
+
readonly kind?: string | undefined;
|
|
206
|
+
readonly case?: C | undefined;
|
|
207
|
+
readonly seat?: S | undefined;
|
|
208
|
+
readonly parent?: C | undefined;
|
|
209
|
+
readonly child?: C | undefined;
|
|
210
|
+
readonly [key: string]: unknown;
|
|
211
|
+
}
|
|
212
|
+
export interface CountExpect<C extends string = string, S extends string = string> {
|
|
213
|
+
readonly match: TrailMatcher<C, S>;
|
|
214
|
+
readonly equals: number;
|
|
215
|
+
}
|
|
216
|
+
export interface TrailExpect<C extends string = string, S extends string = string> {
|
|
217
|
+
readonly scope?: "step" | "all" | undefined;
|
|
218
|
+
readonly contains?: readonly TrailMatcher<C, S>[] | undefined;
|
|
219
|
+
readonly sequence?: readonly TrailMatcher<C, S>[] | undefined;
|
|
220
|
+
readonly counts?: readonly CountExpect<C, S>[] | undefined;
|
|
221
|
+
readonly absent?: readonly TrailMatcher<C, S>[] | undefined;
|
|
222
|
+
}
|
|
223
|
+
export interface WorldExpect {
|
|
224
|
+
readonly awaitedChecks?: readonly {
|
|
225
|
+
readonly check: CheckInput;
|
|
226
|
+
readonly args: Rec;
|
|
227
|
+
}[] | undefined;
|
|
228
|
+
readonly calls?: Omit<TrailExpect, "sequence"> | undefined;
|
|
229
|
+
}
|
|
230
|
+
export interface StepExpect<C extends StrRec = StrRec, S extends StrRec = StrRec, M extends StrRec = EmptyBindings> {
|
|
231
|
+
readonly result?: ResultExpect | undefined;
|
|
232
|
+
readonly states?: PRec<keyof C & string, string> | undefined;
|
|
233
|
+
readonly phases?: PRec<keyof C & string, CasePhase> | undefined;
|
|
234
|
+
readonly data?: PRec<keyof C & string, Rec> | undefined;
|
|
235
|
+
readonly debts?: PRec<keyof C & string, Rec<RoleDebtExpect<keyof M & string>>> | undefined;
|
|
236
|
+
readonly seatDebts?: PRec<keyof S & string, readonly SeatDebtExpect<keyof C & string>[]> | undefined;
|
|
237
|
+
readonly views?: PRec<keyof S & string, ViewExpect<keyof C & string>> | undefined;
|
|
238
|
+
readonly trail?: TrailExpect<keyof C & string, keyof S & string> | undefined;
|
|
239
|
+
readonly world?: WorldExpect | undefined;
|
|
240
|
+
readonly extensions?: Rec | undefined;
|
|
241
|
+
}
|
|
242
|
+
type ExactKeyMap<M, Allowed extends string> = [Exclude<keyof M & string, Allowed>] extends [never] ? M : {
|
|
243
|
+
readonly [K in keyof M]: K extends Allowed ? M[K] : never;
|
|
244
|
+
};
|
|
245
|
+
type CheckEmbeddedAlias<V, Allowed extends string> = V extends `$${string}` ? V extends Allowed ? V : Allowed : V extends readonly (infer E)[] ? readonly CheckEmbeddedAlias<E, Allowed>[] : V extends Rec ? {
|
|
246
|
+
readonly [K in keyof V]: K extends "$absent" | "$contains" ? V[K] : CheckEmbeddedAlias<V[K], Allowed>;
|
|
247
|
+
} : V;
|
|
248
|
+
type ExactViews<Views, CK extends string, SK extends string> = {
|
|
249
|
+
readonly [K in keyof Views]: K extends SK ? Views[K] extends {
|
|
250
|
+
readonly caseData?: infer CD;
|
|
251
|
+
} ? Omit<Views[K], "caseData"> & {
|
|
252
|
+
readonly caseData?: ExactKeyMap<CD, CK>;
|
|
253
|
+
} : Views[K] : never;
|
|
254
|
+
};
|
|
255
|
+
export type ExactStepExpect<C extends StrRec, S extends StrRec, E extends StepExpect<C, S, M>, M extends StrRec = EmptyBindings> = E & {
|
|
256
|
+
readonly [K in keyof E]: K extends "states" | "phases" | "debts" ? ExactKeyMap<E[K], keyof C & string> : K extends "data" ? ExactKeyMap<CheckEmbeddedAlias<E[K], AllAliases<C, S, M>>, keyof C & string> : K extends "seatDebts" ? ExactKeyMap<E[K], keyof S & string> : K extends "views" ? ExactViews<E[K], keyof C & string, keyof S & string> : K extends "trail" | "world" ? CheckEmbeddedAlias<E[K], AllAliases<C, S, M>> : E[K];
|
|
257
|
+
};
|
|
258
|
+
export interface OpenInput<C extends StrRec = StrRec, P extends string = string> {
|
|
259
|
+
readonly protocol: ProtocolInput<P>;
|
|
260
|
+
readonly data?: Rec | undefined;
|
|
261
|
+
readonly parent?: (keyof C & string) | undefined;
|
|
262
|
+
readonly forRole?: RoleInput | undefined;
|
|
263
|
+
readonly scope?: string | undefined;
|
|
264
|
+
}
|
|
265
|
+
type SeatLabelsOpt = {
|
|
266
|
+
readonly labels?: Readonly<Record<string, string>> | undefined;
|
|
267
|
+
};
|
|
268
|
+
export type BindSeatInput<C extends StrRec = StrRec, R extends string = string> = SeatLabelsOpt & ({
|
|
269
|
+
readonly binding: "case";
|
|
270
|
+
readonly role: RoleInput<R>;
|
|
271
|
+
readonly case: keyof C & string;
|
|
272
|
+
} | {
|
|
273
|
+
readonly binding: "all";
|
|
274
|
+
readonly role: RoleInput<R>;
|
|
275
|
+
} | {
|
|
276
|
+
readonly binding: "field";
|
|
277
|
+
readonly role: RoleInput<R>;
|
|
278
|
+
readonly field: string;
|
|
279
|
+
readonly value: string;
|
|
280
|
+
} | {
|
|
281
|
+
readonly binding: "ancestor";
|
|
282
|
+
readonly role: RoleInput<R>;
|
|
283
|
+
readonly protocol: ProtocolInput;
|
|
284
|
+
readonly case: keyof C & string;
|
|
285
|
+
});
|
|
286
|
+
export interface RoleAvailabilityInput {
|
|
287
|
+
readonly role: RoleInput;
|
|
288
|
+
readonly available: boolean;
|
|
289
|
+
readonly reason?: string | undefined;
|
|
290
|
+
}
|
|
291
|
+
export interface CheckEvidenceInput {
|
|
292
|
+
readonly refs?: readonly {
|
|
293
|
+
readonly kind: string;
|
|
294
|
+
readonly id?: string | undefined;
|
|
295
|
+
readonly url?: string | undefined;
|
|
296
|
+
}[] | undefined;
|
|
297
|
+
readonly status?: number | undefined;
|
|
298
|
+
readonly durationMs?: number | undefined;
|
|
299
|
+
readonly readings?: Readonly<Record<string, number>> | undefined;
|
|
300
|
+
}
|
|
301
|
+
interface CheckEventBase {
|
|
302
|
+
readonly kind: "check";
|
|
303
|
+
readonly check: CheckInput;
|
|
304
|
+
readonly args: Rec;
|
|
305
|
+
readonly ok: boolean;
|
|
306
|
+
}
|
|
307
|
+
export type WorldEventInput<Src extends string = string> = (CheckEventBase & {
|
|
308
|
+
readonly hint?: string | undefined;
|
|
309
|
+
readonly evidence?: undefined;
|
|
310
|
+
}) | (CheckEventBase & {
|
|
311
|
+
readonly evidence: CheckEvidenceInput;
|
|
312
|
+
readonly hint?: undefined;
|
|
313
|
+
}) | {
|
|
314
|
+
/** Polls one `config.sources` instance at the scenario clock (ADR 0047 decision 8). */
|
|
315
|
+
readonly kind: "source";
|
|
316
|
+
readonly instance: Src;
|
|
317
|
+
};
|
|
318
|
+
/** The instance names of an inline config's `sources`; any name when the config is a path or set later. */
|
|
319
|
+
export type SourceNames<Cfg> = Cfg extends string ? string : Cfg extends {
|
|
320
|
+
readonly sources: infer X;
|
|
321
|
+
} ? keyof X & string : Cfg extends object ? never : string;
|
|
322
|
+
export interface AnswerInput<C extends StrRec = StrRec, S extends StrRec = StrRec, M extends StrRec = EmptyBindings> {
|
|
323
|
+
readonly case: keyof C & string;
|
|
324
|
+
readonly seat: keyof S & string;
|
|
325
|
+
readonly message?: (keyof M & string) | undefined;
|
|
326
|
+
readonly payload: Rec;
|
|
327
|
+
}
|
|
328
|
+
export interface RunnerReportInput<S extends StrRec = StrRec> {
|
|
329
|
+
readonly seat: keyof S & string;
|
|
330
|
+
readonly report: RunnerReport;
|
|
331
|
+
}
|
|
332
|
+
export interface MessageInput<C extends StrRec = StrRec, S extends StrRec = StrRec> {
|
|
333
|
+
readonly case: keyof C & string;
|
|
334
|
+
readonly seat: keyof S & string;
|
|
335
|
+
readonly toRole: RoleInput;
|
|
336
|
+
readonly messageKind: MessageKindInput;
|
|
337
|
+
readonly payload: Rec;
|
|
338
|
+
}
|
|
339
|
+
export interface ReadInput<S extends StrRec = StrRec, M extends StrRec = StrRec> {
|
|
340
|
+
readonly seat: keyof S & string;
|
|
341
|
+
readonly message: keyof M & string;
|
|
342
|
+
}
|
|
343
|
+
export type ClockInput = {
|
|
344
|
+
readonly at: string;
|
|
345
|
+
readonly advanceMs?: never;
|
|
346
|
+
} | {
|
|
347
|
+
readonly advanceMs: number;
|
|
348
|
+
readonly at?: never;
|
|
349
|
+
};
|
|
350
|
+
export interface CancelInput<C extends StrRec = StrRec> {
|
|
351
|
+
readonly case: keyof C & string;
|
|
352
|
+
readonly reason: string;
|
|
353
|
+
}
|
|
354
|
+
export interface AdoptInput {
|
|
355
|
+
readonly spec: SpecInput;
|
|
356
|
+
readonly migration?: Rec | undefined;
|
|
357
|
+
}
|
|
358
|
+
export interface NamespacedInput {
|
|
359
|
+
readonly kind: `${string}.${string}`;
|
|
360
|
+
readonly [key: string]: unknown;
|
|
361
|
+
}
|
|
362
|
+
export interface StepOptions<C extends StrRec, S extends StrRec, M extends StrRec, E extends StepExpect<C, S, M>> {
|
|
363
|
+
readonly id?: string | undefined;
|
|
364
|
+
readonly note?: string | undefined;
|
|
365
|
+
readonly bind?: never;
|
|
366
|
+
readonly expect?: ExactStepExpect<C, S, E, M> | undefined;
|
|
367
|
+
}
|
|
368
|
+
export interface BindStepOptions<C extends StrRec, S extends StrRec, M extends StrRec, B extends StepBindMap<C>, E extends StepExpect<C & BoundCasesFrom<B>, S & BoundSeatsFrom<B>, M & BoundMessagesFrom<B>>> {
|
|
369
|
+
readonly id?: string | undefined;
|
|
370
|
+
readonly note?: string | undefined;
|
|
371
|
+
readonly bind: LiteralBindMap<C, B, S, M>;
|
|
372
|
+
readonly expect?: ExactStepExpect<C & BoundCasesFrom<B>, S & BoundSeatsFrom<B>, E, M & BoundMessagesFrom<B>> | undefined;
|
|
373
|
+
}
|
|
374
|
+
export type ScopeAliasMap<Outer extends StrRec, Local extends Readonly<Record<string, keyof Outer & string>>> = {
|
|
375
|
+
readonly [K in keyof Local & string]: Local[K] extends keyof Outer & string ? Outer[Local[K]] : never;
|
|
376
|
+
};
|
|
377
|
+
export interface ScenarioStepV1 {
|
|
378
|
+
readonly note?: string;
|
|
379
|
+
readonly input: Rec;
|
|
380
|
+
readonly bind?: Rec<Rec>;
|
|
381
|
+
readonly expect?: Rec;
|
|
382
|
+
}
|
|
383
|
+
export interface TelarScenarioV1 {
|
|
384
|
+
readonly format: "telar.scenario/1";
|
|
385
|
+
readonly id: string;
|
|
386
|
+
readonly title: string;
|
|
387
|
+
readonly stories?: readonly string[];
|
|
388
|
+
readonly spec: string | TelarSpecV1;
|
|
389
|
+
readonly config?: ConfigInput;
|
|
390
|
+
readonly world?: WorldConfig;
|
|
391
|
+
readonly steps: readonly ScenarioStepV1[];
|
|
392
|
+
}
|
|
393
|
+
export interface ScenarioInit {
|
|
394
|
+
readonly id: string;
|
|
395
|
+
readonly title: string;
|
|
396
|
+
readonly spec: SpecInput;
|
|
397
|
+
readonly stories?: NonEmpty<string> | undefined;
|
|
398
|
+
readonly config?: ConfigInput | undefined;
|
|
399
|
+
readonly world?: WorldConfig | undefined;
|
|
400
|
+
}
|
|
401
|
+
type AC<C extends StrRec, A extends string, P extends string> = C & Record<A, P>;
|
|
402
|
+
type AS<S extends StrRec, A extends string, R extends string> = S & Record<A, R>;
|
|
403
|
+
type BC<C extends StrRec, B extends StepBindMap<C>> = C & BoundCasesFrom<B>;
|
|
404
|
+
type BS<S extends StrRec, B extends Rec<{
|
|
405
|
+
readonly kind: string;
|
|
406
|
+
}>> = S & BoundSeatsFrom<B>;
|
|
407
|
+
type BM<M extends StrRec, B extends Rec<{
|
|
408
|
+
readonly kind: string;
|
|
409
|
+
}>> = M & BoundMessagesFrom<B>;
|
|
410
|
+
export interface ScenarioBuilder<C extends StrRec = EmptyBindings, S extends StrRec = EmptyBindings, M extends StrRec = EmptyBindings, Src extends string = string> {
|
|
411
|
+
world(world: WorldConfig): ScenarioBuilder<C, S, M, Src>;
|
|
412
|
+
config<const Cfg extends ConfigInput>(config: Cfg): ScenarioBuilder<C, S, M, SourceNames<Cfg>>;
|
|
413
|
+
open<const A extends string, const P extends string, const E extends StepExpect<AC<C, A, P>, S, M> = StepExpect<AC<C, A, P>, S, M>>(alias: LiteralAlias<A, AllAliases<C, S, M>>, input: OpenInput<C, P>, options?: StepOptions<AC<C, A, P>, S, M, E>): ScenarioBuilder<AC<C, A, P>, S, M, Src>;
|
|
414
|
+
open<const A extends string, const P extends string, const B extends StepBindMap<AC<C, A, P>>, const E extends StepExpect<BC<AC<C, A, P>, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<AC<C, A, P>, B>, BS<S, B>, BM<M, B>>>(alias: LiteralAlias<A, AllAliases<C, S, M>>, input: OpenInput<C, P>, options: BindStepOptions<AC<C, A, P>, S, M, B, E>): ScenarioBuilder<BC<AC<C, A, P>, B>, BS<S, B>, BM<M, B>, Src>;
|
|
415
|
+
openUnbound<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: OpenInput<C>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
416
|
+
bindSeat<const A extends string, const R extends string, const E extends StepExpect<C, AS<S, A, R>, M> = StepExpect<C, AS<S, A, R>, M>>(alias: LiteralAlias<A, AllAliases<C, S, M>>, input: BindSeatInput<C, R>, options?: StepOptions<C, AS<S, A, R>, M, E>): ScenarioBuilder<C, AS<S, A, R>, M, Src>;
|
|
417
|
+
closeSeat<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(seat: keyof S & string, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
418
|
+
runnerReport<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: RunnerReportInput<S>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
419
|
+
roleAvailability<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: RoleAvailabilityInput, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
420
|
+
answer<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: AnswerInput<C, S, M>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
421
|
+
answer<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(input: AnswerInput<C, S, M>, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
422
|
+
message<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: MessageInput<C, S>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
423
|
+
message<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(input: MessageInput<C, S>, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
424
|
+
read<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: ReadInput<S, M>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
425
|
+
read<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(input: ReadInput<S, M>, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
426
|
+
worldEvent<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(event: WorldEventInput<Src>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
427
|
+
worldEvent<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(event: WorldEventInput<Src>, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
428
|
+
clock<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: ClockInput, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
429
|
+
clock<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(input: ClockInput, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
430
|
+
cancel<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: CancelInput<C>, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
431
|
+
adopt<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: AdoptInput, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
432
|
+
extension<const E extends StepExpect<C, S, M> = StepExpect<C, S, M>>(input: NamespacedInput, options?: StepOptions<C, S, M, E>): ScenarioBuilder<C, S, M, Src>;
|
|
433
|
+
extension<const B extends StepBindMap<C>, const E extends StepExpect<BC<C, B>, BS<S, B>, BM<M, B>> = StepExpect<BC<C, B>, BS<S, B>, BM<M, B>>>(input: NamespacedInput, options: BindStepOptions<C, S, M, B, E>): ScenarioBuilder<BC<C, B>, BS<S, B>, BM<M, B>, Src>;
|
|
434
|
+
withScope<const CM extends Readonly<Record<string, keyof C & string>>, const SM extends Readonly<Record<string, keyof S & string>>, const MM extends Readonly<Record<string, keyof M & string>> = EmptyBindings, NC extends StrRec = StrRec, NS extends StrRec = StrRec, NM extends StrRec = EmptyBindings>(prefix: string, map: {
|
|
435
|
+
readonly cases: CM;
|
|
436
|
+
readonly seats: SM;
|
|
437
|
+
readonly messages?: MM;
|
|
438
|
+
}, fn: (sub: ScenarioBuilder<ScopeAliasMap<C, CM>, ScopeAliasMap<S, SM>, ScopeAliasMap<M, MM>, Src>) => ScenarioBuilder<NC, NS, NM, Src>): ScenarioBuilder<C, S, M, Src>;
|
|
439
|
+
build(): TelarScenarioV1;
|
|
440
|
+
}
|
|
441
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ScenarioStepV1 } from "./types.js";
|
|
2
|
+
export declare const STEP_ID_RE: RegExp;
|
|
3
|
+
export declare const STEP_NOTE_RE: RegExp;
|
|
4
|
+
export declare function stepIdOf(step: Pick<ScenarioStepV1, "note">): string | undefined;
|
|
5
|
+
export declare function stepById<S extends Pick<ScenarioStepV1, "note">>(sc: {
|
|
6
|
+
readonly steps: readonly S[];
|
|
7
|
+
}, id: string): S;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScenarioCompileError } from "./types.js";
|
|
2
|
+
export const STEP_ID_RE = /^[a-z0-9][a-z0-9/_.-]*$/;
|
|
3
|
+
export const STEP_NOTE_RE = /^\[id:([a-z0-9][a-z0-9/_.-]*)\](?: ([\s\S]*))?$/;
|
|
4
|
+
export function stepIdOf(step) {
|
|
5
|
+
if (typeof step.note !== "string")
|
|
6
|
+
return undefined;
|
|
7
|
+
const match = STEP_NOTE_RE.exec(step.note);
|
|
8
|
+
return match?.[1];
|
|
9
|
+
}
|
|
10
|
+
export function stepById(sc, id) {
|
|
11
|
+
if (!STEP_ID_RE.test(id)) {
|
|
12
|
+
throw new ScenarioCompileError("stepById", `invalid step id ${JSON.stringify(id)}`);
|
|
13
|
+
}
|
|
14
|
+
const found = sc.steps.find((s) => stepIdOf(s) === id);
|
|
15
|
+
if (found === undefined) {
|
|
16
|
+
throw new ScenarioCompileError("stepById", `scenario has no step with id ${JSON.stringify(id)}`);
|
|
17
|
+
}
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { absent, bindCase, bindMessage, bindSeatRef, contains, scenario, } from "./scenario/builder.js";
|
|
2
|
+
export { checkGateHappyPath, refusalPreservesState, type CheckGateStep, type CheckGateTemplateParams, type RefusalTemplateParams, } from "./scenario/templates.js";
|
|
3
|
+
export { ScenarioCompileError, type ActionStub, type AdoptInput, type AllAliases, type AnswerInput, type BindSeatInput, type BindStepOptions, type BoundCasesFrom, type BoundMessagesFrom, type BoundSeatsFrom, type CancelInput, type CaseBindingDescriptor, type CasePhase, type CheckInput, type CheckStub, type ClockInput, type ConfigInput, type CountExpect, type DebtExpect, type DebtReason, type EmptyBindings, type ExactStepExpect, type FieldInstructionExpect, type FieldProblemExpect, type LiteralAlias, type LiteralBindMap, type MessageBindingDescriptor, type MessageInput, type MessageKindInput, type NamedCheckRef, type NamedContractRef, type NamedMessageRef, type NamedProtocolRef, type NamedRoleRef, type NamespacedInput, type NetworkStub, type OpenInput, type ProcessStub, type ProtocolInput, type ReadInput, type ResultExpect, type RoleAvailabilityInput, type RoleDebtExpect, type RoleInput, type RunnerReportInput, type ScenarioBuilder, type ScenarioInit, type ScenarioIssue, type ScenarioStepV1, type ScopeAliasMap, type ScriptedSeatReply, type SeatBindingDescriptor, type SeatDebtExpect, type ShapeInput, type SpecInput, type StepBindMap, type StepBindingDescriptor, type StepExpect, type StepOptions, type TelarScenarioV1, type TrailExpect, type TrailMatcher, type ViewExpect, type WorldConfig, type WorldEventInput, type CheckEvidenceInput, type WorldExpect, } from "./scenario/types.js";
|
|
4
|
+
export { stepById, stepIdOf } from "./scenario/validate.js";
|
package/dist/scenario.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { absent, bindCase, bindMessage, bindSeatRef, contains, scenario, } from "./scenario/builder.js";
|
|
2
|
+
export { checkGateHappyPath, refusalPreservesState, } from "./scenario/templates.js";
|
|
3
|
+
export { ScenarioCompileError, } from "./scenario/types.js";
|
|
4
|
+
export { stepById, stepIdOf } from "./scenario/validate.js";
|