mythik 0.1.5 → 0.2.0
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 +68 -32
- package/dist/actions/transaction-engine.d.ts +10 -0
- package/dist/actions/transaction-engine.d.ts.map +1 -1
- package/dist/actions/transaction-engine.js +13 -1
- package/dist/actions/transaction-engine.js.map +1 -1
- package/dist/agent-context/inventory.d.ts +62 -0
- package/dist/agent-context/inventory.d.ts.map +1 -0
- package/dist/agent-context/inventory.js +248 -0
- package/dist/agent-context/inventory.js.map +1 -0
- package/dist/data/data-sources.d.ts +12 -0
- package/dist/data/data-sources.d.ts.map +1 -1
- package/dist/data/data-sources.js +13 -0
- package/dist/data/data-sources.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/reveal/context.d.ts +22 -0
- package/dist/reveal/context.d.ts.map +1 -0
- package/dist/reveal/context.js +159 -0
- package/dist/reveal/context.js.map +1 -0
- package/dist/reveal/index.d.ts +7 -0
- package/dist/reveal/index.d.ts.map +1 -0
- package/dist/reveal/index.js +7 -0
- package/dist/reveal/index.js.map +1 -0
- package/dist/reveal/protocol.d.ts +28 -0
- package/dist/reveal/protocol.d.ts.map +1 -0
- package/dist/reveal/protocol.js +2 -0
- package/dist/reveal/protocol.js.map +1 -0
- package/dist/reveal/recorder.d.ts +20 -0
- package/dist/reveal/recorder.d.ts.map +1 -0
- package/dist/reveal/recorder.js +31 -0
- package/dist/reveal/recorder.js.map +1 -0
- package/dist/reveal/redaction.d.ts +12 -0
- package/dist/reveal/redaction.d.ts.map +1 -0
- package/dist/reveal/redaction.js +85 -0
- package/dist/reveal/redaction.js.map +1 -0
- package/dist/reveal/truncation.d.ts +4 -0
- package/dist/reveal/truncation.d.ts.map +1 -0
- package/dist/reveal/truncation.js +48 -0
- package/dist/reveal/truncation.js.map +1 -0
- package/dist/reveal/types.d.ts +104 -0
- package/dist/reveal/types.d.ts.map +1 -0
- package/dist/reveal/types.js +2 -0
- package/dist/reveal/types.js.map +1 -0
- package/dist/runtime/mount-spec-runtime.d.ts +5 -0
- package/dist/runtime/mount-spec-runtime.d.ts.map +1 -1
- package/dist/runtime/mount-spec-runtime.js +1 -0
- package/dist/runtime/mount-spec-runtime.js.map +1 -1
- package/docs/consumer/README.md +11 -0
- package/docs/consumer/WHERE-TO-LOOK.md +1 -1
- package/docs/consumer/ai-context-runtime-semantics.md +14 -11
- package/docs/consumer/ai-context.md +85 -18
- package/docs/consumer/reference-doc.md +131 -34
- package/docs/llms.txt +6 -1
- package/docs/wiki/compiled/README.md +13 -11
- package/docs/wiki/compiled/_gaps.md +1 -1
- package/docs/wiki/compiled/_index.md +11 -7
- package/docs/wiki/compiled/_inventory.md +22 -14
- package/docs/wiki/compiled/_lint.md +21 -17
- package/docs/wiki/compiled/antipattern-store-save-bypass.md +13 -8
- package/docs/wiki/compiled/cli-agent.md +70 -0
- package/docs/wiki/compiled/cli-existing-spec-edit-loop.md +9 -8
- package/docs/wiki/compiled/cli-overview.md +12 -7
- package/docs/wiki/compiled/cli-patch.md +14 -11
- package/docs/wiki/compiled/cli-programmatic-api.md +17 -7
- package/docs/wiki/compiled/cli-push.md +36 -24
- package/docs/wiki/compiled/cli-reveal.md +64 -0
- package/docs/wiki/compiled/cli-toon.md +9 -9
- package/docs/wiki/compiled/cli-versioning-author.md +19 -15
- package/docs/wiki/compiled/concept-agent-context-protocol.md +76 -0
- package/docs/wiki/compiled/concept-mythik-reveal.md +63 -0
- package/docs/wiki/compiled/concept-package-layout.md +7 -6
- package/docs/wiki/compiled/concept-public-package-names.md +9 -5
- package/docs/wiki/compiled/concept-shape-animations.md +4 -2
- package/docs/wiki/compiled/concept-spec-store-interface.md +7 -4
- package/docs/wiki/compiled/concept-spec-store-layering.md +5 -5
- package/docs/wiki/compiled/concept-versioned-store.md +8 -5
- package/docs/wiki/compiled/pattern-git-vs-db-versioning.md +8 -6
- package/docs/wiki/compiled/pattern-push-vs-patch.md +13 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# mythik
|
|
2
2
|
|
|
3
|
-
The Mythik runtime
|
|
4
|
-
stores,
|
|
5
|
-
imports. It also ships the
|
|
6
|
-
the npm tarball
|
|
7
|
-
installed version of the framework
|
|
8
|
-
version drift.
|
|
3
|
+
The Mythik contract runtime: types, validation, expressions, actions,
|
|
4
|
+
spec stores, versioning, editor sessions, and **Reveal** context contracts.
|
|
5
|
+
This is the foundation every Mythik consumer imports. It also ships the
|
|
6
|
+
canonical AI documentation bundled inside the npm tarball, so the docs
|
|
7
|
+
an agent reads always match the installed version of the framework.
|
|
9
8
|
|
|
10
9
|
> See [the framework README on GitHub](https://github.com/mldixdev/mythik#readme)
|
|
11
10
|
> for the full Mythik architecture and design philosophy. This file
|
|
@@ -13,8 +12,8 @@ version drift.
|
|
|
13
12
|
|
|
14
13
|
---
|
|
15
14
|
|
|
16
|
-
## What Mythik is, briefly
|
|
17
|
-
|
|
15
|
+
## What Mythik is, briefly
|
|
16
|
+
|
|
18
17
|
Mythik is an **AI-first JSON-native app framework**. Most of your app
|
|
19
18
|
lives as validated JSON specs loaded at runtime from your database,
|
|
20
19
|
not source code that must be regenerated and redeployed for every
|
|
@@ -35,12 +34,13 @@ npm install mythik
|
|
|
35
34
|
|
|
36
35
|
You install `mythik` whenever you're building anything Mythik-related:
|
|
37
36
|
|
|
38
|
-
| You want to... | Install |
|
|
39
|
-
|---|---|
|
|
40
|
-
| Render specs as a React app | `mythik` + `mythik-react` |
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
37
|
+
| You want to... | Install |
|
|
38
|
+
|---|---|
|
|
39
|
+
| Render specs as a React app | `mythik` + `mythik-react` |
|
|
40
|
+
| Render specs in React Native or Expo | `mythik` + `mythik-react-native` |
|
|
41
|
+
| Build a REST API from an ApiSpec | `mythik` + `mythik-server` |
|
|
42
|
+
| Author or patch specs from the command line | `mythik` + `mythik-cli` (dev) |
|
|
43
|
+
| Validate or query specs from a Node script | `mythik` alone |
|
|
44
44
|
|
|
45
45
|
## What you get
|
|
46
46
|
|
|
@@ -73,6 +73,12 @@ You install `mythik` whenever you're building anything Mythik-related:
|
|
|
73
73
|
`mythik-react`, but the runtime lives here and can be used directly
|
|
74
74
|
for non-React shells or custom integrations.
|
|
75
75
|
|
|
76
|
+
- **Mythik Reveal contracts** — typed runtime context, redaction,
|
|
77
|
+
truncation, event recorder, and protocol shapes used by the React,
|
|
78
|
+
React Native, and CLI **Reveal** integrations. **Reveal** lets a running app
|
|
79
|
+
expose its live contract, selected state, events, diagnostics, and
|
|
80
|
+
environment as structured context for AI agents.
|
|
81
|
+
|
|
76
82
|
## Browser-safe vs Node-only entries
|
|
77
83
|
|
|
78
84
|
```ts
|
|
@@ -188,7 +194,7 @@ node_modules/mythik/docs/
|
|
|
188
194
|
│ ├── ai-context-custom-elements.md # custom expressions/actions
|
|
189
195
|
│ ├── reference-doc.md # full rule catalog
|
|
190
196
|
│ └── WHERE-TO-LOOK.md # navigation guide
|
|
191
|
-
├── wiki/compiled/ #
|
|
197
|
+
├── wiki/compiled/ # atomic per-concept articles
|
|
192
198
|
└── llms.txt # index for LLM tooling
|
|
193
199
|
```
|
|
194
200
|
|
|
@@ -205,25 +211,55 @@ $ npx mythik docs copy ./mythik-docs
|
|
|
205
211
|
Point your AI agent at the printed path before asking it to author or
|
|
206
212
|
modify specs.
|
|
207
213
|
|
|
208
|
-
|
|
214
|
+
For runtime debugging, pair these docs with **Mythik Reveal**:
|
|
209
215
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
the framework evolves.
|
|
216
|
+
```bash
|
|
217
|
+
npx mythik reveal start
|
|
218
|
+
npx mythik reveal apps --json
|
|
219
|
+
npx mythik reveal context --app <app-name>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Docs explain the contract; **Reveal** shows what the running app actually
|
|
223
|
+
mounted.
|
|
219
224
|
|
|
220
|
-
|
|
225
|
+
For fresh AI agents, install the local operating protocol before asking
|
|
226
|
+
for spec changes. `agent init` currently supports `codex`, `claude`, and
|
|
227
|
+
`all`. `codex` creates/updates `AGENTS.md`, `claude` creates/updates
|
|
228
|
+
`CLAUDE.md`, and `all` updates both. Existing agent files are preserved
|
|
229
|
+
outside the Mythik-managed block delimited by
|
|
230
|
+
`<!-- mythik-agent-protocol:start -->` and
|
|
231
|
+
`<!-- mythik-agent-protocol:end -->`.
|
|
221
232
|
|
|
222
|
-
|
|
223
|
-
[CHANGELOG](https://github.com/mldixdev/mythik/blob/main/CHANGELOG.md)
|
|
224
|
-
and on
|
|
225
|
-
[GitHub Releases](https://github.com/mldixdev/mythik/releases).
|
|
233
|
+
The adapters point the agent to shared `.mythik/agent/*` instructions:
|
|
226
234
|
|
|
227
|
-
|
|
235
|
+
```bash
|
|
236
|
+
npx mythik agent init codex
|
|
237
|
+
npx mythik agent context --app <app-id> --include-screens --out .mythik/agent/context.md
|
|
238
|
+
```
|
|
228
239
|
|
|
229
|
-
|
|
240
|
+
The generated protocol names the active Mythik store as the source of
|
|
241
|
+
truth and keeps existing spec edits on
|
|
242
|
+
`manifest -> elements -> patch --from-file --author -> validate -> verify`.
|
|
243
|
+
|
|
244
|
+
## Related packages
|
|
245
|
+
|
|
246
|
+
- [`mythik-react`](https://github.com/mldixdev/mythik/tree/main/packages/react#readme) — render the specs as a React app
|
|
247
|
+
- [`mythik-cli`](https://github.com/mldixdev/mythik/tree/main/packages/cli#readme) — **Agent Protocol**, patch workflow, validation, versioning, environments, and **Reveal** commands
|
|
248
|
+
- [`mythik-server`](https://github.com/mldixdev/mythik/tree/main/packages/server#readme) — declarative REST server from an `ApiSpec`
|
|
249
|
+
- [`mythik-react-native`](https://github.com/mldixdev/mythik/tree/main/packages/react-native#readme) — render supported Mythik primitives in Expo and React Native
|
|
250
|
+
|
|
251
|
+
## Status
|
|
252
|
+
|
|
253
|
+
Public release line. APIs are documented for real-world feedback as
|
|
254
|
+
the framework evolves.
|
|
255
|
+
|
|
256
|
+
## Releases
|
|
257
|
+
|
|
258
|
+
Release notes and patch details are published in the
|
|
259
|
+
[CHANGELOG](https://github.com/mldixdev/mythik/blob/main/CHANGELOG.md)
|
|
260
|
+
and on
|
|
261
|
+
[GitHub Releases](https://github.com/mldixdev/mythik/releases).
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
Apache-2.0.
|
|
@@ -5,9 +5,19 @@ export interface TransactionEngineConfig {
|
|
|
5
5
|
store: StateStore;
|
|
6
6
|
dispatcher: ActionDispatcherInstance;
|
|
7
7
|
resolve: ResolveFn;
|
|
8
|
+
observer?: TransactionObserver;
|
|
8
9
|
}
|
|
9
10
|
export interface TransactionEngine {
|
|
10
11
|
execute: (config: TransactionConfig) => Promise<void>;
|
|
11
12
|
}
|
|
13
|
+
export interface TransactionObserverEvent {
|
|
14
|
+
phase: 'transaction' | 'before' | 'optimistic' | 'confirm' | 'onSuccess' | 'onError';
|
|
15
|
+
status: 'start' | 'success' | 'error' | 'rollback';
|
|
16
|
+
actionCount?: number;
|
|
17
|
+
message?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TransactionObserver {
|
|
20
|
+
onTransactionEvent?: (event: TransactionObserverEvent) => void;
|
|
21
|
+
}
|
|
12
22
|
export declare function createTransactionEngine(config: TransactionEngineConfig): TransactionEngine;
|
|
13
23
|
//# sourceMappingURL=transaction-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-engine.d.ts","sourceRoot":"","sources":["../../src/actions/transaction-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,UAAU,CAAC;IAClB,UAAU,EAAE,wBAAwB,CAAC;IACrC,OAAO,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction-engine.d.ts","sourceRoot":"","sources":["../../src/actions/transaction-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,UAAU,CAAC;IAClB,UAAU,EAAE,wBAAwB,CAAC;IACrC,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,aAAa,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IACrF,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAChE;AAqDD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,uBAAuB,GAAG,iBAAiB,CAmH1F"}
|
|
@@ -39,7 +39,15 @@ function normalizeTransactionError(error, fallbackMessage = 'Transaction failed'
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
export function createTransactionEngine(config) {
|
|
42
|
-
const { store, dispatcher, resolve } = config;
|
|
42
|
+
const { store, dispatcher, resolve, observer } = config;
|
|
43
|
+
const emit = (event) => {
|
|
44
|
+
try {
|
|
45
|
+
observer?.onTransactionEvent?.(event);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Reveal observers must never alter transaction semantics.
|
|
49
|
+
}
|
|
50
|
+
};
|
|
43
51
|
// --- Queue: one transaction at a time ---
|
|
44
52
|
let running = false;
|
|
45
53
|
const queue = [];
|
|
@@ -64,6 +72,7 @@ export function createTransactionEngine(config) {
|
|
|
64
72
|
// --- Core transaction logic ---
|
|
65
73
|
async function runTransaction(txConfig) {
|
|
66
74
|
const timeout = txConfig.timeout ?? DEFAULT_TIMEOUT;
|
|
75
|
+
emit({ phase: 'transaction', status: 'start' });
|
|
67
76
|
// Phase 1: before (not rolled back)
|
|
68
77
|
if (txConfig.before && txConfig.before.length > 0) {
|
|
69
78
|
await executeActions(txConfig.before);
|
|
@@ -93,12 +102,15 @@ export function createTransactionEngine(config) {
|
|
|
93
102
|
if (txConfig.onSuccess && txConfig.onSuccess.length > 0) {
|
|
94
103
|
await executeActions(txConfig.onSuccess);
|
|
95
104
|
}
|
|
105
|
+
emit({ phase: 'transaction', status: 'success' });
|
|
96
106
|
}
|
|
97
107
|
catch (err) {
|
|
98
108
|
// Rollback: restore snapshot atomically (single set, one re-render)
|
|
99
109
|
store.set('/', snapshot);
|
|
110
|
+
emit({ phase: 'transaction', status: 'rollback' });
|
|
100
111
|
// Write error after rollback so root restore cannot erase details.
|
|
101
112
|
store.set('/tx/error', confirmError ?? normalizeTransactionError(err));
|
|
113
|
+
emit({ phase: 'transaction', status: 'error', message: err instanceof Error ? err.message : 'Transaction failed' });
|
|
102
114
|
// Phase 5b: onError (after rollback)
|
|
103
115
|
if (txConfig.onError && txConfig.onError.length > 0) {
|
|
104
116
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-engine.js","sourceRoot":"","sources":["../../src/actions/transaction-engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction-engine.js","sourceRoot":"","sources":["../../src/actions/transaction-engine.ts"],"names":[],"mappings":"AA0BA,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,WAAW,CAAC,GAAG,MAAiB;IACvC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IAClE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAY;IACrC,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,OAAO;YAAE,SAAS;QACrE,MAAM,CAAC,GAAG,CAAC,GAAI,KAA4C,CAAC,GAAG,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAc,EAAE,eAAe,GAAG,oBAAoB;IACvF,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO;YACL,GAAG,iBAAiB,CAAC,KAAK,CAAC;YAC3B,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,eAAe;SAC1C,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,K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AG,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC;YAEpH,qCAAqC;YACrC,IAAI,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpD,IAAI,CAAC;oBACH,MAAM,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACzC,CAAC;gBAAC,OAAO,UAAU,EAAE,CAAC;oBACpB,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,UAAU,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,gBAAgB;YAChB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,qBAAqB;IACrB,SAAS,OAAO,CAAC,QAA2B;QAC1C,OAAO,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,EAAE;YAC1C,KAAK,CAAC,IAAI,CAAC;gBACT,QAAQ;gBACR,IAAI,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE;aAC7B,CAAC,CAAC;YACH,YAAY,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FetchReference } from '../contract/types.js';
|
|
2
|
+
import type { RevealRedactionPolicy } from '../reveal/types.js';
|
|
3
|
+
export interface AgentElementSummary {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
props?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentScreenRef {
|
|
9
|
+
id: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
icon?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentEndpointSummary {
|
|
15
|
+
id: string;
|
|
16
|
+
method: string;
|
|
17
|
+
path: string;
|
|
18
|
+
kind: 'query' | 'crud' | 'handler' | 'unknown';
|
|
19
|
+
}
|
|
20
|
+
export interface AgentCatalogSummary {
|
|
21
|
+
id: string;
|
|
22
|
+
kind: 'static' | 'distinct' | 'valueLabel' | 'unknown';
|
|
23
|
+
}
|
|
24
|
+
export interface AgentDataSourceSummary {
|
|
25
|
+
id: string;
|
|
26
|
+
method: string;
|
|
27
|
+
url: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AgentEditorSessionSummary {
|
|
30
|
+
id: string;
|
|
31
|
+
paths: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface AgentDocumentSummary {
|
|
34
|
+
id: string;
|
|
35
|
+
type: 'screen' | 'app' | 'api' | 'unknown';
|
|
36
|
+
root?: string;
|
|
37
|
+
elementCount?: number;
|
|
38
|
+
elements?: AgentElementSummary[];
|
|
39
|
+
screens?: AgentScreenRef[];
|
|
40
|
+
endpoints?: AgentEndpointSummary[];
|
|
41
|
+
catalogs?: AgentCatalogSummary[];
|
|
42
|
+
}
|
|
43
|
+
export interface AgentDocumentInventory {
|
|
44
|
+
readerPaths: string[];
|
|
45
|
+
writerPaths: string[];
|
|
46
|
+
actions: string[];
|
|
47
|
+
dataSources: AgentDataSourceSummary[];
|
|
48
|
+
editorSessions: AgentEditorSessionSummary[];
|
|
49
|
+
authGates: string[];
|
|
50
|
+
reservedWrites: string[];
|
|
51
|
+
fetchReferences: FetchReference[];
|
|
52
|
+
}
|
|
53
|
+
export interface AgentDocumentInspection {
|
|
54
|
+
summary: AgentDocumentSummary;
|
|
55
|
+
inventory: AgentDocumentInventory;
|
|
56
|
+
screenIds: string[];
|
|
57
|
+
}
|
|
58
|
+
export interface InspectAgentDocumentOptions {
|
|
59
|
+
redaction?: RevealRedactionPolicy;
|
|
60
|
+
}
|
|
61
|
+
export declare function inspectAgentDocument(id: string, doc: unknown, options?: InspectAgentDocumentOptions): AgentDocumentInspection;
|
|
62
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../src/agent-context/inventory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGhE,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;CACxD;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,sBAAsB,EAAE,CAAC;IACtC,cAAc,EAAE,yBAAyB,EAAE,CAAC;IAC5C,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,EAAE,sBAAsB,CAAC;IAClC,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC1C,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AA+KD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,2BAAgC,GAAG,uBAAuB,CAqEjI"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { extractFetchReferences } from '../contract/extractor.js';
|
|
2
|
+
import { scanDeps } from '../renderer/deps.js';
|
|
3
|
+
import { DEFAULT_REVEAL_REDACTION, redactRevealValue } from '../reveal/redaction.js';
|
|
4
|
+
import { RESERVED_PATHS } from '../state/reserved-paths.js';
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function documentType(doc) {
|
|
9
|
+
if (!isRecord(doc))
|
|
10
|
+
return 'unknown';
|
|
11
|
+
if (doc.type === 'app')
|
|
12
|
+
return 'app';
|
|
13
|
+
if (doc.type === 'api')
|
|
14
|
+
return 'api';
|
|
15
|
+
if (typeof doc.root === 'string' && isRecord(doc.elements))
|
|
16
|
+
return 'screen';
|
|
17
|
+
return 'unknown';
|
|
18
|
+
}
|
|
19
|
+
function removePrivateAndFunctions(value) {
|
|
20
|
+
if (Array.isArray(value))
|
|
21
|
+
return value.map((item) => removePrivateAndFunctions(item));
|
|
22
|
+
if (!isRecord(value))
|
|
23
|
+
return typeof value === 'function' ? undefined : value;
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const [key, child] of Object.entries(value)) {
|
|
26
|
+
if (key.startsWith('_') || typeof child === 'function')
|
|
27
|
+
continue;
|
|
28
|
+
const cleaned = removePrivateAndFunctions(child);
|
|
29
|
+
if (cleaned !== undefined)
|
|
30
|
+
out[key] = cleaned;
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function publicProps(element, redaction) {
|
|
35
|
+
if (!isRecord(element) || !isRecord(element.props))
|
|
36
|
+
return undefined;
|
|
37
|
+
const redacted = redactRevealValue(element.props, redaction);
|
|
38
|
+
const cleaned = removePrivateAndFunctions(redacted);
|
|
39
|
+
if (!isRecord(cleaned))
|
|
40
|
+
return undefined;
|
|
41
|
+
return Object.keys(cleaned).length > 0 ? cleaned : undefined;
|
|
42
|
+
}
|
|
43
|
+
function endpointKind(endpoint) {
|
|
44
|
+
if (endpoint.crud !== undefined)
|
|
45
|
+
return 'crud';
|
|
46
|
+
if (endpoint.query !== undefined)
|
|
47
|
+
return 'query';
|
|
48
|
+
if (endpoint.handler !== undefined)
|
|
49
|
+
return 'handler';
|
|
50
|
+
return 'unknown';
|
|
51
|
+
}
|
|
52
|
+
function catalogKind(catalog) {
|
|
53
|
+
if (catalog.static !== undefined)
|
|
54
|
+
return 'static';
|
|
55
|
+
if (catalog.distinct !== undefined)
|
|
56
|
+
return 'distinct';
|
|
57
|
+
if (catalog.value !== undefined || catalog.label !== undefined)
|
|
58
|
+
return 'valueLabel';
|
|
59
|
+
return 'unknown';
|
|
60
|
+
}
|
|
61
|
+
function redactUrlCredentials(value) {
|
|
62
|
+
return value.replace(/^([a-z][a-z0-9+.-]*:\/\/)([^/@\s]+)@/i, '$1[REDACTED]@');
|
|
63
|
+
}
|
|
64
|
+
function scanStringTemplatePaths(value) {
|
|
65
|
+
const paths = [];
|
|
66
|
+
const regex = /\$\{(\/[^}]+)\}/g;
|
|
67
|
+
let match;
|
|
68
|
+
while ((match = regex.exec(value)) !== null)
|
|
69
|
+
paths.push(match[1]);
|
|
70
|
+
return paths;
|
|
71
|
+
}
|
|
72
|
+
function isReservedPath(path) {
|
|
73
|
+
return Object.values(RESERVED_PATHS).some((reserved) => path === reserved || path.startsWith(`${reserved}/`));
|
|
74
|
+
}
|
|
75
|
+
function collectActionBindings(value, actions, writerPaths, reservedWrites) {
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
for (const item of value)
|
|
78
|
+
collectActionBindings(item, actions, writerPaths, reservedWrites);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!isRecord(value))
|
|
82
|
+
return;
|
|
83
|
+
if (typeof value.action === 'string')
|
|
84
|
+
actions.add(value.action);
|
|
85
|
+
const params = isRecord(value.params) ? value.params : undefined;
|
|
86
|
+
const statePath = typeof params?.statePath === 'string' ? params.statePath : undefined;
|
|
87
|
+
if (statePath) {
|
|
88
|
+
writerPaths.add(statePath);
|
|
89
|
+
if (isReservedPath(statePath))
|
|
90
|
+
reservedWrites.add(statePath);
|
|
91
|
+
}
|
|
92
|
+
for (const child of Object.values(value))
|
|
93
|
+
collectActionBindings(child, actions, writerPaths, reservedWrites);
|
|
94
|
+
}
|
|
95
|
+
function buildDataSources(doc) {
|
|
96
|
+
if (!isRecord(doc.dataSources))
|
|
97
|
+
return [];
|
|
98
|
+
return Object.entries(doc.dataSources).map(([sourceId, source]) => {
|
|
99
|
+
const sourceRecord = isRecord(source) ? source : {};
|
|
100
|
+
return {
|
|
101
|
+
id: sourceId,
|
|
102
|
+
method: typeof sourceRecord.method === 'string' ? sourceRecord.method.toUpperCase() : 'GET',
|
|
103
|
+
url: typeof sourceRecord.url === 'string' ? redactUrlCredentials(sourceRecord.url) : '',
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function buildEditorSessions(doc) {
|
|
108
|
+
if (!isRecord(doc.editorSessions))
|
|
109
|
+
return [];
|
|
110
|
+
return Object.entries(doc.editorSessions).map(([sessionId, session]) => {
|
|
111
|
+
const sessionRecord = isRecord(session) ? session : {};
|
|
112
|
+
return {
|
|
113
|
+
id: sessionId,
|
|
114
|
+
paths: Array.isArray(sessionRecord.paths) ? sessionRecord.paths.filter((path) => typeof path === 'string') : [],
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function buildFetchReferences(id, doc) {
|
|
119
|
+
if (!doc.root || !doc.elements)
|
|
120
|
+
return [];
|
|
121
|
+
return extractFetchReferences(id, doc).map((ref) => ({
|
|
122
|
+
...ref,
|
|
123
|
+
path: redactUrlCredentials(ref.path),
|
|
124
|
+
rawUrl: redactUrlCredentials(ref.rawUrl),
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
function buildInventory(id, doc) {
|
|
128
|
+
const readerPaths = new Set();
|
|
129
|
+
const writerPaths = new Set();
|
|
130
|
+
const actions = new Set();
|
|
131
|
+
const reservedWrites = new Set();
|
|
132
|
+
const authGates = new Set();
|
|
133
|
+
for (const dep of scanDeps(doc)) {
|
|
134
|
+
readerPaths.add(dep);
|
|
135
|
+
if (dep.startsWith('/auth/'))
|
|
136
|
+
authGates.add(dep);
|
|
137
|
+
}
|
|
138
|
+
collectActionBindings(doc, actions, writerPaths, reservedWrites);
|
|
139
|
+
const dataSources = buildDataSources(doc);
|
|
140
|
+
const editorSessions = buildEditorSessions(doc);
|
|
141
|
+
const fetchReferences = buildFetchReferences(id, doc);
|
|
142
|
+
for (const source of dataSources) {
|
|
143
|
+
for (const path of scanStringTemplatePaths(source.url))
|
|
144
|
+
readerPaths.add(path);
|
|
145
|
+
}
|
|
146
|
+
for (const ref of fetchReferences) {
|
|
147
|
+
for (const path of scanStringTemplatePaths(ref.rawUrl))
|
|
148
|
+
readerPaths.add(path);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
readerPaths: [...readerPaths].sort(),
|
|
152
|
+
writerPaths: [...writerPaths].sort(),
|
|
153
|
+
actions: [...actions].sort(),
|
|
154
|
+
dataSources,
|
|
155
|
+
editorSessions,
|
|
156
|
+
authGates: [...authGates].sort(),
|
|
157
|
+
reservedWrites: [...reservedWrites].sort(),
|
|
158
|
+
fetchReferences,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function summarizeElements(elements, redaction) {
|
|
162
|
+
return Object.entries(elements).map(([elementId, element]) => {
|
|
163
|
+
const props = publicProps(element, redaction);
|
|
164
|
+
const type = isRecord(element) && typeof element.type === 'string' ? element.type : 'unknown';
|
|
165
|
+
return {
|
|
166
|
+
id: elementId,
|
|
167
|
+
type,
|
|
168
|
+
...(props ? { props } : {}),
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function summarizeScreens(screens) {
|
|
173
|
+
return Object.entries(screens).map(([screenId, screen]) => {
|
|
174
|
+
const screenRecord = isRecord(screen) ? screen : {};
|
|
175
|
+
return {
|
|
176
|
+
id: screenId,
|
|
177
|
+
...(typeof screenRecord.label === 'string' ? { label: screenRecord.label } : {}),
|
|
178
|
+
...(typeof screenRecord.icon === 'string' ? { icon: screenRecord.icon } : {}),
|
|
179
|
+
...(typeof screenRecord.description === 'string' ? { description: screenRecord.description } : {}),
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
export function inspectAgentDocument(id, doc, options = {}) {
|
|
184
|
+
const type = documentType(doc);
|
|
185
|
+
const redaction = options.redaction ?? DEFAULT_REVEAL_REDACTION;
|
|
186
|
+
if (!isRecord(doc)) {
|
|
187
|
+
return { summary: { id, type: 'unknown' }, inventory: buildInventory(id, {}), screenIds: [] };
|
|
188
|
+
}
|
|
189
|
+
if (type === 'screen') {
|
|
190
|
+
const elements = isRecord(doc.elements) ? doc.elements : {};
|
|
191
|
+
return {
|
|
192
|
+
summary: {
|
|
193
|
+
id,
|
|
194
|
+
type,
|
|
195
|
+
root: String(doc.root),
|
|
196
|
+
elementCount: Object.keys(elements).length,
|
|
197
|
+
elements: summarizeElements(elements, redaction),
|
|
198
|
+
},
|
|
199
|
+
inventory: buildInventory(id, doc),
|
|
200
|
+
screenIds: [],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (type === 'app') {
|
|
204
|
+
const layout = isRecord(doc.layout) ? doc.layout : {};
|
|
205
|
+
const elements = isRecord(layout.elements) ? layout.elements : {};
|
|
206
|
+
const screens = isRecord(doc.screens) ? doc.screens : {};
|
|
207
|
+
const screenRefs = summarizeScreens(screens);
|
|
208
|
+
return {
|
|
209
|
+
summary: {
|
|
210
|
+
id,
|
|
211
|
+
type,
|
|
212
|
+
...(typeof layout.root === 'string' ? { root: layout.root } : {}),
|
|
213
|
+
elementCount: Object.keys(elements).length,
|
|
214
|
+
elements: summarizeElements(elements, redaction),
|
|
215
|
+
screens: screenRefs,
|
|
216
|
+
},
|
|
217
|
+
inventory: buildInventory(id, doc),
|
|
218
|
+
screenIds: screenRefs.map((screen) => screen.id),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (type === 'api') {
|
|
222
|
+
const endpoints = isRecord(doc.endpoints) ? doc.endpoints : {};
|
|
223
|
+
const catalogs = isRecord(doc.catalogs) ? doc.catalogs : {};
|
|
224
|
+
return {
|
|
225
|
+
summary: {
|
|
226
|
+
id,
|
|
227
|
+
type,
|
|
228
|
+
endpoints: Object.entries(endpoints).map(([endpointId, endpoint]) => {
|
|
229
|
+
const endpointRecord = isRecord(endpoint) ? endpoint : {};
|
|
230
|
+
return {
|
|
231
|
+
id: endpointId,
|
|
232
|
+
method: typeof endpointRecord.method === 'string' ? endpointRecord.method.toUpperCase() : 'GET',
|
|
233
|
+
path: typeof endpointRecord.path === 'string' ? endpointRecord.path : '',
|
|
234
|
+
kind: endpointKind(endpointRecord),
|
|
235
|
+
};
|
|
236
|
+
}),
|
|
237
|
+
catalogs: Object.entries(catalogs).map(([catalogId, catalog]) => {
|
|
238
|
+
const catalogRecord = isRecord(catalog) ? catalog : {};
|
|
239
|
+
return { id: catalogId, kind: catalogKind(catalogRecord) };
|
|
240
|
+
}),
|
|
241
|
+
},
|
|
242
|
+
inventory: buildInventory(id, doc),
|
|
243
|
+
screenIds: [],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return { summary: { id, type }, inventory: buildInventory(id, doc), screenIds: [] };
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=inventory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../src/agent-context/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAErF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAsE5D,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,IA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,CAAC,CAAC,CAAC,KAAK;wBAC/F,IAAI,EAAE,OAAO,cAAc,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;wBACxE,IAAI,EAAE,YAAY,CAAC,cAAc,CAAC;qBACnC,CAAC;gBACJ,CAAC,CAAC;gBACF,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE;oBAC9D,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;oBACvD,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC7D,CAAC,CAAC;aACH;YACD,SAAS,EAAE,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC;YAClC,SAAS,EAAE,EAAE;SACd,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AACtF,CAAC"}
|
|
@@ -11,6 +11,18 @@ export interface DataSourcesEngineConfig {
|
|
|
11
11
|
status: number;
|
|
12
12
|
json: () => Promise<unknown>;
|
|
13
13
|
}>;
|
|
14
|
+
observer?: DataSourcesObserver;
|
|
15
|
+
}
|
|
16
|
+
export interface DataSourceObserverEvent {
|
|
17
|
+
id: string;
|
|
18
|
+
target: string;
|
|
19
|
+
status: 'deferred' | 'start' | 'success' | 'http-error' | 'error';
|
|
20
|
+
method?: string;
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
message?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface DataSourcesObserver {
|
|
25
|
+
onDataSourceEvent?: (event: DataSourceObserverEvent) => void;
|
|
14
26
|
}
|
|
15
27
|
export interface DataSourcesEngine {
|
|
16
28
|
/** Start reactive data fetching. Performs initial fetch for sources with initialFetch:true. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-sources.d.ts","sourceRoot":"","sources":["../../src/data/data-sources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC9C,uDAAuD;IACvD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"data-sources.d.ts","sourceRoot":"","sources":["../../src/data/data-sources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC9C,uDAAuD;IACvD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IACzH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,OAAO,CAAC;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,iBAAiB;IAChC,+FAA+F;IAC/F,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,wCAAwC;IACxC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,uFAAuF;IACvF,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;CAC7C;AAkBD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,uBAAuB,GAAG,iBAAiB,CA2O1F"}
|
|
@@ -16,6 +16,14 @@ function buildQueryString(params) {
|
|
|
16
16
|
export function createDataSourcesEngine(config) {
|
|
17
17
|
const { store, resolver, dataSources } = config;
|
|
18
18
|
const fetcher = config.fetcher ?? globalThis.fetch?.bind(globalThis);
|
|
19
|
+
const emit = (event) => {
|
|
20
|
+
try {
|
|
21
|
+
config.observer?.onDataSourceEvent?.(event);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Reveal observers must never alter data-source semantics.
|
|
25
|
+
}
|
|
26
|
+
};
|
|
19
27
|
let mounted = false;
|
|
20
28
|
let unsubscribe = null;
|
|
21
29
|
const debounceTimers = new Map();
|
|
@@ -62,6 +70,7 @@ export function createDataSourcesEngine(config) {
|
|
|
62
70
|
if (value === undefined || value === null || value === '') {
|
|
63
71
|
store.set(`/${deferredPath}`, true);
|
|
64
72
|
store.set(`/${loadingPath}`, false);
|
|
73
|
+
emit({ id, target, status: 'deferred' });
|
|
65
74
|
return;
|
|
66
75
|
}
|
|
67
76
|
}
|
|
@@ -95,21 +104,25 @@ export function createDataSourcesEngine(config) {
|
|
|
95
104
|
if (ds.headers) {
|
|
96
105
|
options.headers = resolver.resolve(ds.headers);
|
|
97
106
|
}
|
|
107
|
+
emit({ id, target, status: 'start', method: String(options.method ?? 'GET') });
|
|
98
108
|
const response = await fetcher(fullUrl, options);
|
|
99
109
|
if (!response.ok) {
|
|
100
110
|
store.set(`/${loadingPath}`, false);
|
|
101
111
|
store.set(`/${errorPath}`, { status: response.status, message: `HTTP ${response.status}` });
|
|
112
|
+
emit({ id, target, status: 'http-error', statusCode: response.status });
|
|
102
113
|
return;
|
|
103
114
|
}
|
|
104
115
|
const data = await response.json();
|
|
105
116
|
store.set(target, data);
|
|
106
117
|
store.set(`/${loadingPath}`, false);
|
|
118
|
+
emit({ id, target, status: 'success', statusCode: response.status });
|
|
107
119
|
}
|
|
108
120
|
catch (err) {
|
|
109
121
|
store.set(`/${loadingPath}`, false);
|
|
110
122
|
store.set(`/${errorPath}`, {
|
|
111
123
|
message: err instanceof Error ? err.message : 'Unknown error',
|
|
112
124
|
});
|
|
125
|
+
emit({ id, target, status: 'error', message: err instanceof Error ? err.message : 'Unknown error' });
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
128
|
/** Schedule a fetch with optional debounce. */
|