@koalarx/nest 3.0.7 → 3.0.9
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/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
[](https://bun.sh)
|
|
13
13
|
[](https://www.typescriptlang.org/)
|
|
14
14
|
[](https://www.npmjs.com/package/@koalarx/nest-cli)
|
|
15
|
-
[](https://marketplace.visualstudio.com/items?itemName=koalarx.koala-
|
|
15
|
+
[](https://marketplace.visualstudio.com/items?itemName=koalarx.koala-nest-mcp-docs)
|
|
16
16
|
[](https://nest.koalarx.com/)
|
|
17
17
|
|
|
18
18
|
</div>
|
|
@@ -25,7 +25,7 @@ Acesse a documentação completa e interativa em: **[nest.koalarx.com](https://n
|
|
|
25
25
|
|
|
26
26
|
Acelere seu desenvolvimento com a **extensão oficial para VS Code**! Toda a documentação do Koala Nest integrada diretamente no GitHub Copilot através do Model Context Protocol.
|
|
27
27
|
|
|
28
|
-
**[📦 Instalar Extensão](https://marketplace.visualstudio.com/items?itemName=koalarx.koala-
|
|
28
|
+
**[📦 Instalar Extensão](https://marketplace.visualstudio.com/items?itemName=koalarx.koala-nest-mcp-docs)**
|
|
29
29
|
|
|
30
30
|
Basta instalar e perguntar ao Copilot sobre o Koala Nest - ele terá acesso instantâneo à documentação oficial!
|
|
31
31
|
|
|
@@ -19,6 +19,7 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
|
|
|
19
19
|
private readonly _modelName;
|
|
20
20
|
private readonly _include?;
|
|
21
21
|
constructor({ context, modelName, include, }: RepositoryInitProps<TEntity, TContext>);
|
|
22
|
+
private getPropNameFromEntitySource;
|
|
22
23
|
private listRelationEntities;
|
|
23
24
|
private listToRelationActionList;
|
|
24
25
|
private entityToPrisma;
|
|
@@ -27,7 +28,6 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
|
|
|
27
28
|
private orphanRemoval;
|
|
28
29
|
private getIdPropName;
|
|
29
30
|
private getInclude;
|
|
30
|
-
private getPropNameFromEntitySource;
|
|
31
31
|
private persistRelations;
|
|
32
32
|
protected context(transactionalClient?: TContext): TContext[TModelKey];
|
|
33
33
|
protected findById(id: IComparableId): Promise<TEntity | null>;
|
|
@@ -16,6 +16,21 @@ class RepositoryBase {
|
|
|
16
16
|
this._modelName = modelName;
|
|
17
17
|
this._include = include;
|
|
18
18
|
}
|
|
19
|
+
getPropNameFromEntitySource(source, entity) {
|
|
20
|
+
return Object.keys(source).find((key) => {
|
|
21
|
+
const propDefinitions = auto_mapping_list_1.AutoMappingList.getPropDefinitions(source.constructor, key);
|
|
22
|
+
if (propDefinitions) {
|
|
23
|
+
if (propDefinitions.type === entity.name) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
else if (source[key] instanceof list_1.List) {
|
|
27
|
+
const list = source[key];
|
|
28
|
+
return list.entityType?.name === entity.name;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
19
34
|
listRelationEntities(entity) {
|
|
20
35
|
const relationEntities = [];
|
|
21
36
|
Object.keys(entity).forEach((key) => {
|
|
@@ -23,16 +38,13 @@ class RepositoryBase {
|
|
|
23
38
|
const list = entity[key];
|
|
24
39
|
list.toArray('added').forEach((item) => {
|
|
25
40
|
relationEntities.push(item);
|
|
26
|
-
relationEntities.push(...this.listRelationEntities(item));
|
|
27
41
|
});
|
|
28
42
|
list.toArray('updated').forEach((item) => {
|
|
29
43
|
relationEntities.push(item);
|
|
30
|
-
relationEntities.push(...this.listRelationEntities(item));
|
|
31
44
|
});
|
|
32
45
|
}
|
|
33
46
|
else if (entity[key] instanceof entity_base_1.EntityBase) {
|
|
34
47
|
relationEntities.push(entity[key]);
|
|
35
|
-
relationEntities.push(...this.listRelationEntities(entity[key]));
|
|
36
48
|
}
|
|
37
49
|
});
|
|
38
50
|
return relationEntities;
|
|
@@ -47,6 +59,7 @@ class RepositoryBase {
|
|
|
47
59
|
const entityInstance = list.entityType;
|
|
48
60
|
const modelName = entityInstance.name;
|
|
49
61
|
const parentModelName = entity.constructor.name;
|
|
62
|
+
const parentPropName = this.getPropNameFromEntitySource(new entityInstance(), entity.constructor) ?? parentModelName;
|
|
50
63
|
if (modelName) {
|
|
51
64
|
list.toArray('removed').forEach((item) => {
|
|
52
65
|
relationDeletes.push({
|
|
@@ -63,7 +76,7 @@ class RepositoryBase {
|
|
|
63
76
|
schema: {
|
|
64
77
|
data: {
|
|
65
78
|
...this.entityToPrisma(item),
|
|
66
|
-
[
|
|
79
|
+
[parentPropName]: {
|
|
67
80
|
connect: {
|
|
68
81
|
[this.getIdPropName(entity)]: entity[this.getIdPropName(entity)],
|
|
69
82
|
},
|
|
@@ -119,7 +132,7 @@ class RepositoryBase {
|
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
|
-
else {
|
|
135
|
+
else if (!Array.isArray(entity[key])) {
|
|
123
136
|
prismaSchema[key] = entity[key];
|
|
124
137
|
}
|
|
125
138
|
});
|
|
@@ -165,21 +178,6 @@ class RepositoryBase {
|
|
|
165
178
|
});
|
|
166
179
|
return result;
|
|
167
180
|
}
|
|
168
|
-
getPropNameFromEntitySource(source, entity) {
|
|
169
|
-
return Object.keys(source).find((key) => {
|
|
170
|
-
const propDefinitions = auto_mapping_list_1.AutoMappingList.getPropDefinitions(source.constructor, key);
|
|
171
|
-
if (propDefinitions) {
|
|
172
|
-
if (propDefinitions.type === entity.name) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
else if (source[key] instanceof list_1.List) {
|
|
176
|
-
const list = source[key];
|
|
177
|
-
return list.entityType?.name === entity.name;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
181
|
persistRelations(transaction, entity) {
|
|
184
182
|
const { relationCreates, relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
|
|
185
183
|
return Promise.all([
|
|
@@ -188,18 +186,18 @@ class RepositoryBase {
|
|
|
188
186
|
.then((response) => {
|
|
189
187
|
return Promise.all(relationCreate.relations.map((relation) => {
|
|
190
188
|
const relationPropName = this.getPropNameFromEntitySource(relation, relationCreate.entityInstance);
|
|
191
|
-
if (
|
|
192
|
-
|
|
189
|
+
if (relationPropName) {
|
|
190
|
+
const relationEntity = this.createEntity(response, relationCreate.entityInstance);
|
|
191
|
+
relationEntity._action = entity_base_1.EntityActionType.create;
|
|
192
|
+
relation[relationPropName] = relationEntity;
|
|
193
193
|
}
|
|
194
|
-
const relationEntity = this.createEntity(response, relationCreate.entityInstance);
|
|
195
|
-
relationEntity._action = entity_base_1.EntityActionType.create;
|
|
196
|
-
relation[relationPropName] = relationEntity;
|
|
197
194
|
return transaction[(0, KlString_1.toCamelCase)(relation.constructor.name)]
|
|
198
195
|
.create({
|
|
199
196
|
data: this.entityToPrisma(relation),
|
|
197
|
+
select: { [this.getIdPropName(relation)]: true },
|
|
200
198
|
})
|
|
201
199
|
.then((response) => {
|
|
202
|
-
|
|
200
|
+
relation[this.getIdPropName(relation)] =
|
|
203
201
|
response[this.getIdPropName(relation)];
|
|
204
202
|
return this.persistRelations(transaction, relation);
|
|
205
203
|
});
|