@aeriajs/compiler 0.0.6 → 0.0.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/codegen/generateJSCollections.js +2 -2
- package/dist/codegen/generateJSCollections.mjs +3 -3
- package/dist/codegen/generateTSCollections.js +2 -2
- package/dist/codegen/generateTSCollections.mjs +3 -3
- package/dist/codegen/utils.d.ts +3 -3
- package/dist/codegen/utils.js +16 -8
- package/dist/codegen/utils.mjs +15 -7
- package/dist/compile.d.ts +3 -3
- package/dist/compile.js +13 -9
- package/dist/compile.mjs +12 -8
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ const initialImportedFunctions = [
|
|
|
9
9
|
const generateJSCollections = (ast) => {
|
|
10
10
|
let javascriptCode = '';
|
|
11
11
|
const importsResult = (0, utils_js_1.makeASTImports)(ast, {
|
|
12
|
-
[utils_js_1.
|
|
12
|
+
[utils_js_1.PACKAGE_NAME]: new Set(initialImportedFunctions),
|
|
13
13
|
});
|
|
14
14
|
javascriptCode += importsResult.code + '\n\n';
|
|
15
15
|
javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + '\n\n';
|
|
@@ -85,7 +85,7 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
85
85
|
return (0, utils_js_1.stringify)(collectionSchema);
|
|
86
86
|
};
|
|
87
87
|
const makeJSFunctions = (functions) => {
|
|
88
|
-
return Object.entries(functions).map(([key, _value]) => utils_js_1.
|
|
88
|
+
return Object.entries(functions).map(([key, _value]) => utils_js_1.DEFAULT_FUNCTIONS.includes(key)
|
|
89
89
|
? key
|
|
90
90
|
: `${key}: () => { throw new Error('Function not implemented') }`).join(', ');
|
|
91
91
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { makeASTImports, getProperties, stringify,
|
|
2
|
+
import { makeASTImports, getProperties, stringify, getExtendName, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME, DEFAULT_FUNCTIONS } from "./utils.mjs";
|
|
3
3
|
const initialImportedFunctions = [
|
|
4
4
|
"extendCollection",
|
|
5
5
|
"defineCollection"
|
|
@@ -7,7 +7,7 @@ const initialImportedFunctions = [
|
|
|
7
7
|
export const generateJSCollections = (ast) => {
|
|
8
8
|
let javascriptCode = "";
|
|
9
9
|
const importsResult = makeASTImports(ast, {
|
|
10
|
-
[
|
|
10
|
+
[PACKAGE_NAME]: new Set(initialImportedFunctions)
|
|
11
11
|
});
|
|
12
12
|
javascriptCode += importsResult.code + "\n\n";
|
|
13
13
|
javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + "\n\n";
|
|
@@ -78,5 +78,5 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
78
78
|
return stringify(collectionSchema);
|
|
79
79
|
};
|
|
80
80
|
const makeJSFunctions = (functions) => {
|
|
81
|
-
return Object.entries(functions).map(([key, _value]) =>
|
|
81
|
+
return Object.entries(functions).map(([key, _value]) => DEFAULT_FUNCTIONS.includes(key) ? key : `${key}: () => { throw new Error('Function not implemented') }`).join(", ");
|
|
82
82
|
};
|
|
@@ -10,7 +10,7 @@ const initialImportedTypes = [
|
|
|
10
10
|
];
|
|
11
11
|
const generateTSCollections = (ast) => {
|
|
12
12
|
let code = '';
|
|
13
|
-
code += `import type { ${initialImportedTypes.join(', ')} } from '${utils_js_1.
|
|
13
|
+
code += `import type { ${initialImportedTypes.join(', ')} } from '${utils_js_1.PACKAGE_NAME}'\n`; //Used types
|
|
14
14
|
const importsResult = (0, utils_js_1.makeASTImports)(ast);
|
|
15
15
|
code += importsResult.code + '\n\n';
|
|
16
16
|
code += makeTSCollections(ast, importsResult.modifiedSymbols) + '\n';
|
|
@@ -98,7 +98,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
98
98
|
const makeTSFunctions = (functions) => {
|
|
99
99
|
return Object.keys(functions).reduce((acc, key) => {
|
|
100
100
|
acc[key] = {
|
|
101
|
-
[utils_js_1.UnquotedSymbol]: utils_js_1.
|
|
101
|
+
[utils_js_1.UnquotedSymbol]: utils_js_1.DEFAULT_FUNCTIONS.includes(key)
|
|
102
102
|
? `typeof ${key}`
|
|
103
103
|
: '() => never',
|
|
104
104
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { getProperties, stringify, makeASTImports, resizeFirstChar,
|
|
2
|
+
import { getProperties, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME, DEFAULT_FUNCTIONS } from "./utils.mjs";
|
|
3
3
|
const initialImportedTypes = [
|
|
4
4
|
"Collection",
|
|
5
5
|
"SchemaWithId",
|
|
@@ -8,7 +8,7 @@ const initialImportedTypes = [
|
|
|
8
8
|
];
|
|
9
9
|
export const generateTSCollections = (ast) => {
|
|
10
10
|
let code = "";
|
|
11
|
-
code += `import type { ${initialImportedTypes.join(", ")} } from '${
|
|
11
|
+
code += `import type { ${initialImportedTypes.join(", ")} } from '${PACKAGE_NAME}'
|
|
12
12
|
`;
|
|
13
13
|
const importsResult = makeASTImports(ast);
|
|
14
14
|
code += importsResult.code + "\n\n";
|
|
@@ -92,7 +92,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
92
92
|
const makeTSFunctions = (functions) => {
|
|
93
93
|
return Object.keys(functions).reduce((acc, key) => {
|
|
94
94
|
acc[key] = {
|
|
95
|
-
[UnquotedSymbol]:
|
|
95
|
+
[UnquotedSymbol]: DEFAULT_FUNCTIONS.includes(key) ? `typeof ${key}` : "() => never"
|
|
96
96
|
};
|
|
97
97
|
return acc;
|
|
98
98
|
}, {});
|
package/dist/codegen/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type * as AST from '../ast';
|
|
1
|
+
import type * as AST from '../ast.js';
|
|
2
2
|
import type { Property } from '@aeriajs/types';
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const PACKAGE_NAME = "aeria";
|
|
4
|
+
export declare const DEFAULT_FUNCTIONS: string[];
|
|
5
5
|
export declare const ArraySymbol: unique symbol;
|
|
6
6
|
export declare const getExposedFunctions: (astFunctions: NonNullable<AST.CollectionNode["functions"]>) => {
|
|
7
7
|
[k: string]: import("@aeriajs/types").AccessCondition;
|
package/dist/codegen/utils.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.UnquotedSymbol = exports.getProperties = exports.propertyToSchema = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.
|
|
4
|
-
|
|
5
|
-
exports.
|
|
6
|
-
|
|
3
|
+
exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.UnquotedSymbol = exports.getProperties = exports.propertyToSchema = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.DEFAULT_FUNCTIONS = exports.PACKAGE_NAME = void 0;
|
|
4
|
+
exports.PACKAGE_NAME = 'aeria';
|
|
5
|
+
exports.DEFAULT_FUNCTIONS = [
|
|
6
|
+
'count',
|
|
7
|
+
'get',
|
|
8
|
+
'getAll',
|
|
9
|
+
'insert',
|
|
10
|
+
'upload',
|
|
11
|
+
'remove',
|
|
12
|
+
'removeAll',
|
|
13
|
+
'removeFile',
|
|
14
|
+
];
|
|
7
15
|
exports.ArraySymbol = Symbol('array');
|
|
8
16
|
const getExposedFunctions = (astFunctions) => {
|
|
9
17
|
return Object.fromEntries(Object.entries(astFunctions)
|
|
@@ -29,13 +37,13 @@ const makeASTImports = (ast, initialImports) => {
|
|
|
29
37
|
imports[node.extends.packageName].add(`${node.extends.symbolName} as ${modifiedSymbol}`);
|
|
30
38
|
}
|
|
31
39
|
if (node.functions) {
|
|
32
|
-
const functionsToImport = Object.keys(node.functions).filter((key) => exports.
|
|
40
|
+
const functionsToImport = Object.keys(node.functions).filter((key) => exports.DEFAULT_FUNCTIONS.includes(key));
|
|
33
41
|
if (functionsToImport.length > 0) {
|
|
34
|
-
if (!(exports.
|
|
35
|
-
imports[exports.
|
|
42
|
+
if (!(exports.PACKAGE_NAME in imports)) {
|
|
43
|
+
imports[exports.PACKAGE_NAME] = new Set();
|
|
36
44
|
}
|
|
37
45
|
for (const key of functionsToImport) {
|
|
38
|
-
imports[exports.
|
|
46
|
+
imports[exports.PACKAGE_NAME].add(key);
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
}
|
package/dist/codegen/utils.mjs
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
|
|
2
|
+
export const PACKAGE_NAME = "aeria";
|
|
3
|
+
export const DEFAULT_FUNCTIONS = [
|
|
4
|
+
"count",
|
|
5
|
+
"get",
|
|
6
|
+
"getAll",
|
|
7
|
+
"insert",
|
|
8
|
+
"upload",
|
|
9
|
+
"remove",
|
|
10
|
+
"removeAll",
|
|
11
|
+
"removeFile"
|
|
12
|
+
];
|
|
5
13
|
export const ArraySymbol = Symbol("array");
|
|
6
14
|
export const getExposedFunctions = (astFunctions) => {
|
|
7
15
|
return Object.fromEntries(Object.entries(astFunctions).map(([key, value]) => [
|
|
@@ -22,13 +30,13 @@ export const makeASTImports = (ast, initialImports) => {
|
|
|
22
30
|
imports[node.extends.packageName].add(`${node.extends.symbolName} as ${modifiedSymbol}`);
|
|
23
31
|
}
|
|
24
32
|
if (node.functions) {
|
|
25
|
-
const functionsToImport = Object.keys(node.functions).filter((key) =>
|
|
33
|
+
const functionsToImport = Object.keys(node.functions).filter((key) => DEFAULT_FUNCTIONS.includes(key));
|
|
26
34
|
if (functionsToImport.length > 0) {
|
|
27
|
-
if (!(
|
|
28
|
-
imports[
|
|
35
|
+
if (!(PACKAGE_NAME in imports)) {
|
|
36
|
+
imports[PACKAGE_NAME] = /* @__PURE__ */ new Set();
|
|
29
37
|
}
|
|
30
38
|
for (const key of functionsToImport) {
|
|
31
|
-
imports[
|
|
39
|
+
imports[PACKAGE_NAME].add(key);
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
}
|
package/dist/compile.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as AST from './ast.js';
|
|
|
2
2
|
import { Diagnostic } from './diagnostic.js';
|
|
3
3
|
export type CompilationResult = {
|
|
4
4
|
success: boolean;
|
|
5
|
-
ast
|
|
5
|
+
ast?: AST.ProgramNode;
|
|
6
6
|
errors: Diagnostic[];
|
|
7
7
|
errorCount: number;
|
|
8
8
|
};
|
|
@@ -12,10 +12,10 @@ export type CompilationOptions = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const parseAndCheck: (sources: Record<string, string>) => Promise<CompilationResult>;
|
|
14
14
|
export declare const generateScaffolding: (options: CompilationOptions) => Promise<string[]>;
|
|
15
|
-
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<{
|
|
15
|
+
export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<CompilationResult | {
|
|
16
16
|
emittedFiles: Record<string, string>;
|
|
17
17
|
success: boolean;
|
|
18
|
-
ast
|
|
18
|
+
ast?: AST.ProgramNode;
|
|
19
19
|
errors: Diagnostic[];
|
|
20
20
|
errorCount: number;
|
|
21
21
|
}>;
|
package/dist/compile.js
CHANGED
|
@@ -40,7 +40,7 @@ const parser_js_1 = require("./parser.js");
|
|
|
40
40
|
const semantic_js_1 = require("./semantic.js");
|
|
41
41
|
const codegen_js_1 = require("./codegen.js");
|
|
42
42
|
const path = __importStar(require("node:path"));
|
|
43
|
-
const
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
44
|
const parseAndCheck = async (sources) => {
|
|
45
45
|
const errors = [];
|
|
46
46
|
let errorCount = 0;
|
|
@@ -65,14 +65,14 @@ const parseAndCheck = async (sources) => {
|
|
|
65
65
|
success: errorCount === 0,
|
|
66
66
|
errors,
|
|
67
67
|
errorCount,
|
|
68
|
-
ast
|
|
68
|
+
ast,
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
exports.parseAndCheck = parseAndCheck;
|
|
72
72
|
const generateScaffolding = async (options) => {
|
|
73
73
|
const directories = [path.join(options.outDir, 'collections')];
|
|
74
74
|
for (const dir of directories) {
|
|
75
|
-
await
|
|
75
|
+
await fs.promises.mkdir(dir, {
|
|
76
76
|
recursive: true,
|
|
77
77
|
});
|
|
78
78
|
}
|
|
@@ -80,16 +80,20 @@ const generateScaffolding = async (options) => {
|
|
|
80
80
|
};
|
|
81
81
|
exports.generateScaffolding = generateScaffolding;
|
|
82
82
|
const compileFromFiles = async (schemaDir, options) => {
|
|
83
|
-
const fileList = await
|
|
83
|
+
const fileList = await fs.promises.readdir(schemaDir);
|
|
84
84
|
const sources = {};
|
|
85
85
|
for (const file of fileList) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
sources[file] = await fs.promises.readFile(`${schemaDir}/${file}`, {
|
|
87
|
+
encoding: 'utf-8',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const result = await (0, exports.parseAndCheck)(sources);
|
|
91
|
+
if (!result.ast) {
|
|
92
|
+
return result;
|
|
88
93
|
}
|
|
89
|
-
const
|
|
90
|
-
const emittedFiles = await (0, codegen_js_1.generateCode)(parsed.ast, options);
|
|
94
|
+
const emittedFiles = await (0, codegen_js_1.generateCode)(result.ast, options);
|
|
91
95
|
return {
|
|
92
|
-
...
|
|
96
|
+
...result,
|
|
93
97
|
emittedFiles,
|
|
94
98
|
};
|
|
95
99
|
};
|
package/dist/compile.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { parse } from "./parser.mjs";
|
|
|
5
5
|
import { analyze } from "./semantic.mjs";
|
|
6
6
|
import { generateCode } from "./codegen.mjs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
|
-
import * as
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
9
|
export const parseAndCheck = async (sources) => {
|
|
10
10
|
const errors = [];
|
|
11
11
|
let errorCount = 0;
|
|
@@ -35,23 +35,27 @@ export const parseAndCheck = async (sources) => {
|
|
|
35
35
|
export const generateScaffolding = async (options) => {
|
|
36
36
|
const directories = [path.join(options.outDir, "collections")];
|
|
37
37
|
for (const dir of directories) {
|
|
38
|
-
await
|
|
38
|
+
await fs.promises.mkdir(dir, {
|
|
39
39
|
recursive: true
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
return directories;
|
|
43
43
|
};
|
|
44
44
|
export const compileFromFiles = async (schemaDir, options) => {
|
|
45
|
-
const fileList = await
|
|
45
|
+
const fileList = await fs.promises.readdir(schemaDir);
|
|
46
46
|
const sources = {};
|
|
47
47
|
for (const file of fileList) {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
sources[file] = await fs.promises.readFile(`${schemaDir}/${file}`, {
|
|
49
|
+
encoding: "utf-8"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const result = await parseAndCheck(sources);
|
|
53
|
+
if (!result.ast) {
|
|
54
|
+
return result;
|
|
50
55
|
}
|
|
51
|
-
const
|
|
52
|
-
const emittedFiles = await generateCode(parsed.ast, options);
|
|
56
|
+
const emittedFiles = await generateCode(result.ast, options);
|
|
53
57
|
return {
|
|
54
|
-
...
|
|
58
|
+
...result,
|
|
55
59
|
emittedFiles
|
|
56
60
|
};
|
|
57
61
|
};
|