@morphql/language-definitions 0.1.6 → 0.1.8

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/dist/index.cjs CHANGED
@@ -51,10 +51,10 @@ var KEYWORDS = [
51
51
  parameters: [
52
52
  {
53
53
  name: "format",
54
- description: "If used as first keyword: The starting format, one of `json`, `xml`, or `object`. When used after a section, defines its source"
54
+ description: "If used as first keyword: The starting format name (e.g., `json`, `xml`, `csv`, `object`). When used after a section, defines its source."
55
55
  }
56
56
  ],
57
- example: "from json to xml"
57
+ example: "from json to csv"
58
58
  }
59
59
  },
60
60
  {
@@ -64,18 +64,30 @@ var KEYWORDS = [
64
64
  signature: "to <format>",
65
65
  description: "Specifies the output data format.",
66
66
  parameters: [
67
- { name: "format", description: "One of: `json`, `xml`, or `object`" }
67
+ {
68
+ name: "format",
69
+ description: "The name of one of the available adapters."
70
+ }
68
71
  ],
69
- example: "from json to xml"
72
+ example: "from csv to json"
70
73
  }
71
74
  },
72
75
  {
73
76
  name: "transform",
74
77
  category: "control",
75
78
  doc: {
76
- signature: "transform",
77
- description: "Begins the transformation block containing actions.",
78
- example: "transform\n set name = firstName"
79
+ signature: "transform [unsafe]",
80
+ description: "Begins the transformation block containing actions. Optional 'unsafe' keyword disables safety features (optional chaining) for maximum performance.",
81
+ example: "transform\n set name = firstName\n\ntransform unsafe\n set result = price / quantity"
82
+ }
83
+ },
84
+ {
85
+ name: "unsafe",
86
+ category: "control",
87
+ doc: {
88
+ signature: "transform unsafe",
89
+ description: "Disables safety features (optional chaining) in generated code for maximum performance. Use only with validated/trusted input data.",
90
+ example: "transform unsafe\n set result = price / quantity"
79
91
  }
80
92
  },
81
93
  {
@@ -116,7 +128,7 @@ var KEYWORDS = [
116
128
  description: "(Optional) Source path for the section data"
117
129
  }
118
130
  ],
119
- example: "section metadata(\n from xml to object\n transform\n set name = root.productName\n) from xmlString"
131
+ example: "section items(\n from csv to object\n transform\n set name = A\n) from csvString"
120
132
  }
121
133
  },
122
134
  {
@@ -203,6 +215,16 @@ var KEYWORDS = [
203
215
  ],
204
216
  example: "set total = price * quantity\nmodify total = total * 1.10"
205
217
  }
218
+ },
219
+ {
220
+ name: "return",
221
+ category: "action",
222
+ doc: {
223
+ signature: "return <expression>",
224
+ description: "Returns a value from the transformation, bypassing the default serialization. Reads from target context by default.",
225
+ parameters: [{ name: "expression", description: "The value to return" }],
226
+ example: "set computed = price * 1.1\nreturn computed"
227
+ }
206
228
  }
207
229
  ];
208
230
  var getKeywordsByCategory = (category) => KEYWORDS.filter((k) => k.category === category);
@@ -354,11 +376,21 @@ var FUNCTIONS = [
354
376
  name: "aslist",
355
377
  doc: {
356
378
  signature: "aslist(value)",
357
- description: "Ensures a value is an array. Useful for XML nodes that might be a single object or an array.",
379
+ description: "Ensures a value is an array. Useful for input formats like XML that might return a single object or an array for the same field.",
358
380
  parameters: [{ name: "value", description: "The value to normalize" }],
359
381
  returns: "array",
360
382
  example: "aslist(items) // Always returns an array"
361
383
  }
384
+ },
385
+ {
386
+ name: "spreadsheet",
387
+ doc: {
388
+ signature: "spreadsheet(data)",
389
+ description: "Converts spreadsheet-style data (array of arrays) into an array of objects with named properties. First row is treated as headers.",
390
+ parameters: [{ name: "data", description: "Array of arrays (rows)" }],
391
+ returns: "array of objects",
392
+ example: 'spreadsheet(csvData) // Converts [["name","age"],["John",30]] to [{name:"John",age:30}]'
393
+ }
362
394
  }
363
395
  ];
364
396
  var getFunctionNames = () => FUNCTIONS.map((f) => f.name);
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ var KEYWORDS = [
9
9
  parameters: [
10
10
  {
11
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"
12
+ description: "If used as first keyword: The starting format name (e.g., `json`, `xml`, `csv`, `object`). When used after a section, defines its source."
13
13
  }
14
14
  ],
15
- example: "from json to xml"
15
+ example: "from json to csv"
16
16
  }
17
17
  },
18
18
  {
@@ -22,18 +22,30 @@ var KEYWORDS = [
22
22
  signature: "to <format>",
23
23
  description: "Specifies the output data format.",
24
24
  parameters: [
25
- { name: "format", description: "One of: `json`, `xml`, or `object`" }
25
+ {
26
+ name: "format",
27
+ description: "The name of one of the available adapters."
28
+ }
26
29
  ],
27
- example: "from json to xml"
30
+ example: "from csv to json"
28
31
  }
29
32
  },
30
33
  {
31
34
  name: "transform",
32
35
  category: "control",
33
36
  doc: {
34
- signature: "transform",
35
- description: "Begins the transformation block containing actions.",
36
- example: "transform\n set name = firstName"
37
+ signature: "transform [unsafe]",
38
+ description: "Begins the transformation block containing actions. Optional 'unsafe' keyword disables safety features (optional chaining) for maximum performance.",
39
+ example: "transform\n set name = firstName\n\ntransform unsafe\n set result = price / quantity"
40
+ }
41
+ },
42
+ {
43
+ name: "unsafe",
44
+ category: "control",
45
+ doc: {
46
+ signature: "transform unsafe",
47
+ description: "Disables safety features (optional chaining) in generated code for maximum performance. Use only with validated/trusted input data.",
48
+ example: "transform unsafe\n set result = price / quantity"
37
49
  }
38
50
  },
39
51
  {
@@ -74,7 +86,7 @@ var KEYWORDS = [
74
86
  description: "(Optional) Source path for the section data"
75
87
  }
76
88
  ],
77
- example: "section metadata(\n from xml to object\n transform\n set name = root.productName\n) from xmlString"
89
+ example: "section items(\n from csv to object\n transform\n set name = A\n) from csvString"
78
90
  }
79
91
  },
80
92
  {
@@ -161,6 +173,16 @@ var KEYWORDS = [
161
173
  ],
162
174
  example: "set total = price * quantity\nmodify total = total * 1.10"
163
175
  }
176
+ },
177
+ {
178
+ name: "return",
179
+ category: "action",
180
+ doc: {
181
+ signature: "return <expression>",
182
+ description: "Returns a value from the transformation, bypassing the default serialization. Reads from target context by default.",
183
+ parameters: [{ name: "expression", description: "The value to return" }],
184
+ example: "set computed = price * 1.1\nreturn computed"
185
+ }
164
186
  }
165
187
  ];
166
188
  var getKeywordsByCategory = (category) => KEYWORDS.filter((k) => k.category === category);
@@ -312,11 +334,21 @@ var FUNCTIONS = [
312
334
  name: "aslist",
313
335
  doc: {
314
336
  signature: "aslist(value)",
315
- description: "Ensures a value is an array. Useful for XML nodes that might be a single object or an array.",
337
+ description: "Ensures a value is an array. Useful for input formats like XML that might return a single object or an array for the same field.",
316
338
  parameters: [{ name: "value", description: "The value to normalize" }],
317
339
  returns: "array",
318
340
  example: "aslist(items) // Always returns an array"
319
341
  }
342
+ },
343
+ {
344
+ name: "spreadsheet",
345
+ doc: {
346
+ signature: "spreadsheet(data)",
347
+ description: "Converts spreadsheet-style data (array of arrays) into an array of objects with named properties. First row is treated as headers.",
348
+ parameters: [{ name: "data", description: "Array of arrays (rows)" }],
349
+ returns: "array of objects",
350
+ example: 'spreadsheet(csvData) // Converts [["name","age"],["John",30]] to [{name:"John",age:30}]'
351
+ }
320
352
  }
321
353
  ];
322
354
  var getFunctionNames = () => FUNCTIONS.map((f) => f.name);
@@ -9,10 +9,10 @@
9
9
  "parameters": [
10
10
  {
11
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"
12
+ "description": "If used as first keyword: The starting format name (e.g., `json`, `xml`, `csv`, `object`). When used after a section, defines its source."
13
13
  }
14
14
  ],
15
- "example": "from json to xml"
15
+ "example": "from json to csv"
16
16
  }
17
17
  },
18
18
  {
@@ -24,19 +24,28 @@
24
24
  "parameters": [
25
25
  {
26
26
  "name": "format",
27
- "description": "One of: `json`, `xml`, or `object`"
27
+ "description": "The name of one of the available adapters."
28
28
  }
29
29
  ],
30
- "example": "from json to xml"
30
+ "example": "from csv to json"
31
31
  }
32
32
  },
33
33
  {
34
34
  "name": "transform",
35
35
  "category": "control",
36
36
  "doc": {
37
- "signature": "transform",
38
- "description": "Begins the transformation block containing actions.",
39
- "example": "transform\n set name = firstName"
37
+ "signature": "transform [unsafe]",
38
+ "description": "Begins the transformation block containing actions. Optional 'unsafe' keyword disables safety features (optional chaining) for maximum performance.",
39
+ "example": "transform\n set name = firstName\n\ntransform unsafe\n set result = price / quantity"
40
+ }
41
+ },
42
+ {
43
+ "name": "unsafe",
44
+ "category": "control",
45
+ "doc": {
46
+ "signature": "transform unsafe",
47
+ "description": "Disables safety features (optional chaining) in generated code for maximum performance. Use only with validated/trusted input data.",
48
+ "example": "transform unsafe\n set result = price / quantity"
40
49
  }
41
50
  },
42
51
  {
@@ -86,7 +95,7 @@
86
95
  "description": "(Optional) Source path for the section data"
87
96
  }
88
97
  ],
89
- "example": "section metadata(\n from xml to object\n transform\n set name = root.productName\n) from xmlString"
98
+ "example": "section items(\n from csv to object\n transform\n set name = A\n) from csvString"
90
99
  }
91
100
  },
92
101
  {
@@ -193,6 +202,21 @@
193
202
  ],
194
203
  "example": "set total = price * quantity\nmodify total = total * 1.10"
195
204
  }
205
+ },
206
+ {
207
+ "name": "return",
208
+ "category": "action",
209
+ "doc": {
210
+ "signature": "return <expression>",
211
+ "description": "Returns a value from the transformation, bypassing the default serialization. Reads from target context by default.",
212
+ "parameters": [
213
+ {
214
+ "name": "expression",
215
+ "description": "The value to return"
216
+ }
217
+ ],
218
+ "example": "set computed = price * 1.1\nreturn computed"
219
+ }
196
220
  }
197
221
  ],
198
222
  "functions": [
@@ -393,7 +417,7 @@
393
417
  "name": "aslist",
394
418
  "doc": {
395
419
  "signature": "aslist(value)",
396
- "description": "Ensures a value is an array. Useful for XML nodes that might be a single object or an array.",
420
+ "description": "Ensures a value is an array. Useful for input formats like XML that might return a single object or an array for the same field.",
397
421
  "parameters": [
398
422
  {
399
423
  "name": "value",
@@ -403,6 +427,21 @@
403
427
  "returns": "array",
404
428
  "example": "aslist(items) // Always returns an array"
405
429
  }
430
+ },
431
+ {
432
+ "name": "spreadsheet",
433
+ "doc": {
434
+ "signature": "spreadsheet(data)",
435
+ "description": "Converts spreadsheet-style data (array of arrays) into an array of objects with named properties. First row is treated as headers.",
436
+ "parameters": [
437
+ {
438
+ "name": "data",
439
+ "description": "Array of arrays (rows)"
440
+ }
441
+ ],
442
+ "returns": "array of objects",
443
+ "example": "spreadsheet(csvData) // Converts [[\"name\",\"age\"],[\"John\",30]] to [{name:\"John\",age:30}]"
444
+ }
406
445
  }
407
446
  ],
408
447
  "operators": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morphql/language-definitions",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Shared language definitions for MorphQL across VSCode, Monaco, and documentation",
5
5
  "type": "module",
6
6
  "publishConfig": {