镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 66028e4

Browse files
committed
fix: capture native HTTP metadata and bootstrap search projections
1 parent de6b101 commit 66028e4

28 files changed

Lines changed: 582 additions & 42 deletions

File tree

‎config/server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type { ServerConfig } from '@stacksjs/types'
1010
* Discord or GitHub Discussions.
1111
*/
1212
export default {
13+
// Opt in after publishing the native Request model and migrating its table.
14+
captureRequests: false,
1315
/**
1416
* **API Proxy**
1517
*

‎database/types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ declare module '@stacksjs/database' {
13991399
created_at: string
14001400
updated_at: string | null
14011401
deleted_at: string | null
1402-
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD"
1402+
method: string
14031403
path: string
14041404
status_code: number
14051405
duration_ms: number

‎docs/guide/buddy/commands.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,7 +5072,7 @@ List index settings
50725072

50735073
| Option | Description | Contract | Default |
50745074
| --- | --- | --- | --- |
5075-
| `-m`, `--model` | Target a specific model | value, optional | `false` |
5075+
| `-m`, `--model` | Target a specific model | value, required | `false` |
50765076
| `--verbose` | Enable verbose output | boolean, optional | `false` |
50775077

50785078
### `search-engine:update`
@@ -5086,7 +5086,7 @@ Indexes database data to search engine
50865086

50875087
| Option | Description | Contract | Default |
50885088
| --- | --- | --- | --- |
5089-
| `-m`, `--model` | Target a specific model | value, optional | `""` |
5089+
| `-m`, `--model` | Target a specific model | value, required | `false` |
50905090
| `-f`, `--flush` | Flushes all data from search engine | value, optional | `false` |
50915091
| `-s`, `--settings` | Update index settings | value, optional | `false` |
50925092
| `--verbose` | Enable verbose output | boolean, optional | `false` |

‎storage/framework/core/actions/src/dev/views.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { seedCsrfPageResponse } from './csrf'
88
import { resolveDefaultsResources } from './defaults-resources'
99
import { exitWithParent } from './exit-with-parent'
1010
import type { EnhancedRequest } from '@stacksjs/router'
11+
import { beginRequestCapture, finishRequestCapture } from '@stacksjs/router/request-capture'
1112

1213
/**
1314
* Boot the views/SSR dev server.
@@ -234,6 +235,7 @@ async function startDefaultServer() {
234235
// A page's ambient `ip`, resolved as `buddy serve` resolves it.
235236
clientAddress: viewClientAddress,
236237
onRequest: async (req: Request, server?: Parameters<typeof registerPeerSource>[0]) => {
238+
beginRequestCapture(req)
237239
// First, before any `await`: this request's scope for its server
238240
// scripts (see `installRequestScope()` above).
239241
const snapshot = enterRequestScope(req)
@@ -382,6 +384,7 @@ async function startDefaultServer() {
382384
}
383385

384386
const seeded = await seedCsrfPageResponse(req, current)
387+
finishRequestCapture(req, seeded ?? current)
385388
return seeded ?? (current === baseline ? secured : current)
386389
},
387390
})

‎storage/framework/core/actions/src/helpers/utils.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ export async function runAction(action: Action, options?: ActionOptions): Promis
294294
// whitespace without a shell, so a value or a path containing a space was
295295
// cut into several arguments (see `buddyOptionArgs`).
296296
const opts = isDevAction || !options ? [] : buddyOptionArgs(options as Record<string, any>)
297-
const cmd = ['bun', developmentCondition, watchFlag, path, ...opts].filter(Boolean)
297+
// Only optional launcher flags may disappear. An empty option value is
298+
// still an argv token: dropping it turns `--model ''` into `--model true`.
299+
const cmd = [...['bun', developmentCondition, watchFlag, path].filter(Boolean), ...opts]
298300

299301
// Ensure pantry packages are resolvable via NODE_PATH
300302
// This allows compiled pantry packages (e.g., bun-plugin-stx/serve.js) to
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { overridesReady } from '@stacksjs/config'
2+
import { injectGlobalAutoImports } from '@stacksjs/server'
3+
4+
/** Model projections have the same framework globals in CLI and API processes. */
5+
export async function prepareSearchModels(): Promise<void> {
6+
await overridesReady
7+
await injectGlobalAutoImports()
8+
}

‎storage/framework/core/actions/src/search/flush.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import process from 'node:process'
22
import { parseOptions } from '@stacksjs/cli'
33
import { log } from '@stacksjs/logging'
44
import { flushModelDocuments } from '@stacksjs/search-engine'
5+
import { prepareSearchModels } from './bootstrap'
6+
7+
await prepareSearchModels()
58

69
const options = parseOptions()
710

@@ -12,7 +15,9 @@ const result = await flushModelDocuments(modelOption)
1215
if (result?.isErr) {
1316
console.error(result.error)
1417
await log.error('Flushing search engine failed', result.error)
18+
await log.flush()
1519
process.exit(1)
1620
}
1721

22+
await log.flush()
1823
process.exit(0)

‎storage/framework/core/actions/src/search/import.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import process from 'node:process'
22
import { parseOptions } from '@stacksjs/cli'
33
import { log } from '@stacksjs/logging'
44
import { importModelDocuments } from '@stacksjs/search-engine'
5+
import { prepareSearchModels } from './bootstrap'
6+
7+
await prepareSearchModels()
58

69
const options = parseOptions()
710

@@ -12,7 +15,9 @@ const result = await importModelDocuments(modelOption)
1215
if (result?.isErr) {
1316
console.error(result.error)
1417
await log.error('Import to search engine failed', result.error)
18+
await log.flush()
1519
process.exit(1)
1620
}
1721

22+
await log.flush()
1823
process.exit(0)

‎storage/framework/core/actions/src/search/settings-list.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import process from 'node:process'
22
import { parseOptions } from '@stacksjs/cli'
33
import { log } from '@stacksjs/logging'
44
import { listIndexSettings } from '@stacksjs/search-engine'
5+
import { prepareSearchModels } from './bootstrap'
6+
7+
await prepareSearchModels()
58

69
const options = parseOptions()
710

@@ -12,7 +15,9 @@ const result = await listIndexSettings(modelOption)
1215
if (result?.isErr) {
1316
console.error(result.error)
1417
await log.error('Listing index settings failed', result.error)
18+
await log.flush()
1519
process.exit(1)
1620
}
1721

22+
await log.flush()
1823
process.exit(0)
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import process from 'node:process'
2+
import { parseOptions } from '@stacksjs/cli'
23
import { log } from '@stacksjs/logging'
34
import { updateIndexSettings } from '@stacksjs/search-engine'
5+
import { prepareSearchModels } from './bootstrap'
46

5-
const result = await updateIndexSettings()
7+
await prepareSearchModels()
8+
9+
const result = await updateIndexSettings(parseOptions().model as string | undefined)
610

711
if (result?.isErr) {
812
console.error(result.error)
913
await log.error('Updating search settings failed', result.error)
14+
await log.flush()
1015
process.exit(1)
1116
}
1217

18+
await log.flush()
1319
process.exit(0)

0 commit comments

Comments
 (0)