@cobol-ts/path 0.0.14 → 0.0.17

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 (2) hide show
  1. package/README.md +20 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,15 +1,27 @@
1
- # @cobol-ts/debug
1
+ # @cobol-ts/path
2
2
 
3
- ## Purpose
3
+ Provide bounded, type-checked string and segment-array paths with runtime property access and explicit conversion.
4
4
 
5
- This module supplies a named debug logger controlled by a shared map of enabled names. Its purpose is conditional diagnostics at call sites, not structured metrics or error propagation. The separate [metrics module](../metrics/README.md) counts predefined operations without formatting debug messages.
5
+ Paths are capped at six levels, arrays are terminal, and lookup errors identify the failed segment.
6
6
 
7
- ## Public abstractions
7
+ ## Example
8
8
 
9
- `DebugState` is a `NameAnd<boolean>` map from `@cobol-ts/records`. `makeDebugLog(debugState, name)` constructs a `DebugLog` function for that name. `DebugLog` also exposes additional functions; consult [`src/debug.ts`](src/debug.ts) for their signatures and severity behaviour. `createMockDebugLog()` is a test-friendly implementation provided by [`src/debug.mock.ts`](src/debug.mock.ts).
9
+ ```typescript
10
+ import {stringPathGet, arrayPathGet, fromStringToArray} from '@cobol-ts/path'
10
11
 
11
- Loggers capture their name, and check the debug state when the logger is created; changing the map later does not retroactively enable an already-created logger. Use a single state map when diagnostics across components need coordinated control. Do not rely on debug output for production correctness, counters or deterministic benchmark measurement.
12
+ const data = {customer: {id: 7}}
13
+ const key = stringPathGet(data, 'customer.id')
14
+ const segments = fromStringToArray<typeof data>('customer.id')
15
+ const sameKey = arrayPathGet(data, segments)
16
+ // key and sameKey are 7
17
+ ```
12
18
 
13
- ## Related modules
19
+ `StringPath<T>` and `ArrayPath<T>` statically restrict traversal to six object levels, prohibit dotted property names in the string form and stop at arrays. Runtime accessors throw errors that identify the failing segment rather than silently returning undefined.
14
20
 
15
- The shared record-map type is in [records](../records/README.md), while [test_utils](../test_utils/README.md) can capture console output in tests.
21
+ ## Source and tests
22
+
23
+ **Public entry points:** [path.array.ts](./src/path.array.ts), [path.convert.ts](./src/path.convert.ts), [path.string.ts](./src/path.string.ts).
24
+
25
+ **Tests:** [path.array.spec.ts](src/path.array.spec.ts), [path.convert.spec.ts](src/path.convert.spec.ts), [path.string.spec.ts](src/path.string.spec.ts)
26
+
27
+ **Related:** [@cobol-ts/dependency_node](../../execution/dependency_node/README.md) · [@cobol-ts/records](../records/README.md).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobol-ts/path",
3
3
  "description": "Type safe path through objects",
4
- "version": "0.0.14",
4
+ "version": "0.0.17",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "browserslist": {
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@cobol-ts/records": "0.0.14"
20
+ "@cobol-ts/records": "0.0.17"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "^5.2.2",