{"id":14779,"library":"odata-v4-parser","title":"OData v4 Parser","description":"The `odata-v4-parser` package provides a JavaScript parser for OData v4 URI query strings, converting them into an Abstract Syntax Tree (AST). This allows developers to programmatically interpret and act upon OData query parameters like `$filter`, `$orderby`, `$top`, and `$skip`. The package's current specified version, 0.1.29, reflects its last update several years ago, making it an effectively abandoned project. It was primarily designed for CommonJS environments and does not actively support modern JavaScript features or evolving OData specifications. While it ships with TypeScript type definitions, its long-term maintenance status and compatibility with contemporary Node.js versions are highly questionable. It differentiates itself by offering a direct parsing utility for OData v4 queries, but its lack of updates means it may not support all features of the OData v4 standard or address potential security concerns inherent in parsing external input.","status":"abandoned","version":"0.1.29","language":"javascript","source_language":"en","source_url":"git://github.com/jaystack/odata-v4-parser","tags":["javascript","typescript"],"install":[{"cmd":"npm install odata-v4-parser","lang":"bash","label":"npm"},{"cmd":"yarn add odata-v4-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add odata-v4-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-first and effectively abandoned. Direct `require` is the intended import pattern for v0.1.29.","wrong":"import parser from 'odata-v4-parser'","symbol":"parser","correct":"const parser = require('odata-v4-parser');"},{"note":"The `parse` method is accessed directly from the default-exported parser object, handling full OData URI segments.","wrong":"import { parse } from 'odata-v4-parser'","symbol":"parser.parse","correct":"const parser = require('odata-v4-parser');\nconst ast = parser.parse('$filter=...');"},{"note":"The `filter` method provides a specific entry point for parsing $filter expressions, as shown in the package's GitHub README.","wrong":"import { filter } from 'odata-v4-parser'","symbol":"parser.filter","correct":"const parser = require('odata-v4-parser');\nconst filterAst = parser.filter('Title eq \\'Article1\\'');"}],"quickstart":{"code":"const parser = require('odata-v4-parser');\n\n// Example 1: Parsing a simple $filter expression\nconst filterQuery = \"$filter=Name eq 'John Doe' and Age gt 30\";\ntry {\n  const filterAst = parser.filter(filterQuery);\n  console.log('Parsed Filter AST:', JSON.stringify(filterAst, null, 2));\n} catch (e) {\n  console.error(`Error parsing filter '${filterQuery}':`, e.message);\n}\n\n// Example 2: Parsing a full OData URI (assuming a 'parse' method is available)\nconst fullODataQuery = \"$filter=Category/Name eq 'Books'&$orderby=Price desc&$top=5&$skip=10\";\ntry {\n  const fullAst = parser.parse(fullODataQuery);\n  console.log('Parsed Full Query AST:', JSON.stringify(fullAst, null, 2));\n} catch (e) {\n  console.error(`Error parsing full query '${fullODataQuery}':`, e.message);\n  console.log(\"Note: If 'parser.parse' is not available, you might need to parse sections individually.\");\n}\n\nconsole.log(\"\\nNote: The output AST structure depends on the internal implementation of this specific parser version.\");","lang":"javascript","description":"Demonstrates parsing OData $filter expressions and full OData URI query strings into an Abstract Syntax Tree (AST)."},"warnings":[{"fix":"Migrate to an actively maintained OData parser library, such as `@odata/parser` or a more recent community fork like `@jwstott/odata-v4-parser` if robust OData parsing is critical for your application.","message":"The `odata-v4-parser` package is effectively abandoned, with its last publish dating back several years. This means it lacks updates for new OData v4 specification features, compatibility with recent Node.js versions, and critical security patches.","severity":"breaking","affected_versions":">=0.1.29"},{"fix":"Always use `const parser = require('odata-v4-parser');` for importing the library in environments where it is still supported. For ESM projects, consider a modern alternative.","message":"This package was developed in a CommonJS-first era. Attempting to use ESM `import` statements will result in runtime errors in modern Node.js environments configured for ESM, or if `type: module` is set in `package.json`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid using this library in production environments where security is a concern. If unavoidable, strictly sanitize all OData query inputs before passing them to the parser.","message":"Due to its abandoned status, `odata-v4-parser` may contain unfixed security vulnerabilities, including potential regex denial-of-service (ReDoS) attacks or other input-related exploits common in parsing libraries.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Thoroughly inspect the generated AST by logging it and write extensive unit tests if you rely on its specific structure. Be prepared for manual migration if switching to a different parser.","message":"The internal Abstract Syntax Tree (AST) structure generated by `odata-v4-parser` is specific to this legacy version and may differ significantly from ASTs generated by other OData parsers or newer versions. There is no official, comprehensive documentation for the AST structure.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your module to CommonJS (`.cjs` file or remove `type: \"module\"`) or use a tool like `createRequire` for legacy modules (not recommended for an abandoned package). Better yet, migrate to a modern OData parser that supports ESM.","cause":"Attempting to use `require()` in an ES module (`.mjs` file or `type: \"module\"` in `package.json`).","error":"require is not defined in ESM module scope"},{"fix":"Ensure you are calling the methods on the correct `parser` object, as demonstrated in the quickstart. Inspect `console.log(parser)` to see its available properties. If the methods are truly missing, the library might not support the intended parsing action or the version is corrupted.","cause":"The `odata-v4-parser` object returned by `require` might not have the expected methods, or there's a misunderstanding of the API for this specific version.","error":"TypeError: parser.filter is not a function"},{"fix":"Simplify your OData query string to isolate the problematic part. Refer to the OData v4 specification and cross-reference with known limitations of older parsers. This package may not support all aspects of the full OData v4 grammar.","cause":"The parser might not correctly handle certain valid OData v4 syntax or extended features due to its age and lack of updates, leading to unexpected parsing failures for seemingly correct queries.","error":"Error: Expected `(` or whitespace but `$` found."}],"ecosystem":"npm"}