@manifesto-ai/compiler 3.7.1 → 3.9.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.
@@ -1,4 +1,7 @@
1
1
  import type { ComputedNode, DomainNode, ExprNode, ParamNode, TypeDeclNode, TypeExprNode } from "../parser/ast.js";
2
+ import type { SpreadOperandClassification } from "./object-contribution-types.js";
3
+ export type { SpreadOperandClassification, } from "./object-contribution-types.js";
4
+ export { mayYieldArrayExpr } from "./object-contribution-types.js";
2
5
  export type TypeEnv = Map<string, TypeExprNode>;
3
6
  export type ComparableSurfaceClass = "primitive" | "nonprimitive" | "unknown";
4
7
  export interface DomainTypeSymbols {
@@ -19,3 +22,4 @@ export declare function getIndexType(typeExpr: TypeExprNode | null, symbols: Dom
19
22
  export declare function getArrayElementType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols): TypeExprNode | null;
20
23
  export declare function isPrimitiveEntityIdType(typeExpr: TypeExprNode, symbols: DomainTypeSymbols): boolean;
21
24
  export declare function isNullType(typeExpr: TypeExprNode): boolean;
25
+ export declare function classifySpreadOperandType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols): SpreadOperandClassification;
@@ -0,0 +1,19 @@
1
+ import type { ExprNode, TypeExprNode } from "../parser/ast.js";
2
+ export type SpreadOperandClassification = "object" | "nullable-object" | "invalid" | "unknown";
3
+ type InferExprType<Env, Symbols> = (expr: ExprNode, env: Env, symbols: Symbols) => TypeExprNode | null;
4
+ type ResolveType<Symbols> = (typeExpr: TypeExprNode | null, symbols: Symbols) => TypeExprNode | null;
5
+ type ExprTypeContext<Env, Symbols> = {
6
+ env: Env;
7
+ symbols: Symbols;
8
+ inferExprType: InferExprType<Env, Symbols>;
9
+ resolveType: ResolveType<Symbols>;
10
+ };
11
+ export declare function inferObjectLiteralContributionType<Env, Symbols>(expr: Extract<ExprNode, {
12
+ kind: "objectLiteral";
13
+ }>, env: Env, symbols: Symbols, inferExprType: InferExprType<Env, Symbols>, resolveType: ResolveType<Symbols>): TypeExprNode | null;
14
+ export declare function inferMergeContributionType<Env, Symbols>(expr: Extract<ExprNode, {
15
+ kind: "functionCall";
16
+ }>, env: Env, symbols: Symbols, inferExprType: InferExprType<Env, Symbols>, resolveType: ResolveType<Symbols>): TypeExprNode | null;
17
+ export declare function classifySpreadOperandType<Symbols>(typeExpr: TypeExprNode | null, symbols: Symbols, resolveType: ResolveType<Symbols>): SpreadOperandClassification;
18
+ export declare function mayYieldArrayExpr<Env, Symbols>(expr: ExprNode | undefined, context?: ExprTypeContext<Env, Symbols>): boolean;
19
+ export {};
@@ -64,6 +64,7 @@ export declare class SemanticValidator {
64
64
  private requireAssignable;
65
65
  private requireArrayCompatible;
66
66
  private requireLenCompatible;
67
+ private requireSpreadOperand;
67
68
  private validateCoalesceTypes;
68
69
  private validateMatchCall;
69
70
  private validateArgSelectionCall;
@@ -0,0 +1,12 @@
1
+ import type { LocalTargetKey } from "../annotations.js";
2
+ import type { Diagnostic } from "../diagnostics/types.js";
3
+ import type { MelEditResult, MelTextEdit } from "./compile-fragment-types.js";
4
+ export type MaterializedEdit = {
5
+ readonly edits: readonly MelTextEdit[];
6
+ readonly changedTargets: readonly LocalTargetKey[];
7
+ readonly diagnostics: readonly Diagnostic[];
8
+ };
9
+ export declare function validateThenEdit(diagnostics: readonly Diagnostic[], makeEdit: () => MaterializedEdit): MaterializedEdit;
10
+ export declare function preMaterializationFailure(baseSource: string, diagnostics: readonly Diagnostic[]): MelEditResult;
11
+ export declare function materializationSuccess(edits: readonly MelTextEdit[], changedTargets: readonly LocalTargetKey[]): MaterializedEdit;
12
+ export declare function materializationFailure(...diagnostics: Diagnostic[]): MaterializedEdit;
@@ -0,0 +1,3 @@
1
+ import type { CompileFragmentInContextOptions, MelEditOp, MelEditResult } from "./compile-fragment-types.js";
2
+ export type { CompileFragmentInContextOptions, MelEditAddActionOp, MelEditAddAvailableOp, MelEditAddComputedOp, MelEditAddDispatchableOp, MelEditAddStateFieldOp, MelEditAddTypeOp, MelEditOp, MelEditRemoveDeclarationOp, MelEditRenameDeclarationOp, MelEditReplaceActionBodyOp, MelEditReplaceAvailableOp, MelEditReplaceComputedExprOp, MelEditReplaceDispatchableOp, MelEditReplaceStateDefaultOp, MelEditReplaceTypeFieldOp, MelEditResult, MelParamSource, MelTextEdit, SchemaDiff, SchemaModifiedTarget, } from "./compile-fragment-types.js";
3
+ export declare function compileFragmentInContext(baseSource: string, op: MelEditOp, options?: CompileFragmentInContextOptions): MelEditResult;
@@ -0,0 +1,13 @@
1
+ import type { JsonLiteral } from "../annotations.js";
2
+ import type { Diagnostic } from "../diagnostics/types.js";
3
+ type JsonLiteralSnapshot = {
4
+ readonly ok: true;
5
+ readonly value: JsonLiteral;
6
+ readonly diagnostics: readonly Diagnostic[];
7
+ } | {
8
+ readonly ok: false;
9
+ readonly diagnostics: readonly Diagnostic[];
10
+ };
11
+ export declare function validateJsonLiteralFragment(value: unknown, label: string): Diagnostic[];
12
+ export declare function snapshotJsonLiteralFragment(value: unknown, label: string): JsonLiteralSnapshot;
13
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { Diagnostic } from "../diagnostics/types.js";
2
+ export type CompileFragmentOptionsSnapshot = {
3
+ readonly baseModuleSourceHash: string | null;
4
+ readonly includeModule: boolean;
5
+ readonly includeSchemaDiff: boolean;
6
+ };
7
+ type OptionsSnapshotRead = {
8
+ readonly ok: true;
9
+ readonly value: CompileFragmentOptionsSnapshot;
10
+ } | {
11
+ readonly ok: false;
12
+ readonly diagnostic: Diagnostic;
13
+ };
14
+ export declare function snapshotCompileFragmentOptions(options: unknown): OptionsSnapshotRead;
15
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ProgramNode } from "../parser/index.js";
2
+ import type { OffsetRange, ReferenceSpan, TargetInfo } from "./compile-fragment-reference-types.js";
3
+ export declare function collectTargetReferences(source: string, program: ProgramNode, target: TargetInfo, ignoreRange?: OffsetRange): ReferenceSpan[];
@@ -0,0 +1,40 @@
1
+ import type { LocalTargetKey } from "../annotations.js";
2
+ import type { ProgramNode } from "../parser/index.js";
3
+ import type { MelTextEdit } from "./compile-fragment-types.js";
4
+ export type DeclarationEditPlan = {
5
+ readonly ok: true;
6
+ readonly edits: readonly MelTextEdit[];
7
+ readonly changedTargets: readonly LocalTargetKey[];
8
+ } | {
9
+ readonly ok: false;
10
+ readonly code: DeclarationEditFailureCode;
11
+ readonly message: string;
12
+ readonly location: ProgramNode["location"];
13
+ };
14
+ export type DeclarationEditFailureCode = "E_REMOVE_BLOCKED_BY_REFERENCES" | "E_UNSAFE_RENAME_AMBIGUOUS" | "E_TARGET_NOT_FOUND" | "E_FRAGMENT_SCOPE_VIOLATION";
15
+ export type TargetInfo = {
16
+ readonly kind: "type";
17
+ readonly name: string;
18
+ } | {
19
+ readonly kind: "state_field";
20
+ readonly name: string;
21
+ } | {
22
+ readonly kind: "computed";
23
+ readonly name: string;
24
+ } | {
25
+ readonly kind: "action";
26
+ readonly name: string;
27
+ } | {
28
+ readonly kind: "type_field";
29
+ readonly typeName: string;
30
+ readonly fieldName: string;
31
+ };
32
+ export type ReferenceSpan = {
33
+ readonly range: OffsetRange;
34
+ readonly location: ProgramNode["location"];
35
+ readonly rewrite: boolean;
36
+ };
37
+ export type OffsetRange = {
38
+ readonly start: number;
39
+ readonly end: number;
40
+ };
@@ -0,0 +1,5 @@
1
+ import type { LocalTargetKey } from "../annotations.js";
2
+ import type { ProgramNode } from "../parser/index.js";
3
+ import type { DeclarationEditPlan } from "./compile-fragment-reference-types.js";
4
+ export declare function planRemoveDeclaration(source: string, program: ProgramNode, target: LocalTargetKey): DeclarationEditPlan;
5
+ export declare function planRenameDeclaration(source: string, program: ProgramNode, target: LocalTargetKey, newName: string): DeclarationEditPlan;
@@ -0,0 +1,36 @@
1
+ import type { JsonLiteral, LocalTargetKey } from "../annotations.js";
2
+ import type { DomainSchema } from "../generator/ir.js";
3
+ import { type Token } from "../lexer/index.js";
4
+ import type { ActionNode, ComputedNode, ProgramNode, StateFieldNode, TypeDeclNode, TypeFieldNode } from "../parser/index.js";
5
+ import { type SourcePoint } from "../source-map.js";
6
+ import type { MelEditAddActionOp, MelTextEdit, SchemaDiff } from "./compile-fragment-types.js";
7
+ export declare function findAction(program: ProgramNode, name: string): ActionNode | null;
8
+ export declare function findComputed(program: ProgramNode, name: string): ComputedNode | null;
9
+ export declare function findStateField(program: ProgramNode, name: string): StateFieldNode | null;
10
+ export declare function findTypeDecl(program: ProgramNode, name: string): TypeDeclNode | null;
11
+ export declare function findTypeField(program: ProgramNode, typeName: string, fieldName: string): TypeFieldNode | null;
12
+ export declare function parseTypeFieldTarget(target: `type_field:${string}.${string}`): {
13
+ typeName: string;
14
+ fieldName: string;
15
+ } | null;
16
+ export declare function targetLocation(program: ProgramNode, target: LocalTargetKey): ProgramNode["location"];
17
+ export declare function findActionBodyBraces(source: string, action: ActionNode): {
18
+ open: Token;
19
+ close: Token;
20
+ } | null;
21
+ export declare function findActionToken(source: string, action: ActionNode, kind: Token["kind"]): Token | null;
22
+ export declare function insertBeforeClosingLine(source: string, closeOffset: number, text: string): MelTextEdit;
23
+ export declare function textEdit(source: string, start: number, end: number, replacement: string): MelTextEdit;
24
+ export declare function applyTextEdits(source: string, edits: readonly MelTextEdit[]): string;
25
+ export declare function requiredOffset(point: SourcePoint): number;
26
+ export declare function lineIndentAt(source: string, offset: number): string;
27
+ export declare function indentLines(source: string, indent: string): string;
28
+ export declare function renderAction(op: MelEditAddActionOp): string;
29
+ export declare function renderBodyReplacement(body: string, bodyIndent: string, actionIndent: string): string;
30
+ export declare function renderJsonLiteral(value: JsonLiteral): string;
31
+ export declare function diffSchemas(before: DomainSchema, after: DomainSchema): SchemaDiff;
32
+ export declare function sortTargets(targets: readonly LocalTargetKey[]): LocalTargetKey[];
33
+ export declare function isEditObject(value: unknown): value is {
34
+ readonly kind: string;
35
+ };
36
+ export declare function describeUnknown(value: unknown): string;
@@ -0,0 +1,109 @@
1
+ import type { DomainModule, JsonLiteral, LocalTargetKey } from "../annotations.js";
2
+ import type { SourceSpan } from "../source-map.js";
3
+ import type { Diagnostic } from "../diagnostics/types.js";
4
+ export interface CompileFragmentInContextOptions {
5
+ readonly baseModule?: DomainModule;
6
+ readonly includeModule?: boolean;
7
+ readonly includeSchemaDiff?: boolean;
8
+ }
9
+ export interface MelEditResult {
10
+ readonly ok: boolean;
11
+ readonly newSource: string;
12
+ readonly diagnostics: readonly Diagnostic[];
13
+ readonly module?: DomainModule;
14
+ readonly changedTargets: readonly LocalTargetKey[];
15
+ readonly edits: readonly MelTextEdit[];
16
+ readonly schemaDiff?: SchemaDiff;
17
+ }
18
+ export interface MelTextEdit {
19
+ readonly range: SourceSpan;
20
+ readonly replacement: string;
21
+ }
22
+ export interface SchemaDiff {
23
+ readonly addedTargets: readonly LocalTargetKey[];
24
+ readonly removedTargets: readonly LocalTargetKey[];
25
+ readonly modifiedTargets: readonly SchemaModifiedTarget[];
26
+ }
27
+ export interface SchemaModifiedTarget {
28
+ readonly target: LocalTargetKey;
29
+ readonly beforeHash: string;
30
+ readonly afterHash: string;
31
+ readonly before?: unknown;
32
+ readonly after?: unknown;
33
+ }
34
+ export type MelParamSource = {
35
+ readonly name: string;
36
+ readonly type: string;
37
+ };
38
+ export type MelEditOp = MelEditAddTypeOp | MelEditAddStateFieldOp | MelEditAddComputedOp | MelEditAddActionOp | MelEditAddAvailableOp | MelEditAddDispatchableOp | MelEditReplaceActionBodyOp | MelEditReplaceComputedExprOp | MelEditReplaceAvailableOp | MelEditReplaceDispatchableOp | MelEditReplaceStateDefaultOp | MelEditReplaceTypeFieldOp | MelEditRemoveDeclarationOp | MelEditRenameDeclarationOp;
39
+ export type MelEditAddTypeOp = {
40
+ readonly kind: "addType";
41
+ readonly name: string;
42
+ readonly expr: string;
43
+ };
44
+ export type MelEditAddStateFieldOp = {
45
+ readonly kind: "addStateField";
46
+ readonly name: string;
47
+ readonly type: string;
48
+ readonly defaultValue: JsonLiteral;
49
+ };
50
+ export type MelEditAddComputedOp = {
51
+ readonly kind: "addComputed";
52
+ readonly name: string;
53
+ readonly expr: string;
54
+ };
55
+ export type MelEditAddActionOp = {
56
+ readonly kind: "addAction";
57
+ readonly name: string;
58
+ readonly params: readonly MelParamSource[];
59
+ readonly body: string;
60
+ };
61
+ export type MelEditAddAvailableOp = {
62
+ readonly kind: "addAvailable";
63
+ readonly target: `action:${string}`;
64
+ readonly expr: string;
65
+ };
66
+ export type MelEditAddDispatchableOp = {
67
+ readonly kind: "addDispatchable";
68
+ readonly target: `action:${string}`;
69
+ readonly expr: string;
70
+ };
71
+ export type MelEditReplaceActionBodyOp = {
72
+ readonly kind: "replaceActionBody";
73
+ readonly target: `action:${string}`;
74
+ readonly body: string;
75
+ };
76
+ export type MelEditReplaceComputedExprOp = {
77
+ readonly kind: "replaceComputedExpr";
78
+ readonly target: `computed:${string}`;
79
+ readonly expr: string;
80
+ };
81
+ export type MelEditReplaceAvailableOp = {
82
+ readonly kind: "replaceAvailable";
83
+ readonly target: `action:${string}`;
84
+ readonly expr: string | null;
85
+ };
86
+ export type MelEditReplaceDispatchableOp = {
87
+ readonly kind: "replaceDispatchable";
88
+ readonly target: `action:${string}`;
89
+ readonly expr: string | null;
90
+ };
91
+ export type MelEditReplaceStateDefaultOp = {
92
+ readonly kind: "replaceStateDefault";
93
+ readonly target: `state_field:${string}`;
94
+ readonly value: JsonLiteral;
95
+ };
96
+ export type MelEditReplaceTypeFieldOp = {
97
+ readonly kind: "replaceTypeField";
98
+ readonly target: `type_field:${string}.${string}`;
99
+ readonly type: string;
100
+ };
101
+ export type MelEditRemoveDeclarationOp = {
102
+ readonly kind: "removeDeclaration";
103
+ readonly target: LocalTargetKey;
104
+ };
105
+ export type MelEditRenameDeclarationOp = {
106
+ readonly kind: "renameDeclaration";
107
+ readonly target: LocalTargetKey;
108
+ readonly newName: string;
109
+ };
@@ -0,0 +1,52 @@
1
+ import type { DomainModule, LocalTargetKey } from "../annotations.js";
2
+ import { type Diagnostic } from "../diagnostics/types.js";
3
+ import { type ProgramNode } from "../parser/index.js";
4
+ import type { MelParamSource } from "./compile-fragment-types.js";
5
+ export declare const EMPTY_LOCATION: {
6
+ start: {
7
+ line: number;
8
+ column: number;
9
+ offset: number;
10
+ };
11
+ end: {
12
+ line: number;
13
+ column: number;
14
+ offset: number;
15
+ };
16
+ };
17
+ export declare function editError(code: string, message: string, location?: ProgramNode["location"]): Diagnostic;
18
+ export declare function diagnosticsOf(result: {
19
+ warnings: readonly Diagnostic[];
20
+ errors: readonly Diagnostic[];
21
+ }): Diagnostic[];
22
+ export declare function parseProgram(source: string): {
23
+ program: ProgramNode | null;
24
+ diagnostics: Diagnostic[];
25
+ };
26
+ export declare function validateExpressionFragment(expr: unknown): Diagnostic[];
27
+ export declare function validateTypeFragment(typeSource: unknown): Diagnostic[];
28
+ export declare function validateStateFieldFragment(typeSource: unknown, defaultSource: string): Diagnostic[];
29
+ export declare function validateActionBodyFragment(body: unknown): Diagnostic[];
30
+ export declare function validateIdentifierFragment(value: unknown, label: string): Diagnostic[];
31
+ export declare function validateParamsFragment(params: unknown): Diagnostic[];
32
+ type ParamsFragmentSnapshot = {
33
+ readonly ok: true;
34
+ readonly value: readonly MelParamSource[];
35
+ readonly diagnostics: readonly Diagnostic[];
36
+ } | {
37
+ readonly ok: false;
38
+ readonly diagnostics: readonly Diagnostic[];
39
+ };
40
+ export declare function snapshotParamsFragment(params: unknown): ParamsFragmentSnapshot;
41
+ type EditOperationKindRead = {
42
+ readonly ok: true;
43
+ readonly value: string;
44
+ } | {
45
+ readonly ok: false;
46
+ readonly diagnostic: Diagnostic;
47
+ };
48
+ export declare function readEditOperationKind(value: unknown): EditOperationKindRead;
49
+ export declare function validateTarget(baseModule: DomainModule, target: unknown, allowedKinds: readonly string[]): Diagnostic | null;
50
+ export declare function targetNotFound(target: LocalTargetKey): Diagnostic;
51
+ export declare function targetKind(target: string): string | null;
52
+ export {};
@@ -6,4 +6,6 @@
6
6
  * @see SPEC v0.4.0 §19
7
7
  */
8
8
  export type { Annotation, AnnotationIndex, CompileTrace, CompileMelDomainOptions, CompileMelDomainResult, CompileMelModuleOptions, CompileMelModuleResult, CompileMelPatchOptions, CompileMelPatchResult, DomainModule, JsonLiteral, LocalTargetKey, SourceMapEmissionContext, SourceMapEntry, SourceMapIndex, SourceMapPath, SourcePoint, SourceSpan, } from "./compile-mel.js";
9
+ export type { CompileFragmentInContextOptions, MelEditAddActionOp, MelEditAddAvailableOp, MelEditAddComputedOp, MelEditAddDispatchableOp, MelEditAddStateFieldOp, MelEditAddTypeOp, MelEditOp, MelEditRemoveDeclarationOp, MelEditRenameDeclarationOp, MelEditReplaceActionBodyOp, MelEditReplaceAvailableOp, MelEditReplaceComputedExprOp, MelEditReplaceDispatchableOp, MelEditReplaceStateDefaultOp, MelEditReplaceTypeFieldOp, MelEditResult, MelParamSource, MelTextEdit, SchemaDiff, SchemaModifiedTarget, } from "./compile-fragment-in-context.js";
9
10
  export { compileMelDomain, compileMelModule, compileMelPatch } from "./compile-mel.js";
11
+ export { compileFragmentInContext } from "./compile-fragment-in-context.js";