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.
@@ -7,6 +7,7 @@ import { SimpleColumnType, UnsignedColumnType, WithLengthColumnType, WithPrecisi
7
7
  import { ColumnNumericOptions } from 'typeorm/decorator/options/ColumnNumericOptions';
8
8
  import { ClassOrArray, ParseType } from 'nesties';
9
9
  import { ColumnUnsignedOptions } from 'typeorm/decorator/options/ColumnUnsignedOptions';
10
+ import { Base64BinaryStorage } from '../utility/base64-binary';
10
11
  export interface OpenAPIOptions<T> {
11
12
  description?: string;
12
13
  propertyExtras?: ApiPropertyOptions;
@@ -61,6 +62,7 @@ export declare const StringJsonColumn: <C extends ClassOrArray>(definition: C, o
61
62
  export declare const IsBase64OrBinary: (validationOptions?: ValidationOptions) => PropertyDecorator;
62
63
  export declare const Base64BinaryColumn: (options?: PropertyOptions<string> & {
63
64
  columnType?: SimpleColumnType | WithLengthColumnType;
65
+ binaryStorage?: Base64BinaryStorage;
64
66
  }) => PropertyDecorator;
65
67
  export declare const NotColumn: (options?: OpenAPIOptions<any>, specials?: {
66
68
  keepInCreate?: boolean;
@@ -1,5 +1,6 @@
1
1
  import { QueryCond } from '../bases';
2
2
  import { QueryFullTextColumnOptions } from '../utility/query-full-text-column-options.interface';
3
+ import { Base64BinaryStorage } from '../utility/base64-binary';
3
4
  export declare const QueryCondition: (cond: QueryCond) => PropertyDecorator;
4
5
  export declare const QueryManual: () => PropertyDecorator;
5
6
  export declare class QueryWrapInfo<T = unknown> {
@@ -32,16 +33,20 @@ export declare const createQueryArrayify: (newWrapper: QueryWrapper, singleFallb
32
33
  export declare const createQueryOperatorArrayify: (operator: string, singleFallback?: string | QueryWrapper) => (field?: string) => PropertyDecorator;
33
34
  export declare const QueryIn: (field?: string) => PropertyDecorator;
34
35
  export declare const QueryNotIn: (field?: string) => PropertyDecorator;
36
+ export interface QueryBase64Options {
37
+ field?: string;
38
+ binaryStorage?: Base64BinaryStorage;
39
+ }
35
40
  /**
36
41
  * Builds a query condition for a `Base64BinaryColumn`. The incoming base64
37
- * string (the API-facing form) is decoded into a `Buffer` right before it is
38
- * bound as a query parameter, so it can be compared against the raw binary
39
- * stored in the database. A value that is already binary
40
- * (Buffer / Uint8Array / ArrayBuffer) is used as-is.
42
+ * string (the API-facing form) is decoded into a PostgreSQL-safe bytea hex
43
+ * parameter right before it is bound, so it can be compared against the raw
44
+ * binary stored in the database. A value that is already binary (Buffer /
45
+ * Uint8Array / ArrayBuffer) is used as that binary payload.
41
46
  */
42
- export declare const createQueryBase64Operator: (operator: string) => (field?: string) => PropertyDecorator;
43
- export declare const QueryBase64Equal: (field?: string) => PropertyDecorator;
44
- export declare const QueryBase64NotEqual: (field?: string) => PropertyDecorator;
47
+ export declare const createQueryBase64Operator: (operator: string) => (fieldOrOptions?: string | QueryBase64Options) => PropertyDecorator;
48
+ export declare const QueryBase64Equal: (fieldOrOptions?: string | QueryBase64Options) => PropertyDecorator;
49
+ export declare const QueryBase64NotEqual: (fieldOrOptions?: string | QueryBase64Options) => PropertyDecorator;
45
50
  export declare const QueryFullText: (options?: QueryFullTextColumnOptions) => PropertyDecorator;
46
51
  export declare const QueryAnd: (...decs: PropertyDecorator[]) => PropertyDecorator;
47
52
  export declare const QueryOr: (...decs: PropertyDecorator[]) => PropertyDecorator;
@@ -1,5 +1,6 @@
1
1
  import { ValueTransformer } from 'typeorm';
2
2
  export type BinaryLike = Buffer | Uint8Array | ArrayBuffer;
3
+ export type Base64BinaryStorage = 'postgres-bytea' | 'binary';
3
4
  /**
4
5
  * Whether the value is a raw binary payload (Buffer / Uint8Array / ArrayBuffer).
5
6
  * Such values are considered "already the binary" and are accepted as-is even
@@ -7,17 +8,22 @@ export type BinaryLike = Buffer | Uint8Array | ArrayBuffer;
7
8
  */
8
9
  export declare function isBinaryLike(value: unknown): value is BinaryLike;
9
10
  export declare function binaryToBuffer(value: BinaryLike): Buffer;
11
+ export declare function binaryToPostgresByteaHex(value: BinaryLike): string;
12
+ export declare function base64OrBinaryToBuffer(value: string | BinaryLike): Buffer;
13
+ export declare function base64OrBinaryToDatabaseValue(value: string | BinaryLike, storage?: Base64BinaryStorage): Buffer | string;
10
14
  /**
11
15
  * Bridges a base64 `string` on the entity/API side with raw binary storage in
12
16
  * the database.
13
17
  *
14
- * - `to` (entity -> DB): a base64 string is decoded into a `Buffer`. If the
15
- * incoming value is already binary (Buffer / Uint8Array / ArrayBuffer) it is
16
- * treated as the binary payload itself and stored directly.
18
+ * - `to` (entity -> DB): a base64 string is decoded into a database-safe bytea
19
+ * value. If the incoming value is already binary (Buffer / Uint8Array /
20
+ * ArrayBuffer) it is treated as the binary payload itself and stored directly.
17
21
  * - `from` (DB -> entity): the stored binary is encoded back into a base64
18
22
  * string.
19
23
  */
20
24
  export declare class Base64BinaryTransformer implements ValueTransformer {
21
- to(entValue: string | BinaryLike | null | undefined): Buffer | null | undefined;
22
- from(dbValue: BinaryLike | null | undefined): string | null | undefined;
25
+ private readonly storage;
26
+ constructor(storage?: Base64BinaryStorage);
27
+ to(entValue: string | BinaryLike | null | undefined): Buffer | string | null | undefined;
28
+ from(dbValue: BinaryLike | string | null | undefined): string | null | undefined;
23
29
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nicot",
3
3
  "description": "Nest.js interacting with class-validator + OpenAPI + TypeORM for Nest.js Restful API development.",
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",