@stacksjs/defaults 0.75.569 → 0.75.571
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-database/SKILL.md +48 -0
- package/ai/skills/stacks-http/SKILL.md +33 -2
- package/ai/skills/stacks-native/CATALOG.md +6 -6
- package/ai/skills/stacks-orm/SKILL.md +16 -10
- package/ai/skills/stacks-query-builder/SKILL.md +7 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +1 -1
- package/app/Actions/Dashboard/Content/comment-list.ts +2 -2
- package/app/Actions/Dashboard/Content/page-list.ts +2 -2
- package/app/Actions/Dashboard/Content/post-list.ts +2 -2
- package/app/Actions/Dashboard/Infrastructure/InsightsAction.ts +24 -19
- package/app/Actions/Dashboard/Infrastructure/log-provider.ts +4 -4
- package/app/Actions/Dashboard/Jobs/job-list.ts +1 -1
- package/app/Actions/Dashboard/Kanban/BoardShowAction.ts +2 -2
- package/app/Actions/Dashboard/Kanban/CardShowAction.ts +3 -3
- package/app/Actions/Dashboard/Kanban/card-attachments.ts +1 -1
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryOverviewAction.ts +1 -1
- package/app/Actions/Dashboard/Queries/query-list.ts +1 -1
- package/app/Actions/Dashboard/Queue/queue-stats.ts +2 -2
- package/app/Actions/Dashboard/named-search.ts +1 -1
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
|
@@ -87,6 +87,54 @@ const users = await db.selectFrom('users').where('active', '=', true).get()
|
|
|
87
87
|
|
|
88
88
|
`initializeDbConfig(config)` can be called to update the backing config at runtime.
|
|
89
89
|
|
|
90
|
+
### Values, not promises
|
|
91
|
+
|
|
92
|
+
A `db` call answers where it is written, on SQLite, MySQL and Postgres:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const users = db.selectFrom('users').where('active', '=', true).get() // the rows
|
|
96
|
+
const newest = db.selectFrom('users').orderBy('created_at', 'desc').first() // the row, or undefined
|
|
97
|
+
const changed = db.updateTable('users').set({ active: false }).where('id', '=', 7).execute() // 1
|
|
98
|
+
|
|
99
|
+
const orderId = db.transaction((tx) => {
|
|
100
|
+
const order = tx.insertInto('orders').values({ customer_id: 7 }).returning('id').first()
|
|
101
|
+
tx.insertInto('order_lines').values({ order_id: order.id, sku: 'A-1' }).execute()
|
|
102
|
+
return order.id
|
|
103
|
+
}) // committed by this line; a throw has rolled back and rethrown
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- `await` in front of any of them still works (`await` on a value is that
|
|
107
|
+
value), so existing code is correct as it stands.
|
|
108
|
+
- A failure is thrown where the call stands: `try`/`catch`, not `.catch()` or
|
|
109
|
+
`.then()`. In a test, `expect(() => db.selectFrom('missing').get()).toThrow()`,
|
|
110
|
+
not `await expect(...).rejects`.
|
|
111
|
+
- A query runs where it is written. To start several and judge each on its own
|
|
112
|
+
later, hand them over unstarted: `inspect(() => db.selectFrom(...).get())`.
|
|
113
|
+
- `db.unsafe(sql, params)` and `db.file(path)` build a statement. `.execute()`
|
|
114
|
+
runs it and returns its rows; awaiting the statement resolves to the same
|
|
115
|
+
rows. Nothing runs until one of the two happens.
|
|
116
|
+
- A transaction callback that is `async` is waited for, and the transaction is
|
|
117
|
+
then a promise, as is the callback of `chunk()`. Write the callback without
|
|
118
|
+
`async` when everything in it is a query.
|
|
119
|
+
- While a transaction with an `async` callback is open it holds its locks
|
|
120
|
+
across each `await`, and the code that commits it needs the thread. A
|
|
121
|
+
statement elsewhere in the process that needs one of those locks (or a
|
|
122
|
+
pooled connection, when they are all held) is therefore not waited for in
|
|
123
|
+
place: that one call answers with a promise, which resolves once the
|
|
124
|
+
transaction has finished. It is how `withLockedRow` and `rowToken` can
|
|
125
|
+
contend for one row. A statement that needs nothing held still answers in
|
|
126
|
+
place, and with synchronous callbacks nothing is ever held.
|
|
127
|
+
- Inside a transaction callback `db.` is the transaction: a `db.selectFrom(...)`
|
|
128
|
+
there runs on the transaction's connection, as `tx.selectFrom(...)` does. A
|
|
129
|
+
model call does not (see Gotchas).
|
|
130
|
+
- On SQLite there is one connection. A transaction whose callback is `async`
|
|
131
|
+
holds it until it settles, so a transaction that starts meanwhile queues
|
|
132
|
+
behind it and is a promise whatever its own callback does. With only
|
|
133
|
+
synchronous callbacks that cannot happen.
|
|
134
|
+
- MySQL and Postgres run on a worker thread the caller waits on, sharing one
|
|
135
|
+
pool with the models. `models: { execution: 'async' }` in `config/query-builder.ts`
|
|
136
|
+
gives promises back for both; every call then has to be awaited.
|
|
137
|
+
|
|
90
138
|
For reads which cannot tolerate replication lag, use `db.primary.selectFrom(...)`.
|
|
91
139
|
It stays on the primary when automatic replica routing is enabled, and uses the
|
|
92
140
|
active transaction connection inside a transaction. It does not mark the request
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-http
|
|
3
|
-
description: Use when choosing HTTP status constants, bounded fetch, outbound Httx requests, transport fakes, retry/circuit behavior, or the boundary with reactive browser fetching. Covers @stacksjs/http and @stacksjs/httx.
|
|
3
|
+
description: Use when choosing HTTP status constants, bounded fetch, sanitized transfer observations, caller-read progress diagnostics, outbound Httx requests, transport fakes, retry/circuit behavior, or the boundary with reactive browser fetching. Covers @stacksjs/http and @stacksjs/httx.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -43,6 +43,35 @@ body or a Request with a body is sent once, returning its original response;
|
|
|
43
43
|
use a URL plus buffered bytes for retryable uploads. The budget ends when final
|
|
44
44
|
response headers arrive, so the caller still owns subsequent body consumption.
|
|
45
45
|
|
|
46
|
+
## Transfer observations
|
|
47
|
+
|
|
48
|
+
Use `fetchWithBudget`'s optional `observer.onAttempt` and `observer.onResponse`
|
|
49
|
+
for actual request-attempt and selected-response metadata. Callbacks preserve
|
|
50
|
+
their receiver, are never awaited, and isolate getter/call/promise failures.
|
|
51
|
+
Their immutable records retain HTTP(S) origins, attempt, status and a strictly
|
|
52
|
+
parsed optional Content-Length. They exclude URL credentials/path/query/fragment,
|
|
53
|
+
arbitrary headers and body content. Oversized or invalid metadata is omitted.
|
|
54
|
+
|
|
55
|
+
Use `createHttpTransferObservation()` for a fixed diagnostic report. Pass its
|
|
56
|
+
`observer` to the native request, feed `received(byteLength)` from the caller's
|
|
57
|
+
same existing nonempty-chunk read loop, then `finish(reason)` from the caller's
|
|
58
|
+
actual terminal outcome. The native collector adds no request, timer or body
|
|
59
|
+
reader and changes no transfer, retry, cancellation, hash or publication policy.
|
|
60
|
+
Keep the caller's body deadline and inactivity controller active after headers.
|
|
61
|
+
|
|
62
|
+
Reports contain copied metadata, byte/chunk totals and monotonic header/byte/gap
|
|
63
|
+
timings. Retention is 12 ten-second buckets; observations after 120000 ms merge
|
|
64
|
+
into the last bucket with `coalesced`. This boundary is not a download deadline.
|
|
65
|
+
Invalid observations are flagged, counters saturate rather than wrap, and
|
|
66
|
+
`finish` returns an idempotent deeply frozen snapshot. Counts describe what the
|
|
67
|
+
caller reports, not an independent measurement of socket traffic.
|
|
68
|
+
|
|
69
|
+
Read the [HTTP package README](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/README.md)
|
|
70
|
+
for the complete caller-owned read example, metadata bounds, terminal reasons
|
|
71
|
+
and evidence limits. Real loopback cases cover requests and caller reads;
|
|
72
|
+
worked clock cases cover aggregation. Neither establishes remote throughput or
|
|
73
|
+
an application's original-content acquisition acceptance.
|
|
74
|
+
|
|
46
75
|
## Httx client and fluent requests
|
|
47
76
|
|
|
48
77
|
The separate `@stacksjs/httx` dependency exports HttxClient, the httx facade,
|
|
@@ -86,4 +115,6 @@ buddy http makes an outbound diagnostic request; use its help for options.
|
|
|
86
115
|
Source: `storage/framework/core/http/src/index.ts` and
|
|
87
116
|
`core/buddy/src/commands/http.ts`. Httx's public contract is the installed
|
|
88
117
|
dependency's package exports/declarations. Retained local status/helper tests
|
|
89
|
-
are in `core/http/tests/http.test.ts
|
|
118
|
+
are in `core/http/tests/http.test.ts`, `fetch-budget.test.ts`,
|
|
119
|
+
`retry-after.test.ts` and `transfer-observation.test.ts`; they do not prove a
|
|
120
|
+
remote provider SLA or published-package consumer acceptance.
|
|
@@ -35,7 +35,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
35
35
|
| `@stacksjs/composables` | [`stacks-composables`](../stacks-composables/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/composables/src/index.ts) | 18 |
|
|
36
36
|
| `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts) | 16 |
|
|
37
37
|
| `@stacksjs/cron` | [`stacks-cron`](../stacks-cron/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cron/src/index.ts) | 6 |
|
|
38
|
-
| `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) |
|
|
38
|
+
| `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) | 146 |
|
|
39
39
|
| `@stacksjs/datetime` | [`stacks-datetime`](../stacks-datetime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/datetime/src/index.ts) | 22 |
|
|
40
40
|
| `@stacksjs/defaults` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/defaults/package.json) | 3 |
|
|
41
41
|
| `@stacksjs/deploy` | [`stacks-deploy`](../stacks-deploy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/deploy/package.json) | 1 |
|
|
@@ -56,7 +56,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
56
56
|
| `@stacksjs/github` | [`stacks-git`](../stacks-git/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/github/src/index.ts) | 8 |
|
|
57
57
|
| `@stacksjs/health` | [`stacks-health`](../stacks-health/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/health/src/index.ts) | 2 |
|
|
58
58
|
| `@stacksjs/hq` | [`stacks-hq`](../stacks-hq/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/index.ts) | 8 |
|
|
59
|
-
| `@stacksjs/http` | [`stacks-http`](../stacks-http/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/index.ts) |
|
|
59
|
+
| `@stacksjs/http` | [`stacks-http`](../stacks-http/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/index.ts) | 4 |
|
|
60
60
|
| `@stacksjs/i18n` | [`stacks-i18n`](../stacks-i18n/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/i18n/src/index.ts) | 5 |
|
|
61
61
|
| `@stacksjs/image` | [`stacks-image`](../stacks-image/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/image/src/index.ts) | 4 |
|
|
62
62
|
| `@stacksjs/lint` | [`stacks-lint`](../stacks-lint/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/lint/src/index.ts) | 3 |
|
|
@@ -358,7 +358,7 @@ Declared runtime exports: `Database`, `EntityQueryBuilder`, `__flushAfterCommitN
|
|
|
358
358
|
|
|
359
359
|
Local source modules: [src/affected-rows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/affected-rows.ts), [src/auth-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/auth-tables.ts), [src/custom/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/custom/index.ts), [src/database.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/database.ts), [src/datetime-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/datetime-columns.ts), [src/ddl-constraints.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ddl-constraints.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/defaults.ts), [src/dialect.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/dialect.ts), [src/driver-config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/driver-config.ts), [src/drivers/dynamodb.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/drivers/dynamodb.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/drivers/index.ts), [src/ensure-database.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ensure-database.ts), [src/erd.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/erd.ts), [src/fk-audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/fk-audit.ts), [src/framework-renames.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/framework-renames.ts), [src/framework-route-admission.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/framework-route-admission.ts), [src/hand-written-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/hand-written-migrations.ts), [src/ignored-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/ignored-migrations.ts), [src/index-shape.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index-shape.ts), [src/managed-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/managed-columns.ts), [src/migration-dialect.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-dialect.ts), [src/migration-ledger.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-ledger.ts), [src/migration-names.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-names.ts), [src/migration-path.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migration-path.ts), [src/migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/migrations.ts), [src/model-sources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/model-sources.ts), [src/notification-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/notification-tables.ts), [src/package-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/package-migrations.ts), [src/package-models.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/package-models.ts), [src/query-logger.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/query-logger.ts), [src/rbac-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/rbac-tables.ts), [src/relation-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/relation-columns.ts), [src/replicas.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/replicas.ts), [src/row-lease.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/row-lease.ts), [src/row-lock.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/row-lock.ts), [src/safe-migrations.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/safe-migrations.ts), [src/schema-align.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/schema-align.ts), [src/schema-drift.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/schema-drift.ts), [src/seeder.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/seeder.ts), [src/shadowed-models.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/shadowed-models.ts), [src/sql-helpers.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/sql-helpers.ts), [src/table-exists.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/table-exists.ts), [src/trait-tables.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/trait-tables.ts), [src/transaction-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/transaction-context.ts), [src/transaction-options.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/transaction-options.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/types.ts), [src/unique-audit.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/unique-audit.ts), [src/utc-defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/utc-defaults.ts), [src/utils.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/utils.ts), [src/uuid-columns.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/uuid-columns.ts), [src/vschema.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/vschema.ts).
|
|
360
360
|
|
|
361
|
-
Evidence directory: [
|
|
361
|
+
Evidence directory: [146 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
362
362
|
|
|
363
363
|
### @stacksjs/datetime
|
|
364
364
|
|
|
@@ -554,11 +554,11 @@ Evidence directory: [8 retained tests](https://github.com/stacksjs/stacks/blob/m
|
|
|
554
554
|
|
|
555
555
|
Guidance: [`stacks-http`](../stacks-http/SKILL.md). Source: [storage/framework/core/http/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/index.ts).
|
|
556
556
|
|
|
557
|
-
Declared runtime exports: `Response`, `fetchWithBudget`, `retryAfterMilliseconds`.
|
|
557
|
+
Declared runtime exports: `Response`, `createHttpTransferObservation`, `fetchWithBudget`, `retryAfterMilliseconds`.
|
|
558
558
|
|
|
559
|
-
Local source modules: [src/retry-after.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/retry-after.ts).
|
|
559
|
+
Local source modules: [src/retry-after.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/retry-after.ts), [src/transfer-observation.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/transfer-observation.ts).
|
|
560
560
|
|
|
561
|
-
Evidence directory: [
|
|
561
|
+
Evidence directory: [4 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
562
562
|
|
|
563
563
|
### @stacksjs/i18n
|
|
564
564
|
|
|
@@ -62,19 +62,25 @@ for (const post of Post.where('published', true).get()) titles.push(post.title)
|
|
|
62
62
|
- **How.** SQLite runs a query in place. MySQL and Postgres run on Bun's
|
|
63
63
|
driver, held by a worker thread the caller waits on, so nothing else runs on
|
|
64
64
|
the calling thread while a query is in flight (the cost `bun:sqlite` always
|
|
65
|
-
had). `models: { execution: 'async' }` in `config/
|
|
65
|
+
had). `models: { execution: 'async' }` in `config/query-builder.ts` makes MySQL and
|
|
66
66
|
Postgres calls promises again for an app that needs the event loop free
|
|
67
67
|
during queries; every call then has to be awaited.
|
|
68
|
-
- **
|
|
69
|
-
`transaction()`
|
|
68
|
+
- **The `db` query builder too.** `db.selectFrom(...).get()` is the rows and
|
|
69
|
+
`transaction(tx => ...)` is done when it returns, on the same rule (see
|
|
70
|
+
`stacks-database`, "Values, not promises").
|
|
70
71
|
- **Inside `db.transaction()`, write through `tx`, not through a model.** A
|
|
71
|
-
model call runs on its own connection
|
|
72
|
-
waits for
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
default, `0` for no limit)
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
model call runs on its own connection. One that needs a row the open
|
|
73
|
+
transaction has locked waits for that transaction to finish, and if the
|
|
74
|
+
transaction's own callback is what is waiting for the model call, neither
|
|
75
|
+
can: it fails with `StatementTimeoutError` after `models.timeoutMs` (30
|
|
76
|
+
seconds by default, `0` for no limit). Postgres cancels the abandoned
|
|
77
|
+
statement; MySQL cannot, so there it may still be applied once the lock is
|
|
78
|
+
gone.
|
|
79
|
+
- **The one model call that is a promise.** While a transaction with an
|
|
80
|
+
`async` callback is open in the process, a model call that needs a lock it
|
|
81
|
+
holds answers with a promise instead of waiting on the thread the commit
|
|
82
|
+
needs (see `stacks-database`, "Values, not promises"). Any other call is
|
|
83
|
+
still a value.
|
|
78
84
|
|
|
79
85
|
### Writes: in place, with the work around them
|
|
80
86
|
|
|
@@ -28,6 +28,13 @@ export { createQueryBuilder as QueryBuilder } from 'bun-query-builder'
|
|
|
28
28
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
|
+
A query answers where it is written: `get()`, `first()`, `execute()`, `count()`
|
|
32
|
+
and the rest return the rows, the row or the number, and a transaction is done
|
|
33
|
+
when it returns. The `await` in the examples below is optional (`await` on a
|
|
34
|
+
value is that value); a failure is thrown where the call stands. The full rule,
|
|
35
|
+
including what still returns a promise, is in `stacks-database` under "Values,
|
|
36
|
+
not promises".
|
|
37
|
+
|
|
31
38
|
```typescript
|
|
32
39
|
import { db } from '@stacksjs/database/runtime'
|
|
33
40
|
|
|
@@ -9,7 +9,7 @@ import { sqlHelpers } from '@stacksjs/database/runtime'
|
|
|
9
9
|
|
|
10
10
|
/** What runs the queries: the configured `db`, or a test's own connection. */
|
|
11
11
|
export interface CommerceSqlRunner {
|
|
12
|
-
unsafe: (sql: string, values?: unknown[]) => { execute: () =>
|
|
12
|
+
unsafe: (sql: string, values?: unknown[]) => { execute: () => unknown }
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** A result as rows, whatever the driver returned for an empty one. */
|
|
@@ -254,8 +254,8 @@ async function prepareCommentables(query: CommentListQuery): Promise<Commentable
|
|
|
254
254
|
const columns = await ownerLabelColumns(types)
|
|
255
255
|
const where = commentableWhere(query, columns, guestAuthors)
|
|
256
256
|
const [[counted], statusRows] = await Promise.all([
|
|
257
|
-
db.unsafe(`SELECT COUNT(id) AS count FROM commentables ${where.sql}`, where.values).execute() as
|
|
258
|
-
db.unsafe('SELECT status, COUNT(id) AS count FROM commentables GROUP BY status').execute() as
|
|
257
|
+
db.unsafe(`SELECT COUNT(id) AS count FROM commentables ${where.sql}`, where.values).execute() as unknown as Array<{ count: unknown }>,
|
|
258
|
+
db.unsafe('SELECT status, COUNT(id) AS count FROM commentables GROUP BY status').execute() as unknown as Array<{ status: unknown, count: unknown }>,
|
|
259
259
|
])
|
|
260
260
|
|
|
261
261
|
return { columns, guestAuthors, where, total: countOf(counted?.count), statusRows }
|
|
@@ -92,8 +92,8 @@ export async function readPageListPage(query: PageListQuery, database: typeof db
|
|
|
92
92
|
database.fn.count('id').as('count'),
|
|
93
93
|
database.fn.sum('views').as('views'),
|
|
94
94
|
database.fn.sum('conversions').as('conversions'),
|
|
95
|
-
]).executeTakeFirst() as
|
|
96
|
-
database.selectFrom('pages').select(['title']).orderBy('created_at', 'desc').orderBy('id', 'desc').limit(1).executeTakeFirst() as
|
|
95
|
+
]).executeTakeFirst() as unknown as { count?: unknown, views?: unknown, conversions?: unknown } | undefined,
|
|
96
|
+
database.selectFrom('pages').select(['title']).orderBy('created_at', 'desc').orderBy('id', 'desc').limit(1).executeTakeFirst() as unknown as { title?: string | null } | undefined,
|
|
97
97
|
])
|
|
98
98
|
|
|
99
99
|
return {
|
|
@@ -119,8 +119,8 @@ export async function readPostPage(query: PostListQuery, database: typeof db = d
|
|
|
119
119
|
.execute() as PostListRow[]
|
|
120
120
|
|
|
121
121
|
const [byStatus, views] = await Promise.all([
|
|
122
|
-
database.selectFrom('posts').select(['status', database.fn.count('id').as('count')]).groupBy('status').execute() as
|
|
123
|
-
database.selectFrom('posts').select(database.fn.sum('views').as('views')).executeTakeFirst() as
|
|
122
|
+
database.selectFrom('posts').select(['status', database.fn.count('id').as('count')]).groupBy('status').execute() as unknown as Array<{ status: string, count: unknown }>,
|
|
123
|
+
database.selectFrom('posts').select(database.fn.sum('views').as('views')).executeTakeFirst() as unknown as { views?: unknown } | undefined,
|
|
124
124
|
])
|
|
125
125
|
|
|
126
126
|
const statusCount = (status: PostStatus) => byStatus
|
|
@@ -24,9 +24,14 @@ interface SourceResult<T> {
|
|
|
24
24
|
error: string
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* One source of the page, read on its own: a failure costs that source its
|
|
29
|
+
* numbers and says why, and the others still answer. The work is handed over
|
|
30
|
+
* unstarted, because a query answers (or fails) where it is written.
|
|
31
|
+
*/
|
|
32
|
+
async function inspectSource<T>(work: () => T | Promise<T>, fallback: T, message: string, source: string): Promise<SourceResult<T>> {
|
|
28
33
|
try {
|
|
29
|
-
return { value: await work, error: '' }
|
|
34
|
+
return { value: await work(), error: '' }
|
|
30
35
|
}
|
|
31
36
|
catch (error) {
|
|
32
37
|
return {
|
|
@@ -49,7 +54,7 @@ export default new Action({
|
|
|
49
54
|
const cpu = process.cpuUsage()
|
|
50
55
|
const databaseDriver = String(config.database?.default || 'unknown')
|
|
51
56
|
|
|
52
|
-
const requestSummaryQuery = db
|
|
57
|
+
const requestSummaryQuery = () => db
|
|
53
58
|
.selectFrom('requests')
|
|
54
59
|
.select([
|
|
55
60
|
db.fn.count('id').as('total'),
|
|
@@ -58,16 +63,16 @@ export default new Action({
|
|
|
58
63
|
db.fn.max('created_at').as('latest'),
|
|
59
64
|
])
|
|
60
65
|
.whereNull('deleted_at')
|
|
61
|
-
.executeTakeFirst() as
|
|
66
|
+
.executeTakeFirst() as unknown as NumericSummaryRow | undefined
|
|
62
67
|
|
|
63
|
-
const requestSuccessQuery = db
|
|
68
|
+
const requestSuccessQuery = () => db
|
|
64
69
|
.selectFrom('requests')
|
|
65
70
|
.select(db.fn.count('id').as('count'))
|
|
66
71
|
.whereNull('deleted_at')
|
|
67
72
|
.where('status_code', '<', 400)
|
|
68
|
-
.executeTakeFirst() as
|
|
73
|
+
.executeTakeFirst() as unknown as { count: number | string } | undefined
|
|
69
74
|
|
|
70
|
-
const slowRequestsQuery = db
|
|
75
|
+
const slowRequestsQuery = () => db
|
|
71
76
|
.selectFrom('requests')
|
|
72
77
|
.select(['id', 'method', 'path', 'status_code', 'duration_ms', 'created_at'])
|
|
73
78
|
.whereNull('deleted_at')
|
|
@@ -76,7 +81,7 @@ export default new Action({
|
|
|
76
81
|
.limit(5)
|
|
77
82
|
.execute()
|
|
78
83
|
|
|
79
|
-
const querySummaryQuery = db
|
|
84
|
+
const querySummaryQuery = () => db
|
|
80
85
|
.selectFrom('query_logs')
|
|
81
86
|
.select([
|
|
82
87
|
db.fn.count('id').as('total'),
|
|
@@ -84,15 +89,15 @@ export default new Action({
|
|
|
84
89
|
db.fn.max('duration').as('maximum'),
|
|
85
90
|
db.fn.max('executed_at').as('latest'),
|
|
86
91
|
])
|
|
87
|
-
.executeTakeFirst() as
|
|
92
|
+
.executeTakeFirst() as unknown as NumericSummaryRow | undefined
|
|
88
93
|
|
|
89
|
-
const queryStatusesQuery = db
|
|
94
|
+
const queryStatusesQuery = () => db
|
|
90
95
|
.selectFrom('query_logs')
|
|
91
96
|
.select(['status', db.fn.count('id').as('count')])
|
|
92
97
|
.groupBy('status')
|
|
93
|
-
.execute() as
|
|
98
|
+
.execute() as unknown as StatusCountRow[]
|
|
94
99
|
|
|
95
|
-
const slowQueriesQuery = db
|
|
100
|
+
const slowQueriesQuery = () => db
|
|
96
101
|
.selectFrom('query_logs')
|
|
97
102
|
.select(['id', 'query', 'duration', 'status', 'connection', 'executed_at'])
|
|
98
103
|
.where('duration', '>=', slowThresholdMs)
|
|
@@ -101,15 +106,15 @@ export default new Action({
|
|
|
101
106
|
.limit(5)
|
|
102
107
|
.execute()
|
|
103
108
|
|
|
104
|
-
const errorSummaryQuery = db
|
|
109
|
+
const errorSummaryQuery = () => db
|
|
105
110
|
.selectFrom('errors')
|
|
106
111
|
.select([
|
|
107
112
|
db.fn.count('id').as('total'),
|
|
108
113
|
db.fn.max('created_at').as('latest'),
|
|
109
114
|
])
|
|
110
|
-
.executeTakeFirst() as
|
|
115
|
+
.executeTakeFirst() as unknown as NumericSummaryRow | undefined
|
|
111
116
|
|
|
112
|
-
const recentErrorsQuery = db
|
|
117
|
+
const recentErrorsQuery = () => db
|
|
113
118
|
.selectFrom('errors')
|
|
114
119
|
.select(['id', 'type', 'message', 'status', 'created_at'])
|
|
115
120
|
.orderBy('created_at', 'desc')
|
|
@@ -144,10 +149,10 @@ export default new Action({
|
|
|
144
149
|
inspectSource(slowQueriesQuery, [], 'Query telemetry is unavailable.', 'queries.slowest'),
|
|
145
150
|
inspectSource(errorSummaryQuery, undefined, 'Error telemetry is unavailable.', 'errors.summary'),
|
|
146
151
|
inspectSource(recentErrorsQuery, [], 'Error telemetry is unavailable.', 'errors.recent'),
|
|
147
|
-
inspectSource(checkQueueHealth(), null, 'Queue telemetry is unavailable.', 'queue'),
|
|
148
|
-
inspectSource(cache.getStats(), null, 'Cache telemetry is unavailable.', 'cache'),
|
|
149
|
-
inspectSource(filesystemQuery, null, 'Filesystem telemetry is unavailable.', 'filesystem'),
|
|
150
|
-
inspectSource(databaseFileQuery, null, 'Database file telemetry is unavailable.', 'database-file'),
|
|
152
|
+
inspectSource(() => checkQueueHealth(), null, 'Queue telemetry is unavailable.', 'queue'),
|
|
153
|
+
inspectSource(() => cache.getStats(), null, 'Cache telemetry is unavailable.', 'cache'),
|
|
154
|
+
inspectSource(() => filesystemQuery, null, 'Filesystem telemetry is unavailable.', 'filesystem'),
|
|
155
|
+
inspectSource(() => databaseFileQuery, null, 'Database file telemetry is unavailable.', 'database-file'),
|
|
151
156
|
])
|
|
152
157
|
|
|
153
158
|
const requestTotal = countValue(requestSummary.value?.total)
|
|
@@ -125,12 +125,12 @@ export const localLogsProvider: DashboardLogsProvider = {
|
|
|
125
125
|
|
|
126
126
|
const [countRow, typeRows, sourceRows, projectRows] = await Promise.all([
|
|
127
127
|
applyFilters(db.selectFrom('logs').select(db.fn.count('id').as('count')))
|
|
128
|
-
.executeTakeFirst() as
|
|
128
|
+
.executeTakeFirst() as unknown as { count: number | string } | undefined,
|
|
129
129
|
applyFilters(db.selectFrom('logs').select(['type', db.fn.count('id').as('count')]))
|
|
130
130
|
.groupBy('type')
|
|
131
|
-
.execute() as
|
|
132
|
-
db.selectFrom('logs').select('source').distinct().orderBy('source', 'asc').limit(100).execute() as
|
|
133
|
-
db.selectFrom('logs').select('project').distinct().orderBy('project', 'asc').limit(500).execute() as
|
|
131
|
+
.execute() as unknown as Array<{ type: string, count: number | string }>,
|
|
132
|
+
db.selectFrom('logs').select('source').distinct().orderBy('source', 'asc').limit(100).execute() as unknown as Array<{ source: string }>,
|
|
133
|
+
db.selectFrom('logs').select('project').distinct().orderBy('project', 'asc').limit(500).execute() as unknown as Array<{ project: string }>,
|
|
134
134
|
])
|
|
135
135
|
|
|
136
136
|
const total = Number(countRow?.count || 0)
|
|
@@ -143,7 +143,7 @@ export async function readJobPage(query: JobListQuery): Promise<JobListPage> {
|
|
|
143
143
|
const [activeTotal, failedTotal, queueRows] = await Promise.all([
|
|
144
144
|
countOf(active),
|
|
145
145
|
countOf(failed),
|
|
146
|
-
db.unsafe('SELECT DISTINCT queue FROM jobs UNION SELECT DISTINCT queue FROM failed_jobs').execute() as
|
|
146
|
+
db.unsafe('SELECT DISTINCT queue FROM jobs UNION SELECT DISTINCT queue FROM failed_jobs').execute() as unknown as Array<{ queue: unknown }>,
|
|
147
147
|
])
|
|
148
148
|
|
|
149
149
|
const total = activeTotal + failedTotal
|
|
@@ -122,14 +122,14 @@ export default new Action({
|
|
|
122
122
|
WHERE cl.card_id IN (SELECT id FROM cards WHERE board_id = ${param(1)} AND archived = false)
|
|
123
123
|
ORDER BY l.name ASC`,
|
|
124
124
|
[id],
|
|
125
|
-
).execute() as
|
|
125
|
+
).execute() as unknown as Array<{ card_id: number, id: number, name: string, color: string }>,
|
|
126
126
|
db.unsafe(
|
|
127
127
|
`SELECT ca.card_id, ca.user_id, u.name, u.email
|
|
128
128
|
FROM card_assignees ca
|
|
129
129
|
LEFT JOIN users u ON u.id = ca.user_id
|
|
130
130
|
WHERE ca.card_id IN (SELECT id FROM cards WHERE board_id = ${param(1)} AND archived = false)`,
|
|
131
131
|
[id],
|
|
132
|
-
).execute() as
|
|
132
|
+
).execute() as unknown as Array<{ card_id: number, user_id: number, name: string | null, email: string | null }>,
|
|
133
133
|
])
|
|
134
134
|
|
|
135
135
|
const labelsByCard = new Map<number, Array<{ id: number, name: string, color: string }>>()
|
|
@@ -69,14 +69,14 @@ export default new Action({
|
|
|
69
69
|
WHERE cl.card_id = ${param(1)}
|
|
70
70
|
ORDER BY l.name ASC`,
|
|
71
71
|
[id],
|
|
72
|
-
).execute() as
|
|
72
|
+
).execute() as unknown as Array<{ id: number, name: string, color: string }>,
|
|
73
73
|
db.unsafe(
|
|
74
74
|
`SELECT ca.user_id, ca.assigned_by_user_id, ca.created_at, u.name, u.email
|
|
75
75
|
FROM card_assignees ca
|
|
76
76
|
LEFT JOIN users u ON u.id = ca.user_id
|
|
77
77
|
WHERE ca.card_id = ${param(1)}`,
|
|
78
78
|
[id],
|
|
79
|
-
).execute() as
|
|
79
|
+
).execute() as unknown as Array<{ user_id: number, assigned_by_user_id: number | null, created_at: string | null, name: string | null, email: string | null }>,
|
|
80
80
|
db.unsafe(
|
|
81
81
|
`SELECT cc.id, cc.uuid, cc.user_id, cc.body, cc.created_at, cc.updated_at, u.name, u.email
|
|
82
82
|
FROM card_comments cc
|
|
@@ -84,7 +84,7 @@ export default new Action({
|
|
|
84
84
|
WHERE cc.card_id = ${param(1)}
|
|
85
85
|
ORDER BY cc.created_at ASC, cc.id ASC`,
|
|
86
86
|
[id],
|
|
87
|
-
).execute() as
|
|
87
|
+
).execute() as unknown as Array<{ id: number, uuid: string | null, user_id: number | null, body: string, created_at: string | null, updated_at: string | null, name: string | null, email: string | null }>,
|
|
88
88
|
// Each one carries a freshly signed, expiring URL: the bytes are on a
|
|
89
89
|
// private disk, so there is no path the browser could fetch.
|
|
90
90
|
cardAttachments(id),
|
|
@@ -108,7 +108,7 @@ export async function signCardAttachmentUrl(
|
|
|
108
108
|
|
|
109
109
|
/** What `removeCardAttachments` runs its two statements through: `db`, or a transaction. */
|
|
110
110
|
export interface AttachmentStatementRunner {
|
|
111
|
-
unsafe: (sql: string, params?: unknown[]) => { execute: () =>
|
|
111
|
+
unsafe: (sql: string, params?: unknown[]) => { execute: () => unknown }
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -33,7 +33,7 @@ async function notificationDeliveryOverview() {
|
|
|
33
33
|
db
|
|
34
34
|
.selectFrom('notification_deliveries')
|
|
35
35
|
.select(db.fn.count('id').as('count'))
|
|
36
|
-
.executeTakeFirst() as
|
|
36
|
+
.executeTakeFirst() as unknown as CountRow | undefined,
|
|
37
37
|
db
|
|
38
38
|
.selectFrom('notification_deliveries')
|
|
39
39
|
.select(['status', db.fn.count('id').as('count')])
|
|
@@ -131,7 +131,7 @@ export async function readQueryLogPage(query: QueryListQuery, now: number = Date
|
|
|
131
131
|
FROM query_logs ${filter.all.sql}`,
|
|
132
132
|
filter.all.values,
|
|
133
133
|
).execute(),
|
|
134
|
-
db.unsafe(`SELECT DISTINCT connection FROM query_logs ${filter.range.sql} ORDER BY connection`, filter.range.values).execute() as
|
|
134
|
+
db.unsafe(`SELECT DISTINCT connection FROM query_logs ${filter.range.sql} ORDER BY connection`, filter.range.values).execute() as unknown as Array<{ connection: unknown }>,
|
|
135
135
|
])
|
|
136
136
|
|
|
137
137
|
const counts: QueryCounts = {
|
|
@@ -44,11 +44,11 @@ export async function readQueueCounts(database: typeof db = db): Promise<QueueCo
|
|
|
44
44
|
database.fn.min('id').as('first_id'),
|
|
45
45
|
])
|
|
46
46
|
.groupBy('queue')
|
|
47
|
-
.execute() as
|
|
47
|
+
.execute() as unknown as Array<{ queue: unknown, total: unknown, active: unknown, first_id: unknown }>,
|
|
48
48
|
database.selectFrom('failed_jobs')
|
|
49
49
|
.select(['queue', database.fn.count('id').as('failed')])
|
|
50
50
|
.groupBy('queue')
|
|
51
|
-
.execute() as
|
|
51
|
+
.execute() as unknown as Array<{ queue: unknown, failed: unknown }>,
|
|
52
52
|
])
|
|
53
53
|
|
|
54
54
|
const failed = new Map<string, number>()
|
|
@@ -31,7 +31,7 @@ export interface NamedRow {
|
|
|
31
31
|
|
|
32
32
|
/** What runs the two queries: the configured `db`, or a test's own connection. */
|
|
33
33
|
export interface NamedSearchRunner {
|
|
34
|
-
unsafe: (sql: string, values?: unknown[]) => { execute: () =>
|
|
34
|
+
unsafe: (sql: string, values?: unknown[]) => { execute: () => unknown }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function parseNamedSearchQuery(read: QueryReader): NamedSearchQuery | { error: string } {
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.571",
|
|
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.
|
|
5
|
+
"version": "0.75.571",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
|
-
"@stacksjs/mobile": "0.75.
|
|
48
|
+
"@stacksjs/mobile": "0.75.571",
|
|
49
49
|
"@stacksjs/sanitizer": "^0.2.864",
|
|
50
50
|
"@stacksjs/stx": "^0.2.864",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.571",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|