mnemonica 1.2.1 → 1.2.5
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/FOR_HUMANS.md +186 -138
- package/README.md +70 -249
- package/build/api/errors/exceptionConstructor.js +20 -47
- package/build/api/errors/throwModificationError.js +26 -61
- package/build/api/types/InstanceCreator.js +5 -1
- package/build/api/types/Props.js +24 -10
- package/build/api/types/index.js +18 -12
- package/build/types/index.d.ts +9 -4
- package/build/types/index.js +1 -1
- package/docs/UTILS.md +97 -8
- package/docs/async-constructors.md +2 -0
- package/docs/decorate.md +1 -1
- package/docs/empathy-in-ai.md +20 -10
- package/docs/prototype-chain.md +8 -7
- package/docs/typed-lookup.md +195 -5
- package/docs/typeomatica.md +8 -345
- package/package.json +6 -10
- package/src/api/errors/exceptionConstructor.ts +40 -83
- package/src/api/errors/throwModificationError.ts +64 -104
- package/src/api/types/InstanceCreator.ts +14 -0
- package/src/api/types/Props.ts +53 -18
- package/src/api/types/index.ts +33 -20
- package/src/types/index.ts +15 -5
- package/.ai/AGENTS.md +0 -151
- package/.ai/ARCHITECT.md +0 -110
- package/.ai/DEBUG.md +0 -178
- package/.ai/ONBOARDING.md +0 -189
- package/.ai/PROTOTYPE-CHAIN.md +0 -153
- package/.ai/mode-ask.md +0 -121
- package/.ai/mode-orchestrator.md +0 -141
- package/.ai/performance-vs-security.md +0 -395
- package/.ai/rules-async-constructors.md +0 -352
- package/.ai/rules-code-style.md +0 -95
- package/.ai/rules-coding.md +0 -246
- package/.ai/rules-context-condensing.md +0 -50
- package/.ai/rules-contributing.md +0 -227
- package/.ai/rules-define-patterns.md +0 -159
- package/.ai/rules-ecosystem.md +0 -140
- package/.ai/rules-error-system.md +0 -56
- package/.ai/rules-hooks.md +0 -46
- package/.ai/rules-instance-methods.md +0 -93
- package/.ai/rules-philosophy.md +0 -231
- package/.ai/rules-reminders.md +0 -19
- package/.ai/rules-testing.md +0 -66
- package/.ai/rules-type-system.md +0 -124
- package/.ai/theory-of-operations.md +0 -224
- package/AGENTS.md +0 -345
- package/CONTRIBUTING.md +0 -150
- package/SKILL.md +0 -114
- package/docs/ai-learning-trajectory.md +0 -141
- package/docs/purpose.md +0 -707
- package/docs/tactica-deep-dive.md +0 -629
- package/docs/tactica-pattern.md +0 -146
package/docs/tactica-pattern.md
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# How `lookup` works (and where tactica fits)
|
|
2
|
-
|
|
3
|
-
> The runtime Trie that mnemonica builds is invisible to TypeScript by default. The fix is one TypeScript-level pattern: declaration-merge mnemonica's `TypeRegistry` interface so that `lookup(path)` resolves to a fully-typed constructor. The augmentation can be hand-written or generated by [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica). The runtime behaviour is identical either way.
|
|
4
|
-
>
|
|
5
|
-
> For a side-by-side recipe of both paths, see [`./typed-lookup.md`](./typed-lookup.md).
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## The problem in one sentence
|
|
10
|
-
|
|
11
|
-
mnemonica builds a Trie of constructors at runtime. TypeScript has no idea the Trie exists. `lookup` + an augmented `TypeRegistry` tells TypeScript.
|
|
12
|
-
|
|
13
|
-
Without that bridge, every chain operation requires a cast.
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## What goes wrong without the bridge
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { RequestData } from './collections/requestTypes.js';
|
|
21
|
-
|
|
22
|
-
const requestData = new RequestData({ method: 'GET', url: '/' });
|
|
23
|
-
const routeData = new requestData.RouteData({ pagePath: '/' });
|
|
24
|
-
// Error: Property 'RouteData' does not exist on type 'RequestData'
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
TypeScript rejects valid runtime code. You are forced to write:
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
const routeData = new (requestData as any).RouteData({ ... });
|
|
31
|
-
// or worse:
|
|
32
|
-
const routeData = new requestData.RouteData({ ... }) as unknown as RouteDataT;
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
This is not type safety. This is type suppression.
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## What the bridge looks like
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { lookup } from 'mnemonica';
|
|
43
|
-
|
|
44
|
-
const RequestData = lookup('RequestData');
|
|
45
|
-
|
|
46
|
-
const requestData = new RequestData({ method: 'GET', url: '/' });
|
|
47
|
-
const routeData = new requestData.RouteData({ pagePath: '/' });
|
|
48
|
-
const pageData = new routeData.PageData({ header: {...}, content: '' });
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Zero casts. Zero `any`. Zero `unknown`. TypeScript knows every property, every constructor, every link in the chain.
|
|
52
|
-
|
|
53
|
-
For this to work, mnemonica's `TypeRegistry` interface needs to be augmented with your types via TypeScript declaration merging.
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## Two ways to produce the augmentation
|
|
58
|
-
|
|
59
|
-
### By hand
|
|
60
|
-
|
|
61
|
-
For small projects or for learning, you can write the augmentation directly in a `.d.ts` (or `.ts`) file:
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
// types/mnemonica-registry.d.ts
|
|
65
|
-
import type { ProtoFlat } from 'mnemonica';
|
|
66
|
-
|
|
67
|
-
export type RequestDataInstance = {
|
|
68
|
-
method : string;
|
|
69
|
-
url : string;
|
|
70
|
-
RouteData : new (data: { pagePath: string }) => RouteDataInstance;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export type RouteDataInstance = ProtoFlat<RequestDataInstance, {
|
|
74
|
-
pagePath : string;
|
|
75
|
-
PageData : new (data: { header: object; content: string }) => PageDataInstance;
|
|
76
|
-
RouteData : undefined;
|
|
77
|
-
}>;
|
|
78
|
-
|
|
79
|
-
declare module 'mnemonica' {
|
|
80
|
-
interface TypeRegistry {
|
|
81
|
-
'RequestData' : new (data: { method: string; url: string }) => RequestDataInstance;
|
|
82
|
-
'RequestData.RouteData' : new (data: { pagePath: string }) => RouteDataInstance;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Include the file in `tsconfig.json` `include`. You are done.
|
|
88
|
-
|
|
89
|
-
### Via tactica
|
|
90
|
-
|
|
91
|
-
For projects with many types or for hands-off maintenance, install [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica) and run it as a CLI/codegen utility. It scans your `define()` calls and generates the augmentation:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
npm install --save-dev @mnemonica/tactica
|
|
95
|
-
npx tactica --output ./.tactica --include "src/**/*.ts"
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Include the generated files in `tsconfig.json`:
|
|
99
|
-
|
|
100
|
-
```json
|
|
101
|
-
{
|
|
102
|
-
"include": ["src/**/*.ts", ".tactica/**/*.ts"]
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Tactica writes the same shape of augmentation a careful human would, using `ProtoFlat<Parent, ...>` for nested types and filling in instance-level subtype constructors automatically. The runtime is unaffected. Re-run the CLI whenever your type graph changes, or wire it into your build script.
|
|
107
|
-
|
|
108
|
-
See [`./typed-lookup.md`](./typed-lookup.md) for a side-by-side recipe with both paths.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## The runtime is identical
|
|
113
|
-
|
|
114
|
-
`lookup('RequestData')` and `import { RequestData }` return the **same constructor object** at runtime. The only difference is what TypeScript sees at compile time:
|
|
115
|
-
|
|
116
|
-
| Approach | Runtime | Compile-time |
|
|
117
|
-
|---|---|---|
|
|
118
|
-
| Direct import without augmentation | ✅ Constructor works | ❌ TypeScript blind to sub-types |
|
|
119
|
-
| `lookup` with augmentation (manual) | ✅ Same constructor | ✅ TypeScript knows the Trie |
|
|
120
|
-
| `lookup` with augmentation (tactica) | ✅ Same constructor | ✅ TypeScript knows the Trie |
|
|
121
|
-
|
|
122
|
-
There is no runtime cost. There is no indirection. There is only **type safety, conditional on the augmentation being present**.
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
## The rule
|
|
127
|
-
|
|
128
|
-
The anti-patterns are the same whether you augment by hand or via tactica:
|
|
129
|
-
|
|
130
|
-
- Do not write `as unknown as` casts on mnemonica types.
|
|
131
|
-
- Do not import constructors directly from collection files when `lookup` would work.
|
|
132
|
-
- Do not accept "it compiles with casts" as good enough.
|
|
133
|
-
|
|
134
|
-
What changes is how you keep the `TypeRegistry` augmentation in sync with your code:
|
|
135
|
-
|
|
136
|
-
- **Hand-written:** edit the `.d.ts` when types change.
|
|
137
|
-
- **Tactica:** the CLI/codegen utility keeps `.tactica/` in sync.
|
|
138
|
-
|
|
139
|
-
Pick whichever fits your project. Both are first-class.
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
## Learn more
|
|
144
|
-
|
|
145
|
-
- [`./typed-lookup.md`](./typed-lookup.md) — `lookup` with or without tactica (canonical side-by-side reference)
|
|
146
|
-
- [`./tactica-deep-dive.md`](./tactica-deep-dive.md) — comprehensive technical guide, declaration-merging deep dive, anti-patterns and "when to insist on what"
|