@signal24/dk-server-foundation 26.213.615
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/.gitattributes +2 -0
- package/.gitlab-ci.yml +49 -0
- package/.oxlintrc.json +40 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +15 -0
- package/.serena/project.yml +111 -0
- package/.vscode/launch.json +15 -0
- package/.vscode/settings.json +12 -0
- package/.yarnrc.yml +5 -0
- package/CLAUDE.md +279 -0
- package/LICENSE +21 -0
- package/README.md +439 -0
- package/TEST_MIGRATION_GUIDE.md +348 -0
- package/dist/resources/proto/generated/test/test.d.ts +224 -0
- package/dist/resources/proto/generated/test/test.d.ts.map +1 -0
- package/dist/resources/proto/generated/test/test.js +2376 -0
- package/dist/resources/proto/generated/test/test.js.map +1 -0
- package/dist/src/app/base.d.ts +37 -0
- package/dist/src/app/base.d.ts.map +1 -0
- package/dist/src/app/base.js +244 -0
- package/dist/src/app/base.js.map +1 -0
- package/dist/src/app/config.d.ts +91 -0
- package/dist/src/app/config.d.ts.map +1 -0
- package/dist/src/app/config.js +33 -0
- package/dist/src/app/config.js.map +1 -0
- package/dist/src/app/config.loader.d.ts +14 -0
- package/dist/src/app/config.loader.d.ts.map +1 -0
- package/dist/src/app/config.loader.js +67 -0
- package/dist/src/app/config.loader.js.map +1 -0
- package/dist/src/app/const.d.ts +3 -0
- package/dist/src/app/const.d.ts.map +1 -0
- package/dist/src/app/const.js +6 -0
- package/dist/src/app/const.js.map +1 -0
- package/dist/src/app/dev.d.ts +6 -0
- package/dist/src/app/dev.d.ts.map +1 -0
- package/dist/src/app/dev.js +78 -0
- package/dist/src/app/dev.js.map +1 -0
- package/dist/src/app/index.d.ts +7 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +12 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/openapi.d.ts +4 -0
- package/dist/src/app/openapi.d.ts.map +1 -0
- package/dist/src/app/openapi.js +6 -0
- package/dist/src/app/openapi.js.map +1 -0
- package/dist/src/app/resolver.d.ts +11 -0
- package/dist/src/app/resolver.d.ts.map +1 -0
- package/dist/src/app/resolver.js +60 -0
- package/dist/src/app/resolver.js.map +1 -0
- package/dist/src/app/shutdown.d.ts +12 -0
- package/dist/src/app/shutdown.d.ts.map +1 -0
- package/dist/src/app/shutdown.js +63 -0
- package/dist/src/app/shutdown.js.map +1 -0
- package/dist/src/app/state.d.ts +16 -0
- package/dist/src/app/state.d.ts.map +1 -0
- package/dist/src/app/state.js +12 -0
- package/dist/src/app/state.js.map +1 -0
- package/dist/src/auth/index.d.ts +3 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +6 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt.d.ts +76 -0
- package/dist/src/auth/jwt.d.ts.map +1 -0
- package/dist/src/auth/jwt.js +218 -0
- package/dist/src/auth/jwt.js.map +1 -0
- package/dist/src/auth/provider.d.ts +15 -0
- package/dist/src/auth/provider.d.ts.map +1 -0
- package/dist/src/auth/provider.js +50 -0
- package/dist/src/auth/provider.js.map +1 -0
- package/dist/src/cli/dksf-dev.d.ts +3 -0
- package/dist/src/cli/dksf-dev.d.ts.map +1 -0
- package/dist/src/cli/dksf-dev.js +359 -0
- package/dist/src/cli/dksf-dev.js.map +1 -0
- package/dist/src/cli/dksf-gen-proto.d.ts +3 -0
- package/dist/src/cli/dksf-gen-proto.d.ts.map +1 -0
- package/dist/src/cli/dksf-gen-proto.js +164 -0
- package/dist/src/cli/dksf-gen-proto.js.map +1 -0
- package/dist/src/cli/dksf-install.d.ts +3 -0
- package/dist/src/cli/dksf-install.d.ts.map +1 -0
- package/dist/src/cli/dksf-install.js +10 -0
- package/dist/src/cli/dksf-install.js.map +1 -0
- package/dist/src/cli/dksf-test.d.ts +3 -0
- package/dist/src/cli/dksf-test.d.ts.map +1 -0
- package/dist/src/cli/dksf-test.js +91 -0
- package/dist/src/cli/dksf-test.js.map +1 -0
- package/dist/src/cli/dksf-update.d.ts +3 -0
- package/dist/src/cli/dksf-update.d.ts.map +1 -0
- package/dist/src/cli/dksf-update.js +86 -0
- package/dist/src/cli/dksf-update.js.map +1 -0
- package/dist/src/database/common.d.ts +84 -0
- package/dist/src/database/common.d.ts.map +1 -0
- package/dist/src/database/common.js +380 -0
- package/dist/src/database/common.js.map +1 -0
- package/dist/src/database/dialect.d.ts +10 -0
- package/dist/src/database/dialect.d.ts.map +1 -0
- package/dist/src/database/dialect.js +56 -0
- package/dist/src/database/dialect.js.map +1 -0
- package/dist/src/database/entity.d.ts +62 -0
- package/dist/src/database/entity.d.ts.map +1 -0
- package/dist/src/database/entity.js +198 -0
- package/dist/src/database/entity.js.map +1 -0
- package/dist/src/database/index.d.ts +8 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/index.js +15 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/database/migration/MigrationResetCommand.d.ts +11 -0
- package/dist/src/database/migration/MigrationResetCommand.d.ts.map +1 -0
- package/dist/src/database/migration/MigrationResetCommand.js +149 -0
- package/dist/src/database/migration/MigrationResetCommand.js.map +1 -0
- package/dist/src/database/migration/MigrationRunCommand.d.ts +11 -0
- package/dist/src/database/migration/MigrationRunCommand.d.ts.map +1 -0
- package/dist/src/database/migration/MigrationRunCommand.js +118 -0
- package/dist/src/database/migration/MigrationRunCommand.js.map +1 -0
- package/dist/src/database/migration/characters.d.ts +14 -0
- package/dist/src/database/migration/characters.d.ts.map +1 -0
- package/dist/src/database/migration/characters.js +56 -0
- package/dist/src/database/migration/characters.js.map +1 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.d.ts +11 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.d.ts.map +1 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.js +104 -0
- package/dist/src/database/migration/create/MigrationCreateCommand.js.map +1 -0
- package/dist/src/database/migration/create/comparator.d.ts +3 -0
- package/dist/src/database/migration/create/comparator.d.ts.map +1 -0
- package/dist/src/database/migration/create/comparator.js +408 -0
- package/dist/src/database/migration/create/comparator.js.map +1 -0
- package/dist/src/database/migration/create/db-reader.d.ts +5 -0
- package/dist/src/database/migration/create/db-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/db-reader.js +473 -0
- package/dist/src/database/migration/create/db-reader.js.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts +3 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.js +725 -0
- package/dist/src/database/migration/create/ddl-generator.js.map +1 -0
- package/dist/src/database/migration/create/entity-reader.d.ts +4 -0
- package/dist/src/database/migration/create/entity-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/entity-reader.js +408 -0
- package/dist/src/database/migration/create/entity-reader.js.map +1 -0
- package/dist/src/database/migration/create/file-generator.d.ts +2 -0
- package/dist/src/database/migration/create/file-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/file-generator.js +55 -0
- package/dist/src/database/migration/create/file-generator.js.map +1 -0
- package/dist/src/database/migration/create/prompt.d.ts +4 -0
- package/dist/src/database/migration/create/prompt.d.ts.map +1 -0
- package/dist/src/database/migration/create/prompt.js +55 -0
- package/dist/src/database/migration/create/prompt.js.map +1 -0
- package/dist/src/database/migration/create/schema-model.d.ts +109 -0
- package/dist/src/database/migration/create/schema-model.d.ts.map +1 -0
- package/dist/src/database/migration/create/schema-model.js +24 -0
- package/dist/src/database/migration/create/schema-model.js.map +1 -0
- package/dist/src/database/migration/helpers.d.ts +2 -0
- package/dist/src/database/migration/helpers.d.ts.map +1 -0
- package/dist/src/database/migration/helpers.js +8 -0
- package/dist/src/database/migration/helpers.js.map +1 -0
- package/dist/src/database/migration/index.d.ts +9 -0
- package/dist/src/database/migration/index.d.ts.map +1 -0
- package/dist/src/database/migration/index.js +43 -0
- package/dist/src/database/migration/index.js.map +1 -0
- package/dist/src/database/migration/migration.entity.d.ts +8 -0
- package/dist/src/database/migration/migration.entity.d.ts.map +1 -0
- package/dist/src/database/migration/migration.entity.js +16 -0
- package/dist/src/database/migration/migration.entity.js.map +1 -0
- package/dist/src/database/mysql.d.ts +16 -0
- package/dist/src/database/mysql.d.ts.map +1 -0
- package/dist/src/database/mysql.js +140 -0
- package/dist/src/database/mysql.js.map +1 -0
- package/dist/src/database/postgres.d.ts +16 -0
- package/dist/src/database/postgres.d.ts.map +1 -0
- package/dist/src/database/postgres.js +91 -0
- package/dist/src/database/postgres.js.map +1 -0
- package/dist/src/database/types.d.ts +21 -0
- package/dist/src/database/types.d.ts.map +1 -0
- package/dist/src/database/types.js +27 -0
- package/dist/src/database/types.js.map +1 -0
- package/dist/src/health/health.module.d.ts +6 -0
- package/dist/src/health/health.module.d.ts.map +1 -0
- package/dist/src/health/health.module.js +32 -0
- package/dist/src/health/health.module.js.map +1 -0
- package/dist/src/health/healthcheck.controller.d.ts +10 -0
- package/dist/src/health/healthcheck.controller.d.ts.map +1 -0
- package/dist/src/health/healthcheck.controller.js +30 -0
- package/dist/src/health/healthcheck.controller.js.map +1 -0
- package/dist/src/health/healthcheck.service.d.ts +8 -0
- package/dist/src/health/healthcheck.service.d.ts.map +1 -0
- package/dist/src/health/healthcheck.service.js +20 -0
- package/dist/src/health/healthcheck.service.js.map +1 -0
- package/dist/src/health/index.d.ts +3 -0
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +6 -0
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/helpers/async/context.d.ts +11 -0
- package/dist/src/helpers/async/context.d.ts.map +1 -0
- package/dist/src/helpers/async/context.js +75 -0
- package/dist/src/helpers/async/context.js.map +1 -0
- package/dist/src/helpers/async/process.d.ts +16 -0
- package/dist/src/helpers/async/process.d.ts.map +1 -0
- package/dist/src/helpers/async/process.js +44 -0
- package/dist/src/helpers/async/process.js.map +1 -0
- package/dist/src/helpers/async/promise.d.ts +5 -0
- package/dist/src/helpers/async/promise.d.ts.map +1 -0
- package/dist/src/helpers/async/promise.js +27 -0
- package/dist/src/helpers/async/promise.js.map +1 -0
- package/dist/src/helpers/data/array.d.ts +3 -0
- package/dist/src/helpers/data/array.d.ts.map +1 -0
- package/dist/src/helpers/data/array.js +17 -0
- package/dist/src/helpers/data/array.js.map +1 -0
- package/dist/src/helpers/data/objects.d.ts +12 -0
- package/dist/src/helpers/data/objects.d.ts.map +1 -0
- package/dist/src/helpers/data/objects.js +75 -0
- package/dist/src/helpers/data/objects.js.map +1 -0
- package/dist/src/helpers/data/serialization.d.ts +4 -0
- package/dist/src/helpers/data/serialization.d.ts.map +1 -0
- package/dist/src/helpers/data/serialization.js +15 -0
- package/dist/src/helpers/data/serialization.js.map +1 -0
- package/dist/src/helpers/data/transformer.d.ts +13 -0
- package/dist/src/helpers/data/transformer.d.ts.map +1 -0
- package/dist/src/helpers/data/transformer.js +55 -0
- package/dist/src/helpers/data/transformer.js.map +1 -0
- package/dist/src/helpers/framework/decorators.d.ts +5 -0
- package/dist/src/helpers/framework/decorators.d.ts.map +1 -0
- package/dist/src/helpers/framework/decorators.js +39 -0
- package/dist/src/helpers/framework/decorators.js.map +1 -0
- package/dist/src/helpers/framework/event.d.ts +3 -0
- package/dist/src/helpers/framework/event.d.ts.map +1 -0
- package/dist/src/helpers/framework/event.js +20 -0
- package/dist/src/helpers/framework/event.js.map +1 -0
- package/dist/src/helpers/framework/injection.d.ts +7 -0
- package/dist/src/helpers/framework/injection.d.ts.map +1 -0
- package/dist/src/helpers/framework/injection.js +52 -0
- package/dist/src/helpers/framework/injection.js.map +1 -0
- package/dist/src/helpers/index.d.ts +22 -0
- package/dist/src/helpers/index.d.ts.map +1 -0
- package/dist/src/helpers/index.js +32 -0
- package/dist/src/helpers/index.js.map +1 -0
- package/dist/src/helpers/io/package.d.ts +5 -0
- package/dist/src/helpers/io/package.d.ts.map +1 -0
- package/dist/src/helpers/io/package.js +31 -0
- package/dist/src/helpers/io/package.js.map +1 -0
- package/dist/src/helpers/io/stream.d.ts +18 -0
- package/dist/src/helpers/io/stream.d.ts.map +1 -0
- package/dist/src/helpers/io/stream.js +91 -0
- package/dist/src/helpers/io/stream.js.map +1 -0
- package/dist/src/helpers/redis/broadcast.d.ts +12 -0
- package/dist/src/helpers/redis/broadcast.d.ts.map +1 -0
- package/dist/src/helpers/redis/broadcast.js +99 -0
- package/dist/src/helpers/redis/broadcast.js.map +1 -0
- package/dist/src/helpers/redis/cache.d.ts +7 -0
- package/dist/src/helpers/redis/cache.d.ts.map +1 -0
- package/dist/src/helpers/redis/cache.js +28 -0
- package/dist/src/helpers/redis/cache.js.map +1 -0
- package/dist/src/helpers/redis/mutex.d.ts +24 -0
- package/dist/src/helpers/redis/mutex.d.ts.map +1 -0
- package/dist/src/helpers/redis/mutex.js +240 -0
- package/dist/src/helpers/redis/mutex.js.map +1 -0
- package/dist/src/helpers/redis/redis.d.ts +11 -0
- package/dist/src/helpers/redis/redis.d.ts.map +1 -0
- package/dist/src/helpers/redis/redis.js +59 -0
- package/dist/src/helpers/redis/redis.js.map +1 -0
- package/dist/src/helpers/security/crypto.d.ts +26 -0
- package/dist/src/helpers/security/crypto.d.ts.map +1 -0
- package/dist/src/helpers/security/crypto.js +121 -0
- package/dist/src/helpers/security/crypto.js.map +1 -0
- package/dist/src/helpers/security/validation.d.ts +4 -0
- package/dist/src/helpers/security/validation.d.ts.map +1 -0
- package/dist/src/helpers/security/validation.js +25 -0
- package/dist/src/helpers/security/validation.js.map +1 -0
- package/dist/src/helpers/utils/date.d.ts +4 -0
- package/dist/src/helpers/utils/date.d.ts.map +1 -0
- package/dist/src/helpers/utils/date.js +23 -0
- package/dist/src/helpers/utils/date.js.map +1 -0
- package/dist/src/helpers/utils/error.d.ts +24 -0
- package/dist/src/helpers/utils/error.d.ts.map +1 -0
- package/dist/src/helpers/utils/error.js +168 -0
- package/dist/src/helpers/utils/error.js.map +1 -0
- package/dist/src/helpers/utils/jsx.d.ts +3 -0
- package/dist/src/helpers/utils/jsx.d.ts.map +1 -0
- package/dist/src/helpers/utils/jsx.js +13 -0
- package/dist/src/helpers/utils/jsx.js.map +1 -0
- package/dist/src/helpers/utils/uuid.d.ts +3 -0
- package/dist/src/helpers/utils/uuid.d.ts.map +1 -0
- package/dist/src/helpers/utils/uuid.js +14 -0
- package/dist/src/helpers/utils/uuid.js.map +1 -0
- package/dist/src/http/auth.d.ts +46 -0
- package/dist/src/http/auth.d.ts.map +1 -0
- package/dist/src/http/auth.js +162 -0
- package/dist/src/http/auth.js.map +1 -0
- package/dist/src/http/context.d.ts +5 -0
- package/dist/src/http/context.d.ts.map +1 -0
- package/dist/src/http/context.js +22 -0
- package/dist/src/http/context.js.map +1 -0
- package/dist/src/http/cors.d.ts +36 -0
- package/dist/src/http/cors.d.ts.map +1 -0
- package/dist/src/http/cors.js +171 -0
- package/dist/src/http/cors.js.map +1 -0
- package/dist/src/http/errors.d.ts +3 -0
- package/dist/src/http/errors.d.ts.map +1 -0
- package/dist/src/http/errors.js +10 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/index.d.ts +24 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +25 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/kernel.d.ts +17 -0
- package/dist/src/http/kernel.d.ts.map +1 -0
- package/dist/src/http/kernel.js +133 -0
- package/dist/src/http/kernel.js.map +1 -0
- package/dist/src/http/middleware.d.ts +12 -0
- package/dist/src/http/middleware.d.ts.map +1 -0
- package/dist/src/http/middleware.js +61 -0
- package/dist/src/http/middleware.js.map +1 -0
- package/dist/src/http/overrides.d.ts +2 -0
- package/dist/src/http/overrides.d.ts.map +1 -0
- package/dist/src/http/overrides.js +19 -0
- package/dist/src/http/overrides.js.map +1 -0
- package/dist/src/http/store.d.ts +33 -0
- package/dist/src/http/store.d.ts.map +1 -0
- package/dist/src/http/store.js +102 -0
- package/dist/src/http/store.js.map +1 -0
- package/dist/src/http/uploads.d.ts +7 -0
- package/dist/src/http/uploads.d.ts.map +1 -0
- package/dist/src/http/uploads.js +8 -0
- package/dist/src/http/uploads.js.map +1 -0
- package/dist/src/http/workflow.d.ts +18 -0
- package/dist/src/http/workflow.d.ts.map +1 -0
- package/dist/src/http/workflow.js +181 -0
- package/dist/src/http/workflow.js.map +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/services/cli/invoke.d.ts +5 -0
- package/dist/src/services/cli/invoke.d.ts.map +1 -0
- package/dist/src/services/cli/invoke.js +45 -0
- package/dist/src/services/cli/invoke.js.map +1 -0
- package/dist/src/services/cli/repl.d.ts +5 -0
- package/dist/src/services/cli/repl.d.ts.map +1 -0
- package/dist/src/services/cli/repl.js +71 -0
- package/dist/src/services/cli/repl.js.map +1 -0
- package/dist/src/services/cli.d.ts +12 -0
- package/dist/src/services/cli.d.ts.map +1 -0
- package/dist/src/services/cli.js +76 -0
- package/dist/src/services/cli.js.map +1 -0
- package/dist/src/services/index.d.ts +7 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +10 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/leader.d.ts +32 -0
- package/dist/src/services/leader.d.ts.map +1 -0
- package/dist/src/services/leader.js +174 -0
- package/dist/src/services/leader.js.map +1 -0
- package/dist/src/services/logger.d.ts +35 -0
- package/dist/src/services/logger.d.ts.map +1 -0
- package/dist/src/services/logger.js +245 -0
- package/dist/src/services/logger.js.map +1 -0
- package/dist/src/services/mail/index.d.ts +61 -0
- package/dist/src/services/mail/index.d.ts.map +1 -0
- package/dist/src/services/mail/index.js +90 -0
- package/dist/src/services/mail/index.js.map +1 -0
- package/dist/src/services/mail/postmark.d.ts +11 -0
- package/dist/src/services/mail/postmark.d.ts.map +1 -0
- package/dist/src/services/mail/postmark.js +42 -0
- package/dist/src/services/mail/postmark.js.map +1 -0
- package/dist/src/services/mail/smtp.d.ts +11 -0
- package/dist/src/services/mail/smtp.d.ts.map +1 -0
- package/dist/src/services/mail/smtp.js +61 -0
- package/dist/src/services/mail/smtp.js.map +1 -0
- package/dist/src/services/mesh.d.ts +65 -0
- package/dist/src/services/mesh.d.ts.map +1 -0
- package/dist/src/services/mesh.js +422 -0
- package/dist/src/services/mesh.js.map +1 -0
- package/dist/src/services/worker/bootstrap.d.ts +3 -0
- package/dist/src/services/worker/bootstrap.d.ts.map +1 -0
- package/dist/src/services/worker/bootstrap.js +70 -0
- package/dist/src/services/worker/bootstrap.js.map +1 -0
- package/dist/src/services/worker/cli.d.ts +23 -0
- package/dist/src/services/worker/cli.d.ts.map +1 -0
- package/dist/src/services/worker/cli.js +81 -0
- package/dist/src/services/worker/cli.js.map +1 -0
- package/dist/src/services/worker/entity.d.ts +18 -0
- package/dist/src/services/worker/entity.d.ts.map +1 -0
- package/dist/src/services/worker/entity.js +16 -0
- package/dist/src/services/worker/entity.js.map +1 -0
- package/dist/src/services/worker/index.d.ts +9 -0
- package/dist/src/services/worker/index.d.ts.map +1 -0
- package/dist/src/services/worker/index.js +40 -0
- package/dist/src/services/worker/index.js.map +1 -0
- package/dist/src/services/worker/observer.d.ts +18 -0
- package/dist/src/services/worker/observer.d.ts.map +1 -0
- package/dist/src/services/worker/observer.js +172 -0
- package/dist/src/services/worker/observer.js.map +1 -0
- package/dist/src/services/worker/queue.d.ts +8 -0
- package/dist/src/services/worker/queue.d.ts.map +1 -0
- package/dist/src/services/worker/queue.js +31 -0
- package/dist/src/services/worker/queue.js.map +1 -0
- package/dist/src/services/worker/runner.d.ts +17 -0
- package/dist/src/services/worker/runner.d.ts.map +1 -0
- package/dist/src/services/worker/runner.js +131 -0
- package/dist/src/services/worker/runner.js.map +1 -0
- package/dist/src/services/worker/types.d.ts +26 -0
- package/dist/src/services/worker/types.d.ts.map +1 -0
- package/dist/src/services/worker/types.js +29 -0
- package/dist/src/services/worker/types.js.map +1 -0
- package/dist/src/srpc/SrpcByteStream.d.ts +67 -0
- package/dist/src/srpc/SrpcByteStream.d.ts.map +1 -0
- package/dist/src/srpc/SrpcByteStream.js +319 -0
- package/dist/src/srpc/SrpcByteStream.js.map +1 -0
- package/dist/src/srpc/SrpcClient.d.ts +75 -0
- package/dist/src/srpc/SrpcClient.d.ts.map +1 -0
- package/dist/src/srpc/SrpcClient.js +445 -0
- package/dist/src/srpc/SrpcClient.js.map +1 -0
- package/dist/src/srpc/SrpcServer.d.ts +54 -0
- package/dist/src/srpc/SrpcServer.d.ts.map +1 -0
- package/dist/src/srpc/SrpcServer.js +456 -0
- package/dist/src/srpc/SrpcServer.js.map +1 -0
- package/dist/src/srpc/index.d.ts +7 -0
- package/dist/src/srpc/index.d.ts.map +1 -0
- package/dist/src/srpc/index.js +12 -0
- package/dist/src/srpc/index.js.map +1 -0
- package/dist/src/srpc/types.d.ts +129 -0
- package/dist/src/srpc/types.d.ts.map +1 -0
- package/dist/src/srpc/types.js +65 -0
- package/dist/src/srpc/types.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +2 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +5 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.d.ts +22 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.d.ts.map +1 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.js +248 -0
- package/dist/src/telemetry/otel/MariaDBInstrumentation.js.map +1 -0
- package/dist/src/telemetry/otel/helpers.d.ts +27 -0
- package/dist/src/telemetry/otel/helpers.d.ts.map +1 -0
- package/dist/src/telemetry/otel/helpers.js +126 -0
- package/dist/src/telemetry/otel/helpers.js.map +1 -0
- package/dist/src/telemetry/otel/index.d.ts +14 -0
- package/dist/src/telemetry/otel/index.d.ts.map +1 -0
- package/dist/src/telemetry/otel/index.js +132 -0
- package/dist/src/telemetry/otel/index.js.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts +6 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.js +63 -0
- package/dist/src/telemetry/otel/metrics.controller.js.map +1 -0
- package/dist/src/telemetry/sentry.d.ts +9 -0
- package/dist/src/telemetry/sentry.d.ts.map +1 -0
- package/dist/src/telemetry/sentry.js +62 -0
- package/dist/src/telemetry/sentry.js.map +1 -0
- package/dist/src/testapp/bootstrap.d.ts +1 -0
- package/dist/src/testapp/bootstrap.d.ts.map +1 -0
- package/dist/src/testapp/bootstrap.js +18 -0
- package/dist/src/testapp/bootstrap.js.map +1 -0
- package/dist/src/testapp/sample.d.ts +6 -0
- package/dist/src/testapp/sample.d.ts.map +1 -0
- package/dist/src/testapp/sample.js +228 -0
- package/dist/src/testapp/sample.js.map +1 -0
- package/dist/src/testapp/srpc-test.d.ts +27 -0
- package/dist/src/testapp/srpc-test.d.ts.map +1 -0
- package/dist/src/testapp/srpc-test.js +570 -0
- package/dist/src/testapp/srpc-test.js.map +1 -0
- package/dist/src/testing/expect.d.ts +25 -0
- package/dist/src/testing/expect.d.ts.map +1 -0
- package/dist/src/testing/expect.js +151 -0
- package/dist/src/testing/expect.js.map +1 -0
- package/dist/src/testing/fixtures.d.ts +19 -0
- package/dist/src/testing/fixtures.d.ts.map +1 -0
- package/dist/src/testing/fixtures.js +69 -0
- package/dist/src/testing/fixtures.js.map +1 -0
- package/dist/src/testing/index.d.ts +260 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +345 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/requests.d.ts +10 -0
- package/dist/src/testing/requests.d.ts.map +1 -0
- package/dist/src/testing/requests.js +56 -0
- package/dist/src/testing/requests.js.map +1 -0
- package/dist/src/testing/sql.d.ts +11 -0
- package/dist/src/testing/sql.d.ts.map +1 -0
- package/dist/src/testing/sql.js +55 -0
- package/dist/src/testing/sql.js.map +1 -0
- package/dist/src/types/index.d.ts +57 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +73 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/phone.d.ts +11 -0
- package/dist/src/types/phone.d.ts.map +1 -0
- package/dist/src/types/phone.js +73 -0
- package/dist/src/types/phone.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/README.md +38 -0
- package/docs/authentication.md +215 -0
- package/docs/cli.md +302 -0
- package/docs/configuration.md +176 -0
- package/docs/database.md +422 -0
- package/docs/getting-started.md +154 -0
- package/docs/health.md +53 -0
- package/docs/helpers.md +436 -0
- package/docs/http.md +253 -0
- package/docs/leader-service.md +98 -0
- package/docs/logging.md +150 -0
- package/docs/mail.md +161 -0
- package/docs/mesh-service.md +204 -0
- package/docs/srpc.md +261 -0
- package/docs/telemetry.md +166 -0
- package/docs/testing.md +222 -0
- package/docs/types.md +215 -0
- package/docs/worker.md +174 -0
- package/lefthook.yml +12 -0
- package/openapi.yaml +109 -0
- package/package.json +133 -0
- package/patches/@deepkit+type+1.0.19.patch +38 -0
- package/resources/proto/generated/test/test.ts +2721 -0
- package/resources/proto/sample.proto +85 -0
- package/resources/proto/test.proto +178 -0
- package/src/app/base.ts +257 -0
- package/src/app/config.loader.ts +66 -0
- package/src/app/config.ts +120 -0
- package/src/app/const.ts +4 -0
- package/src/app/dev.ts +70 -0
- package/src/app/index.ts +6 -0
- package/src/app/openapi.ts +3 -0
- package/src/app/resolver.ts +49 -0
- package/src/app/shutdown.ts +55 -0
- package/src/app/state.ts +19 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/jwt.ts +275 -0
- package/src/auth/provider.ts +57 -0
- package/src/cli/dksf-dev.ts +363 -0
- package/src/cli/dksf-gen-proto.ts +176 -0
- package/src/cli/dksf-install.ts +11 -0
- package/src/cli/dksf-test.ts +95 -0
- package/src/cli/dksf-update.ts +101 -0
- package/src/database/CLAUDE.md +390 -0
- package/src/database/common.ts +385 -0
- package/src/database/dialect.ts +43 -0
- package/src/database/entity.ts +285 -0
- package/src/database/index.ts +7 -0
- package/src/database/migration/MigrationResetCommand.ts +152 -0
- package/src/database/migration/MigrationRunCommand.ts +118 -0
- package/src/database/migration/characters.ts +53 -0
- package/src/database/migration/create/MigrationCreateCommand.ts +94 -0
- package/src/database/migration/create/comparator.ts +467 -0
- package/src/database/migration/create/db-reader.ts +510 -0
- package/src/database/migration/create/ddl-generator.ts +755 -0
- package/src/database/migration/create/entity-reader.ts +462 -0
- package/src/database/migration/create/file-generator.ts +52 -0
- package/src/database/migration/create/prompt.ts +49 -0
- package/src/database/migration/create/schema-model.ts +102 -0
- package/src/database/migration/helpers.ts +3 -0
- package/src/database/migration/index.ts +35 -0
- package/src/database/migration/migration.entity.ts +10 -0
- package/src/database/mysql.ts +140 -0
- package/src/database/postgres.ts +97 -0
- package/src/database/types.ts +18 -0
- package/src/health/health.module.ts +30 -0
- package/src/health/healthcheck.controller.ts +17 -0
- package/src/health/healthcheck.service.ts +15 -0
- package/src/health/index.ts +2 -0
- package/src/helpers/CLAUDE.md +71 -0
- package/src/helpers/async/context.ts +67 -0
- package/src/helpers/async/process.ts +49 -0
- package/src/helpers/async/promise.ts +16 -0
- package/src/helpers/data/array.ts +11 -0
- package/src/helpers/data/objects.ts +64 -0
- package/src/helpers/data/serialization.ts +11 -0
- package/src/helpers/data/transformer.ts +54 -0
- package/src/helpers/framework/decorators.ts +27 -0
- package/src/helpers/framework/event.ts +11 -0
- package/src/helpers/framework/injection.ts +47 -0
- package/src/helpers/index.ts +34 -0
- package/src/helpers/io/package.ts +26 -0
- package/src/helpers/io/stream.ts +79 -0
- package/src/helpers/redis/broadcast.ts +94 -0
- package/src/helpers/redis/cache.ts +28 -0
- package/src/helpers/redis/mutex.ts +260 -0
- package/src/helpers/redis/redis.ts +60 -0
- package/src/helpers/security/crypto.ts +133 -0
- package/src/helpers/security/validation.ts +16 -0
- package/src/helpers/utils/date.ts +13 -0
- package/src/helpers/utils/error.ts +155 -0
- package/src/helpers/utils/jsx.ts +8 -0
- package/src/helpers/utils/uuid.ts +8 -0
- package/src/http/auth.ts +156 -0
- package/src/http/context.ts +15 -0
- package/src/http/cors.ts +159 -0
- package/src/http/errors.ts +9 -0
- package/src/http/index.ts +19 -0
- package/src/http/kernel.ts +138 -0
- package/src/http/middleware.ts +59 -0
- package/src/http/overrides.ts +20 -0
- package/src/http/store.ts +86 -0
- package/src/http/uploads.ts +6 -0
- package/src/http/workflow.ts +167 -0
- package/src/index.ts +19 -0
- package/src/services/cli/invoke.ts +39 -0
- package/src/services/cli/repl.ts +67 -0
- package/src/services/cli.ts +74 -0
- package/src/services/index.ts +6 -0
- package/src/services/leader.ts +201 -0
- package/src/services/logger.ts +258 -0
- package/src/services/mail/index.ts +117 -0
- package/src/services/mail/postmark.ts +37 -0
- package/src/services/mail/smtp.ts +46 -0
- package/src/services/mesh.ts +508 -0
- package/src/services/worker/CLAUDE.md +77 -0
- package/src/services/worker/bootstrap.ts +58 -0
- package/src/services/worker/cli.ts +63 -0
- package/src/services/worker/entity.ts +22 -0
- package/src/services/worker/index.ts +30 -0
- package/src/services/worker/observer.ts +180 -0
- package/src/services/worker/queue.ts +34 -0
- package/src/services/worker/runner.ts +146 -0
- package/src/services/worker/types.ts +32 -0
- package/src/srpc/CLAUDE.md +194 -0
- package/src/srpc/SRPC_MIGRATION_GUIDE.md +348 -0
- package/src/srpc/SrpcByteStream.ts +382 -0
- package/src/srpc/SrpcClient.ts +512 -0
- package/src/srpc/SrpcServer.ts +575 -0
- package/src/srpc/index.ts +15 -0
- package/src/srpc/types.ts +144 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/otel/MariaDBInstrumentation.ts +297 -0
- package/src/telemetry/otel/helpers.ts +117 -0
- package/src/telemetry/otel/index.ts +150 -0
- package/src/telemetry/otel/metrics.controller.ts +50 -0
- package/src/telemetry/sentry.ts +58 -0
- package/src/testapp/bootstrap.ts +17 -0
- package/src/testapp/sample.ts +220 -0
- package/src/testapp/srpc-test.ts +684 -0
- package/src/testing/expect.ts +148 -0
- package/src/testing/fixtures.ts +62 -0
- package/src/testing/index.ts +355 -0
- package/src/testing/requests.ts +68 -0
- package/src/testing/sql.ts +50 -0
- package/src/types/index.ts +64 -0
- package/src/types/phone.ts +64 -0
- package/tests/app/app.spec.ts +53 -0
- package/tests/app/type.spec.ts +22 -0
- package/tests/auth/jwt.spec.ts +90 -0
- package/tests/database/entity.spec.ts +382 -0
- package/tests/database/locks.spec.ts +142 -0
- package/tests/database/migration-create-integration.spec.ts +234 -0
- package/tests/database/migration-create-unit.spec.ts +3896 -0
- package/tests/helpers/array.spec.ts +80 -0
- package/tests/helpers/cache.spec.ts +202 -0
- package/tests/helpers/crypto.spec.ts +236 -0
- package/tests/helpers/date.spec.ts +94 -0
- package/tests/helpers/error.spec.ts +233 -0
- package/tests/helpers/mutex.spec.ts +354 -0
- package/tests/helpers/objects.spec.ts +212 -0
- package/tests/helpers/package.spec.ts +90 -0
- package/tests/helpers/promise.spec.ts +119 -0
- package/tests/helpers/redis.spec.ts +50 -0
- package/tests/helpers/serialization.spec.ts +150 -0
- package/tests/helpers/stream.spec.ts +225 -0
- package/tests/helpers/validation.spec.ts +133 -0
- package/tests/services/leader.spec.ts +257 -0
- package/tests/services/logger.spec.ts +269 -0
- package/tests/services/mesh.spec.ts +814 -0
- package/tests/shared/db.ts +105 -0
- package/tests/shared/globalSetup.ts +48 -0
- package/tests/shared/helpers.ts +40 -0
- package/tests/srpc/SrpcByteStream.spec.ts +542 -0
- package/tests/tsconfig.json +4 -0
- package/tests/types/index.spec.ts +60 -0
- package/tests/types/phone.spec.ts +140 -0
- package/tsconfig.json +106 -0
- package/tsconfig.test.json +8 -0
- package/types.d.ts +6 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { pick } from 'lodash';
|
|
2
|
+
|
|
3
|
+
import { asyncMap } from './array';
|
|
4
|
+
|
|
5
|
+
export class Transformer<I> {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
private executor?: (input: I[]) => any[] | Promise<any[]>;
|
|
8
|
+
|
|
9
|
+
static create<I>(input: I[]): Transformer<I> {
|
|
10
|
+
return new Transformer(input);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
constructor(private input: I[] | Transformer<any>) {}
|
|
15
|
+
|
|
16
|
+
apply<O>(fn: (input: I[]) => O[] | Promise<O[]>, shouldApply = true): Transformer<O> {
|
|
17
|
+
this.executor = shouldApply ? fn : input => input;
|
|
18
|
+
return new Transformer<O>(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
applyEach<O>(fn: (input: I) => O, shouldApply = true): Transformer<O> {
|
|
22
|
+
return this.apply(arr => arr.map(fn), shouldApply);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
applyEachAsync<O>(fn: (input: I) => Promise<O>, shouldApply = true): Transformer<O> {
|
|
26
|
+
return this.apply(arr => asyncMap(arr, fn), shouldApply);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
narrow<K extends (keyof I)[]>(...keys: K): Transformer<Pick<I, K[number]>> {
|
|
30
|
+
return this.apply(input => {
|
|
31
|
+
return input.map(i => {
|
|
32
|
+
return pick(i, ...keys) as Pick<I, K[number]>;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
async execute(): Promise<any[]> {
|
|
39
|
+
if (!this.executor) {
|
|
40
|
+
throw new Error('No executor defined');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const input = await this.get();
|
|
44
|
+
return this.executor(input);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async get(): Promise<I[]> {
|
|
48
|
+
if (this.input instanceof Transformer) {
|
|
49
|
+
return await this.input.execute();
|
|
50
|
+
} else {
|
|
51
|
+
return this.input;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ClassType } from '@deepkit/core';
|
|
2
|
+
|
|
3
|
+
export function createSymbolAttachmentClassDecorator(aSymbol: symbol) {
|
|
4
|
+
return (): ClassDecorator => {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
return (target: any) => {
|
|
7
|
+
target[aSymbol] = aSymbol;
|
|
8
|
+
return target;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DecoratorRegistry = new Map<symbol, ClassType[]>();
|
|
14
|
+
export function createRegistryClassDecorator(aSymbol: symbol) {
|
|
15
|
+
return (): ClassDecorator => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
return (target: any) => {
|
|
18
|
+
const classes = DecoratorRegistry.get(aSymbol) ?? [];
|
|
19
|
+
classes.push(target);
|
|
20
|
+
DecoratorRegistry.set(aSymbol, classes);
|
|
21
|
+
return target;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function getRegisteredClasses<T extends ClassType>(aSymbol: symbol): T[] {
|
|
26
|
+
return (DecoratorRegistry.get(aSymbol) as T[]) ?? [];
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClassType } from '@deepkit/core';
|
|
2
|
+
import { eventClass, eventDispatcher } from '@deepkit/event';
|
|
3
|
+
|
|
4
|
+
export function applyParentEventHandlers(target: ClassType) {
|
|
5
|
+
const parent = Object.getPrototypeOf(target);
|
|
6
|
+
const config = eventClass._fetch(parent);
|
|
7
|
+
config?.listeners.forEach(listener => {
|
|
8
|
+
eventDispatcher.listen(listener.eventToken, listener.order)(target.prototype, listener.methodName);
|
|
9
|
+
});
|
|
10
|
+
return target;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getClassName, isClass } from '@deepkit/core';
|
|
2
|
+
import { InjectorModule, isClassProvider, isExistingProvider, isFactoryProvider, isValueProvider } from '@deepkit/injector';
|
|
3
|
+
import { compact } from 'lodash';
|
|
4
|
+
|
|
5
|
+
export function getProviderTree(module: InjectorModule) {
|
|
6
|
+
const result = compact(
|
|
7
|
+
module.providers.map(p => {
|
|
8
|
+
if (isClass(p)) {
|
|
9
|
+
const name = getProviderName(p);
|
|
10
|
+
if (name) {
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
module,
|
|
14
|
+
provide: p
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
} else if (isValueProvider(p) || isClassProvider(p) || isExistingProvider(p) || isFactoryProvider(p)) {
|
|
18
|
+
if (p.scope) return null;
|
|
19
|
+
|
|
20
|
+
const name = getProviderName(p.provide);
|
|
21
|
+
if (name) {
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
module,
|
|
25
|
+
provide: p.provide
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
for (const anImport of module.imports) {
|
|
34
|
+
result.push(...getProviderTree(anImport));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
function getProviderName(p: any) {
|
|
42
|
+
if (typeof p === 'string') {
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
const className = getClassName(p);
|
|
46
|
+
return className !== 'undefined' && className !== 'anonymous class' ? className : null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Data manipulation
|
|
2
|
+
export * from './data/array';
|
|
3
|
+
export * from './data/objects';
|
|
4
|
+
export * from './data/serialization';
|
|
5
|
+
export * from './data/transformer';
|
|
6
|
+
|
|
7
|
+
// Async & concurrency
|
|
8
|
+
export * from './async/context';
|
|
9
|
+
export * from './async/process';
|
|
10
|
+
export * from './async/promise';
|
|
11
|
+
|
|
12
|
+
// Redis-based features
|
|
13
|
+
export * from './redis/broadcast';
|
|
14
|
+
export * from './redis/cache';
|
|
15
|
+
export * from './redis/mutex';
|
|
16
|
+
export * from './redis/redis';
|
|
17
|
+
|
|
18
|
+
// I/O operations
|
|
19
|
+
export * from './io/package';
|
|
20
|
+
export * from './io/stream';
|
|
21
|
+
|
|
22
|
+
// Security & cryptography
|
|
23
|
+
export * from './security/crypto';
|
|
24
|
+
export * from './security/validation';
|
|
25
|
+
|
|
26
|
+
// Framework helpers
|
|
27
|
+
export * from './framework/event';
|
|
28
|
+
export * from './framework/injection';
|
|
29
|
+
|
|
30
|
+
// Utilities
|
|
31
|
+
export * from './utils/date';
|
|
32
|
+
export * from './utils/error';
|
|
33
|
+
export * from './utils/jsx';
|
|
34
|
+
export * from './utils/uuid';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { memoize } from 'lodash';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { cwd } from 'process';
|
|
5
|
+
import type { PackageJson } from 'type-fest';
|
|
6
|
+
|
|
7
|
+
export const getPackageJson: () => PackageJson | undefined = memoize(() => {
|
|
8
|
+
try {
|
|
9
|
+
const pkgJsonStr = readFileSync(join(cwd(), 'package.json'), 'utf8');
|
|
10
|
+
const pkgJson = JSON.parse(pkgJsonStr);
|
|
11
|
+
return pkgJson;
|
|
12
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export function getPackageVersion() {
|
|
19
|
+
const pkgJson = getPackageJson();
|
|
20
|
+
return pkgJson?.version;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getPackageName() {
|
|
24
|
+
const pkgJson = getPackageJson();
|
|
25
|
+
return pkgJson?.name;
|
|
26
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { unlink } from 'fs/promises';
|
|
2
|
+
import { Readable, Writable } from 'stream';
|
|
3
|
+
|
|
4
|
+
export class PipeError extends Error {
|
|
5
|
+
constructor(
|
|
6
|
+
public readonly cause: Error,
|
|
7
|
+
public readonly side: 'input' | 'output'
|
|
8
|
+
) {
|
|
9
|
+
super(cause.message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function safePipe(input: Readable, output: Writable) {
|
|
14
|
+
return new Promise<void>((resolve, reject) => {
|
|
15
|
+
input.on('close', () => {
|
|
16
|
+
if (!input.readableEnded) {
|
|
17
|
+
if (!output.destroyed) output.destroy();
|
|
18
|
+
reject(new PipeError(new Error('Input stream aborted'), 'input'));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
input.on('error', err => {
|
|
22
|
+
if (!output.destroyed) output.destroy();
|
|
23
|
+
reject(new PipeError(err, 'input'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
output.on('close', () => {
|
|
27
|
+
if (!output.writableEnded) {
|
|
28
|
+
if (!input.destroyed) input.destroy();
|
|
29
|
+
reject(new PipeError(new Error('Output stream aborted'), 'output'));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
output.on('error', err => {
|
|
33
|
+
if (!input.destroyed) input.destroy();
|
|
34
|
+
reject(new PipeError(err, 'output'));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
output.on('finish', () => {
|
|
38
|
+
resolve();
|
|
39
|
+
});
|
|
40
|
+
input.pipe(output);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class ResourceTracker {
|
|
45
|
+
files: string[] = [];
|
|
46
|
+
streams: (Readable | Writable)[] = [];
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
constructor(private reject: (err: any) => void) {}
|
|
50
|
+
|
|
51
|
+
addStream(stream: Readable | Writable) {
|
|
52
|
+
stream.on('error', this.reject);
|
|
53
|
+
this.streams.push(stream);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
addFile(file: string) {
|
|
57
|
+
this.files.push(file);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
export function withResourceCleanup<T>(fn: (tracker: ResourceTracker) => Promise<T>, onError?: (err: any) => void) {
|
|
63
|
+
return new Promise<T>((resolve, reject) => {
|
|
64
|
+
const tracker = new ResourceTracker(reject);
|
|
65
|
+
fn(tracker)
|
|
66
|
+
.then(resolve, err => {
|
|
67
|
+
onError?.(err);
|
|
68
|
+
reject(err);
|
|
69
|
+
})
|
|
70
|
+
.finally(() => {
|
|
71
|
+
tracker.files.forEach(file => {
|
|
72
|
+
unlink(file).catch(() => {});
|
|
73
|
+
});
|
|
74
|
+
tracker.streams.forEach(stream => {
|
|
75
|
+
if (!stream.destroyed) stream.destroy();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Logger, LoggerInterface } from '@deepkit/logger';
|
|
2
|
+
import { ReceiveType } from '@deepkit/type';
|
|
3
|
+
import { memoize } from 'lodash';
|
|
4
|
+
import { hostname } from 'os';
|
|
5
|
+
|
|
6
|
+
import { r } from '../../app/resolver';
|
|
7
|
+
import { createRedis } from './redis';
|
|
8
|
+
|
|
9
|
+
const getSharedBroadcastChannel = memoize(() => {
|
|
10
|
+
const logger = r(Logger).scoped('Broadcast');
|
|
11
|
+
const { prefix, client: publishClient } = createRedis('BROADCAST');
|
|
12
|
+
const { client: subscribeClient } = createRedis('BROADCAST');
|
|
13
|
+
|
|
14
|
+
const channel = `${prefix}:broadcast`;
|
|
15
|
+
const localInstanceKey = `${hostname()}/${process.pid}`;
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
const listeners = new Map<string, Set<(message: any) => void>>();
|
|
19
|
+
|
|
20
|
+
subscribeClient.subscribe(channel);
|
|
21
|
+
subscribeClient.on('message', (_, message) => {
|
|
22
|
+
try {
|
|
23
|
+
const { instanceKey, eventName, data } = JSON.parse(message);
|
|
24
|
+
if (instanceKey === localInstanceKey) return;
|
|
25
|
+
const listenersForEvent = listeners.get(eventName);
|
|
26
|
+
if (!listenersForEvent) return;
|
|
27
|
+
for (const listener of listenersForEvent) {
|
|
28
|
+
try {
|
|
29
|
+
listener(data);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
logger.error(`Failed to handle broadcast message`, err, { eventName });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
logger.error('Failed to parse broadcast message', err, message);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
subscribe: (eventName: string, fn: (data: any) => void) => {
|
|
42
|
+
const listenersForEvent = listeners.get(eventName) ?? new Set();
|
|
43
|
+
listenersForEvent.add(fn);
|
|
44
|
+
listeners.set(eventName, listenersForEvent);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
publish: (eventName: string, data: any) => {
|
|
49
|
+
publishClient.publish(channel, JSON.stringify({ instanceKey: localInstanceKey, eventName, data }));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export function createBroadcastChannel<T>(eventName: string, _type?: ReceiveType<T>) {
|
|
55
|
+
const channel = getSharedBroadcastChannel();
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
subscribe: (fn: (data: T) => void) => {
|
|
59
|
+
channel.subscribe(eventName, data => {
|
|
60
|
+
// todo: figure out type validation
|
|
61
|
+
// assert<T>(data, undefined, type);
|
|
62
|
+
fn(data);
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
publish: (data: T) => {
|
|
67
|
+
channel.publish(eventName, data);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface IDistributedMethodParent {
|
|
73
|
+
logger: LoggerInterface;
|
|
74
|
+
}
|
|
75
|
+
export function createDistributedMethod<T>(parent: IDistributedMethodParent, name: string, fn: (data: T) => Promise<void>, type?: ReceiveType<T>) {
|
|
76
|
+
const channel = createBroadcastChannel(name, type);
|
|
77
|
+
|
|
78
|
+
const wrappedFn = async (data: T) => {
|
|
79
|
+
try {
|
|
80
|
+
await fn(data);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
parent.logger.error(`Error executing ${name} distributed method`, err);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// invoke locally when remotely requested
|
|
87
|
+
channel.subscribe(wrappedFn);
|
|
88
|
+
|
|
89
|
+
// publish & invoke locally when locally executed
|
|
90
|
+
return (data: T) => {
|
|
91
|
+
channel.publish(data);
|
|
92
|
+
return wrappedFn(data);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { memoize } from 'lodash';
|
|
2
|
+
|
|
3
|
+
import { createRedis } from './redis';
|
|
4
|
+
|
|
5
|
+
const getRedis = memoize(() => createRedis('CACHE'));
|
|
6
|
+
|
|
7
|
+
export class Cache {
|
|
8
|
+
static async get(key: string): Promise<string | null> {
|
|
9
|
+
const { client, prefix } = getRedis();
|
|
10
|
+
return client.get(`${prefix}:cache:${key}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static async set(key: string, value: string, ttl = 60): Promise<void> {
|
|
14
|
+
const { client, prefix } = getRedis();
|
|
15
|
+
await client.set(`${prefix}:cache:${key}`, value, 'EX', ttl);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static async getObj<T>(key: string): Promise<T | null> {
|
|
19
|
+
const { client, prefix } = getRedis();
|
|
20
|
+
const value = await client.get(`${prefix}:cache:${key}`);
|
|
21
|
+
return value ? JSON.parse(value) : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static async setObj<T>(key: string, value: T, ttl = 60): Promise<void> {
|
|
25
|
+
const { client, prefix } = getRedis();
|
|
26
|
+
await client.set(`${prefix}:cache:${key}`, JSON.stringify(value), 'EX', ttl);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { uuid } from '@deepkit/type';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { memoize } from 'lodash';
|
|
4
|
+
|
|
5
|
+
import { getAppConfig } from '../../app/resolver';
|
|
6
|
+
import { withSpan } from '../../telemetry';
|
|
7
|
+
import { ConcretePrimitive } from '../../types';
|
|
8
|
+
import { getPackageName } from '../io/package';
|
|
9
|
+
import { sleepMs } from '../utils/date';
|
|
10
|
+
import { createRedis } from './redis';
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
type MutexFn<R = any> = (didWait: boolean) => Promise<R>;
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
export type MutexKey = ConcretePrimitive | InstanceType<any>;
|
|
16
|
+
|
|
17
|
+
const getMutexHelpers = memoize(() => {
|
|
18
|
+
const appConfig = getAppConfig();
|
|
19
|
+
|
|
20
|
+
if (appConfig.MUTEX_MODE === 'local') {
|
|
21
|
+
return {
|
|
22
|
+
prepareKey: (k: string) => k,
|
|
23
|
+
exec: localMutexExec
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const prefix = appConfig.MUTEX_REDIS_PREFIX ?? appConfig.REDIS_PREFIX ?? getPackageName() ?? 'app';
|
|
28
|
+
return {
|
|
29
|
+
prepareKey: (k: string) => `${prefix}:${k}`,
|
|
30
|
+
exec: redisMutexExec
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
interface IMutexOptions<T> {
|
|
35
|
+
key: MutexKey | MutexKey[];
|
|
36
|
+
fn: MutexFn<T>;
|
|
37
|
+
retryCount?: number;
|
|
38
|
+
retryDelay?: number;
|
|
39
|
+
renewInterval?: number;
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
const DefaultMutexOptions: Partial<IMutexOptions<any>> = {
|
|
43
|
+
retryCount: 30,
|
|
44
|
+
retryDelay: 1000,
|
|
45
|
+
renewInterval: 1000
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export class MutexAcquisitionError extends Error {
|
|
49
|
+
constructor(message?: string) {
|
|
50
|
+
super(message ?? 'Failed to acquire mutex within timeout');
|
|
51
|
+
this.name = 'MutexAcquisitionError';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function withMutex<T>(options: IMutexOptions<T>): Promise<T> {
|
|
56
|
+
const flattenedKey = flattenMutexKey(options.key);
|
|
57
|
+
const helpers = getMutexHelpers();
|
|
58
|
+
const preparedKey = helpers.prepareKey(flattenedKey);
|
|
59
|
+
return withSpan('mutex:requested', { key: flattenedKey }, () =>
|
|
60
|
+
helpers.exec({
|
|
61
|
+
...DefaultMutexOptions,
|
|
62
|
+
...options,
|
|
63
|
+
key: preparedKey,
|
|
64
|
+
fn: (didWait: boolean) => withSpan('mutex:held', () => options.fn(didWait))
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function withMutexes<T>(options: Omit<IMutexOptions<T>, 'key'> & { keys: IMutexOptions<T>['key'][] }): Promise<T> {
|
|
70
|
+
const currentKey = options.keys[0];
|
|
71
|
+
const remainingKeys = options.keys.slice(1);
|
|
72
|
+
|
|
73
|
+
let didAnyWait = false;
|
|
74
|
+
return withMutex({
|
|
75
|
+
...options,
|
|
76
|
+
key: currentKey,
|
|
77
|
+
fn: didWait => {
|
|
78
|
+
didAnyWait = didAnyWait || didWait;
|
|
79
|
+
return remainingKeys.length ? withMutexes({ ...options, keys: remainingKeys }) : options.fn(didAnyWait);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Local Mutex
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
const localMutexes = new Map<string, Promise<any>>();
|
|
90
|
+
async function localMutexExec<T>(options: IMutexOptions<T>): Promise<T> {
|
|
91
|
+
const hasMutex = localMutexes.has(options.key);
|
|
92
|
+
|
|
93
|
+
if (localMutexes.has(options.key)) {
|
|
94
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
95
|
+
await new Promise<void>(async (resolve, reject) => {
|
|
96
|
+
let hasTimedOut = false;
|
|
97
|
+
|
|
98
|
+
const timeout = setTimeout(() => {
|
|
99
|
+
hasTimedOut = true;
|
|
100
|
+
reject(new MutexAcquisitionError());
|
|
101
|
+
}, options.retryDelay! * options.retryCount!);
|
|
102
|
+
|
|
103
|
+
while (localMutexes.has(options.key)) {
|
|
104
|
+
try {
|
|
105
|
+
await localMutexes.get(options.key);
|
|
106
|
+
} catch {
|
|
107
|
+
/**/
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (hasTimedOut) return;
|
|
112
|
+
clearTimeout(timeout);
|
|
113
|
+
|
|
114
|
+
resolve();
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const promise = new Promise<T>((resolve, reject) => {
|
|
119
|
+
options
|
|
120
|
+
.fn(hasMutex)
|
|
121
|
+
.then(resolve)
|
|
122
|
+
.catch(reject)
|
|
123
|
+
.finally(() => {
|
|
124
|
+
localMutexes.delete(options.key);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
localMutexes.set(options.key, promise);
|
|
128
|
+
return promise;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Redis Mutex
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
// Redis scripts:
|
|
136
|
+
// ACQUIRE [key] [value] [ttl]
|
|
137
|
+
// RENEW [key] [value] [ttl]
|
|
138
|
+
// RELEASE [key] [value]
|
|
139
|
+
const ACQUIRE_SCRIPT = `
|
|
140
|
+
if redis.call("exists", KEYS[1]) == 1 then
|
|
141
|
+
return 0
|
|
142
|
+
end
|
|
143
|
+
redis.call("set", KEYS[1], ARGV[1], "px", ARGV[2])
|
|
144
|
+
return 1
|
|
145
|
+
`;
|
|
146
|
+
const RENEW_SCRIPT = `
|
|
147
|
+
if redis.call("get", KEYS[1]) ~= ARGV[1] then
|
|
148
|
+
return 0
|
|
149
|
+
end
|
|
150
|
+
redis.call("pexpire", KEYS[1], ARGV[2])
|
|
151
|
+
return 1
|
|
152
|
+
`;
|
|
153
|
+
const RELEASE_SCRIPT = `
|
|
154
|
+
if redis.call("get", KEYS[1]) ~= ARGV[1] then
|
|
155
|
+
return 0
|
|
156
|
+
end
|
|
157
|
+
redis.call("del", KEYS[1])
|
|
158
|
+
return 1
|
|
159
|
+
`;
|
|
160
|
+
|
|
161
|
+
const getMutexRedisClient = memoize(() => {
|
|
162
|
+
const { client } = createRedis('MUTEX');
|
|
163
|
+
return client;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const getRedisClient = memoize(() => {
|
|
167
|
+
const redisClient = getMutexRedisClient();
|
|
168
|
+
redisClient.defineCommand('ACQUIRE', {
|
|
169
|
+
lua: ACQUIRE_SCRIPT,
|
|
170
|
+
numberOfKeys: 1
|
|
171
|
+
});
|
|
172
|
+
redisClient.defineCommand('RENEW', {
|
|
173
|
+
lua: RENEW_SCRIPT,
|
|
174
|
+
numberOfKeys: 1
|
|
175
|
+
});
|
|
176
|
+
redisClient.defineCommand('RELEASE', {
|
|
177
|
+
lua: RELEASE_SCRIPT,
|
|
178
|
+
numberOfKeys: 1
|
|
179
|
+
});
|
|
180
|
+
return redisClient as typeof redisClient & {
|
|
181
|
+
ACQUIRE: (key: string, value: string, ttl: number) => Promise<number>;
|
|
182
|
+
RENEW: (key: string, value: string, ttl: number) => Promise<number>;
|
|
183
|
+
RELEASE: (key: string, value: string) => Promise<number>;
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
async function redisMutexExec<T>(options: IMutexOptions<T>): Promise<T> {
|
|
188
|
+
const lockId = uuid();
|
|
189
|
+
const redisClient = getRedisClient();
|
|
190
|
+
|
|
191
|
+
const lockTtl = options.renewInterval! * 3;
|
|
192
|
+
const deadlineMs = Date.now() + options.retryCount! * options.retryDelay!;
|
|
193
|
+
let attempts = 0;
|
|
194
|
+
|
|
195
|
+
do {
|
|
196
|
+
attempts++;
|
|
197
|
+
const result = await redisClient.ACQUIRE(options.key, lockId, lockTtl);
|
|
198
|
+
if (result === 0) {
|
|
199
|
+
await sleepMs(options.retryDelay!);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return new Promise<T>((resolve, reject) => {
|
|
204
|
+
const interval = setInterval(() => {
|
|
205
|
+
redisClient
|
|
206
|
+
.RENEW(options.key, lockId, lockTtl)
|
|
207
|
+
.then(result => {
|
|
208
|
+
if (result === 0) throw new MutexAcquisitionError('Key missing or value mismatch');
|
|
209
|
+
})
|
|
210
|
+
.catch(err => {
|
|
211
|
+
reject(new MutexAcquisitionError(`Failed to renew mutex ${options.key} ${lockId}: ${String(err)}`));
|
|
212
|
+
});
|
|
213
|
+
}, options.renewInterval! / 2);
|
|
214
|
+
|
|
215
|
+
options
|
|
216
|
+
.fn(attempts > 1)
|
|
217
|
+
.then(resolve)
|
|
218
|
+
.catch(reject)
|
|
219
|
+
.finally(() => {
|
|
220
|
+
clearInterval(interval);
|
|
221
|
+
redisClient
|
|
222
|
+
.RELEASE(options.key, lockId)
|
|
223
|
+
.then(result => {
|
|
224
|
+
if (result === 0) throw new MutexAcquisitionError('Key missing or value mismatch');
|
|
225
|
+
})
|
|
226
|
+
.catch(err => {
|
|
227
|
+
console.warn(`Failed to release mutex ${options.key} ${lockId}`, err);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
} while (Date.now() < deadlineMs);
|
|
232
|
+
|
|
233
|
+
throw new MutexAcquisitionError();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Helpers
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
export function flattenMutexKey(key: MutexKey | MutexKey[]): string {
|
|
241
|
+
if (Array.isArray(key)) {
|
|
242
|
+
return key.map(k => flattenMutexKey(k)).join(':');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (typeof key === 'object') {
|
|
246
|
+
if ('name' in key) {
|
|
247
|
+
return key.name;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if ('constructor' in key) {
|
|
251
|
+
return key.constructor.name;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const jsonKey = JSON.stringify(key);
|
|
255
|
+
const objectKey = jsonKey.length === 2 ? String(key) : jsonKey;
|
|
256
|
+
return createHash('md5').update(objectKey).digest('hex');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return String(key);
|
|
260
|
+
}
|