@apso/cli 0.47.4 → 0.47.6
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Entity } from "./types/entity";
|
|
2
|
-
import { ApsorcRelationship, RelationshipMap } from "./types/relationship";
|
|
2
|
+
import { ApsorcRelationship, Relationship, RelationshipMap } from "./types/relationship";
|
|
3
3
|
import { AuthConfig } from "./types/auth";
|
|
4
4
|
import { TargetLanguage } from "./types/generator";
|
|
5
5
|
export declare enum ApiType {
|
|
@@ -82,6 +82,17 @@ export declare const assertCodegenSafeNames: (apsorc: Pick<ApsorcType, "entities
|
|
|
82
82
|
* @returns {Entity} The entity, with a filtered copy of its indexes when needed.
|
|
83
83
|
*/
|
|
84
84
|
export declare const dedupeIndexes: (entity: Entity) => Entity;
|
|
85
|
+
/**
|
|
86
|
+
* Drop a "uniques" entry on exactly the foreign key column of a OneToOne the
|
|
87
|
+
* entity owns. The relationship already makes that column UNIQUE (TypeORM's
|
|
88
|
+
* REL_ constraint), so a second constraint would only duplicate it. Composite
|
|
89
|
+
* entries that include the column are kept. `apso schema lint` warns about it.
|
|
90
|
+
*
|
|
91
|
+
* @param {Entity} entity - An entity from .apsorc.
|
|
92
|
+
* @param {Relationship[]} relationships - The entity's parsed relationships.
|
|
93
|
+
* @returns {Entity} The entity, with a filtered copy of its uniques when needed.
|
|
94
|
+
*/
|
|
95
|
+
export declare const dedupeOneToOneUniques: (entity: Entity, relationships?: Relationship[]) => Entity;
|
|
85
96
|
export declare const parseApsorcV2: (apsorc: ApsorcType) => ParsedApsorcData;
|
|
86
97
|
export declare const parseApsorc: () => ParsedApsorc;
|
|
87
98
|
/**
|
|
@@ -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.dedupeIndexes = exports.assertCodegenSafeNames = exports.ApsorcNamingError = exports.parseApsorcV1 = exports.ApiType = void 0;
|
|
3
|
+
exports.findConfigPath = exports.readApsorcFile = exports.parseApsorc = exports.parseApsorcV2 = exports.dedupeOneToOneUniques = 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"));
|
|
@@ -87,12 +87,37 @@ const dedupeIndexes = (entity) => {
|
|
|
87
87
|
: { ...entity, indexes };
|
|
88
88
|
};
|
|
89
89
|
exports.dedupeIndexes = dedupeIndexes;
|
|
90
|
+
/**
|
|
91
|
+
* Drop a "uniques" entry on exactly the foreign key column of a OneToOne the
|
|
92
|
+
* entity owns. The relationship already makes that column UNIQUE (TypeORM's
|
|
93
|
+
* REL_ constraint), so a second constraint would only duplicate it. Composite
|
|
94
|
+
* entries that include the column are kept. `apso schema lint` warns about it.
|
|
95
|
+
*
|
|
96
|
+
* @param {Entity} entity - An entity from .apsorc.
|
|
97
|
+
* @param {Relationship[]} relationships - The entity's parsed relationships.
|
|
98
|
+
* @returns {Entity} The entity, with a filtered copy of its uniques when needed.
|
|
99
|
+
*/
|
|
100
|
+
const dedupeOneToOneUniques = (entity, relationships = []) => {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!((_a = entity.uniques) === null || _a === void 0 ? void 0 : _a.length))
|
|
103
|
+
return entity;
|
|
104
|
+
const owned = new Set(relationships
|
|
105
|
+
.filter((r) => r.type === "OneToOne" && r.join)
|
|
106
|
+
.map((r) => (0, relationships_1.getRelationshipIdField)(r)));
|
|
107
|
+
const uniques = entity.uniques.filter((u) => !(u.fields.length === 1 && owned.has(u.fields[0])));
|
|
108
|
+
return uniques.length === entity.uniques.length
|
|
109
|
+
? entity
|
|
110
|
+
: { ...entity, uniques };
|
|
111
|
+
};
|
|
112
|
+
exports.dedupeOneToOneUniques = dedupeOneToOneUniques;
|
|
90
113
|
const parseApsorcV2 = (apsorc) => {
|
|
91
|
-
|
|
114
|
+
// A raw .apsorc may omit "relationships" (fresh scaffolds do); parseRc
|
|
115
|
+
// defaults it, but migrate and verify read the file directly.
|
|
116
|
+
const { entities, relationships: apsoRelationships = [] } = apsorc;
|
|
92
117
|
(0, exports.assertCodegenSafeNames)(apsorc);
|
|
93
118
|
const relationshipMap = (0, relationships_1.parseRelationships)(apsoRelationships);
|
|
94
119
|
return {
|
|
95
|
-
entities: entities.map((entity) => (0, exports.dedupeIndexes)(entity)),
|
|
120
|
+
entities: entities.map((entity) => (0, exports.dedupeOneToOneUniques)((0, exports.dedupeIndexes)(entity), relationshipMap[entity.name])),
|
|
96
121
|
relationshipMap,
|
|
97
122
|
};
|
|
98
123
|
};
|
|
@@ -78,10 +78,20 @@ class TypeScriptGenerator extends base_1.BaseGenerator {
|
|
|
78
78
|
const primaryKeyType = entity.primaryKeyType || "serial";
|
|
79
79
|
const relationshipsForTemplate = (0, relationships_1.getRelationshipForTemplate)(name, relationships, allEntities);
|
|
80
80
|
const entitiesToImport = (0, relationships_1.getRelationshipsForImport)(name, relationshipsForTemplate);
|
|
81
|
+
// A OneToOne's FK column has no property of its own on the entity, so
|
|
82
|
+
// @Index/@Unique name the relation property; TypeORM resolves it to the
|
|
83
|
+
// join column (workspaceId -> workspace).
|
|
84
|
+
const oneToOneColumns = new Map(relationshipsForTemplate
|
|
85
|
+
.filter((r) => r.type === "OneToOne" && r.joinTable)
|
|
86
|
+
.map((r) => [r.camelCasedId, r.relationshipName]));
|
|
87
|
+
const toProperties = (list = []) => list.map((c) => ({
|
|
88
|
+
...c,
|
|
89
|
+
fields: c.fields.map((f) => { var _a; return (_a = oneToOneColumns.get(f)) !== null && _a !== void 0 ? _a : f; }),
|
|
90
|
+
}));
|
|
81
91
|
const data = {
|
|
82
92
|
name,
|
|
83
|
-
indexes: indexes
|
|
84
|
-
uniques: uniques
|
|
93
|
+
indexes: toProperties(indexes),
|
|
94
|
+
uniques: toProperties(uniques),
|
|
85
95
|
createPrimaryKey,
|
|
86
96
|
primaryKeyType,
|
|
87
97
|
snakeCasedName: (0, casing_1.snakeCase)(name),
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.6",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@apso/cli",
|
|
9
|
-
"version": "0.47.
|
|
9
|
+
"version": "0.47.6",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@apso/schema-tools": "^0.2.
|
|
12
|
+
"@apso/schema-tools": "^0.2.2",
|
|
13
13
|
"@biomejs/biome": "^1.9.4",
|
|
14
14
|
"@electric-sql/pglite": "^0.2.17",
|
|
15
15
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
@@ -149,9 +149,9 @@
|
|
|
149
149
|
"license": "MIT"
|
|
150
150
|
},
|
|
151
151
|
"node_modules/@apso/schema-tools": {
|
|
152
|
-
"version": "0.2.
|
|
153
|
-
"resolved": "https://registry.npmjs.org/@apso/schema-tools/-/schema-tools-0.2.
|
|
154
|
-
"integrity": "sha512-
|
|
152
|
+
"version": "0.2.2",
|
|
153
|
+
"resolved": "https://registry.npmjs.org/@apso/schema-tools/-/schema-tools-0.2.2.tgz",
|
|
154
|
+
"integrity": "sha512-qLz49EyG6hwWMzjzwxp9L0+Ou7EAi7lu6TaxrJixqPm7/J8EMWzBePssmjTE6eotw9qMZNnh1dZ/ky8a9to1rw==",
|
|
155
155
|
"license": "Apache-2.0",
|
|
156
156
|
"dependencies": {
|
|
157
157
|
"pluralize": "^8.0.0"
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.6",
|
|
4
4
|
"mcpName": "io.github.apsoai/apso",
|
|
5
5
|
"description": "Apso CLI",
|
|
6
6
|
"author": "Apso by Mavric - @mavric",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"/oclif.manifest.json"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@apso/schema-tools": "^0.2.
|
|
27
|
+
"@apso/schema-tools": "^0.2.2",
|
|
28
28
|
"@biomejs/biome": "^1.9.4",
|
|
29
29
|
"@electric-sql/pglite": "^0.2.17",
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.29.0",
|