Update @cubicweb/transaction-builder to better match CubicWeb
Waiting for #1026 (closed)
Proposed API
// -------------- Delete --------------
function pushDeleteEntity(
transaction: Transaction,
entityType: string,
eid: EntityId | TransactionQueryScalarRef
) // ✅ Implemented 🧪 Tested
function pushDeleteEntities(
transaction: Transaction,
entityType: string,
eidList: (EntityId | TransactionQueryScalarRef)[]
) // ✅ Implemented 🧪 Tested
// -------------- Create --------------
function pushCreateEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
entityData?: EntityData
) // ✅ Implemented 🧪 Tested
// -------------- Get --------------
function pushFindEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
{ where, resolve }: RqlQueryOptions
) // ✅ Implemented 🧪 Tested
function pushFindEntities(
transaction: Transaction,
schema: Schema,
entityType: string,
{ pagination, sort, where, resolve }: RqlQueryListOptions
) // ✅ Implemented 🧪 Tested
function pushFindLastCreatedEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
filter?: Filter,
relationsToResolve?: Array<string>
) // ❓ Maybe later
function pushFindLastEditedEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
filter?: Filter,
relationsToResolve?: Array<string>
) // ❓ Maybe later
// -------------- Update --------------
function pushSetAttributes(
transaction: Transaction,
schema: Schema,
entityType: string,
eid: EntityId | TransactionQueryScalarRef,
attributesData: Record<string, AttributeValue>
) // ✅ Implemented 🧪 Tested
function pushSetRelation(
transaction: Transaction,
subjectEidList: (EntityId | TransactionQueryScalarRef)[],
relationType: string,
objectEidList: (EntityId | TransactionQueryScalarRef)[]
) // ✅ Implemented 🧪 Tested
function pushDeleteRelation(
transaction: Transaction,
subjectEidList: (EntityId | TransactionQueryScalarRef)[],
relationType: string,
objectEidList: (EntityId | TransactionQueryScalarRef)[]
) // ✅ Implemented 🧪 Tested
function pushUpdateEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
eid: EntityId | TransactionQueryScalarRef,
newData: EntityData,
initialData: EntityData
) // ✅ Implemented
// -------------- Other helpers --------------
function pushCountEntities(
transaction: Transaction,
schema: Schema,
entityType: string,
filter?: Filter
) // ✅ Implemented 🧪 Tested
function pushGetPossibleTargets(?) // ❓ Maybe later, see https://forge.extranet.logilab.fr/cubicweb/cubicweb/-/issues/831
function pushExistEntity(
transaction: Transaction,
schema: Schema,
entityType: string,
filter?: Filter,
) // ❓ Maybe later
// -------------- Workflow --------------
- fireTransition() // ❓ Maybe later
- getState() // ❓ Maybe later
Types
type EntityId = number;
type AttributeValue = string | number | boolean | null;
interface SortPayload {
relationName: string;
order: string;
}
interface PaginationPayload {
page: number;
perPage: number;
}
type Filter =
| {
type: "rql";
rql: RQLQuery;
}
| {
type: "values";
values: EntityData;
};
export type RqlQueryOptions = {
where?: Filter;
resolve?: Array<string>;
};
export type RqlQueryListOptions = RqlQueryOptions & {
pagination?: PaginationPayload;
sort?: SortPayload;
};
For examples and implementation, see cubicwebjs!92 and cubicwebjs!90
Must still be able to create react-admin data-provider methods:
- getList: (resource, params) => Promise, // get a list of records based on sort, filter, and pagination
- getOne: (resource, params) => Promise, // get a single record by id
- getMany: (resource, params) => Promise, // get a list of records based on an array of ids
- getManyReference: (resource, params) => Promise, // get the records referenced to another record, e.g. comments for a post
- create: (resource, params) => Promise, // create a record
- update: (resource, params) => Promise, // update a record based on a patch
- updateMany: (resource, params) => Promise, // update a list of records based on an array of ids and a common patch
- delete: (resource, params) => Promise, // delete a record by id
- deleteMany: (resource, params) => Promise, // delete a list of records based on an array of ids