@web-ts-toolkit/access-router 0.51.0 → 0.53.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 +1744 -118
- package/advanced.d.mts +1 -4
- package/advanced.d.ts +1 -4
- package/advanced.js +774 -307
- package/advanced.mjs +722 -255
- package/index.d.mts +88 -2
- package/index.d.ts +88 -2
- package/index.js +11011 -7572
- package/index.mjs +11043 -7606
- package/llms.txt +39 -314
- package/package.json +3 -3
- package/{parsers-DhUuvj9B.d.mts → parsers-ZSrF7SNu.d.mts} +2661 -1929
- package/{parsers-DhUuvj9B.d.ts → parsers-ZSrF7SNu.d.ts} +2661 -1929
- package/processors.js +86 -47
- package/processors.mjs +49 -10
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, aT as ModelRequest, dP as AccessRuntime, _ as DataRouterOptions, Y as DataRequest, dQ as DataService, aa as ExtendedDataRouterOptions, af as Filter, bm as Projection, ct as Sort, bi as Populate, aU as ModelRouterOptions, dR as Service, dS as PublicService, b1 as ModelVirtualRecordAccess, aZ as ModelVirtualDescriptor, a$ as ModelVirtualGetter, b0 as ModelVirtualLeaf, ac as ExtendedModelRouterOptions, dq as Validation, cd as RootRouterOptions, dT as OpenApiRouterOptions, dU as OpenApiRegistryOptions, dV as OpenApiRouteDescriptor, dW as OpenApiDocumentOptions, dX as OpenApiParameter, dY as OpenApiSchema, dZ as OpenApiResponses, ao as GlobalOptions, a2 as DefaultModelRouterOptions, ab as ExtendedDefaultModelRouterOptions } from './parsers-ZSrF7SNu.mjs';
|
|
4
|
+
export { d_ as AccessRouterPermissionMap, d$ 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, ar as HydrationMode, au as InputFieldAuthorization, av as InputFieldPath, aw as IoTsContextEntryLike, ax as IoTsDecodeErrorLike, ay as IoTsDecoderLike, az as JoiSchemaLike, aA as JoiValidationErrorDetailLike, aG as MaybePromise, aH as ModelBaseFilterHook, aJ as ModelDeleteHook, aK as ModelDocPermissionsHook, aM as ModelDocumentHook, aN as ModelHook, aP as ModelHydrationOptions, aQ as ModelIdentifierHook, aR as ModelListHook, aS as ModelOverrideFilterHook, aV as ModelValidateHook, aW as ModelVirtualAccess, aX as ModelVirtualAccessRecord, aY as ModelVirtualContext, a_ as ModelVirtualDoc, b2 as ModelVirtuals, b3 as MutationAuthorization, b4 as NewArgs, b5 as NewOptions, e0 as OpenApiMethod, b6 as OperationAccess, b7 as OperationAuthorization, b8 as OutputAuthorization, b9 as OutputFieldOptions, ba as OutputFieldPath, bb as OutputPlanningOptions, be as PairedRouteAccess, bh as PermissionSchema, e1 as Permissions, bk as PopulatePlanningOptions, by as PublicSubdocumentCreateOptions, bz as PublicSubdocumentListOptions, bA as PublicSubdocumentMutationOptions, bB as PublicSubdocumentReadOptions, bH as RelatedAuthorization, bJ as RequestSchemaAdapter, bK as RequestSchemaFailure, bL as RequestSchemaIssue, bM as RequestSchemaLike, bN as RequestSchemaOptions, bO as RequestSchemaResult, bP as RequestSchemaSuccess, bQ as RequestSchemaValidator, cg as RouteBaseAccess, ch as RouteGuardAccess, ci as RouteVariant, cj as RouteVariantAccess, ck as RowAuthorization, co as ServiceAuthorization, cp as ServiceOutputContext, cq as ServiceOutputDecorator, cv as StandardSchemaFailure, cw as StandardSchemaInferOutput, cx as StandardSchemaIssue, cy as StandardSchemaPathSegment, cz as StandardSchemaResult, cA as StandardSchemaSuccess, cB as StandardSchemaV1, cE as SubOperationAccess, cI as SubRouteGuardOptions, cL as SubdocumentCreateAuthorization, cN as SubdocumentCreateOptions, cO as SubdocumentCreateVisibilityAuthorization, cP as SubdocumentDeleteAuthorization, cQ as SubdocumentDeleteOptions, cR as SubdocumentGateAuthorization, cT as SubdocumentInputAuthorization, cU as SubdocumentListOptions, cV as SubdocumentModel, cW as SubdocumentMutationAuthorization, cX as SubdocumentName, cY as SubdocumentOutputAuthorization, c$ as SubdocumentReadAuthorization, d0 as SubdocumentReadOptions, d2 as SubdocumentUpdateOptions, d3 as SubdocumentVirtuals, d4 as SubdocumentVisibilityAuthorization, d5 as SuperstructFailureLike, d6 as SuperstructValidateLike, dj as ValibotIssueLike, dk as ValibotPathItemLike, dl as ValibotSafeParseLike, dm as ValibotSafeParseResult, ds as VineValidationErrorLike, dt as VineValidationMessageLike, du as VineValidatorLike, dv as VirtualSubModel, dw as WithVirtuals, dx as YupSchemaLike, dy as YupValidationErrorLike, e2 as defaultRuntime, dz as defineRequestSchema, dA as fromAjv, dB as fromArkType, dC as fromIoTs, dD as fromJoi, dE as fromStandardSchema, dF as fromSuperstruct, dG as fromValibot, dH as fromVine, dI as fromYup, dJ as fromZod } from './parsers-ZSrF7SNu.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,22 @@ 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. Finalized rows already get their
|
|
464
|
+
* own non-enumerable `permissions` alias from exposed metadata in both modes without
|
|
465
|
+
* this plugin. virtualPermissionField only names this raw getter; its literal _doc
|
|
466
|
+
* lookup does not traverse dotted metadata paths.
|
|
467
|
+
*/
|
|
449
468
|
declare function permissionsPlugin(schema: Schema, options: Options): void;
|
|
450
469
|
|
|
451
470
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -471,24 +490,49 @@ interface OpLogContext {
|
|
|
471
490
|
}
|
|
472
491
|
|
|
473
492
|
type CreateRouter = {
|
|
493
|
+
/**
|
|
494
|
+
* Create a model CRUD router and register this exact Mongoose model/connection
|
|
495
|
+
* with the owning runtime. Configure operationAccess and permissionSchema, then
|
|
496
|
+
* mount the returned `.routes` in Express after express.json(). Route middleware
|
|
497
|
+
* initializes req.macl; field enforcement does not require permissionsPlugin.
|
|
498
|
+
*/
|
|
474
499
|
<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
500
|
+
/**
|
|
501
|
+
* Create a router for an already-registered model name. Isolated runtimes require
|
|
502
|
+
* registerModelInstance(name, model) first; default acl also adopts mongoose.model(name).
|
|
503
|
+
* Prefer the model-instance overload for explicit connection ownership.
|
|
504
|
+
*/
|
|
475
505
|
<TModel, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
506
|
+
/** Create an ordered root batch endpoint for this runtime's targets; mount `.routes`. */
|
|
476
507
|
(options: RootRouterOptions): RootRouter;
|
|
477
508
|
};
|
|
478
509
|
type CreateDataRouter = {
|
|
510
|
+
/**
|
|
511
|
+
* Create request-only list/read routes over an owned in-memory dataset. Set
|
|
512
|
+
* operationAccess, permissionSchema, idParam and idField explicitly. Mount `.routes`;
|
|
513
|
+
* middleware initializes req.dacl. No MongoDB connection or model defaults are used.
|
|
514
|
+
* Data replacement affects new services; existing services keep their captured version.
|
|
515
|
+
*/
|
|
479
516
|
<TData>(dataName: string, options: DataRouterOptions<TData>): DataRouter<TData>;
|
|
480
517
|
};
|
|
518
|
+
/** Runtime-bound OpenAPI factory; returns an Express router mounted directly with app.use(). */
|
|
481
519
|
type CreateRuntimeOpenApiRouter = (options?: OpenApiRouterOptions) => Router;
|
|
482
520
|
type WttSet = {
|
|
521
|
+
/** Set one global option on this API's runtime, not a model option or method default. */
|
|
483
522
|
<K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
|
|
523
|
+
/** Shallowly replace supplied global option values; equivalent to setGlobalOptions(options). */
|
|
484
524
|
(options: {
|
|
485
525
|
[K in keyof GlobalOptions]: GlobalOptions[K];
|
|
486
526
|
}): void;
|
|
487
527
|
};
|
|
488
528
|
interface Wtt {
|
|
529
|
+
/** Owning options/model/OpenAPI registry; also exposes data and exact option getters/setters. */
|
|
489
530
|
runtime: AccessRuntime;
|
|
531
|
+
/** Model instance/name + options creates CRUD routes; a single options object creates a root batch. */
|
|
490
532
|
createRouter: CreateRouter;
|
|
533
|
+
/** Owned in-memory list/read router; no model-default or backend field-grant layer. */
|
|
491
534
|
createDataRouter: CreateDataRouter;
|
|
535
|
+
/** This runtime's OpenAPI/Swagger UI router. Unlike the standalone export, takes only options. */
|
|
492
536
|
createOpenApiRouter: CreateRuntimeOpenApiRouter;
|
|
493
537
|
combineRoutes: typeof combineRoutes;
|
|
494
538
|
set: WttSet;
|
|
@@ -513,8 +557,50 @@ interface Wtt {
|
|
|
513
557
|
ModelRouter: typeof ModelRouter;
|
|
514
558
|
DataRouter: typeof DataRouter;
|
|
515
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Callable runtime-bound facade returned by createAccessRuntime (also the type of acl).
|
|
562
|
+
* Calling api() creates model request middleware for custom routes; generated `.routes`
|
|
563
|
+
* already initialize their own model/data cores. api.runtime is the AccessRuntime owner.
|
|
564
|
+
* Configuration methods on this facade remain bound to that owner.
|
|
565
|
+
*/
|
|
516
566
|
type AccessRuntimeApi = typeof macl & Wtt;
|
|
567
|
+
/**
|
|
568
|
+
* Create an isolated Express/Mongoose router API with its own options, model registry,
|
|
569
|
+
* OpenAPI registry and request-owned work pools. Requires Node >=22, Express >=5 and
|
|
570
|
+
* Mongoose >=8. Pass a Mongoose model instance to createRouter, or register it before
|
|
571
|
+
* using a string name; isolated runtimes do not fall back to global mongoose.models.
|
|
572
|
+
*
|
|
573
|
+
* The returned callable facade exposes factories/setters; `.runtime` is its owner.
|
|
574
|
+
* Mount generated `.routes` after express.json(); connect MongoDB before listening.
|
|
575
|
+
* Model operations default to denied until operationAccess is configured, and field
|
|
576
|
+
* visibility requires permissionSchema. permissionsPlugin is only an optional raw-document alias.
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* import express from 'express';
|
|
581
|
+
* import mongoose from 'mongoose';
|
|
582
|
+
* import { createAccessRuntime } from '@web-ts-toolkit/access-router';
|
|
583
|
+
* const api = createAccessRuntime();
|
|
584
|
+
* const Product = mongoose.model('Product', new mongoose.Schema({ name: String }));
|
|
585
|
+
* const products = api.createRouter(Product, {
|
|
586
|
+
* basePath: '/products',
|
|
587
|
+
* operationAccess: { list: true, read: true },
|
|
588
|
+
* permissionSchema: { name: true },
|
|
589
|
+
* });
|
|
590
|
+
* const app = express();
|
|
591
|
+
* app.use(express.json());
|
|
592
|
+
* app.use(products.routes);
|
|
593
|
+
* // Await mongoose.connect(uri) before app.listen(port).
|
|
594
|
+
* ```
|
|
595
|
+
* @returns A fresh AccessRuntimeApi. See the shipped README's Configuration layers.
|
|
596
|
+
*/
|
|
517
597
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
598
|
+
/**
|
|
599
|
+
* Shared default-runtime API. Canonical import: `import acl from '@web-ts-toolkit/access-router'`;
|
|
600
|
+
* named `{ acl }` is identical. CommonJS uses `require('@web-ts-toolkit/access-router').acl`.
|
|
601
|
+
* Use createAccessRuntime() for an isolated registry/configuration. Mount factory `.routes`;
|
|
602
|
+
* calling acl() alone supplies model middleware for custom handlers.
|
|
603
|
+
*/
|
|
518
604
|
declare const acl: AccessRuntimeApi;
|
|
519
605
|
|
|
520
606
|
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, aT as ModelRequest, dP as AccessRuntime, _ as DataRouterOptions, Y as DataRequest, dQ as DataService, aa as ExtendedDataRouterOptions, af as Filter, bm as Projection, ct as Sort, bi as Populate, aU as ModelRouterOptions, dR as Service, dS as PublicService, b1 as ModelVirtualRecordAccess, aZ as ModelVirtualDescriptor, a$ as ModelVirtualGetter, b0 as ModelVirtualLeaf, ac as ExtendedModelRouterOptions, dq as Validation, cd as RootRouterOptions, dT as OpenApiRouterOptions, dU as OpenApiRegistryOptions, dV as OpenApiRouteDescriptor, dW as OpenApiDocumentOptions, dX as OpenApiParameter, dY as OpenApiSchema, dZ as OpenApiResponses, ao as GlobalOptions, a2 as DefaultModelRouterOptions, ab as ExtendedDefaultModelRouterOptions } from './parsers-ZSrF7SNu.js';
|
|
4
|
+
export { d_ as AccessRouterPermissionMap, d$ 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, ar as HydrationMode, au as InputFieldAuthorization, av as InputFieldPath, aw as IoTsContextEntryLike, ax as IoTsDecodeErrorLike, ay as IoTsDecoderLike, az as JoiSchemaLike, aA as JoiValidationErrorDetailLike, aG as MaybePromise, aH as ModelBaseFilterHook, aJ as ModelDeleteHook, aK as ModelDocPermissionsHook, aM as ModelDocumentHook, aN as ModelHook, aP as ModelHydrationOptions, aQ as ModelIdentifierHook, aR as ModelListHook, aS as ModelOverrideFilterHook, aV as ModelValidateHook, aW as ModelVirtualAccess, aX as ModelVirtualAccessRecord, aY as ModelVirtualContext, a_ as ModelVirtualDoc, b2 as ModelVirtuals, b3 as MutationAuthorization, b4 as NewArgs, b5 as NewOptions, e0 as OpenApiMethod, b6 as OperationAccess, b7 as OperationAuthorization, b8 as OutputAuthorization, b9 as OutputFieldOptions, ba as OutputFieldPath, bb as OutputPlanningOptions, be as PairedRouteAccess, bh as PermissionSchema, e1 as Permissions, bk as PopulatePlanningOptions, by as PublicSubdocumentCreateOptions, bz as PublicSubdocumentListOptions, bA as PublicSubdocumentMutationOptions, bB as PublicSubdocumentReadOptions, bH as RelatedAuthorization, bJ as RequestSchemaAdapter, bK as RequestSchemaFailure, bL as RequestSchemaIssue, bM as RequestSchemaLike, bN as RequestSchemaOptions, bO as RequestSchemaResult, bP as RequestSchemaSuccess, bQ as RequestSchemaValidator, cg as RouteBaseAccess, ch as RouteGuardAccess, ci as RouteVariant, cj as RouteVariantAccess, ck as RowAuthorization, co as ServiceAuthorization, cp as ServiceOutputContext, cq as ServiceOutputDecorator, cv as StandardSchemaFailure, cw as StandardSchemaInferOutput, cx as StandardSchemaIssue, cy as StandardSchemaPathSegment, cz as StandardSchemaResult, cA as StandardSchemaSuccess, cB as StandardSchemaV1, cE as SubOperationAccess, cI as SubRouteGuardOptions, cL as SubdocumentCreateAuthorization, cN as SubdocumentCreateOptions, cO as SubdocumentCreateVisibilityAuthorization, cP as SubdocumentDeleteAuthorization, cQ as SubdocumentDeleteOptions, cR as SubdocumentGateAuthorization, cT as SubdocumentInputAuthorization, cU as SubdocumentListOptions, cV as SubdocumentModel, cW as SubdocumentMutationAuthorization, cX as SubdocumentName, cY as SubdocumentOutputAuthorization, c$ as SubdocumentReadAuthorization, d0 as SubdocumentReadOptions, d2 as SubdocumentUpdateOptions, d3 as SubdocumentVirtuals, d4 as SubdocumentVisibilityAuthorization, d5 as SuperstructFailureLike, d6 as SuperstructValidateLike, dj as ValibotIssueLike, dk as ValibotPathItemLike, dl as ValibotSafeParseLike, dm as ValibotSafeParseResult, ds as VineValidationErrorLike, dt as VineValidationMessageLike, du as VineValidatorLike, dv as VirtualSubModel, dw as WithVirtuals, dx as YupSchemaLike, dy as YupValidationErrorLike, e2 as defaultRuntime, dz as defineRequestSchema, dA as fromAjv, dB as fromArkType, dC as fromIoTs, dD as fromJoi, dE as fromStandardSchema, dF as fromSuperstruct, dG as fromValibot, dH as fromVine, dI as fromYup, dJ as fromZod } from './parsers-ZSrF7SNu.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,22 @@ 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. Finalized rows already get their
|
|
464
|
+
* own non-enumerable `permissions` alias from exposed metadata in both modes without
|
|
465
|
+
* this plugin. virtualPermissionField only names this raw getter; its literal _doc
|
|
466
|
+
* lookup does not traverse dotted metadata paths.
|
|
467
|
+
*/
|
|
449
468
|
declare function permissionsPlugin(schema: Schema, options: Options): void;
|
|
450
469
|
|
|
451
470
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -471,24 +490,49 @@ interface OpLogContext {
|
|
|
471
490
|
}
|
|
472
491
|
|
|
473
492
|
type CreateRouter = {
|
|
493
|
+
/**
|
|
494
|
+
* Create a model CRUD router and register this exact Mongoose model/connection
|
|
495
|
+
* with the owning runtime. Configure operationAccess and permissionSchema, then
|
|
496
|
+
* mount the returned `.routes` in Express after express.json(). Route middleware
|
|
497
|
+
* initializes req.macl; field enforcement does not require permissionsPlugin.
|
|
498
|
+
*/
|
|
474
499
|
<TModel, TVirtuals extends object = Record<never, never>>(model: mongoose.Model<TModel>, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
500
|
+
/**
|
|
501
|
+
* Create a router for an already-registered model name. Isolated runtimes require
|
|
502
|
+
* registerModelInstance(name, model) first; default acl also adopts mongoose.model(name).
|
|
503
|
+
* Prefer the model-instance overload for explicit connection ownership.
|
|
504
|
+
*/
|
|
475
505
|
<TModel, TVirtuals extends object = Record<never, never>>(modelName: string, options: ModelRouterOptions<TModel, TVirtuals>): ModelRouter<TModel, TVirtuals>;
|
|
506
|
+
/** Create an ordered root batch endpoint for this runtime's targets; mount `.routes`. */
|
|
476
507
|
(options: RootRouterOptions): RootRouter;
|
|
477
508
|
};
|
|
478
509
|
type CreateDataRouter = {
|
|
510
|
+
/**
|
|
511
|
+
* Create request-only list/read routes over an owned in-memory dataset. Set
|
|
512
|
+
* operationAccess, permissionSchema, idParam and idField explicitly. Mount `.routes`;
|
|
513
|
+
* middleware initializes req.dacl. No MongoDB connection or model defaults are used.
|
|
514
|
+
* Data replacement affects new services; existing services keep their captured version.
|
|
515
|
+
*/
|
|
479
516
|
<TData>(dataName: string, options: DataRouterOptions<TData>): DataRouter<TData>;
|
|
480
517
|
};
|
|
518
|
+
/** Runtime-bound OpenAPI factory; returns an Express router mounted directly with app.use(). */
|
|
481
519
|
type CreateRuntimeOpenApiRouter = (options?: OpenApiRouterOptions) => Router;
|
|
482
520
|
type WttSet = {
|
|
521
|
+
/** Set one global option on this API's runtime, not a model option or method default. */
|
|
483
522
|
<K extends keyof GlobalOptions>(key: K, value: GlobalOptions[K]): void;
|
|
523
|
+
/** Shallowly replace supplied global option values; equivalent to setGlobalOptions(options). */
|
|
484
524
|
(options: {
|
|
485
525
|
[K in keyof GlobalOptions]: GlobalOptions[K];
|
|
486
526
|
}): void;
|
|
487
527
|
};
|
|
488
528
|
interface Wtt {
|
|
529
|
+
/** Owning options/model/OpenAPI registry; also exposes data and exact option getters/setters. */
|
|
489
530
|
runtime: AccessRuntime;
|
|
531
|
+
/** Model instance/name + options creates CRUD routes; a single options object creates a root batch. */
|
|
490
532
|
createRouter: CreateRouter;
|
|
533
|
+
/** Owned in-memory list/read router; no model-default or backend field-grant layer. */
|
|
491
534
|
createDataRouter: CreateDataRouter;
|
|
535
|
+
/** This runtime's OpenAPI/Swagger UI router. Unlike the standalone export, takes only options. */
|
|
492
536
|
createOpenApiRouter: CreateRuntimeOpenApiRouter;
|
|
493
537
|
combineRoutes: typeof combineRoutes;
|
|
494
538
|
set: WttSet;
|
|
@@ -513,8 +557,50 @@ interface Wtt {
|
|
|
513
557
|
ModelRouter: typeof ModelRouter;
|
|
514
558
|
DataRouter: typeof DataRouter;
|
|
515
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Callable runtime-bound facade returned by createAccessRuntime (also the type of acl).
|
|
562
|
+
* Calling api() creates model request middleware for custom routes; generated `.routes`
|
|
563
|
+
* already initialize their own model/data cores. api.runtime is the AccessRuntime owner.
|
|
564
|
+
* Configuration methods on this facade remain bound to that owner.
|
|
565
|
+
*/
|
|
516
566
|
type AccessRuntimeApi = typeof macl & Wtt;
|
|
567
|
+
/**
|
|
568
|
+
* Create an isolated Express/Mongoose router API with its own options, model registry,
|
|
569
|
+
* OpenAPI registry and request-owned work pools. Requires Node >=22, Express >=5 and
|
|
570
|
+
* Mongoose >=8. Pass a Mongoose model instance to createRouter, or register it before
|
|
571
|
+
* using a string name; isolated runtimes do not fall back to global mongoose.models.
|
|
572
|
+
*
|
|
573
|
+
* The returned callable facade exposes factories/setters; `.runtime` is its owner.
|
|
574
|
+
* Mount generated `.routes` after express.json(); connect MongoDB before listening.
|
|
575
|
+
* Model operations default to denied until operationAccess is configured, and field
|
|
576
|
+
* visibility requires permissionSchema. permissionsPlugin is only an optional raw-document alias.
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* import express from 'express';
|
|
581
|
+
* import mongoose from 'mongoose';
|
|
582
|
+
* import { createAccessRuntime } from '@web-ts-toolkit/access-router';
|
|
583
|
+
* const api = createAccessRuntime();
|
|
584
|
+
* const Product = mongoose.model('Product', new mongoose.Schema({ name: String }));
|
|
585
|
+
* const products = api.createRouter(Product, {
|
|
586
|
+
* basePath: '/products',
|
|
587
|
+
* operationAccess: { list: true, read: true },
|
|
588
|
+
* permissionSchema: { name: true },
|
|
589
|
+
* });
|
|
590
|
+
* const app = express();
|
|
591
|
+
* app.use(express.json());
|
|
592
|
+
* app.use(products.routes);
|
|
593
|
+
* // Await mongoose.connect(uri) before app.listen(port).
|
|
594
|
+
* ```
|
|
595
|
+
* @returns A fresh AccessRuntimeApi. See the shipped README's Configuration layers.
|
|
596
|
+
*/
|
|
517
597
|
declare function createAccessRuntime(): AccessRuntimeApi;
|
|
598
|
+
/**
|
|
599
|
+
* Shared default-runtime API. Canonical import: `import acl from '@web-ts-toolkit/access-router'`;
|
|
600
|
+
* named `{ acl }` is identical. CommonJS uses `require('@web-ts-toolkit/access-router').acl`.
|
|
601
|
+
* Use createAccessRuntime() for an isolated registry/configuration. Mount factory `.routes`;
|
|
602
|
+
* calling acl() alone supplies model middleware for custom handlers.
|
|
603
|
+
*/
|
|
518
604
|
declare const acl: AccessRuntimeApi;
|
|
519
605
|
|
|
520
606
|
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 };
|