@aitoroses/telar 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.
Files changed (92) hide show
  1. package/README.md +453 -2
  2. package/dist/compile.d.ts +48 -0
  3. package/dist/compile.js +1238 -0
  4. package/dist/contract.d.ts +109 -0
  5. package/dist/contract.js +497 -0
  6. package/dist/evaluator.d.ts +23 -0
  7. package/dist/evaluator.js +40 -0
  8. package/dist/guide.d.ts +8 -0
  9. package/dist/guide.js +16 -0
  10. package/dist/install.d.ts +104 -0
  11. package/dist/install.js +402 -0
  12. package/dist/iso.d.ts +8 -0
  13. package/dist/iso.js +68 -0
  14. package/dist/node/build.d.ts +1 -0
  15. package/dist/node/build.js +34 -0
  16. package/dist/node/telar-module.d.ts +2 -0
  17. package/dist/node/telar-module.js +28 -0
  18. package/dist/observer.d.ts +47 -0
  19. package/dist/observer.js +53 -0
  20. package/dist/pieces.d.ts +230 -0
  21. package/dist/pieces.js +178 -0
  22. package/dist/powers.d.ts +46 -0
  23. package/dist/powers.js +126 -0
  24. package/dist/protocol.d.ts +212 -0
  25. package/dist/protocol.js +236 -0
  26. package/dist/query.d.ts +67 -0
  27. package/dist/query.js +102 -0
  28. package/dist/read.d.ts +37 -0
  29. package/dist/read.js +27 -0
  30. package/dist/runner.d.ts +112 -0
  31. package/dist/runner.js +134 -0
  32. package/dist/scenario/builder.d.ts +25 -0
  33. package/dist/scenario/builder.js +603 -0
  34. package/dist/scenario/templates.d.ts +35 -0
  35. package/dist/scenario/templates.js +64 -0
  36. package/dist/scenario/types.d.ts +441 -0
  37. package/dist/scenario/types.js +10 -0
  38. package/dist/scenario/validate.d.ts +7 -0
  39. package/dist/scenario/validate.js +19 -0
  40. package/dist/scenario.d.ts +4 -0
  41. package/dist/scenario.js +4 -0
  42. package/dist/schema.d.ts +219 -0
  43. package/dist/schema.js +221 -0
  44. package/dist/seating.d.ts +49 -0
  45. package/dist/seating.js +26 -0
  46. package/dist/send-hook.d.ts +46 -0
  47. package/dist/send-hook.js +123 -0
  48. package/dist/show.d.ts +34 -0
  49. package/dist/show.js +1 -0
  50. package/dist/source.d.ts +85 -0
  51. package/dist/source.js +104 -0
  52. package/dist/spec.d.ts +20 -0
  53. package/dist/spec.js +17 -0
  54. package/dist/standard-schema.d.ts +21 -0
  55. package/dist/standard-schema.js +1 -0
  56. package/dist/std/accuracy.d.ts +12 -0
  57. package/dist/std/accuracy.js +122 -0
  58. package/dist/std/ack.d.ts +14 -0
  59. package/dist/std/ack.js +43 -0
  60. package/dist/std/actions.d.ts +106 -0
  61. package/dist/std/actions.js +154 -0
  62. package/dist/std/brief.d.ts +36 -0
  63. package/dist/std/brief.js +78 -0
  64. package/dist/std/claude-code.d.ts +9 -0
  65. package/dist/std/claude-code.js +106 -0
  66. package/dist/std/compare.d.ts +29 -0
  67. package/dist/std/compare.js +36 -0
  68. package/dist/std/git-workspace.d.ts +44 -0
  69. package/dist/std/git-workspace.js +184 -0
  70. package/dist/std/judgment.d.ts +85 -0
  71. package/dist/std/judgment.js +462 -0
  72. package/dist/std/observe-command.d.ts +23 -0
  73. package/dist/std/observe-command.js +151 -0
  74. package/dist/std/observe-github-checks.d.ts +26 -0
  75. package/dist/std/observe-github-checks.js +299 -0
  76. package/dist/std/observe-http-status.d.ts +27 -0
  77. package/dist/std/observe-http-status.js +181 -0
  78. package/dist/std/plan.d.ts +7 -0
  79. package/dist/std/plan.js +28 -0
  80. package/dist/std/queries.d.ts +31 -0
  81. package/dist/std/queries.js +318 -0
  82. package/dist/std/reading.d.ts +17 -0
  83. package/dist/std/reading.js +88 -0
  84. package/dist/std/schedule.d.ts +19 -0
  85. package/dist/std/schedule.js +122 -0
  86. package/dist/std.d.ts +15 -0
  87. package/dist/std.js +15 -0
  88. package/dist/types.d.ts +366 -0
  89. package/dist/types.js +1 -0
  90. package/dist/values.d.ts +81 -0
  91. package/dist/values.js +129 -0
  92. package/package.json +65 -3
@@ -0,0 +1,366 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | readonly JsonValue[] | JsonObject;
3
+ export interface JsonObject {
4
+ readonly [key: string]: JsonValue;
5
+ }
6
+ export type NonEmpty<T> = readonly [T, ...T[]];
7
+ export type Rec<V> = Readonly<Record<string, V>>;
8
+ export type Audience = "person" | "agent";
9
+ export type ViewKind = "lineage" | "blind" | "all";
10
+ export type EffortLevel = "low" | "medium" | "high";
11
+ export type RecordMode = "set" | "append";
12
+ export type BriefPiece = "you" | "owes" | "guide" | "asked" | "parentOrder" | "file" | "summary";
13
+ export interface SchemaAnnotations {
14
+ readonly description?: string;
15
+ readonly examples?: readonly JsonValue[];
16
+ readonly audience?: Audience;
17
+ readonly guide?: string;
18
+ }
19
+ export interface StructFieldDecl {
20
+ readonly schema: TypeSchema;
21
+ readonly optional?: true;
22
+ }
23
+ export type TypeSchema = (SchemaAnnotations & {
24
+ readonly kind: "string";
25
+ readonly brand?: string;
26
+ readonly nonEmpty?: boolean;
27
+ readonly maxLength?: number;
28
+ readonly validator?: string;
29
+ }) | (SchemaAnnotations & {
30
+ readonly kind: "number";
31
+ readonly brand?: string;
32
+ readonly integer?: boolean;
33
+ readonly min?: number;
34
+ readonly max?: number;
35
+ readonly exclusiveMin?: number;
36
+ readonly exclusiveMax?: number;
37
+ }) | (SchemaAnnotations & {
38
+ readonly kind: "boolean";
39
+ readonly brand?: string;
40
+ }) | (SchemaAnnotations & {
41
+ readonly kind: "literal";
42
+ readonly value: string | number | boolean;
43
+ }) | (SchemaAnnotations & {
44
+ readonly kind: "enum";
45
+ readonly values: NonEmpty<string>;
46
+ }) | (SchemaAnnotations & {
47
+ readonly kind: "array";
48
+ readonly item: TypeSchema;
49
+ readonly nonEmpty?: boolean;
50
+ }) | (SchemaAnnotations & {
51
+ readonly kind: "struct";
52
+ readonly fields: Rec<StructFieldDecl>;
53
+ readonly validator?: string;
54
+ }) | (SchemaAnnotations & {
55
+ readonly kind: "union";
56
+ readonly tag: string;
57
+ readonly variants: Rec<TypeSchema>;
58
+ }) | (SchemaAnnotations & {
59
+ readonly kind: "ref";
60
+ readonly schema: string;
61
+ });
62
+ export interface DelegationDecl {
63
+ readonly role: string;
64
+ readonly forRole: string;
65
+ }
66
+ export interface ClassDecl {
67
+ readonly authorizedRoles: NonEmpty<string>;
68
+ readonly delegatedWhenAway?: readonly DelegationDecl[];
69
+ readonly requires: readonly string[];
70
+ readonly admitsImpossible: boolean;
71
+ readonly guide?: string;
72
+ }
73
+ export interface ViewPolicyDecl {
74
+ readonly view: ViewKind;
75
+ readonly includePredecessor?: boolean;
76
+ }
77
+ export type SeatLabelsDecl = Rec<NonEmpty<string>>;
78
+ export interface RoleDecl extends ViewPolicyDecl {
79
+ readonly seatLabels?: SeatLabelsDecl;
80
+ readonly guide?: string;
81
+ readonly brief?: readonly BriefPiece[];
82
+ }
83
+ export interface CheckObserveDecl {
84
+ readonly observer: string;
85
+ readonly params: JsonObject;
86
+ }
87
+ export interface CheckDecl {
88
+ readonly input: string;
89
+ readonly evaluator?: string;
90
+ readonly observe?: CheckObserveDecl;
91
+ readonly guide?: string;
92
+ }
93
+ export interface ActionDecl {
94
+ readonly input: string;
95
+ readonly output: string;
96
+ readonly class?: string;
97
+ readonly revert?: string;
98
+ readonly release?: string;
99
+ readonly reversible?: boolean;
100
+ readonly guide?: string;
101
+ }
102
+ export type MessageFieldName = "id" | "kind" | "toRole" | "case";
103
+ export type MissArgDecl = {
104
+ readonly $message: MessageFieldName;
105
+ } | {
106
+ readonly $literal: JsonValue;
107
+ };
108
+ export type MissActionDecl = {
109
+ readonly kind: "redeliver";
110
+ } | {
111
+ readonly kind: "open";
112
+ readonly protocol: string;
113
+ readonly forRole: string;
114
+ readonly dataMap: Rec<MissArgDecl>;
115
+ };
116
+ export type SpecAckDecl = {
117
+ readonly kind: "none";
118
+ } | {
119
+ readonly kind: "read";
120
+ readonly within: number;
121
+ readonly onMiss: NonEmpty<MissActionDecl>;
122
+ } | {
123
+ readonly kind: "answer";
124
+ readonly shape: string;
125
+ readonly within: number;
126
+ readonly onMiss: NonEmpty<MissActionDecl>;
127
+ };
128
+ export interface MessageDecl {
129
+ readonly payload: string;
130
+ readonly template: string;
131
+ readonly ack: SpecAckDecl;
132
+ }
133
+ export type ArgValue = {
134
+ readonly $field: string;
135
+ } | {
136
+ readonly $answer: string;
137
+ } | {
138
+ readonly $seat: "id" | "role";
139
+ } | {
140
+ readonly $cause: "fact";
141
+ } | {
142
+ readonly $literal: JsonValue;
143
+ };
144
+ export interface ChildFilterDecl {
145
+ readonly childField: string;
146
+ readonly parentField: string;
147
+ }
148
+ export interface SeatLabelNeedDecl {
149
+ readonly key: string;
150
+ readonly values: NonEmpty<string>;
151
+ }
152
+ export type NeedDecl = {
153
+ readonly kind: "check";
154
+ readonly check: string;
155
+ readonly args: Rec<ArgValue>;
156
+ readonly guide?: string;
157
+ } | {
158
+ readonly kind: "any";
159
+ readonly of: readonly [NeedDecl, NeedDecl, ...NeedDecl[]];
160
+ readonly guide?: string;
161
+ } | {
162
+ readonly kind: "answer";
163
+ readonly roles: NonEmpty<string>;
164
+ readonly shape: string;
165
+ readonly variants?: NonEmpty<string>;
166
+ readonly seatLabel?: SeatLabelNeedDecl;
167
+ readonly guide?: string;
168
+ } | {
169
+ readonly kind: "authorization";
170
+ readonly class: string;
171
+ readonly guide?: string;
172
+ } | {
173
+ readonly kind: "authorization";
174
+ readonly classFromCaseField: string;
175
+ readonly allowedClasses: NonEmpty<string>;
176
+ readonly guide?: string;
177
+ } | {
178
+ readonly kind: "children";
179
+ readonly protocol?: string;
180
+ readonly condition: "ended";
181
+ readonly where?: ChildFilterDecl;
182
+ readonly allowEmpty: boolean;
183
+ readonly guide?: string;
184
+ } | {
185
+ readonly kind: "children";
186
+ readonly protocol?: string;
187
+ readonly condition: "state" | "ended-in";
188
+ readonly state: string;
189
+ readonly where?: ChildFilterDecl;
190
+ readonly allowEmpty: boolean;
191
+ readonly guide?: string;
192
+ } | {
193
+ readonly kind: "message";
194
+ readonly messageKind: string;
195
+ readonly fromRoles: NonEmpty<string>;
196
+ readonly guide?: string;
197
+ } | {
198
+ readonly kind: "bound-reached";
199
+ readonly step: string;
200
+ readonly guide?: string;
201
+ };
202
+ export type EffectDecl = {
203
+ readonly kind: "record-data";
204
+ readonly mode: RecordMode;
205
+ readonly targetField: string;
206
+ readonly fromAnswerField: string;
207
+ } | {
208
+ readonly kind: "record-data";
209
+ readonly mode: RecordMode;
210
+ readonly targetField: string;
211
+ readonly value: ArgValue;
212
+ } | {
213
+ readonly kind: "record-data";
214
+ readonly mode: RecordMode;
215
+ readonly targetField: string;
216
+ readonly valueMap: Rec<ArgValue>;
217
+ } | {
218
+ readonly kind: "open-child";
219
+ readonly protocol: string;
220
+ readonly forRole: string;
221
+ readonly seatScopeFromField?: string;
222
+ readonly dataMap: Rec<ArgValue>;
223
+ } | {
224
+ readonly kind: "emit-message";
225
+ readonly messageKind: string;
226
+ readonly toRole: string;
227
+ readonly payloadMap?: Rec<ArgValue>;
228
+ } | {
229
+ readonly kind: "call-action";
230
+ readonly action: string;
231
+ readonly args: Rec<ArgValue>;
232
+ };
233
+ export interface BoundByFieldDecl {
234
+ readonly field: string;
235
+ readonly values: Rec<number>;
236
+ }
237
+ export interface BoundDecl {
238
+ readonly max: number;
239
+ readonly byField?: BoundByFieldDecl;
240
+ readonly onLimit: string;
241
+ readonly guide?: string;
242
+ }
243
+ export interface BoundRefDecl {
244
+ readonly ref: string;
245
+ }
246
+ export type StepBoundDecl = BoundDecl | BoundRefDecl;
247
+ export interface StepDecl {
248
+ readonly name: string;
249
+ readonly from: string;
250
+ readonly to: string;
251
+ readonly needs: readonly NeedDecl[];
252
+ readonly then: readonly EffectDecl[];
253
+ readonly bound?: StepBoundDecl;
254
+ readonly optional?: boolean;
255
+ readonly guide?: string;
256
+ }
257
+ export interface FieldByFieldDecl {
258
+ readonly field: string;
259
+ readonly values: Rec<JsonValue>;
260
+ }
261
+ export type EngineManagedFieldPolicy = {
262
+ readonly default?: JsonValue;
263
+ readonly allowFromParentEffect?: boolean;
264
+ } | {
265
+ readonly byField: FieldByFieldDecl;
266
+ readonly default: JsonValue;
267
+ readonly allowFromParentEffect?: false;
268
+ } | {
269
+ readonly digestOf: string;
270
+ readonly allowFromParentEffect?: boolean;
271
+ } | {
272
+ readonly fromPredecessor: string;
273
+ readonly allowFromParentEffect?: false;
274
+ };
275
+ export interface ProtocolDecl {
276
+ readonly states: readonly [string, string, ...string[]];
277
+ readonly start: string;
278
+ readonly final: NonEmpty<string>;
279
+ readonly data: string;
280
+ readonly openData?: string;
281
+ readonly engineManagedFields?: Rec<EngineManagedFieldPolicy>;
282
+ readonly predecessorField?: string;
283
+ readonly predecessorProtocol?: string;
284
+ readonly roleViews?: Rec<ViewPolicyDecl>;
285
+ readonly brief?: readonly BriefPiece[];
286
+ readonly roleBriefs?: Rec<readonly BriefPiece[]>;
287
+ readonly guide?: string;
288
+ readonly children: readonly string[];
289
+ readonly bounds?: Rec<BoundDecl>;
290
+ readonly acks?: Rec<SpecAckDecl>;
291
+ readonly steps: NonEmpty<StepDecl>;
292
+ }
293
+ export interface FallbackSeatBindingDecl {
294
+ readonly provider: string;
295
+ readonly model: string;
296
+ readonly effort: EffortLevel;
297
+ }
298
+ export interface SeatBindingDecl extends FallbackSeatBindingDecl {
299
+ readonly fallback?: FallbackSeatBindingDecl;
300
+ }
301
+ export type NetworkScheme = "http" | "https";
302
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
303
+ export interface ProcessGrantDecl {
304
+ readonly executable: string;
305
+ readonly args?: readonly string[] | undefined;
306
+ readonly argsPrefix?: readonly string[] | undefined;
307
+ }
308
+ export interface RootGrantDecl {
309
+ readonly root: string;
310
+ }
311
+ export interface NetworkGrantDecl {
312
+ readonly scheme?: NetworkScheme | undefined;
313
+ readonly authority: string;
314
+ readonly methods?: NonEmpty<HttpMethod> | undefined;
315
+ readonly pathPrefixes?: NonEmpty<string> | undefined;
316
+ readonly secrets?: readonly string[] | undefined;
317
+ }
318
+ export interface GitGrantDecl {
319
+ readonly repos?: readonly string[] | undefined;
320
+ readonly pushBranches?: readonly string[] | undefined;
321
+ }
322
+ export interface GranteeGrantsDecl {
323
+ readonly process?: readonly ProcessGrantDecl[] | undefined;
324
+ readonly roots?: readonly RootGrantDecl[] | undefined;
325
+ readonly network?: readonly NetworkGrantDecl[] | undefined;
326
+ readonly clock?: boolean | undefined;
327
+ readonly read?: boolean | undefined;
328
+ readonly git?: GitGrantDecl | undefined;
329
+ }
330
+ export type RoleBindingDecl<Field extends string = string, Protocol extends string = string> = {
331
+ readonly by: "case";
332
+ } | {
333
+ readonly by: "all";
334
+ } | {
335
+ readonly by: "field";
336
+ readonly field: Field;
337
+ } | {
338
+ readonly by: "ancestor";
339
+ readonly protocol: Protocol;
340
+ };
341
+ export interface RosterDecl {
342
+ readonly seating: Rec<SeatBindingDecl>;
343
+ readonly bindings?: Rec<RoleBindingDecl>;
344
+ readonly caps: Rec<number>;
345
+ readonly spendCapUsd?: number;
346
+ readonly grants: Rec<GranteeGrantsDecl>;
347
+ }
348
+ export interface HooksDecl {
349
+ readonly send?: string;
350
+ }
351
+ export interface TelarSpecV1 {
352
+ readonly format: "telar.spec/1";
353
+ readonly profile?: "m1";
354
+ readonly name: string;
355
+ readonly governedBy: string;
356
+ readonly schemas: Rec<TypeSchema>;
357
+ readonly classes: Rec<ClassDecl>;
358
+ readonly roles: Rec<RoleDecl>;
359
+ readonly checks: Rec<CheckDecl>;
360
+ readonly actions: Rec<ActionDecl>;
361
+ readonly messages: Rec<MessageDecl>;
362
+ readonly root: string;
363
+ readonly protocols: Rec<ProtocolDecl>;
364
+ readonly roster: RosterDecl;
365
+ readonly hooks?: HooksDecl;
366
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import type { AnyFieldSchemaEntry, AnyTypeDef, Infer, OptionalType, TypedFieldHandle } from "./schema.js";
2
+ import type { ArgValue, EngineManagedFieldPolicy, JsonValue, Rec } from "./types.js";
3
+ declare const argRefBrand: unique symbol;
4
+ declare const fieldTableBrand: unique symbol;
5
+ export type FieldRef<Name extends string = string, T = unknown> = TypedFieldHandle<Name, T>;
6
+ export interface AnswerRef<T = unknown> {
7
+ readonly kind: "answer-ref";
8
+ readonly name: string;
9
+ readonly [argRefBrand]?: T;
10
+ }
11
+ export interface SeatRef {
12
+ readonly kind: "seat-ref";
13
+ readonly part: "id" | "role";
14
+ }
15
+ export interface CauseRef {
16
+ readonly kind: "cause-ref";
17
+ readonly part: "fact";
18
+ }
19
+ export interface LiteralRef<T extends JsonValue = JsonValue> {
20
+ readonly kind: "literal-ref";
21
+ readonly value: T;
22
+ }
23
+ export type AnyArgRef = FieldRef | AnswerRef | SeatRef | CauseRef | LiteralRef;
24
+ export type ArgInput<T = unknown> = FieldRef<string, T> | FieldRef<string, T | undefined> | AnswerRef<T> | AnswerRef | SeatRef | CauseRef | LiteralRef | (NonNullable<T> extends JsonValue ? NonNullable<T> : never);
25
+ export type ArgMapInput<T extends Readonly<Record<string, unknown>>> = {
26
+ readonly [K in keyof T]: ArgInput<T[K]>;
27
+ };
28
+ export type RecordInput<T> = ArgInput<T> | (NonNullable<T> extends Readonly<Record<string, unknown>> ? {
29
+ readonly [K in keyof NonNullable<T>]: ArgInput<NonNullable<T>[K]>;
30
+ } : never);
31
+ export declare function field<T = unknown, const Name extends string = string>(name: Name): FieldRef<Name, T>;
32
+ export declare function fromAnswer<T = unknown>(name: string): AnswerRef<T>;
33
+ export declare const seat: {
34
+ readonly id: SeatRef;
35
+ readonly role: SeatRef;
36
+ };
37
+ export declare const cause: {
38
+ readonly fact: CauseRef;
39
+ };
40
+ export declare function literal<const T extends JsonValue>(value: T): LiteralRef<T>;
41
+ export interface EngineFieldDef<S extends AnyFieldSchemaEntry = AnyFieldSchemaEntry> {
42
+ readonly kind: "engine-field";
43
+ readonly schema: S;
44
+ readonly policy?: EngineManagedFieldPolicy;
45
+ }
46
+ export type ProtocolFieldEntry = AnyFieldSchemaEntry | EngineFieldDef;
47
+ export type ProtocolFieldMap = Readonly<Record<string, ProtocolFieldEntry>>;
48
+ export interface EngineFieldOpts {
49
+ readonly default?: JsonValue | undefined;
50
+ readonly allowFromParentEffect?: boolean | undefined;
51
+ }
52
+ export interface EngineByFieldOpts {
53
+ readonly field: string | FieldRef;
54
+ readonly values: Rec<JsonValue>;
55
+ readonly default: JsonValue;
56
+ }
57
+ export interface EngineDigestOpts {
58
+ readonly allowFromParentEffect?: boolean | undefined;
59
+ }
60
+ export declare const engine: {
61
+ <S extends AnyFieldSchemaEntry>(schema: S, opts?: EngineFieldOpts): EngineFieldDef<S>;
62
+ readonly byField: <S extends AnyTypeDef>(schema: S, opts: EngineByFieldOpts) => EngineFieldDef<S>;
63
+ readonly fromPredecessor: <S extends AnyTypeDef>(schema: S, sourceField: string | FieldRef) => EngineFieldDef<S>;
64
+ readonly digestOf: <S extends AnyTypeDef>(schema: S, sourceField: string | FieldRef, opts?: EngineDigestOpts) => EngineFieldDef<S>;
65
+ };
66
+ type InferEntry<E> = E extends EngineFieldDef<infer Inner> ? InferEntry<Inner> : E extends OptionalType<infer Inner> ? Infer<Inner> | undefined : Infer<E>;
67
+ export type FieldTable<M extends ProtocolFieldMap = ProtocolFieldMap> = {
68
+ readonly [K in keyof M & string]: FieldRef<K, InferEntry<M[K]>>;
69
+ } & {
70
+ readonly [fieldTableBrand]: M;
71
+ };
72
+ export interface InternalFieldTableMeta {
73
+ readonly entries: ProtocolFieldMap;
74
+ }
75
+ export declare function fields<M extends ProtocolFieldMap>(spec: M): FieldTable<M>;
76
+ export declare function fields(spec: ProtocolFieldMap): Readonly<Record<string, FieldRef>>;
77
+ export declare function readFieldTableMeta(value: object): InternalFieldTableMeta | undefined;
78
+ export declare function isArgRef(value: unknown): value is AnyArgRef;
79
+ export declare function assertJsonValue(value: unknown, at: string): JsonValue;
80
+ export declare function liftArg(value: unknown, at: string): ArgValue;
81
+ export {};
package/dist/values.js ADDED
@@ -0,0 +1,129 @@
1
+ export function field(name) {
2
+ return Object.freeze({ kind: "field", name });
3
+ }
4
+ export function fromAnswer(name) {
5
+ return Object.freeze({ kind: "answer-ref", name });
6
+ }
7
+ export const seat = Object.freeze({
8
+ id: Object.freeze({ kind: "seat-ref", part: "id" }),
9
+ role: Object.freeze({ kind: "seat-ref", part: "role" }),
10
+ });
11
+ export const cause = Object.freeze({
12
+ fact: Object.freeze({ kind: "cause-ref", part: "fact" }),
13
+ });
14
+ export function literal(value) {
15
+ return Object.freeze({ kind: "literal-ref", value });
16
+ }
17
+ function makeEngineField(schema, opts) {
18
+ if (opts?.default === undefined && opts?.allowFromParentEffect === undefined) {
19
+ return Object.freeze({ kind: "engine-field", schema });
20
+ }
21
+ const policy = {
22
+ ...(opts.default !== undefined ? { default: opts.default } : {}),
23
+ allowFromParentEffect: opts.allowFromParentEffect ?? false,
24
+ };
25
+ return Object.freeze({ kind: "engine-field", schema, policy });
26
+ }
27
+ export const engine = Object.freeze(Object.assign(makeEngineField, {
28
+ byField(schema, opts) {
29
+ const fieldName = typeof opts.field === "string" ? opts.field : opts.field.name;
30
+ return Object.freeze({
31
+ kind: "engine-field",
32
+ schema,
33
+ policy: {
34
+ byField: { field: fieldName, values: opts.values },
35
+ default: opts.default,
36
+ allowFromParentEffect: false,
37
+ },
38
+ });
39
+ },
40
+ fromPredecessor(schema, sourceField) {
41
+ const fieldName = typeof sourceField === "string" ? sourceField : sourceField.name;
42
+ return Object.freeze({
43
+ kind: "engine-field",
44
+ schema,
45
+ policy: {
46
+ fromPredecessor: fieldName,
47
+ allowFromParentEffect: false,
48
+ },
49
+ });
50
+ },
51
+ digestOf(schema, sourceField, opts) {
52
+ const fieldName = typeof sourceField === "string" ? sourceField : sourceField.name;
53
+ return Object.freeze({
54
+ kind: "engine-field",
55
+ schema,
56
+ policy: {
57
+ digestOf: fieldName,
58
+ ...(opts?.allowFromParentEffect !== undefined
59
+ ? { allowFromParentEffect: opts.allowFromParentEffect }
60
+ : {}),
61
+ },
62
+ });
63
+ },
64
+ }));
65
+ const fieldTableRegistry = new WeakMap();
66
+ export function fields(spec) {
67
+ const handles = {};
68
+ for (const key of Object.keys(spec)) {
69
+ handles[key] = Object.freeze({ kind: "field", name: key });
70
+ }
71
+ const frozen = Object.freeze(handles);
72
+ fieldTableRegistry.set(frozen, { entries: spec });
73
+ return frozen;
74
+ }
75
+ export function readFieldTableMeta(value) {
76
+ return fieldTableRegistry.get(value);
77
+ }
78
+ export function isArgRef(value) {
79
+ if (typeof value !== "object" || value === null || !("kind" in value)) {
80
+ return false;
81
+ }
82
+ const kind = value.kind;
83
+ return (kind === "field" ||
84
+ kind === "answer-ref" ||
85
+ kind === "seat-ref" ||
86
+ kind === "cause-ref" ||
87
+ kind === "literal-ref");
88
+ }
89
+ export function assertJsonValue(value, at) {
90
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
91
+ return value;
92
+ }
93
+ if (typeof value === "number") {
94
+ if (!Number.isFinite(value)) {
95
+ throw new TypeError(`${at}: non-finite number`);
96
+ }
97
+ return value;
98
+ }
99
+ if (Array.isArray(value)) {
100
+ return value.map((item, idx) => assertJsonValue(item, `${at}[${String(idx)}]`));
101
+ }
102
+ if (typeof value === "object") {
103
+ const out = {};
104
+ for (const [k, v] of Object.entries(value)) {
105
+ if (v === undefined)
106
+ continue;
107
+ out[k] = assertJsonValue(v, `${at}.${k}`);
108
+ }
109
+ return out;
110
+ }
111
+ throw new TypeError(`${at}: unsupported JSON literal of type ${typeof value}`);
112
+ }
113
+ export function liftArg(value, at) {
114
+ if (isArgRef(value)) {
115
+ switch (value.kind) {
116
+ case "field":
117
+ return { $field: value.name };
118
+ case "answer-ref":
119
+ return { $answer: value.name };
120
+ case "seat-ref":
121
+ return { $seat: value.part };
122
+ case "cause-ref":
123
+ return { $cause: value.part };
124
+ case "literal-ref":
125
+ return { $literal: assertJsonValue(value.value, at) };
126
+ }
127
+ }
128
+ return { $literal: assertJsonValue(value, at) };
129
+ }
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@aitoroses/telar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Typed authoring libraries compiling to telar.spec/1 and telar.scenario/1",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/aitoroses/telar.git",
9
+ "directory": "packages/telar"
10
+ },
11
+ "bin": {
12
+ "telar-module": "./dist/node/telar-module.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "exports": {
21
+ "./spec": {
22
+ "types": "./dist/spec.d.ts",
23
+ "import": "./dist/spec.js"
24
+ },
25
+ "./std": {
26
+ "types": "./dist/std.d.ts",
27
+ "import": "./dist/std.js"
28
+ },
29
+ "./scenario": {
30
+ "types": "./dist/scenario.d.ts",
31
+ "import": "./dist/scenario.js"
32
+ },
33
+ "./contract": {
34
+ "types": "./dist/contract.d.ts",
35
+ "import": "./dist/contract.js"
36
+ },
37
+ "./build": {
38
+ "types": "./dist/node/build.d.ts",
39
+ "import": "./dist/node/build.js"
40
+ }
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^26.6.11",
44
+ "oxfmt": "^0.80.0",
45
+ "oxlint": "^1.95.0",
46
+ "oxlint-tsgolint": "^7.0.2009",
47
+ "rolldown": "1.3.4",
48
+ "tsrs": "7.1.0-beta.tsrs5",
49
+ "typescript": "^7.0.2",
50
+ "vitest": "^5.1.2"
51
+ },
52
+ "peerDependencies": {
53
+ "rolldown": "^1.3.4"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "rolldown": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "scripts": {
61
+ "build": "tsc -p tsconfig.build.json && tsc -p tsconfig.node.json",
62
+ "typecheck": "tsrs --noEmit -p tsconfig.build.json && tsrs --noEmit -p tsconfig.json",
63
+ "lint": "oxlint --type-aware --deny-warnings",
64
+ "fmt": "oxfmt",
65
+ "fmt:check": "oxfmt --check",
66
+ "test": "pnpm build && vitest run"
67
+ }
6
68
  }