@attentionform/astra 0.0.0-stage → 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.
Files changed (30) hide show
  1. package/LICENSE +206 -0
  2. package/NOTICE +12 -0
  3. package/README.md +211 -2
  4. package/dist/cli.js +40911 -0
  5. package/dist/packages/cli/src/cli/batch-cmd.d.ts +169 -0
  6. package/dist/packages/cli/src/cli/create-cmd.d.ts +4 -0
  7. package/dist/packages/cli/src/cli/errors.d.ts +86 -0
  8. package/dist/packages/cli/src/cli/export-cmd.d.ts +2 -0
  9. package/dist/packages/cli/src/cli/history-cmd.d.ts +5 -0
  10. package/dist/packages/cli/src/cli/import-cmd.d.ts +2 -0
  11. package/dist/packages/cli/src/cli/inspect-cmd.d.ts +3 -0
  12. package/dist/packages/cli/src/cli/io.d.ts +60 -0
  13. package/dist/packages/cli/src/cli/normalize-cmd.d.ts +9 -0
  14. package/dist/packages/cli/src/cli/output.d.ts +95 -0
  15. package/dist/packages/cli/src/cli/run.d.ts +6 -0
  16. package/dist/packages/cli/src/cli/sanitize-cmd.d.ts +26 -0
  17. package/dist/packages/cli/src/cli/search-cmd.d.ts +2 -0
  18. package/dist/packages/cli/src/cli/stats-cmd.d.ts +2 -0
  19. package/dist/packages/cli/src/cli/usage.d.ts +8 -0
  20. package/dist/packages/cli/src/cli/validate-cmd.d.ts +2 -0
  21. package/dist/packages/cli/src/cli/visual-cmd.d.ts +34 -0
  22. package/dist/packages/cli/src/cli.d.ts +44 -0
  23. package/dist/packages/cli/src/export.d.ts +18 -0
  24. package/dist/packages/ooxml-validator/src/index.d.ts +33 -0
  25. package/dist/packages/ooxml-validator/src/one-shot.d.ts +2 -0
  26. package/dist/packages/ooxml-validator/src/protocol.d.ts +30 -0
  27. package/dist/packages/ooxml-validator/src/resolve-binary.d.ts +5 -0
  28. package/dist/packages/ooxml-validator/src/types.d.ts +65 -0
  29. package/dist/packages/ooxml-validator/src/worker-client.d.ts +38 -0
  30. package/package.json +70 -4
@@ -0,0 +1,30 @@
1
+ import type { OfficeVersion, ValidationError } from './types.js';
2
+ export interface WorkerRequestHeader {
3
+ id: number;
4
+ op?: 'validate' | 'ping' | 'version' | 'shutdown' | string;
5
+ kind?: 'docx' | 'pptx' | 'xlsx' | string;
6
+ office?: OfficeVersion | string;
7
+ size?: number;
8
+ maxErrors?: number;
9
+ maxDocBytes?: number;
10
+ }
11
+ export interface WorkerResponse {
12
+ id: number | null;
13
+ ok: boolean;
14
+ pong?: boolean;
15
+ sdkVersion?: string;
16
+ office?: string;
17
+ durationMs?: number;
18
+ errorCount?: number;
19
+ truncated?: boolean;
20
+ fatal?: boolean;
21
+ error?: string;
22
+ errors?: ValidationError[];
23
+ }
24
+ export declare function encodeRequest(header: WorkerRequestHeader, bytes?: Uint8Array | Buffer): Buffer;
25
+ export declare class JsonLineDecoder {
26
+ private decoder;
27
+ private buffer;
28
+ push(chunk: Buffer | Uint8Array): WorkerResponse[];
29
+ end(): WorkerResponse[];
30
+ }
@@ -0,0 +1,5 @@
1
+ export declare function resolveBinaryDetails(): {
2
+ binaryPath: string;
3
+ platformPackage: string;
4
+ };
5
+ export declare function resolveEmbeddedBinary(): string;
@@ -0,0 +1,65 @@
1
+ export declare const OFFICE_VERSIONS: readonly ["Office2007", "Office2010", "Office2013", "Office2016", "Office2019", "Office2021", "Microsoft365"];
2
+ export type OfficeVersion = (typeof OFFICE_VERSIONS)[number];
3
+ export interface ErrorNode {
4
+ localName?: string | null;
5
+ namespaceUri?: string | null;
6
+ }
7
+ export type ValidationErrorClass = 'schema' | 'semantic' | 'markup-compat' | 'package' | 'exception' | string;
8
+ export interface ValidationError {
9
+ /** Human-readable description of the problem. */
10
+ description?: string | null;
11
+ /** Package part the error was found in, e.g. `/word/document.xml`. `null` for `errorType: 'Exception'`. */
12
+ path?: string | null;
13
+ /** XPath of the offending element. `null` for `errorType: 'Exception'`. */
14
+ xPath?: string | null;
15
+ /** Open XML SDK error id, e.g. `Sch_UnexpectedElementContentExpectingComplex`. `null` for `errorType: 'Exception'`. */
16
+ id?: string | null;
17
+ /** `Schema`, `Semantic`, `Package`, `MarkupCompatibility`, or `Exception` when the file could not be opened at all. */
18
+ errorType?: string | null;
19
+ /** Part URI string (e.g. `/word/document.xml`). */
20
+ part?: string | null;
21
+ /** Error classification: 'schema' | 'semantic' | 'markup-compat' | 'package' | 'exception'. */
22
+ class?: ValidationErrorClass | null;
23
+ /** Offending XML element information when present. */
24
+ node?: ErrorNode | null;
25
+ /** Related XML element information when present. */
26
+ relatedNode?: ErrorNode | null;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface ValidationResult {
30
+ file: string;
31
+ ok: boolean;
32
+ errors: ValidationError[];
33
+ sdkVersion?: string;
34
+ office?: string;
35
+ durationMs?: number;
36
+ truncated?: boolean;
37
+ errorCount?: number;
38
+ [key: string]: unknown;
39
+ }
40
+ export interface ValidateOptions {
41
+ /** Open XML schema version to validate against. Defaults to `Microsoft365` for one-shot, `Office2019` for buffer. */
42
+ officeVersion?: OfficeVersion;
43
+ maxErrors?: number;
44
+ timeoutMs?: number;
45
+ maxDocBytes?: number;
46
+ }
47
+ export interface ValidatorPoolOptions {
48
+ workers?: number;
49
+ recycleAfter?: number;
50
+ timeoutMs?: number;
51
+ maxDocBytes?: number;
52
+ maxErrors?: number;
53
+ }
54
+ export interface BackendInfo {
55
+ platformPackage: string;
56
+ binaryPath: string;
57
+ sdkVersion: string;
58
+ binarySha256: string;
59
+ workerSupported: boolean;
60
+ }
61
+ export interface ValidatorInstance {
62
+ validate(bytes: Buffer | Uint8Array, opts?: ValidateOptions): Promise<ValidationResult>;
63
+ validateFile(path: string, opts?: ValidateOptions): Promise<ValidationResult>;
64
+ close(): Promise<void>;
65
+ }
@@ -0,0 +1,38 @@
1
+ import { type WorkerRequestHeader, type WorkerResponse } from './protocol.js';
2
+ import type { ValidatorPoolOptions } from './types.js';
3
+ export declare class WorkerClient {
4
+ private binaryPath;
5
+ private recycleAfter;
6
+ private timeoutMs;
7
+ private maxDocBytes;
8
+ private maxErrors;
9
+ private child;
10
+ private liveChildren;
11
+ private queue;
12
+ private current;
13
+ private nextId;
14
+ private requestsHandled;
15
+ private closed;
16
+ private _spawnCount;
17
+ private _spawnedPids;
18
+ constructor(opts?: ValidatorPoolOptions & {
19
+ binaryPath?: string;
20
+ });
21
+ get pid(): number | undefined;
22
+ get spawnCount(): number;
23
+ get spawnedPids(): number[];
24
+ private ensureWorker;
25
+ private refChild;
26
+ private unrefChild;
27
+ send(header: Omit<WorkerRequestHeader, 'id'>, bytes?: Uint8Array | Buffer, overrideTimeoutMs?: number): Promise<WorkerResponse>;
28
+ private processQueue;
29
+ private handleResponse;
30
+ private handleTimeout;
31
+ private handleWriteError;
32
+ private handleProcessError;
33
+ private handleProcessExit;
34
+ private retryOrReject;
35
+ private recycleWorker;
36
+ private killWorker;
37
+ close(): Promise<void>;
38
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@attentionform/astra",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Command-line tool for OOXML (.docx) document engineering",
5
+ "main": "dist/cli.js",
6
+ "types": "dist/packages/cli/src/cli.d.ts",
7
+ "bin": {
8
+ "astra": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE",
14
+ "NOTICE",
15
+ "!dist/packages/engine",
16
+ "!dist/**/*.map"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "license": "BUSL-1.1",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Attentionform/astra.git",
25
+ "directory": "packages/cli"
26
+ },
27
+ "keywords": [
28
+ "cli",
29
+ "astra",
30
+ "ooxml",
31
+ "docx",
32
+ "word",
33
+ "terminal",
34
+ "document",
35
+ "automation"
36
+ ],
37
+ "type": "commonjs",
38
+ "scripts": {
39
+ "build": "node ../../scripts/check-adm-zip-imports.mjs && tsc --noEmit -p tsconfig.json && esbuild src/cli.ts --bundle --packages=external --platform=node --target=node22 --format=cjs --outfile=dist/cli.js --log-level=warning && tsc -p tsconfig.dts.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
40
+ "typecheck": "tsc --noEmit -p tsconfig.json",
41
+ "test": "vitest run",
42
+ "start": "node dist/cli.js",
43
+ "adm-zip-gate": "node ../../scripts/check-adm-zip-imports.mjs"
44
+ },
45
+ "dependencies": {
46
+ "@attentionform/astra-engine": "^0.1.0",
47
+ "@attentionform/ooxml-validator": "^0.1.0",
48
+ "@xmldom/xmldom": "0.8.15",
49
+ "adm-zip": "0.6.1",
50
+ "isomorphic-git": "^1.25.0",
51
+ "marked": "18.0.5",
52
+ "p-limit": "^3.1.0",
53
+ "zod": "4.6.7"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^25.9.1",
57
+ "esbuild": "^0.25.12",
58
+ "typescript": "^5.2.2",
59
+ "vitest": "^4.1.7"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.19.0"
63
+ },
64
+ "homepage": "https://attentionform.com",
65
+ "bugs": {
66
+ "url": "https://github.com/Attentionform/astra/issues"
67
+ },
68
+ "author": {
69
+ "name": "Attentionform",
70
+ "url": "https://attentionform.com"
71
+ }
72
+ }