@hestia-earth/glossary 0.97.1 → 0.98.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -28,6 +28,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var index_exports = {};
29
29
  __export(index_exports, {
30
30
  getArrayTreatment: () => getArrayTreatment,
31
+ getBackgroundEmissionModels: () => getBackgroundEmissionModels,
32
+ getBackgroundEmissionTerms: () => getBackgroundEmissionTerms,
33
+ getBackgroundEmissionTermsByModel: () => getBackgroundEmissionTermsByModel,
31
34
  getBafuMapping: () => getBafuMapping,
32
35
  getBlankNodesGroup: () => getBlankNodesGroup,
33
36
  getDefaultModelId: () => getDefaultModelId,
@@ -41,6 +44,7 @@ __export(index_exports, {
41
44
  getTermTypeLookups: () => getTermTypeLookups,
42
45
  getWorldSteelMapping: () => getWorldSteelMapping,
43
46
  idToIso31662: () => idToIso31662,
47
+ isBackgroundEmission: () => isBackgroundEmission,
44
48
  isCoverCrop: () => isCoverCrop,
45
49
  isInSystemBoundary: () => isInSystemBoundary,
46
50
  isPlantation: () => isPlantation,
@@ -51,6 +55,8 @@ __export(index_exports, {
51
55
  });
52
56
  module.exports = __toCommonJS(index_exports);
53
57
  var import_arrayTreatment = __toESM(require("./resources/arrayTreatment.json"), 1);
58
+ var import_backgroundEmissionTerms = __toESM(require("./resources/backgroundEmissionTerms.json"), 1);
59
+ var import_backgroundEmissionTermsByModel = __toESM(require("./resources/backgroundEmissionTermsByModel.json"), 1);
54
60
  var import_bafuMapping = __toESM(require("./resources/bafuMapping.json"), 1);
55
61
  var import_blankNodesGroup = __toESM(require("./resources/blankNodesGroup.json"), 1);
56
62
  var import_defaultModelId = __toESM(require("./resources/defaultModelId.json"), 1);
@@ -69,6 +75,8 @@ var import_termType_lookups = __toESM(require("./resources/termType-lookups.json
69
75
  var import_worldsteelMapping = __toESM(require("./resources/worldsteelMapping.json"), 1);
70
76
  const RESOURCES = {
71
77
  "arrayTreatment.json": import_arrayTreatment.default,
78
+ "backgroundEmissionTerms.json": import_backgroundEmissionTerms.default,
79
+ "backgroundEmissionTermsByModel.json": import_backgroundEmissionTermsByModel.default,
72
80
  "bafuMapping.json": import_bafuMapping.default,
73
81
  "blankNodesGroup.json": import_blankNodesGroup.default,
74
82
  "defaultModelId.json": import_defaultModelId.default,
@@ -103,6 +111,19 @@ const isInSystemBoundary = (id) => {
103
111
  const value = import_inHestiaDefaultSystemBoundary.default[id];
104
112
  return !value || value === "true";
105
113
  };
114
+ const backgroundEmissions = new Set(import_backgroundEmissionTerms.default);
115
+ const isBackgroundEmission = (id) => backgroundEmissions.has(id);
116
+ const getBackgroundEmissionTerms = () => [...import_backgroundEmissionTerms.default];
117
+ const getBackgroundEmissionTermsByModel = (modelId) => import_backgroundEmissionTermsByModel.default[modelId];
118
+ const backgroundEmissionModels = Object.entries(
119
+ import_backgroundEmissionTermsByModel.default
120
+ ).reduce((prev, [model, indicators]) => {
121
+ Object.values(indicators).flat().forEach((id) => {
122
+ prev[id] = [...prev[id] ?? [], model];
123
+ });
124
+ return prev;
125
+ }, {});
126
+ const getBackgroundEmissionModels = (id) => backgroundEmissionModels[id] ?? [];
106
127
  const plantations = new Set(import_isPlantation.default);
107
128
  const isPlantation = (id) => plantations.has(id);
108
129
  const getEcoalimMapping = (id) => import_ecoalimMapping.default[id];
@@ -117,6 +138,9 @@ const termOrder = ({ "@id": id, termType }) => termType ? id ? import_term_order
117
138
  // Annotate the CommonJS export names for ESM import in node:
118
139
  0 && (module.exports = {
119
140
  getArrayTreatment,
141
+ getBackgroundEmissionModels,
142
+ getBackgroundEmissionTerms,
143
+ getBackgroundEmissionTermsByModel,
120
144
  getBafuMapping,
121
145
  getBlankNodesGroup,
122
146
  getDefaultModelId,
@@ -130,6 +154,7 @@ const termOrder = ({ "@id": id, termType }) => termType ? id ? import_term_order
130
154
  getTermTypeLookups,
131
155
  getWorldSteelMapping,
132
156
  idToIso31662,
157
+ isBackgroundEmission,
133
158
  isCoverCrop,
134
159
  isInSystemBoundary,
135
160
  isPlantation,
package/index.mjs CHANGED
@@ -1,19 +1,6 @@
1
- // Tree-shakeable ESM entry point — the single source of truth for the public
2
- // API. The CommonJS entry (`index.js`, used by Node `require`) is GENERATED from
3
- // this file by `npm run build:index` (run automatically via the `prepare` hook
4
- // on install/publish), so edit this file only — never `index.js`.
5
- //
6
- // Every resource is imported statically so that bundlers (webpack, rollup,
7
- // esbuild, …) can statically determine which JSON files each export depends on
8
- // and drop the rest. Combined with `"sideEffects": false` in package.json, a
9
- // consumer importing a single getter only pulls in the one resource it needs,
10
- // instead of the whole `resources/` directory.
11
- //
12
- // To add a resource getter: add its static `import` below, the matching
13
- // `export const`, and (only if it should be reachable via the generic
14
- // `loadResourceKey`) an entry in the `RESOURCES` map.
15
-
16
1
  import arrayTreatment from "./resources/arrayTreatment.json" with { type: "json" };
2
+ import backgroundEmissionTermIds from "./resources/backgroundEmissionTerms.json" with { type: "json" };
3
+ import backgroundEmissionTermsByModel from "./resources/backgroundEmissionTermsByModel.json" with { type: "json" };
17
4
  import bafuMapping from "./resources/bafuMapping.json" with { type: "json" };
18
5
  import blankNodesGroup from "./resources/blankNodesGroup.json" with { type: "json" };
19
6
  import defaultModelId from "./resources/defaultModelId.json" with { type: "json" };
@@ -36,6 +23,8 @@ import worldsteelMapping from "./resources/worldsteelMapping.json" with { type:
36
23
  // resources only it references) when a consumer never imports those helpers.
37
24
  const RESOURCES = {
38
25
  "arrayTreatment.json": arrayTreatment,
26
+ "backgroundEmissionTerms.json": backgroundEmissionTermIds,
27
+ "backgroundEmissionTermsByModel.json": backgroundEmissionTermsByModel,
39
28
  "bafuMapping.json": bafuMapping,
40
29
  "blankNodesGroup.json": blankNodesGroup,
41
30
  "defaultModelId.json": defaultModelId,
@@ -157,6 +146,61 @@ export const isInSystemBoundary = (id) => {
157
146
  return !value || value === "true";
158
147
  };
159
148
 
149
+ // built once, so repeated checks do not scan the list
150
+ const backgroundEmissions = new Set(backgroundEmissionTermIds);
151
+
152
+ /**
153
+ * Checks whether the emission or resource use is a background one - attributed to producing an
154
+ * input rather than to the Cycle itself, and carried by a background emissions lookup.
155
+ *
156
+ * @param {string} id The HESTIA term [id](https://hestia.earth/schema/Term#id).
157
+ * @returns {boolean} True if a background emissions lookup carries a value for the Term.
158
+ */
159
+ export const isBackgroundEmission = (id) => backgroundEmissions.has(id);
160
+
161
+ /**
162
+ * Returns every Term a background emissions lookup carries a value for, across every dataset.
163
+ *
164
+ * @returns {string[]} The HESTIA term [ids](https://hestia.earth/schema/Term#id).
165
+ */
166
+ export const getBackgroundEmissionTerms = () => [...backgroundEmissionTermIds];
167
+
168
+ /**
169
+ * Returns the Terms one background emissions dataset carries a value for, by indicator
170
+ * (`emission` and `resourceUse`).
171
+ *
172
+ * @param {string} modelId The `@id` of the model whose lookups carry the values.
173
+ * @returns {{emission: string[], resourceUse: string[]}} The HESTIA term [ids](https://hestia.earth/schema/Term#id).
174
+ */
175
+ export const getBackgroundEmissionTermsByModel = (modelId) =>
176
+ backgroundEmissionTermsByModel[modelId];
177
+
178
+ // built once, so repeated lookups do not scan every dataset
179
+ const backgroundEmissionModels = Object.entries(
180
+ backgroundEmissionTermsByModel,
181
+ ).reduce((prev, [model, indicators]) => {
182
+ Object.values(indicators)
183
+ .flat()
184
+ .forEach((id) => {
185
+ prev[id] = [...(prev[id] ?? []), model];
186
+ });
187
+ return prev;
188
+ }, {});
189
+
190
+ /**
191
+ * Returns the models whose background emissions lookups carry a value for the Term.
192
+ *
193
+ * This is not which model produced a given emission - several datasets carry the same Term, so
194
+ * only the blank node's `methodModel` says which one ran. Models deriving their values from
195
+ * these datasets rather than carrying their own lookups (`linkedImpactAssessment`, `hestia`)
196
+ * are not listed here; `@hestia-earth/engine-models` links those per Term.
197
+ *
198
+ * @param {string} id The HESTIA term [id](https://hestia.earth/schema/Term#id).
199
+ * @returns {string[]} The `@id` of each model.
200
+ */
201
+ export const getBackgroundEmissionModels = (id) =>
202
+ backgroundEmissionModels[id] ?? [];
203
+
160
204
  // built once, so repeated checks do not scan the list
161
205
  const plantations = new Set(plantationIds);
162
206
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/glossary",
3
- "version": "0.97.1",
3
+ "version": "0.98.1",
4
4
  "description": "HESTIA Earth Glossary library",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "scripts": {
24
24
  "gen:impact-assessment": "node scripts/node/generate-impact-assessment-data.js",
25
+ "gen:background-emission-terms": "node scripts/node/generate-background-emission-terms.js",
25
26
  "gen:emission-grouping": "node scripts/node/generate-emission-groupings.js",
26
27
  "gen:lookups-data": "node scripts/node/generate-lookups-data.js",
27
28
  "gen:model-groups": "node scripts/node/generate-model-groups-data.js",