create-tinybase 0.1.4 → 0.2.0

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 (93) hide show
  1. package/cli.js +2 -2
  2. package/package.json +2 -2
  3. package/templates/{base/README.md.hbs → README.md.hbs} +1 -0
  4. package/templates/{base → client}/eslint.config.js.hbs +5 -0
  5. package/templates/client/index.html.hbs +182 -0
  6. package/templates/{base → client}/package.json.hbs +18 -2
  7. package/templates/client/public/favicon.svg +8 -0
  8. package/templates/client/src/chat/App.tsx.hbs +40 -0
  9. package/templates/client/src/chat/ChatStore.tsx.hbs +70 -0
  10. package/templates/client/src/chat/Message.tsx.hbs +21 -0
  11. package/templates/client/src/chat/MessageInput.tsx.hbs +42 -0
  12. package/templates/client/src/chat/Messages.tsx.hbs +29 -0
  13. package/templates/client/src/chat/SettingsStore.tsx.hbs +34 -0
  14. package/templates/client/src/chat/UsernameInput.tsx.hbs +22 -0
  15. package/templates/client/src/chat/app.ts.hbs +39 -0
  16. package/templates/client/src/chat/chatStore.ts.hbs +50 -0
  17. package/templates/client/src/chat/message.css.hbs +20 -0
  18. package/templates/client/src/chat/message.ts.hbs +27 -0
  19. package/templates/client/src/chat/messageInput.css.hbs +6 -0
  20. package/templates/client/src/chat/messageInput.ts.hbs +42 -0
  21. package/templates/client/src/chat/messages.css.hbs +6 -0
  22. package/templates/client/src/chat/messages.ts.hbs +33 -0
  23. package/templates/client/src/chat/settingsStore.ts.hbs +19 -0
  24. package/templates/client/src/chat/usernameInput.css.hbs +14 -0
  25. package/templates/client/src/chat/usernameInput.ts.hbs +30 -0
  26. package/templates/client/src/drawing/App.tsx.hbs +36 -0
  27. package/templates/client/src/drawing/BrushSize.tsx.hbs +22 -0
  28. package/templates/client/src/drawing/Canvas.tsx.hbs +100 -0
  29. package/templates/client/src/drawing/CanvasStore.tsx.hbs +62 -0
  30. package/templates/client/src/drawing/ColorPicker.tsx.hbs +24 -0
  31. package/templates/client/src/drawing/DrawingControls.tsx.hbs +24 -0
  32. package/templates/client/src/drawing/SettingsStore.tsx.hbs +36 -0
  33. package/templates/client/src/drawing/app.ts.hbs +20 -0
  34. package/templates/client/src/drawing/brushSize.css.hbs +21 -0
  35. package/templates/client/src/drawing/brushSize.ts.hbs +33 -0
  36. package/templates/client/src/drawing/canvas.css.hbs +8 -0
  37. package/templates/client/src/drawing/canvas.ts.hbs +103 -0
  38. package/templates/client/src/drawing/canvasStore.ts.hbs +42 -0
  39. package/templates/client/src/drawing/colorPicker.css.hbs +21 -0
  40. package/templates/client/src/drawing/colorPicker.ts.hbs +34 -0
  41. package/templates/client/src/drawing/drawingControls.css.hbs +12 -0
  42. package/templates/client/src/drawing/drawingControls.ts.hbs +26 -0
  43. package/templates/client/src/drawing/settingsStore.ts.hbs +21 -0
  44. package/templates/client/src/game/App.tsx.hbs +28 -0
  45. package/templates/client/src/game/Board.tsx.hbs +27 -0
  46. package/templates/client/src/game/Game.tsx.hbs +78 -0
  47. package/templates/client/src/game/GameStatus.tsx.hbs +21 -0
  48. package/templates/client/src/game/Square.tsx.hbs +23 -0
  49. package/templates/client/src/game/Store.tsx.hbs +67 -0
  50. package/templates/client/src/game/app.ts.hbs +12 -0
  51. package/templates/client/src/game/board.css.hbs +13 -0
  52. package/templates/client/src/game/board.ts.hbs +39 -0
  53. package/templates/client/src/game/game.ts.hbs +74 -0
  54. package/templates/client/src/game/gameStatus.css.hbs +21 -0
  55. package/templates/client/src/game/gameStatus.ts.hbs +27 -0
  56. package/templates/client/src/game/square.css.hbs +38 -0
  57. package/templates/client/src/game/square.ts.hbs +11 -0
  58. package/templates/client/src/game/store.ts.hbs +47 -0
  59. package/templates/client/src/index.tsx.hbs +24 -0
  60. package/templates/client/src/shared/Button.tsx.hbs +16 -0
  61. package/templates/client/src/shared/Input.tsx.hbs +16 -0
  62. package/templates/client/src/shared/button.css.hbs +25 -0
  63. package/templates/client/src/shared/button.ts.hbs +16 -0
  64. package/templates/client/src/shared/config.ts.hbs +9 -0
  65. package/templates/client/src/shared/input.css.hbs +22 -0
  66. package/templates/client/src/shared/input.ts.hbs +17 -0
  67. package/templates/client/src/todos/App.tsx.hbs +32 -0
  68. package/templates/client/src/todos/Store.tsx.hbs +70 -0
  69. package/templates/client/src/todos/TodoInput.tsx.hbs +30 -0
  70. package/templates/client/src/todos/TodoItem.tsx.hbs +20 -0
  71. package/templates/client/src/todos/TodoList.tsx.hbs +18 -0
  72. package/templates/client/src/todos/app.ts.hbs +23 -0
  73. package/templates/client/src/todos/store.ts.hbs +49 -0
  74. package/templates/client/src/todos/todoInput.css.hbs +9 -0
  75. package/templates/client/src/todos/todoInput.ts.hbs +38 -0
  76. package/templates/client/src/todos/todoItem.css.hbs +33 -0
  77. package/templates/client/src/todos/todoItem.ts.hbs +28 -0
  78. package/templates/client/src/todos/todoList.css.hbs +14 -0
  79. package/templates/client/src/todos/todoList.ts.hbs +38 -0
  80. package/templates/{base → client}/vite.config.js.hbs +5 -3
  81. package/templates/package.json.hbs +38 -0
  82. package/templates/server/index-do.ts.hbs +22 -0
  83. package/templates/server/index-node.ts.hbs +8 -0
  84. package/templates/server/package.json.hbs +51 -0
  85. package/templates/server/tsconfig.json.hbs +13 -0
  86. package/templates/server/wrangler.toml.hbs +12 -0
  87. package/templates/base/index.html.hbs +0 -17
  88. package/templates/base/tsconfig.node.json.hbs +0 -9
  89. package/templates/src/App.tsx.hbs +0 -24
  90. package/templates/src/index.css.hbs +0 -110
  91. package/templates/src/index.tsx.hbs +0 -48
  92. /package/templates/{base → client}/.prettierrc.hbs +0 -0
  93. /package/templates/{base → client}/tsconfig.json.hbs +0 -0
@@ -0,0 +1,38 @@
1
+ {{includeFile template="client/src/todos/todoList.css.hbs" output="client/src/todoList.css"}}
2
+ import './todoList.css';
3
+ import {type TodosStore} from './store';
4
+
5
+ {{includeFile template="client/src/todos/todoItem.ts.hbs" output="client/src/todoItem.{{ext}}"}}
6
+ import {createTodoItem} from './todoItem';
7
+
8
+ export const createTodoList = (store: TodosStore): HTMLDivElement => {
9
+ const list = document.createElement('div');
10
+ list.id = 'todoList';
11
+
12
+ const render = () => {
13
+ const todos = store.getTable('todos');
14
+ const todoIds = Object.keys(todos);
15
+
16
+ list.innerHTML = '';
17
+ todoIds.forEach((id) => {
18
+ const todo = todos[id];
19
+ const item = createTodoItem(
20
+ id,
21
+ todo.text,
22
+ todo.completed,
23
+ () => {
24
+ store.setPartialRow('todos', id, {completed: !todo.completed});
25
+ },
26
+ () => {
27
+ store.delRow('todos', id);
28
+ }
29
+ );
30
+ list.appendChild(item);
31
+ });
32
+ };
33
+
34
+ store.addTablesListener(render);
35
+ render();
36
+
37
+ return list;
38
+ };
@@ -1,10 +1,12 @@
1
1
  {{addImport "import {defineConfig} from 'vite';"}}
2
- {{#if isReact}}
2
+ {{#if react}}
3
3
  {{addImport "import react from '@vitejs/plugin-react';"}}
4
4
  {{/if}}
5
5
 
6
6
  export default defineConfig({
7
- {{#if isReact}}
8
- plugins: [react()],
7
+ {{#if react}}
8
+ plugins: [react({
9
+ jsxRuntime: 'automatic',
10
+ })],
9
11
  {{/if}}
10
12
  });
@@ -0,0 +1,38 @@
1
+ {{includeFile template="README.md.hbs" output="README.md"}}
2
+ {
3
+ "name": "{{projectName}}",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "scripts": {
7
+ {{#list}}
8
+ {{#if server}}
9
+ "dev": "concurrently \"npm run dev -w client\" \"npm run dev -w server\""
10
+ "dev:client": "npm run dev -w client"
11
+ "dev:server": "npm run dev -w server"
12
+ {{else}}
13
+ "dev": "npm run dev -w client"
14
+ {{/if}}
15
+ "build": "npm run build -w client"
16
+ "preview": "npm run preview -w client"
17
+ {{/list}}
18
+ },
19
+ {{#if server}}
20
+ "workspaces": ["client", "server"],
21
+ {{else}}
22
+ "workspaces": ["client"],
23
+ {{/if}}
24
+ "devDependencies": {
25
+ {{#list}}
26
+ {{#if server}}
27
+ "concurrently": "^9.1.2"
28
+ {{/if}}
29
+ {{/list}}
30
+ }
31
+ }
32
+ {{#if server}}
33
+ {{includeFile template="server/package.json.hbs" output="server/package.json"}}
34
+ {{/if}}
35
+ {{#if prettier}}
36
+ {{includeFile template="client/.prettierrc.hbs" output=".prettierrc"}}
37
+ {{/if}}
38
+ {{includeFile template="client/package.json.hbs" output="client/package.json"}}
@@ -0,0 +1,22 @@
1
+ import {Id, IdAddedOrRemoved} from 'tinybase';
2
+ import {
3
+ getWsServerDurableObjectFetch,
4
+ WsServerDurableObject,
5
+ } from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
6
+
7
+ export class TinyBaseDurableObject extends WsServerDurableObject {
8
+ onPathId(pathId: Id, addedOrRemoved: IdAddedOrRemoved) {
9
+ console.info((addedOrRemoved ? 'Added' : 'Removed') + ` path ${pathId}`);
10
+ }
11
+
12
+ onClientId(pathId: Id, clientId: Id, addedOrRemoved: IdAddedOrRemoved) {
13
+ console.info(
14
+ (addedOrRemoved ? 'Added' : 'Removed') +
15
+ ` client ${clientId} on path ${pathId}`,
16
+ );
17
+ }
18
+ }
19
+
20
+ export default {
21
+ fetch: getWsServerDurableObjectFetch('TinyBaseDurableObjects'),
22
+ };
@@ -0,0 +1,8 @@
1
+ import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
2
+ import {WebSocketServer} from 'ws';
3
+
4
+ const PORT = 8043;
5
+
6
+ const wsServer = createWsServer(new WebSocketServer({port: PORT}));
7
+
8
+ console.log(`WebSocket server running on ws://localhost:${PORT}`);
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "{{projectName}}-server",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.ts",
6
+ "scripts": {
7
+ {{#list}}
8
+ {{#if (eq serverType "node")}}
9
+ {{includeFile template="server/index-node.ts.hbs" output="server/index.ts"}}
10
+ "dev": "tsx watch index.ts"
11
+ "start": "node index.js"
12
+ {{else}}
13
+ {{includeFile template="server/index-do.ts.hbs" output="server/index.ts"}}
14
+ {{includeFile template="server/wrangler.toml.hbs" output="server/wrangler.toml"}}
15
+ {{#if typescript}}
16
+ {{includeFile template="server/tsconfig.json.hbs" output="server/tsconfig.json"}}
17
+ {{/if}}
18
+ "deploy": "wrangler deploy"
19
+ "dev": "wrangler dev"
20
+ "start": "wrangler dev"
21
+ {{/if}}
22
+ {{/list}}
23
+ },
24
+ "dependencies": {
25
+ {{#list}}
26
+ "tinybase": "^7.3.1"
27
+ {{#if (eq serverType "node")}}
28
+ "ws": "^8.18.3"
29
+ {{/if}}
30
+ {{/list}}
31
+ },
32
+ "devDependencies": {
33
+ {{#list}}
34
+ {{#if (eq serverType "node")}}
35
+ "@types/ws": "^8.18.1"
36
+ {{else}}
37
+ "@cloudflare/workers-types": "^4.20250828.1"
38
+ {{/if}}
39
+ {{#if typescript}}
40
+ "typescript": "^5.9.3"
41
+ {{#if (eq serverType "node")}}
42
+ "tsx": "^4.19.3"
43
+ {{/if}}
44
+ {{/if}}
45
+ {{#if (eq serverType "durable-objects")}}
46
+ "wrangler": "^4.33.1"
47
+ {{/if}}
48
+ {{/list}}
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "lib": ["ES2020"],
6
+ "types": ["@cloudflare/workers-types"],
7
+ "moduleResolution": "node",
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "strict": true
11
+ },
12
+ "include": ["index.ts"]
13
+ }
@@ -0,0 +1,12 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "{{projectName}}-server"
3
+ main = "index.ts"
4
+ compatibility_date = "2024-10-11"
5
+
6
+ [[durable_objects.bindings]]
7
+ name = "TinyBaseDurableObjects"
8
+ class_name = "TinyBaseDurableObject"
9
+
10
+ [[migrations]]
11
+ tag = "v1"
12
+ new_classes = ["TinyBaseDurableObject"]
@@ -1,17 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>TinyBase</title>
8
- </head>
9
-
10
- <body>
11
- {{#if react}}
12
- <div id="app"></div>
13
- {{/if}}
14
- <script type="module" src="/src/index.{{ext}}"></script>
15
- </body>
16
-
17
- </html>
@@ -1,9 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "ESNext",
4
- "moduleResolution": "bundler",
5
- "allowSyntheticDefaultImports": true,
6
- "strict": true,
7
- "skipLibCheck": true
8
- }
9
- }
@@ -1,24 +0,0 @@
1
- {{addImport "import {createStore} from 'tinybase';"}}
2
- {{addImport "import {Provider, useValue} from 'tinybase/ui-react';"}}
3
-
4
- const store = createStore().setValue('count', 0);
5
-
6
- export const App = () => (
7
- <Provider store={store}>
8
- <h1>TinyBase + React</h1>
9
- <Counter />
10
- </Provider>
11
- );
12
-
13
- const Counter = () => {
14
- const count = useValue('count', store);
15
-
16
- return (
17
- <div>
18
- <p>Count: {count}</p>
19
- <button onClick={() => store.setValue('count', (c: number) => c + 1)}>
20
- Increment
21
- </button>
22
- </div>
23
- );
24
- };
@@ -1,110 +0,0 @@
1
- body {
2
- color: #bbb;
3
- background: #111;
4
- font-family: 'Inter', sans-serif;
5
- user-select: none;
6
- }
7
-
8
- #app {
9
- max-width: 40rem;
10
- margin: 2rem auto;
11
- display: grid;
12
- grid-template-columns: 1fr;
13
- column-gap: 2rem;
14
- align-items: start;
15
- row-gap: 1rem;
16
- }
17
-
18
- a {
19
- color: #bbb;
20
- }
21
-
22
- h1 {
23
- font-weight: 600;
24
- img {
25
- margin-right: 1rem;
26
- height: 2.5rem;
27
- vertical-align: text-bottom;
28
- }
29
- }
30
-
31
- h2 {
32
- text-align: center;
33
- font-weight: 800;
34
- font-size: 1.3rem;
35
- margin: 1rem 0 0;
36
- }
37
-
38
- #buttons {
39
- border: solid #666;
40
- border-width: 1px 0;
41
- text-align: center;
42
- }
43
-
44
- #buttons button {
45
- border: 1px solid #666;
46
- border-radius: 0.25rem;
47
- padding: 0.5rem 1rem;
48
- background: #222;
49
- color: #fff;
50
- font-family: inherit;
51
- font-weight: 800;
52
- font-size: 0.8rem;
53
- width: 10rem;
54
- margin: 1rem;
55
- }
56
- #buttons button:hover {
57
- border-color: #d81b60;
58
- }
59
-
60
- table {
61
- border-collapse: collapse;
62
- font-size: inherit;
63
- line-height: inherit;
64
- margin-top: 0.5rem;
65
- table-layout: fixed;
66
- width: 100%;
67
- margin-bottom: 2rem;
68
- caption-side: bottom;
69
- }
70
- table caption {
71
- text-align: left;
72
- button {
73
- border: 0;
74
- margin-right: 0.25rem;
75
- }
76
- }
77
- table caption button {
78
- line-height: 0.7rem;
79
- margin: 0 0.25rem 0 0;
80
- vertical-align: middle;
81
- }
82
- th,
83
- td {
84
- padding: 0.25rem 0.5rem 0.25rem 0;
85
- text-align: left;
86
- }
87
- thead th,
88
- thead td {
89
- border: solid #999;
90
- border-width: 1px 0;
91
- }
92
- tbody th,
93
- tbody td {
94
- border-bottom: 1px solid #333;
95
- }
96
-
97
- table.sortedTable thead th {
98
- cursor: pointer;
99
- }
100
-
101
- @media (min-width: 40rem) {
102
- #app {
103
- grid-template-columns: 1fr 1fr;
104
- }
105
- header,
106
- p,
107
- #buttons {
108
- grid-column: span 2;
109
- }
110
- }
@@ -1,48 +0,0 @@
1
- {{addImport "import './index.css';"}}
2
-
3
- {{#if react}}
4
- {{addImport "import ReactDOM from 'react-dom/client';"}}
5
- {{addImport "import {App} from './App';"}}
6
-
7
- addEventListener('load', () =>
8
- ReactDOM.createRoot(document.getElementById('app')!).render(<App />),
9
- );
10
-
11
- {{else}}
12
- {{addImport "import {createStore} from 'tinybase';"}}
13
-
14
- const onClick = (id: string, onClick: () => void) =>
15
- document.getElementById(id)!.addEventListener('click', onClick);
16
-
17
- const updateJson = (id: string, content: unknown) =>
18
- (document.getElementById(id)!.innerText = JSON.stringify(content, null, 2));
19
-
20
- const getRandom = (max = 100) => Math.floor(Math.random() * max);
21
-
22
- addEventListener('load', () => {
23
- const store = createStore();
24
-
25
- onClick('countButton', () => store.setValue('counter', (value) => value + 1));
26
- onClick('randomButton', () => store.setValue('random', getRandom()));
27
- onClick('addPetButton', () =>
28
- store.addRow('pets', {
29
- name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
30
- species: store.getRowIds('species')[getRandom(5)],
31
- }),
32
- );
33
-
34
- store.addValuesListener(() => updateJson('valuesJson', store.getValues()));
35
- store.addTablesListener(() => updateJson('tablesJson', store.getTables()));
36
-
37
- store
38
- .setValue('counter', 0)
39
- .setRow('pets', '0', {name: 'fido', species: 'dog'})
40
- .setTable('species', {
41
- dog: {price: 5},
42
- cat: {price: 4},
43
- fish: {price: 2},
44
- worm: {price: 1},
45
- parrot: {price: 3},
46
- });
47
- });
48
- {{/if}}
File without changes
File without changes