@uk-open-data-connectors/uk-sources 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/README.md +206 -0
- package/dist/ancientWoodland.d.ts +102 -0
- package/dist/ancientWoodland.d.ts.map +1 -0
- package/dist/ancientWoodland.js +245 -0
- package/dist/ancientWoodland.js.map +1 -0
- package/dist/bankRate.d.ts +107 -0
- package/dist/bankRate.d.ts.map +1 -0
- package/dist/bankRate.js +251 -0
- package/dist/bankRate.js.map +1 -0
- package/dist/carbonIntensity.d.ts +151 -0
- package/dist/carbonIntensity.d.ts.map +1 -0
- package/dist/carbonIntensity.js +257 -0
- package/dist/carbonIntensity.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/fixtures.d.ts +5 -0
- package/dist/fixtures.d.ts.map +1 -0
- package/dist/fixtures.js +11 -0
- package/dist/fixtures.js.map +1 -0
- package/dist/floodMonitoring.d.ts +70 -0
- package/dist/floodMonitoring.d.ts.map +1 -0
- package/dist/floodMonitoring.js +164 -0
- package/dist/floodMonitoring.js.map +1 -0
- package/dist/foodHygiene.d.ts +68 -0
- package/dist/foodHygiene.d.ts.map +1 -0
- package/dist/foodHygiene.js +103 -0
- package/dist/foodHygiene.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/onsDatasets.d.ts +67 -0
- package/dist/onsDatasets.d.ts.map +1 -0
- package/dist/onsDatasets.js +111 -0
- package/dist/onsDatasets.js.map +1 -0
- package/dist/parliamentSeats.d.ts +115 -0
- package/dist/parliamentSeats.d.ts.map +1 -0
- package/dist/parliamentSeats.js +202 -0
- package/dist/parliamentSeats.js.map +1 -0
- package/dist/planningDatasets.d.ts +65 -0
- package/dist/planningDatasets.d.ts.map +1 -0
- package/dist/planningDatasets.js +100 -0
- package/dist/planningDatasets.js.map +1 -0
- package/dist/policeCrimes.d.ts +152 -0
- package/dist/policeCrimes.d.ts.map +1 -0
- package/dist/policeCrimes.js +262 -0
- package/dist/policeCrimes.js.map +1 -0
- package/dist/registry.d.ts +17 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +67 -0
- package/dist/registry.js.map +1 -0
- package/dist/tflBikePoints.d.ts +65 -0
- package/dist/tflBikePoints.d.ts.map +1 -0
- package/dist/tflBikePoints.js +149 -0
- package/dist/tflBikePoints.js.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { UkDataAdapter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Food Standards Agency food hygiene register list. Keyless, published by
|
|
4
|
+
* the FSA under the Open Government Licence v3.
|
|
5
|
+
*
|
|
6
|
+
* The endpoint only answers when the FSA's version header is sent with it:
|
|
7
|
+
* called bare it returns HTTP 404 with "The API 'Authorities' doesn't exist".
|
|
8
|
+
*/
|
|
9
|
+
export declare const FSA_AUTHORITIES_URL = "https://api.ratings.food.gov.uk/Authorities/basic";
|
|
10
|
+
/** Header the FSA food hygiene API requires on every request. */
|
|
11
|
+
export declare const FSA_API_VERSION_HEADER = "x-api-version";
|
|
12
|
+
/** Version of the FSA API this adapter speaks. Version 1 no longer answers. */
|
|
13
|
+
export declare const FSA_API_VERSION = "2";
|
|
14
|
+
/** How many of the largest registers the summary keeps by default. */
|
|
15
|
+
export declare const DEFAULT_LARGEST_AUTHORITY_LIMIT = 10;
|
|
16
|
+
/**
|
|
17
|
+
* Which scheme a register runs. The Food Hygiene Rating Scheme (FHRS) covers
|
|
18
|
+
* England, Wales, and Northern Ireland. The Food Hygiene Information Scheme
|
|
19
|
+
* (FHIS) covers Scotland, where premises are rated pass or improve.
|
|
20
|
+
*/
|
|
21
|
+
export type FoodHygieneScheme = 'fhrs' | 'fhis';
|
|
22
|
+
/** One local authority's food hygiene register, as the FSA lists it. */
|
|
23
|
+
export interface FoodHygieneAuthority {
|
|
24
|
+
localAuthorityId: number;
|
|
25
|
+
/** The FSA's own code for the authority, which it publishes as a string. */
|
|
26
|
+
localAuthorityCode: string;
|
|
27
|
+
localAuthorityName: string;
|
|
28
|
+
/** How many establishments the register holds. */
|
|
29
|
+
establishmentCount: number;
|
|
30
|
+
scheme: FoodHygieneScheme;
|
|
31
|
+
}
|
|
32
|
+
/** Rolled-up counts across every register the FSA publishes. */
|
|
33
|
+
export interface FoodHygieneSummary {
|
|
34
|
+
authorityCount: number;
|
|
35
|
+
/** Establishments summed across every register. */
|
|
36
|
+
establishmentCount: number;
|
|
37
|
+
fhrsAuthorityCount: number;
|
|
38
|
+
fhisAuthorityCount: number;
|
|
39
|
+
/** The registers holding the most establishments, largest first. */
|
|
40
|
+
largestAuthorities: FoodHygieneAuthority[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parses an FSA /Authorities payload into registers.
|
|
44
|
+
*
|
|
45
|
+
* @param payload - the raw JSON body from the register endpoint
|
|
46
|
+
* @returns one flattened register per local authority
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseFoodHygieneAuthorities(payload: unknown): FoodHygieneAuthority[];
|
|
49
|
+
/**
|
|
50
|
+
* Totals the registers and keeps the largest ones.
|
|
51
|
+
*
|
|
52
|
+
* @param authorities - registers from {@link parseFoodHygieneAuthorities}
|
|
53
|
+
* @param largestAuthorityLimit - how many registers to keep in `largestAuthorities`
|
|
54
|
+
* @returns register, establishment, and scheme counts plus the largest registers
|
|
55
|
+
*/
|
|
56
|
+
export declare function summarizeFoodHygieneAuthorities(authorities: FoodHygieneAuthority[], largestAuthorityLimit?: number): FoodHygieneSummary;
|
|
57
|
+
/**
|
|
58
|
+
* Lists every local authority food hygiene register from the FSA.
|
|
59
|
+
*
|
|
60
|
+
* @param options - an optional fetch implementation
|
|
61
|
+
* @returns the registers the endpoint returns
|
|
62
|
+
*/
|
|
63
|
+
export declare function fetchFoodHygieneAuthorities(options?: {
|
|
64
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
65
|
+
}): Promise<FoodHygieneAuthority[]>;
|
|
66
|
+
/** Food Standards Agency food hygiene register adapter, keyless. */
|
|
67
|
+
export declare const foodHygieneAuthoritiesAdapter: UkDataAdapter<FoodHygieneAuthority[]>;
|
|
68
|
+
//# sourceMappingURL=foodHygiene.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foodHygiene.d.ts","sourceRoot":"","sources":["../src/foodHygiene.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AAEvF,iEAAiE;AACjE,eAAO,MAAM,sBAAsB,kBAAkB,CAAC;AAEtD,+EAA+E;AAC/E,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,sEAAsE;AACtE,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhD,wEAAwE;AACxE,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,gEAAgE;AAChE,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;CAC5C;AA6BD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,oBAAoB,EAAE,CAYpF;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,oBAAoB,EAAE,EACnC,qBAAqB,GAAE,MAAwC,GAC9D,kBAAkB,CAmBpB;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAAO,GACpD,OAAO,CAAC,oBAAoB,EAAE,CAAC,CASjC;AAED,oEAAoE;AACpE,eAAO,MAAM,6BAA6B,EAAE,aAAa,CAAC,oBAAoB,EAAE,CAW/E,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UkSourceApiError, UkSourceParseError } from './errors.js';
|
|
3
|
+
import { readFixtureJson } from './fixtures.js';
|
|
4
|
+
/**
|
|
5
|
+
* The Food Standards Agency food hygiene register list. Keyless, published by
|
|
6
|
+
* the FSA under the Open Government Licence v3.
|
|
7
|
+
*
|
|
8
|
+
* The endpoint only answers when the FSA's version header is sent with it:
|
|
9
|
+
* called bare it returns HTTP 404 with "The API 'Authorities' doesn't exist".
|
|
10
|
+
*/
|
|
11
|
+
export const FSA_AUTHORITIES_URL = 'https://api.ratings.food.gov.uk/Authorities/basic';
|
|
12
|
+
/** Header the FSA food hygiene API requires on every request. */
|
|
13
|
+
export const FSA_API_VERSION_HEADER = 'x-api-version';
|
|
14
|
+
/** Version of the FSA API this adapter speaks. Version 1 no longer answers. */
|
|
15
|
+
export const FSA_API_VERSION = '2';
|
|
16
|
+
/** How many of the largest registers the summary keeps by default. */
|
|
17
|
+
export const DEFAULT_LARGEST_AUTHORITY_LIMIT = 10;
|
|
18
|
+
const FSA_AUTHORITY_SCHEMA = z.object({
|
|
19
|
+
LocalAuthorityId: z.number(),
|
|
20
|
+
LocalAuthorityIdCode: z.string(),
|
|
21
|
+
Name: z.string(),
|
|
22
|
+
EstablishmentCount: z.number(),
|
|
23
|
+
SchemeType: z.number(),
|
|
24
|
+
});
|
|
25
|
+
const FSA_AUTHORITIES_RESPONSE_SCHEMA = z.object({
|
|
26
|
+
authorities: z.array(FSA_AUTHORITY_SCHEMA),
|
|
27
|
+
});
|
|
28
|
+
/** Scheme codes the FSA API uses: 1 is FHRS, 2 is FHIS. */
|
|
29
|
+
const FSA_SCHEME_BY_TYPE = { 1: 'fhrs', 2: 'fhis' };
|
|
30
|
+
/** Maps the API's scheme code, naming the register when the code is new. */
|
|
31
|
+
function readFoodHygieneScheme(schemeType, localAuthorityName) {
|
|
32
|
+
const scheme = FSA_SCHEME_BY_TYPE[schemeType];
|
|
33
|
+
if (scheme === undefined) {
|
|
34
|
+
throw new UkSourceParseError('fsa-food-hygiene', `unknown scheme type ${schemeType} on ${localAuthorityName}`);
|
|
35
|
+
}
|
|
36
|
+
return scheme;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses an FSA /Authorities payload into registers.
|
|
40
|
+
*
|
|
41
|
+
* @param payload - the raw JSON body from the register endpoint
|
|
42
|
+
* @returns one flattened register per local authority
|
|
43
|
+
*/
|
|
44
|
+
export function parseFoodHygieneAuthorities(payload) {
|
|
45
|
+
const parsed = FSA_AUTHORITIES_RESPONSE_SCHEMA.safeParse(payload);
|
|
46
|
+
if (!parsed.success) {
|
|
47
|
+
throw new UkSourceParseError('fsa-food-hygiene', parsed.error.message);
|
|
48
|
+
}
|
|
49
|
+
return parsed.data.authorities.map((authority) => ({
|
|
50
|
+
localAuthorityId: authority.LocalAuthorityId,
|
|
51
|
+
localAuthorityCode: authority.LocalAuthorityIdCode,
|
|
52
|
+
localAuthorityName: authority.Name,
|
|
53
|
+
establishmentCount: authority.EstablishmentCount,
|
|
54
|
+
scheme: readFoodHygieneScheme(authority.SchemeType, authority.Name),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Totals the registers and keeps the largest ones.
|
|
59
|
+
*
|
|
60
|
+
* @param authorities - registers from {@link parseFoodHygieneAuthorities}
|
|
61
|
+
* @param largestAuthorityLimit - how many registers to keep in `largestAuthorities`
|
|
62
|
+
* @returns register, establishment, and scheme counts plus the largest registers
|
|
63
|
+
*/
|
|
64
|
+
export function summarizeFoodHygieneAuthorities(authorities, largestAuthorityLimit = DEFAULT_LARGEST_AUTHORITY_LIMIT) {
|
|
65
|
+
const largestAuthorities = [...authorities]
|
|
66
|
+
.sort((left, right) => right.establishmentCount - left.establishmentCount ||
|
|
67
|
+
left.localAuthorityName.localeCompare(right.localAuthorityName))
|
|
68
|
+
.slice(0, largestAuthorityLimit);
|
|
69
|
+
return {
|
|
70
|
+
authorityCount: authorities.length,
|
|
71
|
+
establishmentCount: authorities.reduce((total, authority) => total + authority.establishmentCount, 0),
|
|
72
|
+
fhrsAuthorityCount: authorities.filter((authority) => authority.scheme === 'fhrs').length,
|
|
73
|
+
fhisAuthorityCount: authorities.filter((authority) => authority.scheme === 'fhis').length,
|
|
74
|
+
largestAuthorities,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Lists every local authority food hygiene register from the FSA.
|
|
79
|
+
*
|
|
80
|
+
* @param options - an optional fetch implementation
|
|
81
|
+
* @returns the registers the endpoint returns
|
|
82
|
+
*/
|
|
83
|
+
export async function fetchFoodHygieneAuthorities(options = {}) {
|
|
84
|
+
const { fetchImpl = globalThis.fetch } = options;
|
|
85
|
+
const response = await fetchImpl(FSA_AUTHORITIES_URL, {
|
|
86
|
+
headers: { [FSA_API_VERSION_HEADER]: FSA_API_VERSION },
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new UkSourceApiError('fsa-food-hygiene', `HTTP ${response.status} listing registers`);
|
|
90
|
+
}
|
|
91
|
+
return parseFoodHygieneAuthorities(await response.json());
|
|
92
|
+
}
|
|
93
|
+
/** Food Standards Agency food hygiene register adapter, keyless. */
|
|
94
|
+
export const foodHygieneAuthoritiesAdapter = {
|
|
95
|
+
id: 'food-hygiene-authorities',
|
|
96
|
+
name: 'Food Standards Agency food hygiene registers',
|
|
97
|
+
auth: 'none',
|
|
98
|
+
description: 'Every local authority food hygiene register, with its establishment count.',
|
|
99
|
+
fetchLive: (options) => fetchFoodHygieneAuthorities(options?.fetchImpl === undefined ? {} : { fetchImpl: options.fetchImpl }),
|
|
100
|
+
parse: parseFoodHygieneAuthorities,
|
|
101
|
+
loadFixture: () => parseFoodHygieneAuthorities(readFixtureJson('food-hygiene-authorities.json')),
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=foodHygiene.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foodHygiene.js","sourceRoot":"","sources":["../src/foodHygiene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mDAAmD,CAAC;AAEvF,iEAAiE;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC;AAEtD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC,sEAAsE;AACtE,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AA+BlD,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC5B,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE;IAChC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,kBAAkB,EAAE,CAAC,CAAC,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AAE,QAAQ,QAAQ,CAAC,MAAM,oBAAoB,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,2BAA2B,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,6BAA6B,GAA0C;IAClF,EAAE,EAAE,0BAA0B;IAC9B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,4EAA4E;IACzF,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CACrB,2BAA2B,CACzB,OAAO,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CACzE;IACH,KAAK,EAAE,2BAA2B;IAClC,WAAW,EAAE,GAAG,EAAE,CAAC,2BAA2B,CAAC,eAAe,CAAC,+BAA+B,CAAC,CAAC;CACjG,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Natural England ancient woodland polygons for England (keyless). */
|
|
2
|
+
export { ANCIENT_WOODLAND_CATEGORIES, ANCIENT_WOODLAND_DATASET_URL, ANCIENT_WOODLAND_QUERY_URL, ANCIENT_WOODLAND_SIZE_BANDS, ANCIENT_WOODLAND_SOURCE_ID, ancientWoodlandAdapter, fetchAncientWoodlandProfile, parseAncientWoodlandProfile, } from './ancientWoodland.js';
|
|
3
|
+
/** Ancient woodland types. */
|
|
4
|
+
export type { AncientWoodlandCategory, AncientWoodlandCategoryId, AncientWoodlandProfile, AncientWoodlandResponses, AncientWoodlandSizeBand, AncientWoodlandSizeBandDefinition, } from './ancientWoodland.js';
|
|
5
|
+
/** Bank of England Bank Rate, the daily official rate since 1975 (keyless). */
|
|
6
|
+
export { bankRateAdapter, BANK_RATE_CSV_URL, BANK_RATE_FIRST_QUERY_DATE, BANK_RATE_SERIES_CODE, BANK_RATE_SOURCE_ID, buildBankRateCsvUrl, buildBankRateSpells, fetchBankRateObservations, formatBankRateQueryDate, parseBankRateCsv, summarizeBankRateSeries, } from './bankRate.js';
|
|
7
|
+
/** Bank Rate types. */
|
|
8
|
+
export type { BankRateObservation, BankRateSpell, BankRateSummary } from './bankRate.js';
|
|
9
|
+
/** National Energy System Operator half-hourly carbon intensity (keyless). */
|
|
10
|
+
export { buildCarbonIntensityWindowUrl, carbonIntensityAdapter, CARBON_INTENSITY_API_BASE_URL, CARBON_INTENSITY_INDEX_BANDS, CARBON_INTENSITY_MAX_WINDOW_DAYS, CARBON_INTENSITY_PERIOD_MINUTES, CARBON_INTENSITY_RANGE_URL, CARBON_INTENSITY_SOURCE_ID, DEFAULT_CARBON_INTENSITY_WINDOW_DAYS, fetchCarbonIntensityWindow, formatCarbonIntensityInstant, parseCarbonIntensityWindow, resolveCarbonIntensityWindow, } from './carbonIntensity.js';
|
|
11
|
+
/** Carbon intensity types. */
|
|
12
|
+
export type { CarbonIntensityBandCount, CarbonIntensityIndex, CarbonIntensityPeriod, CarbonIntensityWindow, } from './carbonIntensity.js';
|
|
13
|
+
/** Errors shared by every UK source adapter. */
|
|
14
|
+
export { UkSourceApiError, UkSourceError, UkSourceParseError } from './errors.js';
|
|
15
|
+
/** Environment Agency flood-monitoring stations and readings (keyless). */
|
|
16
|
+
export { DEFAULT_FLOOD_STATION_REFERENCE, fetchFloodStationReadings, fetchFloodStations, floodReadingsAdapter, floodStationsAdapter, parseFloodReadings, parseFloodStations, summarizeFloodReadings, } from './floodMonitoring.js';
|
|
17
|
+
/** Flood-monitoring types. */
|
|
18
|
+
export type { FloodMeasure, FloodReading, FloodReadingSummary, FloodStation, } from './floodMonitoring.js';
|
|
19
|
+
/** Food Standards Agency food hygiene registers (keyless). */
|
|
20
|
+
export { DEFAULT_LARGEST_AUTHORITY_LIMIT, fetchFoodHygieneAuthorities, foodHygieneAuthoritiesAdapter, FSA_API_VERSION, FSA_API_VERSION_HEADER, FSA_AUTHORITIES_URL, parseFoodHygieneAuthorities, summarizeFoodHygieneAuthorities, } from './foodHygiene.js';
|
|
21
|
+
/** Food hygiene register types. */
|
|
22
|
+
export type { FoodHygieneAuthority, FoodHygieneScheme, FoodHygieneSummary } from './foodHygiene.js';
|
|
23
|
+
/** Office for National Statistics dataset catalogue (keyless). */
|
|
24
|
+
export { fetchOnsDatasets, onsDatasetsAdapter, ONS_DATASETS_LIMIT, ONS_DATASETS_URL, parseOnsDatasets, summarizeOnsDatasets, } from './onsDatasets.js';
|
|
25
|
+
/** ONS catalogue types. */
|
|
26
|
+
export type { OnsDatasetRecord, OnsDatasetSummary, OnsDatasetYearCount } from './onsDatasets.js';
|
|
27
|
+
/** UK Parliament state of the parties in the Commons and the Lords (keyless). */
|
|
28
|
+
export { buildParliamentSeatsUrl, fetchParliamentSeats, formatParliamentQueryDate, parliamentSeatsAdapter, parseParliamentPartySeats, parseParliamentSeats, PARLIAMENT_COMMONS_HOUSE, PARLIAMENT_LORDS_HOUSE, PARLIAMENT_MEMBERS_API_BASE_URL, PARLIAMENT_SEATS_SOURCE_ID, PARLIAMENT_STATE_OF_PARTIES_PATH, summarizeParliamentPartySeats, } from './parliamentSeats.js';
|
|
29
|
+
/** Parliament seat types. */
|
|
30
|
+
export type { ParliamentHouse, ParliamentParty, ParliamentPartySeats, ParliamentSeatSummary, } from './parliamentSeats.js';
|
|
31
|
+
/** Planning Data platform dataset catalogue, published by MHCLG (keyless). */
|
|
32
|
+
export { DEFAULT_LARGEST_DATASET_LIMIT, fetchPlanningDatasets, parsePlanningDatasets, planningDatasetsAdapter, PLANNING_DATASET_REALM, PLANNING_DATASETS_URL, summarizePlanningDatasets, } from './planningDatasets.js';
|
|
33
|
+
/** Planning dataset types. */
|
|
34
|
+
export type { PlanningDataset, PlanningDatasetSummary } from './planningDatasets.js';
|
|
35
|
+
/** Home Office police.uk street-level recorded crime (keyless). */
|
|
36
|
+
export { buildPoliceStreetCrimesUrl, DEFAULT_POLICE_CRIME_LOCATION, DEFAULT_POLICE_CRIME_MONTH_COUNT, fetchPoliceCrimeCategories, fetchPoliceCrimeMonths, fetchPoliceCrimeSummary, parsePoliceCrimeSummary, policeCrimesAdapter, POLICE_API_BASE_URL, POLICE_CRIME_CATEGORIES_URL, POLICE_CRIMES_SOURCE_ID, POLICE_STREET_CRIMES_RADIUS_MILES, POLICE_STREET_CRIMES_URL, POLICE_STREET_DATES_URL, } from './policeCrimes.js';
|
|
37
|
+
/** Recorded crime types. */
|
|
38
|
+
export type { PoliceCategoryCount, PoliceCrimeCategory, PoliceCrimeLocation, PoliceCrimeResponses, PoliceCrimeSummary, PoliceMonthCount, PoliceOutcomeCount, } from './policeCrimes.js';
|
|
39
|
+
/** Transport for London Santander Cycles docking stations (keyless). */
|
|
40
|
+
export { DEFAULT_LARGEST_STATION_LIMIT, fetchTflBikePoints, parseTflBikePoints, summarizeTflBikePoints, tflBikePointsAdapter, TFL_BIKE_POINTS_URL, } from './tflBikePoints.js';
|
|
41
|
+
/** Docking station types. */
|
|
42
|
+
export type { DockingStation, DockingStationSummary } from './tflBikePoints.js';
|
|
43
|
+
/** The uniform adapter registry and probe helpers. */
|
|
44
|
+
export { UK_DATA_SOURCES, getUkDataSource, probeAllUkDataSources, probeUkDataSource, } from './registry.js';
|
|
45
|
+
/** Shared adapter contract types. */
|
|
46
|
+
export type { UkDataAdapter, UkFetchOptions, UkSourceAuth, UkSourceProbe } from './types.js';
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,8BAA8B;AAC9B,YAAY,EACV,uBAAuB,EAC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3B,4BAA4B;AAC5B,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,wEAAwE;AACxE,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,6BAA6B;AAC7B,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,sDAAsD;AACtD,OAAO,EACL,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,qCAAqC;AACrC,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Natural England ancient woodland polygons for England (keyless). */
|
|
2
|
+
export { ANCIENT_WOODLAND_CATEGORIES, ANCIENT_WOODLAND_DATASET_URL, ANCIENT_WOODLAND_QUERY_URL, ANCIENT_WOODLAND_SIZE_BANDS, ANCIENT_WOODLAND_SOURCE_ID, ancientWoodlandAdapter, fetchAncientWoodlandProfile, parseAncientWoodlandProfile, } from './ancientWoodland.js';
|
|
3
|
+
/** Bank of England Bank Rate, the daily official rate since 1975 (keyless). */
|
|
4
|
+
export { bankRateAdapter, BANK_RATE_CSV_URL, BANK_RATE_FIRST_QUERY_DATE, BANK_RATE_SERIES_CODE, BANK_RATE_SOURCE_ID, buildBankRateCsvUrl, buildBankRateSpells, fetchBankRateObservations, formatBankRateQueryDate, parseBankRateCsv, summarizeBankRateSeries, } from './bankRate.js';
|
|
5
|
+
/** National Energy System Operator half-hourly carbon intensity (keyless). */
|
|
6
|
+
export { buildCarbonIntensityWindowUrl, carbonIntensityAdapter, CARBON_INTENSITY_API_BASE_URL, CARBON_INTENSITY_INDEX_BANDS, CARBON_INTENSITY_MAX_WINDOW_DAYS, CARBON_INTENSITY_PERIOD_MINUTES, CARBON_INTENSITY_RANGE_URL, CARBON_INTENSITY_SOURCE_ID, DEFAULT_CARBON_INTENSITY_WINDOW_DAYS, fetchCarbonIntensityWindow, formatCarbonIntensityInstant, parseCarbonIntensityWindow, resolveCarbonIntensityWindow, } from './carbonIntensity.js';
|
|
7
|
+
/** Errors shared by every UK source adapter. */
|
|
8
|
+
export { UkSourceApiError, UkSourceError, UkSourceParseError } from './errors.js';
|
|
9
|
+
/** Environment Agency flood-monitoring stations and readings (keyless). */
|
|
10
|
+
export { DEFAULT_FLOOD_STATION_REFERENCE, fetchFloodStationReadings, fetchFloodStations, floodReadingsAdapter, floodStationsAdapter, parseFloodReadings, parseFloodStations, summarizeFloodReadings, } from './floodMonitoring.js';
|
|
11
|
+
/** Food Standards Agency food hygiene registers (keyless). */
|
|
12
|
+
export { DEFAULT_LARGEST_AUTHORITY_LIMIT, fetchFoodHygieneAuthorities, foodHygieneAuthoritiesAdapter, FSA_API_VERSION, FSA_API_VERSION_HEADER, FSA_AUTHORITIES_URL, parseFoodHygieneAuthorities, summarizeFoodHygieneAuthorities, } from './foodHygiene.js';
|
|
13
|
+
/** Office for National Statistics dataset catalogue (keyless). */
|
|
14
|
+
export { fetchOnsDatasets, onsDatasetsAdapter, ONS_DATASETS_LIMIT, ONS_DATASETS_URL, parseOnsDatasets, summarizeOnsDatasets, } from './onsDatasets.js';
|
|
15
|
+
/** UK Parliament state of the parties in the Commons and the Lords (keyless). */
|
|
16
|
+
export { buildParliamentSeatsUrl, fetchParliamentSeats, formatParliamentQueryDate, parliamentSeatsAdapter, parseParliamentPartySeats, parseParliamentSeats, PARLIAMENT_COMMONS_HOUSE, PARLIAMENT_LORDS_HOUSE, PARLIAMENT_MEMBERS_API_BASE_URL, PARLIAMENT_SEATS_SOURCE_ID, PARLIAMENT_STATE_OF_PARTIES_PATH, summarizeParliamentPartySeats, } from './parliamentSeats.js';
|
|
17
|
+
/** Planning Data platform dataset catalogue, published by MHCLG (keyless). */
|
|
18
|
+
export { DEFAULT_LARGEST_DATASET_LIMIT, fetchPlanningDatasets, parsePlanningDatasets, planningDatasetsAdapter, PLANNING_DATASET_REALM, PLANNING_DATASETS_URL, summarizePlanningDatasets, } from './planningDatasets.js';
|
|
19
|
+
/** Home Office police.uk street-level recorded crime (keyless). */
|
|
20
|
+
export { buildPoliceStreetCrimesUrl, DEFAULT_POLICE_CRIME_LOCATION, DEFAULT_POLICE_CRIME_MONTH_COUNT, fetchPoliceCrimeCategories, fetchPoliceCrimeMonths, fetchPoliceCrimeSummary, parsePoliceCrimeSummary, policeCrimesAdapter, POLICE_API_BASE_URL, POLICE_CRIME_CATEGORIES_URL, POLICE_CRIMES_SOURCE_ID, POLICE_STREET_CRIMES_RADIUS_MILES, POLICE_STREET_CRIMES_URL, POLICE_STREET_DATES_URL, } from './policeCrimes.js';
|
|
21
|
+
/** Transport for London Santander Cycles docking stations (keyless). */
|
|
22
|
+
export { DEFAULT_LARGEST_STATION_LIMIT, fetchTflBikePoints, parseTflBikePoints, summarizeTflBikePoints, tflBikePointsAdapter, TFL_BIKE_POINTS_URL, } from './tflBikePoints.js';
|
|
23
|
+
/** The uniform adapter registry and probe helpers. */
|
|
24
|
+
export { UK_DATA_SOURCES, getUkDataSource, probeAllUkDataSources, probeUkDataSource, } from './registry.js';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAU9B,+EAA+E;AAC/E,OAAO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,CAAC;AAQ9B,8EAA8E;AAC9E,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAG/B,mEAAmE;AACnE,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,gCAAgC,EAChC,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,EACvB,iCAAiC,EACjC,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAW3B,wEAAwE;AACxE,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAG5B,sDAAsD;AACtD,OAAO,EACL,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { UkDataAdapter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The ONS beta API dataset catalogue. Keyless, published by the Office for
|
|
4
|
+
* National Statistics under the Open Government Licence v3.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ONS_DATASETS_URL = "https://api.beta.ons.gov.uk/v1/datasets?limit=1000";
|
|
7
|
+
/**
|
|
8
|
+
* How many records the catalogue call asks for. The endpoint answers with its
|
|
9
|
+
* whole catalogue well below this, so the limit is a ceiling, not a page size.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ONS_DATASETS_LIMIT = 1000;
|
|
12
|
+
/** One dataset record as the ONS beta API lists it in the catalogue. */
|
|
13
|
+
export interface OnsDatasetRecord {
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
/** Publication state the API reports, such as "published". */
|
|
17
|
+
state: string;
|
|
18
|
+
/** The API's own last-updated stamp for this record, ISO 8601. */
|
|
19
|
+
lastUpdatedIso: string;
|
|
20
|
+
/** The national-statistic flag, or null when the record leaves it out. */
|
|
21
|
+
isNationalStatistic: boolean | null;
|
|
22
|
+
keywords: string[];
|
|
23
|
+
/** Topic path from the record's taxonomy link, or "" when it has none. */
|
|
24
|
+
topicPath: string;
|
|
25
|
+
}
|
|
26
|
+
/** Catalogue records counted by the year in their last-updated stamp. */
|
|
27
|
+
export interface OnsDatasetYearCount {
|
|
28
|
+
/** Calendar year taken from the stamp, as a four digit string. */
|
|
29
|
+
year: string;
|
|
30
|
+
datasetCount: number;
|
|
31
|
+
}
|
|
32
|
+
/** Rolled-up counts across the ONS dataset catalogue. */
|
|
33
|
+
export interface OnsDatasetSummary {
|
|
34
|
+
datasetCount: number;
|
|
35
|
+
nationalStatisticCount: number;
|
|
36
|
+
/** Records that carry no national-statistic flag at all. */
|
|
37
|
+
unflaggedCount: number;
|
|
38
|
+
/** Records per last-updated year, oldest year first. */
|
|
39
|
+
yearCounts: OnsDatasetYearCount[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses an ONS beta API /datasets payload into catalogue records.
|
|
43
|
+
*
|
|
44
|
+
* @param payload - the raw JSON body from the catalogue endpoint
|
|
45
|
+
* @returns one flattened record per dataset
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseOnsDatasets(payload: unknown): OnsDatasetRecord[];
|
|
48
|
+
/**
|
|
49
|
+
* Counts the catalogue by national-statistic flag and by last-updated year.
|
|
50
|
+
*
|
|
51
|
+
* @param records - dataset records from {@link parseOnsDatasets}
|
|
52
|
+
* @returns dataset, flag, and per-year counts
|
|
53
|
+
*/
|
|
54
|
+
export declare function summarizeOnsDatasets(records: OnsDatasetRecord[]): OnsDatasetSummary;
|
|
55
|
+
/**
|
|
56
|
+
* Lists datasets from the ONS beta API catalogue.
|
|
57
|
+
*
|
|
58
|
+
* @param options - record limit and an optional fetch implementation
|
|
59
|
+
* @returns the catalogue records the endpoint returns
|
|
60
|
+
*/
|
|
61
|
+
export declare function fetchOnsDatasets(options?: {
|
|
62
|
+
limit?: number;
|
|
63
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
64
|
+
}): Promise<OnsDatasetRecord[]>;
|
|
65
|
+
/** ONS beta API dataset catalogue adapter, keyless. */
|
|
66
|
+
export declare const onsDatasetsAdapter: UkDataAdapter<OnsDatasetRecord[]>;
|
|
67
|
+
//# sourceMappingURL=onsDatasets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onsDatasets.d.ts","sourceRoot":"","sources":["../src/onsDatasets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,uDAAuD,CAAC;AAErF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,cAAc,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,yEAAyE;AACzE,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,yDAAyD;AACzD,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,UAAU,EAAE,mBAAmB,EAAE,CAAC;CACnC;AA0BD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAcrE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,iBAAiB,CA0BnF;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAAO,GACpE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAO7B;AAED,uDAAuD;AACvD,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAShE,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { UkSourceApiError, UkSourceParseError } from './errors.js';
|
|
3
|
+
import { readFixtureJson } from './fixtures.js';
|
|
4
|
+
/**
|
|
5
|
+
* The ONS beta API dataset catalogue. Keyless, published by the Office for
|
|
6
|
+
* National Statistics under the Open Government Licence v3.
|
|
7
|
+
*/
|
|
8
|
+
export const ONS_DATASETS_URL = 'https://api.beta.ons.gov.uk/v1/datasets?limit=1000';
|
|
9
|
+
/**
|
|
10
|
+
* How many records the catalogue call asks for. The endpoint answers with its
|
|
11
|
+
* whole catalogue well below this, so the limit is a ceiling, not a page size.
|
|
12
|
+
*/
|
|
13
|
+
export const ONS_DATASETS_LIMIT = 1000;
|
|
14
|
+
const ONS_DATASET_SCHEMA = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
title: z.string(),
|
|
17
|
+
state: z.string(),
|
|
18
|
+
last_updated: z.string(),
|
|
19
|
+
national_statistic: z.boolean().optional(),
|
|
20
|
+
keywords: z.array(z.string()).optional(),
|
|
21
|
+
links: z.object({ taxonomy: z.object({ href: z.string() }).optional() }).optional(),
|
|
22
|
+
});
|
|
23
|
+
const ONS_DATASETS_RESPONSE_SCHEMA = z.object({
|
|
24
|
+
items: z.array(ONS_DATASET_SCHEMA),
|
|
25
|
+
});
|
|
26
|
+
const ONS_TAXONOMY_PREFIX = 'https://api.beta.ons.gov.uk/v1/';
|
|
27
|
+
/** Strips the API prefix from a taxonomy link so the topic path is readable. */
|
|
28
|
+
function readTopicPath(href) {
|
|
29
|
+
if (href === undefined) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
return href.startsWith(ONS_TAXONOMY_PREFIX) ? href.slice(ONS_TAXONOMY_PREFIX.length) : href;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses an ONS beta API /datasets payload into catalogue records.
|
|
36
|
+
*
|
|
37
|
+
* @param payload - the raw JSON body from the catalogue endpoint
|
|
38
|
+
* @returns one flattened record per dataset
|
|
39
|
+
*/
|
|
40
|
+
export function parseOnsDatasets(payload) {
|
|
41
|
+
const parsed = ONS_DATASETS_RESPONSE_SCHEMA.safeParse(payload);
|
|
42
|
+
if (!parsed.success) {
|
|
43
|
+
throw new UkSourceParseError('ons-datasets', parsed.error.message);
|
|
44
|
+
}
|
|
45
|
+
return parsed.data.items.map((item) => ({
|
|
46
|
+
id: item.id,
|
|
47
|
+
title: item.title,
|
|
48
|
+
state: item.state,
|
|
49
|
+
lastUpdatedIso: item.last_updated,
|
|
50
|
+
isNationalStatistic: item.national_statistic ?? null,
|
|
51
|
+
keywords: item.keywords ?? [],
|
|
52
|
+
topicPath: readTopicPath(item.links?.taxonomy?.href),
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Counts the catalogue by national-statistic flag and by last-updated year.
|
|
57
|
+
*
|
|
58
|
+
* @param records - dataset records from {@link parseOnsDatasets}
|
|
59
|
+
* @returns dataset, flag, and per-year counts
|
|
60
|
+
*/
|
|
61
|
+
export function summarizeOnsDatasets(records) {
|
|
62
|
+
const countByYear = new Map();
|
|
63
|
+
let nationalStatisticCount = 0;
|
|
64
|
+
let unflaggedCount = 0;
|
|
65
|
+
for (const record of records) {
|
|
66
|
+
if (record.isNationalStatistic === true) {
|
|
67
|
+
nationalStatisticCount += 1;
|
|
68
|
+
}
|
|
69
|
+
else if (record.isNationalStatistic === null) {
|
|
70
|
+
unflaggedCount += 1;
|
|
71
|
+
}
|
|
72
|
+
const year = record.lastUpdatedIso.slice(0, 4);
|
|
73
|
+
if (year !== '') {
|
|
74
|
+
countByYear.set(year, (countByYear.get(year) ?? 0) + 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const yearCounts = [...countByYear.entries()]
|
|
78
|
+
.map(([year, datasetCount]) => ({ year, datasetCount }))
|
|
79
|
+
.sort((left, right) => left.year.localeCompare(right.year));
|
|
80
|
+
return {
|
|
81
|
+
datasetCount: records.length,
|
|
82
|
+
nationalStatisticCount,
|
|
83
|
+
unflaggedCount,
|
|
84
|
+
yearCounts,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Lists datasets from the ONS beta API catalogue.
|
|
89
|
+
*
|
|
90
|
+
* @param options - record limit and an optional fetch implementation
|
|
91
|
+
* @returns the catalogue records the endpoint returns
|
|
92
|
+
*/
|
|
93
|
+
export async function fetchOnsDatasets(options = {}) {
|
|
94
|
+
const { limit = ONS_DATASETS_LIMIT, fetchImpl = globalThis.fetch } = options;
|
|
95
|
+
const response = await fetchImpl(`https://api.beta.ons.gov.uk/v1/datasets?limit=${limit}`);
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
throw new UkSourceApiError('ons-datasets', `HTTP ${response.status} listing datasets`);
|
|
98
|
+
}
|
|
99
|
+
return parseOnsDatasets(await response.json());
|
|
100
|
+
}
|
|
101
|
+
/** ONS beta API dataset catalogue adapter, keyless. */
|
|
102
|
+
export const onsDatasetsAdapter = {
|
|
103
|
+
id: 'ons-datasets',
|
|
104
|
+
name: 'Office for National Statistics dataset catalogue',
|
|
105
|
+
auth: 'none',
|
|
106
|
+
description: 'Every dataset the ONS beta API lists, with its state and last-updated stamp.',
|
|
107
|
+
fetchLive: (options) => fetchOnsDatasets(options?.fetchImpl === undefined ? {} : { fetchImpl: options.fetchImpl }),
|
|
108
|
+
parse: parseOnsDatasets,
|
|
109
|
+
loadFixture: () => parseOnsDatasets(readFixtureJson('ons-datasets.json')),
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=onsDatasets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onsDatasets.js","sourceRoot":"","sources":["../src/onsDatasets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,oDAAoD,CAAC;AAErF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAkCvC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,kBAAkB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC1C,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,EAA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,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC;IAC7E,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,iDAAiD,KAAK,EAAE,CAAC,CAAC;IAC3F,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,gBAAgB,CAAC,cAAc,EAAE,QAAQ,QAAQ,CAAC,MAAM,mBAAmB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,kBAAkB,GAAsC;IACnE,EAAE,EAAE,cAAc;IAClB,IAAI,EAAE,kDAAkD;IACxD,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,8EAA8E;IAC3F,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CACrB,gBAAgB,CAAC,OAAO,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;IAC5F,KAAK,EAAE,gBAAgB;IACvB,WAAW,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;CAC1E,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { UkDataAdapter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The state of the parties in each house of the UK Parliament, from the
|
|
4
|
+
* Members API. The API answers without a key and Parliament publishes the
|
|
5
|
+
* data under the Open Parliament Licence v3.0:
|
|
6
|
+
* <https://www.parliament.uk/site-information/copyright-parliament/open-parliament-licence/>
|
|
7
|
+
*/
|
|
8
|
+
export declare const PARLIAMENT_SEATS_SOURCE_ID = "parliament-seats";
|
|
9
|
+
/** Root every call here is built from. */
|
|
10
|
+
export declare const PARLIAMENT_MEMBERS_API_BASE_URL = "https://members-api.parliament.uk/api";
|
|
11
|
+
/** Path for the state of the parties in one house on one date. */
|
|
12
|
+
export declare const PARLIAMENT_STATE_OF_PARTIES_PATH = "Parties/StateOfTheParties";
|
|
13
|
+
/**
|
|
14
|
+
* The house number the API uses for the Commons. The Swagger schema behind
|
|
15
|
+
* `House` carries exactly two values: 1 for the Commons, 2 for the Lords.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PARLIAMENT_COMMONS_HOUSE = 1;
|
|
18
|
+
/** The house number the API uses for the Lords. */
|
|
19
|
+
export declare const PARLIAMENT_LORDS_HOUSE = 2;
|
|
20
|
+
/** Which house a seat count belongs to. */
|
|
21
|
+
export type ParliamentHouse = 'commons' | 'lords';
|
|
22
|
+
/** One party as the Members API lists it, with the colours it publishes. */
|
|
23
|
+
export interface ParliamentParty {
|
|
24
|
+
id: number;
|
|
25
|
+
name: string;
|
|
26
|
+
abbreviation: string;
|
|
27
|
+
/** Hex without the leading '#'. Null for the Speaker and a few others. */
|
|
28
|
+
backgroundColour: string | null;
|
|
29
|
+
/** Hex without the leading '#'. Null for the Speaker and a few others. */
|
|
30
|
+
foregroundColour: string | null;
|
|
31
|
+
isIndependent: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** One party's seats, with the member counts the API reports behind them. */
|
|
34
|
+
export interface ParliamentPartySeats {
|
|
35
|
+
party: ParliamentParty;
|
|
36
|
+
seatCount: number;
|
|
37
|
+
maleCount: number;
|
|
38
|
+
femaleCount: number;
|
|
39
|
+
nonBinaryCount: number;
|
|
40
|
+
/**
|
|
41
|
+
* Seats the API counts for the party but name no member. That is the vacant
|
|
42
|
+
* seat, and it is zero for every other row.
|
|
43
|
+
*/
|
|
44
|
+
unallocatedSeatCount: number;
|
|
45
|
+
}
|
|
46
|
+
/** The state of the parties on one date, rolled up into the numbers a page prints. */
|
|
47
|
+
export interface ParliamentSeatSummary {
|
|
48
|
+
/** Seats the house holds: 650 in the Commons while every seat is filled. */
|
|
49
|
+
seatCount: number;
|
|
50
|
+
partyCount: number;
|
|
51
|
+
/** Seats a party needs to hold more than half the house: 326 of 650. */
|
|
52
|
+
majorityThreshold: number;
|
|
53
|
+
partiesWithOneSeat: number;
|
|
54
|
+
/** Parties, largest first, ties broken by name. */
|
|
55
|
+
seats: ParliamentPartySeats[];
|
|
56
|
+
largestParty: ParliamentPartySeats;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Formats a date as the `YYYY-MM-DD` the path takes, in UK local time.
|
|
60
|
+
*
|
|
61
|
+
* @param date - the instant to format
|
|
62
|
+
* @returns the date the API reads, for example `2026-10-01`
|
|
63
|
+
*/
|
|
64
|
+
export declare function formatParliamentQueryDate(date: Date): string;
|
|
65
|
+
/**
|
|
66
|
+
* Builds the state-of-the-parties URL for one house and one date.
|
|
67
|
+
*
|
|
68
|
+
* @param house - 1 for the Commons, 2 for the Lords
|
|
69
|
+
* @param forDate - the date to ask for, as `YYYY-MM-DD`
|
|
70
|
+
* @returns the full URL
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildParliamentSeatsUrl(house: number, forDate: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Parses a state-of-the-parties payload into the seats each party holds.
|
|
75
|
+
*
|
|
76
|
+
* A row the API cannot explain fails the parse rather than quietly shifting
|
|
77
|
+
* the totals: a missing party, a blank name, a party with no seats, or the
|
|
78
|
+
* same party listed twice all throw.
|
|
79
|
+
*
|
|
80
|
+
* @param payload - the API response, or the committed fixture of one
|
|
81
|
+
* @returns one entry per party, in the order the API sent them
|
|
82
|
+
*/
|
|
83
|
+
export declare function parseParliamentPartySeats(payload: unknown): ParliamentPartySeats[];
|
|
84
|
+
/**
|
|
85
|
+
* Rolls a party list into the totals a page prints.
|
|
86
|
+
*
|
|
87
|
+
* @param seats - parties as parsed from the payload
|
|
88
|
+
* @returns the seat total, the party count, the majority line, and the ranking
|
|
89
|
+
*/
|
|
90
|
+
export declare function summarizeParliamentPartySeats(seats: ParliamentPartySeats[]): ParliamentSeatSummary;
|
|
91
|
+
/**
|
|
92
|
+
* Parses a state-of-the-parties payload straight into the summary a page prints.
|
|
93
|
+
*
|
|
94
|
+
* @param payload - the API response, or the committed fixture of one
|
|
95
|
+
* @returns the seat total, the party count, the majority line, and the ranking
|
|
96
|
+
*/
|
|
97
|
+
export declare function parseParliamentSeats(payload: unknown): ParliamentSeatSummary;
|
|
98
|
+
/**
|
|
99
|
+
* Reads the state of the parties in one house, the Commons by default.
|
|
100
|
+
*
|
|
101
|
+
* The API needs a date as well as a house and answers with the composition on
|
|
102
|
+
* that date, so the caller's own date is the one asked for.
|
|
103
|
+
*
|
|
104
|
+
* @param options - the house, the date, and an optional fetch implementation
|
|
105
|
+
* @returns the seat total, the party count, the majority line, and the ranking
|
|
106
|
+
*/
|
|
107
|
+
export declare function fetchParliamentSeats(options?: {
|
|
108
|
+
house?: number;
|
|
109
|
+
forDate?: string;
|
|
110
|
+
now?: Date;
|
|
111
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
112
|
+
}): Promise<ParliamentSeatSummary>;
|
|
113
|
+
/** UK Parliament state of the parties, keyless. */
|
|
114
|
+
export declare const parliamentSeatsAdapter: UkDataAdapter<ParliamentSeatSummary>;
|
|
115
|
+
//# sourceMappingURL=parliamentSeats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parliamentSeats.d.ts","sourceRoot":"","sources":["../src/parliamentSeats.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAE7D,0CAA0C;AAC1C,eAAO,MAAM,+BAA+B,0CAA0C,CAAC;AAEvF,kEAAkE;AAClE,eAAO,MAAM,gCAAgC,8BAA8B,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,mDAAmD;AACnD,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,2CAA2C;AA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