nicot 1.4.1 → 1.4.3
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-CN.md +4 -3
- package/README.md +5 -4
- package/dist/index.cjs +151 -68
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +102 -22
- package/dist/index.mjs.map +4 -4
- package/dist/src/decorators/property.d.ts +2 -0
- package/dist/src/decorators/query.d.ts +12 -7
- package/dist/src/restful.d.ts +3 -3
- package/dist/src/utility/base64-binary.d.ts +11 -5
- package/dist/src/utility/get-api-property.d.ts +3 -0
- package/dist/src/utility/patch-column-in-get.d.ts +1 -1
- package/dist/src/utility/swagger-decorators.d.ts +23 -0
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -853,15 +853,31 @@ function binaryToBuffer(value) {
|
|
|
853
853
|
}
|
|
854
854
|
return Buffer.from(new Uint8Array(value));
|
|
855
855
|
}
|
|
856
|
+
function binaryToPostgresByteaHex(value) {
|
|
857
|
+
return `\\x${binaryToBuffer(value).toString("hex")}`;
|
|
858
|
+
}
|
|
859
|
+
function base64OrBinaryToBuffer(value) {
|
|
860
|
+
if (isBinaryLike(value)) {
|
|
861
|
+
return binaryToBuffer(value);
|
|
862
|
+
}
|
|
863
|
+
return Buffer.from(String(value), "base64");
|
|
864
|
+
}
|
|
865
|
+
function base64OrBinaryToDatabaseValue(value, storage = "postgres-bytea") {
|
|
866
|
+
const buffer = base64OrBinaryToBuffer(value);
|
|
867
|
+
if (storage === "postgres-bytea") {
|
|
868
|
+
return binaryToPostgresByteaHex(buffer);
|
|
869
|
+
}
|
|
870
|
+
return buffer;
|
|
871
|
+
}
|
|
856
872
|
var Base64BinaryTransformer = class {
|
|
873
|
+
constructor(storage = "postgres-bytea") {
|
|
874
|
+
this.storage = storage;
|
|
875
|
+
}
|
|
857
876
|
to(entValue) {
|
|
858
877
|
if (entValue == null) {
|
|
859
878
|
return entValue;
|
|
860
879
|
}
|
|
861
|
-
|
|
862
|
-
return binaryToBuffer(entValue);
|
|
863
|
-
}
|
|
864
|
-
return Buffer.from(String(entValue), "base64");
|
|
880
|
+
return base64OrBinaryToDatabaseValue(entValue, this.storage);
|
|
865
881
|
}
|
|
866
882
|
from(dbValue) {
|
|
867
883
|
if (dbValue == null) {
|
|
@@ -870,7 +886,11 @@ var Base64BinaryTransformer = class {
|
|
|
870
886
|
if (isBinaryLike(dbValue)) {
|
|
871
887
|
return binaryToBuffer(dbValue).toString("base64");
|
|
872
888
|
}
|
|
873
|
-
|
|
889
|
+
const text = String(dbValue);
|
|
890
|
+
if (/^\\x[0-9a-f]*$/i.test(text)) {
|
|
891
|
+
return Buffer.from(text.slice(2), "hex").toString("base64");
|
|
892
|
+
}
|
|
893
|
+
return Buffer.from(text).toString("base64");
|
|
874
894
|
}
|
|
875
895
|
};
|
|
876
896
|
|
|
@@ -1113,7 +1133,9 @@ var Base64BinaryColumn = (options = {}) => MergePropertyDecorators2([
|
|
|
1113
1133
|
Column(options.columnType || "bytea", {
|
|
1114
1134
|
...columnDecoratorOptions(options),
|
|
1115
1135
|
default: void 0,
|
|
1116
|
-
transformer: new Base64BinaryTransformer(
|
|
1136
|
+
transformer: new Base64BinaryTransformer(
|
|
1137
|
+
options.binaryStorage ?? (options.columnType && options.columnType !== "bytea" ? "binary" : "postgres-bytea")
|
|
1138
|
+
)
|
|
1117
1139
|
}),
|
|
1118
1140
|
IsBase64OrBinary(),
|
|
1119
1141
|
validatorDecorator(options),
|
|
@@ -1342,19 +1364,20 @@ var createQueryOperatorArrayify = (operator, singleFallback) => createQueryArray
|
|
|
1342
1364
|
);
|
|
1343
1365
|
var QueryIn = createQueryOperatorArrayify("IN", "=");
|
|
1344
1366
|
var QueryNotIn = createQueryOperatorArrayify("NOT IN", "!=");
|
|
1345
|
-
var
|
|
1367
|
+
var normalizeQueryBase64Options = (fieldOrOptions) => typeof fieldOrOptions === "string" ? { field: fieldOrOptions } : fieldOrOptions ?? {};
|
|
1368
|
+
var toBase64QueryValue = (value, storage = "postgres-bytea") => {
|
|
1346
1369
|
if (value == null) {
|
|
1347
1370
|
return value;
|
|
1348
1371
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1372
|
+
return base64OrBinaryToDatabaseValue(value, storage);
|
|
1373
|
+
};
|
|
1374
|
+
var createQueryBase64Operator = (operator) => (fieldOrOptions) => {
|
|
1375
|
+
const options = normalizeQueryBase64Options(fieldOrOptions);
|
|
1376
|
+
return QueryWrap((entityExpr, varExpr, info) => {
|
|
1377
|
+
info.mutateValue(toBase64QueryValue(info.value, options.binaryStorage));
|
|
1378
|
+
return `${entityExpr} ${operator} ${varExpr}`;
|
|
1379
|
+
}, options.field);
|
|
1353
1380
|
};
|
|
1354
|
-
var createQueryBase64Operator = (operator) => (field) => QueryWrap((entityExpr, varExpr, info) => {
|
|
1355
|
-
info.mutateValue(toBase64QueryBuffer(info.value));
|
|
1356
|
-
return `${entityExpr} ${operator} ${varExpr}`;
|
|
1357
|
-
}, field);
|
|
1358
1381
|
var QueryBase64Equal = createQueryBase64Operator("=");
|
|
1359
1382
|
var QueryBase64NotEqual = createQueryBase64Operator("!=");
|
|
1360
1383
|
var QueryFullText = (options = {}) => {
|
|
@@ -3011,11 +3034,11 @@ import {
|
|
|
3011
3034
|
MergeMethodDecorators,
|
|
3012
3035
|
PaginatedReturnMessageDto as PaginatedReturnMessageDto2,
|
|
3013
3036
|
ReturnMessageDto as ReturnMessageDto2,
|
|
3014
|
-
getApiProperty as getApiProperty2,
|
|
3015
3037
|
DataPipe,
|
|
3016
3038
|
ApiTypeResponse,
|
|
3017
3039
|
ApiBlankResponse,
|
|
3018
|
-
ApiError
|
|
3040
|
+
ApiError,
|
|
3041
|
+
RenameClass
|
|
3019
3042
|
} from "nesties";
|
|
3020
3043
|
import {
|
|
3021
3044
|
ApiBody,
|
|
@@ -3029,7 +3052,6 @@ import {
|
|
|
3029
3052
|
PickType as PickType2
|
|
3030
3053
|
} from "@nestjs/swagger";
|
|
3031
3054
|
import _6, { upperFirst } from "lodash";
|
|
3032
|
-
import { RenameClass } from "nesties";
|
|
3033
3055
|
|
|
3034
3056
|
// src/bases/base-restful-controller.ts
|
|
3035
3057
|
var RestfulMethods = [
|
|
@@ -3095,9 +3117,64 @@ var OmitTypeExclude = (cl, keys) => {
|
|
|
3095
3117
|
};
|
|
3096
3118
|
|
|
3097
3119
|
// src/utility/patch-column-in-get.ts
|
|
3098
|
-
import { getApiProperty } from "nesties";
|
|
3099
3120
|
import _5 from "lodash";
|
|
3100
|
-
|
|
3121
|
+
|
|
3122
|
+
// src/utility/swagger-decorators.ts
|
|
3123
|
+
var DECORATORS_PREFIX = "swagger";
|
|
3124
|
+
var FALLBACK_DECORATORS = {
|
|
3125
|
+
API_OPERATION: `${DECORATORS_PREFIX}/apiOperation`,
|
|
3126
|
+
API_RESPONSE: `${DECORATORS_PREFIX}/apiResponse`,
|
|
3127
|
+
API_PRODUCES: `${DECORATORS_PREFIX}/apiProduces`,
|
|
3128
|
+
API_CONSUMES: `${DECORATORS_PREFIX}/apiConsumes`,
|
|
3129
|
+
API_TAGS: `${DECORATORS_PREFIX}/apiUseTags`,
|
|
3130
|
+
API_WEBHOOK: `${DECORATORS_PREFIX}/apiWebhook`,
|
|
3131
|
+
API_CALLBACKS: `${DECORATORS_PREFIX}/apiCallbacks`,
|
|
3132
|
+
API_PARAMETERS: `${DECORATORS_PREFIX}/apiParameters`,
|
|
3133
|
+
API_HEADERS: `${DECORATORS_PREFIX}/apiHeaders`,
|
|
3134
|
+
API_MODEL_PROPERTIES: `${DECORATORS_PREFIX}/apiModelProperties`,
|
|
3135
|
+
API_MODEL_PROPERTIES_ARRAY: `${DECORATORS_PREFIX}/apiModelPropertiesArray`,
|
|
3136
|
+
API_SECURITY: `${DECORATORS_PREFIX}/apiSecurity`,
|
|
3137
|
+
API_EXCLUDE_ENDPOINT: `${DECORATORS_PREFIX}/apiExcludeEndpoint`,
|
|
3138
|
+
API_INCLUDE_ENDPOINT: `${DECORATORS_PREFIX}/apiIncludeEndpoint`,
|
|
3139
|
+
API_EXCLUDE_CONTROLLER: `${DECORATORS_PREFIX}/apiExcludeController`,
|
|
3140
|
+
API_EXTRA_MODELS: `${DECORATORS_PREFIX}/apiExtraModels`,
|
|
3141
|
+
API_EXTENSION: `${DECORATORS_PREFIX}/apiExtension`,
|
|
3142
|
+
API_SCHEMA: `${DECORATORS_PREFIX}/apiSchema`,
|
|
3143
|
+
API_DEFAULT_GETTER: `${DECORATORS_PREFIX}/apiDefaultGetter`,
|
|
3144
|
+
API_LINK: `${DECORATORS_PREFIX}/apiLink`
|
|
3145
|
+
};
|
|
3146
|
+
function loadSwaggerDecorators() {
|
|
3147
|
+
try {
|
|
3148
|
+
const req = typeof __require === "function" ? __require : void 0;
|
|
3149
|
+
const decorators = req?.("@nestjs/swagger/dist/constants")?.DECORATORS;
|
|
3150
|
+
if (decorators) {
|
|
3151
|
+
return {
|
|
3152
|
+
...FALLBACK_DECORATORS,
|
|
3153
|
+
...decorators
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
} catch {
|
|
3157
|
+
}
|
|
3158
|
+
return FALLBACK_DECORATORS;
|
|
3159
|
+
}
|
|
3160
|
+
var DECORATORS = loadSwaggerDecorators();
|
|
3161
|
+
|
|
3162
|
+
// src/utility/get-api-property.ts
|
|
3163
|
+
var getApiProperty = (cls, key) => {
|
|
3164
|
+
let proto = cls.prototype;
|
|
3165
|
+
while (proto && proto !== Object.prototype) {
|
|
3166
|
+
const meta = Reflect.getMetadata(
|
|
3167
|
+
DECORATORS.API_MODEL_PROPERTIES,
|
|
3168
|
+
proto,
|
|
3169
|
+
key
|
|
3170
|
+
);
|
|
3171
|
+
if (meta) return meta;
|
|
3172
|
+
proto = Object.getPrototypeOf(proto);
|
|
3173
|
+
}
|
|
3174
|
+
return {};
|
|
3175
|
+
};
|
|
3176
|
+
|
|
3177
|
+
// src/utility/patch-column-in-get.ts
|
|
3101
3178
|
var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
3102
3179
|
const omit2 = new Set(fieldsToOmit);
|
|
3103
3180
|
const useCl = originalCl || cl;
|
|
@@ -3445,7 +3522,7 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
3445
3522
|
if (outputFieldsToOmit.has(relation.propertyName)) continue;
|
|
3446
3523
|
if (nonTransformableTypes.has(relation.propertyClass)) continue;
|
|
3447
3524
|
const replace = (useClass) => {
|
|
3448
|
-
const oldApiProperty =
|
|
3525
|
+
const oldApiProperty = getApiProperty(
|
|
3449
3526
|
this.entityClass,
|
|
3450
3527
|
relation.propertyName
|
|
3451
3528
|
);
|
|
@@ -3488,7 +3565,7 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
3488
3565
|
"notRequiredButHasDefault"
|
|
3489
3566
|
).filter((f) => !outputFieldsToOmit.has(f));
|
|
3490
3567
|
for (const field of notRequiredButHasDefaultFields) {
|
|
3491
|
-
const oldApiProperty =
|
|
3568
|
+
const oldApiProperty = getApiProperty(resultDto, field);
|
|
3492
3569
|
ApiProperty5({
|
|
3493
3570
|
...oldApiProperty,
|
|
3494
3571
|
required: true
|
|
@@ -4275,7 +4352,10 @@ export {
|
|
|
4275
4352
|
applyQueryPropertyLike,
|
|
4276
4353
|
applyQueryPropertySearch,
|
|
4277
4354
|
applyQueryPropertyZeroNullable,
|
|
4355
|
+
base64OrBinaryToBuffer,
|
|
4356
|
+
base64OrBinaryToDatabaseValue,
|
|
4278
4357
|
binaryToBuffer,
|
|
4358
|
+
binaryToPostgresByteaHex,
|
|
4279
4359
|
createGetMutator,
|
|
4280
4360
|
createQueryArrayify,
|
|
4281
4361
|
createQueryBase64Operator,
|