@nyc-transit-kit/nyc-open-data 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/package.json +53 -0
- package/src/catalog.ts +29 -0
- package/src/client.ts +21 -0
- package/src/datasets.ts +3 -0
- package/src/descriptors.ts +31 -0
- package/src/index.ts +12 -0
- package/src/internal/descriptor-records.ts +42 -0
- package/src/query.ts +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nyc-transit-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nyc-transit-kit/nyc-open-data",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./catalog": "./src/catalog.ts",
|
|
9
|
+
"./client": "./src/client.ts",
|
|
10
|
+
"./datasets": "./src/datasets.ts",
|
|
11
|
+
"./descriptors": "./src/descriptors.ts",
|
|
12
|
+
"./query": "./src/query.ts"
|
|
13
|
+
},
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.md",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"test": "bun test ./test"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nyc-transit-kit/contracts": "0.1.0",
|
|
26
|
+
"@nyc-transit-kit/soda3": "0.1.0",
|
|
27
|
+
"effect": "4.0.0-beta.83"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/mannyc2/nyc-transit-kit.git",
|
|
36
|
+
"directory": "packages/nyc-open-data"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/mannyc2/nyc-transit-kit#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/mannyc2/nyc-transit-kit/issues"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"bun",
|
|
44
|
+
"effect",
|
|
45
|
+
"mta",
|
|
46
|
+
"nyc",
|
|
47
|
+
"socrata",
|
|
48
|
+
"transit"
|
|
49
|
+
],
|
|
50
|
+
"engines": {
|
|
51
|
+
"bun": ">=1.3.14"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/catalog.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { catalogSearch } from "@nyc-transit-kit/soda3/catalog"
|
|
2
|
+
import { defaultDomain } from "./descriptors"
|
|
3
|
+
|
|
4
|
+
export const searchNycOpenDataCatalog = (input: {
|
|
5
|
+
readonly query?: string
|
|
6
|
+
readonly limit?: number
|
|
7
|
+
readonly offset?: number
|
|
8
|
+
}) => {
|
|
9
|
+
const request: {
|
|
10
|
+
readonly domain: string
|
|
11
|
+
query?: string
|
|
12
|
+
limit?: number
|
|
13
|
+
offset?: number
|
|
14
|
+
} = {
|
|
15
|
+
domain: defaultDomain
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (input.query !== undefined) {
|
|
19
|
+
request.query = input.query
|
|
20
|
+
}
|
|
21
|
+
if (input.limit !== undefined) {
|
|
22
|
+
request.limit = input.limit
|
|
23
|
+
}
|
|
24
|
+
if (input.offset !== undefined) {
|
|
25
|
+
request.offset = input.offset
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return catalogSearch(request)
|
|
29
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { exportResponse } from "@nyc-transit-kit/soda3/export"
|
|
2
|
+
import { defaultDomain } from "./descriptors"
|
|
3
|
+
|
|
4
|
+
export { queryNycOpenDataDataset } from "./query"
|
|
5
|
+
|
|
6
|
+
export const exportNycOpenDataDataset = (input: {
|
|
7
|
+
readonly datasetId: string
|
|
8
|
+
readonly format: "csv" | "json" | "geojson"
|
|
9
|
+
readonly query?: string
|
|
10
|
+
readonly range?: {
|
|
11
|
+
readonly start: number
|
|
12
|
+
readonly end: number
|
|
13
|
+
}
|
|
14
|
+
}) =>
|
|
15
|
+
exportResponse({
|
|
16
|
+
domain: defaultDomain,
|
|
17
|
+
datasetId: input.datasetId,
|
|
18
|
+
format: input.format,
|
|
19
|
+
...(input.query === undefined ? {} : { query: input.query }),
|
|
20
|
+
...(input.range === undefined ? {} : { range: input.range })
|
|
21
|
+
})
|
package/src/datasets.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { makeDescriptorRegistry } from "@nyc-transit-kit/contracts/descriptor-registry"
|
|
2
|
+
import { NycOpenDataDatasetDescriptor } from "@nyc-transit-kit/contracts/nyc-open-data"
|
|
3
|
+
import * as Schema from "effect/Schema"
|
|
4
|
+
import { nycOpenDataDescriptorRecords } from "./internal/descriptor-records"
|
|
5
|
+
|
|
6
|
+
export const defaultDomain = "data.cityofnewyork.us"
|
|
7
|
+
|
|
8
|
+
const decodeDescriptor = Schema.decodeUnknownSync(NycOpenDataDatasetDescriptor)
|
|
9
|
+
const descriptorRegistry = makeDescriptorRegistry({
|
|
10
|
+
descriptors: nycOpenDataDescriptorRecords.map((record) => decodeDescriptor(record)),
|
|
11
|
+
id: (dataset) => String(dataset.id)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const requireNycOpenDataDescriptor = (datasetId: string) => {
|
|
15
|
+
const descriptor = descriptorRegistry.findById(datasetId)
|
|
16
|
+
if (descriptor === undefined) {
|
|
17
|
+
throw new Error(`Missing NYC Open Data descriptor: ${datasetId}`)
|
|
18
|
+
}
|
|
19
|
+
return descriptor
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const busLanesLocalStreetsDescriptor = requireNycOpenDataDescriptor("ycrg-ses3")
|
|
23
|
+
|
|
24
|
+
export const dotTrafficSpeedsDescriptor = requireNycOpenDataDescriptor("i4gi-tjb9")
|
|
25
|
+
|
|
26
|
+
export const trafficVolumeCountsDescriptor = requireNycOpenDataDescriptor("btm5-ppia")
|
|
27
|
+
|
|
28
|
+
export const knownNycOpenDataDatasets: ReadonlyArray<NycOpenDataDatasetDescriptor> =
|
|
29
|
+
descriptorRegistry.all
|
|
30
|
+
|
|
31
|
+
export const findNycOpenDataDataset = (datasetId: string) => descriptorRegistry.findById(datasetId)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const packageName = "@nyc-transit-kit/nyc-open-data"
|
|
2
|
+
export { searchNycOpenDataCatalog } from "./catalog"
|
|
3
|
+
export { exportNycOpenDataDataset } from "./client"
|
|
4
|
+
export {
|
|
5
|
+
busLanesLocalStreetsDescriptor,
|
|
6
|
+
defaultDomain,
|
|
7
|
+
dotTrafficSpeedsDescriptor,
|
|
8
|
+
findNycOpenDataDataset,
|
|
9
|
+
knownNycOpenDataDatasets,
|
|
10
|
+
trafficVolumeCountsDescriptor
|
|
11
|
+
} from "./descriptors"
|
|
12
|
+
export { queryNycOpenDataDataset } from "./query"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NycOpenDataDatasetDescriptorInput } from "@nyc-transit-kit/contracts/nyc-open-data"
|
|
2
|
+
|
|
3
|
+
export const nycOpenDataDescriptorRecords = [
|
|
4
|
+
{
|
|
5
|
+
id: "ycrg-ses3",
|
|
6
|
+
name: "Bus Lanes - Local Streets",
|
|
7
|
+
domain: "data.cityofnewyork.us",
|
|
8
|
+
agency: "DOT",
|
|
9
|
+
backing: "socrata",
|
|
10
|
+
description: "NYC DOT bus lane centerline dataset hosted on NYC Open Data.",
|
|
11
|
+
sourceUrl: "https://data.cityofnewyork.us/d/ycrg-ses3",
|
|
12
|
+
tags: ["transportation", "transit"],
|
|
13
|
+
adapterStatus: "none",
|
|
14
|
+
lastVerified: "2026-06-16"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "i4gi-tjb9",
|
|
18
|
+
name: "DOT Traffic Speeds",
|
|
19
|
+
domain: "data.cityofnewyork.us",
|
|
20
|
+
agency: "DOT",
|
|
21
|
+
backing: "socrata",
|
|
22
|
+
description: "NYC DOT traffic speeds dataset hosted on NYC Open Data.",
|
|
23
|
+
sourceUrl: "https://data.cityofnewyork.us/d/i4gi-tjb9",
|
|
24
|
+
tags: ["transportation", "traffic"],
|
|
25
|
+
temporalFields: ["data_as_of"],
|
|
26
|
+
adapterStatus: "none",
|
|
27
|
+
lastVerified: "2026-06-16"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "btm5-ppia",
|
|
31
|
+
name: "Traffic Volume Counts Historical",
|
|
32
|
+
domain: "data.cityofnewyork.us",
|
|
33
|
+
agency: "DOT",
|
|
34
|
+
backing: "socrata",
|
|
35
|
+
description: "NYC DOT historical traffic volume counts dataset hosted on NYC Open Data.",
|
|
36
|
+
sourceUrl: "https://data.cityofnewyork.us/d/btm5-ppia",
|
|
37
|
+
tags: ["transportation", "traffic"],
|
|
38
|
+
temporalFields: ["count_date"],
|
|
39
|
+
adapterStatus: "none",
|
|
40
|
+
lastVerified: "2026-06-16"
|
|
41
|
+
}
|
|
42
|
+
] satisfies ReadonlyArray<NycOpenDataDatasetDescriptorInput>
|
package/src/query.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { queryRows } from "@nyc-transit-kit/soda3/query"
|
|
2
|
+
import { defaultDomain } from "./descriptors"
|
|
3
|
+
|
|
4
|
+
export const queryNycOpenDataDataset = (input: {
|
|
5
|
+
readonly datasetId: string
|
|
6
|
+
readonly query: string
|
|
7
|
+
readonly page?: {
|
|
8
|
+
readonly pageNumber: number
|
|
9
|
+
readonly pageSize: number
|
|
10
|
+
}
|
|
11
|
+
}) =>
|
|
12
|
+
input.page === undefined
|
|
13
|
+
? queryRows({
|
|
14
|
+
domain: defaultDomain,
|
|
15
|
+
datasetId: input.datasetId,
|
|
16
|
+
query: input.query
|
|
17
|
+
})
|
|
18
|
+
: queryRows({
|
|
19
|
+
domain: defaultDomain,
|
|
20
|
+
datasetId: input.datasetId,
|
|
21
|
+
query: input.query,
|
|
22
|
+
page: input.page
|
|
23
|
+
})
|