@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.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +20 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-search-engine/SKILL.md +14 -0
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
- package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
- package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
- package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
- package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
- package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
- package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
- package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
- package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
- package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
- package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
- package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
- package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
- package/app/Actions/Dashboard/Content/content-list.ts +10 -0
- package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
- package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
- package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
- package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
- package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
- package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
- package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
- package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
- package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
- package/app/Actions/Dashboard/named-search.test.ts +36 -0
- package/app/Actions/Dashboard/named-search.ts +80 -0
- package/app/Models/Request.ts +4 -2
- package/functions/commerce/shippings/dashboard-resource.ts +12 -1
- package/functions/commerce/shippings/delivery-routes.ts +1 -0
- package/functions/commerce/shippings/license-keys.ts +1 -0
- package/functions/dashboard-list.test.ts +146 -1
- package/functions/dashboard-list.ts +216 -1
- package/functions/queue.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +2 -2
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
- package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite'
|
|
2
|
+
import { SQL } from 'bun'
|
|
3
|
+
import { describe, expect, test } from 'bun:test'
|
|
4
|
+
import type { KanbanUserRunner } from './kanban-users'
|
|
5
|
+
import { containsPattern } from '../Content/content-list'
|
|
6
|
+
import { parseKanbanUserQuery, readKanbanUsers } from './kanban-users'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The assignee picker's search, against each dialect's real engine
|
|
10
|
+
* (stacksjs/stacks#3216): case-insensitive over name and email, wildcards
|
|
11
|
+
* taken literally, bounded, with the full match count.
|
|
12
|
+
*/
|
|
13
|
+
const USERS: Array<[string | null, string]> = [
|
|
14
|
+
['Ava Stone', 'ava@example.com'],
|
|
15
|
+
['ben carter', 'BEN@Example.com'],
|
|
16
|
+
['Cara 100% Sure', 'cara@example.com'],
|
|
17
|
+
['Dan_Under', 'dan@example.com'],
|
|
18
|
+
// These two are what an unescaped pattern would wrongly match: `n_u` with
|
|
19
|
+
// `_` as a wildcard matches "n u", and `100%` matches "1000".
|
|
20
|
+
['Dan Under', 'danunder@example.com'],
|
|
21
|
+
['Cara 1000 Sure', 'cara1000@example.com'],
|
|
22
|
+
['Dana Undertow', 'dana@example.com'],
|
|
23
|
+
[null, 'nameless@example.com'],
|
|
24
|
+
['Émile Zola', 'emile@example.com'],
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
async function exercise(run: KanbanUserRunner, dialect: 'sqlite' | 'postgres' | 'mysql') {
|
|
28
|
+
const read = (q: string, limit = 25) => readKanbanUsers({ search: q, limit }, run, dialect)
|
|
29
|
+
|
|
30
|
+
const all = await read('')
|
|
31
|
+
expect(all.total).toBe(USERS.length)
|
|
32
|
+
expect(all.users.map(user => user.email)).toContain('nameless@example.com')
|
|
33
|
+
|
|
34
|
+
// Case is ignored on both columns.
|
|
35
|
+
expect((await read('BEN')).users.map(user => user.email)).toEqual(['BEN@Example.com'])
|
|
36
|
+
expect((await read('example.com')).total).toBe(USERS.length)
|
|
37
|
+
|
|
38
|
+
// `%` and `_` are characters to find, not wildcards.
|
|
39
|
+
expect((await read('100%')).users.map(user => user.name)).toEqual(['Cara 100% Sure'])
|
|
40
|
+
expect((await read('n_u')).users.map(user => user.name)).toEqual(['Dan_Under'])
|
|
41
|
+
|
|
42
|
+
// A user with no name is found by email.
|
|
43
|
+
expect((await read('nameless')).users).toEqual([expect.objectContaining({ name: null, email: 'nameless@example.com' })])
|
|
44
|
+
|
|
45
|
+
// The limit bounds the rows; the total still counts every match.
|
|
46
|
+
const limited = await read('a', 2)
|
|
47
|
+
expect(limited.users).toHaveLength(2)
|
|
48
|
+
expect(limited.total).toBeGreaterThan(2)
|
|
49
|
+
|
|
50
|
+
// Nothing matches is an empty page, not an error.
|
|
51
|
+
expect(await read('zzzz-nobody')).toEqual({ users: [], total: 0 })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('readKanbanUsers on SQLite', () => {
|
|
55
|
+
test('searches, bounds and counts', async () => {
|
|
56
|
+
const database = new Database(':memory:')
|
|
57
|
+
database.run('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)')
|
|
58
|
+
for (const [name, email] of USERS)
|
|
59
|
+
database.query('INSERT INTO users (name, email) VALUES (?, ?)').run(name, email)
|
|
60
|
+
await exercise({ unsafe: (sql, values = []) => ({ execute: async () => database.query(sql).all(...(values as string[])) }) }, 'sqlite')
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
for (const dialect of ['postgres', 'mysql'] as const) {
|
|
65
|
+
const connection = dialect === 'postgres' ? process.env.STACKS_TEST_POSTGRES_URL : process.env.STACKS_TEST_MYSQL_URL
|
|
66
|
+
|
|
67
|
+
test.skipIf(!connection)(`readKanbanUsers on ${dialect} searches, bounds and counts`, async () => {
|
|
68
|
+
const url = new URL(connection!)
|
|
69
|
+
if (!['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))
|
|
70
|
+
throw new Error('Kanban user tests require a local disposable database server')
|
|
71
|
+
|
|
72
|
+
const name = `stacks_kanban_users_${crypto.randomUUID().replaceAll('-', '')}`
|
|
73
|
+
const quoted = dialect === 'mysql' ? `\`${name}\`` : `"${name}"`
|
|
74
|
+
const admin = new SQL({ url: url.href, database: decodeURIComponent(url.pathname.slice(1)) || undefined })
|
|
75
|
+
await admin.unsafe(`CREATE DATABASE ${quoted}`)
|
|
76
|
+
const scoped = new URL(url.href)
|
|
77
|
+
scoped.pathname = `/${name}`
|
|
78
|
+
// Explicit database wins over inherited PGDATABASE / MYSQL_DATABASE in CI.
|
|
79
|
+
const database = new SQL({ url: scoped.href, database: name })
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await database.unsafe(dialect === 'mysql'
|
|
83
|
+
? 'CREATE TABLE users (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NULL, email VARCHAR(255) NULL) CHARACTER SET utf8mb4'
|
|
84
|
+
: 'CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, email TEXT)')
|
|
85
|
+
for (const [userName, email] of USERS)
|
|
86
|
+
await database.unsafe(`INSERT INTO users (name, email) VALUES (${dialect === 'postgres' ? '$1, $2' : '?, ?'})`, [userName, email])
|
|
87
|
+
await exercise({ unsafe: (sql, values = []) => ({ execute: async () => await database.unsafe(sql, values) }) }, dialect)
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await database.close()
|
|
91
|
+
try { await admin.unsafe(`DROP DATABASE ${quoted}${dialect === 'postgres' ? ' WITH (FORCE)' : ''}`) }
|
|
92
|
+
finally { await admin.close() }
|
|
93
|
+
}
|
|
94
|
+
}, 30_000)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe('parseKanbanUserQuery', () => {
|
|
98
|
+
const reader = (values: Record<string, unknown>) => (key: string) => values[key] ?? ''
|
|
99
|
+
|
|
100
|
+
test('defaults to an unfiltered page of 25', () => {
|
|
101
|
+
expect(parseKanbanUserQuery(reader({}))).toEqual({ search: '', limit: 25 })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('rejects a limit out of range and an over-long search', () => {
|
|
105
|
+
expect(parseKanbanUserQuery(reader({ limit: '0' }))).toHaveProperty('error')
|
|
106
|
+
expect(parseKanbanUserQuery(reader({ limit: '101' }))).toHaveProperty('error')
|
|
107
|
+
expect(parseKanbanUserQuery(reader({ limit: 'ten' }))).toHaveProperty('error')
|
|
108
|
+
expect(parseKanbanUserQuery(reader({ q: 'x'.repeat(201) }))).toHaveProperty('error')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('the pattern escapes its own wildcards and lowercases', () => {
|
|
112
|
+
expect(containsPattern('A_b%c!d')).toBe('%a!_b!%c!!d%')
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { QueryBuilderDialect } from '@stacksjs/database/runtime'
|
|
2
|
+
import type { QueryReader } from '../Content/content-list'
|
|
3
|
+
import type { NamedRow, NamedSearchQuery, NamedSearchRunner } from '../named-search'
|
|
4
|
+
import { NAMED_SEARCH_LIMIT, NAMED_SEARCH_MAX_LIMIT, parseNamedSearchQuery, searchNamedRows } from '../named-search'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The users the card dialog's assignee picker offers.
|
|
8
|
+
*
|
|
9
|
+
* It used to load the first 500 users by name, once, with no search: in an app
|
|
10
|
+
* with more, everyone past the 500th could not be assigned, and nothing said
|
|
11
|
+
* so (stacksjs/stacks#3216). Now the picker asks the database through the
|
|
12
|
+
* shared name and email search (`named-search.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export const KANBAN_USER_LIMIT = NAMED_SEARCH_LIMIT
|
|
15
|
+
export const KANBAN_USER_MAX_LIMIT = NAMED_SEARCH_MAX_LIMIT
|
|
16
|
+
|
|
17
|
+
export type KanbanUserQuery = NamedSearchQuery
|
|
18
|
+
export type KanbanUser = NamedRow
|
|
19
|
+
export type KanbanUserRunner = NamedSearchRunner
|
|
20
|
+
|
|
21
|
+
export function parseKanbanUserQuery(read: QueryReader): KanbanUserQuery | { error: string } {
|
|
22
|
+
return parseNamedSearchQuery(read)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function readKanbanUsers(
|
|
26
|
+
query: KanbanUserQuery,
|
|
27
|
+
runner?: KanbanUserRunner,
|
|
28
|
+
dialect?: QueryBuilderDialect,
|
|
29
|
+
): Promise<{ users: KanbanUser[], total: number }> {
|
|
30
|
+
const { rows, total } = await searchNamedRows('users', query, runner, dialect)
|
|
31
|
+
return { users: rows, total }
|
|
32
|
+
}
|
|
@@ -5,6 +5,7 @@ import { response as routerResponse } from '@stacksjs/router'
|
|
|
5
5
|
import { safeGet } from '../../../../resources/functions/dashboard/data'
|
|
6
6
|
import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
|
|
7
7
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
8
|
+
import { isUnmigratedTable } from './model-migration'
|
|
8
9
|
import { isValidModelSlug, type ModelCreateField, type ModelWriteCapabilities, modelCreateFields, modelSchemaColumns, modelWritableColumns, modelWriteCapabilities, slugToPascal } from './model-write'
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -56,6 +57,8 @@ interface ResponseShape {
|
|
|
56
57
|
writeCapabilities: ModelWriteCapabilities
|
|
57
58
|
createFields: ModelCreateField[]
|
|
58
59
|
updateColumns: string[]
|
|
60
|
+
/** False when the model's table does not exist yet: `./buddy migrate` creates it. */
|
|
61
|
+
migrated: boolean
|
|
59
62
|
error: string | null
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -214,6 +217,7 @@ export default new Action({
|
|
|
214
217
|
writeCapabilities: { create: false, update: false, destroy: false },
|
|
215
218
|
createFields: [],
|
|
216
219
|
updateColumns: [],
|
|
220
|
+
migrated: true,
|
|
217
221
|
error: null,
|
|
218
222
|
}
|
|
219
223
|
|
|
@@ -296,6 +300,10 @@ export default new Action({
|
|
|
296
300
|
})
|
|
297
301
|
}
|
|
298
302
|
catch (error) {
|
|
303
|
+
// Not an error to report: the table simply has not been created yet, and
|
|
304
|
+
// the page says so and names the command that creates it.
|
|
305
|
+
if (await isUnmigratedTable(response.tableName))
|
|
306
|
+
return { ...response, columns: [], rows: [], migrated: false }
|
|
299
307
|
return dashboardOperationalError(error, `${modelName} records could not be loaded.`, 'ModelShowAction.query')
|
|
300
308
|
}
|
|
301
309
|
|
|
@@ -4,6 +4,7 @@ import { resolveModelSources } from '@stacksjs/database/model-sources'
|
|
|
4
4
|
import { countRows } from '../../../../resources/functions/dashboard/data'
|
|
5
5
|
import { dashboardOperationalError, dashboardOperationalIssue } from '../dashboard-response'
|
|
6
6
|
import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
|
|
7
|
+
import { isUnmigratedTable } from './model-migration'
|
|
7
8
|
import { modelApiConfiguration } from './model-api'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -32,6 +33,8 @@ interface ModelRow {
|
|
|
32
33
|
source: 'userland' | 'framework'
|
|
33
34
|
apiUri: string
|
|
34
35
|
apiRoutes: string[]
|
|
36
|
+
/** False when the model's table does not exist yet. Its count is `null`, and it is not an error. */
|
|
37
|
+
migrated: boolean
|
|
35
38
|
error: string | null
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -91,6 +94,7 @@ function unavailableModelRow(model: DiscoveredModel, error: string): ModelRow {
|
|
|
91
94
|
source: model.source,
|
|
92
95
|
apiUri: '',
|
|
93
96
|
apiRoutes: [],
|
|
97
|
+
migrated: true,
|
|
94
98
|
error,
|
|
95
99
|
}
|
|
96
100
|
}
|
|
@@ -138,18 +142,25 @@ export default new Action({
|
|
|
138
142
|
dashboardOperationalIssue(error, 'Model metadata could not be loaded.', `ModelsIndexAction.metadata.${m.name}`),
|
|
139
143
|
)
|
|
140
144
|
}
|
|
145
|
+
const table = String(Model.table || pluralize(pascalToSnake(m.name)))
|
|
141
146
|
let count: number | null = null
|
|
142
147
|
let error: string | null = null
|
|
148
|
+
let migrated = true
|
|
143
149
|
try {
|
|
144
150
|
count = await countRows(Model)
|
|
145
151
|
}
|
|
146
152
|
catch (cause) {
|
|
147
|
-
|
|
153
|
+
// A table that was never migrated is reported as that, without logging
|
|
154
|
+
// a driver error for it on every visit to this page.
|
|
155
|
+
if (await isUnmigratedTable(table))
|
|
156
|
+
migrated = false
|
|
157
|
+
else
|
|
158
|
+
error = dashboardOperationalIssue(cause, 'Model count could not be loaded.', `ModelsIndexAction.count.${m.name}`)
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
return {
|
|
151
162
|
name: m.name,
|
|
152
|
-
table
|
|
163
|
+
table,
|
|
153
164
|
href: `/models/${pascalToKebab(m.name)}`,
|
|
154
165
|
count,
|
|
155
166
|
attributeCount: Object.keys(Model.attributes || {}).length,
|
|
@@ -157,6 +168,7 @@ export default new Action({
|
|
|
157
168
|
source: m.source,
|
|
158
169
|
apiUri: api.uri ? `/api/${api.uri}` : '',
|
|
159
170
|
apiRoutes: api.routes,
|
|
171
|
+
migrated,
|
|
160
172
|
error,
|
|
161
173
|
}
|
|
162
174
|
}))
|
|
@@ -168,6 +180,7 @@ export default new Action({
|
|
|
168
180
|
const totalRecords = enriched.reduce((sum, m) => sum + (m.count ?? 0), 0)
|
|
169
181
|
const userlandCount = enriched.filter(m => m.source === 'userland').length
|
|
170
182
|
const unavailableModels = enriched.filter(m => m.error !== null).length
|
|
183
|
+
const unmigratedModels = enriched.filter(m => !m.migrated).length
|
|
171
184
|
|
|
172
185
|
const groupMap = new Map<string, ModelRow[]>()
|
|
173
186
|
for (const m of enriched) {
|
|
@@ -192,6 +205,7 @@ export default new Action({
|
|
|
192
205
|
totalRecords,
|
|
193
206
|
userlandCount,
|
|
194
207
|
unavailableModels,
|
|
208
|
+
unmigratedModels,
|
|
195
209
|
categoryGroups,
|
|
196
210
|
}
|
|
197
211
|
},
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { isUnmigratedTable } from './model-migration'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The models pages answer "not migrated" instead of a 503 only when the
|
|
6
|
+
* catalog says the table is missing. Anything less certain must keep the
|
|
7
|
+
* original error, so a real outage is never relabelled as a migrate hint.
|
|
8
|
+
*/
|
|
9
|
+
describe('isUnmigratedTable', () => {
|
|
10
|
+
test('a table the catalog does not have is unmigrated', async () => {
|
|
11
|
+
expect(await isUnmigratedTable('menus', async () => false)).toBeTrue()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('a table the catalog has is not, so its failure stays an error', async () => {
|
|
15
|
+
expect(await isUnmigratedTable('users', async () => true)).toBeFalse()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('a catalog check that fails too keeps the original error', async () => {
|
|
19
|
+
expect(await isUnmigratedTable('users', async () => { throw new Error('connection refused') })).toBeFalse()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('the table it asks about is the one it was given', async () => {
|
|
23
|
+
const asked: string[] = []
|
|
24
|
+
await isUnmigratedTable('usage_events', async (table) => { asked.push(table); return false })
|
|
25
|
+
expect(asked).toEqual(['usage_events'])
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tableExists } from '@stacksjs/database/runtime'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a model's query failed because its table was never migrated.
|
|
5
|
+
*
|
|
6
|
+
* Asked only after a query has already failed, so a working page pays nothing.
|
|
7
|
+
* The answer comes from the catalog (`tableExists`), not the error's wording.
|
|
8
|
+
* A catalog check that fails too answers `false`, so the original error is
|
|
9
|
+
* reported as it was rather than replaced by a migrate hint.
|
|
10
|
+
*
|
|
11
|
+
* A framework model whose feature an app has not migrated is normal, not an
|
|
12
|
+
* outage: the dashboard lists every model the framework ships, and a fresh
|
|
13
|
+
* app has migrated only some of them. Reporting each as a 503 made every such
|
|
14
|
+
* page look broken and logged a full driver error for it on every request.
|
|
15
|
+
*/
|
|
16
|
+
export async function isUnmigratedTable(table: string, exists: (table: string) => Promise<boolean> = tableExists): Promise<boolean> {
|
|
17
|
+
try {
|
|
18
|
+
return !(await exists(table))
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
2
|
import { FailedJob, Job } from '@stacksjs/orm'
|
|
3
|
-
import { aggregateWorkerMetrics, discoverJobs
|
|
3
|
+
import { aggregateWorkerMetrics, discoverJobs } from '@stacksjs/queue'
|
|
4
4
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
5
|
import { readQueueCounts, withDeclaredQueues } from './queue-stats'
|
|
6
|
+
import { readDashboardWorkerSnapshots } from './worker-snapshots'
|
|
6
7
|
|
|
7
8
|
// A queued job has no `status` column - `queuedJobState` in @stacksjs/queue
|
|
8
9
|
// holds the rule (reserved_at means a worker has it; available_at in the
|
|
@@ -36,7 +37,8 @@ export default new Action({
|
|
|
36
37
|
|
|
37
38
|
// Workers publish bounded snapshots through their native QueueWorker model.
|
|
38
39
|
// The dashboard reads those across processes rather than its own empty tracker.
|
|
39
|
-
const
|
|
40
|
+
const workers = await readDashboardWorkerSnapshots()
|
|
41
|
+
const metrics = aggregateWorkerMetrics(workers.snapshots)
|
|
40
42
|
|
|
41
43
|
const stats = {
|
|
42
44
|
totalQueues: queues.length,
|
|
@@ -48,7 +50,7 @@ export default new Action({
|
|
|
48
50
|
averageProcessingTimeMs: Math.round(metrics.averageDuration),
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
return { queues, stats, queueConnected: true }
|
|
53
|
+
return { queues, stats, queueConnected: true, workersMigrated: workers.migrated }
|
|
52
54
|
}
|
|
53
55
|
catch (error) {
|
|
54
56
|
return dashboardOperationalError(error, 'Queue statistics could not be loaded.', 'QueueStatsAction')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
-
import { readWorkerSnapshots } from '@stacksjs/queue'
|
|
3
2
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
3
|
+
import { readDashboardWorkerSnapshots } from './worker-snapshots'
|
|
4
4
|
|
|
5
5
|
export default new Action({
|
|
6
6
|
name: 'QueueWorkersAction',
|
|
@@ -8,7 +8,7 @@ export default new Action({
|
|
|
8
8
|
method: 'GET',
|
|
9
9
|
async handle() {
|
|
10
10
|
try {
|
|
11
|
-
const snapshots = await
|
|
11
|
+
const { snapshots, migrated } = await readDashboardWorkerSnapshots()
|
|
12
12
|
const tracked = snapshots.map(snapshot => snapshot.worker)
|
|
13
13
|
|
|
14
14
|
// Translate the tracker's internal status into the dashboard's vocabulary
|
|
@@ -38,6 +38,7 @@ export default new Action({
|
|
|
38
38
|
data,
|
|
39
39
|
worker_running: tracked.some(worker => worker.status !== 'stopped'),
|
|
40
40
|
active_jobs: snapshots.reduce((sum, snapshot) => sum + snapshot.activeJobs, 0),
|
|
41
|
+
workers_migrated: migrated,
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import type { WorkerSnapshot } from '@stacksjs/queue'
|
|
3
|
+
import { readDashboardWorkerSnapshots } from './worker-snapshots'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Worker heartbeats are telemetry beside the jobs. A missing `queue_workers`
|
|
7
|
+
* table must leave the Queue and Jobs pages their counts; any other failure
|
|
8
|
+
* must still fail them.
|
|
9
|
+
*/
|
|
10
|
+
describe('readDashboardWorkerSnapshots', () => {
|
|
11
|
+
test('reads the heartbeats when the table exists, without asking the catalog', async () => {
|
|
12
|
+
const snapshot = { worker: { id: 'w1' } } as unknown as WorkerSnapshot
|
|
13
|
+
const read = await readDashboardWorkerSnapshots(async () => [snapshot], async () => { throw new Error('the catalog must not be asked') })
|
|
14
|
+
expect(read).toEqual({ snapshots: [snapshot], migrated: true })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('a missing queue_workers table answers no workers and migrated: false', async () => {
|
|
18
|
+
const asked: string[] = []
|
|
19
|
+
const read = await readDashboardWorkerSnapshots(
|
|
20
|
+
async () => { throw new Error('relation "queue_workers" does not exist') },
|
|
21
|
+
async (table) => { asked.push(table); return true },
|
|
22
|
+
)
|
|
23
|
+
expect(read).toEqual({ snapshots: [], migrated: false })
|
|
24
|
+
expect(asked).toEqual(['queue_workers'])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('any other failure is rethrown', async () => {
|
|
28
|
+
const outage = new Error('connection refused')
|
|
29
|
+
await expect(readDashboardWorkerSnapshots(async () => { throw outage }, async () => false)).rejects.toBe(outage)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { WorkerSnapshot } from '@stacksjs/queue'
|
|
2
|
+
import { readWorkerSnapshots } from '@stacksjs/queue'
|
|
3
|
+
import { isUnmigratedTable } from '../Models/model-migration'
|
|
4
|
+
|
|
5
|
+
/** Where workers publish their heartbeats (`app/Models/QueueWorker.ts`). */
|
|
6
|
+
export const WORKER_TABLE = 'queue_workers'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The worker heartbeats, for the Queue and Jobs pages.
|
|
10
|
+
*
|
|
11
|
+
* Heartbeats are telemetry beside the jobs, not the jobs: the queue counts and
|
|
12
|
+
* job totals come from `jobs` and `failed_jobs`, and a worker already runs
|
|
13
|
+
* without its telemetry table ("Queue worker telemetry unavailable"). So an app
|
|
14
|
+
* that has not migrated `queue_workers` gets its counts with no workers and
|
|
15
|
+
* `migrated: false`, where all three endpoints used to answer 503 and take the
|
|
16
|
+
* page's counts down with them.
|
|
17
|
+
*
|
|
18
|
+
* Only a missing table, as the catalog reports it, is treated that way. Any
|
|
19
|
+
* other failure is rethrown.
|
|
20
|
+
*/
|
|
21
|
+
export async function readDashboardWorkerSnapshots(
|
|
22
|
+
read: () => Promise<WorkerSnapshot[]> = readWorkerSnapshots,
|
|
23
|
+
isMissing: (table: string) => Promise<boolean> = isUnmigratedTable,
|
|
24
|
+
): Promise<{ snapshots: WorkerSnapshot[], migrated: boolean }> {
|
|
25
|
+
try {
|
|
26
|
+
return { snapshots: await read(), migrated: true }
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (await isMissing(WORKER_TABLE))
|
|
30
|
+
return { snapshots: [], migrated: false }
|
|
31
|
+
throw error
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite'
|
|
2
|
+
import { describe, expect, test } from 'bun:test'
|
|
3
|
+
import type { NamedSearchRunner, NamedSearchTable } from './named-search'
|
|
4
|
+
import { searchNamedRows } from './named-search'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shared picker search. kanban-users.test.ts runs it against users on
|
|
8
|
+
* SQLite, PostgreSQL and MySQL; this pins what that does not: the table name
|
|
9
|
+
* is SQL, so only the fixed list is accepted, and customers search the same way.
|
|
10
|
+
*/
|
|
11
|
+
function sqlite(): { database: Database, run: NamedSearchRunner } {
|
|
12
|
+
const database = new Database(':memory:')
|
|
13
|
+
return { database, run: { unsafe: (sql, values = []) => ({ execute: async () => database.query(sql).all(...(values as string[])) }) } }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('searchNamedRows', () => {
|
|
17
|
+
test('searches customers by name or email, bounded, with the full count', async () => {
|
|
18
|
+
const { database, run } = sqlite()
|
|
19
|
+
database.run('CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, email TEXT)')
|
|
20
|
+
for (let index = 1; index <= 40; index++)
|
|
21
|
+
database.query('INSERT INTO customers (name, email) VALUES (?, ?)').run(`Customer ${String(index).padStart(2, '0')}`, `c${index}@example.com`)
|
|
22
|
+
database.query('INSERT INTO customers (name, email) VALUES (?, ?)').run('Zed Ortiz', 'ZED@shop.test')
|
|
23
|
+
|
|
24
|
+
const page = await searchNamedRows('customers', { search: 'customer', limit: 25 }, run, 'sqlite')
|
|
25
|
+
expect(page.rows).toHaveLength(25)
|
|
26
|
+
expect(page.total).toBe(40)
|
|
27
|
+
expect((await searchNamedRows('customers', { search: 'zed@SHOP', limit: 25 }, run, 'sqlite')).rows.map(row => row.name)).toEqual(['Zed Ortiz'])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('refuses a table that is not on the list, before running anything', async () => {
|
|
31
|
+
let ran = false
|
|
32
|
+
const run: NamedSearchRunner = { unsafe: () => ({ execute: async () => { ran = true; return [] } }) }
|
|
33
|
+
await expect(searchNamedRows('users; DROP TABLE users' as NamedSearchTable, { search: '', limit: 5 }, run, 'sqlite')).rejects.toThrow('is not a searchable table')
|
|
34
|
+
expect(ran).toBeFalse()
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { QueryBuilderDialect } from '@stacksjs/database/runtime'
|
|
2
|
+
import { db, getDatabaseDialect, sqlHelpers } from '@stacksjs/database/runtime'
|
|
3
|
+
import type { QueryReader } from './Content/content-list'
|
|
4
|
+
import { containsPattern, countOf, queryText } from './Content/content-list'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A search over a table's `name` and `email`, for the dashboard's pickers: the
|
|
8
|
+
* Kanban assignee picker (users, stacksjs/stacks#3216) and the order dialog's
|
|
9
|
+
* customer (customers, stacksjs/stacks#3218). Each used to load the first 500
|
|
10
|
+
* rows once, so nobody past the 500th could be chosen.
|
|
11
|
+
*
|
|
12
|
+
* Case is ignored on both columns, `%` and `_` are characters to find, the
|
|
13
|
+
* answer is bounded, and `total` says how many matched.
|
|
14
|
+
*/
|
|
15
|
+
export const NAMED_SEARCH_TABLES = ['users', 'customers'] as const
|
|
16
|
+
export type NamedSearchTable = typeof NAMED_SEARCH_TABLES[number]
|
|
17
|
+
|
|
18
|
+
export const NAMED_SEARCH_LIMIT = 25
|
|
19
|
+
export const NAMED_SEARCH_MAX_LIMIT = 100
|
|
20
|
+
|
|
21
|
+
export interface NamedSearchQuery {
|
|
22
|
+
search: string
|
|
23
|
+
limit: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NamedRow {
|
|
27
|
+
id: number
|
|
28
|
+
name: string | null
|
|
29
|
+
email: string | null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What runs the two queries: the configured `db`, or a test's own connection. */
|
|
33
|
+
export interface NamedSearchRunner {
|
|
34
|
+
unsafe: (sql: string, values?: unknown[]) => { execute: () => Promise<unknown> }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function parseNamedSearchQuery(read: QueryReader): NamedSearchQuery | { error: string } {
|
|
38
|
+
const search = queryText(read, 'q')
|
|
39
|
+
if (search.length > 200)
|
|
40
|
+
return { error: 'q must be 200 characters or fewer.' }
|
|
41
|
+
|
|
42
|
+
const limitText = queryText(read, 'limit')
|
|
43
|
+
const limit = limitText === '' ? NAMED_SEARCH_LIMIT : Number(limitText)
|
|
44
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > NAMED_SEARCH_MAX_LIMIT)
|
|
45
|
+
return { error: `limit must be a whole number from 1 to ${NAMED_SEARCH_MAX_LIMIT}.` }
|
|
46
|
+
|
|
47
|
+
return { search, limit }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function searchNamedRows(
|
|
51
|
+
table: NamedSearchTable,
|
|
52
|
+
query: NamedSearchQuery,
|
|
53
|
+
runner: NamedSearchRunner = db,
|
|
54
|
+
dialect: QueryBuilderDialect = getDatabaseDialect(),
|
|
55
|
+
): Promise<{ rows: NamedRow[], total: number }> {
|
|
56
|
+
// The table name is SQL, not a value, so only the fixed list is accepted.
|
|
57
|
+
if (!(NAMED_SEARCH_TABLES as readonly string[]).includes(table))
|
|
58
|
+
throw new TypeError(`${table} is not a searchable table.`)
|
|
59
|
+
|
|
60
|
+
const sql = sqlHelpers(dialect)
|
|
61
|
+
const values: unknown[] = []
|
|
62
|
+
let where = ''
|
|
63
|
+
if (query.search) {
|
|
64
|
+
const pattern = containsPattern(query.search)
|
|
65
|
+
values.push(pattern, pattern)
|
|
66
|
+
where = ` WHERE LOWER(COALESCE(name, '')) LIKE ${sql.param(1)} ESCAPE '!' OR LOWER(COALESCE(email, '')) LIKE ${sql.param(2)} ESCAPE '!'`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const counted = await runner.unsafe(`SELECT COUNT(*) AS total_count FROM ${table}${where}`, values).execute() as Array<{ total_count: unknown }>
|
|
70
|
+
const found = await runner.unsafe(
|
|
71
|
+
// LOWER, so the order is the same on every dialect: each collates case its own way.
|
|
72
|
+
`SELECT id, name, email FROM ${table}${where} ORDER BY LOWER(COALESCE(name, '')) ASC, id ASC LIMIT ${query.limit}`,
|
|
73
|
+
values,
|
|
74
|
+
).execute() as Array<{ id: unknown, name: string | null, email: string | null }>
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
rows: (Array.isArray(found) ? found : []).map(row => ({ id: Number(row.id), name: row.name ?? null, email: row.email ?? null })),
|
|
78
|
+
total: countOf(Array.isArray(counted) ? counted[0]?.total_count : 0),
|
|
79
|
+
}
|
|
80
|
+
}
|
package/app/Models/Request.ts
CHANGED
|
@@ -48,9 +48,11 @@ export default defineModel({
|
|
|
48
48
|
method: {
|
|
49
49
|
fillable: true,
|
|
50
50
|
validation: {
|
|
51
|
-
|
|
51
|
+
// Observations include rejected methods (for example PROPFIND -> 405).
|
|
52
|
+
// An enum of application verbs silently lost those requests at insert.
|
|
53
|
+
rule: schema.string().max(255),
|
|
52
54
|
message: {
|
|
53
|
-
|
|
55
|
+
string: 'method must be an HTTP method token',
|
|
54
56
|
required: 'method is required',
|
|
55
57
|
},
|
|
56
58
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dashboardApi } from '../../dashboard-api'
|
|
2
|
+
import { readEveryPage } from '../../dashboard-list'
|
|
2
3
|
import { pushToast } from '../../toasts'
|
|
3
4
|
import { useStorage } from '@stacksjs/browser/composables/useStorage'
|
|
4
5
|
|
|
@@ -11,6 +12,13 @@ interface DashboardResourceOptions {
|
|
|
11
12
|
storageKey: string
|
|
12
13
|
singular: string
|
|
13
14
|
plural: string
|
|
15
|
+
/**
|
|
16
|
+
* The endpoint answers one page at a time (`{ records, total }`, with
|
|
17
|
+
* `page` and `per_page`) instead of a bare array, as the dashboard's
|
|
18
|
+
* delivery routes do (stacksjs/stacks#3218). `fetchAll` then reads every
|
|
19
|
+
* page, so it still returns every record.
|
|
20
|
+
*/
|
|
21
|
+
paged?: boolean
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
export function createDashboardResource<
|
|
@@ -19,9 +27,12 @@ export function createDashboardResource<
|
|
|
19
27
|
>(options: DashboardResourceOptions) {
|
|
20
28
|
const items = useStorage<TRecord[]>(options.storageKey, [])
|
|
21
29
|
|
|
30
|
+
const fetchPages = (): Promise<TRecord[]> => readEveryPage((page, perPage) =>
|
|
31
|
+
dashboardApi<{ records?: TRecord[], total?: number }>(`${options.path}?page=${page}&per_page=${perPage}`))
|
|
32
|
+
|
|
22
33
|
async function fetchAll(): Promise<TRecord[]> {
|
|
23
34
|
try {
|
|
24
|
-
const data = await dashboardApi<TRecord[]>(options.path)
|
|
35
|
+
const data = options.paged ? await fetchPages() : await dashboardApi<TRecord[]>(options.path)
|
|
25
36
|
if (!Array.isArray(data))
|
|
26
37
|
throw new TypeError('Server returned a non-array response')
|
|
27
38
|
|