@kitr/storage 0.3.1 → 0.4.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.
package/dist/kitr.js CHANGED
@@ -18,19 +18,21 @@ export default defineConfig({
18
18
 
19
19
  /** Cookies are typed once and read with \`cookies(event).get(item)\` from @kitr/storage/server. */
20
20
  export const localeCookie = defineCookie('locale', { default: 'en', maxAge: 60 * 60 * 24 * 365 })
21
- ` : `import { defineCookie, defineStorage } from '@kitr/storage'
21
+ ` : `import { defineCookie } from '@kitr/storage'
22
22
 
23
23
  /**
24
24
  * Every persisted value, in one file, typed. Components read them with
25
25
  * \`useStorage(item)\` / \`useCookie(item)\` from @kitr/storage/react; plain code with \`item.get()\`.
26
+ * A local or session storage value is declared the same way:
27
+ *
28
+ * import { defineStorage } from '@kitr/storage'
29
+ *
30
+ * export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
31
+ * export const recentSearches = defineStorage<string[]>('recent-searches', {
32
+ * default: [],
33
+ * area: 'session',
34
+ * })
26
35
  */
27
- export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
28
-
29
- export const recentSearches = defineStorage<string[]>('recent-searches', {
30
- default: [],
31
- area: 'session',
32
- version: 1,
33
- })
34
36
 
35
37
  /** Readable on the server too (\`localeCookie.get(request.headers)\`), so SSR picks the right locale. */
36
38
  export const localeCookie = defineCookie('locale', { default: 'en', maxAge: 60 * 60 * 24 * 365 })
package/docs/index.md CHANGED
@@ -35,7 +35,7 @@ kitr add storage
35
35
 
36
36
  - Installs `@kitr/storage` and adds its provider and package to `kitrrc.ts`.
37
37
  - Writes `config/storage.ts` (see [Configure](#configure)).
38
- - Writes `app/storage.ts` with three sample values: `sidebar`, `recentSearches` and `localeCookie`. A server-only project gets only `localeCookie`.
38
+ - Writes `app/storage.ts` with one value, `localeCookie`, and a commented `defineStorage` example.
39
39
  - Adds a `## kitr: storage` section to `AGENTS.md`.
40
40
 
41
41
  It asks no questions and adds no environment variables or scripts. It does not overwrite `config/storage.ts` or `app/storage.ts` when they exist.
@@ -50,19 +50,21 @@ The generated `app/storage.ts` in a project with React:
50
50
 
51
51
  ```ts
52
52
  // app/storage.ts
53
- import { defineCookie, defineStorage } from '@kitr/storage'
53
+ import { defineCookie } from '@kitr/storage'
54
54
 
55
55
  /**
56
56
  * Every persisted value, in one file, typed. Components read them with
57
57
  * `useStorage(item)` / `useCookie(item)` from @kitr/storage/react; plain code with `item.get()`.
58
+ * A local or session storage value is declared the same way:
59
+ *
60
+ * import { defineStorage } from '@kitr/storage'
61
+ *
62
+ * export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
63
+ * export const recentSearches = defineStorage<string[]>('recent-searches', {
64
+ * default: [],
65
+ * area: 'session',
66
+ * })
58
67
  */
59
- export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
60
-
61
- export const recentSearches = defineStorage<string[]>('recent-searches', {
62
- default: [],
63
- area: 'session',
64
- version: 1,
65
- })
66
68
 
67
69
  /** Readable on the server too (`localeCookie.get(request.headers)`), so SSR picks the right locale. */
68
70
  export const localeCookie = defineCookie('locale', { default: 'en', maxAge: 60 * 60 * 24 * 365 })
@@ -103,7 +105,16 @@ export default defineConfig({
103
105
 
104
106
  ## Save your first value
105
107
 
106
- Read and write a value from a component with `useStorage`. It returns the value, a setter and a remover, like `useState`:
108
+ Declare the value in `app/storage.ts` first, with its default. The type comes from the default:
109
+
110
+ ```ts
111
+ // app/storage.ts
112
+ import { defineStorage } from '@kitr/storage'
113
+
114
+ export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
115
+ ```
116
+
117
+ Read and write it from a component with `useStorage`. It returns the value, a setter and a remover, like `useState`:
107
118
 
108
119
  ```tsx
109
120
  // app/components/sidebar-toggle.tsx
package/docs/overview.md CHANGED
@@ -18,11 +18,20 @@ Storage items run in the browser and native shells; cookies run on both sides. F
18
18
  kitr add storage
19
19
  ```
20
20
 
21
- Adds `@kitr/storage`, its provider, `config/storage.ts` and `app/storage.ts` with three sample items. [Every change](/packages/storage/guide#install).
21
+ Adds `@kitr/storage`, its provider, `config/storage.ts` and `app/storage.ts` with the locale cookie. [Every change](/packages/storage/guide#install).
22
22
 
23
23
  ## Quick start
24
24
 
25
- Declare each value once in `app/storage.ts`, then read and write it like `useState`:
25
+ Declare each value once in `app/storage.ts`, with its default:
26
+
27
+ ```ts
28
+ // app/storage.ts
29
+ import { defineStorage } from '@kitr/storage'
30
+
31
+ export const sidebar = defineStorage('sidebar', { default: { collapsed: false } })
32
+ ```
33
+
34
+ Then read and write it like `useState`:
26
35
 
27
36
  ```tsx
28
37
  // app/components/sidebar-toggle.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitr/storage",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "@kitr/storage: typed localStorage/sessionStorage items and cookies with one API on the client and the server; SSR-safe React hooks.",
5
5
  "keywords": [
6
6
  "kitr",
@@ -47,7 +47,7 @@
47
47
  "docs"
48
48
  ],
49
49
  "dependencies": {
50
- "@kitr/core": "0.3.1"
50
+ "@kitr/core": "0.4.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "react": ">=18.0.0",
@@ -69,7 +69,7 @@
69
69
  "h3": "^2.0.8",
70
70
  "@types/node": "^22.19.0",
71
71
  "react-dom": "^19.3.1",
72
- "@kitr/devtools": "0.3.1"
72
+ "@kitr/devtools": "0.4.0"
73
73
  },
74
74
  "kitr": {
75
75
  "name": "storage",