@web-ts-toolkit/access-router 0.3.0 → 0.4.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/index.mjs CHANGED
@@ -3204,7 +3204,7 @@ var clientErrors = JsonRouter4.clientErrors;
3204
3204
  function parsePathParam(value, parameter) {
3205
3205
  const result = stringOrStringArray.safeParse(value);
3206
3206
  if (!result.success) {
3207
- throwValidationError(result.error.issues, parameter, "parameter");
3207
+ throwValidationError(normalizeIssues(result.error.issues), parameter, "parameter");
3208
3208
  }
3209
3209
  const param = Array.isArray(result.data) ? result.data[0] : result.data;
3210
3210
  if (!param) {
@@ -3217,49 +3217,333 @@ function parsePathParam(value, parameter) {
3217
3217
  function parseQuery(schema, value) {
3218
3218
  const result = schema.safeParse(value);
3219
3219
  if (!result.success) {
3220
- throwValidationError(result.error.issues, void 0, "parameter");
3220
+ throwValidationError(normalizeIssues(result.error.issues), void 0, "parameter");
3221
3221
  }
3222
3222
  return result.data;
3223
3223
  }
3224
3224
  function parseBody(schema, value) {
3225
3225
  const result = schema.safeParse(value ?? {});
3226
3226
  if (!result.success) {
3227
- throwValidationError(result.error.issues, void 0, "pointer");
3227
+ throwValidationError(normalizeIssues(result.error.issues), void 0, "pointer");
3228
3228
  }
3229
3229
  return result.data;
3230
3230
  }
3231
3231
  function parseBodyWithSchema(schema, value, userSchema) {
3232
3232
  const body = parseBody(schema, value);
3233
- return isZodSchema(userSchema) ? parseUserSchema(userSchema, body) : body;
3233
+ return isRequestSchema(userSchema) ? parseUserSchema(userSchema, body) : Promise.resolve(body);
3234
3234
  }
3235
- function parseNestedBodyWithSchema(schema, value, nestedKey, userSchema) {
3235
+ async function parseNestedBodyWithSchema(schema, value, nestedKey, userSchema) {
3236
3236
  const body = parseBody(schema, value);
3237
- if (!isZodSchema(userSchema)) return body;
3237
+ if (!isRequestSchema(userSchema)) return body;
3238
3238
  return {
3239
3239
  ...body,
3240
- [nestedKey]: parseUserSchema(userSchema, body?.[nestedKey], [nestedKey])
3240
+ [nestedKey]: await parseUserSchema(userSchema, body?.[nestedKey], [nestedKey])
3241
3241
  };
3242
3242
  }
3243
3243
  function throwValidationError(issues, key, location = "pointer") {
3244
3244
  const errors = issues.map((issue) => formatIssue(issue, key, location));
3245
3245
  throw new clientErrors.BadRequestError("Bad Request", { errors });
3246
3246
  }
3247
- function parseUserSchema(schema, value, prefix = []) {
3248
- const result = schema.safeParse(value);
3249
- if (!result.success) {
3250
- const issues = result.error.issues.map((issue) => ({
3251
- ...issue,
3252
- path: prefix.concat(issue.path.map(String))
3253
- }));
3254
- throwValidationError(issues, void 0, "pointer");
3255
- }
3256
- return result.data;
3247
+ async function parseUserSchema(schema, value, prefix = []) {
3248
+ const validator = toRequestSchemaValidator(schema);
3249
+ const result = await validator(value);
3250
+ if (!isRequestSchemaFailure(result)) {
3251
+ return result.data;
3252
+ }
3253
+ const issues = result.issues.map((issue) => ({
3254
+ ...issue,
3255
+ path: prefix.concat((issue.path ?? []).map(String))
3256
+ }));
3257
+ throwValidationError(issues, void 0, "pointer");
3257
3258
  }
3258
3259
  function isZodSchema(schema) {
3259
3260
  return typeof schema === "object" && schema !== null && "safeParse" in schema && typeof schema.safeParse === "function";
3260
3261
  }
3262
+ function isRequestSchema(schema) {
3263
+ return isZodSchema(schema) || isStandardSchema(schema) || isRequestSchemaValidator(schema) || isRequestSchemaAdapter(schema);
3264
+ }
3265
+ function isRequestSchemaValidator(schema) {
3266
+ return typeof schema === "function";
3267
+ }
3268
+ function isRequestSchemaAdapter(schema) {
3269
+ return typeof schema === "object" && schema !== null && "validate" in schema && typeof schema.validate === "function";
3270
+ }
3271
+ function isStandardSchema(schema) {
3272
+ return typeof schema === "object" && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && "validate" in schema["~standard"] && typeof schema["~standard"].validate === "function";
3273
+ }
3274
+ function isRequestSchemaFailure(result) {
3275
+ return result.success === false;
3276
+ }
3277
+ function toRequestSchemaValidator(schema) {
3278
+ if (isZodSchema(schema)) return fromZod(schema);
3279
+ if (isStandardSchema(schema)) return fromStandardSchema(schema);
3280
+ if (isRequestSchemaValidator(schema)) return schema;
3281
+ return schema.validate;
3282
+ }
3283
+ function defineRequestSchema(validator) {
3284
+ return validator;
3285
+ }
3286
+ function fromZod(schema) {
3287
+ return (value) => {
3288
+ const result = schema.safeParse(value);
3289
+ if (result.success) {
3290
+ return {
3291
+ success: true,
3292
+ data: result.data
3293
+ };
3294
+ }
3295
+ return {
3296
+ success: false,
3297
+ issues: normalizeIssues(result.error.issues)
3298
+ };
3299
+ };
3300
+ }
3301
+ function fromStandardSchema(schema) {
3302
+ return async (value) => {
3303
+ const result = await schema["~standard"].validate(value);
3304
+ if (!isStandardSchemaFailure(result)) {
3305
+ return {
3306
+ success: true,
3307
+ data: result.value
3308
+ };
3309
+ }
3310
+ return {
3311
+ success: false,
3312
+ issues: normalizeIssues(result.issues)
3313
+ };
3314
+ };
3315
+ }
3316
+ function fromYup(schema) {
3317
+ return async (value) => {
3318
+ try {
3319
+ const data = await schema.validate(value, { abortEarly: false });
3320
+ return {
3321
+ success: true,
3322
+ data
3323
+ };
3324
+ } catch (error) {
3325
+ return {
3326
+ success: false,
3327
+ issues: normalizeYupIssues(error)
3328
+ };
3329
+ }
3330
+ };
3331
+ }
3332
+ function fromJoi(schema) {
3333
+ return async (value) => {
3334
+ const result = await schema.validate(value, { abortEarly: false });
3335
+ if (!result.error?.details?.length) {
3336
+ return {
3337
+ success: true,
3338
+ data: result.value
3339
+ };
3340
+ }
3341
+ return {
3342
+ success: false,
3343
+ issues: normalizeJoiIssues(result.error.details)
3344
+ };
3345
+ };
3346
+ }
3347
+ function fromAjv(validator) {
3348
+ return async (value) => {
3349
+ const valid = await validator(value);
3350
+ if (valid) {
3351
+ return {
3352
+ success: true,
3353
+ data: value
3354
+ };
3355
+ }
3356
+ return {
3357
+ success: false,
3358
+ issues: normalizeAjvIssues(validator.errors ?? [])
3359
+ };
3360
+ };
3361
+ }
3362
+ function fromValibot(schema, safeParse) {
3363
+ return async (value) => {
3364
+ const result = await safeParse(schema, value, { abortEarly: false });
3365
+ if (result.success) {
3366
+ return {
3367
+ success: true,
3368
+ data: result.output
3369
+ };
3370
+ }
3371
+ return {
3372
+ success: false,
3373
+ issues: normalizeValibotIssues(result.issues)
3374
+ };
3375
+ };
3376
+ }
3377
+ function fromArkType(type) {
3378
+ return async (value) => {
3379
+ const result = await type(value);
3380
+ if (!isArkTypeErrors(result)) {
3381
+ return {
3382
+ success: true,
3383
+ data: result
3384
+ };
3385
+ }
3386
+ return {
3387
+ success: false,
3388
+ issues: normalizeArkTypeIssues(result)
3389
+ };
3390
+ };
3391
+ }
3392
+ function fromIoTs(decoder) {
3393
+ return async (value) => {
3394
+ const result = decoder.decode(value);
3395
+ if (result._tag === "Right") {
3396
+ return {
3397
+ success: true,
3398
+ data: result.right
3399
+ };
3400
+ }
3401
+ return {
3402
+ success: false,
3403
+ issues: normalizeIoTsIssues(result.left)
3404
+ };
3405
+ };
3406
+ }
3407
+ function fromSuperstruct(struct, validate) {
3408
+ return async (value) => {
3409
+ const [failure, output] = await validate(value, struct);
3410
+ if (!failure) {
3411
+ return {
3412
+ success: true,
3413
+ data: output
3414
+ };
3415
+ }
3416
+ return {
3417
+ success: false,
3418
+ issues: normalizeSuperstructFailure(failure)
3419
+ };
3420
+ };
3421
+ }
3422
+ function fromVine(validator) {
3423
+ return async (value) => {
3424
+ try {
3425
+ const output = await validator.validate(value);
3426
+ return {
3427
+ success: true,
3428
+ data: output
3429
+ };
3430
+ } catch (error) {
3431
+ return {
3432
+ success: false,
3433
+ issues: normalizeVineError(error)
3434
+ };
3435
+ }
3436
+ };
3437
+ }
3438
+ function isStandardSchemaFailure(result) {
3439
+ return Array.isArray(result.issues);
3440
+ }
3441
+ function normalizeIssues(issues) {
3442
+ return issues.map((issue) => ({
3443
+ message: issue.message,
3444
+ path: issue.path?.flatMap((segment) => normalizePathSegment(segment))
3445
+ }));
3446
+ }
3447
+ function normalizePathSegment(segment) {
3448
+ const key = isStandardSchemaPathSegment(segment) ? segment.key : segment;
3449
+ return typeof key === "string" || typeof key === "number" ? [key] : [];
3450
+ }
3451
+ function isStandardSchemaPathSegment(segment) {
3452
+ return typeof segment === "object" && segment !== null && "key" in segment;
3453
+ }
3454
+ function normalizeYupIssues(error) {
3455
+ if (!isYupValidationError(error)) {
3456
+ return [{ message: "Validation failed" }];
3457
+ }
3458
+ const issues = error.inner?.length ? error.inner : [error];
3459
+ return issues.map((issue) => ({
3460
+ message: issue.message,
3461
+ path: parsePathString(issue.path)
3462
+ }));
3463
+ }
3464
+ function normalizeJoiIssues(issues) {
3465
+ return issues.map((issue) => ({
3466
+ message: issue.message,
3467
+ path: issue.path ? [...issue.path] : void 0
3468
+ }));
3469
+ }
3470
+ function normalizeAjvIssues(issues) {
3471
+ return issues.map((issue) => ({
3472
+ message: issue.message ?? "Validation failed",
3473
+ path: parseAjvPath(issue)
3474
+ }));
3475
+ }
3476
+ function normalizeValibotIssues(issues) {
3477
+ return issues.map((issue) => ({
3478
+ message: issue.message,
3479
+ path: issue.path?.flatMap(
3480
+ (item) => typeof item.key === "string" || typeof item.key === "number" ? [item.key] : []
3481
+ )
3482
+ }));
3483
+ }
3484
+ function normalizeArkTypeIssues(issues) {
3485
+ const normalized = issues.map((issue) => ({
3486
+ message: issue.message ?? issue.problem ?? issues.summary ?? "Validation failed",
3487
+ path: issue.path ? [...issue.path] : void 0
3488
+ }));
3489
+ return normalized.length ? normalized : [{ message: issues.summary ?? "Validation failed" }];
3490
+ }
3491
+ function normalizeIoTsIssues(issues) {
3492
+ return issues.map((issue) => ({
3493
+ message: issue.message ?? "Validation failed",
3494
+ path: issue.context.map((entry) => entry.key).filter(Boolean)
3495
+ }));
3496
+ }
3497
+ function normalizeSuperstructFailure(failure) {
3498
+ const failures = failure.failures?.() ?? [failure];
3499
+ return failures.map((entry) => ({
3500
+ message: entry.message ?? "Validation failed",
3501
+ path: normalizeSuperstructPath(entry)
3502
+ }));
3503
+ }
3504
+ function normalizeSuperstructPath(failure) {
3505
+ if (failure.path?.length) return [...failure.path];
3506
+ if (typeof failure.key === "string" || typeof failure.key === "number") return [failure.key];
3507
+ return void 0;
3508
+ }
3509
+ function normalizeVineError(error) {
3510
+ if (!isVineValidationError(error)) {
3511
+ return [{ message: "Validation failed" }];
3512
+ }
3513
+ return error.messages.map((message) => ({
3514
+ message: message.message,
3515
+ path: normalizeVineField(message)
3516
+ }));
3517
+ }
3518
+ function normalizeVineField(message) {
3519
+ const path = message.field.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
3520
+ if (typeof message.index === "number" && path.length === 0) {
3521
+ return [message.index];
3522
+ }
3523
+ return path.length ? path : void 0;
3524
+ }
3525
+ function parseAjvPath(issue) {
3526
+ const path = issue.instancePath?.split("/").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
3527
+ if (issue.params?.missingProperty) {
3528
+ return (path ?? []).concat(issue.params.missingProperty);
3529
+ }
3530
+ return path;
3531
+ }
3532
+ function parsePathString(path) {
3533
+ if (!path) return void 0;
3534
+ return path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
3535
+ }
3536
+ function isYupValidationError(error) {
3537
+ return typeof error === "object" && error !== null && "message" in error;
3538
+ }
3539
+ function isArkTypeErrors(value) {
3540
+ return Array.isArray(value);
3541
+ }
3542
+ function isVineValidationError(error) {
3543
+ return typeof error === "object" && error !== null && "messages" in error && Array.isArray(error.messages);
3544
+ }
3261
3545
  function formatIssue(issue, key, location = "pointer") {
3262
- const path = issue.path.map(String);
3546
+ const path = (issue.path ?? []).map(String);
3263
3547
  const joinedPath = path.join(".");
3264
3548
  if (location === "parameter") {
3265
3549
  return {
@@ -3696,7 +3980,7 @@ function setModelCollectionRoutes(context) {
3696
3980
  });
3697
3981
  router.post(`/${options.queryRouteSegment}`, async (req) => {
3698
3982
  await context.assertAllowed(req, "list");
3699
- const body = parseBodyWithSchema(
3983
+ const body = await parseBodyWithSchema(
3700
3984
  listBodySchema,
3701
3985
  req.body,
3702
3986
  context.getRequestSchema("requestSchemas.advancedList")
@@ -3722,7 +4006,11 @@ function setModelCollectionRoutes(context) {
3722
4006
  router.post("", async (req) => {
3723
4007
  await context.assertAllowed(req, "create");
3724
4008
  const { include_permissions } = parseQuery(requestSchemas.createQuery, req.query);
3725
- const data = parseBodyWithSchema(createBodySchema, req.body, context.getRequestSchema("requestSchemas.create"));
4009
+ const data = await parseBodyWithSchema(
4010
+ createBodySchema,
4011
+ req.body,
4012
+ context.getRequestSchema("requestSchemas.create")
4013
+ );
3726
4014
  const svc = context.getPublicService(req);
3727
4015
  const result = await svc._create(data, {}, { includePermissions: parseBooleanString(include_permissions) });
3728
4016
  handleResultError(result);
@@ -3731,7 +4019,7 @@ function setModelCollectionRoutes(context) {
3731
4019
  router.post(`/${options.mutationRouteSegment}`, async (req) => {
3732
4020
  await context.assertAllowed(req, "create");
3733
4021
  const { include_permissions } = parseQuery(requestSchemas.createQuery, req.query);
3734
- const body = parseNestedBodyWithSchema(
4022
+ const body = await parseNestedBodyWithSchema(
3735
4023
  advancedCreateBodySchema,
3736
4024
  req.body,
3737
4025
  "data",
@@ -3739,7 +4027,7 @@ function setModelCollectionRoutes(context) {
3739
4027
  );
3740
4028
  const { data, select, populate, tasks } = body;
3741
4029
  const advancedOptions = body.options ?? {};
3742
- parseBodyWithSchema(
4030
+ await parseBodyWithSchema(
3743
4031
  advancedCreateBodySchema,
3744
4032
  { data, select, populate, tasks, options: advancedOptions },
3745
4033
  context.getRequestSchema("requestSchemas.advancedCreate.default") ?? context.getRequestSchema("requestSchemas.advancedCreate")
@@ -3777,7 +4065,7 @@ function setModelDocumentRoutes(context) {
3777
4065
  });
3778
4066
  router.post("/count", async (req) => {
3779
4067
  await context.assertAllowed(req, "count");
3780
- const { filter: filter2, options: countOptions = {} } = parseBodyWithSchema(
4068
+ const { filter: filter2, options: countOptions = {} } = await parseBodyWithSchema(
3781
4069
  countBodySchema,
3782
4070
  req.body,
3783
4071
  context.getRequestSchema("requestSchemas.count")
@@ -3808,7 +4096,7 @@ function setModelDocumentRoutes(context) {
3808
4096
  });
3809
4097
  router.post(`/${options.queryRouteSegment}/__filter`, async (req) => {
3810
4098
  await context.assertAllowed(req, "read");
3811
- const body = parseBodyWithSchema(
4099
+ const body = await parseBodyWithSchema(
3812
4100
  readFilterBodySchema,
3813
4101
  req.body,
3814
4102
  context.getRequestSchema("requestSchemas.advancedReadFilter")
@@ -3828,7 +4116,7 @@ function setModelDocumentRoutes(context) {
3828
4116
  router.post(`/${options.queryRouteSegment}/:${options.idParam}`, async (req) => {
3829
4117
  await context.assertAllowed(req, "read");
3830
4118
  const id = parsePathParam(req.params[options.idParam], options.idParam);
3831
- const body = parseBodyWithSchema(
4119
+ const body = await parseBodyWithSchema(
3832
4120
  readByIdBodySchema,
3833
4121
  req.body,
3834
4122
  context.getRequestSchema("requestSchemas.advancedRead")
@@ -3849,7 +4137,11 @@ function setModelDocumentRoutes(context) {
3849
4137
  await context.assertAllowed(req, "update");
3850
4138
  const id = parsePathParam(req.params[options.idParam], options.idParam);
3851
4139
  const { returning_all, include_permissions } = parseQuery(requestSchemas.updateQuery, req.query);
3852
- const data = parseBodyWithSchema(updateBodySchema, req.body, context.getRequestSchema("requestSchemas.update"));
4140
+ const data = await parseBodyWithSchema(
4141
+ updateBodySchema,
4142
+ req.body,
4143
+ context.getRequestSchema("requestSchemas.update")
4144
+ );
3853
4145
  const svc = context.getPublicService(req);
3854
4146
  const result = await svc._update(
3855
4147
  id,
@@ -3867,7 +4159,7 @@ function setModelDocumentRoutes(context) {
3867
4159
  await context.assertAllowed(req, "update");
3868
4160
  const id = parsePathParam(req.params[options.idParam], options.idParam);
3869
4161
  const { returning_all, include_permissions } = parseQuery(requestSchemas.updateQuery, req.query);
3870
- const body = parseNestedBodyWithSchema(
4162
+ const body = await parseNestedBodyWithSchema(
3871
4163
  advancedUpdateBodySchema,
3872
4164
  req.body,
3873
4165
  "data",
@@ -3875,7 +4167,7 @@ function setModelDocumentRoutes(context) {
3875
4167
  );
3876
4168
  const { data, select, populate, tasks } = body;
3877
4169
  const advancedOptions = body.options ?? {};
3878
- parseBodyWithSchema(
4170
+ await parseBodyWithSchema(
3879
4171
  advancedUpdateBodySchema,
3880
4172
  { data, select, populate, tasks, options: advancedOptions },
3881
4173
  context.getRequestSchema("requestSchemas.advancedUpdate.default") ?? context.getRequestSchema("requestSchemas.advancedUpdate")
@@ -3899,7 +4191,11 @@ function setModelDocumentRoutes(context) {
3899
4191
  await context.assertAllowed(req, "upsert");
3900
4192
  const svc = context.getPublicService(req);
3901
4193
  const { returning_all, include_permissions } = parseQuery(requestSchemas.upsertQuery, req.query);
3902
- const body = parseBodyWithSchema(upsertBodySchema, req.body, context.getRequestSchema("requestSchemas.upsert"));
4194
+ const body = await parseBodyWithSchema(
4195
+ upsertBodySchema,
4196
+ req.body,
4197
+ context.getRequestSchema("requestSchemas.upsert")
4198
+ );
3903
4199
  const result = await svc._upsert(
3904
4200
  body,
3905
4201
  {},
@@ -3915,7 +4211,7 @@ function setModelDocumentRoutes(context) {
3915
4211
  await context.assertAllowed(req, "upsert");
3916
4212
  const svc = context.getPublicService(req);
3917
4213
  const { returning_all, include_permissions } = parseQuery(requestSchemas.upsertQuery, req.query);
3918
- const body = parseNestedBodyWithSchema(
4214
+ const body = await parseNestedBodyWithSchema(
3919
4215
  advancedUpsertBodySchema,
3920
4216
  req.body,
3921
4217
  "data",
@@ -3923,7 +4219,7 @@ function setModelDocumentRoutes(context) {
3923
4219
  );
3924
4220
  const { data, select, populate, tasks } = body;
3925
4221
  const advancedOptions = body.options ?? {};
3926
- parseBodyWithSchema(
4222
+ await parseBodyWithSchema(
3927
4223
  advancedUpsertBodySchema,
3928
4224
  { data, select, populate, tasks, options: advancedOptions },
3929
4225
  context.getRequestSchema("requestSchemas.advancedUpsert.default") ?? context.getRequestSchema("requestSchemas.advancedUpsert")
@@ -3960,7 +4256,7 @@ function setModelDocumentRoutes(context) {
3960
4256
  router.post("/distinct/:field", async (req) => {
3961
4257
  await context.assertAllowed(req, "distinct");
3962
4258
  const field = parsePathParam(req.params.field, "field");
3963
- const { filter: filter2 } = parseBodyWithSchema(
4259
+ const { filter: filter2 } = await parseBodyWithSchema(
3964
4260
  distinctBodySchema,
3965
4261
  req.body,
3966
4262
  context.getRequestSchema("requestSchemas.distinct")
@@ -3991,7 +4287,7 @@ function setModelSubDocumentRoutes(context) {
3991
4287
  async (req) => {
3992
4288
  await context.assertAllowed(req, `subs.${sub}.list`);
3993
4289
  const id = parsePathParam(req.params[context.options.idParam], context.options.idParam);
3994
- const body = parseBodyWithSchema(
4290
+ const body = await parseBodyWithSchema(
3995
4291
  subListBodySchema,
3996
4292
  req.body,
3997
4293
  context.getRequestSchema("requestSchemas.subList")
@@ -4005,7 +4301,7 @@ function setModelSubDocumentRoutes(context) {
4005
4301
  context.router.patch(`/:${context.options.idParam}/${sub}`, async (req) => {
4006
4302
  await context.assertAllowed(req, `subs.${sub}.update`);
4007
4303
  const id = parsePathParam(req.params[context.options.idParam], context.options.idParam);
4008
- const data = parseBodyWithSchema(
4304
+ const data = await parseBodyWithSchema(
4009
4305
  subMutationBodySchema,
4010
4306
  req.body,
4011
4307
  context.getRequestSchema("requestSchemas.subBulkUpdate")
@@ -4030,7 +4326,7 @@ function setModelSubDocumentRoutes(context) {
4030
4326
  await context.assertAllowed(req, `subs.${sub}.read`);
4031
4327
  const id = parsePathParam(req.params[context.options.idParam], context.options.idParam);
4032
4328
  const subId = parsePathParam(req.params.subId, "subId");
4033
- const body = parseBodyWithSchema(
4329
+ const body = await parseBodyWithSchema(
4034
4330
  subReadBodySchema,
4035
4331
  req.body,
4036
4332
  context.getRequestSchema("requestSchemas.subRead")
@@ -4047,7 +4343,7 @@ function setModelSubDocumentRoutes(context) {
4047
4343
  await context.assertAllowed(req, `subs.${sub}.update`);
4048
4344
  const id = parsePathParam(req.params[context.options.idParam], context.options.idParam);
4049
4345
  const subId = parsePathParam(req.params.subId, "subId");
4050
- const data = parseBodyWithSchema(
4346
+ const data = await parseBodyWithSchema(
4051
4347
  subMutationBodySchema,
4052
4348
  req.body,
4053
4349
  context.getRequestSchema("requestSchemas.subUpdate")
@@ -4060,7 +4356,7 @@ function setModelSubDocumentRoutes(context) {
4060
4356
  context.router.post(`/:${context.options.idParam}/${sub}`, async (req) => {
4061
4357
  await context.assertAllowed(req, `subs.${sub}.create`);
4062
4358
  const id = parsePathParam(req.params[context.options.idParam], context.options.idParam);
4063
- const data = parseBodyWithSchema(
4359
+ const data = await parseBodyWithSchema(
4064
4360
  subMutationBodySchema,
4065
4361
  req.body,
4066
4362
  context.getRequestSchema("requestSchemas.subCreate")
@@ -4783,7 +5079,7 @@ var DataRouter = class {
4783
5079
  page,
4784
5080
  pageSize,
4785
5081
  options = {}
4786
- } = parseBodyWithSchema(dataListBodySchema, req.body, this.getRequestSchema("requestSchemas.advancedList"));
5082
+ } = await parseBodyWithSchema(dataListBodySchema, req.body, this.getRequestSchema("requestSchemas.advancedList"));
4787
5083
  const { includeCount, includeExtraHeaders } = options;
4788
5084
  const svc = this.getService(req);
4789
5085
  const result = await svc.find(
@@ -4811,7 +5107,7 @@ var DataRouter = class {
4811
5107
  });
4812
5108
  this.router.post(`/${this.options.queryRouteSegment}/__filter`, async (req) => {
4813
5109
  await this.assertAllowed(req, "read");
4814
- let { filter: filter2, select } = parseBodyWithSchema(
5110
+ let { filter: filter2, select } = await parseBodyWithSchema(
4815
5111
  dataReadFilterBodySchema,
4816
5112
  req.body,
4817
5113
  this.getRequestSchema("requestSchemas.advancedReadFilter")
@@ -4825,7 +5121,7 @@ var DataRouter = class {
4825
5121
  this.router.post(`/${this.options.queryRouteSegment}/:${this.options.idParam}`, async (req) => {
4826
5122
  await this.assertAllowed(req, "read");
4827
5123
  const id = parsePathParam(req.params[this.options.idParam], this.options.idParam);
4828
- let { select } = parseBodyWithSchema(
5124
+ let { select } = await parseBodyWithSchema(
4829
5125
  dataReadByIdBodySchema,
4830
5126
  req.body,
4831
5127
  this.getRequestSchema("requestSchemas.advancedRead")
@@ -4954,6 +5250,17 @@ export {
4954
5250
  combineRoutes,
4955
5251
  createAccessRuntime,
4956
5252
  index_default as default,
5253
+ defineRequestSchema,
5254
+ fromAjv,
5255
+ fromArkType,
5256
+ fromIoTs,
5257
+ fromJoi,
5258
+ fromStandardSchema,
5259
+ fromSuperstruct,
5260
+ fromValibot,
5261
+ fromVine,
5262
+ fromYup,
5263
+ fromZod,
4957
5264
  getDefaultModelOption,
4958
5265
  getDefaultModelOptions,
4959
5266
  getGlobalOption,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@web-ts-toolkit/access-router",
3
3
  "description": "Access-policy Express routers and in-memory data services for Mongoose-backed APIs",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "keywords": [
6
6
  "express",
7
7
  "mongoose",
@@ -33,11 +33,11 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@web-ts-toolkit/express-json-router": "0.3.0",
36
+ "@web-ts-toolkit/express-json-router": "0.4.0",
37
37
  "deep-diff": "^1.0.2",
38
38
  "mongoose-schema-jsonschema": "^4.0.1",
39
39
  "sift": "^17.1.3",
40
- "@web-ts-toolkit/utils": "0.3.0",
40
+ "@web-ts-toolkit/utils": "0.4.0",
41
41
  "winston": "^3.19.0",
42
42
  "zod": "^4.1.12"
43
43
  },