mates 0.4.1 → 0.4.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.
@@ -1,4 +1,5 @@
1
1
  export * from "./ssr-bridge";
2
2
  export * from "./ssrFlag";
3
+ export * from "./ssr-render-store";
3
4
  export * from "./useCtx";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC"}
@@ -1,42 +1,8 @@
1
1
  /**
2
2
  * mates — ssr/ssr-bridge.ts
3
3
  *
4
- * A tiny, zero-dependency module that holds two pieces of shared state
5
- * needed for the Fetch SSR shortcut:
6
- *
7
- * _ssrApiLookup — a function wired in by mates-ssr at server startup.
8
- * When set, FetchClient.fetch() calls API handlers
9
- * directly instead of making real HTTP requests.
10
- *
11
- * _ssrRequest — the original HTTP Request for the current SSR render
12
- * pass. Set by mates-ssr's server before each renderPage()
13
- * call so that Fetch can forward cookies / auth headers
14
- * to directly-called API handlers.
15
- *
16
- * Why a separate file?
17
- *
18
- * mates-ssr's server.ts needs to import these setters at the top level.
19
- * server.ts is re-exported through mates-ssr's index.ts, which is imported
20
- * by the user's mates.config.ts — BEFORE bootRenderer() has been called
21
- * and BEFORE happy-dom has patched globalThis.document.
22
- *
23
- * If the setters lived in Fetch.ts, importing them would pull in the entire
24
- * mates bundle (lit-html, x-view custom element, etc.) at config-load time,
25
- * triggering "document is not defined" before the DOM shim is ready.
26
- *
27
- * This file has NO imports whatsoever. It is safe to import at any point
28
- * in the process lifecycle, including before bootRenderer().
29
- *
30
- * Consumers:
31
- * - mates/lib/Fetch/Fetch.ts reads _ssrApiLookup and _ssrRequest
32
- * - mates-ssr/src/server.ts writes both via the exported setters
33
- * - mates/lib/index.ts re-exports the setters as public API
34
- */
35
- /**
36
- * The shape of the API handler lookup function supplied by mates-ssr.
37
- *
38
- * Takes a method ("GET", "POST", …) and a pathname ("/api/users") and
39
- * returns the matching handler + route context, or null when nothing matches.
4
+ * API lookup + request for Fetch SSR shortcut.
5
+ * Per-render values come from AsyncLocalStorage when mates-ssr is active.
40
6
  */
41
7
  export type ApiLookupFn = (method: string, pathname: string) => {
42
8
  handler: (req: Request, ctx: {
@@ -46,44 +12,8 @@ export type ApiLookupFn = (method: string, pathname: string) => {
46
12
  params: Record<string, string>;
47
13
  };
48
14
  } | null;
49
- /**
50
- * Wire in the API handler registry from mates-ssr.
51
- *
52
- * Called once by mates-ssr's startServer() after scanning src/api/.
53
- * Pass null on server shutdown to unregister.
54
- *
55
- * @example
56
- * // mates-ssr/src/server.ts
57
- * import { setSSRApiLookup } from "mates";
58
- * setSSRApiLookup(lookupApiHandler); // startup
59
- * setSSRApiLookup(null); // shutdown
60
- */
61
15
  export declare function setSSRApiLookup(fn: ApiLookupFn | null): void;
62
- /**
63
- * Store the original HTTP Request for the current SSR render pass.
64
- *
65
- * Called by mates-ssr's renderPage() immediately before the component
66
- * outer function runs, and cleared (null) in the finally block.
67
- *
68
- * Fetch.ts reads this to forward cookies and auth headers to directly-
69
- * called API handlers so the handler sees real auth state.
70
- *
71
- * @example
72
- * // mates-ssr/src/server.ts
73
- * import { setSSRRequest } from "mates";
74
- * setSSRRequest(req); // before render
75
- * setSSRRequest(null); // after render (finally block)
76
- */
77
16
  export declare function setSSRRequest(req: Request | null): void;
78
- /**
79
- * Returns the currently wired API lookup function, or null when not set.
80
- * Called on every FetchClient.fetch() call during SSR.
81
- */
82
17
  export declare function getSSRApiLookup(): ApiLookupFn | null;
83
- /**
84
- * Returns the original HTTP Request for the current SSR render pass,
85
- * or null when called outside an SSR context.
86
- * Called by FetchClient.fetch() to forward auth headers.
87
- */
88
18
  export declare function getSSRRequest(): Request | null;
89
19
  //# sourceMappingURL=ssr-bridge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-bridge.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssr-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,KACb;IACH,OAAO,EAAE,CACP,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,KACpC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvB,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CACzC,GAAG,IAAI,CAAC;AAST;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAE5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAEvD;AAID;;;GAGG;AACH,wBAAgB,eAAe,IAAI,WAAW,GAAG,IAAI,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,GAAG,IAAI,CAE9C"}
1
+ {"version":3,"file":"ssr-bridge.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssr-bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,MAAM,WAAW,GAAG,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,KACb;IACH,OAAO,EAAE,CACP,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,KACpC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvB,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CACzC,GAAG,IAAI,CAAC;AAMT,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAG5D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAGvD;AAED,wBAAgB,eAAe,IAAI,WAAW,GAAG,IAAI,CAIpD;AAED,wBAAgB,aAAa,IAAI,OAAO,GAAG,IAAI,CAI9C"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * mates — ssr-render-store.ts
3
+ *
4
+ * Per-render SSR state accessor (AsyncLocalStorage-backed in mates-ssr).
5
+ * Browser-safe: no node:async_hooks import here.
6
+ */
7
+ import type { ApiLookupFn } from "./ssr-bridge.js";
8
+ export interface SsrRenderStore {
9
+ /** Nesting depth for nested render calls within one request. */
10
+ depth: number;
11
+ asyncCounter: number;
12
+ doneCallback: (() => void) | null;
13
+ doneTimer: ReturnType<typeof setTimeout> | null;
14
+ request: Request | null;
15
+ apiLookup: ApiLookupFn | null;
16
+ }
17
+ export interface SsrRenderAccessor {
18
+ getStore(): SsrRenderStore | undefined;
19
+ }
20
+ /** @internal Registered by mates-ssr at startup. */
21
+ export declare function registerSsrRenderAccessor(accessor: SsrRenderAccessor | null): void;
22
+ export declare function getActiveSsrRenderStore(): SsrRenderStore | undefined;
23
+ //# sourceMappingURL=ssr-render-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-render-store.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssr-render-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAClC,SAAS,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC;IAChD,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,WAAW,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,IAAI,cAAc,GAAG,SAAS,CAAC;CACxC;AAID,oDAAoD;AACpD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,GACjC,IAAI,CAGN;AAED,wBAAgB,uBAAuB,IAAI,cAAc,GAAG,SAAS,CAKpE"}
@@ -1,73 +1,25 @@
1
1
  /**
2
2
  * mates — SSR mode flag + async completion tracking
3
3
  *
4
- * SSR mode flag:
5
- * A simple global boolean that browser-only hooks check before doing work.
6
- * When `setSSRMode(true)` is called (by mates-ssr's renderer before rendering),
7
- * hooks like onBlur, onFocus, onResize, onInterval, etc. skip their work
8
- * entirely — no event listeners, no timers, no observers.
9
- *
10
- * SSR async completion tracking:
11
- * Tracks in-flight asyncAction and Fetch calls during SSR.
12
- * When all async work completes (counter hits 0), a 5ms debounce fires
13
- * the registered done callback so the renderer knows it's safe to serialize.
14
- *
15
- * asyncAction and Fetch call incrementSsrAsyncCounter() on start and
16
- * decrementSsrAsyncCounter() on finish (success or error).
17
- *
18
- * The renderer registers a callback via setSsrDoneCallback() before rendering.
19
- * Users can also call done() explicitly to signal early completion.
4
+ * Per-render state lives in AsyncLocalStorage when mates-ssr is loaded
5
+ * (via registerSsrRenderAccessor). Legacy module-level fallbacks remain for
6
+ * tests and direct renderToString() without a render context.
20
7
  */
21
8
  /**
22
- * Enable or disable SSR mode.
23
- * When enabled, browser-only hooks become no-ops.
9
+ * Enable or disable SSR mode (legacy / standalone renders).
10
+ * When mates-ssr wraps a render in AsyncLocalStorage, this is a no-op.
24
11
  */
25
12
  export declare function setSSRMode(value: boolean): void;
26
- /**
27
- * Returns true when the framework is running inside an SSR render pass.
28
- * Hooks should check this and bail early if true.
29
- */
13
+ /** Returns true during an SSR render pass. */
30
14
  export declare function isSSR(): boolean;
31
- /**
32
- * Register the callback the renderer will invoke when all async work is done.
33
- * Called by the renderer once per render pass, before setup runs.
34
- * @internal
35
- */
15
+ /** @internal */
36
16
  export declare function setSsrDoneCallback(cb: () => void): void;
37
- /**
38
- * Increment the in-flight counter.
39
- * Called by asyncAction and Fetch when they start an async operation during SSR.
40
- * @internal
41
- */
17
+ /** @internal */
42
18
  export declare function incrementSsrAsyncCounter(): void;
43
- /**
44
- * Decrement the in-flight counter.
45
- * Called by asyncAction and Fetch when they finish (success or error).
46
- * When counter hits 0, schedules the done callback with a 5ms debounce.
47
- * @internal
48
- */
19
+ /** @internal */
49
20
  export declare function decrementSsrAsyncCounter(): void;
50
- /**
51
- * Explicitly signal that the component is done with all async work.
52
- * Call this if you have async work that happens outside asyncAction/Fetch
53
- * and the renderer should not wait longer.
54
- *
55
- * @example
56
- * export default (_: Props<{}>) => {
57
- * const data = asyncAction(fetchData);
58
- * data();
59
- *
60
- * // If you have additional async work tracked manually:
61
- * done();
62
- *
63
- * return () => html`...`;
64
- * };
65
- */
21
+ /** Signal early completion for custom async outside asyncAction/Fetch. */
66
22
  export declare function done(): void;
67
- /**
68
- * Returns the current number of in-flight SSR async operations.
69
- * Useful for debugging and tests.
70
- */
71
23
  export declare function getSsrAsyncCounter(): number;
72
24
  export declare function isDev(): boolean;
73
25
  //# sourceMappingURL=ssrFlag.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrFlag.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssrFlag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAQ/C;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAgBD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAOvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAI/C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,IAAI,IAAI,CAS3B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAqBD,wBAAgB,KAAK,IAAI,OAAO,CAQ/B"}
1
+ {"version":3,"file":"ssrFlag.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssrFlag.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6FH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAI/C;AAED,8CAA8C;AAC9C,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAIvD;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,IAAI,IAAI,CAI/C;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,IAAI,IAAI,CAI/C;AAED,0EAA0E;AAC1E,wBAAgB,IAAI,IAAI,IAAI,CAO3B;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAmBD,wBAAgB,KAAK,IAAI,OAAO,CAQ/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mates",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Mates is a front end framework for building web applications",
6
6
  "main": "dist/index.js",