@aeriajs/compiler 0.0.59 → 0.0.60
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/generateContracts.js +2 -2
- package/dist/codegen/generateContracts.mjs +1 -1
- package/dist/codegen/generateExports.d.ts +6 -4
- package/dist/codegen/generateExports.js +13 -13
- package/dist/codegen/generateExports.mjs +13 -5
- package/dist/codegen/generateTSCollections.js +1 -1
- package/dist/codegen/utils.js +23 -13
- package/dist/codegen/utils.mjs +24 -12
- package/dist/codegen.js +2 -2
- package/dist/codegen.mjs +2 -2
- package/package.json +3 -3
|
@@ -43,7 +43,7 @@ const makeJSContractsCode = (ast) => {
|
|
|
43
43
|
responseString = (0, utils_js_1.stringify)(responseArray);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
responseString =
|
|
46
|
+
responseString = getCodeForResponse(response);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
const contractSchema = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(contractProperty);
|
|
@@ -57,7 +57,7 @@ const makeJSContractsCode = (ast) => {
|
|
|
57
57
|
}
|
|
58
58
|
return `export const ${name} = defineContract(${(0, utils_js_1.stringify)(contractSchema)})`;
|
|
59
59
|
}).join('\n\n');
|
|
60
|
-
return `import { ${Array.from(imports).join(', ')} } from
|
|
60
|
+
return `import { ${Array.from(imports).join(', ')} } from 'aeria'\n\n` + declarations;
|
|
61
61
|
};
|
|
62
62
|
const getResponseSchema = (response) => {
|
|
63
63
|
const responseSchema = (0, utils_js_1.unwrapPropertyNode)(response);
|
|
@@ -37,7 +37,7 @@ const makeJSContractsCode = (ast) => {
|
|
|
37
37
|
}
|
|
38
38
|
responseString = stringify(responseArray);
|
|
39
39
|
} else {
|
|
40
|
-
responseString =
|
|
40
|
+
responseString = getCodeForResponse(response);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
const contractSchema = recursivelyUnwrapPropertyNodes(contractProperty);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type * as AST from '../ast.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}) => {
|
|
5
|
-
main: {
|
|
2
|
+
type Exports = {
|
|
3
|
+
index: {
|
|
6
4
|
js: string;
|
|
7
5
|
dts: string;
|
|
8
6
|
};
|
|
@@ -15,3 +13,7 @@ export declare const generateExports: (ast: AST.ProgramNode, options?: {
|
|
|
15
13
|
dts: string;
|
|
16
14
|
};
|
|
17
15
|
};
|
|
16
|
+
export declare const generateExports: (ast: AST.ProgramNode, options?: {
|
|
17
|
+
hasContracts: boolean;
|
|
18
|
+
}) => Exports;
|
|
19
|
+
export {};
|
|
@@ -14,28 +14,28 @@ const generateExports = (ast, options = {
|
|
|
14
14
|
};
|
|
15
15
|
return symbols;
|
|
16
16
|
}, {}));
|
|
17
|
+
let indexJs = "export * as collections from './collections/index.js'\n" +
|
|
18
|
+
`export { ${symbolsToExport.map((symbol) => symbol.extend).join(', ')} } from './collections/collections.js'\n`;
|
|
19
|
+
let indexDts = "export * as collections from './collections/index.js'\n" +
|
|
20
|
+
`export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(', ')} } from './collections/collections.js'\n`;
|
|
21
|
+
if (options.hasContracts) {
|
|
22
|
+
indexJs += "export * as contracts from './contracts/index.js'\n";
|
|
23
|
+
indexDts += "export * as contracts from './contracts/index.js'\n";
|
|
24
|
+
}
|
|
17
25
|
const exports = {
|
|
18
26
|
collections: {
|
|
19
27
|
js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
|
|
20
28
|
dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
|
|
21
29
|
},
|
|
22
|
-
|
|
23
|
-
js:
|
|
24
|
-
|
|
25
|
-
: '') +
|
|
26
|
-
'export * as collections from \'./collections/index.js\'\n' +
|
|
27
|
-
`export { ${symbolsToExport.map((symbol) => symbol.extend).join(', ')} } from './collections/collections.js'`,
|
|
28
|
-
dts: (options.hasContracts
|
|
29
|
-
? 'export * as contracts from \'./contracts/index.js\'\n'
|
|
30
|
-
: '') +
|
|
31
|
-
'export * as collections from \'./collections/index.js\'\n' +
|
|
32
|
-
`export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(', ')} } from './collections/collections.js'`,
|
|
30
|
+
index: {
|
|
31
|
+
js: indexJs,
|
|
32
|
+
dts: indexDts,
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
35
|
if (options.hasContracts) {
|
|
36
36
|
exports.contracts = {
|
|
37
|
-
js:
|
|
38
|
-
dts:
|
|
37
|
+
js: "export * from './contracts.js'",
|
|
38
|
+
dts: "export * from './contracts.js'",
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
return exports;
|
|
@@ -12,16 +12,24 @@ export const generateExports = (ast, options = {
|
|
|
12
12
|
};
|
|
13
13
|
return symbols;
|
|
14
14
|
}, {}));
|
|
15
|
+
let indexJs = `export * as collections from './collections/index.mjs'
|
|
16
|
+
export { ${symbolsToExport.map((symbol) => symbol.extend).join(", ")} } from './collections/collections.mjs'
|
|
17
|
+
`;
|
|
18
|
+
let indexDts = `export * as collections from './collections/index.mjs'
|
|
19
|
+
export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(", ")} } from './collections/collections.mjs'
|
|
20
|
+
`;
|
|
21
|
+
if (options.hasContracts) {
|
|
22
|
+
indexJs += "export * as contracts from './contracts/index.mjs'\n";
|
|
23
|
+
indexDts += "export * as contracts from './contracts/index.mjs'\n";
|
|
24
|
+
}
|
|
15
25
|
const exports = {
|
|
16
26
|
collections: {
|
|
17
27
|
js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`,
|
|
18
28
|
dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`
|
|
19
29
|
},
|
|
20
|
-
|
|
21
|
-
js:
|
|
22
|
-
|
|
23
|
-
dts: (options.hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
|
|
24
|
-
export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(", ")} } from './collections/collections.mjs'`
|
|
30
|
+
index: {
|
|
31
|
+
js: indexJs,
|
|
32
|
+
dts: indexDts
|
|
25
33
|
}
|
|
26
34
|
};
|
|
27
35
|
if (options.hasContracts) {
|
|
@@ -67,7 +67,7 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
|
|
|
67
67
|
break;
|
|
68
68
|
case 'middlewares':
|
|
69
69
|
collectionSchema.middlewares = {
|
|
70
|
-
[utils_js_1.UnquotedSymbol]:
|
|
70
|
+
[utils_js_1.UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]",
|
|
71
71
|
};
|
|
72
72
|
break;
|
|
73
73
|
case 'functions':
|
package/dist/codegen/utils.js
CHANGED
|
@@ -134,20 +134,30 @@ const stringify = (value, parents = []) => {
|
|
|
134
134
|
});
|
|
135
135
|
return arrayString + `${'\t'.repeat(parents.length)}]`;
|
|
136
136
|
}
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
if (isRecord(value)) {
|
|
138
|
+
const objectString = Object.keys(value).map((key) => {
|
|
139
|
+
const currentParents = [
|
|
140
|
+
...parents,
|
|
141
|
+
key,
|
|
142
|
+
];
|
|
143
|
+
const indentation = '\t'.repeat(currentParents.length);
|
|
144
|
+
return `${indentation}${key}: ${checkQuotes(currentParents, value[key])}`;
|
|
145
|
+
}).join(',\n');
|
|
146
|
+
return `{\n${objectString}\n${'\t'.repeat(parents.length)}}`;
|
|
147
|
+
}
|
|
148
|
+
switch (typeof value) {
|
|
149
|
+
case 'undefined':
|
|
150
|
+
case 'number':
|
|
151
|
+
case 'boolean': {
|
|
152
|
+
return String(value);
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
if (value === null) {
|
|
156
|
+
return String(value);
|
|
157
|
+
}
|
|
158
|
+
return `"${String(value)}"`;
|
|
159
|
+
}
|
|
141
160
|
}
|
|
142
|
-
const objectString = Object.keys(value).map((key) => {
|
|
143
|
-
const currentParents = [
|
|
144
|
-
...parents,
|
|
145
|
-
key,
|
|
146
|
-
];
|
|
147
|
-
const prefix = '\t'.repeat(currentParents.length);
|
|
148
|
-
return `${prefix}${key}: ${checkQuotes(currentParents, value[key])}`;
|
|
149
|
-
}).join(',\n');
|
|
150
|
-
return `{\n${objectString}\n${'\t'.repeat(parents.length)}}`;
|
|
151
161
|
};
|
|
152
162
|
exports.stringify = stringify;
|
|
153
163
|
const checkQuotes = (parents, value) => {
|
package/dist/codegen/utils.mjs
CHANGED
|
@@ -118,20 +118,32 @@ export const stringify = (value, parents = []) => {
|
|
|
118
118
|
});
|
|
119
119
|
return arrayString + `${" ".repeat(parents.length)}]`;
|
|
120
120
|
}
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
}).join(",\n");
|
|
132
|
-
return `{
|
|
121
|
+
if (isRecord(value)) {
|
|
122
|
+
const objectString = Object.keys(value).map((key) => {
|
|
123
|
+
const currentParents = [
|
|
124
|
+
...parents,
|
|
125
|
+
key
|
|
126
|
+
];
|
|
127
|
+
const indentation = " ".repeat(currentParents.length);
|
|
128
|
+
return `${indentation}${key}: ${checkQuotes(currentParents, value[key])}`;
|
|
129
|
+
}).join(",\n");
|
|
130
|
+
return `{
|
|
133
131
|
${objectString}
|
|
134
132
|
${" ".repeat(parents.length)}}`;
|
|
133
|
+
}
|
|
134
|
+
switch (typeof value) {
|
|
135
|
+
case "undefined":
|
|
136
|
+
case "number":
|
|
137
|
+
case "boolean": {
|
|
138
|
+
return String(value);
|
|
139
|
+
}
|
|
140
|
+
default: {
|
|
141
|
+
if (value === null) {
|
|
142
|
+
return String(value);
|
|
143
|
+
}
|
|
144
|
+
return `"${String(value)}"`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
135
147
|
};
|
|
136
148
|
const checkQuotes = (parents, value) => {
|
|
137
149
|
if (value && typeof value === "object" && UnquotedSymbol in value) {
|
package/dist/codegen.js
CHANGED
|
@@ -68,8 +68,8 @@ const generateCode = async (ast, options) => {
|
|
|
68
68
|
['index.d.ts']: exports.collections.dts,
|
|
69
69
|
['index.js']: exports.collections.js,
|
|
70
70
|
},
|
|
71
|
-
['index.d.ts']: exports.
|
|
72
|
-
['index.js']: exports.
|
|
71
|
+
['index.d.ts']: exports.index.dts,
|
|
72
|
+
['index.js']: exports.index.js,
|
|
73
73
|
};
|
|
74
74
|
if (contracts) {
|
|
75
75
|
fileTree.contracts = {
|
package/dist/codegen.mjs
CHANGED
|
@@ -33,8 +33,8 @@ export const generateCode = async (ast, options) => {
|
|
|
33
33
|
["index.d.ts"]: exports.collections.dts,
|
|
34
34
|
["index.mjs"]: exports.collections.js
|
|
35
35
|
},
|
|
36
|
-
["index.d.ts"]: exports.
|
|
37
|
-
["index.mjs"]: exports.
|
|
36
|
+
["index.d.ts"]: exports.index.dts,
|
|
37
|
+
["index.mjs"]: exports.index.js
|
|
38
38
|
};
|
|
39
39
|
if (contracts) {
|
|
40
40
|
fileTree.contracts = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@aeriajs/common": "^0.0.
|
|
25
|
-
"@aeriajs/types": "^0.0.
|
|
24
|
+
"@aeriajs/common": "^0.0.157",
|
|
25
|
+
"@aeriajs/types": "^0.0.135"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@aeriajs/common": "link:../common",
|