@morphql/language-definitions 0.1.3 → 0.1.5

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.
@@ -0,0 +1,495 @@
1
+ {
2
+ "keywords": [
3
+ {
4
+ "name": "from",
5
+ "category": "control",
6
+ "doc": {
7
+ "signature": "from <format>",
8
+ "description": "Specifies the input data format.",
9
+ "parameters": [
10
+ {
11
+ "name": "format",
12
+ "description": "If used as first keyword: The starting format, one of `json`, `xml`, or `object`. When used after a section, defines its source"
13
+ }
14
+ ],
15
+ "example": "from json to xml"
16
+ }
17
+ },
18
+ {
19
+ "name": "to",
20
+ "category": "control",
21
+ "doc": {
22
+ "signature": "to <format>",
23
+ "description": "Specifies the output data format.",
24
+ "parameters": [
25
+ {
26
+ "name": "format",
27
+ "description": "One of: `json`, `xml`, or `object`"
28
+ }
29
+ ],
30
+ "example": "from json to xml"
31
+ }
32
+ },
33
+ {
34
+ "name": "transform",
35
+ "category": "control",
36
+ "doc": {
37
+ "signature": "transform",
38
+ "description": "Begins the transformation block containing actions.",
39
+ "example": "transform\n set name = firstName"
40
+ }
41
+ },
42
+ {
43
+ "name": "set",
44
+ "category": "action",
45
+ "doc": {
46
+ "signature": "set <target> = <expression>",
47
+ "description": "Assigns a value to a field in the output.",
48
+ "parameters": [
49
+ {
50
+ "name": "target",
51
+ "description": "The field name to set"
52
+ },
53
+ {
54
+ "name": "expression",
55
+ "description": "The value or expression to assign"
56
+ }
57
+ ],
58
+ "example": "set fullName = firstName + \" \" + lastName"
59
+ }
60
+ },
61
+ {
62
+ "name": "section",
63
+ "category": "action",
64
+ "doc": {
65
+ "signature": "section [multiple] <name>( [subquery] <actions> ) [from <path>]",
66
+ "description": "Creates a nested object or array in the output. Can optionally include a subquery for format conversion.",
67
+ "parameters": [
68
+ {
69
+ "name": "multiple",
70
+ "description": "(Optional) Treat as array mapping"
71
+ },
72
+ {
73
+ "name": "name",
74
+ "description": "The section/field name"
75
+ },
76
+ {
77
+ "name": "subquery",
78
+ "description": "(Optional) Nested query: from <format> to <format> [transform]"
79
+ },
80
+ {
81
+ "name": "actions",
82
+ "description": "Actions to perform within the section"
83
+ },
84
+ {
85
+ "name": "from",
86
+ "description": "(Optional) Source path for the section data"
87
+ }
88
+ ],
89
+ "example": "section metadata(\n from xml to object\n transform\n set name = root.productName\n) from xmlString"
90
+ }
91
+ },
92
+ {
93
+ "name": "multiple",
94
+ "category": "action",
95
+ "doc": {
96
+ "signature": "section multiple <name>(...)",
97
+ "description": "Modifier for `section` to map over an array.",
98
+ "example": "section multiple items(\n set id = itemId\n) from products"
99
+ }
100
+ },
101
+ {
102
+ "name": "clone",
103
+ "category": "action",
104
+ "doc": {
105
+ "signature": "clone([field1, field2, ...])",
106
+ "description": "Copies fields from the source to the output.",
107
+ "parameters": [
108
+ {
109
+ "name": "fields",
110
+ "description": "(Optional) Specific fields to clone. If omitted, clones all fields."
111
+ }
112
+ ],
113
+ "example": "clone(id, name, email)"
114
+ }
115
+ },
116
+ {
117
+ "name": "delete",
118
+ "category": "action",
119
+ "doc": {
120
+ "signature": "delete <field>",
121
+ "description": "Removes a field from the output (useful after `clone`).",
122
+ "parameters": [
123
+ {
124
+ "name": "field",
125
+ "description": "The field name to delete"
126
+ }
127
+ ],
128
+ "example": "clone()\ndelete password"
129
+ }
130
+ },
131
+ {
132
+ "name": "define",
133
+ "category": "action",
134
+ "doc": {
135
+ "signature": "define <alias> = <expression>",
136
+ "description": "Creates a local variable/alias for use in subsequent expressions.",
137
+ "parameters": [
138
+ {
139
+ "name": "alias",
140
+ "description": "The variable name"
141
+ },
142
+ {
143
+ "name": "expression",
144
+ "description": "The value to assign"
145
+ }
146
+ ],
147
+ "example": "define taxRate = 0.22\nset totalWithTax = total * (1 + taxRate)"
148
+ }
149
+ },
150
+ {
151
+ "name": "if",
152
+ "category": "control",
153
+ "doc": {
154
+ "signature": "if (condition) ( actions ) [else ( actions )]",
155
+ "description": "Conditional execution of action blocks.",
156
+ "parameters": [
157
+ {
158
+ "name": "condition",
159
+ "description": "Boolean expression"
160
+ },
161
+ {
162
+ "name": "actions",
163
+ "description": "Actions to execute if true/false"
164
+ }
165
+ ],
166
+ "example": "if (age >= 18) (\n set status = \"adult\"\n) else (\n set status = \"minor\"\n)"
167
+ }
168
+ },
169
+ {
170
+ "name": "else",
171
+ "category": "control",
172
+ "doc": {
173
+ "signature": "else ( actions )",
174
+ "description": "Defines the else branch of an `if` statement.",
175
+ "example": "if (condition) (\n ...\n) else (\n ...\n)"
176
+ }
177
+ },
178
+ {
179
+ "name": "modify",
180
+ "category": "action",
181
+ "doc": {
182
+ "signature": "modify <target> = <expression>",
183
+ "description": "Modifies a field in the output by reading from the target (not source). Useful for post-processing already-mapped values.",
184
+ "parameters": [
185
+ {
186
+ "name": "target",
187
+ "description": "The field name to modify"
188
+ },
189
+ {
190
+ "name": "expression",
191
+ "description": "The expression to assign (reads from target, not source)"
192
+ }
193
+ ],
194
+ "example": "set total = price * quantity\nmodify total = total * 1.10"
195
+ }
196
+ }
197
+ ],
198
+ "functions": [
199
+ {
200
+ "name": "substring",
201
+ "doc": {
202
+ "signature": "substring(str, start, [length])",
203
+ "description": "Extracts a portion of a string. Supports negative indices.",
204
+ "parameters": [
205
+ {
206
+ "name": "str",
207
+ "description": "The source string"
208
+ },
209
+ {
210
+ "name": "start",
211
+ "description": "Starting index (0-based, negative counts from end)"
212
+ },
213
+ {
214
+ "name": "length",
215
+ "description": "(Optional) Number of characters to extract"
216
+ }
217
+ ],
218
+ "returns": "string",
219
+ "example": "substring(\"Hello World\", 0, 5) // \"Hello\"\nsubstring(\"Hello World\", -5) // \"World\""
220
+ }
221
+ },
222
+ {
223
+ "name": "split",
224
+ "doc": {
225
+ "signature": "split(str, [separator], [limit])",
226
+ "description": "Splits a string into an array.",
227
+ "parameters": [
228
+ {
229
+ "name": "str",
230
+ "description": "The string to split"
231
+ },
232
+ {
233
+ "name": "separator",
234
+ "description": "(Optional) Delimiter string. Default: \"\""
235
+ },
236
+ {
237
+ "name": "limit",
238
+ "description": "(Optional) Maximum number of splits"
239
+ }
240
+ ],
241
+ "returns": "array",
242
+ "example": "split(\"a,b,c\", \",\") // [\"a\", \"b\", \"c\"]"
243
+ }
244
+ },
245
+ {
246
+ "name": "replace",
247
+ "doc": {
248
+ "signature": "replace(str, search, replacement)",
249
+ "description": "Replaces occurrences in a string.",
250
+ "parameters": [
251
+ {
252
+ "name": "str",
253
+ "description": "The source string"
254
+ },
255
+ {
256
+ "name": "search",
257
+ "description": "The substring to find"
258
+ },
259
+ {
260
+ "name": "replacement",
261
+ "description": "The replacement string"
262
+ }
263
+ ],
264
+ "returns": "string",
265
+ "example": "replace(\"Hello World\", \"World\", \"MorphQL\") // \"Hello MorphQL\""
266
+ }
267
+ },
268
+ {
269
+ "name": "text",
270
+ "doc": {
271
+ "signature": "text(value)",
272
+ "description": "Converts a value to a string.",
273
+ "parameters": [
274
+ {
275
+ "name": "value",
276
+ "description": "The value to convert"
277
+ }
278
+ ],
279
+ "returns": "string",
280
+ "example": "text(123) // \"123\""
281
+ }
282
+ },
283
+ {
284
+ "name": "number",
285
+ "doc": {
286
+ "signature": "number(value)",
287
+ "description": "Converts a value to a number.",
288
+ "parameters": [
289
+ {
290
+ "name": "value",
291
+ "description": "The value to convert"
292
+ }
293
+ ],
294
+ "returns": "number",
295
+ "example": "number(\"42\") // 42"
296
+ }
297
+ },
298
+ {
299
+ "name": "uppercase",
300
+ "doc": {
301
+ "signature": "uppercase(str)",
302
+ "description": "Converts a string to uppercase.",
303
+ "parameters": [
304
+ {
305
+ "name": "str",
306
+ "description": "The string to convert"
307
+ }
308
+ ],
309
+ "returns": "string",
310
+ "example": "uppercase(\"hello\") // \"HELLO\""
311
+ }
312
+ },
313
+ {
314
+ "name": "lowercase",
315
+ "doc": {
316
+ "signature": "lowercase(str)",
317
+ "description": "Converts a string to lowercase.",
318
+ "parameters": [
319
+ {
320
+ "name": "str",
321
+ "description": "The string to convert"
322
+ }
323
+ ],
324
+ "returns": "string",
325
+ "example": "lowercase(\"HELLO\") // \"hello\""
326
+ }
327
+ },
328
+ {
329
+ "name": "extractnumber",
330
+ "doc": {
331
+ "signature": "extractnumber(str)",
332
+ "description": "Extracts the first numeric sequence from a string.",
333
+ "parameters": [
334
+ {
335
+ "name": "str",
336
+ "description": "The string to extract from"
337
+ }
338
+ ],
339
+ "returns": "number",
340
+ "example": "extractnumber(\"Price: 100USD\") // 100"
341
+ }
342
+ },
343
+ {
344
+ "name": "xmlnode",
345
+ "doc": {
346
+ "signature": "xmlnode(value, [attrKey, attrVal, ...])",
347
+ "description": "Wraps a value for XML output with optional attributes.",
348
+ "parameters": [
349
+ {
350
+ "name": "value",
351
+ "description": "The node content"
352
+ },
353
+ {
354
+ "name": "attrKey, attrVal",
355
+ "description": "(Optional) Pairs of attribute keys and values"
356
+ }
357
+ ],
358
+ "returns": "XML node",
359
+ "example": "xmlnode(content, \"id\", 1, \"type\", \"text\")"
360
+ }
361
+ },
362
+ {
363
+ "name": "to_base64",
364
+ "doc": {
365
+ "signature": "to_base64(value)",
366
+ "description": "Encodes a string value to Base64.",
367
+ "parameters": [
368
+ {
369
+ "name": "value",
370
+ "description": "The string to encode"
371
+ }
372
+ ],
373
+ "returns": "string",
374
+ "example": "to_base64(\"hello\") // \"aGVsbG8=\""
375
+ }
376
+ },
377
+ {
378
+ "name": "from_base64",
379
+ "doc": {
380
+ "signature": "from_base64(value)",
381
+ "description": "Decodes a Base64 string value.",
382
+ "parameters": [
383
+ {
384
+ "name": "value",
385
+ "description": "The Base64 string to decode"
386
+ }
387
+ ],
388
+ "returns": "string",
389
+ "example": "from_base64(\"aGVsbG8=\") // \"hello\""
390
+ }
391
+ },
392
+ {
393
+ "name": "aslist",
394
+ "doc": {
395
+ "signature": "aslist(value)",
396
+ "description": "Ensures a value is an array. Useful for XML nodes that might be a single object or an array.",
397
+ "parameters": [
398
+ {
399
+ "name": "value",
400
+ "description": "The value to normalize"
401
+ }
402
+ ],
403
+ "returns": "array",
404
+ "example": "aslist(items) // Always returns an array"
405
+ }
406
+ }
407
+ ],
408
+ "operators": [
409
+ {
410
+ "symbol": "===",
411
+ "category": "comparison",
412
+ "precedence": 7
413
+ },
414
+ {
415
+ "symbol": "!==",
416
+ "category": "comparison",
417
+ "precedence": 7
418
+ },
419
+ {
420
+ "symbol": "==",
421
+ "category": "comparison",
422
+ "precedence": 7
423
+ },
424
+ {
425
+ "symbol": "!=",
426
+ "category": "comparison",
427
+ "precedence": 7
428
+ },
429
+ {
430
+ "symbol": "<=",
431
+ "category": "comparison",
432
+ "precedence": 6
433
+ },
434
+ {
435
+ "symbol": ">=",
436
+ "category": "comparison",
437
+ "precedence": 6
438
+ },
439
+ {
440
+ "symbol": "<",
441
+ "category": "comparison",
442
+ "precedence": 6
443
+ },
444
+ {
445
+ "symbol": ">",
446
+ "category": "comparison",
447
+ "precedence": 6
448
+ },
449
+ {
450
+ "symbol": "&&",
451
+ "category": "logical",
452
+ "precedence": 5
453
+ },
454
+ {
455
+ "symbol": "||",
456
+ "category": "logical",
457
+ "precedence": 4
458
+ },
459
+ {
460
+ "symbol": "!",
461
+ "category": "logical",
462
+ "precedence": 9
463
+ },
464
+ {
465
+ "symbol": "+",
466
+ "category": "arithmetic",
467
+ "precedence": 10
468
+ },
469
+ {
470
+ "symbol": "-",
471
+ "category": "arithmetic",
472
+ "precedence": 10
473
+ },
474
+ {
475
+ "symbol": "*",
476
+ "category": "arithmetic",
477
+ "precedence": 11
478
+ },
479
+ {
480
+ "symbol": "/",
481
+ "category": "arithmetic",
482
+ "precedence": 11
483
+ },
484
+ {
485
+ "symbol": "=",
486
+ "category": "assignment",
487
+ "precedence": 1
488
+ }
489
+ ],
490
+ "comments": {
491
+ "line": "//",
492
+ "blockStart": "/*",
493
+ "blockEnd": "*/"
494
+ }
495
+ }
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@morphql/language-definitions",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Shared language definitions for MorphQL across VSCode, Monaco, and documentation",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
9
14
  "main": "./dist/index.cjs",
10
15
  "module": "./dist/index.js",
11
16
  "types": "./dist/index.d.ts",
@@ -28,8 +33,17 @@
28
33
  "vscode",
29
34
  "monaco"
30
35
  ],
31
- "author": "",
36
+ "author": "Hyperwindmill",
32
37
  "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/Hyperwindmill/morphql.git",
41
+ "directory": "packages/language-definitions"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/Hyperwindmill/morphql/issues"
45
+ },
46
+ "homepage": "https://github.com/Hyperwindmill/morphql/tree/main/packages/language-definitions#readme",
33
47
  "devDependencies": {
34
48
  "tsup": "^8.0.0",
35
49
  "tsx": "^4.0.0",
package/export-json.ts DELETED
@@ -1,107 +0,0 @@
1
- import { MORPHQL_LANGUAGE } from "./src/index";
2
- import fs from "fs";
3
- import path from "path";
4
- import { fileURLToPath } from "url";
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- const distDir = path.resolve(__dirname, "dist");
10
- if (!fs.existsSync(distDir)) {
11
- fs.mkdirSync(distDir, { recursive: true });
12
- }
13
-
14
- // 1. Export JSON
15
- const jsonPath = path.resolve(distDir, "morphql-lang.json");
16
- fs.writeFileSync(jsonPath, JSON.stringify(MORPHQL_LANGUAGE, null, 2));
17
- console.log(`Language definitions exported to ${jsonPath}`);
18
-
19
- // 2. Export Kotlin Constants
20
- const constantsPath = path.resolve(
21
- __dirname,
22
- "../jetbrains-extension/src/main/kotlin/org/morphql/jetbrains/MorphQLConstants.kt",
23
- );
24
-
25
- const keywords = MORPHQL_LANGUAGE.keywords.map((k) => k.name);
26
- const functions = MORPHQL_LANGUAGE.functions.map((f) => f.name);
27
- const operators = MORPHQL_LANGUAGE.operators.map((o) => o.symbol);
28
-
29
- const constantsContent = `package org.morphql.jetbrains
30
-
31
- /**
32
- * GENERATED FILE - DO NOT EDIT MANUALLY
33
- * Generated by packages/language-definitions/export-json.ts
34
- */
35
- object MorphQLConstants {
36
- val KEYWORDS = setOf(
37
- ${keywords.map((k) => ` "${k}"`).join(",\n")}
38
- )
39
-
40
- val FUNCTIONS = setOf(
41
- ${functions.map((f) => ` "${f}"`).join(",\n")}
42
- )
43
-
44
- val OPERATORS = setOf(
45
- ${operators.map((o) => ` "${o}"`).join(",\n")}
46
- )
47
- }
48
- `;
49
-
50
- if (fs.existsSync(path.dirname(constantsPath))) {
51
- fs.writeFileSync(constantsPath, constantsContent);
52
- console.log(`Kotlin constants exported to ${constantsPath}`);
53
- }
54
-
55
- // 3. Export Kotlin Documentation
56
- const docsPath = path.resolve(
57
- __dirname,
58
- "../jetbrains-extension/src/main/kotlin/org/morphql/jetbrains/MorphQLDocumentation.kt",
59
- );
60
-
61
- const allDocs: Record<string, any> = {};
62
- MORPHQL_LANGUAGE.keywords.forEach((k) => {
63
- allDocs[k.name] = k.doc;
64
- });
65
- MORPHQL_LANGUAGE.functions.forEach((f) => {
66
- allDocs[f.name] = f.doc;
67
- });
68
-
69
- const escapeQuotes = (str: string) =>
70
- str.replace(/"/g, '\\"').replace(/\n/g, "\\n");
71
-
72
- const docsEntries = Object.entries(allDocs)
73
- .map(([name, doc]) => {
74
- return ` "${name}" to """
75
- <b>${doc.signature}</b><br/>
76
- ${doc.description}<br/><br/>
77
- ${
78
- doc.parameters && doc.parameters.length > 0
79
- ? `<b>Parameters:</b><ul>${doc.parameters
80
- .map(
81
- (p: any) => `<li><b>${p.name}:</b> ${p.description}</li>`,
82
- )
83
- .join("")}</ul>`
84
- : ""
85
- }
86
- ${doc.example ? `<b>Example:</b><pre>${doc.example}</pre>` : ""}
87
- """.trimIndent()`;
88
- })
89
- .join(",\n");
90
-
91
- const docsContent = `package org.morphql.jetbrains
92
-
93
- /**
94
- * GENERATED FILE - DO NOT EDIT MANUALLY
95
- * Generated by packages/language-definitions/export-json.ts
96
- */
97
- object MorphQLDocumentation {
98
- val DOCS = mapOf(
99
- ${docsEntries}
100
- )
101
- }
102
- `;
103
-
104
- if (fs.existsSync(path.dirname(docsPath))) {
105
- fs.writeFileSync(docsPath, docsContent);
106
- console.log(`Kotlin documentation exported to ${docsPath}`);
107
- }