Giter Site home page Giter Site logo

light-odata's Introduction

OData Client

npm (scoped) NPM npm unittest codecov

npm bundle size (scoped) node-lts (scoped with tag) Maintainability Rating Technical Debt DeepScan grade

Javascript OData Client for OData (v2/v4) Service.

Installation

npm i -S @odata/client

Alternative, in native browser environment, just add unpkg or jsdeliver umd link to your page, and the OData object will be available in window.

<script src="https://cdn.jsdelivr.net/npm/@odata/client/lib/odata-client-umd.js"></script>

ODataClient

How to use @odata/client

Start with a simple query, following code start a GET http request, and asks the server to respond to all customers which phone number equals 030-0074321

import { OData } from "@odata/client"
// import "@odata/client/lib/polyfill" // server side polyfill

// odata.org sample odata service
const serviceEndpoint = "https://services.odata.org/V2/Northwind/Northwind.svc/"
const client = OData.New({ serviceEndpoint })

const runner = async () => {
  
  // Query by filter
  //
  // GET /Customers?$format=json&$filter=Phone eq '030-0074321'
  const filter = client.newFilter().property("Phone").eq("030-0074321");

  // just an example, suggest to use the EntitySet API
  const result = await client.newRequest({ // ODataRequest object
    collection: "Customers", // entity set
    params: client.newParam().filter(filter) // odata param
  })

}
// OData V4 client
const client = OData.New4({ serviceEndpoint: "https://odata-v4-demo-001.herokuapp.com/odata/" })

SystemQueryOption

use SystemQueryOption to control response size, element projection and order

go to the document

ODataFilter

use the ODataFilter to filter data

go to the document

EntitySet

use EntitySet to perform CRUD on a specific entity

go to the document

Batch requests

use odata $batch api for operating multi entities in single HTTP request, it will save a lot of time between client & server (In the case of processing a large number of requests).

go to the document

Advanced

some advanced topics

  • literal in uri
  • request interpreter
  • server side polyfill

go to the document

Thanks JetBrains

light-odata's People

Contributors

bopzor avatar dependabot-preview[bot] avatar dependabot[bot] avatar lgtm-com[bot] avatar luciandavies avatar mend-bolt-for-github[bot] avatar renovate[bot] avatar snyk-bot avatar soontao avatar u-dover avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

light-odata's Issues

Support for $apply to perform groupBy in the queries

Is your feature request related to a problem? Please describe.
I want to group some data based on a Gender, City etc and get count of the result

Describe the solution you'd like
A support for $apply through which we can apply groupBy with aggregate function like count,sum,avg etc.

Additional context
Similar to the aggregation extension that odata provides.
http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/odata-data-aggregation-ext-v4.0.html

Getting fetch not defined error[Question]

System Environment

  • OS: Windows 10
  • NodeJS Version: 14.17.0
  • This LIbrary Version: 2.20.1

Question Description

I'm getting ReferenceError: fetch is not defined when I try to use client.newRequest API as shown below.

image

The error happens when line 32 is executed in @OData\client\lib\request.js:32 file.
I added const fetch = require("node-fetch"); line in @OData\client\lib\request.js file and error was resolved. I'm not sure what is the problem, can anyone please help me to resolve this issue ?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/codeql.yml
  • actions/checkout v4@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/nodejs-cov.yml
  • actions/checkout v4@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
  • actions/setup-node v4
  • actions/cache v4
  • codecov/codecov-action v4.3.1
.github/workflows/nodejs-lint.yml
  • actions/checkout v4@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
  • actions/setup-node v4
  • actions/cache v4
.github/workflows/nodejs-release.yml
  • actions/checkout v4@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
  • actions/setup-node v4
.github/workflows/nodejs.yml
  • actions/checkout v4@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
  • actions/setup-node v4
  • actions/cache v4
npm
package.json
  • @newdash/newdash ^5.22.1
  • @odata/parser ^0.2.14
  • @types/node-fetch ^2.6.11
  • fetch-cookie ^3.0.1
  • http-string-parser ^0.0.6
  • node-fetch ^2.7.0
  • uuid ^9.0.1
  • @types/http-string-parser 0.0.33
  • @types/jest 29.5.12
  • @types/mockjs 1.0.10
  • @types/node 20.12.11
  • @types/uuid 9.0.8
  • @typescript-eslint/eslint-plugin 7.8.0
  • @typescript-eslint/parser 7.8.0
  • eslint 8.57.0
  • jest 29.7.0
  • ts-jest 29.1.2
  • typescript 5.4.5
  • fsevents ^2.3.3
  • node >=18
  • npm >=8
  • glob-parent >=6.0.2
  • json5 >=2.2.3

  • Check this box to trigger a request for Renovate to run again on this repository

fetch-cookie-2.1.0.tgz: 1 vulnerabilities (highest severity is: 6.5) - autoclosed

Vulnerable Library - fetch-cookie-2.1.0.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/tough-cookie/package.json

Found in HEAD commit: 0b3d5216b45d4e39d3677092ffbeae66e09e0e4a

Vulnerabilities

CVE Severity CVSS Dependency Type Fixed in (fetch-cookie version) Remediation Available
CVE-2023-26136 Medium 6.5 tough-cookie-4.1.2.tgz Transitive N/A*

*For some transitive vulnerabilities, there is no version of direct dependency with a fix. Check the "Details" section below to see if there is a version of transitive dependency where vulnerability is fixed.

Details

CVE-2023-26136

Vulnerable Library - tough-cookie-4.1.2.tgz

RFC6265 Cookies and Cookie Jar for node.js

Library home page: https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/tough-cookie/package.json

Dependency Hierarchy:

  • fetch-cookie-2.1.0.tgz (Root Library)
    • tough-cookie-4.1.2.tgz (Vulnerable Library)

Found in HEAD commit: 0b3d5216b45d4e39d3677092ffbeae66e09e0e4a

Found in base branch: main

Vulnerability Details

Versions of the package tough-cookie before 4.1.3 are vulnerable to Prototype Pollution due to improper handling of Cookies when using CookieJar in rejectPublicSuffixes=false mode. This issue arises from the manner in which the objects are initialized.

Publish Date: 2023-07-01

URL: CVE-2023-26136

CVSS 3 Score Details (6.5)

Base Score Metrics:

  • Exploitability Metrics:
    • Attack Vector: Network
    • Attack Complexity: Low
    • Privileges Required: None
    • User Interaction: None
    • Scope: Unchanged
  • Impact Metrics:
    • Confidentiality Impact: Low
    • Integrity Impact: Low
    • Availability Impact: None

For more information on CVSS3 Scores, click here.

Suggested Fix

Type: Upgrade version

Origin: https://www.cve.org/CVERecord?id=CVE-2023-26136

Release Date: 2023-07-01

Fix Resolution: tough-cookie - 4.1.3

Step up your Open Source Security Game with Mend here

How to perform a `ILIKE` filter ?

Hello,

I'm new to using odata, and I'm looking for a way to perform a ILIKE filter in odata v2.

I find in odata documentation that it might be possible using a function (bool substringof(string po, string p1)), but I'm not sure light-odata already support it (?).

Does anyone know another way to do it?

Thanks for your time :)

update-0.7.4.tgz: 4 vulnerabilities (highest severity is: 9.8) - autoclosed

Vulnerable Library - update-0.7.4.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/pkg-store/node_modules/set-value/package.json,/node_modules/map-schema/node_modules/set-value/package.json,/node_modules/data-store/node_modules/set-value/package.json,/node_modules/vinyl-item/node_modules/set-value/package.json,/node_modules/option-cache/node_modules/set-value/package.json

Found in HEAD commit: 4960c5e57a377ff84983ea2cb6c176e76e5ac674

Vulnerabilities

CVE Severity CVSS Dependency Type Fixed in (update version) Remediation Available
CVE-2021-23440 High 9.8 detected in multiple dependencies Transitive N/A*
CVE-2019-10747 High 9.8 detected in multiple dependencies Transitive N/A*
CVE-2018-16486 High 9.8 defaults-deep-0.2.4.tgz Transitive N/A*
CVE-2020-7608 Medium 5.3 yargs-parser-2.4.1.tgz Transitive N/A*

*For some transitive vulnerabilities, there is no version of direct dependency with a fix. Check the "Details" section below to see if there is a version of transitive dependency where vulnerability is fixed.

Details

CVE-2021-23440

Vulnerable Libraries - set-value-0.4.3.tgz, set-value-0.2.0.tgz, set-value-0.3.3.tgz

set-value-0.4.3.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/pkg-store/node_modules/set-value/package.json,/node_modules/map-schema/node_modules/set-value/package.json,/node_modules/data-store/node_modules/set-value/package.json,/node_modules/vinyl-item/node_modules/set-value/package.json,/node_modules/option-cache/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • data-store-0.16.1.tgz
      • union-value-0.2.4.tgz
        • set-value-0.4.3.tgz (Vulnerable Library)

set-value-0.2.0.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.2.0.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/engine/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • assemble-core-0.25.0.tgz
      • templates-0.24.3.tgz
        • engine-base-0.1.3.tgz
          • engine-0.1.12.tgz
            • set-value-0.2.0.tgz (Vulnerable Library)

set-value-0.3.3.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.3.3.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/question-cache/node_modules/set-value/package.json,/node_modules/expand-object/node_modules/set-value/package.json,/node_modules/templates/node_modules/set-value/package.json,/node_modules/expand-args/node_modules/set-value/package.json,/node_modules/base-option/node_modules/set-value/package.json,/node_modules/question-store/node_modules/set-value/package.json,/node_modules/gulp-choose-files/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • base-generators-0.4.6.tgz
      • base-option-0.8.4.tgz
        • set-value-0.3.3.tgz (Vulnerable Library)

Found in HEAD commit: 4960c5e57a377ff84983ea2cb6c176e76e5ac674

Found in base branch: main

Vulnerability Details

Mend Note: After conducting further research, Mend has determined that all versions of set-value before versions 2.0.1, 4.0.1 are vulnerable to CVE-2021-23440.

Publish Date: 2021-09-12

URL: CVE-2021-23440

CVSS 3 Score Details (9.8)

Base Score Metrics:

  • Exploitability Metrics:
    • Attack Vector: Network
    • Attack Complexity: Low
    • Privileges Required: None
    • User Interaction: None
    • Scope: Unchanged
  • Impact Metrics:
    • Confidentiality Impact: High
    • Integrity Impact: High
    • Availability Impact: High

For more information on CVSS3 Scores, click here.

Suggested Fix

Type: Upgrade version

Origin: https://www.huntr.dev/bounties/2eae1159-01de-4f82-a177-7478a408c4a2/

Release Date: 2021-09-12

Fix Resolution: set-value - 2.0.1,4.0.1

Step up your Open Source Security Game with Mend here

CVE-2019-10747

Vulnerable Libraries - set-value-0.3.3.tgz, set-value-0.2.0.tgz, set-value-0.4.3.tgz

set-value-0.3.3.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.3.3.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/question-cache/node_modules/set-value/package.json,/node_modules/expand-object/node_modules/set-value/package.json,/node_modules/templates/node_modules/set-value/package.json,/node_modules/expand-args/node_modules/set-value/package.json,/node_modules/base-option/node_modules/set-value/package.json,/node_modules/question-store/node_modules/set-value/package.json,/node_modules/gulp-choose-files/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • base-generators-0.4.6.tgz
      • base-option-0.8.4.tgz
        • set-value-0.3.3.tgz (Vulnerable Library)

set-value-0.2.0.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.2.0.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/engine/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • assemble-core-0.25.0.tgz
      • templates-0.24.3.tgz
        • engine-base-0.1.3.tgz
          • engine-0.1.12.tgz
            • set-value-0.2.0.tgz (Vulnerable Library)

set-value-0.4.3.tgz

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

Library home page: https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/pkg-store/node_modules/set-value/package.json,/node_modules/map-schema/node_modules/set-value/package.json,/node_modules/data-store/node_modules/set-value/package.json,/node_modules/vinyl-item/node_modules/set-value/package.json,/node_modules/option-cache/node_modules/set-value/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • data-store-0.16.1.tgz
      • union-value-0.2.4.tgz
        • set-value-0.4.3.tgz (Vulnerable Library)

Found in HEAD commit: 4960c5e57a377ff84983ea2cb6c176e76e5ac674

Found in base branch: main

Vulnerability Details

set-value is vulnerable to Prototype Pollution in versions lower than 3.0.1. The function mixin-deep could be tricked into adding or modifying properties of Object.prototype using any of the constructor, prototype and proto payloads.

Publish Date: 2019-08-23

URL: CVE-2019-10747

CVSS 3 Score Details (9.8)

Base Score Metrics:

  • Exploitability Metrics:
    • Attack Vector: Network
    • Attack Complexity: Low
    • Privileges Required: None
    • User Interaction: None
    • Scope: Unchanged
  • Impact Metrics:
    • Confidentiality Impact: High
    • Integrity Impact: High
    • Availability Impact: High

For more information on CVSS3 Scores, click here.

Suggested Fix

Type: Upgrade version

Release Date: 2019-08-23

Fix Resolution: 2.0.1,3.0.1

Step up your Open Source Security Game with Mend here

CVE-2018-16486

Vulnerable Library - defaults-deep-0.2.4.tgz

Like `extend` but recursively copies only the missing properties/values to the target object.

Library home page: https://registry.npmjs.org/defaults-deep/-/defaults-deep-0.2.4.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/defaults-deep/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • base-generators-0.4.6.tgz
      • base-pkg-0.2.5.tgz
        • expand-pkg-0.1.9.tgz
          • defaults-deep-0.2.4.tgz (Vulnerable Library)

Found in HEAD commit: 4960c5e57a377ff84983ea2cb6c176e76e5ac674

Found in base branch: main

Vulnerability Details

A prototype pollution vulnerability was found in defaults-deep <=0.2.4 that would allow a malicious user to inject properties onto Object.prototype.

Publish Date: 2019-02-01

URL: CVE-2018-16486

CVSS 3 Score Details (9.8)

Base Score Metrics:

  • Exploitability Metrics:
    • Attack Vector: Network
    • Attack Complexity: Low
    • Privileges Required: None
    • User Interaction: None
    • Scope: Unchanged
  • Impact Metrics:
    • Confidentiality Impact: High
    • Integrity Impact: High
    • Availability Impact: High

For more information on CVSS3 Scores, click here.

Step up your Open Source Security Game with Mend here

CVE-2020-7608

Vulnerable Library - yargs-parser-2.4.1.tgz

the mighty option parser used by yargs

Library home page: https://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz

Path to dependency file: /package.json

Path to vulnerable library: /node_modules/common-config/node_modules/yargs-parser/package.json,/node_modules/update/node_modules/yargs-parser/package.json

Dependency Hierarchy:

  • update-0.7.4.tgz (Root Library)
    • yargs-parser-2.4.1.tgz (Vulnerable Library)

Found in HEAD commit: 4960c5e57a377ff84983ea2cb6c176e76e5ac674

Found in base branch: main

Vulnerability Details

yargs-parser could be tricked into adding or modifying properties of Object.prototype using a "proto" payload.

Publish Date: 2020-03-16

URL: CVE-2020-7608

CVSS 3 Score Details (5.3)

Base Score Metrics:

  • Exploitability Metrics:
    • Attack Vector: Local
    • Attack Complexity: Low
    • Privileges Required: Low
    • User Interaction: None
    • Scope: Unchanged
  • Impact Metrics:
    • Confidentiality Impact: Low
    • Integrity Impact: Low
    • Availability Impact: Low

For more information on CVSS3 Scores, click here.

Suggested Fix

Type: Upgrade version

Release Date: 2020-03-16

Fix Resolution: 5.0.1;13.1.2;15.0.1;18.1.1

Step up your Open Source Security Game with Mend here

[SECURITY] glob-parent before 6.0.1 vulnerable to Regular Expression Denial of Service (ReDoS)

When running audit with the following command we get a medium severity issue!

npm audit --production --only=prod --audit-level=low --registry=https://registry.npmjs.org

node_modules/@odata/client/node_modules/fast-glob/node_modules/glob-parent
  fast-glob  *
  Depends on vulnerable versions of glob-parent
  node_modules/@odata/client/node_modules/fast-glob
    globby  >=8.0.0
    Depends on vulnerable versions of fast-glob
    node_modules/@odata/client/node_modules/globby
      @typescript-eslint/typescript-estree  >=3.10.2-alpha.0
      Depends on vulnerable versions of globby
      node_modules/@odata/client/node_modules/@typescript-eslint/typescript-estree
        @typescript-eslint/parser  >=3.10.2-alpha.0
        Depends on vulnerable versions of @typescript-eslint/typescript-estree
        node_modules/@odata/client/node_modules/@typescript-eslint/parser
          @typescript-eslint/eslint-plugin  >=4.0.1-alpha.0
          Depends on vulnerable versions of @typescript-eslint/parser
          Depends on vulnerable versions of @typescript-eslint/utils
          node_modules/@odata/client/node_modules/@typescript-eslint/eslint-plugin
        @typescript-eslint/utils  *
        Depends on vulnerable versions of @typescript-eslint/typescript-estree
        node_modules/@odata/client/node_modules/@typescript-eslint/utils
          @typescript-eslint/type-utils  >=5.9.2-alpha.0
          Depends on vulnerable versions of @typescript-eslint/utils
          node_modules/@odata/client/node_modules/@typescript-eslint/type-utils

Please fix this issue by updating the depending packages.

Nested expand

Hi @Soontao,

is it possible to have a nested expand like in the following example:

const expand = OData.newParam().expand('to_ConnectionObjectNotes/to_NoteText/to_NoteTextT')

I get an error when I execute the request with the expand above:

"error": Object {
"code": "400",
"message": "Expected uri token 'STAR' could not be found in 'to_ConnectionObjectNotes/to_NoteText/to_NoteTextT' at position 26",
},

In general the URL for the request would look like the following, but I don't know how the library handles it in version 2.19.4:

http://localhost:4004/odata-service/Reading?$expand=to_ConnectionObjectNotes/to_NoteText/to_NoteTextT

Best regards
Mario

Feature Request: Enhance ODataFilter Class to Support OR Operator with Functions

Is your feature request related to a problem? Please describe.

Currently, it seems like the ODataFilter class doesn't support the usage of OR operators between different functions, which limits the filtering capabilities, especially when I want to perform string searches across multiple properties.

Describe the solution you'd like

I propose an enhancement in the ODataFilter class to support the OR operator between functions, making it possible to search a string in multiple properties simultaneously. This can be done by extending the existing methods or creating new methods to accommodate this functionality. The goal is to enable queries that look like this:

// Query should be able to support filters like:
// "substringof('test', CompanyName) eq true or substringof('test', CompanyDescription)"
OData
  .newFilter()
  .property("substringof('test', CompanyName)").eq(true)
  .or()
  .property("substringof('test', CompanyDescription)").eq(true)
  .build();

Describe alternatives you've considered

An alternative could be writing a custom function to handle these types of queries outside of the ODataFilter class. However, integrating this feature directly into the ODataFilter class would provide a more streamlined and native experience for the users.

Additional context

This feature enhancement would improve the flexibility and capabilities of the ODataFilter class, allowing for more complex and nuanced queries, especially when dealing with string searches across different properties.

visibility of getCsrfToken() method

Hello Soontao,

Is it possible to change the visibility of the getCsrfToken() method to public ?

private async getCsrfToken() {

For some reasons, I need to fetch/get the x-crsf-token without doing an odata request.
In SAPUI5 framework, you can get this token using the getSecurityToken() method:
https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.model.odata.v2.ODataModel%23methods/getSecurityToken

Thanks for you help,

BR,

Support for null query

I want to use a filter that would generate a query like: $filter=Name eq null but this is not currently possible. Passing null to the eq function is not possible and passing null as a string puts it between quotes like 'null'

Is there any way around this and if not can this feature be added?

UrlSearchParam is not a constructor

When adding $expand query parameter to the request I'm getting the following error:
UrlSearchParam is not a constructor

Error points to var rt = new UrlSearchParam(); in params.js in c4codata/lib/params.js
If I change var UrlSearchParam = require("@ungap/url-search-params"); to
var UrlSearchParam = require("@ungap/url-search-params").default; the error goes away.

Do not know if the problem is in the c4codata itself or in my config (I am using Create React App with TypeScript 3.5.1)

How to send a file?

config.body = JSON.stringify(body, ODataValueJSONReplacer);

Why does body turn into a string? When I try to send a file to the server, my FormData turns into "{}". Is it possible to do without this?

[Question] How to read all records from a collection

System Environment

  • OS: Windows 10
  • NodeJS Version: 16.14.2
  • This LIbrary Version: 2.20.1

I want to read all records for a given collection, currently I could only read 200 records.

I'm trying to read all the items in Orders collection from Northwind OData V4 service. I could only read 200 records and get "@Odata.nextlink" in reply. I tried making 2nd call by appending nextlink to the url, but I still get back same first 200 records. Can somebody help me with some example on how to do it?

for reference I want ti implement "Get All Records" feature highlighted in below screen.
image

Below is the sample code I've tried

let client = OData.New({ metadataUri: url, version: "v4"});
let result = await client.newRequest({
  collection: "Orders",
  params: OData.newParam().select("OderID"),
});
urlNew = url + result["@odata.nextLink"]
var finished = result["@odata.nextLink"] === undefined

do {
  let clientlocal = OData.New({ metadataUri: urlNew , version: "v4" });
  let resultlocal = await clientlocal.newRequest({
    collection: "Orders",
    params: OData.newParam().select("OderID"),
  });
  urlNew = url + result["@odata.nextLink"]
  finished = resultlocal["@odata.nextLink"] === undefined
} while (!finished)

Support for Edm.DateTime in KeyPredicate

Hello @Soontao,

I need to perform requests (GET, PATCH, DELETE) on entities that have datetimes in the key predicate :
/Entity(StartDate=datetime'2022-01-01T00%3A00%3A00',EndDate=datetime'2022-12-31T00%3A00%3A00')

And Date values are not supported in the formatIdString function :

private formatIdString(id: any): string {

Is is possible to improve this function to support date formats (especially Edm.DateTime) ?

You can find all OData v2 primitives Data Types here :
https://www.odata.org/documentation/odata-version-2-0/overview/#ServiceMetadataDocument

Thanks a lot for your help

BR,

Is it possible to set custom headers?

Hello Soontao,

at first: This library is great work. Thank you for this.

Now back to my question. Is it possible to set additional headers e.g. to pass a Bearer token?

Best regards.

[FEATURE REQUEST] nodejs native fetch support

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Generator removes $metadata from path

Generator seems to remove $metadata from metadata query

> ./node_modules/c4codata/lib/cli/index.js -d true -m https://myxxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/API_PURCHASEREQ_PROCESS_SRV/$metadata -u USER -p "Password"
fetch metadata: https://myXXXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/API_PURCHASEREQ_PROCESS_SRV/
Cannot read property 'edmx:DataServices' of undefined
TypeError: Cannot read property 'edmx:DataServices' of undefined
    at getEntityTypesDefault (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/generator/parser.js:43:29)
    at Object.parseMetaClassFromDefault (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/generator/parser.js:112:41)
    at Object.generateAllDefault (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/generator/generator.js:11:15)
    at generateAndWriteSingle (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/cli/index.js:89:40)
    at Object.<anonymous> (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/cli/index.js:117:21)
    at step (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/cli/index.js:44:23)
    at Object.next (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/cli/index.js:25:53)
    at fulfilled (/Users/ulysses/Code/projects/adb-safegate/contractreqtype/node_modules/c4codata/lib/cli/index.js:16:58)

Logging the fetch code /$metadata is not queried, thus not returned

while using batch feature, I always got "multipartBody.split is not a function" error[Question]

System Environment

  • OS:
  • NodeJS Version:
  • This LIbrary Version:

Question Description

add some question description here
I am trying to use batch feature, I followed the example(https://github.com/Soontao/light-odata/blob/74d2d0cfe2f1285482f8f3ca763db51b7df9446a/docs/Batch.md) provided, but got error as below
TypeError: multipartBody.split is not a function
at parseMultiPartContent (XXX@odata\client\lib\batch.js:128:37)
at OData.execBatchRequests (XXX\node_modules@odata\client\lib\odata.js:408:56)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Please advise, thanks!

CSRF Token Error

from early light-odata 2.0.0 version

        const r = await odata.newRequest<any>({
            collection: "BO_GLBalancePeroidBalanceCollection",
            method: "POST",
            entity: {
                ParentObjectID2: rootObjectId,
                FiscalYear: fiscalYear,
                Period: period
            }
        });
        console.log(r);
        const obj = r.d.results;
        // const obj = await GLBalancePeriodBalance.create({

        // });
        periodId = obj.ObjectID;
CSRF 令牌验证失败
TypeError: Cannot read property 'results' of undefined

[Question] How to use in this library in a browser environment

System Environment

  • OS: MacOS 14.4.1
  • NodeJS Version: none, I'm trying to load the library using a <script> tag in the latest firefox and chrome browser
  • This LIbrary Version: 2.21.9 from unpgk.com

Question Description

I am currently working on a legacy project where it is hard to add libraries using npm/yarn, therefore I tried to import the library using <script> tags as described in the README.md.
However it seem like the OData object is not added to the window object. I can see that the odata-client-umd.js file is fetched during load but nothing is added to the window object.
Other libraries I tried to import using a CDN like vue.js and axios are working as expected.

Here is an example index.html to show what I tried to do.

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
    <script src="https://unpkg.com/@odata/[email protected]/lib/odata-client-umd.js"></script>
</head>
<body>
<script>
    console.log(window)
    console.log(Vue)
    console.log(axios)
    console.log(OData)
</script>
</body>
</html>

I assume the issue is just me not understanding something obvious, but I would appreciate any help you can give me since this library looks awesome.

Best regards.

[Question] Support older version of nodejs

System Environment

  • OS: Ubuntu
  • NodeJS Version: 10.x
  • This LIbrary Version:2.21.0

Question Description

Due to the recent implementation change for native fetch support for polyfill, can't use latest version of OData Client

Due to this commit, I'm not able to use latest version of Odata client since I get globalThis is undefined error on older version of nodejs (10.x version). Due to certain reasons we need to use older version of nodejs. Is there any possibility to change the referred implementation to check if globalfetch is undefined or not. Something like below would work I believe:
if (globalThis == undefined || globalThis.fetch === undefined) { global.fetch = require("fetch-cookie")(require("node-fetch")); }

Client is not properly closing itself

ClientCredentialsOAuthClient has a function destroy() to call clearInterval()

Unfortunately there's no way to call this function from OData type itself as ClientCredentialsOAuthClient is private there.

Hanging setInterval() prevents proper Node shutdown.

destroy() function should be exposed.

On the other hand it's not clear why do you need to have setInterval() at all because you can simply check expiration of OAuth token on the next call.

[BUG] Can't retrieve by a GUID ID key

Describe the bug

It seems there is no way to retrieve an entity by its key if that key is Edm.Guid?

To Reproduce

  test("Read by GUID ID", async () => {
    const odata = OData.New({
      metadataUri: "https://services.odata.org/v4/OData/OData.svc/$metadata",
      version: "v4",
    });
    const result = await odata.newRequest<Advertisement>({
      collection: "Advertisements",
      id: "f89dee73-af9f-4cd4-b330-db93c25ff3c7",
    });
    expect(result.error).toBeUndefined();
    expect(result.Name).toEqual("Old School Lemonade Store, Retro Style");
  });

Produces an error "Bad Request - Error in query syntax."

Expected behavior

Maybe I need to define something like

class ODataGuid extends ODataValueObject {
    ...
}

and pass that object as the id? I'm not sure what the right approach here is.

[BUG] Package breaks `npm ci` command

Describe the bug

After installing the @odata/client package, npm ci stops working.

System Environment

  • OS: Windows 11
  • Node Version: 18.12.0
  • This Library Version: 2.21.1

To Reproduce

Steps to reproduce the behavior:

  1. Create empty npm project
  2. Run npm install @odata/client
  3. Run npm ci
  4. See error

Expected behavior

The command finishes without error

Additional context

Here is the error I get, for reference

$ npm ci

npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for @esbuild/[email protected]: wanted {"os":"android","arch":"arm"} (current: {"os":"win32","arch":"x64"})
npm ERR! notsup Valid OS:    android
npm ERR! notsup Valid Arch:  arm
npm ERR! notsup Actual OS:   win32
npm ERR! notsup Actual Arch: x64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.