# xrefparser

> OpenEdge XREF parser

Latest version **3.1.0** (published 2018-11-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install xrefparser
pnpm add xrefparser
yarn add xrefparser
bun add xrefparser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2018-11-30 |
| First published | 2018-06-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 71.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | bfv |
| Maintainers | bfv |
| Keywords | openedge, xref, db |

## Links

- npm: https://www.npmjs.com/package/xrefparser
- Repository: https://github.com/bfv/xrefparser
- Homepage: https://github.com/bfv/xrefparser#readme
- Issues: https://github.com/bfv/xrefparser/issues
- npm.io page: https://npm.io/package/xrefparser

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^10.3.2

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 3.1.0 (latest) — 2018-11-30
- 3.0.4 — 2018-08-06
- 3.0.3 — 2018-08-06
- 3.0.2 — 2018-07-27
- 3.0.1 — 2018-07-27
- 3.0.0 — 2018-07-27
- 2.2.1 — 2018-07-17
- 2.2.0 — 2018-07-17
- 2.1.1 — 2018-07-17
- 2.1.0 — 2018-07-04
- 2.0.0 — 2018-07-04
- 1.1.0 — 2018-07-02
- 1.0.0 — 2018-07-02
- 0.3.5 — 2018-06-22
- 0.3.4 — 2018-06-22
- … 14 more at https://npm.io/package/xrefparser/versions

## README

# OpenEdge XREF parser in TypeScript

This is a parser/searcher library for OpenEdge xref files.

## Initialization

Searching the sources which contain creates and deletes of in 'Klantbes' table is as easy as:

```
import { Parser, Searcher } from 'xrefparser';

const parser = new Parser();
const xrefdata = parser.parseDir('c:/usr/xref', 'D:\\wintmp\\build492943069\\devmain\\');

const searcher = new Searcher(xrefdata);

const sources = searcher
                .getTableReferences('Klantbes', true, undefined, true)
                .map(table => table.sourcefile);

console.log(sources);

```

## Parser class
When instantiated there's basically one relevant method; parseDir

### parseDir
```
parseDir(dirname: string, sourcebasedir?: string): XrefFile[]
```

`dirname` is the root directory where all the .xref files are located.
`sourcebasedir` is the optional parameter stating what the root directory of the sources when they were compiled. This is substracted from the `sourcefile` properties.

## Searcher class
The only constructor takes `XrefFile[]` as input.

### add
```
add(xreffiles: Xreffile[]);
```

This method add/merges the `xreffiles` into the existing Xreffile[]'s.

### getDatabaseNames
```
getDatabaseNames(sources?: string[]): string[]
```

Returns an array of database names found in `sources`. If `sources` is undefined, all the database names of all sources are returned.

### getDatabaseReferences
```
getDatabaseReferences(databaseName: string): XrefFile[]
```

Returns an array  with all the `XrefFile` contains references to the `databaseName`

### getFieldReferences
```
getFieldReferences(fieldname: string, tablename?: string, hasUpdates?: boolean): XrefFile[]
```

Looks for occurences of `fieldname`, optionally in table `tablename`. The optional `hasUpdates` parameter gives the possibility the search for sources which update a certain field (or not). If `tablename` or `hasUpdates` are not to be taken into consideration, omit them or pass `undefined`.


### getTableReferences
```
getTableReferences(tablename: string, hasCreates?: boolean, hasUpdates?: boolean, hasDeletes?: boolean): Xreffile[]
```

Looks for uses of `tablename` in the all the `Xreffile` objects and returns `XrefFile[]`. Use `map` as in the example to turn it into an array of source names (or whatever you want). If for the `has*` parameters `undefined` is used, the particular action is not searched for. This contrary to `hasCreated = false` where sources are returned that do *not* create the particular table.

## Performance
Above case takes on a Dell XPS15 9560 around 8s to parse all the xref files and 3ms to search for create/delete references in the 'Klantbes' table.
There are around 3850 xref files which are combined 350MB on disk.

## Release notes
The release notes can be found at [github/releasenotes.md](https://github.com/bfv/xrefparser/blob/master/releasenotes.md)

## Example `Xreffile`
The `Parser` turns in the `.xref` files into an array of `Xreffile` objects. Beneath an example which is pretty self explanatory:
```
{
  "xreffile": "C:/devoe/sandbox/src/xref_out/xref/CustomerBE.cls.xref",
  "sourcefile": "xref/CustomerBE.cls",
  "cpInternal": "UTF-8",
  "cpStream": "UTF-8",
  "includes": [
    "xref/findfirstcustomer.i"
  ],
  "tablenames": [
    "Customer"
  ],
  "classes": [],
  "invokes": [
    "xref.BaseClass:Cleanup",
    "xref.BusinessEntity:BusinessEntity",
    "xref.CustomerBE:Cleanup"
  ],
  "annotations": [
    "todo(version=12.x, message=refactor for efficiency)",
    "linecheck(lineno=44)",
    "linecheck(lineno=46)"
  ],
  "tables": [
    {
      "name": "Customer",
      "database": "sports2000",
      "isCreated": false,
      "isDeleted": false,
      "isUpdated": true,
      "fields": [
        {
          "name": "CustNum",
          "isUpdated": false
        },
        {
          "name": "CreditLimit",
          "isUpdated": true
        },
        {
          "name": "Name",
          "isUpdated": false
        }
      ]
    }
  ],
  "class": {
    "name": "xref.CustomerBE",
    "inherits": "xref.BusinessEntity",
    "implements": [
      "xref.IDisposable"
    ]
  }
}
```

---
_Source: https://npm.io/package/xrefparser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
