@taujs/server 0.4.5 → 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.
- package/dist/{Config-CEhfq8Mm.d.ts → Config-DHz6Lax2.d.ts} +45 -4
- package/dist/Config.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -100
- package/package.json +4 -11
|
@@ -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<
|
|
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,
|
|
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,
|
|
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-
|
|
3
|
-
export { I as InitialRouteParams } from './Config-
|
|
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
|
@@ -97,101 +97,10 @@ var require_picocolors = __commonJS({
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// node_modules/fastify-plugin/lib/getPluginName.js
|
|
101
|
-
var require_getPluginName = __commonJS({
|
|
102
|
-
"node_modules/fastify-plugin/lib/getPluginName.js"(exports, module) {
|
|
103
|
-
"use strict";
|
|
104
|
-
var fpStackTracePattern = /at\s{1}(?:.*\.)?plugin\s{1}.*\n\s*(.*)/;
|
|
105
|
-
var fileNamePattern = /(\w*(\.\w*)*)\..*/;
|
|
106
|
-
module.exports = function getPluginName(fn) {
|
|
107
|
-
if (fn.name.length > 0) return fn.name;
|
|
108
|
-
const stackTraceLimit = Error.stackTraceLimit;
|
|
109
|
-
Error.stackTraceLimit = 10;
|
|
110
|
-
try {
|
|
111
|
-
throw new Error("anonymous function");
|
|
112
|
-
} catch (e) {
|
|
113
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
114
|
-
return extractPluginName(e.stack);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
function extractPluginName(stack) {
|
|
118
|
-
const m = stack.match(fpStackTracePattern);
|
|
119
|
-
return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
|
|
120
|
-
}
|
|
121
|
-
module.exports.extractPluginName = extractPluginName;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// node_modules/fastify-plugin/lib/toCamelCase.js
|
|
126
|
-
var require_toCamelCase = __commonJS({
|
|
127
|
-
"node_modules/fastify-plugin/lib/toCamelCase.js"(exports, module) {
|
|
128
|
-
"use strict";
|
|
129
|
-
module.exports = function toCamelCase(name) {
|
|
130
|
-
if (name[0] === "@") {
|
|
131
|
-
name = name.slice(1).replace("/", "-");
|
|
132
|
-
}
|
|
133
|
-
return name.replace(/-(.)/g, function(match2, g1) {
|
|
134
|
-
return g1.toUpperCase();
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// node_modules/fastify-plugin/plugin.js
|
|
141
|
-
var require_plugin = __commonJS({
|
|
142
|
-
"node_modules/fastify-plugin/plugin.js"(exports, module) {
|
|
143
|
-
"use strict";
|
|
144
|
-
var getPluginName = require_getPluginName();
|
|
145
|
-
var toCamelCase = require_toCamelCase();
|
|
146
|
-
var count = 0;
|
|
147
|
-
function plugin(fn, options = {}) {
|
|
148
|
-
let autoName = false;
|
|
149
|
-
if (fn.default !== void 0) {
|
|
150
|
-
fn = fn.default;
|
|
151
|
-
}
|
|
152
|
-
if (typeof fn !== "function") {
|
|
153
|
-
throw new TypeError(
|
|
154
|
-
`fastify-plugin expects a function, instead got a '${typeof fn}'`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
if (typeof options === "string") {
|
|
158
|
-
options = {
|
|
159
|
-
fastify: options
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
if (typeof options !== "object" || Array.isArray(options) || options === null) {
|
|
163
|
-
throw new TypeError("The options object should be an object");
|
|
164
|
-
}
|
|
165
|
-
if (options.fastify !== void 0 && typeof options.fastify !== "string") {
|
|
166
|
-
throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`);
|
|
167
|
-
}
|
|
168
|
-
if (!options.name) {
|
|
169
|
-
autoName = true;
|
|
170
|
-
options.name = getPluginName(fn) + "-auto-" + count++;
|
|
171
|
-
}
|
|
172
|
-
fn[Symbol.for("skip-override")] = options.encapsulate !== true;
|
|
173
|
-
fn[Symbol.for("fastify.display-name")] = options.name;
|
|
174
|
-
fn[Symbol.for("plugin-meta")] = options;
|
|
175
|
-
if (!fn.default) {
|
|
176
|
-
fn.default = fn;
|
|
177
|
-
}
|
|
178
|
-
const camelCase = toCamelCase(options.name);
|
|
179
|
-
if (!autoName && !fn[camelCase]) {
|
|
180
|
-
fn[camelCase] = fn;
|
|
181
|
-
}
|
|
182
|
-
return fn;
|
|
183
|
-
}
|
|
184
|
-
module.exports = plugin;
|
|
185
|
-
module.exports.default = plugin;
|
|
186
|
-
module.exports.fastifyPlugin = plugin;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
100
|
// src/CreateServer.ts
|
|
191
101
|
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
192
102
|
import path7 from "path";
|
|
193
103
|
import { performance as performance3 } from "perf_hooks";
|
|
194
|
-
import fastifyStatic from "@fastify/static";
|
|
195
104
|
import Fastify from "fastify";
|
|
196
105
|
|
|
197
106
|
// src/Setup.ts
|
|
@@ -851,8 +760,8 @@ var verifyContracts = (app, routes, contracts, security) => {
|
|
|
851
760
|
};
|
|
852
761
|
|
|
853
762
|
// src/SSRServer.ts
|
|
854
|
-
var import_fastify_plugin3 = __toESM(require_plugin(), 1);
|
|
855
763
|
import path6 from "path";
|
|
764
|
+
import fp3 from "fastify-plugin";
|
|
856
765
|
|
|
857
766
|
// src/logging/utils/index.ts
|
|
858
767
|
var httpStatusFrom = (err, fallback = 500) => err instanceof AppError ? err.httpStatus : fallback;
|
|
@@ -1083,7 +992,7 @@ var createAuthHook = (routeMatchers, logger) => {
|
|
|
1083
992
|
};
|
|
1084
993
|
|
|
1085
994
|
// src/security/CSP.ts
|
|
1086
|
-
|
|
995
|
+
import fp from "fastify-plugin";
|
|
1087
996
|
import crypto from "crypto";
|
|
1088
997
|
|
|
1089
998
|
// src/utils/System.ts
|
|
@@ -1129,7 +1038,7 @@ var findMatchingRoute = (routeMatchers, path9) => {
|
|
|
1129
1038
|
const match2 = matchRoute(path9, routeMatchers);
|
|
1130
1039
|
return match2 ? { route: match2.route, params: match2.params } : null;
|
|
1131
1040
|
};
|
|
1132
|
-
var cspPlugin = (
|
|
1041
|
+
var cspPlugin = fp(
|
|
1133
1042
|
async (fastify, opts) => {
|
|
1134
1043
|
const { generateCSP = defaultGenerateCSP, routes = [], routeMatchers, debug } = opts;
|
|
1135
1044
|
const globalDirectives = opts.directives || DEV_CSP_DIRECTIVES;
|
|
@@ -1180,7 +1089,7 @@ var cspPlugin = (0, import_fastify_plugin.default)(
|
|
|
1180
1089
|
);
|
|
1181
1090
|
|
|
1182
1091
|
// src/security/CSPReporting.ts
|
|
1183
|
-
|
|
1092
|
+
import fp2 from "fastify-plugin";
|
|
1184
1093
|
function sanitiseContext(ctx) {
|
|
1185
1094
|
return {
|
|
1186
1095
|
userAgent: ctx.userAgent,
|
|
@@ -1263,7 +1172,7 @@ var processCSPReport = (body, context, logger) => {
|
|
|
1263
1172
|
);
|
|
1264
1173
|
}
|
|
1265
1174
|
};
|
|
1266
|
-
var cspReportPlugin = (
|
|
1175
|
+
var cspReportPlugin = fp2(
|
|
1267
1176
|
async (fastify, opts) => {
|
|
1268
1177
|
const { onViolation } = opts;
|
|
1269
1178
|
if (!opts.path || typeof opts.path !== "string") throw AppError.badRequest("CSP report path is required and must be a string");
|
|
@@ -1667,6 +1576,12 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
|
|
|
1667
1576
|
}
|
|
1668
1577
|
const { route, params } = matchedRoute;
|
|
1669
1578
|
const { attr, appId } = route;
|
|
1579
|
+
const routeContext = {
|
|
1580
|
+
appId,
|
|
1581
|
+
path: route.path,
|
|
1582
|
+
attr,
|
|
1583
|
+
params
|
|
1584
|
+
};
|
|
1670
1585
|
const config = processedConfigs.find((c) => c.appId === appId);
|
|
1671
1586
|
if (!config) {
|
|
1672
1587
|
throw AppError.internal("No configuration found for the request", {
|
|
@@ -1736,7 +1651,7 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
|
|
|
1736
1651
|
let headContent = "";
|
|
1737
1652
|
let appHtml = "";
|
|
1738
1653
|
try {
|
|
1739
|
-
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 });
|
|
1740
1655
|
headContent = res.headContent;
|
|
1741
1656
|
appHtml = res.appHtml;
|
|
1742
1657
|
logger.debug?.("ssr", {}, "ssr data resolved");
|
|
@@ -1885,7 +1800,7 @@ var handleRender = async (req, reply, routeMatchers, processedConfigs, serviceRe
|
|
|
1885
1800
|
attr?.meta,
|
|
1886
1801
|
cspNonce,
|
|
1887
1802
|
ac.signal,
|
|
1888
|
-
{ logger: reqLogger }
|
|
1803
|
+
{ logger: reqLogger, routeContext }
|
|
1889
1804
|
);
|
|
1890
1805
|
writable.on("finish", () => {
|
|
1891
1806
|
if (abortedState.aborted || reply.raw.writableEnded) return;
|
|
@@ -2018,7 +1933,7 @@ async function registerStaticAssets(app, baseClientRoot, reg, defaults, projectR
|
|
|
2018
1933
|
}
|
|
2019
1934
|
|
|
2020
1935
|
// src/SSRServer.ts
|
|
2021
|
-
var SSRServer = (
|
|
1936
|
+
var SSRServer = fp3(
|
|
2022
1937
|
async (app, opts) => {
|
|
2023
1938
|
const { alias, configs, routes, serviceRegistry = {}, clientRoot: baseClientRoot, security } = opts;
|
|
2024
1939
|
const logger = createLogger({
|
|
@@ -2183,7 +2098,7 @@ var createServer = async (opts) => {
|
|
|
2183
2098
|
configs,
|
|
2184
2099
|
routes,
|
|
2185
2100
|
serviceRegistry: opts.serviceRegistry,
|
|
2186
|
-
staticAssets: opts.staticAssets
|
|
2101
|
+
staticAssets: opts.staticAssets ?? false,
|
|
2187
2102
|
debug: opts.debug,
|
|
2188
2103
|
alias: opts.alias,
|
|
2189
2104
|
security,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taujs/server",
|
|
3
|
-
"version": "0.4.
|
|
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",
|
|
@@ -44,36 +44,29 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"fastify": "^5.6.1",
|
|
48
|
+
"fastify-plugin": "^5.1.0",
|
|
47
49
|
"path-to-regexp": "^8.1.0",
|
|
48
|
-
"vite
|
|
50
|
+
"vite": "^7.1.11"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@arethetypeswrong/cli": "^0.15.4",
|
|
52
54
|
"@babel/preset-typescript": "^7.24.7",
|
|
53
55
|
"@changesets/cli": "^2.27.7",
|
|
54
|
-
"@fastify/static": "^8.3.0",
|
|
55
56
|
"@types/node": "^20.14.9",
|
|
56
57
|
"@vitest/coverage-v8": "^3.2.4",
|
|
57
58
|
"@vitest/ui": "^3.2.4",
|
|
58
|
-
"fastify": "^5.6.1",
|
|
59
59
|
"jsdom": "^25.0.0",
|
|
60
60
|
"prettier": "^3.3.3",
|
|
61
61
|
"tsup": "^8.2.4",
|
|
62
62
|
"typescript": "^5.5.4",
|
|
63
|
-
"vite": "^7.1.11",
|
|
64
63
|
"vitest": "^3.2.4"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
|
-
"@fastify/static": "^8.3.0",
|
|
68
66
|
"fastify": "^5.6.1",
|
|
69
67
|
"typescript": "^5.5.4",
|
|
70
68
|
"vite": "^7.1.11"
|
|
71
69
|
},
|
|
72
|
-
"peerDependenciesMeta": {
|
|
73
|
-
"@fastify/static": {
|
|
74
|
-
"optional": true
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
70
|
"scripts": {
|
|
78
71
|
"build": "tsup",
|
|
79
72
|
"build-local": "tsup && ./move.sh",
|