Registry / database / spraypaint

spraypaint

JSON →
library0.10.24jsnpmunverified

JS Client for Graphiti, a JSON:API-compliant ORM similar to ActiveRecord. v0.10.24 is current. Supports TypeScript and plain JavaScript, isomorphic (browser + Node.js). Key differentiators: decorator-based model definitions, fluent query builder, includes/pagination/sorting. Actively maintained with regular releases.

npm install spraypaint
INSTALL
IMPORT
SIG · SPRAYPAINT
S
spraypaint
databasejavascriptv0.10.24
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.

SpraypaintBase
import { SpraypaintBase } from 'spraypaint'
const SpraypaintBase = require('spraypaint').SpraypaintBase
ESM only. Default export is not available; use named imports.
Model
import { Model } from 'spraypaint'
import * as spraypaint from 'spraypaint'; @spraypaint.Model()
Model is a decorator function, not a class. Must be imported directly for decorator syntax.
Attr
import { Attr } from 'spraypaint'
import { Attribute } from 'spraypaint'
Use @Attr() not @Attribute().
HasMany
import { HasMany } from 'spraypaint'
import { hasMany } from 'spraypaint'
Decorator is PascalCase 'HasMany'.
JsonapiQuery
import { JsonapiQuery } from 'spraypaint'
For advanced query building.

Demonstrates defining models with decorators, configuring base URL, and using chained query methods.

import { SpraypaintBase, Model, Attr, HasMany } from 'spraypaint' import 'reflect-metadata' @Model() class ApplicationRecord extends SpraypaintBase { static baseUrl = 'http://localhost:3000' static apiNamespace = '/api/v1' } @Model() class Person extends ApplicationRecord { static jsonapiType = 'people' @Attr() firstName!: string @Attr() lastName!: string @HasMany() pets!: Pet[] } @Model() class Pet extends ApplicationRecord { static jsonapiType = 'pets' @Attr() name!: string } async function main() { const { data } = await Person .where({ name: 'Joe' }) .page(2).per(10) .sort('name') .includes('pets') .all() data.forEach(p => console.log(p.fullName)) }
Debug
Known issues
breakingVersion 0.10.0 changed decorator syntax: classes must be decorated with @Model() to be recognized.
fix
Add @Model() decorator to all model classes extending SpraypaintBase.
affects: >=0.10.0
deprecatedOld spelling 'Attribute' is removed; use 'Attr' instead.
fix
Replace @Attribute() with @Attr().
affects: >=0.8.0
gotchareflect-metadata must be imported at the entry point of the application for decorators to work.
fix
Add 'import "reflect-metadata"' at the top of your main file.
affects: >=0.6.0
gotchaTypeScript strict mode may require definite assignment assertions (!) for model attributes.
fix
Declare attributes with '!' as in '@Attr() firstName!: string'
affects: >=0.9.0
gotchaAll models must have a static 'jsonapiType' property (string). If missing, calls fail with a misleading TypeError.
fix
Define static jsonapiType = 'your-type-string' in each model.
affects: >=0.5.0
gotchabaseUrl and apiNamespace are static properties on the base class, not instance properties.
fix
Set static baseUrl and static apiNamespace on the ApplicationRecord or each model.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing or incorrect import of SpraypaintBase.
fix
Ensure import { SpraypaintBase } from 'spraypaint' is correct and reflect-metadata is imported before usage.
Cannot find module 'reflect-metadata'
reflect-metadata is not installed in the project.
fix
Run 'npm install reflect-metadata' and add import 'reflect-metadata' at the top of your entry file.
TypeError: Cannot read properties of undefined (reading 'prototype')
Model class is not decorated with @Model().
fix
Add the @Model() decorator to the model class definition.
Error: Each model must have a jsonapiType static property
Missing static jsonapiType in model class.
fix
Add 'static jsonapiType = 'your-type-name'' to the model.
Upgrade
Version history
0.10.24latest on npm
Audit
Dependencies
reflect-metadatarequiredRequired for decorator support in TypeScript
Agent activity
6 hits · last 30 days
node
4
Meta
2
Resources
spraypaint — npm install spraypaint · libregistry