@apso/cli 0.42.0 → 0.42.1
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/lib/apsorc-parser.d.ts +11 -0
- package/dist/lib/apsorc-parser.js +41 -3
- package/npm-shrinkwrap.json +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -71,6 +71,17 @@ export declare class ApsorcNamingError extends Error {
|
|
|
71
71
|
* schema builder runs the same rules, so a schema that passes there passes here.
|
|
72
72
|
*/
|
|
73
73
|
export declare const assertCodegenSafeNames: (apsorc: Pick<ApsorcType, "entities" | "relationships">) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Drop indexes the database cannot create alongside another. TypeORM names an
|
|
76
|
+
* index from its table and columns only, so a plain and a unique index on the
|
|
77
|
+
* same columns get one name and the second CREATE fails, rolling back the
|
|
78
|
+
* schema (prod svc 52: Warehouse.manager_email). The unique index also serves
|
|
79
|
+
* lookups, so it is kept; exact duplicates are dropped too.
|
|
80
|
+
*
|
|
81
|
+
* @param {Entity} entity - An entity from .apsorc.
|
|
82
|
+
* @returns {Entity} The entity, with a filtered copy of its indexes when needed.
|
|
83
|
+
*/
|
|
84
|
+
export declare const dedupeIndexes: (entity: Entity) => Entity;
|
|
74
85
|
export declare const parseApsorcV2: (apsorc: ApsorcType) => ParsedApsorcData;
|
|
75
86
|
export declare const parseApsorc: () => ParsedApsorc;
|
|
76
87
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findConfigPath = exports.readApsorcFile = exports.parseApsorc = exports.parseApsorcV2 = exports.assertCodegenSafeNames = exports.ApsorcNamingError = exports.parseApsorcV1 = exports.ApiType = void 0;
|
|
3
|
+
exports.findConfigPath = exports.readApsorcFile = exports.parseApsorc = exports.parseApsorcV2 = exports.dedupeIndexes = exports.assertCodegenSafeNames = exports.ApsorcNamingError = exports.parseApsorcV1 = exports.ApiType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
@@ -55,11 +55,46 @@ const assertCodegenSafeNames = (apsorc) => {
|
|
|
55
55
|
throw new ApsorcNamingError(`${error.message}${more > 0 ? ` (${more} more error${more === 1 ? "" : "s"})` : ""} Run "apso schema lint" to see every issue, or "apso schema lint --fix" to apply the safe fixes.`, error.rule, error.entity || "", error.field);
|
|
56
56
|
};
|
|
57
57
|
exports.assertCodegenSafeNames = assertCodegenSafeNames;
|
|
58
|
+
const columns = (fields) => fields.join(",");
|
|
59
|
+
/**
|
|
60
|
+
* Drop indexes the database cannot create alongside another. TypeORM names an
|
|
61
|
+
* index from its table and columns only, so a plain and a unique index on the
|
|
62
|
+
* same columns get one name and the second CREATE fails, rolling back the
|
|
63
|
+
* schema (prod svc 52: Warehouse.manager_email). The unique index also serves
|
|
64
|
+
* lookups, so it is kept; exact duplicates are dropped too.
|
|
65
|
+
*
|
|
66
|
+
* @param {Entity} entity - An entity from .apsorc.
|
|
67
|
+
* @returns {Entity} The entity, with a filtered copy of its indexes when needed.
|
|
68
|
+
*/
|
|
69
|
+
const dedupeIndexes = (entity) => {
|
|
70
|
+
var _a;
|
|
71
|
+
if (!((_a = entity.indexes) === null || _a === void 0 ? void 0 : _a.length))
|
|
72
|
+
return entity;
|
|
73
|
+
const uniqueColumns = new Set(entity.indexes
|
|
74
|
+
.filter((index) => index.unique)
|
|
75
|
+
.map((index) => columns(index.fields)));
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
const indexes = entity.indexes.filter((index) => {
|
|
78
|
+
const key = `${columns(index.fields)}|${index.unique ? "unique" : ""}`;
|
|
79
|
+
if (seen.has(key) ||
|
|
80
|
+
(!index.unique && uniqueColumns.has(columns(index.fields))))
|
|
81
|
+
return false;
|
|
82
|
+
seen.add(key);
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
return indexes.length === entity.indexes.length
|
|
86
|
+
? entity
|
|
87
|
+
: { ...entity, indexes };
|
|
88
|
+
};
|
|
89
|
+
exports.dedupeIndexes = dedupeIndexes;
|
|
58
90
|
const parseApsorcV2 = (apsorc) => {
|
|
59
91
|
const { entities, relationships: apsoRelationships } = apsorc;
|
|
60
92
|
(0, exports.assertCodegenSafeNames)(apsorc);
|
|
61
93
|
const relationshipMap = (0, relationships_1.parseRelationships)(apsoRelationships);
|
|
62
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
entities: entities.map((entity) => (0, exports.dedupeIndexes)(entity)),
|
|
96
|
+
relationshipMap,
|
|
97
|
+
};
|
|
63
98
|
};
|
|
64
99
|
exports.parseApsorcV2 = parseApsorcV2;
|
|
65
100
|
const parseRc = () => {
|
|
@@ -156,7 +191,10 @@ const readApsorcFile = () => {
|
|
|
156
191
|
if (!configPath) {
|
|
157
192
|
throw new Error("No .apsorc found in this directory or any parent.");
|
|
158
193
|
}
|
|
159
|
-
return {
|
|
194
|
+
return {
|
|
195
|
+
configPath,
|
|
196
|
+
apsorc: JSON.parse(fs.readFileSync(configPath).toString()),
|
|
197
|
+
};
|
|
160
198
|
};
|
|
161
199
|
exports.readApsorcFile = readApsorcFile;
|
|
162
200
|
const findConfigPath = () => {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@apso/cli",
|
|
9
|
-
"version": "0.42.
|
|
9
|
+
"version": "0.42.1",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@apso/schema-tools": "^0.2.0",
|
package/oclif.manifest.json
CHANGED