create-wirejs-app 2.0.14 → 2.0.16
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/package.json
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"dompurify": "^3.2.3",
|
|
12
12
|
"marked": "^15.0.6",
|
|
13
13
|
"wirejs-dom": "^1.0.38",
|
|
14
|
-
"wirejs-resources": "^0.1.
|
|
14
|
+
"wirejs-resources": "^0.1.13"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"wirejs-scripts": "^3.0.
|
|
17
|
+
"wirejs-scripts": "^3.0.11",
|
|
18
18
|
"typescript": "^5.7.3"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AuthenticationService, FileService, withContext } from 'wirejs-resources';
|
|
2
|
-
|
|
3
|
-
const userTodos = new FileService('app', 'userTodoApp');
|
|
4
|
-
const wikiPages = new FileService('app', 'wikiPages');
|
|
5
|
-
const authService = new AuthenticationService('app', 'core-users');
|
|
6
|
-
|
|
7
|
-
export const auth = authService.buildApi();
|
|
8
|
-
|
|
9
|
-
export type Todo = {
|
|
10
|
-
id: string;
|
|
11
|
-
text: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const todos = withContext(context => ({
|
|
15
|
-
async read(): Promise<Todo[]> {
|
|
16
|
-
const user = await auth.requireCurrentUser(context);
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const todos = await userTodos.read(`${user.id}/todos.json`);
|
|
20
|
-
return todos ? JSON.parse(todos) : [];
|
|
21
|
-
} catch (error) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
async write(todos: Todo[]) {
|
|
26
|
-
const user = await auth.requireCurrentUser(context);
|
|
27
|
-
|
|
28
|
-
if (!Array.isArray(todos) || !todos.every(todo =>
|
|
29
|
-
typeof todo.id === 'string'
|
|
30
|
-
&& typeof todo.text === 'string')
|
|
31
|
-
) {
|
|
32
|
-
throw new Error("Invalid todos!");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const finalTodos = todos.map(todo => ({ id: todo.id, text: todo.text }));
|
|
36
|
-
await userTodos.write(`${user.id}/todos.json`, JSON.stringify(finalTodos));
|
|
37
|
-
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
function normalizeWikiPageFilename(page: string) {
|
|
43
|
-
return page.replace(/[^-_a-zA-Z0-9/]/g, '-') + '.md';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const wiki = withContext(context => ({
|
|
47
|
-
async read(page: string) {
|
|
48
|
-
const filename = normalizeWikiPageFilename(page);
|
|
49
|
-
try {
|
|
50
|
-
return await wikiPages.read(filename);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
async write(page: string, content: string) {
|
|
56
|
-
await auth.requireCurrentUser(context);
|
|
57
|
-
|
|
58
|
-
const filename = normalizeWikiPageFilename(page);
|
|
59
|
-
await wikiPages.write(filename, content);
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}));
|