nicot 1.4.0 → 1.4.1
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 +40 -0
- package/README.md +41 -0
- package/dist/index.cjs +89 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +85 -2
- package/dist/index.mjs.map +4 -4
- package/dist/src/decorators/property.d.ts +10 -0
- package/dist/src/decorators/query.d.ts +10 -0
- package/dist/src/utility/base64-binary.d.ts +23 -0
- package/dist/src/utility/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -677,6 +677,7 @@ import { ApiProperty as ApiProperty2 } from "@nestjs/swagger";
|
|
|
677
677
|
import { MergePropertyDecorators as MergePropertyDecorators2 } from "nesties";
|
|
678
678
|
import { Column, Index } from "typeorm";
|
|
679
679
|
import {
|
|
680
|
+
buildMessage,
|
|
680
681
|
IsDate,
|
|
681
682
|
IsEnum,
|
|
682
683
|
IsInt,
|
|
@@ -687,7 +688,9 @@ import {
|
|
|
687
688
|
Max,
|
|
688
689
|
MaxLength,
|
|
689
690
|
Min,
|
|
690
|
-
|
|
691
|
+
ValidateBy,
|
|
692
|
+
ValidateNested as ValidateNested2,
|
|
693
|
+
isBase64
|
|
691
694
|
} from "class-validator";
|
|
692
695
|
import { Exclude, Transform, Type as Type2 } from "class-transformer";
|
|
693
696
|
|
|
@@ -837,6 +840,40 @@ var GetMutatorJson = createGetMutator((s) => JSON.parse(s), {
|
|
|
837
840
|
example: `{"key1":"value1","key2":2,"key3":[1,2,3]}`
|
|
838
841
|
});
|
|
839
842
|
|
|
843
|
+
// src/utility/base64-binary.ts
|
|
844
|
+
function isBinaryLike(value) {
|
|
845
|
+
return Buffer.isBuffer(value) || value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
846
|
+
}
|
|
847
|
+
function binaryToBuffer(value) {
|
|
848
|
+
if (Buffer.isBuffer(value)) {
|
|
849
|
+
return value;
|
|
850
|
+
}
|
|
851
|
+
if (value instanceof Uint8Array) {
|
|
852
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
853
|
+
}
|
|
854
|
+
return Buffer.from(new Uint8Array(value));
|
|
855
|
+
}
|
|
856
|
+
var Base64BinaryTransformer = class {
|
|
857
|
+
to(entValue) {
|
|
858
|
+
if (entValue == null) {
|
|
859
|
+
return entValue;
|
|
860
|
+
}
|
|
861
|
+
if (isBinaryLike(entValue)) {
|
|
862
|
+
return binaryToBuffer(entValue);
|
|
863
|
+
}
|
|
864
|
+
return Buffer.from(String(entValue), "base64");
|
|
865
|
+
}
|
|
866
|
+
from(dbValue) {
|
|
867
|
+
if (dbValue == null) {
|
|
868
|
+
return dbValue;
|
|
869
|
+
}
|
|
870
|
+
if (isBinaryLike(dbValue)) {
|
|
871
|
+
return binaryToBuffer(dbValue).toString("base64");
|
|
872
|
+
}
|
|
873
|
+
return Buffer.from(String(dbValue)).toString("base64");
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
840
877
|
// src/decorators/property.ts
|
|
841
878
|
var NotRequiredButHasDefaultDec = () => Metadata.set(
|
|
842
879
|
"notRequiredButHasDefault",
|
|
@@ -1059,6 +1096,29 @@ var StringJsonColumn = createJsonColumnDef(
|
|
|
1059
1096
|
"text",
|
|
1060
1097
|
TypeTransformerString
|
|
1061
1098
|
);
|
|
1099
|
+
var IsBase64OrBinary = (validationOptions) => ValidateBy(
|
|
1100
|
+
{
|
|
1101
|
+
name: "isBase64OrBinary",
|
|
1102
|
+
validator: {
|
|
1103
|
+
validate: (value) => isBinaryLike(value) || typeof value === "string" && isBase64(value),
|
|
1104
|
+
defaultMessage: buildMessage(
|
|
1105
|
+
(eachPrefix) => `${eachPrefix}$property must be a base64 string or binary data (Buffer / Uint8Array / ArrayBuffer)`,
|
|
1106
|
+
validationOptions
|
|
1107
|
+
)
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
validationOptions
|
|
1111
|
+
);
|
|
1112
|
+
var Base64BinaryColumn = (options = {}) => MergePropertyDecorators2([
|
|
1113
|
+
Column(options.columnType || "bytea", {
|
|
1114
|
+
...columnDecoratorOptions(options),
|
|
1115
|
+
default: void 0,
|
|
1116
|
+
transformer: new Base64BinaryTransformer()
|
|
1117
|
+
}),
|
|
1118
|
+
IsBase64OrBinary(),
|
|
1119
|
+
validatorDecorator(options),
|
|
1120
|
+
swaggerDecorator(options, { type: String, format: "byte" })
|
|
1121
|
+
]);
|
|
1062
1122
|
var NotColumn = (options = {}, specials = {}) => MergePropertyDecorators2([
|
|
1063
1123
|
Exclude(),
|
|
1064
1124
|
swaggerDecorator({
|
|
@@ -1282,6 +1342,21 @@ var createQueryOperatorArrayify = (operator, singleFallback) => createQueryArray
|
|
|
1282
1342
|
);
|
|
1283
1343
|
var QueryIn = createQueryOperatorArrayify("IN", "=");
|
|
1284
1344
|
var QueryNotIn = createQueryOperatorArrayify("NOT IN", "!=");
|
|
1345
|
+
var toBase64QueryBuffer = (value) => {
|
|
1346
|
+
if (value == null) {
|
|
1347
|
+
return value;
|
|
1348
|
+
}
|
|
1349
|
+
if (isBinaryLike(value)) {
|
|
1350
|
+
return binaryToBuffer(value);
|
|
1351
|
+
}
|
|
1352
|
+
return Buffer.from(String(value), "base64");
|
|
1353
|
+
};
|
|
1354
|
+
var createQueryBase64Operator = (operator) => (field) => QueryWrap((entityExpr, varExpr, info) => {
|
|
1355
|
+
info.mutateValue(toBase64QueryBuffer(info.value));
|
|
1356
|
+
return `${entityExpr} ${operator} ${varExpr}`;
|
|
1357
|
+
}, field);
|
|
1358
|
+
var QueryBase64Equal = createQueryBase64Operator("=");
|
|
1359
|
+
var QueryBase64NotEqual = createQueryBase64Operator("!=");
|
|
1285
1360
|
var QueryFullText = (options = {}) => {
|
|
1286
1361
|
const configurationName = options.parser ? `nicot_parser_${options.parser}` : options.configuration || "english";
|
|
1287
1362
|
const tsQueryFunction = options.tsQueryFunction || "websearch_to_tsquery";
|
|
@@ -4107,6 +4182,8 @@ TransactionalTypeOrmModule = __decorateClass([
|
|
|
4107
4182
|
Module({})
|
|
4108
4183
|
], TransactionalTypeOrmModule);
|
|
4109
4184
|
export {
|
|
4185
|
+
Base64BinaryColumn,
|
|
4186
|
+
Base64BinaryTransformer,
|
|
4110
4187
|
BindingColumn,
|
|
4111
4188
|
BindingValue,
|
|
4112
4189
|
BlankCursorPaginationReturnMessageDto,
|
|
@@ -4139,6 +4216,7 @@ export {
|
|
|
4139
4216
|
Inner,
|
|
4140
4217
|
IntColumn,
|
|
4141
4218
|
InternalColumn,
|
|
4219
|
+
IsBase64OrBinary,
|
|
4142
4220
|
JsonColumn,
|
|
4143
4221
|
NotChangeable,
|
|
4144
4222
|
NotColumn,
|
|
@@ -4152,6 +4230,8 @@ export {
|
|
|
4152
4230
|
PageSettingsDto,
|
|
4153
4231
|
PickPipe,
|
|
4154
4232
|
QueryAnd,
|
|
4233
|
+
QueryBase64Equal,
|
|
4234
|
+
QueryBase64NotEqual,
|
|
4155
4235
|
QueryColumn,
|
|
4156
4236
|
QueryCondition,
|
|
4157
4237
|
QueryEqual,
|
|
@@ -4195,8 +4275,10 @@ export {
|
|
|
4195
4275
|
applyQueryPropertyLike,
|
|
4196
4276
|
applyQueryPropertySearch,
|
|
4197
4277
|
applyQueryPropertyZeroNullable,
|
|
4278
|
+
binaryToBuffer,
|
|
4198
4279
|
createGetMutator,
|
|
4199
4280
|
createQueryArrayify,
|
|
4281
|
+
createQueryBase64Operator,
|
|
4200
4282
|
createQueryCondition,
|
|
4201
4283
|
createQueryOperator,
|
|
4202
4284
|
createQueryOperatorArrayify,
|
|
@@ -4204,6 +4286,7 @@ export {
|
|
|
4204
4286
|
getTransactionalEntityManagerProvider,
|
|
4205
4287
|
getTransactionalEntityManagerToken,
|
|
4206
4288
|
getTransactionalRepositoryProvider,
|
|
4207
|
-
getTransactionalRepositoryToken
|
|
4289
|
+
getTransactionalRepositoryToken,
|
|
4290
|
+
isBinaryLike
|
|
4208
4291
|
};
|
|
4209
4292
|
//# sourceMappingURL=index.mjs.map
|