@iyulab/m3l 0.5.0 → 0.5.6
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/index.d.ts +303 -4
- package/index.js +2 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,25 +1,324 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// M3L TypeScript AST Type Definitions
|
|
3
|
+
// Generated from crates/m3l-core/src/types.rs
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
// --- Result wrapper ---
|
|
7
|
+
|
|
8
|
+
export interface M3lResult<T> {
|
|
9
|
+
success: boolean;
|
|
10
|
+
data?: T;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// --- Source location ---
|
|
15
|
+
|
|
16
|
+
export interface SourceLocation {
|
|
17
|
+
file: string;
|
|
18
|
+
line: number;
|
|
19
|
+
col: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// --- Primitive union types ---
|
|
23
|
+
|
|
24
|
+
/** Attribute argument value (untagged union: string | number | boolean) */
|
|
25
|
+
export type AttrArgValue = string | number | boolean;
|
|
26
|
+
|
|
27
|
+
/** Field type parameter (untagged union: string | number) */
|
|
28
|
+
export type ParamValue = string | number;
|
|
29
|
+
|
|
30
|
+
// --- Enums ---
|
|
31
|
+
|
|
32
|
+
/** Field kind — serialized as lowercase string */
|
|
33
|
+
export type FieldKind = "stored" | "computed" | "lookup" | "rollup";
|
|
34
|
+
|
|
35
|
+
/** Model type — serialized as lowercase string */
|
|
36
|
+
export type ModelType = "model" | "enum" | "interface" | "view";
|
|
37
|
+
|
|
38
|
+
/** Diagnostic severity — serialized as lowercase string */
|
|
39
|
+
export type DiagnosticSeverity = "error" | "warning";
|
|
40
|
+
|
|
41
|
+
/** Default value type — serialized as lowercase string */
|
|
42
|
+
export type DefaultValueType = "literal" | "expression";
|
|
43
|
+
|
|
44
|
+
// --- Attribute types ---
|
|
45
|
+
|
|
46
|
+
export interface FieldAttribute {
|
|
47
|
+
name: string;
|
|
48
|
+
args?: AttrArgValue[];
|
|
49
|
+
cascade?: string;
|
|
50
|
+
isStandard?: boolean;
|
|
51
|
+
isRegistered?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface CustomAttributeParsed {
|
|
55
|
+
name: string;
|
|
56
|
+
arguments: AttrArgValue[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface CustomAttribute {
|
|
60
|
+
content: string;
|
|
61
|
+
raw: string;
|
|
62
|
+
parsed?: CustomAttributeParsed;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- Enum types ---
|
|
66
|
+
|
|
67
|
+
export interface EnumValue {
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
type?: string;
|
|
71
|
+
value?: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// --- Field definition types ---
|
|
75
|
+
|
|
76
|
+
export interface LookupDef {
|
|
77
|
+
path: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface RollupDef {
|
|
81
|
+
target: string;
|
|
82
|
+
fk: string;
|
|
83
|
+
aggregate: string;
|
|
84
|
+
field?: string;
|
|
85
|
+
where?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ComputedDef {
|
|
89
|
+
expression: string;
|
|
90
|
+
platform?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// --- Field node ---
|
|
94
|
+
|
|
95
|
+
export interface FieldNode {
|
|
96
|
+
name: string;
|
|
97
|
+
label?: string;
|
|
98
|
+
type?: string;
|
|
99
|
+
params?: ParamValue[];
|
|
100
|
+
generic_params?: string[];
|
|
101
|
+
nullable: boolean;
|
|
102
|
+
array: boolean;
|
|
103
|
+
arrayItemNullable: boolean;
|
|
104
|
+
kind: FieldKind;
|
|
105
|
+
default_value?: string;
|
|
106
|
+
default_value_type?: DefaultValueType;
|
|
107
|
+
description?: string;
|
|
108
|
+
attributes: FieldAttribute[];
|
|
109
|
+
framework_attrs?: CustomAttribute[];
|
|
110
|
+
lookup?: LookupDef;
|
|
111
|
+
rollup?: RollupDef;
|
|
112
|
+
computed?: ComputedDef;
|
|
113
|
+
enum_values?: EnumValue[];
|
|
114
|
+
fields?: FieldNode[];
|
|
115
|
+
loc: SourceLocation;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --- View types ---
|
|
119
|
+
|
|
120
|
+
export interface JoinDef {
|
|
121
|
+
model: string;
|
|
122
|
+
on: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ViewSourceDef {
|
|
126
|
+
from?: string;
|
|
127
|
+
joins?: JoinDef[];
|
|
128
|
+
where?: string;
|
|
129
|
+
order_by?: string;
|
|
130
|
+
group_by?: string[];
|
|
131
|
+
raw_sql?: string;
|
|
132
|
+
language_hint?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface RefreshDef {
|
|
136
|
+
strategy: string;
|
|
137
|
+
interval?: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- Sections ---
|
|
141
|
+
|
|
142
|
+
export interface Sections {
|
|
143
|
+
indexes: unknown[];
|
|
144
|
+
relations: unknown[];
|
|
145
|
+
behaviors: unknown[];
|
|
146
|
+
metadata: Record<string, unknown>;
|
|
147
|
+
/** Additional custom sections (via serde flatten) */
|
|
148
|
+
[key: string]: unknown;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// --- Model node ---
|
|
152
|
+
|
|
153
|
+
export interface ModelNode {
|
|
154
|
+
name: string;
|
|
155
|
+
label?: string;
|
|
156
|
+
type: ModelType;
|
|
157
|
+
source: string;
|
|
158
|
+
/** Namespace of the source file (`# Namespace: ...`), if any. */
|
|
159
|
+
namespace?: string;
|
|
160
|
+
line: number;
|
|
161
|
+
inherits: string[];
|
|
162
|
+
description?: string;
|
|
163
|
+
attributes: FieldAttribute[];
|
|
164
|
+
fields: FieldNode[];
|
|
165
|
+
sections: Sections;
|
|
166
|
+
materialized?: boolean;
|
|
167
|
+
source_def?: ViewSourceDef;
|
|
168
|
+
refresh?: RefreshDef;
|
|
169
|
+
loc: SourceLocation;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// --- Enum node ---
|
|
173
|
+
|
|
174
|
+
export interface EnumNode {
|
|
175
|
+
name: string;
|
|
176
|
+
label?: string;
|
|
177
|
+
type: ModelType;
|
|
178
|
+
source: string;
|
|
179
|
+
/** Namespace of the source file (`# Namespace: ...`), if any. */
|
|
180
|
+
namespace?: string;
|
|
181
|
+
line: number;
|
|
182
|
+
inherits: string[];
|
|
183
|
+
description?: string;
|
|
184
|
+
values: EnumValue[];
|
|
185
|
+
loc: SourceLocation;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- Project info ---
|
|
189
|
+
|
|
190
|
+
export interface ProjectInfo {
|
|
191
|
+
name?: string;
|
|
192
|
+
version?: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// --- Diagnostics ---
|
|
196
|
+
|
|
197
|
+
export interface Diagnostic {
|
|
198
|
+
code: string;
|
|
199
|
+
severity: DiagnosticSeverity;
|
|
200
|
+
file: string;
|
|
201
|
+
line: number;
|
|
202
|
+
col: number;
|
|
203
|
+
message: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// --- Attribute registry ---
|
|
207
|
+
|
|
208
|
+
export interface AttributeRegistryEntry {
|
|
209
|
+
name: string;
|
|
210
|
+
description?: string;
|
|
211
|
+
target: string[];
|
|
212
|
+
type: string;
|
|
213
|
+
range?: [number, number];
|
|
214
|
+
required: boolean;
|
|
215
|
+
defaultValue?: AttrArgValue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// --- Top-level AST ---
|
|
219
|
+
|
|
220
|
+
export interface M3lAst {
|
|
221
|
+
parserVersion: string;
|
|
222
|
+
astVersion: string;
|
|
223
|
+
project: ProjectInfo;
|
|
224
|
+
sources: string[];
|
|
225
|
+
models: ModelNode[];
|
|
226
|
+
enums: EnumNode[];
|
|
227
|
+
interfaces: ModelNode[];
|
|
228
|
+
views: ModelNode[];
|
|
229
|
+
attributeRegistry: AttributeRegistryEntry[];
|
|
230
|
+
errors: Diagnostic[];
|
|
231
|
+
warnings: Diagnostic[];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// --- Validate result ---
|
|
235
|
+
|
|
236
|
+
export interface ValidateResult {
|
|
237
|
+
errors: Diagnostic[];
|
|
238
|
+
warnings: Diagnostic[];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// --- Lint types ---
|
|
242
|
+
|
|
243
|
+
/** Lint severity — serialized as lowercase string */
|
|
244
|
+
export type LintSeverity = "error" | "warning" | "info";
|
|
245
|
+
|
|
246
|
+
/** Lint rule level — serialized as lowercase string */
|
|
247
|
+
export type RuleLevel = "off" | "warn" | "error";
|
|
248
|
+
|
|
249
|
+
export interface LintDiagnostic {
|
|
250
|
+
rule: string;
|
|
251
|
+
severity: LintSeverity;
|
|
252
|
+
file: string;
|
|
253
|
+
line: number;
|
|
254
|
+
col: number;
|
|
255
|
+
message: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface LintConfig {
|
|
259
|
+
rules?: Record<string, RuleLevel>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface LintResult {
|
|
263
|
+
diagnostics: LintDiagnostic[];
|
|
264
|
+
file_count: number;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// --- Input types ---
|
|
268
|
+
|
|
269
|
+
export interface FileInput {
|
|
270
|
+
content: string;
|
|
271
|
+
filename: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface ValidateOptions {
|
|
275
|
+
strict?: boolean;
|
|
276
|
+
filename?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
// Function declarations
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
|
|
1
283
|
/**
|
|
2
284
|
* Parse a single M3L file and return the AST as JSON.
|
|
3
285
|
*
|
|
286
|
+
* The returned JSON string deserializes to `M3lResult<M3lAst>`.
|
|
287
|
+
*
|
|
4
288
|
* @param content - M3L markdown text
|
|
5
289
|
* @param filename - Source filename for error reporting
|
|
6
|
-
* @returns JSON string with `{ success: boolean, data?:
|
|
290
|
+
* @returns JSON string with `{ success: boolean, data?: M3lAst, error?: string }`
|
|
7
291
|
*/
|
|
8
292
|
export function parse(content: string, filename: string): string;
|
|
9
293
|
|
|
10
294
|
/**
|
|
11
295
|
* Parse multiple M3L files and return the merged AST as JSON.
|
|
12
296
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
297
|
+
* The returned JSON string deserializes to `M3lResult<M3lAst>`.
|
|
298
|
+
*
|
|
299
|
+
* @param filesJson - JSON array of `FileInput` objects
|
|
300
|
+
* @returns JSON string with `{ success: boolean, data?: M3lAst, error?: string }`
|
|
15
301
|
*/
|
|
16
302
|
export function parseMulti(filesJson: string): string;
|
|
17
303
|
|
|
18
304
|
/**
|
|
19
305
|
* Validate M3L content and return diagnostics as JSON.
|
|
20
306
|
*
|
|
307
|
+
* The returned JSON string deserializes to `M3lResult<ValidateResult>`.
|
|
308
|
+
*
|
|
21
309
|
* @param content - M3L markdown text
|
|
22
|
-
* @param optionsJson - JSON options `
|
|
310
|
+
* @param optionsJson - JSON options (`ValidateOptions`)
|
|
23
311
|
* @returns JSON string with `{ success: boolean, data?: ValidateResult, error?: string }`
|
|
24
312
|
*/
|
|
25
313
|
export function validate(content: string, optionsJson: string): string;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Lint M3L content and return diagnostics as JSON.
|
|
317
|
+
*
|
|
318
|
+
* The returned JSON string deserializes to `M3lResult<LintResult>`.
|
|
319
|
+
*
|
|
320
|
+
* @param content - M3L markdown text
|
|
321
|
+
* @param configJson - JSON config (`LintConfig`)
|
|
322
|
+
* @returns JSON string with `{ success: boolean, data?: LintResult, error?: string }`
|
|
323
|
+
*/
|
|
324
|
+
export function lint(content: string, configJson: string): string;
|
package/index.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* All parsing is performed by the Rust m3l-core library.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const { parse, parseMulti, validate } = require('@iyulab/m3l-napi');
|
|
8
|
+
const { parse, parseMulti, validate, lint } = require('@iyulab/m3l-napi');
|
|
9
9
|
|
|
10
10
|
module.exports.parse = parse;
|
|
11
11
|
module.exports.parseMulti = parseMulti;
|
|
12
12
|
module.exports.validate = validate;
|
|
13
|
+
module.exports.lint = lint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iyulab/m3l",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "M3L parser — Markdown-based schema definition language (.m3l.md → JSON AST)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"index.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@iyulab/m3l-napi": "0.5.
|
|
13
|
+
"@iyulab/m3l-napi": "0.5.6"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">= 18"
|