@ruiapp/rapid-core 0.1.82 → 0.2.0
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/bootstrapApplicationConfig.d.ts +6 -0
- package/dist/helpers/metaHelper.d.ts +3 -3
- package/dist/index.js +57 -16
- package/dist/plugins/webhooks/pluginConfig.d.ts +1 -0
- package/dist/types.d.ts +19 -1
- package/package.json +1 -1
- package/src/bootstrapApplicationConfig.ts +615 -602
- package/src/core/server.ts +142 -142
- package/src/dataAccess/columnTypeMapper.ts +22 -22
- package/src/dataAccess/dataAccessTypes.ts +151 -151
- package/src/dataAccess/entityManager.ts +1499 -1496
- package/src/dataAccess/entityMapper.ts +100 -100
- package/src/dataAccess/propertyMapper.ts +28 -28
- package/src/deno-std/http/cookie.ts +372 -372
- package/src/helpers/filterHelper.ts +47 -47
- package/src/helpers/metaHelper.ts +80 -76
- package/src/helpers/runCollectionEntityActionHandler.ts +27 -27
- package/src/index.ts +46 -46
- package/src/plugins/auth/AuthPlugin.ts +85 -85
- package/src/plugins/cronJob/CronJobPlugin.ts +112 -112
- package/src/plugins/dataManage/DataManagePlugin.ts +163 -163
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +38 -38
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +22 -22
- package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +146 -146
- package/src/plugins/fileManage/FileManagePlugin.ts +52 -52
- package/src/plugins/fileManage/actionHandlers/downloadFile.ts +44 -44
- package/src/plugins/metaManage/MetaManagePlugin.ts +500 -488
- package/src/plugins/routeManage/RouteManagePlugin.ts +62 -62
- package/src/plugins/sequence/SequencePlugin.ts +136 -136
- package/src/plugins/sequence/SequencePluginTypes.ts +69 -69
- package/src/plugins/sequence/segments/autoIncrement.ts +78 -78
- package/src/plugins/sequence/segments/dayOfMonth.ts +17 -17
- package/src/plugins/sequence/segments/literal.ts +14 -14
- package/src/plugins/sequence/segments/month.ts +17 -17
- package/src/plugins/sequence/segments/parameter.ts +18 -18
- package/src/plugins/sequence/segments/year.ts +17 -17
- package/src/plugins/setting/SettingPlugin.ts +68 -68
- package/src/plugins/setting/SettingPluginTypes.ts +37 -37
- package/src/plugins/stateMachine/StateMachinePlugin.ts +186 -186
- package/src/plugins/stateMachine/StateMachinePluginTypes.ts +48 -48
- package/src/plugins/webhooks/WebhooksPlugin.ts +148 -148
- package/src/plugins/webhooks/pluginConfig.ts +1 -0
- package/src/queryBuilder/queryBuilder.ts +637 -637
- package/src/server.ts +463 -451
- package/src/types.ts +659 -637
- package/src/utilities/errorUtility.ts +15 -15
|
@@ -5,6 +5,7 @@ declare const _default: {
|
|
|
5
5
|
maintainedBy: string;
|
|
6
6
|
namespace: string;
|
|
7
7
|
name: string;
|
|
8
|
+
code: string;
|
|
8
9
|
singularCode: string;
|
|
9
10
|
pluralCode: string;
|
|
10
11
|
schema: string;
|
|
@@ -77,6 +78,7 @@ declare const _default: {
|
|
|
77
78
|
maintainedBy: string;
|
|
78
79
|
namespace: string;
|
|
79
80
|
name: string;
|
|
81
|
+
code: string;
|
|
80
82
|
singularCode: string;
|
|
81
83
|
pluralCode: string;
|
|
82
84
|
schema: string;
|
|
@@ -170,6 +172,7 @@ declare const _default: {
|
|
|
170
172
|
maintainedBy: string;
|
|
171
173
|
namespace: string;
|
|
172
174
|
name: string;
|
|
175
|
+
code: string;
|
|
173
176
|
singularCode: string;
|
|
174
177
|
pluralCode: string;
|
|
175
178
|
schema: string;
|
|
@@ -246,6 +249,7 @@ declare const _default: {
|
|
|
246
249
|
maintainedBy: string;
|
|
247
250
|
namespace: string;
|
|
248
251
|
name: string;
|
|
252
|
+
code: string;
|
|
249
253
|
singularCode: string;
|
|
250
254
|
pluralCode: string;
|
|
251
255
|
schema: string;
|
|
@@ -322,6 +326,7 @@ declare const _default: {
|
|
|
322
326
|
maintainedBy: string;
|
|
323
327
|
namespace: string;
|
|
324
328
|
name: string;
|
|
329
|
+
code: string;
|
|
325
330
|
singularCode: string;
|
|
326
331
|
pluralCode: string;
|
|
327
332
|
schema: string;
|
|
@@ -357,6 +362,7 @@ declare const _default: {
|
|
|
357
362
|
})[];
|
|
358
363
|
indexes?: undefined;
|
|
359
364
|
})[];
|
|
365
|
+
dataDictionaries: any[];
|
|
360
366
|
routes: {
|
|
361
367
|
namespace: string;
|
|
362
368
|
name: string;
|
|
@@ -5,6 +5,6 @@ export declare function isOneRelationProperty(property: RpdDataModelProperty): b
|
|
|
5
5
|
export declare function isManyRelationProperty(property: RpdDataModelProperty): boolean;
|
|
6
6
|
export declare function getEntityProperties(server: IRpdServer, model: RpdDataModel): RpdDataModelProperty[];
|
|
7
7
|
export declare function getEntityPropertiesIncludingBase(server: IRpdServer, model: RpdDataModel): RpdDataModelProperty[];
|
|
8
|
-
export declare function getEntityPropertyByCode(server: IRpdServer, model: RpdDataModel, propertyCode: string): RpdDataModelProperty;
|
|
9
|
-
export declare function getEntityProperty(server: IRpdServer, model: RpdDataModel, predicate: (item: RpdDataModelProperty) => boolean): RpdDataModelProperty;
|
|
10
|
-
export declare function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string): RpdDataModelProperty;
|
|
8
|
+
export declare function getEntityPropertyByCode(server: IRpdServer, model: RpdDataModel, propertyCode: string): RpdDataModelProperty | undefined;
|
|
9
|
+
export declare function getEntityProperty(server: IRpdServer, model: RpdDataModel, predicate: (item: RpdDataModelProperty) => boolean): RpdDataModelProperty | undefined;
|
|
10
|
+
export declare function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string): RpdDataModelProperty | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1407,6 +1407,7 @@ var bootstrapApplicationConfig = {
|
|
|
1407
1407
|
maintainedBy: "metaManager",
|
|
1408
1408
|
namespace: "meta",
|
|
1409
1409
|
name: "model",
|
|
1410
|
+
code: "Model",
|
|
1410
1411
|
singularCode: "model",
|
|
1411
1412
|
pluralCode: "models",
|
|
1412
1413
|
schema: "public",
|
|
@@ -1434,6 +1435,13 @@ var bootstrapApplicationConfig = {
|
|
|
1434
1435
|
type: "text",
|
|
1435
1436
|
required: false,
|
|
1436
1437
|
},
|
|
1438
|
+
{
|
|
1439
|
+
name: "code",
|
|
1440
|
+
code: "code",
|
|
1441
|
+
columnName: "code",
|
|
1442
|
+
type: "text",
|
|
1443
|
+
required: false,
|
|
1444
|
+
},
|
|
1437
1445
|
{
|
|
1438
1446
|
name: "singular code",
|
|
1439
1447
|
code: "singularCode",
|
|
@@ -1547,6 +1555,7 @@ var bootstrapApplicationConfig = {
|
|
|
1547
1555
|
maintainedBy: "metaManager",
|
|
1548
1556
|
namespace: "meta",
|
|
1549
1557
|
name: "property",
|
|
1558
|
+
code: "Property",
|
|
1550
1559
|
singularCode: "property",
|
|
1551
1560
|
pluralCode: "properties",
|
|
1552
1561
|
schema: "public",
|
|
@@ -1717,6 +1726,7 @@ var bootstrapApplicationConfig = {
|
|
|
1717
1726
|
maintainedBy: "metaManager",
|
|
1718
1727
|
namespace: "meta",
|
|
1719
1728
|
name: "data dictionary",
|
|
1729
|
+
code: "DataDictionary",
|
|
1720
1730
|
singularCode: "data_dictionary",
|
|
1721
1731
|
pluralCode: "data_dictionaries",
|
|
1722
1732
|
schema: "public",
|
|
@@ -1808,6 +1818,7 @@ var bootstrapApplicationConfig = {
|
|
|
1808
1818
|
maintainedBy: "metaManager",
|
|
1809
1819
|
namespace: "meta",
|
|
1810
1820
|
name: "data dictionary entry",
|
|
1821
|
+
code: "DataDictionaryEntry",
|
|
1811
1822
|
singularCode: "data_dictionary_entry",
|
|
1812
1823
|
pluralCode: "data_dictionary_entries",
|
|
1813
1824
|
schema: "public",
|
|
@@ -1885,6 +1896,7 @@ var bootstrapApplicationConfig = {
|
|
|
1885
1896
|
maintainedBy: "dataManager",
|
|
1886
1897
|
namespace: "meta",
|
|
1887
1898
|
name: "routes",
|
|
1899
|
+
code: "Route",
|
|
1888
1900
|
singularCode: "route",
|
|
1889
1901
|
pluralCode: "routes",
|
|
1890
1902
|
schema: "public",
|
|
@@ -1957,6 +1969,7 @@ var bootstrapApplicationConfig = {
|
|
|
1957
1969
|
],
|
|
1958
1970
|
},
|
|
1959
1971
|
],
|
|
1972
|
+
dataDictionaries: [],
|
|
1960
1973
|
routes: [
|
|
1961
1974
|
{
|
|
1962
1975
|
namespace: "meta",
|
|
@@ -2262,6 +2275,9 @@ function convertEntityOrderByToRowOrderBy(server, model, baseModel, orderByList)
|
|
|
2262
2275
|
}
|
|
2263
2276
|
if (relationField) {
|
|
2264
2277
|
const relationProperty = getEntityPropertyByCode(server, model, relationField);
|
|
2278
|
+
if (!relationProperty) {
|
|
2279
|
+
throw new Error(`Property '${relationProperty}' was not found in ${model.namespace}.${model.singularCode}`);
|
|
2280
|
+
}
|
|
2265
2281
|
if (!isRelationProperty(relationProperty)) {
|
|
2266
2282
|
throw new Error("orderBy[].relation must be a one-relation property.");
|
|
2267
2283
|
}
|
|
@@ -2318,7 +2334,9 @@ async function findEntities(server, dataAccessor, options) {
|
|
|
2318
2334
|
let relationOptions = options.relations || {};
|
|
2319
2335
|
let relationPropertyCodes = Object.keys(relationOptions) || [];
|
|
2320
2336
|
if (!options.properties || !options.properties.length) {
|
|
2321
|
-
propertiesToSelect = getEntityPropertiesIncludingBase(server, model).filter((property) =>
|
|
2337
|
+
propertiesToSelect = getEntityPropertiesIncludingBase(server, model).filter((property) => {
|
|
2338
|
+
return !isRelationProperty(property) || relationPropertyCodes.includes(property.code);
|
|
2339
|
+
});
|
|
2322
2340
|
}
|
|
2323
2341
|
else {
|
|
2324
2342
|
propertiesToSelect = getEntityPropertiesIncludingBase(server, model).filter((property) => options.properties.includes(property.code) || relationPropertyCodes.includes(property.code));
|
|
@@ -3204,7 +3222,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
3204
3222
|
await server.queryDatabaseObject(`DELETE FROM ${server.queryBuilder.quoteTable({
|
|
3205
3223
|
schema: property.linkSchema,
|
|
3206
3224
|
tableName: property.linkTableName,
|
|
3207
|
-
})} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
|
|
3225
|
+
})} WHERE ${server.queryBuilder.quoteObject(property.selfIdColumnName)} = $1
|
|
3208
3226
|
AND ${server.queryBuilder.quoteObject(property.targetIdColumnName)} <> ALL($2::int[])`, [id, targetIdsToKeep]);
|
|
3209
3227
|
}
|
|
3210
3228
|
else {
|
|
@@ -3473,11 +3491,11 @@ class EntityManager {
|
|
|
3473
3491
|
const command = `INSERT INTO ${queryBuilder.quoteTable({
|
|
3474
3492
|
schema: relationProperty.linkSchema,
|
|
3475
3493
|
tableName: relationProperty.linkTableName,
|
|
3476
|
-
})} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
|
|
3477
|
-
SELECT $1, $2 WHERE NOT EXISTS (
|
|
3478
|
-
SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
|
|
3479
|
-
FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
|
|
3480
|
-
WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
|
|
3494
|
+
})} (${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)})
|
|
3495
|
+
SELECT $1, $2 WHERE NOT EXISTS (
|
|
3496
|
+
SELECT ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}, ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}
|
|
3497
|
+
FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
|
|
3498
|
+
WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2
|
|
3481
3499
|
)`;
|
|
3482
3500
|
const params = [id, relation.id];
|
|
3483
3501
|
await server.queryDatabaseObject(command, params);
|
|
@@ -3517,7 +3535,7 @@ class EntityManager {
|
|
|
3517
3535
|
const { queryBuilder } = server;
|
|
3518
3536
|
if (relationProperty.linkTableName) {
|
|
3519
3537
|
for (const relation of relations) {
|
|
3520
|
-
const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
|
|
3538
|
+
const command = `DELETE FROM ${queryBuilder.quoteTable({ schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName })}
|
|
3521
3539
|
WHERE ${queryBuilder.quoteObject(relationProperty.selfIdColumnName)}=$1 AND ${queryBuilder.quoteObject(relationProperty.targetIdColumnName)}=$2;`;
|
|
3522
3540
|
const params = [id, relation.id];
|
|
3523
3541
|
await server.queryDatabaseObject(command, params);
|
|
@@ -3619,7 +3637,7 @@ class RapidServer {
|
|
|
3619
3637
|
return this.#applicationConfig;
|
|
3620
3638
|
}
|
|
3621
3639
|
appendApplicationConfig(config) {
|
|
3622
|
-
const { models, routes } = config;
|
|
3640
|
+
const { models, dataDictionaries, routes } = config;
|
|
3623
3641
|
if (models) {
|
|
3624
3642
|
for (const model of models) {
|
|
3625
3643
|
const originalModel = lodash.find(this.#applicationConfig.models, (item) => item.singularCode == model.singularCode);
|
|
@@ -3642,6 +3660,19 @@ class RapidServer {
|
|
|
3642
3660
|
}
|
|
3643
3661
|
}
|
|
3644
3662
|
}
|
|
3663
|
+
if (dataDictionaries) {
|
|
3664
|
+
for (const dataDictionary of dataDictionaries) {
|
|
3665
|
+
const originalDataDictionary = lodash.find(this.#applicationConfig.dataDictionaries, (item) => item.code == dataDictionary.code);
|
|
3666
|
+
if (originalDataDictionary) {
|
|
3667
|
+
originalDataDictionary.name = dataDictionary.name;
|
|
3668
|
+
originalDataDictionary.description = dataDictionary.description;
|
|
3669
|
+
originalDataDictionary.entries = dataDictionary.entries;
|
|
3670
|
+
}
|
|
3671
|
+
else {
|
|
3672
|
+
this.#applicationConfig.dataDictionaries.push(dataDictionary);
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3645
3676
|
if (routes) {
|
|
3646
3677
|
for (const route of routes) {
|
|
3647
3678
|
const originalRoute = lodash.find(this.#applicationConfig.routes, (item) => item.code == route.code);
|
|
@@ -4114,8 +4145,9 @@ class MetaManager {
|
|
|
4114
4145
|
const logger = server.getLogger();
|
|
4115
4146
|
try {
|
|
4116
4147
|
logger.info("Loading meta of models...");
|
|
4117
|
-
const models = await
|
|
4118
|
-
|
|
4148
|
+
const models = await listDataModels(server);
|
|
4149
|
+
const dataDictionaries = await listDataDictionaries(server);
|
|
4150
|
+
server.appendApplicationConfig({ models, dataDictionaries });
|
|
4119
4151
|
}
|
|
4120
4152
|
catch (error) {
|
|
4121
4153
|
logger.crit("Failed to load meta of models.", { error });
|
|
@@ -4175,7 +4207,7 @@ async function handleEntityDeleteEvent(server, sender, payload) {
|
|
|
4175
4207
|
}
|
|
4176
4208
|
}
|
|
4177
4209
|
}
|
|
4178
|
-
function
|
|
4210
|
+
function listDataModels(server) {
|
|
4179
4211
|
const entityManager = server.getEntityManager("model");
|
|
4180
4212
|
const model = entityManager.getModel();
|
|
4181
4213
|
const properties = getEntityPropertiesIncludingBase(server, model);
|
|
@@ -4183,6 +4215,14 @@ function listCollections(server, applicationConfig) {
|
|
|
4183
4215
|
properties: properties.map((item) => item.code),
|
|
4184
4216
|
});
|
|
4185
4217
|
}
|
|
4218
|
+
function listDataDictionaries(server) {
|
|
4219
|
+
const dataDictionaryManager = server.getEntityManager("data_dictionary");
|
|
4220
|
+
const model = dataDictionaryManager.getModel();
|
|
4221
|
+
const properties = getEntityPropertiesIncludingBase(server, model);
|
|
4222
|
+
return dataDictionaryManager.findEntities({
|
|
4223
|
+
properties: properties.map((item) => item.code),
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4186
4226
|
async function syncDatabaseSchema(server, applicationConfig) {
|
|
4187
4227
|
const logger = server.getLogger();
|
|
4188
4228
|
logger.info("Synchronizing database schema...");
|
|
@@ -4198,7 +4238,7 @@ async function syncDatabaseSchema(server, applicationConfig) {
|
|
|
4198
4238
|
await server.queryDatabaseObject(`CREATE TABLE IF NOT EXISTS ${queryBuilder.quoteTable(model)} ()`, []);
|
|
4199
4239
|
}
|
|
4200
4240
|
}
|
|
4201
|
-
const sqlQueryColumnInformations = `SELECT table_schema, table_name, column_name, data_type, udt_name, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale
|
|
4241
|
+
const sqlQueryColumnInformations = `SELECT table_schema, table_name, column_name, data_type, udt_name, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale
|
|
4202
4242
|
FROM information_schema.columns;`;
|
|
4203
4243
|
const columnsInDb = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
|
|
4204
4244
|
for (const model of applicationConfig.models) {
|
|
@@ -5473,6 +5513,7 @@ var pluginConfig = {
|
|
|
5473
5513
|
],
|
|
5474
5514
|
},
|
|
5475
5515
|
],
|
|
5516
|
+
dataDictionaries: [],
|
|
5476
5517
|
routes: [],
|
|
5477
5518
|
};
|
|
5478
5519
|
|
|
@@ -7401,9 +7442,9 @@ class EntityAccessControlPlugin {
|
|
|
7401
7442
|
if (!userId) {
|
|
7402
7443
|
return;
|
|
7403
7444
|
}
|
|
7404
|
-
const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
|
|
7405
|
-
inner join oc_role_sys_action_links ra on a.id = ra.action_id
|
|
7406
|
-
inner join oc_role_user_links ru on ru.role_id = ra.role_id
|
|
7445
|
+
const actions = await server.queryDatabaseObject(`select distinct a.* from sys_actions a
|
|
7446
|
+
inner join oc_role_sys_action_links ra on a.id = ra.action_id
|
|
7447
|
+
inner join oc_role_user_links ru on ru.role_id = ra.role_id
|
|
7407
7448
|
where ru.user_id = $1;`, [userId]);
|
|
7408
7449
|
routeContext.state.allowedActions = actions.map((item) => item.code);
|
|
7409
7450
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -154,12 +154,14 @@ export interface RpdApplicationConfig {
|
|
|
154
154
|
code?: string;
|
|
155
155
|
name?: string;
|
|
156
156
|
models: RpdDataModel[];
|
|
157
|
+
dataDictionaries: RpdDataDictionary[];
|
|
157
158
|
routes: RpdRoute[];
|
|
158
159
|
}
|
|
159
160
|
export interface RpdDataModel {
|
|
160
161
|
maintainedBy?: string;
|
|
161
162
|
name: string;
|
|
162
163
|
namespace: string;
|
|
164
|
+
code?: string;
|
|
163
165
|
singularCode: string;
|
|
164
166
|
pluralCode: string;
|
|
165
167
|
schema?: string;
|
|
@@ -283,11 +285,19 @@ export type RpdDataDictionary = {
|
|
|
283
285
|
/**
|
|
284
286
|
* 字典名称
|
|
285
287
|
*/
|
|
288
|
+
name?: string;
|
|
289
|
+
/**
|
|
290
|
+
* 描述
|
|
291
|
+
*/
|
|
286
292
|
description?: string;
|
|
287
293
|
/**
|
|
288
294
|
* 字典项值类型
|
|
289
295
|
*/
|
|
290
|
-
|
|
296
|
+
valueType: "string" | "integer";
|
|
297
|
+
/**
|
|
298
|
+
* 字典级别
|
|
299
|
+
*/
|
|
300
|
+
level: "sys" | "app" | "user";
|
|
291
301
|
/**
|
|
292
302
|
* 字典项
|
|
293
303
|
*/
|
|
@@ -305,6 +315,14 @@ export type RpdDataDictionaryEntry = {
|
|
|
305
315
|
* 值
|
|
306
316
|
*/
|
|
307
317
|
value: string;
|
|
318
|
+
/**
|
|
319
|
+
* 颜色
|
|
320
|
+
*/
|
|
321
|
+
color?: string;
|
|
322
|
+
/**
|
|
323
|
+
* 图标
|
|
324
|
+
*/
|
|
325
|
+
icon?: string;
|
|
308
326
|
/**
|
|
309
327
|
* 描述
|
|
310
328
|
*/
|