@taujs/server 0.4.6 → 0.4.7

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.
@@ -121,6 +121,47 @@ interface InitialRouteParams extends Record<string, unknown> {
121
121
  serviceName?: string;
122
122
  serviceMethod?: string;
123
123
  }
124
+ type AppId<C extends {
125
+ apps: readonly {
126
+ appId: string;
127
+ }[];
128
+ }> = C['apps'][number]['appId'];
129
+ type AppOf<C extends {
130
+ apps: readonly any[];
131
+ }, A extends AppId<C>> = Extract<C['apps'][number], {
132
+ appId: A;
133
+ }>;
134
+ type RoutesOfApp<C extends {
135
+ apps: readonly any[];
136
+ }, A extends AppId<C>> = AppOf<C, A>['routes'] extends readonly any[] ? AppOf<C, A>['routes'][number] : never;
137
+ type RouteDataOf<R> = R extends {
138
+ attr?: {
139
+ data?: (...args: any) => infer Ret;
140
+ };
141
+ } ? Awaited<Ret> : unknown;
142
+ type RoutePathOf<R> = R extends {
143
+ path: infer P;
144
+ } ? P : never;
145
+ type SingleRouteContext<C extends {
146
+ apps: readonly any[];
147
+ }, A extends AppId<C>, R extends RoutesOfApp<C, A>> = R extends any ? {
148
+ appId: A;
149
+ path: RoutePathOf<R>;
150
+ data: RouteDataOf<R>;
151
+ attr: R extends {
152
+ attr?: infer Attr;
153
+ } ? Attr : never;
154
+ } : never;
155
+ type RouteContext<C extends {
156
+ apps: readonly any[];
157
+ }> = {
158
+ [A in AppId<C>]: SingleRouteContext<C, A, RoutesOfApp<C, A>>;
159
+ }[AppId<C>];
160
+ type RouteData<C extends {
161
+ apps: readonly any[];
162
+ }, Path extends string> = Extract<RouteContext<C>, {
163
+ path: Path;
164
+ }>['data'];
124
165
 
125
166
  type CSPDirectives = Record<string, string[]>;
126
167
 
@@ -194,10 +235,10 @@ type AppConfig = {
194
235
  appId: string;
195
236
  entryPoint: string;
196
237
  plugins?: PluginOption[];
197
- routes?: AppRoute[];
238
+ routes?: readonly AppRoute[];
198
239
  };
199
240
  type TaujsConfig = {
200
- apps: AppConfig[];
241
+ apps: readonly AppConfig[];
201
242
  security?: SecurityConfig;
202
243
  server?: {
203
244
  host?: string;
@@ -206,6 +247,6 @@ type TaujsConfig = {
206
247
  };
207
248
  };
208
249
 
209
- declare function defineConfig<T extends TaujsConfig>(config: T): T;
250
+ declare function defineConfig<const C>(config: C & TaujsConfig): C;
210
251
 
211
- export { type AppConfig as A, type BaseLogger as B, type DebugConfig as D, type InitialRouteParams as I, type RegistryCaller as R, type ServiceRegistry as S, type TaujsConfig as T, type SecurityConfig as a, type AppRoute as b, callServiceMethod as c, defineConfig as d, defineService as e, defineServiceRegistry as f, type ServiceContext as g, AppError as h, withDeadline as w };
252
+ export { type AppConfig as A, type BaseLogger as B, type DebugConfig as D, type InitialRouteParams as I, type RegistryCaller as R, type ServiceRegistry as S, type TaujsConfig as T, type SecurityConfig as a, type AppRoute as b, callServiceMethod as c, defineConfig as d, defineService as e, defineServiceRegistry as f, type ServiceContext as g, type RouteContext as h, type RouteData as i, AppError as j, withDeadline as w };
package/dist/Config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'fastify';
2
2
  import 'vite';
3
- export { A as AppConfig, h as AppError, b as AppRoute, R as RegistryCaller, a as SecurityConfig, g as ServiceContext, T as TaujsConfig, c as callServiceMethod, d as defineConfig, e as defineService, f as defineServiceRegistry, w as withDeadline } from './Config-CEhfq8Mm.js';
3
+ export { A as AppConfig, j as AppError, b as AppRoute, R as RegistryCaller, h as RouteContext, i as RouteData, a as SecurityConfig, g as ServiceContext, T as TaujsConfig, c as callServiceMethod, d as defineConfig, e as defineService, f as defineServiceRegistry, w as withDeadline } from './Config-DHz6Lax2.js';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FastifyPluginCallback, FastifyPluginAsync, FastifyInstance } from 'fastify';
2
- import { T as TaujsConfig, S as ServiceRegistry, D as DebugConfig, B as BaseLogger, A as AppConfig } from './Config-CEhfq8Mm.js';
3
- export { I as InitialRouteParams } from './Config-CEhfq8Mm.js';
2
+ import { T as TaujsConfig, S as ServiceRegistry, D as DebugConfig, B as BaseLogger, A as AppConfig } from './Config-DHz6Lax2.js';
3
+ export { I as InitialRouteParams } from './Config-DHz6Lax2.js';
4
4
  import { InlineConfig } from 'vite';
5
5
 
6
6
  type StaticMountEntry = {
package/dist/index.js CHANGED
@@ -1576,6 +1576,12 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
1576
1576
  }
1577
1577
  const { route, params } = matchedRoute;
1578
1578
  const { attr, appId } = route;
1579
+ const routeContext = {
1580
+ appId,
1581
+ path: route.path,
1582
+ attr,
1583
+ params
1584
+ };
1579
1585
  const config = processedConfigs.find((c) => c.appId === appId);
1580
1586
  if (!config) {
1581
1587
  throw AppError.internal("No configuration found for the request", {
@@ -1645,7 +1651,7 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
1645
1651
  let headContent = "";
1646
1652
  let appHtml = "";
1647
1653
  try {
1648
- const res = await renderSSR(initialDataResolved, req.url, attr?.meta, ac.signal, { logger: reqLogger });
1654
+ const res = await renderSSR(initialDataResolved, req.url, attr?.meta, ac.signal, { logger: reqLogger, routeContext });
1649
1655
  headContent = res.headContent;
1650
1656
  appHtml = res.appHtml;
1651
1657
  logger.debug?.("ssr", {}, "ssr data resolved");
@@ -1794,7 +1800,7 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
1794
1800
  attr?.meta,
1795
1801
  cspNonce,
1796
1802
  ac.signal,
1797
- { logger: reqLogger }
1803
+ { logger: reqLogger, routeContext }
1798
1804
  );
1799
1805
  writable.on("finish", () => {
1800
1806
  if (abortedState.aborted || reply.raw.writableEnded) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taujs/server",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "τjs [ taujs ]",
5
5
  "author": "John Smith | Aoede <taujs@aoede.uk.net> (https://www.aoede.uk.net)",
6
6
  "license": "MIT",