@happyvertical/smrt-template-sveltekit 0.37.10 → 0.38.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/package.json +2 -2
- package/template/README.md +61 -0
- package/template/package.json +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-template-sveltekit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "SvelteKit project template with SMRT framework integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"directory": "packages/template-sveltekit"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@happyvertical/smrt-core": "0.
|
|
32
|
+
"@happyvertical/smrt-core": "0.38.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"vitest": "^4.1.9"
|
package/template/README.md
CHANGED
|
@@ -165,6 +165,67 @@ published content, navigation. Do **not** cache:
|
|
|
165
165
|
Pass `cache: false` on a specific call to bypass a model-level cache where
|
|
166
166
|
freshness matters.
|
|
167
167
|
|
|
168
|
+
### Client live collections (opt-in)
|
|
169
|
+
|
|
170
|
+
The server-load pattern above renders a page and refreshes it with
|
|
171
|
+
`invalidate()`. For **interactive surfaces** that mutate rows and want an
|
|
172
|
+
optimistic, reactive local store (an editor, a live dashboard), layer the
|
|
173
|
+
browser client-data runtime on top: `@happyvertical/smrt-web` (the engine
|
|
174
|
+
wrapper) + `@happyvertical/smrt-svelte/web` (the Svelte 5 runes binding). It is
|
|
175
|
+
**opt-in per surface** — the client engine (~76 kB gzip) should never load on
|
|
176
|
+
public or content pages, so import it only in routes that use live collections.
|
|
177
|
+
|
|
178
|
+
Keep loading the initial rows in a server `load` (SSR + no waterfall), then
|
|
179
|
+
**seed** the client collection from the hydrated `PageData` with `initialData`,
|
|
180
|
+
so the first client render serves the SSR rows with no duplicate fetch and only
|
|
181
|
+
revalidates once they go stale:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// src/routes/live/+page.server.ts — same server-load pattern, plain rows out.
|
|
185
|
+
import { getCollection } from '$lib/server/smrt';
|
|
186
|
+
import type { Item } from '$lib/objects/Item';
|
|
187
|
+
import type { PageServerLoad } from './$types';
|
|
188
|
+
|
|
189
|
+
export const load: PageServerLoad = async () => {
|
|
190
|
+
const items = await getCollection<Item>('Item');
|
|
191
|
+
const rows = await items.list({ orderBy: 'created_at DESC', limit: 50 });
|
|
192
|
+
return { items: rows.map((i) => ({ id: i.id, title: i.title, status: i.status })) };
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
```svelte
|
|
197
|
+
<!-- src/routes/live/+page.svelte -->
|
|
198
|
+
<script lang="ts">
|
|
199
|
+
import { createSmrtCollection } from '@happyvertical/smrt-web';
|
|
200
|
+
import { liveCollection } from '@happyvertical/smrt-svelte/web';
|
|
201
|
+
import { getCollectionDefinition } from '@happyvertical/smrt-virt-web';
|
|
202
|
+
import type { PageProps } from './$types';
|
|
203
|
+
|
|
204
|
+
let { data }: PageProps = $props();
|
|
205
|
+
|
|
206
|
+
// initialData seeds the cache from the SSR rows: the first read is served
|
|
207
|
+
// from data.items with NO network request, and revalidates after staleTimeMs.
|
|
208
|
+
// basePath MUST match this app's generated routes — they are served at
|
|
209
|
+
// `/api/*` (routesDir: 'src/routes/api'), not the runtime's `/api/v1` default,
|
|
210
|
+
// so revalidation and live mutations hit `/api/items` instead of 404ing.
|
|
211
|
+
const items = createSmrtCollection(getCollectionDefinition('items'), {
|
|
212
|
+
initialData: data.items,
|
|
213
|
+
basePath: '/api',
|
|
214
|
+
});
|
|
215
|
+
const view = liveCollection(items);
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
{#each view.rows as item (item.id)}
|
|
219
|
+
<p>{item.title}</p>
|
|
220
|
+
{/each}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`getCollectionDefinition('items')` comes from the plugin-generated
|
|
224
|
+
`@happyvertical/smrt-virt-web` virtual module (its `<collection>` key is the
|
|
225
|
+
same REST route segment as `depends`/`invalidate`). Add
|
|
226
|
+
`@happyvertical/smrt-web` and `@happyvertical/smrt-svelte` to the project's
|
|
227
|
+
dependencies before using this pattern.
|
|
228
|
+
|
|
168
229
|
## Multi-tenancy
|
|
169
230
|
|
|
170
231
|
This template ships with multi-tenancy pre-wired. Out of the box you get:
|
package/template/package.json
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"vite": "^8.1.2"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@happyvertical/smrt-core": "^0.
|
|
24
|
-
"@happyvertical/smrt-tenancy": "^0.
|
|
25
|
-
"@happyvertical/smrt-users": "^0.
|
|
23
|
+
"@happyvertical/smrt-core": "^0.38.0",
|
|
24
|
+
"@happyvertical/smrt-tenancy": "^0.38.0",
|
|
25
|
+
"@happyvertical/smrt-users": "^0.38.0"
|
|
26
26
|
}
|
|
27
27
|
}
|