@buenojs/bueno 0.8.9 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cache/index.d.ts +187 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +595 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cli/bin.d.ts +8 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +9 -9
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/commands/add-frontend.d.ts +7 -0
- package/dist/cli/commands/add-frontend.d.ts.map +1 -0
- package/dist/cli/commands/add-frontend.js +376 -0
- package/dist/cli/commands/add-frontend.js.map +1 -0
- package/dist/cli/commands/build.d.ts +7 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +347 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +7 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +205 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +7 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +491 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/help.d.ts +7 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +51 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/index.d.ts +59 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +77 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/migration.d.ts +7 -0
- package/dist/cli/commands/migration.d.ts.map +1 -0
- package/dist/cli/commands/migration.js +295 -0
- package/dist/cli/commands/migration.js.map +1 -0
- package/dist/cli/commands/new.d.ts +7 -0
- package/dist/cli/commands/new.d.ts.map +1 -0
- package/dist/cli/commands/new.js +641 -0
- package/dist/cli/commands/new.js.map +1 -0
- package/dist/cli/commands/start.d.ts +7 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +171 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/core/args.d.ts +61 -0
- package/dist/cli/core/args.d.ts.map +1 -0
- package/dist/cli/core/args.js +224 -0
- package/dist/cli/core/args.js.map +1 -0
- package/dist/cli/core/console.d.ts +135 -0
- package/dist/cli/core/console.d.ts.map +1 -0
- package/dist/cli/core/console.js +268 -0
- package/dist/cli/core/console.js.map +1 -0
- package/dist/cli/core/index.d.ts +10 -0
- package/dist/cli/core/index.d.ts.map +1 -0
- package/dist/cli/core/index.js +10 -0
- package/dist/cli/core/index.js.map +1 -0
- package/dist/cli/core/prompt.d.ts +63 -0
- package/dist/cli/core/prompt.d.ts.map +1 -0
- package/dist/cli/core/prompt.js +338 -0
- package/dist/cli/core/prompt.js.map +1 -0
- package/dist/cli/core/spinner.d.ts +111 -0
- package/dist/cli/core/spinner.d.ts.map +1 -0
- package/dist/cli/core/spinner.js +208 -0
- package/dist/cli/core/spinner.js.map +1 -0
- package/dist/cli/index.d.ts +47 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +127 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/templates/database/index.d.ts +24 -0
- package/dist/cli/templates/database/index.d.ts.map +1 -0
- package/dist/cli/templates/database/index.js +49 -0
- package/dist/cli/templates/database/index.js.map +1 -0
- package/dist/cli/templates/database/mysql.d.ts +6 -0
- package/dist/cli/templates/database/mysql.d.ts.map +1 -0
- package/dist/cli/templates/database/mysql.js +12 -0
- package/dist/cli/templates/database/mysql.js.map +1 -0
- package/dist/cli/templates/database/none.d.ts +8 -0
- package/dist/cli/templates/database/none.d.ts.map +1 -0
- package/dist/cli/templates/database/none.js +14 -0
- package/dist/cli/templates/database/none.js.map +1 -0
- package/dist/cli/templates/database/postgresql.d.ts +6 -0
- package/dist/cli/templates/database/postgresql.d.ts.map +1 -0
- package/dist/cli/templates/database/postgresql.js +12 -0
- package/dist/cli/templates/database/postgresql.js.map +1 -0
- package/dist/cli/templates/database/sqlite.d.ts +6 -0
- package/dist/cli/templates/database/sqlite.d.ts.map +1 -0
- package/dist/cli/templates/database/sqlite.js +12 -0
- package/dist/cli/templates/database/sqlite.js.map +1 -0
- package/dist/cli/templates/deploy.d.ts +41 -0
- package/dist/cli/templates/deploy.d.ts.map +1 -0
- package/dist/cli/templates/deploy.js +278 -0
- package/dist/cli/templates/deploy.js.map +1 -0
- package/dist/cli/templates/docker.d.ts +30 -0
- package/dist/cli/templates/docker.d.ts.map +1 -0
- package/dist/cli/templates/docker.js +298 -0
- package/dist/cli/templates/docker.js.map +1 -0
- package/dist/cli/templates/frontend/index.d.ts +25 -0
- package/dist/cli/templates/frontend/index.d.ts.map +1 -0
- package/dist/cli/templates/frontend/index.js +40 -0
- package/dist/cli/templates/frontend/index.js.map +1 -0
- package/dist/cli/templates/frontend/none.d.ts +8 -0
- package/dist/cli/templates/frontend/none.d.ts.map +1 -0
- package/dist/cli/templates/frontend/none.js +15 -0
- package/dist/cli/templates/frontend/none.js.map +1 -0
- package/dist/cli/templates/frontend/react.d.ts +6 -0
- package/dist/cli/templates/frontend/react.d.ts.map +1 -0
- package/dist/cli/templates/frontend/react.js +139 -0
- package/dist/cli/templates/frontend/react.js.map +1 -0
- package/dist/cli/templates/frontend/solid.d.ts +6 -0
- package/dist/cli/templates/frontend/solid.d.ts.map +1 -0
- package/dist/cli/templates/frontend/solid.js +133 -0
- package/dist/cli/templates/frontend/solid.js.map +1 -0
- package/dist/cli/templates/frontend/svelte.d.ts +6 -0
- package/dist/cli/templates/frontend/svelte.d.ts.map +1 -0
- package/dist/cli/templates/frontend/svelte.js +130 -0
- package/dist/cli/templates/frontend/svelte.js.map +1 -0
- package/dist/cli/templates/frontend/vue.d.ts +6 -0
- package/dist/cli/templates/frontend/vue.d.ts.map +1 -0
- package/dist/cli/templates/frontend/vue.js +129 -0
- package/dist/cli/templates/frontend/vue.js.map +1 -0
- package/dist/cli/templates/generators/index.d.ts +29 -0
- package/dist/cli/templates/generators/index.d.ts.map +1 -0
- package/dist/cli/templates/generators/index.js +308 -0
- package/dist/cli/templates/generators/index.js.map +1 -0
- package/dist/cli/templates/generators/types.d.ts +32 -0
- package/dist/cli/templates/generators/types.d.ts.map +1 -0
- package/dist/cli/templates/generators/types.js +21 -0
- package/dist/cli/templates/generators/types.js.map +1 -0
- package/dist/cli/templates/index.d.ts +12 -0
- package/dist/cli/templates/index.d.ts.map +1 -0
- package/dist/cli/templates/index.js +18 -0
- package/dist/cli/templates/index.js.map +1 -0
- package/dist/cli/templates/project/api.d.ts +6 -0
- package/dist/cli/templates/project/api.d.ts.map +1 -0
- package/dist/cli/templates/project/api.js +79 -0
- package/dist/cli/templates/project/api.js.map +1 -0
- package/dist/cli/templates/project/default.d.ts +6 -0
- package/dist/cli/templates/project/default.d.ts.map +1 -0
- package/dist/cli/templates/project/default.js +136 -0
- package/dist/cli/templates/project/default.js.map +1 -0
- package/dist/cli/templates/project/fullstack.d.ts +14 -0
- package/dist/cli/templates/project/fullstack.d.ts.map +1 -0
- package/dist/cli/templates/project/fullstack.js +19 -0
- package/dist/cli/templates/project/fullstack.js.map +1 -0
- package/dist/cli/templates/project/index.d.ts +26 -0
- package/dist/cli/templates/project/index.d.ts.map +1 -0
- package/dist/cli/templates/project/index.js +60 -0
- package/dist/cli/templates/project/index.js.map +1 -0
- package/dist/cli/templates/project/minimal.d.ts +6 -0
- package/dist/cli/templates/project/minimal.d.ts.map +1 -0
- package/dist/cli/templates/project/minimal.js +43 -0
- package/dist/cli/templates/project/minimal.js.map +1 -0
- package/dist/cli/templates/project/types.d.ts +80 -0
- package/dist/cli/templates/project/types.d.ts.map +1 -0
- package/dist/cli/templates/project/types.js +7 -0
- package/dist/cli/templates/project/types.js.map +1 -0
- package/dist/cli/templates/project/website.d.ts +8 -0
- package/dist/cli/templates/project/website.d.ts.map +1 -0
- package/dist/cli/templates/project/website.js +312 -0
- package/dist/cli/templates/project/website.js.map +1 -0
- package/dist/cli/utils/fs.d.ts +137 -0
- package/dist/cli/utils/fs.d.ts.map +1 -0
- package/dist/cli/utils/fs.js +350 -0
- package/dist/cli/utils/fs.js.map +1 -0
- package/dist/cli/utils/index.d.ts +9 -0
- package/dist/cli/utils/index.d.ts.map +1 -0
- package/dist/cli/utils/index.js +9 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/cli/utils/strings.d.ts +86 -0
- package/dist/cli/utils/strings.d.ts.map +1 -0
- package/dist/cli/utils/strings.js +190 -0
- package/dist/cli/utils/strings.js.map +1 -0
- package/dist/cli/utils/version.d.ts +15 -0
- package/dist/cli/utils/version.d.ts.map +1 -0
- package/dist/cli/utils/version.js +38 -0
- package/dist/cli/utils/version.js.map +1 -0
- package/dist/config/env-validation.d.ts +49 -0
- package/dist/config/env-validation.d.ts.map +1 -0
- package/dist/config/env-validation.js +77 -0
- package/dist/config/env-validation.js.map +1 -0
- package/dist/config/env.d.ts +167 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +392 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +168 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +329 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +81 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +242 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/merge.d.ts +66 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +226 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/types.d.ts +322 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +443 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validation.d.ts +100 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +548 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/container/forward-ref.d.ts +116 -0
- package/dist/container/forward-ref.d.ts.map +1 -0
- package/dist/container/forward-ref.js +105 -0
- package/dist/container/forward-ref.js.map +1 -0
- package/dist/container/index.d.ts +95 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js.map +1 -0
- package/dist/context/index.d.ts +143 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js.map +1 -0
- package/dist/database/index.d.ts +219 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/migrations/index.d.ts +151 -0
- package/dist/database/migrations/index.d.ts.map +1 -0
- package/dist/database/migrations/index.js +258 -0
- package/dist/database/migrations/index.js.map +1 -0
- package/dist/database/orm/builder.d.ts +122 -0
- package/dist/database/orm/builder.d.ts.map +1 -0
- package/dist/database/orm/builder.js +355 -0
- package/dist/database/orm/builder.js.map +1 -0
- package/dist/database/orm/casts/index.d.ts +16 -0
- package/dist/database/orm/casts/index.d.ts.map +1 -0
- package/dist/database/orm/casts/index.js +131 -0
- package/dist/database/orm/casts/index.js.map +1 -0
- package/dist/database/orm/casts/types.d.ts +16 -0
- package/dist/database/orm/casts/types.d.ts.map +1 -0
- package/dist/database/orm/casts/types.js +5 -0
- package/dist/database/orm/casts/types.js.map +1 -0
- package/dist/database/orm/compiler.d.ts +90 -0
- package/dist/database/orm/compiler.d.ts.map +1 -0
- package/dist/database/orm/compiler.js +218 -0
- package/dist/database/orm/compiler.js.map +1 -0
- package/dist/database/orm/hooks/index.d.ts +53 -0
- package/dist/database/orm/hooks/index.d.ts.map +1 -0
- package/dist/database/orm/hooks/index.js +81 -0
- package/dist/database/orm/hooks/index.js.map +1 -0
- package/dist/database/orm/index.d.ts +21 -0
- package/dist/database/orm/index.d.ts.map +1 -0
- package/dist/database/orm/index.js +23 -0
- package/dist/database/orm/index.js.map +1 -0
- package/dist/database/orm/model-registry.d.ts +33 -0
- package/dist/database/orm/model-registry.d.ts.map +1 -0
- package/dist/database/orm/model-registry.js +49 -0
- package/dist/database/orm/model-registry.js.map +1 -0
- package/dist/database/orm/model.d.ts +245 -0
- package/dist/database/orm/model.d.ts.map +1 -0
- package/dist/database/orm/model.js +599 -0
- package/dist/database/orm/model.js.map +1 -0
- package/dist/database/orm/relationships/base.d.ts +69 -0
- package/dist/database/orm/relationships/base.d.ts.map +1 -0
- package/dist/database/orm/relationships/base.js +84 -0
- package/dist/database/orm/relationships/base.js.map +1 -0
- package/dist/database/orm/relationships/belongs-to-many.d.ts +47 -0
- package/dist/database/orm/relationships/belongs-to-many.d.ts.map +1 -0
- package/dist/database/orm/relationships/belongs-to-many.js +136 -0
- package/dist/database/orm/relationships/belongs-to-many.js.map +1 -0
- package/dist/database/orm/relationships/belongs-to.d.ts +17 -0
- package/dist/database/orm/relationships/belongs-to.d.ts.map +1 -0
- package/dist/database/orm/relationships/belongs-to.js +38 -0
- package/dist/database/orm/relationships/belongs-to.js.map +1 -0
- package/dist/database/orm/relationships/has-many.d.ts +14 -0
- package/dist/database/orm/relationships/has-many.d.ts.map +1 -0
- package/dist/database/orm/relationships/has-many.js +35 -0
- package/dist/database/orm/relationships/has-many.js.map +1 -0
- package/dist/database/orm/relationships/has-one.d.ts +14 -0
- package/dist/database/orm/relationships/has-one.d.ts.map +1 -0
- package/dist/database/orm/relationships/has-one.js +32 -0
- package/dist/database/orm/relationships/has-one.js.map +1 -0
- package/dist/database/orm/relationships/index.d.ts +10 -0
- package/dist/database/orm/relationships/index.d.ts.map +1 -0
- package/dist/database/orm/relationships/index.js +9 -0
- package/dist/database/orm/relationships/index.js.map +1 -0
- package/dist/database/orm/scopes/index.d.ts +36 -0
- package/dist/database/orm/scopes/index.d.ts.map +1 -0
- package/dist/database/orm/scopes/index.js +47 -0
- package/dist/database/orm/scopes/index.js.map +1 -0
- package/dist/database/schema/index.d.ts +155 -0
- package/dist/database/schema/index.d.ts.map +1 -0
- package/dist/database/schema/index.js +401 -0
- package/dist/database/schema/index.js.map +1 -0
- package/dist/frontend/api-routes.d.ts +189 -0
- package/dist/frontend/api-routes.d.ts.map +1 -0
- package/dist/frontend/api-routes.js +548 -0
- package/dist/frontend/api-routes.js.map +1 -0
- package/dist/frontend/bundler.d.ts +99 -0
- package/dist/frontend/bundler.d.ts.map +1 -0
- package/dist/frontend/bundler.js +555 -0
- package/dist/frontend/bundler.js.map +1 -0
- package/dist/frontend/console-client.d.ts +11 -0
- package/dist/frontend/console-client.d.ts.map +1 -0
- package/dist/frontend/console-client.js +414 -0
- package/dist/frontend/console-client.js.map +1 -0
- package/dist/frontend/console-stream.d.ts +138 -0
- package/dist/frontend/console-stream.d.ts.map +1 -0
- package/dist/frontend/console-stream.js +535 -0
- package/dist/frontend/console-stream.js.map +1 -0
- package/dist/frontend/dev-server.d.ts +174 -0
- package/dist/frontend/dev-server.d.ts.map +1 -0
- package/dist/frontend/dev-server.js +735 -0
- package/dist/frontend/dev-server.js.map +1 -0
- package/dist/frontend/file-router.d.ts +170 -0
- package/dist/frontend/file-router.d.ts.map +1 -0
- package/dist/frontend/file-router.js +531 -0
- package/dist/frontend/file-router.js.map +1 -0
- package/dist/frontend/frameworks/index.d.ts +41 -0
- package/dist/frontend/frameworks/index.d.ts.map +1 -0
- package/dist/frontend/frameworks/index.js +87 -0
- package/dist/frontend/frameworks/index.js.map +1 -0
- package/dist/frontend/frameworks/react.d.ts +32 -0
- package/dist/frontend/frameworks/react.d.ts.map +1 -0
- package/dist/frontend/frameworks/react.js +66 -0
- package/dist/frontend/frameworks/react.js.map +1 -0
- package/dist/frontend/frameworks/solid.d.ts +42 -0
- package/dist/frontend/frameworks/solid.d.ts.map +1 -0
- package/dist/frontend/frameworks/solid.js +84 -0
- package/dist/frontend/frameworks/solid.js.map +1 -0
- package/dist/frontend/frameworks/svelte.d.ts +57 -0
- package/dist/frontend/frameworks/svelte.d.ts.map +1 -0
- package/dist/frontend/frameworks/svelte.js +90 -0
- package/dist/frontend/frameworks/svelte.js.map +1 -0
- package/dist/frontend/frameworks/vue.d.ts +36 -0
- package/dist/frontend/frameworks/vue.d.ts.map +1 -0
- package/dist/frontend/frameworks/vue.js +72 -0
- package/dist/frontend/frameworks/vue.js.map +1 -0
- package/dist/frontend/hmr-client.d.ts +22 -0
- package/dist/frontend/hmr-client.d.ts.map +1 -0
- package/dist/frontend/hmr-client.js +654 -0
- package/dist/frontend/hmr-client.js.map +1 -0
- package/dist/frontend/hmr.d.ts +185 -0
- package/dist/frontend/hmr.d.ts.map +1 -0
- package/dist/frontend/hmr.js +619 -0
- package/dist/frontend/hmr.js.map +1 -0
- package/dist/frontend/index.d.ts +34 -0
- package/dist/frontend/index.d.ts.map +1 -0
- package/dist/frontend/index.js.map +1 -0
- package/dist/frontend/islands.d.ts +135 -0
- package/dist/frontend/islands.d.ts.map +1 -0
- package/dist/frontend/islands.js +455 -0
- package/dist/frontend/islands.js.map +1 -0
- package/dist/frontend/isr.d.ts +143 -0
- package/dist/frontend/isr.d.ts.map +1 -0
- package/dist/frontend/isr.js +440 -0
- package/dist/frontend/isr.js.map +1 -0
- package/dist/frontend/layout.d.ts +140 -0
- package/dist/frontend/layout.d.ts.map +1 -0
- package/dist/frontend/layout.js +392 -0
- package/dist/frontend/layout.js.map +1 -0
- package/dist/frontend/ssr/react.d.ts +118 -0
- package/dist/frontend/ssr/react.d.ts.map +1 -0
- package/dist/frontend/ssr/react.js +373 -0
- package/dist/frontend/ssr/react.js.map +1 -0
- package/dist/frontend/ssr/solid.d.ts +141 -0
- package/dist/frontend/ssr/solid.d.ts.map +1 -0
- package/dist/frontend/ssr/solid.js +440 -0
- package/dist/frontend/ssr/solid.js.map +1 -0
- package/dist/frontend/ssr/svelte.d.ts +158 -0
- package/dist/frontend/ssr/svelte.d.ts.map +1 -0
- package/dist/frontend/ssr/svelte.js +439 -0
- package/dist/frontend/ssr/svelte.js.map +1 -0
- package/dist/frontend/ssr/vue.d.ts +161 -0
- package/dist/frontend/ssr/vue.d.ts.map +1 -0
- package/dist/frontend/ssr/vue.js +385 -0
- package/dist/frontend/ssr/vue.js.map +1 -0
- package/dist/frontend/ssr.d.ts +147 -0
- package/dist/frontend/ssr.d.ts.map +1 -0
- package/dist/frontend/ssr.js +609 -0
- package/dist/frontend/ssr.js.map +1 -0
- package/dist/frontend/types.d.ts +1902 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +8 -0
- package/dist/frontend/types.js.map +1 -0
- package/dist/graphql/built-in-engine.d.ts +36 -0
- package/dist/graphql/built-in-engine.d.ts.map +1 -0
- package/dist/graphql/built-in-engine.js +443 -0
- package/dist/graphql/built-in-engine.js.map +1 -0
- package/dist/graphql/context-builder.d.ts +44 -0
- package/dist/graphql/context-builder.d.ts.map +1 -0
- package/dist/graphql/context-builder.js +91 -0
- package/dist/graphql/context-builder.js.map +1 -0
- package/dist/graphql/decorators.d.ts +162 -0
- package/dist/graphql/decorators.d.ts.map +1 -0
- package/dist/graphql/decorators.js +291 -0
- package/dist/graphql/decorators.js.map +1 -0
- package/dist/graphql/execution-pipeline.d.ts +67 -0
- package/dist/graphql/execution-pipeline.d.ts.map +1 -0
- package/dist/graphql/execution-pipeline.js +127 -0
- package/dist/graphql/execution-pipeline.js.map +1 -0
- package/dist/graphql/graphql-module.d.ts +70 -0
- package/dist/graphql/graphql-module.d.ts.map +1 -0
- package/dist/graphql/graphql-module.js +442 -0
- package/dist/graphql/graphql-module.js.map +1 -0
- package/dist/graphql/index.d.ts +48 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/metadata.d.ts +37 -0
- package/dist/graphql/metadata.d.ts.map +1 -0
- package/dist/graphql/metadata.js +130 -0
- package/dist/graphql/metadata.js.map +1 -0
- package/dist/graphql/schema-builder.d.ts +34 -0
- package/dist/graphql/schema-builder.d.ts.map +1 -0
- package/dist/graphql/schema-builder.js +251 -0
- package/dist/graphql/schema-builder.js.map +1 -0
- package/dist/graphql/subscription-handler.d.ts +47 -0
- package/dist/graphql/subscription-handler.d.ts.map +1 -0
- package/dist/graphql/subscription-handler.js +201 -0
- package/dist/graphql/subscription-handler.js.map +1 -0
- package/dist/graphql/types.d.ts +252 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +28 -0
- package/dist/graphql/types.js.map +1 -0
- package/dist/health/index.d.ts +176 -0
- package/dist/health/index.d.ts.map +1 -0
- package/dist/health/index.js.map +1 -0
- package/dist/i18n/engine.d.ts +105 -0
- package/dist/i18n/engine.d.ts.map +1 -0
- package/dist/i18n/engine.js +248 -0
- package/dist/i18n/engine.js.map +1 -0
- package/dist/i18n/index.d.ts +13 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/loader.d.ts +79 -0
- package/dist/i18n/loader.d.ts.map +1 -0
- package/dist/i18n/loader.js +192 -0
- package/dist/i18n/loader.js.map +1 -0
- package/dist/i18n/middleware.d.ts +96 -0
- package/dist/i18n/middleware.d.ts.map +1 -0
- package/dist/i18n/middleware.js +126 -0
- package/dist/i18n/middleware.js.map +1 -0
- package/dist/i18n/negotiator.d.ts +84 -0
- package/dist/i18n/negotiator.d.ts.map +1 -0
- package/dist/i18n/negotiator.js +139 -0
- package/dist/i18n/negotiator.js.map +1 -0
- package/dist/i18n/types.d.ts +129 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +8 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/drivers/memory.d.ts +38 -0
- package/dist/jobs/drivers/memory.d.ts.map +1 -0
- package/dist/jobs/drivers/memory.js +246 -0
- package/dist/jobs/drivers/memory.js.map +1 -0
- package/dist/jobs/drivers/redis.d.ts +34 -0
- package/dist/jobs/drivers/redis.d.ts.map +1 -0
- package/dist/jobs/drivers/redis.js +355 -0
- package/dist/jobs/drivers/redis.js.map +1 -0
- package/dist/jobs/index.d.ts +12 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/queue.d.ts +93 -0
- package/dist/jobs/queue.d.ts.map +1 -0
- package/dist/jobs/queue.js +233 -0
- package/dist/jobs/queue.js.map +1 -0
- package/dist/jobs/types.d.ts +193 -0
- package/dist/jobs/types.d.ts.map +1 -0
- package/dist/jobs/types.js +8 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/jobs/worker.d.ts +91 -0
- package/dist/jobs/worker.d.ts.map +1 -0
- package/dist/jobs/worker.js +300 -0
- package/dist/jobs/worker.js.map +1 -0
- package/dist/lock/index.d.ts +141 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/logger/index.d.ts +156 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/transports/index.d.ts +371 -0
- package/dist/logger/transports/index.d.ts.map +1 -0
- package/dist/logger/transports/index.js +740 -0
- package/dist/logger/transports/index.js.map +1 -0
- package/dist/metrics/index.d.ts +163 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/middleware/built-in.d.ts +50 -0
- package/dist/middleware/built-in.d.ts.map +1 -0
- package/dist/middleware/built-in.js +220 -0
- package/dist/middleware/built-in.js.map +1 -0
- package/dist/middleware/index.d.ts +40 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/migrations/index.d.ts +48 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +3 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/modules/filters.d.ts +150 -0
- package/dist/modules/filters.d.ts.map +1 -0
- package/dist/modules/filters.js +338 -0
- package/dist/modules/filters.js.map +1 -0
- package/dist/modules/guards.d.ts +188 -0
- package/dist/modules/guards.d.ts.map +1 -0
- package/dist/modules/guards.js +278 -0
- package/dist/modules/guards.js.map +1 -0
- package/dist/modules/index.d.ts +266 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/interceptors.d.ts +242 -0
- package/dist/modules/interceptors.d.ts.map +1 -0
- package/dist/modules/interceptors.js +407 -0
- package/dist/modules/interceptors.js.map +1 -0
- package/dist/modules/lazy.d.ts +187 -0
- package/dist/modules/lazy.d.ts.map +1 -0
- package/dist/modules/lazy.js +305 -0
- package/dist/modules/lazy.js.map +1 -0
- package/dist/modules/lifecycle.d.ts +221 -0
- package/dist/modules/lifecycle.d.ts.map +1 -0
- package/dist/modules/lifecycle.js +314 -0
- package/dist/modules/lifecycle.js.map +1 -0
- package/dist/modules/metadata.d.ts +32 -0
- package/dist/modules/metadata.d.ts.map +1 -0
- package/dist/modules/metadata.js +59 -0
- package/dist/modules/metadata.js.map +1 -0
- package/dist/modules/pipes.d.ts +287 -0
- package/dist/modules/pipes.d.ts.map +1 -0
- package/dist/modules/pipes.js +443 -0
- package/dist/modules/pipes.js.map +1 -0
- package/dist/notification/channels/base.d.ts +32 -0
- package/dist/notification/channels/base.d.ts.map +1 -0
- package/dist/notification/channels/base.js +37 -0
- package/dist/notification/channels/base.js.map +1 -0
- package/dist/notification/channels/email.d.ts +37 -0
- package/dist/notification/channels/email.d.ts.map +1 -0
- package/dist/notification/channels/email.js +85 -0
- package/dist/notification/channels/email.js.map +1 -0
- package/dist/notification/channels/push.d.ts +37 -0
- package/dist/notification/channels/push.d.ts.map +1 -0
- package/dist/notification/channels/push.js +84 -0
- package/dist/notification/channels/push.js.map +1 -0
- package/dist/notification/channels/sms.d.ts +37 -0
- package/dist/notification/channels/sms.d.ts.map +1 -0
- package/dist/notification/channels/sms.js +83 -0
- package/dist/notification/channels/sms.js.map +1 -0
- package/dist/notification/channels/whatsapp.d.ts +37 -0
- package/dist/notification/channels/whatsapp.d.ts.map +1 -0
- package/dist/notification/channels/whatsapp.js +81 -0
- package/dist/notification/channels/whatsapp.js.map +1 -0
- package/dist/notification/index.d.ts +15 -0
- package/dist/notification/index.d.ts.map +1 -0
- package/dist/notification/index.js.map +1 -0
- package/dist/notification/service.d.ts +100 -0
- package/dist/notification/service.d.ts.map +1 -0
- package/dist/notification/service.js +279 -0
- package/dist/notification/service.js.map +1 -0
- package/dist/notification/types.d.ts +253 -0
- package/dist/notification/types.d.ts.map +1 -0
- package/dist/notification/types.js +14 -0
- package/dist/notification/types.js.map +1 -0
- package/dist/observability/__tests__/observability.test.d.ts +2 -0
- package/dist/observability/__tests__/observability.test.d.ts.map +1 -0
- package/dist/observability/__tests__/observability.test.js +404 -0
- package/dist/observability/__tests__/observability.test.js.map +1 -0
- package/dist/observability/breadcrumbs.d.ts +48 -0
- package/dist/observability/breadcrumbs.d.ts.map +1 -0
- package/dist/observability/breadcrumbs.js +97 -0
- package/dist/observability/breadcrumbs.js.map +1 -0
- package/dist/observability/index.d.ts +95 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/interceptor.d.ts +19 -0
- package/dist/observability/interceptor.d.ts.map +1 -0
- package/dist/observability/interceptor.js +67 -0
- package/dist/observability/interceptor.js.map +1 -0
- package/dist/observability/service.d.ts +101 -0
- package/dist/observability/service.d.ts.map +1 -0
- package/dist/observability/service.js +249 -0
- package/dist/observability/service.js.map +1 -0
- package/dist/observability/trace.d.ts +21 -0
- package/dist/observability/trace.d.ts.map +1 -0
- package/dist/observability/trace.js +35 -0
- package/dist/observability/trace.js.map +1 -0
- package/dist/observability/types.d.ts +172 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +8 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/openapi/decorators.d.ts +173 -0
- package/dist/openapi/decorators.d.ts.map +1 -0
- package/dist/openapi/decorators.js +276 -0
- package/dist/openapi/decorators.js.map +1 -0
- package/dist/openapi/document-builder.d.ts +82 -0
- package/dist/openapi/document-builder.d.ts.map +1 -0
- package/dist/openapi/document-builder.js +228 -0
- package/dist/openapi/document-builder.js.map +1 -0
- package/dist/openapi/index.d.ts +48 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/metadata.d.ts +36 -0
- package/dist/openapi/metadata.d.ts.map +1 -0
- package/dist/openapi/metadata.js +78 -0
- package/dist/openapi/metadata.js.map +1 -0
- package/dist/openapi/route-scanner.d.ts +34 -0
- package/dist/openapi/route-scanner.d.ts.map +1 -0
- package/dist/openapi/route-scanner.js +174 -0
- package/dist/openapi/route-scanner.js.map +1 -0
- package/dist/openapi/schema-generator.d.ts +53 -0
- package/dist/openapi/schema-generator.d.ts.map +1 -0
- package/dist/openapi/schema-generator.js +236 -0
- package/dist/openapi/schema-generator.js.map +1 -0
- package/dist/openapi/swagger-module.d.ts +57 -0
- package/dist/openapi/swagger-module.d.ts.map +1 -0
- package/dist/openapi/swagger-module.js +143 -0
- package/dist/openapi/swagger-module.js.map +1 -0
- package/dist/openapi/types.d.ts +344 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/openapi/types.js +7 -0
- package/dist/openapi/types.js.map +1 -0
- package/dist/orm/index.d.ts +10 -0
- package/dist/orm/index.d.ts.map +1 -0
- package/dist/orm/index.js.map +1 -0
- package/dist/router/index.d.ts +73 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/linear.d.ts +54 -0
- package/dist/router/linear.d.ts.map +1 -0
- package/dist/router/linear.js +261 -0
- package/dist/router/linear.js.map +1 -0
- package/dist/router/regex.d.ts +49 -0
- package/dist/router/regex.d.ts.map +1 -0
- package/dist/router/regex.js +201 -0
- package/dist/router/regex.js.map +1 -0
- package/dist/router/tree.d.ts +112 -0
- package/dist/router/tree.d.ts.map +1 -0
- package/dist/router/tree.js +360 -0
- package/dist/router/tree.js.map +1 -0
- package/dist/rpc/index.d.ts +321 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/schema/index.d.ts +10 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/security/index.d.ts +126 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +309 -0
- package/dist/security/index.js.map +1 -0
- package/dist/ssg/index.d.ts +73 -0
- package/dist/ssg/index.d.ts.map +1 -0
- package/dist/ssg/index.js +464 -0
- package/dist/ssg/index.js.map +1 -0
- package/dist/storage/index.d.ts +99 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +338 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +376 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/template/index.d.ts +7 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js.map +1 -0
- package/dist/templates/engine.d.ts +60 -0
- package/dist/templates/engine.d.ts.map +1 -0
- package/dist/templates/engine.js +177 -0
- package/dist/templates/engine.js.map +1 -0
- package/dist/templates/index.d.ts +9 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/loader.d.ts +45 -0
- package/dist/templates/loader.d.ts.map +1 -0
- package/dist/templates/loader.js +274 -0
- package/dist/templates/loader.js.map +1 -0
- package/dist/templates/renderers/markdown.d.ts +46 -0
- package/dist/templates/renderers/markdown.d.ts.map +1 -0
- package/dist/templates/renderers/markdown.js +181 -0
- package/dist/templates/renderers/markdown.js.map +1 -0
- package/dist/templates/renderers/simple.d.ts +35 -0
- package/dist/templates/renderers/simple.d.ts.map +1 -0
- package/dist/templates/renderers/simple.js +245 -0
- package/dist/templates/renderers/simple.js.map +1 -0
- package/dist/templates/types.d.ts +138 -0
- package/dist/templates/types.d.ts.map +1 -0
- package/dist/templates/types.js +8 -0
- package/dist/templates/types.js.map +1 -0
- package/dist/testing/index.d.ts +539 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/validation/index.d.ts +89 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +276 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +283 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +407 -0
- package/dist/validation/schemas.js.map +1 -0
- package/dist/websocket/index.d.ts +252 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +749 -0
- package/dist/websocket/index.js.map +1 -0
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/src/cli/commands/new.ts +1 -1
- package/src/cli/templates/frontend/react.ts +1 -1
- package/src/cli/templates/frontend/solid.ts +1 -1
- package/src/cli/templates/frontend/svelte.ts +1 -1
- package/src/cli/templates/frontend/vue.ts +1 -1
- package/src/cli/templates/project/default.ts +1 -1
- package/src/cli/templates/project/website.ts +3 -3
- package/src/database/migrations/index.ts +8 -0
- package/src/migrations/index.ts +40 -1
- package/src/types/index.ts +1 -1
- package/tsconfig.json +2 -6
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket Helpers
|
|
3
|
+
*
|
|
4
|
+
* Utilities for WebSocket connections, pub/sub patterns,
|
|
5
|
+
* and real-time communication in Bueno applications.
|
|
6
|
+
*/
|
|
7
|
+
export class WebSocketServer {
|
|
8
|
+
options;
|
|
9
|
+
connections = new Map();
|
|
10
|
+
rooms = new Map();
|
|
11
|
+
messageHandlers = new Map();
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.options = {
|
|
14
|
+
idleTimeout: 255,
|
|
15
|
+
maxPayloadLength: 1024 * 1024, // 1MB
|
|
16
|
+
perMessageDeflate: true,
|
|
17
|
+
...options,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get Bun WebSocket configuration
|
|
22
|
+
*/
|
|
23
|
+
getWebSocketConfig() {
|
|
24
|
+
return {
|
|
25
|
+
idleTimeout: this.options.idleTimeout,
|
|
26
|
+
maxPayloadLength: this.options.maxPayloadLength,
|
|
27
|
+
perMessageDeflate: this.options.perMessageDeflate,
|
|
28
|
+
open: (ws) => {
|
|
29
|
+
this.connections.set(ws.data.id, ws);
|
|
30
|
+
this.options.onOpen?.(ws);
|
|
31
|
+
},
|
|
32
|
+
message: (ws, message) => {
|
|
33
|
+
let parsed;
|
|
34
|
+
if (typeof message === "string") {
|
|
35
|
+
try {
|
|
36
|
+
parsed = JSON.parse(message);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
parsed = { type: "raw", payload: message, timestamp: Date.now() };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
parsed = { type: "binary", payload: message, timestamp: Date.now() };
|
|
44
|
+
}
|
|
45
|
+
// Call global handler
|
|
46
|
+
this.options.onMessage?.(ws, parsed);
|
|
47
|
+
// Call type-specific handlers
|
|
48
|
+
const handlers = this.messageHandlers.get(parsed.type);
|
|
49
|
+
if (handlers) {
|
|
50
|
+
for (const handler of handlers) {
|
|
51
|
+
handler(ws, parsed);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
close: (ws, code, reason) => {
|
|
56
|
+
this.connections.delete(ws.data.id);
|
|
57
|
+
// Remove from all rooms
|
|
58
|
+
for (const [room, members] of this.rooms) {
|
|
59
|
+
members.delete(ws.data.id);
|
|
60
|
+
}
|
|
61
|
+
this.options.onClose?.(ws, code, reason);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Register a message type handler
|
|
67
|
+
*/
|
|
68
|
+
on(type, handler) {
|
|
69
|
+
const handlers = this.messageHandlers.get(type) ?? [];
|
|
70
|
+
handlers.push(handler);
|
|
71
|
+
this.messageHandlers.set(type, handlers);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Broadcast to all connections
|
|
76
|
+
*/
|
|
77
|
+
broadcast(type, payload) {
|
|
78
|
+
const message = { type, payload, timestamp: Date.now() };
|
|
79
|
+
const data = JSON.stringify(message);
|
|
80
|
+
for (const ws of this.connections.values()) {
|
|
81
|
+
ws.send(data);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Send to specific connection
|
|
86
|
+
*/
|
|
87
|
+
send(connectionId, type, payload) {
|
|
88
|
+
const ws = this.connections.get(connectionId);
|
|
89
|
+
if (!ws)
|
|
90
|
+
return false;
|
|
91
|
+
const message = { type, payload, timestamp: Date.now() };
|
|
92
|
+
ws.send(JSON.stringify(message));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Broadcast to a room
|
|
97
|
+
*/
|
|
98
|
+
broadcastToRoom(room, type, payload) {
|
|
99
|
+
const members = this.rooms.get(room);
|
|
100
|
+
if (!members)
|
|
101
|
+
return;
|
|
102
|
+
const message = { type, payload, timestamp: Date.now() };
|
|
103
|
+
const data = JSON.stringify(message);
|
|
104
|
+
for (const id of members) {
|
|
105
|
+
const ws = this.connections.get(id);
|
|
106
|
+
if (ws) {
|
|
107
|
+
ws.send(data);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Join a room
|
|
113
|
+
*/
|
|
114
|
+
joinRoom(connectionId, room) {
|
|
115
|
+
if (!this.rooms.has(room)) {
|
|
116
|
+
this.rooms.set(room, new Set());
|
|
117
|
+
}
|
|
118
|
+
this.rooms.get(room)?.add(connectionId);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Leave a room
|
|
122
|
+
*/
|
|
123
|
+
leaveRoom(connectionId, room) {
|
|
124
|
+
this.rooms.get(room)?.delete(connectionId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get room members
|
|
128
|
+
*/
|
|
129
|
+
getRoomMembers(room) {
|
|
130
|
+
return Array.from(this.rooms.get(room) ?? []);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get all connection IDs
|
|
134
|
+
*/
|
|
135
|
+
getConnectionIds() {
|
|
136
|
+
return Array.from(this.connections.keys());
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get connection count
|
|
140
|
+
*/
|
|
141
|
+
get connectionCount() {
|
|
142
|
+
return this.connections.size;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if connection exists
|
|
146
|
+
*/
|
|
147
|
+
hasConnection(connectionId) {
|
|
148
|
+
return this.connections.has(connectionId);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Close a connection
|
|
152
|
+
*/
|
|
153
|
+
closeConnection(connectionId, code = 1000, reason = "Closed by server") {
|
|
154
|
+
const ws = this.connections.get(connectionId);
|
|
155
|
+
if (!ws)
|
|
156
|
+
return false;
|
|
157
|
+
ws.close(code, reason);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Close all connections
|
|
162
|
+
*/
|
|
163
|
+
closeAll(code = 1000, reason = "Server shutting down") {
|
|
164
|
+
for (const ws of this.connections.values()) {
|
|
165
|
+
ws.close(code, reason);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export class WebSocketClient {
|
|
170
|
+
ws = null;
|
|
171
|
+
options;
|
|
172
|
+
reconnectAttempts = 0;
|
|
173
|
+
shouldReconnect = true;
|
|
174
|
+
messageQueue = [];
|
|
175
|
+
constructor(options) {
|
|
176
|
+
this.options = {
|
|
177
|
+
reconnect: true,
|
|
178
|
+
reconnectInterval: 1000,
|
|
179
|
+
maxReconnectAttempts: 5,
|
|
180
|
+
...options,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Connect to WebSocket server
|
|
185
|
+
*/
|
|
186
|
+
connect() {
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
try {
|
|
189
|
+
this.ws = new WebSocket(this.options.url, this.options.protocols);
|
|
190
|
+
this.shouldReconnect = true;
|
|
191
|
+
this.ws.onopen = () => {
|
|
192
|
+
this.reconnectAttempts = 0;
|
|
193
|
+
// Send queued messages
|
|
194
|
+
while (this.messageQueue.length > 0) {
|
|
195
|
+
const message = this.messageQueue.shift();
|
|
196
|
+
this.ws?.send(message);
|
|
197
|
+
}
|
|
198
|
+
this.options.onOpen?.();
|
|
199
|
+
resolve();
|
|
200
|
+
};
|
|
201
|
+
this.ws.onclose = (event) => {
|
|
202
|
+
this.options.onClose?.(event);
|
|
203
|
+
if (this.shouldReconnect && this.options.reconnect) {
|
|
204
|
+
this.attemptReconnect();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
this.ws.onmessage = (event) => {
|
|
208
|
+
let message;
|
|
209
|
+
try {
|
|
210
|
+
message = JSON.parse(event.data);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
message = {
|
|
214
|
+
type: "raw",
|
|
215
|
+
payload: event.data,
|
|
216
|
+
timestamp: Date.now(),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
this.options.onMessage?.(message);
|
|
220
|
+
};
|
|
221
|
+
this.ws.onerror = (event) => {
|
|
222
|
+
this.options.onError?.(event);
|
|
223
|
+
reject(event);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
reject(error);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Attempt to reconnect
|
|
233
|
+
*/
|
|
234
|
+
attemptReconnect() {
|
|
235
|
+
if (this.reconnectAttempts >= (this.options.maxReconnectAttempts ?? 5)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.reconnectAttempts++;
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
this.connect().catch(() => {
|
|
241
|
+
// Reconnect failed, will try again if attempts remaining
|
|
242
|
+
});
|
|
243
|
+
}, this.options.reconnectInterval);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Send a message
|
|
247
|
+
*/
|
|
248
|
+
send(type, payload) {
|
|
249
|
+
const message = { type, payload, timestamp: Date.now() };
|
|
250
|
+
const data = JSON.stringify(message);
|
|
251
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
252
|
+
this.ws.send(data);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Queue message for when connection is ready
|
|
256
|
+
this.messageQueue.push(data);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Send raw data
|
|
261
|
+
*/
|
|
262
|
+
async sendRaw(data) {
|
|
263
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
264
|
+
if (data instanceof Blob) {
|
|
265
|
+
this.ws.send(await data.arrayBuffer());
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.ws.send(data);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Close the connection
|
|
274
|
+
*/
|
|
275
|
+
close(code = 1000, reason = "Client closing") {
|
|
276
|
+
this.shouldReconnect = false;
|
|
277
|
+
this.ws?.close(code, reason);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Check if connected
|
|
281
|
+
*/
|
|
282
|
+
get isConnected() {
|
|
283
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get ready state
|
|
287
|
+
*/
|
|
288
|
+
get readyState() {
|
|
289
|
+
return this.ws?.readyState ?? WebSocket.CLOSED;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// ============= In-Memory Pub/Sub (Fallback) =============
|
|
293
|
+
class InMemoryPubSub {
|
|
294
|
+
channels = new Map();
|
|
295
|
+
patterns = new Map();
|
|
296
|
+
async publish(channel, data) {
|
|
297
|
+
const message = {
|
|
298
|
+
channel,
|
|
299
|
+
data,
|
|
300
|
+
timestamp: Date.now(),
|
|
301
|
+
};
|
|
302
|
+
let deliveredCount = 0;
|
|
303
|
+
// Direct channel subscribers
|
|
304
|
+
const subscribers = this.channels.get(channel);
|
|
305
|
+
if (subscribers) {
|
|
306
|
+
for (const callback of subscribers) {
|
|
307
|
+
await callback(message);
|
|
308
|
+
deliveredCount++;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Pattern subscribers
|
|
312
|
+
for (const [pattern, callbacks] of this.patterns) {
|
|
313
|
+
if (this.matchPattern(pattern, channel)) {
|
|
314
|
+
const patternMessage = { ...message, pattern };
|
|
315
|
+
for (const callback of callbacks) {
|
|
316
|
+
await callback(patternMessage);
|
|
317
|
+
deliveredCount++;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return deliveredCount;
|
|
322
|
+
}
|
|
323
|
+
async subscribe(channel, callback) {
|
|
324
|
+
if (!this.channels.has(channel)) {
|
|
325
|
+
this.channels.set(channel, new Set());
|
|
326
|
+
}
|
|
327
|
+
this.channels.get(channel)?.add(callback);
|
|
328
|
+
return () => {
|
|
329
|
+
this.channels.get(channel)?.delete(callback);
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
async psubscribe(pattern, callback) {
|
|
333
|
+
if (!this.patterns.has(pattern)) {
|
|
334
|
+
this.patterns.set(pattern, new Set());
|
|
335
|
+
}
|
|
336
|
+
this.patterns.get(pattern)?.add(callback);
|
|
337
|
+
return () => {
|
|
338
|
+
this.patterns.get(pattern)?.delete(callback);
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
async unsubscribe(channel) {
|
|
342
|
+
this.channels.delete(channel);
|
|
343
|
+
}
|
|
344
|
+
async punsubscribe(pattern) {
|
|
345
|
+
this.patterns.delete(pattern);
|
|
346
|
+
}
|
|
347
|
+
getChannelSubscribers(channel) {
|
|
348
|
+
return this.channels.get(channel)?.size ?? 0;
|
|
349
|
+
}
|
|
350
|
+
getPatternSubscribers(pattern) {
|
|
351
|
+
return this.patterns.get(pattern)?.size ?? 0;
|
|
352
|
+
}
|
|
353
|
+
getTotalSubscribers() {
|
|
354
|
+
let total = 0;
|
|
355
|
+
for (const subscribers of this.channels.values()) {
|
|
356
|
+
total += subscribers.size;
|
|
357
|
+
}
|
|
358
|
+
for (const subscribers of this.patterns.values()) {
|
|
359
|
+
total += subscribers.size;
|
|
360
|
+
}
|
|
361
|
+
return total;
|
|
362
|
+
}
|
|
363
|
+
async clear() {
|
|
364
|
+
this.channels.clear();
|
|
365
|
+
this.patterns.clear();
|
|
366
|
+
}
|
|
367
|
+
destroy() {
|
|
368
|
+
this.channels.clear();
|
|
369
|
+
this.patterns.clear();
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Match a pattern against a channel name
|
|
373
|
+
* Supports * (match any characters) and ? (match single character)
|
|
374
|
+
*/
|
|
375
|
+
matchPattern(pattern, channel) {
|
|
376
|
+
const regex = new RegExp(`^${pattern
|
|
377
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape special regex chars except * and ?
|
|
378
|
+
.replace(/\*/g, ".*") // * matches any characters
|
|
379
|
+
.replace(/\?/g, ".")}$`);
|
|
380
|
+
return regex.test(channel);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// ============= Redis Pub/Sub (Bun.redis Native) =============
|
|
384
|
+
class RedisPubSub {
|
|
385
|
+
publisher = null;
|
|
386
|
+
subscriber = null;
|
|
387
|
+
url;
|
|
388
|
+
keyPrefix;
|
|
389
|
+
channelCallbacks = new Map();
|
|
390
|
+
patternCallbacks = new Map();
|
|
391
|
+
_isConnected = false;
|
|
392
|
+
reconnect;
|
|
393
|
+
reconnectInterval;
|
|
394
|
+
maxReconnectAttempts;
|
|
395
|
+
reconnectAttempts = 0;
|
|
396
|
+
constructor(config) {
|
|
397
|
+
this.url = config.url ?? "redis://localhost:6379";
|
|
398
|
+
this.keyPrefix = config.keyPrefix ?? "";
|
|
399
|
+
this.reconnect = config.reconnect ?? true;
|
|
400
|
+
this.reconnectInterval = config.reconnectInterval ?? 1000;
|
|
401
|
+
this.maxReconnectAttempts = config.maxReconnectAttempts ?? 5;
|
|
402
|
+
}
|
|
403
|
+
async connect() {
|
|
404
|
+
try {
|
|
405
|
+
// Use Bun's native Redis client
|
|
406
|
+
const { RedisClient } = await import("bun");
|
|
407
|
+
// Create separate connections for pub and sub
|
|
408
|
+
// (Subscriber connections enter a special mode and can't run other commands)
|
|
409
|
+
this.publisher = new RedisClient(this.url);
|
|
410
|
+
this.subscriber = new RedisClient(this.url);
|
|
411
|
+
this._isConnected = true;
|
|
412
|
+
this.reconnectAttempts = 0;
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
throw new Error(`Failed to connect to Redis: ${error instanceof Error ? error.message : String(error)}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async disconnect() {
|
|
419
|
+
const pub = this.publisher;
|
|
420
|
+
const sub = this.subscriber;
|
|
421
|
+
if (pub?.close)
|
|
422
|
+
await pub.close();
|
|
423
|
+
if (sub?.close)
|
|
424
|
+
await sub.close();
|
|
425
|
+
this._isConnected = false;
|
|
426
|
+
this.publisher = null;
|
|
427
|
+
this.subscriber = null;
|
|
428
|
+
}
|
|
429
|
+
get isConnected() {
|
|
430
|
+
return this._isConnected;
|
|
431
|
+
}
|
|
432
|
+
async publish(channel, data) {
|
|
433
|
+
if (!this._isConnected) {
|
|
434
|
+
throw new Error("Redis Pub/Sub not connected");
|
|
435
|
+
}
|
|
436
|
+
const fullChannel = this.keyPrefix + channel;
|
|
437
|
+
const message = JSON.stringify({
|
|
438
|
+
channel,
|
|
439
|
+
data,
|
|
440
|
+
timestamp: Date.now(),
|
|
441
|
+
});
|
|
442
|
+
const client = this.publisher;
|
|
443
|
+
return client.publish(fullChannel, message);
|
|
444
|
+
}
|
|
445
|
+
async subscribe(channel, callback) {
|
|
446
|
+
if (!this._isConnected) {
|
|
447
|
+
throw new Error("Redis Pub/Sub not connected");
|
|
448
|
+
}
|
|
449
|
+
const fullChannel = this.keyPrefix + channel;
|
|
450
|
+
// Store callback
|
|
451
|
+
if (!this.channelCallbacks.has(channel)) {
|
|
452
|
+
this.channelCallbacks.set(channel, new Set());
|
|
453
|
+
}
|
|
454
|
+
this.channelCallbacks.get(channel)?.add(callback);
|
|
455
|
+
// Subscribe to Redis channel
|
|
456
|
+
const client = this.subscriber;
|
|
457
|
+
// Create wrapper callback for Redis
|
|
458
|
+
const wrappedCallback = (message, redisChannel) => {
|
|
459
|
+
try {
|
|
460
|
+
const parsed = JSON.parse(message);
|
|
461
|
+
callback({
|
|
462
|
+
channel: parsed.channel ?? channel,
|
|
463
|
+
data: parsed.data,
|
|
464
|
+
timestamp: parsed.timestamp ?? Date.now(),
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
// Handle raw string messages
|
|
469
|
+
callback({
|
|
470
|
+
channel,
|
|
471
|
+
data: message,
|
|
472
|
+
timestamp: Date.now(),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
await client.subscribe(fullChannel, wrappedCallback);
|
|
477
|
+
// Return unsubscribe function
|
|
478
|
+
return async () => {
|
|
479
|
+
this.channelCallbacks.get(channel)?.delete(callback);
|
|
480
|
+
// If no more callbacks for this channel, unsubscribe from Redis
|
|
481
|
+
if (this.channelCallbacks.get(channel)?.size === 0) {
|
|
482
|
+
this.channelCallbacks.delete(channel);
|
|
483
|
+
const unsubClient = this.subscriber;
|
|
484
|
+
await unsubClient.unsubscribe(fullChannel);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
async psubscribe(pattern, callback) {
|
|
489
|
+
if (!this._isConnected) {
|
|
490
|
+
throw new Error("Redis Pub/Sub not connected");
|
|
491
|
+
}
|
|
492
|
+
const fullPattern = this.keyPrefix + pattern;
|
|
493
|
+
// Store callback
|
|
494
|
+
if (!this.patternCallbacks.has(pattern)) {
|
|
495
|
+
this.patternCallbacks.set(pattern, new Set());
|
|
496
|
+
}
|
|
497
|
+
this.patternCallbacks.get(pattern)?.add(callback);
|
|
498
|
+
// Subscribe to Redis pattern
|
|
499
|
+
const client = this.subscriber;
|
|
500
|
+
// Create wrapper callback for Redis
|
|
501
|
+
const wrappedCallback = (message, redisChannel, redisPattern) => {
|
|
502
|
+
try {
|
|
503
|
+
const parsed = JSON.parse(message);
|
|
504
|
+
callback({
|
|
505
|
+
channel: parsed.channel ?? redisChannel.replace(this.keyPrefix, ""),
|
|
506
|
+
pattern: pattern,
|
|
507
|
+
data: parsed.data,
|
|
508
|
+
timestamp: parsed.timestamp ?? Date.now(),
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
callback({
|
|
513
|
+
channel: redisChannel.replace(this.keyPrefix, ""),
|
|
514
|
+
pattern: pattern,
|
|
515
|
+
data: message,
|
|
516
|
+
timestamp: Date.now(),
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
await client.psubscribe(fullPattern, wrappedCallback);
|
|
521
|
+
// Return unsubscribe function
|
|
522
|
+
return async () => {
|
|
523
|
+
this.patternCallbacks.get(pattern)?.delete(callback);
|
|
524
|
+
// If no more callbacks for this pattern, unsubscribe from Redis
|
|
525
|
+
if (this.patternCallbacks.get(pattern)?.size === 0) {
|
|
526
|
+
this.patternCallbacks.delete(pattern);
|
|
527
|
+
const unsubClient = this.subscriber;
|
|
528
|
+
await unsubClient.punsubscribe(fullPattern);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
async unsubscribe(channel) {
|
|
533
|
+
if (!this._isConnected)
|
|
534
|
+
return;
|
|
535
|
+
const fullChannel = this.keyPrefix + channel;
|
|
536
|
+
this.channelCallbacks.delete(channel);
|
|
537
|
+
const client = this.subscriber;
|
|
538
|
+
await client.unsubscribe(fullChannel);
|
|
539
|
+
}
|
|
540
|
+
async punsubscribe(pattern) {
|
|
541
|
+
if (!this._isConnected)
|
|
542
|
+
return;
|
|
543
|
+
const fullPattern = this.keyPrefix + pattern;
|
|
544
|
+
this.patternCallbacks.delete(pattern);
|
|
545
|
+
const client = this.subscriber;
|
|
546
|
+
await client.punsubscribe(fullPattern);
|
|
547
|
+
}
|
|
548
|
+
getChannelSubscribers(channel) {
|
|
549
|
+
return this.channelCallbacks.get(channel)?.size ?? 0;
|
|
550
|
+
}
|
|
551
|
+
getPatternSubscribers(pattern) {
|
|
552
|
+
return this.patternCallbacks.get(pattern)?.size ?? 0;
|
|
553
|
+
}
|
|
554
|
+
getTotalSubscribers() {
|
|
555
|
+
let total = 0;
|
|
556
|
+
for (const subscribers of this.channelCallbacks.values()) {
|
|
557
|
+
total += subscribers.size;
|
|
558
|
+
}
|
|
559
|
+
for (const subscribers of this.patternCallbacks.values()) {
|
|
560
|
+
total += subscribers.size;
|
|
561
|
+
}
|
|
562
|
+
return total;
|
|
563
|
+
}
|
|
564
|
+
async clear() {
|
|
565
|
+
// Unsubscribe from all channels
|
|
566
|
+
for (const channel of this.channelCallbacks.keys()) {
|
|
567
|
+
await this.unsubscribe(channel);
|
|
568
|
+
}
|
|
569
|
+
// Unsubscribe from all patterns
|
|
570
|
+
for (const pattern of this.patternCallbacks.keys()) {
|
|
571
|
+
await this.punsubscribe(pattern);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
destroy() {
|
|
575
|
+
this.disconnect().catch(() => { });
|
|
576
|
+
this.channelCallbacks.clear();
|
|
577
|
+
this.patternCallbacks.clear();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
// ============= Pub/Sub Class (Unified Interface) =============
|
|
581
|
+
export class PubSub {
|
|
582
|
+
driver;
|
|
583
|
+
driverType;
|
|
584
|
+
_isConnected = false;
|
|
585
|
+
constructor(config = {}) {
|
|
586
|
+
this.driverType = config.driver ?? "memory";
|
|
587
|
+
if (this.driverType === "redis" && config.url) {
|
|
588
|
+
this.driver = new RedisPubSub(config);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
this.driver = new InMemoryPubSub();
|
|
592
|
+
// Memory driver is always "connected"
|
|
593
|
+
this._isConnected = true;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Connect to the pub/sub backend (Redis only)
|
|
598
|
+
*/
|
|
599
|
+
async connect() {
|
|
600
|
+
if (this.driver instanceof RedisPubSub) {
|
|
601
|
+
await this.driver.connect();
|
|
602
|
+
}
|
|
603
|
+
this._isConnected = true;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Disconnect from the pub/sub backend
|
|
607
|
+
*/
|
|
608
|
+
async disconnect() {
|
|
609
|
+
if (this.driver instanceof RedisPubSub) {
|
|
610
|
+
await this.driver.disconnect();
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
this.driver.destroy();
|
|
614
|
+
}
|
|
615
|
+
this._isConnected = false;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Check if connected
|
|
619
|
+
*/
|
|
620
|
+
get isConnected() {
|
|
621
|
+
return this._isConnected;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Get the driver type
|
|
625
|
+
*/
|
|
626
|
+
getDriverType() {
|
|
627
|
+
return this.driverType;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Publish a message to a channel
|
|
631
|
+
* Returns the number of subscribers that received the message
|
|
632
|
+
*/
|
|
633
|
+
async publish(channel, data) {
|
|
634
|
+
return this.driver.publish(channel, data);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Subscribe to a channel
|
|
638
|
+
* Returns an unsubscribe function
|
|
639
|
+
*/
|
|
640
|
+
async subscribe(channel, callback) {
|
|
641
|
+
return this.driver.subscribe(channel, callback);
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Subscribe to channels matching a pattern
|
|
645
|
+
* Supports * (any characters) and ? (single character)
|
|
646
|
+
* Returns an unsubscribe function
|
|
647
|
+
*/
|
|
648
|
+
async psubscribe(pattern, callback) {
|
|
649
|
+
return this.driver.psubscribe(pattern, callback);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Unsubscribe all callbacks from a channel
|
|
653
|
+
*/
|
|
654
|
+
async unsubscribe(channel) {
|
|
655
|
+
return this.driver.unsubscribe(channel);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Unsubscribe all callbacks from a pattern
|
|
659
|
+
*/
|
|
660
|
+
async punsubscribe(pattern) {
|
|
661
|
+
return this.driver.punsubscribe(pattern);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Get subscriber count for a specific channel
|
|
665
|
+
*/
|
|
666
|
+
getChannelSubscribers(channel) {
|
|
667
|
+
return this.driver.getChannelSubscribers(channel);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Get subscriber count for a specific pattern
|
|
671
|
+
*/
|
|
672
|
+
getPatternSubscribers(pattern) {
|
|
673
|
+
return this.driver.getPatternSubscribers(pattern);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Get total subscriber count across all channels and patterns
|
|
677
|
+
*/
|
|
678
|
+
getTotalSubscribers() {
|
|
679
|
+
return this.driver.getTotalSubscribers();
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Clear all subscriptions
|
|
683
|
+
*/
|
|
684
|
+
async clear() {
|
|
685
|
+
return this.driver.clear();
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Destroy the pub/sub instance and release resources
|
|
689
|
+
*/
|
|
690
|
+
destroy() {
|
|
691
|
+
this.driver.destroy();
|
|
692
|
+
this._isConnected = false;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
// ============= Factory Functions =============
|
|
696
|
+
/**
|
|
697
|
+
* Create a WebSocket server
|
|
698
|
+
*/
|
|
699
|
+
export function createWebSocketServer(options) {
|
|
700
|
+
return new WebSocketServer(options);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Create a WebSocket client
|
|
704
|
+
*/
|
|
705
|
+
export function createWebSocketClient(options) {
|
|
706
|
+
return new WebSocketClient(options);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Create a pub/sub instance
|
|
710
|
+
* @param config Configuration options including driver type and Redis URL
|
|
711
|
+
*/
|
|
712
|
+
export function createPubSub(config) {
|
|
713
|
+
return new PubSub(config);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Create a Redis pub/sub instance (convenience function)
|
|
717
|
+
*/
|
|
718
|
+
export function createRedisPubSub(url, options) {
|
|
719
|
+
return new PubSub({ driver: "redis", url, ...options });
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Create an in-memory pub/sub instance (convenience function)
|
|
723
|
+
*/
|
|
724
|
+
export function createMemoryPubSub() {
|
|
725
|
+
return new PubSub({ driver: "memory" });
|
|
726
|
+
}
|
|
727
|
+
// ============= Upgrade Helper =============
|
|
728
|
+
/**
|
|
729
|
+
* Check if request is a WebSocket upgrade request
|
|
730
|
+
*/
|
|
731
|
+
export function isWebSocketRequest(request) {
|
|
732
|
+
return request.headers.get("upgrade")?.toLowerCase() === "websocket";
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Generate WebSocket connection ID
|
|
736
|
+
*/
|
|
737
|
+
export function generateConnectionId() {
|
|
738
|
+
return crypto.randomUUID();
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Create WebSocket data for new connection
|
|
742
|
+
*/
|
|
743
|
+
export function createWebSocketData(data) {
|
|
744
|
+
return {
|
|
745
|
+
id: generateConnectionId(),
|
|
746
|
+
...data,
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
//# sourceMappingURL=index.js.map
|