@ruiapp/rapid-core 0.3.0 → 0.4.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/core/routeContext.d.ts +9 -0
- package/dist/core/server.d.ts +2 -1
- package/dist/dataAccess/dataAccessor.d.ts +8 -8
- package/dist/helpers/runCollectionEntityActionHandler.d.ts +1 -1
- package/dist/index.js +291 -202
- package/dist/plugins/dataManage/actionHandlers/deleteCollectionEntities.d.ts +1 -0
- package/dist/plugins/sequence/SequenceService.d.ts +3 -2
- package/dist/plugins/sequence/segments/autoIncrement.d.ts +2 -1
- package/dist/plugins/sequence/segments/dayOfMonth.d.ts +2 -1
- package/dist/plugins/sequence/segments/literal.d.ts +2 -1
- package/dist/plugins/sequence/segments/month.d.ts +2 -1
- package/dist/plugins/sequence/segments/parameter.d.ts +2 -1
- package/dist/plugins/sequence/segments/year.d.ts +2 -1
- package/dist/server.d.ts +1 -0
- package/dist/types.d.ts +13 -8
- package/package.json +1 -1
- package/src/core/routeContext.ts +53 -0
- package/src/core/server.ts +2 -0
- package/src/dataAccess/dataAccessor.ts +15 -15
- package/src/dataAccess/entityManager.ts +66 -50
- package/src/helpers/runCollectionEntityActionHandler.ts +37 -7
- package/src/plugins/auth/actionHandlers/changePassword.ts +22 -15
- package/src/plugins/auth/actionHandlers/createSession.ts +14 -11
- package/src/plugins/auth/actionHandlers/resetPassword.ts +21 -14
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +7 -12
- package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +3 -2
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +52 -13
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +12 -16
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntities.ts +32 -25
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +12 -14
- package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +3 -2
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +12 -12
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +8 -13
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +26 -29
- package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +6 -6
- package/src/plugins/fileManage/actionHandlers/downloadFile.ts +3 -3
- package/src/plugins/metaManage/MetaManagePlugin.ts +3 -2
- package/src/plugins/notification/models/Notification.ts +3 -0
- package/src/plugins/sequence/SequencePlugin.ts +29 -19
- package/src/plugins/sequence/SequenceService.ts +25 -14
- package/src/plugins/sequence/actionHandlers/generateSn.ts +3 -3
- package/src/plugins/sequence/segments/autoIncrement.ts +36 -24
- package/src/plugins/sequence/segments/dayOfMonth.ts +2 -0
- package/src/plugins/sequence/segments/literal.ts +2 -0
- package/src/plugins/sequence/segments/month.ts +2 -0
- package/src/plugins/sequence/segments/parameter.ts +2 -0
- package/src/plugins/sequence/segments/year.ts +2 -0
- package/src/plugins/stateMachine/StateMachinePlugin.ts +26 -16
- package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +14 -11
- package/src/server.ts +4 -0
- package/src/types.ts +14 -8
|
@@ -7,8 +7,8 @@ import { getFileBaseName } from "~/utilities/pathUtility";
|
|
|
7
7
|
export const code = "downloadDocument";
|
|
8
8
|
|
|
9
9
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
10
|
-
const { server, applicationConfig, routerContext, input } = ctx;
|
|
11
|
-
const { request, response } =
|
|
10
|
+
const { server, applicationConfig, routerContext: routeContext, input } = ctx;
|
|
11
|
+
const { request, response } = routeContext;
|
|
12
12
|
|
|
13
13
|
const documentDataAccessor = ctx.server.getDataAccessor({
|
|
14
14
|
singularCode: "ecm_document",
|
|
@@ -24,7 +24,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
24
24
|
let fileName: string;
|
|
25
25
|
let { revisionId, documentId } = input;
|
|
26
26
|
if (revisionId) {
|
|
27
|
-
const revision = await revisionDataAccessor.findById(revisionId);
|
|
27
|
+
const revision = await revisionDataAccessor.findById(revisionId, routeContext?.getDbTransactionClient());
|
|
28
28
|
if (!revision) {
|
|
29
29
|
ctx.output = { error: new Error(`Revision with id "${revisionId}" was not found.`) };
|
|
30
30
|
return;
|
|
@@ -32,14 +32,14 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
32
32
|
storageObjectId = revision.storage_object_id;
|
|
33
33
|
|
|
34
34
|
documentId = revision.document_id;
|
|
35
|
-
const document = await documentDataAccessor.findById(documentId);
|
|
35
|
+
const document = await documentDataAccessor.findById(documentId, routeContext?.getDbTransactionClient());
|
|
36
36
|
if (!document) {
|
|
37
37
|
ctx.output = { error: new Error(`Document with id "${documentId}" was not found.`) };
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
fileName = `${getFileBaseName(document.name!)}${revision.ext_name}`;
|
|
41
41
|
} else if (documentId) {
|
|
42
|
-
const document = await documentDataAccessor.findById(documentId);
|
|
42
|
+
const document = await documentDataAccessor.findById(documentId, routeContext?.getDbTransactionClient());
|
|
43
43
|
if (!document) {
|
|
44
44
|
ctx.output = { error: new Error(`Document with id "${documentId}" was not found.`) };
|
|
45
45
|
return;
|
|
@@ -51,7 +51,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const storageObject = await storageDataAccessor.findById(storageObjectId);
|
|
54
|
+
const storageObject = await storageDataAccessor.findById(storageObjectId, routeContext?.getDbTransactionClient());
|
|
55
55
|
if (!storageObject) {
|
|
56
56
|
ctx.output = { error: new Error(`Storage object with id "${storageObjectId}" was not found.`) };
|
|
57
57
|
return;
|
|
@@ -13,8 +13,8 @@ export type DownloadFileInput = {
|
|
|
13
13
|
export const code = "downloadFile";
|
|
14
14
|
|
|
15
15
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
16
|
-
const { server, applicationConfig, routerContext } = ctx;
|
|
17
|
-
const { request, response } =
|
|
16
|
+
const { server, applicationConfig, routerContext: routeContext } = ctx;
|
|
17
|
+
const { request, response } = routeContext;
|
|
18
18
|
//TODO: only public files can download by this handler
|
|
19
19
|
|
|
20
20
|
const input: DownloadFileInput = ctx.input;
|
|
@@ -26,7 +26,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
26
26
|
singularCode: "ecm_storage_object",
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const storageObject = await dataAccessor.findById(input.fileId);
|
|
29
|
+
const storageObject = await dataAccessor.findById(input.fileId, routeContext?.getDbTransactionClient());
|
|
30
30
|
if (!storageObject) {
|
|
31
31
|
ctx.output = { error: new Error("Storage object not found.") };
|
|
32
32
|
return;
|
|
@@ -31,6 +31,7 @@ import { getEntityPropertiesIncludingBase, getEntityPropertyByCode, isOneRelatio
|
|
|
31
31
|
import { DataAccessPgColumnTypes } from "~/dataAccess/dataAccessTypes";
|
|
32
32
|
import { pgPropertyTypeColumnMap } from "~/dataAccess/columnTypeMapper";
|
|
33
33
|
import { convertModelIndexConditionsToRowFilterOptions } from "~/helpers/filterHelper";
|
|
34
|
+
import { RouteContext } from "~/core/routeContext";
|
|
34
35
|
|
|
35
36
|
class MetaManager implements RapidPlugin {
|
|
36
37
|
get code(): string {
|
|
@@ -119,7 +120,7 @@ async function handleEntityUpdateEvent(server: IRpdServer, sender: RapidPlugin,
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
async function handleEntityDeleteEvent(server: IRpdServer, sender: RapidPlugin, payload: RpdEntityDeleteEventPayload) {
|
|
123
|
+
async function handleEntityDeleteEvent(server: IRpdServer, sender: RapidPlugin, payload: RpdEntityDeleteEventPayload, routeContext?: RouteContext) {
|
|
123
124
|
if (sender === this) {
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
@@ -150,7 +151,7 @@ async function handleEntityDeleteEvent(server: IRpdServer, sender: RapidPlugin,
|
|
|
150
151
|
namespace: "meta",
|
|
151
152
|
singularCode: "model",
|
|
152
153
|
});
|
|
153
|
-
const model = await dataAccessor.findById((deletedProperty as any).modelId);
|
|
154
|
+
const model = await dataAccessor.findById((deletedProperty as any).modelId, routeContext?.getDbTransactionClient());
|
|
154
155
|
if (model) {
|
|
155
156
|
await server.queryDatabaseObject(`ALTER TABLE ${queryBuilder.quoteTable(model)} DROP COLUMN ${queryBuilder.quoteObject(columnNameToDrop)}`, []);
|
|
156
157
|
}
|
|
@@ -45,11 +45,14 @@ export default {
|
|
|
45
45
|
columnName: "details",
|
|
46
46
|
description: '{"url": "", "actions": [{"text": "", "url": ""}]}',
|
|
47
47
|
type: "json",
|
|
48
|
+
required: false,
|
|
48
49
|
},
|
|
49
50
|
{
|
|
50
51
|
name: "用户",
|
|
51
52
|
code: "user",
|
|
52
53
|
type: "relation",
|
|
54
|
+
required: false,
|
|
55
|
+
relation: "one",
|
|
53
56
|
targetSingularCode: "oc_user",
|
|
54
57
|
targetIdColumnName: "user_id",
|
|
55
58
|
},
|
|
@@ -78,29 +78,39 @@ class SequencePlugin implements RapidPlugin {
|
|
|
78
78
|
const sequenceRuleDataAccessor = server.getDataAccessor({
|
|
79
79
|
singularCode: "sequence_rule",
|
|
80
80
|
});
|
|
81
|
-
const sequenceRule = await sequenceRuleDataAccessor.findOne(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const sequenceRule = await sequenceRuleDataAccessor.findOne(
|
|
82
|
+
{
|
|
83
|
+
filters: [
|
|
84
|
+
{
|
|
85
|
+
operator: "eq",
|
|
86
|
+
field: {
|
|
87
|
+
name: "code",
|
|
88
|
+
},
|
|
89
|
+
value: ruleCode,
|
|
87
90
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
null,
|
|
94
|
+
);
|
|
92
95
|
|
|
93
96
|
if (sequenceRule) {
|
|
94
97
|
if (isEqual(sequenceRule.config, ruleConfig)) {
|
|
95
|
-
await sequenceRuleDataAccessor.updateById(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
await sequenceRuleDataAccessor.updateById(
|
|
99
|
+
sequenceRule.id,
|
|
100
|
+
{
|
|
101
|
+
config: ruleConfig,
|
|
102
|
+
},
|
|
103
|
+
null,
|
|
104
|
+
);
|
|
98
105
|
}
|
|
99
106
|
} else {
|
|
100
|
-
await sequenceRuleDataAccessor.create(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
await sequenceRuleDataAccessor.create(
|
|
108
|
+
{
|
|
109
|
+
code: ruleCode,
|
|
110
|
+
config: ruleConfig,
|
|
111
|
+
},
|
|
112
|
+
null,
|
|
113
|
+
);
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
}
|
|
@@ -108,13 +118,13 @@ class SequencePlugin implements RapidPlugin {
|
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
async beforeCreateEntity(server: IRpdServer, model: RpdDataModel, options: CreateEntityOptions) {
|
|
111
|
-
const entity = options
|
|
121
|
+
const { routeContext, entity } = options;
|
|
112
122
|
for (const property of getEntityPropertiesIncludingBase(server, model)) {
|
|
113
123
|
const sequenceConfig: PropertySequenceConfig = property.config?.sequence;
|
|
114
124
|
const propertyValue = entity[property.code];
|
|
115
125
|
if (sequenceConfig && sequenceConfig.enabled && isNullOrUndefined(propertyValue)) {
|
|
116
126
|
const ruleCode = getSequenceRuleCode(model, property);
|
|
117
|
-
const numbers = await this.#sequenceService.generateSn(server, {
|
|
127
|
+
const numbers = await this.#sequenceService.generateSn(routeContext, server, {
|
|
118
128
|
ruleCode,
|
|
119
129
|
amount: 1,
|
|
120
130
|
parameters: entity,
|
|
@@ -2,6 +2,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
2
2
|
import segmentResolvers from "./segments";
|
|
3
3
|
import { find } from "lodash";
|
|
4
4
|
import { SequenceRuleConfig, SequenceSegmentConfig } from "./SequencePluginTypes";
|
|
5
|
+
import { RouteContext } from "~/core/routeContext";
|
|
5
6
|
|
|
6
7
|
export interface GenerateSequenceNumbersInput {
|
|
7
8
|
ruleCode: string;
|
|
@@ -15,7 +16,13 @@ export interface GenerateSequenceNumbersOutput {
|
|
|
15
16
|
|
|
16
17
|
export interface SegmentResolver {
|
|
17
18
|
segmentType: string;
|
|
18
|
-
resolveSegmentValue(
|
|
19
|
+
resolveSegmentValue(
|
|
20
|
+
routeContext: RouteContext,
|
|
21
|
+
server: IRpdServer,
|
|
22
|
+
ruleCode: string,
|
|
23
|
+
config: SequenceSegmentConfig,
|
|
24
|
+
input: GenerateSequenceNumbersInput,
|
|
25
|
+
): Promise<string>;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
export default class SequenceService {
|
|
@@ -25,7 +32,7 @@ export default class SequenceService {
|
|
|
25
32
|
this.#server = server;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
async generateSn(server: IRpdServer, input: GenerateSequenceNumbersInput): Promise<string[]> {
|
|
35
|
+
async generateSn(routeContext: RouteContext | null, server: IRpdServer, input: GenerateSequenceNumbersInput): Promise<string[]> {
|
|
29
36
|
const sequenceNumbers = [];
|
|
30
37
|
const { ruleCode, parameters } = input;
|
|
31
38
|
let { amount } = input;
|
|
@@ -38,17 +45,20 @@ export default class SequenceService {
|
|
|
38
45
|
singularCode: "sequence_rule",
|
|
39
46
|
});
|
|
40
47
|
|
|
41
|
-
const sequenceRule = await sequenceRuleDataAccessor.findOne(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const sequenceRule = await sequenceRuleDataAccessor.findOne(
|
|
49
|
+
{
|
|
50
|
+
filters: [
|
|
51
|
+
{
|
|
52
|
+
operator: "eq",
|
|
53
|
+
field: {
|
|
54
|
+
name: "code",
|
|
55
|
+
},
|
|
56
|
+
value: ruleCode,
|
|
47
57
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
routeContext?.getDbTransactionClient(),
|
|
61
|
+
);
|
|
52
62
|
|
|
53
63
|
if (!sequenceRule) {
|
|
54
64
|
throw new Error(`Failed to generate sequence number. Sequence with code '${sequenceRule.code}' not found.`);
|
|
@@ -65,11 +75,12 @@ export default class SequenceService {
|
|
|
65
75
|
for (const segmentConfig of sequenceConfig.segments) {
|
|
66
76
|
const segmentResolver: SegmentResolver = find(segmentResolvers, (item) => item.segmentType === segmentConfig.type);
|
|
67
77
|
if (!segmentResolver) {
|
|
68
|
-
// TODO: deal with
|
|
78
|
+
// TODO: deal with unknown segment type
|
|
79
|
+
server.getLogger().warn(`Unknown segment type "${segmentConfig.type}"`);
|
|
69
80
|
continue;
|
|
70
81
|
}
|
|
71
82
|
|
|
72
|
-
const segment = await segmentResolver.resolveSegmentValue(server, ruleCode, segmentConfig, input);
|
|
83
|
+
const segment = await segmentResolver.resolveSegmentValue(routeContext, server, ruleCode, segmentConfig, input);
|
|
73
84
|
sequenceNumber += segment;
|
|
74
85
|
}
|
|
75
86
|
|
|
@@ -9,8 +9,8 @@ export interface GenerateSequenceNumbersOptions {
|
|
|
9
9
|
export const code = "generateSn";
|
|
10
10
|
|
|
11
11
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: GenerateSequenceNumbersOptions) {
|
|
12
|
-
const { server, routerContext } = ctx;
|
|
13
|
-
const { response } =
|
|
12
|
+
const { server, routerContext: routeContext } = ctx;
|
|
13
|
+
const { response } = routeContext;
|
|
14
14
|
|
|
15
15
|
const input: GenerateSequenceNumbersInput = ctx.input;
|
|
16
16
|
|
|
@@ -24,7 +24,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
24
24
|
|
|
25
25
|
const sequenceService = server.getService<SequenceService>("sequenceService");
|
|
26
26
|
|
|
27
|
-
const sequences = await sequenceService.generateSn(server, input);
|
|
27
|
+
const sequences = await sequenceService.generateSn(routeContext, server, input);
|
|
28
28
|
|
|
29
29
|
ctx.output = {
|
|
30
30
|
sequences,
|
|
@@ -4,10 +4,12 @@ import { IRpdServer } from "~/core/server";
|
|
|
4
4
|
import { get } from "lodash";
|
|
5
5
|
import dayjs from "dayjs";
|
|
6
6
|
import { SequenceAutoIncrementSegmentConfig } from "../SequencePluginTypes";
|
|
7
|
+
import { RouteContext } from "~/core/routeContext";
|
|
7
8
|
|
|
8
9
|
export const segmentType = "autoIncrement";
|
|
9
10
|
|
|
10
11
|
export async function resolveSegmentValue(
|
|
12
|
+
routeContext: RouteContext,
|
|
11
13
|
server: IRpdServer,
|
|
12
14
|
ruleCode: string,
|
|
13
15
|
config: SequenceAutoIncrementSegmentConfig,
|
|
@@ -19,20 +21,23 @@ export async function resolveSegmentValue(
|
|
|
19
21
|
|
|
20
22
|
const scope = get(input.parameters, config.scope, "");
|
|
21
23
|
|
|
22
|
-
const autoIncrementRecord = await autoIncrementRecordDataAccessor.findOne(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
const autoIncrementRecord = await autoIncrementRecordDataAccessor.findOne(
|
|
25
|
+
{
|
|
26
|
+
filters: [
|
|
27
|
+
{
|
|
28
|
+
operator: "eq",
|
|
29
|
+
field: "rule_code",
|
|
30
|
+
value: ruleCode,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
operator: "eq",
|
|
34
|
+
field: "scope",
|
|
35
|
+
value: scope,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
routeContext?.getDbTransactionClient(),
|
|
40
|
+
);
|
|
36
41
|
|
|
37
42
|
let now = dayjs();
|
|
38
43
|
let nowString = now.format("YYYY-MM-DD HH:mm:ss.SSS Z");
|
|
@@ -59,17 +64,24 @@ export async function resolveSegmentValue(
|
|
|
59
64
|
if (!shouldReset) {
|
|
60
65
|
nextValue = autoIncrementRecord.current_value + 1;
|
|
61
66
|
}
|
|
62
|
-
await autoIncrementRecordDataAccessor.updateById(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
await autoIncrementRecordDataAccessor.updateById(
|
|
68
|
+
autoIncrementRecord.id,
|
|
69
|
+
{
|
|
70
|
+
current_value: nextValue,
|
|
71
|
+
updated_at: nowString,
|
|
72
|
+
},
|
|
73
|
+
routeContext?.getDbTransactionClient(),
|
|
74
|
+
);
|
|
66
75
|
} else {
|
|
67
|
-
await autoIncrementRecordDataAccessor.create(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
await autoIncrementRecordDataAccessor.create(
|
|
77
|
+
{
|
|
78
|
+
rule_code: ruleCode,
|
|
79
|
+
scope: scope,
|
|
80
|
+
current_value: nextValue,
|
|
81
|
+
updated_at: nowString,
|
|
82
|
+
},
|
|
83
|
+
routeContext?.getDbTransactionClient(),
|
|
84
|
+
);
|
|
73
85
|
}
|
|
74
86
|
|
|
75
87
|
const segmentValue = nextValue.toString();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteContext } from "~/core/routeContext";
|
|
1
2
|
import { SequenceDayOfMonthSegmentConfig } from "../SequencePluginTypes";
|
|
2
3
|
import { GenerateSequenceNumbersInput } from "../SequenceService";
|
|
3
4
|
import { padSegment } from "../segment-utility";
|
|
@@ -6,6 +7,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
7
|
export const segmentType = "dayOfMonth";
|
|
7
8
|
|
|
8
9
|
export async function resolveSegmentValue(
|
|
10
|
+
routeContext: RouteContext,
|
|
9
11
|
server: IRpdServer,
|
|
10
12
|
ruleCode: string,
|
|
11
13
|
config: SequenceDayOfMonthSegmentConfig,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteContext } from "~/core/routeContext";
|
|
1
2
|
import { SequenceLiteralSegmentConfig } from "../SequencePluginTypes";
|
|
2
3
|
import { GenerateSequenceNumbersInput } from "../SequenceService";
|
|
3
4
|
import { IRpdServer } from "~/core/server";
|
|
@@ -5,6 +6,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
5
6
|
export const segmentType = "literal";
|
|
6
7
|
|
|
7
8
|
export async function resolveSegmentValue(
|
|
9
|
+
routeContext: RouteContext,
|
|
8
10
|
server: IRpdServer,
|
|
9
11
|
ruleCode: string,
|
|
10
12
|
config: SequenceLiteralSegmentConfig,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteContext } from "~/core/routeContext";
|
|
1
2
|
import { SequenceMonthSegmentConfig } from "../SequencePluginTypes";
|
|
2
3
|
import { GenerateSequenceNumbersInput } from "../SequenceService";
|
|
3
4
|
import { padSegment } from "../segment-utility";
|
|
@@ -6,6 +7,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
7
|
export const segmentType = "month";
|
|
7
8
|
|
|
8
9
|
export async function resolveSegmentValue(
|
|
10
|
+
routeContext: RouteContext,
|
|
9
11
|
server: IRpdServer,
|
|
10
12
|
ruleCode: string,
|
|
11
13
|
config: SequenceMonthSegmentConfig,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteContext } from "~/core/routeContext";
|
|
1
2
|
import { SequenceParameterSegmentConfig } from "../SequencePluginTypes";
|
|
2
3
|
import { GenerateSequenceNumbersInput } from "../SequenceService";
|
|
3
4
|
import { padSegment } from "../segment-utility";
|
|
@@ -7,6 +8,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
7
8
|
export const segmentType = "parameter";
|
|
8
9
|
|
|
9
10
|
export async function resolveSegmentValue(
|
|
11
|
+
routeContext: RouteContext,
|
|
10
12
|
server: IRpdServer,
|
|
11
13
|
ruleCode: string,
|
|
12
14
|
config: SequenceParameterSegmentConfig,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteContext } from "~/core/routeContext";
|
|
1
2
|
import { SequenceYearSegmentConfig } from "../SequencePluginTypes";
|
|
2
3
|
import { GenerateSequenceNumbersInput } from "../SequenceService";
|
|
3
4
|
import { padSegment } from "../segment-utility";
|
|
@@ -6,6 +7,7 @@ import { IRpdServer } from "~/core/server";
|
|
|
6
7
|
export const segmentType = "year";
|
|
7
8
|
|
|
8
9
|
export async function resolveSegmentValue(
|
|
10
|
+
routeContext: RouteContext,
|
|
9
11
|
server: IRpdServer,
|
|
10
12
|
ruleCode: string,
|
|
11
13
|
config: SequenceYearSegmentConfig,
|
|
@@ -67,27 +67,37 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
67
67
|
const stateMachineDataAccessor = server.getDataAccessor({
|
|
68
68
|
singularCode: "state_machine",
|
|
69
69
|
});
|
|
70
|
-
const stateMachine = await stateMachineDataAccessor.findOne(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const stateMachine = await stateMachineDataAccessor.findOne(
|
|
71
|
+
{
|
|
72
|
+
filters: [
|
|
73
|
+
{
|
|
74
|
+
operator: "eq",
|
|
75
|
+
field: "code",
|
|
76
|
+
value: stateMachineCode,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
null,
|
|
81
|
+
);
|
|
79
82
|
|
|
80
83
|
if (stateMachine) {
|
|
81
84
|
if (!isEqual(stateMachine.config, stateMachineConfig)) {
|
|
82
|
-
await stateMachineDataAccessor.updateById(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
await stateMachineDataAccessor.updateById(
|
|
86
|
+
stateMachine.id,
|
|
87
|
+
{
|
|
88
|
+
config: stateMachineConfig,
|
|
89
|
+
},
|
|
90
|
+
null,
|
|
91
|
+
);
|
|
85
92
|
}
|
|
86
93
|
} else {
|
|
87
|
-
await stateMachineDataAccessor.create(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
await stateMachineDataAccessor.create(
|
|
95
|
+
{
|
|
96
|
+
code: stateMachineCode,
|
|
97
|
+
config: stateMachineConfig,
|
|
98
|
+
},
|
|
99
|
+
null,
|
|
100
|
+
);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
}
|
|
@@ -6,8 +6,8 @@ import { getStateMachineNextSnapshot } from "../stateMachineHelper";
|
|
|
6
6
|
export const code = "sendStateMachineEvent";
|
|
7
7
|
|
|
8
8
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: SendStateMachineEventOptions) {
|
|
9
|
-
const { server, routerContext } = ctx;
|
|
10
|
-
const { response } =
|
|
9
|
+
const { server, routerContext: routeContext } = ctx;
|
|
10
|
+
const { response } = routeContext;
|
|
11
11
|
|
|
12
12
|
const input: SendStateMachineEventInput = ctx.input;
|
|
13
13
|
if (options?.code) {
|
|
@@ -22,15 +22,18 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
22
22
|
singularCode: "state_machine",
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
const stateMachine = await stateMachineDataAccessor.findOne(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const stateMachine = await stateMachineDataAccessor.findOne(
|
|
26
|
+
{
|
|
27
|
+
filters: [
|
|
28
|
+
{
|
|
29
|
+
operator: "eq",
|
|
30
|
+
field: "code",
|
|
31
|
+
value: input.code,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
routeContext?.getDbTransactionClient(),
|
|
36
|
+
);
|
|
34
37
|
|
|
35
38
|
if (!stateMachine) {
|
|
36
39
|
throw new Error(`State machine with code '${input.code}' was not found.`);
|
package/src/server.ts
CHANGED
|
@@ -139,6 +139,10 @@ export class RapidServer implements IRpdServer {
|
|
|
139
139
|
return this.#applicationConfig;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
getDatabaseAccessor(): IDatabaseAccessor {
|
|
143
|
+
return this.#databaseAccessor;
|
|
144
|
+
}
|
|
145
|
+
|
|
142
146
|
appendApplicationConfig(config: Partial<RpdApplicationConfig>) {
|
|
143
147
|
const { models, dataDictionaries, routes } = config;
|
|
144
148
|
if (models) {
|
package/src/types.ts
CHANGED
|
@@ -24,8 +24,14 @@ export type DatabaseQuery = {
|
|
|
24
24
|
params?: unknown[] | Record<string, unknown>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
export interface IDatabaseClient {
|
|
28
|
+
release();
|
|
29
|
+
query(sql: any, params?: any): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
export interface IDatabaseAccessor {
|
|
28
|
-
|
|
33
|
+
getClient(): Promise<IDatabaseClient>;
|
|
34
|
+
queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>, client?: IDatabaseClient) => Promise<any[]>;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export interface RunEntityActionHandlerOptions {
|
|
@@ -460,13 +466,13 @@ export interface RpdRouteActionConfig {
|
|
|
460
466
|
|
|
461
467
|
export interface IRpdDataAccessor<T = any> {
|
|
462
468
|
getModel(): RpdDataModel;
|
|
463
|
-
create(entity: any): Promise<any>;
|
|
464
|
-
updateById(id: any, entity: any): Promise<any>;
|
|
465
|
-
find(options: FindRowOptions): Promise<T[]>;
|
|
466
|
-
findOne(options: FindRowOptions): Promise<T | null>;
|
|
467
|
-
findById(id: any): Promise<T | null>;
|
|
468
|
-
count(options: CountRowOptions): Promise<number>;
|
|
469
|
-
deleteById(id: any): Promise<void>;
|
|
469
|
+
create(entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
|
|
470
|
+
updateById(id: any, entity: any, databaseClient: IDatabaseClient | null): Promise<any>;
|
|
471
|
+
find(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T[]>;
|
|
472
|
+
findOne(options: FindRowOptions, databaseClient: IDatabaseClient | null): Promise<T | null>;
|
|
473
|
+
findById(id: any, databaseClient: IDatabaseClient | null): Promise<T | null>;
|
|
474
|
+
count(options: CountRowOptions, databaseClient: IDatabaseClient | null): Promise<number>;
|
|
475
|
+
deleteById(id: any, databaseClient: IDatabaseClient | null): Promise<void>;
|
|
470
476
|
}
|
|
471
477
|
|
|
472
478
|
export type EntityFilterRelationalOperators =
|