dirsql 0.4.36 → 0.4.37

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,10 @@
1
+ export type Toml = Record<string, any>;
2
+ /** Load a config's `[[dirsql.extension]]` entries with its base directory.
3
+ *
4
+ * `null` when the config is missing, unreadable/malformed, or declares no
5
+ * extension array — the caller leaves such configs to the core.
6
+ */
7
+ export declare function loadExtensionEntries(configPath: string): {
8
+ entries: Toml[];
9
+ base: string;
10
+ } | null;
@@ -0,0 +1,27 @@
1
+ // Read a TOML config's `[[dirsql.extension]]` array off disk.
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { dirname, resolve as resolvePath } from "node:path";
4
+ import { parse as parseToml } from "smol-toml";
5
+ /** Load a config's `[[dirsql.extension]]` entries with its base directory.
6
+ *
7
+ * `null` when the config is missing, unreadable/malformed, or declares no
8
+ * extension array — the caller leaves such configs to the core.
9
+ */
10
+ export function loadExtensionEntries(configPath) {
11
+ if (!existsSync(configPath)) {
12
+ return null;
13
+ }
14
+ let doc;
15
+ try {
16
+ doc = parseToml(readFileSync(configPath, "utf8"));
17
+ }
18
+ catch {
19
+ // Leave a malformed config for the core to report.
20
+ return null;
21
+ }
22
+ const dirsql = (doc.dirsql ?? {});
23
+ if (!Array.isArray(dirsql.extension)) {
24
+ return null;
25
+ }
26
+ return { entries: dirsql.extension, base: dirname(resolvePath(configPath)) };
27
+ }
@@ -1,4 +1,15 @@
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
+ */
2
13
  export declare function resolveConfigExtensionSpecs(configPath: string): ExtensionSpec[] | null;
3
14
  /**
4
15
  * Resolve the `[[dirsql.extension]]` entries of several configs, in order.
@@ -7,10 +7,17 @@
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 { existsSync, readFileSync } from "node:fs";
11
- import { dirname, resolve as resolvePath } from "node:path";
12
- import { parse as parseToml } from "smol-toml";
10
+ import { loadExtensionEntries } from "./load-extension-entries.js";
13
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
+ }
14
21
  /**
15
22
  * Resolve a TOML config's `[[dirsql.extension]]` entries to literal paths.
16
23
  *
@@ -22,38 +29,6 @@ import { isBareName, resolveExtensionPath } from "./resolve-extension.js";
22
29
  * (and error reporting) untouched. Throws if a package name cannot be
23
30
  * resolved.
24
31
  */
25
- /** Load a config's `[[dirsql.extension]]` entries with its base directory.
26
- *
27
- * `null` when the config is missing, unreadable/malformed, or declares no
28
- * extension array — the caller leaves such configs to the core.
29
- */
30
- function loadExtensionEntries(configPath) {
31
- if (!existsSync(configPath)) {
32
- return null;
33
- }
34
- let doc;
35
- try {
36
- doc = parseToml(readFileSync(configPath, "utf8"));
37
- }
38
- catch {
39
- // Leave a malformed config for the core to report.
40
- return null;
41
- }
42
- const dirsql = (doc.dirsql ?? {});
43
- if (!Array.isArray(dirsql.extension)) {
44
- return null;
45
- }
46
- return { entries: dirsql.extension, base: dirname(resolvePath(configPath)) };
47
- }
48
- function hasBareName(entries) {
49
- return entries.some((e) => typeof e.path === "string" && isBareName(e.path));
50
- }
51
- function resolveEntries(entries, base) {
52
- return entries.map((e) => ({
53
- path: resolveExtensionPath(e.path, base, true),
54
- entrypoint: typeof e.entrypoint === "string" ? e.entrypoint : undefined,
55
- }));
56
- }
57
32
  export function resolveConfigExtensionSpecs(configPath) {
58
33
  const loaded = loadExtensionEntries(configPath);
59
34
  if (loaded === null || !hasBareName(loaded.entries)) {
@@ -1,4 +1,4 @@
1
- import { type PackageResolver } from "./package-dir.js";
1
+ import type { PackageResolver } from "./package-dir.js";
2
2
  /** True when `path` is a bare package name rather than a file path. */
3
3
  export declare function isBareName(path: string): boolean;
4
4
  /**
@@ -11,10 +11,10 @@
11
11
  // and the current platform's loadable is globbed from inside it. Zero
12
12
  // matches and multiple matches are both hard errors -- disambiguate
13
13
  // with a literal path.
14
- import { existsSync, readdirSync, statSync } from "node:fs";
14
+ import { existsSync, statSync } from "node:fs";
15
15
  import { createRequire } from "node:module";
16
- import { isAbsolute, join, resolve as resolvePath } from "node:path";
17
- import { packageDir } from "./package-dir.js";
16
+ import { isAbsolute, resolve as resolvePath } from "node:path";
17
+ import { resolvePackage } from "./resolve-package.js";
18
18
  // Suffixes that mark a value as "already a file path" (so package resolution is
19
19
  // never attempted).
20
20
  const LOADABLE_SUFFIXES = [".so", ".dylib", ".dll", ".node"];
@@ -25,16 +25,6 @@ function defaultResolver() {
25
25
  paths: (s) => req.resolve.paths(s),
26
26
  };
27
27
  }
28
- /** Loadable-file glob suffix(es) for the current platform. */
29
- function platformSuffixes() {
30
- if (process.platform === "darwin") {
31
- return [".dylib", ".node"];
32
- }
33
- if (process.platform === "win32") {
34
- return [".dll", ".node"];
35
- }
36
- return [".so", ".node"];
37
- }
38
28
  /** True when `path` is a bare package name rather than a file path. */
39
29
  export function isBareName(path) {
40
30
  if (path.includes("/") || path.includes("\\")) {
@@ -42,23 +32,6 @@ export function isBareName(path) {
42
32
  }
43
33
  return !LOADABLE_SUFFIXES.some((s) => path.endsWith(s));
44
34
  }
45
- /** Glob the platform loadable inside a bare name's package dir. */
46
- function resolvePackage(name, resolver) {
47
- const dir = packageDir(name, resolver);
48
- const suffixes = platformSuffixes();
49
- const matches = readdirSync(dir, { recursive: true })
50
- .filter((entry) => suffixes.some((s) => entry.endsWith(s)))
51
- .map((entry) => join(dir, entry))
52
- .sort();
53
- const desc = suffixes.join(" / ");
54
- if (matches.length === 0) {
55
- throw new Error(`no loadable extension file (${desc}) found in package '${name}' (searched ${dir})`);
56
- }
57
- if (matches.length > 1) {
58
- throw new Error(`multiple loadable extension files found in package '${name}': ${matches.join(", ")}; disambiguate with a literal path`);
59
- }
60
- return matches[0];
61
- }
62
35
  /**
63
36
  * Resolve an extension `path` to a concrete file. `base` is the directory a
64
37
  * relative path and the bare-name shadow probe resolve against (a config file's
@@ -0,0 +1,3 @@
1
+ import { type PackageResolver } from "./package-dir.js";
2
+ /** Glob the platform loadable inside a bare name's package dir. */
3
+ export declare function resolvePackage(name: string, resolver: PackageResolver): string;
@@ -0,0 +1,31 @@
1
+ // Glob a bare package name's platform loadable out of its installed directory.
2
+ import { readdirSync } from "node:fs";
3
+ import { join } from "node:path";
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
+ }
15
+ /** Glob the platform loadable inside a bare name's package dir. */
16
+ export function resolvePackage(name, resolver) {
17
+ const dir = packageDir(name, resolver);
18
+ const suffixes = platformSuffixes();
19
+ const matches = readdirSync(dir, { recursive: true })
20
+ .filter((entry) => suffixes.some((s) => entry.endsWith(s)))
21
+ .map((entry) => join(dir, entry))
22
+ .sort();
23
+ const desc = suffixes.join(" / ");
24
+ if (matches.length === 0) {
25
+ throw new Error(`no loadable extension file (${desc}) found in package '${name}' (searched ${dir})`);
26
+ }
27
+ if (matches.length > 1) {
28
+ throw new Error(`multiple loadable extension files found in package '${name}': ${matches.join(", ")}; disambiguate with a literal path`);
29
+ }
30
+ return matches[0];
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirsql",
3
- "version": "0.4.36",
3
+ "version": "0.4.37",
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.36",
217
- "@dirsql/lib-linux-arm64-gnu": "0.4.36",
218
- "@dirsql/lib-darwin-x64": "0.4.36",
219
- "@dirsql/lib-darwin-arm64": "0.4.36",
220
- "@dirsql/lib-win32-x64-msvc": "0.4.36"
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"
221
221
  }
222
222
  }