This commit is contained in:
srosset81
2026-08-07 16:18:08 +02:00
parent 0fc977fcca
commit 7a4b15f894
2 changed files with 8 additions and 20 deletions
+6 -12
View File
@@ -10,8 +10,6 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
// In the future, it may use offset-based or cursor-based pagination, which would work with this stateless data provider. // In the future, it may use offset-based or cursor-based pagination, which would work with this stateless data provider.
// Fortunately, Refine handle pagination automatically if the total number of objects is larger than the page size. // Fortunately, Refine handle pagination automatically if the total number of objects is larger than the page size.
getList: async ({ resource, pagination, sorters, filters, meta }) => { getList: async ({ resource, pagination, sorters, filters, meta }) => {
console.log('list', resource, pagination, sorters, filters, meta);
const objects = await getObjects(shapeTypes[resource], { const objects = await getObjects(shapeTypes[resource], {
graphs: [""], graphs: [""],
orderBy: sorters && sorters.length > 0 orderBy: sorters && sorters.length > 0
@@ -19,8 +17,12 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
: undefined, : undefined,
where: filters && filters.length > 0 where: filters && filters.length > 0
? filters.reduce((acc, filter) => { ? filters.reduce((acc, filter) => {
if ("field" in filter && filter.operator === "eq") { if ("field" in filter) {
acc[filter.field] = filter.value; if (filter.operator === "eq") {
acc[filter.field] = filter.value;
} else {
console.warn(`Unsupported filter operator: ${filter.operator}. Only "eq" is supported.`);
}
} }
return acc; return acc;
}, {} as any) }, {} as any)
@@ -33,8 +35,6 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
}; };
}, },
create: async ({ resource, variables, meta }) => { create: async ({ resource, variables, meta }) => {
console.log("create", resource, variables, meta);
const session = authProvider.getSession(); const session = authProvider.getSession();
const docNuri = await ng.doc_create( const docNuri = await ng.doc_create(
@@ -61,8 +61,6 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
}; };
}, },
update: async ({ resource, id, variables, meta }) => { update: async ({ resource, id, variables, meta }) => {
console.log('update', resource, id, variables, meta);
const set = await getSignalObject(shapeTypes[resource], [`${id}`]); const set = await getSignalObject(shapeTypes[resource], [`${id}`]);
const oldData = set.first()!; const oldData = set.first()!;
@@ -86,8 +84,6 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
}; };
}, },
deleteOne: async ({ resource, id, variables, meta }) => { deleteOne: async ({ resource, id, variables, meta }) => {
console.log('deleteOne', resource, id, variables, meta);
const set = await getSignalObject(shapeTypes[resource], [`${id}`]); const set = await getSignalObject(shapeTypes[resource], [`${id}`]);
const oldData = set.first()!; const oldData = set.first()!;
@@ -99,8 +95,6 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
}; };
}, },
getOne: async ({ resource, id, meta }) => { getOne: async ({ resource, id, meta }) => {
console.log('getOne', resource, id, meta);
// The ID should be a graph URI, but if it's an object key, we can use the subjects filter to the the object // The ID should be a graph URI, but if it's an object key, we can use the subjects filter to the the object
const objects = await getObjects(shapeTypes[resource], isGraphKey(id) ? { graphs: [`${id}`] } : { graphs: [""], subjects: [`${id}`] }); const objects = await getObjects(shapeTypes[resource], isGraphKey(id) ? { graphs: [`${id}`] } : { graphs: [""], subjects: [`${id}`] });
+2 -8
View File
@@ -5,8 +5,6 @@ import { LiveProviderConfig, UnwatchFn } from "./types";
const liveProvider = ({ shapeTypes }: LiveProviderConfig) : LiveProvider => ({ const liveProvider = ({ shapeTypes }: LiveProviderConfig) : LiveProvider => ({
subscribe: async ({ channel, params, types, callback, meta }) : Promise<UnwatchFn> => { subscribe: async ({ channel, params, types, callback, meta }) : Promise<UnwatchFn> => {
console.log('subscribe', channel, params?.subscriptionType, params, types, meta);
const ids = params?.ids as string[]; const ids = params?.ids as string[];
if (channel.startsWith("resources/")) { if (channel.startsWith("resources/")) {
@@ -18,9 +16,7 @@ const liveProvider = ({ shapeTypes }: LiveProviderConfig) : LiveProvider => ({
// We don't close the subscription because we want to keep listening for changes // We don't close the subscription because we want to keep listening for changes
const set = await getSignalObject(shapeTypes[resource], ids, false); const set = await getSignalObject(shapeTypes[resource], ids, false);
const { stopListening } = watch(set, ({ newValue, patches }) => { const { stopListening } = watch(set, ({ patches }) => {
console.log('object modified', newValue, patches);
const modifiedIds = parsePatches(patches); const modifiedIds = parsePatches(patches);
for( const [graphId, eventType] of Object.entries(modifiedIds)) { for( const [graphId, eventType] of Object.entries(modifiedIds)) {
@@ -39,8 +35,7 @@ const liveProvider = ({ shapeTypes }: LiveProviderConfig) : LiveProvider => ({
// We don't close the subscription because we want to keep listening for changes // We don't close the subscription because we want to keep listening for changes
const set = await getSignalObject(shapeTypes[resource], undefined, false); const set = await getSignalObject(shapeTypes[resource], undefined, false);
const { stopListening } = watch(set, ({ newValue, patches }) => { const { stopListening } = watch(set, ({ patches }) => {
console.log('objects list modified', newValue, patches);
const modifiedIds = parsePatches(patches); const modifiedIds = parsePatches(patches);
@@ -62,7 +57,6 @@ const liveProvider = ({ shapeTypes }: LiveProviderConfig) : LiveProvider => ({
return () => undefined; return () => undefined;
}, },
unsubscribe: async (unwatchFn: UnwatchFn | Promise<UnwatchFn>) => { unsubscribe: async (unwatchFn: UnwatchFn | Promise<UnwatchFn>) => {
console.log('unsubscribe', unwatchFn);
const fn = await Promise.resolve(unwatchFn); const fn = await Promise.resolve(unwatchFn);
if (typeof fn === "function") { if (typeof fn === "function") {
fn(); fn();