Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forEachVertex-method #42

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/graph/file.graph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
FileGraphAbstract,
ICallbackVertex,
IFindVertex,
IPredicate,
IUpdater,
Expand All @@ -13,8 +14,8 @@

class FileGraphIml implements FileGraphAbstract {
constructor(
private readonly storageFile: StorageFile,

Check warning on line 17 in lib/graph/file.graph.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'storageFile' is defined but never used

Check warning on line 17 in lib/graph/file.graph.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'storageFile' is defined but never used
private readonly asyncTaskQueue: AsyncTaskQueue,

Check warning on line 18 in lib/graph/file.graph.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'asyncTaskQueue' is defined but never used

Check warning on line 18 in lib/graph/file.graph.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'asyncTaskQueue' is defined but never used
) {}

public async createVertex<T extends object>(data: T): Promise<IVertex<T>> {
Expand Down Expand Up @@ -47,7 +48,7 @@
);
}

public async findOne<T extends object>(
public findOne<T extends object>(
predicate: IPredicate<T>,
): Promise<IVertex<T> | null> {
return this.storageFile.searchLine(predicate);
Expand All @@ -64,6 +65,12 @@
return vertices;
}

public async forEachVertex<T extends object>(
callbackVertex: ICallbackVertex<T>,
): Promise<void> {
await this.storageFile.searchLine(callbackVertex);
}

public async createEdge(ids: IUuidArray): Promise<boolean> {
const updater = (vertex: IVertex<object>) => {
const index = ids.indexOf(vertex.id);
Expand Down
3 changes: 2 additions & 1 deletion lib/graph/storage.file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import readline from 'readline';
import { mergeVertices, uuid } from '../utils';
import {
ICallbackVertex,
IFindVertex,
ILineReturn,
IPredicate,
Expand All @@ -16,7 +17,7 @@
} from '../interfaces';

export class StorageFile {
constructor(private readonly path: string) {}

Check warning on line 20 in lib/graph/storage.file.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'path' is defined but never used

Check warning on line 20 in lib/graph/storage.file.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'path' is defined but never used

public async appendFile<T extends object>(vertex: T): Promise<void> {
const vertexSer = Array.isArray(vertex)
Expand All @@ -27,7 +28,7 @@
}

public async searchLine<T extends object>(
predicate: IFindVertex<T> | IPredicate<T>,
predicate: IFindVertex<T> | IPredicate<T> | ICallbackVertex<T>,
): Promise<IVertex<T>> {
const fileStream = this.createLineStream(true);
return await fileStream(async line => {
Expand Down
13 changes: 13 additions & 0 deletions lib/interfaces/graph.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ICallbackVertex,
IPredicate,
IUpdater,
IUuidArray,
Expand All @@ -13,7 +14,7 @@
* @param {T} data - The data vertex for creating the node.
* @returns {IVertex<T>} - created node.
*/
public abstract createVertex<T extends object>(data: T): Promise<IVertex<T>>;

Check warning on line 17 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'data' is defined but never used

Check warning on line 17 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'data' is defined but never used

/**
* Creates multiple vertices in the graph.
Expand All @@ -24,7 +25,7 @@
* @returns {Promise<uuidType[]>} A promise that resolves to an array of unique identifiers of the created vertices.
*/
public abstract createVertices<T extends object>(
data: T[],

Check warning on line 28 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'data' is defined but never used

Check warning on line 28 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'data' is defined but never used
): Promise<IVertex<T>[]>;

/**
Expand All @@ -39,7 +40,7 @@
* @returns {Promise<boolean>} A promise that resolves to `true` if the record was successfully updated, and `false` if the record was not found or an error occurred.
*/
public abstract updateVertex<T extends object>(
updater: IUpdater<T>,

Check warning on line 43 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'updater' is defined but never used

Check warning on line 43 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'updater' is defined but never used
): Promise<boolean>;

/**
Expand All @@ -54,7 +55,7 @@
* @returns {Promise<boolean>} A promise that resolves to `true` if the record was successfully deleted, and `false` if the record was not found or an error occurred.
*/
public abstract deleteVertex<T extends object>(
predicate: IPredicate<T>,

Check warning on line 58 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used

Check warning on line 58 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used
): Promise<boolean>;

/**
Expand All @@ -64,7 +65,7 @@
* @returns {Promise<T | null>} A promise that resolves to the found vertex if a match is found, or `null` if no match is found.
*/
public abstract findOne<T extends object>(
predicate: IPredicate<T>,

Check warning on line 68 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used

Check warning on line 68 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used
): Promise<IVertex<T> | null>;

/**
Expand All @@ -77,9 +78,21 @@
* @returns {Promise<T[]>} A promise that resolves to an array of vertices that match the search criteria.
*/
public abstract findAll<T extends object>(
predicate: IPredicate<T>,

Check warning on line 81 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used

Check warning on line 81 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'predicate' is defined but never used
): Promise<IVertex<T>[]>;

/**
* Iterates over each vertex in the graph and applies the provided callback function.
*
* @template T - The type of the vertex object.
* @param {ICallbackVertex<T>} callbackVertex - A callback function that is invoked for each vertex.
* If it returns `true`, the iteration stops.
* @returns {Promise<void>} - A promise that resolves when the iteration is complete or has been stopped.
*/
public abstract forEachVertex<T extends object>(
callbackVertex: ICallbackVertex<T>,

Check warning on line 93 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'callbackVertex' is defined but never used

Check warning on line 93 in lib/interfaces/graph.interface.ts

View workflow job for this annotation

GitHub Actions / lint-and-test (20.x)

'callbackVertex' is defined but never used
): Promise<void>;

/**
* Creates edges (links) between the specified vertices.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/interfaces/params.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export interface IVertexTree<T extends object> extends IVertex<T> {

export type IUuidArray = [uuidType, ...uuidType[]];
export type IPredicate<T extends object> = (vertex: IVertex<T>) => boolean;
export type ICallbackVertex<T extends object> = (
vertex: IVertex<T>,
) => void | boolean;
export type IUpdater<T extends object> = (
vertex: IVertex<T>,
) => IVertex<T> | object;
Expand Down
Loading