@duplojs/http 0.7.4 → 0.8.5
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/client/getBody.cjs +3 -3
- package/dist/client/getBody.mjs +3 -3
- package/dist/client/hooks.cjs +45 -0
- package/dist/client/hooks.d.ts +6 -1
- package/dist/client/hooks.mjs +41 -1
- package/dist/client/httpClient.cjs +25 -1
- package/dist/client/httpClient.d.ts +8 -3
- package/dist/client/httpClient.mjs +25 -1
- package/dist/client/index.cjs +7 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.mjs +2 -1
- package/dist/client/insertParamsInPath.cjs +1 -1
- package/dist/client/insertParamsInPath.mjs +1 -1
- package/dist/client/promiseRequest.cjs +83 -26
- package/dist/client/promiseRequest.d.ts +46 -29
- package/dist/client/promiseRequest.mjs +83 -26
- package/dist/client/queryToString.cjs +1 -1
- package/dist/client/queryToString.mjs +1 -1
- package/dist/client/serverSentEvents.cjs +231 -0
- package/dist/client/serverSentEvents.d.ts +2 -0
- package/dist/client/serverSentEvents.mjs +208 -0
- package/dist/client/types/clientRequestParams.d.ts +2 -0
- package/dist/client/types/clientResponse.d.ts +34 -3
- package/dist/client/types/hooks.d.ts +17 -7
- package/dist/client/types/promiseRequestParams.d.ts +1 -0
- package/dist/client/types/serverRoute.d.ts +2 -0
- package/dist/core/builders/route/handler.d.ts +5 -2
- package/dist/core/defaultHooks/index.cjs +8 -0
- package/dist/core/defaultHooks/index.d.ts +1 -1
- package/dist/core/defaultHooks/index.mjs +8 -0
- package/dist/core/functionsBuilders/route/default.cjs +9 -13
- package/dist/core/functionsBuilders/route/default.mjs +2 -6
- package/dist/core/functionsBuilders/steps/create.d.ts +2 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +1 -1
- package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +1 -1
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +37 -17
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +37 -17
- package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +3 -3
- package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +3 -3
- package/dist/core/hub/defaultEmptyReaderImplementation.cjs +9 -0
- package/dist/core/hub/defaultEmptyReaderImplementation.d.ts +1 -0
- package/dist/core/hub/defaultEmptyReaderImplementation.mjs +7 -0
- package/dist/core/hub/defaultMalformedUrlHandler.cjs +14 -0
- package/dist/core/hub/defaultMalformedUrlHandler.d.ts +10 -0
- package/dist/core/hub/defaultMalformedUrlHandler.mjs +12 -0
- package/dist/core/hub/defaultNotfoundHandler.d.ts +1 -1
- package/dist/core/hub/index.cjs +14 -1
- package/dist/core/hub/index.d.ts +4 -0
- package/dist/core/hub/index.mjs +13 -2
- package/dist/core/implementHttpServer.cjs +7 -2
- package/dist/core/implementHttpServer.d.ts +7 -1
- package/dist/core/implementHttpServer.mjs +5 -0
- package/dist/core/index.cjs +18 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.mjs +8 -2
- package/dist/core/request/bodyController/base.cjs +24 -6
- package/dist/core/request/bodyController/base.d.ts +9 -0
- package/dist/core/request/bodyController/base.mjs +25 -8
- package/dist/core/request/bodyController/empty.cjs +11 -0
- package/dist/core/request/bodyController/empty.d.ts +3 -0
- package/dist/core/request/bodyController/empty.mjs +8 -0
- package/dist/core/request/bodyController/formData.cjs +1 -0
- package/dist/core/request/bodyController/formData.d.ts +4 -2
- package/dist/core/request/bodyController/formData.mjs +1 -0
- package/dist/core/request/bodyController/index.cjs +4 -0
- package/dist/core/request/bodyController/index.d.ts +1 -0
- package/dist/core/request/bodyController/index.mjs +2 -1
- package/dist/core/request/index.cjs +5 -0
- package/dist/core/request/index.d.ts +1 -1
- package/dist/core/request/index.mjs +6 -1
- package/dist/core/response/contract.cjs +17 -4
- package/dist/core/response/contract.d.ts +19 -4
- package/dist/core/response/contract.mjs +17 -4
- package/dist/core/response/index.cjs +2 -0
- package/dist/core/response/index.d.ts +1 -0
- package/dist/core/response/index.mjs +1 -0
- package/dist/core/response/serverSentEventsPredicted.cjs +23 -0
- package/dist/core/response/serverSentEventsPredicted.d.ts +14 -0
- package/dist/core/response/serverSentEventsPredicted.mjs +21 -0
- package/dist/core/route/hooks.cjs +9 -0
- package/dist/core/route/hooks.d.ts +10 -9
- package/dist/core/route/hooks.mjs +9 -1
- package/dist/core/route/index.cjs +1 -0
- package/dist/core/route/index.mjs +1 -1
- package/dist/core/router/buildSystemRoute.cjs +33 -0
- package/dist/core/router/buildSystemRoute.d.ts +11 -0
- package/dist/core/router/buildSystemRoute.mjs +31 -0
- package/dist/core/router/decodeUrl.cjs +5 -4
- package/dist/core/router/decodeUrl.d.ts +1 -1
- package/dist/core/router/decodeUrl.mjs +5 -4
- package/dist/core/router/index.cjs +24 -23
- package/dist/core/router/index.d.ts +1 -0
- package/dist/core/router/index.mjs +25 -25
- package/dist/core/serverSentEvents.cjs +96 -0
- package/dist/core/serverSentEvents.d.ts +33 -0
- package/dist/core/serverSentEvents.mjs +96 -0
- package/dist/core/steps/cut.d.ts +2 -2
- package/dist/core/steps/handler.d.ts +10 -5
- package/dist/interfaces/node/bodyReaders/formData/index.cjs +34 -14
- package/dist/interfaces/node/bodyReaders/formData/index.mjs +35 -15
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.cjs +18 -12
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.d.ts +2 -1
- package/dist/interfaces/node/bodyReaders/formData/readRequestFormData.mjs +18 -12
- package/dist/interfaces/node/createHttpServer.cjs +2 -3
- package/dist/interfaces/node/createHttpServer.mjs +2 -3
- package/dist/interfaces/node/hooks/index.cjs +61 -38
- package/dist/interfaces/node/hooks/index.d.ts +6 -4
- package/dist/interfaces/node/hooks/index.mjs +61 -38
- package/dist/interfaces/node/index.cjs +1 -1
- package/dist/interfaces/node/index.mjs +1 -1
- package/dist/plugins/cacheController/createResponseHeader.cjs +43 -0
- package/dist/plugins/cacheController/createResponseHeader.d.ts +2 -0
- package/dist/plugins/cacheController/createResponseHeader.mjs +41 -0
- package/dist/plugins/cacheController/hooks.cjs +23 -0
- package/dist/plugins/cacheController/hooks.d.ts +4 -0
- package/dist/plugins/cacheController/hooks.mjs +21 -0
- package/dist/plugins/cacheController/index.cjs +10 -0
- package/dist/plugins/cacheController/index.d.ts +3 -0
- package/dist/plugins/cacheController/index.mjs +3 -0
- package/dist/plugins/cacheController/types/cacheControlDirectives.cjs +2 -0
- package/dist/plugins/cacheController/types/cacheControlDirectives.d.ts +16 -0
- package/dist/plugins/cacheController/types/cacheControlDirectives.mjs +1 -0
- package/dist/plugins/cacheController/types/index.cjs +4 -0
- package/dist/plugins/cacheController/types/index.d.ts +1 -0
- package/dist/plugins/cacheController/types/index.mjs +1 -0
- package/dist/plugins/codeGenerator/aggregateStepContract.cjs +9 -2
- package/dist/plugins/codeGenerator/aggregateStepContract.d.ts +1 -1
- package/dist/plugins/codeGenerator/aggregateStepContract.mjs +10 -3
- package/dist/plugins/codeGenerator/plugin.cjs +4 -4
- package/dist/plugins/codeGenerator/plugin.mjs +1 -1
- package/dist/plugins/openApiGenerator/aggregateStepContract.d.ts +2 -7
- package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +46 -8
- package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +2 -2
- package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +46 -8
- package/dist/plugins/openApiGenerator/types/endpointResponse.d.ts +7 -3
- package/dist/plugins/static/index.cjs +14 -0
- package/dist/plugins/static/index.d.ts +3 -0
- package/dist/plugins/static/index.mjs +3 -0
- package/dist/plugins/static/kind.cjs +9 -0
- package/dist/plugins/static/kind.d.ts +6 -0
- package/dist/plugins/static/kind.mjs +7 -0
- package/dist/plugins/static/makeRouteFile.cjs +62 -0
- package/dist/plugins/static/makeRouteFile.d.ts +48 -0
- package/dist/plugins/static/makeRouteFile.mjs +58 -0
- package/dist/plugins/static/makeRouteFolder.cjs +67 -0
- package/dist/plugins/static/makeRouteFolder.d.ts +39 -0
- package/dist/plugins/static/makeRouteFolder.mjs +65 -0
- package/dist/plugins/static/plugin.cjs +53 -0
- package/dist/plugins/static/plugin.d.ts +26 -0
- package/dist/plugins/static/plugin.mjs +50 -0
- package/package.json +18 -7
- /package/dist/plugins/codeGenerator/{typescriptTransfomer.cjs → typescriptTransformer.cjs} +0 -0
- /package/dist/plugins/codeGenerator/{typescriptTransfomer.d.ts → typescriptTransformer.d.ts} +0 -0
- /package/dist/plugins/codeGenerator/{typescriptTransfomer.mjs → typescriptTransformer.mjs} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var serverUtils = require('@duplojs/server-utils');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
require('../../core/builders/index.cjs');
|
|
6
|
+
require('../../core/metadata/index.cjs');
|
|
7
|
+
require('../../core/response/index.cjs');
|
|
8
|
+
var hooks = require('../cacheController/hooks.cjs');
|
|
9
|
+
var builder = require('../../core/builders/route/builder.cjs');
|
|
10
|
+
var ignoreByRouteStore = require('../../core/metadata/ignoreByRouteStore.cjs');
|
|
11
|
+
var contract = require('../../core/response/contract.cjs');
|
|
12
|
+
|
|
13
|
+
function makeRouteFolder(params) {
|
|
14
|
+
const sourcePath = utils.whenNot(params.source.path, utils.S.endsWith("/"), utils.S.concat("/"));
|
|
15
|
+
const localPrefix = utils.A.coalescing(params.prefix);
|
|
16
|
+
const routePath = utils.A.mapTuple(localPrefix, (prefix) => `${prefix}/*`);
|
|
17
|
+
const prefixRegex = utils.pipe(localPrefix, utils.A.map(utils.escapeRegExp), utils.A.join("|"), (value) => new RegExp(`^(?:${value})(?:/|$)`));
|
|
18
|
+
const getResourcePath = utils.innerPipe(utils.S.replace(prefixRegex, ""), utils.S.prepend(sourcePath));
|
|
19
|
+
return builder.useRouteBuilder("GET", routePath, {
|
|
20
|
+
metadata: [ignoreByRouteStore.IgnoreByRouteStoreMetadata()],
|
|
21
|
+
hooks: [hooks.createCacheControllerHooks(params.cacheControlConfig)],
|
|
22
|
+
})
|
|
23
|
+
.handler([
|
|
24
|
+
contract.ResponseContract.ok("resource.found", serverUtils.SDP.file()),
|
|
25
|
+
contract.ResponseContract.notFound("resource.notfound"),
|
|
26
|
+
contract.ResponseContract.notModified("resource.notModified"),
|
|
27
|
+
], async (__, { request, response }) => {
|
|
28
|
+
if (!utils.Path.isAbsolute(request.path)) {
|
|
29
|
+
return response("resource.notfound");
|
|
30
|
+
}
|
|
31
|
+
const resourcePath = getResourcePath(request.path);
|
|
32
|
+
const resultStat = await serverUtils.SF.stat(resourcePath);
|
|
33
|
+
if (utils.E.isLeft(resultStat)) {
|
|
34
|
+
return response("resource.notfound");
|
|
35
|
+
}
|
|
36
|
+
const stat = utils.unwrap(resultStat);
|
|
37
|
+
if (stat.isDirectory && !params.directoryFallBackFile) {
|
|
38
|
+
return response("resource.notfound");
|
|
39
|
+
}
|
|
40
|
+
const resource = serverUtils.SF.createFileInterface(stat.isDirectory && params.directoryFallBackFile
|
|
41
|
+
? `${resourcePath}/${params.directoryFallBackFile}`
|
|
42
|
+
: resourcePath);
|
|
43
|
+
const resultResourceStat = stat.isFile
|
|
44
|
+
? stat
|
|
45
|
+
: await resource.stat();
|
|
46
|
+
if (utils.E.isLeft(resultResourceStat)) {
|
|
47
|
+
return response("resource.notfound");
|
|
48
|
+
}
|
|
49
|
+
const resourceStat = utils.unwrap(resultResourceStat);
|
|
50
|
+
if (!resourceStat.isFile) {
|
|
51
|
+
return response("resource.notfound");
|
|
52
|
+
}
|
|
53
|
+
if (request.headers["if-modified-since"]
|
|
54
|
+
&& typeof request.headers["if-modified-since"] === "string"
|
|
55
|
+
&& resourceStat.modifiedAt
|
|
56
|
+
&& new Date(request.headers["if-modified-since"]).getTime() >= resourceStat.modifiedAt.getTime()) {
|
|
57
|
+
return response("resource.notModified")
|
|
58
|
+
.setHeader("last-modified", resourceStat.modifiedAt.toISOString());
|
|
59
|
+
}
|
|
60
|
+
return resourceStat.modifiedAt
|
|
61
|
+
? response("resource.found", resource)
|
|
62
|
+
.setHeader("last-modified", resourceStat.modifiedAt.toISOString())
|
|
63
|
+
: response("resource.found", resource);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.makeRouteFolder = makeRouteFolder;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SDP, SF } from "@duplojs/server-utils";
|
|
2
|
+
import { type AnyTuple } from "@duplojs/utils";
|
|
3
|
+
import { ResponseContract } from "../../core/response";
|
|
4
|
+
import type { RoutePath } from "../../core/route";
|
|
5
|
+
import { type CacheControlDirectives } from "../cacheController/types";
|
|
6
|
+
interface MakeRouteFolderParams {
|
|
7
|
+
readonly source: SF.FolderInterface;
|
|
8
|
+
readonly prefix: RoutePath | AnyTuple<RoutePath>;
|
|
9
|
+
readonly cacheControlConfig?: CacheControlDirectives;
|
|
10
|
+
readonly directoryFallBackFile?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function makeRouteFolder(params: MakeRouteFolderParams): import("../../core/route").Route<{
|
|
13
|
+
readonly method: "GET";
|
|
14
|
+
readonly metadata: readonly [import("../../core/metadata").Metadata<"ignore-by-route-store", unknown>];
|
|
15
|
+
readonly hooks: readonly [{
|
|
16
|
+
readonly beforeSendResponse: ({ currentResponse, next }: import("../../core/route").RouteHookParamsAfter<import("../../core/request").Request>) => import("../../core/route").RouteHookNext;
|
|
17
|
+
}];
|
|
18
|
+
readonly paths: [`/${string}/*`] | [`/${string}/*`, ...`/${string}/*`[]];
|
|
19
|
+
readonly preflightSteps: readonly [];
|
|
20
|
+
readonly bodyController: null;
|
|
21
|
+
readonly steps: readonly [import("../../core/steps").HandlerStep<{
|
|
22
|
+
readonly responseContract: [NoInfer<ResponseContract.Contract<"200", "resource.found", SDP.DataParserFile<{
|
|
23
|
+
readonly mimeType?: RegExp | undefined;
|
|
24
|
+
readonly errorMessage?: string | undefined;
|
|
25
|
+
readonly coerce: boolean;
|
|
26
|
+
readonly minSize?: number | undefined;
|
|
27
|
+
readonly maxSize?: number | undefined;
|
|
28
|
+
readonly checkExist: boolean;
|
|
29
|
+
readonly checkers: readonly [];
|
|
30
|
+
}>>>, NoInfer<ResponseContract.Contract<"404", "resource.notfound", import("@duplojs/utils/dataParser").DataParserEmpty<{
|
|
31
|
+
readonly errorMessage?: string | undefined;
|
|
32
|
+
readonly coerce: boolean;
|
|
33
|
+
readonly checkers: readonly [];
|
|
34
|
+
}>>>, NoInfer<ResponseContract.Contract<"304", "resource.notModified", import("@duplojs/utils/dataParser").DataParserEmpty<import("@duplojs/utils/dataParser").DataParserDefinitionEmpty>>>];
|
|
35
|
+
theFunction(floor: {}, param: import("../../core/steps").HandlerStepFunctionParams<import("../../core/request").Request, import("../../core/response").PredictedResponse<"200", "resource.found", SF.FileInterface> | import("../../core/response").PredictedResponse<"404", "resource.notfound", undefined> | import("../../core/response").PredictedResponse<"304", "resource.notModified", undefined>>): import("@duplojs/utils").MaybePromise<import("../../core/response").PredictedResponse<"200", "resource.found", SF.FileInterface> | import("../../core/response").PredictedResponse<"404", "resource.notfound", undefined> | import("../../core/response").PredictedResponse<"304", "resource.notModified", undefined>>;
|
|
36
|
+
readonly metadata: readonly [];
|
|
37
|
+
}>];
|
|
38
|
+
}>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { SDP, SF } from '@duplojs/server-utils';
|
|
2
|
+
import { whenNot, S, A, pipe, escapeRegExp, innerPipe, Path, E, unwrap } from '@duplojs/utils';
|
|
3
|
+
import '../../core/builders/index.mjs';
|
|
4
|
+
import '../../core/metadata/index.mjs';
|
|
5
|
+
import '../../core/response/index.mjs';
|
|
6
|
+
import { createCacheControllerHooks } from '../cacheController/hooks.mjs';
|
|
7
|
+
import { useRouteBuilder } from '../../core/builders/route/builder.mjs';
|
|
8
|
+
import { IgnoreByRouteStoreMetadata } from '../../core/metadata/ignoreByRouteStore.mjs';
|
|
9
|
+
import { ResponseContract } from '../../core/response/contract.mjs';
|
|
10
|
+
|
|
11
|
+
function makeRouteFolder(params) {
|
|
12
|
+
const sourcePath = whenNot(params.source.path, S.endsWith("/"), S.concat("/"));
|
|
13
|
+
const localPrefix = A.coalescing(params.prefix);
|
|
14
|
+
const routePath = A.mapTuple(localPrefix, (prefix) => `${prefix}/*`);
|
|
15
|
+
const prefixRegex = pipe(localPrefix, A.map(escapeRegExp), A.join("|"), (value) => new RegExp(`^(?:${value})(?:/|$)`));
|
|
16
|
+
const getResourcePath = innerPipe(S.replace(prefixRegex, ""), S.prepend(sourcePath));
|
|
17
|
+
return useRouteBuilder("GET", routePath, {
|
|
18
|
+
metadata: [IgnoreByRouteStoreMetadata()],
|
|
19
|
+
hooks: [createCacheControllerHooks(params.cacheControlConfig)],
|
|
20
|
+
})
|
|
21
|
+
.handler([
|
|
22
|
+
ResponseContract.ok("resource.found", SDP.file()),
|
|
23
|
+
ResponseContract.notFound("resource.notfound"),
|
|
24
|
+
ResponseContract.notModified("resource.notModified"),
|
|
25
|
+
], async (__, { request, response }) => {
|
|
26
|
+
if (!Path.isAbsolute(request.path)) {
|
|
27
|
+
return response("resource.notfound");
|
|
28
|
+
}
|
|
29
|
+
const resourcePath = getResourcePath(request.path);
|
|
30
|
+
const resultStat = await SF.stat(resourcePath);
|
|
31
|
+
if (E.isLeft(resultStat)) {
|
|
32
|
+
return response("resource.notfound");
|
|
33
|
+
}
|
|
34
|
+
const stat = unwrap(resultStat);
|
|
35
|
+
if (stat.isDirectory && !params.directoryFallBackFile) {
|
|
36
|
+
return response("resource.notfound");
|
|
37
|
+
}
|
|
38
|
+
const resource = SF.createFileInterface(stat.isDirectory && params.directoryFallBackFile
|
|
39
|
+
? `${resourcePath}/${params.directoryFallBackFile}`
|
|
40
|
+
: resourcePath);
|
|
41
|
+
const resultResourceStat = stat.isFile
|
|
42
|
+
? stat
|
|
43
|
+
: await resource.stat();
|
|
44
|
+
if (E.isLeft(resultResourceStat)) {
|
|
45
|
+
return response("resource.notfound");
|
|
46
|
+
}
|
|
47
|
+
const resourceStat = unwrap(resultResourceStat);
|
|
48
|
+
if (!resourceStat.isFile) {
|
|
49
|
+
return response("resource.notfound");
|
|
50
|
+
}
|
|
51
|
+
if (request.headers["if-modified-since"]
|
|
52
|
+
&& typeof request.headers["if-modified-since"] === "string"
|
|
53
|
+
&& resourceStat.modifiedAt
|
|
54
|
+
&& new Date(request.headers["if-modified-since"]).getTime() >= resourceStat.modifiedAt.getTime()) {
|
|
55
|
+
return response("resource.notModified")
|
|
56
|
+
.setHeader("last-modified", resourceStat.modifiedAt.toISOString());
|
|
57
|
+
}
|
|
58
|
+
return resourceStat.modifiedAt
|
|
59
|
+
? response("resource.found", resource)
|
|
60
|
+
.setHeader("last-modified", resourceStat.modifiedAt.toISOString())
|
|
61
|
+
: response("resource.found", resource);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { makeRouteFolder };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@duplojs/utils');
|
|
4
|
+
var serverUtils = require('@duplojs/server-utils');
|
|
5
|
+
var kind = require('./kind.cjs');
|
|
6
|
+
var makeRouteFile = require('./makeRouteFile.cjs');
|
|
7
|
+
var makeRouteFolder = require('./makeRouteFolder.cjs');
|
|
8
|
+
|
|
9
|
+
class StaticPluginError extends utils.kindHeritage("static-plugin", kind.createStaticPluginKind("static-plugin"), Error) {
|
|
10
|
+
information;
|
|
11
|
+
error;
|
|
12
|
+
constructor(information, error) {
|
|
13
|
+
super({}, [`Error during registration static route: ${information}`]);
|
|
14
|
+
this.information = information;
|
|
15
|
+
this.error = error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function staticPlugin(...args) {
|
|
19
|
+
const route = utils.P.match(args)
|
|
20
|
+
.with([utils.toCurriedPredicate(serverUtils.SF.isFolderInterface)], ([source, params]) => makeRouteFolder.makeRouteFolder({
|
|
21
|
+
source,
|
|
22
|
+
...params,
|
|
23
|
+
}))
|
|
24
|
+
.with([utils.toCurriedPredicate(serverUtils.SF.isFileInterface)], ([source, params]) => makeRouteFile.makeRouteFile({
|
|
25
|
+
source,
|
|
26
|
+
...params,
|
|
27
|
+
}))
|
|
28
|
+
.exhaustive();
|
|
29
|
+
return {
|
|
30
|
+
name: "static",
|
|
31
|
+
routes: [route],
|
|
32
|
+
hooksHubLifeCycle: [
|
|
33
|
+
{
|
|
34
|
+
beforeStartServer: async () => {
|
|
35
|
+
const statResult = await args[0].stat();
|
|
36
|
+
if (utils.E.isLeft(statResult)) {
|
|
37
|
+
throw new StaticPluginError(`source does not exit (${args[0].path}).`, utils.unwrap(statResult));
|
|
38
|
+
}
|
|
39
|
+
const stat = utils.unwrap(statResult);
|
|
40
|
+
if (serverUtils.SF.isFileInterface(args[0]) && !stat.isFile) {
|
|
41
|
+
throw new StaticPluginError(`source does not file (${args[0].path}).`, stat);
|
|
42
|
+
}
|
|
43
|
+
else if (serverUtils.SF.isFolderInterface(args[0]) && stat.isFile) {
|
|
44
|
+
throw new StaticPluginError(`source does not folder (${args[0].path}).`, stat);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.StaticPluginError = StaticPluginError;
|
|
53
|
+
exports.staticPlugin = staticPlugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type AnyTuple } from "@duplojs/utils";
|
|
2
|
+
import { SF } from "@duplojs/server-utils";
|
|
3
|
+
import type { HubPlugin } from "../../core/hub";
|
|
4
|
+
import type { RoutePath } from "../../core/route";
|
|
5
|
+
import { type CacheControlDirectives } from "../cacheController/types";
|
|
6
|
+
export interface BaseStaticPluginParams {
|
|
7
|
+
readonly cacheControlConfig?: CacheControlDirectives;
|
|
8
|
+
}
|
|
9
|
+
export interface StaticPluginFileParams extends BaseStaticPluginParams {
|
|
10
|
+
readonly path: RoutePath | AnyTuple<RoutePath>;
|
|
11
|
+
}
|
|
12
|
+
export interface StaticPluginFolderParams extends BaseStaticPluginParams {
|
|
13
|
+
readonly prefix: RoutePath | AnyTuple<RoutePath>;
|
|
14
|
+
readonly directoryIndexFilePrefix?: string;
|
|
15
|
+
}
|
|
16
|
+
declare const StaticPluginError_base: new (params: {
|
|
17
|
+
"@DuplojsStaticPlugin/static-plugin"?: unknown;
|
|
18
|
+
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsStaticPlugin/static-plugin", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"static-plugin", unknown>, unknown>;
|
|
19
|
+
export declare class StaticPluginError extends StaticPluginError_base {
|
|
20
|
+
information: string;
|
|
21
|
+
error: unknown;
|
|
22
|
+
constructor(information: string, error: unknown);
|
|
23
|
+
}
|
|
24
|
+
export declare function staticPlugin(source: SF.FolderInterface, params: StaticPluginFolderParams): HubPlugin;
|
|
25
|
+
export declare function staticPlugin(source: SF.FileInterface, params: StaticPluginFileParams): HubPlugin;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { kindHeritage, P, toCurriedPredicate, E, unwrap } from '@duplojs/utils';
|
|
2
|
+
import { SF } from '@duplojs/server-utils';
|
|
3
|
+
import { createStaticPluginKind } from './kind.mjs';
|
|
4
|
+
import { makeRouteFile } from './makeRouteFile.mjs';
|
|
5
|
+
import { makeRouteFolder } from './makeRouteFolder.mjs';
|
|
6
|
+
|
|
7
|
+
class StaticPluginError extends kindHeritage("static-plugin", createStaticPluginKind("static-plugin"), Error) {
|
|
8
|
+
information;
|
|
9
|
+
error;
|
|
10
|
+
constructor(information, error) {
|
|
11
|
+
super({}, [`Error during registration static route: ${information}`]);
|
|
12
|
+
this.information = information;
|
|
13
|
+
this.error = error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function staticPlugin(...args) {
|
|
17
|
+
const route = P.match(args)
|
|
18
|
+
.with([toCurriedPredicate(SF.isFolderInterface)], ([source, params]) => makeRouteFolder({
|
|
19
|
+
source,
|
|
20
|
+
...params,
|
|
21
|
+
}))
|
|
22
|
+
.with([toCurriedPredicate(SF.isFileInterface)], ([source, params]) => makeRouteFile({
|
|
23
|
+
source,
|
|
24
|
+
...params,
|
|
25
|
+
}))
|
|
26
|
+
.exhaustive();
|
|
27
|
+
return {
|
|
28
|
+
name: "static",
|
|
29
|
+
routes: [route],
|
|
30
|
+
hooksHubLifeCycle: [
|
|
31
|
+
{
|
|
32
|
+
beforeStartServer: async () => {
|
|
33
|
+
const statResult = await args[0].stat();
|
|
34
|
+
if (E.isLeft(statResult)) {
|
|
35
|
+
throw new StaticPluginError(`source does not exit (${args[0].path}).`, unwrap(statResult));
|
|
36
|
+
}
|
|
37
|
+
const stat = unwrap(statResult);
|
|
38
|
+
if (SF.isFileInterface(args[0]) && !stat.isFile) {
|
|
39
|
+
throw new StaticPluginError(`source does not file (${args[0].path}).`, stat);
|
|
40
|
+
}
|
|
41
|
+
else if (SF.isFolderInterface(args[0]) && stat.isFile) {
|
|
42
|
+
throw new StaticPluginError(`source does not folder (${args[0].path}).`, stat);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { StaticPluginError, staticPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duplojs/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"author": "mathcovax",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"test:tu:bench": "vitest bench",
|
|
18
18
|
"test:tu:watch": "vitest --coverage --watch",
|
|
19
19
|
"test:tu:update": "vitest --coverage --update",
|
|
20
|
-
"test:types": "
|
|
21
|
-
"test:lint": "eslint
|
|
22
|
-
"test:lint:fix": "eslint --fix
|
|
20
|
+
"test:types": "./.commands/test-types.sh",
|
|
21
|
+
"test:lint": "./.commands/test-eslint.sh",
|
|
22
|
+
"test:lint:fix": "./.commands/test-eslint.sh --fix",
|
|
23
23
|
"prepare": "husky"
|
|
24
24
|
},
|
|
25
25
|
"types": "./dist/core/index.d.ts",
|
|
@@ -58,6 +58,16 @@
|
|
|
58
58
|
"import": "./dist/plugins/openApiGenerator/index.mjs",
|
|
59
59
|
"require": "./dist/plugins/openApiGenerator/index.cjs",
|
|
60
60
|
"types": "./dist/plugins/openApiGenerator/index.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./cacheController": {
|
|
63
|
+
"import": "./dist/plugins/cacheController/index.mjs",
|
|
64
|
+
"require": "./dist/plugins/cacheController/index.cjs",
|
|
65
|
+
"types": "./dist/plugins/cacheController/index.d.ts"
|
|
66
|
+
},
|
|
67
|
+
"./static": {
|
|
68
|
+
"import": "./dist/plugins/static/index.mjs",
|
|
69
|
+
"require": "./dist/plugins/static/index.cjs",
|
|
70
|
+
"types": "./dist/plugins/static/index.d.ts"
|
|
61
71
|
}
|
|
62
72
|
},
|
|
63
73
|
"files": [
|
|
@@ -65,9 +75,9 @@
|
|
|
65
75
|
"README.md"
|
|
66
76
|
],
|
|
67
77
|
"peerDependencies": {
|
|
68
|
-
"@duplojs/data-parser-tools": ">=0.2.
|
|
69
|
-
"@duplojs/server-utils": ">=0.2.
|
|
70
|
-
"@duplojs/utils": ">=1.5.
|
|
78
|
+
"@duplojs/data-parser-tools": ">=0.2.9 <1.0.0",
|
|
79
|
+
"@duplojs/server-utils": ">=0.2.2 <1.0.0",
|
|
80
|
+
"@duplojs/utils": ">=1.5.13 <2.0.0"
|
|
71
81
|
},
|
|
72
82
|
"devDependencies": {
|
|
73
83
|
"@commitlint/cli": "19.8.1",
|
|
@@ -80,6 +90,7 @@
|
|
|
80
90
|
"@types/web": "^0.0.317",
|
|
81
91
|
"@vitest/coverage-istanbul": "3.2.4",
|
|
82
92
|
"eslint": "9.34.0",
|
|
93
|
+
"eventsource": "^4.1.0",
|
|
83
94
|
"form-data": "^4.0.5",
|
|
84
95
|
"husky": "9.1.7",
|
|
85
96
|
"node-mocks-http": "^1.17.2",
|
|
File without changes
|
/package/dist/plugins/codeGenerator/{typescriptTransfomer.d.ts → typescriptTransformer.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|