@ruiapp/rapid-configure-tools 0.5.3 → 0.6.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/mod.js +107 -1
- package/dist/rapid-models-updater/PageUpdater.d.ts +4 -0
- package/dist/rapid-models-updater/mod.d.ts +2 -1
- package/dist/rapid-models-updater/types.d.ts +15 -1
- package/package.json +3 -3
- package/src/rapid-models-updater/AppUpdater.ts +1 -1
- package/src/rapid-models-updater/PageUpdater.ts +115 -0
- package/src/rapid-models-updater/mod.ts +10 -1
- package/src/rapid-models-updater/types.ts +17 -1
package/dist/mod.js
CHANGED
|
@@ -564,7 +564,7 @@ class RapidUpdater {
|
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
for (const entityToSave of entitiesToSave) {
|
|
567
|
-
if (!modelUpdater.relationFields) {
|
|
567
|
+
if (!modelUpdater.relationFields || !modelUpdater.relationFields.length) {
|
|
568
568
|
continue;
|
|
569
569
|
}
|
|
570
570
|
console.log(`update relation fields of ${modelUpdater.modelType} ${modelUpdater.inputTitlePrinter(entityToSave)}`);
|
|
@@ -908,13 +908,114 @@ function newPropertyUpdater(rapidConfigApi) {
|
|
|
908
908
|
return propertyUpdater;
|
|
909
909
|
}
|
|
910
910
|
|
|
911
|
+
function convertInputToEntity(input) {
|
|
912
|
+
const inputEntity = {
|
|
913
|
+
subSystem: input.subSystem,
|
|
914
|
+
appCode: input.appCode,
|
|
915
|
+
code: input.code,
|
|
916
|
+
parentCode: input.parentCode,
|
|
917
|
+
routePath: input.routePath,
|
|
918
|
+
name: input.name,
|
|
919
|
+
title: input.title,
|
|
920
|
+
permissionCheck: input.permissionCheck,
|
|
921
|
+
config: {
|
|
922
|
+
view: input.view,
|
|
923
|
+
stores: input.stores,
|
|
924
|
+
eventSubscriptions: input.eventSubscriptions,
|
|
925
|
+
functions: input.functions,
|
|
926
|
+
$i18n: input.$i18n,
|
|
927
|
+
$locales: input.$locales,
|
|
928
|
+
},
|
|
929
|
+
};
|
|
930
|
+
return inputEntity;
|
|
931
|
+
}
|
|
932
|
+
function newPageUpdater(rapidConfigApi) {
|
|
933
|
+
const pageUpdater = {
|
|
934
|
+
modelType: "page",
|
|
935
|
+
relationFields: [],
|
|
936
|
+
entityBatchMode: false,
|
|
937
|
+
inputTitlePrinter(input) {
|
|
938
|
+
return input.code;
|
|
939
|
+
},
|
|
940
|
+
entityKeyGetter(input) {
|
|
941
|
+
return input.code;
|
|
942
|
+
},
|
|
943
|
+
async entitySingleFinder(entityKey) {
|
|
944
|
+
const res = await rapidConfigApi.post(`meta/pages/operations/find`, {
|
|
945
|
+
filters: [
|
|
946
|
+
{
|
|
947
|
+
operator: "eq",
|
|
948
|
+
field: "code",
|
|
949
|
+
value: entityKey,
|
|
950
|
+
},
|
|
951
|
+
],
|
|
952
|
+
});
|
|
953
|
+
const entities = res.data.list;
|
|
954
|
+
if (entities && entities.length) {
|
|
955
|
+
return entities[0];
|
|
956
|
+
}
|
|
957
|
+
return null;
|
|
958
|
+
},
|
|
959
|
+
entityExistensePredicate(input, entity) {
|
|
960
|
+
return entity.code === input.code;
|
|
961
|
+
},
|
|
962
|
+
isEntityChanged(input, remoteEntity) {
|
|
963
|
+
const inputEntity = convertInputToEntity(input);
|
|
964
|
+
const changedFieldNames = detectChangedFields(inputEntity, remoteEntity, [
|
|
965
|
+
"subSystem",
|
|
966
|
+
"appCode",
|
|
967
|
+
"code",
|
|
968
|
+
"parentCode",
|
|
969
|
+
"routePath",
|
|
970
|
+
"name",
|
|
971
|
+
"title",
|
|
972
|
+
"config",
|
|
973
|
+
"permissionCheck",
|
|
974
|
+
]);
|
|
975
|
+
if (changedFieldNames.length) {
|
|
976
|
+
console.log(`${this.modelType} ${this.inputTitlePrinter(inputEntity)} changed with these fields:`, changedFieldNames);
|
|
977
|
+
}
|
|
978
|
+
return changedFieldNames.length > 0;
|
|
979
|
+
},
|
|
980
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
981
|
+
async createEntity(input, mainEntity, inputIndex) {
|
|
982
|
+
const createEntityInput = convertInputToEntity(input);
|
|
983
|
+
const res = await rapidConfigApi.post(`meta/pages`, createEntityInput);
|
|
984
|
+
const { data } = res;
|
|
985
|
+
if (!data.id) {
|
|
986
|
+
console.log("Response:");
|
|
987
|
+
console.log(data);
|
|
988
|
+
console.log("Input:");
|
|
989
|
+
console.log(createEntityInput);
|
|
990
|
+
}
|
|
991
|
+
return data;
|
|
992
|
+
},
|
|
993
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
994
|
+
async updateEntity(input, remoteEntity, mainEntity, inputIndex) {
|
|
995
|
+
const updateEntityInput = convertInputToEntity(input);
|
|
996
|
+
const res = await rapidConfigApi.patch(`meta/pages/${remoteEntity.id}`, updateEntityInput);
|
|
997
|
+
const { data } = res;
|
|
998
|
+
if (!data.id) {
|
|
999
|
+
console.log("Response:");
|
|
1000
|
+
console.log(data);
|
|
1001
|
+
console.log("Input:");
|
|
1002
|
+
console.log(updateEntityInput);
|
|
1003
|
+
}
|
|
1004
|
+
return data;
|
|
1005
|
+
},
|
|
1006
|
+
};
|
|
1007
|
+
return pageUpdater;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
911
1010
|
class RapidModelsUpdater {
|
|
912
1011
|
#rapidConfigApi;
|
|
913
1012
|
#entities;
|
|
914
1013
|
#dataDictionaries;
|
|
1014
|
+
#pages;
|
|
915
1015
|
constructor(options) {
|
|
916
1016
|
this.#entities = options.entities;
|
|
917
1017
|
this.#dataDictionaries = options.dataDictionaries;
|
|
1018
|
+
this.#pages = options.pages;
|
|
918
1019
|
const { appDataDirLocation, rapidApiUrl } = options;
|
|
919
1020
|
const cookieJarStorageLocation = path__default["default"].join(appDataDirLocation, "rapid-cookie-jar.json");
|
|
920
1021
|
if (!fs__default["default"].existsSync(appDataDirLocation)) {
|
|
@@ -944,6 +1045,7 @@ class RapidModelsUpdater {
|
|
|
944
1045
|
newDictionaryEntryUpdater(rapidConfigApi),
|
|
945
1046
|
newModelUpdater(rapidConfigApi),
|
|
946
1047
|
newPropertyUpdater(rapidConfigApi),
|
|
1048
|
+
newPageUpdater(rapidConfigApi),
|
|
947
1049
|
],
|
|
948
1050
|
});
|
|
949
1051
|
appUpdater.updateModels([
|
|
@@ -955,6 +1057,10 @@ class RapidModelsUpdater {
|
|
|
955
1057
|
modelType: "model",
|
|
956
1058
|
entities: this.#entities.filter((item) => !item.metaOnly),
|
|
957
1059
|
},
|
|
1060
|
+
{
|
|
1061
|
+
modelType: "page",
|
|
1062
|
+
entities: this.#pages,
|
|
1063
|
+
},
|
|
958
1064
|
]);
|
|
959
1065
|
}
|
|
960
1066
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RapidPage } from "@ruiapp/rapid-extension";
|
|
2
|
+
import type { AxiosInstance } from "axios";
|
|
3
|
+
import type { RapidPageEntity } from "./types";
|
|
4
|
+
export declare function newPageUpdater(rapidConfigApi: AxiosInstance): import("./types").IRapidModelUpdaterSingleGetMode<RapidPageEntity, RapidPage, any>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { RapidDataDictionary, RapidEntity } from "@ruiapp/rapid-extension";
|
|
1
|
+
import type { RapidDataDictionary, RapidEntity, RapidPage } from "@ruiapp/rapid-extension";
|
|
2
2
|
export interface RapidModelsUpdateOptions {
|
|
3
3
|
appDataDirLocation: string;
|
|
4
4
|
rapidApiUrl: string;
|
|
5
5
|
entities: RapidEntity[];
|
|
6
6
|
dataDictionaries: RapidDataDictionary[];
|
|
7
|
+
pages: RapidPage[];
|
|
7
8
|
}
|
|
8
9
|
export default class RapidModelsUpdater {
|
|
9
10
|
#private;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RapidDataDictionary, RapidDataDictionaryEntry, RapidEntity, RapidField } from "@ruiapp/rapid-extension";
|
|
1
|
+
import type { RapidDataDictionary, RapidDataDictionaryEntry, RapidEntity, RapidField, RapidPage } from "@ruiapp/rapid-extension";
|
|
2
2
|
export type IRapidModelUpdater<TEntity, TInput, TMainEntity = any> = IRapidModelUpdaterBatchGetMode<TEntity, TInput, TMainEntity> | IRapidModelUpdaterSingleGetMode<TEntity, TInput, TMainEntity>;
|
|
3
3
|
export interface IRapidModelUpdaterCommon<TEntity, TInput, TMainEntity> {
|
|
4
4
|
modelType: string;
|
|
@@ -43,3 +43,17 @@ export type CreateRapidPropertyInput = RapidField & {
|
|
|
43
43
|
};
|
|
44
44
|
export type UpdateRapidPropertyInput = CreateRapidPropertyInput;
|
|
45
45
|
export type RapidProperty = ObjWithIdProp & RapidField;
|
|
46
|
+
export type CreateRapidPageInput = RapidPage;
|
|
47
|
+
export type UpdateRapidPageInput = CreateRapidPageInput;
|
|
48
|
+
export type RapidPageEntity = {
|
|
49
|
+
id?: string;
|
|
50
|
+
subSystem?: string;
|
|
51
|
+
appCode?: string;
|
|
52
|
+
code: string;
|
|
53
|
+
parentCode?: string;
|
|
54
|
+
routePath?: string;
|
|
55
|
+
name: string;
|
|
56
|
+
title?: string;
|
|
57
|
+
config?: Record<any, any>;
|
|
58
|
+
permissionCheck?: Record<any, any>;
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruiapp/rapid-configure-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/mod.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"axios-cookiejar-support": "^4.0.7",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
22
|
"tough-cookie": "^4.1.3",
|
|
23
|
-
"@ruiapp/rapid-
|
|
24
|
-
"@ruiapp/rapid-
|
|
23
|
+
"@ruiapp/rapid-extension": "^0.6.0",
|
|
24
|
+
"@ruiapp/rapid-core": "^0.10.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {},
|
|
27
27
|
"scripts": {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { FindEntityOptions, RapidPage } from "@ruiapp/rapid-extension";
|
|
2
|
+
import type { AxiosInstance } from "axios";
|
|
3
|
+
import { detectChangedFields } from "./ObjectChangesDetector";
|
|
4
|
+
import type { CreateRapidPageInput, IRapidModelUpdater, UpdateRapidPageInput, RapidPageEntity } from "./types";
|
|
5
|
+
|
|
6
|
+
function convertInputToEntity(input: RapidPage) {
|
|
7
|
+
const inputEntity: RapidPageEntity = {
|
|
8
|
+
subSystem: input.subSystem,
|
|
9
|
+
appCode: input.appCode,
|
|
10
|
+
code: input.code,
|
|
11
|
+
parentCode: input.parentCode,
|
|
12
|
+
routePath: input.routePath,
|
|
13
|
+
name: input.name,
|
|
14
|
+
title: input.title,
|
|
15
|
+
permissionCheck: input.permissionCheck,
|
|
16
|
+
config: {
|
|
17
|
+
view: input.view,
|
|
18
|
+
stores: input.stores,
|
|
19
|
+
eventSubscriptions: input.eventSubscriptions,
|
|
20
|
+
functions: input.functions,
|
|
21
|
+
$i18n: input.$i18n,
|
|
22
|
+
$locales: input.$locales,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return inputEntity;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function newPageUpdater(rapidConfigApi: AxiosInstance) {
|
|
29
|
+
const pageUpdater: IRapidModelUpdater<RapidPageEntity, RapidPage> = {
|
|
30
|
+
modelType: "page",
|
|
31
|
+
relationFields: [],
|
|
32
|
+
|
|
33
|
+
entityBatchMode: false,
|
|
34
|
+
|
|
35
|
+
inputTitlePrinter(input) {
|
|
36
|
+
return input.code;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
entityKeyGetter(input) {
|
|
40
|
+
return input.code;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
async entitySingleFinder(entityKey: string) {
|
|
44
|
+
const res = await rapidConfigApi.post(`meta/pages/operations/find`, {
|
|
45
|
+
filters: [
|
|
46
|
+
{
|
|
47
|
+
operator: "eq",
|
|
48
|
+
field: "code",
|
|
49
|
+
value: entityKey,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
} satisfies FindEntityOptions);
|
|
53
|
+
|
|
54
|
+
const entities = res.data.list;
|
|
55
|
+
if (entities && entities.length) {
|
|
56
|
+
return entities[0];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
entityExistensePredicate(input, entity) {
|
|
63
|
+
return entity.code === input.code;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
isEntityChanged(input, remoteEntity) {
|
|
67
|
+
const inputEntity = convertInputToEntity(input);
|
|
68
|
+
const changedFieldNames = detectChangedFields(inputEntity, remoteEntity, [
|
|
69
|
+
"subSystem",
|
|
70
|
+
"appCode",
|
|
71
|
+
"code",
|
|
72
|
+
"parentCode",
|
|
73
|
+
"routePath",
|
|
74
|
+
"name",
|
|
75
|
+
"title",
|
|
76
|
+
"config",
|
|
77
|
+
"permissionCheck",
|
|
78
|
+
]);
|
|
79
|
+
if (changedFieldNames.length) {
|
|
80
|
+
console.log(`${this.modelType} ${this.inputTitlePrinter(inputEntity)} changed with these fields:`, changedFieldNames);
|
|
81
|
+
}
|
|
82
|
+
return changedFieldNames.length > 0;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
|
+
async createEntity(input, mainEntity, inputIndex) {
|
|
87
|
+
const createEntityInput: CreateRapidPageInput = convertInputToEntity(input);
|
|
88
|
+
const res = await rapidConfigApi.post(`meta/pages`, createEntityInput);
|
|
89
|
+
const { data } = res;
|
|
90
|
+
if (!data.id) {
|
|
91
|
+
console.log("Response:");
|
|
92
|
+
console.log(data);
|
|
93
|
+
console.log("Input:");
|
|
94
|
+
console.log(createEntityInput);
|
|
95
|
+
}
|
|
96
|
+
return data;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
+
async updateEntity(input, remoteEntity, mainEntity, inputIndex) {
|
|
101
|
+
const updateEntityInput: UpdateRapidPageInput = convertInputToEntity(input);
|
|
102
|
+
const res = await rapidConfigApi.patch(`meta/pages/${remoteEntity.id}`, updateEntityInput);
|
|
103
|
+
const { data } = res;
|
|
104
|
+
if (!data.id) {
|
|
105
|
+
console.log("Response:");
|
|
106
|
+
console.log(data);
|
|
107
|
+
console.log("Input:");
|
|
108
|
+
console.log(updateEntityInput);
|
|
109
|
+
}
|
|
110
|
+
return data;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return pageUpdater;
|
|
115
|
+
}
|
|
@@ -8,23 +8,27 @@ import { newDictionaryUpdater } from "./DictionaryUpdater";
|
|
|
8
8
|
import { newDictionaryEntryUpdater } from "./DictionaryEntryUpdater";
|
|
9
9
|
import { newModelUpdater } from "./ModelUpdater";
|
|
10
10
|
import { newPropertyUpdater } from "./PropertyUpdater";
|
|
11
|
-
import type { RapidDataDictionary, RapidEntity } from "@ruiapp/rapid-extension";
|
|
11
|
+
import type { RapidDataDictionary, RapidEntity, RapidPage } from "@ruiapp/rapid-extension";
|
|
12
|
+
import { newPageUpdater } from "./PageUpdater";
|
|
12
13
|
|
|
13
14
|
export interface RapidModelsUpdateOptions {
|
|
14
15
|
appDataDirLocation: string;
|
|
15
16
|
rapidApiUrl: string;
|
|
16
17
|
entities: RapidEntity[];
|
|
17
18
|
dataDictionaries: RapidDataDictionary[];
|
|
19
|
+
pages: RapidPage[];
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export default class RapidModelsUpdater {
|
|
21
23
|
#rapidConfigApi: AxiosInstance;
|
|
22
24
|
#entities: RapidEntity[];
|
|
23
25
|
#dataDictionaries: RapidDataDictionary[];
|
|
26
|
+
#pages: RapidPage[];
|
|
24
27
|
|
|
25
28
|
constructor(options: RapidModelsUpdateOptions) {
|
|
26
29
|
this.#entities = options.entities;
|
|
27
30
|
this.#dataDictionaries = options.dataDictionaries;
|
|
31
|
+
this.#pages = options.pages;
|
|
28
32
|
|
|
29
33
|
const { appDataDirLocation, rapidApiUrl } = options;
|
|
30
34
|
|
|
@@ -61,6 +65,7 @@ export default class RapidModelsUpdater {
|
|
|
61
65
|
newDictionaryEntryUpdater(rapidConfigApi),
|
|
62
66
|
newModelUpdater(rapidConfigApi),
|
|
63
67
|
newPropertyUpdater(rapidConfigApi),
|
|
68
|
+
newPageUpdater(rapidConfigApi),
|
|
64
69
|
],
|
|
65
70
|
});
|
|
66
71
|
appUpdater.updateModels([
|
|
@@ -72,6 +77,10 @@ export default class RapidModelsUpdater {
|
|
|
72
77
|
modelType: "model",
|
|
73
78
|
entities: this.#entities.filter((item) => !item.metaOnly),
|
|
74
79
|
},
|
|
80
|
+
{
|
|
81
|
+
modelType: "page",
|
|
82
|
+
entities: this.#pages,
|
|
83
|
+
},
|
|
75
84
|
]);
|
|
76
85
|
}
|
|
77
86
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RapidDataDictionary, RapidDataDictionaryEntry, RapidEntity, RapidField } from "@ruiapp/rapid-extension";
|
|
1
|
+
import type { RapidDataDictionary, RapidDataDictionaryEntry, RapidEntity, RapidField, RapidPage } from "@ruiapp/rapid-extension";
|
|
2
2
|
|
|
3
3
|
export type IRapidModelUpdater<TEntity, TInput, TMainEntity = any> =
|
|
4
4
|
| IRapidModelUpdaterBatchGetMode<TEntity, TInput, TMainEntity>
|
|
@@ -62,3 +62,19 @@ export type CreateRapidPropertyInput = RapidField & {
|
|
|
62
62
|
export type UpdateRapidPropertyInput = CreateRapidPropertyInput;
|
|
63
63
|
|
|
64
64
|
export type RapidProperty = ObjWithIdProp & RapidField;
|
|
65
|
+
|
|
66
|
+
export type CreateRapidPageInput = RapidPage;
|
|
67
|
+
export type UpdateRapidPageInput = CreateRapidPageInput;
|
|
68
|
+
|
|
69
|
+
export type RapidPageEntity = {
|
|
70
|
+
id?: string;
|
|
71
|
+
subSystem?: string;
|
|
72
|
+
appCode?: string;
|
|
73
|
+
code: string;
|
|
74
|
+
parentCode?: string;
|
|
75
|
+
routePath?: string;
|
|
76
|
+
name: string;
|
|
77
|
+
title?: string;
|
|
78
|
+
config?: Record<any, any>;
|
|
79
|
+
permissionCheck?: Record<any, any>;
|
|
80
|
+
};
|