@varavel/vdl-plugin-sdk 0.0.0 → 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 +0 -0
- package/README.md +168 -0
- package/bin/vdl-plugin.js +66 -0
- package/dist/{ir.cjs → index.cjs} +234 -2
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +373 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +373 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{ir.js → index.js} +219 -3
- package/dist/index.js.map +1 -0
- package/package.json +18 -5
- package/schemas/common/position.vdl +14 -0
- package/schemas/ir.vdl +319 -0
- package/schemas/plugin.vdl +19 -0
- package/schemas/plugin_input.vdl +30 -0
- package/schemas/plugin_output.vdl +72 -0
- package/src/define-plugin.ts +33 -0
- package/src/index.ts +7 -0
- package/src/runtime.ts +10 -0
- package/src/types/index.ts +10 -0
- package/src/{ir.ts → types/types.ts} +341 -282
- package/src/utils/annotations.test.ts +86 -0
- package/src/utils/annotations.ts +26 -0
- package/src/utils/literals.test.ts +115 -0
- package/src/utils/literals.ts +60 -0
- package/src/utils/options.test.ts +88 -0
- package/src/utils/options.ts +115 -0
- package/tsconfig.base.json +18 -0
- package/dist/ir.cjs.map +0 -1
- package/dist/ir.d.cts +0 -213
- package/dist/ir.d.cts.map +0 -1
- package/dist/ir.d.ts +0 -213
- package/dist/ir.d.ts.map +0 -1
- package/dist/ir.js.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
//#region src/runtime.d.ts
|
|
2
|
+
declare global {
|
|
3
|
+
const console: {
|
|
4
|
+
log(...args: unknown[]): void;
|
|
5
|
+
info(...args: unknown[]): void;
|
|
6
|
+
warn(...args: unknown[]): void;
|
|
7
|
+
error(...args: unknown[]): void;
|
|
8
|
+
};
|
|
9
|
+
} //# sourceMappingURL=runtime.d.ts.map
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/types.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Underlying storage kind used by an enum
|
|
14
|
+
*/
|
|
15
|
+
type EnumValueType = "string" | "int";
|
|
16
|
+
declare const EnumValueTypeList: EnumValueType[];
|
|
17
|
+
declare function isEnumValueType(value: unknown): value is EnumValueType;
|
|
18
|
+
/**
|
|
19
|
+
* Kind discriminator for LiteralValue.
|
|
20
|
+
*
|
|
21
|
+
* LiteralValue is used for fully resolved literal data in:
|
|
22
|
+
*
|
|
23
|
+
* - constant values
|
|
24
|
+
* - annotation arguments
|
|
25
|
+
*/
|
|
26
|
+
type LiteralKind = "string" | "int" | "float" | "bool" | "object" | "array";
|
|
27
|
+
declare const LiteralKindList: LiteralKind[];
|
|
28
|
+
declare function isLiteralKind(value: unknown): value is LiteralKind;
|
|
29
|
+
/**
|
|
30
|
+
* Primitive scalar type names
|
|
31
|
+
*/
|
|
32
|
+
type PrimitiveType = "string" | "int" | "float" | "bool" | "datetime";
|
|
33
|
+
declare const PrimitiveTypeList: PrimitiveType[];
|
|
34
|
+
declare function isPrimitiveType(value: unknown): value is PrimitiveType;
|
|
35
|
+
/**
|
|
36
|
+
* Kind discriminator for TypeRef
|
|
37
|
+
*/
|
|
38
|
+
type TypeKind = "primitive" | "type" | "enum" | "array" | "map" | "object";
|
|
39
|
+
declare const TypeKindList: TypeKind[];
|
|
40
|
+
declare function isTypeKind(value: unknown): value is TypeKind;
|
|
41
|
+
/**
|
|
42
|
+
* Annotation Annotation metadata preserved in IR.
|
|
43
|
+
*
|
|
44
|
+
* `name` is the annotation identifier without the `@` prefix.
|
|
45
|
+
* `argument`, when present, is fully resolved as a LiteralValue.
|
|
46
|
+
*/
|
|
47
|
+
type Annotation = {
|
|
48
|
+
position: Position;
|
|
49
|
+
name: string;
|
|
50
|
+
argument?: LiteralValue;
|
|
51
|
+
};
|
|
52
|
+
declare function hydrateAnnotation(input: Annotation): Annotation;
|
|
53
|
+
declare function validateAnnotation(input: unknown, path?: string): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* ConstantDef Fully resolved constant definition.
|
|
56
|
+
*
|
|
57
|
+
* `typeRef` is explicit or inferred by analysis.
|
|
58
|
+
* `value` contains the fully resolved literal payload.
|
|
59
|
+
*/
|
|
60
|
+
type ConstantDef = {
|
|
61
|
+
position: Position;
|
|
62
|
+
name: string;
|
|
63
|
+
doc?: string;
|
|
64
|
+
annotations: Annotation[];
|
|
65
|
+
typeRef: TypeRef;
|
|
66
|
+
value: LiteralValue;
|
|
67
|
+
};
|
|
68
|
+
declare function hydrateConstantDef(input: ConstantDef): ConstantDef;
|
|
69
|
+
declare function validateConstantDef(input: unknown, path?: string): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* EnumDef Flattened enum definition.
|
|
72
|
+
*
|
|
73
|
+
* All enum spreads are already expanded into `members`.
|
|
74
|
+
*/
|
|
75
|
+
type EnumDef = {
|
|
76
|
+
position: Position;
|
|
77
|
+
name: string;
|
|
78
|
+
doc?: string;
|
|
79
|
+
annotations: Annotation[];
|
|
80
|
+
enumType: EnumValueType;
|
|
81
|
+
members: EnumMember[];
|
|
82
|
+
};
|
|
83
|
+
declare function hydrateEnumDef(input: EnumDef): EnumDef;
|
|
84
|
+
declare function validateEnumDef(input: unknown, path?: string): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* EnumMember Enum member definition
|
|
87
|
+
*/
|
|
88
|
+
type EnumMember = {
|
|
89
|
+
position: Position;
|
|
90
|
+
name: string;
|
|
91
|
+
value: LiteralValue;
|
|
92
|
+
doc?: string;
|
|
93
|
+
annotations: Annotation[];
|
|
94
|
+
};
|
|
95
|
+
declare function hydrateEnumMember(input: EnumMember): EnumMember;
|
|
96
|
+
declare function validateEnumMember(input: unknown, path?: string): string | null;
|
|
97
|
+
/**
|
|
98
|
+
* Field Flattened object/type field definition
|
|
99
|
+
*/
|
|
100
|
+
type Field = {
|
|
101
|
+
position: Position;
|
|
102
|
+
name: string;
|
|
103
|
+
doc?: string;
|
|
104
|
+
optional: boolean;
|
|
105
|
+
annotations: Annotation[];
|
|
106
|
+
typeRef: TypeRef;
|
|
107
|
+
};
|
|
108
|
+
declare function hydrateField(input: Field): Field;
|
|
109
|
+
declare function validateField(input: unknown, path?: string): string | null;
|
|
110
|
+
/**
|
|
111
|
+
* IrSchema IrSchema is the generator-facing representation of a VDL program.
|
|
112
|
+
*
|
|
113
|
+
* This model is intentionally "flat" and "resolved":
|
|
114
|
+
*
|
|
115
|
+
* - spreads are already expanded
|
|
116
|
+
* - references are already resolved
|
|
117
|
+
* - collections are in deterministic order
|
|
118
|
+
*
|
|
119
|
+
* A code generator should be able to consume IrSchema directly, without needing
|
|
120
|
+
* to re-run parser or semantic-analysis logic.
|
|
121
|
+
*/
|
|
122
|
+
type IrSchema = {
|
|
123
|
+
entryPoint: string;
|
|
124
|
+
constants: ConstantDef[];
|
|
125
|
+
enums: EnumDef[];
|
|
126
|
+
types: TypeDef[];
|
|
127
|
+
docs: TopLevelDoc[];
|
|
128
|
+
};
|
|
129
|
+
declare function hydrateIrSchema(input: IrSchema): IrSchema;
|
|
130
|
+
declare function validateIrSchema(input: unknown, path?: string): string | null;
|
|
131
|
+
/**
|
|
132
|
+
* LiteralValue Fully resolved literal value.
|
|
133
|
+
*
|
|
134
|
+
* The selected payload is determined by `kind`:
|
|
135
|
+
*
|
|
136
|
+
* - `string` -> `stringValue`
|
|
137
|
+
* - `int` -> `intValue`
|
|
138
|
+
* - `float` -> `floatValue`
|
|
139
|
+
* - `bool` -> `boolValue`
|
|
140
|
+
* - `object` -> `objectEntries`
|
|
141
|
+
* - `array` -> `arrayItems`
|
|
142
|
+
*/
|
|
143
|
+
type LiteralValue = {
|
|
144
|
+
position: Position;
|
|
145
|
+
kind: LiteralKind;
|
|
146
|
+
stringValue?: string;
|
|
147
|
+
intValue?: number;
|
|
148
|
+
floatValue?: number;
|
|
149
|
+
boolValue?: boolean;
|
|
150
|
+
objectEntries?: ObjectEntry[];
|
|
151
|
+
arrayItems?: LiteralValue[];
|
|
152
|
+
};
|
|
153
|
+
declare function hydrateLiteralValue(input: LiteralValue): LiteralValue;
|
|
154
|
+
declare function validateLiteralValue(input: unknown, path?: string): string | null;
|
|
155
|
+
/**
|
|
156
|
+
* ObjectEntry Key/value pair inside an object LiteralValue payload
|
|
157
|
+
*/
|
|
158
|
+
type ObjectEntry = {
|
|
159
|
+
position: Position;
|
|
160
|
+
key: string;
|
|
161
|
+
value: LiteralValue;
|
|
162
|
+
};
|
|
163
|
+
declare function hydrateObjectEntry(input: ObjectEntry): ObjectEntry;
|
|
164
|
+
declare function validateObjectEntry(input: unknown, path?: string): string | null;
|
|
165
|
+
/**
|
|
166
|
+
* PluginInput PluginInput represents the data payload sent to a plugin.
|
|
167
|
+
*
|
|
168
|
+
* The plugin receives this as a single argument containing the complete
|
|
169
|
+
* Intermediate Representation of the VDL schema along with any user-defined
|
|
170
|
+
* configuration options from `vdl.config.vdl`.
|
|
171
|
+
*/
|
|
172
|
+
type PluginInput = {
|
|
173
|
+
version: string;
|
|
174
|
+
ir: IrSchema;
|
|
175
|
+
options: Record<string, string>;
|
|
176
|
+
};
|
|
177
|
+
declare function hydratePluginInput(input: PluginInput): PluginInput;
|
|
178
|
+
declare function validatePluginInput(input: unknown, path?: string): string | null;
|
|
179
|
+
/**
|
|
180
|
+
* PluginOutput PluginOutput represents the response payload returned by the `plugin` function.
|
|
181
|
+
*
|
|
182
|
+
* After processing the input schema, the plugin outputs this object containing
|
|
183
|
+
* all files to be generated or errors to be displayed to the user.
|
|
184
|
+
*
|
|
185
|
+
* If there are no errors and at least one file is returned, VDL will write each
|
|
186
|
+
* file to the specified path within the output directory. If there are errors,
|
|
187
|
+
* VDL will display them to the user and not write any files.
|
|
188
|
+
*/
|
|
189
|
+
type PluginOutput = {
|
|
190
|
+
files?: PluginOutputFile[];
|
|
191
|
+
errors?: PluginOutputError[];
|
|
192
|
+
};
|
|
193
|
+
declare function hydratePluginOutput(input: PluginOutput): PluginOutput;
|
|
194
|
+
declare function validatePluginOutput(input: unknown, path?: string): string | null;
|
|
195
|
+
/**
|
|
196
|
+
* PluginOutputError A structured error reported by the plugin.
|
|
197
|
+
*/
|
|
198
|
+
type PluginOutputError = {
|
|
199
|
+
message: string;
|
|
200
|
+
position?: Position;
|
|
201
|
+
};
|
|
202
|
+
declare function hydratePluginOutputError(input: PluginOutputError): PluginOutputError;
|
|
203
|
+
declare function validatePluginOutputError(input: unknown, path?: string): string | null;
|
|
204
|
+
/**
|
|
205
|
+
* PluginOutputFile PluginOutputFile represents a single generated file produced by the plugin.
|
|
206
|
+
*
|
|
207
|
+
* This abstraction allows plugins to generate multiple files from a single
|
|
208
|
+
* invocation, enabling patterns like one-file-per-type or splitting large
|
|
209
|
+
* outputs across multiple modules.
|
|
210
|
+
*/
|
|
211
|
+
type PluginOutputFile = {
|
|
212
|
+
path: string;
|
|
213
|
+
content: string;
|
|
214
|
+
};
|
|
215
|
+
declare function hydratePluginOutputFile(input: PluginOutputFile): PluginOutputFile;
|
|
216
|
+
declare function validatePluginOutputFile(_input: unknown, _path?: string): string | null;
|
|
217
|
+
/**
|
|
218
|
+
* Position It represents a position within a file and is used for error
|
|
219
|
+
* reporting, diagnostics, plugins, and tooling support.
|
|
220
|
+
*/
|
|
221
|
+
type Position = {
|
|
222
|
+
file: string;
|
|
223
|
+
line: number;
|
|
224
|
+
column: number;
|
|
225
|
+
};
|
|
226
|
+
declare function hydratePosition(input: Position): Position;
|
|
227
|
+
declare function validatePosition(_input: unknown, _path?: string): string | null;
|
|
228
|
+
/**
|
|
229
|
+
* TopLevelDoc Standalone documentation block.
|
|
230
|
+
*
|
|
231
|
+
* Used for top-level docstrings that are not attached to a type/enum/constant.
|
|
232
|
+
*/
|
|
233
|
+
type TopLevelDoc = {
|
|
234
|
+
position: Position;
|
|
235
|
+
content: string;
|
|
236
|
+
};
|
|
237
|
+
declare function hydrateTopLevelDoc(input: TopLevelDoc): TopLevelDoc;
|
|
238
|
+
declare function validateTopLevelDoc(input: unknown, path?: string): string | null;
|
|
239
|
+
/**
|
|
240
|
+
* TypeDef Flattened type definition.
|
|
241
|
+
*
|
|
242
|
+
* All spreads are already expanded. The unified `typeRef` describes what this
|
|
243
|
+
* type IS, a primitive, custom reference, map, array, or object with fields.
|
|
244
|
+
*/
|
|
245
|
+
type TypeDef = {
|
|
246
|
+
position: Position;
|
|
247
|
+
name: string;
|
|
248
|
+
doc?: string;
|
|
249
|
+
annotations: Annotation[];
|
|
250
|
+
typeRef: TypeRef;
|
|
251
|
+
};
|
|
252
|
+
declare function hydrateTypeDef(input: TypeDef): TypeDef;
|
|
253
|
+
declare function validateTypeDef(input: unknown, path?: string): string | null;
|
|
254
|
+
/**
|
|
255
|
+
* TypeRef Normalized type reference used by fields and constants.
|
|
256
|
+
*
|
|
257
|
+
* `kind` selects which payload fields are meaningful. Generators should inspect
|
|
258
|
+
* `kind` first, then read the related payload fields.
|
|
259
|
+
*/
|
|
260
|
+
type TypeRef = {
|
|
261
|
+
kind: TypeKind;
|
|
262
|
+
primitiveName?: PrimitiveType;
|
|
263
|
+
typeName?: string;
|
|
264
|
+
enumName?: string;
|
|
265
|
+
enumType?: EnumValueType;
|
|
266
|
+
arrayType?: TypeRef;
|
|
267
|
+
arrayDims?: number;
|
|
268
|
+
mapType?: TypeRef;
|
|
269
|
+
objectFields?: Field[];
|
|
270
|
+
};
|
|
271
|
+
declare function hydrateTypeRef(input: TypeRef): TypeRef;
|
|
272
|
+
declare function validateTypeRef(input: unknown, path?: string): string | null;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/define-plugin.d.ts
|
|
275
|
+
/**
|
|
276
|
+
* Defines a VDL plugin handler function.
|
|
277
|
+
*
|
|
278
|
+
* @param input - The input data for the plugin containing the IR and other relevant information.
|
|
279
|
+
* @returns The output data from the plugin containing the generated files and any errors.
|
|
280
|
+
*/
|
|
281
|
+
type VdlPluginHandler = (input: PluginInput) => PluginOutput;
|
|
282
|
+
/**
|
|
283
|
+
* Defines a VDL plugin by wrapping the provided handler function. This is a helper function
|
|
284
|
+
* that can be used to create plugins in a more concise way.
|
|
285
|
+
*
|
|
286
|
+
* Example usage:
|
|
287
|
+
* ```typescript
|
|
288
|
+
* import { definePlugin } from "@varavel/vdl-plugin-sdk";
|
|
289
|
+
*
|
|
290
|
+
* export const generate = definePlugin((input) => {
|
|
291
|
+
* // Plugin logic goes here
|
|
292
|
+
* return {
|
|
293
|
+
* files: [],
|
|
294
|
+
* errors: []
|
|
295
|
+
* };
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @param handler - The plugin handler function that contains the logic for processing the input and generating the output.
|
|
300
|
+
* @returns The same handler function, which can be exported as the plugin's main entry point.
|
|
301
|
+
*/
|
|
302
|
+
declare function definePlugin(handler: VdlPluginHandler): VdlPluginHandler;
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/utils/annotations.d.ts
|
|
305
|
+
/**
|
|
306
|
+
* Returns the first annotation that matches the provided name.
|
|
307
|
+
*/
|
|
308
|
+
declare function getAnnotation(annotations: Annotation[] | undefined, name: string): Annotation | undefined;
|
|
309
|
+
/**
|
|
310
|
+
* Returns the raw literal argument stored in an annotation.
|
|
311
|
+
*
|
|
312
|
+
* VDL annotations currently expose a single literal argument.
|
|
313
|
+
* Pair this helper with `unwrapLiteral` when you need a plain JavaScript value.
|
|
314
|
+
*/
|
|
315
|
+
declare function getAnnotationArgs(annotations: Annotation[] | undefined, name: string): LiteralValue | undefined;
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/utils/literals.d.ts
|
|
318
|
+
/**
|
|
319
|
+
* Native JavaScript value produced by `unwrapLiteral`.
|
|
320
|
+
*
|
|
321
|
+
* `undefined` is preserved when a literal is missing its kind-specific payload.
|
|
322
|
+
* `null` is returned for unknown literal kinds to keep the resolver non-throwing.
|
|
323
|
+
*/
|
|
324
|
+
type UnwrappedLiteral = string | number | boolean | null | undefined | UnwrappedLiteral[] | {
|
|
325
|
+
[key: string]: UnwrappedLiteral;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Resolves a `LiteralValue` into its native JavaScript representation.
|
|
329
|
+
*
|
|
330
|
+
* Pass a generic when you already know the expected shape.
|
|
331
|
+
* Omit it to get `unknown` and narrow the result yourself.
|
|
332
|
+
*
|
|
333
|
+
* The generic only affects TypeScript types. It does not validate the runtime value.
|
|
334
|
+
*/
|
|
335
|
+
declare function unwrapLiteral<T = unknown>(value: LiteralValue): T;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/utils/options.d.ts
|
|
338
|
+
/**
|
|
339
|
+
* Returns a string option or the provided fallback when the key is missing.
|
|
340
|
+
*/
|
|
341
|
+
declare function getOptionString(options: Record<string, string> | undefined, key: string, defaultValue: string): string;
|
|
342
|
+
/**
|
|
343
|
+
* Returns a boolean option using common truthy and falsy string values.
|
|
344
|
+
*
|
|
345
|
+
* Accepted truthy values: `true`, `1`, `yes`, `on`, `enable`, `enabled`, `y`.
|
|
346
|
+
*
|
|
347
|
+
* Accepted falsy values: `false`, `0`, `no`, `off`, `disable`, `disabled`, `n`.
|
|
348
|
+
*
|
|
349
|
+
* Invalid values fall back to the provided default.
|
|
350
|
+
*/
|
|
351
|
+
declare function getOptionBool(options: Record<string, string> | undefined, key: string, defaultValue: boolean): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Returns a numeric option or the provided fallback when parsing fails.
|
|
354
|
+
*
|
|
355
|
+
* Empty, invalid, and non-finite values fall back to the default.
|
|
356
|
+
*/
|
|
357
|
+
declare function getOptionNumber(options: Record<string, string> | undefined, key: string, defaultValue: number): number;
|
|
358
|
+
/**
|
|
359
|
+
* Returns a string array option from a separator-delimited value.
|
|
360
|
+
*
|
|
361
|
+
* Empty items are removed and each entry is trimmed.
|
|
362
|
+
*
|
|
363
|
+
* Missing values return the provided default.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* // For options: { "features": "feature1, feature2, feature3" }
|
|
367
|
+
* getOptionArray(options, "features", [], ",")
|
|
368
|
+
* // returns ["feature1", "feature2", "feature3"]
|
|
369
|
+
*/
|
|
370
|
+
declare function getOptionArray(options: Record<string, string> | undefined, key: string, defaultValue?: string[], separator?: string): string[];
|
|
371
|
+
//#endregion
|
|
372
|
+
export { Annotation, ConstantDef, EnumDef, EnumMember, EnumValueType, EnumValueTypeList, Field, IrSchema, LiteralKind, LiteralKindList, LiteralValue, ObjectEntry, PluginInput, PluginOutput, PluginOutputError, PluginOutputFile, Position, PrimitiveType, PrimitiveTypeList, TopLevelDoc, TypeDef, TypeKind, TypeKindList, TypeRef, UnwrappedLiteral, VdlPluginHandler, definePlugin, getAnnotation, getAnnotationArgs, getOptionArray, getOptionBool, getOptionNumber, getOptionString, hydrateAnnotation, hydrateConstantDef, hydrateEnumDef, hydrateEnumMember, hydrateField, hydrateIrSchema, hydrateLiteralValue, hydrateObjectEntry, hydratePluginInput, hydratePluginOutput, hydratePluginOutputError, hydratePluginOutputFile, hydratePosition, hydrateTopLevelDoc, hydrateTypeDef, hydrateTypeRef, isEnumValueType, isLiteralKind, isPrimitiveType, isTypeKind, unwrapLiteral, validateAnnotation, validateConstantDef, validateEnumDef, validateEnumMember, validateField, validateIrSchema, validateLiteralValue, validateObjectEntry, validatePluginInput, validatePluginOutput, validatePluginOutputError, validatePluginOutputFile, validatePosition, validateTopLevelDoc, validateTypeDef, validateTypeRef };
|
|
373
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/runtime.ts","../src/types/types.ts","../src/define-plugin.ts","../src/utils/annotations.ts","../src/utils/literals.ts","../src/utils/options.ts"],"mappings":";QAEQ,MAAA;EAAA,MACA,OAAA;IACJ,GAAA,IAAO,IAAA;IACP,IAAA,IAAQ,IAAA;IACR,IAAA,IAAQ,IAAA;IACR,KAAA,IAAS,IAAA;EAAA;AAAA;;;;AAPH;;KCgBE,aAAA;AAAA,cAEC,iBAAA,EAAm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A;EACA,OAAA,GAAU,OAAA;EACV,YAAA,GAAe,KAAA;AAAA;AAAA,iBAGD,cAAA,CAAe,KAAA,EAAO,OAAA,GAAU,OAAA;AAAA,iBAuBhC,eAAA,CAAgB,KAAA,WAAgB,IAAA;;;ADt9BtC;;;;;;AAAA,KEQE,gBAAA,IAAoB,KAAA,EAAO,WAAA,KAAgB,YAAA;;;;;;;;;;;;;;ADQvD;;;;;AAEA;;iBCYgB,YAAA,CAAa,OAAA,EAAS,gBAAA,GAAmB,gBAAA;;;AF9B/C;;;AAAA,iBGKM,aAAA,CACd,WAAA,EAAa,UAAA,gBACb,IAAA,WACC,UAAA;;;;;;;iBAWa,iBAAA,CACd,WAAA,EAAa,UAAA,gBACb,IAAA,WACC,YAAA;;;AHtBO;;;;;;AAAA,KIQE,gBAAA,kDAMR,gBAAA;EAAA,CACG,GAAA,WAAc,gBAAA;AAAA;;;;;;;;;iBAUL,aAAA,aAAA,CAA2B,KAAA,EAAO,YAAA,GAAe,CAAA;;;;AJzBvD;;iBKGM,eAAA,CACd,OAAA,EAAS,MAAA,8BACT,GAAA,UACA,YAAA;;;;;;;;;;iBAec,aAAA,CACd,OAAA,EAAS,MAAA,8BACT,GAAA,UACA,YAAA;;;;;;iBAmCc,eAAA,CACd,OAAA,EAAS,MAAA,8BACT,GAAA,UACA,YAAA;;AJ9CF;;;;;AAEA;;;;;AAKA;iBIqEgB,cAAA,CACd,OAAA,EAAS,MAAA,8BACT,GAAA,UACA,YAAA,aACA,SAAA"}
|
package/dist/{ir.js → index.js}
RENAMED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/define-plugin.ts
|
|
2
|
+
/**
|
|
3
|
+
* Defines a VDL plugin by wrapping the provided handler function. This is a helper function
|
|
4
|
+
* that can be used to create plugins in a more concise way.
|
|
5
|
+
*
|
|
6
|
+
* Example usage:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { definePlugin } from "@varavel/vdl-plugin-sdk";
|
|
9
|
+
*
|
|
10
|
+
* export const generate = definePlugin((input) => {
|
|
11
|
+
* // Plugin logic goes here
|
|
12
|
+
* return {
|
|
13
|
+
* files: [],
|
|
14
|
+
* errors: []
|
|
15
|
+
* };
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param handler - The plugin handler function that contains the logic for processing the input and generating the output.
|
|
20
|
+
* @returns The same handler function, which can be exported as the plugin's main entry point.
|
|
21
|
+
*/
|
|
22
|
+
function definePlugin(handler) {
|
|
23
|
+
return handler;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/types/types.ts
|
|
2
27
|
const EnumValueTypeList = ["string", "int"];
|
|
3
28
|
function isEnumValueType(value) {
|
|
4
29
|
return EnumValueTypeList.includes(value);
|
|
@@ -285,6 +310,72 @@ function validateObjectEntry(input, path = "ObjectEntry") {
|
|
|
285
310
|
}
|
|
286
311
|
return null;
|
|
287
312
|
}
|
|
313
|
+
function hydratePluginInput(input) {
|
|
314
|
+
return {
|
|
315
|
+
version: input.version,
|
|
316
|
+
ir: hydrateIrSchema(input.ir),
|
|
317
|
+
options: input.options
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function validatePluginInput(input, path = "PluginInput") {
|
|
321
|
+
if (input === null || input === void 0 || typeof input !== "object") return `${path}: expected object, got ${typeof input}`;
|
|
322
|
+
const obj = input;
|
|
323
|
+
if (obj.ir === void 0 || obj.ir === null) return `${path}.ir: required field is missing`;
|
|
324
|
+
{
|
|
325
|
+
const err = validateIrSchema(obj.ir, `${path}.ir`);
|
|
326
|
+
if (err !== null) return err;
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
function hydratePluginOutput(input) {
|
|
331
|
+
return {
|
|
332
|
+
files: input.files ? input.files.map((el) => hydratePluginOutputFile(el)) : input.files,
|
|
333
|
+
errors: input.errors ? input.errors.map((el) => hydratePluginOutputError(el)) : input.errors
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function validatePluginOutput(input, path = "PluginOutput") {
|
|
337
|
+
if (input === null || input === void 0 || typeof input !== "object") return `${path}: expected object, got ${typeof input}`;
|
|
338
|
+
const obj = input;
|
|
339
|
+
if (obj.files !== void 0 && obj.files !== null) {
|
|
340
|
+
if (!Array.isArray(obj.files)) return `${path}.files: expected array, got ${typeof obj.files}`;
|
|
341
|
+
for (let i = 0; i < obj.files.length; i++) {
|
|
342
|
+
const err = validatePluginOutputFile(obj.files[i], `${path}.files[${i}]`);
|
|
343
|
+
if (err !== null) return err;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (obj.errors !== void 0 && obj.errors !== null) {
|
|
347
|
+
if (!Array.isArray(obj.errors)) return `${path}.errors: expected array, got ${typeof obj.errors}`;
|
|
348
|
+
for (let i = 0; i < obj.errors.length; i++) {
|
|
349
|
+
const err = validatePluginOutputError(obj.errors[i], `${path}.errors[${i}]`);
|
|
350
|
+
if (err !== null) return err;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
function hydratePluginOutputError(input) {
|
|
356
|
+
return {
|
|
357
|
+
message: input.message,
|
|
358
|
+
position: input.position ? hydratePosition(input.position) : input.position
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function validatePluginOutputError(input, path = "PluginOutputError") {
|
|
362
|
+
if (input === null || input === void 0 || typeof input !== "object") return `${path}: expected object, got ${typeof input}`;
|
|
363
|
+
const obj = input;
|
|
364
|
+
if (obj.position !== void 0 && obj.position !== null) {
|
|
365
|
+
const err = validatePosition(obj.position, `${path}.position`);
|
|
366
|
+
if (err !== null) return err;
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
function hydratePluginOutputFile(input) {
|
|
371
|
+
return {
|
|
372
|
+
path: input.path,
|
|
373
|
+
content: input.content
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function validatePluginOutputFile(_input, _path = "PluginOutputFile") {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
288
379
|
function hydratePosition(input) {
|
|
289
380
|
return {
|
|
290
381
|
file: input.file,
|
|
@@ -383,6 +474,131 @@ function validateTypeRef(input, path = "TypeRef") {
|
|
|
383
474
|
return null;
|
|
384
475
|
}
|
|
385
476
|
//#endregion
|
|
386
|
-
|
|
477
|
+
//#region src/utils/annotations.ts
|
|
478
|
+
/**
|
|
479
|
+
* Returns the first annotation that matches the provided name.
|
|
480
|
+
*/
|
|
481
|
+
function getAnnotation(annotations, name) {
|
|
482
|
+
if (!annotations) return void 0;
|
|
483
|
+
return annotations.find((anno) => anno.name === name);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Returns the raw literal argument stored in an annotation.
|
|
487
|
+
*
|
|
488
|
+
* VDL annotations currently expose a single literal argument.
|
|
489
|
+
* Pair this helper with `unwrapLiteral` when you need a plain JavaScript value.
|
|
490
|
+
*/
|
|
491
|
+
function getAnnotationArgs(annotations, name) {
|
|
492
|
+
const anno = getAnnotation(annotations, name);
|
|
493
|
+
return anno === null || anno === void 0 ? void 0 : anno.argument;
|
|
494
|
+
}
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/utils/literals.ts
|
|
497
|
+
/**
|
|
498
|
+
* Resolves a `LiteralValue` into its native JavaScript representation.
|
|
499
|
+
*
|
|
500
|
+
* Pass a generic when you already know the expected shape.
|
|
501
|
+
* Omit it to get `unknown` and narrow the result yourself.
|
|
502
|
+
*
|
|
503
|
+
* The generic only affects TypeScript types. It does not validate the runtime value.
|
|
504
|
+
*/
|
|
505
|
+
function unwrapLiteral(value) {
|
|
506
|
+
return unwrapLiteralValue(value);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Performs the recursive literal resolution used by `unwrapLiteral`.
|
|
510
|
+
*/
|
|
511
|
+
function unwrapLiteralValue(value) {
|
|
512
|
+
switch (value.kind) {
|
|
513
|
+
case "string": return value.stringValue;
|
|
514
|
+
case "int": return value.intValue;
|
|
515
|
+
case "float": return value.floatValue;
|
|
516
|
+
case "bool": return value.boolValue;
|
|
517
|
+
case "object": {
|
|
518
|
+
var _value$objectEntries;
|
|
519
|
+
const resolvedObject = {};
|
|
520
|
+
const entries = (_value$objectEntries = value.objectEntries) !== null && _value$objectEntries !== void 0 ? _value$objectEntries : [];
|
|
521
|
+
for (const entry of entries) resolvedObject[entry.key] = unwrapLiteralValue(entry.value);
|
|
522
|
+
return resolvedObject;
|
|
523
|
+
}
|
|
524
|
+
case "array":
|
|
525
|
+
var _value$arrayItems;
|
|
526
|
+
return ((_value$arrayItems = value.arrayItems) !== null && _value$arrayItems !== void 0 ? _value$arrayItems : []).map((item) => unwrapLiteralValue(item));
|
|
527
|
+
default: return null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/utils/options.ts
|
|
532
|
+
/**
|
|
533
|
+
* Returns a string option or the provided fallback when the key is missing.
|
|
534
|
+
*/
|
|
535
|
+
function getOptionString(options, key, defaultValue) {
|
|
536
|
+
const value = options === null || options === void 0 ? void 0 : options[key];
|
|
537
|
+
return value === void 0 ? defaultValue : value;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Returns a boolean option using common truthy and falsy string values.
|
|
541
|
+
*
|
|
542
|
+
* Accepted truthy values: `true`, `1`, `yes`, `on`, `enable`, `enabled`, `y`.
|
|
543
|
+
*
|
|
544
|
+
* Accepted falsy values: `false`, `0`, `no`, `off`, `disable`, `disabled`, `n`.
|
|
545
|
+
*
|
|
546
|
+
* Invalid values fall back to the provided default.
|
|
547
|
+
*/
|
|
548
|
+
function getOptionBool(options, key, defaultValue) {
|
|
549
|
+
const value = options === null || options === void 0 ? void 0 : options[key];
|
|
550
|
+
if (value === void 0) return defaultValue;
|
|
551
|
+
switch (value.trim().toLowerCase()) {
|
|
552
|
+
case "true":
|
|
553
|
+
case "1":
|
|
554
|
+
case "yes":
|
|
555
|
+
case "on":
|
|
556
|
+
case "enable":
|
|
557
|
+
case "enabled":
|
|
558
|
+
case "y": return true;
|
|
559
|
+
case "false":
|
|
560
|
+
case "0":
|
|
561
|
+
case "no":
|
|
562
|
+
case "off":
|
|
563
|
+
case "disable":
|
|
564
|
+
case "disabled":
|
|
565
|
+
case "n": return false;
|
|
566
|
+
default: return defaultValue;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Returns a numeric option or the provided fallback when parsing fails.
|
|
571
|
+
*
|
|
572
|
+
* Empty, invalid, and non-finite values fall back to the default.
|
|
573
|
+
*/
|
|
574
|
+
function getOptionNumber(options, key, defaultValue) {
|
|
575
|
+
const value = options === null || options === void 0 ? void 0 : options[key];
|
|
576
|
+
if (value === void 0) return defaultValue;
|
|
577
|
+
const trimmedValue = value.trim();
|
|
578
|
+
if (trimmedValue === "") return defaultValue;
|
|
579
|
+
const parsedValue = Number(trimmedValue);
|
|
580
|
+
return Number.isFinite(parsedValue) ? parsedValue : defaultValue;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Returns a string array option from a separator-delimited value.
|
|
584
|
+
*
|
|
585
|
+
* Empty items are removed and each entry is trimmed.
|
|
586
|
+
*
|
|
587
|
+
* Missing values return the provided default.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* // For options: { "features": "feature1, feature2, feature3" }
|
|
591
|
+
* getOptionArray(options, "features", [], ",")
|
|
592
|
+
* // returns ["feature1", "feature2", "feature3"]
|
|
593
|
+
*/
|
|
594
|
+
function getOptionArray(options, key, defaultValue = [], separator = ",") {
|
|
595
|
+
const value = options === null || options === void 0 ? void 0 : options[key];
|
|
596
|
+
if (value === void 0) return defaultValue;
|
|
597
|
+
const trimmedValue = value.trim();
|
|
598
|
+
if (trimmedValue === "") return [];
|
|
599
|
+
return trimmedValue.split(separator).map((item) => item.trim()).filter((item) => item.length > 0);
|
|
600
|
+
}
|
|
601
|
+
//#endregion
|
|
602
|
+
export { EnumValueTypeList, LiteralKindList, PrimitiveTypeList, TypeKindList, definePlugin, getAnnotation, getAnnotationArgs, getOptionArray, getOptionBool, getOptionNumber, getOptionString, hydrateAnnotation, hydrateConstantDef, hydrateEnumDef, hydrateEnumMember, hydrateField, hydrateIrSchema, hydrateLiteralValue, hydrateObjectEntry, hydratePluginInput, hydratePluginOutput, hydratePluginOutputError, hydratePluginOutputFile, hydratePosition, hydrateTopLevelDoc, hydrateTypeDef, hydrateTypeRef, isEnumValueType, isLiteralKind, isPrimitiveType, isTypeKind, unwrapLiteral, validateAnnotation, validateConstantDef, validateEnumDef, validateEnumMember, validateField, validateIrSchema, validateLiteralValue, validateObjectEntry, validatePluginInput, validatePluginOutput, validatePluginOutputError, validatePluginOutputFile, validatePosition, validateTopLevelDoc, validateTypeDef, validateTypeRef };
|
|
387
603
|
|
|
388
|
-
//# sourceMappingURL=
|
|
604
|
+
//# sourceMappingURL=index.js.map
|