@docxkit/errors 0.0.0-stage → 0.7.0-rc.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) 2025-PRESENT ntnyq <https://github.com/ntnyq>
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.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @docxkit/errors
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared error class and error codes for docx-kit packages. This package has no runtime dependencies, so generation and browser preview use the same `DocxKitError` class without depending on each other.
4
+
5
+ ```ts
6
+ import { DocxKitError, ERROR_CODES } from '@docxkit/errors'
7
+ import type { ErrorCode } from '@docxkit/errors'
8
+
9
+ const code: ErrorCode = ERROR_CODES.EXPORT_FAILED
10
+ throw new DocxKitError(code, 'Document export failed')
11
+ ```
12
+
13
+ `@docxkit/core` and `docx-kit` re-export these APIs. Document, style, and plugin types remain in the declaration-only `@docxkit/types` package.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * `@docxkit/errors` — Shared error codes and error class for docx-kit.
3
+ *
4
+ * @module errors
5
+ */
6
+ /**
7
+ * Well-known error codes used throughout the library.
8
+ *
9
+ * Consumers can match against these codes for structured error handling.
10
+ */
11
+ export declare const ERROR_CODES: {
12
+ /**
13
+ * Document export failed.
14
+ */
15
+ readonly EXPORT_FAILED: "EXPORT_FAILED";
16
+ /**
17
+ * Image data is empty, corrupt, or unsupported.
18
+ */
19
+ readonly IMAGE_INVALID_DATA: "IMAGE_INVALID_DATA";
20
+ /**
21
+ * Plugin manifest JSON is missing required fields or has invalid structure.
22
+ */
23
+ readonly MANIFEST_INVALID: "MANIFEST_INVALID";
24
+ /**
25
+ * Plugin manifest file was not found at the expected path.
26
+ */
27
+ readonly MANIFEST_MISSING: "MANIFEST_MISSING";
28
+ /**
29
+ * A required plugin dependency was not found or version is incompatible.
30
+ */
31
+ readonly PLUGIN_DEPENDENCY_MISSING: "PLUGIN_DEPENDENCY_MISSING";
32
+ /**
33
+ * Plugin failed to load (import error, network error, etc.).
34
+ */
35
+ readonly PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED";
36
+ /**
37
+ * A plugin node referenced an unregistered plugin.
38
+ */
39
+ readonly PLUGIN_NOT_REGISTERED: "PLUGIN_NOT_REGISTERED";
40
+ /**
41
+ * A plugin's `render()` method threw an error.
42
+ */
43
+ readonly PLUGIN_RENDER_FAILED: "PLUGIN_RENDER_FAILED";
44
+ /**
45
+ * Plugin's `docxKit` semver range is incompatible with the running version.
46
+ */
47
+ readonly PLUGIN_VERSION_MISMATCH: "PLUGIN_VERSION_MISMATCH";
48
+ /**
49
+ * A `className` referenced a stylesheet key that doesn't exist.
50
+ */
51
+ readonly STYLE_UNKNOWN_CLASS: "STYLE_UNKNOWN_CLASS";
52
+ /**
53
+ * Table has no columns, invalid spans, or overlapping cell positions.
54
+ */
55
+ readonly TABLE_INVALID_COLUMNS: "TABLE_INVALID_COLUMNS";
56
+ /**
57
+ * Encountered a node type that has no registered compiler.
58
+ */
59
+ readonly UNKNOWN_NODE_TYPE: "UNKNOWN_NODE_TYPE";
60
+ };
61
+ /**
62
+ * Union type of all known error codes.
63
+ */
64
+ export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
65
+ /**
66
+ * Structured error class for docx-kit.
67
+ *
68
+ * Carries a machine-readable `code`, a human-readable `message`,
69
+ * and optionally the underlying `cause`.
70
+ */
71
+ export declare class DocxKitError extends Error {
72
+ /**
73
+ * The underlying error that caused this failure (if any).
74
+ */
75
+ readonly cause: unknown;
76
+ /**
77
+ * Machine-readable error code.
78
+ */
79
+ readonly code: string | ErrorCode;
80
+ /**
81
+ * @param code - — Known error code from {@link ERROR_CODES}
82
+ * @param message - — Human-readable description
83
+ * @param cause - — Optional underlying error
84
+ */
85
+ constructor(code: string | ErrorCode, message: string, cause?: unknown);
86
+ }
package/dist/index.js ADDED
@@ -0,0 +1,89 @@
1
+ // src/index.ts
2
+ /**
3
+ * `@docxkit/errors` — Shared error codes and error class for docx-kit.
4
+ *
5
+ * @module errors
6
+ */
7
+ /**
8
+ * Well-known error codes used throughout the library.
9
+ *
10
+ * Consumers can match against these codes for structured error handling.
11
+ */
12
+ const ERROR_CODES = {
13
+ /**
14
+ * Document export failed.
15
+ */
16
+ EXPORT_FAILED: "EXPORT_FAILED",
17
+ /**
18
+ * Image data is empty, corrupt, or unsupported.
19
+ */
20
+ IMAGE_INVALID_DATA: "IMAGE_INVALID_DATA",
21
+ /**
22
+ * Plugin manifest JSON is missing required fields or has invalid structure.
23
+ */
24
+ MANIFEST_INVALID: "MANIFEST_INVALID",
25
+ /**
26
+ * Plugin manifest file was not found at the expected path.
27
+ */
28
+ MANIFEST_MISSING: "MANIFEST_MISSING",
29
+ /**
30
+ * A required plugin dependency was not found or version is incompatible.
31
+ */
32
+ PLUGIN_DEPENDENCY_MISSING: "PLUGIN_DEPENDENCY_MISSING",
33
+ /**
34
+ * Plugin failed to load (import error, network error, etc.).
35
+ */
36
+ PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED",
37
+ /**
38
+ * A plugin node referenced an unregistered plugin.
39
+ */
40
+ PLUGIN_NOT_REGISTERED: "PLUGIN_NOT_REGISTERED",
41
+ /**
42
+ * A plugin's `render()` method threw an error.
43
+ */
44
+ PLUGIN_RENDER_FAILED: "PLUGIN_RENDER_FAILED",
45
+ /**
46
+ * Plugin's `docxKit` semver range is incompatible with the running version.
47
+ */
48
+ PLUGIN_VERSION_MISMATCH: "PLUGIN_VERSION_MISMATCH",
49
+ /**
50
+ * A `className` referenced a stylesheet key that doesn't exist.
51
+ */
52
+ STYLE_UNKNOWN_CLASS: "STYLE_UNKNOWN_CLASS",
53
+ /**
54
+ * Table has no columns, invalid spans, or overlapping cell positions.
55
+ */
56
+ TABLE_INVALID_COLUMNS: "TABLE_INVALID_COLUMNS",
57
+ /**
58
+ * Encountered a node type that has no registered compiler.
59
+ */
60
+ UNKNOWN_NODE_TYPE: "UNKNOWN_NODE_TYPE"
61
+ };
62
+ /**
63
+ * Structured error class for docx-kit.
64
+ *
65
+ * Carries a machine-readable `code`, a human-readable `message`,
66
+ * and optionally the underlying `cause`.
67
+ */
68
+ var DocxKitError = class extends Error {
69
+ /**
70
+ * The underlying error that caused this failure (if any).
71
+ */
72
+ cause;
73
+ /**
74
+ * Machine-readable error code.
75
+ */
76
+ code;
77
+ /**
78
+ * @param code - — Known error code from {@link ERROR_CODES}
79
+ * @param message - — Human-readable description
80
+ * @param cause - — Optional underlying error
81
+ */
82
+ constructor(code, message, cause) {
83
+ super(message);
84
+ this.name = "DocxKitError";
85
+ this.code = code;
86
+ this.cause = cause;
87
+ }
88
+ };
89
+ export { DocxKitError, ERROR_CODES };
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@docxkit/errors",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "version": "0.7.0-rc.0",
5
+ "description": "Shared error class and error codes for docx-kit packages",
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "ntnyq",
9
+ "email": "ntnyq13@gmail.com"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ntnyq/docx-kit.git",
14
+ "directory": "packages/errors"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "sideEffects": false,
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "dev": "tsdown --watch"
34
+ }
35
+ }