@aeriajs/compiler 0.0.62 → 0.0.63

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.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PropertyModifiers = exports.PropertyType = exports.LOCATION_SYMBOL = void 0;
4
- exports.LOCATION_SYMBOL = Symbol();
5
- exports.PropertyType = {
1
+ export const LOCATION_SYMBOL = Symbol();
2
+ export const PropertyType = {
6
3
  str: 'string',
7
4
  int: 'integer',
8
5
  num: 'number',
@@ -13,7 +10,7 @@ exports.PropertyType = {
13
10
  objectid: 'string',
14
11
  const: 'const',
15
12
  };
16
- exports.PropertyModifiers = {
13
+ export const PropertyModifiers = {
17
14
  Error: {
18
15
  packageName: 'aeria',
19
16
  importPath: 'aeria',
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateContracts = void 0;
4
- const types_1 = require("@aeriajs/types");
5
- const utils_js_1 = require("./utils.js");
6
- const generateContracts = (ast) => {
1
+ import { errorSchema, resultSchema } from '@aeriajs/types';
2
+ import { recursivelyUnwrapPropertyNodes, unwrapPropertyNode, stringify, UnquotedSymbol } from './utils.js';
3
+ export const generateContracts = (ast) => {
7
4
  if (ast.contracts.length === 0) {
8
5
  return false;
9
6
  }
@@ -12,13 +9,12 @@ const generateContracts = (ast) => {
12
9
  dts: makeTSContractsCode(ast),
13
10
  };
14
11
  };
15
- exports.generateContracts = generateContracts;
16
12
  const makeJSContractsCode = (ast) => {
17
13
  const imports = new Set(['defineContract']);
18
14
  const getCodeForResponse = (responseProperty) => {
19
15
  const { kind, modifier, ...propertyNode } = responseProperty;
20
16
  if (!modifier) {
21
- return (0, utils_js_1.stringify)((0, utils_js_1.unwrapPropertyNode)(propertyNode));
17
+ return stringify(unwrapPropertyNode(propertyNode));
22
18
  }
23
19
  const modifierSymbol = responseProperty.modifier === 'Result'
24
20
  ? 'resultSchema'
@@ -26,7 +22,7 @@ const makeJSContractsCode = (ast) => {
26
22
  if (!imports.has(modifierSymbol)) {
27
23
  imports.add(modifierSymbol);
28
24
  }
29
- return `${modifierSymbol}(${(0, utils_js_1.stringify)((0, utils_js_1.unwrapPropertyNode)(propertyNode))})`;
25
+ return `${modifierSymbol}(${stringify(unwrapPropertyNode(propertyNode))})`;
30
26
  };
31
27
  const declarations = ast.contracts.map((node) => {
32
28
  const { name, kind, roles, response, ...contractProperty } = node;
@@ -37,36 +33,36 @@ const makeJSContractsCode = (ast) => {
37
33
  const responseArray = [];
38
34
  for (const responseElement of response) {
39
35
  responseArray.push({
40
- [utils_js_1.UnquotedSymbol]: getCodeForResponse(responseElement),
36
+ [UnquotedSymbol]: getCodeForResponse(responseElement),
41
37
  });
42
38
  }
43
- responseString = (0, utils_js_1.stringify)(responseArray);
39
+ responseString = stringify(responseArray);
44
40
  }
45
41
  else {
46
42
  responseString = getCodeForResponse(response);
47
43
  }
48
44
  }
49
- const contractSchema = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(contractProperty);
45
+ const contractSchema = recursivelyUnwrapPropertyNodes(contractProperty);
50
46
  if (responseString) {
51
47
  contractSchema.response = {
52
- [utils_js_1.UnquotedSymbol]: responseString,
48
+ [UnquotedSymbol]: responseString,
53
49
  };
54
50
  }
55
51
  if (roles) {
56
52
  contractSchema.roles = roles;
57
53
  }
58
- return `export const ${name} = defineContract(${(0, utils_js_1.stringify)(contractSchema)})`;
54
+ return `export const ${name} = defineContract(${stringify(contractSchema)})`;
59
55
  }).join('\n\n');
60
56
  return `import { ${Array.from(imports).join(', ')} } from 'aeria'\n\n` + declarations;
61
57
  };
62
58
  const getResponseSchema = (response) => {
63
- const responseSchema = (0, utils_js_1.unwrapPropertyNode)(response);
59
+ const responseSchema = unwrapPropertyNode(response);
64
60
  if (!response.modifier) {
65
61
  return responseSchema;
66
62
  }
67
63
  return response.modifier === 'Result' ?
68
- (0, types_1.resultSchema)(responseSchema) :
69
- (0, types_1.errorSchema)(responseSchema);
64
+ resultSchema(responseSchema) :
65
+ errorSchema(responseSchema);
70
66
  };
71
67
  const makeTSContractsCode = (ast) => {
72
68
  return ast.contracts.map((node) => {
@@ -80,13 +76,13 @@ const makeTSContractsCode = (ast) => {
80
76
  responseSchema = getResponseSchema(contractSchema.response);
81
77
  }
82
78
  }
83
- const contractProperties = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(contractSchema);
79
+ const contractProperties = recursivelyUnwrapPropertyNodes(contractSchema);
84
80
  if (responseSchema) {
85
81
  contractProperties.response = responseSchema;
86
82
  }
87
83
  if (roles) {
88
84
  contractProperties.roles = roles;
89
85
  }
90
- return `export declare const ${node.name}: ${(0, utils_js_1.stringify)(contractProperties)}`;
86
+ return `export declare const ${node.name}: ${stringify(contractProperties)}`;
91
87
  }).join('\n\n');
92
88
  };
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateExports = void 0;
4
- const utils_js_1 = require("./utils.js");
5
- const generateExports = (ast, options = {
1
+ import { resizeFirstChar, getExtendName, getCollectionId } from './utils.js';
2
+ export const generateExports = (ast, options = {
6
3
  hasContracts: false,
7
4
  }) => {
8
5
  const symbolsToExport = Object.values(ast.collections.reduce((symbols, node) => {
9
- const id = (0, utils_js_1.getCollectionId)(node.name);
6
+ const id = getCollectionId(node.name);
10
7
  symbols[id] = {
11
8
  id,
12
- schema: (0, utils_js_1.resizeFirstChar)(node.name, true),
13
- extend: (0, utils_js_1.getExtendName)(node.name),
9
+ schema: resizeFirstChar(node.name, true),
10
+ extend: getExtendName(node.name),
14
11
  };
15
12
  return symbols;
16
13
  }, {}));
@@ -40,4 +37,3 @@ const generateExports = (ast, options = {
40
37
  }
41
38
  return exports;
42
39
  };
43
- exports.generateExports = generateExports;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateJSCollections = void 0;
4
- const utils_js_1 = require("./utils.js");
1
+ import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, getCollectionId, UnquotedSymbol, getExposedFunctions, getExtendName, PACKAGE_NAME } from './utils.js';
5
2
  const initialImportedFunctions = [
6
3
  'extendCollection',
7
4
  'defineCollection',
8
5
  ];
9
- const generateJSCollections = (ast) => {
6
+ export const generateJSCollections = (ast) => {
10
7
  let javascriptCode = '';
11
- const importsResult = (0, utils_js_1.makeASTImports)(ast.collections, {
12
- [utils_js_1.PACKAGE_NAME]: new Set(initialImportedFunctions),
8
+ const importsResult = makeASTImports(ast.collections, {
9
+ [PACKAGE_NAME]: new Set(initialImportedFunctions),
13
10
  }, {
14
11
  includeRuntimeOnlyImports: true,
15
12
  });
@@ -17,12 +14,11 @@ const generateJSCollections = (ast) => {
17
14
  javascriptCode += makeJSCollections(ast, importsResult.modifiedSymbols) + '\n\n';
18
15
  return javascriptCode;
19
16
  };
20
- exports.generateJSCollections = generateJSCollections;
21
17
  const makeJSCollections = (ast, modifiedSymbols) => {
22
18
  const collectionCodes = {};
23
19
  for (const collectionNode of ast.collections) {
24
- const id = (0, utils_js_1.getCollectionId)(collectionNode.name); // CollectionName -> collectionName
25
- const extendCollectionName = (0, utils_js_1.getExtendName)(collectionNode.name);
20
+ const id = getCollectionId(collectionNode.name); // CollectionName -> collectionName
21
+ const extendCollectionName = getExtendName(collectionNode.name);
26
22
  const collectionDefinition = `export const ${id} = ${collectionNode.extends
27
23
  ? `extendCollection(${id in modifiedSymbols
28
24
  ? modifiedSymbols[id]
@@ -51,21 +47,21 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
51
47
  }
52
48
  switch (key) {
53
49
  case 'properties':
54
- collectionSchema.description[key] = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(collectionNode[key]);
50
+ collectionSchema.description[key] = recursivelyUnwrapPropertyNodes(collectionNode[key]);
55
51
  break;
56
52
  case 'owned':
57
53
  collectionSchema.description[key] = collectionNode[key];
58
54
  break;
59
55
  case 'middlewares':
60
56
  collectionSchema.middlewares = {
61
- [utils_js_1.UnquotedSymbol]: `[ ${collectionNode[key].join(', ')} ]`,
57
+ [UnquotedSymbol]: `[ ${collectionNode[key].join(', ')} ]`,
62
58
  };
63
59
  break;
64
60
  case 'functions':
65
61
  collectionSchema.functions = {
66
- [utils_js_1.UnquotedSymbol]: `{ ${makeJSFunctions(collectionNode[key])} }`,
62
+ [UnquotedSymbol]: `{ ${makeJSFunctions(collectionNode[key])} }`,
67
63
  };
68
- collectionSchema.exposedFunctions = (0, utils_js_1.getExposedFunctions)(collectionNode[key]);
64
+ collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
69
65
  break;
70
66
  case 'required':
71
67
  collectionSchema.description[key] = collectionNode[key];
@@ -91,14 +87,14 @@ const makeJSCollectionSchema = (ast, collectionNode, collectionId) => {
91
87
  collectionSchema.description[key] = collectionNode[key];
92
88
  break;
93
89
  case 'layout':
94
- collectionSchema.description[key] = (0, utils_js_1.unwrapNode)(collectionNode[key]);
90
+ collectionSchema.description[key] = unwrapNode(collectionNode[key]);
95
91
  break;
96
92
  case 'formLayout':
97
- collectionSchema.description[key] = (0, utils_js_1.unwrapNode)(collectionNode[key]);
93
+ collectionSchema.description[key] = unwrapNode(collectionNode[key]);
98
94
  break;
99
95
  }
100
96
  }
101
- return (0, utils_js_1.stringify)(collectionSchema);
97
+ return stringify(collectionSchema);
102
98
  };
103
99
  const makeJSFunctions = (functionNodes) => {
104
100
  let output = '';
@@ -1,27 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateTSCollections = void 0;
4
- const utils_js_1 = require("./utils.js");
1
+ import { unwrapNode, recursivelyUnwrapPropertyNodes, stringify, makeASTImports, resizeFirstChar, getCollectionId, UnquotedSymbol, getExposedFunctions, PACKAGE_NAME } from './utils.js';
5
2
  const initialImportedTypes = [
6
3
  'Collection',
7
4
  'SchemaWithId',
8
5
  'ExtendCollection',
9
6
  'Context',
10
7
  ];
11
- const generateTSCollections = (ast) => {
8
+ export const generateTSCollections = (ast) => {
12
9
  let code = '';
13
- code += `import type { ${initialImportedTypes.join(', ')} } from '${utils_js_1.PACKAGE_NAME}'\n`; //Used types
14
- const importsResult = (0, utils_js_1.makeASTImports)(ast.collections);
10
+ code += `import type { ${initialImportedTypes.join(', ')} } from '${PACKAGE_NAME}'\n`; //Used types
11
+ const importsResult = makeASTImports(ast.collections);
15
12
  code += importsResult.code.join('\n') + '\n\n';
16
13
  code += makeTSCollections(ast, importsResult.modifiedSymbols) + '\n';
17
14
  return code;
18
15
  };
19
- exports.generateTSCollections = generateTSCollections;
20
16
  const makeTSCollections = (ast, modifiedSymbols) => {
21
17
  const collectionCodes = {};
22
18
  for (const collectionNode of ast.collections) {
23
- const id = (0, utils_js_1.getCollectionId)(collectionNode.name); // CollectionName -> collectionName
24
- const schemaName = (0, utils_js_1.resizeFirstChar)(collectionNode.name, true); // collectionName -> CollectionName
19
+ const id = getCollectionId(collectionNode.name); // CollectionName -> collectionName
20
+ const schemaName = resizeFirstChar(collectionNode.name, true); // collectionName -> CollectionName
25
21
  const typeName = id + 'Collection'; // Pet -> petCollection
26
22
  const collectionType = `export declare type ${typeName} = ${id in modifiedSymbols
27
23
  ? `ExtendCollection<typeof ${modifiedSymbols[id]}, ${makeTSCollectionSchema(collectionNode, id)}>`
@@ -60,19 +56,19 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
60
56
  }
61
57
  switch (key) {
62
58
  case 'properties':
63
- collectionSchema.description.properties = (0, utils_js_1.recursivelyUnwrapPropertyNodes)(collectionNode[key]);
59
+ collectionSchema.description.properties = recursivelyUnwrapPropertyNodes(collectionNode[key]);
64
60
  break;
65
61
  case 'owned':
66
62
  collectionSchema.description.owned = collectionNode[key];
67
63
  break;
68
64
  case 'middlewares':
69
65
  collectionSchema.middlewares = {
70
- [utils_js_1.UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]",
66
+ [UnquotedSymbol]: "import('@aeriajs/types').CollectionMiddleware<unknown>[]",
71
67
  };
72
68
  break;
73
69
  case 'functions':
74
70
  collectionSchema.functions = makeTSFunctions(collectionNode[key]);
75
- collectionSchema.exposedFunctions = (0, utils_js_1.getExposedFunctions)(collectionNode[key]);
71
+ collectionSchema.exposedFunctions = getExposedFunctions(collectionNode[key]);
76
72
  break;
77
73
  case 'required':
78
74
  collectionSchema.description[key] = collectionNode[key];
@@ -98,20 +94,20 @@ const makeTSCollectionSchema = (collectionNode, collectionId) => {
98
94
  collectionSchema.description[key] = collectionNode[key];
99
95
  break;
100
96
  case 'layout':
101
- collectionSchema.description[key] = (0, utils_js_1.unwrapNode)(collectionNode[key]);
97
+ collectionSchema.description[key] = unwrapNode(collectionNode[key]);
102
98
  break;
103
99
  case 'formLayout':
104
- collectionSchema.description[key] = (0, utils_js_1.unwrapNode)(collectionNode[key]);
100
+ collectionSchema.description[key] = unwrapNode(collectionNode[key]);
105
101
  break;
106
102
  }
107
103
  }
108
- return (0, utils_js_1.stringify)(collectionSchema);
104
+ return stringify(collectionSchema);
109
105
  };
110
106
  const makeTSFunctions = (functionNodes) => {
111
107
  const funs = {};
112
108
  for (const functionNode of functionNodes) {
113
109
  funs[functionNode.name] = {
114
- [utils_js_1.UnquotedSymbol]: functionNode.exportSymbol
110
+ [UnquotedSymbol]: functionNode.exportSymbol
115
111
  ? `typeof import('${functionNode.exportSymbol.importPath}').${functionNode.exportSymbol.symbolName}`
116
112
  : 'unknown',
117
113
  };
@@ -1,20 +1,4 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./generateJSCollections.js"), exports);
18
- __exportStar(require("./generateTSCollections.js"), exports);
19
- __exportStar(require("./generateExports.js"), exports);
20
- __exportStar(require("./generateContracts.js"), exports);
1
+ export * from './generateJSCollections.js';
2
+ export * from './generateTSCollections.js';
3
+ export * from './generateExports.js';
4
+ export * from './generateContracts.js';
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExtendName = exports.getCollectionId = exports.resizeFirstChar = exports.stringify = exports.recursivelyUnwrapPropertyNodes = exports.unwrapPropertyNode = exports.unwrapNode = exports.makeASTImports = exports.getExposedFunctions = exports.ArraySymbol = exports.UnquotedSymbol = exports.MIDDLEWARES_RUNTIME_PATH = exports.PACKAGE_NAME = void 0;
4
- exports.PACKAGE_NAME = 'aeria';
5
- exports.MIDDLEWARES_RUNTIME_PATH = '../../../dist/middlewares/index.js';
6
- exports.UnquotedSymbol = Symbol('unquoted');
7
- exports.ArraySymbol = Symbol('array');
8
- const getExposedFunctions = (functionNodes) => {
1
+ export const PACKAGE_NAME = 'aeria';
2
+ export const MIDDLEWARES_RUNTIME_PATH = '../../../dist/middlewares/index.js';
3
+ export const UnquotedSymbol = Symbol('unquoted');
4
+ export const ArraySymbol = Symbol('array');
5
+ export const getExposedFunctions = (functionNodes) => {
9
6
  return Object.fromEntries(functionNodes.map((node) => [
10
7
  node.name,
11
8
  node.accessCondition,
12
9
  ]));
13
10
  };
14
- exports.getExposedFunctions = getExposedFunctions;
15
- const makeASTImports = (ast, initialImports = {}, options = {
11
+ export const makeASTImports = (ast, initialImports = {}, options = {
16
12
  includeRuntimeOnlyImports: false,
17
13
  }) => {
18
14
  const modifiedSymbols = {};
19
15
  const toImport = ast.reduce((imports, node) => {
20
16
  if (node.kind === 'collection') {
21
17
  if (node.extends) {
22
- const modifiedSymbol = `${node.extends.packageName}${(0, exports.resizeFirstChar)(node.extends.symbolName, true)}`;
18
+ const modifiedSymbol = `${node.extends.packageName}${resizeFirstChar(node.extends.symbolName, true)}`;
23
19
  modifiedSymbols[node.extends.symbolName] = modifiedSymbol;
24
20
  imports[node.extends.importPath] ??= new Set();
25
21
  imports[node.extends.importPath].add(`${node.extends.symbolName} as ${modifiedSymbol}`);
@@ -35,9 +31,9 @@ const makeASTImports = (ast, initialImports = {}, options = {
35
31
  }
36
32
  if (options.includeRuntimeOnlyImports) {
37
33
  if (node.middlewares) {
38
- imports[exports.MIDDLEWARES_RUNTIME_PATH] ??= new Set();
34
+ imports[MIDDLEWARES_RUNTIME_PATH] ??= new Set();
39
35
  for (const middleware of node.middlewares) {
40
- imports[exports.MIDDLEWARES_RUNTIME_PATH].add(middleware);
36
+ imports[MIDDLEWARES_RUNTIME_PATH].add(middleware);
41
37
  }
42
38
  }
43
39
  }
@@ -49,13 +45,11 @@ const makeASTImports = (ast, initialImports = {}, options = {
49
45
  modifiedSymbols,
50
46
  };
51
47
  };
52
- exports.makeASTImports = makeASTImports;
53
- const unwrapNode = (node) => {
48
+ export const unwrapNode = (node) => {
54
49
  const { kind, ...unwrappedNode } = Object.fromEntries(Object.entries(node).filter(([key]) => typeof key === 'string'));
55
50
  return unwrappedNode;
56
51
  };
57
- exports.unwrapNode = unwrapNode;
58
- const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProperties }) => {
52
+ export const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProperties }) => {
59
53
  const propertyOrPropertyItems = 'items' in property
60
54
  ? property.items
61
55
  : property;
@@ -63,19 +57,19 @@ const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProper
63
57
  if ('$ref' in propertyOrPropertyItems) {
64
58
  unwrappedProperty = {
65
59
  ...propertyOrPropertyItems,
66
- $ref: (0, exports.getCollectionId)(propertyOrPropertyItems.$ref),
60
+ $ref: getCollectionId(propertyOrPropertyItems.$ref),
67
61
  };
68
62
  }
69
63
  else if ('type' in propertyOrPropertyItems && propertyOrPropertyItems.type === 'object') {
70
64
  let properties;
71
65
  let additionalProperties;
72
66
  if (nestedProperties) {
73
- properties = (0, exports.recursivelyUnwrapPropertyNodes)(nestedProperties);
67
+ properties = recursivelyUnwrapPropertyNodes(nestedProperties);
74
68
  }
75
69
  if (nestedAdditionalProperties) {
76
70
  additionalProperties = typeof nestedAdditionalProperties === 'boolean'
77
71
  ? nestedAdditionalProperties
78
- : (0, exports.unwrapPropertyNode)(nestedAdditionalProperties);
72
+ : unwrapPropertyNode(nestedAdditionalProperties);
79
73
  }
80
74
  if (properties && additionalProperties) {
81
75
  unwrappedProperty = {
@@ -105,29 +99,27 @@ const unwrapPropertyNode = ({ property, nestedProperties, nestedAdditionalProper
105
99
  }
106
100
  return unwrappedProperty;
107
101
  };
108
- exports.unwrapPropertyNode = unwrapPropertyNode;
109
- const recursivelyUnwrapPropertyNodes = (properties) => {
102
+ export const recursivelyUnwrapPropertyNodes = (properties) => {
110
103
  return Object.entries(properties).reduce((acc, [key, value]) => {
111
104
  if (Array.isArray(value)) {
112
- acc[key] = value.map((propertyNode) => (0, exports.unwrapPropertyNode)(propertyNode));
105
+ acc[key] = value.map((propertyNode) => unwrapPropertyNode(propertyNode));
113
106
  }
114
107
  else {
115
- acc[key] = (0, exports.unwrapPropertyNode)(value);
108
+ acc[key] = unwrapPropertyNode(value);
116
109
  }
117
110
  return acc;
118
111
  }, {});
119
112
  };
120
- exports.recursivelyUnwrapPropertyNodes = recursivelyUnwrapPropertyNodes;
121
113
  const isRecord = (value) => {
122
114
  return !!(value && typeof value === 'object');
123
115
  };
124
- const stringify = (value, parents = []) => {
116
+ export const stringify = (value, parents = []) => {
125
117
  if (Array.isArray(value)) {
126
118
  let arrayString = '[\n';
127
119
  value.map((element) => {
128
120
  const currentParents = [
129
121
  ...parents,
130
- exports.ArraySymbol,
122
+ ArraySymbol,
131
123
  ];
132
124
  arrayString += '\t'.repeat(currentParents.length) +
133
125
  checkQuotes(currentParents, element) + ',\n';
@@ -159,21 +151,17 @@ const stringify = (value, parents = []) => {
159
151
  }
160
152
  }
161
153
  };
162
- exports.stringify = stringify;
163
154
  const checkQuotes = (parents, value) => {
164
- if (value && typeof value === 'object' && exports.UnquotedSymbol in value) {
165
- return value[exports.UnquotedSymbol];
155
+ if (value && typeof value === 'object' && UnquotedSymbol in value) {
156
+ return value[UnquotedSymbol];
166
157
  }
167
- return (0, exports.stringify)(value, parents);
158
+ return stringify(value, parents);
168
159
  };
169
- const resizeFirstChar = (text, capitalize) => {
160
+ export const resizeFirstChar = (text, capitalize) => {
170
161
  if (capitalize === true) {
171
162
  return text.charAt(0).toUpperCase() + text.slice(1);
172
163
  }
173
164
  return text.charAt(0).toLowerCase() + text.slice(1);
174
165
  };
175
- exports.resizeFirstChar = resizeFirstChar;
176
- const getCollectionId = (name) => (0, exports.resizeFirstChar)(name, false);
177
- exports.getCollectionId = getCollectionId;
178
- const getExtendName = (name) => `extend${(0, exports.resizeFirstChar)(name, true)}Collection`;
179
- exports.getExtendName = getExtendName;
166
+ export const getCollectionId = (name) => resizeFirstChar(name, false);
167
+ export const getExtendName = (name) => `extend${resizeFirstChar(name, true)}Collection`;
package/dist/codegen.js CHANGED
@@ -1,42 +1,6 @@
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.generateCode = void 0;
37
- const index_js_1 = require("./codegen/index.js");
38
- const fsPromises = __importStar(require("node:fs/promises"));
39
- const path = __importStar(require("node:path"));
1
+ import { generateContracts, generateExports, generateJSCollections, generateTSCollections } from './codegen/index.js';
2
+ import * as fsPromises from 'node:fs/promises';
3
+ import * as path from 'node:path';
40
4
  const generateFileMap = async (fileTree, outDir = '.') => {
41
5
  const mappedPaths = {};
42
6
  const mapPathTree = async (tree, previousPath) => {
@@ -56,15 +20,15 @@ const generateFileMap = async (fileTree, outDir = '.') => {
56
20
  await mapPathTree(fileTree, outDir);
57
21
  return mappedPaths;
58
22
  };
59
- const generateCode = async (ast, options) => {
60
- const contracts = (0, index_js_1.generateContracts)(ast);
61
- const exports = (0, index_js_1.generateExports)(ast, {
23
+ export const generateCode = async (ast, options) => {
24
+ const contracts = generateContracts(ast);
25
+ const exports = generateExports(ast, {
62
26
  hasContracts: !!contracts,
63
27
  });
64
28
  const fileTree = {
65
29
  ['collections']: {
66
- ['collections.d.ts']: (0, index_js_1.generateTSCollections)(ast),
67
- ['collections.js']: (0, index_js_1.generateJSCollections)(ast),
30
+ ['collections.d.ts']: generateTSCollections(ast),
31
+ ['collections.js']: generateJSCollections(ast),
68
32
  ['index.d.ts']: exports.collections.dts,
69
33
  ['index.js']: exports.collections.js,
70
34
  },
@@ -87,4 +51,3 @@ const generateCode = async (ast, options) => {
87
51
  }
88
52
  return fileStructure;
89
53
  };
90
- exports.generateCode = generateCode;