Files
ng-eventually/packages/client/src/polyfill.ts
T
Sylvain Duchesne bb2d9c3e59 Initial scaffold: @ng-eventually/client — SDK-shaped polyfill over NextGraph
Generic polyfill layer that makes a single NextGraph broker behave like the
not-yet-shipped multi-user NextGraph (emulated capabilities + inbox). Zero app domain.

@ng-eventually/client exposes an SDK-identical surface (ng, useShape, inbox); the
polyfill bootstrap (configure + capability helpers) is isolated under /polyfill, so
the main entry stays a drop-in for @ng-org/web|orm. The real SDK is injected at
configure() (no hard import → build-alias safe + testable).

Scaffold: NextGraph wiring stubbed with TODO; capability helpers implemented and
unit-tested (4 tests, typecheck clean). The global-index curator is deferred — in
NextGraph apps/services are mono-user with no global data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 16:35:40 +02:00

50 lines
1.8 KiB
TypeScript

/**
* The polyfill bootstrap — the ONLY non-SDK surface of the client.
*
* It injects the REAL SDK and the polyfill settings; afterwards the SDK-shaped
* exports (`ng`, `useShape`, `inbox`) behave as drop-ins. This is exposed at the
* subpath `@ng-eventually/client/polyfill` so the main entry
* (`@ng-eventually/client`) stays a **pure, SDK-identical** surface. Everything
* here is removed at migration.
*/
import type { NgLike, UseShapeLike, PrincipalId } from "./types";
export interface EventuallyConfig {
/** The REAL `@ng-org/web` `ng` (injected to avoid a hard import / alias loop). */
ng: NgLike;
/** The REAL `@ng-org/orm` `useShape`. */
useShape: UseShapeLike;
/** Shared-wallet credentials — polyfill only (one wallet for everyone). */
sharedWallet?: { name: string; secret: string };
/** Initial current user; may also be set later via {@link setCurrentUser}. */
currentUser?: PrincipalId;
}
let cfg: EventuallyConfig | null = null;
let currentUser: PrincipalId | null = null;
export function configure(c: EventuallyConfig): void {
cfg = c;
currentUser = c.currentUser ?? null;
}
/** @internal — used by the SDK-shaped wrappers to reach the injected real SDK. */
export function getConfig(): EventuallyConfig {
if (!cfg) throw new Error("[ng-eventually] configure() must be called before use");
return cfg;
}
/** Set the current app-level user (the polyfill's notion of "who am I"). */
export function setCurrentUser(id: PrincipalId | null): void {
currentUser = id;
}
export function getCurrentUser(): PrincipalId | null {
return currentUser;
}
// Capability helpers — polyfill-era surface (caps are emulated now; native at
// migration). Re-exported here so the whole polyfill API lives under /polyfill.
export { canRead, canWrite, defaultGrant, grantRead } from "./access";