Take into account new ordering and filtering options

This commit is contained in:
srosset81
2026-08-07 15:56:33 +02:00
parent 3d3a69d3f6
commit 0fc977fcca
5 changed files with 136 additions and 24 deletions
+21 -4
View File
@@ -1,18 +1,35 @@
import { DataProvider } from "@refinedev/core";
import { ng } from "@ng-org/web";
import { getObjects } from "@ng-org/orm";
import { addIdToObject, isGraphKey, getSignalObject } from "./utils";
import { getObjects } from "./getObjects";
import { DataProviderConfig } from "./types";
const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataProvider => ({
// Note: the `pagination` parameter is not used, because the ORM handle currently handle pagination within the ORM objects.
// 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.
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: [""],
orderBy: sorters && sorters.length > 0
? sorters.map(s => ({ [s.field]: s.order })) as any
: undefined,
where: filters && filters.length > 0
? filters.reduce((acc, filter) => {
if ("field" in filter && filter.operator === "eq") {
acc[filter.field] = filter.value;
}
return acc;
}, {} as any)
: undefined
});
return {
data: [...objects].map(addIdToObject) as any,
total: 1,
total: objects.size,
};
},
create: async ({ resource, variables, meta }) => {
@@ -85,7 +102,7 @@ const dataProvider = ({ shapeTypes, authProvider }: DataProviderConfig) : DataPr
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
const objects = await getObjects(shapeTypes[resource], isGraphKey(id) ? `${id}` : { subjects: [`${id}`] });
const objects = await getObjects(shapeTypes[resource], isGraphKey(id) ? { graphs: [`${id}`] } : { graphs: [""], subjects: [`${id}`] });
return {
data: addIdToObject([...objects][0])
+26
View File
@@ -0,0 +1,26 @@
import type { BaseType, ShapeType } from "@ng-org/shex-orm";
import { RdfOrmSubscription, normalizeConf } from "@ng-org/orm";
import type { RdfOrmConfig } from "@ng-org/orm/all";
import { RAW_KEY } from "@ng-org/alien-deepsignals";
/**
* Local copy of `@ng-org/orm`'s `getObjects` until the fix is released
* https://git.nextgraph.org/NextGraph/nextgraph-rs/commit/02cb531f53dfb7a64014917e9b38cd5134efcdd8
*/
export async function getObjects<T extends BaseType>(
shapeType: ShapeType<T>,
config: Omit<RdfOrmConfig<T>, "pageSize" | "maxActivePages">
) {
const connection = RdfOrmSubscription.getOrCreate(
shapeType,
normalizeConf(config) as any
);
await connection.readyPromise;
setTimeout(() => {
connection.close();
}, 1_000);
return structuredClone(connection.signalObject[RAW_KEY]);
}
+2 -2
View File
@@ -1,10 +1,10 @@
import { BaseKey } from "@refinedev/core";
import { OrmSubscription } from "@ng-org/orm";
import { RdfOrmSubscription } from "@ng-org/orm";
import type { ShapeType } from "@ng-org/shex-orm";
import { DeepSignalSet, DeepPatch } from "@ng-org/alien-deepsignals"
export const getSignalObject = async (shapeType: ShapeType<any>, ids?: string[], closeSubscription: boolean = true) : Promise<DeepSignalSet<any>> => {
const subscription = OrmSubscription.getOrCreate(shapeType, { graphs: ids || [''] });
const subscription = RdfOrmSubscription.getOrCreate(shapeType, { graphs: ids || [''] });
await subscription.readyPromise;
const { signalObject } = subscription;
if (closeSubscription) subscription.close();