@aeriajs/compiler 0.0.66 → 0.0.68
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/generateExports.js +5 -2
- package/dist/codegen/generateJSCollections.d.ts +1 -1
- package/dist/codegen/generateJSCollections.js +27 -20
- package/dist/codegen/generateTSCollections.d.ts +1 -1
- package/dist/codegen/generateTSCollections.js +24 -21
- package/dist/codegen/utils.d.ts +1 -2
- package/dist/codegen/utils.js +12 -13
- package/dist/codegen.js +2 -2
- package/dist/parser.js +4 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +8 -0
- package/package.json +2 -2
package/dist/ast.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformSymbolName } from '../utils.js';
|
|
2
|
+
import { getExtendName, getCollectionId } from './utils.js';
|
|
2
3
|
export const generateExports = (ast, options = {
|
|
3
4
|
hasContracts: false,
|
|
4
5
|
}) => {
|
|
@@ -6,7 +7,9 @@ export const generateExports = (ast, options = {
|
|
|
6
7
|
const id = getCollectionId(node.name);
|
|
7
8
|
symbols[id] = {
|
|
8
9
|
id,
|
|
9
|
-
schema:
|
|
10
|
+
schema: transformSymbolName(node.name, {
|
|
11
|
+
capitalize: true,
|
|
12
|
+
}),
|
|
10
13
|
extend: getExtendName(node.name),
|
|
11
14
|
};
|
|
12
15
|
return symbols;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type * as AST from '../ast.js';
|
|
2
|
-
export declare const generateJSCollections: (ast: AST.ProgramNode) => string
|
|
2
|
+
export declare const generateJSCollections: (ast: AST.ProgramNode) => Promise<string>;
|
|
@@ -3,7 +3,7 @@ const initialImportedFunctions = [
|
|
|
3
3
|
'extendCollection',
|
|
4
4
|
'defineCollection',
|
|
5
5
|
];
|
|
6
|
-
export const generateJSCollections = (ast) => {
|
|
6
|
+
export const generateJSCollections = async (ast) => {
|
|
7
7
|
let javascriptCode = '';
|
|
8
8
|
const importsResult = makeASTImports(ast.collections, {
|
|
9
9
|
[PACKAGE_NAME]: new Set(initialImportedFunctions),
|
|
@@ -11,19 +11,36 @@ export const generateJSCollections = (ast) => {
|
|
|
11
11
|
includeRuntimeOnlyImports: true,
|
|
12
12
|
});
|
|
13
13
|
javascriptCode += importsResult.code.join('\n') + '\n\n';
|
|
14
|
-
javascriptCode += makeJSCollections(ast, importsResult.
|
|
14
|
+
javascriptCode += await makeJSCollections(ast, importsResult.aliasedSymbols) + '\n\n';
|
|
15
15
|
return javascriptCode;
|
|
16
16
|
};
|
|
17
|
-
const
|
|
17
|
+
const makeJSFunctions = async (collectionNode) => {
|
|
18
|
+
let output = '';
|
|
19
|
+
for (const functionNode of collectionNode.functions) {
|
|
20
|
+
if (collectionNode.extends) {
|
|
21
|
+
const module = await import(collectionNode.extends.importPath);
|
|
22
|
+
const collection = module[collectionNode.extends.symbolName];
|
|
23
|
+
if (collection.functions && typeof collection.functions[functionNode.name] === 'function') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
output += functionNode.exportSymbol
|
|
28
|
+
? functionNode.exportSymbol.symbolName
|
|
29
|
+
: `${functionNode.name}: () => { throw new Error('Function not implemented') }`;
|
|
30
|
+
output += ', ';
|
|
31
|
+
}
|
|
32
|
+
return output;
|
|
33
|
+
};
|
|
34
|
+
const makeJSCollections = async (ast, aliasedSymbols) => {
|
|
18
35
|
const collectionCodes = {};
|
|
19
36
|
for (const collectionNode of ast.collections) {
|
|
20
|
-
const id = getCollectionId(collectionNode.name);
|
|
37
|
+
const id = getCollectionId(collectionNode.name);
|
|
21
38
|
const extendCollectionName = getExtendName(collectionNode.name);
|
|
22
39
|
const collectionDefinition = `export const ${id} = ${collectionNode.extends
|
|
23
|
-
? `extendCollection(${id in
|
|
24
|
-
?
|
|
25
|
-
: id}, ${makeJSCollectionSchema(ast, collectionNode, id)})`
|
|
26
|
-
: `defineCollection(${makeJSCollectionSchema(ast, collectionNode, id)})`}`;
|
|
40
|
+
? `extendCollection(${id in aliasedSymbols
|
|
41
|
+
? aliasedSymbols[id]
|
|
42
|
+
: id}, ${await makeJSCollectionSchema(ast, collectionNode, id)})`
|
|
43
|
+
: `defineCollection(${await makeJSCollectionSchema(ast, collectionNode, id)})`}`;
|
|
27
44
|
const collectionDeclaration = `export const ${extendCollectionName} = (collection) => extendCollection(${id}, collection)`;
|
|
28
45
|
collectionCodes[collectionNode.name] = [
|
|
29
46
|
'//' + collectionNode.name,
|
|
@@ -33,7 +50,7 @@ const makeJSCollections = (ast, modifiedSymbols) => {
|
|
|
33
50
|
}
|
|
34
51
|
return Object.values(collectionCodes).join('\n\n');
|
|
35
52
|
};
|
|
36
|
-
const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
|
|
53
|
+
const makeJSCollectionSchema = async (ast, collectionNode, collectionId) => {
|
|
37
54
|
const collectionSchema = {
|
|
38
55
|
item: {},
|
|
39
56
|
description: {
|
|
@@ -59,7 +76,7 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
|
|
|
59
76
|
break;
|
|
60
77
|
case 'functions':
|
|
61
78
|
collectionSchema.functions = {
|
|
62
|
-
[UnquotedSymbol]: `{ ${makeJSFunctions(collectionNode
|
|
79
|
+
[UnquotedSymbol]: `{ ${await makeJSFunctions(collectionNode)} }`,
|
|
63
80
|
};
|
|
64
81
|
collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
|
|
65
82
|
break;
|
|
@@ -96,13 +113,3 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
|
|
|
96
113
|
}
|
|
97
114
|
return stringify(collectionSchema);
|
|
98
115
|
};
|
|
99
|
-
const makeJSFunctions = (functionNodes) => {
|
|
100
|
-
let output = '';
|
|
101
|
-
for (const functionNode of functionNodes) {
|
|
102
|
-
output += functionNode.exportSymbol
|
|
103
|
-
? functionNode.exportSymbol.symbolName
|
|
104
|
-
: `${functionNode.name}: () => { throw new Error('Function not implemented') }`;
|
|
105
|
-
output += ', ';
|
|
106
|
-
}
|
|
107
|
-
return output;
|
|
108
|
-
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type * as AST from '../ast.js';
|
|
2
|
-
export declare const generateTSCollections: (ast: AST.ProgramNode) => string
|
|
2
|
+
export declare const generateTSCollections: (ast: AST.ProgramNode) => Promise<string>;
|
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformSymbolName } from '../utils.js';
|
|
2
|
+
import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME } from './utils.js';
|
|
2
3
|
const initialImportedTypes = [
|
|
3
4
|
'Collection',
|
|
4
5
|
'SchemaWithId',
|
|
5
6
|
'ExtendCollection',
|
|
6
7
|
'Context',
|
|
7
8
|
];
|
|
8
|
-
|
|
9
|
+
const makeTSFunctions = (collectionNode) => {
|
|
10
|
+
const funs = {};
|
|
11
|
+
for (const functionNode of collectionNode.functions) {
|
|
12
|
+
funs[functionNode.name] = {
|
|
13
|
+
[UnquotedSymbol]: functionNode.exportSymbol
|
|
14
|
+
? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}`
|
|
15
|
+
: 'unknown',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return funs;
|
|
19
|
+
};
|
|
20
|
+
export const generateTSCollections = async (ast) => {
|
|
9
21
|
let code = '';
|
|
10
22
|
code += `import type { ${initialImportedTypes.join(', ')} } from '${PACKAGE_NAME}'\n`; //Used types
|
|
11
23
|
const importsResult = makeASTImports(ast.collections);
|
|
12
24
|
code += importsResult.code.join('\n') + '\n\n';
|
|
13
|
-
code += makeTSCollections(ast, importsResult.
|
|
25
|
+
code += makeTSCollections(ast, importsResult.aliasedSymbols) + '\n';
|
|
14
26
|
return code;
|
|
15
27
|
};
|
|
16
|
-
const makeTSCollections = (ast,
|
|
28
|
+
const makeTSCollections = (ast, aliasedSymbols) => {
|
|
17
29
|
const collectionCodes = {};
|
|
18
30
|
for (const collectionNode of ast.collections) {
|
|
19
|
-
const id = getCollectionId(collectionNode.name);
|
|
20
|
-
const schemaName =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const id = getCollectionId(collectionNode.name);
|
|
32
|
+
const schemaName = transformSymbolName(collectionNode.name, {
|
|
33
|
+
capitalize: true,
|
|
34
|
+
});
|
|
35
|
+
const typeName = `${id}Collection`;
|
|
36
|
+
const collectionType = `export declare type ${typeName} = ${id in aliasedSymbols
|
|
37
|
+
? `ExtendCollection<typeof ${aliasedSymbols[id]}, ${makeTSCollectionSchema(collectionNode, id)}>`
|
|
24
38
|
: makeTSCollectionSchema(collectionNode, id)}`;
|
|
25
39
|
const collectionDeclaration = `export declare const ${id}: ${typeName} & { item: SchemaWithId<${typeName}["description"]> }`;
|
|
26
40
|
const collectionSchema = `export declare type ${schemaName} = SchemaWithId<typeof ${id}.description>`;
|
|
@@ -67,7 +81,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
67
81
|
};
|
|
68
82
|
break;
|
|
69
83
|
case 'functions':
|
|
70
|
-
collectionSchema.functions = makeTSFunctions(collectionNode
|
|
84
|
+
collectionSchema.functions = makeTSFunctions(collectionNode);
|
|
71
85
|
collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
|
|
72
86
|
break;
|
|
73
87
|
case 'required':
|
|
@@ -103,14 +117,3 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
103
117
|
}
|
|
104
118
|
return stringify(collectionSchema);
|
|
105
119
|
};
|
|
106
|
-
const makeTSFunctions = (functionNodes) => {
|
|
107
|
-
const funs = {};
|
|
108
|
-
for (const functionNode of functionNodes) {
|
|
109
|
-
funs[functionNode.name] = {
|
|
110
|
-
[UnquotedSymbol]: functionNode.exportSymbol
|
|
111
|
-
? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}`
|
|
112
|
-
: 'unknown',
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
return funs;
|
|
116
|
-
};
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<s
|
|
|
14
14
|
includeRuntimeOnlyImports: boolean;
|
|
15
15
|
}) => {
|
|
16
16
|
code: string[];
|
|
17
|
-
|
|
17
|
+
aliasedSymbols: Record<string, string>;
|
|
18
18
|
};
|
|
19
19
|
export declare const unwrapNode: <TNode extends {
|
|
20
20
|
kind: string;
|
|
@@ -22,6 +22,5 @@ export declare const unwrapNode: <TNode extends {
|
|
|
22
22
|
export declare const unwrapPropertyNode: ({ property, nestedProperties, nestedAdditionalProperties }: Pick<AST.PropertyNode, "property" | "nestedProperties" | "nestedAdditionalProperties">) => Property;
|
|
23
23
|
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;
|
|
24
24
|
export declare const stringify: (value: StringifyProperty, parents?: (symbol | string)[]) => string;
|
|
25
|
-
export declare const resizeFirstChar: (text: string, capitalize: boolean) => string;
|
|
26
25
|
export declare const getCollectionId: (name: string) => string;
|
|
27
26
|
export declare const getExtendName: (name: string) => string;
|
package/dist/codegen/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transformSymbolName } from '../utils.js';
|
|
1
2
|
export const PACKAGE_NAME = 'aeria';
|
|
2
3
|
export const MIDDLEWARES_RUNTIME_PATH = '../../../dist/middlewares/index.js';
|
|
3
4
|
export const UnquotedSymbol = Symbol('unquoted');
|
|
@@ -11,14 +12,16 @@ export const getExposedFunctions = (functionNodes) => {
|
|
|
11
12
|
export const makeASTImports = (ast, initialImports = {}, options = {
|
|
12
13
|
includeRuntimeOnlyImports: false,
|
|
13
14
|
}) => {
|
|
14
|
-
const
|
|
15
|
+
const aliasedSymbols = {};
|
|
15
16
|
const toImport = ast.reduce((imports, node) => {
|
|
16
17
|
if (node.kind === 'collection') {
|
|
17
18
|
if (node.extends) {
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const aliasedSymbol = `${node.extends.packageName}${transformSymbolName(node.extends.symbolName, {
|
|
20
|
+
capitalize: true,
|
|
21
|
+
})}`;
|
|
22
|
+
aliasedSymbols[node.extends.symbolName] = aliasedSymbol;
|
|
20
23
|
imports[node.extends.importPath] ??= new Set();
|
|
21
|
-
imports[node.extends.importPath].add(`${node.extends.symbolName} as ${
|
|
24
|
+
imports[node.extends.importPath].add(`${node.extends.symbolName} as ${aliasedSymbol}`);
|
|
22
25
|
}
|
|
23
26
|
if (node.functions) {
|
|
24
27
|
for (const functionNode of node.functions) {
|
|
@@ -42,7 +45,7 @@ export const makeASTImports = (ast, initialImports = {}, options = {
|
|
|
42
45
|
}, initialImports);
|
|
43
46
|
return {
|
|
44
47
|
code: Object.keys(toImport).map((key) => `import { ${Array.from(toImport[key]).join(', ')} } from '${key}'`),
|
|
45
|
-
|
|
48
|
+
aliasedSymbols,
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
51
|
export const unwrapNode = (node) => {
|
|
@@ -157,11 +160,7 @@ const checkQuotes = (parents, value) => {
|
|
|
157
160
|
}
|
|
158
161
|
return stringify(value, parents);
|
|
159
162
|
};
|
|
160
|
-
export const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
165
|
-
};
|
|
166
|
-
export const getCollectionId = (name) => resizeFirstChar(name, false);
|
|
167
|
-
export const getExtendName = (name) => `extend${resizeFirstChar(name, true)}Collection`;
|
|
163
|
+
export const getCollectionId = (name) => transformSymbolName(name);
|
|
164
|
+
export const getExtendName = (name) => `extend${transformSymbolName(name, {
|
|
165
|
+
capitalize: true,
|
|
166
|
+
})}Collection`;
|
package/dist/codegen.js
CHANGED
|
@@ -27,8 +27,8 @@ export const generateCode = async (ast, options) => {
|
|
|
27
27
|
});
|
|
28
28
|
const fileTree = {
|
|
29
29
|
['collections']: {
|
|
30
|
-
['collections.d.ts']: generateTSCollections(ast),
|
|
31
|
-
['collections.js']: generateJSCollections(ast),
|
|
30
|
+
['collections.d.ts']: await generateTSCollections(ast),
|
|
31
|
+
['collections.js']: await generateJSCollections(ast),
|
|
32
32
|
['index.d.ts']: exports.collections.dts,
|
|
33
33
|
['index.js']: exports.collections.js,
|
|
34
34
|
},
|
package/dist/parser.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as guards from './guards.js';
|
|
|
5
5
|
import * as lexer from './lexer.js';
|
|
6
6
|
import { TokenType } from './token.js';
|
|
7
7
|
import { Diagnostic } from './diagnostic.js';
|
|
8
|
-
import { DEFAULT_EXPORT_SYMBOLS } from './utils.js';
|
|
8
|
+
import { DEFAULT_EXPORT_SYMBOLS, transformSymbolName } from './utils.js';
|
|
9
9
|
const MAX_ERROR_MESSAGE_ITEMS = 20;
|
|
10
10
|
const ICON_NAMES = icons.map((icon) => icon.name);
|
|
11
11
|
export const locationMap = new WeakMap();
|
|
@@ -663,6 +663,9 @@ export const parse = (tokens) => {
|
|
|
663
663
|
packageName,
|
|
664
664
|
importPath: packageName,
|
|
665
665
|
symbolName: symbolName[0].toLowerCase() + symbolName.slice(1),
|
|
666
|
+
aliasedSymbolName: `${packageName}${transformSymbolName(symbolName, {
|
|
667
|
+
capitalize: true,
|
|
668
|
+
})}`,
|
|
666
669
|
};
|
|
667
670
|
}
|
|
668
671
|
consume(TokenType.LeftBracket);
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -9,3 +9,11 @@ export const DEFAULT_EXPORT_SYMBOLS = {
|
|
|
9
9
|
unpaginatedGetAll: 'aeria',
|
|
10
10
|
upload: 'aeria',
|
|
11
11
|
};
|
|
12
|
+
export const transformSymbolName = (symbolName, options = {
|
|
13
|
+
capitalize: false,
|
|
14
|
+
}) => {
|
|
15
|
+
if (options.capitalize === true) {
|
|
16
|
+
return symbolName.charAt(0).toUpperCase() + symbolName.slice(1);
|
|
17
|
+
}
|
|
18
|
+
return symbolName.charAt(0).toLowerCase() + symbolName.slice(1);
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.68",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@aeriajs/common": "^0.0.
|
|
24
|
+
"@aeriajs/common": "^0.0.160",
|
|
25
25
|
"@aeriajs/types": "^0.0.136"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|