@ruiapp/rapid-core 0.1.54 → 0.1.56
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/server.d.ts +2 -2
- package/dist/dataAccess/entityManager.d.ts +3 -3
- package/dist/index.js +217 -96
- package/dist/server.d.ts +2 -2
- package/dist/types.d.ts +34 -25
- package/package.json +1 -1
- package/src/core/http-types.ts +4 -4
- package/src/core/server.ts +2 -2
- package/src/dataAccess/entityManager.ts +128 -75
- package/src/deno-std/assert/assert.ts +9 -9
- package/src/deno-std/assert/assertion_error.ts +7 -7
- package/src/helpers/inputHelper.ts +11 -11
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +3 -2
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +4 -1
- package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +4 -1
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +3 -2
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +9 -2
- package/src/plugins/metaManage/MetaManagePlugin.ts +33 -2
- package/src/plugins/serverOperation/actionHandlers/runServerOperation.ts +15 -15
- package/src/plugins/stateMachine/stateMachineHelper.ts +36 -36
- package/src/plugins/webhooks/pluginConfig.ts +74 -74
- package/src/proxy/types.ts +21 -21
- package/src/queryBuilder/index.ts +1 -1
- package/src/server.ts +6 -4
- package/src/types.ts +37 -25
- package/src/utilities/rapidUtility.ts +5 -5
- package/src/utilities/typeUtility.ts +11 -11
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
import { AssertionError } from "./assertion_error";
|
|
3
|
-
|
|
4
|
-
/** Make an assertion, error will be thrown if `expr` does not have truthy value. */
|
|
5
|
-
export function assert(expr: unknown, msg = ""): asserts expr {
|
|
6
|
-
if (!expr) {
|
|
7
|
-
throw new AssertionError(msg);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { AssertionError } from "./assertion_error";
|
|
3
|
+
|
|
4
|
+
/** Make an assertion, error will be thrown if `expr` does not have truthy value. */
|
|
5
|
+
export function assert(expr: unknown, msg = ""): asserts expr {
|
|
6
|
+
if (!expr) {
|
|
7
|
+
throw new AssertionError(msg);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
export class AssertionError extends Error {
|
|
3
|
-
override name = "AssertionError";
|
|
4
|
-
constructor(message: string) {
|
|
5
|
-
super(message);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
export class AssertionError extends Error {
|
|
3
|
+
override name = "AssertionError";
|
|
4
|
+
constructor(message: string) {
|
|
5
|
+
super(message);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isArray, mergeWith } from "lodash";
|
|
2
|
-
|
|
3
|
-
export function mergeInput(defaultInput: any, input: any, fixedInput: any) {
|
|
4
|
-
return mergeWith({}, defaultInput, input, fixedInput, doNotMergeArray);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function doNotMergeArray(objValue: any, srcValue: any) {
|
|
8
|
-
if (isArray(srcValue)) {
|
|
9
|
-
return srcValue;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
import { isArray, mergeWith } from "lodash";
|
|
2
|
+
|
|
3
|
+
export function mergeInput(defaultInput: any, input: any, fixedInput: any) {
|
|
4
|
+
return mergeWith({}, defaultInput, input, fixedInput, doNotMergeArray);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function doNotMergeArray(objValue: any, srcValue: any) {
|
|
8
|
+
if (isArray(srcValue)) {
|
|
9
|
+
return srcValue;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -13,7 +13,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
13
13
|
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
14
14
|
|
|
15
15
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
16
|
-
mergedInput.
|
|
16
|
+
mergedInput.routeContext = ctx.routerContext;
|
|
17
17
|
await entityManager.addRelations(mergedInput, plugin);
|
|
18
18
|
|
|
19
19
|
ctx.output = {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunEntityActionHandlerOptions } from "~/types";
|
|
1
|
+
import { CountEntityOptions, RunEntityActionHandlerOptions } from "~/types";
|
|
2
2
|
import runCollectionEntityActionHandler from "~/helpers/runCollectionEntityActionHandler";
|
|
3
3
|
import { removeFiltersWithNullValue } from "~/dataAccess/filterHelper";
|
|
4
4
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
@@ -7,8 +7,9 @@ import { RapidPlugin } from "~/core/server";
|
|
|
7
7
|
export const code = "countCollectionEntities";
|
|
8
8
|
|
|
9
9
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
10
|
-
await runCollectionEntityActionHandler(ctx, options, code, (entityManager, input) => {
|
|
10
|
+
await runCollectionEntityActionHandler(ctx, options, code, (entityManager, input: CountEntityOptions) => {
|
|
11
11
|
input.filters = removeFiltersWithNullValue(input.filters);
|
|
12
|
+
input.routeContext = ctx.routerContext;
|
|
12
13
|
return entityManager.count(input);
|
|
13
14
|
});
|
|
14
15
|
}
|
|
@@ -30,7 +30,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
30
30
|
const newEntity = await entityManager.createEntity(
|
|
31
31
|
{
|
|
32
32
|
entity: mergedEntity,
|
|
33
|
-
|
|
33
|
+
routeContext: ctx.routerContext,
|
|
34
34
|
},
|
|
35
35
|
plugin,
|
|
36
36
|
);
|
|
@@ -9,7 +9,10 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
9
9
|
logger.debug(`Running ${code} handler...`);
|
|
10
10
|
|
|
11
11
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
12
|
-
await entityManager.deleteById(
|
|
12
|
+
await entityManager.deleteById({
|
|
13
|
+
id: input.id,
|
|
14
|
+
routeContext: ctx.routerContext,
|
|
15
|
+
}, plugin);
|
|
13
16
|
|
|
14
17
|
ctx.status = 200;
|
|
15
18
|
ctx.output = {};
|
|
@@ -9,7 +9,7 @@ export const code = "findCollectionEntities";
|
|
|
9
9
|
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: RunEntityActionHandlerOptions) {
|
|
10
10
|
await runCollectionEntityActionHandler(ctx, options, code, async (entityManager, input: FindEntityOptions) => {
|
|
11
11
|
input.filters = removeFiltersWithNullValue(input.filters);
|
|
12
|
-
input.
|
|
12
|
+
input.routeContext = ctx.routerContext;
|
|
13
13
|
const entities = await entityManager.findEntities(input);
|
|
14
14
|
const result: {
|
|
15
15
|
list: any;
|
|
@@ -10,7 +10,10 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
10
10
|
const { id } = input;
|
|
11
11
|
|
|
12
12
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
13
|
-
const entity = await entityManager.findById(
|
|
13
|
+
const entity = await entityManager.findById({
|
|
14
|
+
id,
|
|
15
|
+
routeContext: ctx.routerContext,
|
|
16
|
+
});
|
|
14
17
|
if (!entity) {
|
|
15
18
|
throw new Error(`${options.namespace}.${options.singularCode} with id "${id}" was not found.`);
|
|
16
19
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunEntityActionHandlerOptions } from "~/types";
|
|
1
|
+
import { RemoveEntityRelationsOptions, RunEntityActionHandlerOptions } from "~/types";
|
|
2
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
3
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
4
|
import { RapidPlugin } from "~/core/server";
|
|
@@ -9,8 +9,9 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
9
9
|
const { logger, server, input } = ctx;
|
|
10
10
|
const { defaultInput, fixedInput } = options;
|
|
11
11
|
|
|
12
|
-
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
12
|
+
const mergedInput: RemoveEntityRelationsOptions = mergeInput(defaultInput, input, fixedInput);
|
|
13
13
|
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
14
|
+
mergedInput.routeContext = ctx.routerContext;
|
|
14
15
|
|
|
15
16
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
16
17
|
await entityManager.removeRelations(mergedInput, plugin);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunEntityActionHandlerOptions } from "~/types";
|
|
1
|
+
import { RunEntityActionHandlerOptions, UpdateEntityByIdOptions } from "~/types";
|
|
2
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
3
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
4
|
import { RapidPlugin } from "~/core/server";
|
|
@@ -22,7 +22,14 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
22
22
|
delete mergedInput.$stateProperties;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const updateEntityByIdOptions: UpdateEntityByIdOptions = {
|
|
26
|
+
id: mergedInput.id,
|
|
27
|
+
entityToSave: mergedInput,
|
|
28
|
+
operation,
|
|
29
|
+
stateProperties,
|
|
30
|
+
routeContext: ctx.routerContext,
|
|
31
|
+
};
|
|
25
32
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
26
|
-
const output = await entityManager.updateEntityById(
|
|
33
|
+
const output = await entityManager.updateEntityById(updateEntityByIdOptions, plugin);
|
|
27
34
|
ctx.output = output;
|
|
28
35
|
}
|
|
@@ -161,6 +161,13 @@ type ColumnInformation = {
|
|
|
161
161
|
numeric_scale: number;
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
+
type ConstraintInformation = {
|
|
165
|
+
table_schema: string;
|
|
166
|
+
table_name: string;
|
|
167
|
+
constraint_type: string;
|
|
168
|
+
constraint_name: string;
|
|
169
|
+
};
|
|
170
|
+
|
|
164
171
|
async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
|
|
165
172
|
const logger = server.getLogger();
|
|
166
173
|
logger.info("Synchronizing database schema...");
|
|
@@ -187,7 +194,7 @@ async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdAppl
|
|
|
187
194
|
logger.debug(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
|
|
188
195
|
|
|
189
196
|
for (const property of model.properties) {
|
|
190
|
-
let columnDDL;
|
|
197
|
+
let columnDDL = "";
|
|
191
198
|
if (isRelationProperty(property)) {
|
|
192
199
|
if (property.relation === "one") {
|
|
193
200
|
const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
|
|
@@ -222,6 +229,12 @@ async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdAppl
|
|
|
222
229
|
selfIdColumnName: property.selfIdColumnName!,
|
|
223
230
|
});
|
|
224
231
|
}
|
|
232
|
+
|
|
233
|
+
const contraintName = `${property.linkTableName}_pk`;
|
|
234
|
+
columnDDL += `ALTER TABLE ${queryBuilder.quoteTable(({
|
|
235
|
+
schema: property.linkSchema,
|
|
236
|
+
tableName: property.linkTableName,
|
|
237
|
+
}))} ADD CONSTRAINT ${queryBuilder.quoteObject(contraintName)} PRIMARY KEY (id);`;
|
|
225
238
|
} else {
|
|
226
239
|
const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
|
|
227
240
|
if (!targetModel) {
|
|
@@ -307,6 +320,24 @@ async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdAppl
|
|
|
307
320
|
}
|
|
308
321
|
}
|
|
309
322
|
}
|
|
323
|
+
|
|
324
|
+
const sqlQueryConstraints = `SELECT table_schema, table_name, constraint_type, constraint_name FROM information_schema.table_constraints WHERE constraint_type = 'PRIMARY KEY';`;
|
|
325
|
+
const constraintsInDb: ConstraintInformation[] = await server.queryDatabaseObject(sqlQueryConstraints);
|
|
326
|
+
for (const model of applicationConfig.models) {
|
|
327
|
+
const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
|
|
328
|
+
const expectedTableName = model.tableName;
|
|
329
|
+
const expectedContraintName = `${expectedTableName}_pk`;
|
|
330
|
+
logger.debug(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
|
|
331
|
+
const constraintInDb = find(constraintsInDb, {
|
|
332
|
+
table_schema: expectedTableSchema,
|
|
333
|
+
table_name: expectedTableName,
|
|
334
|
+
constraint_type: "PRIMARY KEY",
|
|
335
|
+
constraint_name: expectedContraintName,
|
|
336
|
+
});
|
|
337
|
+
if (!constraintInDb) {
|
|
338
|
+
await server.queryDatabaseObject(`ALTER TABLE ${queryBuilder.quoteTable(model)} ADD CONSTRAINT ${queryBuilder.quoteObject(expectedContraintName)} PRIMARY KEY (id);`, []);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
310
341
|
}
|
|
311
342
|
|
|
312
343
|
function generateCreateColumnDDL(
|
|
@@ -358,7 +389,7 @@ function generateLinkTableDDL(
|
|
|
358
389
|
})} (`;
|
|
359
390
|
columnDDL += `id serial not null,`;
|
|
360
391
|
columnDDL += `${queryBuilder.quoteObject(options.selfIdColumnName)} integer not null,`;
|
|
361
|
-
columnDDL += `${queryBuilder.quoteObject(options.targetIdColumnName)} integer not null)
|
|
392
|
+
columnDDL += `${queryBuilder.quoteObject(options.targetIdColumnName)} integer not null);`;
|
|
362
393
|
|
|
363
394
|
return columnDDL;
|
|
364
395
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
2
|
-
import { RapidPlugin } from "~/core/server";
|
|
3
|
-
|
|
4
|
-
export const code = "runServerOperation";
|
|
5
|
-
|
|
6
|
-
export async function handler(
|
|
7
|
-
plugin: RapidPlugin,
|
|
8
|
-
ctx: ActionHandlerContext,
|
|
9
|
-
options: {
|
|
10
|
-
operation: (ctx: ActionHandlerContext) => Promise<void>;
|
|
11
|
-
},
|
|
12
|
-
) {
|
|
13
|
-
const { operation } = options;
|
|
14
|
-
await operation(ctx);
|
|
15
|
-
}
|
|
1
|
+
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
2
|
+
import { RapidPlugin } from "~/core/server";
|
|
3
|
+
|
|
4
|
+
export const code = "runServerOperation";
|
|
5
|
+
|
|
6
|
+
export async function handler(
|
|
7
|
+
plugin: RapidPlugin,
|
|
8
|
+
ctx: ActionHandlerContext,
|
|
9
|
+
options: {
|
|
10
|
+
operation: (ctx: ActionHandlerContext) => Promise<void>;
|
|
11
|
+
},
|
|
12
|
+
) {
|
|
13
|
+
const { operation } = options;
|
|
14
|
+
await operation(ctx);
|
|
15
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { DefaultStateMachineSnapshot, GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes";
|
|
2
|
-
import { createMachine, getInitialSnapshot, getNextSnapshot } from "xstate";
|
|
3
|
-
|
|
4
|
-
export async function getStateMachineNextSnapshot(options: GetStateMachineNextSnapshotOptions) {
|
|
5
|
-
const { machineConfig, currentState, event } = options;
|
|
6
|
-
machineConfig.initial = currentState;
|
|
7
|
-
|
|
8
|
-
const machine = createMachine(machineConfig);
|
|
9
|
-
const snapshot = getInitialSnapshot(machine);
|
|
10
|
-
|
|
11
|
-
if (!snapshot.can(event)) {
|
|
12
|
-
throw new Error(`'${event.type}' action is not allowed at '${currentState}' state.`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
16
|
-
return nextSnapshot;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function tryGetStateMachineNextSnapshot(options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult> {
|
|
20
|
-
const { machineConfig, currentState, event } = options;
|
|
21
|
-
machineConfig.initial = currentState;
|
|
22
|
-
|
|
23
|
-
const machine = createMachine(machineConfig);
|
|
24
|
-
const snapshot = getInitialSnapshot(machine);
|
|
25
|
-
|
|
26
|
-
const canTransfer = snapshot.can(event);
|
|
27
|
-
let nextSnapshot: DefaultStateMachineSnapshot;
|
|
28
|
-
if (canTransfer) {
|
|
29
|
-
nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
canTransfer,
|
|
34
|
-
nextSnapshot,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
1
|
+
import { DefaultStateMachineSnapshot, GetStateMachineNextSnapshotOptions, TryGetStateMachineNextSnapshotResult } from "./StateMachinePluginTypes";
|
|
2
|
+
import { createMachine, getInitialSnapshot, getNextSnapshot } from "xstate";
|
|
3
|
+
|
|
4
|
+
export async function getStateMachineNextSnapshot(options: GetStateMachineNextSnapshotOptions) {
|
|
5
|
+
const { machineConfig, currentState, event } = options;
|
|
6
|
+
machineConfig.initial = currentState;
|
|
7
|
+
|
|
8
|
+
const machine = createMachine(machineConfig);
|
|
9
|
+
const snapshot = getInitialSnapshot(machine);
|
|
10
|
+
|
|
11
|
+
if (!snapshot.can(event)) {
|
|
12
|
+
throw new Error(`'${event.type}' action is not allowed at '${currentState}' state.`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
16
|
+
return nextSnapshot;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function tryGetStateMachineNextSnapshot(options: GetStateMachineNextSnapshotOptions): Promise<TryGetStateMachineNextSnapshotResult> {
|
|
20
|
+
const { machineConfig, currentState, event } = options;
|
|
21
|
+
machineConfig.initial = currentState;
|
|
22
|
+
|
|
23
|
+
const machine = createMachine(machineConfig);
|
|
24
|
+
const snapshot = getInitialSnapshot(machine);
|
|
25
|
+
|
|
26
|
+
const canTransfer = snapshot.can(event);
|
|
27
|
+
let nextSnapshot: DefaultStateMachineSnapshot;
|
|
28
|
+
if (canTransfer) {
|
|
29
|
+
nextSnapshot = getNextSnapshot(machine, snapshot, event);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
canTransfer,
|
|
34
|
+
nextSnapshot,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { RpdApplicationConfig } from "~/types";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
models: [
|
|
5
|
-
{
|
|
6
|
-
name: "webhook",
|
|
7
|
-
namespace: "sys",
|
|
8
|
-
singularCode: "webhook",
|
|
9
|
-
pluralCode: "webhooks",
|
|
10
|
-
schema: "public",
|
|
11
|
-
tableName: "sys_webhooks",
|
|
12
|
-
properties: [
|
|
13
|
-
{
|
|
14
|
-
name: "id",
|
|
15
|
-
code: "id",
|
|
16
|
-
columnName: "id",
|
|
17
|
-
type: "integer",
|
|
18
|
-
required: true,
|
|
19
|
-
autoIncrement: true,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: "name",
|
|
23
|
-
code: "name",
|
|
24
|
-
columnName: "name",
|
|
25
|
-
type: "text",
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: "url",
|
|
30
|
-
code: "url",
|
|
31
|
-
columnName: "url",
|
|
32
|
-
type: "text",
|
|
33
|
-
required: true,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: "secret",
|
|
37
|
-
code: "secret",
|
|
38
|
-
columnName: "secret",
|
|
39
|
-
type: "text",
|
|
40
|
-
required: false,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "namespace",
|
|
44
|
-
code: "namespace",
|
|
45
|
-
columnName: "namespace",
|
|
46
|
-
type: "text",
|
|
47
|
-
required: true,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: "model singular code",
|
|
51
|
-
code: "modelSingularCode",
|
|
52
|
-
columnName: "model_singular_code",
|
|
53
|
-
type: "text",
|
|
54
|
-
required: true,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "events",
|
|
58
|
-
code: "events",
|
|
59
|
-
columnName: "events",
|
|
60
|
-
type: "json",
|
|
61
|
-
required: false,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "enabled",
|
|
65
|
-
code: "enabled",
|
|
66
|
-
columnName: "enabled",
|
|
67
|
-
type: "boolean",
|
|
68
|
-
required: true,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
routes: [],
|
|
74
|
-
} satisfies RpdApplicationConfig;
|
|
1
|
+
import { RpdApplicationConfig } from "~/types";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
models: [
|
|
5
|
+
{
|
|
6
|
+
name: "webhook",
|
|
7
|
+
namespace: "sys",
|
|
8
|
+
singularCode: "webhook",
|
|
9
|
+
pluralCode: "webhooks",
|
|
10
|
+
schema: "public",
|
|
11
|
+
tableName: "sys_webhooks",
|
|
12
|
+
properties: [
|
|
13
|
+
{
|
|
14
|
+
name: "id",
|
|
15
|
+
code: "id",
|
|
16
|
+
columnName: "id",
|
|
17
|
+
type: "integer",
|
|
18
|
+
required: true,
|
|
19
|
+
autoIncrement: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "name",
|
|
23
|
+
code: "name",
|
|
24
|
+
columnName: "name",
|
|
25
|
+
type: "text",
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "url",
|
|
30
|
+
code: "url",
|
|
31
|
+
columnName: "url",
|
|
32
|
+
type: "text",
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "secret",
|
|
37
|
+
code: "secret",
|
|
38
|
+
columnName: "secret",
|
|
39
|
+
type: "text",
|
|
40
|
+
required: false,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "namespace",
|
|
44
|
+
code: "namespace",
|
|
45
|
+
columnName: "namespace",
|
|
46
|
+
type: "text",
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "model singular code",
|
|
51
|
+
code: "modelSingularCode",
|
|
52
|
+
columnName: "model_singular_code",
|
|
53
|
+
type: "text",
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "events",
|
|
58
|
+
code: "events",
|
|
59
|
+
columnName: "events",
|
|
60
|
+
type: "json",
|
|
61
|
+
required: false,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "enabled",
|
|
65
|
+
code: "enabled",
|
|
66
|
+
columnName: "enabled",
|
|
67
|
+
type: "boolean",
|
|
68
|
+
required: true,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
routes: [],
|
|
74
|
+
} satisfies RpdApplicationConfig;
|
package/src/proxy/types.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { RapidRequest } from "~/core/request";
|
|
2
|
-
import { RunProxyHandlerOptions } from "../types";
|
|
3
|
-
import { RapidResponse } from "~/core/response";
|
|
4
|
-
|
|
5
|
-
export interface ProxyContext {
|
|
6
|
-
sourceContext: ProxySourceContext;
|
|
7
|
-
targetContext: ProxyTargetContext;
|
|
8
|
-
options: ProxyOptions;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ProxySourceContext {
|
|
12
|
-
request: RapidRequest;
|
|
13
|
-
response: RapidResponse;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ProxyTargetContext {
|
|
17
|
-
request?: RapidRequest;
|
|
18
|
-
response?: RapidResponse;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ProxyOptions = RunProxyHandlerOptions;
|
|
1
|
+
import { RapidRequest } from "~/core/request";
|
|
2
|
+
import { RunProxyHandlerOptions } from "../types";
|
|
3
|
+
import { RapidResponse } from "~/core/response";
|
|
4
|
+
|
|
5
|
+
export interface ProxyContext {
|
|
6
|
+
sourceContext: ProxySourceContext;
|
|
7
|
+
targetContext: ProxyTargetContext;
|
|
8
|
+
options: ProxyOptions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ProxySourceContext {
|
|
12
|
+
request: RapidRequest;
|
|
13
|
+
response: RapidResponse;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ProxyTargetContext {
|
|
17
|
+
request?: RapidRequest;
|
|
18
|
+
response?: RapidResponse;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ProxyOptions = RunProxyHandlerOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./queryBuilder";
|
|
1
|
+
export * from "./queryBuilder";
|
package/src/server.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DataAccessor from "./dataAccess/dataAccessor";
|
|
2
|
-
import { GetDataAccessorOptions, GetModelOptions, IDatabaseAccessor, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes, RapidServerConfig, RpdDataModelProperty, CreateEntityOptions, UpdateEntityByIdOptions, EntityWatchHandlerContext, EntityWatcherType, RpdEntityCreateEventPayload } from "./types";
|
|
2
|
+
import { GetDataAccessorOptions, GetModelOptions, IDatabaseAccessor, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RpdApplicationConfig, RpdDataModel, RpdServerEventTypes, RapidServerConfig, RpdDataModelProperty, CreateEntityOptions, UpdateEntityByIdOptions, EntityWatchHandlerContext, EntityWatcherType, RpdEntityCreateEventPayload, EmitServerEventOptions } from "./types";
|
|
3
3
|
|
|
4
4
|
import QueryBuilder from "./queryBuilder/queryBuilder";
|
|
5
5
|
import PluginManager from "./core/pluginManager";
|
|
@@ -237,9 +237,10 @@ export class RapidServer implements IRpdServer {
|
|
|
237
237
|
this.#entityWatchers.push(entityWatcher);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
async emitEvent<
|
|
240
|
+
async emitEvent<TEventName extends keyof RpdServerEventTypes>(event: EmitServerEventOptions<TEventName>) {
|
|
241
|
+
const { eventName, payload, sender, routeContext: routerContext } = event;
|
|
241
242
|
this.#logger.debug(`Emitting '${eventName}' event.`, { eventName, payload });
|
|
242
|
-
await this.#eventManager.emit<
|
|
243
|
+
await this.#eventManager.emit<TEventName>(eventName, sender, payload as any, routerContext);
|
|
243
244
|
|
|
244
245
|
// TODO: should move this logic into metaManager
|
|
245
246
|
// if (
|
|
@@ -392,11 +393,12 @@ export class RapidServer implements IRpdServer {
|
|
|
392
393
|
await this.#pluginManager.beforeUpdateEntity(model, options, currentEntity);
|
|
393
394
|
}
|
|
394
395
|
|
|
395
|
-
async #handleEntityEvent(eventName: keyof RpdServerEventTypes, sender: RapidPlugin, payload: RpdEntityCreateEventPayload) {
|
|
396
|
+
async #handleEntityEvent(eventName: keyof RpdServerEventTypes, sender: RapidPlugin, payload: RpdEntityCreateEventPayload, routerContext?: RouteContext) {
|
|
396
397
|
const { modelSingularCode, baseModelSingularCode } = payload;
|
|
397
398
|
const entityWatchHandlerContext: EntityWatchHandlerContext<typeof eventName> = {
|
|
398
399
|
server: this,
|
|
399
400
|
payload,
|
|
401
|
+
routerContext,
|
|
400
402
|
};
|
|
401
403
|
|
|
402
404
|
let emitter: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|