@guren/server 2.10.1 → 2.11.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.
@@ -2,8 +2,28 @@ import type { ResourceData, ResourceClass } from './types.js';
2
2
  /**
3
3
  * Abstract base class for API resources.
4
4
  * Transforms model data into API response format.
5
+ *
6
+ * `TData` names the payload `toArray()` builds, so `toJSON()` reports it too:
7
+ * `class PostResource extends Resource<PostRecord, PostResourceData>`. Without
8
+ * it every subclass had to restate the payload in an override whose only body
9
+ * was `return super.toJSON() as PostResourceData` — a cast that says nothing a
10
+ * type parameter cannot, and one nothing checks against the `toArray()` right
11
+ * above it.
12
+ *
13
+ * It defaults to `ResourceData` so `Resource<T>` and those overrides keep
14
+ * compiling: an override narrowing the return type stays assignable to the
15
+ * base. The polymorphic alternative (`toJSON(): ReturnType<this['toArray']>`)
16
+ * needs no parameter at all but rejects every existing override, which is a
17
+ * breaking change for code the scaffolds have been emitting all along.
18
+ *
19
+ * `TData` is a claim about `toArray()`, not about `toJSON()`'s every key:
20
+ * `additional()` takes arbitrary `ResourceData` and is spread *after* the
21
+ * payload, so a key that collides overwrites a typed field while the return
22
+ * type still reads `TData`. That hole is not new — it is what the
23
+ * `super.toJSON() as PostResourceData` override asserted past — but the type
24
+ * parameter does not close it. `additional()` is for keys beside the payload.
5
25
  */
6
- export declare abstract class Resource<T> {
26
+ export declare abstract class Resource<T, TData extends ResourceData = ResourceData> {
7
27
  /**
8
28
  * The underlying resource.
9
29
  */
@@ -17,11 +37,11 @@ export declare abstract class Resource<T> {
17
37
  * Transform the resource into an array/object.
18
38
  * Must be implemented by subclasses.
19
39
  */
20
- abstract toArray(): ResourceData;
40
+ abstract toArray(): TData;
21
41
  /**
22
42
  * Transform the resource to JSON.
23
43
  */
24
- toJSON(): ResourceData;
44
+ toJSON(): TData;
25
45
  /**
26
46
  * Add additional data to the resource.
27
47
  */
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { r as isMcpEndpointEnabled } from "./endpoint-D-20PiHY.js";
11
11
  import { n as isHotReloadRuntime, r as matchingOpenParen, t as claimHotDisposable } from "./hot-disposables-WsTX2ySN.js";
12
12
  import { a as setI18n, c as tryGetI18n, d as getPluralizationRule, f as pluralizationRules, i as getI18n, l as JsonLoader, n as I18nManager, o as t, p as selectPluralForm, r as createI18n, s as tc, t as MemoryLoader, u as Translator } from "./i18n-mcWi7LCd.js";
13
13
  import { _ as AuthorizationException, a as Policy, c as Response$1, d as cannot, f as createGate, g as setGate, i as withAuthorization, l as authorize, m as getGate, n as authorizeMiddleware, o as definePolicy, p as defineGate, r as authorizeResourceMiddleware, s as Gate, t as authorizeAllMiddleware, u as can } from "./authorization-Dbcuc5ZK.js";
14
- import { a as logDevServerBanner, i as isWildcardHost, o as DEFAULT_DEV_STYLES_ENTRY, r as formatHostPort, s as parseImportMap, t as startViteDevServer } from "./vite-dev-server-CpCUqmiC.js";
14
+ import { a as logDevServerBanner, i as isWildcardHost, o as DEFAULT_DEV_STYLES_ENTRY, r as formatHostPort, s as parseImportMap, t as startViteDevServer } from "./vite-dev-server-BSJkduhZ.js";
15
15
  import { r as isDocsViewerEnabled } from "./endpoint-D6GIqOpe.js";
16
16
  import { a as RequestFinished, c as UserLoggedOut, d as createEventManager, f as Event, i as JobProcessed, l as Listener, n as ApplicationStarted, o as RequestReceived, r as JobFailed, s as UserAuthenticated, t as ApplicationShutdown, u as EventManager } from "./events-aIH_bWRx.js";
17
17
  import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, t as CacheManager } from "./cache-BYnZf2FR.js";
@@ -5661,6 +5661,26 @@ function createSeederRunner(options) {
5661
5661
  /**
5662
5662
  * Abstract base class for API resources.
5663
5663
  * Transforms model data into API response format.
5664
+ *
5665
+ * `TData` names the payload `toArray()` builds, so `toJSON()` reports it too:
5666
+ * `class PostResource extends Resource<PostRecord, PostResourceData>`. Without
5667
+ * it every subclass had to restate the payload in an override whose only body
5668
+ * was `return super.toJSON() as PostResourceData` — a cast that says nothing a
5669
+ * type parameter cannot, and one nothing checks against the `toArray()` right
5670
+ * above it.
5671
+ *
5672
+ * It defaults to `ResourceData` so `Resource<T>` and those overrides keep
5673
+ * compiling: an override narrowing the return type stays assignable to the
5674
+ * base. The polymorphic alternative (`toJSON(): ReturnType<this['toArray']>`)
5675
+ * needs no parameter at all but rejects every existing override, which is a
5676
+ * breaking change for code the scaffolds have been emitting all along.
5677
+ *
5678
+ * `TData` is a claim about `toArray()`, not about `toJSON()`'s every key:
5679
+ * `additional()` takes arbitrary `ResourceData` and is spread *after* the
5680
+ * payload, so a key that collides overwrites a typed field while the return
5681
+ * type still reads `TData`. That hole is not new — it is what the
5682
+ * `super.toJSON() as PostResourceData` override asserted past — but the type
5683
+ * parameter does not close it. `additional()` is for keys beside the payload.
5664
5684
  */
5665
5685
  var Resource = class {
5666
5686
  /**
@@ -1,6 +1,6 @@
1
1
  import { n as trimTrailingSlashes } from "../trim-slashes-ZJ_VsY5s.js";
2
2
  import { n as hash } from "../Hash-CzrwKeDp.js";
3
- import { a as logDevServerBanner, n as GUREN_ASCII_ART, s as parseImportMap, t as startViteDevServer } from "../vite-dev-server-CpCUqmiC.js";
3
+ import { a as logDevServerBanner, n as GUREN_ASCII_ART, s as parseImportMap, t as startViteDevServer } from "../vite-dev-server-BSJkduhZ.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { realpath } from "node:fs/promises";
6
6
  import { dirname, extname, join, resolve, sep } from "node:path";
@@ -37,7 +37,7 @@ function parseImportMap(value, options = {}) {
37
37
  const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
38
38
  //#endregion
39
39
  //#region package.json
40
- var version = "2.10.1";
40
+ var version = "2.11.0";
41
41
  //#endregion
42
42
  //#region src/http/dev-banner.ts
43
43
  figlet.parseFont("Standard", standard);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.10.1",
3
+ "version": "2.11.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",