@kakasoo/deep-strict-types 2.0.6 → 2.0.7

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/README.md CHANGED
@@ -10,6 +10,45 @@ Type-safe `Pick`, `Omit`, and key extraction for deeply nested TypeScript object
10
10
 
11
11
  ![example](https://github.com/user-attachments/assets/28316425-8302-453e-b238-0c732606e6a7)
12
12
 
13
+ ## Why in the AI Era?
14
+
15
+ AI writes more code than ever — and makes more subtle mistakes than ever. This library serves as a **compile-time guardrail** for AI-generated code.
16
+
17
+ ### The Problem
18
+
19
+ AI coding tools often produce code that looks correct but has subtle type mismatches in deeply nested structures:
20
+
21
+ ```typescript
22
+ // AI-generated code: looks fine, but "prce" is a typo
23
+ function getTotal(order: Order) {
24
+ return order.items.map(i => i.prce); // no error with loose types
25
+ }
26
+ ```
27
+
28
+ ### The Solution
29
+
30
+ With strict deep types as constraints, the TypeScript compiler catches AI mistakes **instantly**:
31
+
32
+ ```typescript
33
+ import { DeepStrictPick } from '@kakasoo/deep-strict-types';
34
+
35
+ type OrderSummary = DeepStrictPick<Order, 'items[*].price' | 'customer.name'>;
36
+
37
+ // Now AI gets a precise error:
38
+ // Type '"items[*].prce"' is not assignable to
39
+ // type '"items" | "items[*]" | "items[*].price" | "customer" | "customer.name"'
40
+ ```
41
+
42
+ ### AI Self-Correction Loop
43
+
44
+ When used with `tsc` or `tsx` in a build loop, AI agents can read the type error, understand exactly what went wrong, and fix it automatically:
45
+
46
+ ```
47
+ AI generates code → tsc compile → type error → AI reads error → AI self-corrects → recompile
48
+ ```
49
+
50
+ The stricter your types, the better the error messages, and the faster AI converges on correct code. **In an AI-driven workflow, deep strict types aren't overhead — they're the safety net.**
51
+
13
52
  ## Installation
14
53
 
15
54
  ```bash
@@ -9,6 +9,8 @@ import { DeepStrictPick } from '../types/DeepStrictPick';
9
9
  *
10
10
  * This is the runtime counterpart of the {@link DeepStrictPick} type.
11
11
  *
12
+ * @deprecated Use {@link deepStrictPick} instead. This curried form will be removed in a future version.
13
+ *
12
14
  * @template T - The object type of the input
13
15
  * @param input - The source object to extract properties from
14
16
  * @returns A function that accepts a key path `K` and returns the deeply-picked result
@@ -1 +1 @@
1
- {"version":3,"file":"DeepStrictAssert.d.ts","sourceRoot":"","sources":["../../../src/functions/DeepStrictAssert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,SAAS,MAAM,SAAS,CAAC,MAC1B,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAiC/D,CAAC"}
1
+ {"version":3,"file":"DeepStrictAssert.d.ts","sourceRoot":"","sources":["../../../src/functions/DeepStrictAssert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,SAAS,MAAM,SAAS,CAAC,MAC1B,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAiC/D,CAAC"}
@@ -10,6 +10,8 @@ exports.deepStrictAssert = void 0;
10
10
  *
11
11
  * This is the runtime counterpart of the {@link DeepStrictPick} type.
12
12
  *
13
+ * @deprecated Use {@link deepStrictPick} instead. This curried form will be removed in a future version.
14
+ *
13
15
  * @template T - The object type of the input
14
16
  * @param input - The source object to extract properties from
15
17
  * @returns A function that accepts a key path `K` and returns the deeply-picked result
@@ -1 +1 @@
1
- {"version":3,"file":"DeepStrictAssert.js","sourceR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AAC;gBACrC,CAAC;gBAED,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;gBACnB,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;oBAC9D,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnD,CAAC;gBACD,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAyB,CAAC;AACvD,CAAC,CAAC;AAnCS,QAAA,gBAAgB,oBAmCzB"}
@@ -0,0 +1,24 @@
1
+ import { DeepStrictObjectKeys } from '../types/DeepStrictObjectKeys';
2
+ import { DeepStrictPick } from '../types/DeepStrictPick';
3
+ /**
4
+ * @title Runtime Function for Type-Safe Deep Property Picking.
5
+ *
6
+ * Takes an object and a dot-notation key path, and returns a new object
7
+ * containing only the specified nested property, preserving the original structure.
8
+ *
9
+ * This is the runtime counterpart of the {@link DeepStrictPick} type.
10
+ *
11
+ * @template T - The object type of the input
12
+ * @template K - The key path to pick
13
+ * @param input - The source object to extract properties from
14
+ * @param key - A dot-notation key path specifying which property to pick
15
+ * @returns A new object containing only the picked property with its original structure
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const result = deepStrictPick({ a: { b: 1, c: 2 } }, 'a.b');
20
+ * // result: { a: { b: 1 } }
21
+ * ```
22
+ */
23
+ export declare const deepStrictPick: <T extends object, K extends DeepStrictObjectKeys<T>>(input: T, key: K) => DeepStrictPick<T, K>;
24
+ //# sourceMappingURL=DeepStrictPick.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepStrictPick.d.ts","sourceRoot":"","sources":["../../../src/functions/DeepStrictPick.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,SACzE,CAAC,OACH,CAAC,KACL,cAAc,CAAC,CAAC,EAAE,CAAC,CAiCrB,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepStrictPick = void 0;
4
+ /**
5
+ * @title Runtime Function for Type-Safe Deep Property Picking.
6
+ *
7
+ * Takes an object and a dot-notation key path, and returns a new object
8
+ * containing only the specified nested property, preserving the original structure.
9
+ *
10
+ * This is the runtime counterpart of the {@link DeepStrictPick} type.
11
+ *
12
+ * @template T - The object type of the input
13
+ * @template K - The key path to pick
14
+ * @param input - The source object to extract properties from
15
+ * @param key - A dot-notation key path specifying which property to pick
16
+ * @returns A new object containing only the picked property with its original structure
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const result = deepStrictPick({ a: { b: 1, c: 2 } }, 'a.b');
21
+ * // result: { a: { b: 1 } }
22
+ * ```
23
+ */
24
+ const deepStrictPick = (input, key) => {
25
+ const keys = key.split(/(?:\[\*\])?\./g).filter(Boolean);
26
+ const traverse = (input, keys) => {
27
+ const [first, ...rest] = keys;
28
+ if (input instanceof Array) {
29
+ const elements = input.map((element) => {
30
+ if (first in element) {
31
+ if (typeof element[first] === 'object' && element[first] !== null && rest.length > 0) {
32
+ return { [first]: traverse(element[first], rest) };
33
+ }
34
+ return { [first]: element[first] };
35
+ }
36
+ return element;
37
+ });
38
+ return elements;
39
+ }
40
+ else {
41
+ if (first in input) {
42
+ if (typeof input[first] === 'object' && input[first] !== null && rest.length > 0) {
43
+ return { [first]: traverse(input[first], rest) };
44
+ }
45
+ return { [first]: input[first] };
46
+ }
47
+ throw new Error(`input doesn\'t has key: ${first}`);
48
+ }
49
+ };
50
+ return traverse(input, keys);
51
+ };
52
+ exports.deepStrictPick = deepStrictPick;
53
+ //# sourceMappingURL=DeepStrictPick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepStrictPick.js","sourceRoot":"","sources":["../../../src/functions/DeepStrictPick.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,cAAc,GAAG,CAC5B,KAAQ,EACR,GAAM,EACgB,EAAE;IACxB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEzD,MAAM,QAAQ,GAAG,CAAC,KAAkD,EAAE,IAAc,EAAO,EAAE;QAC3F,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QAE9B,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;gBACrC,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;oBACrB,IAAI,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACrF,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;oBACrD,CAAC;oBAED,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,CAAC;gBAED,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;gBACnB,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACjF,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnD,CAAC;gBACD,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAyB,CAAC;AACvD,CAAC,CAAC;AApCW,QAAA,cAAc,kBAoCzB"}
@@ -1,3 +1,4 @@
1
1
  export * from './DeepStrictAssert';
2
2
  export * from './DeepStrictObjectKeys';
3
+ export * from './DeepStrictPick';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC"}
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./DeepStrictAssert"), exports);
18
18
  __exportStar(require("./DeepStrictObjectKeys"), exports);
19
+ __exportStar(require("./DeepStrictPick"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,mDAAiC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakasoo/deep-strict-types",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "typescript utility types including deep-strict-omit and pick type",
5
5
  "private": false,
6
6
  "publishConfig": {