@hakodb/client 0.5.13 → 0.5.15

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.
@@ -0,0 +1,31 @@
1
+ # Quick gate for branch protection (required check on main).
2
+ # Typecheck only (no build step in these packages).
3
+
4
+ name: ci-quick
5
+
6
+ on:
7
+ pull_request:
8
+ branches: [main]
9
+ push:
10
+ branches: [main]
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ check:
17
+ name: quick-check
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - uses: actions/setup-node@v4
23
+ with:
24
+ node-version: 22
25
+ cache: npm
26
+
27
+ - name: install
28
+ run: npm ci
29
+
30
+ - name: typecheck
31
+ run: npx tsc --noEmit -p tsconfig.json
package/README.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # hakojs
2
2
 
3
+ > Part of [**HakoDB**](https://github.com/hakodb/hakodb) — embedded Firestore-style document DB in Rust. The engine + C ABI live in `hakodb/hakodb`; this repo holds the JavaScript/TypeScript SDK.
4
+
3
5
  JavaScript/TypeScript SDK for HakoDB:
4
6
  high-level client (`client.ts`: `HakoClient`, `HakoConfig`) and native
5
7
  FFI bindings over koffi/Bun (`native.ts`). Tauri lives in `@hakodb/tauri`
6
- (sibling dir, renaming with repo creation).
8
+ (sibling repo [`hakodb/hakotaurits`](https://github.com/hakodb/hakotaurits)).
7
9
 
8
10
  ## Compatibility
9
11
 
10
12
  | hakojs | hako core |
11
13
  |---|---|
12
- | 0.5.12 | `cloud_sync` branch / `v0.8.21`+ release asset |
14
+ | 0.5.13 | `cloud_sync` branch / `v0.8.21`+ release asset |
13
15
 
14
16
  ## Setup — native library
15
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/client.ts CHANGED
@@ -600,6 +600,33 @@ export class HakoClient {
600
600
  return n;
601
601
  }
602
602
 
603
+ /** Relocate docs by id src -> dst. Returns {moved, missing}; refusals throw. */
604
+ async relocateDocs(src: string, dst: string, ids: string[]): Promise<{ moved: string[]; missing: string[] }> {
605
+ this.assertOpen();
606
+ const json = this.native.engineRelocateDocs(this.engine, src, dst, JSON.stringify(ids));
607
+ if (!json) throw new Error(`engineRelocateDocs failed: ${this.native.lastError()}`);
608
+ return JSON.parse(json);
609
+ }
610
+
611
+ /** Load a lazy collection's snapshot into the index now. */
612
+ async loadCollection(collection: string): Promise<void> {
613
+ this.assertOpen();
614
+ ensureOk(this.native.engineLoadCollection(this.engine, collection), this.native, 'engineLoadCollection');
615
+ }
616
+
617
+ /** Unload a lazy collection (frees RAM; snapshot stays). Refuses non-lazy. */
618
+ async unloadCollection(collection: string): Promise<void> {
619
+ this.assertOpen();
620
+ ensureOk(this.native.engineUnloadCollection(this.engine, collection), this.native, 'engineUnloadCollection');
621
+ }
622
+
623
+ /** Lazy collections currently out of the index. */
624
+ async unloadedCollections(): Promise<string[]> {
625
+ this.assertOpen();
626
+ const json = this.native.engineUnloadedCollections(this.engine);
627
+ return json ? JSON.parse(json) : [];
628
+ }
629
+
603
630
  nativeBindings(): NativeBindings { return this.native; }
604
631
  engineHandle(): unknown { return this.engine; }
605
632
 
package/src/native.ts CHANGED
@@ -65,6 +65,10 @@ export interface NativeBindings {
65
65
  engineReplicateKey(engine: Handle, collection: string, docId: string): number;
66
66
  engineReplicateCollection(engine: Handle, collection: string): number;
67
67
  engineVacuumCollection(engine: Handle, collection: string): number;
68
+ engineRelocateDocs(engine: Handle, src: string, dst: string, idsJson: string): string | null;
69
+ engineLoadCollection(engine: Handle, collection: string): number;
70
+ engineUnloadCollection(engine: Handle, collection: string): number;
71
+ engineUnloadedCollections(engine: Handle): string | null;
68
72
  enginePatch(engine: Handle, collection: string, docId: string, updates: Handle): number;
69
73
  engineInsertSubDoc(engine: Handle, col: string, id: string, subCol: string, subId: string, doc: Handle): number;
70
74
  engineGetByRef(engine: Handle, doc: Handle, fieldKey: string): Handle;
@@ -271,6 +275,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
271
275
  hk_engine_replicate_key: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
272
276
  hk_engine_replicate_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
273
277
  hk_engine_vacuum_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
278
+ hk_engine_relocate_docs: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
279
+ hk_engine_load_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
280
+ hk_engine_unload_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
281
+ hk_engine_unloaded_collections: { args: [FFIType.ptr], returns: FFIType.ptr },
274
282
  hk_engine_patch: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
275
283
  hk_engine_insert_subdoc: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
276
284
  hk_engine_get_by_ref: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
@@ -452,6 +460,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
452
460
  engineReplicateKey: (engine, collection, docId) => symbols.hk_engine_replicate_key(engine, toC(collection), toC(docId)),
453
461
  engineReplicateCollection: (engine, collection) => symbols.hk_engine_replicate_collection(engine, toC(collection)),
454
462
  engineVacuumCollection: (engine, collection) => symbols.hk_engine_vacuum_collection(engine, toC(collection)),
463
+ engineRelocateDocs: (engine, src, dst, idsJson) => ptrToStringAndFree(symbols.hk_engine_relocate_docs(engine, toC(src), toC(dst), toC(idsJson))),
464
+ engineLoadCollection: (engine, collection) => symbols.hk_engine_load_collection(engine, toC(collection)),
465
+ engineUnloadCollection: (engine, collection) => symbols.hk_engine_unload_collection(engine, toC(collection)),
466
+ engineUnloadedCollections: (engine) => ptrToStringAndFree(symbols.hk_engine_unloaded_collections(engine)),
455
467
  enginePatch: (engine, collection, docId, updates) => symbols.hk_engine_patch(engine, toC(collection), toC(docId), updates),
456
468
  engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => symbols.hk_engine_insert_subdoc(engine, toC(col), toC(id), toC(subCol), toC(subId), doc),
457
469
  engineGetByRef: (engine, doc, fieldKey) => symbols.hk_engine_get_by_ref(engine, doc, toC(fieldKey)),
@@ -661,6 +673,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
661
673
  hk_engine_replicate_key: lib.func('int hk_engine_replicate_key(HK_Engine* engine, const char* collection, const char* doc_id)'),
662
674
  hk_engine_replicate_collection: lib.func('int hk_engine_replicate_collection(HK_Engine* engine, const char* collection)'),
663
675
  hk_engine_vacuum_collection: lib.func('int hk_engine_vacuum_collection(HK_Engine* engine, const char* collection)'),
676
+ hk_engine_relocate_docs: lib.func('HeapStr hk_engine_relocate_docs(HK_Engine* engine, const char* src, const char* dst, const char* ids_json)'),
677
+ hk_engine_load_collection: lib.func('int hk_engine_load_collection(HK_Engine* engine, const char* collection)'),
678
+ hk_engine_unload_collection: lib.func('int hk_engine_unload_collection(HK_Engine* engine, const char* collection)'),
679
+ hk_engine_unloaded_collections: lib.func('HeapStr hk_engine_unloaded_collections(HK_Engine* engine)'),
664
680
  hk_engine_patch: lib.func('int hk_engine_patch(HK_Engine* engine, const char* collection, const char* doc_id, const HK_Doc* updates)'),
665
681
  hk_engine_insert_subdoc: lib.func('int hk_engine_insert_subdoc(HK_Engine* engine, const char* col, const char* id, const char* sub_col, const char* sub_id, const HK_Doc* doc)'),
666
682
  hk_engine_get_by_ref: lib.func('HK_Doc* hk_engine_get_by_ref(HK_Engine* engine, const HK_Doc* doc, const char* field_key)'),
@@ -845,6 +861,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
845
861
  engineReplicateKey: (engine, collection, docId) => fn.hk_engine_replicate_key(engine, collection, docId),
846
862
  engineReplicateCollection: (engine, collection) => fn.hk_engine_replicate_collection(engine, collection),
847
863
  engineVacuumCollection: (engine, collection) => fn.hk_engine_vacuum_collection(engine, collection),
864
+ engineRelocateDocs: (engine, src, dst, idsJson) => ptrToStringAndFree(fn.hk_engine_relocate_docs(engine, src, dst, idsJson)),
865
+ engineLoadCollection: (engine, collection) => fn.hk_engine_load_collection(engine, collection),
866
+ engineUnloadCollection: (engine, collection) => fn.hk_engine_unload_collection(engine, collection),
867
+ engineUnloadedCollections: (engine) => ptrToStringAndFree(fn.hk_engine_unloaded_collections(engine)),
848
868
  enginePatch: (engine, collection, docId, updates) => fn.hk_engine_patch(engine, collection, docId, updates),
849
869
  engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => fn.hk_engine_insert_subdoc(engine, col, id, subCol, subId, doc),
850
870
  engineGetByRef: (engine, doc, fieldKey) => fn.hk_engine_get_by_ref(engine, doc, fieldKey),
package/sync-native.ps1 CHANGED
@@ -1,30 +1,55 @@
1
- #Requires -Version 5.1
2
- <#
3
- .SYNOPSIS
4
- Populate native/ from a core checkout or a release tag asset.
5
- .EXAMPLE
6
- .\sync-native.ps1 -CoreDir C:\Dev\libs\firelite
7
- .\sync-native.ps1 -Tag v0.8.20
8
- #>
9
- param(
10
- [string]$CoreDir = "",
11
- [string]$Tag = ""
12
- )
13
-
14
- $ErrorActionPreference = "Stop"
15
- $Root = Split-Path -Parent $MyInvocation.MyCommand.Path
16
- $Native = Join-Path $Root "native"
17
- New-Item -ItemType Directory -Force $Native | Out-Null
18
-
19
- if ($CoreDir -ne "") {
20
- $dll = Join-Path $CoreDir "target\release\hakodb.dll"
21
- if (-not (Test-Path $dll)) { throw "no release DLL at $dll (cargo build --release first)" }
22
- Copy-Item $dll $Native -Force
23
- Write-Output "synced from checkout: $CoreDir"
24
- } elseif ($Tag -ne "") {
25
- $base = "https://github.com/hakodb/hakodb/releases/download/$Tag"
26
- Invoke-WebRequest -Uri "$base/hakodb-x86_64-pc-windows-msvc.dll" -OutFile (Join-Path $Native "hakodb.dll")
27
- Write-Output "synced from release asset: $Tag"
28
- } else {
29
- throw "pass -CoreDir or -Tag"
30
- }
1
+ #Requires -Version 5.1
2
+ <#
3
+ .SYNOPSIS
4
+ Populate native/ from a core checkout or a release tag asset (multi-platform).
5
+ .EXAMPLE
6
+ .\sync-native.ps1 -CoreDir C:\Dev\libs\hakodb
7
+ .\sync-native.ps1 -Tag v0.9.0
8
+ .\sync-native.ps1 -Tag v0.9.0 -Platform linux
9
+ #>
10
+ param(
11
+ [string]$CoreDir = "",
12
+ [string]$Tag = "",
13
+ [string]$Platform = "",
14
+ [string]$LibTag = "linux-glibc2.28-el8"
15
+ )
16
+
17
+ $ErrorActionPreference = "Stop"
18
+ $Root = Split-Path -Parent $MyInvocation.MyCommand.Path
19
+ $Native = Join-Path $Root "native"
20
+ New-Item -ItemType Directory -Force $Native | Out-Null
21
+
22
+ # No macOS prebuilts (no CI job yet): build from source via -CoreDir on a Mac.
23
+
24
+ if ($CoreDir -ne "") {
25
+ $dll = Join-Path $CoreDir "target\release\hakodb.dll"
26
+ $so = Join-Path $CoreDir "target\release\libhakodb.so"
27
+ $dylib = Join-Path $CoreDir "target\release\libhakodb.dylib"
28
+ $found = @($dll, $so, $dylib) | Where-Object { Test-Path $_ } | Select-Object -First 1
29
+ if (-not $found) { throw "no release library under $CoreDir\target\release (cargo build --release first)" }
30
+ Copy-Item $found $Native -Force
31
+ Write-Output "synced from checkout: $CoreDir"
32
+ } elseif ($Tag -ne "") {
33
+ if ($Platform -eq "") {
34
+ if ($IsWindows -or $env:OS -eq "Windows_NT") { $Platform = "win32" }
35
+ elseif ($IsLinux) { $Platform = "linux" }
36
+ elseif ($IsMacOS) { $Platform = "darwin" }
37
+ else { $Platform = "win32" }
38
+ }
39
+ $base = "https://github.com/hakodb/hakodb/releases/download/$Tag"
40
+ if ($Platform -eq "win32") {
41
+ Invoke-WebRequest -Uri "$base/hakodb-x86_64-pc-windows-msvc.dll" -OutFile (Join-Path $Native "hakodb.dll")
42
+ } elseif ($Platform -eq "linux") {
43
+ # el8 build runs on glibc >= 2.28 everywhere; override -LibTag for an exact distro.
44
+ Invoke-WebRequest -Uri "$base/libhakodb-x86_64-unknown-$LibTag.so" -OutFile (Join-Path $Native "libhakodb.so")
45
+ } elseif ($Platform -eq "android") {
46
+ Invoke-WebRequest -Uri "$base/libhakodb-aarch64-linux-android.so" -OutFile (Join-Path $Native "libhakodb.so")
47
+ } elseif ($Platform -eq "darwin") {
48
+ throw "no macOS prebuilt (no CI job yet) - build from source and use -CoreDir on a Mac"
49
+ } else {
50
+ throw "unknown -Platform '$Platform' (win32|linux|android|darwin)"
51
+ }
52
+ Write-Output "synced from release asset: $Tag ($Platform)"
53
+ } else {
54
+ throw "pass -CoreDir or -Tag"
55
+ }