quack-search 0.0.2 → 0.0.3
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/api/fetch.d.ts +2 -1
- package/dist/api/fetch.js +2 -4
- package/dist/api/search.d.ts +2 -2
- package/dist/api/search.js +2 -4
- package/dist/core/binary.d.ts +1 -1
- package/dist/core/binary.js +18 -18
- package/dist/core/runner.d.ts +2 -2
- package/dist/core/runner.js +11 -4
- package/dist/index.js +34 -37
- package/dist/types/core.d.ts +15 -1
- package/dist/types/core.js +1 -0
- package/package.json +10 -8
- package/bin/quack-darwin-arm64 +0 -0
- package/bin/quack-darwin-x64 +0 -0
- package/bin/quack-linux-x64 +0 -0
- package/bin/quack-windows-x64.exe +0 -0
- package/scripts/postinstall.js +0 -25
package/dist/api/fetch.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { FetchResult } from "../types/core";
|
|
2
|
+
export declare function fetchContent(url: string, timeoutMs?: number): Promise<FetchResult>;
|
package/dist/api/fetch.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { runCore } from "../core/runner";
|
|
2
2
|
export async function fetchContent(url, timeoutMs) {
|
|
3
|
-
|
|
4
|
-
throw new Error("url is required");
|
|
5
|
-
}
|
|
6
|
-
return runCore({
|
|
3
|
+
const res = await runCore({
|
|
7
4
|
action: "fetch",
|
|
8
5
|
url,
|
|
9
6
|
}, timeoutMs);
|
|
7
|
+
return res.fetch ?? { success: false, reason: "unknown" };
|
|
10
8
|
}
|
package/dist/api/search.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SearchOptions } from "../types/core";
|
|
2
|
-
export declare function search(query: string, options?: SearchOptions): Promise<
|
|
1
|
+
import type { SearchOptions, SearchResult } from "../types/core";
|
|
2
|
+
export declare function search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
package/dist/api/search.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { runCore } from "../core/runner";
|
|
2
2
|
export async function search(query, options = {}) {
|
|
3
|
-
|
|
4
|
-
throw new Error("query is required");
|
|
5
|
-
}
|
|
6
|
-
return runCore({
|
|
3
|
+
const res = await runCore({
|
|
7
4
|
action: "search",
|
|
8
5
|
query,
|
|
9
6
|
maxResults: options.maxResults ?? 10,
|
|
10
7
|
}, options.timeoutMs);
|
|
8
|
+
return res.results ?? [];
|
|
11
9
|
}
|
package/dist/core/binary.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function resolveBinaryPath(
|
|
1
|
+
export declare function resolveBinaryPath(): string;
|
package/dist/core/binary.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let suffix;
|
|
1
|
+
import { platform, arch } from "node:process";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
function resolveBinaryPackage() {
|
|
7
6
|
if (platform === "darwin" && arch === "arm64") {
|
|
8
|
-
|
|
7
|
+
return "quack-search-darwin-arm64";
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (platform === "darwin" && arch === "x64") {
|
|
10
|
+
return "quack-search-darwin-x64";
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (platform === "linux" && arch === "x64") {
|
|
13
|
+
return "quack-search-linux-x64";
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (platform === "win32" && arch === "x64") {
|
|
16
|
+
return "quack-search-windows-x64";
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
throw new Error(`unsupported platform: ${platform} ${arch}`);
|
|
19
|
+
}
|
|
20
|
+
export function resolveBinaryPath() {
|
|
21
|
+
const pkgName = resolveBinaryPackage();
|
|
22
|
+
const pkgEntry = require.resolve(pkgName);
|
|
23
|
+
return pkgEntry;
|
|
24
24
|
}
|
package/dist/core/runner.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CoreRequest } from "../types/core";
|
|
2
|
-
export declare function runCore(payload: CoreRequest, timeoutMs?: number
|
|
1
|
+
import type { CoreRequest, CoreResponse } from "../types/core";
|
|
2
|
+
export declare function runCore(payload: CoreRequest, timeoutMs?: number): Promise<CoreResponse>;
|
package/dist/core/runner.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { resolveBinaryPath } from "./binary";
|
|
3
|
-
export function runCore(payload, timeoutMs = 30_000
|
|
3
|
+
export function runCore(payload, timeoutMs = 30_000) {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
|
-
|
|
5
|
+
let binaryPath;
|
|
6
|
+
try {
|
|
7
|
+
binaryPath = resolveBinaryPath();
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
reject(err);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
6
13
|
const proc = spawn(binaryPath, {
|
|
7
14
|
stdio: ["pipe", "pipe", "pipe"],
|
|
8
15
|
});
|
|
@@ -40,11 +47,11 @@ export function runCore(payload, timeoutMs = 30_000, metaUrl = import.meta.url)
|
|
|
40
47
|
reject(new Error(parsed.error));
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
|
-
if (!parsed.
|
|
50
|
+
if (!parsed.results && !parsed.fetch) {
|
|
44
51
|
reject(new Error("empty response from core"));
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
|
-
resolve(parsed
|
|
54
|
+
resolve(parsed);
|
|
48
55
|
});
|
|
49
56
|
proc.stdin.write(JSON.stringify(payload));
|
|
50
57
|
proc.stdin.end();
|
package/dist/index.js
CHANGED
|
@@ -3,39 +3,40 @@
|
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
4
|
|
|
5
5
|
// src/core/binary.ts
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { fileURLToPath } from "url";
|
|
11
|
-
function resolveDirname(metaUrl) {
|
|
12
|
-
return typeof import.meta.dir === "string" ? import.meta.dir : dirname(fileURLToPath(metaUrl));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/core/binary.ts
|
|
16
|
-
function resolveBinaryPath(metaUrl) {
|
|
17
|
-
const platform = process.platform;
|
|
18
|
-
const arch = process.arch;
|
|
19
|
-
let suffix;
|
|
6
|
+
import { platform, arch } from "process";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
var require2 = createRequire(import.meta.url);
|
|
9
|
+
function resolveBinaryPackage() {
|
|
20
10
|
if (platform === "darwin" && arch === "arm64") {
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error(`unsupported platform: ${platform} ${arch}`);
|
|
11
|
+
return "quack-search-darwin-arm64";
|
|
12
|
+
}
|
|
13
|
+
if (platform === "darwin" && arch === "x64") {
|
|
14
|
+
return "quack-search-darwin-x64";
|
|
15
|
+
}
|
|
16
|
+
if (platform === "linux" && arch === "x64") {
|
|
17
|
+
return "quack-search-linux-x64";
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
if (platform === "win32" && arch === "x64") {
|
|
20
|
+
return "quack-search-windows-x64";
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`unsupported platform: ${platform} ${arch}`);
|
|
23
|
+
}
|
|
24
|
+
function resolveBinaryPath() {
|
|
25
|
+
const pkgName = resolveBinaryPackage();
|
|
26
|
+
const pkgEntry = require2.resolve(pkgName);
|
|
27
|
+
return pkgEntry;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
// src/core/runner.ts
|
|
36
|
-
function runCore(payload, timeoutMs = 30000
|
|
31
|
+
function runCore(payload, timeoutMs = 30000) {
|
|
37
32
|
return new Promise((resolve, reject) => {
|
|
38
|
-
|
|
33
|
+
let binaryPath;
|
|
34
|
+
try {
|
|
35
|
+
binaryPath = resolveBinaryPath();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
reject(err);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
39
40
|
const proc = spawn(binaryPath, {
|
|
40
41
|
stdio: ["pipe", "pipe", "pipe"]
|
|
41
42
|
});
|
|
@@ -72,11 +73,11 @@ function runCore(payload, timeoutMs = 30000, metaUrl = import.meta.url) {
|
|
|
72
73
|
reject(new Error(parsed.error));
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
|
-
if (!parsed.
|
|
76
|
+
if (!parsed.results && !parsed.fetch) {
|
|
76
77
|
reject(new Error("empty response from core"));
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
|
-
resolve(parsed
|
|
80
|
+
resolve(parsed);
|
|
80
81
|
});
|
|
81
82
|
proc.stdin.write(JSON.stringify(payload));
|
|
82
83
|
proc.stdin.end();
|
|
@@ -85,24 +86,20 @@ function runCore(payload, timeoutMs = 30000, metaUrl = import.meta.url) {
|
|
|
85
86
|
|
|
86
87
|
// src/api/search.ts
|
|
87
88
|
async function search(query, options = {}) {
|
|
88
|
-
|
|
89
|
-
throw new Error("query is required");
|
|
90
|
-
}
|
|
91
|
-
return runCore({
|
|
89
|
+
const res = await runCore({
|
|
92
90
|
action: "search",
|
|
93
91
|
query,
|
|
94
92
|
maxResults: options.maxResults ?? 10
|
|
95
93
|
}, options.timeoutMs);
|
|
94
|
+
return res.results ?? [];
|
|
96
95
|
}
|
|
97
96
|
// src/api/fetch.ts
|
|
98
97
|
async function fetchContent(url, timeoutMs) {
|
|
99
|
-
|
|
100
|
-
throw new Error("url is required");
|
|
101
|
-
}
|
|
102
|
-
return runCore({
|
|
98
|
+
const res = await runCore({
|
|
103
99
|
action: "fetch",
|
|
104
100
|
url
|
|
105
101
|
}, timeoutMs);
|
|
102
|
+
return res.fetch ?? { success: false, reason: "unknown" };
|
|
106
103
|
}
|
|
107
104
|
export {
|
|
108
105
|
search,
|
package/dist/types/core.d.ts
CHANGED
|
@@ -10,7 +10,21 @@ export type CoreRequest = {
|
|
|
10
10
|
action: "fetch";
|
|
11
11
|
url: string;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
13
|
+
export type SearchResult = {
|
|
14
|
+
title: string;
|
|
15
|
+
url: string;
|
|
16
|
+
snippet: string;
|
|
17
|
+
rank: number;
|
|
18
|
+
};
|
|
19
|
+
export type FetchFailureReason = "blocked" | "timeout" | "http_error" | "unknown";
|
|
20
|
+
export type FetchResult = {
|
|
21
|
+
success: boolean;
|
|
14
22
|
text?: string;
|
|
23
|
+
reason?: FetchFailureReason;
|
|
24
|
+
truncated?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type CoreResponse = {
|
|
27
|
+
results?: SearchResult[];
|
|
28
|
+
fetch?: FetchResult;
|
|
15
29
|
error?: string;
|
|
16
30
|
};
|
package/dist/types/core.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quack-search",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"bin",
|
|
9
|
-
"scripts"
|
|
10
|
-
],
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
11
8
|
"scripts": {
|
|
12
|
-
"build": "bunx tsc -p tsconfig.build.json && bun build src/index.ts --outdir dist --target bun"
|
|
13
|
-
"postinstall": "node scripts/postinstall.js"
|
|
9
|
+
"build": "bunx tsc -p tsconfig.build.json && bun build src/index.ts --outdir dist --target bun"
|
|
14
10
|
},
|
|
15
11
|
"devDependencies": {
|
|
16
12
|
"@types/bun": "latest",
|
|
@@ -18,5 +14,11 @@
|
|
|
18
14
|
},
|
|
19
15
|
"peerDependencies": {
|
|
20
16
|
"typescript": "^5"
|
|
17
|
+
},
|
|
18
|
+
"optionalDependencies": {
|
|
19
|
+
"quack-search-darwin-arm64": "0.0.3",
|
|
20
|
+
"quack-search-darwin-x64": "0.0.3",
|
|
21
|
+
"quack-search-linux-x64": "0.0.3",
|
|
22
|
+
"quack-search-windows-x64": "0.0.3"
|
|
21
23
|
}
|
|
22
24
|
}
|
package/bin/quack-darwin-arm64
DELETED
|
Binary file
|
package/bin/quack-darwin-x64
DELETED
|
Binary file
|
package/bin/quack-linux-x64
DELETED
|
Binary file
|
|
Binary file
|
package/scripts/postinstall.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { platform, arch } from "node:process";
|
|
2
|
-
import { chmodSync, existsSync } from "node:fs";
|
|
3
|
-
import { join, dirname } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const BIN_DIR = join(__dirname, "..", "bin");
|
|
8
|
-
|
|
9
|
-
function suffix() {
|
|
10
|
-
if (platform === "darwin" && arch === "arm64") return "darwin-arm64";
|
|
11
|
-
if (platform === "darwin" && arch === "x64") return "darwin-x64";
|
|
12
|
-
if (platform === "linux" && arch === "x64") return "linux-x64";
|
|
13
|
-
if (platform === "win32" && arch === "x64") return "windows-x64.exe";
|
|
14
|
-
throw new Error(`Unsupported platform: ${platform} ${arch}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const binPath = join(BIN_DIR, `quack-${suffix()}`);
|
|
18
|
-
|
|
19
|
-
if (!existsSync(binPath)) {
|
|
20
|
-
console.error(`Missing binary: ${binPath}`);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
chmodSync(binPath, 0o755);
|
|
25
|
-
console.log(`quack binary ready: ${binPath}`);
|