Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@sdxc/data-model

Latest version: v2026.11.29

Overview

Last scanned
29 Nov 2026
Published
29 Nov 2026
npm package Publisher: sergiodxa
18 Stars
1 Forks
15 Versions
816 Downloads
TypeScript Repo language

Scan summary

@sdxc/data-model was last scanned on 29 Nov 2026 at version 2026.11.29. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 15 versions; the latest was published on 29 Nov 2026.
  • Findings: No rules fired in version 2026.11.29.
  • Downloads: 816 downloads.

Versions

15 versions published
Versions and the rules that fired in each
VersionPublishedStatus
2026.11.29 LATEST 29 Nov 2026 No rules fired
2026.11.22 22 Nov 2026 No rules fired
2026.11.10 10 Nov 2026 No rules fired
2026.11.3 3 Nov 2026 Not shown
2026.10.25 25 Oct 2026 Not shown

No rules fired in 2026.11.29

Findings

Findings for v2026.11.29. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 2026.11.29; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

@sdxc/data-model

Models over remix/data-table tables with scopes, async callbacks and typed meta fields.

A model is a remix/data-table table plus named scopes, custom methods, async callbacks and typed fields over a key/value meta table. Define it once and bind it per request, job or test to the right database; rows stay the plain objects data-table returns, and every scope is a real data-table Query, so pagination, search and eager loading take them unchanged.

Installation

npm add @sdxc/data-model

Tables come from remix/data-table in remix; writes answer a Result from @sdxc/result and fail with the ValidationError from @sdxc/validate. The ./jobs entry point needs @sdxc/jobs, ./cli needs @sdxc/cli, and ./testing and ./seed need @sdxc/sample.

Usage

Define a model
import { createModel } from "@sdxc/data-model";
import { generateUUID } from "@sdxc/uuid/v7";
import { fail } from "remix/data-table";

import { users } from "./schema.js";

export const Users = createModel(users, {
    generateId: generateUUID,
    defaultScope: (query) => query.where({ deleted_at: null }),
    scopes: {
        inTeam: (query, teamId: string) => query.where({ team_id: teamId }),
    },
    methods: {
        findByEmail(email: string) {
            return this.query().where({ email: email.toLowerCase() }).first();
        },
    },
    callbacks: {
        async validate(values) {
            if (values.name === "") return fail("Name is required", ["name"]);
        },
        async beforeCreate(values) {
            return { ...values, email: values.email.toLowerCase() };
        },
    },
});
Bind it, read and write
import { ConstraintViolation } from "@sdxc/data-model";
import { isFailure } from "@sdxc/result";

let users = Users.bind({ db });

let created = await users.create({ email: "Pat@Example.com", name: "Pat" });
if (isFailure(created)) {
    if (created.error instanceof ConstraintViolation && created.error.kind === "unique") {
        return "That email is taken";
    }
    return created.error.issues;
}

await users.find(created.data.id); // the row, or null
await users.inTeam(teamId).orderBy("name", "asc").all(); // deleted users left out
await users.unscoped().where({ id }).first(); // including deleted ones

Reads answer null for a missing row. create, update, upsert and delete answer a Result: a callback's fail(...) or a database constraint comes back as a ValidationError, and an update or delete of a row the model cannot see comes back as NotFound.

Publish models per request
import { createModels } from "@sdxc/data-model";
import { models } from "@sdxc/data-model/router";
import { createRouter } from "remix/fetch-router";

export const registry = createModels({
    users: Users,
    articles: () => import("./models/articles.js"),
});

let router = createRouter({
    middleware: [database(), models(registry, (ctx) => ({ db: ctx.db }))],
});

router.get(routes.users.show, async (ctx) => {
    let user = await ctx.models.users.findByEmail(ctx.url.searchParams.get("email") ?? "");
    return user === null ? new Response(null, { status: 404 }) : Response.json(user);
});

The context function runs once per request, on the first model access, so it reads whatever earlier middleware published. An entry written as an import loads on its first call.

./jobs and ./cli export the same models() for a job dispatcher and an @sdxc/cli command line, publishing under the same Models key:

import { createCLI, failure, success } from "@sdxc/cli";
import { models } from "@sdxc/data-model/cli";
import { database } from "@sdxc/database-middleware/cli";

let cli = createCLI({
    name: "app",
    commands: contract,
    middleware: [database(db), models(registry, (ctx) => ({ db: ctx.db }))],
});

cli.map(contract.users.find, async (ctx) => {
    let user = await ctx.models.users.findByEmail(ctx.arguments.email);
    if (user === null) return failure(new Error(`No user ${ctx.arguments.email}`));
    ctx.stdout(`${user.id}\t${user.name}\n`);
    return success();
});
Reach services and defer side effects

Callbacks receive a ModelContext and methods read it as this.context: db, models (the rest of the registry, bound alongside) and get(key), which reads the host context. Add whatever else your models need to the interface, and supply it wherever you bind:

import type { BoundModels } from "@sdxc/data-model";
import type { JobEnqueuer } from "@sdxc/jobs";

interface AppModels {
    users: typeof Users;
    teams: typeof Teams;
}

declare module "@sdxc/data-model" {
    interface ModelContext {
        jobs: JobEnqueuer;
        models: BoundModels<AppModels>;
    }
}

export const Users = createModel(users, {
    methods: {
        async signUp(email: string, name: string) {
            let user = await this.create({ email, name });
            if (isFailure(user)) return user;
            return this.context.models.teams.create({ owner_id: user.data.id, name: "Personal" });
        },
    },
    callbacks: {
        async afterCommit(event, ctx) {
            if (event.operation === "create")
                await ctx.jobs.enqueue(sendWelcome, { userId: event.row.id });
        },
    },
});

router.use(models(registry, (ctx) => ({ db: ctx.db, jobs: ctx.jobs })));

let result = await ctx.models.transaction(async (models) => {
    let user = await models.users.create({ email, name });
    if (isFailure(user)) return user;
    return models.teams.create({ owner_id: user.data.id, name: "Personal" });
});

Inside transaction, afterCommit events queue and flush once the callback resolves with anything but a Failure; a throw or a returned Failure drops them. Writes roll back only where the database has real transactions, so on D1 the user above stays written when the team fails, and no welcome job goes out for it.

Type models from an interface listing the entries rather than from typeof registry, so a method calling a sibling leaves the rest of the registry's type alone.

API

createModel(table, options?)

Defines a model over a data-table table. Every option is optional:

  • scopes: named refinements (query, ...args) => query, callable on the bound model and on every query from it. A scope may call where, having, orderBy, groupBy, limit, offset and distinct; with() and select() change the row type, so they belong in methods.
  • defaultScope: a scope every read applies, including the row an update or delete targets. unscoped() reads without it.
  • methods: custom methods with this bound to the model. Each answers a promise or a model query; a method answering a plain value, or a method or scope named like a built-in member (see ReservedName), turns the definition into an InvalidModel naming it.
  • callbacks: validate, beforeCreate, beforeUpdate, beforeDelete, afterCreate, afterUpdate, afterDelete and afterCommit, all async and all receiving the ModelContext. validate and before* fail with fail(...) from remix/data-table; before* may return rewritten values.
  • constraints: columns pinned to fixed values. Every read filters on them, every create writes them, and an update or delete of a row outside them answers NotFound.
  • inheritance: the discriminator column extend() pins sub-models on.
  • optional: columns create may leave out because a callback or the database fills them. Nullable columns and created_at/updated_at are optional already.
  • generateId: creates the primary key of a row create or upsert inserts without one, such as generateUUID from @sdxc/uuid/v7, and makes the key optional in create. A key the caller passes is kept; the table needs a single-column primary key.
  • metaTable and meta: a key/value companion table and the typed fields read from it.
withContext<Context>()

Answers { createModel } typed with Context in place of ModelContext, for an app binding one registry per database. Declare Context as an interface extending ModelContext; an intersection type resolves eagerly and makes the models circular.

interface FeedContext extends ModelContext {
    models: BoundModels<FeedModels>;
}

export const { createModel } = withContext<FeedContext>();
definition.bind(context, host?, options?)

Binds a model for a script, a seed or a test. context holds db and every member the app added to ModelContext; host is what ctx.get reads through to, such as a RequestContext; options.transactions is "database" for an adapter with real transactions and "none", the default, for D1 and Durable Object SQLite.

definition.extend(value, options)

A sub-model pinned to one value of the base's inheritance column, with every scope, method and callback of the base; its own callbacks run after the base's. A scope or method named like one of the base's is a type error.

Bound model
Member Answers
query(), scopes A data-table Query with the model's scopes chainable
unscoped() The same, without the default scope
withMeta(keys) A query loading only those meta keys
whereMeta(key, v) A query keeping rows holding v under the key
from(query) Another package's query, with constraints and scopes added
find(key) Row \| null
findBy(where) Row \| null
create(values) Result<Row, ValidationError>
update(key, values) Result<Row, ValidationError \| NotFound>
upsert(values, opts) Result<Row, ValidationError>, in one statement
delete(key) Result<Row, ValidationError \| NotFound>
transaction(fn) Whatever fn returns, with afterCommit deferred
db The database it is bound to, for a method's raw statement
context The model context
load() The bound model once a lazily loaded module has loaded

A single key is the column's value, a composite key an object; a key of any other shape, such as a list, answers null from find and NotFound from update and delete. Every update sets the table's updatedAt column, so update(key, {}) marks a row as changed and runs the update callbacks.

upsert(values, { conflict, update }) is one INSERT … ON CONFLICT statement, so it runs no callbacks and supplies its own id. conflict defaults to the primary key; update defaults to the values without the conflict and key columns and createdAt, and update: {} keeps a conflicting row as it is. A model with constraints reads the conflict target first, so a conflicting row outside them is refused and left as it is.

A bulk write built from a query, users.inTeam(teamId).update({ ... }, { touch: false }), is data-table's own statement and runs no callbacks; touch: false leaves updatedAt as it is and returning answers the updated rows.

createModels(entries)

A registry keyed by the name each model is bound under. An entry is a model or a function importing a module that default-exports one. registry.bind(context, host?, options?) binds every entry, and the bound registry's transaction(fn) opens a unit of work across them.

field

Meta field codecs: text, integer, number, boolean, timestamp, url (http and https only, so a stored value is safe to link to), enum(values), json(schema) and list(field). Every field reads as T | undefined unless it declares .default(value); .required() makes create refuse a write without it.

models(registry, context, options?) from ./router, ./jobs and ./cli

Middleware publishing the registry bound to each request, job run or command run as ctx.models (or options.property) and under the Models context key. options.transactions is passed to the binding.

NotFound

The failure an update or delete answers when no visible row has the key, with model and key.

ConstraintViolation

The ValidationError a write answers when the database refuses it, with kind ("unique", "foreign-key", "not-null" or "check") and the column it covers.

./testing
  • defineFactory(model, attributes, options?): a factory whose attributes are values or functions of { sample, sequence, create }; .trait(name, attributes) adds a named set.
  • createFactories(models, { seed, now? }): build, create and createMany for a bound registry, writing through the models so callbacks and constraints behave as in production.
  • overrideModel(model, build): replaces members in every binding until the returned function runs; build receives the original members, so a replacement can wrap them.
  • publishModels(ctx, registry, context, options?): binds a registry with ctx as its host and publishes it the way the middleware does, for a test calling a handler directly.
./seed
  • defineSeed(registry, steps): a Seeder whose named steps receive { models, factories } and run in order; seeder.run({ db }, { seed? }) binds the registry and answers the names that ran, or a failure naming the step that threw.
Types

BoundModel<M>, ModelQuery<M>, ModelRow<M>, CreateValues<M> and UpdateValues<M> name a model's bound type, query, row and write inputs from typeof Model. AnyModel<Shape> constrains a helper to models whose rows have Shape. ModelContext is what callbacks receive. BoundModels<Entries> names a bound registry from an interface of its entries, and BoundRegistry<typeof registry> from the registry itself. ReservedName lists the member names a scope or method cannot take.

Pattern: Scopes Over A Soft-Deleted Table

A default scope hides archived rows from every read, including the row an update or delete targets; named scopes take arguments and chain in any order with data-table's own methods.

import { createModel } from "@sdxc/data-model";
import { lte } from "remix/data-table";

import { tasks } from "./schema.js";

export const Tasks = createModel(tasks, {
    defaultScope: (query) => query.where({ archived_at: null }),
    scopes: {
        assignedTo: (query, userId: string) => query.where({ assignee_id: userId }),
        open: (query) => query.where({ completed_at: null }),
        dueBy: (query, instant: string) => query.where(lte("due_at", instant)).orderBy("due_at", "asc"),
    },
    methods: {
        agenda(userId: string, until: string) {
            return this.assignedTo(userId).open().dueBy(until);
        },
        async restore(id: string) {
            return this.unscoped().where({ id }).update({ archived_at: null });
        },
    },
});

let tasks = Tasks.bind({ db });
await tasks.agenda(userId, today).limit(10).all(); // archived tasks never appear
await tasks.open().count(); // nor here
await tasks.update(archivedId, { title: "x" }); // NotFound: the default scope hides it
await tasks.restore(archivedId); // a bulk write through unscoped() reaches it

A scope refines a query and answers it, so it may call where, having, orderBy, groupBy, limit, offset and distinct; anything that changes the row type belongs in a method.

Pattern: Custom Methods That Answer Queries, Results Or Raw Rows

this is the bound model, so a method composes its scopes, its queries, its siblings through this.context.models and, for what the builder cannot express, a raw statement on this.db.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @sdxc/data-model

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Ethersphere Hijacked With Crypto Stealing Malware (1)
npm

Ethersphere Hijacked With Crypto Stealing Malware Via Github & npm

Critical Apache HTTP Server Flaw Exposes Web Servers to RCE (1)
CVE

CVE-2026-119618: Critical Apache HTTP Server Flaw Exposes Web Servers to Remote Code Execution

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Frame 2085668439 (1)
Group 1261154229