blendsdk 5.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/cmdline/cmdline.d.ts +144 -0
- package/dist/cmdline/cmdline.d.ts.map +1 -0
- package/dist/cmdline/cmdline.js +683 -0
- package/dist/cmdline/cmdline.js.map +1 -0
- package/dist/cmdline/errors.d.ts +105 -0
- package/dist/cmdline/errors.d.ts.map +1 -0
- package/dist/cmdline/errors.js +153 -0
- package/dist/cmdline/errors.js.map +1 -0
- package/dist/cmdline/index.d.ts +5 -0
- package/dist/cmdline/index.d.ts.map +1 -0
- package/dist/cmdline/index.js +5 -0
- package/dist/cmdline/index.js.map +1 -0
- package/dist/cmdline/types.d.ts +260 -0
- package/dist/cmdline/types.d.ts.map +1 -0
- package/dist/cmdline/types.js +9 -0
- package/dist/cmdline/types.js.map +1 -0
- package/dist/cmdline/validators.d.ts +28 -0
- package/dist/cmdline/validators.d.ts.map +1 -0
- package/dist/cmdline/validators.js +211 -0
- package/dist/cmdline/validators.js.map +1 -0
- package/dist/codegen/database/index.d.ts +3 -0
- package/dist/codegen/database/index.d.ts.map +1 -0
- package/dist/codegen/database/index.js +3 -0
- package/dist/codegen/database/index.js.map +1 -0
- package/dist/codegen/database/introspect/index.d.ts +3 -0
- package/dist/codegen/database/introspect/index.d.ts.map +1 -0
- package/dist/codegen/database/introspect/index.js +3 -0
- package/dist/codegen/database/introspect/index.js.map +1 -0
- package/dist/codegen/database/introspect/introspect-query.d.ts +2 -0
- package/dist/codegen/database/introspect/introspect-query.d.ts.map +1 -0
- package/dist/codegen/database/introspect/introspect-query.js +416 -0
- package/dist/codegen/database/introspect/introspect-query.js.map +1 -0
- package/dist/codegen/database/introspect/introspect-types.d.ts +45 -0
- package/dist/codegen/database/introspect/introspect-types.d.ts.map +1 -0
- package/dist/codegen/database/introspect/introspect-types.js +2 -0
- package/dist/codegen/database/introspect/introspect-types.js.map +1 -0
- package/dist/codegen/database/introspect/introspect.d.ts +21 -0
- package/dist/codegen/database/introspect/introspect.d.ts.map +1 -0
- package/dist/codegen/database/introspect/introspect.js +223 -0
- package/dist/codegen/database/introspect/introspect.js.map +1 -0
- package/dist/codegen/database/schema/check-constraint.d.ts +8 -0
- package/dist/codegen/database/schema/check-constraint.d.ts.map +1 -0
- package/dist/codegen/database/schema/check-constraint.js +12 -0
- package/dist/codegen/database/schema/check-constraint.js.map +1 -0
- package/dist/codegen/database/schema/column-schema.d.ts +7 -0
- package/dist/codegen/database/schema/column-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/column-schema.js +9 -0
- package/dist/codegen/database/schema/column-schema.js.map +1 -0
- package/dist/codegen/database/schema/constraint-base.d.ts +13 -0
- package/dist/codegen/database/schema/constraint-base.d.ts.map +1 -0
- package/dist/codegen/database/schema/constraint-base.js +32 -0
- package/dist/codegen/database/schema/constraint-base.js.map +1 -0
- package/dist/codegen/database/schema/database-schema.d.ts +19 -0
- package/dist/codegen/database/schema/database-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/database-schema.js +48 -0
- package/dist/codegen/database/schema/database-schema.js.map +1 -0
- package/dist/codegen/database/schema/dataobject-schema.d.ts +9 -0
- package/dist/codegen/database/schema/dataobject-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/dataobject-schema.js +18 -0
- package/dist/codegen/database/schema/dataobject-schema.js.map +1 -0
- package/dist/codegen/database/schema/fkey-constraints.d.ts +21 -0
- package/dist/codegen/database/schema/fkey-constraints.d.ts.map +1 -0
- package/dist/codegen/database/schema/fkey-constraints.js +58 -0
- package/dist/codegen/database/schema/fkey-constraints.js.map +1 -0
- package/dist/codegen/database/schema/index-constraint.d.ts +34 -0
- package/dist/codegen/database/schema/index-constraint.d.ts.map +1 -0
- package/dist/codegen/database/schema/index-constraint.js +79 -0
- package/dist/codegen/database/schema/index-constraint.js.map +1 -0
- package/dist/codegen/database/schema/index.d.ts +5 -0
- package/dist/codegen/database/schema/index.d.ts.map +1 -0
- package/dist/codegen/database/schema/index.js +5 -0
- package/dist/codegen/database/schema/index.js.map +1 -0
- package/dist/codegen/database/schema/primarykey-constraint.d.ts +4 -0
- package/dist/codegen/database/schema/primarykey-constraint.d.ts.map +1 -0
- package/dist/codegen/database/schema/primarykey-constraint.js +4 -0
- package/dist/codegen/database/schema/primarykey-constraint.js.map +1 -0
- package/dist/codegen/database/schema/relation-schema.d.ts +16 -0
- package/dist/codegen/database/schema/relation-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/relation-schema.js +32 -0
- package/dist/codegen/database/schema/relation-schema.js.map +1 -0
- package/dist/codegen/database/schema/table-column-schema.d.ts +59 -0
- package/dist/codegen/database/schema/table-column-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/table-column-schema.js +137 -0
- package/dist/codegen/database/schema/table-column-schema.js.map +1 -0
- package/dist/codegen/database/schema/table-schema.d.ts +48 -0
- package/dist/codegen/database/schema/table-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/table-schema.js +219 -0
- package/dist/codegen/database/schema/table-schema.js.map +1 -0
- package/dist/codegen/database/schema/types.d.ts +13 -0
- package/dist/codegen/database/schema/types.d.ts.map +1 -0
- package/dist/codegen/database/schema/types.js +175 -0
- package/dist/codegen/database/schema/types.js.map +1 -0
- package/dist/codegen/database/schema/unique-constraint.d.ts +4 -0
- package/dist/codegen/database/schema/unique-constraint.d.ts.map +1 -0
- package/dist/codegen/database/schema/unique-constraint.js +4 -0
- package/dist/codegen/database/schema/unique-constraint.js.map +1 -0
- package/dist/codegen/database/schema/view-schema.d.ts +14 -0
- package/dist/codegen/database/schema/view-schema.d.ts.map +1 -0
- package/dist/codegen/database/schema/view-schema.js +32 -0
- package/dist/codegen/database/schema/view-schema.js.map +1 -0
- package/dist/codegen/generator/ctype-generator.d.ts +5 -0
- package/dist/codegen/generator/ctype-generator.d.ts.map +1 -0
- package/dist/codegen/generator/ctype-generator.js +26 -0
- package/dist/codegen/generator/ctype-generator.js.map +1 -0
- package/dist/codegen/generator/generator.d.ts +17 -0
- package/dist/codegen/generator/generator.d.ts.map +1 -0
- package/dist/codegen/generator/generator.js +57 -0
- package/dist/codegen/generator/generator.js.map +1 -0
- package/dist/codegen/generator/index.d.ts +8 -0
- package/dist/codegen/generator/index.d.ts.map +1 -0
- package/dist/codegen/generator/index.js +8 -0
- package/dist/codegen/generator/index.js.map +1 -0
- package/dist/codegen/generator/openapi-generator.d.ts +239 -0
- package/dist/codegen/generator/openapi-generator.d.ts.map +1 -0
- package/dist/codegen/generator/openapi-generator.js +434 -0
- package/dist/codegen/generator/openapi-generator.js.map +1 -0
- package/dist/codegen/generator/openapi-types.d.ts +263 -0
- package/dist/codegen/generator/openapi-types.d.ts.map +1 -0
- package/dist/codegen/generator/openapi-types.js +11 -0
- package/dist/codegen/generator/openapi-types.js.map +1 -0
- package/dist/codegen/generator/postgres-schema-generator.d.ts +48 -0
- package/dist/codegen/generator/postgres-schema-generator.d.ts.map +1 -0
- package/dist/codegen/generator/postgres-schema-generator.js +339 -0
- package/dist/codegen/generator/postgres-schema-generator.js.map +1 -0
- package/dist/codegen/generator/type-generator.d.ts +113 -0
- package/dist/codegen/generator/type-generator.d.ts.map +1 -0
- package/dist/codegen/generator/type-generator.js +249 -0
- package/dist/codegen/generator/type-generator.js.map +1 -0
- package/dist/codegen/generator/zod-generator.d.ts +15 -0
- package/dist/codegen/generator/zod-generator.d.ts.map +1 -0
- package/dist/codegen/generator/zod-generator.js +86 -0
- package/dist/codegen/generator/zod-generator.js.map +1 -0
- package/dist/codegen/generator/zod-to-openapi.d.ts +69 -0
- package/dist/codegen/generator/zod-to-openapi.d.ts.map +1 -0
- package/dist/codegen/generator/zod-to-openapi.js +480 -0
- package/dist/codegen/generator/zod-to-openapi.js.map +1 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +4 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/schema/any-schema.d.ts +6 -0
- package/dist/codegen/schema/any-schema.d.ts.map +1 -0
- package/dist/codegen/schema/any-schema.js +12 -0
- package/dist/codegen/schema/any-schema.js.map +1 -0
- package/dist/codegen/schema/boolean-schema.d.ts +6 -0
- package/dist/codegen/schema/boolean-schema.d.ts.map +1 -0
- package/dist/codegen/schema/boolean-schema.js +12 -0
- package/dist/codegen/schema/boolean-schema.js.map +1 -0
- package/dist/codegen/schema/date-schema.d.ts +6 -0
- package/dist/codegen/schema/date-schema.d.ts.map +1 -0
- package/dist/codegen/schema/date-schema.js +12 -0
- package/dist/codegen/schema/date-schema.js.map +1 -0
- package/dist/codegen/schema/index.d.ts +10 -0
- package/dist/codegen/schema/index.d.ts.map +1 -0
- package/dist/codegen/schema/index.js +10 -0
- package/dist/codegen/schema/index.js.map +1 -0
- package/dist/codegen/schema/object-schema.d.ts +10 -0
- package/dist/codegen/schema/object-schema.d.ts.map +1 -0
- package/dist/codegen/schema/object-schema.js +21 -0
- package/dist/codegen/schema/object-schema.js.map +1 -0
- package/dist/codegen/schema/primitive-schema.d.ts +20 -0
- package/dist/codegen/schema/primitive-schema.d.ts.map +1 -0
- package/dist/codegen/schema/primitive-schema.js +48 -0
- package/dist/codegen/schema/primitive-schema.js.map +1 -0
- package/dist/codegen/schema/ref-schema.d.ts +6 -0
- package/dist/codegen/schema/ref-schema.d.ts.map +1 -0
- package/dist/codegen/schema/ref-schema.js +11 -0
- package/dist/codegen/schema/ref-schema.js.map +1 -0
- package/dist/codegen/schema/schema-container.d.ts +14 -0
- package/dist/codegen/schema/schema-container.d.ts.map +1 -0
- package/dist/codegen/schema/schema-container.js +38 -0
- package/dist/codegen/schema/schema-container.js.map +1 -0
- package/dist/codegen/schema/schema-object.d.ts +42 -0
- package/dist/codegen/schema/schema-object.d.ts.map +1 -0
- package/dist/codegen/schema/schema-object.js +90 -0
- package/dist/codegen/schema/schema-object.js.map +1 -0
- package/dist/codegen/schema/schema-scope.d.ts +23 -0
- package/dist/codegen/schema/schema-scope.d.ts.map +1 -0
- package/dist/codegen/schema/schema-scope.js +67 -0
- package/dist/codegen/schema/schema-scope.js.map +1 -0
- package/dist/codegen/schema/utils.d.ts +17 -0
- package/dist/codegen/schema/utils.d.ts.map +1 -0
- package/dist/codegen/schema/utils.js +47 -0
- package/dist/codegen/schema/utils.js.map +1 -0
- package/dist/dbcore/crud-statement.d.ts +67 -0
- package/dist/dbcore/crud-statement.d.ts.map +1 -0
- package/dist/dbcore/crud-statement.js +75 -0
- package/dist/dbcore/crud-statement.js.map +1 -0
- package/dist/dbcore/database.d.ts +272 -0
- package/dist/dbcore/database.d.ts.map +1 -0
- package/dist/dbcore/database.js +53 -0
- package/dist/dbcore/database.js.map +1 -0
- package/dist/dbcore/dataservice-base.d.ts +18 -0
- package/dist/dbcore/dataservice-base.d.ts.map +1 -0
- package/dist/dbcore/dataservice-base.js +19 -0
- package/dist/dbcore/dataservice-base.js.map +1 -0
- package/dist/dbcore/delete-statement.d.ts +29 -0
- package/dist/dbcore/delete-statement.d.ts.map +1 -0
- package/dist/dbcore/delete-statement.js +30 -0
- package/dist/dbcore/delete-statement.js.map +1 -0
- package/dist/dbcore/filterable-statement.d.ts +126 -0
- package/dist/dbcore/filterable-statement.d.ts.map +1 -0
- package/dist/dbcore/filterable-statement.js +178 -0
- package/dist/dbcore/filterable-statement.js.map +1 -0
- package/dist/dbcore/from-statement.d.ts +120 -0
- package/dist/dbcore/from-statement.d.ts.map +1 -0
- package/dist/dbcore/from-statement.js +150 -0
- package/dist/dbcore/from-statement.js.map +1 -0
- package/dist/dbcore/index.d.ts +21 -0
- package/dist/dbcore/index.d.ts.map +1 -0
- package/dist/dbcore/index.js +21 -0
- package/dist/dbcore/index.js.map +1 -0
- package/dist/dbcore/insert-statement.d.ts +48 -0
- package/dist/dbcore/insert-statement.d.ts.map +1 -0
- package/dist/dbcore/insert-statement.js +52 -0
- package/dist/dbcore/insert-statement.js.map +1 -0
- package/dist/dbcore/query-dataservice.d.ts +144 -0
- package/dist/dbcore/query-dataservice.d.ts.map +1 -0
- package/dist/dbcore/query-dataservice.js +144 -0
- package/dist/dbcore/query-dataservice.js.map +1 -0
- package/dist/dbcore/statement.d.ts +133 -0
- package/dist/dbcore/statement.d.ts.map +1 -0
- package/dist/dbcore/statement.js +138 -0
- package/dist/dbcore/statement.js.map +1 -0
- package/dist/dbcore/update-statement.d.ts +48 -0
- package/dist/dbcore/update-statement.d.ts.map +1 -0
- package/dist/dbcore/update-statement.js +52 -0
- package/dist/dbcore/update-statement.js.map +1 -0
- package/dist/expression/builders/comparison-builder.d.ts +47 -0
- package/dist/expression/builders/comparison-builder.d.ts.map +1 -0
- package/dist/expression/builders/comparison-builder.js +197 -0
- package/dist/expression/builders/comparison-builder.js.map +1 -0
- package/dist/expression/builders/query-builder.d.ts +80 -0
- package/dist/expression/builders/query-builder.d.ts.map +1 -0
- package/dist/expression/builders/query-builder.js +229 -0
- package/dist/expression/builders/query-builder.js.map +1 -0
- package/dist/expression/compiler/postgresql-compiler.d.ts +56 -0
- package/dist/expression/compiler/postgresql-compiler.d.ts.map +1 -0
- package/dist/expression/compiler/postgresql-compiler.js +217 -0
- package/dist/expression/compiler/postgresql-compiler.js.map +1 -0
- package/dist/expression/core/ast-node.d.ts +47 -0
- package/dist/expression/core/ast-node.d.ts.map +1 -0
- package/dist/expression/core/ast-node.js +154 -0
- package/dist/expression/core/ast-node.js.map +1 -0
- package/dist/expression/core/parameter-manager.d.ts +84 -0
- package/dist/expression/core/parameter-manager.d.ts.map +1 -0
- package/dist/expression/core/parameter-manager.js +164 -0
- package/dist/expression/core/parameter-manager.js.map +1 -0
- package/dist/expression/core/query-builder-interfaces.d.ts +188 -0
- package/dist/expression/core/query-builder-interfaces.d.ts.map +1 -0
- package/dist/expression/core/query-builder-interfaces.js +6 -0
- package/dist/expression/core/query-builder-interfaces.js.map +1 -0
- package/dist/expression/core/types.d.ts +239 -0
- package/dist/expression/core/types.d.ts.map +1 -0
- package/dist/expression/core/types.js +121 -0
- package/dist/expression/core/types.js.map +1 -0
- package/dist/expression/index.d.ts +11 -0
- package/dist/expression/index.d.ts.map +1 -0
- package/dist/expression/index.js +11 -0
- package/dist/expression/index.js.map +1 -0
- package/dist/i18n/content-file-source.d.ts +109 -0
- package/dist/i18n/content-file-source.d.ts.map +1 -0
- package/dist/i18n/content-file-source.js +218 -0
- package/dist/i18n/content-file-source.js.map +1 -0
- package/dist/i18n/index.d.ts +19 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +21 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/json-file-source.d.ts +96 -0
- package/dist/i18n/json-file-source.d.ts.map +1 -0
- package/dist/i18n/json-file-source.js +258 -0
- package/dist/i18n/json-file-source.js.map +1 -0
- package/dist/i18n/merge-catalogs.d.ts +20 -0
- package/dist/i18n/merge-catalogs.d.ts.map +1 -0
- package/dist/i18n/merge-catalogs.js +34 -0
- package/dist/i18n/merge-catalogs.js.map +1 -0
- package/dist/i18n/node.d.ts +20 -0
- package/dist/i18n/node.d.ts.map +1 -0
- package/dist/i18n/node.js +19 -0
- package/dist/i18n/node.js.map +1 -0
- package/dist/i18n/translation-source.d.ts +35 -0
- package/dist/i18n/translation-source.d.ts.map +1 -0
- package/dist/i18n/translation-source.js +2 -0
- package/dist/i18n/translation-source.js.map +1 -0
- package/dist/i18n/translator.d.ts +162 -0
- package/dist/i18n/translator.d.ts.map +1 -0
- package/dist/i18n/translator.js +259 -0
- package/dist/i18n/translator.js.map +1 -0
- package/dist/i18n/types.d.ts +80 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +2 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/postgresql/database.d.ts +204 -0
- package/dist/postgresql/database.d.ts.map +1 -0
- package/dist/postgresql/database.js +321 -0
- package/dist/postgresql/database.js.map +1 -0
- package/dist/postgresql/delete-statement.d.ts +36 -0
- package/dist/postgresql/delete-statement.d.ts.map +1 -0
- package/dist/postgresql/delete-statement.js +54 -0
- package/dist/postgresql/delete-statement.js.map +1 -0
- package/dist/postgresql/index.d.ts +12 -0
- package/dist/postgresql/index.d.ts.map +1 -0
- package/dist/postgresql/index.js +12 -0
- package/dist/postgresql/index.js.map +1 -0
- package/dist/postgresql/insert-statement.d.ts +34 -0
- package/dist/postgresql/insert-statement.d.ts.map +1 -0
- package/dist/postgresql/insert-statement.js +48 -0
- package/dist/postgresql/insert-statement.js.map +1 -0
- package/dist/postgresql/update-statement.d.ts +38 -0
- package/dist/postgresql/update-statement.d.ts.map +1 -0
- package/dist/postgresql/update-statement.js +75 -0
- package/dist/postgresql/update-statement.js.map +1 -0
- package/dist/stdlib/formatString.d.ts +52 -0
- package/dist/stdlib/formatString.d.ts.map +1 -0
- package/dist/stdlib/formatString.js +118 -0
- package/dist/stdlib/formatString.js.map +1 -0
- package/dist/stdlib/index.d.ts +8 -0
- package/dist/stdlib/index.d.ts.map +1 -0
- package/dist/stdlib/index.js +8 -0
- package/dist/stdlib/index.js.map +1 -0
- package/dist/stdlib/isBoolean.d.ts +15 -0
- package/dist/stdlib/isBoolean.d.ts.map +1 -0
- package/dist/stdlib/isBoolean.js +17 -0
- package/dist/stdlib/isBoolean.js.map +1 -0
- package/dist/stdlib/isNullOrUndef.d.ts +24 -0
- package/dist/stdlib/isNullOrUndef.d.ts.map +1 -0
- package/dist/stdlib/isNullOrUndef.js +28 -0
- package/dist/stdlib/isNullOrUndef.js.map +1 -0
- package/dist/stdlib/isNumeric.d.ts +20 -0
- package/dist/stdlib/isNumeric.d.ts.map +1 -0
- package/dist/stdlib/isNumeric.js +39 -0
- package/dist/stdlib/isNumeric.js.map +1 -0
- package/dist/stdlib/isString.d.ts +15 -0
- package/dist/stdlib/isString.d.ts.map +1 -0
- package/dist/stdlib/isString.js +17 -0
- package/dist/stdlib/isString.js.map +1 -0
- package/dist/stdlib/isTemplateString.d.ts +18 -0
- package/dist/stdlib/isTemplateString.d.ts.map +1 -0
- package/dist/stdlib/isTemplateString.js +38 -0
- package/dist/stdlib/isTemplateString.js.map +1 -0
- package/dist/stdlib/wrapInArray.d.ts +14 -0
- package/dist/stdlib/wrapInArray.d.ts.map +1 -0
- package/dist/stdlib/wrapInArray.js +17 -0
- package/dist/stdlib/wrapInArray.js.map +1 -0
- package/dist/webafx/application/application-settings.d.ts +129 -0
- package/dist/webafx/application/application-settings.d.ts.map +1 -0
- package/dist/webafx/application/application-settings.js +162 -0
- package/dist/webafx/application/application-settings.js.map +1 -0
- package/dist/webafx/application/base-controller.d.ts +128 -0
- package/dist/webafx/application/base-controller.d.ts.map +1 -0
- package/dist/webafx/application/base-controller.js +122 -0
- package/dist/webafx/application/base-controller.js.map +1 -0
- package/dist/webafx/application/console-logger.d.ts +81 -0
- package/dist/webafx/application/console-logger.d.ts.map +1 -0
- package/dist/webafx/application/console-logger.js +111 -0
- package/dist/webafx/application/console-logger.js.map +1 -0
- package/dist/webafx/application/controller-registry.d.ts +34 -0
- package/dist/webafx/application/controller-registry.d.ts.map +1 -0
- package/dist/webafx/application/controller-registry.js +32 -0
- package/dist/webafx/application/controller-registry.js.map +1 -0
- package/dist/webafx/application/error-handler-middleware.d.ts +22 -0
- package/dist/webafx/application/error-handler-middleware.d.ts.map +1 -0
- package/dist/webafx/application/error-handler-middleware.js +70 -0
- package/dist/webafx/application/error-handler-middleware.js.map +1 -0
- package/dist/webafx/application/index.d.ts +13 -0
- package/dist/webafx/application/index.d.ts.map +1 -0
- package/dist/webafx/application/index.js +13 -0
- package/dist/webafx/application/index.js.map +1 -0
- package/dist/webafx/application/logger.d.ts +2 -0
- package/dist/webafx/application/logger.d.ts.map +1 -0
- package/dist/webafx/application/logger.js +2 -0
- package/dist/webafx/application/logger.js.map +1 -0
- package/dist/webafx/application/plugin.d.ts +73 -0
- package/dist/webafx/application/plugin.d.ts.map +1 -0
- package/dist/webafx/application/plugin.js +90 -0
- package/dist/webafx/application/plugin.js.map +1 -0
- package/dist/webafx/application/rate-limiter.d.ts +35 -0
- package/dist/webafx/application/rate-limiter.d.ts.map +1 -0
- package/dist/webafx/application/rate-limiter.js +74 -0
- package/dist/webafx/application/rate-limiter.js.map +1 -0
- package/dist/webafx/application/request-context.d.ts +62 -0
- package/dist/webafx/application/request-context.d.ts.map +1 -0
- package/dist/webafx/application/request-context.js +54 -0
- package/dist/webafx/application/request-context.js.map +1 -0
- package/dist/webafx/application/request-id-middleware.d.ts +30 -0
- package/dist/webafx/application/request-id-middleware.d.ts.map +1 -0
- package/dist/webafx/application/request-id-middleware.js +57 -0
- package/dist/webafx/application/request-id-middleware.js.map +1 -0
- package/dist/webafx/application/route-builder.d.ts +231 -0
- package/dist/webafx/application/route-builder.d.ts.map +1 -0
- package/dist/webafx/application/route-builder.js +182 -0
- package/dist/webafx/application/route-builder.js.map +1 -0
- package/dist/webafx/application/service-container.d.ts +144 -0
- package/dist/webafx/application/service-container.d.ts.map +1 -0
- package/dist/webafx/application/service-container.js +192 -0
- package/dist/webafx/application/service-container.js.map +1 -0
- package/dist/webafx/application/services.d.ts +27 -0
- package/dist/webafx/application/services.d.ts.map +1 -0
- package/dist/webafx/application/services.js +33 -0
- package/dist/webafx/application/services.js.map +1 -0
- package/dist/webafx/application/structured-logger.d.ts +99 -0
- package/dist/webafx/application/structured-logger.d.ts.map +1 -0
- package/dist/webafx/application/structured-logger.js +132 -0
- package/dist/webafx/application/structured-logger.js.map +1 -0
- package/dist/webafx/application/type.d.ts +29 -0
- package/dist/webafx/application/type.d.ts.map +1 -0
- package/dist/webafx/application/type.js +2 -0
- package/dist/webafx/application/type.js.map +1 -0
- package/dist/webafx/application/web-application.d.ts +257 -0
- package/dist/webafx/application/web-application.d.ts.map +1 -0
- package/dist/webafx/application/web-application.js +611 -0
- package/dist/webafx/application/web-application.js.map +1 -0
- package/dist/webafx/errors/api-error.d.ts +21 -0
- package/dist/webafx/errors/api-error.d.ts.map +1 -0
- package/dist/webafx/errors/api-error.js +38 -0
- package/dist/webafx/errors/api-error.js.map +1 -0
- package/dist/webafx/errors/http-errors.d.ts +56 -0
- package/dist/webafx/errors/http-errors.d.ts.map +1 -0
- package/dist/webafx/errors/http-errors.js +74 -0
- package/dist/webafx/errors/http-errors.js.map +1 -0
- package/dist/webafx/errors/index.d.ts +4 -0
- package/dist/webafx/errors/index.d.ts.map +1 -0
- package/dist/webafx/errors/index.js +4 -0
- package/dist/webafx/errors/index.js.map +1 -0
- package/dist/webafx/errors/types.d.ts +42 -0
- package/dist/webafx/errors/types.d.ts.map +1 -0
- package/dist/webafx/errors/types.js +2 -0
- package/dist/webafx/errors/types.js.map +1 -0
- package/dist/webafx/index.d.ts +3 -0
- package/dist/webafx/index.d.ts.map +1 -0
- package/dist/webafx/index.js +3 -0
- package/dist/webafx/index.js.map +1 -0
- package/dist/webafx-auth/abstract-auth-provider.d.ts +178 -0
- package/dist/webafx-auth/abstract-auth-provider.d.ts.map +1 -0
- package/dist/webafx-auth/abstract-auth-provider.js +240 -0
- package/dist/webafx-auth/abstract-auth-provider.js.map +1 -0
- package/dist/webafx-auth/index.d.ts +27 -0
- package/dist/webafx-auth/index.d.ts.map +1 -0
- package/dist/webafx-auth/index.js +32 -0
- package/dist/webafx-auth/index.js.map +1 -0
- package/dist/webafx-auth/jwt-auth-provider.d.ts +100 -0
- package/dist/webafx-auth/jwt-auth-provider.d.ts.map +1 -0
- package/dist/webafx-auth/jwt-auth-provider.js +154 -0
- package/dist/webafx-auth/jwt-auth-provider.js.map +1 -0
- package/dist/webafx-auth/memory-auth-provider.d.ts +100 -0
- package/dist/webafx-auth/memory-auth-provider.d.ts.map +1 -0
- package/dist/webafx-auth/memory-auth-provider.js +122 -0
- package/dist/webafx-auth/memory-auth-provider.js.map +1 -0
- package/dist/webafx-auth/types.d.ts +333 -0
- package/dist/webafx-auth/types.d.ts.map +1 -0
- package/dist/webafx-auth/types.js +24 -0
- package/dist/webafx-auth/types.js.map +1 -0
- package/dist/webafx-cache/abstract-cache-provider.d.ts +185 -0
- package/dist/webafx-cache/abstract-cache-provider.d.ts.map +1 -0
- package/dist/webafx-cache/abstract-cache-provider.js +133 -0
- package/dist/webafx-cache/abstract-cache-provider.js.map +1 -0
- package/dist/webafx-cache/abstract-pubsub-provider.d.ts +170 -0
- package/dist/webafx-cache/abstract-pubsub-provider.d.ts.map +1 -0
- package/dist/webafx-cache/abstract-pubsub-provider.js +132 -0
- package/dist/webafx-cache/abstract-pubsub-provider.js.map +1 -0
- package/dist/webafx-cache/cache-plugin.d.ts +114 -0
- package/dist/webafx-cache/cache-plugin.d.ts.map +1 -0
- package/dist/webafx-cache/cache-plugin.js +176 -0
- package/dist/webafx-cache/cache-plugin.js.map +1 -0
- package/dist/webafx-cache/index.d.ts +33 -0
- package/dist/webafx-cache/index.d.ts.map +1 -0
- package/dist/webafx-cache/index.js +44 -0
- package/dist/webafx-cache/index.js.map +1 -0
- package/dist/webafx-cache/memory-cache-provider.d.ts +99 -0
- package/dist/webafx-cache/memory-cache-provider.d.ts.map +1 -0
- package/dist/webafx-cache/memory-cache-provider.js +251 -0
- package/dist/webafx-cache/memory-cache-provider.js.map +1 -0
- package/dist/webafx-cache/memory-pubsub-provider.d.ts +124 -0
- package/dist/webafx-cache/memory-pubsub-provider.d.ts.map +1 -0
- package/dist/webafx-cache/memory-pubsub-provider.js +195 -0
- package/dist/webafx-cache/memory-pubsub-provider.js.map +1 -0
- package/dist/webafx-cache/pubsub-plugin.d.ts +128 -0
- package/dist/webafx-cache/pubsub-plugin.d.ts.map +1 -0
- package/dist/webafx-cache/pubsub-plugin.js +182 -0
- package/dist/webafx-cache/pubsub-plugin.js.map +1 -0
- package/dist/webafx-cache/redis-cache-provider.d.ts +81 -0
- package/dist/webafx-cache/redis-cache-provider.d.ts.map +1 -0
- package/dist/webafx-cache/redis-cache-provider.js +209 -0
- package/dist/webafx-cache/redis-cache-provider.js.map +1 -0
- package/dist/webafx-cache/redis-pubsub-provider.d.ts +164 -0
- package/dist/webafx-cache/redis-pubsub-provider.d.ts.map +1 -0
- package/dist/webafx-cache/redis-pubsub-provider.js +329 -0
- package/dist/webafx-cache/redis-pubsub-provider.js.map +1 -0
- package/dist/webafx-cache/types.d.ts +206 -0
- package/dist/webafx-cache/types.d.ts.map +1 -0
- package/dist/webafx-cache/types.js +27 -0
- package/dist/webafx-cache/types.js.map +1 -0
- package/dist/webafx-i18n/i18n-plugin.d.ts +29 -0
- package/dist/webafx-i18n/i18n-plugin.d.ts.map +1 -0
- package/dist/webafx-i18n/i18n-plugin.js +145 -0
- package/dist/webafx-i18n/i18n-plugin.js.map +1 -0
- package/dist/webafx-i18n/index.d.ts +12 -0
- package/dist/webafx-i18n/index.d.ts.map +1 -0
- package/dist/webafx-i18n/index.js +12 -0
- package/dist/webafx-i18n/index.js.map +1 -0
- package/dist/webafx-i18n/locale-resolver.d.ts +33 -0
- package/dist/webafx-i18n/locale-resolver.d.ts.map +1 -0
- package/dist/webafx-i18n/locale-resolver.js +67 -0
- package/dist/webafx-i18n/locale-resolver.js.map +1 -0
- package/dist/webafx-i18n/postgresql-source.d.ts +101 -0
- package/dist/webafx-i18n/postgresql-source.d.ts.map +1 -0
- package/dist/webafx-i18n/postgresql-source.js +101 -0
- package/dist/webafx-i18n/postgresql-source.js.map +1 -0
- package/dist/webafx-i18n/types.d.ts +70 -0
- package/dist/webafx-i18n/types.d.ts.map +1 -0
- package/dist/webafx-i18n/types.js +2 -0
- package/dist/webafx-i18n/types.js.map +1 -0
- package/dist/webafx-mailer/abstract-mail-provider.d.ts +55 -0
- package/dist/webafx-mailer/abstract-mail-provider.d.ts.map +1 -0
- package/dist/webafx-mailer/abstract-mail-provider.js +37 -0
- package/dist/webafx-mailer/abstract-mail-provider.js.map +1 -0
- package/dist/webafx-mailer/index.d.ts +24 -0
- package/dist/webafx-mailer/index.d.ts.map +1 -0
- package/dist/webafx-mailer/index.js +34 -0
- package/dist/webafx-mailer/index.js.map +1 -0
- package/dist/webafx-mailer/mail-plugin.d.ts +98 -0
- package/dist/webafx-mailer/mail-plugin.d.ts.map +1 -0
- package/dist/webafx-mailer/mail-plugin.js +155 -0
- package/dist/webafx-mailer/mail-plugin.js.map +1 -0
- package/dist/webafx-mailer/memory-mail-provider.d.ts +85 -0
- package/dist/webafx-mailer/memory-mail-provider.d.ts.map +1 -0
- package/dist/webafx-mailer/memory-mail-provider.js +111 -0
- package/dist/webafx-mailer/memory-mail-provider.js.map +1 -0
- package/dist/webafx-mailer/smtp-mail-provider.d.ts +65 -0
- package/dist/webafx-mailer/smtp-mail-provider.d.ts.map +1 -0
- package/dist/webafx-mailer/smtp-mail-provider.js +113 -0
- package/dist/webafx-mailer/smtp-mail-provider.js.map +1 -0
- package/dist/webafx-mailer/types.d.ts +136 -0
- package/dist/webafx-mailer/types.d.ts.map +1 -0
- package/dist/webafx-mailer/types.js +13 -0
- package/dist/webafx-mailer/types.js.map +1 -0
- package/package.json +159 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all cache provider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides a Redis-like API with transparent key namespacing via rootKey prefix.
|
|
5
|
+
* Both RedisCacheProvider and MemoryCacheProvider extend this class and implement
|
|
6
|
+
* the abstract methods with backend-specific logic.
|
|
7
|
+
*
|
|
8
|
+
* Design principles:
|
|
9
|
+
* - Application-wide singleton (not per-request)
|
|
10
|
+
* - Root key prefix isolates keys per application/concern
|
|
11
|
+
* - Configurable serviceName for multi-cache scenarios
|
|
12
|
+
* - JSON serialization for all stored values
|
|
13
|
+
* - All methods are async for a uniform API
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import type { CacheProviderConfig } from "./types.js";
|
|
18
|
+
/**
|
|
19
|
+
* Abstract base class for cache implementations.
|
|
20
|
+
*
|
|
21
|
+
* All cache backends (Redis, In-Memory) derive from this class.
|
|
22
|
+
* Provides a Redis-like API with transparent key namespacing via rootKey.
|
|
23
|
+
*
|
|
24
|
+
* Usage through concrete implementations:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const cache = new RedisCacheProvider({ rootKey: 'MyApp' });
|
|
27
|
+
* await cache.set('user:123', { name: 'Alice' }, 300);
|
|
28
|
+
* const user = await cache.get<User>('user:123');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class CacheProvider {
|
|
32
|
+
/** Root key prefix applied to all cache keys */
|
|
33
|
+
protected rootKey: string;
|
|
34
|
+
/** Service name for WebAFX service container registration */
|
|
35
|
+
protected _serviceName: string;
|
|
36
|
+
/** Default TTL in seconds (0 = no expiry) */
|
|
37
|
+
protected defaultTTL: number;
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the cache provider with configuration.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Base configuration with rootKey, optional serviceName and defaultTTL
|
|
42
|
+
* @throws Error if rootKey is empty or not provided
|
|
43
|
+
*/
|
|
44
|
+
constructor(config: CacheProviderConfig);
|
|
45
|
+
/** Get the service name used for WebAFX service container registration */
|
|
46
|
+
get serviceName(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Build the actual storage key by prepending the root prefix.
|
|
49
|
+
*
|
|
50
|
+
* This method is called by every cache operation to ensure all keys
|
|
51
|
+
* are namespaced under the rootKey, preventing key collisions in
|
|
52
|
+
* shared backends (e.g., multiple apps sharing one Redis instance).
|
|
53
|
+
*
|
|
54
|
+
* @param key - The user-provided cache key
|
|
55
|
+
* @returns The prefixed key (e.g., rootKey='MyApp', key='user:123' → 'MyApp:user:123')
|
|
56
|
+
*/
|
|
57
|
+
protected buildKey(key: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Build the pattern key for pattern-based operations (deletePattern, clear).
|
|
60
|
+
*
|
|
61
|
+
* @param pattern - The user-provided pattern (e.g., 'user:*')
|
|
62
|
+
* @returns The prefixed pattern (e.g., 'MyApp:user:*')
|
|
63
|
+
*/
|
|
64
|
+
protected buildPattern(pattern: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve the effective TTL for an operation.
|
|
67
|
+
*
|
|
68
|
+
* Uses the provided TTL if given, otherwise falls back to defaultTTL.
|
|
69
|
+
* Returns undefined if effective TTL is 0 (meaning no expiry).
|
|
70
|
+
*
|
|
71
|
+
* @param ttlSeconds - Optional TTL override for this operation
|
|
72
|
+
* @returns The effective TTL in seconds, or undefined if no expiry
|
|
73
|
+
*/
|
|
74
|
+
protected resolveTTL(ttlSeconds?: number): number | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Set a value in the cache.
|
|
77
|
+
*
|
|
78
|
+
* The value is JSON-serialized before storage. The rootKey prefix
|
|
79
|
+
* is applied automatically to the key.
|
|
80
|
+
*
|
|
81
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
82
|
+
* @param value - Value to store (will be JSON-serialized)
|
|
83
|
+
* @param ttlSeconds - Optional TTL in seconds. Uses defaultTTL if not provided. 0 = no expiry.
|
|
84
|
+
*/
|
|
85
|
+
abstract set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Get a value from the cache.
|
|
88
|
+
*
|
|
89
|
+
* The stored JSON is deserialized before returning. Returns undefined
|
|
90
|
+
* for cache misses or expired entries.
|
|
91
|
+
*
|
|
92
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
93
|
+
* @returns The deserialized value, or undefined if not found / expired
|
|
94
|
+
*/
|
|
95
|
+
abstract get<T>(key: string): Promise<T | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Delete a key from the cache.
|
|
98
|
+
*
|
|
99
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
100
|
+
* @returns true if the key was deleted, false if it didn't exist
|
|
101
|
+
*/
|
|
102
|
+
abstract delete(key: string): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Check if a key exists in the cache (and is not expired).
|
|
105
|
+
*
|
|
106
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
107
|
+
* @returns true if the key exists and is not expired
|
|
108
|
+
*/
|
|
109
|
+
abstract exists(key: string): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Update the TTL on an existing key without changing its value.
|
|
112
|
+
*
|
|
113
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
114
|
+
* @param ttlSeconds - New TTL in seconds
|
|
115
|
+
* @returns true if the key exists and TTL was updated, false otherwise
|
|
116
|
+
*/
|
|
117
|
+
abstract expire(key: string, ttlSeconds: number): Promise<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* Get the remaining TTL of a key in seconds.
|
|
120
|
+
*
|
|
121
|
+
* Follows Redis conventions for return values:
|
|
122
|
+
* - Positive number: remaining TTL in seconds
|
|
123
|
+
* - -1: key exists but has no expiry
|
|
124
|
+
* - -2: key does not exist
|
|
125
|
+
*
|
|
126
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
127
|
+
* @returns Remaining TTL in seconds, -1 if no expiry, -2 if key doesn't exist
|
|
128
|
+
*/
|
|
129
|
+
abstract ttl(key: string): Promise<number>;
|
|
130
|
+
/**
|
|
131
|
+
* Delete all keys matching a pattern within this root namespace.
|
|
132
|
+
*
|
|
133
|
+
* Pattern uses '*' as wildcard:
|
|
134
|
+
* - 'user:*' matches 'user:123', 'user:abc'
|
|
135
|
+
* - '*:session' matches 'admin:session', 'guest:session'
|
|
136
|
+
*
|
|
137
|
+
* For Redis, this uses SCAN (not KEYS) to avoid blocking the server.
|
|
138
|
+
*
|
|
139
|
+
* @param pattern - Pattern to match (rootKey prefix applied automatically)
|
|
140
|
+
* @returns Number of keys deleted
|
|
141
|
+
*/
|
|
142
|
+
abstract deletePattern(pattern: string): Promise<number>;
|
|
143
|
+
/**
|
|
144
|
+
* Clear all keys under this root namespace.
|
|
145
|
+
*
|
|
146
|
+
* Only removes keys with this provider's rootKey prefix — does NOT
|
|
147
|
+
* flush the entire Redis database or clear other namespaces.
|
|
148
|
+
*/
|
|
149
|
+
abstract clear(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Health check — returns true if the backend is operational.
|
|
152
|
+
*
|
|
153
|
+
* For Redis: sends a PING command and checks connectivity.
|
|
154
|
+
* For In-Memory: always returns true.
|
|
155
|
+
*/
|
|
156
|
+
abstract health(): Promise<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* Graceful shutdown — close connections, clear intervals, release resources.
|
|
159
|
+
*
|
|
160
|
+
* For Redis: disconnects the ioredis client.
|
|
161
|
+
* For In-Memory: clears the cleanup interval and empties the store.
|
|
162
|
+
*/
|
|
163
|
+
abstract shutdown(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Cache-aside pattern: get a value if it exists, otherwise call the factory
|
|
166
|
+
* function to produce it, cache the result, and return it.
|
|
167
|
+
*
|
|
168
|
+
* This is the most common caching pattern and is implemented once in the
|
|
169
|
+
* base class since the logic is identical for all backends.
|
|
170
|
+
*
|
|
171
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
172
|
+
* @param factory - Async function that produces the value on cache miss
|
|
173
|
+
* @param ttlSeconds - Optional TTL in seconds for the cached value
|
|
174
|
+
* @returns The cached or freshly produced value
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const user = await cache.getOrSet('user:123', async () => {
|
|
179
|
+
* return await db.fetchUser(123);
|
|
180
|
+
* }, 300); // Cache for 5 minutes
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
getOrSet<T>(key: string, factory: () => Promise<T>, ttlSeconds?: number): Promise<T>;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=abstract-cache-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-cache-provider.d.ts","sourceRoot":"","sources":["../src/abstract-cache-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGtD;;;;;;;;;;;;GAYG;AACH,8BAAsB,aAAa;IAC/B,gDAAgD;IAChD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAE1B,6DAA6D;IAC7D,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,6CAA6C;IAC7C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;gBACS,MAAM,EAAE,mBAAmB;IAevC,0EAA0E;IAC1E,IAAI,WAAW,IAAI,MAAM,CAExB;IAMD;;;;;;;;;OASG;IACH,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIvC;;;;;OAKG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAI/C;;;;;;;;OAQG;IACH,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAS7D;;;;;;;;;OASG;IACH,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E;;;;;;;;OAQG;IACH,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAE9C;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAE9C;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAElE;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAE1C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAExD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAE/B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAEnC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlC;;;;;;;;;;;;;;;;;;OAkBG;IACG,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAe7F"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all cache provider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides a Redis-like API with transparent key namespacing via rootKey prefix.
|
|
5
|
+
* Both RedisCacheProvider and MemoryCacheProvider extend this class and implement
|
|
6
|
+
* the abstract methods with backend-specific logic.
|
|
7
|
+
*
|
|
8
|
+
* Design principles:
|
|
9
|
+
* - Application-wide singleton (not per-request)
|
|
10
|
+
* - Root key prefix isolates keys per application/concern
|
|
11
|
+
* - Configurable serviceName for multi-cache scenarios
|
|
12
|
+
* - JSON serialization for all stored values
|
|
13
|
+
* - All methods are async for a uniform API
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_SERVICE_NAME, DEFAULT_TTL, KEY_SEPARATOR } from "./types.js";
|
|
18
|
+
/**
|
|
19
|
+
* Abstract base class for cache implementations.
|
|
20
|
+
*
|
|
21
|
+
* All cache backends (Redis, In-Memory) derive from this class.
|
|
22
|
+
* Provides a Redis-like API with transparent key namespacing via rootKey.
|
|
23
|
+
*
|
|
24
|
+
* Usage through concrete implementations:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const cache = new RedisCacheProvider({ rootKey: 'MyApp' });
|
|
27
|
+
* await cache.set('user:123', { name: 'Alice' }, 300);
|
|
28
|
+
* const user = await cache.get<User>('user:123');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class CacheProvider {
|
|
32
|
+
/** Root key prefix applied to all cache keys */
|
|
33
|
+
rootKey;
|
|
34
|
+
/** Service name for WebAFX service container registration */
|
|
35
|
+
_serviceName;
|
|
36
|
+
/** Default TTL in seconds (0 = no expiry) */
|
|
37
|
+
defaultTTL;
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the cache provider with configuration.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Base configuration with rootKey, optional serviceName and defaultTTL
|
|
42
|
+
* @throws Error if rootKey is empty or not provided
|
|
43
|
+
*/
|
|
44
|
+
constructor(config) {
|
|
45
|
+
// Validate rootKey — it must be a non-empty string for namespace isolation
|
|
46
|
+
if (!config.rootKey || config.rootKey.trim().length === 0) {
|
|
47
|
+
throw new Error("CacheProvider: rootKey is required and cannot be empty");
|
|
48
|
+
}
|
|
49
|
+
this.rootKey = config.rootKey;
|
|
50
|
+
this._serviceName = config.serviceName ?? DEFAULT_SERVICE_NAME;
|
|
51
|
+
this.defaultTTL = config.defaultTTL ?? DEFAULT_TTL;
|
|
52
|
+
}
|
|
53
|
+
// -----------------------------------------------------------------------
|
|
54
|
+
// Public Accessors
|
|
55
|
+
// -----------------------------------------------------------------------
|
|
56
|
+
/** Get the service name used for WebAFX service container registration */
|
|
57
|
+
get serviceName() {
|
|
58
|
+
return this._serviceName;
|
|
59
|
+
}
|
|
60
|
+
// -----------------------------------------------------------------------
|
|
61
|
+
// Key Building (protected helpers for subclasses)
|
|
62
|
+
// -----------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* Build the actual storage key by prepending the root prefix.
|
|
65
|
+
*
|
|
66
|
+
* This method is called by every cache operation to ensure all keys
|
|
67
|
+
* are namespaced under the rootKey, preventing key collisions in
|
|
68
|
+
* shared backends (e.g., multiple apps sharing one Redis instance).
|
|
69
|
+
*
|
|
70
|
+
* @param key - The user-provided cache key
|
|
71
|
+
* @returns The prefixed key (e.g., rootKey='MyApp', key='user:123' → 'MyApp:user:123')
|
|
72
|
+
*/
|
|
73
|
+
buildKey(key) {
|
|
74
|
+
return `${this.rootKey}${KEY_SEPARATOR}${key}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build the pattern key for pattern-based operations (deletePattern, clear).
|
|
78
|
+
*
|
|
79
|
+
* @param pattern - The user-provided pattern (e.g., 'user:*')
|
|
80
|
+
* @returns The prefixed pattern (e.g., 'MyApp:user:*')
|
|
81
|
+
*/
|
|
82
|
+
buildPattern(pattern) {
|
|
83
|
+
return `${this.rootKey}${KEY_SEPARATOR}${pattern}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the effective TTL for an operation.
|
|
87
|
+
*
|
|
88
|
+
* Uses the provided TTL if given, otherwise falls back to defaultTTL.
|
|
89
|
+
* Returns undefined if effective TTL is 0 (meaning no expiry).
|
|
90
|
+
*
|
|
91
|
+
* @param ttlSeconds - Optional TTL override for this operation
|
|
92
|
+
* @returns The effective TTL in seconds, or undefined if no expiry
|
|
93
|
+
*/
|
|
94
|
+
resolveTTL(ttlSeconds) {
|
|
95
|
+
const ttl = ttlSeconds ?? this.defaultTTL;
|
|
96
|
+
return ttl > 0 ? ttl : undefined;
|
|
97
|
+
}
|
|
98
|
+
// -----------------------------------------------------------------------
|
|
99
|
+
// Concrete Methods (shared logic implemented once for all backends)
|
|
100
|
+
// -----------------------------------------------------------------------
|
|
101
|
+
/**
|
|
102
|
+
* Cache-aside pattern: get a value if it exists, otherwise call the factory
|
|
103
|
+
* function to produce it, cache the result, and return it.
|
|
104
|
+
*
|
|
105
|
+
* This is the most common caching pattern and is implemented once in the
|
|
106
|
+
* base class since the logic is identical for all backends.
|
|
107
|
+
*
|
|
108
|
+
* @param key - Cache key (rootKey prefix applied automatically)
|
|
109
|
+
* @param factory - Async function that produces the value on cache miss
|
|
110
|
+
* @param ttlSeconds - Optional TTL in seconds for the cached value
|
|
111
|
+
* @returns The cached or freshly produced value
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const user = await cache.getOrSet('user:123', async () => {
|
|
116
|
+
* return await db.fetchUser(123);
|
|
117
|
+
* }, 300); // Cache for 5 minutes
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
async getOrSet(key, factory, ttlSeconds) {
|
|
121
|
+
// Try to get from cache first
|
|
122
|
+
const cached = await this.get(key);
|
|
123
|
+
if (cached !== undefined) {
|
|
124
|
+
return cached;
|
|
125
|
+
}
|
|
126
|
+
// Cache miss — call factory to produce the value
|
|
127
|
+
const value = await factory();
|
|
128
|
+
// Store in cache with the specified or default TTL
|
|
129
|
+
await this.set(key, value, ttlSeconds);
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=abstract-cache-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-cache-provider.js","sourceRoot":"","sources":["../src/abstract-cache-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,aAAa;IAC/B,gDAAgD;IACtC,OAAO,CAAS;IAE1B,6DAA6D;IACnD,YAAY,CAAS;IAE/B,6CAA6C;IACnC,UAAU,CAAS;IAE7B;;;;;OAKG;IACH,YAAY,MAA2B;QACnC,2EAA2E;QAC3E,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,IAAI,oBAAoB,CAAC;QAC/D,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,WAAW,CAAC;IACvD,CAAC;IAED,0EAA0E;IAC1E,mBAAmB;IACnB,0EAA0E;IAE1E,0EAA0E;IAC1E,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,0EAA0E;IAC1E,kDAAkD;IAClD,0EAA0E;IAE1E;;;;;;;;;OASG;IACO,QAAQ,CAAC,GAAW;QAC1B,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,aAAa,GAAG,GAAG,EAAE,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACO,YAAY,CAAC,OAAe;QAClC,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,aAAa,GAAG,OAAO,EAAE,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACO,UAAU,CAAC,UAAmB;QACpC,MAAM,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC;QAC1C,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACrC,CAAC;IAyGD,0EAA0E;IAC1E,oEAAoE;IACpE,0EAA0E;IAE1E;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,QAAQ,CAAI,GAAW,EAAE,OAAyB,EAAE,UAAmB;QACzE,8BAA8B;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;QACtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,iDAAiD;QACjD,MAAM,KAAK,GAAG,MAAM,OAAO,EAAE,CAAC;QAE9B,mDAAmD;QACnD,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all pub/sub provider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed, JSON-serialized messaging API with transparent channel
|
|
5
|
+
* prefix management. Both RedisPubSubProvider and MemoryPubSubProvider
|
|
6
|
+
* extend this class and implement the abstract methods with backend-specific logic.
|
|
7
|
+
*
|
|
8
|
+
* Design principles:
|
|
9
|
+
* - Application-wide singleton (not per-request)
|
|
10
|
+
* - Channel prefix isolates channels per application/concern
|
|
11
|
+
* - Configurable serviceName for multi-pubsub scenarios
|
|
12
|
+
* - JSON serialization for all messages
|
|
13
|
+
* - All methods are async for a uniform API
|
|
14
|
+
* - Handler errors are isolated (log + continue)
|
|
15
|
+
*
|
|
16
|
+
* Architecture note:
|
|
17
|
+
* This hierarchy is completely independent from CacheProvider. They are
|
|
18
|
+
* parallel abstractions that happen to live in the same package.
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
import type { PubSubProviderConfig, PubSubMessage, MessageHandler } from "./types.js";
|
|
23
|
+
/**
|
|
24
|
+
* Abstract base class for pub/sub implementations.
|
|
25
|
+
*
|
|
26
|
+
* All pub/sub backends (Redis, In-Memory) derive from this class.
|
|
27
|
+
* Provides typed, JSON-serialized messaging with channel prefix support.
|
|
28
|
+
*
|
|
29
|
+
* Usage through concrete implementations:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const pubsub = new RedisPubSubProvider({ channelPrefix: 'MyApp' });
|
|
32
|
+
* await pubsub.subscribe<OrderEvent>('order:new', (msg) => {
|
|
33
|
+
* console.log('New order:', msg.data);
|
|
34
|
+
* });
|
|
35
|
+
* await pubsub.publish('order:new', { orderId: 123, total: 49.99 });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare abstract class PubSubProvider {
|
|
39
|
+
/** Channel prefix for namespace isolation */
|
|
40
|
+
protected channelPrefix: string | undefined;
|
|
41
|
+
/** Service name for WebAFX registration */
|
|
42
|
+
protected _serviceName: string;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the pub/sub provider with configuration.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Base configuration with optional channelPrefix and serviceName
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: PubSubProviderConfig);
|
|
49
|
+
/** Get the service name used for WebAFX service container registration */
|
|
50
|
+
get serviceName(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Build the full channel name by prepending the prefix.
|
|
53
|
+
*
|
|
54
|
+
* Called by every publish/subscribe operation to ensure all channels
|
|
55
|
+
* are namespaced under the channelPrefix, preventing collisions
|
|
56
|
+
* when multiple applications share the same Redis instance.
|
|
57
|
+
*
|
|
58
|
+
* @param channel - User-provided channel name
|
|
59
|
+
* @returns Prefixed channel (e.g., prefix='MyApp', channel='order:new' → 'MyApp:order:new')
|
|
60
|
+
*/
|
|
61
|
+
protected buildChannel(channel: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Build the full pattern by prepending the prefix.
|
|
64
|
+
*
|
|
65
|
+
* Used by psubscribe to namespace glob patterns the same way
|
|
66
|
+
* buildChannel namespaces exact channel names.
|
|
67
|
+
*
|
|
68
|
+
* @param pattern - User-provided pattern (e.g., 'order:*')
|
|
69
|
+
* @returns Prefixed pattern (e.g., 'MyApp:order:*')
|
|
70
|
+
*/
|
|
71
|
+
protected buildChannelPattern(pattern: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Strip the channel prefix from a full channel name.
|
|
74
|
+
*
|
|
75
|
+
* Used when delivering messages to handlers — they should see
|
|
76
|
+
* the original channel name, not the internal prefixed version.
|
|
77
|
+
* This keeps the handler code agnostic of the prefix configuration.
|
|
78
|
+
*
|
|
79
|
+
* @param fullChannel - The prefixed channel (from Redis or internal store)
|
|
80
|
+
* @returns The user-facing channel name without prefix
|
|
81
|
+
*/
|
|
82
|
+
protected stripPrefix(fullChannel: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Safely invoke a message handler, catching and logging errors.
|
|
85
|
+
*
|
|
86
|
+
* Handler errors must never break other subscribers or crash
|
|
87
|
+
* the subscriber connection. This method wraps every handler
|
|
88
|
+
* invocation in a try/catch and logs errors to console.error.
|
|
89
|
+
*
|
|
90
|
+
* @param handler - The handler function to invoke
|
|
91
|
+
* @param message - The message to pass to the handler
|
|
92
|
+
*/
|
|
93
|
+
protected safeInvoke<T>(handler: MessageHandler<T>, message: PubSubMessage<T>): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Publish a typed message to a channel.
|
|
96
|
+
*
|
|
97
|
+
* The data is JSON-serialized before sending. The channel prefix
|
|
98
|
+
* is applied automatically.
|
|
99
|
+
*
|
|
100
|
+
* @param channel - Channel name (prefix applied automatically)
|
|
101
|
+
* @param data - Message payload (will be JSON-serialized)
|
|
102
|
+
* @returns Number of subscribers that received the message
|
|
103
|
+
*/
|
|
104
|
+
abstract publish<T>(channel: string, data: T): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* Subscribe to an exact channel with a typed handler.
|
|
107
|
+
*
|
|
108
|
+
* Multiple handlers can be registered for the same channel.
|
|
109
|
+
* The handler receives a `PubSubMessage<T>` with the deserialized
|
|
110
|
+
* payload and channel metadata.
|
|
111
|
+
*
|
|
112
|
+
* @param channel - Exact channel name (prefix applied automatically)
|
|
113
|
+
* @param handler - Function called when a message is received
|
|
114
|
+
*/
|
|
115
|
+
abstract subscribe<T = unknown>(channel: string, handler: MessageHandler<T>): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Unsubscribe from an exact channel.
|
|
118
|
+
*
|
|
119
|
+
* Removes all handlers for the specified channel and unsubscribes
|
|
120
|
+
* from the underlying transport.
|
|
121
|
+
*
|
|
122
|
+
* @param channel - Channel name to unsubscribe from
|
|
123
|
+
*/
|
|
124
|
+
abstract unsubscribe(channel: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Subscribe to a channel pattern with a typed handler.
|
|
127
|
+
*
|
|
128
|
+
* Pattern uses '*' as wildcard (glob matching). For example,
|
|
129
|
+
* 'order:*' matches 'order:new', 'order:cancelled', etc.
|
|
130
|
+
*
|
|
131
|
+
* @param pattern - Channel pattern (e.g., 'order:*')
|
|
132
|
+
* @param handler - Function called when a matching message is received
|
|
133
|
+
*/
|
|
134
|
+
abstract psubscribe<T = unknown>(pattern: string, handler: MessageHandler<T>): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Unsubscribe from a channel pattern.
|
|
137
|
+
*
|
|
138
|
+
* Removes all handlers for the specified pattern and unsubscribes
|
|
139
|
+
* from the underlying transport.
|
|
140
|
+
*
|
|
141
|
+
* @param pattern - Pattern to unsubscribe from
|
|
142
|
+
*/
|
|
143
|
+
abstract punsubscribe(pattern: string): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Get the list of currently active subscriptions.
|
|
146
|
+
*
|
|
147
|
+
* Returns user-facing channel/pattern names (prefix stripped).
|
|
148
|
+
*
|
|
149
|
+
* @returns Object with `channels` (exact) and `patterns` (glob) arrays
|
|
150
|
+
*/
|
|
151
|
+
abstract activeSubscriptions(): {
|
|
152
|
+
channels: string[];
|
|
153
|
+
patterns: string[];
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Health check — returns true if the backend is operational.
|
|
157
|
+
*
|
|
158
|
+
* For Redis: checks connectivity on both publisher and subscriber connections.
|
|
159
|
+
* For In-Memory: always returns true.
|
|
160
|
+
*/
|
|
161
|
+
abstract health(): Promise<boolean>;
|
|
162
|
+
/**
|
|
163
|
+
* Graceful shutdown — unsubscribe all, close connections, release resources.
|
|
164
|
+
*
|
|
165
|
+
* For Redis: disconnects both publisher and subscriber ioredis clients.
|
|
166
|
+
* For In-Memory: removes all handlers.
|
|
167
|
+
*/
|
|
168
|
+
abstract shutdown(): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=abstract-pubsub-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-pubsub-provider.d.ts","sourceRoot":"","sources":["../src/abstract-pubsub-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGtF;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,cAAc;IAChC,6CAA6C;IAC7C,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C,2CAA2C;IAC3C,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;gBACS,MAAM,EAAE,oBAAoB;IASxC,0EAA0E;IAC1E,IAAI,WAAW,IAAI,MAAM,CAExB;IAMD;;;;;;;;;OASG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAO/C;;;;;;;;OAQG;IACH,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOtD;;;;;;;;;OASG;IACH,SAAS,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAUlD;;;;;;;;;OASG;cACa,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnG;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAE9D;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3F;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEpD;;;;;;;;OAQG;IACH,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE5F;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAErD;;;;;;OAMG;IACH,QAAQ,CAAC,mBAAmB,IAAI;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;IAE1E;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAEnC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CACrC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all pub/sub provider implementations.
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed, JSON-serialized messaging API with transparent channel
|
|
5
|
+
* prefix management. Both RedisPubSubProvider and MemoryPubSubProvider
|
|
6
|
+
* extend this class and implement the abstract methods with backend-specific logic.
|
|
7
|
+
*
|
|
8
|
+
* Design principles:
|
|
9
|
+
* - Application-wide singleton (not per-request)
|
|
10
|
+
* - Channel prefix isolates channels per application/concern
|
|
11
|
+
* - Configurable serviceName for multi-pubsub scenarios
|
|
12
|
+
* - JSON serialization for all messages
|
|
13
|
+
* - All methods are async for a uniform API
|
|
14
|
+
* - Handler errors are isolated (log + continue)
|
|
15
|
+
*
|
|
16
|
+
* Architecture note:
|
|
17
|
+
* This hierarchy is completely independent from CacheProvider. They are
|
|
18
|
+
* parallel abstractions that happen to live in the same package.
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
import { DEFAULT_PUBSUB_SERVICE_NAME, CHANNEL_SEPARATOR } from "./types.js";
|
|
23
|
+
/**
|
|
24
|
+
* Abstract base class for pub/sub implementations.
|
|
25
|
+
*
|
|
26
|
+
* All pub/sub backends (Redis, In-Memory) derive from this class.
|
|
27
|
+
* Provides typed, JSON-serialized messaging with channel prefix support.
|
|
28
|
+
*
|
|
29
|
+
* Usage through concrete implementations:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const pubsub = new RedisPubSubProvider({ channelPrefix: 'MyApp' });
|
|
32
|
+
* await pubsub.subscribe<OrderEvent>('order:new', (msg) => {
|
|
33
|
+
* console.log('New order:', msg.data);
|
|
34
|
+
* });
|
|
35
|
+
* await pubsub.publish('order:new', { orderId: 123, total: 49.99 });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export class PubSubProvider {
|
|
39
|
+
/** Channel prefix for namespace isolation */
|
|
40
|
+
channelPrefix;
|
|
41
|
+
/** Service name for WebAFX registration */
|
|
42
|
+
_serviceName;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the pub/sub provider with configuration.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Base configuration with optional channelPrefix and serviceName
|
|
47
|
+
*/
|
|
48
|
+
constructor(config) {
|
|
49
|
+
this.channelPrefix = config.channelPrefix;
|
|
50
|
+
this._serviceName = config.serviceName ?? DEFAULT_PUBSUB_SERVICE_NAME;
|
|
51
|
+
}
|
|
52
|
+
// -------------------------------------------------------------------
|
|
53
|
+
// Public Accessors
|
|
54
|
+
// -------------------------------------------------------------------
|
|
55
|
+
/** Get the service name used for WebAFX service container registration */
|
|
56
|
+
get serviceName() {
|
|
57
|
+
return this._serviceName;
|
|
58
|
+
}
|
|
59
|
+
// -------------------------------------------------------------------
|
|
60
|
+
// Channel Building (protected helpers for subclasses)
|
|
61
|
+
// -------------------------------------------------------------------
|
|
62
|
+
/**
|
|
63
|
+
* Build the full channel name by prepending the prefix.
|
|
64
|
+
*
|
|
65
|
+
* Called by every publish/subscribe operation to ensure all channels
|
|
66
|
+
* are namespaced under the channelPrefix, preventing collisions
|
|
67
|
+
* when multiple applications share the same Redis instance.
|
|
68
|
+
*
|
|
69
|
+
* @param channel - User-provided channel name
|
|
70
|
+
* @returns Prefixed channel (e.g., prefix='MyApp', channel='order:new' → 'MyApp:order:new')
|
|
71
|
+
*/
|
|
72
|
+
buildChannel(channel) {
|
|
73
|
+
if (this.channelPrefix) {
|
|
74
|
+
return `${this.channelPrefix}${CHANNEL_SEPARATOR}${channel}`;
|
|
75
|
+
}
|
|
76
|
+
return channel;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build the full pattern by prepending the prefix.
|
|
80
|
+
*
|
|
81
|
+
* Used by psubscribe to namespace glob patterns the same way
|
|
82
|
+
* buildChannel namespaces exact channel names.
|
|
83
|
+
*
|
|
84
|
+
* @param pattern - User-provided pattern (e.g., 'order:*')
|
|
85
|
+
* @returns Prefixed pattern (e.g., 'MyApp:order:*')
|
|
86
|
+
*/
|
|
87
|
+
buildChannelPattern(pattern) {
|
|
88
|
+
if (this.channelPrefix) {
|
|
89
|
+
return `${this.channelPrefix}${CHANNEL_SEPARATOR}${pattern}`;
|
|
90
|
+
}
|
|
91
|
+
return pattern;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Strip the channel prefix from a full channel name.
|
|
95
|
+
*
|
|
96
|
+
* Used when delivering messages to handlers — they should see
|
|
97
|
+
* the original channel name, not the internal prefixed version.
|
|
98
|
+
* This keeps the handler code agnostic of the prefix configuration.
|
|
99
|
+
*
|
|
100
|
+
* @param fullChannel - The prefixed channel (from Redis or internal store)
|
|
101
|
+
* @returns The user-facing channel name without prefix
|
|
102
|
+
*/
|
|
103
|
+
stripPrefix(fullChannel) {
|
|
104
|
+
if (this.channelPrefix) {
|
|
105
|
+
const prefix = `${this.channelPrefix}${CHANNEL_SEPARATOR}`;
|
|
106
|
+
if (fullChannel.startsWith(prefix)) {
|
|
107
|
+
return fullChannel.slice(prefix.length);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return fullChannel;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Safely invoke a message handler, catching and logging errors.
|
|
114
|
+
*
|
|
115
|
+
* Handler errors must never break other subscribers or crash
|
|
116
|
+
* the subscriber connection. This method wraps every handler
|
|
117
|
+
* invocation in a try/catch and logs errors to console.error.
|
|
118
|
+
*
|
|
119
|
+
* @param handler - The handler function to invoke
|
|
120
|
+
* @param message - The message to pass to the handler
|
|
121
|
+
*/
|
|
122
|
+
async safeInvoke(handler, message) {
|
|
123
|
+
try {
|
|
124
|
+
await handler(message);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
// Log and continue — handler errors must not break other subscribers
|
|
128
|
+
console.error(`[PubSub] Handler error on channel "${message.channel}":`, error instanceof Error ? error.message : error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=abstract-pubsub-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-pubsub-provider.js","sourceRoot":"","sources":["../src/abstract-pubsub-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAgB,cAAc;IAChC,6CAA6C;IACnC,aAAa,CAAqB;IAE5C,2CAA2C;IACjC,YAAY,CAAS;IAE/B;;;;OAIG;IACH,YAAY,MAA4B;QACpC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,IAAI,2BAA2B,CAAC;IAC1E,CAAC;IAED,sEAAsE;IACtE,mBAAmB;IACnB,sEAAsE;IAEtE,0EAA0E;IAC1E,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,sEAAsE;IACtE,sDAAsD;IACtD,sEAAsE;IAEtE;;;;;;;;;OASG;IACO,YAAY,CAAC,OAAe;QAClC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO,GAAG,IAAI,CAAC,aAAa,GAAG,iBAAiB,GAAG,OAAO,EAAE,CAAC;QACjE,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED;;;;;;;;OAQG;IACO,mBAAmB,CAAC,OAAe;QACzC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO,GAAG,IAAI,CAAC,aAAa,GAAG,iBAAiB,GAAG,OAAO,EAAE,CAAC;QACjE,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED;;;;;;;;;OASG;IACO,WAAW,CAAC,WAAmB;QACrC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,GAAG,iBAAiB,EAAE,CAAC;YAC3D,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjC,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;QACD,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;;;;;;;OASG;IACO,KAAK,CAAC,UAAU,CAAI,OAA0B,EAAE,OAAyB;QAC/E,IAAI,CAAC;YACD,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,qEAAqE;YACrE,OAAO,CAAC,KAAK,CACT,sCAAsC,OAAO,CAAC,OAAO,IAAI,EACzD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CACjD,CAAC;QACN,CAAC;IACL,CAAC;CAqFJ"}
|