@northtalk/ts 0.1.0 → 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.
- package/README.md +9 -5
- package/{encoding-DWlbPq-e.js → base64-DORMd3Hv.js} +197 -1368
- package/binary-value-CEmh60GC.d.ts +15 -0
- package/capabilities-CH0FkRMq.js +1301 -0
- package/checker-Dc1jl2WH.js +6657 -0
- package/core-DptnvQT9.d.ts +14 -0
- package/{debug-D8Z_u244.d.ts → debug-CQBxKnJB.d.ts} +1147 -780
- package/debug.d.ts +2 -1
- package/debug.js +2 -1
- package/driver.d.ts +16 -2
- package/driver.js +98 -20
- package/encoding-nlrpj-Pb.js +99 -0
- package/{engine-CgCMdGGd.js → engine-BGaJ9dAk.js} +7 -5
- package/{engine-BPFnHT9N.d.ts → engine-vbYInVYF.d.ts} +3 -3
- package/{errors-DHwz1Vho.js → errors-LYJZ_c8h.js} +91 -17
- package/{group-B4eyJKTA.js → group-B742gg4T.js} +1490 -7278
- package/{sqlite-capability-CrCej3Po.js → http-capability-CSTkw1Yt.js} +255 -5
- package/http.d.ts +59 -0
- package/http.js +465 -0
- package/index.d.ts +23 -17
- package/index.js +19 -12
- package/manifest-BscyH_rW.d.ts +70 -0
- package/{manifest-DKe2Je6Z.js → manifest-DjsxDSuB.js} +11 -90
- package/message-layer.d.ts +12 -0
- package/message-layer.js +4 -0
- package/notify.d.ts +2 -1
- package/notify.js +2 -1
- package/{objects-MeXIDDFo.d.ts → objects-DJ3QtCCs.d.ts} +23 -8
- package/objects-Db7IB5vQ.js +91 -0
- package/operation-promises-EgZXG5N_.js +23 -0
- package/package.json +9 -1
- package/readers-BFPuosPk.d.ts +25 -0
- package/{readers-DyjxJEkL.js → readers-CjJHKHvH.js} +6 -3
- package/request-pump-binary-DdY3X-yl.js +2246 -0
- package/{router-DHPJNvbt.js → router--71qvxtY.js} +8 -6
- package/{router-DpDpAJjz.d.ts → router-Zhrw5l__.d.ts} +6 -5
- package/session.d.ts +2 -1
- package/session.js +58 -24
- package/setup.d.ts +2 -1
- package/setup.js +8 -4
- package/{sha256-0jiTgVJu.js → sha256-B_kyYw3Z.js} +1 -0
- package/sqlite.d.ts +3 -4
- package/sqlite.js +6 -5
- package/{store-capability-CDoVafZL.js → store-capability-OZp4hXmj.js} +10 -7
- package/{store-DrYjcoru.js → store-hJrRULMx.js} +3 -2
- package/store.d.ts +3 -2
- package/store.js +3 -2
- package/{user-capability-Cv0oJhhv.js → user-capability-BK4Asg7D.js} +8 -5
- package/wasm.d.ts +42 -22
- package/wasm.js +330 -46
- package/core-eU5KaYkz.d.ts +0 -23
- package/readers-Oh4tO2dK.d.ts +0 -57
- package/sqlite-capability-C7-SYdD7.d.ts +0 -87
- package/user-capability-CLkDsrCX.d.ts +0 -40
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
//#region src/syntax.d.ts
|
|
2
3
|
type SyntaxErrorCode = 'unterminated interpolation' | 'empty interpolation' | 'invalid text escape' | 'invalid text indentation' | 'invalid text delimiter' | 'bad character' | 'unterminated text' | 'bad unit' | 'unexpected token' | 'not a container';
|
|
3
4
|
/** All offsets index the original TS string; line and col count Unicode scalars. */
|
|
@@ -9,7 +10,7 @@ type Trivia = {
|
|
|
9
10
|
pos: number;
|
|
10
11
|
raw: string;
|
|
11
12
|
};
|
|
12
|
-
type SyntaxRule = 'Source' | 'Entry' | 'Error' | 'Declaration' | 'Use' | 'Handler' | 'Parameter' | 'Function' | 'Block' | 'Body' | 'Statement' | 'SimpleStatement' | 'ExpressionList' | 'Container' | 'AndWait' | 'Send' | 'AskTell' | 'TellBlock' | 'TimeoutBlock' | 'OperationLine' | 'Wait' | 'Event' | 'If' | 'Repeat' | 'Collecting' | 'Match' | 'Try' | 'OfferClause' | 'OfferParameter' | 'RecoveryMarker' | 'ChooseOffer' | 'Replace' | 'IgnoringCase' | 'Expression' | 'Lambda' | 'Whose' | 'EveryHead' | 'WhoseKey' | 'Default' | 'Or' | 'And' | 'Not' | 'Comparison' | 'Concat' | 'Range' | 'Additive' | 'Multiplicative' | 'Power' | 'Unary' | 'Conversion' | 'Kind' | 'ChunkLevel' | 'Postfix' | 'Key' | 'Call' | 'Primary' | 'Interpolated' | 'Chunk' | 'The' | 'List' | 'MapKey' | 'Map' | 'Pattern' | 'PatternPrimary' | 'TextPattern' | 'Alternation' | 'Element' | 'Atom' | 'BinaryPattern' | 'Field' | 'AsText' | 'FieldType' | 'BinaryBuild' | 'Name' | 'MessageName' | 'Label';
|
|
13
|
+
type SyntaxRule = 'Source' | 'Entry' | 'Error' | 'Declaration' | 'Use' | 'Handler' | 'Parameter' | 'Function' | 'Block' | 'Body' | 'Statement' | 'SimpleStatement' | 'ExpressionList' | 'Container' | 'AndWait' | 'ResultTarget' | 'Send' | 'AskTell' | 'TellBlock' | 'TimeoutBlock' | 'OperationLine' | 'Wait' | 'Event' | 'If' | 'Repeat' | 'Collecting' | 'Match' | 'Try' | 'OfferClause' | 'OfferParameter' | 'RecoveryMarker' | 'ChooseOffer' | 'Replace' | 'IgnoringCase' | 'Expression' | 'Lambda' | 'Whose' | 'EveryHead' | 'WhoseKey' | 'Default' | 'Or' | 'And' | 'Not' | 'Comparison' | 'Concat' | 'Range' | 'Additive' | 'Multiplicative' | 'Power' | 'Unary' | 'Conversion' | 'Kind' | 'ChunkLevel' | 'Postfix' | 'Key' | 'Call' | 'Primary' | 'Interpolated' | 'Chunk' | 'The' | 'List' | 'MapKey' | 'Map' | 'Pattern' | 'PatternPrimary' | 'TextPattern' | 'Alternation' | 'Element' | 'Atom' | 'BinaryPattern' | 'Field' | 'AsText' | 'FieldType' | 'BinaryBuild' | 'Name' | 'MessageName' | 'Label';
|
|
13
14
|
type SyntaxElement = SyntaxNode | Token;
|
|
14
15
|
/** Children are ordered and own each source character exactly once. Spans include trivia. */
|
|
15
16
|
type SyntaxNode = {
|
|
@@ -563,6 +564,7 @@ type Stmt = {
|
|
|
563
564
|
target: Expr;
|
|
564
565
|
} | {
|
|
565
566
|
args: Expr[];
|
|
567
|
+
into?: SemanticName;
|
|
566
568
|
k: 'send';
|
|
567
569
|
/** The message name, or for `send (e)` the expression that computes it. */
|
|
568
570
|
message: string | Expr;
|
|
@@ -574,7 +576,11 @@ type Stmt = {
|
|
|
574
576
|
} | {
|
|
575
577
|
args: Expr[];
|
|
576
578
|
grant: string;
|
|
579
|
+
/** A Result Target (ADR 0114). */
|
|
580
|
+
into?: SemanticName;
|
|
577
581
|
k: 'ask' | 'tell';
|
|
582
|
+
/** A labelled call's Argument Labels, checked at load only (ADR 0115). */
|
|
583
|
+
labels?: string[];
|
|
578
584
|
operation: string;
|
|
579
585
|
pos: Pos;
|
|
580
586
|
wait: boolean;
|
|
@@ -590,6 +596,7 @@ type Stmt = {
|
|
|
590
596
|
pos: Pos;
|
|
591
597
|
} | {
|
|
592
598
|
event: Event;
|
|
599
|
+
guard: Guard | null;
|
|
593
600
|
k: 'wait-for';
|
|
594
601
|
pos: Pos;
|
|
595
602
|
timeout: Expr | null;
|
|
@@ -630,11 +637,13 @@ type Stmt = {
|
|
|
630
637
|
call: Expr & {
|
|
631
638
|
k: 'call';
|
|
632
639
|
};
|
|
640
|
+
into?: SemanticName;
|
|
633
641
|
k: 'call';
|
|
634
642
|
pos: Pos;
|
|
635
643
|
wait: boolean;
|
|
636
644
|
} | {
|
|
637
645
|
args: Expr[];
|
|
646
|
+
into?: SemanticName;
|
|
638
647
|
k: 'command';
|
|
639
648
|
name: SemanticName;
|
|
640
649
|
pos: Pos;
|
|
@@ -785,665 +794,207 @@ declare class LoadError extends Error {
|
|
|
785
794
|
declare class MailboxFull extends Error {
|
|
786
795
|
name: string;
|
|
787
796
|
}
|
|
797
|
+
/** Why a `send failed` came with no answer (ADR 0033, chapter 9). */
|
|
798
|
+
type SendFailedReason = 'errored' | 'limit fault' | 'cancelled' | 'unhandled' | 'dropped' | 'stopped' | 'function gone' | 'effect failed';
|
|
788
799
|
/**
|
|
789
800
|
* A Script-level error as the Host sees it, such as a Request's `send failed`
|
|
790
|
-
* or a `run end`'s error. Its `data` is a map, or Nothing.
|
|
801
|
+
* or a `run end`'s error. Its `data` is a map, or Nothing. A `send failed`
|
|
802
|
+
* also carries its `reason` from `data`.
|
|
791
803
|
*/
|
|
792
804
|
declare class ScriptError extends Error {
|
|
793
805
|
readonly code: string;
|
|
794
806
|
readonly data: Value;
|
|
807
|
+
readonly reason: SendFailedReason | undefined;
|
|
795
808
|
constructor(code: string, message: string, data?: Value);
|
|
796
809
|
}
|
|
797
810
|
//#endregion
|
|
798
|
-
//#region src/
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
k: 'kind';
|
|
805
|
-
kind: string;
|
|
806
|
-
} | {
|
|
807
|
-
k: 'object';
|
|
808
|
-
kind: string;
|
|
809
|
-
} | {
|
|
810
|
-
k: 'quantity';
|
|
811
|
-
unit: string;
|
|
812
|
-
} | {
|
|
813
|
-
k: 'unitKind';
|
|
814
|
-
kind: string;
|
|
815
|
-
} | {
|
|
816
|
-
k: 'list';
|
|
817
|
-
of: Shape;
|
|
818
|
-
} | {
|
|
819
|
-
fields: readonly {
|
|
820
|
-
key: string;
|
|
821
|
-
optional: boolean;
|
|
822
|
-
shape: Shape;
|
|
823
|
-
}[];
|
|
824
|
-
k: 'map';
|
|
825
|
-
open: boolean;
|
|
826
|
-
} | {
|
|
827
|
-
k: 'oneOf';
|
|
828
|
-
of: readonly Shape[];
|
|
829
|
-
} | {
|
|
830
|
-
k: 'optional';
|
|
831
|
-
of: Shape;
|
|
832
|
-
};
|
|
833
|
-
type FieldShape = Shape | {
|
|
834
|
-
optional: true;
|
|
835
|
-
shape: Shape;
|
|
836
|
-
};
|
|
837
|
-
/** The Shape constructors of `talk.ts`. */
|
|
838
|
-
declare const shape: {
|
|
839
|
-
any: Shape;
|
|
840
|
-
value: Shape;
|
|
841
|
-
nothing: Shape;
|
|
842
|
-
bool: Shape;
|
|
843
|
-
number: Shape;
|
|
844
|
-
text: Shape;
|
|
845
|
-
bytes: Shape;
|
|
846
|
-
instant: Shape;
|
|
847
|
-
civilDate: Shape;
|
|
848
|
-
range: Shape;
|
|
849
|
-
pattern: Shape;
|
|
850
|
-
function: Shape;
|
|
851
|
-
object: <N>(kind: ObjectKind<N>) => Shape;
|
|
852
|
-
quantityOf: (unit: string) => Shape;
|
|
853
|
-
quantityKind: (unitKind: string) => Shape;
|
|
854
|
-
listOf: (of: Shape) => Shape;
|
|
855
|
-
map: (fields: Record<string, FieldShape>) => Shape;
|
|
856
|
-
openMap: (fields: Record<string, FieldShape>) => Shape;
|
|
857
|
-
oneOf: (...of: Shape[]) => Shape;
|
|
858
|
-
optional: (of: Shape) => Shape;
|
|
859
|
-
};
|
|
860
|
-
type ScopeDecl = {
|
|
861
|
-
abandon: string;
|
|
862
|
-
opens: string;
|
|
863
|
-
} | {
|
|
864
|
-
closes: string;
|
|
865
|
-
};
|
|
866
|
-
/** Synchronous, unmetered participant lifecycle work. */
|
|
867
|
-
type SegmentContext<B> = {
|
|
868
|
-
readonly binding: B;
|
|
869
|
-
/** The first enrolled Grant. */
|
|
870
|
-
readonly grantName: string;
|
|
871
|
-
/** Enrolled, in enrollment order; `begin` sees only the first. */
|
|
872
|
-
readonly grants: readonly SegmentGrant<B>[];
|
|
873
|
-
readonly group: Group;
|
|
874
|
-
readonly now: bigint;
|
|
875
|
-
readonly runId: string;
|
|
876
|
-
readonly scriptName: string;
|
|
877
|
-
readonly segmentId: string;
|
|
878
|
-
};
|
|
879
|
-
type SegmentGrant<B> = {
|
|
880
|
-
readonly binding: B;
|
|
881
|
-
readonly grantName: string;
|
|
882
|
-
};
|
|
883
|
-
type EffectResult = {
|
|
884
|
-
detail?: string;
|
|
885
|
-
status: 'ok' | 'failed' | 'unknown';
|
|
886
|
-
};
|
|
887
|
-
type SegmentLifecycle<B> = {
|
|
888
|
-
begin(context: SegmentContext<B>): EffectResult;
|
|
889
|
-
commit(context: SegmentContext<B>): EffectResult;
|
|
890
|
-
rollback(context: SegmentContext<B>): EffectResult;
|
|
891
|
-
};
|
|
892
|
-
/** Compared by identity: Grants mapped to one coordinator share a Segment's participant (ADR 0069). */
|
|
893
|
-
type SegmentCoordinator = SegmentLifecycle<unknown>;
|
|
894
|
-
/** Maps each binding to its coordinator once, when a Grant is created. */
|
|
895
|
-
type CoordinatedLifecycle<B> = {
|
|
896
|
-
coordinator(binding: B): SegmentCoordinator;
|
|
897
|
-
};
|
|
898
|
-
type Cost = {
|
|
899
|
-
alloc?: number;
|
|
900
|
-
fuel: number;
|
|
901
|
-
};
|
|
902
|
-
type ErrorDecl = {
|
|
903
|
-
code: string;
|
|
904
|
-
fields?: Record<string, FieldShape>;
|
|
905
|
-
};
|
|
906
|
-
type OpBase = {
|
|
907
|
-
args?: Shape[];
|
|
908
|
-
/** Also callable as a Host Command, by its name alone (ADR 0094). */
|
|
909
|
-
command?: boolean;
|
|
910
|
-
cost: Cost;
|
|
911
|
-
/** Plain-text documentation, carried only by the Host Manifest. */
|
|
912
|
-
description?: string;
|
|
913
|
-
errors?: ErrorDecl[];
|
|
914
|
-
examples?: string[];
|
|
915
|
-
result?: Shape;
|
|
916
|
-
};
|
|
917
|
-
/** What the Core gives a Host function at each call (chapter 9, The call). */
|
|
918
|
-
type Call<B> = {
|
|
919
|
-
/** Queued, for a suspending call; ignored once the call isn't pending. */
|
|
920
|
-
answer(v: Value, lateCost?: {
|
|
921
|
-
fuel: number;
|
|
922
|
-
}): void;
|
|
923
|
-
readonly automatic: boolean;
|
|
924
|
-
readonly binding: B;
|
|
925
|
-
/** Draws more Fuel, before the work. Throws LimitReached. */
|
|
926
|
-
charge(fuel: number): void;
|
|
927
|
-
fail(e: ScriptError): void;
|
|
928
|
-
readonly grantName: string;
|
|
929
|
-
readonly group: Group;
|
|
930
|
-
readonly id: string;
|
|
931
|
-
readonly now: bigint;
|
|
932
|
-
readonly runId: string;
|
|
933
|
-
readonly scopeName?: string;
|
|
934
|
-
readonly scriptName: string;
|
|
935
|
-
readonly segmentId: string;
|
|
936
|
-
readonly signal: AbortSignal;
|
|
937
|
-
};
|
|
938
|
-
type ImmediateOp<B> = OpBase & {
|
|
939
|
-
do(call: Call<B>, ...args: Value[]): Value;
|
|
940
|
-
mode: 'immediate';
|
|
941
|
-
scope?: ScopeDecl;
|
|
942
|
-
segmentBound?: boolean;
|
|
943
|
-
};
|
|
944
|
-
type SuspendingOp<B> = OpBase & {
|
|
945
|
-
maxPendingMs?: number;
|
|
946
|
-
mode: 'suspending';
|
|
947
|
-
run?(call: Call<B>, ...args: Value[]): Promise<Value>;
|
|
948
|
-
start?(call: Call<B>, ...args: Value[]): void;
|
|
811
|
+
//#region src/binary.d.ts
|
|
812
|
+
/** A reader: Bytes and the position of the next byte to read. */
|
|
813
|
+
type Reader = {
|
|
814
|
+
at: number;
|
|
815
|
+
bytes: Uint8Array;
|
|
816
|
+
k: 'reader';
|
|
949
817
|
};
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region src/units.d.ts
|
|
820
|
+
/** One slot of a Unit: a Unit of a Unit Kind, and its exponent. */
|
|
821
|
+
type Slot = {
|
|
822
|
+
readonly exponent: number;
|
|
823
|
+
readonly unit: string;
|
|
953
824
|
};
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
825
|
+
/** A Unit's slots in Kind order. An empty Unit is a plain number. */
|
|
826
|
+
type UnitSpec = readonly Slot[];
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region src/operations.d.ts
|
|
829
|
+
/** Behaviour this Core doesn't implement yet; never a Script error. */
|
|
830
|
+
declare class NotImplementedError extends Error {
|
|
957
831
|
name: string;
|
|
958
832
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
readonly
|
|
964
|
-
readonly
|
|
965
|
-
readonly now: bigint;
|
|
966
|
-
readonly reason: ReleaseReason;
|
|
967
|
-
readonly scriptName: string;
|
|
968
|
-
};
|
|
969
|
-
/** Synchronous, unmetered cleanup. Exceptions cannot refuse release. */
|
|
970
|
-
type ReleaseHook<B> = (context: GrantContext<B>) => void;
|
|
971
|
-
type CapabilityDef<B> = {
|
|
972
|
-
/** Maps a Grant's binding to its Segment Coordinator. */
|
|
973
|
-
coordinator?(binding: B): SegmentCoordinator;
|
|
974
|
-
/** A reusable template. Each load binds it to one Script. */
|
|
975
|
-
grant(ops: readonly string[] | 'all', binding: B): Grant<B>;
|
|
976
|
-
/** A plain lifecycle, making each Grant its own coordinator. */
|
|
977
|
-
readonly lifecycle?: SegmentLifecycle<B>;
|
|
978
|
-
readonly name: string;
|
|
979
|
-
/** Its Operations, ordered by name. */
|
|
980
|
-
readonly operations: ReadonlyMap<string, Operation<B>>;
|
|
981
|
-
release?(context: GrantContext<B>): void;
|
|
982
|
-
};
|
|
983
|
-
type Grant<B> = {
|
|
984
|
-
readonly binding: B;
|
|
985
|
-
readonly capability: CapabilityDef<B>;
|
|
986
|
-
/** Resolved at Grant creation; absent when the Grant is its own coordinator. */
|
|
987
|
-
readonly coordinator?: SegmentCoordinator;
|
|
988
|
-
readonly ops: ReadonlySet<string>;
|
|
833
|
+
/** `wait d`'s duration in microseconds; anything but an exact duration is `wrong kind`. */
|
|
834
|
+
declare const waitUs: (v: Value) => bigint;
|
|
835
|
+
/** A verified static Unit target, owned by its loaded code unit. */
|
|
836
|
+
type UnitConversion = {
|
|
837
|
+
readonly to: string;
|
|
838
|
+
readonly unit: UnitSpec;
|
|
989
839
|
};
|
|
990
|
-
|
|
991
|
-
declare const defineCapability: <B = void>(name: string, ops: Record<string, Operation<B>>, lifecycle?: SegmentLifecycle<B> | CoordinatedLifecycle<B>, release?: ReleaseHook<B>) => CapabilityDef<B>;
|
|
840
|
+
declare const canConvert: (v: Value, kind: string, prepared?: UnitConversion) => Value;
|
|
992
841
|
//#endregion
|
|
993
|
-
//#region src/
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
mode: OperationMode;
|
|
1000
|
-
}>>>>;
|
|
842
|
+
//#region src/waits.d.ts
|
|
843
|
+
/**
|
|
844
|
+
* The ways a call's Wait ends without its answer being used. Hosts see only
|
|
845
|
+
* the aborted signal; neither the Trace nor a save records the reason.
|
|
846
|
+
*/
|
|
847
|
+
type AbandonReason = 'cancelled' | 'effect-failed' | 'join-ended' | 'join-failed' | 'limit' | 'rewound' | 'stopped' | 'timeout';
|
|
1001
848
|
//#endregion
|
|
1002
|
-
//#region src/
|
|
1003
|
-
type
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
849
|
+
//#region src/machine.d.ts
|
|
850
|
+
type LimitName = 'fuelPerRun' | 'allocPerRun' | 'persistentState' | 'callDepth' | 'patternSize' | 'mailboxDepth' | 'maxWaitMs' | 'maxJoin' | 'cleanupBudget';
|
|
851
|
+
type Limits = Record<LimitName, number>;
|
|
852
|
+
declare const defaultLimits: Limits;
|
|
853
|
+
/** A code unit that can't load: a literal pattern past its limit, or a failed initialiser. */
|
|
854
|
+
declare class UnitLoadError extends Error {
|
|
855
|
+
readonly code: 'pattern too large' | 'initialiser failed';
|
|
856
|
+
readonly line: number;
|
|
857
|
+
readonly col: number;
|
|
858
|
+
readonly error: Value | null;
|
|
859
|
+
constructor(code: 'pattern too large' | 'initialiser failed', line: number, col: number, error?: Value | null);
|
|
860
|
+
}
|
|
861
|
+
type Constant = {
|
|
862
|
+
k: 'value';
|
|
863
|
+
value: Value;
|
|
864
|
+
} | {
|
|
865
|
+
els: readonly PatternElement[];
|
|
866
|
+
k: 'template';
|
|
867
|
+
} | {
|
|
868
|
+
k: 'unimplemented';
|
|
869
|
+
what: string;
|
|
1010
870
|
};
|
|
1011
871
|
/**
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1014
|
-
* gets a nonzero index, negative from the end.
|
|
872
|
+
* A loaded code unit, a Script's or a Library's: its constants, definitions
|
|
873
|
+
* and Handler clauses, linked to the Libraries its `use` lines name.
|
|
1015
874
|
*/
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
declare const civilFromFields: (f: {
|
|
1068
|
-
day: number;
|
|
1069
|
-
hour?: number;
|
|
1070
|
-
microsecond?: number;
|
|
1071
|
-
minute?: number;
|
|
1072
|
-
month: number;
|
|
1073
|
-
second?: number;
|
|
1074
|
-
year: number;
|
|
1075
|
-
}) => CivilRef | string;
|
|
1076
|
-
/** A Civil Date's fields, as the Host reads them. */
|
|
1077
|
-
declare const civilFields: (c: CivilRef) => {
|
|
1078
|
-
year: number;
|
|
1079
|
-
month: number;
|
|
1080
|
-
day: number;
|
|
1081
|
-
} | {
|
|
1082
|
-
hour: number;
|
|
1083
|
-
minute: number;
|
|
1084
|
-
second: number;
|
|
1085
|
-
microsecond: number;
|
|
1086
|
-
year: number;
|
|
1087
|
-
month: number;
|
|
1088
|
-
day: number;
|
|
1089
|
-
};
|
|
1090
|
-
/** An Instant's text form, always in UTC: `2026-09-27T13:30:00Z`. */
|
|
1091
|
-
declare const formatInstant: (us: bigint) => string;
|
|
1092
|
-
/** An Instant's display form as epoch microseconds, for the Host and the Trace. */
|
|
1093
|
-
declare const parseInstant: (s: string) => bigint;
|
|
1094
|
-
//#endregion
|
|
1095
|
-
//#region src/units.d.ts
|
|
1096
|
-
/** One slot of a Unit: a Unit of a Unit Kind, and its exponent. */
|
|
1097
|
-
type Slot = {
|
|
1098
|
-
readonly exponent: number;
|
|
1099
|
-
readonly unit: string;
|
|
1100
|
-
};
|
|
1101
|
-
/** A Unit's slots in Kind order. An empty Unit is a plain number. */
|
|
1102
|
-
type UnitSpec = readonly Slot[];
|
|
1103
|
-
//#endregion
|
|
1104
|
-
//#region src/values.d.ts
|
|
1105
|
-
/** The kinds implemented so far; the rest of chapter 3's follow with #126. */
|
|
1106
|
-
type Kind = 'nothing' | 'boolean' | 'number' | 'quantity' | 'text' | 'bytes' | 'list' | 'map' | 'range' | 'instant' | 'civil date' | 'pattern' | 'function' | 'object';
|
|
1107
|
-
type Pairs = readonly (readonly [string, Value])[];
|
|
875
|
+
declare class Code {
|
|
876
|
+
readonly unit: CodeUnit;
|
|
877
|
+
readonly identity: string;
|
|
878
|
+
/** Static conversion metadata; rebuilt on Load, Reload and Restore. */
|
|
879
|
+
readonly conversions: Map<Instruction, UnitConversion>;
|
|
880
|
+
readonly constants: Constant[];
|
|
881
|
+
readonly definitions: Value[];
|
|
882
|
+
readonly clauses: Map<string, Body[]>;
|
|
883
|
+
/**
|
|
884
|
+
* Its Fallback Handler's clauses, in source order. They are kept apart
|
|
885
|
+
* from `clauses`, so no Selector finds them (ADR 0064).
|
|
886
|
+
*/
|
|
887
|
+
fallback: Body[];
|
|
888
|
+
/** The Libraries it imports, by name. */
|
|
889
|
+
readonly libraries: Map<string, Code>;
|
|
890
|
+
/** Whether it is a stdlib Library's, whose errors name the caller (ADR 0037). */
|
|
891
|
+
stdlib: boolean;
|
|
892
|
+
/**
|
|
893
|
+
* Whether its errors name the caller, as a stdlib Library's do. A Host may
|
|
894
|
+
* ask this of any Library, outside the Spec, as `northtalk test` does.
|
|
895
|
+
*/
|
|
896
|
+
atCaller: boolean;
|
|
897
|
+
constructor(unit: CodeUnit, identity?: string);
|
|
898
|
+
get name(): string;
|
|
899
|
+
constant(i: number): Value;
|
|
900
|
+
/** The Library that holds an import, written `library:name`. */
|
|
901
|
+
library(name: string): {
|
|
902
|
+
code: Code;
|
|
903
|
+
name: string;
|
|
904
|
+
};
|
|
905
|
+
/** An exported function's body. */
|
|
906
|
+
function(name: string): Body;
|
|
907
|
+
/** Link the Libraries it imports, and take the Constants it imports from them. */
|
|
908
|
+
link(libraries: ReadonlyMap<string, Code>, home?: Script$1): void;
|
|
909
|
+
}
|
|
910
|
+
/** A loaded Script: its code, and its Script Variables. */
|
|
911
|
+
declare class Script$1 extends Code {
|
|
912
|
+
readonly limits: Limits;
|
|
913
|
+
readonly home?: Script$1 | undefined;
|
|
914
|
+
variables: Value[];
|
|
915
|
+
functionGroup?: object;
|
|
916
|
+
readonly boundConstants: Map<Value, Value>;
|
|
917
|
+
live: boolean;
|
|
918
|
+
readonly units: Code[];
|
|
919
|
+
variableNames: string[];
|
|
920
|
+
constructor(unit: CodeUnit, limits?: Limits, home?: Script$1 | undefined, identity?: string);
|
|
921
|
+
codeFor(body: Body): Code;
|
|
922
|
+
attach(extension: Script$1): void;
|
|
923
|
+
/** The Script Variables' share of Persistent State. */
|
|
924
|
+
variablesSize(): number;
|
|
925
|
+
}
|
|
1108
926
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
* is the Abstract Machine's own reference, which no Host or Script sees.
|
|
927
|
+
* Load a code unit: check each literal Text Pattern against the size limit,
|
|
928
|
+
* then run the initialiser, which is never charged (chapter 8, Charging).
|
|
1112
929
|
*/
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
readonly group?: object;
|
|
1120
|
-
readonly home: string;
|
|
1121
|
-
/** Equal for the same Lambda or named function in the same Home Script. */
|
|
1122
|
-
readonly identity: string;
|
|
1123
|
-
readonly maySuspend: boolean;
|
|
1124
|
-
/** Where its code is, as its display form shows it: `12:3`, `tax`, `text:pad`. */
|
|
1125
|
-
readonly place: string;
|
|
930
|
+
declare const loadScript: (unit: CodeUnit, limits?: Partial<Limits>, libraries?: ReadonlyMap<string, Code>, initialVariables?: readonly Value[], home?: Script$1, identity?: string, functionGroup?: object) => Script$1;
|
|
931
|
+
type Iterator = {
|
|
932
|
+
at: number;
|
|
933
|
+
count: number;
|
|
934
|
+
k: 'iterator';
|
|
935
|
+
source: Value | null;
|
|
1126
936
|
};
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
readonly
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
937
|
+
type Replacement = {
|
|
938
|
+
at: number;
|
|
939
|
+
cs: readonly string[];
|
|
940
|
+
found: {
|
|
941
|
+
end: number;
|
|
942
|
+
start: number;
|
|
943
|
+
}[];
|
|
944
|
+
k: 'replacement';
|
|
945
|
+
matches: Value[];
|
|
946
|
+
pieces: string[];
|
|
947
|
+
subject: Value;
|
|
1133
948
|
};
|
|
949
|
+
type Item = Value | Iterator | Replacement | Reader | Receiver | Deadline;
|
|
1134
950
|
/**
|
|
1135
|
-
* A
|
|
1136
|
-
*
|
|
951
|
+
* A Timeout Block's mathematical microsecond deadline and its duration
|
|
952
|
+
* (ADR 0073). The count may lie outside the Clock's Instant range.
|
|
1137
953
|
*/
|
|
1138
|
-
type
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
954
|
+
type Deadline = {
|
|
955
|
+
after: Value;
|
|
956
|
+
at: bigint;
|
|
957
|
+
k: 'deadline';
|
|
1142
958
|
};
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
959
|
+
type Dispatch = {
|
|
960
|
+
args: Value[];
|
|
961
|
+
clauses: Body[];
|
|
962
|
+
code: Code;
|
|
963
|
+
/**
|
|
964
|
+
* A Delivery that may reach a Fallback Handler: its clauses, tried after
|
|
965
|
+
* `clauses` with the message map, and the message's Selector (ADR 0064).
|
|
966
|
+
*/
|
|
967
|
+
fallback?: {
|
|
968
|
+
clauses: Body[];
|
|
969
|
+
selector: string;
|
|
970
|
+
};
|
|
971
|
+
next: number;
|
|
1147
972
|
};
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
/** A Civil Date's fields; a date-only value has no time fields. */
|
|
1174
|
-
asCivilDate(): ReturnType<typeof civilFields> | undefined;
|
|
1175
|
-
/** The Abstract Machine's view of a Civil Date. */
|
|
1176
|
-
civilRef(): CivilRef | undefined;
|
|
1177
|
-
/** A copy of the bytes. */
|
|
1178
|
-
asBytes(): Uint8Array | undefined;
|
|
1179
|
-
/** The Abstract Machine's view of Bytes, which it never writes to. */
|
|
1180
|
-
bytesView(): Uint8Array | undefined;
|
|
1181
|
-
asRange(): {
|
|
1182
|
-
from: Value;
|
|
1183
|
-
to: Value;
|
|
1184
|
-
} | undefined;
|
|
1185
|
-
/** A Function Value's Home Script, its only Host-visible read. */
|
|
1186
|
-
homeScript(): string | undefined;
|
|
1187
|
-
/** A Text Pattern's canonical source, for display. */
|
|
1188
|
-
patternSource(): string | undefined;
|
|
1189
|
-
asPattern(): PatternRef | undefined;
|
|
1190
|
-
/** The Host Object handle this value stands for (chapter 9). */
|
|
1191
|
-
asObject(): HostObject | undefined;
|
|
1192
|
-
/** A Host Object's kind, id and handle. */
|
|
1193
|
-
asObjectRef(): ObjectRef | undefined;
|
|
1194
|
-
/** The Abstract Machine's view of a Function Value. */
|
|
1195
|
-
asFunction(): FunctionRef | undefined;
|
|
1196
|
-
get length(): number;
|
|
1197
|
-
index(i: number): Value;
|
|
1198
|
-
get(key: string): Value;
|
|
1199
|
-
/** Internal: the frozen pairs themselves, without copying. */
|
|
1200
|
-
mapPairs(): Pairs | undefined;
|
|
1201
|
-
get mapSize(): number;
|
|
1202
|
-
hasKey(key: string): boolean;
|
|
1203
|
-
entries(): [string, Value][];
|
|
1204
|
-
equals(other: Value): boolean;
|
|
1205
|
-
toString(): string;
|
|
1206
|
-
}
|
|
1207
|
-
declare const nothing: Value;
|
|
1208
|
-
declare const bool: (b: boolean) => Value;
|
|
1209
|
-
declare const text: (s: string) => Value;
|
|
1210
|
-
declare const dec: (s: string) => Value;
|
|
1211
|
-
/** ECMAScript's shortest round-trip digits, expanded without rounding. */
|
|
1212
|
-
declare const num: (n: number | bigint) => Value;
|
|
1213
|
-
declare const list: (...vs: Value[]) => Value;
|
|
1214
|
-
/** Two numbers, or two Quantities of one dimension, kept as given (ADR 0034). */
|
|
1215
|
-
declare const range: (from: Value, to: Value) => Value;
|
|
1216
|
-
/**
|
|
1217
|
-
* A Quantity of a number Value in a Unit spelled as a Script spells it, such
|
|
1218
|
-
* as `"kg"`. A Unit whose slots all drop, such as `"m/m"`, leaves the number.
|
|
1219
|
-
*/
|
|
1220
|
-
declare const quantity: (n: Value, unit: string) => Value;
|
|
1221
|
-
/** An Instant, from epoch microseconds; a JS Date is never accepted. */
|
|
1222
|
-
declare const instant: (epochMicros: bigint) => Value;
|
|
1223
|
-
type DateFields = Parameters<typeof civilFromFields>[0];
|
|
1224
|
-
/** A Civil Date, from its fields or from text in the `as civil date` form. */
|
|
1225
|
-
declare const civilDate: (f: DateFields | string) => Value;
|
|
1226
|
-
/** Bytes, copied in. */
|
|
1227
|
-
declare const bytes: (b: Uint8Array) => Value;
|
|
1228
|
-
declare const map: (input: Map<string, Value> | Iterable<[string, Value]>) => Value;
|
|
1229
|
-
declare const record: (input: Record<string, Value>) => Value;
|
|
1230
|
-
/**
|
|
1231
|
-
* Tooling's source form: the display form, with the substitutions that make it
|
|
1232
|
-
* source that reads back as an equal value with the same display form. Nothing
|
|
1233
|
-
* about it is normative (ADR 0028). An unreadable value keeps its display form.
|
|
1234
|
-
*/
|
|
1235
|
-
declare const sourceForm: (value: Value) => string;
|
|
1236
|
-
/** A value is readable when it contains no Function Value or Host Object. */
|
|
1237
|
-
declare const isReadable: (value: Value) => boolean;
|
|
1238
|
-
//#endregion
|
|
1239
|
-
//#region src/run-accounting.d.ts
|
|
1240
|
-
type RunAncestry = {
|
|
1241
|
-
parentCall?: string;
|
|
1242
|
-
parentRun?: string;
|
|
1243
|
-
rootDelivery: string;
|
|
1244
|
-
};
|
|
1245
|
-
type RunStarted = RunAncestry & {
|
|
1246
|
-
args: Value[];
|
|
1247
|
-
delivery?: string;
|
|
1248
|
-
fn?: Value;
|
|
1249
|
-
kind: 'run started';
|
|
1250
|
-
run: string;
|
|
1251
|
-
script: string;
|
|
1252
|
-
selector?: string;
|
|
1253
|
-
};
|
|
1254
|
-
type RunDiscarded = RunAncestry & {
|
|
1255
|
-
kind: 'run discarded';
|
|
1256
|
-
reason: string;
|
|
1257
|
-
run: string;
|
|
1258
|
-
script: string;
|
|
1259
|
-
};
|
|
1260
|
-
type RunAccounting = RunAncestry & {
|
|
1261
|
-
fuel: number;
|
|
1262
|
-
kind: 'run accounting';
|
|
1263
|
-
run: string;
|
|
1264
|
-
script: string;
|
|
1265
|
-
state: 'live' | 'terminal' | 'discarded';
|
|
1266
|
-
};
|
|
1267
|
-
type CausalWork = {
|
|
1268
|
-
discardedMessages: number;
|
|
1269
|
-
kind: 'causal work';
|
|
1270
|
-
liveRuns: number;
|
|
1271
|
-
queuedMessages: number;
|
|
1272
|
-
rootDelivery: string;
|
|
1273
|
-
};
|
|
1274
|
-
type AccountingReport = RunStarted | RunDiscarded | RunAccounting | CausalWork;
|
|
1275
|
-
//#endregion
|
|
1276
|
-
//#region src/binary.d.ts
|
|
1277
|
-
/** A reader: Bytes and the position of the next byte to read. */
|
|
1278
|
-
type Reader = {
|
|
1279
|
-
at: number;
|
|
1280
|
-
bytes: Uint8Array;
|
|
1281
|
-
k: 'reader';
|
|
1282
|
-
};
|
|
1283
|
-
//#endregion
|
|
1284
|
-
//#region src/operations.d.ts
|
|
1285
|
-
/** Behaviour this Core doesn't implement yet; never a Script error. */
|
|
1286
|
-
declare class NotImplementedError extends Error {
|
|
1287
|
-
name: string;
|
|
1288
|
-
}
|
|
1289
|
-
/** `wait d`'s duration in microseconds; anything but an exact duration is `wrong kind`. */
|
|
1290
|
-
declare const waitUs: (v: Value) => bigint;
|
|
1291
|
-
/** A verified static Unit target, owned by its loaded code unit. */
|
|
1292
|
-
type UnitConversion = {
|
|
1293
|
-
readonly to: string;
|
|
1294
|
-
readonly unit: UnitSpec;
|
|
1295
|
-
};
|
|
1296
|
-
declare const canConvert: (v: Value, kind: string, prepared?: UnitConversion) => Value;
|
|
1297
|
-
//#endregion
|
|
1298
|
-
//#region src/machine.d.ts
|
|
1299
|
-
type LimitName = 'fuelPerRun' | 'allocPerRun' | 'persistentState' | 'callDepth' | 'patternSize' | 'mailboxDepth' | 'maxWaitMs' | 'maxJoin' | 'cleanupBudget';
|
|
1300
|
-
type Limits = Record<LimitName, number>;
|
|
1301
|
-
declare const defaultLimits: Limits;
|
|
1302
|
-
/** A code unit that can't load: a literal pattern past its limit, or a failed initialiser. */
|
|
1303
|
-
declare class UnitLoadError extends Error {
|
|
1304
|
-
readonly code: 'pattern too large' | 'initialiser failed';
|
|
1305
|
-
readonly line: number;
|
|
1306
|
-
readonly col: number;
|
|
1307
|
-
readonly error: Value | null;
|
|
1308
|
-
constructor(code: 'pattern too large' | 'initialiser failed', line: number, col: number, error?: Value | null);
|
|
1309
|
-
}
|
|
1310
|
-
type Constant = {
|
|
1311
|
-
k: 'value';
|
|
1312
|
-
value: Value;
|
|
1313
|
-
} | {
|
|
1314
|
-
els: readonly PatternElement[];
|
|
1315
|
-
k: 'template';
|
|
1316
|
-
} | {
|
|
1317
|
-
k: 'unimplemented';
|
|
1318
|
-
what: string;
|
|
1319
|
-
};
|
|
1320
|
-
/**
|
|
1321
|
-
* A loaded code unit, a Script's or a Library's: its constants, definitions
|
|
1322
|
-
* and Handler clauses, linked to the Libraries its `use` lines name.
|
|
1323
|
-
*/
|
|
1324
|
-
declare class Code {
|
|
1325
|
-
readonly unit: CodeUnit;
|
|
1326
|
-
readonly identity: string;
|
|
1327
|
-
/** Static conversion metadata; rebuilt on Load, Reload and Restore. */
|
|
1328
|
-
readonly conversions: Map<Instruction, UnitConversion>;
|
|
1329
|
-
readonly constants: Constant[];
|
|
1330
|
-
readonly definitions: Value[];
|
|
1331
|
-
readonly clauses: Map<string, Body[]>;
|
|
1332
|
-
/**
|
|
1333
|
-
* Its Fallback Handler's clauses, in source order. They are kept apart
|
|
1334
|
-
* from `clauses`, so no Selector finds them (ADR 0064).
|
|
1335
|
-
*/
|
|
1336
|
-
fallback: Body[];
|
|
1337
|
-
/** The Libraries it imports, by name. */
|
|
1338
|
-
readonly libraries: Map<string, Code>;
|
|
1339
|
-
/** Whether it is a stdlib Library's, whose errors name the caller (ADR 0037). */
|
|
1340
|
-
stdlib: boolean;
|
|
1341
|
-
/**
|
|
1342
|
-
* Whether its errors name the caller, as a stdlib Library's do. A Host may
|
|
1343
|
-
* ask this of any Library, outside the Spec, as `northtalk test` does.
|
|
1344
|
-
*/
|
|
1345
|
-
atCaller: boolean;
|
|
1346
|
-
constructor(unit: CodeUnit, identity?: string);
|
|
1347
|
-
get name(): string;
|
|
1348
|
-
constant(i: number): Value;
|
|
1349
|
-
/** The Library that holds an import, written `library:name`. */
|
|
1350
|
-
library(name: string): {
|
|
1351
|
-
code: Code;
|
|
1352
|
-
name: string;
|
|
1353
|
-
};
|
|
1354
|
-
/** An exported function's body. */
|
|
1355
|
-
function(name: string): Body;
|
|
1356
|
-
/** Link the Libraries it imports, and take the Constants it imports from them. */
|
|
1357
|
-
link(libraries: ReadonlyMap<string, Code>, home?: Script$1): void;
|
|
1358
|
-
}
|
|
1359
|
-
/** A loaded Script: its code, and its Script Variables. */
|
|
1360
|
-
declare class Script$1 extends Code {
|
|
1361
|
-
readonly limits: Limits;
|
|
1362
|
-
readonly home?: Script$1 | undefined;
|
|
1363
|
-
variables: Value[];
|
|
1364
|
-
functionGroup?: object;
|
|
1365
|
-
readonly boundConstants: Map<Value, Value>;
|
|
1366
|
-
live: boolean;
|
|
1367
|
-
readonly units: Code[];
|
|
1368
|
-
variableNames: string[];
|
|
1369
|
-
constructor(unit: CodeUnit, limits?: Limits, home?: Script$1 | undefined, identity?: string);
|
|
1370
|
-
codeFor(body: Body): Code;
|
|
1371
|
-
attach(extension: Script$1): void;
|
|
1372
|
-
/** The Script Variables' share of Persistent State. */
|
|
1373
|
-
variablesSize(): number;
|
|
1374
|
-
}
|
|
1375
|
-
/**
|
|
1376
|
-
* Load a code unit: check each literal Text Pattern against the size limit,
|
|
1377
|
-
* then run the initialiser, which is never charged (chapter 8, Charging).
|
|
1378
|
-
*/
|
|
1379
|
-
declare const loadScript: (unit: CodeUnit, limits?: Partial<Limits>, libraries?: ReadonlyMap<string, Code>, initialVariables?: readonly Value[], home?: Script$1, identity?: string, functionGroup?: object) => Script$1;
|
|
1380
|
-
type Iterator = {
|
|
1381
|
-
at: number;
|
|
1382
|
-
count: number;
|
|
1383
|
-
k: 'iterator';
|
|
1384
|
-
source: Value | null;
|
|
1385
|
-
};
|
|
1386
|
-
type Replacement = {
|
|
1387
|
-
at: number;
|
|
1388
|
-
cs: readonly string[];
|
|
1389
|
-
found: {
|
|
1390
|
-
end: number;
|
|
1391
|
-
start: number;
|
|
1392
|
-
}[];
|
|
1393
|
-
k: 'replacement';
|
|
1394
|
-
matches: Value[];
|
|
1395
|
-
pieces: string[];
|
|
1396
|
-
subject: Value;
|
|
1397
|
-
};
|
|
1398
|
-
type Item = Value | Iterator | Replacement | Reader | Receiver | Deadline;
|
|
1399
|
-
/**
|
|
1400
|
-
* A Timeout Block's deadline, kept on the stack below its body: the Instant
|
|
1401
|
-
* in Clock microseconds, and the block's duration in `ms` (ADR 0073).
|
|
1402
|
-
*/
|
|
1403
|
-
type Deadline = {
|
|
1404
|
-
after: Value;
|
|
1405
|
-
at: bigint;
|
|
1406
|
-
k: 'deadline';
|
|
1407
|
-
};
|
|
1408
|
-
type Dispatch = {
|
|
1409
|
-
args: Value[];
|
|
1410
|
-
clauses: Body[];
|
|
1411
|
-
code: Code;
|
|
1412
|
-
/**
|
|
1413
|
-
* A Delivery that may reach a Fallback Handler: its clauses, tried after
|
|
1414
|
-
* `clauses` with the message map, and the message's Selector (ADR 0064).
|
|
1415
|
-
*/
|
|
1416
|
-
fallback?: {
|
|
1417
|
-
clauses: Body[];
|
|
1418
|
-
selector: string;
|
|
1419
|
-
};
|
|
1420
|
-
next: number;
|
|
1421
|
-
};
|
|
1422
|
-
type Frame = {
|
|
1423
|
-
activation?: boolean;
|
|
1424
|
-
body: Body;
|
|
1425
|
-
/** A clause's `clause` charge, added to its first instruction's. */
|
|
1426
|
-
clauseCharge: boolean;
|
|
1427
|
-
/** The code unit the body is in: the Script's own, or a Library's. */
|
|
1428
|
-
code: Code;
|
|
1429
|
-
dispatch: Dispatch | null;
|
|
1430
|
-
handler: string;
|
|
1431
|
-
locals: Value[];
|
|
1432
|
-
owner?: Frame;
|
|
1433
|
-
pc: number;
|
|
1434
|
-
/** Inherited by calls and retained recovery/cleanup activations. */
|
|
1435
|
-
restricted: boolean;
|
|
1436
|
-
stack: Item[];
|
|
1437
|
-
};
|
|
1438
|
-
/**
|
|
1439
|
-
* What happened in a Run that a Trace records: each raise, caught or not,
|
|
1440
|
-
* and each clause or branch a guard region skipped, with its error's code or
|
|
1441
|
-
* the value its Guard gave that wasn't a boolean.
|
|
1442
|
-
*/
|
|
1443
|
-
type RunRecord = {
|
|
1444
|
-
args: Value[];
|
|
1445
|
-
at: {
|
|
1446
|
-
pc: number;
|
|
973
|
+
type Frame = {
|
|
974
|
+
activation?: boolean;
|
|
975
|
+
body: Body;
|
|
976
|
+
/** A clause's `clause` charge, added to its first instruction's. */
|
|
977
|
+
clauseCharge: boolean;
|
|
978
|
+
/** The code unit the body is in: the Script's own, or a Library's. */
|
|
979
|
+
code: Code;
|
|
980
|
+
dispatch: Dispatch | null;
|
|
981
|
+
handler: string;
|
|
982
|
+
locals: Value[];
|
|
983
|
+
owner?: Frame;
|
|
984
|
+
pc: number;
|
|
985
|
+
/** Inherited by calls and retained recovery/cleanup activations. */
|
|
986
|
+
restricted: boolean;
|
|
987
|
+
stack: Item[];
|
|
988
|
+
};
|
|
989
|
+
/**
|
|
990
|
+
* What happened in a Run that a Trace records: each raise, caught or not,
|
|
991
|
+
* and each clause or branch a guard region skipped, with its error's code or
|
|
992
|
+
* the value its Guard gave that wasn't a boolean.
|
|
993
|
+
*/
|
|
994
|
+
type RunRecord = {
|
|
995
|
+
args: Value[];
|
|
996
|
+
at: {
|
|
997
|
+
pc: number;
|
|
1447
998
|
unit: string;
|
|
1448
999
|
};
|
|
1449
1000
|
attempt: number;
|
|
@@ -1536,7 +1087,7 @@ type CallContext = {
|
|
|
1536
1087
|
declared: number;
|
|
1537
1088
|
id: string;
|
|
1538
1089
|
named: [string, Value][];
|
|
1539
|
-
op:
|
|
1090
|
+
op: ValueOperation<unknown>;
|
|
1540
1091
|
/** As the Trace names it, `<granted name>.<operation>`. */
|
|
1541
1092
|
opName: string;
|
|
1542
1093
|
/** The rate the call is charged by. */
|
|
@@ -1605,6 +1156,11 @@ type Member = {
|
|
|
1605
1156
|
ms: number;
|
|
1606
1157
|
/** A Script reply received before its preempted Join closes. */
|
|
1607
1158
|
reply?: Resumption;
|
|
1159
|
+
/** The checked member instruction retains its destination and owning frame. */
|
|
1160
|
+
site: {
|
|
1161
|
+
frame: Frame;
|
|
1162
|
+
pc: number;
|
|
1163
|
+
};
|
|
1608
1164
|
};
|
|
1609
1165
|
/** What resumes a suspended Run. */
|
|
1610
1166
|
type Resumption = {
|
|
@@ -1667,15 +1223,28 @@ type RunHost = {
|
|
|
1667
1223
|
callValue(fn: Value, args: Value[], reply: string): string;
|
|
1668
1224
|
/** Land Stop and CancelRun after the crossing record, before conversion. */
|
|
1669
1225
|
crossing?(): boolean;
|
|
1226
|
+
/** The id of the Host Delivery that started the Run, if one did (ADR 0125). */
|
|
1227
|
+
readonly delivery?: string;
|
|
1670
1228
|
disableGrant(name: string): void;
|
|
1671
|
-
expose?(tree: unknown): void;
|
|
1672
1229
|
/**
|
|
1673
|
-
*
|
|
1674
|
-
*
|
|
1675
|
-
*/
|
|
1230
|
+
* The next `random(n)` draw from the Group's generator; `commit` advances
|
|
1231
|
+
* the generator past it (chapter 7, Random numbers).
|
|
1232
|
+
*/
|
|
1233
|
+
drawRandom(n: bigint): {
|
|
1234
|
+
commit(): void;
|
|
1235
|
+
value: bigint;
|
|
1236
|
+
};
|
|
1237
|
+
expose?(tree: unknown): void;
|
|
1238
|
+
/**
|
|
1239
|
+
* Queues its failure, as `fail`; null fails with what isn't a Script error,
|
|
1240
|
+
* which `detail` describes for the `call failed` report.
|
|
1241
|
+
*/
|
|
1676
1242
|
fail(id: string, error: ScriptError | null, detail?: string): void;
|
|
1677
1243
|
readonly grants: ReadonlyMap<string, Grant<unknown>>;
|
|
1244
|
+
/** The Group, as the Calls and Segment contexts the Run makes see it. */
|
|
1678
1245
|
readonly group: Group;
|
|
1246
|
+
/** Whether a Value refers only to objects of this Group. */
|
|
1247
|
+
holdsObject(v: Value): boolean;
|
|
1679
1248
|
isDisabled(name: string): boolean;
|
|
1680
1249
|
isRevoked?(name: string): boolean;
|
|
1681
1250
|
/** Whether a name is a Script of the Group. */
|
|
@@ -1769,17 +1338,9 @@ declare class Run {
|
|
|
1769
1338
|
private segment;
|
|
1770
1339
|
private scopes;
|
|
1771
1340
|
private participant;
|
|
1772
|
-
private
|
|
1773
|
-
effectStateUnknown: boolean;
|
|
1341
|
+
private get participantSite();
|
|
1774
1342
|
get hasParticipant(): boolean;
|
|
1775
|
-
|
|
1776
|
-
private get participantName();
|
|
1777
|
-
private enrolled;
|
|
1778
|
-
/** Whether a Segment-bound call through this Grant joins the participant. */
|
|
1779
|
-
private sharesParticipant;
|
|
1780
|
-
private lifecycle;
|
|
1781
|
-
private effectFailure;
|
|
1782
|
-
private rollbackParticipant;
|
|
1343
|
+
get effectStateUnknown(): boolean;
|
|
1783
1344
|
/** After charges/state checks, before any Segment outcome becomes visible. */
|
|
1784
1345
|
finalizeEffects(rollback?: boolean): void;
|
|
1785
1346
|
get hasOpenScopes(): boolean;
|
|
@@ -1844,7 +1405,7 @@ declare class Run {
|
|
|
1844
1405
|
/** Drop a new Run immediately after dispatch, without entering its body. */
|
|
1845
1406
|
drop(): void;
|
|
1846
1407
|
/** Roll back the active Segment and abandon every pending call without unwinding. */
|
|
1847
|
-
discard(betweenSegments?: boolean): string[];
|
|
1408
|
+
discard(reason: AbandonReason, betweenSegments?: boolean): string[];
|
|
1848
1409
|
/** Cancellation lands here; only finally copies are kept for the next turn. */
|
|
1849
1410
|
cancel(betweenSegments?: boolean): void;
|
|
1850
1411
|
/** Other Runs may have committed since cancellation made this Run ready. */
|
|
@@ -1894,6 +1455,14 @@ declare class Run {
|
|
|
1894
1455
|
private reader;
|
|
1895
1456
|
private peek;
|
|
1896
1457
|
step(clausePaid?: () => void): void;
|
|
1458
|
+
/**
|
|
1459
|
+
* Execute the simple instructions ahead, while they spend less than `room`
|
|
1460
|
+
* Fuel, without the general step's machinery. These instructions cannot
|
|
1461
|
+
* raise, fault, suspend or write a record; anything else, or a charge the
|
|
1462
|
+
* Run can't pay, is left for `step`, as is every Run with something due.
|
|
1463
|
+
* The Group calls this only when no tooling observes the steps.
|
|
1464
|
+
*/
|
|
1465
|
+
fastSteps(room: number): void;
|
|
1897
1466
|
/** Internal: also called after a debug-deferred unwind. */
|
|
1898
1467
|
finishInstruction(): void;
|
|
1899
1468
|
/** TS tooling: a resumption consumes the suspension instruction, not a new statement. */
|
|
@@ -1917,6 +1486,7 @@ declare class Run {
|
|
|
1917
1486
|
*/
|
|
1918
1487
|
private resume;
|
|
1919
1488
|
private settled;
|
|
1489
|
+
private memberTarget;
|
|
1920
1490
|
private withIndex;
|
|
1921
1491
|
/**
|
|
1922
1492
|
* Whether a message a `wait for` is waiting on fires one of its `when`
|
|
@@ -2016,51 +1586,827 @@ declare class Run {
|
|
|
2016
1586
|
private replace;
|
|
2017
1587
|
}
|
|
2018
1588
|
/**
|
|
2019
|
-
* Start a Run by dispatching a message to a Handler's clauses, and then, for
|
|
2020
|
-
* a message that may reach one, to the Script's Fallback Handler's (ADR 0064).
|
|
1589
|
+
* Start a Run by dispatching a message to a Handler's clauses, and then, for
|
|
1590
|
+
* a message that may reach one, to the Script's Fallback Handler's (ADR 0064).
|
|
1591
|
+
*/
|
|
1592
|
+
declare const deliver: (script: Script$1, message: string, args: Value[], limits?: Partial<Limits>, fallback?: boolean) => Run;
|
|
1593
|
+
/** Call a named function of the unit, as a Run on its own. */
|
|
1594
|
+
declare const callFunction: (script: Script$1, name: string, args: Value[]) => Run;
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region src/library.d.ts
|
|
1597
|
+
type OperationRef = {
|
|
1598
|
+
capability: string;
|
|
1599
|
+
operation: string;
|
|
1600
|
+
};
|
|
1601
|
+
type LibrarySource = {
|
|
1602
|
+
name: string;
|
|
1603
|
+
source: string;
|
|
1604
|
+
version: string;
|
|
1605
|
+
};
|
|
1606
|
+
/** A compiled Library, which any Group may add (chapter 9). */
|
|
1607
|
+
type Library = {
|
|
1608
|
+
/** 32 bytes. */
|
|
1609
|
+
readonly identity: Uint8Array;
|
|
1610
|
+
readonly imports: readonly Library[];
|
|
1611
|
+
readonly name: string;
|
|
1612
|
+
readonly needs: readonly OperationRef[];
|
|
1613
|
+
readonly source: string;
|
|
1614
|
+
readonly version: string;
|
|
1615
|
+
};
|
|
1616
|
+
/** A unit's code identity, given its direct imports' identities (chapter 9). */
|
|
1617
|
+
declare const codeIdentity: (unit: "script" | "library" | "extension", name: string, source: string, imports?: readonly string[]) => string;
|
|
1618
|
+
/** How a Host asks a Library to be compiled, outside the Spec. */
|
|
1619
|
+
type LibraryOptions = {
|
|
1620
|
+
/**
|
|
1621
|
+
* An error raised in it gets an `at` naming the call that entered it, as
|
|
1622
|
+
* for stdlib code (ADR 0037), rather than its own position.
|
|
1623
|
+
*/
|
|
1624
|
+
atCaller?: boolean;
|
|
1625
|
+
};
|
|
1626
|
+
/**
|
|
1627
|
+
* Compile a Library, once per process for each code identity. `imports` holds
|
|
1628
|
+
* every Library its `use` lines name, other than the stdlib's, which are
|
|
1629
|
+
* always there. Throws LoadError.
|
|
1630
|
+
*/
|
|
1631
|
+
declare const compileLibrary: (src: LibrarySource, imports?: readonly Library[], declarations?: GrantDecls, options?: LibraryOptions) => Library;
|
|
1632
|
+
/** Recompile the complete dependent Library graph without changing its registrations. */
|
|
1633
|
+
declare const replacementLibraries: (available: ReadonlyMap<string, Library>, replacement: Library) => Map<string, Library>;
|
|
1634
|
+
//#endregion
|
|
1635
|
+
//#region src/standard-capabilities.d.ts
|
|
1636
|
+
type Costs = Readonly<Record<string, Cost>>;
|
|
1637
|
+
type ConsoleImpl = {
|
|
1638
|
+
read(call: Call<unknown>): void;
|
|
1639
|
+
write(call: Call<unknown>, value: Value): void;
|
|
1640
|
+
};
|
|
1641
|
+
type TimerImpl = {
|
|
1642
|
+
cancel(call: Call<unknown>, name: string): void;
|
|
1643
|
+
schedule(call: Call<unknown>, name: string, at: Value, message: string, args: Value): void;
|
|
1644
|
+
};
|
|
1645
|
+
/** The Pump's Clock reading; there is no Host clock implementation. */
|
|
1646
|
+
declare const clockCapability: (costs: Costs) => CapabilityDef<void>;
|
|
1647
|
+
/** The Host owns durable timers, scoped by Script and name. */
|
|
1648
|
+
declare const timerCapability: (impl: TimerImpl, costs: Costs) => CapabilityDef<unknown>;
|
|
1649
|
+
/** The Host shows Values in text form and answers read with a line of text. */
|
|
1650
|
+
declare const consoleCapability: (impl: ConsoleImpl, costs: Costs) => CapabilityDef<unknown>;
|
|
1651
|
+
type CalendarImpl = {
|
|
1652
|
+
now(call: Call<string>, zone?: string): Value;
|
|
1653
|
+
offset(call: Call<string>, instant: Value, zone?: string): Value;
|
|
1654
|
+
toCivil(call: Call<string>, instant: Value, zone?: string): Value;
|
|
1655
|
+
today(call: Call<string>, zone?: string): Value;
|
|
1656
|
+
toInstant(call: Call<string>, civil: Value, disambiguation: string, zone?: string): Value;
|
|
1657
|
+
zone(call: Call<string>, zone?: string): Value;
|
|
1658
|
+
};
|
|
1659
|
+
/** The Host owns zone data; the Grant binding supplies its default zone. */
|
|
1660
|
+
declare const calendarCapability: (impl: CalendarImpl, costs: Costs) => CapabilityDef<string>;
|
|
1661
|
+
//#endregion
|
|
1662
|
+
//#region src/locale-capability.d.ts
|
|
1663
|
+
type LocaleImpl = {
|
|
1664
|
+
compare(call: Call<string>, a: Value, b: Value, opts: Value, tag?: string): Value;
|
|
1665
|
+
dayNames(call: Call<string>, opts: Value, tag?: string): Value;
|
|
1666
|
+
lower(call: Call<string>, s: Value, tag?: string): Value;
|
|
1667
|
+
monthNames(call: Call<string>, opts: Value, tag?: string): Value;
|
|
1668
|
+
numberSymbols(call: Call<string>, tag?: string): Value;
|
|
1669
|
+
rank(call: Call<string>, texts: Value, opts: Value, tag?: string): Value;
|
|
1670
|
+
tag(call: Call<string>, tag?: string): Value;
|
|
1671
|
+
upper(call: Call<string>, s: Value, tag?: string): Value;
|
|
1672
|
+
};
|
|
1673
|
+
/** The Host resolves tags and provides every Operation for each Locale. */
|
|
1674
|
+
declare const localeCapability: (impl: LocaleImpl, costs: Costs) => CapabilityDef<string>;
|
|
1675
|
+
//#endregion
|
|
1676
|
+
//#region src/sqlite-capability.d.ts
|
|
1677
|
+
/**
|
|
1678
|
+
* sqlite is optional (chapter 7, ADR 0070). The binding names a database the
|
|
1679
|
+
* Host keeps; tables, when present, limits the tables a Grant may use, and
|
|
1680
|
+
* maxRows caps the rows a call may give.
|
|
1681
|
+
*/
|
|
1682
|
+
type SqliteBinding = {
|
|
1683
|
+
readonly database: string;
|
|
1684
|
+
readonly maxRows: number;
|
|
1685
|
+
readonly tables?: readonly string[];
|
|
1686
|
+
};
|
|
1687
|
+
/** NULL, INTEGER, REAL, TEXT and BLOB. */
|
|
1688
|
+
type SqlValue = null | bigint | number | string | Uint8Array;
|
|
1689
|
+
/** A list binds `?` and `?NNN`; a Map binds `:name`, keyed without the colon. */
|
|
1690
|
+
type SqlParams = readonly SqlValue[] | ReadonlyMap<string, SqlValue>;
|
|
1691
|
+
type SqlRows = {
|
|
1692
|
+
readonly columns: readonly string[];
|
|
1693
|
+
readonly rows: readonly (readonly SqlValue[])[];
|
|
1694
|
+
};
|
|
1695
|
+
/**
|
|
1696
|
+
* The Core has checked the Shapes and max, converted params by the chapter 7
|
|
1697
|
+
* rules and charged max × perRow. It converts the result, raising `sql` for a
|
|
1698
|
+
* column named twice and `unrepresentable` for a double it can't hold.
|
|
1699
|
+
* change, begin, commit and rollback are Segment-bound: they act inside the
|
|
1700
|
+
* calling Segment's transaction, which the coordinator publishes or discards.
|
|
1701
|
+
* begin, commit and rollback open, release and roll back a savepoint. A failed
|
|
1702
|
+
* call leaves the database as it was. Throw ScriptError `sql` {reason},
|
|
1703
|
+
* `constraint` {kind}, `sqlite busy`, `not read-only`, `too many rows` {max},
|
|
1704
|
+
* or `unrepresentable` {column} for TEXT that isn't valid UTF-8 (chapter 9).
|
|
1705
|
+
*/
|
|
1706
|
+
type SqliteImpl = {
|
|
1707
|
+
begin(call: Call<SqliteBinding>): void;
|
|
1708
|
+
change(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows & {
|
|
1709
|
+
readonly changes: number;
|
|
1710
|
+
};
|
|
1711
|
+
commit(call: Call<SqliteBinding>): void;
|
|
1712
|
+
/** Called once per Grant. The same database gives the same coordinator. */
|
|
1713
|
+
coordinator(database: string): SegmentCoordinator;
|
|
1714
|
+
query(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows;
|
|
1715
|
+
rollback(call: Call<SqliteBinding>): void;
|
|
1716
|
+
};
|
|
1717
|
+
/** Optional for Hosts. perRow is whole Fuel charged per row of max. */
|
|
1718
|
+
declare const sqliteCapability: (impl: SqliteImpl, costs: Costs, perRow: number) => CapabilityDef<SqliteBinding>;
|
|
1719
|
+
//#endregion
|
|
1720
|
+
//#region src/store-capability.d.ts
|
|
1721
|
+
/**
|
|
1722
|
+
* The binding is the Store's name. `set`, `delete`, `increment` and `swap`
|
|
1723
|
+
* act on the calling Segment's pending writes, to every Store it writes,
|
|
1724
|
+
* which `commit` applies together and `rollback` discards (chapter 7,
|
|
1725
|
+
* ADR 0062). The implementation is the Segment Coordinator of every binding,
|
|
1726
|
+
* so its hooks see each enrolled Store's Grant (ADR 0069). Watch registrations
|
|
1727
|
+
* are final at the call, independent of the participant, and release drops
|
|
1728
|
+
* their owner when the named Grant stops being effective (ADR 0061).
|
|
1729
|
+
*/
|
|
1730
|
+
type StoreImpl = SegmentLifecycle<string> & {
|
|
1731
|
+
delete(call: Call<string>, key: string): void;
|
|
1732
|
+
get(call: Call<string>, key: string, fallback?: Value): Value;
|
|
1733
|
+
increment(call: Call<string>, key: string, by?: Value): Value;
|
|
1734
|
+
keys(call: Call<string>, prefix?: string): Value;
|
|
1735
|
+
release(context: GrantContext<string>): void;
|
|
1736
|
+
set(call: Call<string>, key: string, value: Value): void;
|
|
1737
|
+
swap(call: Call<string>, key: string, expected: Value, replacement: Value): boolean;
|
|
1738
|
+
unwatch(call: Call<string>, name: string): void;
|
|
1739
|
+
watch(call: Call<string>, name: string, prefix: string, message: string): void;
|
|
1740
|
+
};
|
|
1741
|
+
/** The `+` rules outside any Run, uncharged (chapter 9, Adding). */
|
|
1742
|
+
declare const add: (a: Value, b: Value) => Value;
|
|
1743
|
+
/** The Store is the Host's; the Grant binding names it, and `impl` coordinates every binding. */
|
|
1744
|
+
declare const storeCapability: (impl: StoreImpl, costs: Costs) => CapabilityDef<string>;
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region src/user-capability.d.ts
|
|
1747
|
+
/** An omitted prompt, default or title is "". */
|
|
1748
|
+
type UserImpl = {
|
|
1749
|
+
choose(call: Call<unknown>, items: readonly string[], prompt: string, multiple: boolean): void;
|
|
1750
|
+
confirm(call: Call<unknown>, message: string): void;
|
|
1751
|
+
enter(call: Call<unknown>, message: string, fallback: string): void;
|
|
1752
|
+
notify(call: Call<unknown>, message: string, title: string): void;
|
|
1753
|
+
};
|
|
1754
|
+
/** Optional for Hosts. The binding is ignored. */
|
|
1755
|
+
declare const userCapability: (impl: UserImpl, costs: Costs) => CapabilityDef<unknown>;
|
|
1756
|
+
//#endregion
|
|
1757
|
+
//#region src/http-capability.d.ts
|
|
1758
|
+
/**
|
|
1759
|
+
* `serve` hears its effective message, `httpRequest` when omitted or
|
|
1760
|
+
* Nothing, and its options as a map, empty when omitted or Nothing, and
|
|
1761
|
+
* answers through the Call with `{host, port}`. `respond` hears the response
|
|
1762
|
+
* map as the Script gave it, except that a `json` value is replaced by its
|
|
1763
|
+
* compact JSON text, written by the `json` Library's rules.
|
|
1764
|
+
*/
|
|
1765
|
+
type HttpImpl = {
|
|
1766
|
+
respond(call: Call<unknown>, exchange: HostObject, response: Value): void;
|
|
1767
|
+
serve(call: Call<unknown>, name: string, prefix: string, message: string, options: Value): void;
|
|
1768
|
+
unserve(call: Call<unknown>, name: string): void;
|
|
1769
|
+
};
|
|
1770
|
+
/** Optional for Hosts. The binding is the Host's own description of the addresses a Grant may listen on. */
|
|
1771
|
+
declare const httpCapability: (impl: HttpImpl, costs: Costs) => CapabilityDef<unknown>;
|
|
1772
|
+
//#endregion
|
|
1773
|
+
//#region src/versions.d.ts
|
|
1774
|
+
type Versions = {
|
|
1775
|
+
core: string;
|
|
1776
|
+
costModel: string;
|
|
1777
|
+
language: string;
|
|
1778
|
+
saveFormat: string;
|
|
1779
|
+
unicode: string;
|
|
1780
|
+
};
|
|
1781
|
+
declare const coreVersions: Versions;
|
|
1782
|
+
//#endregion
|
|
1783
|
+
//#region src/embedding.d.ts
|
|
1784
|
+
/**
|
|
1785
|
+
* Process-wide: the compile cache, and Capability and Object Kind definitions.
|
|
1786
|
+
* `createCore` is each entry point's own: synchronous on the TS Core,
|
|
1787
|
+
* asynchronous on the Zig Host Adapter.
|
|
1788
|
+
*/
|
|
1789
|
+
type Core = {
|
|
1790
|
+
calendarCapability: typeof calendarCapability;
|
|
1791
|
+
clockCapability: typeof clockCapability;
|
|
1792
|
+
/** Throws LoadError. `imports` holds every Library its `use` lines name. */
|
|
1793
|
+
compileLibrary(src: LibrarySource, imports?: Library[], declarations?: GrantDecls): Library;
|
|
1794
|
+
consoleCapability: typeof consoleCapability;
|
|
1795
|
+
defineCapability: typeof defineCapability;
|
|
1796
|
+
defineObjectKind<N>(k: ObjectKindDef<N>): ObjectKind<N>;
|
|
1797
|
+
httpCapability: typeof httpCapability;
|
|
1798
|
+
localeCapability: typeof localeCapability;
|
|
1799
|
+
newGroup(o: GroupOptions): Group;
|
|
1800
|
+
restore(save: Uint8Array, o: RestoreOptions): {
|
|
1801
|
+
group: Group;
|
|
1802
|
+
result: RestoreResult;
|
|
1803
|
+
};
|
|
1804
|
+
sqliteCapability: typeof sqliteCapability;
|
|
1805
|
+
storeCapability: typeof storeCapability;
|
|
1806
|
+
timerCapability: typeof timerCapability;
|
|
1807
|
+
userCapability: typeof userCapability;
|
|
1808
|
+
readonly versions: Versions;
|
|
1809
|
+
};
|
|
1810
|
+
/**
|
|
1811
|
+
* A Script Group. The TS Core's Group adds `save(options)` and the debugger
|
|
1812
|
+
* hooks; the Zig Host Adapter's adds `memoryBytes()`, `rebind()` and `restore()`.
|
|
1813
|
+
*/
|
|
1814
|
+
type Group = {
|
|
1815
|
+
addLibrary(l: Library): void;
|
|
1816
|
+
broadcast(m: Message): string;
|
|
1817
|
+
call(fn: Value, args: Value[], o?: CancellationOptions & {
|
|
1818
|
+
limits?: LimitOverride;
|
|
1819
|
+
}): Requested;
|
|
1820
|
+
callPump(fn: Value, args: Value[], now: bigint, o?: PumpOptions & CancellationOptions & {
|
|
1821
|
+
limits?: LimitOverride;
|
|
1822
|
+
}): PumpedRequest;
|
|
1823
|
+
decide(to: HostObject, m: Message, o?: CancellationOptions): Deciding;
|
|
1824
|
+
decideBroadcast(m: Message, o?: CancellationOptions): Deciding;
|
|
1825
|
+
deliver(to: HostObject, m: Message): string;
|
|
1826
|
+
dispose(o: HostObject): void;
|
|
1827
|
+
fingerprint(): Uint8Array;
|
|
1828
|
+
inspect(): Inspection;
|
|
1829
|
+
load(o: LoadOptions): Script;
|
|
1830
|
+
readonly name: string;
|
|
1831
|
+
object<N>(kind: ObjectKind<N>, id: string, native: N): HostObject<N>;
|
|
1832
|
+
objectById(kind: string, id: string): HostObject | undefined;
|
|
1833
|
+
pump(now: bigint, o?: PumpOptions): PumpResult;
|
|
1834
|
+
replaceLibrary(l: Library, carry: CarryOver): Report[];
|
|
1835
|
+
request(to: HostObject, m: Message, o?: CancellationOptions): Requested;
|
|
1836
|
+
requestPump(to: HostObject, m: Message, now: bigint, o?: PumpOptions & CancellationOptions): PumpedRequest;
|
|
1837
|
+
save(): Uint8Array;
|
|
1838
|
+
script(name: string): Script | undefined;
|
|
1839
|
+
scriptNames(): string[];
|
|
1840
|
+
setParent(o: HostObject, parent: HostObject | undefined): void;
|
|
1841
|
+
settle(callId: string, s: Settlement): Call<unknown> | undefined;
|
|
1842
|
+
};
|
|
1843
|
+
/** A loaded Script's handle. */
|
|
1844
|
+
type Script = {
|
|
1845
|
+
cancelRun(runId: string): void;
|
|
1846
|
+
counters(): Counters;
|
|
1847
|
+
decide(m: Message, o?: CancellationOptions): Deciding;
|
|
1848
|
+
deliver(m: Message): string;
|
|
1849
|
+
extend(source: string): void;
|
|
1850
|
+
grants(): Record<string, string[]>;
|
|
1851
|
+
invoke(name: string, ...args: Value[]): Promise<Value>;
|
|
1852
|
+
readonly name: string;
|
|
1853
|
+
reload(source: string, carry: CarryOver, o?: {
|
|
1854
|
+
keepMailbox?: boolean;
|
|
1855
|
+
}): Report[];
|
|
1856
|
+
request(m: Message, o?: CancellationOptions): Requested;
|
|
1857
|
+
requestPump(m: Message, now: bigint, o?: PumpOptions & CancellationOptions): PumpedRequest;
|
|
1858
|
+
revoke(grantName: string): void;
|
|
1859
|
+
rewindRun(runId: string): void;
|
|
1860
|
+
stop(reason: string): void;
|
|
1861
|
+
};
|
|
1862
|
+
//#endregion
|
|
1863
|
+
//#region src/capabilities.d.ts
|
|
1864
|
+
declare const plainForm: unique symbol;
|
|
1865
|
+
/**
|
|
1866
|
+
* A Shape, carrying the JS type a typed Host function receives for it
|
|
1867
|
+
* (#1420). The type is compile-time only.
|
|
1868
|
+
*/
|
|
1869
|
+
type Shape<T = unknown> = ShapeNode & {
|
|
1870
|
+
readonly [plainForm]?: T;
|
|
1871
|
+
};
|
|
1872
|
+
type ShapeNode = {
|
|
1873
|
+
k: 'any';
|
|
1874
|
+
} | {
|
|
1875
|
+
k: 'value';
|
|
1876
|
+
} | {
|
|
1877
|
+
k: 'kind';
|
|
1878
|
+
kind: string;
|
|
1879
|
+
} | {
|
|
1880
|
+
k: 'object';
|
|
1881
|
+
kind: string;
|
|
1882
|
+
} | {
|
|
1883
|
+
k: 'quantity';
|
|
1884
|
+
unit: string;
|
|
1885
|
+
} | {
|
|
1886
|
+
k: 'unitKind';
|
|
1887
|
+
kind: string;
|
|
1888
|
+
} | {
|
|
1889
|
+
k: 'list';
|
|
1890
|
+
of: Shape;
|
|
1891
|
+
} | {
|
|
1892
|
+
fields: readonly {
|
|
1893
|
+
key: string;
|
|
1894
|
+
optional: boolean;
|
|
1895
|
+
shape: Shape;
|
|
1896
|
+
}[];
|
|
1897
|
+
k: 'map';
|
|
1898
|
+
open: boolean;
|
|
1899
|
+
} | {
|
|
1900
|
+
k: 'oneOf';
|
|
1901
|
+
of: readonly Shape[];
|
|
1902
|
+
} | {
|
|
1903
|
+
k: 'optional';
|
|
1904
|
+
of: Shape;
|
|
1905
|
+
};
|
|
1906
|
+
type FieldShape = Shape | {
|
|
1907
|
+
optional: true;
|
|
1908
|
+
shape: Shape;
|
|
1909
|
+
};
|
|
1910
|
+
/** The Shape constructors of `talk.ts`. */
|
|
1911
|
+
declare const shape: {
|
|
1912
|
+
any: Shape<Value>;
|
|
1913
|
+
value: Shape<Value>;
|
|
1914
|
+
nothing: Shape<null>;
|
|
1915
|
+
bool: Shape<boolean>;
|
|
1916
|
+
number: Shape<Decimal>;
|
|
1917
|
+
text: Shape<string>;
|
|
1918
|
+
bytes: Shape<Uint8Array>;
|
|
1919
|
+
instant: Shape<bigint>;
|
|
1920
|
+
civilDate: Shape<Value>;
|
|
1921
|
+
range: Shape<Value>;
|
|
1922
|
+
pattern: Shape<Value>;
|
|
1923
|
+
function: Shape<Value>;
|
|
1924
|
+
object: <N>(kind: ObjectKind<N>) => Shape<HostObject<N>>;
|
|
1925
|
+
quantityOf: (unit: string) => Shape<Value>;
|
|
1926
|
+
quantityKind: (unitKind: string) => Shape<Value>;
|
|
1927
|
+
listOf: (of: Shape) => Shape<Value>;
|
|
1928
|
+
map: (fields: Record<string, FieldShape>) => Shape<Value>;
|
|
1929
|
+
openMap: (fields: Record<string, FieldShape>) => Shape<Value>;
|
|
1930
|
+
oneOf: (...of: Shape[]) => Shape<Value>;
|
|
1931
|
+
/** Supplied Nothing is null; an omitted trailing argument is undefined. */
|
|
1932
|
+
optional: <T>(of: Shape<T>) => Shape<T | null | undefined>;
|
|
1933
|
+
};
|
|
1934
|
+
type ScopeDecl = {
|
|
1935
|
+
abandon: string;
|
|
1936
|
+
opens: string;
|
|
1937
|
+
} | {
|
|
1938
|
+
closes: string;
|
|
1939
|
+
};
|
|
1940
|
+
/** Synchronous, unmetered participant lifecycle work. */
|
|
1941
|
+
type SegmentContext<B> = {
|
|
1942
|
+
readonly binding: B;
|
|
1943
|
+
/** The first enrolled Grant. */
|
|
1944
|
+
readonly grantName: string;
|
|
1945
|
+
/** Enrolled, in enrollment order; `begin` sees only the first. */
|
|
1946
|
+
readonly grants: readonly SegmentGrant<B>[];
|
|
1947
|
+
readonly group: Group;
|
|
1948
|
+
readonly now: bigint;
|
|
1949
|
+
readonly runId: string;
|
|
1950
|
+
readonly scriptName: string;
|
|
1951
|
+
readonly segmentId: string;
|
|
1952
|
+
};
|
|
1953
|
+
type SegmentGrant<B> = {
|
|
1954
|
+
readonly binding: B;
|
|
1955
|
+
readonly grantName: string;
|
|
1956
|
+
};
|
|
1957
|
+
type EffectResult = {
|
|
1958
|
+
detail?: string;
|
|
1959
|
+
status: 'ok' | 'failed' | 'unknown';
|
|
1960
|
+
};
|
|
1961
|
+
type SegmentLifecycle<B> = {
|
|
1962
|
+
begin(context: SegmentContext<B>): EffectResult;
|
|
1963
|
+
commit(context: SegmentContext<B>): EffectResult;
|
|
1964
|
+
rollback(context: SegmentContext<B>): EffectResult;
|
|
1965
|
+
};
|
|
1966
|
+
/** Compared by identity: Grants mapped to one coordinator share a Segment's participant (ADR 0069). */
|
|
1967
|
+
type SegmentCoordinator = SegmentLifecycle<unknown>;
|
|
1968
|
+
/** Maps each binding to its coordinator once, when a Grant is created. */
|
|
1969
|
+
type CoordinatedLifecycle<B> = {
|
|
1970
|
+
coordinator(binding: B): SegmentCoordinator;
|
|
1971
|
+
};
|
|
1972
|
+
type Cost = {
|
|
1973
|
+
alloc?: number;
|
|
1974
|
+
fuel: number;
|
|
1975
|
+
};
|
|
1976
|
+
type ErrorDecl = {
|
|
1977
|
+
code: string;
|
|
1978
|
+
fields?: Record<string, FieldShape>;
|
|
1979
|
+
};
|
|
1980
|
+
type OpBase<A extends readonly Shape[] = Shape[], R = Shape> = {
|
|
1981
|
+
args?: A;
|
|
1982
|
+
/** Also callable as a Host Command, by its name alone (ADR 0094). */
|
|
1983
|
+
command?: boolean;
|
|
1984
|
+
cost: Cost;
|
|
1985
|
+
/** Plain-text documentation, carried only by the Host Manifest. */
|
|
1986
|
+
description?: string;
|
|
1987
|
+
errors?: ErrorDecl[];
|
|
1988
|
+
examples?: string[];
|
|
1989
|
+
/**
|
|
1990
|
+
* Argument Labels, one per argument after the first, that a call may write
|
|
1991
|
+
* between its arguments; checked at load only (ADR 0115). Empty is absent.
|
|
1992
|
+
*/
|
|
1993
|
+
labels?: string[];
|
|
1994
|
+
result?: R;
|
|
1995
|
+
};
|
|
1996
|
+
/** What the Core gives a Host function at each call (chapter 9, The call). */
|
|
1997
|
+
type Call<B, R = Value> = {
|
|
1998
|
+
/** Queued, for a suspending call; ignored once the call isn't pending. */
|
|
1999
|
+
answer(v: R, lateCost?: {
|
|
2000
|
+
fuel: number;
|
|
2001
|
+
}): void;
|
|
2002
|
+
readonly automatic: boolean;
|
|
2003
|
+
readonly binding: B;
|
|
2004
|
+
/** Draws more Fuel, before the work. Throws LimitReached. */
|
|
2005
|
+
charge(fuel: number): void;
|
|
2006
|
+
/** The Host Delivery that started the calling Run; absent when none did (ADR 0125). */
|
|
2007
|
+
readonly delivery?: string;
|
|
2008
|
+
fail(e: ScriptError): void;
|
|
2009
|
+
readonly grantName: string;
|
|
2010
|
+
readonly group: Group;
|
|
2011
|
+
readonly id: string;
|
|
2012
|
+
readonly now: bigint;
|
|
2013
|
+
readonly runId: string;
|
|
2014
|
+
readonly scopeName?: string;
|
|
2015
|
+
readonly scriptName: string;
|
|
2016
|
+
readonly segmentId: string;
|
|
2017
|
+
readonly signal: AbortSignal;
|
|
2018
|
+
};
|
|
2019
|
+
/**
|
|
2020
|
+
* The JS type a Host function receives for an argument of Shape S (#1420):
|
|
2021
|
+
* scalars as their JS forms, Nothing as null, a Host Object as its handle,
|
|
2022
|
+
* and every other Shape as the Value. A Shape whose type was lost is unknown.
|
|
2023
|
+
*/
|
|
2024
|
+
type PlainArg<S> = S extends Shape<infer T> ? (unknown extends T ? unknown : T) : unknown;
|
|
2025
|
+
/** What a Host function may return for a result of Shape R: its JS form, a bigint for a number, or any Value. */
|
|
2026
|
+
type PlainResult<R> = [R] extends [undefined] ? Value : (R extends Shape<infer T> ? unknown extends T ? unknown : T extends Decimal ? Decimal | bigint : T : unknown) | Value;
|
|
2027
|
+
type PlainArgs<A extends readonly Shape[]> = { -readonly [K in keyof A]: PlainArg<A[K]>; };
|
|
2028
|
+
type ImmediateOp<B, A extends readonly Shape[] = Shape[], R = Shape> = OpBase<A, R> & {
|
|
2029
|
+
do(call: Call<B, PlainResult<R>>, ...args: PlainArgs<A>): PlainResult<R>;
|
|
2030
|
+
mode: 'immediate';
|
|
2031
|
+
scope?: ScopeDecl;
|
|
2032
|
+
segmentBound?: boolean;
|
|
2033
|
+
};
|
|
2034
|
+
type SuspendingOp<B, A extends readonly Shape[] = Shape[], R = Shape> = OpBase<A, R> & {
|
|
2035
|
+
maxPendingMs?: number;
|
|
2036
|
+
mode: 'suspending';
|
|
2037
|
+
run?(call: Call<B, PlainResult<R>>, ...args: PlainArgs<A>): Promise<PlainResult<R>>;
|
|
2038
|
+
start?(call: Call<B, PlainResult<R>>, ...args: PlainArgs<A>): void;
|
|
2039
|
+
};
|
|
2040
|
+
type FireOp<B, A extends readonly Shape[] = Shape[], R = Shape> = OpBase<A, R> & {
|
|
2041
|
+
fire(call: Call<B, PlainResult<R>>, ...args: PlainArgs<A>): void;
|
|
2042
|
+
mode: 'fire-and-forget';
|
|
2043
|
+
};
|
|
2044
|
+
/** An Operation whose Host function takes the JS forms of its Shapes (#1420). */
|
|
2045
|
+
type Operation<B, A extends readonly Shape[] = Shape[], R = Shape> = ImmediateOp<B, A, R> | SuspendingOp<B, A, R> | FireOp<B, A, R>;
|
|
2046
|
+
/** The Core's own form: every argument and result is a Value. */
|
|
2047
|
+
type ValueImmediateOp<B> = OpBase & {
|
|
2048
|
+
do(call: Call<B>, ...args: Value[]): Value;
|
|
2049
|
+
mode: 'immediate';
|
|
2050
|
+
scope?: ScopeDecl;
|
|
2051
|
+
segmentBound?: boolean;
|
|
2052
|
+
};
|
|
2053
|
+
type ValueSuspendingOp<B> = OpBase & {
|
|
2054
|
+
maxPendingMs?: number;
|
|
2055
|
+
mode: 'suspending';
|
|
2056
|
+
run?(call: Call<B>, ...args: Value[]): Promise<Value>;
|
|
2057
|
+
start?(call: Call<B>, ...args: Value[]): void;
|
|
2058
|
+
};
|
|
2059
|
+
type ValueFireOp<B> = OpBase & {
|
|
2060
|
+
fire(call: Call<B>, ...args: Value[]): void;
|
|
2061
|
+
mode: 'fire-and-forget';
|
|
2062
|
+
};
|
|
2063
|
+
type ValueOperation<B> = ValueImmediateOp<B> | ValueSuspendingOp<B> | ValueFireOp<B>;
|
|
2064
|
+
type OpDecl = {
|
|
2065
|
+
args?: readonly Shape[];
|
|
2066
|
+
mode: Operation<unknown>['mode'];
|
|
2067
|
+
result?: Shape;
|
|
2068
|
+
};
|
|
2069
|
+
type ArgsOf<D> = D extends {
|
|
2070
|
+
args: infer A extends readonly Shape[];
|
|
2071
|
+
} ? A : D extends {
|
|
2072
|
+
args?: infer A extends readonly Shape[];
|
|
2073
|
+
} ? A : [];
|
|
2074
|
+
type ResultOf<D> = D extends {
|
|
2075
|
+
result: infer R;
|
|
2076
|
+
} ? R : D extends {
|
|
2077
|
+
result?: infer R;
|
|
2078
|
+
} ? R : undefined;
|
|
2079
|
+
type ByMode<B, D> = D extends {
|
|
2080
|
+
mode: 'immediate';
|
|
2081
|
+
} ? ImmediateOp<B, ArgsOf<D>, ResultOf<D>> : D extends {
|
|
2082
|
+
mode: 'suspending';
|
|
2083
|
+
} ? SuspendingOp<B, ArgsOf<D>, ResultOf<D>> : FireOp<B, ArgsOf<D>, ResultOf<D>>;
|
|
2084
|
+
/**
|
|
2085
|
+
* Each Operation typed from its own `args` and `result`: the Pick lets
|
|
2086
|
+
* TypeScript infer them from the literal before it types the callbacks.
|
|
2087
|
+
*/
|
|
2088
|
+
type Operations<B, O> = { [K in keyof O]: Pick<O[K], keyof OpDecl & keyof O[K]> & ByMode<B, O[K]>; };
|
|
2089
|
+
/** Thrown by `call.charge` when the Run's Fuel can't cover it. */
|
|
2090
|
+
declare class LimitReached extends Error {
|
|
2091
|
+
name: string;
|
|
2092
|
+
}
|
|
2093
|
+
type ReleaseReason = 'stop' | 'reload' | 'revoke' | 'disable';
|
|
2094
|
+
/** One loaded Script's named Grant, identified within its Group. */
|
|
2095
|
+
type GrantContext<B> = {
|
|
2096
|
+
readonly binding: B;
|
|
2097
|
+
readonly grantName: string;
|
|
2098
|
+
readonly group: Group;
|
|
2099
|
+
readonly now: bigint;
|
|
2100
|
+
readonly reason: ReleaseReason;
|
|
2101
|
+
readonly scriptName: string;
|
|
2102
|
+
};
|
|
2103
|
+
/** Synchronous, unmetered cleanup. Exceptions cannot refuse release. */
|
|
2104
|
+
type ReleaseHook<B> = (context: GrantContext<B>) => void;
|
|
2105
|
+
type CapabilityDef<B> = {
|
|
2106
|
+
/** Maps a Grant's binding to its Segment Coordinator. */
|
|
2107
|
+
coordinator?(binding: B): SegmentCoordinator;
|
|
2108
|
+
/** A reusable template. Each load binds it to one Script. */
|
|
2109
|
+
grant(ops: readonly string[] | 'all', binding: B): Grant<B>;
|
|
2110
|
+
/** A plain lifecycle, making each Grant its own coordinator. */
|
|
2111
|
+
readonly lifecycle?: SegmentLifecycle<B>;
|
|
2112
|
+
readonly name: string;
|
|
2113
|
+
/** Its Operations, ordered by name. */
|
|
2114
|
+
readonly operations: ReadonlyMap<string, ValueOperation<B>>;
|
|
2115
|
+
release?(context: GrantContext<B>): void;
|
|
2116
|
+
};
|
|
2117
|
+
type Grant<B> = {
|
|
2118
|
+
readonly binding: B;
|
|
2119
|
+
readonly capability: CapabilityDef<B>;
|
|
2120
|
+
/** Resolved at Grant creation; absent when the Grant is its own coordinator. */
|
|
2121
|
+
readonly coordinator?: SegmentCoordinator;
|
|
2122
|
+
readonly ops: ReadonlySet<string>;
|
|
2123
|
+
};
|
|
2124
|
+
type CapabilityDefiner<B> = <const O extends Record<string, OpDecl>>(name: string, ops: Operations<B, O>, lifecycle?: SegmentLifecycle<B> | CoordinatedLifecycle<B>, release?: ReleaseHook<B>) => CapabilityDef<B>;
|
|
2125
|
+
/**
|
|
2126
|
+
* Define a Capability, once per process (chapter 9, Capabilities). Each Host
|
|
2127
|
+
* function takes the JS forms of its argument Shapes and may return its
|
|
2128
|
+
* result's JS form (#1420). With a binding, name its type by currying:
|
|
2129
|
+
* `defineCapability<Db>()(name, ops)`.
|
|
2130
|
+
*/
|
|
2131
|
+
declare function defineCapability<const O extends Record<string, OpDecl>>(name: string, ops: Operations<void, O>, lifecycle?: SegmentLifecycle<void> | CoordinatedLifecycle<void>, release?: ReleaseHook<void>): CapabilityDef<void>;
|
|
2132
|
+
declare function defineCapability<B>(): CapabilityDefiner<B>;
|
|
2133
|
+
//#endregion
|
|
2134
|
+
//#region src/effects.d.ts
|
|
2135
|
+
type OperationMode = 'immediate' | 'suspending' | 'fire-and-forget';
|
|
2136
|
+
/** Each Grant's Operations, by the name the Script uses. */
|
|
2137
|
+
type GrantDecls = Readonly<Record<string, Readonly<Record<string, {
|
|
2138
|
+
args: readonly Shape[];
|
|
2139
|
+
command?: boolean;
|
|
2140
|
+
labels?: readonly string[];
|
|
2141
|
+
mode: OperationMode;
|
|
2142
|
+
}>>>>;
|
|
2143
|
+
//#endregion
|
|
2144
|
+
//#region src/objects.d.ts
|
|
2145
|
+
type PropDef<N> = {
|
|
2146
|
+
get(o: HostObject<N>): Value;
|
|
2147
|
+
getCost?: Cost;
|
|
2148
|
+
/** Omit for read-only. Throw ScriptError to refuse. */
|
|
2149
|
+
set?(o: HostObject<N>, v: Value): void;
|
|
2150
|
+
setCost?: Cost;
|
|
2151
|
+
shape?: Shape;
|
|
2152
|
+
};
|
|
2153
|
+
/**
|
|
2154
|
+
* An Object Kind's ordered, named collection of Host Objects (#1143). Its
|
|
2155
|
+
* callbacks are synchronous and read-only, like a property's `get`; `at`
|
|
2156
|
+
* gets a nonzero index, negative from the end.
|
|
2157
|
+
*/
|
|
2158
|
+
type ObjectElements<N> = {
|
|
2159
|
+
at(o: HostObject<N>, index: number): Value;
|
|
2160
|
+
atCost: Cost;
|
|
2161
|
+
count(o: HostObject<N>): Value;
|
|
2162
|
+
countCost: Cost;
|
|
2163
|
+
find(o: HostObject<N>, name: string): Value;
|
|
2164
|
+
findCost: Cost;
|
|
2165
|
+
shape: Shape;
|
|
2166
|
+
};
|
|
2167
|
+
type ObjectKindDef<N> = {
|
|
2168
|
+
/** Omit for a kind with no collection. */
|
|
2169
|
+
elements?: ObjectElements<N>;
|
|
2170
|
+
name: string;
|
|
2171
|
+
/** For the Host Manifest only; `setParent` doesn't check it. */
|
|
2172
|
+
parentKinds?: string[];
|
|
2173
|
+
props: Record<string, PropDef<N>>;
|
|
2174
|
+
};
|
|
2175
|
+
type ObjectKind<N = unknown> = {
|
|
2176
|
+
readonly elements: Readonly<ObjectElements<N>> | null;
|
|
2177
|
+
readonly name: string;
|
|
2178
|
+
readonly parentKinds: readonly string[];
|
|
2179
|
+
readonly props: ReadonlyMap<string, PropDef<N>>;
|
|
2180
|
+
};
|
|
2181
|
+
/** Define an Object Kind, once per process. */
|
|
2182
|
+
declare const defineObjectKind: <N>(k: ObjectKindDef<N>) => ObjectKind<N>;
|
|
2183
|
+
/** A Group-scoped handle to something the Host owns. */
|
|
2184
|
+
type HostObject<N = unknown> = {
|
|
2185
|
+
readonly id: string;
|
|
2186
|
+
readonly kind: ObjectKind<N>;
|
|
2187
|
+
readonly native: N;
|
|
2188
|
+
readonly value: Value;
|
|
2189
|
+
};
|
|
2190
|
+
/** What the Group holds for each of its objects (chapter 9, Host Objects). */
|
|
2191
|
+
type ObjectState = {
|
|
2192
|
+
disposed: boolean;
|
|
2193
|
+
handle: HostObject;
|
|
2194
|
+
/** The Script that owns it, by name. */
|
|
2195
|
+
owner: string | null;
|
|
2196
|
+
parent: ObjectState | null;
|
|
2197
|
+
};
|
|
2198
|
+
//#endregion
|
|
2199
|
+
//#region src/dates.d.ts
|
|
2200
|
+
/** The current wall-clock time as epoch microseconds, for `pump`. */
|
|
2201
|
+
declare const nowMicros: () => bigint;
|
|
2202
|
+
/** A Civil Date: a date, and a time of day as microseconds since midnight, or null. */
|
|
2203
|
+
type CivilRef = {
|
|
2204
|
+
readonly day: number;
|
|
2205
|
+
readonly month: number;
|
|
2206
|
+
/** Microseconds since midnight, for a date-time; null for a date-only value. */
|
|
2207
|
+
readonly us: bigint | null;
|
|
2208
|
+
readonly year: number;
|
|
2209
|
+
};
|
|
2210
|
+
/** A Civil Date from its fields, or a reason it isn't one. */
|
|
2211
|
+
declare const civilFromFields: (f: {
|
|
2212
|
+
day: number;
|
|
2213
|
+
hour?: number;
|
|
2214
|
+
microsecond?: number;
|
|
2215
|
+
minute?: number;
|
|
2216
|
+
month: number;
|
|
2217
|
+
second?: number;
|
|
2218
|
+
year: number;
|
|
2219
|
+
}) => CivilRef | string;
|
|
2220
|
+
/** A Civil Date's fields, as the Host reads them. */
|
|
2221
|
+
declare const civilFields: (c: CivilRef) => {
|
|
2222
|
+
year: number;
|
|
2223
|
+
month: number;
|
|
2224
|
+
day: number;
|
|
2225
|
+
} | {
|
|
2226
|
+
hour: number;
|
|
2227
|
+
minute: number;
|
|
2228
|
+
second: number;
|
|
2229
|
+
microsecond: number;
|
|
2230
|
+
year: number;
|
|
2231
|
+
month: number;
|
|
2232
|
+
day: number;
|
|
2233
|
+
};
|
|
2234
|
+
/** An Instant's text form, always in UTC: `2026-09-27T13:30:00Z`. */
|
|
2235
|
+
declare const formatInstant: (us: bigint) => string;
|
|
2236
|
+
/** An Instant's display form as epoch microseconds, for the Host and the Trace. */
|
|
2237
|
+
declare const parseInstant: (s: string) => bigint;
|
|
2238
|
+
//#endregion
|
|
2239
|
+
//#region src/values.d.ts
|
|
2240
|
+
/** The kinds implemented so far; the rest of chapter 3's follow with #126. */
|
|
2241
|
+
type Kind = 'nothing' | 'boolean' | 'number' | 'quantity' | 'text' | 'bytes' | 'list' | 'map' | 'range' | 'instant' | 'civil date' | 'pattern' | 'function' | 'object';
|
|
2242
|
+
type Pairs = readonly (readonly [string, Value])[];
|
|
2243
|
+
/**
|
|
2244
|
+
* A Function Value (chapter 3, ADR 0025): its Home Script, where its code is,
|
|
2245
|
+
* its captured values in capture-slot order, and its may-suspend flag. `code`
|
|
2246
|
+
* is the Abstract Machine's own reference, which no Host or Script sees.
|
|
2021
2247
|
*/
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2248
|
+
type FunctionRef = {
|
|
2249
|
+
readonly captures: Pairs;
|
|
2250
|
+
readonly code: unknown;
|
|
2251
|
+
/** The extension unit used in the display form, while home remains the Script. */
|
|
2252
|
+
readonly displayHome?: string;
|
|
2253
|
+
/** The Core's Group identity; rebound by same-family restore. */
|
|
2254
|
+
readonly group?: object;
|
|
2255
|
+
readonly home: string;
|
|
2256
|
+
/** Equal for the same Lambda or named function in the same Home Script. */
|
|
2257
|
+
readonly identity: string;
|
|
2258
|
+
readonly maySuspend: boolean;
|
|
2259
|
+
/** Where its code is, as its display form shows it: `12:3`, `tax`, `text:pad`. */
|
|
2260
|
+
readonly place: string;
|
|
2035
2261
|
};
|
|
2036
|
-
/** A
|
|
2037
|
-
type
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
readonly
|
|
2041
|
-
readonly name: string;
|
|
2042
|
-
readonly needs: readonly OperationRef[];
|
|
2262
|
+
/** A Text Pattern: its canonical source, and the matcher's own data. */
|
|
2263
|
+
type PatternRef = {
|
|
2264
|
+
readonly data: unknown;
|
|
2265
|
+
/** The number of instructions in its compiled program. */
|
|
2266
|
+
readonly program: number;
|
|
2043
2267
|
readonly source: string;
|
|
2044
|
-
readonly version: string;
|
|
2045
2268
|
};
|
|
2046
|
-
/**
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2269
|
+
/**
|
|
2270
|
+
* A Host Object (chapter 3): its kind and its id, and the Group's own handle,
|
|
2271
|
+
* whose identity is the object's, so two are equal only when they are one.
|
|
2272
|
+
*/
|
|
2273
|
+
type ObjectRef = {
|
|
2274
|
+
readonly handle: unknown;
|
|
2275
|
+
readonly id: string;
|
|
2276
|
+
readonly kind: string;
|
|
2277
|
+
};
|
|
2278
|
+
/** A Quantity: its number and its Unit, in Kind order (chapter 3). */
|
|
2279
|
+
type QuantityRef = {
|
|
2280
|
+
readonly number: Decimal;
|
|
2281
|
+
readonly unit: UnitSpec;
|
|
2055
2282
|
};
|
|
2283
|
+
declare class Decimal {
|
|
2284
|
+
#private;
|
|
2285
|
+
private constructor();
|
|
2286
|
+
toString(): string;
|
|
2287
|
+
toBigInt(): bigint;
|
|
2288
|
+
toNumberLossy(): number;
|
|
2289
|
+
}
|
|
2290
|
+
/** Immutable, opaque value. Host code uses the named constructors. */
|
|
2291
|
+
declare class Value {
|
|
2292
|
+
#private;
|
|
2293
|
+
readonly kind: Kind;
|
|
2294
|
+
private constructor();
|
|
2295
|
+
static isValue(input: unknown): input is Value;
|
|
2296
|
+
asText(): string | undefined;
|
|
2297
|
+
asBool(): boolean | undefined;
|
|
2298
|
+
asDecimal(): Decimal | undefined;
|
|
2299
|
+
/** A Quantity's number and its Unit in normal form, as the Host reads it. */
|
|
2300
|
+
asQuantity(): {
|
|
2301
|
+
number: Decimal;
|
|
2302
|
+
unit: string;
|
|
2303
|
+
} | undefined;
|
|
2304
|
+
/** The Abstract Machine's view of a Quantity: its Unit's slots. */
|
|
2305
|
+
asQuantityRef(): QuantityRef | undefined;
|
|
2306
|
+
/** An Instant as epoch microseconds. */
|
|
2307
|
+
asInstant(): bigint | undefined;
|
|
2308
|
+
/** A Civil Date's fields; a date-only value has no time fields. */
|
|
2309
|
+
asCivilDate(): ReturnType<typeof civilFields> | undefined;
|
|
2310
|
+
/** The Abstract Machine's view of a Civil Date. */
|
|
2311
|
+
civilRef(): CivilRef | undefined;
|
|
2312
|
+
/** A copy of the bytes. */
|
|
2313
|
+
asBytes(): Uint8Array | undefined;
|
|
2314
|
+
/** The Abstract Machine's view of Bytes, which it never writes to. */
|
|
2315
|
+
bytesView(): Uint8Array | undefined;
|
|
2316
|
+
asRange(): {
|
|
2317
|
+
from: Value;
|
|
2318
|
+
to: Value;
|
|
2319
|
+
} | undefined;
|
|
2320
|
+
/** A Function Value's Home Script, its only Host-visible read. */
|
|
2321
|
+
homeScript(): string | undefined;
|
|
2322
|
+
/** A Text Pattern's canonical source, for display. */
|
|
2323
|
+
patternSource(): string | undefined;
|
|
2324
|
+
asPattern(): PatternRef | undefined;
|
|
2325
|
+
/** The Host Object handle this value stands for (chapter 9). */
|
|
2326
|
+
asObject(): HostObject | undefined;
|
|
2327
|
+
/** A Host Object's kind, id and handle. */
|
|
2328
|
+
asObjectRef(): ObjectRef | undefined;
|
|
2329
|
+
/** The Abstract Machine's view of a Function Value. */
|
|
2330
|
+
asFunction(): FunctionRef | undefined;
|
|
2331
|
+
get length(): number;
|
|
2332
|
+
index(i: number): Value;
|
|
2333
|
+
get(key: string): Value;
|
|
2334
|
+
/** Internal: the frozen pairs themselves, without copying. */
|
|
2335
|
+
mapPairs(): Pairs | undefined;
|
|
2336
|
+
get mapSize(): number;
|
|
2337
|
+
hasKey(key: string): boolean;
|
|
2338
|
+
entries(): [string, Value][];
|
|
2339
|
+
equals(other: Value): boolean;
|
|
2340
|
+
toString(): string;
|
|
2341
|
+
}
|
|
2342
|
+
declare const nothing: Value;
|
|
2343
|
+
declare const bool: (b: boolean) => Value;
|
|
2344
|
+
declare const text: (s: string) => Value;
|
|
2345
|
+
declare const dec: (s: string) => Value;
|
|
2346
|
+
/** ECMAScript's shortest round-trip digits, expanded without rounding. */
|
|
2347
|
+
declare const num: (n: number | bigint) => Value;
|
|
2348
|
+
declare const list: (...vs: Value[]) => Value;
|
|
2349
|
+
/** Two numbers, or two Quantities of one dimension, kept as given (ADR 0034). */
|
|
2350
|
+
declare const range: (from: Value, to: Value) => Value;
|
|
2056
2351
|
/**
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2059
|
-
* always there. Throws LoadError.
|
|
2352
|
+
* A Quantity of a number Value in a Unit spelled as a Script spells it, such
|
|
2353
|
+
* as `"kg"`. A Unit whose slots all drop, such as `"m/m"`, leaves the number.
|
|
2060
2354
|
*/
|
|
2061
|
-
declare const
|
|
2062
|
-
/**
|
|
2063
|
-
declare const
|
|
2355
|
+
declare const quantity: (n: Value, unit: string) => Value;
|
|
2356
|
+
/** An Instant, from epoch microseconds; a JS Date is never accepted. */
|
|
2357
|
+
declare const instant: (epochMicros: bigint) => Value;
|
|
2358
|
+
type DateFields = Parameters<typeof civilFromFields>[0];
|
|
2359
|
+
/** A Civil Date, from its fields or from text in the `as civil date` form. */
|
|
2360
|
+
declare const civilDate: (f: DateFields | string) => Value;
|
|
2361
|
+
/** Bytes, copied in. */
|
|
2362
|
+
declare const bytes: (b: Uint8Array) => Value;
|
|
2363
|
+
declare const map: (input: Map<string, Value> | Iterable<[string, Value]>) => Value;
|
|
2364
|
+
declare const record: (input: Record<string, Value>) => Value;
|
|
2365
|
+
/**
|
|
2366
|
+
* Tooling's source form: the display form, with the substitutions that make it
|
|
2367
|
+
* source that reads back as an equal value with the same display form. Nothing
|
|
2368
|
+
* about it is normative (ADR 0028). An unreadable value keeps its display form.
|
|
2369
|
+
*/
|
|
2370
|
+
declare const sourceForm: (value: Value) => string;
|
|
2371
|
+
/** A value is readable when it contains no Function Value or Host Object. */
|
|
2372
|
+
declare const isReadable: (value: Value) => boolean;
|
|
2373
|
+
//#endregion
|
|
2374
|
+
//#region src/run-accounting.d.ts
|
|
2375
|
+
type RunAncestry = {
|
|
2376
|
+
parentCall?: string;
|
|
2377
|
+
parentRun?: string;
|
|
2378
|
+
rootDelivery: string;
|
|
2379
|
+
};
|
|
2380
|
+
type RunStarted = RunAncestry & {
|
|
2381
|
+
args: Value[];
|
|
2382
|
+
delivery?: string;
|
|
2383
|
+
fn?: Value;
|
|
2384
|
+
kind: 'run started';
|
|
2385
|
+
run: string;
|
|
2386
|
+
script: string;
|
|
2387
|
+
selector?: string;
|
|
2388
|
+
};
|
|
2389
|
+
type RunDiscarded = RunAncestry & {
|
|
2390
|
+
kind: 'run discarded';
|
|
2391
|
+
reason: string;
|
|
2392
|
+
run: string;
|
|
2393
|
+
script: string;
|
|
2394
|
+
};
|
|
2395
|
+
type RunAccounting = RunAncestry & {
|
|
2396
|
+
fuel: number;
|
|
2397
|
+
kind: 'run accounting';
|
|
2398
|
+
run: string;
|
|
2399
|
+
script: string;
|
|
2400
|
+
state: 'live' | 'terminal' | 'discarded';
|
|
2401
|
+
};
|
|
2402
|
+
type CausalWork = {
|
|
2403
|
+
discardedMessages: number;
|
|
2404
|
+
kind: 'causal work';
|
|
2405
|
+
liveRuns: number;
|
|
2406
|
+
queuedMessages: number;
|
|
2407
|
+
rootDelivery: string;
|
|
2408
|
+
};
|
|
2409
|
+
type AccountingReport = RunStarted | RunDiscarded | RunAccounting | CausalWork;
|
|
2064
2410
|
//#endregion
|
|
2065
2411
|
//#region src/group.d.ts
|
|
2066
2412
|
type GroupOptions = {
|
|
@@ -2108,10 +2454,29 @@ type RunEvent = {
|
|
|
2108
2454
|
outcome: string;
|
|
2109
2455
|
run: string;
|
|
2110
2456
|
};
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2457
|
+
/**
|
|
2458
|
+
* TS-internal, and not exported from the package: how a Session Host follows
|
|
2459
|
+
* a TS Core Group (ADR 0045). The Group calls `connect` once, when the port
|
|
2460
|
+
* attaches, with the controls only the Session drives.
|
|
2461
|
+
*/
|
|
2462
|
+
type SessionPort = {
|
|
2463
|
+
connect(controls: SessionControls): void;
|
|
2464
|
+
runs(r: RunEvent): void;
|
|
2465
|
+
values(tree: unknown): void;
|
|
2466
|
+
};
|
|
2467
|
+
type SessionControls = {
|
|
2468
|
+
/** Whether Host Inputs wait for the next Pump (chapter 12, The foreground). */
|
|
2469
|
+
queuedInputs(): boolean;
|
|
2470
|
+
/** Settles a Call the Session's message layer answered. */
|
|
2471
|
+
reply(id: string, reply: Resumption): void;
|
|
2472
|
+
};
|
|
2473
|
+
/** The TS Core's own options, beyond the embedding interface's. */
|
|
2474
|
+
type TsGroupOptions = GroupOptions & {
|
|
2475
|
+
session?: SessionPort;
|
|
2476
|
+
};
|
|
2477
|
+
type TsRestoreOptions = RestoreOptions & {
|
|
2478
|
+
session?: SessionPort;
|
|
2479
|
+
};
|
|
2115
2480
|
type LoadOptions = {
|
|
2116
2481
|
/** Its Grants, by the name the Script uses for each. */
|
|
2117
2482
|
grants?: Readonly<Record<string, Grant<any>>>;
|
|
@@ -2155,6 +2520,34 @@ type Requested = {
|
|
|
2155
2520
|
id: string;
|
|
2156
2521
|
result: Promise<Value>;
|
|
2157
2522
|
};
|
|
2523
|
+
/** Admission failure has no handle. A refused Pump retains the admitted Request. */
|
|
2524
|
+
type PumpedRequest = {
|
|
2525
|
+
admitted: false;
|
|
2526
|
+
error: unknown;
|
|
2527
|
+
} | {
|
|
2528
|
+
admitted: true;
|
|
2529
|
+
pump: {
|
|
2530
|
+
ok: true;
|
|
2531
|
+
result: PumpResult;
|
|
2532
|
+
} | {
|
|
2533
|
+
error: unknown;
|
|
2534
|
+
ok: false;
|
|
2535
|
+
};
|
|
2536
|
+
requested: Requested;
|
|
2537
|
+
};
|
|
2538
|
+
/** Native TS only; the Zig-backed adapter retains its own save format. */
|
|
2539
|
+
type SaveOptions = {
|
|
2540
|
+
sources?: 'embedded' | 'external';
|
|
2541
|
+
};
|
|
2542
|
+
type ScriptCodeRequest = {
|
|
2543
|
+
/** Base source first, then extensions in their saved order. */
|
|
2544
|
+
identities: readonly string[];
|
|
2545
|
+
name: string;
|
|
2546
|
+
};
|
|
2547
|
+
type ScriptSources = {
|
|
2548
|
+
extensions?: readonly string[];
|
|
2549
|
+
source: string;
|
|
2550
|
+
};
|
|
2158
2551
|
type RestoreOptions = GroupOptions & {
|
|
2159
2552
|
grants(script: string, name: string): Grant<unknown> | undefined;
|
|
2160
2553
|
libraries: readonly Library[];
|
|
@@ -2162,6 +2555,8 @@ type RestoreOptions = GroupOptions & {
|
|
|
2162
2555
|
resolve(kind: string, id: string): {
|
|
2163
2556
|
native: unknown;
|
|
2164
2557
|
} | undefined;
|
|
2558
|
+
/** Native TS external-source snapshots only. Different code requires variables-only policy. */
|
|
2559
|
+
scriptSources?(request: ScriptCodeRequest): ScriptSources | undefined;
|
|
2165
2560
|
};
|
|
2166
2561
|
type PendingCall = {
|
|
2167
2562
|
args: Value[];
|
|
@@ -2315,59 +2710,29 @@ type Inspection = {
|
|
|
2315
2710
|
vars: [string, Value][];
|
|
2316
2711
|
}[];
|
|
2317
2712
|
};
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
type Delivery = {
|
|
2336
|
-
ancestry?: RunAncestry;
|
|
2337
|
-
args: Value[];
|
|
2338
|
-
/** The object whose Owning Script holds it, which it climbs on from. */
|
|
2339
|
-
at: ObjectState | null;
|
|
2340
|
-
ballot?: Ballot;
|
|
2341
|
-
broadcast?: string;
|
|
2342
|
-
/** The failed message, for an internal `error` Delivery. */
|
|
2343
|
-
during?: Value;
|
|
2344
|
-
fn?: Value;
|
|
2345
|
-
/** For a message a Script sent, the sending Run. */
|
|
2346
|
-
from: string | null;
|
|
2347
|
-
/** The delivery id; a message a Script sent has none. */
|
|
2348
|
-
id: string | null;
|
|
2349
|
-
limits: LimitOverride;
|
|
2350
|
-
message: string;
|
|
2351
|
-
/** The current path starts here; a climb excludes the last owner that handled it. */
|
|
2352
|
-
path?: {
|
|
2353
|
-
after: boolean;
|
|
2354
|
-
from: ObjectState;
|
|
2355
|
-
};
|
|
2356
|
-
/** For a `send … and wait`, the sender's call id, which the Run's end settles. */
|
|
2357
|
-
reply: string | null;
|
|
2358
|
-
request: {
|
|
2359
|
-
reject: (e: Error) => void;
|
|
2360
|
-
resolve: (v: Value) => void;
|
|
2361
|
-
} | null;
|
|
2362
|
-
/** The object it was addressed to: `the target` all the way up. */
|
|
2363
|
-
target: ObjectState | null;
|
|
2364
|
-
unsubscribe?: () => void;
|
|
2713
|
+
/**
|
|
2714
|
+
* What a Script handle reaches its Group through: the Group's Script-only
|
|
2715
|
+
* operations, which aren't on the Group itself.
|
|
2716
|
+
*/
|
|
2717
|
+
type ScriptChannel = {
|
|
2718
|
+
combine: TsGroup['combine'];
|
|
2719
|
+
counters: TsGroup['scriptCounters'];
|
|
2720
|
+
extend: TsGroup['extend'];
|
|
2721
|
+
grants: TsGroup['scriptGrants'];
|
|
2722
|
+
queueCancelRun: TsGroup['queueCancelRun'];
|
|
2723
|
+
queueDecision: TsGroup['queueDecision'];
|
|
2724
|
+
queueDelivery: TsGroup['queueDelivery'];
|
|
2725
|
+
queueRevoke: TsGroup['queueRevoke'];
|
|
2726
|
+
queueRewindRun: TsGroup['queueRewindRun'];
|
|
2727
|
+
queueStop: TsGroup['queueStop'];
|
|
2728
|
+
reload: TsGroup['reload'];
|
|
2729
|
+
watchCancellation: TsGroup['watchCancellation'];
|
|
2365
2730
|
};
|
|
2366
2731
|
/** A handle for calls addressed to one Script. */
|
|
2367
|
-
declare class Script {
|
|
2732
|
+
declare class TsScript implements Script {
|
|
2368
2733
|
private readonly group;
|
|
2369
2734
|
readonly name: string;
|
|
2370
|
-
constructor(group:
|
|
2735
|
+
constructor(group: ScriptChannel, name: string);
|
|
2371
2736
|
/** Worker. A snapshot of kept Operations, including revoked Grants. */
|
|
2372
2737
|
grants(): Record<string, string[]>;
|
|
2373
2738
|
/** Worker. Lifetime totals and current state, without draining inputs. */
|
|
@@ -2378,6 +2743,10 @@ declare class Script {
|
|
|
2378
2743
|
decide(m: Message, o?: CancellationOptions): Deciding;
|
|
2379
2744
|
/** Queued. Settles when a Pump ends the Run, or rejects with `send failed`. */
|
|
2380
2745
|
request(m: Message, o?: CancellationOptions): Requested;
|
|
2746
|
+
/** Queued. A Request for the answer only; use `request` for its id or a signal. */
|
|
2747
|
+
invoke(name: string, ...args: Value[]): Promise<Value>;
|
|
2748
|
+
/** Worker. Request this Script and perform exactly one Pump. */
|
|
2749
|
+
requestPump(m: Message, now: bigint, o?: PumpOptions & CancellationOptions): PumpedRequest;
|
|
2381
2750
|
reload(source: string, carry: CarryOver, o?: {
|
|
2382
2751
|
keepMailbox?: boolean;
|
|
2383
2752
|
}): Report[];
|
|
@@ -2389,23 +2758,20 @@ declare class Script {
|
|
|
2389
2758
|
/** Queued. In-flight calls are left to the Host. */
|
|
2390
2759
|
revoke(grantName: string): void;
|
|
2391
2760
|
}
|
|
2392
|
-
declare class Group {
|
|
2393
|
-
private
|
|
2394
|
-
|
|
2395
|
-
[sessionReply](id: string, reply: Resumption): void;
|
|
2761
|
+
declare class TsGroup implements Group {
|
|
2762
|
+
private session;
|
|
2763
|
+
private readonly channel;
|
|
2396
2764
|
readonly name: string;
|
|
2397
2765
|
private readonly trace;
|
|
2398
2766
|
private readonly onReady;
|
|
2399
2767
|
private readonly scripts;
|
|
2400
2768
|
private readonly libraries;
|
|
2401
|
-
private readonly
|
|
2769
|
+
private readonly waits;
|
|
2402
2770
|
private readonly functionGroup;
|
|
2403
2771
|
private readonly objects;
|
|
2404
2772
|
private drainReports;
|
|
2405
2773
|
private accounting;
|
|
2406
2774
|
private discardReason;
|
|
2407
|
-
private timers;
|
|
2408
|
-
private timerSeq;
|
|
2409
2775
|
private inputs;
|
|
2410
2776
|
private deliveries;
|
|
2411
2777
|
private broadcasts;
|
|
@@ -2413,6 +2779,8 @@ declare class Group {
|
|
|
2413
2779
|
private lastClock;
|
|
2414
2780
|
private randomState;
|
|
2415
2781
|
private pumping;
|
|
2782
|
+
private combining;
|
|
2783
|
+
private combinedAdmission;
|
|
2416
2784
|
private cleaning;
|
|
2417
2785
|
private effectStateUnknown;
|
|
2418
2786
|
private terminalReports;
|
|
@@ -2427,10 +2795,7 @@ declare class Group {
|
|
|
2427
2795
|
* The next `random(n)` draw from the Group's generator; `commit` advances
|
|
2428
2796
|
* the generator past it (chapter 7, Random numbers).
|
|
2429
2797
|
*/
|
|
2430
|
-
drawRandom
|
|
2431
|
-
commit(): void;
|
|
2432
|
-
value: bigint;
|
|
2433
|
-
};
|
|
2798
|
+
private drawRandom;
|
|
2434
2799
|
private ancestry;
|
|
2435
2800
|
private accountStart;
|
|
2436
2801
|
private accountEnd;
|
|
@@ -2439,19 +2804,15 @@ declare class Group {
|
|
|
2439
2804
|
/** TS tooling only, outside the embedding interface and Trace parity. */
|
|
2440
2805
|
debug(): DebugController;
|
|
2441
2806
|
private advanceDebugPump;
|
|
2442
|
-
private
|
|
2443
|
-
/** TS-internal: receives the records a Session Host follows (ADR 0045). */
|
|
2444
|
-
[observeRuns](observer: ((r: RunEvent) => void) | null): void;
|
|
2445
|
-
/** TS-internal: whether Host Inputs wait for the next Pump (chapter 12, The foreground). */
|
|
2446
|
-
[queuedInputs](): boolean;
|
|
2807
|
+
private attachSession;
|
|
2447
2808
|
/** Worker. A Fingerprint covers code, declarations and limits, never state. */
|
|
2448
2809
|
fingerprint(): Uint8Array;
|
|
2449
|
-
private snapshotReferences;
|
|
2450
2810
|
/** Worker. Host callbacks, bindings and native objects aren't in the bytes. */
|
|
2451
|
-
|
|
2811
|
+
private references;
|
|
2812
|
+
save(o?: SaveOptions): Uint8Array;
|
|
2452
2813
|
/** Build and check the complete replacement before publishing the Group. */
|
|
2453
|
-
static restore(bytes: Uint8Array, o:
|
|
2454
|
-
group:
|
|
2814
|
+
static restore(bytes: Uint8Array, o: TsRestoreOptions): {
|
|
2815
|
+
group: TsGroup;
|
|
2455
2816
|
result: RestoreResult;
|
|
2456
2817
|
};
|
|
2457
2818
|
private discardedDecisions;
|
|
@@ -2463,17 +2824,17 @@ declare class Group {
|
|
|
2463
2824
|
settle(id: string, settlement: Settlement): Call<unknown> | undefined;
|
|
2464
2825
|
private applySettlement;
|
|
2465
2826
|
private pendingCall;
|
|
2466
|
-
private
|
|
2827
|
+
private holders;
|
|
2467
2828
|
private pendingOperations;
|
|
2468
2829
|
/** A Request's signal lives until its Run ends; a Decision's until its seal. */
|
|
2469
|
-
watchCancellation
|
|
2830
|
+
private watchCancellation;
|
|
2470
2831
|
/** Queue the Host Input produced by aborting a Request, Decision or Host call. */
|
|
2471
2832
|
cancelDelivery(id: string): void;
|
|
2472
2833
|
private cancelDeliveryNow;
|
|
2473
|
-
queueCancelRun
|
|
2474
|
-
queueRewindRun
|
|
2475
|
-
queueStop
|
|
2476
|
-
queueRevoke
|
|
2834
|
+
private queueCancelRun;
|
|
2835
|
+
private queueRewindRun;
|
|
2836
|
+
private queueStop;
|
|
2837
|
+
private queueRevoke;
|
|
2477
2838
|
private applyInput;
|
|
2478
2839
|
private runsOf;
|
|
2479
2840
|
private forgetWait;
|
|
@@ -2494,18 +2855,18 @@ declare class Group {
|
|
|
2494
2855
|
private acceptDelivery;
|
|
2495
2856
|
private recordRefusal;
|
|
2496
2857
|
private landUrgentInputs;
|
|
2497
|
-
constructor(options:
|
|
2498
|
-
script(name: string):
|
|
2858
|
+
constructor(options: TsGroupOptions);
|
|
2859
|
+
script(name: string): TsScript | undefined;
|
|
2499
2860
|
/** Any time, inside a Pump too. Its Scripts' names, in load order; not a Host Input. */
|
|
2500
2861
|
scriptNames(): string[];
|
|
2501
2862
|
private queueInput;
|
|
2502
2863
|
private worker;
|
|
2503
2864
|
private finalizeEffects;
|
|
2504
2865
|
private accumulateRunCosts;
|
|
2505
|
-
scriptCounters
|
|
2506
|
-
scriptGrants
|
|
2866
|
+
private scriptCounters;
|
|
2867
|
+
private scriptGrants;
|
|
2507
2868
|
/** Worker. Compiles, checks and loads a Script, or throws LoadError. */
|
|
2508
|
-
load(o: LoadOptions):
|
|
2869
|
+
load(o: LoadOptions): TsScript;
|
|
2509
2870
|
private loadPrepared;
|
|
2510
2871
|
private writeDiagnostics;
|
|
2511
2872
|
private replacement;
|
|
@@ -2525,19 +2886,17 @@ declare class Group {
|
|
|
2525
2886
|
replaceLibrary(l: Library, carry: CarryOver): Report[];
|
|
2526
2887
|
private hostFor;
|
|
2527
2888
|
private enqueue;
|
|
2528
|
-
private timer;
|
|
2529
2889
|
private fireTimer;
|
|
2530
2890
|
private ready;
|
|
2531
2891
|
private settleReply;
|
|
2532
|
-
private endWaiter;
|
|
2533
2892
|
private observe;
|
|
2534
2893
|
private suspended;
|
|
2535
2894
|
private checkFunctionGroups;
|
|
2536
2895
|
/** A queued Delivery: its id now, its line and its mailbox entry at the next Pump. */
|
|
2537
|
-
queueDelivery
|
|
2896
|
+
private queueDelivery;
|
|
2538
2897
|
/** Queued. Asks the object's Message Path for a Verdict. */
|
|
2539
2898
|
decide(to: HostObject, m: Message, o?: CancellationOptions): Deciding;
|
|
2540
|
-
queueDecision
|
|
2899
|
+
private queueDecision;
|
|
2541
2900
|
/** Queued. Takes recipients at drain, then waits for every Verdict. */
|
|
2542
2901
|
decideBroadcast(m: Message, o?: CancellationOptions): Deciding;
|
|
2543
2902
|
/** Queued. Delivers to recipients taken in load order at drain. */
|
|
@@ -2550,6 +2909,13 @@ declare class Group {
|
|
|
2550
2909
|
deliver(to: HostObject, m: Message): string;
|
|
2551
2910
|
/** Queued. As `deliver`, and settles when a Pump ends the Run. */
|
|
2552
2911
|
request(to: HostObject, m: Message, o?: CancellationOptions): Requested;
|
|
2912
|
+
/** Worker. Admit once, then Pump once; a Pump refusal retains the Request. */
|
|
2913
|
+
requestPump(to: HostObject, m: Message, now: bigint, o?: PumpOptions & CancellationOptions): PumpedRequest;
|
|
2914
|
+
/** Worker. A Function Call and one Pump, with ordinary Call options. */
|
|
2915
|
+
callPump(fn: Value, args: Value[], now: bigint, o?: PumpOptions & CancellationOptions & {
|
|
2916
|
+
limits?: LimitOverride;
|
|
2917
|
+
}): PumpedRequest;
|
|
2918
|
+
private combine;
|
|
2553
2919
|
/** Queued. Calls a Function Value as a Request to its Home Script. */
|
|
2554
2920
|
call(fn: Value, args: Value[], o?: CancellationOptions & {
|
|
2555
2921
|
limits?: LimitOverride;
|
|
@@ -2559,7 +2925,7 @@ declare class Group {
|
|
|
2559
2925
|
/** The handle with this Object Kind name and id, disposed or not, such as one Restore made. */
|
|
2560
2926
|
objectById(kind: string, id: string): HostObject | undefined;
|
|
2561
2927
|
/** Whether an object value is one of this Group's handles. */
|
|
2562
|
-
holdsObject
|
|
2928
|
+
private holdsObject;
|
|
2563
2929
|
private held;
|
|
2564
2930
|
private parentError;
|
|
2565
2931
|
/** Queued. Refuses cycles and disposed children at admission and again at drain. */
|
|
@@ -2572,6 +2938,7 @@ declare class Group {
|
|
|
2572
2938
|
private deliveryLine;
|
|
2573
2939
|
/** Worker. One Clock reading, the queue drained, then turns until done (chapter 5). */
|
|
2574
2940
|
pump(now: bigint, o?: PumpOptions): PumpResult;
|
|
2941
|
+
private pumpWorker;
|
|
2575
2942
|
private pumpAtClock;
|
|
2576
2943
|
private moveDelivery;
|
|
2577
2944
|
private turn;
|
|
@@ -2591,9 +2958,9 @@ declare class Group {
|
|
|
2591
2958
|
inspect(): Inspection;
|
|
2592
2959
|
private inspection;
|
|
2593
2960
|
}
|
|
2594
|
-
declare const newGroup: (o:
|
|
2595
|
-
declare const restore: (bytes: Uint8Array, options:
|
|
2596
|
-
group:
|
|
2961
|
+
declare const newGroup: (o: TsGroupOptions) => TsGroup;
|
|
2962
|
+
declare const restore: (bytes: Uint8Array, options: TsRestoreOptions) => {
|
|
2963
|
+
group: TsGroup;
|
|
2597
2964
|
result: RestoreResult;
|
|
2598
2965
|
};
|
|
2599
2966
|
//#endregion
|
|
@@ -2695,4 +3062,4 @@ declare class DebugController {
|
|
|
2695
3062
|
enter(pause: DebugPause): void;
|
|
2696
3063
|
}
|
|
2697
3064
|
//#endregion
|
|
2698
|
-
export {
|
|
3065
|
+
export { isReadable as $, EventEntry as $n, httpCapability as $t, SessionControls as A, Outcome as An, ImmediateOp as At, CausalWork as B, canConvert as Bn, SegmentCoordinator as Bt, Requested as C, LibrarySource as Cn, SyntaxNode as Cr, Cost as Ct, SaveOptions as D, replacementLibraries as Dn, syntaxText as Dr, FireOp as Dt, RunEvent as E, compileLibrary as En, syntaxSelector as Er, FieldShape as Et, TsRestoreOptions as F, callFunction as Fn, PlainResult as Ft, Decimal as G, LoadError as Gn, defineCapability as Gt, RunAncestry as H, HostError as Hn, SegmentLifecycle as Ht, TsScript as I, defaultLimits as In, ReleaseHook as It, bool as J, SendFailedReason as Jn, Group as Jt, Kind as K, MailboxFull as Kn, shape as Kt, Verdict as L, deliver as Ln, ReleaseReason as Lt, Settlement as M, RunRecord as Mn, Operation as Mt, TsGroup as N, Script$1 as Nn, Operations as Nt, ScriptCodeRequest as O, LimitName as On, Grant as Ot, TsGroupOptions as P, UnitLoadError as Pn, PlainArg as Pt, instant as Q, EventBranch as Qn, HttpImpl as Qt, newGroup as R, loadScript as Rn, ScopeDecl as Rt, Report as S, LibraryOptions as Sn, SyntaxErrorCode as Sr, CoordinatedLifecycle as St, RestoreResult as T, codeIdentity as Tn, Trivia as Tr, ErrorDecl as Tt, RunDiscarded as U, HostErrorCode as Un, Shape as Ut, RunAccounting as V, waitUs as Vn, SegmentGrant as Vt, RunStarted as W, LoadDiagnostic as Wn, SuspendingOp as Wt, civilDate as X, BodyKind as Xn, Versions as Xt, bytes as Y, Body as Yn, Script as Yt, dec as Z, CodeUnit as Zn, coreVersions as Zt, Message as _, calendarCapability as _n, Lexer as _r, defineObjectKind as _t, DebugSnapshot as a, SqlParams as an, BindingKind as ar, range as at, PumpResult as b, timerCapability as bn, Token as br, CapabilityDef as bt, CancellationOptions as c, SqliteBinding as cn, LibraryExport as cr, text as ct, Decided as d, LocaleImpl as dn, SemanticName as dr, parseInstant as dt, UserImpl as en, Instruction as er, list as et, Deciding as f, localeCapability as fn, SemanticNode as fr, HostObject as ft, LoadOptions as g, TimerImpl as gn, SourceSpan as gr, PropDef as gt, Inspection as h, Costs as hn, SemanticTree as hr, ObjectKindDef as ht, DebugPause as i, storeCapability as in, Binding as ir, quantity as it, SessionPort as j, Run as jn, LimitReached as jt, ScriptSources as k, Limits as kn, GrantContext as kt, CarryOver as l, SqliteImpl as ln, NameRole as lr, formatInstant as lt, GroupOptions as m, ConsoleImpl as mn, SemanticToken as mr, ObjectKind as mt, DebugFrame as n, StoreImpl as nn, UnwindEntry as nr, nothing as nt, DebugSource as o, SqlRows as on, ExportKind as or, record as ot, EffectFailure as p, CalendarImpl as pn, SemanticScope as pr, ObjectElements as pt, Value as q, ScriptError as qn, Core as qt, DebugInstruction as r, add as rn, disassemble as rr, num as rt, RepeatedEffect as s, SqlValue as sn, FunctionContract as sr, sourceForm as st, DebugController as t, userCapability as tn, Operand as tr, map as tt, Counters as u, sqliteCapability as un, SemanticElement as ur, nowMicros as ut, PendingCall as v, clockCapability as vn, Mode as vr, GrantDecls as vt, RestoreOptions as w, OperationRef as wn, SyntaxRule as wr, EffectResult as wt, PumpedRequest as x, Library as xn, SyntaxElement as xr, CapabilityDefiner as xt, PumpOptions as y, consoleCapability as yn, TokType as yr, Call as yt, restore as z, NotImplementedError as zn, SegmentContext as zt };
|