@buka/nestjs-kit 4.3.3 → 4.3.5
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 +35 -117
- package/dist/index.d.ts +35 -117
- package/dist/index.js +67 -155
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -152
- package/dist/index.mjs.map +1 -1
- package/docs/core/urn.md +66 -64
- 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
|
* - `*` 匹配恰好一个段
|
|
@@ -2853,6 +2754,21 @@ function resolveEntityType(entityRef, eager) {
|
|
|
2853
2754
|
if (!cls) return Object;
|
|
2854
2755
|
return eager ? cls : PrimaryKeyType(cls);
|
|
2855
2756
|
}
|
|
2757
|
+
/**
|
|
2758
|
+
* 为 Swagger schema 解析实体类引用。始终返回完整实体类(非 PrimaryKeyType),
|
|
2759
|
+
* 保证 `$ref` 指向正确注册的 schema。
|
|
2760
|
+
*
|
|
2761
|
+
* 返回函数形式以支持延迟求值,避免装饰器执行时的循环引用问题。
|
|
2762
|
+
*/
|
|
2763
|
+
function resolveEntitySchemaType(entityRef) {
|
|
2764
|
+
return () => {
|
|
2765
|
+
if (!entityRef) return Object;
|
|
2766
|
+
const result = entityRef();
|
|
2767
|
+
const entityName = Array.isArray(result) ? result[0] : result;
|
|
2768
|
+
if (!entityName) return Object;
|
|
2769
|
+
return resolveEntityClass(entityName) || Object;
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2856
2772
|
//#endregion
|
|
2857
2773
|
//#region src/modules/mikro-orm/decorators/cardinality/many-to-one.cardinality.ts
|
|
2858
2774
|
/**
|
|
@@ -2965,8 +2881,8 @@ function OneToMany$1(options) {
|
|
|
2965
2881
|
},
|
|
2966
2882
|
schema: {
|
|
2967
2883
|
description: options.comment,
|
|
2968
|
-
type:
|
|
2969
|
-
|
|
2884
|
+
type: resolveEntitySchemaType(entityRef),
|
|
2885
|
+
isArray: true
|
|
2970
2886
|
}
|
|
2971
2887
|
})(target, propertyKey);
|
|
2972
2888
|
};
|
|
@@ -3006,8 +2922,8 @@ function ManyToMany$1(entity, mappedBy, options) {
|
|
|
3006
2922
|
},
|
|
3007
2923
|
schema: {
|
|
3008
2924
|
description: resolvedOptions?.comment,
|
|
3009
|
-
type:
|
|
3010
|
-
|
|
2925
|
+
type: resolveEntitySchemaType(entityRef),
|
|
2926
|
+
isArray: true
|
|
3011
2927
|
}
|
|
3012
2928
|
})(target, propertyKey);
|
|
3013
2929
|
};
|
|
@@ -10066,6 +9982,6 @@ ObjectStorageModule = __decorate([Global(), Module({
|
|
|
10066
9982
|
exports: [ObjectStorageService]
|
|
10067
9983
|
})], ObjectStorageModule);
|
|
10068
9984
|
//#endregion
|
|
10069
|
-
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,
|
|
9985
|
+
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 };
|
|
10070
9986
|
|
|
10071
9987
|
//# sourceMappingURL=index.mjs.map
|