@aeriajs/compiler 0.0.17 → 0.0.18
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/ast.d.ts +1 -0
- package/dist/codegen/generateContracts.js +5 -5
- package/dist/codegen/generateContracts.mjs +6 -6
- package/dist/codegen/generateJSCollections.js +1 -1
- package/dist/codegen/generateJSCollections.mjs +2 -2
- package/dist/codegen/generateTSCollections.js +1 -1
- package/dist/codegen/generateTSCollections.mjs +2 -2
- package/dist/codegen/utils.d.ts +2 -2
- package/dist/codegen/utils.js +50 -21
- package/dist/codegen/utils.mjs +42 -18
- package/dist/lexer.d.ts +1 -1
- package/dist/lexer.js +1 -0
- package/dist/lexer.mjs +1 -0
- package/dist/parser.js +20 -5
- package/dist/parser.mjs +19 -6
- package/dist/semantic.js +18 -7
- package/dist/semantic.mjs +17 -7
- package/package.json +1 -1
package/dist/ast.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
19
19
|
const getCodeForResponse = (responseProperty) => {
|
|
20
20
|
const { kind, modifier, ...propertyNode } = responseProperty;
|
|
21
21
|
if (!modifier) {
|
|
22
|
-
return (0, utils_js_1.stringify)((0, utils_js_1.
|
|
22
|
+
return (0, utils_js_1.stringify)((0, utils_js_1.unwrapPropertyNode)(propertyNode));
|
|
23
23
|
}
|
|
24
24
|
const modifierSymbol = responseProperty.modifier === 'Result'
|
|
25
25
|
? 'resultSchema'
|
|
@@ -27,7 +27,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
27
27
|
if (!imports.has(modifierSymbol)) {
|
|
28
28
|
imports.add(modifierSymbol);
|
|
29
29
|
}
|
|
30
|
-
return `${modifierSymbol}(${(0, utils_js_1.stringify)((0, utils_js_1.
|
|
30
|
+
return `${modifierSymbol}(${(0, utils_js_1.stringify)((0, utils_js_1.unwrapPropertyNode)(propertyNode))})`;
|
|
31
31
|
};
|
|
32
32
|
const declarations = contractAst.map((contractNode) => {
|
|
33
33
|
const { name, kind, roles, response, ...contractProperty } = contractNode;
|
|
@@ -47,7 +47,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
47
47
|
responseString = (0, utils_js_1.stringify)(getCodeForResponse(response));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
const contractSchema = (0, utils_js_1.
|
|
50
|
+
const contractSchema = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(contractProperty);
|
|
51
51
|
if (responseString) {
|
|
52
52
|
contractSchema.response = {
|
|
53
53
|
[utils_js_1.UnquotedSymbol]: responseString,
|
|
@@ -61,7 +61,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
61
61
|
return `import { ${Array.from(imports).join(', ')} } from \'aeria\'\n\n` + declarations;
|
|
62
62
|
};
|
|
63
63
|
const getResponseSchema = (response) => {
|
|
64
|
-
const responseSchema = (0, utils_js_1.
|
|
64
|
+
const responseSchema = (0, utils_js_1.unwrapPropertyNode)(response);
|
|
65
65
|
if (!response.modifier) {
|
|
66
66
|
return responseSchema;
|
|
67
67
|
}
|
|
@@ -81,7 +81,7 @@ const makeTSContractsCode = (contractAst) => {
|
|
|
81
81
|
responseSchema = getResponseSchema(contractSchema.response);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
const contractProperties = (0, utils_js_1.
|
|
84
|
+
const contractProperties = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(contractSchema);
|
|
85
85
|
if (responseSchema) {
|
|
86
86
|
contractProperties.response = responseSchema;
|
|
87
87
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { errorSchema, resultSchema } from "@aeriajs/types";
|
|
3
|
-
import {
|
|
3
|
+
import { recursivelyUnwrapPropertyNodes, unwrapPropertyNode, stringify, UnquotedSymbol } from "./utils.mjs";
|
|
4
4
|
export const generateContracts = (ast) => {
|
|
5
5
|
const contractNodes = ast.filter((node) => node.kind === "contract");
|
|
6
6
|
if (contractNodes.length === 0) {
|
|
@@ -16,13 +16,13 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
16
16
|
const getCodeForResponse = (responseProperty) => {
|
|
17
17
|
const { kind, modifier, ...propertyNode } = responseProperty;
|
|
18
18
|
if (!modifier) {
|
|
19
|
-
return stringify(
|
|
19
|
+
return stringify(unwrapPropertyNode(propertyNode));
|
|
20
20
|
}
|
|
21
21
|
const modifierSymbol = responseProperty.modifier === "Result" ? "resultSchema" : "errorSchema";
|
|
22
22
|
if (!imports.has(modifierSymbol)) {
|
|
23
23
|
imports.add(modifierSymbol);
|
|
24
24
|
}
|
|
25
|
-
return `${modifierSymbol}(${stringify(
|
|
25
|
+
return `${modifierSymbol}(${stringify(unwrapPropertyNode(propertyNode))})`;
|
|
26
26
|
};
|
|
27
27
|
const declarations = contractAst.map((contractNode) => {
|
|
28
28
|
const { name, kind, roles, response, ...contractProperty } = contractNode;
|
|
@@ -41,7 +41,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
41
41
|
responseString = stringify(getCodeForResponse(response));
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
const contractSchema =
|
|
44
|
+
const contractSchema = recursivelyUnwrapPropertyNodes(contractProperty);
|
|
45
45
|
if (responseString) {
|
|
46
46
|
contractSchema.response = {
|
|
47
47
|
[UnquotedSymbol]: responseString
|
|
@@ -57,7 +57,7 @@ const makeJSContractsCode = (contractAst) => {
|
|
|
57
57
|
` + declarations;
|
|
58
58
|
};
|
|
59
59
|
const getResponseSchema = (response) => {
|
|
60
|
-
const responseSchema =
|
|
60
|
+
const responseSchema = unwrapPropertyNode(response);
|
|
61
61
|
if (!response.modifier) {
|
|
62
62
|
return responseSchema;
|
|
63
63
|
}
|
|
@@ -74,7 +74,7 @@ const makeTSContractsCode = (contractAst) => {
|
|
|
74
74
|
responseSchema = getResponseSchema(contractSchema.response);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
const contractProperties =
|
|
77
|
+
const contractProperties = recursivelyUnwrapPropertyNodes(contractSchema);
|
|
78
78
|
if (responseSchema) {
|
|
79
79
|
contractProperties.response = responseSchema;
|
|
80
80
|
}
|
|
@@ -47,7 +47,7 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
47
47
|
}
|
|
48
48
|
switch (key) {
|
|
49
49
|
case 'properties':
|
|
50
|
-
collectionSchema.description[key] = (0, utils_js_1.
|
|
50
|
+
collectionSchema.description[key] = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(collectionNode[key]);
|
|
51
51
|
break;
|
|
52
52
|
case 'owned':
|
|
53
53
|
collectionSchema.description[key] = collectionNode[key];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { makeASTImports,
|
|
2
|
+
import { makeASTImports, recursivelyUnwrapPropertyNodes, stringify, getExtendName, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME, DEFAULT_FUNCTIONS } from "./utils.mjs";
|
|
3
3
|
const initialImportedFunctions = [
|
|
4
4
|
"extendCollection",
|
|
5
5
|
"defineCollection"
|
|
@@ -40,7 +40,7 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
40
40
|
}
|
|
41
41
|
switch (key) {
|
|
42
42
|
case "properties":
|
|
43
|
-
collectionSchema.description[key] =
|
|
43
|
+
collectionSchema.description[key] = recursivelyUnwrapPropertyNodes(collectionNode[key]);
|
|
44
44
|
break;
|
|
45
45
|
case "owned":
|
|
46
46
|
collectionSchema.description[key] = collectionNode[key];
|
|
@@ -59,7 +59,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
59
59
|
}
|
|
60
60
|
switch (key) {
|
|
61
61
|
case 'properties':
|
|
62
|
-
collectionSchema.description.properties = (0, utils_js_1.
|
|
62
|
+
collectionSchema.description.properties = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(collectionNode[key]);
|
|
63
63
|
break;
|
|
64
64
|
case 'owned':
|
|
65
65
|
collectionSchema.description.owned = collectionNode[key];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { recursivelyUnwrapPropertyNodes, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME, DEFAULT_FUNCTIONS } from "./utils.mjs";
|
|
3
3
|
const initialImportedTypes = [
|
|
4
4
|
"Collection",
|
|
5
5
|
"SchemaWithId",
|
|
@@ -54,7 +54,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
54
54
|
}
|
|
55
55
|
switch (key) {
|
|
56
56
|
case "properties":
|
|
57
|
-
collectionSchema.description.properties =
|
|
57
|
+
collectionSchema.description.properties = recursivelyUnwrapPropertyNodes(collectionNode[key]);
|
|
58
58
|
break;
|
|
59
59
|
case "owned":
|
|
60
60
|
collectionSchema.description.owned = collectionNode[key];
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<s
|
|
|
13
13
|
code: string[];
|
|
14
14
|
modifiedSymbols: Record<string, string>;
|
|
15
15
|
};
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const unwrapPropertyNode: ({ property, nestedProperties, nestedAdditionalProperties }: Pick<AST.PropertyNode, "property" | "nestedProperties" | "nestedAdditionalProperties">) => Property;
|
|
17
17
|
/** Transforms the AST properties to the format of aeria schema properties */
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const recursivelyUnwrapPropertyNodes: <TProperties extends Record<string, AST.PropertyNode | AST.PropertyNode[]>, TReturnType = TProperties[keyof TProperties] extends Array<unknown> ? Record<string, Property[]> : Record<string, Property>>(properties: TProperties) => TReturnType;
|
|
19
19
|
export declare const UnquotedSymbol: unique symbol;
|
|
20
20
|
/** Serves to know if the value must be unquoted on strinfigy function */
|
|
21
21
|
export type StringifyProperty = unknown | {
|
package/dist/codegen/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.UnquotedSymbol = exports.
|
|
3
|
+
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.UnquotedSymbol = exports.recursivelyUnwrapPropertyNodes = exports.unwrapPropertyNode = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.DEFAULT_FUNCTIONS = exports.PACKAGE_NAME = void 0;
|
|
4
4
|
exports.PACKAGE_NAME = 'aeria';
|
|
5
5
|
exports.DEFAULT_FUNCTIONS = [
|
|
6
6
|
'count',
|
|
@@ -55,41 +55,70 @@ const makeASTImports = (ast, initialImports) => {
|
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
exports.makeASTImports = makeASTImports;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProperties }) => {
|
|
59
|
+
const propertyOrPropertyItems = 'items' in property
|
|
60
|
+
? property.items
|
|
61
|
+
: property;
|
|
62
|
+
let unwrappedProperty = propertyOrPropertyItems;
|
|
63
|
+
if ('$ref' in propertyOrPropertyItems) {
|
|
64
|
+
unwrappedProperty = {
|
|
65
|
+
...propertyOrPropertyItems,
|
|
66
|
+
$ref: (0, exports.getCollectionId)(propertyOrPropertyItems.$ref),
|
|
67
|
+
};
|
|
62
68
|
}
|
|
63
|
-
else if ('
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
else if ('type' in propertyOrPropertyItems && propertyOrPropertyItems.type === 'object') {
|
|
70
|
+
let properties;
|
|
71
|
+
let additionalProperties;
|
|
72
|
+
if (nestedProperties) {
|
|
73
|
+
properties = (0, exports.recursivelyUnwrapPropertyNodes)(nestedProperties);
|
|
74
|
+
}
|
|
75
|
+
if (nestedAdditionalProperties) {
|
|
76
|
+
additionalProperties = typeof nestedAdditionalProperties === 'boolean'
|
|
77
|
+
? nestedAdditionalProperties
|
|
78
|
+
: (0, exports.unwrapPropertyNode)(nestedAdditionalProperties);
|
|
79
|
+
}
|
|
80
|
+
if (properties && additionalProperties) {
|
|
81
|
+
unwrappedProperty = {
|
|
82
|
+
...propertyOrPropertyItems,
|
|
83
|
+
properties,
|
|
84
|
+
additionalProperties,
|
|
85
|
+
};
|
|
69
86
|
}
|
|
70
|
-
else if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
properties
|
|
87
|
+
else if (properties) {
|
|
88
|
+
unwrappedProperty = {
|
|
89
|
+
...propertyOrPropertyItems,
|
|
90
|
+
properties,
|
|
74
91
|
};
|
|
75
92
|
}
|
|
93
|
+
else if (additionalProperties) {
|
|
94
|
+
unwrappedProperty = {
|
|
95
|
+
...propertyOrPropertyItems,
|
|
96
|
+
additionalProperties,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if ('items' in property) {
|
|
101
|
+
return {
|
|
102
|
+
...property,
|
|
103
|
+
items: unwrappedProperty,
|
|
104
|
+
};
|
|
76
105
|
}
|
|
77
|
-
return
|
|
106
|
+
return unwrappedProperty;
|
|
78
107
|
};
|
|
79
|
-
exports.
|
|
108
|
+
exports.unwrapPropertyNode = unwrapPropertyNode;
|
|
80
109
|
/** Transforms the AST properties to the format of aeria schema properties */
|
|
81
|
-
const
|
|
110
|
+
const recursivelyUnwrapPropertyNodes = (properties) => {
|
|
82
111
|
return Object.entries(properties).reduce((acc, [key, value]) => {
|
|
83
112
|
if (Array.isArray(value)) {
|
|
84
|
-
acc[key] = value.map((propertyNode) => (0, exports.
|
|
113
|
+
acc[key] = value.map((propertyNode) => (0, exports.unwrapPropertyNode)(propertyNode));
|
|
85
114
|
}
|
|
86
115
|
else {
|
|
87
|
-
acc[key] = (0, exports.
|
|
116
|
+
acc[key] = (0, exports.unwrapPropertyNode)(value);
|
|
88
117
|
}
|
|
89
118
|
return acc;
|
|
90
119
|
}, {});
|
|
91
120
|
};
|
|
92
|
-
exports.
|
|
121
|
+
exports.recursivelyUnwrapPropertyNodes = recursivelyUnwrapPropertyNodes;
|
|
93
122
|
exports.UnquotedSymbol = Symbol('unquoted');
|
|
94
123
|
const isRecord = (value) => typeof value === 'object';
|
|
95
124
|
/** Assure if specific fields needs to be between quotes or not */
|
package/dist/codegen/utils.mjs
CHANGED
|
@@ -48,31 +48,55 @@ export const makeASTImports = (ast, initialImports) => {
|
|
|
48
48
|
modifiedSymbols
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
-
export const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
export const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProperties }) => {
|
|
52
|
+
const propertyOrPropertyItems = "items" in property ? property.items : property;
|
|
53
|
+
let unwrappedProperty = propertyOrPropertyItems;
|
|
54
|
+
if ("$ref" in propertyOrPropertyItems) {
|
|
55
|
+
unwrappedProperty = {
|
|
56
|
+
...propertyOrPropertyItems,
|
|
57
|
+
$ref: getCollectionId(propertyOrPropertyItems.$ref)
|
|
58
|
+
};
|
|
59
|
+
} else if ("type" in propertyOrPropertyItems && propertyOrPropertyItems.type === "object") {
|
|
60
|
+
let properties;
|
|
61
|
+
let additionalProperties;
|
|
62
|
+
if (nestedProperties) {
|
|
63
|
+
properties = recursivelyUnwrapPropertyNodes(nestedProperties);
|
|
64
|
+
}
|
|
65
|
+
if (nestedAdditionalProperties) {
|
|
66
|
+
additionalProperties = typeof nestedAdditionalProperties === "boolean" ? nestedAdditionalProperties : unwrapPropertyNode(nestedAdditionalProperties);
|
|
67
|
+
}
|
|
68
|
+
if (properties && additionalProperties) {
|
|
69
|
+
unwrappedProperty = {
|
|
70
|
+
...propertyOrPropertyItems,
|
|
71
|
+
properties,
|
|
72
|
+
additionalProperties
|
|
73
|
+
};
|
|
74
|
+
} else if (properties) {
|
|
75
|
+
unwrappedProperty = {
|
|
76
|
+
...propertyOrPropertyItems,
|
|
77
|
+
properties
|
|
78
|
+
};
|
|
79
|
+
} else if (additionalProperties) {
|
|
80
|
+
unwrappedProperty = {
|
|
81
|
+
...propertyOrPropertyItems,
|
|
82
|
+
additionalProperties
|
|
65
83
|
};
|
|
66
84
|
}
|
|
67
85
|
}
|
|
68
|
-
|
|
86
|
+
if ("items" in property) {
|
|
87
|
+
return {
|
|
88
|
+
...property,
|
|
89
|
+
items: unwrappedProperty
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return unwrappedProperty;
|
|
69
93
|
};
|
|
70
|
-
export const
|
|
94
|
+
export const recursivelyUnwrapPropertyNodes = (properties) => {
|
|
71
95
|
return Object.entries(properties).reduce((acc, [key, value]) => {
|
|
72
96
|
if (Array.isArray(value)) {
|
|
73
|
-
acc[key] = value.map((propertyNode) =>
|
|
97
|
+
acc[key] = value.map((propertyNode) => unwrapPropertyNode(propertyNode));
|
|
74
98
|
} else {
|
|
75
|
-
acc[key] =
|
|
99
|
+
acc[key] = unwrapPropertyNode(value);
|
|
76
100
|
}
|
|
77
101
|
return acc;
|
|
78
102
|
}, {});
|
package/dist/lexer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Token } from './token.js';
|
|
2
2
|
import { Diagnostic } from './diagnostic.js';
|
|
3
3
|
export type Keyword = typeof COLLECTION_KEYWORDS[number] | typeof COLLECTION_ACTIONS_KEYWORDS[number] | typeof COLLECTION_SEARCH_KEYWORDS[number] | typeof CONTRACT_KEYWORDS[number] | typeof TOPLEVEL_KEYWORDS[number] | typeof MISC_KEYWORDS[number];
|
|
4
|
-
export declare const COLLECTION_KEYWORDS: readonly ["actions", "filters", "form", "functions", "icon", "indexes", "individualActions", "owned", "presets", "properties", "required", "search", "table"];
|
|
4
|
+
export declare const COLLECTION_KEYWORDS: readonly ["actions", "additionalProperties", "filters", "form", "functions", "icon", "indexes", "individualActions", "owned", "presets", "properties", "required", "search", "table"];
|
|
5
5
|
export declare const COLLECTION_ACTIONS_KEYWORDS: readonly ["ask", "button", "clearItem", "effect", "event", "fetchItem", "function", "icon", "label", "params", "query", "requires", "roles", "route", "selection", "setItem", "translate"];
|
|
6
6
|
export declare const COLLECTION_SEARCH_KEYWORDS: readonly ["indexes", "placeholder", "exactMatches"];
|
|
7
7
|
export declare const CONTRACT_KEYWORDS: readonly ["roles", "payload", "query", "response"];
|
package/dist/lexer.js
CHANGED
package/dist/lexer.mjs
CHANGED
package/dist/parser.js
CHANGED
|
@@ -378,6 +378,7 @@ const parse = (tokens) => {
|
|
|
378
378
|
}) => {
|
|
379
379
|
let property;
|
|
380
380
|
let nestedProperties;
|
|
381
|
+
let nestedAdditionalProperties;
|
|
381
382
|
let modifierToken;
|
|
382
383
|
const typeSymbol = Symbol();
|
|
383
384
|
if (match(token_js_1.TokenType.LeftSquareBracket)) {
|
|
@@ -469,6 +470,16 @@ const parse = (tokens) => {
|
|
|
469
470
|
nestedProperties = parsePropertiesBlock(options);
|
|
470
471
|
break;
|
|
471
472
|
}
|
|
473
|
+
case 'additionalProperties': {
|
|
474
|
+
consume(token_js_1.TokenType.Keyword);
|
|
475
|
+
if (match(token_js_1.TokenType.Boolean)) {
|
|
476
|
+
nestedAdditionalProperties = consume(token_js_1.TokenType.Boolean).value;
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
nestedAdditionalProperties = parsePropertyType();
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
472
483
|
default:
|
|
473
484
|
throw new diagnostic_js_1.Diagnostic(`invalid keyword "${keyword}"`, location);
|
|
474
485
|
}
|
|
@@ -545,6 +556,7 @@ const parse = (tokens) => {
|
|
|
545
556
|
kind: 'property',
|
|
546
557
|
property,
|
|
547
558
|
nestedProperties,
|
|
559
|
+
nestedAdditionalProperties,
|
|
548
560
|
};
|
|
549
561
|
if (modifierToken) {
|
|
550
562
|
node.modifier = modifierToken.value;
|
|
@@ -663,11 +675,14 @@ const parse = (tokens) => {
|
|
|
663
675
|
try {
|
|
664
676
|
switch (keyword) {
|
|
665
677
|
case 'owned': {
|
|
666
|
-
if (match(token_js_1.TokenType.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
node.owned = consume(token_js_1.TokenType.QuotedString
|
|
678
|
+
if (match(token_js_1.TokenType.Boolean)) {
|
|
679
|
+
node.owned = consume(token_js_1.TokenType.Boolean).value;
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
node.owned = consume(token_js_1.TokenType.QuotedString, [
|
|
683
|
+
'always',
|
|
684
|
+
'on-write',
|
|
685
|
+
]).value;
|
|
671
686
|
}
|
|
672
687
|
break;
|
|
673
688
|
}
|
package/dist/parser.mjs
CHANGED
|
@@ -336,6 +336,7 @@ export const parse = (tokens) => {
|
|
|
336
336
|
}) => {
|
|
337
337
|
let property;
|
|
338
338
|
let nestedProperties;
|
|
339
|
+
let nestedAdditionalProperties;
|
|
339
340
|
let modifierToken;
|
|
340
341
|
const typeSymbol = Symbol();
|
|
341
342
|
if (match(TokenType.LeftSquareBracket)) {
|
|
@@ -425,6 +426,15 @@ export const parse = (tokens) => {
|
|
|
425
426
|
nestedProperties = parsePropertiesBlock(options);
|
|
426
427
|
break;
|
|
427
428
|
}
|
|
429
|
+
case "additionalProperties": {
|
|
430
|
+
consume(TokenType.Keyword);
|
|
431
|
+
if (match(TokenType.Boolean)) {
|
|
432
|
+
nestedAdditionalProperties = consume(TokenType.Boolean).value;
|
|
433
|
+
} else {
|
|
434
|
+
nestedAdditionalProperties = parsePropertyType();
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
428
438
|
default:
|
|
429
439
|
throw new Diagnostic(`invalid keyword "${keyword}"`, location);
|
|
430
440
|
}
|
|
@@ -497,7 +507,8 @@ export const parse = (tokens) => {
|
|
|
497
507
|
const node = {
|
|
498
508
|
kind: "property",
|
|
499
509
|
property,
|
|
500
|
-
nestedProperties
|
|
510
|
+
nestedProperties,
|
|
511
|
+
nestedAdditionalProperties
|
|
501
512
|
};
|
|
502
513
|
if (modifierToken) {
|
|
503
514
|
node.modifier = modifierToken.value;
|
|
@@ -610,11 +621,13 @@ export const parse = (tokens) => {
|
|
|
610
621
|
try {
|
|
611
622
|
switch (keyword) {
|
|
612
623
|
case "owned": {
|
|
613
|
-
if (match(TokenType.
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
624
|
+
if (match(TokenType.Boolean)) {
|
|
625
|
+
node.owned = consume(TokenType.Boolean).value;
|
|
626
|
+
} else {
|
|
627
|
+
node.owned = consume(TokenType.QuotedString, [
|
|
628
|
+
"always",
|
|
629
|
+
"on-write"
|
|
630
|
+
]).value;
|
|
618
631
|
}
|
|
619
632
|
break;
|
|
620
633
|
}
|
package/dist/semantic.js
CHANGED
|
@@ -97,13 +97,18 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
const recurseProperty = async (node) => {
|
|
100
|
-
if (node.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await
|
|
100
|
+
if ('type' in node.property && node.property.type === 'object') {
|
|
101
|
+
if (typeof node.nestedAdditionalProperties === 'object') {
|
|
102
|
+
await recurseProperty(node.nestedAdditionalProperties);
|
|
103
|
+
}
|
|
104
|
+
if (node.nestedProperties) {
|
|
105
|
+
await checkObjectLocalProperties(node, 'required');
|
|
106
|
+
await checkObjectLocalProperties(node, 'writable');
|
|
107
|
+
await checkObjectLocalProperties(node, 'form');
|
|
108
|
+
for (const propName in node.nestedProperties) {
|
|
109
|
+
const subProperty = node.nestedProperties[propName];
|
|
110
|
+
await recurseProperty(subProperty);
|
|
111
|
+
}
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
else if ('$ref' in node.property) {
|
|
@@ -118,6 +123,12 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
118
123
|
await checkCollectionForeignProperties(foreignCollection, node.property, 'populate');
|
|
119
124
|
await checkCollectionForeignProperties(foreignCollection, node.property, 'form');
|
|
120
125
|
}
|
|
126
|
+
else if ('items' in node.property) {
|
|
127
|
+
await recurseProperty({
|
|
128
|
+
kind: 'property',
|
|
129
|
+
property: node.property.items,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
121
132
|
};
|
|
122
133
|
for (const node of ast.collections) {
|
|
123
134
|
await checkCollectionLocalProperties(node, 'indexes');
|
package/dist/semantic.mjs
CHANGED
|
@@ -62,13 +62,18 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
const recurseProperty = async (node) => {
|
|
65
|
-
if (node.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
await
|
|
65
|
+
if ("type" in node.property && node.property.type === "object") {
|
|
66
|
+
if (typeof node.nestedAdditionalProperties === "object") {
|
|
67
|
+
await recurseProperty(node.nestedAdditionalProperties);
|
|
68
|
+
}
|
|
69
|
+
if (node.nestedProperties) {
|
|
70
|
+
await checkObjectLocalProperties(node, "required");
|
|
71
|
+
await checkObjectLocalProperties(node, "writable");
|
|
72
|
+
await checkObjectLocalProperties(node, "form");
|
|
73
|
+
for (const propName in node.nestedProperties) {
|
|
74
|
+
const subProperty = node.nestedProperties[propName];
|
|
75
|
+
await recurseProperty(subProperty);
|
|
76
|
+
}
|
|
72
77
|
}
|
|
73
78
|
} else if ("$ref" in node.property) {
|
|
74
79
|
const refName = node.property.$ref;
|
|
@@ -81,6 +86,11 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
81
86
|
await checkCollectionForeignProperties(foreignCollection, node.property, "indexes");
|
|
82
87
|
await checkCollectionForeignProperties(foreignCollection, node.property, "populate");
|
|
83
88
|
await checkCollectionForeignProperties(foreignCollection, node.property, "form");
|
|
89
|
+
} else if ("items" in node.property) {
|
|
90
|
+
await recurseProperty({
|
|
91
|
+
kind: "property",
|
|
92
|
+
property: node.property.items
|
|
93
|
+
});
|
|
84
94
|
}
|
|
85
95
|
};
|
|
86
96
|
for (const node of ast.collections) {
|