
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@forgehive/schema
Advanced tools
A powerful schema validation library built on top of Zod, providing type-safe validation and type inference.
A powerful schema validation library built on top of Zod, providing type-safe validation and type inference.
npm install @forgehive/schema
The @forgehive/schema
package provides a wrapper around Zod with additional features:
Here's a simple example of creating and using a schema:
import { Schema } from '@forgehive/schema';
// Create a schema with validation
const userSchema = new Schema({
name: Schema.string(),
age: Schema.number().min(0).max(120),
email: Schema.string().email(),
tags: Schema.array(Schema.string())
});
// Validate data
const result = userSchema.safeParse({
name: 'John Doe',
age: 30,
email: 'john@example.com',
tags: ['user', 'active']
});
if (result.success) {
// TypeScript knows the shape of the data
const user = result.data;
console.log(user.name); // TypeScript knows this is a string
}
The package provides several schema types:
// Basic types
Schema.string()
Schema.number()
Schema.boolean()
Schema.date()
// Arrays
Schema.array(Schema.string())
Schema.array(Schema.number())
Schema.array(Schema.boolean())
Schema.array(Schema.date())
// Records
Schema.stringRecord() // Record<string, string>
Schema.numberRecord() // Record<string, number>
Schema.booleanRecord() // Record<string, boolean>
Schema.mixedRecord() // Record<string, string | number | boolean>
Schemas provide several validation methods:
const schema = new Schema({
name: Schema.string(),
age: Schema.number()
});
// Parse and throw on error
const data = schema.parse({ name: 'John', age: 30 });
// Safe parse with result object
const result = schema.safeParse({ name: 'John', age: 30 });
if (result.success) {
const data = result.data;
} else {
const errors = result.error;
}
// Validate without parsing
const isValid = schema.validate({ name: 'John', age: 30 });
You can get a description of the schema structure:
const schema = new Schema({
name: Schema.string(),
age: Schema.number().min(0),
email: Schema.string().email()
});
const description = schema.describe();
// Returns:
// {
// name: { type: 'string' },
// age: { type: 'number', validations: { min: 0 } },
// email: { type: 'string', validations: { email: true } }
// }
The package provides type utilities for inferring types from schemas:
import { Schema, type InferSchema } from '@forgehive/schema';
const schema = new Schema({
name: Schema.string(),
age: Schema.number()
});
// Infer the type from the schema
type User = InferSchema<typeof schema>;
// Type is: { name: string; age: number }
Schema
Classconstructor(fields: Record<string, SchemaType>)
: Creates a new schemaparse(data: unknown)
: Parses and validates data, throws on errorsafeParse(data: unknown)
: Safely parses and validates datavalidate(data: unknown)
: Validates data without parsingdescribe()
: Returns a description of the schema structureasZod()
: Returns the underlying Zod schemastring()
: Creates a string schemanumber()
: Creates a number schemaboolean()
: Creates a boolean schemadate()
: Creates a date schemaarray(type)
: Creates an array schemastringRecord()
: Creates a record schema with string valuesnumberRecord()
: Creates a record schema with number valuesbooleanRecord()
: Creates a record schema with boolean valuesmixedRecord()
: Creates a record schema with mixed valuesMIT
FAQs
A powerful schema validation library built on top of Zod, providing type-safe validation and type inference.
The npm package @forgehive/schema receives a total of 51 weekly downloads. As such, @forgehive/schema popularity was classified as not popular.
We found that @forgehive/schema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.