@aeriajs/compiler 0.0.62 → 0.0.64

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/semantic.js CHANGED
@@ -1,61 +1,28 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.analyze = void 0;
37
- const common_1 = require("@aeriajs/common");
38
- const parser_js_1 = require("./parser.js");
39
- const diagnostic_js_1 = require("./diagnostic.js");
40
- const AST = __importStar(require("./ast.js"));
1
+ import { isValidCollection } from '@aeriajs/common';
2
+ import { locationMap } from './parser.js';
3
+ import { Diagnostic } from './diagnostic.js';
4
+ import * as AST from './ast.js';
5
+ const containsPropertyWithId = (propName, properties) => {
6
+ return propName === '_id' || propName in properties;
7
+ };
41
8
  const collectionHasProperty = async (collection, propName, options = {}) => {
42
- let hasProperty = propName in collection.properties;
9
+ let hasProperty = containsPropertyWithId(propName, collection.properties);
43
10
  if (!hasProperty) {
44
11
  if (collection.extends) {
45
12
  if (options.languageServer) {
46
13
  return true;
47
14
  }
48
15
  const { importPath, symbolName } = collection.extends;
49
- const { [symbolName]: importedCollection } = await Promise.resolve(`${importPath}`).then(s => __importStar(require(s)));
50
- if (!(0, common_1.isValidCollection)(importedCollection)) {
16
+ const { [symbolName]: importedCollection } = await import(importPath);
17
+ if (!isValidCollection(importedCollection)) {
51
18
  throw new Error;
52
19
  }
53
- hasProperty = propName in importedCollection.description.properties;
20
+ hasProperty = containsPropertyWithId(propName, importedCollection.description.properties);
54
21
  }
55
22
  }
56
23
  return hasProperty;
57
24
  };
58
- const analyze = async (ast, options, errors = []) => {
25
+ export const analyze = async (ast, options, errors = []) => {
59
26
  const checkCollectionForeignProperties = async (foreignCollection, property, attributeName) => {
60
27
  if (!property[attributeName]) {
61
28
  return;
@@ -64,9 +31,9 @@ const analyze = async (ast, options, errors = []) => {
64
31
  if (!await collectionHasProperty(foreignCollection, foreignPropName, options)) {
65
32
  let location;
66
33
  if (property[AST.LOCATION_SYMBOL]) {
67
- location = parser_js_1.locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
34
+ location = locationMap.get(property[AST.LOCATION_SYMBOL].attributes[attributeName]);
68
35
  }
69
- errors.push(new diagnostic_js_1.Diagnostic(`collection "${foreignCollection.name}" hasn't such property "${foreignPropName}"`, location));
36
+ errors.push(new Diagnostic(`collection "${foreignCollection.name}" hasn't such property "${foreignPropName}"`, location));
70
37
  }
71
38
  }
72
39
  };
@@ -78,8 +45,8 @@ const analyze = async (ast, options, errors = []) => {
78
45
  const propName = node[attributeName][index];
79
46
  if (!await collectionHasProperty(node, propName, options)) {
80
47
  const symbol = node[AST.LOCATION_SYMBOL].arrays[attributeName][index];
81
- const location = parser_js_1.locationMap.get(symbol);
82
- errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
48
+ const location = locationMap.get(symbol);
49
+ errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
83
50
  }
84
51
  }
85
52
  };
@@ -91,9 +58,8 @@ const analyze = async (ast, options, errors = []) => {
91
58
  const propName = node.property[attributeName][index];
92
59
  if (!(propName in node.nestedProperties)) {
93
60
  const symbol = node.property[AST.LOCATION_SYMBOL].arrays[attributeName][index];
94
- const location = parser_js_1.locationMap.get(symbol);
95
- console.log(JSON.stringify(node));
96
- errors.push(new diagnostic_js_1.Diagnostic(`object hasn't such property "${propName}"`, location));
61
+ const location = locationMap.get(symbol);
62
+ errors.push(new Diagnostic(`object hasn't such property "${propName}"`, location));
97
63
  }
98
64
  }
99
65
  };
@@ -116,8 +82,8 @@ const analyze = async (ast, options, errors = []) => {
116
82
  const refName = node.property.$ref;
117
83
  const foreignCollection = ast.collections.find(({ name }) => name === refName);
118
84
  if (!foreignCollection) {
119
- const location = parser_js_1.locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
120
- errors.push(new diagnostic_js_1.Diagnostic(`invalid reference "${refName}"`, location));
85
+ const location = locationMap.get(node.property[AST.LOCATION_SYMBOL].type);
86
+ errors.push(new Diagnostic(`invalid reference "${refName}"`, location));
121
87
  return;
122
88
  }
123
89
  await checkCollectionForeignProperties(foreignCollection, node.property, 'indexes');
@@ -126,8 +92,8 @@ const analyze = async (ast, options, errors = []) => {
126
92
  if (node.property.constraints) {
127
93
  for (const [name, symbol] of node.property[AST.LOCATION_SYMBOL].contraintTerms) {
128
94
  if (!await collectionHasProperty(foreignCollection, name, options)) {
129
- const location = parser_js_1.locationMap.get(symbol);
130
- errors.push(new diagnostic_js_1.Diagnostic(`left operand "${name}" does not exist on collection "${foreignCollection.name}"`, location));
95
+ const location = locationMap.get(symbol);
96
+ errors.push(new Diagnostic(`left operand "${name}" does not exist on collection "${foreignCollection.name}"`, location));
131
97
  }
132
98
  }
133
99
  }
@@ -151,10 +117,10 @@ const analyze = async (ast, options, errors = []) => {
151
117
  : Object.keys(node.required);
152
118
  for (const index in propNames) {
153
119
  const propName = propNames[index];
154
- if (!(propName in node.properties)) {
120
+ if (!containsPropertyWithId(propName, node.properties)) {
155
121
  const symbol = node[AST.LOCATION_SYMBOL].required[index];
156
- const location = parser_js_1.locationMap.get(symbol);
157
- errors.push(new diagnostic_js_1.Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
122
+ const location = locationMap.get(symbol);
123
+ errors.push(new Diagnostic(`collection "${node.name}" hasn't such property "${propName}"`, location));
158
124
  }
159
125
  }
160
126
  }
@@ -164,9 +130,9 @@ const analyze = async (ast, options, errors = []) => {
164
130
  }
165
131
  if (node[AST.LOCATION_SYMBOL].requiredTerms) {
166
132
  for (const [name, symbol] of node[AST.LOCATION_SYMBOL].requiredTerms) {
167
- if (!(name in node.properties)) {
168
- const location = parser_js_1.locationMap.get(symbol);
169
- errors.push(new diagnostic_js_1.Diagnostic(`invalid left operand "${name}"`, location));
133
+ if (!containsPropertyWithId(name, node.properties)) {
134
+ const location = locationMap.get(symbol);
135
+ errors.push(new Diagnostic(`invalid left operand "${name}"`, location));
170
136
  }
171
137
  }
172
138
  }
@@ -176,16 +142,16 @@ const analyze = async (ast, options, errors = []) => {
176
142
  const option = node.layout.options[name];
177
143
  if (Array.isArray(option)) {
178
144
  for (const [i, propName] of option.entries()) {
179
- if (!(propName in node.properties)) {
180
- const location = parser_js_1.locationMap.get(value[i]);
181
- errors.push(new diagnostic_js_1.Diagnostic(`invalid property "${propName}"`, location));
145
+ if (!containsPropertyWithId(propName, node.properties)) {
146
+ const location = locationMap.get(value[i]);
147
+ errors.push(new Diagnostic(`invalid property "${propName}"`, location));
182
148
  }
183
149
  }
184
150
  }
185
151
  else {
186
- if (!(option in node.properties)) {
187
- const location = parser_js_1.locationMap.get(value);
188
- errors.push(new diagnostic_js_1.Diagnostic(`invalid property "${option}"`, location));
152
+ if (!containsPropertyWithId(option, node.properties)) {
153
+ const location = locationMap.get(value);
154
+ errors.push(new Diagnostic(`invalid property "${option}"`, location));
189
155
  }
190
156
  }
191
157
  }
@@ -194,17 +160,17 @@ const analyze = async (ast, options, errors = []) => {
194
160
  if (node.formLayout) {
195
161
  if (node.formLayout.fields) {
196
162
  for (const [name, value] of Object.entries(node.formLayout[AST.LOCATION_SYMBOL].fields)) {
197
- if (!(name in node.properties)) {
198
- const location = parser_js_1.locationMap.get(value.name);
199
- errors.push(new diagnostic_js_1.Diagnostic(`invalid property "${name}"`, location));
163
+ if (!containsPropertyWithId(name, node.properties)) {
164
+ const location = locationMap.get(value.name);
165
+ errors.push(new Diagnostic(`invalid property "${name}"`, location));
200
166
  }
201
167
  }
202
168
  }
203
169
  if (node.formLayout[AST.LOCATION_SYMBOL].terms) {
204
170
  for (const [name, symbol] of node.formLayout[AST.LOCATION_SYMBOL].terms) {
205
- if (!(name in node.properties)) {
206
- const location = parser_js_1.locationMap.get(symbol);
207
- errors.push(new diagnostic_js_1.Diagnostic(`invalid left operand "${name}"`, location));
171
+ if (!containsPropertyWithId(name, node.properties)) {
172
+ const location = locationMap.get(symbol);
173
+ errors.push(new Diagnostic(`invalid left operand "${name}"`, location));
208
174
  }
209
175
  }
210
176
  }
@@ -212,9 +178,9 @@ const analyze = async (ast, options, errors = []) => {
212
178
  if (node.search) {
213
179
  for (const [i, symbol] of node[AST.LOCATION_SYMBOL].searchIndexes.entries()) {
214
180
  const propName = node.search.indexes[i];
215
- if (!(propName in node.properties)) {
216
- const location = parser_js_1.locationMap.get(symbol);
217
- errors.push(new diagnostic_js_1.Diagnostic(`invalid property "${propName}"`, location));
181
+ if (!containsPropertyWithId(propName, node.properties)) {
182
+ const location = locationMap.get(symbol);
183
+ errors.push(new Diagnostic(`invalid property "${propName}"`, location));
218
184
  }
219
185
  }
220
186
  }
@@ -241,4 +207,3 @@ const analyze = async (ast, options, errors = []) => {
241
207
  errors,
242
208
  };
243
209
  };
244
- exports.analyze = analyze;
package/dist/token.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenType = void 0;
4
- exports.TokenType = {
1
+ export const TokenType = {
5
2
  LineBreak: 'LINE_BREAK',
6
3
  Comment: 'COMMENT',
7
4
  LeftBracket: 'LEFT_BRACKET',
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/utils.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_EXPORT_SYMBOLS = void 0;
4
- exports.DEFAULT_EXPORT_SYMBOLS = {
1
+ export const DEFAULT_EXPORT_SYMBOLS = {
5
2
  count: 'aeria',
6
3
  get: 'aeria',
7
4
  getAll: 'aeria',
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.62",
3
+ "type": "module",
4
+ "version": "0.0.64",
4
5
  "description": "",
5
6
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -11,7 +11,7 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
14
+ "default": "./dist/index.js"
15
15
  }
16
16
  },
17
17
  "keywords": [],
@@ -21,8 +21,8 @@
21
21
  "dist"
22
22
  ],
23
23
  "peerDependencies": {
24
- "@aeriajs/common": "^0.0.157",
25
- "@aeriajs/types": "^0.0.135"
24
+ "@aeriajs/common": "^0.0.158",
25
+ "@aeriajs/types": "^0.0.136"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@aeriajs/common": "link:../common",
@@ -33,9 +33,6 @@
33
33
  "test": "echo skipping",
34
34
  "lint": "eslint .",
35
35
  "lint:fix": "eslint . --fix",
36
- "build": "pnpm build:cjs && pnpm build:esm",
37
- "build:cjs": "tsc",
38
- "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
39
- "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
36
+ "build": "tsc"
40
37
  }
41
38
  }
package/dist/ast.mjs DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- export const LOCATION_SYMBOL = Symbol();
3
- export const PropertyType = {
4
- str: "string",
5
- int: "integer",
6
- num: "number",
7
- bool: "boolean",
8
- enum: "enum",
9
- date: "string",
10
- datetime: "string",
11
- objectid: "string",
12
- const: "const"
13
- };
14
- export const PropertyModifiers = {
15
- Error: {
16
- packageName: "aeria",
17
- importPath: "aeria",
18
- symbolName: "errorSchema"
19
- },
20
- Result: {
21
- packageName: "aeria",
22
- importPath: "aeria",
23
- symbolName: "resultSchema"
24
- }
25
- };
@@ -1,85 +0,0 @@
1
- "use strict";
2
- import { errorSchema, resultSchema } from "@aeriajs/types";
3
- import { recursivelyUnwrapPropertyNodes, unwrapPropertyNode, stringify, UnquotedSymbol } from "./utils.mjs";
4
- export const generateContracts = (ast) => {
5
- if (ast.contracts.length === 0) {
6
- return false;
7
- }
8
- return {
9
- js: makeJSContractsCode(ast),
10
- dts: makeTSContractsCode(ast)
11
- };
12
- };
13
- const makeJSContractsCode = (ast) => {
14
- const imports = /* @__PURE__ */ new Set(["defineContract"]);
15
- const getCodeForResponse = (responseProperty) => {
16
- const { kind, modifier, ...propertyNode } = responseProperty;
17
- if (!modifier) {
18
- return stringify(unwrapPropertyNode(propertyNode));
19
- }
20
- const modifierSymbol = responseProperty.modifier === "Result" ? "resultSchema" : "errorSchema";
21
- if (!imports.has(modifierSymbol)) {
22
- imports.add(modifierSymbol);
23
- }
24
- return `${modifierSymbol}(${stringify(unwrapPropertyNode(propertyNode))})`;
25
- };
26
- const declarations = ast.contracts.map((node) => {
27
- const { name, kind, roles, response, ...contractProperty } = node;
28
- let responseString;
29
- if (response) {
30
- responseString = "";
31
- if (Array.isArray(response)) {
32
- const responseArray = [];
33
- for (const responseElement of response) {
34
- responseArray.push({
35
- [UnquotedSymbol]: getCodeForResponse(responseElement)
36
- });
37
- }
38
- responseString = stringify(responseArray);
39
- } else {
40
- responseString = getCodeForResponse(response);
41
- }
42
- }
43
- const contractSchema = recursivelyUnwrapPropertyNodes(contractProperty);
44
- if (responseString) {
45
- contractSchema.response = {
46
- [UnquotedSymbol]: responseString
47
- };
48
- }
49
- if (roles) {
50
- contractSchema.roles = roles;
51
- }
52
- return `export const ${name} = defineContract(${stringify(contractSchema)})`;
53
- }).join("\n\n");
54
- return `import { ${Array.from(imports).join(", ")} } from 'aeria'
55
-
56
- ` + declarations;
57
- };
58
- const getResponseSchema = (response) => {
59
- const responseSchema = unwrapPropertyNode(response);
60
- if (!response.modifier) {
61
- return responseSchema;
62
- }
63
- return response.modifier === "Result" ? resultSchema(responseSchema) : errorSchema(responseSchema);
64
- };
65
- const makeTSContractsCode = (ast) => {
66
- return ast.contracts.map((node) => {
67
- const { name, kind, roles, ...contractSchema } = node;
68
- let responseSchema = null;
69
- if (contractSchema.response) {
70
- if (Array.isArray(contractSchema.response)) {
71
- responseSchema = contractSchema.response.map(getResponseSchema);
72
- } else {
73
- responseSchema = getResponseSchema(contractSchema.response);
74
- }
75
- }
76
- const contractProperties = recursivelyUnwrapPropertyNodes(contractSchema);
77
- if (responseSchema) {
78
- contractProperties.response = responseSchema;
79
- }
80
- if (roles) {
81
- contractProperties.roles = roles;
82
- }
83
- return `export declare const ${node.name}: ${stringify(contractProperties)}`;
84
- }).join("\n\n");
85
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- import { resizeFirstChar, getExtendName, getCollectionId } from "./utils.mjs";
3
- export const generateExports = (ast, options = {
4
- hasContracts: false
5
- }) => {
6
- const symbolsToExport = Object.values(ast.collections.reduce((symbols, node) => {
7
- const id = getCollectionId(node.name);
8
- symbols[id] = {
9
- id,
10
- schema: resizeFirstChar(node.name, true),
11
- extend: getExtendName(node.name)
12
- };
13
- return symbols;
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
- }
25
- const exports = {
26
- collections: {
27
- js: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`,
28
- dts: `export { ${symbolsToExport.map((symbol) => `${symbol.id}`).join(", ")} } from './collections.mjs'`
29
- },
30
- index: {
31
- js: indexJs,
32
- dts: indexDts
33
- }
34
- };
35
- if (options.hasContracts) {
36
- exports.contracts = {
37
- js: "export * from './contracts.mjs'",
38
- dts: "export * from './contracts.mjs'"
39
- };
40
- }
41
- return exports;
42
- };
@@ -1,103 +0,0 @@
1
- "use strict";
2
- import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, getCollectionId, UnquotedSymbol, getExposedFunctions, getExtendName, PACKAGE_NAME } from "./utils.mjs";
3
- const initialImportedFunctions = [
4
- "extendCollection",
5
- "defineCollection"
6
- ];
7
- export const generateJSCollections = (ast) => {
8
- let javascriptCode = "";
9
- const importsResult = makeASTImports(ast.collections, {
10
- [PACKAGE_NAME]: new Set(initialImportedFunctions)
11
- }, {
12
- includeRuntimeOnlyImports: true
13
- });
14
- javascriptCode += importsResult.code.join("\n") + "\n\n";
15
- javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + "\n\n";
16
- return javascriptCode;
17
- };
18
- const makeJSCollections = (ast, modifiedSymbols) => {
19
- const collectionCodes = {};
20
- for (const collectionNode of ast.collections) {
21
- const id = getCollectionId(collectionNode.name);
22
- const extendCollectionName = getExtendName(collectionNode.name);
23
- const collectionDefinition = `export const ${id} = ${collectionNode.extends ? `extendCollection(${id in modifiedSymbols ? modifiedSymbols[id] : id}, ${makeJSCollectionSchema(ast, collectionNode, id)})` : `defineCollection(${makeJSCollectionSchema(ast, collectionNode, id)})`}`;
24
- const collectionDeclaration = `export const ${extendCollectionName} = (collection) => extendCollection(${id}, collection)`;
25
- collectionCodes[collectionNode.name] = [
26
- "//" + collectionNode.name,
27
- collectionDefinition,
28
- collectionDeclaration
29
- ].join("\n");
30
- }
31
- return Object.values(collectionCodes).join("\n\n");
32
- };
33
- const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
34
- const collectionSchema = {
35
- item: {},
36
- description: {
37
- $id: collectionId,
38
- properties: {}
39
- }
40
- };
41
- for (const key of Object.keys(collectionNode)) {
42
- if (collectionNode[key] === void 0) {
43
- continue;
44
- }
45
- switch (key) {
46
- case "properties":
47
- collectionSchema.description[key] = recursivelyUnwrapPropertyNodes(collectionNode[key]);
48
- break;
49
- case "owned":
50
- collectionSchema.description[key] = collectionNode[key];
51
- break;
52
- case "middlewares":
53
- collectionSchema.middlewares = {
54
- [UnquotedSymbol]: `[ ${collectionNode[key].join(", ")} ]`
55
- };
56
- break;
57
- case "functions":
58
- collectionSchema.functions = {
59
- [UnquotedSymbol]: `{ ${makeJSFunctions(collectionNode[key])} }`
60
- };
61
- collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
62
- break;
63
- case "required":
64
- collectionSchema.description[key] = collectionNode[key];
65
- break;
66
- case "table":
67
- case "tableMeta":
68
- case "filters":
69
- case "indexes":
70
- case "form":
71
- collectionSchema.description[key] = collectionNode[key];
72
- break;
73
- case "actions":
74
- case "individualActions":
75
- collectionSchema.description[key] = collectionNode[key];
76
- break;
77
- case "icon":
78
- collectionSchema.description[key] = collectionNode[key];
79
- break;
80
- case "presets":
81
- collectionSchema.description[key] = collectionNode[key];
82
- break;
83
- case "search":
84
- collectionSchema.description[key] = collectionNode[key];
85
- break;
86
- case "layout":
87
- collectionSchema.description[key] = unwrapNode(collectionNode[key]);
88
- break;
89
- case "formLayout":
90
- collectionSchema.description[key] = unwrapNode(collectionNode[key]);
91
- break;
92
- }
93
- }
94
- return stringify(collectionSchema);
95
- };
96
- const makeJSFunctions = (functionNodes) => {
97
- let output = "";
98
- for (const functionNode of functionNodes) {
99
- output += functionNode.exportSymbol ? functionNode.exportSymbol.symbolName : `${functionNode.name}: () => { throw new Error('Function not implemented') }`;
100
- output += ", ";
101
- }
102
- return output;
103
- };
@@ -1,114 +0,0 @@
1
- "use strict";
2
- import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME } from "./utils.mjs";
3
- const initialImportedTypes = [
4
- "Collection",
5
- "SchemaWithId",
6
- "ExtendCollection",
7
- "Context"
8
- ];
9
- export const generateTSCollections = (ast) => {
10
- let code = "";
11
- code += `import type { ${initialImportedTypes.join(", ")} } from '${PACKAGE_NAME}'
12
- `;
13
- const importsResult = makeASTImports(ast.collections);
14
- code += importsResult.code.join("\n") + "\n\n";
15
- code += makeTSCollections(ast, importsResult.modifiedSymbols) + "\n";
16
- return code;
17
- };
18
- const makeTSCollections = (ast, modifiedSymbols) => {
19
- const collectionCodes = {};
20
- for (const collectionNode of ast.collections) {
21
- const id = getCollectionId(collectionNode.name);
22
- const schemaName = resizeFirstChar(collectionNode.name, true);
23
- const typeName = id + "Collection";
24
- const collectionType = `export declare type ${typeName} = ${id in modifiedSymbols ? `ExtendCollection<typeof ${modifiedSymbols[id]}, ${makeTSCollectionSchema(collectionNode, id)}>` : makeTSCollectionSchema(collectionNode, id)}`;
25
- const collectionDeclaration = `export declare const ${id}: ${typeName} & { item: SchemaWithId<${typeName}["description"]> }`;
26
- const collectionSchema = `export declare type ${schemaName} = SchemaWithId<typeof ${id}.description>`;
27
- const collectionExtend = `export declare const extend${schemaName}Collection: <
28
- const TCollection extends {
29
- [P in Exclude<keyof Collection, "functions">]?: Partial<Collection[P]>
30
- } & {
31
- functions?: {
32
- [F: string]: (payload: any, context: Context<typeof ${id}["description"]>) => unknown
33
- }
34
- }>(collection: TCollection) => ExtendCollection<typeof ${id}, TCollection>`;
35
- collectionCodes[collectionNode.name] = [
36
- "//" + collectionNode.name,
37
- collectionType,
38
- collectionDeclaration,
39
- collectionSchema,
40
- collectionExtend
41
- ].join("\n");
42
- }
43
- return Object.values(collectionCodes).join("\n\n");
44
- };
45
- const makeTSCollectionSchema = (collectionNode, collectionId) => {
46
- const collectionSchema = {
47
- item: {},
48
- description: {
49
- $id: collectionId,
50
- properties: {}
51
- }
52
- };
53
- for (const key of Object.keys(collectionNode)) {
54
- if (collectionNode[key] === void 0) {
55
- continue;
56
- }
57
- switch (key) {
58
- case "properties":
59
- collectionSchema.description.properties = recursivelyUnwrapPropertyNodes(collectionNode[key]);
60
- break;
61
- case "owned":
62
- collectionSchema.description.owned = collectionNode[key];
63
- break;
64
- case "middlewares":
65
- collectionSchema.middlewares = {
66
- [UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]"
67
- };
68
- break;
69
- case "functions":
70
- collectionSchema.functions = makeTSFunctions(collectionNode[key]);
71
- collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
72
- break;
73
- case "required":
74
- collectionSchema.description[key] = collectionNode[key];
75
- break;
76
- case "table":
77
- case "tableMeta":
78
- case "filters":
79
- case "indexes":
80
- case "form":
81
- collectionSchema.description[key] = collectionNode[key];
82
- break;
83
- case "actions":
84
- case "individualActions":
85
- collectionSchema.description[key] = collectionNode[key];
86
- break;
87
- case "icon":
88
- collectionSchema.description[key] = collectionNode[key];
89
- break;
90
- case "presets":
91
- collectionSchema.description[key] = collectionNode[key];
92
- break;
93
- case "search":
94
- collectionSchema.description[key] = collectionNode[key];
95
- break;
96
- case "layout":
97
- collectionSchema.description[key] = unwrapNode(collectionNode[key]);
98
- break;
99
- case "formLayout":
100
- collectionSchema.description[key] = unwrapNode(collectionNode[key]);
101
- break;
102
- }
103
- }
104
- return stringify(collectionSchema);
105
- };
106
- const makeTSFunctions = (functionNodes) => {
107
- const funs = {};
108
- for (const functionNode of functionNodes) {
109
- funs[functionNode.name] = {
110
- [UnquotedSymbol]: functionNode.exportSymbol ? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}` : "unknown"
111
- };
112
- }
113
- return funs;
114
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- export * from "./generateJSCollections.mjs";
3
- export * from "./generateTSCollections.mjs";
4
- export * from "./generateExports.mjs";
5
- export * from "./generateContracts.mjs";