@hardkas/query 0.2.2-alpha.1 → 0.3.0-alpha
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/dist/index.d.ts +17 -1
- package/dist/index.js +35 -4
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -323,7 +323,19 @@ interface QueryBackend {
|
|
|
323
323
|
/** Perform index integrity check. */
|
|
324
324
|
doctor(): Promise<any>;
|
|
325
325
|
/** Atomic wipe and rebuild. */
|
|
326
|
-
rebuild(
|
|
326
|
+
rebuild(options?: {
|
|
327
|
+
strict?: boolean;
|
|
328
|
+
}): Promise<any>;
|
|
329
|
+
/** Incremental index update. */
|
|
330
|
+
sync(options?: {
|
|
331
|
+
strict?: boolean;
|
|
332
|
+
}): Promise<any>;
|
|
333
|
+
/** Apply pending schema migrations. */
|
|
334
|
+
migrate(): Promise<{
|
|
335
|
+
applied: number;
|
|
336
|
+
}>;
|
|
337
|
+
/** Execute raw SQL (if supported). */
|
|
338
|
+
executeRawSql(sql: string): Promise<any[]>;
|
|
327
339
|
/** Find all transaction receipts (for replay analysis). */
|
|
328
340
|
findReceipts(filters?: {
|
|
329
341
|
status?: string;
|
|
@@ -340,6 +352,10 @@ interface QueryEngineOptions {
|
|
|
340
352
|
readonly artifactDir: string;
|
|
341
353
|
/** Primary data backend. If not provided, defaults to auto-discovery (SQLite > Filesystem). */
|
|
342
354
|
readonly backend?: QueryBackend;
|
|
355
|
+
/** Automatically synchronize the store before queries. Requires 'query-store' lock. */
|
|
356
|
+
readonly autoSync?: boolean;
|
|
357
|
+
/** Whether to wait for the lock if held. */
|
|
358
|
+
readonly waitLock?: boolean;
|
|
343
359
|
}
|
|
344
360
|
declare class QueryEngine {
|
|
345
361
|
private readonly adapters;
|
package/dist/index.js
CHANGED
|
@@ -100,7 +100,15 @@ var FilesystemQueryBackend = class {
|
|
|
100
100
|
async doctor() {
|
|
101
101
|
return { ok: true, backend: "filesystem" };
|
|
102
102
|
}
|
|
103
|
-
async rebuild() {
|
|
103
|
+
async rebuild(options) {
|
|
104
|
+
return {
|
|
105
|
+
schema: "hardkas.queryRebuild.v1",
|
|
106
|
+
ok: true,
|
|
107
|
+
artifacts: { scanned: 0, indexed: 0, duplicates: 0, corrupted: 0 },
|
|
108
|
+
events: { scanned: 0, indexed: 0, duplicates: 0, corrupted: 0 },
|
|
109
|
+
warnings: ["Filesystem backend does not support indexing"],
|
|
110
|
+
errors: []
|
|
111
|
+
};
|
|
104
112
|
}
|
|
105
113
|
async findReceipts(filters) {
|
|
106
114
|
return this.findArtifacts({ schema: "hardkas.txReceipt", ...filters });
|
|
@@ -112,6 +120,15 @@ var FilesystemQueryBackend = class {
|
|
|
112
120
|
}
|
|
113
121
|
return artifacts;
|
|
114
122
|
}
|
|
123
|
+
async sync(options) {
|
|
124
|
+
return this.rebuild(options);
|
|
125
|
+
}
|
|
126
|
+
async migrate() {
|
|
127
|
+
return { applied: 0 };
|
|
128
|
+
}
|
|
129
|
+
async executeRawSql(_sql) {
|
|
130
|
+
throw new Error("Raw SQL execution not supported by Filesystem backend. Use SQLite backend.");
|
|
131
|
+
}
|
|
115
132
|
async scanFiles(dir) {
|
|
116
133
|
const results = [];
|
|
117
134
|
try {
|
|
@@ -1906,6 +1923,7 @@ var TxQueryAdapter = class {
|
|
|
1906
1923
|
};
|
|
1907
1924
|
|
|
1908
1925
|
// src/engine.ts
|
|
1926
|
+
import { withLock } from "@hardkas/core";
|
|
1909
1927
|
import fs6 from "fs";
|
|
1910
1928
|
import path6 from "path";
|
|
1911
1929
|
var QueryEngine = class _QueryEngine {
|
|
@@ -1922,9 +1940,22 @@ var QueryEngine = class _QueryEngine {
|
|
|
1922
1940
|
try {
|
|
1923
1941
|
const { HardkasStore, SqliteQueryBackend, HardkasIndexer } = await import("@hardkas/query-store");
|
|
1924
1942
|
const store = new HardkasStore({ dbPath });
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1943
|
+
if (options.autoSync) {
|
|
1944
|
+
await withLock({
|
|
1945
|
+
rootDir: options.artifactDir,
|
|
1946
|
+
name: "query-store",
|
|
1947
|
+
command: "query-engine-auto-sync",
|
|
1948
|
+
wait: options.waitLock ?? false,
|
|
1949
|
+
timeoutMs: 5e3
|
|
1950
|
+
// Short timeout for auto-sync
|
|
1951
|
+
}, async () => {
|
|
1952
|
+
store.connect({ autoMigrate: true });
|
|
1953
|
+
const indexer = new HardkasIndexer(store.getDatabase());
|
|
1954
|
+
await indexer.sync();
|
|
1955
|
+
});
|
|
1956
|
+
} else {
|
|
1957
|
+
store.connect();
|
|
1958
|
+
}
|
|
1928
1959
|
backend = new SqliteQueryBackend(store);
|
|
1929
1960
|
} catch (e) {
|
|
1930
1961
|
backend = new FilesystemQueryBackend(options.artifactDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/query",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"picocolors": "^1.1.1",
|
|
17
|
-
"@hardkas/core": "0.
|
|
18
|
-
"@hardkas/query-store": "0.
|
|
19
|
-
"@hardkas/artifacts": "0.
|
|
17
|
+
"@hardkas/core": "0.3.0-alpha",
|
|
18
|
+
"@hardkas/query-store": "0.3.0-alpha",
|
|
19
|
+
"@hardkas/artifacts": "0.3.0-alpha"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"tsup": "^8.3.5",
|