create-jen-app 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/colors.js +0 -17
- package/dist/create.js +5 -17
- package/dist/generator.js +14 -31
- package/dist/index.js +6 -1
- package/package.json +1 -1
- package/templates/ssr-isr/README.md +77 -0
- package/templates/ssr-isr/build.js +118 -0
- package/templates/ssr-isr/jen.config.ts +109 -0
- package/templates/ssr-isr/jenjs.d.ts +22 -0
- package/templates/ssr-isr/lib/api/(hello).js +9 -0
- package/templates/ssr-isr/lib/auth/cookie-utils.js +79 -0
- package/templates/ssr-isr/lib/auth/index.js +2 -0
- package/templates/ssr-isr/lib/auth/jwt.js +57 -0
- package/templates/ssr-isr/lib/auth/session.js +92 -0
- package/templates/ssr-isr/lib/build/asset-hashing.d.ts +10 -0
- package/templates/ssr-isr/lib/build/asset-hashing.js +25 -0
- package/templates/ssr-isr/lib/build/asset-manifest.d.ts +11 -0
- package/templates/ssr-isr/lib/build/asset-manifest.js +21 -0
- package/templates/{static → ssr-isr}/lib/build/build.d.ts +1 -1
- package/templates/ssr-isr/lib/build/build.js +141 -0
- package/templates/{static → ssr-isr}/lib/build/island-hydration.d.ts +8 -5
- package/templates/ssr-isr/lib/build/island-hydration.js +44 -0
- package/templates/ssr-isr/lib/build/minifier.d.ts +20 -0
- package/templates/ssr-isr/lib/build/minifier.js +46 -0
- package/templates/ssr-isr/lib/build/page-renderer.d.ts +17 -0
- package/templates/ssr-isr/lib/build/page-renderer.js +28 -0
- package/templates/ssr-isr/lib/build/production-build.d.ts +10 -0
- package/templates/ssr-isr/lib/build/production-build.js +13 -0
- package/templates/ssr-isr/lib/build/ssg-pipeline.d.ts +15 -0
- package/templates/ssr-isr/lib/build/ssg-pipeline.js +113 -0
- package/templates/ssr-isr/lib/build-tools/build-site.js +36 -0
- package/templates/ssr-isr/lib/cache/index.js +10 -0
- package/templates/ssr-isr/lib/cache/memory.js +40 -0
- package/templates/ssr-isr/lib/cache/redis.js +61 -0
- package/templates/ssr-isr/lib/cli/banner.js +28 -0
- package/templates/ssr-isr/lib/cli/templates/ssg/jen.config.js +32 -0
- package/templates/ssr-isr/lib/cli/templates/ssg/site/index.js +9 -0
- package/templates/ssr-isr/lib/cli/templates/ssr/jen.config.js +32 -0
- package/templates/ssr-isr/lib/cli/templates/ssr/site/index.js +9 -0
- package/templates/ssr-isr/lib/compilers/esbuild-plugins.js +111 -0
- package/templates/ssr-isr/lib/compilers/svelte.js +44 -0
- package/templates/ssr-isr/lib/compilers/vue.js +90 -0
- package/templates/ssr-isr/lib/core/http.js +71 -0
- package/templates/ssr-isr/lib/core/middleware-hooks.js +97 -0
- package/templates/ssr-isr/lib/core/paths.js +39 -0
- package/templates/ssr-isr/lib/core/routes/match.js +47 -0
- package/templates/ssr-isr/lib/core/routes/scan.js +190 -0
- package/templates/ssr-isr/lib/core/types.js +1 -0
- package/templates/ssr-isr/lib/css/compiler.js +74 -0
- package/templates/ssr-isr/lib/db/connector.js +42 -0
- package/templates/ssr-isr/lib/db/drivers/jdb.js +44 -0
- package/templates/ssr-isr/lib/db/drivers/sql.js +182 -0
- package/templates/ssr-isr/lib/db/index.js +48 -0
- package/templates/ssr-isr/lib/db/types.js +1 -0
- package/templates/ssr-isr/lib/graphql/index.js +52 -0
- package/templates/ssr-isr/lib/graphql/resolvers.js +25 -0
- package/templates/ssr-isr/lib/graphql/schema.js +35 -0
- package/templates/ssr-isr/lib/i18n/en.json +4 -0
- package/templates/ssr-isr/lib/i18n/es.json +4 -0
- package/templates/ssr-isr/lib/i18n/index.js +15 -0
- package/templates/ssr-isr/lib/import/jen-import.js +161 -0
- package/templates/ssr-isr/lib/index.js +116 -0
- package/templates/ssr-isr/lib/jdb/engine.js +275 -0
- package/templates/ssr-isr/lib/jdb/index.js +34 -0
- package/templates/ssr-isr/lib/jdb/types.js +1 -0
- package/templates/ssr-isr/lib/jdb/utils.js +176 -0
- package/templates/{static → ssr-isr}/lib/middleware/builtins/body-parser.js +0 -17
- package/templates/ssr-isr/lib/middleware/builtins/cors.js +54 -0
- package/templates/{static → ssr-isr}/lib/middleware/builtins/logger.js +0 -17
- package/templates/{static → ssr-isr}/lib/middleware/builtins/rate-limit.js +0 -17
- package/templates/{static → ssr-isr}/lib/middleware/builtins/request-id.js +0 -17
- package/templates/{static → ssr-isr}/lib/middleware/builtins/security-headers.js +0 -17
- package/templates/ssr-isr/lib/middleware/context.js +124 -0
- package/templates/{static → ssr-isr}/lib/middleware/decorators.js +0 -17
- package/templates/{static → ssr-isr}/lib/middleware/errors/handler.js +0 -17
- package/templates/ssr-isr/lib/middleware/errors/http-error.js +10 -0
- package/templates/ssr-isr/lib/middleware/kernel.js +85 -0
- package/templates/ssr-isr/lib/middleware/pipeline.js +148 -0
- package/templates/ssr-isr/lib/middleware/registry.js +85 -0
- package/templates/ssr-isr/lib/middleware/response.js +107 -0
- package/templates/ssr-isr/lib/middleware/types.d.ts +1 -0
- package/templates/ssr-isr/lib/middleware/types.js +1 -0
- package/templates/ssr-isr/lib/middleware/utils/matcher.js +13 -0
- package/templates/{static → ssr-isr}/lib/native/bundle.js +0 -17
- package/templates/{static → ssr-isr}/lib/native/dev-server.js +0 -17
- package/templates/{static → ssr-isr}/lib/native/index.js +0 -17
- package/templates/{static → ssr-isr}/lib/native/optimizer.js +0 -17
- package/templates/ssr-isr/lib/native/style-compiler.js +19 -0
- package/templates/ssr-isr/lib/plugin/loader.js +36 -0
- package/templates/ssr-isr/lib/runtime/client-runtime.js +25 -0
- package/templates/ssr-isr/lib/runtime/hmr.js +59 -0
- package/templates/ssr-isr/lib/runtime/hydrate.js +55 -0
- package/templates/ssr-isr/lib/runtime/island-hydration-client.js +146 -0
- package/templates/ssr-isr/lib/runtime/islands.js +110 -0
- package/templates/ssr-isr/lib/runtime/render.js +244 -0
- package/templates/ssr-isr/lib/server/api-routes.js +237 -0
- package/templates/ssr-isr/lib/server/api.js +108 -0
- package/templates/ssr-isr/lib/server/app.js +438 -0
- package/templates/ssr-isr/lib/server/runtimeServe.js +169 -0
- package/templates/ssr-isr/lib/server/ssr.js +202 -0
- package/templates/ssr-isr/lib/shared/log.js +64 -0
- package/templates/ssr-isr/package.json +23 -0
- package/templates/ssr-isr/server.js +128 -0
- package/templates/ssr-isr/site/pages/(index).tsx +11 -0
- package/templates/ssr-isr/site/styles/global.scss +37 -0
- package/templates/ssr-isr/tsconfig.json +39 -0
- package/templates/static/build.js +30 -18
- package/templates/static/jen.config.ts +0 -18
- package/templates/static/jenjs.d.ts +0 -18
- package/templates/static/lib/api/(hello).js +0 -17
- package/templates/static/lib/api/examples/files/[...slug].js +22 -0
- package/templates/static/lib/api/examples/hello.js +11 -0
- package/templates/static/lib/api/examples/posts/[id].js +37 -0
- package/templates/static/lib/api/examples/posts.js +37 -0
- package/templates/static/lib/api/examples/search.js +23 -0
- package/templates/static/lib/api/index.js +41 -0
- package/templates/static/lib/api/loader.js +234 -0
- package/templates/static/lib/api/router.js +259 -0
- package/templates/static/lib/assets/types.js +1 -0
- package/templates/static/lib/auth/cookie-utils.js +3 -16
- package/templates/static/lib/auth/index.js +0 -17
- package/templates/static/lib/auth/jwt.js +0 -17
- package/templates/static/lib/auth/session.js +0 -17
- package/templates/static/lib/build/asset-hashing.js +44 -36
- package/templates/static/lib/build/asset-manifest.js +16 -33
- package/templates/static/lib/build/build.js +270 -125
- package/templates/static/lib/build/bundle-analyzer-ui.js +417 -0
- package/templates/static/lib/build/bundle-analyzer.js +945 -0
- package/templates/static/lib/build/code-splitter.js +194 -0
- package/templates/static/lib/build/feature-analyzer.js +190 -0
- package/templates/static/lib/build/feature-gate.js +257 -0
- package/templates/static/lib/build/island-hydration.js +17 -35
- package/templates/static/lib/build/lazy-loader.js +322 -0
- package/templates/static/lib/build/minifier.js +40 -59
- package/templates/static/lib/build/page-renderer.js +23 -40
- package/templates/static/lib/build/production-build.js +9 -26
- package/templates/static/lib/build/rust-hashing.js +71 -0
- package/templates/static/lib/build/script-optimizer.js +285 -0
- package/templates/static/lib/build/ssg-pipeline.js +100 -106
- package/templates/static/lib/build/vercel-output.js +298 -0
- package/templates/static/lib/build-tools/build-site.js +0 -17
- package/templates/static/lib/cache/index.js +0 -17
- package/templates/static/lib/cache/memory.js +0 -17
- package/templates/static/lib/cache/redis.js +0 -17
- package/templates/static/lib/cli/banner.js +0 -17
- package/templates/static/lib/cli/templates/ssg/jen.config.js +0 -17
- package/templates/static/lib/cli/templates/ssr/jen.config.js +0 -17
- package/templates/static/lib/client/Image.js +42 -0
- package/templates/static/lib/client/Link.js +190 -0
- package/templates/static/lib/client/PWA.js +46 -0
- package/templates/static/lib/client/Seo.js +97 -0
- package/templates/static/lib/client/index.js +9 -0
- package/templates/static/lib/client/useNavigation.js +25 -0
- package/templates/static/lib/client/useRouter.js +64 -0
- package/templates/static/lib/client-routing/Link.js +17 -0
- package/templates/static/lib/client-routing/index.js +19 -0
- package/templates/static/lib/client-routing/router.js +151 -0
- package/templates/static/lib/client-routing/signal.js +147 -0
- package/templates/static/lib/compilers/esbuild-plugins.js +0 -17
- package/templates/static/lib/compilers/svelte.js +0 -17
- package/templates/static/lib/compilers/vue.js +0 -17
- package/templates/static/lib/core/config.js +0 -17
- package/templates/static/lib/core/feature-guard.js +136 -0
- package/templates/static/lib/core/features.js +99 -0
- package/templates/static/lib/core/http.js +0 -17
- package/templates/static/lib/core/layouts/index.js +10 -0
- package/templates/static/lib/core/layouts/render.js +158 -0
- package/templates/static/lib/core/layouts/scan.js +112 -0
- package/templates/static/lib/core/layouts/types.js +1 -0
- package/templates/static/lib/core/lifecycle.js +129 -0
- package/templates/static/lib/core/loader-schema.js +81 -0
- package/templates/static/lib/core/middleware-hooks.js +0 -17
- package/templates/static/lib/core/paths.js +0 -17
- package/templates/static/lib/core/routes/advanced.js +114 -0
- package/templates/static/lib/core/routes/handlers.js +181 -0
- package/templates/static/lib/core/routes/match.js +89 -17
- package/templates/static/lib/core/routes/orchestrator.js +171 -0
- package/templates/static/lib/core/routes/rendering-config.js +131 -0
- package/templates/static/lib/core/routes/scan.js +0 -17
- package/templates/static/lib/core/types.js +0 -17
- package/templates/static/lib/css/compiler.js +1 -18
- package/templates/static/lib/data-fetching/cache.js +223 -0
- package/templates/static/lib/data-fetching/client.js +202 -0
- package/templates/static/lib/data-fetching/feature-guard.js +29 -0
- package/templates/static/lib/data-fetching/graphql.js +265 -0
- package/templates/static/lib/data-fetching/index.js +57 -0
- package/templates/static/lib/data-fetching/rest.js +256 -0
- package/templates/static/lib/data-fetching/server.js +182 -0
- package/templates/static/lib/data-fetching/types.js +5 -0
- package/templates/static/lib/db/connector.js +0 -17
- package/templates/static/lib/db/drivers/jdb.js +0 -17
- package/templates/static/lib/db/drivers/sql.js +0 -17
- package/templates/static/lib/db/index.js +0 -17
- package/templates/static/lib/db/types.js +0 -17
- package/templates/static/lib/devtools/component-tree.js +106 -0
- package/templates/static/lib/devtools/devtools.js +638 -0
- package/templates/static/lib/devtools/event-bus.js +29 -0
- package/templates/static/lib/devtools/event-logger.js +67 -0
- package/templates/static/lib/devtools/index.js +9 -0
- package/templates/static/lib/devtools/integration.js +149 -0
- package/templates/static/lib/devtools/performance.js +84 -0
- package/templates/static/lib/devtools/persistence.js +57 -0
- package/templates/static/lib/devtools/plugins.js +97 -0
- package/templates/static/lib/devtools/search.js +89 -0
- package/templates/static/lib/devtools/ui.js +769 -0
- package/templates/static/lib/features/api/handler.js +10 -0
- package/templates/static/lib/features/api/index.js +5 -0
- package/templates/static/lib/features/api/types.js +4 -0
- package/templates/static/lib/features/middleware/compiled.js +7 -0
- package/templates/static/lib/features/middleware/index.js +5 -0
- package/templates/static/lib/features/middleware/types.js +4 -0
- package/templates/static/lib/fonts/index.js +46 -0
- package/templates/static/lib/fonts/inject.js +125 -0
- package/templates/static/lib/fonts/loader.js +196 -0
- package/templates/static/lib/fonts/types.js +1 -0
- package/templates/static/lib/graphql/index.js +1 -18
- package/templates/static/lib/graphql/resolvers.js +20 -13
- package/templates/static/lib/graphql/schema.js +0 -17
- package/templates/static/lib/i18n/index.js +7 -19
- package/templates/static/lib/import/jen-import.js +1 -18
- package/templates/static/lib/index.js +79 -125
- package/templates/static/lib/jdb/engine.js +0 -17
- package/templates/static/lib/jdb/index.js +1 -18
- package/templates/static/lib/jdb/types.js +0 -17
- package/templates/static/lib/jdb/utils.js +0 -17
- package/templates/static/lib/middleware/builtins/cors.js +3 -16
- package/templates/static/lib/middleware/context.js +0 -17
- package/templates/static/lib/middleware/kernel.js +117 -25
- package/templates/static/lib/middleware/pipeline.js +0 -17
- package/templates/static/lib/middleware/registry.js +0 -17
- package/templates/static/lib/middleware/response.js +0 -17
- package/templates/static/lib/plugin/examples/analytics-plugin.js +183 -0
- package/templates/static/lib/plugin/examples/cdn-upload-plugin.js +94 -0
- package/templates/static/lib/plugin/loader.js +0 -17
- package/templates/static/lib/plugin/plugin-manager.js +177 -0
- package/templates/static/lib/plugin/types.js +28 -0
- package/templates/static/lib/runtime/client-runtime.js +0 -17
- package/templates/static/lib/runtime/hmr.js +0 -17
- package/templates/static/lib/runtime/hydrate.js +0 -17
- package/templates/static/lib/runtime/island-hydration-client.js +0 -17
- package/templates/static/lib/runtime/islands.js +0 -17
- package/templates/static/lib/runtime/render.js +208 -50
- package/templates/static/lib/security/security-config.js +60 -0
- package/templates/static/lib/security/security-middleware.js +229 -0
- package/templates/static/lib/server/api-routes.js +153 -43
- package/templates/static/lib/server/api.js +0 -17
- package/templates/static/lib/server/app.js +539 -223
- package/templates/static/lib/server/isr.js +365 -0
- package/templates/static/lib/server/runtimeServe.js +31 -24
- package/templates/static/lib/server/ssr.js +98 -22
- package/templates/static/lib/server-actions/handler.js +180 -0
- package/templates/static/lib/server-actions/index.js +19 -0
- package/templates/static/lib/server-actions/middleware.js +146 -0
- package/templates/static/lib/server-actions/scan.js +152 -0
- package/templates/static/lib/server-actions/types.js +1 -0
- package/templates/static/lib/server-actions/validators.js +156 -0
- package/templates/static/lib/shared/log.js +19 -20
- package/templates/static/lib/telemetry/api/rate-limiter.js +32 -0
- package/templates/static/lib/telemetry/api/validator.js +67 -0
- package/templates/static/lib/telemetry/client.js +121 -0
- package/templates/static/lib/telemetry/tests/rate-limiter.test.js +46 -0
- package/templates/static/lib/telemetry/tests/validator.test.js +62 -0
- package/templates/static/lib/vendor/glob/glob.js +4766 -0
- package/templates/static/lib/vendor/preact/LICENSE +21 -0
- package/templates/static/lib/vendor/preact/preact.module.js +797 -0
- package/templates/static/lib/vendor/sass/sass.node.mjs +212 -0
- package/templates/static/package.json +4 -0
- package/templates/static/server.js +22 -22
- package/templates/static/site/(home).tsx +0 -18
- package/templates/static/tsconfig.json +5 -1
- package/templates/static/.esbuild/jen.config.js +0 -19
- package/templates/static/lib/build/asset-hashing.d.ts +0 -10
- package/templates/static/lib/build/asset-manifest.d.ts +0 -11
- package/templates/static/lib/build/minifier.d.ts +0 -20
- package/templates/static/lib/build/page-renderer.d.ts +0 -17
- package/templates/static/lib/build/production-build.d.ts +0 -10
- package/templates/static/lib/build/ssg-pipeline.d.ts +0 -15
- package/templates/static/lib/middleware/errors/http-error.js +0 -27
- package/templates/static/lib/middleware/types.js +0 -18
- package/templates/static/lib/middleware/utils/matcher.js +0 -30
- package/templates/static/lib/native/style-compiler.js +0 -36
- /package/templates/{static → ssr-isr}/lib/api/(hello).d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/auth/cookie-utils.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/auth/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/auth/jwt.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/auth/session.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/build-tools/build-site.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cache/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cache/memory.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cache/redis.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cli/banner.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cli/templates/ssg/jen.config.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cli/templates/ssg/site/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cli/templates/ssr/jen.config.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/cli/templates/ssr/site/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/compilers/esbuild-plugins.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/compilers/svelte.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/compilers/vue.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/config.d.ts +0 -0
- /package/templates/{static/lib/middleware/types.d.ts → ssr-isr/lib/core/config.js} +0 -0
- /package/templates/{static → ssr-isr}/lib/core/http.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/middleware-hooks.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/paths.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/routes/match.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/routes/scan.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/core/types.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/css/compiler.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/db/connector.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/db/drivers/jdb.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/db/drivers/sql.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/db/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/db/types.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/graphql/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/graphql/resolvers.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/graphql/schema.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/i18n/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/import/jen-import.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/jdb/engine.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/jdb/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/jdb/types.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/jdb/utils.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/body-parser.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/cors.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/logger.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/rate-limit.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/request-id.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/builtins/security-headers.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/context.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/decorators.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/errors/handler.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/errors/http-error.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/kernel.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/pipeline.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/registry.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/response.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/middleware/utils/matcher.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/native/bundle.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/native/dev-server.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/native/index.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/native/optimizer.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/native/style-compiler.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/plugin/loader.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/client-runtime.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/hmr.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/hydrate.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/island-hydration-client.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/islands.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/runtime/render.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/server/api-routes.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/server/api.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/server/app.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/server/runtimeServe.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/server/ssr.d.ts +0 -0
- /package/templates/{static → ssr-isr}/lib/shared/log.d.ts +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an absolute path relative to the configured site directory.
|
|
4
|
+
* Used throughout the framework to locate source files, assets, pages, and other site content.
|
|
5
|
+
*
|
|
6
|
+
* The site directory is typically where user-written code (pages, routes, components, etc.) resides.
|
|
7
|
+
* This function ensures consistent path resolution across different environments and working directories.
|
|
8
|
+
*
|
|
9
|
+
* @param config Framework configuration object containing the siteDir path.
|
|
10
|
+
* @param p Path segments to join with the site directory. Can be multiple arguments.
|
|
11
|
+
* @returns Absolute file system path.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const config = { siteDir: 'src' };
|
|
15
|
+
* resolveSitePath(config, 'pages', 'index.tsx');
|
|
16
|
+
* // Returns: /absolute/path/to/project/src/pages/index.tsx
|
|
17
|
+
*/
|
|
18
|
+
export function resolveSitePath(config, ...p) {
|
|
19
|
+
return join(process.cwd(), config.siteDir, ...p);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an absolute path relative to the configured distribution/build output directory.
|
|
23
|
+
* Used to locate compiled assets, static files, and build artifacts.
|
|
24
|
+
*
|
|
25
|
+
* The distribution directory contains the output of the build process: compiled HTML,
|
|
26
|
+
* CSS, JavaScript bundles, and other files ready for deployment or serving.
|
|
27
|
+
*
|
|
28
|
+
* @param config Framework configuration object containing the distDir path.
|
|
29
|
+
* @param p Path segments to join with the dist directory. Can be multiple arguments.
|
|
30
|
+
* @returns Absolute file system path.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const config = { distDir: 'dist' };
|
|
34
|
+
* resolveDistPath(config, 'styles.css');
|
|
35
|
+
* // Returns: /absolute/path/to/project/dist/styles.css
|
|
36
|
+
*/
|
|
37
|
+
export function resolveDistPath(config, ...p) {
|
|
38
|
+
return join(process.cwd(), config.distDir, ...p);
|
|
39
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches a URL pathname against a list of routes and returns the matching route with extracted parameters.
|
|
3
|
+
*
|
|
4
|
+
* Algorithm:
|
|
5
|
+
* 1. Iterate through routes in specificity order (most specific first)
|
|
6
|
+
* 2. For each route, compile its regex pattern and test against pathname
|
|
7
|
+
* 3. On first match, extract captured groups as parameters
|
|
8
|
+
* 4. URL-decode parameter values to handle special characters
|
|
9
|
+
* 5. Return matched route and parameters
|
|
10
|
+
*
|
|
11
|
+
* Route specificity:
|
|
12
|
+
* - Static routes (no parameters) are tried before dynamic routes
|
|
13
|
+
* - Exact matches are preferred over catch-alls
|
|
14
|
+
* - This order is determined by scanRoutes() and must not be changed
|
|
15
|
+
*
|
|
16
|
+
* @param routes Array of RouteEntry objects from scanRoutes(), must be pre-sorted by specificity
|
|
17
|
+
* @param pathname URL path to match, e.g., "/posts/42" or "/docs/api/reference"
|
|
18
|
+
*
|
|
19
|
+
* @returns MatchResult object with matched route and parameters, or null if no route matches
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const routes = scanRoutes(config);
|
|
23
|
+
* const match = matchRoute(routes, "/posts/42");
|
|
24
|
+
* if (match) {
|
|
25
|
+
* console.log(match.route.urlPath); // "/posts/:id"
|
|
26
|
+
* console.log(match.params.id); // "42"
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export function matchRoute(routes, pathname) {
|
|
30
|
+
for (const r of routes) {
|
|
31
|
+
const re = new RegExp(r.pattern);
|
|
32
|
+
const m = pathname.match(re);
|
|
33
|
+
if (!m) continue;
|
|
34
|
+
/**
|
|
35
|
+
* Extract captured groups from the regex match.
|
|
36
|
+
* Captured group 0 is the entire match; groups 1+ are the parameters.
|
|
37
|
+
* Each parameter name from r.paramNames corresponds to its regex group by index.
|
|
38
|
+
* URL-decode parameter values since they came from a URL path.
|
|
39
|
+
*/
|
|
40
|
+
const params = {};
|
|
41
|
+
for (let i = 0; i < r.paramNames.length; i++) {
|
|
42
|
+
params[r.paramNames[i]] = decodeURIComponent(m[i + 1] ?? "");
|
|
43
|
+
}
|
|
44
|
+
return { route: r, params };
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Recursively walks a directory and returns all file paths.
|
|
5
|
+
* Used to discover all potential route files in the siteDir.
|
|
6
|
+
*
|
|
7
|
+
* @param dir Directory path to walk
|
|
8
|
+
* @returns Flat array of all file paths found, relative or absolute as provided
|
|
9
|
+
*/
|
|
10
|
+
function walk(dir) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const name of readdirSync(dir)) {
|
|
13
|
+
const p = join(dir, name);
|
|
14
|
+
const st = statSync(p);
|
|
15
|
+
if (st.isDirectory()) out.push(...walk(p));
|
|
16
|
+
else out.push(p);
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes filesystem path separators to forward slashes.
|
|
22
|
+
* Ensures consistent path format across Windows and Unix systems.
|
|
23
|
+
*
|
|
24
|
+
* @param p Path with possibly mixed separators
|
|
25
|
+
* @returns Path with forward slashes only
|
|
26
|
+
*/
|
|
27
|
+
function normalizeSlashes(p) {
|
|
28
|
+
return p.split(sep).join("/");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Escapes special regex characters in a string.
|
|
32
|
+
* Prevents literal characters from being interpreted as regex syntax.
|
|
33
|
+
*
|
|
34
|
+
* @param s String to escape
|
|
35
|
+
* @returns Escaped string safe for regex
|
|
36
|
+
*/
|
|
37
|
+
function escapeRegex(s) {
|
|
38
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts a URL path segment to a regex pattern.
|
|
42
|
+
* Handles dynamic parameters (:id) and catch-alls (*rest).
|
|
43
|
+
* Side effect: appends parameter names to provided array.
|
|
44
|
+
*
|
|
45
|
+
* @param seg URL segment like "id", ":id", or "*rest"
|
|
46
|
+
* @param paramNames Array to accumulate discovered parameter names
|
|
47
|
+
* @returns Regex pattern for this segment
|
|
48
|
+
*/
|
|
49
|
+
function segmentToRegex(seg, paramNames) {
|
|
50
|
+
// (id) => ([^/]+)
|
|
51
|
+
// (...rest) => (.*)
|
|
52
|
+
if (seg.startsWith("...")) {
|
|
53
|
+
const name = seg.slice(3);
|
|
54
|
+
paramNames.push(name);
|
|
55
|
+
return "(.*)";
|
|
56
|
+
}
|
|
57
|
+
paramNames.push(seg);
|
|
58
|
+
return "([^/]+)";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Converts a URL path string into a compiled regex pattern and parameter list.
|
|
62
|
+
* Handles static segments, dynamic parameters (:param), and catch-all routes (*rest).
|
|
63
|
+
*
|
|
64
|
+
* @param urlPath URL path like "/posts/:id" or "/docs/*rest"
|
|
65
|
+
* @returns Object with regex source string and ordered parameter names
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* buildRoutePattern("/posts/:id") => {
|
|
69
|
+
* src: "^/posts/([^/]+)/?$",
|
|
70
|
+
* paramNames: ["id"]
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
function buildRoutePattern(urlPath) {
|
|
74
|
+
// Convert /user/:id into regex
|
|
75
|
+
// We store urlPath with placeholders already replaced during scan
|
|
76
|
+
const parts = urlPath.split("/").filter(Boolean);
|
|
77
|
+
const paramNames = [];
|
|
78
|
+
const regexParts = parts.map((p) => {
|
|
79
|
+
if (p.startsWith(":")) {
|
|
80
|
+
paramNames.push(p.slice(1));
|
|
81
|
+
return "([^/]+)";
|
|
82
|
+
}
|
|
83
|
+
if (p.startsWith("*")) {
|
|
84
|
+
paramNames.push(p.slice(1));
|
|
85
|
+
return "(.*)";
|
|
86
|
+
}
|
|
87
|
+
return escapeRegex(p);
|
|
88
|
+
});
|
|
89
|
+
const src = "^/" + regexParts.join("/") + "/?$";
|
|
90
|
+
return { src, paramNames };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Scans the configured siteDir for route files and returns an ordered list.
|
|
94
|
+
* Files are matched against config.routes.routeFilePattern (typically /^\(([^)]+)\)/).
|
|
95
|
+
* Only files with extensions in config.routes.fileExtensions are considered.
|
|
96
|
+
*
|
|
97
|
+
* Naming conventions:
|
|
98
|
+
* - (home).tsx => route "/" (root, or within its directory)
|
|
99
|
+
* - ($paramName).tsx => dynamic route "/:paramName" (requires $ prefix)
|
|
100
|
+
* - (...restName).tsx => catch-all route "/*restName" (requires ... prefix)
|
|
101
|
+
* - (name).tsx => literal route "/name"
|
|
102
|
+
*
|
|
103
|
+
* Routes are sorted by specificity: static routes first, then dynamic/catch-all.
|
|
104
|
+
*
|
|
105
|
+
* @param config Framework configuration with siteDir and route patterns
|
|
106
|
+
* @returns Array of RouteEntry objects, sorted by specificity (most specific first)
|
|
107
|
+
* @throws {Error} If a parameter name is invalid (e.g., starts with number)
|
|
108
|
+
*/
|
|
109
|
+
export function scanRoutes(config) {
|
|
110
|
+
const siteRoot = join(process.cwd(), config.siteDir);
|
|
111
|
+
const files = walk(siteRoot);
|
|
112
|
+
const routes = [];
|
|
113
|
+
for (const abs of files) {
|
|
114
|
+
const rel = normalizeSlashes(relative(siteRoot, abs));
|
|
115
|
+
const extMatch = config.routes.fileExtensions.some((ext) =>
|
|
116
|
+
rel.endsWith(ext),
|
|
117
|
+
);
|
|
118
|
+
if (!extMatch) continue;
|
|
119
|
+
const base = rel.split("/").pop();
|
|
120
|
+
const m = base.match(config.routes.routeFilePattern);
|
|
121
|
+
if (!m) continue;
|
|
122
|
+
const name = m[1]; // inside ( )
|
|
123
|
+
const relDir = rel.split("/").slice(0, -1).join("/");
|
|
124
|
+
// name parsing:
|
|
125
|
+
// home => /
|
|
126
|
+
// about => /about
|
|
127
|
+
// id => /:id
|
|
128
|
+
// ...rest => /*rest
|
|
129
|
+
let routeSeg = name;
|
|
130
|
+
let urlSeg = "";
|
|
131
|
+
if (routeSeg === "home") urlSeg = "";
|
|
132
|
+
else if (routeSeg.startsWith("...")) urlSeg = "*" + routeSeg.slice(3);
|
|
133
|
+
else urlSeg = routeSeg;
|
|
134
|
+
// build url path
|
|
135
|
+
let url = "/" + (relDir ? relDir + "/" : "") + urlSeg;
|
|
136
|
+
url = url.replaceAll("//", "/");
|
|
137
|
+
/**
|
|
138
|
+
* Dynamic route segment detection based on filename within parentheses.
|
|
139
|
+
* Routes are determined by the filename prefix conventions:
|
|
140
|
+
* - (home).tsx => / (root) or /{dir}/ (in subdirectory)
|
|
141
|
+
* - ($paramName).tsx => /:paramName (dynamic param, requires $ prefix)
|
|
142
|
+
* - (...restName).tsx => /*restName (catch-all, requires ... prefix)
|
|
143
|
+
* - Any other (name).tsx => /name (literal segment)
|
|
144
|
+
*/
|
|
145
|
+
const rawName = name;
|
|
146
|
+
// Handle special prefixes for dynamic routing
|
|
147
|
+
if (rawName.startsWith("$") && !rawName.startsWith("...")) {
|
|
148
|
+
// ($paramName) syntax for dynamic parameters
|
|
149
|
+
const param = rawName.slice(1);
|
|
150
|
+
if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(param)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Invalid parameter name: ${param} in route file ${rel}`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
url = "/" + (relDir ? relDir + "/" : "") + ":" + param;
|
|
156
|
+
url = url.replaceAll("//", "/");
|
|
157
|
+
} else if (rawName.startsWith("...")) {
|
|
158
|
+
// (...restName) syntax for catch-all routes
|
|
159
|
+
const restName = rawName.slice(3);
|
|
160
|
+
if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(restName)) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Invalid rest parameter name: ${restName} in route file ${rel}`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
url = "/" + (relDir ? relDir + "/" : "") + "*" + restName;
|
|
166
|
+
url = url.replaceAll("//", "/");
|
|
167
|
+
} else if (rawName === "home") {
|
|
168
|
+
// (home) is special - becomes root of its directory
|
|
169
|
+
url = relDir === "" ? "/" : "/" + relDir;
|
|
170
|
+
}
|
|
171
|
+
// else: (anything else) treated as literal segment
|
|
172
|
+
const { src, paramNames } = buildRoutePattern(url);
|
|
173
|
+
routes.push({
|
|
174
|
+
id: rel.replaceAll("/", "_"),
|
|
175
|
+
filePath: abs,
|
|
176
|
+
urlPath: url,
|
|
177
|
+
pattern: src,
|
|
178
|
+
paramNames,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// Sort by specificity: exact matches and static routes first, dynamic routes last
|
|
182
|
+
routes.sort((a, b) => {
|
|
183
|
+
// more specific first
|
|
184
|
+
const aDyn = a.urlPath.includes(":") || a.urlPath.includes("*");
|
|
185
|
+
const bDyn = b.urlPath.includes(":") || b.urlPath.includes("*");
|
|
186
|
+
if (aDyn !== bDyn) return aDyn ? 1 : -1;
|
|
187
|
+
return a.urlPath.localeCompare(b.urlPath);
|
|
188
|
+
});
|
|
189
|
+
return routes;
|
|
190
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { compile, compileString } from "sass";
|
|
2
|
+
import { globSync } from "glob";
|
|
3
|
+
import { writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { dirname, join, relative } from "node:path";
|
|
5
|
+
import { log } from "../shared/log.js";
|
|
6
|
+
export class ScssCompiler {
|
|
7
|
+
compile(options) {
|
|
8
|
+
const {
|
|
9
|
+
inputPath,
|
|
10
|
+
outputPath,
|
|
11
|
+
minified = false,
|
|
12
|
+
sourceMap = false,
|
|
13
|
+
} = options;
|
|
14
|
+
try {
|
|
15
|
+
if (!existsSync(inputPath)) {
|
|
16
|
+
return { css: "", error: `File not found: ${inputPath}` };
|
|
17
|
+
}
|
|
18
|
+
const result = compile(inputPath, {
|
|
19
|
+
style: minified ? "compressed" : "expanded",
|
|
20
|
+
sourceMap,
|
|
21
|
+
});
|
|
22
|
+
if (outputPath) {
|
|
23
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
24
|
+
writeFileSync(outputPath, result.css);
|
|
25
|
+
if (result.sourceMap && sourceMap) {
|
|
26
|
+
writeFileSync(outputPath + ".map", JSON.stringify(result.sourceMap));
|
|
27
|
+
}
|
|
28
|
+
log.info(
|
|
29
|
+
`[SCSS] ✓ ${relative(process.cwd(), inputPath)} → ${relative(process.cwd(), outputPath)}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
css: result.css,
|
|
34
|
+
sourceMap: result.sourceMap
|
|
35
|
+
? JSON.stringify(result.sourceMap)
|
|
36
|
+
: undefined,
|
|
37
|
+
};
|
|
38
|
+
} catch (err) {
|
|
39
|
+
const message = err.message || String(err);
|
|
40
|
+
log.error(`[SCSS] ✗ ${inputPath}: ${message}`);
|
|
41
|
+
return { css: "", error: message };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
compileString(scss, options) {
|
|
45
|
+
try {
|
|
46
|
+
const result = compileString(scss, {
|
|
47
|
+
style: options?.minified ? "compressed" : "expanded",
|
|
48
|
+
});
|
|
49
|
+
return { css: result.css };
|
|
50
|
+
} catch (err) {
|
|
51
|
+
const message = err.message || String(err);
|
|
52
|
+
log.error(`[SCSS] ✗ Inline compilation error: ${message}`);
|
|
53
|
+
return { css: "", error: message };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
compileGlob(pattern, outputDir, minified = false) {
|
|
57
|
+
const files = globSync(pattern);
|
|
58
|
+
let count = 0;
|
|
59
|
+
files.forEach((file) => {
|
|
60
|
+
const rel = relative(outputDir, file);
|
|
61
|
+
const output = join(outputDir, rel.replace(/\.scss$/, ".css"));
|
|
62
|
+
const result = this.compile({
|
|
63
|
+
inputPath: file,
|
|
64
|
+
outputPath: output,
|
|
65
|
+
minified,
|
|
66
|
+
});
|
|
67
|
+
if (!result.error) count++;
|
|
68
|
+
});
|
|
69
|
+
return count;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createScssCompiler() {
|
|
73
|
+
return new ScssCompiler();
|
|
74
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { JDBDriver } from "./drivers/jdb";
|
|
2
|
+
import { SQLDriver } from "./drivers/sql";
|
|
3
|
+
/**
|
|
4
|
+
* Factory class for creating database driver instances.
|
|
5
|
+
* The DBConnector uses the factory pattern to instantiate the appropriate driver
|
|
6
|
+
* based on the configured database type. This allows the application to support
|
|
7
|
+
* multiple database backends without tight coupling to any single implementation.
|
|
8
|
+
*
|
|
9
|
+
* Supported database types:
|
|
10
|
+
* - jdb: Embedded JSON database (built-in, no external dependencies)
|
|
11
|
+
* - sqlite: SQLite relational database
|
|
12
|
+
* - postgres: PostgreSQL relational database
|
|
13
|
+
* - mysql: MySQL relational database
|
|
14
|
+
*/
|
|
15
|
+
export class DBConnector {
|
|
16
|
+
/**
|
|
17
|
+
* Creates and returns a database driver instance based on the configuration.
|
|
18
|
+
* The driver implements the IDBDriver interface and provides the same API
|
|
19
|
+
* regardless of the underlying database type.
|
|
20
|
+
*
|
|
21
|
+
* @param config The database configuration including type and connection parameters.
|
|
22
|
+
* @returns An IDBDriver instance for the specified database type.
|
|
23
|
+
* @throws Error if the configured database type is not supported.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const config: DBConfig = { type: 'sqlite', path: './data.db' };
|
|
27
|
+
* const driver = DBConnector.create(config);
|
|
28
|
+
* const records = await driver.query('SELECT * FROM users');
|
|
29
|
+
*/
|
|
30
|
+
static create(config) {
|
|
31
|
+
switch (config.type) {
|
|
32
|
+
case "jdb":
|
|
33
|
+
return new JDBDriver(config);
|
|
34
|
+
case "sqlite":
|
|
35
|
+
case "postgres":
|
|
36
|
+
case "mysql":
|
|
37
|
+
return new SQLDriver(config);
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unsupported DB type: ${config.type}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { JDBEngine } from "../../jdb";
|
|
2
|
+
export class JDBDriver {
|
|
3
|
+
engine;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
const jdbConfig = config.jdb || {
|
|
6
|
+
root: "./data",
|
|
7
|
+
inMemory: false,
|
|
8
|
+
};
|
|
9
|
+
this.engine = new JDBEngine(jdbConfig);
|
|
10
|
+
}
|
|
11
|
+
async connect() {
|
|
12
|
+
await this.engine.connect();
|
|
13
|
+
}
|
|
14
|
+
async disconnect() {
|
|
15
|
+
await this.engine.disconnect();
|
|
16
|
+
}
|
|
17
|
+
async query(q) {
|
|
18
|
+
if (typeof q === "string") {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Raw string queries not supported in JDB directly. Use object syntax.",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if ("sql" in q) {
|
|
24
|
+
throw new Error("SQL queries not supported in JDB driver.");
|
|
25
|
+
}
|
|
26
|
+
const query = q;
|
|
27
|
+
const coll = this.engine.collection(query.find);
|
|
28
|
+
return await coll.find(query.where || {}, query.options);
|
|
29
|
+
}
|
|
30
|
+
async create(collection, data) {
|
|
31
|
+
return await this.engine.collection(collection).insert(data);
|
|
32
|
+
}
|
|
33
|
+
async update(collection, filter, update) {
|
|
34
|
+
return await this.engine
|
|
35
|
+
.collection(collection)
|
|
36
|
+
.update(filter, update, true);
|
|
37
|
+
}
|
|
38
|
+
async delete(collection, filter) {
|
|
39
|
+
return await this.engine.collection(collection).delete(filter, true);
|
|
40
|
+
}
|
|
41
|
+
async count(collection, filter) {
|
|
42
|
+
return await this.engine.collection(collection).count(filter);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Whitelist of allowed identifiers (table/column names) - must be explicitly allowed
|
|
2
|
+
const ALLOWED_IDENTIFIERS = new Set();
|
|
3
|
+
/**
|
|
4
|
+
* Safely quote SQL identifier to prevent injection
|
|
5
|
+
* Only accepts alphanumeric, underscore, dollar sign
|
|
6
|
+
* Note: Hyphen is NOT allowed as it can cause confusion with operators
|
|
7
|
+
*/
|
|
8
|
+
function quoteIdentifier(id) {
|
|
9
|
+
if (!id || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(id)) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Invalid SQL identifier: ${id}. Only alphanumeric, underscore, and dollar sign allowed. Must start with letter, underscore, or dollar.`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return `\`${id}\``; // Use backticks for MySQL, adjust for other databases
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validate and register allowed table/collection names for security
|
|
18
|
+
*/
|
|
19
|
+
export function registerAllowedTable(tableName) {
|
|
20
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(tableName)) {
|
|
21
|
+
ALLOWED_IDENTIFIERS.add(tableName);
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Invalid table name: ${tableName}. Must start with letter, underscore, or dollar. Only alphanumeric, underscore, and dollar allowed.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if table is in allowed list
|
|
30
|
+
*/
|
|
31
|
+
function isTableAllowed(tableName) {
|
|
32
|
+
return ALLOWED_IDENTIFIERS.has(tableName);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate integer value (for LIMIT/OFFSET)
|
|
36
|
+
*/
|
|
37
|
+
function validateInteger(value) {
|
|
38
|
+
const num = parseInt(value, 10);
|
|
39
|
+
if (isNaN(num) || num < 0) {
|
|
40
|
+
throw new Error(`Invalid integer value: ${value}`);
|
|
41
|
+
}
|
|
42
|
+
return num;
|
|
43
|
+
}
|
|
44
|
+
export class SQLDriver {
|
|
45
|
+
executor;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
if (typeof config.connection === "function") {
|
|
48
|
+
this.executor = config.connection;
|
|
49
|
+
} else if (config.connection && config.connection.query) {
|
|
50
|
+
// Support objects like Pool or Client from pg/mysql
|
|
51
|
+
this.executor = (sql, params) => config.connection.query(sql, params);
|
|
52
|
+
} else {
|
|
53
|
+
// Default stub that warns if no connection provided, or we could try to load a default
|
|
54
|
+
this.executor = async () => {
|
|
55
|
+
throw new Error("No SQL connection provided to SQLDriver");
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async connect() {
|
|
60
|
+
// Connection management usually handled by the pool passed in, but we can add logic here if needed
|
|
61
|
+
}
|
|
62
|
+
async disconnect() {
|
|
63
|
+
// No-op or close pool
|
|
64
|
+
}
|
|
65
|
+
async query(q) {
|
|
66
|
+
if (typeof q === "string") {
|
|
67
|
+
return this.executor(q, []);
|
|
68
|
+
}
|
|
69
|
+
if ("sql" in q) {
|
|
70
|
+
return this.executor(q.sql, q.params || []);
|
|
71
|
+
}
|
|
72
|
+
// Convert NoSQL style to SQL (Basic translation)
|
|
73
|
+
const query = q;
|
|
74
|
+
const { sql, params } = this.translateQuery(query);
|
|
75
|
+
return this.executor(sql, params);
|
|
76
|
+
}
|
|
77
|
+
translateQuery(q) {
|
|
78
|
+
// Security: Validate table name
|
|
79
|
+
if (!isTableAllowed(q.find)) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Table '${q.find}' not registered. Call registerAllowedTable() first.`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
let sql = `SELECT * FROM ${quoteIdentifier(q.find)}`;
|
|
85
|
+
const params = [];
|
|
86
|
+
if (q.where && Object.keys(q.where).length > 0) {
|
|
87
|
+
const conditions = [];
|
|
88
|
+
const whereRecord = q.where;
|
|
89
|
+
for (const key in whereRecord) {
|
|
90
|
+
// Security: Validate column name
|
|
91
|
+
if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Invalid column name: ${key}. Must start with letter, underscore, or dollar. Only alphanumeric, underscore, and dollar allowed.`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
// Safely access where property
|
|
97
|
+
const val = whereRecord[key];
|
|
98
|
+
conditions.push(`${quoteIdentifier(key)} = ?`);
|
|
99
|
+
params.push(val);
|
|
100
|
+
}
|
|
101
|
+
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
102
|
+
}
|
|
103
|
+
if (q.options?.limit) {
|
|
104
|
+
// Security: Validate limit is a positive integer
|
|
105
|
+
const limit = validateInteger(q.options.limit);
|
|
106
|
+
sql += ` LIMIT ${limit}`;
|
|
107
|
+
}
|
|
108
|
+
if (q.options?.skip) {
|
|
109
|
+
// Security: Validate offset is a non-negative integer
|
|
110
|
+
const skip = validateInteger(q.options.skip);
|
|
111
|
+
sql += ` OFFSET ${skip}`;
|
|
112
|
+
}
|
|
113
|
+
return { sql, params };
|
|
114
|
+
}
|
|
115
|
+
async create(collection, data) {
|
|
116
|
+
// Security: Validate table name
|
|
117
|
+
if (!isTableAllowed(collection)) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Table '${collection}' not registered. Call registerAllowedTable() first.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const keys = Object.keys(data);
|
|
123
|
+
// Security: Validate all column names
|
|
124
|
+
for (const key of keys) {
|
|
125
|
+
if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Invalid column name: ${key}. Must start with letter, underscore, or dollar. Only alphanumeric, underscore, and dollar allowed.`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const placeholders = keys.map(() => "?").join(",");
|
|
132
|
+
const quotedKeys = keys.map((k) => quoteIdentifier(k)).join(",");
|
|
133
|
+
const sql = `INSERT INTO ${quoteIdentifier(collection)} (${quotedKeys}) VALUES (${placeholders})`;
|
|
134
|
+
const params = keys.map((k) => data[k]);
|
|
135
|
+
await this.executor(sql, params);
|
|
136
|
+
// Retrieve generic - this might need adjustment per driver for "returning" support
|
|
137
|
+
return data;
|
|
138
|
+
}
|
|
139
|
+
async update(collection, filter, update) {
|
|
140
|
+
// Basic implementation requiring WHERE clause
|
|
141
|
+
// This is complex to map generic Mongo-style updates to SQL without a robust builder
|
|
142
|
+
throw new Error(
|
|
143
|
+
"Complex update translation not implemented for Generic SQL Driver yet. Use raw SQL.",
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
async delete(collection, filter) {
|
|
147
|
+
// Security: Validate table name
|
|
148
|
+
if (!isTableAllowed(collection)) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Table '${collection}' not registered. Call registerAllowedTable() first.`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
// Validate that filter is not empty to prevent accidental full table delete
|
|
154
|
+
if (!filter || Object.keys(filter).length === 0) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
"Delete requires at least one filter condition. Use truncate or raw SQL for full table deletion.",
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const { sql, params } = this.translateQuery({
|
|
160
|
+
find: collection,
|
|
161
|
+
where: filter,
|
|
162
|
+
});
|
|
163
|
+
const deleteSql = sql.replace("SELECT \\*", "DELETE");
|
|
164
|
+
await this.executor(deleteSql, params);
|
|
165
|
+
return 1; // Unknown count without driver specific result
|
|
166
|
+
}
|
|
167
|
+
async count(collection, filter) {
|
|
168
|
+
// Security: Validate table name
|
|
169
|
+
if (!isTableAllowed(collection)) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Table '${collection}' not registered. Call registerAllowedTable() first.`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
const { sql, params } = this.translateQuery({
|
|
175
|
+
find: collection,
|
|
176
|
+
where: filter,
|
|
177
|
+
});
|
|
178
|
+
const countSql = sql.replace("SELECT *", "SELECT COUNT(*) as count");
|
|
179
|
+
const res = await this.executor(countSql, params);
|
|
180
|
+
return res[0]?.count || 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DBConnector } from "./connector";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./drivers/jdb";
|
|
4
|
+
export * from "./drivers/sql";
|
|
5
|
+
export class DB {
|
|
6
|
+
driver;
|
|
7
|
+
config;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.driver = DBConnector.create(config);
|
|
11
|
+
}
|
|
12
|
+
async connect() {
|
|
13
|
+
await this.driver.connect();
|
|
14
|
+
}
|
|
15
|
+
async disconnect() {
|
|
16
|
+
await this.driver.disconnect();
|
|
17
|
+
}
|
|
18
|
+
async query(q, params) {
|
|
19
|
+
if (typeof q === "string") {
|
|
20
|
+
return this.driver.query({ sql: q, params });
|
|
21
|
+
}
|
|
22
|
+
return this.driver.query(q);
|
|
23
|
+
}
|
|
24
|
+
// Fluent API Shortcuts
|
|
25
|
+
find(collection, filter, options) {
|
|
26
|
+
return this.driver.query({ find: collection, where: filter, options });
|
|
27
|
+
}
|
|
28
|
+
async findOne(collection, filter) {
|
|
29
|
+
const res = await this.driver.query({
|
|
30
|
+
find: collection,
|
|
31
|
+
where: filter,
|
|
32
|
+
options: { limit: 1 },
|
|
33
|
+
});
|
|
34
|
+
return res[0] || null;
|
|
35
|
+
}
|
|
36
|
+
create(collection, data) {
|
|
37
|
+
return this.driver.create(collection, data);
|
|
38
|
+
}
|
|
39
|
+
update(collection, filter, update) {
|
|
40
|
+
return this.driver.update(collection, filter, update);
|
|
41
|
+
}
|
|
42
|
+
delete(collection, filter) {
|
|
43
|
+
return this.driver.delete(collection, filter);
|
|
44
|
+
}
|
|
45
|
+
count(collection, filter) {
|
|
46
|
+
return this.driver.count(collection, filter);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|