{"id":49284,"library":"schema-decorator","title":"schema-decorator","description":"DEPRECATED TypeScript library for runtime type validation and sanitization using decorators, version 2.61.2. Originally designed to secure web apps by validating route params, query strings, JSON bodies, and responses, plus schemaless database data. Offers AssertDelegate<> and sd.check<> for runtime enforcement with compile-time type inference via TypeOf<> and AcceptsOf<>. Deprecated in favor of type-mapping.","status":"deprecated","version":"2.61.2","language":"javascript","source_language":"en","source_url":"https://github.com/AnyhowStep/schema-decorator","tags":["javascript","typescript"],"install":[{"cmd":"npm install schema-decorator","lang":"bash","label":"npm"},{"cmd":"yarn add schema-decorator","lang":"bash","label":"yarn"},{"cmd":"pnpm add schema-decorator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exports a namespace, not named exports; use wildcard import.","wrong":"import { schema-decorator } from 'schema-decorator'","symbol":"sd","correct":"import * as sd from 'schema-decorator'"},{"note":"naturalNumber is a method on the default export, not a named export.","wrong":"import { naturalNumber } from 'schema-decorator'; naturalNumber()('x', 34)","symbol":"naturalNumber","correct":"import * as sd from 'schema-decorator'; const x = sd.naturalNumber()('x', 34)"},{"note":"TypeOf is a helper type accessible via namespace.","wrong":"import { TypeOf } from 'schema-decorator'","symbol":"TypeOf","correct":"import * as sd from 'schema-decorator'; type N = sd.TypeOf<typeof someAssert>"},{"note":"check is a function on the namespace; CommonJS destructuring works but ESM style is preferred.","wrong":"const { check } = require('schema-decorator')","symbol":"check","correct":"import * as sd from 'schema-decorator'; sd.check(sd.naturalNumber(), 'x', 34)"}],"quickstart":{"code":"import * as sd from 'schema-decorator';\n\n// Validate natural number\nconst x = sd.naturalNumber()('x', 34);\nconsole.log(x); // 34\n\n// Will throw at runtime\ntry {\n  sd.naturalNumber()('y', 34.5);\n} catch (e) {\n  console.error(e.message); // \"Expected y to be a natural number\"\n}\n\n// Compile-time check using sd.check<>()\nconst y = sd.check(sd.naturalNumber(), 'z', 123); // OK\n// sd.check(sd.naturalNumber(), 'z', '34'); // Compile-time error: Argument of type '\"34\"' is not assignable to parameter of type 'number'.","lang":"typescript","description":"Illustrates basic usage of naturalNumber() assert delegate, runtime error on invalid input, and compile-time check with sd.check()."},"warnings":[{"fix":"Replace with type-mapping (https://github.com/anyhowstep/type-mapping)","message":"Package is deprecated; use type-mapping instead.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use sd.naturalNumber()('field', value) instead of sd.naturalNumber()","message":"naturalNumber() returns a function, not a direct value; must call it with (name, mixed).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use TypeScript for type inference; otherwise, rely on runtime checks.","message":"TypeOf<> and AcceptsOf<> are types, not runtime values; cannot be used in JavaScript (non-TypeScript) projects.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2.61.2':16 'acceptsof':53 'app':22 'assertdeleg':38 'bodi':30 'compil':46 'compile-tim':45 'data':36 'databas':35 'decor':3,14 'deprec':4,54 'design':18 'enforc':43 'favor':56 'infer':49 'javascript':61 'json':29 'librari':6 'map':60 'offer':37 'origin':17 'param':26 'plus':33 'queri':27 'respons':32 'rout':25 'runtim':8,42 'sanit':12 'schema':2 'schema-decor':1 'schemaless':34 'sd.check':40 'secur':20 'string':28 'time':47 'type':9,48,59 'type-map':58 'typeof':51 'typescript':5,62 'use':13 'valid':10,24 'version':15 'via':50 'web':21","created_at":"2026-06-07T17:00:58.979779+00:00","updated_at":"2026-06-07T17:00:58.979779+00:00","problems":[{"fix":"Use 'import * as sd from 'schema-decorator'' then call sd.naturalNumber()","cause":"Incorrect import: using named import instead of namespace import.","error":"TypeError: sd.naturalNumber is not a function"},{"fix":"Ensure the value matches the expected type, or use the raw assert delegate (which allows any at compile time).","cause":"Passing a string literal to sd.check() when the assert expects number.","error":"Argument of type '\"34\"' is not assignable to parameter of type 'number'."},{"fix":"Add 'import * as sd from 'schema-decorator'' at top of file.","cause":"Forget to import the package.","error":"Cannot find name 'sd'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/AnyhowStep/schema-decorator#readme","github":"https://github.com/AnyhowStep/schema-decorator","docs":null,"changelog":null,"pypi":null,"npm":"schema-decorator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["security","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}