New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

odata

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

odata - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

12

package.json
{
"name": "odata",
"description": "o.js is a isomorphic 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": "1.2.1",
"version": "1.3.0",
"main": "dist/cjs/o.js",

@@ -10,3 +10,3 @@ "browser": "dist/umd/o.js",

"engines": {
"node": ">=10.0"
"node": ">=10.14.2"
},

@@ -20,5 +20,5 @@ "dependencies": {

"@babel/core": "^7.2.2",
"@types/jest": "^23.3.10",
"@types/jest": "^26.0.15",
"@types/node": "^10.12.24",
"jest": "^25.0.0",
"jest": "^26.6.1",
"rollup": "^0.68.2",

@@ -34,4 +34,4 @@ "rollup-plugin-babel": "^4.3.2",

"typescript": "^3.9.7",
"whatwg-fetch": "^3.4.1",
"url-polyfill": "^1.1.11"
"url-polyfill": "^1.1.11",
"whatwg-fetch": "^3.4.1"
},

@@ -38,0 +38,0 @@ "scripts": {

@@ -173,2 +173,2 @@ # o.js

## Polyfills
Polyfills are automatically added for `fetch()` and `URL()` if needed. The automatic polyfilling can be disabled in the options.
Polyfills are automatically added for node.js. If you like polyfills to support IE11 please include the `dist/umd/o.polyfill.js` file.

@@ -1,2 +0,3 @@

import {o, OBatch} from "./o";
import { o, OBatch } from "./o";
import { OdataConfig } from "./OdataConfig";

@@ -12,3 +13,3 @@ describe("initialize a new oHandler", () => {

// expect
expect(when.config.rootUrl.href).toEqual(url);
expect((when.config.rootUrl as URL).href).toEqual(url);
});

@@ -25,3 +26,3 @@

// expect
expect(when.config.rootUrl.href).toEqual(url);
expect((when.config.rootUrl as URL).href).toEqual(url);
});

@@ -38,3 +39,3 @@

// expect
expect(when.config.rootUrl.href).toEqual(config.rootUrl);
expect((when.config.rootUrl as URL).href).toEqual(config.rootUrl);
});

@@ -51,3 +52,3 @@

// expect
expect(when.config.rootUrl.href).toEqual(`${config.rootUrl}foo`);
expect((when.config.rootUrl as URL).href).toEqual(`${config.rootUrl}foo`);
});

@@ -63,3 +64,3 @@

// expect
expect(when.config.rootUrl.href).toEqual(`http://localhost/foo`);
expect((when.config.rootUrl as URL).href).toEqual(`http://localhost/foo`);
});

@@ -82,3 +83,3 @@

const url = "foo";
const config = {
const config: Partial<OdataConfig> = {
mode: "no-cors",

@@ -95,3 +96,3 @@ rootUrl: "http://bar.de/foo",

expect(when.config.referrer).toBe("client");
expect(when.config.rootUrl.href).toBe("http://bar.de/foo/foo");
expect((when.config.rootUrl as URL).href).toBe("http://bar.de/foo/foo");
});

@@ -104,3 +105,3 @@ });

const data = await o(
"https://services.odata.org/TripPinRESTierService/People?$top=2",
"https://services.odata.org/V4/TripPinServiceRW/People?$top=2"
)

@@ -117,3 +118,3 @@ .get()

// when
const data = await o("https://services.odata.org/TripPinRESTierService/")
const data = await o("https://services.odata.org/V4/TripPinServiceRW/")
.get(resource1)

@@ -131,11 +132,13 @@ .get(resource2)

const data = await o(
"https://services.odata.org/TripPinRESTierService/People?$top=2",
"https://services.odata.org/V4/TripPinServiceRW/People?$top=2",
{
query: { $top: 1, $filter: `FirstName eq 'john'` }
query: { $top: 1, $filter: `FirstName eq 'john'` },
}
).get().fetch();
)
.get()
.fetch();
// expect
expect(decodeURIComponent((data as Response).url)).toContain(
"People?$top=1&$filter=FirstName+eq+'john'",
"People?$top=1&$filter=FirstName+eq+'john'"
);

@@ -147,11 +150,13 @@ });

const data = await o(
"https://services.odata.org/TripPinRESTierService/People",
"https://services.odata.org/V4/TripPinServiceRW/People",
{
query: { $top: 1 }
query: { $top: 1 },
}
).get().fetch({ $top: 2 });
)
.get()
.fetch({ $top: 2 });
// expect
expect(decodeURIComponent((data as Response).url)).toContain(
"People?$top=2",
"People?$top=2"
);

@@ -163,8 +168,10 @@ });

const data = await o(
"https://services.odata.org/TripPinRESTierService/People?$top=1",
).get().fetch({ $top: 2 });
"https://services.odata.org/V4/TripPinServiceRW/People?$top=1"
)
.get()
.fetch({ $top: 2 });
// expect
expect(decodeURIComponent((data as Response).url)).toContain(
"People?$top=2",
"People?$top=2"
);

@@ -176,11 +183,13 @@ });

const data = await o(
"https://services.odata.org/TripPinRESTierService/People?$top=1",
"https://services.odata.org/V4/TripPinServiceRW/People?$top=1",
{
query: { $top: 2 }
query: { $top: 2 },
}
).get().fetch();
)
.get()
.fetch();
// expect
expect(decodeURIComponent((data as Response).url)).toContain(
"People?$top=2",
"People?$top=2"
);

@@ -194,3 +203,3 @@ });

beforeEach(() => {
oHandler = o("https://services.odata.org/TripPinRESTierService/");
oHandler = o("https://services.odata.org/V4/TripPinServiceRW/");
});

@@ -215,6 +224,3 @@

// when
await oHandler
.get(resource)
.get(resource)
.query();
await oHandler.get(resource).get(resource).query();
// expect

@@ -228,6 +234,3 @@ expect(oHandler.pending).toBe(0);

// when
await oHandler
.get(resource)
.get(resource)
.fetch();
await oHandler.get(resource).get(resource).fetch();
// expect

@@ -242,6 +245,3 @@ expect(oHandler.pending).toBe(0);

try {
await oHandler
.get(resource)
.get(resource)
.batch();
await oHandler.get(resource).get(resource).batch();
} catch (ex) {

@@ -267,3 +267,3 @@ // intended empty

expect(decodeURIComponent(req[0].url)).toContain(
"People?$top=1&$filter=FirstName+eq+'john'",
"People?$top=1&$filter=FirstName+eq+'john'"
);

@@ -289,3 +289,3 @@ });

beforeAll(() => {
oHandler = o("https://services.odata.org/TripPinRESTierService/");
oHandler = o("https://services.odata.org/V4/TripPinServiceRW/");
});

@@ -333,6 +333,3 @@

// when
const data = await oHandler
.get(resource1)
.get(resource2)
.query();
const data = await oHandler.get(resource1).get(resource2).query();

@@ -364,6 +361,3 @@ // expect

try {
await oHandler
.get(resource1)
.get(resource2)
.query();
await oHandler.get(resource1).get(resource2).query();
} catch (res) {

@@ -380,9 +374,3 @@ // expect

beforeAll(async () => {
// Use the non restier service as it has CORS enabled
const response: Response = await o(
"http://services.odata.org/V4/TripPinServiceRW/",
)
.get()
.fetch() as Response;
oHandler = o(response.url, {
oHandler = o('https://services.odata.org/V4/TripPinServiceRW/(S(ojstest))/', {
headers: { "If-match": "*", "Content-Type": "application/json" },

@@ -473,7 +461,7 @@ });

// Use the non restier service as it has CORS enabled
const response: Response = await o(
"https://services.odata.org/V4/TripPinServiceRW/",
const response: Response = (await o(
"https://services.odata.org/V4/TripPinServiceRW/"
)
.get()
.fetch() as Response;
.fetch()) as Response;

@@ -489,9 +477,6 @@ oHandler = o(response.url, {

// when
const data = await oHandler
.get(resource1)
.get(resource2)
.batch();
const data = await oHandler.get(resource1).get(resource2).batch();
// expect
expect(data.length).toBe(2);
expect(data[0].length).toBeDefined();
expect(data[0].body.length).toBeDefined();
});

@@ -508,3 +493,3 @@

// expect
expect(data[0].length).toBe(2);
expect(data[0].body.length).toBe(2);
});

@@ -523,4 +508,4 @@

expect(data.length).toBe(3);
expect(data[1]).toBe(204);
expect(data[2].Name).toBe("New");
expect(data[1].status).toBe(204);
expect(data[2].body.Name).toBe("New");
});

@@ -540,4 +525,4 @@

const request = oHandler
.post(resource1, resouce1data)
.patch(resource2, { Name: "New" });
.post(resource1, resouce1data)
.patch(resource2, { Name: "New" });
const batch = new OBatch(request.requests, request.config, null);

@@ -547,4 +532,4 @@ const data = await request.batch();

expect(data.length).toBe(2);
expect(data[0].LastName).toBe(resouce1data.LastName);
expect(data[1]).toBe(204);
expect(data[0].body.LastName).toBe(resouce1data.LastName);
expect(data[1].status).toBe(204);
});

@@ -571,5 +556,5 @@

expect(result.length).toBe(3);
expect(result[1]).toBe(204);
expect(result[2].LastName).toBe("Bar");
expect(result[1].status).toBe(204);
expect(result[2].body.LastName).toBe("Bar");
});
});

@@ -24,3 +24,6 @@ import { OdataConfig } from "./OdataConfig";

*/
export function o(rootUrl: string | URL, config: OdataConfig | any = {}) {
export function o(
rootUrl: string | URL,
config: Partial<OdataConfig> = {}
) {
// polyfill fetch if we have no fetch

@@ -65,3 +68,3 @@ const env = typeof window !== "undefined" ? window : global;

// set the default configuration values
const defaultConfigValues = {
const defaultConfigValues: OdataConfig = {
batch: {

@@ -90,7 +93,8 @@ boundaryPrefix: "batch_",

const mergedConfig = { ...defaultConfigValues, ...config };
const mergedConfig: OdataConfig = { ...defaultConfigValues, ...config };
if (typeof rootUrl === "string") {
try {
// we assuming a resource
const configUrl = mergedConfig.rootUrl || window.location.href;
const configUrl = (mergedConfig.rootUrl ||
window.location.href) as string;
rootUrl = new URL(

@@ -97,0 +101,0 @@ rootUrl,

@@ -70,9 +70,3 @@ import { OdataConfig } from "./OdataConfig";

} else {
// check if return is JSON
try {
const error = await res.json();
throw { res, error };
} catch (ex) {
throw res;
}
throw res;
}

@@ -102,14 +96,23 @@ }

return this.parseResponse(dataSegments.join("\r\n\r\n"), header);
} else if (dataSegments.length === 3) {
// if length >= 3 we have a body, try to parse if JSON and return that!
try {
const parsed = JSON.parse(dataSegments[2]);
const hasFragment = parsed[this.batchConfig.fragment];
return hasFragment || parsed;
} catch (ex) {
return dataSegments[2];
} else {
var contentIdHeader = dataSegments[0].split("\r\n").find(function (x) { return x.startsWith("Content-ID: "); });
if (contentIdHeader) {
try {
var contentId = parseInt(contentIdHeader.substring(12), 10);
} catch (ex) {
}
}
} else {
// it seems like we have no body, return the status code
return +dataSegments[1].split(" ")[1];
var status = +dataSegments[1].split(" ")[1];
if (dataSegments.length === 3) {
// if length == 3 we have a body, try to parse if JSON and return that!
var body;
try {
const parsed = JSON.parse(dataSegments[2]);
const hasFragment = parsed[this.batchConfig.fragment];
body = hasFragment || parsed;
} catch (ex) {
body = dataSegments[2];
}
}
return { contentId, status, body };
}

@@ -201,3 +204,3 @@ });

// Strip away matching root from request.
href = href.replace(this.batchConfig.rootUrl.href, '');
href = href.replace((this.batchConfig.rootUrl as URL).href, "");
}

@@ -204,0 +207,0 @@ return href;

import { OHandler } from "./OHandler";
import { OdataQuery } from "./OdataQuery";

@@ -19,3 +20,3 @@ export interface OdataBatchConfig {

*/
rootUrl: URL;
rootUrl?: URL | string;

@@ -25,6 +26,6 @@ /**

*/
query?: URLSearchParams;
query?: URLSearchParams | OdataQuery;
/**
* The fragment to parse data from
* The fragment to parse data from
* Default is: value

@@ -42,3 +43,3 @@ */

*/
disablePolyfill: boolean;
disablePolyfill?: boolean;

@@ -48,3 +49,3 @@ /**

*/
onStart: (oHandler: OHandler) => void;
onStart: (oHandler: OHandler) => null;

@@ -54,9 +55,8 @@ /**

*/
onFinish: (oHandler: OHandler, res?: Response) => void;
onFinish: (oHandler: OHandler, res?: Response) => null;
/**
* A function which is called when a request has a error
*/
onError: (oHandler: OHandler, res: Response) => void;
onError: (oHandler: OHandler, res: Response) => null;
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc