@jsonkit/db 1.0.1 → 3.0.1

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.
@@ -1,4 +1,4 @@
1
- import type { FileMeta } from './types';
1
+ import type { FileMeta } from '../common/types';
2
2
  type ListOptions = {
3
3
  depth?: number;
4
4
  stripBasepath?: string;
@@ -18,7 +18,7 @@ type CopyOptions = {
18
18
  recursive?: boolean;
19
19
  overwrite?: boolean;
20
20
  };
21
- export declare class FilesService {
21
+ export declare class Files {
22
22
  move(oldPath: string, newPath: string): Promise<void>;
23
23
  copy(sourcePath: string, destinationPath: string, options?: CopyOptions): Promise<void>;
24
24
  copyRecursive(sourcePath: string, destinationPath: string): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { Identifiable, DeleteManyOutput, Promisable, JsonEntryParser, MultiEntryFileDbOptions, MultiEntryDb } from '../common';
2
+ import { Files } from './files';
3
+ export declare class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {
4
+ protected readonly dirpath: string;
5
+ protected readonly files: Files;
6
+ protected readonly parser: JsonEntryParser<T>;
7
+ readonly noPathlikeIds: boolean;
8
+ constructor(dirpath: string, options?: MultiEntryFileDbOptions<T>);
9
+ create(entry: T): Promise<T>;
10
+ getById(id: T['id']): Promise<T | null>;
11
+ update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
12
+ deleteById(id: T['id']): Promise<boolean>;
13
+ deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
14
+ destroy(): Promise<void>;
15
+ protected getFilePath(id: T['id']): string;
16
+ protected writeEntry(entry: T): Promise<void>;
17
+ isIdValid(id: T['id']): boolean;
18
+ protected iterEntries(): AsyncGenerator<T, void, unknown>;
19
+ protected iterIds(): AsyncGenerator<string, void, unknown>;
20
+ }
@@ -1,9 +1,9 @@
1
- import type { JsonEntryParser, Promisable } from './types';
2
- import { FilesService } from './files';
1
+ import { JsonEntryParser, Promisable } from '../common/types';
2
+ import { Files } from './files';
3
3
  export declare class SingleEntryFileDb<T> {
4
4
  protected readonly filepath: string;
5
5
  protected readonly parser: JsonEntryParser<T>;
6
- protected readonly files: FilesService;
6
+ protected readonly files: Files;
7
7
  constructor(filepath: string, parser?: JsonEntryParser<T>);
8
8
  path(): string;
9
9
  isInited(): Promise<boolean>;
@@ -1,3 +1,5 @@
1
- export * from './multiEntryFileDb';
2
- export * from './singleEntryFileDb';
3
- export * from './types';
1
+ export * from './file/multiEntryFileDb';
2
+ export * from './file/singleEntryFileDb';
3
+ export * from './memory/multiEntryMemDb';
4
+ export * from './memory/singleEntryMemDb';
5
+ export * from './common/types';
@@ -0,0 +1,11 @@
1
+ import { Identifiable, Promisable, MultiEntryDb } from '../common';
2
+ export declare class MultiEntryMemDb<T extends Identifiable> extends MultiEntryDb<T> {
3
+ protected entries: Map<T['id'], T>;
4
+ create(entry: T): Promise<T>;
5
+ getById(id: T['id']): Promise<T | null>;
6
+ update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
7
+ deleteById(id: T['id']): Promise<boolean>;
8
+ destroy(): Promise<void>;
9
+ protected iterEntries(): AsyncGenerator<T, void, unknown>;
10
+ protected iterIds(): AsyncGenerator<T["id"], void, unknown>;
11
+ }
@@ -0,0 +1,8 @@
1
+ export declare class SingleEntryMemDb<T> {
2
+ protected entry: T | null;
3
+ constructor(initialEntry?: T | null);
4
+ isInited(): boolean;
5
+ read(): T;
6
+ write(updaterOrEntry: T | ((entry: T) => Partial<T>)): T;
7
+ delete(): void;
8
+ }
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@jsonkit/db",
3
- "version": "1.0.1",
3
+ "version": "3.0.1",
4
4
  "description": "Simple database using JSON and your local filesystem",
5
5
  "license": "MIT",
6
6
  "author": "taennan <taennan.dev@protonmail.com>",
7
- "repository": "https://github.com/taennan/jsonkit",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/taennan/jsonkit.git"
10
+ },
8
11
  "keywords": [
9
12
  "typescript",
10
13
  "json",
@@ -1,26 +0,0 @@
1
- import type { Identifiable, DeleteManyOutput, Promisable, PredicateFn, JsonEntryParser } from './types';
2
- import { FilesService } from './files';
3
- export declare class MultiEntryFileDb<T extends Identifiable> {
4
- protected readonly dirpath: string;
5
- protected readonly parser: JsonEntryParser<T>;
6
- protected readonly files: FilesService;
7
- constructor(dirpath: string, parser?: JsonEntryParser<T>);
8
- create(entry: T): Promise<T>;
9
- getById(id: T['id']): Promise<T | null>;
10
- getByIdOrThrow(id: T['id']): Promise<T>;
11
- getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]>;
12
- getAll(whereIds?: T['id'][]): Promise<T[]>;
13
- getAllIds(): Promise<T['id'][]>;
14
- update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
15
- delete(id: T['id']): Promise<boolean>;
16
- deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
17
- deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
18
- destroy(): Promise<void>;
19
- exists(id: T['id']): Promise<boolean>;
20
- countAll(): Promise<number>;
21
- countWhere(predicate: PredicateFn<T>): Promise<number>;
22
- protected getFilePath(id: T['id']): string;
23
- protected readEntry(id: T['id']): Promise<T | null>;
24
- protected writeEntry(entry: T): Promise<void>;
25
- protected iterEntries(): AsyncGenerator<T, void, unknown>;
26
- }