@bakery-framework/core 2.4.1 → 2.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cache/shared-db.ts +3 -4
- package/src/client/livereload.ts +2 -2
- package/src/client/utils.ts +0 -2
- package/src/compiler/dev-service.ts +1 -1
- package/src/compiler/prompt-tracker.ts +1 -1
- package/src/core/cache-version.ts +0 -5
- package/src/core/jsx.ts +1 -2
- package/src/global.d.ts +1 -2
- package/src/handlers/core/$base.ts +0 -1
- package/src/handlers/core/$dynamic.ts +0 -1
- package/src/handlers/core/$registry.ts +0 -1
- package/src/handlers/core/$routing.ts +0 -1
- package/src/logger/logger.ts +2 -2
- package/src/utils/common/index.ts +2 -2
- package/src/utils/fs.ts +4 -1
- package/src/utils/http/dom.ts +1 -1
- package/src/utils/http/etag.ts +0 -1
- package/src/utils/http/html.ts +1 -1
- package/src/utils/http/index.ts +1 -1
- package/src/utils/http/validate.ts +2 -4
- package/src/utils/common/match.ts +0 -6
- package/src/utils/common/try.ts +0 -6
- package/src/utils/http/escape.ts +0 -8
- package/src/utils/isomorphic/index.ts +0 -15
package/package.json
CHANGED
package/src/cache/shared-db.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Bakery } from '../core/bakery'
|
|
|
4
4
|
import { checkCacheVersion } from '../core/cache-version'
|
|
5
5
|
import { serveLog } from '../logger/serve-log'
|
|
6
6
|
import { fs } from '../utils'
|
|
7
|
-
import { Try } from '../utils/
|
|
7
|
+
import { Try } from '../utils/isomorphic/try'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The tiered cache's spill-to-disk store: sessions and LRU overflow.
|
|
@@ -134,9 +134,8 @@ if (!stored) {
|
|
|
134
134
|
export function applyJournalMode(db: Database, file: string): string {
|
|
135
135
|
const asked = Try.return(
|
|
136
136
|
() =>
|
|
137
|
-
db
|
|
138
|
-
|
|
139
|
-
.get()?.journal_mode ?? '',
|
|
137
|
+
db.query<{ journal_mode: string }, []>('PRAGMA journal_mode = WAL;').get()
|
|
138
|
+
?.journal_mode ?? '',
|
|
140
139
|
(error: Error) => `threw: ${error.message}`,
|
|
141
140
|
)
|
|
142
141
|
if (asked.toLowerCase() === 'wal') return 'wal'
|
package/src/client/livereload.ts
CHANGED
|
@@ -362,7 +362,7 @@ function connect() {
|
|
|
362
362
|
ws.onmessage = e => {
|
|
363
363
|
const data = typeof e.data === 'string' ? e.data : String(e.data)
|
|
364
364
|
|
|
365
|
-
// The server sends two frame shapes:
|
|
365
|
+
// The server sends two frame shapes: plain strings (a
|
|
366
366
|
// watcher-relative filename, or the literal 'force_reload') and JSON
|
|
367
367
|
// objects, currently `{type: 'error', title, body}` from
|
|
368
368
|
// compiler/dev-service.ts's notifyError. A relative path can never begin
|
|
@@ -374,7 +374,7 @@ function connect() {
|
|
|
374
374
|
frame = JSON.parse(data)
|
|
375
375
|
} catch {
|
|
376
376
|
// A '{'-prefixed frame that is not JSON is not a filename either;
|
|
377
|
-
// frame stays null and the string falls through as a
|
|
377
|
+
// frame stays null and the string falls through as a plain frame.
|
|
378
378
|
}
|
|
379
379
|
if (frame) {
|
|
380
380
|
if (frame.type === 'error') {
|
package/src/client/utils.ts
CHANGED
|
@@ -29,7 +29,7 @@ export function notifySockets(server: any, filename: string) {
|
|
|
29
29
|
* `{type: 'error', title, body}`. client/livereload.ts renders it as an
|
|
30
30
|
* overlay and removes it on the next successful reload frame.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
32
|
+
* Reload frames are plain filename strings: the client distinguishes
|
|
33
33
|
* the two by a leading `{`, so this must always be JSON and filenames must
|
|
34
34
|
* never be. Paths that cannot reach a live socket at all (worker dead, boot
|
|
35
35
|
* failure before `Bun.serve`) are covered client-side by the disconnect
|
|
@@ -64,11 +64,6 @@ export function isCacheStale(
|
|
|
64
64
|
)
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/** Test seam: forget that the check ran, so a fixture can exercise it again. */
|
|
68
|
-
export function __resetCacheVersionCheck(): void {
|
|
69
|
-
done = null
|
|
70
|
-
}
|
|
71
|
-
|
|
72
67
|
async function run(): Promise<void> {
|
|
73
68
|
// Workers inherit a directory the master already validated. Re-running here
|
|
74
69
|
// would race the master's own wipe.
|
package/src/core/jsx.ts
CHANGED
|
@@ -142,8 +142,7 @@ export function html<P = {}>(render: RenderFn<P>) {
|
|
|
142
142
|
const prefix =
|
|
143
143
|
startsAt < 0 ? '' : rawDom.slice(startsAt, startsAt + 9).toLowerCase()
|
|
144
144
|
|
|
145
|
-
if (prefix.startsWith('<html'))
|
|
146
|
-
return `<!DOCTYPE html>\n${rawDom}`
|
|
145
|
+
if (prefix.startsWith('<html')) return `<!DOCTYPE html>\n${rawDom}`
|
|
147
146
|
if (prefix.startsWith('<!doctype')) return rawDom
|
|
148
147
|
|
|
149
148
|
let title = 'Document'
|
package/src/global.d.ts
CHANGED
|
@@ -50,8 +50,7 @@ declare global {
|
|
|
50
50
|
* string) is ignored and the next middleware runs. See `$middleware.ts`.
|
|
51
51
|
*/
|
|
52
52
|
type MiddlewareResponse =
|
|
53
|
-
|
|
|
54
|
-
| import('./utils/common/json').JsonResponseData
|
|
53
|
+
Response | import('./utils/common/json').JsonResponseData
|
|
55
54
|
|
|
56
55
|
type HostEntry = {
|
|
57
56
|
root?: string
|
|
@@ -115,7 +115,6 @@ export namespace Route {
|
|
|
115
115
|
// namespace for its nested classes; `const RouteData = { Info: class {} }`
|
|
116
116
|
// provides only the value, and every one of those type references stops
|
|
117
117
|
// resolving.
|
|
118
|
-
// biome-ignore lint/complexity/noStaticOnlyClass: also a type namespace. See above
|
|
119
118
|
export class RouteData {
|
|
120
119
|
static Info = class Info {
|
|
121
120
|
readonly params: string[]
|
|
@@ -130,7 +130,6 @@ export class DynamicHandler extends Handler {
|
|
|
130
130
|
// Segment matching with catch-all and specificity precedence. The branches
|
|
131
131
|
// are the precedence rules; splitting them hides the ordering that is the
|
|
132
132
|
// whole point.
|
|
133
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: route-precedence dispatcher
|
|
134
133
|
static findDynamicRoute(path: string): Route.Info | null {
|
|
135
134
|
const root = Bakery.serveRoot
|
|
136
135
|
let deferred: Route.Info[] | null = null
|
|
@@ -125,7 +125,6 @@ export class HandlerMap<T extends typeof Handler = typeof Handler> extends Map<
|
|
|
125
125
|
*/
|
|
126
126
|
// The `probed` bookkeeping exists because middleware has side effects and
|
|
127
127
|
// must not run twice. That constraint is what the branching encodes.
|
|
128
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: cache-path + side-effect-sensitive probe loop
|
|
129
128
|
async resolve(path: string, req?: Request, ...rest: any[]) {
|
|
130
129
|
// The **resolved** host, not the header. `__hostname` is whatever arrived
|
|
131
130
|
// in `Host`, and `routeCache` is one bounded LRU shared by every tenant, so
|
package/src/logger/logger.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PromptTracker } from '../compiler/prompt-tracker'
|
|
2
2
|
import type { MapOf } from '../types'
|
|
3
3
|
import { Case } from '../utils/common/case'
|
|
4
|
-
import { match } from '../utils/
|
|
5
|
-
import { Try } from '../utils/
|
|
4
|
+
import { match } from '../utils/isomorphic/match'
|
|
5
|
+
import { Try } from '../utils/isomorphic/try'
|
|
6
6
|
|
|
7
7
|
const logLevels = ['info', 'warn', 'error', 'fatal', 'debug', 'trace'] as const
|
|
8
8
|
const byLength = 15
|
package/src/utils/fs.ts
CHANGED
|
@@ -585,7 +585,10 @@ export namespace FileSystem {
|
|
|
585
585
|
* of the source before it. That is how an SFC in a dev server kept its old
|
|
586
586
|
* styles beside a new template and script after three quick edits.
|
|
587
587
|
*/
|
|
588
|
-
function versionedName(
|
|
588
|
+
function versionedName(
|
|
589
|
+
cacheName: string,
|
|
590
|
+
sourceMtime: number | null,
|
|
591
|
+
): string {
|
|
589
592
|
if (!sourceMtime) return cacheName
|
|
590
593
|
const ext = parse(cacheName).ext
|
|
591
594
|
return `${cacheName.slice(0, cacheName.length - ext.length)}@${sourceMtime}${ext}`
|
package/src/utils/http/dom.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Bakery, hostStore } from '../../core/bakery'
|
|
|
4
4
|
import { hostEntryKey } from '../../core/config'
|
|
5
5
|
import type { MapOf } from '../../types'
|
|
6
6
|
import { is } from '../common/misc'
|
|
7
|
-
import { Try } from '../
|
|
7
|
+
import { Try } from '../isomorphic/try'
|
|
8
8
|
import { fs } from '../fs'
|
|
9
9
|
import { escapeScriptJson } from '../isomorphic/escape'
|
|
10
10
|
|
package/src/utils/http/etag.ts
CHANGED
|
@@ -135,7 +135,6 @@ export namespace ETag {
|
|
|
135
135
|
negotiationMemo.clear()
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: content negotiation, one branch per encoding outcome
|
|
139
138
|
function negotiateFile(file: Bun.BunFile, req?: Request) {
|
|
140
139
|
const fileName = file.name || 'file'
|
|
141
140
|
|
package/src/utils/http/html.ts
CHANGED
package/src/utils/http/index.ts
CHANGED
|
@@ -28,8 +28,7 @@ export interface StandardSchemaLike<T> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
type StandardResult<T> =
|
|
31
|
-
|
|
32
|
-
| { issues: readonly StandardIssue[] }
|
|
31
|
+
{ value: T; issues?: undefined } | { issues: readonly StandardIssue[] }
|
|
33
32
|
|
|
34
33
|
interface StandardIssue {
|
|
35
34
|
message: string
|
|
@@ -48,8 +47,7 @@ export interface ValidationIssue {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
export type ValidationResult<T> =
|
|
51
|
-
|
|
52
|
-
| { ok: false; issues: ValidationIssue[] }
|
|
50
|
+
{ ok: true; value: T } | { ok: false; issues: ValidationIssue[] }
|
|
53
51
|
|
|
54
52
|
function isStandardSchema<T>(v: Validator<T>): v is StandardSchemaLike<T> {
|
|
55
53
|
return typeof v === 'object' && v !== null && '~standard' in v
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Moved to `utils/isomorphic/match` so the browser bundle and the server share
|
|
3
|
-
* one implementation: the prototype-chain fix (`Object.hasOwn` rather than
|
|
4
|
-
* `in`) previously had to be applied to both copies separately.
|
|
5
|
-
*/
|
|
6
|
-
export * from '../isomorphic/match'
|
package/src/utils/common/try.ts
DELETED
package/src/utils/http/escape.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-facing path for the escaping primitives.
|
|
3
|
-
*
|
|
4
|
-
* The implementation lives in `utils/isomorphic/escape` because the browser
|
|
5
|
-
* bundle needs it too; server code imports it from here (or from `@server/utils`)
|
|
6
|
-
* so callers don't have to know which side of that boundary it sits on.
|
|
7
|
-
*/
|
|
8
|
-
export { escapeHtml, escapeScriptJson } from '../isomorphic/escape'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure utilities shared by the server and the browser bundle.
|
|
3
|
-
*
|
|
4
|
-
* Rule for this directory: no `Bun.*`, no node builtins, no DOM globals. These
|
|
5
|
-
* modules are compiled into the client bundle as-is, so anything that reaches
|
|
6
|
-
* for a runtime API belongs one layer up in `utils/` or in `client/`.
|
|
7
|
-
*/
|
|
8
|
-
export * from './case'
|
|
9
|
-
export * from './escape'
|
|
10
|
-
export * from './is'
|
|
11
|
-
export * from './match'
|
|
12
|
-
export * from './math'
|
|
13
|
-
export * from './misc'
|
|
14
|
-
export * from './stringify'
|
|
15
|
-
export * from './try'
|