@guren/server 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-AOPXIURJ.js → chunk-O5XIXGYM.js} +2 -2
- package/dist/{chunk-JTNRAWQR.js → chunk-SQR7277M.js} +1 -0
- package/dist/database/Seeder.d.ts +38 -0
- package/dist/database/SeederRunner.d.ts +17 -0
- package/dist/database/types.d.ts +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -42
- package/dist/mvc/Controller.d.ts +22 -2
- package/dist/mvc/Router.d.ts +31 -5
- package/dist/runtime/index.js +1 -1
- package/dist/storage/index.js +1 -1
- package/package.json +2 -2
|
@@ -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.
|
|
9
|
+
version: "2.9.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.
|
|
122
|
+
"@guren/orm": "^2.6.0",
|
|
123
123
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
124
124
|
chalk: "^5.3.0",
|
|
125
125
|
consola: "^3.4.2",
|
|
@@ -1,18 +1,53 @@
|
|
|
1
1
|
import type { SeederClass } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Reset called seeders tracking (for testing).
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Bookkeeping for {@link BaseSeeder}'s `callOnce`. Write seeders
|
|
6
|
+
* with `defineSeeder` from `@guren/core` instead, which needs no such
|
|
7
|
+
* tracking. Deprecated in 2.9.0, removed in 3.0.0.
|
|
4
8
|
*/
|
|
5
9
|
export declare function resetCalledSeeders(): void;
|
|
6
10
|
/**
|
|
7
11
|
* Abstract base class for database seeders.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Write seeders with `defineSeeder` from `@guren/core` instead.
|
|
14
|
+
* Deprecated in 2.9.0, removed in 3.0.0.
|
|
15
|
+
*
|
|
16
|
+
* A seeder class is not itself the problem: `db:seed` loads every seeder
|
|
17
|
+
* through `runSeeders()`, which does accept an exported class whose prototype
|
|
18
|
+
* has a `run` method, constructs it, and calls `run({ db })`. What this base
|
|
19
|
+
* class gets wrong is the signature it imposes on that method. `run()` is
|
|
20
|
+
* declared to take no parameters, so it hides the one argument a seeder
|
|
21
|
+
* needs.
|
|
22
|
+
*
|
|
23
|
+
* A subclass cannot simply correct that: declaring `run(ctx: SeederContext)`
|
|
24
|
+
* fails to compile against the base (`TS2416: Target signature provides too
|
|
25
|
+
* few arguments. Expected 1 or more, but got 0`). Widening it to an optional
|
|
26
|
+
* `run(ctx?: SeederContext)` does compile, but then the subclass has to handle
|
|
27
|
+
* a missing context — and that case is real, because
|
|
28
|
+
* {@link BaseSeeder.call}, {@link BaseSeeder.callOnce},
|
|
29
|
+
* {@link BaseSeeder.callMany} and {@link BaseSeeder.callParallel} construct
|
|
30
|
+
* child seeders and invoke `run()` with no arguments at all. A parent that
|
|
31
|
+
* received a context cannot pass it down.
|
|
32
|
+
*
|
|
33
|
+
* The orchestration these classes were written for, `SeederRunner`, is
|
|
34
|
+
* reached by no Guren command.
|
|
8
35
|
*/
|
|
9
36
|
export declare abstract class BaseSeeder {
|
|
37
|
+
constructor();
|
|
10
38
|
/**
|
|
11
39
|
* Run the seeder.
|
|
40
|
+
*
|
|
41
|
+
* Declared without parameters, which is what makes this class the wrong
|
|
42
|
+
* base: `runSeeders()` calls it with a `{ db }` context that this signature
|
|
43
|
+
* cannot name.
|
|
12
44
|
*/
|
|
13
45
|
abstract run(): Promise<void>;
|
|
14
46
|
/**
|
|
15
47
|
* Call another seeder.
|
|
48
|
+
*
|
|
49
|
+
* No context is forwarded: the child's `run()` is invoked with no
|
|
50
|
+
* arguments, whatever the caller itself received.
|
|
16
51
|
*/
|
|
17
52
|
protected call(SeederClass: SeederClass): Promise<void>;
|
|
18
53
|
/**
|
|
@@ -31,5 +66,8 @@ export declare abstract class BaseSeeder {
|
|
|
31
66
|
}
|
|
32
67
|
/**
|
|
33
68
|
* Alias for BaseSeeder.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated Write seeders with `defineSeeder` from `@guren/core` instead.
|
|
71
|
+
* Deprecated in 2.9.0, removed in 3.0.0. See {@link BaseSeeder}.
|
|
34
72
|
*/
|
|
35
73
|
export { BaseSeeder as Seeder };
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { SeederClass, SeederRunnerOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Seeder runner for executing database seeders.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated No Guren command reaches this runner. Write seeders with
|
|
6
|
+
* `defineSeeder` from `@guren/core` and run them with `db:seed`. Deprecated
|
|
7
|
+
* in 2.9.0, removed in 3.0.0.
|
|
8
|
+
*
|
|
9
|
+
* `db:seed` seeds by loading the seeders folder through `runSeeders()`, which
|
|
10
|
+
* runs every seeder it finds there and hands each one a `{ db }` context. This
|
|
11
|
+
* runner orchestrates differently: it runs a single seeder per call, taken
|
|
12
|
+
* from a class passed in, a name registered with {@link SeederRunner.register},
|
|
13
|
+
* or a name resolved to `<seedersPath>/<Name>.ts` and defaulting to
|
|
14
|
+
* `DatabaseSeeder`; it constructs it with `new` and invokes `.run()` with no
|
|
15
|
+
* context. Nothing in the framework calls any of it. See {@link BaseSeeder}
|
|
16
|
+
* for what the no-context `run()` costs a seeder written against it.
|
|
4
17
|
*/
|
|
5
18
|
export declare class SeederRunner {
|
|
6
19
|
private options;
|
|
@@ -37,5 +50,9 @@ export declare class SeederRunner {
|
|
|
37
50
|
}
|
|
38
51
|
/**
|
|
39
52
|
* Create a seeder runner.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated No Guren command reaches this runner. Write seeders with
|
|
55
|
+
* `defineSeeder` from `@guren/core` instead. Deprecated in 2.9.0, removed in
|
|
56
|
+
* 3.0.0. See {@link SeederRunner}.
|
|
40
57
|
*/
|
|
41
58
|
export declare function createSeederRunner(options?: SeederRunnerOptions): SeederRunner;
|
package/dist/database/types.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Seeder class interface.
|
|
3
|
+
*
|
|
4
|
+
* @deprecated The constructor shape `BaseSeeder` and `SeederRunner` expect.
|
|
5
|
+
* Write seeders with `defineSeeder` from `@guren/core` instead. Deprecated in
|
|
6
|
+
* 2.9.0, removed in 3.0.0.
|
|
3
7
|
*/
|
|
4
8
|
export interface SeederClass {
|
|
5
9
|
new (): Seeder;
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
8
12
|
* Abstract seeder interface.
|
|
13
|
+
*
|
|
14
|
+
* Exported from the package root as `SeederInterface`.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated The no-context `run()` shape `BaseSeeder` imposes. Write seeders
|
|
17
|
+
* with `defineSeeder` from `@guren/core` instead, whose handler is typed to
|
|
18
|
+
* receive `{ db }`. Deprecated in 2.9.0, removed in 3.0.0.
|
|
9
19
|
*/
|
|
10
20
|
export interface Seeder {
|
|
11
21
|
run(): Promise<void>;
|
|
@@ -28,6 +38,10 @@ export interface Factory<T> {
|
|
|
28
38
|
}
|
|
29
39
|
/**
|
|
30
40
|
* Seeder runner options.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Options for `SeederRunner`, which no Guren command reaches.
|
|
43
|
+
* Write seeders with `defineSeeder` from `@guren/core` and run them with
|
|
44
|
+
* `db:seed`. Deprecated in 2.9.0, removed in 3.0.0.
|
|
31
45
|
*/
|
|
32
46
|
export interface SeederRunnerOptions {
|
|
33
47
|
/**
|
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,17 +5,7 @@ import {
|
|
|
5
5
|
logDevServerBanner,
|
|
6
6
|
parseImportMap,
|
|
7
7
|
startViteDevServer
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import {
|
|
10
|
-
LocalDriver,
|
|
11
|
-
MemoryDriver as MemoryDriver3,
|
|
12
|
-
S3Driver,
|
|
13
|
-
StorageManager,
|
|
14
|
-
createStorageManager
|
|
15
|
-
} from "./chunk-JTNRAWQR.js";
|
|
16
|
-
import {
|
|
17
|
-
trimSlashes
|
|
18
|
-
} from "./chunk-AZOYI43J.js";
|
|
8
|
+
} from "./chunk-O5XIXGYM.js";
|
|
19
9
|
import {
|
|
20
10
|
PendingSchedule,
|
|
21
11
|
Schedule,
|
|
@@ -30,6 +20,17 @@ import {
|
|
|
30
20
|
parseCron,
|
|
31
21
|
toTimezone
|
|
32
22
|
} from "./chunk-EI5GYMAT.js";
|
|
23
|
+
import {
|
|
24
|
+
LocalDriver,
|
|
25
|
+
MemoryDriver as MemoryDriver3,
|
|
26
|
+
S3Driver,
|
|
27
|
+
StorageManager,
|
|
28
|
+
createStorageManager,
|
|
29
|
+
warnOnce
|
|
30
|
+
} from "./chunk-SQR7277M.js";
|
|
31
|
+
import {
|
|
32
|
+
trimSlashes
|
|
33
|
+
} from "./chunk-AZOYI43J.js";
|
|
33
34
|
import {
|
|
34
35
|
isDocsViewerEnabled
|
|
35
36
|
} from "./chunk-A5JJ7XTH.js";
|
|
@@ -408,6 +409,16 @@ function capabilitiesOf(handler) {
|
|
|
408
409
|
}
|
|
409
410
|
|
|
410
411
|
// src/mvc/Router.ts
|
|
412
|
+
function normalizeModelBinding(binding) {
|
|
413
|
+
if (Array.isArray(binding)) {
|
|
414
|
+
const [model, key] = binding;
|
|
415
|
+
return { model, key };
|
|
416
|
+
}
|
|
417
|
+
return { model: binding };
|
|
418
|
+
}
|
|
419
|
+
async function resolveModelBinding({ model, key }, value) {
|
|
420
|
+
return key === void 0 ? model.findOrFail(value) : model.findOrFail(value, key);
|
|
421
|
+
}
|
|
411
422
|
function assertSyncGroupCallback(result, method) {
|
|
412
423
|
if (typeof result?.then !== "function") return;
|
|
413
424
|
throw new Error(
|
|
@@ -440,8 +451,6 @@ var Router = class {
|
|
|
440
451
|
middlewareAliases = /* @__PURE__ */ new Map();
|
|
441
452
|
middlewareGroups = /* @__PURE__ */ new Map();
|
|
442
453
|
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
454
|
aliasMiddleware(name, handler) {
|
|
446
455
|
this.middlewareAliases.set(name, handler);
|
|
447
456
|
return this;
|
|
@@ -457,21 +466,30 @@ var Router = class {
|
|
|
457
466
|
middleware(...items) {
|
|
458
467
|
return new RouterMiddlewareGroupBuilder(this, items);
|
|
459
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* Bind a route parameter for every route on this router whose path names
|
|
471
|
+
* it. A model (class or `[Model, column]`) resolves through `findOrFail`
|
|
472
|
+
* and reaches the controller both via `this.model(Model)` and as a
|
|
473
|
+
* positional argument after the context; a custom resolver's value only
|
|
474
|
+
* arrives positionally, in path-parameter order:
|
|
475
|
+
*
|
|
476
|
+
* ```ts
|
|
477
|
+
* router.bind('post', async (slug) => Post.where('slug', slug).firstOrFail())
|
|
478
|
+
* router.get('/posts/:post', [PostController, 'show'])
|
|
479
|
+
*
|
|
480
|
+
* async show(_ctx: Context, post: PostRecord) { ... }
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
460
483
|
bind(param, modelOrResolver) {
|
|
461
|
-
if (typeof modelOrResolver === "function" && "findOrFail" in modelOrResolver) {
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
});
|
|
484
|
+
if (typeof modelOrResolver === "function" && !("findOrFail" in modelOrResolver)) {
|
|
485
|
+
this.modelBindings.set(param, { resolve: modelOrResolver });
|
|
486
|
+
return this;
|
|
474
487
|
}
|
|
488
|
+
const binding = normalizeModelBinding(modelOrResolver);
|
|
489
|
+
this.modelBindings.set(param, {
|
|
490
|
+
model: binding.model,
|
|
491
|
+
resolve: (value) => resolveModelBinding(binding, value)
|
|
492
|
+
});
|
|
475
493
|
return this;
|
|
476
494
|
}
|
|
477
495
|
on(method, path, handlerOrOptions, ...rest) {
|
|
@@ -549,7 +567,6 @@ var Router = class {
|
|
|
549
567
|
this.middlewareAliases.clear();
|
|
550
568
|
this.middlewareGroups.clear();
|
|
551
569
|
this.modelBindings.clear();
|
|
552
|
-
this.modelBindingNames.clear();
|
|
553
570
|
}
|
|
554
571
|
definitions() {
|
|
555
572
|
return this.registry.map(({ method, path, name, schemas, resource, openapi, routeMiddlewareNames, middlewares, scopedMiddlewares, handler, bindings }) => ({
|
|
@@ -565,7 +582,7 @@ var Router = class {
|
|
|
565
582
|
hasInlineMiddleware: middlewares.length > 0,
|
|
566
583
|
capabilities: this.aggregateCapabilities(routeMiddlewareNames, [...scopedMiddlewares, ...middlewares]),
|
|
567
584
|
controller: isControllerAction(handler) ? { name: handler[0].name, action: String(handler[1]) } : void 0,
|
|
568
|
-
bindings: serializeBindings(path, bindings, this.
|
|
585
|
+
bindings: serializeBindings(path, bindings, this.modelBindings),
|
|
569
586
|
...openapi
|
|
570
587
|
}));
|
|
571
588
|
}
|
|
@@ -685,7 +702,9 @@ function applyRouteContract(route, options) {
|
|
|
685
702
|
deprecated: options.deprecated
|
|
686
703
|
};
|
|
687
704
|
if (options.bind) {
|
|
688
|
-
route.bindings = new Map(
|
|
705
|
+
route.bindings = new Map(
|
|
706
|
+
Object.entries(options.bind).map(([param, binding]) => [param, normalizeModelBinding(binding)])
|
|
707
|
+
);
|
|
689
708
|
}
|
|
690
709
|
}
|
|
691
710
|
var RouterMiddlewareGroupBuilder = class {
|
|
@@ -891,13 +910,14 @@ function resolveHandler(action, modelBindings, container, routeBindings, path) {
|
|
|
891
910
|
if (container) {
|
|
892
911
|
controller.setContainer(container);
|
|
893
912
|
}
|
|
913
|
+
const routeBoundModels = /* @__PURE__ */ new Set();
|
|
894
914
|
if (routeBindings && routeBindings.size > 0) {
|
|
895
915
|
const params = c.req.param();
|
|
896
|
-
for (const [paramName,
|
|
916
|
+
for (const [paramName, binding] of routeBindings) {
|
|
897
917
|
const value = params[paramName];
|
|
898
918
|
if (value !== void 0) {
|
|
899
|
-
|
|
900
|
-
|
|
919
|
+
controller.setResolvedModel(binding.model, await resolveModelBinding(binding, value));
|
|
920
|
+
routeBoundModels.add(binding.model);
|
|
901
921
|
}
|
|
902
922
|
}
|
|
903
923
|
}
|
|
@@ -906,7 +926,11 @@ function resolveHandler(action, modelBindings, container, routeBindings, path) {
|
|
|
906
926
|
throw new Error(`Controller method ${String(methodName)} is not defined on ${ControllerClass.name}.`);
|
|
907
927
|
}
|
|
908
928
|
const resolvedBindings = modelBindings.size > 0 ? await resolveModelBindings(c, modelBindings, path) : [];
|
|
909
|
-
const args =
|
|
929
|
+
const args = [c];
|
|
930
|
+
for (const { model, value } of resolvedBindings) {
|
|
931
|
+
if (model && !routeBoundModels.has(model)) controller.setResolvedModel(model, value);
|
|
932
|
+
args.push(value);
|
|
933
|
+
}
|
|
910
934
|
const result = await method.apply(controller, args);
|
|
911
935
|
return ensureResponse(result, c);
|
|
912
936
|
};
|
|
@@ -927,12 +951,11 @@ async function resolveModelBindings(c, modelBindings, path) {
|
|
|
927
951
|
const params = c.req.param();
|
|
928
952
|
const pathParams = path ? extractPathParamNames(path) : [];
|
|
929
953
|
for (const param of pathParams) {
|
|
930
|
-
const
|
|
931
|
-
if (!
|
|
954
|
+
const binding = modelBindings.get(param);
|
|
955
|
+
if (!binding) continue;
|
|
932
956
|
const value = params[param];
|
|
933
957
|
if (value !== void 0) {
|
|
934
|
-
|
|
935
|
-
resolved.push(model);
|
|
958
|
+
resolved.push({ model: binding.model, value: await binding.resolve(value) });
|
|
936
959
|
}
|
|
937
960
|
}
|
|
938
961
|
return resolved;
|
|
@@ -963,13 +986,13 @@ function buildResponse(result) {
|
|
|
963
986
|
}
|
|
964
987
|
return new Response(String(result));
|
|
965
988
|
}
|
|
966
|
-
function serializeBindings(path, routeBindings,
|
|
989
|
+
function serializeBindings(path, routeBindings, routerBindings) {
|
|
967
990
|
const entries = /* @__PURE__ */ new Map();
|
|
968
991
|
for (const param of extractPathParamNames(path)) {
|
|
969
|
-
const name =
|
|
992
|
+
const name = routerBindings.get(param)?.model?.name;
|
|
970
993
|
if (name) entries.set(param, name);
|
|
971
994
|
}
|
|
972
|
-
for (const [param, model] of routeBindings ?? []) {
|
|
995
|
+
for (const [param, { model }] of routeBindings ?? []) {
|
|
973
996
|
if (model.name) entries.set(param, model.name);
|
|
974
997
|
}
|
|
975
998
|
return entries.size > 0 ? Object.fromEntries(entries) : void 0;
|
|
@@ -2928,6 +2951,7 @@ var Application = class {
|
|
|
2928
2951
|
if (!hasUserProviderOf(InertiaServiceProvider)) {
|
|
2929
2952
|
this.providerManager.register(InertiaServiceProvider);
|
|
2930
2953
|
}
|
|
2954
|
+
setContainer(this.container);
|
|
2931
2955
|
}
|
|
2932
2956
|
options;
|
|
2933
2957
|
hono;
|
|
@@ -3365,12 +3389,16 @@ var Controller = class {
|
|
|
3365
3389
|
this.resolvedModels.set(modelClass, instance);
|
|
3366
3390
|
}
|
|
3367
3391
|
/**
|
|
3368
|
-
* Retrieve a model instance resolved via route model binding
|
|
3392
|
+
* Retrieve a model instance resolved via route model binding — a per-route
|
|
3393
|
+
* `bind` option or a router-level `router.bind(param, Model)`. Look up by
|
|
3394
|
+
* primary key with the class alone, or by another column with a
|
|
3395
|
+
* `[Model, column]` tuple.
|
|
3369
3396
|
*
|
|
3370
3397
|
* @example
|
|
3371
3398
|
* ```typescript
|
|
3372
3399
|
* // routes/web.ts
|
|
3373
3400
|
* posts.get('/:id', { bind: { id: Post }, name: 'posts.show' }, [PostController, 'show'])
|
|
3401
|
+
* posts.get('/by-slug/:slug', { bind: { slug: [Post, 'slug'] } }, [PostController, 'show'])
|
|
3374
3402
|
*
|
|
3375
3403
|
* // PostController.ts
|
|
3376
3404
|
* async show() {
|
|
@@ -3383,7 +3411,7 @@ var Controller = class {
|
|
|
3383
3411
|
const instance = this.resolvedModels?.get(modelClass);
|
|
3384
3412
|
if (instance === void 0) {
|
|
3385
3413
|
throw new Error(
|
|
3386
|
-
`No model binding found for ${modelClass.name ?? "unknown"}. Ensure the route has a matching bind option in RouteContractOptions.`
|
|
3414
|
+
`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
3415
|
);
|
|
3388
3416
|
}
|
|
3389
3417
|
return instance;
|
|
@@ -4769,8 +4797,17 @@ function resetCalledSeeders() {
|
|
|
4769
4797
|
calledSeeders.clear();
|
|
4770
4798
|
}
|
|
4771
4799
|
var BaseSeeder = class {
|
|
4800
|
+
constructor() {
|
|
4801
|
+
warnOnce(
|
|
4802
|
+
"seeder-class-convention:base-seeder",
|
|
4803
|
+
"[guren] Deprecation (seeder-class-convention): BaseSeeder/Seeder is deprecated\n since 2.9.0, will be removed in 3.0.0.\n Write seeders with defineSeeder from '@guren/core': its handler receives { db }, which BaseSeeder.run() is declared not to take."
|
|
4804
|
+
);
|
|
4805
|
+
}
|
|
4772
4806
|
/**
|
|
4773
4807
|
* Call another seeder.
|
|
4808
|
+
*
|
|
4809
|
+
* No context is forwarded: the child's `run()` is invoked with no
|
|
4810
|
+
* arguments, whatever the caller itself received.
|
|
4774
4811
|
*/
|
|
4775
4812
|
async call(SeederClass) {
|
|
4776
4813
|
const seeder = new SeederClass();
|
|
@@ -4962,6 +4999,10 @@ var SeederRunner = class {
|
|
|
4962
4999
|
options;
|
|
4963
5000
|
seeders = /* @__PURE__ */ new Map();
|
|
4964
5001
|
constructor(options = {}) {
|
|
5002
|
+
warnOnce(
|
|
5003
|
+
"seeder-class-convention:seeder-runner",
|
|
5004
|
+
"[guren] Deprecation (seeder-class-convention): SeederRunner is deprecated\n since 2.9.0, will be removed in 3.0.0.\n No Guren command runs it. Write seeders with defineSeeder from '@guren/core' and run them with `guren db:seed`."
|
|
5005
|
+
);
|
|
4965
5006
|
this.options = {
|
|
4966
5007
|
seedersPath: options.seedersPath ?? "db/seeders",
|
|
4967
5008
|
defaultSeeder: options.defaultSeeder ?? "DatabaseSeeder",
|
package/dist/mvc/Controller.d.ts
CHANGED
|
@@ -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):
|
|
145
|
+
}>(modelClass: T): BoundModelRecord<T>;
|
|
126
146
|
protected get ctx(): Context;
|
|
127
147
|
protected get request(): import("hono").HonoRequest<any, unknown>;
|
|
128
148
|
/**
|
package/dist/mvc/Router.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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>;
|
package/dist/runtime/index.js
CHANGED
package/dist/storage/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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.
|
|
116
|
+
"@guren/orm": "^2.6.0",
|
|
117
117
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
118
118
|
"chalk": "^5.3.0",
|
|
119
119
|
"consola": "^3.4.2",
|