@weiliang0121/capix-diagnostics 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +18 -2
- package/dist/detail.d.ts +6 -0
- package/dist/detail.js +2 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.js +2 -0
- package/dist/helper.d.ts +4 -0
- package/dist/helper.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/persistence.d.ts +5 -0
- package/dist/persistence.js +2 -0
- package/dist/traversal.d.ts +18 -0
- package/dist/traversal.js +2 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wei.liang (https://github.com/weiliang0121)
|
|
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,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @weiliang0121/capix-diagnostics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bounded diagnostics and persistence failures for CAPiX.
|
|
4
|
+
|
|
5
|
+
ES modules and TypeScript declarations. Requires Node.js 22.23.2 or newer.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @weiliang0121/capix-diagnostics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public entry points
|
|
12
|
+
|
|
13
|
+
- `@weiliang0121/capix-diagnostics`
|
|
14
|
+
|
|
15
|
+
This package is part of CAPiX. The npm distribution contains compiled JavaScript, type declarations, and this package's MIT license. Reference services and client applications are not included in this package or the initial npm release.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT. Copyright (c) 2026 wei.liang. See [LICENSE](LICENSE).
|
package/dist/detail.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RuntimeErrorDetail } from '@weiliang0121/capix-contracts';
|
|
2
|
+
import { ErrorTraversal } from './traversal.js';
|
|
3
|
+
type NestedErrorConverter = (value: unknown, depth: number) => RuntimeErrorDetail;
|
|
4
|
+
export declare function formatDetail(value: unknown, traversal: ErrorTraversal, depth: number, formatNestedError: NestedErrorConverter): RuntimeErrorDetail;
|
|
5
|
+
export declare function formatText(value: string): string;
|
|
6
|
+
export {};
|
package/dist/detail.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{isArray,isFinite}from"es-toolkit/compat";import{isNativeError}from"node:util/types";import{isBoolean,isDate,isMap,isNull,isNumber,isSet,isString,isSymbol,isUndefined}from"es-toolkit/predicate";import{formatLimits}from"./traversal.js";function formatDetail(value,traversal,depth,formatNestedError){if(!traversal.consume(depth))return"[Truncated: error conversion limit]";if(value===null||typeof value!="object")return formatScalar(value);if(traversal.contains(value))return"[Circular reference]";try{if(isNativeError(value))return formatNestedError(value,depth+1);const convert=__name(item=>formatDetail(item,traversal,depth+1,formatNestedError),"convert");return traversal.within(value,()=>formatObject(value,convert))}catch{return"[Uninspectable value]"}}__name(formatDetail,"formatDetail");function formatText(value){return value.length>formatLimits.string?`${value.slice(0,formatLimits.string)}[Truncated: string limit]`:value}__name(formatText,"formatText");function formatScalar(value){return isNull(value)||isBoolean(value)?value:isString(value)?formatText(value):isNumber(value)?isFinite(value)?value:`[Number: ${value}]`:isUndefined(value)?"[Undefined]":typeof value=="bigint"?formatText(`[BigInt: ${value}]`):isSymbol(value)?formatText(`[Symbol: ${value.description??""}]`):"[Function]"}__name(formatScalar,"formatScalar");function formatObject(value,convert){return isDate(value)?formatDate(value):isMap(value)?{type:"Map",entries:formatEntries(Map.prototype.entries.call(value),([key,item])=>[convert(key),convert(item)])}:isSet(value)?{type:"Set",entries:formatEntries(Set.prototype.values.call(value),convert)}:isArray(value)?formatArray(value,convert):formatProperties(value,convert)}__name(formatObject,"formatObject");function formatDate(value){const time=Date.prototype.getTime.call(value);return{type:"Date",value:isFinite(time)?new Date(time).toISOString():"[Invalid Date]"}}__name(formatDate,"formatDate");function formatEntries(values,convert){const entries=[];for(const value of values){if(entries.length>=formatLimits.entries){entries.push("[Truncated: entry limit]");break}entries.push(convert(value))}return entries}__name(formatEntries,"formatEntries");function formatArray(value,convert){const items=[];for(let i=0;i<Math.min(value.length,formatLimits.entries);i++)items.push(convert(readOwnValue(value,String(i))));return value.length>formatLimits.entries&&items.push("[Truncated: entry limit]"),items}__name(formatArray,"formatArray");function formatProperties(value,convert){const result=Object.create(null),keys=Object.keys(value);for(const key of keys.slice(0,formatLimits.entries))result[key]=convert(readOwnValue(value,key));return keys.length>formatLimits.entries&&(result["[Truncated]"]="Entry limit reached"),result}__name(formatProperties,"formatProperties");function readOwnValue(value,key){const descriptor=Object.getOwnPropertyDescriptor(value,key);return descriptor&&"value"in descriptor?descriptor.value:descriptor?"[Accessor not evaluated]":void 0}__name(readOwnValue,"readOwnValue");export{formatDetail,formatText};
|
package/dist/format.d.ts
ADDED
package/dist/format.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{isArray}from"es-toolkit/compat";import{isNativeError,isProxy}from"node:util/types";import{zipObject}from"es-toolkit/array";import{isError,isString,isUndefined}from"es-toolkit/predicate";import{formatLimits}from"./traversal.js";import{formatDetail,formatText}from"./detail.js";const errorFieldNames=["code","message","name","stack","detail","cause","errors"],nativeDOMGetters=new Set(typeof DOMException>"u"?[]:["name","message","code"].map(key=>Object.getOwnPropertyDescriptor(DOMException.prototype,key)?.get).filter(get=>get!==void 0)),nativeStackGetter=Object.getOwnPropertyDescriptor(new Error,"stack")?.get,nativeStackFormatter=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace")?.value;function formatError(error,traversal,depth=0){if(!traversal.consume(depth))return{code:"ERROR_TRUNCATED",message:"[Truncated: error conversion limit]"};if(error===null||typeof error!="object")return formatThrownValue(error,traversal,depth);if(isProxy(error))return{code:"UNREADABLE_ERROR",message:"[Uninspectable thrown object]"};if(traversal.contains(error))return{code:"CIRCULAR_ERROR",message:"[Circular error reference]"};try{return!isNativeError(error)&&!isError(error)?formatThrownValue(error,traversal,depth):traversal.within(error,()=>formatFields(readFields(error),traversal,depth))}catch{return{code:"UNREADABLE_ERROR",message:"[Uninspectable thrown object]"}}}__name(formatError,"formatError");function formatThrownValue(value,traversal,depth){return{code:"NON_ERROR_THROWN",message:"A non-Error value was thrown",detail:formatContent(value,traversal,depth+1)}}__name(formatThrownValue,"formatThrownValue");function readFields(error){return zipObject(errorFieldNames,errorFieldNames.map(key=>readProperty(error,key)))}__name(readFields,"readFields");function formatFields(fields,traversal,depth){return{code:isString(fields.code)?formatText(fields.code):isArray(fields.errors)?"AGGREGATE_ERROR":"INTERNAL_ERROR",message:isString(fields.message)?formatText(fields.message):"Error message unavailable",name:isString(fields.name)?formatText(fields.name):"Error",...isString(fields.stack)?{stack:formatText(fields.stack)}:{},...isUndefined(fields.detail)?{}:{detail:formatContent(fields.detail,traversal,depth+1)},...isUndefined(fields.cause)?{}:{cause:formatError(fields.cause,traversal,depth+1)},...isUndefined(fields.errors)?{}:{errors:formatMembers(fields.errors,traversal,depth+1)}}}__name(formatFields,"formatFields");function formatContent(value,traversal,depth){return formatDetail(value,traversal,depth,(error,nestedDepth)=>formatError(error,traversal,nestedDepth))}__name(formatContent,"formatContent");function formatMembers(members,traversal,depth){if(isProxy(members)||!isArray(members))return[{code:"UNREADABLE_ERROR",message:"[Unreadable aggregate members]"}];const errors=[];for(let i=0;i<Math.min(members.length,formatLimits.entries);i++)errors.push(formatError(readProperty(members,String(i)),traversal,depth));return members.length>formatLimits.entries&&errors.push({code:"ERROR_TRUNCATED",message:"[Truncated: aggregate member limit]"}),errors}__name(formatMembers,"formatMembers");function readProperty(value,key){try{let current=value;for(let depth=0;current&&depth<=formatLimits.depth;depth++){if(isProxy(current))return"[Unreadable property]";const descriptor=Object.getOwnPropertyDescriptor(current,key);if(descriptor){if("value"in descriptor)return descriptor.value;if(descriptor.get&&nativeDOMGetters.has(descriptor.get))return descriptor.get.call(value);if(key==="stack"&&descriptor.get&&descriptor.get===nativeStackGetter&&safeErrorText(value,"name")&&safeErrorText(value,"message")){const formatter=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");if(formatter&&"value"in formatter&&formatter.value===nativeStackFormatter)return descriptor.get.call(value)}return"[Accessor not evaluated]"}current=Object.getPrototypeOf(current)}return current?"[Truncated: prototype limit]":void 0}catch{return"[Unreadable property]"}}__name(readProperty,"readProperty");function safeErrorText(value,key){let current=value;for(let depth=0;current&&depth<=formatLimits.depth;depth++){if(isProxy(current))return!1;const descriptor=Object.getOwnPropertyDescriptor(current,key);if(descriptor)return"value"in descriptor&&(typeof descriptor.value=="string"||descriptor.value===void 0);current=Object.getPrototypeOf(current)}return current===null}__name(safeErrorText,"safeErrorText");export{formatError};
|
package/dist/helper.d.ts
ADDED
package/dist/helper.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{ErrorTraversal,formatLimits}from"./traversal.js";import{formatError}from"./format.js";class RuntimeErrorHelper{static{__name(this,"RuntimeErrorHelper")}static format(error){return formatError(error,new ErrorTraversal(formatLimits))}}export{RuntimeErrorHelper};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{RuntimeError}from"@weiliang0121/capix-contracts";class PersistenceError extends RuntimeError{static{__name(this,"PersistenceError")}operation;constructor(operation,cause){super("PERSISTENCE_FAILED",`Required persistence failed: ${operation}`,void 0,{cause}),this.operation=operation}}export{PersistenceError};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const formatLimits: {
|
|
2
|
+
readonly depth: 12;
|
|
3
|
+
readonly values: 2048;
|
|
4
|
+
readonly entries: 100;
|
|
5
|
+
readonly string: 16384;
|
|
6
|
+
};
|
|
7
|
+
export declare class ErrorTraversal {
|
|
8
|
+
private readonly limits;
|
|
9
|
+
private readonly ancestors;
|
|
10
|
+
private remaining;
|
|
11
|
+
constructor(limits: {
|
|
12
|
+
depth: number;
|
|
13
|
+
values: number;
|
|
14
|
+
});
|
|
15
|
+
consume(depth: number): boolean;
|
|
16
|
+
contains(value: object): boolean;
|
|
17
|
+
within<Result>(value: object, convert: () => Result): Result;
|
|
18
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
|
|
2
|
+
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});const formatLimits={depth:12,values:2048,entries:100,string:16384};class ErrorTraversal{static{__name(this,"ErrorTraversal")}limits;ancestors=new Set;remaining;constructor(limits){this.limits=limits,this.remaining=limits.values}consume(depth){return depth<=this.limits.depth&&this.remaining-- >0}contains(value){return this.ancestors.has(value)}within(value,convert){this.ancestors.add(value);try{return convert()}finally{this.ancestors.delete(value)}}}export{ErrorTraversal,formatLimits};
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weiliang0121/capix-diagnostics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"es-toolkit": "1.52.0",
|
|
14
|
+
"@weiliang0121/capix-contracts": "0.2.0"
|
|
15
|
+
},
|
|
16
|
+
"description": "Bounded diagnostics and persistence failures for CAPiX.",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "wei.liang (https://github.com/weiliang0121)",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/weiliang0121/capix.git",
|
|
22
|
+
"directory": "packages/diagnostics"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.23.2"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*.js",
|
|
31
|
+
"dist/**/*.d.ts",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "node ../../scripts/test/run.mjs --package ."
|
|
43
|
+
}
|
|
6
44
|
}
|