@adisuper94/nih-reporter 0.0.4 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aditya Subramanian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,3 +2,34 @@
2
2
 
3
3
  A TypeScript/JavaScript wrapper to call NIH reporter API
4
4
 
5
+ ## Installation
6
+
7
+ ### Deno
8
+
9
+ ```bash
10
+ deno add @jsr:@adisuper94/nih-reporter
11
+ ```
12
+
13
+ ### Node
14
+
15
+ ```bash
16
+ npm install @adisuper94/nih-reporter
17
+ ```
18
+
19
+ ## Basic Usage
20
+
21
+ ```typescript
22
+ import { NIHProjectQuery } from "@adisuper94/nih-reporter";
23
+
24
+ const nihPersonIds: number[] = [12345679, 12345678];
25
+ let query = new NIHProjectQuery();
26
+ query.setPIProfileIds(nihPersonIds).setLimit(100).setFiscalYears([2020, 2021, 2022, 2023, 2024, 2025]);
27
+ const iter = query.safeIterator();
28
+ for await (const [project, err] of iter) {
29
+ if (err) {
30
+ // Handle error
31
+ console.error(err);
32
+ continue;
33
+ }
34
+ }
35
+ ```
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { NIHProjectQuery } from "./project.js";
2
+ import type { NIHProject } from "./types.js";
3
+ export { type NIHProject, NIHProjectQuery };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,81 @@
1
+ import { type NIHProject, type NIHProjectFields } from "./types.js";
2
+ /**
3
+ * NIHProjectQuery class to query the NIH Reporter API for projects
4
+ * All methods follow the builder pattern (are chainable) and return the same instance of the class
5
+ */
6
+ declare class NIHProjectQuery {
7
+ private useRelavance;
8
+ private fiscalYears;
9
+ private includeActiveProjects;
10
+ private piProfileIds;
11
+ private excludeFields;
12
+ private offset;
13
+ private limit;
14
+ constructor();
15
+ /**
16
+ * Set query params to return projects associated with "ANY" of the PI profile IDs passed
17
+ * @param piProfileIds - The PI profile IDs to filter the projects by
18
+ */
19
+ setPIProfileIds(piProfileIds: number[]): NIHProjectQuery;
20
+ /**
21
+ * Sets query params return projects that started in "ANY" of the fiscal years entered
22
+ * @param fiscalYears - The fiscal years to filter the projects by
23
+ */
24
+ setFiscalYears(fiscalYears: number[]): NIHProjectQuery;
25
+ /**
26
+ * If sets true, it will bring the most closely matching records with the search criteria on top
27
+ * @param useRelevance - If true, use relevance scoring for the results, default is false
28
+ */
29
+ setUseRelevance(useRelevance: boolean): NIHProjectQuery;
30
+ /**
31
+ * Return the result with active projects if set to true
32
+ * @param includeActiveProjects - If true, include active projects in the result, default is false
33
+ */
34
+ setIncludeActiveProjects(includeActiveProjects: boolean): NIHProjectQuery;
35
+ /**
36
+ * Set the fields to exclude from the result
37
+ * @param excludeFields - The fields to exclude from the result
38
+ */
39
+ setExcludeFields(excludeFields: NIHProjectFields[]): NIHProjectQuery;
40
+ /**
41
+ * Add a field to exclude from the result
42
+ * @param excludeField - The field to exclude from the result
43
+ */
44
+ addExcludeField(excludeField: NIHProjectFields): NIHProjectQuery;
45
+ /**
46
+ * Remove a field to exclude from the result.
47
+ * @param excludeField - The field to remove from the exclude list
48
+ */
49
+ removeExcludeField(excludeField: string): NIHProjectQuery;
50
+ /**
51
+ * Set the number of records to return
52
+ * @param limit - The number of records to return, default is 50
53
+ */
54
+ setLimit(limit: number): NIHProjectQuery;
55
+ /**
56
+ * Set the offset for the records to return
57
+ * @param offset - The offset for the records to return, default is 0
58
+ */
59
+ setOffset(offset: number): NIHProjectQuery;
60
+ /**
61
+ * Execute the query and return the results
62
+ * @returns - The results of the query
63
+ * @throws - Error if the NIH Reporter API call fails
64
+ */
65
+ execute(): Promise<NIHProject[]>;
66
+ /**
67
+ * Creates an async iterator that will yield NIHProject objects queried from the NIH Reporter API
68
+ * @param offset to start from, by default it is 0
69
+ * @returns an async iterator that will yield NIHProject objects
70
+ * @throws Error if the NIH Reporter API call fails
71
+ */
72
+ iterator(offset?: number): AsyncGenerator<NIHProject, void, void>;
73
+ /**
74
+ * Creates a safe async iterator that will yield NIHProject objects queried from the NIH Reporter API
75
+ * @param offset to start from, by default it is 0
76
+ * @returns a safe async iterator that will yield NIHProject objects in Golang style (value, error) tuple
77
+ */
78
+ safeIterator(offset?: number): AsyncGenerator<[NIHProject?, Error?], [undefined, undefined], void>;
79
+ }
80
+ export { type NIHProject, NIHProjectQuery };
81
+ //#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AM,SAAI,GAAG,cAAc,CAAC,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC;CA6BrG;AACD,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,CAAC"}
@@ -1,6 +1,52 @@
1
1
  import { parseNIHProject } from "./types.js";
2
+ /**
3
+ * NIHProjectQuery class to query the NIH Reporter API for projects
4
+ * All methods follow the builder pattern (are chainable) and return the same instance of the class
5
+ */
2
6
  class NIHProjectQuery {
3
7
  constructor() {
8
+ Object.defineProperty(this, "useRelavance", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ Object.defineProperty(this, "fiscalYears", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ Object.defineProperty(this, "includeActiveProjects", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.defineProperty(this, "piProfileIds", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ Object.defineProperty(this, "excludeFields", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "offset", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "limit", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
4
50
  this.useRelavance = false;
5
51
  this.fiscalYears = [];
6
52
  this.includeActiveProjects = true;
@@ -10,14 +56,16 @@ class NIHProjectQuery {
10
56
  this.limit = 50;
11
57
  }
12
58
  /**
13
- * When executed, this will return projects associated with "ANY" of the PI profile IDs passed
59
+ * Set query params to return projects associated with "ANY" of the PI profile IDs passed
60
+ * @param piProfileIds - The PI profile IDs to filter the projects by
14
61
  */
15
62
  setPIProfileIds(piProfileIds) {
16
63
  this.piProfileIds = piProfileIds;
17
64
  return this;
18
65
  }
19
66
  /**
20
- * When executed, this will return projects that started in "ANY" of the fiscal years entered
67
+ * Sets query params return projects that started in "ANY" of the fiscal years entered
68
+ * @param fiscalYears - The fiscal years to filter the projects by
21
69
  */
22
70
  setFiscalYears(fiscalYears) {
23
71
  this.fiscalYears = fiscalYears;
@@ -25,7 +73,7 @@ class NIHProjectQuery {
25
73
  }
26
74
  /**
27
75
  * If sets true, it will bring the most closely matching records with the search criteria on top
28
- * Default is false
76
+ * @param useRelevance - If true, use relevance scoring for the results, default is false
29
77
  */
30
78
  setUseRelevance(useRelevance) {
31
79
  this.useRelavance = useRelevance;
@@ -33,26 +81,42 @@ class NIHProjectQuery {
33
81
  }
34
82
  /**
35
83
  * Return the result with active projects if set to true
36
- * Default is false
84
+ * @param includeActiveProjects - If true, include active projects in the result, default is false
37
85
  */
38
86
  setIncludeActiveProjects(includeActiveProjects) {
39
87
  this.includeActiveProjects = includeActiveProjects;
40
88
  return this;
41
89
  }
90
+ /**
91
+ * Set the fields to exclude from the result
92
+ * @param excludeFields - The fields to exclude from the result
93
+ */
42
94
  setExcludeFields(excludeFields) {
43
95
  this.excludeFields = excludeFields;
44
96
  return this;
45
97
  }
98
+ /**
99
+ * Add a field to exclude from the result
100
+ * @param excludeField - The field to exclude from the result
101
+ */
46
102
  addExcludeField(excludeField) {
47
103
  if (!this.excludeFields.includes(excludeField)) {
48
104
  this.excludeFields.push(excludeField);
49
105
  }
50
106
  return this;
51
107
  }
108
+ /**
109
+ * Remove a field to exclude from the result.
110
+ * @param excludeField - The field to remove from the exclude list
111
+ */
52
112
  removeExcludeField(excludeField) {
53
113
  this.excludeFields = this.excludeFields.filter((field) => field !== excludeField);
54
114
  return this;
55
115
  }
116
+ /**
117
+ * Set the number of records to return
118
+ * @param limit - The number of records to return, default is 50
119
+ */
56
120
  setLimit(limit) {
57
121
  if (limit <= 0) {
58
122
  this.limit = 50;
@@ -65,6 +129,10 @@ class NIHProjectQuery {
65
129
  }
66
130
  return this;
67
131
  }
132
+ /**
133
+ * Set the offset for the records to return
134
+ * @param offset - The offset for the records to return, default is 0
135
+ */
68
136
  setOffset(offset) {
69
137
  if (offset < 0) {
70
138
  this.offset = 0;
@@ -74,6 +142,11 @@ class NIHProjectQuery {
74
142
  }
75
143
  return this;
76
144
  }
145
+ /**
146
+ * Execute the query and return the results
147
+ * @returns - The results of the query
148
+ * @throws - Error if the NIH Reporter API call fails
149
+ */
77
150
  async execute() {
78
151
  const resp = await fetch("https://api.reporter.nih.gov/v2/projects/search", {
79
152
  method: "POST",
@@ -99,10 +172,17 @@ class NIHProjectQuery {
99
172
  const errMsg = data[0];
100
173
  throw new Error(`NIH API err_msg: ${errMsg}`);
101
174
  }
102
- const projects = results.map((raw) => parseNIHProject(raw));
175
+ const projects = results.map((p) => {
176
+ const [project, err] = parseNIHProject(p);
177
+ if (err) {
178
+ throw new Error(`NIH API parse err_msg: ${JSON.stringify(err, null, 1)}`);
179
+ }
180
+ return project;
181
+ });
103
182
  return projects;
104
183
  }
105
184
  /**
185
+ * Creates an async iterator that will yield NIHProject objects queried from the NIH Reporter API
106
186
  * @param offset to start from, by default it is 0
107
187
  * @returns an async iterator that will yield NIHProject objects
108
188
  * @throws Error if the NIH Reporter API call fails
@@ -128,6 +208,7 @@ class NIHProjectQuery {
128
208
  }
129
209
  }
130
210
  /**
211
+ * Creates a safe async iterator that will yield NIHProject objects queried from the NIH Reporter API
131
212
  * @param offset to start from, by default it is 0
132
213
  * @returns a safe async iterator that will yield NIHProject objects in Golang style (value, error) tuple
133
214
  */
@@ -1,4 +1,35 @@
1
- type NIHProject = {
1
+ interface NIHPerson {
2
+ nihPersonId: number;
3
+ firstName: string;
4
+ lastName: string;
5
+ middleName: string;
6
+ fullName: string;
7
+ isContactPI: boolean;
8
+ title?: string;
9
+ }
10
+ interface NIHOrg {
11
+ orgName: string;
12
+ city?: string;
13
+ country?: string;
14
+ orgCity: string;
15
+ orgState: string;
16
+ orgCountry?: string;
17
+ orgStateName?: string;
18
+ orgZipCode: string;
19
+ orgFips: string;
20
+ orgIPFCode: string;
21
+ externalOrgId: number;
22
+ deptType: string;
23
+ fipsCountyCode?: string;
24
+ orgDuns: string[];
25
+ orgUeis: string[];
26
+ primaryDuns: string;
27
+ primaryUei: string;
28
+ }
29
+ /**
30
+ * NIH Project/Award object
31
+ */
32
+ interface NIHProject {
2
33
  applId: number;
3
34
  subProjectId?: string;
4
35
  fiscalYear: number;
@@ -10,7 +41,7 @@ type NIHProject = {
10
41
  directCost: number;
11
42
  indirectCost: number;
12
43
  isActive: boolean;
13
- congDistrict: string;
44
+ congDistrict?: string;
14
45
  projectStartDate: Date;
15
46
  projectEndDate: Date;
16
47
  budgetStartDate: Date;
@@ -28,38 +59,15 @@ type NIHProject = {
28
59
  cfdaCode: string;
29
60
  org: NIHOrg;
30
61
  spendingCategories?: number[];
62
+ spendingCategoriesDesc?: string[];
31
63
  terms?: string[];
32
64
  prefTerms?: string[];
33
65
  abstractText?: string;
34
- };
35
- type NIHPerson = {
36
- eraId: number;
37
- firstName: string;
38
- lastName: string;
39
- middleName: string;
40
- fullName: string;
41
- isContactPI: boolean;
42
- title?: string;
43
- };
44
- type NIHOrg = {
45
- orgName: string;
46
- city?: string;
47
- country?: string;
48
- orgCity: string;
49
- orgState: string;
50
- orgCountry?: string;
51
- orgStateName?: string;
52
- orgZipCode: string;
53
- orgFips: string;
54
- orgIPFCode: string;
55
- externalOrgId: string;
56
- deptType: string;
57
- fipsCountyCode?: string;
58
- orgDuns: string[];
59
- orgUeis: string[];
60
- primaryDuns: string;
61
- primaryUei: string;
62
- };
63
- declare function parseNIHProject(raw: any): NIHProject;
66
+ }
67
+ /**
68
+ * NIHProjectFields which can be used to filter the fields returned by the NIH Reporter API
69
+ */
64
70
  type NIHProjectFields = "SpendingCategories" | "SpendingCategoriesDesc" | "ProgramOfficers" | "AbstractText" | "Terms" | "PrefTerms" | "CovidResponse" | "SubprojectId";
65
- export { parseNIHProject, NIHProjectFields, NIHProject };
71
+ export declare function parseNIHProject(obj: unknown): [NIHProject, undefined] | [undefined, Error];
72
+ export type { NIHProject, NIHProjectFields };
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqCD,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAwDD;;GAEG;AACH,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,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E,UAAU,EAAE,gBAAgB,EAAE,CAAC"}
package/esm/types.js ADDED
@@ -0,0 +1,169 @@
1
+ import * as z from "@zod/zod/mini";
2
+ z.config(z.locales.en());
3
+ const NIHPersonSchema = z.pipe(z.object({
4
+ profile_id: z.number(),
5
+ first_name: z.string(),
6
+ last_name: z.string(),
7
+ middle_name: z.string(),
8
+ full_name: z.string(),
9
+ is_contact_pi: z.boolean(),
10
+ title: z.optional(z.string()),
11
+ }), z.transform((p) => {
12
+ const nihPerson = {
13
+ nihPersonId: p.profile_id,
14
+ firstName: p.first_name,
15
+ lastName: p.last_name,
16
+ middleName: p.middle_name,
17
+ fullName: p.full_name,
18
+ isContactPI: p.is_contact_pi,
19
+ };
20
+ if (p.title !== null && p.title !== undefined) {
21
+ nihPerson.title = p.title;
22
+ }
23
+ return nihPerson;
24
+ }));
25
+ function _testTypeNIHPerson(nihPerson) {
26
+ return nihPerson;
27
+ }
28
+ function __testTypeNIHPerson(nihPerson) {
29
+ return nihPerson;
30
+ }
31
+ const NIHOrgSchema = z.pipe(z.object({
32
+ org_name: z.string(),
33
+ city: z.nullable(z.string()),
34
+ country: z.nullable(z.string()),
35
+ org_city: z.string(),
36
+ org_state: z.string(),
37
+ org_country: z.string(),
38
+ org_state_name: z.nullable(z.string()),
39
+ org_zipcode: z.string(),
40
+ org_fips: z.string(),
41
+ org_ipf_code: z.string(),
42
+ external_org_id: z.coerce.number(),
43
+ dept_type: z.string(),
44
+ fips_county_code: z.nullish(z.string()),
45
+ org_duns: z.array(z.string()),
46
+ org_ueis: z.array(z.string()),
47
+ primary_duns: z.string(),
48
+ primary_uei: z.string(),
49
+ }), z.transform((o) => {
50
+ const org = {
51
+ orgName: o.org_name,
52
+ city: o.city ?? undefined,
53
+ country: o.country ?? undefined,
54
+ orgCity: o.org_city,
55
+ orgState: o.org_state,
56
+ orgCountry: o.org_country ?? undefined,
57
+ orgStateName: o.org_state_name ?? undefined,
58
+ deptType: o.dept_type,
59
+ orgDuns: o.org_duns,
60
+ orgUeis: o.org_ueis,
61
+ orgZipCode: o.org_zipcode,
62
+ primaryDuns: o.primary_duns,
63
+ primaryUei: o.primary_uei,
64
+ orgFips: o.org_fips,
65
+ orgIPFCode: o.org_ipf_code,
66
+ externalOrgId: o.external_org_id,
67
+ fipsCountyCode: o.fips_county_code ?? undefined,
68
+ };
69
+ return org;
70
+ }));
71
+ function _testTypeNIHOrg(org) {
72
+ return org;
73
+ }
74
+ function __testTypeNIHOrg(org) {
75
+ return org;
76
+ }
77
+ const NIHProjectSchema = z.pipe(z.object({
78
+ appl_id: z.number(),
79
+ subproject_id: z.nullish(z.string()),
80
+ fiscal_year: z.number(),
81
+ project_num: z.string(),
82
+ project_serial_num: z.string(),
83
+ award_type: z.string(),
84
+ activity_code: z.string(),
85
+ award_amount: z.number(),
86
+ direct_cost_amt: z.number(),
87
+ indirect_cost_amt: z.number(),
88
+ is_active: z.boolean(),
89
+ cong_district: z.optional(z.string()),
90
+ project_start_date: z.string(),
91
+ project_end_date: z.string(),
92
+ budget_start: z.string(),
93
+ budget_end: z.string(),
94
+ principal_investigators: z.array(NIHPersonSchema),
95
+ date_added: z.string(),
96
+ agency_code: z.string(),
97
+ arra_funded: z.string(),
98
+ opportunity_number: z.string(),
99
+ is_new: z.boolean(),
100
+ core_project_num: z.string(),
101
+ mechanism_code_dc: z.string(),
102
+ project_title: z.string(),
103
+ covid_response: z.nullish(z.string()),
104
+ cfda_code: z.string(),
105
+ organization: NIHOrgSchema,
106
+ spending_categories: z.nullish(z.array(z.coerce.number())),
107
+ spending_categories_desc: z.nullish(z.string()),
108
+ terms: z.nullish(z.string()),
109
+ pref_terms: z.nullish(z.string()),
110
+ abstract_text: z.nullish(z.string()),
111
+ }), z.transform((p) => {
112
+ const org = p.organization;
113
+ const pis = p.principal_investigators;
114
+ const nihProject = {
115
+ applId: p.appl_id,
116
+ subProjectId: p.subproject_id ?? undefined,
117
+ fiscalYear: p.fiscal_year,
118
+ projectNum: p.project_num,
119
+ projectSerialNum: p.project_serial_num,
120
+ awardType: p.award_type,
121
+ activityCode: p.activity_code,
122
+ awardAmount: p.award_amount,
123
+ directCost: p.direct_cost_amt,
124
+ indirectCost: p.indirect_cost_amt,
125
+ isActive: p.is_active,
126
+ congDistrict: p.cong_district,
127
+ projectStartDate: new Date(p.project_start_date),
128
+ projectEndDate: new Date(p.project_end_date),
129
+ budgetStartDate: new Date(p.budget_start),
130
+ budgetEndDate: new Date(p.budget_end),
131
+ principalInvestigators: pis,
132
+ dateAdded: new Date(p.date_added),
133
+ agencyCode: p.agency_code,
134
+ arraFunded: p.arra_funded,
135
+ oppurtunityNumber: p.opportunity_number,
136
+ isNew: p.is_new,
137
+ coreProjectNum: p.core_project_num,
138
+ mechanismCodeDc: p.mechanism_code_dc,
139
+ projectTitle: p.project_title,
140
+ covidResponse: p.covid_response ?? undefined,
141
+ cfdaCode: p.cfda_code,
142
+ org: org,
143
+ spendingCategories: typeof p.spending_categories === "object" ? p.spending_categories : undefined,
144
+ terms: typeof p.terms === "string"
145
+ ? (p.terms.match(/<([^>]+)>/g)?.map((tag) => tag.slice(1, -1)) || [])
146
+ : undefined,
147
+ spendingCategoriesDesc: typeof p.spending_categories_desc === "string"
148
+ ? p.spending_categories_desc.split(";")
149
+ : undefined,
150
+ prefTerms: typeof p.pref_terms === "string" ? p.pref_terms.split(";") : undefined,
151
+ abstractText: p.abstract_text ?? undefined,
152
+ };
153
+ return nihProject;
154
+ }));
155
+ function _testTypeNIHProject(project) {
156
+ return project;
157
+ }
158
+ function __testTypeNIHProject(project) {
159
+ return project;
160
+ }
161
+ export function parseNIHProject(obj) {
162
+ const result = NIHProjectSchema.safeParse(obj);
163
+ if (result.success) {
164
+ return [result.data, undefined];
165
+ }
166
+ else {
167
+ return [undefined, result.error];
168
+ }
169
+ }
package/package.json CHANGED
@@ -1,27 +1,35 @@
1
1
  {
2
2
  "name": "@adisuper94/nih-reporter",
3
- "version": "0.0.4",
4
- "description": "",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "build": "tsc",
10
- "test": "node --loader ts-node/esm --no-warnings=ExperimentalWarning tests/*"
11
- },
3
+ "version": "0.0.8",
4
+ "description": "NIH Reporter API client",
5
+ "keywords": [
6
+ "nih",
7
+ "nih-reporter",
8
+ "api"
9
+ ],
10
+ "author": "Aditya Subramanian",
11
+ "homepage": "https://github.com/adiSuper94/nih-reporter#readme",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/adiSuper94/nih-reporter.git"
15
15
  },
16
- "keywords": [],
17
- "author": "Aditya Subramanian",
16
+ "license": "MIT",
18
17
  "bugs": {
19
18
  "url": "https://github.com/adiSuper94/nih-reporter/issues"
20
19
  },
21
- "homepage": "https://github.com/adiSuper94/nih-reporter#readme",
20
+ "main": "./script/index.js",
21
+ "module": "./esm/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./esm/index.js",
25
+ "require": "./script/index.js"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "@zod/mini": "^4.0.0-beta.20250424T163858"
30
+ },
22
31
  "devDependencies": {
23
- "@types/node": "^22.14.0",
24
- "ts-node": "^10.9.2",
25
- "typescript": "^5.8.2"
26
- }
27
- }
32
+ "@types/node": "^20.9.0"
33
+ },
34
+ "_generatedBy": "dnt@dev"
35
+ }
@@ -0,0 +1,4 @@
1
+ import { NIHProjectQuery } from "./project.js";
2
+ import type { NIHProject } from "./types.js";
3
+ export { type NIHProject, NIHProjectQuery };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NIHProjectQuery = void 0;
4
+ const project_js_1 = require("./project.js");
5
+ Object.defineProperty(exports, "NIHProjectQuery", { enumerable: true, get: function () { return project_js_1.NIHProjectQuery; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }