Skip to content

Commit

Permalink
Merge pull request #28 from data-depot/staging
Browse files Browse the repository at this point in the history
chore: release
  • Loading branch information
Walee Ahmed authored May 9, 2020
2 parents f0180ff + 014a99e commit 557ccfc
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 43 deletions.
12 changes: 12 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/src/ @deanban @walleXD
/package.json @walleXD
/.github/workflows/ @walleXD
/config/ @walleXD
/.eslintrc.js @walleXD
/.gitignore @walleXD
/.nvmrc @walleXD
/jest.config.js @walleXD
/LICENSE @walleXD @deanban
/README.md @walleXD @deanban
/release.config.js @walleXD
/tsconfig.json @walleXD
3 changes: 0 additions & 3 deletions .releaserc

This file was deleted.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ functional SoQL wrapper to interact with Open Data API
```bash
# for js
yarn add ramda rxjs soda-ts
# for the adventurous 🤷🏼‍♂️
yarn add https://github.com/data-depot/soda-ts.git
# for ts
yarn add -D @types/ramda
```
Expand All @@ -33,7 +35,10 @@ import { createQuery } from 'soda-ts'
const query = createQuery({ src: 'w7w3-xahh' })

// to pull from other domains
const query = createQuery({ domain: 'data.cityofchicago.org', src: 'ydr8-5enu' })
const query = createQuery({
domain: 'data.cityofchicago.org',
src: 'ydr8-5enu'
})
```

A raw `query` is the most primitive form of query.
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": "0.1.6",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -9,6 +10,14 @@
"engines": {
"node": ">=10"
},
"keywords": [
"soda",
"opendata",
"socrata",
"rxjs",
"typescript",
"javascript"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
Expand Down Expand Up @@ -49,6 +58,7 @@
"author": "[email protected]",
"repository": "https://github.com/data-depot/soda-ts",
"homepage": "https://github.com/data-depot/soda-ts",
"description": "Seamlessly interact with OpenData APIs in TS or JS",
"module": "dist/soda-ts.esm.js",
"devDependencies": {
"@commitlint/config-conventional": "^8.3.4",
Expand Down
33 changes: 18 additions & 15 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
module.exports = {
"dryRun": false,
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
dryRun: false,
branches: ['master'],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
[
"@semantic-release/changelog",
'@semantic-release/changelog',
{
"changelogFile": "docs/CHANGELOG.md"
changelogFile: 'docs/CHANGELOG.md'
}
],
"@semantic-release/npm",
"@semantic-release/github",
'@semantic-release/npm',
'@semantic-release/github',
[
"@semantic-release/git",
'@semantic-release/git',
{
"assets": [
"docs/CHANGELOG.md",
"package.json",
"package-lock.json"
assets: [
'docs/CHANGELOG.md',
'package.json',
'package-lock.json'
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
message:
// eslint-disable-next-line no-template-curly-in-string
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
}
]
]
};
}
16 changes: 6 additions & 10 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const logger = debug('soda-ts:manager')
// unifity them and resuse nested types as needed

/** options for pagiantion manager creation */
interface ManagerOpts {
export interface ManagerOpts {
/** pagiantion item limits */
limit: number
/** items to offset by for req */
Expand All @@ -25,7 +25,7 @@ interface ManagerOpts {
}

/** options for pagination */
interface PaginationOpts {
export interface PaginationOpts {
limit: number
pageSize: number
offset: number
Expand Down Expand Up @@ -141,12 +141,9 @@ export const createManagerCreator = <T>(
* @param subject subject used to publish acquired data
*
*/
export const autoPaginator = async <T>(
// TODO: BREAKING CHANGE: turn it into a properly curryable fn like autoPaginator$
// this fn would fit that well within flow with pipe
manager: Manager<T>,
export const autoPaginator = <T>(
subject: Subject<T[]>
): Promise<void> => {
) => async (manager: Manager<T>): Promise<void> => {
let currentPageSize = 0
do {
try {
Expand All @@ -172,6 +169,5 @@ export const autoPaginator = async <T>(
*/
export const autoPaginator$ = <T>(
subject: Subject<T[]>
) => (manager: Manager<T>): Observable<void> => {
return defer(() => from(autoPaginator(manager, subject)))
}
) => (manager: Manager<T>): Observable<void> =>
defer(() => from(autoPaginator(subject)(manager)))
17 changes: 15 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { of, Observable } from 'rxjs'

// local
import { Query } from './types'

/**
* options for the `createQuery` fn
*/
interface QueryOpts {
export interface QueryOpts {
/** source data id */
src: string
/** domain of data source */
Expand All @@ -18,7 +20,7 @@ interface QueryOpts {
*
* @param queryOpts options to create a query w/
*
* @returns `Query` curried fn used by runners & managers to make requests
* @returns `Query` used by runners & managers to make requests
*/
export const createQuery = ({
src,
Expand All @@ -30,3 +32,14 @@ export const createQuery = ({
apiPath: apiPath ?? 'resource',
clauses: []
})

/**
* create Query Observable for SODA req
*
* @param queryOpts options to create a query w/
*
* @returns `Query` Observable
*/
export const createQuery$ = (
opts: QueryOpts
): Observable<Query> => of(createQuery(opts))
13 changes: 7 additions & 6 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const logger = debug('soda-ts:runner')
* runner
* )(query)
*/
export const createRunner = <T>(
authOpts?: AuthOpts
) => async (query: Query): Promise<T> => {
export const createRunner = <T>({
appToken,
keysCamelCased
}: AuthOpts = {}) => async (query: Query): Promise<T> => {
const url = `https://${query.domain}/${query.apiPath}/${query.src}.json`

logger(`making req to url: ${url}`)
Expand All @@ -59,8 +60,8 @@ export const createRunner = <T>(
)

const headers = {
...(authOpts?.appToken && {
'X-App-Token': authOpts?.appToken
...(appToken && {
'X-App-Token': appToken
})
}

Expand All @@ -79,7 +80,7 @@ export const createRunner = <T>(
})
.json<T>()

if (authOpts?.keysCamelCased) {
if (keysCamelCased) {
return camelCaseKeys(res)
} else {
return res
Expand Down
10 changes: 5 additions & 5 deletions test/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('manager', () => {
done()
})

await autoPaginator(manager, paginatorSubject)
await autoPaginator(paginatorSubject)(manager)
})

// eslint-disable-next-line jest/no-test-callback
Expand All @@ -118,7 +118,7 @@ describe('manager', () => {
}
})

await autoPaginator(manager, paginatorSubject)
await autoPaginator(paginatorSubject)(manager)
})

// eslint-disable-next-line jest/no-test-callback
Expand All @@ -135,7 +135,7 @@ describe('manager', () => {
}
})

await autoPaginator(newManager, paginatorSubject)
await autoPaginator(paginatorSubject)(newManager)
})

// eslint-disable-next-line jest/no-test-callback
Expand All @@ -159,7 +159,7 @@ describe('manager', () => {
}
})

await autoPaginator(manager, paginatorSubject)
await autoPaginator(paginatorSubject)(manager)
})

// eslint-disable-next-line jest/no-test-callback
Expand All @@ -184,7 +184,7 @@ describe('manager', () => {
}
})

await autoPaginator(manager, paginatorSubject)
await autoPaginator(paginatorSubject)(manager)
})

// eslint-disable-next-line jest/no-test-callback
Expand Down
8 changes: 7 additions & 1 deletion test/query.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createQuery } from '../src'
import { createQuery, createQuery$ } from '../src'

const SRC = 'w7w3-xahh'
const DOMAIN = 'data.cityofnewyork.us'
Expand Down Expand Up @@ -54,4 +54,10 @@ describe('query', () => {

expect(query.domain).toBe('TEST')
})

it('createQUery$', () => {
createQuery$({ src: SRC }).subscribe((val) => {
expect(val.src).toBe(SRC)
})
})
})

0 comments on commit 557ccfc

Please sign in to comment.