json-server 1.0.0-beta.1 → 1.0.0-beta.12
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 -44
- package/README.md +140 -88
- package/lib/adapters/normalized-adapter.js +31 -0
- package/lib/app.js +81 -51
- package/lib/bin.js +54 -50
- package/lib/matches-where.js +87 -0
- package/lib/paginate.js +24 -0
- package/lib/parse-where.js +56 -0
- package/lib/random-id.js +4 -0
- package/lib/service.js +18 -190
- package/lib/where-operators.js +15 -0
- package/package.json +58 -44
- package/schema.json +10 -0
- package/views/index.html +73 -75
- package/lib/app.d.ts +0 -8
- package/lib/bin.d.ts +0 -2
- package/lib/observer.d.ts +0 -11
- package/lib/service.d.ts +0 -38
- /package/lib/{observer.js → adapters/observer.js} +0 -0
package/package.json
CHANGED
|
@@ -1,59 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-server",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.12",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"JSON",
|
|
7
|
+
"server",
|
|
8
|
+
"fake",
|
|
9
|
+
"REST",
|
|
10
|
+
"API",
|
|
11
|
+
"prototyping",
|
|
12
|
+
"mock",
|
|
13
|
+
"mocking",
|
|
14
|
+
"test",
|
|
15
|
+
"testing",
|
|
16
|
+
"rest",
|
|
17
|
+
"data",
|
|
18
|
+
"dummy"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "typicode <typicode@gmail.com>",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/typicode/json-server.git"
|
|
25
|
+
},
|
|
6
26
|
"bin": {
|
|
7
27
|
"json-server": "lib/bin.js"
|
|
8
28
|
},
|
|
9
|
-
"types": "lib",
|
|
10
29
|
"files": [
|
|
11
30
|
"lib",
|
|
12
|
-
"views"
|
|
31
|
+
"views",
|
|
32
|
+
"schema.json"
|
|
13
33
|
],
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/typicode/json-server.git"
|
|
34
|
+
"type": "module",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@tinyhttp/app": "^3.0.1",
|
|
37
|
+
"@tinyhttp/cors": "^2.0.1",
|
|
38
|
+
"@tinyhttp/logger": "^2.1.0",
|
|
39
|
+
"chalk": "^5.6.2",
|
|
40
|
+
"chokidar": "^5.0.0",
|
|
41
|
+
"dot-prop": "^10.1.0",
|
|
42
|
+
"eta": "^4.5.0",
|
|
43
|
+
"inflection": "^3.0.2",
|
|
44
|
+
"json5": "^2.2.3",
|
|
45
|
+
"lowdb": "^7.0.1",
|
|
46
|
+
"milliparsec": "^5.1.0",
|
|
47
|
+
"sirv": "^3.0.2",
|
|
48
|
+
"sort-on": "^7.0.0"
|
|
31
49
|
},
|
|
32
50
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"@types/node": "^20.14.1",
|
|
36
|
-
"@typicode/eslint-config": "^2.0.0",
|
|
37
|
-
"concurrently": "^8.2.2",
|
|
51
|
+
"@types/node": "^25.0.8",
|
|
52
|
+
"concurrently": "^9.2.1",
|
|
38
53
|
"get-port": "^7.1.0",
|
|
39
|
-
"husky": "^9.
|
|
54
|
+
"husky": "^9.1.7",
|
|
55
|
+
"oxfmt": "^0.24.0",
|
|
56
|
+
"oxlint": "^1.39.0",
|
|
40
57
|
"tempy": "^3.1.0",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"typescript": "^5.4.5"
|
|
58
|
+
"type-fest": "^5.4.0",
|
|
59
|
+
"typescript": "^5.9.3"
|
|
44
60
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"sirv": "^2.0.4",
|
|
57
|
-
"sort-on": "^6.0.0"
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=22.12.0"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"dev": "node --watch --experimental-strip-types src/bin.ts fixtures/db.json",
|
|
66
|
+
"build": "rm -rf lib && tsc",
|
|
67
|
+
"typecheck": "tsc --noEmit",
|
|
68
|
+
"test": "node --experimental-strip-types --test src/*.test.ts",
|
|
69
|
+
"lint": "oxlint src",
|
|
70
|
+
"fmt": "oxfmt",
|
|
71
|
+
"fmt:check": "oxfmt --check"
|
|
58
72
|
}
|
|
59
|
-
}
|
|
73
|
+
}
|
package/schema.json
ADDED
package/views/index.html
CHANGED
|
@@ -1,97 +1,95 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!doctype html>
|
|
2
2
|
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<style>
|
|
7
|
+
html {
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
line-height: 1.5;
|
|
10
|
+
background-color: #fff;
|
|
11
|
+
color: #000;
|
|
12
|
+
}
|
|
3
13
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
line-height: 1.5;
|
|
11
|
-
background-color: #fff;
|
|
12
|
-
color: #000;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
body {
|
|
16
|
-
margin: 0 auto;
|
|
17
|
-
max-width: 720px;
|
|
18
|
-
padding: 0 16px;
|
|
19
|
-
font-family: sans-serif;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
a {
|
|
23
|
-
color: #db2777;
|
|
24
|
-
text-decoration: none;
|
|
25
|
-
}
|
|
14
|
+
body {
|
|
15
|
+
margin: 0 auto;
|
|
16
|
+
max-width: 720px;
|
|
17
|
+
padding: 0 16px;
|
|
18
|
+
font-family: sans-serif;
|
|
19
|
+
}
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
a {
|
|
22
|
+
color: #db2777;
|
|
23
|
+
text-decoration: none;
|
|
24
|
+
}
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
header {
|
|
27
|
+
margin-bottom: 32px;
|
|
28
|
+
padding: 16px 0;
|
|
29
|
+
}
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
nav {
|
|
32
|
+
display: flex;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
}
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
list-style: none;
|
|
45
|
-
}
|
|
36
|
+
nav div a {
|
|
37
|
+
margin-left: 16px;
|
|
38
|
+
}
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
ul {
|
|
41
|
+
margin: 0;
|
|
42
|
+
padding: 0;
|
|
43
|
+
list-style: none;
|
|
44
|
+
}
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
html {
|
|
54
|
-
background-color: #1e293b;
|
|
55
|
-
color: #fff;
|
|
46
|
+
li {
|
|
47
|
+
margin-bottom: 8px;
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
|
|
50
|
+
/* Dark mode styles */
|
|
51
|
+
@media (prefers-color-scheme: dark) {
|
|
52
|
+
html {
|
|
53
|
+
background-color: #1e293b;
|
|
54
|
+
color: #fff;
|
|
55
|
+
}
|
|
59
56
|
|
|
57
|
+
a {
|
|
58
|
+
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
</style>
|
|
64
|
-
</head>
|
|
60
|
+
</style>
|
|
61
|
+
</head>
|
|
65
62
|
|
|
66
|
-
<body>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
<body>
|
|
64
|
+
<header>
|
|
65
|
+
<nav>
|
|
66
|
+
<strong>JSON Server</strong>
|
|
67
|
+
<div>
|
|
68
|
+
<a href="https://github.com/typicode/json-server">Docs</a>
|
|
69
|
+
<a href="https://github.com/sponsors/typicode">♡ Sponsor</a>
|
|
70
|
+
</div>
|
|
71
|
+
</nav>
|
|
72
|
+
</header>
|
|
73
|
+
<main class="my-12">
|
|
74
|
+
<p
|
|
75
|
+
class="bg-gradient-to-r from-purple-500 via-pink-500 to-red-500 text-transparent bg-clip-text"
|
|
76
|
+
>
|
|
77
|
+
✧*。٩(ˊᗜˋ*)و✧*。
|
|
78
|
+
</p>
|
|
79
|
+
<% if (Object.keys(it.data).length===0) { %>
|
|
79
80
|
<p>No resources found in JSON file</p>
|
|
80
|
-
|
|
81
|
-
<% Object.entries(it.data).forEach(function([name]) { %>
|
|
81
|
+
<% } %> <% Object.entries(it.data).forEach(function([name]) { %>
|
|
82
82
|
<ul>
|
|
83
83
|
<li>
|
|
84
84
|
<a href="<%= name %>">/<%= name %></a>
|
|
85
85
|
<span>
|
|
86
|
-
<% if (Array.isArray(it.data[name])) { %>
|
|
87
|
-
|
|
88
|
-
<%= it.data[name].length> 1 ? 'items' : 'item' %>
|
|
86
|
+
<% if (Array.isArray(it.data[name])) { %> - <%= it.data[name].length %> <%=
|
|
87
|
+
it.data[name].length> 1 ? 'items' : 'item' %>
|
|
89
88
|
</span>
|
|
90
89
|
<% } %>
|
|
91
90
|
</li>
|
|
92
91
|
</ul>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
</body>
|
|
96
|
-
|
|
97
|
-
</html>
|
|
92
|
+
<% }) %>
|
|
93
|
+
</main>
|
|
94
|
+
</body>
|
|
95
|
+
</html>
|
package/lib/app.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { App } from '@tinyhttp/app';
|
|
2
|
-
import { Low } from 'lowdb';
|
|
3
|
-
import { Data } from './service.js';
|
|
4
|
-
export type AppOptions = {
|
|
5
|
-
logger?: boolean;
|
|
6
|
-
static?: string[];
|
|
7
|
-
};
|
|
8
|
-
export declare function createApp(db: Low<Data>, options?: AppOptions): App<import("@tinyhttp/app").Request, import("@tinyhttp/app").Response<unknown>>;
|
package/lib/bin.d.ts
DELETED
package/lib/observer.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Adapter } from 'lowdb';
|
|
2
|
-
export declare class Observer<T> {
|
|
3
|
-
#private;
|
|
4
|
-
onReadStart: () => void;
|
|
5
|
-
onReadEnd: (data: T | null) => void;
|
|
6
|
-
onWriteStart: () => void;
|
|
7
|
-
onWriteEnd: () => void;
|
|
8
|
-
constructor(adapter: Adapter<T>);
|
|
9
|
-
read(): Promise<T | null>;
|
|
10
|
-
write(arg: T): Promise<void>;
|
|
11
|
-
}
|
package/lib/service.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Low } from 'lowdb';
|
|
2
|
-
export type Item = Record<string, unknown>;
|
|
3
|
-
export type Data = Record<string, Item[] | Item>;
|
|
4
|
-
export declare function isItem(obj: unknown): obj is Item;
|
|
5
|
-
export declare function isData(obj: unknown): obj is Record<string, Item[]>;
|
|
6
|
-
export type PaginatedItems = {
|
|
7
|
-
first: number;
|
|
8
|
-
prev: number | null;
|
|
9
|
-
next: number | null;
|
|
10
|
-
last: number;
|
|
11
|
-
pages: number;
|
|
12
|
-
items: number;
|
|
13
|
-
data: Item[];
|
|
14
|
-
};
|
|
15
|
-
export declare class Service {
|
|
16
|
-
#private;
|
|
17
|
-
constructor(db: Low<Data>);
|
|
18
|
-
has(name: string): boolean;
|
|
19
|
-
findById(name: string, id: string, query: {
|
|
20
|
-
_embed?: string[] | string;
|
|
21
|
-
}): Item | undefined;
|
|
22
|
-
find(name: string, query?: {
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
_embed?: string | string[];
|
|
25
|
-
_sort?: string;
|
|
26
|
-
_start?: number;
|
|
27
|
-
_end?: number;
|
|
28
|
-
_limit?: number;
|
|
29
|
-
_page?: number;
|
|
30
|
-
_per_page?: number;
|
|
31
|
-
}): Item[] | PaginatedItems | Item | undefined;
|
|
32
|
-
create(name: string, data?: Omit<Item, 'id'>): Promise<Item | undefined>;
|
|
33
|
-
update(name: string, body?: Item): Promise<Item | undefined>;
|
|
34
|
-
patch(name: string, body?: Item): Promise<Item | undefined>;
|
|
35
|
-
updateById(name: string, id: string, body?: Item): Promise<Item | undefined>;
|
|
36
|
-
patchById(name: string, id: string, body?: Item): Promise<Item | undefined>;
|
|
37
|
-
destroyById(name: string, id: string, dependent?: string | string[]): Promise<Item | undefined>;
|
|
38
|
-
}
|
|
File without changes
|