@taujs/server 0.3.1 → 0.3.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.
- package/README.md +3 -3
- package/dist/{SSRServer-C7MMCfVq.d.ts → SSRServer-D_82uJ06.d.ts} +13 -15
- package/dist/build.d.ts +1 -1
- package/dist/build.js +17 -24
- package/dist/config.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -24
- package/dist/security/csp.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,10 +85,10 @@ Integral to τjs is its internal routing:
|
|
|
85
85
|
|
|
86
86
|
In ensuring a particular 'route' receives data for hydration there are two options:
|
|
87
87
|
|
|
88
|
-
1.
|
|
89
|
-
2.
|
|
88
|
+
1. Internal service call returning data as per your architecture
|
|
89
|
+
2. An HTTP call from your app passing resolved data to @taujs/server
|
|
90
90
|
|
|
91
|
-
In supporting Option
|
|
91
|
+
In supporting Option 1. there is a registry of services. More detail in 'Service Registry'.
|
|
92
92
|
|
|
93
93
|
Each routes 'path' is a simple URL regex as per below examples.
|
|
94
94
|
|
|
@@ -79,14 +79,6 @@ type RenderCallbacks = {
|
|
|
79
79
|
onFinish: (initialDataResolved: unknown) => void;
|
|
80
80
|
onError: (error: unknown) => void;
|
|
81
81
|
};
|
|
82
|
-
type FetchConfig = {
|
|
83
|
-
url?: string;
|
|
84
|
-
options: RequestInit & {
|
|
85
|
-
params?: Record<string, unknown>;
|
|
86
|
-
};
|
|
87
|
-
serviceName?: string;
|
|
88
|
-
serviceMethod?: string;
|
|
89
|
-
};
|
|
90
82
|
type SSRManifest = {
|
|
91
83
|
[key: string]: string[];
|
|
92
84
|
};
|
|
@@ -118,22 +110,28 @@ type BaseMiddleware = {
|
|
|
118
110
|
strategy?: string;
|
|
119
111
|
};
|
|
120
112
|
};
|
|
113
|
+
type ServiceCall = {
|
|
114
|
+
serviceName: string;
|
|
115
|
+
serviceMethod: string;
|
|
116
|
+
args?: Record<string, unknown>;
|
|
117
|
+
};
|
|
118
|
+
type DataResult = Record<string, unknown> | ServiceCall;
|
|
119
|
+
type DataHandler<Params> = (params: Params, ctx: {
|
|
120
|
+
headers: Record<string, string>;
|
|
121
|
+
[key: string]: unknown;
|
|
122
|
+
}) => Promise<DataResult>;
|
|
121
123
|
type RouteAttributes<Params = {}, Middleware = BaseMiddleware> = {
|
|
122
124
|
render: 'ssr';
|
|
123
125
|
hydrate?: boolean;
|
|
124
126
|
meta?: Record<string, unknown>;
|
|
125
127
|
middleware?: Middleware;
|
|
126
|
-
|
|
127
|
-
params?: Record<string, unknown>;
|
|
128
|
-
}) => Promise<FetchConfig>;
|
|
128
|
+
data?: DataHandler<Params>;
|
|
129
129
|
} | {
|
|
130
130
|
render: 'streaming';
|
|
131
131
|
hydrate?: never;
|
|
132
132
|
meta: Record<string, unknown>;
|
|
133
133
|
middleware?: Middleware;
|
|
134
|
-
|
|
135
|
-
params?: Record<string, unknown>;
|
|
136
|
-
}) => Promise<FetchConfig>;
|
|
134
|
+
data?: DataHandler<Params>;
|
|
137
135
|
};
|
|
138
136
|
type Route<Params = {}> = {
|
|
139
137
|
attr?: RouteAttributes<Params>;
|
|
@@ -147,4 +145,4 @@ interface InitialRouteParams extends Record<string, unknown> {
|
|
|
147
145
|
type RouteParams = InitialRouteParams & Record<string, unknown>;
|
|
148
146
|
type RoutePathsAndAttributes<Params = {}> = Omit<Route<Params>, 'element'>;
|
|
149
147
|
|
|
150
|
-
export { type BaseMiddleware as B, type Config as C, type
|
|
148
|
+
export { type BaseMiddleware as B, type Config as C, type DataResult as D, type InitialRouteParams as I, type ManifestEntry as M, type NamedService as N, type ProcessedConfig as P, type Route as R, SSRServer as S, TEMPLATE as T, type RouteParams as a, type RouteAttributes as b, createMaps as c, type SSRServerOptions as d, type ServiceMethod as e, type ServiceRegistry as f, type RenderCallbacks as g, type SSRManifest as h, type Manifest as i, type RenderSSR as j, type RenderStream as k, type RenderModule as l, type ServiceCall as m, type DataHandler as n, type RoutePathsAndAttributes as o, processConfigs as p, type CSPDirectives as q, type CSPOptions as r, defaultGenerateCSP as s, generateNonce as t, createCSPHook as u, getRequestNonce as v, applyCSP as w };
|
package/dist/build.d.ts
CHANGED
package/dist/build.js
CHANGED
|
@@ -406,32 +406,25 @@ var callServiceMethod = async (registry, serviceName, methodName, params) => {
|
|
|
406
406
|
throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
|
|
407
407
|
return data;
|
|
408
408
|
};
|
|
409
|
-
var
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const data = await response.json();
|
|
414
|
-
if (typeof data !== "object" || data === null) throw new Error(`Expected object response from ${url}, but got ${typeof data}`);
|
|
415
|
-
return data;
|
|
416
|
-
}
|
|
417
|
-
throw new Error("URL must be provided to fetch data");
|
|
409
|
+
var isServiceDescriptor = (obj) => {
|
|
410
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return false;
|
|
411
|
+
const maybe = obj;
|
|
412
|
+
return typeof maybe.serviceName === "string" && typeof maybe.serviceMethod === "string";
|
|
418
413
|
};
|
|
419
|
-
var fetchInitialData = async (attr, params, serviceRegistry) => {
|
|
420
|
-
if (attr
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
throw error;
|
|
432
|
-
});
|
|
414
|
+
var fetchInitialData = async (attr, params, serviceRegistry, ctx = { headers: {} }, callServiceMethodImpl = callServiceMethod) => {
|
|
415
|
+
if (!attr?.data || typeof attr.data !== "function") return {};
|
|
416
|
+
const result = await attr.data(params, ctx);
|
|
417
|
+
if (isServiceDescriptor(result)) {
|
|
418
|
+
const { serviceName, serviceMethod, args } = result;
|
|
419
|
+
if (serviceRegistry[serviceName]?.[serviceMethod]) {
|
|
420
|
+
return await callServiceMethodImpl(serviceRegistry, serviceName, serviceMethod, args ?? {});
|
|
421
|
+
}
|
|
422
|
+
throw new Error(`Invalid service: serviceName=${String(serviceName)}, method=${String(serviceMethod)}`);
|
|
423
|
+
}
|
|
424
|
+
if (typeof result === "object" && result !== null) {
|
|
425
|
+
return result;
|
|
433
426
|
}
|
|
434
|
-
|
|
427
|
+
throw new Error("Invalid result from attr.data");
|
|
435
428
|
};
|
|
436
429
|
var matchRoute = (url, renderRoutes) => {
|
|
437
430
|
for (const route of renderRoutes) {
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PluginOption } from 'vite';
|
|
2
|
-
import { R as Route, a as RouteParams, b as RouteAttributes } from './SSRServer-
|
|
2
|
+
import { R as Route, a as RouteParams, b as RouteAttributes } from './SSRServer-D_82uJ06.js';
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import 'fastify';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyReply } from 'fastify';
|
|
2
|
-
export { B as BaseMiddleware, C as Config,
|
|
2
|
+
export { B as BaseMiddleware, C as Config, n as DataHandler, D as DataResult, I as InitialRouteParams, i as Manifest, M as ManifestEntry, N as NamedService, P as ProcessedConfig, g as RenderCallbacks, l as RenderModule, j as RenderSSR, k as RenderStream, R as Route, b as RouteAttributes, a as RouteParams, o as RoutePathsAndAttributes, h as SSRManifest, S as SSRServer, d as SSRServerOptions, m as ServiceCall, e as ServiceMethod, f as ServiceRegistry, T as TEMPLATE, c as createMaps, p as processConfigs } from './SSRServer-D_82uJ06.js';
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ declare module 'fastify' {
|
|
|
9
9
|
}
|
|
10
10
|
interface FastifyInstance {
|
|
11
11
|
/**
|
|
12
|
-
* Optional authentication hook to be used by the
|
|
12
|
+
* Optional authentication hook to be used by the taujs SSRServer.
|
|
13
13
|
* This method must be decorated by the user when using auth middleware in `taujs.config.ts`.
|
|
14
14
|
*
|
|
15
15
|
* Example usage:
|
package/dist/index.js
CHANGED
|
@@ -404,32 +404,25 @@ var callServiceMethod = async (registry, serviceName, methodName, params) => {
|
|
|
404
404
|
throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
|
|
405
405
|
return data;
|
|
406
406
|
};
|
|
407
|
-
var
|
|
408
|
-
if (
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const data = await response.json();
|
|
412
|
-
if (typeof data !== "object" || data === null) throw new Error(`Expected object response from ${url}, but got ${typeof data}`);
|
|
413
|
-
return data;
|
|
414
|
-
}
|
|
415
|
-
throw new Error("URL must be provided to fetch data");
|
|
407
|
+
var isServiceDescriptor = (obj) => {
|
|
408
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return false;
|
|
409
|
+
const maybe = obj;
|
|
410
|
+
return typeof maybe.serviceName === "string" && typeof maybe.serviceMethod === "string";
|
|
416
411
|
};
|
|
417
|
-
var fetchInitialData = async (attr, params, serviceRegistry) => {
|
|
418
|
-
if (attr
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
throw error;
|
|
430
|
-
});
|
|
412
|
+
var fetchInitialData = async (attr, params, serviceRegistry, ctx = { headers: {} }, callServiceMethodImpl = callServiceMethod) => {
|
|
413
|
+
if (!attr?.data || typeof attr.data !== "function") return {};
|
|
414
|
+
const result = await attr.data(params, ctx);
|
|
415
|
+
if (isServiceDescriptor(result)) {
|
|
416
|
+
const { serviceName, serviceMethod, args } = result;
|
|
417
|
+
if (serviceRegistry[serviceName]?.[serviceMethod]) {
|
|
418
|
+
return await callServiceMethodImpl(serviceRegistry, serviceName, serviceMethod, args ?? {});
|
|
419
|
+
}
|
|
420
|
+
throw new Error(`Invalid service: serviceName=${String(serviceName)}, method=${String(serviceMethod)}`);
|
|
421
|
+
}
|
|
422
|
+
if (typeof result === "object" && result !== null) {
|
|
423
|
+
return result;
|
|
431
424
|
}
|
|
432
|
-
|
|
425
|
+
throw new Error("Invalid result from attr.data");
|
|
433
426
|
};
|
|
434
427
|
var matchRoute = (url, renderRoutes) => {
|
|
435
428
|
for (const route of renderRoutes) {
|
package/dist/security/csp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'fastify';
|
|
2
|
-
export {
|
|
2
|
+
export { q as CSPDirectives, r as CSPOptions, w as applyCSP, u as createCSPHook, s as defaultGenerateCSP, t as generateNonce, v as getRequestNonce } from '../SSRServer-D_82uJ06.js';
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import 'vite';
|