create-lykosjs 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -2
- package/bootstrap/.env.example +4 -0
- package/bootstrap/.github/workflows/ci.yml +1 -0
- package/bootstrap/.prettierrc +14 -0
- package/bootstrap/AGENTS.md +94 -0
- package/bootstrap/CLAUDE.md +46 -0
- package/bootstrap/README.md +73 -0
- package/bootstrap/gitignore.template +34 -0
- package/bootstrap/package.json +25 -0
- package/bootstrap/src/graphql/graphql.executor.ts +54 -0
- package/bootstrap/src/graphql/graphql.handler.ts +18 -0
- package/bootstrap/src/graphql/graphql.resolvers.ts +14 -0
- package/bootstrap/src/graphql/graphql.schema.ts +58 -0
- package/bootstrap/src/launch.ts +36 -0
- package/bootstrap/src/modules/users/graphql-schema/users.graphql +29 -0
- package/bootstrap/src/modules/users/tests/users.resolver.test.ts +161 -0
- package/bootstrap/src/modules/users/tests/users.service.test.ts +36 -0
- package/bootstrap/src/modules/users/users.module.ts +8 -0
- package/bootstrap/src/modules/users/users.resolver.ts +42 -0
- package/bootstrap/src/modules/users/users.service.ts +33 -0
- package/bootstrap/src/modules.ts +3 -0
- package/bootstrap/tsconfig.build.json +22 -0
- package/bootstrap/tsconfig.json +30 -0
- package/index.js +154 -0
- package/lib/args.js +55 -0
- package/lib/prompt.js +90 -0
- package/lib/scaffold.js +88 -0
- package/lib/templates.js +32 -0
- package/package.json +17 -4
- package/template/.env.example +4 -0
- package/template/.github/workflows/ci.yml +1 -0
- package/template/.prettierrc +14 -0
- package/template/AGENTS.md +81 -0
- package/template/CLAUDE.md +40 -0
- package/template/README.md +41 -0
- package/template/gitignore.template +34 -0
- package/template/package.json +21 -0
- package/template/src/launch.ts +17 -0
- package/template/src/modules/users/rules/create.ts +7 -0
- package/template/src/modules/users/rules/update.ts +3 -0
- package/template/src/modules/users/schemas/user.schema.ts +1 -0
- package/template/src/modules/users/tests/users.controller.test.ts +19 -0
- package/template/src/modules/users/tests/users.service.test.ts +18 -0
- package/template/src/modules/users/users.controller.ts +36 -0
- package/template/src/modules/users/users.module.ts +12 -0
- package/template/src/modules/users/users.route.ts +30 -0
- package/template/src/modules/users/users.service.ts +22 -0
- package/template/src/modules.ts +3 -0
- package/template/tsconfig.build.json +22 -0
- package/template/tsconfig.json +30 -0
package/lib/scaffold.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { access, cp, mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Entries that must never end up inside a generated project. */
|
|
5
|
+
const IGNORED_ENTRIES = new Set(["node_modules", ".git", ".DS_Store", "Thumbs.db"]);
|
|
6
|
+
|
|
7
|
+
const FALLBACK_PACKAGE_NAME = "my-riser-bob-app";
|
|
8
|
+
|
|
9
|
+
export class ScaffoldError extends Error {}
|
|
10
|
+
|
|
11
|
+
const exists = async (path) => {
|
|
12
|
+
try {
|
|
13
|
+
await access(path);
|
|
14
|
+
return true;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error.code !== "ENOENT") throw error;
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Turns the folder name into a valid npm package name
|
|
23
|
+
* ("My App" -> "my-app"). Falls back to the template default.
|
|
24
|
+
*/
|
|
25
|
+
export function toPackageName(projectName) {
|
|
26
|
+
const name = basename(projectName)
|
|
27
|
+
.trim()
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/\s+/g, "-")
|
|
30
|
+
.replace(/[^a-z0-9._~-]/g, "-")
|
|
31
|
+
.replace(/-+/g, "-")
|
|
32
|
+
.replace(/^[-._]+|-+$/g, "");
|
|
33
|
+
|
|
34
|
+
return name || FALLBACK_PACKAGE_NAME;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Returns an error message when the project name can't be used, otherwise undefined. */
|
|
38
|
+
export function validateProjectName(projectName) {
|
|
39
|
+
if (!projectName || !projectName.trim()) return "Choose a project directory name.";
|
|
40
|
+
if (projectName.includes("\0")) return "Project name contains an invalid character.";
|
|
41
|
+
if (process.platform === "win32" && /[<>"|?*]/.test(projectName)) {
|
|
42
|
+
return 'Project name cannot contain any of: < > " | ? *';
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Copies `templateDir` into `target` and prepares it:
|
|
49
|
+
* - copies every entry (hidden files included) except dev-only folders
|
|
50
|
+
* - turns `gitignore.template` into `.gitignore`
|
|
51
|
+
* - sets the package name to the chosen project name
|
|
52
|
+
*
|
|
53
|
+
* If anything fails after the target folder was created, it is removed again.
|
|
54
|
+
*/
|
|
55
|
+
export async function scaffold({ templateDir, target, projectName }) {
|
|
56
|
+
if (!(await exists(join(templateDir, "package.json")))) {
|
|
57
|
+
throw new ScaffoldError(`Template package.json not found at ${templateDir}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await mkdir(target, { recursive: true });
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const entries = await readdir(templateDir, { withFileTypes: true });
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
if (IGNORED_ENTRIES.has(entry.name)) continue;
|
|
66
|
+
await cp(join(templateDir, entry.name), join(target, entry.name), {
|
|
67
|
+
recursive: true,
|
|
68
|
+
filter: (source) => !IGNORED_ENTRIES.has(basename(source)),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const gitignoreTemplate = join(target, "gitignore.template");
|
|
73
|
+
if (await exists(gitignoreTemplate)) {
|
|
74
|
+
await rename(gitignoreTemplate, join(target, ".gitignore"));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const packageJsonPath = join(target, "package.json");
|
|
78
|
+
if (!(await exists(packageJsonPath))) {
|
|
79
|
+
throw new ScaffoldError("package.json was not copied.");
|
|
80
|
+
}
|
|
81
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
82
|
+
packageJson.name = toPackageName(projectName);
|
|
83
|
+
await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
await rm(target, { recursive: true, force: true });
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
package/lib/templates.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Every project flavour has its own, fully independent template folder.
|
|
8
|
+
* `dir` is resolved relative to the root of this package.
|
|
9
|
+
*/
|
|
10
|
+
export const TEMPLATES = [
|
|
11
|
+
{
|
|
12
|
+
id: "rest",
|
|
13
|
+
label: "REST API",
|
|
14
|
+
hint: "controllers, routes, modules & validation rules",
|
|
15
|
+
dir: resolve(packageRoot, "template"),
|
|
16
|
+
endpoint: null,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "graphql",
|
|
20
|
+
label: "GraphQL",
|
|
21
|
+
hint: "schema-first with resolvers",
|
|
22
|
+
dir: resolve(packageRoot, "bootstrap"),
|
|
23
|
+
endpoint: "POST http://localhost:4000/graphql",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_TEMPLATE_ID = "rest";
|
|
28
|
+
|
|
29
|
+
export function findTemplate(id) {
|
|
30
|
+
const needle = String(id ?? "").trim().toLowerCase();
|
|
31
|
+
return TEMPLATES.find((template) => template.id === needle);
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-lykosjs",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Create a new LykosJS application",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-lykosjs": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"lib",
|
|
12
|
+
"template",
|
|
13
|
+
"bootstrap"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "bun test"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# GitHub Actions workflow for running tests and building the project on every push and pull request.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"singleQuote": true,
|
|
3
|
+
"semi": false,
|
|
4
|
+
"trailingComma": "all",
|
|
5
|
+
"printWidth": 100,
|
|
6
|
+
"tabWidth": 2,
|
|
7
|
+
"useTabs": false,
|
|
8
|
+
"bracketSpacing": true,
|
|
9
|
+
"bracketSameLine": false,
|
|
10
|
+
"arrowParens": "always",
|
|
11
|
+
"endOfLine": "lf",
|
|
12
|
+
"quoteProps": "as-needed",
|
|
13
|
+
"proseWrap": "preserve"
|
|
14
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
This project is built with LykosJS, a lightweight, modular backend framework built for speed and DX.
|
|
6
|
+
|
|
7
|
+
Follow the existing project structure and conventions. Prefer simple, maintainable solutions over unnecessary abstractions.
|
|
8
|
+
|
|
9
|
+
## Technology Stack
|
|
10
|
+
|
|
11
|
+
- Runtime and package manager: Bun
|
|
12
|
+
- Language: TypeScript
|
|
13
|
+
- backend framework: LykosJS
|
|
14
|
+
- Tests: Bun's built-in test runner (`bun:test`)
|
|
15
|
+
|
|
16
|
+
Use Bun for installing dependencies, running scripts, and executing tests.
|
|
17
|
+
|
|
18
|
+
## Project Structure
|
|
19
|
+
|
|
20
|
+
- `src/index.ts`: Main application entry point.
|
|
21
|
+
- `src/modules.ts`: Centralized module registration.
|
|
22
|
+
- `src/modules/`: Feature modules.
|
|
23
|
+
- `src/modules/users/`: Example Users module.
|
|
24
|
+
- `src/modules/users/users.controller.ts`: Controller logic.
|
|
25
|
+
- `src/modules/users/users.service.ts`: Service logic.
|
|
26
|
+
- `src/modules/users/users.route.ts`: Route definitions.
|
|
27
|
+
- `src/modules/users/users.module.ts`: Module configuration.
|
|
28
|
+
- `src/modules/users/schemas/`: Data schemas.
|
|
29
|
+
- `src/modules/users/rules/`: Validation rules.
|
|
30
|
+
|
|
31
|
+
Follow the actual files in the repository if the structure changes.
|
|
32
|
+
|
|
33
|
+
## Development Rules
|
|
34
|
+
|
|
35
|
+
1. Inspect relevant files before making changes.
|
|
36
|
+
2. Follow existing LykosJS APIs and established project patterns.
|
|
37
|
+
3. Do not invent framework methods, decorators, middleware, or configuration options.
|
|
38
|
+
4. Use TypeScript types instead of `any` whenever possible.
|
|
39
|
+
5. Keep modules focused and responsibilities clearly separated.
|
|
40
|
+
6. Validate input at the appropriate application boundary.
|
|
41
|
+
7. Handle errors consistently with the existing application.
|
|
42
|
+
8. Avoid unrelated refactoring and unnecessary dependencies.
|
|
43
|
+
9. Preserve existing behavior unless the requested change requires otherwise.
|
|
44
|
+
10. Never claim that tests or builds passed unless they were actually executed.
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
47
|
+
|
|
48
|
+
Check `package.json` before assuming a script exists.
|
|
49
|
+
|
|
50
|
+
Common commands may include:
|
|
51
|
+
|
|
52
|
+
- `bun install` — install dependencies.
|
|
53
|
+
- `bun run dev` — start the development server.
|
|
54
|
+
- `bun run build` — build the project, if configured.
|
|
55
|
+
- `bun test` — run tests.
|
|
56
|
+
|
|
57
|
+
Use only commands supported by the current project configuration.
|
|
58
|
+
|
|
59
|
+
## Testing
|
|
60
|
+
|
|
61
|
+
- Use `bun:test` for unit tests.
|
|
62
|
+
- Test observable behavior, not just whether methods exist.
|
|
63
|
+
- Include success cases, failure cases, and relevant edge cases.
|
|
64
|
+
- Run the relevant tests after modifying code when possible.
|
|
65
|
+
- Report any tests that could not be executed.
|
|
66
|
+
|
|
67
|
+
## Dependencies and Security
|
|
68
|
+
|
|
69
|
+
- Avoid adding dependencies when existing tools are sufficient.
|
|
70
|
+
- Never hardcode secrets, tokens, or credentials.
|
|
71
|
+
- Validate untrusted input.
|
|
72
|
+
- Do not weaken authentication, authorization, or validation to make tests pass.
|
|
73
|
+
|
|
74
|
+
## Final Response
|
|
75
|
+
|
|
76
|
+
When completing a task, summarize:
|
|
77
|
+
|
|
78
|
+
1. What changed.
|
|
79
|
+
2. Which files were affected.
|
|
80
|
+
3. Which tests or build commands were actually run.
|
|
81
|
+
4. Any remaining limitations or follow-up work.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Claude Code Instructions
|
|
2
|
+
|
|
3
|
+
## Start Here
|
|
4
|
+
|
|
5
|
+
Read `AGENTS.md` before making changes. Follow its project conventions and requirements throughout the task.
|
|
6
|
+
|
|
7
|
+
## Working with LykosJS
|
|
8
|
+
|
|
9
|
+
This project uses LykosJS, Bun, and TypeScript.
|
|
10
|
+
|
|
11
|
+
- Inspect the existing implementation before using a framework API.
|
|
12
|
+
- Follow the APIs and patterns actually present in the project.
|
|
13
|
+
- Do not assume LykosJS behaves like Express, NestJS, or another framework.
|
|
14
|
+
- Do not invent methods, decorators, route registration patterns, or configuration options.
|
|
15
|
+
- Consult the installed package's types and the existing source code when API behavior is unclear.
|
|
16
|
+
|
|
17
|
+
## Editing Rules
|
|
18
|
+
|
|
19
|
+
- Keep changes focused on the user's request.
|
|
20
|
+
- Preserve the existing architecture and public interfaces.
|
|
21
|
+
- Avoid unrelated file changes and unnecessary rewrites.
|
|
22
|
+
- Prefer explicit TypeScript types and avoid `any`.
|
|
23
|
+
- Do not add dependencies without a clear need.
|
|
24
|
+
- Never overwrite user changes without inspecting them first.
|
|
25
|
+
|
|
26
|
+
## Verification
|
|
27
|
+
|
|
28
|
+
Before finishing:
|
|
29
|
+
|
|
30
|
+
1. Review the changes you made.
|
|
31
|
+
2. Run relevant tests using the project's configured commands.
|
|
32
|
+
3. Run the build if a build script exists and is relevant.
|
|
33
|
+
4. Fix issues caused by your changes when possible.
|
|
34
|
+
5. Report exactly which checks passed and which were not run.
|
|
35
|
+
|
|
36
|
+
Never claim successful verification without executing the corresponding command.
|
|
37
|
+
|
|
38
|
+
## Communication
|
|
39
|
+
|
|
40
|
+
Explain important implementation decisions concisely. Mention affected files, verification results, and any unresolved issues.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://res.cloudinary.com/dgagbheuj/image/upload/v1795227129/koakwx1uyjf68edpilc8.png" alt="LykosJS Logo" width="110" />
|
|
4
|
+
|
|
5
|
+
# LykosJS
|
|
6
|
+
|
|
7
|
+
**Built for Speed. Designed for Scale.**
|
|
8
|
+
|
|
9
|
+
A lightweight, modular backend framework built for speed and DX.
|
|
10
|
+
|
|
11
|
+
[](https://bun.sh)
|
|
12
|
+
[](https://www.typescriptlang.org/)
|
|
13
|
+
[](https://lykosjs.com/docs/license)
|
|
14
|
+
|
|
15
|
+
[Documentation](https://lykosjs.com/docs) · [License](https://lykosjs.com/docs/license)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Requires [Bun](https://bun.sh) 1.4 or newer.
|
|
22
|
+
|
|
23
|
+
**Create a new project (recommended)**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun create lykosjs my-app
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Or install the package**
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add lykosjs
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<img
|
|
37
|
+
src="https://res.cloudinary.com/dgagbheuj/image/upload/v1795313052/muvd4yk1qmoa3kmdql43.png"
|
|
38
|
+
alt="LykosJS — Built for Speed. Designed for Scale."
|
|
39
|
+
width="100%"
|
|
40
|
+
/>
|
|
41
|
+
</p>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# dependencies (bun install)
|
|
2
|
+
node_modules
|
|
3
|
+
|
|
4
|
+
# output
|
|
5
|
+
out
|
|
6
|
+
dist
|
|
7
|
+
*.tgz
|
|
8
|
+
|
|
9
|
+
# code coverage
|
|
10
|
+
coverage
|
|
11
|
+
*.lcov
|
|
12
|
+
|
|
13
|
+
# logs
|
|
14
|
+
logs
|
|
15
|
+
_.log
|
|
16
|
+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|
17
|
+
|
|
18
|
+
# dotenv environment variable files
|
|
19
|
+
.env
|
|
20
|
+
.env.development.local
|
|
21
|
+
.env.test.local
|
|
22
|
+
.env.production.local
|
|
23
|
+
.env.local
|
|
24
|
+
|
|
25
|
+
# caches
|
|
26
|
+
.eslintcache
|
|
27
|
+
.cache
|
|
28
|
+
*.tsbuildinfo
|
|
29
|
+
|
|
30
|
+
# IntelliJ based IDEs
|
|
31
|
+
.idea
|
|
32
|
+
|
|
33
|
+
# Finder (MacOS) folder config
|
|
34
|
+
.DS_Store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-lykosjs-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "bun run --watch src/launch.ts",
|
|
8
|
+
"build": "bun build src/launch.ts --outdir dist --target=bun --minify",
|
|
9
|
+
"start": "bun run src/launch.ts",
|
|
10
|
+
"typecheck": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"lykosjs": "^0.0.1",
|
|
14
|
+
"@socket.io/bun-engine": "^0.1.2",
|
|
15
|
+
"socket.io": "^4.8.4"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bun": "latest",
|
|
19
|
+
"typescript": "^5.9.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Lykos } from 'lykosjs'
|
|
2
|
+
import { Modules } from './modules'
|
|
3
|
+
|
|
4
|
+
async function launch() {
|
|
5
|
+
const app = new Lykos()
|
|
6
|
+
|
|
7
|
+
app.GET('/', async (ctx, reply) => reply.send('Welcome to LykosJS 🐺'))
|
|
8
|
+
|
|
9
|
+
app.modules(Modules)
|
|
10
|
+
|
|
11
|
+
app.listen(4000, () => console.log('🐺 LykosJS is running at http://localhost:4000'))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
launch().catch((error: unknown) => {
|
|
15
|
+
console.error('🐺 [LykosJS] Failed to start application:', error)
|
|
16
|
+
process.exit(1)
|
|
17
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class UserSchema {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { UsersController } from '../users.controller'
|
|
3
|
+
import { UsersService } from '../users.service'
|
|
4
|
+
|
|
5
|
+
describe('UsersController', () => {
|
|
6
|
+
const usersController = new UsersController(new UsersService())
|
|
7
|
+
|
|
8
|
+
test('should be defined', () => {
|
|
9
|
+
expect(usersController).toBeDefined()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('should expose all route handlers', () => {
|
|
13
|
+
expect(typeof usersController.create).toBe('function')
|
|
14
|
+
expect(typeof usersController.findAll).toBe('function')
|
|
15
|
+
expect(typeof usersController.findOne).toBe('function')
|
|
16
|
+
expect(typeof usersController.update).toBe('function')
|
|
17
|
+
expect(typeof usersController.delete).toBe('function')
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { UsersService } from '../users.service'
|
|
3
|
+
|
|
4
|
+
describe('UsersService', () => {
|
|
5
|
+
const usersService = new UsersService()
|
|
6
|
+
|
|
7
|
+
test('should be defined', () => {
|
|
8
|
+
expect(usersService).toBeDefined()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('should expose all service methods', () => {
|
|
12
|
+
expect(typeof usersService.create).toBe('function')
|
|
13
|
+
expect(typeof usersService.findAll).toBe('function')
|
|
14
|
+
expect(typeof usersService.findOne).toBe('function')
|
|
15
|
+
expect(typeof usersService.update).toBe('function')
|
|
16
|
+
expect(typeof usersService.delete).toBe('function')
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ContextHandler } from 'lykosjs'
|
|
2
|
+
import type { UsersService } from './users.service'
|
|
3
|
+
|
|
4
|
+
export class UsersController {
|
|
5
|
+
constructor(private readonly usersService: UsersService) {}
|
|
6
|
+
|
|
7
|
+
readonly create: ContextHandler = async (ctx, reply) => {
|
|
8
|
+
// TODO: Implement creation logic.
|
|
9
|
+
const result = await this.usersService.create()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
readonly findAll: ContextHandler = async (ctx, reply) => {
|
|
13
|
+
// TODO: Implement fetching all records.
|
|
14
|
+
const result = await this.usersService.findAll()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
readonly findOne: ContextHandler = async (ctx, reply) => {
|
|
18
|
+
// TODO: Implement fetching a record by ID.
|
|
19
|
+
const result = await this.usersService.findOne()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readonly update: ContextHandler = async (ctx, reply) => {
|
|
23
|
+
// TODO: Implement updating a record.
|
|
24
|
+
const result = await this.usersService.update()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
readonly delete: ContextHandler = async (ctx, reply) => {
|
|
28
|
+
// TODO: Implement deleting a record.
|
|
29
|
+
const result = await this.usersService.delete()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
verifyToken(token: string) {
|
|
33
|
+
// TODO: Implement token verification.
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthMiddleware, bind, defineAuth, Lykos, DIModule } from 'lykosjs'
|
|
2
|
+
import { UsersService } from './users.service'
|
|
3
|
+
import { UsersController } from './users.controller'
|
|
4
|
+
import { UsersRouter } from './users.route'
|
|
5
|
+
|
|
6
|
+
export class UsersModule extends DIModule {
|
|
7
|
+
override imports = []
|
|
8
|
+
override providers = [UsersService]
|
|
9
|
+
override controllers = [bind(UsersController, UsersService)]
|
|
10
|
+
override routers = [bind(UsersRouter, Lykos, UsersController, AuthMiddleware)]
|
|
11
|
+
override auth = defineAuth({ verifier: UsersController, mode: 'bearer' })
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Lykos } from 'lykosjs'
|
|
2
|
+
import { AuthMiddleware } from 'lykosjs'
|
|
3
|
+
import { UsersController } from './users.controller'
|
|
4
|
+
|
|
5
|
+
export class UsersRouter {
|
|
6
|
+
constructor(
|
|
7
|
+
private readonly app: Lykos,
|
|
8
|
+
private readonly controller: UsersController,
|
|
9
|
+
private readonly authMiddleware: AuthMiddleware,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
register(): void {
|
|
13
|
+
// Public routes
|
|
14
|
+
this.app.group('/api/users', (guest) => {
|
|
15
|
+
guest.GET('/', this.controller.findAll)
|
|
16
|
+
guest.GET('/:id', this.controller.findOne)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Protected routes
|
|
20
|
+
this.app.group(
|
|
21
|
+
'/api/users',
|
|
22
|
+
(auth) => {
|
|
23
|
+
auth.POST('/', this.controller.create)
|
|
24
|
+
auth.PUT('/:id', this.controller.update)
|
|
25
|
+
auth.DELETE('/:id', this.controller.delete)
|
|
26
|
+
},
|
|
27
|
+
this.authMiddleware.middleware,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class UsersService {
|
|
2
|
+
constructor() {}
|
|
3
|
+
async create() {
|
|
4
|
+
// TODO: Implement creation logic.
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async findAll() {
|
|
8
|
+
// TODO: Implement fetching all records.
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async findOne() {
|
|
12
|
+
// TODO: Implement fetching a record by ID.
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async update() {
|
|
16
|
+
// TODO: Implement updating a record.
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async delete() {
|
|
20
|
+
// TODO: Implement deleting a record.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["ESNext"],
|
|
6
|
+
"types": ["bun"],
|
|
7
|
+
"module": "Preserve",
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"noEmit": false,
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"rewriteRelativeImportExtensions": true,
|
|
14
|
+
"outDir": "./dist",
|
|
15
|
+
"rootDir": "./src",
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true,
|
|
18
|
+
"noImplicitOverride": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts"],
|
|
21
|
+
"exclude": ["test", "tests", "node_modules", "dist"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"types": ["bun"],
|
|
11
|
+
|
|
12
|
+
// Bundler mode
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"allowImportingTsExtensions": true,
|
|
15
|
+
"verbatimModuleSyntax": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"noImplicitOverride": true,
|
|
24
|
+
|
|
25
|
+
// Some stricter flags (disabled by default)
|
|
26
|
+
"noUnusedLocals": false,
|
|
27
|
+
"noUnusedParameters": false,
|
|
28
|
+
"noPropertyAccessFromIndexSignature": false
|
|
29
|
+
}
|
|
30
|
+
}
|