@kaapi/validator-arktype 0.0.23 → 0.0.24

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.
@@ -1,5 +1,6 @@
1
1
  // src/doc-helpers.ts
2
2
  import { OpenAPIJsonHelper, PostmanJsonHelper } from "@novice1/api-doc-json-helper";
3
+ import { type, Type } from "arktype";
3
4
  function transformValue(value) {
4
5
  let r = value;
5
6
  if (value && typeof value === "function" && "toJsonSchema" in value && typeof value.toJsonSchema === "function") {
@@ -38,6 +39,9 @@ function transformValue(value) {
38
39
  var OpenAPIArkHelper = class _OpenAPIArkHelper extends OpenAPIJsonHelper {
39
40
  constructor(params, isRequired) {
40
41
  super({ ...params, value: transformValue(params.value) }, isRequired);
42
+ if (params.value instanceof Type) {
43
+ this._originalSchema = params.value;
44
+ }
41
45
  }
42
46
  isValid() {
43
47
  return !!(this._schema && typeof this._schema === "object" && !("~standard" in this._schema) && ("type" in this._schema && typeof this._schema.type === "string" || "oneOf" in this._schema && Array.isArray(this._schema.oneOf) || "anyOf" in this._schema && Array.isArray(this._schema.anyOf) || "enum" in this._schema && Array.isArray(this._schema.enum)));
@@ -81,16 +85,47 @@ var OpenAPIArkHelper = class _OpenAPIArkHelper extends OpenAPIJsonHelper {
81
85
  }
82
86
  return r;
83
87
  }
88
+ isRequired() {
89
+ let r = super.isRequired();
90
+ if (!r && this._originalSchema) {
91
+ const schema = this._schema;
92
+ if ("required" in schema && Array.isArray(schema.required) && "properties" in schema && typeof schema.properties === "object" && schema.properties && schema.required.length === Object.keys(schema.properties).length) {
93
+ r = true;
94
+ }
95
+ }
96
+ return r;
97
+ }
84
98
  getFilesChildren() {
85
99
  const r = {};
86
100
  const schema = this._schema;
87
101
  if ("properties" in schema && typeof schema.properties === "object" && schema.properties) {
88
102
  const properties = schema.properties;
89
- for (const p in properties) {
90
- const isRequired = "required" in schema && Array.isArray(schema.required) && schema.required.includes(p);
91
- const ch = new _OpenAPIArkHelper({ value: properties[p] }, isRequired);
92
- if (ch.isFile()) {
93
- r[p] = properties[p];
103
+ if (this._originalSchema) {
104
+ const betterR = {};
105
+ for (const p in properties) {
106
+ const isRequired = "required" in schema && Array.isArray(schema.required) && schema.required.includes(p);
107
+ const ch = new _OpenAPIArkHelper({ value: properties[p] }, isRequired);
108
+ if (ch.isFile()) {
109
+ const propOriginalSchema = this._originalSchema?.props?.find((v) => v.key === p);
110
+ if (propOriginalSchema) {
111
+ let key = p;
112
+ if (!isRequired) {
113
+ key = `${p}?`;
114
+ }
115
+ betterR[key] = propOriginalSchema.value;
116
+ }
117
+ }
118
+ }
119
+ if (Object.keys(betterR).length) {
120
+ return type(betterR);
121
+ }
122
+ } else {
123
+ for (const p in properties) {
124
+ const isRequired = "required" in schema && Array.isArray(schema.required) && schema.required.includes(p);
125
+ const ch = new _OpenAPIArkHelper({ value: properties[p] }, isRequired);
126
+ if (ch.isFile()) {
127
+ r[p] = properties[p];
128
+ }
94
129
  }
95
130
  }
96
131
  }
@@ -102,7 +137,7 @@ var PostmanArkHelper = class _PostmanArkHelper extends PostmanJsonHelper {
102
137
  super({ ...params, value: transformValue(params.value) }, isRequired);
103
138
  }
104
139
  isValid() {
105
- return !!(this._schema && typeof this._schema === "object" && ("type" in this._schema && typeof this._schema.type === "string" || "oneOf" in this._schema && Array.isArray(this._schema.oneOf) || "anyOf" in this._schema && Array.isArray(this._schema.anyOf) || "enum" in this._schema && Array.isArray(this._schema.enum)));
140
+ return !!(this._schema && typeof this._schema === "object" && !("~standard" in this._schema) && ("type" in this._schema && typeof this._schema.type === "string" || "oneOf" in this._schema && Array.isArray(this._schema.oneOf) || "anyOf" in this._schema && Array.isArray(this._schema.anyOf) || "enum" in this._schema && Array.isArray(this._schema.enum)));
106
141
  }
107
142
  getFirstItem() {
108
143
  const schema = this._schema;
@@ -139,4 +174,4 @@ export {
139
174
  OpenAPIArkHelper,
140
175
  PostmanArkHelper
141
176
  };
142
- //# sourceMappingURL=chunk-3R3TW4ZK.js.map
177
+ //# sourceMappingURL=chunk-ML2GHWVG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/doc-helpers.ts"],"sourcesContent":["import type { KaapiOpenAPIHelperInterface } from '@kaapi/kaapi';\nimport { OpenAPIJsonHelper, PostmanJsonHelper } from '@novice1/api-doc-json-helper';\nimport { type, Type, type JsonSchema } from 'arktype';\n\nfunction transformValue(value?: Type | object | unknown) {\n let r: unknown = value;\n if (value && typeof value === 'function' && 'toJsonSchema' in value && typeof value.toJsonSchema === 'function') {\n r = (value as Type).toJsonSchema({\n fallback: (v) => {\n let r: JsonSchema & { _instanceof?: string } = {};\n let _instanceof = '';\n if (v && 'proto' in v && v.proto && typeof v.proto === 'function' && 'name' in v.proto) {\n r.type = 'object';\n r._instanceof = `${v.proto.name}`;\n _instanceof = `${v.proto.name}`;\n }\n if (v.base) {\n r = { ...r, ...v.base };\n if ('out' in v && v.out) {\n if ('anyOf' in r && 'type' in v.out) {\n const description = r.anyOf[0]?.description;\n r = { ...v.out };\n if (description) {\n r.description = description;\n }\n if (_instanceof) {\n r._instanceof = _instanceof;\n }\n } else {\n r = { ...r, ...v.out };\n }\n }\n }\n return r;\n },\n });\n }\n\n return r;\n}\n\nexport class OpenAPIArkHelper extends OpenAPIJsonHelper implements KaapiOpenAPIHelperInterface {\n protected _originalSchema?: Type\n constructor(\n params: {\n value?: Type | object | unknown;\n isRoot?: boolean;\n },\n isRequired?: boolean\n ) {\n super({ ...params, value: transformValue(params.value) }, isRequired);\n if (params.value instanceof Type) {\n this._originalSchema = params.value\n }\n }\n isValid(): boolean {\n return !!(\n this._schema &&\n typeof this._schema === 'object' &&\n !('~standard' in this._schema) &&\n (('type' in this._schema && typeof this._schema.type === 'string') ||\n ('oneOf' in this._schema && Array.isArray(this._schema.oneOf)) ||\n ('anyOf' in this._schema && Array.isArray(this._schema.anyOf)) ||\n ('enum' in this._schema && Array.isArray(this._schema.enum)))\n );\n }\n getFirstItem(): OpenAPIArkHelper | undefined {\n const schema = this._schema;\n\n if ('items' in schema && typeof schema.items === 'object') {\n return new OpenAPIArkHelper({ value: schema.items });\n }\n\n return;\n }\n getChildren(): Record<string, OpenAPIArkHelper> {\n const r: Record<string, OpenAPIArkHelper> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n r[p] = new OpenAPIArkHelper({ value: properties[p] }, isRequired);\n }\n }\n return r;\n }\n getAlternatives(): OpenAPIArkHelper[] {\n const r: OpenAPIArkHelper[] = [];\n const schema = this._schema;\n if ('oneOf' in schema && Array.isArray(schema.oneOf)) {\n for (const p of schema.oneOf) {\n r.push(new OpenAPIArkHelper({ value: p }));\n }\n }\n return r;\n }\n isFile(): boolean | undefined {\n if (!this.isValid()) return false;\n let r: boolean = false;\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n r = !!(\n '_data' in properties &&\n properties._data &&\n typeof properties._data === 'object' &&\n '_instanceof' in properties._data &&\n properties._data._instanceof === 'Buffer'\n );\n }\n return r;\n }\n isRequired(): boolean {\n let r = super.isRequired()\n if (!r && this._originalSchema) {\n const schema = this._schema;\n if ('required' in schema &&\n Array.isArray(schema.required) &&\n 'properties' in schema &&\n typeof schema.properties === 'object' &&\n schema.properties &&\n schema.required.length === Object.keys(schema.properties).length\n ) {\n r = true\n }\n }\n return r;\n }\n getFilesChildren(): Record<string, unknown> {\n const r: Record<string, unknown> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n if (this._originalSchema) {\n const betterR: Record<string, Type> = {}\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n const ch = new OpenAPIArkHelper({ value: properties[p] }, isRequired);\n if (ch.isFile()) {\n const propOriginalSchema = (this._originalSchema as Type<Record<string, unknown>>)?.props?.find(v => v.key === p)\n if (propOriginalSchema) {\n let key = p;\n if (!isRequired) {\n key = `${p}?` // set it as optional\n }\n betterR[key] = propOriginalSchema.value\n }\n }\n }\n if (Object.keys(betterR).length) {\n return type<unknown, Type<typeof betterR>>(betterR) as unknown as Record<string, unknown>\n }\n } else {\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n const ch = new OpenAPIArkHelper({ value: properties[p] }, isRequired);\n if (ch.isFile()) {\n r[p] = properties[p];\n }\n }\n }\n }\n return r;\n }\n}\n\nexport class PostmanArkHelper extends PostmanJsonHelper {\n constructor(\n params: {\n value?: Type | object | unknown;\n isRoot?: boolean;\n },\n isRequired?: boolean\n ) {\n super({ ...params, value: transformValue(params.value) }, isRequired);\n }\n isValid(): boolean {\n return !!(\n this._schema &&\n typeof this._schema === 'object' &&\n !('~standard' in this._schema) &&\n (('type' in this._schema && typeof this._schema.type === 'string') ||\n ('oneOf' in this._schema && Array.isArray(this._schema.oneOf)) ||\n ('anyOf' in this._schema && Array.isArray(this._schema.anyOf)) ||\n ('enum' in this._schema && Array.isArray(this._schema.enum)))\n );\n }\n getFirstItem(): PostmanArkHelper | undefined {\n const schema = this._schema;\n\n if ('items' in schema && typeof schema.items === 'object') {\n return new PostmanArkHelper({ value: schema.items });\n }\n\n return;\n }\n getChildren(): Record<string, PostmanArkHelper> {\n const r: Record<string, PostmanArkHelper> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n r[p] = new PostmanArkHelper({ value: properties[p] }, isRequired);\n }\n }\n return r;\n }\n getAlternatives(): PostmanArkHelper[] {\n const r: PostmanArkHelper[] = [];\n const schema = this._schema;\n if ('oneOf' in schema && Array.isArray(schema.oneOf)) {\n for (const p of schema.oneOf) {\n r.push(new PostmanArkHelper({ value: p }));\n }\n }\n return r;\n }\n}\n"],"mappings":";AACA,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,MAAM,YAA6B;AAE5C,SAAS,eAAe,OAAiC;AACrD,MAAI,IAAa;AACjB,MAAI,SAAS,OAAO,UAAU,cAAc,kBAAkB,SAAS,OAAO,MAAM,iBAAiB,YAAY;AAC7G,QAAK,MAAe,aAAa;AAAA,MAC7B,UAAU,CAAC,MAAM;AACb,YAAIA,KAA2C,CAAC;AAChD,YAAI,cAAc;AAClB,YAAI,KAAK,WAAW,KAAK,EAAE,SAAS,OAAO,EAAE,UAAU,cAAc,UAAU,EAAE,OAAO;AACpF,UAAAA,GAAE,OAAO;AACT,UAAAA,GAAE,cAAc,GAAG,EAAE,MAAM,IAAI;AAC/B,wBAAc,GAAG,EAAE,MAAM,IAAI;AAAA,QACjC;AACA,YAAI,EAAE,MAAM;AACR,UAAAA,KAAI,EAAE,GAAGA,IAAG,GAAG,EAAE,KAAK;AACtB,cAAI,SAAS,KAAK,EAAE,KAAK;AACrB,gBAAI,WAAWA,MAAK,UAAU,EAAE,KAAK;AACjC,oBAAM,cAAcA,GAAE,MAAM,CAAC,GAAG;AAChC,cAAAA,KAAI,EAAE,GAAG,EAAE,IAAI;AACf,kBAAI,aAAa;AACb,gBAAAA,GAAE,cAAc;AAAA,cACpB;AACA,kBAAI,aAAa;AACb,gBAAAA,GAAE,cAAc;AAAA,cACpB;AAAA,YACJ,OAAO;AACH,cAAAA,KAAI,EAAE,GAAGA,IAAG,GAAG,EAAE,IAAI;AAAA,YACzB;AAAA,UACJ;AAAA,QACJ;AACA,eAAOA;AAAA,MACX;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO;AACX;AAEO,IAAM,mBAAN,MAAM,0BAAyB,kBAAyD;AAAA,EAE3F,YACI,QAIA,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AAE,OAAO,OAAO,MAAM,CAAC;AAAA,IACvD;AAEA;AAAA,EACJ;AAAA,EACA,cAAgD;AAC5C,UAAM,IAAsC,CAAC;AAC7C,UAAM,SAAS,KAAK;AACpB,QAAI,gBAAgB,UAAU,OAAO,OAAO,eAAe,YAAY,OAAO,YAAY;AACtF,YAAM,aAAsC,OAAO;AACnD,iBAAW,KAAK,YAAY;AACxB,cAAM,aACF,cAAc,UAAU,MAAM,QAAQ,OAAO,QAAQ,KAAK,OAAO,SAAS,SAAS,CAAC;AACxF,UAAE,CAAC,IAAI,IAAI,kBAAiB,EAAE,OAAO,WAAW,CAAC,EAAE,GAAG,UAAU;AAAA,MACpE;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AAAA,EACA,kBAAsC;AAClC,UAAM,IAAwB,CAAC;AAC/B,UAAM,SAAS,KAAK;AACpB,QAAI,WAAW,UAAU,MAAM,QAAQ,OAAO,KAAK,GAAG;AAClD,iBAAW,KAAK,OAAO,OAAO;AAC1B,UAAE,KAAK,IAAI,kBAAiB,EAAE,OAAO,EAAE,CAAC,CAAC;AAAA,MAC7C;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AACJ;","names":["r"]}
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  OpenAPIArkHelper,
3
3
  PostmanArkHelper
4
- } from "./chunk-3R3TW4ZK.js";
4
+ } from "./chunk-ML2GHWVG.js";
5
5
 
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@kaapi/validator-arktype",
9
9
  type: "module",
10
- version: "0.0.23",
10
+ version: "0.0.24",
11
11
  private: false,
12
12
  description: "ArkType-powered request validation and documentation plugin for Kaapi.",
13
13
  main: "lib/index.js",
@@ -179,4 +179,4 @@ export {
179
179
  supportedProps,
180
180
  validatorArk
181
181
  };
182
- //# sourceMappingURL=chunk-HTN32YW4.js.map
182
+ //# sourceMappingURL=chunk-ZAKDEELE.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/validator.ts"],"sourcesContent":["{\n \"name\": \"@kaapi/validator-arktype\",\n \"type\": \"module\",\n \"version\": \"0.0.23\",\n \"private\": false,\n \"description\": \"ArkType-powered request validation and documentation plugin for Kaapi.\",\n \"main\": \"lib/index.js\",\n \"exports\": {\n \".\": {\n \"types\": \"./lib/index.d.ts\",\n \"default\": \"./lib/index.js\"\n }\n },\n \"scripts\": {\n \"build\": \"tsup src !src/**/*.d.ts --format esm --outDir lib --clean --metafile --dts --sourcemap && node ./scripts/buildDT.mjs\",\n \"check\": \"tsc --noEmit\",\n \"check:deps\": \"depcruise src --validate\",\n \"ci\": \"npm run verify\",\n \"coverage\": \"c8 node --loader ts-node/esm --experimental-specifier-resolution=node --no-warnings ../../node_modules/mocha/bin/mocha test/**/*.spec.ts\",\n \"format\": \"prettier --write ./\",\n \"format:check\": \"prettier --check ./\",\n \"lint\": \"eslint .\",\n \"test\": \"node --loader ts-node/esm --experimental-specifier-resolution=node --no-warnings ../../node_modules/mocha/bin/mocha test/**/*.spec.ts\",\n \"type-coverage\": \"type-coverage --at-least 90 --detail\",\n \"verify\": \"npm run lint && npm run format:check && npm run check && npm run check:deps && npm run type-coverage && npm run test:kaukau && npm run coverage\"\n },\n \"keywords\": [\n \"kaapi\",\n \"hapi\",\n \"arktype\",\n \"typescript\",\n \"validation\"\n ],\n \"author\": \"demingongo\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/demingongo/kaapi.git\",\n \"directory\": \"packages/validator-arktype\"\n },\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@hapi/boom\": \"^10.0.1\",\n \"@kaapi/kaapi\": \"workspace:^\",\n \"@novice1/api-doc-json-helper\": \"^1.0.6\",\n \"arktype\": \"^2.1.25\",\n \"tslib\": \"^2.8.1\"\n },\n \"devDependencies\": {\n \"@types/mocha\": \"^10.0.10\"\n },\n \"peerDependencies\": {\n \"arktype\": \"^2.1.25\"\n }\n}\n","import pkg from '../package.json' with { type: 'json' };\nimport { OpenAPIArkHelper, PostmanArkHelper } from './doc-helpers.js';\nimport type {\n ArklessReqRef,\n ArklessReqRefDefaults,\n ValidatorArk,\n ValidatorArkReqRef,\n ValidatorArkSchema,\n} from './types.js';\nimport Boom from '@hapi/boom';\nimport type {\n KaapiServerRoute,\n HandlerDecorations,\n Lifecycle,\n KaapiPlugin,\n Request,\n ResponseToolkit,\n} from '@kaapi/kaapi';\nimport { type, type Type } from 'arktype';\n\nconst { parse = { payload: true, query: true, params: true, headers: true, state: true } } = {};\nexport const supportedProps = ['payload', 'query', 'params', 'headers', 'state'] as const;\nconst normalizeBooleans = (obj: Record<string, unknown>) => {\n for (const key in obj) {\n const val = obj[key];\n if (typeof val === 'string') {\n if (val === 'true') obj[key] = true;\n else if (val === 'false') obj[key] = false;\n } else if (Array.isArray(val)) {\n obj[key] = val.map((v) => (v === 'true' ? true : v === 'false' ? false : v));\n }\n }\n return obj;\n};\n\nexport const validatorArk: KaapiPlugin = {\n async integrate(t) {\n const validator: ValidatorArk = <V extends ValidatorArkSchema>(schema: V) => {\n return {\n route<R extends ArklessReqRef = ArklessReqRefDefaults>(\n serverRoute: KaapiServerRoute<ValidatorArkReqRef<V> & R>,\n handler?:\n | HandlerDecorations\n | Lifecycle.Method<ValidatorArkReqRef<V> & R, Lifecycle.ReturnValue<ValidatorArkReqRef<V> & R>>\n ) {\n if (!serverRoute.options) {\n serverRoute.options = {};\n }\n if (typeof serverRoute.options === 'object') {\n // validate\n if (!serverRoute.options.plugins) {\n serverRoute.options.plugins = {};\n }\n serverRoute.options.plugins.ark = schema;\n\n // docs\n serverRoute.options.plugins.kaapi = serverRoute.options.plugins.kaapi || {};\n if (\n serverRoute.options.plugins.kaapi.docs != false && // docs not disabled\n !serverRoute.options.plugins.kaapi.docs?.disabled // docs not disabled\n ) {\n if (!serverRoute.options.plugins?.kaapi?.docs?.helperSchemaProperty)\n // docs have not helperSchemaProperty\n serverRoute.options.plugins.kaapi.docs = {\n ...serverRoute.options.plugins.kaapi.docs,\n helperSchemaProperty: 'ark',\n };\n if (!serverRoute.options.plugins?.kaapi?.docs?.openAPIHelperClass)\n // docs have not openAPIHelperClass\n serverRoute.options.plugins.kaapi.docs = {\n ...serverRoute.options.plugins.kaapi.docs,\n openAPIHelperClass: OpenAPIArkHelper,\n };\n }\n }\n t.route(serverRoute, handler);\n return t.server;\n },\n };\n };\n\n await t.server.register({\n name: 'kaapi-validator-arktype',\n version: pkg.version,\n register: async function (server) {\n server.ext('onPreHandler', async (request: Request, h: ResponseToolkit) => {\n const routeValidation = request?.route?.settings?.plugins?.ark as ValidatorArkSchema | undefined;\n try {\n // Initialize empty objects to hold the parsed data and corresponding ArkType schemas\n const data: Record<string, unknown> = {};\n const dataSchema: Record<string, Type> = {};\n\n // Loop through all supported properties for this route\n for (const prop of supportedProps) {\n // Check if validation exists for this property and there is a parser defined\n if (routeValidation?.[prop] && parse[prop]) {\n // Add the ArkType schema for this property to the dataSchema\n dataSchema[prop] = routeValidation[prop];\n // Prepare the value for parsing:\n // - For query params, normalize boolean strings to actual booleans\n // - Otherwise, take the raw value from the request object\n data[prop] = prop === 'query' ? normalizeBooleans(request[prop]) : request[prop];\n }\n }\n\n // Determine if there are any properties to validate\n let hasProps = false;\n for (const key in dataSchema) {\n // Safely check own properties to avoid inherited keys\n if (Object.prototype.hasOwnProperty.call(dataSchema, key)) {\n hasProps = true;\n break;\n }\n }\n\n // If we have any props to validate, parse them using ArkType\n if (hasProps) {\n // Create an ArkType object from the collected schema and parse\n const parsedProps = type(dataSchema)(data);\n if (parsedProps instanceof type.errors) {\n // throw ArkErrors\n throw parsedProps;\n }\n // Merge the parsed and validated properties back into the request object\n Object.assign(request, parsedProps);\n }\n\n // Continue the Hapi request lifecycle\n return h.continue;\n } catch (err) {\n // Initialize a set to track which paths (properties) failed validation\n const issuePaths = new Set<string>();\n let message: string;\n\n // Check if the error is instance of ValiError\n if (err instanceof type.errors && err.issues.length) {\n const firstIssue = err.issues[0];\n message = firstIssue.message;\n } else if (err instanceof Error) {\n // If it’s a regular Error, use its message\n message = err.message;\n } else {\n // Unknown error type\n message = 'Unknown error';\n }\n\n // Create a Boom badRequest response with the error message\n const response = Boom.badRequest(message);\n\n // Attach the raw validation error object for debugging/logging\n response.data = {\n validationError: err,\n };\n\n // Handle custom failAction if it’s a function\n if (typeof routeValidation?.failAction === 'function') {\n return routeValidation.failAction(request, h, response);\n }\n\n // If failAction is 'log', log the validation error with the request\n if (routeValidation?.failAction === 'log') {\n request.log(['validation', 'error', 'arktype', ...issuePaths], response);\n // Note: unlike Hapi's failAction 'log', 'log' here still returns a Boom response\n }\n\n // Return the error response to halt request processing\n return response;\n }\n });\n server.decorate('server', 'ark', validator);\n },\n });\n\n if (t.openapi) {\n t.openapi.addHelperClass(OpenAPIArkHelper);\n }\n if (t.postman) {\n t.postman.addHelperClass(PostmanArkHelper);\n }\n },\n};\n"],"mappings":";;;;;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,EACF;AAAA,EACA,SAAW;AAAA,IACT,OAAS;AAAA,IACT,OAAS;AAAA,IACT,cAAc;AAAA,IACd,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,MAAQ;AAAA,IACR,MAAQ;AAAA,IACR,iBAAiB;AAAA,IACjB,QAAU;AAAA,EACZ;AAAA,EACA,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,SAAW;AAAA,EACX,cAAgB;AAAA,IACd,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,gCAAgC;A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cACV;AAEA,qBAAO,OAAO,SAAS,WAAW;AAAA,YACtC;AAGA,mBAAO,EAAE;AAAA,UACb,SAAS,KAAK;AAEV,kBAAM,aAAa,oBAAI,IAAY;AACnC,gBAAI;AAGJ,gBAAI,eAAe,KAAK,UAAU,IAAI,OAAO,QAAQ;AACjD,oBAAM,aAAa,IAAI,OAAO,CAAC;AAC/B,wBAAU,WAAW;AAAA,YACzB,WAAW,eAAe,OAAO;AAE7B,wBAAU,IAAI;AAAA,YAClB,OAAO;AAEH,wBAAU;AAAA,YACd;AAGA,kBAAM,WAAW,KAAK,WAAW,OAAO;AAGxC,qBAAS,OAAO;AAAA,cACZ,iBAAiB;AAAA,YACrB;AAGA,gBAAI,OAAO,iBAAiB,eAAe,YAAY;AACnD,qBAAO,gBAAgB,WAAW,SAAS,GAAG,QAAQ;AAAA,YAC1D;AAGA,gBAAI,iBAAiB,eAAe,OAAO;AACvC,sBAAQ,IAAI,CAAC,cAAc,SAAS,WAAW,GAAG,UAAU,GAAG,QAAQ;AAAA,YAE3E;AAGA,mBAAO;AAAA,UACX;AAAA,QACJ,CAAC;AACD,eAAO,SAAS,UAAU,OAAO,SAAS;AAAA,MAC9C;AAAA,IACJ,CAAC;AAED,QAAI,EAAE,SAAS;AACX,QAAE,QAAQ,eAAe,gBAAgB;AAAA,IAC7C;AACA,QAAI,EAAE,SAAS;AACX,QAAE,QAAQ,eAAe,gBAAgB;AAAA,IAC7C;AAAA,EACJ;AACJ;","names":[]}
1
+ {"version":3,"sources":["../package.json","../src/validator.ts"],"sourcesContent":["{\n \"name\": \"@kaapi/validator-arktype\",\n \"type\": \"module\",\n \"version\": \"0.0.24\",\n \"private\": false,\n \"description\": \"ArkType-powered request validation and documentation plugin for Kaapi.\",\n \"main\": \"lib/index.js\",\n \"exports\": {\n \".\": {\n \"types\": \"./lib/index.d.ts\",\n \"default\": \"./lib/index.js\"\n }\n },\n \"scripts\": {\n \"build\": \"tsup src !src/**/*.d.ts --format esm --outDir lib --clean --metafile --dts --sourcemap && node ./scripts/buildDT.mjs\",\n \"check\": \"tsc --noEmit\",\n \"check:deps\": \"depcruise src --validate\",\n \"ci\": \"npm run verify\",\n \"coverage\": \"c8 node --loader ts-node/esm --experimental-specifier-resolution=node --no-warnings ../../node_modules/mocha/bin/mocha test/**/*.spec.ts\",\n \"format\": \"prettier --write ./\",\n \"format:check\": \"prettier --check ./\",\n \"lint\": \"eslint .\",\n \"test\": \"node --loader ts-node/esm --experimental-specifier-resolution=node --no-warnings ../../node_modules/mocha/bin/mocha test/**/*.spec.ts\",\n \"type-coverage\": \"type-coverage --at-least 90 --detail\",\n \"verify\": \"npm run lint && npm run format:check && npm run check && npm run check:deps && npm run type-coverage && npm run test:kaukau && npm run coverage\"\n },\n \"keywords\": [\n \"kaapi\",\n \"hapi\",\n \"arktype\",\n \"typescript\",\n \"validation\"\n ],\n \"author\": \"demingongo\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/demingongo/kaapi.git\",\n \"directory\": \"packages/validator-arktype\"\n },\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@hapi/boom\": \"^10.0.1\",\n \"@kaapi/kaapi\": \"workspace:^\",\n \"@novice1/api-doc-json-helper\": \"^1.0.6\",\n \"arktype\": \"^2.1.25\",\n \"tslib\": \"^2.8.1\"\n },\n \"devDependencies\": {\n \"@types/mocha\": \"^10.0.10\"\n },\n \"peerDependencies\": {\n \"arktype\": \"^2.1.25\"\n }\n}\n","import pkg from '../package.json' with { type: 'json' };\nimport { OpenAPIArkHelper, PostmanArkHelper } from './doc-helpers.js';\nimport type {\n ArklessReqRef,\n ArklessReqRefDefaults,\n ValidatorArk,\n ValidatorArkReqRef,\n ValidatorArkSchema,\n} from './types.js';\nimport Boom from '@hapi/boom';\nimport type {\n KaapiServerRoute,\n HandlerDecorations,\n Lifecycle,\n KaapiPlugin,\n Request,\n ResponseToolkit,\n} from '@kaapi/kaapi';\nimport { type, type Type } from 'arktype';\n\nconst { parse = { payload: true, query: true, params: true, headers: true, state: true } } = {};\nexport const supportedProps = ['payload', 'query', 'params', 'headers', 'state'] as const;\nconst normalizeBooleans = (obj: Record<string, unknown>) => {\n for (const key in obj) {\n const val = obj[key];\n if (typeof val === 'string') {\n if (val === 'true') obj[key] = true;\n else if (val === 'false') obj[key] = false;\n } else if (Array.isArray(val)) {\n obj[key] = val.map((v) => (v === 'true' ? true : v === 'false' ? false : v));\n }\n }\n return obj;\n};\n\nexport const validatorArk: KaapiPlugin = {\n async integrate(t) {\n const validator: ValidatorArk = <V extends ValidatorArkSchema>(schema: V) => {\n return {\n route<R extends ArklessReqRef = ArklessReqRefDefaults>(\n serverRoute: KaapiServerRoute<ValidatorArkReqRef<V> & R>,\n handler?:\n | HandlerDecorations\n | Lifecycle.Method<ValidatorArkReqRef<V> & R, Lifecycle.ReturnValue<ValidatorArkReqRef<V> & R>>\n ) {\n if (!serverRoute.options) {\n serverRoute.options = {};\n }\n if (typeof serverRoute.options === 'object') {\n // validate\n if (!serverRoute.options.plugins) {\n serverRoute.options.plugins = {};\n }\n serverRoute.options.plugins.ark = schema;\n\n // docs\n serverRoute.options.plugins.kaapi = serverRoute.options.plugins.kaapi || {};\n if (\n serverRoute.options.plugins.kaapi.docs != false && // docs not disabled\n !serverRoute.options.plugins.kaapi.docs?.disabled // docs not disabled\n ) {\n if (!serverRoute.options.plugins?.kaapi?.docs?.helperSchemaProperty)\n // docs have not helperSchemaProperty\n serverRoute.options.plugins.kaapi.docs = {\n ...serverRoute.options.plugins.kaapi.docs,\n helperSchemaProperty: 'ark',\n };\n if (!serverRoute.options.plugins?.kaapi?.docs?.openAPIHelperClass)\n // docs have not openAPIHelperClass\n serverRoute.options.plugins.kaapi.docs = {\n ...serverRoute.options.plugins.kaapi.docs,\n openAPIHelperClass: OpenAPIArkHelper,\n };\n }\n }\n t.route(serverRoute, handler);\n return t.server;\n },\n };\n };\n\n await t.server.register({\n name: 'kaapi-validator-arktype',\n version: pkg.version,\n register: async function (server) {\n server.ext('onPreHandler', async (request: Request, h: ResponseToolkit) => {\n const routeValidation = request?.route?.settings?.plugins?.ark as ValidatorArkSchema | undefined;\n try {\n // Initialize empty objects to hold the parsed data and corresponding ArkType schemas\n const data: Record<string, unknown> = {};\n const dataSchema: Record<string, Type> = {};\n\n // Loop through all supported properties for this route\n for (const prop of supportedProps) {\n // Check if validation exists for this property and there is a parser defined\n if (routeValidation?.[prop] && parse[prop]) {\n // Add the ArkType schema for this property to the dataSchema\n dataSchema[prop] = routeValidation[prop];\n // Prepare the value for parsing:\n // - For query params, normalize boolean strings to actual booleans\n // - Otherwise, take the raw value from the request object\n data[prop] = prop === 'query' ? normalizeBooleans(request[prop]) : request[prop];\n }\n }\n\n // Determine if there are any properties to validate\n let hasProps = false;\n for (const key in dataSchema) {\n // Safely check own properties to avoid inherited keys\n if (Object.prototype.hasOwnProperty.call(dataSchema, key)) {\n hasProps = true;\n break;\n }\n }\n\n // If we have any props to validate, parse them using ArkType\n if (hasProps) {\n // Create an ArkType object from the collected schema and parse\n const parsedProps = type(dataSchema)(data);\n if (parsedProps instanceof type.errors) {\n // throw ArkErrors\n throw parsedProps;\n }\n // Merge the parsed and validated properties back into the request object\n Object.assign(request, parsedProps);\n }\n\n // Continue the Hapi request lifecycle\n return h.continue;\n } catch (err) {\n // Initialize a set to track which paths (properties) failed validation\n const issuePaths = new Set<string>();\n let message: string;\n\n // Check if the error is instance of ValiError\n if (err instanceof type.errors && err.issues.length) {\n const firstIssue = err.issues[0];\n message = firstIssue.message;\n } else if (err instanceof Error) {\n // If it’s a regular Error, use its message\n message = err.message;\n } else {\n // Unknown error type\n message = 'Unknown error';\n }\n\n // Create a Boom badRequest response with the error message\n const response = Boom.badRequest(message);\n\n // Attach the raw validation error object for debugging/logging\n response.data = {\n validationError: err,\n };\n\n // Handle custom failAction if it’s a function\n if (typeof routeValidation?.failAction === 'function') {\n return routeValidation.failAction(request, h, response);\n }\n\n // If failAction is 'log', log the validation error with the request\n if (routeValidation?.failAction === 'log') {\n request.log(['validation', 'error', 'arktype', ...issuePaths], response);\n // Note: unlike Hapi's failAction 'log', 'log' here still returns a Boom response\n }\n\n // Return the error response to halt request processing\n return response;\n }\n });\n server.decorate('server', 'ark', validator);\n },\n });\n\n if (t.openapi) {\n t.openapi.addHelperClass(OpenAPIArkHelper);\n }\n if (t.postman) {\n t.postman.addHelperClass(PostmanArkHelper);\n }\n },\n};\n"],"mappings":";;;;;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,EACF;AAAA,EACA,SAAW;AAAA,IACT,OAAS;AAAA,IACT,OAAS;AAAA,IACT,cAAc;AAAA,IACd,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,MAAQ;AAAA,IACR,MAAQ;AAAA,IACR,iBAAiB;AAAA,IACjB,QAAU;AAAA,EACZ;AAAA,EACA,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,SAAW;AAAA,EACX,cAAgB;AAAA,IACd,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,gCAAgC;AAAA,IAChC,SAAW;AAAA,IACX,OAAS;AAAA,EACX;AAAA,EACA,iBAAmB;AAAA,IACjB,gBAAgB;AAAA,EAClB;AAAA,EACA,kBAAoB;AAAA,IAClB,SAAW;AAAA,EACb;AACF;;;AC5CA,OAAO,UAAU;AASjB,SAAS,YAAuB;AAEhC,IAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,OAAO,MAAM,QAAQ,MAAM,SAAS,MAAM,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AO;AAE7B,wBAAU,IAAI;AAAA,YAClB,OAAO;AAEH,wBAAU;AAAA,YACd;AAGA,kBAAM,WAAW,KAAK,WAAW,OAAO;AAGxC,qBAAS,OAAO;AAAA,cACZ,iBAAiB;AAAA,YACrB;AAGA,gBAAI,OAAO,iBAAiB,eAAe,YAAY;AACnD,qBAAO,gBAAgB,WAAW,SAAS,GAAG,QAAQ;AAAA,YAC1D;AAGA,gBAAI,iBAAiB,eAAe,OAAO;AACvC,sBAAQ,IAAI,CAAC,cAAc,SAAS,WAAW,GAAG,UAAU,GAAG,QAAQ;AAAA,YAE3E;AAGA,mBAAO;AAAA,UACX;AAAA,QACJ,CAAC;AACD,eAAO,SAAS,UAAU,OAAO,SAAS;AAAA,MAC9C;AAAA,IACJ,CAAC;AAED,QAAI,EAAE,SAAS;AACX,QAAE,QAAQ,eAAe,gBAAgB;AAAA,IAC7C;AACA,QAAI,EAAE,SAAS;AACX,QAAE,QAAQ,eAAe,gBAAgB;AAAA,IAC7C;AAAA,EACJ;AACJ;","names":[]}
@@ -3,6 +3,7 @@ import { OpenAPIJsonHelper, PostmanJsonHelper } from '@novice1/api-doc-json-help
3
3
  import { Type } from 'arktype';
4
4
 
5
5
  declare class OpenAPIArkHelper extends OpenAPIJsonHelper implements KaapiOpenAPIHelperInterface {
6
+ protected _originalSchema?: Type;
6
7
  constructor(params: {
7
8
  value?: Type | object | unknown;
8
9
  isRoot?: boolean;
@@ -12,6 +13,7 @@ declare class OpenAPIArkHelper extends OpenAPIJsonHelper implements KaapiOpenAPI
12
13
  getChildren(): Record<string, OpenAPIArkHelper>;
13
14
  getAlternatives(): OpenAPIArkHelper[];
14
15
  isFile(): boolean | undefined;
16
+ isRequired(): boolean;
15
17
  getFilesChildren(): Record<string, unknown>;
16
18
  }
17
19
  declare class PostmanArkHelper extends PostmanJsonHelper {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIArkHelper,
3
3
  PostmanArkHelper
4
- } from "./chunk-3R3TW4ZK.js";
4
+ } from "./chunk-ML2GHWVG.js";
5
5
  export {
6
6
  OpenAPIArkHelper,
7
7
  PostmanArkHelper
package/lib/index.js CHANGED
@@ -2,11 +2,11 @@ import "./chunk-55J6XMHW.js";
2
2
  import {
3
3
  supportedProps,
4
4
  validatorArk
5
- } from "./chunk-HTN32YW4.js";
5
+ } from "./chunk-ZAKDEELE.js";
6
6
  import {
7
7
  OpenAPIArkHelper,
8
8
  PostmanArkHelper
9
- } from "./chunk-3R3TW4ZK.js";
9
+ } from "./chunk-ML2GHWVG.js";
10
10
  export {
11
11
  OpenAPIArkHelper,
12
12
  PostmanArkHelper,
@@ -1 +1 @@
1
- {"inputs":{"src/doc-helpers.ts":{"bytes":7238,"imports":[{"path":"@novice1/api-doc-json-helper","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":1833,"imports":[],"format":"esm"},"package.json":{"bytes":1797,"imports":[],"format":"esm","with":{"type":"json"}},"src/validator.ts":{"bytes":8695,"imports":[{"path":"package.json","kind":"import-statement","original":"../package.json","with":{"type":"json"}},{"path":"src/doc-helpers.ts","kind":"import-statement","original":"./doc-helpers.js"},{"path":"@hapi/boom","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":94,"imports":[{"path":"src/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/doc-helpers.ts","kind":"import-statement","original":"./doc-helpers.js"},{"path":"src/validator.ts","kind":"import-statement","original":"./validator.js"}],"format":"esm"}},"outputs":{"lib/doc-helpers.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/doc-helpers.js":{"imports":[{"path":"lib/chunk-3R3TW4ZK.js","kind":"import-statement"}],"exports":["OpenAPIArkHelper","PostmanArkHelper"],"entryPoint":"src/doc-helpers.ts","inputs":{},"bytes":129},"lib/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/index.js":{"imports":[{"path":"lib/chunk-55J6XMHW.js","kind":"import-statement"},{"path":"lib/chunk-HTN32YW4.js","kind":"import-statement"},{"path":"lib/chunk-3R3TW4ZK.js","kind":"import-statement"}],"exports":["OpenAPIArkHelper","PostmanArkHelper","supportedProps","validatorArk"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":265},"lib/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/types.js":{"imports":[{"path":"lib/chunk-55J6XMHW.js","kind":"import-statement"}],"exports":[],"entryPoint":"src/types.ts","inputs":{},"bytes":30},"lib/chunk-55J6XMHW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/chunk-55J6XMHW.js":{"imports":[],"exports":[],"inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"lib/validator.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/validator.js":{"imports":[{"path":"lib/chunk-HTN32YW4.js","kind":"import-statement"},{"path":"lib/chunk-3R3TW4ZK.js","kind":"import-statement"}],"exports":["supportedProps","validatorArk"],"entryPoint":"src/validator.ts","inputs":{},"bytes":147},"lib/chunk-HTN32YW4.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":14467},"lib/chunk-HTN32YW4.js":{"imports":[{"path":"lib/chunk-3R3TW4ZK.js","kind":"import-statement"},{"path":"@hapi/boom","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"exports":["supportedProps","validatorArk"],"inputs":{"package.json":{"bytesInOutput":1758},"src/validator.ts":{"bytesInOutput":4285}},"bytes":6205},"lib/chunk-3R3TW4ZK.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":11310},"lib/chunk-3R3TW4ZK.js":{"imports":[{"path":"@novice1/api-doc-json-helper","kind":"import-statement","external":true}],"exports":["OpenAPIArkHelper","PostmanArkHelper"],"inputs":{"src/doc-helpers.ts":{"bytesInOutput":5107}},"bytes":5181}}}
1
+ {"inputs":{"src/doc-helpers.ts":{"bytes":9157,"imports":[{"path":"@novice1/api-doc-json-helper","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":1833,"imports":[],"format":"esm"},"package.json":{"bytes":1797,"imports":[],"format":"esm","with":{"type":"json"}},"src/validator.ts":{"bytes":8695,"imports":[{"path":"package.json","kind":"import-statement","original":"../package.json","with":{"type":"json"}},{"path":"src/doc-helpers.ts","kind":"import-statement","original":"./doc-helpers.js"},{"path":"@hapi/boom","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":94,"imports":[{"path":"src/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/doc-helpers.ts","kind":"import-statement","original":"./doc-helpers.js"},{"path":"src/validator.ts","kind":"import-statement","original":"./validator.js"}],"format":"esm"}},"outputs":{"lib/doc-helpers.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/doc-helpers.js":{"imports":[{"path":"lib/chunk-ML2GHWVG.js","kind":"import-statement"}],"exports":["OpenAPIArkHelper","PostmanArkHelper"],"entryPoint":"src/doc-helpers.ts","inputs":{},"bytes":129},"lib/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/index.js":{"imports":[{"path":"lib/chunk-55J6XMHW.js","kind":"import-statement"},{"path":"lib/chunk-ZAKDEELE.js","kind":"import-statement"},{"path":"lib/chunk-ML2GHWVG.js","kind":"import-statement"}],"exports":["OpenAPIArkHelper","PostmanArkHelper","supportedProps","validatorArk"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":265},"lib/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/types.js":{"imports":[{"path":"lib/chunk-55J6XMHW.js","kind":"import-statement"}],"exports":[],"entryPoint":"src/types.ts","inputs":{},"bytes":30},"lib/chunk-55J6XMHW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/chunk-55J6XMHW.js":{"imports":[],"exports":[],"inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"lib/validator.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"lib/validator.js":{"imports":[{"path":"lib/chunk-ZAKDEELE.js","kind":"import-statement"},{"path":"lib/chunk-ML2GHWVG.js","kind":"import-statement"}],"exports":["supportedProps","validatorArk"],"entryPoint":"src/validator.ts","inputs":{},"bytes":147},"lib/chunk-ZAKDEELE.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":14467},"lib/chunk-ZAKDEELE.js":{"imports":[{"path":"lib/chunk-ML2GHWVG.js","kind":"import-statement"},{"path":"@hapi/boom","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"exports":["supportedProps","validatorArk"],"inputs":{"package.json":{"bytesInOutput":1758},"src/validator.ts":{"bytesInOutput":4285}},"bytes":6205},"lib/chunk-ML2GHWVG.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":14190},"lib/chunk-ML2GHWVG.js":{"imports":[{"path":"@novice1/api-doc-json-helper","kind":"import-statement","external":true},{"path":"arktype","kind":"import-statement","external":true}],"exports":["OpenAPIArkHelper","PostmanArkHelper"],"inputs":{"src/doc-helpers.ts":{"bytesInOutput":6443}},"bytes":6517}}}
package/lib/validator.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  supportedProps,
3
3
  validatorArk
4
- } from "./chunk-HTN32YW4.js";
5
- import "./chunk-3R3TW4ZK.js";
4
+ } from "./chunk-ZAKDEELE.js";
5
+ import "./chunk-ML2GHWVG.js";
6
6
  export {
7
7
  supportedProps,
8
8
  validatorArk
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaapi/validator-arktype",
3
3
  "type": "module",
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "private": false,
6
6
  "description": "ArkType-powered request validation and documentation plugin for Kaapi.",
7
7
  "main": "lib/index.js",
@@ -30,7 +30,7 @@
30
30
  "@novice1/api-doc-json-helper": "^1.0.6",
31
31
  "arktype": "^2.1.25",
32
32
  "tslib": "^2.8.1",
33
- "@kaapi/kaapi": "^0.0.23"
33
+ "@kaapi/kaapi": "^0.0.24"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/mocha": "^10.0.10"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/doc-helpers.ts"],"sourcesContent":["import type { KaapiOpenAPIHelperInterface } from '@kaapi/kaapi';\nimport { OpenAPIJsonHelper, PostmanJsonHelper } from '@novice1/api-doc-json-helper';\nimport type { Type, JsonSchema } from 'arktype';\n\nfunction transformValue(value?: Type | object | unknown) {\n let r: unknown = value;\n if (value && typeof value === 'function' && 'toJsonSchema' in value && typeof value.toJsonSchema === 'function') {\n r = (value as Type).toJsonSchema({\n fallback: (v) => {\n let r: JsonSchema & { _instanceof?: string } = {};\n let _instanceof = '';\n if (v && 'proto' in v && v.proto && typeof v.proto === 'function' && 'name' in v.proto) {\n r.type = 'object';\n r._instanceof = `${v.proto.name}`;\n _instanceof = `${v.proto.name}`;\n }\n if (v.base) {\n r = { ...r, ...v.base };\n if ('out' in v && v.out) {\n if ('anyOf' in r && 'type' in v.out) {\n const description = r.anyOf[0]?.description;\n r = { ...v.out };\n if (description) {\n r.description = description;\n }\n if (_instanceof) {\n r._instanceof = _instanceof;\n }\n } else {\n r = { ...r, ...v.out };\n }\n }\n }\n return r;\n },\n });\n }\n\n return r;\n}\n\nexport class OpenAPIArkHelper extends OpenAPIJsonHelper implements KaapiOpenAPIHelperInterface {\n constructor(\n params: {\n value?: Type | object | unknown;\n isRoot?: boolean;\n },\n isRequired?: boolean\n ) {\n super({ ...params, value: transformValue(params.value) }, isRequired);\n }\n isValid(): boolean {\n return !!(\n this._schema &&\n typeof this._schema === 'object' &&\n !('~standard' in this._schema) &&\n (('type' in this._schema && typeof this._schema.type === 'string') ||\n ('oneOf' in this._schema && Array.isArray(this._schema.oneOf)) ||\n ('anyOf' in this._schema && Array.isArray(this._schema.anyOf)) ||\n ('enum' in this._schema && Array.isArray(this._schema.enum)))\n );\n }\n getFirstItem(): OpenAPIArkHelper | undefined {\n const schema = this._schema;\n\n if ('items' in schema && typeof schema.items === 'object') {\n return new OpenAPIArkHelper({ value: schema.items });\n }\n\n return;\n }\n getChildren(): Record<string, OpenAPIArkHelper> {\n const r: Record<string, OpenAPIArkHelper> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n r[p] = new OpenAPIArkHelper({ value: properties[p] }, isRequired);\n }\n }\n return r;\n }\n getAlternatives(): OpenAPIArkHelper[] {\n const r: OpenAPIArkHelper[] = [];\n const schema = this._schema;\n if ('oneOf' in schema && Array.isArray(schema.oneOf)) {\n for (const p of schema.oneOf) {\n r.push(new OpenAPIArkHelper({ value: p }));\n }\n }\n return r;\n }\n isFile(): boolean | undefined {\n if (!this.isValid()) return false;\n let r: boolean = false;\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n r = !!(\n '_data' in properties &&\n properties._data &&\n typeof properties._data === 'object' &&\n '_instanceof' in properties._data &&\n properties._data._instanceof === 'Buffer'\n );\n }\n return r;\n }\n getFilesChildren(): Record<string, unknown> {\n const r: Record<string, unknown> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n const ch = new OpenAPIArkHelper({ value: properties[p] }, isRequired);\n if (ch.isFile()) {\n r[p] = properties[p];\n }\n }\n }\n return r;\n }\n}\n\nexport class PostmanArkHelper extends PostmanJsonHelper {\n constructor(\n params: {\n value?: Type | object | unknown;\n isRoot?: boolean;\n },\n isRequired?: boolean\n ) {\n super({ ...params, value: transformValue(params.value) }, isRequired);\n }\n isValid(): boolean {\n return !!(\n this._schema &&\n typeof this._schema === 'object' &&\n (('type' in this._schema && typeof this._schema.type === 'string') ||\n ('oneOf' in this._schema && Array.isArray(this._schema.oneOf)) ||\n ('anyOf' in this._schema && Array.isArray(this._schema.anyOf)) ||\n ('enum' in this._schema && Array.isArray(this._schema.enum)))\n );\n }\n getFirstItem(): PostmanArkHelper | undefined {\n const schema = this._schema;\n\n if ('items' in schema && typeof schema.items === 'object') {\n return new PostmanArkHelper({ value: schema.items });\n }\n\n return;\n }\n getChildren(): Record<string, PostmanArkHelper> {\n const r: Record<string, PostmanArkHelper> = {};\n const schema = this._schema;\n if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {\n const properties: Record<string, unknown> = schema.properties as Record<string, unknown>;\n for (const p in properties) {\n const isRequired: boolean =\n 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);\n r[p] = new PostmanArkHelper({ value: properties[p] }, isRequired);\n }\n }\n return r;\n }\n getAlternatives(): PostmanArkHelper[] {\n const r: PostmanArkHelper[] = [];\n const schema = this._schema;\n if ('oneOf' in schema && Array.isArray(schema.oneOf)) {\n for (const p of schema.oneOf) {\n r.push(new PostmanArkHelper({ value: p }));\n }\n }\n return r;\n }\n}\n"],"mappings":";AACA,SAAS,mBAAmB,yBAAyB;AAGrD,SAAS,eAAe,OAAiC;AACrD,MAAI,IAAa;AACjB,MAAI,SAAS,OAAO,UAAU,cAAc,kBAAkB,SAAS,OAAO,MAAM,iBAAiB,YAAY;AAC7G,QAAK,MAAe,aAAa;AAAA,MAC7B,UAAU,CAAC,MAAM;AACb,YAAIA,KAA2C,CAAC;AAChD,YAAI,cAAc;AAClB,YAAI,KAAK,WAAW,KAAK,EAAE,SAAS,OAAO,EAAE,UAAU,cAAc,UAAU,EAAE,OAAO;AACpF,UAAAA,GAAE,OAAO;AACT,UAAAA,GAAE,cAAc,GAAG,EAAE,MAAM,IAAI;AAC/B,wBAAc,GAAG,EAAE,MAAM,IAAI;A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