@duraxis/storage-disk 0.0.0-stage → 0.1.0
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/CHANGELOG.md +4 -0
- package/LICENSE +15 -0
- package/README.md +32 -2
- package/dist/async-disk-storage.driver.d.ts +70 -0
- package/dist/disk-format.d.ts +28 -0
- package/dist/index.cjs +669 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +668 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -3
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Dias
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @duraxis/storage-disk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Driver assíncrono de filesystem para Duraxis. Ele armazena objetos e journal em um diretório
|
|
4
|
+
local e exige posse exclusiva desse diretório enquanto estiver aberto.
|
|
5
|
+
|
|
6
|
+
## Instalação
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @duraxis/storage-disk
|
|
10
|
+
npm install @duraxis/storage-disk
|
|
11
|
+
yarn add @duraxis/storage-disk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { AsyncDiskStorageDriver } from "@duraxis/storage-disk";
|
|
16
|
+
|
|
17
|
+
const storage = await AsyncDiskStorageDriver.open({ directory: "./data/duraxis" });
|
|
18
|
+
try {
|
|
19
|
+
await storage.put("example", new TextEncoder().encode("value"), {
|
|
20
|
+
condition: { type: "if-absent" },
|
|
21
|
+
});
|
|
22
|
+
} finally {
|
|
23
|
+
await storage.close();
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
A API exporta `AsyncDiskStorageDriver` e os tipos de opção, capacidades de durabilidade,
|
|
28
|
+
injeção de falhas e recuperação de posse. A recuperação de uma trava abandonada exige a
|
|
29
|
+
confirmação explícita definida pela API e só deve ocorrer após verificar acesso exclusivo.
|
|
30
|
+
|
|
31
|
+
O driver integra-se a `@duraxis/core` por meio do contrato de `@duraxis/storage`. Ele não oferece
|
|
32
|
+
coordenação entre hosts e as garantias frente a perda de energia dependem do suporte do sistema
|
|
33
|
+
operacional a sincronização de arquivos e diretórios. Requer Node.js 22.12+.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type DeleteOptions, type DeleteResult, type StorageDriver, type StorageDriverMetrics, type StorageObject, type StorageObjectInfo, type WriteOptions, type WriteResult } from "@duraxis/storage";
|
|
2
|
+
declare const OWNERSHIP_CONFIRMATION = "I_HAVE_VERIFIED_EXCLUSIVE_ACCESS";
|
|
3
|
+
export type DiskFaultPoint = "after-object-sync" | "after-object-publish" | "after-object-directory-sync" | "after-journal-write" | "after-journal-sync" | "after-journal-rotation";
|
|
4
|
+
export interface DiskFaultContext {
|
|
5
|
+
readonly operation: "put" | "delete" | "compact";
|
|
6
|
+
readonly key?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AsyncDiskStorageOptions {
|
|
9
|
+
readonly directory: string;
|
|
10
|
+
readonly maxKeyBytes?: number;
|
|
11
|
+
readonly maxObjectBytes?: number;
|
|
12
|
+
readonly maxJournalBytes?: number;
|
|
13
|
+
readonly nodeCacheHint?: number;
|
|
14
|
+
readonly faultInjector?: (point: DiskFaultPoint, context: DiskFaultContext) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface RecoverOwnershipOptions {
|
|
17
|
+
readonly directory: string;
|
|
18
|
+
readonly confirmation: typeof OWNERSHIP_CONFIRMATION;
|
|
19
|
+
}
|
|
20
|
+
export interface DiskDurabilityCapabilities {
|
|
21
|
+
readonly fileDataSync: true;
|
|
22
|
+
readonly directoryEntrySync: boolean;
|
|
23
|
+
readonly ownership: "exclusive-directory";
|
|
24
|
+
readonly processCrashRecovery: true;
|
|
25
|
+
readonly powerLossGuarantee: "file-and-directory-sync" | "file-sync-only";
|
|
26
|
+
}
|
|
27
|
+
export declare class AsyncDiskStorageDriver implements StorageDriver {
|
|
28
|
+
private readonly root;
|
|
29
|
+
private readonly registryKey;
|
|
30
|
+
private readonly options;
|
|
31
|
+
private static readonly activeDirectories;
|
|
32
|
+
private readonly entries;
|
|
33
|
+
private readonly ownerId;
|
|
34
|
+
private readonly metrics;
|
|
35
|
+
private operationTail;
|
|
36
|
+
private journal;
|
|
37
|
+
private lockHandle;
|
|
38
|
+
private journalBytes;
|
|
39
|
+
private sequence;
|
|
40
|
+
private directorySync;
|
|
41
|
+
private closed;
|
|
42
|
+
private closing;
|
|
43
|
+
private poisoned;
|
|
44
|
+
private constructor();
|
|
45
|
+
static open(options: AsyncDiskStorageOptions): Promise<AsyncDiskStorageDriver>;
|
|
46
|
+
static recoverAbandonedOwnership(options: RecoverOwnershipOptions): Promise<void>;
|
|
47
|
+
get durability(): DiskDurabilityCapabilities;
|
|
48
|
+
getMetrics(): Readonly<StorageDriverMetrics>;
|
|
49
|
+
private initialize;
|
|
50
|
+
private validateKey;
|
|
51
|
+
private assertUsable;
|
|
52
|
+
private exclusive;
|
|
53
|
+
get(key: string): Promise<StorageObject | null>;
|
|
54
|
+
put(key: string, data: Uint8Array, options: WriteOptions): Promise<WriteResult>;
|
|
55
|
+
delete(key: string, options: DeleteOptions): Promise<DeleteResult>;
|
|
56
|
+
list(prefix: string): Promise<readonly StorageObjectInfo[]>;
|
|
57
|
+
private append;
|
|
58
|
+
compact(): Promise<void>;
|
|
59
|
+
close(): Promise<void>;
|
|
60
|
+
private objectPath;
|
|
61
|
+
private assertCurrentObjectsExist;
|
|
62
|
+
private cleanupPhysicalObjects;
|
|
63
|
+
private recoverJournalRotation;
|
|
64
|
+
private fault;
|
|
65
|
+
private removeObsolete;
|
|
66
|
+
private syncDirectory;
|
|
67
|
+
private static syncDirectoryStatic;
|
|
68
|
+
private cleanupFailedOpen;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const MAX_JOURNAL_FRAME_BYTES: number;
|
|
2
|
+
export interface StoredMetadata {
|
|
3
|
+
readonly version: string;
|
|
4
|
+
readonly createdAt: number;
|
|
5
|
+
readonly size: number;
|
|
6
|
+
readonly digest: string;
|
|
7
|
+
}
|
|
8
|
+
export type JournalPayload = ({
|
|
9
|
+
readonly format: 1;
|
|
10
|
+
readonly sequence: number;
|
|
11
|
+
readonly op: "put";
|
|
12
|
+
readonly key: string;
|
|
13
|
+
} & StoredMetadata) | {
|
|
14
|
+
readonly format: 1;
|
|
15
|
+
readonly sequence: number;
|
|
16
|
+
readonly op: "delete";
|
|
17
|
+
readonly key: string;
|
|
18
|
+
};
|
|
19
|
+
export interface DecodedJournal {
|
|
20
|
+
readonly frames: readonly JournalPayload[];
|
|
21
|
+
readonly validBytes: number;
|
|
22
|
+
readonly incompleteTail: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function sha256(data: Uint8Array | string): string;
|
|
25
|
+
export declare function encodePhysicalObject(key: string, metadata: StoredMetadata, data: Uint8Array): Uint8Array;
|
|
26
|
+
export declare function decodePhysicalObject(bytes: Uint8Array, expectedKey: string, expected: StoredMetadata): Uint8Array;
|
|
27
|
+
export declare function encodeJournalFrame(payload: JournalPayload): Uint8Array;
|
|
28
|
+
export declare function decodeJournal(bytes: Uint8Array): DecodedJournal;
|