data-analyst-mcp 0.0.0-stage → 0.3.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.
Files changed (640) hide show
  1. package/README.md +261 -2
  2. package/dist/adapters/_acf_tidy.d.ts +18 -0
  3. package/dist/adapters/_acf_tidy.js +432 -0
  4. package/dist/adapters/_acf_tidy.js.map +1 -0
  5. package/dist/adapters/_actuaries_read.d.ts +38 -0
  6. package/dist/adapters/_actuaries_read.js +728 -0
  7. package/dist/adapters/_actuaries_read.js.map +1 -0
  8. package/dist/adapters/_census_micro.d.ts +70 -0
  9. package/dist/adapters/_census_micro.js +622 -0
  10. package/dist/adapters/_census_micro.js.map +1 -0
  11. package/dist/adapters/_census_util.d.ts +40 -0
  12. package/dist/adapters/_census_util.js +275 -0
  13. package/dist/adapters/_census_util.js.map +1 -0
  14. package/dist/adapters/_dol_states.d.ts +6 -0
  15. package/dist/adapters/_dol_states.js +58 -0
  16. package/dist/adapters/_dol_states.js.map +1 -0
  17. package/dist/adapters/_govinfo_entities.d.ts +4 -0
  18. package/dist/adapters/_govinfo_entities.js +6 -0
  19. package/dist/adapters/_govinfo_entities.js.map +1 -0
  20. package/dist/adapters/_govinfo_json.d.ts +13 -0
  21. package/dist/adapters/_govinfo_json.js +107 -0
  22. package/dist/adapters/_govinfo_json.js.map +1 -0
  23. package/dist/adapters/_govinfo_py.d.ts +22 -0
  24. package/dist/adapters/_govinfo_py.js +272 -0
  25. package/dist/adapters/_govinfo_py.js.map +1 -0
  26. package/dist/adapters/_govinfo_xml.d.ts +22 -0
  27. package/dist/adapters/_govinfo_xml.js +233 -0
  28. package/dist/adapters/_govinfo_xml.js.map +1 -0
  29. package/dist/adapters/_hud_excel.d.ts +2 -0
  30. package/dist/adapters/_hud_excel.js +166 -0
  31. package/dist/adapters/_hud_excel.js.map +1 -0
  32. package/dist/adapters/_omb_grid.d.ts +17 -0
  33. package/dist/adapters/_omb_grid.js +132 -0
  34. package/dist/adapters/_omb_grid.js.map +1 -0
  35. package/dist/adapters/_omb_util.d.ts +40 -0
  36. package/dist/adapters/_omb_util.js +192 -0
  37. package/dist/adapters/_omb_util.js.map +1 -0
  38. package/dist/adapters/_usaspending_state.d.ts +6 -0
  39. package/dist/adapters/_usaspending_state.js +54 -0
  40. package/dist/adapters/_usaspending_state.js.map +1 -0
  41. package/dist/adapters/_usda-fna_book.d.ts +59 -0
  42. package/dist/adapters/_usda-fna_book.js +869 -0
  43. package/dist/adapters/_usda-fna_book.js.map +1 -0
  44. package/dist/adapters/_usda-fna_pdf.d.ts +20 -0
  45. package/dist/adapters/_usda-fna_pdf.js +361 -0
  46. package/dist/adapters/_usda-fna_pdf.js.map +1 -0
  47. package/dist/adapters/_usda-outlook_read.d.ts +70 -0
  48. package/dist/adapters/_usda-outlook_read.js +362 -0
  49. package/dist/adapters/_usda-outlook_read.js.map +1 -0
  50. package/dist/adapters/acf.d.ts +3 -0
  51. package/dist/adapters/acf.js +187 -0
  52. package/dist/adapters/acf.js.map +1 -0
  53. package/dist/adapters/actuaries.d.ts +3 -0
  54. package/dist/adapters/actuaries.js +293 -0
  55. package/dist/adapters/actuaries.js.map +1 -0
  56. package/dist/adapters/bts.d.ts +3 -0
  57. package/dist/adapters/bts.js +26 -0
  58. package/dist/adapters/bts.js.map +1 -0
  59. package/dist/adapters/census-geocoder.d.ts +10 -0
  60. package/dist/adapters/census-geocoder.js +47 -0
  61. package/dist/adapters/census-geocoder.js.map +1 -0
  62. package/dist/adapters/census.d.ts +17 -0
  63. package/dist/adapters/census.js +983 -0
  64. package/dist/adapters/census.js.map +1 -0
  65. package/dist/adapters/cfpb.d.ts +7 -0
  66. package/dist/adapters/cfpb.js +348 -0
  67. package/dist/adapters/cfpb.js.map +1 -0
  68. package/dist/adapters/clinical-trials.d.ts +3 -0
  69. package/dist/adapters/clinical-trials.js +135 -0
  70. package/dist/adapters/clinical-trials.js.map +1 -0
  71. package/dist/adapters/cms.d.ts +3 -0
  72. package/dist/adapters/cms.js +292 -0
  73. package/dist/adapters/cms.js.map +1 -0
  74. package/dist/adapters/college-scorecard.d.ts +3 -0
  75. package/dist/adapters/college-scorecard.js +122 -0
  76. package/dist/adapters/college-scorecard.js.map +1 -0
  77. package/dist/adapters/congress.d.ts +33 -0
  78. package/dist/adapters/congress.js +589 -0
  79. package/dist/adapters/congress.js.map +1 -0
  80. package/dist/adapters/dhs-ohss.d.ts +13 -0
  81. package/dist/adapters/dhs-ohss.js +598 -0
  82. package/dist/adapters/dhs-ohss.js.map +1 -0
  83. package/dist/adapters/doj-news.d.ts +7 -0
  84. package/dist/adapters/doj-news.js +286 -0
  85. package/dist/adapters/doj-news.js.map +1 -0
  86. package/dist/adapters/dol.d.ts +4 -0
  87. package/dist/adapters/dol.js +634 -0
  88. package/dist/adapters/dol.js.map +1 -0
  89. package/dist/adapters/eia.d.ts +15 -0
  90. package/dist/adapters/eia.js +456 -0
  91. package/dist/adapters/eia.js.map +1 -0
  92. package/dist/adapters/epa-aqs.d.ts +3 -0
  93. package/dist/adapters/epa-aqs.js +357 -0
  94. package/dist/adapters/epa-aqs.js.map +1 -0
  95. package/dist/adapters/epa.d.ts +3 -0
  96. package/dist/adapters/epa.js +298 -0
  97. package/dist/adapters/epa.js.map +1 -0
  98. package/dist/adapters/fbi.d.ts +3 -0
  99. package/dist/adapters/fbi.js +192 -0
  100. package/dist/adapters/fbi.js.map +1 -0
  101. package/dist/adapters/fda.d.ts +5 -0
  102. package/dist/adapters/fda.js +184 -0
  103. package/dist/adapters/fda.js.map +1 -0
  104. package/dist/adapters/fdic.d.ts +4 -0
  105. package/dist/adapters/fdic.js +95 -0
  106. package/dist/adapters/fdic.js.map +1 -0
  107. package/dist/adapters/fec.d.ts +3 -0
  108. package/dist/adapters/fec.js +142 -0
  109. package/dist/adapters/fec.js.map +1 -0
  110. package/dist/adapters/fed-board.d.ts +12 -0
  111. package/dist/adapters/fed-board.js +581 -0
  112. package/dist/adapters/fed-board.js.map +1 -0
  113. package/dist/adapters/federal-register.d.ts +11 -0
  114. package/dist/adapters/federal-register.js +43 -0
  115. package/dist/adapters/federal-register.js.map +1 -0
  116. package/dist/adapters/fhfa.d.ts +3 -0
  117. package/dist/adapters/fhfa.js +253 -0
  118. package/dist/adapters/fhfa.js.map +1 -0
  119. package/dist/adapters/fsa.d.ts +9 -0
  120. package/dist/adapters/fsa.js +335 -0
  121. package/dist/adapters/fsa.js.map +1 -0
  122. package/dist/adapters/govinfo.d.ts +30 -0
  123. package/dist/adapters/govinfo.js +636 -0
  124. package/dist/adapters/govinfo.js.map +1 -0
  125. package/dist/adapters/gsa-calc.d.ts +10 -0
  126. package/dist/adapters/gsa-calc.js +318 -0
  127. package/dist/adapters/gsa-calc.js.map +1 -0
  128. package/dist/adapters/hud.d.ts +3 -0
  129. package/dist/adapters/hud.js +200 -0
  130. package/dist/adapters/hud.js.map +1 -0
  131. package/dist/adapters/index.d.ts +3 -0
  132. package/dist/adapters/index.js +25 -0
  133. package/dist/adapters/index.js.map +1 -0
  134. package/dist/adapters/irs-soi.d.ts +6 -0
  135. package/dist/adapters/irs-soi.js +576 -0
  136. package/dist/adapters/irs-soi.js.map +1 -0
  137. package/dist/adapters/naep.d.ts +15 -0
  138. package/dist/adapters/naep.js +341 -0
  139. package/dist/adapters/naep.js.map +1 -0
  140. package/dist/adapters/nhtsa.d.ts +10 -0
  141. package/dist/adapters/nhtsa.js +239 -0
  142. package/dist/adapters/nhtsa.js.map +1 -0
  143. package/dist/adapters/nih.d.ts +5 -0
  144. package/dist/adapters/nih.js +196 -0
  145. package/dist/adapters/nih.js.map +1 -0
  146. package/dist/adapters/noaa.d.ts +3 -0
  147. package/dist/adapters/noaa.js +148 -0
  148. package/dist/adapters/noaa.js.map +1 -0
  149. package/dist/adapters/nrel.d.ts +3 -0
  150. package/dist/adapters/nrel.js +186 -0
  151. package/dist/adapters/nrel.js.map +1 -0
  152. package/dist/adapters/nws.d.ts +3 -0
  153. package/dist/adapters/nws.js +119 -0
  154. package/dist/adapters/nws.js.map +1 -0
  155. package/dist/adapters/omb.d.ts +15 -0
  156. package/dist/adapters/omb.js +517 -0
  157. package/dist/adapters/omb.js.map +1 -0
  158. package/dist/adapters/open-payments.d.ts +5 -0
  159. package/dist/adapters/open-payments.js +149 -0
  160. package/dist/adapters/open-payments.js.map +1 -0
  161. package/dist/adapters/pbgc.d.ts +13 -0
  162. package/dist/adapters/pbgc.js +283 -0
  163. package/dist/adapters/pbgc.js.map +1 -0
  164. package/dist/adapters/philfed.d.ts +12 -0
  165. package/dist/adapters/philfed.js +59 -0
  166. package/dist/adapters/philfed.js.map +1 -0
  167. package/dist/adapters/regulations.d.ts +6 -0
  168. package/dist/adapters/regulations.js +58 -0
  169. package/dist/adapters/regulations.js.map +1 -0
  170. package/dist/adapters/sec.d.ts +13 -0
  171. package/dist/adapters/sec.js +504 -0
  172. package/dist/adapters/sec.js.map +1 -0
  173. package/dist/adapters/senate-lobbying.d.ts +3 -0
  174. package/dist/adapters/senate-lobbying.js +181 -0
  175. package/dist/adapters/senate-lobbying.js.map +1 -0
  176. package/dist/adapters/snapqc.d.ts +32 -0
  177. package/dist/adapters/snapqc.js +701 -0
  178. package/dist/adapters/snapqc.js.map +1 -0
  179. package/dist/adapters/treasury-yields.d.ts +3 -0
  180. package/dist/adapters/treasury-yields.js +170 -0
  181. package/dist/adapters/treasury-yields.js.map +1 -0
  182. package/dist/adapters/usaspending.d.ts +3 -0
  183. package/dist/adapters/usaspending.js +340 -0
  184. package/dist/adapters/usaspending.js.map +1 -0
  185. package/dist/adapters/usda-fna.d.ts +7 -0
  186. package/dist/adapters/usda-fna.js +707 -0
  187. package/dist/adapters/usda-fna.js.map +1 -0
  188. package/dist/adapters/usda-fooddata.d.ts +3 -0
  189. package/dist/adapters/usda-fooddata.js +101 -0
  190. package/dist/adapters/usda-fooddata.js.map +1 -0
  191. package/dist/adapters/usda-nass.d.ts +3 -0
  192. package/dist/adapters/usda-nass.js +108 -0
  193. package/dist/adapters/usda-nass.js.map +1 -0
  194. package/dist/adapters/usda-outlook.d.ts +12 -0
  195. package/dist/adapters/usda-outlook.js +696 -0
  196. package/dist/adapters/usda-outlook.js.map +1 -0
  197. package/dist/adapters/usgs.d.ts +9 -0
  198. package/dist/adapters/usgs.js +265 -0
  199. package/dist/adapters/usgs.js.map +1 -0
  200. package/dist/adapters/usitc.d.ts +18 -0
  201. package/dist/adapters/usitc.js +170 -0
  202. package/dist/adapters/usitc.js.map +1 -0
  203. package/dist/adapters/uspto.d.ts +3 -0
  204. package/dist/adapters/uspto.js +47 -0
  205. package/dist/adapters/uspto.js.map +1 -0
  206. package/dist/adapters/world-bank.d.ts +3 -0
  207. package/dist/adapters/world-bank.js +163 -0
  208. package/dist/adapters/world-bank.js.map +1 -0
  209. package/dist/analysis/cite.d.ts +31 -0
  210. package/dist/analysis/cite.js +229 -0
  211. package/dist/analysis/cite.js.map +1 -0
  212. package/dist/analysis/combine.d.ts +27 -0
  213. package/dist/analysis/combine.js +198 -0
  214. package/dist/analysis/combine.js.map +1 -0
  215. package/dist/analysis/compute.d.ts +62 -0
  216. package/dist/analysis/compute.js +583 -0
  217. package/dist/analysis/compute.js.map +1 -0
  218. package/dist/analysis/expr.d.ts +69 -0
  219. package/dist/analysis/expr.js +780 -0
  220. package/dist/analysis/expr.js.map +1 -0
  221. package/dist/analysis/factfmt.d.ts +16 -0
  222. package/dist/analysis/factfmt.js +187 -0
  223. package/dist/analysis/factfmt.js.map +1 -0
  224. package/dist/analysis/facts.d.ts +63 -0
  225. package/dist/analysis/facts.js +355 -0
  226. package/dist/analysis/facts.js.map +1 -0
  227. package/dist/analysis/handoff.d.ts +58 -0
  228. package/dist/analysis/handoff.js +208 -0
  229. package/dist/analysis/handoff.js.map +1 -0
  230. package/dist/analysis/pyfmt.d.ts +16 -0
  231. package/dist/analysis/pyfmt.js +156 -0
  232. package/dist/analysis/pyfmt.js.map +1 -0
  233. package/dist/analysis/rerun.d.ts +13 -0
  234. package/dist/analysis/rerun.js +125 -0
  235. package/dist/analysis/rerun.js.map +1 -0
  236. package/dist/analysis/table.d.ts +18 -0
  237. package/dist/analysis/table.js +109 -0
  238. package/dist/analysis/table.js.map +1 -0
  239. package/dist/analysis/tools.d.ts +67 -0
  240. package/dist/analysis/tools.js +217 -0
  241. package/dist/analysis/tools.js.map +1 -0
  242. package/dist/analysis/write_table.d.ts +13 -0
  243. package/dist/analysis/write_table.js +59 -0
  244. package/dist/analysis/write_table.js.map +1 -0
  245. package/dist/bin/cli.d.ts +10 -0
  246. package/dist/bin/cli.js +177 -0
  247. package/dist/bin/cli.js.map +1 -0
  248. package/dist/core/cache.d.ts +14 -0
  249. package/dist/core/cache.js +90 -0
  250. package/dist/core/cache.js.map +1 -0
  251. package/dist/core/context.d.ts +12 -0
  252. package/dist/core/context.js +15 -0
  253. package/dist/core/context.js.map +1 -0
  254. package/dist/core/env.d.ts +14 -0
  255. package/dist/core/env.js +52 -0
  256. package/dist/core/env.js.map +1 -0
  257. package/dist/core/generic-rest.d.ts +61 -0
  258. package/dist/core/generic-rest.js +639 -0
  259. package/dist/core/generic-rest.js.map +1 -0
  260. package/dist/core/http.d.ts +120 -0
  261. package/dist/core/http.js +514 -0
  262. package/dist/core/http.js.map +1 -0
  263. package/dist/core/keys.d.ts +43 -0
  264. package/dist/core/keys.js +174 -0
  265. package/dist/core/keys.js.map +1 -0
  266. package/dist/core/manual.d.ts +41 -0
  267. package/dist/core/manual.js +218 -0
  268. package/dist/core/manual.js.map +1 -0
  269. package/dist/core/package.d.ts +58 -0
  270. package/dist/core/package.js +228 -0
  271. package/dist/core/package.js.map +1 -0
  272. package/dist/core/packs.d.ts +139 -0
  273. package/dist/core/packs.js +173 -0
  274. package/dist/core/packs.js.map +1 -0
  275. package/dist/core/policy.d.ts +69 -0
  276. package/dist/core/policy.js +189 -0
  277. package/dist/core/policy.js.map +1 -0
  278. package/dist/core/py.d.ts +40 -0
  279. package/dist/core/py.js +171 -0
  280. package/dist/core/py.js.map +1 -0
  281. package/dist/core/routing.d.ts +10 -0
  282. package/dist/core/routing.js +39 -0
  283. package/dist/core/routing.js.map +1 -0
  284. package/dist/core/tabular.d.ts +21 -0
  285. package/dist/core/tabular.js +229 -0
  286. package/dist/core/tabular.js.map +1 -0
  287. package/dist/deep/_bea_api.d.ts +102 -0
  288. package/dist/deep/_bea_api.js +457 -0
  289. package/dist/deep/_bea_api.js.map +1 -0
  290. package/dist/deep/_bea_fetch.d.ts +151 -0
  291. package/dist/deep/_bea_fetch.js +1274 -0
  292. package/dist/deep/_bea_fetch.js.map +1 -0
  293. package/dist/deep/_bea_util.d.ts +14 -0
  294. package/dist/deep/_bea_util.js +156 -0
  295. package/dist/deep/_bea_util.js.map +1 -0
  296. package/dist/deep/_bls_api.d.ts +84 -0
  297. package/dist/deep/_bls_api.js +231 -0
  298. package/dist/deep/_bls_api.js.map +1 -0
  299. package/dist/deep/_bls_ids.d.ts +43 -0
  300. package/dist/deep/_bls_ids.js +188 -0
  301. package/dist/deep/_bls_ids.js.map +1 -0
  302. package/dist/deep/_bls_lib.d.ts +61 -0
  303. package/dist/deep/_bls_lib.js +442 -0
  304. package/dist/deep/_bls_lib.js.map +1 -0
  305. package/dist/deep/_fred_api.d.ts +148 -0
  306. package/dist/deep/_fred_api.js +545 -0
  307. package/dist/deep/_fred_api.js.map +1 -0
  308. package/dist/deep/_fred_pack.d.ts +162 -0
  309. package/dist/deep/_fred_pack.js +1027 -0
  310. package/dist/deep/_fred_pack.js.map +1 -0
  311. package/dist/deep/_fred_py.d.ts +40 -0
  312. package/dist/deep/_fred_py.js +199 -0
  313. package/dist/deep/_fred_py.js.map +1 -0
  314. package/dist/deep/_ipums_bundle.d.ts +29 -0
  315. package/dist/deep/_ipums_bundle.js +194 -0
  316. package/dist/deep/_ipums_bundle.js.map +1 -0
  317. package/dist/deep/_ipums_ddi.d.ts +23 -0
  318. package/dist/deep/_ipums_ddi.js +162 -0
  319. package/dist/deep/_ipums_ddi.js.map +1 -0
  320. package/dist/deep/_opm_io.d.ts +26 -0
  321. package/dist/deep/_opm_io.js +383 -0
  322. package/dist/deep/_opm_io.js.map +1 -0
  323. package/dist/deep/_opm_parquet.d.ts +31 -0
  324. package/dist/deep/_opm_parquet.js +744 -0
  325. package/dist/deep/_opm_parquet.js.map +1 -0
  326. package/dist/deep/_opm_py.d.ts +6 -0
  327. package/dist/deep/_opm_py.js +74 -0
  328. package/dist/deep/_opm_py.js.map +1 -0
  329. package/dist/deep/_treasury_api.d.ts +48 -0
  330. package/dist/deep/_treasury_api.js +221 -0
  331. package/dist/deep/_treasury_api.js.map +1 -0
  332. package/dist/deep/_treasury_context.d.ts +34 -0
  333. package/dist/deep/_treasury_context.js +142 -0
  334. package/dist/deep/_treasury_context.js.map +1 -0
  335. package/dist/deep/_treasury_lib.d.ts +109 -0
  336. package/dist/deep/_treasury_lib.js +686 -0
  337. package/dist/deep/_treasury_lib.js.map +1 -0
  338. package/dist/deep/bea.d.ts +3 -0
  339. package/dist/deep/bea.js +248 -0
  340. package/dist/deep/bea.js.map +1 -0
  341. package/dist/deep/bls.d.ts +3 -0
  342. package/dist/deep/bls.js +220 -0
  343. package/dist/deep/bls.js.map +1 -0
  344. package/dist/deep/fred.d.ts +3 -0
  345. package/dist/deep/fred.js +325 -0
  346. package/dist/deep/fred.js.map +1 -0
  347. package/dist/deep/ipums.d.ts +59 -0
  348. package/dist/deep/ipums.js +744 -0
  349. package/dist/deep/ipums.js.map +1 -0
  350. package/dist/deep/opm.d.ts +56 -0
  351. package/dist/deep/opm.js +1033 -0
  352. package/dist/deep/opm.js.map +1 -0
  353. package/dist/deep/treasury.d.ts +3 -0
  354. package/dist/deep/treasury.js +218 -0
  355. package/dist/deep/treasury.js.map +1 -0
  356. package/dist/envelope.d.ts +47 -0
  357. package/dist/envelope.js +88 -0
  358. package/dist/envelope.js.map +1 -0
  359. package/dist/index.d.ts +277 -0
  360. package/dist/index.js +106 -0
  361. package/dist/index.js.map +1 -0
  362. package/dist/remote/app.d.ts +21 -0
  363. package/dist/remote/app.js +218 -0
  364. package/dist/remote/app.js.map +1 -0
  365. package/dist/remote/oauth.d.ts +14 -0
  366. package/dist/remote/oauth.js +90 -0
  367. package/dist/remote/oauth.js.map +1 -0
  368. package/dist/remote/pages.d.ts +8 -0
  369. package/dist/remote/pages.js +56 -0
  370. package/dist/remote/pages.js.map +1 -0
  371. package/dist/remote/sign.d.ts +4 -0
  372. package/dist/remote/sign.js +40 -0
  373. package/dist/remote/sign.js.map +1 -0
  374. package/dist/remote/store.d.ts +31 -0
  375. package/dist/remote/store.js +129 -0
  376. package/dist/remote/store.js.map +1 -0
  377. package/dist/report/audit_answer.d.ts +94 -0
  378. package/dist/report/audit_answer.js +1349 -0
  379. package/dist/report/audit_answer.js.map +1 -0
  380. package/dist/report/audit_report.d.ts +23 -0
  381. package/dist/report/audit_report.js +637 -0
  382. package/dist/report/audit_report.js.map +1 -0
  383. package/dist/report/build_report.d.ts +27 -0
  384. package/dist/report/build_report.js +1168 -0
  385. package/dist/report/build_report.js.map +1 -0
  386. package/dist/report/method_audit.d.ts +47 -0
  387. package/dist/report/method_audit.js +716 -0
  388. package/dist/report/method_audit.js.map +1 -0
  389. package/dist/report/policyset.d.ts +50 -0
  390. package/dist/report/policyset.js +421 -0
  391. package/dist/report/policyset.js.map +1 -0
  392. package/dist/report/py.d.ts +58 -0
  393. package/dist/report/py.js +311 -0
  394. package/dist/report/py.js.map +1 -0
  395. package/dist/report/scan_secrets.d.ts +24 -0
  396. package/dist/report/scan_secrets.js +265 -0
  397. package/dist/report/scan_secrets.js.map +1 -0
  398. package/dist/report/style_check.d.ts +29 -0
  399. package/dist/report/style_check.js +173 -0
  400. package/dist/report/style_check.js.map +1 -0
  401. package/dist/report/tools.d.ts +87 -0
  402. package/dist/report/tools.js +167 -0
  403. package/dist/report/tools.js.map +1 -0
  404. package/dist/server.d.ts +5 -0
  405. package/dist/server.js +247 -0
  406. package/dist/server.js.map +1 -0
  407. package/dist/session.d.ts +47 -0
  408. package/dist/session.js +107 -0
  409. package/dist/session.js.map +1 -0
  410. package/dist/toolkit.d.ts +21 -0
  411. package/dist/toolkit.js +2 -0
  412. package/dist/toolkit.js.map +1 -0
  413. package/dist/tools.d.ts +299 -0
  414. package/dist/tools.js +491 -0
  415. package/dist/tools.js.map +1 -0
  416. package/guide/WORKFLOW.md +134 -0
  417. package/guide/assets/disclaimer.txt +1 -0
  418. package/guide/assets/download_data.ps1 +162 -0
  419. package/guide/assets/download_data.sh +143 -0
  420. package/guide/assets/report_template.html +597 -0
  421. package/guide/references/report_patterns.md +199 -0
  422. package/guide/references/routing.md +171 -0
  423. package/guide/references/style_guide.md +398 -0
  424. package/package.json +54 -4
  425. package/packs/acf/endpoints.json +114 -0
  426. package/packs/acf/policy.json +104 -0
  427. package/packs/acf/source.md +138 -0
  428. package/packs/actuaries/endpoints.json +82 -0
  429. package/packs/actuaries/policy.json +109 -0
  430. package/packs/actuaries/source.md +137 -0
  431. package/packs/bea/assets/download_bea.ps1 +182 -0
  432. package/packs/bea/assets/download_bea.sh +144 -0
  433. package/packs/bea/docs/bea_api.md +461 -0
  434. package/packs/bea/docs/datasets.md +157 -0
  435. package/packs/bea/docs/report_patterns.md +112 -0
  436. package/packs/bea/policy.json +170 -0
  437. package/packs/bea/source.md +152 -0
  438. package/packs/bls/assets/download_bls.ps1 +152 -0
  439. package/packs/bls/assets/download_bls.sh +167 -0
  440. package/packs/bls/docs/analysis_patterns.md +108 -0
  441. package/packs/bls/docs/bls_api.md +73 -0
  442. package/packs/bls/docs/series_ids.md +149 -0
  443. package/packs/bls/policy.json +238 -0
  444. package/packs/bls/series_ids.json +1375 -0
  445. package/packs/bls/source.md +156 -0
  446. package/packs/bts/endpoints.json +347 -0
  447. package/packs/bts/policy.json +94 -0
  448. package/packs/bts/source.md +97 -0
  449. package/packs/cdc/endpoints.json +197 -0
  450. package/packs/cdc/policy.json +83 -0
  451. package/packs/cdc/source.md +74 -0
  452. package/packs/census/endpoints.json +99 -0
  453. package/packs/census/policy.json +238 -0
  454. package/packs/census/source.md +304 -0
  455. package/packs/census-geocoder/endpoints.json +70 -0
  456. package/packs/census-geocoder/policy.json +80 -0
  457. package/packs/census-geocoder/source.md +53 -0
  458. package/packs/cfpb/endpoints.json +327 -0
  459. package/packs/cfpb/policy.json +119 -0
  460. package/packs/cfpb/source.md +96 -0
  461. package/packs/clinical-trials/endpoints.json +167 -0
  462. package/packs/clinical-trials/policy.json +84 -0
  463. package/packs/clinical-trials/source.md +82 -0
  464. package/packs/cms/endpoints.json +69 -0
  465. package/packs/cms/policy.json +96 -0
  466. package/packs/cms/source.md +112 -0
  467. package/packs/college-scorecard/endpoints.json +253 -0
  468. package/packs/college-scorecard/policy.json +106 -0
  469. package/packs/college-scorecard/source.md +92 -0
  470. package/packs/congress/endpoints.json +1701 -0
  471. package/packs/congress/policy.json +117 -0
  472. package/packs/congress/source.md +190 -0
  473. package/packs/dhs-ohss/endpoints.json +66 -0
  474. package/packs/dhs-ohss/policy.json +107 -0
  475. package/packs/dhs-ohss/source.md +120 -0
  476. package/packs/doj-news/endpoints.json +59 -0
  477. package/packs/doj-news/policy.json +96 -0
  478. package/packs/doj-news/source.md +99 -0
  479. package/packs/dol/endpoints.json +818 -0
  480. package/packs/dol/policy.json +135 -0
  481. package/packs/dol/source.md +181 -0
  482. package/packs/eia/endpoints.json +718 -0
  483. package/packs/eia/policy.json +112 -0
  484. package/packs/eia/source.md +112 -0
  485. package/packs/epa/endpoints.json +292 -0
  486. package/packs/epa/policy.json +99 -0
  487. package/packs/epa/source.md +99 -0
  488. package/packs/epa-aqs/endpoints.json +174 -0
  489. package/packs/epa-aqs/policy.json +96 -0
  490. package/packs/epa-aqs/source.md +97 -0
  491. package/packs/fbi/endpoints.json +1842 -0
  492. package/packs/fbi/policy.json +118 -0
  493. package/packs/fbi/source.md +108 -0
  494. package/packs/fda/endpoints.json +238 -0
  495. package/packs/fda/policy.json +121 -0
  496. package/packs/fda/source.md +117 -0
  497. package/packs/fdic/endpoints.json +417 -0
  498. package/packs/fdic/policy.json +83 -0
  499. package/packs/fdic/source.md +92 -0
  500. package/packs/fec/endpoints.json +708 -0
  501. package/packs/fec/policy.json +93 -0
  502. package/packs/fec/source.md +90 -0
  503. package/packs/fed-board/endpoints.json +89 -0
  504. package/packs/fed-board/policy.json +136 -0
  505. package/packs/fed-board/source.md +118 -0
  506. package/packs/federal-register/endpoints.json +143 -0
  507. package/packs/federal-register/policy.json +86 -0
  508. package/packs/federal-register/source.md +98 -0
  509. package/packs/fema/endpoints.json +646 -0
  510. package/packs/fema/policy.json +103 -0
  511. package/packs/fema/source.md +103 -0
  512. package/packs/fhfa/endpoints.json +105 -0
  513. package/packs/fhfa/policy.json +109 -0
  514. package/packs/fhfa/source.md +108 -0
  515. package/packs/fred/assets/download_fred.ps1 +122 -0
  516. package/packs/fred/assets/download_fred.sh +123 -0
  517. package/packs/fred/docs/analysis_patterns.md +124 -0
  518. package/packs/fred/docs/fred_api.md +94 -0
  519. package/packs/fred/docs/series.md +188 -0
  520. package/packs/fred/policy.json +253 -0
  521. package/packs/fred/source.md +142 -0
  522. package/packs/fsa/endpoints.json +150 -0
  523. package/packs/fsa/policy.json +99 -0
  524. package/packs/fsa/source.md +102 -0
  525. package/packs/govinfo/endpoints.json +520 -0
  526. package/packs/govinfo/policy.json +116 -0
  527. package/packs/govinfo/source.md +241 -0
  528. package/packs/gsa-calc/endpoints.json +93 -0
  529. package/packs/gsa-calc/policy.json +97 -0
  530. package/packs/gsa-calc/source.md +108 -0
  531. package/packs/hud/endpoints.json +147 -0
  532. package/packs/hud/policy.json +84 -0
  533. package/packs/hud/source.md +97 -0
  534. package/packs/ipums/assets/download_ipums.ps1 +215 -0
  535. package/packs/ipums/assets/download_ipums.sh +192 -0
  536. package/packs/ipums/docs/ipums_api.md +67 -0
  537. package/packs/ipums/docs/report_patterns.md +117 -0
  538. package/packs/ipums/docs/variables.md +284 -0
  539. package/packs/ipums/lib/fetch_text.json +112 -0
  540. package/packs/ipums/policy.json +215 -0
  541. package/packs/ipums/source.md +169 -0
  542. package/packs/irs-soi/endpoints.json +114 -0
  543. package/packs/irs-soi/policy.json +107 -0
  544. package/packs/irs-soi/source.md +124 -0
  545. package/packs/medicaid/endpoints.json +412 -0
  546. package/packs/medicaid/policy.json +108 -0
  547. package/packs/medicaid/source.md +136 -0
  548. package/packs/naep/endpoints.json +217 -0
  549. package/packs/naep/policy.json +100 -0
  550. package/packs/naep/source.md +120 -0
  551. package/packs/nhtsa/endpoints.json +132 -0
  552. package/packs/nhtsa/policy.json +93 -0
  553. package/packs/nhtsa/source.md +109 -0
  554. package/packs/nih/endpoints.json +453 -0
  555. package/packs/nih/policy.json +86 -0
  556. package/packs/nih/source.md +108 -0
  557. package/packs/noaa/endpoints.json +432 -0
  558. package/packs/noaa/policy.json +95 -0
  559. package/packs/noaa/source.md +88 -0
  560. package/packs/nrel/endpoints.json +328 -0
  561. package/packs/nrel/policy.json +96 -0
  562. package/packs/nrel/source.md +91 -0
  563. package/packs/nws/endpoints.json +272 -0
  564. package/packs/nws/policy.json +82 -0
  565. package/packs/nws/source.md +81 -0
  566. package/packs/nyfed/endpoints.json +80 -0
  567. package/packs/nyfed/policy.json +92 -0
  568. package/packs/nyfed/source.md +89 -0
  569. package/packs/omb/endpoints.json +460 -0
  570. package/packs/omb/policy.json +106 -0
  571. package/packs/omb/source.md +130 -0
  572. package/packs/open-payments/endpoints.json +298 -0
  573. package/packs/open-payments/policy.json +101 -0
  574. package/packs/open-payments/source.md +99 -0
  575. package/packs/opm/assets/download_opm.ps1 +125 -0
  576. package/packs/opm/assets/download_opm.sh +85 -0
  577. package/packs/opm/docs/fields.md +184 -0
  578. package/packs/opm/docs/opm_api.md +71 -0
  579. package/packs/opm/docs/report_patterns.md +83 -0
  580. package/packs/opm/lib/data_dictionary.csv +73 -0
  581. package/packs/opm/policy.json +142 -0
  582. package/packs/opm/source.md +137 -0
  583. package/packs/pbgc/endpoints.json +483 -0
  584. package/packs/pbgc/policy.json +94 -0
  585. package/packs/pbgc/source.md +95 -0
  586. package/packs/philfed/endpoints.json +85 -0
  587. package/packs/philfed/policy.json +94 -0
  588. package/packs/philfed/source.md +125 -0
  589. package/packs/port.json +287 -0
  590. package/packs/regulations/endpoints.json +288 -0
  591. package/packs/regulations/policy.json +86 -0
  592. package/packs/regulations/source.md +84 -0
  593. package/packs/sec/endpoints.json +237 -0
  594. package/packs/sec/policy.json +86 -0
  595. package/packs/sec/source.md +101 -0
  596. package/packs/senate-lobbying/endpoints.json +554 -0
  597. package/packs/senate-lobbying/policy.json +99 -0
  598. package/packs/senate-lobbying/source.md +100 -0
  599. package/packs/snapqc/endpoints.json +1426 -0
  600. package/packs/snapqc/policy.json +92 -0
  601. package/packs/snapqc/source.md +96 -0
  602. package/packs/treasury/catalog.json +2267 -0
  603. package/packs/treasury/docs/api_guide.md +245 -0
  604. package/packs/treasury/docs/datasets.md +56 -0
  605. package/packs/treasury/docs/report_patterns.md +126 -0
  606. package/packs/treasury/policy.json +159 -0
  607. package/packs/treasury/source.md +170 -0
  608. package/packs/treasury-yields/endpoints.json +226 -0
  609. package/packs/treasury-yields/policy.json +86 -0
  610. package/packs/treasury-yields/source.md +80 -0
  611. package/packs/usaspending/endpoints.json +1316 -0
  612. package/packs/usaspending/policy.json +109 -0
  613. package/packs/usaspending/source.md +103 -0
  614. package/packs/usda-fna/endpoints.json +427 -0
  615. package/packs/usda-fna/policy.json +133 -0
  616. package/packs/usda-fna/source.md +217 -0
  617. package/packs/usda-fooddata/endpoints.json +181 -0
  618. package/packs/usda-fooddata/policy.json +94 -0
  619. package/packs/usda-fooddata/source.md +105 -0
  620. package/packs/usda-nass/endpoints.json +324 -0
  621. package/packs/usda-nass/policy.json +95 -0
  622. package/packs/usda-nass/source.md +85 -0
  623. package/packs/usda-outlook/endpoints.json +86 -0
  624. package/packs/usda-outlook/policy.json +109 -0
  625. package/packs/usda-outlook/source.md +144 -0
  626. package/packs/usgs/endpoints.json +313 -0
  627. package/packs/usgs/policy.json +95 -0
  628. package/packs/usgs/source.md +96 -0
  629. package/packs/usitc/endpoints.json +74 -0
  630. package/packs/usitc/policy.json +111 -0
  631. package/packs/usitc/source.md +90 -0
  632. package/packs/uspto/endpoints.json +141 -0
  633. package/packs/uspto/policy.json +95 -0
  634. package/packs/uspto/source.md +101 -0
  635. package/packs/va/endpoints.json +414 -0
  636. package/packs/va/policy.json +101 -0
  637. package/packs/va/source.md +129 -0
  638. package/packs/world-bank/endpoints.json +122 -0
  639. package/packs/world-bank/policy.json +101 -0
  640. package/packs/world-bank/source.md +93 -0
@@ -0,0 +1,1027 @@
1
+ /**
2
+ * The fred deep pack's spec, download and packaging (ported from sources/fred/fetch.py).
3
+ *
4
+ * spec:
5
+ * {"description": "Output gap since 2019",
6
+ * "series": [{"id": "GDPC1", "label": "Real GDP"}, "GDPPOT"], // or plain IDs
7
+ * "start": "2018-01-01", "end": null, // end: latest
8
+ * "recessions": true, // adds USREC (NBER recession indicator, monthly)
9
+ * // optional, globally or per series (per series wins):
10
+ * "frequency": "q", "aggregation_method": "avg", "units": "lin",
11
+ * "vintage": "latest" | {"as_of": [dates]} | "first_release" | "all",
12
+ * "regional": [{"series_id": "CAUR", "region_type": "state", "date": "2025-01-01"}], // GeoFRED, key
13
+ * "release_dates": {"release_id": 50, "start": "2026-10-01", "end": "2026-12-31"}, // calendar, key
14
+ * "release_observations": [{"release_id": 53, "limit": 10000, "max_pages": 2, "series": [IDs]}]} // v2, key
15
+ * Per series also (they do not change the download): "source", "copyright" (public_domain | citation_required |
16
+ * preapproval_required) with "copyright_basis".
17
+ *
18
+ * Output (<workspace>/data/fred/): fred_observations.csv, series.csv, regional.csv, release_dates.csv,
19
+ * release_series.csv / release_observations.csv (when asked), raw/, request.json, README.md.
20
+ */
21
+ import { createHash } from "node:crypto";
22
+ import fs from "node:fs";
23
+ import path from "node:path";
24
+ import { parse } from "csv-parse/sync";
25
+ import { trail } from "../core/context.js";
26
+ import * as keys from "../core/keys.js";
27
+ import { dataDir as coreDataDir } from "../core/package.js";
28
+ import * as pol from "../core/policy.js";
29
+ import { parsePyJson, pyFloatRepr, pyJsonDumps } from "../core/py.js";
30
+ import { writeCsv } from "../core/tabular.js";
31
+ import { API, API_V2, citation, copyrightFromTag, copyrightStatus, copyrightTagOf, FredError, GRAPH_MAX, GRAPH_XLSX, graphUrl, isFatal, LEGAL_URL, NOTICE, observationRows, parseGraphCsv, parseGraphXlsx, parseValue, regionalRows, TERMS_URL, } from "./_fred_api.js";
32
+ import { cell, cmp, cmpTuple, dayBeforeFirst, daysBetween, dumpsIndent, isDigits, localToday, nowIso, pstr, PY_SPACE, pyInt, pyRepr, pyStrip, PyValueError, roundHalfEven, truthy, tupleRepr, urlencodeSafe, } from "./_fred_py.js";
33
+ export const SOURCE = "fred";
34
+ export const FREQS = ["d", "w", "bw", "m", "q", "sa", "a"];
35
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.\-]{0,40}$/;
36
+ /** FRED's labels on a series page: "Public Domain: Citation Requested", "Copyrighted: Citation Required",
37
+ * "Copyrighted: Pre-Approval Required". */
38
+ export const COPYRIGHT_LABELS = ["public_domain", "citation_required", "preapproval_required"];
39
+ /** fields that do not change the download */
40
+ const NOT_DATA = ["label", "copyright", "copyright_basis", "source", "auto"];
41
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
42
+ const isDict = (v) => !!v && typeof v === "object" && !Array.isArray(v);
43
+ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
44
+ const get = (o, k, d = null) => (has(o, k) ? o[k] : d);
45
+ const blank = (v) => v === null || v === undefined || v === "";
46
+ /** dict(x) of a spec entry (Python raises TypeError on anything else). */
47
+ function asDict(x) {
48
+ if (isDict(x))
49
+ return { ...x };
50
+ const t = x === null || x === undefined ? "NoneType" : typeof x === "number" ? (Number.isInteger(x) ? "int" : "float")
51
+ : typeof x === "boolean" ? "bool" : Array.isArray(x) ? "list" : "str";
52
+ throw new PyValueError(Array.isArray(x) ? "cannot convert dictionary update sequence element #0 to a sequence"
53
+ : `'${t}' object is not iterable`);
54
+ }
55
+ export function normVintage(v) {
56
+ if (v === null || v === undefined || v === "" || v === "latest")
57
+ return { kind: "latest", dates: [] };
58
+ if (v === "first_release" || v === "initial")
59
+ return { kind: "first_release", dates: [] };
60
+ if (v === "all" || v === "all_vintages")
61
+ return { kind: "all", dates: [] };
62
+ if (isDict(v) && has(v, "as_of")) {
63
+ const raw = Array.isArray(v.as_of) ? v.as_of : [v.as_of];
64
+ const dates = [...new Set(raw.map((d) => pstr(d).slice(0, 10)))].sort(cmp);
65
+ const bad = dates.filter((d) => !DATE_RE.test(d));
66
+ if (bad.length || !dates.length)
67
+ throw new PyValueError(`vintage as_of needs YYYY-MM-DD dates, got ${pyRepr(v.as_of)}`);
68
+ return { kind: "as_of", dates };
69
+ }
70
+ throw new PyValueError(`vintage must be "latest", {"as_of": [dates]}, "first_release" or "all", got ${pyRepr(v)}`);
71
+ }
72
+ export function normSpec(spec) {
73
+ if (!isDict(spec))
74
+ throw new PyValueError("spec must be a JSON object");
75
+ const G = ["start", "end", "frequency", "aggregation_method", "units"];
76
+ const g = Object.fromEntries(G.map((k) => [k, get(spec, k)]));
77
+ const gv = get(spec, "vintage");
78
+ const series = [];
79
+ const list = (v) => (truthy(v) ? (Array.isArray(v) ? v : isDict(v) ? Object.keys(v) : typeof v === "string" ? [...v] : [v]) : []);
80
+ for (const x0 of list(spec.series)) {
81
+ const x = typeof x0 === "string" ? { id: x0 } : asDict(x0);
82
+ if (!has(x, "id"))
83
+ throw new PyValueError("'id'");
84
+ const sid = pyStrip(pstr(x.id)).toUpperCase();
85
+ if (!ID_RE.test(sid))
86
+ throw new PyValueError(`not a FRED series ID: ${pyRepr(x.id)}`);
87
+ const item = { id: sid, label: get(x, "label", "") };
88
+ if (truthy(x.copyright)) { // read on the series page when the keyless route gave no notes
89
+ if (!COPYRIGHT_LABELS.includes(x.copyright))
90
+ throw new PyValueError(`${sid}: copyright must be one of ${tupleRepr(COPYRIGHT_LABELS)}`);
91
+ item.copyright = x.copyright;
92
+ item.copyright_basis = truthy(x.copyright_basis) ? x.copyright_basis : "set in spec.json";
93
+ }
94
+ if (truthy(x.source))
95
+ item.source = pstr(x.source); // the source agency, for the citation (keyless route)
96
+ for (const k of G) {
97
+ const val = has(x, k) ? x[k] : g[k];
98
+ item[k] = blank(val) ? null : pyStrip(pstr(val));
99
+ }
100
+ item.vintage = normVintage(has(x, "vintage") ? x.vintage : gv);
101
+ for (const k of ["start", "end"]) {
102
+ if (item[k] && !DATE_RE.test(item[k]))
103
+ throw new PyValueError(`${sid}: ${k} must be YYYY-MM-DD, got ${pyRepr(item[k])}`);
104
+ }
105
+ if (item.frequency && !FREQS.includes(item.frequency.toLowerCase())) {
106
+ throw new PyValueError(`${sid}: frequency must be one of ${tupleRepr(FREQS)}`);
107
+ }
108
+ if (item.frequency)
109
+ item.frequency = item.frequency.toLowerCase();
110
+ if (item.aggregation_method && !["avg", "sum", "eop"].includes(item.aggregation_method)) {
111
+ throw new PyValueError(`${sid}: aggregation_method must be avg, sum or eop`);
112
+ }
113
+ if (item.units === "lin")
114
+ item.units = null;
115
+ series.push(item);
116
+ }
117
+ if (truthy(spec.recessions) && !series.some((s) => s.id === "USREC")) {
118
+ // the same entry as an explicit {"id": "USREC"} would get, so listing it later (to add its source and copyright)
119
+ // is the same request
120
+ series.push({ id: "USREC", label: "NBER recession indicator", start: g.start, end: g.end, frequency: null,
121
+ aggregation_method: null, units: null, vintage: normVintage(gv), auto: "recessions" });
122
+ }
123
+ const keyOf = (s) => pyJsonDumps([s.id, s.units, s.frequency, s.vintage.kind, s.vintage.dates]);
124
+ const counts = new Map();
125
+ for (const s of series)
126
+ counts.set(keyOf(s), (counts.get(keyOf(s)) || 0) + 1);
127
+ const dup = [...new Set(series.filter((s) => counts.get(keyOf(s)) > 1).map((s) => s.id))].sort(cmp);
128
+ if (dup.length)
129
+ throw new PyValueError(`duplicate series in spec.json: ${pyRepr(dup)}`);
130
+ const regional = [];
131
+ for (const r0 of list(spec.regional)) {
132
+ if (!isDict(r0))
133
+ throw new PyValueError(`'${typeof r0 === "string" ? "str" : typeof r0}' object has no attribute 'get'`);
134
+ if (!(truthy(r0.series_id) || truthy(r0.series_group))) {
135
+ throw new PyValueError("each regional block needs series_id (any series of the group) or series_group");
136
+ }
137
+ const r = {};
138
+ for (const k of ["series_id", "series_group", "region_type", "date", "start_date", "season", "units", "frequency",
139
+ "aggregation_method", "transformation", "label"])
140
+ if (!blank(r0[k]))
141
+ r[k] = r0[k];
142
+ regional.push(r);
143
+ }
144
+ let rdates = null;
145
+ if (truthy(spec.release_dates)) {
146
+ const rd0 = spec.release_dates;
147
+ const rd = typeof rd0 === "number" || typeof rd0 === "string" || typeof rd0 === "boolean" ? { release_id: rd0 } : asDict(rd0);
148
+ for (const k of ["start", "end"]) {
149
+ if (truthy(rd[k]) && !DATE_RE.test(pstr(rd[k])))
150
+ throw new PyValueError(`release_dates ${k} must be YYYY-MM-DD, got ${pyRepr(rd[k])}`);
151
+ }
152
+ if (!blank(rd.release_id) && !isDigits(pstr(rd.release_id))) {
153
+ throw new PyValueError(`release_dates release_id must be a number, got ${pyRepr(rd.release_id)}`);
154
+ }
155
+ rdates = { release_id: !blank(rd.release_id) ? pyInt(rd.release_id) : null, start: get(rd, "start"), end: get(rd, "end"),
156
+ limit: pyInt(truthy(rd.limit) ? rd.limit : 10000) };
157
+ }
158
+ const robs = [];
159
+ for (const ro0 of list(spec.release_observations)) {
160
+ const ro = typeof ro0 === "number" || typeof ro0 === "string" || typeof ro0 === "boolean" ? { release_id: ro0 } : asDict(ro0);
161
+ if (!isDigits(pstr(get(ro, "release_id", "")))) {
162
+ throw new PyValueError(`release_observations needs a numeric release_id, got ${pyRepr(get(ro, "release_id"))}`);
163
+ }
164
+ const lim = pyInt(truthy(ro.limit) ? ro.limit : 10000), pages = pyInt(truthy(ro.max_pages) ? ro.max_pages : 5);
165
+ if (!(lim >= 1 && lim <= 500000) || !(pages >= 1 && pages <= 50)) {
166
+ throw new PyValueError("release_observations: limit 1-500000 observations per page, max_pages 1-50");
167
+ }
168
+ const keep = list(ro.series).map((x) => pyStrip(pstr(x)).toUpperCase());
169
+ robs.push({ release_id: pyInt(ro.release_id), limit: lim, max_pages: pages, series: keep, label: get(ro, "label", "") });
170
+ }
171
+ if (!series.length && !regional.length && !rdates && !robs.length) {
172
+ throw new PyValueError("spec.json has no series, regional, release_dates or release_observations block");
173
+ }
174
+ return { description: get(spec, "description", ""), series, regional, recessions: truthy(spec.recessions),
175
+ release_dates: rdates, release_observations: robs };
176
+ }
177
+ const sha16 = (s) => createHash("sha256").update(s).digest("hex").slice(0, 16);
178
+ const omit = (o, drop) => Object.fromEntries(Object.entries(o).filter(([k]) => !drop.includes(k)));
179
+ const byJson = (a, b) => cmp(pyJsonDumps(a, true), pyJsonDumps(b, true));
180
+ /** Two specs asking for the same data hash the same (labels and description do not matter). */
181
+ export function fingerprint(s) {
182
+ const core = {
183
+ series: s.series.map((x) => omit(x, NOT_DATA)).sort(byJson),
184
+ regional: s.regional.map((r) => omit(r, ["label"])).sort(byJson),
185
+ };
186
+ if (s.release_dates)
187
+ core.release_dates = s.release_dates;
188
+ if (s.release_observations.length)
189
+ core.release_observations = s.release_observations.map((r) => omit(r, ["label"]));
190
+ return sha16(pyJsonDumps(core, true));
191
+ }
192
+ /** The spec fields that change only the packaging (labels, sources, copyright). */
193
+ export function metaFingerprint(s) {
194
+ const core = s.series.map((x) => [x.id, ...NOT_DATA.map((k) => get(x, k))]);
195
+ return sha16(pyJsonDumps(core, true));
196
+ }
197
+ /** What in this request only the API (with a key) can deliver. */
198
+ export function keyOnlyNeeds(s) {
199
+ const out = s.series.filter((x) => x.vintage.kind === "first_release" || x.vintage.kind === "all")
200
+ .map((x) => `${x.id}: ${x.vintage.kind.replaceAll("_", " ")} vintages`);
201
+ if (s.regional.length)
202
+ out.push(`${s.regional.length} GeoFRED regional cross-section(s)`);
203
+ if (s.release_dates)
204
+ out.push("the release calendar (release/dates)");
205
+ for (const r of s.release_observations)
206
+ out.push(`release ${r.release_id} observations (v2 release/observations)`);
207
+ return out;
208
+ }
209
+ /** The as-of dates of one series in groups of GRAPH_MAX: one keyless graph download holds at most 12 columns and FRED
210
+ * drops the rest silently (checked live: 14 as-of dates returned 12 vintages). [null] = latest only. */
211
+ export function vintageChunks(x) {
212
+ const d = x.vintage.dates;
213
+ if (!d.length)
214
+ return [null];
215
+ const out = [];
216
+ for (let i = 0; i < d.length; i += GRAPH_MAX)
217
+ out.push(d.slice(i, i + GRAPH_MAX));
218
+ return out;
219
+ }
220
+ export function chunkFile(x, n, of) {
221
+ return of === 1 ? `${tag(x)}.csv` : `${tag(x)}_p${n}.csv`;
222
+ }
223
+ /** A file-name-safe name for one requested series variant. */
224
+ export function tag(x) {
225
+ const parts = [x.id];
226
+ if (x.units)
227
+ parts.push(x.units);
228
+ if (x.frequency)
229
+ parts.push(x.frequency + (x.aggregation_method || "avg"));
230
+ if (x.vintage.kind !== "latest")
231
+ parts.push(x.vintage.kind !== "as_of" ? x.vintage.kind : "asof");
232
+ return parts.join("_");
233
+ }
234
+ export function dataDir(out) {
235
+ return coreDataDir(out, SOURCE);
236
+ }
237
+ export function existingData(out, fp) {
238
+ const d = dataDir(out);
239
+ const rq = path.join(d, "request.json"), csvPath = path.join(d, "fred_observations.csv");
240
+ if (!fs.existsSync(rq))
241
+ return null;
242
+ let saved;
243
+ try {
244
+ saved = JSON.parse(fs.readFileSync(rq, "utf8"));
245
+ }
246
+ catch {
247
+ return null;
248
+ }
249
+ const retrieved = saved.retrieved || "";
250
+ const t = Date.parse(retrieved);
251
+ return { path: csvPath, csv_exists: fs.existsSync(csvPath), matches: saved.fingerprint === fp,
252
+ meta_fingerprint: saved.meta_fingerprint ?? null, acquired: saved.acquired || "", retrieved,
253
+ age_days: Number.isFinite(t) ? Math.floor((Date.now() - t) / 86400000) : null, route: saved.route ?? null,
254
+ latest: saved.latest ?? null, problems: saved.problems || [] };
255
+ }
256
+ function apiUrl(p, params, geo = false) {
257
+ const q = {};
258
+ for (const [k, v] of Object.entries(params))
259
+ if (!blank(v))
260
+ q[k] = v;
261
+ q.api_key = "__FRED_KEY__";
262
+ q.file_type = "json";
263
+ const base = geo ? API.replace("/fred/", "/geofred/") : API;
264
+ return `${base}${p}?${urlencodeSafe(q)}`;
265
+ }
266
+ /** Every file the user downloads: FRED's keyless graph files where they serve, API calls otherwise (the Python
267
+ * manifest; keyed URLs carry the __FRED_KEY__ placeholder). */
268
+ export function pyManualItems(s) {
269
+ const items = [];
270
+ for (const x of s.series) {
271
+ const kind = x.vintage.kind;
272
+ if (kind === "latest" || kind === "as_of") {
273
+ const chunks = vintageChunks(x);
274
+ chunks.forEach((dates, i) => {
275
+ const url = graphUrl(x.id, { start: x.start, end: x.end, frequency: x.frequency,
276
+ aggregation_method: x.aggregation_method, units: x.units, vintage_dates: dates });
277
+ items.push({ file: chunkFile(x, i + 1, chunks.length), url, keyed: false,
278
+ what: (truthy(x.label) ? pstr(x.label) : x.id) + (chunks.length > 1 ? ` (vintages ${dates[0]} to ${dates[dates.length - 1]})` : "") });
279
+ });
280
+ continue;
281
+ }
282
+ const p = { series_id: x.id, observation_start: x.start, observation_end: x.end, units: x.units,
283
+ frequency: x.frequency, aggregation_method: x.aggregation_method, realtime_start: "1776-07-04",
284
+ realtime_end: "9999-12-31" };
285
+ if (kind === "first_release")
286
+ p.output_type = 4;
287
+ items.push({ file: `${tag(x)}.json`, url: apiUrl("series/observations", p), keyed: true,
288
+ what: `${x.id} ${kind.replaceAll("_", " ")}` });
289
+ items.push({ file: `${x.id}__series.json`, url: apiUrl("series", { series_id: x.id }), keyed: true,
290
+ what: `${x.id} notes (source, copyright)` });
291
+ }
292
+ const ids = [...new Set(s.series.map((x) => x.id))].sort(cmp); // the XLSX gives titles and units without a key
293
+ for (let i = 0; i < ids.length; i += GRAPH_MAX) {
294
+ const chunk = ids.slice(i, i + GRAPH_MAX);
295
+ items.push({ file: `metadata_${String(i / GRAPH_MAX + 1).padStart(2, "0")}.xlsx`, keyed: false, what: "titles, units, frequency",
296
+ url: `${GRAPH_XLSX}?${urlencodeSafe({ id: chunk.join(",") })}` });
297
+ }
298
+ s.regional.forEach((rb, j0) => {
299
+ const j = String(j0 + 1).padStart(2, "0");
300
+ const p = omit(rb, ["label", "series_id"]);
301
+ if (has(p, "series_group")) {
302
+ items.push({ file: `regional_${j}.json`, keyed: true, what: "GeoFRED cross-section", url: apiUrl("regional/data", p, true) });
303
+ return;
304
+ }
305
+ // two steps: the group of the member series, then the cross-section; the download scripts fill the __GROUP_*__
306
+ // placeholders from the first reply
307
+ const tpl = { series_group: "__GROUP_SERIES_GROUP__", region_type: "__GROUP_REGION_TYPE__", season: "__GROUP_SEASON__",
308
+ units: "__GROUP_UNITS__", frequency: "__GROUP_FREQUENCY__", date: "__GROUP_MAX_DATE__", ...p };
309
+ items.push({ file: `regional_${j}__group.json`, keyed: true, what: "GeoFRED group",
310
+ url: apiUrl("series/group", { series_id: rb.series_id }, true),
311
+ then: { file: `regional_${j}.json`, url: apiUrl("regional/data", tpl, true) } });
312
+ });
313
+ const rd = s.release_dates;
314
+ if (rd) {
315
+ const start = rd.start || localToday();
316
+ const end = rd.end || (rd.release_id ? "9999-12-31" : localToday(14));
317
+ let p = { realtime_start: start, realtime_end: end, include_release_dates_with_no_data: "true",
318
+ sort_order: "asc", limit: rd.limit };
319
+ const pth = rd.release_id ? "release/dates" : "releases/dates";
320
+ if (rd.release_id)
321
+ p = { release_id: rd.release_id, ...p };
322
+ items.push({ file: "release_dates.json", keyed: true, what: "release calendar", url: apiUrl(pth, p) });
323
+ }
324
+ for (const ro of s.release_observations) {
325
+ const q = urlencodeSafe({ release_id: ro.release_id, format: "json", limit: ro.limit }).replaceAll(",", "%2C");
326
+ items.push({ file: `release_${ro.release_id}.json`, keyed: true, bearer: true, pages: ro.max_pages,
327
+ what: `release ${ro.release_id} observations (FRED API v2)`, url: `${API_V2}release/observations?${q}` });
328
+ }
329
+ const seen = new Set();
330
+ return items.filter((it) => (seen.has(it.file) ? false : (seen.add(it.file), true))); // one notes file per series
331
+ }
332
+ /** The items as src/core/manual.ts takes them ({API_KEY} where the key goes). The core scripts send a key only as
333
+ * a query parameter and make one request per item, so a v2 whole-release page (Bearer header, cursor pages) and the
334
+ * second GeoFRED step are listed with a note instead of being fetched blind. */
335
+ export function coreManualItems(s) {
336
+ return pyManualItems(s).map((it) => {
337
+ const url = it.url.replace("__FRED_KEY__", "{API_KEY}");
338
+ if (it.bearer) {
339
+ return { name: it.file, url, filename: it.file, needs_key: false, method: "GET", optional: true,
340
+ note: `${it.what}: FRED API v2 takes the key as an "Authorization: Bearer" header, which this script does not send ` +
341
+ "(the request answers HTTP 401 without it). Download it where a key is set up (fetch with a key), saving page 2 " +
342
+ `on as release_${it.file.slice(8, -5)}__p02.json and so on.` };
343
+ }
344
+ if (it.then) {
345
+ return { name: it.file, url, filename: it.file, needs_key: true, method: "GET", optional: false,
346
+ note: `${it.what} (step 1 of 2): the cross-section ${it.then.file} needs this reply's series_group, region_type, ` +
347
+ "season, units, frequency and max_date. Put series_group in the spec's regional block to download it in one step." };
348
+ }
349
+ return { name: it.file, url, filename: it.file, needs_key: it.keyed, method: "GET", optional: false, note: it.what };
350
+ });
351
+ }
352
+ // --------------------------------------------------------------------------- download
353
+ /** GeoFRED's series-group frequency ("a", "Annual", "Semiannual", "bw" ...) as the regional/data code (d, w, bw, m, q,
354
+ * sa, a). The first letter alone turns "sa" into "s" and "bw" into "b". */
355
+ export function geoFreq(f) {
356
+ const s = pyStrip(pstr(truthy(f) ? f : "a")).toLowerCase();
357
+ if (FREQS.includes(s))
358
+ return s;
359
+ const words = [["daily", "d"], ["weekly", "w"], ["biweekly", "bw"], ["monthly", "m"], ["quarterly", "q"],
360
+ ["semiannual", "sa"], ["annual", "a"]];
361
+ return words.find(([w]) => s.replaceAll("-", "").startsWith(w))?.[1] ?? "a";
362
+ }
363
+ export function vintageLabel(x, rtStart = "", column = "") {
364
+ const k = x.vintage.kind;
365
+ if (k === "latest")
366
+ return "latest";
367
+ if (k === "first_release")
368
+ return "first_release";
369
+ if (k === "all")
370
+ return rtStart;
371
+ const m = /_(\d{8})$/.exec(column);
372
+ return m ? `${m[1].slice(0, 4)}-${m[1].slice(4, 6)}-${m[1].slice(6)}` : "";
373
+ }
374
+ export function newParts(calls) {
375
+ return { obs: [], meta: new Map(), raw: [], regional: [], problems: [], calls, release_dates: [], release_series: [],
376
+ release_obs: [], notes: [] };
377
+ }
378
+ /** The series' copyright tag ("copyrighted: citation required" ...), "" when the tags cannot be read. */
379
+ export async function seriesCopyrightTag(c, sid) {
380
+ try {
381
+ return copyrightTagOf(await c.get("series/tags", { series_id: sid }));
382
+ }
383
+ catch (e) {
384
+ if (isFatal(e) || !(e instanceof FredError))
385
+ throw e;
386
+ return "";
387
+ }
388
+ }
389
+ /** A per-series failure becomes a problem; auth, network, rate and outage failures stop the run. */
390
+ function problem(e, parts, what) {
391
+ if (isFatal(e) || !(e instanceof FredError))
392
+ throw e;
393
+ parts.problems.push(`${what}: ${e.message}`);
394
+ }
395
+ /** Everything through the API. Returns the collected parts for packageData(). */
396
+ export async function fetchApi(s, c) {
397
+ const parts = newParts(c.calls);
398
+ const sources = new Map();
399
+ for (const x of s.series) {
400
+ const sid = x.id;
401
+ try {
402
+ if (!parts.meta.has(sid)) {
403
+ const m = await c.series(sid);
404
+ const rel = await c.releaseOf(sid);
405
+ const rid = rel.id ?? null;
406
+ if (rid !== null && !sources.has(rid))
407
+ sources.set(rid, await c.releaseSources(rid));
408
+ const srcs = sources.get(rid) || [];
409
+ const ctag = await seriesCopyrightTag(c, sid);
410
+ Object.assign(m, { release: rel.name ?? "", release_id: rid, copyright_tag: ctag,
411
+ source: srcs.filter((z) => truthy(z.name)).map((z) => z.name ?? "").join("; "), metadata_source: "api" });
412
+ parts.meta.set(sid, m);
413
+ parts.raw.push({ name: `${sid}__series.json`, request: `series, series/release, release/sources for ${sid}`,
414
+ response: { seriess: [m] } });
415
+ }
416
+ const p = { observation_start: x.start, observation_end: x.end, units: x.units,
417
+ frequency: x.frequency, aggregation_method: x.aggregation_method };
418
+ const k = x.vintage.kind;
419
+ if (k === "as_of")
420
+ p.vintage_dates = x.vintage.dates.join(",");
421
+ else if (k === "first_release") { // needs the whole real-time window (checked live 2026-10-20)
422
+ Object.assign(p, { output_type: 4, realtime_start: "1776-07-04", realtime_end: "9999-12-31" });
423
+ }
424
+ else if (k === "all")
425
+ Object.assign(p, { realtime_start: "1776-07-04", realtime_end: "9999-12-31" });
426
+ const obs = await c.observations(sid, p);
427
+ parts.raw.push({ name: `${tag(x)}.json`, request: c.calls[c.calls.length - 1], response: { observations: obs } });
428
+ let rows = observationRows(sid, obs);
429
+ if (k === "as_of") { // assign each real-time period to the vintages it covers
430
+ const exp = [];
431
+ for (const r of rows) {
432
+ for (const v of x.vintage.dates) {
433
+ if (r.realtime_start <= v && (!r.realtime_end || v <= r.realtime_end))
434
+ exp.push({ ...r, vintage: v });
435
+ }
436
+ }
437
+ rows = exp;
438
+ }
439
+ else
440
+ for (const r of rows)
441
+ r.vintage = vintageLabel(x, r.realtime_start);
442
+ parts.obs.push([x, rows]);
443
+ }
444
+ catch (e) {
445
+ problem(e, parts, tag(x));
446
+ }
447
+ }
448
+ for (let j = 1; j <= s.regional.length; j++) {
449
+ const rb = s.regional[j - 1];
450
+ try {
451
+ const p = omit(rb, ["label", "series_id"]);
452
+ if (!has(p, "series_group")) {
453
+ const grp = await c.seriesGroup(rb.series_id);
454
+ p.series_group = grp.series_group ?? null;
455
+ for (const k of ["region_type", "season", "units"])
456
+ if (!has(p, k))
457
+ p[k] = grp[k] ?? null;
458
+ if (!has(p, "frequency"))
459
+ p.frequency = geoFreq(grp.frequency);
460
+ if (!has(p, "date"))
461
+ p.date = grp.max_date ?? null;
462
+ }
463
+ const payload = await c.regional(p);
464
+ parts.raw.push({ name: `regional_${String(j).padStart(2, "0")}.json`, request: c.calls[c.calls.length - 1], response: payload });
465
+ for (const r of regionalRows(payload)) {
466
+ parts.regional.push({ group: p.series_group, label: get(rb, "label", ""), ...r, units: get(p, "units", ""),
467
+ season: get(p, "season", ""), frequency: get(p, "frequency", "") });
468
+ }
469
+ }
470
+ catch (e) {
471
+ problem(e, parts, `regional block ${j}`);
472
+ }
473
+ }
474
+ const rd = s.release_dates;
475
+ if (rd) {
476
+ try {
477
+ const j = await c.releaseDates(rd.release_id, rd.start, rd.end, rd.limit);
478
+ parts.raw.push({ name: "release_dates.json", request: c.calls[c.calls.length - 1], response: j });
479
+ parts.release_dates = releaseDateRows(j);
480
+ if (rd.release_id && parts.release_dates.some((r) => !truthy(r.release_name))) {
481
+ let name = "";
482
+ try { // release/dates for one release carries no name: look it up once
483
+ const rel = await c.get("release", { release_id: rd.release_id });
484
+ name = ((rel.releases && rel.releases.length ? rel.releases : [{}])[0]).name ?? "";
485
+ }
486
+ catch (e) {
487
+ if (isFatal(e) || !(e instanceof FredError))
488
+ throw e;
489
+ name = "";
490
+ }
491
+ for (const r of parts.release_dates)
492
+ r.release_name = truthy(r.release_name) ? r.release_name : name;
493
+ }
494
+ if (pyInt(truthy(j.count) ? j.count : 0) > parts.release_dates.length) {
495
+ parts.problems.push(`release_dates: ${pstr(j.count ?? null)} dates exist, ${parts.release_dates.length} kept (limit ` +
496
+ `${rd.limit}); narrow start/end or raise limit`);
497
+ }
498
+ }
499
+ catch (e) {
500
+ problem(e, parts, "release_dates");
501
+ }
502
+ }
503
+ for (const ro of s.release_observations) {
504
+ try {
505
+ const [rel, series] = await c.releaseObservations(ro.release_id, ro.limit, ro.max_pages);
506
+ parts.raw.push({ name: `release_${ro.release_id}.json`, request: c.calls[c.calls.length - 1],
507
+ response: { release: rel, series } });
508
+ addReleaseRows(parts, ro, rel, series);
509
+ }
510
+ catch (e) {
511
+ problem(e, parts, `release ${ro.release_id} observations`);
512
+ }
513
+ }
514
+ return parts;
515
+ }
516
+ export function releaseDateRows(j) {
517
+ return (j.release_dates || []).map((d) => ({ release_id: get(d, "release_id", ""), release_name: get(d, "release_name", ""),
518
+ date: get(d, "date", "") }));
519
+ }
520
+ /** Uploaded v2 release/observations pages in order (one file per page, or one merged reply) -> [release, series], as
521
+ * FredClient.releaseObservations returns them. A page can end inside a series: the next page continues it. */
522
+ export function mergeReleasePages(pages) {
523
+ let release = {};
524
+ const series = [];
525
+ for (const j of pages) {
526
+ if (!truthy(release))
527
+ release = { ...(j.release || {}) };
528
+ for (const x of j.series || []) {
529
+ if (series.length && series[series.length - 1].series_id === x.series_id) {
530
+ const last = series[series.length - 1];
531
+ last.observations = [...(last.observations || []), ...(x.observations || [])];
532
+ }
533
+ else
534
+ series.push({ ...x });
535
+ }
536
+ }
537
+ const last = pages.length ? pages[pages.length - 1] : {};
538
+ if (has(last, "has_more")) { // a raw page; a merged reply keeps these in its release
539
+ const cursor = truthy(last.has_more) ? last.next_cursor : null;
540
+ Object.assign(release, { has_more: truthy(cursor), next_cursor: truthy(cursor) ? cursor : "" });
541
+ }
542
+ return [release, series];
543
+ }
544
+ const floatCell = (v) => (v === null ? "" : pyFloatRepr(v));
545
+ /** v2 release/observations -> release_series rows (one per series, with FRED's copyright tag) and release_observations
546
+ * rows (one per series and date). */
547
+ export function addReleaseRows(parts, ro, rel, series) {
548
+ const keep = new Set(ro.series || []);
549
+ let n = 0;
550
+ for (const x of series) {
551
+ const sid = pstr(get(x, "series_id", "")).toUpperCase();
552
+ if (keep.size && !keep.has(sid))
553
+ continue;
554
+ n++;
555
+ const tg = get(x, "copyright_id", "");
556
+ const rid = get(rel, "release_id", ro.release_id);
557
+ parts.release_series.push({ release_id: rid, release: get(rel, "name", ""), series_id: sid, title: get(x, "title", ""),
558
+ units: get(x, "units", ""), frequency: get(x, "frequency", ""), seasonal_adjustment: get(x, "seasonal_adjustment", ""),
559
+ last_updated: get(x, "last_updated", ""), copyright_tag: tg,
560
+ copyright: copyrightFromTag(tg) || copyrightStatus(x.notes, true), n_obs: (x.observations || []).length });
561
+ for (const o of x.observations || []) {
562
+ parts.release_obs.push({ release_id: rid, series_id: sid, date: get(o, "date", ""), value: floatCell(parseValue(o.value)) });
563
+ }
564
+ }
565
+ if (keep.size && !n)
566
+ parts.problems.push(`release ${ro.release_id}: none of ${pyRepr([...keep].sort(cmp))} in the pages downloaded`);
567
+ if (truthy(rel.has_more)) {
568
+ parts.notes.push(`release ${ro.release_id}: stopped after max_pages=${ro.max_pages} (more pages exist; next_cursor ` +
569
+ `${pstr(rel.next_cursor ?? null)}). Raise max_pages or filter with series.`);
570
+ }
571
+ }
572
+ /** Graph-CSV columns -> observation rows. An as-of vintage ends where that vintage's data ended: the empty cells after
573
+ * its last value are dates not yet published then, not missing values. */
574
+ export function graphRows(x, cols) {
575
+ const rows = [];
576
+ for (const [col, pts0] of cols) {
577
+ const v = vintageLabel(x, "", col);
578
+ let pts = pts0;
579
+ if (x.vintage.kind === "as_of") {
580
+ let last = -1;
581
+ pts.forEach((p, i) => { if (p.value !== null)
582
+ last = i; });
583
+ pts = pts.slice(0, last + 1);
584
+ }
585
+ for (const p of pts)
586
+ rows.push({ ...p, realtime_start: "", realtime_end: "", vintage: v });
587
+ }
588
+ return rows;
589
+ }
590
+ export async function fetchKeyless(s, k) {
591
+ const parts = newParts(k.calls);
592
+ for (const need of keyOnlyNeeds(s))
593
+ parts.problems.push(`needs a FRED API key, not downloaded: ${need}`);
594
+ const ids = [...new Set(s.series.map((x) => x.id))].sort(cmp);
595
+ for (let i = 0; i < ids.length; i += GRAPH_MAX) {
596
+ const chunk = ids.slice(i, i + GRAPH_MAX);
597
+ try {
598
+ const [meta, body] = await k.metadata(chunk);
599
+ parts.raw.push({ name: `metadata_${String(i / GRAPH_MAX + 1).padStart(2, "0")}.xlsx`, request: k.calls[k.calls.length - 1], bytes: body });
600
+ for (const [sid, m] of meta) {
601
+ m.metadata_source = "fredgraph.xlsx";
602
+ parts.meta.set(sid, m);
603
+ }
604
+ }
605
+ catch (e) {
606
+ if ((e instanceof FredError && e.fk === "network") || !(e instanceof FredError))
607
+ throw e;
608
+ parts.problems.push(`metadata for ${chunk.join(", ")}: ${e.message}`);
609
+ }
610
+ }
611
+ for (const x of s.series) {
612
+ if (x.vintage.kind !== "latest" && x.vintage.kind !== "as_of")
613
+ continue;
614
+ const chunks = vintageChunks(x);
615
+ const rows = [];
616
+ for (let n = 1; n <= chunks.length; n++) {
617
+ const dates = chunks[n - 1];
618
+ let cols, body, lastMod;
619
+ try {
620
+ [cols, body, lastMod] = await k.csv(x.id, { start: x.start, end: x.end, frequency: x.frequency,
621
+ aggregation_method: x.aggregation_method, units: x.units, vintage_dates: dates });
622
+ }
623
+ catch (e) {
624
+ if ((e instanceof FredError && e.fk === "network") || !(e instanceof FredError))
625
+ throw e;
626
+ parts.problems.push(x.id + (dates ? ` vintages ${dates[0]} to ${dates[dates.length - 1]}` : "") + `: ${e.message}`);
627
+ continue;
628
+ }
629
+ parts.raw.push({ name: chunkFile(x, n, chunks.length), request: k.calls[k.calls.length - 1], bytes: body });
630
+ rows.push(...graphRows(x, cols));
631
+ if (lastMod && parts.meta.has(x.id)) {
632
+ const m = parts.meta.get(x.id);
633
+ if (!has(m, "http_last_modified"))
634
+ m.http_last_modified = lastMod;
635
+ }
636
+ }
637
+ if (rows.length)
638
+ parts.obs.push([x, rows]);
639
+ if (x.vintage.kind === "as_of") {
640
+ const got = new Set(rows.map((r) => r.vintage));
641
+ const missing = [...new Set(x.vintage.dates)].filter((d) => !got.has(d)).sort(cmp);
642
+ if (missing.length)
643
+ parts.problems.push(`${x.id}: no data for as-of vintage(s) ${missing.join(", ")}`);
644
+ }
645
+ }
646
+ return parts;
647
+ }
648
+ // --------------------------------------------------------------------------- package
649
+ /** csv.DictWriter: the header, then each row's fields (None empty, extras ignored); no fields = an empty header line. */
650
+ function writeCsvFile(file, rows, fields) {
651
+ const cols = fields ?? [...new Set(rows.flatMap((r) => Object.keys(r)))];
652
+ if (!cols.length) {
653
+ fs.writeFileSync(file, "\r\n".repeat(1 + rows.length));
654
+ return cols;
655
+ }
656
+ fs.writeFileSync(file, writeCsv(rows.map((r) => Object.fromEntries(cols.map((c) => [c, cell(r[c])]))), cols));
657
+ return cols;
658
+ }
659
+ export const CREDIT = "Data from FRED\u00ae, Federal Reserve Bank of St. Louis (downloaded without the API); this product is " +
660
+ "not endorsed or certified by the Federal Reserve Bank of St. Louis.";
661
+ /** Last day of the period an observation stands for: FRED dates most periods by their first day (2026-10-01 = 2026 Q4,
662
+ * which has not ended on 2026-10-20) and fiscal-year dollar series by their last day. */
663
+ export function periodEndIso(d, dated) {
664
+ if (!d || d.slice(8, 10) !== "01" || dated.length < 2)
665
+ return d;
666
+ const days = daysBetween(dated[0], dated[1]);
667
+ if (Number.isNaN(days))
668
+ throw new PyValueError(`Invalid isoformat string: ${pyRepr(Number.isNaN(daysBetween(dated[0], dated[0])) ? dated[0] : dated[1])}`);
669
+ if (days < 28)
670
+ return d; // daily, weekly, biweekly: the date is the observation itself
671
+ const step = roundHalfEven(days / 30.4);
672
+ if (![1, 3, 6, 12].includes(step))
673
+ return d;
674
+ let y = Number(d.slice(0, 4)), mth = Number(d.slice(5, 7)) + step;
675
+ [y, mth] = [y + Math.floor((mth - 1) / 12), ((mth - 1) % 12) + 1];
676
+ return dayBeforeFirst(y, mth);
677
+ }
678
+ export const TRANSFORM_UNITS = { chg: "Change", ch1: "Change from Year Ago", pch: "Percent Change",
679
+ pc1: "Percent Change from Year Ago", pca: "Compounded Annual Rate of Change", cch: "Continuously Compounded Rate of Change",
680
+ cca: "Continuously Compounded Annual Rate of Change", log: "Natural Log" };
681
+ /** Federal fiscal-year series: FRED says so in the frequency ("Annual, Fiscal Year"), and the annual OMB/Treasury series
682
+ * it does not label (FYOIGDA188S, FYFSGDA188S ...) start with FY. */
683
+ export function isFiscal(m, sid = "") {
684
+ const t = ["frequency", "sheet", "title", "notes"].map((k) => pstr(get(m, k, ""))).join(" ");
685
+ if (t.toLowerCase().includes("fiscal year"))
686
+ return true;
687
+ return sid.toUpperCase().startsWith("FY") && pstr(get(m, "frequency", "")).toLowerCase().startsWith("annual");
688
+ }
689
+ /** Lines in a text file, as Python's `for _ in open(f)` counts them (universal newlines). */
690
+ function lineCount(file) {
691
+ const t = fs.readFileSync(file, "utf8");
692
+ if (!t)
693
+ return 0;
694
+ const n = t.split(/\r\n|\r|\n/).length;
695
+ return /(\r\n|\r|\n)$/.test(t) ? n - 1 : n;
696
+ }
697
+ const sha256File = (file) => createHash("sha256").update(fs.readFileSync(file)).digest("hex");
698
+ export function packageData(pack, parts, s, out, route, acquired, retrieved = null, n0 = 0) {
699
+ const P = pack.policy;
700
+ const d = dataDir(out);
701
+ const rawDir = path.join(d, "raw");
702
+ fs.rmSync(rawDir, { recursive: true, force: true });
703
+ fs.mkdirSync(rawDir, { recursive: true });
704
+ for (const x of parts.raw) {
705
+ const p = path.join(rawDir, x.name);
706
+ if (x.bytes)
707
+ fs.writeFileSync(p, x.bytes);
708
+ else
709
+ fs.writeFileSync(p, keys.redact(dumpsIndent({ request: x.request, response: x.response }, 1)));
710
+ }
711
+ const now = retrieved || nowIso();
712
+ const today = localToday();
713
+ const rows = [];
714
+ const problems = [...parts.problems];
715
+ for (const [x, obs] of parts.obs) {
716
+ if (!obs.length)
717
+ problems.push(`${x.id}: no observations returned for ${x.start || "start"} to ${x.end || "latest"}`);
718
+ for (const o of obs) {
719
+ rows.push({ series_id: x.id, label: x.label, variant: tag(x), vintage: o.vintage, date: o.date,
720
+ value: floatCell(o.value), realtime_start: o.realtime_start ?? "", realtime_end: o.realtime_end ?? "" });
721
+ }
722
+ }
723
+ const sk = (r) => [r.series_id, r.variant, r.vintage, r.date].map((v) => pstr(v));
724
+ rows.sort((a, b) => cmpTuple(sk(a), sk(b)));
725
+ const columns = {};
726
+ columns.fred_observations = writeCsvFile(path.join(d, "fred_observations.csv"), rows, ["series_id", "label", "variant", "vintage", "date", "value", "realtime_start", "realtime_end"]);
727
+ const regionalPath = path.join(d, "regional.csv");
728
+ if (parts.regional.length) {
729
+ columns.regional = writeCsvFile(regionalPath, parts.regional.map((r) => ({ ...r,
730
+ value: r.value === null || typeof r.value === "number" ? floatCell(r.value) : r.value })), ["group", "label", "title", "date", "region", "code", "series_id", "value", "units", "season", "frequency"]);
731
+ }
732
+ else
733
+ fs.rmSync(regionalPath, { force: true });
734
+ for (const [name, key, cols] of [
735
+ ["release_dates", "release_dates", ["release_id", "release_name", "date"]],
736
+ ["release_series", "release_series", ["release_id", "release", "series_id", "title", "units", "frequency",
737
+ "seasonal_adjustment", "last_updated", "copyright_tag", "copyright", "n_obs"]],
738
+ ["release_observations", "release_obs", ["release_id", "series_id", "date", "value"]],
739
+ ]) {
740
+ const p = path.join(d, `${name}.csv`);
741
+ const list = parts[key];
742
+ if (list.length)
743
+ columns[name] = writeCsvFile(p, list, cols);
744
+ else
745
+ fs.rmSync(p, { force: true });
746
+ }
747
+ const metaRows = [];
748
+ for (const x of s.series) {
749
+ const m = parts.meta.get(x.id) || {};
750
+ const mine = rows.filter((r) => r.variant === tag(x));
751
+ const dated = [...new Set(mine.map((r) => r.date))].sort(cmp); // vintages repeat dates
752
+ const fromApi = m.metadata_source === "api";
753
+ const notes = pyStrip(pstr(truthy(m.notes) ? m.notes : ""));
754
+ const title = get(m, "title", "");
755
+ if (!Object.keys(m).length)
756
+ problems.push(`${x.id}: no metadata (title, units) could be read; check the ID`);
757
+ const mUnits = get(m, "units", "");
758
+ const u = x.units || "lin";
759
+ const source = truthy(get(m, "source", "")) ? m.source : x.source ?? "";
760
+ metaRows.push({
761
+ series_id: x.id, label: x.label, variant: tag(x),
762
+ vintage: x.vintage.kind + (x.vintage.dates.length ? ":" + x.vintage.dates.join(",") : ""),
763
+ title, units: (u !== "lin" ? (TRANSFORM_UNITS[u] ?? "") + ` (of ${pstr(mUnits)})` : cell(mUnits)) +
764
+ (x.vintage.kind !== "latest" && truthy(mUnits)
765
+ ? " (as FRED labels the series today; this vintage may use an earlier base year or definition)" : ""),
766
+ frequency: get(m, "frequency", ""), seasonal_adjustment: get(m, "seasonal_adjustment", ""),
767
+ last_updated: get(m, "last_updated", ""), fiscal_year: isFiscal(m, x.id) ? 1 : 0, transformation: x.units || "",
768
+ converted_to: x.frequency ? `${x.frequency} (${x.aggregation_method || "avg"})` : "",
769
+ first_date: dated.length ? dated[0] : "", last_date: dated.length ? dated[dated.length - 1] : "",
770
+ n_obs: mine.length, n_missing: mine.filter((r) => r.value === "").length,
771
+ n_future: mine.filter((r) => periodEndIso(r.date, dated) > today).length,
772
+ source, release: get(m, "release", ""),
773
+ copyright: x.copyright || copyrightFromTag(m.copyright_tag) || copyrightStatus(notes, fromApi),
774
+ copyright_basis: truthy(x.copyright_basis) ? x.copyright_basis : truthy(m.copyright_tag)
775
+ ? `series tag "${pstr(m.copyright_tag)}" (FRED API)` : fromApi ? "series notes (FRED API)" : "",
776
+ metadata_source: get(m, "metadata_source", ""),
777
+ citation: citation(x.id, truthy(title) ? pstr(title) : "", truthy(source) ? pstr(source) : "", now),
778
+ notes: [...notes.replace(PY_SPACE, " ")].slice(0, 600).join(""),
779
+ });
780
+ }
781
+ columns.series = writeCsvFile(path.join(d, "series.csv"), metaRows);
782
+ const latest = {};
783
+ const byVariant = new Map();
784
+ for (const r of rows) {
785
+ if (!byVariant.has(r.variant))
786
+ byVariant.set(r.variant, new Set());
787
+ byVariant.get(r.variant).add(r.date);
788
+ }
789
+ const firstTwo = new Map([...byVariant].map(([v, ds]) => [v, [...ds].sort(cmp).slice(0, 2)]));
790
+ for (const r of rows) {
791
+ if (r.value !== "" && (r.vintage === "latest" || r.vintage === "first_release") &&
792
+ periodEndIso(r.date, firstTwo.get(r.variant)) <= today) { // an in-progress quarter is not data
793
+ const prev = latest[r.variant] ?? "";
794
+ latest[r.variant] = prev > r.date ? prev : r.date;
795
+ }
796
+ }
797
+ const tables = [];
798
+ for (const name of ["fred_observations", "series", "regional", "release_dates", "release_series", "release_observations"]) {
799
+ const p = path.join(d, `${name}.csv`);
800
+ if (fs.existsSync(p))
801
+ tables.push({ name, file: `${name}.csv`, rows: Math.max(0, lineCount(p) - 1), sha256: sha256File(p) });
802
+ }
803
+ const req = { source: SOURCE, fingerprint: fingerprint(s), meta_fingerprint: metaFingerprint(s),
804
+ retrieved: retrieved || now, route, acquired,
805
+ keyless: route !== "api" && ![...parts.meta.values()].some((m) => m.metadata_source === "api"),
806
+ spec: s, requests: parts.calls.map((u) => keys.redact(u)), n_requests: parts.calls.length,
807
+ request_log: trail().slice(n0), tables, notes: parts.notes, problems, latest, rows: rows.length,
808
+ regional_rows: parts.regional.length, release_rows: parts.release_obs.length,
809
+ release_date_rows: parts.release_dates.length,
810
+ policy: { redistribution: P.redistribution.mode, cache: P.cache.mode } };
811
+ fs.writeFileSync(path.join(d, "request.json"), keys.redact(dumpsIndent(req, 2)));
812
+ writeReadme(pack, d, s, metaRows, rows, req);
813
+ return { req, columns, meta: metaRows };
814
+ }
815
+ const commas = (n) => n.toLocaleString("en-US");
816
+ export function writeReadme(pack, d, s, meta, rows, req) {
817
+ const P = pack.policy;
818
+ const keyless = req.keyless;
819
+ const m0 = (m, k) => pstr(m[k] ?? null);
820
+ const lines = [
821
+ `# FRED data: ${truthy(s.description) ? pstr(s.description) : meta.map((m) => m0(m, "series_id")).join(", ")}`,
822
+ "",
823
+ `- Retrieved: ${pol.localStamp(req.retrieved)} (${pstr(req.acquired)}; route \`${pstr(req.route)}\`)`,
824
+ `- Rows: ${commas(rows.length)} in \`fred_observations.csv\` (one per series variant, vintage and date); series ` +
825
+ "details in `series.csv`" + (truthy(req.regional_rows) ? "; GeoFRED cross-sections in `regional.csv`" : ""),
826
+ "- Raw responses: `raw/`; the exact requests (without the key): `request.json`" +
827
+ (truthy(req.release_date_rows) ? "; release calendar in `release_dates.csv`" : "") +
828
+ (truthy(req.release_rows) ? "; whole-release downloads in `release_observations.csv` and `release_series.csv`" : ""),
829
+ "",
830
+ "## Series",
831
+ "| Series ID | Label | Title | Units | Freq | SA | Vintage | Dates | Missing | Future | Updated | Copyright |",
832
+ "|---|---|---|---|---|---|---|---|---|---|---|---|",
833
+ ...meta.map((m) => `| \`${m0(m, "series_id")}\` | ${m0(m, "label")} | ${m0(m, "title")} | ${m0(m, "units")} | ${m0(m, "frequency")}` +
834
+ `${truthy(m.fiscal_year) && !m0(m, "frequency").toLowerCase().includes("fiscal") ? " (fiscal year)" : ""} | ` +
835
+ `${m0(m, "seasonal_adjustment")} | ${m0(m, "vintage")} | ${m0(m, "first_date")} to ${m0(m, "last_date")} (${m0(m, "n_obs")}) | ` +
836
+ `${m0(m, "n_missing")} | ${m0(m, "n_future")} | ${m0(m, "last_updated")} | ${m0(m, "copyright")} |`),
837
+ "",
838
+ "## Read this before analyzing",
839
+ "- `value` is empty where FRED has no value (`.` in the API): a day without trading, a month not collected " +
840
+ "(October 2025 for the CPI, CPS and LAUS). A change across a gap needs both endpoints.",
841
+ "- **Future dates are projections, not data.** `n_future` > 0 (for example CBO's GDPPOT, NGDPPOT and NROU run 10 " +
842
+ "years ahead): cut those series at the last actual date of the series you compare them with.",
843
+ "- **Fiscal years.** `fiscal_year` = 1 marks federal fiscal-year series (October to September). FRED dates dollar " +
844
+ "amounts at the end of the fiscal year (2025-09-30 = FY2025) and some percent-of-GDP series at January 1 of the fiscal " +
845
+ "year's number (2025-01-01 = FY2025): label each value by the fiscal year it belongs to.",
846
+ "- `variant` names any FRED-side conversion (`_pc1`, `_qavg` ...). FRED's own frequency conversion averages whatever " +
847
+ "observations exist, so a quarter with a missing month still gets a value; prefer native-frequency data and " +
848
+ "convert it yourself, dropping incomplete periods.",
849
+ "- `vintage` is `latest`, an as-of date (ALFRED: the data as published on that date), `first_release`, or for full " +
850
+ "histories the date a value was first published (`realtime_start`).",
851
+ ];
852
+ if (keyless) {
853
+ lines.push("- These data came from FRED's keyless graph downloads: `source` and `copyright` are not known. Read them " +
854
+ "on each series page (links in the citations) before publishing.");
855
+ }
856
+ for (const m of meta) { // FRED posts some series late at the publisher's request (UMCSENT: one month)
857
+ const late = /[^.]*\b(?:delayed|embargoed)\b[^.]*\.?/i.exec(pstr(truthy(m.notes) ? m.notes : ""));
858
+ if (late) {
859
+ lines.push(`- **\`${m0(m, "series_id")}\` reaches FRED late:** "${pyStrip(late[0])}" The publisher's own site has ` +
860
+ "newer values: when the question asks for the latest, read them there, save them in published/ with source_url " +
861
+ "and accessed, and say which month FRED ends on.");
862
+ }
863
+ }
864
+ if (truthy(req.regional_rows)) {
865
+ lines.push("- **`regional.csv` (GeoFRED):** one row per region and date; `units`, `season` and `frequency` as " +
866
+ "requested. `title` is GeoFRED's group title and can name another month than `date` (\"2026 September ... \" for " +
867
+ "2026-08-01 data): trust `date`. The regional series are not in `series.csv`: cite GeoFRED with the group title and " +
868
+ "retrieval date, and the source agency named on any one series page (e.g. BLS LAUS for state unemployment rates); " +
869
+ "recent LAUS months are preliminary.");
870
+ }
871
+ if (truthy(req.notes))
872
+ lines.push("", "## Notes", ...req.notes.map((n) => `- ${n}`));
873
+ if (truthy(req.problems))
874
+ lines.push("", "## Problems", ...req.problems.map((p) => `- ${p}`));
875
+ const pre = meta.filter((m) => m.copyright === "preapproval_required");
876
+ lines.push("", "## Reading the data", "```python", "import pandas as pd", "df = pd.read_csv('fred_observations.csv', parse_dates=['date'])", "w = df[df.vintage == 'latest'].pivot(index='date', columns='variant', values='value')", "```", "", "## Citations", ...[...new Set(meta.map((m) => m0(m, "citation")))].map((c) => `- ${c}`), "", "## FRED terms of use", req.route === "api" ? NOTICE : CREDIT, "", `FRED's terms (${TERMS_URL}, ${LEGAL_URL}) require each user to use their own API key, forbid wholesale downloading ` +
877
+ "and building an archive of FRED content, and ask that each series be cited. Series whose notes carry a copyright " +
878
+ "(`copyright` = preapproval_required) need the owner's permission before they are redistributed; public-domain series " +
879
+ "may be shared with a citation. An `unknown` status must be checked on the series page before the data are shared." +
880
+ (!pre.length ? "" : " **Pre-approval required here:** " + pre.map((m) => `\`${m0(m, "series_id")}\``).join(", ") +
881
+ ": say in the answer that these values may not be republished without the owner's permission."), "", "## Use and redistribution", `Rule: **${P.redistribution.mode}**. ${P.redistribution.why ?? ""} Cache: **${P.cache.mode}** (${P.cache.why ?? ""})`);
882
+ fs.writeFileSync(path.join(d, "README.md"), lines.join("\n") + "\n");
883
+ }
884
+ // --------------------------------------------------------------------------- ingest uploaded files
885
+ const OWN_CSVS = new Set(["fred_observations.csv", "series.csv", "regional.csv", "release_dates.csv", "release_series.csv",
886
+ "release_observations.csv", "data_dictionary.csv"]);
887
+ function walk(dir) {
888
+ const out = [];
889
+ for (const n of fs.readdirSync(dir)) {
890
+ const p = path.join(dir, n);
891
+ if (fs.statSync(p).isDirectory())
892
+ out.push(...walk(p));
893
+ else
894
+ out.push(p);
895
+ }
896
+ return out;
897
+ }
898
+ /** Package files the user downloaded (graph CSV/XLSX, API JSON as the download scripts or the API route saved them:
899
+ * wrapped as {"request", "response"} or the API's own reply). */
900
+ export function ingest(pack, paths, s, out, route = "manual_download", acquired = "downloaded by the user and uploaded", retrieved = null) {
901
+ const files = [];
902
+ for (const p of paths) {
903
+ if (fs.existsSync(p) && fs.statSync(p).isDirectory())
904
+ files.push(...walk(p).sort(cmp));
905
+ else if (fs.existsSync(p))
906
+ files.push(p);
907
+ else
908
+ throw new FredError(`Not found: ${p}`, "request");
909
+ }
910
+ const byTag = new Map(s.series.map((x) => [tag(x), x]));
911
+ const parts = newParts([]);
912
+ const got = new Map();
913
+ const apiObs = new Map(), groups = [];
914
+ const releasePages = new Map();
915
+ for (const fp of files) {
916
+ const name = path.basename(fp);
917
+ const low = name.toLowerCase();
918
+ const body = fs.readFileSync(fp);
919
+ try {
920
+ if (low.endsWith(".xlsx")) {
921
+ for (const [sid, m] of parseGraphXlsx(body)) {
922
+ m.metadata_source = "fredgraph.xlsx";
923
+ if (!parts.meta.has(sid))
924
+ parts.meta.set(sid, m);
925
+ }
926
+ parts.raw.push({ name, request: "uploaded", bytes: body });
927
+ }
928
+ else if (low.endsWith(".csv") || low.endsWith(".zip")) {
929
+ if (OWN_CSVS.has(name))
930
+ continue;
931
+ const cols = parseGraphCsv(body);
932
+ const t = path.parse(name).name.replace(/_p\d+$/, ""); // vintage chunk files <tag>_pN.csv
933
+ const x = byTag.get(t) ?? s.series.find((v) => [...cols.keys()].some((c) => c === v.id || c.startsWith(v.id + "_")));
934
+ if (!x)
935
+ continue; // no spec series matches its columns: skipped
936
+ if (!got.has(tag(x)))
937
+ got.set(tag(x), []);
938
+ got.get(tag(x)).push(...graphRows(x, cols));
939
+ parts.raw.push({ name, request: "uploaded", bytes: body });
940
+ }
941
+ else if (low.endsWith(".json")) {
942
+ const j = parsePyJson(body.toString("utf8").replace(/^\ufeff/, ""));
943
+ if (!isDict(j) || name === "manifest.json" || name === "request.json")
944
+ continue;
945
+ const wrapped = has(j, "response");
946
+ const resp = wrapped ? j.response : j;
947
+ if (!isDict(resp))
948
+ continue;
949
+ parts.raw.push({ name, request: wrapped ? keys.redact(pstr(get(j, "request", ""))) : "uploaded", response: resp });
950
+ if (has(resp, "seriess")) {
951
+ const m = resp.seriess[0];
952
+ m.metadata_source = "api";
953
+ parts.meta.set(pstr(m.id).toUpperCase(), m);
954
+ }
955
+ else if (has(resp, "observations"))
956
+ apiObs.set(path.parse(name).name, resp.observations);
957
+ else if (has(resp, "series_group"))
958
+ groups.push(name);
959
+ else if (has(resp, "release_dates"))
960
+ parts.release_dates = releaseDateRows(resp);
961
+ else if (has(resp, "series") && has(resp, "release")) { // v2 pages: release_<id>.json, __p02.json, ...
962
+ const m = /__p(\d+)\.json$/.exec(low);
963
+ const rid = (resp.release || {}).release_id ?? null;
964
+ if (!releasePages.has(rid))
965
+ releasePages.set(rid, []);
966
+ releasePages.get(rid).push([m ? Number(m[1]) : 1, resp]);
967
+ }
968
+ else
969
+ parts.regional.push(...regionalRows(resp).map((r) => ({ group: "", label: "", ...r })));
970
+ }
971
+ }
972
+ catch (e) {
973
+ parts.problems.push(`${name}: could not read (${e?.message ?? e})`);
974
+ }
975
+ }
976
+ for (const [rid, pages] of releasePages) {
977
+ const [rel, series] = mergeReleasePages([...pages].sort((a, b) => a[0] - b[0]).map(([, r]) => r));
978
+ const ro = s.release_observations.find((r) => r.release_id === rid) ??
979
+ { release_id: rid, series: [], max_pages: pages.length };
980
+ addReleaseRows(parts, ro, rel, series);
981
+ }
982
+ if (groups.length && !parts.regional.length) {
983
+ parts.problems.push(`${groups.join(", ")}: a GeoFRED group lookup but no cross-section; download regional_NN.json ` +
984
+ "(the regional/data reply for that group) too, or give the regional block a series_group, then ingest again");
985
+ }
986
+ for (const [t, obs] of apiObs) {
987
+ const x = byTag.get(t);
988
+ if (x)
989
+ got.set(t, observationRows(x.id, obs).map((r) => ({ ...r, vintage: vintageLabel(x, r.realtime_start) })));
990
+ }
991
+ for (const x of s.series) {
992
+ if (got.has(tag(x)))
993
+ parts.obs.push([x, got.get(tag(x))]);
994
+ else
995
+ parts.problems.push(`${x.id} (${tag(x)}): no uploaded file holds it`);
996
+ }
997
+ if (!got.size && !parts.regional.length && !parts.release_dates.length && !parts.release_obs.length) {
998
+ throw new FredError("None of the uploaded files holds FRED data for this spec.", "request");
999
+ }
1000
+ parts.calls = route === "manual_download" ? pyManualItems(s).map((f) => f.url) : [];
1001
+ return packageData(pack, parts, s, out, route, acquired, retrieved);
1002
+ }
1003
+ /** Labels, sources or copyright changed in the spec, the data did not: rebuild data/fred/ from data/fred/raw/ without
1004
+ * downloading again, keeping the original route and retrieval time. */
1005
+ export function repackage(pack, s, out) {
1006
+ const raw = path.join(dataDir(out), "raw");
1007
+ const tmp = path.join(dataDir(out), "_raw_prev");
1008
+ fs.rmSync(tmp, { recursive: true, force: true });
1009
+ fs.cpSync(raw, tmp, { recursive: true });
1010
+ try {
1011
+ const saved = JSON.parse(fs.readFileSync(path.join(dataDir(out), "request.json"), "utf8"));
1012
+ const res = ingest(pack, [tmp], s, out, saved.route ?? "", saved.acquired ?? "", saved.retrieved ?? null);
1013
+ res.req.requests = saved.requests ?? [];
1014
+ res.req.n_requests = saved.n_requests ?? 0;
1015
+ fs.writeFileSync(path.join(dataDir(out), "request.json"), keys.redact(dumpsIndent(res.req, 2)));
1016
+ return res;
1017
+ }
1018
+ finally {
1019
+ fs.rmSync(tmp, { recursive: true, force: true });
1020
+ }
1021
+ }
1022
+ /** The header of a CSV written here. */
1023
+ export function csvColumns(file) {
1024
+ const first = fs.readFileSync(file, "utf8").split(/\r?\n/)[0];
1025
+ return first ? parse(first)[0] ?? [] : [];
1026
+ }
1027
+ //# sourceMappingURL=_fred_pack.js.map