dirsql 0.2.2 → 0.2.4
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/README.md +16 -11
- package/dist/index.d.ts +65 -34
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -73
- package/dist/index.js.map +1 -1
- package/dist/loadNativeCore.d.ts +12 -0
- package/dist/loadNativeCore.d.ts.map +1 -0
- package/dist/loadNativeCore.js +26 -0
- package/dist/loadNativeCore.js.map +1 -0
- package/dist/loadNativeCore.test.d.ts +2 -0
- package/dist/loadNativeCore.test.d.ts.map +1 -0
- package/dist/loadNativeCore.test.js +48 -0
- package/dist/loadNativeCore.test.js.map +1 -0
- package/dist/platforms.d.ts +12 -1
- package/dist/platforms.d.ts.map +1 -1
- package/dist/platforms.js +39 -9
- package/dist/platforms.js.map +1 -1
- package/dist/platforms.test.js +28 -1
- package/dist/platforms.test.js.map +1 -1
- package/package.json +1 -2
- package/dirsql.node +0 -0
package/README.md
CHANGED
|
@@ -12,26 +12,31 @@ Also available as [`dirsql` on crates.io](https://crates.io/crates/dirsql) and [
|
|
|
12
12
|
pnpm add dirsql
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Prebuilt binaries ship for linux-x64, linux-arm64, darwin-x64, darwin-arm64, and win32-x64. npm / pnpm pick up the right one via `optionalDependencies` — no Rust toolchain required.
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { DirSQL } from "dirsql";
|
|
21
21
|
|
|
22
|
-
const db = new DirSQL(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
const db = new DirSQL({
|
|
23
|
+
root: "/path/to/directory",
|
|
24
|
+
tables: [
|
|
25
|
+
{
|
|
26
|
+
ddl: "CREATE TABLE users (name TEXT, age INTEGER)",
|
|
27
|
+
glob: "data/*.json",
|
|
28
|
+
extract: (_filePath, content) => JSON.parse(content),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const rows = await db.query("SELECT * FROM users WHERE age > 25");
|
|
31
34
|
console.log(rows);
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
## Building
|
|
37
|
+
## Building (from source)
|
|
38
|
+
|
|
39
|
+
Building from source requires a Rust toolchain.
|
|
35
40
|
|
|
36
41
|
```bash
|
|
37
42
|
pnpm install
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,29 @@ export interface TableDef {
|
|
|
9
9
|
/** If true, reject rows with columns not declared in `ddl`. */
|
|
10
10
|
strict?: boolean;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Options accepted by the {@link DirSQL} constructor.
|
|
14
|
+
*
|
|
15
|
+
* At least one of `root` or `config` must be supplied. When both are set,
|
|
16
|
+
* the explicit `root` wins over any `[dirsql].root` declared in the config
|
|
17
|
+
* file (a warning is emitted by the native layer).
|
|
18
|
+
*/
|
|
19
|
+
export interface DirSQLOptions {
|
|
20
|
+
/** Root directory to scan. */
|
|
21
|
+
root?: string;
|
|
22
|
+
/** Programmatic table definitions. Each table's `extract` runs in-process. */
|
|
23
|
+
tables?: TableDef[];
|
|
24
|
+
/** Glob patterns (relative to `root`) to ignore. */
|
|
25
|
+
ignore?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Path to a `.dirsql.toml` config file. Its `[[table]]` entries are
|
|
28
|
+
* appended to any programmatic `tables`; its `[dirsql].ignore` patterns
|
|
29
|
+
* are appended to any explicit `ignore`. If the config declares a
|
|
30
|
+
* `[dirsql].root` and no explicit `root` is given, it is resolved
|
|
31
|
+
* relative to the config file's parent directory.
|
|
32
|
+
*/
|
|
33
|
+
config?: string;
|
|
34
|
+
}
|
|
12
35
|
/** A row-level event emitted by the file watcher. */
|
|
13
36
|
export interface RowEvent {
|
|
14
37
|
/**
|
|
@@ -29,8 +52,7 @@ interface NativeDirSQL {
|
|
|
29
52
|
pollEvents(timeoutMs: number): Promise<RowEvent[]>;
|
|
30
53
|
}
|
|
31
54
|
interface NativeDirSQLConstructor {
|
|
32
|
-
|
|
33
|
-
fromConfig(configPath: string): NativeDirSQL;
|
|
55
|
+
openAsync(root: string | null, tables: TableDef[] | null, ignore: string[] | null, config: string | null): Promise<NativeDirSQL>;
|
|
34
56
|
}
|
|
35
57
|
interface CoreModule {
|
|
36
58
|
DirSQL: NativeDirSQLConstructor;
|
|
@@ -47,61 +69,70 @@ export declare function __setCoreForTesting(fake: CoreModule | null): void;
|
|
|
47
69
|
/**
|
|
48
70
|
* Ephemeral SQL index over a local directory.
|
|
49
71
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
72
|
+
* The constructor is overloaded: pass a config-file path directly, or an
|
|
73
|
+
* options object with any combination of `root`, `tables`, `ignore`, and
|
|
74
|
+
* `config`.
|
|
75
|
+
*
|
|
76
|
+
* Constructing a `DirSQL` returns immediately; the directory scan, file
|
|
77
|
+
* reads, and initial row extraction run asynchronously. `db.ready`
|
|
78
|
+
* resolves once construction has completed, and every method (including
|
|
79
|
+
* {@link query}, {@link startWatcher}, {@link pollEvents}, and
|
|
80
|
+
* {@link watch}) transparently awaits `ready` before doing any work, so
|
|
81
|
+
* callers can start using the instance immediately:
|
|
56
82
|
*
|
|
57
83
|
* ```ts
|
|
58
|
-
*
|
|
59
|
-
*
|
|
84
|
+
* // From a config file:
|
|
85
|
+
* const db = new DirSQL("./my-config.toml");
|
|
86
|
+
*
|
|
87
|
+
* // Programmatic:
|
|
88
|
+
* const db2 = new DirSQL({ root: "./data", tables: [...] });
|
|
89
|
+
*
|
|
90
|
+
* await db.ready; // optional: wait for the initial scan explicitly
|
|
60
91
|
* const rows = await db.query("SELECT ...");
|
|
61
92
|
* for await (const event of db.watch()) { ... }
|
|
62
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* The scan runs on the libuv threadpool, so constructing a `DirSQL` does
|
|
96
|
+
* not block the JS event loop even for large directories.
|
|
63
97
|
*/
|
|
64
98
|
export declare class DirSQL {
|
|
65
99
|
/**
|
|
66
|
-
* Resolves once the initial directory scan
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* uniformly across SDKs.
|
|
100
|
+
* Resolves once the initial directory scan + row extraction have
|
|
101
|
+
* completed, or rejects if construction failed. Every other method on
|
|
102
|
+
* this class implicitly awaits `ready`, so awaiting it explicitly is
|
|
103
|
+
* only necessary when a caller needs to observe construction errors
|
|
104
|
+
* synchronously (without issuing a query first).
|
|
72
105
|
*/
|
|
73
106
|
readonly ready: Promise<void>;
|
|
74
107
|
private _inner;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* The root directory is derived from the config file's parent. Tables
|
|
80
|
-
* are parsed using the built-in parser for each format declared in the
|
|
81
|
-
* config. No JS `extract` callback is required.
|
|
82
|
-
*/
|
|
83
|
-
static fromConfig(configPath: string): DirSQL;
|
|
108
|
+
/** Construct from a `.dirsql.toml` config-file path. */
|
|
109
|
+
constructor(configPath: string);
|
|
110
|
+
/** Construct from structured options. */
|
|
111
|
+
constructor(options: DirSQLOptions);
|
|
84
112
|
/**
|
|
85
113
|
* Execute a SQL query and return results as an array of row objects.
|
|
86
114
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
115
|
+
* Awaits the initial scan if it has not yet finished, then runs the
|
|
116
|
+
* query on the libuv threadpool, so the JS event loop stays responsive
|
|
117
|
+
* even for large result sets or long-running queries.
|
|
89
118
|
*/
|
|
90
119
|
query(sql: string): Promise<Record<string, unknown>[]>;
|
|
91
120
|
/**
|
|
92
121
|
* Start the file watcher. Must be called before {@link pollEvents}.
|
|
93
122
|
* Idempotent — safe to call multiple times.
|
|
94
123
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
124
|
+
* Awaits the initial scan if it has not yet finished, then runs on the
|
|
125
|
+
* libuv threadpool so the JS event loop stays responsive while the
|
|
126
|
+
* watcher is being initialized.
|
|
97
127
|
*/
|
|
98
128
|
startWatcher(): Promise<void>;
|
|
99
129
|
/**
|
|
100
130
|
* Poll for file change events, blocking up to `timeoutMs` for the first
|
|
101
131
|
* event. Returns all events observed in the window (possibly empty).
|
|
102
132
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
133
|
+
* Awaits the initial scan if it has not yet finished, then runs on the
|
|
134
|
+
* libuv threadpool so the JS event loop stays responsive for the
|
|
135
|
+
* duration of the poll timeout.
|
|
105
136
|
*/
|
|
106
137
|
pollEvents(timeoutMs: number): Promise<RowEvent[]>;
|
|
107
138
|
/**
|
|
@@ -111,9 +142,9 @@ export declare class DirSQL {
|
|
|
111
142
|
* for await (const event of db.watch()) { ... }
|
|
112
143
|
* ```
|
|
113
144
|
*
|
|
114
|
-
*
|
|
115
|
-
* bounded native poll each cycle. The iterator
|
|
116
|
-
* out of the `for await` loop to stop.
|
|
145
|
+
* Awaits the initial scan on first iteration, starts the underlying
|
|
146
|
+
* watcher, then awaits a bounded native poll each cycle. The iterator
|
|
147
|
+
* runs indefinitely; break out of the `for await` loop to stop.
|
|
117
148
|
*/
|
|
118
149
|
watch(): AsyncGenerator<RowEvent, void, unknown>;
|
|
119
150
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAcA,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,OAAO,EAAE,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MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC1B;AAID,UAAU,UAAU;IAClB,MAAM,EAAE,uBAAuB,CAAC;CACjC;AAaD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,MAAM;IACjB;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAG9B,OAAO,CAAC,MAAM,CAAgB;IAE9B,wDAAwD;gBAC5C,UAAU,EAAE,MAAM;IAC9B,yCAAyC;gBAC7B,OAAO,EAAE,aAAa;IAgBlC;;;;;;OAMG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAK5D;;;;;;;OAOG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC;;;;;;;OAOG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAKxD;;;;;;;;;;OAUG;IACI,KAAK,IAAI,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC;CAaxD"}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
// dirsql TypeScript SDK.
|
|
2
2
|
//
|
|
3
|
-
// The public surface is implemented in Rust via napi-rs.
|
|
4
|
-
// `napi build` which
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// fields.
|
|
3
|
+
// The public surface is implemented in Rust via napi-rs. In development
|
|
4
|
+
// `pnpm build` runs `napi build` which drops `dirsql.node` at the
|
|
5
|
+
// package root; the loader in `loadNativeCore.ts` falls back to that
|
|
6
|
+
// file so running from source works.
|
|
8
7
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// Lazy-loaded reference to the core module. Populated on first access
|
|
17
|
-
// by `loadNativeCore()`, or by `__setCoreForTesting()` for tests.
|
|
8
|
+
// In a published install the napi binary ships inside a per-platform
|
|
9
|
+
// `@dirsql/lib-<slug>` sub-package (wired via `optionalDependencies`),
|
|
10
|
+
// and the loader resolves the one matching the host's OS/arch. No Rust
|
|
11
|
+
// toolchain is required at install time on any supported platform.
|
|
12
|
+
import { loadNativeCore as defaultLoadNativeCore } from "./loadNativeCore.js";
|
|
13
|
+
// Lazy-loaded reference to the core module. Populated on first access by
|
|
14
|
+
// `defaultLoadNativeCore()`, or by `__setCoreForTesting()` for tests.
|
|
18
15
|
let core = null;
|
|
19
|
-
/**
|
|
20
|
-
* Load the native napi-rs binary. Resolved relative to this compiled
|
|
21
|
-
* module: after `tsc` emits to `dist/`, the module's directory is
|
|
22
|
-
* `<pkg>/dist`, so `..` reaches the package root where napi-rs writes
|
|
23
|
-
* `dirsql.node`. The binary itself is a CommonJS addon, so we use
|
|
24
|
-
* `createRequire` to load it from inside an ESM module.
|
|
25
|
-
*/
|
|
26
|
-
function loadNativeCore() {
|
|
27
|
-
const bindingPath = join(import.meta.dirname, "..", "dirsql.node");
|
|
28
|
-
const requireFromHere = createRequire(import.meta.url);
|
|
29
|
-
return requireFromHere(bindingPath);
|
|
30
|
-
}
|
|
31
16
|
function getCore() {
|
|
32
17
|
if (core === null) {
|
|
33
|
-
core =
|
|
18
|
+
core = defaultLoadNativeCore();
|
|
34
19
|
}
|
|
35
20
|
return core;
|
|
36
21
|
}
|
|
@@ -48,80 +33,84 @@ export function __setCoreForTesting(fake) {
|
|
|
48
33
|
/**
|
|
49
34
|
* Ephemeral SQL index over a local directory.
|
|
50
35
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
36
|
+
* The constructor is overloaded: pass a config-file path directly, or an
|
|
37
|
+
* options object with any combination of `root`, `tables`, `ignore`, and
|
|
38
|
+
* `config`.
|
|
39
|
+
*
|
|
40
|
+
* Constructing a `DirSQL` returns immediately; the directory scan, file
|
|
41
|
+
* reads, and initial row extraction run asynchronously. `db.ready`
|
|
42
|
+
* resolves once construction has completed, and every method (including
|
|
43
|
+
* {@link query}, {@link startWatcher}, {@link pollEvents}, and
|
|
44
|
+
* {@link watch}) transparently awaits `ready` before doing any work, so
|
|
45
|
+
* callers can start using the instance immediately:
|
|
57
46
|
*
|
|
58
47
|
* ```ts
|
|
59
|
-
*
|
|
60
|
-
*
|
|
48
|
+
* // From a config file:
|
|
49
|
+
* const db = new DirSQL("./my-config.toml");
|
|
50
|
+
*
|
|
51
|
+
* // Programmatic:
|
|
52
|
+
* const db2 = new DirSQL({ root: "./data", tables: [...] });
|
|
53
|
+
*
|
|
54
|
+
* await db.ready; // optional: wait for the initial scan explicitly
|
|
61
55
|
* const rows = await db.query("SELECT ...");
|
|
62
56
|
* for await (const event of db.watch()) { ... }
|
|
63
57
|
* ```
|
|
58
|
+
*
|
|
59
|
+
* The scan runs on the libuv threadpool, so constructing a `DirSQL` does
|
|
60
|
+
* not block the JS event loop even for large directories.
|
|
64
61
|
*/
|
|
65
62
|
export class DirSQL {
|
|
66
63
|
/**
|
|
67
|
-
* Resolves once the initial directory scan
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* uniformly across SDKs.
|
|
64
|
+
* Resolves once the initial directory scan + row extraction have
|
|
65
|
+
* completed, or rejects if construction failed. Every other method on
|
|
66
|
+
* this class implicitly awaits `ready`, so awaiting it explicitly is
|
|
67
|
+
* only necessary when a caller needs to observe construction errors
|
|
68
|
+
* synchronously (without issuing a query first).
|
|
73
69
|
*/
|
|
74
70
|
ready;
|
|
71
|
+
// Initialized by `ready`. Do NOT touch before awaiting `ready`.
|
|
75
72
|
_inner;
|
|
76
|
-
constructor(
|
|
73
|
+
constructor(arg) {
|
|
74
|
+
const options = typeof arg === "string" ? { config: arg } : arg;
|
|
77
75
|
const Ctor = getCore().DirSQL;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.ready = Promise.resolve();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Load a {@link DirSQL} instance from a `.dirsql.toml` config file.
|
|
86
|
-
*
|
|
87
|
-
* The root directory is derived from the config file's parent. Tables
|
|
88
|
-
* are parsed using the built-in parser for each format declared in the
|
|
89
|
-
* config. No JS `extract` callback is required.
|
|
90
|
-
*/
|
|
91
|
-
static fromConfig(configPath) {
|
|
92
|
-
const instance = Object.create(DirSQL.prototype);
|
|
93
|
-
const writable = instance;
|
|
94
|
-
writable._inner = getCore().DirSQL.fromConfig(configPath);
|
|
95
|
-
writable.ready = Promise.resolve();
|
|
96
|
-
return instance;
|
|
76
|
+
const openPromise = Ctor.openAsync(options.root ?? null, options.tables ?? null, options.ignore ?? null, options.config ?? null);
|
|
77
|
+
this.ready = openPromise.then((inner) => {
|
|
78
|
+
this._inner = inner;
|
|
79
|
+
});
|
|
97
80
|
}
|
|
98
81
|
/**
|
|
99
82
|
* Execute a SQL query and return results as an array of row objects.
|
|
100
83
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
84
|
+
* Awaits the initial scan if it has not yet finished, then runs the
|
|
85
|
+
* query on the libuv threadpool, so the JS event loop stays responsive
|
|
86
|
+
* even for large result sets or long-running queries.
|
|
103
87
|
*/
|
|
104
|
-
query(sql) {
|
|
88
|
+
async query(sql) {
|
|
89
|
+
await this.ready;
|
|
105
90
|
return this._inner.query(sql);
|
|
106
91
|
}
|
|
107
92
|
/**
|
|
108
93
|
* Start the file watcher. Must be called before {@link pollEvents}.
|
|
109
94
|
* Idempotent — safe to call multiple times.
|
|
110
95
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
96
|
+
* Awaits the initial scan if it has not yet finished, then runs on the
|
|
97
|
+
* libuv threadpool so the JS event loop stays responsive while the
|
|
98
|
+
* watcher is being initialized.
|
|
113
99
|
*/
|
|
114
|
-
startWatcher() {
|
|
100
|
+
async startWatcher() {
|
|
101
|
+
await this.ready;
|
|
115
102
|
return this._inner.startWatcher();
|
|
116
103
|
}
|
|
117
104
|
/**
|
|
118
105
|
* Poll for file change events, blocking up to `timeoutMs` for the first
|
|
119
106
|
* event. Returns all events observed in the window (possibly empty).
|
|
120
107
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
108
|
+
* Awaits the initial scan if it has not yet finished, then runs on the
|
|
109
|
+
* libuv threadpool so the JS event loop stays responsive for the
|
|
110
|
+
* duration of the poll timeout.
|
|
123
111
|
*/
|
|
124
|
-
pollEvents(timeoutMs) {
|
|
112
|
+
async pollEvents(timeoutMs) {
|
|
113
|
+
await this.ready;
|
|
125
114
|
return this._inner.pollEvents(timeoutMs);
|
|
126
115
|
}
|
|
127
116
|
/**
|
|
@@ -131,11 +120,12 @@ export class DirSQL {
|
|
|
131
120
|
* for await (const event of db.watch()) { ... }
|
|
132
121
|
* ```
|
|
133
122
|
*
|
|
134
|
-
*
|
|
135
|
-
* bounded native poll each cycle. The iterator
|
|
136
|
-
* out of the `for await` loop to stop.
|
|
123
|
+
* Awaits the initial scan on first iteration, starts the underlying
|
|
124
|
+
* watcher, then awaits a bounded native poll each cycle. The iterator
|
|
125
|
+
* runs indefinitely; break out of the `for await` loop to stop.
|
|
137
126
|
*/
|
|
138
127
|
async *watch() {
|
|
128
|
+
await this.ready;
|
|
139
129
|
await this._inner.startWatcher();
|
|
140
130
|
while (true) {
|
|
141
131
|
// Native `pollEvents` now runs on the libuv threadpool and returns a
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"m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AC,KAAK,EAAE,EAAE;YACtC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,GAAW;QACrB,MAAM,IAAI,CAAC,KAAK,CAAC;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,KAAK,CAAC;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,MAAM,IAAI,CAAC,KAAK,CAAC;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,CAAC,KAAK;QACV,MAAM,IAAI,CAAC,KAAK,CAAC;QACjB,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,IAAI,EAAE,CAAC;YACZ,qEAAqE;YACrE,gEAAgE;YAChE,sEAAsE;YACtE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACjD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CoreModule {
|
|
2
|
+
DirSQL: unknown;
|
|
3
|
+
}
|
|
4
|
+
/** `createRequire`-shaped loader. Injectable for tests. */
|
|
5
|
+
export type Requirer = (specifier: string) => unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Return path of this module's directory. Split out so tests can pin the
|
|
8
|
+
* dev-fallback location without mocking `import.meta`.
|
|
9
|
+
*/
|
|
10
|
+
export type DirnameFn = () => string;
|
|
11
|
+
export declare function loadNativeCore(key?: string, requirer?: Requirer, dirnameFn?: DirnameFn): CoreModule;
|
|
12
|
+
//# sourceMappingURL=loadNativeCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadNativeCore.d.ts","sourceRoot":"","sources":["../ts/loadNativeCore.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC;AAErC,wBAAgB,cAAc,CAC5B,GAAG,SAAwC,EAC3C,QAAQ,GAAE,QAAyC,EACnD,SAAS,GAAE,SAAqC,GAC/C,UAAU,CAeZ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Loads the napi-rs native addon. Consumers installing `dirsql` from npm
|
|
2
|
+
// pick up a single `@dirsql/lib-<slug>` sub-package via the main package's
|
|
3
|
+
// `optionalDependencies`; this loader resolves that package at runtime.
|
|
4
|
+
//
|
|
5
|
+
// During development (this monorepo, or any local `napi build`) the sub-
|
|
6
|
+
// package isn't published yet and `dirsql.node` sits at the package root.
|
|
7
|
+
// We fall back to that path so `pnpm test` works from source.
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { libTriples } from "./platforms.js";
|
|
11
|
+
export function loadNativeCore(key = `${process.platform}-${process.arch}`, requirer = createRequire(import.meta.url), dirnameFn = () => import.meta.dirname) {
|
|
12
|
+
const libs = libTriples();
|
|
13
|
+
const pkg = libs[key];
|
|
14
|
+
if (pkg) {
|
|
15
|
+
try {
|
|
16
|
+
return requirer(pkg);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Sub-package not installed (dev checkout, or `npm install
|
|
20
|
+
// --no-optional`). Fall through to the dev path.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const bindingPath = join(dirnameFn(), "..", "dirsql.node");
|
|
24
|
+
return requirer(bindingPath);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=loadNativeCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadNativeCore.js","sourceRoot":"","sources":["../ts/loadNativeCore.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,8DAA8D;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAe5C,MAAM,UAAU,cAAc,CAC5B,GAAG,GAAG,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,EAC3C,WAAqB,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EACnD,YAAuB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO;IAEhD,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAEtB,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,CAAC;YACH,OAAO,QAAQ,CAAC,GAAG,CAAe,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;YAC3D,iDAAiD;QACnD,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,WAAW,CAAe,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadNativeCore.test.d.ts","sourceRoot":"","sources":["../ts/loadNativeCore.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { loadNativeCore } from "./loadNativeCore.js";
|
|
3
|
+
describe("loadNativeCore", () => {
|
|
4
|
+
describe("when the platform sub-package is installed", () => {
|
|
5
|
+
it("loads via the `@dirsql/lib-<slug>` require and never hits the dev fallback", () => {
|
|
6
|
+
const fakeCore = { DirSQL: vi.fn() };
|
|
7
|
+
const requirer = vi.fn((spec) => {
|
|
8
|
+
if (spec === "@dirsql/lib-linux-x64-gnu")
|
|
9
|
+
return fakeCore;
|
|
10
|
+
throw new Error(`unexpected require(${spec})`);
|
|
11
|
+
});
|
|
12
|
+
const core = loadNativeCore("linux-x64", requirer, () => "/fake");
|
|
13
|
+
expect(core).toBe(fakeCore);
|
|
14
|
+
expect(requirer).toHaveBeenCalledExactlyOnceWith("@dirsql/lib-linux-x64-gnu");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe("when the platform sub-package is missing", () => {
|
|
18
|
+
it("falls back to `<pkgRoot>/dirsql.node`", () => {
|
|
19
|
+
const fakeCore = { DirSQL: vi.fn() };
|
|
20
|
+
const requirer = vi.fn((spec) => {
|
|
21
|
+
if (spec === "@dirsql/lib-darwin-arm64") {
|
|
22
|
+
throw new Error("Cannot find module '@dirsql/lib-darwin-arm64'");
|
|
23
|
+
}
|
|
24
|
+
if (spec.endsWith("dirsql.node"))
|
|
25
|
+
return fakeCore;
|
|
26
|
+
throw new Error(`unexpected require(${spec})`);
|
|
27
|
+
});
|
|
28
|
+
const core = loadNativeCore("darwin-arm64", requirer, () => "/pkg/ts");
|
|
29
|
+
expect(core).toBe(fakeCore);
|
|
30
|
+
expect(requirer).toHaveBeenCalledTimes(2);
|
|
31
|
+
expect(requirer).toHaveBeenLastCalledWith("/pkg/dirsql.node");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("on a platform with no corresponding sub-package", () => {
|
|
35
|
+
it("goes straight to the dev fallback without attempting a sub-package load", () => {
|
|
36
|
+
const fakeCore = { DirSQL: vi.fn() };
|
|
37
|
+
const requirer = vi.fn((spec) => {
|
|
38
|
+
if (spec.endsWith("dirsql.node"))
|
|
39
|
+
return fakeCore;
|
|
40
|
+
throw new Error(`unexpected require(${spec})`);
|
|
41
|
+
});
|
|
42
|
+
const core = loadNativeCore("freebsd-x64", requirer, () => "/pkg/ts");
|
|
43
|
+
expect(core).toBe(fakeCore);
|
|
44
|
+
expect(requirer).toHaveBeenCalledExactlyOnceWith("/pkg/dirsql.node");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=loadNativeCore.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadNativeCore.test.js","sourceRoot":"","sources":["../ts/loadNativeCore.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;QAC1D,EAAE,CAAC,4EAA4E,EAAE,GAAG,EAAE;YACpF,MAAM,QAAQ,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE;gBACtC,IAAI,IAAI,KAAK,2BAA2B;oBAAE,OAAO,QAAQ,CAAC;gBAC1D,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,GAAG,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,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E,GAAG,EAAE;YACjF,MAAM,QAAQ,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE;gBACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;oBAAE,OAAO,QAAQ,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,GAAG,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,cAAc,CACzB,aAAa,EACb,QAA6C,EAC7C,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,MAAM,CAAC,QAAQ,CAAC,CAAC,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/platforms.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ export interface Platform {
|
|
|
5
5
|
nodePlatform: NodeJS.Platform;
|
|
6
6
|
/** Node `process.arch` value for this target. */
|
|
7
7
|
nodeArch: NodeJS.Architecture;
|
|
8
|
-
/**
|
|
8
|
+
/** CLI sub-package name (`@dirsql/cli-<slug>`). */
|
|
9
9
|
name: string;
|
|
10
|
+
/** napi library sub-package name (`@dirsql/lib-<slug>`). */
|
|
11
|
+
libName: string;
|
|
10
12
|
/** Wheel-style `os` constraint for the sub-package's package.json. */
|
|
11
13
|
os: string[];
|
|
12
14
|
/** Wheel-style `cpu` constraint for the sub-package's package.json. */
|
|
@@ -21,4 +23,13 @@ export interface Platform {
|
|
|
21
23
|
export declare const PLATFORMS: readonly Platform[];
|
|
22
24
|
/** Node `${platform}-${arch}` → `@dirsql/cli-*` sub-package name. */
|
|
23
25
|
export declare function nodeTriples(): Record<string, string>;
|
|
26
|
+
/** Node `${platform}-${arch}` → `@dirsql/lib-*` napi sub-package name. */
|
|
27
|
+
export declare function libTriples(): Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Suffix used in the napi `.node` filename for a given triple. Follows the
|
|
30
|
+
* `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
|
|
31
|
+
* `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
|
|
32
|
+
* on-disk artifact name and the npm package name can't drift.
|
|
33
|
+
*/
|
|
34
|
+
export declare function librarySlug(p: Platform): string;
|
|
24
35
|
//# sourceMappingURL=platforms.d.ts.map
|
package/dist/platforms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platforms.d.ts","sourceRoot":"","sources":["../ts/platforms.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platforms.d.ts","sourceRoot":"","sources":["../ts/platforms.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC9B,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC,YAAY,CAAC;IAC9B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,uEAAuE;IACvE,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,0DAA0D;IAC1D,GAAG,EAAE,QAAQ,GAAG,KAAK,CAAC;IACtB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,QAAQ,EAsDxC,CAAC;AAEF,qEAAqE;AACrE,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMpD;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAM/C"}
|
package/dist/platforms.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Single source of truth for the target platforms `dirsql` publishes.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// Every target triple generates two npm sub-packages:
|
|
4
4
|
//
|
|
5
|
-
// 1.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
5
|
+
// 1. `@dirsql/cli-<slug>` — holds the standalone `dirsql` CLI binary
|
|
6
|
+
// (from cargo-dist). Consumed at runtime by `ts/bin/resolveBinary.ts`
|
|
7
|
+
// when a user runs the `dirsql` CLI.
|
|
8
|
+
// 2. `@dirsql/lib-<slug>` — holds the napi-rs `.node` addon used by the
|
|
9
|
+
// TypeScript SDK. Consumed at runtime by `loadNativeCore()` in
|
|
10
|
+
// `ts/index.ts` when a user `import`s from `dirsql`.
|
|
11
|
+
//
|
|
12
|
+
// Both sub-package sets use `optionalDependencies` on the main `dirsql`
|
|
13
|
+
// package so npm/pnpm install only the one matching the host's OS/arch.
|
|
14
|
+
//
|
|
15
|
+
// `nodeTriples()` / `libTriples()` return `${process.platform}-${process.arch}`
|
|
16
|
+
// → sub-package-name maps for the respective layer.
|
|
13
17
|
export const PLATFORMS = [
|
|
14
18
|
{
|
|
15
19
|
triple: "x86_64-unknown-linux-gnu",
|
|
16
20
|
nodePlatform: "linux",
|
|
17
21
|
nodeArch: "x64",
|
|
18
22
|
name: "@dirsql/cli-linux-x64-gnu",
|
|
23
|
+
libName: "@dirsql/lib-linux-x64-gnu",
|
|
19
24
|
os: ["linux"],
|
|
20
25
|
cpu: ["x64"],
|
|
21
26
|
libc: ["glibc"],
|
|
@@ -26,6 +31,7 @@ export const PLATFORMS = [
|
|
|
26
31
|
nodePlatform: "linux",
|
|
27
32
|
nodeArch: "arm64",
|
|
28
33
|
name: "@dirsql/cli-linux-arm64-gnu",
|
|
34
|
+
libName: "@dirsql/lib-linux-arm64-gnu",
|
|
29
35
|
os: ["linux"],
|
|
30
36
|
cpu: ["arm64"],
|
|
31
37
|
libc: ["glibc"],
|
|
@@ -36,6 +42,7 @@ export const PLATFORMS = [
|
|
|
36
42
|
nodePlatform: "darwin",
|
|
37
43
|
nodeArch: "x64",
|
|
38
44
|
name: "@dirsql/cli-darwin-x64",
|
|
45
|
+
libName: "@dirsql/lib-darwin-x64",
|
|
39
46
|
os: ["darwin"],
|
|
40
47
|
cpu: ["x64"],
|
|
41
48
|
ext: "tar.xz",
|
|
@@ -45,6 +52,7 @@ export const PLATFORMS = [
|
|
|
45
52
|
nodePlatform: "darwin",
|
|
46
53
|
nodeArch: "arm64",
|
|
47
54
|
name: "@dirsql/cli-darwin-arm64",
|
|
55
|
+
libName: "@dirsql/lib-darwin-arm64",
|
|
48
56
|
os: ["darwin"],
|
|
49
57
|
cpu: ["arm64"],
|
|
50
58
|
ext: "tar.xz",
|
|
@@ -54,6 +62,7 @@ export const PLATFORMS = [
|
|
|
54
62
|
nodePlatform: "win32",
|
|
55
63
|
nodeArch: "x64",
|
|
56
64
|
name: "@dirsql/cli-win32-x64-msvc",
|
|
65
|
+
libName: "@dirsql/lib-win32-x64-msvc",
|
|
57
66
|
os: ["win32"],
|
|
58
67
|
cpu: ["x64"],
|
|
59
68
|
ext: "zip",
|
|
@@ -68,4 +77,25 @@ export function nodeTriples() {
|
|
|
68
77
|
}
|
|
69
78
|
return out;
|
|
70
79
|
}
|
|
80
|
+
/** Node `${platform}-${arch}` → `@dirsql/lib-*` napi sub-package name. */
|
|
81
|
+
export function libTriples() {
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const p of PLATFORMS) {
|
|
84
|
+
out[`${p.nodePlatform}-${p.nodeArch}`] = p.libName;
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Suffix used in the napi `.node` filename for a given triple. Follows the
|
|
90
|
+
* `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
|
|
91
|
+
* `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
|
|
92
|
+
* on-disk artifact name and the npm package name can't drift.
|
|
93
|
+
*/
|
|
94
|
+
export function librarySlug(p) {
|
|
95
|
+
const prefix = "@dirsql/lib-";
|
|
96
|
+
if (!p.libName.startsWith(prefix)) {
|
|
97
|
+
throw new Error(`libName ${p.libName} missing ${prefix} prefix`);
|
|
98
|
+
}
|
|
99
|
+
return p.libName.slice(prefix.length);
|
|
100
|
+
}
|
|
71
101
|
//# sourceMappingURL=platforms.js.map
|
package/dist/platforms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../ts/platforms.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"platforms.js","sourceRoot":"","sources":["../ts/platforms.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,sDAAsD;AACtD,EAAE;AACF,qEAAqE;AACrE,yEAAyE;AACzE,wCAAwC;AACxC,wEAAwE;AACxE,kEAAkE;AAClE,wDAAwD;AACxD,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,EAAE;AACF,gFAAgF;AAChF,oDAAoD;AAyBpD,MAAM,CAAC,MAAM,SAAS,GAAwB;IAC5C;QACE,MAAM,EAAE,0BAA0B;QAClC,YAAY,EAAE,OAAO;QACrB,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,2BAA2B;QACpC,EAAE,EAAE,CAAC,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E,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IAClD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,UAAU;IACxB,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IACrD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,MAAM,MAAM,GAAG,cAAc,CAAC;IAC9B,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,OAAO,YAAY,MAAM,SAAS,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/platforms.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { PLATFORMS } from "./platforms.js";
|
|
2
|
+
import { PLATFORMS, libTriples, nodeTriples } from "./platforms.js";
|
|
3
3
|
describe("PLATFORMS", () => {
|
|
4
4
|
describe("shape invariants", () => {
|
|
5
5
|
it("lists all five target triples", () => {
|
|
@@ -17,6 +17,15 @@ describe("PLATFORMS", () => {
|
|
|
17
17
|
expect(p.name).toMatch(/^@dirsql\/cli-/);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
+
it("uses the `@dirsql/lib-` npm scope for every napi sub-package", () => {
|
|
21
|
+
for (const p of PLATFORMS) {
|
|
22
|
+
expect(p.libName).toMatch(/^@dirsql\/lib-/);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
it("gives each platform a distinct libName", () => {
|
|
26
|
+
const libs = PLATFORMS.map((p) => p.libName);
|
|
27
|
+
expect(new Set(libs).size).toBe(libs.length);
|
|
28
|
+
});
|
|
20
29
|
it("pairs tar.xz with unix targets and zip with windows", () => {
|
|
21
30
|
for (const p of PLATFORMS) {
|
|
22
31
|
if (p.os.includes("win32")) {
|
|
@@ -44,5 +53,23 @@ describe("PLATFORMS", () => {
|
|
|
44
53
|
expect(new Set(names).size).toBe(names.length);
|
|
45
54
|
});
|
|
46
55
|
});
|
|
56
|
+
describe("nodeTriples()", () => {
|
|
57
|
+
it("maps every `${platform}-${arch}` key to its cli-* sub-package", () => {
|
|
58
|
+
const map = nodeTriples();
|
|
59
|
+
expect(Object.keys(map).length).toBe(PLATFORMS.length);
|
|
60
|
+
for (const p of PLATFORMS) {
|
|
61
|
+
expect(map[`${p.nodePlatform}-${p.nodeArch}`]).toBe(p.name);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("libTriples()", () => {
|
|
66
|
+
it("maps every `${platform}-${arch}` key to its lib-* sub-package", () => {
|
|
67
|
+
const map = libTriples();
|
|
68
|
+
expect(Object.keys(map).length).toBe(PLATFORMS.length);
|
|
69
|
+
for (const p of PLATFORMS) {
|
|
70
|
+
expect(map[`${p.nodePlatform}-${p.nodeArch}`]).toBe(p.libName);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
47
74
|
});
|
|
48
75
|
//# sourceMappingURL=platforms.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platforms.test.js","sourceRoot":"","sources":["../ts/platforms.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,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CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Ephemeral SQL index over a local directory",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/thekevinscott/dirsql",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist/",
|
|
21
|
-
"dirsql.node",
|
|
22
21
|
"README.md",
|
|
23
22
|
"LICENSE"
|
|
24
23
|
],
|
package/dirsql.node
DELETED
|
Binary file
|