@aeriajs/compiler 0.0.59 → 0.0.61

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.
@@ -43,7 +43,7 @@ const makeJSContractsCode = (ast) => {
43
43
  responseString = (0, utils_js_1.stringify)(responseArray);
44
44
  }
45
45
  else {
46
- responseString = (0, utils_js_1.stringify)(getCodeForResponse(response));
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 \'aeria\'\n\n` + declarations;
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 = stringify(getCodeForResponse(response));
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
- export declare const generateExports: (ast: AST.ProgramNode, options?: {
3
- hasContracts: boolean;
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
- main: {
23
- js: (options.hasContracts
24
- ? 'export * as contracts from \'./contracts/index.js\'\n'
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: 'export * from \'./contracts.js\'',
38
- dts: 'export * from \'./contracts.js\'',
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
- main: {
21
- js: (options.hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
22
- export { ${symbolsToExport.map((symbol) => symbol.extend).join(", ")} } from './collections/collections.mjs'`,
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]: 'import(\'@aeriajs/types\').CollectionMiddleware<unknown>[]',
70
+ [utils_js_1.UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]",
71
71
  };
72
72
  break;
73
73
  case 'functions':
@@ -134,20 +134,30 @@ const stringify = (value, parents = []) => {
134
134
  });
135
135
  return arrayString + `${'\t'.repeat(parents.length)}]`;
136
136
  }
137
- if (!isRecord(value)) {
138
- return typeof value === 'number' || typeof value === 'boolean' || !value
139
- ? String(value)
140
- : `"${String(value)}"`;
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) => {
@@ -118,20 +118,32 @@ export const stringify = (value, parents = []) => {
118
118
  });
119
119
  return arrayString + `${" ".repeat(parents.length)}]`;
120
120
  }
121
- if (!isRecord(value)) {
122
- return typeof value === "number" || typeof value === "boolean" || !value ? String(value) : `"${String(value)}"`;
123
- }
124
- const objectString = Object.keys(value).map((key) => {
125
- const currentParents = [
126
- ...parents,
127
- key
128
- ];
129
- const prefix = " ".repeat(currentParents.length);
130
- return `${prefix}${key}: ${checkQuotes(currentParents, value[key])}`;
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.main.dts,
72
- ['index.js']: exports.main.js,
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.main.dts,
37
- ["index.mjs"]: exports.main.js
36
+ ["index.d.ts"]: exports.index.dts,
37
+ ["index.mjs"]: exports.index.js
38
38
  };
39
39
  if (contracts) {
40
40
  fileTree.contracts = {
package/dist/parser.js CHANGED
@@ -144,9 +144,16 @@ const parse = (tokens) => {
144
144
  }
145
145
  };
146
146
  const parseArray = (types) => {
147
- const { location: openingLocation } = consume(token_js_1.TokenType.LeftSquareBracket);
148
147
  const array = [];
149
148
  const symbols = [];
149
+ const { location: openingLocation } = consume(token_js_1.TokenType.LeftSquareBracket);
150
+ if (match(token_js_1.TokenType.RightSquareBracket)) {
151
+ consume(token_js_1.TokenType.RightSquareBracket);
152
+ return {
153
+ value: [],
154
+ symbols: [],
155
+ };
156
+ }
150
157
  let type;
151
158
  for (const typeCandidate of types) {
152
159
  if (match(typeCandidate)) {
@@ -681,7 +688,9 @@ const parse = (tokens) => {
681
688
  };
682
689
  if (match(token_js_1.TokenType.Keyword, 'extends')) {
683
690
  consume(token_js_1.TokenType.Keyword);
684
- const { value: packageName } = consume(token_js_1.TokenType.Identifier);
691
+ const { value: packageName } = match(token_js_1.TokenType.QuotedString)
692
+ ? consume(token_js_1.TokenType.QuotedString)
693
+ : consume(token_js_1.TokenType.Identifier);
685
694
  consume(token_js_1.TokenType.Dot);
686
695
  const { value: symbolName } = consume(token_js_1.TokenType.Identifier);
687
696
  node.extends = {
@@ -856,7 +865,9 @@ const parse = (tokens) => {
856
865
  }
857
866
  let functionNode;
858
867
  if (current().type === token_js_1.TokenType.Identifier && next().type === token_js_1.TokenType.Dot) {
859
- const { value: packageName } = consume(token_js_1.TokenType.Identifier);
868
+ const { value: packageName } = match(token_js_1.TokenType.QuotedString)
869
+ ? consume(token_js_1.TokenType.QuotedString)
870
+ : consume(token_js_1.TokenType.Identifier);
860
871
  consume(token_js_1.TokenType.Dot);
861
872
  const { value: symbolName } = consume(token_js_1.TokenType.Identifier);
862
873
  functionNode = {
package/dist/parser.mjs CHANGED
@@ -106,9 +106,16 @@ export const parse = (tokens) => {
106
106
  }
107
107
  };
108
108
  const parseArray = (types) => {
109
- const { location: openingLocation } = consume(TokenType.LeftSquareBracket);
110
109
  const array = [];
111
110
  const symbols = [];
111
+ const { location: openingLocation } = consume(TokenType.LeftSquareBracket);
112
+ if (match(TokenType.RightSquareBracket)) {
113
+ consume(TokenType.RightSquareBracket);
114
+ return {
115
+ value: [],
116
+ symbols: []
117
+ };
118
+ }
112
119
  let type;
113
120
  for (const typeCandidate of types) {
114
121
  if (match(typeCandidate)) {
@@ -628,7 +635,7 @@ export const parse = (tokens) => {
628
635
  };
629
636
  if (match(TokenType.Keyword, "extends")) {
630
637
  consume(TokenType.Keyword);
631
- const { value: packageName } = consume(TokenType.Identifier);
638
+ const { value: packageName } = match(TokenType.QuotedString) ? consume(TokenType.QuotedString) : consume(TokenType.Identifier);
632
639
  consume(TokenType.Dot);
633
640
  const { value: symbolName } = consume(TokenType.Identifier);
634
641
  node.extends = {
@@ -801,7 +808,7 @@ export const parse = (tokens) => {
801
808
  }
802
809
  let functionNode;
803
810
  if (current().type === TokenType.Identifier && next().type === TokenType.Dot) {
804
- const { value: packageName } = consume(TokenType.Identifier);
811
+ const { value: packageName } = match(TokenType.QuotedString) ? consume(TokenType.QuotedString) : consume(TokenType.Identifier);
805
812
  consume(TokenType.Dot);
806
813
  const { value: symbolName } = consume(TokenType.Identifier);
807
814
  functionNode = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
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.156",
25
- "@aeriajs/types": "^0.0.134"
24
+ "@aeriajs/common": "^0.0.157",
25
+ "@aeriajs/types": "^0.0.135"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@aeriajs/common": "link:../common",