@nest-omni/core 4.1.3-2 → 4.1.3-22
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/audit/audit.module.d.ts +11 -0
- package/audit/audit.module.js +65 -1
- package/audit/controllers/audit.controller.d.ts +81 -1
- package/audit/controllers/audit.controller.js +67 -0
- package/audit/decorators/audit-action.decorator.d.ts +74 -0
- package/audit/decorators/audit-action.decorator.js +42 -0
- package/audit/decorators/audit-controller.decorator.d.ts +9 -1
- package/audit/decorators/audit-controller.decorator.js +11 -2
- package/audit/decorators/audit-operation.decorator.d.ts +38 -0
- package/audit/decorators/audit-operation.decorator.js +42 -0
- package/audit/decorators/entity-audit.decorator.d.ts +85 -1
- package/audit/decorators/entity-audit.decorator.js +153 -3
- package/audit/decorators/index.d.ts +2 -0
- package/audit/decorators/index.js +2 -0
- package/audit/dto/audit-action-query.dto.d.ts +13 -0
- package/audit/dto/audit-action-query.dto.js +77 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/index.d.ts +1 -0
- package/audit/dto/index.js +1 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/audit-action-summary.entity.d.ts +23 -0
- package/audit/entities/audit-action-summary.entity.js +101 -0
- package/audit/entities/entity-audit-log.entity.d.ts +10 -2
- package/audit/entities/entity-audit-log.entity.js +48 -9
- package/audit/entities/entity-transaction.entity.d.ts +11 -2
- package/audit/entities/entity-transaction.entity.js +42 -3
- package/audit/entities/index.d.ts +3 -0
- package/audit/entities/index.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -2
- package/audit/entities/manual-operation-log.entity.js +12 -9
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +29 -6
- package/audit/enums/audit.enums.js +31 -7
- package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
- package/audit/examples/decorator-value-mapping.example.js +414 -0
- package/audit/index.d.ts +5 -1
- package/audit/index.js +38 -1
- package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
- package/audit/interceptors/audit-action.interceptor.js +215 -0
- package/audit/interceptors/audit.interceptor.d.ts +16 -0
- package/audit/interceptors/audit.interceptor.js +41 -11
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +1 -0
- package/audit/interfaces/audit.interfaces.d.ts +174 -4
- package/audit/services/audit-action.service.d.ts +141 -0
- package/audit/services/audit-action.service.js +244 -0
- package/audit/services/audit-context.service.d.ts +106 -0
- package/audit/services/audit-context.service.js +185 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +273 -5
- package/audit/services/entity-audit.service.js +840 -60
- package/audit/services/index.d.ts +3 -0
- package/audit/services/index.js +3 -0
- package/audit/services/manual-audit-log.service.d.ts +133 -9
- package/audit/services/manual-audit-log.service.js +157 -42
- package/audit/services/multi-database.service.d.ts +9 -2
- package/audit/services/multi-database.service.js +9 -21
- package/audit/services/operation-description.service.d.ts +71 -2
- package/audit/services/operation-description.service.js +231 -20
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +53 -5
- package/audit/subscribers/entity-audit.subscriber.d.ts +20 -0
- package/audit/subscribers/entity-audit.subscriber.js +98 -6
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +87 -2
- package/cache/cache.module.js +84 -11
- package/cache/cache.service.d.ts +143 -3
- package/cache/cache.service.js +173 -4
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +83 -7
- package/cache/dependencies/db.dependency.js +89 -14
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +75 -4
- package/cache/dependencies/tag.dependency.js +145 -11
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/entities/index.d.ts +1 -0
- package/cache/entities/index.js +17 -0
- package/cache/entities/typeorm-cache.entity.d.ts +71 -0
- package/cache/entities/typeorm-cache.entity.js +110 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.d.ts +2 -1
- package/cache/index.js +28 -2
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +89 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/index.d.ts +2 -1
- package/cache/providers/index.js +2 -1
- package/cache/providers/lrucache.provider.d.ts +76 -0
- package/cache/providers/lrucache.provider.js +226 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/providers/typeorm-cache.provider.d.ts +211 -0
- package/cache/providers/typeorm-cache.provider.js +483 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +143 -0
- package/common/boilerplate.polyfill.js +35 -1
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/helpers/validation-metadata-helper.d.ts +55 -0
- package/common/helpers/validation-metadata-helper.js +60 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +4 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.d.ts +72 -3
- package/decorators/field.decorators.js +155 -19
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -2
- package/decorators/transform.decorators.js +29 -23
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/file-upload/controllers/file-access.controller.d.ts +23 -0
- package/file-upload/controllers/file-access.controller.js +128 -0
- package/file-upload/decorators/column.decorator.d.ts +151 -0
- package/file-upload/decorators/column.decorator.js +273 -0
- package/file-upload/decorators/csv-data.decorator.d.ts +30 -0
- package/file-upload/decorators/csv-data.decorator.js +85 -0
- package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
- package/file-upload/decorators/csv-import.decorator.js +24 -0
- package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
- package/file-upload/decorators/examples/column-mapping.example.js +122 -0
- package/file-upload/decorators/excel-data.decorator.d.ts +30 -0
- package/file-upload/decorators/excel-data.decorator.js +85 -0
- package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
- package/file-upload/decorators/file-upload.decorator.js +172 -0
- package/file-upload/decorators/index.d.ts +5 -0
- package/file-upload/decorators/index.js +38 -0
- package/file-upload/decorators/process.decorator.d.ts +40 -0
- package/file-upload/decorators/process.decorator.js +52 -0
- package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
- package/file-upload/decorators/validate-data.decorator.js +39 -0
- package/file-upload/dto/create-file.dto.d.ts +24 -0
- package/file-upload/dto/create-file.dto.js +112 -0
- package/file-upload/dto/find-files.dto.d.ts +15 -0
- package/file-upload/dto/find-files.dto.js +76 -0
- package/file-upload/dto/index.d.ts +4 -0
- package/file-upload/dto/index.js +20 -0
- package/file-upload/dto/pagination.dto.d.ts +7 -0
- package/file-upload/dto/pagination.dto.js +39 -0
- package/file-upload/dto/update-file.dto.d.ts +15 -0
- package/file-upload/dto/update-file.dto.js +67 -0
- package/file-upload/entities/file-metadata.entity.d.ts +25 -0
- package/file-upload/entities/file-metadata.entity.js +76 -0
- package/file-upload/entities/file.entity.d.ts +114 -0
- package/file-upload/entities/file.entity.js +350 -0
- package/file-upload/entities/index.d.ts +2 -0
- package/file-upload/entities/index.js +18 -0
- package/file-upload/enums/file-type.enum.d.ts +72 -0
- package/file-upload/enums/file-type.enum.js +212 -0
- package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
- package/file-upload/exceptions/file-upload.exception.js +120 -0
- package/file-upload/exceptions/index.d.ts +1 -0
- package/file-upload/exceptions/index.js +17 -0
- package/file-upload/file-upload.module.d.ts +89 -0
- package/file-upload/file-upload.module.js +292 -0
- package/file-upload/index.d.ts +37 -0
- package/file-upload/index.js +77 -0
- package/file-upload/interceptors/file-upload.interceptor.d.ts +101 -0
- package/file-upload/interceptors/file-upload.interceptor.js +594 -0
- package/file-upload/interceptors/index.d.ts +1 -0
- package/file-upload/interceptors/index.js +17 -0
- package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
- package/file-upload/interfaces/custom-file-type.interface.js +2 -0
- package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
- package/file-upload/interfaces/file-buffer.interface.js +2 -0
- package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
- package/file-upload/interfaces/file-entity.interface.js +28 -0
- package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
- package/file-upload/interfaces/file-metadata.interface.js +2 -0
- package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
- package/file-upload/interfaces/file-processor.interface.js +2 -0
- package/file-upload/interfaces/file-upload-options.interface.d.ts +74 -0
- package/file-upload/interfaces/file-upload-options.interface.js +5 -0
- package/file-upload/interfaces/index.d.ts +7 -0
- package/file-upload/interfaces/index.js +24 -0
- package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
- package/file-upload/interfaces/processor-options.interface.js +2 -0
- package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
- package/file-upload/interfaces/storage-provider.interface.js +2 -0
- package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
- package/file-upload/interfaces/upload-options.interface.js +2 -0
- package/file-upload/processors/csv.processor.d.ts +98 -0
- package/file-upload/processors/csv.processor.js +391 -0
- package/file-upload/processors/excel.processor.d.ts +130 -0
- package/file-upload/processors/excel.processor.js +547 -0
- package/file-upload/processors/image.processor.d.ts +199 -0
- package/file-upload/processors/image.processor.js +377 -0
- package/file-upload/providers/index.d.ts +2 -0
- package/file-upload/providers/index.js +18 -0
- package/file-upload/providers/local-storage.provider.d.ts +98 -0
- package/file-upload/providers/local-storage.provider.js +484 -0
- package/file-upload/providers/s3-storage.provider.d.ts +87 -0
- package/file-upload/providers/s3-storage.provider.js +455 -0
- package/file-upload/services/file-signature-validator.service.d.ts +118 -0
- package/file-upload/services/file-signature-validator.service.js +376 -0
- package/file-upload/services/file.service.d.ts +193 -0
- package/file-upload/services/file.service.js +638 -0
- package/file-upload/services/index.d.ts +4 -0
- package/file-upload/services/index.js +20 -0
- package/file-upload/services/malicious-file-detector.service.d.ts +300 -0
- package/file-upload/services/malicious-file-detector.service.js +1234 -0
- package/file-upload/services/mime-registry.service.d.ts +47 -0
- package/file-upload/services/mime-registry.service.js +167 -0
- package/file-upload/utils/checksum.util.d.ts +28 -0
- package/file-upload/utils/checksum.util.js +65 -0
- package/file-upload/utils/dynamic-import.util.d.ts +54 -0
- package/file-upload/utils/dynamic-import.util.js +156 -0
- package/file-upload/utils/filename.util.d.ts +59 -0
- package/file-upload/utils/filename.util.js +184 -0
- package/file-upload/utils/filepath.util.d.ts +70 -0
- package/file-upload/utils/filepath.util.js +152 -0
- package/file-upload/utils/index.d.ts +4 -0
- package/file-upload/utils/index.js +20 -0
- package/filters/bad-request.filter.js +19 -4
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +20 -0
- package/http-client/config/http-client.config.js +48 -21
- package/http-client/decorators/http-client.decorators.d.ts +55 -14
- package/http-client/decorators/http-client.decorators.js +154 -78
- package/http-client/entities/http-log.entity.d.ts +217 -8
- package/http-client/entities/http-log.entity.js +7 -22
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +40 -0
- package/http-client/examples/advanced-usage.example.js +53 -61
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
- package/http-client/examples/proxy-from-environment.example.js +409 -0
- package/http-client/http-client.module.d.ts +48 -2
- package/http-client/http-client.module.js +147 -68
- package/http-client/index.d.ts +1 -1
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +80 -45
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +109 -52
- package/http-client/services/api-client-registry.service.d.ts +50 -11
- package/http-client/services/api-client-registry.service.js +90 -250
- package/http-client/services/circuit-breaker.service.d.ts +115 -2
- package/http-client/services/circuit-breaker.service.js +237 -7
- package/http-client/services/http-client.service.d.ts +124 -14
- package/http-client/services/http-client.service.js +437 -148
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +121 -13
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/index.d.ts +0 -1
- package/http-client/services/index.js +0 -1
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +116 -7
- package/http-client/services/logging.service.js +349 -86
- package/http-client/utils/call-stack-extractor.util.d.ts +63 -0
- package/http-client/utils/call-stack-extractor.util.js +83 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +54 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/index.d.ts +1 -0
- package/http-client/utils/index.js +1 -0
- package/http-client/utils/proxy-environment.util.d.ts +42 -0
- package/http-client/utils/proxy-environment.util.js +148 -0
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/http-client/utils/security-validator.util.d.ts +118 -0
- package/http-client/utils/security-validator.util.js +352 -0
- package/index.d.ts +3 -1
- package/index.js +12 -1
- package/interceptors/translation-interceptor.service.js +5 -0
- package/ip-filter/constants.d.ts +21 -0
- package/ip-filter/constants.js +24 -0
- package/ip-filter/decorators/index.d.ts +1 -0
- package/ip-filter/decorators/index.js +17 -0
- package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
- package/ip-filter/decorators/ip-filter.decorator.js +79 -0
- package/ip-filter/guards/index.d.ts +1 -0
- package/ip-filter/guards/index.js +17 -0
- package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
- package/ip-filter/guards/ip-filter.guard.js +174 -0
- package/ip-filter/index.d.ts +7 -0
- package/ip-filter/index.js +23 -0
- package/ip-filter/interfaces/index.d.ts +4 -0
- package/ip-filter/interfaces/index.js +20 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
- package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
- package/ip-filter/interfaces/ip-rule.interface.js +2 -0
- package/ip-filter/ip-filter.module.d.ts +55 -0
- package/ip-filter/ip-filter.module.js +105 -0
- package/ip-filter/services/index.d.ts +1 -0
- package/ip-filter/services/index.js +17 -0
- package/ip-filter/services/ip-filter.service.d.ts +92 -0
- package/ip-filter/services/ip-filter.service.js +238 -0
- package/ip-filter/utils/index.d.ts +1 -0
- package/ip-filter/utils/index.js +17 -0
- package/ip-filter/utils/ip-utils.d.ts +61 -0
- package/ip-filter/utils/ip-utils.js +162 -0
- package/package.json +32 -29
- package/providers/context.provider.d.ts +9 -0
- package/providers/context.provider.js +15 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +80 -0
- package/redis-lock/lock-heartbeat.service.js +232 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +282 -0
- package/redis-lock/redis-lock.service.js +343 -20
- package/setup/bootstrap.setup.d.ts +2 -1
- package/setup/bootstrap.setup.js +22 -1
- package/setup/index.d.ts +1 -0
- package/setup/index.js +1 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/run-in-mode.decorator.d.ts +56 -0
- package/setup/run-in-mode.decorator.js +92 -0
- package/setup/schedule.decorator.d.ts +227 -0
- package/setup/schedule.decorator.js +240 -12
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +97 -0
- package/shared/index.d.ts +1 -1
- package/shared/index.js +1 -1
- package/shared/{serviceRegistryModule.js → service-registry.module.js} +19 -18
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +21 -9
- package/shared/services/index.d.ts +0 -1
- package/shared/services/index.js +0 -1
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +23 -0
- package/validators/custom-validate.examples.js +78 -6
- package/validators/custom-validate.validator.d.ts +108 -0
- package/validators/custom-validate.validator.js +85 -0
- package/validators/file-mimetype.validator.d.ts +0 -2
- package/validators/file-mimetype.validator.js +4 -6
- package/validators/index.d.ts +1 -0
- package/validators/index.js +1 -0
- package/validators/is-exists.validator.d.ts +26 -6
- package/validators/is-exists.validator.js +30 -7
- package/validators/is-unique.validator.d.ts +33 -7
- package/validators/is-unique.validator.js +59 -17
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/cache/providers/memory-cache.provider.d.ts +0 -26
- package/cache/providers/memory-cache.provider.js +0 -171
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
- package/http-client/services/cache.service.d.ts +0 -24
- package/http-client/services/cache.service.js +0 -264
- package/shared/services/validator.service.d.ts +0 -3
- package/shared/services/validator.service.js +0 -20
- /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeORM Cache Entity
|
|
3
|
+
*
|
|
4
|
+
* Stores cached data in the database with automatic expiration support.
|
|
5
|
+
* Used by TypeormCacheProvider for persistent caching.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Namespace isolation for different cache segments
|
|
9
|
+
* - Automatic expiration handling
|
|
10
|
+
* - TTL tracking
|
|
11
|
+
* - Value JSON serialization
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // In your TypeORM configuration:
|
|
16
|
+
* {
|
|
17
|
+
* entities: [TypeormCacheEntity],
|
|
18
|
+
* // ... other options
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class TypeormCacheEntity {
|
|
23
|
+
/**
|
|
24
|
+
* Composite key: namespace + key
|
|
25
|
+
* Allows same key in different namespaces
|
|
26
|
+
*/
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* Namespace for cache isolation
|
|
30
|
+
* Multiple applications can share the same table
|
|
31
|
+
*/
|
|
32
|
+
namespace: string;
|
|
33
|
+
/**
|
|
34
|
+
* Cached value (JSON serialized)
|
|
35
|
+
*/
|
|
36
|
+
value: string;
|
|
37
|
+
/**
|
|
38
|
+
* Expiration timestamp
|
|
39
|
+
* NULL means no expiration
|
|
40
|
+
*/
|
|
41
|
+
expires_at: Date | null;
|
|
42
|
+
/**
|
|
43
|
+
* Time to live in seconds
|
|
44
|
+
* Stored for reference and debugging
|
|
45
|
+
*/
|
|
46
|
+
ttl: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Creation timestamp
|
|
49
|
+
*/
|
|
50
|
+
created_at: Date;
|
|
51
|
+
/**
|
|
52
|
+
* Last update timestamp
|
|
53
|
+
*/
|
|
54
|
+
updated_at: Date;
|
|
55
|
+
/**
|
|
56
|
+
* Check if entry is expired
|
|
57
|
+
*/
|
|
58
|
+
isExpired(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Check if entry is valid (not expired)
|
|
61
|
+
*/
|
|
62
|
+
isValid(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Update value and expiration
|
|
65
|
+
*/
|
|
66
|
+
updateValue(newValue: string, ttl?: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get remaining time to live in milliseconds
|
|
69
|
+
*/
|
|
70
|
+
getRemainingTTL(): number;
|
|
71
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TypeormCacheEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
/**
|
|
15
|
+
* TypeORM Cache Entity
|
|
16
|
+
*
|
|
17
|
+
* Stores cached data in the database with automatic expiration support.
|
|
18
|
+
* Used by TypeormCacheProvider for persistent caching.
|
|
19
|
+
*
|
|
20
|
+
* Features:
|
|
21
|
+
* - Namespace isolation for different cache segments
|
|
22
|
+
* - Automatic expiration handling
|
|
23
|
+
* - TTL tracking
|
|
24
|
+
* - Value JSON serialization
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // In your TypeORM configuration:
|
|
29
|
+
* {
|
|
30
|
+
* entities: [TypeormCacheEntity],
|
|
31
|
+
* // ... other options
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
let TypeormCacheEntity = class TypeormCacheEntity {
|
|
36
|
+
/**
|
|
37
|
+
* Check if entry is expired
|
|
38
|
+
*/
|
|
39
|
+
isExpired() {
|
|
40
|
+
if (!this.expires_at) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return new Date() > this.expires_at;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if entry is valid (not expired)
|
|
47
|
+
*/
|
|
48
|
+
isValid() {
|
|
49
|
+
return !this.isExpired();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Update value and expiration
|
|
53
|
+
*/
|
|
54
|
+
updateValue(newValue, ttl) {
|
|
55
|
+
this.value = newValue;
|
|
56
|
+
if (ttl && ttl > 0) {
|
|
57
|
+
this.ttl = Math.floor(ttl / 1000);
|
|
58
|
+
this.expires_at = new Date(Date.now() + ttl);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.ttl = null;
|
|
62
|
+
this.expires_at = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get remaining time to live in milliseconds
|
|
67
|
+
*/
|
|
68
|
+
getRemainingTTL() {
|
|
69
|
+
if (!this.expires_at) {
|
|
70
|
+
return -1; // No expiration
|
|
71
|
+
}
|
|
72
|
+
const remaining = this.expires_at.getTime() - Date.now();
|
|
73
|
+
return Math.max(0, remaining);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.TypeormCacheEntity = TypeormCacheEntity;
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 255 }),
|
|
79
|
+
(0, typeorm_1.Index)(),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], TypeormCacheEntity.prototype, "key", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 255 }),
|
|
84
|
+
(0, typeorm_1.Index)(),
|
|
85
|
+
__metadata("design:type", String)
|
|
86
|
+
], TypeormCacheEntity.prototype, "namespace", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, typeorm_1.Column)({ type: 'text' }),
|
|
89
|
+
__metadata("design:type", String)
|
|
90
|
+
], TypeormCacheEntity.prototype, "value", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, typeorm_1.Column)({ type: 'datetime', nullable: true }),
|
|
93
|
+
(0, typeorm_1.Index)(),
|
|
94
|
+
__metadata("design:type", Date)
|
|
95
|
+
], TypeormCacheEntity.prototype, "expires_at", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
98
|
+
__metadata("design:type", Number)
|
|
99
|
+
], TypeormCacheEntity.prototype, "ttl", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
(0, typeorm_1.CreateDateColumn)({ type: 'datetime', name: 'created_at' }),
|
|
102
|
+
__metadata("design:type", Date)
|
|
103
|
+
], TypeormCacheEntity.prototype, "created_at", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
(0, typeorm_1.UpdateDateColumn)({ type: 'datetime', name: 'updated_at' }),
|
|
106
|
+
__metadata("design:type", Date)
|
|
107
|
+
], TypeormCacheEntity.prototype, "updated_at", void 0);
|
|
108
|
+
exports.TypeormCacheEntity = TypeormCacheEntity = __decorate([
|
|
109
|
+
(0, typeorm_1.Entity)('typeorm_cache')
|
|
110
|
+
], TypeormCacheEntity);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础缓存使用示例
|
|
3
|
+
*/
|
|
1
4
|
import { CacheService } from '../index';
|
|
2
5
|
interface User {
|
|
3
6
|
id: string;
|
|
@@ -25,6 +28,9 @@ declare class UserRepository {
|
|
|
25
28
|
declare class PostRepository {
|
|
26
29
|
findByAuthor(authorId: string): Promise<Post[]>;
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* 用户服务示例
|
|
33
|
+
*/
|
|
28
34
|
export declare class UserService {
|
|
29
35
|
private cacheService;
|
|
30
36
|
private userRepository;
|
|
@@ -39,6 +45,9 @@ export declare class UserService {
|
|
|
39
45
|
cacheLargeData(id: string): Promise<void>;
|
|
40
46
|
getLargeData(id: string): Promise<any>;
|
|
41
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* 文章服务示例 - 展示依赖使用
|
|
50
|
+
*/
|
|
42
51
|
export declare class PostService {
|
|
43
52
|
private cacheService;
|
|
44
53
|
private postRepository;
|
|
@@ -47,6 +56,9 @@ export declare class PostService {
|
|
|
47
56
|
getFeaturedPosts(): Promise<Post[]>;
|
|
48
57
|
private getConfigVersion;
|
|
49
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* 缓存统计和监控示例
|
|
61
|
+
*/
|
|
50
62
|
export declare class CacheMonitoringService {
|
|
51
63
|
private cacheService;
|
|
52
64
|
constructor(cacheService: CacheService);
|
|
@@ -54,5 +66,8 @@ export declare class CacheMonitoringService {
|
|
|
54
66
|
resetStats(): void;
|
|
55
67
|
startMonitoring(intervalMs?: number): void;
|
|
56
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* 使用示例
|
|
71
|
+
*/
|
|
57
72
|
declare function demonstrateCacheUsage(): Promise<void>;
|
|
58
73
|
export { demonstrateCacheUsage };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 基础缓存使用示例
|
|
4
|
+
*/
|
|
2
5
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
6
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
7
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -22,16 +25,18 @@ exports.CacheMonitoringService = exports.PostService = exports.UserService = voi
|
|
|
22
25
|
exports.demonstrateCacheUsage = demonstrateCacheUsage;
|
|
23
26
|
const common_1 = require("@nestjs/common");
|
|
24
27
|
const index_1 = require("../index");
|
|
28
|
+
// 模拟的仓库类
|
|
25
29
|
class UserRepository {
|
|
26
30
|
findOne(id) {
|
|
27
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
// 模拟数据库查询
|
|
28
33
|
console.log(`[DB] 查询用户 ${id}`);
|
|
29
34
|
return {
|
|
30
35
|
id,
|
|
31
36
|
name: `User ${id}`,
|
|
32
37
|
email: `user${id}@example.com`,
|
|
33
38
|
profile: {
|
|
34
|
-
bio: `这是用户 ${id} 的个人简介`.repeat(10),
|
|
39
|
+
bio: `这是用户 ${id} 的个人简介`.repeat(10), // 长文本,用于测试压缩
|
|
35
40
|
avatar: `avatar_${id}.jpg`,
|
|
36
41
|
},
|
|
37
42
|
};
|
|
@@ -80,37 +85,45 @@ class PostRepository {
|
|
|
80
85
|
.map((_, i) => ({
|
|
81
86
|
id: `post_${authorId}_${i}`,
|
|
82
87
|
title: `文章 ${i}`,
|
|
83
|
-
content: `这是文章 ${i} 的内容`.repeat(15),
|
|
88
|
+
content: `这是文章 ${i} 的内容`.repeat(15), // 长内容,用于测试压缩
|
|
84
89
|
authorId,
|
|
85
90
|
createdAt: new Date(),
|
|
86
91
|
}));
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 用户服务示例
|
|
97
|
+
*/
|
|
90
98
|
let UserService = class UserService {
|
|
91
99
|
constructor(cacheService, userRepository) {
|
|
92
100
|
this.cacheService = cacheService;
|
|
93
101
|
this.userRepository = userRepository;
|
|
94
102
|
}
|
|
103
|
+
// 基础缓存使用
|
|
95
104
|
getUser(id) {
|
|
96
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
106
|
return yield this.cacheService.getOrSet(`user:${id}`, () => this.userRepository.findOne(id), { ttl: 300000 });
|
|
98
107
|
});
|
|
99
108
|
}
|
|
109
|
+
// 使用装饰器缓存
|
|
100
110
|
getUserProfile(id) {
|
|
101
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
112
|
return yield this.userRepository.findOne(id);
|
|
103
113
|
});
|
|
104
114
|
}
|
|
115
|
+
// 条件缓存 - 不缓存管理员用户
|
|
105
116
|
getUserData(id) {
|
|
106
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
118
|
return yield this.userRepository.findOne(id);
|
|
108
119
|
});
|
|
109
120
|
}
|
|
121
|
+
// 批量获取用户
|
|
110
122
|
getUsersBatch(ids) {
|
|
111
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
124
|
const keys = ids.map((id) => `user:${id}`);
|
|
113
125
|
const cachedUsers = yield this.cacheService.mget(keys);
|
|
126
|
+
// 找出缓存中没有的用户
|
|
114
127
|
const uncachedIds = [];
|
|
115
128
|
const result = [];
|
|
116
129
|
cachedUsers.forEach((user, index) => {
|
|
@@ -121,8 +134,10 @@ let UserService = class UserService {
|
|
|
121
134
|
uncachedIds.push(ids[index]);
|
|
122
135
|
}
|
|
123
136
|
});
|
|
137
|
+
// 批量查询未缓存的用户
|
|
124
138
|
if (uncachedIds.length > 0) {
|
|
125
139
|
const newUsers = yield this.userRepository.findMany(uncachedIds);
|
|
140
|
+
// 批量设置缓存
|
|
126
141
|
const cacheItems = newUsers.map((user) => ({
|
|
127
142
|
key: `user:${user.id}`,
|
|
128
143
|
value: user,
|
|
@@ -133,22 +148,26 @@ let UserService = class UserService {
|
|
|
133
148
|
return result;
|
|
134
149
|
});
|
|
135
150
|
}
|
|
151
|
+
// 更新用户并缓存
|
|
136
152
|
updateUser(id, data) {
|
|
137
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
154
|
const updatedUser = yield this.userRepository.save(Object.assign({ id }, data));
|
|
139
155
|
return updatedUser;
|
|
140
156
|
});
|
|
141
157
|
}
|
|
158
|
+
// 删除用户并清除缓存
|
|
142
159
|
deleteUser(id) {
|
|
143
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
161
|
yield this.userRepository.delete(id);
|
|
145
162
|
});
|
|
146
163
|
}
|
|
164
|
+
// 使用标签失效
|
|
147
165
|
invalidateAllProfiles() {
|
|
148
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
167
|
console.log('清除所有用户资料缓存');
|
|
150
168
|
});
|
|
151
169
|
}
|
|
170
|
+
// 缓存大数据(测试压缩)
|
|
152
171
|
cacheLargeData(id) {
|
|
153
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
173
|
const largeData = {
|
|
@@ -173,11 +192,13 @@ let UserService = class UserService {
|
|
|
173
192
|
averageRating: (Math.random() * 5).toFixed(2),
|
|
174
193
|
},
|
|
175
194
|
};
|
|
195
|
+
// 这个数据会被自动压缩,因为大于 1KB
|
|
176
196
|
yield this.cacheService.set(`user:${id}:large-data`, largeData, {
|
|
177
|
-
ttl: 3600000,
|
|
197
|
+
ttl: 3600000, // 1小时
|
|
178
198
|
});
|
|
179
199
|
});
|
|
180
200
|
}
|
|
201
|
+
// 获取大数据
|
|
181
202
|
getLargeData(id) {
|
|
182
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
204
|
return yield this.cacheService.get(`user:${id}:large-data`);
|
|
@@ -188,7 +209,7 @@ exports.UserService = UserService;
|
|
|
188
209
|
__decorate([
|
|
189
210
|
(0, index_1.Cacheable)({
|
|
190
211
|
key: (id) => `user:${id}:profile`,
|
|
191
|
-
ttl: 600000,
|
|
212
|
+
ttl: 600000, // 10分钟
|
|
192
213
|
dependencies: [new index_1.TagDependency(['user-profile'])],
|
|
193
214
|
}),
|
|
194
215
|
__metadata("design:type", Function),
|
|
@@ -235,18 +256,24 @@ exports.UserService = UserService = __decorate([
|
|
|
235
256
|
__metadata("design:paramtypes", [index_1.CacheService,
|
|
236
257
|
UserRepository])
|
|
237
258
|
], UserService);
|
|
259
|
+
/**
|
|
260
|
+
* 文章服务示例 - 展示依赖使用
|
|
261
|
+
*/
|
|
238
262
|
let PostService = class PostService {
|
|
239
263
|
constructor(cacheService, postRepository) {
|
|
240
264
|
this.cacheService = cacheService;
|
|
241
265
|
this.postRepository = postRepository;
|
|
242
266
|
}
|
|
267
|
+
// 使用数据库依赖 - 当用户表更新时,相关文章缓存会自动失效
|
|
243
268
|
getPostsByAuthor(authorId) {
|
|
244
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
245
270
|
return yield this.postRepository.findByAuthor(authorId);
|
|
246
271
|
});
|
|
247
272
|
}
|
|
273
|
+
// 使用回调依赖 - 基于配置版本
|
|
248
274
|
getFeaturedPosts() {
|
|
249
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
// 模拟获取推荐文章
|
|
250
277
|
console.log('[DB] 获取推荐文章');
|
|
251
278
|
return Array(10)
|
|
252
279
|
.fill(null)
|
|
@@ -261,6 +288,7 @@ let PostService = class PostService {
|
|
|
261
288
|
}
|
|
262
289
|
getConfigVersion() {
|
|
263
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
// 模拟获取配置版本
|
|
264
292
|
return '1.0.0';
|
|
265
293
|
});
|
|
266
294
|
}
|
|
@@ -269,7 +297,7 @@ exports.PostService = PostService;
|
|
|
269
297
|
__decorate([
|
|
270
298
|
(0, index_1.Cacheable)({
|
|
271
299
|
key: (authorId) => `posts:by-author:${authorId}`,
|
|
272
|
-
ttl: 600000,
|
|
300
|
+
ttl: 600000, // 10分钟
|
|
273
301
|
dependencies: [
|
|
274
302
|
new index_1.DbDependency('SELECT updated_at FROM users WHERE id = ?', (authorId) => [authorId]),
|
|
275
303
|
],
|
|
@@ -281,10 +309,11 @@ __decorate([
|
|
|
281
309
|
__decorate([
|
|
282
310
|
(0, index_1.Cacheable)({
|
|
283
311
|
key: 'posts:featured',
|
|
284
|
-
ttl: 1800000,
|
|
312
|
+
ttl: 1800000, // 30分钟
|
|
285
313
|
dependencies: [
|
|
286
314
|
new index_1.CallbackDependency(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
287
|
-
|
|
315
|
+
// 检查配置版本,如果配置改变则失效缓存
|
|
316
|
+
return yield 'v1.0.0'; // 简化为固定值
|
|
288
317
|
})),
|
|
289
318
|
],
|
|
290
319
|
}),
|
|
@@ -297,10 +326,14 @@ exports.PostService = PostService = __decorate([
|
|
|
297
326
|
__metadata("design:paramtypes", [index_1.CacheService,
|
|
298
327
|
PostRepository])
|
|
299
328
|
], PostService);
|
|
329
|
+
/**
|
|
330
|
+
* 缓存统计和监控示例
|
|
331
|
+
*/
|
|
300
332
|
let CacheMonitoringService = class CacheMonitoringService {
|
|
301
333
|
constructor(cacheService) {
|
|
302
334
|
this.cacheService = cacheService;
|
|
303
335
|
}
|
|
336
|
+
// 获取缓存统计信息
|
|
304
337
|
getCacheStats() {
|
|
305
338
|
const stats = this.cacheService.getStats();
|
|
306
339
|
console.log('=== 缓存统计信息 ===');
|
|
@@ -317,13 +350,16 @@ let CacheMonitoringService = class CacheMonitoringService {
|
|
|
317
350
|
}
|
|
318
351
|
return stats;
|
|
319
352
|
}
|
|
353
|
+
// 重置统计
|
|
320
354
|
resetStats() {
|
|
321
355
|
this.cacheService.resetStats();
|
|
322
356
|
console.log('缓存统计已重置');
|
|
323
357
|
}
|
|
358
|
+
// 定期监控
|
|
324
359
|
startMonitoring(intervalMs = 60000) {
|
|
325
360
|
setInterval(() => {
|
|
326
361
|
const stats = this.getCacheStats();
|
|
362
|
+
// 如果命中率过低,发出警告
|
|
327
363
|
if (stats.hitRate < 0.7) {
|
|
328
364
|
console.warn(`⚠️ 缓存命中率过低: ${(stats.hitRate * 100).toFixed(2)}%`);
|
|
329
365
|
}
|
|
@@ -336,38 +372,56 @@ exports.CacheMonitoringService = CacheMonitoringService = __decorate([
|
|
|
336
372
|
(0, common_1.Injectable)(),
|
|
337
373
|
__metadata("design:paramtypes", [index_1.CacheService])
|
|
338
374
|
], CacheMonitoringService);
|
|
375
|
+
/**
|
|
376
|
+
* 使用示例
|
|
377
|
+
*/
|
|
339
378
|
function demonstrateCacheUsage() {
|
|
340
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
-
|
|
380
|
+
// 注意:在实际应用中,这些服务会通过依赖注入获得
|
|
381
|
+
const userService = new UserService(new index_1.CacheService(
|
|
382
|
+
// 这些参数在实际应用中会通过模块配置自动注入
|
|
383
|
+
{}, // CLS Provider
|
|
384
|
+
{}, // Memory Provider
|
|
385
|
+
{}, // Redis Provider
|
|
386
|
+
true, // 启用压缩
|
|
387
|
+
1024), new UserRepository());
|
|
342
388
|
const postService = new PostService(new index_1.CacheService({}, {}, {}, true, 1024), new PostRepository());
|
|
343
389
|
const monitoringService = new CacheMonitoringService(new index_1.CacheService({}, {}, {}, true, 1024));
|
|
344
390
|
console.log('🚀 开始缓存演示...\n');
|
|
345
391
|
try {
|
|
392
|
+
// 1. 基础缓存演示
|
|
346
393
|
console.log('1. 基础缓存使用:');
|
|
347
394
|
const user1 = yield userService.getUser('1');
|
|
348
395
|
console.log(`获取用户: ${user1.name}`);
|
|
396
|
+
// 第二次获取应该从缓存获取
|
|
349
397
|
const user1Cached = yield userService.getUser('1');
|
|
350
398
|
console.log(`从缓存获取用户: ${user1Cached.name}\n`);
|
|
399
|
+
// 2. 装饰器缓存演示
|
|
351
400
|
console.log('2. 装饰器缓存:');
|
|
352
401
|
const profile = yield userService.getUserProfile('2');
|
|
353
402
|
console.log(`获取用户资料: ${profile.name}`);
|
|
354
403
|
const profileCached = yield userService.getUserProfile('2');
|
|
355
404
|
console.log(`从缓存获取用户资料: ${profileCached.name}\n`);
|
|
405
|
+
// 3. 批量操作演示
|
|
356
406
|
console.log('3. 批量操作:');
|
|
357
407
|
const users = yield userService.getUsersBatch(['1', '2', '3', '4', '5']);
|
|
358
408
|
console.log(`批量获取 ${users.length} 个用户\n`);
|
|
409
|
+
// 4. 大数据压缩演示
|
|
359
410
|
console.log('4. 大数据压缩:');
|
|
360
411
|
yield userService.cacheLargeData('1');
|
|
361
412
|
console.log('缓存大数据完成(应该自动压缩)');
|
|
362
413
|
const largeData = yield userService.getLargeData('1');
|
|
363
414
|
console.log(`获取大数据: 用户 ${largeData.user.name}, 文章数 ${largeData.posts.length}\n`);
|
|
415
|
+
// 5. 依赖系统演示
|
|
364
416
|
console.log('5. 依赖系统:');
|
|
365
417
|
const posts = yield postService.getPostsByAuthor('1');
|
|
366
418
|
console.log(`获取作者文章: ${posts.length} 篇`);
|
|
367
419
|
const featuredPosts = yield postService.getFeaturedPosts();
|
|
368
420
|
console.log(`获取推荐文章: ${featuredPosts.length} 篇\n`);
|
|
421
|
+
// 6. 缓存统计
|
|
369
422
|
console.log('6. 缓存统计:');
|
|
370
423
|
monitoringService.getCacheStats();
|
|
424
|
+
// 7. 缓存失效演示
|
|
371
425
|
console.log('\n7. 缓存失效:');
|
|
372
426
|
yield userService.invalidateAllProfiles();
|
|
373
427
|
console.log('已清除所有用户资料缓存');
|
package/cache/index.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export { CacheWarmupService, type CacheWarmupConfig, type CacheWarmupResult, } f
|
|
|
6
6
|
export { CacheMetricsService, type CacheMetrics, type CacheOperationRecord, } from './cache-metrics.service';
|
|
7
7
|
export { CacheSerializationService, type CacheSerializationOptions, type SerializationResult, type DeserializationResult, } from './cache-serialization.service';
|
|
8
8
|
export { Cacheable, CacheEvict, CachePut, getCacheService, setCacheService, } from './decorators';
|
|
9
|
-
export { ClsCacheProvider,
|
|
9
|
+
export { ClsCacheProvider, LRUCacheProvider, TypeormCacheProvider, RedisCacheProvider, BaseCacheProvider, } from './providers';
|
|
10
10
|
export { REDIS_CLIENT } from './providers/redis-cache.provider';
|
|
11
11
|
export type { CacheProvider } from './interfaces/cache-provider.interface';
|
|
12
|
+
export * from './entities';
|
|
12
13
|
export { CallbackDependency, ChainDependency, DbDependency, FileDependency, TagDependency, TimeDependency, } from './dependencies';
|
|
13
14
|
export { CacheLayer, type CacheDependency, type CacheEvictOptions, type CacheOptions, type CachePutOptions, type CacheableOptions, type CacheStats, type DependencyData, } from './interfaces';
|
|
14
15
|
export { DependencyManager, KeyGenerator, type CachedValueWithDependencies, } from './utils';
|
package/cache/index.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyGenerator = exports.DependencyManager = exports.CacheLayer = exports.TimeDependency = exports.TagDependency = exports.FileDependency = exports.DbDependency = exports.ChainDependency = exports.CallbackDependency = exports.REDIS_CLIENT = exports.BaseCacheProvider = exports.RedisCacheProvider = exports.
|
|
17
|
+
exports.KeyGenerator = exports.DependencyManager = exports.CacheLayer = exports.TimeDependency = exports.TagDependency = exports.FileDependency = exports.DbDependency = exports.ChainDependency = exports.CallbackDependency = exports.REDIS_CLIENT = exports.BaseCacheProvider = exports.RedisCacheProvider = exports.TypeormCacheProvider = exports.LRUCacheProvider = exports.ClsCacheProvider = exports.setCacheService = exports.getCacheService = exports.CachePut = exports.CacheEvict = exports.Cacheable = exports.CacheSerializationService = exports.CacheMetricsService = exports.CacheWarmupService = exports.CacheHealthChecker = exports.CacheService = exports.CACHE_COMPRESSION_THRESHOLD = exports.CACHE_COMPRESSION_ENABLED = exports.CACHE_SERVICE = exports.CacheModule = void 0;
|
|
18
|
+
// Module
|
|
4
19
|
var cache_module_1 = require("./cache.module");
|
|
5
20
|
Object.defineProperty(exports, "CacheModule", { enumerable: true, get: function () { return cache_module_1.CacheModule; } });
|
|
6
21
|
Object.defineProperty(exports, "CACHE_SERVICE", { enumerable: true, get: function () { return cache_module_1.CACHE_SERVICE; } });
|
|
22
|
+
// Constants
|
|
7
23
|
var cache_constants_1 = require("./cache.constants");
|
|
8
24
|
Object.defineProperty(exports, "CACHE_COMPRESSION_ENABLED", { enumerable: true, get: function () { return cache_constants_1.CACHE_COMPRESSION_ENABLED; } });
|
|
9
25
|
Object.defineProperty(exports, "CACHE_COMPRESSION_THRESHOLD", { enumerable: true, get: function () { return cache_constants_1.CACHE_COMPRESSION_THRESHOLD; } });
|
|
26
|
+
// Service
|
|
10
27
|
var cache_service_1 = require("./cache.service");
|
|
11
28
|
Object.defineProperty(exports, "CacheService", { enumerable: true, get: function () { return cache_service_1.CacheService; } });
|
|
29
|
+
// Additional Services
|
|
12
30
|
var cache_health_1 = require("./cache.health");
|
|
13
31
|
Object.defineProperty(exports, "CacheHealthChecker", { enumerable: true, get: function () { return cache_health_1.CacheHealthChecker; } });
|
|
14
32
|
var cache_warmup_service_1 = require("./cache.warmup.service");
|
|
@@ -17,19 +35,25 @@ var cache_metrics_service_1 = require("./cache-metrics.service");
|
|
|
17
35
|
Object.defineProperty(exports, "CacheMetricsService", { enumerable: true, get: function () { return cache_metrics_service_1.CacheMetricsService; } });
|
|
18
36
|
var cache_serialization_service_1 = require("./cache-serialization.service");
|
|
19
37
|
Object.defineProperty(exports, "CacheSerializationService", { enumerable: true, get: function () { return cache_serialization_service_1.CacheSerializationService; } });
|
|
38
|
+
// Decorators
|
|
20
39
|
var decorators_1 = require("./decorators");
|
|
21
40
|
Object.defineProperty(exports, "Cacheable", { enumerable: true, get: function () { return decorators_1.Cacheable; } });
|
|
22
41
|
Object.defineProperty(exports, "CacheEvict", { enumerable: true, get: function () { return decorators_1.CacheEvict; } });
|
|
23
42
|
Object.defineProperty(exports, "CachePut", { enumerable: true, get: function () { return decorators_1.CachePut; } });
|
|
24
43
|
Object.defineProperty(exports, "getCacheService", { enumerable: true, get: function () { return decorators_1.getCacheService; } });
|
|
25
44
|
Object.defineProperty(exports, "setCacheService", { enumerable: true, get: function () { return decorators_1.setCacheService; } });
|
|
45
|
+
// Providers
|
|
26
46
|
var providers_1 = require("./providers");
|
|
27
47
|
Object.defineProperty(exports, "ClsCacheProvider", { enumerable: true, get: function () { return providers_1.ClsCacheProvider; } });
|
|
28
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "LRUCacheProvider", { enumerable: true, get: function () { return providers_1.LRUCacheProvider; } });
|
|
49
|
+
Object.defineProperty(exports, "TypeormCacheProvider", { enumerable: true, get: function () { return providers_1.TypeormCacheProvider; } });
|
|
29
50
|
Object.defineProperty(exports, "RedisCacheProvider", { enumerable: true, get: function () { return providers_1.RedisCacheProvider; } });
|
|
30
51
|
Object.defineProperty(exports, "BaseCacheProvider", { enumerable: true, get: function () { return providers_1.BaseCacheProvider; } });
|
|
31
52
|
var redis_cache_provider_1 = require("./providers/redis-cache.provider");
|
|
32
53
|
Object.defineProperty(exports, "REDIS_CLIENT", { enumerable: true, get: function () { return redis_cache_provider_1.REDIS_CLIENT; } });
|
|
54
|
+
// Entities
|
|
55
|
+
__exportStar(require("./entities"), exports);
|
|
56
|
+
// Dependencies
|
|
33
57
|
var dependencies_1 = require("./dependencies");
|
|
34
58
|
Object.defineProperty(exports, "CallbackDependency", { enumerable: true, get: function () { return dependencies_1.CallbackDependency; } });
|
|
35
59
|
Object.defineProperty(exports, "ChainDependency", { enumerable: true, get: function () { return dependencies_1.ChainDependency; } });
|
|
@@ -37,8 +61,10 @@ Object.defineProperty(exports, "DbDependency", { enumerable: true, get: function
|
|
|
37
61
|
Object.defineProperty(exports, "FileDependency", { enumerable: true, get: function () { return dependencies_1.FileDependency; } });
|
|
38
62
|
Object.defineProperty(exports, "TagDependency", { enumerable: true, get: function () { return dependencies_1.TagDependency; } });
|
|
39
63
|
Object.defineProperty(exports, "TimeDependency", { enumerable: true, get: function () { return dependencies_1.TimeDependency; } });
|
|
64
|
+
// Interfaces
|
|
40
65
|
var interfaces_1 = require("./interfaces");
|
|
41
66
|
Object.defineProperty(exports, "CacheLayer", { enumerable: true, get: function () { return interfaces_1.CacheLayer; } });
|
|
67
|
+
// Utils (advanced usage)
|
|
42
68
|
var utils_1 = require("./utils");
|
|
43
69
|
Object.defineProperty(exports, "DependencyManager", { enumerable: true, get: function () { return utils_1.DependencyManager; } });
|
|
44
70
|
Object.defineProperty(exports, "KeyGenerator", { enumerable: true, get: function () { return utils_1.KeyGenerator; } });
|
|
@@ -1,11 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache dependency interface - similar to Yii2 cache dependency system
|
|
3
|
+
*
|
|
4
|
+
* A cache dependency represents a dependency relationship between cached data
|
|
5
|
+
* and some external state. When the external state changes, the cached data
|
|
6
|
+
* becomes invalid.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Tag-based dependency
|
|
11
|
+
* new TagDependency(['user-list'])
|
|
12
|
+
*
|
|
13
|
+
* // Database-based dependency
|
|
14
|
+
* new DbDependency('SELECT MAX(updated_at) FROM users WHERE id = ?', [userId])
|
|
15
|
+
*
|
|
16
|
+
* // Callback-based dependency
|
|
17
|
+
* new CallbackDependency(() => ConfigService.get('app.version'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
1
20
|
export interface CacheDependency {
|
|
21
|
+
/**
|
|
22
|
+
* Get a unique key that identifies this dependency
|
|
23
|
+
* This key is used to store the dependency state
|
|
24
|
+
*
|
|
25
|
+
* @returns Unique dependency key
|
|
26
|
+
*/
|
|
2
27
|
getKey(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current state/value of this dependency
|
|
30
|
+
* This value will be compared with stored state to detect changes
|
|
31
|
+
*
|
|
32
|
+
* @returns Current dependency data/state
|
|
33
|
+
*/
|
|
3
34
|
getData(): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Check if the dependency has changed by comparing old data with current data
|
|
37
|
+
*
|
|
38
|
+
* @param oldData - Previously stored dependency data
|
|
39
|
+
* @returns true if dependency has changed, false otherwise
|
|
40
|
+
*/
|
|
4
41
|
isChanged(oldData: any): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Reset/clear the dependency state
|
|
44
|
+
* Used when manually invalidating dependencies
|
|
45
|
+
*/
|
|
5
46
|
reset?(): Promise<void>;
|
|
6
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Serialized dependency data stored alongside cached values
|
|
50
|
+
*/
|
|
7
51
|
export interface DependencyData {
|
|
52
|
+
/**
|
|
53
|
+
* Dependency key
|
|
54
|
+
*/
|
|
8
55
|
key: string;
|
|
56
|
+
/**
|
|
57
|
+
* Dependency state snapshot at cache time
|
|
58
|
+
*/
|
|
9
59
|
data: any;
|
|
60
|
+
/**
|
|
61
|
+
* Timestamp when dependency was captured
|
|
62
|
+
*/
|
|
10
63
|
timestamp: number;
|
|
11
64
|
}
|