adminforth 2.27.0-next.7 → 2.27.0-next.71

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 (110) hide show
  1. package/commands/callTsProxy.js +10 -5
  2. package/commands/createApp/templates/api.ts.hbs +28 -9
  3. package/commands/createApp/templates/package.json.hbs +2 -1
  4. package/commands/proxy.ts +18 -10
  5. package/dist/basePlugin.js +1 -1
  6. package/dist/basePlugin.js.map +1 -1
  7. package/dist/commands/proxy.js +14 -10
  8. package/dist/commands/proxy.js.map +1 -1
  9. package/dist/dataConnectors/baseConnector.d.ts +10 -4
  10. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  11. package/dist/dataConnectors/baseConnector.js +76 -54
  12. package/dist/dataConnectors/baseConnector.js.map +1 -1
  13. package/dist/dataConnectors/clickhouse.d.ts +5 -2
  14. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  15. package/dist/dataConnectors/clickhouse.js +76 -10
  16. package/dist/dataConnectors/clickhouse.js.map +1 -1
  17. package/dist/dataConnectors/mongo.d.ts.map +1 -1
  18. package/dist/dataConnectors/mongo.js +3 -1
  19. package/dist/dataConnectors/mongo.js.map +1 -1
  20. package/dist/dataConnectors/mysql.d.ts.map +1 -1
  21. package/dist/dataConnectors/mysql.js +3 -1
  22. package/dist/dataConnectors/mysql.js.map +1 -1
  23. package/dist/dataConnectors/postgres.d.ts.map +1 -1
  24. package/dist/dataConnectors/postgres.js +3 -1
  25. package/dist/dataConnectors/postgres.js.map +1 -1
  26. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  27. package/dist/dataConnectors/sqlite.js +4 -2
  28. package/dist/dataConnectors/sqlite.js.map +1 -1
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +17 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/modules/configValidator.d.ts.map +1 -1
  34. package/dist/modules/configValidator.js +16 -9
  35. package/dist/modules/configValidator.js.map +1 -1
  36. package/dist/modules/restApi.d.ts.map +1 -1
  37. package/dist/modules/restApi.js +598 -15
  38. package/dist/modules/restApi.js.map +1 -1
  39. package/dist/modules/styles.js +1 -1
  40. package/dist/modules/utils.d.ts +1 -1
  41. package/dist/modules/utils.d.ts.map +1 -1
  42. package/dist/modules/utils.js +3 -5
  43. package/dist/modules/utils.js.map +1 -1
  44. package/dist/servers/express.d.ts +18 -7
  45. package/dist/servers/express.d.ts.map +1 -1
  46. package/dist/servers/express.js +141 -1
  47. package/dist/servers/express.js.map +1 -1
  48. package/dist/servers/openapi.d.ts +25 -0
  49. package/dist/servers/openapi.d.ts.map +1 -0
  50. package/dist/servers/openapi.js +92 -0
  51. package/dist/servers/openapi.js.map +1 -0
  52. package/dist/servers/openapiDocument.d.ts +12 -0
  53. package/dist/servers/openapiDocument.d.ts.map +1 -0
  54. package/dist/servers/openapiDocument.js +313 -0
  55. package/dist/servers/openapiDocument.js.map +1 -0
  56. package/dist/spa/package-lock.json +41 -0
  57. package/dist/spa/package.json +4 -0
  58. package/dist/spa/pnpm-lock.yaml +384 -310
  59. package/dist/spa/pnpm-workspace.yaml +4 -0
  60. package/dist/spa/src/App.vue +78 -76
  61. package/dist/spa/src/afcl/Button.vue +2 -3
  62. package/dist/spa/src/afcl/Dialog.vue +1 -1
  63. package/dist/spa/src/afcl/Input.vue +1 -1
  64. package/dist/spa/src/afcl/Select.vue +8 -2
  65. package/dist/spa/src/afcl/Skeleton.vue +5 -0
  66. package/dist/spa/src/afcl/Spinner.vue +1 -1
  67. package/dist/spa/src/components/CallActionWrapper.vue +1 -1
  68. package/dist/spa/src/components/ColumnValueInput.vue +16 -3
  69. package/dist/spa/src/components/ColumnValueInputWrapper.vue +25 -2
  70. package/dist/spa/src/components/CustomRangePicker.vue +10 -14
  71. package/dist/spa/src/components/Filters.vue +95 -63
  72. package/dist/spa/src/components/GroupsTable.vue +9 -6
  73. package/dist/spa/src/components/MenuLink.vue +2 -2
  74. package/dist/spa/src/components/ResourceForm.vue +103 -9
  75. package/dist/spa/src/components/ResourceListTable.vue +16 -10
  76. package/dist/spa/src/components/ShowTable.vue +3 -3
  77. package/dist/spa/src/components/Sidebar.vue +29 -8
  78. package/dist/spa/src/components/ThreeDotsMenu.vue +25 -9
  79. package/dist/spa/src/components/ValueRenderer.vue +1 -0
  80. package/dist/spa/src/controls/BoolToggle.vue +2 -2
  81. package/dist/spa/src/renderers/RichText.vue +2 -2
  82. package/dist/spa/src/renderers/ZeroStylesRichText.vue +2 -2
  83. package/dist/spa/src/spa_types/core.ts +32 -0
  84. package/dist/spa/src/stores/core.ts +16 -2
  85. package/dist/spa/src/stores/filters.ts +16 -12
  86. package/dist/spa/src/types/Back.ts +137 -26
  87. package/dist/spa/src/types/Common.ts +25 -6
  88. package/dist/spa/src/types/adapters/CompletionAdapter.ts +27 -5
  89. package/dist/spa/src/types/adapters/index.ts +2 -2
  90. package/dist/spa/src/utils/createEditUtils.ts +65 -0
  91. package/dist/spa/src/utils/index.ts +2 -1
  92. package/dist/spa/src/utils/listUtils.ts +3 -3
  93. package/dist/spa/src/utils/utils.ts +42 -7
  94. package/dist/spa/src/utils.ts +2 -1
  95. package/dist/spa/src/views/CreateEditSkeleton.vue +74 -0
  96. package/dist/spa/src/views/CreateView.vue +24 -50
  97. package/dist/spa/src/views/EditView.vue +23 -40
  98. package/dist/spa/src/views/ListView.vue +22 -32
  99. package/dist/spa/src/views/ShowView.vue +66 -24
  100. package/dist/types/Back.d.ts +140 -32
  101. package/dist/types/Back.d.ts.map +1 -1
  102. package/dist/types/Back.js.map +1 -1
  103. package/dist/types/Common.d.ts +32 -6
  104. package/dist/types/Common.d.ts.map +1 -1
  105. package/dist/types/Common.js.map +1 -1
  106. package/dist/types/adapters/CompletionAdapter.d.ts +18 -3
  107. package/dist/types/adapters/CompletionAdapter.d.ts.map +1 -1
  108. package/dist/types/adapters/index.d.ts +1 -1
  109. package/dist/types/adapters/index.d.ts.map +1 -1
  110. package/package.json +11 -6
@@ -1,5 +1,7 @@
1
1
  import type { Express, Request, Response } from 'express';
2
+ import type { AnySchemaObject } from 'ajv';
2
3
  import type { Writable } from 'stream';
4
+ import type { ZodType } from 'zod';
3
5
 
4
6
  import { ActionCheckSource, AdminForthFilterOperators, AdminForthSortDirections, AllowedActionsEnum, AdminForthResourcePages,
5
7
  type AdminForthComponentDeclaration,
@@ -13,6 +15,7 @@ import { ActionCheckSource, AdminForthFilterOperators, AdminForthSortDirections,
13
15
  type AdminForthConfigMenuItem,
14
16
  type AnnouncementBadgeResponse,
15
17
  type AdminForthResourceColumnInputCommon,
18
+ type ColumnMinMaxValue,
16
19
  } from './Common.js';
17
20
 
18
21
  export interface ICodeInjector {
@@ -37,6 +40,81 @@ export interface IAdminForthHttpResponse {
37
40
  blobStream: () => Writable,
38
41
  };
39
42
 
43
+ export interface IAdminForthEndpointHandlerInput {
44
+ body: any;
45
+ adminUser: AdminUser | undefined;
46
+ query: {[key: string]: any};
47
+ headers: {[key: string]: any};
48
+ cookies: Array<{ key: string, value: string }>;
49
+ response: IAdminForthHttpResponse;
50
+ requestUrl: string;
51
+ abortSignal: AbortSignal;
52
+ _raw_express_req: Request;
53
+ _raw_express_res: Response;
54
+ tr: ITranslateFunction;
55
+ }
56
+
57
+ export interface IAdminForthEndpointOptions {
58
+ method: string,
59
+ noAuth?: boolean,
60
+ path: string,
61
+ description?: string,
62
+ request_schema?: AnySchemaObject,
63
+ response_schema?: AnySchemaObject,
64
+ responce_schema?: AnySchemaObject,
65
+ handler: (input: IAdminForthEndpointHandlerInput) => void | Promise<any>,
66
+ }
67
+
68
+ export type AdminForthExpressSchemaInput = AnySchemaObject | ZodType;
69
+
70
+ export interface IAdminForthExpressRouteSchema {
71
+ /**
72
+ * Detailed OpenAPI operation description for a custom Express route.
73
+ */
74
+ description?: string;
75
+
76
+ /**
77
+ * JSON schema or Zod schema describing the request body for a custom Express route.
78
+ */
79
+ request?: AdminForthExpressSchemaInput;
80
+
81
+ /**
82
+ * JSON schema or Zod schema describing the JSON response body for a custom Express route.
83
+ */
84
+ response?: AdminForthExpressSchemaInput;
85
+ }
86
+
87
+ export interface IRegisteredApiSchema {
88
+ method: string;
89
+ path: string;
90
+ description?: string;
91
+ request_schema?: AnySchemaObject;
92
+ response_schema?: AnySchemaObject;
93
+ }
94
+
95
+ export interface IAdminForthApiValidationError {
96
+ instancePath: string;
97
+ schemaPath: string;
98
+ keyword: string;
99
+ message?: string;
100
+ params: {[key: string]: any};
101
+ }
102
+
103
+ export interface IAdminForthApiValidationResult {
104
+ valid: boolean;
105
+ errors?: IAdminForthApiValidationError[];
106
+ }
107
+
108
+ export interface IOpenApiRegistry {
109
+ registeredSchemas: IRegisteredApiSchema[];
110
+
111
+ registerApiSchema(options: IAdminForthEndpointOptions): IRegisteredApiSchema;
112
+ register_api_schema(options: IAdminForthEndpointOptions): IRegisteredApiSchema;
113
+ validateRequestSchema(route: IRegisteredApiSchema | null, payload: any): IAdminForthApiValidationResult;
114
+ validateResponseSchema(route: IRegisteredApiSchema | null, payload: any): IAdminForthApiValidationResult;
115
+ renderOpenApiDocument(): {[key: string]: any};
116
+ }
117
+
40
118
  /**
41
119
  * Implement this interface to create custom HTTP server adapter for AdminForth.
42
120
  */
@@ -56,23 +134,7 @@ export interface IHttpServer {
56
134
  *
57
135
  * @param options : Object with method, path and handler properties.
58
136
  */
59
- endpoint(options: {
60
- method: string,
61
- noAuth?: boolean,
62
- path: string,
63
- handler: (
64
- body: any,
65
- adminUser: any,
66
- query: {[key: string]: string},
67
- headers: {[key: string]: string},
68
- cookies: {[key: string]: string},
69
- response: IAdminForthHttpResponse,
70
- requestUrl: string,
71
- abortSignal: AbortSignal,
72
- _raw_express_req: Request,
73
- _raw_express_res: Response,
74
- ) => void,
75
- }): void;
137
+ endpoint(options: IAdminForthEndpointOptions): void;
76
138
 
77
139
  }
78
140
 
@@ -106,14 +168,38 @@ export interface IExpressHttpServer extends IHttpServer {
106
168
  * ```
107
169
  *
108
170
  */
109
- authorize(callable: Function): void;
171
+ authorize(callable: (...args: any[]) => any): (...args: any[]) => any;
172
+
173
+ /**
174
+ * Method (middleware) to inject translation helper into Express request object.
175
+ */
176
+ translatable(callable: (...args: any[]) => any): (...args: any[]) => any;
177
+
178
+ /**
179
+ * Registers OpenAPI schemas for a custom Express route.
180
+ *
181
+ * Wrap this around the handler passed to `app.get/post/...`.
182
+ * If you also need authorization, make `withSchema` the outer wrapper:
183
+ *
184
+ * ```ts
185
+ * import * as z from 'zod';
186
+ *
187
+ * app.get('/myApi', admin.express.withSchema({
188
+ * description: 'Returns current user profile',
189
+ * response: z.object({ user: z.unknown() }),
190
+ * }, admin.express.authorize((req, res) => {
191
+ * res.json({ user: req.adminUser });
192
+ * })));
193
+ * ```
194
+ */
195
+ withSchema(schema: IAdminForthExpressRouteSchema, callable: (...args: any[]) => any): (...args: any[]) => any;
110
196
  }
111
197
 
112
198
  export interface ITranslateFunction {
113
199
  (
114
200
  msg: string,
115
201
  category: string,
116
- params: any,
202
+ params?: any,
117
203
  pluralizationNumber?: number
118
204
  ): Promise<string>;
119
205
  }
@@ -256,7 +342,7 @@ export interface IAdminForthDataSourceConnector {
256
342
  *
257
343
  * Internally should call {@link IAdminForthDataSourceConnector.getFieldValue} for both min and max values.
258
344
  */
259
- getMinMaxForColumnsWithOriginalTypes({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
345
+ getMinMaxForColumnsWithOriginalTypes({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<ColumnMinMaxValue>;
260
346
 
261
347
 
262
348
  /**
@@ -309,7 +395,7 @@ export interface IAdminForthDataSourceConnectorBase extends IAdminForthDataSourc
309
395
  newValues: any,
310
396
  }): Promise<{ok: boolean, error?: string}>;
311
397
 
312
- getMinMaxForColumns({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<{ [key: string]: { min: any, max: any } }>;
398
+ getMinMaxForColumns({ resource, columns }: { resource: AdminForthResource, columns: AdminForthResourceColumn[] }): Promise<ColumnMinMaxValue>;
313
399
 
314
400
  deleteMany?({resource, recordIds}:{resource: AdminForthResource, recordIds: any[]}): Promise<number>;
315
401
  }
@@ -358,7 +444,8 @@ export interface IAdminForthRestAPI {
358
444
  export interface IAdminForth {
359
445
  config: AdminForthConfig;
360
446
  codeInjector: ICodeInjector;
361
- express: IHttpServer;
447
+ express: IExpressHttpServer;
448
+ openApi: IOpenApiRegistry;
362
449
 
363
450
  restApi: IAdminForthRestAPI;
364
451
  activatedPlugins: Array<IAdminForthPlugin>;
@@ -455,6 +542,8 @@ export interface IAdminForth {
455
542
  * ```
456
543
  */
457
544
  getPluginById<T>(id: string): T;
545
+
546
+ refreshMenuBadge(menuItemId: string, adminUser: AdminUser): Promise<void>;
458
547
  }
459
548
 
460
549
 
@@ -532,7 +621,7 @@ export type BeforeDataSourceRequestFunction = (params: {
532
621
  body: any,
533
622
  query: Record<string, string>,
534
623
  headers: Record<string, string>,
535
- cookies: Record<string, string>,
624
+ cookies: { key: string, value: string }[],
536
625
  requestUrl: string,
537
626
  },
538
627
  filtersTools: any,
@@ -570,7 +659,7 @@ export interface HttpExtra {
570
659
  body: any,
571
660
  query: Record<string, string>,
572
661
  headers: Record<string, string>,
573
- cookies: Record<string, string>,
662
+ cookies: { key: string, value: string }[],
574
663
  requestUrl: string,
575
664
  meta?: any,
576
665
  response: IAdminForthHttpResponse
@@ -1305,6 +1394,19 @@ export interface AdminForthActionInput {
1305
1394
  standardAllowedActions: AllowedActions;
1306
1395
  }) => boolean;
1307
1396
  url?: string;
1397
+ bulkHandler?: (params: {
1398
+ adminforth: IAdminForth;
1399
+ resource: AdminForthResource;
1400
+ recordIds: (string | number)[];
1401
+ adminUser: AdminUser;
1402
+ response: IAdminForthHttpResponse;
1403
+ extra?: HttpExtra;
1404
+ tr: ITranslateFunction;
1405
+ }) => Promise<{
1406
+ ok: boolean;
1407
+ error?: string;
1408
+ successMessage?: string;
1409
+ }>;
1308
1410
  action?: (params: {
1309
1411
  adminforth: IAdminForth;
1310
1412
  resource: AdminForthResource;
@@ -1312,7 +1414,7 @@ export interface AdminForthActionInput {
1312
1414
  adminUser: AdminUser;
1313
1415
  response: IAdminForthHttpResponse;
1314
1416
  extra?: HttpExtra;
1315
- tr: Function;
1417
+ tr: ITranslateFunction;
1316
1418
  }) => Promise<{
1317
1419
  ok: boolean;
1318
1420
  error?: string;
@@ -1837,6 +1939,8 @@ export interface ResourceOptionsInput extends Omit<NonNullable<AdminForthResourc
1837
1939
  /**
1838
1940
  * Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
1839
1941
  * using checkboxes.
1942
+ * @deprecated Since 2.26.5. Will be removed in 3.0.0. Use `actions` instead.
1943
+
1840
1944
  */
1841
1945
  bulkActions?: Array<AdminForthBulkAction>,
1842
1946
 
@@ -2003,7 +2107,7 @@ export interface AdminForthBulkAction extends AdminForthBulkActionCommon {
2003
2107
  * It should return Promise which will be resolved when action is done.
2004
2108
  */
2005
2109
  action: ({ resource, selectedIds, adminUser, response, tr }: {
2006
- resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser, response: IAdminForthHttpResponse, tr: (key: string, category?: string, params?: any) => string
2110
+ resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser, response: IAdminForthHttpResponse, tr: ITranslateFunction
2007
2111
  }) => Promise<{ ok: boolean, error?: string, successMessage?: string }>,
2008
2112
 
2009
2113
  /**
@@ -2136,4 +2240,11 @@ export interface IWebSocketBroker {
2136
2240
  publish: (topic: string, data: any, filterUsers?: (adminUser: AdminUser) => Promise<boolean>) => void;
2137
2241
 
2138
2242
  registerWsClient: (client: IWebSocketClient) => void;
2243
+ }
2244
+ export interface PluginsCommonOptions {
2245
+ /**
2246
+ * Id of the plugin. It should be unique across all plugins.
2247
+ * It is required if you want to log custom actions, otherwise it is optional.
2248
+ */
2249
+ id?: string;
2139
2250
  }
@@ -303,7 +303,7 @@ export interface AdminForthComponentDeclarationFull {
303
303
  [key: string]: any,
304
304
  }
305
305
  }
306
- import { type AdminForthActionInput, type AdminForthResource } from './Back.js'
306
+ import { type IAdminForth, type AdminForthActionInput, type AdminForthResource } from './Back.js'
307
307
  export { type AdminForthActionInput } from './Back.js'
308
308
 
309
309
  export type AdminForthComponentDeclaration = AdminForthComponentDeclarationFull | string;
@@ -314,8 +314,9 @@ export type FieldGroup = {
314
314
  noTitle?: boolean;
315
315
  };
316
316
 
317
- export interface AdminForthActionFront extends Omit<AdminForthActionInput, 'id'> {
317
+ export interface AdminForthActionFront extends Omit<AdminForthActionInput, 'id' | 'bulkHandler' | 'action' | 'allowed'> {
318
318
  id: string;
319
+ hasBulkHandler?: boolean;
319
320
  }
320
321
 
321
322
  export interface AdminForthBulkActionFront extends Omit<AdminForthBulkActionCommon, 'id'> {
@@ -329,7 +330,7 @@ export interface AdminForthOptionsForFrontend extends Omit<AdminforthOptionsComm
329
330
  bulkActions?: AdminForthBulkActionFront[],
330
331
  }
331
332
 
332
- export interface AdminForthResourceFrontend extends Omit<AdminForthResourceCommon, 'options'> {
333
+ export interface AdminForthResourceFrontend extends Omit<AdminForthResourceCommon, 'options' | 'table' | 'dataSource'> {
333
334
  options: AdminForthOptionsForFrontend;
334
335
  }
335
336
 
@@ -610,14 +611,14 @@ export type ValidationObject = {
610
611
  * ```
611
612
  *
612
613
  */
613
- regExp: string,
614
+ regExp?: string,
614
615
 
615
616
  /**
616
617
  * Error message shown to user if validation fails
617
618
  *
618
619
  * Example: "Invalid email format"
619
620
  */
620
- message: string,
621
+ message?: string,
621
622
 
622
623
  /**
623
624
  * Whether to check case sensitivity (i flag)
@@ -633,6 +634,20 @@ export type ValidationObject = {
633
634
  * Whether to check global strings (g flag)
634
635
  */
635
636
  global?: boolean
637
+
638
+ /**
639
+ * Custom validator function.
640
+ *
641
+ * Example:
642
+ *
643
+ * ```ts
644
+ * validator: async (value) => {
645
+ * // custom validation logic
646
+ * return { isValid: true, message: 'Validation passed' }; // or { isValid: false, message: 'Validation failed' }
647
+ * }
648
+ * ```
649
+ */
650
+ validator?: (value: any, record: any, adminForth: IAdminForth) => {isValid: boolean, message?: string} | Promise<{isValid: boolean, message?: string}> | boolean,
636
651
  }
637
652
 
638
653
 
@@ -1149,7 +1164,7 @@ export interface AdminForthConfigMenuItem {
1149
1164
  * Optional callback which will be called before rendering the menu for each item.
1150
1165
  * Result of callback if not null will be used as a small badge near the menu item.
1151
1166
  */
1152
- badge?: string | ((user: AdminUser) => Promise<string>),
1167
+ badge?: string | number | ((user: AdminUser, adminForth: IAdminForth) => Promise<string | number> | string | number),
1153
1168
 
1154
1169
  /**
1155
1170
  * Tooltip shown on hover for badge
@@ -1242,4 +1257,8 @@ export interface GetBaseConfigResponse {
1242
1257
  config: AdminForthConfigForFrontend,
1243
1258
  adminUser: AdminUser,
1244
1259
  version: string,
1260
+ }
1261
+
1262
+ export interface ColumnMinMaxValue {
1263
+ [key: string]: { min: any, max: any }
1245
1264
  }
@@ -1,3 +1,18 @@
1
+ import type { JSONSchemaType } from "ajv";
2
+
3
+ export type CompletionStreamEvent = {
4
+ type: "output" | "reasoning";
5
+ delta: string;
6
+ text: string;
7
+ source?: "summary" | "text";
8
+ };
9
+
10
+ export type CompletionTool<Input = Record<string, any>, Output = any> = {
11
+ name: string;
12
+ input_schema: JSONSchemaType<Input>;
13
+ description?: string;
14
+ handler: (input: Input) => Promise<Output> | Output;
15
+ };
1
16
  export interface CompletionAdapter {
2
17
 
3
18
  /**
@@ -7,17 +22,24 @@ export interface CompletionAdapter {
7
22
  validate(): void;
8
23
 
9
24
  /**
10
- * This method should return a text completion based on the provided content and stop sequence.
25
+ * This method should return a text completion based on the provided content.
11
26
  * @param content - The input text to complete
12
- * @param stop - An array of stop sequences to indicate where to stop the completion
13
27
  * @param maxTokens - The maximum number of tokens to generate
28
+ * @param outputSchema - Optional structured output schema for the response
29
+ * @param reasoningEffort - Optional parameter to indicate the level of reasoning effort for the completion
30
+ * @param onChunk - Optional callback invoked for each streamed chunk or reasoning event
14
31
  * @returns A promise that resolves to an object containing the completed text and other metadata
15
32
  */
16
33
  complete(
17
34
  content: string,
18
- stop: string[],
19
35
  maxTokens: number,
20
- outputSchema?: any
36
+ outputSchema?: any,
37
+ reasoningEffort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh',
38
+ tools?: CompletionTool[],
39
+ onChunk?: (
40
+ chunk: string,
41
+ event?: CompletionStreamEvent,
42
+ ) => void | Promise<void>,
21
43
  ): Promise<{
22
44
  content?: string;
23
45
  finishReason?: string;
@@ -30,4 +52,4 @@ export interface CompletionAdapter {
30
52
  * @returns The number of tokens in the input content
31
53
  */
32
54
  measureTokensCount(content: string): Promise<number> | number;
33
- }
55
+ }
@@ -1,8 +1,8 @@
1
1
  export type { EmailAdapter } from './EmailAdapter.js';
2
- export type { CompletionAdapter } from './CompletionAdapter.js';
2
+ export type { CompletionAdapter, CompletionStreamEvent, CompletionTool } from './CompletionAdapter.js';
3
3
  export type { ImageGenerationAdapter } from './ImageGenerationAdapter.js';
4
4
  export type { KeyValueAdapter } from './KeyValueAdapter.js';
5
5
  export type { ImageVisionAdapter } from './ImageVisionAdapter.js';
6
6
  export type { OAuth2Adapter } from './OAuth2Adapter.js';
7
7
  export type { StorageAdapter } from './StorageAdapter.js';
8
- export type { CaptchaAdapter } from './CaptchaAdapter.js';
8
+ export type { CaptchaAdapter } from './CaptchaAdapter.js';
@@ -0,0 +1,65 @@
1
+ import type { AdminForthResourceColumn } from '@/types/Back';
2
+ import { useAdminforth } from '@/adminforth';
3
+ import { type Ref, nextTick } from 'vue';
4
+
5
+ export function scrollToInvalidField(resourceFormRef: any, t: (key: string) => string) {
6
+ const { alert } = useAdminforth();
7
+ let columnsWithErrors: {column: AdminForthResourceColumn, error: string}[] = [];
8
+ for (const column of resourceFormRef.value?.editableColumns || []) {
9
+ if (resourceFormRef.value?.columnsWithErrors[column.name]) {
10
+ columnsWithErrors.push({
11
+ column,
12
+ error: resourceFormRef.value?.columnsWithErrors[column.name]
13
+ });
14
+ }
15
+ }
16
+ const errorMessage = t('Failed to save. Please fix errors for the following fields:') + '<ul class="mt-2 list-disc list-inside">' + columnsWithErrors.map(c => `<li><strong>${c.column.label || c.column.name}</strong>: ${c.error}</li>`).join('') + '</ul>';
17
+ alert({
18
+ messageHtml: errorMessage,
19
+ variant: 'danger'
20
+ });
21
+ const firstInvalidElement = document.querySelector('.af-invalid-field-message');
22
+ if (firstInvalidElement) {
23
+ firstInvalidElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
24
+ }
25
+ }
26
+
27
+ export async function saveRecordPreparations(
28
+ viewMode: 'create' | 'edit',
29
+ validatingMode: Ref<boolean>,
30
+ resourceFormRef: Ref<any>,
31
+ isValid: Ref<boolean>,
32
+ t: (key: string) => string,
33
+ saving: Ref<boolean>,
34
+ runSaveInterceptors: any,
35
+ record: Ref<Record<string, any>>,
36
+ coreStore: any,
37
+ route: any
38
+ ) {
39
+ validatingMode.value = true;
40
+ await nextTick();
41
+ //wait for response for the user validation function if it exists
42
+ while (1) {
43
+ if (resourceFormRef.value?.isValidating) {
44
+ await new Promise(resolve => setTimeout(resolve, 100));
45
+ } else {
46
+ break;
47
+ }
48
+ }
49
+ if (!isValid.value) {
50
+ await nextTick();
51
+ scrollToInvalidField(resourceFormRef, t);
52
+ return;
53
+ } else {
54
+ validatingMode.value = false;
55
+ }
56
+
57
+ saving.value = true;
58
+ const interceptorsResult = await runSaveInterceptors({
59
+ action: viewMode,
60
+ values: record.value,
61
+ resource: coreStore.resource,
62
+ resourceId: route.params.resourceId as string,
63
+ });
64
+ return interceptorsResult;
65
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './utils';
2
- export * from './listUtils';
2
+ export * from './listUtils';
3
+ export * from './createEditUtils';
@@ -1,11 +1,11 @@
1
1
  import { nextTick, onMounted, ref, resolveComponent } from 'vue';
2
2
  import { callAdminForthApi } from '@/utils';
3
- import { type AdminForthResourceCommon } from '../types/Common';
3
+ import { type AdminForthResourceFrontend } from '../types/Common';
4
4
  import { useAdminforth } from '@/adminforth';
5
5
  import { showErrorTost } from '@/composables/useFrontendApi'
6
6
 
7
7
  let getResourceDataLastAbortController: AbortController | null = null;
8
- export async function getList(resource: AdminForthResourceCommon, isPageLoaded: boolean, page: number | null , pageSize: number, sort: any, checkboxes:{ value: any[] }, filters: any = [] ) {
8
+ export async function getList(resource: AdminForthResourceFrontend, isPageLoaded: boolean, page: number | null , pageSize: number, sort: any, checkboxes:{ value: any[] }, filters: any = [] ) {
9
9
  let rows: any[] = [];
10
10
  let totalRows: number | null = null;
11
11
  if (!isPageLoaded) {
@@ -53,7 +53,7 @@ export async function getList(resource: AdminForthResourceCommon, isPageLoaded:
53
53
 
54
54
 
55
55
 
56
- export async function startBulkAction(actionId: string, resource: AdminForthResourceCommon, checkboxes: { value: any[] },
56
+ export async function startBulkAction(actionId: string, resource: AdminForthResourceFrontend, checkboxes: { value: any[] },
57
57
  bulkActionLoadingStates: {value: Record<string, boolean>}, getListInner: () => Promise<any>) {
58
58
  const action = resource?.options?.bulkActions?.find(a => a.id === actionId);
59
59
  const { confirm, alert } = useAdminforth();
@@ -8,7 +8,7 @@ import { Dropdown } from 'flowbite';
8
8
  import adminforth, { useAdminforth } from '../adminforth';
9
9
  import sanitizeHtml from 'sanitize-html'
10
10
  import debounce from 'debounce';
11
- import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
11
+ import type { AdminForthActionFront, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, Predicate } from '@/types/Common';
12
12
  import { i18nInstance } from '../i18n'
13
13
  import { useI18n } from 'vue-i18n';
14
14
  import { onBeforeRouteLeave } from 'vue-router';
@@ -101,11 +101,13 @@ export async function callAdminForthApi(
101
101
  }
102
102
  }
103
103
 
104
- export function formatComponent(component: AdminForthComponentDeclaration): AdminForthComponentDeclarationFull {
104
+ export function formatComponent(component: AdminForthComponentDeclaration | undefined): AdminForthComponentDeclarationFull {
105
105
  if (typeof component === 'string') {
106
106
  return { file: component, meta: {} };
107
- } else {
107
+ } else if (typeof component === 'object') {
108
108
  return { file: component.file, meta: component.meta };
109
+ } else {
110
+ return { file: '', meta: {} };
109
111
  }
110
112
  }
111
113
 
@@ -191,7 +193,8 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
191
193
  if ( validation?.length ) {
192
194
  const validationArray = validation;
193
195
  for (let i = 0; i < validationArray.length; i++) {
194
- if (validationArray[i].regExp) {
196
+ const regExpPattern = validationArray[i].regExp;
197
+ if (regExpPattern) {
195
198
  let flags = '';
196
199
  if (validationArray[i].caseSensitive) {
197
200
  flags += 'i';
@@ -203,7 +206,7 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
203
206
  flags += 'g';
204
207
  }
205
208
 
206
- const regExp = new RegExp(validationArray[i].regExp, flags);
209
+ const regExp = new RegExp(regExpPattern, flags);
207
210
  if (value === undefined || value === null) {
208
211
  value = '';
209
212
  }
@@ -766,6 +769,7 @@ export async function executeCustomBulkAction({
766
769
  onError,
767
770
  setLoadingState,
768
771
  confirmMessage,
772
+ resource,
769
773
  }: {
770
774
  actionId: string | number | undefined,
771
775
  resourceId: string,
@@ -775,6 +779,7 @@ export async function executeCustomBulkAction({
775
779
  onError?: (error: string) => void,
776
780
  setLoadingState?: (loading: boolean) => void,
777
781
  confirmMessage?: string,
782
+ resource?: AdminForthResourceFrontend,
778
783
  }): Promise<any> {
779
784
  if (!recordIds || recordIds.length === 0) {
780
785
  if (onError) {
@@ -796,7 +801,38 @@ export async function executeCustomBulkAction({
796
801
  setLoadingState?.(true);
797
802
 
798
803
  try {
799
- // Execute action for all records in parallel using Promise.all
804
+ const action = resource?.options?.actions?.find((a: any) => a.id === actionId) as AdminForthActionFront | undefined;
805
+
806
+ if (action?.hasBulkHandler && action?.showIn?.bulkButton) {
807
+ const result = await callAdminForthApi({
808
+ path: '/start_custom_bulk_action',
809
+ method: 'POST',
810
+ body: {
811
+ resourceId,
812
+ actionId,
813
+ recordIds,
814
+ extra: extra || {},
815
+ }
816
+ });
817
+
818
+ if (result?.ok) {
819
+ if (onSuccess) {
820
+ await onSuccess([result]);
821
+ }
822
+ return { ok: true, results: [result] };
823
+ }
824
+
825
+ if (result?.error) {
826
+ if (onError) {
827
+ onError(result.error);
828
+ }
829
+ return { error: result.error };
830
+ }
831
+
832
+ return result;
833
+ }
834
+
835
+ // Per-record parallel calls (legacy path)
800
836
  const results = await Promise.all(
801
837
  recordIds.map(recordId =>
802
838
  callAdminForthApi({
@@ -811,7 +847,6 @@ export async function executeCustomBulkAction({
811
847
  })
812
848
  )
813
849
  );
814
-
815
850
  const lastResult = results[results.length - 1];
816
851
  if (lastResult?.redirectUrl) {
817
852
  if (lastResult.redirectUrl.includes('target=_blank')) {
@@ -1,2 +1,3 @@
1
1
  export * from './utils/utils';
2
- export * from './utils/listUtils';
2
+ export * from './utils/listUtils';
3
+ export * from './utils/createEditUtils';