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/README-CN.md +40 -0
- package/README.md +41 -0
- package/dist/index.cjs +196 -54
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +146 -9
- 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/restful.d.ts +3 -3
- package/dist/src/utility/base64-binary.d.ts +23 -0
- package/dist/src/utility/get-api-property.d.ts +3 -0
- package/dist/src/utility/index.d.ts +1 -0
- package/dist/src/utility/patch-column-in-get.d.ts +1 -1
- package/dist/src/utility/swagger-decorators.d.ts +23 -0
- package/package.json +3 -2
package/README-CN.md
CHANGED
|
@@ -192,6 +192,7 @@ content: string;
|
|
|
192
192
|
| QueryGreater/Less | 数值比较 |
|
|
193
193
|
| QueryIn / QueryNotIn| IN / NOT IN |
|
|
194
194
|
| QueryMatchBoolean | 自动解析 true/false |
|
|
195
|
+
| QueryBase64Equal / QueryBase64NotEqual | base64 字符串解码为二进制后比较(配合 `@Base64BinaryColumn()`) |
|
|
195
196
|
| QueryOperator | 自定义操作符 |
|
|
196
197
|
| QueryWrap | 自定义表达式 |
|
|
197
198
|
| QueryAnd / QueryOr | 条件组合 |
|
|
@@ -199,6 +200,45 @@ content: string;
|
|
|
199
200
|
|
|
200
201
|
---
|
|
201
202
|
|
|
203
|
+
## Base64 二进制列:`@Base64BinaryColumn()`
|
|
204
|
+
|
|
205
|
+
`@Base64BinaryColumn()` 让你在**数据库里存原始二进制**,而在 实体 / DTO /
|
|
206
|
+
OpenAPI 层面统统“伪装成”一个普通的 base64 `string` 字段:
|
|
207
|
+
|
|
208
|
+
- 实体属性类型是 `string`(base64 字符串)。
|
|
209
|
+
- OpenAPI 中以 `{ type: String, format: 'byte' }` 展示。
|
|
210
|
+
- 通过 TypeORM `ValueTransformer`:写库时把 base64 字符串解码成 `Buffer`
|
|
211
|
+
(默认列类型 `bytea`),读取时再编码回 base64 字符串。
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
@Entity()
|
|
215
|
+
export class Attachment extends IdBase() {
|
|
216
|
+
@Base64BinaryColumn({ required: true })
|
|
217
|
+
data: string; // 接口里是 base64,PostgreSQL 里是 bytea
|
|
218
|
+
|
|
219
|
+
// MySQL 可指定 blob 系列类型:
|
|
220
|
+
@Base64BinaryColumn({ columnType: 'longblob' })
|
|
221
|
+
thumbnail: string;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**直接赋二进制也合法。** 虽然类型是 base64 `string`,但如果在你自己的代码里
|
|
226
|
+
(例如 `repo.save`)直接赋了 `Buffer` / `Uint8Array` / `ArrayBuffer`,会被认为
|
|
227
|
+
“这就是那段二进制”原样入库,校验同样通过;读出来时依然是 base64 字符串。
|
|
228
|
+
|
|
229
|
+
**查询。** base64 二进制列本身就是可查询字段(不需要 `GetMutator`)。想在
|
|
230
|
+
`findAll` 中按它过滤,给它挂上 `@QueryBase64Equal()`(或
|
|
231
|
+
`@QueryBase64NotEqual()`)即可:传入的 base64 查询串会在绑定参数前被解码成
|
|
232
|
+
`Buffer`,从而与列里存的二进制匹配。
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
@Base64BinaryColumn()
|
|
236
|
+
@QueryBase64Equal()
|
|
237
|
+
signature: string; // GET /attachment?signature=3q2+7w==
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
202
242
|
## GET Mutator(URL → 类型转换)
|
|
203
243
|
|
|
204
244
|
URL 参数永远是 string。
|
package/README.md
CHANGED
|
@@ -289,6 +289,7 @@ Common ones:
|
|
|
289
289
|
| `@SimpleJsonColumn` | `json` | same as above |
|
|
290
290
|
| `@StringJsonColumn` | `text` (stringified JSON) | same as above |
|
|
291
291
|
| `@EnumColumn(Enum)` | enum or text | enum validation |
|
|
292
|
+
| `@Base64BinaryColumn()` | `bytea` (binary)| base64 string / binary |
|
|
292
293
|
|
|
293
294
|
All of them accept an `options` parameter:
|
|
294
295
|
|
|
@@ -301,6 +302,46 @@ All of them accept an `options` parameter:
|
|
|
301
302
|
displayName: string;
|
|
302
303
|
```
|
|
303
304
|
|
|
305
|
+
### `@Base64BinaryColumn()` — base64 over the wire, binary in the database
|
|
306
|
+
|
|
307
|
+
`@Base64BinaryColumn()` lets you store **raw binary** in the database while the
|
|
308
|
+
entity / DTO / OpenAPI surface all behave like a plain **base64 `string`**:
|
|
309
|
+
|
|
310
|
+
- The TS property type is `string` (a base64 string).
|
|
311
|
+
- It is exposed to OpenAPI as `{ type: String, format: 'byte' }`.
|
|
312
|
+
- A TypeORM `ValueTransformer` decodes the base64 string into a `Buffer` on the
|
|
313
|
+
way into the DB (`bytea` by default) and encodes it back to base64 on read.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
@Entity()
|
|
317
|
+
export class Attachment extends IdBase() {
|
|
318
|
+
@Base64BinaryColumn({ required: true })
|
|
319
|
+
data: string; // base64 in the API, bytea in PostgreSQL
|
|
320
|
+
|
|
321
|
+
// MySQL? pick a blob type:
|
|
322
|
+
@Base64BinaryColumn({ columnType: 'longblob' })
|
|
323
|
+
thumbnail: string;
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Assigning raw binary directly.** Even though the type is a base64 `string`,
|
|
328
|
+
if you assign a `Buffer` / `Uint8Array` / `ArrayBuffer` (e.g. from `repo.save`
|
|
329
|
+
in your own code), it is treated as *the binary itself* and stored as-is —
|
|
330
|
+
validation accepts it too. It still comes back out as a base64 string over the
|
|
331
|
+
API.
|
|
332
|
+
|
|
333
|
+
**Querying.** A base64 binary column is a normal queryable field (no
|
|
334
|
+
`GetMutator` required). To filter on it in `findAll`, attach
|
|
335
|
+
`@QueryBase64Equal()` (or `@QueryBase64NotEqual()`); the incoming base64 query
|
|
336
|
+
string is decoded to a `Buffer` right before it is bound, so it matches the
|
|
337
|
+
binary stored in the column:
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
@Base64BinaryColumn()
|
|
341
|
+
@QueryBase64Equal()
|
|
342
|
+
signature: string; // GET /attachment?signature=3q2+7w==
|
|
343
|
+
```
|
|
344
|
+
|
|
304
345
|
---
|
|
305
346
|
|
|
306
347
|
## Access control decorators
|