@nasa-gcn/schema 4.1.0

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 (62) hide show
  1. package/.github/auto_request_review.yml +12 -0
  2. package/.github/dependabot.yml +12 -0
  3. package/.github/workflows/release.yml +27 -0
  4. package/.github/workflows/review.yml +15 -0
  5. package/.github/workflows/validate.yml +32 -0
  6. package/.husky/pre-commit +1 -0
  7. package/README.md +36 -0
  8. package/gcn/circulars.example.json +11 -0
  9. package/gcn/circulars.schema.json +46 -0
  10. package/gcn/notices/burstcube/alert.example.json +29 -0
  11. package/gcn/notices/burstcube/alert.schema.json +27 -0
  12. package/gcn/notices/burstcube/test.example.json +29 -0
  13. package/gcn/notices/burstcube/test.schema.json +27 -0
  14. package/gcn/notices/core/AdditionalInfo.schema.json +13 -0
  15. package/gcn/notices/core/Alert.schema.json +28 -0
  16. package/gcn/notices/core/DateTime.schema.json +25 -0
  17. package/gcn/notices/core/DetectorStatus.schema.json +7 -0
  18. package/gcn/notices/core/Distance.schema.json +19 -0
  19. package/gcn/notices/core/Duration.schema.json +28 -0
  20. package/gcn/notices/core/Event.schema.json +23 -0
  21. package/gcn/notices/core/FollowUp.schema.json +26 -0
  22. package/gcn/notices/core/GeoLocBase.schema.json +26 -0
  23. package/gcn/notices/core/HardnessRatio.schema.json +33 -0
  24. package/gcn/notices/core/Localization.example.json +13 -0
  25. package/gcn/notices/core/Localization.schema.json +64 -0
  26. package/gcn/notices/core/Pointing.example.json +10 -0
  27. package/gcn/notices/core/Pointing.schema.json +43 -0
  28. package/gcn/notices/core/Redshift.schema.json +21 -0
  29. package/gcn/notices/core/Reporter.example.json +7 -0
  30. package/gcn/notices/core/Reporter.schema.json +42 -0
  31. package/gcn/notices/core/Statistics.example.json +16 -0
  32. package/gcn/notices/core/Statistics.schema.json +69 -0
  33. package/gcn/notices/core/spectral/GammaRay.schema.json +92 -0
  34. package/gcn/notices/core/spectral/models/Band.schema.json +42 -0
  35. package/gcn/notices/core/spectral/models/CutOffPowerLaw.schema.json +34 -0
  36. package/gcn/notices/core/spectral/models/PowerLaw.schema.json +26 -0
  37. package/gcn/notices/einstein_probe/wxt/alert.example.json +13 -0
  38. package/gcn/notices/einstein_probe/wxt/alert.schema.json +15 -0
  39. package/gcn/notices/glowbug/Alert.example.json +34 -0
  40. package/gcn/notices/glowbug/Alert.schema.json +52 -0
  41. package/gcn/notices/heasarc/archive_alert.example.json +13 -0
  42. package/gcn/notices/heasarc/archive_alert.schema.json +31 -0
  43. package/gcn/notices/icecube/lvk_nu_track_search.example.json +45 -0
  44. package/gcn/notices/icecube/lvk_nu_track_search.schema.json +85 -0
  45. package/gcn/notices/icecube/test/gold_bronze.update.example.json +18 -0
  46. package/gcn/notices/icecube/test/gold_bronze_track_alerts.example.json +16 -0
  47. package/gcn/notices/icecube/test/gold_bronze_track_alerts.schema.json +25 -0
  48. package/gcn/notices/svom/eclairs/trigger.catalog.example.json +18 -0
  49. package/gcn/notices/svom/eclairs/trigger.not-slewing.example.json +17 -0
  50. package/gcn/notices/svom/eclairs/trigger.slewing.example.json +17 -0
  51. package/gcn/notices/svom/eclairs/trigger.wakeup.example.json +17 -0
  52. package/gcn/notices/svom/grm/trigger.example.json +16 -0
  53. package/gcn/notices/svom/trigger.schema.json +33 -0
  54. package/gcn/notices/swift/bat/Guano.Retraction.example.json +15 -0
  55. package/gcn/notices/swift/bat/Guano.example.json +20 -0
  56. package/gcn/notices/swift/bat/Guano.schema.json +28 -0
  57. package/gcn/notices/swift/bat/guano.loc_arc_min.example.json +28 -0
  58. package/gcn/notices/swift/bat/guano.loc_map.example.json +22 -0
  59. package/index.js +1 -0
  60. package/package.json +53 -0
  61. package/update-tags.mjs +55 -0
  62. package/validate.mjs +100 -0
@@ -0,0 +1,85 @@
1
+ {
2
+ "$id": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/icecube/lvk_nu_track_search.schema.json",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "type": "object",
5
+ "title": "IceCube LVK Alert Nu Track Search",
6
+ "description": "IceCube LVK Coincident Neutrino Track Search",
7
+ "allOf": [
8
+ {
9
+ "$ref": "../core/Alert.schema.json",
10
+ "description": "Alert information (alert_datetime and alert_type) from LVK alert notices"
11
+ },
12
+ {
13
+ "$ref": "../core/FollowUp.schema.json",
14
+ "description": "ID (ref_ID) of LVK alert notice"
15
+ },
16
+ { "$ref": "../core/AdditionalInfo.schema.json" },
17
+ {
18
+ "$ref": "../core/Reporter.schema.json",
19
+ "description": "Record/Sequence number of LVK alerts"
20
+ },
21
+ { "$ref": "../core/DateTime.schema.json" }
22
+ ],
23
+ "properties": {
24
+ "pval_generic": {
25
+ "description": "P-value from generic transient search; consistency with background expectations [0-1]",
26
+ "type": ["number", "null"]
27
+ },
28
+ "pval_bayesian": {
29
+ "description": "P-value from LLAMA Bayesian search; consistency with background expectations [0-1]",
30
+ "type": ["number", "null"]
31
+ },
32
+ "n_events_coincident": {
33
+ "description": "Number of IceCube events in spatial and temporal coincidence with the GW map",
34
+ "type": "number"
35
+ },
36
+ "coincident_events": {
37
+ "type": "array",
38
+ "description": "An array of summary of information for each coincident neutrino track event",
39
+ "items": { "$ref": "#/$defs/coincevent" }
40
+ },
41
+ "most_probable_direction": {
42
+ "description": "Most likely source direction based on all coincident events and GW localizations",
43
+ "$ref": "../core/Localization.schema.json"
44
+ },
45
+ "neutrino_flux_sensitivity_range": {
46
+ "description": "Time integrated flux sensitivity ranges assuming an E^-2 spectrum (E^2 dN/dE) within the GW map localization",
47
+ "$ref": "#/$defs/fluxlimits"
48
+ }
49
+ },
50
+ "$defs": {
51
+ "fluxlimits": {
52
+ "type": "object",
53
+ "properties": {
54
+ "flux_sensitivity": {
55
+ "description": "Time integrated flux sensitivity range (min, max) [GeV cm^-2] assuming an E^-2 spectrum (E^2 dN/dE) found within the 90% region of GW map localization",
56
+ "type": "array",
57
+ "items": { "type": "number" }
58
+ },
59
+ "sensitive_energy_range": {
60
+ "description": "Energy sensitivity range (lower, upper) [GeV] assuming an E^-2 spectrum (E^2 dN/dE)",
61
+ "type": "array",
62
+ "items": { "type": "number" }
63
+ }
64
+ }
65
+ },
66
+ "coincevent": {
67
+ "type": "object",
68
+ "allOf": [{ "$ref": "../core/Localization.schema.json" }],
69
+ "properties": {
70
+ "event_dt": {
71
+ "description": "Time difference between LVK alert time and neutrino candidate [sec]",
72
+ "type": "number"
73
+ },
74
+ "event_pval_generic": {
75
+ "description": "Per-event P-value from generic transient search; consistency with background expectations [0-1]",
76
+ "type": ["number", "null"]
77
+ },
78
+ "event_pval_bayesian": {
79
+ "description": "Per-event P-value from LLAMA Bayesian search; consistency with background expectations [0-1]",
80
+ "type": ["number", "null"]
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/icecube/test/gold_bronze_track_alerts.schema.json",
3
+ "additional_info": "IceCube Bronze Neutrino Track Alert",
4
+ "event_name": ["IceCube-230416A"],
5
+ "id": ["137840", "57034692"],
6
+ "alert_datetime": "2023-04-16T05:42:00.0Z",
7
+ "alert_type": "update",
8
+ "ra": 345.82,
9
+ "dec": 9.01,
10
+ "ra_dec_error": 0.5,
11
+ "containment_probability": 0.9,
12
+ "systematic_included": false,
13
+ "healpix_url": "https://roc.icecube.wisc.edu/public/",
14
+ "trigger_time": "2023-04-16T05:22:26.150574Z",
15
+ "nu_energy": 127.29,
16
+ "signalness": 0.34064,
17
+ "far": 8.029e-8
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/icecube/test/gold_bronze_track_alerts.schema.json",
3
+ "additional_info": "IceCube Bronze Neutrino Track Alert",
4
+ "id": ["137840", "57034692"],
5
+ "alert_datetime": "2023-04-16T05:22:29.55Z",
6
+ "alert_type": "initial",
7
+ "ra": 345.82,
8
+ "dec": 9.01,
9
+ "ra_dec_error": 0.5,
10
+ "containment_probability": 0.9,
11
+ "systematic_included": false,
12
+ "trigger_time": "2023-04-16T05:22:26.150574Z",
13
+ "nu_energy": 127.29,
14
+ "signalness": 0.34064,
15
+ "far": 8.029e-8
16
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$id": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/icecube/test/gold_bronze_track_alerts.schema.json",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "type": "object",
5
+ "title": "IceCubeGoldAndBronzeTracks",
6
+ "description": "IceCube Astrotrack Gold And Bronze track alert events",
7
+ "allOf": [
8
+ { "$ref": "../../core/AdditionalInfo.schema.json" },
9
+ { "$ref": "../../core/Event.schema.json" },
10
+ { "$ref": "../../core/Alert.schema.json" },
11
+ { "$ref": "../../core/Localization.schema.json" },
12
+ { "$ref": "../../core/DateTime.schema.json" },
13
+ { "$ref": "../../core/Statistics.schema.json" }
14
+ ],
15
+ "properties": {
16
+ "nu_energy": {
17
+ "description": "Most probable neutrino energy [TeV] that would have produced an event",
18
+ "type": "number"
19
+ },
20
+ "signalness": {
21
+ "description": "Probability [dn] that this is an astrophysical signal relative to backgrounds",
22
+ "type": "number"
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "instrument": "ECLAIRs",
4
+ "alert_datetime": "2024-02-22T08:51:55",
5
+ "alert_tense": "test",
6
+ "alert_type": "initial",
7
+ "id": ["sb24022203"],
8
+ "event_name": ["M1"],
9
+ "trigger_time": "2024-02-22T08:51:31.320000",
10
+ "ra": 143.2478,
11
+ "dec": -68.0289,
12
+ "ra_dec_error": 0.1,
13
+ "image_snr": 25.67,
14
+ "image_duration": 0,
15
+ "image_energy_range": [4, 20],
16
+ "trigger_type": "rate",
17
+ "slew_status": "not_requested"
18
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "instrument": "ECLAIRs",
4
+ "alert_datetime": "2024-02-22T08:51:55",
5
+ "alert_tense": "test",
6
+ "alert_type": "update",
7
+ "id": ["sb24022203"],
8
+ "trigger_time": "2024-02-22T08:51:31.320000",
9
+ "ra": 143.2478,
10
+ "dec": -68.0289,
11
+ "ra_dec_error": 0.1,
12
+ "image_snr": 25.67,
13
+ "image_duration": 0,
14
+ "image_energy_range": [4, 20],
15
+ "trigger_type": "rate",
16
+ "slew_status": "rejected"
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "instrument": "ECLAIRs",
4
+ "alert_datetime": "2024-02-22T08:51:55",
5
+ "alert_tense": "test",
6
+ "alert_type": "update",
7
+ "id": ["sb24022203"],
8
+ "trigger_time": "2024-02-22T08:51:31.320000",
9
+ "ra": 143.2478,
10
+ "dec": -68.0289,
11
+ "ra_dec_error": 0.1,
12
+ "image_snr": 25.67,
13
+ "image_duration": 0,
14
+ "image_energy_range": [4, 20],
15
+ "trigger_type": "rate",
16
+ "slew_status": "accepted"
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "instrument": "ECLAIRs",
4
+ "alert_datetime": "2024-02-22T08:51:55",
5
+ "alert_tense": "test",
6
+ "alert_type": "initial",
7
+ "id": ["sb24022203"],
8
+ "trigger_time": "2024-02-22T08:51:31.320000",
9
+ "ra": 143.2478,
10
+ "dec": -68.0289,
11
+ "ra_dec_error": 0.1,
12
+ "image_snr": 25.67,
13
+ "image_duration": 0,
14
+ "image_energy_range": [4, 20],
15
+ "trigger_type": "rate",
16
+ "slew_status": "not_requested"
17
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "instrument": "GRM",
4
+ "alert_datetime": "2024-02-22T08:51:55",
5
+ "alert_tense": "test",
6
+ "alert_type": "initial",
7
+ "id": ["sb24022203"],
8
+ "trigger_time": "2024-02-22T08:51:31.320000",
9
+ "ra": 143.2478,
10
+ "dec": -68.0289,
11
+ "ra_dec_error": 0.1,
12
+ "rate_snr": 25.67,
13
+ "rate_duration": 0,
14
+ "rate_energy_range": [15, 550],
15
+ "triggered_GRDs": [true, true, true]
16
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "$id": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/svom/trigger.schema.json",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "type": "object",
5
+ "unevaluatedProperties": false,
6
+ "title": "SVOM trigger alerts",
7
+ "description": "ECLAIRs or GRM trigger parameters computed onboard",
8
+ "allOf": [
9
+ { "$ref": "../core/AdditionalInfo.schema.json" },
10
+ { "$ref": "../core/Alert.schema.json" },
11
+ { "$ref": "../core/DateTime.schema.json" },
12
+ { "$ref": "../core/Event.schema.json" },
13
+ { "$ref": "../core/Localization.schema.json" },
14
+ { "$ref": "../core/Reporter.schema.json" },
15
+ { "$ref": "../core/Statistics.schema.json" },
16
+ { "$ref": "../core/Pointing.schema.json" },
17
+ { "$ref": "../core/GeoLocBase.schema.json" }
18
+ ],
19
+ "properties": {
20
+ "$schema": true,
21
+ "slew_status": {
22
+ "enum": ["accepted", "rejected", "not_requested"],
23
+ "description": "Spacecraft slew status"
24
+ },
25
+ "triggered_GRDs": {
26
+ "type": "array",
27
+ "items": { "type": "boolean" },
28
+ "minItems": 3,
29
+ "maxItems": 3,
30
+ "description": "In case of a GRM trigger, trigger status the 3 GRDs. Each item correspond to one of the 3 GRDs: true means the GRD triggers, false not"
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/swift/bat/Guano.schema.json",
3
+ "mission": "Swift",
4
+ "instrument": "BAT-GUANO",
5
+ "messenger": "EM",
6
+ "record_number": 4,
7
+ "alert_datetime": "2023-01-01T03:24:36.0Z",
8
+ "alert_tense": "current",
9
+ "alert_type": "retraction",
10
+ "trigger_time": "2022-12-31T21:46:05.13Z",
11
+ "follow_up_event": "Fermi 694215970",
12
+ "follow_up_type": "GRB",
13
+ "data_archive_page": "https://guano.swift.psu.edu/trigger_report?id=694215995",
14
+ "id": ["694215995"]
15
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/swift/bat/Guano.schema.json",
3
+ "mission": "Swift",
4
+ "instrument": "BAT-GUANO",
5
+ "messenger": "EM",
6
+ "record_number": 1,
7
+ "alert_datetime": "2023-01-01T03:24:36.0Z",
8
+ "alert_tense": "current",
9
+ "alert_type": "initial",
10
+ "trigger_time": "2022-12-31T21:46:05.13Z",
11
+ "rate_snr": 15.8,
12
+ "rate_duration": 0.256,
13
+ "rate_energy_range": [15, 350],
14
+ "classification": { "GRB": 1 },
15
+ "far": 0.00001,
16
+ "follow_up_event": "Fermi 694215970",
17
+ "follow_up_type": "GRB",
18
+ "data_archive_page": "https://guano.swift.psu.edu/trigger_report?id=694215995",
19
+ "id": ["694215995"]
20
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$id": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/swift/bat/Guano.schema.json",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "title": "Swift/BAT-GUANO Alert",
5
+ "description": "Candidate gamma-ray transient reported from the BAT-GUANO targeted search",
6
+ "type": "object",
7
+ "allOf": [
8
+ { "$ref": "../../core/Alert.schema.json" },
9
+ { "$ref": "../../core/Event.schema.json" },
10
+ { "$ref": "../../core/DateTime.schema.json" },
11
+ { "$ref": "../../core/Localization.schema.json" },
12
+ { "$ref": "../../core/Statistics.schema.json" },
13
+ { "$ref": "../../core/Reporter.schema.json" },
14
+ { "$ref": "../../core/AdditionalInfo.schema.json" }
15
+ ],
16
+ "properties": {
17
+ "$schema": true,
18
+ "follow_up_event": {
19
+ "type": "string",
20
+ "description": "Name or trigger time of the external trigger that launched the search."
21
+ },
22
+ "follow_up_type": {
23
+ "type": "string",
24
+ "description": "Type of external trigger that launched the search, eg GW, neutrino, etc."
25
+ }
26
+ },
27
+ "unevaluatedProperties": false
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/swift/bat/Guano.schema.json",
3
+ "mission": "Swift",
4
+ "instrument": "BAT-GUANO",
5
+ "messenger": "EM",
6
+ "record_number": 3,
7
+ "alert_datetime": "2023-01-01T05:33:01Z",
8
+ "alert_tense": "current",
9
+ "alert_type": "update",
10
+ "trigger_time": "2022-12-31T21:46:05.13Z",
11
+ "ra": 336.26,
12
+ "dec": 25.139,
13
+ "ra_dec_error": 0.5,
14
+ "containment_probability": 0.9,
15
+ "systematic_included": true,
16
+ "rate_snr": 15.8,
17
+ "rate_duration": 0.256,
18
+ "rate_energy_range": [15, 350],
19
+ "image_snr": 13.94,
20
+ "image_duration": 0.256,
21
+ "image_energy_range": [15, 350],
22
+ "classification": { "GRB": 1 },
23
+ "far": 0.00001,
24
+ "follow_up_event": "Fermi 694215970",
25
+ "follow_up_type": "GRB",
26
+ "data_archive_page": "https://guano.swift.psu.edu/trigger_report?id=694215995",
27
+ "id": ["694215995"]
28
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://gcn.nasa.gov/schema/v4.1.0/gcn/notices/swift/bat/Guano.schema.json",
3
+ "mission": "Swift",
4
+ "instrument": "BAT-GUANO",
5
+ "messenger": "EM",
6
+ "record_number": 2,
7
+ "alert_datetime": "2023-01-01T03:24:36.0Z",
8
+ "alert_tense": "current",
9
+ "alert_type": "update",
10
+ "trigger_time": "2022-12-31T21:46:05.13Z",
11
+ "healpix_file": "hhhh...",
12
+ "systematic_included": true,
13
+ "rate_snr": 7.5,
14
+ "rate_duration": 0.256,
15
+ "rate_energy_range": [15, 350],
16
+ "classification": { "GRB": 1 },
17
+ "far": 0.00001,
18
+ "follow_up_event": "Fermi 694215970",
19
+ "follow_up_type": "GRB",
20
+ "data_archive_page": "https://guano.swift.psu.edu/trigger_report?id=694215995",
21
+ "id": ["694215995"]
22
+ }
package/index.js ADDED
@@ -0,0 +1 @@
1
+ // This file is intentionally left blank.
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@nasa-gcn/schema",
3
+ "description": "Unified JSON Schema for multi-messenger and high-energy astronomy alerts",
4
+ "version": "4.1.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "github:nasa-gcn/gcn-schema"
8
+ },
9
+ "scripts": {
10
+ "prepare": "husky",
11
+ "test": "node validate.mjs",
12
+ "version": "node update-tags.mjs && git add -u",
13
+ "postversion": "node update-tags.mjs --reset && git add -u && git commit --no-verify -m \"Back to development\""
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "devDependencies": {
19
+ "@nasa-gcn/eslint-config-gitignore": "^0.0.2",
20
+ "ajv": "^8.17.1",
21
+ "ajv-formats": "^3.0.1",
22
+ "eslint": "^8.34.0",
23
+ "eslint-config-prettier": "^9.1.0",
24
+ "execa": "^9.3.0",
25
+ "glob": "^10.1.0",
26
+ "husky": "^9.1.1",
27
+ "lint-staged": "^15.2.7",
28
+ "prettier": "3.3.3"
29
+ },
30
+ "prettier": {
31
+ "semi": false,
32
+ "singleQuote": true
33
+ },
34
+ "eslintConfig": {
35
+ "env": {
36
+ "es2022": true,
37
+ "node": true
38
+ },
39
+ "extends": [
40
+ "eslint:recommended",
41
+ "@nasa-gcn/eslint-config-gitignore",
42
+ "prettier"
43
+ ],
44
+ "parserOptions": {
45
+ "sourceType": "module"
46
+ }
47
+ },
48
+ "lint-staged": {
49
+ "*.{json,js,mjs}": "prettier --write",
50
+ "*.{js,mjs}": "eslint --max-warnings 0",
51
+ "*.schema.json": "node validate.mjs"
52
+ }
53
+ }
@@ -0,0 +1,55 @@
1
+ import { readFile, writeFile } from 'fs/promises'
2
+ import { glob as baseGlob } from 'glob'
3
+ import * as prettier from 'prettier'
4
+
5
+ // FIXME: replace with a JSON import when Import Attributes become part of
6
+ // EcmaScript. See https://github.com/tc39/proposal-import-attributes
7
+ const { version } = JSON.parse(
8
+ await readFile('package.json', { encoding: 'utf8' }),
9
+ )
10
+
11
+ const tagPath = `v${version}`
12
+
13
+ async function glob(path) {
14
+ return await baseGlob(path, {
15
+ ignore: ['node_modules/**'],
16
+ posix: true,
17
+ })
18
+ }
19
+
20
+ async function fileUpdates(fileSet, key, oldValue, newValue) {
21
+ await Promise.all(
22
+ fileSet.map(async (fileItem) => {
23
+ let file = JSON.parse(
24
+ await readFile(fileItem, {
25
+ encoding: 'utf-8',
26
+ }),
27
+ )
28
+ file[key] = file[key].replace(
29
+ `https://gcn.nasa.gov/schema/${oldValue}/`,
30
+ `https://gcn.nasa.gov/schema/${newValue}/`,
31
+ )
32
+
33
+ await writeFile(
34
+ fileItem,
35
+ await prettier.format(JSON.stringify(file), {
36
+ parser: 'json',
37
+ }),
38
+ )
39
+ }),
40
+ )
41
+ }
42
+
43
+ async function loadAndUpdateFiles(oldValue, newValue) {
44
+ const schemaFilenames = await glob('**/*.schema.json')
45
+ await fileUpdates(schemaFilenames, '$id', oldValue, newValue)
46
+
47
+ const exampleFilenames = await glob('**/*.example.json')
48
+ await fileUpdates(exampleFilenames, '$schema', oldValue, newValue)
49
+ }
50
+
51
+ if (process.argv.includes('--reset')) {
52
+ await loadAndUpdateFiles(tagPath, 'main')
53
+ } else {
54
+ await loadAndUpdateFiles('main', tagPath)
55
+ }
package/validate.mjs ADDED
@@ -0,0 +1,100 @@
1
+ import { readFile } from 'fs/promises'
2
+ import Ajv from 'ajv/dist/2020.js'
3
+ import addFormats from 'ajv-formats'
4
+ import meta from 'ajv/dist/refs/json-schema-2020-12/index.js'
5
+ import { glob as baseGlob } from 'glob'
6
+ import { execa, ExecaError } from 'execa'
7
+
8
+ let ref
9
+ try {
10
+ const { stdout } = await execa`git describe --exact-match --tags`
11
+ ref = stdout
12
+ } catch (e) {
13
+ if (e instanceof ExecaError && e.failed) ref = 'main'
14
+ else throw e
15
+ }
16
+
17
+ const schemaIdPrefix = `https://gcn.nasa.gov/schema/${ref}`
18
+
19
+ const ajv = new Ajv({
20
+ validateSchema: true,
21
+ verbose: true,
22
+ allowUnionTypes: true,
23
+ })
24
+ addFormats(ajv)
25
+ ajv.addMetaSchema(meta)
26
+
27
+ async function glob(path) {
28
+ return await baseGlob(path, {
29
+ ignore: ['test/**', 'node_modules/**'],
30
+ posix: true,
31
+ })
32
+ }
33
+
34
+ async function validate() {
35
+ const schemaFilenames = await glob('**/*.schema.json')
36
+ const schemas = await Promise.all(
37
+ schemaFilenames.map(async (match) => {
38
+ const json = JSON.parse(
39
+ await readFile(match, {
40
+ encoding: 'utf-8',
41
+ }),
42
+ )
43
+ const expectedId = `${schemaIdPrefix}/${match}`
44
+ if (json['$id'] !== expectedId) {
45
+ console.error(
46
+ `error: ${match}: expected value of $id to be ${expectedId}, but found ${json['$id']}`,
47
+ )
48
+ process.exitCode = 1
49
+ }
50
+ return json
51
+ }),
52
+ )
53
+
54
+ try {
55
+ ajv.addSchema(schemas).compile(true)
56
+ } catch (e) {
57
+ if (e instanceof Error) {
58
+ process.exitCode = 1
59
+ console.error(`error: ${e.message}`)
60
+ } else {
61
+ throw e
62
+ }
63
+ }
64
+
65
+ const exampleFilenames = await glob('**/*.example.json')
66
+ await Promise.all(
67
+ exampleFilenames.map(async (path) => {
68
+ const example = JSON.parse(
69
+ await readFile(path, {
70
+ encoding: 'utf-8',
71
+ }),
72
+ )
73
+
74
+ const schemaId = example['$schema']
75
+ if (!schemaId) {
76
+ process.exitCode = 1
77
+ console.error(`error: ${path}: missing required $schema property`)
78
+ return
79
+ }
80
+
81
+ try {
82
+ ajv.validate(schemaId, example)
83
+ } catch (e) {
84
+ if (e instanceof Error) {
85
+ process.exitCode = 1
86
+ console.error(`error: ${path}: ${e.message}`)
87
+ } else {
88
+ throw e
89
+ }
90
+ }
91
+
92
+ if (ajv.errors) {
93
+ console.log(JSON.stringify(ajv.errors, null, 2))
94
+ process.exitCode = 1
95
+ }
96
+ }),
97
+ )
98
+ }
99
+
100
+ await validate()