@zyno-io/dk-server-foundation 26.216.430
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/LICENSE +21 -0
- package/README.md +458 -0
- package/dist/devconsole/assets/index-CKF3C3kv.css +1 -0
- package/dist/devconsole/assets/index-CsHdomhM.js +27 -0
- package/dist/devconsole/index.html +13 -0
- package/dist/resources/proto/generated/devconsole/devconsole.d.ts +320 -0
- package/dist/resources/proto/generated/devconsole/devconsole.d.ts.map +1 -0
- package/dist/resources/proto/generated/devconsole/devconsole.js +3751 -0
- package/dist/resources/proto/generated/devconsole/devconsole.js.map +1 -0
- package/dist/src/app/base.d.ts +36 -0
- package/dist/src/app/base.d.ts.map +1 -0
- package/dist/src/app/base.js +240 -0
- package/dist/src/app/base.js.map +1 -0
- package/dist/src/app/config.d.ts +90 -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 +7 -0
- package/dist/src/app/dev.d.ts.map +1 -0
- package/dist/src/app/dev.js +105 -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 +408 -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 +78 -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 +9 -0
- package/dist/src/database/migration/MigrationResetCommand.d.ts.map +1 -0
- package/dist/src/database/migration/MigrationResetCommand.js +75 -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 +106 -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 +417 -0
- package/dist/src/database/migration/create/entity-reader.js.map +1 -0
- package/dist/src/database/migration/create/file-generator.d.ts +3 -0
- package/dist/src/database/migration/create/file-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/file-generator.js +62 -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 +3 -0
- package/dist/src/database/migration/helpers.d.ts.map +1 -0
- package/dist/src/database/migration/helpers.js +13 -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/devconsole/devconsole.controller.d.ts +7 -0
- package/dist/src/devconsole/devconsole.controller.d.ts.map +1 -0
- package/dist/src/devconsole/devconsole.controller.js +82 -0
- package/dist/src/devconsole/devconsole.controller.js.map +1 -0
- package/dist/src/devconsole/devconsole.middleware.d.ts +12 -0
- package/dist/src/devconsole/devconsole.middleware.d.ts.map +1 -0
- package/dist/src/devconsole/devconsole.middleware.js +28 -0
- package/dist/src/devconsole/devconsole.middleware.js.map +1 -0
- package/dist/src/devconsole/devconsole.srpc.d.ts +14 -0
- package/dist/src/devconsole/devconsole.srpc.d.ts.map +1 -0
- package/dist/src/devconsole/devconsole.srpc.js +94 -0
- package/dist/src/devconsole/devconsole.srpc.js.map +1 -0
- package/dist/src/devconsole/devconsole.store.d.ts +101 -0
- package/dist/src/devconsole/devconsole.store.d.ts.map +1 -0
- package/dist/src/devconsole/devconsole.store.js +125 -0
- package/dist/src/devconsole/devconsole.store.js.map +1 -0
- package/dist/src/devconsole/devconsole.ws.d.ts +18 -0
- package/dist/src/devconsole/devconsole.ws.d.ts.map +1 -0
- package/dist/src/devconsole/devconsole.ws.js +470 -0
- package/dist/src/devconsole/devconsole.ws.js.map +1 -0
- package/dist/src/devconsole/index.d.ts +2 -0
- package/dist/src/devconsole/index.d.ts.map +1 -0
- package/dist/src/devconsole/index.js +6 -0
- package/dist/src/devconsole/index.js.map +1 -0
- package/dist/src/devconsole/patches.d.ts +6 -0
- package/dist/src/devconsole/patches.d.ts.map +1 -0
- package/dist/src/devconsole/patches.js +397 -0
- package/dist/src/devconsole/patches.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 +13 -0
- package/dist/src/health/healthcheck.service.d.ts.map +1 -0
- package/dist/src/health/healthcheck.service.js +33 -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 +13 -0
- package/dist/src/helpers/redis/broadcast.d.ts.map +1 -0
- package/dist/src/helpers/redis/broadcast.js +100 -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-context.d.ts +13 -0
- package/dist/src/services/cli/repl-context.d.ts.map +1 -0
- package/dist/src/services/cli/repl-context.js +60 -0
- package/dist/src/services/cli/repl-context.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 +32 -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 +64 -0
- package/dist/src/services/worker/bootstrap.js.map +1 -0
- package/dist/src/services/worker/cli.d.ts +11 -0
- package/dist/src/services/worker/cli.d.ts.map +1 -0
- package/dist/src/services/worker/cli.js +43 -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/queue.d.ts +8 -0
- package/dist/src/services/worker/queue.d.ts.map +1 -0
- package/dist/src/services/worker/queue.js +32 -0
- package/dist/src/services/worker/queue.js.map +1 -0
- package/dist/src/services/worker/recorder.d.ts +16 -0
- package/dist/src/services/worker/recorder.d.ts.map +1 -0
- package/dist/src/services/worker/recorder.js +168 -0
- package/dist/src/services/worker/recorder.js.map +1 -0
- package/dist/src/services/worker/runner.d.ts +21 -0
- package/dist/src/services/worker/runner.d.ts.map +1 -0
- package/dist/src/services/worker/runner.js +156 -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 +80 -0
- package/dist/src/srpc/SrpcServer.d.ts.map +1 -0
- package/dist/src/srpc/SrpcServer.js +561 -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 +131 -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/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/docs/.vitepress/config.mts +79 -0
- package/docs/.yarnrc.yml +1 -0
- package/docs/content/CONTRIBUTING.md +140 -0
- package/docs/content/README-DEV.md +142 -0
- package/docs/content/README.md +39 -0
- package/docs/content/authentication.md +215 -0
- package/docs/content/cli.md +335 -0
- package/docs/content/configuration.md +175 -0
- package/docs/content/database.md +422 -0
- package/docs/content/devconsole.md +123 -0
- package/docs/content/getting-started.md +154 -0
- package/docs/content/guides/test-migration-guide.md +351 -0
- package/docs/content/health.md +54 -0
- package/docs/content/helpers.md +322 -0
- package/docs/content/http.md +253 -0
- package/docs/content/index.md +147 -0
- package/docs/content/leader-service.md +98 -0
- package/docs/content/logging.md +150 -0
- package/docs/content/mail.md +161 -0
- package/docs/content/mesh-service.md +204 -0
- package/docs/content/public/images/devconsole/01-dashboard.png +0 -0
- package/docs/content/public/images/devconsole/02-routes.png +0 -0
- package/docs/content/public/images/devconsole/03-openapi.png +0 -0
- package/docs/content/public/images/devconsole/04-requests.png +0 -0
- package/docs/content/public/images/devconsole/05-srpc.png +0 -0
- package/docs/content/public/images/devconsole/06-database.png +0 -0
- package/docs/content/public/images/devconsole/07-health.png +0 -0
- package/docs/content/public/images/devconsole/08-mutex.png +0 -0
- package/docs/content/public/images/devconsole/09-repl.png +0 -0
- package/docs/content/public/images/devconsole/10-workers.png +0 -0
- package/docs/content/redis.md +168 -0
- package/docs/content/srpc.md +261 -0
- package/docs/content/telemetry.md +166 -0
- package/docs/content/testing.md +222 -0
- package/docs/content/types.md +215 -0
- package/docs/content/worker.md +177 -0
- package/docs/package.json +16 -0
- package/docs/scripts/README-SCREENSHOTS.md +145 -0
- package/docs/scripts/capture-devconsole-screenshots.js +184 -0
- package/docs/yarn.lock +2408 -0
- package/package.json +144 -0
- package/patches/@deepkit+type+1.0.19.patch +38 -0
- package/patches/deepkit-openapi-core+0.0.9.patch +62 -0
- package/src/app/base.ts +253 -0
- package/src/app/config.loader.ts +66 -0
- package/src/app/config.ts +119 -0
- package/src/app/const.ts +4 -0
- package/src/app/dev.ts +92 -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 +416 -0
- package/src/cli/dksf-gen-proto.ts +176 -0
- package/src/cli/dksf-install.ts +11 -0
- package/src/cli/dksf-test.ts +84 -0
- package/src/cli/dksf-update.ts +101 -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 +72 -0
- package/src/database/migration/MigrationRunCommand.ts +118 -0
- package/src/database/migration/characters.ts +53 -0
- package/src/database/migration/create/MigrationCreateCommand.ts +96 -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 +471 -0
- package/src/database/migration/create/file-generator.ts +57 -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 +7 -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/devconsole/devconsole.controller.ts +59 -0
- package/src/devconsole/devconsole.middleware.ts +23 -0
- package/src/devconsole/devconsole.srpc.ts +94 -0
- package/src/devconsole/devconsole.store.ts +190 -0
- package/src/devconsole/devconsole.ws.ts +491 -0
- package/src/devconsole/index.ts +1 -0
- package/src/devconsole/patches.ts +428 -0
- package/src/health/health.module.ts +30 -0
- package/src/health/healthcheck.controller.ts +17 -0
- package/src/health/healthcheck.service.ts +28 -0
- package/src/health/index.ts +2 -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 +96 -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-context.ts +63 -0
- package/src/services/cli/repl.ts +22 -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/bootstrap.ts +53 -0
- package/src/services/worker/cli.ts +32 -0
- package/src/services/worker/entity.ts +22 -0
- package/src/services/worker/index.ts +30 -0
- package/src/services/worker/queue.ts +35 -0
- package/src/services/worker/recorder.ts +172 -0
- package/src/services/worker/runner.ts +179 -0
- package/src/services/worker/types.ts +32 -0
- package/src/srpc/SrpcByteStream.ts +382 -0
- package/src/srpc/SrpcClient.ts +512 -0
- package/src/srpc/SrpcServer.ts +681 -0
- package/src/srpc/index.ts +15 -0
- package/src/srpc/types.ts +146 -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/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/types.d.ts +20 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { App } from '@deepkit/app';
|
|
2
|
+
import { ClassType } from '@deepkit/core';
|
|
3
|
+
import { FrameworkModule } from '@deepkit/framework';
|
|
4
|
+
|
|
5
|
+
import { r } from '../../app/resolver';
|
|
6
|
+
import { DBProvider } from '../../app/state';
|
|
7
|
+
import { BaseDatabase } from '../common';
|
|
8
|
+
import { MigrationCharactersCommand } from './characters';
|
|
9
|
+
import { MigrationCreateCommand } from './create/MigrationCreateCommand';
|
|
10
|
+
import { MigrationResetCommand } from './MigrationResetCommand';
|
|
11
|
+
import { MigrationRunCommand } from './MigrationRunCommand';
|
|
12
|
+
|
|
13
|
+
export * from './characters';
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
export function replaceMigrationCommands(_app: App<any>, frameworkModule: FrameworkModule, dbClass?: ClassType<BaseDatabase>) {
|
|
17
|
+
frameworkModule.controllers = frameworkModule.controllers.filter(c => !c.name.startsWith('Migration'));
|
|
18
|
+
|
|
19
|
+
if (!dbClass) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
frameworkModule.addController(MigrationRunCommand);
|
|
24
|
+
frameworkModule.addController(MigrationCreateCommand);
|
|
25
|
+
frameworkModule.addController(MigrationCharactersCommand);
|
|
26
|
+
frameworkModule.addController(MigrationResetCommand);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createMigration<T extends BaseDatabase>(fn: (db: T) => Promise<void>) {
|
|
30
|
+
return fn;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function runMigrations() {
|
|
34
|
+
return new MigrationRunCommand(r(DBProvider)).execute();
|
|
35
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ClassType, getClassName } from '@deepkit/core';
|
|
2
|
+
import { Logger } from '@deepkit/logger';
|
|
3
|
+
import { MySQLConnection, MySQLDatabaseAdapter as BaseMySQLDatabaseAdapter } from '@deepkit/mysql';
|
|
4
|
+
import { Database, DatabaseSession } from '@deepkit/orm';
|
|
5
|
+
import { isNonUndefined } from '@deepkit/sql';
|
|
6
|
+
import { databaseAnnotation, ReflectionKind, Type } from '@deepkit/type';
|
|
7
|
+
import { PoolConfig } from 'mariadb';
|
|
8
|
+
|
|
9
|
+
import { getAppConfig, r } from '../app/resolver';
|
|
10
|
+
import { globalState } from '../app/state';
|
|
11
|
+
import { Coordinate } from '.';
|
|
12
|
+
import { BaseDatabase } from './common';
|
|
13
|
+
|
|
14
|
+
export type MySQLDatabaseSession = DatabaseSession<MySQLDatabaseAdapter>;
|
|
15
|
+
|
|
16
|
+
const originalRun = MySQLConnection.prototype.run;
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
MySQLConnection.prototype.run = async function (sql: string, params: any[] = []) {
|
|
19
|
+
await originalRun.call(this, sql, params);
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
return this.lastExecResult?.[0] as any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class MySQLDatabaseAdapter extends BaseMySQLDatabaseAdapter {
|
|
25
|
+
registerTransformations() {
|
|
26
|
+
// any
|
|
27
|
+
this.platform.serializer.deserializeRegistry.register(ReflectionKind.any, (_type, state) => {
|
|
28
|
+
state.addSetter(state.accessor);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// date string
|
|
32
|
+
this.platform.serializer.deserializeRegistry.addDecorator(
|
|
33
|
+
t => t.typeName === 'DateString',
|
|
34
|
+
(_type, state) => {
|
|
35
|
+
state.addSetter(`${state.accessor} instanceof Date ? ${state.accessor}.toISOString().substring(0, 10) : ${state.accessor}`);
|
|
36
|
+
state.ended = true;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// register POINT as a coordinate
|
|
41
|
+
// a specificity of 2 on the type guard allows the default object literal (at specificity 1) to match the {x,y} object
|
|
42
|
+
// while allowing a fallback to match the POINT object coming from the mariadb driver
|
|
43
|
+
const isCoordinateClass = (t: Type): boolean => t.kind === ReflectionKind.class && getClassName(t.classType) === 'Coordinate';
|
|
44
|
+
const isCoordinateTypeName = (t: Type): boolean => {
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
const typeName = (t as any).typeName;
|
|
47
|
+
return typeName === 'MySQLCoordinate' || typeName === 'NullableMySQLCoordinate' || typeName === 'Coordinate';
|
|
48
|
+
};
|
|
49
|
+
const hasMySQLPointAnnotation = (t: Type): boolean => {
|
|
50
|
+
const mysqlOptions = databaseAnnotation.getDatabase<{ type?: string }>(t, 'mysql');
|
|
51
|
+
return mysqlOptions?.type === 'point';
|
|
52
|
+
};
|
|
53
|
+
const containsCoordinate = (t: Type): boolean => {
|
|
54
|
+
if (isCoordinateClass(t)) return true;
|
|
55
|
+
if (isCoordinateTypeName(t)) return true;
|
|
56
|
+
if (hasMySQLPointAnnotation(t)) return true;
|
|
57
|
+
if (t.kind === ReflectionKind.intersection) return t.types.some(containsCoordinate);
|
|
58
|
+
if (t.kind === ReflectionKind.union) return t.types.filter(isNonUndefined).some(containsCoordinate);
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
this.platform.addType(containsCoordinate, 'point');
|
|
62
|
+
this.platform.serializer.typeGuards.registerClass(2, Coordinate, (_type, state) => {
|
|
63
|
+
state.addSetter(`typeof ${state.accessor} === 'object' && ${state.accessor}.type === 'Point'`);
|
|
64
|
+
});
|
|
65
|
+
this.platform.serializer.serializeRegistry.registerClass(Coordinate, (_type, state) => {
|
|
66
|
+
state.addCodeForSetter(`
|
|
67
|
+
const c = ${state.accessor};
|
|
68
|
+
${state.setter} = { type: 'Point', coordinates: [c.x, c.y] };
|
|
69
|
+
`);
|
|
70
|
+
state.ended = true;
|
|
71
|
+
});
|
|
72
|
+
this.platform.serializer.deserializeRegistry.registerClass(Coordinate, (_type, state) => {
|
|
73
|
+
state.addCodeForSetter(`
|
|
74
|
+
const c = ${state.accessor};
|
|
75
|
+
${state.setter} = { x: c.coordinates[0], y: c.coordinates[1] };
|
|
76
|
+
`);
|
|
77
|
+
state.ended = true;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// when Jest mocks dates, the Date object checked by Deepkit is not the same as the one created by Jest
|
|
81
|
+
if (process.env.APP_ENV === 'test') {
|
|
82
|
+
const isDate = (t: Type) => t.kind === ReflectionKind.class && t.classType.name === 'Date';
|
|
83
|
+
this.platform.addType(isDate, 'datetime');
|
|
84
|
+
this.platform.addType(t => t.kind === ReflectionKind.union && t.types.filter(isNonUndefined).every(isDate), 'datetime');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface IMySQLDatabaseAdapterConfig extends PoolConfig {
|
|
90
|
+
enableLocksTable?: boolean;
|
|
91
|
+
}
|
|
92
|
+
export function createMySQLDatabase(
|
|
93
|
+
config: IMySQLDatabaseAdapterConfig,
|
|
94
|
+
entities: ConstructorParameters<typeof Database>[1] = []
|
|
95
|
+
): ClassType<BaseDatabase<MySQLDatabaseAdapter>> {
|
|
96
|
+
return class extends BaseDatabase<MySQLDatabaseAdapter> {
|
|
97
|
+
constructor() {
|
|
98
|
+
const appConfig = getAppConfig();
|
|
99
|
+
const isProduction = appConfig.APP_ENV === 'production';
|
|
100
|
+
|
|
101
|
+
const { enableLocksTable, ...otherConfig } = config;
|
|
102
|
+
|
|
103
|
+
const adapter = new MySQLDatabaseAdapter({
|
|
104
|
+
host: appConfig.MYSQL_HOST,
|
|
105
|
+
port: appConfig.MYSQL_PORT,
|
|
106
|
+
user: appConfig.MYSQL_USER,
|
|
107
|
+
password: appConfig.MYSQL_PASSWORD_SECRET,
|
|
108
|
+
database: appConfig.MYSQL_DATABASE,
|
|
109
|
+
connectionLimit: appConfig.MYSQL_CONNECTION_LIMIT ?? (isProduction ? 10 : 5),
|
|
110
|
+
minimumIdle: appConfig.MYSQL_MIN_IDLE_CONNECTIONS ?? (isProduction ? undefined : 1),
|
|
111
|
+
idleTimeout: appConfig.MYSQL_IDLE_TIMEOUT_SECONDS ?? (isProduction ? 60 : 5),
|
|
112
|
+
allowPublicKeyRetrieval: true,
|
|
113
|
+
trace: true,
|
|
114
|
+
...otherConfig
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
adapter.registerTransformations();
|
|
118
|
+
|
|
119
|
+
if (globalState.additionalEntities) {
|
|
120
|
+
entities.push(...globalState.additionalEntities);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
super(adapter, entities);
|
|
124
|
+
|
|
125
|
+
if (enableLocksTable) {
|
|
126
|
+
this.rawExecute(
|
|
127
|
+
`CREATE TABLE IF NOT EXISTS \`_locks\` (
|
|
128
|
+
\`key\` VARCHAR(255) NOT NULL PRIMARY KEY,
|
|
129
|
+
\`createdAt\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
130
|
+
\`lastTouched\` DATETIME
|
|
131
|
+
)`
|
|
132
|
+
)
|
|
133
|
+
.then(() => this.rawExecute(`DELETE FROM _locks WHERE lastTouched < NOW() - INTERVAL 1 HOUR`))
|
|
134
|
+
.catch(err => {
|
|
135
|
+
r(Logger).error(`Could not create _locks table: %s`, err);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ClassType } from '@deepkit/core';
|
|
2
|
+
import { Logger } from '@deepkit/logger';
|
|
3
|
+
import { Database, DatabaseSession } from '@deepkit/orm';
|
|
4
|
+
import { PostgresConnection, PostgresDatabaseAdapter as BasePostgresDatabaseAdapter } from '@deepkit/postgres';
|
|
5
|
+
import { isNonUndefined } from '@deepkit/sql';
|
|
6
|
+
import { ReflectionKind, Type } from '@deepkit/type';
|
|
7
|
+
import { PoolConfig } from 'pg';
|
|
8
|
+
|
|
9
|
+
import { getAppConfig, r } from '../app/resolver';
|
|
10
|
+
import { globalState } from '../app/state';
|
|
11
|
+
import { BaseDatabase } from './common';
|
|
12
|
+
|
|
13
|
+
export type PostgresDatabaseSession = DatabaseSession<PostgresDatabaseAdapter>;
|
|
14
|
+
|
|
15
|
+
const originalRun = PostgresConnection.prototype.run;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
PostgresConnection.prototype.run = async function (sql: string, params: any[] = []) {
|
|
18
|
+
await originalRun.call(this, sql, params);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return { affectedRows: (this as any).changes ?? 0, insertId: 0 } as any;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class PostgresDatabaseAdapter extends BasePostgresDatabaseAdapter {
|
|
24
|
+
registerTransformations() {
|
|
25
|
+
// any
|
|
26
|
+
this.platform.serializer.deserializeRegistry.register(ReflectionKind.any, (_type, state) => {
|
|
27
|
+
state.addSetter(state.accessor);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// date string
|
|
31
|
+
this.platform.serializer.deserializeRegistry.addDecorator(
|
|
32
|
+
t => t.typeName === 'DateString',
|
|
33
|
+
(_type, state) => {
|
|
34
|
+
state.addSetter(`${state.accessor} instanceof Date ? ${state.accessor}.toISOString().substring(0, 10) : ${state.accessor}`);
|
|
35
|
+
state.ended = true;
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// when Jest/test mocks dates, the Date object checked by Deepkit is not the same as the one created by the mock
|
|
40
|
+
if (process.env.APP_ENV === 'test') {
|
|
41
|
+
const isDate = (t: Type) => t.kind === ReflectionKind.class && t.classType.name === 'Date';
|
|
42
|
+
this.platform.addType(isDate, 'timestamp');
|
|
43
|
+
this.platform.addType(t => t.kind === ReflectionKind.union && t.types.filter(isNonUndefined).every(isDate), 'timestamp');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IPostgresDatabaseAdapterConfig extends PoolConfig {
|
|
49
|
+
enableLocksTable?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createPostgresDatabase(
|
|
53
|
+
config: IPostgresDatabaseAdapterConfig,
|
|
54
|
+
entities: ConstructorParameters<typeof Database>[1] = []
|
|
55
|
+
): ClassType<BaseDatabase<PostgresDatabaseAdapter>> {
|
|
56
|
+
return class extends BaseDatabase<PostgresDatabaseAdapter> {
|
|
57
|
+
constructor() {
|
|
58
|
+
const appConfig = getAppConfig();
|
|
59
|
+
const isProduction = appConfig.APP_ENV === 'production';
|
|
60
|
+
|
|
61
|
+
const { enableLocksTable, ...otherConfig } = config;
|
|
62
|
+
|
|
63
|
+
const adapter = new PostgresDatabaseAdapter({
|
|
64
|
+
host: appConfig.PG_HOST,
|
|
65
|
+
port: appConfig.PG_PORT,
|
|
66
|
+
user: appConfig.PG_USER,
|
|
67
|
+
password: appConfig.PG_PASSWORD_SECRET,
|
|
68
|
+
database: appConfig.PG_DATABASE,
|
|
69
|
+
max: appConfig.PG_CONNECTION_LIMIT ?? (isProduction ? 10 : 5),
|
|
70
|
+
idleTimeoutMillis: (appConfig.PG_IDLE_TIMEOUT_SECONDS ?? (isProduction ? 60 : 5)) * 1000,
|
|
71
|
+
...otherConfig
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
adapter.registerTransformations();
|
|
75
|
+
|
|
76
|
+
if (globalState.additionalEntities) {
|
|
77
|
+
entities.push(...globalState.additionalEntities);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
super(adapter, entities);
|
|
81
|
+
|
|
82
|
+
if (enableLocksTable) {
|
|
83
|
+
this.rawExecute(
|
|
84
|
+
`CREATE TABLE IF NOT EXISTS "_locks" (
|
|
85
|
+
"key" VARCHAR(255) NOT NULL PRIMARY KEY,
|
|
86
|
+
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
87
|
+
"lastTouched" TIMESTAMP
|
|
88
|
+
)`
|
|
89
|
+
)
|
|
90
|
+
.then(() => this.rawExecute(`DELETE FROM "_locks" WHERE "lastTouched" < NOW() - INTERVAL '1 hour'`))
|
|
91
|
+
.catch(err => {
|
|
92
|
+
r(Logger).error(`Could not create _locks table: %s`, err);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypeAnnotation } from '@deepkit/core';
|
|
2
|
+
import { MySQL, Type, Validate, ValidatorError } from '@deepkit/type';
|
|
3
|
+
|
|
4
|
+
export declare type UuidString = string & TypeAnnotation<'dksf:type', 'uuid'>;
|
|
5
|
+
|
|
6
|
+
export class Coordinate {
|
|
7
|
+
x!: number;
|
|
8
|
+
y!: number;
|
|
9
|
+
}
|
|
10
|
+
export type MySQLCoordinate = Coordinate & MySQL<{ type: 'point' }>;
|
|
11
|
+
export type NullableMySQLCoordinate = (Coordinate | null) & MySQL<{ type: 'point' }>;
|
|
12
|
+
|
|
13
|
+
function _validateLength(value: string, _type: Type, length: number) {
|
|
14
|
+
if (typeof value === 'string' && value.length !== length) {
|
|
15
|
+
return new ValidatorError('invalidLength', `Value must be exactly ${length} characters long.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare type Length<T extends number> = string & Validate<typeof _validateLength, T> & TypeAnnotation<'dksf:length', T>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
|
|
3
|
+
import { http, HttpNotFoundError, HttpRequest, HttpResponse } from '@deepkit/http';
|
|
4
|
+
import send from 'send';
|
|
5
|
+
|
|
6
|
+
import { serializeOpenApiSchema } from '../app/dev';
|
|
7
|
+
import { globalState } from '../app/state';
|
|
8
|
+
import { DevConsoleLocalhostMiddleware } from './devconsole.middleware';
|
|
9
|
+
|
|
10
|
+
const STATIC_DIR = resolve(__dirname, '../../devconsole');
|
|
11
|
+
|
|
12
|
+
function serveStatic(req: HttpRequest, res: HttpResponse, path: string): Promise<void> {
|
|
13
|
+
return new Promise<void>((resolve, reject) => {
|
|
14
|
+
send(req, path, { root: STATIC_DIR })
|
|
15
|
+
.on('error', (err: { status: number }) => {
|
|
16
|
+
if (err.status === 404) {
|
|
17
|
+
reject(new HttpNotFoundError());
|
|
18
|
+
} else {
|
|
19
|
+
reject(err);
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.on('end', resolve)
|
|
23
|
+
.pipe(res);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@(http.controller('/_devconsole').middleware(DevConsoleLocalhostMiddleware))
|
|
28
|
+
export class DevConsoleController {
|
|
29
|
+
@http.GET('')
|
|
30
|
+
serveIndex(req: HttpRequest, res: HttpResponse): Promise<void> {
|
|
31
|
+
return serveStatic(req, res, 'index.html');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@http.GET('assets/:path')
|
|
35
|
+
serveAsset(path: string, req: HttpRequest, res: HttpResponse): Promise<void> {
|
|
36
|
+
return serveStatic(req, res, `assets/${path}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@http.GET('openapi.json')
|
|
40
|
+
serveOpenApiSchema(res: HttpResponse): void {
|
|
41
|
+
const app = globalState.currentApp;
|
|
42
|
+
if (!app) {
|
|
43
|
+
res.status(503);
|
|
44
|
+
res.setHeader('content-type', 'application/json');
|
|
45
|
+
res.end(JSON.stringify({ error: 'App not ready' }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const schema = serializeOpenApiSchema(app);
|
|
51
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
52
|
+
res.end(JSON.stringify(schema, undefined, 2));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
res.status(500);
|
|
55
|
+
res.setHeader('content-type', 'application/json');
|
|
56
|
+
res.end(JSON.stringify({ error: String(err) }));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createHttpError, HttpRequest, HttpResponse } from '@deepkit/http';
|
|
2
|
+
|
|
3
|
+
import { HttpMiddleware } from '../http/middleware';
|
|
4
|
+
|
|
5
|
+
const HttpForbiddenError = createHttpError(403, 'Forbidden');
|
|
6
|
+
|
|
7
|
+
export function isLocalhostDirect(request: { socket: { remoteAddress?: string }; headers: Record<string, string | string[] | undefined> }): boolean {
|
|
8
|
+
// Reject if request was forwarded through a reverse proxy
|
|
9
|
+
if (request.headers['x-forwarded-for'] || request.headers['x-real-ip']) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const ip = request.socket.remoteAddress ?? '';
|
|
13
|
+
const normalized = ip.startsWith('::ffff:') ? ip.slice(7) : ip;
|
|
14
|
+
return normalized === '127.0.0.1' || ip === '::1';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class DevConsoleLocalhostMiddleware extends HttpMiddleware {
|
|
18
|
+
handle(request: HttpRequest, _response: HttpResponse) {
|
|
19
|
+
if (!isLocalhostDirect(request)) {
|
|
20
|
+
throw new HttpForbiddenError();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { DevConsoleStore } from './devconsole.store';
|
|
2
|
+
import type { SrpcStream } from '../srpc/types';
|
|
3
|
+
|
|
4
|
+
export interface SrpcMessageObserver {
|
|
5
|
+
onInboundMessage?(stream: SrpcStream, messageType: string, data: Record<string, unknown>): void;
|
|
6
|
+
onOutboundMessage?(stream: SrpcStream, messageType: string, data: Record<string, unknown>): void;
|
|
7
|
+
onConnectionEstablished?(stream: SrpcStream): void;
|
|
8
|
+
onConnectionClosed?(stream: SrpcStream, cause: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const BASE_MESSAGE_KEYS = new Set(['requestId', 'reply', 'error', 'userError', 'trace', 'pingPong', 'byteStreamOperation']);
|
|
12
|
+
|
|
13
|
+
function identifyMessageType(data: Record<string, unknown>): string {
|
|
14
|
+
for (const key of Object.keys(data)) {
|
|
15
|
+
if (!BASE_MESSAGE_KEYS.has(key) && data[key] != null) {
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return 'unknown';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
function sanitizeData(data: Record<string, any>): Record<string, unknown> {
|
|
24
|
+
const result: Record<string, unknown> = {};
|
|
25
|
+
for (const [key, value] of Object.entries(data)) {
|
|
26
|
+
if (key === 'trace') continue;
|
|
27
|
+
if (key === 'byteStreamOperation' && value) {
|
|
28
|
+
result[key] = {
|
|
29
|
+
streamId: value.streamId,
|
|
30
|
+
operation: value.write ? 'write' : value.finish ? 'finish' : value.destroy ? 'destroy' : 'unknown'
|
|
31
|
+
};
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
result[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createDevConsoleSrpcObserver(store: DevConsoleStore): SrpcMessageObserver {
|
|
40
|
+
return {
|
|
41
|
+
onInboundMessage(stream: SrpcStream, messageType: string, data: Record<string, unknown>) {
|
|
42
|
+
const conn = store.srpcConnections.get(stream.id);
|
|
43
|
+
if (conn) conn.messageCount++;
|
|
44
|
+
|
|
45
|
+
store.addSrpcMessage({
|
|
46
|
+
id: (data.requestId as string) ?? '',
|
|
47
|
+
timestamp: Date.now(),
|
|
48
|
+
streamId: stream.id,
|
|
49
|
+
clientId: stream.clientId,
|
|
50
|
+
direction: 'inbound',
|
|
51
|
+
messageType,
|
|
52
|
+
isReply: !!data.reply,
|
|
53
|
+
data: sanitizeData(data),
|
|
54
|
+
error: data.error as string | undefined,
|
|
55
|
+
isUserError: data.userError as boolean | undefined
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
onOutboundMessage(stream: SrpcStream, messageType: string, data: Record<string, unknown>) {
|
|
60
|
+
store.addSrpcMessage({
|
|
61
|
+
id: (data.requestId as string) ?? '',
|
|
62
|
+
timestamp: Date.now(),
|
|
63
|
+
streamId: stream.id,
|
|
64
|
+
clientId: stream.clientId,
|
|
65
|
+
direction: 'outbound',
|
|
66
|
+
messageType,
|
|
67
|
+
isReply: !!data.reply,
|
|
68
|
+
data: sanitizeData(data),
|
|
69
|
+
error: data.error as string | undefined,
|
|
70
|
+
isUserError: data.userError as boolean | undefined
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
onConnectionEstablished(stream: SrpcStream) {
|
|
75
|
+
store.addSrpcConnection({
|
|
76
|
+
streamId: stream.id,
|
|
77
|
+
clientId: stream.clientId,
|
|
78
|
+
clientStreamId: stream.clientStreamId,
|
|
79
|
+
appVersion: stream.appVersion,
|
|
80
|
+
address: stream.address,
|
|
81
|
+
connectedAt: stream.connectedAt,
|
|
82
|
+
lastPingAt: stream.lastPingAt,
|
|
83
|
+
meta: stream.meta as Record<string, unknown>,
|
|
84
|
+
messageCount: 0
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
onConnectionClosed(stream: SrpcStream, cause: string) {
|
|
89
|
+
store.removeSrpcConnection(stream.id, stream.clientId, cause);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { identifyMessageType, sanitizeData };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
export class RingBuffer<T> {
|
|
2
|
+
private buffer: (T | undefined)[];
|
|
3
|
+
private head = 0;
|
|
4
|
+
private count = 0;
|
|
5
|
+
|
|
6
|
+
constructor(private capacity: number) {
|
|
7
|
+
this.buffer = Array.from({ length: capacity });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
push(item: T): void {
|
|
11
|
+
this.buffer[this.head] = item;
|
|
12
|
+
this.head = (this.head + 1) % this.capacity;
|
|
13
|
+
if (this.count < this.capacity) this.count++;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toArray(): T[] {
|
|
17
|
+
if (this.count === 0) return [];
|
|
18
|
+
if (this.count < this.capacity) {
|
|
19
|
+
return this.buffer.slice(0, this.count) as T[];
|
|
20
|
+
}
|
|
21
|
+
return [...this.buffer.slice(this.head), ...this.buffer.slice(0, this.head)] as T[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get length(): number {
|
|
25
|
+
return this.count;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface DevConsoleErrorInfo {
|
|
30
|
+
name: string;
|
|
31
|
+
message: string;
|
|
32
|
+
stack?: string;
|
|
33
|
+
cause?: DevConsoleErrorInfo;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DevConsoleHttpEntry {
|
|
39
|
+
id: string;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
method: string;
|
|
42
|
+
url: string;
|
|
43
|
+
remoteAddress: string;
|
|
44
|
+
requestHeaders: Record<string, string | string[] | undefined>;
|
|
45
|
+
requestBody: string | null;
|
|
46
|
+
statusCode: number;
|
|
47
|
+
responseHeaders: Record<string, string | string[] | undefined>;
|
|
48
|
+
responseBody: string | null;
|
|
49
|
+
durationMs: number;
|
|
50
|
+
error?: DevConsoleErrorInfo;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DevConsoleSrpcMessage {
|
|
54
|
+
id: string;
|
|
55
|
+
timestamp: number;
|
|
56
|
+
streamId: string;
|
|
57
|
+
clientId: string;
|
|
58
|
+
direction: 'inbound' | 'outbound';
|
|
59
|
+
messageType: string;
|
|
60
|
+
isReply: boolean;
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
data: Record<string, any>;
|
|
63
|
+
error?: string;
|
|
64
|
+
isUserError?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface DevConsoleSrpcConnection {
|
|
68
|
+
streamId: string;
|
|
69
|
+
clientId: string;
|
|
70
|
+
clientStreamId: string;
|
|
71
|
+
appVersion: string;
|
|
72
|
+
address: string;
|
|
73
|
+
connectedAt: number;
|
|
74
|
+
lastPingAt: number;
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
meta: Record<string, any>;
|
|
77
|
+
messageCount: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface DevConsoleSrpcDisconnection {
|
|
81
|
+
streamId: string;
|
|
82
|
+
clientId: string;
|
|
83
|
+
disconnectedAt: number;
|
|
84
|
+
cause: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DevConsoleMutexEntry {
|
|
88
|
+
id: string;
|
|
89
|
+
key: string;
|
|
90
|
+
status: 'pending' | 'acquired' | 'released' | 'error' | 'failed';
|
|
91
|
+
startedAt: number;
|
|
92
|
+
acquiredAt?: number;
|
|
93
|
+
releasedAt?: number;
|
|
94
|
+
durationMs?: number;
|
|
95
|
+
waitDurationMs?: number;
|
|
96
|
+
waited?: boolean;
|
|
97
|
+
error?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class DevConsoleStore {
|
|
101
|
+
private static instance: DevConsoleStore | null = null;
|
|
102
|
+
|
|
103
|
+
readonly httpEntries = new RingBuffer<DevConsoleHttpEntry>(500);
|
|
104
|
+
readonly srpcMessages = new RingBuffer<DevConsoleSrpcMessage>(500);
|
|
105
|
+
readonly srpcConnections = new Map<string, DevConsoleSrpcConnection>();
|
|
106
|
+
readonly srpcDisconnected = new RingBuffer<DevConsoleSrpcDisconnection>(50);
|
|
107
|
+
readonly mutexEntries = new RingBuffer<DevConsoleMutexEntry>(200);
|
|
108
|
+
readonly activeMutexes = new Map<string, DevConsoleMutexEntry>();
|
|
109
|
+
readonly startedAt = Date.now();
|
|
110
|
+
|
|
111
|
+
onEvent?: (type: string, data: unknown) => void;
|
|
112
|
+
|
|
113
|
+
addHttpEntry(entry: DevConsoleHttpEntry) {
|
|
114
|
+
this.httpEntries.push(entry);
|
|
115
|
+
this.onEvent?.('http:entry', entry);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addSrpcMessage(msg: DevConsoleSrpcMessage) {
|
|
119
|
+
this.srpcMessages.push(msg);
|
|
120
|
+
this.onEvent?.('srpc:message', msg);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addSrpcConnection(conn: DevConsoleSrpcConnection) {
|
|
124
|
+
this.srpcConnections.set(conn.streamId, conn);
|
|
125
|
+
this.onEvent?.('srpc:connection', conn);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
removeSrpcConnection(streamId: string, clientId: string, cause: string) {
|
|
129
|
+
this.srpcConnections.delete(streamId);
|
|
130
|
+
const disc: DevConsoleSrpcDisconnection = { streamId, clientId, disconnectedAt: Date.now(), cause };
|
|
131
|
+
this.srpcDisconnected.push(disc);
|
|
132
|
+
this.onEvent?.('srpc:disconnection', disc);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
addMutexPending(entry: DevConsoleMutexEntry) {
|
|
136
|
+
this.mutexEntries.push(entry);
|
|
137
|
+
this.activeMutexes.set(entry.id, entry);
|
|
138
|
+
this.onEvent?.('mutex:pending', entry);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
updateMutexAcquired(id: string, waited: boolean) {
|
|
142
|
+
const entry = this.activeMutexes.get(id);
|
|
143
|
+
if (entry) {
|
|
144
|
+
entry.status = 'acquired';
|
|
145
|
+
entry.acquiredAt = Date.now();
|
|
146
|
+
entry.waitDurationMs = entry.acquiredAt - entry.startedAt;
|
|
147
|
+
entry.waited = waited;
|
|
148
|
+
this.onEvent?.('mutex:acquired', entry);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
updateMutexReleased(id: string) {
|
|
153
|
+
const entry = this.activeMutexes.get(id);
|
|
154
|
+
if (entry) {
|
|
155
|
+
entry.status = 'released';
|
|
156
|
+
entry.releasedAt = Date.now();
|
|
157
|
+
entry.durationMs = entry.releasedAt - (entry.acquiredAt ?? entry.startedAt);
|
|
158
|
+
this.activeMutexes.delete(id);
|
|
159
|
+
this.onEvent?.('mutex:released', entry);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
updateMutexError(id: string, err: unknown) {
|
|
164
|
+
const entry = this.activeMutexes.get(id);
|
|
165
|
+
if (entry) {
|
|
166
|
+
entry.status = 'error';
|
|
167
|
+
entry.releasedAt = Date.now();
|
|
168
|
+
entry.durationMs = entry.releasedAt - (entry.acquiredAt ?? entry.startedAt);
|
|
169
|
+
entry.error = err instanceof Error ? err.message : String(err);
|
|
170
|
+
this.activeMutexes.delete(id);
|
|
171
|
+
this.onEvent?.('mutex:error', entry);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
addMutexFailed(entry: DevConsoleMutexEntry) {
|
|
176
|
+
this.mutexEntries.push(entry);
|
|
177
|
+
this.onEvent?.('mutex:failed', entry);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static init(): DevConsoleStore {
|
|
181
|
+
if (!this.instance) {
|
|
182
|
+
this.instance = new DevConsoleStore();
|
|
183
|
+
}
|
|
184
|
+
return this.instance;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static get(): DevConsoleStore | null {
|
|
188
|
+
return this.instance;
|
|
189
|
+
}
|
|
190
|
+
}
|