@stone-js/starters 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/basic-react-declarative/LICENSE +21 -0
- package/basic-react-declarative/README.md +39 -0
- package/basic-react-declarative/app/Application.tsx +89 -0
- package/basic-react-declarative/assets/css/index.css +26 -0
- package/basic-react-declarative/package.json +39 -0
- package/basic-react-declarative/public/logo.png +0 -0
- package/basic-react-declarative/tests/Application.spec.ts +96 -0
- package/basic-react-declarative/tests/__snapshots__/Application.spec.ts.snap +3 -0
- package/basic-react-declarative/tsconfig.json +33 -0
- package/basic-react-declarative/vitest.config.ts +24 -0
- package/basic-react-imperative/LICENSE +21 -0
- package/basic-react-imperative/README.md +39 -0
- package/basic-react-imperative/app/Application.tsx +89 -0
- package/basic-react-imperative/assets/css/index.css +26 -0
- package/basic-react-imperative/package.json +39 -0
- package/basic-react-imperative/public/logo.png +0 -0
- package/basic-react-imperative/tests/Application.spec.ts +80 -0
- package/basic-react-imperative/tests/__snapshots__/Application.spec.ts.snap +3 -0
- package/basic-react-imperative/tsconfig.json +33 -0
- package/basic-react-imperative/vitest.config.ts +24 -0
- package/basic-service-declarative/LICENSE +21 -0
- package/basic-service-declarative/README.md +39 -0
- package/basic-service-declarative/app/Application.ts +56 -0
- package/basic-service-declarative/package.json +34 -0
- package/basic-service-declarative/tests/Application.spec.ts +60 -0
- package/basic-service-declarative/tsconfig.json +25 -0
- package/basic-service-declarative/vitest.config.ts +24 -0
- package/basic-service-imperative/LICENSE +21 -0
- package/basic-service-imperative/README.md +39 -0
- package/basic-service-imperative/app/Application.ts +60 -0
- package/basic-service-imperative/package.json +34 -0
- package/basic-service-imperative/tests/Application.spec.ts +52 -0
- package/basic-service-imperative/tsconfig.json +25 -0
- package/basic-service-imperative/vitest.config.ts +24 -0
- package/continuum-showcase/README.md +44 -0
- package/continuum-showcase/app/env.d.ts +34 -0
- package/continuum-showcase/app/layouts/MainLayout.tsx +20 -0
- package/continuum-showcase/app/pages/BlogPostPage.tsx +62 -0
- package/continuum-showcase/app/pages/HomePage.tsx +58 -0
- package/continuum-showcase/package.json +25 -0
- package/continuum-showcase/stone.config.mjs +20 -0
- package/full-react-declarative/.env.example +1 -0
- package/full-react-declarative/.env.public.example +1 -0
- package/full-react-declarative/LICENSE +21 -0
- package/full-react-declarative/README.md +39 -0
- package/full-react-declarative/app/Application.ts +85 -0
- package/full-react-declarative/app/clients/AxiosClient.ts +136 -0
- package/full-react-declarative/app/clients/CommentClient.ts +61 -0
- package/full-react-declarative/app/clients/PostClient.ts +90 -0
- package/full-react-declarative/app/clients/SecurityClient.ts +66 -0
- package/full-react-declarative/app/clients/UserClient.ts +97 -0
- package/full-react-declarative/app/components/ChangePasswordForm/ChangePasswordForm.tsx +50 -0
- package/full-react-declarative/app/components/CommentForm/CommentForm.tsx +37 -0
- package/full-react-declarative/app/components/CommentItem/CommentItem.tsx +42 -0
- package/full-react-declarative/app/components/CommentWidget/CommentWidget.tsx +95 -0
- package/full-react-declarative/app/components/LoginForm/LoginForm.css +0 -0
- package/full-react-declarative/app/components/LoginForm/LoginForm.tsx +71 -0
- package/full-react-declarative/app/components/PostDetails/PostDetails.tsx +44 -0
- package/full-react-declarative/app/components/PostForm/PostForm.css +0 -0
- package/full-react-declarative/app/components/PostForm/PostForm.tsx +47 -0
- package/full-react-declarative/app/components/PostItem/PostItem.css +0 -0
- package/full-react-declarative/app/components/PostItem/PostItem.tsx +34 -0
- package/full-react-declarative/app/components/RegisterForm/RegisterForm.tsx +110 -0
- package/full-react-declarative/app/components/UserForm/UserForm.tsx +47 -0
- package/full-react-declarative/app/configurations/AppConfiguration.ts +17 -0
- package/full-react-declarative/app/error-pages/DefaultErrorPage/DefaultErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/DefaultErrorPage/DefaultErrorPage.tsx +52 -0
- package/full-react-declarative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.tsx +53 -0
- package/full-react-declarative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.tsx +54 -0
- package/full-react-declarative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.css +0 -0
- package/full-react-declarative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.tsx +53 -0
- package/full-react-declarative/app/errors/ForbiddenError.ts +11 -0
- package/full-react-declarative/app/errors/PostNotFoundError.ts +11 -0
- package/full-react-declarative/app/errors/UnauthorizedError.ts +11 -0
- package/full-react-declarative/app/errors/UserNotFoundError.ts +11 -0
- package/full-react-declarative/app/events/UserEvent.ts +18 -0
- package/full-react-declarative/app/layout/AppLayout/AppLayout.css +20 -0
- package/full-react-declarative/app/layout/AppLayout/AppLayout.tsx +101 -0
- package/full-react-declarative/app/layout/ErrorLayout/ErrorLayout.css +0 -0
- package/full-react-declarative/app/layout/ErrorLayout/ErrorLayout.tsx +41 -0
- package/full-react-declarative/app/layout/SecurityLayout/SecurityLayout.css +0 -0
- package/full-react-declarative/app/layout/SecurityLayout/SecurityLayout.tsx +39 -0
- package/full-react-declarative/app/middleware/AuthMiddleware.ts +85 -0
- package/full-react-declarative/app/models/Comment.ts +31 -0
- package/full-react-declarative/app/models/Post.ts +22 -0
- package/full-react-declarative/app/models/User.ts +62 -0
- package/full-react-declarative/app/pages/home/HomePage.tsx +44 -0
- package/full-react-declarative/app/pages/login/LoginPage.css +0 -0
- package/full-react-declarative/app/pages/login/LoginPage.tsx +73 -0
- package/full-react-declarative/app/pages/posts/CreatePostPage/CreatePostPage.css +0 -0
- package/full-react-declarative/app/pages/posts/CreatePostPage/CreatePostPage.tsx +67 -0
- package/full-react-declarative/app/pages/posts/PostPage/PostPage.tsx +60 -0
- package/full-react-declarative/app/pages/posts/ShowPostPage/ShowPostPage.tsx +83 -0
- package/full-react-declarative/app/pages/posts/UpdatePostPage/UpdatePostPage.tsx +77 -0
- package/full-react-declarative/app/pages/register/RegisterPage.tsx +68 -0
- package/full-react-declarative/app/pages/users/CreateUserPage.tsx +48 -0
- package/full-react-declarative/app/pages/users/ShowUserPage.tsx +62 -0
- package/full-react-declarative/app/pages/users/UpdateUserPage.tsx +57 -0
- package/full-react-declarative/app/pages/users/UserPage.tsx +57 -0
- package/full-react-declarative/app/providers/AppServiceProvider.ts +43 -0
- package/full-react-declarative/app/services/CommentService.ts +59 -0
- package/full-react-declarative/app/services/PostService.ts +108 -0
- package/full-react-declarative/app/services/SecurityService.ts +80 -0
- package/full-react-declarative/app/services/TokenService.ts +116 -0
- package/full-react-declarative/app/services/UserService.ts +126 -0
- package/full-react-declarative/app/utils.ts +17 -0
- package/full-react-declarative/assets/css/index.css +301 -0
- package/full-react-declarative/assets/img/logo.png +0 -0
- package/full-react-declarative/package.json +46 -0
- package/full-react-declarative/public/logo.png +0 -0
- package/full-react-declarative/public/vite.svg +1 -0
- package/full-react-declarative/stone.config.mjs +12 -0
- package/full-react-declarative/tsconfig.json +29 -0
- package/full-react-declarative/vitest.config.ts +24 -0
- package/full-react-imperative/.env.example +1 -0
- package/full-react-imperative/.env.public.example +1 -0
- package/full-react-imperative/LICENSE +21 -0
- package/full-react-imperative/README.md +39 -0
- package/full-react-imperative/app/Application.ts +79 -0
- package/full-react-imperative/app/clients/AxiosClient.ts +124 -0
- package/full-react-imperative/app/clients/CommentClient.ts +57 -0
- package/full-react-imperative/app/clients/PostClient.ts +86 -0
- package/full-react-imperative/app/clients/SecurityClient.ts +60 -0
- package/full-react-imperative/app/clients/UserClient.ts +93 -0
- package/full-react-imperative/app/clients/contracts/IAxiosClient.ts +97 -0
- package/full-react-imperative/app/clients/contracts/ICommentClient.ts +31 -0
- package/full-react-imperative/app/clients/contracts/IPostClient.ts +55 -0
- package/full-react-imperative/app/clients/contracts/ISecurityClient.ts +33 -0
- package/full-react-imperative/app/clients/contracts/IUserClient.ts +61 -0
- package/full-react-imperative/app/components/ChangePasswordForm/ChangePasswordForm.tsx +50 -0
- package/full-react-imperative/app/components/CommentForm/CommentForm.css +35 -0
- package/full-react-imperative/app/components/CommentForm/CommentForm.tsx +45 -0
- package/full-react-imperative/app/components/CommentItem/CommentItem.css +74 -0
- package/full-react-imperative/app/components/CommentItem/CommentItem.tsx +62 -0
- package/full-react-imperative/app/components/CommentWidget/CommentWidget.css +25 -0
- package/full-react-imperative/app/components/CommentWidget/CommentWidget.tsx +119 -0
- package/full-react-imperative/app/components/Dropdown/Dropdown.css +52 -0
- package/full-react-imperative/app/components/Dropdown/Dropdown.tsx +40 -0
- package/full-react-imperative/app/components/LayoutHeader/LayoutHeader.css +62 -0
- package/full-react-imperative/app/components/LayoutHeader/LayoutHeader.tsx +61 -0
- package/full-react-imperative/app/components/LayoutLeftMenu/LayoutLeftMenu.css +25 -0
- package/full-react-imperative/app/components/LayoutLeftMenu/LayoutLeftMenu.tsx +32 -0
- package/full-react-imperative/app/components/LoginForm/LoginForm.css +0 -0
- package/full-react-imperative/app/components/LoginForm/LoginForm.tsx +71 -0
- package/full-react-imperative/app/components/NotificationBadge/NotificationBadge.css +41 -0
- package/full-react-imperative/app/components/NotificationBadge/NotificationBadge.tsx +63 -0
- package/full-react-imperative/app/components/PostCard/PostCard.css +129 -0
- package/full-react-imperative/app/components/PostCard/PostCard.tsx +65 -0
- package/full-react-imperative/app/components/PostForm/PostForm.css +92 -0
- package/full-react-imperative/app/components/PostForm/PostForm.tsx +76 -0
- package/full-react-imperative/app/components/PostSkeleton/PostSkeleton.css +65 -0
- package/full-react-imperative/app/components/PostSkeleton/PostSkeleton.tsx +25 -0
- package/full-react-imperative/app/components/PostWidget/PostWidget.tsx +95 -0
- package/full-react-imperative/app/components/ProfileForm/ProfileForm.css +84 -0
- package/full-react-imperative/app/components/ProfileForm/ProfileForm.tsx +79 -0
- package/full-react-imperative/app/components/RegisterForm/RegisterForm.tsx +110 -0
- package/full-react-imperative/app/components/RightAsidePanel/RightAsidePanel.css +32 -0
- package/full-react-imperative/app/components/RightAsidePanel/RightAsidePanel.tsx +62 -0
- package/full-react-imperative/app/components/SettingsForm/SettingsForm.css +126 -0
- package/full-react-imperative/app/components/SettingsForm/SettingsForm.tsx +86 -0
- package/full-react-imperative/app/components/UserAvatar/UserAvatar.css +18 -0
- package/full-react-imperative/app/components/UserAvatar/UserAvatar.tsx +60 -0
- package/full-react-imperative/app/components/UserBadge/UserBadge.css +33 -0
- package/full-react-imperative/app/components/UserBadge/UserBadge.tsx +49 -0
- package/full-react-imperative/app/components/UserCard/UserCard.css +70 -0
- package/full-react-imperative/app/components/UserCard/UserCard.tsx +43 -0
- package/full-react-imperative/app/configurations/AppConfiguration.ts +19 -0
- package/full-react-imperative/app/error-pages/DefaultErrorPage/DefaultErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/DefaultErrorPage/DefaultErrorPage.tsx +41 -0
- package/full-react-imperative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/ForbiddenErrorPage/ForbiddenErrorPage.tsx +42 -0
- package/full-react-imperative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/NotFoundErrorPage/NotFoundErrorPage.tsx +49 -0
- package/full-react-imperative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.css +0 -0
- package/full-react-imperative/app/error-pages/UnauthorizedErrorPage/UnauthorizedErrorPage.tsx +42 -0
- package/full-react-imperative/app/errors/ForbiddenError.ts +11 -0
- package/full-react-imperative/app/errors/PostNotFoundError.ts +11 -0
- package/full-react-imperative/app/errors/UnauthorizedError.ts +11 -0
- package/full-react-imperative/app/errors/UserNotFoundError.ts +11 -0
- package/full-react-imperative/app/events/UserEvent.ts +18 -0
- package/full-react-imperative/app/layout/AppLayout/AppLayout.css +106 -0
- package/full-react-imperative/app/layout/AppLayout/AppLayout.tsx +48 -0
- package/full-react-imperative/app/layout/ErrorLayout/ErrorLayout.css +0 -0
- package/full-react-imperative/app/layout/ErrorLayout/ErrorLayout.tsx +45 -0
- package/full-react-imperative/app/layout/SecurityLayout/SecurityLayout.css +0 -0
- package/full-react-imperative/app/layout/SecurityLayout/SecurityLayout.tsx +43 -0
- package/full-react-imperative/app/layout/SettingsLayout/SettingsLayout.css +99 -0
- package/full-react-imperative/app/layout/SettingsLayout/SettingsLayout.tsx +44 -0
- package/full-react-imperative/app/middleware/AuthMiddleware.ts +56 -0
- package/full-react-imperative/app/models/Comment.ts +35 -0
- package/full-react-imperative/app/models/Post.ts +27 -0
- package/full-react-imperative/app/models/User.ts +68 -0
- package/full-react-imperative/app/pages/Settings/SettingsPage.tsx +23 -0
- package/full-react-imperative/app/pages/home/HomePage.tsx +58 -0
- package/full-react-imperative/app/pages/login/LoginPage.css +0 -0
- package/full-react-imperative/app/pages/login/LoginPage.tsx +65 -0
- package/full-react-imperative/app/pages/posts/ShowPostPage/ShowPostPage.tsx +64 -0
- package/full-react-imperative/app/pages/posts/UpdatePostPage/UpdatePostPage.tsx +56 -0
- package/full-react-imperative/app/pages/register/RegisterPage.tsx +71 -0
- package/full-react-imperative/app/pages/users/ShowUserPage/ShowUserPage.css +64 -0
- package/full-react-imperative/app/pages/users/ShowUserPage/ShowUserPage.tsx +104 -0
- package/full-react-imperative/app/pages/users/UpdateUserPage/UpdateUserPage.css +0 -0
- package/full-react-imperative/app/pages/users/UpdateUserPage/UpdateUserPage.tsx +43 -0
- package/full-react-imperative/app/pages/users/UserPage/UserPage.css +31 -0
- package/full-react-imperative/app/pages/users/UserPage/UserPage.tsx +59 -0
- package/full-react-imperative/app/pages/utils.ts +67 -0
- package/full-react-imperative/app/providers/AppServiceProvider.ts +40 -0
- package/full-react-imperative/app/services/CommentService.ts +53 -0
- package/full-react-imperative/app/services/PostService.ts +102 -0
- package/full-react-imperative/app/services/SecurityService.ts +72 -0
- package/full-react-imperative/app/services/TokenService.ts +108 -0
- package/full-react-imperative/app/services/UserService.ts +115 -0
- package/full-react-imperative/app/services/contracts/ICommentService.ts +30 -0
- package/full-react-imperative/app/services/contracts/IPostService.ts +65 -0
- package/full-react-imperative/app/services/contracts/ISecurityService.ts +39 -0
- package/full-react-imperative/app/services/contracts/ITokenService.ts +44 -0
- package/full-react-imperative/app/services/contracts/IUserService.ts +70 -0
- package/full-react-imperative/app/utils.ts +31 -0
- package/full-react-imperative/assets/css/index.css +301 -0
- package/full-react-imperative/assets/img/logo.png +0 -0
- package/full-react-imperative/package.json +48 -0
- package/full-react-imperative/public/logo.png +0 -0
- package/full-react-imperative/public/vite.svg +1 -0
- package/full-react-imperative/stone.config.mjs +12 -0
- package/full-react-imperative/tsconfig.json +29 -0
- package/full-react-imperative/vitest.config.ts +24 -0
- package/full-service-declarative/.env.example +2 -0
- package/full-service-declarative/LICENSE +21 -0
- package/full-service-declarative/README.md +65 -0
- package/full-service-declarative/app/Application.ts +327 -0
- package/full-service-declarative/app/commands/ListSessionsCommand.ts +70 -0
- package/full-service-declarative/app/commands/ListUsersCommand.ts +56 -0
- package/full-service-declarative/app/configurations/AppConfiguration.ts +52 -0
- package/full-service-declarative/app/configurations/UserLiveConfiguration.ts +28 -0
- package/full-service-declarative/app/database/DatabaseClient.ts +43 -0
- package/full-service-declarative/app/database/schema.ts +43 -0
- package/full-service-declarative/app/error-handlers/SecurityErrorHandler.ts +61 -0
- package/full-service-declarative/app/errors/CredentialsError.ts +12 -0
- package/full-service-declarative/app/events/UserEvent.ts +17 -0
- package/full-service-declarative/app/handlers/CommentEventHandler.ts +103 -0
- package/full-service-declarative/app/handlers/PostEventHandler.ts +104 -0
- package/full-service-declarative/app/handlers/SecurityEventHandler.ts +108 -0
- package/full-service-declarative/app/handlers/UserEventHandler.ts +159 -0
- package/full-service-declarative/app/listeners/UserEventListener.ts +35 -0
- package/full-service-declarative/app/middleware/AuthMiddleware.ts +54 -0
- package/full-service-declarative/app/models/Comment.ts +38 -0
- package/full-service-declarative/app/models/Post.ts +50 -0
- package/full-service-declarative/app/models/Session.ts +14 -0
- package/full-service-declarative/app/models/User.ts +77 -0
- package/full-service-declarative/app/providers/DrizzleServiceProvider.ts +59 -0
- package/full-service-declarative/app/repositories/CommentRepository.ts +155 -0
- package/full-service-declarative/app/repositories/PostRepository.ts +138 -0
- package/full-service-declarative/app/repositories/SessionRepository.ts +123 -0
- package/full-service-declarative/app/repositories/UserRepository.ts +99 -0
- package/full-service-declarative/app/services/CommentService.ts +112 -0
- package/full-service-declarative/app/services/PostService.ts +100 -0
- package/full-service-declarative/app/services/SecurityService.ts +232 -0
- package/full-service-declarative/app/services/SessionService.ts +130 -0
- package/full-service-declarative/app/services/UserService.ts +110 -0
- package/full-service-declarative/app/subscribers/UserEventSubscriber.ts +38 -0
- package/full-service-declarative/drizzle.config.ts +13 -0
- package/full-service-declarative/package.json +48 -0
- package/full-service-declarative/stone.config.mjs +12 -0
- package/full-service-declarative/tsconfig.json +25 -0
- package/full-service-declarative/vitest.config.ts +24 -0
- package/full-service-imperative/.env.example +2 -0
- package/full-service-imperative/LICENSE +21 -0
- package/full-service-imperative/README.md +65 -0
- package/full-service-imperative/app/Application.ts +317 -0
- package/full-service-imperative/app/commands/ListSessionsCommand.ts +54 -0
- package/full-service-imperative/app/commands/ListUsersCommand.ts +42 -0
- package/full-service-imperative/app/configurations/AppConfiguration.ts +44 -0
- package/full-service-imperative/app/configurations/UserLiveConfiguration.ts +26 -0
- package/full-service-imperative/app/database/DatabaseClient.ts +39 -0
- package/full-service-imperative/app/database/schema.ts +43 -0
- package/full-service-imperative/app/error-handlers/SecurityErrorHandler.ts +58 -0
- package/full-service-imperative/app/errors/CredentialsError.ts +12 -0
- package/full-service-imperative/app/events/UserEvent.ts +17 -0
- package/full-service-imperative/app/handlers/CommentEventHandler.ts +99 -0
- package/full-service-imperative/app/handlers/PostEventHandler.ts +99 -0
- package/full-service-imperative/app/handlers/SecurityEventHandler.ts +83 -0
- package/full-service-imperative/app/handlers/UserEventHandler.ts +132 -0
- package/full-service-imperative/app/listeners/UserEventListener.ts +23 -0
- package/full-service-imperative/app/middleware/AuthMiddleware.ts +44 -0
- package/full-service-imperative/app/models/Comment.ts +38 -0
- package/full-service-imperative/app/models/Post.ts +50 -0
- package/full-service-imperative/app/models/Session.ts +14 -0
- package/full-service-imperative/app/models/User.ts +77 -0
- package/full-service-imperative/app/providers/DrizzleServiceProvider.ts +56 -0
- package/full-service-imperative/app/repositories/CommentRepository.ts +148 -0
- package/full-service-imperative/app/repositories/PostRepository.ts +130 -0
- package/full-service-imperative/app/repositories/SessionRepository.ts +115 -0
- package/full-service-imperative/app/repositories/UserRepository.ts +91 -0
- package/full-service-imperative/app/repositories/contracts/ICommentRepository.ts +72 -0
- package/full-service-imperative/app/repositories/contracts/IPostRepository.ts +63 -0
- package/full-service-imperative/app/repositories/contracts/ISessionRepository.ts +65 -0
- package/full-service-imperative/app/repositories/contracts/IUserRepository.ts +55 -0
- package/full-service-imperative/app/services/CommentService.ts +109 -0
- package/full-service-imperative/app/services/PostService.ts +97 -0
- package/full-service-imperative/app/services/SecurityService.ts +224 -0
- package/full-service-imperative/app/services/SessionService.ts +124 -0
- package/full-service-imperative/app/services/UserService.ts +105 -0
- package/full-service-imperative/app/services/contracts/ICommentService.ts +62 -0
- package/full-service-imperative/app/services/contracts/IPostService.ts +53 -0
- package/full-service-imperative/app/services/contracts/ISecurityService.ts +97 -0
- package/full-service-imperative/app/services/contracts/ISessionService.ts +73 -0
- package/full-service-imperative/app/services/contracts/IUserService.ts +57 -0
- package/full-service-imperative/app/subscribers/UserEventSubscriber.ts +28 -0
- package/full-service-imperative/drizzle.config.ts +13 -0
- package/full-service-imperative/package.json +48 -0
- package/full-service-imperative/stone.config.mjs +12 -0
- package/full-service-imperative/tsconfig.json +25 -0
- package/full-service-imperative/vitest.config.ts +24 -0
- package/package.json +225 -0
- package/standard-react-declarative/LICENSE +21 -0
- package/standard-react-declarative/README.md +39 -0
- package/standard-react-declarative/app/Application.ts +45 -0
- package/standard-react-declarative/app/pages/welcome/WelcomePage.tsx +57 -0
- package/standard-react-declarative/app/services/WelcomeService.ts +38 -0
- package/standard-react-declarative/assets/css/index.css +26 -0
- package/standard-react-declarative/package.json +42 -0
- package/standard-react-declarative/tsconfig.json +33 -0
- package/standard-react-declarative/vitest.config.ts +24 -0
- package/standard-react-imperative/LICENSE +21 -0
- package/standard-react-imperative/README.md +39 -0
- package/standard-react-imperative/app/Application.ts +41 -0
- package/standard-react-imperative/app/pages/welcome/WelcomePage.tsx +50 -0
- package/standard-react-imperative/app/services/WelcomeService.ts +38 -0
- package/standard-react-imperative/assets/css/index.css +26 -0
- package/standard-react-imperative/package.json +42 -0
- package/standard-react-imperative/tsconfig.json +33 -0
- package/standard-react-imperative/vitest.config.ts +24 -0
- package/standard-service-declarative/LICENSE +21 -0
- package/standard-service-declarative/README.md +39 -0
- package/standard-service-declarative/app/Application.ts +39 -0
- package/standard-service-declarative/app/handlers/WelcomeEventHandler.ts +45 -0
- package/standard-service-declarative/app/services/WelcomeService.ts +38 -0
- package/standard-service-declarative/package.json +36 -0
- package/standard-service-declarative/tsconfig.json +25 -0
- package/standard-service-declarative/vitest.config.ts +24 -0
- package/standard-service-imperative/LICENSE +21 -0
- package/standard-service-imperative/README.md +39 -0
- package/standard-service-imperative/app/Application.ts +11 -0
- package/standard-service-imperative/app/handlers/welcomeEventHandler.ts +31 -0
- package/standard-service-imperative/app/services/welcomeService.ts +38 -0
- package/standard-service-imperative/package.json +35 -0
- package/standard-service-imperative/tsconfig.json +25 -0
- package/standard-service-imperative/vitest.config.ts +24 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { eq } from 'drizzle-orm'
|
|
2
|
+
import { users } from '../database/schema'
|
|
3
|
+
import { UserModel } from '../models/User'
|
|
4
|
+
import { defineStone } from '@stone-js/core'
|
|
5
|
+
import { LibSQLDatabase } from 'drizzle-orm/libsql'
|
|
6
|
+
import { IUserRepository } from './contracts/IUserRepository'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* User Repository Options
|
|
10
|
+
*/
|
|
11
|
+
export interface UserRepositoryOptions {
|
|
12
|
+
database: LibSQLDatabase
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Factory User Repository
|
|
17
|
+
*/
|
|
18
|
+
export function factoryUserRepository ({ database }: UserRepositoryOptions): IUserRepository {
|
|
19
|
+
return {
|
|
20
|
+
/**
|
|
21
|
+
* List users
|
|
22
|
+
*
|
|
23
|
+
* @param limit - The limit of users to list
|
|
24
|
+
* @returns The list of users
|
|
25
|
+
*/
|
|
26
|
+
async list (limit: number): Promise<UserModel[]> {
|
|
27
|
+
return await database.select().from(users).limit(limit)
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Find a user by ID
|
|
32
|
+
*
|
|
33
|
+
* @param id - The ID of the user to find
|
|
34
|
+
* @returns The user or undefined if not found
|
|
35
|
+
*/
|
|
36
|
+
async findById (id: number): Promise<UserModel | undefined> {
|
|
37
|
+
const result = await database.select().from(users).where(eq(users.id, id)).get()
|
|
38
|
+
return result ?? undefined
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Find a user by dynamic conditions
|
|
43
|
+
*
|
|
44
|
+
* @param conditions - Conditions to match the user
|
|
45
|
+
* @returns The user or undefined if not found
|
|
46
|
+
*/
|
|
47
|
+
async findBy (conditions: Partial<UserModel>): Promise<UserModel | undefined> {
|
|
48
|
+
const result = await database.select().from(users).where(eq(users.email, conditions.email ?? '')).get()
|
|
49
|
+
return result ?? undefined
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a user
|
|
54
|
+
*
|
|
55
|
+
* @param user - The user to create
|
|
56
|
+
* @returns The ID of the created user
|
|
57
|
+
*/
|
|
58
|
+
async create (user: Omit<UserModel, 'id'>): Promise<bigint | undefined> {
|
|
59
|
+
const result = await database.insert(users).values(user)
|
|
60
|
+
return result.lastInsertRowid
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Update a user
|
|
65
|
+
*
|
|
66
|
+
* @param id - The ID of the user to update
|
|
67
|
+
* @param user - The user data to update
|
|
68
|
+
* @returns The updated user or undefined if not found
|
|
69
|
+
*/
|
|
70
|
+
async update (id: number, user: Partial<UserModel>): Promise<UserModel | undefined> {
|
|
71
|
+
const result = await database.update(users).set(user).where(eq(users.id, id)).returning().get()
|
|
72
|
+
return result ?? undefined
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Delete a user
|
|
77
|
+
*
|
|
78
|
+
* @param id - The ID of the user to delete
|
|
79
|
+
* @returns `true` if the user was deleted, `false` if the user was not found
|
|
80
|
+
*/
|
|
81
|
+
async delete (id: number): Promise<boolean> {
|
|
82
|
+
const result = await database.delete(users).where(eq(users.id, id)).run()
|
|
83
|
+
return result.rowsAffected > 0
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* User Repository
|
|
90
|
+
*/
|
|
91
|
+
export const UserRepository = defineStone(factoryUserRepository, { isFactory: true, singleton: true, alias: 'userRepository' })
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Comment, CommentCreateModel, CommentModel } from '../../models/Comment'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Comment Repository contract
|
|
5
|
+
*/
|
|
6
|
+
export interface ICommentRepository {
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves a list of comments with optional filtering and sorting.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Optional filters (postId, authorId, limit).
|
|
11
|
+
* @returns The list of comments.
|
|
12
|
+
*/
|
|
13
|
+
list: (options?: { postId?: number, authorId?: number, limit?: number }) => Promise<Comment[]>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves all comments created by a specific author.
|
|
17
|
+
*
|
|
18
|
+
* @param authorId - The ID of the author.
|
|
19
|
+
* @param limit - The number of comments to retrieve.
|
|
20
|
+
* @returns The list of comments.
|
|
21
|
+
*/
|
|
22
|
+
listByAuthor: (authorId: number, limit: number) => Promise<Comment[]>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves all comments for a specific post.
|
|
26
|
+
*
|
|
27
|
+
* @param postId - The ID of the post.
|
|
28
|
+
* @param limit - The number of comments to retrieve.
|
|
29
|
+
* @returns The list of comments.
|
|
30
|
+
*/
|
|
31
|
+
listByPost: (postId: number, limit: number) => Promise<Comment[]>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Finds a comment by its ID.
|
|
35
|
+
*
|
|
36
|
+
* @param commentId - The ID of the comment.
|
|
37
|
+
* @returns The comment or `undefined` if not found.
|
|
38
|
+
*/
|
|
39
|
+
findById: (commentId: number) => Promise<Comment | undefined>
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new comment.
|
|
43
|
+
*
|
|
44
|
+
* @param comment - The comment data.
|
|
45
|
+
* @returns The ID of the created comment.
|
|
46
|
+
*/
|
|
47
|
+
create: (comment: CommentCreateModel) => Promise<bigint | undefined>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Updates a comment by its ID.
|
|
51
|
+
*
|
|
52
|
+
* @param commentId - The ID of the comment to update.
|
|
53
|
+
* @param comment - The updated comment data.
|
|
54
|
+
* @returns The updated comment or `undefined` if not found.
|
|
55
|
+
*/
|
|
56
|
+
update: (commentId: number, comment: Partial<CommentModel>) => Promise<Comment | undefined>
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deletes a comment by its ID.
|
|
60
|
+
*
|
|
61
|
+
* @param commentId - The ID of the comment to delete.
|
|
62
|
+
* @returns `true` if deleted, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
delete: (commentId: number) => Promise<boolean>
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Selects comment fields along with author information.
|
|
68
|
+
*
|
|
69
|
+
* @returns The selection descriptor for joined comment-author records.
|
|
70
|
+
*/
|
|
71
|
+
selectWithAuthor: () => Record<string, any>
|
|
72
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Post, PostCreateModel, PostModel } from '../../models/Post'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Post Repository contract
|
|
5
|
+
*/
|
|
6
|
+
export interface IPostRepository {
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves a list of posts with optional filtering and sorting.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Optional filters (authorId, limit).
|
|
11
|
+
* @returns The list of posts.
|
|
12
|
+
*/
|
|
13
|
+
list: (options?: { authorId?: number, limit?: number }) => Promise<Post[]>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves all posts created by a specific author.
|
|
17
|
+
*
|
|
18
|
+
* @param authorId - The ID of the author.
|
|
19
|
+
* @param limit - The number of posts to retrieve.
|
|
20
|
+
* @returns The list of posts.
|
|
21
|
+
*/
|
|
22
|
+
listByAuthor: (authorId: number, limit: number) => Promise<Post[]>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Finds a post by its ID.
|
|
26
|
+
*
|
|
27
|
+
* @param postId - The ID of the post to retrieve.
|
|
28
|
+
* @returns The post or `undefined` if not found.
|
|
29
|
+
*/
|
|
30
|
+
findById: (postId: number) => Promise<Post | undefined>
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new post.
|
|
34
|
+
*
|
|
35
|
+
* @param post - The post to create.
|
|
36
|
+
* @returns The ID of the created post.
|
|
37
|
+
*/
|
|
38
|
+
create: (post: PostCreateModel) => Promise<bigint | undefined>
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Updates a post by its ID.
|
|
42
|
+
*
|
|
43
|
+
* @param postId - The ID of the post to update.
|
|
44
|
+
* @param post - The updated post data.
|
|
45
|
+
* @returns `true` if the update was successful.
|
|
46
|
+
*/
|
|
47
|
+
update: (postId: number, post: Partial<PostModel>) => Promise<boolean>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Deletes a post by its ID.
|
|
51
|
+
*
|
|
52
|
+
* @param postId - The ID of the post to delete.
|
|
53
|
+
* @returns `true` if the post was deleted, otherwise `false`.
|
|
54
|
+
*/
|
|
55
|
+
delete: (postId: number) => Promise<boolean>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Selects posts with author information.
|
|
59
|
+
*
|
|
60
|
+
* @returns A selection descriptor including post and author fields.
|
|
61
|
+
*/
|
|
62
|
+
selectWithAuthor: () => Record<string, any>
|
|
63
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { UserModel } from '../../models/User'
|
|
2
|
+
import { Session } from '../../models/Session'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Session Repository contract
|
|
6
|
+
*/
|
|
7
|
+
export interface ISessionRepository {
|
|
8
|
+
/**
|
|
9
|
+
* List sessions
|
|
10
|
+
*
|
|
11
|
+
* @param limit - The limit of sessions to list
|
|
12
|
+
* @returns The list of sessions
|
|
13
|
+
*/
|
|
14
|
+
list: (limit: number) => Promise<Session[]>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* List sessions by user
|
|
18
|
+
*
|
|
19
|
+
* @param user - The user
|
|
20
|
+
* @param limit - The limit of sessions to list
|
|
21
|
+
* @returns The list of sessions
|
|
22
|
+
*/
|
|
23
|
+
listByUser: (user: UserModel, limit: number) => Promise<Session[]>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Find a session by ID
|
|
27
|
+
*
|
|
28
|
+
* @param id - The session ID
|
|
29
|
+
* @returns The session or undefined
|
|
30
|
+
*/
|
|
31
|
+
findById: (id: number) => Promise<Session | undefined>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get latest session for a user
|
|
35
|
+
*
|
|
36
|
+
* @param user - The user
|
|
37
|
+
* @returns The latest session or undefined
|
|
38
|
+
*/
|
|
39
|
+
getLatest: (user: UserModel) => Promise<Session | undefined>
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a session
|
|
43
|
+
*
|
|
44
|
+
* @param session - The session data
|
|
45
|
+
* @returns The created session
|
|
46
|
+
*/
|
|
47
|
+
create: (session: Omit<Session, 'id'>) => Promise<Session>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Update a session
|
|
51
|
+
*
|
|
52
|
+
* @param id - The session ID
|
|
53
|
+
* @param session - The partial session data
|
|
54
|
+
* @returns The updated session or undefined
|
|
55
|
+
*/
|
|
56
|
+
update: (id: number, session: Partial<Session>) => Promise<Session | undefined>
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Delete a session
|
|
60
|
+
*
|
|
61
|
+
* @param id - The session ID
|
|
62
|
+
* @returns `true` if deleted, `false` otherwise
|
|
63
|
+
*/
|
|
64
|
+
delete: (id: number) => Promise<boolean>
|
|
65
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { UserModel } from '../../models/User'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* User Repository contract
|
|
5
|
+
*/
|
|
6
|
+
export interface IUserRepository {
|
|
7
|
+
/**
|
|
8
|
+
* List users
|
|
9
|
+
*
|
|
10
|
+
* @param limit - The limit of users to list
|
|
11
|
+
* @returns The list of users
|
|
12
|
+
*/
|
|
13
|
+
list: (limit: number) => Promise<UserModel[]>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Find a user by ID
|
|
17
|
+
*
|
|
18
|
+
* @param id - The ID of the user to find
|
|
19
|
+
* @returns The user or undefined if not found
|
|
20
|
+
*/
|
|
21
|
+
findById: (id: number) => Promise<UserModel | undefined>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Find a user by dynamic conditions
|
|
25
|
+
*
|
|
26
|
+
* @param conditions - Conditions to match the user
|
|
27
|
+
* @returns The user or undefined if not found
|
|
28
|
+
*/
|
|
29
|
+
findBy: (conditions: Partial<UserModel>) => Promise<UserModel | undefined>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create a user
|
|
33
|
+
*
|
|
34
|
+
* @param user - The user to create
|
|
35
|
+
* @returns The ID of the created user
|
|
36
|
+
*/
|
|
37
|
+
create: (user: Omit<UserModel, 'id'>) => Promise<bigint | undefined>
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update a user
|
|
41
|
+
*
|
|
42
|
+
* @param id - The ID of the user to update
|
|
43
|
+
* @param user - The user data to update
|
|
44
|
+
* @returns The updated user or undefined if not found
|
|
45
|
+
*/
|
|
46
|
+
update: (id: number, user: Partial<UserModel>) => Promise<UserModel | undefined>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Delete a user
|
|
50
|
+
*
|
|
51
|
+
* @param id - The ID of the user to delete
|
|
52
|
+
* @returns `true` if the user was deleted, `false` if not
|
|
53
|
+
*/
|
|
54
|
+
delete: (id: number) => Promise<boolean>
|
|
55
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { NotFoundError } from '@stone-js/http-core'
|
|
2
|
+
import { DependencyResolver } from '@stone-js/router'
|
|
3
|
+
import { Comment, CommentModel } from '../models/Comment'
|
|
4
|
+
import { defineService, isNotEmpty } from '@stone-js/core'
|
|
5
|
+
import { ICommentService } from './contracts/ICommentService'
|
|
6
|
+
import { ICommentRepository } from '../repositories/contracts/ICommentRepository'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Comment Service Options
|
|
10
|
+
*/
|
|
11
|
+
export interface CommentServiceOptions {
|
|
12
|
+
commentRepository: ICommentRepository
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Factory Comment Service
|
|
17
|
+
*/
|
|
18
|
+
export function factoryCommentService ({ commentRepository }: CommentServiceOptions): ICommentService {
|
|
19
|
+
return {
|
|
20
|
+
/**
|
|
21
|
+
* List comments.
|
|
22
|
+
*
|
|
23
|
+
* @param limit - The limit of comments to list.
|
|
24
|
+
*/
|
|
25
|
+
async list (limit: number = 10): Promise<Comment[]> {
|
|
26
|
+
return await commentRepository.list({ limit })
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve comments for a specific post.
|
|
31
|
+
*
|
|
32
|
+
* @param postId - The post ID.
|
|
33
|
+
* @param limit - The number of comments to retrieve.
|
|
34
|
+
*/
|
|
35
|
+
async listByPost (postId: number, limit: number = 10): Promise<Comment[]> {
|
|
36
|
+
return await commentRepository.list({ postId, limit })
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve comments by a specific user.
|
|
41
|
+
*
|
|
42
|
+
* @param authorId - The author ID.
|
|
43
|
+
* @param limit - The number of comments to retrieve.
|
|
44
|
+
*/
|
|
45
|
+
async listByAuthor (authorId: number, limit: number = 10): Promise<Comment[]> {
|
|
46
|
+
return await commentRepository.list({ authorId, limit })
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Find a comment by ID.
|
|
51
|
+
*
|
|
52
|
+
* @param id - The ID of the comment.
|
|
53
|
+
* @returns The found comment.
|
|
54
|
+
*/
|
|
55
|
+
async findById (id: number): Promise<Comment> {
|
|
56
|
+
const comment: Comment | undefined = await commentRepository.findById(id)
|
|
57
|
+
if (isNotEmpty<CommentModel>(comment)) return comment
|
|
58
|
+
throw new NotFoundError(`Comment with ID ${id} not found`)
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a new comment.
|
|
63
|
+
*
|
|
64
|
+
* @param payload - The comment data to create.
|
|
65
|
+
*/
|
|
66
|
+
async create (payload: Omit<CommentModel, 'id'>): Promise<bigint | undefined> {
|
|
67
|
+
return await commentRepository.create({ ...payload, createdAt: Date.now() })
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Update an existing comment.
|
|
72
|
+
*
|
|
73
|
+
* @param id - The ID of the comment.
|
|
74
|
+
* @param payload - The comment data to update.
|
|
75
|
+
* @returns The updated comment.
|
|
76
|
+
*/
|
|
77
|
+
async update (id: number, payload: Partial<CommentModel>): Promise<Comment> {
|
|
78
|
+
const comment: Comment | undefined = await commentRepository.update(id, payload)
|
|
79
|
+
if (isNotEmpty<CommentModel>(comment)) return comment
|
|
80
|
+
throw new NotFoundError(`Comment with ID ${id} not found`)
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Delete a comment.
|
|
85
|
+
*
|
|
86
|
+
* @param id - The ID of the comment.
|
|
87
|
+
*/
|
|
88
|
+
async delete (id: number): Promise<boolean> {
|
|
89
|
+
return await commentRepository.delete(id)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Resolve route binding.
|
|
96
|
+
*
|
|
97
|
+
* @param _key - The key of the binding.
|
|
98
|
+
* @param value - The value of the binding.
|
|
99
|
+
* @param container - The container instance.
|
|
100
|
+
*/
|
|
101
|
+
export async function commentResolveRouteBinding (_key: string, value: any, container?: DependencyResolver): Promise<Comment | undefined> {
|
|
102
|
+
const commentService = container?.resolve<ICommentService>('commentService')
|
|
103
|
+
return await commentService?.findById(Number(value))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Comment Service
|
|
108
|
+
*/
|
|
109
|
+
export const CommentService = defineService(factoryCommentService, { isFactory: true, singleton: true, alias: 'commentService' })
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { NotFoundError } from '@stone-js/http-core'
|
|
2
|
+
import { DependencyResolver } from '@stone-js/router'
|
|
3
|
+
import { IPostService } from './contracts/IPostService'
|
|
4
|
+
import { defineService, isNotEmpty } from '@stone-js/core'
|
|
5
|
+
import { Post, PostCreateModel, PostModel } from '../models/Post'
|
|
6
|
+
import { IPostRepository } from '../repositories/contracts/IPostRepository'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Post Service Options
|
|
10
|
+
*/
|
|
11
|
+
export interface PostServiceOptions {
|
|
12
|
+
postRepository: IPostRepository
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Factory Post Service
|
|
17
|
+
*/
|
|
18
|
+
export function factoryPostService ({ postRepository }: PostServiceOptions): IPostService {
|
|
19
|
+
return {
|
|
20
|
+
/**
|
|
21
|
+
* List posts.
|
|
22
|
+
*
|
|
23
|
+
* @param limit - The limit of posts to list.
|
|
24
|
+
*/
|
|
25
|
+
async list (limit: number = 10): Promise<Post[]> {
|
|
26
|
+
return await postRepository.list({ limit })
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve posts by a specific user.
|
|
31
|
+
*
|
|
32
|
+
* @param authorId - The author ID.
|
|
33
|
+
* @param limit - The number of posts to retrieve.
|
|
34
|
+
*/
|
|
35
|
+
async listByAuthor (authorId: number, limit: number = 10): Promise<Post[]> {
|
|
36
|
+
return await postRepository.listByAuthor(authorId, limit)
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Find a post by ID.
|
|
41
|
+
*
|
|
42
|
+
* @param id - The ID of the post.
|
|
43
|
+
* @returns The found post.
|
|
44
|
+
*/
|
|
45
|
+
async findById (id: number): Promise<Post> {
|
|
46
|
+
const post: Post | undefined = await postRepository.findById(id)
|
|
47
|
+
if (isNotEmpty<PostModel>(post)) return post
|
|
48
|
+
throw new NotFoundError(`Post with ID ${id} not found`)
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a new post.
|
|
53
|
+
*
|
|
54
|
+
* @param payload - The post data to create.
|
|
55
|
+
*/
|
|
56
|
+
async create (payload: Omit<PostCreateModel, 'id'>): Promise<bigint | undefined> {
|
|
57
|
+
return await postRepository.create({ ...payload, createdAt: Date.now(), updatedAt: Date.now() })
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Update an existing post.
|
|
62
|
+
*
|
|
63
|
+
* @param id - The ID of the post.
|
|
64
|
+
* @param payload - The post data to update.
|
|
65
|
+
* @returns The updated post.
|
|
66
|
+
*/
|
|
67
|
+
async update (id: number, payload: Partial<PostModel>): Promise<boolean> {
|
|
68
|
+
return await postRepository.update(id, payload)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Delete a post.
|
|
73
|
+
*
|
|
74
|
+
* @param id - The ID of the post.
|
|
75
|
+
*/
|
|
76
|
+
async delete (id: number): Promise<boolean> {
|
|
77
|
+
return await postRepository.delete(id)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Resolve route binding.
|
|
84
|
+
*
|
|
85
|
+
* @param _key - The key of the binding.
|
|
86
|
+
* @param value - The value of the binding.
|
|
87
|
+
* @param container - The container instance.
|
|
88
|
+
*/
|
|
89
|
+
export async function postResolveRouteBinding (_key: string, value: any, container?: DependencyResolver): Promise<Post | undefined> {
|
|
90
|
+
const postService = container?.resolve<IPostService>('postService')
|
|
91
|
+
return await postService?.findById(Number(value))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Post Service
|
|
96
|
+
*/
|
|
97
|
+
export const PostService = defineService(factoryPostService, { isFactory: true, singleton: true, alias: 'postService' })
|