@mrxsys/mrx-core 2.7.0 → 2.9.0-1-and-259-20250918
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/dist/chunk-00s6t4tw.js +26 -0
- package/dist/chunk-0601exyg.js +7 -0
- package/dist/chunk-4mvsje21.js +7 -0
- package/dist/chunk-547mr88s.js +10 -0
- package/dist/chunk-5pwb7peq.js +9 -0
- package/dist/{chunk-z6q192p8.js → chunk-6g29g0tk.js} +17 -26
- package/dist/chunk-6tqh339a.js +9 -0
- package/dist/{chunk-qb6x364m.js → chunk-75hgws2d.js} +18 -39
- package/dist/chunk-8y9b2m5a.js +53 -0
- package/dist/chunk-9cgzhc50.js +15 -0
- package/dist/chunk-9dzsj7f2.js +23 -0
- package/dist/chunk-b23dvm2d.js +29 -0
- package/dist/chunk-b6f6ez2w.js +8 -0
- package/dist/{chunk-zaje5tv4.js → chunk-c9vjf06h.js} +31 -30
- package/dist/chunk-d0p9787v.js +272 -0
- package/dist/{chunk-5qtpggzv.js → chunk-grfyngq0.js} +3 -2
- package/dist/{chunk-4n72ks5x.js → chunk-h4dyeeqg.js} +4 -5
- package/dist/{chunk-9nw6qekv.js → chunk-h9t48r9q.js} +2 -1
- package/dist/chunk-k9dtqf1p.js +101 -0
- package/dist/{chunk-26brdrbz.js → chunk-kje1qysg.js} +59 -46
- package/dist/{chunk-4mt568fz.js → chunk-m3grz32t.js} +4 -3
- package/dist/{chunk-yvyahr2h.js → chunk-mvrxngm7.js} +2 -1
- package/dist/{chunk-j28jpfv2.js → chunk-n6d9ncnv.js} +2 -1
- package/dist/chunk-ngrxhdkb.js +32 -0
- package/dist/{chunk-79mw7w0g.js → chunk-nvt16s80.js} +2 -1
- package/dist/{chunk-yd82hdxv.js → chunk-w1547qd4.js} +2 -1
- package/dist/chunk-yagxbm1r.js +9 -0
- package/dist/{chunk-snqdnkk7.js → chunk-z9a175mk.js} +4 -3
- package/dist/chunk-zwrygafm.js +61 -0
- package/dist/errors/base-error.d.ts +5 -0
- package/dist/errors/enums/index.d.ts +1 -1
- package/dist/errors/enums/index.js +1 -1
- package/dist/errors/http-error.d.ts +11 -0
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +3 -3
- package/dist/errors/utils/index.d.ts +1 -0
- package/dist/errors/utils/index.js +16 -0
- package/dist/errors/utils/is-nowarajs-error.ts.d.ts +4 -0
- package/dist/modules/data/data.d.ts +3 -3
- package/dist/modules/data/enums/index.d.ts +1 -1
- package/dist/modules/data/enums/index.js +1 -1
- package/dist/modules/data/index.js +3 -3
- package/dist/modules/data/transformers/{camelCase.d.ts → camel-case.d.ts} +2 -2
- package/dist/modules/data/transformers/index.d.ts +4 -4
- package/dist/modules/data/transformers/index.js +4 -4
- package/dist/modules/data/transformers/{kebabCase.d.ts → kebab-case.d.ts} +2 -2
- package/dist/modules/data/transformers/{pascalCase.d.ts → pascal-case.d.ts} +2 -2
- package/dist/modules/data/transformers/{snakeCase.d.ts → snake-case.d.ts} +2 -2
- package/dist/modules/data/types/index.d.ts +10 -10
- package/dist/modules/data/types/{pascalCase.d.ts → pascal-case.d.ts} +1 -1
- package/dist/modules/data/types/{transformKeysCamelCase.d.ts → transform-keys-camel-case.d.ts} +1 -1
- package/dist/modules/data/types/{transformKeysKebabCase.d.ts → transform-keys-kebab-case.d.ts} +1 -1
- package/dist/modules/data/types/{transformKeysPascalCase.d.ts → transform-keys-pascal-case.d.ts} +1 -1
- package/dist/modules/data/types/{transformKeysSnakeCase.d.ts → transform-keys-snake-case.d.ts} +1 -1
- package/dist/modules/data/types/{transformObjectKeys.d.ts → transform-object-keys.d.ts} +8 -8
- package/dist/modules/database/enums/index.d.ts +2 -2
- package/dist/modules/database/enums/index.js +1 -1
- package/dist/modules/database/events/index.d.ts +2 -2
- package/dist/modules/database/events/{mssqlEventMap.d.ts → mssql-event-map.d.ts} +1 -1
- package/dist/modules/database/events/{tableEventMap.d.ts → table-event-map.d.ts} +1 -1
- package/dist/modules/database/index.js +8 -8
- package/dist/modules/database/mssql.d.ts +3 -3
- package/dist/modules/database/table.d.ts +2 -2
- package/dist/modules/database/types/index.d.ts +3 -3
- package/dist/modules/elysia/cache/cache.d.ts +189 -0
- package/dist/modules/elysia/cache/index.d.ts +1 -0
- package/dist/modules/elysia/cache/index.js +70 -0
- package/dist/modules/elysia/cache/types/cache-item.d.ts +7 -0
- package/dist/modules/elysia/cache/types/cache-options.d.ts +21 -0
- package/dist/modules/elysia/cache/types/index.d.ts +1 -0
- package/dist/modules/elysia/cache/utils/generate-cache-key.d.ts +5 -0
- package/dist/modules/elysia/cache/utils/index.d.ts +1 -0
- package/dist/modules/elysia/cache/utils/index.js +7 -0
- package/dist/modules/elysia/{crudSchema/crudSchema.d.ts → crud/crud-schema.d.ts} +4 -4
- package/dist/modules/elysia/crud/crud.d.ts +34 -42
- package/dist/modules/elysia/crud/index.d.ts +1 -0
- package/dist/modules/elysia/crud/index.js +128 -280
- package/dist/modules/elysia/crud/operations/count.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/delete.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/deleteOne.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/find.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/findOne.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/index.d.ts +8 -0
- package/dist/modules/elysia/crud/operations/index.js +33 -0
- package/dist/modules/elysia/crud/operations/insert.d.ts +258 -0
- package/dist/modules/elysia/crud/operations/update.d.ts +268 -0
- package/dist/modules/elysia/crud/operations/updateOne.d.ts +268 -0
- package/dist/modules/elysia/{crudSchema/types/adaptiveWhereClauseSchema.d.ts → crud/types/adaptive-where-clause-schema.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/count-response-200-schema.d.ts +5 -0
- package/dist/modules/elysia/crud/types/count-schema.d.ts +10 -0
- package/dist/modules/elysia/crud/types/crud-operation-base.d.ts +4 -0
- package/dist/modules/elysia/crud/types/crud-operation-count.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-delete-one.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-delete.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-find-one.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-find.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-insert.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operation-update-one.d.ts +16 -0
- package/dist/modules/elysia/crud/types/crud-operation-update.d.ts +14 -0
- package/dist/modules/elysia/crud/types/crud-operations.d.ts +19 -0
- package/dist/modules/elysia/crud/types/crud-options.d.ts +44 -0
- package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +12 -0
- package/dist/modules/elysia/{crudSchema/types/crudSchemaOptions.d.ts → crud/types/crud-schema-options.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/delete-schema.d.ts +12 -0
- package/dist/modules/elysia/crud/types/filter-schema.d.ts +9 -0
- package/dist/modules/elysia/crud/types/find-schema.d.ts +16 -0
- package/dist/modules/elysia/{crudSchema/utils/createIdParamSchema.d.ts → crud/types/id-param-schema.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/index.d.ts +29 -11
- package/dist/modules/elysia/crud/types/insert-schema.d.ts +11 -0
- package/dist/modules/elysia/{crudSchema/types/orderSchema.d.ts → crud/types/order-schema.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/properties-schema.d.ts +9 -0
- package/dist/modules/elysia/{crudSchema/types/qSchema.d.ts → crud/types/q-schema.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/response-200-schema.d.ts +11 -0
- package/dist/modules/elysia/{crudSchema/types/selectedFieldSchema.d.ts → crud/types/selected-field-schema.d.ts} +1 -1
- package/dist/modules/elysia/crud/types/update-one-schema.d.ts +4 -0
- package/dist/modules/elysia/crud/types/update-schema.d.ts +13 -0
- package/dist/modules/elysia/{crudSchema/utils/createAdaptiveWhereClauseSchema.d.ts → crud/utils/create-adaptive-where-clause-schema.d.ts} +2 -2
- package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +8 -0
- package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +12 -0
- package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +12 -0
- package/dist/modules/elysia/{crudSchema/utils/createFiltersSchema.d.ts → crud/utils/create-filters-schema.d.ts} +3 -6
- package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +12 -0
- package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +2 -0
- package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +8 -0
- package/dist/modules/elysia/{crudSchema/utils/createOrderSchema.d.ts → crud/utils/create-order-schema.d.ts} +2 -2
- package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +12 -0
- package/dist/modules/elysia/{crudSchema/utils/createQSchema.d.ts → crud/utils/create-q-schema.d.ts} +2 -2
- package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +3 -0
- package/dist/modules/elysia/{crudSchema/utils/createSelectedFieldsSchema.d.ts → crud/utils/create-selected-fields-schema.d.ts} +2 -2
- package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +3 -0
- package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +3 -0
- package/dist/modules/elysia/crud/utils/index.d.ts +16 -0
- package/dist/modules/elysia/{crudSchema → crud}/utils/index.js +7 -4
- package/dist/modules/elysia/{crudSchema/utils/isDateFromElysiaTypeBox.d.ts → crud/utils/is-date-from-elysia-typebox.d.ts} +1 -1
- package/dist/modules/elysia/db-resolver/db-resolver.d.ts +193 -0
- package/dist/modules/elysia/db-resolver/enums/db-resolver-error-keys.d.ts +3 -0
- package/dist/modules/elysia/db-resolver/enums/index.d.ts +1 -0
- package/dist/modules/elysia/{dbResolver → db-resolver}/enums/index.js +1 -1
- package/dist/modules/elysia/db-resolver/index.d.ts +1 -0
- package/dist/modules/elysia/db-resolver/index.js +18 -0
- package/dist/modules/elysia/error/error.d.ts +14 -3
- package/dist/modules/elysia/error/index.js +14 -5
- package/dist/modules/elysia/microservice/microservice.d.ts +17 -14
- package/dist/modules/elysia/rate-limit/enums/index.d.ts +1 -0
- package/dist/modules/elysia/{rateLimit → rate-limit}/enums/index.js +1 -1
- package/dist/modules/elysia/rate-limit/index.d.ts +1 -0
- package/dist/modules/elysia/rate-limit/index.js +55 -0
- package/dist/modules/elysia/{rateLimit/rateLimit.d.ts → rate-limit/rate-limit.d.ts} +33 -13
- package/dist/modules/elysia/rate-limit/types/index.d.ts +1 -0
- package/dist/modules/elysia/{rateLimit/types/rateLimitOptions.d.ts → rate-limit/types/rate-limit-options.d.ts} +3 -15
- package/dist/modules/jwt/enums/index.d.ts +2 -0
- package/dist/modules/jwt/enums/index.js +11 -0
- package/dist/modules/jwt/enums/jwt-error-keys.d.ts +5 -0
- package/dist/modules/jwt/enums/parse-human-time-to-seconds-error-keys.d.ts +3 -0
- package/dist/modules/jwt/index.d.ts +1 -0
- package/dist/modules/jwt/index.js +51 -0
- package/dist/modules/jwt/jwt.d.ts +3 -0
- package/dist/modules/jwt/utils/index.d.ts +1 -0
- package/dist/modules/jwt/utils/index.js +9 -0
- package/dist/modules/jwt/utils/parse-human-time-to-seconds.d.ts +17 -0
- package/dist/modules/kv-store/enums/index.d.ts +1 -0
- package/dist/modules/kv-store/enums/index.js +7 -0
- package/dist/modules/kv-store/enums/kv-store-error-keys.d.ts +5 -0
- package/dist/modules/kv-store/ioredis/index.d.ts +1 -0
- package/dist/modules/kv-store/ioredis/index.js +92 -0
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +107 -0
- package/dist/modules/kv-store/memory/index.d.ts +1 -0
- package/dist/modules/kv-store/memory/index.js +9 -0
- package/dist/modules/kv-store/memory/memory-store.d.ts +119 -0
- package/dist/modules/{elysia/rateLimit/types/memoryStoreEntry.d.ts → kv-store/memory/types/memory-store-entry.d.ts} +2 -2
- package/dist/modules/kv-store/types/index.d.ts +1 -0
- package/dist/modules/kv-store/types/kv-store.d.ts +81 -0
- package/dist/modules/logger/enums/index.d.ts +1 -1
- package/dist/modules/logger/enums/index.js +1 -1
- package/dist/modules/logger/enums/logger-error-keys.d.ts +6 -0
- package/dist/modules/logger/events/index.d.ts +1 -1
- package/dist/modules/logger/events/logger-events.d.ts +11 -0
- package/dist/modules/logger/index.js +40 -52
- package/dist/modules/logger/logger.d.ts +172 -172
- package/dist/modules/logger/sinks/console-logger.d.ts +22 -0
- package/dist/modules/logger/sinks/file-logger.d.ts +25 -0
- package/dist/modules/logger/sinks/index.d.ts +2 -0
- package/dist/modules/logger/{strategies → sinks}/index.js +6 -6
- package/dist/modules/logger/types/bodies-intersection.d.ts +2 -0
- package/dist/modules/logger/types/index.d.ts +6 -6
- package/dist/modules/logger/types/log-stream-chunk.d.ts +15 -0
- package/dist/modules/logger/types/{loggerStrategy.d.ts → logger-sink.d.ts} +3 -3
- package/dist/modules/logger/types/sink-body.d.ts +2 -0
- package/dist/modules/logger/types/sink-map.d.ts +2 -0
- package/dist/modules/mailer/enums/index.d.ts +1 -1
- package/dist/modules/mailer/enums/index.js +1 -1
- package/dist/modules/mailer/index.js +5 -8
- package/dist/modules/mailer/smtp.d.ts +1 -1
- package/dist/modules/mailer/types/index.d.ts +3 -3
- package/dist/modules/mailer/types/{smtpOptions.d.ts → smtp-options.d.ts} +2 -2
- package/dist/modules/repository/index.js +6 -6
- package/dist/modules/repository/repository.d.ts +5 -5
- package/dist/modules/repository/types/filter.d.ts +2 -2
- package/dist/modules/repository/types/index.d.ts +6 -6
- package/dist/modules/repository/types/{queryOptionsExtendPagination.d.ts → query-options-extend-pagination.d.ts} +1 -1
- package/dist/modules/repository/types/{queryOptionsExtendStream.d.ts → query-options-extend-stream.d.ts} +1 -1
- package/dist/modules/repository/types/{queryOptions.d.ts → query-options.d.ts} +7 -3
- package/dist/modules/singleton-manager/enums/index.d.ts +1 -0
- package/dist/modules/{singletonManager → singleton-manager}/enums/index.js +1 -1
- package/dist/modules/singleton-manager/enums/singleton-manager-error-keys.d.ts +4 -0
- package/dist/modules/singleton-manager/index.d.ts +1 -0
- package/dist/modules/singleton-manager/index.js +9 -0
- package/dist/modules/{singletonManager/singletonManager.d.ts → singleton-manager/singleton-manager.d.ts} +9 -11
- package/dist/modules/totp/enums/index.d.ts +1 -1
- package/dist/modules/totp/enums/index.js +1 -1
- package/dist/modules/totp/hotp.d.ts +11 -0
- package/dist/modules/totp/index.d.ts +3 -1
- package/dist/modules/totp/index.js +33 -42
- package/dist/modules/totp/otp-auth-uri.d.ts +21 -0
- package/dist/modules/totp/totp.d.ts +2 -42
- package/dist/modules/totp/types/index.d.ts +3 -3
- package/dist/modules/totp/types/{verifyOptions.d.ts → verify-options.d.ts} +1 -1
- package/dist/modules/totp/utils/base32.d.ts +1 -1
- package/dist/modules/totp/utils/index.d.ts +5 -4
- package/dist/modules/totp/utils/index.js +12 -11
- package/dist/modules/totp/utils/time-remaining.d.ts +9 -0
- package/dist/modules/typed-event-emitter/index.d.ts +1 -0
- package/dist/modules/{typedEventEmitter → typed-event-emitter}/index.js +1 -1
- package/dist/modules/typed-event-emitter/typed-event-emitter.d.ts +221 -0
- package/dist/modules/typed-event-emitter/types/index.d.ts +1 -0
- package/dist/shared/enums/index.d.ts +1 -0
- package/dist/{utils → shared}/enums/index.js +1 -1
- package/dist/shared/types/index.d.ts +3 -0
- package/dist/shared/types/tflatten.d.ts +5 -0
- package/dist/shared/utils/flatten.d.ts +3 -0
- package/dist/{utils → shared/utils}/index.d.ts +2 -1
- package/dist/{utils → shared/utils}/index.js +10 -9
- package/package.json +96 -90
- package/CHANGELOG.md +0 -79
- package/dist/chunk-45gt9273.js +0 -8
- package/dist/chunk-4xs0e8cm.js +0 -9
- package/dist/chunk-683sda6e.js +0 -28
- package/dist/chunk-7jsxw1ts.js +0 -40
- package/dist/chunk-cqw9xq4y.js +0 -7
- package/dist/chunk-dwfyt1m6.js +0 -6
- package/dist/chunk-g821m8gq.js +0 -77
- package/dist/chunk-hcc6g1fd.js +0 -7
- package/dist/chunk-tm71j126.js +0 -54
- package/dist/chunk-vknq69e0.js +0 -23
- package/dist/errors/baseError.d.ts +0 -9
- package/dist/errors/httpError.d.ts +0 -14
- package/dist/errors/types/baseErrorOptions.d.ts +0 -15
- package/dist/errors/types/httpErrorOptions.d.ts +0 -13
- package/dist/errors/types/index.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationBaseOptions.d.ts +0 -6
- package/dist/modules/elysia/crud/types/crudOperationCountOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationDeleteOneOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationDeleteOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationFindOneOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationFindOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationInsertOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationUpdateOneOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationUpdateOptions.d.ts +0 -2
- package/dist/modules/elysia/crud/types/crudOperationsOptions.d.ts +0 -18
- package/dist/modules/elysia/crud/types/crudOptions.d.ts +0 -23
- package/dist/modules/elysia/crudSchema/index.d.ts +0 -1
- package/dist/modules/elysia/crudSchema/index.js +0 -11
- package/dist/modules/elysia/crudSchema/types/crudModelsType.d.ts +0 -14
- package/dist/modules/elysia/crudSchema/types/index.d.ts +0 -8
- package/dist/modules/elysia/crudSchema/types/queryOptionsBuilderOptions.d.ts +0 -11
- package/dist/modules/elysia/crudSchema/utils/createCountResponse200Schema.d.ts +0 -11
- package/dist/modules/elysia/crudSchema/utils/createCountSchema.d.ts +0 -16
- package/dist/modules/elysia/crudSchema/utils/createDeleteSchema.d.ts +0 -18
- package/dist/modules/elysia/crudSchema/utils/createFindSchema.d.ts +0 -22
- package/dist/modules/elysia/crudSchema/utils/createInsertSchema.d.ts +0 -8
- package/dist/modules/elysia/crudSchema/utils/createPropertiesSchema.d.ts +0 -12
- package/dist/modules/elysia/crudSchema/utils/createResponse200Schema.d.ts +0 -5
- package/dist/modules/elysia/crudSchema/utils/createUpdateOneSchema.d.ts +0 -4
- package/dist/modules/elysia/crudSchema/utils/createUpdateSchema.d.ts +0 -10
- package/dist/modules/elysia/crudSchema/utils/index.d.ts +0 -15
- package/dist/modules/elysia/dbResolver/dbResolver.d.ts +0 -17
- package/dist/modules/elysia/dbResolver/enums/dbResolverErrorKeys.d.ts +0 -3
- package/dist/modules/elysia/dbResolver/enums/index.d.ts +0 -1
- package/dist/modules/elysia/dbResolver/index.d.ts +0 -1
- package/dist/modules/elysia/dbResolver/index.js +0 -18
- package/dist/modules/elysia/dbResolver/types/dynamicDbOptions.d.ts +0 -7
- package/dist/modules/elysia/dbResolver/types/index.d.ts +0 -1
- package/dist/modules/elysia/jwt/enums/index.d.ts +0 -1
- package/dist/modules/elysia/jwt/enums/index.js +0 -7
- package/dist/modules/elysia/jwt/enums/jwtErrorKeys.d.ts +0 -4
- package/dist/modules/elysia/jwt/index.d.ts +0 -1
- package/dist/modules/elysia/jwt/index.js +0 -77
- package/dist/modules/elysia/jwt/jwt.d.ts +0 -119
- package/dist/modules/elysia/jwt/types/index.d.ts +0 -1
- package/dist/modules/elysia/jwt/types/jwtOptions.d.ts +0 -98
- package/dist/modules/elysia/rateLimit/enums/index.d.ts +0 -1
- package/dist/modules/elysia/rateLimit/index.d.ts +0 -1
- package/dist/modules/elysia/rateLimit/index.js +0 -139
- package/dist/modules/elysia/rateLimit/stores/memoryStore.d.ts +0 -47
- package/dist/modules/elysia/rateLimit/types/index.d.ts +0 -1
- package/dist/modules/elysia/rateLimit/types/rateLimitStore.d.ts +0 -21
- package/dist/modules/logger/enums/loggerErrorKeys.d.ts +0 -6
- package/dist/modules/logger/events/loggerEvents.d.ts +0 -11
- package/dist/modules/logger/strategies/consoleLogger.d.ts +0 -22
- package/dist/modules/logger/strategies/fileLogger.d.ts +0 -25
- package/dist/modules/logger/strategies/index.d.ts +0 -2
- package/dist/modules/logger/types/bodiesIntersection.d.ts +0 -2
- package/dist/modules/logger/types/logStreamChunk.d.ts +0 -15
- package/dist/modules/logger/types/strategyBody.d.ts +0 -2
- package/dist/modules/logger/types/strategyMap.d.ts +0 -2
- package/dist/modules/singletonManager/enums/index.d.ts +0 -1
- package/dist/modules/singletonManager/enums/singletonManagerErrorKeys.d.ts +0 -4
- package/dist/modules/singletonManager/index.d.ts +0 -1
- package/dist/modules/singletonManager/index.js +0 -9
- package/dist/modules/typedEventEmitter/index.d.ts +0 -1
- package/dist/modules/typedEventEmitter/typedEventEmitter.d.ts +0 -221
- package/dist/modules/typedEventEmitter/types/index.d.ts +0 -1
- package/dist/modules/typedEventEmitter/types/index.js +0 -1
- package/dist/utils/enums/index.d.ts +0 -1
- package/dist/utils/types/index.d.ts +0 -2
- package/dist/utils/types/index.js +0 -1
- package/dist/errors/enums/{httpErrorStatusCodes.d.ts → http-status-codes.d.ts} +0 -0
- package/dist/modules/data/enums/{dataErrorKeys.d.ts → data-error-keys.d.ts} +0 -0
- package/dist/modules/data/types/{camelCase.d.ts → camel-case.d.ts} +0 -0
- package/dist/modules/data/types/{caseTransformer.d.ts → case-transformer.d.ts} +0 -0
- package/dist/modules/data/types/{kebabCase.d.ts → kebab-case.d.ts} +0 -0
- package/dist/modules/data/types/{snakeCase.d.ts → snake-case.d.ts} +0 -0
- package/dist/modules/database/enums/{databaseErrorKeys.d.ts → database-error-keys.d.ts} +15 -15
- package/dist/modules/database/enums/{mssqlErrorCode.d.ts → mssql-error-code.d.ts} +12 -12
- package/dist/modules/database/types/{mssqlDatabaseOption.d.ts → mssql-database-option.d.ts} +0 -0
- package/dist/modules/database/types/{mssqlEventLog.d.ts → mssql-event-log.d.ts} +0 -0
- package/dist/modules/database/types/{queryContext.d.ts → query-context.d.ts} +0 -0
- package/dist/{errors → modules/elysia/cache}/types/index.js +0 -0
- package/dist/modules/elysia/{crudSchema/types/crudSchemaOperations.d.ts → crud/types/crud-schema-operations.d.ts} +0 -0
- package/dist/modules/elysia/{rateLimit/enums/rateLimitErrorKeys.d.ts → rate-limit/enums/rate-limit-error-keys.d.ts} +0 -0
- package/dist/modules/elysia/{crudSchema → rate-limit}/types/index.js +0 -0
- package/dist/modules/{elysia/dbResolver → kv-store}/types/index.js +0 -0
- package/dist/modules/logger/types/{logLevels.d.ts → log-levels.d.ts} +0 -0
- package/dist/modules/mailer/enums/{mailerErrorKeys.d.ts → mailer-error-keys.d.ts} +1 -1
- package/dist/modules/mailer/types/{smtpCredentials.d.ts → smtp-credentials.d.ts} +0 -0
- package/dist/modules/mailer/types/{smtpPoolOptions.d.ts → smtp-pool-options.d.ts} +0 -0
- package/dist/modules/repository/types/{adaptiveWhereClause.d.ts → adaptive-where-clause.d.ts} +0 -0
- package/dist/modules/repository/types/{orderByItem.d.ts → order-by-item.d.ts} +0 -0
- package/dist/modules/repository/types/{selectedFields.d.ts → selected-fields.d.ts} +0 -0
- package/dist/modules/totp/enums/{totpErrorKeys.d.ts → totp-error-keys.d.ts} +2 -2
- /package/dist/modules/totp/types/{otpAuthUri.d.ts → otp-auth-uri.d.ts} +0 -0
- /package/dist/modules/totp/types/{totpOptions.d.ts → totp-options.d.ts} +0 -0
- /package/dist/modules/totp/utils/{createCounterBuffer.d.ts → create-counter-buffer.d.ts} +0 -0
- /package/dist/modules/totp/utils/{dynamicTruncation.d.ts → dynamic-truncation.d.ts} +0 -0
- /package/dist/modules/totp/utils/{generateHmac.d.ts → generate-hmac.d.ts} +0 -0
- /package/dist/modules/totp/utils/{generateSecretBytes.d.ts → generate-secret-bytes.d.ts} +0 -0
- /package/dist/modules/{typedEventEmitter/types/eventMap.d.ts → typed-event-emitter/types/event-map.d.ts} +0 -0
- /package/dist/modules/{elysia/jwt → typed-event-emitter}/types/index.js +0 -0
- /package/dist/{utils/enums/utilsErrorKeys.d.ts → shared/enums/utils-error-keys.d.ts} +0 -0
- /package/dist/{modules/elysia/rateLimit → shared}/types/index.js +0 -0
- /package/dist/{utils/types/renameKey.d.ts → shared/types/rename-key.d.ts} +0 -0
- /package/dist/{utils/types/streamWithAsyncIterable.d.ts → shared/types/stream-with-async-iterable.d.ts} +0 -0
- /package/dist/{utils → shared/utils}/env.d.ts +0 -0
- /package/dist/{utils/isDateString.d.ts → shared/utils/is-date-string.d.ts} +0 -0
- /package/dist/{utils → shared/utils}/stream.d.ts +0 -0
|
@@ -33,6 +33,7 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
33
33
|
macro: {};
|
|
34
34
|
macroFn: {};
|
|
35
35
|
parser: {};
|
|
36
|
+
response: {};
|
|
36
37
|
}, {
|
|
37
38
|
microservice: {
|
|
38
39
|
ping: {
|
|
@@ -42,9 +43,6 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
42
43
|
query: unknown;
|
|
43
44
|
headers: unknown;
|
|
44
45
|
response: {
|
|
45
|
-
200: {
|
|
46
|
-
message: string;
|
|
47
|
-
};
|
|
48
46
|
422: {
|
|
49
47
|
type: "validation";
|
|
50
48
|
on: string;
|
|
@@ -54,6 +52,9 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
54
52
|
property?: string;
|
|
55
53
|
expected?: string;
|
|
56
54
|
};
|
|
55
|
+
200: {
|
|
56
|
+
message: string;
|
|
57
|
+
};
|
|
57
58
|
};
|
|
58
59
|
};
|
|
59
60
|
};
|
|
@@ -67,15 +68,6 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
67
68
|
query: unknown;
|
|
68
69
|
headers: unknown;
|
|
69
70
|
response: {
|
|
70
|
-
200: {
|
|
71
|
-
message: string;
|
|
72
|
-
content: {
|
|
73
|
-
description: string;
|
|
74
|
-
version: string;
|
|
75
|
-
name: string;
|
|
76
|
-
author: string;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
71
|
422: {
|
|
80
72
|
type: "validation";
|
|
81
73
|
on: string;
|
|
@@ -85,6 +77,15 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
85
77
|
property?: string;
|
|
86
78
|
expected?: string;
|
|
87
79
|
};
|
|
80
|
+
200: {
|
|
81
|
+
message: string;
|
|
82
|
+
content: {
|
|
83
|
+
description: string;
|
|
84
|
+
version: string;
|
|
85
|
+
name: string;
|
|
86
|
+
author: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
88
89
|
};
|
|
89
90
|
};
|
|
90
91
|
};
|
|
@@ -92,11 +93,13 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
92
93
|
}, {
|
|
93
94
|
derive: {};
|
|
94
95
|
resolve: {};
|
|
95
|
-
schema:
|
|
96
|
-
standaloneSchema:
|
|
96
|
+
schema: {};
|
|
97
|
+
standaloneSchema: {};
|
|
98
|
+
response: {};
|
|
97
99
|
}, {
|
|
98
100
|
derive: {};
|
|
99
101
|
resolve: {};
|
|
100
102
|
schema: {};
|
|
101
103
|
standaloneSchema: {};
|
|
104
|
+
response: {};
|
|
102
105
|
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RATE_LIMIT_ERROR_KEYS } from './rate-limit-error-keys';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { rateLimit } from './rate-limit';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
RATE_LIMIT_ERROR_KEYS
|
|
4
|
+
} from "../../../chunk-w1547qd4.js";
|
|
5
|
+
import {
|
|
6
|
+
MemoryStore
|
|
7
|
+
} from "../../../chunk-k9dtqf1p.js";
|
|
8
|
+
import"../../../chunk-6tqh339a.js";
|
|
9
|
+
import {
|
|
10
|
+
HttpError
|
|
11
|
+
} from "../../../chunk-00s6t4tw.js";
|
|
12
|
+
import"../../../chunk-h9t48r9q.js";
|
|
13
|
+
import"../../../chunk-9cgzhc50.js";
|
|
14
|
+
|
|
15
|
+
// source/modules/elysia/rate-limit/rate-limit.ts
|
|
16
|
+
import { Elysia } from "elysia";
|
|
17
|
+
var rateLimit = ({ store, limit, window }) => {
|
|
18
|
+
const storeInstance = store === ":memory:" || !store ? new MemoryStore : store;
|
|
19
|
+
return new Elysia({
|
|
20
|
+
name: "rateLimit",
|
|
21
|
+
seed: {
|
|
22
|
+
store,
|
|
23
|
+
limit,
|
|
24
|
+
window
|
|
25
|
+
}
|
|
26
|
+
}).onRequest(async ({ set, request, server }) => {
|
|
27
|
+
const ip = request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || server?.requestIP(request)?.address || "127.0.0.1";
|
|
28
|
+
const key = `ratelimit:${ip}`;
|
|
29
|
+
const count = await storeInstance.get(key);
|
|
30
|
+
let newCount;
|
|
31
|
+
if (count === null) {
|
|
32
|
+
await storeInstance.set(key, 1, window);
|
|
33
|
+
newCount = 1;
|
|
34
|
+
} else {
|
|
35
|
+
newCount = await storeInstance.increment(key);
|
|
36
|
+
}
|
|
37
|
+
if (newCount > limit) {
|
|
38
|
+
set.status = 429;
|
|
39
|
+
throw new HttpError(RATE_LIMIT_ERROR_KEYS.RATE_LIMIT_EXCEEDED, "TOO_MANY_REQUESTS", {
|
|
40
|
+
limit,
|
|
41
|
+
window,
|
|
42
|
+
remaining: 0,
|
|
43
|
+
reset: await storeInstance.ttl(key)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
set.headers = {
|
|
47
|
+
"X-RateLimit-Limit": limit.toString(),
|
|
48
|
+
"X-RateLimit-Remaining": Math.max(0, limit - newCount).toString(),
|
|
49
|
+
"X-RateLimit-Reset": (await storeInstance.ttl(key)).toString()
|
|
50
|
+
};
|
|
51
|
+
}).as("global");
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
rateLimit
|
|
55
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import type { RateLimitOptions } from './types/
|
|
2
|
+
import type { RateLimitOptions } from './types/rate-limit-options';
|
|
3
3
|
/**
|
|
4
4
|
* The `rateLimitPlugin` provides rate limiting capabilities for Elysia applications,
|
|
5
5
|
* protecting APIs from excessive use and potential abuse. It tracks request rates by client IP
|
|
@@ -16,26 +16,43 @@ import type { RateLimitOptions } from './types/rateLimitOptions';
|
|
|
16
16
|
* @returns An {@link Elysia} plugin that adds rate limiting functionality
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
+
* Basic usage with default in-memory store
|
|
19
20
|
* ```ts
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* import { rateLimit } from '@nowarajs/elysia-ratelimit';
|
|
22
|
+
* import { Elysia } from 'elysia';
|
|
23
|
+
*
|
|
24
|
+
* const app = new Elysia()
|
|
25
|
+
* .use(rateLimit({
|
|
26
|
+
* store: ':memory:', // Use in-memory store
|
|
27
|
+
* limit: 100, // 100 requests
|
|
28
|
+
* window: 60, // per minute
|
|
29
|
+
* }))
|
|
30
|
+
* .get('/api/endpoint', () => ({ message: 'Hello World' }));
|
|
31
|
+
*
|
|
32
|
+
* app.listen(3000);
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Using Redis store for distributed rate limiting
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { IoRedisStore } from '@nowarajs/kv-store';
|
|
39
|
+
* import { rateLimit } from '@nowarajs/elysia-ratelimit';
|
|
40
|
+
* import { Elysia } from 'elysia';
|
|
41
|
+
*
|
|
42
|
+
* const redisStore = new IoRedisStore({
|
|
22
43
|
* host: 'localhost',
|
|
23
44
|
* port: 6379
|
|
24
45
|
* });
|
|
25
|
-
* await
|
|
46
|
+
* await redisStore.connect();
|
|
26
47
|
*
|
|
27
|
-
* // Create and configure the application with rate limiting
|
|
28
48
|
* const app = new Elysia()
|
|
29
49
|
* .use(rateLimit({
|
|
30
|
-
* store:
|
|
31
|
-
* limit:
|
|
32
|
-
* window:
|
|
50
|
+
* store: redisStore,
|
|
51
|
+
* limit: 1000, // 1000 requests
|
|
52
|
+
* window: 3600, // per hour
|
|
33
53
|
* }))
|
|
34
|
-
* .get('/
|
|
35
|
-
* return { success: true, message: 'This endpoint is rate limited' };
|
|
36
|
-
* });
|
|
54
|
+
* .get('/api/endpoint', () => ({ message: 'Hello World' }));
|
|
37
55
|
*
|
|
38
|
-
* // Start the server
|
|
39
56
|
* app.listen(3000);
|
|
40
57
|
* ```
|
|
41
58
|
*/
|
|
@@ -48,19 +65,22 @@ export declare const rateLimit: ({ store, limit, window }: RateLimitOptions) =>
|
|
|
48
65
|
typebox: {};
|
|
49
66
|
error: {};
|
|
50
67
|
}, {
|
|
51
|
-
schema:
|
|
68
|
+
schema: {};
|
|
52
69
|
standaloneSchema: {};
|
|
53
70
|
macro: {};
|
|
54
71
|
macroFn: {};
|
|
55
72
|
parser: {};
|
|
73
|
+
response: {};
|
|
56
74
|
}, {}, {
|
|
57
75
|
derive: {};
|
|
58
76
|
resolve: {};
|
|
59
77
|
schema: {};
|
|
60
78
|
standaloneSchema: {};
|
|
79
|
+
response: {};
|
|
61
80
|
}, {
|
|
62
81
|
derive: {};
|
|
63
82
|
resolve: {};
|
|
64
83
|
schema: {};
|
|
65
84
|
standaloneSchema: {};
|
|
85
|
+
response: {};
|
|
66
86
|
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { RateLimitOptions } from './rate-limit-options';
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* Options to configure the rate limit plugin.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const options: RateLimitOptions = {
|
|
8
|
-
* store: redisInstance, // Your Redis instance
|
|
9
|
-
* limit: 100, // Allow 100 requests
|
|
10
|
-
* window: 60, // Per 60 seconds
|
|
11
|
-
* };
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
1
|
+
import type { KvStore } from '../../../../modules/kv-store/types/kv-store';
|
|
14
2
|
export interface RateLimitOptions {
|
|
15
3
|
/**
|
|
16
4
|
* Storage backend for rate limit data.
|
|
17
5
|
*
|
|
18
6
|
* - If not specified, defaults to in-memory storage
|
|
19
7
|
* - Use ':memory:' to explicitly specify in-memory storage
|
|
20
|
-
* - Provide a
|
|
8
|
+
* - Provide a KvStore instance for persistent distributed storage
|
|
21
9
|
*/
|
|
22
|
-
readonly store?: ':memory:' |
|
|
10
|
+
readonly store?: ':memory:' | KvStore;
|
|
23
11
|
/**
|
|
24
12
|
* Maximum number of requests allowed in the time window.
|
|
25
13
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { signJWT, verifyJWT } from './jwt';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
JWT_ERROR_KEYS
|
|
4
|
+
} from "../../chunk-yagxbm1r.js";
|
|
5
|
+
import {
|
|
6
|
+
parseHumanTimeToSeconds
|
|
7
|
+
} from "../../chunk-zwrygafm.js";
|
|
8
|
+
import"../../chunk-0601exyg.js";
|
|
9
|
+
import {
|
|
10
|
+
HttpError
|
|
11
|
+
} from "../../chunk-00s6t4tw.js";
|
|
12
|
+
import"../../chunk-h9t48r9q.js";
|
|
13
|
+
import"../../chunk-9cgzhc50.js";
|
|
14
|
+
|
|
15
|
+
// source/modules/jwt/jwt.ts
|
|
16
|
+
import {
|
|
17
|
+
SignJWT,
|
|
18
|
+
jwtVerify
|
|
19
|
+
} from "jose";
|
|
20
|
+
var signJWT = (secret, payload, expiration = Math.floor(Date.now() / 1000) + 60 * 15) => {
|
|
21
|
+
const exp = expiration instanceof Date ? Math.floor(expiration.getTime() / 1000) : typeof expiration === "number" ? expiration : parseHumanTimeToSeconds(expiration);
|
|
22
|
+
if (exp <= Math.floor(Date.now() / 1000))
|
|
23
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_EXPIRATION_PASSED, "BAD_REQUEST");
|
|
24
|
+
const finalPayload = {
|
|
25
|
+
iss: "Core-Issuer",
|
|
26
|
+
sub: "",
|
|
27
|
+
aud: ["Core-Audience"],
|
|
28
|
+
jti: Bun.randomUUIDv7(),
|
|
29
|
+
nbf: Math.floor(Date.now() / 1000),
|
|
30
|
+
iat: Math.floor(Date.now() / 1000),
|
|
31
|
+
exp,
|
|
32
|
+
...payload
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
const jwt = new SignJWT(finalPayload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuer(finalPayload.iss).setSubject(finalPayload.sub).setAudience(finalPayload.aud).setJti(finalPayload.jti).setNotBefore(finalPayload.nbf).setIssuedAt(finalPayload.iat).setExpirationTime(expiration).sign(new TextEncoder().encode(secret));
|
|
36
|
+
return jwt;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_SIGN_ERROR, "INTERNAL_SERVER_ERROR", error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var verifyJWT = async (token, secret) => {
|
|
42
|
+
try {
|
|
43
|
+
return await jwtVerify(token, new TextEncoder().encode(secret));
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
verifyJWT,
|
|
50
|
+
signJWT
|
|
51
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type JWTPayload, type JWTVerifyResult } from 'jose';
|
|
2
|
+
export declare const signJWT: (secret: string, payload: JWTPayload, expiration?: number | string | Date) => Promise<string>;
|
|
3
|
+
export declare const verifyJWT: (token: string, secret: string) => Promise<JWTVerifyResult | false>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseHumanTimeToSeconds } from './parse-human-time-to-seconds';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a human-readable time expression to seconds
|
|
3
|
+
*
|
|
4
|
+
* @param timeExpression - A string representing a time period (e.g., "2 hours", "30 minutes ago", "+1 day")
|
|
5
|
+
*
|
|
6
|
+
* @throws ({@link BaseError}) - If the time expression is invalid or contains an unknown unit
|
|
7
|
+
*
|
|
8
|
+
* @returns The time period in seconds (negative for past times)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* parseHumanTimeToSeconds("2 hours") // Returns 7200
|
|
13
|
+
* parseHumanTimeToSeconds("30 mins ago") // Returns -1800
|
|
14
|
+
* parseHumanTimeToSeconds("+1 day") // Returns 86400
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const parseHumanTimeToSeconds: (timeExpression: string) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { KV_STORE_ERROR_KEYS } from './kv-store-error-keys';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IoRedisStore } from './ioredis-store';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
KV_STORE_ERROR_KEYS
|
|
4
|
+
} from "../../../chunk-6tqh339a.js";
|
|
5
|
+
import {
|
|
6
|
+
BaseError
|
|
7
|
+
} from "../../../chunk-9cgzhc50.js";
|
|
8
|
+
|
|
9
|
+
// source/modules/kv-store/ioredis/ioredis-store.ts
|
|
10
|
+
import { Redis } from "ioredis";
|
|
11
|
+
class IoRedisStore {
|
|
12
|
+
_client;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this._client = new Redis({
|
|
15
|
+
...options,
|
|
16
|
+
lazyConnect: true
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async connect() {
|
|
20
|
+
try {
|
|
21
|
+
await this._client.connect();
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.CONNECTION_FAILED, e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async close() {
|
|
27
|
+
try {
|
|
28
|
+
await this._client.quit();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.CLOSING_CONNECTION_FAILED, e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async get(key) {
|
|
34
|
+
const value = await this._client.get(key);
|
|
35
|
+
if (value === null)
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(value);
|
|
39
|
+
} catch {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async set(key, value, ttlSec) {
|
|
44
|
+
const serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
45
|
+
if (ttlSec)
|
|
46
|
+
await this._client.setex(key, ttlSec, serialized);
|
|
47
|
+
else
|
|
48
|
+
await this._client.set(key, serialized);
|
|
49
|
+
}
|
|
50
|
+
async increment(key, amount = 1) {
|
|
51
|
+
const current = await this._client.get(key);
|
|
52
|
+
if (current !== null) {
|
|
53
|
+
const parsed = Number(current);
|
|
54
|
+
if (Number.isNaN(parsed))
|
|
55
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
56
|
+
}
|
|
57
|
+
if (amount === 1)
|
|
58
|
+
return this._client.incr(key);
|
|
59
|
+
return this._client.incrby(key, amount);
|
|
60
|
+
}
|
|
61
|
+
async decrement(key, amount = 1) {
|
|
62
|
+
const current = await this._client.get(key);
|
|
63
|
+
if (current !== null) {
|
|
64
|
+
const parsed = Number(current);
|
|
65
|
+
if (Number.isNaN(parsed))
|
|
66
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
67
|
+
}
|
|
68
|
+
if (amount === 1)
|
|
69
|
+
return this._client.decr(key);
|
|
70
|
+
return this._client.decrby(key, amount);
|
|
71
|
+
}
|
|
72
|
+
async del(key) {
|
|
73
|
+
const result = await this._client.del(key);
|
|
74
|
+
return result === 1;
|
|
75
|
+
}
|
|
76
|
+
async expire(key, ttlSec) {
|
|
77
|
+
const result = await this._client.expire(key, ttlSec);
|
|
78
|
+
return result === 1;
|
|
79
|
+
}
|
|
80
|
+
ttl(key) {
|
|
81
|
+
return this._client.ttl(key);
|
|
82
|
+
}
|
|
83
|
+
async clean() {
|
|
84
|
+
const keys = await this._client.keys("*");
|
|
85
|
+
if (keys.length === 0)
|
|
86
|
+
return 0;
|
|
87
|
+
return this._client.del(...keys);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
IoRedisStore
|
|
92
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type RedisOptions } from 'ioredis';
|
|
2
|
+
import type { KvStore } from '../../../modules/kv-store/types/kv-store';
|
|
3
|
+
/**
|
|
4
|
+
* Redis-based key-value store implementation using ioredis client.
|
|
5
|
+
*
|
|
6
|
+
* Provides a Redis-backed implementation of the KvStore interface with
|
|
7
|
+
* automatic JSON serialization/deserialization and proper error handling.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IoRedisStore implements KvStore {
|
|
10
|
+
/**
|
|
11
|
+
* Redis client instance.
|
|
12
|
+
*/
|
|
13
|
+
private readonly _client;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an IoRedis store instance.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Redis connection options
|
|
18
|
+
*/
|
|
19
|
+
constructor(options: RedisOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Establishes connection to Redis server.
|
|
22
|
+
*
|
|
23
|
+
* @throws ({@link BaseError}) - When connection fails
|
|
24
|
+
*/
|
|
25
|
+
connect(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Closes the Redis connection gracefully.
|
|
28
|
+
*
|
|
29
|
+
* @throws ({@link BaseError}) - When closing connection fails
|
|
30
|
+
*/
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves a value from Redis by key.
|
|
34
|
+
*
|
|
35
|
+
* @template T - The expected type of the stored value
|
|
36
|
+
*
|
|
37
|
+
* @param key - The key to retrieve
|
|
38
|
+
*
|
|
39
|
+
* @returns The value associated with the key, or null if not found or expired
|
|
40
|
+
*/
|
|
41
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Stores a value in Redis with optional TTL.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The type of the value being stored
|
|
46
|
+
*
|
|
47
|
+
* @param key - The key to store the value under
|
|
48
|
+
* @param value - The value to store
|
|
49
|
+
* @param ttlSec - Time to live in seconds (optional)
|
|
50
|
+
*/
|
|
51
|
+
set<T = unknown>(key: string, value: T, ttlSec?: number): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Increments a numeric value stored at key by the specified amount.
|
|
54
|
+
* If the key does not exist, it is set to 0 before performing the operation.
|
|
55
|
+
*
|
|
56
|
+
* @param key - The key containing the numeric value
|
|
57
|
+
* @param amount - The amount to increment by (default: 1)
|
|
58
|
+
*
|
|
59
|
+
* @throws ({@link BaseError}) - When the value is not a valid integer
|
|
60
|
+
*
|
|
61
|
+
* @returns The value after incrementing
|
|
62
|
+
*/
|
|
63
|
+
increment(key: string, amount?: number): Promise<number>;
|
|
64
|
+
/**
|
|
65
|
+
* Decrements a numeric value stored at key by the specified amount.
|
|
66
|
+
* If the key does not exist, it is set to 0 before performing the operation.
|
|
67
|
+
*
|
|
68
|
+
* @param key - The key containing the numeric value
|
|
69
|
+
* @param amount - The amount to decrement by (default: 1)
|
|
70
|
+
*
|
|
71
|
+
* @throws ({@link BaseError}) - When the value is not a valid integer
|
|
72
|
+
*
|
|
73
|
+
* @returns The value after decrementing
|
|
74
|
+
*/
|
|
75
|
+
decrement(key: string, amount?: number): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Deletes a key from Redis.
|
|
78
|
+
*
|
|
79
|
+
* @param key - The key to delete
|
|
80
|
+
*
|
|
81
|
+
* @returns True if the key was deleted, false if it did not exist
|
|
82
|
+
*/
|
|
83
|
+
del(key: string): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Sets an expiration time for a key.
|
|
86
|
+
*
|
|
87
|
+
* @param key - The key to set expiration for
|
|
88
|
+
* @param ttlSec - Time to live in seconds
|
|
89
|
+
*
|
|
90
|
+
* @returns True if the expiration was set, false if the key does not exist
|
|
91
|
+
*/
|
|
92
|
+
expire(key: string, ttlSec: number): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the remaining time to live for a key.
|
|
95
|
+
*
|
|
96
|
+
* @param key - The key to check
|
|
97
|
+
*
|
|
98
|
+
* @returns Time to live in seconds, -1 if key has no expiration, -2 if key does not exist
|
|
99
|
+
*/
|
|
100
|
+
ttl(key: string): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Removes all keys from the Redis database.
|
|
103
|
+
*
|
|
104
|
+
* @returns The number of keys that were deleted
|
|
105
|
+
*/
|
|
106
|
+
clean(): Promise<number>;
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MemoryStore } from './memory-store';
|