{"id":15013335,"url":"https://github.com/gregivy/simpleddp","last_synced_at":"2025-04-06T02:11:11.215Z","repository":{"id":31818208,"uuid":"128840447","full_name":"Gregivy/simpleddp","owner":"Gregivy","description":"An easy to use DDP client library","archived":false,"fork":false,"pushed_at":"2022-12-07T13:09:08.000Z","size":716,"stargazers_count":165,"open_issues_count":28,"forks_count":20,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T01:13:03.108Z","etag":null,"topics":["apps","ddp","ddp-client","ddp-subscription","ionic","meteor","meteor-ionic","meteor-react-basics","meteorjs","reactive","simpleddp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gregivy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-09T22:19:17.000Z","updated_at":"2024-10-04T05:54:42.000Z","dependencies_parsed_at":"2023-01-14T20:00:38.355Z","dependency_job_id":null,"html_url":"https://github.com/Gregivy/simpleddp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregivy%2Fsimpleddp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregivy%2Fsimpleddp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregivy%2Fsimpleddp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gregivy%2Fsimpleddp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gregivy","download_url":"https://codeload.github.com/Gregivy/simpleddp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apps","ddp","ddp-client","ddp-subscription","ionic","meteor","meteor-ionic","meteor-react-basics","meteorjs","reactive","simpleddp"],"created_at":"2024-09-24T19:44:07.068Z","updated_at":"2025-04-06T02:11:11.184Z","avatar_url":"https://github.com/Gregivy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/simpleddp.svg)](https://badge.fury.io/js/simpleddp)\n[![Build Status](https://travis-ci.org/Gregivy/simpleddp.svg?branch=master)](https://travis-ci.org/Gregivy/simpleddp)\n[![Dependency Status](https://david-dm.org/gregivy/simpleddp.svg)](https://david-dm.org/gregivy/simpleddp)\n[![devDependency Status](https://david-dm.org/gregivy/simpleddp/dev-status.svg)](https://david-dm.org/gregivy/simpleddp#info=devDependencies)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"300\" height=\"300\" src=\"https://github.com/Gregivy/simpleddp/raw/master/simpleddp.png\"\u003e\n\u003c/p\u003e\n\n# SimpleDDP 🥚\n\nThe aim of this library is to simplify the process of working with Meteor.js server over DDP protocol using external JS environments (like Node.js, Cordova, Ionic, ReactNative, etc).\n\nIt is battle tested 🏰 in production and ready to use 🔨.\n\nIf you like this project ⭐ is always welcome.\n\n**Important**\n\nSimpleDDP is written in ES6 and uses modern features like *promises*. Though its precompiled with Babel, your js environment must support ES6 features. So if you are planning to use SimpleDDP be sure that your js environment supports ES6 features or include polyfills yourself (like Babel Polyfill).\n\nProject uses [semantic versioning 2.0.0](https://semver.org/spec/v2.0.0.html).\n\nDDP (protocol) [specification](https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.md).\n\n## [CHANGE LOG](https://github.com/Gregivy/simpleddp/blob/master/CHANGELOG.md)\n\n## Install\n\n`npm install simpleddp --save`\n\n## [Documentation](https://gregivy.github.io/simpleddp/simpleDDP.html)\n\n## Plugins\n\n* [simpleddp-plugin-login](https://github.com/Gregivy/simpleddp-plugin-login)\n\n## [Adding custom EJSON types](https://github.com/Gregivy/simpleddp/blob/master/custom_ejson.md) ⭐\n\n## Example\n\nFirst of all you need WebSocket implementation for your node app.\nWe will use [isomorphic-ws](https://www.npmjs.com/package/isomorphic-ws) package for this\nsince it works on the client and serverside.\n\n`npm install isomorphic-ws ws --save`\n\nImport/require `simpleDDP`.\n\n```javascript\nconst simpleDDP = require(\"simpleddp\"); // nodejs\nconst ws = require(\"isomorphic-ws\");\n```\n\nor\n\n```javascript\nimport simpleDDP from 'simpleDDP'; // ES6\nimport ws from 'isomorphic-ws';\n```\n\nNow you should make a new simpleDDP instance.\n\n```javascript\nlet opts = {\n    endpoint: \"ws://someserver.com/websocket\",\n    SocketConstructor: ws,\n    reconnectInterval: 5000\n};\nconst server = new simpleDDP(opts);\n```\n\nConnection is not going to be established immediately after you create a simpleDDP instance. If you need to check your connection simply use `server.connected` property which is `true` if you are connected to the server, otherwise it's `false`.\n\nYou can also add some events for connection status.\n\n```javascript\nserver.on('connected', () =\u003e {\n    // do something\n});\n\nserver.on('disconnected', () =\u003e {\n    // for example show alert to user\n});\n\nserver.on('error', (e) =\u003e {\n    // global errors from server\n});\n```\n\nAs an alternative you can use a *async/await* style (or `then(...)`).\n\n```javascript\n(async ()=\u003e{\n  await server.connect();\n  // connection is ready here\n})();\n```\n\nThe next thing we are going to do is subscribing to some publications.\n\n```javascript\nlet userSub = server.subscribe(\"user_pub\");\nlet otherSub = server.subscribe(\"other_pub\",'param1',2); // you can specify arguments for subscription\n\n(async ()=\u003e{\n  await userSub.ready();\n  let nextSub = server.subscribe(\"next_pub\"); // subscribing after userSub is ready\n  await nextSub.ready();\n  //all subs are ready here\n})();\n```\n\nYou can fetch all things you've subscribed for using [server.collection](https://gregivy.github.io/simpleddp/simpleDDP.html#collection) method.\nAlso you can get reactive data sources (plain js objects which will be automatically updated if something changes on the server).\n\n\n```javascript\n(async ()=\u003e{\n\n  // call some method\n  await server.call('somemethod');\n\n  let userSub = server.subscribe(\"user\",userId);\n  await userSub.ready();\n\n  // get non-reactive user object\n  let user = server.collection('users').filter(user=\u003euser.id==userId).fetch()[0];\n\n  // get reactive user object\n  let userReactiveCursor = server.collection('users').filter(user=\u003euser.id==userId).reactive().one();\n  let userReactiveObject = userReactiveCursor.data();\n\n  // observing the changes\n  server.collection('users').filter(user=\u003euser.id==userId).onChange(({prev,next})=\u003e{\n    console.log('previus user data',state.prev);\n    console.log('next user data',state.next);\n  });\n\n  // observing changes in reactive data source\n  userReactiveCursor.onChange((newData)=\u003e{\n    console.log('new user state', newData);\n  });\n\n  let participantsSub = server.subscribe(\"participants\");\n\n  await participantsSub.ready();\n\n  let reactiveCollection = server.collection('participants').reactive();\n\n  // reactive reduce\n  let reducedReactive = reactiveCollection.reduce((acc,val,i,arr)=\u003e{\n    if (i\u003carr.length-1)  {\n      return acc + val.age;\n    } else {\n      return (acc + val.age)/arr.length;\n    }\n  },0);\n\n  // reactive mean age of all participants\n  let meanAge = reducedReactive.data();\n\n  // observing changes in reactive data source\n  userReactiveCursor.onChange((newData)=\u003e{\n    console.log('new user state', newData);\n  });\n})();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregivy%2Fsimpleddp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregivy%2Fsimpleddp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregivy%2Fsimpleddp/lists"}