Registry / database / can-define-realtime-rest-model

can-define-realtime-rest-model

JSON →
library2.0.0jsnpmunverified

A CanJS plugin that turns a DefineMap into a realtime REST model, providing automatic CRUD operations and real-time synchronization via the can-connect layer. Current stable version is 2.0.0, released as part of the CanJS 5+ ecosystem. It is maintained by Bitovi and follows a semantic versioning release cadence. Key differentiators include seamless integration with CanJS's define system and real-time behavior via can-connect's behavior architecture, making it distinct from generic REST clients like axios or fetch.

npm install can-define-realtime-rest-model
INSTALL
IMPORT
SIG · CAN-DEFINE-REALTIM
C
can-define-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.

defineRealtimeRestModel
import { defineRealtimeRestModel } from 'can-define-realtime-rest-model'
const defineRealtimeRestModel = require('can-define-realtime-rest-model');
ESM-only since v2; CommonJS require will fail.
DefineMap
import { DefineMap } from 'can-define'
import { DefineMap } from 'can-define-realtime-rest-model'
DefineMap is from can-define, not this package.
realtimeRestModel
import { realtimeRestModel } from 'can-define-realtime-rest-model'
import realtimeRestModel from 'can-define-realtime-rest-model'
This is a named export, not default.

Shows how to define a realtime REST model using can-define-realtime-rest-model with a Todo map.

import { defineRealtimeRestModel, realtimeRestModel } from 'can-define-realtime-rest-model'; import { DefineMap } from 'can-define'; const Todo = DefineMap.extend('Todo', { id: { type: 'number', identity: true }, name: 'string', completed: 'boolean' }); const connection = defineRealtimeRestModel({ Map: Todo, List: Todo.List, url: '/api/todos', // Enable real-time via can-connect/real-time behavior: realtimeRestModel }); // Usage connection.getList({}).then(todos => console.log(todos)); connection.get({ id: 1 }).then(todo => console.log(todo));
Debug
Known issues
breakingRemoved CommonJS support; ESM only.
fix
Use import syntax instead of require().
affects: >=2.0.0
breakingBehavior API changed; realtimeRestModel is now a named export.
fix
Import { realtimeRestModel } instead of relying on default.
affects: >=2.0.0
deprecatedcan-define-realtime-rest-model is deprecated in favor of can-connect's built-in realtime behavior.
fix
Migrate to can-connect with connection.get() pattern.
affects: >=1.0.0
gotchaMissing identity property on Map causes errors.
fix
Ensure Map has an identity property (e.g., id: { type: 'number', identity: true }).
affects: >=1.0.0
gotchaURL must be absolute or relative to the page base; no automatic base path.
fix
Set url to a full path (e.g., '/api/todos').
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: defineRealtimeRestModel is not a function
Importing incorrectly (e.g., using require or wrong import).
fix
Use import { defineRealtimeRestModel } from 'can-define-realtime-rest-model' in an ESM context.
Error: can-define-realtime-rest-model: You must provide a Map type.
Missing Map property in options.
fix
Pass a DefineMap constructor in the Map option.
Error: can-define-realtime-rest-model: List type must be provided.
Missing List property.
fix
Provide a DefineList constructor in the List option.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
can-definerequiredRequired to define the map types used by the model.
can-connectrequiredProvides the real-time and REST connection behaviors.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
2
Amazon
1
Resources
can-define-realtime-rest-model — npm install can-define-realtime-rest-model · libregistry