Registry / database / mobiletto-orm-typedef

mobiletto-orm-typedef

JSON →
library2.4.5jsnpmunverified

mobiletto-orm-typedef is a shared type definition system for mobiletto-orm, providing `MobilettoOrmTypeDef` and error types independent of the underlying mobiletto and mobiletto-orm libraries. Version 2.4.5 is the current stable release, updated regularly with patches. It enables frontend form validation synchronized with backend storage validation, without requiring frontend code to depend on mobiletto or mobiletto-orm. Key differentiator: decouples type definitions from ORM logic, allowing lightweight frontend integration.

npm install mobiletto-orm-typedef
INSTALL
IMPORT
SIG · MOBILETTO-ORM-TYPE
M
mobiletto-orm-typedef
databasejavascriptv2.4.5
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.

MobilettoOrmTypeDef
import { MobilettoOrmTypeDef } from 'mobiletto-orm-typedef'
const { MobilettoOrmTypeDef } = require('mobiletto-orm-typedef')
The package is ESM-only; CommonJS require is not supported.
MobilettoOrmError
import { MobilettoOrmError } from 'mobiletto-orm-typedef'
import MobilettoOrmError from 'mobiletto-orm-typedef'
Named export, not default export.
type definitions
import type { SomeType } from 'mobiletto-orm-typedef'
import { SomeType } from 'mobiletto-orm-typedef'
For type-only imports, use `import type` to avoid runtime overhead. Package ships TypeScript types.

Demonstrates importing and using MobilettoOrmTypeDef to define a user schema and validate an object against it.

import { MobilettoOrmTypeDef, MobilettoOrmError, MobilettoOrmValidationError } from 'mobiletto-orm-typedef'; // Define a type def for a user object const userTypeDef = new MobilettoOrmTypeDef('user', { name: { type: 'string', required: true }, email: { type: 'string', required: true, pattern: /^[^@]+@[^@]+\.[^@]+$/ }, age: { type: 'number', optional: true, min: 0, max: 150 } }); // Validate an object against the type def const errors = userTypeDef.validate({ name: 'Alice', email: 'alice@example.com', age: 30 }); if (errors.length > 0) { console.error('Validation failed:', errors); } else { console.log('Validation passed'); }
Debug
Known issues
breakingBreaking change: v2 removed support for CommonJS require; package is now ESM-only.
fix
Switch to ESM imports: `import { MobilettoOrmTypeDef } from 'mobiletto-orm-typedef'`.
affects: >=2.0.0
deprecatedThe default export `MobilettoOrmTypeDef` replaced by named exports; default export removed in v2.
fix
Use named export: `import { MobilettoOrmTypeDef } from 'mobiletto-orm-typedef'`.
affects: >=2.0.0
gotchaType validation pattern uses RegExp; ensure regex is properly escaped when constructing pattern strings.
fix
Use RegExp literals (e.g., `/pattern/`) or `new RegExp('escaped pattern')`.
affects: >=0.0.0
gotchaField order in type definition may affect serialization order in some storage backends.
fix
Specify field order explicitly if required by backend; use ordered objects.
affects: >=0.0.0
gotchaMin/Max validation for numbers only works if `type: 'number'` is set; otherwise ignored.
fix
Ensure field type is 'number' for numeric constraints.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ESM import syntax in a CommonJS project without proper module configuration.
fix
Set `"type": "module"` in package.json or use `.mjs` extension for ESM files.
TypeError: MobilettoOrmTypeDef is not a constructor
Importing default export instead of named export in v2.
fix
Use `import { MobilettoOrmTypeDef } from 'mobiletto-orm-typedef'` instead of default import.
Error: Validation failed: email must be a string
Passing a non-string value for a field with `type: 'string'`.
fix
Ensure all required fields are of the correct type before validation.
Upgrade
Version history
2.4.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
24
Resources
mobiletto-orm-typedef — npm install mobiletto-orm-typedef · libregistry