@ruiapp/rapid-core 0.1.13 → 0.1.15
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/index.js +16 -11
- package/package.json +1 -1
- package/src/core/pluginManager.ts +3 -1
- package/src/dataAccess/entityManager.ts +18 -10
package/dist/index.js
CHANGED
|
@@ -453,7 +453,9 @@ class PluginManager {
|
|
|
453
453
|
/** 初始化插件时调用。 */
|
|
454
454
|
async initPlugins() {
|
|
455
455
|
for (const plugin of this.#plugins) {
|
|
456
|
-
|
|
456
|
+
if (plugin.initPlugin) {
|
|
457
|
+
await plugin.initPlugin(this.#server);
|
|
458
|
+
}
|
|
457
459
|
}
|
|
458
460
|
}
|
|
459
461
|
/** 注册中间件 */
|
|
@@ -1811,6 +1813,17 @@ async function findEntity(server, dataAccessor, options) {
|
|
|
1811
1813
|
const entities = await findEntities(server, dataAccessor, options);
|
|
1812
1814
|
return ___namespace.first(entities);
|
|
1813
1815
|
}
|
|
1816
|
+
async function findById(server, dataAccessor, id) {
|
|
1817
|
+
return await findEntity(server, dataAccessor, {
|
|
1818
|
+
filters: [
|
|
1819
|
+
{
|
|
1820
|
+
operator: "eq",
|
|
1821
|
+
field: "id",
|
|
1822
|
+
value: id,
|
|
1823
|
+
}
|
|
1824
|
+
]
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1814
1827
|
async function replaceFiltersWithFiltersOperator(server, model, filters) {
|
|
1815
1828
|
if (!filters || !filters.length) {
|
|
1816
1829
|
return [];
|
|
@@ -2106,7 +2119,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2106
2119
|
if (!id) {
|
|
2107
2120
|
throw new Error("Id is required when updating an entity.");
|
|
2108
2121
|
}
|
|
2109
|
-
const entity = await
|
|
2122
|
+
const entity = await findById(server, dataAccessor, id);
|
|
2110
2123
|
if (!entity) {
|
|
2111
2124
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
2112
2125
|
}
|
|
@@ -2245,15 +2258,7 @@ class EntityManager {
|
|
|
2245
2258
|
return await findEntity(this.#server, this.#dataAccessor, options);
|
|
2246
2259
|
}
|
|
2247
2260
|
async findById(id) {
|
|
2248
|
-
return await this
|
|
2249
|
-
filters: [
|
|
2250
|
-
{
|
|
2251
|
-
operator: "eq",
|
|
2252
|
-
field: "id",
|
|
2253
|
-
value: id,
|
|
2254
|
-
}
|
|
2255
|
-
]
|
|
2256
|
-
});
|
|
2261
|
+
return await findById(this.#server, this.#dataAccessor, id);
|
|
2257
2262
|
}
|
|
2258
2263
|
async createEntity(options, plugin) {
|
|
2259
2264
|
const model = this.getModel();
|
package/package.json
CHANGED
|
@@ -173,6 +173,22 @@ async function findEntity(
|
|
|
173
173
|
return _.first(entities);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
async function findById(
|
|
177
|
+
server: IRpdServer,
|
|
178
|
+
dataAccessor: IRpdDataAccessor,
|
|
179
|
+
id: any,
|
|
180
|
+
): Promise<any> {
|
|
181
|
+
return await findEntity(server, dataAccessor, {
|
|
182
|
+
filters: [
|
|
183
|
+
{
|
|
184
|
+
operator: "eq",
|
|
185
|
+
field: "id",
|
|
186
|
+
value: id,
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
176
192
|
async function replaceFiltersWithFiltersOperator(
|
|
177
193
|
server: IRpdServer,
|
|
178
194
|
model: RpdDataModel,
|
|
@@ -544,7 +560,7 @@ async function updateEntityById(
|
|
|
544
560
|
throw new Error("Id is required when updating an entity.")
|
|
545
561
|
}
|
|
546
562
|
|
|
547
|
-
const entity = await
|
|
563
|
+
const entity = await findById(server, dataAccessor, id);
|
|
548
564
|
if (!entity) {
|
|
549
565
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
550
566
|
}
|
|
@@ -702,15 +718,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
702
718
|
}
|
|
703
719
|
|
|
704
720
|
async findById(id: any): Promise<TEntity | null> {
|
|
705
|
-
return await this
|
|
706
|
-
filters: [
|
|
707
|
-
{
|
|
708
|
-
operator: "eq",
|
|
709
|
-
field: "id",
|
|
710
|
-
value: id,
|
|
711
|
-
}
|
|
712
|
-
]
|
|
713
|
-
});
|
|
721
|
+
return await findById(this.#server, this.#dataAccessor, id);
|
|
714
722
|
}
|
|
715
723
|
|
|
716
724
|
async createEntity(options: CreateEntityOptions, plugin: RapidPlugin): Promise<TEntity> {
|