Skip to content

feat: add @script-development/fs-dialog package#10

Merged
Goosterhof merged 1 commit into
mainfrom
fs-dialog
Apr 2, 2026
Merged

feat: add @script-development/fs-dialog package#10
Goosterhof merged 1 commit into
mainfrom
fs-dialog

Conversation

@Goosterhof

Copy link
Copy Markdown
Contributor

Summary

  • New @script-development/fs-dialog package — component-agnostic dialog stack service for Vue 3
  • LIFO stack with closeFrom(index) semantics: closing a dialog closes everything above it
  • Error middleware chain (registerErrorMiddleware) for centralized error handling within dialogs
  • V-model prop synchronization, body scroll lock, native <dialog> with showModal()
  • Zero fs-* dependencies — only peer dep is Vue 3.5+

Design decisions

  • LIFO stackcloseFrom(index) is the primitive. closeAll() and per-dialog onClose are built on top
  • Native <dialog> — Browser-native focus trapping, backdrop, keyboard handling
  • Error middlewareregisterErrorMiddleware(handler) returns unregister. Chain stops on false. Only Error instances trigger middleware
  • No styling opinions — Inline style reset on <dialog> (padding:0; margin:auto; background:transparent; border:none). Backdrop styling is consumer CSS
  • Suspense wrapping — Supports defineAsyncComponent usage. Fallback is null (no opinionated loading UI)

Package API

const dialogService = createDialogService();

// Open a dialog
dialogService.open(MyDialogComponent, { title: "Edit", onSubmit: handleSubmit });

// Close all
dialogService.closeAll();

// Error middleware
const unregister = dialogService.registerErrorMiddleware((error, { closeAll }) => {
  if (error instanceof NotFoundError) { closeAll(); return false; }
  return true;
});

// Mount in template: <component :is="dialogService.DialogContainerComponent" />

Test plan

  • All 8 CI gates pass (format, lint, build, typecheck, lint:pkg, coverage, mutation)
  • 33 unit tests covering: open, stack, closeAll, closeFrom, cancel prevention, backdrop click, v-model sync, error middleware chain, isolation, body scroll lock
  • 100% line/branch/function/statement coverage
  • 92.16% overall mutation score (threshold: 90%)

🤖 Generated with Claude Code

Component-agnostic dialog stack service for Vue 3.
LIFO stack with closeFrom(index), error middleware chain,
v-model prop sync, body scroll lock, native <dialog> showModal().
Zero fs-* dependencies. Only peer dep is Vue 3.5+.
@Goosterhof Goosterhof merged commit f52df0c into main Apr 2, 2026
1 check passed
Goosterhof added a commit that referenced this pull request May 13, 2026
…iddleware-driven trigger

Public-API surface tests (new):

- Returned module has exactly {getAll, getById, getOrFailById, generateNew, prime} — five enumerable keys.
- `expect(store).not.toHaveProperty('retrieveAll')` — verifies the narrowing.
- `expect(store).not.toHaveProperty('retrieveById')` — verifies the narrowing.

prime() behavior (new group):

- Cold start (localHash null, no header) → exactly one inner fetch.
- localHash set but no header → exactly one inner fetch.
- Already in sync → no inner fetch.
- Mismatch on cold-start with header already seen → fires inner once, persists new hash.
- Idempotency: two rapid prime() calls → exactly one inner fetch (in-flight dedup).
- Post-success no-op: after successful prime, second prime returns immediately.
- Post-success no-op requires localHash !== null — if persist did not happen (no header), second prime CAN fire again (pins the localHash !== null clause of the guard).

Middleware-driven trigger (new group):

- Response with hash differing from localHash (cold + warm) → middleware fires inner exactly once and updates persisted hash on success.
- Response with hash equal to localHash → middleware does NOT fire inner.
- Response with header missing/malformed (5a/5b/5c) → middleware does NOT fire inner.

prime + middleware race coordination (new group):

- Mid-flight response arriving during a prime() call → ONE inner fetch via shared in-flight ref (v1 once-per-burst contract; later mismatches handled by the NEXT header).

Persist-after-success timing (rewritten):

- ONLY after inner success does storageService.put fire — verified with a pending Promise that holds the inner fetch open so we can assert the negative before resolving.
- Inner rejection (prime path) → no persist; rejection surfaces to caller.
- Inner rejection (middleware path) → no persist; rejection swallowed (fire-and-forget; no unhandled-rejection escape).

Idempotent middleware registration (rewritten):

- Existing assertions preserved; entry-point swapped from retrieveAll() to prime().

Parser branches (rewritten):

- All malformed-header tests now drive through prime() instead of retrieveAll. Setup-rig comment updated to describe the new entry point.

Exception-safe response middleware (Architecture Lock #10, rewritten):

- Existing 5a/5b/5c contract-pin tests preserved (no longer chain to a removed retrieveAll on the rig, just verify no-throw on delivery).
- 5-success: rewritten to await store.prime() so the assertion rendezvous with the middleware-triggered inner fetch.
- NEW: inner.retrieveAll rejection on the middleware path does NOT propagate back through the middleware — verified via `process.on('unhandledRejection', ...)` capturing during microtask drain.

types.spec.ts (rewritten):

- Asserts the factory's return type is `CachedStoreModuleForAdapter<DemoItem, DemoAdapted, DemoNewAdapted>` (was `StoreModuleForAdapter<...>`).
- Adds a `@ts-expect-error` assertion that the wrapper's return is NOT assignable to `StoreModuleForAdapter<...>`. If a future refactor re-adds retrieveAll/retrieveById, the directive becomes unused and tsc errors out.
- Type-test body guarded by `if (false as boolean)` so the type-level assignment is checked but the runtime call into the real factory (against an empty config) never executes.

Test count: 69 → 80 (+11, well above the order's ≥69 baseline).
Coverage: 100% statements/branches/functions/lines on src/cached-adapter-store.ts and src/types.ts.
Mutation: 94.81% on cached-adapter-store.ts (≥90% threshold; 4 surviving mutants are documented equivalent — parser try/catch fall-throughs and the post-success hasCompletedAtLeastOnce/early-return optimization, observationally indistinguishable from the unmutated form because skip-when-equal in triggerInnerRetrieveAll catches the same case).
Goosterhof added a commit that referenced this pull request May 15, 2026
…iddleware-driven trigger

Public-API surface tests (new):

- Returned module has exactly {getAll, getById, getOrFailById, generateNew, prime} — five enumerable keys.
- `expect(store).not.toHaveProperty('retrieveAll')` — verifies the narrowing.
- `expect(store).not.toHaveProperty('retrieveById')` — verifies the narrowing.

prime() behavior (new group):

- Cold start (localHash null, no header) → exactly one inner fetch.
- localHash set but no header → exactly one inner fetch.
- Already in sync → no inner fetch.
- Mismatch on cold-start with header already seen → fires inner once, persists new hash.
- Idempotency: two rapid prime() calls → exactly one inner fetch (in-flight dedup).
- Post-success no-op: after successful prime, second prime returns immediately.
- Post-success no-op requires localHash !== null — if persist did not happen (no header), second prime CAN fire again (pins the localHash !== null clause of the guard).

Middleware-driven trigger (new group):

- Response with hash differing from localHash (cold + warm) → middleware fires inner exactly once and updates persisted hash on success.
- Response with hash equal to localHash → middleware does NOT fire inner.
- Response with header missing/malformed (5a/5b/5c) → middleware does NOT fire inner.

prime + middleware race coordination (new group):

- Mid-flight response arriving during a prime() call → ONE inner fetch via shared in-flight ref (v1 once-per-burst contract; later mismatches handled by the NEXT header).

Persist-after-success timing (rewritten):

- ONLY after inner success does storageService.put fire — verified with a pending Promise that holds the inner fetch open so we can assert the negative before resolving.
- Inner rejection (prime path) → no persist; rejection surfaces to caller.
- Inner rejection (middleware path) → no persist; rejection swallowed (fire-and-forget; no unhandled-rejection escape).

Idempotent middleware registration (rewritten):

- Existing assertions preserved; entry-point swapped from retrieveAll() to prime().

Parser branches (rewritten):

- All malformed-header tests now drive through prime() instead of retrieveAll. Setup-rig comment updated to describe the new entry point.

Exception-safe response middleware (Architecture Lock #10, rewritten):

- Existing 5a/5b/5c contract-pin tests preserved (no longer chain to a removed retrieveAll on the rig, just verify no-throw on delivery).
- 5-success: rewritten to await store.prime() so the assertion rendezvous with the middleware-triggered inner fetch.
- NEW: inner.retrieveAll rejection on the middleware path does NOT propagate back through the middleware — verified via `process.on('unhandledRejection', ...)` capturing during microtask drain.

types.spec.ts (rewritten):

- Asserts the factory's return type is `CachedStoreModuleForAdapter<DemoItem, DemoAdapted, DemoNewAdapted>` (was `StoreModuleForAdapter<...>`).
- Adds a `@ts-expect-error` assertion that the wrapper's return is NOT assignable to `StoreModuleForAdapter<...>`. If a future refactor re-adds retrieveAll/retrieveById, the directive becomes unused and tsc errors out.
- Type-test body guarded by `if (false as boolean)` so the type-level assignment is checked but the runtime call into the real factory (against an empty config) never executes.

Test count: 69 → 80 (+11, well above the order's ≥69 baseline).
Coverage: 100% statements/branches/functions/lines on src/cached-adapter-store.ts and src/types.ts.
Mutation: 94.81% on cached-adapter-store.ts (≥90% threshold; 4 surviving mutants are documented equivalent — parser try/catch fall-throughs and the post-success hasCompletedAtLeastOnce/early-return optimization, observationally indistinguishable from the unmutated form because skip-when-equal in triggerInnerRetrieveAll catches the same case).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant