@maelstrom-co/react 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/_testing.d.ts +13 -0
- package/dist/_testing.d.ts.map +1 -0
- package/dist/_testing.js +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6181 -0
- package/dist/lib/build-execute-action.d.ts +9 -0
- package/dist/lib/build-execute-action.d.ts.map +1 -0
- package/dist/lib/chart/chart.d.ts +14 -0
- package/dist/lib/chart/chart.d.ts.map +1 -0
- package/dist/lib/chart/error-boundary.d.ts +17 -0
- package/dist/lib/chart/error-boundary.d.ts.map +1 -0
- package/dist/lib/chart/loading.d.ts +14 -0
- package/dist/lib/chart/loading.d.ts.map +1 -0
- package/dist/lib/chart/motion/flip.d.ts +18 -0
- package/dist/lib/chart/motion/flip.d.ts.map +1 -0
- package/dist/lib/chart/motion/measure.d.ts +8 -0
- package/dist/lib/chart/motion/measure.d.ts.map +1 -0
- package/dist/lib/chart/motion/motion-config.d.ts +27 -0
- package/dist/lib/chart/motion/motion-config.d.ts.map +1 -0
- package/dist/lib/chart/motion/use-chart-motion.d.ts +7 -0
- package/dist/lib/chart/motion/use-chart-motion.d.ts.map +1 -0
- package/dist/lib/chart/motion/use-exiting-instances.d.ts +9 -0
- package/dist/lib/chart/motion/use-exiting-instances.d.ts.map +1 -0
- package/dist/lib/config-types.d.ts +29 -0
- package/dist/lib/config-types.d.ts.map +1 -0
- package/dist/lib/context.d.ts +42 -0
- package/dist/lib/context.d.ts.map +1 -0
- package/dist/lib/create-maelstrom.d.ts +39 -0
- package/dist/lib/create-maelstrom.d.ts.map +1 -0
- package/dist/lib/dynamic-vessel-types.d.ts +57 -0
- package/dist/lib/dynamic-vessel-types.d.ts.map +1 -0
- package/dist/lib/extension-types.d.ts +58 -0
- package/dist/lib/extension-types.d.ts.map +1 -0
- package/dist/lib/maelstrom-instance-types.d.ts +228 -0
- package/dist/lib/maelstrom-instance-types.d.ts.map +1 -0
- package/dist/lib/maelstrom-state-types.d.ts +30 -0
- package/dist/lib/maelstrom-state-types.d.ts.map +1 -0
- package/dist/lib/provider.d.ts +135 -0
- package/dist/lib/provider.d.ts.map +1 -0
- package/dist/lib/register-vessel.d.ts +13 -0
- package/dist/lib/register-vessel.d.ts.map +1 -0
- package/dist/lib/require-context.d.ts +9 -0
- package/dist/lib/require-context.d.ts.map +1 -0
- package/dist/lib/update-vessel.d.ts +21 -0
- package/dist/lib/update-vessel.d.ts.map +1 -0
- package/dist/lib/use-actions.d.ts +19 -0
- package/dist/lib/use-actions.d.ts.map +1 -0
- package/dist/lib/use-instance.d.ts +11 -0
- package/dist/lib/use-instance.d.ts.map +1 -0
- package/dist/lib/use-intent-submission.d.ts +8 -0
- package/dist/lib/use-intent-submission.d.ts.map +1 -0
- package/dist/lib/use-latest-ref.d.ts +4 -0
- package/dist/lib/use-latest-ref.d.ts.map +1 -0
- package/dist/lib/use-maelstrom.d.ts +7 -0
- package/dist/lib/use-maelstrom.d.ts.map +1 -0
- package/dist/lib/use-store-selector.d.ts +17 -0
- package/dist/lib/use-store-selector.d.ts.map +1 -0
- package/dist/lib/use-vessel-core.d.ts +18 -0
- package/dist/lib/use-vessel-core.d.ts.map +1 -0
- package/dist/lib/use-vessel.d.ts +7 -0
- package/dist/lib/use-vessel.d.ts.map +1 -0
- package/dist/lib/vessel-entry-types.d.ts +170 -0
- package/dist/lib/vessel-entry-types.d.ts.map +1 -0
- package/dist/lib/vessel.d.ts +10 -0
- package/dist/lib/vessel.d.ts.map +1 -0
- package/dist/lib/warn-once.d.ts +23 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/warn-once-Cq9ShMdA.js +10 -0
- package/package.json +83 -4
- package/skills/maelstrom-react-sdk/SKILL.md +29 -0
- package/skills/maelstrom-react-sdk/references/common-tasks.md +146 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Orchestrator } from '@maelstrom-co/client';
|
|
2
|
+
import { InstanceId } from '@maelstrom-co/protocol';
|
|
3
|
+
import { MutableRefObject } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Builds the `executeAction` callback injected into vessel components — a
|
|
6
|
+
* client-authoritative dispatch through `Orchestrator.invokeAction`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildExecuteAction(orchestrator: Orchestrator, instanceId: InstanceId, debug: boolean, onErrorRef: MutableRefObject<((error: Error) => void) | undefined>): (name: string, params?: Record<string, unknown>) => void;
|
|
9
|
+
//# sourceMappingURL=build-execute-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-execute-action.d.ts","sourceRoot":"","sources":["../../src/lib/build-execute-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,GACjE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAa1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType, CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import { MaelstromContextPair } from '../context.js';
|
|
3
|
+
/** Props for the `m.Chart` layout component. */
|
|
4
|
+
export interface ChartProps {
|
|
5
|
+
/** CSS class name applied to the chart container. */
|
|
6
|
+
className?: string | undefined;
|
|
7
|
+
/** Additional styles merged onto the chart container (layout-critical properties cannot be overridden). */
|
|
8
|
+
style?: CSSProperties | undefined;
|
|
9
|
+
/** Slot content rendered inside the chart container alongside vessels. */
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/** Create the Chart component bound to a Maelstrom context. Internal — called by `createMaelstrom()`. */
|
|
13
|
+
export declare function createChart(contextPair: MaelstromContextPair): ComponentType<ChartProps>;
|
|
14
|
+
//# sourceMappingURL=chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.d.ts","sourceRoot":"","sources":["../../../src/lib/chart/chart.tsx"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGlB,KAAK,SAAS,EAOf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAkE1D,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,2GAA2G;IAC3G,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAClC,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,yGAAyG;AACzG,wBAAgB,WAAW,CACzB,WAAW,EAAE,oBAAoB,GAChC,aAAa,CAAC,UAAU,CAAC,CA6pB3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Component, ErrorInfo, ReactNode } from 'react';
|
|
2
|
+
interface ErrorBoundaryProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
fallback: (error: Error) => ReactNode;
|
|
5
|
+
onError?: ((error: Error, errorInfo: ErrorInfo) => void) | undefined;
|
|
6
|
+
}
|
|
7
|
+
interface ErrorBoundaryState {
|
|
8
|
+
error: Error | null;
|
|
9
|
+
}
|
|
10
|
+
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
11
|
+
constructor(props: ErrorBoundaryProps);
|
|
12
|
+
static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
|
|
13
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
14
|
+
render(): ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=error-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/lib/chart/error-boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElE,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACtE;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,qBAAa,aAAc,SAAQ,SAAS,CAC1C,kBAAkB,EAClB,kBAAkB,CACnB;gBACa,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAI3D,MAAM,IAAI,SAAS;CAM7B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { VesselId } from '@maelstrom-co/protocol';
|
|
2
|
+
export interface VesselLoadingSkeletonProps {
|
|
3
|
+
vesselId: VesselId;
|
|
4
|
+
vesselName?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare function VesselLoadingSkeleton({ vesselId, vesselName, }: VesselLoadingSkeletonProps): import("react").JSX.Element;
|
|
7
|
+
export interface VesselLoadErrorProps {
|
|
8
|
+
vesselId: VesselId;
|
|
9
|
+
error: Error;
|
|
10
|
+
debug?: boolean | undefined;
|
|
11
|
+
retry?: (() => void) | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function VesselLoadError({ vesselId, error, debug, retry, }: VesselLoadErrorProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=loading.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading.d.ts","sourceRoot":"","sources":["../../../src/lib/chart/loading.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,UAAU,GACX,EAAE,0BAA0B,+BAmD5B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,KAAK,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,GACN,EAAE,oBAAoB,+BAkDtB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface MotionRect {
|
|
2
|
+
readonly x: number;
|
|
3
|
+
readonly y: number;
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface FlipDelta {
|
|
8
|
+
readonly dx: number;
|
|
9
|
+
readonly dy: number;
|
|
10
|
+
readonly sx: number;
|
|
11
|
+
readonly sy: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function computeFlipDelta(prev: MotionRect, next: MotionRect): FlipDelta | null;
|
|
14
|
+
export declare function flipKeyframes(delta: FlipDelta): Keyframe[];
|
|
15
|
+
export declare function enterKeyframes(): Keyframe[];
|
|
16
|
+
export declare function exitKeyframes(): Keyframe[];
|
|
17
|
+
export declare function staggerOrder(rects: ReadonlyArray<readonly [string, MotionRect]>): string[];
|
|
18
|
+
//# sourceMappingURL=flip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../../../src/lib/chart/motion/flip.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAOD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,GACf,SAAS,GAAG,IAAI,CAelB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,EAAE,CAQ1D;AAED,wBAAgB,cAAc,IAAI,QAAQ,EAAE,CAK3C;AAED,wBAAgB,aAAa,IAAI,QAAQ,EAAE,CAK1C;AASD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAClD,MAAM,EAAE,CASV"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MotionRect } from './flip.js';
|
|
2
|
+
export interface MeasuredInstance {
|
|
3
|
+
readonly node: HTMLElement;
|
|
4
|
+
readonly rect: MotionRect;
|
|
5
|
+
}
|
|
6
|
+
export declare function measureInstances(container: HTMLElement): Map<string, MeasuredInstance>;
|
|
7
|
+
export declare function measureInstanceRects(container: HTMLElement): Map<string, MotionRect>;
|
|
8
|
+
//# sourceMappingURL=measure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../../src/lib/chart/motion/measure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B;AAYD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,GACrB,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAoB/B;AAKD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,WAAW,GACrB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAIzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choreography settings for Chart layout changes. All motion honors
|
|
3
|
+
* `prefers-reduced-motion: reduce` regardless of these values — the media
|
|
4
|
+
* preference always wins over configuration.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChartMotionConfig {
|
|
7
|
+
/** Move/resize + enter/exit duration in ms. Default 350. */
|
|
8
|
+
readonly durationMs?: number;
|
|
9
|
+
/** CSS easing for all chart animations. Default 'cubic-bezier(0.22, 1, 0.36, 1)'. */
|
|
10
|
+
readonly easing?: string;
|
|
11
|
+
/** Per-vessel delay in reading order for enter/move waves. Default 30. */
|
|
12
|
+
readonly staggerMs?: number;
|
|
13
|
+
/** Disables all chart motion when true. Default false. */
|
|
14
|
+
readonly disabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ResolvedChartMotionConfig {
|
|
17
|
+
readonly durationMs: number;
|
|
18
|
+
readonly easing: string;
|
|
19
|
+
readonly staggerMs: number;
|
|
20
|
+
readonly disabled: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const EXIT_CLEANUP_BUFFER_MS = 100;
|
|
23
|
+
export declare const DEFAULT_MOTION: ResolvedChartMotionConfig;
|
|
24
|
+
export declare function resolveMotionConfig(config: ChartMotionConfig | undefined): ResolvedChartMotionConfig;
|
|
25
|
+
/** True when motion must not run: disabled by config or by the user's OS preference. */
|
|
26
|
+
export declare function motionSuppressed(resolved: ResolvedChartMotionConfig): boolean;
|
|
27
|
+
//# sourceMappingURL=motion-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion-config.d.ts","sourceRoot":"","sources":["../../../../src/lib/chart/motion/motion-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAKD,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,eAAO,MAAM,cAAc,EAAE,yBAK5B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GAAG,SAAS,GACpC,yBAAyB,CAwB3B;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,OAAO,CAK7E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { ResolvedChartMotionConfig } from './motion-config.js';
|
|
3
|
+
export declare function useChartMotion(containerRef: RefObject<HTMLElement | null>, keys: {
|
|
4
|
+
layoutKey: string;
|
|
5
|
+
sizeKey: string;
|
|
6
|
+
}, motion: ResolvedChartMotionConfig): void;
|
|
7
|
+
//# sourceMappingURL=use-chart-motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-chart-motion.d.ts","sourceRoot":"","sources":["../../../../src/lib/chart/motion/use-chart-motion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AASpE,wBAAgB,cAAc,CAC5B,YAAY,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAC3C,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC5C,MAAM,EAAE,yBAAyB,GAChC,IAAI,CAyHN"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MotionRect } from './flip.js';
|
|
2
|
+
import { ResolvedChartMotionConfig } from './motion-config.js';
|
|
3
|
+
export interface ExitingEntry<T> {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly item: T;
|
|
6
|
+
readonly rect: MotionRect;
|
|
7
|
+
}
|
|
8
|
+
export declare function useExitingInstances<T>(current: ReadonlyArray<readonly [string, T]>, measureRects: () => ReadonlyMap<string, MotionRect>, motion: ResolvedChartMotionConfig, signature: string): ReadonlyArray<ExitingEntry<T>>;
|
|
9
|
+
//# sourceMappingURL=use-exiting-instances.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-exiting-instances.d.ts","sourceRoot":"","sources":["../../../../src/lib/chart/motion/use-exiting-instances.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAGpE,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B;AAeD,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAC5C,YAAY,EAAE,MAAM,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EACnD,MAAM,EAAE,yBAAyB,EACjC,SAAS,EAAE,MAAM,GAChB,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAwJhC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IntentQueueOptions } from '@maelstrom-co/client';
|
|
2
|
+
import { ChartMotionConfig, ResolvedChartMotionConfig } from './chart/motion/motion-config.js';
|
|
3
|
+
/** Resolved config after merging factory defaults + Provider overrides */
|
|
4
|
+
export interface ResolvedMaelstromConfig {
|
|
5
|
+
/** Client queue policy captured when the Provider mounts; later changes are ignored. */
|
|
6
|
+
intentQueue?: IntentQueueOptions;
|
|
7
|
+
cellSizePx: number;
|
|
8
|
+
tilingPaddingPx: number;
|
|
9
|
+
debug: boolean;
|
|
10
|
+
motion: ResolvedChartMotionConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Overrides accepted at the factory (createMaelstrom) or Provider seam.
|
|
14
|
+
* `motion` is unresolved here — its leaf fields are all optional, unlike
|
|
15
|
+
* `ResolvedMaelstromConfig.motion` where every field is required.
|
|
16
|
+
*/
|
|
17
|
+
export type ConfigOverrides = Partial<Omit<ResolvedMaelstromConfig, 'motion'>> & {
|
|
18
|
+
motion?: ChartMotionConfig;
|
|
19
|
+
};
|
|
20
|
+
/** Default config values */
|
|
21
|
+
export declare const CONFIG_DEFAULTS: {
|
|
22
|
+
readonly cellSizePx: 80;
|
|
23
|
+
readonly tilingPaddingPx: 8;
|
|
24
|
+
readonly debug: false;
|
|
25
|
+
readonly motion: ResolvedChartMotionConfig;
|
|
26
|
+
};
|
|
27
|
+
/** Resolve config with priority: provider overrides > factory defaults > hardcoded defaults */
|
|
28
|
+
export declare function resolveConfig(factory: ConfigOverrides, provider: ConfigOverrides): ResolvedMaelstromConfig;
|
|
29
|
+
//# sourceMappingURL=config-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../../src/lib/config-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAMzC,0EAA0E;AAC1E,MAAM,WAAW,uBAAuB;IACtC,wFAAwF;IACxF,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,CACnC,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CACxC,GAAG;IACF,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,4BAA4B;AAC5B,eAAO,MAAM,eAAe;;;;;CAKgB,CAAC;AAE7C,+FAA+F;AAC/F,wBAAgB,aAAa,CAC3B,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,eAAe,GACxB,uBAAuB,CAwBzB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EngineConnector, Orchestrator } from '@maelstrom-co/client';
|
|
2
|
+
import { VesselId } from '@maelstrom-co/protocol';
|
|
3
|
+
import { ComponentType, MutableRefObject } from 'react';
|
|
4
|
+
import { ResolvedMaelstromConfig } from './config-types.js';
|
|
5
|
+
import { LazyVesselComponentLoader, TypedVesselProps } from './vessel-entry-types.js';
|
|
6
|
+
export interface MaelstromContextValue {
|
|
7
|
+
orchestrator: Orchestrator;
|
|
8
|
+
connector: EngineConnector;
|
|
9
|
+
config: ResolvedMaelstromConfig;
|
|
10
|
+
/** Ref to onError callback from Provider props — allows hook to call it without re-renders */
|
|
11
|
+
onErrorRef: MutableRefObject<((error: Error) => void) | undefined>;
|
|
12
|
+
/** Maps vessel ID → React component */
|
|
13
|
+
componentRegistry: Map<VesselId, ComponentType<TypedVesselProps<any>>>;
|
|
14
|
+
/** Maps vessel ID → loading skeleton (for lazy vessels) */
|
|
15
|
+
loadingRegistry: Map<VesselId, ComponentType<{
|
|
16
|
+
vesselId: VesselId;
|
|
17
|
+
}>>;
|
|
18
|
+
/** Set of vessel IDs that are lazy-loaded */
|
|
19
|
+
lazyVesselIds: Set<VesselId>;
|
|
20
|
+
/**
|
|
21
|
+
* Raw lazy loader per vessel id. Chart wraps with React.lazy() locally on
|
|
22
|
+
* each render keyed by a retry counter, so the retry path can bust the
|
|
23
|
+
* cached rejected Promise. Mirrors lazyVesselIds — invariant: ids match.
|
|
24
|
+
*/
|
|
25
|
+
lazyLoaderRegistry: Map<VesselId, LazyVesselComponentLoader<any>>;
|
|
26
|
+
/** Guard: only one Chart may be mounted per Provider */
|
|
27
|
+
chartMountedRef: MutableRefObject<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/** Create a new per-factory React context */
|
|
30
|
+
export declare function createMaelstromContext(): {
|
|
31
|
+
readonly onOrchestrator: (attach: (orchestrator: Orchestrator) => () => void) => () => void;
|
|
32
|
+
readonly orchestratorObservers: Set<(orchestrator: Orchestrator) => () => void>;
|
|
33
|
+
readonly Context: import('react').Context<MaelstromContextValue | null>;
|
|
34
|
+
readonly useMaelstromContext: () => MaelstromContextValue;
|
|
35
|
+
readonly contextRef: MutableRefObject<MaelstromContextValue | null>;
|
|
36
|
+
};
|
|
37
|
+
export declare function createOrchestratorObservers(inherited?: Iterable<(orchestrator: Orchestrator) => () => void>): {
|
|
38
|
+
readonly onOrchestrator: (attach: (orchestrator: Orchestrator) => () => void) => () => void;
|
|
39
|
+
readonly orchestratorObservers: Set<(orchestrator: Orchestrator) => () => void>;
|
|
40
|
+
};
|
|
41
|
+
export type MaelstromContextPair = ReturnType<typeof createMaelstromContext>;
|
|
42
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,uBAAuB,CAAC;IAChC,8FAA8F;IAC9F,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACnE,uCAAuC;IAEvC,iBAAiB,EAAE,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvE,2DAA2D;IAC3D,eAAe,EAAE,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CAAC;IACtE,6CAA6C;IAC7C,aAAa,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B;;;;OAIG;IAEH,kBAAkB,EAAE,GAAG,CAAC,QAAQ,EAAE,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,wDAAwD;IACxD,eAAe,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED,6CAA6C;AAC7C,wBAAgB,sBAAsB;sCAgC1B,CAAC,YAAY,EAAE,YAAY,KAAK,MAAM,IAAI;uDAJjB,YAAY,KAAK,MAAM,IAAI;;wCAnB9B,qBAAqB;;EAgBtD;AAED,wBAAgB,2BAA2B,CACzC,SAAS,GAAE,QAAQ,CAAC,CAAC,YAAY,EAAE,YAAY,KAAK,MAAM,IAAI,CAAM;sCAI1D,CAAC,YAAY,EAAE,YAAY,KAAK,MAAM,IAAI;uDAJjB,YAAY,KAAK,MAAM,IAAI;EAgB/D;AAED,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IntentQueueOptions } from '@maelstrom-co/client';
|
|
2
|
+
import { ChartMotionConfig } from './chart/motion/motion-config.js';
|
|
3
|
+
import { MaelstromInstance } from './maelstrom-instance-types.js';
|
|
4
|
+
import { AnyVesselEntry } from './vessel-entry-types.js';
|
|
5
|
+
/** Compile-time guard: rejects entries where any vessel ID has widened to `string` */
|
|
6
|
+
type AssertNarrowIds<T extends readonly AnyVesselEntry[]> = string extends T[number]['vessel']['id'] ? 'Error: All vessel IDs must be literal string types (e.g. "orders"), not `string`. Use vessel() or defineVessel() to preserve literal types.' : T;
|
|
7
|
+
/** Configuration used to create one typed React Maelstrom instance. */
|
|
8
|
+
export interface CreateMaelstromConfig<T extends readonly AnyVesselEntry[]> {
|
|
9
|
+
/** Vessel entries available to the Provider and generated hooks. */
|
|
10
|
+
vessels: AssertNarrowIds<T> & T;
|
|
11
|
+
/**
|
|
12
|
+
* Grid cell size in pixels. Defaults to 80, must be positive, and may be
|
|
13
|
+
* overridden by the Provider.
|
|
14
|
+
*/
|
|
15
|
+
cellSizePx?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Pixel gap inset around computed tiling regions. Defaults to 8, must be
|
|
18
|
+
* non-negative, and may be overridden by the Provider.
|
|
19
|
+
*/
|
|
20
|
+
tilingPaddingPx?: number;
|
|
21
|
+
/** Enables client diagnostic logging. Defaults to `false`. */
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Chart motion/choreography settings. A `motion` prop on the Provider
|
|
25
|
+
* overrides this as a whole object (no per-field merge).
|
|
26
|
+
*/
|
|
27
|
+
motion?: ChartMotionConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Mount-time shared FIFO policy. Defaults: 8 pending, 30s queue wait,
|
|
30
|
+
* 10s disconnected grace, 60s active result deadline. The deadline does not
|
|
31
|
+
* cancel work. Provider overrides replace this object; remount to change it.
|
|
32
|
+
* Invalid limits fail Provider construction, as in the client SDK.
|
|
33
|
+
*/
|
|
34
|
+
intentQueue?: IntentQueueOptions;
|
|
35
|
+
}
|
|
36
|
+
/** Create a Maelstrom instance with Provider, hooks, and typed vessel access */
|
|
37
|
+
export declare function createMaelstrom<const T extends readonly AnyVesselEntry[]>(config: CreateMaelstromConfig<T>): MaelstromInstance<T>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=create-maelstrom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-maelstrom.d.ts","sourceRoot":"","sources":["../../src/lib/create-maelstrom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAYzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAQvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,sFAAsF;AACtF,KAAK,eAAe,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,IACtD,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GACpC,6IAA6I,GAC7I,CAAC,CAAC;AAER,uEAAuE;AACvE,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE;IACxE,oEAAoE;IACpE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,EACvE,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC/B,iBAAiB,CAAC,CAAC,CAAC,CAuBtB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ActionRunner } from '@maelstrom-co/client';
|
|
2
|
+
import { ActionName, InstanceId, VariantName, VesselDefinition, VesselId } from '@maelstrom-co/protocol';
|
|
3
|
+
import { RepublishableVessel, TypedVesselProps, UpdateVesselResult } from './vessel-entry-types.js';
|
|
4
|
+
/** Untyped vessel props — escape hatch for heterogeneous instance lists */
|
|
5
|
+
export interface UntypedVesselProps {
|
|
6
|
+
instanceId: InstanceId;
|
|
7
|
+
vesselId: VesselId;
|
|
8
|
+
variantProps: {
|
|
9
|
+
variant: VariantName;
|
|
10
|
+
} & Record<string, unknown>;
|
|
11
|
+
executeAction: (name: ActionName, params?: Record<string, unknown>) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Handle returned by `m.registerVessel()` for dynamically registered vessels.
|
|
15
|
+
* Provides typed hooks scoped to the registered vessel and a cleanup method.
|
|
16
|
+
*/
|
|
17
|
+
export interface DynamicVesselHandle<V extends VesselDefinition> {
|
|
18
|
+
/** Typed vessel props hook — equivalent to `m.useVessel(vesselId, instanceId)` but pre-scoped */
|
|
19
|
+
useVessel: (instanceId: string) => TypedVesselProps<V> | null;
|
|
20
|
+
/** Typed action runner registration — equivalent to `m.useActions(vesselId, instanceId, runner)` but pre-scoped */
|
|
21
|
+
useActions: (instanceId: string, runner: ActionRunner<V>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Republish this vessel's definition — its description, variants, and
|
|
24
|
+
* action parameters — without touching its component registration, so the
|
|
25
|
+
* vessel does not remount and keeps any DOM/canvas state it owns.
|
|
26
|
+
*
|
|
27
|
+
* This is the runtime-registration counterpart to `m.updateVessel()`: a
|
|
28
|
+
* vessel registered via `registerVessel()` never appears in the factory's
|
|
29
|
+
* `vessels` tuple, so `m.updateVessel()` cannot name its id at the type
|
|
30
|
+
* level. `handle.update()` closes that gap — `V` is exactly the
|
|
31
|
+
* definition inferred at the `registerVessel()` call site, fixed at
|
|
32
|
+
* compile time, so `definition` is checked against it the same way
|
|
33
|
+
* `m.updateVessel()` checks a factory-declared vessel's payload against
|
|
34
|
+
* the entry passed to `createMaelstrom({ vessels })`.
|
|
35
|
+
*
|
|
36
|
+
* Enforces the same runtime guards as `m.updateVessel()`: throws a plain
|
|
37
|
+
* `Error` if no Provider is mounted, the vessel id is not registered, or
|
|
38
|
+
* the definition fails validation. Returns `{ ok: false, conflict }`
|
|
39
|
+
* instead of throwing if a live instance's current variant is missing
|
|
40
|
+
* from the new definition (`'variant_dropped'`), if the new definition
|
|
41
|
+
* drops an action that instance's variant still declares
|
|
42
|
+
* (`'action_dropped'`), or if a command batch is already queued or in
|
|
43
|
+
* flight (`'batch_in_flight'`) — see `m.updateVessel()`'s JSDoc for the
|
|
44
|
+
* full result contract.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const handle = m.registerVessel(widgetEntry);
|
|
48
|
+
* const result = handle.update({ ...widgetEntry.vessel, description: 'Updated widget' });
|
|
49
|
+
* if (!result.ok) {
|
|
50
|
+
* console.warn(result.conflict.message);
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
update: (definition: RepublishableVessel<V>) => UpdateVesselResult;
|
|
54
|
+
/** Remove vessel from all registries (vesselManager, componentMap, loadingMap) */
|
|
55
|
+
unregister: () => void;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=dynamic-vessel-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-vessel-types.d.ts","sourceRoot":"","sources":["../../src/lib/dynamic-vessel-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjE,aAAa,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CAC7E;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,gBAAgB;IAC7D,iGAAiG;IACjG,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9D,mHAAmH;IACnH,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAClE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,EAAE,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC;IACnE,kFAAkF;IAClF,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EngineConnector, Orchestrator } from '@maelstrom-co/client';
|
|
2
|
+
import { MutableRefObject } from 'react';
|
|
3
|
+
import { ResolvedMaelstromConfig } from './config-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Stable shape passed to extensions when they read context from inside a
|
|
6
|
+
* Provider tree. Deliberately narrower than the internal context value
|
|
7
|
+
* so extension authors do not couple to private bookkeeping (component
|
|
8
|
+
* registry, vessel entries, mount guards) that may be reshaped between
|
|
9
|
+
* minor versions.
|
|
10
|
+
*/
|
|
11
|
+
export interface MaelstromExtensionContextValue {
|
|
12
|
+
orchestrator: Orchestrator;
|
|
13
|
+
connector: EngineConnector;
|
|
14
|
+
config: ResolvedMaelstromConfig;
|
|
15
|
+
/** Ref to onError callback from Provider props. Lets extensions surface errors without re-renders. */
|
|
16
|
+
onErrorRef: MutableRefObject<((error: Error) => void) | undefined>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Context handle handed to a `MaelstromExtension`. Exposes a hook that,
|
|
20
|
+
* when called inside the matching Provider tree, returns the stable
|
|
21
|
+
* extension-context subset. The actual runtime object carries more
|
|
22
|
+
* fields, but only those listed here are part of the supported contract.
|
|
23
|
+
*/
|
|
24
|
+
export interface MaelstromExtensionContext {
|
|
25
|
+
/** Observes this extension branch and its descendants before Provider connection; returns registration cleanup. */
|
|
26
|
+
onOrchestrator?: (attach: (orchestrator: Orchestrator) => () => void) => () => void;
|
|
27
|
+
useMaelstromContext: () => MaelstromExtensionContextValue;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Constraint for extension factory return values. Restricts the shape to a
|
|
31
|
+
* plain object — the `{ then?: never }` clause rejects `Promise<...>` so an
|
|
32
|
+
* accidentally-async factory (`async (ctx) => ({...})`) fails at compile
|
|
33
|
+
* time instead of silently spreading a thenable onto the instance.
|
|
34
|
+
*/
|
|
35
|
+
export type ExtensionOutput = object & {
|
|
36
|
+
then?: never;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Factory function that receives the extension context and returns
|
|
40
|
+
* additional fields to be merged onto the `MaelstromInstance`.
|
|
41
|
+
*
|
|
42
|
+
* Extension authors implement this type to create addons (voice, analytics,
|
|
43
|
+
* devtools, etc.) and consumers apply them via `instance.with(extension)`.
|
|
44
|
+
*
|
|
45
|
+
* Extensions must return a plain object synchronously. Async factories,
|
|
46
|
+
* arrays, and primitive values are rejected at compile time via the
|
|
47
|
+
* `ExtensionOutput` constraint.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const myExtension: MaelstromExtension<{ greet: () => string }> = (ctx) => ({
|
|
51
|
+
* greet: () => 'Hello from extension!',
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const m = createMaelstrom({ vessels }).with(myExtension);
|
|
55
|
+
* m.greet(); // 'Hello from extension!'
|
|
56
|
+
*/
|
|
57
|
+
export type MaelstromExtension<Out extends ExtensionOutput> = (ctx: MaelstromExtensionContext) => Out;
|
|
58
|
+
//# sourceMappingURL=extension-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-types.d.ts","sourceRoot":"","sources":["../../src/lib/extension-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,uBAAuB,CAAC;IAChC,sGAAsG;IACtG,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;CACpE;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,mHAAmH;IACnH,cAAc,CAAC,EAAE,CACf,MAAM,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,MAAM,IAAI,KAC/C,MAAM,IAAI,CAAC;IAChB,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;CAC3D;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAExD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,kBAAkB,CAAC,GAAG,SAAS,eAAe,IAAI,CAC5D,GAAG,EAAE,yBAAyB,KAC3B,GAAG,CAAC"}
|