dirsql 0.4.37 → 0.4.39

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,18 @@
1
+ /**
2
+ * Keep Ctrl-C fatal while the CLI runs in-process.
3
+ *
4
+ * The core installs tokio signal handlers for `dirsql server`, and
5
+ * signal-hook (which tokio uses) *chains*: it runs its own actions and then
6
+ * the handler installed before it. CPython installs `default_int_handler` at
7
+ * startup, so the pip launcher gets a terminating disposition for free —
8
+ * bare Node leaves `SIG_DFL`, which signal-hook does not emulate, so the
9
+ * signal is swallowed and the process becomes SIGKILL-only (measured: a
10
+ * probe ignored SIGTERM for 143 seconds).
11
+ *
12
+ * Registering a JS listener first gives signal-hook a real prior handler to
13
+ * chain to. This cannot be fixed after the fact: `removeAllListeners` only
14
+ * drops JS listeners and cannot touch a disposition installed by native
15
+ * code, and `unregister_signal` leaves the OS handler in place. One listener
16
+ * is the whole remedy — no `unsafe`, no `sigaction`.
17
+ */
18
+ export declare function keepSignalsFatal(): void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Keep Ctrl-C fatal while the CLI runs in-process.
3
+ *
4
+ * The core installs tokio signal handlers for `dirsql server`, and
5
+ * signal-hook (which tokio uses) *chains*: it runs its own actions and then
6
+ * the handler installed before it. CPython installs `default_int_handler` at
7
+ * startup, so the pip launcher gets a terminating disposition for free —
8
+ * bare Node leaves `SIG_DFL`, which signal-hook does not emulate, so the
9
+ * signal is swallowed and the process becomes SIGKILL-only (measured: a
10
+ * probe ignored SIGTERM for 143 seconds).
11
+ *
12
+ * Registering a JS listener first gives signal-hook a real prior handler to
13
+ * chain to. This cannot be fixed after the fact: `removeAllListeners` only
14
+ * drops JS listeners and cannot touch a disposition installed by native
15
+ * code, and `unregister_signal` leaves the OS handler in place. One listener
16
+ * is the whole remedy — no `unsafe`, no `sigaction`.
17
+ */
18
+ export function keepSignalsFatal() {
19
+ // While the core is running, its own handler drives shutdown and this
20
+ // listener is the tail of the chain; it matters for signals arriving
21
+ // outside that window, where exiting is exactly right.
22
+ process.on("SIGINT", () => process.exit(130));
23
+ process.on("SIGTERM", () => process.exit(143));
24
+ }
package/dist/cli/main.js CHANGED
@@ -6,51 +6,10 @@
6
6
  // `@dirsql/lib-*` addon the SDK loads carries the CLI, so a package ships one
7
7
  // copy of the core instead of two (#739).
8
8
  import { mainInProcess } from "bin-shim";
9
- import { loadNativeCore } from "../load-native-core.js";
10
9
  import { die } from "./die.js";
10
+ import { keepSignalsFatal } from "./keep-signals-fatal.js";
11
11
  import { withResolvedExtensions } from "./resolve-config-extensions.js";
12
- /**
13
- * Resolve `runCli` off the same addon the SDK loads.
14
- *
15
- * bin-shim can resolve an addon itself, but its default naming is
16
- * `@{scope}/lib-{platform}-{arch}`, which cannot express the ABI suffix
17
- * dirsql's packages carry (`@dirsql/lib-linux-x64-gnu`). Reusing
18
- * `loadNativeCore` keeps one resolution rule for the SDK and the CLI —
19
- * including its dev fallback to a locally built `dirsql.node` — so a
20
- * monorepo checkout and a published install take the same path.
21
- */
22
- function resolveRunCli() {
23
- const core = loadNativeCore();
24
- if (typeof core.runCli !== "function") {
25
- throw new Error("dirsql: the native addon has no callable `runCli` export; " +
26
- "it was built without the `cli` feature.");
27
- }
28
- return core.runCli;
29
- }
30
- /**
31
- * Keep Ctrl-C fatal while the CLI runs in-process.
32
- *
33
- * The core installs tokio signal handlers for `dirsql server`, and
34
- * signal-hook (which tokio uses) *chains*: it runs its own actions and then
35
- * the handler installed before it. CPython installs `default_int_handler` at
36
- * startup, so the pip launcher gets a terminating disposition for free —
37
- * bare Node leaves `SIG_DFL`, which signal-hook does not emulate, so the
38
- * signal is swallowed and the process becomes SIGKILL-only (measured: a
39
- * probe ignored SIGTERM for 143 seconds).
40
- *
41
- * Registering a JS listener first gives signal-hook a real prior handler to
42
- * chain to. This cannot be fixed after the fact: `removeAllListeners` only
43
- * drops JS listeners and cannot touch a disposition installed by native
44
- * code, and `unregister_signal` leaves the OS handler in place. One listener
45
- * is the whole remedy — no `unsafe`, no `sigaction`.
46
- */
47
- function keepSignalsFatal() {
48
- // While the core is running, its own handler drives shutdown and this
49
- // listener is the tail of the chain; it matters for signals arriving
50
- // outside that window, where exiting is exactly right.
51
- process.on("SIGINT", () => process.exit(130));
52
- process.on("SIGTERM", () => process.exit(143));
53
- }
12
+ import { resolveRunCli } from "./resolve-run-cli.js";
54
13
  export async function main(argv = process.argv.slice(2)) {
55
14
  keepSignalsFatal();
56
15
  // Resolve any package-name extensions in a TOML config here (the core
@@ -0,0 +1,13 @@
1
+ /** The addon's CLI entry point, as napi exports it. */
2
+ export type RunCli = (argv: readonly string[]) => number;
3
+ /**
4
+ * Resolve `runCli` off the same addon the SDK loads.
5
+ *
6
+ * bin-shim can resolve an addon itself, but its default naming is
7
+ * `@{scope}/lib-{platform}-{arch}`, which cannot express the ABI suffix
8
+ * dirsql's packages carry (`@dirsql/lib-linux-x64-gnu`). Reusing
9
+ * `loadNativeCore` keeps one resolution rule for the SDK and the CLI —
10
+ * including its dev fallback to a locally built `dirsql.node` — so a
11
+ * monorepo checkout and a published install take the same path.
12
+ */
13
+ export declare function resolveRunCli(): RunCli;
@@ -0,0 +1,19 @@
1
+ import { loadNativeCore } from "../load-native-core.js";
2
+ /**
3
+ * Resolve `runCli` off the same addon the SDK loads.
4
+ *
5
+ * bin-shim can resolve an addon itself, but its default naming is
6
+ * `@{scope}/lib-{platform}-{arch}`, which cannot express the ABI suffix
7
+ * dirsql's packages carry (`@dirsql/lib-linux-x64-gnu`). Reusing
8
+ * `loadNativeCore` keeps one resolution rule for the SDK and the CLI —
9
+ * including its dev fallback to a locally built `dirsql.node` — so a
10
+ * monorepo checkout and a published install take the same path.
11
+ */
12
+ export function resolveRunCli() {
13
+ const core = loadNativeCore();
14
+ if (typeof core.runCli !== "function") {
15
+ throw new Error("dirsql: the native addon has no callable `runCli` export; " +
16
+ "it was built without the `cli` feature.");
17
+ }
18
+ return core.runCli;
19
+ }
@@ -0,0 +1,3 @@
1
+ import type { PackageResolver } from "./package-dir.js";
2
+ /** `require.resolve`-backed resolver used when a caller injects none. */
3
+ export declare function defaultResolver(): PackageResolver;
@@ -0,0 +1,9 @@
1
+ import { createRequire } from "node:module";
2
+ /** `require.resolve`-backed resolver used when a caller injects none. */
3
+ export function defaultResolver() {
4
+ const req = createRequire(import.meta.url);
5
+ return {
6
+ resolve: (s) => req.resolve(s),
7
+ paths: (s) => req.resolve.paths(s),
8
+ };
9
+ }
@@ -0,0 +1,3 @@
1
+ import type { Toml } from "./load-extension-entries.js";
2
+ /** True when some entry's `path` names an extension by bare package name. */
3
+ export declare function hasBareName(entries: Toml[]): boolean;
@@ -0,0 +1,5 @@
1
+ import { isBareName } from "./is-bare-name.js";
2
+ /** True when some entry's `path` names an extension by bare package name. */
3
+ export function hasBareName(entries) {
4
+ return entries.some((e) => typeof e.path === "string" && isBareName(e.path));
5
+ }
@@ -0,0 +1,2 @@
1
+ /** True when `path` is a bare package name rather than a file path. */
2
+ export declare function isBareName(path: string): boolean;
@@ -0,0 +1,10 @@
1
+ /** True when `path` is a bare package name rather than a file path. */
2
+ export function isBareName(path) {
3
+ // Suffixes that mark a value as "already a file path" (so package resolution is
4
+ // never attempted).
5
+ const loadableSuffixes = [".so", ".dylib", ".dll", ".node"];
6
+ if (path.includes("/") || path.includes("\\")) {
7
+ return false;
8
+ }
9
+ return !loadableSuffixes.some((s) => path.endsWith(s));
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { Platform } from "./platforms.js";
2
+ /**
3
+ * Suffix used in the napi `.node` filename for a given triple. Follows the
4
+ * `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
5
+ * `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
6
+ * on-disk artifact name and the npm package name can't drift.
7
+ */
8
+ export declare function librarySlug(p: Platform): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Suffix used in the napi `.node` filename for a given triple. Follows the
3
+ * `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
4
+ * `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
5
+ * on-disk artifact name and the npm package name can't drift.
6
+ */
7
+ export function librarySlug(p) {
8
+ const prefix = "@dirsql/lib-";
9
+ if (!p.libName.startsWith(prefix)) {
10
+ throw new Error(`libName ${p.libName} missing ${prefix} prefix`);
11
+ }
12
+ return p.libName.slice(prefix.length);
13
+ }
@@ -0,0 +1,2 @@
1
+ /** Loadable-file glob suffix(es) for the current platform. */
2
+ export declare function platformSuffixes(): string[];
@@ -0,0 +1,10 @@
1
+ /** Loadable-file glob suffix(es) for the current platform. */
2
+ export function platformSuffixes() {
3
+ if (process.platform === "darwin") {
4
+ return [".dylib", ".node"];
5
+ }
6
+ if (process.platform === "win32") {
7
+ return [".dll", ".node"];
8
+ }
9
+ return [".so", ".node"];
10
+ }
@@ -17,10 +17,3 @@ export interface Platform {
17
17
  export declare const PLATFORMS: readonly Platform[];
18
18
  /** Node `${platform}-${arch}` → `@dirsql/lib-*` napi sub-package name. */
19
19
  export declare function libTriples(): Record<string, string>;
20
- /**
21
- * Suffix used in the napi `.node` filename for a given triple. Follows the
22
- * `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
23
- * `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
24
- * on-disk artifact name and the npm package name can't drift.
25
- */
26
- export declare function librarySlug(p: Platform): string;
package/dist/platforms.js CHANGED
@@ -64,16 +64,3 @@ export function libTriples() {
64
64
  }
65
65
  return out;
66
66
  }
67
- /**
68
- * Suffix used in the napi `.node` filename for a given triple. Follows the
69
- * `@napi-rs/cli` convention: `dirsql.<platform>-<arch>[-<abi>].node`, e.g.
70
- * `dirsql.linux-x64-gnu.node`. Derived from the sub-package name so the
71
- * on-disk artifact name and the npm package name can't drift.
72
- */
73
- export function librarySlug(p) {
74
- const prefix = "@dirsql/lib-";
75
- if (!p.libName.startsWith(prefix)) {
76
- throw new Error(`libName ${p.libName} missing ${prefix} prefix`);
77
- }
78
- return p.libName.slice(prefix.length);
79
- }
@@ -0,0 +1,13 @@
1
+ import type { ExtensionSpec } from "./dirsql.js";
2
+ /**
3
+ * Resolve a TOML config's `[[dirsql.extension]]` entries to literal paths.
4
+ *
5
+ * Returns the resolved specs — every entry resolved via
6
+ * `resolveExtensionPath` against the config file's parent directory — when at
7
+ * least one entry's `path` is a bare package name. Returns `null` when the
8
+ * caller should not intervene: the config is missing, malformed, declares no
9
+ * extensions, or uses only literal paths — leaving the core's own loading
10
+ * (and error reporting) untouched. Throws if a package name cannot be
11
+ * resolved.
12
+ */
13
+ export declare function resolveConfigExtensionSpecs(configPath: string): ExtensionSpec[] | null;
@@ -0,0 +1,21 @@
1
+ import { hasBareName } from "./has-bare-name.js";
2
+ import { loadExtensionEntries } from "./load-extension-entries.js";
3
+ import { resolveEntries } from "./resolve-entries.js";
4
+ /**
5
+ * Resolve a TOML config's `[[dirsql.extension]]` entries to literal paths.
6
+ *
7
+ * Returns the resolved specs — every entry resolved via
8
+ * `resolveExtensionPath` against the config file's parent directory — when at
9
+ * least one entry's `path` is a bare package name. Returns `null` when the
10
+ * caller should not intervene: the config is missing, malformed, declares no
11
+ * extensions, or uses only literal paths — leaving the core's own loading
12
+ * (and error reporting) untouched. Throws if a package name cannot be
13
+ * resolved.
14
+ */
15
+ export function resolveConfigExtensionSpecs(configPath) {
16
+ const loaded = loadExtensionEntries(configPath);
17
+ if (loaded === null || !hasBareName(loaded.entries)) {
18
+ return null;
19
+ }
20
+ return resolveEntries(loaded.entries, loaded.base);
21
+ }
@@ -1,16 +1,4 @@
1
1
  import type { ExtensionSpec } from "./dirsql.js";
2
- /**
3
- * Resolve a TOML config's `[[dirsql.extension]]` entries to literal paths.
4
- *
5
- * Returns the resolved specs — every entry resolved via
6
- * `resolveExtensionPath` against the config file's parent directory — when at
7
- * least one entry's `path` is a bare package name. Returns `null` when the
8
- * caller should not intervene: the config is missing, malformed, declares no
9
- * extensions, or uses only literal paths — leaving the core's own loading
10
- * (and error reporting) untouched. Throws if a package name cannot be
11
- * resolved.
12
- */
13
- export declare function resolveConfigExtensionSpecs(configPath: string): ExtensionSpec[] | null;
14
2
  /**
15
3
  * Resolve the `[[dirsql.extension]]` entries of several configs, in order.
16
4
  *
@@ -7,35 +7,9 @@
7
7
  // own config-extension loading so the entries are not loaded twice.
8
8
  //
9
9
  // Shared by the `DirSQL` constructor (`config` option) and the CLI launcher.
10
+ import { hasBareName } from "./has-bare-name.js";
10
11
  import { loadExtensionEntries } from "./load-extension-entries.js";
11
- import { isBareName, resolveExtensionPath } from "./resolve-extension.js";
12
- function hasBareName(entries) {
13
- return entries.some((e) => typeof e.path === "string" && isBareName(e.path));
14
- }
15
- function resolveEntries(entries, base) {
16
- return entries.map((e) => ({
17
- path: resolveExtensionPath(e.path, base, true),
18
- entrypoint: typeof e.entrypoint === "string" ? e.entrypoint : undefined,
19
- }));
20
- }
21
- /**
22
- * Resolve a TOML config's `[[dirsql.extension]]` entries to literal paths.
23
- *
24
- * Returns the resolved specs — every entry resolved via
25
- * `resolveExtensionPath` against the config file's parent directory — when at
26
- * least one entry's `path` is a bare package name. Returns `null` when the
27
- * caller should not intervene: the config is missing, malformed, declares no
28
- * extensions, or uses only literal paths — leaving the core's own loading
29
- * (and error reporting) untouched. Throws if a package name cannot be
30
- * resolved.
31
- */
32
- export function resolveConfigExtensionSpecs(configPath) {
33
- const loaded = loadExtensionEntries(configPath);
34
- if (loaded === null || !hasBareName(loaded.entries)) {
35
- return null;
36
- }
37
- return resolveEntries(loaded.entries, loaded.base);
38
- }
12
+ import { resolveEntries } from "./resolve-entries.js";
39
13
  /**
40
14
  * Resolve the `[[dirsql.extension]]` entries of several configs, in order.
41
15
  *
@@ -0,0 +1,4 @@
1
+ import type { ExtensionSpec } from "./dirsql.js";
2
+ import type { Toml } from "./load-extension-entries.js";
3
+ /** Resolve a config's entries to specs, against that config's own directory. */
4
+ export declare function resolveEntries(entries: Toml[], base: string): ExtensionSpec[];
@@ -0,0 +1,8 @@
1
+ import { resolveExtensionPath } from "./resolve-extension.js";
2
+ /** Resolve a config's entries to specs, against that config's own directory. */
3
+ export function resolveEntries(entries, base) {
4
+ return entries.map((e) => ({
5
+ path: resolveExtensionPath(e.path, base, true),
6
+ entrypoint: typeof e.entrypoint === "string" ? e.entrypoint : undefined,
7
+ }));
8
+ }
@@ -1,6 +1,4 @@
1
1
  import type { PackageResolver } from "./package-dir.js";
2
- /** True when `path` is a bare package name rather than a file path. */
3
- export declare function isBareName(path: string): boolean;
4
2
  /**
5
3
  * Resolve an extension `path` to a concrete file. `base` is the directory a
6
4
  * relative path and the bare-name shadow probe resolve against (a config file's
@@ -12,26 +12,10 @@
12
12
  // matches and multiple matches are both hard errors -- disambiguate
13
13
  // with a literal path.
14
14
  import { existsSync, statSync } from "node:fs";
15
- import { createRequire } from "node:module";
16
15
  import { isAbsolute, resolve as resolvePath } from "node:path";
16
+ import { defaultResolver } from "./default-resolver.js";
17
+ import { isBareName } from "./is-bare-name.js";
17
18
  import { resolvePackage } from "./resolve-package.js";
18
- // Suffixes that mark a value as "already a file path" (so package resolution is
19
- // never attempted).
20
- const LOADABLE_SUFFIXES = [".so", ".dylib", ".dll", ".node"];
21
- function defaultResolver() {
22
- const req = createRequire(import.meta.url);
23
- return {
24
- resolve: (s) => req.resolve(s),
25
- paths: (s) => req.resolve.paths(s),
26
- };
27
- }
28
- /** True when `path` is a bare package name rather than a file path. */
29
- export function isBareName(path) {
30
- if (path.includes("/") || path.includes("\\")) {
31
- return false;
32
- }
33
- return !LOADABLE_SUFFIXES.some((s) => path.endsWith(s));
34
- }
35
19
  /**
36
20
  * Resolve an extension `path` to a concrete file. `base` is the directory a
37
21
  * relative path and the bare-name shadow probe resolve against (a config file's
@@ -2,16 +2,7 @@
2
2
  import { readdirSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { packageDir } from "./package-dir.js";
5
- /** Loadable-file glob suffix(es) for the current platform. */
6
- function platformSuffixes() {
7
- if (process.platform === "darwin") {
8
- return [".dylib", ".node"];
9
- }
10
- if (process.platform === "win32") {
11
- return [".dll", ".node"];
12
- }
13
- return [".so", ".node"];
14
- }
5
+ import { platformSuffixes } from "./platform-suffixes.js";
15
6
  /** Glob the platform loadable inside a bare name's package dir. */
16
7
  export function resolvePackage(name, resolver) {
17
8
  const dir = packageDir(name, resolver);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirsql",
3
- "version": "0.4.37",
3
+ "version": "0.4.39",
4
4
  "description": "Ephemeral SQL index over a local directory",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/thekevinscott/dirsql",
@@ -213,10 +213,10 @@
213
213
  ]
214
214
  },
215
215
  "optionalDependencies": {
216
- "@dirsql/lib-linux-x64-gnu": "0.4.37",
217
- "@dirsql/lib-linux-arm64-gnu": "0.4.37",
218
- "@dirsql/lib-darwin-x64": "0.4.37",
219
- "@dirsql/lib-darwin-arm64": "0.4.37",
220
- "@dirsql/lib-win32-x64-msvc": "0.4.37"
216
+ "@dirsql/lib-linux-x64-gnu": "0.4.39",
217
+ "@dirsql/lib-linux-arm64-gnu": "0.4.39",
218
+ "@dirsql/lib-darwin-x64": "0.4.39",
219
+ "@dirsql/lib-darwin-arm64": "0.4.39",
220
+ "@dirsql/lib-win32-x64-msvc": "0.4.39"
221
221
  }
222
222
  }