nicot 1.4.2 → 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/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
- if (isBinaryLike(entValue)) {
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
- return Buffer.from(String(dbValue)).toString("base64");
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 toBase64QueryBuffer = (value) => {
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
- if (isBinaryLike(value)) {
1350
- return binaryToBuffer(value);
1351
- }
1352
- return Buffer.from(String(value), "base64");
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 = {}) => {
@@ -4329,7 +4352,10 @@ export {
4329
4352
  applyQueryPropertyLike,
4330
4353
  applyQueryPropertySearch,
4331
4354
  applyQueryPropertyZeroNullable,
4355
+ base64OrBinaryToBuffer,
4356
+ base64OrBinaryToDatabaseValue,
4332
4357
  binaryToBuffer,
4358
+ binaryToPostgresByteaHex,
4333
4359
  createGetMutator,
4334
4360
  createQueryArrayify,
4335
4361
  createQueryBase64Operator,