You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

Build runtime infrastructure layer: aapp + 5 new artifacts Adds the application composition root and six new runtime artifacts. lang and logr alone could not cover an app surface — locale propagation, format helpers, frontend preferences, validation, persistence and DOM service all needed independent artifacts that aapp wires together under a single locale source of truth and a shared logger. New artifacts: - aapp: composition root. createActiveApp + createTestApp + App.createSiumEngine + frontend.persist + Storage wiring. - stor: pluggable adapters (local/session/memory/cookie + SSR via cookieAdapter.fromCookies), envelope versioning + migrate + TTL, validate via Standard Schema, intra-tab + cross-tab sync, Storage.clear(), per-entry adapter/namespace overrides. - adom: reactive DOM service. shareViewport opt-in + per-window tracker, dispose(). breakpoints, viewport, attribute writes. - fend: frontend preferences (theme, mode, dir, density, reducedMotion, reducedSound) with auto/clear/isAuto pattern. - fmts: localized formatting (numbers, currency, units, dates) with shared LocaleSource and per-domain auto/clear pattern. - sium: validation engine. Standard Schema interop, Lang/Logger injection, codec/refine/transform, domain types (color/date/time), introspection. Existing artifacts extended: - lang: BCP 47 SupportedLocale (LangBase | base-region), mono lang for monolingual apps, extend() leaf-overwrite warning, EngineLang/ActiveLang naming alignment with the rest of the project (no Instance suffix). - logr: EngineLogger.dispose(), failureThrottleMs anti-cascade for transports, README sync to the per-level filter API (minLevel removed). Cross-cutting: - $locale: shared LocaleSource type consumed by fmts and fend. - arts/README.md: artifact map, dependency graph, naming conventions. - Test pages for every artifact under /test/<artifact>. 733 tests passing; svelte-check clean except 2 pre-existing errors on sium/svelte provider (port pending). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 months ago
import type { SyncStorageAdapter } from '../types';
import { BROWSER_EVENT_STORAGE, STORAGE_ADAPTER_LOCAL } from '../consts';
Build runtime infrastructure layer: aapp + 5 new artifacts Adds the application composition root and six new runtime artifacts. lang and logr alone could not cover an app surface — locale propagation, format helpers, frontend preferences, validation, persistence and DOM service all needed independent artifacts that aapp wires together under a single locale source of truth and a shared logger. New artifacts: - aapp: composition root. createActiveApp + createTestApp + App.createSiumEngine + frontend.persist + Storage wiring. - stor: pluggable adapters (local/session/memory/cookie + SSR via cookieAdapter.fromCookies), envelope versioning + migrate + TTL, validate via Standard Schema, intra-tab + cross-tab sync, Storage.clear(), per-entry adapter/namespace overrides. - adom: reactive DOM service. shareViewport opt-in + per-window tracker, dispose(). breakpoints, viewport, attribute writes. - fend: frontend preferences (theme, mode, dir, density, reducedMotion, reducedSound) with auto/clear/isAuto pattern. - fmts: localized formatting (numbers, currency, units, dates) with shared LocaleSource and per-domain auto/clear pattern. - sium: validation engine. Standard Schema interop, Lang/Logger injection, codec/refine/transform, domain types (color/date/time), introspection. Existing artifacts extended: - lang: BCP 47 SupportedLocale (LangBase | base-region), mono lang for monolingual apps, extend() leaf-overwrite warning, EngineLang/ActiveLang naming alignment with the rest of the project (no Instance suffix). - logr: EngineLogger.dispose(), failureThrottleMs anti-cascade for transports, README sync to the per-level filter API (minLevel removed). Cross-cutting: - $locale: shared LocaleSource type consumed by fmts and fend. - arts/README.md: artifact map, dependency graph, naming conventions. - Test pages for every artifact under /test/<artifact>. 733 tests passing; svelte-check clean except 2 pre-existing errors on sium/svelte provider (port pending). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 months ago
function getLocalStorage(): Storage | null {
if (typeof window === 'undefined') return null;
return window.localStorage;
}
/**
* `localStorage` adapter. Singleton — the underlying store is process-wide,
* so multiple `EngineStorage` instances over `localAdapter` write to the
* same backend.
*
* `onChange` subscribes to the `storage` event for cross-tab sync. The event
* does **not** fire in the originating tab; intra-tab sync is handled by the
* EntryBus inside `EngineStorage`.
*
* SSR-safe: every method is a no-op outside the browser. Reads return `null`
* so consumers fall back to defaults.
*/
export const localAdapter: SyncStorageAdapter = {
name: STORAGE_ADAPTER_LOCAL,
Build runtime infrastructure layer: aapp + 5 new artifacts Adds the application composition root and six new runtime artifacts. lang and logr alone could not cover an app surface — locale propagation, format helpers, frontend preferences, validation, persistence and DOM service all needed independent artifacts that aapp wires together under a single locale source of truth and a shared logger. New artifacts: - aapp: composition root. createActiveApp + createTestApp + App.createSiumEngine + frontend.persist + Storage wiring. - stor: pluggable adapters (local/session/memory/cookie + SSR via cookieAdapter.fromCookies), envelope versioning + migrate + TTL, validate via Standard Schema, intra-tab + cross-tab sync, Storage.clear(), per-entry adapter/namespace overrides. - adom: reactive DOM service. shareViewport opt-in + per-window tracker, dispose(). breakpoints, viewport, attribute writes. - fend: frontend preferences (theme, mode, dir, density, reducedMotion, reducedSound) with auto/clear/isAuto pattern. - fmts: localized formatting (numbers, currency, units, dates) with shared LocaleSource and per-domain auto/clear pattern. - sium: validation engine. Standard Schema interop, Lang/Logger injection, codec/refine/transform, domain types (color/date/time), introspection. Existing artifacts extended: - lang: BCP 47 SupportedLocale (LangBase | base-region), mono lang for monolingual apps, extend() leaf-overwrite warning, EngineLang/ActiveLang naming alignment with the rest of the project (no Instance suffix). - logr: EngineLogger.dispose(), failureThrottleMs anti-cascade for transports, README sync to the per-level filter API (minLevel removed). Cross-cutting: - $locale: shared LocaleSource type consumed by fmts and fend. - arts/README.md: artifact map, dependency graph, naming conventions. - Test pages for every artifact under /test/<artifact>. 733 tests passing; svelte-check clean except 2 pre-existing errors on sium/svelte provider (port pending). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 months ago
getItem(key) {
return getLocalStorage()?.getItem(key) ?? null;
},
setItem(key, value) {
getLocalStorage()?.setItem(key, value);
},
removeItem(key) {
getLocalStorage()?.removeItem(key);
},
onChange: (fn) => {
if (typeof window === 'undefined') return () => {};
let storage: Storage;
try {
const resolved = getLocalStorage();
if (resolved === null) return () => {};
storage = resolved;
} catch {
return () => {};
}
const listener = (event: StorageEvent): void => {
// Filter out events from sessionStorage / clearAll (key === null).
if (event.storageArea !== storage) return;
if (event.key === null) return;
fn(event.key, event.newValue);
};
window.addEventListener(BROWSER_EVENT_STORAGE, listener);
return () => window.removeEventListener(BROWSER_EVENT_STORAGE, listener);
Build runtime infrastructure layer: aapp + 5 new artifacts Adds the application composition root and six new runtime artifacts. lang and logr alone could not cover an app surface — locale propagation, format helpers, frontend preferences, validation, persistence and DOM service all needed independent artifacts that aapp wires together under a single locale source of truth and a shared logger. New artifacts: - aapp: composition root. createActiveApp + createTestApp + App.createSiumEngine + frontend.persist + Storage wiring. - stor: pluggable adapters (local/session/memory/cookie + SSR via cookieAdapter.fromCookies), envelope versioning + migrate + TTL, validate via Standard Schema, intra-tab + cross-tab sync, Storage.clear(), per-entry adapter/namespace overrides. - adom: reactive DOM service. shareViewport opt-in + per-window tracker, dispose(). breakpoints, viewport, attribute writes. - fend: frontend preferences (theme, mode, dir, density, reducedMotion, reducedSound) with auto/clear/isAuto pattern. - fmts: localized formatting (numbers, currency, units, dates) with shared LocaleSource and per-domain auto/clear pattern. - sium: validation engine. Standard Schema interop, Lang/Logger injection, codec/refine/transform, domain types (color/date/time), introspection. Existing artifacts extended: - lang: BCP 47 SupportedLocale (LangBase | base-region), mono lang for monolingual apps, extend() leaf-overwrite warning, EngineLang/ActiveLang naming alignment with the rest of the project (no Instance suffix). - logr: EngineLogger.dispose(), failureThrottleMs anti-cascade for transports, README sync to the per-level filter API (minLevel removed). Cross-cutting: - $locale: shared LocaleSource type consumed by fmts and fend. - arts/README.md: artifact map, dependency graph, naming conventions. - Test pages for every artifact under /test/<artifact>. 733 tests passing; svelte-check clean except 2 pre-existing errors on sium/svelte provider (port pending). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 months ago
}
};

Powered by TurnKey Linux.