Registry / security / schema-decorator

schema-decorator

JSON →
library2.61.2jsnpmunverified

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.

securitytesting
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Package exports a namespace, not named exports; use wildcard import.

import * as sd from 'schema-decorator'

naturalNumber is a method on the default export, not a named export.

import * as sd from 'schema-decorator'; const x = sd.naturalNumber()('x', 34)

TypeOf is a helper type accessible via namespace.

import * as sd from 'schema-decorator'; type N = sd.TypeOf<typeof someAssert>

check is a function on the namespace; CommonJS destructuring works but ESM style is preferred.

import * as sd from 'schema-decorator'; sd.check(sd.naturalNumber(), 'x', 34)

Illustrates basic usage of naturalNumber() assert delegate, runtime error on invalid input, and compile-time check with sd.check().

import * as sd from 'schema-decorator'; // Validate natural number const x = sd.naturalNumber()('x', 34); console.log(x); // 34 // Will throw at runtime try { sd.naturalNumber()('y', 34.5); } catch (e) { console.error(e.message); // "Expected y to be a natural number" } // Compile-time check using sd.check<>() const y = sd.check(sd.naturalNumber(), 'z', 123); // OK // sd.check(sd.naturalNumber(), 'z', '34'); // Compile-time error: Argument of type '"34"' is not assignable to parameter of type 'number'.
Debug
Known footguns
deprecatedPackage is deprecated; use type-mapping instead.
gotchanaturalNumber() returns a function, not a direct value; must call it with (name, mixed).
gotchaTypeOf<> and AcceptsOf<> are types, not runtime values; cannot be used in JavaScript (non-TypeScript) projects.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
20 hits · last 30 days
gptbot
3
bytedance
3
ahrefsbot
1
amazonbot
1
Resources