@stacksjs/defaults 0.75.489 → 0.75.492

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 (153) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-dashboard/SKILL.md +20 -2
  3. package/ai/skills/stacks-native/CATALOG.md +9 -9
  4. package/ai/skills/stacks-search-engine/SKILL.md +14 -0
  5. package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
  6. package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
  7. package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
  8. package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
  9. package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
  10. package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
  11. package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
  12. package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
  13. package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
  14. package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
  15. package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
  16. package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
  17. package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
  18. package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
  19. package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
  20. package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
  21. package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
  22. package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
  23. package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
  24. package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
  25. package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
  26. package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
  27. package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
  28. package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
  29. package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
  30. package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
  31. package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
  32. package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
  33. package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
  34. package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
  35. package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
  36. package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
  37. package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
  38. package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
  39. package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
  40. package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
  41. package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
  42. package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
  43. package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
  44. package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
  45. package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
  46. package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
  47. package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
  48. package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
  49. package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
  50. package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
  51. package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
  52. package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
  53. package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
  54. package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
  55. package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
  56. package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
  57. package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
  58. package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
  59. package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
  60. package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
  61. package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
  62. package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
  63. package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
  64. package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
  65. package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
  66. package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
  67. package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
  68. package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
  69. package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
  70. package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
  71. package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
  72. package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
  73. package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
  74. package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
  75. package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
  76. package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
  77. package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
  78. package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
  79. package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
  80. package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
  81. package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
  82. package/app/Actions/Dashboard/Content/content-list.ts +10 -0
  83. package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
  84. package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
  85. package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
  86. package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
  87. package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
  88. package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
  89. package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
  90. package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
  91. package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
  92. package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
  93. package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
  94. package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
  95. package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
  96. package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
  97. package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
  98. package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
  99. package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
  100. package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
  101. package/app/Actions/Dashboard/named-search.test.ts +36 -0
  102. package/app/Actions/Dashboard/named-search.ts +80 -0
  103. package/app/Models/Request.ts +4 -2
  104. package/functions/commerce/shippings/dashboard-resource.ts +12 -1
  105. package/functions/commerce/shippings/delivery-routes.ts +1 -0
  106. package/functions/commerce/shippings/license-keys.ts +1 -0
  107. package/functions/dashboard-list.test.ts +146 -1
  108. package/functions/dashboard-list.ts +216 -1
  109. package/functions/queue.ts +2 -0
  110. package/ide/vscode/package.json +1 -1
  111. package/package.json +2 -2
  112. package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
  113. package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
  114. package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
  115. package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
  116. package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
  117. package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
  118. package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
  119. package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
  120. package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
  121. package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
  122. package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
  123. package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
  124. package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
  125. package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
  126. package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
  127. package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
  128. package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
  129. package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
  130. package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
  131. package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
  132. package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
  133. package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
  134. package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
  135. package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
  136. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
  137. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
  138. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
  139. package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
  140. package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
  141. package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
  142. package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
  143. package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
  144. package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
  145. package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
  146. package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
  147. package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
  148. package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
  149. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
  150. package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
  151. package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
  152. package/routes/dashboard-api.ts +11 -0
  153. package/views/dashboard/stores/kanban.ts +38 -6
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it } from 'bun:test'
2
- import { pageControls, useRecordsDashboard } from './dashboard-list'
2
+ import { state } from '@stacksjs/stx'
3
+ import { LARGEST_PAGE, pageControls, readEveryPage, useRecordsDashboard, useServerList } from './dashboard-list'
3
4
 
4
5
  /** The smallest thing with the two members `pageControls` reads. */
5
6
  function pageSignal(initial: number) {
@@ -226,3 +227,147 @@ describe('useRecordsDashboard goToPage', () => {
226
227
  expect(d.page()).toBe(1)
227
228
  })
228
229
  })
230
+
231
+ describe('useServerList', () => {
232
+ /** A fetch that records what it was asked and answers when told to. */
233
+ function server() {
234
+ const asked: URLSearchParams[] = []
235
+ const pending: Array<(answer: { records: string[], total: number, page: number }) => void> = []
236
+ const fetch = (params: URLSearchParams) => {
237
+ asked.push(params)
238
+ return new Promise<{ records: string[], total: number, page: number }>(resolve => pending.push(resolve))
239
+ }
240
+ return { asked, pending, fetch }
241
+ }
242
+ const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
243
+
244
+ it('asks for the default order and lands the answer', async () => {
245
+ const api = server()
246
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: { sort: 'created', direction: 'desc' } })
247
+ const loading = list.load()
248
+ expect(api.asked[0]!.toString()).toBe('sort=created&direction=desc&page=1&per_page=25')
249
+ api.pending[0]!({ records: ['a', 'b'], total: 30, page: 1 })
250
+ await loading
251
+ expect(list.records()).toEqual(['a', 'b'])
252
+ expect(list.total()).toBe(30)
253
+ expect(list.loading()).toBe(false)
254
+ })
255
+
256
+ it('keeps only the newest answer when two overlap', async () => {
257
+ const api = server()
258
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: { sort: 'created', direction: 'desc' } })
259
+ const first = list.load()
260
+ const second = list.load()
261
+ api.pending[1]!({ records: ['new'], total: 1, page: 1 })
262
+ api.pending[0]!({ records: ['old'], total: 9, page: 1 })
263
+ await Promise.all([first, second])
264
+ expect(list.records()).toEqual(['new'])
265
+ expect(list.total()).toBe(1)
266
+ })
267
+
268
+ it('asks for page 1 when a filter changes, and leaves out "all"', async () => {
269
+ const api = server()
270
+ const status = state('all')
271
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: { sort: 'id', direction: 'asc' }, filters: () => ({ status: status() }) })
272
+ list.page.set(3)
273
+ status.set('active')
274
+ expect(api.asked.length).toBe(1)
275
+ expect(api.asked[0]!.get('status')).toBe('active')
276
+ expect(api.asked[0]!.get('page')).toBe('1')
277
+ status.set('all')
278
+ expect(api.asked[1]!.has('status')).toBe(false)
279
+ })
280
+
281
+ it('sends the search once typing pauses', async () => {
282
+ const api = server()
283
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: { sort: 'id', direction: 'asc' }, searchDelay: 20 })
284
+ list.search.set('a')
285
+ list.search.set('ab')
286
+ list.search.set('abc ')
287
+ expect(api.asked.length).toBe(0)
288
+ await sleep(40)
289
+ expect(api.asked.length).toBe(1)
290
+ expect(api.asked[0]!.get('q')).toBe('abc')
291
+ expect(list.params().get('q')).toBe('abc')
292
+ })
293
+
294
+ it('maps a column header to the server sort, and an unknown one back to the default', () => {
295
+ const api = server()
296
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: { sort: 'created', direction: 'desc' }, columnSorts: { stopsLabel: 'stops' } })
297
+ list.changeSort({ key: 'stopsLabel', direction: 'asc' })
298
+ expect(api.asked[0]!.get('sort')).toBe('stops')
299
+ expect(api.asked[0]!.get('direction')).toBe('asc')
300
+ list.changeSort({ key: 'notes', direction: 'asc' })
301
+ expect(api.asked[1]!.get('sort')).toBe('created')
302
+ expect(api.asked[1]!.get('direction')).toBe('desc')
303
+ })
304
+
305
+ it('follows a sort select, handing the order back from a header sort', () => {
306
+ const api = server()
307
+ const sort = state<{ sort: string, direction: 'asc' | 'desc' }>({ sort: 'name', direction: 'asc' })
308
+ const list = useServerList<string>({ fetch: api.fetch, defaultSort: () => sort(), columnSorts: { typeLabel: 'type' } })
309
+ list.changeSort({ key: 'typeLabel', direction: 'desc' })
310
+ expect(api.asked[0]!.get('sort')).toBe('type')
311
+ list.page.set(4)
312
+ sort.set({ sort: 'newest', direction: 'desc' })
313
+ expect(api.asked.length).toBe(2)
314
+ expect(api.asked[1]!.get('sort')).toBe('newest')
315
+ expect(api.asked[1]!.get('direction')).toBe('desc')
316
+ expect(api.asked[1]!.get('page')).toBe('1')
317
+ })
318
+
319
+ it('reports a failed load, and ignores one that a newer load replaced', async () => {
320
+ const errors: unknown[] = []
321
+ let calls = 0
322
+ const list = useServerList<string>({
323
+ fetch: async () => {
324
+ calls++
325
+ if (calls === 1)
326
+ throw new Error('boom')
327
+ return { records: ['ok'], total: 1, page: 1 }
328
+ },
329
+ defaultSort: { sort: 'id', direction: 'asc' },
330
+ onError: error => errors.push(error),
331
+ })
332
+ await list.load()
333
+ expect(list.loadError()).toBe('boom')
334
+ expect(errors.length).toBe(1)
335
+ await list.load()
336
+ expect(list.loadError()).toBe('')
337
+ expect(list.records()).toEqual(['ok'])
338
+ })
339
+ })
340
+
341
+ describe('readEveryPage', () => {
342
+ /** A paged endpoint over `count` numbered rows. */
343
+ function endpoint(count: number) {
344
+ const asked: number[] = []
345
+ const get = async (page: number, perPage: number) => {
346
+ asked.push(page)
347
+ const records = Array.from({ length: count }, (_, i) => i + 1).slice((page - 1) * perPage, page * perPage)
348
+ return { records, total: count }
349
+ }
350
+ return { asked, get }
351
+ }
352
+
353
+ it('reads every page, past the 500 a single read used to stop at', async () => {
354
+ const api = endpoint(523)
355
+ const rows = await readEveryPage(api.get)
356
+ expect(rows.length).toBe(523)
357
+ expect(rows.at(-1)).toBe(523)
358
+ expect(api.asked).toEqual([1, 2, 3, 4, 5, 6])
359
+ })
360
+
361
+ it('stops at an exact multiple of the page size, and on an empty list', async () => {
362
+ const exact = endpoint(LARGEST_PAGE * 2)
363
+ expect((await readEveryPage(exact.get)).length).toBe(LARGEST_PAGE * 2)
364
+ expect(exact.asked).toEqual([1, 2])
365
+ const empty = endpoint(0)
366
+ expect(await readEveryPage(empty.get)).toEqual([])
367
+ expect(empty.asked).toEqual([1])
368
+ })
369
+
370
+ it('refuses an answer that is not a page', async () => {
371
+ await expect(readEveryPage(async () => ({ total: 3 }) as never)).rejects.toThrow('without records')
372
+ })
373
+ })
@@ -1,5 +1,5 @@
1
1
  import type { Signal } from '@stacksjs/stx'
2
- import { state } from '@stacksjs/stx'
2
+ import { effect, state } from '@stacksjs/stx'
3
3
 
4
4
  /**
5
5
  * Shared pieces of the dashboard's list screens.
@@ -255,3 +255,218 @@ export function useRecordsDashboard<T>(options: RecordsDashboardOptions<T>): Rec
255
255
  clampPage,
256
256
  }
257
257
  }
258
+
259
+ /** One page as a server-paged list endpoint answers it. */
260
+ export interface ServerListPage<T> {
261
+ records?: T[]
262
+ total?: number
263
+ page?: number
264
+ }
265
+
266
+ export interface ServerListOptions<T> {
267
+ /**
268
+ * Ask for one page. `params` carries `sort`, `direction`, `q`, the filters,
269
+ * `page` and `per_page`, as the commerce list endpoints read them.
270
+ */
271
+ fetch: (params: URLSearchParams) => Promise<ServerListPage<T>>
272
+ /**
273
+ * The order before any column header is clicked. An accessor when the page
274
+ * has a sort select: changing it hands the order back from a header sort
275
+ * and asks for page 1.
276
+ */
277
+ defaultSort: { sort: string, direction: 'asc' | 'desc' } | (() => { sort: string, direction: 'asc' | 'desc' })
278
+ /** The table's sortable column keys, as the server's sort names. A column not listed returns to `defaultSort`. */
279
+ columnSorts?: Record<string, string>
280
+ /** The filter values, read reactively: a change asks for page 1. `''` or `'all'` leaves a filter out. */
281
+ filters?: () => Record<string, string>
282
+ /** Rows per page. Default 25, the list endpoints' own default. */
283
+ perPage?: number
284
+ /** How long typing pauses before the search is sent. Default 250ms. */
285
+ searchDelay?: number
286
+ /** Called with whatever a load threw, after `loadError` is set. */
287
+ onError?: (error: unknown) => void
288
+ /** Called with each answer that lands, for anything else it carries (a summary, choices). */
289
+ onLoad?: (result: ServerListPage<T>) => void
290
+ }
291
+
292
+ export interface ServerList<T> {
293
+ records: Signal<T[]>
294
+ /** How many rows match, across every page. */
295
+ total: Signal<number>
296
+ page: Signal<number>
297
+ perPage: Signal<number>
298
+ /** What the search box holds; it is sent once typing pauses. */
299
+ search: Signal<string>
300
+ loading: Signal<boolean>
301
+ loadError: Signal<string>
302
+ /** The search, filters and order as query parameters, without the page: what an export link needs. */
303
+ params: () => URLSearchParams
304
+ /** Ask for the current page again, after a save or a delete. */
305
+ load: () => Promise<void>
306
+ changePage: (value: number | CustomEvent<number>) => void
307
+ changePageSize: (value: number | CustomEvent<number>) => void
308
+ changeSort: (value: { key: string, direction: string } | CustomEvent<{ key: string, direction: string }>) => void
309
+ }
310
+
311
+ function eventValue<V>(value: V | CustomEvent<V>): V {
312
+ return typeof CustomEvent !== 'undefined' && value instanceof CustomEvent ? value.detail : value as V
313
+ }
314
+
315
+ /**
316
+ * A list the server searches, filters, sorts and pages (stacksjs/stacks#3218).
317
+ *
318
+ * The Orders, Payments, Products, Gift Cards, Reviews and waitlist pages each
319
+ * wrote the same request counter, page, page size, header sort and search
320
+ * debounce. This is that, once: only the newest answer lands, a filter or
321
+ * search change asks for page 1, and a column header the server cannot sort
322
+ * by returns to the default order.
323
+ *
324
+ * The caller still owns when to load first (call `load()` in `onMount`), its
325
+ * toasts, and what its endpoint returns beyond the page (`onLoad`).
326
+ */
327
+ export function useServerList<T>(options: ServerListOptions<T>): ServerList<T> {
328
+ const records = state<T[]>([])
329
+ const total = state(0)
330
+ const page = state(1)
331
+ const perPage = state(options.perPage ?? 25)
332
+ const search = state('')
333
+ const loading = state(true)
334
+ const loadError = state('')
335
+ const appliedSearch = state('')
336
+ const headerSort = state<{ sort: string, direction: string } | null>(null)
337
+ let request = 0
338
+ let timer: ReturnType<typeof setTimeout> | null = null
339
+ const defaultOrder = () => typeof options.defaultSort === 'function' ? options.defaultSort() : options.defaultSort
340
+
341
+ const params = (): URLSearchParams => {
342
+ const query = new URLSearchParams()
343
+ const order = headerSort() ?? defaultOrder()
344
+ query.set('sort', order.sort)
345
+ query.set('direction', order.direction)
346
+ if (appliedSearch())
347
+ query.set('q', appliedSearch())
348
+ for (const [name, value] of Object.entries(options.filters?.() ?? {})) {
349
+ if (value !== '' && value !== 'all')
350
+ query.set(name, value)
351
+ }
352
+ return query
353
+ }
354
+
355
+ const load = async (): Promise<void> => {
356
+ const current = ++request
357
+ loading.set(true)
358
+ loadError.set('')
359
+ try {
360
+ const query = params()
361
+ query.set('page', String(page()))
362
+ query.set('per_page', String(perPage()))
363
+ const result = await options.fetch(query)
364
+ if (current !== request)
365
+ return
366
+ records.set(Array.isArray(result.records) ? result.records : [])
367
+ total.set(Number(result.total) || 0)
368
+ page.set(Number(result.page) || 1)
369
+ options.onLoad?.(result)
370
+ }
371
+ catch (error) {
372
+ if (current !== request)
373
+ return
374
+ loadError.set(error instanceof Error ? error.message : String(error))
375
+ options.onError?.(error)
376
+ }
377
+ finally {
378
+ if (current === request)
379
+ loading.set(false)
380
+ }
381
+ }
382
+
383
+ if (options.filters) {
384
+ let shown = JSON.stringify(options.filters())
385
+ effect(() => {
386
+ const filters = JSON.stringify(options.filters!())
387
+ if (filters === shown)
388
+ return
389
+ shown = filters
390
+ page.set(1)
391
+ void load()
392
+ })
393
+ }
394
+
395
+ if (typeof options.defaultSort === 'function') {
396
+ let shownOrder = JSON.stringify(defaultOrder())
397
+ effect(() => {
398
+ const order = JSON.stringify(defaultOrder())
399
+ if (order === shownOrder)
400
+ return
401
+ shownOrder = order
402
+ headerSort.set(null)
403
+ page.set(1)
404
+ void load()
405
+ })
406
+ }
407
+
408
+ let shownSearch = search().trim()
409
+ effect(() => {
410
+ const term = search().trim()
411
+ if (term === shownSearch)
412
+ return
413
+ shownSearch = term
414
+ if (timer)
415
+ clearTimeout(timer)
416
+ timer = setTimeout(() => {
417
+ appliedSearch.set(term)
418
+ page.set(1)
419
+ void load()
420
+ }, options.searchDelay ?? 250)
421
+ })
422
+
423
+ return {
424
+ records,
425
+ total,
426
+ page,
427
+ perPage,
428
+ search,
429
+ loading,
430
+ loadError,
431
+ params,
432
+ load,
433
+ changePage(value) {
434
+ page.set(Number(eventValue(value)) || 1)
435
+ void load()
436
+ },
437
+ changePageSize(value) {
438
+ perPage.set(Number(eventValue(value)) || (options.perPage ?? 25))
439
+ page.set(1)
440
+ void load()
441
+ },
442
+ changeSort(value) {
443
+ const column = eventValue(value)
444
+ const sort = options.columnSorts?.[column.key]
445
+ headerSort.set(sort ? { sort, direction: column.direction === 'asc' ? 'asc' : 'desc' } : null)
446
+ page.set(1)
447
+ void load()
448
+ },
449
+ }
450
+ }
451
+
452
+ /** The largest page the list endpoints serve. */
453
+ export const LARGEST_PAGE = 100
454
+
455
+ /**
456
+ * Every record a paged list endpoint holds, a page at a time: for a caller
457
+ * that does want all of them, such as a resource's `fetchAll`. Stops at the
458
+ * first short page, so a count that moved while it read cannot loop it.
459
+ */
460
+ export async function readEveryPage<T>(
461
+ get: (page: number, perPage: number) => Promise<{ records?: T[], total?: number }>,
462
+ ): Promise<T[]> {
463
+ const all: T[] = []
464
+ for (let page = 1; ; page++) {
465
+ const data = await get(page, LARGEST_PAGE)
466
+ if (!Array.isArray(data?.records))
467
+ throw new TypeError('Server returned a page without records')
468
+ all.push(...data.records)
469
+ if (data.records.length < LARGEST_PAGE || all.length >= Number(data.total))
470
+ return all
471
+ }
472
+ }
@@ -51,6 +51,8 @@ export interface QueueWorkersResponse {
51
51
  data: QueueWorker[]
52
52
  worker_running: boolean
53
53
  active_jobs: number
54
+ /** False when `queue_workers` has not been migrated: there is no worker telemetry to read yet. */
55
+ workers_migrated?: boolean
54
56
  }
55
57
 
56
58
  export async function fetchQueueStats(): Promise<QueueStatsResponse> {
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.489",
5
+ "version": "0.75.492",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.489",
5
+ "version": "0.75.492",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.489",
48
+ "@stacksjs/mobile": "0.75.492",
49
49
  "@stacksjs/sanitizer": "0.2.807",
50
50
  "@stacksjs/stx": "0.2.807",
51
51
  "@xterm/addon-fit": "^0.11.0",
@@ -1,8 +1,35 @@
1
1
  <script client>
2
- import type { GiftCardSummary } from '../../../../app/Actions/Dashboard/Commerce/gift-card-records'
2
+ import type { GiftCardCurrencySummary, GiftCardStatus, GiftCardSummary } from '../../../../app/Actions/Dashboard/Commerce/gift-card-records'
3
3
  import { formatCurrency } from '@stacksjs/commerce/money'
4
4
 
5
- const { summary } = defineProps<{ summary: GiftCardSummary }>()
5
+ // A reactive prop, as every other commerce breakdown reads its data: a
6
+ // destructured `defineProps` value is read once, before the page has loaded
7
+ // anything, so these panels used to render with no numbers at all.
8
+ const summary = useReactiveProp('summary', {
9
+ total: 0,
10
+ available: 0,
11
+ enabled: 0,
12
+ digital: 0,
13
+ reloadable: 0,
14
+ statuses: { ACTIVE: 0, USED: 0, EXPIRED: 0, DEACTIVATED: 0 },
15
+ currencies: [],
16
+ } as GiftCardSummary)
17
+
18
+ const STATUS_LABELS: Array<{ key: GiftCardStatus, label: string }> = [
19
+ { key: 'ACTIVE', label: 'Active' },
20
+ { key: 'USED', label: 'Used' },
21
+ { key: 'EXPIRED', label: 'Expired' },
22
+ { key: 'DEACTIVATED', label: 'Deactivated' },
23
+ ]
24
+
25
+ function statusRows(): Array<{ key: GiftCardStatus, label: string, count: number }> {
26
+ const counts = summary().statuses
27
+ return STATUS_LABELS.map(status => ({ ...status, count: counts?.[status.key] ?? 0 }))
28
+ }
29
+
30
+ function currencyRows(): GiftCardCurrencySummary[] {
31
+ return Array.isArray(summary().currencies) ? summary().currencies : []
32
+ }
6
33
 
7
34
  function money(value: number, currency: string): string {
8
35
  return formatCurrency(value, currency)
@@ -13,18 +40,17 @@ function money(value: number, currency: string): string {
13
40
  <article class="p-4 bg-white dark:bg-neutral-800 border border-gray-200 rounded-lg dark:border-neutral-700">
14
41
  <h2 class="font-semibold text-gray-900 text-sm dark:text-white">Status distribution</h2>
15
42
  <dl class="mt-4 space-y-3 text-sm">
16
- <div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">Active</dt><dd class="font-medium text-gray-900 dark:text-white">{{ summary.statuses.ACTIVE }}</dd></div>
17
- <div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">Used</dt><dd class="font-medium text-gray-900 dark:text-white">{{ summary.statuses.USED }}</dd></div>
18
- <div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">Expired</dt><dd class="font-medium text-gray-900 dark:text-white">{{ summary.statuses.EXPIRED }}</dd></div>
19
- <div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">Deactivated</dt><dd class="font-medium text-gray-900 dark:text-white">{{ summary.statuses.DEACTIVATED }}</dd></div>
43
+ <template :for="item in statusRows()" :key="item.key">
44
+ <div class="flex justify-between"><dt class="text-gray-500 dark:text-neutral-400">{{ item.label }}</dt><dd class="font-medium text-gray-900 dark:text-white">{{ item.count }}</dd></div>
45
+ </template>
20
46
  </dl>
21
47
  </article>
22
48
 
23
49
  <article class="p-4 bg-white dark:bg-neutral-800 border border-gray-200 rounded-lg dark:border-neutral-700">
24
50
  <h2 class="font-semibold text-gray-900 text-sm dark:text-white">Outstanding by currency</h2>
25
- <div :if="summary.currencies.length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No balances recorded.</div>
26
- <ul :if="summary.currencies.length > 0" class="mt-4 space-y-3">
27
- <template :for="item in summary.currencies" :key="item.currency">
51
+ <div :if="currencyRows().length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No balances recorded.</div>
52
+ <ul :if="currencyRows().length > 0" class="mt-4 space-y-3">
53
+ <template :for="item in currencyRows()" :key="item.currency">
28
54
  <li class="flex gap-4 justify-between text-sm">
29
55
  <span class="text-gray-500 dark:text-neutral-400">{{ item.currency }} <span class="text-gray-500 text-xs dark:text-neutral-500">({{ item.cards }})</span></span>
30
56
  <span class="font-medium text-gray-900 dark:text-white">{{ money(item.currentBalance, item.currency) }}</span>
@@ -35,9 +61,9 @@ function money(value: number, currency: string): string {
35
61
 
36
62
  <article class="p-4 bg-white dark:bg-neutral-800 border border-gray-200 rounded-lg dark:border-neutral-700">
37
63
  <h2 class="font-semibold text-gray-900 text-sm dark:text-white">Redeemed by currency</h2>
38
- <div :if="summary.currencies.length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No redemption value recorded.</div>
39
- <ul :if="summary.currencies.length > 0" class="mt-4 space-y-3">
40
- <template :for="item in summary.currencies" :key="item.currency">
64
+ <div :if="currencyRows().length === 0" class="mt-4 text-gray-500 text-sm dark:text-neutral-400">No redemption value recorded.</div>
65
+ <ul :if="currencyRows().length > 0" class="mt-4 space-y-3">
66
+ <template :for="item in currencyRows()" :key="item.currency">
41
67
  <li class="flex gap-4 justify-between text-sm">
42
68
  <span class="text-gray-500 dark:text-neutral-400">{{ item.currency }}</span>
43
69
  <span class="font-medium text-gray-900 dark:text-white">{{ money(item.redeemedBalance, item.currency) }}</span>