@nyc-transit-kit/mta 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 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
@@ -0,0 +1,5 @@
1
+ # @nyc-transit-kit/mta
2
+
3
+ Part of `nyc-transit-kit`, an Effect-native Bun toolkit for official NYC and MTA transit data APIs.
4
+
5
+ See the repository README and docs/api-reference.md for public import paths, CLI commands, and release notes.
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@nyc-transit-kit/mta",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": "./src/index.ts",
8
+ "./datasets": "./src/datasets.ts",
9
+ "./feeds": "./src/feeds.ts",
10
+ "./errors": "./src/errors.ts",
11
+ "./gtfs-realtime": "./src/gtfs-realtime.ts",
12
+ "./gtfs-static": "./src/gtfs-static.ts",
13
+ "./open-data": "./src/open-data.ts"
14
+ },
15
+ "types": "./src/index.ts",
16
+ "files": [
17
+ "LICENSE",
18
+ "README.md",
19
+ "src"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc -b",
23
+ "test": "bun test ./test"
24
+ },
25
+ "dependencies": {
26
+ "@nyc-transit-kit/contracts": "0.1.0",
27
+ "@nyc-transit-kit/soda3": "0.1.0",
28
+ "effect": "4.0.0-beta.83",
29
+ "gtfs-realtime-bindings": "2.0.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/mannyc2/nyc-transit-kit.git",
38
+ "directory": "packages/mta"
39
+ },
40
+ "homepage": "https://github.com/mannyc2/nyc-transit-kit#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/mannyc2/nyc-transit-kit/issues"
43
+ },
44
+ "keywords": [
45
+ "bun",
46
+ "effect",
47
+ "mta",
48
+ "nyc",
49
+ "socrata",
50
+ "transit"
51
+ ],
52
+ "engines": {
53
+ "bun": ">=1.3.14"
54
+ }
55
+ }
@@ -0,0 +1,27 @@
1
+ import { makeDescriptorRegistry } from "@nyc-transit-kit/contracts/descriptor-registry"
2
+ import { MtaOpenDataDatasetDescriptor } from "@nyc-transit-kit/contracts/mta"
3
+ import * as Schema from "effect/Schema"
4
+ import { mtaOpenDataDescriptorRecords } from "./internal/open-data-descriptor-records"
5
+
6
+ export const mtaOpenDataDomain = "data.ny.gov"
7
+
8
+ const decodeDescriptor = Schema.decodeUnknownSync(MtaOpenDataDatasetDescriptor)
9
+ const descriptorRegistry = makeDescriptorRegistry({
10
+ descriptors: mtaOpenDataDescriptorRecords.map((record) => decodeDescriptor(record)),
11
+ id: (dataset) => String(dataset.id)
12
+ })
13
+
14
+ const requireMtaOpenDataDescriptor = (datasetId: string) => {
15
+ const descriptor = descriptorRegistry.findById(datasetId)
16
+ if (descriptor === undefined) {
17
+ throw new Error(`Missing MTA Open Data descriptor: ${datasetId}`)
18
+ }
19
+ return descriptor
20
+ }
21
+
22
+ export const mtaOpenDataCatalogDescriptor = requireMtaOpenDataDescriptor("f462-ka72")
23
+
24
+ export const mtaOpenDataDatasets: ReadonlyArray<MtaOpenDataDatasetDescriptor> =
25
+ descriptorRegistry.all
26
+
27
+ export const findMtaOpenDataDataset = (datasetId: string) => descriptorRegistry.findById(datasetId)
package/src/errors.ts ADDED
@@ -0,0 +1,22 @@
1
+ import * as Schema from "effect/Schema"
2
+
3
+ export class MtaHttpError extends Schema.TaggedErrorClass<MtaHttpError>()("MtaHttpError", {
4
+ operation: Schema.String,
5
+ status: Schema.Number,
6
+ statusText: Schema.String
7
+ }) {}
8
+
9
+ export class MtaDecodeError extends Schema.TaggedErrorClass<MtaDecodeError>()("MtaDecodeError", {
10
+ feed: Schema.String,
11
+ message: Schema.String
12
+ }) {}
13
+
14
+ export class MtaInvalidInputError extends Schema.TaggedErrorClass<MtaInvalidInputError>()(
15
+ "MtaInvalidInputError",
16
+ {
17
+ operation: Schema.String,
18
+ message: Schema.String
19
+ }
20
+ ) {}
21
+
22
+ export type MtaError = MtaHttpError | MtaDecodeError | MtaInvalidInputError
package/src/feeds.ts ADDED
@@ -0,0 +1,69 @@
1
+ import type { GtfsFeedKind } from "@nyc-transit-kit/contracts/mta"
2
+ import {
3
+ mtaGtfsRealtimeFeedRecords,
4
+ mtaGtfsStaticFeedRecords,
5
+ mtaJsonDirectFeedRecords
6
+ } from "./internal/direct-feed-records"
7
+
8
+ export type MtaDirectFeedSurface =
9
+ | "gtfs-static"
10
+ | "gtfs-realtime"
11
+ | "service-alerts"
12
+ | "elevator-escalator"
13
+ | "bus-time"
14
+
15
+ export interface MtaDirectFeedDescriptor {
16
+ readonly id: string
17
+ readonly name: string
18
+ readonly surface: MtaDirectFeedSurface
19
+ readonly url: string
20
+ readonly description?: string
21
+ }
22
+
23
+ export interface MtaGtfsStaticFeedDescriptor extends MtaDirectFeedDescriptor {
24
+ readonly surface: "gtfs-static"
25
+ readonly mode: "subway" | "rail" | "bus"
26
+ }
27
+
28
+ export interface MtaGtfsRealtimeFeedDescriptor extends MtaDirectFeedDescriptor {
29
+ readonly surface: "gtfs-realtime"
30
+ readonly feed: GtfsFeedKind
31
+ readonly family: "subway" | "rail" | "alerts"
32
+ }
33
+
34
+ export interface MtaJsonDirectFeedDescriptor extends MtaDirectFeedDescriptor {
35
+ readonly surface: "service-alerts" | "elevator-escalator" | "bus-time"
36
+ readonly format: "json" | "xml"
37
+ readonly requiresApiKey?: boolean
38
+ }
39
+
40
+ export const mtaGtfsStaticFeeds = mtaGtfsStaticFeedRecords
41
+
42
+ export const mtaGtfsRealtimeFeeds = mtaGtfsRealtimeFeedRecords
43
+
44
+ export const mtaJsonDirectFeeds = mtaJsonDirectFeedRecords
45
+
46
+ export const mtaDirectFeeds = [
47
+ ...mtaGtfsStaticFeeds,
48
+ ...mtaGtfsRealtimeFeeds,
49
+ ...mtaJsonDirectFeeds
50
+ ] satisfies ReadonlyArray<
51
+ MtaGtfsStaticFeedDescriptor | MtaGtfsRealtimeFeedDescriptor | MtaJsonDirectFeedDescriptor
52
+ >
53
+
54
+ const normalizedLookupKey = (value: string) => value.trim().toLowerCase()
55
+
56
+ const findFeed = <Feed extends MtaDirectFeedDescriptor>(
57
+ feeds: ReadonlyArray<Feed>,
58
+ key: string
59
+ ) => {
60
+ const normalized = normalizedLookupKey(key)
61
+ return feeds.find(
62
+ (feed) =>
63
+ normalizedLookupKey(feed.id) === normalized || normalizedLookupKey(feed.name) === normalized
64
+ )
65
+ }
66
+
67
+ export const findMtaGtfsStaticFeed = (key: string) => findFeed(mtaGtfsStaticFeeds, key)
68
+
69
+ export const findMtaGtfsRealtimeFeed = (key: string) => findFeed(mtaGtfsRealtimeFeeds, key)
@@ -0,0 +1,259 @@
1
+ import {
2
+ type GtfsFeedKind,
3
+ MtaGtfsRealtimeCaptureRequest,
4
+ type MtaGtfsRealtimeCaptureRequestInput,
5
+ MtaGtfsRealtimeCaptureResult,
6
+ MtaGtfsRealtimeDecodedHeader,
7
+ MtaGtfsRealtimeDecodedSummary,
8
+ MtaGtfsRealtimeProbeRequest,
9
+ type MtaGtfsRealtimeProbeRequestInput,
10
+ MtaGtfsRealtimeProbeResult
11
+ } from "@nyc-transit-kit/contracts/mta"
12
+ import * as Context from "effect/Context"
13
+ import * as Effect from "effect/Effect"
14
+ import * as Layer from "effect/Layer"
15
+ import * as Schema from "effect/Schema"
16
+ import * as HttpClient from "effect/unstable/http/HttpClient"
17
+ import type * as HttpClientError from "effect/unstable/http/HttpClientError"
18
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest"
19
+ import * as GtfsRealtimeBindings from "gtfs-realtime-bindings"
20
+ import { MtaDecodeError, MtaHttpError, MtaInvalidInputError } from "./errors"
21
+
22
+ export type GtfsRealtimeDecoderImplementation = (
23
+ bytes: Uint8Array,
24
+ feed: GtfsFeedKind
25
+ ) => Effect.Effect<unknown, MtaDecodeError>
26
+ export type { MtaGtfsRealtimeCaptureRequestInput, MtaGtfsRealtimeProbeRequestInput }
27
+
28
+ const FeedMessage = GtfsRealtimeBindings.transit_realtime.FeedMessage
29
+ const FeedHeaderIncrementality = GtfsRealtimeBindings.transit_realtime.FeedHeader.Incrementality
30
+
31
+ const hasOwn = (value: object, key: PropertyKey) => Object.hasOwn(value, key)
32
+
33
+ const errorMessage = (cause: unknown) => (cause instanceof Error ? cause.message : String(cause))
34
+
35
+ const byteToHex = (byte: number) => byte.toString(16).padStart(2, "0")
36
+
37
+ const arrayBufferFromBytes = (bytes: Uint8Array) => {
38
+ const buffer = new ArrayBuffer(bytes.byteLength)
39
+ new Uint8Array(buffer).set(bytes)
40
+ return buffer
41
+ }
42
+
43
+ const shouldRedactSearchParameter = (name: string) => {
44
+ const lower = name.toLowerCase()
45
+ return lower.includes("key") || lower.includes("token") || lower.includes("secret")
46
+ }
47
+
48
+ const redactGtfsRealtimeUrl = (url: string) => {
49
+ try {
50
+ const parsed = new URL(url)
51
+
52
+ for (const name of parsed.searchParams.keys()) {
53
+ if (shouldRedactSearchParameter(name)) {
54
+ parsed.searchParams.set(name, "REDACTED")
55
+ }
56
+ }
57
+
58
+ return parsed.toString()
59
+ } catch {
60
+ return "[invalid-url]"
61
+ }
62
+ }
63
+
64
+ const incrementalityName = (
65
+ value: GtfsRealtimeBindings.transit_realtime.FeedHeader.Incrementality
66
+ ) => {
67
+ if (value === FeedHeaderIncrementality.FULL_DATASET) {
68
+ return "FULL_DATASET"
69
+ }
70
+ if (value === FeedHeaderIncrementality.DIFFERENTIAL) {
71
+ return "DIFFERENTIAL"
72
+ }
73
+ return String(value)
74
+ }
75
+
76
+ const decodedHeader = (header: GtfsRealtimeBindings.transit_realtime.IFeedHeader) =>
77
+ MtaGtfsRealtimeDecodedHeader.make({
78
+ gtfsRealtimeVersion: header.gtfsRealtimeVersion,
79
+ ...(hasOwn(header, "incrementality")
80
+ ? {
81
+ incrementality: incrementalityName(
82
+ header.incrementality ?? FeedHeaderIncrementality.FULL_DATASET
83
+ )
84
+ }
85
+ : {}),
86
+ ...(hasOwn(header, "timestamp") && header.timestamp !== undefined && header.timestamp !== null
87
+ ? { timestamp: Number(header.timestamp) }
88
+ : {})
89
+ })
90
+
91
+ export const decodeGtfsRealtimeBytes = Effect.fn("Mta.decodeGtfsRealtimeBytes")(function* (
92
+ bytes: Uint8Array,
93
+ feed: GtfsFeedKind
94
+ ) {
95
+ return yield* Effect.try({
96
+ try: () => {
97
+ const raw = FeedMessage.decode(bytes)
98
+ const entities = raw.entity
99
+
100
+ return MtaGtfsRealtimeDecodedSummary.make({
101
+ feed,
102
+ entityCount: entities.length,
103
+ tripUpdateCount: entities.filter(
104
+ (entity) => entity.tripUpdate !== undefined && entity.tripUpdate !== null
105
+ ).length,
106
+ vehiclePositionCount: entities.filter(
107
+ (entity) => entity.vehicle !== undefined && entity.vehicle !== null
108
+ ).length,
109
+ alertCount: entities.filter((entity) => entity.alert !== undefined && entity.alert !== null)
110
+ .length,
111
+ header: decodedHeader(raw.header),
112
+ raw
113
+ })
114
+ },
115
+ catch: (cause) =>
116
+ MtaDecodeError.make({
117
+ feed,
118
+ message: errorMessage(cause)
119
+ })
120
+ })
121
+ })
122
+
123
+ export class GtfsRealtimeDecoder extends Context.Service<
124
+ GtfsRealtimeDecoder,
125
+ {
126
+ readonly decode: GtfsRealtimeDecoderImplementation
127
+ }
128
+ >()("@nyc-transit-kit/mta/GtfsRealtimeDecoder") {
129
+ static readonly Live = Layer.succeed(GtfsRealtimeDecoder)({
130
+ decode: decodeGtfsRealtimeBytes
131
+ })
132
+
133
+ // Test/custom fallback for callers that want to bypass protobuf decoding.
134
+ static readonly Passthrough = Layer.succeed(GtfsRealtimeDecoder)({
135
+ decode: (bytes, feed) =>
136
+ Effect.succeed({
137
+ feed,
138
+ byteLength: bytes.byteLength
139
+ })
140
+ })
141
+ }
142
+
143
+ const decodeRealtimeInput =
144
+ <S extends Schema.Top>(schema: S) =>
145
+ (input: unknown) =>
146
+ Schema.decodeUnknownEffect(schema)(input).pipe(
147
+ Effect.catchTag("SchemaError", (error) =>
148
+ Effect.fail(
149
+ MtaInvalidInputError.make({
150
+ operation: "gtfs-realtime",
151
+ message: error.message
152
+ })
153
+ )
154
+ )
155
+ )
156
+
157
+ const decodeRealtimeProbeRequest = decodeRealtimeInput(MtaGtfsRealtimeProbeRequest)
158
+ const decodeRealtimeCaptureRequest = decodeRealtimeInput(MtaGtfsRealtimeCaptureRequest)
159
+
160
+ const httpStatusText = (status: number) => `HTTP ${status}`
161
+
162
+ const mapMtaHttpClientError = (operation: string, error: HttpClientError.HttpClientError) => {
163
+ const response = error.response
164
+
165
+ if (response !== undefined) {
166
+ return MtaHttpError.make({
167
+ operation,
168
+ status: response.status,
169
+ statusText: httpStatusText(response.status)
170
+ })
171
+ }
172
+
173
+ return MtaHttpError.make({
174
+ operation,
175
+ status: 0,
176
+ statusText: error.message
177
+ })
178
+ }
179
+
180
+ const fetchGtfsRealtimeBytes = Effect.fn("Mta.fetchGtfsRealtimeBytes")(function* (request: {
181
+ readonly feed: GtfsFeedKind
182
+ readonly url: string
183
+ }) {
184
+ const response = yield* HttpClient.execute(HttpClientRequest.get(request.url)).pipe(
185
+ Effect.mapError((error) => mapMtaHttpClientError("gtfs-realtime", error))
186
+ )
187
+
188
+ if (response.status < 200 || response.status >= 300) {
189
+ return yield* MtaHttpError.make({
190
+ operation: "gtfs-realtime",
191
+ status: response.status,
192
+ statusText: httpStatusText(response.status)
193
+ })
194
+ }
195
+
196
+ const buffer = yield* response.arrayBuffer.pipe(
197
+ Effect.mapError(() =>
198
+ MtaHttpError.make({
199
+ operation: "gtfs-realtime",
200
+ status: response.status,
201
+ statusText: "Failed to read response body"
202
+ })
203
+ )
204
+ )
205
+ const bytes = new Uint8Array(buffer)
206
+
207
+ return {
208
+ response,
209
+ bytes
210
+ }
211
+ })
212
+
213
+ const sha256Hex = Effect.fn("Mta.sha256Hex")(function* (bytes: Uint8Array, feed: GtfsFeedKind) {
214
+ const digest = yield* Effect.tryPromise({
215
+ try: () => crypto.subtle.digest("SHA-256", arrayBufferFromBytes(bytes)),
216
+ catch: (cause) =>
217
+ MtaDecodeError.make({
218
+ feed,
219
+ message: `Failed to hash GTFS realtime capture: ${errorMessage(cause)}`
220
+ })
221
+ })
222
+
223
+ return Array.from(new Uint8Array(digest), byteToHex).join("")
224
+ })
225
+
226
+ export const probeGtfsRealtime = Effect.fn("Mta.probeGtfsRealtime")(function* (
227
+ input: MtaGtfsRealtimeProbeRequestInput
228
+ ) {
229
+ const request = yield* decodeRealtimeProbeRequest(input)
230
+ const decoder = yield* GtfsRealtimeDecoder
231
+ const { response, bytes } = yield* fetchGtfsRealtimeBytes(request)
232
+ const decoded = yield* decoder.decode(bytes, request.feed)
233
+
234
+ return MtaGtfsRealtimeProbeResult.make({
235
+ feed: request.feed,
236
+ ok: response.status >= 200 && response.status < 300,
237
+ status: response.status,
238
+ byteLength: bytes.byteLength,
239
+ decoded
240
+ })
241
+ })
242
+
243
+ export const captureGtfsRealtime = Effect.fn("Mta.captureGtfsRealtime")(function* (
244
+ input: MtaGtfsRealtimeCaptureRequestInput
245
+ ) {
246
+ const request = yield* decodeRealtimeCaptureRequest(input)
247
+ const { response, bytes } = yield* fetchGtfsRealtimeBytes(request)
248
+ const sha256 = yield* sha256Hex(bytes, request.feed)
249
+
250
+ return MtaGtfsRealtimeCaptureResult.make({
251
+ feed: request.feed,
252
+ status: response.status,
253
+ byteLength: bytes.byteLength,
254
+ sha256,
255
+ capturedAt: new Date().toISOString(),
256
+ url: redactGtfsRealtimeUrl(request.url),
257
+ bytes
258
+ })
259
+ })
@@ -0,0 +1,117 @@
1
+ import {
2
+ MtaGtfsStaticFetchRequest,
3
+ type MtaGtfsStaticFetchRequestInput,
4
+ MtaGtfsStaticProbeResult
5
+ } from "@nyc-transit-kit/contracts/mta"
6
+ import * as Effect from "effect/Effect"
7
+ import * as Schema from "effect/Schema"
8
+ import * as Stream from "effect/Stream"
9
+ import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"
10
+ import * as HttpClient from "effect/unstable/http/HttpClient"
11
+ import type * as HttpClientError from "effect/unstable/http/HttpClientError"
12
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest"
13
+ import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse"
14
+ import { MtaHttpError, MtaInvalidInputError } from "./errors"
15
+
16
+ export type { MtaGtfsStaticFetchRequestInput }
17
+
18
+ export const MtaHttpLive = FetchHttpClient.layer
19
+
20
+ const decodeStaticFetchRequest = (input: unknown) =>
21
+ Schema.decodeUnknownEffect(MtaGtfsStaticFetchRequest)(input).pipe(
22
+ Effect.catchTag("SchemaError", (error) =>
23
+ Effect.fail(
24
+ MtaInvalidInputError.make({
25
+ operation: "gtfs-static",
26
+ message: error.message
27
+ })
28
+ )
29
+ )
30
+ )
31
+
32
+ const httpStatusText = (status: number) => `HTTP ${status}`
33
+
34
+ const mapMtaHttpClientError = (operation: string, error: HttpClientError.HttpClientError) => {
35
+ const response = error.response
36
+
37
+ if (response !== undefined) {
38
+ return MtaHttpError.make({
39
+ operation,
40
+ status: response.status,
41
+ statusText: httpStatusText(response.status)
42
+ })
43
+ }
44
+
45
+ return MtaHttpError.make({
46
+ operation,
47
+ status: 0,
48
+ statusText: error.message
49
+ })
50
+ }
51
+
52
+ const toWebResponse = (response: HttpClientResponse.HttpClientResponse) =>
53
+ Effect.map(
54
+ Stream.toReadableStreamEffect(response.stream),
55
+ (body) =>
56
+ new Response(body, {
57
+ status: response.status,
58
+ headers: response.headers
59
+ })
60
+ )
61
+
62
+ const responseContentLength = (response: HttpClientResponse.HttpClientResponse) => {
63
+ const value = response.headers["content-length"]
64
+ return value === undefined ? undefined : Number(value)
65
+ }
66
+
67
+ export const probeGtfsStatic = Effect.fn("Mta.probeGtfsStatic")(function* (
68
+ input: MtaGtfsStaticFetchRequestInput
69
+ ) {
70
+ const request = yield* decodeStaticFetchRequest(input)
71
+ const response = yield* HttpClient.execute(HttpClientRequest.head(request.url)).pipe(
72
+ Effect.mapError((error) => mapMtaHttpClientError("gtfs-static", error))
73
+ )
74
+
75
+ return MtaGtfsStaticProbeResult.make({
76
+ url: request.url,
77
+ ok: response.status >= 200 && response.status < 300,
78
+ status: response.status,
79
+ contentType: response.headers["content-type"],
80
+ contentLength: responseContentLength(response)
81
+ })
82
+ })
83
+
84
+ export const fetchGtfsStaticResponse = Effect.fn("Mta.fetchGtfsStaticResponse")(function* (
85
+ input: MtaGtfsStaticFetchRequestInput
86
+ ) {
87
+ const request = yield* decodeStaticFetchRequest(input)
88
+ const response = yield* HttpClient.execute(HttpClientRequest.get(request.url)).pipe(
89
+ Effect.mapError((error) => mapMtaHttpClientError("gtfs-static", error))
90
+ )
91
+
92
+ if (response.status < 200 || response.status >= 300) {
93
+ return yield* MtaHttpError.make({
94
+ operation: "gtfs-static",
95
+ status: response.status,
96
+ statusText: httpStatusText(response.status)
97
+ })
98
+ }
99
+
100
+ return yield* toWebResponse(response)
101
+ })
102
+
103
+ export const fetchGtfsStatic = Effect.fn("Mta.fetchGtfsStatic")(function* (
104
+ input: MtaGtfsStaticFetchRequestInput
105
+ ) {
106
+ const response = yield* fetchGtfsStaticResponse(input)
107
+
108
+ return yield* Effect.tryPromise({
109
+ try: () => response.arrayBuffer(),
110
+ catch: () =>
111
+ MtaHttpError.make({
112
+ operation: "gtfs-static",
113
+ status: response.status,
114
+ statusText: "Failed to read response body"
115
+ })
116
+ })
117
+ })
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ export const packageName = "@nyc-transit-kit/mta"
2
+ export const gtfsStaticSurface = "gtfs-static"
3
+ export const gtfsRealtimeSurface = "gtfs-realtime"
4
+ export {
5
+ findMtaOpenDataDataset,
6
+ mtaOpenDataCatalogDescriptor,
7
+ mtaOpenDataDatasets,
8
+ mtaOpenDataDomain
9
+ } from "./datasets"
10
+ export type { MtaError } from "./errors"
11
+ export { MtaDecodeError, MtaHttpError, MtaInvalidInputError } from "./errors"
12
+ export type {
13
+ MtaDirectFeedDescriptor,
14
+ MtaDirectFeedSurface,
15
+ MtaGtfsRealtimeFeedDescriptor,
16
+ MtaGtfsStaticFeedDescriptor,
17
+ MtaJsonDirectFeedDescriptor
18
+ } from "./feeds"
19
+ export {
20
+ findMtaGtfsRealtimeFeed,
21
+ findMtaGtfsStaticFeed,
22
+ mtaDirectFeeds,
23
+ mtaGtfsRealtimeFeeds,
24
+ mtaGtfsStaticFeeds,
25
+ mtaJsonDirectFeeds
26
+ } from "./feeds"
27
+ export type {
28
+ GtfsRealtimeDecoderImplementation,
29
+ MtaGtfsRealtimeCaptureRequestInput,
30
+ MtaGtfsRealtimeProbeRequestInput
31
+ } from "./gtfs-realtime"
32
+ export {
33
+ captureGtfsRealtime,
34
+ decodeGtfsRealtimeBytes,
35
+ GtfsRealtimeDecoder,
36
+ probeGtfsRealtime
37
+ } from "./gtfs-realtime"
38
+ export {
39
+ fetchGtfsStatic,
40
+ fetchGtfsStaticResponse,
41
+ MtaHttpLive,
42
+ probeGtfsStatic
43
+ } from "./gtfs-static"
44
+ export { queryMtaOpenData } from "./open-data"
@@ -0,0 +1,241 @@
1
+ import type {
2
+ MtaGtfsRealtimeFeedDescriptor,
3
+ MtaGtfsStaticFeedDescriptor,
4
+ MtaJsonDirectFeedDescriptor
5
+ } from "../feeds"
6
+
7
+ export const mtaGtfsStaticFeedRecords = [
8
+ {
9
+ id: "subway-regular",
10
+ name: "Subway Regular GTFS",
11
+ surface: "gtfs-static",
12
+ mode: "subway",
13
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_subway.zip"
14
+ },
15
+ {
16
+ id: "subway-supplemented",
17
+ name: "Subway Supplemented GTFS",
18
+ surface: "gtfs-static",
19
+ mode: "subway",
20
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_supplemented.zip"
21
+ },
22
+ {
23
+ id: "lirr",
24
+ name: "Long Island Rail Road GTFS",
25
+ surface: "gtfs-static",
26
+ mode: "rail",
27
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfslirr.zip"
28
+ },
29
+ {
30
+ id: "metro-north",
31
+ name: "Metro-North Railroad GTFS",
32
+ surface: "gtfs-static",
33
+ mode: "rail",
34
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfsmnr.zip"
35
+ },
36
+ {
37
+ id: "bronx-bus",
38
+ name: "Bronx Bus GTFS",
39
+ surface: "gtfs-static",
40
+ mode: "bus",
41
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_bx.zip"
42
+ },
43
+ {
44
+ id: "brooklyn-bus",
45
+ name: "Brooklyn Bus GTFS",
46
+ surface: "gtfs-static",
47
+ mode: "bus",
48
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_b.zip"
49
+ },
50
+ {
51
+ id: "manhattan-bus",
52
+ name: "Manhattan Bus GTFS",
53
+ surface: "gtfs-static",
54
+ mode: "bus",
55
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_m.zip"
56
+ },
57
+ {
58
+ id: "queens-bus",
59
+ name: "Queens Bus GTFS",
60
+ surface: "gtfs-static",
61
+ mode: "bus",
62
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_q.zip"
63
+ },
64
+ {
65
+ id: "staten-island-bus",
66
+ name: "Staten Island Bus GTFS",
67
+ surface: "gtfs-static",
68
+ mode: "bus",
69
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_si.zip"
70
+ },
71
+ {
72
+ id: "mta-bus-company",
73
+ name: "MTA Bus Company GTFS",
74
+ surface: "gtfs-static",
75
+ mode: "bus",
76
+ url: "https://rrgtfsfeeds.s3.amazonaws.com/gtfs_busco.zip"
77
+ }
78
+ ] satisfies ReadonlyArray<MtaGtfsStaticFeedDescriptor>
79
+
80
+ export const mtaGtfsRealtimeFeedRecords = [
81
+ {
82
+ id: "subway-ace",
83
+ name: "Subway A/C/E GTFS-RT",
84
+ surface: "gtfs-realtime",
85
+ feed: "trip-updates",
86
+ family: "subway",
87
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-ace"
88
+ },
89
+ {
90
+ id: "subway-bdfm",
91
+ name: "Subway B/D/F/M GTFS-RT",
92
+ surface: "gtfs-realtime",
93
+ feed: "trip-updates",
94
+ family: "subway",
95
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-bdfm"
96
+ },
97
+ {
98
+ id: "subway-g",
99
+ name: "Subway G GTFS-RT",
100
+ surface: "gtfs-realtime",
101
+ feed: "trip-updates",
102
+ family: "subway",
103
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-g"
104
+ },
105
+ {
106
+ id: "subway-jz",
107
+ name: "Subway J/Z GTFS-RT",
108
+ surface: "gtfs-realtime",
109
+ feed: "trip-updates",
110
+ family: "subway",
111
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-jz"
112
+ },
113
+ {
114
+ id: "subway-nqrw",
115
+ name: "Subway N/Q/R/W GTFS-RT",
116
+ surface: "gtfs-realtime",
117
+ feed: "trip-updates",
118
+ family: "subway",
119
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-nqrw"
120
+ },
121
+ {
122
+ id: "subway-l",
123
+ name: "Subway L GTFS-RT",
124
+ surface: "gtfs-realtime",
125
+ feed: "trip-updates",
126
+ family: "subway",
127
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-l"
128
+ },
129
+ {
130
+ id: "subway-1234567",
131
+ name: "Subway 1/2/3/4/5/6/7 GTFS-RT",
132
+ surface: "gtfs-realtime",
133
+ feed: "trip-updates",
134
+ family: "subway",
135
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs"
136
+ },
137
+ {
138
+ id: "staten-island-railway",
139
+ name: "Staten Island Railway GTFS-RT",
140
+ surface: "gtfs-realtime",
141
+ feed: "trip-updates",
142
+ family: "subway",
143
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs-si"
144
+ },
145
+ {
146
+ id: "lirr",
147
+ name: "Long Island Rail Road GTFS-RT",
148
+ surface: "gtfs-realtime",
149
+ feed: "trip-updates",
150
+ family: "rail",
151
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/lirr%2Fgtfs-lirr"
152
+ },
153
+ {
154
+ id: "metro-north",
155
+ name: "Metro-North Railroad GTFS-RT",
156
+ surface: "gtfs-realtime",
157
+ feed: "trip-updates",
158
+ family: "rail",
159
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/mnr%2Fgtfs-mnr"
160
+ },
161
+ {
162
+ id: "alerts-all",
163
+ name: "All MTA Service Alerts GTFS-RT",
164
+ surface: "gtfs-realtime",
165
+ feed: "alerts",
166
+ family: "alerts",
167
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fall-alerts"
168
+ },
169
+ {
170
+ id: "alerts-subway",
171
+ name: "Subway Service Alerts GTFS-RT",
172
+ surface: "gtfs-realtime",
173
+ feed: "alerts",
174
+ family: "alerts",
175
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fsubway-alerts"
176
+ },
177
+ {
178
+ id: "alerts-bus",
179
+ name: "Bus Service Alerts GTFS-RT",
180
+ surface: "gtfs-realtime",
181
+ feed: "alerts",
182
+ family: "alerts",
183
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fbus-alerts"
184
+ },
185
+ {
186
+ id: "alerts-lirr",
187
+ name: "LIRR Service Alerts GTFS-RT",
188
+ surface: "gtfs-realtime",
189
+ feed: "alerts",
190
+ family: "alerts",
191
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Flirr-alerts"
192
+ },
193
+ {
194
+ id: "alerts-metro-north",
195
+ name: "Metro-North Service Alerts GTFS-RT",
196
+ surface: "gtfs-realtime",
197
+ feed: "alerts",
198
+ family: "alerts",
199
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/camsys%2Fmnr-alerts"
200
+ }
201
+ ] satisfies ReadonlyArray<MtaGtfsRealtimeFeedDescriptor>
202
+
203
+ export const mtaJsonDirectFeedRecords = [
204
+ {
205
+ id: "elevator-escalator-current",
206
+ name: "Elevator/Escalator Status Current JSON",
207
+ surface: "elevator-escalator",
208
+ format: "json",
209
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fnyct_ene.json"
210
+ },
211
+ {
212
+ id: "elevator-escalator-upcoming",
213
+ name: "Elevator/Escalator Status Upcoming JSON",
214
+ surface: "elevator-escalator",
215
+ format: "json",
216
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fnyct_ene_upcoming.json"
217
+ },
218
+ {
219
+ id: "elevator-escalator-equipment",
220
+ name: "Elevator/Escalator Equipment JSON",
221
+ surface: "elevator-escalator",
222
+ format: "json",
223
+ url: "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fnyct_ene_equipments.json"
224
+ },
225
+ {
226
+ id: "bus-time-vehicle-monitoring",
227
+ name: "Bus Time SIRI Vehicle Monitoring",
228
+ surface: "bus-time",
229
+ format: "json",
230
+ requiresApiKey: true,
231
+ url: "https://bustime.mta.info/api/siri/vehicle-monitoring.json"
232
+ },
233
+ {
234
+ id: "bus-time-stop-monitoring",
235
+ name: "Bus Time SIRI Stop Monitoring",
236
+ surface: "bus-time",
237
+ format: "json",
238
+ requiresApiKey: true,
239
+ url: "https://bustime.mta.info/api/siri/stop-monitoring.json"
240
+ }
241
+ ] satisfies ReadonlyArray<MtaJsonDirectFeedDescriptor>
@@ -0,0 +1,15 @@
1
+ import type { MtaOpenDataDatasetDescriptorInput } from "@nyc-transit-kit/contracts/mta"
2
+
3
+ export const mtaOpenDataDescriptorRecords = [
4
+ {
5
+ id: "f462-ka72",
6
+ name: "MTA Open Data Catalog",
7
+ domain: "data.ny.gov",
8
+ backing: "socrata",
9
+ description: "MTA Open Data catalog entry surfaced through NYS Open Data.",
10
+ sourceUrl: "https://data.ny.gov/d/f462-ka72",
11
+ tags: ["transportation", "transit", "catalog"],
12
+ adapterStatus: "none",
13
+ lastVerified: "2026-06-16"
14
+ }
15
+ ] satisfies ReadonlyArray<MtaOpenDataDatasetDescriptorInput>
@@ -0,0 +1,23 @@
1
+ import { queryRows } from "@nyc-transit-kit/soda3/client"
2
+ import { mtaOpenDataDomain } from "./datasets"
3
+
4
+ export const queryMtaOpenData = (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: mtaOpenDataDomain,
15
+ datasetId: input.datasetId,
16
+ query: input.query
17
+ })
18
+ : queryRows({
19
+ domain: mtaOpenDataDomain,
20
+ datasetId: input.datasetId,
21
+ query: input.query,
22
+ page: input.page
23
+ })