@bakery-framework/core 2.0.0-alpha.6 → 2.0.0-alpha.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/core",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.7",
4
4
  "description": "Bakery framework core: handlers, router, config, session, caches, logger, compiler.",
5
5
  "keywords": [
6
6
  "bakery",
package/src/core/index.ts CHANGED
@@ -4,6 +4,10 @@ import { Case, is, Math2, match, Try } from '../utils/common'
4
4
  import { encodeSSE, response, sse } from '../utils/http'
5
5
  import Bakery, { getHostname, hostKey, hostStore } from './bakery'
6
6
  import { getConfig, NOOP } from './config'
7
+ // `./context` is already in this barrel's graph — line 5 reaches it through
8
+ // `./bakery`, which re-exports `hostStore` from exactly here — so naming it
9
+ // adds no module edge, only a name.
10
+ import { getFrameworkVersion } from './context'
7
11
  import { createElement, Fragment, html } from './jsx'
8
12
 
9
13
  export const defineConfig = <T extends AppConfig>(config: T): T => config
@@ -63,6 +67,19 @@ export {
63
67
  encodeSSE,
64
68
  Fragment,
65
69
  getConfig,
70
+ /**
71
+ * The version of `@bakery-framework/core` itself, read from its own manifest.
72
+ *
73
+ * **Not the app's version**, which is what `import.meta.env.BAKERY_VERSION`
74
+ * and `getAppVersion()` report — the compiler reads those from
75
+ * `<cwd>/package.json`, so in an application they answer with the
76
+ * application's number. The name is a long-standing misnomer and this is the
77
+ * one that means what "Bakery version" sounds like it means.
78
+ *
79
+ * Exported because a plugin rendering framework chrome has no other way to
80
+ * ask. The dashboard's footer showed a hardcoded `v3` for want of it.
81
+ */
82
+ getFrameworkVersion,
66
83
  // Multi-host helpers. Documented in docs/configuration/multi-host.md, and
67
84
  // the only reason `./core/bakery` had to be a subpath of its own.
68
85
  getHostname,
@@ -30,11 +30,16 @@ export class HandlerMap<T extends typeof Handler = typeof Handler> extends Map<
30
30
  }
31
31
  }
32
32
 
33
- set(handlerClass: any, priority: number = 10): this {
34
- super.set(handlerClass, priority)
33
+ /** Drop the derived views. Every mutation has to call this, not just `set`. */
34
+ private invalidate(): void {
35
35
  this.cachedList = null
36
36
  this.cachedGates = null
37
37
  this.cachedOrder = null
38
+ }
39
+
40
+ set(handlerClass: any, priority: number = 10): this {
41
+ super.set(handlerClass, priority)
42
+ this.invalidate()
38
43
  return this
39
44
  }
40
45
 
@@ -42,6 +47,30 @@ export class HandlerMap<T extends typeof Handler = typeof Handler> extends Map<
42
47
  return this.set(handlerClass, priority)
43
48
  }
44
49
 
50
+ /**
51
+ * `delete` and `clear` invalidate too, and neither used to.
52
+ *
53
+ * `list()` memoizes the sorted handler array and only `set` cleared it, so a
54
+ * removed handler stayed in the list — and therefore stayed *in the request
55
+ * pipeline* — until something happened to add one. Registration is
56
+ * add-only in a served process, which is why this never bit: it is reachable
57
+ * only by code that unregisters, and the first thing to do that was a test.
58
+ *
59
+ * A cache that survives the removal of its input is wrong regardless of who
60
+ * currently calls it, and "nothing removes handlers today" is a property of
61
+ * the callers rather than of this class.
62
+ */
63
+ override delete(handlerClass: any): boolean {
64
+ const removed = super.delete(handlerClass)
65
+ if (removed) this.invalidate()
66
+ return removed
67
+ }
68
+
69
+ override clear(): void {
70
+ super.clear()
71
+ this.invalidate()
72
+ }
73
+
45
74
  list(): T[] {
46
75
  if (this.cachedList) {
47
76
  return this.cachedList