@iyulab/m3l 0.5.0 → 0.5.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.
Files changed (3) hide show
  1. package/index.d.ts +299 -4
  2. package/index.js +2 -1
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -1,25 +1,320 @@
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
+ line: number;
159
+ inherits: string[];
160
+ description?: string;
161
+ attributes: FieldAttribute[];
162
+ fields: FieldNode[];
163
+ sections: Sections;
164
+ materialized?: boolean;
165
+ source_def?: ViewSourceDef;
166
+ refresh?: RefreshDef;
167
+ loc: SourceLocation;
168
+ }
169
+
170
+ // --- Enum node ---
171
+
172
+ export interface EnumNode {
173
+ name: string;
174
+ label?: string;
175
+ type: ModelType;
176
+ source: string;
177
+ line: number;
178
+ inherits: string[];
179
+ description?: string;
180
+ values: EnumValue[];
181
+ loc: SourceLocation;
182
+ }
183
+
184
+ // --- Project info ---
185
+
186
+ export interface ProjectInfo {
187
+ name?: string;
188
+ version?: string;
189
+ }
190
+
191
+ // --- Diagnostics ---
192
+
193
+ export interface Diagnostic {
194
+ code: string;
195
+ severity: DiagnosticSeverity;
196
+ file: string;
197
+ line: number;
198
+ col: number;
199
+ message: string;
200
+ }
201
+
202
+ // --- Attribute registry ---
203
+
204
+ export interface AttributeRegistryEntry {
205
+ name: string;
206
+ description?: string;
207
+ target: string[];
208
+ type: string;
209
+ range?: [number, number];
210
+ required: boolean;
211
+ defaultValue?: AttrArgValue;
212
+ }
213
+
214
+ // --- Top-level AST ---
215
+
216
+ export interface M3lAst {
217
+ parserVersion: string;
218
+ astVersion: string;
219
+ project: ProjectInfo;
220
+ sources: string[];
221
+ models: ModelNode[];
222
+ enums: EnumNode[];
223
+ interfaces: ModelNode[];
224
+ views: ModelNode[];
225
+ attributeRegistry: AttributeRegistryEntry[];
226
+ errors: Diagnostic[];
227
+ warnings: Diagnostic[];
228
+ }
229
+
230
+ // --- Validate result ---
231
+
232
+ export interface ValidateResult {
233
+ errors: Diagnostic[];
234
+ warnings: Diagnostic[];
235
+ }
236
+
237
+ // --- Lint types ---
238
+
239
+ /** Lint severity — serialized as lowercase string */
240
+ export type LintSeverity = "error" | "warning" | "info";
241
+
242
+ /** Lint rule level — serialized as lowercase string */
243
+ export type RuleLevel = "off" | "warn" | "error";
244
+
245
+ export interface LintDiagnostic {
246
+ rule: string;
247
+ severity: LintSeverity;
248
+ file: string;
249
+ line: number;
250
+ col: number;
251
+ message: string;
252
+ }
253
+
254
+ export interface LintConfig {
255
+ rules?: Record<string, RuleLevel>;
256
+ }
257
+
258
+ export interface LintResult {
259
+ diagnostics: LintDiagnostic[];
260
+ file_count: number;
261
+ }
262
+
263
+ // --- Input types ---
264
+
265
+ export interface FileInput {
266
+ content: string;
267
+ filename: string;
268
+ }
269
+
270
+ export interface ValidateOptions {
271
+ strict?: boolean;
272
+ filename?: string;
273
+ }
274
+
275
+ // ---------------------------------------------------------------------------
276
+ // Function declarations
277
+ // ---------------------------------------------------------------------------
278
+
1
279
  /**
2
280
  * Parse a single M3L file and return the AST as JSON.
3
281
  *
282
+ * The returned JSON string deserializes to `M3lResult<M3lAst>`.
283
+ *
4
284
  * @param content - M3L markdown text
5
285
  * @param filename - Source filename for error reporting
6
- * @returns JSON string with `{ success: boolean, data?: AST, error?: string }`
286
+ * @returns JSON string with `{ success: boolean, data?: M3lAst, error?: string }`
7
287
  */
8
288
  export function parse(content: string, filename: string): string;
9
289
 
10
290
  /**
11
291
  * Parse multiple M3L files and return the merged AST as JSON.
12
292
  *
13
- * @param filesJson - JSON array of `{ content: string, filename: string }` objects
14
- * @returns JSON string with `{ success: boolean, data?: AST, error?: string }`
293
+ * The returned JSON string deserializes to `M3lResult<M3lAst>`.
294
+ *
295
+ * @param filesJson - JSON array of `FileInput` objects
296
+ * @returns JSON string with `{ success: boolean, data?: M3lAst, error?: string }`
15
297
  */
16
298
  export function parseMulti(filesJson: string): string;
17
299
 
18
300
  /**
19
301
  * Validate M3L content and return diagnostics as JSON.
20
302
  *
303
+ * The returned JSON string deserializes to `M3lResult<ValidateResult>`.
304
+ *
21
305
  * @param content - M3L markdown text
22
- * @param optionsJson - JSON options `{ strict?: boolean, filename?: string }`
306
+ * @param optionsJson - JSON options (`ValidateOptions`)
23
307
  * @returns JSON string with `{ success: boolean, data?: ValidateResult, error?: string }`
24
308
  */
25
309
  export function validate(content: string, optionsJson: string): string;
310
+
311
+ /**
312
+ * Lint M3L content and return diagnostics as JSON.
313
+ *
314
+ * The returned JSON string deserializes to `M3lResult<LintResult>`.
315
+ *
316
+ * @param content - M3L markdown text
317
+ * @param configJson - JSON config (`LintConfig`)
318
+ * @returns JSON string with `{ success: boolean, data?: LintResult, error?: string }`
319
+ */
320
+ 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.0",
3
+ "version": "0.5.1",
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.0"
13
+ "@iyulab/m3l-napi": "0.5.1"
14
14
  },
15
15
  "engines": {
16
16
  "node": ">= 18"