@alstar/studio 0.0.0-beta.7 → 0.0.0-beta.8

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/api/api-key.ts CHANGED
@@ -7,10 +7,9 @@ import crypto from 'node:crypto'
7
7
 
8
8
  import { stripNewlines } from '../utils/strip-newlines.ts'
9
9
  import { sql } from '../utils/sql.ts'
10
- import { type Structure } from '../types.ts'
11
10
  import Settings from '../components/Settings.ts'
12
11
 
13
- export default (structure: Structure) => {
12
+ export default () => {
14
13
  const app = new Hono<{ Bindings: HttpBindings }>()
15
14
 
16
15
  app.post('/api-key', async (c) => {
package/api/backup.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { type HttpBindings } from '@hono/node-server'
2
+ import { Hono } from 'hono'
3
+ import { streamSSE } from 'hono/streaming'
4
+ import { DatabaseSync } from 'node:sqlite'
5
+
6
+ import { stripNewlines } from '../utils/strip-newlines.ts'
7
+ import { db } from '@alstar/db'
8
+
9
+ export default () => {
10
+ const app = new Hono<{ Bindings: HttpBindings }>()
11
+
12
+ app.post('/backup', async (c) => {
13
+ // const totalPagesTransferred = await backup(db.database, './backups/backup.db', {
14
+ // rate: 1, // Copy one page at a time.
15
+ // progress: ({ totalPages, remainingPages }) => {
16
+ // console.log('Backup in progress', { totalPages, remainingPages })
17
+ // },
18
+ // })
19
+
20
+ // console.log('Backup completed', totalPagesTransferred)
21
+
22
+ return c.html('good')
23
+
24
+ // return streamSSE(c, async (stream) => {
25
+ // await stream.writeSSE({
26
+ // event: 'datastar-patch-signals',
27
+ // data: `signals {}`,
28
+ // })
29
+
30
+ // await stream.writeSSE({
31
+ // event: 'datastar-patch-elements',
32
+ // data: `elements ${stripNewlines(Settings())}`,
33
+ // })
34
+ // })
35
+ })
36
+
37
+ return app
38
+ }
package/api/index.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import block from './block.ts'
2
2
  import apiKey from './api-key.ts'
3
+ import type { Structure } from '../types.ts'
4
+ import backup from './backup.ts'
3
5
 
4
- export const api = (structure) => {
6
+ export const api = (structure: Structure) => {
5
7
  const app = block(structure)
6
-
7
- app.route('/', apiKey(structure))
8
+
9
+ app.route('/', apiKey())
10
+ app.route('/', backup())
8
11
 
9
12
  return app
10
13
  }
@@ -0,0 +1,10 @@
1
+ import { html } from 'hono/html'
2
+
3
+ export default () => {
4
+ return html`<article>
5
+ <header>Backup</header>
6
+ <form data-on-submit="@post('/admin/api/backup', { contentType: 'form' })">
7
+ <button type="submit">Backup database</button>
8
+ </form>
9
+ </article>`
10
+ }
@@ -8,15 +8,15 @@ export default (props: {
8
8
  id?: number
9
9
  structure: BlockDef
10
10
  }) => {
11
- const { entryId, parentId, structure, id } = props
11
+ const { entryId, parentId, structure } = props
12
12
 
13
13
  const entries = Object.entries(structure.fields)
14
14
 
15
- return entries.map(([name, field]) => {
16
- try {
17
- return Render({ entryId, parentId, structure: field, name })
18
- } catch (error) {
19
- return html`<p>Cound not render: "${name}"</p>`
20
- }
21
- }).join('')
15
+ return html`${entries.map(([name, field]) => {
16
+ try {
17
+ return Render({ entryId, parentId, structure: field, name })
18
+ } catch (error) {
19
+ return html`<p>Cound not render: "${name}"</p>`
20
+ }
21
+ })}`
22
22
  }
@@ -21,7 +21,7 @@ export default (props: {
21
21
  id?: number
22
22
  name: string
23
23
  sortOrder?: number
24
- }): HtmlEscapedString | Promise<HtmlEscapedString> | string => {
24
+ }): HtmlEscapedString | Promise<HtmlEscapedString> => {
25
25
  const { entryId, parentId, structure, name, id } = props
26
26
 
27
27
  if (!structure) return html`<p>No block</p>`
@@ -2,6 +2,7 @@ import { db } from '@alstar/db'
2
2
  import { html } from 'hono/html'
3
3
  import { sql } from '../utils/sql.ts'
4
4
  import * as icons from './icons.ts'
5
+ import Backup from './Backup.ts'
5
6
 
6
7
  export default () => {
7
8
  const apiKeys = db.database
@@ -93,6 +94,8 @@ export default () => {
93
94
  </article>
94
95
  </dialog>
95
96
  </article>
97
+
98
+ ${Backup()}
96
99
  </div>
97
100
  `
98
101
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@alstar/studio",
3
- "version": "0.0.0-beta.7",
3
+ "version": "0.0.0-beta.8",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "dependencies": {
7
7
  "@hono/node-server": "^1.18.1",
8
8
  "@starfederation/datastar-sdk": "1.0.0-RC.1",
9
9
  "hono": "^4.8.12",
10
+ "@alstar/refresher": "0.0.0-beta.2",
10
11
  "@alstar/ui": "0.0.0-beta.1",
11
- "@alstar/db": "0.0.0-beta.1",
12
- "@alstar/refresher": "0.0.0-beta.2"
12
+ "@alstar/db": "0.0.0-beta.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "^24.1.0",