{"_id":"o.js-sap","_rev":"1-ff16fa10c469760c5e15d29eb7ad12da","name":"o.js-sap","dist-tags":{"latest":"0.3.8"},"versions":{"0.3.8":{"name":"o.js-sap","description":"o.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.","version":"0.3.8","main":"o.js","dependencies":{"q":"^1.5.0","xhr2":"^0.1.4 "},"devDependencies":{"jslint":"^0.10.3","jasmine":"*","uglify-js":"*"},"scripts":{"test":"jasmine","uglify":"uglifyjs --compress --mangle -o o.min.js o.js"},"repository":{"type":"git","url":"git://github.com/gmalpha/o.js.git"},"author":{"name":"Jan Hommes"},"contributors":[{"name":"Matteo Antony Mistretta","email":"antony.mistretta@gmail.com","url":"http://www.ingloriouscoderz.it"}],"license":"MIT","eslintConfig":{"env":{"browser":true}},"gitHead":"9df28f0dd7c3dc73cd6884ca27f59f2e29d45d84","bugs":{"url":"https://github.com/gmalpha/o.js/issues"},"homepage":"https://github.com/gmalpha/o.js#readme","_id":"o.js-sap@0.3.8","_npmVersion":"5.8.0","_nodeVersion":"8.10.0","_npmUser":{"name":"gmalpha","email":"gmnpmalpha@gmail.com"},"dist":{"integrity":"sha512-tSdeanhSykKfrUqbVk1FHbWKx+1jIcpoGM7lRJCXz1EMC6HNWZPBVQwUHttptMjvQjAyP4iN47lRb4pDetA7gQ==","shasum":"29fa112be531e1c747ee52312aec71a2d396ed92","tarball":"https://registry.npmjs.org/o.js-sap/-/o.js-sap-0.3.8.tgz","fileCount":33,"unpackedSize":1258824,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbYg+dCRA9TVsSAnZWagAA1UAP/1Ssp/WCWOs2519W/bO7\nFG7B72omJVAOxzu7vKteHhpSfmadMu2HqLEo62DBUFhWvxlD4lqFjrQRSI/5\nWz3ts4L3CIbsEUVaLB/tKN6DYz4QFgFAQJVyXizquxwPow8eyUpIM4vrqW6d\nH+E91DVz6+N1KDV3geMXK/vzzVpapZJrrElKGe2TZL9QlTiBPJXQXv+u+jan\nAh+CM9Iab3k7zG8jiSjmWwNK5zW6VdCRF3s56whLAyStaxg2Ile6F8KTNWQn\nRk0pEfc1mRrkR3s3nw/aKKj275FEAuXb8bwOPcAmY/KB84Y/v9qc8Zc/HIbJ\n4gvPFCyH8m+1Ic9ipU28hhvOh1gVA5mguvEzkEz1LlBIKyjCLSsySzqRY7wl\nIka0Cvl7TsMoz6mMbvCd47moW25/xUX11C8d4IO67Uko7Fu2lSGzx9benQEb\nkCOAmYFcyMHLQCXVPaEhyqJMXQOabejO0vdiBSKQh17FktTE0XheYFgNcKWq\npdxxIrAMO633ETNITGX6XvdtG8NML8zBizeEN6oM5mnJ9K9SjjM0VM3fYfxF\neUckx1Vff8HbWhZwRpIaE2J+MqeOOmyx0+zaCu44666/wpL5s9VCJRqRcwDf\neDH/XQM9yW/tjW+jKe8vB0eEMAhjLPOM+1v45pxEyacl0F7T+j8f6f5LRCJB\n7R3e\r\n=MRMC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEHw9IVglqEUlw1OufvQpTkIJ8h6j8+bBNKiKzA0b6tAAiEAxcDVwY0hU0EDy4snrQf+D34WZ2Pq73silLxd1B5tkew="}]},"maintainers":[{"name":"gmalpha","email":"gmnpmalpha@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/o.js-sap_0.3.8_1533153180484_0.49045512661531343"},"_hasShrinkwrap":false}},"time":{"created":"2018-08-01T19:53:00.484Z","0.3.8":"2018-08-01T19:53:00.651Z","modified":"2022-05-12T00:04:15.658Z"},"maintainers":[{"name":"gmalpha","email":"gmnpmalpha@gmail.com"}],"description":"o.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.","homepage":"https://github.com/gmalpha/o.js#readme","repository":{"type":"git","url":"git://github.com/gmalpha/o.js.git"},"contributors":[{"name":"Matteo Antony Mistretta","email":"antony.mistretta@gmail.com","url":"http://www.ingloriouscoderz.it"}],"author":{"name":"Jan Hommes"},"bugs":{"url":"https://github.com/gmalpha/o.js/issues"},"license":"MIT","readme":"# o.js\n\n_o.js beta v0.3.8_\n\no.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a **standalone, lightweight and easy** to understand Odata lib.\n\n## Install\n\nDownload the _o.js_ or _o.min.js_ file or install it via _bower_:\n\n```\nbower install o.js\n```\n\nThen you can add the script into your file (`<script src=\"bower_components/o.js/o.js\"></script>`), or load it with your favorite AMD loader:\n\n```javascript\nrequire.config({paths: {'odata': 'bower_components/o.js/o'}});\ndefine(['odata'], function(o) {...});\n```\n\nYou can use o.js in node.js as well, by installing the `odata` package:\n\n```\nnpm install odata\n```\n\n```javascript\nvar o = require('odata');\n```\n\n## Samples\n\nFor all samples we are using the test odata service from [Odata.org](http://www.odata.org). You can find the metadata of this service [here](http://services.odata.org/V4/OData/OData.svc).\n\n### Simple Odata query with o.js\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products').get(function(data) {\n  console.log(data); //returns an array of Product data\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\no.js uses a jQuery like syntax to determine which resource you want to access. You can define any Odata service url (or any json web service) in the o-function: `o('<your odata service resource>')`. This only holds a handler to this resource and doesn't start the ajax call. If you want to get the resource, you need to call `.get()`. Get accepts a function callback which contains the data as the first parameter.\n\n### Methods\n\nBy adding some chained functions to the o-handler you can add query options:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products').take(5).skip(2).get(function(data) {\n  console.log(data); //An array of 5 products skipped by 2\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\n### Routing\n\nYou can use hash routes to map your Odata service endpoint to your website:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products').find(':0').route('Product/Detail/:0/:1',function(data) {\n  console.log('Route Product/Detail/'+this.param[0]+'/'+this.param[1]+' triggered. Result:');\n  console.log(data);\n});\n```\n\nInstead of manual getting your data with the `get()` function, this routing function always returns the data when somebody navigates to an URL with the hash value `index.html#Product/Detail/1/Some more parameter`. The `find()` method automatically maps the right parameter (in this example _1_). [See this](https://github.com/janhommes/o.js/tree/master/example) demonstration for more examples.\n\n### Get data (details)\n\nIf you want to get data you need to call the `get()` function. This functions returns an async callback function which holds an array as it's parameter. If you use `first()` or the `find()` method it only returns the data because an array is not needed. You can also save your o-function to call it later:\n\n```javascript\nvar oHandler = o('http://services.odata.org/V4/OData/OData.svc/Products');\n//do something\noHandler.find(1);\n// do some more\n\n//get the data\noHandler.get(function(data) {\n  console.log(data);\n  //or the saved var also contains the data:\n  console.log(oHandler.data);\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\nIf you need to get several data you can use promise. Currently o.js only supports [q.js](https://github.com/kriskowal/q). The following example show how you can get the data of two different resources:\n\n```javascript\nQ.all([\n  o('http://services.odata.org/V4/OData/OData.svc/Products(4)').get(),\n  o('http://services.odata.org/V4/OData/OData.svc/Categories').take(2).get()\n]).then(function(oHandlerArray) {\n  //The oHandler array contains the Product oHandler and the Group oHandler:\n  oHandlerArray[0].data); // 1 Product with id 4\n  oHandlerArray[1].data.length); // 2 Categories\n});\n```\n\nYou can also use promise for only one resource. The main advantage is, that you can use a fail-function:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products(2)').get().then(function(oHandler) {\n  console.log(oHandler.data);\n}).fail(function(ex) {\n  console.log(ex);\n});\n```\n\n## Add and change data\n\nTo add and change data you can use the http verb in combination with the `save()` method:\n\n### Post:\n\nYou can use the `post()` function in combination with the `save()` method to add data:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products').post({Name:'Example 1',Description:'a'}).post({Name:'Example 2',Description:'b'}).save(function(data) {\n  console.log(\"Two Products added\");\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\n### Patch/Put:\n\nChanging (PATCH or PUT) data is nearly the same:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products(1)').patch({Name:'NewName'}).save(function(data) {\n  console.log(\"Product Name changed\");\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\n### Delete:\n\nTo remove (DELETE) data you need to call `remove()`:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products(1)').remove().save(function(data) {\n  console.log(\"Product deleted\");\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\n### Reference:\n\nTo add an reference to an other resource use `ref` (to remove it simply use `removeRef` the same way):\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products(1)').ref('Categories', 2).save(function(data) {\n  console.log(\"Products(1) associated with Categories(2)\");\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\nIf the navigation property you are trying to set is not named the same as the collection:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products(1)').ref('RelatedProducts', 'Products', 2).save(function(data) {\n  console.log(\"Products(1) associated with Products(2) using the RelatedProducts navigation property\");\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\nYou can also combine a single data request (`first()` or `find()`) with the save method and chain it:\n\n```javascript\no('http://services.odata.org/V4/OData/OData.svc/Products').find(2).get().then(function(oHandler) {\n  oHandler.data.Name=\"NewName\";\n  return(o.save());\n}).then(function(oHandler) {\n  console.log(oHandler.data.Name); //NewName\n}).fail(function(ex) {\n  console.log(\"error\");\n});\n```\n\n### Endpoint configuration\n\nYou can configure a endpoint with the `o().config()` function. This configuration is persistent over all off your o.js calls. Example:\n\n```javascript\n// set an endpoint\no().config({\n  endpoint:'http://services.odata.org/V4/OData/OData.svc'\n});\n\n// after you have set an endpoint, you can shorten your queries:\no('Products').get(function(data) {\n  //same result like the first example on this page\n}, function(status) {\n  console.error(status); // error with status\n});\n```\n\nHowever, if you have set an endpoint you can still do a full endpoint request for example to another domain `o('http://odata.example.de/Customer')`. With this function you can also do some more basic configs:\n\n```javascript\n//basic config\no().config({\n    endpoint: null,   // The default endpoint to use.\n    format: 'json', \t// The media format. Default is JSON.\n    autoFormat: true,   // Will always append a $format=json to each query if set to true.\n    version: 4, \t\t// currently only tested for Version 4. Most will work in version 3 as well.\n    strictMode: true, \t// strict mode throws exception, non strict mode only logs them\n    start: null, \t\t// a function which is executed on loading\n    ready: null,\t\t// a function which is executed on ready\n    error: null,\t\t// a function which is executed on error\n    headers: [],\t\t// an array of additional headers [{name:'headername',value:'headervalue'}]\n    username: null, \t// the basic auth username\n    password: null,\t\t// the basic auth password\n    isAsync: true\t\t// set this to false to enable sync requests. Only usable without basic auth\n\tisCors: true,       // set this to false to disable CORS\n    isHashRoute: true,  // set this var to false to disable automatic #-hash setting on routes\n    appending: ''\t\t// set this value to append something to a any request. eg.: [{name:'apikey', value:'xyz'}]\n});\n```\n\n### Full list of supported functions\n\nCurrently the following queries are supported:\n\n`.find(int)` - returns the object with the given id. (Odata: Products_(1)_)\n\n`.top(int)` - returns the top x objects (Odata: Products/?_$top=2_) - Synonym: `.take`\n\n`.skip(int)` - returns the objects skipped by the given value (Odata: Products/?_$skip=2_)\n\n`.first()` - returns the first object which is found (Odata: Products/?_$top=1_)\n\n`.filter(string)` - adds a filter string (o.js can converted simple JS-Syntax. If you need something complex use the plain Odata $filter syntax: [see the Odata doc](http://www.odata.org/documentation/odata-version-3-0/url-conventions/) for more information) (Odata: Products/?_$filter=Name eq 'Example'_) - Synonym: `.where`\n\n`.any(string, string)` - applies an any filter to an resource (Odata: Products/?_$filter=Categories/any(x:x/Name eq 'Test')_)\n\n`.search(array, string)` - builds up a search $filter. The first parameter defines the columns to search in the second the search word (e.g.: `.search(['Name', 'Description'], 'Test')`)\n\n`.orderBy(string, direction)` - orders the data (Odata: Products/?_$orderBy=Name_)\n\n`.orderByDesc(string)` - orders the data descending (Odata: Products/?_$orderBy=Name_)\n\n`.count()` - only counts the result (Odata: Products/_$count_)\n\n`.inlineCount(string)` - adds a inlinecount to the result. (Odata: Products/?_$count=true_)\n\n`.batch(string)` - adds a second resource to the request (Odata: $batch)\n\n`.expand(string)` - expands a related resource (Odata: Products/?_$expand=ProductUnit_)\n\n`.select(string)` - selects only certain properties (Odata: Products/?_$select=Name)\n\n`.ref(string, string, [string])` - expands a related resource (Odata: Products(1)/Category/_$ref=Categories(1)_)\n\n`.deleteRef(string, string, [string])` - expands a related resource (Odata: Products(1)/Category/_$ref=Categories(1)_)\n\n`.post(object)` - Post data to an endpoint\n\n`.patch(object)` - PATCH data on an endpoint\n\n`.put(object)` - PUT data on an endpoint\n\n`.remove(object)` - DELETE data on an endpoint (You must define only one resource: e.g: Products(1) )\n\n`.query()` - get the query as string\n","readmeFilename":"README.md"}