@taujs/server 0.5.3 → 0.5.4

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.
@@ -7,10 +7,10 @@ type DebugConfig = boolean | DebugCategory[] | ({
7
7
  all?: boolean;
8
8
  } & Partial<Record<DebugCategory, boolean>>);
9
9
  interface BaseLogger {
10
- debug?(meta?: Record<string, unknown>, message?: string): void;
11
- info?(meta?: Record<string, unknown>, message?: string): void;
12
- warn?(meta?: Record<string, unknown>, message?: string): void;
13
- error?(meta?: Record<string, unknown>, message?: string): void;
10
+ debug?(meta?: unknown, message?: string): void;
11
+ info?(meta?: unknown, message?: string): void;
12
+ warn?(meta?: unknown, message?: string): void;
13
+ error?(meta?: unknown, message?: string): void;
14
14
  child?(context: Record<string, unknown>): BaseLogger;
15
15
  }
16
16
  interface Logs extends BaseLogger {
@@ -67,19 +67,20 @@ declare function callServiceMethod(registry: ServiceRegistry, serviceName: strin
67
67
  type RequestContext<L extends Logs = Logs> = {
68
68
  traceId: string;
69
69
  logger: L;
70
- headers: Record<string, string>;
70
+ headers?: Record<string, string>;
71
71
  };
72
72
 
73
+ type PathToRegExpParams = Partial<Record<string, string | string[]>>;
73
74
  type RouteCSPConfig = {
74
75
  disabled?: boolean;
75
76
  mode?: 'merge' | 'replace';
76
- directives?: CSPDirectives | ((args: {
77
+ directives?: unknown | ((args: {
77
78
  url: string;
78
79
  params: PathToRegExpParams;
79
- headers: FastifyRequest['headers'];
80
- req: FastifyRequest;
81
- }) => CSPDirectives);
82
- generateCSP?: (directives: CSPDirectives, nonce: string, req: FastifyRequest) => string;
80
+ headers: Record<string, string>;
81
+ req?: unknown;
82
+ }) => unknown);
83
+ generateCSP?: (directives: unknown, nonce: string, req?: unknown) => string;
83
84
  reportOnly?: boolean;
84
85
  };
85
86
  type BaseMiddleware = {
@@ -91,14 +92,15 @@ type BaseMiddleware = {
91
92
  csp?: RouteCSPConfig | false;
92
93
  };
93
94
  type DataResult = Record<string, unknown> | ServiceDescriptor;
94
- type RequestServiceContext<L extends Logs = Logs> = RequestContext<L> & {
95
- call: RegistryCaller<ServiceRegistry>;
96
- headers?: Record<string, string>;
95
+ type RequestServiceContext<L extends Logs = Logs> = ServiceContext & RequestContext<L> & {
96
+ call?: RegistryCaller<ServiceRegistry>;
97
+ headers: Record<string, string>;
97
98
  };
98
- type DataHandler<Params extends PathToRegExpParams, L extends Logs = Logs> = (params: Params, ctx: RequestServiceContext<L> & {
99
+ type DataHandler<Params extends PathToRegExpParams, L extends Logs = Logs> = (params: Params, ctx: (RequestServiceContext<L> & {
100
+ call: RegistryCaller<ServiceRegistry>;
101
+ }) & {
99
102
  [key: string]: unknown;
100
103
  }) => Promise<DataResult>;
101
- type PathToRegExpParams = Partial<Record<string, string | string[]>>;
102
104
  type RouteAttributes<Params extends PathToRegExpParams = PathToRegExpParams, Middleware = BaseMiddleware, L extends Logs = Logs> = {
103
105
  render: 'ssr';
104
106
  hydrate?: boolean;
@@ -117,10 +119,6 @@ type Route<Params extends PathToRegExpParams = PathToRegExpParams> = {
117
119
  path: string;
118
120
  appId?: string;
119
121
  };
120
- interface InitialRouteParams extends Record<string, unknown> {
121
- serviceName?: string;
122
- serviceMethod?: string;
123
- }
124
122
  type AppId<C extends {
125
123
  apps: readonly {
126
124
  appId: string;
@@ -152,16 +150,46 @@ type SingleRouteContext<C extends {
152
150
  attr?: infer Attr;
153
151
  } ? Attr : never;
154
152
  } : never;
155
- type RouteContext<C extends {
153
+ type RouteContext$1<C extends {
156
154
  apps: readonly any[];
157
155
  }> = {
158
156
  [A in AppId<C>]: SingleRouteContext<C, A, RoutesOfApp<C, A>>;
159
157
  }[AppId<C>];
160
- type RouteData<C extends {
158
+ type RouteData$1<C extends {
161
159
  apps: readonly any[];
162
- }, Path extends string> = Extract<RouteContext<C>, {
160
+ }, Path extends string> = Extract<RouteContext$1<C>, {
163
161
  path: Path;
164
162
  }>['data'];
163
+ type CoreSecurityConfig = {
164
+ csp?: {
165
+ defaultMode?: 'merge' | 'replace';
166
+ directives?: unknown;
167
+ generateCSP?: (directives: unknown, nonce: string, req?: unknown) => string;
168
+ reporting?: {
169
+ endpoint: string;
170
+ onViolation?: (report: unknown, req: unknown) => void;
171
+ reportOnly?: boolean;
172
+ };
173
+ };
174
+ };
175
+ type AppRoute = Omit<Route<PathToRegExpParams>, 'appId'> & {
176
+ attr?: RouteAttributes<PathToRegExpParams>;
177
+ };
178
+ type CoreAppConfig = {
179
+ appId: string;
180
+ entryPoint: string;
181
+ plugins?: readonly unknown[];
182
+ routes?: readonly AppRoute[];
183
+ };
184
+ type CoreTaujsConfig = {
185
+ apps: readonly CoreAppConfig[];
186
+ security?: CoreSecurityConfig;
187
+ server?: {
188
+ host?: string;
189
+ port?: number;
190
+ hmrPort?: number;
191
+ };
192
+ };
165
193
 
166
194
  type CSPDirectives = Record<string, string[]>;
167
195
 
@@ -206,17 +234,7 @@ declare class AppError extends Error {
206
234
  static from(err: unknown, fallback?: string): AppError;
207
235
  }
208
236
 
209
- /**
210
- * τjs [ taujs ] Orchestration System
211
- * (c) 2024-present Aoede Ltd
212
- * Author: John Smith
213
- *
214
- * Licensed under the MIT License - attribution appreciated.
215
- * Part of the τjs [ taujs ] system for declarative, build-time orchestration of microfrontend applications,
216
- * including CSR, SSR, streaming, and middleware composition.
217
- */
218
-
219
- type SecurityConfig = {
237
+ type SecurityConfig = CoreSecurityConfig & {
220
238
  csp?: {
221
239
  defaultMode?: 'merge' | 'replace';
222
240
  directives?: CSPDirectives;
@@ -228,25 +246,18 @@ type SecurityConfig = {
228
246
  };
229
247
  };
230
248
  };
231
- type AppRoute = Omit<Route<PathToRegExpParams>, 'appId'> & {
232
- attr?: RouteAttributes<PathToRegExpParams>;
233
- };
234
- type AppConfig = {
235
- appId: string;
236
- entryPoint: string;
249
+ type AppConfig = CoreAppConfig & {
237
250
  plugins?: PluginOption[];
238
251
  routes?: readonly AppRoute[];
239
252
  };
240
- type TaujsConfig = {
253
+ type TaujsConfig = CoreTaujsConfig & {
241
254
  apps: readonly AppConfig[];
242
255
  security?: SecurityConfig;
243
- server?: {
244
- host?: string;
245
- port?: number;
246
- hmrPort?: number;
247
- };
248
256
  };
249
257
 
250
- declare function defineConfig<const C>(config: C & TaujsConfig): C;
258
+ type RouteContext = RouteContext$1<TaujsConfig>;
259
+ type RouteData<C extends TaujsConfig = TaujsConfig, P extends string = string> = RouteData$1<C, P>;
260
+
261
+ declare function defineConfig<const C extends TaujsConfig>(config: C): C;
251
262
 
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 };
263
+ export { type AppConfig as A, type BaseLogger as B, type CoreAppConfig as C, type DebugConfig as D, type RouteContext as R, type ServiceRegistry as S, type TaujsConfig as T, type SecurityConfig as a, type RouteData as b, callServiceMethod as c, defineConfig as d, defineService as e, defineServiceRegistry as f, type RegistryCaller as g, type ServiceContext as h, AppError as i, 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, 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';
3
+ export { A as AppConfig, i as AppError, g as RegistryCaller, R as RouteContext, b as RouteData, a as SecurityConfig, h as ServiceContext, T as TaujsConfig, c as callServiceMethod, d as defineConfig, e as defineService, f as defineServiceRegistry, w as withDeadline } from './Config-2Loymxo2.js';
package/dist/Config.js CHANGED
@@ -1,7 +1,4 @@
1
- // src/utils/DataServices.ts
2
- import { performance } from "perf_hooks";
3
-
4
- // src/logging/AppError.ts
1
+ // src/core/errors/AppError.ts
5
2
  var HTTP_STATUS = {
6
3
  infra: 500,
7
4
  upstream: 502,
@@ -111,7 +108,27 @@ var AppError = class _AppError extends Error {
111
108
  }
112
109
  };
113
110
 
114
- // src/utils/DataServices.ts
111
+ // src/core/logging/noop.ts
112
+ var noopLogger = {
113
+ debug: () => {
114
+ },
115
+ info: () => {
116
+ },
117
+ warn: () => {
118
+ },
119
+ error: () => {
120
+ },
121
+ child: () => noopLogger,
122
+ isDebugEnabled: () => false
123
+ };
124
+
125
+ // src/core/logging/resolve.ts
126
+ var resolveLogs = (logger) => logger ?? noopLogger;
127
+
128
+ // src/core/telemetry/Telemetry.ts
129
+ var now = () => globalThis.performance?.now?.() ?? Date.now();
130
+
131
+ // src/core/services/DataServices.ts
115
132
  var runSchema = (schema, input) => {
116
133
  if (!schema) return input;
117
134
  return typeof schema.parse === "function" ? schema.parse(input) : schema(input);
@@ -155,26 +172,27 @@ async function callServiceMethod(registry, serviceName, methodName, params, ctx)
155
172
  if (!service) throw AppError.notFound(`Unknown service: ${serviceName}`);
156
173
  const method = service[methodName];
157
174
  if (!method) throw AppError.notFound(`Unknown method: ${serviceName}.${methodName}`);
158
- const logger = ctx.logger?.child?.({
175
+ const baseLogger = resolveLogs(ctx.logger);
176
+ const logger = baseLogger.child({
159
177
  component: "service-call",
160
178
  service: serviceName,
161
179
  method: methodName,
162
180
  traceId: ctx.traceId
163
181
  });
164
- const t0 = performance.now();
182
+ const t0 = now();
165
183
  try {
166
184
  const result = await method(params ?? {}, ctx);
167
185
  if (typeof result !== "object" || result === null) {
168
186
  throw AppError.internal(`Non-object result from ${serviceName}.${methodName}`);
169
187
  }
170
- logger?.debug?.({ ms: +(performance.now() - t0).toFixed(1) }, "Service method ok");
188
+ logger.debug({ ms: +(now() - t0).toFixed(1) }, "Service method ok");
171
189
  return result;
172
190
  } catch (err) {
173
- logger?.error?.(
191
+ logger.error(
174
192
  {
175
193
  params,
176
194
  error: err instanceof Error ? { name: err.name, message: err.message, stack: err.stack } : String(err),
177
- ms: +(performance.now() - t0).toFixed(1)
195
+ ms: +(now() - t0).toFixed(1)
178
196
  },
179
197
  "Service method failed"
180
198
  );
package/dist/index.d.ts CHANGED
@@ -1,20 +1,19 @@
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-DHz6Lax2.js';
3
- export { I as InitialRouteParams } from './Config-DHz6Lax2.js';
2
+ import { T as TaujsConfig, S as ServiceRegistry, D as DebugConfig, B as BaseLogger, C as CoreAppConfig } from './Config-2Loymxo2.js';
4
3
  import { InlineConfig } from 'vite';
5
4
 
6
- type StaticMountEntry = {
7
- plugin: FastifyPluginCallback<any> | FastifyPluginAsync<any>;
8
- options?: Record<string, unknown>;
9
- };
10
- type StaticAssetsRegistration = false | StaticMountEntry | StaticMountEntry[];
11
-
12
5
  type NetResolved = {
13
6
  host: string;
14
7
  port: number;
15
8
  hmrPort: number;
16
9
  };
17
10
 
11
+ type StaticMountEntry = {
12
+ plugin: FastifyPluginCallback<any> | FastifyPluginAsync<any>;
13
+ options?: Record<string, unknown>;
14
+ };
15
+ type StaticAssetsRegistration = false | StaticMountEntry | StaticMountEntry[];
16
+
18
17
  type CreateServerOptions = {
19
18
  config: TaujsConfig;
20
19
  serviceRegistry?: ServiceRegistry;
@@ -95,7 +94,7 @@ type ViteBuildContext = {
95
94
  type ViteConfigOverride = Partial<InlineConfig> | ((ctx: ViteBuildContext) => Partial<InlineConfig>);
96
95
  declare function taujsBuild({ config, projectRoot, clientBaseDir, isSSRBuild, alias: userAlias, vite: userViteConfig, }: {
97
96
  config: {
98
- apps: readonly AppConfig[];
97
+ apps: readonly CoreAppConfig[];
99
98
  };
100
99
  projectRoot: string;
101
100
  clientBaseDir: string;
@@ -131,4 +130,9 @@ interface MessageMetaLogger {
131
130
  }
132
131
  declare function winstonAdapter(winston: MessageMetaLogger): BaseLogger;
133
132
 
134
- export { BaseLogger, createServer, taujsBuild, winstonAdapter };
133
+ interface InitialRouteParams extends Record<string, unknown> {
134
+ serviceName?: string;
135
+ serviceMethod?: string;
136
+ }
137
+
138
+ export { BaseLogger, type InitialRouteParams, createServer, taujsBuild, winstonAdapter };