bcchapi 2.1.0 → 2.2.1
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/CHANGELOG.md +29 -0
- package/README.md +87 -25
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/transform.d.ts +19 -0
- package/dist/utils/transform.d.ts.map +1 -1
- package/dist/utils/transform.js +34 -0
- package/dist/utils/transform.js.map +1 -1
- package/package.json +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,33 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [2.2.1] - 2026-03-10
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Add npm keywords for discoverability
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
## [2.2.0] - 2026-03-10
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Add fillForward utility
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- Release v2.2.0
|
|
29
|
+
- Always run format before check in dev workflow
|
|
30
|
+
- Fix formatting
|
|
31
|
+
- Add check script and move release docs to CONTRIBUTING.md
|
|
32
|
+
- Update README for v2.1.0 caching and fix AGENTS.md checklists
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
---
|
|
9
36
|
## [2.1.0] - 2026-03-10
|
|
10
37
|
|
|
11
38
|
|
|
@@ -16,6 +43,8 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
|
16
43
|
|
|
17
44
|
### Changed
|
|
18
45
|
|
|
46
|
+
- Bump version to 2.1.0
|
|
47
|
+
- Release v2.1.0
|
|
19
48
|
- Fix formatting
|
|
20
49
|
|
|
21
50
|
|
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ console.log(data.observations); // [{ indexDateString, value, statusCode }, ...]
|
|
|
38
38
|
### Transform observations
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
|
-
import { toNumbers, toArrays, filterValid, mean, rollingMean } from 'bcchapi/utils';
|
|
41
|
+
import { toNumbers, toArrays, filterValid, fillForward, mean, rollingMean } from 'bcchapi/utils';
|
|
42
42
|
|
|
43
43
|
// Parse values to number | null (null for gaps)
|
|
44
44
|
const values = toNumbers(data.observations); // [37000.12, null, 37050.45, ...]
|
|
@@ -49,6 +49,11 @@ const { dates, values } = toArrays(data.observations);
|
|
|
49
49
|
// Filter out gap observations
|
|
50
50
|
const valid = filterValid(data.observations);
|
|
51
51
|
|
|
52
|
+
// Fill gaps by carrying the last valid value forward (e.g. weekends, holidays)
|
|
53
|
+
// Throws if the first observation has no valid value — ensure the start date
|
|
54
|
+
// falls on a trading day.
|
|
55
|
+
const filled = fillForward(data.observations);
|
|
56
|
+
|
|
52
57
|
// Summary statistics (gaps are ignored)
|
|
53
58
|
const avg = mean(data.observations);
|
|
54
59
|
|
|
@@ -75,6 +80,39 @@ const monthlySeries = await client.searchSeries('MONTHLY');
|
|
|
75
80
|
console.log(monthlySeries.map((s) => s.englishTitle));
|
|
76
81
|
```
|
|
77
82
|
|
|
83
|
+
### Enable caching
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Client } from 'bcchapi/client';
|
|
87
|
+
import { MemoryCache } from 'bcchapi/cache';
|
|
88
|
+
|
|
89
|
+
const client = new Client({
|
|
90
|
+
user: 'me@example.com',
|
|
91
|
+
pass: 'secret',
|
|
92
|
+
cache: new MemoryCache({ defaultTtlMs: 60 * 60 * 1000 }), // 1 hour
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Repeated calls with the same arguments hit the cache — no HTTP request
|
|
96
|
+
const data = await client.getSeries(SERIES.PRICES.UF);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Bring your own backend by implementing the `Cache` interface:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import type { Cache } from 'bcchapi/cache';
|
|
103
|
+
|
|
104
|
+
const redisCache: Cache = {
|
|
105
|
+
get: (key) => {
|
|
106
|
+
/* ... */
|
|
107
|
+
},
|
|
108
|
+
set: (key, value, ttlMs) => {
|
|
109
|
+
/* ... */
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const client = new Client({ user, pass, cache: redisCache });
|
|
114
|
+
```
|
|
115
|
+
|
|
78
116
|
### Error handling
|
|
79
117
|
|
|
80
118
|
```ts
|
|
@@ -102,11 +140,13 @@ try {
|
|
|
102
140
|
|
|
103
141
|
#### `new Client(options)`
|
|
104
142
|
|
|
105
|
-
| Option
|
|
106
|
-
|
|
|
107
|
-
| `user`
|
|
108
|
-
| `pass`
|
|
109
|
-
| `fetch`
|
|
143
|
+
| Option | Type | Description |
|
|
144
|
+
| ------------ | -------------- | --------------------------------------------------------------------------------- |
|
|
145
|
+
| `user` | `string` | BCCH account email |
|
|
146
|
+
| `pass` | `string` | BCCH account password |
|
|
147
|
+
| `fetch` | `typeof fetch` | Custom fetch implementation (optional, useful for testing) |
|
|
148
|
+
| `cache` | `Cache` | Cache backend (optional) — any object satisfying the `Cache` interface |
|
|
149
|
+
| `cacheTtlMs` | `number` | TTL in milliseconds passed to `cache.set` on every successful response (optional) |
|
|
110
150
|
|
|
111
151
|
#### `client.getSeries(seriesId, options?)`
|
|
112
152
|
|
|
@@ -126,6 +166,27 @@ Returns metadata for all series with the given frequency. `frequency` is one of
|
|
|
126
166
|
|
|
127
167
|
Returns `Promise<SeriesInfo[]>`.
|
|
128
168
|
|
|
169
|
+
### `bcchapi/cache`
|
|
170
|
+
|
|
171
|
+
#### `Cache` interface
|
|
172
|
+
|
|
173
|
+
Minimal interface for plugging in any cache backend:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
interface Cache {
|
|
177
|
+
get(key: string): unknown;
|
|
178
|
+
set(key: string, value: unknown, ttlMs?: number): void;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### `new MemoryCache(options?)`
|
|
183
|
+
|
|
184
|
+
Built-in in-memory cache. Entries are evicted lazily on `get` — no background timers.
|
|
185
|
+
|
|
186
|
+
| Option | Type | Description |
|
|
187
|
+
| -------------- | -------- | ---------------------------------------------------------------- |
|
|
188
|
+
| `defaultTtlMs` | `number` | Default TTL in milliseconds. Omit for entries that never expire. |
|
|
189
|
+
|
|
129
190
|
### `bcchapi/series`
|
|
130
191
|
|
|
131
192
|
`SERIES` is a nested `as const` object of curated series IDs grouped by domain:
|
|
@@ -148,15 +209,16 @@ Use [si3.bcentral.cl](https://si3.bcentral.cl/siete) or `client.searchSeries()`
|
|
|
148
209
|
|
|
149
210
|
#### Transform functions
|
|
150
211
|
|
|
151
|
-
| Function | Description
|
|
152
|
-
| ---------------------------------- |
|
|
153
|
-
| `parseValue(value)` | Parses a value string to `number \| null` (`null` for empty or non-numeric)
|
|
154
|
-
| `filterValid(observations)` | Returns only observations with parseable numeric values
|
|
155
|
-
| `toNumbers(observations)` | Maps observations to `Array<number \| null>`
|
|
156
|
-
| `toMap(observations)` | Returns a `Map<string, number \| null>` keyed by `indexDateString`
|
|
157
|
-
| `toArrays(observations)` | Returns `{ dates: Date[], values: Array<number \| null> }`
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
212
|
+
| Function | Description |
|
|
213
|
+
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
214
|
+
| `parseValue(value)` | Parses a value string to `number \| null` (`null` for empty or non-numeric) |
|
|
215
|
+
| `filterValid(observations)` | Returns only observations with parseable numeric values |
|
|
216
|
+
| `toNumbers(observations)` | Maps observations to `Array<number \| null>` |
|
|
217
|
+
| `toMap(observations)` | Returns a `Map<string, number \| null>` keyed by `indexDateString` |
|
|
218
|
+
| `toArrays(observations)` | Returns `{ dates: Date[], values: Array<number \| null> }` |
|
|
219
|
+
| `fillForward(observations)` | Fills gap observations by carrying the last valid value forward. Throws if the first observation has no valid value. |
|
|
220
|
+
| `parseObservationDate(dateString)` | Parses `"DD-MM-YYYY"` to a UTC `Date` |
|
|
221
|
+
| `formatQueryDate(date)` | Formats a `Date` to `"YYYY-MM-DD"` for use in `getSeries` options |
|
|
160
222
|
|
|
161
223
|
#### Statistics functions
|
|
162
224
|
|
|
@@ -172,19 +234,19 @@ All stats functions operate on `Observation[]` and ignore gap values (empty or n
|
|
|
172
234
|
| `annualVariation(observations, periodsPerYear)` | Year-over-year fractional change (`value[i] / value[i - n] - 1`) |
|
|
173
235
|
| `rollingMean(observations, window)` | Rolling mean over a fixed window; `null` if any value in window is a gap |
|
|
174
236
|
|
|
175
|
-
##
|
|
237
|
+
## Terms of Use
|
|
176
238
|
|
|
177
|
-
|
|
178
|
-
# 1. Regenerate CHANGELOG.md (auto-determines next version)
|
|
179
|
-
npm run changelog
|
|
239
|
+
Use of the Banco Central de Chile API is subject to their [terms and conditions](https://si3.bcentral.cl/estadisticas/Principal1/Web_Services/index_BDE_TC.htm). Key points:
|
|
180
240
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
241
|
+
- **Registration required** — you must register and accept the terms at [si3.bcentral.cl](https://si3.bcentral.cl/siete) to obtain credentials.
|
|
242
|
+
- **Rate limit** — maximum 5 simultaneous requests per second per account. The API does not support bulk or parallel fetching.
|
|
243
|
+
- **Attribution** — any application or publication that uses data from this API must credit **Banco Central de Chile** as the original source.
|
|
184
244
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
245
|
+
This library does not redistribute any data. All data is fetched directly from the official API at runtime by the consuming application.
|
|
246
|
+
|
|
247
|
+
## Contributing
|
|
248
|
+
|
|
249
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
188
250
|
|
|
189
251
|
## License
|
|
190
252
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export type { Cache, ClientOptions, Frequency, GetSeriesOptions, Observation, Se
|
|
|
3
3
|
export { MemoryCache } from './cache/index.js';
|
|
4
4
|
export type { MemoryCacheOptions } from './cache/index.js';
|
|
5
5
|
export { SERIES } from './series/index.js';
|
|
6
|
-
export { parseObservationDate, formatQueryDate, filterValid, parseValue, toArrays, toMap, toNumbers, annualVariation, max, mean, min, periodVariation, rollingMean, stdDev, } from './utils/index.js';
|
|
6
|
+
export { parseObservationDate, formatQueryDate, fillForward, filterValid, parseValue, toArrays, toMap, toNumbers, annualVariation, max, mean, min, periodVariation, rollingMean, stdDev, } from './utils/index.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EACV,KAAK,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,eAAe,EACf,GAAG,EACH,IAAI,EACJ,GAAG,EACH,eAAe,EACf,WAAW,EACX,MAAM,GACP,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EACV,KAAK,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,eAAe,EACf,GAAG,EACH,IAAI,EACJ,GAAG,EACH,eAAe,EACf,WAAW,EACX,MAAM,GACP,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Client, ApiError, HttpError } from './client/index.js';
|
|
2
2
|
export { MemoryCache } from './cache/index.js';
|
|
3
3
|
export { SERIES } from './series/index.js';
|
|
4
|
-
export { parseObservationDate, formatQueryDate, filterValid, parseValue, toArrays, toMap, toNumbers, annualVariation, max, mean, min, periodVariation, rollingMean, stdDev, } from './utils/index.js';
|
|
4
|
+
export { parseObservationDate, formatQueryDate, fillForward, filterValid, parseValue, toArrays, toMap, toNumbers, annualVariation, max, mean, min, periodVariation, rollingMean, stdDev, } from './utils/index.js';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWhE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,eAAe,EACf,GAAG,EACH,IAAI,EACJ,GAAG,EACH,eAAe,EACf,WAAW,EACX,MAAM,GACP,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWhE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,eAAe,EACf,GAAG,EACH,IAAI,EACJ,GAAG,EACH,eAAe,EACf,WAAW,EACX,MAAM,GACP,MAAM,kBAAkB,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { formatQueryDate, parseObservationDate } from './dates.js';
|
|
2
|
-
export { filterValid, parseValue, toArrays, toMap, toNumbers } from './transform.js';
|
|
2
|
+
export { fillForward, filterValid, parseValue, toArrays, toMap, toNumbers } from './transform.js';
|
|
3
3
|
export { annualVariation, max, mean, min, periodVariation, rollingMean, stdDev } from './stats.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { formatQueryDate, parseObservationDate } from './dates.js';
|
|
2
|
-
export { filterValid, parseValue, toArrays, toMap, toNumbers } from './transform.js';
|
|
2
|
+
export { fillForward, filterValid, parseValue, toArrays, toMap, toNumbers } from './transform.js';
|
|
3
3
|
export { annualVariation, max, mean, min, periodVariation, rollingMean, stdDev } from './stats.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import type { Observation } from '../client/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fills forward gap observations using the last valid value seen.
|
|
4
|
+
*
|
|
5
|
+
* Each gap (empty or non-numeric `value`) is replaced with the `value` string
|
|
6
|
+
* of the most recent valid observation. The original `indexDateString` and
|
|
7
|
+
* `statusCode` of each observation are preserved.
|
|
8
|
+
*
|
|
9
|
+
* @param observations - Array of observations to fill.
|
|
10
|
+
* @returns A new array of the same length with gaps filled forward.
|
|
11
|
+
* @throws {Error} When the first observation has no valid value. Ensure the
|
|
12
|
+
* start date falls on a trading day with an available observation.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const filled = fillForward(data.observations);
|
|
17
|
+
* // Gap observations now carry the last known value forward
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function fillForward(observations: Observation[]): Observation[];
|
|
2
21
|
/**
|
|
3
22
|
* Parses a raw observation value string to a number, or `null` for gaps.
|
|
4
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOvD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAEtE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE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K,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9B,CAQA"}
|
package/dist/utils/transform.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import { parseObservationDate } from './dates.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fills forward gap observations using the last valid value seen.
|
|
4
|
+
*
|
|
5
|
+
* Each gap (empty or non-numeric `value`) is replaced with the `value` string
|
|
6
|
+
* of the most recent valid observation. The original `indexDateString` and
|
|
7
|
+
* `statusCode` of each observation are preserved.
|
|
8
|
+
*
|
|
9
|
+
* @param observations - Array of observations to fill.
|
|
10
|
+
* @returns A new array of the same length with gaps filled forward.
|
|
11
|
+
* @throws {Error} When the first observation has no valid value. Ensure the
|
|
12
|
+
* start date falls on a trading day with an available observation.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const filled = fillForward(data.observations);
|
|
17
|
+
* // Gap observations now carry the last known value forward
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function fillForward(observations) {
|
|
21
|
+
if (observations.length === 0) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
if (parseValue(observations[0].value) === null) {
|
|
25
|
+
throw new Error('fillForward: first observation has no valid value — ensure the start date falls on a trading day');
|
|
26
|
+
}
|
|
27
|
+
let lastValue = observations[0].value;
|
|
28
|
+
return observations.map((obs) => {
|
|
29
|
+
if (parseValue(obs.value) !== null) {
|
|
30
|
+
lastValue = obs.value;
|
|
31
|
+
return obs;
|
|
32
|
+
}
|
|
33
|
+
return { ...obs, value: lastValue };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
2
36
|
/**
|
|
3
37
|
* Parses a raw observation value string to a number, or `null` for gaps.
|
|
4
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY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IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bcchapi",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Node.js wrapper for the Banco Central de Chile API. Features a fully typed API client and utility tools to streamline macroeconomic data integration.",
|
|
5
5
|
"homepage": "https://github.com/airarrazaval/bcchapi#readme",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/airarrazaval/bcchapi/issues"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"bcch",
|
|
12
|
+
"banco-central",
|
|
13
|
+
"banco-central-de-chile",
|
|
14
|
+
"chile",
|
|
15
|
+
"economics",
|
|
16
|
+
"macroeconomics",
|
|
17
|
+
"api",
|
|
18
|
+
"api-client",
|
|
19
|
+
"time-series",
|
|
20
|
+
"finance",
|
|
21
|
+
"uf",
|
|
22
|
+
"utm"
|
|
23
|
+
],
|
|
10
24
|
"repository": {
|
|
11
25
|
"type": "git",
|
|
12
26
|
"url": "https://github.com/airarrazaval/bcchapi.git"
|
|
@@ -59,10 +73,11 @@
|
|
|
59
73
|
"lint:fix": "oxlint --fix src tests",
|
|
60
74
|
"format": "oxfmt",
|
|
61
75
|
"format:check": "oxfmt --check",
|
|
76
|
+
"check": "npm run typecheck && npm run lint && npm test",
|
|
62
77
|
"clean": "rm -rf dist docs",
|
|
63
78
|
"docs": "typedoc",
|
|
64
79
|
"changelog": "git-cliff --bump -o CHANGELOG.md",
|
|
65
|
-
"prepublishOnly": "npm run
|
|
80
|
+
"prepublishOnly": "npm run check && npm run clean && npm run build"
|
|
66
81
|
},
|
|
67
82
|
"devDependencies": {
|
|
68
83
|
"@types/node": "^24.12.0",
|