{"id":47217,"library":"can-realtime-rest-model","title":"can-realtime-rest-model","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/canjs/can-realtime-rest-model","tags":["javascript","canjs","donejs","donejs-plugin","model"],"install":[{"cmd":"npm install can-realtime-rest-model","lang":"bash","label":"npm"},{"cmd":"yarn add can-realtime-rest-model","lang":"bash","label":"yarn"},{"cmd":"pnpm add can-realtime-rest-model","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the base connection and realtime behavior","package":"can-connect","optional":false},{"reason":"Required for defining observable map types","package":"can-define","optional":false},{"reason":"Used for tracking observable dependencies","package":"can-observation-recorder","optional":false}],"imports":[{"note":"ESM import only; CommonJS require() will not work because the package is ESM-only.","wrong":"const realtimeRestModel = require('can-realtime-rest-model');","symbol":"realtimeRestModel","correct":"import { realtimeRestModel } from 'can-realtime-rest-model';"},{"note":"The package exports a single function as default export. Named export 'realtimeRestModel' also exists, but default import is the main usage.","wrong":"import { realtimeRestModel as default } from 'can-realtime-rest-model';","symbol":"default (the function itself)","correct":"import realtimeRestModel from 'can-realtime-rest-model';"},{"note":"TypeScript types are bundled; use with 'import type' for type-only imports.","wrong":null,"symbol":"type definitions","correct":"import type { RealtimeRestModel } from 'can-realtime-rest-model';"}],"quickstart":{"code":"import realtimeRestModel from 'can-realtime-rest-model';\nimport DefineMap from 'can-define/map/map';\n\nconst Todo = DefineMap.extend('Todo', {\n  id: { type: 'number', identity: true },\n  name: 'string',\n  complete: 'boolean'\n});\n\nconst todoConnection = realtimeRestModel({\n  Map: Todo,\n  url: '/api/todos'\n});\n\nconst todo = new Todo({ id: 1, name: 'Learn CanJS', complete: false });\nawait todo.save(); // POST /api/todos; realtime syncs updates","lang":"typescript","description":"Shows how to define a map, create a realtime REST connection, and save an instance, triggering real-time updates."},"warnings":[{"fix":"Use import syntax or dynamic import().","message":"In version 2.0.0, the package switched to ESM-only. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update to pass an options object instead of a constructor.","message":"The 'realtimeRestModel' function used to accept a constructor; now expects an object with Map, url, etc.","severity":"deprecated","affected_versions":"<2.0.0"},{"fix":"Ensure your map has an identity property (usually 'id') with identity: true.","message":"If you do not set the 'identity' property on your map, the connection will fail to match instances for realtime updates.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a server that implements realtime channels (WebSocket/SSE).","message":"Realtime updates require a compatible server (e.g., can-connect-feathers). Without it, realtime features will be silent no-ops.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.0':36 'api':18 'automat':20,46 'build':38 'can-realtime-rest-model':1 'canj':7,40,63,81 'chang':22 'client':58 'conflict':52 'connect':10 'current':32 'data':49 'deep':60 'definemap':14 'differ':54 'donej':78,82,84 'donejs-plugin':83 'ecosystem':79 'event':31 'generic':56 'integr':61 'javascript':80 'layer':44 'like':13 'map':12 'model':5,43,86 'observ':65 'part':75 'pattern':66 'plugin':8,85 'propag':72 'provid':45 'real':69 'real-tim':68 'realtim':3,24,42 'releas':73 'resolut':53 'rest':4,17,57 'sent':30 'serial':47 'server':29 'server-s':28 'stabl':33 'sync':21 'time':70 'track':50 'unsav':48 'updat':71 'version':34 'via':25 'websocket':26","created_at":"2026-06-07T16:50:23.741830+00:00","updated_at":"2026-06-07T16:50:23.741830+00:00","problems":[{"fix":"Change to import realtimeRestModel from 'can-realtime-rest-model'; or use dynamic import.","cause":"Using CommonJS require() on an ESM-only package.","error":"TypeError: realtimeRestModel is not a function"},{"fix":"Add identity: true to the id property in your DefineMap definition.","cause":"The map does not have an identity property defined.","error":"Error: You must provide a Map with an identity property"},{"fix":"Wrap in an options object: realtimeRestModel({ Map: MyMap, url: ... })","cause":"Passing a constructor directly instead of an options object (pre v2.0.0 pattern).","error":"Error: realtimeRestModel expects an options object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://canjs.com","github":"git://github.com/canjs/can-realtime-rest-model","docs":null,"changelog":null,"pypi":null,"npm":"can-realtime-rest-model","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}