nicot 1.4.0 → 1.4.2

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.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
- ValidateNested as ValidateNested2
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";
@@ -2936,11 +3011,11 @@ import {
2936
3011
  MergeMethodDecorators,
2937
3012
  PaginatedReturnMessageDto as PaginatedReturnMessageDto2,
2938
3013
  ReturnMessageDto as ReturnMessageDto2,
2939
- getApiProperty as getApiProperty2,
2940
3014
  DataPipe,
2941
3015
  ApiTypeResponse,
2942
3016
  ApiBlankResponse,
2943
- ApiError
3017
+ ApiError,
3018
+ RenameClass
2944
3019
  } from "nesties";
2945
3020
  import {
2946
3021
  ApiBody,
@@ -2954,7 +3029,6 @@ import {
2954
3029
  PickType as PickType2
2955
3030
  } from "@nestjs/swagger";
2956
3031
  import _6, { upperFirst } from "lodash";
2957
- import { RenameClass } from "nesties";
2958
3032
 
2959
3033
  // src/bases/base-restful-controller.ts
2960
3034
  var RestfulMethods = [
@@ -3020,9 +3094,64 @@ var OmitTypeExclude = (cl, keys) => {
3020
3094
  };
3021
3095
 
3022
3096
  // src/utility/patch-column-in-get.ts
3023
- import { getApiProperty } from "nesties";
3024
3097
  import _5 from "lodash";
3025
- import { DECORATORS } from "@nestjs/swagger/dist/constants";
3098
+
3099
+ // src/utility/swagger-decorators.ts
3100
+ var DECORATORS_PREFIX = "swagger";
3101
+ var FALLBACK_DECORATORS = {
3102
+ API_OPERATION: `${DECORATORS_PREFIX}/apiOperation`,
3103
+ API_RESPONSE: `${DECORATORS_PREFIX}/apiResponse`,
3104
+ API_PRODUCES: `${DECORATORS_PREFIX}/apiProduces`,
3105
+ API_CONSUMES: `${DECORATORS_PREFIX}/apiConsumes`,
3106
+ API_TAGS: `${DECORATORS_PREFIX}/apiUseTags`,
3107
+ API_WEBHOOK: `${DECORATORS_PREFIX}/apiWebhook`,
3108
+ API_CALLBACKS: `${DECORATORS_PREFIX}/apiCallbacks`,
3109
+ API_PARAMETERS: `${DECORATORS_PREFIX}/apiParameters`,
3110
+ API_HEADERS: `${DECORATORS_PREFIX}/apiHeaders`,
3111
+ API_MODEL_PROPERTIES: `${DECORATORS_PREFIX}/apiModelProperties`,
3112
+ API_MODEL_PROPERTIES_ARRAY: `${DECORATORS_PREFIX}/apiModelPropertiesArray`,
3113
+ API_SECURITY: `${DECORATORS_PREFIX}/apiSecurity`,
3114
+ API_EXCLUDE_ENDPOINT: `${DECORATORS_PREFIX}/apiExcludeEndpoint`,
3115
+ API_INCLUDE_ENDPOINT: `${DECORATORS_PREFIX}/apiIncludeEndpoint`,
3116
+ API_EXCLUDE_CONTROLLER: `${DECORATORS_PREFIX}/apiExcludeController`,
3117
+ API_EXTRA_MODELS: `${DECORATORS_PREFIX}/apiExtraModels`,
3118
+ API_EXTENSION: `${DECORATORS_PREFIX}/apiExtension`,
3119
+ API_SCHEMA: `${DECORATORS_PREFIX}/apiSchema`,
3120
+ API_DEFAULT_GETTER: `${DECORATORS_PREFIX}/apiDefaultGetter`,
3121
+ API_LINK: `${DECORATORS_PREFIX}/apiLink`
3122
+ };
3123
+ function loadSwaggerDecorators() {
3124
+ try {
3125
+ const req = typeof __require === "function" ? __require : void 0;
3126
+ const decorators = req?.("@nestjs/swagger/dist/constants")?.DECORATORS;
3127
+ if (decorators) {
3128
+ return {
3129
+ ...FALLBACK_DECORATORS,
3130
+ ...decorators
3131
+ };
3132
+ }
3133
+ } catch {
3134
+ }
3135
+ return FALLBACK_DECORATORS;
3136
+ }
3137
+ var DECORATORS = loadSwaggerDecorators();
3138
+
3139
+ // src/utility/get-api-property.ts
3140
+ var getApiProperty = (cls, key) => {
3141
+ let proto = cls.prototype;
3142
+ while (proto && proto !== Object.prototype) {
3143
+ const meta = Reflect.getMetadata(
3144
+ DECORATORS.API_MODEL_PROPERTIES,
3145
+ proto,
3146
+ key
3147
+ );
3148
+ if (meta) return meta;
3149
+ proto = Object.getPrototypeOf(proto);
3150
+ }
3151
+ return {};
3152
+ };
3153
+
3154
+ // src/utility/patch-column-in-get.ts
3026
3155
  var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
3027
3156
  const omit2 = new Set(fieldsToOmit);
3028
3157
  const useCl = originalCl || cl;
@@ -3370,7 +3499,7 @@ var _RestfulFactory = class _RestfulFactory {
3370
3499
  if (outputFieldsToOmit.has(relation.propertyName)) continue;
3371
3500
  if (nonTransformableTypes.has(relation.propertyClass)) continue;
3372
3501
  const replace = (useClass) => {
3373
- const oldApiProperty = getApiProperty2(
3502
+ const oldApiProperty = getApiProperty(
3374
3503
  this.entityClass,
3375
3504
  relation.propertyName
3376
3505
  );
@@ -3413,7 +3542,7 @@ var _RestfulFactory = class _RestfulFactory {
3413
3542
  "notRequiredButHasDefault"
3414
3543
  ).filter((f) => !outputFieldsToOmit.has(f));
3415
3544
  for (const field of notRequiredButHasDefaultFields) {
3416
- const oldApiProperty = getApiProperty2(resultDto, field);
3545
+ const oldApiProperty = getApiProperty(resultDto, field);
3417
3546
  ApiProperty5({
3418
3547
  ...oldApiProperty,
3419
3548
  required: true
@@ -4107,6 +4236,8 @@ TransactionalTypeOrmModule = __decorateClass([
4107
4236
  Module({})
4108
4237
  ], TransactionalTypeOrmModule);
4109
4238
  export {
4239
+ Base64BinaryColumn,
4240
+ Base64BinaryTransformer,
4110
4241
  BindingColumn,
4111
4242
  BindingValue,
4112
4243
  BlankCursorPaginationReturnMessageDto,
@@ -4139,6 +4270,7 @@ export {
4139
4270
  Inner,
4140
4271
  IntColumn,
4141
4272
  InternalColumn,
4273
+ IsBase64OrBinary,
4142
4274
  JsonColumn,
4143
4275
  NotChangeable,
4144
4276
  NotColumn,
@@ -4152,6 +4284,8 @@ export {
4152
4284
  PageSettingsDto,
4153
4285
  PickPipe,
4154
4286
  QueryAnd,
4287
+ QueryBase64Equal,
4288
+ QueryBase64NotEqual,
4155
4289
  QueryColumn,
4156
4290
  QueryCondition,
4157
4291
  QueryEqual,
@@ -4195,8 +4329,10 @@ export {
4195
4329
  applyQueryPropertyLike,
4196
4330
  applyQueryPropertySearch,
4197
4331
  applyQueryPropertyZeroNullable,
4332
+ binaryToBuffer,
4198
4333
  createGetMutator,
4199
4334
  createQueryArrayify,
4335
+ createQueryBase64Operator,
4200
4336
  createQueryCondition,
4201
4337
  createQueryOperator,
4202
4338
  createQueryOperatorArrayify,
@@ -4204,6 +4340,7 @@ export {
4204
4340
  getTransactionalEntityManagerProvider,
4205
4341
  getTransactionalEntityManagerToken,
4206
4342
  getTransactionalRepositoryProvider,
4207
- getTransactionalRepositoryToken
4343
+ getTransactionalRepositoryToken,
4344
+ isBinaryLike
4208
4345
  };
4209
4346
  //# sourceMappingURL=index.mjs.map