{"version":3,"file":"schema-C5viMUkI.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n  JsonSchema7AllOfType,\n  JsonSchema7ArrayType,\n  JsonSchema7BooleanType,\n  JsonSchema7LiteralType,\n  JsonSchema7NumberType,\n  JsonSchema7ObjectType,\n  JsonSchema7PrimitiveLiteralType,\n  JsonSchema7StringType,\n  JsonSchema7TupleType\n} from \"./types\";\n\n/**\n * Type guard for {@link JsonSchema7AllOfType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7AllOfType}, false otherwise\n */\nexport function isJsonSchema7AllOfType(\n  schema: any\n): schema is JsonSchema7AllOfType {\n  if (\"type\" in schema && schema.type === \"string\") {\n    return false;\n  }\n\n  return \"allOf\" in schema;\n}\n\n/**\n * Type guard for {@link JsonSchema7ObjectType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7ObjectType}, false otherwise\n */\nexport function isJsonSchema7ObjectType(\n  schema: any\n): schema is JsonSchema7ObjectType {\n  return \"type\" in schema && schema.type === \"object\";\n}\n\n/**\n * Type guard for {@link JsonSchema7StringType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7StringType}, false otherwise\n */\nexport function isJsonSchema7StringType(\n  schema: any\n): schema is JsonSchema7StringType {\n  return \"type\" in schema && schema.type === \"string\";\n}\n\n/**\n * Type guard for {@link JsonSchema7NumberType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7NumberType}, false otherwise\n */\nexport function isJsonSchema7NumberType(\n  schema: any\n): schema is JsonSchema7NumberType {\n  return (\n    \"type\" in schema && (schema.type === \"number\" || schema.type === \"integer\")\n  );\n}\n\n/**\n * Type guard for {@link JsonSchema7BooleanType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7BooleanType}, false otherwise\n */\nexport function isJsonSchema7BooleanType(\n  schema: any\n): schema is JsonSchema7BooleanType {\n  return \"type\" in schema && schema.type === \"boolean\";\n}\n\n/**\n * Type guard for {@link JsonSchema7ArrayType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7ArrayType}, false otherwise\n */\nexport function isJsonSchema7ArrayType(\n  schema: any\n): schema is JsonSchema7ArrayType {\n  return \"type\" in schema && schema.type === \"array\" && \"items\" in schema;\n}\n\n/**\n * Type guard for {@link JsonSchema7TupleType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7TupleType}, false otherwise\n */\nexport function isJsonSchema7TupleType(\n  schema: any\n): schema is JsonSchema7TupleType {\n  return (\n    \"type\" in schema &&\n    schema.type === \"array\" &&\n    \"items\" in schema &&\n    Array.isArray(schema.items)\n  );\n}\n\n/**\n * Type guard for {@link JsonSchema7PrimitiveLiteralType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7PrimitiveLiteralType}, false otherwise\n */\nexport function isJsonSchema7PrimitiveLiteralType(\n  schema: any\n): schema is JsonSchema7PrimitiveLiteralType {\n  if (!(\"type\" in schema)) {\n    return false;\n  }\n\n  const { type } = schema;\n\n  return (\n    (type === \"string\" ||\n      type === \"number\" ||\n      type === \"integer\" ||\n      type === \"boolean\") &&\n    \"const\" in schema\n  );\n}\n\n/**\n * Type guard for {@link JsonSchema7LiteralType}\n *\n * @param schema - The schema to check\n * @returns True if the schema is a {@link JsonSchema7LiteralType}, false otherwise\n */\nexport function isJsonSchema7LiteralType(\n  schema: any\n): schema is JsonSchema7LiteralType {\n  if (isJsonSchema7PrimitiveLiteralType(schema)) {\n    return true;\n  }\n\n  if (!(\"type\" in schema)) {\n    return false;\n  }\n\n  return schema.type === \"object\" || schema.type === \"array\";\n}\n\n/**\n * Type guard to check if a value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}.\n *\n * @remarks\n * This function checks if the value has the structure of a Standard JSON Schema, which includes a `~standard` property with a `jsonSchema` object that has `input` and `output` functions.\n *\n * @see https://standardschema.dev/json-schema\n *\n * @param value - The value to check.\n * @returns True if the value is a {@link StandardJSONSchemaV1 | Standard JSON Schema}, false otherwise.\n */\nexport function isStandardJsonSchema<Input = unknown, Output = Input>(\n  value: any\n): value is StandardJSONSchemaV1<Input, Output> {\n  return (\n    isSetObject(value) &&\n    \"~standard\" in value &&\n    isSetObject(value[\"~standard\"]) &&\n    \"jsonSchema\" in value[\"~standard\"] &&\n    isSetObject(value[\"~standard\"].jsonSchema) &&\n    \"input\" in value[\"~standard\"].jsonSchema &&\n    isFunction(value[\"~standard\"].jsonSchema.input) &&\n    \"output\" in value[\"~standard\"].jsonSchema &&\n    isFunction(value[\"~standard\"].jsonSchema.output)\n  );\n}\n"],"mappings":";;;;;;;;;AAuCA,SAAgB,uBACd,QACgC;AAChC,KAAI,UAAU,UAAU,OAAO,SAAS,SACtC,QAAO;AAGT,QAAO,WAAW;;;;;;;;AASpB,SAAgB,wBACd,QACiC;AACjC,QAAO,UAAU,UAAU,OAAO,SAAS;;;;;;;;AAS7C,SAAgB,wBACd,QACiC;AACjC,QAAO,UAAU,UAAU,OAAO,SAAS;;;;;;;;AAS7C,SAAgB,wBACd,QACiC;AACjC,QACE,UAAU,WAAW,OAAO,SAAS,YAAY,OAAO,SAAS;;;;;;;;AAUrE,SAAgB,yBACd,QACkC;AAClC,QAAO,UAAU,UAAU,OAAO,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