@marktiderman/genesis-core 2.16.1 → 2.17.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 (124) hide show
  1. package/README.md +3 -2
  2. package/dist/{aggregate-Y5IJ5aPn.d.ts → aggregate-v_r-nZbH.d.ts} +1 -1
  3. package/dist/{chunk-M5IX7C6U.js → chunk-24X4HWL5.js} +4 -4
  4. package/dist/{chunk-M5IX7C6U.js.map → chunk-24X4HWL5.js.map} +1 -1
  5. package/dist/chunk-2ORQLYVW.js +115 -0
  6. package/dist/chunk-2ORQLYVW.js.map +1 -0
  7. package/dist/{chunk-XPBS5YE4.js → chunk-4POVYF6P.js} +4 -4
  8. package/dist/{chunk-XPBS5YE4.js.map → chunk-4POVYF6P.js.map} +1 -1
  9. package/dist/{chunk-IYGVJFCV.js → chunk-5KLIFJYG.js} +3 -3
  10. package/dist/{chunk-IYGVJFCV.js.map → chunk-5KLIFJYG.js.map} +1 -1
  11. package/dist/{chunk-ALLWIK62.js → chunk-6B4CN2TC.js} +8 -6
  12. package/dist/chunk-6B4CN2TC.js.map +1 -0
  13. package/dist/chunk-6JOWGO2X.js +266 -0
  14. package/dist/chunk-6JOWGO2X.js.map +1 -0
  15. package/dist/{chunk-E3K2A3PK.js → chunk-6SHGMEA6.js} +3 -3
  16. package/dist/{chunk-E3K2A3PK.js.map → chunk-6SHGMEA6.js.map} +1 -1
  17. package/dist/chunk-6VNM6KAX.js +59 -0
  18. package/dist/chunk-6VNM6KAX.js.map +1 -0
  19. package/dist/{chunk-SOO54YYY.js → chunk-AQX5HQD6.js} +3 -3
  20. package/dist/{chunk-SOO54YYY.js.map → chunk-AQX5HQD6.js.map} +1 -1
  21. package/dist/chunk-BNKP2H7J.js +11 -0
  22. package/dist/chunk-BNKP2H7J.js.map +1 -0
  23. package/dist/{chunk-FXPODKCK.js → chunk-FBMKI22S.js} +6 -6
  24. package/dist/{chunk-FXPODKCK.js.map → chunk-FBMKI22S.js.map} +1 -1
  25. package/dist/{chunk-POUI7GAI.js → chunk-JF7FXSQB.js} +5 -5
  26. package/dist/{chunk-POUI7GAI.js.map → chunk-JF7FXSQB.js.map} +1 -1
  27. package/dist/chunk-JNWTHDGF.js +892 -0
  28. package/dist/chunk-JNWTHDGF.js.map +1 -0
  29. package/dist/chunk-K33LWVUF.js +31 -0
  30. package/dist/chunk-K33LWVUF.js.map +1 -0
  31. package/dist/chunk-KRRESUXT.js +192 -0
  32. package/dist/chunk-KRRESUXT.js.map +1 -0
  33. package/dist/{chunk-LB6FMQQM.js → chunk-KV2HW4G4.js} +3 -11
  34. package/dist/chunk-KV2HW4G4.js.map +1 -0
  35. package/dist/{chunk-42NVJJTT.js → chunk-MMMC37AP.js} +3 -3
  36. package/dist/{chunk-42NVJJTT.js.map → chunk-MMMC37AP.js.map} +1 -1
  37. package/dist/chunk-MZVFOTAE.js +96 -0
  38. package/dist/chunk-MZVFOTAE.js.map +1 -0
  39. package/dist/{chunk-R3YXYVWF.js → chunk-OIZNABG4.js} +5 -4
  40. package/dist/chunk-OIZNABG4.js.map +1 -0
  41. package/dist/{chunk-QGWQ6LK3.js → chunk-QJOKZZKY.js} +9 -6
  42. package/dist/chunk-QJOKZZKY.js.map +1 -0
  43. package/dist/chunk-TWLPC4S3.js +53 -0
  44. package/dist/chunk-TWLPC4S3.js.map +1 -0
  45. package/dist/{chunk-7EFTWOMA.js → chunk-UNEZF3ZP.js} +73 -15
  46. package/dist/chunk-UNEZF3ZP.js.map +1 -0
  47. package/dist/chunk-WNOCPV4A.js +220 -0
  48. package/dist/chunk-WNOCPV4A.js.map +1 -0
  49. package/dist/{chunk-ZYOJWU62.js → chunk-XIBQ5BTZ.js} +12 -53
  50. package/dist/chunk-XIBQ5BTZ.js.map +1 -0
  51. package/dist/chunk-YMFJLBIZ.js +159 -0
  52. package/dist/chunk-YMFJLBIZ.js.map +1 -0
  53. package/dist/{chunk-UDSTWXXZ.js → chunk-ZKLB2HB5.js} +3 -3
  54. package/dist/{chunk-UDSTWXXZ.js.map → chunk-ZKLB2HB5.js.map} +1 -1
  55. package/dist/csv.d.ts +12 -3
  56. package/dist/csv.js +4 -4
  57. package/dist/csv.js.map +1 -1
  58. package/dist/form-types.d.ts +1 -1
  59. package/dist/headless/index.d.ts +1 -1
  60. package/dist/hooks/index.d.ts +16 -6
  61. package/dist/hooks/index.js +27 -15
  62. package/dist/hooks/mutation-mode.d.ts +1 -1
  63. package/dist/hooks/mutation-mode.js +3 -3
  64. package/dist/hooks/related-keys.d.ts +1 -1
  65. package/dist/hooks/use-aggregate.d.ts +2 -2
  66. package/dist/hooks/use-aggregate.js +3 -3
  67. package/dist/hooks/use-board-columns.d.ts +79 -0
  68. package/dist/hooks/use-board-columns.js +4 -0
  69. package/dist/hooks/use-board-columns.js.map +1 -0
  70. package/dist/hooks/use-capabilities.d.ts +1 -1
  71. package/dist/hooks/use-capabilities.js +2 -2
  72. package/dist/hooks/use-infinite-resource.d.ts +1 -1
  73. package/dist/hooks/use-infinite-resource.js +3 -3
  74. package/dist/hooks/use-link-options.d.ts +1 -1
  75. package/dist/hooks/use-link-options.js +5 -5
  76. package/dist/hooks/use-list-state.d.ts +103 -0
  77. package/dist/hooks/use-list-state.js +21 -0
  78. package/dist/hooks/use-list-state.js.map +1 -0
  79. package/dist/hooks/use-live.d.ts +1 -1
  80. package/dist/hooks/use-live.js +2 -2
  81. package/dist/hooks/use-one.d.ts +7 -1
  82. package/dist/hooks/use-one.js +3 -3
  83. package/dist/hooks/use-persisted-ui-state.js +2 -2
  84. package/dist/hooks/use-relation-label.d.ts +1 -1
  85. package/dist/hooks/use-relation-label.js +2 -2
  86. package/dist/hooks/use-resource-form.d.ts +1 -1
  87. package/dist/hooks/use-resource-form.js +7 -7
  88. package/dist/hooks/use-resource.d.ts +7 -1
  89. package/dist/hooks/use-resource.js +5 -5
  90. package/dist/hooks/use-segment-counts.d.ts +23 -0
  91. package/dist/hooks/use-segment-counts.js +19 -0
  92. package/dist/hooks/use-segment-counts.js.map +1 -0
  93. package/dist/hooks/use-view-board.d.ts +120 -0
  94. package/dist/hooks/use-view-board.js +29 -0
  95. package/dist/hooks/use-view-board.js.map +1 -0
  96. package/dist/hooks/use-view-calendar-range.d.ts +91 -0
  97. package/dist/hooks/use-view-calendar-range.js +22 -0
  98. package/dist/hooks/use-view-calendar-range.js.map +1 -0
  99. package/dist/hooks/use-write.d.ts +1 -1
  100. package/dist/index.d.ts +41 -11
  101. package/dist/index.js +119 -26
  102. package/dist/index.js.map +1 -1
  103. package/dist/provider/index.d.ts +61 -8
  104. package/dist/provider/index.js +2 -2
  105. package/dist/resource-view/index.d.ts +162 -757
  106. package/dist/resource-view/index.js +31 -686
  107. package/dist/resource-view/index.js.map +1 -1
  108. package/dist/saved-views-C45lRm7i.d.ts +155 -0
  109. package/dist/schema/index.d.ts +3 -3
  110. package/dist/schema/index.js +2 -1
  111. package/dist/testing/index.d.ts +2 -2
  112. package/dist/types-BAhcze_-.d.ts +1063 -0
  113. package/dist/{types-BriIV4e_.d.ts → types-CiQY6hUy.d.ts} +11 -1
  114. package/dist/{viewer-scope-Dx0N9AYk.d.ts → viewer-oOk0ZZk9.d.ts} +36 -34
  115. package/dist/{workspaces-CxpiFu2-.d.ts → workspaces-DeaFix5Z.d.ts} +1 -1
  116. package/dist/workspaces.d.ts +2 -2
  117. package/dist/{write-outcome-CkQXgtJq.d.ts → write-outcome-DuwfsnyO.d.ts} +1 -1
  118. package/package.json +11 -1
  119. package/dist/chunk-7EFTWOMA.js.map +0 -1
  120. package/dist/chunk-ALLWIK62.js.map +0 -1
  121. package/dist/chunk-LB6FMQQM.js.map +0 -1
  122. package/dist/chunk-QGWQ6LK3.js.map +0 -1
  123. package/dist/chunk-R3YXYVWF.js.map +0 -1
  124. package/dist/chunk-ZYOJWU62.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,14 +1,19 @@
1
- import { c as ListParams, d as Identifier } from './types-BriIV4e_.js';
2
- export { i as AggregateMetric, A as AggregateParams, b as AggregateResult, k as ArrayFilter, h as AuditEntry, B as BaseRecord, l as BulkChange, m as BulkResult, C as ControlHint, n as CountMode, o as CreateParams, p as CreateResult, D as DataProvider, j as DataRow, q as DeleteParams, r as DeleteResult, s as FieldPermissions, e as FieldReference, F as FieldSchema, t as FieldType, u as FilterOperator, a as FilterParam, G as GetManyParams, v as GetManyResult, w as GetOneParams, x as GetOneResult, H as HistoryParams, y as ImportParams, I as InvalidationKey, L as ListResult, N as NullFilter, z as PaginationParam, P as ProviderCapabilities, E as RangeFilter, J as RecordComment, K as ResourceAccess, g as ResourceChangeEvent, M as ResourceContract, R as ResourceFormFieldDef, O as ResourceRelation, Q as ResourceSchema, T as ResourceSummary, U as RowAction, V as RowFailure, X as RowOf, Y as ScalarFilter, Z as SelectOption, S as SortParam, _ as StorageType, f as SubscribeParams, $ as UpdateParams, a0 as UpdateResult, a1 as VersionField, a2 as WidgetHint, W as WriteEvent, a3 as defineResource, a4 as fieldControl } from './types-BriIV4e_.js';
3
- export { R as ResolveAggregateOptions, a as aggregateProblems, r as resolveAggregate, t as toAggregateValues } from './aggregate-Y5IJ5aPn.js';
4
- export { D as DataWriteError, a as DataWriteErrorOptions, N as NO_ROWS_MATCHED, W as WriteOutcome, i as isDataWriteError } from './write-outcome-CkQXgtJq.js';
5
- export { CallRpcOptions, CreateOrAdoptOptions, CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProviderRoot, DataProviderRootProps, GenesisProvider, GenesisProviderProps, MockProviderOptions, PostgrestFieldErrors, RPC_FAILED, RpcClient, SupabaseClient, SupabaseClientInput, SupabaseProviderOptions, SupabaseRealtimeChannel, SupabaseRealtimePayload, SupabaseResourceConfig, SupabaseUpdateContext, SupabaseWriteContext, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode } from './provider/index.js';
1
+ import { b as ListParams, c as Identifier } from './types-CiQY6hUy.js';
2
+ export { k as AggregateMetric, A as AggregateParams, d as AggregateResult, n as ArrayFilter, j as AuditEntry, B as BaseRecord, o as BulkChange, p as BulkResult, C as ControlHint, q as CountMode, r as CreateParams, s as CreateResult, D as DataProvider, e as DataRow, t as DeleteParams, u as DeleteResult, v as FieldPermissions, f as FieldReference, F as FieldSchema, w as FieldType, x as FilterOperator, a as FilterParam, G as GetManyParams, y as GetManyResult, z as GetOneParams, E as GetOneResult, H as HistoryParams, J as ImportParams, I as InvalidationKey, L as ListResult, N as NullFilter, K as PaginationParam, P as ProviderCapabilities, M as RangeFilter, O as RecordComment, Q as ResourceAccess, h as ResourceChangeEvent, R as ResourceContract, i as ResourceFormFieldDef, T as ResourceRelation, U as ResourceSchema, V as ResourceSummary, m as RowAction, X as RowFailure, l as RowOf, Y as ScalarFilter, Z as SelectOption, S as SortParam, _ as StorageType, g as SubscribeParams, $ as UpdateParams, a0 as UpdateResult, a1 as VersionField, a2 as WidgetHint, W as WriteEvent, a3 as defineResource, a4 as fieldControl } from './types-CiQY6hUy.js';
3
+ export { R as ResolveAggregateOptions, a as aggregateProblems, r as resolveAggregate, t as toAggregateValues } from './aggregate-v_r-nZbH.js';
4
+ export { D as DataWriteError, a as DataWriteErrorOptions, N as NO_ROWS_MATCHED, W as WriteOutcome, i as isDataWriteError } from './write-outcome-DuwfsnyO.js';
5
+ export { CallRpcOptions, CreateOrAdoptOptions, CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProviderRoot, DataProviderRootProps, GenesisProvider, GenesisProviderProps, MockProviderOptions, PostgrestFieldErrors, RPC_FAILED, RpcClient, SourceArgsContext, SourcePages, SupabaseClient, SupabaseClientInput, SupabaseProviderOptions, SupabaseRealtimeChannel, SupabaseRealtimePayload, SupabaseResourceConfig, SupabaseUpdateContext, SupabaseWriteContext, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode } from './provider/index.js';
6
6
  export { D as DataReadError, a as DataReadErrorOptions, R as ReadOutcome, i as isDataReadError, r as readFailureMessage } from './read-outcome-BnboMYOV.js';
7
7
  export { S as StorageAdapter } from './types-DKcxHXxq.js';
8
8
  export { createLocalStorageAdapter, createMemoryStorageAdapter, createNoopStorageAdapter } from './storage/index.js';
9
9
  export { UpdateOptions, UseResourceOptions, UseResourceReturn, useResource } from './hooks/use-resource.js';
10
10
  export { UseOneOptions, useOne } from './hooks/use-one.js';
11
11
  export { UseAggregateOptions, useAggregate } from './hooks/use-aggregate.js';
12
+ export { useSegmentCounts } from './hooks/use-segment-counts.js';
13
+ export { BOARD_NONE, BOARD_PAGE, BoardColumnData, UseBoardColumnsOptions, UseBoardColumnsReturn, boardColumnFilter, useBoardColumns } from './hooks/use-board-columns.js';
14
+ export { UseViewBoardOptions, ViewBoardColumn, ViewBoardConflict, ViewBoardState, ViewBoardWords, useViewBoard } from './hooks/use-view-board.js';
15
+ export { CALENDAR_LIMIT, UseViewCalendarRangeOptions, ViewCalendarRange, ViewCalendarRangeState, useViewCalendarRange } from './hooks/use-view-calendar-range.js';
16
+ export { ListSort, ListStateResult, ListUrlAdapter, UseListStateOptions, useListState } from './hooks/use-list-state.js';
12
17
  export { UseRelationLabelOptions, loadRelationLabel, relationNamingField, useRelationLabel } from './hooks/use-relation-label.js';
13
18
  export { LinkOption, LinkTarget, UseLinkOptionsOptions, UseLinkOptionsReturn, useLinkOptions } from './hooks/use-link-options.js';
14
19
  export { InfinitePageParam, UseInfiniteResourceOptions, UseInfiniteResourceReturn, useInfiniteResource } from './hooks/use-infinite-resource.js';
@@ -17,7 +22,7 @@ export { PersistedUiStateOptions, usePersistedUiState } from './hooks/use-persis
17
22
  export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './hooks/use-write.js';
18
23
  export { UseDraftReturn, useDraft } from './hooks/use-draft.js';
19
24
  export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './hooks/draft-controller.js';
20
- export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, s as scopeClock, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-scope-Dx0N9AYk.js';
25
+ export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, s as scopeClock, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-oOk0ZZk9.js';
21
26
  export { WorkspaceContext, WorkspaceScope, WorkspaceScopeProps, rememberedWorkspaceId, useWorkspace } from './hooks/index.js';
22
27
  export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions, useLiveInvalidation } from './hooks/use-live.js';
23
28
  export { UseResourceFormOptions, UseResourceFormReturn, blankValues, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
@@ -30,12 +35,16 @@ import { Query } from '@tanstack/react-query';
30
35
  export { isSafeUrl, normalizeLinkUrl } from './urls.js';
31
36
  export { ClassifiedError, ClassifyErrorOptions, ErrorKind, ErrorMessages, ErrorReportContext, ErrorReporter, classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter } from './errors.js';
32
37
  export { titleCase } from './utils.js';
33
- import { A as AppearancePreferenceValues, R as ResolvedAppearancePreferences, a as AppearancePreferenceLayers, b as Appearance, D as Density } from './workspaces-CxpiFu2-.js';
34
- export { c as APPEARANCES, d as AppearancePreferenceSource, e as DENSITIES, G as GENESIS_APPEARANCE_DEFAULTS, i as isAppearance, f as isDensity, r as resolveAppearancePreferences, t as toAppearancePreferenceValues } from './workspaces-CxpiFu2-.js';
38
+ import { A as AppearancePreferenceValues, R as ResolvedAppearancePreferences, a as AppearancePreferenceLayers, b as Appearance, D as Density } from './workspaces-DeaFix5Z.js';
39
+ export { c as APPEARANCES, d as AppearancePreferenceSource, e as DENSITIES, G as GENESIS_APPEARANCE_DEFAULTS, i as isAppearance, f as isDensity, r as resolveAppearancePreferences, t as toAppearancePreferenceValues } from './workspaces-DeaFix5Z.js';
35
40
  import * as react from 'react';
36
41
  import { ReactNode } from 'react';
37
42
  import './types-CsKSAKqs.js';
43
+ import './types-BAhcze_-.js';
44
+ import './status-BXRokZD9.js';
45
+ import './gallery/index.js';
38
46
  import './dates.js';
47
+ import './saved-views-C45lRm7i.js';
39
48
  import 'react-hook-form';
40
49
 
41
50
  /** Who and when a key is for. `viewer` is required; null means signed out. */
@@ -119,9 +128,20 @@ declare function resourceKeys(resource: string): {
119
128
  */
120
129
  interface AppearancePreferencesStore {
121
130
  read(): AppearancePreferenceValues | null | undefined | Promise<AppearancePreferenceValues | null | undefined>;
122
- write(values: AppearancePreferenceValues): void | Promise<void>;
131
+ /**
132
+ * Save the person's values. Writes are sent one at a time, in order, and a write that a newer
133
+ * one replaces before it starts is skipped. `context.previous` is what the store last answered
134
+ * or accepted (null for nothing yet), so a store can write conditionally (compare and set) and
135
+ * refuse a write made from a stale copy by throwing: `onWriteError` hears it.
136
+ */
137
+ write(values: AppearancePreferenceValues, context: AppearanceWriteContext): void | Promise<void>;
123
138
  subscribe?(onChange: (values: AppearancePreferenceValues | null) => void): () => void;
124
139
  }
140
+ /** What a store's `write` is told beside the values. @stability Beta */
141
+ interface AppearanceWriteContext {
142
+ /** The values the store last read or accepted; null when it has none yet. */
143
+ readonly previous: AppearancePreferenceValues | null;
144
+ }
125
145
  /** What `defineAppearancePreferences` accepts. */
126
146
  interface AppearancePreferencesDefinition {
127
147
  /** Where the person's choice is kept beyond this device. Unset: the device only. */
@@ -130,12 +150,20 @@ interface AppearancePreferencesDefinition {
130
150
  storageKey?: string;
131
151
  /** Values the app fixes: nobody below can change them. */
132
152
  lock?: AppearancePreferenceValues;
153
+ /**
154
+ * Hears a store write that failed (offline, refused, a conditional write that lost), with the
155
+ * values it tried to save. The device keeps the choice for this visit; the next successful read
156
+ * of the store (another visit, another device) wins over it. Default: the
157
+ * error goes to `reportError`.
158
+ */
159
+ onWriteError?: (error: unknown, values: AppearancePreferenceValues) => void;
133
160
  }
134
161
  /** A defined appearance-preferences setup. */
135
162
  interface AppearancePreferences {
136
163
  readonly store?: AppearancePreferencesStore;
137
164
  readonly storageKey: string;
138
165
  readonly lock: Readonly<AppearancePreferenceValues>;
166
+ readonly onWriteError?: (error: unknown, values: AppearancePreferenceValues) => void;
139
167
  }
140
168
  /**
141
169
  * Declare where a person's appearance and density are kept and what the app locks. Checks the
@@ -182,6 +210,8 @@ interface AppearancePreferencesProviderProps {
182
210
  organization?: AppearancePreferenceValues | undefined;
183
211
  /** The app theme's defaults. */
184
212
  theme?: AppearancePreferenceValues | undefined;
213
+ /** Hears a failed store write (wins over the definition's `onWriteError`). */
214
+ onWriteError?: ((error: unknown, values: AppearancePreferenceValues) => void) | undefined;
185
215
  children: ReactNode;
186
216
  }
187
217
  /**
@@ -191,7 +221,7 @@ interface AppearancePreferencesProviderProps {
191
221
  *
192
222
  * @stability Beta
193
223
  */
194
- declare function AppearancePreferencesProvider({ preferences, organization, theme, children }: AppearancePreferencesProviderProps): react.JSX.Element;
224
+ declare function AppearancePreferencesProvider({ preferences, organization, theme, onWriteError, children }: AppearancePreferencesProviderProps): react.JSX.Element;
195
225
  /**
196
226
  * The person's appearance and density, resolved, with setters. Throws outside an
197
227
  * `AppearancePreferencesProvider`; a component that works with or without one reads
@@ -208,4 +238,4 @@ declare function useAppearancePreferences(): UseAppearancePreferencesReturn;
208
238
  */
209
239
  declare function useOptionalAppearancePreferences(): UseAppearancePreferencesReturn | null;
210
240
 
211
- export { Appearance, AppearancePreferenceLayers, AppearancePreferenceValues, type AppearancePreferences, type AppearancePreferencesDefinition, AppearancePreferencesProvider, type AppearancePreferencesProviderProps, type AppearancePreferencesStore, Density, Identifier, type KeyFilter, type KeyScope, ListParams, type QueryKeys, ResolvedAppearancePreferences, type ScopedKey, type UseAppearancePreferencesReturn, defineAppearancePreferences, defineQueryKeys, resourceKeys, useAppearancePreferences, useOptionalAppearancePreferences };
241
+ export { Appearance, AppearancePreferenceLayers, AppearancePreferenceValues, type AppearancePreferences, type AppearancePreferencesDefinition, AppearancePreferencesProvider, type AppearancePreferencesProviderProps, type AppearancePreferencesStore, type AppearanceWriteContext, Density, Identifier, type KeyFilter, type KeyScope, ListParams, type QueryKeys, ResolvedAppearancePreferences, type ScopedKey, type UseAppearancePreferencesReturn, defineAppearancePreferences, defineQueryKeys, resourceKeys, useAppearancePreferences, useOptionalAppearancePreferences };
package/dist/index.js CHANGED
@@ -1,29 +1,40 @@
1
- export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from './chunk-7EFTWOMA.js';
2
- export { decodeRecordKey, defineResource, encodeRecordKey, fieldControl, keyFields } from './chunk-LB6FMQQM.js';
3
1
  import './chunk-XCX2TRBL.js';
4
- export { ViewerScope, WorkspaceScope, clearViewerCache, rememberedWorkspaceId, scopeClock, useOptionalViewerScope, useViewer, useViewerScope, useWorkspace } from './chunk-ZYOJWU62.js';
2
+ export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from './chunk-UNEZF3ZP.js';
3
+ export { WorkspaceScope, rememberedWorkspaceId, useWorkspace } from './chunk-TWLPC4S3.js';
4
+ export { useSegmentCounts } from './chunk-K33LWVUF.js';
5
+ export { useViewBoard } from './chunk-KRRESUXT.js';
6
+ import './chunk-JNWTHDGF.js';
7
+ export { defineResource, fieldControl } from './chunk-BNKP2H7J.js';
8
+ export { CALENDAR_LIMIT, useViewCalendarRange } from './chunk-2ORQLYVW.js';
9
+ import './chunk-YMFJLBIZ.js';
10
+ export { decodeRecordKey, encodeRecordKey, keyFields } from './chunk-KV2HW4G4.js';
11
+ export { useWizard } from './chunk-7KOLYF27.js';
5
12
  export { WRITE_FAILED, useWrite } from './chunk-NQFIAULD.js';
13
+ export { useLinkOptions } from './chunk-JF7FXSQB.js';
14
+ export { useListState } from './chunk-WNOCPV4A.js';
15
+ import './chunk-MZVFOTAE.js';
16
+ import './chunk-6JOWGO2X.js';
17
+ export { ViewerScope, clearViewerCache, scopeClock, useOptionalViewerScope, useViewer, useViewerScope } from './chunk-XIBQ5BTZ.js';
6
18
  export { NO_VIEWER } from './chunk-OZYF55E3.js';
7
- import { usePersistedUiState } from './chunk-IYGVJFCV.js';
8
- export { usePersistedUiState } from './chunk-IYGVJFCV.js';
9
- export { blankValues, buildArrayItemDefaults, useResourceForm } from './chunk-FXPODKCK.js';
10
- export { writeConflict } from './chunk-LKRJB632.js';
11
- export { useOne } from './chunk-QGWQ6LK3.js';
12
- export { useResource } from './chunk-ALLWIK62.js';
19
+ import { usePersistedUiState } from './chunk-5KLIFJYG.js';
20
+ export { usePersistedUiState } from './chunk-5KLIFJYG.js';
21
+ export { loadRelationLabel, relationNamingField, useRelationLabel } from './chunk-ZKLB2HB5.js';
22
+ export { blankValues, buildArrayItemDefaults, useResourceForm } from './chunk-FBMKI22S.js';
13
23
  export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from './chunk-RVWKVD5Q.js';
14
- export { useWizard } from './chunk-7KOLYF27.js';
15
- export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-SOO54YYY.js';
24
+ export { writeConflict } from './chunk-LKRJB632.js';
25
+ export { useOne } from './chunk-QJOKZZKY.js';
26
+ export { useResource } from './chunk-6B4CN2TC.js';
27
+ export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-AQX5HQD6.js';
16
28
  import './chunk-7NUL32W7.js';
17
- export { useAggregate } from './chunk-XPBS5YE4.js';
18
- export { useCapabilities } from './chunk-42NVJJTT.js';
29
+ export { useAggregate } from './chunk-4POVYF6P.js';
30
+ export { BOARD_NONE, BOARD_PAGE, boardColumnFilter, useBoardColumns } from './chunk-6VNM6KAX.js';
31
+ export { useCapabilities } from './chunk-MMMC37AP.js';
19
32
  export { useDraft } from './chunk-SQLM5CIJ.js';
20
33
  import './chunk-AJGVLF37.js';
21
- export { useLinkOptions } from './chunk-POUI7GAI.js';
22
- export { loadRelationLabel, relationNamingField, useRelationLabel } from './chunk-UDSTWXXZ.js';
23
- export { useInfiniteResource } from './chunk-M5IX7C6U.js';
24
- export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, useLiveInvalidation } from './chunk-E3K2A3PK.js';
34
+ export { useInfiniteResource } from './chunk-24X4HWL5.js';
35
+ export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, useLiveInvalidation } from './chunk-6SHGMEA6.js';
25
36
  export { defineQueryKeys, resourceKeys } from './chunk-2IGAUXYH.js';
26
- export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from './chunk-R3YXYVWF.js';
37
+ export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from './chunk-OIZNABG4.js';
27
38
  export { aggregateProblems, resolveAggregate, toAggregateValues } from './chunk-J54XXKQD.js';
28
39
  export { createLocalStorageAdapter, createMemoryStorageAdapter, createNoopStorageAdapter } from './chunk-4PTQYT5J.js';
29
40
  import { isAppearance, APPEARANCES, isDensity, DENSITIES, toAppearancePreferenceValues, resolveAppearancePreferences } from './chunk-APFXV6FZ.js';
@@ -51,9 +62,11 @@ function defineAppearancePreferences(definition = {}) {
51
62
  problems.push("store: an object with read() and write()");
52
63
  if (definition.storageKey !== void 0 && (typeof definition.storageKey !== "string" || !definition.storageKey.trim()))
53
64
  problems.push("storageKey: a non-empty string");
65
+ if (definition.onWriteError !== void 0 && typeof definition.onWriteError !== "function") problems.push("onWriteError: a function");
54
66
  if (problems.length) throw new Error(`defineAppearancePreferences: ${problems.join("; ")}`);
55
67
  return Object.freeze({
56
68
  ...definition.store ? { store: definition.store } : {},
69
+ ...definition.onWriteError ? { onWriteError: definition.onWriteError } : {},
57
70
  storageKey: definition.storageKey ?? "genesis-appearance",
58
71
  lock: Object.freeze(toAppearancePreferenceValues(lock))
59
72
  });
@@ -70,29 +83,73 @@ var FORMAT = {
70
83
  };
71
84
  var NONE = {};
72
85
  var DEVICE_ONLY = defineAppearancePreferences();
73
- function AppearancePreferencesProvider({ preferences = DEVICE_ONLY, organization, theme, children }) {
86
+ function AppearancePreferencesProvider({ preferences = DEVICE_ONLY, organization, theme, onWriteError, children }) {
74
87
  const { store, storageKey, lock } = preferences;
75
88
  const [device, setDevice] = usePersistedUiState(storageKey, NONE, FORMAT);
76
89
  const [stored, setStored] = useState(void 0);
77
90
  const [ready, setReady] = useState(!store);
78
91
  const latestStore = useRef(store);
79
92
  latestStore.current = store;
93
+ const firstRead = useRef(store ? "pending" : "settled");
94
+ const waiting = useRef(null);
95
+ const writesDone = useRef(0);
96
+ const generation = useRef(0);
97
+ const confirmed = useRef(null);
98
+ const queue = useRef({ running: false, next: null });
99
+ const deviceSetter = useRef(setDevice);
100
+ deviceSetter.current = setDevice;
101
+ const writeErrorHandler = useRef(onWriteError ?? preferences.onWriteError);
102
+ writeErrorHandler.current = onWriteError ?? preferences.onWriteError;
80
103
  useEffect(() => {
104
+ generation.current += 1;
105
+ queue.current = { running: false, next: null };
106
+ waiting.current = null;
107
+ confirmed.current = null;
81
108
  if (!store) return;
82
109
  let active = true;
110
+ firstRead.current = "pending";
111
+ const writesAtStart = writesDone.current;
112
+ const release = (base) => {
113
+ firstRead.current = "settled";
114
+ const patch = waiting.current;
115
+ waiting.current = null;
116
+ if (!patch) return;
117
+ const merged = toAppearancePreferenceValues({ ...base ?? {}, ...patch });
118
+ setStored(merged);
119
+ deviceSetter.current(Object.keys(merged).length ? merged : void 0);
120
+ queue.current.next = { patch: merged, generation: generation.current };
121
+ void drainRef.current();
122
+ };
83
123
  Promise.resolve().then(() => store.read()).then(
84
124
  (values) => {
85
125
  if (!active) return;
86
- setStored(values ? toAppearancePreferenceValues(values) : null);
126
+ const read = values ? toAppearancePreferenceValues(values) : null;
127
+ const fresh = writesDone.current === writesAtStart;
128
+ if (fresh) {
129
+ confirmed.current = read;
130
+ if (!waiting.current) {
131
+ setStored(read);
132
+ if (read) deviceSetter.current(Object.keys(read).length ? read : void 0);
133
+ }
134
+ }
135
+ release(fresh ? read : confirmed.current);
87
136
  setReady(true);
88
137
  },
89
138
  (error) => {
90
139
  reportError(error, "core:appearance-preferences");
91
- if (active) setReady(true);
140
+ if (!active) return;
141
+ release(deviceRef.current);
142
+ setReady(true);
92
143
  }
93
144
  );
94
145
  const unsubscribe = store.subscribe?.((values) => {
95
- if (active) setStored(values ? toAppearancePreferenceValues(values) : null);
146
+ if (!active) return;
147
+ const next = values ? toAppearancePreferenceValues(values) : null;
148
+ confirmed.current = next;
149
+ writesDone.current += 1;
150
+ const shown = waiting.current ? toAppearancePreferenceValues({ ...next ?? {}, ...waiting.current }) : next;
151
+ setStored(shown);
152
+ if (shown) deviceSetter.current(Object.keys(shown).length ? shown : void 0);
96
153
  });
97
154
  return () => {
98
155
  active = false;
@@ -100,18 +157,54 @@ function AppearancePreferencesProvider({ preferences = DEVICE_ONLY, organization
100
157
  };
101
158
  }, [store]);
102
159
  const person = useMemo(() => ({ ...device, ...stored ?? {} }), [device, stored]);
160
+ const deviceRef = useRef(device);
161
+ deviceRef.current = device;
162
+ const drain = useCallback(async () => {
163
+ const q = queue.current;
164
+ if (q.running) return;
165
+ q.running = true;
166
+ try {
167
+ while (q.next) {
168
+ const { patch, generation: owner } = q.next;
169
+ q.next = null;
170
+ const target = latestStore.current;
171
+ if (!target) break;
172
+ if (owner !== generation.current) continue;
173
+ const values = toAppearancePreferenceValues({ ...confirmed.current ?? {}, ...patch });
174
+ try {
175
+ const freshAtStart = writesDone.current;
176
+ await target.write(values, { previous: confirmed.current });
177
+ if (owner !== generation.current) continue;
178
+ if (writesDone.current === freshAtStart) confirmed.current = values;
179
+ writesDone.current += 1;
180
+ } catch (error) {
181
+ const handler = writeErrorHandler.current;
182
+ if (handler) handler(error, values);
183
+ else reportError(error, "core:appearance-preferences");
184
+ }
185
+ }
186
+ } finally {
187
+ q.running = false;
188
+ }
189
+ }, []);
190
+ const drainRef = useRef(drain);
191
+ drainRef.current = drain;
103
192
  const save = useCallback(
104
193
  (patch) => {
105
194
  const next = toAppearancePreferenceValues({ ...person, ...patch });
106
195
  setDevice(Object.keys(next).length ? next : void 0);
107
196
  if (latestStore.current) {
108
197
  setStored(next);
109
- void Promise.resolve().then(() => latestStore.current?.write(next)).catch((error) => {
110
- reportError(error, "core:appearance-preferences");
111
- });
198
+ if (firstRead.current === "pending") {
199
+ waiting.current = { ...waiting.current ?? {}, ...patch };
200
+ return;
201
+ }
202
+ const q = queue.current;
203
+ q.next = { patch: { ...q.next?.generation === generation.current ? q.next.patch : {}, ...patch }, generation: generation.current };
204
+ void drain();
112
205
  }
113
206
  },
114
- [person, setDevice]
207
+ [person, setDevice, drain]
115
208
  );
116
209
  const value = useMemo(() => {
117
210
  const layers = { lock, person, organization, theme };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/appearance.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFO,SAAS,2BAAA,CAA4B,UAAA,GAA8C,EAAC,EAA0B;AACnH,EAAA,MAAM,WAAqB,EAAC;AAC5B,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,IAAA,IAAQ,EAAC;AACjC,EAAA,IAAI,IAAA,CAAK,UAAA,KAAe,MAAA,IAAa,CAAC,aAAa,IAAA,CAAK,UAAU,CAAA,EAAG,QAAA,CAAS,KAAK,CAAA,wBAAA,EAA2B,WAAA,CAAY,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AACtI,EAAA,IAAI,IAAA,CAAK,OAAA,KAAY,MAAA,IAAa,CAAC,UAAU,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ACL,GAAG,QAAA;AAAA,MACH,MAAA;AAAA,MACA,MAAA;AAAA,MACA,MAAA;AAAA,MACA,KAAA;AAAA,MACA,aAAA,EAAe,CAAC,UAAA,KAAe;AAC7B,QAAA,IAAI,CAAC,MAAA,CAAO,UAAA,EAAY,IAAA,CAAK,EAAE,YAAY,CAAA;AAAA,MAC7C,CAAA;AAAA,MACA,UAAA,EAAY,CAAC,OAAA,KAAY;AACvB,QAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,IAAA,CAAK,EAAE,SAAS,CAAA;AAAA,MACvC;AAAA,KACF;AAAA,EACF,CAAA,EAAG,CAAC,IAAA,EAAM,MAAA,EAAQ,cAAc,KAAA,EAAO,KAAA,EAAO,IAAI,CAAC,CAAA;AAEnD,EAAA,uBAAO,GAAA,CAAC,4BAAA,CAA6B,QAAA,EAA7B,EAAsC,OAAe,QAAA,EAAS,CAAA;AACxE;AASO,SAAS,wBAAA,GAA2D;AACzE,EAAA,MAAM,KAAA,GAAQ,WAAW,4BAA4B,CAAA;AACrD,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,kFAAkF,CAAA;AAC9G,EAAA,OAAO,KAAA;AACT;AAQO,SAAS,gCAAA,GAA0E;AACxF,EAAA,OAAO,WAAW,4BAA4B,CAAA;AAChD","file":"index.js","sourcesContent":["\"use client\";\n/**\n * Appearance preferences (ADR 0024): who sets a person's appearance (light, dark or system) and\n * density (compact, comfortable, spacious).\n *\n * Both are the person's. An app can lock either one; an organization can set a default for its\n * people; an app theme sets the default under that; Genesis's own default is last:\n *\n * app lock > person > organization default > theme default > Genesis default\n *\n * `resolveAppearancePreferences` is that order as a pure function. `defineAppearancePreferences`\n * declares an app's lock, defaults and where a person's choice is kept: a store (an adapter the\n * app backs with its own server table, so the choice follows the person to every device), with\n * the device's storage (`useStorage()`) as a copy and the fallback. `AppearancePreferencesProvider`\n * serves it to the tree: genesis-ui's `AppearanceProvider` (light and dark) and `AppShell`\n * (density) read it when it is there, and work as before when it isn't.\n *\n * Brand is not here: an organization sets its brand (`WorkspaceTheme.brand`), and the app sets\n * the theme per area.\n */\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { usePersistedUiState } from \"./hooks/use-persisted-ui-state\";\nimport { reportError } from \"./errors\";\nimport {\n APPEARANCES,\n DENSITIES,\n isAppearance,\n isDensity,\n resolveAppearancePreferences,\n toAppearancePreferenceValues,\n type Appearance,\n type AppearancePreferenceLayers,\n type AppearancePreferenceValues,\n type Density,\n type ResolvedAppearancePreferences,\n} from \"./appearance-values\";\n\n/**\n * Where a person's appearance preferences are kept: an adapter an app backs with its own server\n * table (a `profiles` row, say), so the choice follows the person. `read` may be async; return\n * null when the person has chosen nothing. `subscribe` (optional) reports a change made elsewhere.\n *\n * @stability Beta\n */\nexport interface AppearancePreferencesStore {\n read(): AppearancePreferenceValues | null | undefined | Promise<AppearancePreferenceValues | null | undefined>;\n write(values: AppearancePreferenceValues): void | Promise<void>;\n subscribe?(onChange: (values: AppearancePreferenceValues | null) => void): () => void;\n}\n\n/** What `defineAppearancePreferences` accepts. */\nexport interface AppearancePreferencesDefinition {\n /** Where the person's choice is kept beyond this device. Unset: the device only. */\n store?: AppearancePreferencesStore;\n /** The device copy's storage key (`useStorage()`). Default `genesis-appearance`. */\n storageKey?: string;\n /** Values the app fixes: nobody below can change them. */\n lock?: AppearancePreferenceValues;\n}\n\n/** A defined appearance-preferences setup. */\nexport interface AppearancePreferences {\n readonly store?: AppearancePreferencesStore;\n readonly storageKey: string;\n readonly lock: Readonly<AppearancePreferenceValues>;\n}\n\n/**\n * Declare where a person's appearance and density are kept and what the app locks. Checks the\n * lock and returns it frozen; throws on a value that isn't an appearance or a density.\n *\n * ```ts\n * export const appearance = defineAppearancePreferences({\n * store: {\n * read: () => api.myPreferences(), // { appearance: \"dark\", density: \"compact\" }\n * write: (values) => api.saveMyPreferences(values),\n * },\n * lock: { density: \"comfortable\" },\n * });\n * ```\n *\n * @stability Beta\n */\nexport function defineAppearancePreferences(definition: AppearancePreferencesDefinition = {}): AppearancePreferences {\n const problems: string[] = [];\n const lock = definition.lock ?? {};\n if (lock.appearance !== undefined && !isAppearance(lock.appearance)) problems.push(`lock.appearance: one of ${APPEARANCES.join(\", \")}`);\n if (lock.density !== undefined && !isDensity(lock.density)) problems.push(`lock.density: one of ${DENSITIES.join(\", \")}`);\n if (definition.store && (typeof definition.store.read !== \"function\" || typeof definition.store.write !== \"function\"))\n problems.push(\"store: an object with read() and write()\");\n if (definition.storageKey !== undefined && (typeof definition.storageKey !== \"string\" || !definition.storageKey.trim()))\n problems.push(\"storageKey: a non-empty string\");\n if (problems.length) throw new Error(`defineAppearancePreferences: ${problems.join(\"; \")}`);\n return Object.freeze({\n ...(definition.store ? { store: definition.store } : {}),\n storageKey: definition.storageKey ?? \"genesis-appearance\",\n lock: Object.freeze(toAppearancePreferenceValues(lock)),\n });\n}\n\n/** What `useAppearancePreferences` returns. */\nexport interface UseAppearancePreferencesReturn extends ResolvedAppearancePreferences {\n /** The person's own choice (the store's, else this device's), before the order is applied. */\n person: AppearancePreferenceValues;\n /** Which values the app has locked. */\n locked: { appearance: boolean; density: boolean };\n /**\n * Every layer as given, for a component with a default of its own to put in the order\n * (`AppShell` puts its `options.density` under the theme's).\n */\n layers: AppearancePreferenceLayers;\n /** False until the store's first read has answered. */\n ready: boolean;\n /** Save the person's appearance (`undefined` clears it back to the defaults). Ignored when locked. */\n setAppearance(appearance: Appearance | undefined): void;\n /** Save the person's density (`undefined` clears it). Ignored when locked. */\n setDensity(density: Density | undefined): void;\n}\n\nconst AppearancePreferencesContext = createContext<UseAppearancePreferencesReturn | null>(null);\n\nconst FORMAT = {\n parse: (raw: string) => {\n try {\n return toAppearancePreferenceValues(JSON.parse(raw));\n } catch {\n return undefined;\n }\n },\n};\nconst NONE: AppearancePreferenceValues = {};\n\nexport interface AppearancePreferencesProviderProps {\n /** From `defineAppearancePreferences`. Default: this device only, nothing locked. */\n preferences?: AppearancePreferences;\n /** The active organization's defaults (`resolveWorkspaceAppearance(workspace)`). */\n organization?: AppearancePreferenceValues | undefined;\n /** The app theme's defaults. */\n theme?: AppearancePreferenceValues | undefined;\n children: ReactNode;\n}\n\nconst DEVICE_ONLY = defineAppearancePreferences();\n\n/**\n * Serves a person's appearance and density to the tree, resolved in the written order. Reads the\n * store once on mount (and on its `subscribe`), keeps a copy on the device, and writes both when\n * the person changes a value.\n *\n * @stability Beta\n */\nexport function AppearancePreferencesProvider({ preferences = DEVICE_ONLY, organization, theme, children }: AppearancePreferencesProviderProps) {\n const { store, storageKey, lock } = preferences;\n const [device, setDevice] = usePersistedUiState<AppearancePreferenceValues>(storageKey, NONE, FORMAT);\n const [stored, setStored] = useState<AppearancePreferenceValues | null | undefined>(undefined);\n const [ready, setReady] = useState(!store);\n const latestStore = useRef(store);\n latestStore.current = store;\n\n useEffect(() => {\n if (!store) return;\n let active = true;\n Promise.resolve()\n .then(() => store.read())\n .then(\n (values) => {\n if (!active) return;\n setStored(values ? toAppearancePreferenceValues(values) : null);\n setReady(true);\n },\n (error: unknown) => {\n // A store that can't be read leaves the device's copy in charge.\n reportError(error, \"core:appearance-preferences\");\n if (active) setReady(true);\n },\n );\n const unsubscribe = store.subscribe?.((values) => {\n if (active) setStored(values ? toAppearancePreferenceValues(values) : null);\n });\n return () => {\n active = false;\n unsubscribe?.();\n };\n }, [store]);\n\n // The store's answer is the person's choice; the device's copy fills in until it comes, and\n // when there is no store.\n const person = useMemo<AppearancePreferenceValues>(() => ({ ...device, ...(stored ?? {}) }), [device, stored]);\n\n const save = useCallback(\n (patch: AppearancePreferenceValues) => {\n // An undefined value in the patch clears that key: the spread sets it, and the check drops it.\n const next = toAppearancePreferenceValues({ ...person, ...patch });\n setDevice(Object.keys(next).length ? next : undefined);\n if (latestStore.current) {\n setStored(next);\n void Promise.resolve()\n .then(() => latestStore.current?.write(next))\n .catch((error: unknown) => {\n reportError(error, \"core:appearance-preferences\");\n });\n }\n },\n [person, setDevice],\n );\n\n const value = useMemo<UseAppearancePreferencesReturn>(() => {\n const layers: AppearancePreferenceLayers = { lock, person, organization, theme };\n const resolved = resolveAppearancePreferences(layers);\n const locked = { appearance: lock.appearance !== undefined, density: lock.density !== undefined };\n return {\n ...resolved,\n person,\n locked,\n layers,\n ready,\n setAppearance: (appearance) => {\n if (!locked.appearance) save({ appearance });\n },\n setDensity: (density) => {\n if (!locked.density) save({ density });\n },\n };\n }, [lock, person, organization, theme, ready, save]);\n\n return <AppearancePreferencesContext.Provider value={value}>{children}</AppearancePreferencesContext.Provider>;\n}\n\n/**\n * The person's appearance and density, resolved, with setters. Throws outside an\n * `AppearancePreferencesProvider`; a component that works with or without one reads\n * `useOptionalAppearancePreferences`.\n *\n * @stability Beta\n */\nexport function useAppearancePreferences(): UseAppearancePreferencesReturn {\n const value = useContext(AppearancePreferencesContext);\n if (!value) throw new Error(\"useAppearancePreferences: no AppearancePreferencesProvider above this component.\");\n return value;\n}\n\n/**\n * Like `useAppearancePreferences`, but null outside a provider: for a component (a shell, a\n * theme provider) that keeps its own behaviour when an app hasn't set preferences up.\n *\n * @stability Beta\n */\nexport function useOptionalAppearancePreferences(): UseAppearancePreferencesReturn | null {\n return useContext(AppearancePreferencesContext);\n}\n"]}
1
+ {"version":3,"sources":["../src/appearance.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGO,SAAS,2BAAA,CAA4B,UAAA,GAA8C,EAAC,EAA0B;AACnH,EAAA,MAAM,WAAqB,EAAC;AAC5B,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,IAAA,IAAQ,EAAC;AACjC,EAAA,IAAI,IAAA,CAAK,UAAA,KAAe,MAAA,IAAa,CAAC,aAAa,IAAA,CAAK,UAAU,CAAA,EAAG,QAAA,CAAS,KAAK,CAAA,wBAAA,EAA2B,WAAA,CAAY,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAA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AA;AACxE;AASO,SAAS,wBAAA,GAA2D;AACzE,EAAA,MAAM,KAAA,GAAQ,WAAW,4BAA4B,CAAA;AACrD,EAAA,IAAI,CAAC,KAAA,EAAO,MAAM,IAAI,MAAM,kFAAkF,CAAA;AAC9G,EAAA,OAAO,KAAA;AACT;AAQO,SAAS,gCAAA,GAA0E;AACxF,EAAA,OAAO,WAAW,4BAA4B,CAAA;AAChD","file":"index.js","sourcesContent":["\"use client\";\n/**\n * Appearance preferences (ADR 0024): who sets a person's appearance (light, dark or system) and\n * density (compact, comfortable, spacious).\n *\n * Both are the person's. An app can lock either one; an organization can set a default for its\n * people; an app theme sets the default under that; Genesis's own default is last:\n *\n * app lock > person > organization default > theme default > Genesis default\n *\n * `resolveAppearancePreferences` is that order as a pure function. `defineAppearancePreferences`\n * declares an app's lock, defaults and where a person's choice is kept: a store (an adapter the\n * app backs with its own server table, so the choice follows the person to every device), with\n * the device's storage (`useStorage()`) as a copy and the fallback. `AppearancePreferencesProvider`\n * serves it to the tree: genesis-ui's `AppearanceProvider` (light and dark) and `AppShell`\n * (density) read it when it is there, and work as before when it isn't.\n *\n * Brand is not here: an organization sets its brand (`WorkspaceTheme.brand`), and the app sets\n * the theme per area.\n */\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { usePersistedUiState } from \"./hooks/use-persisted-ui-state\";\nimport { reportError } from \"./errors\";\nimport {\n APPEARANCES,\n DENSITIES,\n isAppearance,\n isDensity,\n resolveAppearancePreferences,\n toAppearancePreferenceValues,\n type Appearance,\n type AppearancePreferenceLayers,\n type AppearancePreferenceValues,\n type Density,\n type ResolvedAppearancePreferences,\n} from \"./appearance-values\";\n\n/**\n * Where a person's appearance preferences are kept: an adapter an app backs with its own server\n * table (a `profiles` row, say), so the choice follows the person. `read` may be async; return\n * null when the person has chosen nothing. `subscribe` (optional) reports a change made elsewhere.\n *\n * @stability Beta\n */\nexport interface AppearancePreferencesStore {\n read(): AppearancePreferenceValues | null | undefined | Promise<AppearancePreferenceValues | null | undefined>;\n /**\n * Save the person's values. Writes are sent one at a time, in order, and a write that a newer\n * one replaces before it starts is skipped. `context.previous` is what the store last answered\n * or accepted (null for nothing yet), so a store can write conditionally (compare and set) and\n * refuse a write made from a stale copy by throwing: `onWriteError` hears it.\n */\n write(values: AppearancePreferenceValues, context: AppearanceWriteContext): void | Promise<void>;\n subscribe?(onChange: (values: AppearancePreferenceValues | null) => void): () => void;\n}\n\n/** What a store's `write` is told beside the values. @stability Beta */\nexport interface AppearanceWriteContext {\n /** The values the store last read or accepted; null when it has none yet. */\n readonly previous: AppearancePreferenceValues | null;\n}\n\n/** What `defineAppearancePreferences` accepts. */\nexport interface AppearancePreferencesDefinition {\n /** Where the person's choice is kept beyond this device. Unset: the device only. */\n store?: AppearancePreferencesStore;\n /** The device copy's storage key (`useStorage()`). Default `genesis-appearance`. */\n storageKey?: string;\n /** Values the app fixes: nobody below can change them. */\n lock?: AppearancePreferenceValues;\n /**\n * Hears a store write that failed (offline, refused, a conditional write that lost), with the\n * values it tried to save. The device keeps the choice for this visit; the next successful read\n * of the store (another visit, another device) wins over it. Default: the\n * error goes to `reportError`.\n */\n onWriteError?: (error: unknown, values: AppearancePreferenceValues) => void;\n}\n\n/** A defined appearance-preferences setup. */\nexport interface AppearancePreferences {\n readonly store?: AppearancePreferencesStore;\n readonly storageKey: string;\n readonly lock: Readonly<AppearancePreferenceValues>;\n readonly onWriteError?: (error: unknown, values: AppearancePreferenceValues) => void;\n}\n\n/**\n * Declare where a person's appearance and density are kept and what the app locks. Checks the\n * lock and returns it frozen; throws on a value that isn't an appearance or a density.\n *\n * ```ts\n * export const appearance = defineAppearancePreferences({\n * store: {\n * read: () => api.myPreferences(), // { appearance: \"dark\", density: \"compact\" }\n * write: (values) => api.saveMyPreferences(values),\n * },\n * lock: { density: \"comfortable\" },\n * });\n * ```\n *\n * @stability Beta\n */\nexport function defineAppearancePreferences(definition: AppearancePreferencesDefinition = {}): AppearancePreferences {\n const problems: string[] = [];\n const lock = definition.lock ?? {};\n if (lock.appearance !== undefined && !isAppearance(lock.appearance)) problems.push(`lock.appearance: one of ${APPEARANCES.join(\", \")}`);\n if (lock.density !== undefined && !isDensity(lock.density)) problems.push(`lock.density: one of ${DENSITIES.join(\", \")}`);\n if (definition.store && (typeof definition.store.read !== \"function\" || typeof definition.store.write !== \"function\"))\n problems.push(\"store: an object with read() and write()\");\n if (definition.storageKey !== undefined && (typeof definition.storageKey !== \"string\" || !definition.storageKey.trim()))\n problems.push(\"storageKey: a non-empty string\");\n if (definition.onWriteError !== undefined && typeof definition.onWriteError !== \"function\") problems.push(\"onWriteError: a function\");\n if (problems.length) throw new Error(`defineAppearancePreferences: ${problems.join(\"; \")}`);\n return Object.freeze({\n ...(definition.store ? { store: definition.store } : {}),\n ...(definition.onWriteError ? { onWriteError: definition.onWriteError } : {}),\n storageKey: definition.storageKey ?? \"genesis-appearance\",\n lock: Object.freeze(toAppearancePreferenceValues(lock)),\n });\n}\n\n/** What `useAppearancePreferences` returns. */\nexport interface UseAppearancePreferencesReturn extends ResolvedAppearancePreferences {\n /** The person's own choice (the store's, else this device's), before the order is applied. */\n person: AppearancePreferenceValues;\n /** Which values the app has locked. */\n locked: { appearance: boolean; density: boolean };\n /**\n * Every layer as given, for a component with a default of its own to put in the order\n * (`AppShell` puts its `options.density` under the theme's).\n */\n layers: AppearancePreferenceLayers;\n /** False until the store's first read has answered. */\n ready: boolean;\n /** Save the person's appearance (`undefined` clears it back to the defaults). Ignored when locked. */\n setAppearance(appearance: Appearance | undefined): void;\n /** Save the person's density (`undefined` clears it). Ignored when locked. */\n setDensity(density: Density | undefined): void;\n}\n\nconst AppearancePreferencesContext = createContext<UseAppearancePreferencesReturn | null>(null);\n\nconst FORMAT = {\n parse: (raw: string) => {\n try {\n return toAppearancePreferenceValues(JSON.parse(raw));\n } catch {\n return undefined;\n }\n },\n};\nconst NONE: AppearancePreferenceValues = {};\n\nexport interface AppearancePreferencesProviderProps {\n /** From `defineAppearancePreferences`. Default: this device only, nothing locked. */\n preferences?: AppearancePreferences;\n /** The active organization's defaults (`resolveWorkspaceAppearance(workspace)`). */\n organization?: AppearancePreferenceValues | undefined;\n /** The app theme's defaults. */\n theme?: AppearancePreferenceValues | undefined;\n /** Hears a failed store write (wins over the definition's `onWriteError`). */\n onWriteError?: ((error: unknown, values: AppearancePreferenceValues) => void) | undefined;\n children: ReactNode;\n}\n\nconst DEVICE_ONLY = defineAppearancePreferences();\n\n/**\n * Serves a person's appearance and density to the tree, resolved in the written order. Reads the\n * store once on mount (and on its `subscribe`), keeps a copy on the device, and writes both when\n * the person changes a value.\n *\n * @stability Beta\n */\nexport function AppearancePreferencesProvider({ preferences = DEVICE_ONLY, organization, theme, onWriteError, children }: AppearancePreferencesProviderProps) {\n const { store, storageKey, lock } = preferences;\n const [device, setDevice] = usePersistedUiState<AppearancePreferenceValues>(storageKey, NONE, FORMAT);\n const [stored, setStored] = useState<AppearancePreferenceValues | null | undefined>(undefined);\n const [ready, setReady] = useState(!store);\n const latestStore = useRef(store);\n latestStore.current = store;\n // The first read settles before any write goes out: choices made while it's in flight wait here as\n // patches, then go out merged onto what the store said, with that as `previous`.\n const firstRead = useRef<\"pending\" | \"settled\">(store ? \"pending\" : \"settled\");\n const waiting = useRef<AppearancePreferenceValues | null>(null);\n // How many newer values the store has given since a read started (a write it accepted, or a\n // value its `subscribe` delivered): a read that started before one is older than it.\n const writesDone = useRef(0);\n // Which store the queue and its writes belong to: a store change drops what was waiting for the\n // old one, and an old write that completes afterwards changes nothing here.\n const generation = useRef(0);\n // What the store last answered or accepted, for a conditional write.\n const confirmed = useRef<AppearancePreferenceValues | null>(null);\n // One write at a time, in order; the newest waiting write replaces an older waiting one.\n // One write at a time per store: each store generation gets its own queue, so a store never\n // waits behind the last one's write. What waits is a patch (the person's choices), merged onto\n // the store's latest confirmed values when it goes out, so a newer value from another device\n // isn't overwritten by a stale snapshot.\n type Queue = { running: boolean; next: { patch: AppearancePreferenceValues; generation: number } | null };\n const queue = useRef<Queue>({ running: false, next: null });\n const deviceSetter = useRef(setDevice);\n deviceSetter.current = setDevice;\n const writeErrorHandler = useRef(onWriteError ?? preferences.onWriteError);\n writeErrorHandler.current = onWriteError ?? preferences.onWriteError;\n\n useEffect(() => {\n generation.current += 1;\n // What waited for the last store isn't this one's to write: neither a queued write nor a\n // choice held while that store's first read was out (the device keeps its copy).\n queue.current = { running: false, next: null };\n waiting.current = null;\n // What the last store confirmed isn't this one's `previous`: a conditional write to the new\n // store must start from what it says (its read), or from nothing.\n confirmed.current = null;\n if (!store) return;\n let active = true;\n firstRead.current = \"pending\";\n const writesAtStart = writesDone.current;\n // Choices made meanwhile go out now: merged onto what the store said, or onto this device's.\n const release = (base: AppearancePreferenceValues | null) => {\n firstRead.current = \"settled\";\n const patch = waiting.current;\n waiting.current = null;\n if (!patch) return;\n const merged = toAppearancePreferenceValues({ ...(base ?? {}), ...patch });\n setStored(merged);\n deviceSetter.current(Object.keys(merged).length ? merged : undefined);\n queue.current.next = { patch: merged, generation: generation.current };\n void drainRef.current();\n };\n Promise.resolve()\n .then(() => store.read())\n .then(\n (values) => {\n if (!active) return;\n const read = values ? toAppearancePreferenceValues(values) : null;\n // A read older than an accepted write or a delivered value says nothing new: drop it, and\n // put a held patch onto the newest values instead.\n const fresh = writesDone.current === writesAtStart;\n if (fresh) {\n confirmed.current = read;\n if (!waiting.current) {\n setStored(read);\n // The device keeps a copy of what the store said, for the next visit's first paint.\n if (read) deviceSetter.current(Object.keys(read).length ? read : undefined);\n }\n }\n release(fresh ? read : confirmed.current);\n setReady(true);\n },\n (error: unknown) => {\n // A store that can't be read leaves the device's copy in charge.\n reportError(error, \"core:appearance-preferences\");\n if (!active) return;\n release(deviceRef.current);\n setReady(true);\n },\n );\n const unsubscribe = store.subscribe?.((values) => {\n if (!active) return;\n const next = values ? toAppearancePreferenceValues(values) : null;\n confirmed.current = next;\n writesDone.current += 1;\n // The store's values are the baseline; a choice still held for the first read stays on top,\n // shown and kept on the device, until it goes out.\n const shown = waiting.current ? toAppearancePreferenceValues({ ...(next ?? {}), ...waiting.current }) : next;\n setStored(shown);\n if (shown) deviceSetter.current(Object.keys(shown).length ? shown : undefined);\n });\n return () => {\n active = false;\n unsubscribe?.();\n };\n }, [store]);\n\n // The store's answer is the person's choice; the device's copy fills in until it comes, and\n // when there is no store.\n const person = useMemo<AppearancePreferenceValues>(() => ({ ...device, ...(stored ?? {}) }), [device, stored]);\n const deviceRef = useRef(device);\n deviceRef.current = device;\n\n const drain = useCallback(async () => {\n const q = queue.current;\n if (q.running) return;\n q.running = true;\n try {\n while (q.next) {\n const { patch, generation: owner } = q.next;\n q.next = null;\n const target = latestStore.current;\n if (!target) break;\n // Queued for a store that has since been replaced: not this one's to write.\n if (owner !== generation.current) continue;\n const values = toAppearancePreferenceValues({ ...(confirmed.current ?? {}), ...patch });\n try {\n // Newer values the store's subscription delivers while this write is out win over it.\n const freshAtStart = writesDone.current;\n await target.write(values, { previous: confirmed.current });\n // The store changed while it was out: the new one's state isn't this write's.\n if (owner !== generation.current) continue;\n if (writesDone.current === freshAtStart) confirmed.current = values;\n writesDone.current += 1;\n } catch (error: unknown) {\n const handler = writeErrorHandler.current;\n if (handler) handler(error, values);\n else reportError(error, \"core:appearance-preferences\");\n }\n }\n } finally {\n q.running = false;\n }\n }, []);\n const drainRef = useRef(drain);\n drainRef.current = drain;\n\n const save = useCallback(\n (patch: AppearancePreferenceValues) => {\n // An undefined value in the patch clears that key: the spread sets it, and the check drops it.\n const next = toAppearancePreferenceValues({ ...person, ...patch });\n setDevice(Object.keys(next).length ? next : undefined);\n if (latestStore.current) {\n setStored(next);\n if (firstRead.current === \"pending\") {\n // Not yet: the patch waits for the store's answer, so nothing it holds is overwritten.\n waiting.current = { ...(waiting.current ?? {}), ...patch };\n return;\n }\n const q = queue.current;\n // Kept raw: an undefined value (a cleared choice) must survive to clear the key on write.\n q.next = { patch: { ...(q.next?.generation === generation.current ? q.next.patch : {}), ...patch }, generation: generation.current };\n void drain();\n }\n },\n [person, setDevice, drain],\n );\n\n const value = useMemo<UseAppearancePreferencesReturn>(() => {\n const layers: AppearancePreferenceLayers = { lock, person, organization, theme };\n const resolved = resolveAppearancePreferences(layers);\n const locked = { appearance: lock.appearance !== undefined, density: lock.density !== undefined };\n return {\n ...resolved,\n person,\n locked,\n layers,\n ready,\n setAppearance: (appearance) => {\n if (!locked.appearance) save({ appearance });\n },\n setDensity: (density) => {\n if (!locked.density) save({ density });\n },\n };\n }, [lock, person, organization, theme, ready, save]);\n\n return <AppearancePreferencesContext.Provider value={value}>{children}</AppearancePreferencesContext.Provider>;\n}\n\n/**\n * The person's appearance and density, resolved, with setters. Throws outside an\n * `AppearancePreferencesProvider`; a component that works with or without one reads\n * `useOptionalAppearancePreferences`.\n *\n * @stability Beta\n */\nexport function useAppearancePreferences(): UseAppearancePreferencesReturn {\n const value = useContext(AppearancePreferencesContext);\n if (!value) throw new Error(\"useAppearancePreferences: no AppearancePreferencesProvider above this component.\");\n return value;\n}\n\n/**\n * Like `useAppearancePreferences`, but null outside a provider: for a component (a shell, a\n * theme provider) that keeps its own behaviour when an app hasn't set preferences up.\n *\n * @stability Beta\n */\nexport function useOptionalAppearancePreferences(): UseAppearancePreferencesReturn | null {\n return useContext(AppearancePreferencesContext);\n}\n"]}
@@ -1,8 +1,8 @@
1
- import { D as DataProvider, d as Identifier, B as BaseRecord, I as InvalidationKey, W as WriteEvent, n as CountMode, a as FilterParam } from '../types-BriIV4e_.js';
2
- export { i as AggregateMetric, A as AggregateParams, b as AggregateResult, k as ArrayFilter, l as BulkChange, m as BulkResult, o as CreateParams, p as CreateResult, q as DeleteParams, r as DeleteResult, G as GetManyParams, v as GetManyResult, w as GetOneParams, x as GetOneResult, H as HistoryParams, y as ImportParams, c as ListParams, L as ListResult, N as NullFilter, z as PaginationParam, E as RangeFilter, g as ResourceChangeEvent, V as RowFailure, Y as ScalarFilter, S as SortParam, f as SubscribeParams, $ as UpdateParams, a0 as UpdateResult } from '../types-BriIV4e_.js';
3
- export { R as ResolveAggregateOptions, a as aggregateProblems, r as resolveAggregate, t as toAggregateValues } from '../aggregate-Y5IJ5aPn.js';
4
- import { D as DataWriteError, W as WriteOutcome } from '../write-outcome-CkQXgtJq.js';
5
- export { a as DataWriteErrorOptions, N as NO_ROWS_MATCHED, i as isDataWriteError } from '../write-outcome-CkQXgtJq.js';
1
+ import { D as DataProvider, a as FilterParam, c as Identifier, B as BaseRecord, I as InvalidationKey, W as WriteEvent, q as CountMode } from '../types-CiQY6hUy.js';
2
+ export { k as AggregateMetric, A as AggregateParams, d as AggregateResult, n as ArrayFilter, o as BulkChange, p as BulkResult, r as CreateParams, s as CreateResult, t as DeleteParams, u as DeleteResult, G as GetManyParams, y as GetManyResult, z as GetOneParams, E as GetOneResult, H as HistoryParams, J as ImportParams, b as ListParams, L as ListResult, N as NullFilter, K as PaginationParam, M as RangeFilter, h as ResourceChangeEvent, X as RowFailure, Y as ScalarFilter, S as SortParam, g as SubscribeParams, $ as UpdateParams, a0 as UpdateResult } from '../types-CiQY6hUy.js';
3
+ export { R as ResolveAggregateOptions, a as aggregateProblems, r as resolveAggregate, t as toAggregateValues } from '../aggregate-v_r-nZbH.js';
4
+ import { D as DataWriteError, W as WriteOutcome } from '../write-outcome-DuwfsnyO.js';
5
+ export { a as DataWriteErrorOptions, N as NO_ROWS_MATCHED, i as isDataWriteError } from '../write-outcome-DuwfsnyO.js';
6
6
  import { D as DataReadError, R as ReadOutcome } from '../read-outcome-BnboMYOV.js';
7
7
  export { a as DataReadErrorOptions, i as isDataReadError, r as readFailureMessage } from '../read-outcome-BnboMYOV.js';
8
8
  import * as react from 'react';
@@ -138,7 +138,39 @@ interface SupabaseUpdateContext {
138
138
  */
139
139
  expectedVersion?: string;
140
140
  }
141
+ /**
142
+ * A function source that pages itself (`SupabaseResourceConfig.source`'s `pages`): the order its
143
+ * rows come in, and the column that carries the whole result's count. A count alone asks the
144
+ * function for `page_limit: 0`, which it answers with one row that carries the count (and builds
145
+ * no other row).
146
+ *
147
+ * @stability Beta
148
+ */
149
+ interface SourcePages {
150
+ readonly order?: readonly {
151
+ field: string;
152
+ order: "asc" | "desc";
153
+ }[];
154
+ readonly total?: string;
155
+ }
141
156
  /** Per-resource rules for `createSupabaseProvider`. Every field is optional. */
157
+ /**
158
+ * What a function source's `args` gets (`SupabaseResourceConfig.source`): the list's filters,
159
+ * which carry the viewer's scope, and `take`, which reads one equality filter's value (`null` for
160
+ * "is empty") and keeps that filter out of the query.
161
+ *
162
+ * @stability Beta
163
+ */
164
+ interface SourceArgsContext {
165
+ readonly resource: string;
166
+ readonly filters: readonly FilterParam[];
167
+ take(field: string): string | number | boolean | null | undefined;
168
+ /**
169
+ * The values of a filter on `field` that an `in` (or an `eq`, as one value) gives, taken out of
170
+ * the query like `take`; undefined when there's none. For a function that filters by a list.
171
+ */
172
+ takeIn(field: string): readonly unknown[] | undefined;
173
+ }
142
174
  interface SupabaseResourceConfig {
143
175
  /** Singular noun for failure messages, e.g. "project". Defaults to "record". */
144
176
  noun?: string;
@@ -235,13 +267,34 @@ interface SupabaseResourceConfig {
235
267
  * ```ts
236
268
  * resources: {
237
269
  * tasks: { source: "tasks_with_people" },
238
- * course_progress: { source: { rpc: "group_progress", args: () => ({ group_id: currentGroup() }) } },
270
+ * course_progress: { source: { rpc: "group_progress", args: ({ take }) => ({ group_id: take("group_id") }) } },
239
271
  * }
240
272
  * ```
273
+ *
274
+ * A function's `args` gets the list's filters (`context.filters`), which hold the viewer's scope
275
+ * as ResourceView applies it (a view's `scope: ["group_id"]` filters `group_id`), so a function
276
+ * that takes its scope as an argument reads it there rather than from a module variable.
277
+ * `context.take(field)` returns an equality filter's value and leaves that filter out of the
278
+ * query, for a scope the function takes as an argument and doesn't return as a column. A record
279
+ * read (`getOne`, `getMany`) gets the list's filters from `scope` (less a text search's
280
+ * `contains`, which `useOne` leaves out) when the caller passes them
281
+ * (`useOne`'s `scope`, which ResourceView's table, inbox and NativeResourceView's peek and
282
+ * edit sheet pass for a record off the loaded page), else none, and
283
+ * the function's own default scope applies.
284
+ *
285
+ * A function that pages itself declares `pages`: it takes `page_limit` and `page_offset`
286
+ * arguments, returns its rows in `pages.order` (newest first, say) and carries the whole
287
+ * result's count on each row (`pages.total`, default `total_count`). A list page whose filters
288
+ * the function all took, with no search and no sort other than `pages.order`, then passes the
289
+ * page to the function instead of a `range`, and reads its total from that column, so the
290
+ * function never builds rows outside the page. A count alone (a segment's) sends
291
+ * `page_limit: 0`: the function returns one row carrying the count, and builds no other. Any other list reads every row, as without
292
+ * `pages`, since PostgREST can only filter, search or sort what the function returned.
241
293
  */
242
294
  source?: string | {
243
295
  rpc: string;
244
- args?: () => Record<string, unknown>;
296
+ args?: (context: SourceArgsContext) => Record<string, unknown>;
297
+ pages?: SourcePages;
245
298
  };
246
299
  /**
247
300
  * How lists of this resource count their total (default `exact`). Use
@@ -535,4 +588,4 @@ type GenesisProviderProps = {
535
588
  */
536
589
  declare function GenesisProvider({ children, provider, mock, storage, queryClient: queryClientProp, persist, persistScope, }: GenesisProviderProps): react.JSX.Element;
537
590
 
538
- export { BaseRecord, type CallRpcOptions, CountMode, type CreateOrAdoptOptions, type CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProvider, DataProviderRoot, type DataProviderRootProps, DataReadError, DataWriteError, FilterParam, GenesisProvider, type GenesisProviderProps, Identifier, InvalidationKey, type MockProviderOptions, type PostgrestFieldErrors, RPC_FAILED, ReadOutcome, type RpcClient, type SupabaseClient, type SupabaseClientInput, type SupabaseProviderOptions, type SupabaseRealtimeChannel, type SupabaseRealtimePayload, type SupabaseResourceConfig, type SupabaseUpdateContext, type SupabaseWriteContext, WriteEvent, WriteOutcome, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode };
591
+ export { BaseRecord, type CallRpcOptions, CountMode, type CreateOrAdoptOptions, type CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProvider, DataProviderRoot, type DataProviderRootProps, DataReadError, DataWriteError, FilterParam, GenesisProvider, type GenesisProviderProps, Identifier, InvalidationKey, type MockProviderOptions, type PostgrestFieldErrors, RPC_FAILED, ReadOutcome, type RpcClient, type SourceArgsContext, type SourcePages, type SupabaseClient, type SupabaseClientInput, type SupabaseProviderOptions, type SupabaseRealtimeChannel, type SupabaseRealtimePayload, type SupabaseResourceConfig, type SupabaseUpdateContext, type SupabaseWriteContext, WriteEvent, WriteOutcome, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode };
@@ -1,5 +1,5 @@
1
- export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-7EFTWOMA.js';
2
- export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-R3YXYVWF.js';
1
+ export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-UNEZF3ZP.js';
2
+ export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-OIZNABG4.js';
3
3
  export { aggregateProblems, resolveAggregate, toAggregateValues } from '../chunk-J54XXKQD.js';
4
4
  import '../chunk-4PTQYT5J.js';
5
5
  export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-NOPS5EIH.js';