create-wirejs-app 2.0.40-table-resource → 2.0.42-table-resource

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wirejs-app",
3
- "version": "2.0.40-table-resource",
3
+ "version": "2.0.42-table-resource",
4
4
  "description": "Initializes a wirejs package.",
5
5
  "author": "Jon Wire",
6
6
  "license": "MIT",
@@ -11,25 +11,39 @@ const userTodos = new DistributedTable('app', 'userTodos', {
11
11
  key: {
12
12
  partition: { field: 'userId', type: 'string' },
13
13
  sort: { field: 'id', type: 'string' }
14
- }
14
+ },
15
+ indexes: [
16
+ {
17
+ partition: { field: 'userId', type: 'string' },
18
+ sort: { field: 'list', type: 'string' },
19
+ }
20
+ ]
15
21
  });
16
22
 
17
23
  const wikiPages = new FileService('app', 'wikiPages');
18
24
  const authService = new AuthenticationService('app', 'core-users');
19
25
 
20
26
  export const auth = authService.buildApi();
27
+
21
28
  export type Todo = {
22
29
  id: string;
23
30
  text: string;
24
31
  order: number;
32
+ list: string;
25
33
  };
26
34
 
27
35
  export const todos = withContext(context => ({
28
- async read(): Promise<Todo[]> {
36
+ async read(list?: string): Promise<Todo[]> {
29
37
  const user = await auth.requireCurrentUser(context);
30
38
 
31
39
  try {
32
- const todos = userTodos.query({ userId: user.id });
40
+ const todos = userTodos.query({
41
+ by: 'userId-list',
42
+ where: {
43
+ userId: { eq: user.id },
44
+ list: { eq: list ?? 'default' }
45
+ },
46
+ });
33
47
  const todosArray = await Array.fromAsync(todos);
34
48
  return todosArray
35
49
  .sort((a, b) => a.order - b.order)
@@ -37,6 +51,7 @@ export const todos = withContext(context => ({
37
51
  id: todo.id,
38
52
  text: todo.text,
39
53
  order: todo.order,
54
+ list: todo.list || 'default'
40
55
  }));
41
56
  } catch (error) {
42
57
  return [];
@@ -55,6 +70,7 @@ export const todos = withContext(context => ({
55
70
  id: todo.id,
56
71
  text: todo.text,
57
72
  order: todo.order,
73
+ list: todo.list || 'default'
58
74
  };
59
75
  await userTodos.save(finalTodo);
60
76
 
@@ -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.35-table-resource"
14
+ "wirejs-resources": "^0.1.37-table-resource"
15
15
  },
16
16
  "devDependencies": {
17
- "wirejs-scripts": "^3.0.33-table-resource",
17
+ "wirejs-scripts": "^3.0.35-table-resource",
18
18
  "typescript": "^5.7.3"
19
19
  },
20
20
  "scripts": {
@@ -1,9 +1,4 @@
1
- import { html, hydrate } from 'wirejs-dom/v2';
2
-
3
- async function App() {
4
- return html`<div id='app'>
5
- </div>`;
6
- }
1
+ import { html } from 'wirejs-dom/v2';
7
2
 
8
3
  export async function generate() {
9
4
  const page = html`
@@ -3,14 +3,6 @@ import { accountMenu } from '../components/account-menu.js';
3
3
  import { auth, todos, Todo } from 'my-api';
4
4
 
5
5
  function Todos() {
6
- const add = async (todo: Todo) => {
7
- try {
8
- await todos.save(null, todo);
9
- } catch (error) {
10
- alert(error);
11
- }
12
- }
13
-
14
6
  const remove = (todo: Todo) => {
15
7
  self.data.todos = self.data.todos.filter(t => t.id !== todo.id);
16
8
  todos.remove(null, todo.id);
@@ -31,21 +23,22 @@ function Todos() {
31
23
  event.preventDefault();
32
24
  const todo = {
33
25
  id: newid(),
34
- text: self.data.newTodo,
26
+ list: 'default',
27
+ text: self.data.newTodoText,
35
28
  order: (self.data.todos[
36
29
  self.data.todos.length - 1
37
30
  ]?.order ?? 0) + 1,
38
31
  };
39
32
  self.data.todos.push(todo);
40
- self.data.newTodo = '';
41
- add(todo);
33
+ self.data.newTodoText = '';
34
+ todos.save(null, todo).catch((e: any) => alert(e.message));
42
35
  }}>
43
- <input type='text' value=${attribute('newTodo', '' as string)} />
36
+ <input type='text' value=${attribute('newTodoText', '' as string)} />
44
37
  <input type='submit' value='Add' />
45
38
  </form>
46
39
  </div>
47
40
  <div>`.onadd(async self => {
48
- self.data.todos = await todos.read(null);
41
+ self.data.todos = await todos.read(null, 'default');
49
42
  });
50
43
  return self;
51
44
  }