@cumulus/cmrjs 21.3.1 → 21.3.2

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.
@@ -25,6 +25,7 @@ function isEcho10XmlBaseGranule(obj: any): obj is Echo10XmlBaseGranule {
25
25
  * @param params.xml - The parsed XML object (e.g., from xml2js) representing ECHO10 metadata.
26
26
  * @param params.granuleUr - The new GranuleUR value to apply to the metadata.
27
27
  * @param params.producerGranuleId - The original identifier value to be set as ProducerGranuleId.
28
+ * @param params.excludeDataGranule - Whether to add or update the DataGranule node in the metadata
28
29
  * @returns A deep-cloned and updated copy of the original ECHO10 metadata object.
29
30
  * @throws If the input object does not conform to the expected ECHO10 structure.
30
31
  */
@@ -32,10 +33,12 @@ export function updateEcho10XMLGranuleUrAndGranuleIdentifier({
32
33
  xml, // The parsed XML object (e.g., from xml2js)
33
34
  granuleUr, // The new GranuleUR value
34
35
  producerGranuleId, // The original identifier to store
36
+ excludeDataGranule = false, // Whether to add/update the DataGranule node in the metadata
35
37
  }: {
36
38
  xml: unknown;
37
39
  granuleUr: string;
38
40
  producerGranuleId: string;
41
+ excludeDataGranule?: boolean;
39
42
  }): any {
40
43
  if (!isEcho10XmlBaseGranule(xml)) {
41
44
  throw new Error('Invalid XML input - expected an object with GranuleUR');
@@ -46,46 +49,48 @@ export function updateEcho10XMLGranuleUrAndGranuleIdentifier({
46
49
  moddedXml.Granule ??= {};
47
50
  moddedXml.Granule.GranuleUR = granuleUr;
48
51
 
49
- moddedXml.Granule.DataGranule ??= {};
52
+ if (excludeDataGranule === false) {
53
+ moddedXml.Granule.DataGranule ??= {};
50
54
 
51
- const dataGranule = moddedXml.Granule.DataGranule as any;
52
- const orderedDataGranule = new Map<string, any>();
55
+ const dataGranule = moddedXml.Granule.DataGranule as any;
56
+ const orderedDataGranule = new Map<string, any>();
53
57
 
54
- // ECHO10 DataGranule element order as defined in the XSD schema
55
- // https://git.earthdata.nasa.gov/projects/EMFD/repos/echo-schemas/browse/schemas/10.0/Granule.xsd
56
- const echo10DataGranuleOrder = [
57
- 'DataGranuleSizeInBytes',
58
- 'SizeMBDataGranule',
59
- 'Checksum',
60
- 'ReprocessingPlanned',
61
- 'ReprocessingActual',
62
- 'ProducerGranuleId',
63
- 'DayNightFlag',
64
- 'ProductionDateTime',
65
- 'LocalVersionId',
66
- 'AdditionalFile',
67
- ];
58
+ // ECHO10 DataGranule element order as defined in the XSD schema
59
+ // https://git.earthdata.nasa.gov/projects/EMFD/repos/echo-schemas/browse/schemas/10.0/Granule.xsd
60
+ const echo10DataGranuleOrder = [
61
+ 'DataGranuleSizeInBytes',
62
+ 'SizeMBDataGranule',
63
+ 'Checksum',
64
+ 'ReprocessingPlanned',
65
+ 'ReprocessingActual',
66
+ 'ProducerGranuleId',
67
+ 'DayNightFlag',
68
+ 'ProductionDateTime',
69
+ 'LocalVersionId',
70
+ 'AdditionalFile',
71
+ ];
68
72
 
69
- const existingKeys = Object.keys(dataGranule);
70
- const unexpectedKeys = existingKeys.filter((key) => !echo10DataGranuleOrder.includes(key));
73
+ const existingKeys = Object.keys(dataGranule);
74
+ const unexpectedKeys = existingKeys.filter((key) => !echo10DataGranuleOrder.includes(key));
71
75
 
72
- if (unexpectedKeys.length > 0) {
73
- throw new Error(
74
- `Unexpected DataGranule key(s) found: ${unexpectedKeys.join(', ')}. `
75
- + `Valid keys are: ${echo10DataGranuleOrder.join(', ')}. `
76
- + `GranuleUR: ${moddedXml.Granule.GranuleUR}`
77
- );
78
- }
79
-
80
- echo10DataGranuleOrder.forEach((key) => {
81
- if (key === 'ProducerGranuleId') {
82
- orderedDataGranule.set(key, producerGranuleId);
83
- } else if (dataGranule[key] !== undefined) {
84
- orderedDataGranule.set(key, dataGranule[key]);
76
+ if (unexpectedKeys.length > 0) {
77
+ throw new Error(
78
+ `Unexpected DataGranule key(s) found: ${unexpectedKeys.join(', ')}. `
79
+ + `Valid keys are: ${echo10DataGranuleOrder.join(', ')}. `
80
+ + `GranuleUR: ${moddedXml.Granule.GranuleUR}`
81
+ );
85
82
  }
86
- });
87
83
 
88
- moddedXml.Granule.DataGranule = orderedDataGranule as any;
84
+ echo10DataGranuleOrder.forEach((key) => {
85
+ if (key === 'ProducerGranuleId') {
86
+ orderedDataGranule.set(key, producerGranuleId);
87
+ } else if (dataGranule[key] !== undefined) {
88
+ orderedDataGranule.set(key, dataGranule[key]);
89
+ }
90
+ });
91
+
92
+ moddedXml.Granule.DataGranule = orderedDataGranule as any;
93
+ }
89
94
 
90
95
  return moddedXml;
91
96
  }
@@ -29,6 +29,7 @@ function isUMMGGranule(obj: any): obj is UMMGGranule {
29
29
  * @param metadataObject - The parsed UMM-G metadata object to be modified.
30
30
  * @param granuleUr - The new GranuleUR value to assign.
31
31
  * @param producerGranuleId - The ProducerGranuleId to store in the Identifiers list.
32
+ * @param excludeDataGranule - Whether to add or update the DataGranule node in the metadata
32
33
  * @returns A deep-cloned and updated copy of the UMM-G metadata object.
33
34
  * @throws If the input does not match the expected UMM-G granule structure.
34
35
  */
@@ -37,10 +38,12 @@ export function updateUMMGGranuleURAndGranuleIdentifier({
37
38
  metadataObject,
38
39
  granuleUr,
39
40
  producerGranuleId,
41
+ excludeDataGranule = false,
40
42
  }: {
41
43
  metadataObject: unknown;
42
44
  granuleUr: string;
43
45
  producerGranuleId: string;
46
+ excludeDataGranule?: boolean;
44
47
  }): UMMGGranule {
45
48
  if (!isUMMGGranule(metadataObject)) {
46
49
  throw new Error('Invalid UMM-G JSON metadata');
@@ -49,22 +52,28 @@ export function updateUMMGGranuleURAndGranuleIdentifier({
49
52
  const moddedJson = structuredClone(metadataObject);
50
53
 
51
54
  moddedJson.GranuleUR = granuleUr;
52
- moddedJson.DataGranule ??= {};
53
- moddedJson.DataGranule.Identifiers ??= [];
54
55
 
55
- const producerIndex = moddedJson.DataGranule.Identifiers.findIndex(
56
- (id) => id.IdentifierType === 'ProducerGranuleId'
57
- );
56
+ if (excludeDataGranule === false) {
57
+ moddedJson.DataGranule ??= {};
58
+ moddedJson.DataGranule.Identifiers ??= [];
58
59
 
59
- const producerGranuleIdIdentifier = {
60
- Identifier: producerGranuleId,
61
- IdentifierType: 'ProducerGranuleId',
62
- };
60
+ const producerIndex = moddedJson.DataGranule.Identifiers.findIndex(
61
+ (id: any) => id.IdentifierType === 'ProducerGranuleId'
62
+ );
63
+
64
+ const producerGranuleIdIdentifier = {
65
+ Identifier: producerGranuleId,
66
+ IdentifierType: 'ProducerGranuleId',
67
+ };
68
+
69
+ if (producerIndex !== -1) {
70
+ moddedJson.DataGranule.Identifiers[producerIndex] = producerGranuleIdIdentifier;
71
+ } else {
72
+ moddedJson.DataGranule.Identifiers.push(producerGranuleIdIdentifier);
73
+ }
63
74
 
64
- if (producerIndex !== -1) {
65
- moddedJson.DataGranule.Identifiers[producerIndex] = producerGranuleIdIdentifier;
66
- } else {
67
- moddedJson.DataGranule.Identifiers.push(producerGranuleIdIdentifier);
75
+ moddedJson.DataGranule.DayNightFlag ??= 'Unspecified';
76
+ moddedJson.DataGranule.ProductionDateTime ??= new Date().toISOString();
68
77
  }
69
78
 
70
79
  return moddedJson;