@ruiapp/rapid-configure-tools 0.5.3 → 0.6.1

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 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)}`);
@@ -764,6 +764,7 @@ function newModelUpdater(rapidConfigApi) {
764
764
  "derivedType",
765
765
  "derivedTypePropertyCode",
766
766
  "displayPropertyCode",
767
+ "defaultOrderBy",
767
768
  "indexes",
768
769
  "permissionPolicies",
769
770
  "softDelete",
@@ -908,13 +909,114 @@ function newPropertyUpdater(rapidConfigApi) {
908
909
  return propertyUpdater;
909
910
  }
910
911
 
912
+ function convertInputToEntity(input) {
913
+ const inputEntity = {
914
+ subSystem: input.subSystem,
915
+ appCode: input.appCode,
916
+ code: input.code,
917
+ parentCode: input.parentCode,
918
+ routePath: input.routePath,
919
+ name: input.name,
920
+ title: input.title,
921
+ permissionCheck: input.permissionCheck,
922
+ config: {
923
+ view: input.view,
924
+ stores: input.stores,
925
+ eventSubscriptions: input.eventSubscriptions,
926
+ functions: input.functions,
927
+ $i18n: input.$i18n,
928
+ $locales: input.$locales,
929
+ },
930
+ };
931
+ return inputEntity;
932
+ }
933
+ function newPageUpdater(rapidConfigApi) {
934
+ const pageUpdater = {
935
+ modelType: "page",
936
+ relationFields: [],
937
+ entityBatchMode: false,
938
+ inputTitlePrinter(input) {
939
+ return input.code;
940
+ },
941
+ entityKeyGetter(input) {
942
+ return input.code;
943
+ },
944
+ async entitySingleFinder(entityKey) {
945
+ const res = await rapidConfigApi.post(`meta/pages/operations/find`, {
946
+ filters: [
947
+ {
948
+ operator: "eq",
949
+ field: "code",
950
+ value: entityKey,
951
+ },
952
+ ],
953
+ });
954
+ const entities = res.data.list;
955
+ if (entities && entities.length) {
956
+ return entities[0];
957
+ }
958
+ return null;
959
+ },
960
+ entityExistensePredicate(input, entity) {
961
+ return entity.code === input.code;
962
+ },
963
+ isEntityChanged(input, remoteEntity) {
964
+ const inputEntity = convertInputToEntity(input);
965
+ const changedFieldNames = detectChangedFields(inputEntity, remoteEntity, [
966
+ "subSystem",
967
+ "appCode",
968
+ "code",
969
+ "parentCode",
970
+ "routePath",
971
+ "name",
972
+ "title",
973
+ "config",
974
+ "permissionCheck",
975
+ ]);
976
+ if (changedFieldNames.length) {
977
+ console.log(`${this.modelType} ${this.inputTitlePrinter(inputEntity)} changed with these fields:`, changedFieldNames);
978
+ }
979
+ return changedFieldNames.length > 0;
980
+ },
981
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
982
+ async createEntity(input, mainEntity, inputIndex) {
983
+ const createEntityInput = convertInputToEntity(input);
984
+ const res = await rapidConfigApi.post(`meta/pages`, createEntityInput);
985
+ const { data } = res;
986
+ if (!data.id) {
987
+ console.log("Response:");
988
+ console.log(data);
989
+ console.log("Input:");
990
+ console.log(createEntityInput);
991
+ }
992
+ return data;
993
+ },
994
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
995
+ async updateEntity(input, remoteEntity, mainEntity, inputIndex) {
996
+ const updateEntityInput = convertInputToEntity(input);
997
+ const res = await rapidConfigApi.patch(`meta/pages/${remoteEntity.id}`, updateEntityInput);
998
+ const { data } = res;
999
+ if (!data.id) {
1000
+ console.log("Response:");
1001
+ console.log(data);
1002
+ console.log("Input:");
1003
+ console.log(updateEntityInput);
1004
+ }
1005
+ return data;
1006
+ },
1007
+ };
1008
+ return pageUpdater;
1009
+ }
1010
+
911
1011
  class RapidModelsUpdater {
912
1012
  #rapidConfigApi;
913
1013
  #entities;
914
1014
  #dataDictionaries;
1015
+ #pages;
915
1016
  constructor(options) {
916
1017
  this.#entities = options.entities;
917
1018
  this.#dataDictionaries = options.dataDictionaries;
1019
+ this.#pages = options.pages;
918
1020
  const { appDataDirLocation, rapidApiUrl } = options;
919
1021
  const cookieJarStorageLocation = path__default["default"].join(appDataDirLocation, "rapid-cookie-jar.json");
920
1022
  if (!fs__default["default"].existsSync(appDataDirLocation)) {
@@ -944,6 +1046,7 @@ class RapidModelsUpdater {
944
1046
  newDictionaryEntryUpdater(rapidConfigApi),
945
1047
  newModelUpdater(rapidConfigApi),
946
1048
  newPropertyUpdater(rapidConfigApi),
1049
+ newPageUpdater(rapidConfigApi),
947
1050
  ],
948
1051
  });
949
1052
  appUpdater.updateModels([
@@ -955,6 +1058,10 @@ class RapidModelsUpdater {
955
1058
  modelType: "model",
956
1059
  entities: this.#entities.filter((item) => !item.metaOnly),
957
1060
  },
1061
+ {
1062
+ modelType: "page",
1063
+ entities: this.#pages,
1064
+ },
958
1065
  ]);
959
1066
  }
960
1067
  }
@@ -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.5.3",
3
+ "version": "0.6.1",
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-core": "^0.9.8",
24
- "@ruiapp/rapid-extension": "^0.5.44"
23
+ "@ruiapp/rapid-core": "^0.10.1",
24
+ "@ruiapp/rapid-extension": "^0.6.1"
25
25
  },
26
26
  "dependencies": {},
27
27
  "scripts": {
@@ -62,7 +62,7 @@ export default class RapidUpdater {
62
62
  }
63
63
 
64
64
  for (const entityToSave of entitiesToSave) {
65
- if (!modelUpdater.relationFields) {
65
+ if (!modelUpdater.relationFields || !modelUpdater.relationFields.length) {
66
66
  continue;
67
67
  }
68
68
 
@@ -42,6 +42,7 @@ export function newModelUpdater(rapidConfigApi: AxiosInstance) {
42
42
  "derivedType",
43
43
  "derivedTypePropertyCode",
44
44
  "displayPropertyCode",
45
+ "defaultOrderBy",
45
46
  "indexes",
46
47
  "permissionPolicies",
47
48
  "softDelete",
@@ -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
+ };