@@ -15,6 +15,7 @@ npm install @script-development/fs-adapter-store
1515## The Big Picture
1616
1717A typical application has domain resources — users, projects, invoices — that need to be:
18+
18191 . ** Fetched** from an API
19202 . ** Stored** in reactive state
20213 . ** Displayed** in components
@@ -43,11 +44,11 @@ import { createAdapterStoreModule, resourceAdapter } from "@script-development/f
4344import { http , storage , loading } from " @/services" ;
4445
4546const usersStore = createAdapterStoreModule <User >({
46- domainName: " users" , // API endpoint: /users
47- adapter: resourceAdapter , // CRUD adapter factory
48- httpService: http , // for API calls
49- storageService: storage , // for offline persistence
50- loadingService: loading , // for waiting on data
47+ domainName: " users" , // API endpoint: /users
48+ adapter: resourceAdapter , // CRUD adapter factory
49+ httpService: http , // for API calls
50+ storageService: storage , // for offline persistence
51+ loadingService: loading , // for waiting on data
5152});
5253```
5354
@@ -117,15 +118,15 @@ When a resource comes from the API (has an `id`), it's wrapped in an `Adapted` o
117118const user = usersStore .getById (1 ).value ;
118119
119120// Read original values (readonly, frozen)
120- user .id ; // 1
121- user .name ; // "Alice"
121+ user .id ; // 1
122+ user .name ; // "Alice"
122123user .email ; // "alice@example.com"
123124
124125// Edit via mutable ref
125126user .mutable .value .name = " Bob" ;
126127
127128// Save changes
128- await user .update (); // PUT /users/1 — sends full object
129+ await user .update (); // PUT /users/1 — sends full object
129130await user .patch ({ name: " Bob" }); // PATCH /users/1 — sends partial update
130131
131132// Discard edits
@@ -143,7 +144,7 @@ When you create a new resource via `generateNew()`, it's wrapped in a `NewAdapte
143144const newUser = usersStore .generateNew ();
144145
145146// Default values (readonly, frozen)
146- newUser .name ; // "" (empty defaults)
147+ newUser .name ; // "" (empty defaults)
147148newUser .email ; // ""
148149
149150// Edit via mutable ref
@@ -218,40 +219,40 @@ import { EntryNotFoundError, MissingResponseDataError } from "@script-developmen
218219
219220### ` createAdapterStoreModule(config) `
220221
221- | Parameter | Type | Description |
222- | -----------| ------| -------------|
223- | ` config.domainName ` | ` string ` | Resource endpoint name (e.g., ` "users" ` ) |
224- | ` config.adapter ` | ` Adapter ` | CRUD adapter factory (use ` resourceAdapter ` ) |
225- | ` config.httpService ` | ` Pick<HttpService, "getRequest"> ` | HTTP service for fetching |
226- | ` config.storageService ` | ` Pick<StorageService, "get" \| "put"> ` | Storage for persistence |
227- | ` config.loadingService ` | ` Pick<LoadingService, "ensureLoadingFinished"> ` | Loading service for sync |
222+ | Parameter | Type | Description |
223+ | ----------------------- | ----------------------------------------------- | -------------------------------------------- |
224+ | ` config.domainName ` | ` string ` | Resource endpoint name (e.g., ` "users" ` ) |
225+ | ` config.adapter ` | ` Adapter ` | CRUD adapter factory (use ` resourceAdapter ` ) |
226+ | ` config.httpService ` | ` Pick<HttpService, "getRequest"> ` | HTTP service for fetching |
227+ | ` config.storageService ` | ` Pick<StorageService, "get" \| "put"> ` | Storage for persistence |
228+ | ` config.loadingService ` | ` Pick<LoadingService, "ensureLoadingFinished"> ` | Loading service for sync |
228229
229230### Store Module Methods
230231
231- | Method | Returns | Description |
232- | --------| ---------| -------------|
233- | ` getAll ` | ` ComputedRef<Adapted[]> ` | Reactive list of all adapted resources |
234- | ` getById(id) ` | ` ComputedRef<Adapted \| undefined> ` | Reactive lookup by ID |
235- | ` getOrFailById(id) ` | ` Promise<Adapted> ` | Wait for loading, throw if not found |
236- | ` generateNew() ` | ` NewAdapted ` | Create a new unsaved resource |
237- | ` retrieveAll() ` | ` Promise<void> ` | Fetch all from API and update state |
232+ | Method | Returns | Description |
233+ | ------------------- | ----------------------------------- | -------------------------------------- |
234+ | ` getAll ` | ` ComputedRef<Adapted[]> ` | Reactive list of all adapted resources |
235+ | ` getById(id) ` | ` ComputedRef<Adapted \| undefined> ` | Reactive lookup by ID |
236+ | ` getOrFailById(id) ` | ` Promise<Adapted> ` | Wait for loading, throw if not found |
237+ | ` generateNew() ` | ` NewAdapted ` | Create a new unsaved resource |
238+ | ` retrieveAll() ` | ` Promise<void> ` | Fetch all from API and update state |
238239
239240### Adapted Properties
240241
241- | Property | Type | Description |
242- | ----------| ------| -------------|
243- | * (all resource fields)* | ` readonly ` | Original values from API |
244- | ` mutable ` | ` Ref<Writable<T>> ` | Editable copy |
245- | ` reset() ` | ` () => void ` | Revert mutable to original |
246- | ` update() ` | ` () => Promise<T> ` | PUT full resource |
247- | ` patch(partial) ` | ` (partial) => Promise<T> ` | PATCH partial update |
248- | ` delete() ` | ` () => Promise<void> ` | DELETE resource |
242+ | Property | Type | Description |
243+ | ----------------------- | ------------------------- | -------------------------- |
244+ | _ (all resource fields)_ | ` readonly ` | Original values from API |
245+ | ` mutable ` | ` Ref<Writable<T>> ` | Editable copy |
246+ | ` reset() ` | ` () => void ` | Revert mutable to original |
247+ | ` update() ` | ` () => Promise<T> ` | PUT full resource |
248+ | ` patch(partial) ` | ` (partial) => Promise<T> ` | PATCH partial update |
249+ | ` delete() ` | ` () => Promise<void> ` | DELETE resource |
249250
250251### NewAdapted Properties
251252
252- | Property | Type | Description |
253- | ----------| ------| -------------|
254- | * (all new fields)* | ` readonly ` | Default values |
255- | ` mutable ` | ` Ref<Writable<N>> ` | Editable copy |
256- | ` reset() ` | ` () => void ` | Revert mutable to defaults |
257- | ` create() ` | ` () => Promise<T> ` | POST to create resource |
253+ | Property | Type | Description |
254+ | ------------------ | ------------------ | -------------------------- |
255+ | _ (all new fields)_ | ` readonly ` | Default values |
256+ | ` mutable ` | ` Ref<Writable<N>> ` | Editable copy |
257+ | ` reset() ` | ` () => void ` | Revert mutable to defaults |
258+ | ` create() ` | ` () => Promise<T> ` | POST to create resource |
0 commit comments