@jsonkit/db 3.0.1 → 3.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonkit/db",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Simple database using JSON and your local filesystem",
5
5
  "license": "MIT",
6
6
  "author": "taennan <taennan.dev@protonmail.com>",
@@ -15,28 +15,29 @@
15
15
  "filesystem"
16
16
  ],
17
17
  "type": "module",
18
- "main": "dist/cjs/index.cjs",
19
18
  "module": "dist/esm/index.js",
20
- "types": "dist/types/index.d.ts",
19
+ "main": "dist/cjs/index.cjs",
20
+ "types": "dist/index.d.ts",
21
21
  "exports": {
22
+ "./package.json": "./package.json",
22
23
  ".": {
23
24
  "import": {
24
- "types": "./dist/types/index.d.ts",
25
- "default": "./dist/esm/index.js"
25
+ "default": "./dist/esm/index.js",
26
+ "types": "./dist/index.d.ts"
26
27
  },
27
28
  "require": {
28
- "types": "./dist/types/index.d.ts",
29
- "default": "./dist/cjs/index.cjs"
29
+ "default": "./dist/cjs/index.cjs",
30
+ "types": "./dist/index.d.ts"
30
31
  }
31
32
  }
32
33
  },
33
34
  "scripts": {
34
- "build": "npm run clean && npm run build:bundle && npm run build:types",
35
+ "build": "npm run clean && npm run build:bundle",
35
36
  "clean": "rm -rf dist",
36
- "check": "tsc --noEmit",
37
- "build:bundle": "npx rollup -c --bundleConfigAsCjs",
38
- "build:types": "tsc -p tsconfig.json",
39
- "fmt": "prettier --write .",
37
+ "build:bundle": "npx rollup -c",
38
+ "fix": "npm run fix:types && npm run fix:format",
39
+ "fix:types": "tsc --noEmit",
40
+ "fix:format": "prettier --write . --config ../../.prettierrc --ignore-path ../../.prettierignore",
40
41
  "test": "jest"
41
42
  },
42
43
  "files": [
@@ -1,2 +0,0 @@
1
- export * from './multiEntryDb';
2
- export * from './types';
@@ -1,19 +0,0 @@
1
- import type { Identifiable, DeleteManyOutput, PaginationInput, PredicateFn, Promisable } from './types';
2
- export declare abstract class MultiEntryDb<T extends Identifiable> {
3
- abstract create(entry: T): Promise<T>;
4
- abstract getById(id: T['id']): Promise<T | null>;
5
- abstract update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
6
- abstract deleteById(id: T['id']): Promise<boolean>;
7
- abstract destroy(): Promise<void>;
8
- protected abstract iterEntries(): AsyncIterable<T>;
9
- protected abstract iterIds(): AsyncIterable<T['id']>;
10
- getByIdOrThrow(id: T['id']): Promise<T>;
11
- getWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<T[]>;
12
- getAll(): Promise<T[]>;
13
- getAllIds(): Promise<T['id'][]>;
14
- deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
15
- deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
16
- exists(id: T['id']): Promise<boolean>;
17
- countAll(): Promise<number>;
18
- countWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<number>;
19
- }
@@ -1,38 +0,0 @@
1
- export type Identifiable = {
2
- id: Id;
3
- };
4
- export type Id = string;
5
- export type Promisable<T> = T | Promise<T>;
6
- export type PaginationInput = {
7
- take: number;
8
- page: number;
9
- skip?: number | undefined | null;
10
- };
11
- export type DeleteManyOutput = {
12
- deletedIds: Id[];
13
- ignoredIds: Id[];
14
- };
15
- export type PredicateFn<T extends Identifiable> = (entry: T) => boolean;
16
- export type JsonEntryParser<T> = {
17
- parse: (text: string) => T;
18
- };
19
- export type MultiEntryFileDbOptions<T> = {
20
- noPathlikeIds?: boolean;
21
- parser?: JsonEntryParser<T>;
22
- };
23
- export type FileMeta = {
24
- path: string;
25
- size: number;
26
- created: Date;
27
- modified: Date;
28
- accessed: Date;
29
- } & ({
30
- type: FileType.File;
31
- } | {
32
- type: FileType.Directory;
33
- children: FileMeta[];
34
- });
35
- export declare enum FileType {
36
- File = "file",
37
- Directory = "directory"
38
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,44 +0,0 @@
1
- import type { FileMeta } from '../common/types';
2
- type ListOptions = {
3
- depth?: number;
4
- stripBasepath?: string;
5
- };
6
- type DeleteOptions = {
7
- force?: boolean;
8
- recursive?: boolean;
9
- };
10
- type WriteOptions = {
11
- encoding?: BufferEncoding;
12
- };
13
- type ReadOptions = {
14
- encoding?: BufferEncoding;
15
- lines?: number;
16
- };
17
- type CopyOptions = {
18
- recursive?: boolean;
19
- overwrite?: boolean;
20
- };
21
- export declare class Files {
22
- move(oldPath: string, newPath: string): Promise<void>;
23
- copy(sourcePath: string, destinationPath: string, options?: CopyOptions): Promise<void>;
24
- copyRecursive(sourcePath: string, destinationPath: string): Promise<void>;
25
- mkdir(filepath: string): Promise<void>;
26
- protected mkdirUnsafe(filepath: string): Promise<void>;
27
- write(filepath: string, content: string, options?: WriteOptions): Promise<void>;
28
- touch(filepath: string): Promise<void>;
29
- read(filepath: string, options?: ReadOptions): Promise<string>;
30
- delete(filepath: string, options?: DeleteOptions): Promise<void>;
31
- exists(filepath: string): Promise<boolean>;
32
- isDir(filepath: string): Promise<boolean>;
33
- isFile(filepath: string): Promise<boolean>;
34
- isSymlink(filepath: string): Promise<boolean>;
35
- getMeta(filepath: string, options?: ListOptions): Promise<FileMeta>;
36
- list(dirpath: string, options?: ListOptions): Promise<string[]>;
37
- listRead(dirpath: string, options?: ListOptions): AsyncGenerator<{
38
- filepath: string;
39
- content: string;
40
- }, void, unknown>;
41
- protected listRecursive(dirpath: string, maxDepth: number, currentDepth: number, stripBasepath: string | undefined): Promise<string[]>;
42
- protected stripBasepath(original: string, pathToStrip: string | undefined): string;
43
- }
44
- export {};
@@ -1,20 +0,0 @@
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,13 +0,0 @@
1
- import { JsonEntryParser, Promisable } from '../common/types';
2
- import { Files } from './files';
3
- export declare class SingleEntryFileDb<T> {
4
- protected readonly filepath: string;
5
- protected readonly parser: JsonEntryParser<T>;
6
- protected readonly files: Files;
7
- constructor(filepath: string, parser?: JsonEntryParser<T>);
8
- path(): string;
9
- isInited(): Promise<boolean>;
10
- read(): Promise<T>;
11
- write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T>;
12
- delete(): Promise<void>;
13
- }
@@ -1,5 +0,0 @@
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';
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
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
- }