@web-ts-toolkit/access-router 0.43.0 → 0.44.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 +20 -0
- package/advanced.d.mts +1 -1
- package/advanced.d.ts +1 -1
- package/advanced.js +156 -24
- package/advanced.mjs +156 -24
- package/index.d.mts +18 -10
- package/index.d.ts +18 -10
- package/index.js +254 -68
- package/index.mjs +254 -68
- package/llms.txt +3 -0
- package/package.json +18 -6
- package/{parsers-PMWujHUV.d.mts → parsers-B5dbVmjm.d.mts} +68 -22
- package/{parsers-PMWujHUV.d.ts → parsers-B5dbVmjm.d.ts} +68 -22
- package/processors.js +5 -2
- package/processors.mjs +5 -2
package/README.md
CHANGED
|
@@ -104,6 +104,17 @@ snapshots. Mutating the original options object, a fetched options snapshot, or
|
|
|
104
104
|
not change live runtime policy or served in-memory records. Replace configured data through `router.data(next)`
|
|
105
105
|
or `setDataOption(name, 'data', next)`.
|
|
106
106
|
|
|
107
|
+
ACL filter hooks may return `false` to deny a query. That denial is terminal through identifier, override, and
|
|
108
|
+
base-filter composition. `overrideFilter` is a trusted hook that may replace an ordinary client or identifier
|
|
109
|
+
filter before the base filter is applied, but it is not called for an existing `false` filter and cannot revive
|
|
110
|
+
that denial. Returning `false` from `overrideFilter` also denies the query. Empty or absent filters retain their
|
|
111
|
+
normal unrestricted meaning unless a base filter restricts them.
|
|
112
|
+
|
|
113
|
+
Advanced mutation validators drive dispatch: nested `data` validators run first, then the whole-body (`default`)
|
|
114
|
+
validator sees that transformed envelope, and the service persists only the final parsed `data`, `select`,
|
|
115
|
+
`populate`, `tasks`, and allowed `options`. Missing body options fall back to `returning_all`/`include_permissions`
|
|
116
|
+
query params; only `includePermissions`/`populateAccess` (plus `returningAll` for update/upsert) are forwarded.
|
|
117
|
+
|
|
107
118
|
## Main Exports
|
|
108
119
|
|
|
109
120
|
Root entrypoint (`@web-ts-toolkit/access-router`):
|
|
@@ -152,6 +163,15 @@ to `runtime.createRouter(model, options)` or call `runtime.registerModelInstance
|
|
|
152
163
|
string-name router. The default `acl` runtime retains string-name compatibility with `mongoose.model(name, schema)` and
|
|
153
164
|
adopts that exact global model instance into its registry on first lookup.
|
|
154
165
|
|
|
166
|
+
Cross-runtime composition on a shared request keeps independent runtime-owned state. When one request passes through
|
|
167
|
+
middleware from runtime A and then runtime B, B initializes its own core, resolves its own `globalPermissions`, and
|
|
168
|
+
uses its own base-filter cache; it never reuses A's permissions or cached filters, even when both runtimes use the
|
|
169
|
+
same `requestPermissionField` name. Repeating the same runtime's middleware on one request reuses that runtime's state
|
|
170
|
+
without rerunning its resolver. Values already present in `requestPermissionField` before any runtime middleware runs
|
|
171
|
+
are treated as application-supplied and preserved. Migration: if you relied on B silently inheriting A's resolved
|
|
172
|
+
permissions on a shared request, set those permissions explicitly before the chain or configure B's `globalPermissions`
|
|
173
|
+
to resolve them.
|
|
174
|
+
|
|
155
175
|
## createRouter overloads
|
|
156
176
|
|
|
157
177
|
`createRouter(modelName, options)` — on the default `acl` runtime, accept the Mongoose model name registered with `mongoose.model(name, schema)`. On isolated runtimes, the name must already be registered with that runtime.
|
package/advanced.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AccessRouterBaseRequest, a as AccessRouterFieldKey, b as AccessRouterLogger, c as AccessRouterRequest, d as AccessRouterRequestExtensions, e as AdvancedCreateBody, f as AdvancedListBody, g as AdvancedReadBody, h as AdvancedReadFilterBody, i as AdvancedUpdateBody, j as AdvancedUpsertBody, k as AfterPersistAccess, l as AjvErrorObjectLike, m as
|
|
1
|
+
export { A as AccessRouterBaseRequest, a as AccessRouterFieldKey, b as AccessRouterLogger, c as AccessRouterRequest, d as AccessRouterRequestExtensions, e as AdvancedCreateBody, f as AdvancedListBody, g as AdvancedReadBody, h as AdvancedReadFilterBody, i as AdvancedUpdateBody, j as AdvancedUpsertBody, k as AfterPersistAccess, l as AjvErrorObjectLike, m as AjvValidationErrorLike, n as AjvValidatorLike, o as ArkTypeErrorsLike, p as ArkTypeLike, q as ArkTypeProblemLike, B as BaseFilterAccess, C as Change, r as Codes, s as CountBody, t as CreateArgs, u as CreateOptions, v as CreateQueryInput, w as CustomHeaders, D as DATA_MIDDLEWARE, x as DataBaseFilterHook, y as DataFilter, z as DataFindArgs, E as DataFindOneArgs, F as DataFindOneOptions, G as DataFindOptions, H as DataHook, I as DataHookContext, J as DataIdentifierHook, K as DataListHook, L as DataOverrideFilterHook, M as DataRequest, N as DataRequestSchemas, O as DataRouterOptions, P as DecorateAccess, Q as DecorateAllAccess, R as DeepFieldPath, S as DefaultModelRouterOptions, T as Defaults, U as DistinctArgs, V as DistinctBody, W as DocPermissionsAccess, X as ErrorResult, Y as ExistsOptions, Z as ExtendedDataRouterOptions, _ as ExtendedDefaultModelRouterOptions, $ as ExtendedModelRouterOptions, a0 as Filter, a1 as FilterOperator, a2 as FindAccess, a3 as FindArgs, a4 as FindByIdArgs, a5 as FindByIdOptions, a6 as FindOneArgs, a7 as FindOneOptions, a8 as FindOptions, a9 as GlobalOptions, aa as GlobalPermissionValue, ab as GuardHook, ac as IdentifierHook, ad as Include, ae as IoTsContextEntryLike, af as IoTsDecodeErrorLike, ag as IoTsDecoderLike, ah as JoiSchemaLike, ai as JoiValidationErrorDetailLike, aj as KeyValueProjection, ak as ListQueryInput, al as ListResult, am as MIDDLEWARE, an as MaybePromise, ao as ModelBaseFilterHook, ap as ModelChangeHook, aq as ModelDeleteHook, ar as ModelDocPermissionsHook, as as ModelDocument, at as ModelDocumentHook, au as ModelHook, av as ModelHookContext, aw as ModelIdentifierHook, ax as ModelListHook, ay as ModelOverrideFilterHook, az as ModelRequest, aA as ModelRouterOptions, aB as ModelValidateHook, aC as PERMISSIONS, aD as PERMISSION_KEYS, aE as PathValue, aF as PermissionSchema, aG as Populate, aH as PopulateAccess, aI as PrepareAccess, aJ as Projection, aK as PublicCreateArgs, aL as PublicCreateOptions, aM as PublicErrorResult, aN as PublicListArgs, aO as PublicListOptions, aP as PublicListResult, aQ as PublicOutput, aR as PublicReadArgs, aS as PublicReadOptions, aT as PublicServiceResult, aU as PublicSingleResult, aV as PublicUpdateArgs, aW as PublicUpdateOptions, aX as PublicUpsertArgs, aY as PublicUpsertOptions, aZ as ReadQueryInput, a_ as Request, a$ as RequestSchemaAdapter, b0 as RequestSchemaFailure, b1 as RequestSchemaIssue, b2 as RequestSchemaLike, b3 as RequestSchemaOptions, b4 as RequestSchemaResult, b5 as RequestSchemaSuccess, b6 as RequestSchemaValidator, b7 as RequestSchemas, b8 as RootDataListQueryEntry, b9 as RootDataOperation, ba as RootDataReadByFilterQueryEntry, bb as RootDataReadByIdQueryEntry, bc as RootModelCountQueryEntry, bd as RootModelCreateQueryEntry, be as RootModelDeleteQueryEntry, bf as RootModelDistinctQueryEntry, bg as RootModelListQueryEntry, bh as RootModelNewQueryEntry, bi as RootModelOperation, bj as RootModelReadByFilterQueryEntry, bk as RootModelReadByIdQueryEntry, bl as RootModelSubBulkUpdateQueryEntry, bm as RootModelSubCreateQueryEntry, bn as RootModelSubDeleteQueryEntry, bo as RootModelSubListQueryEntry, bp as RootModelSubReadQueryEntry, bq as RootModelSubUpdateQueryEntry, br as RootModelUpdateQueryEntry, bs as RootModelUpsertQueryEntry, bt as RootOperationResult, bu as RootQueryEntry, bv as RootRouterOptions, bw as RootSubOperation, bx as RootTarget, by as RouteGuardAccess, bz as SelectAccess, bA as SelectedPopulatedPublicOutput, bB as SelectedPublicOutput, bC as ServiceResult, bD as SingleResult, bE as Sort, bF as SortOrder, bG as StandardSchemaFailure, bH as StandardSchemaInferOutput, bI as StandardSchemaIssue, bJ as StandardSchemaPathSegment, bK as StandardSchemaResult, bL as StandardSchemaSuccess, bM as StandardSchemaV1, bN as StatusCodes, bO as SubListBody, bP as SubPopulate, bQ as SubQueryEntry, bR as SubReadBody, bS as SubdocumentBulkRecord, bT as SubdocumentBulkUpdateInput, bU as SubdocumentCreateInput, bV as SubdocumentCreateOptions, bW as SubdocumentId, bX as SubdocumentListOptions, bY as SubdocumentName, bZ as SubdocumentParentArgs, b_ as SubdocumentParentOptions, b$ as SubdocumentReadOptions, c0 as SubdocumentRecord, c1 as SuperstructFailureLike, c2 as SuperstructValidateLike, c3 as Task, c4 as TransformAccess, c5 as TypedFilter, c6 as UpdateByIdArgs, c7 as UpdateByIdOptions, c8 as UpdateOneArgs, c9 as UpdateOneOptions, ca as UpdateQueryInput, cb as UpsertArgs, cc as UpsertOptions, cd as UpsertQueryInput, ce as ValibotIssueLike, cf as ValibotPathItemLike, cg as ValibotSafeParseLike, ch as ValibotSafeParseResult, ci as ValidateAccess, cj as ValidateRule, ck as Validation, cl as ValidationError, cm as VineValidationErrorLike, cn as VineValidationMessageLike, co as VineValidatorLike, cp as YupSchemaLike, cq as YupValidationErrorLike, cr as defineRequestSchema, cs as fromAjv, ct as fromArkType, cu as fromIoTs, cv as fromJoi, cw as fromStandardSchema, cx as fromSuperstruct, cy as fromValibot, cz as fromVine, cA as fromYup, cB as fromZod, cC as parseBody, cD as parseBodyWithSchema, cE as parseNestedBodyWithSchema, cF as parsePathParam, cG as parseQuery } from './parsers-B5dbVmjm.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import 'mongoose';
|
|
4
4
|
import 'express';
|
package/advanced.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AccessRouterBaseRequest, a as AccessRouterFieldKey, b as AccessRouterLogger, c as AccessRouterRequest, d as AccessRouterRequestExtensions, e as AdvancedCreateBody, f as AdvancedListBody, g as AdvancedReadBody, h as AdvancedReadFilterBody, i as AdvancedUpdateBody, j as AdvancedUpsertBody, k as AfterPersistAccess, l as AjvErrorObjectLike, m as
|
|
1
|
+
export { A as AccessRouterBaseRequest, a as AccessRouterFieldKey, b as AccessRouterLogger, c as AccessRouterRequest, d as AccessRouterRequestExtensions, e as AdvancedCreateBody, f as AdvancedListBody, g as AdvancedReadBody, h as AdvancedReadFilterBody, i as AdvancedUpdateBody, j as AdvancedUpsertBody, k as AfterPersistAccess, l as AjvErrorObjectLike, m as AjvValidationErrorLike, n as AjvValidatorLike, o as ArkTypeErrorsLike, p as ArkTypeLike, q as ArkTypeProblemLike, B as BaseFilterAccess, C as Change, r as Codes, s as CountBody, t as CreateArgs, u as CreateOptions, v as CreateQueryInput, w as CustomHeaders, D as DATA_MIDDLEWARE, x as DataBaseFilterHook, y as DataFilter, z as DataFindArgs, E as DataFindOneArgs, F as DataFindOneOptions, G as DataFindOptions, H as DataHook, I as DataHookContext, J as DataIdentifierHook, K as DataListHook, L as DataOverrideFilterHook, M as DataRequest, N as DataRequestSchemas, O as DataRouterOptions, P as DecorateAccess, Q as DecorateAllAccess, R as DeepFieldPath, S as DefaultModelRouterOptions, T as Defaults, U as DistinctArgs, V as DistinctBody, W as DocPermissionsAccess, X as ErrorResult, Y as ExistsOptions, Z as ExtendedDataRouterOptions, _ as ExtendedDefaultModelRouterOptions, $ as ExtendedModelRouterOptions, a0 as Filter, a1 as FilterOperator, a2 as FindAccess, a3 as FindArgs, a4 as FindByIdArgs, a5 as FindByIdOptions, a6 as FindOneArgs, a7 as FindOneOptions, a8 as FindOptions, a9 as GlobalOptions, aa as GlobalPermissionValue, ab as GuardHook, ac as IdentifierHook, ad as Include, ae as IoTsContextEntryLike, af as IoTsDecodeErrorLike, ag as IoTsDecoderLike, ah as JoiSchemaLike, ai as JoiValidationErrorDetailLike, aj as KeyValueProjection, ak as ListQueryInput, al as ListResult, am as MIDDLEWARE, an as MaybePromise, ao as ModelBaseFilterHook, ap as ModelChangeHook, aq as ModelDeleteHook, ar as ModelDocPermissionsHook, as as ModelDocument, at as ModelDocumentHook, au as ModelHook, av as ModelHookContext, aw as ModelIdentifierHook, ax as ModelListHook, ay as ModelOverrideFilterHook, az as ModelRequest, aA as ModelRouterOptions, aB as ModelValidateHook, aC as PERMISSIONS, aD as PERMISSION_KEYS, aE as PathValue, aF as PermissionSchema, aG as Populate, aH as PopulateAccess, aI as PrepareAccess, aJ as Projection, aK as PublicCreateArgs, aL as PublicCreateOptions, aM as PublicErrorResult, aN as PublicListArgs, aO as PublicListOptions, aP as PublicListResult, aQ as PublicOutput, aR as PublicReadArgs, aS as PublicReadOptions, aT as PublicServiceResult, aU as PublicSingleResult, aV as PublicUpdateArgs, aW as PublicUpdateOptions, aX as PublicUpsertArgs, aY as PublicUpsertOptions, aZ as ReadQueryInput, a_ as Request, a$ as RequestSchemaAdapter, b0 as RequestSchemaFailure, b1 as RequestSchemaIssue, b2 as RequestSchemaLike, b3 as RequestSchemaOptions, b4 as RequestSchemaResult, b5 as RequestSchemaSuccess, b6 as RequestSchemaValidator, b7 as RequestSchemas, b8 as RootDataListQueryEntry, b9 as RootDataOperation, ba as RootDataReadByFilterQueryEntry, bb as RootDataReadByIdQueryEntry, bc as RootModelCountQueryEntry, bd as RootModelCreateQueryEntry, be as RootModelDeleteQueryEntry, bf as RootModelDistinctQueryEntry, bg as RootModelListQueryEntry, bh as RootModelNewQueryEntry, bi as RootModelOperation, bj as RootModelReadByFilterQueryEntry, bk as RootModelReadByIdQueryEntry, bl as RootModelSubBulkUpdateQueryEntry, bm as RootModelSubCreateQueryEntry, bn as RootModelSubDeleteQueryEntry, bo as RootModelSubListQueryEntry, bp as RootModelSubReadQueryEntry, bq as RootModelSubUpdateQueryEntry, br as RootModelUpdateQueryEntry, bs as RootModelUpsertQueryEntry, bt as RootOperationResult, bu as RootQueryEntry, bv as RootRouterOptions, bw as RootSubOperation, bx as RootTarget, by as RouteGuardAccess, bz as SelectAccess, bA as SelectedPopulatedPublicOutput, bB as SelectedPublicOutput, bC as ServiceResult, bD as SingleResult, bE as Sort, bF as SortOrder, bG as StandardSchemaFailure, bH as StandardSchemaInferOutput, bI as StandardSchemaIssue, bJ as StandardSchemaPathSegment, bK as StandardSchemaResult, bL as StandardSchemaSuccess, bM as StandardSchemaV1, bN as StatusCodes, bO as SubListBody, bP as SubPopulate, bQ as SubQueryEntry, bR as SubReadBody, bS as SubdocumentBulkRecord, bT as SubdocumentBulkUpdateInput, bU as SubdocumentCreateInput, bV as SubdocumentCreateOptions, bW as SubdocumentId, bX as SubdocumentListOptions, bY as SubdocumentName, bZ as SubdocumentParentArgs, b_ as SubdocumentParentOptions, b$ as SubdocumentReadOptions, c0 as SubdocumentRecord, c1 as SuperstructFailureLike, c2 as SuperstructValidateLike, c3 as Task, c4 as TransformAccess, c5 as TypedFilter, c6 as UpdateByIdArgs, c7 as UpdateByIdOptions, c8 as UpdateOneArgs, c9 as UpdateOneOptions, ca as UpdateQueryInput, cb as UpsertArgs, cc as UpsertOptions, cd as UpsertQueryInput, ce as ValibotIssueLike, cf as ValibotPathItemLike, cg as ValibotSafeParseLike, ch as ValibotSafeParseResult, ci as ValidateAccess, cj as ValidateRule, ck as Validation, cl as ValidationError, cm as VineValidationErrorLike, cn as VineValidationMessageLike, co as VineValidatorLike, cp as YupSchemaLike, cq as YupValidationErrorLike, cr as defineRequestSchema, cs as fromAjv, ct as fromArkType, cu as fromIoTs, cv as fromJoi, cw as fromStandardSchema, cx as fromSuperstruct, cy as fromValibot, cz as fromVine, cA as fromYup, cB as fromZod, cC as parseBody, cD as parseBodyWithSchema, cE as parseNestedBodyWithSchema, cF as parsePathParam, cG as parseQuery } from './parsers-B5dbVmjm.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import 'mongoose';
|
|
4
4
|
import 'express';
|
package/advanced.js
CHANGED
|
@@ -557,6 +557,29 @@ var cloneConfigValue = (value) => {
|
|
|
557
557
|
])
|
|
558
558
|
);
|
|
559
559
|
};
|
|
560
|
+
var cloneForRead = (value) => {
|
|
561
|
+
if (Array.isArray(value)) {
|
|
562
|
+
if (Object.isFrozen(value)) {
|
|
563
|
+
return value;
|
|
564
|
+
}
|
|
565
|
+
return value.map((item) => cloneForRead(item));
|
|
566
|
+
}
|
|
567
|
+
if (!value || typeof value !== "object") {
|
|
568
|
+
return value;
|
|
569
|
+
}
|
|
570
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) {
|
|
571
|
+
return value;
|
|
572
|
+
}
|
|
573
|
+
if (Object.isFrozen(value)) {
|
|
574
|
+
return value;
|
|
575
|
+
}
|
|
576
|
+
return Object.fromEntries(
|
|
577
|
+
Object.entries(value).map(([entryKey, entryValue]) => [
|
|
578
|
+
entryKey,
|
|
579
|
+
cloneForRead(entryValue)
|
|
580
|
+
])
|
|
581
|
+
);
|
|
582
|
+
};
|
|
560
583
|
var freezeConfigValue = (value) => {
|
|
561
584
|
if (!value || typeof value !== "object") {
|
|
562
585
|
return value;
|
|
@@ -572,6 +595,7 @@ var freezeConfigValue = (value) => {
|
|
|
572
595
|
}
|
|
573
596
|
return value;
|
|
574
597
|
};
|
|
598
|
+
var cloneAndFreezeForStore = (value) => freezeConfigValue(cloneForRead(value));
|
|
575
599
|
var getNestedOption = (manager, key, defaultValue) => {
|
|
576
600
|
const keys2 = String(key).split(".");
|
|
577
601
|
if (keys2.length === 1) {
|
|
@@ -601,6 +625,14 @@ var OptionsManager = class {
|
|
|
601
625
|
target[keystr] = value;
|
|
602
626
|
_this.listeners[keystr] && _this.listeners[keystr].call(_this, value, keystr, target, oldvalue);
|
|
603
627
|
return true;
|
|
628
|
+
},
|
|
629
|
+
defineProperty(target, key, descriptor) {
|
|
630
|
+
const keystr = String(key);
|
|
631
|
+
const oldvalue = target[keystr];
|
|
632
|
+
const result = Reflect.defineProperty(target, key, descriptor);
|
|
633
|
+
const newValue = target[keystr];
|
|
634
|
+
_this.listeners[keystr] && _this.listeners[keystr].call(_this, newValue, keystr, target, oldvalue);
|
|
635
|
+
return result;
|
|
604
636
|
}
|
|
605
637
|
});
|
|
606
638
|
}
|
|
@@ -614,18 +646,18 @@ var OptionsManager = class {
|
|
|
614
646
|
set(key, value) {
|
|
615
647
|
const path = toPath(key);
|
|
616
648
|
if (path.length <= 1) {
|
|
617
|
-
(0, import_utils6.set)(this.currentOptions, path, this.preserveKeys.has(String(path[0])) ? value :
|
|
649
|
+
(0, import_utils6.set)(this.currentOptions, path, this.preserveKeys.has(String(path[0])) ? value : cloneAndFreezeForStore(value));
|
|
618
650
|
return;
|
|
619
651
|
}
|
|
620
652
|
const [rootKey, ...nestedPath] = path;
|
|
621
653
|
const currentRoot = (0, import_utils6.get)(this.currentOptions, [rootKey], void 0);
|
|
622
654
|
const baseRoot = (0, import_utils6.isPlainObject)(currentRoot) ? currentRoot : {};
|
|
623
655
|
const nextRoot = cloneConfigValue(baseRoot);
|
|
624
|
-
(0, import_utils6.set)(nextRoot, nestedPath,
|
|
625
|
-
(0, import_utils6.set)(this.currentOptions, [rootKey], nextRoot);
|
|
656
|
+
(0, import_utils6.set)(nextRoot, nestedPath, cloneForRead(value));
|
|
657
|
+
(0, import_utils6.set)(this.currentOptions, [rootKey], freezeConfigValue(nextRoot));
|
|
626
658
|
}
|
|
627
659
|
fetch() {
|
|
628
|
-
const cloned =
|
|
660
|
+
const cloned = cloneForRead(this.currentOptions);
|
|
629
661
|
for (const key of this.preserveKeys) {
|
|
630
662
|
if (key in this.currentOptions) {
|
|
631
663
|
cloned[key] = this.currentOptions[key];
|
|
@@ -634,20 +666,20 @@ var OptionsManager = class {
|
|
|
634
666
|
return freezeConfigValue(cloned);
|
|
635
667
|
}
|
|
636
668
|
assign(options) {
|
|
637
|
-
const cloned =
|
|
669
|
+
const cloned = cloneForRead(options);
|
|
638
670
|
for (const key of this.preserveKeys) {
|
|
639
671
|
if (key in options) {
|
|
640
672
|
cloned[key] = options[key];
|
|
641
673
|
}
|
|
642
674
|
}
|
|
643
|
-
(0, import_utils6.assign)(this.currentOptions, cloned);
|
|
675
|
+
(0, import_utils6.assign)(this.currentOptions, freezeConfigValue(cloned));
|
|
644
676
|
}
|
|
645
677
|
onchange(key, func) {
|
|
646
678
|
(0, import_utils6.set)(this.listeners, key, func);
|
|
647
679
|
return this;
|
|
648
680
|
}
|
|
649
681
|
snapshot() {
|
|
650
|
-
const cloned =
|
|
682
|
+
const cloned = cloneForRead(this.currentOptions);
|
|
651
683
|
for (const key of this.preserveKeys) {
|
|
652
684
|
if (key in this.currentOptions) {
|
|
653
685
|
cloned[key] = this.currentOptions[key];
|
|
@@ -663,13 +695,13 @@ var OptionsManager = class {
|
|
|
663
695
|
delete current[key];
|
|
664
696
|
}
|
|
665
697
|
}
|
|
666
|
-
const cloned =
|
|
698
|
+
const cloned = cloneForRead(snap);
|
|
667
699
|
for (const key of this.preserveKeys) {
|
|
668
700
|
if (key in snap) {
|
|
669
701
|
cloned[key] = snap[key];
|
|
670
702
|
}
|
|
671
703
|
}
|
|
672
|
-
(0, import_utils6.assign)(current, cloned);
|
|
704
|
+
(0, import_utils6.assign)(current, freezeConfigValue(cloned));
|
|
673
705
|
}
|
|
674
706
|
};
|
|
675
707
|
|
|
@@ -1139,8 +1171,7 @@ var AccessRuntime = class {
|
|
|
1139
1171
|
}
|
|
1140
1172
|
setDataOptions(dataName, options) {
|
|
1141
1173
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
1142
|
-
|
|
1143
|
-
manager.assign({ ...currentDataOptions, ...options });
|
|
1174
|
+
manager.assign(options);
|
|
1144
1175
|
}
|
|
1145
1176
|
setDataOption(dataName, key, value) {
|
|
1146
1177
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
@@ -1150,6 +1181,11 @@ var AccessRuntime = class {
|
|
|
1150
1181
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
1151
1182
|
return manager.fetch();
|
|
1152
1183
|
}
|
|
1184
|
+
getDataSnapshot(dataName) {
|
|
1185
|
+
const manager = this.getOrCreateDataOptions(dataName);
|
|
1186
|
+
const snapshot = manager.get("data");
|
|
1187
|
+
return snapshot ?? [];
|
|
1188
|
+
}
|
|
1153
1189
|
getDataOption(dataName, key, defaultValue) {
|
|
1154
1190
|
const manager = this.getOrCreateDataOptions(dataName);
|
|
1155
1191
|
return getNestedOption(manager, key, defaultValue);
|
|
@@ -1395,8 +1431,9 @@ function defineRequestSchema(validator, options = {}) {
|
|
|
1395
1431
|
};
|
|
1396
1432
|
}
|
|
1397
1433
|
function fromZod(schema) {
|
|
1398
|
-
return (value) => {
|
|
1399
|
-
const
|
|
1434
|
+
return async (value) => {
|
|
1435
|
+
const candidate = schema;
|
|
1436
|
+
const result = typeof candidate.safeParseAsync === "function" ? await candidate.safeParseAsync.call(schema, value) : schema.safeParse(value);
|
|
1400
1437
|
if (result.success) {
|
|
1401
1438
|
return {
|
|
1402
1439
|
success: true,
|
|
@@ -1433,6 +1470,9 @@ function fromYup(schema) {
|
|
|
1433
1470
|
data
|
|
1434
1471
|
};
|
|
1435
1472
|
} catch (error) {
|
|
1473
|
+
if (!isYupValidationError(error)) {
|
|
1474
|
+
throw error;
|
|
1475
|
+
}
|
|
1436
1476
|
return {
|
|
1437
1477
|
success: false,
|
|
1438
1478
|
issues: normalizeYupIssues(error)
|
|
@@ -1457,8 +1497,32 @@ function fromJoi(schema) {
|
|
|
1457
1497
|
}
|
|
1458
1498
|
function fromAjv(validator) {
|
|
1459
1499
|
return async (value) => {
|
|
1460
|
-
const
|
|
1461
|
-
if (
|
|
1500
|
+
const outcome = validator(value);
|
|
1501
|
+
if (isThenable(outcome)) {
|
|
1502
|
+
try {
|
|
1503
|
+
const data = await outcome;
|
|
1504
|
+
if (data === false) {
|
|
1505
|
+
return {
|
|
1506
|
+
success: false,
|
|
1507
|
+
issues: normalizeAjvIssues(validator.errors ?? [])
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
return {
|
|
1511
|
+
success: true,
|
|
1512
|
+
data: data === true ? value : data
|
|
1513
|
+
};
|
|
1514
|
+
} catch (error) {
|
|
1515
|
+
if (!isAjvValidationError(error)) {
|
|
1516
|
+
throw error;
|
|
1517
|
+
}
|
|
1518
|
+
return {
|
|
1519
|
+
success: false,
|
|
1520
|
+
issues: normalizeAjvIssues(error.errors ?? [])
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
const errorsSnapshot = validator.errors ? [...validator.errors] : [];
|
|
1525
|
+
if (outcome) {
|
|
1462
1526
|
return {
|
|
1463
1527
|
success: true,
|
|
1464
1528
|
data: value
|
|
@@ -1466,7 +1530,7 @@ function fromAjv(validator) {
|
|
|
1466
1530
|
}
|
|
1467
1531
|
return {
|
|
1468
1532
|
success: false,
|
|
1469
|
-
issues: normalizeAjvIssues(
|
|
1533
|
+
issues: normalizeAjvIssues(errorsSnapshot)
|
|
1470
1534
|
};
|
|
1471
1535
|
};
|
|
1472
1536
|
}
|
|
@@ -1487,6 +1551,25 @@ function fromValibot(schema, safeParse) {
|
|
|
1487
1551
|
}
|
|
1488
1552
|
function fromArkType(type) {
|
|
1489
1553
|
return async (value) => {
|
|
1554
|
+
if (isStandardSchema(type)) {
|
|
1555
|
+
const result2 = await type["~standard"].validate(value);
|
|
1556
|
+
if (isArkTypeErrors(result2)) {
|
|
1557
|
+
return {
|
|
1558
|
+
success: false,
|
|
1559
|
+
issues: normalizeArkTypeIssues(result2)
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
if (isStandardSchemaFailure(result2)) {
|
|
1563
|
+
return {
|
|
1564
|
+
success: false,
|
|
1565
|
+
issues: normalizeArkTypeStandardIssues(result2.issues)
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
return {
|
|
1569
|
+
success: true,
|
|
1570
|
+
data: result2.value
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1490
1573
|
const result = await type(value);
|
|
1491
1574
|
if (!isArkTypeErrors(result)) {
|
|
1492
1575
|
return {
|
|
@@ -1539,6 +1622,9 @@ function fromVine(validator) {
|
|
|
1539
1622
|
data: output
|
|
1540
1623
|
};
|
|
1541
1624
|
} catch (error) {
|
|
1625
|
+
if (!isVineValidationError(error)) {
|
|
1626
|
+
throw error;
|
|
1627
|
+
}
|
|
1542
1628
|
return {
|
|
1543
1629
|
success: false,
|
|
1544
1630
|
issues: normalizeVineError(error)
|
|
@@ -1599,6 +1685,13 @@ function normalizeArkTypeIssues(issues) {
|
|
|
1599
1685
|
}));
|
|
1600
1686
|
return normalized.length ? normalized : [{ message: issues.summary ?? "Validation failed" }];
|
|
1601
1687
|
}
|
|
1688
|
+
function normalizeArkTypeStandardIssues(issues) {
|
|
1689
|
+
const normalized = issues.map((issue) => ({
|
|
1690
|
+
message: issue.message ?? issue.problem ?? "Validation failed",
|
|
1691
|
+
path: issue.path?.flatMap((segment) => normalizePathSegment(segment))
|
|
1692
|
+
}));
|
|
1693
|
+
return normalized.length ? normalized : [{ message: "Validation failed" }];
|
|
1694
|
+
}
|
|
1602
1695
|
function normalizeIoTsIssues(issues) {
|
|
1603
1696
|
return issues.map((issue) => ({
|
|
1604
1697
|
message: issue.message ?? "Validation failed",
|
|
@@ -1633,25 +1726,64 @@ function normalizeVineField(message) {
|
|
|
1633
1726
|
}
|
|
1634
1727
|
return path.length ? path : void 0;
|
|
1635
1728
|
}
|
|
1729
|
+
function decodeAjvSegment(segment) {
|
|
1730
|
+
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1731
|
+
}
|
|
1732
|
+
function encodePointerSegment(segment) {
|
|
1733
|
+
return encodeURIComponent(segment.replace(/~/g, "~0").replace(/\//g, "~1"));
|
|
1734
|
+
}
|
|
1636
1735
|
function parseAjvPath(issue) {
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1639
|
-
|
|
1736
|
+
const raw = issue.instancePath;
|
|
1737
|
+
const base = raw == null || raw === "" ? [] : (raw.startsWith("/") ? raw.slice(1) : raw).split("/").map(decodeAjvSegment);
|
|
1738
|
+
const missing = issue.params?.missingProperty;
|
|
1739
|
+
if (typeof missing === "string") {
|
|
1740
|
+
return [...base, missing];
|
|
1640
1741
|
}
|
|
1641
|
-
return
|
|
1742
|
+
return base;
|
|
1642
1743
|
}
|
|
1643
1744
|
function parsePathString(path) {
|
|
1644
1745
|
if (!path) return void 0;
|
|
1645
1746
|
return path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
|
|
1646
1747
|
}
|
|
1647
1748
|
function isYupValidationError(error) {
|
|
1648
|
-
|
|
1749
|
+
if (typeof error !== "object" || error === null || !("message" in error)) {
|
|
1750
|
+
return false;
|
|
1751
|
+
}
|
|
1752
|
+
const candidate = error;
|
|
1753
|
+
return candidate.name === "ValidationError" && typeof candidate.message === "string" && Array.isArray(candidate.errors) && Array.isArray(candidate.inner);
|
|
1649
1754
|
}
|
|
1650
1755
|
function isArkTypeErrors(value) {
|
|
1651
|
-
|
|
1756
|
+
if (typeof value !== "object" || value === null) {
|
|
1757
|
+
return false;
|
|
1758
|
+
}
|
|
1759
|
+
const record = value;
|
|
1760
|
+
return record.arkKind === "errors" || record[" arkKind"] === "errors";
|
|
1761
|
+
}
|
|
1762
|
+
function isThenable(value) {
|
|
1763
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
1764
|
+
}
|
|
1765
|
+
function isAjvValidationError(error) {
|
|
1766
|
+
if (typeof error !== "object" || error === null || !("errors" in error)) {
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1769
|
+
const errors = error.errors;
|
|
1770
|
+
return errors == null || Array.isArray(errors);
|
|
1652
1771
|
}
|
|
1653
1772
|
function isVineValidationError(error) {
|
|
1654
|
-
|
|
1773
|
+
if (typeof error !== "object" || error === null || !("messages" in error)) {
|
|
1774
|
+
return false;
|
|
1775
|
+
}
|
|
1776
|
+
const candidate = error;
|
|
1777
|
+
if (!Array.isArray(candidate.messages) || candidate.messages.length === 0) {
|
|
1778
|
+
return false;
|
|
1779
|
+
}
|
|
1780
|
+
const hasDiscriminator = candidate.code === "E_VALIDATION_ERROR" || candidate.name === "ValidationError";
|
|
1781
|
+
if (!hasDiscriminator) {
|
|
1782
|
+
return false;
|
|
1783
|
+
}
|
|
1784
|
+
return candidate.messages.every(
|
|
1785
|
+
(message) => typeof message === "object" && message !== null && typeof message.message === "string" && typeof message.field === "string"
|
|
1786
|
+
);
|
|
1655
1787
|
}
|
|
1656
1788
|
function formatIssue(issue, key, location = "pointer") {
|
|
1657
1789
|
const path = (issue.path ?? []).map(String);
|
|
@@ -1668,7 +1800,7 @@ function formatIssue(issue, key, location = "pointer") {
|
|
|
1668
1800
|
};
|
|
1669
1801
|
}
|
|
1670
1802
|
function buildPointer(path) {
|
|
1671
|
-
return path.length === 0 ? "#" : `#/${path.join("/")}`;
|
|
1803
|
+
return path.length === 0 ? "#" : `#/${path.map(encodePointerSegment).join("/")}`;
|
|
1672
1804
|
}
|
|
1673
1805
|
|
|
1674
1806
|
// src/validation/model-router.ts
|