@duraxis/core 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.
Files changed (49) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +15 -0
  3. package/README.md +51 -2
  4. package/dist/catalog/collection-schema.d.ts +41 -0
  5. package/dist/commit/commit-coordinator.d.ts +11 -0
  6. package/dist/commit/commit-record.d.ts +9 -0
  7. package/dist/commit/manifest.d.ts +19 -0
  8. package/dist/database/duraxis-database.d.ts +85 -0
  9. package/dist/errors/commit-outcome-unknown.error.d.ts +4 -0
  10. package/dist/errors/transaction-conflict.error.d.ts +4 -0
  11. package/dist/errors/transaction-state.error.d.ts +3 -0
  12. package/dist/gc/garbage-collector.d.ts +31 -0
  13. package/dist/gc/reachability-scanner.d.ts +13 -0
  14. package/dist/index.cjs +3832 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.ts +50 -0
  17. package/dist/index.js +3768 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/indexes/bptree/bptree-batch-store.d.ts +10 -0
  20. package/dist/indexes/bptree/bptree-codec.d.ts +16 -0
  21. package/dist/indexes/bptree/bptree-node-cache.d.ts +17 -0
  22. package/dist/indexes/bptree/bptree-node-store.d.ts +13 -0
  23. package/dist/indexes/bptree/bptree-node.d.ts +44 -0
  24. package/dist/indexes/bptree/bptree-validator.d.ts +17 -0
  25. package/dist/indexes/bptree/bptree.d.ts +27 -0
  26. package/dist/indexes/index-consistency-checker.d.ts +9 -0
  27. package/dist/indexes/index-key.d.ts +28 -0
  28. package/dist/indexes/primary/primary-index.d.ts +19 -0
  29. package/dist/indexes/secondary/secondary-index-manager.d.ts +50 -0
  30. package/dist/integrity/integrity.d.ts +2 -0
  31. package/dist/query/context/query-context.d.ts +58 -0
  32. package/dist/query/executor/operators/operators.d.ts +138 -0
  33. package/dist/query/executor/predicate.d.ts +8 -0
  34. package/dist/query/executor/query-executor.d.ts +24 -0
  35. package/dist/query/model/cursor.d.ts +8 -0
  36. package/dist/query/model/query.d.ts +75 -0
  37. package/dist/query/planner/access-path-enumerator.d.ts +15 -0
  38. package/dist/query/planner/explain.d.ts +2 -0
  39. package/dist/query/planner/physical-plan.d.ts +53 -0
  40. package/dist/query/planner/plan-compiler.d.ts +8 -0
  41. package/dist/query/planner/predicate-analyzer.d.ts +22 -0
  42. package/dist/query/planner/rule-based-planner.d.ts +10 -0
  43. package/dist/query/testing/reference-query-executor.d.ts +10 -0
  44. package/dist/query/validation/query-validator.d.ts +3 -0
  45. package/dist/recovery/recovery-manager.d.ts +10 -0
  46. package/dist/security/storage-key-manager.d.ts +19 -0
  47. package/dist/snapshots/snapshot-reader.d.ts +12 -0
  48. package/dist/transactions/transaction.d.ts +69 -0
  49. package/package.json +58 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # @duraxis/core changelog
2
+
3
+ This file is maintained by Changesets. Future releases will add versioned
4
+ entries automatically.
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,52 @@
1
- # Temporary Holding Version
1
+ # @duraxis/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Motor embutido do Duraxis. Ele usa um `StorageDriver` para manter catálogo, documentos, índices,
4
+ manifests e histórico de commits, e expõe transações, snapshots, consultas e manutenção.
5
+
6
+ ## Instalação
7
+
8
+ Escolha também um driver:
9
+
10
+ ```bash
11
+ pnpm add @duraxis/core @duraxis/storage-memory
12
+ npm install @duraxis/core @duraxis/storage-memory
13
+ yarn add @duraxis/core @duraxis/storage-memory
14
+ ```
15
+
16
+ ## Uso
17
+
18
+ ```ts
19
+ import { DuraxisDatabase } from "@duraxis/core";
20
+ import { MemoryStorageDriver } from "@duraxis/storage-memory";
21
+
22
+ const database = new DuraxisDatabase({ storage: new MemoryStorageDriver() });
23
+
24
+ await database.defineCollection({
25
+ name: "notes",
26
+ fields: { title: { type: "string", required: true } },
27
+ allowAdditionalFields: true,
28
+ indexes: [],
29
+ });
30
+
31
+ await database.transaction((transaction) => {
32
+ transaction.putDocument("notes", "1", { title: "Duraxis" });
33
+ });
34
+
35
+ const note = await database.getDocument("notes", "1");
36
+ await database.close();
37
+ ```
38
+
39
+ ## API principal
40
+
41
+ - `DuraxisDatabase`, `Transaction` e leitura por snapshot;
42
+ - definições de coleção, campos e índices;
43
+ - modelo, validação, planejamento e execução de consultas;
44
+ - B+ tree, índices primário/secundário e verificadores;
45
+ - recuperação, integridade, checkpoint de histórico e garbage collection;
46
+ - erros de conflito, estado de transação e resultado de commit desconhecido.
47
+
48
+ O pacote depende somente de `@duraxis/storage` em runtime. Drivers são instalados
49
+ separadamente. `@duraxis/orm` adiciona entidades e repositórios sobre esta API.
50
+
51
+ Duraxis ainda está em `0.x`. As garantias efetivas dependem do driver; não há coordenação
52
+ distribuída, e o formato persistido pode evoluir. Requer Node.js 22.12+.
@@ -0,0 +1,41 @@
1
+ export type FieldType = "string" | "number" | "boolean" | "date";
2
+ export type IndexOrder = "ASC" | "DESC";
3
+ export type IndexScalar = string | number | boolean | Date | null;
4
+ export interface FieldDefinition {
5
+ readonly type: FieldType;
6
+ readonly required?: boolean;
7
+ readonly nullable?: boolean;
8
+ }
9
+ export interface IndexFieldDefinition {
10
+ readonly field: string;
11
+ readonly order: IndexOrder;
12
+ }
13
+ export interface SecondaryIndexDefinition {
14
+ readonly name: string;
15
+ readonly unique: boolean;
16
+ readonly fields?: readonly IndexFieldDefinition[];
17
+ readonly field?: string;
18
+ }
19
+ export interface CollectionDefinition {
20
+ readonly name: string;
21
+ readonly fields?: Readonly<Record<string, FieldDefinition>>;
22
+ readonly allowAdditionalFields?: boolean;
23
+ readonly indexes: readonly SecondaryIndexDefinition[];
24
+ }
25
+ export type DocumentRecord = Record<string, unknown>;
26
+ export declare const RECORD_PREFIX = "@duraxis/records/";
27
+ export declare function isValidSchemaName(name: unknown): name is string;
28
+ export declare function indexFields(index: SecondaryIndexDefinition): readonly IndexFieldDefinition[];
29
+ export declare function fieldDefinition(schema: CollectionDefinition, name: string): FieldDefinition | undefined;
30
+ export declare function normalizeCollection(schema: CollectionDefinition): CollectionDefinition;
31
+ export declare function validateCollection(schema: CollectionDefinition): void;
32
+ export declare function validateDocument(schema: CollectionDefinition, document: DocumentRecord): DocumentRecord;
33
+ export declare function recordKey(collection: string, id: string): string;
34
+ export declare function parseRecordKey(key: string): {
35
+ collection: string;
36
+ id: string;
37
+ } | null;
38
+ export declare function indexId(collection: string, index: string): string;
39
+ export declare function encodeDocument(document: DocumentRecord): Uint8Array;
40
+ export declare function decodeDocument(bytes: Uint8Array): DocumentRecord;
41
+ export declare function indexedValue(document: DocumentRecord, field: string, definition?: FieldDefinition): IndexScalar | undefined;
@@ -0,0 +1,11 @@
1
+ import type { StorageDriver } from "@duraxis/storage";
2
+ import { Transaction } from "../transactions/transaction.js";
3
+ import { StorageKeyManager } from "../security/storage-key-manager.js";
4
+ export declare class CommitCoordinator {
5
+ private readonly storage;
6
+ private readonly keys;
7
+ private readonly primary;
8
+ private readonly secondary;
9
+ constructor(storage: StorageDriver, keys?: StorageKeyManager);
10
+ commit(transaction: Transaction): Promise<void>;
11
+ }
@@ -0,0 +1,9 @@
1
+ import type { StorageDriver } from "@duraxis/storage";
2
+ import { StorageKeyManager } from "../security/storage-key-manager.js";
3
+ export interface CommitRecord {
4
+ readonly format: 1;
5
+ readonly transactionId: string;
6
+ readonly previous: string | null;
7
+ }
8
+ export declare function encodeCommitRecord(record: CommitRecord): Uint8Array;
9
+ export declare function readCommitRecord(storage: StorageDriver, keys: StorageKeyManager, key: string): Promise<CommitRecord>;
@@ -0,0 +1,19 @@
1
+ import { StorageKeyManager } from "../security/storage-key-manager.js";
2
+ import { type CollectionDefinition } from "../catalog/collection-schema.js";
3
+ export declare const MANIFEST_KEY = "__duraxis/v1/manifest";
4
+ export declare const MAX_MANIFEST_BYTES: number;
5
+ export interface Manifest {
6
+ readonly format: 1;
7
+ readonly transactionId: string;
8
+ readonly commitHead: string | null;
9
+ readonly primaryRoot: string | null;
10
+ readonly indexRoots: ReadonlyMap<string, string | null>;
11
+ readonly catalog: ReadonlyMap<string, CollectionDefinition>;
12
+ }
13
+ export interface Snapshot {
14
+ readonly manifest: Manifest;
15
+ readonly storageVersion: string | null;
16
+ }
17
+ export declare function emptyManifest(): Manifest;
18
+ export declare function encodeManifest(manifest: Manifest, keys?: StorageKeyManager): Uint8Array;
19
+ export declare function decodeManifest(bytes: Uint8Array, keys?: StorageKeyManager): Manifest;
@@ -0,0 +1,85 @@
1
+ import type { StorageDriver } from "@duraxis/storage";
2
+ import { Transaction } from "../transactions/transaction.js";
3
+ import type { SnapshotReader } from "../snapshots/snapshot-reader.js";
4
+ import { type GarbageCollectionOptions, type GarbageCollectionReport } from "../gc/garbage-collector.js";
5
+ import { type QueryExecutorOptions, type QueryPage } from "../query/executor/query-executor.js";
6
+ import type { QueryOperator } from "../query/executor/operators/operators.js";
7
+ import type { LogicalQuery } from "../query/model/query.js";
8
+ import type { QueryRow } from "../query/executor/predicate.js";
9
+ import type { ExplainResult, PhysicalPlan } from "../query/planner/physical-plan.js";
10
+ import { type CollectionDefinition, type SecondaryIndexDefinition, type DocumentRecord, type IndexScalar } from "../catalog/collection-schema.js";
11
+ export interface DuraxisDatabaseOptions {
12
+ readonly storage: StorageDriver;
13
+ readonly namespace?: string;
14
+ readonly cursorSigningKey?: Uint8Array;
15
+ }
16
+ export interface CollectionRow {
17
+ readonly id: string;
18
+ readonly document: DocumentRecord;
19
+ }
20
+ export interface DuraxisMetrics {
21
+ readonly transactionsStarted: number;
22
+ readonly transactionsCommitted: number;
23
+ readonly transactionConflicts: number;
24
+ readonly commitOutcomesUnknown: number;
25
+ readonly commitDurationMs: number;
26
+ readonly queries: number;
27
+ readonly queryDurationMs: number;
28
+ readonly garbageCollections: number;
29
+ readonly garbageCollectionDurationMs: number;
30
+ readonly storage?: ReturnType<NonNullable<StorageDriver["getMetrics"]>>;
31
+ }
32
+ export declare class DuraxisDatabase {
33
+ private readonly storage;
34
+ private readonly keys;
35
+ private readonly coordinator;
36
+ private readonly recovery;
37
+ private readonly primary;
38
+ private readonly secondary;
39
+ private readonly cursorSigningKey;
40
+ private readonly planner;
41
+ private readonly planCompiler;
42
+ private readonly metrics;
43
+ private readonly active;
44
+ private maintenance;
45
+ private pendingSnapshotAcquisitions;
46
+ private closed;
47
+ constructor(options: DuraxisDatabaseOptions);
48
+ transaction<T>(callback: (tx: Transaction) => Promise<T> | T): Promise<T>;
49
+ snapshot<T>(callback: (reader: SnapshotReader) => Promise<T> | T): Promise<T>;
50
+ defineCollection(schema: CollectionDefinition): Promise<void>;
51
+ getCollectionDefinitions(): Promise<readonly CollectionDefinition[]>;
52
+ addIndex(collection: string, index: SecondaryIndexDefinition): Promise<void>;
53
+ removeIndex(collection: string, indexName: string): Promise<void>;
54
+ query(query: LogicalQuery, options?: QueryExecutorOptions): AsyncIterable<QueryRow>;
55
+ query(query: LogicalQuery, source: QueryOperator, options?: QueryExecutorOptions): AsyncIterable<QueryRow>;
56
+ queryPage(query: LogicalQuery, options?: QueryExecutorOptions): Promise<QueryPage>;
57
+ queryPage(query: LogicalQuery, source: QueryOperator, options?: QueryExecutorOptions): Promise<QueryPage>;
58
+ queryAll(query: LogicalQuery, options?: QueryExecutorOptions): Promise<readonly QueryRow[]>;
59
+ explain(query: LogicalQuery): Promise<ExplainResult>;
60
+ executePlan(query: LogicalQuery, plan: PhysicalPlan, options?: QueryExecutorOptions): AsyncIterable<QueryRow>;
61
+ getDocument(collection: string, id: string): Promise<DocumentRecord | null>;
62
+ findByIndex(collection: string, indexName: string, value: IndexScalar | readonly IndexScalar[], limit?: number): Promise<CollectionRow[]>;
63
+ scanCollection(collection: string, limit?: number): Promise<CollectionRow[]>;
64
+ getCommitStatus(transactionId: string): Promise<import("../recovery/recovery-manager.js").CommitStatus>;
65
+ verifyHistory(): Promise<number>;
66
+ /** Starts a new verifiable commit-history chain without changing data roots. */
67
+ checkpointHistory(): Promise<string>;
68
+ verifyIntegrity(): Promise<{
69
+ objects: number;
70
+ nodes: number;
71
+ indexes: number;
72
+ commits: number;
73
+ }>;
74
+ collectGarbage(storage: StorageDriver, options?: GarbageCollectionOptions): Promise<GarbageCollectionReport>;
75
+ private releaseSnapshot;
76
+ private queryOptions;
77
+ private bindSignal;
78
+ private isOperator;
79
+ private acquireSnapshot;
80
+ getMetrics(): DuraxisMetrics;
81
+ close(options?: {
82
+ readonly closeStorage?: boolean;
83
+ }): Promise<void>;
84
+ private createSnapshot;
85
+ }
@@ -0,0 +1,4 @@
1
+ export declare class CommitOutcomeUnknownError extends Error {
2
+ readonly transactionId: string;
3
+ constructor(transactionId: string, cause: unknown);
4
+ }
@@ -0,0 +1,4 @@
1
+ export declare class TransactionConflictError extends Error {
2
+ message: string;
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,3 @@
1
+ export declare class TransactionStateError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,31 @@
1
+ import type { StorageDriver } from "@duraxis/storage";
2
+ import { type Snapshot } from "../commit/manifest.js";
3
+ import { StorageKeyManager } from "../security/storage-key-manager.js";
4
+ import { type ReachabilityScanner } from "./reachability-scanner.js";
5
+ export interface GarbageCollectionOptions {
6
+ readonly dryRun?: boolean;
7
+ readonly exclusiveMaintenance?: boolean;
8
+ readonly olderThanMs?: number;
9
+ readonly batchSize?: number;
10
+ readonly signal?: AbortSignal;
11
+ readonly continueOnError?: boolean;
12
+ }
13
+ export interface GarbageCollectionReport {
14
+ readonly scanned: number;
15
+ readonly nodesScanned: number;
16
+ readonly reachable: number;
17
+ readonly candidates: number;
18
+ readonly deleted: number;
19
+ readonly failed: number;
20
+ readonly commitsScanned: number;
21
+ readonly durationMs: number;
22
+ readonly dryRun: boolean;
23
+ }
24
+ export declare class GarbageCollector {
25
+ private readonly storage;
26
+ private readonly keys;
27
+ private readonly activeSnapshots;
28
+ private readonly scanner;
29
+ constructor(storage: StorageDriver, keys: StorageKeyManager, activeSnapshots: () => readonly Snapshot[], scanner?: ReachabilityScanner);
30
+ collect(options?: GarbageCollectionOptions): Promise<GarbageCollectionReport>;
31
+ }
@@ -0,0 +1,13 @@
1
+ import type { StorageDriver } from "@duraxis/storage";
2
+ import type { Snapshot } from "../commit/manifest.js";
3
+ import { StorageKeyManager } from "../security/storage-key-manager.js";
4
+ export interface ReachabilityScanner {
5
+ scan(snapshot: Snapshot): Promise<ReadonlySet<string>>;
6
+ }
7
+ export declare class ManifestReachabilityScanner implements ReachabilityScanner {
8
+ private readonly keys;
9
+ private readonly nodes;
10
+ private readonly primary;
11
+ constructor(keys: StorageKeyManager, storage: StorageDriver);
12
+ scan(snapshot: Snapshot): Promise<ReadonlySet<string>>;
13
+ }