@ruiapp/rapid-core 0.1.56 → 0.1.58

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/index.js CHANGED
@@ -1809,7 +1809,7 @@ function getEntityPropertiesIncludingBase(server, model) {
1809
1809
  });
1810
1810
  let baseProperties = [];
1811
1811
  if (baseModel) {
1812
- baseModel.properties.map((property) => {
1812
+ baseProperties = baseModel.properties.map((property) => {
1813
1813
  property = lodash.cloneDeep(property);
1814
1814
  property.isBaseProperty = true;
1815
1815
  return property;
@@ -2604,6 +2604,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
2604
2604
  modelSingularCode: model.singularCode,
2605
2605
  before: entity,
2606
2606
  changes: options.entityToSave,
2607
+ operation: options.operation,
2608
+ stateProperties: options.stateProperties,
2607
2609
  },
2608
2610
  sender: plugin,
2609
2611
  routeContext: options.routeContext,
@@ -2766,6 +2768,8 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
2766
2768
  before: entity,
2767
2769
  after: updatedEntity,
2768
2770
  changes: changes,
2771
+ operation: options.operation,
2772
+ stateProperties: options.stateProperties,
2769
2773
  },
2770
2774
  sender: plugin,
2771
2775
  routeContext: options.routeContext,
package/dist/types.d.ts CHANGED
@@ -84,6 +84,10 @@ export interface RpdEntityBeforeUpdateEventPayload {
84
84
  baseModelSingularCode?: string;
85
85
  before: any;
86
86
  changes: any;
87
+ operation?: {
88
+ type: string;
89
+ };
90
+ stateProperties?: string[];
87
91
  }
88
92
  export interface RpdEntityUpdateEventPayload {
89
93
  namespace: string;
@@ -92,6 +96,10 @@ export interface RpdEntityUpdateEventPayload {
92
96
  before: any;
93
97
  after: any;
94
98
  changes: any;
99
+ operation?: {
100
+ type: string;
101
+ };
102
+ stateProperties?: string[];
95
103
  }
96
104
  export interface RpdEntityBeforeDeleteEventPayload {
97
105
  namespace: string;
@@ -412,7 +420,9 @@ export interface UpdateEntityByIdOptions {
412
420
  routeContext?: RouteContext;
413
421
  id: any;
414
422
  entityToSave: any;
415
- operation?: any;
423
+ operation?: {
424
+ type: string;
425
+ };
416
426
  stateProperties?: string[];
417
427
  }
418
428
  export interface DeleteEntityOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- export type HttpStatus = number;
2
- export type ResponseData = string | ArrayBuffer | ReadableStream;
3
-
4
- export type HeadersDefinition = [string, string][] | Record<string, string>;
1
+ export type HttpStatus = number;
2
+ export type ResponseData = string | ArrayBuffer | ReadableStream;
3
+
4
+ export type HeadersDefinition = [string, string][] | Record<string, string>;
@@ -721,6 +721,8 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
721
721
  modelSingularCode: model.singularCode,
722
722
  before: entity,
723
723
  changes: options.entityToSave,
724
+ operation: options.operation,
725
+ stateProperties: options.stateProperties,
724
726
  },
725
727
  sender: plugin,
726
728
  routeContext: options.routeContext,
@@ -894,6 +896,8 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
894
896
  before: entity,
895
897
  after: updatedEntity,
896
898
  changes: changes,
899
+ operation: options.operation,
900
+ stateProperties: options.stateProperties,
897
901
  },
898
902
  sender: plugin,
899
903
  routeContext: options.routeContext,
@@ -16,7 +16,7 @@ export function getEntityPropertiesIncludingBase(server: IRpdServer, model: RpdD
16
16
  });
17
17
  let baseProperties: RpdDataModelProperty[] = [];
18
18
  if (baseModel) {
19
- baseModel.properties.map((property) => {
19
+ baseProperties = baseModel.properties.map((property) => {
20
20
  property = cloneDeep(property);
21
21
  property.isBaseProperty = true;
22
22
  return property;
@@ -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
+ }
@@ -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;
@@ -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/types.ts CHANGED
@@ -99,6 +99,10 @@ export interface RpdEntityBeforeUpdateEventPayload {
99
99
  baseModelSingularCode?: string;
100
100
  before: any;
101
101
  changes: any;
102
+ operation?: {
103
+ type: string;
104
+ };
105
+ stateProperties?: string[];
102
106
  }
103
107
 
104
108
  export interface RpdEntityUpdateEventPayload {
@@ -108,6 +112,10 @@ export interface RpdEntityUpdateEventPayload {
108
112
  before: any;
109
113
  after: any;
110
114
  changes: any;
115
+ operation?: {
116
+ type: string;
117
+ };
118
+ stateProperties?: string[];
111
119
  }
112
120
 
113
121
  export interface RpdEntityBeforeDeleteEventPayload {
@@ -481,7 +489,9 @@ export interface UpdateEntityByIdOptions {
481
489
  routeContext?: RouteContext;
482
490
  id: any;
483
491
  entityToSave: any;
484
- operation?: any;
492
+ operation?: {
493
+ type: string;
494
+ };
485
495
  stateProperties?: string[];
486
496
  }
487
497
 
@@ -1,5 +1,5 @@
1
- import { RpdDataModelProperty } from "../types";
2
-
3
- export function isRelationProperty(property: RpdDataModelProperty) {
4
- return property.type === "relation" || property.type === "relation[]";
5
- }
1
+ import { RpdDataModelProperty } from "../types";
2
+
3
+ export function isRelationProperty(property: RpdDataModelProperty) {
4
+ return property.type === "relation" || property.type === "relation[]";
5
+ }
@@ -1,11 +1,11 @@
1
- export function isUndefined(val: any) {
2
- return typeof val === "undefined";
3
- }
4
-
5
- export function isNull(val: any) {
6
- return val === null;
7
- }
8
-
9
- export function isNullOrUndefined(val: any) {
10
- return isNull(val) || isUndefined(val);
11
- }
1
+ export function isUndefined(val: any) {
2
+ return typeof val === "undefined";
3
+ }
4
+
5
+ export function isNull(val: any) {
6
+ return val === null;
7
+ }
8
+
9
+ export function isNullOrUndefined(val: any) {
10
+ return isNull(val) || isUndefined(val);
11
+ }