ts-util-core 2.0.1 → 2.0.2

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 +89 -26
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,56 +1,107 @@
1
1
  <p align="center">
2
- <img src="docs/banner.svg" alt="TS-Util — Type-safe form validation, AJAX, messaging, and view management" width="100%" />
2
+ <img src="https://raw.githubusercontent.com/MattAtAIEra/TS-Util/main/docs/banner.svg" alt="TS-Util — Agent Discipline for Humans and AI" width="100%" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <strong>The form infrastructure toolkit for enterprise web apps.</strong><br/>
7
- Drop jQuery. Keep the patterns. Ship with confidence.
6
+ <strong>One pipeline. Same guardrails. Whether it's your team or your AI Agents writing the code.</strong>
8
7
  </p>
9
8
 
10
9
  <p align="center">
10
+ <a href="#1-why-agent-discipline">Why</a>&ensp;&bull;&ensp;
11
+ <a href="#2-how-it-works">How</a>&ensp;&bull;&ensp;
12
+ <a href="#3-advantages">Advantages</a>&ensp;&bull;&ensp;
11
13
  <a href="#quick-start">Quick Start</a>&ensp;&bull;&ensp;
12
14
  <a href="#live-demo">Live Demo</a>&ensp;&bull;&ensp;
13
15
  <a href="#modules">Modules</a>&ensp;&bull;&ensp;
14
- <a href="#api-reference">API Reference</a>&ensp;&bull;&ensp;
15
- <a href="https://github.com/MattAtAIEra/TS-Util/blob/main/docs/good-design-pattern-implementation-after.md">Design Patterns</a>
16
+ <a href="#api-reference">API</a>
16
17
  </p>
17
18
 
18
19
  ---
19
20
 
20
- ## Why TS-Util?
21
+ ## 1. Why Agent Discipline?
21
22
 
22
- | Pain point | How this library solves it |
23
+ You don't have a code quality problem. You have a **consistency problem.**
24
+
25
+ Ten engineers write ten different AJAX calls. Ten AI Agents generate ten different fetch patterns. Some validate forms, some don't. Some show loading overlays, some forget. Some handle errors gracefully, some swallow them silently.
26
+
27
+ Code review catches some of it. **Architecture catches all of it.**
28
+
29
+ | The real problem | What actually happens |
23
30
  |---|---|
24
- | **"Our forms need validation, masking, AJAX, dialogs that's 4 libraries."** | One import. Six modules. Zero dependencies. |
25
- | **"Dynamic content loaded via AJAX has no validation."** | `VIEW.load()` auto-initializes constraints and formatters on every fragment. |
26
- | **"Adding a custom input format means touching library internals."** | `Formatter.add({ key, format })` register from the outside, never fork. |
27
- | **"Runtime surprises: wrong callback shape, misspelled event name."** | Every event, callback, and option is type-checked at compile time. |
31
+ | "Every developer does AJAX differently." | Validation gets skipped. Loading spinners are inconsistent. Error handling is a coin flip. |
32
+ | "AI Agents generate verbose, repetitive code." | Each Agent expands `fetch` + validation + error handling + loading from scratch, burning context tokens on boilerplate. |
33
+ | "New team members break conventions." | They didn't know there *was* a conventionit was tribal knowledge, not enforced infrastructure. |
34
+ | "We can't tell if the Agent forgot something." | You'd have to audit every generated function. At scale, that's impossible. |
28
35
 
29
- ### The deeper reason: discipline at scale
36
+ **The solution is not more code review. The solution is making wrong code impossible to write.**
30
37
 
31
- Every frontend project eventually hits the same problem: ten engineers (or ten AI Agents) write ten different ways to make an AJAX call. Should you validate the form before sending? Show a loading overlay? How should errors be handled? Everyone has a different answer, and code review can only do so much.
38
+ ---
32
39
 
33
- **TS-Util encodes decisions into infrastructure.** When you call `AJAX.request()`, form validation, loading state management, error broadcasting, and data serialization all happen automatically. You can't skip any of them — and neither can your teammates or your AI coding assistants.
40
+ ## 2. How It Works
34
41
 
35
- **For teams** engineers learn one API, new members read one example to get started, and every request flows through the same pipeline. No debates, no divergence.
42
+ TS-Util wraps AJAX, VIEW, validation, formatting, and messaging into **a single enforced pipeline**. When anyone human or AI calls `AJAX.request()`, the following happens automatically:
36
43
 
37
- **For AI Agents** — an Agent emits `AJAX.request({ url, form })` instead of expanding the full fetch + validation + error handling logic every time. Context window is AI's most precious resource; saving tokens preserves quality. The abstraction layer also acts as a guardrail — an Agent cannot "forget" to validate a form because the architecture enforces it automatically.
44
+ ```
45
+ AJAX.request({ url, form })
46
+
47
+
48
+ ┌─ 1. Validate form ──────── can't skip
49
+ ├─ 2. Emit ajax:before ───── loading overlay
50
+ ├─ 3. Serialize + POST ───── consistent format
51
+ ├─ 4. Emit ajax:after ────── overlay hides
52
+ └─ 5. Error broadcasting ─── centralized handling
53
+ ```
38
54
 
39
- > **Wrapping isn't about writing less code — it's about making ten people, or ten Agents, produce output that looks like it came from one.**
55
+ ```typescript
56
+ // This is ALL the code an engineer or AI Agent needs to write:
57
+ await AJAX.request({
58
+ url: '/api/orders',
59
+ form: document.getElementById('order-form')!,
60
+ success: () => MSG.info('Saved!', { autoclose: 3000 }),
61
+ });
40
62
 
41
- 📖 Read the full article in [six languages](https://github.com/MattAtAIEra/TS-Util/blob/main/docs/why-wrap-ajax-and-view.md) (繁體中文 · English · 日本語 · 한국어 · Español · Deutsch)
63
+ // Everything else validation, loading state, error events,
64
+ // data serialization — is handled by the pipeline.
65
+ ```
66
+
67
+ The same principle applies to `VIEW.load()` — every dynamically loaded HTML fragment automatically goes through constraint binding, input formatting, and custom hook execution. No manual initialization. No "forgetting" to set up validation on new content.
68
+
69
+ ```typescript
70
+ // Load HTML fragment — validation + formatting auto-initialize
71
+ await VIEW.load(container, { url: '/api/partial-view' });
72
+ ```
42
73
 
43
74
  ---
44
75
 
45
- ## Live Demo
76
+ ## 3. Advantages
46
77
 
47
- > **[Open `demo.html`](demo.html)** — an interactive single-page guide with live output consoles for every module.
78
+ ### For Engineering Teams
79
+
80
+ | Before | After |
81
+ |--------|-------|
82
+ | 10 engineers, 10 AJAX patterns | 1 API: `AJAX.request()` |
83
+ | New hire reads 10 scattered patterns | New hire reads 1 example, ships on day one |
84
+ | "Did you add the loading overlay?" | Loading overlay is automatic — can't forget |
85
+ | "Did you validate the form?" | Validation is automatic — can't skip |
86
+ | Code review debates on style | Architecture enforces the style |
87
+
88
+ ### For AI Agents
89
+
90
+ | Before | After |
91
+ |--------|-------|
92
+ | Agent expands 15 lines of fetch + validation + error handling | Agent emits 1 line: `AJAX.request({ url, form })` |
93
+ | Context window burned on boilerplate | Tokens preserved for business logic |
94
+ | Different Agents produce different patterns | All Agents produce identical pipeline calls |
95
+ | Must audit every Agent's output for missing steps | Pipeline guarantees completeness — **guardrail by design** |
96
+ | Agent "forgets" loading overlay | Impossible — architecture enforces it |
97
+
98
+ ### The Core Insight
99
+
100
+ > **Discipline is not "remembering to do the right thing." Discipline is making the right thing the only thing that can happen.**
48
101
  >
49
- > ```bash
50
- > npx serve . # then open http://localhost:3000/demo.html
51
- > ```
102
+ > That's what TS-Util does — for your team today, and for the AI Agents that will write most of your code tomorrow.
52
103
 
53
- The demo lets you click through Events, AJAX, Validation, Formatting, MSG dialogs, VIEW injection, and utility functions with code snippets alongside real-time results.
104
+ 📖 Read the full article in [six languages](https://github.com/MattAtAIEra/TS-Util/blob/main/docs/why-wrap-ajax-and-view.md) (繁體中文 · English · 日本語 · 한국어 · Español · Deutsch)
54
105
 
55
106
  ---
56
107
 
@@ -77,7 +128,7 @@ import { AJAX, VIEW, MSG, Validation, Formatter, Events } from 'ts-util-core';
77
128
  </script>
78
129
  ```
79
130
 
80
- ### A real-world example in 12 lines
131
+ ### A real-world example
81
132
 
82
133
  ```typescript
83
134
  import { AJAX, MSG, Events } from 'ts-util-core';
@@ -103,6 +154,18 @@ That single `AJAX.request()` call will:
103
154
 
104
155
  ---
105
156
 
157
+ ## Live Demo
158
+
159
+ > **[Open `demo.html`](demo.html)** — an interactive single-page guide with live output consoles for every module.
160
+ >
161
+ > ```bash
162
+ > npx serve . # then open http://localhost:3000/demo.html
163
+ > ```
164
+
165
+ The demo lets you click through Events, AJAX, Validation, Formatting, MSG dialogs, VIEW injection, and utility functions — with code snippets alongside real-time results.
166
+
167
+ ---
168
+
106
169
  ## Architecture
107
170
 
108
171
  ```
@@ -323,7 +386,7 @@ isDateValid('not-a-date'); // → false
323
386
  | `MSG` | `Message` | DOM dialog system |
324
387
  | `Validation` | `Validator` | Form validation engine |
325
388
  | `Formatter` | `FormatterRegistry` | Input mask registry |
326
- | `Events` | `EventEmitter<TSUtilEventMap>` | Typed event bus |
389
+ | `Events` | `EventEmitter<AppEventMap>` | Typed event bus |
327
390
 
328
391
  ### Utility functions
329
392
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-util-core",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "TS-Util Core Library — form validation, AJAX, view loading, messaging, and formatting utilities",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",