nicot 1.1.37 → 1.2.0

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.md CHANGED
@@ -135,14 +135,18 @@ NICOT 提供了一系列 `***Column()` 装饰器,统一处理字段的:
135
135
 
136
136
  ### 字段类型装饰器(`***Column()`)
137
137
 
138
- | 装饰器名 | 数据类型 | 自动添加的验证与文档 |
139
- |----------------------|----------------|---------------------------------|
140
- | `@StringColumn(len)` | string | `@IsString()` + `@Length()` |
141
- | `@IntColumn(type)` | int/bigint/... | `@IsInt()` + Swagger number 类型 |
142
- | `@FloatColumn(type)` | float/decimal | `@IsNumber()` |
143
- | `@BoolColumn()` | boolean | `@IsBoolean()` |
144
- | `@DateColumn()` | Date | `@IsDate()` |
145
- | `@JsonColumn(T)` | 任意对象/数组 | `@IsObject()` / `@ValidateNested()` 等 |
138
+ | 装饰器名 | 数据类型 | 自动添加的验证与文档 |
139
+ |------------------------|-----------------|---------------------------------------|
140
+ | `@StringColumn(len)` | varchar | `@IsString()` + `@Length()` |
141
+ | `@TextColumn()` | text | `@IsString()` |
142
+ | `@UuidColumn()` | uuid | `@IsUUID()` |
143
+ | `@IntColumn(type)` | int/bigint/... | `@IsInt()` + Swagger number 类型 |
144
+ | `@FloatColumn(type)` | float/decimal | `@IsNumber()` |
145
+ | `@BoolColumn()` | boolean | `@IsBoolean()` |
146
+ | `@DateColumn()` | Date | `@IsDate()` |
147
+ | `@JsonColumn(T)` | 任意对象/数组 (jsonb) | `@IsObject()` / `@ValidateNested()` 等 |
148
+ | `@SimpleJsonColumn(T)` | 任意对象/数组 (json) | `@IsObject()` / `@ValidateNested()` 等 |
149
+ | `@StringJsonColumn(T)` | 任意对象/数组 (text) | `@IsObject()` / `@ValidateNested()` 等 |
146
150
 
147
151
  所有字段装饰器都支持第二个参数 `options`:
148
152
 
@@ -204,18 +208,23 @@ NICOT 提供了一套查询装饰器,用于在 Entity 字段上声明支持的
204
208
 
205
209
  ### ✅ 内建查询装饰器
206
210
 
207
- | 装饰器名 | 查询效果 |
208
- |-------------------------------|------------------------------------------|
209
- | `@QueryEqual()` | 精确匹配:`WHERE field = :value` |
210
- | `@QueryLike()` | 前缀模糊匹配:`WHERE field LIKE :value%` |
211
- | `@QuerySearch()` | 宽泛模糊搜索:`WHERE field LIKE %:value%` |
212
- | `@QueryMatchBoolean()` | `true/false/1/0` 转换为布尔类型查询 |
213
- | `@QueryEqualZeroNullable()` | `0 → IS NULL`,否则 `= :value`(适合 nullable) |
214
- | `@QueryGreater(field)` | 大于查询:`WHERE field > :value` |
215
- | `@QueryLess(field)` | 小于查询:`WHERE field < :value` |
216
- | `@QueryGreaterOrEqual(field)` | 大于等于查询:`WHERE field >= :value` |
217
- | `@QueryLessOrEqual(field)` | 小于等于查询:`WHERE field <= :value` |
218
- | `@QueryFullText(options)` | 全文搜索查询,只支持 PostgreSQL,会自动建索引 |
211
+ | 装饰器名 | 查询效果 |
212
+ |------------------------------------------------------|-------------------------------------------------|
213
+ | `@QueryEqual()` | 精确匹配:`WHERE field = :value` |
214
+ | `@QueryLike()` | 前缀模糊匹配:`WHERE field LIKE :value%` |
215
+ | `@QuerySearch()` | 宽泛模糊搜索:`WHERE field LIKE %:value%` |
216
+ | `@QueryMatchBoolean()` | `true/false/1/0` 转换为布尔类型查询 |
217
+ | `@QueryEqualZeroNullable()` | `0 → IS NULL`,否则 `= :value`(适合 nullable) |
218
+ | `@QueryIn()` | 包含查询:`WHERE field IN (:...value)`,value 可以数组或者逗号分隔 |
219
+ | `@QueryNotIn()` | 不包含查询:`WHERE field NOT IN (:...value)` |
220
+ | `@QueryGreater(field)` | 大于查询:`WHERE field > :value` |
221
+ | `@QueryLess(field)` | 小于查询:`WHERE field < :value` |
222
+ | `@QueryGreaterOrEqual(field)` | 大于等于查询:`WHERE field >= :value` |
223
+ | `@QueryLessOrEqual(field)` | 小于等于查询:`WHERE field <= :value` |
224
+ | `@QueryJsonbHas()` | JSONB 包含键查询:`WHERE field ? :value` |
225
+ | `@QueryOperator('=')` | 自定义操作符查询:`WHERE field <operator> :value` |
226
+ | `@QueryWrap((entExpr, valExpr) => `${entExpr} = ${valExpr}`) | 自定义查询片段 |
227
+ | `@QueryFullText(options)` | 全文搜索查询,只支持 PostgreSQL,会自动建索引 |
219
228
 
220
229
  ---
221
230
 
@@ -300,6 +309,35 @@ viewsOrderBy?: 'ASC' | 'DESC';
300
309
 
301
310
  ---
302
311
 
312
+ ## GetMutator
313
+
314
+ GET 方法的参数只能是 URL 参数,因此数据类型只能是 string,具有局限性。
315
+
316
+ NICOT 提供了 `GetMutator` 装饰器,允许你在实体字段上定义一个转换函数,将 URL 参数转换为正确的数据类型,并把 OpenAPI 文档中 GET 接口的数据类型改为目标类型。
317
+
318
+ ### 示例
319
+
320
+ ```ts
321
+ @JsonColumn(SomeObject)
322
+ @GetMutator((val: string) => JSON.parse(val)) // GET 参数不会体现为 SomeObject,而是 string
323
+ @QueryOperator('@>') // JSONB 包含查询
324
+ meta: SomeObject;
325
+ ```
326
+
327
+ ### 内建 GetMutator
328
+
329
+ - `@GetMutatorBool()`
330
+ - `@GetMutatorInt()`
331
+ - `@GetMutatorFloat()`
332
+ - `@GetMutatorStringSeparated(',')`
333
+ - `@GetMutatorIntSeparated()`
334
+ - `@GetMutatorFloatSeparated()`
335
+ - `@GetMutatorJson()`
336
+
337
+ > `@BoolColumn()` 已经内建了 `@GetMutatorBool()`
338
+
339
+ ---
340
+
303
341
  ## 🧩 实体关系示例
304
342
 
305
343
  ```ts