Updated @ldo/ldo to have a transaction dataset
parent
744603bef6
commit
893e745903
@ -0,0 +1,19 @@ |
|||||||
|
import { TransactionDataset } from "@ldo/subscribable-dataset"; |
||||||
|
import type { Quad } from "@rdfjs/types"; |
||||||
|
import type { ILdoDataset } from "./types"; |
||||||
|
import { LdoBuilder } from "./LdoBuilder"; |
||||||
|
import type { ShapeType } from "./ShapeType"; |
||||||
|
import type { LdoBase } from "./util"; |
||||||
|
import jsonldDatasetProxy from "@ldo/jsonld-dataset-proxy"; |
||||||
|
|
||||||
|
export class LdoTransactionDataset |
||||||
|
extends TransactionDataset<Quad> |
||||||
|
implements ILdoDataset |
||||||
|
{ |
||||||
|
usingType<Type extends LdoBase>( |
||||||
|
shapeType: ShapeType<Type>, |
||||||
|
): LdoBuilder<Type> { |
||||||
|
const proxyBuilder = jsonldDatasetProxy(this, shapeType.context); |
||||||
|
return new LdoBuilder(proxyBuilder, shapeType); |
||||||
|
} |
||||||
|
} |
@ -1,23 +0,0 @@ |
|||||||
import type { TransactionalDataset } from "@ldo/subscribable-dataset"; |
|
||||||
import { LdoDataset } from "../dist/LdoDataset"; |
|
||||||
import type { Quad } from "@rdfjs/types"; |
|
||||||
import type { DatasetChanges } from "@ldo/rdf-utils"; |
|
||||||
|
|
||||||
export class LdoTransactionalDataset |
|
||||||
extends LdoDataset |
|
||||||
implements TransactionalDataset<Quad> |
|
||||||
{ |
|
||||||
constructor() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
rollback(): void { |
|
||||||
throw new Error("Method not implemented."); |
|
||||||
} |
|
||||||
commit(): void { |
|
||||||
throw new Error("Method not implemented."); |
|
||||||
} |
|
||||||
getChanges(): DatasetChanges<Quad> { |
|
||||||
throw new Error("Method not implemented."); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,9 @@ |
|||||||
|
import type { ISubscribableDataset } from "@ldo/subscribable-dataset"; |
||||||
|
import type { LdoBuilder } from "./LdoBuilder"; |
||||||
|
import type { ShapeType } from "./ShapeType"; |
||||||
|
import type { LdoBase } from "./util"; |
||||||
|
import type { Quad } from "@rdfjs/types"; |
||||||
|
|
||||||
|
export interface ILdoDataset extends ISubscribableDataset<Quad> { |
||||||
|
usingType<Type extends LdoBase>(shapeType: ShapeType<Type>): LdoBuilder<Type>; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
import { createLdoDataset } from "../src/createLdoDataset"; |
||||||
|
import { ProfileShapeType } from "./profileData"; |
||||||
|
|
||||||
|
describe("TransactionLdoDataset", () => { |
||||||
|
it("Uses transactions with an LdoBuilder", () => { |
||||||
|
const ldoDataset = createLdoDataset(); |
||||||
|
const transaction = ldoDataset.startTransaction(); |
||||||
|
const profile = transaction |
||||||
|
.usingType(ProfileShapeType) |
||||||
|
.fromSubject("https://example.com/Person1"); |
||||||
|
profile.fn = "John Doe"; |
||||||
|
expect(transaction.getChanges().added?.toString()).toBe( |
||||||
|
'<https://example.com/Person1> <http://www.w3.org/2006/vcard/ns#fn> "John Doe" .\n', |
||||||
|
); |
||||||
|
expect(ldoDataset.toString()).toBe(""); |
||||||
|
transaction.commit(); |
||||||
|
expect(ldoDataset.toString()).toBe( |
||||||
|
'<https://example.com/Person1> <http://www.w3.org/2006/vcard/ns#fn> "John Doe" .\n', |
||||||
|
); |
||||||
|
}); |
||||||
|
}); |
Loading…
Reference in new issue