Skip to content

Commit

Permalink
Merge pull request #39 from openaddresses/schema
Browse files Browse the repository at this point in the history
Feature Layer => JSON Schema
  • Loading branch information
ingalls authored Jul 24, 2023
2 parents a2eeea4 + 6ab64c5 commit 3d301f5
Show file tree
Hide file tree
Showing 32 changed files with 2,050 additions and 536 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"plugins": ["@typescript-eslint"],
"root": true,
"rules": {
"@typescript-eslint/ban-ts-comment": 1
"@typescript-eslint/ban-ts-comment": 1,
"@typescript-eslint/no-explicit-any": 1
}
}
42 changes: 32 additions & 10 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,61 @@ import EsriDump from './index.js';
import minimist from 'minimist';

const argv = minimist(process.argv, {
string: ['approach'],
string: ['approach', 'header'],
boolean: ['help']
});

if (argv.help) {
console.log();
console.log('Usage:');
console.log(' node cli.js [--help] [--approach=bbox]');
console.log(' node cli.js [mode] [--help]');
console.log();
console.log('Args:');
console.log(' --help Display this message');
console.log('Mode: fetch [--approach] <url>');
console.log(' --header \'key=value\' IE --header \'Content-Type=123\'');
console.log(' --approach [approach] Download Approach');
console.log(' "bbox" Download features by iterating over bboxes');
console.log(' slowest but most reliable approach');
console.log(' "iter" Iterate over OIDs');
console.log(' faster but not supported by all servers');
console.log('Mode: schema <url>');
console.log();
process.exit();
}

const url = argv._[2];
if (!argv._[2]) throw new Error('Mode required');

const url = argv._[3];
if (!url) throw new Error('url required');

const headers: any = {};

Check warning on line 34 in cli.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (argv.header) {
if (typeof argv.header === 'string') argv.header = [ argv.header ];
for (const header of argv.header) {
const parsed = header.split('=');
headers[parsed[0]] = parsed.slice(1, parsed.length).join('=');
}
}


const esri = new EsriDump(url, {
approach: argv.approach
approach: argv.approach,
headers
});

esri.on('error', (err) => {
throw err;
}).on('feature', (feature) => {
console.log(JSON.stringify(feature));
});

await esri.fetch();
if (argv._[2] === 'fetch') {
esri.on('error', (err) => {
throw err;
}).on('feature', (feature) => {
console.log(JSON.stringify(feature));
});

await esri.fetch();
} else if (argv._[2] === 'schema') {
await esri.schema();
} else {
throw new Error('Unknown Mode');
}

43 changes: 33 additions & 10 deletions dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cli.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 67 additions & 24 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d301f5

Please sign in to comment.