@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.
Files changed (46) hide show
  1. package/dist/bootstrapApplicationConfig.d.ts +6 -0
  2. package/dist/helpers/metaHelper.d.ts +3 -3
  3. package/dist/index.js +57 -16
  4. package/dist/plugins/webhooks/pluginConfig.d.ts +1 -0
  5. package/dist/types.d.ts +19 -1
  6. package/package.json +1 -1
  7. package/src/bootstrapApplicationConfig.ts +615 -602
  8. package/src/core/server.ts +142 -142
  9. package/src/dataAccess/columnTypeMapper.ts +22 -22
  10. package/src/dataAccess/dataAccessTypes.ts +151 -151
  11. package/src/dataAccess/entityManager.ts +1499 -1496
  12. package/src/dataAccess/entityMapper.ts +100 -100
  13. package/src/dataAccess/propertyMapper.ts +28 -28
  14. package/src/deno-std/http/cookie.ts +372 -372
  15. package/src/helpers/filterHelper.ts +47 -47
  16. package/src/helpers/metaHelper.ts +80 -76
  17. package/src/helpers/runCollectionEntityActionHandler.ts +27 -27
  18. package/src/index.ts +46 -46
  19. package/src/plugins/auth/AuthPlugin.ts +85 -85
  20. package/src/plugins/cronJob/CronJobPlugin.ts +112 -112
  21. package/src/plugins/dataManage/DataManagePlugin.ts +163 -163
  22. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +38 -38
  23. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +22 -22
  24. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +146 -146
  25. package/src/plugins/fileManage/FileManagePlugin.ts +52 -52
  26. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +44 -44
  27. package/src/plugins/metaManage/MetaManagePlugin.ts +500 -488
  28. package/src/plugins/routeManage/RouteManagePlugin.ts +62 -62
  29. package/src/plugins/sequence/SequencePlugin.ts +136 -136
  30. package/src/plugins/sequence/SequencePluginTypes.ts +69 -69
  31. package/src/plugins/sequence/segments/autoIncrement.ts +78 -78
  32. package/src/plugins/sequence/segments/dayOfMonth.ts +17 -17
  33. package/src/plugins/sequence/segments/literal.ts +14 -14
  34. package/src/plugins/sequence/segments/month.ts +17 -17
  35. package/src/plugins/sequence/segments/parameter.ts +18 -18
  36. package/src/plugins/sequence/segments/year.ts +17 -17
  37. package/src/plugins/setting/SettingPlugin.ts +68 -68
  38. package/src/plugins/setting/SettingPluginTypes.ts +37 -37
  39. package/src/plugins/stateMachine/StateMachinePlugin.ts +186 -186
  40. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +48 -48
  41. package/src/plugins/webhooks/WebhooksPlugin.ts +148 -148
  42. package/src/plugins/webhooks/pluginConfig.ts +1 -0
  43. package/src/queryBuilder/queryBuilder.ts +637 -637
  44. package/src/server.ts +463 -451
  45. package/src/types.ts +659 -637
  46. package/src/utilities/errorUtility.ts +15 -15
@@ -1,62 +1,62 @@
1
- /**
2
- * Route manager plugin
3
- */
4
-
5
- import { RpdApplicationConfig } from "~/types";
6
- import {
7
- RpdServerPluginExtendingAbilities,
8
- RpdServerPluginConfigurableTargetOptions,
9
- RpdConfigurationItemOptions,
10
- IRpdServer,
11
- RapidPlugin,
12
- } from "~/core/server";
13
- import * as httpProxy from "./actionHandlers/httpProxy";
14
-
15
- class RouteManager implements RapidPlugin {
16
- get code(): string {
17
- return "routeManager";
18
- }
19
-
20
- get description(): string {
21
- return null;
22
- }
23
-
24
- get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
25
- return [];
26
- }
27
-
28
- get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
29
- return [];
30
- }
31
-
32
- get configurations(): RpdConfigurationItemOptions[] {
33
- return [];
34
- }
35
-
36
- async registerActionHandlers(server: IRpdServer): Promise<any> {
37
- server.registerActionHandler(this, httpProxy);
38
- }
39
-
40
- async registerEventHandlers(server: IRpdServer): Promise<any> {
41
- // TODO: Should rebuild routes after route configurations changed.
42
- // server.registerEventHandler("entity.create", handleEntityEvent.bind(null, server))
43
- // server.registerEventHandler("entity.update", handleEntityEvent.bind(null, server))
44
- // server.registerEventHandler("entity.delete", handleEntityEvent.bind(null, server))
45
- }
46
-
47
- async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
48
- const logger = server.getLogger();
49
- try {
50
- logger.info("Loading meta of routes...");
51
- const entityManager = server.getEntityManager("route");
52
- const routes = await entityManager.findEntities({
53
- orderBy: [{ field: "endpoint" }],
54
- });
55
- applicationConfig.routes.push(...routes);
56
- } catch (error) {
57
- logger.crit("Failed to load meta of routes.", { error });
58
- }
59
- }
60
- }
61
-
62
- export default RouteManager;
1
+ /**
2
+ * Route manager plugin
3
+ */
4
+
5
+ import { RpdApplicationConfig } from "~/types";
6
+ import {
7
+ RpdServerPluginExtendingAbilities,
8
+ RpdServerPluginConfigurableTargetOptions,
9
+ RpdConfigurationItemOptions,
10
+ IRpdServer,
11
+ RapidPlugin,
12
+ } from "~/core/server";
13
+ import * as httpProxy from "./actionHandlers/httpProxy";
14
+
15
+ class RouteManager implements RapidPlugin {
16
+ get code(): string {
17
+ return "routeManager";
18
+ }
19
+
20
+ get description(): string {
21
+ return null;
22
+ }
23
+
24
+ get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
25
+ return [];
26
+ }
27
+
28
+ get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
29
+ return [];
30
+ }
31
+
32
+ get configurations(): RpdConfigurationItemOptions[] {
33
+ return [];
34
+ }
35
+
36
+ async registerActionHandlers(server: IRpdServer): Promise<any> {
37
+ server.registerActionHandler(this, httpProxy);
38
+ }
39
+
40
+ async registerEventHandlers(server: IRpdServer): Promise<any> {
41
+ // TODO: Should rebuild routes after route configurations changed.
42
+ // server.registerEventHandler("entity.create", handleEntityEvent.bind(null, server))
43
+ // server.registerEventHandler("entity.update", handleEntityEvent.bind(null, server))
44
+ // server.registerEventHandler("entity.delete", handleEntityEvent.bind(null, server))
45
+ }
46
+
47
+ async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
48
+ const logger = server.getLogger();
49
+ try {
50
+ logger.info("Loading meta of routes...");
51
+ const entityManager = server.getEntityManager("route");
52
+ const routes = await entityManager.findEntities({
53
+ orderBy: [{ field: "endpoint" }],
54
+ });
55
+ applicationConfig.routes.push(...routes);
56
+ } catch (error) {
57
+ logger.crit("Failed to load meta of routes.", { error });
58
+ }
59
+ }
60
+ }
61
+
62
+ export default RouteManager;
@@ -1,136 +1,136 @@
1
- /**
2
- * Sequence plugin
3
- */
4
-
5
- import { CreateEntityOptions, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty } from "~/types";
6
- import {
7
- IRpdServer,
8
- RapidPlugin,
9
- RpdConfigurationItemOptions,
10
- RpdServerPluginConfigurableTargetOptions,
11
- RpdServerPluginExtendingAbilities,
12
- } from "~/core/server";
13
-
14
- import pluginActionHandlers from "./actionHandlers";
15
- import pluginModels from "./models";
16
- import pluginRoutes from "./routes";
17
- import { PropertySequenceConfig } from "./SequencePluginTypes";
18
- import { isEqual } from "lodash";
19
- import SequenceService from "./SequenceService";
20
- import { isNullOrUndefined } from "~/utilities/typeUtility";
21
- import { getEntityPropertiesIncludingBase } from "~/helpers/metaHelper";
22
-
23
- class SequencePlugin implements RapidPlugin {
24
- #sequenceService!: SequenceService;
25
-
26
- get sequenceService() {
27
- return this.#sequenceService;
28
- }
29
-
30
- get code(): string {
31
- return "sequencePlugin";
32
- }
33
-
34
- get description(): string {
35
- return null;
36
- }
37
-
38
- get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
39
- return [];
40
- }
41
-
42
- get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
43
- return [];
44
- }
45
-
46
- get configurations(): RpdConfigurationItemOptions[] {
47
- return [];
48
- }
49
-
50
- async registerActionHandlers(server: IRpdServer): Promise<any> {
51
- for (const actionHandler of pluginActionHandlers) {
52
- server.registerActionHandler(this, actionHandler);
53
- }
54
- }
55
-
56
- async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
57
- server.appendApplicationConfig({ models: pluginModels });
58
- }
59
-
60
- async configureServices(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
61
- this.#sequenceService = new SequenceService(server);
62
- server.registerService("sequenceService", this.#sequenceService);
63
- }
64
-
65
- async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
66
- server.appendApplicationConfig({ routes: pluginRoutes });
67
- }
68
-
69
- async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
70
- const models = server.getApplicationConfig().models;
71
- for (const model of models) {
72
- for (const property of getEntityPropertiesIncludingBase(server, model)) {
73
- const propertySequenceConfig: PropertySequenceConfig = property.config?.sequence;
74
- if (propertySequenceConfig) {
75
- const ruleCode = getSequenceRuleCode(model, property);
76
- const ruleConfig = propertySequenceConfig.config;
77
-
78
- const sequenceRuleDataAccessor = server.getDataAccessor({
79
- singularCode: "sequence_rule",
80
- });
81
- const sequenceRule = await sequenceRuleDataAccessor.findOne({
82
- filters: [
83
- {
84
- operator: "eq",
85
- field: {
86
- name: "code",
87
- },
88
- value: ruleCode,
89
- },
90
- ],
91
- });
92
-
93
- if (sequenceRule) {
94
- if (isEqual(sequenceRule.config, ruleConfig)) {
95
- await sequenceRuleDataAccessor.updateById(sequenceRule.id, {
96
- config: ruleConfig,
97
- });
98
- }
99
- } else {
100
- await sequenceRuleDataAccessor.create({
101
- code: ruleCode,
102
- config: ruleConfig,
103
- });
104
- }
105
- }
106
- }
107
- }
108
- }
109
-
110
- async beforeCreateEntity(server: IRpdServer, model: RpdDataModel, options: CreateEntityOptions) {
111
- const entity = options.entity;
112
- for (const property of getEntityPropertiesIncludingBase(server, model)) {
113
- const sequenceConfig: PropertySequenceConfig = property.config?.sequence;
114
- const propertyValue = entity[property.code];
115
- if (sequenceConfig && sequenceConfig.enabled && isNullOrUndefined(propertyValue)) {
116
- const ruleCode = getSequenceRuleCode(model, property);
117
- const numbers = await this.#sequenceService.generateSn(server, {
118
- ruleCode,
119
- amount: 1,
120
- parameters: entity,
121
- });
122
- entity[property.code] = numbers[0];
123
- }
124
- }
125
- }
126
- }
127
-
128
- function getSequenceRuleCode(model: RpdDataModel, property: RpdDataModelProperty) {
129
- if (property.isBaseProperty) {
130
- return `propertyAutoGenerate.${model.namespace}.${model.base}.${property.code}`;
131
- } else {
132
- return `propertyAutoGenerate.${model.namespace}.${model.singularCode}.${property.code}`;
133
- }
134
- }
135
-
136
- export default SequencePlugin;
1
+ /**
2
+ * Sequence plugin
3
+ */
4
+
5
+ import { CreateEntityOptions, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty } from "~/types";
6
+ import {
7
+ IRpdServer,
8
+ RapidPlugin,
9
+ RpdConfigurationItemOptions,
10
+ RpdServerPluginConfigurableTargetOptions,
11
+ RpdServerPluginExtendingAbilities,
12
+ } from "~/core/server";
13
+
14
+ import pluginActionHandlers from "./actionHandlers";
15
+ import pluginModels from "./models";
16
+ import pluginRoutes from "./routes";
17
+ import { PropertySequenceConfig } from "./SequencePluginTypes";
18
+ import { isEqual } from "lodash";
19
+ import SequenceService from "./SequenceService";
20
+ import { isNullOrUndefined } from "~/utilities/typeUtility";
21
+ import { getEntityPropertiesIncludingBase } from "~/helpers/metaHelper";
22
+
23
+ class SequencePlugin implements RapidPlugin {
24
+ #sequenceService!: SequenceService;
25
+
26
+ get sequenceService() {
27
+ return this.#sequenceService;
28
+ }
29
+
30
+ get code(): string {
31
+ return "sequencePlugin";
32
+ }
33
+
34
+ get description(): string {
35
+ return null;
36
+ }
37
+
38
+ get extendingAbilities(): RpdServerPluginExtendingAbilities[] {
39
+ return [];
40
+ }
41
+
42
+ get configurableTargets(): RpdServerPluginConfigurableTargetOptions[] {
43
+ return [];
44
+ }
45
+
46
+ get configurations(): RpdConfigurationItemOptions[] {
47
+ return [];
48
+ }
49
+
50
+ async registerActionHandlers(server: IRpdServer): Promise<any> {
51
+ for (const actionHandler of pluginActionHandlers) {
52
+ server.registerActionHandler(this, actionHandler);
53
+ }
54
+ }
55
+
56
+ async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
57
+ server.appendApplicationConfig({ models: pluginModels });
58
+ }
59
+
60
+ async configureServices(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
61
+ this.#sequenceService = new SequenceService(server);
62
+ server.registerService("sequenceService", this.#sequenceService);
63
+ }
64
+
65
+ async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
66
+ server.appendApplicationConfig({ routes: pluginRoutes });
67
+ }
68
+
69
+ async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
70
+ const models = server.getApplicationConfig().models;
71
+ for (const model of models) {
72
+ for (const property of getEntityPropertiesIncludingBase(server, model)) {
73
+ const propertySequenceConfig: PropertySequenceConfig = property.config?.sequence;
74
+ if (propertySequenceConfig) {
75
+ const ruleCode = getSequenceRuleCode(model, property);
76
+ const ruleConfig = propertySequenceConfig.config;
77
+
78
+ const sequenceRuleDataAccessor = server.getDataAccessor({
79
+ singularCode: "sequence_rule",
80
+ });
81
+ const sequenceRule = await sequenceRuleDataAccessor.findOne({
82
+ filters: [
83
+ {
84
+ operator: "eq",
85
+ field: {
86
+ name: "code",
87
+ },
88
+ value: ruleCode,
89
+ },
90
+ ],
91
+ });
92
+
93
+ if (sequenceRule) {
94
+ if (isEqual(sequenceRule.config, ruleConfig)) {
95
+ await sequenceRuleDataAccessor.updateById(sequenceRule.id, {
96
+ config: ruleConfig,
97
+ });
98
+ }
99
+ } else {
100
+ await sequenceRuleDataAccessor.create({
101
+ code: ruleCode,
102
+ config: ruleConfig,
103
+ });
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ async beforeCreateEntity(server: IRpdServer, model: RpdDataModel, options: CreateEntityOptions) {
111
+ const entity = options.entity;
112
+ for (const property of getEntityPropertiesIncludingBase(server, model)) {
113
+ const sequenceConfig: PropertySequenceConfig = property.config?.sequence;
114
+ const propertyValue = entity[property.code];
115
+ if (sequenceConfig && sequenceConfig.enabled && isNullOrUndefined(propertyValue)) {
116
+ const ruleCode = getSequenceRuleCode(model, property);
117
+ const numbers = await this.#sequenceService.generateSn(server, {
118
+ ruleCode,
119
+ amount: 1,
120
+ parameters: entity,
121
+ });
122
+ entity[property.code] = numbers[0];
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ function getSequenceRuleCode(model: RpdDataModel, property: RpdDataModelProperty) {
129
+ if (property.isBaseProperty) {
130
+ return `propertyAutoGenerate.${model.namespace}.${model.base}.${property.code}`;
131
+ } else {
132
+ return `propertyAutoGenerate.${model.namespace}.${model.singularCode}.${property.code}`;
133
+ }
134
+ }
135
+
136
+ export default SequencePlugin;
@@ -1,69 +1,69 @@
1
- export type PropertySequenceConfig = {
2
- enabled: boolean;
3
- config: SequenceRuleConfig;
4
- };
5
-
6
- export type SequenceRuleConfig = {
7
- segments: SequenceSegmentConfig[];
8
- };
9
-
10
- export type SequenceSegmentConfig =
11
- | SequenceLiteralSegmentConfig
12
- | SequenceYearSegmentConfig
13
- | SequenceMonthSegmentConfig
14
- | SequenceDayOfMonthSegmentConfig
15
- | SequenceDayOfWeekSegmentConfig
16
- | SequenceDayOfYearSegmentConfig
17
- | SequenceParameterSegmentConfig
18
- | SequenceAutoIncrementSegmentConfig;
19
-
20
- export type SequenceLiteralSegmentConfig = {
21
- type: "literal";
22
- content: string;
23
- };
24
-
25
- export type SequenceYearSegmentConfig = {
26
- type: "year";
27
- padding?: string;
28
- length?: number;
29
- };
30
-
31
- export type SequenceMonthSegmentConfig = {
32
- type: "month";
33
- padding?: string;
34
- length?: number;
35
- };
36
-
37
- export type SequenceDayOfMonthSegmentConfig = {
38
- type: "dayOfMonth";
39
- padding?: string;
40
- length?: number;
41
- };
42
-
43
- export type SequenceDayOfWeekSegmentConfig = {
44
- type: "dayOfWeek";
45
- padding?: string;
46
- length?: number;
47
- };
48
-
49
- export type SequenceDayOfYearSegmentConfig = {
50
- type: "dayOfYear";
51
- padding?: string;
52
- length?: number;
53
- };
54
-
55
- export type SequenceParameterSegmentConfig = {
56
- type: "parameter";
57
- parameterName: string;
58
- defaultContent?: string;
59
- padding?: string;
60
- length?: number;
61
- };
62
-
63
- export type SequenceAutoIncrementSegmentConfig = {
64
- type: "autoIncrement";
65
- scope?: string;
66
- period?: "forever" | "day" | "month" | "year";
67
- padding?: string;
68
- length?: number;
69
- };
1
+ export type PropertySequenceConfig = {
2
+ enabled: boolean;
3
+ config: SequenceRuleConfig;
4
+ };
5
+
6
+ export type SequenceRuleConfig = {
7
+ segments: SequenceSegmentConfig[];
8
+ };
9
+
10
+ export type SequenceSegmentConfig =
11
+ | SequenceLiteralSegmentConfig
12
+ | SequenceYearSegmentConfig
13
+ | SequenceMonthSegmentConfig
14
+ | SequenceDayOfMonthSegmentConfig
15
+ | SequenceDayOfWeekSegmentConfig
16
+ | SequenceDayOfYearSegmentConfig
17
+ | SequenceParameterSegmentConfig
18
+ | SequenceAutoIncrementSegmentConfig;
19
+
20
+ export type SequenceLiteralSegmentConfig = {
21
+ type: "literal";
22
+ content: string;
23
+ };
24
+
25
+ export type SequenceYearSegmentConfig = {
26
+ type: "year";
27
+ padding?: string;
28
+ length?: number;
29
+ };
30
+
31
+ export type SequenceMonthSegmentConfig = {
32
+ type: "month";
33
+ padding?: string;
34
+ length?: number;
35
+ };
36
+
37
+ export type SequenceDayOfMonthSegmentConfig = {
38
+ type: "dayOfMonth";
39
+ padding?: string;
40
+ length?: number;
41
+ };
42
+
43
+ export type SequenceDayOfWeekSegmentConfig = {
44
+ type: "dayOfWeek";
45
+ padding?: string;
46
+ length?: number;
47
+ };
48
+
49
+ export type SequenceDayOfYearSegmentConfig = {
50
+ type: "dayOfYear";
51
+ padding?: string;
52
+ length?: number;
53
+ };
54
+
55
+ export type SequenceParameterSegmentConfig = {
56
+ type: "parameter";
57
+ parameterName: string;
58
+ defaultContent?: string;
59
+ padding?: string;
60
+ length?: number;
61
+ };
62
+
63
+ export type SequenceAutoIncrementSegmentConfig = {
64
+ type: "autoIncrement";
65
+ scope?: string;
66
+ period?: "forever" | "day" | "month" | "year";
67
+ padding?: string;
68
+ length?: number;
69
+ };