@markitdownjs/pack 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MarkItDownJS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export { pack, unpack } from "./pack.js";
2
+ export type { PackBundle, PackManifest, PackOptions, PackCompression } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { pack, unpack } from "./pack.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
package/dist/pack.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { ConversionResult } from "@markitdownjs/shared";
2
+ import type { PackBundle, PackOptions } from "./types.js";
3
+ /**
4
+ * Pack a ConversionResult into a portable bundle.
5
+ * The bundle contains compressed chunks and metadata that can be restored anywhere.
6
+ */
7
+ export declare function pack(result: ConversionResult, options?: PackOptions): Promise<PackBundle>;
8
+ /**
9
+ * Unpack a PackBundle back into a ConversionResult-like object.
10
+ */
11
+ export declare function unpack(bundle: PackBundle): {
12
+ markdown: string;
13
+ chunks: any[];
14
+ metadata: Record<string, unknown>;
15
+ ast?: any;
16
+ };
17
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAgB,WAAW,EAAE,MAAM,YAAY,CAAC;AAExE;;;GAGG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAoDnG;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAWA"}
package/dist/pack.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Pack a ConversionResult into a portable bundle.
3
+ * The bundle contains compressed chunks and metadata that can be restored anywhere.
4
+ */
5
+ export async function pack(result, options = {}) {
6
+ const { compression: _compression = "none", includeAst = false, includeChunks = true, metadata, } = options;
7
+ const chunks = result.chunks ?? [];
8
+ // Build the payload data.
9
+ const payloadData = {};
10
+ if (includeChunks) {
11
+ payloadData.chunks = chunks.map((c) => ({
12
+ id: c.id,
13
+ content: c.content,
14
+ metadata: c.metadata,
15
+ ast: includeAst ? c.ast : undefined,
16
+ }));
17
+ }
18
+ if (includeAst && result.ast) {
19
+ payloadData.ast = result.ast;
20
+ }
21
+ payloadData.markdown = result.markdown;
22
+ payloadData.metadata = result.metadata;
23
+ // Serialize to JSON.
24
+ const json = JSON.stringify(payloadData);
25
+ // Base64-encode (compression is reserved for future use).
26
+ const payload = btoa(unescape(encodeURIComponent(json)));
27
+ // Compute manifest.
28
+ const totalTokens = chunks.reduce((sum, c) => sum + (c.metadata.tokenCount ?? 0), 0);
29
+ const manifest = {
30
+ chunkCount: chunks.length,
31
+ tokenCount: totalTokens,
32
+ };
33
+ // Simple fingerprint from markdown content.
34
+ let hash = 0;
35
+ for (let i = 0; i < result.markdown.length; i++) {
36
+ hash = ((hash << 5) - hash + result.markdown.charCodeAt(i)) | 0;
37
+ }
38
+ manifest.fingerprint = `djb2:${Math.abs(hash).toString(16).padStart(8, "0")}`;
39
+ return {
40
+ format: "markitdownjs-pack-v1",
41
+ manifest,
42
+ payload,
43
+ metadata,
44
+ };
45
+ }
46
+ /**
47
+ * Unpack a PackBundle back into a ConversionResult-like object.
48
+ */
49
+ export function unpack(bundle) {
50
+ // Decode base64 payload.
51
+ const json = decodeURIComponent(escape(atob(bundle.payload)));
52
+ const data = JSON.parse(json);
53
+ return {
54
+ markdown: data.markdown ?? "",
55
+ chunks: data.chunks ?? [],
56
+ metadata: data.metadata ?? {},
57
+ ast: data.ast,
58
+ };
59
+ }
60
+ //# sourceMappingURL=pack.js.map
@@ -0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,GAAG,EAAE,IAAI,CAAC,GAAG;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /** Compression type for the pack payload */
2
+ export type PackCompression = "none" | "gzip" | "brotli";
3
+ /** Manifest for a packed bundle */
4
+ export interface PackManifest {
5
+ /** Total number of chunks */
6
+ chunkCount: number;
7
+ /** Total token count across all chunks */
8
+ tokenCount: number;
9
+ /** Token reduction percentage vs raw text */
10
+ reduction?: string;
11
+ /** Content fingerprint for dedup */
12
+ fingerprint?: string;
13
+ }
14
+ /** Configuration for packing */
15
+ export interface PackOptions {
16
+ /** Compression algorithm (default: "none") */
17
+ compression?: PackCompression;
18
+ /** Include the full AST in the bundle (default: false for smaller payload) */
19
+ includeAst?: boolean;
20
+ /** Include chunks in the bundle (default: true) */
21
+ includeChunks?: boolean;
22
+ /** Optional metadata to embed in the manifest */
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ /** A portable bundle produced by pack() */
26
+ export interface PackBundle {
27
+ /** Format identifier */
28
+ format: "markitdownjs-pack-v1";
29
+ /** Manifest with summary stats */
30
+ manifest: PackManifest;
31
+ /** Base64-encoded compressed payload */
32
+ payload: string;
33
+ /** Embedded metadata */
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEzD,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mDAAmD;IACnD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,2CAA2C;AAC3C,MAAM,WAAW,UAAU;IACzB,wBAAwB;IACxB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,kCAAkC;IAClC,QAAQ,EAAE,YAAY,CAAC;IACvB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@markitdownjs/pack",
3
+ "version": "0.1.0",
4
+ "description": "Standardized portable output format for MarkItDownJS",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@markitdownjs/shared": "0.2.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^20.0.0",
24
+ "typescript": "^5.5.0"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc --project tsconfig.json",
28
+ "dev": "tsc --watch --project tsconfig.json",
29
+ "typecheck": "tsc --noEmit",
30
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
31
+ }
32
+ }