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.

npm install schema-decorator
INSTALL
IMPORT
SIG · SCHEMA-DECORATOR
S
schema-decorator
securityjavascriptv2.61.2
harness data pending
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.

sd
import * as sd from 'schema-decorator'
import { schema-decorator } from 'schema-decorator'
Package exports a namespace, not named exports; use wildcard import.
naturalNumber
import * as sd from 'schema-decorator'; const x = sd.naturalNumber()('x', 34)
import { naturalNumber } from 'schema-decorator'; naturalNumber()('x', 34)
naturalNumber is a method on the default export, not a named export.
TypeOf
import * as sd from 'schema-decorator'; type N = sd.TypeOf<typeof someAssert>
import { TypeOf } from 'schema-decorator'
TypeOf is a helper type accessible via namespace.
check
import * as sd from 'schema-decorator'; sd.check(sd.naturalNumber(), 'x', 34)
const { check } = require('schema-decorator')
check is a function on the namespace; CommonJS destructuring works but ESM style is preferred.

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 issues
deprecatedPackage is deprecated; use type-mapping instead.
fix
Replace with type-mapping (https://github.com/anyhowstep/type-mapping)
affects: >=0.0.0
gotchanaturalNumber() returns a function, not a direct value; must call it with (name, mixed).
fix
Use sd.naturalNumber()('field', value) instead of sd.naturalNumber()
affects: >=0.0.0
gotchaTypeOf<> and AcceptsOf<> are types, not runtime values; cannot be used in JavaScript (non-TypeScript) projects.
fix
Use TypeScript for type inference; otherwise, rely on runtime checks.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: sd.naturalNumber is not a function
Incorrect import: using named import instead of namespace import.
fix
Use 'import * as sd from 'schema-decorator'' then call sd.naturalNumber()
Argument of type '"34"' is not assignable to parameter of type 'number'.
Passing a string literal to sd.check() when the assert expects number.
fix
Ensure the value matches the expected type, or use the raw assert delegate (which allows any at compile time).
Cannot find name 'sd'
Forget to import the package.
fix
Add 'import * as sd from 'schema-decorator'' at top of file.
Upgrade
Version history
2.61.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
schema-decorator — npm install schema-decorator · libregistry