@guren/server 2.6.0 → 2.8.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.
@@ -6,7 +6,7 @@ import standard from "figlet/importable-fonts/Standard.js";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@guren/server",
9
- version: "2.6.0",
9
+ version: "2.8.0",
10
10
  type: "module",
11
11
  license: "MIT",
12
12
  repository: {
@@ -119,7 +119,7 @@ var package_default = {
119
119
  test: "bun test"
120
120
  },
121
121
  dependencies: {
122
- "@guren/orm": "^2.4.0",
122
+ "@guren/orm": "^2.5.0",
123
123
  "@modelcontextprotocol/sdk": "^1.30.0",
124
124
  chalk: "^5.3.0",
125
125
  consola: "^3.4.2",
@@ -16,6 +16,18 @@ import {
16
16
  } from "fs/promises";
17
17
  import { existsSync } from "fs";
18
18
  import { join, dirname, resolve, sep } from "path";
19
+
20
+ // src/support/warn-once.ts
21
+ var warned = /* @__PURE__ */ new Set();
22
+ function warnOnce(key, message) {
23
+ if (warned.has(key)) {
24
+ return;
25
+ }
26
+ warned.add(key);
27
+ console.warn(message);
28
+ }
29
+
30
+ // src/storage/drivers/LocalDriver.ts
19
31
  var LocalDriver = class {
20
32
  root;
21
33
  baseUrl;
@@ -47,6 +59,9 @@ var LocalDriver = class {
47
59
  }
48
60
  }
49
61
  async put(path, content, options) {
62
+ if (options?.visibility) {
63
+ this.warnUnsupportedVisibility(options.visibility, "put");
64
+ }
50
65
  const fullPath = this.fullPath(path);
51
66
  await this.ensureDirectory(fullPath);
52
67
  const buffer = typeof content === "string" ? Buffer.from(content) : content;
@@ -181,10 +196,31 @@ var LocalDriver = class {
181
196
  }
182
197
  }
183
198
  async setVisibility(path, visibility) {
199
+ await this.warnIfMissing(path, "setVisibility");
200
+ this.warnUnsupportedVisibility(visibility, "setVisibility");
184
201
  }
185
202
  async getVisibility(path) {
203
+ await this.warnIfMissing(path, "getVisibility");
186
204
  return this.defaultVisibility;
187
205
  }
206
+ async warnIfMissing(path, operation) {
207
+ if (await this.exists(path)) {
208
+ return;
209
+ }
210
+ warnOnce(
211
+ `local-visibility-missing:${operation}`,
212
+ `[guren] LocalDriver.${operation}("${path}") was called for a file that does not exist and returned as if it had succeeded. Every other storage driver throws \`File not found\` here, and LocalDriver will too in the next major \u2014 check \`exists()\` first, or handle the error.`
213
+ );
214
+ }
215
+ warnUnsupportedVisibility(requested, operation) {
216
+ if (requested === this.defaultVisibility) {
217
+ return;
218
+ }
219
+ warnOnce(
220
+ `local-visibility-per-object:${operation}`,
221
+ `[guren] LocalDriver.${operation}() was asked to make an object ${requested} on a ${this.defaultVisibility} disk, and did nothing. A local disk has no per-object visibility \u2014 what makes a file reachable is the disk root and whatever serves it \u2014 so the request was never carried out, it only looked like it was. Declare the disk's "visibility" option to match, or keep restricted files on a disk that is not served. This becomes an error in the next major.`
222
+ );
223
+ }
188
224
  /**
189
225
  * Get the root directory.
190
226
  */
@@ -193,6 +229,22 @@ var LocalDriver = class {
193
229
  }
194
230
  };
195
231
 
232
+ // src/storage/drivers/s3-acl.ts
233
+ function cannedAcl(visibility) {
234
+ return visibility === "public" ? "public-read" : "private";
235
+ }
236
+ function putAclFields(acl, visibility) {
237
+ return acl ? { ACL: cannedAcl(visibility) } : {};
238
+ }
239
+ function assertVisibilitySupported(acl, diskVisibility, requested, operation) {
240
+ if (acl || !requested || requested === diskVisibility) {
241
+ return;
242
+ }
243
+ throw new Error(
244
+ `S3Driver.${operation}: cannot make an object ${requested} on a ${diskVisibility} disk configured with acl: false. This endpoint does not implement S3 object ACLs, so visibility is a property of the bucket. Declare it with the driver's "visibility" option, or serve restricted files through your own route.`
245
+ );
246
+ }
247
+
196
248
  // src/storage/drivers/S3Driver.ts
197
249
  var S3Driver = class {
198
250
  constructor(options) {
@@ -206,6 +258,7 @@ var S3Driver = class {
206
258
  this.prefix = options.prefix ?? "";
207
259
  this.baseUrl = options.url ?? `https://${this.bucket}.s3.${this.region}.amazonaws.com`;
208
260
  this.defaultVisibility = options.visibility ?? "private";
261
+ this.acl = options.acl ?? true;
209
262
  }
210
263
  options;
211
264
  client = null;
@@ -217,6 +270,7 @@ var S3Driver = class {
217
270
  prefix;
218
271
  baseUrl;
219
272
  defaultVisibility;
273
+ acl;
220
274
  /**
221
275
  * Get or create the S3 client.
222
276
  */
@@ -247,13 +301,8 @@ var S3Driver = class {
247
301
  prefixKey(path) {
248
302
  return this.prefix ? `${this.prefix}/${path}` : path;
249
303
  }
250
- /**
251
- * Get ACL from visibility.
252
- */
253
- getAcl(visibility) {
254
- return visibility === "public" ? "public-read" : "private";
255
- }
256
304
  async put(path, content, options) {
305
+ assertVisibilitySupported(this.acl, this.defaultVisibility, options?.visibility, "put");
257
306
  const client = await this.getClient();
258
307
  const { PutObjectCommand } = await importAwsModule("@aws-sdk/client-s3");
259
308
  const body = typeof content === "string" ? Buffer.from(content) : content;
@@ -263,7 +312,7 @@ var S3Driver = class {
263
312
  Key: this.prefixKey(path),
264
313
  Body: body,
265
314
  ContentType: options?.contentType,
266
- ACL: this.getAcl(visibility),
315
+ ...putAclFields(this.acl, visibility),
267
316
  Metadata: options?.metadata
268
317
  });
269
318
  await client.send(command);
@@ -412,6 +461,14 @@ var S3Driver = class {
412
461
  throw error;
413
462
  }
414
463
  }
464
+ /** `metadata()`, but honouring the contract's not-found error. */
465
+ async metadataOrFail(path) {
466
+ const metadata = await this.metadata(path);
467
+ if (!metadata) {
468
+ throw new Error(`File not found: ${path}`);
469
+ }
470
+ return metadata;
471
+ }
415
472
  async files(directory) {
416
473
  const client = await this.getClient();
417
474
  const { ListObjectsV2Command } = await importAwsModule("@aws-sdk/client-s3");
@@ -459,16 +516,25 @@ var S3Driver = class {
459
516
  }
460
517
  }
461
518
  async setVisibility(path, visibility) {
519
+ assertVisibilitySupported(this.acl, this.defaultVisibility, visibility, "setVisibility");
520
+ if (!this.acl) {
521
+ await this.metadataOrFail(path);
522
+ return;
523
+ }
462
524
  const client = await this.getClient();
463
525
  const { PutObjectAclCommand } = await importAwsModule("@aws-sdk/client-s3");
464
526
  const command = new PutObjectAclCommand({
465
527
  Bucket: this.bucket,
466
528
  Key: this.prefixKey(path),
467
- ACL: this.getAcl(visibility)
529
+ ACL: cannedAcl(visibility)
468
530
  });
469
531
  await client.send(command);
470
532
  }
471
533
  async getVisibility(path) {
534
+ if (!this.acl) {
535
+ await this.metadataOrFail(path);
536
+ return this.defaultVisibility;
537
+ }
472
538
  const client = await this.getClient();
473
539
  const { GetObjectAclCommand } = await importAwsModule("@aws-sdk/client-s3");
474
540
  const command = new GetObjectAclCommand({
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { parseRequestPayload, formatValidationErrors } from './http/request.js';
4
4
  export { Controller } from './mvc/Controller.js';
5
5
  export type { InertiaResponse, InferInertiaProps, ControllerInertiaProps, AuthPayload } from './mvc/Controller.js';
6
6
  export { Router } from './mvc/Router.js';
7
- export type { RouteBuilder, RouteContractOptions, RouteDefinition, RouteMiddlewareInput, RouteOpenApiMetadata, ResourceAction as RouteResourceAction, ResourceResponseHint, ResourceResponseShape, ResourceRouteOptions, } from './mvc/Router.js';
7
+ export type { BindableModel, RouteBuilder, RouteContractOptions, RouteDefinition, RouteMiddlewareInput, RouteModelBinding, RouteOpenApiMetadata, ResourceAction as RouteResourceAction, ResourceResponseHint, ResourceResponseShape, ResourceRouteOptions, } from './mvc/Router.js';
8
8
  export { ViewEngine } from './mvc/ViewEngine.js';
9
9
  export { inertia, setInertiaSsrRenderer, setInertiaDocument } from './mvc/inertia/InertiaEngine.js';
10
10
  export { setInertiaSharedProps, getInertiaSharedPropsResolver, shareInertiaProps } from './mvc/inertia/shared.js';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  logDevServerBanner,
6
6
  parseImportMap,
7
7
  startViteDevServer
8
- } from "./chunk-RGGEGXOE.js";
8
+ } from "./chunk-4BUZXYGV.js";
9
9
  import {
10
10
  PendingSchedule,
11
11
  Schedule,
@@ -26,7 +26,7 @@ import {
26
26
  S3Driver,
27
27
  StorageManager,
28
28
  createStorageManager
29
- } from "./chunk-HWEWL6TE.js";
29
+ } from "./chunk-JTNRAWQR.js";
30
30
  import {
31
31
  trimSlashes
32
32
  } from "./chunk-AZOYI43J.js";
@@ -408,6 +408,16 @@ function capabilitiesOf(handler) {
408
408
  }
409
409
 
410
410
  // src/mvc/Router.ts
411
+ function normalizeModelBinding(binding) {
412
+ if (Array.isArray(binding)) {
413
+ const [model, key] = binding;
414
+ return { model, key };
415
+ }
416
+ return { model: binding };
417
+ }
418
+ async function resolveModelBinding({ model, key }, value) {
419
+ return key === void 0 ? model.findOrFail(value) : model.findOrFail(value, key);
420
+ }
411
421
  function assertSyncGroupCallback(result, method) {
412
422
  if (typeof result?.then !== "function") return;
413
423
  throw new Error(
@@ -440,8 +450,6 @@ var Router = class {
440
450
  middlewareAliases = /* @__PURE__ */ new Map();
441
451
  middlewareGroups = /* @__PURE__ */ new Map();
442
452
  modelBindings = /* @__PURE__ */ new Map();
443
- /** Model class names for router-level bind(param, Model) calls — resolver-only binds carry no name. */
444
- modelBindingNames = /* @__PURE__ */ new Map();
445
453
  aliasMiddleware(name, handler) {
446
454
  this.middlewareAliases.set(name, handler);
447
455
  return this;
@@ -457,21 +465,30 @@ var Router = class {
457
465
  middleware(...items) {
458
466
  return new RouterMiddlewareGroupBuilder(this, items);
459
467
  }
468
+ /**
469
+ * Bind a route parameter for every route on this router whose path names
470
+ * it. A model (class or `[Model, column]`) resolves through `findOrFail`
471
+ * and reaches the controller both via `this.model(Model)` and as a
472
+ * positional argument after the context; a custom resolver's value only
473
+ * arrives positionally, in path-parameter order:
474
+ *
475
+ * ```ts
476
+ * router.bind('post', async (slug) => Post.where('slug', slug).firstOrFail())
477
+ * router.get('/posts/:post', [PostController, 'show'])
478
+ *
479
+ * async show(_ctx: Context, post: PostRecord) { ... }
480
+ * ```
481
+ */
460
482
  bind(param, modelOrResolver) {
461
- if (typeof modelOrResolver === "function" && "findOrFail" in modelOrResolver) {
462
- const model = modelOrResolver;
463
- if (model.name) this.modelBindingNames.set(param, model.name);
464
- this.modelBindings.set(param, async (value) => {
465
- return model.findOrFail(value);
466
- });
467
- } else if (typeof modelOrResolver === "function") {
468
- this.modelBindings.set(param, modelOrResolver);
469
- } else {
470
- const model = modelOrResolver;
471
- this.modelBindings.set(param, async (value) => {
472
- return model.findOrFail(value);
473
- });
483
+ if (typeof modelOrResolver === "function" && !("findOrFail" in modelOrResolver)) {
484
+ this.modelBindings.set(param, { resolve: modelOrResolver });
485
+ return this;
474
486
  }
487
+ const binding = normalizeModelBinding(modelOrResolver);
488
+ this.modelBindings.set(param, {
489
+ model: binding.model,
490
+ resolve: (value) => resolveModelBinding(binding, value)
491
+ });
475
492
  return this;
476
493
  }
477
494
  on(method, path, handlerOrOptions, ...rest) {
@@ -549,7 +566,6 @@ var Router = class {
549
566
  this.middlewareAliases.clear();
550
567
  this.middlewareGroups.clear();
551
568
  this.modelBindings.clear();
552
- this.modelBindingNames.clear();
553
569
  }
554
570
  definitions() {
555
571
  return this.registry.map(({ method, path, name, schemas, resource, openapi, routeMiddlewareNames, middlewares, scopedMiddlewares, handler, bindings }) => ({
@@ -565,7 +581,7 @@ var Router = class {
565
581
  hasInlineMiddleware: middlewares.length > 0,
566
582
  capabilities: this.aggregateCapabilities(routeMiddlewareNames, [...scopedMiddlewares, ...middlewares]),
567
583
  controller: isControllerAction(handler) ? { name: handler[0].name, action: String(handler[1]) } : void 0,
568
- bindings: serializeBindings(path, bindings, this.modelBindingNames),
584
+ bindings: serializeBindings(path, bindings, this.modelBindings),
569
585
  ...openapi
570
586
  }));
571
587
  }
@@ -685,7 +701,9 @@ function applyRouteContract(route, options) {
685
701
  deprecated: options.deprecated
686
702
  };
687
703
  if (options.bind) {
688
- route.bindings = new Map(Object.entries(options.bind));
704
+ route.bindings = new Map(
705
+ Object.entries(options.bind).map(([param, binding]) => [param, normalizeModelBinding(binding)])
706
+ );
689
707
  }
690
708
  }
691
709
  var RouterMiddlewareGroupBuilder = class {
@@ -891,13 +909,14 @@ function resolveHandler(action, modelBindings, container, routeBindings, path) {
891
909
  if (container) {
892
910
  controller.setContainer(container);
893
911
  }
912
+ const routeBoundModels = /* @__PURE__ */ new Set();
894
913
  if (routeBindings && routeBindings.size > 0) {
895
914
  const params = c.req.param();
896
- for (const [paramName, model] of routeBindings) {
915
+ for (const [paramName, binding] of routeBindings) {
897
916
  const value = params[paramName];
898
917
  if (value !== void 0) {
899
- const resolved = await model.findOrFail(value);
900
- controller.setResolvedModel(model, resolved);
918
+ controller.setResolvedModel(binding.model, await resolveModelBinding(binding, value));
919
+ routeBoundModels.add(binding.model);
901
920
  }
902
921
  }
903
922
  }
@@ -906,7 +925,11 @@ function resolveHandler(action, modelBindings, container, routeBindings, path) {
906
925
  throw new Error(`Controller method ${String(methodName)} is not defined on ${ControllerClass.name}.`);
907
926
  }
908
927
  const resolvedBindings = modelBindings.size > 0 ? await resolveModelBindings(c, modelBindings, path) : [];
909
- const args = resolvedBindings.length > 0 ? [c, ...resolvedBindings] : [c];
928
+ const args = [c];
929
+ for (const { model, value } of resolvedBindings) {
930
+ if (model && !routeBoundModels.has(model)) controller.setResolvedModel(model, value);
931
+ args.push(value);
932
+ }
910
933
  const result = await method.apply(controller, args);
911
934
  return ensureResponse(result, c);
912
935
  };
@@ -927,12 +950,11 @@ async function resolveModelBindings(c, modelBindings, path) {
927
950
  const params = c.req.param();
928
951
  const pathParams = path ? extractPathParamNames(path) : [];
929
952
  for (const param of pathParams) {
930
- const resolver = modelBindings.get(param);
931
- if (!resolver) continue;
953
+ const binding = modelBindings.get(param);
954
+ if (!binding) continue;
932
955
  const value = params[param];
933
956
  if (value !== void 0) {
934
- const model = await resolver(value);
935
- resolved.push(model);
957
+ resolved.push({ model: binding.model, value: await binding.resolve(value) });
936
958
  }
937
959
  }
938
960
  return resolved;
@@ -963,13 +985,13 @@ function buildResponse(result) {
963
985
  }
964
986
  return new Response(String(result));
965
987
  }
966
- function serializeBindings(path, routeBindings, routerBindingNames) {
988
+ function serializeBindings(path, routeBindings, routerBindings) {
967
989
  const entries = /* @__PURE__ */ new Map();
968
990
  for (const param of extractPathParamNames(path)) {
969
- const name = routerBindingNames.get(param);
991
+ const name = routerBindings.get(param)?.model?.name;
970
992
  if (name) entries.set(param, name);
971
993
  }
972
- for (const [param, model] of routeBindings ?? []) {
994
+ for (const [param, { model }] of routeBindings ?? []) {
973
995
  if (model.name) entries.set(param, model.name);
974
996
  }
975
997
  return entries.size > 0 ? Object.fromEntries(entries) : void 0;
@@ -2928,6 +2950,7 @@ var Application = class {
2928
2950
  if (!hasUserProviderOf(InertiaServiceProvider)) {
2929
2951
  this.providerManager.register(InertiaServiceProvider);
2930
2952
  }
2953
+ setContainer(this.container);
2931
2954
  }
2932
2955
  options;
2933
2956
  hono;
@@ -3365,12 +3388,16 @@ var Controller = class {
3365
3388
  this.resolvedModels.set(modelClass, instance);
3366
3389
  }
3367
3390
  /**
3368
- * Retrieve a model instance resolved via route model binding.
3391
+ * Retrieve a model instance resolved via route model binding — a per-route
3392
+ * `bind` option or a router-level `router.bind(param, Model)`. Look up by
3393
+ * primary key with the class alone, or by another column with a
3394
+ * `[Model, column]` tuple.
3369
3395
  *
3370
3396
  * @example
3371
3397
  * ```typescript
3372
3398
  * // routes/web.ts
3373
3399
  * posts.get('/:id', { bind: { id: Post }, name: 'posts.show' }, [PostController, 'show'])
3400
+ * posts.get('/by-slug/:slug', { bind: { slug: [Post, 'slug'] } }, [PostController, 'show'])
3374
3401
  *
3375
3402
  * // PostController.ts
3376
3403
  * async show() {
@@ -3383,7 +3410,7 @@ var Controller = class {
3383
3410
  const instance = this.resolvedModels?.get(modelClass);
3384
3411
  if (instance === void 0) {
3385
3412
  throw new Error(
3386
- `No model binding found for ${modelClass.name ?? "unknown"}. Ensure the route has a matching bind option in RouteContractOptions.`
3413
+ `No model binding found for ${modelClass.name ?? "unknown"}. Ensure the route has a matching bind option in RouteContractOptions, or the router a bind(param, Model) call.`
3387
3414
  );
3388
3415
  }
3389
3416
  return instance;
@@ -33,6 +33,22 @@ export type SafeValidationResult<T> = {
33
33
  success: false;
34
34
  errors: Record<string, string>;
35
35
  };
36
+ /**
37
+ * The record `Controller.model()` returns for a bound model class. ORM models
38
+ * carry their row type as a `recordType` marker (set by `defineModel()`);
39
+ * `findOrFail`'s own return type cannot be read off the class because the
40
+ * method is generic in `this`, and `ReturnType` widens it to the base row.
41
+ * Anything without a usable marker — a class extending `Model` directly
42
+ * without redeclaring it, or a plain `{ findOrFail }` adapter — falls back to
43
+ * whatever its `findOrFail` resolves to. The marker is only trusted when it
44
+ * names an object type: `Model`'s own is `unknown`, and an unrelated
45
+ * `recordType` on some adapter (a string tag, say) describes no record.
46
+ */
47
+ export type BoundModelRecord<T extends {
48
+ findOrFail(...args: any[]): Promise<any>;
49
+ }> = T extends {
50
+ readonly recordType: infer R;
51
+ } ? unknown extends R ? Awaited<ReturnType<T['findOrFail']>> : R extends object ? R : Awaited<ReturnType<T['findOrFail']>> : Awaited<ReturnType<T['findOrFail']>>;
36
52
  type DefaultInertiaProps = Record<string, unknown>;
37
53
  export type AuthPayload = Record<string, unknown> & {
38
54
  user: unknown;
@@ -106,12 +122,16 @@ export declare class Controller {
106
122
  */
107
123
  setResolvedModel(modelClass: unknown, instance: unknown): void;
108
124
  /**
109
- * Retrieve a model instance resolved via route model binding.
125
+ * Retrieve a model instance resolved via route model binding — a per-route
126
+ * `bind` option or a router-level `router.bind(param, Model)`. Look up by
127
+ * primary key with the class alone, or by another column with a
128
+ * `[Model, column]` tuple.
110
129
  *
111
130
  * @example
112
131
  * ```typescript
113
132
  * // routes/web.ts
114
133
  * posts.get('/:id', { bind: { id: Post }, name: 'posts.show' }, [PostController, 'show'])
134
+ * posts.get('/by-slug/:slug', { bind: { slug: [Post, 'slug'] } }, [PostController, 'show'])
115
135
  *
116
136
  * // PostController.ts
117
137
  * async show() {
@@ -122,7 +142,7 @@ export declare class Controller {
122
142
  */
123
143
  protected model<T extends {
124
144
  findOrFail(...args: any[]): Promise<any>;
125
- }>(modelClass: T): Awaited<ReturnType<T['findOrFail']>>;
145
+ }>(modelClass: T): BoundModelRecord<T>;
126
146
  protected get ctx(): Context;
127
147
  protected get request(): import("hono").HonoRequest<any, unknown>;
128
148
  /**
@@ -29,11 +29,19 @@ type ModelBindingResolver = (value: string) => Promise<unknown>;
29
29
  /**
30
30
  * Model class with findOrFail static method.
31
31
  */
32
- interface BindableModel {
32
+ export interface BindableModel {
33
33
  findOrFail(id: unknown, key?: string): Promise<unknown>;
34
34
  /** Bound values are model classes at runtime; the constructor name is the introspection payload. */
35
35
  readonly name?: string;
36
36
  }
37
+ /**
38
+ * A model bound to a route parameter: the model class alone looks the value
39
+ * up by primary key (`Model.findOrFail(value)`); a `[Model, column]` tuple
40
+ * looks it up by that column (`Model.findOrFail(value, column)`), e.g.
41
+ * `bind: { slug: [Post, 'slug'] }`. Either way the controller reads the
42
+ * resolved record with `this.model(Model)`.
43
+ */
44
+ export type RouteModelBinding = BindableModel | readonly [BindableModel, string];
37
45
  /**
38
46
  * A Resource class accepted as a response hint. Only the constructor name is
39
47
  * introspected — the router never instantiates it, so any class whose
@@ -94,7 +102,13 @@ export interface RouteContractOptions<TParamsSchema extends SchemaLike<unknown>
94
102
  * it is the one actually enforced.
95
103
  */
96
104
  resource?: ResourceResponseHint;
97
- bind?: Record<string, BindableModel>;
105
+ /**
106
+ * Route model bindings: param name → model (see {@link RouteModelBinding}).
107
+ * `{ id: Post }` resolves by primary key, `{ slug: [Post, 'slug'] }` by
108
+ * that column; both throw the model's not-found exception (404) on a miss
109
+ * and expose the record to the controller via `this.model(Post)`.
110
+ */
111
+ bind?: Record<string, RouteModelBinding>;
98
112
  }
99
113
  export interface RouteOpenApiMetadata {
100
114
  summary?: string;
@@ -207,8 +221,6 @@ export declare class Router<M extends string = never> {
207
221
  private readonly middlewareAliases;
208
222
  private readonly middlewareGroups;
209
223
  private readonly modelBindings;
210
- /** Model class names for router-level bind(param, Model) calls — resolver-only binds carry no name. */
211
- private readonly modelBindingNames;
212
224
  aliasMiddleware<N extends string>(name: N, handler: MiddlewareHandler): Router<M | N>;
213
225
  groupMiddleware<N extends string>(name: N, middlewareNames: M[]): Router<M | N>;
214
226
  /**
@@ -216,7 +228,21 @@ export declare class Router<M extends string = never> {
216
228
  * builder. See {@link RouteMiddlewareInput}.
217
229
  */
218
230
  middleware(...items: RouteMiddlewareInput<M>[]): RouterMiddlewareGroupBuilder<M>;
219
- bind(param: string, modelOrResolver: BindableModel | ModelBindingResolver): this;
231
+ /**
232
+ * Bind a route parameter for every route on this router whose path names
233
+ * it. A model (class or `[Model, column]`) resolves through `findOrFail`
234
+ * and reaches the controller both via `this.model(Model)` and as a
235
+ * positional argument after the context; a custom resolver's value only
236
+ * arrives positionally, in path-parameter order:
237
+ *
238
+ * ```ts
239
+ * router.bind('post', async (slug) => Post.where('slug', slug).firstOrFail())
240
+ * router.get('/posts/:post', [PostController, 'show'])
241
+ *
242
+ * async show(_ctx: Context, post: PostRecord) { ... }
243
+ * ```
244
+ */
245
+ bind(param: string, modelOrResolver: RouteModelBinding | ModelBindingResolver): this;
220
246
  on<C extends ControllerConstructor>(method: string, path: string, handler: RouteHandler<C>, ...middlewares: MiddlewareHandler[]): RouteBuilder<M>;
221
247
  on<TParamsSchema extends SchemaLike<unknown>, TQuerySchema extends SchemaLike<unknown>, TBodySchema extends SchemaLike<unknown>, TOutputSchema extends SchemaLike<unknown>>(method: string, path: string, options: RouteContractOptions<TParamsSchema, TQuerySchema, TBodySchema, TOutputSchema>, handler: TypedRouteHandler<TParamsSchema, TQuerySchema, TBodySchema, TOutputSchema>): RouteBuilder<M>;
222
248
  on<C extends ControllerConstructor, TParamsSchema extends SchemaLike<unknown>, TQuerySchema extends SchemaLike<unknown>, TBodySchema extends SchemaLike<unknown>, TOutputSchema extends SchemaLike<unknown>>(method: string, path: string, options: RouteContractOptions<TParamsSchema, TQuerySchema, TBodySchema, TOutputSchema>, handler: ControllerAction<C>): RouteBuilder<M>;
@@ -4,7 +4,7 @@ import {
4
4
  logDevServerBanner,
5
5
  parseImportMap,
6
6
  startViteDevServer
7
- } from "../chunk-RGGEGXOE.js";
7
+ } from "../chunk-4BUZXYGV.js";
8
8
  import {
9
9
  trimTrailingSlashes
10
10
  } from "../chunk-AZOYI43J.js";
@@ -48,6 +48,8 @@ export declare class LocalDriver implements StorageDriver {
48
48
  deleteDirectory(path: string): Promise<void>;
49
49
  setVisibility(path: string, visibility: 'public' | 'private'): Promise<void>;
50
50
  getVisibility(path: string): Promise<'public' | 'private'>;
51
+ private warnIfMissing;
52
+ private warnUnsupportedVisibility;
51
53
  /**
52
54
  * Get the root directory.
53
55
  */
@@ -27,6 +27,7 @@ export declare class S3Driver implements StorageDriver {
27
27
  private readonly prefix;
28
28
  private readonly baseUrl;
29
29
  private readonly defaultVisibility;
30
+ private readonly acl;
30
31
  constructor(options: S3DriverOptions);
31
32
  /**
32
33
  * Get or create the S3 client.
@@ -36,10 +37,6 @@ export declare class S3Driver implements StorageDriver {
36
37
  * Get the prefixed key.
37
38
  */
38
39
  private prefixKey;
39
- /**
40
- * Get ACL from visibility.
41
- */
42
- private getAcl;
43
40
  put(path: string, content: Buffer | string, options?: PutOptions): Promise<string>;
44
41
  putFile(path: string, localPath: string, options?: PutOptions): Promise<string>;
45
42
  get(path: string): Promise<Buffer | null>;
@@ -54,6 +51,8 @@ export declare class S3Driver implements StorageDriver {
54
51
  size(path: string): Promise<number>;
55
52
  lastModified(path: string): Promise<Date>;
56
53
  metadata(path: string): Promise<FileMetadata | null>;
54
+ /** `metadata()`, but honouring the contract's not-found error. */
55
+ private metadataOrFail;
57
56
  files(directory: string): Promise<string[]>;
58
57
  directories(directory: string): Promise<string[]>;
59
58
  allFiles(directory: string): Promise<string[]>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The ACL half of the S3 driver, kept out of the driver so it can be tested
3
+ * without the optional `@aws-sdk/client-s3` peer installed: these functions
4
+ * decide what goes into a command, which is exactly the part that was wrong
5
+ * for every S3-compatible endpoint without ACL support.
6
+ */
7
+ export type Visibility = 'public' | 'private';
8
+ /** The canned ACL S3 uses for each visibility. */
9
+ export declare function cannedAcl(visibility: Visibility): string;
10
+ /**
11
+ * The `ACL` field for a `PutObject` input, or nothing when the endpoint has
12
+ * no ACLs. Returned as a spreadable object so the caller never sends an
13
+ * explicit `ACL: undefined`, which some S3 implementations reject outright
14
+ * rather than treat as absent.
15
+ */
16
+ export declare function putAclFields(acl: boolean, visibility: Visibility): {
17
+ ACL?: string;
18
+ };
19
+ /**
20
+ * Guard for a per-object visibility an ACL-less endpoint cannot honour.
21
+ * Throws rather than silently dropping the request: a `setVisibility(path,
22
+ * 'private')` that does nothing on a public bucket is a leak that looks like
23
+ * success.
24
+ */
25
+ export declare function assertVisibilitySupported(acl: boolean, diskVisibility: Visibility, requested: Visibility | undefined, operation: string): void;
@@ -4,7 +4,7 @@ import {
4
4
  S3Driver,
5
5
  StorageManager,
6
6
  createStorageManager
7
- } from "../chunk-HWEWL6TE.js";
7
+ } from "../chunk-JTNRAWQR.js";
8
8
  import "../chunk-AZOYI43J.js";
9
9
  export {
10
10
  LocalDriver,
@@ -160,12 +160,29 @@ export interface StorageDriver {
160
160
  deleteDirectory(path: string): Promise<void>;
161
161
  /**
162
162
  * Set file visibility.
163
+ *
164
+ * Contract: throws when the file does not exist, so a caller cannot take
165
+ * success as proof the object is there. A driver whose backend has no
166
+ * per-object visibility (bucket-level access, a plain filesystem) reports
167
+ * the disk's configured visibility and throws when asked for the other
168
+ * value, rather than accepting a request it cannot honour — silently
169
+ * doing nothing is a leak that looks like success.
170
+ *
171
+ * `LocalDriver` is such a backend: what makes a local file reachable is
172
+ * the disk root and whatever serves it, not a flag on one file. It has
173
+ * always accepted per-object requests and done nothing, so it warns
174
+ * instead of throwing and will throw in the next major.
175
+ *
163
176
  * @param path File path
164
177
  * @param visibility Visibility setting
165
178
  */
166
179
  setVisibility(path: string, visibility: 'public' | 'private'): Promise<void>;
167
180
  /**
168
181
  * Get file visibility.
182
+ *
183
+ * Contract: throws when the file does not exist. Drivers without
184
+ * per-object visibility report the disk's configured value.
185
+ *
169
186
  * @param path File path
170
187
  */
171
188
  getVisibility(path: string): Promise<'public' | 'private'>;
@@ -233,6 +250,24 @@ export interface S3DriverOptions {
233
250
  * @default 'private'
234
251
  */
235
252
  visibility?: 'public' | 'private';
253
+ /**
254
+ * Whether the endpoint implements S3 object ACLs.
255
+ *
256
+ * AWS S3 does, so this defaults to `true` and every `put` carries an
257
+ * `x-amz-acl` header derived from the file's visibility. Several
258
+ * S3-compatible endpoints do not: Cloudflare R2 documents `x-amz-acl` and
259
+ * the ACL operations as unsupported (access is decided per bucket), and
260
+ * MinIO/others vary. Set `acl: false` for those.
261
+ *
262
+ * With `acl: false` the driver stops sending the header, and visibility
263
+ * becomes a property of the whole disk: `getVisibility()` reports the
264
+ * configured `visibility`, and `put({ visibility })` / `setVisibility()`
265
+ * throw when asked for the other value rather than silently not applying
266
+ * it. Enforce per-object access in front of the disk instead.
267
+ *
268
+ * @default true
269
+ */
270
+ acl?: boolean;
236
271
  }
237
272
  /**
238
273
  * Memory driver options.
@@ -3,8 +3,9 @@
3
3
  * quadratically on adversarial input (long slash runs mid-string), and
4
4
  * several call sites here feed request-derived paths.
5
5
  *
6
- * A twin of `trimSlashes` lives in `@guren/cli` (`src/utils.ts`); the
7
- * packages share no dependency edge, so the six lines are duplicated by
6
+ * Twins live in `@guren/cli` (`src/utils.ts`, `trimSlashes`) and
7
+ * `@guren/plugin-cloudflare` (`src/storage/R2Driver.ts`, both functions);
8
+ * neither package can import this module, so the lines are duplicated by
8
9
  * convention.
9
10
  */
10
11
  export declare function trimTrailingSlashes(value: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Emit a warning the first time a given key is seen in this process.
3
+ *
4
+ * Deprecation warnings have to be loud enough to be read once and quiet
5
+ * enough not to drown a request log, which is the same shape the OAuth
6
+ * warnings settled on (`auth/oauth/index.ts`) — this is that pattern with a
7
+ * key, so several call sites can share it.
8
+ */
9
+ export declare function warnOnce(key: string, message: string): void;
10
+ /** Test seam: forget what has already been warned about. */
11
+ export declare function resetWarnOnce(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -113,7 +113,7 @@
113
113
  "test": "bun test"
114
114
  },
115
115
  "dependencies": {
116
- "@guren/orm": "^2.4.0",
116
+ "@guren/orm": "^2.5.0",
117
117
  "@modelcontextprotocol/sdk": "^1.30.0",
118
118
  "chalk": "^5.3.0",
119
119
  "consola": "^3.4.2",