{"id":18962287,"url":"https://github.com/lipp/jet-js","last_synced_at":"2026-06-19T18:31:10.257Z","repository":{"id":13284512,"uuid":"15970290","full_name":"lipp/jet-js","owner":"lipp","description":"Jet for Browser. Deprecated repo.","archived":false,"fork":false,"pushed_at":"2015-04-13T12:03:20.000Z","size":496,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T06:13:20.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jetbus.io","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/lipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2014-01-16T14:35:47.000Z","updated_at":"2015-04-13T12:03:20.000Z","dependencies_parsed_at":"2022-09-23T11:40:38.052Z","dependency_job_id":null,"html_url":"https://github.com/lipp/jet-js","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/lipp/jet-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fjet-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fjet-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fjet-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fjet-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/jet-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fjet-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34544403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-08T14:15:50.741Z","updated_at":"2026-06-19T18:31:10.234Z","avatar_url":"https://github.com/lipp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED\n\nThis repo is DEPRECATED.\n\njet-js is now part of [node-jet](http://github.com/lipp/node-jet). Jet can be either `required` with browserify or directly included as [single file/global](https://github.com/lipp/node-jet/tree/master/build).\n\n\n# About\n\nJavascript Peer implementation of the Jet Protocol. Visit the\n[Jet homepage](http://jetbus.io) for general information.\n[![Build Status](https://travis-ci.org/lipp/jet-js.png?branch=master)](https://travis-ci.org/lipp/jet-js/builds)\n[![Coverage Status](https://img.shields.io/coveralls/lipp/jet-js.svg)](https://coveralls.io/r/lipp/jet-js?branch=master)\n[![Code Climate](https://codeclimate.com/github/lipp/jet-js/badges/gpa.svg)](https://codeclimate.com/github/lipp/jet-js)\n\n# License\n\n[MIT](http://github.com/lipp/jet-js/blob/master/LICENSE) Copyright (c) 2013, 2014\nGerhard Preuss.\n\n# API\n\n## `peer = new jet.Peer(config)`\n\nCreates and returns a new Jet Peer instance with the specified config.\nThe supported config fields are:\n\n- `url`: {String} The Jet Daemon Websocket URL\n- `onOpen`: {Function, Optional} Called when the connection to the Daemon has been established\n- `onError`: {Function, Optional} Called on network or other error\n- `onClose`: {Function, Optional} Called whenever the connection has been closed\n\n```javascript\nvar peer = new jet.Peer({\n  url: 'ws://jet.nodejitsu.com:80',\n  onOpen: function() {\n    console.log('connection to Daemon established');\n  }\n});\n```\n\n## `peer.close()`\n\nCloses the connection to the Daemon.\n\n## `peer.set(path, value, [callbacks])`\n\nTries to set the Jet State specified by `path` to `value`.\n\n```javascript\npeer.set('foo', 123, {\n  success: function() {\n    console.log('set finished successfully');\n  },\n  error: function(e) {\n    console.log('set failed', e);\n  }\n});\n\n// dont care about the result\npeer.set('foo', 12341);\n```\n\n## `peer.call(path, args, [callbacks])`\n\nCalls the Jet Method specified by `path` with `args` as arguments.\n`args` must be an Object or an Array.\n\n```javascript\npeer.call('sum', [1,2,3,4,5], {\n  success: function(result) {\n    console.log('sum is', result);\n  },\n  error: function(e) {\n    console.log('could not calc the sum', e);\n  }\n});\n\n// dont care about the result\npeer.call('greet', {first: 'John', last: 'Mitchell'});\n```\n\n## `fetch = peer.fetch(rule, fetchCb, [callbacks])`\n\nCreates and returns a Fetch instance. The supported fields of `rule` are:\n\n- `path`: {Object, Optional} For path based fetches\n- `value`: {Object, Optional} For value based fetches\n- `valueField`: {Object, Optional} For valuefield based fetches\n- `sort`: {Object, Optional} For sorted fetches\n\nIf `rule` is a empty Object, a \"Fetch all\" is set up.\n\n```javascript\nvar fetchAll = peer.fetch({}, function(path, event, value) {\n  console.log(path, event, value);\n});\n```\n\nThe `fetchCb` arguments for non-sorting fetches are:\n\n- `path`: {String} The path of the State / Method which triggered the Fetch Notification\n- `event`: {String} The event which triggered the Fetch Notification ('add', 'remove',\n   'change')\n- `value`: {Any | undefined} The current value of the State or `undefined` for Methods\n\n```javascript\nvar fetchPersons = peer.fetch({\n  path: {\n    startsWith: 'persons/'\n  }\n}, function(path, event, value) {\n  console.log(path, event, value);\n}, {\n  success: function() {\n    console.log('fetch setup successfully');\n  },\n  error: function(e) {\n    console.log('fetch setup failed', e);\n  }\n}});\n```\n\nThe `fetchCb` argument for sorting fetches are:\n\n- `changes`: {Array} The changes compared to the previous time the function was\n  invoked:\n  - `path`: {String} The path of the State / Method which triggered the Fetch Notification\n  - `index`: {Number} The index / position within the range (from-to)\n  - `value`: {Any | undefined} The current value of the State or `undefined` for Methods\n- `n`: {Number} The number of matches within the given range (from-to)\n\n```javascript\nvar sortedPersons = [];\nvar fetchPersons = peer.fetch({\n  path: {\n    startsWith: 'persons/'\n  },\n  sort: {\n    from: 1,\n    to: 10,\n    byValueField: {\n      age: 'number'\n    }\n  }\n}, function(changes, n) {\n  sortedPersons.length = n;  \n  changes.forEach(function(change) {\n    // indices are 1 based (not 0 based).\n    sortedPersons[change.index-1] = {\n      name: change.value.name,\n      age: change.value.age\n    };\n  });\n});\n```\n\n## `method = peer.method(desc, [callbacks])`\n\nCreates and returns a Jet Method given the information provided by `desc`.\nThe supported `desc` fields are:\n\n- `path`: {String} The unique path of the Method\n- `call`: {Function, Optional} The Function which \"executes\" the method (synchonous)\n- `callAsync`: {Function, Optional} The Function which \"executes\" the method\n  (asychronously)\n\nDon't specify `call` and `callAsync` at the same time.\n\nThe arguments to the `call` Function are:\n\n- An Object with the forwarded \"args\" field from of original \"call\" Request\n- An unpacked Array, if the forwarded \"args\" of the original \"call\" Request\n  field was an Array\n\nThe `call` method can return anything or throw an Error (String/JSON-RPC error)\nif required.\n\n```javascript\nvar greet = peer.method({\n  path: 'greet',\n  call: function(who) {\n    if (who.first === 'John') {\n      throw 'John is dismissed';\n    }\n    var greet = 'Hello Mr. ' + who.last;\n    console.log(greet);\n    return greet;\n  }\n})\n\nvar sum = peer.method({\n  path: `sum`,\n  call: function(a,b,c,d,e) {\n    var sum = a + b +c + d + e;\n    return sum;\n  }\n}, {\n  success: function() {\n    console.log('method added successfully');\n  },\n  error: function(e) {\n    console.log('method adding failed', e);\n  }\n})\n```\n\nThe arguments to the `callAsync` Function are:\n\n- `reply`: {Function} Method for sending the result/error.\n- An Object with the forwarded \"args\" field from of original \"call\" Request\n- An unpacked Array, if the forwarded \"args\" of the original \"call\" Request\n  field was an Array\n\nThe `callAsync` method can return anything or throw an Error (String/JSON-RPC error)\nif required.\n\n```javascript\nvar greet = peer.method({\n  path: `greet`,\n  callAsync: function(reply, who) {\n    if (who.first === 'John') {\n      throw 'John is dismissed';\n    }\n    setTimeout(function() {\n      if (allOk) {\n        var greet = 'Hello Mr. ' + who.last;\n        console.log(greet);\n        reply({\n          result: greet\n        });\n      } else {\n        reply({\n          error: 'something went wrong'\n        });\n      }\n    }, 100);\n  }\n})\n```\n\n\n## `state = peer.state(desc, [callbacks])`\n\nCreates and returns a State given the information provided by `desc`.\nThe supported `desc` fields are:\n\n- `path`: {String} The unique path of the State\n- `value`: {Any} The initial value of the State\n- `set`: {Function, Optional} The callback Function, that handles State \"set\"\n  messages (synchronously)\n- `setAsync`: {Function, Optional} The callback Function, that handles State \"set\"\n  messages (asynchronously)\n\nDon't specify `set` and `setAsync` at the same time. If neither one is provided,\nthe State is considered read-only and an appropriate response is replied when\nsomeone tries to `set` the State.\n\nThe argument to the `set` is the requested `newValue`. The function is free to:\n\n- return nothing, a State change is posted automatically with the `newValue`\n- throw an Error, the Error should be a String or an Object with `code` and `message`\n- return on Object with the supported fields:\n  - `value`: {Any, Optional} the \"real/adjusted\" new value. This is posted as the\n     new value.\n  - `dontNotify`: {Boolean, Optional} Don't auto-send a change Notification\n\n\n```javascript\nvar test = peer.state({\n  path: 'test',\n  value: 123,\n  set: function(newValue) {\n    if (newValue \u003e 999999){\n      throw 'too big';\n    }\n    setTest(newValue);\n  }\n},{\n  success: function() {\n    console.log('state added successfully');\n  },\n  error: function(e) {\n    console.log('state adding failed', e);\n  }\n});\n\nvar testAdjust = peer.state({\n  path: 'testAdjust',\n  value: 123,\n  set: function(newValue) {\n    if (newValue \u003e 999999){\n      throw 'too big';\n    } else if (newValue \u003c 1000) {\n      newValue = 1000; // adjust the request value\n    }\n    setTest(newValue);\n    return {\n      value: newValue\n    };\n  }\n});\n```\n\nThe arguments to the `setAsync` is a `reply` Function and the requested `newValue`.\nThe Function is free to:\n\n- return nothing, the implementation MUST call the `reply` Function with\n  - `result`: {Truish, Optional} Operation was success\n  - `error`: {String/JSON-RPC Error, Optional} Operation failed\n  - `dontNotify`: {Boolean, Optional} Don't auto-send a change Notification\n- throw an Error, the Error should be a String or an Object with `code` and `message`\n\nThe `callbacks` object is optional. When specified, the supported fields are:\n\n- `success`: {Function, Optional} Called, when adding the State to the Daemon was\n  ok\n- `error`: {Function, Optional} Called, when adding the State to the Daemon was not\n  ok\n\n```javascript\nvar testAsync = peer.state({\n  path: 'testAsync',\n  value: 123,\n  setAsync: function(reply, newValue) {\n    if (newValue \u003e 999999){\n      throw 'too big';\n    }\n    setTimeout(function() {\n      if (allOk) {\n        setTest(newValue);\n        reply({\n          result: true\n        });\n      } else {\n        reply({\n          error: 'something went wrong'\n        });\n      }\n    },100);\n  }\n});\n\nvar testAsyncAdjust = peer.state({\n  path: 'testAsyncAdjust',\n  value: 123,\n  setAsync: function(newValue) {\n    if (newValue \u003e 999999){\n      throw 'too big';\n    }\n    setTimeout(function() {\n      if (allOk) {\n        if (newValue \u003c 1000) {\n          newValue = 1000;\n        }\n        setTest(newValue);\n        reply({\n          result: true,\n          value: newValue\n        });\n      } else {\n        reply({\n          error: 'something went wrong'\n        });\n      }\n    },100);\n  }\n});\n```\n\n## `fetcher.unfetch([callbacks])`\n\nUnfetches (removes) the Fetcher. `callbacks` is optional.\n\n```javascript\n// setup some fetcher\nvar fetcher = peer.fetch({},function(){});\n\n// unfetch it\nfetcher.unfetch();\n```\n\n## `state.remove([callbacks])`\n\nRemoves the State. `callbacks` is optional.\n\n```javascript\n// create some state\nvar state = peer.state({\n  path: 'test',\n  value: 123\n});\n\n// remove it\nstate.remove({\n  success: function() {\n    console.log('state is now removed');\n  },\n  error: function(e) {\n    console.log('could not remove state', e);\n  }\n});\n\n// or just\nstate.remove();\n```\n\n## `method.remove([callbacks])`\n\nRemoves the method. `callbacks` is optional.\n\n```javascript\n// create some method\nvar method = peer.method({\n  path: 'test',\n  value: 123\n});\n\n// remove it\nmethod.remove({\n  success: function() {\n    console.log('method is now removed');\n  },\n  error: function(e) {\n    console.log('could not remove method', e);\n  }\n});\n```\n\n## `state.value([newValue])`\n\nIf `newValue` is `undefined`, returns the current value. Else posts a value\nchange Notification that the State's value is now `newValue`.\nUse this for spontaneouos changes of a State which were not initially triggered\nby a `set` or `setAsync` invokation.\n\n```javascript\nvar ticker = peer.state({\n  path: 'ticker',\n  value: 1\n});\n\nsetTimeout(function() {\n  var old = ticker.value();\n  ticker.value(++old);\n},1000);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Fjet-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Fjet-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Fjet-js/lists"}