nicot 1.3.8 → 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 +100 -12
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +96 -13
- 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 +6 -4
package/dist/index.mjs
CHANGED
|
@@ -90,7 +90,7 @@ var require_typeorm_utils = __commonJS({
|
|
|
90
90
|
throw new circular_dependency_exception_1.CircularDependencyException("@InjectRepository()");
|
|
91
91
|
}
|
|
92
92
|
const dataSourcePrefix = getDataSourcePrefix(dataSource);
|
|
93
|
-
if (entity instanceof Function && (entity.prototype instanceof typeorm_1.Repository || entity.prototype instanceof typeorm_1.AbstractRepository)) {
|
|
93
|
+
if (entity instanceof Function && (entity.prototype instanceof typeorm_1.Repository || typeorm_1.AbstractRepository && entity.prototype instanceof typeorm_1.AbstractRepository)) {
|
|
94
94
|
if (!dataSourcePrefix) {
|
|
95
95
|
return entity;
|
|
96
96
|
}
|
|
@@ -108,7 +108,7 @@ var require_typeorm_utils = __commonJS({
|
|
|
108
108
|
return repository.name;
|
|
109
109
|
}
|
|
110
110
|
function getDataSourceToken(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
111
|
-
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.DataSource
|
|
111
|
+
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.DataSource : "string" === typeof dataSource ? `${dataSource}DataSource` : typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name ? typeorm_1.DataSource : `${dataSource.name}DataSource`;
|
|
112
112
|
}
|
|
113
113
|
exports.getConnectionToken = getDataSourceToken;
|
|
114
114
|
function getDataSourcePrefix(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
@@ -313,7 +313,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
313
313
|
typeOrmModuleOptions
|
|
314
314
|
];
|
|
315
315
|
const exports2 = [entityManagerProvider, dataSourceProvider];
|
|
316
|
-
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
316
|
+
if (typeorm_1.Connection && dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
317
317
|
providers.push({
|
|
318
318
|
provide: typeorm_1.Connection,
|
|
319
319
|
useExisting: typeorm_1.DataSource
|
|
@@ -360,7 +360,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
360
360
|
entityManagerProvider,
|
|
361
361
|
dataSourceProvider
|
|
362
362
|
];
|
|
363
|
-
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
363
|
+
if (typeorm_1.Connection && dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
364
364
|
providers.push({
|
|
365
365
|
provide: typeorm_1.Connection,
|
|
366
366
|
useExisting: typeorm_1.DataSource
|
|
@@ -423,9 +423,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
423
423
|
}
|
|
424
424
|
static async createDataSourceFactory(options, dataSourceFactory) {
|
|
425
425
|
const dataSourceToken = (0, typeorm_utils_1.getDataSourceName)(options);
|
|
426
|
-
const createTypeormDataSource = dataSourceFactory ?? ((options2) =>
|
|
427
|
-
return typeorm_1.DataSource === void 0 ? (0, typeorm_1.createConnection)(options2) : new typeorm_1.DataSource(options2);
|
|
428
|
-
});
|
|
426
|
+
const createTypeormDataSource = dataSourceFactory ?? ((options2) => new typeorm_1.DataSource(options2));
|
|
429
427
|
return await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => {
|
|
430
428
|
let dataSource;
|
|
431
429
|
if (!options.autoLoadEntities) {
|
|
@@ -442,7 +440,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
442
440
|
entities
|
|
443
441
|
});
|
|
444
442
|
}
|
|
445
|
-
return
|
|
443
|
+
return !dataSource.isInitialized && !options.manualInitialization ? dataSource.initialize() : dataSource;
|
|
446
444
|
}).pipe((0, typeorm_utils_1.handleRetry)(options.retryAttempts, options.retryDelay, dataSourceToken, options.verboseRetryLog, options.toRetry)));
|
|
447
445
|
}
|
|
448
446
|
};
|
|
@@ -679,6 +677,7 @@ import { ApiProperty as ApiProperty2 } from "@nestjs/swagger";
|
|
|
679
677
|
import { MergePropertyDecorators as MergePropertyDecorators2 } from "nesties";
|
|
680
678
|
import { Column, Index } from "typeorm";
|
|
681
679
|
import {
|
|
680
|
+
buildMessage,
|
|
682
681
|
IsDate,
|
|
683
682
|
IsEnum,
|
|
684
683
|
IsInt,
|
|
@@ -689,7 +688,9 @@ import {
|
|
|
689
688
|
Max,
|
|
690
689
|
MaxLength,
|
|
691
690
|
Min,
|
|
692
|
-
|
|
691
|
+
ValidateBy,
|
|
692
|
+
ValidateNested as ValidateNested2,
|
|
693
|
+
isBase64
|
|
693
694
|
} from "class-validator";
|
|
694
695
|
import { Exclude, Transform, Type as Type2 } from "class-transformer";
|
|
695
696
|
|
|
@@ -839,6 +840,40 @@ var GetMutatorJson = createGetMutator((s) => JSON.parse(s), {
|
|
|
839
840
|
example: `{"key1":"value1","key2":2,"key3":[1,2,3]}`
|
|
840
841
|
});
|
|
841
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
|
+
|
|
842
877
|
// src/decorators/property.ts
|
|
843
878
|
var NotRequiredButHasDefaultDec = () => Metadata.set(
|
|
844
879
|
"notRequiredButHasDefault",
|
|
@@ -972,7 +1007,8 @@ var FloatColumn = (type, options = {}) => {
|
|
|
972
1007
|
}
|
|
973
1008
|
}
|
|
974
1009
|
return MergePropertyDecorators2([
|
|
975
|
-
Column(
|
|
1010
|
+
Column({
|
|
1011
|
+
type,
|
|
976
1012
|
default: options.default,
|
|
977
1013
|
unsigned: options.unsigned,
|
|
978
1014
|
...columnDecoratorOptions(options)
|
|
@@ -1060,6 +1096,29 @@ var StringJsonColumn = createJsonColumnDef(
|
|
|
1060
1096
|
"text",
|
|
1061
1097
|
TypeTransformerString
|
|
1062
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
|
+
]);
|
|
1063
1122
|
var NotColumn = (options = {}, specials = {}) => MergePropertyDecorators2([
|
|
1064
1123
|
Exclude(),
|
|
1065
1124
|
swaggerDecorator({
|
|
@@ -1283,6 +1342,21 @@ var createQueryOperatorArrayify = (operator, singleFallback) => createQueryArray
|
|
|
1283
1342
|
);
|
|
1284
1343
|
var QueryIn = createQueryOperatorArrayify("IN", "=");
|
|
1285
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("!=");
|
|
1286
1360
|
var QueryFullText = (options = {}) => {
|
|
1287
1361
|
const configurationName = options.parser ? `nicot_parser_${options.parser}` : options.configuration || "english";
|
|
1288
1362
|
const tsQueryFunction = options.tsQueryFunction || "websearch_to_tsquery";
|
|
@@ -1994,6 +2068,7 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
1994
2068
|
|
|
1995
2069
|
// src/crud-base.ts
|
|
1996
2070
|
import PQueue from "p-queue";
|
|
2071
|
+
var existingEntitySelect = () => ({ id: true, deleteTime: true });
|
|
1997
2072
|
var Relation = (name, options = {}) => {
|
|
1998
2073
|
return { name, inner: false, ...options };
|
|
1999
2074
|
};
|
|
@@ -2199,7 +2274,7 @@ var CrudBase = class {
|
|
|
2199
2274
|
where: {
|
|
2200
2275
|
id: In(chunk)
|
|
2201
2276
|
},
|
|
2202
|
-
select: this.crudOptions.createOrUpdate ? void 0 :
|
|
2277
|
+
select: this.crudOptions.createOrUpdate ? void 0 : existingEntitySelect(),
|
|
2203
2278
|
withDeleted: true
|
|
2204
2279
|
})
|
|
2205
2280
|
)
|
|
@@ -2304,7 +2379,7 @@ var CrudBase = class {
|
|
|
2304
2379
|
if (ent.id != null) {
|
|
2305
2380
|
const existingEnt = await repo.findOne({
|
|
2306
2381
|
where: { id: ent.id },
|
|
2307
|
-
select: this.crudOptions.createOrUpdate ? void 0 :
|
|
2382
|
+
select: this.crudOptions.createOrUpdate ? void 0 : existingEntitySelect(),
|
|
2308
2383
|
withDeleted: true,
|
|
2309
2384
|
lock: {
|
|
2310
2385
|
mode: "pessimistic_write",
|
|
@@ -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
|