@web-ts-toolkit/access-router 0.43.0 → 0.45.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.
@@ -65,6 +65,13 @@ declare class Service<TModel = unknown> extends Base<TModel> {
65
65
  protected authorizeDistinctField(field: string): Promise<ErrorResult | null>;
66
66
  distinct(field: string, args?: DistinctArgs<TModel>): Promise<ListResult<unknown> | ErrorResult>;
67
67
  count(filter: Filter<TModel>, access?: BaseFilterAccess): Promise<SingleResult<number> | ErrorResult>;
68
+ /**
69
+ * Trusted count for correlated includes (ACI-03): the caller already
70
+ * resolved parent references, revalidated expanded operands, and applied
71
+ * explicit `count` access via `genFilter`. This skips client-filter
72
+ * validation and subquery parsing so substituted parent data stays inert.
73
+ */
74
+ countTrusted(authorizedFilter: Filter<TModel>): Promise<SingleResult<number> | ErrorResult>;
68
75
  countByFieldValues(foreignField: string, values: unknown[], filter?: Filter<TModel>, access?: BaseFilterAccess): Promise<SingleResult<Map<string, Set<string>>> | ErrorResult>;
69
76
  getDocPermissions(doc: unknown): Record<string, unknown>;
70
77
  private resolveFindOneArgs;
@@ -196,7 +203,9 @@ type StandardSchemaV1<Input = unknown, Output = Input> = {
196
203
  type StandardSchemaInferOutput<TSchema extends StandardSchemaV1> = NonNullable<TSchema['~standard']['types']>['output'];
197
204
  type RequestSchemaLike<T = unknown> = RequestSchemaValidator<T> | RequestSchemaAdapter<T> | StandardSchemaV1;
198
205
  type YupValidationErrorLike = {
206
+ name: 'ValidationError';
199
207
  message: string;
208
+ errors: ReadonlyArray<string>;
200
209
  path?: string;
201
210
  inner?: ReadonlyArray<YupValidationErrorLike>;
202
211
  };
@@ -234,9 +243,13 @@ type AjvErrorObjectLike = {
234
243
  missingProperty?: string;
235
244
  };
236
245
  };
246
+ type AjvValidationErrorLike = {
247
+ errors?: ReadonlyArray<AjvErrorObjectLike> | null;
248
+ };
237
249
  type AjvValidatorLike<T = unknown> = {
238
- (value: unknown): boolean | Promise<boolean>;
250
+ (value: unknown): boolean | Promise<T | boolean>;
239
251
  errors?: ReadonlyArray<AjvErrorObjectLike> | null;
252
+ $async?: boolean;
240
253
  };
241
254
  type ValibotPathItemLike = {
242
255
  key?: unknown;
@@ -264,10 +277,13 @@ type ArkTypeProblemLike = {
264
277
  };
265
278
  type ArkTypeErrorsLike = ReadonlyArray<ArkTypeProblemLike> & {
266
279
  summary?: string;
280
+ readonly arkKind?: string;
281
+ readonly ' arkKind'?: string;
267
282
  };
268
283
  type ArkTypeLike<T = unknown> = {
269
- (value: unknown): T | ArkTypeErrorsLike;
284
+ (value: unknown): T | ArkTypeErrorsLike | Promise<T | ArkTypeErrorsLike>;
270
285
  errors?: unknown;
286
+ readonly '~standard'?: StandardSchemaV1['~standard'];
271
287
  };
272
288
  type IoTsContextEntryLike = {
273
289
  key: string;
@@ -299,6 +315,9 @@ type VineValidationMessageLike = {
299
315
  index?: number;
300
316
  };
301
317
  type VineValidationErrorLike = {
318
+ name?: string;
319
+ code?: string;
320
+ status?: number;
302
321
  messages: ReadonlyArray<VineValidationMessageLike>;
303
322
  };
304
323
  type VineValidatorLike<T = unknown> = {
@@ -430,6 +449,8 @@ interface RequestComplexityOptions {
430
449
  maxSubQueryCount?: number;
431
450
  maxBulkConcurrency?: number;
432
451
  maxHookConcurrency?: number;
452
+ maxCorrelatedQueries?: number;
453
+ maxCorrelatedDepth?: number;
433
454
  }
434
455
 
435
456
  declare class RequestConcurrencyScheduler {
@@ -440,6 +461,10 @@ declare class RequestConcurrencyScheduler {
440
461
  }
441
462
 
442
463
  type CrossResourceModelOperation = 'list' | 'read' | 'count';
464
+ interface CorrelatedExecState {
465
+ totalQueries: number;
466
+ scheduler: RequestConcurrencyScheduler;
467
+ }
443
468
  declare class Base<TModel = unknown> {
444
469
  protected req: ModelRequest;
445
470
  protected modelName: string;
@@ -476,9 +501,11 @@ declare class Base<TModel = unknown> {
476
501
  protected throwClientRequestError(code: ErrorResult['code'], detail: string): never;
477
502
  protected getAuthorizedTargetService(modelName: string, op: CrossResourceModelOperation): Promise<PublicService<unknown>>;
478
503
  protected processInclude(include: Include | Include[]): {
479
- includes: Include[];
504
+ includes: LegacyInclude[];
505
+ correlatedIncludes: CorrelatedInclude[];
480
506
  includeLocalFields: string[];
481
507
  includePaths: string[];
508
+ correlatedReferenceFields: string[];
482
509
  };
483
510
  private getForeignKeyValues;
484
511
  private getForeignKey;
@@ -491,6 +518,13 @@ declare class Base<TModel = unknown> {
491
518
  private includeDocsRead;
492
519
  private includeDocsList;
493
520
  private includeDocsCount;
521
+ protected getCorrelatedExecState(): CorrelatedExecState;
522
+ protected claimCorrelatedQuerySlot(): void;
523
+ private sanitizeCorrelatedArgs;
524
+ protected includeCorrelatedDocs<TDoc>(docs: TDoc[], correlatedIncludes: CorrelatedInclude[], snapshots?: unknown[], depth?: number): Promise<TDoc[]>;
525
+ private includeCorrelatedRead;
526
+ private includeCorrelatedList;
527
+ private includeCorrelatedCount;
494
528
  protected parseClientData<TValue>(filter: TValue, scheduler?: RequestConcurrencyScheduler, scheduled?: boolean): Promise<TValue>;
495
529
  private handleSubQuery;
496
530
  private handleDate;
@@ -526,6 +560,7 @@ type InternalModelHookContext = ModelHookContext & {
526
560
  declare class Core {
527
561
  private req;
528
562
  private caches;
563
+ private cachedPermissions;
529
564
  constructor(req: AccessRouterBaseRequest);
530
565
  getIdentifier(modelName: string): string;
531
566
  genIDFilter<TModel = unknown>(modelName: string, id: string): Promise<Filter<TModel>>;
@@ -565,6 +600,7 @@ declare class Core {
565
600
  declare class DataCore {
566
601
  private req;
567
602
  private caches;
603
+ private cachedPermissions;
568
604
  constructor(req: AccessRouterBaseRequest);
569
605
  genIDFilter<TData = unknown>(dataName: string, id: string): Promise<Filter<TData>>;
570
606
  genFilter<TData = unknown>(dataName: string, access?: BaseFilterAccess, _filter?: Filter<TData>): Promise<Filter<TData>>;
@@ -789,10 +825,11 @@ type PopulateEntryShape<T, TPath extends string, TValue> = TPath extends `${infe
789
825
  type PopulateOutputShape<T, TPopulateEntry> = PopulatePath<TPopulateEntry> extends infer TPath extends string ? PopulateEntryShape<T, TPath, PopulateLeafValue<PathValue<WithDefaultId<T>, TPath>, TPopulateEntry>> : {};
790
826
  type PopulateOutput<T, TPopulate> = string extends PopulatePath<PopulateInputs<TPopulate>> ? {} : [PopulatePath<PopulateInputs<TPopulate>>] extends [never] ? {} : Simplify<UnionToIntersection<PopulateOutputShape<T, Extract<PopulateInputs<TPopulate>, PopulateInput>>>>;
791
827
  type SelectedPopulatedPublicOutput<T, TProjection, TPopulate> = Simplify<SelectedPublicOutput<T, TProjection> & PopulateOutput<T, TPopulate>>;
792
- type DeepFieldPath<T, Depth extends number = 4> = [Depth] extends [never] ? never : Descend<T> extends NonTraversable ? never : {
793
- [K in Extract<keyof Descend<T>, string>]: K | (Descend<T>[K] extends NonTraversable ? never : Descend<T>[K] extends readonly (infer U)[] ? U extends NonTraversable ? never : `${K}.${DeepFieldPath<U, PrevDepth[Depth]>}` : Descend<T>[K] extends object ? `${K}.${DeepFieldPath<Descend<T>[K], PrevDepth[Depth]>}` : never);
794
- }[Extract<keyof Descend<T>, string>];
795
- type PathValue<T, TPath extends string> = TPath extends `${infer Head}.${infer Tail}` ? Head extends Extract<keyof Descend<T>, string> ? PathValue<Descend<Descend<T>[Head]>, Tail> : unknown : TPath extends Extract<keyof Descend<T>, string> ? Descend<T>[TPath] : unknown;
828
+ type Unwrap<T> = NonNullable<Descend<T>>;
829
+ type DeepFieldPath<T, Depth extends number = 4> = [Depth] extends [never] ? never : Unwrap<T> extends NonTraversable ? never : {
830
+ [K in Extract<keyof Unwrap<T>, string>]: K | (NonNullable<Unwrap<T>[K]> extends NonTraversable ? never : NonNullable<Unwrap<T>[K]> extends readonly (infer U)[] ? Unwrap<U> extends NonTraversable ? never : `${K}.${DeepFieldPath<U, PrevDepth[Depth]>}` : NonNullable<Unwrap<T>[K]> extends object ? `${K}.${DeepFieldPath<NonNullable<Unwrap<T>[K]>, PrevDepth[Depth]>}` : never);
831
+ }[Extract<keyof Unwrap<T>, string>];
832
+ type PathValue<T, TPath extends string> = TPath extends `${infer Head}.${infer Tail}` ? Head extends Extract<keyof Unwrap<T>, string> ? PathValue<Unwrap<Unwrap<T>[Head]>, Tail> : unknown : TPath extends Extract<keyof Unwrap<T>, string> ? Unwrap<T>[TPath] : unknown;
796
833
  type FieldFilterOperators<T> = {
797
834
  $eq?: T;
798
835
  $ne?: T;
@@ -824,7 +861,8 @@ type TypedFilterObject<T> = {
824
861
  };
825
862
  type TypedFilter<T> = false | TypedFilterObject<WithDefaultId<T>>;
826
863
  type Filter<T = unknown> = IsUnknown<T> extends true ? LooseFilter : TypedFilter<T>;
827
- interface Include {
864
+ interface LegacyInclude {
865
+ mode?: 'legacy';
828
866
  model: string;
829
867
  op: 'list' | 'read' | 'count';
830
868
  path: string;
@@ -834,6 +872,56 @@ interface Include {
834
872
  args?: unknown;
835
873
  options?: unknown;
836
874
  }
875
+ /**
876
+ * Explicit structural marker referencing a field of the immediate parent
877
+ * document (ACI-01 D2.1). Recognized only in filter/id value positions of
878
+ * correlated includes; magic `$field` strings are never markers.
879
+ */
880
+ interface ParentRef {
881
+ $parent: string;
882
+ }
883
+ /** Filter template for correlated includes; values may carry {@link ParentRef} markers. */
884
+ type CorrelatedFilter = Record<string, unknown>;
885
+ interface CorrelatedIncludeArgs {
886
+ select?: Projection;
887
+ sort?: Sort;
888
+ skip?: number | string;
889
+ limit?: number | string;
890
+ page?: number | string;
891
+ pageSize?: number | string;
892
+ include?: Include | Include[];
893
+ }
894
+ interface CorrelatedIncludeBase {
895
+ mode: 'correlated';
896
+ model: string;
897
+ op: 'list' | 'read' | 'count';
898
+ path: string;
899
+ args?: CorrelatedIncludeArgs;
900
+ options?: Record<string, never>;
901
+ }
902
+ /** Identifier read: exactly one of `id` / `filter` must be present. */
903
+ interface CorrelatedReadByIdInclude extends CorrelatedIncludeBase {
904
+ op: 'read';
905
+ id: string | ParentRef;
906
+ filter?: never;
907
+ }
908
+ interface CorrelatedReadByFilterInclude extends CorrelatedIncludeBase {
909
+ op: 'read';
910
+ filter: CorrelatedFilter;
911
+ id?: never;
912
+ }
913
+ interface CorrelatedListInclude extends CorrelatedIncludeBase {
914
+ op: 'list';
915
+ filter: CorrelatedFilter;
916
+ id?: never;
917
+ }
918
+ interface CorrelatedCountInclude extends CorrelatedIncludeBase {
919
+ op: 'count';
920
+ filter: CorrelatedFilter;
921
+ id?: never;
922
+ }
923
+ type CorrelatedInclude = CorrelatedReadByIdInclude | CorrelatedReadByFilterInclude | CorrelatedListInclude | CorrelatedCountInclude;
924
+ type Include = LegacyInclude | CorrelatedInclude;
837
925
  type FindAccess = 'list' | 'read';
838
926
  type PopulateAccess = 'list' | 'read';
839
927
  interface Populate {
@@ -1041,10 +1129,11 @@ interface SubQueryEntry {
1041
1129
  compact?: boolean;
1042
1130
  };
1043
1131
  }
1132
+ type TaskType = 'COPY_AND_DEPOPULATE' | 'COPY' | 'MOVE' | 'SLICE' | 'COUNT' | 'MASK' | string;
1044
1133
  interface Task {
1045
- type: string;
1134
+ type: TaskType;
1046
1135
  args: unknown;
1047
- options: Record<string, unknown>;
1136
+ options?: Record<string, unknown>;
1048
1137
  }
1049
1138
  interface AccessRouterBaseRequest extends AccessRouterRequest {
1050
1139
  query: Record<'skip' | 'limit' | 'page' | 'page_size' | 'try_list' | 'skim' | 'include_permissions' | 'include_count' | 'include_extra_headers' | 'returning_all', string>;
@@ -1402,24 +1491,24 @@ interface ExtendedModelRouterOptions<TModel = unknown> extends ModelRouterOption
1402
1491
  'overrideFilter.read'?: ModelOverrideFilterHook;
1403
1492
  'overrideFilter.update'?: ModelOverrideFilterHook;
1404
1493
  'overrideFilter.delete'?: ModelOverrideFilterHook;
1405
- 'decorate.default'?: ModelHook;
1406
- 'decorate.list'?: ModelHook;
1407
- 'decorate.create'?: ModelHook;
1408
- 'decorate.read'?: ModelHook;
1409
- 'decorate.update'?: ModelHook;
1410
- 'decorateAll.default'?: ModelListHook;
1411
- 'decorateAll.list'?: ModelListHook;
1494
+ 'decorate.default'?: ModelHook<TModel>;
1495
+ 'decorate.list'?: ModelHook<TModel>;
1496
+ 'decorate.create'?: ModelHook<TModel>;
1497
+ 'decorate.read'?: ModelHook<TModel>;
1498
+ 'decorate.update'?: ModelHook<TModel>;
1499
+ 'decorateAll.default'?: ModelListHook<TModel>;
1500
+ 'decorateAll.list'?: ModelListHook<TModel>;
1412
1501
  'validate.default'?: ValidateRule | ModelValidateHook;
1413
1502
  'validate.create'?: ValidateRule | ModelValidateHook;
1414
1503
  'validate.update'?: ValidateRule | ModelValidateHook;
1415
- 'prepare.default'?: ModelHook;
1416
- 'prepare.create'?: ModelHook;
1417
- 'prepare.update'?: ModelHook;
1418
- 'transform.default'?: ModelDocumentHook;
1419
- 'transform.update'?: ModelDocumentHook;
1420
- 'afterPersist.default'?: ModelDocumentHook;
1421
- 'afterPersist.create'?: ModelDocumentHook;
1422
- 'afterPersist.update'?: ModelDocumentHook;
1504
+ 'prepare.default'?: ModelHook<TModel>;
1505
+ 'prepare.create'?: ModelHook<TModel>;
1506
+ 'prepare.update'?: ModelHook<TModel>;
1507
+ 'transform.default'?: ModelDocumentHook<TModel>;
1508
+ 'transform.update'?: ModelDocumentHook<TModel>;
1509
+ 'afterPersist.default'?: ModelDocumentHook<TModel>;
1510
+ 'afterPersist.create'?: ModelDocumentHook<TModel>;
1511
+ 'afterPersist.update'?: ModelDocumentHook<TModel>;
1423
1512
  onChange?: Record<string, ModelChangeHook>;
1424
1513
  'requestSchemas.create'?: RequestSchema;
1425
1514
  'requestSchemas.update'?: RequestSchema;
@@ -1515,6 +1604,11 @@ declare function defineRequestSchema<T = unknown>(validator: RequestSchemaValida
1515
1604
  /**
1516
1605
  * Adapts a Zod schema into a `RequestSchemaValidator` for `access-router`.
1517
1606
  *
1607
+ * Supports both synchronous schemas and schemas with async refinements or
1608
+ * transforms via `safeParseAsync` when available. Synchronous schemas keep
1609
+ * their existing output values and issue paths. Operational exceptions thrown
1610
+ * by `safeParseAsync` itself propagate unchanged.
1611
+ *
1518
1612
  * @example
1519
1613
  * const validator = fromZod(z.object({ name: z.string() }));
1520
1614
  */
@@ -1522,11 +1616,37 @@ declare function fromZod<TSchema extends z.ZodTypeAny>(schema: TSchema): Request
1522
1616
  declare function fromStandardSchema<TSchema extends StandardSchemaV1>(schema: TSchema): RequestSchemaValidator<StandardSchemaInferOutput<TSchema>>;
1523
1617
  declare function fromYup<TSchema extends YupSchemaLike>(schema: TSchema): RequestSchemaValidator;
1524
1618
  declare function fromJoi<TSchema extends JoiSchemaLike>(schema: TSchema): RequestSchemaValidator;
1619
+ /**
1620
+ * Adapts an AJV validator into a `RequestSchemaValidator`.
1621
+ *
1622
+ * Contract: synchronous validators return a boolean and expose input-local
1623
+ * diagnostics via mutable `validator.errors`; those errors are snapshotted
1624
+ * synchronously before any suspension so concurrent same-turn validations do
1625
+ * not observe another input's diagnostics. Asynchronous AJV schemas
1626
+ * (`$async: true`) return a promise that resolves with validated data on
1627
+ * success or rejects with a `ValidationError` carrying an `errors` array on
1628
+ * failure; rejection-carried errors are normalized, while any other rejection
1629
+ * propagates unchanged as an operational exception.
1630
+ */
1525
1631
  declare function fromAjv<TValue = unknown>(validator: AjvValidatorLike<TValue>): RequestSchemaValidator<TValue>;
1526
1632
  declare function fromValibot<TSchema, TOutput = unknown>(schema: TSchema, safeParse: ValibotSafeParseLike): RequestSchemaValidator<TOutput>;
1633
+ /**
1634
+ * Adapts an ArkType type into a `RequestSchemaValidator`.
1635
+ *
1636
+ * Success/failure is discriminated via the supported ArkErrors brand key
1637
+ * (`hasArkKind(result, "errors")`, stored at runtime as `' arkKind'` with a
1638
+ * leading space; the unspaced `arkKind` alias is also accepted) or, when the
1639
+ * type exposes a Standard Schema `~standard.validate` contract, via that
1640
+ * contract. ArkType's Standard Schema `validate` returns `{ value }` on
1641
+ * success but returns raw `ArkErrors` on failure instead of `{ issues }`, so
1642
+ * both shapes are handled. Array shape and `message`/`path`-like record
1643
+ * fields are never used as discriminators, so valid empty/scalar/record/
1644
+ * nullable arrays pass through unchanged. Unexpected exceptions thrown by the
1645
+ * type propagate unchanged.
1646
+ */
1527
1647
  declare function fromArkType<TValue = unknown>(type: ArkTypeLike<TValue>): RequestSchemaValidator<TValue>;
1528
1648
  declare function fromIoTs<TValue = unknown>(decoder: IoTsDecoderLike<TValue>): RequestSchemaValidator<TValue>;
1529
1649
  declare function fromSuperstruct<TStruct, TOutput = unknown>(struct: TStruct, validate: SuperstructValidateLike): RequestSchemaValidator<TOutput>;
1530
1650
  declare function fromVine<TValue = unknown>(validator: VineValidatorLike<TValue>): RequestSchemaValidator<TValue>;
1531
1651
 
1532
- export { type Filter as $, type AccessRouterBaseRequest as A, type BaseFilterAccess as B, type Change as C, DATA_MIDDLEWARE as D, type DataFindOneOptions as E, type DataFindOptions as F, type DataHook as G, type DataHookContext as H, type DataIdentifierHook as I, type DataListHook as J, type DataOverrideFilterHook as K, type DataRequest as L, type DataRequestSchemas as M, type DataRouterOptions as N, type DecorateAccess as O, type DecorateAllAccess as P, type DeepFieldPath as Q, type DefaultModelRouterOptions as R, type Defaults as S, type DistinctArgs as T, type DistinctBody as U, type DocPermissionsAccess as V, type ErrorResult as W, type ExistsOptions as X, type ExtendedDataRouterOptions as Y, type ExtendedDefaultModelRouterOptions as Z, type ExtendedModelRouterOptions as _, type AccessRouterFieldKey as a, type RequestSchemaFailure as a$, FilterOperator as a0, type FindAccess as a1, type FindArgs as a2, type FindByIdArgs as a3, type FindByIdOptions as a4, type FindOneArgs as a5, type FindOneOptions as a6, type FindOptions as a7, type GlobalOptions as a8, type GlobalPermissionValue as a9, type ModelValidateHook as aA, PERMISSIONS as aB, PERMISSION_KEYS as aC, type PathValue as aD, type PermissionSchema as aE, type Populate as aF, type PopulateAccess as aG, type PrepareAccess as aH, type Projection as aI, type PublicCreateArgs as aJ, type PublicCreateOptions as aK, type PublicErrorResult as aL, type PublicListArgs as aM, type PublicListOptions as aN, type PublicListResult as aO, type PublicOutput as aP, type PublicReadArgs as aQ, type PublicReadOptions as aR, type PublicServiceResult as aS, type PublicSingleResult as aT, type PublicUpdateArgs as aU, type PublicUpdateOptions as aV, type PublicUpsertArgs as aW, type PublicUpsertOptions as aX, type ReadQueryInput as aY, type Request as aZ, type RequestSchemaAdapter as a_, type GuardHook as aa, type IdentifierHook as ab, type Include as ac, type IoTsContextEntryLike as ad, type IoTsDecodeErrorLike as ae, type IoTsDecoderLike as af, type JoiSchemaLike as ag, type JoiValidationErrorDetailLike as ah, type KeyValueProjection as ai, type ListQueryInput as aj, type ListResult as ak, MIDDLEWARE as al, type MaybePromise as am, type ModelBaseFilterHook as an, type ModelChangeHook as ao, type ModelDeleteHook as ap, type ModelDocPermissionsHook as aq, type ModelDocument as ar, type ModelDocumentHook as as, type ModelHook as at, type ModelHookContext as au, type ModelIdentifierHook as av, type ModelListHook as aw, type ModelOverrideFilterHook as ax, type ModelRequest as ay, type ModelRouterOptions as az, type AccessRouterLogger as b, type SubdocumentRecord as b$, type RequestSchemaIssue as b0, type RequestSchemaLike as b1, type RequestSchemaOptions as b2, type RequestSchemaResult as b3, type RequestSchemaSuccess as b4, type RequestSchemaValidator as b5, type RequestSchemas as b6, type RootDataListQueryEntry as b7, type RootDataOperation as b8, type RootDataReadByFilterQueryEntry as b9, type SelectedPublicOutput as bA, type ServiceResult as bB, type SingleResult as bC, type Sort as bD, type SortOrder as bE, type StandardSchemaFailure as bF, type StandardSchemaInferOutput as bG, type StandardSchemaIssue as bH, type StandardSchemaPathSegment as bI, type StandardSchemaResult as bJ, type StandardSchemaSuccess as bK, type StandardSchemaV1 as bL, StatusCodes as bM, type SubListBody as bN, type SubPopulate as bO, type SubQueryEntry as bP, type SubReadBody as bQ, type SubdocumentBulkRecord as bR, type SubdocumentBulkUpdateInput as bS, type SubdocumentCreateInput as bT, type SubdocumentCreateOptions as bU, type SubdocumentId as bV, type SubdocumentListOptions as bW, type SubdocumentName as bX, type SubdocumentParentArgs as bY, type SubdocumentParentOptions as bZ, type SubdocumentReadOptions as b_, type RootDataReadByIdQueryEntry as ba, type RootModelCountQueryEntry as bb, type RootModelCreateQueryEntry as bc, type RootModelDeleteQueryEntry as bd, type RootModelDistinctQueryEntry as be, type RootModelListQueryEntry as bf, type RootModelNewQueryEntry as bg, type RootModelOperation as bh, type RootModelReadByFilterQueryEntry as bi, type RootModelReadByIdQueryEntry as bj, type RootModelSubBulkUpdateQueryEntry as bk, type RootModelSubCreateQueryEntry as bl, type RootModelSubDeleteQueryEntry as bm, type RootModelSubListQueryEntry as bn, type RootModelSubReadQueryEntry as bo, type RootModelSubUpdateQueryEntry as bp, type RootModelUpdateQueryEntry as bq, type RootModelUpsertQueryEntry as br, type RootOperationResult as bs, type RootQueryEntry as bt, type RootRouterOptions as bu, type RootSubOperation as bv, type RootTarget as bw, type RouteGuardAccess as bx, type SelectAccess as by, type SelectedPopulatedPublicOutput as bz, type AccessRouterRequest as c, type SuperstructFailureLike as c0, type SuperstructValidateLike as c1, type Task as c2, type TransformAccess as c3, type TypedFilter as c4, type UpdateByIdArgs as c5, type UpdateByIdOptions as c6, type UpdateOneArgs as c7, type UpdateOneOptions as c8, type UpdateQueryInput as c9, fromZod as cA, parseBody as cB, parseBodyWithSchema as cC, parseNestedBodyWithSchema as cD, parsePathParam as cE, parseQuery as cF, DataService as cG, Service as cH, PublicService as cI, type AccessRouterPermissionMap as cJ, type AccessRouterPermissions as cK, type Permissions as cL, type UpsertArgs as ca, type UpsertOptions as cb, type UpsertQueryInput as cc, type ValibotIssueLike as cd, type ValibotPathItemLike as ce, type ValibotSafeParseLike as cf, type ValibotSafeParseResult as cg, type ValidateAccess as ch, type ValidateRule as ci, type Validation as cj, type ValidationError as ck, type VineValidationErrorLike as cl, type VineValidationMessageLike as cm, type VineValidatorLike as cn, type YupSchemaLike as co, type YupValidationErrorLike as cp, defineRequestSchema as cq, fromAjv as cr, fromArkType as cs, fromIoTs as ct, fromJoi as cu, fromStandardSchema as cv, fromSuperstruct as cw, fromValibot as cx, fromVine as cy, fromYup as cz, type AccessRouterRequestExtensions as d, type AdvancedCreateBody as e, type AdvancedListBody as f, type AdvancedReadBody as g, type AdvancedReadFilterBody as h, type AdvancedUpdateBody as i, type AdvancedUpsertBody as j, type AfterPersistAccess as k, type AjvErrorObjectLike as l, type AjvValidatorLike as m, type ArkTypeErrorsLike as n, type ArkTypeLike as o, type ArkTypeProblemLike as p, Codes as q, type CountBody as r, type CreateArgs as s, type CreateOptions as t, type CreateQueryInput as u, CustomHeaders as v, type DataBaseFilterHook as w, type DataFilter as x, type DataFindArgs as y, type DataFindOneArgs as z };
1652
+ export { type DistinctArgs as $, type AccessRouterBaseRequest as A, type BaseFilterAccess as B, type Change as C, type CreateArgs as D, type CreateOptions as E, type CreateQueryInput as F, CustomHeaders as G, DATA_MIDDLEWARE as H, type DataBaseFilterHook as I, type DataFilter as J, type DataFindArgs as K, type DataFindOneArgs as L, type DataFindOneOptions as M, type DataFindOptions as N, type DataHook as O, type DataHookContext as P, type DataIdentifierHook as Q, type DataListHook as R, type DataOverrideFilterHook as S, type DataRequest as T, type DataRequestSchemas as U, type DataRouterOptions as V, type DecorateAccess as W, type DecorateAllAccess as X, type DeepFieldPath as Y, type DefaultModelRouterOptions as Z, type Defaults as _, type AccessRouterFieldKey as a, type PublicReadOptions as a$, type DistinctBody as a0, type DocPermissionsAccess as a1, type ErrorResult as a2, type ExistsOptions as a3, type ExtendedDataRouterOptions as a4, type ExtendedDefaultModelRouterOptions as a5, type ExtendedModelRouterOptions as a6, type Filter as a7, FilterOperator as a8, type FindAccess as a9, type ModelDocument as aA, type ModelDocumentHook as aB, type ModelHook as aC, type ModelHookContext as aD, type ModelIdentifierHook as aE, type ModelListHook as aF, type ModelOverrideFilterHook as aG, type ModelRequest as aH, type ModelRouterOptions as aI, type ModelValidateHook as aJ, PERMISSIONS as aK, PERMISSION_KEYS as aL, type ParentRef as aM, type PathValue as aN, type PermissionSchema as aO, type Populate as aP, type PopulateAccess as aQ, type PrepareAccess as aR, type Projection as aS, type PublicCreateArgs as aT, type PublicCreateOptions as aU, type PublicErrorResult as aV, type PublicListArgs as aW, type PublicListOptions as aX, type PublicListResult as aY, type PublicOutput as aZ, type PublicReadArgs as a_, type FindArgs as aa, type FindByIdArgs as ab, type FindByIdOptions as ac, type FindOneArgs as ad, type FindOneOptions as ae, type FindOptions as af, type GlobalOptions as ag, type GlobalPermissionValue as ah, type GuardHook as ai, type IdentifierHook as aj, type Include as ak, type IoTsContextEntryLike as al, type IoTsDecodeErrorLike as am, type IoTsDecoderLike as an, type JoiSchemaLike as ao, type JoiValidationErrorDetailLike as ap, type KeyValueProjection as aq, type LegacyInclude as ar, type ListQueryInput as as, type ListResult as at, MIDDLEWARE as au, type MaybePromise as av, type ModelBaseFilterHook as aw, type ModelChangeHook as ax, type ModelDeleteHook as ay, type ModelDocPermissionsHook as az, type AccessRouterLogger as b, type SubdocumentBulkRecord as b$, type PublicServiceResult as b0, type PublicSingleResult as b1, type PublicUpdateArgs as b2, type PublicUpdateOptions as b3, type PublicUpsertArgs as b4, type PublicUpsertOptions as b5, type ReadQueryInput as b6, type Request as b7, type RequestSchemaAdapter as b8, type RequestSchemaFailure as b9, type RootModelUpdateQueryEntry as bA, type RootModelUpsertQueryEntry as bB, type RootOperationResult as bC, type RootQueryEntry as bD, type RootRouterOptions as bE, type RootSubOperation as bF, type RootTarget as bG, type RouteGuardAccess as bH, type SelectAccess as bI, type SelectedPopulatedPublicOutput as bJ, type SelectedPublicOutput as bK, type ServiceResult as bL, type SingleResult as bM, type Sort as bN, type SortOrder as bO, type StandardSchemaFailure as bP, type StandardSchemaInferOutput as bQ, type StandardSchemaIssue as bR, type StandardSchemaPathSegment as bS, type StandardSchemaResult as bT, type StandardSchemaSuccess as bU, type StandardSchemaV1 as bV, StatusCodes as bW, type SubListBody as bX, type SubPopulate as bY, type SubQueryEntry as bZ, type SubReadBody as b_, type RequestSchemaIssue as ba, type RequestSchemaLike as bb, type RequestSchemaOptions as bc, type RequestSchemaResult as bd, type RequestSchemaSuccess as be, type RequestSchemaValidator as bf, type RequestSchemas as bg, type RootDataListQueryEntry as bh, type RootDataOperation as bi, type RootDataReadByFilterQueryEntry as bj, type RootDataReadByIdQueryEntry as bk, type RootModelCountQueryEntry as bl, type RootModelCreateQueryEntry as bm, type RootModelDeleteQueryEntry as bn, type RootModelDistinctQueryEntry as bo, type RootModelListQueryEntry as bp, type RootModelNewQueryEntry as bq, type RootModelOperation as br, type RootModelReadByFilterQueryEntry as bs, type RootModelReadByIdQueryEntry as bt, type RootModelSubBulkUpdateQueryEntry as bu, type RootModelSubCreateQueryEntry as bv, type RootModelSubDeleteQueryEntry as bw, type RootModelSubListQueryEntry as bx, type RootModelSubReadQueryEntry as by, type RootModelSubUpdateQueryEntry as bz, type AccessRouterRequest as c, type SubdocumentBulkUpdateInput as c0, type SubdocumentCreateInput as c1, type SubdocumentCreateOptions as c2, type SubdocumentId as c3, type SubdocumentListOptions as c4, type SubdocumentName as c5, type SubdocumentParentArgs as c6, type SubdocumentParentOptions as c7, type SubdocumentReadOptions as c8, type SubdocumentRecord as c9, type YupValidationErrorLike as cA, defineRequestSchema as cB, fromAjv as cC, fromArkType as cD, fromIoTs as cE, fromJoi as cF, fromStandardSchema as cG, fromSuperstruct as cH, fromValibot as cI, fromVine as cJ, fromYup as cK, fromZod as cL, parseBody as cM, parseBodyWithSchema as cN, parseNestedBodyWithSchema as cO, parsePathParam as cP, parseQuery as cQ, DataService as cR, Service as cS, PublicService as cT, type AccessRouterPermissionMap as cU, type AccessRouterPermissions as cV, type Permissions as cW, type SuperstructFailureLike as ca, type SuperstructValidateLike as cb, type Task as cc, type TaskType as cd, type TransformAccess as ce, type TypedFilter as cf, type UpdateByIdArgs as cg, type UpdateByIdOptions as ch, type UpdateOneArgs as ci, type UpdateOneOptions as cj, type UpdateQueryInput as ck, type UpsertArgs as cl, type UpsertOptions as cm, type UpsertQueryInput as cn, type ValibotIssueLike as co, type ValibotPathItemLike as cp, type ValibotSafeParseLike as cq, type ValibotSafeParseResult as cr, type ValidateAccess as cs, type ValidateRule as ct, type Validation as cu, type ValidationError as cv, type VineValidationErrorLike as cw, type VineValidationMessageLike as cx, type VineValidatorLike as cy, type YupSchemaLike as cz, type AccessRouterRequestExtensions as d, type AdvancedCreateBody as e, type AdvancedListBody as f, type AdvancedReadBody as g, type AdvancedReadFilterBody as h, type AdvancedUpdateBody as i, type AdvancedUpsertBody as j, type AfterPersistAccess as k, type AjvErrorObjectLike as l, type AjvValidationErrorLike as m, type AjvValidatorLike as n, type ArkTypeErrorsLike as o, type ArkTypeLike as p, type ArkTypeProblemLike as q, Codes as r, type CorrelatedCountInclude as s, type CorrelatedFilter as t, type CorrelatedInclude as u, type CorrelatedIncludeArgs as v, type CorrelatedListInclude as w, type CorrelatedReadByFilterInclude as x, type CorrelatedReadByIdInclude as y, type CountBody as z };
package/processors.d.mts CHANGED
@@ -47,6 +47,97 @@ interface CopyAndDepopulateOptions {
47
47
  */
48
48
  idField?: string;
49
49
  }
50
+ /**
51
+ * A path copy operation consumed by {@link copyPaths} and the `COPY` task.
52
+ * Reuses the same `{ src, dest }` shape as {@link ProcessCopy}.
53
+ */
54
+ type ProcessPathCopy = ProcessCopy;
55
+ /**
56
+ * A path move operation consumed by {@link movePaths} and the `MOVE` task.
57
+ * Reuses the same `{ src, dest }` shape as {@link ProcessCopy}.
58
+ */
59
+ type ProcessPathMove = ProcessCopy;
60
+ /**
61
+ * A slice operation consumed by {@link sliceArrays} and the `SLICE` task.
62
+ */
63
+ interface ProcessSlice {
64
+ /**
65
+ * Dotted source path of the array to slice. Intermediate segments fan out
66
+ * across arrays like {@link copyAndDepopulate}. Missing, null, or
67
+ * non-array leaves are safe no-ops.
68
+ */
69
+ src: string;
70
+ /**
71
+ * Dotted destination path (relative to the leaf parent) where the sliced
72
+ * window is written. When omitted, the slice is applied in place at `src`.
73
+ * Empty-string destinations are safe no-ops.
74
+ */
75
+ dest?: string;
76
+ /**
77
+ * Number of leading array members to skip. Defaults to `0`. Must be a
78
+ * non-negative safe integer when present.
79
+ */
80
+ skip?: number;
81
+ /**
82
+ * Maximum number of array members to keep from `skip`. When omitted, the
83
+ * tail from `skip` to the end is kept. When present it is clamped to
84
+ * `maxSlice` (default `1000`). Must be a non-negative safe integer.
85
+ */
86
+ limit?: number;
87
+ }
88
+ /**
89
+ * A count operation consumed by {@link countPaths} and the `COUNT` task.
90
+ */
91
+ interface ProcessCount {
92
+ /**
93
+ * Dotted source path whose size is measured. Arrays measure length, plain
94
+ * objects measure key count, present scalars count as `1`, and
95
+ * null/undefined leaves count as `0`. Missing leaves are safe no-ops.
96
+ */
97
+ src: string;
98
+ /**
99
+ * Dotted destination path (relative to the leaf parent) where the numeric
100
+ * count is written. Empty destinations are safe no-ops.
101
+ */
102
+ dest: string;
103
+ }
104
+ /**
105
+ * A mask operation consumed by {@link maskPaths} and the `MASK` task.
106
+ */
107
+ interface ProcessMask {
108
+ /**
109
+ * Dotted source path to redact. Each resolved leaf present on its parent
110
+ * is replaced with `replacement`. Missing leaves are safe no-ops.
111
+ */
112
+ src: string;
113
+ /**
114
+ * Replacement value written at `src`. Defaults to `'***'` when the key is
115
+ * absent. An explicitly provided value (including `null`) is used as-is.
116
+ */
117
+ replacement?: unknown;
118
+ }
119
+ /**
120
+ * Shared mutable/clone option for path processors.
121
+ */
122
+ interface ProcessorOptions {
123
+ /**
124
+ * When `true` (default), `docObject` is mutated in place and returned.
125
+ * When `false`, a deep clone is produced via `cloneDeep` and the input is
126
+ * left untouched.
127
+ */
128
+ mutable?: boolean;
129
+ }
130
+ /**
131
+ * Options for {@link sliceArrays}.
132
+ */
133
+ interface SliceProcessorOptions extends ProcessorOptions {
134
+ /**
135
+ * Upper bound applied to a client-requested `limit`. Defaults to `1000`,
136
+ * matching the `listHardLimit` default. Must be a non-negative safe
137
+ * integer when present.
138
+ */
139
+ maxSlice?: number;
140
+ }
50
141
  /**
51
142
  * Conservative default output for {@link copyAndDepopulate}.
52
143
  *
@@ -90,5 +181,64 @@ type CopyAndDepopulateOutput = Record<string, unknown>;
90
181
  * `constructor`, or when a populated record is missing the configured id field.
91
182
  */
92
183
  declare const copyAndDepopulate: <Output extends object = CopyAndDepopulateOutput>(docObject: object, operations: ProcessCopy[], options?: CopyAndDepopulateOptions) => Output;
184
+ /**
185
+ * Conservative default output for path processors.
186
+ */
187
+ type ProcessorOutput = Record<string, unknown>;
188
+ /**
189
+ * Copy the value at `src` to `dest` without modifying `src`.
190
+ *
191
+ * Semantics mirror {@link copyAndDepopulate} traversal: intermediate segments
192
+ * fan out across arrays, missing/null/scalar intermediates are safe no-ops,
193
+ * and unsafe (`__proto__`, `prototype`, `constructor`) or empty paths are
194
+ * handled the same way. The copied value is deep-cloned so later tasks in
195
+ * the chain cannot alias `src` through `dest`. Copying a path onto itself
196
+ * is a safe no-op.
197
+ *
198
+ * @throws Error when a path contains an unsafe segment.
199
+ */
200
+ declare const copyPaths: <Output extends object = ProcessorOutput>(docObject: object, operations: ProcessCopy[], options?: ProcessorOptions) => Output;
201
+ /**
202
+ * Move the value at `src` to `dest` and delete `src`.
203
+ *
204
+ * Traversal and safety semantics match {@link copyPaths}. Moving a path onto
205
+ * itself is a safe no-op. A `dest` nested under the moved leaf (for example
206
+ * `src: 'a'`, `dest: 'a.b'`) copies without deleting `src` so the freshly
207
+ * written destination is not removed.
208
+ *
209
+ * @throws Error when a path contains an unsafe segment.
210
+ */
211
+ declare const movePaths: <Output extends object = ProcessorOutput>(docObject: object, operations: ProcessCopy[], options?: ProcessorOptions) => Output;
212
+ /**
213
+ * Slice the array at `src` to `[skip, skip + limit)` and write the window to
214
+ * `dest` (default: in place at `src`).
215
+ *
216
+ * Missing, null, or non-array leaves are safe no-ops. `skip` defaults to `0`;
217
+ * an omitted `limit` keeps the tail from `skip`. A present `limit` is clamped
218
+ * to `maxSlice` (default `1000`) so client-requested windows stay bounded.
219
+ *
220
+ * @throws Error when a path contains an unsafe segment or when
221
+ * `skip`/`limit`/`maxSlice` is not a non-negative safe integer.
222
+ */
223
+ declare const sliceArrays: <Output extends object = ProcessorOutput>(docObject: object, operations: ProcessSlice[], options?: SliceProcessorOptions) => Output;
224
+ /**
225
+ * Write the size of `src` to `dest`: array length, plain-object key count,
226
+ * `0` for null/undefined leaves, and `1` for other present scalars.
227
+ *
228
+ * Missing leaves are safe no-ops (no destination is created).
229
+ *
230
+ * @throws Error when a path contains an unsafe segment.
231
+ */
232
+ declare const countPaths: <Output extends object = ProcessorOutput>(docObject: object, operations: ProcessCount[], options?: ProcessorOptions) => Output;
233
+ /**
234
+ * Replace the value at `src` with `replacement` (default `'***'`).
235
+ *
236
+ * Only existing leaves are redacted; missing paths are safe no-ops and no
237
+ * new keys are created. Intermediate segments fan out across arrays like
238
+ * {@link copyAndDepopulate}.
239
+ *
240
+ * @throws Error when a path contains an unsafe segment.
241
+ */
242
+ declare const maskPaths: <Output extends object = ProcessorOutput>(docObject: object, operations: ProcessMask[], options?: ProcessorOptions) => Output;
93
243
 
94
- export { type CopyAndDepopulateOptions, type CopyAndDepopulateOutput, type ProcessCopy, copyAndDepopulate };
244
+ export { type CopyAndDepopulateOptions, type CopyAndDepopulateOutput, type ProcessCopy, type ProcessCount, type ProcessMask, type ProcessPathCopy, type ProcessPathMove, type ProcessSlice, type ProcessorOptions, type ProcessorOutput, type SliceProcessorOptions, copyAndDepopulate, copyPaths, countPaths, maskPaths, movePaths, sliceArrays };