mnemonica 1.0.1 → 1.0.6

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 (89) hide show
  1. package/.ai/ONBOARDING.md +1 -1
  2. package/.ai/ask/AGENTS.md +15 -9
  3. package/.ai/rules-skill/contributing.md +1 -1
  4. package/.ai/rules-skill/define-patterns.md +8 -2
  5. package/.ai/rules-skill/ecosystem.md +4 -4
  6. package/.ai/rules-skill/instance-methods.md +48 -15
  7. package/.ai/rules-skill/type-system.md +12 -2
  8. package/AGENTS.md +6 -2
  9. package/CONTRIBUTING.md +7 -1
  10. package/FOR_HUMANS.md +143 -199
  11. package/README.md +74 -39
  12. package/build/api/errors/exceptionConstructor.js +20 -12
  13. package/build/api/errors/index.js +9 -5
  14. package/build/api/errors/throwModificationError.js +15 -9
  15. package/build/api/index.js +35 -2
  16. package/build/api/types/InstanceCreator.js +5 -2
  17. package/build/api/types/Mnemosyne.d.ts +6 -6
  18. package/build/api/types/Mnemosyne.js +43 -120
  19. package/build/api/types/Props.js +5 -3
  20. package/build/api/types/TypeProxy.js +13 -9
  21. package/build/api/types/compileNewModificatorFunctionBody.js +14 -8
  22. package/build/api/types/index.js +56 -13
  23. package/build/api/utils/index.js +21 -12
  24. package/build/constants/index.js +11 -8
  25. package/build/descriptors/types/index.js +79 -26
  26. package/build/index.d.ts +4 -4
  27. package/build/index.js +62 -15
  28. package/build/types/index.d.ts +52 -31
  29. package/build/types/index.js +1 -1
  30. package/build/utils/clone.d.ts +1 -0
  31. package/build/utils/clone.js +11 -0
  32. package/build/utils/collectConstructors.js +5 -3
  33. package/build/utils/exception.d.ts +1 -0
  34. package/build/utils/exception.js +14 -0
  35. package/build/utils/extract.d.ts +2 -3
  36. package/build/utils/extract.js +3 -2
  37. package/build/utils/fork.d.ts +1 -0
  38. package/build/utils/fork.js +33 -0
  39. package/build/utils/index.d.ts +2 -3
  40. package/build/utils/index.js +21 -7
  41. package/build/utils/merge.d.ts +2 -1
  42. package/build/utils/merge.js +10 -6
  43. package/build/utils/parent.d.ts +1 -1
  44. package/build/utils/parent.js +3 -2
  45. package/build/utils/parse.d.ts +2 -12
  46. package/build/utils/parse.js +1 -1
  47. package/build/utils/pick.d.ts +4 -3
  48. package/build/utils/pick.js +4 -5
  49. package/build/utils/sibling.d.ts +1 -0
  50. package/build/utils/sibling.js +25 -0
  51. package/build/utils/toJSON.d.ts +1 -1
  52. package/build/utils/toJSON.js +3 -2
  53. package/docs/UTILS.md +184 -0
  54. package/docs/ai-learning-trajectory.md +1 -1
  55. package/docs/async-constructors.md +3 -1
  56. package/docs/empathy-in-ai.md +170 -0
  57. package/docs/hott-primer.md +47 -0
  58. package/docs/performance-vs-security.md +2 -2
  59. package/docs/purpose.md +38 -7
  60. package/docs/tactica-pattern.md +10 -10
  61. package/docs/theory-of-operations.md +224 -0
  62. package/docs/typed-lookup.md +12 -12
  63. package/package.json +12 -7
  64. package/src/api/errors/exceptionConstructor.ts +14 -9
  65. package/src/api/errors/index.ts +8 -4
  66. package/src/api/errors/throwModificationError.ts +10 -9
  67. package/src/api/types/InstanceCreator.ts +5 -8
  68. package/src/api/types/Mnemosyne.ts +72 -231
  69. package/src/api/types/Props.ts +4 -2
  70. package/src/api/types/TypeProxy.ts +7 -11
  71. package/src/api/types/compileNewModificatorFunctionBody.ts +13 -7
  72. package/src/api/types/index.ts +15 -8
  73. package/src/api/utils/index.ts +16 -14
  74. package/src/constants/index.ts +6 -9
  75. package/src/descriptors/types/index.ts +44 -24
  76. package/src/index.ts +28 -21
  77. package/src/types/index.ts +101 -69
  78. package/src/utils/clone.ts +11 -0
  79. package/src/utils/collectConstructors.ts +4 -2
  80. package/src/utils/exception.ts +16 -0
  81. package/src/utils/extract.ts +5 -2
  82. package/src/utils/fork.ts +57 -0
  83. package/src/utils/index.ts +32 -13
  84. package/src/utils/merge.ts +18 -6
  85. package/src/utils/parent.ts +4 -6
  86. package/src/utils/parse.ts +5 -4
  87. package/src/utils/pick.ts +10 -2
  88. package/src/utils/sibling.ts +33 -0
  89. package/src/utils/toJSON.ts +3 -2
package/FOR_HUMANS.md CHANGED
@@ -323,17 +323,14 @@ console.log(subInstance.some); // 'arguments' (inherited)
323
323
  console.log(subInstance.other); // 'data needed' (own)
324
324
  ```
325
325
 
326
- ### The `.extract()` Method
326
+ ### The `utils.extract()` Utility
327
327
 
328
328
  Extract all inherited properties into a flat object:
329
329
 
330
330
  ```js
331
- const extracted = subInstance.extract();
332
- // Result: { data, description, other, some }
333
-
334
- // Or use the standalone utility
335
331
  const { utils: { extract } } = require('mnemonica');
336
- const extracted2 = extract(subInstance);
332
+ const extracted = extract(subInstance);
333
+ // Result: { data, description, other, some }
337
334
  ```
338
335
 
339
336
  ---
@@ -444,54 +441,21 @@ const subInstance = call(someInstance, SomeSubType, 'arg1', 'arg2');
444
441
 
445
442
  ### Exported Type Definitions
446
443
 
447
- The following types are available for advanced TypeScript usage:
444
+ The most commonly used types for TypeScript projects:
448
445
 
449
446
  ```typescript
450
447
  import {
451
- // Core constructor types
452
- IDEF, // Base constructor function type: { new(): T } | { (this: T, ...args): void }
453
- ConstructorFunction, // Constructor with prototype
454
- Constructor, // Generic constructor type
455
-
456
- // Instance types
457
- MnemonicaInstance, // Instance methods interface (extract, pick, parent, fork, etc.)
458
- Props, // Internal instance properties (__type__, __args__, __parent__, etc.)
459
- SiblingAccessor, // Sibling type accessor type
460
-
461
- // Type definition types
462
- TypeClass, // Base type constructor returned by define()
463
- IDefinitorInstance, // Definitor instance with define/lookup methods and subtypes
464
- DecoratedClass, // Type for @decorate decorated classes
465
- TypeDef, // Type definition object structure
466
-
467
- // Configuration types
468
- constructorOptions, // Type config options (strictChain, blockErrors, etc.)
469
- hooksTypes, // 'preCreation' | 'postCreation' | 'creationError'
470
- hook, // Hook callback type
471
- hooksOpts, // Hook options passed to callbacks
472
- CollectionDef, // Types collection definition
473
-
474
- // Utility function types
475
- ApplyFunction, // apply(entity, Ctor, args) => S
476
- CallFunction, // call(entity, Ctor, ...args) => S
477
- BindFunction, // bind(entity, Ctor) => (...args) => S
478
-
479
- // createTypesCollection types — use only when you need isolation
480
- CreateTypesCollectionFunction, // (config?: constructorOptions) => TypesCollection
481
- TypesCollection, // Interface returned by createTypesCollection
482
-
483
- // Configuration helper types
484
- HideInstanceMethodsOptions, // constructorOptions & { exposeInstanceMethods: true }
485
- IsHidingMethods<Config>, // Conditional type for exposeInstanceMethods: false detection
486
-
487
- // Utility types
488
- Proto<P, T>, // Merges parent P and child T types
489
- SN, // String-Name map for nested constructors
490
- SubtypesMap, // Map<string, TypeClass>
491
- TypeAbsorber, // Main define() function interface with overloads
448
+ IDEF, // Base constructor function type
449
+ MnemonicaInstance, // Instance methods interface (extract, pick, parent, fork, etc.)
450
+ constructorOptions, // Type config options (strictChain, blockErrors, etc.)
451
+ hooksTypes, // 'preCreation' | 'postCreation' | 'creationError'
452
+ hook, // Hook callback type
453
+ TypeClass, // Base type constructor returned by define()
492
454
  } from 'mnemonica';
493
455
  ```
494
456
 
457
+ Additional types available: `Constructor`, `Props`, `SiblingAccessor`, `IDefinitorInstance`, `DecoratedClass`, `TypeDef`, `CollectionDef`, `hooksOpts`, `ApplyFunction`, `CallFunction`, `BindFunction`, `CreateTypesCollectionFunction`, `TypesCollection`, `HideInstanceMethodsOptions`, `IsHidingMethods`, `Proto`, `SubtypesMap`, `TypeAbsorber`. See [`src/types/index.ts`](./src/types/index.ts) for full definitions.
458
+
495
459
  ### Generic Type Patterns
496
460
 
497
461
  Define types with proper generic constraints for full type safety:
@@ -538,6 +502,19 @@ const AsyncTypeNoReturn = define('AsyncType', async function () {
538
502
 
539
503
  ## API Reference
540
504
 
505
+ **Quick reference:**
506
+
507
+ | I want to... | Use |
508
+ |---|---|
509
+ | Define a type | `define('Name', ctor)` |
510
+ | Create from instance | `new instance.SubType(args)` |
511
+ | Look up a type | `lookup('Name')` or `lookupTyped('Name')` |
512
+ | Read construction history | `getProps(instance)` |
513
+ | Get parent instance | `utils.parent(instance)` or `utils.parent(instance, 'TypeName')` |
514
+ | Flatten to plain object | `utils.extract(instance)` |
515
+ | Add lifecycle hooks | `type.registerHook('postCreation', cb)` |
516
+ | Use classes | `@decorate()` decorator |
517
+
541
518
  ### Core Functions
542
519
 
543
520
  #### `define(typeName, constructHandler, config?)`
@@ -623,24 +600,16 @@ const subInstance = createSub('arg1', 'arg2');
623
600
 
624
601
  TypeScript decorator for class-based definitions.
625
602
 
626
- **Usage Patterns:**
627
-
628
603
  ```typescript
629
604
  import { decorate } from 'mnemonica';
630
605
 
631
- // 1. Basic decoration
606
+ // Basic decoration
632
607
  @decorate()
633
608
  class MyClass {
634
609
  field: number = 123;
635
610
  }
636
611
 
637
- // 2. With configuration
638
- @decorate({ strictChain: false, blockErrors: true })
639
- class ConfiguredClass {
640
- field: number = 123;
641
- }
642
-
643
- // 3. Nested decoration (define as subtype)
612
+ // Nested decoration (define as subtype)
644
613
  @decorate()
645
614
  class ParentClass {
646
615
  parentField: string = 'parent';
@@ -654,30 +623,23 @@ class ChildClass {
654
623
  // Create parent instance, then child from it
655
624
  const parent = new ParentClass();
656
625
  const child = new parent.ChildClass();
626
+ ```
657
627
 
658
- // 4. Parent with configuration
659
- @decorate(ParentClass, { strictChain: false })
660
- class ConfiguredChildClass {
661
- field: number = 123;
662
- }
628
+ **With configuration:**
663
629
 
664
- // 5. Using decorated class as decorator (advanced)
665
- // After a class is decorated with @decorate(), it can be used
666
- // as a decorator for nested types
667
- @decorate()
668
- class BaseDecorator {
669
- baseField: number = 100;
630
+ ```typescript
631
+ @decorate({ strictChain: false, blockErrors: true })
632
+ class ConfiguredClass {
633
+ field: number = 123;
670
634
  }
671
635
 
672
- // Use BaseDecorator as a decorator
673
- // @ts-ignore - TypeScript limitation with callable class types
674
- @BaseDecorator()
675
- class ExtendedClass {
676
- extField: number = 200;
636
+ @decorate(ParentClass, { strictChain: false })
637
+ class ConfiguredChildClass {
638
+ field: number = 123;
677
639
  }
678
640
  ```
679
641
 
680
- **Note:** When using decorated classes as decorators (pattern 5), TypeScript may require `@ts-ignore` due to type checking limitations with callable class types.
642
+ **Note:** After a class is decorated with `@decorate()`, it can be used as a decorator for nested types (advanced pattern; may require `@ts-ignore` due to TypeScript limitations with callable class types).
681
643
 
682
644
  #### `registerHook(Constructor, hookType, callback)`
683
645
 
@@ -700,7 +662,7 @@ For advanced TypeScript usage, the following types are exported from `mnemonica`
700
662
  | Type | Description | Usage |
701
663
  |------|-------------|-------|
702
664
  | `IDEF<T>` | Base constructor function type | `define('Name', fn: IDEF<MyType>)` |
703
- | `MnemonicaInstance` | Instance methods interface | `instance.extract()`, `instance.pick()` |
665
+ | `MnemonicaInstance` | Optional helper interface | Can be used when attaching the legacy instance methods to your own prototype |
704
666
  | `TypeClass` | Base type constructor | `const MyType: TypeClass = define(...)` |
705
667
  | `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` |
706
668
  | `IDefinitorInstance<N, S>` | Constructor with subtypes | Returned by `define()` with `.define()` method |
@@ -759,12 +721,6 @@ const MyType = myCollection.define('MyType', function () {});
759
721
  const FoundType = myCollection.lookup('MyType');
760
722
  ```
761
723
 
762
- ```js
763
- const { createTypesCollection } = require('mnemonica');
764
- const myCollection = createTypesCollection();
765
- const MyType = myCollection.define('MyType', function () {});
766
- ```
767
-
768
724
  **`TypesCollection` Interface:**
769
725
 
770
726
  `createTypesCollection()` returns a `TypesCollection` object with the following interface:
@@ -802,8 +758,7 @@ const { createTypesCollection } = require('mnemonica');
802
758
  // Create isolated collection with custom config
803
759
  const myCollection = createTypesCollection({
804
760
  strictChain: false,
805
- blockErrors: false,
806
- exposeInstanceMethods: false // Hide instance methods for cleaner API
761
+ blockErrors: false
807
762
  });
808
763
 
809
764
  // Define types in isolation
@@ -838,80 +793,106 @@ setProps(instance, { __timestamp__: Date.now() });
838
793
 
839
794
  ### Instance Methods
840
795
 
841
- All mnemonica instances have the following methods:
796
+ Starting from v1.0.6 these convenience methods are **no longer auto-injected** on instances. Use the standalone utilities from `utils`:
842
797
 
843
- > **Note:** You can disable instance methods by setting `exposeInstanceMethods: false` in the type configuration. When disabled, these methods are still accessible via `getProps(instance).__self__` or the standalone `utils` export.
798
+ ```js
799
+ const { utils } = require('mnemonica');
844
800
 
845
- #### `.extract()`
801
+ utils.extract(instance);
802
+ utils.pick(instance, 'key');
803
+ utils.parent(instance, 'ParentType');
804
+ utils.fork(instance)(newArgs);
805
+ utils.exception(instance, error);
806
+ utils.sibling(instance);
807
+ utils.clone(instance);
808
+ ```
846
809
 
847
- Extracts all inherited properties into a single flat object.
810
+ To restore the old instance-method style for a specific root constructor, attach the methods to its prototype **before** passing it to `define()`. See `test/instance-methods-helper.js` for a complete reference pattern.
848
811
 
849
- ```js
850
- const extracted = instance.extract();
812
+ #### `utils.extract(instance)`
813
+
814
+ Extracts all enumerable user properties into a single flat object. TypeScript
815
+ returns `Extracted<T>` — legacy instance-method names are filtered out and
816
+ optionality is preserved from the source type.
817
+
818
+ ```ts
819
+ const extracted = utils.extract(instance);
820
+ // hover: { name: string; email: string; age: number; }
851
821
  ```
852
822
 
853
- #### `.pick(...keys)` / `.pick([keys])`
823
+ #### `utils.pick(instance, ...keys)` / `utils.pick(instance, [keys])`
854
824
 
855
- Picks specific properties from the instance and its inheritance chain.
825
+ Picks specific properties from the instance and its inheritance chain. Literal
826
+ keys produce a typed subset; dynamic or unknown keys fall back to
827
+ `Record<string, unknown>`.
856
828
 
857
- ```js
858
- const picked = instance.pick('email', 'password');
859
- // or
860
- const picked = instance.pick(['email', 'password']);
829
+ ```ts
830
+ const picked = utils.pick(instance, 'email', 'password');
831
+ // hover: { email: string; password: string; }
832
+
833
+ const pickedArray = utils.pick(instance, ['email', 'password']);
861
834
  ```
862
835
 
863
- #### `.parent(constructorName?)`
836
+ #### `utils.parent(instance, constructorName?)`
864
837
 
865
838
  Gets the parent instance. If `constructorName` is provided, walks up the chain.
839
+ The structural return type is `object | undefined`; a specific nominal parent
840
+ type requires a `TypeRegistry` augmentation (see [`docs/typed-lookup.md`](./docs/typed-lookup.md)).
866
841
 
867
- ```js
868
- const immediateParent = instance.parent();
869
- const specificParent = instance.parent('UserType');
842
+ ```ts
843
+ const immediateParent = utils.parent(instance);
844
+ const specificParent = utils.parent(instance, 'UserType'); // object | undefined
870
845
  ```
871
846
 
872
- #### `.clone`
847
+ #### `utils.clone(instance)`
873
848
 
874
- Property that returns a cloned instance (same parent, same args).
849
+ Returns a cloned instance (same parent, same args). The return type is the
850
+ instance type.
875
851
 
876
- ```js
877
- const cloned = instance.clone;
878
- // Note: For async constructors, use: await instance.clone
852
+ ```ts
853
+ const cloned = utils.clone(instance);
854
+ // Note: For async constructors, use: await utils.clone(instance)
879
855
  ```
880
856
 
881
- #### `.fork(...args)`
857
+ #### `utils.fork(instance)`
882
858
 
883
- Creates a forked instance from the same parent with optional new arguments.
859
+ Returns a fork constructor for the instance. Call it with optional new
860
+ arguments to create a forked instance from the same parent.
884
861
 
885
- ```js
886
- const forked = instance.fork(); // same args
887
- const forkedWithNewArgs = instance.fork('new', 'args');
888
- // Note: For async constructors, use: await instance.fork(...)
862
+ ```ts
863
+ const forkFn = utils.fork(instance);
864
+ const forked = forkFn(); // same args
865
+ const forkedWithNewArgs = forkFn('new', 'args');
866
+ // Note: For async constructors, use: await forkFn(...)
889
867
  ```
890
868
 
891
- #### `.fork.call(thisArg, ...args)` / `.fork.apply(thisArg, args)`
869
+ #### `utils.fork(instance).call(thisArg, ...args)` / `.apply(thisArg, args)`
892
870
 
893
871
  Forks with a different `this` context (useful for Directed Acyclic Graphs).
894
872
 
895
- ```js
896
- const dagInstance = instanceA.fork.call(instanceB, 'args');
873
+ ```ts
874
+ const forkFn = utils.fork(instanceA);
875
+ const dagInstance = forkFn.call(instanceB, 'args');
897
876
  ```
898
877
 
899
- #### `.exception(error, ...args)`
878
+ #### `utils.exception(instance, error, ...args)`
900
879
 
901
- Creates an exception instance from the current instance.
880
+ Creates an exception instance from the given instance.
902
881
 
903
- ```js
904
- const error = someInstance.exception(new Error('Something went wrong'));
882
+ ```ts
883
+ const error = utils.exception(someInstance, new Error('Something went wrong'));
905
884
  throw error;
906
885
  ```
907
886
 
908
- #### `.sibling(typeName)` / `.sibling.TypeName`
887
+ #### `utils.sibling(instance)`
909
888
 
910
- Access sibling types from the same collection.
889
+ Access sibling types from the same collection. Returns a callable/proxy object
890
+ that resolves to `TypeClass | undefined`.
911
891
 
912
- ```js
913
- const siblingType = instance.sibling('OtherType');
914
- const sibling = instance.sibling.OtherType;
892
+ ```ts
893
+ const siblingAccessor = utils.sibling(instance);
894
+ const siblingType = siblingAccessor('OtherType');
895
+ const sibling = siblingAccessor.OtherType;
915
896
  ```
916
897
 
917
898
  ---
@@ -930,7 +911,7 @@ All instances have non-enumerable internal properties:
930
911
  | `.__stack__` | `string` | Stack trace (if `submitStack: true` in config) |
931
912
  | `.__creator__` | `InstanceCreatorContext` | Instance creator reference |
932
913
  | `.__timestamp__` | `number` | Creation timestamp (ms since epoch) |
933
- | `.__self__` | `object` | Self reference to the instance (useful when `exposeInstanceMethods: false`) |
914
+ | `.__self__` | `object` | Self reference to the instance |
934
915
 
935
916
  ---
936
917
 
@@ -938,54 +919,28 @@ All instances have non-enumerable internal properties:
938
919
 
939
920
  Access via `utils` export:
940
921
 
941
- ```js
922
+ ```ts
942
923
  const { utils } = require('mnemonica');
943
924
  ```
944
925
 
945
- #### `utils.extract(instance)`
946
- Standalone extract function.
947
-
948
- #### `utils.pick(instance, ...keys)`
949
- Standalone pick function.
950
-
951
- #### `utils.parent(instance, constructorName?)`
952
- Standalone parent function.
953
-
954
- #### `utils.parse(instance)`
955
- Parses an instance structure, returning:
956
- - `name`: constructor name
957
- - `props`: extracted properties
958
- - `self`: the instance itself
959
- - `proto`: prototype object
960
- - `joint`: prototype properties
961
- - `parent`: parent prototype
926
+ All utilities infer their type parameter from the instance argument; no
927
+ explicit `<T>` cast is required for ordinary use.
962
928
 
963
- ```js
964
- const { utils: { parse } } = require('mnemonica');
965
- const parsed = parse(instance);
966
- ```
967
-
968
- #### `utils.merge(A, B, ...args)`
969
- Merges two instances using fork semantics.
970
-
971
- ```js
972
- const merged = utils.merge(instanceA, instanceB, 'args');
973
- // Note: For async constructors, use: await utils.merge(...)
974
- ```
975
-
976
- #### `utils.toJSON(instance)`
977
- Serializes an instance to JSON.
978
-
979
- ```js
980
- const json = utils.toJSON(instance);
981
- ```
982
-
983
- #### `utils.collectConstructors(instance, flat?)`
984
- Collects all constructors in the instance's prototype chain.
985
-
986
- ```js
987
- const constructors = utils.collectConstructors(instance, true);
988
- ```
929
+ | Utility | Inferred return type |
930
+ |---|---|
931
+ | `utils.extract(instance)` | `Extracted<T>` — plain user-field object |
932
+ | `utils.pick(instance, 'a', 'b')` | `{ a: T['a'], b: T['b'] }` |
933
+ | `utils.clone(instance)` | `T` |
934
+ | `utils.fork(instance)` | `(this: object, ...args: unknown[]) => T` |
935
+ | `utils.parent(instance, path?)` | `object \| undefined` |
936
+ | `utils.sibling(instance)` | `SiblingAccessor` |
937
+ | `utils.merge(A, B, ...args)` | `InstanceResult<Merge<B, A>, constructorOptions>` |
938
+ | `utils.parse(instance)` | `Parsed<T>` |
939
+ | `utils.toJSON(instance)` | `string` |
940
+ | `utils.collectConstructors(instance, flat?)` | `(CallableFunction \| string)[]` |
941
+
942
+ For the full type-level explanation, helper types, and examples, see
943
+ [`docs/UTILS.md`](./docs/UTILS.md).
989
944
 
990
945
  ---
991
946
 
@@ -1079,10 +1034,11 @@ errors.WRONG_STACK_CLEANER
1079
1034
 
1080
1035
  #### Exception Instances
1081
1036
 
1082
- When creating exceptions using `instance.exception()`:
1037
+ When creating exceptions using `utils.exception()`:
1083
1038
 
1084
1039
  ```js
1085
- const error = instance.exception(new Error('Original error'));
1040
+ const { utils } = require('mnemonica');
1041
+ const error = utils.exception(instance, new Error('Original error'));
1086
1042
 
1087
1043
  // Properties:
1088
1044
  error.originalError // The original error
@@ -1129,8 +1085,7 @@ define('SomeType', function () {}, {
1129
1085
  submitStack: false, // Collect stack trace as __stack__ property
1130
1086
  awaitReturn: true, // Ensure await new Constructor() returns value
1131
1087
  ModificationConstructor: fn, // Custom modification constructor
1132
- asClass: false, // Force class mode (auto-detected by default)
1133
- exposeInstanceMethods: true // Expose instance methods (default: true for backward compatibility)
1088
+ asClass: false // Force class mode (auto-detected by default)
1134
1089
  });
1135
1090
  ```
1136
1091
 
@@ -1143,39 +1098,27 @@ define('SomeType', function () {}, {
1143
1098
  | `submitStack` | `boolean` | `false` | If `true`, collects stack trace and stores as `__stack__` property on instances. |
1144
1099
  | `awaitReturn` | `boolean` | `true` | For async constructors, ensures `await new Constructor()` returns the instance. |
1145
1100
  | `asClass` | `boolean` | `auto` | Force class mode detection. Usually auto-detected from constructor syntax. |
1146
- | `exposeInstanceMethods` | `boolean` | `true` | Expose instance methods on the instance. Set to `false` to hide from TypeScript types. See details below. |
1147
1101
  | `ModificationConstructor` | `Function` | - | Custom constructor function for internal instance modification. |
1148
1102
 
1149
- ### `exposeInstanceMethods` Option
1103
+ ### Instance Method Opt-In
1150
1104
 
1151
- Controls whether instance methods (`extract()`, `pick()`, `parent()`, `clone`, `fork()`, `exception()`, `sibling()`) are exposed on the instance type.
1152
-
1153
- | Value | Behavior |
1154
- |-------|----------|
1155
- | `true` (default) | All instance methods are available directly on instances |
1156
- | `false` | Methods are hidden from TypeScript types but still accessible via prototype chain |
1157
-
1158
- **Use Case:** Set to `false` when you want a cleaner public API and don't want internal mnemonica methods cluttering autocomplete/IntelliSense.
1105
+ Starting from v1.0.6 instance methods are **not** exposed on instances by default. Use the standalone `utils` export or attach the methods to your constructor's prototype before calling `define()`:
1159
1106
 
1160
1107
  ```typescript
1161
- import { define, getProps, utils } from 'mnemonica';
1162
-
1163
- // With exposeInstanceMethods: false
1164
- const CleanType = define('CleanType', function (data) {
1165
- Object.assign(this, data);
1166
- }, { exposeInstanceMethods: false });
1167
-
1168
- const instance = new CleanType({ value: 42 });
1108
+ import { define, utils } from 'mnemonica';
1169
1109
 
1170
- // Methods not available directly on instance (TypeScript error)
1171
- // instance.extract(); // Error!
1110
+ // Preferred: standalone utilities
1111
+ const instance = new MyType({ value: 42 });
1112
+ utils.extract(instance);
1172
1113
 
1173
- // But still accessible via getProps
1174
- const props = getProps(instance);
1175
- props.__self__.extract(); // Works!
1176
-
1177
- // Or using utils
1178
- utils.extract(instance); // Works!
1114
+ // Legacy opt-in: attach methods to the constructor prototype before define()
1115
+ function MyType(data) {
1116
+ Object.assign(this, data);
1117
+ }
1118
+ Object.defineProperty(MyType.prototype, 'extract', {
1119
+ get() { return () => utils.extract(this); }
1120
+ });
1121
+ const MyTypeWithMethods = define('MyType', MyType);
1179
1122
  ```
1180
1123
 
1181
1124
  ### Override Default Config for Collection
@@ -1299,7 +1242,8 @@ const usingReactAsProto = ReactDOOMed.call(ReactDOM);
1299
1242
 
1300
1243
  ```js
1301
1244
  // Fork from different parent
1302
- const dagInstance = instanceA.fork.call(instanceB, 'args');
1245
+ const { utils: { fork } } = require('mnemonica');
1246
+ const dagInstance = fork(instanceA).call(instanceB, 'args');
1303
1247
 
1304
1248
  // Or use merge utility
1305
1249
  const { utils: { merge } } = require('mnemonica');