fix(core): update

This commit is contained in:
2024-05-11 12:51:20 +02:00
parent fedb37ee16
commit d225a9584f
42 changed files with 1435 additions and 522 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedserver',
version: '3.0.29',
version: '3.0.30',
description: 'A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.'
}

View File

@ -1,3 +0,0 @@
export * from './requestmodifier.js';
export * from './responsemodifier.js';
export * from './typedrequests.js';

View File

@ -1,11 +0,0 @@
export type TRequestModifier = <T>(responseArg: {
headers: { [header: string]: string | string[] | undefined };
path: string;
body: string;
travelData?: T;
}) => Promise<{
headers: { [header: string]: string | string[] | undefined };
path: string;
body: string;
travelData?: T;
}>;

View File

@ -1,11 +0,0 @@
export type TResponseModifier = <T>(responseArg: {
headers: { [header: string]: number | string | string[] | undefined };
path: string;
responseContent: Buffer;
travelData?: T;
}) => Promise<{
headers: { [header: string]: number | string | string[] | undefined };
path: string;
responseContent: Buffer;
travelData?: T;
}>;

View File

@ -1,26 +0,0 @@
// not using the global plugins here to support better bundling...
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
export interface IReq_PushLatestServerChangeTime
extends typedrequestInterfaces.implementsTR<
typedrequestInterfaces.ITypedRequest,
IReq_PushLatestServerChangeTime
> {
method: 'pushLatestServerChangeTime';
request: {
time: number;
};
response: {};
}
export interface IReq_GetLatestServerChangeTime
extends typedrequestInterfaces.implementsTR<
typedrequestInterfaces.ITypedRequest,
IReq_GetLatestServerChangeTime
> {
method: 'getLatestServerChangeTime';
request: {};
response: {
time: number;
};
}

7
ts/paths.ts Normal file
View File

@ -0,0 +1,7 @@
import * as plugins from './plugins.js';
export const packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../'
);
export const distBundleDir = plugins.path.join(packageDir, './dist_bundle');

View File

@ -1,7 +1,7 @@
import * as plugins from '../plugins.js';
import { Handler } from './classes.handler.js';
import * as interfaces from '../interfaces/index.js';
import * as interfaces from '../../dist_ts_interfaces/index.js';
export class HandlerProxy extends Handler {
/**

View File

@ -1,5 +1,5 @@
import * as plugins from '../plugins.js';
import * as interfaces from '../interfaces/index.js';
import * as interfaces from '../../dist_ts_interfaces/index.js';
import { Handler } from './classes.handler.js';
import { Compressor, type TCompressionMethod, type ICompressionResult } from './classes.compressor.js';

View File

@ -1,7 +1,7 @@
import * as plugins from '../plugins.js';
import { Handler } from './classes.handler.js';
import * as interfaces from '../interfaces/index.js';
import * as interfaces from '../../dist_ts_interfaces/index.js';
export class HandlerTypedRouter extends Handler {
/**

View File

@ -0,0 +1,60 @@
import * as plugins from '../plugins.js';
import * as paths from '../paths.js';
import * as interfaces from '../../dist_ts_interfaces/index.js'
import { Handler } from './classes.handler.js';
import type { TypedServer } from '../typedserver.classes.typedserver.js';
import { HandlerTypedRouter } from './classes.handlertypedrouter.js';
const lswJS: string = plugins.smartfile.fs.toStringSync(
plugins.path.join(paths.distBundleDir, './lsw.js')
);
const lswJSMeta: string = plugins.smartfile.fs.toStringSync(
plugins.path.join(paths.distBundleDir, './lsw.js.map')
);
let lswVersionInfo: interfaces.serviceworker.IRequest_Serviceworker_Backend_VersionInfo['response'] =
null;
const serviceworkerHandler = new Handler(
'GET',
async (req, res) => {
if (req.path === '/lsw.js') {
res.status(200);
res.set('Content-Type', 'text/javascript');
res.write(lswJS + '\n' + `/** appSemVer: ${lswVersionInfo?.appSemVer || 'not set'} */`);
} else if (req.path === '/lsw.js.map') {
res.status(200);
res.set('Content-Type', 'application/json');
res.write(lswJSMeta);
}
res.end();
}
);
export const addServiceWorkerRoute = (
typedserverInstance: TypedServer,
lswData: () => interfaces.serviceworker.IRequest_Serviceworker_Backend_VersionInfo['response']
) => {
// lets the version info as unique string;
lswVersionInfo = lswData();
// the basic stuff
typedserverInstance.server.addRoute('/lsw.js*', serviceworkerHandler);
// the typed stuff
const typedrouter = new plugins.typedrequest.TypedRouter();
typedrouter.addTypedHandler(
new plugins.typedrequest.TypedHandler<interfaces.serviceworker.IRequest_Serviceworker_Backend_VersionInfo>(
'serviceworker_versionInfo',
async (req) => {
const versionInfoResponse = lswData();
return versionInfoResponse;
}
)
);
typedserverInstance.server.addRoute(
'/lsw-typedrequest',
new HandlerTypedRouter(typedrouter)
);
};

View File

@ -1,6 +1,6 @@
import * as plugins from './plugins.js';
import * as paths from './typedserver.paths.js';
import * as interfaces from './interfaces/index.js';
import * as interfaces from '../dist_ts_interfaces/index.js';
import * as servertools from './servertools/index.js';
import { type TCompressionMethod } from './servertools/classes.compressor.js';