adminforth 1.3.26 → 1.3.28
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/auth.ts +0 -1
- package/dataConnectors/baseConnector.ts +19 -7
- package/dataConnectors/clickhouse.ts +1 -2
- package/dataConnectors/mongo.ts +1 -1
- package/dataConnectors/postgres.ts +1 -1
- package/dataConnectors/sqlite.ts +3 -3
- package/dist/dataConnectors/baseConnector.js +16 -4
- package/dist/dataConnectors/clickhouse.js +1 -2
- package/dist/dataConnectors/mongo.js +1 -1
- package/dist/dataConnectors/postgres.js +1 -1
- package/dist/dataConnectors/sqlite.js +3 -3
- package/dist/index.js +113 -21
- package/dist/modules/codeInjector.js +8 -8
- package/dist/modules/restApi.js +23 -88
- package/index.ts +128 -24
- package/modules/codeInjector.ts +8 -8
- package/modules/operationalResource.ts +2 -3
- package/modules/restApi.ts +23 -94
- package/package.json +1 -1
- package/spa/src/components/ResourceForm.vue +6 -16
- package/spa/src/utils.ts +34 -1
- package/types/AdminForthConfig.ts +37 -11
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
|
|
146
146
|
import CustomDatePicker from "@/components/CustomDatePicker.vue";
|
|
147
147
|
import Dropdown from '@/components/Dropdown.vue';
|
|
148
|
-
import { callAdminForthApi, getCustomComponent } from '@/utils';
|
|
148
|
+
import { applyRegexValidation, callAdminForthApi, getCustomComponent } from '@/utils';
|
|
149
149
|
import { IconExclamationCircleSolid, IconEyeSlashSolid, IconEyeSolid } from '@iconify-prerendered/vue-flowbite';
|
|
150
150
|
import { computedAsync } from '@vueuse/core';
|
|
151
151
|
import { initFlowbite } from 'flowbite';
|
|
@@ -172,7 +172,7 @@ const currentValues = ref(null);
|
|
|
172
172
|
|
|
173
173
|
const customComponentsInValidity = ref({});
|
|
174
174
|
const customComponentsEmptiness = ref({});
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
|
|
177
177
|
const columnError = (column) => {
|
|
178
178
|
const val = computed(() => {
|
|
@@ -212,22 +212,12 @@ const columnError = (column) => {
|
|
|
212
212
|
return `This field must be less than ${column.maxValue}`;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
if ( column.validation && column.validation.length ) {
|
|
216
|
-
const validationArray = column.validation;
|
|
217
|
-
for (let i = 0; i < validationArray.length; i++) {
|
|
218
|
-
if (validationArray[i].regExp) {
|
|
219
|
-
const regExp = new RegExp(validationArray[i].regExp);
|
|
220
|
-
let value = currentValues.value[column.name];
|
|
221
|
-
if (value === undefined || value === null) {
|
|
222
|
-
value = '';
|
|
223
|
-
}
|
|
224
|
-
if (!regExp.test(value)) {
|
|
225
|
-
return validationArray[i].message;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
215
|
|
|
216
|
+
const error = applyRegexValidation(currentValues.value[column.name], column.validation);
|
|
217
|
+
if (error) {
|
|
218
|
+
return error;
|
|
230
219
|
}
|
|
220
|
+
|
|
231
221
|
return null;
|
|
232
222
|
});
|
|
233
223
|
return val.value;
|
package/spa/src/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { onMounted, ref, resolveComponent } from 'vue';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CoreConfig } from './spa_types/core';
|
|
3
|
+
import type { ValidationObject } from './types/AdminForthConfig';
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
import router from "./router";
|
|
5
7
|
import { useCoreStore } from './stores/core';
|
|
@@ -113,4 +115,35 @@ export function initThreeDotsDropdown() {
|
|
|
113
115
|
dd.hide();
|
|
114
116
|
}
|
|
115
117
|
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function applyRegexValidation(value: any, validation: ValidationObject[] | undefined) {
|
|
121
|
+
|
|
122
|
+
if ( validation?.length ) {
|
|
123
|
+
const validationArray = validation;
|
|
124
|
+
for (let i = 0; i < validationArray.length; i++) {
|
|
125
|
+
if (validationArray[i].regExp) {
|
|
126
|
+
let flags = '';
|
|
127
|
+
if (validationArray[i].caseSensitive) {
|
|
128
|
+
flags += 'i';
|
|
129
|
+
}
|
|
130
|
+
if (validationArray[i].multiline) {
|
|
131
|
+
flags += 'm';
|
|
132
|
+
}
|
|
133
|
+
if (validationArray[i].global) {
|
|
134
|
+
flags += 'g';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const regExp = new RegExp(validationArray[i].regExp, flags);
|
|
138
|
+
if (value === undefined || value === null) {
|
|
139
|
+
value = '';
|
|
140
|
+
}
|
|
141
|
+
let valueS = `${value}`;
|
|
142
|
+
|
|
143
|
+
if (!regExp.test(valueS)) {
|
|
144
|
+
return validationArray[i].message;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
116
149
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Express } from 'express';
|
|
2
|
-
import OperationalResource from '../modules/operationalResource.js';
|
|
3
2
|
|
|
4
3
|
export interface ICodeInjector {
|
|
5
4
|
srcFoldersToSync: Object;
|
|
@@ -190,14 +189,12 @@ export interface IAdminForthDataSourceConnector {
|
|
|
190
189
|
createRecordOriginalValues({ resource, record }: { resource: AdminForthResource, record: any }): Promise<void>;
|
|
191
190
|
|
|
192
191
|
/**
|
|
193
|
-
*
|
|
192
|
+
* Update record in database. newValues might have not all fields in record, but only changed ones.
|
|
194
193
|
* recordId is value of field which is marked as {@link AdminForthResourceColumn.primaryKey}
|
|
195
|
-
* newValues is array of fields which should be updated (might be not all fields in record, but only changed fields).
|
|
196
194
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
updateRecordOriginalValues({ resource, recordId, newValues }: { resource: AdminForthResource; recordId: string; newValues: any; }): Promise<void>;
|
|
196
|
+
|
|
197
|
+
|
|
201
198
|
/**
|
|
202
199
|
* Used to delete record in database.
|
|
203
200
|
*/
|
|
@@ -229,12 +226,18 @@ export interface IAdminForthDataSourceConnectorBase extends IAdminForthDataSourc
|
|
|
229
226
|
adminUser: AdminUser
|
|
230
227
|
}): Promise<{ok: boolean, error?: string, createdRecord?: any}>;
|
|
231
228
|
|
|
229
|
+
updateRecord({ resource, recordId, newValues }: {
|
|
230
|
+
resource: AdminForthResource,
|
|
231
|
+
recordId: string,
|
|
232
|
+
newValues: any,
|
|
233
|
+
}): Promise<{ok: boolean, error?: string}>;
|
|
234
|
+
|
|
232
235
|
getMinMaxForColumns({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
|
|
233
236
|
}
|
|
234
237
|
|
|
235
238
|
|
|
236
239
|
export interface IAdminForthDataSourceConnectorConstructor {
|
|
237
|
-
new ({ url }: { url: string }):
|
|
240
|
+
new ({ url }: { url: string }): IAdminForthDataSourceConnectorBase;
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
export interface IAdminForthAuth {
|
|
@@ -267,7 +270,15 @@ export interface IAdminForth {
|
|
|
267
270
|
|
|
268
271
|
createResourceRecord(
|
|
269
272
|
params: { resource: AdminForthResource, record: any, adminUser: AdminUser }
|
|
270
|
-
): Promise<{
|
|
273
|
+
): Promise<{ error?: string, createdRecord?: any }>;
|
|
274
|
+
|
|
275
|
+
updateResourceRecord(
|
|
276
|
+
params: { resource: AdminForthResource, recordId: any, record: any, oldRecord: any, adminUser: AdminUser }
|
|
277
|
+
): Promise<{ error?: string }>;
|
|
278
|
+
|
|
279
|
+
deleteResourceRecord(
|
|
280
|
+
params: { resource: AdminForthResource, recordId: string, adminUser: AdminUser, record: any }
|
|
281
|
+
): Promise<{ error?: string }>;
|
|
271
282
|
|
|
272
283
|
auth: IAdminForthAuth;
|
|
273
284
|
|
|
@@ -702,13 +713,13 @@ export type AfterDataSourceResponseFunction = (params: {resource: AdminForthReso
|
|
|
702
713
|
* Modify record to change how data is saved to database.
|
|
703
714
|
* Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
|
|
704
715
|
*/
|
|
705
|
-
export type BeforeSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
716
|
+
export type BeforeSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any, oldRecord?: any}) => Promise<{ok: boolean, error?: string}>;
|
|
706
717
|
|
|
707
718
|
/**
|
|
708
719
|
* Modify record to change how data is saved to database.
|
|
709
720
|
* Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
|
|
710
721
|
*/
|
|
711
|
-
export type AfterSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
|
|
722
|
+
export type AfterSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any, oldRecord?: any}) => Promise<{ok: boolean, error?: string}>;
|
|
712
723
|
|
|
713
724
|
/**
|
|
714
725
|
* Allow to get user data before login confirmation, will triger when user try to login.
|
|
@@ -1509,6 +1520,21 @@ export type ValidationObject = {
|
|
|
1509
1520
|
* Example: "Invalid email format"
|
|
1510
1521
|
*/
|
|
1511
1522
|
message: string,
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* Whether to check case sensitivity (i flag)
|
|
1526
|
+
*/
|
|
1527
|
+
caseSensitive: boolean,
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Whether to check Multiline strings (m flag)
|
|
1531
|
+
*/
|
|
1532
|
+
multiline: boolean,
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Whether to check global strings (g flag)
|
|
1536
|
+
*/
|
|
1537
|
+
global: boolean
|
|
1512
1538
|
}
|
|
1513
1539
|
|
|
1514
1540
|
export type AdminForthComponentDeclarationFull = {
|