@aeriajs/compiler 0.0.50 → 0.0.52
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 +12 -11
- package/dist/ast.js +2 -0
- package/dist/ast.mjs +2 -0
- package/dist/codegen/generateJSCollections.js +9 -4
- package/dist/codegen/generateJSCollections.mjs +8 -3
- package/dist/codegen/generateTSCollections.js +8 -7
- package/dist/codegen/generateTSCollections.mjs +8 -7
- package/dist/codegen/utils.d.ts +1 -2
- package/dist/codegen/utils.js +16 -29
- package/dist/codegen/utils.mjs +15 -28
- package/dist/compile.js +1 -1
- package/dist/compile.mjs +1 -1
- package/dist/parser.d.ts +2 -1
- package/dist/parser.js +43 -14
- package/dist/parser.mjs +42 -14
- package/dist/semantic.js +4 -3
- package/dist/semantic.mjs +4 -3
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +12 -0
- package/dist/utils.mjs +11 -0
- package/package.json +1 -1
package/dist/ast.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const PropertyType: {
|
|
|
14
14
|
export declare const PropertyModifiers: Record<'Error' | 'Result', ExportSymbol>;
|
|
15
15
|
export type ExportSymbol = {
|
|
16
16
|
packageName: string;
|
|
17
|
+
importPath: string;
|
|
17
18
|
symbolName: string;
|
|
18
19
|
};
|
|
19
20
|
export type NodeBase<TType> = {
|
|
@@ -54,6 +55,16 @@ export type PropertyNode = NodeBase<'property'> & {
|
|
|
54
55
|
nestedProperties?: Record<string, PropertyNode>;
|
|
55
56
|
nestedAdditionalProperties?: PropertyNode | boolean;
|
|
56
57
|
};
|
|
58
|
+
export type FunctionNode = NodeBase<'function'> & {
|
|
59
|
+
name: string;
|
|
60
|
+
exportSymbol?: ExportSymbol;
|
|
61
|
+
accessCondition?: AccessCondition;
|
|
62
|
+
};
|
|
63
|
+
export type FunctionSetNode = NodeBase<'functionset'> & {
|
|
64
|
+
name: string;
|
|
65
|
+
functions: FunctionNode[];
|
|
66
|
+
functionSets: [string, symbol][];
|
|
67
|
+
};
|
|
57
68
|
export type CollectionNode = NodeBase<'collection'> & {
|
|
58
69
|
name: string;
|
|
59
70
|
extends?: ExportSymbol;
|
|
@@ -63,9 +74,7 @@ export type CollectionNode = NodeBase<'collection'> & {
|
|
|
63
74
|
actions?: CollectionActions;
|
|
64
75
|
individualActions?: CollectionActions;
|
|
65
76
|
properties: Record<string, PropertyNode>;
|
|
66
|
-
functions?:
|
|
67
|
-
accessCondition: AccessCondition;
|
|
68
|
-
}>;
|
|
77
|
+
functions?: FunctionNode[];
|
|
69
78
|
functionSets?: [string, symbol][];
|
|
70
79
|
required?: RequiredProperties;
|
|
71
80
|
indexes?: readonly string[];
|
|
@@ -93,14 +102,6 @@ export type ContractNode = NodeBase<'contract'> & {
|
|
|
93
102
|
payload?: PropertyNode;
|
|
94
103
|
response?: PropertyNode | PropertyNode[];
|
|
95
104
|
};
|
|
96
|
-
export type FunctionSetNode = NodeBase<'functionset'> & {
|
|
97
|
-
name: string;
|
|
98
|
-
functions: Record<string, {
|
|
99
|
-
accessCondition: AccessCondition;
|
|
100
|
-
fromFunctionSet?: true;
|
|
101
|
-
}>;
|
|
102
|
-
functionSets: [string, symbol][];
|
|
103
|
-
};
|
|
104
105
|
export type ProgramNode = NodeBase<'program'> & {
|
|
105
106
|
collections: CollectionNode[];
|
|
106
107
|
contracts: ContractNode[];
|
package/dist/ast.js
CHANGED
|
@@ -15,10 +15,12 @@ exports.PropertyType = {
|
|
|
15
15
|
exports.PropertyModifiers = {
|
|
16
16
|
Error: {
|
|
17
17
|
packageName: 'aeria',
|
|
18
|
+
importPath: 'aeria',
|
|
18
19
|
symbolName: 'errorSchema',
|
|
19
20
|
},
|
|
20
21
|
Result: {
|
|
21
22
|
packageName: 'aeria',
|
|
23
|
+
importPath: 'aeria',
|
|
22
24
|
symbolName: 'resultSchema',
|
|
23
25
|
},
|
|
24
26
|
};
|
package/dist/ast.mjs
CHANGED
|
@@ -13,10 +13,12 @@ export const PropertyType = {
|
|
|
13
13
|
export const PropertyModifiers = {
|
|
14
14
|
Error: {
|
|
15
15
|
packageName: "aeria",
|
|
16
|
+
importPath: "aeria",
|
|
16
17
|
symbolName: "errorSchema"
|
|
17
18
|
},
|
|
18
19
|
Result: {
|
|
19
20
|
packageName: "aeria",
|
|
21
|
+
importPath: "aeria",
|
|
20
22
|
symbolName: "resultSchema"
|
|
21
23
|
}
|
|
22
24
|
};
|
|
@@ -99,8 +99,13 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
|
|
|
99
99
|
}
|
|
100
100
|
return (0, utils_js_1.stringify)(collectionSchema);
|
|
101
101
|
};
|
|
102
|
-
const makeJSFunctions = (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const makeJSFunctions = (functionNodes) => {
|
|
103
|
+
let output = '';
|
|
104
|
+
for (const functionNode of functionNodes) {
|
|
105
|
+
output += functionNode.exportSymbol
|
|
106
|
+
? functionNode.exportSymbol.symbolName
|
|
107
|
+
: `${functionNode.name}: () => { throw new Error('Function not implemented') }`;
|
|
108
|
+
output += ', ';
|
|
109
|
+
}
|
|
110
|
+
return output;
|
|
106
111
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, getCollectionId, UnquotedSymbol, getExposedFunctions, getExtendName, PACKAGE_NAME
|
|
2
|
+
import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, getCollectionId, UnquotedSymbol, getExposedFunctions, getExtendName, PACKAGE_NAME } from "./utils.mjs";
|
|
3
3
|
const initialImportedFunctions = [
|
|
4
4
|
"extendCollection",
|
|
5
5
|
"defineCollection"
|
|
@@ -92,6 +92,11 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
|
|
|
92
92
|
}
|
|
93
93
|
return stringify(collectionSchema);
|
|
94
94
|
};
|
|
95
|
-
const makeJSFunctions = (
|
|
96
|
-
|
|
95
|
+
const makeJSFunctions = (functionNodes) => {
|
|
96
|
+
let output = "";
|
|
97
|
+
for (const functionNode of functionNodes) {
|
|
98
|
+
output += functionNode.exportSymbol ? functionNode.exportSymbol.symbolName : `${functionNode.name}: () => { throw new Error('Function not implemented') }`;
|
|
99
|
+
output += ", ";
|
|
100
|
+
}
|
|
101
|
+
return output;
|
|
97
102
|
};
|
|
@@ -106,13 +106,14 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
106
106
|
}
|
|
107
107
|
return (0, utils_js_1.stringify)(collectionSchema);
|
|
108
108
|
};
|
|
109
|
-
const makeTSFunctions = (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
const makeTSFunctions = (functionNodes) => {
|
|
110
|
+
const funs = {};
|
|
111
|
+
for (const functionNode of functionNodes) {
|
|
112
|
+
funs[functionNode.name] = {
|
|
113
|
+
[utils_js_1.UnquotedSymbol]: functionNode.exportSymbol
|
|
114
|
+
? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}`
|
|
114
115
|
: 'unknown',
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
}
|
|
118
|
+
return funs;
|
|
118
119
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME
|
|
2
|
+
import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME } from "./utils.mjs";
|
|
3
3
|
const initialImportedTypes = [
|
|
4
4
|
"Collection",
|
|
5
5
|
"SchemaWithId",
|
|
@@ -102,11 +102,12 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
102
102
|
}
|
|
103
103
|
return stringify(collectionSchema);
|
|
104
104
|
};
|
|
105
|
-
const makeTSFunctions = (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const makeTSFunctions = (functionNodes) => {
|
|
106
|
+
const funs = {};
|
|
107
|
+
for (const functionNode of functionNodes) {
|
|
108
|
+
funs[functionNode.name] = {
|
|
109
|
+
[UnquotedSymbol]: functionNode.exportSymbol ? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}` : "unknown"
|
|
109
110
|
};
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
}
|
|
112
|
+
return funs;
|
|
112
113
|
};
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -2,13 +2,12 @@ import type * as AST from '../ast.js';
|
|
|
2
2
|
import type { Property } from '@aeriajs/types';
|
|
3
3
|
export declare const PACKAGE_NAME = "aeria";
|
|
4
4
|
export declare const MIDDLEWARES_RUNTIME_PATH = "../../../dist/middlewares/index.js";
|
|
5
|
-
export declare const DEFAULT_FUNCTIONS: string[];
|
|
6
5
|
export declare const UnquotedSymbol: unique symbol;
|
|
7
6
|
export declare const ArraySymbol: unique symbol;
|
|
8
7
|
export type StringifyProperty = unknown | {
|
|
9
8
|
[UnquotedSymbol]: string;
|
|
10
9
|
};
|
|
11
|
-
export declare const getExposedFunctions: (
|
|
10
|
+
export declare const getExposedFunctions: (functionNodes: AST.FunctionNode[]) => {
|
|
12
11
|
[k: string]: import("@aeriajs/types").AccessCondition;
|
|
13
12
|
};
|
|
14
13
|
export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<string, Set<string>>, options?: {
|
package/dist/codegen/utils.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.recursivelyUnwrapPropertyNodes = exports.unwrapPropertyNode = exports.unwrapNode = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.UnquotedSymbol = exports.
|
|
3
|
+
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.recursivelyUnwrapPropertyNodes = exports.unwrapPropertyNode = exports.unwrapNode = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.UnquotedSymbol = exports.MIDDLEWARES_RUNTIME_PATH = exports.PACKAGE_NAME = void 0;
|
|
4
4
|
exports.PACKAGE_NAME = 'aeria';
|
|
5
5
|
exports.MIDDLEWARES_RUNTIME_PATH = '../../../dist/middlewares/index.js';
|
|
6
|
-
exports.DEFAULT_FUNCTIONS = [
|
|
7
|
-
'count',
|
|
8
|
-
'get',
|
|
9
|
-
'getAll',
|
|
10
|
-
'insert',
|
|
11
|
-
'remove',
|
|
12
|
-
'removeAll',
|
|
13
|
-
'removeFile',
|
|
14
|
-
'unpaginatedGetAll',
|
|
15
|
-
'upload',
|
|
16
|
-
];
|
|
17
6
|
exports.UnquotedSymbol = Symbol('unquoted');
|
|
18
7
|
exports.ArraySymbol = Symbol('array');
|
|
19
|
-
const getExposedFunctions = (
|
|
20
|
-
return Object.fromEntries(
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
const getExposedFunctions = (functionNodes) => {
|
|
9
|
+
return Object.fromEntries(functionNodes.map((node) => [
|
|
10
|
+
node.name,
|
|
11
|
+
node.accessCondition,
|
|
23
12
|
]));
|
|
24
13
|
};
|
|
25
14
|
exports.getExposedFunctions = getExposedFunctions;
|
|
26
|
-
const makeASTImports = (ast, initialImports, options = {
|
|
15
|
+
const makeASTImports = (ast, initialImports = {}, options = {
|
|
27
16
|
includeRuntimeOnlyImports: false,
|
|
28
17
|
}) => {
|
|
29
18
|
const modifiedSymbols = {};
|
|
30
19
|
const toImport = ast.reduce((imports, node) => {
|
|
31
20
|
if (node.kind === 'collection') {
|
|
32
|
-
if (node.extends
|
|
33
|
-
|
|
34
|
-
imports[node.extends.packageName] = new Set();
|
|
35
|
-
}
|
|
36
|
-
const modifiedSymbol = `original${(0, exports.resizeFirstChar)(node.extends.symbolName, true)}`;
|
|
21
|
+
if (node.extends) {
|
|
22
|
+
const modifiedSymbol = `${node.extends.packageName}${(0, exports.resizeFirstChar)(node.extends.symbolName, true)}`;
|
|
37
23
|
modifiedSymbols[node.extends.symbolName] = modifiedSymbol;
|
|
38
|
-
imports[node.extends.
|
|
24
|
+
imports[node.extends.importPath] ??= new Set();
|
|
25
|
+
imports[node.extends.importPath].add(`${node.extends.symbolName} as ${modifiedSymbol}`);
|
|
39
26
|
}
|
|
40
27
|
if (node.functions) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
imports[
|
|
28
|
+
for (const functionNode of node.functions) {
|
|
29
|
+
if (functionNode.exportSymbol) {
|
|
30
|
+
const { importPath, symbolName } = functionNode.exportSymbol;
|
|
31
|
+
imports[importPath] ??= new Set();
|
|
32
|
+
imports[importPath].add(symbolName);
|
|
46
33
|
}
|
|
47
34
|
}
|
|
48
35
|
}
|
|
@@ -56,7 +43,7 @@ const makeASTImports = (ast, initialImports, options = {
|
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
45
|
return imports;
|
|
59
|
-
}, initialImports
|
|
46
|
+
}, initialImports);
|
|
60
47
|
return {
|
|
61
48
|
code: Object.keys(toImport).map((key) => `import { ${Array.from(toImport[key]).join(', ')} } from '${key}'`),
|
|
62
49
|
modifiedSymbols,
|
package/dist/codegen/utils.mjs
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export const PACKAGE_NAME = "aeria";
|
|
3
3
|
export const MIDDLEWARES_RUNTIME_PATH = "../../../dist/middlewares/index.mjs";
|
|
4
|
-
export const DEFAULT_FUNCTIONS = [
|
|
5
|
-
"count",
|
|
6
|
-
"get",
|
|
7
|
-
"getAll",
|
|
8
|
-
"insert",
|
|
9
|
-
"remove",
|
|
10
|
-
"removeAll",
|
|
11
|
-
"removeFile",
|
|
12
|
-
"unpaginatedGetAll",
|
|
13
|
-
"upload"
|
|
14
|
-
];
|
|
15
4
|
export const UnquotedSymbol = Symbol("unquoted");
|
|
16
5
|
export const ArraySymbol = Symbol("array");
|
|
17
|
-
export const getExposedFunctions = (
|
|
18
|
-
return Object.fromEntries(
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
export const getExposedFunctions = (functionNodes) => {
|
|
7
|
+
return Object.fromEntries(functionNodes.map((node) => [
|
|
8
|
+
node.name,
|
|
9
|
+
node.accessCondition
|
|
21
10
|
]));
|
|
22
11
|
};
|
|
23
|
-
export const makeASTImports = (ast, initialImports, options = {
|
|
12
|
+
export const makeASTImports = (ast, initialImports = {}, options = {
|
|
24
13
|
includeRuntimeOnlyImports: false
|
|
25
14
|
}) => {
|
|
26
15
|
const modifiedSymbols = {};
|
|
27
16
|
const toImport = ast.reduce((imports, node) => {
|
|
28
17
|
if (node.kind === "collection") {
|
|
29
|
-
if (node.extends
|
|
30
|
-
|
|
31
|
-
imports[node.extends.packageName] = /* @__PURE__ */ new Set();
|
|
32
|
-
}
|
|
33
|
-
const modifiedSymbol = `original${resizeFirstChar(node.extends.symbolName, true)}`;
|
|
18
|
+
if (node.extends) {
|
|
19
|
+
const modifiedSymbol = `${node.extends.packageName}${resizeFirstChar(node.extends.symbolName, true)}`;
|
|
34
20
|
modifiedSymbols[node.extends.symbolName] = modifiedSymbol;
|
|
35
|
-
imports[node.extends.
|
|
21
|
+
imports[node.extends.importPath] ??= /* @__PURE__ */ new Set();
|
|
22
|
+
imports[node.extends.importPath].add(`${node.extends.symbolName} as ${modifiedSymbol}`);
|
|
36
23
|
}
|
|
37
24
|
if (node.functions) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
imports[
|
|
25
|
+
for (const functionNode of node.functions) {
|
|
26
|
+
if (functionNode.exportSymbol) {
|
|
27
|
+
const { importPath, symbolName } = functionNode.exportSymbol;
|
|
28
|
+
imports[importPath] ??= /* @__PURE__ */ new Set();
|
|
29
|
+
imports[importPath].add(symbolName);
|
|
43
30
|
}
|
|
44
31
|
}
|
|
45
32
|
}
|
|
@@ -53,7 +40,7 @@ export const makeASTImports = (ast, initialImports, options = {
|
|
|
53
40
|
}
|
|
54
41
|
}
|
|
55
42
|
return imports;
|
|
56
|
-
}, initialImports
|
|
43
|
+
}, initialImports);
|
|
57
44
|
return {
|
|
58
45
|
code: Object.keys(toImport).map((key) => `import { ${Array.from(toImport[key]).join(", ")} } from '${key}'`),
|
|
59
46
|
modifiedSymbols
|
package/dist/compile.js
CHANGED
|
@@ -52,7 +52,7 @@ const postflight = (ast) => {
|
|
|
52
52
|
errors.push(new diagnostic_js_1.Diagnostic(`invalid function set "${functionSetName}"`, location));
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
node.functions.push(...functionSet.functions);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
package/dist/compile.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export const postflight = (ast) => {
|
|
|
17
17
|
errors.push(new Diagnostic(`invalid function set "${functionSetName}"`, location));
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
node.functions.push(...functionSet.functions);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import * as AST from './ast.js';
|
|
1
2
|
import { type Token, type Location } from './token.js';
|
|
2
3
|
import { Diagnostic } from './diagnostic.js';
|
|
3
|
-
import * as AST from './ast.js';
|
|
4
4
|
export declare const locationMap: WeakMap<symbol, Location>;
|
|
5
5
|
export declare const memoTable: {
|
|
6
6
|
roles?: readonly string[];
|
|
7
|
+
defaultExportSymbols?: Record<string, string>;
|
|
7
8
|
};
|
|
8
9
|
export declare const parse: (tokens: (Token | undefined)[]) => {
|
|
9
10
|
ast: AST.ProgramNode;
|
package/dist/parser.js
CHANGED
|
@@ -34,17 +34,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.parse = exports.memoTable = exports.locationMap = void 0;
|
|
37
|
-
const token_js_1 = require("./token.js");
|
|
38
37
|
const types_1 = require("@aeriajs/types");
|
|
39
38
|
const core_1 = require("@phosphor-icons/core");
|
|
40
|
-
const diagnostic_js_1 = require("./diagnostic.js");
|
|
41
39
|
const AST = __importStar(require("./ast.js"));
|
|
42
40
|
const guards = __importStar(require("./guards.js"));
|
|
43
41
|
const lexer = __importStar(require("./lexer.js"));
|
|
42
|
+
const token_js_1 = require("./token.js");
|
|
43
|
+
const diagnostic_js_1 = require("./diagnostic.js");
|
|
44
|
+
const utils_js_1 = require("./utils.js");
|
|
44
45
|
const MAX_ERROR_MESSAGE_ITEMS = 20;
|
|
45
46
|
const ICON_NAMES = core_1.icons.map((icon) => icon.name);
|
|
46
47
|
exports.locationMap = new WeakMap();
|
|
47
|
-
exports.memoTable = {
|
|
48
|
+
exports.memoTable = {
|
|
49
|
+
defaultExportSymbols: utils_js_1.DEFAULT_EXPORT_SYMBOLS,
|
|
50
|
+
};
|
|
48
51
|
const isFileProperty = (property) => {
|
|
49
52
|
return property.$ref === 'File';
|
|
50
53
|
};
|
|
@@ -682,6 +685,7 @@ const parse = (tokens) => {
|
|
|
682
685
|
const { value: symbolName } = consume(token_js_1.TokenType.Identifier);
|
|
683
686
|
node.extends = {
|
|
684
687
|
packageName,
|
|
688
|
+
importPath: packageName,
|
|
685
689
|
symbolName: symbolName[0].toLowerCase() + symbolName.slice(1),
|
|
686
690
|
};
|
|
687
691
|
}
|
|
@@ -827,7 +831,7 @@ const parse = (tokens) => {
|
|
|
827
831
|
};
|
|
828
832
|
const parseFunctionsBlock = () => {
|
|
829
833
|
consume(token_js_1.TokenType.LeftBracket);
|
|
830
|
-
const functions =
|
|
834
|
+
const functions = [];
|
|
831
835
|
const functionSets = [];
|
|
832
836
|
while (!match(token_js_1.TokenType.RightBracket)) {
|
|
833
837
|
try {
|
|
@@ -848,23 +852,48 @@ const parse = (tokens) => {
|
|
|
848
852
|
}
|
|
849
853
|
continue;
|
|
850
854
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
+
let functionNode;
|
|
856
|
+
if (current().type === token_js_1.TokenType.Identifier && next().type === token_js_1.TokenType.Dot) {
|
|
857
|
+
const { value: packageName } = consume(token_js_1.TokenType.Identifier);
|
|
858
|
+
consume(token_js_1.TokenType.Dot);
|
|
859
|
+
const { value: symbolName } = consume(token_js_1.TokenType.Identifier);
|
|
860
|
+
functionNode = {
|
|
861
|
+
kind: 'function',
|
|
862
|
+
name: symbolName,
|
|
863
|
+
exportSymbol: {
|
|
864
|
+
packageName,
|
|
865
|
+
importPath: packageName,
|
|
866
|
+
symbolName,
|
|
867
|
+
},
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
const { value: functionName } = consume(token_js_1.TokenType.Identifier);
|
|
872
|
+
let exportSymbol;
|
|
873
|
+
if (exports.memoTable.defaultExportSymbols && functionName in exports.memoTable.defaultExportSymbols) {
|
|
874
|
+
const packageName = exports.memoTable.defaultExportSymbols[functionName];
|
|
875
|
+
exportSymbol = {
|
|
876
|
+
packageName,
|
|
877
|
+
importPath: packageName,
|
|
878
|
+
symbolName: functionName,
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
functionNode = {
|
|
882
|
+
kind: 'function',
|
|
883
|
+
name: functionName,
|
|
884
|
+
exportSymbol,
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
functions.push(functionNode);
|
|
855
888
|
while (match(token_js_1.TokenType.AttributeName, 'expose')) {
|
|
856
889
|
consume(token_js_1.TokenType.AttributeName, 'expose');
|
|
857
890
|
if (match(token_js_1.TokenType.LeftParens)) {
|
|
858
891
|
consume(token_js_1.TokenType.LeftParens);
|
|
859
|
-
|
|
860
|
-
accessCondition: parseAccessCondition(),
|
|
861
|
-
};
|
|
892
|
+
functionNode.accessCondition = parseAccessCondition();
|
|
862
893
|
consume(token_js_1.TokenType.RightParens);
|
|
863
894
|
}
|
|
864
895
|
else {
|
|
865
|
-
|
|
866
|
-
accessCondition: true,
|
|
867
|
-
};
|
|
896
|
+
functionNode.accessCondition = true;
|
|
868
897
|
}
|
|
869
898
|
}
|
|
870
899
|
}
|
package/dist/parser.mjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { TokenType } from "./token.mjs";
|
|
3
2
|
import { DESCRIPTION_PRESETS, LAYOUT_NAMES, PROPERTY_ARRAY_ELEMENTS, PROPERTY_FORMATS, PROPERTY_INPUT_ELEMENTS, PROPERTY_INPUT_TYPES } from "@aeriajs/types";
|
|
4
3
|
import { icons } from "@phosphor-icons/core";
|
|
5
|
-
import { Diagnostic } from "./diagnostic.mjs";
|
|
6
4
|
import * as AST from "./ast.mjs";
|
|
7
5
|
import * as guards from "./guards.mjs";
|
|
8
6
|
import * as lexer from "./lexer.mjs";
|
|
7
|
+
import { TokenType } from "./token.mjs";
|
|
8
|
+
import { Diagnostic } from "./diagnostic.mjs";
|
|
9
|
+
import { DEFAULT_EXPORT_SYMBOLS } from "./utils.mjs";
|
|
9
10
|
const MAX_ERROR_MESSAGE_ITEMS = 20;
|
|
10
11
|
const ICON_NAMES = icons.map((icon) => icon.name);
|
|
11
12
|
export const locationMap = /* @__PURE__ */ new WeakMap();
|
|
12
|
-
export const memoTable = {
|
|
13
|
+
export const memoTable = {
|
|
14
|
+
defaultExportSymbols: DEFAULT_EXPORT_SYMBOLS
|
|
15
|
+
};
|
|
13
16
|
const isFileProperty = (property) => {
|
|
14
17
|
return property.$ref === "File";
|
|
15
18
|
};
|
|
@@ -629,6 +632,7 @@ export const parse = (tokens) => {
|
|
|
629
632
|
const { value: symbolName } = consume(TokenType.Identifier);
|
|
630
633
|
node.extends = {
|
|
631
634
|
packageName,
|
|
635
|
+
importPath: packageName,
|
|
632
636
|
symbolName: symbolName[0].toLowerCase() + symbolName.slice(1)
|
|
633
637
|
};
|
|
634
638
|
}
|
|
@@ -772,7 +776,7 @@ export const parse = (tokens) => {
|
|
|
772
776
|
};
|
|
773
777
|
const parseFunctionsBlock = () => {
|
|
774
778
|
consume(TokenType.LeftBracket);
|
|
775
|
-
const functions =
|
|
779
|
+
const functions = [];
|
|
776
780
|
const functionSets = [];
|
|
777
781
|
while (!match(TokenType.RightBracket)) {
|
|
778
782
|
try {
|
|
@@ -793,22 +797,46 @@ export const parse = (tokens) => {
|
|
|
793
797
|
}
|
|
794
798
|
continue;
|
|
795
799
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
+
let functionNode;
|
|
801
|
+
if (current().type === TokenType.Identifier && next().type === TokenType.Dot) {
|
|
802
|
+
const { value: packageName } = consume(TokenType.Identifier);
|
|
803
|
+
consume(TokenType.Dot);
|
|
804
|
+
const { value: symbolName } = consume(TokenType.Identifier);
|
|
805
|
+
functionNode = {
|
|
806
|
+
kind: "function",
|
|
807
|
+
name: symbolName,
|
|
808
|
+
exportSymbol: {
|
|
809
|
+
packageName,
|
|
810
|
+
importPath: packageName,
|
|
811
|
+
symbolName
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
} else {
|
|
815
|
+
const { value: functionName } = consume(TokenType.Identifier);
|
|
816
|
+
let exportSymbol;
|
|
817
|
+
if (memoTable.defaultExportSymbols && functionName in memoTable.defaultExportSymbols) {
|
|
818
|
+
const packageName = memoTable.defaultExportSymbols[functionName];
|
|
819
|
+
exportSymbol = {
|
|
820
|
+
packageName,
|
|
821
|
+
importPath: packageName,
|
|
822
|
+
symbolName: functionName
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
functionNode = {
|
|
826
|
+
kind: "function",
|
|
827
|
+
name: functionName,
|
|
828
|
+
exportSymbol
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
functions.push(functionNode);
|
|
800
832
|
while (match(TokenType.AttributeName, "expose")) {
|
|
801
833
|
consume(TokenType.AttributeName, "expose");
|
|
802
834
|
if (match(TokenType.LeftParens)) {
|
|
803
835
|
consume(TokenType.LeftParens);
|
|
804
|
-
|
|
805
|
-
accessCondition: parseAccessCondition()
|
|
806
|
-
};
|
|
836
|
+
functionNode.accessCondition = parseAccessCondition();
|
|
807
837
|
consume(TokenType.RightParens);
|
|
808
838
|
} else {
|
|
809
|
-
|
|
810
|
-
accessCondition: true
|
|
811
|
-
};
|
|
839
|
+
functionNode.accessCondition = true;
|
|
812
840
|
}
|
|
813
841
|
}
|
|
814
842
|
} catch (err) {
|
package/dist/semantic.js
CHANGED
|
@@ -45,8 +45,8 @@ const collectionHasProperty = async (collection, propName, options = {}) => {
|
|
|
45
45
|
if (options.languageServer) {
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
const {
|
|
49
|
-
const { [symbolName]: importedCollection } = await Promise.resolve(`${
|
|
48
|
+
const { importPath, symbolName } = collection.extends;
|
|
49
|
+
const { [symbolName]: importedCollection } = await Promise.resolve(`${importPath}`).then(s => __importStar(require(s)));
|
|
50
50
|
if (!(0, common_1.isValidCollection)(importedCollection)) {
|
|
51
51
|
throw new Error;
|
|
52
52
|
}
|
|
@@ -89,9 +89,10 @@ const analyze = async (ast, options, errors = []) => {
|
|
|
89
89
|
}
|
|
90
90
|
for (const index in node.property[attributeName]) {
|
|
91
91
|
const propName = node.property[attributeName][index];
|
|
92
|
-
if (!(propName in node.
|
|
92
|
+
if (!(propName in node.nestedProperties)) {
|
|
93
93
|
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
94
94
|
const location = parser_js_1.locationMap.get(symbol);
|
|
95
|
+
console.log(JSON.stringify(node));
|
|
95
96
|
errors.push(new diagnostic_js_1.Diagnostic(`object hasn't such property "${propName}"`, location));
|
|
96
97
|
}
|
|
97
98
|
}
|
package/dist/semantic.mjs
CHANGED
|
@@ -10,8 +10,8 @@ const collectionHasProperty = async (collection, propName, options = {}) => {
|
|
|
10
10
|
if (options.languageServer) {
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
|
-
const {
|
|
14
|
-
const { [symbolName]: importedCollection } = await import(
|
|
13
|
+
const { importPath, symbolName } = collection.extends;
|
|
14
|
+
const { [symbolName]: importedCollection } = await import(importPath);
|
|
15
15
|
if (!isValidCollection(importedCollection)) {
|
|
16
16
|
throw new Error();
|
|
17
17
|
}
|
|
@@ -54,9 +54,10 @@ export const analyze = async (ast, options, errors = []) => {
|
|
|
54
54
|
}
|
|
55
55
|
for (const index in node.property[attributeName]) {
|
|
56
56
|
const propName = node.property[attributeName][index];
|
|
57
|
-
if (!(propName in node.
|
|
57
|
+
if (!(propName in node.nestedProperties)) {
|
|
58
58
|
const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
|
|
59
59
|
const location = locationMap.get(symbol);
|
|
60
|
+
console.log(JSON.stringify(node));
|
|
60
61
|
errors.push(new Diagnostic(`object hasn't such property "${propName}"`, location));
|
|
61
62
|
}
|
|
62
63
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export type ArrayProperties<T> = keyof {
|
|
2
2
|
[P in Extract<keyof T, string> as NonNullable<T[P]> extends string[] | readonly string[] ? P : never]: never;
|
|
3
3
|
};
|
|
4
|
+
export declare const DEFAULT_EXPORT_SYMBOLS: {
|
|
5
|
+
count: string;
|
|
6
|
+
get: string;
|
|
7
|
+
getAll: string;
|
|
8
|
+
insert: string;
|
|
9
|
+
remove: string;
|
|
10
|
+
removeAll: string;
|
|
11
|
+
removeFile: string;
|
|
12
|
+
unpaginatedGetAll: string;
|
|
13
|
+
upload: string;
|
|
14
|
+
};
|
package/dist/utils.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_EXPORT_SYMBOLS = void 0;
|
|
4
|
+
exports.DEFAULT_EXPORT_SYMBOLS = {
|
|
5
|
+
count: 'aeria',
|
|
6
|
+
get: 'aeria',
|
|
7
|
+
getAll: 'aeria',
|
|
8
|
+
insert: 'aeria',
|
|
9
|
+
remove: 'aeria',
|
|
10
|
+
removeAll: 'aeria',
|
|
11
|
+
removeFile: 'aeria',
|
|
12
|
+
unpaginatedGetAll: 'aeria',
|
|
13
|
+
upload: 'aeria',
|
|
14
|
+
};
|
package/dist/utils.mjs
CHANGED