@aeriajs/compiler 0.0.15 → 0.0.16

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 CHANGED
@@ -23,6 +23,7 @@ export type PropertyNode = NodeBase<'property'> & {
23
23
  modifier?: keyof typeof PropertyModifiers;
24
24
  property: Property & {
25
25
  [LOCATION_SYMBOL]?: {
26
+ type: symbol;
26
27
  attributes: Record<string, symbol>;
27
28
  arrays: {
28
29
  [P in ArrayProperties<Extract<Property, {
@@ -1,5 +1,5 @@
1
1
  import type * as AST from '../ast.js';
2
2
  export declare const generateContracts: (ast: AST.Node[]) => false | {
3
3
  js: string;
4
- dTs: string;
4
+ dts: string;
5
5
  };
@@ -10,7 +10,7 @@ const generateContracts = (ast) => {
10
10
  }
11
11
  return {
12
12
  js: makeJSContractsCode(contractNodes),
13
- dTs: makeTSContractsCode(contractNodes),
13
+ dts: makeTSContractsCode(contractNodes),
14
14
  };
15
15
  };
16
16
  exports.generateContracts = generateContracts;
@@ -8,7 +8,7 @@ export const generateContracts = (ast) => {
8
8
  }
9
9
  return {
10
10
  js: makeJSContractsCode(contractNodes),
11
- dTs: makeTSContractsCode(contractNodes)
11
+ dts: makeTSContractsCode(contractNodes)
12
12
  };
13
13
  };
14
14
  const makeJSContractsCode = (contractAst) => {
@@ -2,14 +2,14 @@ import type * as AST from '../ast.js';
2
2
  export declare const generateExports: (ast: AST.ProgramNode, hasContracts?: boolean) => {
3
3
  main: {
4
4
  js: string;
5
- dTs: string;
5
+ dts: string;
6
6
  };
7
7
  collections: {
8
8
  js: string;
9
- dTs: string;
9
+ dts: string;
10
10
  };
11
11
  contracts?: {
12
12
  js: string;
13
- dTs: string;
13
+ dts: string;
14
14
  };
15
15
  };
@@ -15,7 +15,7 @@ const generateExports = (ast, hasContracts = false) => {
15
15
  const exports = {
16
16
  collections: {
17
17
  js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
18
- dTs: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
18
+ dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(', ')} } from './collections.js'`,
19
19
  },
20
20
  main: {
21
21
  js: (hasContracts
@@ -23,7 +23,7 @@ const generateExports = (ast, hasContracts = false) => {
23
23
  : '') +
24
24
  'export * as collections from \'./collections/index.js\'\n' +
25
25
  `export { ${symbolsToExport.map((symbol) => symbol.extend).join(', ')} } from './collections/collections.js'`,
26
- dTs: (hasContracts
26
+ dts: (hasContracts
27
27
  ? 'export * as contracts from \'./contracts/index.js\'\n'
28
28
  : '') +
29
29
  'export * as collections from \'./collections/index.js\'\n' +
@@ -33,7 +33,7 @@ const generateExports = (ast, hasContracts = false) => {
33
33
  if (hasContracts) {
34
34
  exports.contracts = {
35
35
  js: 'export * from \'./contracts.js\'',
36
- dTs: 'export * from \'./contracts.js\'',
36
+ dts: 'export * from \'./contracts.js\'',
37
37
  };
38
38
  }
39
39
  return exports;
@@ -13,19 +13,19 @@ export const generateExports = (ast, hasContracts = false) => {
13
13
  const exports = {
14
14
  collections: {
15
15
  js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`,
16
- dTs: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`
16
+ dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`
17
17
  },
18
18
  main: {
19
19
  js: (hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
20
20
  export { ${symbolsToExport.map((symbol) => symbol.extend).join(", ")} } from './collections/collections.mjs'`,
21
- dTs: (hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
21
+ dts: (hasContracts ? "export * as contracts from './contracts/index.mjs'\n" : "") + `export * as collections from './collections/index.mjs'
22
22
  export { ${symbolsToExport.map((symbol) => `${symbol.extend}, ${symbol.schema}`).join(", ")} } from './collections/collections.mjs'`
23
23
  }
24
24
  };
25
25
  if (hasContracts) {
26
26
  exports.contracts = {
27
27
  js: "export * from './contracts.mjs'",
28
- dTs: "export * from './contracts.mjs'"
28
+ dts: "export * from './contracts.mjs'"
29
29
  };
30
30
  }
31
31
  return exports;
@@ -47,10 +47,10 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
47
47
  }
48
48
  switch (key) {
49
49
  case 'properties':
50
- collectionSchema.description.properties = (0, utils_js_1.getProperties)(collectionNode[key]);
50
+ collectionSchema.description[key] = (0, utils_js_1.getProperties)(collectionNode[key]);
51
51
  break;
52
52
  case 'owned':
53
- collectionSchema.description.owned = collectionNode[key];
53
+ collectionSchema.description[key] = collectionNode[key];
54
54
  break;
55
55
  case 'functions':
56
56
  collectionSchema.functions = {
@@ -40,10 +40,10 @@ const makeJSCollectionSchema = (collectionNode, collectionId) => {
40
40
  }
41
41
  switch (key) {
42
42
  case "properties":
43
- collectionSchema.description.properties = getProperties(collectionNode[key]);
43
+ collectionSchema.description[key] = getProperties(collectionNode[key]);
44
44
  break;
45
45
  case "owned":
46
- collectionSchema.description.owned = collectionNode[key];
46
+ collectionSchema.description[key] = collectionNode[key];
47
47
  break;
48
48
  case "functions":
49
49
  collectionSchema.functions = {
@@ -15,7 +15,7 @@ export declare const makeASTImports: (ast: AST.Node[], initialImports?: Record<s
15
15
  };
16
16
  export declare const propertyToSchema: ({ property, nestedProperties }: Pick<AST.PropertyNode, "property" | "nestedProperties">) => Property;
17
17
  /** Transforms the AST properties to the format of aeria schema properties */
18
- export declare const getProperties: <TProperties extends Record<string, AST.PropertyNode | AST.PropertyNode[]>, TReturnType = TProperties[keyof TProperties] extends unknown[] ? Record<string, Property[]> : Record<string, Property>>(properties: TProperties) => TReturnType;
18
+ export declare const getProperties: <TProperties extends Record<string, AST.PropertyNode | AST.PropertyNode[]>, TReturnType = TProperties[keyof TProperties] extends Array<unknown> ? Record<string, Property[]> : Record<string, Property>>(properties: TProperties) => TReturnType;
19
19
  export declare const UnquotedSymbol: unique symbol;
20
20
  /** Serves to know if the value must be unquoted on strinfigy function */
21
21
  export type StringifyProperty = unknown | {
package/dist/codegen.js CHANGED
@@ -77,17 +77,17 @@ const generateCode = async (ast, options) => {
77
77
  ['collections']: {
78
78
  ['collections.d.ts']: (0, index_js_1.generateTSCollections)(ast.collections),
79
79
  ['collections.js']: (0, index_js_1.generateJSCollections)(ast.collections),
80
- ['index.d.ts']: exports.collections.dTs,
80
+ ['index.d.ts']: exports.collections.dts,
81
81
  ['index.js']: exports.collections.js,
82
82
  },
83
- ['index.d.ts']: exports.main.dTs,
83
+ ['index.d.ts']: exports.main.dts,
84
84
  ['index.js']: exports.main.js,
85
85
  };
86
86
  if (contracts) {
87
87
  fileTree.contracts = {
88
88
  ['contracts.js']: contracts.js,
89
- ['contracts.d.ts']: contracts.dTs,
90
- ['index.d.ts']: exports.contracts.dTs,
89
+ ['contracts.d.ts']: contracts.dts,
90
+ ['index.d.ts']: exports.contracts.dts,
91
91
  ['index.js']: exports.contracts.js,
92
92
  };
93
93
  }
package/dist/codegen.mjs CHANGED
@@ -28,17 +28,17 @@ export const generateCode = async (ast, options) => {
28
28
  ["collections"]: {
29
29
  ["collections.d.ts"]: generateTSCollections(ast.collections),
30
30
  ["collections.mjs"]: generateJSCollections(ast.collections),
31
- ["index.d.ts"]: exports.collections.dTs,
31
+ ["index.d.ts"]: exports.collections.dts,
32
32
  ["index.mjs"]: exports.collections.js
33
33
  },
34
- ["index.d.ts"]: exports.main.dTs,
34
+ ["index.d.ts"]: exports.main.dts,
35
35
  ["index.mjs"]: exports.main.js
36
36
  };
37
37
  if (contracts) {
38
38
  fileTree.contracts = {
39
39
  ["contracts.mjs"]: contracts.js,
40
- ["contracts.d.ts"]: contracts.dTs,
41
- ["index.d.ts"]: exports.contracts.dTs,
40
+ ["contracts.d.ts"]: contracts.dts,
41
+ ["index.d.ts"]: exports.contracts.dts,
42
42
  ["index.mjs"]: exports.contracts.js
43
43
  };
44
44
  }
package/dist/compile.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Diagnostic } from './diagnostic.js';
3
3
  export declare const FILE_PRECEDENCE: string[];
4
4
  export declare const parseAndCheck: (sources: Record<string, string>, options?: Pick<CompilationOptions, "languageServer">) => Promise<CompilationResult>;
5
5
  export declare const generateScaffolding: (options: CompilationOptions) => Promise<string[]>;
6
- export declare const compileFromFiles: (schemaDir: string, options: CompilationOptions) => Promise<CompilationResult | {
6
+ export declare const compileFromFiles: (globPattern: string, options: CompilationOptions) => Promise<CompilationResult | {
7
7
  emittedFiles: Record<string, string>;
8
8
  success: boolean;
9
9
  ast?: import("./ast.js").ProgramNode;
package/dist/compile.js CHANGED
@@ -44,28 +44,23 @@ const fs = __importStar(require("node:fs"));
44
44
  exports.FILE_PRECEDENCE = ['contract'];
45
45
  const parseAndCheck = async (sources, options = {}) => {
46
46
  const errors = [];
47
- let errorCount = 0;
48
47
  let ast;
48
+ const allTokens = [];
49
49
  for (const fileName in sources) {
50
50
  diagnostic_js_1.Diagnostic.currentFile = fileName;
51
51
  const { errors: lexerErrors, tokens } = (0, lexer_js_1.tokenize)(sources[fileName]);
52
- const { errors: parserErrors, ast: currentAst } = (0, parser_js_1.parse)(Array.from(tokens));
53
- const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(currentAst, options);
54
- errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
55
- errorCount += errors.length;
56
- if (!ast) {
57
- ast = currentAst;
58
- }
59
- else {
60
- ast.collections.push(...currentAst.collections);
61
- ast.contracts.push(...currentAst.contracts);
62
- ast.functionsets.push(...currentAst.functionsets);
52
+ if (lexerErrors.length > 0) {
53
+ errors.push(...lexerErrors);
63
54
  }
55
+ allTokens.push(...tokens);
64
56
  }
57
+ const { errors: parserErrors, ast: currentAst } = (0, parser_js_1.parse)(allTokens);
58
+ const { errors: semanticErrors } = await (0, semantic_js_1.analyze)(currentAst, options);
59
+ errors.push(...parserErrors.concat(semanticErrors));
65
60
  return {
66
- success: errorCount === 0,
61
+ success: errors.length === 0,
67
62
  errors,
68
- errorCount,
63
+ errorCount: errors.length,
69
64
  ast,
70
65
  };
71
66
  };
@@ -80,8 +75,8 @@ const generateScaffolding = async (options) => {
80
75
  return directories;
81
76
  };
82
77
  exports.generateScaffolding = generateScaffolding;
83
- const compileFromFiles = async (schemaDir, options) => {
84
- const fileList = await Array.fromAsync(fs.promises.glob(`${schemaDir}/*.aeria`));
78
+ const compileFromFiles = async (globPattern, options) => {
79
+ const fileList = await Array.fromAsync(fs.promises.glob(globPattern));
85
80
  const sortedFileList = fileList.sort((a, b) => {
86
81
  const aIndex = exports.FILE_PRECEDENCE.findIndex((file) => a.split('/').at(-1).startsWith(file));
87
82
  const bIndex = exports.FILE_PRECEDENCE.findIndex((file) => b.split('/').at(-1).startsWith(file));
package/dist/compile.mjs CHANGED
@@ -9,27 +9,23 @@ import * as fs from "node:fs";
9
9
  export const FILE_PRECEDENCE = ["contract"];
10
10
  export const parseAndCheck = async (sources, options = {}) => {
11
11
  const errors = [];
12
- let errorCount = 0;
13
12
  let ast;
13
+ const allTokens = [];
14
14
  for (const fileName in sources) {
15
15
  Diagnostic.currentFile = fileName;
16
16
  const { errors: lexerErrors, tokens } = tokenize(sources[fileName]);
17
- const { errors: parserErrors, ast: currentAst } = parse(Array.from(tokens));
18
- const { errors: semanticErrors } = await analyze(currentAst, options);
19
- errors.push(...lexerErrors.concat(parserErrors, semanticErrors));
20
- errorCount += errors.length;
21
- if (!ast) {
22
- ast = currentAst;
23
- } else {
24
- ast.collections.push(...currentAst.collections);
25
- ast.contracts.push(...currentAst.contracts);
26
- ast.functionsets.push(...currentAst.functionsets);
17
+ if (lexerErrors.length > 0) {
18
+ errors.push(...lexerErrors);
27
19
  }
20
+ allTokens.push(...tokens);
28
21
  }
22
+ const { errors: parserErrors, ast: currentAst } = parse(allTokens);
23
+ const { errors: semanticErrors } = await analyze(currentAst, options);
24
+ errors.push(...parserErrors.concat(semanticErrors));
29
25
  return {
30
- success: errorCount === 0,
26
+ success: errors.length === 0,
31
27
  errors,
32
- errorCount,
28
+ errorCount: errors.length,
33
29
  ast
34
30
  };
35
31
  };
@@ -42,8 +38,8 @@ export const generateScaffolding = async (options) => {
42
38
  }
43
39
  return directories;
44
40
  };
45
- export const compileFromFiles = async (schemaDir, options) => {
46
- const fileList = await Array.fromAsync(fs.promises.glob(`${schemaDir}/*.aeria`));
41
+ export const compileFromFiles = async (globPattern, options) => {
42
+ const fileList = await Array.fromAsync(fs.promises.glob(globPattern));
47
43
  const sortedFileList = fileList.sort((a, b) => {
48
44
  const aIndex = FILE_PRECEDENCE.findIndex((file) => a.split("/").at(-1).startsWith(file));
49
45
  const bIndex = FILE_PRECEDENCE.findIndex((file) => b.split("/").at(-1).startsWith(file));
package/dist/parser.js CHANGED
@@ -379,6 +379,8 @@ const parse = (tokens) => {
379
379
  let property;
380
380
  let nestedProperties;
381
381
  let modifierToken;
382
+ const typeSymbol = Symbol();
383
+ exports.locationMap.set(typeSymbol, next().location);
382
384
  if (match(token_js_1.TokenType.LeftSquareBracket)) {
383
385
  consume(token_js_1.TokenType.LeftSquareBracket);
384
386
  const arrayProperty = {
@@ -387,6 +389,7 @@ const parse = (tokens) => {
387
389
  while (!match(token_js_1.TokenType.RightSquareBracket)) {
388
390
  const attributeSymbol = Symbol();
389
391
  arrayProperty[AST.LOCATION_SYMBOL] ??= {
392
+ type: typeSymbol,
390
393
  attributes: {},
391
394
  arrays: {},
392
395
  };
@@ -444,6 +447,7 @@ const parse = (tokens) => {
444
447
  type: 'object',
445
448
  properties: {},
446
449
  [AST.LOCATION_SYMBOL]: {
450
+ type: typeSymbol,
447
451
  attributes: {},
448
452
  arrays: {},
449
453
  },
@@ -471,7 +475,7 @@ const parse = (tokens) => {
471
475
  consume(token_js_1.TokenType.RightBracket);
472
476
  }
473
477
  else {
474
- const { value: identifier, location } = consume(token_js_1.TokenType.Identifier);
478
+ const { value: identifier } = consume(token_js_1.TokenType.Identifier);
475
479
  if (guards.isNativePropertyType(identifier)) {
476
480
  switch (identifier) {
477
481
  case 'enum': {
@@ -507,12 +511,13 @@ const parse = (tokens) => {
507
511
  }
508
512
  }
509
513
  else {
510
- const collection = ast.collections.find((node) => node.name === identifier);
511
- if (!collection) {
512
- throw new diagnostic_js_1.Diagnostic(`invalid reference "${identifier}"`, location);
513
- }
514
514
  property = {
515
515
  $ref: identifier,
516
+ [AST.LOCATION_SYMBOL]: {
517
+ type: typeSymbol,
518
+ attributes: {},
519
+ arrays: {},
520
+ },
516
521
  };
517
522
  }
518
523
  }
@@ -523,6 +528,7 @@ const parse = (tokens) => {
523
528
  const attributeSymbol = Symbol();
524
529
  exports.locationMap.set(attributeSymbol, next().location);
525
530
  property[AST.LOCATION_SYMBOL] ??= {
531
+ type: typeSymbol,
526
532
  attributes: {},
527
533
  arrays: {},
528
534
  };
package/dist/parser.mjs CHANGED
@@ -337,6 +337,8 @@ export const parse = (tokens) => {
337
337
  let property;
338
338
  let nestedProperties;
339
339
  let modifierToken;
340
+ const typeSymbol = Symbol();
341
+ locationMap.set(typeSymbol, next().location);
340
342
  if (match(TokenType.LeftSquareBracket)) {
341
343
  consume(TokenType.LeftSquareBracket);
342
344
  const arrayProperty = {
@@ -345,6 +347,7 @@ export const parse = (tokens) => {
345
347
  while (!match(TokenType.RightSquareBracket)) {
346
348
  const attributeSymbol = Symbol();
347
349
  arrayProperty[AST.LOCATION_SYMBOL] ??= {
350
+ type: typeSymbol,
348
351
  attributes: {},
349
352
  arrays: {}
350
353
  };
@@ -400,6 +403,7 @@ export const parse = (tokens) => {
400
403
  type: "object",
401
404
  properties: {},
402
405
  [AST.LOCATION_SYMBOL]: {
406
+ type: typeSymbol,
403
407
  attributes: {},
404
408
  arrays: {}
405
409
  }
@@ -426,7 +430,7 @@ export const parse = (tokens) => {
426
430
  }
427
431
  consume(TokenType.RightBracket);
428
432
  } else {
429
- const { value: identifier, location } = consume(TokenType.Identifier);
433
+ const { value: identifier } = consume(TokenType.Identifier);
430
434
  if (guards.isNativePropertyType(identifier)) {
431
435
  switch (identifier) {
432
436
  case "enum": {
@@ -461,12 +465,13 @@ export const parse = (tokens) => {
461
465
  };
462
466
  }
463
467
  } else {
464
- const collection = ast.collections.find((node2) => node2.name === identifier);
465
- if (!collection) {
466
- throw new Diagnostic(`invalid reference "${identifier}"`, location);
467
- }
468
468
  property = {
469
- $ref: identifier
469
+ $ref: identifier,
470
+ [AST.LOCATION_SYMBOL]: {
471
+ type: typeSymbol,
472
+ attributes: {},
473
+ arrays: {}
474
+ }
470
475
  };
471
476
  }
472
477
  }
@@ -477,6 +482,7 @@ export const parse = (tokens) => {
477
482
  const attributeSymbol = Symbol();
478
483
  locationMap.set(attributeSymbol, next().location);
479
484
  property[AST.LOCATION_SYMBOL] ??= {
485
+ type: typeSymbol,
480
486
  attributes: {},
481
487
  arrays: {}
482
488
  };
package/dist/semantic.js CHANGED
@@ -110,7 +110,9 @@ const analyze = async (ast, options, errors = []) => {
110
110
  const refName = node.property.$ref;
111
111
  const foreignCollection = ast.collections.find(({ name }) => name === refName);
112
112
  if (!foreignCollection) {
113
- throw new Error;
113
+ const location = parser_js_1.locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
114
+ errors.push(new diagnostic_js_1.Diagnostic(`invalid reference "${refName}"`, location));
115
+ return;
114
116
  }
115
117
  await checkCollectionForeignProperties(foreignCollection, node.property, 'indexes');
116
118
  await checkCollectionForeignProperties(foreignCollection, node.property, 'populate');
package/dist/semantic.mjs CHANGED
@@ -74,7 +74,9 @@ export const analyze = async (ast, options, errors = []) => {
74
74
  const refName = node.property.$ref;
75
75
  const foreignCollection = ast.collections.find(({ name }) => name === refName);
76
76
  if (!foreignCollection) {
77
- throw new Error();
77
+ const location = locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
78
+ errors.push(new Diagnostic(`invalid reference "${refName}"`, location));
79
+ return;
78
80
  }
79
81
  await checkCollectionForeignProperties(foreignCollection, node.property, "indexes");
80
82
  await checkCollectionForeignProperties(foreignCollection, node.property, "populate");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",