@buka/nestjs-kit 4.3.2 → 4.3.4
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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +89 -149
- package/dist/index.d.ts +89 -149
- package/dist/index.js +127 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -214
- package/dist/index.mjs.map +1 -1
- package/docs/core/converters.md +4 -0
- package/docs/core/models.md +54 -0
- package/docs/core/urn.md +66 -64
- package/docs/mikro-orm.md +61 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -339,99 +339,71 @@ const URN_PREFIX = "urn:buka:";
|
|
|
339
339
|
/**
|
|
340
340
|
* 统一资源名称(URN)
|
|
341
341
|
*
|
|
342
|
-
* 格式: urn:buka:<domain>:<resource
|
|
342
|
+
* 格式: urn:buka:<domain>:<resource...>
|
|
343
343
|
*
|
|
344
|
-
* 支持三种粒度:
|
|
345
344
|
* - 概念域级: urn:buka:galaxy
|
|
346
|
-
* -
|
|
347
|
-
* - 实例级: urn:buka:galaxy:principal:550e8400-e29b-41d4-a716-446655440000
|
|
345
|
+
* - 资源级: urn:buka:galaxy:auth-client:galaxy:console
|
|
348
346
|
*
|
|
349
|
-
* domain
|
|
350
|
-
* resource
|
|
347
|
+
* domain 之后的全部段为 resource 路径(: 分隔),parser 不区分"类型"和"实例"。
|
|
348
|
+
* 应用层自行约定 resource 各段的语义。
|
|
351
349
|
*
|
|
352
|
-
* 推荐通过静态工厂方法或派生方法构建层级 URN:
|
|
353
350
|
* ```ts
|
|
354
|
-
* Urn.of('galaxy')
|
|
355
|
-
* Urn.of('galaxy', '
|
|
356
|
-
* Urn.of('galaxy', '
|
|
357
|
-
*
|
|
358
|
-
* //
|
|
359
|
-
* Urn.of('galaxy')
|
|
360
|
-
* .withResourceType('principal') // → ResourceTypeUrn
|
|
361
|
-
* .withResourceId('550e8400-...') // → ResourceIdUrn
|
|
351
|
+
* Urn.of('galaxy') // → 概念域级 URN
|
|
352
|
+
* Urn.of('galaxy', 'auth-client:galaxy:console') // → 资源级 URN
|
|
353
|
+
* Urn.of('galaxy', ['auth-client', 'galaxy', 'console'])
|
|
354
|
+
*
|
|
355
|
+
* // 或通过派生方法构建
|
|
356
|
+
* Urn.of('galaxy').withResource('auth-client', 'galaxy', 'console')
|
|
362
357
|
* ```
|
|
363
358
|
*/
|
|
364
359
|
var Urn = class Urn {
|
|
365
|
-
constructor(domain,
|
|
360
|
+
constructor(domain, resource) {
|
|
366
361
|
this.domain = domain;
|
|
367
|
-
this.
|
|
368
|
-
this.resourceId = resourceId;
|
|
362
|
+
this.resource = resource;
|
|
369
363
|
if (!/^(?:\*|[a-z][a-z0-9-]*)$/.test(domain)) throw new Error(`Invalid domain: ${domain}`);
|
|
370
|
-
if (
|
|
371
|
-
for (const seg of
|
|
364
|
+
if (resource !== void 0) {
|
|
365
|
+
for (const seg of resource.split(":")) if (!/^(?:\*{1,2}|[a-z0-9][a-z0-9-]*)$/.test(seg)) throw new Error(`Invalid resource segment: '${seg}' in '${resource}'`);
|
|
372
366
|
}
|
|
373
|
-
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* resource 按 `:` 拆分后的段数组
|
|
370
|
+
*/
|
|
371
|
+
get resourceSegments() {
|
|
372
|
+
return this.resource ? this.resource.split(":") : [];
|
|
374
373
|
}
|
|
375
374
|
/**
|
|
376
375
|
* 序列化为 URN 字符串
|
|
377
376
|
*/
|
|
378
377
|
toString() {
|
|
379
378
|
let urn = `${URN_PREFIX}${this.domain}`;
|
|
380
|
-
if (this.
|
|
381
|
-
if (this.resourceId) urn += `:${this.resourceId}`;
|
|
379
|
+
if (this.resource) urn += `:${this.resource}`;
|
|
382
380
|
return urn;
|
|
383
381
|
}
|
|
384
|
-
/**
|
|
385
|
-
* 返回 resourceType 按 `:` 拆分后的层级数组
|
|
386
|
-
*/
|
|
387
|
-
get resourceTypeSegments() {
|
|
388
|
-
return this.resourceType ? this.resourceType.split(":") : [];
|
|
389
|
-
}
|
|
390
382
|
toSegments() {
|
|
391
383
|
const segments = [this.domain];
|
|
392
|
-
if (this.
|
|
393
|
-
if (this.resourceId) segments.push(this.resourceId);
|
|
384
|
+
if (this.resource) segments.push(...this.resource.split(":"));
|
|
394
385
|
return segments;
|
|
395
386
|
}
|
|
396
387
|
/**
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* @throws Error 当前 URN 已有 resourceType 时抛出
|
|
400
|
-
*/
|
|
401
|
-
withResourceType(resourceType) {
|
|
402
|
-
if (this.resourceType !== void 0) throw new Error(`Cannot derive ResourceTypeUrn from a URN that already has a resourceType: ${this.toString()}`);
|
|
403
|
-
return new Urn(this.domain, resourceType);
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* 衍生出实例级 URN
|
|
388
|
+
* 从概念域级 URN 衍生出资源级 URN
|
|
407
389
|
*
|
|
408
|
-
* @throws Error 当前 URN
|
|
390
|
+
* @throws Error 当前 URN 已有 resource 时抛出
|
|
409
391
|
*/
|
|
410
|
-
|
|
411
|
-
if (this.
|
|
412
|
-
|
|
413
|
-
return new Urn(this.domain, this.resourceType, resourceId);
|
|
392
|
+
withResource(...segments) {
|
|
393
|
+
if (this.resource !== void 0) throw new Error(`Cannot derive resource URN from a URN that already has a resource: ${this.toString()}`);
|
|
394
|
+
return new Urn(this.domain, segments.join(":"));
|
|
414
395
|
}
|
|
415
396
|
/**
|
|
416
|
-
* 类型守卫:判断是否为概念域级 URN
|
|
397
|
+
* 类型守卫:判断是否为概念域级 URN(无 resource)
|
|
417
398
|
*/
|
|
418
399
|
isDomainUrn() {
|
|
419
|
-
return this.
|
|
400
|
+
return this.resource === void 0;
|
|
420
401
|
}
|
|
421
402
|
/**
|
|
422
|
-
*
|
|
403
|
+
* 根据参数创建对应层级的 URN
|
|
423
404
|
*/
|
|
424
|
-
|
|
425
|
-
return
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* 类型守卫:判断是否为实例级 URN
|
|
429
|
-
*/
|
|
430
|
-
isResourceIdUrn() {
|
|
431
|
-
return this.resourceType !== void 0 && this.resourceId !== void 0;
|
|
432
|
-
}
|
|
433
|
-
static of(domain, resourceType, resourceId) {
|
|
434
|
-
return new Urn(domain, resourceType, resourceId);
|
|
405
|
+
static of(domain, resource) {
|
|
406
|
+
return new Urn(domain, resource === void 0 ? void 0 : Array.isArray(resource) ? resource.join(":") : resource);
|
|
435
407
|
}
|
|
436
408
|
/**
|
|
437
409
|
* 从 URN 字符串解析,支持通配符 `*` 和 `**`
|
|
@@ -458,31 +430,30 @@ var Urn = class Urn {
|
|
|
458
430
|
}
|
|
459
431
|
if (segments.length === 0) throw new Error(`Invalid URN: ${urn}`);
|
|
460
432
|
const domain = segments[0];
|
|
461
|
-
|
|
462
|
-
let resourceId;
|
|
463
|
-
if (segments[segments.length - 1] === "**") {
|
|
464
|
-
if (segments.length === 1) {} else if (segments.length === 2) resourceType = segments[1] !== "**" ? segments[1] : void 0;
|
|
465
|
-
else resourceType = segments.slice(1, -1).join(":");
|
|
466
|
-
resourceId = "**";
|
|
467
|
-
} else if (segments.length === 2) resourceType = segments[1];
|
|
468
|
-
else if (segments.length >= 3) {
|
|
469
|
-
resourceType = segments.slice(1, -1).join(":");
|
|
470
|
-
resourceId = segments[segments.length - 1];
|
|
471
|
-
}
|
|
472
|
-
return new Urn(domain, resourceType, resourceId);
|
|
433
|
+
return new Urn(domain, segments.length > 1 ? segments.slice(1).join(":") : void 0);
|
|
473
434
|
}
|
|
474
435
|
/**
|
|
475
|
-
* 判断是否匹配指定的 domain
|
|
436
|
+
* 判断是否匹配指定的 domain 和 resource
|
|
476
437
|
*
|
|
477
|
-
*
|
|
438
|
+
* 未传入的参数不参与比较。
|
|
478
439
|
*/
|
|
479
|
-
is(domain,
|
|
440
|
+
is(domain, resource) {
|
|
480
441
|
if (this.domain !== domain) return false;
|
|
481
|
-
if (
|
|
482
|
-
if (resourceId !== void 0 && this.resourceId !== resourceId) return false;
|
|
442
|
+
if (resource !== void 0 && this.resource !== resource) return false;
|
|
483
443
|
return true;
|
|
484
444
|
}
|
|
485
445
|
/**
|
|
446
|
+
* 判断当前 URN 是否匹配指定的 URN 模式(支持通配符)
|
|
447
|
+
*
|
|
448
|
+
* ```ts
|
|
449
|
+
* urn.match('urn:buka:galaxy:principal:*') // resource 以 principal: 开头
|
|
450
|
+
* urn.match('urn:buka:galaxy:auth-client:**') // 任意深度的 auth-client
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
match(pattern) {
|
|
454
|
+
return Urn.parse(pattern).contains(this);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
486
457
|
* 判断当前 URN 是否包含另一个 URN
|
|
487
458
|
*
|
|
488
459
|
* 当前 URN 含通配符(`*` 或 `**`)时,作为集合模式判断:
|
|
@@ -509,8 +480,6 @@ var Urn = class Urn {
|
|
|
509
480
|
//#region src/modules/core/decorators/class-validator/is-urn.ts
|
|
510
481
|
const IS_URN = "isUrn";
|
|
511
482
|
const IS_DOMAIN_URN = "isDomainUrn";
|
|
512
|
-
const IS_RESOURCE_TYPE_URN = "isResourceTypeUrn";
|
|
513
|
-
const IS_RESOURCE_ID_URN = "isResourceIdUrn";
|
|
514
483
|
/**
|
|
515
484
|
* 验证字符串是否为合法的 URN(任意层级)。
|
|
516
485
|
*
|
|
@@ -581,74 +550,6 @@ function IsDomainUrn(validationOptions) {
|
|
|
581
550
|
};
|
|
582
551
|
}
|
|
583
552
|
/**
|
|
584
|
-
* 验证字符串是否为资源类型级 URN(含 domain 和 resourceType,无 resourceId)。
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* ```typescript
|
|
588
|
-
* class ResourceDTO {
|
|
589
|
-
* @IsResourceTypeUrn()
|
|
590
|
-
* resourceType: string
|
|
591
|
-
* }
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
function IsResourceTypeUrn(validationOptions) {
|
|
595
|
-
return function(object, propertyName) {
|
|
596
|
-
registerDecorator({
|
|
597
|
-
name: IS_RESOURCE_TYPE_URN,
|
|
598
|
-
target: object.constructor,
|
|
599
|
-
propertyName,
|
|
600
|
-
options: validationOptions,
|
|
601
|
-
validator: {
|
|
602
|
-
validate(value) {
|
|
603
|
-
if (typeof value !== "string") return false;
|
|
604
|
-
try {
|
|
605
|
-
return Urn.parse(value).isResourceTypeUrn();
|
|
606
|
-
} catch {
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
defaultMessage() {
|
|
611
|
-
return "$property must be a resource-type-level URN (urn:buka:<domain>:<resource-type>)";
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* 验证字符串是否为实例级 URN(含完整三段:domain、resourceType 和 resourceId)。
|
|
619
|
-
*
|
|
620
|
-
* @example
|
|
621
|
-
* ```typescript
|
|
622
|
-
* class TokenPayloadDTO {
|
|
623
|
-
* @IsResourceIdUrn()
|
|
624
|
-
* sub: string
|
|
625
|
-
* }
|
|
626
|
-
* ```
|
|
627
|
-
*/
|
|
628
|
-
function IsResourceIdUrn(validationOptions) {
|
|
629
|
-
return function(object, propertyName) {
|
|
630
|
-
registerDecorator({
|
|
631
|
-
name: IS_RESOURCE_ID_URN,
|
|
632
|
-
target: object.constructor,
|
|
633
|
-
propertyName,
|
|
634
|
-
options: validationOptions,
|
|
635
|
-
validator: {
|
|
636
|
-
validate(value) {
|
|
637
|
-
if (typeof value !== "string") return false;
|
|
638
|
-
try {
|
|
639
|
-
return Urn.parse(value).isResourceIdUrn();
|
|
640
|
-
} catch {
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
},
|
|
644
|
-
defaultMessage() {
|
|
645
|
-
return "$property must be a resource-id-level URN (urn:buka:<domain>:<resource-type>:<resource-id>)";
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
553
|
* 验证字符串是否匹配指定的 URN 模式(支持通配符 `*` 和 `**`)。
|
|
653
554
|
*
|
|
654
555
|
* - `*` 匹配恰好一个段
|
|
@@ -966,7 +867,7 @@ function Composite(options) {
|
|
|
966
867
|
if (optional) IsOptional()(target, propertyKey);
|
|
967
868
|
else IsNotEmpty({ message: "$property is required" })(target, propertyKey);
|
|
968
869
|
Type$1(options.type)(target, propertyKey);
|
|
969
|
-
if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
870
|
+
if (!options.lazy) if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
970
871
|
else ApiProperty(schema)(target, propertyKey);
|
|
971
872
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
972
873
|
kind: "composite",
|
|
@@ -991,7 +892,7 @@ function applyUntypedList(target, propertyKey, options) {
|
|
|
991
892
|
each: true,
|
|
992
893
|
message: "$property is required"
|
|
993
894
|
})(target, propertyKey);
|
|
994
|
-
if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
895
|
+
if (!options.lazy) if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
995
896
|
else ApiProperty(schema)(target, propertyKey);
|
|
996
897
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
997
898
|
kind: "list",
|
|
@@ -1015,7 +916,7 @@ function applyScalarList(target, propertyKey, options) {
|
|
|
1015
916
|
each: true,
|
|
1016
917
|
message: "$property is required"
|
|
1017
918
|
})(target, propertyKey);
|
|
1018
|
-
if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
919
|
+
if (!options.lazy) if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
1019
920
|
else ApiProperty(schema)(target, propertyKey);
|
|
1020
921
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1021
922
|
kind: "list",
|
|
@@ -1040,7 +941,7 @@ function applyCompositeList(target, propertyKey, options) {
|
|
|
1040
941
|
each: true,
|
|
1041
942
|
message: "$property is required"
|
|
1042
943
|
})(target, propertyKey);
|
|
1043
|
-
if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
944
|
+
if (!options.lazy) if (optional) ApiPropertyOptional(schema)(target, propertyKey);
|
|
1044
945
|
else ApiProperty(schema)(target, propertyKey);
|
|
1045
946
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1046
947
|
kind: "list",
|
|
@@ -2756,6 +2657,48 @@ __decorate([
|
|
|
2756
2657
|
__decorateMetadata("design:type", String)
|
|
2757
2658
|
], DiscreteEntity.prototype, "id", void 0);
|
|
2758
2659
|
//#endregion
|
|
2660
|
+
//#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.ts
|
|
2661
|
+
/**
|
|
2662
|
+
* 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
|
|
2663
|
+
*
|
|
2664
|
+
* 返回的类:
|
|
2665
|
+
* - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
|
|
2666
|
+
* - 仅包含非 `lazy: true` 的 Model 属性
|
|
2667
|
+
* - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
|
|
2668
|
+
* - 保留所有 Swagger、class-validator、class-transformer 元数据
|
|
2669
|
+
* - Swagger schema 与 `findOne()` 不加 populate 的结果一致
|
|
2670
|
+
*
|
|
2671
|
+
* @param classRef - 使用 `@Model()` 标注的实体类引用
|
|
2672
|
+
* @returns 可用于 `extends` 派生的纯 DTO 类
|
|
2673
|
+
*
|
|
2674
|
+
* @example
|
|
2675
|
+
* ```typescript
|
|
2676
|
+
* // 基本用法:派生不含 Collection 的 DTO
|
|
2677
|
+
* class UserProfileBriefDto extends EntityDto(UserProfile) {}
|
|
2678
|
+
*
|
|
2679
|
+
* // 扩展用法:手动添加 lazy 属性
|
|
2680
|
+
* class UserProfileDetailDto extends EntityDto(UserProfile) {
|
|
2681
|
+
* @List({ type: () => PrimaryKeyType(Avatar) })
|
|
2682
|
+
* avatars!: PrimaryKeyTypeClass[]
|
|
2683
|
+
* }
|
|
2684
|
+
* ```
|
|
2685
|
+
*/
|
|
2686
|
+
function EntityDto(classRef) {
|
|
2687
|
+
if (!ModelRegister.isModel(classRef)) throw new TypeError("EntityDto only accepts a class annotated with @Model().");
|
|
2688
|
+
class EntityDtoClass {}
|
|
2689
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
2690
|
+
if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) continue;
|
|
2691
|
+
ModelRegister.copyProperty(classRef, EntityDtoClass, propertyKey);
|
|
2692
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
|
|
2693
|
+
for (const metadataKey of metadataKeys) {
|
|
2694
|
+
const value = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
|
|
2695
|
+
if (Reflect.hasMetadata(metadataKey, EntityDtoClass.prototype, propertyKey)) continue;
|
|
2696
|
+
Reflect.defineMetadata(metadataKey, value, EntityDtoClass.prototype, propertyKey);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
return EntityDtoClass;
|
|
2700
|
+
}
|
|
2701
|
+
//#endregion
|
|
2759
2702
|
//#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
|
|
2760
2703
|
function getMetadata(classRef) {
|
|
2761
2704
|
const metadatas = [];
|
|
@@ -2916,6 +2859,7 @@ function OneToMany$1(options) {
|
|
|
2916
2859
|
List({
|
|
2917
2860
|
type,
|
|
2918
2861
|
optional: options.nullable,
|
|
2862
|
+
lazy: options.eager !== true,
|
|
2919
2863
|
association: {
|
|
2920
2864
|
kind: "1:m",
|
|
2921
2865
|
type
|
|
@@ -2956,6 +2900,7 @@ function ManyToMany$1(entity, mappedBy, options) {
|
|
|
2956
2900
|
List({
|
|
2957
2901
|
type,
|
|
2958
2902
|
optional: resolvedOptions?.nullable,
|
|
2903
|
+
lazy: resolvedOptions?.eager !== true,
|
|
2959
2904
|
association: {
|
|
2960
2905
|
kind: "m:n",
|
|
2961
2906
|
type
|
|
@@ -3265,6 +3210,36 @@ var Slice = class Slice {
|
|
|
3265
3210
|
}
|
|
3266
3211
|
};
|
|
3267
3212
|
//#endregion
|
|
3213
|
+
//#region src/modules/core/converters/pick-type/pick-type.ts
|
|
3214
|
+
/**
|
|
3215
|
+
* 从模型中选取指定属性,生成新的子集类型。
|
|
3216
|
+
*
|
|
3217
|
+
* 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
3218
|
+
*
|
|
3219
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3220
|
+
* @param keys - 需要选取的属性名数组
|
|
3221
|
+
* @returns 仅包含指定属性的新类
|
|
3222
|
+
*
|
|
3223
|
+
* @example
|
|
3224
|
+
* ```typescript
|
|
3225
|
+
* const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
|
|
3226
|
+
* ```
|
|
3227
|
+
*/
|
|
3228
|
+
function PickType(classRef, keys) {
|
|
3229
|
+
if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
|
|
3230
|
+
const PickTypeClass = PickType$1(classRef, keys);
|
|
3231
|
+
for (const key of keys) {
|
|
3232
|
+
ModelRegister.copyProperty(classRef, PickTypeClass, key);
|
|
3233
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
|
|
3234
|
+
for (const metadataKey of metadataKeys) {
|
|
3235
|
+
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
|
|
3236
|
+
if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
|
|
3237
|
+
Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
return PickTypeClass;
|
|
3241
|
+
}
|
|
3242
|
+
//#endregion
|
|
3268
3243
|
//#region src/modules/core/converters/omit-type/omit-type.ts
|
|
3269
3244
|
/**
|
|
3270
3245
|
* 从模型中排除指定属性,生成新的类型。
|
|
@@ -3296,68 +3271,6 @@ function OmitType(classRef, keys) {
|
|
|
3296
3271
|
return OmitTypeClass;
|
|
3297
3272
|
}
|
|
3298
3273
|
//#endregion
|
|
3299
|
-
//#region src/modules/core/converters/eager-type/eager-type.ts
|
|
3300
|
-
/**
|
|
3301
|
-
* 从模型中排除所有标记为 `lazy: true` 的属性,生成仅包含非懒加载字段的新类型。
|
|
3302
|
-
*
|
|
3303
|
-
* 适用于 API 响应场景,避免返回未加载的字段。
|
|
3304
|
-
*
|
|
3305
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3306
|
-
* @returns 排除了 lazy 属性的新类
|
|
3307
|
-
*
|
|
3308
|
-
* @example
|
|
3309
|
-
* ```typescript
|
|
3310
|
-
* @Model()
|
|
3311
|
-
* class User {
|
|
3312
|
-
* @Property()
|
|
3313
|
-
* name: string
|
|
3314
|
-
*
|
|
3315
|
-
* @Property({ lazy: true })
|
|
3316
|
-
* bio: string
|
|
3317
|
-
* }
|
|
3318
|
-
*
|
|
3319
|
-
* const UserResponse = EagerType(User)
|
|
3320
|
-
* // UserResponse 仅包含 name,不包含 bio
|
|
3321
|
-
* ```
|
|
3322
|
-
*/
|
|
3323
|
-
function EagerType(classRef) {
|
|
3324
|
-
if (!ModelRegister.isModel(classRef)) throw new TypeError("EagerType only accepts a class annotated with @Model().");
|
|
3325
|
-
const lazyKeys = [];
|
|
3326
|
-
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) lazyKeys.push(propertyKey);
|
|
3327
|
-
if (lazyKeys.length === 0) return classRef;
|
|
3328
|
-
return OmitType(classRef, lazyKeys);
|
|
3329
|
-
}
|
|
3330
|
-
//#endregion
|
|
3331
|
-
//#region src/modules/core/converters/pick-type/pick-type.ts
|
|
3332
|
-
/**
|
|
3333
|
-
* 从模型中选取指定属性,生成新的子集类型。
|
|
3334
|
-
*
|
|
3335
|
-
* 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
3336
|
-
*
|
|
3337
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3338
|
-
* @param keys - 需要选取的属性名数组
|
|
3339
|
-
* @returns 仅包含指定属性的新类
|
|
3340
|
-
*
|
|
3341
|
-
* @example
|
|
3342
|
-
* ```typescript
|
|
3343
|
-
* const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
|
|
3344
|
-
* ```
|
|
3345
|
-
*/
|
|
3346
|
-
function PickType(classRef, keys) {
|
|
3347
|
-
if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
|
|
3348
|
-
const PickTypeClass = PickType$1(classRef, keys);
|
|
3349
|
-
for (const key of keys) {
|
|
3350
|
-
ModelRegister.copyProperty(classRef, PickTypeClass, key);
|
|
3351
|
-
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
|
|
3352
|
-
for (const metadataKey of metadataKeys) {
|
|
3353
|
-
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
|
|
3354
|
-
if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
|
|
3355
|
-
Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
|
|
3356
|
-
}
|
|
3357
|
-
}
|
|
3358
|
-
return PickTypeClass;
|
|
3359
|
-
}
|
|
3360
|
-
//#endregion
|
|
3361
3274
|
//#region src/modules/core/converters/partial-type/partial-type.ts
|
|
3362
3275
|
/**
|
|
3363
3276
|
* 将模型的所有属性变为可选,生成新的 Partial 类型。
|
|
@@ -10054,6 +9967,6 @@ ObjectStorageModule = __decorate([Global(), Module({
|
|
|
10054
9967
|
exports: [ObjectStorageService]
|
|
10055
9968
|
})], ObjectStorageModule);
|
|
10056
9969
|
//#endregion
|
|
10057
|
-
export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity,
|
|
9970
|
+
export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity, EncryptedPayload, EntityDto, EntityRef, Enum, EnvelopeEncryptionModule, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, ExceptionDetailSchema, ExceptionModule, FeatureException, FilterQuery, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelRegister, ModuleExceptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuthConfig, OpenBaoHttpClient, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoTokenAuthConfig, OpenBaoTokenManager, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, RateLimitException, ResponseBodyType, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
10058
9971
|
|
|
10059
9972
|
//# sourceMappingURL=index.mjs.map
|