@graphvideo/kernel 1.0.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/dist/context.d.ts +28 -0
- package/dist/delivery.d.ts +36 -0
- package/dist/effect-harness.d.ts +51 -0
- package/dist/effect-harness.mjs +191 -0
- package/dist/effects.d.ts +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +1104 -0
- package/dist/internal-access.d.ts +3 -0
- package/dist/node.d.ts +99 -0
- package/dist/observation.d.ts +204 -0
- package/dist/runtime.d.ts +121 -0
- package/dist/scheduler.d.ts +20 -0
- package/dist/snapshot.d.ts +14 -0
- package/dist/types.d.ts +107 -0
- package/package.json +28 -0
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Info, InfoEnvelope, ChangeRecord, DomainChangeContext, WorldChangeContext } from './types';
|
|
2
|
+
import type { NodeStateSnapshot, EncodedValue, RuntimeIdKind } from './observation';
|
|
3
|
+
import { ChangeContextImpl } from './context';
|
|
4
|
+
import { changeContextCapability, nodeRuntimeCapability } from './internal-access';
|
|
5
|
+
export { ChangeContextImpl };
|
|
6
|
+
export type NodeStatus = 'IDLE' | 'RUNNING' | 'ERROR' | 'ABORTED';
|
|
7
|
+
export type Disposer = () => void | Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Minimal Graph Node Base Class
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class Node<S = any, C extends DomainChangeContext<S> = DomainChangeContext<S>> {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
readonly factoryKey: string;
|
|
15
|
+
isWorldNode: boolean;
|
|
16
|
+
status: NodeStatus;
|
|
17
|
+
executionCount: number;
|
|
18
|
+
lastActiveTime: number;
|
|
19
|
+
lastErrorMessage: string | null;
|
|
20
|
+
protected state: S;
|
|
21
|
+
private regionVersions;
|
|
22
|
+
private globalVersion;
|
|
23
|
+
private readonly mailbox;
|
|
24
|
+
private drainingMailbox;
|
|
25
|
+
private activeChangeId;
|
|
26
|
+
private disposers;
|
|
27
|
+
private abortController;
|
|
28
|
+
private kernel;
|
|
29
|
+
constructor(id: string, name: string, initialState?: S, factoryKey?: string);
|
|
30
|
+
getState(): Readonly<S>;
|
|
31
|
+
getStateRegionVersions(): Readonly<Record<string, number>>;
|
|
32
|
+
getGlobalStateVersion(): number;
|
|
33
|
+
getMailboxSize(): number;
|
|
34
|
+
getActiveChangeId(): string | undefined;
|
|
35
|
+
_restoreStateSnapshot(capability: typeof nodeRuntimeCapability, snapshot: NodeStateSnapshot, decodedState: unknown): void;
|
|
36
|
+
/** @internal Runtime ownership boundary. Domain nodes cannot reach the engine directly. */
|
|
37
|
+
_mountKernel(capability: typeof nodeRuntimeCapability, kernel: unknown): void;
|
|
38
|
+
/** @internal Runtime ownership boundary. */
|
|
39
|
+
_unmountKernel(capability: typeof nodeRuntimeCapability, kernel: unknown): void;
|
|
40
|
+
_enqueueMailbox(capability: typeof nodeRuntimeCapability, info: Info, envelope?: InfoEnvelope, options?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
_drainMailbox(capability: typeof nodeRuntimeCapability): Promise<void>;
|
|
44
|
+
private runWithinChangeContext;
|
|
45
|
+
protected createChangeContext(info: Info, changeId: string, envelope?: InfoEnvelope, signal?: AbortSignal): ChangeContextImpl<S>;
|
|
46
|
+
get stateVersion(): number;
|
|
47
|
+
commitStateFromChange(capability: typeof changeContextCapability, changeId: string, patch: Partial<S>, causeInfo?: Info): void;
|
|
48
|
+
_sendFromChange(capability: typeof changeContextCapability, info: Info, target: Node<any> | string, options?: {
|
|
49
|
+
infoId?: string;
|
|
50
|
+
causedByChangeId?: string;
|
|
51
|
+
causeInfoId?: string;
|
|
52
|
+
submissionId?: string;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}): void;
|
|
55
|
+
protected change(_info: Info, _ctx: C): void | Promise<void>;
|
|
56
|
+
runtimeNow(): number;
|
|
57
|
+
runtimeMonotonicNow(): number;
|
|
58
|
+
runtimeId(kind: RuntimeIdKind): string;
|
|
59
|
+
encodeTraceValue(field: string, value: unknown): EncodedValue;
|
|
60
|
+
runtimeValueRef(kind: string, value: unknown): string;
|
|
61
|
+
recordChangeStarted(input: {
|
|
62
|
+
changeId: string;
|
|
63
|
+
nodeId: string;
|
|
64
|
+
causeInfoId: string;
|
|
65
|
+
causeInfoType: string;
|
|
66
|
+
stateVersionBefore: number;
|
|
67
|
+
}): void;
|
|
68
|
+
recordChange(record: ChangeRecord): void;
|
|
69
|
+
recordEffectRequested(input: {
|
|
70
|
+
effectId: string;
|
|
71
|
+
changeId: string;
|
|
72
|
+
nodeId: string;
|
|
73
|
+
name?: string;
|
|
74
|
+
adapterId?: string;
|
|
75
|
+
requestRef?: string;
|
|
76
|
+
}): void;
|
|
77
|
+
recordEffectObserved(input: {
|
|
78
|
+
effectId: string;
|
|
79
|
+
changeId: string;
|
|
80
|
+
nodeId: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
status: 'succeeded' | 'failed';
|
|
83
|
+
adapterId?: string;
|
|
84
|
+
requestRef?: string;
|
|
85
|
+
observationRef?: string;
|
|
86
|
+
}): void;
|
|
87
|
+
onMount(): void;
|
|
88
|
+
onUnmount(): void;
|
|
89
|
+
registerDisposer(disposer: Disposer): void;
|
|
90
|
+
dispose(): Promise<void>;
|
|
91
|
+
abort(reason?: string): void;
|
|
92
|
+
reset(): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* WorldNode Base Class
|
|
96
|
+
*/
|
|
97
|
+
export declare abstract class WorldNode<S = any, C extends WorldChangeContext<S> = WorldChangeContext<S>> extends Node<S, C> {
|
|
98
|
+
isWorldNode: boolean;
|
|
99
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { ChangeRecord, InfoEnvelope } from './types';
|
|
2
|
+
export declare const traceSchemaVersion: 2;
|
|
3
|
+
export type TraceId = string;
|
|
4
|
+
export type RunId = string;
|
|
5
|
+
export type EventId = string;
|
|
6
|
+
export type RuntimeIdKind = 'trace' | 'run' | 'event' | 'info' | 'info-root' | 'send' | 'change' | 'effect' | 'snapshot' | 'submission' | 'task';
|
|
7
|
+
export interface Clock {
|
|
8
|
+
now(): number;
|
|
9
|
+
monotonicNow(): number;
|
|
10
|
+
}
|
|
11
|
+
export interface IdProvider {
|
|
12
|
+
nextId(kind: RuntimeIdKind): string;
|
|
13
|
+
}
|
|
14
|
+
export interface RandomSource {
|
|
15
|
+
next(): number;
|
|
16
|
+
}
|
|
17
|
+
export declare const systemClock: Clock;
|
|
18
|
+
export declare const systemRandomSource: RandomSource;
|
|
19
|
+
export declare class TimeRandomIdProvider implements IdProvider {
|
|
20
|
+
private clock;
|
|
21
|
+
private randomSource;
|
|
22
|
+
private counter;
|
|
23
|
+
constructor(clock?: Clock, randomSource?: RandomSource);
|
|
24
|
+
nextId(kind: RuntimeIdKind): string;
|
|
25
|
+
}
|
|
26
|
+
export type EncodedValue = {
|
|
27
|
+
$type: 'primitive';
|
|
28
|
+
value: string | number | boolean | null | undefined;
|
|
29
|
+
} | {
|
|
30
|
+
$type: 'array';
|
|
31
|
+
value: EncodedValue[];
|
|
32
|
+
} | {
|
|
33
|
+
$type: 'object';
|
|
34
|
+
value: Record<string, EncodedValue>;
|
|
35
|
+
} | {
|
|
36
|
+
$type: 'map';
|
|
37
|
+
entries: Array<[EncodedValue, EncodedValue]>;
|
|
38
|
+
} | {
|
|
39
|
+
$type: 'set';
|
|
40
|
+
values: EncodedValue[];
|
|
41
|
+
} | {
|
|
42
|
+
$type: 'bytes';
|
|
43
|
+
value: string;
|
|
44
|
+
byteLength: number;
|
|
45
|
+
} | {
|
|
46
|
+
$type: 'ref';
|
|
47
|
+
kind: string;
|
|
48
|
+
summary: string;
|
|
49
|
+
id?: string;
|
|
50
|
+
} | {
|
|
51
|
+
$type: 'truncated';
|
|
52
|
+
originalType: string;
|
|
53
|
+
summary: string;
|
|
54
|
+
byteLength?: number;
|
|
55
|
+
};
|
|
56
|
+
export interface ValueCodecOptions {
|
|
57
|
+
maxDepth?: number;
|
|
58
|
+
maxBytes?: number;
|
|
59
|
+
maxArrayLength?: number;
|
|
60
|
+
rootPath?: string[];
|
|
61
|
+
redactedKeys?: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
export declare class ValueCodec {
|
|
64
|
+
private defaultOptions;
|
|
65
|
+
constructor(defaultOptions?: ValueCodecOptions);
|
|
66
|
+
encode(value: unknown, options?: ValueCodecOptions): EncodedValue;
|
|
67
|
+
private _encodeValue;
|
|
68
|
+
decode(encoded: EncodedValue): any;
|
|
69
|
+
}
|
|
70
|
+
export declare const defaultValueCodec: ValueCodec;
|
|
71
|
+
export declare function fnv1a32(str: string): string;
|
|
72
|
+
export interface StateDelta {
|
|
73
|
+
readonly ordinal: number;
|
|
74
|
+
readonly field: string;
|
|
75
|
+
readonly before: EncodedValue;
|
|
76
|
+
readonly after: EncodedValue;
|
|
77
|
+
}
|
|
78
|
+
export interface NodeStateSnapshot {
|
|
79
|
+
readonly nodeId: string;
|
|
80
|
+
readonly factoryKey: string;
|
|
81
|
+
readonly state: EncodedValue;
|
|
82
|
+
readonly globalVersion: number;
|
|
83
|
+
readonly regionVersions: Record<string, number>;
|
|
84
|
+
}
|
|
85
|
+
export interface StateSnapshot {
|
|
86
|
+
readonly snapshotId: string;
|
|
87
|
+
readonly traceId: TraceId;
|
|
88
|
+
readonly runId: RunId;
|
|
89
|
+
readonly capturedAt: number;
|
|
90
|
+
readonly reason: 'initial' | 'mounted' | 'checkpoint' | 'manual';
|
|
91
|
+
readonly nodes: NodeStateSnapshot[];
|
|
92
|
+
}
|
|
93
|
+
export interface TraceEventBase {
|
|
94
|
+
readonly schemaVersion: typeof traceSchemaVersion;
|
|
95
|
+
readonly traceId: TraceId;
|
|
96
|
+
readonly runId: RunId;
|
|
97
|
+
readonly eventId: EventId;
|
|
98
|
+
readonly sequence: number;
|
|
99
|
+
readonly timestamp: number;
|
|
100
|
+
}
|
|
101
|
+
export type TraceEventPayload = {
|
|
102
|
+
type: 'TraceStarted';
|
|
103
|
+
graphFingerprint?: string;
|
|
104
|
+
runtimeVersion: string;
|
|
105
|
+
} | {
|
|
106
|
+
type: 'GraphMounted';
|
|
107
|
+
nodeIds: string[];
|
|
108
|
+
nodeFactories: Record<string, string>;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'StateSnapshotCaptured';
|
|
111
|
+
snapshot: StateSnapshot;
|
|
112
|
+
} | {
|
|
113
|
+
type: 'StateSnapshotRestored';
|
|
114
|
+
snapshotId: string;
|
|
115
|
+
nodeIds: string[];
|
|
116
|
+
} | {
|
|
117
|
+
type: 'InfoEmitted';
|
|
118
|
+
envelope: InfoEnvelope;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'InfoDelivered';
|
|
121
|
+
envelope: InfoEnvelope;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'BoundaryOutputCaptured';
|
|
124
|
+
fragmentId: string;
|
|
125
|
+
envelope: InfoEnvelope;
|
|
126
|
+
} | {
|
|
127
|
+
type: 'FragmentBoundaryViolation';
|
|
128
|
+
fragmentId: string;
|
|
129
|
+
sourceNodeId: string;
|
|
130
|
+
targetNodeId: string;
|
|
131
|
+
infoType: string;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'ChangeStarted';
|
|
134
|
+
changeId: string;
|
|
135
|
+
nodeId: string;
|
|
136
|
+
causeInfoId: string;
|
|
137
|
+
causeInfoType: string;
|
|
138
|
+
stateVersionBefore: number;
|
|
139
|
+
} | {
|
|
140
|
+
type: 'StateDeltaCommitted';
|
|
141
|
+
changeId: string;
|
|
142
|
+
nodeId: string;
|
|
143
|
+
stateVersionAfter: number;
|
|
144
|
+
deltas: StateDelta[];
|
|
145
|
+
} | {
|
|
146
|
+
type: 'EffectRequested';
|
|
147
|
+
effectId: string;
|
|
148
|
+
changeId: string;
|
|
149
|
+
nodeId: string;
|
|
150
|
+
name?: string;
|
|
151
|
+
adapterId?: string;
|
|
152
|
+
requestRef?: string;
|
|
153
|
+
} | {
|
|
154
|
+
type: 'WorldEffectRejected';
|
|
155
|
+
fragmentId: string;
|
|
156
|
+
effectId: string;
|
|
157
|
+
changeId: string;
|
|
158
|
+
nodeId: string;
|
|
159
|
+
name?: string;
|
|
160
|
+
adapterId?: string;
|
|
161
|
+
requestRef?: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: 'EffectObserved';
|
|
164
|
+
effectId: string;
|
|
165
|
+
changeId: string;
|
|
166
|
+
nodeId: string;
|
|
167
|
+
name?: string;
|
|
168
|
+
status: 'succeeded' | 'failed';
|
|
169
|
+
adapterId?: string;
|
|
170
|
+
requestRef?: string;
|
|
171
|
+
observationRef?: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: 'ChangeCompleted';
|
|
174
|
+
record: ChangeRecord;
|
|
175
|
+
} | {
|
|
176
|
+
type: 'TraceCompleted';
|
|
177
|
+
status: 'completed' | 'failed';
|
|
178
|
+
error?: string;
|
|
179
|
+
};
|
|
180
|
+
export type TraceEvent = TraceEventBase & TraceEventPayload;
|
|
181
|
+
export interface TraceStore {
|
|
182
|
+
append(event: TraceEvent): Promise<void> | void;
|
|
183
|
+
getEvents?(traceId?: string): Promise<TraceEvent[]> | TraceEvent[];
|
|
184
|
+
}
|
|
185
|
+
export declare class MemoryTraceStore implements TraceStore {
|
|
186
|
+
private events;
|
|
187
|
+
append(event: TraceEvent): void;
|
|
188
|
+
getEvents(): TraceEvent[];
|
|
189
|
+
clear(): void;
|
|
190
|
+
}
|
|
191
|
+
export declare class TraceSession {
|
|
192
|
+
readonly traceId: string;
|
|
193
|
+
readonly runId: string;
|
|
194
|
+
private idProvider;
|
|
195
|
+
private clock;
|
|
196
|
+
private traceStore?;
|
|
197
|
+
sequence: number;
|
|
198
|
+
readonly events: TraceEvent[];
|
|
199
|
+
readonly records: ChangeRecord[];
|
|
200
|
+
constructor(traceId: string, runId: string, idProvider: IdProvider, clock: Clock, traceStore?: TraceStore | undefined);
|
|
201
|
+
record(payload: TraceEventPayload): TraceEvent;
|
|
202
|
+
recordChange(record: ChangeRecord): void;
|
|
203
|
+
}
|
|
204
|
+
export declare function applyStateDeltas(encodedState: EncodedValue, deltas: readonly StateDelta[]): EncodedValue;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Node } from './node';
|
|
2
|
+
import type { Info, InfoEnvelope, ChangeRecord, Probe, GraphProjection, InjectionResult } from './types';
|
|
3
|
+
import type { Clock, IdProvider, RandomSource, ValueCodec, ValueCodecOptions, TraceStore, RuntimeIdKind, StateSnapshot, EncodedValue, TraceEvent } from './observation';
|
|
4
|
+
import { TraceSession } from './observation';
|
|
5
|
+
import type { KernelSchedulerSnapshot } from './scheduler';
|
|
6
|
+
import type { KernelDeliveryOptions } from './delivery';
|
|
7
|
+
export interface KernelRuntimeOptions {
|
|
8
|
+
clock?: Clock;
|
|
9
|
+
idProvider?: IdProvider;
|
|
10
|
+
randomSource?: RandomSource;
|
|
11
|
+
valueCodec?: ValueCodec;
|
|
12
|
+
valueCodecOptions?: ValueCodecOptions;
|
|
13
|
+
traceStore?: TraceStore;
|
|
14
|
+
stateSnapshots?: {
|
|
15
|
+
captureInitial?: boolean;
|
|
16
|
+
everyChanges?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Pure In-Process Kernel Runtime Execution Engine
|
|
21
|
+
*/
|
|
22
|
+
export declare class KernelRuntime {
|
|
23
|
+
readonly nodes: Map<string, Node<any>>;
|
|
24
|
+
readonly envelopes: InfoEnvelope[];
|
|
25
|
+
readonly probes: Probe[];
|
|
26
|
+
readonly clock: Clock;
|
|
27
|
+
readonly idProvider: IdProvider;
|
|
28
|
+
readonly randomSource: RandomSource;
|
|
29
|
+
readonly valueCodec: ValueCodec;
|
|
30
|
+
readonly valueCodecOptions: ValueCodecOptions;
|
|
31
|
+
readonly traceStore?: TraceStore;
|
|
32
|
+
readonly traceSession: TraceSession;
|
|
33
|
+
logicalClock: number;
|
|
34
|
+
pendingDeliveryCount: number;
|
|
35
|
+
activeChangeIds: Set<string>;
|
|
36
|
+
scheduledGraphMicrotaskCount: number;
|
|
37
|
+
schedulerListeners: Set<(state: KernelSchedulerSnapshot) => void>;
|
|
38
|
+
scheduledMailboxNodeIds: Set<string>;
|
|
39
|
+
projectionListeners: Set<(projection: GraphProjection) => void>;
|
|
40
|
+
projectionRevision: number;
|
|
41
|
+
private readonly submissions;
|
|
42
|
+
captureInitialStateSnapshot: boolean;
|
|
43
|
+
initialStateSnapshotCaptured: boolean;
|
|
44
|
+
private isDisposed;
|
|
45
|
+
constructor(options?: KernelRuntimeOptions);
|
|
46
|
+
now(): number;
|
|
47
|
+
monotonicNow(): number;
|
|
48
|
+
nextId(kind: RuntimeIdKind): string;
|
|
49
|
+
mount(...nodes: Node<any>[]): this;
|
|
50
|
+
unmount(...nodeIds: string[]): this;
|
|
51
|
+
getNode<T extends Node<any> = Node<any>>(id: string): T | undefined;
|
|
52
|
+
getNodes(): Node<any>[];
|
|
53
|
+
/** @internal Called only by a Node's active ChangeContext. */
|
|
54
|
+
_deliverSendFromChange(source: Node<any>, info: Info, target: Node<any> | string, options?: KernelDeliveryOptions): void;
|
|
55
|
+
injectRootInfo(target: Node<any>, info: Info, options?: {
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
submissionId?: string;
|
|
58
|
+
}): string;
|
|
59
|
+
inject(input: {
|
|
60
|
+
submissionId: string;
|
|
61
|
+
targetNodeId: string;
|
|
62
|
+
info: Info;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}): Promise<InjectionResult>;
|
|
65
|
+
cancel(submissionId: string): boolean;
|
|
66
|
+
waitForSubmission(submissionId: string): Promise<void>;
|
|
67
|
+
trackSubmissionDeliveryEnqueued(submissionId?: string): void;
|
|
68
|
+
trackSubmissionDeliverySettled(submissionId?: string, error?: unknown): void;
|
|
69
|
+
snapshot(): StateSnapshot;
|
|
70
|
+
publishSchedulerState(): void;
|
|
71
|
+
readProjection(): GraphProjection;
|
|
72
|
+
subscribeProjection(listener: (projection: GraphProjection) => void): () => void;
|
|
73
|
+
publishProjection(): void;
|
|
74
|
+
getSchedulerSnapshot(): KernelSchedulerSnapshot;
|
|
75
|
+
subscribeScheduler(listener: (state: KernelSchedulerSnapshot) => void): () => void;
|
|
76
|
+
scheduleMicrotask<T>(task: () => T | Promise<T>): Promise<T>;
|
|
77
|
+
waitForQuiescence(options?: {
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}): Promise<KernelSchedulerSnapshot>;
|
|
80
|
+
captureStateSnapshot(reason?: StateSnapshot['reason'], nodeIds?: readonly string[]): StateSnapshot;
|
|
81
|
+
restoreStateSnapshot(snapshot: StateSnapshot): void;
|
|
82
|
+
ensureInitialStateSnapshot(): void;
|
|
83
|
+
encodeTraceValue(nodeId: string, field: string, value: unknown): EncodedValue;
|
|
84
|
+
recordValueRef(kind: string, value: unknown): string;
|
|
85
|
+
beginChangeExecution(changeId: string): void;
|
|
86
|
+
endChangeExecution(changeId: string): void;
|
|
87
|
+
recordChangeStarted(input: {
|
|
88
|
+
changeId: string;
|
|
89
|
+
nodeId: string;
|
|
90
|
+
causeInfoId: string;
|
|
91
|
+
causeInfoType: string;
|
|
92
|
+
stateVersionBefore: number;
|
|
93
|
+
}): void;
|
|
94
|
+
get causalRecords(): readonly ChangeRecord[];
|
|
95
|
+
get events(): readonly TraceEvent[];
|
|
96
|
+
recordChange(record: ChangeRecord): void;
|
|
97
|
+
recordEffectRequested(input: {
|
|
98
|
+
effectId: string;
|
|
99
|
+
changeId: string;
|
|
100
|
+
nodeId: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
adapterId?: string;
|
|
103
|
+
requestRef?: string;
|
|
104
|
+
}): void;
|
|
105
|
+
recordEffectObserved(input: {
|
|
106
|
+
effectId: string;
|
|
107
|
+
changeId: string;
|
|
108
|
+
nodeId: string;
|
|
109
|
+
name?: string;
|
|
110
|
+
status: 'succeeded' | 'failed';
|
|
111
|
+
adapterId?: string;
|
|
112
|
+
requestRef?: string;
|
|
113
|
+
observationRef?: string;
|
|
114
|
+
}): void;
|
|
115
|
+
addProbe(probe: Probe): this;
|
|
116
|
+
removeProbe(probe: Probe): this;
|
|
117
|
+
dispose(): Promise<void>;
|
|
118
|
+
private createSubmission;
|
|
119
|
+
private settleSubmissionIfComplete;
|
|
120
|
+
}
|
|
121
|
+
export declare function createKernelRuntime(options?: KernelRuntimeOptions): KernelRuntime;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface KernelSchedulerSnapshot {
|
|
2
|
+
readonly pendingDeliveries: number;
|
|
3
|
+
readonly activeChanges: number;
|
|
4
|
+
readonly scheduledGraphMicrotasks: number;
|
|
5
|
+
readonly isQuiescent: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function schedulerCancellationError(signal: AbortSignal): Error;
|
|
8
|
+
export interface SchedulerKernelContext {
|
|
9
|
+
pendingDeliveryCount: number;
|
|
10
|
+
activeChangeIds: Set<string>;
|
|
11
|
+
scheduledGraphMicrotaskCount: number;
|
|
12
|
+
schedulerListeners: Set<(state: KernelSchedulerSnapshot) => void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function computeSchedulerSnapshot(ctx: SchedulerKernelContext): KernelSchedulerSnapshot;
|
|
15
|
+
export declare function subscribeSchedulerHelper(ctx: SchedulerKernelContext, listener: (state: KernelSchedulerSnapshot) => void): () => void;
|
|
16
|
+
export declare function publishSchedulerStateHelper(ctx: SchedulerKernelContext): void;
|
|
17
|
+
export declare function scheduleGraphMicrotaskHelper<T>(ctx: SchedulerKernelContext, task: () => T | Promise<T>): Promise<T>;
|
|
18
|
+
export declare function waitForQuiescenceHelper(ctx: SchedulerKernelContext, options?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<KernelSchedulerSnapshot>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Node } from './node';
|
|
2
|
+
import type { StateSnapshot, EncodedValue, ValueCodec, ValueCodecOptions, TraceSession, RuntimeIdKind } from './observation';
|
|
3
|
+
export { applyStateDeltas } from './observation';
|
|
4
|
+
export interface SnapshotKernelContext {
|
|
5
|
+
nodes: Map<string, Node<any>>;
|
|
6
|
+
valueCodec: ValueCodec;
|
|
7
|
+
valueCodecOptions: ValueCodecOptions;
|
|
8
|
+
traceSession: TraceSession;
|
|
9
|
+
now(): number;
|
|
10
|
+
nextId(kind: RuntimeIdKind): string;
|
|
11
|
+
}
|
|
12
|
+
export declare function encodeTraceValueHelper(ctx: SnapshotKernelContext, nodeId: string, field: string, value: unknown): EncodedValue;
|
|
13
|
+
export declare function captureStateSnapshotHelper(ctx: SnapshotKernelContext, reason?: StateSnapshot['reason'], nodeIds?: readonly string[]): StateSnapshot;
|
|
14
|
+
export declare function restoreStateSnapshotHelper(ctx: SnapshotKernelContext, snapshot: StateSnapshot): void;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Kernel Types & DTOs
|
|
3
|
+
*/
|
|
4
|
+
export interface Info {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface InfoEnvelope<TInfo = Info> {
|
|
9
|
+
readonly infoId: string;
|
|
10
|
+
readonly senderNodeId: string;
|
|
11
|
+
readonly targetNodeId: string;
|
|
12
|
+
readonly causedByChangeId?: string;
|
|
13
|
+
readonly causeInfoId?: string;
|
|
14
|
+
readonly submissionId?: string;
|
|
15
|
+
readonly sequence: number;
|
|
16
|
+
readonly timestamp: number;
|
|
17
|
+
readonly payload: TInfo;
|
|
18
|
+
}
|
|
19
|
+
export interface SpanRecord {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly durationMs: number;
|
|
22
|
+
readonly timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ChangeRecord {
|
|
25
|
+
readonly changeId: string;
|
|
26
|
+
readonly nodeId: string;
|
|
27
|
+
readonly causeInfoId: string;
|
|
28
|
+
readonly causeInfoType: string;
|
|
29
|
+
readonly causedByChangeId?: string;
|
|
30
|
+
readonly stateVersionBefore: number;
|
|
31
|
+
readonly stateVersionAfter: number;
|
|
32
|
+
readonly reads: string[];
|
|
33
|
+
readonly writes: string[];
|
|
34
|
+
readonly stateDeltas?: import('./observation').StateDelta[];
|
|
35
|
+
readonly spans: SpanRecord[];
|
|
36
|
+
readonly durationMs: number;
|
|
37
|
+
readonly timestamp: number;
|
|
38
|
+
readonly error?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface DomainChangeContext<S = any> {
|
|
41
|
+
read<K extends keyof S>(key: K): S[K];
|
|
42
|
+
write<K extends keyof S>(key: K, value: S[K]): void;
|
|
43
|
+
patchState(patch: Partial<S>): void;
|
|
44
|
+
send(info: Info, targetNodeId: string): void;
|
|
45
|
+
span<T>(name: string, action: () => Promise<T> | T): Promise<T>;
|
|
46
|
+
}
|
|
47
|
+
export interface WorldChangeContext<S = any> extends DomainChangeContext<S> {
|
|
48
|
+
effectAdapter<Request, Observation>(adapter: import('./effects').EffectAdapter<Request, Observation>, request: Request, options?: {
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): Promise<Observation>;
|
|
51
|
+
}
|
|
52
|
+
export type ChangeContext<S = any> = DomainChangeContext<S>;
|
|
53
|
+
export interface Probe {
|
|
54
|
+
onTraceEvent?(event: import('./observation').TraceEvent): void;
|
|
55
|
+
onChangeRecord?(record: ChangeRecord): void;
|
|
56
|
+
}
|
|
57
|
+
export interface GraphProjectionNode {
|
|
58
|
+
readonly nodeId: string;
|
|
59
|
+
readonly state: any;
|
|
60
|
+
readonly version: number;
|
|
61
|
+
readonly status?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface GraphProjection {
|
|
64
|
+
readonly revision: number;
|
|
65
|
+
readonly nodes: GraphProjectionNode[];
|
|
66
|
+
readonly scheduler: {
|
|
67
|
+
readonly pendingDeliveries: number;
|
|
68
|
+
readonly activeChanges: number;
|
|
69
|
+
readonly scheduledGraphMicrotasks: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface InjectionResult {
|
|
73
|
+
readonly status: 'accepted' | 'rejected';
|
|
74
|
+
readonly submissionId: string;
|
|
75
|
+
readonly reason?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface GraphSyscallRequestMap {
|
|
78
|
+
'graph.injectRootInfo': {
|
|
79
|
+
input: {
|
|
80
|
+
targetNodeId: string;
|
|
81
|
+
info: Info;
|
|
82
|
+
submissionId?: string;
|
|
83
|
+
};
|
|
84
|
+
output: InjectionResult & {
|
|
85
|
+
projection: GraphProjection;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
'graph.cancel': {
|
|
89
|
+
input: {
|
|
90
|
+
submissionId: string;
|
|
91
|
+
};
|
|
92
|
+
output: {
|
|
93
|
+
cancelled: boolean;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
'graph.projection.read': {
|
|
97
|
+
input: Record<string, never>;
|
|
98
|
+
output: {
|
|
99
|
+
projection: GraphProjection;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export interface GraphSyscallEventMap {
|
|
104
|
+
'graph.projection.updated': {
|
|
105
|
+
projection: GraphProjection;
|
|
106
|
+
};
|
|
107
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphvideo/kernel",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zero-business-semantics causal graph microkernel for GraphFramework",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git@github.com:vd249175-cpu/GSDK.git",
|
|
13
|
+
"directory": "kernel"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./effect-harness": {
|
|
21
|
+
"types": "./dist/effect-harness.d.ts",
|
|
22
|
+
"import": "./dist/effect-harness.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
]
|
|
28
|
+
}
|