nesties 1.1.23 → 1.1.24
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/index.cjs +234 -9
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +228 -9
- package/dist/index.mjs.map +4 -4
- package/dist/src/i18n-module/i18n-factory.d.ts +6 -0
- package/dist/src/i18n-module/i18n-param-resolver.token.d.ts +2 -0
- package/dist/src/i18n-module/i18n.module.d.ts +2 -0
- package/dist/src/i18n-module/i18n.service.d.ts +3 -2
- package/dist/src/i18n-module/locale.context.d.ts +8 -0
- package/dist/src/resolver/index.d.ts +3 -0
- package/dist/src/resolver/lambda.d.ts +10 -0
- package/dist/src/{resolver.d.ts → resolver/resolver.d.ts} +3 -3
- package/dist/src/utility/index.d.ts +1 -0
- package/dist/src/utility/parse-bool.d.ts +1 -0
- package/package.json +1 -1
- package/dist/src/utility/parse-i18n.d.ts +0 -14
- /package/dist/src/{api-inject.d.ts → resolver/api-inject.d.ts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -67,6 +67,18 @@ var createMutateInject = (tokenResolver) => (token) => (target, propertyKey, par
|
|
|
67
67
|
);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
// src/utility/parse-bool.ts
|
|
71
|
+
var parseBool = (value) => {
|
|
72
|
+
const trueValues = ["true", "1", "yes", "on", true, 1];
|
|
73
|
+
const falseValues = ["false", "0", "no", "off", false, 0];
|
|
74
|
+
if (trueValues.indexOf(value) !== -1) return true;
|
|
75
|
+
if (falseValues.indexOf(value) !== -1) return false;
|
|
76
|
+
if (!!value) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return void 0;
|
|
80
|
+
};
|
|
81
|
+
|
|
70
82
|
// src/insert-field.ts
|
|
71
83
|
function InsertField(cl, map, newName) {
|
|
72
84
|
const extendedCl = class extends cl {
|
|
@@ -259,7 +271,7 @@ import {
|
|
|
259
271
|
import { ConfigService } from "@nestjs/config";
|
|
260
272
|
import { ApiHeader as ApiHeader2 } from "@nestjs/swagger";
|
|
261
273
|
|
|
262
|
-
// src/resolver.ts
|
|
274
|
+
// src/resolver/resolver.ts
|
|
263
275
|
import {
|
|
264
276
|
createParamDecorator,
|
|
265
277
|
Inject as Inject2,
|
|
@@ -303,7 +315,7 @@ var uniqBy = (arr, fn) => {
|
|
|
303
315
|
return result;
|
|
304
316
|
};
|
|
305
317
|
|
|
306
|
-
// src/resolver.ts
|
|
318
|
+
// src/resolver/resolver.ts
|
|
307
319
|
var ParamResolverCopiedFieldsFromSwagger = [
|
|
308
320
|
"required",
|
|
309
321
|
"description",
|
|
@@ -566,6 +578,145 @@ var ApiFromResolver = (_options, extras = {}) => {
|
|
|
566
578
|
return getParamResolver(_options).toApiPropertyDecorator(extras)();
|
|
567
579
|
};
|
|
568
580
|
|
|
581
|
+
// src/resolver/lambda.ts
|
|
582
|
+
var createLambdaParamResolver = (cb) => (resolver) => new TransformParamResolver(resolver, cb);
|
|
583
|
+
var ParseIntParamResolver = createLambdaParamResolver((s) => {
|
|
584
|
+
if (s == null) {
|
|
585
|
+
return s;
|
|
586
|
+
}
|
|
587
|
+
const res = parseInt(s, 10);
|
|
588
|
+
if (isNaN(res)) {
|
|
589
|
+
throw new BlankReturnMessageDto(
|
|
590
|
+
400,
|
|
591
|
+
"Invalid integer parameter"
|
|
592
|
+
).toException();
|
|
593
|
+
}
|
|
594
|
+
return res;
|
|
595
|
+
});
|
|
596
|
+
var ParseFloatParamResolver = createLambdaParamResolver(
|
|
597
|
+
(s) => {
|
|
598
|
+
if (s == null) {
|
|
599
|
+
return s;
|
|
600
|
+
}
|
|
601
|
+
const res = parseFloat(s);
|
|
602
|
+
if (isNaN(res)) {
|
|
603
|
+
throw new BlankReturnMessageDto(
|
|
604
|
+
400,
|
|
605
|
+
"Invalid float parameter"
|
|
606
|
+
).toException();
|
|
607
|
+
}
|
|
608
|
+
return res;
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
var ParseBoolParamResolver = createLambdaParamResolver(parseBool);
|
|
612
|
+
var ParseDateParamResolver = createLambdaParamResolver(
|
|
613
|
+
(s) => {
|
|
614
|
+
if (s == null) {
|
|
615
|
+
return s;
|
|
616
|
+
}
|
|
617
|
+
const res = new Date(s);
|
|
618
|
+
if (isNaN(res.getTime())) {
|
|
619
|
+
throw new BlankReturnMessageDto(
|
|
620
|
+
400,
|
|
621
|
+
"Invalid date parameter"
|
|
622
|
+
).toException();
|
|
623
|
+
}
|
|
624
|
+
return res;
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
var ParseBase64ParamResolver = createLambdaParamResolver(
|
|
628
|
+
(s) => {
|
|
629
|
+
if (s == null) {
|
|
630
|
+
return s;
|
|
631
|
+
}
|
|
632
|
+
const normalized = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
633
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
634
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(padded)) {
|
|
635
|
+
throw new BlankReturnMessageDto(
|
|
636
|
+
400,
|
|
637
|
+
"Invalid base64 parameter"
|
|
638
|
+
).toException();
|
|
639
|
+
}
|
|
640
|
+
const buf = Buffer.from(padded, "base64");
|
|
641
|
+
const re = buf.toString("base64").replace(/=+$/g, "");
|
|
642
|
+
const in0 = padded.replace(/=+$/g, "");
|
|
643
|
+
if (re !== in0) {
|
|
644
|
+
throw new BlankReturnMessageDto(
|
|
645
|
+
400,
|
|
646
|
+
"Invalid base64 parameter"
|
|
647
|
+
).toException();
|
|
648
|
+
}
|
|
649
|
+
return buf;
|
|
650
|
+
}
|
|
651
|
+
);
|
|
652
|
+
var DefaultValueParamResolver = (r, defaultValue) => createLambdaParamResolver(
|
|
653
|
+
(value) => value === void 0 || value === null ? defaultValue : value
|
|
654
|
+
)(r);
|
|
655
|
+
|
|
656
|
+
// src/utility/collect-info-from-injection-token.ts
|
|
657
|
+
import {
|
|
658
|
+
PARAMTYPES_METADATA,
|
|
659
|
+
SELF_DECLARED_DEPS_METADATA
|
|
660
|
+
} from "@nestjs/common/constants";
|
|
661
|
+
function asArray(v) {
|
|
662
|
+
if (v == null) return [];
|
|
663
|
+
return Array.isArray(v) ? v : [v];
|
|
664
|
+
}
|
|
665
|
+
function getCtorDepsFromClass(cls) {
|
|
666
|
+
const paramTypes = Reflect.getMetadata(PARAMTYPES_METADATA, cls) ?? [];
|
|
667
|
+
const selfDeclared = Reflect.getMetadata(SELF_DECLARED_DEPS_METADATA, cls) ?? [];
|
|
668
|
+
const overrides = new Map(
|
|
669
|
+
selfDeclared.map((d) => [d.index, d.param])
|
|
670
|
+
);
|
|
671
|
+
return paramTypes.map((t, i) => overrides.get(i) ?? t).filter((t) => t != null && t !== Object);
|
|
672
|
+
}
|
|
673
|
+
var collectInfoFromInjectionToken = (map, token) => {
|
|
674
|
+
const visited = /* @__PURE__ */ new Set();
|
|
675
|
+
const out = /* @__PURE__ */ new Set();
|
|
676
|
+
const dfs = (t) => {
|
|
677
|
+
if (t == null) return;
|
|
678
|
+
if (visited.has(t)) return;
|
|
679
|
+
visited.add(t);
|
|
680
|
+
for (const v of asArray(map.get(t))) {
|
|
681
|
+
out.add(v);
|
|
682
|
+
}
|
|
683
|
+
const deps = InjectionTokenMap.get(t);
|
|
684
|
+
if (deps?.length) {
|
|
685
|
+
for (const d of deps) dfs(d);
|
|
686
|
+
}
|
|
687
|
+
if (typeof t === "function") {
|
|
688
|
+
const ctorDeps = getCtorDepsFromClass(t);
|
|
689
|
+
for (const d of ctorDeps) dfs(d);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
dfs(token);
|
|
693
|
+
return Array.from(out);
|
|
694
|
+
};
|
|
695
|
+
var createCollectorFromInjectionToken = (map) => (token) => collectInfoFromInjectionToken(map, token);
|
|
696
|
+
|
|
697
|
+
// src/utility/swagger-injection-collector.ts
|
|
698
|
+
var swaggerInjectionCollector = createCollectorFromInjectionToken(ResolverSwaggerMap);
|
|
699
|
+
|
|
700
|
+
// src/resolver/api-inject.ts
|
|
701
|
+
var clsUsedMap = /* @__PURE__ */ new WeakMap();
|
|
702
|
+
var ApiInject = createMutateInject((token, cls) => {
|
|
703
|
+
const swaggers = swaggerInjectionCollector(token);
|
|
704
|
+
if (!swaggers.length) return token;
|
|
705
|
+
let usedSet = clsUsedMap.get(cls);
|
|
706
|
+
if (!usedSet) {
|
|
707
|
+
usedSet = /* @__PURE__ */ new Set();
|
|
708
|
+
clsUsedMap.set(cls, usedSet);
|
|
709
|
+
}
|
|
710
|
+
for (const swagger of swaggers) {
|
|
711
|
+
if (usedSet.has(swagger.token)) {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
usedSet.add(swagger.token);
|
|
715
|
+
swagger.swagger()(cls);
|
|
716
|
+
}
|
|
717
|
+
return token;
|
|
718
|
+
});
|
|
719
|
+
|
|
569
720
|
// src/token.guard.ts
|
|
570
721
|
import { MetadataSetter, Reflector } from "typed-reflector";
|
|
571
722
|
import { ModuleRef as ModuleRef2 } from "@nestjs/core";
|
|
@@ -804,14 +955,20 @@ var I18nModuleOptionsToken = MODULE_OPTIONS_TOKEN;
|
|
|
804
955
|
// src/i18n-module/i18n.service.ts
|
|
805
956
|
import { ModuleRef as ModuleRef4 } from "@nestjs/core";
|
|
806
957
|
import { I18n } from "nfkit";
|
|
958
|
+
|
|
959
|
+
// src/i18n-module/i18n-param-resolver.token.ts
|
|
960
|
+
var I18nParamResolverToken = "I18N_PARAM_RESOLVER";
|
|
961
|
+
var I18nParamResolverProviderToken = "I18N_PARAM_RESOLVER_PROVIDER";
|
|
962
|
+
|
|
963
|
+
// src/i18n-module/i18n.service.ts
|
|
807
964
|
var I18nService = class extends I18n {
|
|
808
|
-
constructor(i18nServiceOptions, moduleRef) {
|
|
965
|
+
constructor(i18nServiceOptions, moduleRef, resolver) {
|
|
809
966
|
super(i18nServiceOptions);
|
|
810
967
|
this.i18nServiceOptions = i18nServiceOptions;
|
|
811
968
|
this.moduleRef = moduleRef;
|
|
969
|
+
this.resolver = resolver;
|
|
812
970
|
this._shadowMiddlewareMap = /* @__PURE__ */ new Map();
|
|
813
971
|
this.logger = new ConsoleLogger("I18nService");
|
|
814
|
-
this.resolver = createResolver(this.i18nServiceOptions.resolver);
|
|
815
972
|
}
|
|
816
973
|
middleware(mw, prior = false) {
|
|
817
974
|
const wrappedMw = async (locale, text, next, ctx) => {
|
|
@@ -838,19 +995,20 @@ var I18nService = class extends I18n {
|
|
|
838
995
|
}
|
|
839
996
|
async getExactLocaleFromRequest(ctx) {
|
|
840
997
|
const req = ctx.switchToHttp().getRequest();
|
|
841
|
-
const locale = await this.resolver(req, this.moduleRef);
|
|
998
|
+
const locale = await this.resolver.resolve(req, this.moduleRef);
|
|
842
999
|
return this.getExactLocale(locale);
|
|
843
1000
|
}
|
|
844
1001
|
async translateRequest(ctx, obj) {
|
|
845
1002
|
const req = ctx.switchToHttp().getRequest();
|
|
846
|
-
const locale = await this.resolver(req, this.moduleRef);
|
|
1003
|
+
const locale = await this.resolver.resolve(req, this.moduleRef);
|
|
847
1004
|
return this.translate(locale, obj, ctx);
|
|
848
1005
|
}
|
|
849
1006
|
};
|
|
850
1007
|
I18nService = __decorateClass([
|
|
851
1008
|
Injectable3(),
|
|
852
1009
|
__decorateParam(0, Inject6(I18nModuleOptionsToken)),
|
|
853
|
-
__decorateParam(1, Inject6(ModuleRef4))
|
|
1010
|
+
__decorateParam(1, Inject6(ModuleRef4)),
|
|
1011
|
+
__decorateParam(2, Inject6(I18nParamResolverToken))
|
|
854
1012
|
], I18nService);
|
|
855
1013
|
|
|
856
1014
|
// src/i18n-module/i18n.module.ts
|
|
@@ -893,12 +1051,26 @@ var _dec = createParamDecorator3(
|
|
|
893
1051
|
var PutLocale = (resolver) => _dec(resolver, LocalePipe);
|
|
894
1052
|
|
|
895
1053
|
// src/i18n-module/i18n.module.ts
|
|
1054
|
+
var providerFromOptions = createProvider(
|
|
1055
|
+
{
|
|
1056
|
+
provide: I18nParamResolverToken,
|
|
1057
|
+
inject: [I18nModuleOptionsToken]
|
|
1058
|
+
},
|
|
1059
|
+
(options) => getParamResolver(
|
|
1060
|
+
options.resolver || {
|
|
1061
|
+
paramType: "header",
|
|
1062
|
+
paramName: "x-client-language"
|
|
1063
|
+
}
|
|
1064
|
+
)
|
|
1065
|
+
);
|
|
896
1066
|
var I18nModule = class extends ConfigurableModuleClass {
|
|
1067
|
+
static forRoot(options) {
|
|
1068
|
+
}
|
|
897
1069
|
};
|
|
898
1070
|
I18nModule = __decorateClass([
|
|
899
1071
|
Global(),
|
|
900
1072
|
Module2({
|
|
901
|
-
providers: [I18nService, LocalePipe],
|
|
1073
|
+
providers: [I18nService, LocalePipe, providerFromOptions],
|
|
902
1074
|
exports: [I18nService, LocalePipe]
|
|
903
1075
|
})
|
|
904
1076
|
], I18nModule);
|
|
@@ -958,6 +1130,24 @@ var createI18nDecorator = (options) => {
|
|
|
958
1130
|
]);
|
|
959
1131
|
};
|
|
960
1132
|
|
|
1133
|
+
// src/i18n-module/locale.context.ts
|
|
1134
|
+
import { Inject as Inject9, Injectable as Injectable6, Scope as Scope4 } from "@nestjs/common";
|
|
1135
|
+
var LocaleContext = class {
|
|
1136
|
+
constructor(localeInput, i18nService) {
|
|
1137
|
+
this.localeInput = localeInput;
|
|
1138
|
+
this.i18nService = i18nService;
|
|
1139
|
+
this.locale = this.i18nService.getExactLocale(this.localeInput);
|
|
1140
|
+
}
|
|
1141
|
+
translate(v) {
|
|
1142
|
+
return this.i18nService.translate(this.locale, v);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
LocaleContext = __decorateClass([
|
|
1146
|
+
Injectable6({ scope: Scope4.REQUEST }),
|
|
1147
|
+
__decorateParam(0, Inject9(I18nParamResolverProviderToken)),
|
|
1148
|
+
__decorateParam(1, Inject9(I18nService))
|
|
1149
|
+
], LocaleContext);
|
|
1150
|
+
|
|
961
1151
|
// src/i18n-module/i18n-factory.ts
|
|
962
1152
|
var createI18n = (options) => {
|
|
963
1153
|
if (!options.resolver) {
|
|
@@ -966,9 +1156,29 @@ var createI18n = (options) => {
|
|
|
966
1156
|
paramName: "x-client-language"
|
|
967
1157
|
};
|
|
968
1158
|
}
|
|
1159
|
+
const resolver = getParamResolver(options.resolver);
|
|
1160
|
+
const paramProvider = resolver.toRequestScopedProvider();
|
|
1161
|
+
const module = I18nModule.register(options);
|
|
1162
|
+
module.providers ??= [];
|
|
1163
|
+
module.exports ??= [];
|
|
1164
|
+
module.providers.push(
|
|
1165
|
+
paramProvider.provider,
|
|
1166
|
+
LocaleContext,
|
|
1167
|
+
// re-exports the resolved param value for LocaleContext injection
|
|
1168
|
+
createProvider(
|
|
1169
|
+
{
|
|
1170
|
+
provide: I18nParamResolverProviderToken,
|
|
1171
|
+
inject: [paramProvider.token]
|
|
1172
|
+
},
|
|
1173
|
+
(s) => s
|
|
1174
|
+
)
|
|
1175
|
+
);
|
|
1176
|
+
module.exports.push(paramProvider.provider, LocaleContext);
|
|
969
1177
|
return {
|
|
970
1178
|
UseI18n: createI18nDecorator(options),
|
|
971
|
-
I18nModule:
|
|
1179
|
+
I18nModule: module,
|
|
1180
|
+
I18nParamResolver: resolver,
|
|
1181
|
+
I18nParamResolverProvider: paramProvider
|
|
972
1182
|
};
|
|
973
1183
|
};
|
|
974
1184
|
|
|
@@ -983,6 +1193,7 @@ export {
|
|
|
983
1193
|
ApiError,
|
|
984
1194
|
ApiErrorTyped,
|
|
985
1195
|
ApiFromResolver,
|
|
1196
|
+
ApiInject,
|
|
986
1197
|
ApiTypeResponse,
|
|
987
1198
|
As,
|
|
988
1199
|
BlankPaginatedReturnMessageDto,
|
|
@@ -991,6 +1202,7 @@ export {
|
|
|
991
1202
|
DataBody,
|
|
992
1203
|
DataPipe,
|
|
993
1204
|
DataQuery,
|
|
1205
|
+
DefaultValueParamResolver,
|
|
994
1206
|
GenericPaginatedReturnMessageDto,
|
|
995
1207
|
GenericReturnMessageDto,
|
|
996
1208
|
I18nInterceptor,
|
|
@@ -1010,6 +1222,11 @@ export {
|
|
|
1010
1222
|
ParamResolver,
|
|
1011
1223
|
ParamResolverBase,
|
|
1012
1224
|
ParamResolverPipe,
|
|
1225
|
+
ParseBase64ParamResolver,
|
|
1226
|
+
ParseBoolParamResolver,
|
|
1227
|
+
ParseDateParamResolver,
|
|
1228
|
+
ParseFloatParamResolver,
|
|
1229
|
+
ParseIntParamResolver,
|
|
1013
1230
|
PutLocale,
|
|
1014
1231
|
RenameClass,
|
|
1015
1232
|
RequireToken,
|
|
@@ -1021,6 +1238,7 @@ export {
|
|
|
1021
1238
|
createAbortableProvider,
|
|
1022
1239
|
createI18n,
|
|
1023
1240
|
createI18nDecorator,
|
|
1241
|
+
createLambdaParamResolver,
|
|
1024
1242
|
createMutateInject,
|
|
1025
1243
|
createProvider,
|
|
1026
1244
|
createResolver,
|
|
@@ -1028,6 +1246,7 @@ export {
|
|
|
1028
1246
|
getApiProperty,
|
|
1029
1247
|
getClassFromClassOrArray,
|
|
1030
1248
|
getParamResolver,
|
|
1249
|
+
parseBool,
|
|
1031
1250
|
takeUntilAbort
|
|
1032
1251
|
};
|
|
1033
1252
|
//# sourceMappingURL=index.mjs.map
|