@rdfx/git 0.0.34
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/dist/AbstractGitGraphStore.d.ts +28 -0
- package/dist/AbstractGitGraphStore.js +28 -0
- package/dist/AbstractVersionedRdfFileGraphStore.d.ts +49 -0
- package/dist/AbstractVersionedRdfFileGraphStore.js +153 -0
- package/dist/GitDirectoryGraphStore.d.ts +7 -0
- package/dist/GitDirectoryGraphStore.js +6 -0
- package/dist/GitFileSystem.d.ts +15 -0
- package/dist/GitFileSystem.js +30 -0
- package/dist/GitGraphStore copy.d.ts +7 -0
- package/dist/GitGraphStore copy.js +6 -0
- package/dist/GitGraphStore.d.ts +7 -0
- package/dist/GitGraphStore.js +6 -0
- package/dist/GitVersionedGraphStore.d.ts +2 -0
- package/dist/GitVersionedGraphStore.js +2 -0
- package/dist/VersionedFileSystem.d.ts +35 -0
- package/dist/VersionedFileSystem.js +79 -0
- package/dist/VersionedRdfDirectoryGraphStore.d.ts +13 -0
- package/dist/VersionedRdfDirectoryGraphStore.js +47 -0
- package/dist/VersionedRdfFileGraphStore.d.ts +16 -0
- package/dist/VersionedRdfFileGraphStore.js +57 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +34 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Stream } from "@rdfjs/types";
|
|
2
|
+
import type { GraphIdentifier, GraphStore, VersionedGraphStore } from "@rdfx/graph-store";
|
|
3
|
+
import type { Either, Maybe } from "purify-ts";
|
|
4
|
+
export declare abstract class AbstractGitGraphStore implements VersionedGraphStore<string> {
|
|
5
|
+
constructor(path: string, {}: {});
|
|
6
|
+
clear(options?: object | undefined): Promise<Either<Error, {
|
|
7
|
+
readonly version: string;
|
|
8
|
+
}>>;
|
|
9
|
+
delete(identifier: GraphIdentifier, options?: object | undefined): Promise<Either<Error, {
|
|
10
|
+
readonly version: string;
|
|
11
|
+
}>>;
|
|
12
|
+
get(identifier: GraphIdentifier, options?: {
|
|
13
|
+
readonly version?: string | undefined;
|
|
14
|
+
} | undefined): Promise<Either<Error, Maybe<Stream>>>;
|
|
15
|
+
head(identifier: GraphIdentifier, options?: {
|
|
16
|
+
readonly version?: string | undefined;
|
|
17
|
+
} | undefined): Promise<Either<Error, boolean>>;
|
|
18
|
+
identifiers(): Promise<Either<Error, readonly GraphIdentifier[]>>;
|
|
19
|
+
isEmpty(): Promise<Either<Error, boolean>>;
|
|
20
|
+
post(quads: Stream, options?: object | undefined): Promise<Either<Error, {
|
|
21
|
+
readonly version: string;
|
|
22
|
+
}>>;
|
|
23
|
+
put(quads: Stream, options?: object | undefined): Promise<Either<Error, {
|
|
24
|
+
readonly version: string;
|
|
25
|
+
}>>;
|
|
26
|
+
protected abstract readonly delegate: GraphStore;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=AbstractGitGraphStore.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class AbstractGitGraphStore {
|
|
2
|
+
constructor(path, {}) { }
|
|
3
|
+
clear(options) {
|
|
4
|
+
throw new Error("Method not implemented.");
|
|
5
|
+
}
|
|
6
|
+
delete(identifier, options) {
|
|
7
|
+
throw new Error("Method not implemented.");
|
|
8
|
+
}
|
|
9
|
+
get(identifier, options) {
|
|
10
|
+
throw new Error("Method not implemented.");
|
|
11
|
+
}
|
|
12
|
+
head(identifier, options) {
|
|
13
|
+
throw new Error("Method not implemented.");
|
|
14
|
+
}
|
|
15
|
+
identifiers() {
|
|
16
|
+
throw new Error("Method not implemented.");
|
|
17
|
+
}
|
|
18
|
+
isEmpty() {
|
|
19
|
+
throw new Error("Method not implemented.");
|
|
20
|
+
}
|
|
21
|
+
post(quads, options) {
|
|
22
|
+
throw new Error("Method not implemented.");
|
|
23
|
+
}
|
|
24
|
+
put(quads, options) {
|
|
25
|
+
throw new Error("Method not implemented.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=AbstractGitGraphStore.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Stream } from "@rdfjs/types";
|
|
2
|
+
import { type FileSystem, type RdfDirectoryGraphStore, type RdfFileGraphStore } from "@rdfx/fs";
|
|
3
|
+
import type { GraphIdentifier, VersionedGraphStore } from "@rdfx/graph-store";
|
|
4
|
+
import * as git from "isomorphic-git";
|
|
5
|
+
import { type Either, type Maybe } from "purify-ts";
|
|
6
|
+
import { type Logger } from "ts-log";
|
|
7
|
+
export declare abstract class AbstractVersionedRdfFileGraphStore implements VersionedGraphStore<string> {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
protected readonly gitParameters: GitParameters;
|
|
10
|
+
protected readonly logger: Logger;
|
|
11
|
+
constructor(path: string, { gitParameters, logger, }: {
|
|
12
|
+
gitParameters: Omit<GitParameters, "fs">;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
});
|
|
15
|
+
clear(): Promise<Either<Error, {
|
|
16
|
+
readonly version: string;
|
|
17
|
+
}>>;
|
|
18
|
+
delete(identifier: GraphIdentifier): Promise<Either<Error, {
|
|
19
|
+
readonly version: string;
|
|
20
|
+
}>>;
|
|
21
|
+
get(identifier: GraphIdentifier, options?: {
|
|
22
|
+
readonly version?: string;
|
|
23
|
+
}): Promise<Either<Error, Maybe<Stream>>>;
|
|
24
|
+
protected abstract getVersion(identifier: GraphIdentifier, version: string): Promise<Either<Error, Maybe<Stream>>>;
|
|
25
|
+
head(identifier: GraphIdentifier, options?: {
|
|
26
|
+
readonly version?: string;
|
|
27
|
+
}): Promise<Either<Error, boolean>>;
|
|
28
|
+
identifiers(): Promise<Either<Error, readonly GraphIdentifier[]>>;
|
|
29
|
+
isEmpty(): Promise<Either<Error, boolean>>;
|
|
30
|
+
post(quads: Stream): Promise<Either<Error, {
|
|
31
|
+
readonly version: string;
|
|
32
|
+
}>>;
|
|
33
|
+
put(quads: Stream): Promise<Either<Error, {
|
|
34
|
+
readonly version: string;
|
|
35
|
+
}>>;
|
|
36
|
+
protected abstract delegate(options?: {
|
|
37
|
+
fileSystem?: FileSystem;
|
|
38
|
+
}): RdfDirectoryGraphStore | RdfFileGraphStore;
|
|
39
|
+
private mutate;
|
|
40
|
+
protected gitRelativeFilePath(path: string): string;
|
|
41
|
+
}
|
|
42
|
+
type GitParameters = {
|
|
43
|
+
readonly author?: Parameters<typeof git.commit>[0]["author"];
|
|
44
|
+
readonly dir: string;
|
|
45
|
+
readonly fs: git.PromiseFsClient;
|
|
46
|
+
readonly gitdir?: string;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=AbstractVersionedRdfFileGraphStore.d.ts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { NodeFileSystem, } from "@rdfx/fs";
|
|
4
|
+
import * as git from "isomorphic-git";
|
|
5
|
+
import { EitherAsync } from "purify-ts";
|
|
6
|
+
import { dummyLogger } from "ts-log";
|
|
7
|
+
export class AbstractVersionedRdfFileGraphStore {
|
|
8
|
+
path;
|
|
9
|
+
gitParameters;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(path, { gitParameters, logger, }) {
|
|
12
|
+
this.path = path;
|
|
13
|
+
this.gitParameters = {
|
|
14
|
+
...gitParameters,
|
|
15
|
+
fs,
|
|
16
|
+
};
|
|
17
|
+
this.logger = logger ?? dummyLogger;
|
|
18
|
+
}
|
|
19
|
+
async clear() {
|
|
20
|
+
return this.mutate((delegate) => delegate.clear());
|
|
21
|
+
}
|
|
22
|
+
async delete(identifier) {
|
|
23
|
+
return this.mutate((delegate) => delegate.delete(identifier));
|
|
24
|
+
}
|
|
25
|
+
get(identifier, options) {
|
|
26
|
+
const version = options?.version;
|
|
27
|
+
if (!version) {
|
|
28
|
+
return this.delegate().get(identifier);
|
|
29
|
+
}
|
|
30
|
+
return this.getVersion(identifier, version);
|
|
31
|
+
}
|
|
32
|
+
async head(identifier, options) {
|
|
33
|
+
const version = options?.version;
|
|
34
|
+
if (!version) {
|
|
35
|
+
return this.delegate().head(identifier);
|
|
36
|
+
}
|
|
37
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
38
|
+
const stream = (await liftEither(await this.getVersion(identifier, version))).extract();
|
|
39
|
+
if (!stream) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return await stream.some((quad) => quad.graph.equals(identifier));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
identifiers() {
|
|
46
|
+
return this.delegate().identifiers();
|
|
47
|
+
}
|
|
48
|
+
isEmpty() {
|
|
49
|
+
return this.delegate().isEmpty();
|
|
50
|
+
}
|
|
51
|
+
async post(quads) {
|
|
52
|
+
return this.mutate((delegate) => delegate.post(quads));
|
|
53
|
+
}
|
|
54
|
+
async put(quads) {
|
|
55
|
+
return this.mutate((delegate) => delegate.put(quads));
|
|
56
|
+
}
|
|
57
|
+
async mutate(mutator) {
|
|
58
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
59
|
+
const addedFilePaths = [];
|
|
60
|
+
const gitRelativeFilePath = (filePath) => this.gitRelativeFilePath(filePath);
|
|
61
|
+
const gitParameters = this.gitParameters;
|
|
62
|
+
const removedFilePaths = [];
|
|
63
|
+
const underlyingFileSystem = NodeFileSystem.instance;
|
|
64
|
+
const fileSystem = {
|
|
65
|
+
createDirectory(path, options) {
|
|
66
|
+
return underlyingFileSystem.createDirectory(path, options);
|
|
67
|
+
},
|
|
68
|
+
createReadStream(path) {
|
|
69
|
+
return underlyingFileSystem.createReadStream(path);
|
|
70
|
+
},
|
|
71
|
+
async deleteDirectory(path, options) {
|
|
72
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
73
|
+
const filePaths = (await liftEither(await underlyingFileSystem.readDirectory(path, options)))
|
|
74
|
+
.filter((dirent) => dirent.isFile())
|
|
75
|
+
.map((dirent) => join(dirent.parentPath, dirent.name));
|
|
76
|
+
await liftEither(await underlyingFileSystem.deleteDirectory(path, options));
|
|
77
|
+
for (const filePath of filePaths) {
|
|
78
|
+
await git.remove({
|
|
79
|
+
...gitParameters,
|
|
80
|
+
filepath: gitRelativeFilePath(filePath),
|
|
81
|
+
});
|
|
82
|
+
removedFilePaths.push(filePath);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
async deleteFile(path, options) {
|
|
87
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
88
|
+
await liftEither(await underlyingFileSystem.deleteFile(path, options));
|
|
89
|
+
await git.remove({
|
|
90
|
+
...gitParameters,
|
|
91
|
+
filepath: gitRelativeFilePath(path),
|
|
92
|
+
});
|
|
93
|
+
removedFilePaths.push(path);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
readDirectory(path, options) {
|
|
97
|
+
return underlyingFileSystem.readDirectory(path, options);
|
|
98
|
+
},
|
|
99
|
+
readFile(path) {
|
|
100
|
+
return underlyingFileSystem.readFile(path);
|
|
101
|
+
},
|
|
102
|
+
realpath(path) {
|
|
103
|
+
return underlyingFileSystem.realpath(path);
|
|
104
|
+
},
|
|
105
|
+
stat(path) {
|
|
106
|
+
return underlyingFileSystem.stat(path);
|
|
107
|
+
},
|
|
108
|
+
async writeFile(path, data) {
|
|
109
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
110
|
+
await liftEither(await underlyingFileSystem.writeFile(path, data));
|
|
111
|
+
await git.add({
|
|
112
|
+
...gitParameters,
|
|
113
|
+
filepath: gitRelativeFilePath(path),
|
|
114
|
+
});
|
|
115
|
+
addedFilePaths.push(path);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
async writeFileStream(path, write) {
|
|
119
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
120
|
+
const result = await liftEither(await underlyingFileSystem.writeFileStream(path, write));
|
|
121
|
+
await git.add({
|
|
122
|
+
...gitParameters,
|
|
123
|
+
filepath: gitRelativeFilePath(path),
|
|
124
|
+
});
|
|
125
|
+
addedFilePaths.push(path);
|
|
126
|
+
return result;
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const delegate = this.delegate({ fileSystem });
|
|
131
|
+
await liftEither(await mutator(delegate));
|
|
132
|
+
if (addedFilePaths.length === 0 && removedFilePaths.length === 0) {
|
|
133
|
+
throw new Error("didn't add or remove any file paths from git");
|
|
134
|
+
}
|
|
135
|
+
const objectId = await git.commit({
|
|
136
|
+
...gitParameters,
|
|
137
|
+
author: gitParameters.author ?? {
|
|
138
|
+
name: "John Doe",
|
|
139
|
+
email: "author@example.com",
|
|
140
|
+
},
|
|
141
|
+
message: addedFilePaths
|
|
142
|
+
.map((filePath) => `add: ${this.gitRelativeFilePath(filePath)}`)
|
|
143
|
+
.concat(removedFilePaths.map((filePath) => `remove: ${this.gitRelativeFilePath(filePath)}`))
|
|
144
|
+
.join("\n"),
|
|
145
|
+
});
|
|
146
|
+
return { version: objectId };
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
gitRelativeFilePath(path) {
|
|
150
|
+
return relative(this.gitParameters.dir, path);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=AbstractVersionedRdfFileGraphStore.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RdfDirectoryGraphStore, RdfFileGraphStore } from "@rdfx/fs";
|
|
2
|
+
import type { VersionedGraphStore } from "@rdfx/graph-store";
|
|
3
|
+
export type GitGraphStore = VersionedGraphStore<string>;
|
|
4
|
+
export declare namespace GitGraphStore {
|
|
5
|
+
function wrap(delegate: RdfDirectoryGraphStore | RdfFileGraphStore): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=GitDirectoryGraphStore.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
import { NodeFileSystem } from "@rdfx/fs";
|
|
3
|
+
import { type Either } from "purify-ts";
|
|
4
|
+
/**
|
|
5
|
+
* FileSystem implementation that git adds/removes files that are written or deleted successfully from the underlying node:fs.
|
|
6
|
+
*/
|
|
7
|
+
export declare class GitFileSystem extends NodeFileSystem {
|
|
8
|
+
private readonly gitParameters;
|
|
9
|
+
constructor({ dir, gitdir, }: {
|
|
10
|
+
dir: string;
|
|
11
|
+
gitdir?: string;
|
|
12
|
+
});
|
|
13
|
+
writeFileStream<ReturnT>(path: string, write: (stream: Writable) => Promise<Either<Error, ReturnT>>): Promise<Either<Error, ReturnT>>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=GitFileSystem.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import { NodeFileSystem } from "@rdfx/fs";
|
|
4
|
+
import * as git from "isomorphic-git";
|
|
5
|
+
import { EitherAsync } from "purify-ts";
|
|
6
|
+
/**
|
|
7
|
+
* FileSystem implementation that git adds/removes files that are written or deleted successfully from the underlying node:fs.
|
|
8
|
+
*/
|
|
9
|
+
export class GitFileSystem extends NodeFileSystem {
|
|
10
|
+
gitParameters;
|
|
11
|
+
constructor({ dir, gitdir, }) {
|
|
12
|
+
super();
|
|
13
|
+
this.gitParameters = {
|
|
14
|
+
dir,
|
|
15
|
+
fs: fs.promises,
|
|
16
|
+
gitdir,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async writeFileStream(path, write) {
|
|
20
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
21
|
+
const result = await liftEither(await super.writeFileStream(path, write));
|
|
22
|
+
await git.add({
|
|
23
|
+
...this.gitParameters,
|
|
24
|
+
filepath: relative(this.gitParameters.dir, path),
|
|
25
|
+
});
|
|
26
|
+
return result;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=GitFileSystem.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RdfDirectoryGraphStore, RdfFileGraphStore } from "@rdfx/fs";
|
|
2
|
+
import type { VersionedGraphStore } from "@rdfx/graph-store";
|
|
3
|
+
export type GitGraphStore = VersionedGraphStore<string>;
|
|
4
|
+
export declare namespace GitGraphStore {
|
|
5
|
+
function wrap(delegate: RdfDirectoryGraphStore | RdfFileGraphStore): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=GitGraphStore%20copy.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RdfDirectoryGraphStore, RdfFileGraphStore } from "@rdfx/fs";
|
|
2
|
+
import type { VersionedGraphStore } from "@rdfx/graph-store";
|
|
3
|
+
export type GitGraphStore = VersionedGraphStore<string>;
|
|
4
|
+
export declare namespace GitGraphStore {
|
|
5
|
+
function wrap(delegate: RdfDirectoryGraphStore | RdfFileGraphStore): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=GitGraphStore.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { Dirent, ErrnoException, FileSystem, Stat } from "@rdfx/fs";
|
|
3
|
+
import * as git from "isomorphic-git";
|
|
4
|
+
import { type Either } from "purify-ts";
|
|
5
|
+
/**
|
|
6
|
+
* FileSystem implementation that git adds/removes files that are written or deleted successfully from the underlying node:fs.
|
|
7
|
+
*/
|
|
8
|
+
export declare class VersionedFileSystem implements FileSystem {
|
|
9
|
+
private readonly delegate;
|
|
10
|
+
readonly gitParameters: VersionedFileSystem.GitParameters & {
|
|
11
|
+
readonly fs: git.PromiseFsClient;
|
|
12
|
+
};
|
|
13
|
+
constructor({ delegate, gitParameters, }: {
|
|
14
|
+
delegate: FileSystem;
|
|
15
|
+
gitParameters: VersionedFileSystem.GitParameters;
|
|
16
|
+
});
|
|
17
|
+
createDirectory(path: string, options?: FileSystem.CreateDirectoryOptions): Promise<Either<ErrnoException, void>>;
|
|
18
|
+
createReadStream(path: string): Readable;
|
|
19
|
+
deleteDirectory(path: string, options?: FileSystem.DeleteDirectoryOptions): Promise<Either<ErrnoException, void>>;
|
|
20
|
+
deleteFile(path: string, options?: FileSystem.DeleteFileOptions): Promise<Either<ErrnoException, void>>;
|
|
21
|
+
gitRelativeFilePath(path: string): string;
|
|
22
|
+
readDirectory(path: string, options?: FileSystem.ReadDirectoryOptions): Promise<Either<ErrnoException, readonly Dirent[]>>;
|
|
23
|
+
readFile(path: string): Promise<Either<ErrnoException, Uint8Array>>;
|
|
24
|
+
realpath(path: string): Promise<Either<ErrnoException, string>>;
|
|
25
|
+
stat(path: string): Promise<Either<ErrnoException, Stat>>;
|
|
26
|
+
writeFile(path: string, data: Uint8Array): Promise<Either<ErrnoException, void>>;
|
|
27
|
+
writeFileStream<ReturnT>(path: string, write: (stream: Writable) => Promise<Either<Error, ReturnT>>): Promise<Either<Error, ReturnT>>;
|
|
28
|
+
}
|
|
29
|
+
export declare namespace VersionedFileSystem {
|
|
30
|
+
interface GitParameters {
|
|
31
|
+
readonly dir: string;
|
|
32
|
+
readonly gitdir?: string;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=VersionedFileSystem.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import * as git from "isomorphic-git";
|
|
4
|
+
import { EitherAsync } from "purify-ts";
|
|
5
|
+
/**
|
|
6
|
+
* FileSystem implementation that git adds/removes files that are written or deleted successfully from the underlying node:fs.
|
|
7
|
+
*/
|
|
8
|
+
export class VersionedFileSystem {
|
|
9
|
+
delegate;
|
|
10
|
+
gitParameters;
|
|
11
|
+
constructor({ delegate, gitParameters, }) {
|
|
12
|
+
this.delegate = delegate;
|
|
13
|
+
this.gitParameters = { ...gitParameters, fs: fs.promises };
|
|
14
|
+
}
|
|
15
|
+
createDirectory(path, options) {
|
|
16
|
+
return this.delegate.createDirectory(path, options);
|
|
17
|
+
}
|
|
18
|
+
createReadStream(path) {
|
|
19
|
+
return this.delegate.createReadStream(path);
|
|
20
|
+
}
|
|
21
|
+
async deleteDirectory(path, options) {
|
|
22
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
23
|
+
const filePaths = (await liftEither(await this.delegate.readDirectory(path, options)))
|
|
24
|
+
.filter((dirent) => dirent.isFile())
|
|
25
|
+
.map((dirent) => join(dirent.parentPath, dirent.name));
|
|
26
|
+
await liftEither(await this.delegate.deleteDirectory(path, options));
|
|
27
|
+
for (const filePath of filePaths) {
|
|
28
|
+
await git.remove({
|
|
29
|
+
...this.gitParameters,
|
|
30
|
+
filepath: this.gitRelativeFilePath(filePath),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async deleteFile(path, options) {
|
|
36
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
37
|
+
await liftEither(await this.delegate.deleteFile(path, options));
|
|
38
|
+
await git.remove({
|
|
39
|
+
...this.gitParameters,
|
|
40
|
+
filepath: this.gitRelativeFilePath(path),
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
gitRelativeFilePath(path) {
|
|
45
|
+
return relative(this.gitParameters.dir, path);
|
|
46
|
+
}
|
|
47
|
+
readDirectory(path, options) {
|
|
48
|
+
return this.delegate.readDirectory(path, options);
|
|
49
|
+
}
|
|
50
|
+
readFile(path) {
|
|
51
|
+
return this.delegate.readFile(path);
|
|
52
|
+
}
|
|
53
|
+
realpath(path) {
|
|
54
|
+
return this.delegate.realpath(path);
|
|
55
|
+
}
|
|
56
|
+
stat(path) {
|
|
57
|
+
return this.delegate.stat(path);
|
|
58
|
+
}
|
|
59
|
+
async writeFile(path, data) {
|
|
60
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
61
|
+
await liftEither(await this.delegate.writeFile(path, data));
|
|
62
|
+
await git.add({
|
|
63
|
+
...this.gitParameters,
|
|
64
|
+
filepath: this.gitRelativeFilePath(path),
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async writeFileStream(path, write) {
|
|
69
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
70
|
+
const result = await liftEither(await this.delegate.writeFileStream(path, write));
|
|
71
|
+
await git.add({
|
|
72
|
+
...this.gitParameters,
|
|
73
|
+
filepath: this.gitRelativeFilePath(path),
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=VersionedFileSystem.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Stream } from "@rdfjs/types";
|
|
2
|
+
import { type FileSystem, RdfDirectoryGraphStore } from "@rdfx/fs";
|
|
3
|
+
import type { GraphIdentifier } from "@rdfx/graph-store";
|
|
4
|
+
import { type Either, Maybe } from "purify-ts";
|
|
5
|
+
import { AbstractVersionedRdfFileGraphStore } from "./AbstractVersionedRdfFileGraphStore.js";
|
|
6
|
+
export declare class VersionedRdfDirectoryGraphStore extends AbstractVersionedRdfFileGraphStore {
|
|
7
|
+
constructor(path: string, options?: Partial<ConstructorParameters<typeof AbstractVersionedRdfFileGraphStore>[1]>);
|
|
8
|
+
protected getVersion(identifier: GraphIdentifier, version: string): Promise<Either<Error, Maybe<Stream>>>;
|
|
9
|
+
protected delegate(options?: {
|
|
10
|
+
fileSystem?: FileSystem;
|
|
11
|
+
}): RdfDirectoryGraphStore;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=VersionedRdfDirectoryGraphStore.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import dataFactory from "@rdfx/data-factory";
|
|
3
|
+
import { CompressedRdfStream, RdfDirectoryGraphStore, } from "@rdfx/fs";
|
|
4
|
+
import * as git from "isomorphic-git";
|
|
5
|
+
import { EitherAsync, Maybe } from "purify-ts";
|
|
6
|
+
import { AbstractVersionedRdfFileGraphStore } from "./AbstractVersionedRdfFileGraphStore.js";
|
|
7
|
+
export class VersionedRdfDirectoryGraphStore extends AbstractVersionedRdfFileGraphStore {
|
|
8
|
+
constructor(path, options) {
|
|
9
|
+
super(path, {
|
|
10
|
+
gitParameters: options?.gitParameters ?? {
|
|
11
|
+
dir: path,
|
|
12
|
+
},
|
|
13
|
+
logger: options?.logger,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async getVersion(identifier, version) {
|
|
17
|
+
return EitherAsync(async () => {
|
|
18
|
+
let blob;
|
|
19
|
+
try {
|
|
20
|
+
blob = (await git.readBlob({
|
|
21
|
+
...this.gitParameters,
|
|
22
|
+
oid: version,
|
|
23
|
+
filepath: this.gitRelativeFilePath(this.delegate().graphFilePath(identifier)),
|
|
24
|
+
})).blob;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof git.Errors.NotFoundError) {
|
|
28
|
+
return Maybe.empty();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const stream = CompressedRdfStream.parse(RdfDirectoryGraphStore.fileFormat, Readable.from(Buffer.from(blob)));
|
|
35
|
+
return Maybe.of(identifier.termType === "DefaultGraph"
|
|
36
|
+
? stream
|
|
37
|
+
: stream.map((quad) => dataFactory.quad(quad.subject, quad.predicate, quad.object, identifier)));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
delegate(options) {
|
|
41
|
+
return new RdfDirectoryGraphStore(this.path, {
|
|
42
|
+
...options,
|
|
43
|
+
logger: this.logger,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=VersionedRdfDirectoryGraphStore.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Stream } from "@rdfjs/types";
|
|
2
|
+
import { type FileSystem, RdfFileGraphStore, RdfFormat } from "@rdfx/fs";
|
|
3
|
+
import type { GraphIdentifier } from "@rdfx/graph-store";
|
|
4
|
+
import { type Either, Maybe } from "purify-ts";
|
|
5
|
+
import { AbstractVersionedRdfFileGraphStore } from "./AbstractVersionedRdfFileGraphStore.js";
|
|
6
|
+
export declare class VersionedRdfFileGraphStore extends AbstractVersionedRdfFileGraphStore {
|
|
7
|
+
private readonly format;
|
|
8
|
+
constructor(path: string, options?: Partial<ConstructorParameters<typeof AbstractVersionedRdfFileGraphStore>[1]> & {
|
|
9
|
+
format?: RdfFormat;
|
|
10
|
+
});
|
|
11
|
+
protected delegate(options?: {
|
|
12
|
+
fileSystem?: FileSystem;
|
|
13
|
+
}): RdfFileGraphStore;
|
|
14
|
+
protected getVersion(identifier: GraphIdentifier, version: string): Promise<Either<Error, Maybe<Stream>>>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=VersionedRdfFileGraphStore.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { Readable } from "node:stream";
|
|
9
|
+
import { CompressedRdfStream, RdfFileGraphStore, RdfFormat, } from "@rdfx/fs";
|
|
10
|
+
import * as git from "isomorphic-git";
|
|
11
|
+
import { EitherAsync, Maybe } from "purify-ts";
|
|
12
|
+
import { Memoize } from "typescript-memoize";
|
|
13
|
+
import { AbstractVersionedRdfFileGraphStore } from "./AbstractVersionedRdfFileGraphStore.js";
|
|
14
|
+
export class VersionedRdfFileGraphStore extends AbstractVersionedRdfFileGraphStore {
|
|
15
|
+
format;
|
|
16
|
+
constructor(path, options) {
|
|
17
|
+
super(path, {
|
|
18
|
+
gitParameters: options?.gitParameters ?? {
|
|
19
|
+
dir: dirname(path),
|
|
20
|
+
},
|
|
21
|
+
logger: options?.logger,
|
|
22
|
+
});
|
|
23
|
+
this.format = options?.format ?? RdfFormat.fromPath(path).unsafeCoerce();
|
|
24
|
+
}
|
|
25
|
+
delegate(options) {
|
|
26
|
+
return new RdfFileGraphStore(this.path, {
|
|
27
|
+
...options,
|
|
28
|
+
format: this.format,
|
|
29
|
+
logger: this.logger,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async getVersion(identifier, version) {
|
|
33
|
+
return EitherAsync(async () => {
|
|
34
|
+
let blob;
|
|
35
|
+
try {
|
|
36
|
+
blob = (await git.readBlob({
|
|
37
|
+
...this.gitParameters,
|
|
38
|
+
oid: version,
|
|
39
|
+
filepath: this.gitRelativeFilePath(this.path),
|
|
40
|
+
})).blob;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof git.Errors.NotFoundError) {
|
|
44
|
+
return Maybe.empty();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return Maybe.of(CompressedRdfStream.parse(this.format, Readable.from(Buffer.from(blob))).filter((quad) => quad.graph.equals(identifier)));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
__decorate([
|
|
55
|
+
Memoize()
|
|
56
|
+
], VersionedRdfFileGraphStore.prototype, "delegate", null);
|
|
57
|
+
//# sourceMappingURL=VersionedRdfFileGraphStore.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@rdfx/fs": "0.0.34",
|
|
4
|
+
"@rdfx/graph-store": "0.0.34",
|
|
5
|
+
"isomorphic-git": "~1.38.3",
|
|
6
|
+
"ts-log": "~3.0.2",
|
|
7
|
+
"typescript-memoize": "~1.1.1"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {},
|
|
10
|
+
"files": [
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"dist/*.d.ts",
|
|
13
|
+
"dist/*.js"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"name": "@rdfx/git",
|
|
18
|
+
"packageManager": "npm@11.11.0",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/minorg/rdfx.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b",
|
|
25
|
+
"clean": "rimraf dist",
|
|
26
|
+
"depcheck": "depcheck .",
|
|
27
|
+
"dev": "tsc -w --preserveWatchOutput",
|
|
28
|
+
"dev:tests": "tsc -p __tests__ -w --preserveWatchOutput",
|
|
29
|
+
"test": "cd ../.. && vitest run /Users/minor/projects/rdfx/packages/git/__tests__"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"version": "0.0.34"
|
|
34
|
+
}
|