@web-ts-toolkit/access-router 0.50.0 → 0.52.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/README.md +1582 -117
- package/advanced.d.mts +1 -1
- package/advanced.d.ts +1 -1
- package/advanced.js +693 -302
- package/advanced.mjs +641 -250
- package/index.d.mts +85 -2
- package/index.d.ts +85 -2
- package/index.js +10873 -7616
- package/index.mjs +10887 -7632
- package/llms.txt +36 -314
- package/package.json +3 -3
- package/{parsers-DhUuvj9B.d.mts → parsers-BnmChTfF.d.mts} +2621 -1934
- package/{parsers-DhUuvj9B.d.ts → parsers-BnmChTfF.d.ts} +2621 -1934
package/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Schema } from 'mongoose';
|
|
2
2
|
import { Response, NextFunction, RequestHandler, Router } from 'express';
|
|
3
|
-
import { A as AccessRouterBaseRequest,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AccessRouterBaseRequest, aq as GuardHook, aR as ModelRequest, dN as AccessRuntime, _ as DataRouterOptions, Y as DataRequest, dO as DataService, aa as ExtendedDataRouterOptions, af as Filter, bk as Projection, cr as Sort, bg as Populate, aS as ModelRouterOptions, dP as Service, dQ as PublicService, a$ as ModelVirtualRecordAccess, aX as ModelVirtualDescriptor, aZ as ModelVirtualGetter, a_ as ModelVirtualLeaf, ac as ExtendedModelRouterOptions, dn as Validation, cb as RootRouterOptions, dR as OpenApiRouterOptions, dS as OpenApiRegistryOptions, dT as OpenApiRouteDescriptor, dU as OpenApiDocumentOptions, dV as OpenApiParameter, dW as OpenApiSchema, dX as OpenApiResponses, ao as GlobalOptions, a2 as DefaultModelRouterOptions, ab as ExtendedDefaultModelRouterOptions } from './parsers-BnmChTfF.mjs';
|
|
4
|
+
export { dY as AccessRouterPermissionMap, dZ as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, n as AjvValidatorLike, o as AllowedOutputFieldOptions, p as ArkTypeErrorsLike, q as ArkTypeLike, s as AuthorizedListResult, t as AuthorizedSingleResult, H as CreateAuthorization, N as DataFieldOptions, a7 as DocumentAuthorization, ad as FieldAuthorization, ae as FieldOperationAccess, ap as GlobalPermissionValue, at as InputFieldAuthorization, au as InputFieldPath, av as IoTsContextEntryLike, aw as IoTsDecodeErrorLike, ax as IoTsDecoderLike, ay as JoiSchemaLike, az as JoiValidationErrorDetailLike, aF as MaybePromise, aG as ModelBaseFilterHook, aI as ModelDeleteHook, aJ as ModelDocPermissionsHook, aL as ModelDocumentHook, aM as ModelHook, aO as ModelIdentifierHook, aP as ModelListHook, aQ as ModelOverrideFilterHook, aT as ModelValidateHook, aU as ModelVirtualAccess, aV as ModelVirtualAccessRecord, aW as ModelVirtualContext, aY as ModelVirtualDoc, b0 as ModelVirtuals, b1 as MutationAuthorization, b2 as NewArgs, b3 as NewOptions, d_ as OpenApiMethod, b4 as OperationAccess, b5 as OperationAuthorization, b6 as OutputAuthorization, b7 as OutputFieldOptions, b8 as OutputFieldPath, b9 as OutputPlanningOptions, bc as PairedRouteAccess, bf as PermissionSchema, d$ as Permissions, bi as PopulatePlanningOptions, bw as PublicSubdocumentCreateOptions, bx as PublicSubdocumentListOptions, by as PublicSubdocumentMutationOptions, bz as PublicSubdocumentReadOptions, bF as RelatedAuthorization, bH as RequestSchemaAdapter, bI as RequestSchemaFailure, bJ as RequestSchemaIssue, bK as RequestSchemaLike, bL as RequestSchemaOptions, bM as RequestSchemaResult, bN as RequestSchemaSuccess, bO as RequestSchemaValidator, ce as RouteBaseAccess, cf as RouteGuardAccess, cg as RouteVariant, ch as RouteVariantAccess, ci as RowAuthorization, cm as ServiceAuthorization, cn as ServiceOutputContext, co as ServiceOutputDecorator, ct as StandardSchemaFailure, cu as StandardSchemaInferOutput, cv as StandardSchemaIssue, cw as StandardSchemaPathSegment, cx as StandardSchemaResult, cy as StandardSchemaSuccess, cz as StandardSchemaV1, cC as SubOperationAccess, cG as SubRouteGuardOptions, cJ as SubdocumentCreateAuthorization, cL as SubdocumentCreateOptions, cM as SubdocumentCreateVisibilityAuthorization, cN as SubdocumentDeleteAuthorization, cO as SubdocumentDeleteOptions, cP as SubdocumentGateAuthorization, cR as SubdocumentInputAuthorization, cS as SubdocumentListOptions, cT as SubdocumentModel, cU as SubdocumentMutationAuthorization, cV as SubdocumentName, cW as SubdocumentOutputAuthorization, cZ as SubdocumentReadAuthorization, c_ as SubdocumentReadOptions, d0 as SubdocumentUpdateOptions, d1 as SubdocumentVirtuals, d2 as SubdocumentVisibilityAuthorization, d3 as SuperstructFailureLike, d4 as SuperstructValidateLike, dh as ValibotIssueLike, di as ValibotPathItemLike, dj as ValibotSafeParseLike, dk as ValibotSafeParseResult, dq as VineValidationErrorLike, dr as VineValidationMessageLike, ds as VineValidatorLike, dt as VirtualSubModel, du as WithVirtuals, dv as YupSchemaLike, dw as YupValidationErrorLike, e0 as defaultRuntime, dx as defineRequestSchema, dy as fromAjv, dz as fromArkType, dA as fromIoTs, dB as fromJoi, dC as fromStandardSchema, dD as fromSuperstruct, dE as fromValibot, dF as fromVine, dG as fromYup, dH as fromZod } from './parsers-BnmChTfF.mjs';
|
|
5
5
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
@@ -125,6 +125,12 @@ declare class ModelRouter<TModel = unknown, TVirtuals extends object = Record<ne
|
|
|
125
125
|
constructor(modelName: string, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime);
|
|
126
126
|
static fromModel<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime): ModelRouter<TModel, TVirtuals>;
|
|
127
127
|
private getRequestSchema;
|
|
128
|
+
/**
|
|
129
|
+
* Acquire the model-generic internal service after this runtime's middleware
|
|
130
|
+
* initializes req.macl. Supply trusted per-call authorization in service options;
|
|
131
|
+
* selection/query args stay separate. Successful results carry opaque document
|
|
132
|
+
* handles in context(s), never data. Use getPublicService for request-only wrappers.
|
|
133
|
+
*/
|
|
128
134
|
getService(req: ModelRequest): Service<TModel, TVirtuals>;
|
|
129
135
|
getPublicService(req: ModelRequest): PublicService<TModel, TVirtuals>;
|
|
130
136
|
private assertAllowed;
|
|
@@ -443,9 +449,19 @@ declare const getDefaultModelOptions: () => DefaultModelRouterOptions<unknown>;
|
|
|
443
449
|
declare const getDefaultModelOption: <K extends keyof ExtendedDefaultModelRouterOptions>(key: K, defaultValue?: ExtendedDefaultModelRouterOptions[K]) => ExtendedDefaultModelRouterOptions<unknown>[K];
|
|
444
450
|
|
|
445
451
|
interface Options {
|
|
452
|
+
/** Hydrated-document getter alias; defaults to `permissions`. */
|
|
446
453
|
virtualPermissionField?: string;
|
|
454
|
+
/** Registered model whose documentPermissionField setting supplies the metadata slot. */
|
|
447
455
|
modelName: string;
|
|
448
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Optional Mongoose getter alias for existing document permission metadata. Defaults
|
|
459
|
+
* to `doc.permissions`, reading `_doc[documentPermissionField]` (usually `_permissions`).
|
|
460
|
+
* Option lookup uses the active runtime, or the default runtime outside managed execution.
|
|
461
|
+
* This plugin neither computes grants nor enables field enforcement: routers/services
|
|
462
|
+
* already enforce operationAccess and permissionSchema without it. It is separate from
|
|
463
|
+
* the package's computed `virtuals` output API and is unnecessary for lean output.
|
|
464
|
+
*/
|
|
449
465
|
declare function permissionsPlugin(schema: Schema, options: Options): void;
|
|
450
466
|
|
|
451
467
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -471,24 +487,49 @@ interface OpLogContext {
|
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
type CreateRouter = {
|
|
490
|
+
/**
|
|
491
|
+
* Create a model CRUD router and register this exact Mongoose model/connection
|
|
492
|
+
* with the owning runtime. Configure operationAccess and permissionSchema, then
|
|
493
|
+
* mount the returned `.routes` in Express after express.json(). Route middleware
|
|
494
|
+
* initializes req.macl; field enforcement does not require permissionsPlugin.
|
|
495
|
+
*/
|
|
474
496
|
<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
497
|
+
/**
|
|
498
|
+
* Create a router for an already-registered model name. Isolated runtimes require
|
|
499
|
+
* registerModelInstance(name, model) first; default acl also adopts mongoose.model(name).
|
|
500
|
+
* Prefer the model-instance overload for explicit connection ownership.
|
|
501
|
+
*/
|
|
475
502
|
<TModel, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
503
|
+
/** Create an ordered root batch endpoint for this runtime's targets; mount `.routes`. */
|
|
476
504
|
(options: RootRouterOptions): RootRouter;
|
|
477
505
|
};
|
|
478
506
|
type CreateDataRouter = {
|
|
507
|
+
/**
|
|
508
|
+
* Create request-only list/read routes over an owned in-memory dataset. Set
|
|
509
|
+
* operationAccess, permissionSchema, idParam and idField explicitly. Mount `.routes`;
|
|
510
|
+
* middleware initializes req.dacl. No MongoDB connection or model defaults are used.
|
|
511
|
+
* Data replacement affects new services; existing services keep their captured version.
|
|
512
|
+
*/
|
|
479
513
|
<TData>(dataName: string, options: DataRouterOptions<TData>): DataRouter<TData>;
|
|
480
514
|
};
|
|
515
|
+
/** Runtime-bound OpenAPI factory; returns an Express router mounted directly with app.use(). */
|
|
481
516
|
type CreateRuntimeOpenApiRouter = (options?: OpenApiRouterOptions) => Router;
|
|
482
517
|
type WttSet = {
|
|
518
|
+
/** Set one global option on this API's runtime, not a model option or method default. */
|
|
483
519
|
<K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
|
|
520
|
+
/** Shallowly replace supplied global option values; equivalent to setGlobalOptions(options). */
|
|
484
521
|
(options: {
|
|
485
522
|
[K in keyof GlobalOptions]: GlobalOptions[K];
|
|
486
523
|
}): void;
|
|
487
524
|
};
|
|
488
525
|
interface Wtt {
|
|
526
|
+
/** Owning options/model/OpenAPI registry; also exposes data and exact option getters/setters. */
|
|
489
527
|
runtime: AccessRuntime;
|
|
528
|
+
/** Model instance/name + options creates CRUD routes; a single options object creates a root batch. */
|
|
490
529
|
createRouter: CreateRouter;
|
|
530
|
+
/** Owned in-memory list/read router; no model-default or backend field-grant layer. */
|
|
491
531
|
createDataRouter: CreateDataRouter;
|
|
532
|
+
/** This runtime's OpenAPI/Swagger UI router. Unlike the standalone export, takes only options. */
|
|
492
533
|
createOpenApiRouter: CreateRuntimeOpenApiRouter;
|
|
493
534
|
combineRoutes: typeof combineRoutes;
|
|
494
535
|
set: WttSet;
|
|
@@ -513,8 +554,50 @@ interface Wtt {
|
|
|
513
554
|
ModelRouter: typeof ModelRouter;
|
|
514
555
|
DataRouter: typeof DataRouter;
|
|
515
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* Callable runtime-bound facade returned by createAccessRuntime (also the type of acl).
|
|
559
|
+
* Calling api() creates model request middleware for custom routes; generated `.routes`
|
|
560
|
+
* already initialize their own model/data cores. api.runtime is the AccessRuntime owner.
|
|
561
|
+
* Configuration methods on this facade remain bound to that owner.
|
|
562
|
+
*/
|
|
516
563
|
type AccessRuntimeApi = typeof macl & Wtt;
|
|
564
|
+
/**
|
|
565
|
+
* Create an isolated Express/Mongoose router API with its own options, model registry,
|
|
566
|
+
* OpenAPI registry and request-owned work pools. Requires Node >=22, Express >=5 and
|
|
567
|
+
* Mongoose >=8. Pass a Mongoose model instance to createRouter, or register it before
|
|
568
|
+
* using a string name; isolated runtimes do not fall back to global mongoose.models.
|
|
569
|
+
*
|
|
570
|
+
* The returned callable facade exposes factories/setters; `.runtime` is its owner.
|
|
571
|
+
* Mount generated `.routes` after express.json(); connect MongoDB before listening.
|
|
572
|
+
* Model operations default to denied until operationAccess is configured, and field
|
|
573
|
+
* visibility requires permissionSchema. permissionsPlugin is only an optional alias.
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```ts
|
|
577
|
+
* import express from 'express';
|
|
578
|
+
* import mongoose from 'mongoose';
|
|
579
|
+
* import { createAccessRuntime } from '@web-ts-toolkit/access-router';
|
|
580
|
+
* const api = createAccessRuntime();
|
|
581
|
+
* const Product = mongoose.model('Product', new mongoose.Schema({ name: String }));
|
|
582
|
+
* const products = api.createRouter(Product, {
|
|
583
|
+
* basePath: '/products',
|
|
584
|
+
* operationAccess: { list: true, read: true },
|
|
585
|
+
* permissionSchema: { name: true },
|
|
586
|
+
* });
|
|
587
|
+
* const app = express();
|
|
588
|
+
* app.use(express.json());
|
|
589
|
+
* app.use(products.routes);
|
|
590
|
+
* // Await mongoose.connect(uri) before app.listen(port).
|
|
591
|
+
* ```
|
|
592
|
+
* @returns A fresh AccessRuntimeApi. See the shipped README's Configuration layers.
|
|
593
|
+
*/
|
|
517
594
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
595
|
+
/**
|
|
596
|
+
* Shared default-runtime API. Canonical import: `import acl from '@web-ts-toolkit/access-router'`;
|
|
597
|
+
* named `{ acl }` is identical. CommonJS uses `require('@web-ts-toolkit/access-router').acl`.
|
|
598
|
+
* Use createAccessRuntime() for an isolated registry/configuration. Mount factory `.routes`;
|
|
599
|
+
* calling acl() alone supplies model middleware for custom handlers.
|
|
600
|
+
*/
|
|
518
601
|
declare const acl: AccessRuntimeApi;
|
|
519
602
|
|
|
520
603
|
export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, DefaultModelRouterOptions, ExtendedDataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, GuardHook, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, ModelVirtualDescriptor, ModelVirtualGetter, ModelVirtualLeaf, ModelVirtualRecordAccess, type OpLogContext, OpenApiCollisionError, OpenApiDocumentOptions, OpenApiRegistry, OpenApiRegistryOptions, OpenApiRouteDescriptor, OpenApiRouterOptions, RootRouter, RootRouterOptions, Validation, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Schema } from 'mongoose';
|
|
2
2
|
import { Response, NextFunction, RequestHandler, Router } from 'express';
|
|
3
|
-
import { A as AccessRouterBaseRequest,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AccessRouterBaseRequest, aq as GuardHook, aR as ModelRequest, dN as AccessRuntime, _ as DataRouterOptions, Y as DataRequest, dO as DataService, aa as ExtendedDataRouterOptions, af as Filter, bk as Projection, cr as Sort, bg as Populate, aS as ModelRouterOptions, dP as Service, dQ as PublicService, a$ as ModelVirtualRecordAccess, aX as ModelVirtualDescriptor, aZ as ModelVirtualGetter, a_ as ModelVirtualLeaf, ac as ExtendedModelRouterOptions, dn as Validation, cb as RootRouterOptions, dR as OpenApiRouterOptions, dS as OpenApiRegistryOptions, dT as OpenApiRouteDescriptor, dU as OpenApiDocumentOptions, dV as OpenApiParameter, dW as OpenApiSchema, dX as OpenApiResponses, ao as GlobalOptions, a2 as DefaultModelRouterOptions, ab as ExtendedDefaultModelRouterOptions } from './parsers-BnmChTfF.js';
|
|
4
|
+
export { dY as AccessRouterPermissionMap, dZ as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, n as AjvValidatorLike, o as AllowedOutputFieldOptions, p as ArkTypeErrorsLike, q as ArkTypeLike, s as AuthorizedListResult, t as AuthorizedSingleResult, H as CreateAuthorization, N as DataFieldOptions, a7 as DocumentAuthorization, ad as FieldAuthorization, ae as FieldOperationAccess, ap as GlobalPermissionValue, at as InputFieldAuthorization, au as InputFieldPath, av as IoTsContextEntryLike, aw as IoTsDecodeErrorLike, ax as IoTsDecoderLike, ay as JoiSchemaLike, az as JoiValidationErrorDetailLike, aF as MaybePromise, aG as ModelBaseFilterHook, aI as ModelDeleteHook, aJ as ModelDocPermissionsHook, aL as ModelDocumentHook, aM as ModelHook, aO as ModelIdentifierHook, aP as ModelListHook, aQ as ModelOverrideFilterHook, aT as ModelValidateHook, aU as ModelVirtualAccess, aV as ModelVirtualAccessRecord, aW as ModelVirtualContext, aY as ModelVirtualDoc, b0 as ModelVirtuals, b1 as MutationAuthorization, b2 as NewArgs, b3 as NewOptions, d_ as OpenApiMethod, b4 as OperationAccess, b5 as OperationAuthorization, b6 as OutputAuthorization, b7 as OutputFieldOptions, b8 as OutputFieldPath, b9 as OutputPlanningOptions, bc as PairedRouteAccess, bf as PermissionSchema, d$ as Permissions, bi as PopulatePlanningOptions, bw as PublicSubdocumentCreateOptions, bx as PublicSubdocumentListOptions, by as PublicSubdocumentMutationOptions, bz as PublicSubdocumentReadOptions, bF as RelatedAuthorization, bH as RequestSchemaAdapter, bI as RequestSchemaFailure, bJ as RequestSchemaIssue, bK as RequestSchemaLike, bL as RequestSchemaOptions, bM as RequestSchemaResult, bN as RequestSchemaSuccess, bO as RequestSchemaValidator, ce as RouteBaseAccess, cf as RouteGuardAccess, cg as RouteVariant, ch as RouteVariantAccess, ci as RowAuthorization, cm as ServiceAuthorization, cn as ServiceOutputContext, co as ServiceOutputDecorator, ct as StandardSchemaFailure, cu as StandardSchemaInferOutput, cv as StandardSchemaIssue, cw as StandardSchemaPathSegment, cx as StandardSchemaResult, cy as StandardSchemaSuccess, cz as StandardSchemaV1, cC as SubOperationAccess, cG as SubRouteGuardOptions, cJ as SubdocumentCreateAuthorization, cL as SubdocumentCreateOptions, cM as SubdocumentCreateVisibilityAuthorization, cN as SubdocumentDeleteAuthorization, cO as SubdocumentDeleteOptions, cP as SubdocumentGateAuthorization, cR as SubdocumentInputAuthorization, cS as SubdocumentListOptions, cT as SubdocumentModel, cU as SubdocumentMutationAuthorization, cV as SubdocumentName, cW as SubdocumentOutputAuthorization, cZ as SubdocumentReadAuthorization, c_ as SubdocumentReadOptions, d0 as SubdocumentUpdateOptions, d1 as SubdocumentVirtuals, d2 as SubdocumentVisibilityAuthorization, d3 as SuperstructFailureLike, d4 as SuperstructValidateLike, dh as ValibotIssueLike, di as ValibotPathItemLike, dj as ValibotSafeParseLike, dk as ValibotSafeParseResult, dq as VineValidationErrorLike, dr as VineValidationMessageLike, ds as VineValidatorLike, dt as VirtualSubModel, du as WithVirtuals, dv as YupSchemaLike, dw as YupValidationErrorLike, e0 as defaultRuntime, dx as defineRequestSchema, dy as fromAjv, dz as fromArkType, dA as fromIoTs, dB as fromJoi, dC as fromStandardSchema, dD as fromSuperstruct, dE as fromValibot, dF as fromVine, dG as fromYup, dH as fromZod } from './parsers-BnmChTfF.js';
|
|
5
5
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
@@ -125,6 +125,12 @@ declare class ModelRouter<TModel = unknown, TVirtuals extends object = Record<ne
|
|
|
125
125
|
constructor(modelName: string, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime);
|
|
126
126
|
static fromModel<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, initialOptions: ModelRouterOptions<TModel, TVirtuals>, runtime?: AccessRuntime): ModelRouter<TModel, TVirtuals>;
|
|
127
127
|
private getRequestSchema;
|
|
128
|
+
/**
|
|
129
|
+
* Acquire the model-generic internal service after this runtime's middleware
|
|
130
|
+
* initializes req.macl. Supply trusted per-call authorization in service options;
|
|
131
|
+
* selection/query args stay separate. Successful results carry opaque document
|
|
132
|
+
* handles in context(s), never data. Use getPublicService for request-only wrappers.
|
|
133
|
+
*/
|
|
128
134
|
getService(req: ModelRequest): Service<TModel, TVirtuals>;
|
|
129
135
|
getPublicService(req: ModelRequest): PublicService<TModel, TVirtuals>;
|
|
130
136
|
private assertAllowed;
|
|
@@ -443,9 +449,19 @@ declare const getDefaultModelOptions: () => DefaultModelRouterOptions<unknown>;
|
|
|
443
449
|
declare const getDefaultModelOption: <K extends keyof ExtendedDefaultModelRouterOptions>(key: K, defaultValue?: ExtendedDefaultModelRouterOptions[K]) => ExtendedDefaultModelRouterOptions<unknown>[K];
|
|
444
450
|
|
|
445
451
|
interface Options {
|
|
452
|
+
/** Hydrated-document getter alias; defaults to `permissions`. */
|
|
446
453
|
virtualPermissionField?: string;
|
|
454
|
+
/** Registered model whose documentPermissionField setting supplies the metadata slot. */
|
|
447
455
|
modelName: string;
|
|
448
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Optional Mongoose getter alias for existing document permission metadata. Defaults
|
|
459
|
+
* to `doc.permissions`, reading `_doc[documentPermissionField]` (usually `_permissions`).
|
|
460
|
+
* Option lookup uses the active runtime, or the default runtime outside managed execution.
|
|
461
|
+
* This plugin neither computes grants nor enables field enforcement: routers/services
|
|
462
|
+
* already enforce operationAccess and permissionSchema without it. It is separate from
|
|
463
|
+
* the package's computed `virtuals` output API and is unnecessary for lean output.
|
|
464
|
+
*/
|
|
449
465
|
declare function permissionsPlugin(schema: Schema, options: Options): void;
|
|
450
466
|
|
|
451
467
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -471,24 +487,49 @@ interface OpLogContext {
|
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
type CreateRouter = {
|
|
490
|
+
/**
|
|
491
|
+
* Create a model CRUD router and register this exact Mongoose model/connection
|
|
492
|
+
* with the owning runtime. Configure operationAccess and permissionSchema, then
|
|
493
|
+
* mount the returned `.routes` in Express after express.json(). Route middleware
|
|
494
|
+
* initializes req.macl; field enforcement does not require permissionsPlugin.
|
|
495
|
+
*/
|
|
474
496
|
<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
497
|
+
/**
|
|
498
|
+
* Create a router for an already-registered model name. Isolated runtimes require
|
|
499
|
+
* registerModelInstance(name, model) first; default acl also adopts mongoose.model(name).
|
|
500
|
+
* Prefer the model-instance overload for explicit connection ownership.
|
|
501
|
+
*/
|
|
475
502
|
<TModel, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
503
|
+
/** Create an ordered root batch endpoint for this runtime's targets; mount `.routes`. */
|
|
476
504
|
(options: RootRouterOptions): RootRouter;
|
|
477
505
|
};
|
|
478
506
|
type CreateDataRouter = {
|
|
507
|
+
/**
|
|
508
|
+
* Create request-only list/read routes over an owned in-memory dataset. Set
|
|
509
|
+
* operationAccess, permissionSchema, idParam and idField explicitly. Mount `.routes`;
|
|
510
|
+
* middleware initializes req.dacl. No MongoDB connection or model defaults are used.
|
|
511
|
+
* Data replacement affects new services; existing services keep their captured version.
|
|
512
|
+
*/
|
|
479
513
|
<TData>(dataName: string, options: DataRouterOptions<TData>): DataRouter<TData>;
|
|
480
514
|
};
|
|
515
|
+
/** Runtime-bound OpenAPI factory; returns an Express router mounted directly with app.use(). */
|
|
481
516
|
type CreateRuntimeOpenApiRouter = (options?: OpenApiRouterOptions) => Router;
|
|
482
517
|
type WttSet = {
|
|
518
|
+
/** Set one global option on this API's runtime, not a model option or method default. */
|
|
483
519
|
<K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
|
|
520
|
+
/** Shallowly replace supplied global option values; equivalent to setGlobalOptions(options). */
|
|
484
521
|
(options: {
|
|
485
522
|
[K in keyof GlobalOptions]: GlobalOptions[K];
|
|
486
523
|
}): void;
|
|
487
524
|
};
|
|
488
525
|
interface Wtt {
|
|
526
|
+
/** Owning options/model/OpenAPI registry; also exposes data and exact option getters/setters. */
|
|
489
527
|
runtime: AccessRuntime;
|
|
528
|
+
/** Model instance/name + options creates CRUD routes; a single options object creates a root batch. */
|
|
490
529
|
createRouter: CreateRouter;
|
|
530
|
+
/** Owned in-memory list/read router; no model-default or backend field-grant layer. */
|
|
491
531
|
createDataRouter: CreateDataRouter;
|
|
532
|
+
/** This runtime's OpenAPI/Swagger UI router. Unlike the standalone export, takes only options. */
|
|
492
533
|
createOpenApiRouter: CreateRuntimeOpenApiRouter;
|
|
493
534
|
combineRoutes: typeof combineRoutes;
|
|
494
535
|
set: WttSet;
|
|
@@ -513,8 +554,50 @@ interface Wtt {
|
|
|
513
554
|
ModelRouter: typeof ModelRouter;
|
|
514
555
|
DataRouter: typeof DataRouter;
|
|
515
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* Callable runtime-bound facade returned by createAccessRuntime (also the type of acl).
|
|
559
|
+
* Calling api() creates model request middleware for custom routes; generated `.routes`
|
|
560
|
+
* already initialize their own model/data cores. api.runtime is the AccessRuntime owner.
|
|
561
|
+
* Configuration methods on this facade remain bound to that owner.
|
|
562
|
+
*/
|
|
516
563
|
type AccessRuntimeApi = typeof macl & Wtt;
|
|
564
|
+
/**
|
|
565
|
+
* Create an isolated Express/Mongoose router API with its own options, model registry,
|
|
566
|
+
* OpenAPI registry and request-owned work pools. Requires Node >=22, Express >=5 and
|
|
567
|
+
* Mongoose >=8. Pass a Mongoose model instance to createRouter, or register it before
|
|
568
|
+
* using a string name; isolated runtimes do not fall back to global mongoose.models.
|
|
569
|
+
*
|
|
570
|
+
* The returned callable facade exposes factories/setters; `.runtime` is its owner.
|
|
571
|
+
* Mount generated `.routes` after express.json(); connect MongoDB before listening.
|
|
572
|
+
* Model operations default to denied until operationAccess is configured, and field
|
|
573
|
+
* visibility requires permissionSchema. permissionsPlugin is only an optional alias.
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```ts
|
|
577
|
+
* import express from 'express';
|
|
578
|
+
* import mongoose from 'mongoose';
|
|
579
|
+
* import { createAccessRuntime } from '@web-ts-toolkit/access-router';
|
|
580
|
+
* const api = createAccessRuntime();
|
|
581
|
+
* const Product = mongoose.model('Product', new mongoose.Schema({ name: String }));
|
|
582
|
+
* const products = api.createRouter(Product, {
|
|
583
|
+
* basePath: '/products',
|
|
584
|
+
* operationAccess: { list: true, read: true },
|
|
585
|
+
* permissionSchema: { name: true },
|
|
586
|
+
* });
|
|
587
|
+
* const app = express();
|
|
588
|
+
* app.use(express.json());
|
|
589
|
+
* app.use(products.routes);
|
|
590
|
+
* // Await mongoose.connect(uri) before app.listen(port).
|
|
591
|
+
* ```
|
|
592
|
+
* @returns A fresh AccessRuntimeApi. See the shipped README's Configuration layers.
|
|
593
|
+
*/
|
|
517
594
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
595
|
+
/**
|
|
596
|
+
* Shared default-runtime API. Canonical import: `import acl from '@web-ts-toolkit/access-router'`;
|
|
597
|
+
* named `{ acl }` is identical. CommonJS uses `require('@web-ts-toolkit/access-router').acl`.
|
|
598
|
+
* Use createAccessRuntime() for an isolated registry/configuration. Mount factory `.routes`;
|
|
599
|
+
* calling acl() alone supplies model middleware for custom handlers.
|
|
600
|
+
*/
|
|
518
601
|
declare const acl: AccessRuntimeApi;
|
|
519
602
|
|
|
520
603
|
export { AccessRuntime, type AccessRuntimeApi, type CombinedRouteInput, DataRouter, DataRouterOptions, DefaultModelRouterOptions, ExtendedDataRouterOptions, ExtendedDefaultModelRouterOptions, ExtendedModelRouterOptions, GlobalOptions, GuardHook, type GuardModelCondition, type GuardModelConditionID, ModelRouter, ModelRouterOptions, ModelVirtualDescriptor, ModelVirtualGetter, ModelVirtualLeaf, ModelVirtualRecordAccess, type OpLogContext, OpenApiCollisionError, OpenApiDocumentOptions, OpenApiRegistry, OpenApiRegistryOptions, OpenApiRouteDescriptor, OpenApiRouterOptions, RootRouter, RootRouterOptions, Validation, acl, combineRoutes, createAccessRuntime, createOpenApiRouter, acl as default, getDefaultModelOption, getDefaultModelOptions, getGlobalOption, getGlobalOptions, getModelInstance, getModelJsonSchema, getModelNames, getModelOption, getModelOptions, guard, hasModelInstance, isLevelEnabled, permissionsPlugin, redactFilter, redactPayload, registerModelInstance, safeStringify, setDefaultModelOption, setDefaultModelOptions, setGlobalOption, setGlobalOptions, setModelOption, setModelOptions };
|