@atscript/moost-db 0.1.149 → 0.1.150

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/dist/index.cjs CHANGED
@@ -2108,6 +2108,393 @@ function walk(node, def, shallow) {
2108
2108
  }
2109
2109
  }
2110
2110
  //#endregion
2111
+ //#region src/http-path-design-time.ts
2112
+ const KEY$1 = "db.http.path";
2113
+ /** The `@db.http.path` value a model carried before moost-db first wrote its published path. */
2114
+ const designTime = /* @__PURE__ */ new WeakMap();
2115
+ /**
2116
+ * Remembers the model's own `@db.http.path` (or its absence) before the first
2117
+ * published path is mirrored into its runtime metadata. Idempotent.
2118
+ *
2119
+ * @since 0.1.150
2120
+ */
2121
+ function captureDesignTime(type) {
2122
+ if (!designTime.has(type)) designTime.set(type, type.metadata.get(KEY$1));
2123
+ }
2124
+ /**
2125
+ * The route hint a model declares with `@db.http.path` — never the path
2126
+ * moost-db mirrored into the runtime metadata afterwards. Decorators and
2127
+ * `assertExposed` read this.
2128
+ *
2129
+ * @since 0.1.150
2130
+ */
2131
+ function designTimeHttpPath(type) {
2132
+ return designTime.has(type) ? designTime.get(type) : type.metadata.get(KEY$1);
2133
+ }
2134
+ /** The captured design-time value (`undefined` when none was captured or declared). */
2135
+ function getDesignTime(type) {
2136
+ return designTime.get(type);
2137
+ }
2138
+ //#endregion
2139
+ //#region src/decorators.ts
2140
+ /**
2141
+ * DI token under which the {@link AtscriptDbReadable} instance
2142
+ * is exposed to the readable controller's constructor via `@Inject`.
2143
+ */
2144
+ const READABLE_DEF = "__atscript_db_readable_def";
2145
+ /**
2146
+ * DI token under which the {@link AtscriptDbTable} instance
2147
+ * is exposed to the controller's constructor via `@Inject`.
2148
+ * Points to the same token as READABLE_DEF for backward compatibility.
2149
+ */
2150
+ const TABLE_DEF = READABLE_DEF;
2151
+ function normalizeOptions(prefixOrOptions) {
2152
+ if (typeof prefixOrOptions === "string") return { prefix: prefixOrOptions };
2153
+ return prefixOrOptions ?? {};
2154
+ }
2155
+ /**
2156
+ * Builds the shared binding metadata for a decorator invocation: classifies
2157
+ * the binding form, computes the static route prefix, and packages a uniform
2158
+ * `resolve()` used by both the DI provide factory and the base controller's
2159
+ * `super(app)` fallback.
2160
+ */
2161
+ function buildBinding(binding, options, decoratorName) {
2162
+ const canonical = options.canonical;
2163
+ if ((0, _atscript_typescript_utils.isAnnotatedType)(binding)) {
2164
+ const model = binding;
2165
+ const space = options.space ?? model.metadata.get("db.space");
2166
+ const hinted = designTimeHttpPath(model);
2167
+ const prefix = options.prefix || hinted || model.metadata.get("db.table") || model.metadata.get("db.view") || model.id || "";
2168
+ const prefixSource = options.prefix ? "option" : hinted ? "annotation" : "name";
2169
+ if (!prefix) throw new Error(`[moost-db] @${decoratorName}: cannot derive a route prefix from the model token (no @db.http.path / @db.table / @db.view and no type id). Pass an explicit prefix.`);
2170
+ return {
2171
+ meta: {
2172
+ model,
2173
+ resolve: () => require_db_space_registry.resolveDbSpace(space).get(model),
2174
+ prefix,
2175
+ prefixSource,
2176
+ canonical
2177
+ },
2178
+ prefix
2179
+ };
2180
+ }
2181
+ if (typeof binding === "function") {
2182
+ if (!options.prefix) throw new Error(`[moost-db] @${decoratorName}: the lazy factory form needs an explicit route prefix (the readable is not created until app.init()). Pass a prefix, or use the model token form which derives it from @db.http.path / @db.table.`);
2183
+ return {
2184
+ meta: {
2185
+ resolve: binding,
2186
+ prefix: options.prefix,
2187
+ prefixSource: "option",
2188
+ canonical
2189
+ },
2190
+ prefix: options.prefix
2191
+ };
2192
+ }
2193
+ const readable = binding;
2194
+ const hinted = designTimeHttpPath(readable.type);
2195
+ const prefix = options.prefix || hinted || readable.tableName;
2196
+ return {
2197
+ meta: {
2198
+ model: readable.type,
2199
+ resolve: () => readable,
2200
+ prefix,
2201
+ prefixSource: options.prefix ? "option" : hinted ? "annotation" : "name",
2202
+ canonical
2203
+ },
2204
+ prefix
2205
+ };
2206
+ }
2207
+ function bindReadableController(binding, prefixOrOptions, decoratorName) {
2208
+ const { meta, prefix } = buildBinding(binding, normalizeOptions(prefixOrOptions), decoratorName);
2209
+ return (0, moost.ApplyDecorators)(getAtscriptDbMate().decorate((classMeta) => {
2210
+ classMeta.atscript_db_readable_binding = meta;
2211
+ return classMeta;
2212
+ }), (0, moost.Provide)(READABLE_DEF, () => meta.resolve()), (0, moost.Controller)(prefix), (0, moost.Inherit)());
2213
+ }
2214
+ /**
2215
+ * Combines the boilerplate needed to turn an {@link AsDbController}
2216
+ * subclass into a fully wired HTTP controller for a given `@db.table` model.
2217
+ *
2218
+ * Internally applies three decorators:
2219
+ * 1. **Provide** — registers the readable resolver under {@link TABLE_DEF}.
2220
+ * 2. **Controller** — registers the class as a Moost HTTP controller
2221
+ * with an optional route prefix (defaults to `@db.http.path`, then the
2222
+ * table name).
2223
+ * 3. **Inherit** — copies metadata (routes, guards, etc.) from the
2224
+ * parent class so they stay active in the derived controller.
2225
+ *
2226
+ * All three binding forms are supported (see {@link TReadableBinding}):
2227
+ *
2228
+ * ```ts
2229
+ * ‎@TableController(User) // model token (preferred)
2230
+ * ‎@TableController(User, { space: "analytics" })
2231
+ * ‎@TableController(() => db.getTable(User), "users") // lazy factory
2232
+ * ‎@TableController(usersTable) // instance (legacy)
2233
+ * export class UsersController extends AsDbController<typeof User> {}
2234
+ * ```
2235
+ *
2236
+ * Token and factory forms resolve lazily at first controller instantiation
2237
+ * (during `app.init()`), so the `DbSpace` does not have to exist when the
2238
+ * controller module is imported. For the token form, register the space with
2239
+ * `provideDbSpace(db)` before `app.init()`.
2240
+ *
2241
+ * @param binding Model token, lazy factory, or {@link AtscriptDbTable} instance.
2242
+ * @param prefixOrOptions Route prefix string, or {@link TControllerBindingOptions}.
2243
+ */
2244
+ const TableController = (binding, prefixOrOptions) => bindReadableController(binding, prefixOrOptions, "TableController");
2245
+ /**
2246
+ * Combines the boilerplate needed to turn an {@link AsDbReadableController}
2247
+ * subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
2248
+ *
2249
+ * Accepts the same three binding forms as {@link TableController}.
2250
+ *
2251
+ * @param binding Model token, lazy factory, or {@link AtscriptDbReadable} instance.
2252
+ * @param prefixOrOptions Route prefix string, or {@link TControllerBindingOptions}.
2253
+ *
2254
+ * @example
2255
+ * ```ts
2256
+ * ‎@ReadableController(ActiveTasks)
2257
+ * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
2258
+ * ```
2259
+ */
2260
+ const ReadableController = (binding, prefixOrOptions) => bindReadableController(binding, prefixOrOptions, "ReadableController");
2261
+ /**
2262
+ * Alias for {@link ReadableController} — use with view-backed controllers.
2263
+ *
2264
+ * @example
2265
+ * ```ts
2266
+ * ‎@ViewController(ActiveTasks)
2267
+ * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
2268
+ * ```
2269
+ */
2270
+ const ViewController = ReadableController;
2271
+ /**
2272
+ * Finds the readable binding written by `@TableController` /
2273
+ * `@ReadableController` / `@ViewController` on a controller class, walking the
2274
+ * prototype chain so intermediate undecorated classes don't hide the binding
2275
+ * (nearest decorated ancestor wins).
2276
+ */
2277
+ function findReadableBinding(ctor) {
2278
+ const mate = getAtscriptDbMate();
2279
+ let current = ctor;
2280
+ while (typeof current === "function") {
2281
+ const binding = mate.read(current)?.atscript_db_readable_binding;
2282
+ if (binding) return binding;
2283
+ current = Object.getPrototypeOf(current);
2284
+ }
2285
+ }
2286
+ /**
2287
+ * Resolves the readable bound to a controller class via
2288
+ * {@link findReadableBinding}, throwing with wiring guidance when none is
2289
+ * found.
2290
+ *
2291
+ * Used by {@link AsDbReadableController}'s constructor when `readable` is
2292
+ * `undefined` — i.e. a subclass with its own constructor called
2293
+ * `super(app)` instead of forwarding an injected instance.
2294
+ */
2295
+ function resolveBoundReadable(ctor) {
2296
+ const binding = findReadableBinding(ctor);
2297
+ if (binding) return binding.resolve();
2298
+ throw new Error(`[moost-db] ${ctor?.name || "controller"}: no readable bound. Either pass a table/view to super(...), or decorate the class with @TableController / @ReadableController (model token, lazy factory, or instance form).`);
2299
+ }
2300
+ //#endregion
2301
+ //#region src/http-path.ts
2302
+ const KEY = "db.http.path";
2303
+ /**
2304
+ * Normalizes a controller prefix into a public path: one leading slash, no
2305
+ * empty segments, no trailing slash.
2306
+ *
2307
+ * @since 0.1.150
2308
+ */
2309
+ function normalizeHttpPath(prefix) {
2310
+ return `/${prefix.split("/").filter(Boolean).join("/")}`;
2311
+ }
2312
+ /** A path with a route parameter or a wildcard cannot be a static picker URL. */
2313
+ function isParametricPath(path) {
2314
+ return path.split("/").some((s) => s.startsWith(":") || s.includes("*"));
2315
+ }
2316
+ /** Per app (the constructor's `app` argument): another app's construction never alters this app's records. */
2317
+ const bound = /* @__PURE__ */ new WeakMap();
2318
+ /**
2319
+ * Process-wide records per ctor: the fallback for an app that never
2320
+ * constructed the class itself (a DI singleton reused across apps), read only
2321
+ * when it holds exactly one model.
2322
+ */
2323
+ const boundAny = /* @__PURE__ */ new WeakMap();
2324
+ let boundVersion = 0;
2325
+ /**
2326
+ * Records that `ctor` serves `type` inside `app` (called by the readable base constructor).
2327
+ * Pure bookkeeping — nothing is written to the model. Only a NEW pair bumps
2328
+ * the version that invalidates per-app scopes.
2329
+ */
2330
+ function recordBoundType(app, ctor, type, canonical) {
2331
+ let ofApp = bound.get(app);
2332
+ if (!ofApp) {
2333
+ ofApp = /* @__PURE__ */ new WeakMap();
2334
+ bound.set(app, ofApp);
2335
+ }
2336
+ let models = ofApp.get(ctor);
2337
+ if (!models) {
2338
+ models = /* @__PURE__ */ new Map();
2339
+ ofApp.set(ctor, models);
2340
+ }
2341
+ let any = boundAny.get(ctor);
2342
+ if (!any) {
2343
+ any = /* @__PURE__ */ new Map();
2344
+ boundAny.set(ctor, any);
2345
+ }
2346
+ any.set(type, canonical);
2347
+ if (!models.has(type) || models.get(type) !== canonical) {
2348
+ models.set(type, canonical);
2349
+ boundVersion++;
2350
+ }
2351
+ }
2352
+ const apps = /* @__PURE__ */ new WeakMap();
2353
+ function stateOf(app) {
2354
+ let s = apps.get(app);
2355
+ if (!s) {
2356
+ s = {
2357
+ version: -1,
2358
+ published: false,
2359
+ hookAdded: false,
2360
+ warned: /* @__PURE__ */ new Set()
2361
+ };
2362
+ apps.set(app, s);
2363
+ }
2364
+ return s;
2365
+ }
2366
+ const idOf = (type) => type.id ?? "(unnamed model)";
2367
+ const hasOverview = (app) => !!app && typeof app.getControllersOverview === "function";
2368
+ function endsWithSegments(path, suffix) {
2369
+ const a = path.split("/").filter(Boolean);
2370
+ const b = suffix.split("/").filter(Boolean);
2371
+ if (b.length > a.length) return false;
2372
+ return b.every((seg, i) => a[a.length - b.length + i] === seg);
2373
+ }
2374
+ function warnOnce(app, s, key, message) {
2375
+ if (s.warned.has(key)) return;
2376
+ s.warned.add(key);
2377
+ try {
2378
+ app.getLogger?.("moost-db")?.warn(message);
2379
+ } catch {}
2380
+ }
2381
+ function buildScope(app, s) {
2382
+ const mounts = /* @__PURE__ */ new Map();
2383
+ for (const o of app.getControllersOverview()) {
2384
+ if (typeof o.computedPrefix !== "string") continue;
2385
+ const ctor = o.type;
2386
+ const binding = findReadableBinding(ctor);
2387
+ let recorded = bound.get(app)?.get(ctor);
2388
+ if (!recorded) {
2389
+ const any = boundAny.get(ctor);
2390
+ if (any?.size === 1) recorded = any;
2391
+ }
2392
+ const models = recorded?.size ? [...recorded] : binding?.model ? [[binding.model, void 0]] : [];
2393
+ if (models.length === 0) continue;
2394
+ if (models.length > 1) {
2395
+ warnOnce(app, s, `multi-model|${ctor.name}`, `[moost-db] ${ctor.name} serves several models; none of them gets a published value-help path (db.http.path).`);
2396
+ continue;
2397
+ }
2398
+ const [model, recordedCanonical] = models[0];
2399
+ const path = normalizeHttpPath(o.computedPrefix);
2400
+ const ownPrefix = o.meta?.controller?.prefix ?? "";
2401
+ const fromAnnotation = binding?.prefixSource === "annotation" && ownPrefix === binding.prefix && endsWithSegments(path, binding.prefix ?? "");
2402
+ const list = mounts.get(model) ?? [];
2403
+ list.push({
2404
+ ctor,
2405
+ path,
2406
+ canonical: binding?.canonical ?? recordedCanonical,
2407
+ fromAnnotation,
2408
+ parametric: isParametricPath(path)
2409
+ });
2410
+ mounts.set(model, list);
2411
+ }
2412
+ const paths = /* @__PURE__ */ new Map();
2413
+ for (const [model, list] of mounts) paths.set(model, resolveCanonical(app, s, model, list));
2414
+ return { paths };
2415
+ }
2416
+ const distinct = (list) => [...new Set(list.map((m) => m.path))];
2417
+ function resolveCanonical(app, s, model, list) {
2418
+ const cands = list.filter((m) => !m.parametric && m.canonical !== false);
2419
+ const marked = distinct(cands.filter((m) => m.canonical === true));
2420
+ if (marked.length === 1) return marked[0];
2421
+ if (marked.length > 1) return ambiguous(app, s, model, cands, "has several canonical mounts");
2422
+ const all = distinct(cands);
2423
+ if (all.length === 0) return null;
2424
+ if (all.length === 1) return all[0];
2425
+ const derived = distinct(cands.filter((m) => m.fromAnnotation));
2426
+ if (derived.length === 1) return derived[0];
2427
+ return ambiguous(app, s, model, cands, "is served by several controllers on different routes");
2428
+ }
2429
+ function ambiguous(app, s, model, cands, what) {
2430
+ const where = cands.map((m) => `${m.ctor.name} at ${m.path}`);
2431
+ const id = idOf(model);
2432
+ warnOnce(app, s, `${id}|${distinct(cands).toSorted().join(",")}|${what}`, `[moost-db] Model "${id}" ${what}:\n ${where.join(", ")}.\nIts value-help path (db.http.path) is left unset, so references to it render no picker.\nMark the controller that serves its value help with \`canonical: true\`\n(@TableController(${id}, { canonical: true }), or a value-help controller's \`{ canonical: true }\`\nconstructor option) or \`canonical: false\` on the others, or declare @db.http.path on the\nmodel and mount that controller without an explicit prefix.`);
2433
+ return null;
2434
+ }
2435
+ /**
2436
+ * The scope of `app`: built lazily, rebuilt on publish or when a new
2437
+ * controller → model pair was recorded. A hit never polls the overview.
2438
+ * `undefined` when `app` has no controller overview (mock apps).
2439
+ */
2440
+ function httpPathScopeFor(app) {
2441
+ if (!hasOverview(app)) return void 0;
2442
+ const s = stateOf(app);
2443
+ if (!s.scope || s.version !== boundVersion) {
2444
+ s.scope = buildScope(app, s);
2445
+ s.version = boundVersion;
2446
+ }
2447
+ return s.scope;
2448
+ }
2449
+ /** Models whose runtime metadata a publish wrote, with the value written. */
2450
+ const mirrored = /* @__PURE__ */ new Map();
2451
+ /** (Re)builds the scope of `app`, warns on ambiguity and writes the global compat mirror. */
2452
+ function publishDbHttpPaths(app) {
2453
+ if (!hasOverview(app)) return;
2454
+ const s = stateOf(app);
2455
+ s.published = true;
2456
+ s.scope = buildScope(app, s);
2457
+ s.version = boundVersion;
2458
+ const { paths } = s.scope;
2459
+ for (const [type, value] of paths) {
2460
+ captureDesignTime(type);
2461
+ if (value === null) type.metadata.delete(KEY);
2462
+ else type.metadata.set(KEY, value);
2463
+ mirrored.set(type, value ?? void 0);
2464
+ }
2465
+ for (const [type, written] of mirrored) {
2466
+ if (paths.has(type)) continue;
2467
+ if (type.metadata.get(KEY) === written) {
2468
+ const original = getDesignTime(type);
2469
+ if (original === void 0) type.metadata.delete(KEY);
2470
+ else type.metadata.set(KEY, original);
2471
+ }
2472
+ mirrored.delete(type);
2473
+ }
2474
+ }
2475
+ /** Lazy fallback for apps that never ran the hook (singletons reused across apps). */
2476
+ function ensurePublished(app) {
2477
+ if (!hasOverview(app)) return;
2478
+ if (!stateOf(app).published) publishDbHttpPaths(app);
2479
+ }
2480
+ /** Registers the publish hook once per app (no-op on mock apps without `addInitHook`). */
2481
+ function addPublishHook(app) {
2482
+ if (!app || typeof app.addInitHook !== "function") return;
2483
+ const s = stateOf(app);
2484
+ if (s.hookAdded) return;
2485
+ s.hookAdded = true;
2486
+ app.addInitHook((a) => publishDbHttpPaths(a), { priority: Number.MIN_SAFE_INTEGER });
2487
+ }
2488
+ /**
2489
+ * The `annotationOverrides` contribution for `scope`: the only way a path
2490
+ * reaches the wire. Models the app does not serve pass through at their
2491
+ * design-time value (never another app's mirror).
2492
+ */
2493
+ function httpPathOverrides(scope, type) {
2494
+ if (scope.paths.has(type)) return { [KEY]: scope.paths.get(type) ?? void 0 };
2495
+ if (mirrored.has(type) && type.metadata.get(KEY) === mirrored.get(type)) return { [KEY]: getDesignTime(type) };
2496
+ }
2497
+ //#endregion
2111
2498
  //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateMetadata.js
2112
2499
  function __decorateMetadata(k, v) {
2113
2500
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
@@ -2140,19 +2527,29 @@ let AsReadableController = class AsReadableController {
2140
2527
  app;
2141
2528
  /** Cached serialized type definition (lazy, computed on first access). */
2142
2529
  _serializedType;
2530
+ /** App scope every cache below was built for; a different scope drops them all ({@link enterScope}). */
2531
+ _cacheScope;
2532
+ /** Scope of the synchronous build in flight — instance-local, cleared in `finally`. */
2533
+ _buildScope;
2143
2534
  /** Cached full meta response (computed lazily on first meta() call). */
2144
2535
  _metaResponse;
2145
2536
  /** {@link metaCacheKey} the cached response was built for. */
2146
2537
  _metaResponseKey;
2147
2538
  /** Cached serialized form schemas keyed by `FormType.name` — populated lazily by {@link metaForm}. */
2148
2539
  _formSchemas = /* @__PURE__ */ new Map();
2149
- constructor(boundType, controllerName, app, kindTag = "readable") {
2540
+ /**
2541
+ * @param opts.canonical Multi-mount models only: marks (`true`) or excludes
2542
+ * (`false`) this controller as the model's published value-help route
2543
+ * (since 0.1.150). Decorator-bound controllers use the decorator option.
2544
+ */
2545
+ constructor(boundType, controllerName, app, kindTag = "readable", opts) {
2150
2546
  this.boundType = boundType;
2151
2547
  this.controllerName = controllerName;
2152
2548
  this.app = app;
2153
2549
  this.logger = app.getLogger(`db [${controllerName}]`);
2154
2550
  this.logger.info(`Initializing ${kindTag} controller`);
2155
- this._resolveHttpPath();
2551
+ recordBoundType(app, this.constructor, boundType, opts?.canonical);
2552
+ addPublishHook(app);
2156
2553
  try {
2157
2554
  const p = this.init();
2158
2555
  if (p instanceof Promise) p.catch((error) => {
@@ -2163,22 +2560,40 @@ let AsReadableController = class AsReadableController {
2163
2560
  throw error;
2164
2561
  }
2165
2562
  }
2166
- /** Sets @db.http.path on the type metadata from the controller's computed prefix. */
2167
- _resolveHttpPath() {
2168
- let prefix;
2563
+ /**
2564
+ * The app of the current event, through DI — never the one this
2565
+ * (singleton) instance was constructed in, which may be gone (a re-booted
2566
+ * app, a hot reload). Outside an event it is {@link app}.
2567
+ *
2568
+ * @since 0.1.150
2569
+ */
2570
+ async currentApp() {
2169
2571
  try {
2170
- prefix = (0, moost.useControllerContext)().getPrefix();
2171
- } catch {}
2172
- if (!prefix) prefix = (this.app.getControllersOverview?.()?.find((o) => o.type === this.constructor))?.computedPrefix;
2173
- if (prefix) {
2174
- if (!prefix.startsWith("/")) prefix = `/${prefix}`;
2175
- this.boundType.metadata.set("db.http.path", prefix);
2572
+ return await (0, moost.useControllerContext)().instantiate(moost.Moost);
2573
+ } catch {
2574
+ return this.app;
2176
2575
  }
2177
2576
  }
2178
- /** Lazily serializes the bound type (after all controllers have set @db.http.path). */
2577
+ /** Lazily serializes the bound type (dropped with the other caches on a scope change). */
2179
2578
  getSerializedType() {
2180
- if (!this._serializedType) this._serializedType = this.serializeForMeta(this.boundType);
2181
- return this._serializedType;
2579
+ return this._serializedType ??= this.serializeForMeta(this.boundType);
2580
+ }
2581
+ /** Drops every scope-dependent cache when `scope` is not the one they were built for. */
2582
+ enterScope(scope) {
2583
+ if (scope === this._cacheScope) return;
2584
+ this._cacheScope = scope;
2585
+ this._serializedType = void 0;
2586
+ this._metaResponse = void 0;
2587
+ this._formSchemas.clear();
2588
+ }
2589
+ /** Runs a synchronous build with `scope`'s `db.http.path` overrides applied. */
2590
+ buildScoped(scope, build) {
2591
+ this._buildScope = scope;
2592
+ try {
2593
+ return build();
2594
+ } finally {
2595
+ this._buildScope = void 0;
2596
+ }
2182
2597
  }
2183
2598
  /**
2184
2599
  * Serializes a type for the meta surfaces (`/meta`, `/meta/form/:name`)
@@ -2188,10 +2603,31 @@ let AsReadableController = class AsReadableController {
2188
2603
  * serialize exactly as before.
2189
2604
  */
2190
2605
  serializeForMeta(type) {
2191
- const options = this.getSerializeOptions();
2606
+ const options = this._effectiveSerializeOptions();
2192
2607
  return applyTerminalRefs((0, _atscript_typescript_utils.serializeAnnotatedType)(type, options), type, options);
2193
2608
  }
2194
2609
  /**
2610
+ * {@link getSerializeOptions} plus the current build's per-app `db.http.path`
2611
+ * overrides (a subclass's own `annotationOverrides` entry wins for the same key).
2612
+ */
2613
+ _effectiveSerializeOptions() {
2614
+ const base = this.getSerializeOptions();
2615
+ const scope = this._buildScope;
2616
+ if (!scope) return base;
2617
+ const own = base.annotationOverrides;
2618
+ return {
2619
+ ...base,
2620
+ annotationOverrides: (t) => {
2621
+ const ours = httpPathOverrides(scope, t);
2622
+ const theirs = own?.(t);
2623
+ return ours || theirs ? {
2624
+ ...ours,
2625
+ ...theirs
2626
+ } : void 0;
2627
+ }
2628
+ };
2629
+ }
2630
+ /**
2195
2631
  * One-time initialization hook. Override to seed data, register watchers, etc.
2196
2632
  */
2197
2633
  init() {}
@@ -2389,7 +2825,53 @@ let AsReadableController = class AsReadableController {
2389
2825
  */
2390
2826
  async meta() {
2391
2827
  await this.parseRequest("meta");
2392
- return this.resolveMeta();
2828
+ return this._withOwnHttpPath(await this.resolveMeta());
2829
+ }
2830
+ /**
2831
+ * The root of a controller's own `/meta` carries its own mount as
2832
+ * `db.http.path` (a secondary mount answers with its own route; references to
2833
+ * the model elsewhere carry the canonical one). Left alone for parametric
2834
+ * mounts and when the serialize options strip the key. Never mutates the
2835
+ * cached envelope.
2836
+ */
2837
+ _withOwnHttpPath(meta) {
2838
+ const KEY = "db.http.path";
2839
+ let prefix;
2840
+ try {
2841
+ prefix = (0, moost.useControllerContext)().getPrefix();
2842
+ } catch {
2843
+ return meta;
2844
+ }
2845
+ if (prefix === void 0 || prefix === null) return meta;
2846
+ const own = normalizeHttpPath(prefix);
2847
+ if (isParametricPath(own)) return meta;
2848
+ const options = this.getSerializeOptions();
2849
+ if (options.ignoreAnnotations?.includes(KEY)) return meta;
2850
+ let key = KEY;
2851
+ let value = own;
2852
+ if (options.processAnnotation) {
2853
+ const out = options.processAnnotation({
2854
+ key: KEY,
2855
+ value: own,
2856
+ path: [],
2857
+ kind: "object"
2858
+ });
2859
+ if (!out) return meta;
2860
+ key = out.key;
2861
+ value = out.value;
2862
+ }
2863
+ const type = meta.type;
2864
+ if (!type || type.metadata?.[key] === value) return meta;
2865
+ return {
2866
+ ...meta,
2867
+ type: {
2868
+ ...meta.type,
2869
+ metadata: {
2870
+ ...type.metadata,
2871
+ [key]: value
2872
+ }
2873
+ }
2874
+ };
2393
2875
  }
2394
2876
  /**
2395
2877
  * The `/meta` payload for the current request — the cached envelope
@@ -2401,12 +2883,17 @@ let AsReadableController = class AsReadableController {
2401
2883
  * @since 0.1.143
2402
2884
  */
2403
2885
  resolveMeta() {
2404
- const key = this.metaCacheKey();
2405
- if (!this._metaResponse || key !== this._metaResponseKey) {
2406
- this._metaResponse = this.buildMetaResponse();
2407
- this._metaResponseKey = key;
2408
- }
2409
- return this.applyMetaOverlay(this._metaResponse);
2886
+ return this.currentApp().then((app) => {
2887
+ ensurePublished(app);
2888
+ const scope = httpPathScopeFor(app);
2889
+ this.enterScope(scope);
2890
+ const key = this.metaCacheKey();
2891
+ if (!this._metaResponse || key !== this._metaResponseKey) {
2892
+ this._metaResponse = this.buildScoped(scope, () => this.buildMetaResponse());
2893
+ this._metaResponseKey = key;
2894
+ }
2895
+ return this.applyMetaOverlay(this._metaResponse);
2896
+ });
2410
2897
  }
2411
2898
  /**
2412
2899
  * Identity of the inputs the cached `/meta` envelope is built from — a new
@@ -2429,9 +2916,13 @@ let AsReadableController = class AsReadableController {
2429
2916
  const envelopes = discoverActions(this.constructor, this.app, this.logger);
2430
2917
  const formType = getControllerFormType(this.constructor, name);
2431
2918
  if (!formType || !await this.authorizeForm(name, envelopes.filter((e) => e.info.inputForm === name).map((e) => e.info.name))) throw new _moostjs_event_http.HttpError(404, `Unknown form "${name}"`);
2919
+ const app = await this.currentApp();
2920
+ ensurePublished(app);
2921
+ const scope = httpPathScopeFor(app);
2922
+ this.enterScope(scope);
2432
2923
  let cached = this._formSchemas.get(name);
2433
2924
  if (!cached) {
2434
- cached = this.serializeForMeta(formType);
2925
+ cached = this.buildScoped(scope, () => this.serializeForMeta(formType));
2435
2926
  this._formSchemas.set(name, cached);
2436
2927
  }
2437
2928
  return cached;
@@ -2513,6 +3004,7 @@ AsReadableController = __decorate([UseValidationErrorTransform(), __decorateMeta
2513
3004
  Object,
2514
3005
  String,
2515
3006
  typeof moost.Moost === "undefined" ? Object : moost.Moost,
3007
+ Object,
2516
3008
  Object
2517
3009
  ])], AsReadableController);
2518
3010
  //#endregion
@@ -3925,9 +4417,14 @@ var DecorationPlanner = class {
3925
4417
  if (memoize) memo.meta.set(meta, out);
3926
4418
  return out;
3927
4419
  }
3928
- /** The declared interface serialized for `/meta.decorations`, once per class. */
3929
- serialized(serialize) {
3930
- return this.index.memo.serialized ??= serialize();
4420
+ /** The declared interface serialized for `/meta.decorations`, once per class and app scope. */
4421
+ serialized(scope, serialize) {
4422
+ const { memo } = this.index;
4423
+ if (!memo.serialized || memo.serializedScope !== scope) {
4424
+ memo.serialized = serialize();
4425
+ memo.serializedScope = scope;
4426
+ }
4427
+ return memo.serialized;
3931
4428
  }
3932
4429
  };
3933
4430
  /** Removes what a read must not carry — the unserved declared keys and the hook-only paths — from `rows`. */
@@ -4014,153 +4511,6 @@ function stripsNothing(read) {
4014
4511
  return read === void 0 || read.dropKeys.length === 0 && read.dropPaths.length === 0;
4015
4512
  }
4016
4513
  //#endregion
4017
- //#region src/decorators.ts
4018
- /**
4019
- * DI token under which the {@link AtscriptDbReadable} instance
4020
- * is exposed to the readable controller's constructor via `@Inject`.
4021
- */
4022
- const READABLE_DEF = "__atscript_db_readable_def";
4023
- /**
4024
- * DI token under which the {@link AtscriptDbTable} instance
4025
- * is exposed to the controller's constructor via `@Inject`.
4026
- * Points to the same token as READABLE_DEF for backward compatibility.
4027
- */
4028
- const TABLE_DEF = READABLE_DEF;
4029
- function normalizeOptions(prefixOrOptions) {
4030
- if (typeof prefixOrOptions === "string") return { prefix: prefixOrOptions };
4031
- return prefixOrOptions ?? {};
4032
- }
4033
- /**
4034
- * Builds the shared binding metadata for a decorator invocation: classifies
4035
- * the binding form, computes the static route prefix, and packages a uniform
4036
- * `resolve()` used by both the DI provide factory and the base controller's
4037
- * `super(app)` fallback.
4038
- */
4039
- function buildBinding(binding, options, decoratorName) {
4040
- if ((0, _atscript_typescript_utils.isAnnotatedType)(binding)) {
4041
- const model = binding;
4042
- const space = options.space ?? model.metadata.get("db.space");
4043
- const prefix = options.prefix || model.metadata.get("db.http.path") || model.metadata.get("db.table") || model.metadata.get("db.view") || model.id || "";
4044
- if (!prefix) throw new Error(`[moost-db] @${decoratorName}: cannot derive a route prefix from the model token (no @db.http.path / @db.table / @db.view and no type id). Pass an explicit prefix.`);
4045
- return {
4046
- meta: {
4047
- model,
4048
- resolve: () => require_db_space_registry.resolveDbSpace(space).get(model)
4049
- },
4050
- prefix
4051
- };
4052
- }
4053
- if (typeof binding === "function") {
4054
- if (!options.prefix) throw new Error(`[moost-db] @${decoratorName}: the lazy factory form needs an explicit route prefix (the readable is not created until app.init()). Pass a prefix, or use the model token form which derives it from @db.http.path / @db.table.`);
4055
- return {
4056
- meta: { resolve: binding },
4057
- prefix: options.prefix
4058
- };
4059
- }
4060
- const readable = binding;
4061
- const prefix = options.prefix || readable.type.metadata.get("db.http.path") || readable.tableName;
4062
- return {
4063
- meta: {
4064
- model: readable.type,
4065
- resolve: () => readable
4066
- },
4067
- prefix
4068
- };
4069
- }
4070
- function bindReadableController(binding, prefixOrOptions, decoratorName) {
4071
- const { meta, prefix } = buildBinding(binding, normalizeOptions(prefixOrOptions), decoratorName);
4072
- return (0, moost.ApplyDecorators)(getAtscriptDbMate().decorate((classMeta) => {
4073
- classMeta.atscript_db_readable_binding = meta;
4074
- return classMeta;
4075
- }), (0, moost.Provide)(READABLE_DEF, () => meta.resolve()), (0, moost.Controller)(prefix), (0, moost.Inherit)());
4076
- }
4077
- /**
4078
- * Combines the boilerplate needed to turn an {@link AsDbController}
4079
- * subclass into a fully wired HTTP controller for a given `@db.table` model.
4080
- *
4081
- * Internally applies three decorators:
4082
- * 1. **Provide** — registers the readable resolver under {@link TABLE_DEF}.
4083
- * 2. **Controller** — registers the class as a Moost HTTP controller
4084
- * with an optional route prefix (defaults to `@db.http.path`, then the
4085
- * table name).
4086
- * 3. **Inherit** — copies metadata (routes, guards, etc.) from the
4087
- * parent class so they stay active in the derived controller.
4088
- *
4089
- * All three binding forms are supported (see {@link TReadableBinding}):
4090
- *
4091
- * ```ts
4092
- * ‎@TableController(User) // model token (preferred)
4093
- * ‎@TableController(User, { space: "analytics" })
4094
- * ‎@TableController(() => db.getTable(User), "users") // lazy factory
4095
- * ‎@TableController(usersTable) // instance (legacy)
4096
- * export class UsersController extends AsDbController<typeof User> {}
4097
- * ```
4098
- *
4099
- * Token and factory forms resolve lazily at first controller instantiation
4100
- * (during `app.init()`), so the `DbSpace` does not have to exist when the
4101
- * controller module is imported. For the token form, register the space with
4102
- * `provideDbSpace(db)` before `app.init()`.
4103
- *
4104
- * @param binding Model token, lazy factory, or {@link AtscriptDbTable} instance.
4105
- * @param prefixOrOptions Route prefix string, or {@link TControllerBindingOptions}.
4106
- */
4107
- const TableController = (binding, prefixOrOptions) => bindReadableController(binding, prefixOrOptions, "TableController");
4108
- /**
4109
- * Combines the boilerplate needed to turn an {@link AsDbReadableController}
4110
- * subclass into a fully wired HTTP controller for a given `@db.view` or `@db.table` model.
4111
- *
4112
- * Accepts the same three binding forms as {@link TableController}.
4113
- *
4114
- * @param binding Model token, lazy factory, or {@link AtscriptDbReadable} instance.
4115
- * @param prefixOrOptions Route prefix string, or {@link TControllerBindingOptions}.
4116
- *
4117
- * @example
4118
- * ```ts
4119
- * ‎@ReadableController(ActiveTasks)
4120
- * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
4121
- * ```
4122
- */
4123
- const ReadableController = (binding, prefixOrOptions) => bindReadableController(binding, prefixOrOptions, "ReadableController");
4124
- /**
4125
- * Alias for {@link ReadableController} — use with view-backed controllers.
4126
- *
4127
- * @example
4128
- * ```ts
4129
- * ‎@ViewController(ActiveTasks)
4130
- * export class ActiveTasksController extends AsDbReadableController<typeof ActiveTasks> {}
4131
- * ```
4132
- */
4133
- const ViewController = ReadableController;
4134
- /**
4135
- * Finds the readable binding written by `@TableController` /
4136
- * `@ReadableController` / `@ViewController` on a controller class, walking the
4137
- * prototype chain so intermediate undecorated classes don't hide the binding
4138
- * (nearest decorated ancestor wins).
4139
- */
4140
- function findReadableBinding(ctor) {
4141
- const mate = getAtscriptDbMate();
4142
- let current = ctor;
4143
- while (typeof current === "function") {
4144
- const binding = mate.read(current)?.atscript_db_readable_binding;
4145
- if (binding) return binding;
4146
- current = Object.getPrototypeOf(current);
4147
- }
4148
- }
4149
- /**
4150
- * Resolves the readable bound to a controller class via
4151
- * {@link findReadableBinding}, throwing with wiring guidance when none is
4152
- * found.
4153
- *
4154
- * Used by {@link AsDbReadableController}'s constructor when `readable` is
4155
- * `undefined` — i.e. a subclass with its own constructor called
4156
- * `super(app)` instead of forwarding an injected instance.
4157
- */
4158
- function resolveBoundReadable(ctor) {
4159
- const binding = findReadableBinding(ctor);
4160
- if (binding) return binding.resolve();
4161
- throw new Error(`[moost-db] ${ctor?.name || "controller"}: no readable bound. Either pass a table/view to super(...), or decorate the class with @TableController / @ReadableController (model token, lazy factory, or instance form).`);
4162
- }
4163
- //#endregion
4164
4514
  //#region src/permissions/crud-controls.ts
4165
4515
  /**
4166
4516
  * Static control whitelists per read op. Each list is the matching DTO's
@@ -4811,9 +5161,16 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
4811
5161
  }
4812
5162
  return out;
4813
5163
  }
5164
+ /**
5165
+ * The index visibility gate applies: {@link hasField} is overridden, or the
5166
+ * model has `@db.writeOnly` fields (never readable through a search hit).
5167
+ */
5168
+ get _indexGateActive() {
5169
+ return this._hasFieldOverridden || this._writeOnlySet.size > 0;
5170
+ }
4814
5171
  /** Every path `entry` reads is visible to this request. */
4815
5172
  _indexVisible(entry) {
4816
- return entry.fields.every(this.fieldVisibility.isVisible);
5173
+ return entry.fields.every((path) => this.fieldVisibility.isVisible(path) && (0, _atscript_db.selfOrAncestor)(path, this._writeOnlySet) === void 0);
4817
5174
  }
4818
5175
  /**
4819
5176
  * Native text search serves this request: the adapter searches natively
@@ -4832,7 +5189,7 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
4832
5189
  }
4833
5190
  _resolveNativeSearch(controls) {
4834
5191
  if (!this.readable.isSearchable()) return false;
4835
- if (!this._hasFieldOverridden) return true;
5192
+ if (!this._indexGateActive) return true;
4836
5193
  if (typeof controls.$index === "string" && controls.$index) return true;
4837
5194
  const def = this.indexFieldPaths().find((e) => e.type === "text" && e.isDefault);
4838
5195
  return def === void 0 || this._indexVisible(def);
@@ -4846,7 +5203,7 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
4846
5203
  * nonexistent index (the core's wording).
4847
5204
  */
4848
5205
  _checkIndexGate(controls) {
4849
- if (!this._hasFieldOverridden) return void 0;
5206
+ if (!this._indexGateActive) return void 0;
4850
5207
  const name = typeof controls.$index === "string" ? controls.$index : void 0;
4851
5208
  if (controls.$center !== void 0) {
4852
5209
  const geoIndexes = this.indexFieldPaths().filter((e) => e.type === "geo");
@@ -4878,7 +5235,7 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
4878
5235
  * `@db.column.searchable` fallback when any of its fields is visible).
4879
5236
  */
4880
5237
  _applyIndexVisibility(meta) {
4881
- if (!this._hasFieldOverridden) return meta;
5238
+ if (!this._indexGateActive) return meta;
4882
5239
  const entries = this.indexFieldPaths();
4883
5240
  const visibleDefault = (type) => {
4884
5241
  const def = entries.find((e) => e.type === type && e.isDefault);
@@ -5675,6 +6032,7 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
5675
6032
  for (const fd of this.readable.fieldDescriptors) {
5676
6033
  if (fd.ignored) continue;
5677
6034
  if (!fd.type?.metadata?.has?.("db.column.searchable")) continue;
6035
+ if (typeof (0, _atscript_db.searchMemberKind)(fd.type) === "object") continue;
5678
6036
  if (!this.capabilities.isPhysicallyFilterable(fd.path)) continue;
5679
6037
  out.push(fd.path);
5680
6038
  }
@@ -5747,6 +6105,14 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
5747
6105
  * nothing can apply is ignored. Resolvers (query targets, `resolveQuery`)
5748
6106
  * refuse it — a subclass override that applies the term must return a new
5749
6107
  * filter object.
6108
+ *
6109
+ * A string field matches when the term is a substring of its text; an
6110
+ * INTEGER field (`number.int` and its sizes, `@expect.int`,
6111
+ * `@db.default.increment`) when it is a substring of the number's decimal
6112
+ * text — `2946` finds `29461277` (since 0.1.150). To search numeric IDs
6113
+ * declare `@db.column.searchable` (fallback) or `@db.index.fulltext`
6114
+ * (native, exact number) on the integer field — override this hook only for
6115
+ * search rules the annotations cannot express.
5750
6116
  */
5751
6117
  applySearchFallback(filter, controls) {
5752
6118
  const term = controls.$search;
@@ -5785,6 +6151,51 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
5785
6151
  delete rest.$index;
5786
6152
  return rest;
5787
6153
  }
6154
+ /**
6155
+ * `$count` of a native text / vector search: the adapter's own count, so it
6156
+ * agrees with `/query` and `/pages`. A text search counts every match (the
6157
+ * single returned row is discarded); a vector search counts the nearest
6158
+ * neighbours up to `$limit` (default 1000), as `/query` returns them.
6159
+ */
6160
+ async _countSearched(strategy, filter, controls, sealedControls) {
6161
+ const { $count: _count, ...sealed } = sealedControls;
6162
+ if (strategy.kind === "search") {
6163
+ const q = {
6164
+ filter,
6165
+ controls: this._searchReadControls(controls, sealed, sealed.$select, {
6166
+ $skip: void 0,
6167
+ $limit: 1
6168
+ })
6169
+ };
6170
+ const { count } = await this.readable.searchWithCount(strategy.term, q, strategy.index);
6171
+ return count;
6172
+ }
6173
+ const q = {
6174
+ filter,
6175
+ controls: this._searchReadControls(controls, sealed, sealed.$select, {
6176
+ $skip: void 0,
6177
+ $limit: controls.$limit || 1e3
6178
+ })
6179
+ };
6180
+ const { count } = await (strategy.vectorField ? this.readable.vectorSearchWithCount(strategy.vectorField, strategy.vector, q) : this.readable.vectorSearchWithCount(strategy.vector, q));
6181
+ return count;
6182
+ }
6183
+ /**
6184
+ * The controls a native search / vector read is run with: the request's
6185
+ * sealed controls (so every search control — `$fuzzy`, … — reaches the
6186
+ * adapter) plus the select, the threshold and the caller's paging. ONE
6187
+ * builder for `/query`, `/pages` and the native `$count`, so they can't
6188
+ * disagree about what a search matches.
6189
+ */
6190
+ _searchReadControls(controls, sealed, select, paging) {
6191
+ const threshold = controls.$threshold ? Number(controls.$threshold) : void 0;
6192
+ return {
6193
+ ...sealed,
6194
+ $select: select,
6195
+ ...paging,
6196
+ $threshold: threshold
6197
+ };
6198
+ }
5788
6199
  async _resolveReadStrategy(controls) {
5789
6200
  const searchTerm = controls.$search;
5790
6201
  const indexName = controls.$index;
@@ -5839,21 +6250,13 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
5839
6250
  if (decorated === void 0) return strip();
5840
6251
  return Promise.resolve(decorated).then(strip);
5841
6252
  }
5842
- /**
5843
- * The app of the current event, through DI — never the one this
5844
- * (singleton) instance was constructed in, which may be gone (a re-booted
5845
- * app, a hot reload).
5846
- */
5847
- _currentApp() {
5848
- return (0, moost.useControllerContext)().instantiate(moost.Moost);
5849
- }
5850
6253
  /** The class's `@DbActionsFrom` delegations, validated on first use (per app). */
5851
6254
  async _delegations() {
5852
6255
  if (!this._hasDelegations) return [];
5853
6256
  return discoverDelegations({
5854
6257
  ctor: this.constructor,
5855
6258
  readable: this.readable,
5856
- app: await this._currentApp(),
6259
+ app: await this.currentApp(),
5857
6260
  logger: this.logger,
5858
6261
  instantiate: (ctor) => (0, moost.useControllerContext)().instantiate(ctor)
5859
6262
  });
@@ -6211,24 +6614,22 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
6211
6614
  }
6212
6615
  const [transformedFilter, { sealed, finish }] = await Promise.all([this.transformFilter(clientFilter), this._projectRead(controls)]);
6213
6616
  const filter = this.applySearchFallback(transformedFilter, controls);
6214
- if (controls.$count) return this.readable.count({
6215
- filter,
6216
- controls: {
6217
- ...controls,
6218
- $select: sealed.$select
6219
- }
6220
- });
6617
+ if (controls.$count) {
6618
+ const strategy = await this._resolveReadStrategy(controls);
6619
+ if (strategy.kind === "plain") return this.readable.count({
6620
+ filter,
6621
+ controls: {
6622
+ ...controls,
6623
+ $select: sealed.$select
6624
+ }
6625
+ });
6626
+ return this._countSearched(strategy, filter, controls, sealed);
6627
+ }
6221
6628
  const projected = finish();
6222
6629
  if (projected instanceof _moostjs_event_http.HttpError) return projected;
6223
- const threshold = controls.$threshold ? Number(controls.$threshold) : void 0;
6224
6630
  const queryObj = {
6225
6631
  filter,
6226
- controls: {
6227
- ...sealed,
6228
- $select: projected.select,
6229
- $limit: controls.$limit || 1e3,
6230
- $threshold: threshold
6231
- }
6632
+ controls: this._searchReadControls(controls, sealed, projected.select, { $limit: controls.$limit || 1e3 })
6232
6633
  };
6233
6634
  return (await this._runReadWithActions("query", queryObj, controls, projected, async (q, strategy) => {
6234
6635
  switch (strategy.kind) {
@@ -6255,16 +6656,12 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
6255
6656
  const filter = this.applySearchFallback(transformedFilter, controls);
6256
6657
  const projected = finish();
6257
6658
  if (projected instanceof _moostjs_event_http.HttpError) return projected;
6258
- const threshold = controls.$threshold ? Number(controls.$threshold) : void 0;
6259
6659
  const query = {
6260
6660
  filter,
6261
- controls: {
6262
- ...sealed,
6263
- $select: projected.select,
6661
+ controls: this._searchReadControls(controls, sealed, projected.select, {
6264
6662
  $skip: skip,
6265
- $limit: size,
6266
- $threshold: threshold
6267
- }
6663
+ $limit: size
6664
+ })
6268
6665
  };
6269
6666
  const result = await this._runReadWithActions("pages", query, controls, projected, async (q, strategy) => {
6270
6667
  switch (strategy.kind) {
@@ -6745,7 +7142,7 @@ let AsDbReadableController = _AsDbReadableController = class AsDbReadableControl
6745
7142
  relations,
6746
7143
  fields,
6747
7144
  type: this.getSerializedType(),
6748
- ...this._decorations && { decorations: this._planner.serialized(() => this.serializeForMeta(this._decorations.type)) },
7145
+ ...this._decorations && { decorations: this._planner.serialized(this._buildScope, () => this.serializeForMeta(this._decorations.type)) },
6749
7146
  actions: this.buildActions(),
6750
7147
  crud: this.buildCrud(),
6751
7148
  versionColumn: this.readable.versionColumn,
@@ -7028,7 +7425,8 @@ let AsDbController = _AsDbController = class AsDbController extends AsDbReadable
7028
7425
  * Bulk auto-lift: each item carries its own `version` → `$cas`.
7029
7426
  * NOTE: per-item conflict disambiguation in the response body is deferred
7030
7427
  * (§6.4) — the aggregate `{ matchedCount, modifiedCount }` surfaces partial
7031
- * application; callers can detect mismatches via `modifiedCount < N`.
7428
+ * application; callers can detect mismatches via `matchedCount < N` (`modifiedCount` may
7429
+ * be lower for unchanged values, e.g. a version-exempt patch on MySQL / Mongo).
7032
7430
  */
7033
7431
  _resolveBulkCas(rows, versionColumn) {
7034
7432
  if (versionColumn === void 0) return;
@@ -7240,8 +7638,8 @@ let AsValueHelpController = class AsValueHelpController extends AsReadableContro
7240
7638
  searchableFields;
7241
7639
  /** The `@meta.id` field name on the bound interface, if any. */
7242
7640
  primaryKey;
7243
- constructor(boundType, controllerName, app) {
7244
- super(boundType, controllerName, app, "value-help");
7641
+ constructor(boundType, controllerName, app, opts) {
7642
+ super(boundType, controllerName, app, "value-help", opts);
7245
7643
  assertNoValueHelpActions(this.constructor);
7246
7644
  const fieldMeta = /* @__PURE__ */ new Map();
7247
7645
  const explicitlySearchable = [];
@@ -7457,7 +7855,8 @@ __decorate([
7457
7855
  AsValueHelpController = __decorate([(0, moost.Inherit)(), __decorateMetadata("design:paramtypes", [
7458
7856
  Object,
7459
7857
  String,
7460
- typeof moost.Moost === "undefined" ? Object : moost.Moost
7858
+ typeof moost.Moost === "undefined" ? Object : moost.Moost,
7859
+ Object
7461
7860
  ])], AsValueHelpController);
7462
7861
  registerAsValueHelpController(AsValueHelpController);
7463
7862
  //#endregion
@@ -7465,9 +7864,9 @@ registerAsValueHelpController(AsValueHelpController);
7465
7864
  let AsJsonValueHelpController = class AsJsonValueHelpController extends AsValueHelpController {
7466
7865
  rows;
7467
7866
  _pkIndex;
7468
- constructor(boundType, rows, app, controllerName) {
7867
+ constructor(boundType, rows, app, controllerName, opts) {
7469
7868
  const name = controllerName || boundType.metadata.get("db.table") || "value-help";
7470
- super(boundType, name, app);
7869
+ super(boundType, name, app, opts);
7471
7870
  this.rows = rows;
7472
7871
  if (this.primaryKey) {
7473
7872
  const pk = this.primaryKey;
@@ -7542,7 +7941,8 @@ AsJsonValueHelpController = __decorate([(0, moost.Inherit)(), __decorateMetadata
7542
7941
  Object,
7543
7942
  Array,
7544
7943
  typeof moost.Moost === "undefined" ? Object : moost.Moost,
7545
- String
7944
+ String,
7945
+ Object
7546
7946
  ])], AsJsonValueHelpController);
7547
7947
  //#endregion
7548
7948
  //#region src/assert-exposed.ts
@@ -7586,7 +7986,7 @@ function assertExposed(app, models, options) {
7586
7986
  const missing = [];
7587
7987
  for (const model of models) {
7588
7988
  if ((0, _atscript_db.aliasTargetOf)(model)) continue;
7589
- const httpPath = model.metadata.get("db.http.path");
7989
+ const httpPath = designTimeHttpPath(model);
7590
7990
  if (!auditAll && httpPath === void 0) continue;
7591
7991
  if (excluded.has(model) || exposed.has(model)) continue;
7592
7992
  missing.push(model);