@taruvi/refine-providers 1.1.6 → 1.1.8
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/README.md +101 -39
- package/dist/index.cjs +159 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -23
- package/dist/index.d.ts +44 -23
- package/dist/index.js +160 -96
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataProvider, AuthProvider, AccessControlProvider, MetaQuery, CrudFilter, CrudSort, Pagination } from '@refinedev/core';
|
|
2
|
-
import { Client } from '@taruvi/sdk';
|
|
2
|
+
import { Client, GraphFormat, GraphInclude } from '@taruvi/sdk';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a Refine DataProvider for Taruvi database operations.
|
|
@@ -20,36 +20,52 @@ interface StorageUploadVariables {
|
|
|
20
20
|
declare function storageDataProvider(client: Client): DataProvider;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Meta options for function execution via custom().
|
|
24
24
|
*/
|
|
25
25
|
interface FunctionMeta {
|
|
26
|
+
kind: "function";
|
|
26
27
|
/** Whether to execute the function asynchronously */
|
|
27
28
|
async?: boolean;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Meta options for analytics query execution via custom().
|
|
32
|
+
*/
|
|
33
|
+
interface AnalyticsMeta {
|
|
34
|
+
kind: "analytics";
|
|
35
|
+
}
|
|
36
|
+
type AppCustomMeta = FunctionMeta | AnalyticsMeta;
|
|
31
37
|
/**
|
|
32
38
|
* Creates a Refine DataProvider for Taruvi App operations.
|
|
33
39
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* -
|
|
38
|
-
* - "settings" (getOne): Fetch app settings
|
|
40
|
+
* Supported operations:
|
|
41
|
+
* - getList("roles"): Fetch app roles
|
|
42
|
+
* - getOne("settings"): Fetch app settings
|
|
43
|
+
* - custom(): Execute edge functions or analytics queries via meta.kind
|
|
39
44
|
*
|
|
40
45
|
* @example
|
|
41
46
|
* ```typescript
|
|
42
47
|
* // Get app roles
|
|
43
|
-
*
|
|
48
|
+
* useList({ dataProviderName: "app", resource: "roles" });
|
|
49
|
+
*
|
|
50
|
+
* // Get app settings
|
|
51
|
+
* useOne({ dataProviderName: "app", resource: "settings", id: "" });
|
|
52
|
+
*
|
|
53
|
+
* // Execute an edge function
|
|
54
|
+
* useCustom({
|
|
44
55
|
* dataProviderName: "app",
|
|
45
|
-
*
|
|
56
|
+
* url: "process-order",
|
|
57
|
+
* method: "post",
|
|
58
|
+
* config: { payload: { orderId: 123 } },
|
|
59
|
+
* meta: { kind: "function", async: false },
|
|
46
60
|
* });
|
|
47
61
|
*
|
|
48
|
-
* //
|
|
49
|
-
*
|
|
62
|
+
* // Execute an analytics query
|
|
63
|
+
* useCustom({
|
|
50
64
|
* dataProviderName: "app",
|
|
51
|
-
*
|
|
52
|
-
*
|
|
65
|
+
* url: "monthly-report",
|
|
66
|
+
* method: "post",
|
|
67
|
+
* config: { payload: { period: "Q1" } },
|
|
68
|
+
* meta: { kind: "analytics" },
|
|
53
69
|
* });
|
|
54
70
|
* ```
|
|
55
71
|
*/
|
|
@@ -96,13 +112,10 @@ declare function appDataProvider(client: Client): DataProvider;
|
|
|
96
112
|
*/
|
|
97
113
|
declare function userDataProvider(client: Client): DataProvider;
|
|
98
114
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/** Additional parameters to pass to the analytics query */
|
|
104
|
-
params?: Record<string, unknown>;
|
|
105
|
-
}
|
|
115
|
+
/** @deprecated Use `appDataProvider` with `useCustom` and `meta.kind: "function"` instead. */
|
|
116
|
+
declare function functionsDataProvider(client: Client): DataProvider;
|
|
117
|
+
|
|
118
|
+
/** @deprecated Use `appDataProvider` with `useCustom` and `meta.kind: "analytics"` instead. */
|
|
106
119
|
declare function analyticsDataProvider(client: Client): DataProvider;
|
|
107
120
|
|
|
108
121
|
/**
|
|
@@ -203,6 +216,14 @@ interface TaruviMeta extends MetaQuery {
|
|
|
203
216
|
groupBy?: string[];
|
|
204
217
|
/** Filters for aggregate results (same format as regular filters) */
|
|
205
218
|
having?: CrudFilter[];
|
|
219
|
+
/** Graph format: 'tree' or 'graph' */
|
|
220
|
+
format?: GraphFormat;
|
|
221
|
+
/** Graph traversal direction */
|
|
222
|
+
include?: GraphInclude;
|
|
223
|
+
/** Graph traversal depth */
|
|
224
|
+
depth?: number;
|
|
225
|
+
/** Graph edge types to filter */
|
|
226
|
+
graph_types?: string[];
|
|
206
227
|
}
|
|
207
228
|
/**
|
|
208
229
|
* Response wrapper for Taruvi list endpoints.
|
|
@@ -257,4 +278,4 @@ declare function buildQueryString(params?: Record<string, unknown>): string;
|
|
|
257
278
|
*/
|
|
258
279
|
declare function handleError(error: unknown): never;
|
|
259
280
|
|
|
260
|
-
export { type AnalyticsMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
|
|
281
|
+
export { type AnalyticsMeta, type AppCustomMeta, type FunctionMeta, type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, accessControlProvider, analyticsDataProvider, appDataProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, functionsDataProvider, handleError, storageDataProvider, userDataProvider };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Database, Storage, Functions, App, User,
|
|
1
|
+
import { Graph, Database, Storage, Functions, Analytics, App, User, Auth, Policy } from '@taruvi/sdk';
|
|
2
2
|
import DataLoader2 from 'dataloader';
|
|
3
3
|
|
|
4
4
|
// src/dataProvider.ts
|
|
@@ -80,6 +80,18 @@ function applyPopulate(query, meta) {
|
|
|
80
80
|
const populateArray = Array.isArray(meta.populate) ? meta.populate : meta.populate.split(",").map((s) => s.trim());
|
|
81
81
|
return query.populate(populateArray);
|
|
82
82
|
}
|
|
83
|
+
function isGraphQuery(meta) {
|
|
84
|
+
return !!(meta?.format || meta?.graph_types || meta?.include || meta?.depth);
|
|
85
|
+
}
|
|
86
|
+
function buildGraphQuery(client, tableName, meta, recordId) {
|
|
87
|
+
let query = new Graph(client).from(tableName);
|
|
88
|
+
if (recordId) query = query.get(recordId);
|
|
89
|
+
if (meta?.format) query = query.format(meta.format);
|
|
90
|
+
if (meta?.include) query = query.include(meta.include);
|
|
91
|
+
if (meta?.depth) query = query.depth(meta.depth);
|
|
92
|
+
if (meta?.graph_types) query = query.types(meta.graph_types);
|
|
93
|
+
return query;
|
|
94
|
+
}
|
|
83
95
|
function dataProvider(client) {
|
|
84
96
|
const config = client.getConfig();
|
|
85
97
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
@@ -90,6 +102,12 @@ function dataProvider(client) {
|
|
|
90
102
|
const { resource, pagination, filters, sorters, meta } = params;
|
|
91
103
|
const taruviMeta = meta;
|
|
92
104
|
const tableName = getTableName(resource, taruviMeta);
|
|
105
|
+
if (isGraphQuery(taruviMeta)) {
|
|
106
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta).execute();
|
|
107
|
+
const data = Array.isArray(response2) ? response2 : response2?.data ?? [];
|
|
108
|
+
const total = response2?.total ?? data.length;
|
|
109
|
+
return { data, total };
|
|
110
|
+
}
|
|
93
111
|
let query = new Database(client).from(tableName);
|
|
94
112
|
query = applyFilters(query, filters);
|
|
95
113
|
query = applySorters(query, sorters);
|
|
@@ -102,6 +120,11 @@ function dataProvider(client) {
|
|
|
102
120
|
const { resource, id, meta } = params;
|
|
103
121
|
const taruviMeta = meta;
|
|
104
122
|
const tableName = getTableName(resource, taruviMeta);
|
|
123
|
+
if (isGraphQuery(taruviMeta)) {
|
|
124
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta, String(id)).execute();
|
|
125
|
+
const data = Array.isArray(response2) ? response2[0] : response2?.data?.[0] ?? response2;
|
|
126
|
+
return { data };
|
|
127
|
+
}
|
|
105
128
|
let query = new Database(client).from(tableName);
|
|
106
129
|
query = applyPopulate(query, taruviMeta);
|
|
107
130
|
const response = await query.get(String(id)).execute();
|
|
@@ -111,6 +134,15 @@ function dataProvider(client) {
|
|
|
111
134
|
const { resource, ids, meta } = params;
|
|
112
135
|
const taruviMeta = meta;
|
|
113
136
|
const tableName = getTableName(resource, taruviMeta);
|
|
137
|
+
if (isGraphQuery(taruviMeta)) {
|
|
138
|
+
const data = await Promise.all(
|
|
139
|
+
ids.map(async (id) => {
|
|
140
|
+
const response2 = await buildGraphQuery(client, tableName, taruviMeta, String(id)).execute();
|
|
141
|
+
return Array.isArray(response2) ? response2[0] : response2?.data?.[0] ?? response2;
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
return { data };
|
|
145
|
+
}
|
|
114
146
|
const idColumn = getIdColumn(taruviMeta);
|
|
115
147
|
let query = new Database(client).from(tableName);
|
|
116
148
|
query = query.filter(idColumn, "in", ids.map(String));
|
|
@@ -122,6 +154,10 @@ function dataProvider(client) {
|
|
|
122
154
|
const { resource, variables, meta } = params;
|
|
123
155
|
const taruviMeta = meta;
|
|
124
156
|
const tableName = getTableName(resource, taruviMeta);
|
|
157
|
+
if (isGraphQuery(taruviMeta)) {
|
|
158
|
+
const data2 = await new Graph(client).from(tableName).createEdge(variables).execute();
|
|
159
|
+
return { data: data2 };
|
|
160
|
+
}
|
|
125
161
|
const data = await new Database(client).from(tableName).create(variables).execute();
|
|
126
162
|
return { data };
|
|
127
163
|
},
|
|
@@ -140,6 +176,10 @@ function dataProvider(client) {
|
|
|
140
176
|
const { resource, id, variables, meta } = params;
|
|
141
177
|
const taruviMeta = meta;
|
|
142
178
|
const tableName = getTableName(resource, taruviMeta);
|
|
179
|
+
if (isGraphQuery(taruviMeta)) {
|
|
180
|
+
const data2 = await new Graph(client).from(tableName).updateEdge(String(id), variables).execute();
|
|
181
|
+
return { data: data2 };
|
|
182
|
+
}
|
|
143
183
|
const data = await new Database(client).from(tableName).get(String(id)).update(variables).execute();
|
|
144
184
|
return { data };
|
|
145
185
|
},
|
|
@@ -158,6 +198,10 @@ function dataProvider(client) {
|
|
|
158
198
|
const { resource, id, meta } = params;
|
|
159
199
|
const taruviMeta = meta;
|
|
160
200
|
const tableName = getTableName(resource, taruviMeta);
|
|
201
|
+
if (isGraphQuery(taruviMeta)) {
|
|
202
|
+
const data2 = await new Graph(client).from(tableName).deleteEdge([String(id)]).execute();
|
|
203
|
+
return { data: data2 };
|
|
204
|
+
}
|
|
161
205
|
const data = await new Database(client).from(tableName).delete(String(id)).execute();
|
|
162
206
|
return { data };
|
|
163
207
|
},
|
|
@@ -165,34 +209,36 @@ function dataProvider(client) {
|
|
|
165
209
|
const { resource, ids, meta } = params;
|
|
166
210
|
const taruviMeta = meta;
|
|
167
211
|
const tableName = getTableName(resource, taruviMeta);
|
|
212
|
+
if (isGraphQuery(taruviMeta)) {
|
|
213
|
+
const data2 = await new Graph(client).from(tableName).deleteEdge(ids.map(String)).execute();
|
|
214
|
+
return { data: [data2] };
|
|
215
|
+
}
|
|
168
216
|
const data = await Promise.all(
|
|
169
|
-
ids.map(
|
|
170
|
-
return new Database(client).from(tableName).delete(String(id)).execute();
|
|
171
|
-
})
|
|
217
|
+
ids.map((id) => new Database(client).from(tableName).delete(String(id)).execute())
|
|
172
218
|
);
|
|
173
219
|
return { data };
|
|
174
220
|
},
|
|
175
221
|
custom: async (params) => {
|
|
176
222
|
const { url, method, payload, query } = params;
|
|
223
|
+
let fullUrl = `api/apps/${config.appSlug}/datatables/${url}`;
|
|
177
224
|
let data;
|
|
178
225
|
switch (method.toLowerCase()) {
|
|
179
226
|
case "get": {
|
|
180
|
-
let requestUrl = url;
|
|
181
227
|
if (query && Object.keys(query).length > 0) {
|
|
182
228
|
const queryString = new URLSearchParams(query).toString();
|
|
183
|
-
|
|
229
|
+
fullUrl = `${fullUrl}${fullUrl.includes("?") ? "&" : "?"}${queryString}`;
|
|
184
230
|
}
|
|
185
|
-
data = await client.httpClient.get(
|
|
231
|
+
data = await client.httpClient.get(fullUrl);
|
|
186
232
|
break;
|
|
187
233
|
}
|
|
188
234
|
case "post":
|
|
189
|
-
data = await client.httpClient.post(
|
|
235
|
+
data = await client.httpClient.post(fullUrl, payload);
|
|
190
236
|
break;
|
|
191
237
|
case "put":
|
|
192
|
-
data = await client.httpClient.put(
|
|
238
|
+
data = await client.httpClient.put(fullUrl, payload);
|
|
193
239
|
break;
|
|
194
240
|
case "delete":
|
|
195
|
-
data = await client.httpClient.delete(
|
|
241
|
+
data = await client.httpClient.delete(fullUrl);
|
|
196
242
|
break;
|
|
197
243
|
default:
|
|
198
244
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -401,25 +447,25 @@ function storageDataProvider(client) {
|
|
|
401
447
|
},
|
|
402
448
|
custom: async (params) => {
|
|
403
449
|
const { url, method, payload, query } = params;
|
|
450
|
+
let fullUrl = `api/apps/${config.appSlug}/storage/buckets/${url}`;
|
|
404
451
|
let data;
|
|
405
452
|
switch (method.toLowerCase()) {
|
|
406
453
|
case "get": {
|
|
407
|
-
let requestUrl = url;
|
|
408
454
|
if (query && Object.keys(query).length > 0) {
|
|
409
455
|
const queryString = new URLSearchParams(query).toString();
|
|
410
|
-
|
|
456
|
+
fullUrl = `${fullUrl}${fullUrl.includes("?") ? "&" : "?"}${queryString}`;
|
|
411
457
|
}
|
|
412
|
-
data = await client.httpClient.get(
|
|
458
|
+
data = await client.httpClient.get(fullUrl);
|
|
413
459
|
break;
|
|
414
460
|
}
|
|
415
461
|
case "post":
|
|
416
|
-
data = await client.httpClient.post(
|
|
462
|
+
data = await client.httpClient.post(fullUrl, payload);
|
|
417
463
|
break;
|
|
418
464
|
case "put":
|
|
419
|
-
data = await client.httpClient.put(
|
|
465
|
+
data = await client.httpClient.put(fullUrl, payload);
|
|
420
466
|
break;
|
|
421
467
|
case "delete":
|
|
422
|
-
data = await client.httpClient.delete(
|
|
468
|
+
data = await client.httpClient.delete(fullUrl);
|
|
423
469
|
break;
|
|
424
470
|
default:
|
|
425
471
|
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
@@ -430,83 +476,11 @@ function storageDataProvider(client) {
|
|
|
430
476
|
updateMany: void 0
|
|
431
477
|
};
|
|
432
478
|
}
|
|
433
|
-
function functionsDataProvider(client) {
|
|
434
|
-
const config = client.getConfig();
|
|
435
|
-
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
436
|
-
const functions = new Functions(client);
|
|
437
|
-
return {
|
|
438
|
-
/**
|
|
439
|
-
* Execute an edge function.
|
|
440
|
-
*
|
|
441
|
-
* @param resource - The function slug to execute
|
|
442
|
-
* @param variables - Parameters to pass to the function
|
|
443
|
-
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
444
|
-
*/
|
|
445
|
-
create: async ({
|
|
446
|
-
resource,
|
|
447
|
-
variables,
|
|
448
|
-
meta
|
|
449
|
-
}) => {
|
|
450
|
-
const functionMeta = meta;
|
|
451
|
-
const response = await functions.execute(resource, {
|
|
452
|
-
async: functionMeta?.async ?? false,
|
|
453
|
-
params: variables
|
|
454
|
-
});
|
|
455
|
-
return { data: response.data };
|
|
456
|
-
},
|
|
457
|
-
getApiUrl: () => baseApiUrl,
|
|
458
|
-
// Edge functions don't support custom method - use create() instead
|
|
459
|
-
custom: async () => {
|
|
460
|
-
throw new Error(
|
|
461
|
-
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
462
|
-
);
|
|
463
|
-
},
|
|
464
|
-
// Edge functions don't support other CRUD operations
|
|
465
|
-
getList: async () => {
|
|
466
|
-
throw new Error(
|
|
467
|
-
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
468
|
-
);
|
|
469
|
-
},
|
|
470
|
-
getOne: async () => {
|
|
471
|
-
throw new Error(
|
|
472
|
-
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
473
|
-
);
|
|
474
|
-
},
|
|
475
|
-
getMany: async () => {
|
|
476
|
-
throw new Error(
|
|
477
|
-
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
478
|
-
);
|
|
479
|
-
},
|
|
480
|
-
createMany: async () => {
|
|
481
|
-
throw new Error(
|
|
482
|
-
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
483
|
-
);
|
|
484
|
-
},
|
|
485
|
-
update: async () => {
|
|
486
|
-
throw new Error(
|
|
487
|
-
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
488
|
-
);
|
|
489
|
-
},
|
|
490
|
-
updateMany: async () => {
|
|
491
|
-
throw new Error(
|
|
492
|
-
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
493
|
-
);
|
|
494
|
-
},
|
|
495
|
-
deleteOne: async () => {
|
|
496
|
-
throw new Error(
|
|
497
|
-
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
498
|
-
);
|
|
499
|
-
},
|
|
500
|
-
deleteMany: async () => {
|
|
501
|
-
throw new Error(
|
|
502
|
-
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
503
|
-
);
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
479
|
function appDataProvider(client) {
|
|
508
480
|
const config = client.getConfig();
|
|
509
481
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
482
|
+
const functions = new Functions(client);
|
|
483
|
+
const analytics = new Analytics(client);
|
|
510
484
|
return {
|
|
511
485
|
getList: async (params) => {
|
|
512
486
|
const { resource } = params;
|
|
@@ -520,7 +494,6 @@ function appDataProvider(client) {
|
|
|
520
494
|
}
|
|
521
495
|
throw new Error(`Unknown app resource: ${resource}. Supported resources: roles`);
|
|
522
496
|
},
|
|
523
|
-
getApiUrl: () => baseApiUrl,
|
|
524
497
|
getOne: async (params) => {
|
|
525
498
|
const { resource } = params;
|
|
526
499
|
if (resource === "settings") {
|
|
@@ -532,12 +505,32 @@ function appDataProvider(client) {
|
|
|
532
505
|
}
|
|
533
506
|
throw new Error(`Unknown app resource for getOne: ${resource}. Supported resources: settings`);
|
|
534
507
|
},
|
|
535
|
-
|
|
508
|
+
custom: async (params) => {
|
|
509
|
+
const { url: slug, payload, meta } = params;
|
|
510
|
+
const customMeta = meta;
|
|
511
|
+
if (customMeta?.kind === "function") {
|
|
512
|
+
const response = await functions.execute(slug, {
|
|
513
|
+
async: customMeta.async ?? false,
|
|
514
|
+
params: payload ?? {}
|
|
515
|
+
});
|
|
516
|
+
return { data: response.data };
|
|
517
|
+
}
|
|
518
|
+
if (customMeta?.kind === "analytics") {
|
|
519
|
+
const response = await analytics.execute(slug, {
|
|
520
|
+
params: payload ?? {}
|
|
521
|
+
});
|
|
522
|
+
return { data: response.data };
|
|
523
|
+
}
|
|
524
|
+
throw new Error(
|
|
525
|
+
'Specify meta.kind as "function" or "analytics" for custom operations on the app provider.'
|
|
526
|
+
);
|
|
527
|
+
},
|
|
528
|
+
getApiUrl: () => baseApiUrl,
|
|
536
529
|
getMany: async () => {
|
|
537
530
|
throw new Error("getMany is not supported for app resources");
|
|
538
531
|
},
|
|
539
532
|
create: async () => {
|
|
540
|
-
throw new Error("create is not supported for app resources");
|
|
533
|
+
throw new Error("create is not supported for app resources. Use useCustom with meta.kind");
|
|
541
534
|
},
|
|
542
535
|
createMany: async () => {
|
|
543
536
|
throw new Error("createMany is not supported for app resources");
|
|
@@ -553,9 +546,6 @@ function appDataProvider(client) {
|
|
|
553
546
|
},
|
|
554
547
|
deleteMany: async () => {
|
|
555
548
|
throw new Error("deleteMany is not supported for app resources");
|
|
556
|
-
},
|
|
557
|
-
custom: async () => {
|
|
558
|
-
throw new Error("custom is not supported for app resources");
|
|
559
549
|
}
|
|
560
550
|
};
|
|
561
551
|
}
|
|
@@ -695,6 +685,80 @@ function userDataProvider(client) {
|
|
|
695
685
|
}
|
|
696
686
|
};
|
|
697
687
|
}
|
|
688
|
+
function functionsDataProvider(client) {
|
|
689
|
+
const config = client.getConfig();
|
|
690
|
+
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|
|
691
|
+
const functions = new Functions(client);
|
|
692
|
+
return {
|
|
693
|
+
/**
|
|
694
|
+
* Execute an edge function.
|
|
695
|
+
*
|
|
696
|
+
* @param resource - The function slug to execute
|
|
697
|
+
* @param variables - Parameters to pass to the function
|
|
698
|
+
* @param meta.async - Whether to execute asynchronously (default: false)
|
|
699
|
+
*/
|
|
700
|
+
create: async ({
|
|
701
|
+
resource,
|
|
702
|
+
variables,
|
|
703
|
+
meta
|
|
704
|
+
}) => {
|
|
705
|
+
const functionMeta = meta;
|
|
706
|
+
const response = await functions.execute(resource, {
|
|
707
|
+
async: functionMeta?.async ?? false,
|
|
708
|
+
params: variables
|
|
709
|
+
});
|
|
710
|
+
return { data: response.data };
|
|
711
|
+
},
|
|
712
|
+
getApiUrl: () => baseApiUrl,
|
|
713
|
+
// Edge functions don't support custom method - use create() instead
|
|
714
|
+
custom: async () => {
|
|
715
|
+
throw new Error(
|
|
716
|
+
"custom is not supported for edge functions. Use useCreate to execute functions."
|
|
717
|
+
);
|
|
718
|
+
},
|
|
719
|
+
// Edge functions don't support other CRUD operations
|
|
720
|
+
getList: async () => {
|
|
721
|
+
throw new Error(
|
|
722
|
+
"getList is not supported for edge functions. Use useCreate to execute functions."
|
|
723
|
+
);
|
|
724
|
+
},
|
|
725
|
+
getOne: async () => {
|
|
726
|
+
throw new Error(
|
|
727
|
+
"getOne is not supported for edge functions. Use useCreate to execute functions."
|
|
728
|
+
);
|
|
729
|
+
},
|
|
730
|
+
getMany: async () => {
|
|
731
|
+
throw new Error(
|
|
732
|
+
"getMany is not supported for edge functions. Use useCreate to execute functions."
|
|
733
|
+
);
|
|
734
|
+
},
|
|
735
|
+
createMany: async () => {
|
|
736
|
+
throw new Error(
|
|
737
|
+
"createMany is not supported for edge functions. Use useCreate to execute functions."
|
|
738
|
+
);
|
|
739
|
+
},
|
|
740
|
+
update: async () => {
|
|
741
|
+
throw new Error(
|
|
742
|
+
"update is not supported for edge functions. Use useCreate to execute functions."
|
|
743
|
+
);
|
|
744
|
+
},
|
|
745
|
+
updateMany: async () => {
|
|
746
|
+
throw new Error(
|
|
747
|
+
"updateMany is not supported for edge functions. Use useCreate to execute functions."
|
|
748
|
+
);
|
|
749
|
+
},
|
|
750
|
+
deleteOne: async () => {
|
|
751
|
+
throw new Error(
|
|
752
|
+
"deleteOne is not supported for edge functions. Use useCreate to execute functions."
|
|
753
|
+
);
|
|
754
|
+
},
|
|
755
|
+
deleteMany: async () => {
|
|
756
|
+
throw new Error(
|
|
757
|
+
"deleteMany is not supported for edge functions. Use useCreate to execute functions."
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
698
762
|
function analyticsDataProvider(client) {
|
|
699
763
|
const config = client.getConfig();
|
|
700
764
|
const baseApiUrl = `${config.baseUrl}/api/apps/${config.appSlug}`;
|