@notedge/panduck 0.0.0 → 0.0.1
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/bin/{panduck.mjs → panduck} +11 -11
- package/locales/en-US/cli.json +46 -46
- package/locales/locales.json +7 -7
- package/locales/zh-CN/cli.json +46 -46
- package/package.json +29 -34
- package/readme.md +5 -5
- package/src/cli/cli.ts +28 -28
- package/src/cli/commands/check-cmd.ts +174 -174
- package/src/cli/commands/convert-cmd.ts +300 -300
- package/src/cli/commands/doctor-cmd.ts +84 -84
- package/src/cli/commands/formats-cmd.ts +50 -50
- package/src/cli/commands/inspect-cmd.ts +231 -231
- package/src/cli/commands/plan-cmd.ts +188 -188
- package/src/cli/console-backend.ts +16 -16
- package/src/cli/context.ts +98 -98
- package/src/cli/diagnostics.ts +24 -24
- package/src/cli/exit-codes.ts +14 -14
- package/src/cli/format-registry.ts +170 -170
- package/src/cli/index.ts +7 -7
- package/src/cli/main.ts +10 -10
- package/src/cli/options.ts +127 -127
- package/src/cli/paths.ts +57 -56
- package/src/cli/pipeline.ts +225 -225
- package/src/cli/report.ts +110 -110
- package/src/index.ts +8 -8
- package/src/node/index.ts +14 -14
- package/src/node/load.ts +120 -120
- package/src/types.ts +49 -49
- package/src/wasm/index.ts +2 -2
- package/src/wasm/load.ts +23 -23
- package/src/wasm/panduck_wasm.d.ts +6 -6
package/src/cli/report.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import type { CapabilityState } from "./format-registry.js";
|
|
2
|
-
|
|
3
|
-
export const REPORT_SCHEMA_VERSION = "panduck.report/v1";
|
|
4
|
-
|
|
5
|
-
export type ReportStatus =
|
|
6
|
-
| "success"
|
|
7
|
-
| "success_with_loss"
|
|
8
|
-
| "partial"
|
|
9
|
-
| "blocked"
|
|
10
|
-
| "failed";
|
|
11
|
-
|
|
12
|
-
export type LossPolicy = "allow" | "warn" | "deny";
|
|
13
|
-
|
|
14
|
-
export type PanduckReport = {
|
|
15
|
-
schema_version: string;
|
|
16
|
-
tool: {
|
|
17
|
-
name: string;
|
|
18
|
-
version: string;
|
|
19
|
-
};
|
|
20
|
-
operation: string;
|
|
21
|
-
status: ReportStatus;
|
|
22
|
-
inputs: Array<{ path: string; format?: string }>;
|
|
23
|
-
detection?: {
|
|
24
|
-
outer?: string;
|
|
25
|
-
inner?: string;
|
|
26
|
-
format?: string;
|
|
27
|
-
confidence?: "hint" | "verified" | "ambiguous";
|
|
28
|
-
hints?: string[];
|
|
29
|
-
};
|
|
30
|
-
pipeline?: {
|
|
31
|
-
reader?: string;
|
|
32
|
-
writer?: string;
|
|
33
|
-
stages?: string[];
|
|
34
|
-
blocked_reason?: string;
|
|
35
|
-
};
|
|
36
|
-
parts?: string[];
|
|
37
|
-
decoded_parts?: Array<{
|
|
38
|
-
path: string;
|
|
39
|
-
compression_method: number;
|
|
40
|
-
compressed_size: number;
|
|
41
|
-
uncompressed_size: number;
|
|
42
|
-
decoded_size: number;
|
|
43
|
-
}>;
|
|
44
|
-
coverage?: {
|
|
45
|
-
state: CapabilityState;
|
|
46
|
-
read?: number;
|
|
47
|
-
write?: number;
|
|
48
|
-
};
|
|
49
|
-
losses?: Array<{
|
|
50
|
-
code: string;
|
|
51
|
-
owner: string;
|
|
52
|
-
severity: string;
|
|
53
|
-
message: string;
|
|
54
|
-
action?: string;
|
|
55
|
-
}>;
|
|
56
|
-
diagnostics?: Array<{
|
|
57
|
-
owner: string;
|
|
58
|
-
severity: string;
|
|
59
|
-
message: string;
|
|
60
|
-
code?: string;
|
|
61
|
-
}>;
|
|
62
|
-
outputs?: Array<{ path: string; published: boolean }>;
|
|
63
|
-
budgets?: Record<string, number>;
|
|
64
|
-
determinism?: {
|
|
65
|
-
profile?: string;
|
|
66
|
-
config?: string | null;
|
|
67
|
-
};
|
|
68
|
-
status_policy?: {
|
|
69
|
-
loss: LossPolicy;
|
|
70
|
-
strict: boolean;
|
|
71
|
-
exit_code: number;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export function createReport(input: {
|
|
76
|
-
operation: string;
|
|
77
|
-
toolVersion: string;
|
|
78
|
-
status: ReportStatus;
|
|
79
|
-
inputs: PanduckReport["inputs"];
|
|
80
|
-
detection?: PanduckReport["detection"];
|
|
81
|
-
pipeline?: PanduckReport["pipeline"];
|
|
82
|
-
parts?: PanduckReport["parts"];
|
|
83
|
-
decodedParts?: PanduckReport["decoded_parts"];
|
|
84
|
-
coverage?: PanduckReport["coverage"];
|
|
85
|
-
losses?: PanduckReport["losses"];
|
|
86
|
-
diagnostics?: PanduckReport["diagnostics"];
|
|
87
|
-
outputs?: PanduckReport["outputs"];
|
|
88
|
-
budgets?: PanduckReport["budgets"];
|
|
89
|
-
determinism?: PanduckReport["determinism"];
|
|
90
|
-
statusPolicy?: PanduckReport["status_policy"];
|
|
91
|
-
}): PanduckReport {
|
|
92
|
-
return {
|
|
93
|
-
schema_version: REPORT_SCHEMA_VERSION,
|
|
94
|
-
tool: { name: "panduck", version: input.toolVersion },
|
|
95
|
-
operation: input.operation,
|
|
96
|
-
status: input.status,
|
|
97
|
-
inputs: input.inputs,
|
|
98
|
-
detection: input.detection,
|
|
99
|
-
pipeline: input.pipeline,
|
|
100
|
-
parts: input.parts,
|
|
101
|
-
decoded_parts: input.decodedParts,
|
|
102
|
-
coverage: input.coverage,
|
|
103
|
-
losses: input.losses ?? [],
|
|
104
|
-
diagnostics: input.diagnostics ?? [],
|
|
105
|
-
outputs: input.outputs ?? [],
|
|
106
|
-
budgets: input.budgets ?? {},
|
|
107
|
-
determinism: input.determinism,
|
|
108
|
-
status_policy: input.statusPolicy,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
1
|
+
import type { CapabilityState } from "./format-registry.js";
|
|
2
|
+
|
|
3
|
+
export const REPORT_SCHEMA_VERSION = "panduck.report/v1";
|
|
4
|
+
|
|
5
|
+
export type ReportStatus =
|
|
6
|
+
| "success"
|
|
7
|
+
| "success_with_loss"
|
|
8
|
+
| "partial"
|
|
9
|
+
| "blocked"
|
|
10
|
+
| "failed";
|
|
11
|
+
|
|
12
|
+
export type LossPolicy = "allow" | "warn" | "deny";
|
|
13
|
+
|
|
14
|
+
export type PanduckReport = {
|
|
15
|
+
schema_version: string;
|
|
16
|
+
tool: {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
operation: string;
|
|
21
|
+
status: ReportStatus;
|
|
22
|
+
inputs: Array<{ path: string; format?: string }>;
|
|
23
|
+
detection?: {
|
|
24
|
+
outer?: string;
|
|
25
|
+
inner?: string;
|
|
26
|
+
format?: string;
|
|
27
|
+
confidence?: "hint" | "verified" | "ambiguous";
|
|
28
|
+
hints?: string[];
|
|
29
|
+
};
|
|
30
|
+
pipeline?: {
|
|
31
|
+
reader?: string;
|
|
32
|
+
writer?: string;
|
|
33
|
+
stages?: string[];
|
|
34
|
+
blocked_reason?: string;
|
|
35
|
+
};
|
|
36
|
+
parts?: string[];
|
|
37
|
+
decoded_parts?: Array<{
|
|
38
|
+
path: string;
|
|
39
|
+
compression_method: number;
|
|
40
|
+
compressed_size: number;
|
|
41
|
+
uncompressed_size: number;
|
|
42
|
+
decoded_size: number;
|
|
43
|
+
}>;
|
|
44
|
+
coverage?: {
|
|
45
|
+
state: CapabilityState;
|
|
46
|
+
read?: number;
|
|
47
|
+
write?: number;
|
|
48
|
+
};
|
|
49
|
+
losses?: Array<{
|
|
50
|
+
code: string;
|
|
51
|
+
owner: string;
|
|
52
|
+
severity: string;
|
|
53
|
+
message: string;
|
|
54
|
+
action?: string;
|
|
55
|
+
}>;
|
|
56
|
+
diagnostics?: Array<{
|
|
57
|
+
owner: string;
|
|
58
|
+
severity: string;
|
|
59
|
+
message: string;
|
|
60
|
+
code?: string;
|
|
61
|
+
}>;
|
|
62
|
+
outputs?: Array<{ path: string; published: boolean }>;
|
|
63
|
+
budgets?: Record<string, number>;
|
|
64
|
+
determinism?: {
|
|
65
|
+
profile?: string;
|
|
66
|
+
config?: string | null;
|
|
67
|
+
};
|
|
68
|
+
status_policy?: {
|
|
69
|
+
loss: LossPolicy;
|
|
70
|
+
strict: boolean;
|
|
71
|
+
exit_code: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export function createReport(input: {
|
|
76
|
+
operation: string;
|
|
77
|
+
toolVersion: string;
|
|
78
|
+
status: ReportStatus;
|
|
79
|
+
inputs: PanduckReport["inputs"];
|
|
80
|
+
detection?: PanduckReport["detection"];
|
|
81
|
+
pipeline?: PanduckReport["pipeline"];
|
|
82
|
+
parts?: PanduckReport["parts"];
|
|
83
|
+
decodedParts?: PanduckReport["decoded_parts"];
|
|
84
|
+
coverage?: PanduckReport["coverage"];
|
|
85
|
+
losses?: PanduckReport["losses"];
|
|
86
|
+
diagnostics?: PanduckReport["diagnostics"];
|
|
87
|
+
outputs?: PanduckReport["outputs"];
|
|
88
|
+
budgets?: PanduckReport["budgets"];
|
|
89
|
+
determinism?: PanduckReport["determinism"];
|
|
90
|
+
statusPolicy?: PanduckReport["status_policy"];
|
|
91
|
+
}): PanduckReport {
|
|
92
|
+
return {
|
|
93
|
+
schema_version: REPORT_SCHEMA_VERSION,
|
|
94
|
+
tool: { name: "panduck", version: input.toolVersion },
|
|
95
|
+
operation: input.operation,
|
|
96
|
+
status: input.status,
|
|
97
|
+
inputs: input.inputs,
|
|
98
|
+
detection: input.detection,
|
|
99
|
+
pipeline: input.pipeline,
|
|
100
|
+
parts: input.parts,
|
|
101
|
+
decoded_parts: input.decodedParts,
|
|
102
|
+
coverage: input.coverage,
|
|
103
|
+
losses: input.losses ?? [],
|
|
104
|
+
diagnostics: input.diagnostics ?? [],
|
|
105
|
+
outputs: input.outputs ?? [],
|
|
106
|
+
budgets: input.budgets ?? {},
|
|
107
|
+
determinism: input.determinism,
|
|
108
|
+
status_policy: input.statusPolicy,
|
|
109
|
+
};
|
|
110
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type { PanduckBindings, PanduckWasmOptions } from "./types.js";
|
|
2
|
-
export { loadPanduckNative, loadPanduckNode } from "./node/index.js";
|
|
3
|
-
export { loadPanduckWasm } from "./wasm/index.js";
|
|
4
|
-
export { buildPanduckCli, runCli, getFormatRegistry, ExitCode, REPORT_SCHEMA_VERSION } from "./cli/index.js";
|
|
5
|
-
export type { FormatRecord, PanduckReport, CapabilityState } from "./cli/index.js";
|
|
6
|
-
|
|
7
|
-
/** @deprecated Use `loadPanduckNode` or `loadPanduckNative`. */
|
|
8
|
-
export type PanduckNative = import("./types.js").PanduckBindings;
|
|
1
|
+
export type { PanduckBindings, PanduckWasmOptions } from "./types.js";
|
|
2
|
+
export { loadPanduckNative, loadPanduckNode } from "./node/index.js";
|
|
3
|
+
export { loadPanduckWasm } from "./wasm/index.js";
|
|
4
|
+
export { buildPanduckCli, runCli, getFormatRegistry, ExitCode, REPORT_SCHEMA_VERSION } from "./cli/index.js";
|
|
5
|
+
export type { FormatRecord, PanduckReport, CapabilityState } from "./cli/index.js";
|
|
6
|
+
|
|
7
|
+
/** @deprecated Use `loadPanduckNode` or `loadPanduckNative`. */
|
|
8
|
+
export type PanduckNative = import("./types.js").PanduckBindings;
|
package/src/node/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { loadPanduckNode } from "./load.js";
|
|
2
|
-
|
|
3
|
-
export type { PanduckBindings } from "../types.js";
|
|
4
|
-
export { loadPanduckNode } from "./load.js";
|
|
5
|
-
|
|
6
|
-
let cached: import("../types.js").PanduckBindings | undefined;
|
|
7
|
-
|
|
8
|
-
/** Cached Node-API binding loader. */
|
|
9
|
-
export function loadPanduckNative(): import("../types.js").PanduckBindings {
|
|
10
|
-
if (!cached) {
|
|
11
|
-
cached = loadPanduckNode();
|
|
12
|
-
}
|
|
13
|
-
return cached;
|
|
14
|
-
}
|
|
1
|
+
import { loadPanduckNode } from "./load.js";
|
|
2
|
+
|
|
3
|
+
export type { PanduckBindings } from "../types.js";
|
|
4
|
+
export { loadPanduckNode } from "./load.js";
|
|
5
|
+
|
|
6
|
+
let cached: import("../types.js").PanduckBindings | undefined;
|
|
7
|
+
|
|
8
|
+
/** Cached Node-API binding loader. */
|
|
9
|
+
export function loadPanduckNative(): import("../types.js").PanduckBindings {
|
|
10
|
+
if (!cached) {
|
|
11
|
+
cached = loadPanduckNode();
|
|
12
|
+
}
|
|
13
|
+
return cached;
|
|
14
|
+
}
|
package/src/node/load.ts
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
import type { PanduckBindings } from "../types.js";
|
|
4
|
-
|
|
5
|
-
type NativeBinding = {
|
|
6
|
-
panduckVersion: () => string;
|
|
7
|
-
supportedFormats: () => string[];
|
|
8
|
-
isSupportedFormat: (name: string) => boolean;
|
|
9
|
-
supportsConversion?: (from: string, to: string) => boolean;
|
|
10
|
-
supportedConversions?: () => string[];
|
|
11
|
-
convertDocument?: (from: string, to: string, inputPath: string) => {
|
|
12
|
-
exitCode: number;
|
|
13
|
-
markdown?: string;
|
|
14
|
-
binary?: Uint8Array;
|
|
15
|
-
reportJson: string;
|
|
16
|
-
};
|
|
17
|
-
inspectIndex?: (inputPath: string) => {
|
|
18
|
-
format: string;
|
|
19
|
-
outer: string;
|
|
20
|
-
inner: string;
|
|
21
|
-
parts: string[];
|
|
22
|
-
reportJson: string;
|
|
23
|
-
};
|
|
24
|
-
installConsoleLogFile?: (path: string) => void;
|
|
25
|
-
installLoggerLogFile?: (path: string) => void;
|
|
26
|
-
inspectDecode?: (inputPath: string, partPath?: string) => {
|
|
27
|
-
format: string;
|
|
28
|
-
outer: string;
|
|
29
|
-
inner: string;
|
|
30
|
-
parts: Array<{
|
|
31
|
-
path: string;
|
|
32
|
-
compressionMethod: number;
|
|
33
|
-
compressedSize: number;
|
|
34
|
-
uncompressedSize: number;
|
|
35
|
-
decodedSize: number;
|
|
36
|
-
}>;
|
|
37
|
-
reportJson: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const PLATFORM_PACKAGES: Record<string, string> = {
|
|
42
|
-
"win32-x64": "@notedge/panduck-win32-x64",
|
|
43
|
-
"linux-x64": "@notedge/panduck-linux-x64",
|
|
44
|
-
"linux-arm64": "@notedge/panduck-linux-arm64",
|
|
45
|
-
"darwin-x64": "@notedge/panduck-darwin-x64",
|
|
46
|
-
"darwin-arm64": "@notedge/panduck-darwin-arm64",
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/** Load the platform-specific Node-API binary from `@notedge/panduck-<platform>`. */
|
|
50
|
-
export function loadPanduckNode(): PanduckBindings {
|
|
51
|
-
const key = `${process.platform}-${process.arch}`;
|
|
52
|
-
const pkg = PLATFORM_PACKAGES[key];
|
|
53
|
-
if (!pkg) {
|
|
54
|
-
throw new Error(`Unsupported platform for Panduck native bindings: ${key}`);
|
|
55
|
-
}
|
|
56
|
-
const require = createRequire(import.meta.url);
|
|
57
|
-
const binding = require(pkg).default as NativeBinding;
|
|
58
|
-
return {
|
|
59
|
-
panduckVersion: () => binding.panduckVersion(),
|
|
60
|
-
supportedFormats: () => binding.supportedFormats(),
|
|
61
|
-
isSupportedFormat: (name) => binding.isSupportedFormat(name),
|
|
62
|
-
supportsConversion: binding.supportsConversion
|
|
63
|
-
? (from, to) => binding.supportsConversion!(from, to)
|
|
64
|
-
: undefined,
|
|
65
|
-
supportedConversions: binding.supportedConversions
|
|
66
|
-
? () => binding.supportedConversions!()
|
|
67
|
-
: undefined,
|
|
68
|
-
convertDocument: binding.convertDocument
|
|
69
|
-
? (from, to, inputPath) => {
|
|
70
|
-
const response = binding.convertDocument!(from, to, inputPath);
|
|
71
|
-
return {
|
|
72
|
-
exitCode: response.exitCode,
|
|
73
|
-
markdown: response.markdown,
|
|
74
|
-
binary: response.binary
|
|
75
|
-
? new Uint8Array(response.binary)
|
|
76
|
-
: undefined,
|
|
77
|
-
reportJson: response.reportJson,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
inspectIndex: binding.inspectIndex
|
|
82
|
-
? (inputPath) => {
|
|
83
|
-
const response = binding.inspectIndex!(inputPath);
|
|
84
|
-
return {
|
|
85
|
-
format: response.format,
|
|
86
|
-
outer: response.outer,
|
|
87
|
-
inner: response.inner,
|
|
88
|
-
parts: response.parts,
|
|
89
|
-
reportJson: response.reportJson,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
: undefined,
|
|
93
|
-
inspectDecode: binding.inspectDecode
|
|
94
|
-
? (inputPath, partPath) => {
|
|
95
|
-
const response = binding.inspectDecode!(inputPath, partPath);
|
|
96
|
-
return {
|
|
97
|
-
format: response.format,
|
|
98
|
-
outer: response.outer,
|
|
99
|
-
inner: response.inner,
|
|
100
|
-
parts: response.parts,
|
|
101
|
-
reportJson: response.reportJson,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
: undefined,
|
|
105
|
-
installLoggerLogFile: binding.installLoggerLogFile
|
|
106
|
-
? (path) => {
|
|
107
|
-
binding.installLoggerLogFile!(path);
|
|
108
|
-
}
|
|
109
|
-
: binding.installConsoleLogFile
|
|
110
|
-
? (path) => {
|
|
111
|
-
binding.installConsoleLogFile!(path);
|
|
112
|
-
}
|
|
113
|
-
: undefined,
|
|
114
|
-
installConsoleLogFile: binding.installConsoleLogFile
|
|
115
|
-
? (path) => {
|
|
116
|
-
binding.installConsoleLogFile!(path);
|
|
117
|
-
}
|
|
118
|
-
: undefined,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
import type { PanduckBindings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
type NativeBinding = {
|
|
6
|
+
panduckVersion: () => string;
|
|
7
|
+
supportedFormats: () => string[];
|
|
8
|
+
isSupportedFormat: (name: string) => boolean;
|
|
9
|
+
supportsConversion?: (from: string, to: string) => boolean;
|
|
10
|
+
supportedConversions?: () => string[];
|
|
11
|
+
convertDocument?: (from: string, to: string, inputPath: string) => {
|
|
12
|
+
exitCode: number;
|
|
13
|
+
markdown?: string;
|
|
14
|
+
binary?: Uint8Array;
|
|
15
|
+
reportJson: string;
|
|
16
|
+
};
|
|
17
|
+
inspectIndex?: (inputPath: string) => {
|
|
18
|
+
format: string;
|
|
19
|
+
outer: string;
|
|
20
|
+
inner: string;
|
|
21
|
+
parts: string[];
|
|
22
|
+
reportJson: string;
|
|
23
|
+
};
|
|
24
|
+
installConsoleLogFile?: (path: string) => void;
|
|
25
|
+
installLoggerLogFile?: (path: string) => void;
|
|
26
|
+
inspectDecode?: (inputPath: string, partPath?: string) => {
|
|
27
|
+
format: string;
|
|
28
|
+
outer: string;
|
|
29
|
+
inner: string;
|
|
30
|
+
parts: Array<{
|
|
31
|
+
path: string;
|
|
32
|
+
compressionMethod: number;
|
|
33
|
+
compressedSize: number;
|
|
34
|
+
uncompressedSize: number;
|
|
35
|
+
decodedSize: number;
|
|
36
|
+
}>;
|
|
37
|
+
reportJson: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const PLATFORM_PACKAGES: Record<string, string> = {
|
|
42
|
+
"win32-x64": "@notedge/panduck-win32-x64",
|
|
43
|
+
"linux-x64": "@notedge/panduck-linux-x64",
|
|
44
|
+
"linux-arm64": "@notedge/panduck-linux-arm64",
|
|
45
|
+
"darwin-x64": "@notedge/panduck-darwin-x64",
|
|
46
|
+
"darwin-arm64": "@notedge/panduck-darwin-arm64",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Load the platform-specific Node-API binary from `@notedge/panduck-<platform>`. */
|
|
50
|
+
export function loadPanduckNode(): PanduckBindings {
|
|
51
|
+
const key = `${process.platform}-${process.arch}`;
|
|
52
|
+
const pkg = PLATFORM_PACKAGES[key];
|
|
53
|
+
if (!pkg) {
|
|
54
|
+
throw new Error(`Unsupported platform for Panduck native bindings: ${key}`);
|
|
55
|
+
}
|
|
56
|
+
const require = createRequire(import.meta.url);
|
|
57
|
+
const binding = require(pkg).default as NativeBinding;
|
|
58
|
+
return {
|
|
59
|
+
panduckVersion: () => binding.panduckVersion(),
|
|
60
|
+
supportedFormats: () => binding.supportedFormats(),
|
|
61
|
+
isSupportedFormat: (name) => binding.isSupportedFormat(name),
|
|
62
|
+
supportsConversion: binding.supportsConversion
|
|
63
|
+
? (from, to) => binding.supportsConversion!(from, to)
|
|
64
|
+
: undefined,
|
|
65
|
+
supportedConversions: binding.supportedConversions
|
|
66
|
+
? () => binding.supportedConversions!()
|
|
67
|
+
: undefined,
|
|
68
|
+
convertDocument: binding.convertDocument
|
|
69
|
+
? (from, to, inputPath) => {
|
|
70
|
+
const response = binding.convertDocument!(from, to, inputPath);
|
|
71
|
+
return {
|
|
72
|
+
exitCode: response.exitCode,
|
|
73
|
+
markdown: response.markdown,
|
|
74
|
+
binary: response.binary
|
|
75
|
+
? new Uint8Array(response.binary)
|
|
76
|
+
: undefined,
|
|
77
|
+
reportJson: response.reportJson,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
: undefined,
|
|
81
|
+
inspectIndex: binding.inspectIndex
|
|
82
|
+
? (inputPath) => {
|
|
83
|
+
const response = binding.inspectIndex!(inputPath);
|
|
84
|
+
return {
|
|
85
|
+
format: response.format,
|
|
86
|
+
outer: response.outer,
|
|
87
|
+
inner: response.inner,
|
|
88
|
+
parts: response.parts,
|
|
89
|
+
reportJson: response.reportJson,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
inspectDecode: binding.inspectDecode
|
|
94
|
+
? (inputPath, partPath) => {
|
|
95
|
+
const response = binding.inspectDecode!(inputPath, partPath);
|
|
96
|
+
return {
|
|
97
|
+
format: response.format,
|
|
98
|
+
outer: response.outer,
|
|
99
|
+
inner: response.inner,
|
|
100
|
+
parts: response.parts,
|
|
101
|
+
reportJson: response.reportJson,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
: undefined,
|
|
105
|
+
installLoggerLogFile: binding.installLoggerLogFile
|
|
106
|
+
? (path) => {
|
|
107
|
+
binding.installLoggerLogFile!(path);
|
|
108
|
+
}
|
|
109
|
+
: binding.installConsoleLogFile
|
|
110
|
+
? (path) => {
|
|
111
|
+
binding.installConsoleLogFile!(path);
|
|
112
|
+
}
|
|
113
|
+
: undefined,
|
|
114
|
+
installConsoleLogFile: binding.installConsoleLogFile
|
|
115
|
+
? (path) => {
|
|
116
|
+
binding.installConsoleLogFile!(path);
|
|
117
|
+
}
|
|
118
|
+
: undefined,
|
|
119
|
+
};
|
|
120
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
export type ConvertResponse = {
|
|
2
|
-
exitCode: number;
|
|
3
|
-
markdown?: string;
|
|
4
|
-
binary?: Uint8Array;
|
|
5
|
-
reportJson: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type InspectIndexResponse = {
|
|
9
|
-
format: string;
|
|
10
|
-
outer: string;
|
|
11
|
-
inner: string;
|
|
12
|
-
parts: string[];
|
|
13
|
-
reportJson: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type InspectDecodedPart = {
|
|
17
|
-
path: string;
|
|
18
|
-
compressionMethod: number;
|
|
19
|
-
compressedSize: number;
|
|
20
|
-
uncompressedSize: number;
|
|
21
|
-
decodedSize: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type InspectDecodeResponse = {
|
|
25
|
-
format: string;
|
|
26
|
-
outer: string;
|
|
27
|
-
inner: string;
|
|
28
|
-
parts: InspectDecodedPart[];
|
|
29
|
-
reportJson: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** Shared Panduck binding surface for Node-API and WebAssembly backends. */
|
|
33
|
-
export type PanduckBindings = {
|
|
34
|
-
panduckVersion: () => string;
|
|
35
|
-
supportedFormats: () => string[];
|
|
36
|
-
isSupportedFormat: (name: string) => boolean;
|
|
37
|
-
supportsConversion?: (from: string, to: string) => boolean;
|
|
38
|
-
supportedConversions?: () => string[];
|
|
39
|
-
convertDocument?: (from: string, to: string, inputPath: string) => ConvertResponse;
|
|
40
|
-
inspectIndex?: (inputPath: string) => InspectIndexResponse;
|
|
41
|
-
inspectDecode?: (inputPath: string, partPath?: string) => InspectDecodeResponse;
|
|
42
|
-
installLoggerLogFile?: (path: string) => void;
|
|
43
|
-
installConsoleLogFile?: (path: string) => void;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type PanduckWasmOptions = {
|
|
47
|
-
/** Browser URL for `panduck_wasm_bg.wasm` when not using the default package layout. */
|
|
48
|
-
url?: string | URL;
|
|
49
|
-
};
|
|
1
|
+
export type ConvertResponse = {
|
|
2
|
+
exitCode: number;
|
|
3
|
+
markdown?: string;
|
|
4
|
+
binary?: Uint8Array;
|
|
5
|
+
reportJson: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type InspectIndexResponse = {
|
|
9
|
+
format: string;
|
|
10
|
+
outer: string;
|
|
11
|
+
inner: string;
|
|
12
|
+
parts: string[];
|
|
13
|
+
reportJson: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type InspectDecodedPart = {
|
|
17
|
+
path: string;
|
|
18
|
+
compressionMethod: number;
|
|
19
|
+
compressedSize: number;
|
|
20
|
+
uncompressedSize: number;
|
|
21
|
+
decodedSize: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type InspectDecodeResponse = {
|
|
25
|
+
format: string;
|
|
26
|
+
outer: string;
|
|
27
|
+
inner: string;
|
|
28
|
+
parts: InspectDecodedPart[];
|
|
29
|
+
reportJson: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Shared Panduck binding surface for Node-API and WebAssembly backends. */
|
|
33
|
+
export type PanduckBindings = {
|
|
34
|
+
panduckVersion: () => string;
|
|
35
|
+
supportedFormats: () => string[];
|
|
36
|
+
isSupportedFormat: (name: string) => boolean;
|
|
37
|
+
supportsConversion?: (from: string, to: string) => boolean;
|
|
38
|
+
supportedConversions?: () => string[];
|
|
39
|
+
convertDocument?: (from: string, to: string, inputPath: string) => ConvertResponse;
|
|
40
|
+
inspectIndex?: (inputPath: string) => InspectIndexResponse;
|
|
41
|
+
inspectDecode?: (inputPath: string, partPath?: string) => InspectDecodeResponse;
|
|
42
|
+
installLoggerLogFile?: (path: string) => void;
|
|
43
|
+
installConsoleLogFile?: (path: string) => void;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type PanduckWasmOptions = {
|
|
47
|
+
/** Browser URL for `panduck_wasm_bg.wasm` when not using the default package layout. */
|
|
48
|
+
url?: string | URL;
|
|
49
|
+
};
|
package/src/wasm/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { PanduckBindings, PanduckWasmOptions } from "../types.js";
|
|
2
|
-
export { loadPanduckWasm } from "./load.js";
|
|
1
|
+
export type { PanduckBindings, PanduckWasmOptions } from "../types.js";
|
|
2
|
+
export { loadPanduckWasm } from "./load.js";
|
package/src/wasm/load.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { PanduckBindings, PanduckWasmOptions } from "../types.js";
|
|
2
|
-
|
|
3
|
-
type WasmModule = {
|
|
4
|
-
default: (input?: { module_or_path?: string | URL }) => Promise<unknown>;
|
|
5
|
-
panduckVersion: () => string;
|
|
6
|
-
supportedFormats: () => string[];
|
|
7
|
-
isSupportedFormat: (name: string) => boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/** Load `@notedge/panduck-unknown-wasm32` and return the Panduck binding surface. */
|
|
11
|
-
export async function loadPanduckWasm(options: PanduckWasmOptions = {}): Promise<PanduckBindings> {
|
|
12
|
-
const wasm = (await import("@notedge/panduck-unknown-wasm32
|
|
13
|
-
if (options.url) {
|
|
14
|
-
await wasm.default({ module_or_path: options.url });
|
|
15
|
-
} else {
|
|
16
|
-
await wasm.default();
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
panduckVersion: () => wasm.panduckVersion(),
|
|
20
|
-
supportedFormats: () => wasm.supportedFormats(),
|
|
21
|
-
isSupportedFormat: (name) => wasm.isSupportedFormat(name),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
1
|
+
import type { PanduckBindings, PanduckWasmOptions } from "../types.js";
|
|
2
|
+
|
|
3
|
+
type WasmModule = {
|
|
4
|
+
default: (input?: { module_or_path?: string | URL }) => Promise<unknown>;
|
|
5
|
+
panduckVersion: () => string;
|
|
6
|
+
supportedFormats: () => string[];
|
|
7
|
+
isSupportedFormat: (name: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Load `@notedge/panduck-unknown-wasm32` and return the Panduck binding surface. */
|
|
11
|
+
export async function loadPanduckWasm(options: PanduckWasmOptions = {}): Promise<PanduckBindings> {
|
|
12
|
+
const wasm = (await import("@notedge/panduck-unknown-wasm32")) as WasmModule;
|
|
13
|
+
if (options.url) {
|
|
14
|
+
await wasm.default({ module_or_path: options.url });
|
|
15
|
+
} else {
|
|
16
|
+
await wasm.default();
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
panduckVersion: () => wasm.panduckVersion(),
|
|
20
|
+
supportedFormats: () => wasm.supportedFormats(),
|
|
21
|
+
isSupportedFormat: (name) => wasm.isSupportedFormat(name),
|
|
22
|
+
};
|
|
23
|
+
}
|