db-json-cli 1.0.5 → 2.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.
Files changed (119) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-build-manifest.json +26 -0
  3. package/.next/app-path-routes-manifest.json +1 -0
  4. package/.next/build-manifest.json +32 -0
  5. package/.next/cache/webpack/client-production/0.pack +0 -0
  6. package/.next/cache/webpack/client-production/1.pack +0 -0
  7. package/.next/cache/webpack/client-production/2.pack +0 -0
  8. package/.next/cache/webpack/client-production/3.pack +0 -0
  9. package/.next/cache/webpack/client-production/4.pack +0 -0
  10. package/.next/cache/webpack/client-production/index.pack +0 -0
  11. package/.next/cache/webpack/client-production/index.pack.old +0 -0
  12. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  13. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  14. package/.next/cache/webpack/server-production/0.pack +0 -0
  15. package/.next/cache/webpack/server-production/1.pack +0 -0
  16. package/.next/cache/webpack/server-production/2.pack +0 -0
  17. package/.next/cache/webpack/server-production/3.pack +0 -0
  18. package/.next/cache/webpack/server-production/index.pack +0 -0
  19. package/.next/cache/webpack/server-production/index.pack.old +0 -0
  20. package/.next/export-marker.json +1 -0
  21. package/.next/images-manifest.json +1 -0
  22. package/.next/next-minimal-server.js.nft.json +1 -0
  23. package/.next/next-server.js.nft.json +1 -0
  24. package/.next/package.json +1 -0
  25. package/.next/prerender-manifest.json +1 -0
  26. package/.next/react-loadable-manifest.json +1 -0
  27. package/.next/required-server-files.json +1 -0
  28. package/.next/routes-manifest.json +1 -0
  29. package/.next/server/app/_not-found/page.js +1 -0
  30. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  31. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  32. package/.next/server/app/_not-found.html +1 -0
  33. package/.next/server/app/_not-found.meta +6 -0
  34. package/.next/server/app/_not-found.rsc +9 -0
  35. package/.next/server/app/api/[resource]/[id]/route.js +1 -0
  36. package/.next/server/app/api/[resource]/[id]/route.js.nft.json +1 -0
  37. package/.next/server/app/api/[resource]/route.js +1 -0
  38. package/.next/server/app/api/[resource]/route.js.nft.json +1 -0
  39. package/.next/server/app/api/info/route.js +1 -0
  40. package/.next/server/app/api/info/route.js.nft.json +1 -0
  41. package/.next/server/app/api/info.body +1 -0
  42. package/.next/server/app/api/info.meta +1 -0
  43. package/.next/server/app/api/login/route.js +1 -0
  44. package/.next/server/app/api/login/route.js.nft.json +1 -0
  45. package/.next/server/app/api/register/route.js +1 -0
  46. package/.next/server/app/api/register/route.js.nft.json +1 -0
  47. package/.next/server/app/index.html +1 -0
  48. package/.next/server/app/index.meta +5 -0
  49. package/.next/server/app/index.rsc +7 -0
  50. package/.next/server/app/page.js +1 -0
  51. package/.next/server/app/page.js.nft.json +1 -0
  52. package/.next/server/app/page_client-reference-manifest.js +1 -0
  53. package/.next/server/app-paths-manifest.json +9 -0
  54. package/.next/server/chunks/276.js +2 -0
  55. package/.next/server/chunks/471.js +2 -0
  56. package/.next/server/chunks/610.js +12 -0
  57. package/.next/server/chunks/682.js +6 -0
  58. package/.next/server/chunks/944.js +1 -0
  59. package/.next/server/chunks/font-manifest.json +1 -0
  60. package/.next/server/font-manifest.json +1 -0
  61. package/.next/server/functions-config-manifest.json +1 -0
  62. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  63. package/.next/server/middleware-build-manifest.js +1 -0
  64. package/.next/server/middleware-manifest.json +6 -0
  65. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  66. package/.next/server/next-font-manifest.js +1 -0
  67. package/.next/server/next-font-manifest.json +1 -0
  68. package/.next/server/pages/404.html +1 -0
  69. package/.next/server/pages/500.html +1 -0
  70. package/.next/server/pages/_app.js +1 -0
  71. package/.next/server/pages/_app.js.nft.json +1 -0
  72. package/.next/server/pages/_document.js +1 -0
  73. package/.next/server/pages/_document.js.nft.json +1 -0
  74. package/.next/server/pages/_error.js +1 -0
  75. package/.next/server/pages/_error.js.nft.json +1 -0
  76. package/.next/server/pages-manifest.json +1 -0
  77. package/.next/server/server-reference-manifest.js +1 -0
  78. package/.next/server/server-reference-manifest.json +1 -0
  79. package/.next/server/webpack-runtime.js +1 -0
  80. package/.next/static/chunks/117-9bcfe95f89d4b2e1.js +2 -0
  81. package/.next/static/chunks/29-984b7c92c950b64f.js +1 -0
  82. package/.next/static/chunks/app/_not-found/page-32c70da5a397ed57.js +1 -0
  83. package/.next/static/chunks/app/layout-cbd3ebdc4ecc5247.js +1 -0
  84. package/.next/static/chunks/app/page-448ab87af648362a.js +1 -0
  85. package/.next/static/chunks/fd9d1056-9f91b5e418130764.js +1 -0
  86. package/.next/static/chunks/framework-f66176bb897dc684.js +1 -0
  87. package/.next/static/chunks/main-a3aef5995f5a9328.js +1 -0
  88. package/.next/static/chunks/main-app-9982ced3bf7037dc.js +1 -0
  89. package/.next/static/chunks/pages/_app-72b849fbd24ac258.js +1 -0
  90. package/.next/static/chunks/pages/_error-7ba65e1336b92748.js +1 -0
  91. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  92. package/.next/static/chunks/webpack-35b091ca5c5192ac.js +1 -0
  93. package/.next/static/vSEQaRlm1A99jSM80ZjFU/_buildManifest.js +1 -0
  94. package/.next/static/vSEQaRlm1A99jSM80ZjFU/_ssgManifest.js +1 -0
  95. package/.next/trace +2 -0
  96. package/.next/types/app/api/[resource]/[id]/route.ts +343 -0
  97. package/.next/types/app/api/[resource]/route.ts +343 -0
  98. package/.next/types/app/api/info/route.ts +343 -0
  99. package/.next/types/app/api/login/route.ts +343 -0
  100. package/.next/types/app/api/register/route.ts +343 -0
  101. package/.next/types/app/layout.ts +79 -0
  102. package/.next/types/app/page.ts +79 -0
  103. package/.next/types/package.json +1 -0
  104. package/app/api/[resource]/[id]/route.js +34 -0
  105. package/app/api/[resource]/route.js +74 -0
  106. package/app/api/info/route.js +26 -0
  107. package/app/api/login/route.js +27 -0
  108. package/app/api/register/route.js +32 -0
  109. package/app/layout.jsx +7 -0
  110. package/app/page.jsx +321 -0
  111. package/bin/cli.js +37 -0
  112. package/jsconfig.json +8 -0
  113. package/{src → lib}/auth.js +13 -11
  114. package/lib/db.js +47 -0
  115. package/next.config.js +21 -0
  116. package/package.json +24 -13
  117. package/bin/db-json-cli.js +0 -30
  118. package/src/index.ejs +0 -261
  119. package/src/server.js +0 -146
package/src/index.ejs DELETED
@@ -1,261 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>db-json-cli API Documentation</title>
7
- <style>
8
- * {
9
- margin: 0;
10
- padding: 0;
11
- box-sizing: border-box;
12
- }
13
- body {
14
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
15
- background: linear-gradient(to bottom, #1a1a2e 0%, #16213e 100%);
16
- color: #333;
17
- min-height: 100vh;
18
- }
19
- .header {
20
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
21
- padding: 3rem 2rem;
22
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
23
- }
24
- .container {
25
- max-width: 1200px;
26
- margin: 0 auto;
27
- }
28
- .header h1 {
29
- color: white;
30
- font-size: 2.5rem;
31
- margin-bottom: 0.5rem;
32
- font-weight: 700;
33
- }
34
- .header p {
35
- color: rgba(255, 255, 255, 0.9);
36
- font-size: 1.1rem;
37
- }
38
- .content {
39
- padding: 2rem;
40
- }
41
- .info-box {
42
- background: white;
43
- border-radius: 12px;
44
- padding: 1.5rem;
45
- margin-bottom: 2rem;
46
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
47
- }
48
- .info-box h2 {
49
- color: #667eea;
50
- font-size: 1.3rem;
51
- margin-bottom: 0.5rem;
52
- }
53
- .info-box p {
54
- color: #666;
55
- line-height: 1.6;
56
- }
57
- .base-url {
58
- background: #f8f9fa;
59
- padding: 0.5rem 1rem;
60
- border-radius: 6px;
61
- font-family: "Courier New", monospace;
62
- color: #333;
63
- display: inline-block;
64
- margin-top: 0.5rem;
65
- }
66
- .endpoints {
67
- background: white;
68
- border-radius: 12px;
69
- padding: 2rem;
70
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
71
- }
72
- .endpoints h2 {
73
- color: #333;
74
- font-size: 1.5rem;
75
- margin-bottom: 1.5rem;
76
- padding-bottom: 0.5rem;
77
- border-bottom: 2px solid #667eea;
78
- }
79
- .endpoint-item {
80
- background: #f8f9fa;
81
- border: 1px solid #e9ecef;
82
- border-radius: 8px;
83
- padding: 1.5rem;
84
- margin-bottom: 1rem;
85
- transition: all 0.3s ease;
86
- }
87
- .endpoint-item:hover {
88
- transform: translateY(-2px);
89
- box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
90
- border-color: #667eea;
91
- }
92
- .endpoint-header {
93
- display: flex;
94
- align-items: center;
95
- gap: 1rem;
96
- margin-bottom: 1rem;
97
- flex-wrap: wrap;
98
- }
99
- .method-badge {
100
- padding: 0.3rem 0.8rem;
101
- border-radius: 4px;
102
- font-weight: 600;
103
- font-size: 0.75rem;
104
- text-transform: uppercase;
105
- letter-spacing: 0.5px;
106
- }
107
- .method-get {
108
- background: #e7f5ff;
109
- color: #1971c2;
110
- }
111
- .method-post {
112
- background: #d3f9d8;
113
- color: #2f9e44;
114
- }
115
- .permission-badge {
116
- padding: 0.3rem 0.8rem;
117
- border-radius: 4px;
118
- font-weight: 600;
119
- font-size: 0.75rem;
120
- text-transform: uppercase;
121
- letter-spacing: 0.5px;
122
- }
123
- .permission-public {
124
- background: #d3f9d8;
125
- color: #2f9e44;
126
- }
127
- .permission-private {
128
- background: #ffd43b;
129
- color: #856404;
130
- }
131
- .endpoint-path {
132
- font-family: "Courier New", monospace;
133
- font-size: 1.1rem;
134
- color: #333;
135
- font-weight: 500;
136
- }
137
- .endpoint-count {
138
- margin-left: auto;
139
- background: #667eea;
140
- color: white;
141
- padding: 0.3rem 0.8rem;
142
- border-radius: 20px;
143
- font-size: 0.85rem;
144
- font-weight: 600;
145
- }
146
- .endpoint-description {
147
- color: #666;
148
- margin-bottom: 1rem;
149
- line-height: 1.5;
150
- }
151
- .endpoint-actions {
152
- display: flex;
153
- gap: 0.5rem;
154
- }
155
- .action-btn {
156
- padding: 0.5rem 1rem;
157
- border-radius: 6px;
158
- text-decoration: none;
159
- font-size: 0.9rem;
160
- font-weight: 500;
161
- transition: all 0.2s;
162
- display: inline-block;
163
- }
164
- .btn-primary {
165
- background: #667eea;
166
- color: white;
167
- }
168
- .btn-primary:hover {
169
- background: #5568d3;
170
- transform: translateY(-1px);
171
- }
172
- .btn-secondary {
173
- background: #e9ecef;
174
- color: #333;
175
- }
176
- .btn-secondary:hover {
177
- background: #dee2e6;
178
- }
179
- .footer {
180
- text-align: center;
181
- padding: 2rem;
182
- color: rgba(255, 255, 255, 0.7);
183
- font-size: 0.9rem;
184
- }
185
- </style>
186
- </head>
187
- <body>
188
- <div class="header">
189
- <div class="container">
190
- <h1>🚀 db-json-cli API</h1>
191
- <p>RESTful JSON API Documentation</p>
192
- </div>
193
- </div>
194
-
195
- <div class="container content">
196
- <div class="info-box">
197
- <h2>📖 API Information</h2>
198
- <p>Welcome to the db-json-cli API. This API provides RESTful endpoints for managing your data.</p>
199
- <div class="base-url">Base URL: http://localhost:<%= port %></div>
200
- </div>
201
-
202
- <div class="endpoints">
203
- <h2>Available Endpoints</h2>
204
- <% routeList.forEach(r => { %>
205
- <div class="endpoint-item">
206
- <div class="endpoint-header">
207
- <span class="method-badge method-get">GET</span>
208
- <span class="endpoint-path">/<%= r.key %></span>
209
- <span class="permission-badge permission-<%= r.permission %>"><%= r.permission.toUpperCase() %></span>
210
- <span class="endpoint-count"><%= r.count %> <%= r.count === 1 ? 'item' : 'items' %></span>
211
- </div>
212
- <div class="endpoint-description">Retrieve all <%= r.key %> or filter by ID range using ?from=1&to=10</div>
213
- <div class="endpoint-actions">
214
- <a href="http://localhost:<%= port %>/<%= r.key %>" target="_blank" class="action-btn btn-primary">
215
- Try it out
216
- </a>
217
- </div>
218
- </div>
219
-
220
- <div class="endpoint-item">
221
- <div class="endpoint-header">
222
- <span class="method-badge method-get">GET</span>
223
- <span class="endpoint-path">/<%= r.key %>/:id</span>
224
- <span class="permission-badge permission-<%= r.permission %>"><%= r.permission.toUpperCase() %></span>
225
- </div>
226
- <div class="endpoint-description">Retrieve a specific item by ID</div>
227
- </div>
228
-
229
- <div class="endpoint-item">
230
- <div class="endpoint-header">
231
- <span class="method-badge method-post">POST</span>
232
- <span class="endpoint-path">/<%= r.key %></span>
233
- <span class="permission-badge permission-<%= r.permission %>"><%= r.permission.toUpperCase() %></span>
234
- </div>
235
- <div class="endpoint-description">Create a new item (ID will be auto-generated)</div>
236
- </div>
237
- <% }) %>
238
-
239
- <div class="endpoint-item">
240
- <div class="endpoint-header">
241
- <span class="method-badge method-post">POST</span>
242
- <span class="endpoint-path">/register</span>
243
- </div>
244
- <div class="endpoint-description">Register a new user account</div>
245
- </div>
246
-
247
- <div class="endpoint-item">
248
- <div class="endpoint-header">
249
- <span class="method-badge method-post">POST</span>
250
- <span class="endpoint-path">/login</span>
251
- </div>
252
- <div class="endpoint-description">Login and receive access tokens</div>
253
- </div>
254
- </div>
255
- </div>
256
-
257
- <div class="footer">
258
- <p>Generated by db-json-cli • Made with ♥</p>
259
- </div>
260
- </body>
261
- </html>
package/src/server.js DELETED
@@ -1,146 +0,0 @@
1
- import express from "express";
2
- import fs from "fs-extra";
3
- import bodyParser from "body-parser";
4
- import cors from "cors";
5
- import { hashPassword, comparePassword, generateTokens, authMiddleware } from "./auth.js";
6
-
7
- import path from "path";
8
- import { fileURLToPath } from "url";
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = path.dirname(__filename);
12
-
13
- export const startServer = async (dbPath, port = 4000) => {
14
- const app = express();
15
- app.use(cors());
16
- app.use(bodyParser.json());
17
-
18
- // EJS 설정
19
- app.set("view engine", "ejs");
20
- app.set("views", __dirname);
21
-
22
- app.use(express.static("public"));
23
-
24
- let db = {
25
- users: [],
26
- rules: { test1: "public", test2: "private", test3: "public" },
27
- test1: [
28
- { id: 1, message: "good" },
29
- { id: 2, message: "good" },
30
- { id: 3, message: "good" },
31
- ],
32
- test2: [
33
- { id: 1, message: "good" },
34
- { id: 2, message: "good" },
35
- { id: 3, message: "good" },
36
- ],
37
- test3: [
38
- { id: 1, message: "good" },
39
- { id: 2, message: "good" },
40
- { id: 3, message: "good" },
41
- ],
42
- };
43
- if (fs.existsSync(dbPath)) db = await fs.readJson(dbPath);
44
-
45
- const saveDB = async () => fs.writeJson(dbPath, db, { spaces: 2 });
46
-
47
- // REGISTER
48
- app.post("/register", async (req, res) => {
49
- const { email, password, name } = req.body;
50
- if (!email || !password) return res.status(400).json({ message: "Email/password required" });
51
-
52
- const exists = db.users.find((u) => u.email === email);
53
- if (exists) return res.status(409).json({ message: "User already exists" });
54
-
55
- const hashed = await hashPassword(password);
56
- const id = db.users.length ? Math.max(...db.users.map((u) => u.id)) + 1 : 1;
57
- const newUser = { id, email, name: name || "", password: hashed };
58
- db.users.push(newUser);
59
- await saveDB();
60
-
61
- const tokens = generateTokens({ id, email });
62
- res.json(tokens);
63
- });
64
-
65
- // LOGIN
66
- app.post("/login", async (req, res) => {
67
- const { email, password } = req.body;
68
- const user = db.users.find((u) => u.email === email);
69
- if (!user) return res.status(401).json({ message: "Invalid credentials" });
70
-
71
- const valid = await comparePassword(password, user.password);
72
- if (!valid) return res.status(401).json({ message: "Invalid credentials" });
73
-
74
- const tokens = generateTokens({ id: user.id, email: user.email });
75
- res.json(tokens);
76
- });
77
-
78
- // AUTO ROUTES
79
- const routeList = [];
80
- Object.keys(db).forEach((key) => {
81
- if (["users", "rules"].includes(key)) return;
82
- const isPrivate = db.rules?.[key] === "private";
83
- const route = express.Router();
84
-
85
- // GET /key
86
- route.get("/", async (req, res) => {
87
- const { from, to } = req.query;
88
- let data = db[key];
89
- if (from && to) {
90
- const fromNum = Number(from);
91
- const toNum = Number(to);
92
- data = data.filter((item) => item.id >= fromNum && item.id <= toNum);
93
- }
94
- res.json(data);
95
- });
96
-
97
- // GET /key/:id
98
- route.get("/:id", async (req, res) => {
99
- const id = Number(req.params.id);
100
- const item = db[key].find((i) => i.id === id);
101
- if (!item) return res.status(404).json({ message: "Not found" });
102
- res.json(item);
103
- });
104
-
105
- // POST /key
106
- route.post("/", async (req, res) => {
107
- const newItem = req.body;
108
- if (!newItem || typeof newItem !== "object") return res.status(400).json({ message: "Invalid body" });
109
-
110
- const id = db[key].length ? Math.max(...db[key].map((i) => i.id)) + 1 : 1;
111
- const item = { id, ...newItem };
112
- db[key].push(item);
113
- await saveDB();
114
- res.json(item);
115
- });
116
-
117
- if (isPrivate) {
118
- app.use(`/${key}`, authMiddleware, route);
119
- } else {
120
- app.use(`/${key}`, route);
121
- }
122
-
123
- // routeList에 추가 (권한 정보 포함)
124
- routeList.push({
125
- key,
126
- count: db[key].length,
127
- permission: isPrivate ? "private" : "public"
128
- });
129
- });
130
-
131
- // Index HTML
132
- app.get("/", (req, res) => {
133
- res.render("index", { routeList, port });
134
- });
135
-
136
- app.listen(port, () => {
137
- console.log(`✅ db-json-cli Success! ✧*。٩(ˊᗜˋ*)و✧*。\n`);
138
- console.log(`Index:\nhttp://localhost:${port}/\n\n`);
139
-
140
- console.log("Endpoints:");
141
- routeList.forEach((r) => {
142
- const badge = r.permission === "private" ? "🔒 PRIVATE" : "🔓 PUBLIC";
143
- console.log(`${badge} - http://localhost:${port}/${r.key} (${r.count} items)`);
144
- });
145
- });
146
- };