Registry / database / can-realtime-rest-model

can-realtime-rest-model

JSON →
library2.0.0jsnpmunverified

A CanJS plugin that connects a map (like DefineMap) to a RESTful API and automatically syncs changes in realtime via WebSockets or Server-Sent Events. Current stable version is 2.0.0. It builds on CanJS's realtime model layer, providing automatic serialization, unsaved data tracking, and conflict resolution. Different from generic REST clients by deep integration with CanJS's observable patterns and real-time update propagation. Released as part of the DoneJS ecosystem.

npm install can-realtime-rest-model
INSTALL
IMPORT
SIG · CAN-REALTIME-REST-
C
can-realtime-rest-model
databasejavascriptv2.0.0
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.

realtimeRestModel
import { realtimeRestModel } from 'can-realtime-rest-model';
const realtimeRestModel = require('can-realtime-rest-model');
ESM import only; CommonJS require() will not work because the package is ESM-only.
default (the function itself)
import realtimeRestModel from 'can-realtime-rest-model';
import { realtimeRestModel as default } from 'can-realtime-rest-model';
The package exports a single function as default export. Named export 'realtimeRestModel' also exists, but default import is the main usage.
type definitions
import type { RealtimeRestModel } from 'can-realtime-rest-model';
TypeScript types are bundled; use with 'import type' for type-only imports.

Shows how to define a map, create a realtime REST connection, and save an instance, triggering real-time updates.

import realtimeRestModel from 'can-realtime-rest-model'; import DefineMap from 'can-define/map/map'; const Todo = DefineMap.extend('Todo', { id: { type: 'number', identity: true }, name: 'string', complete: 'boolean' }); const todoConnection = realtimeRestModel({ Map: Todo, url: '/api/todos' }); const todo = new Todo({ id: 1, name: 'Learn CanJS', complete: false }); await todo.save(); // POST /api/todos; realtime syncs updates
Debug
Known issues
breakingIn version 2.0.0, the package switched to ESM-only. CommonJS require() will throw an error.
fix
Use import syntax or dynamic import().
affects: >=2.0.0
deprecatedThe 'realtimeRestModel' function used to accept a constructor; now expects an object with Map, url, etc.
fix
Update to pass an options object instead of a constructor.
affects: <2.0.0
gotchaIf you do not set the 'identity' property on your map, the connection will fail to match instances for realtime updates.
fix
Ensure your map has an identity property (usually 'id') with identity: true.
affects: >=1.0.0
gotchaRealtime updates require a compatible server (e.g., can-connect-feathers). Without it, realtime features will be silent no-ops.
fix
Use a server that implements realtime channels (WebSocket/SSE).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: realtimeRestModel is not a function
Using CommonJS require() on an ESM-only package.
fix
Change to import realtimeRestModel from 'can-realtime-rest-model'; or use dynamic import.
Error: You must provide a Map with an identity property
The map does not have an identity property defined.
fix
Add identity: true to the id property in your DefineMap definition.
Error: realtimeRestModel expects an options object
Passing a constructor directly instead of an options object (pre v2.0.0 pattern).
fix
Wrap in an options object: realtimeRestModel({ Map: MyMap, url: ... })
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
can-connectrequiredProvides the base connection and realtime behavior
can-definerequiredRequired for defining observable map types
can-observation-recorderrequiredUsed for tracking observable dependencies
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
can-realtime-rest-model — npm install can-realtime-rest-model · libregistry