@atmosx/event-product-parser 3.0.51 → 3.0.52

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 (139) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/CODE_OF_CONDUCT.md +9 -9
  3. package/CONTRIBUTING.md +29 -29
  4. package/LICENSE +17 -17
  5. package/README.md +443 -444
  6. package/SECURITY.md +20 -20
  7. package/SUPPORTED_EVENTS.md +369 -368
  8. package/dist/cjs/index.cjs +161 -204
  9. package/dist/esm/index.mjs +160 -203
  10. package/package.json +52 -52
  11. package/src/@building/building.attachments.ts +82 -82
  12. package/src/@building/building.clean.ts +29 -29
  13. package/src/@building/building.create.ts +55 -55
  14. package/src/@building/building.enhance.ts +59 -59
  15. package/src/@building/building.geometry.ts +47 -47
  16. package/src/@building/building.headers.ts +36 -36
  17. package/src/@building/building.office.ts +42 -42
  18. package/src/@building/building.polygon.ts +69 -69
  19. package/src/@building/building.properties.ts +95 -95
  20. package/src/@building/building.signature.ts +60 -60
  21. package/src/@building/building.tags.ts +23 -23
  22. package/src/@building/building.tracking.ts +67 -67
  23. package/src/@building/building.validate.ts +152 -151
  24. package/src/@core/core.clearEvents.ts +30 -30
  25. package/src/@core/core.createListener.ts +23 -23
  26. package/src/@core/core.getEvents.ts +23 -23
  27. package/src/@core/core.getNodes.ts +23 -23
  28. package/src/@core/core.getRandomEvent.ts +23 -23
  29. package/src/@core/core.getVersion.ts +23 -23
  30. package/src/@core/core.manualEvent.ts +38 -0
  31. package/src/@core/core.query.ts +38 -38
  32. package/src/@core/core.setNode.ts +80 -80
  33. package/src/@core/core.start.ts +60 -60
  34. package/src/@core/core.stop.ts +31 -31
  35. package/src/@dictionaries/dictionaries.actions.ts +27 -27
  36. package/src/@dictionaries/dictionaries.awips.ts +363 -363
  37. package/src/@dictionaries/dictionaries.cancellation.ts +30 -30
  38. package/src/@dictionaries/dictionaries.causes.ts +35 -35
  39. package/src/@dictionaries/dictionaries.correlations.ts +42 -42
  40. package/src/@dictionaries/dictionaries.enhanced.ts +66 -109
  41. package/src/@dictionaries/dictionaries.events.ts +82 -82
  42. package/src/@dictionaries/dictionaries.expressions.ts +28 -28
  43. package/src/@dictionaries/dictionaries.global.ts +24 -0
  44. package/src/@dictionaries/dictionaries.hail.ts +35 -35
  45. package/src/@dictionaries/dictionaries.icao.ts +258 -258
  46. package/src/@dictionaries/dictionaries.matches.ts +54 -35
  47. package/src/@dictionaries/dictionaries.products.ts +24 -24
  48. package/src/@dictionaries/dictionaries.records.ts +25 -25
  49. package/src/@dictionaries/dictionaries.severity.ts +27 -27
  50. package/src/@dictionaries/dictionaries.shapefiles.ts +35 -35
  51. package/src/@dictionaries/dictionaries.states.ts +71 -71
  52. package/src/@dictionaries/dictionaries.status.ts +30 -30
  53. package/src/@dictionaries/dictionaries.tags.ts +92 -92
  54. package/src/@dictionaries/dictionaries.testing.ts +24 -24
  55. package/src/@events/events.api.ts +116 -116
  56. package/src/@events/events.text.ts +84 -80
  57. package/src/@events/events.ugc.ts +89 -85
  58. package/src/@events/events.vtec.ts +86 -86
  59. package/src/@manager/manager.mkEvent.ts +97 -93
  60. package/src/@manager/manager.rmEvent.ts +56 -51
  61. package/src/@manager/manager.setHash.ts +35 -35
  62. package/src/@manager/manager.updateEvents.ts +32 -32
  63. package/src/@manager/manager.updateListener.ts +154 -154
  64. package/src/@manager/manager.updateNodes.ts +53 -53
  65. package/src/@modules/@database/database.broadcastify.ts +66 -66
  66. package/src/@modules/@database/database.cache.ts +49 -49
  67. package/src/@modules/@database/database.init.ts +58 -58
  68. package/src/@modules/@database/database.shapefiles.ts +92 -92
  69. package/src/@modules/@database/database.stanza.ts +46 -46
  70. package/src/@modules/@eas/eas.getCleanDescription.ts +91 -91
  71. package/src/@modules/@eas/eas.getFloatPCM16.ts +29 -29
  72. package/src/@modules/@eas/eas.getMergedPCM16.ts +32 -32
  73. package/src/@modules/@eas/eas.getPCM16.ts +52 -52
  74. package/src/@modules/@eas/eas.getPCMToFloat.ts +26 -26
  75. package/src/@modules/@eas/eas.getSampledPCM16.ts +36 -36
  76. package/src/@modules/@eas/eas.getTTS.ts +54 -54
  77. package/src/@modules/@eas/eas.getWavPCM16.ts +52 -52
  78. package/src/@modules/@eas/eas.setAFSK.ts +51 -51
  79. package/src/@modules/@eas/eas.setAsciiToBits.ts +31 -31
  80. package/src/@modules/@eas/eas.setAttentionTone.ts +40 -40
  81. package/src/@modules/@eas/eas.setEasTone.ts +151 -151
  82. package/src/@modules/@eas/eas.setNoise.ts +32 -32
  83. package/src/@modules/@eas/eas.setRadioEffect.ts +50 -50
  84. package/src/@modules/@eas/eas.setSameHeader.ts +44 -44
  85. package/src/@modules/@stanza/stanza.getAwipsType.ts +45 -45
  86. package/src/@modules/@stanza/stanza.validate.ts +49 -49
  87. package/src/@modules/@utilities/utilities.createHttp.ts +70 -70
  88. package/src/@modules/@utilities/utilities.getFormattedTime.ts +43 -43
  89. package/src/@modules/@utilities/utilities.getLatestIssuance.ts +32 -32
  90. package/src/@modules/@utilities/utilities.getMatched.ts +33 -33
  91. package/src/@modules/@utilities/utilities.getSettings.ts +25 -25
  92. package/src/@modules/@utilities/utilities.getShapeNearestPoint.ts +114 -114
  93. package/src/@modules/@utilities/utilities.setCronSchedule.ts +94 -94
  94. package/src/@modules/@utilities/utilities.setDebug.ts +38 -38
  95. package/src/@modules/@utilities/utilities.setEventEmit.ts +41 -41
  96. package/src/@modules/@utilities/utilities.setListener.ts +30 -30
  97. package/src/@modules/@utilities/utilities.setSettings.ts +42 -42
  98. package/src/@modules/@utilities/utilities.setSleep.ts +33 -33
  99. package/src/@modules/@utilities/utilities.setTimeoutAction.ts +62 -62
  100. package/src/@modules/@utilities/utilities.setWarning.ts +34 -34
  101. package/src/@modules/@xmpp/xmpp.xDeploy.ts +57 -57
  102. package/src/@modules/@xmpp/xmpp.xError.ts +26 -26
  103. package/src/@modules/@xmpp/xmpp.xOffline.ts +36 -36
  104. package/src/@modules/@xmpp/xmpp.xOnline.ts +45 -44
  105. package/src/@modules/@xmpp/xmpp.xReconnect.ts +64 -64
  106. package/src/@modules/@xmpp/xmpp.xStanza.ts +62 -62
  107. package/src/@parsers/@hvtec/hvtec.extract.ts +39 -39
  108. package/src/@parsers/@pvtec/pvtec.expires.ts +25 -25
  109. package/src/@parsers/@pvtec/pvtec.extract.ts +48 -48
  110. package/src/@parsers/@text/text.getDescriptionFromProduct.ts +52 -52
  111. package/src/@parsers/@text/text.getEmbed.ts +55 -55
  112. package/src/@parsers/@text/text.getPolygonFromProduct.ts +53 -32
  113. package/src/@parsers/@text/text.getTextFromProduct.ts +42 -42
  114. package/src/@parsers/@text/text.getXML.ts +60 -60
  115. package/src/@parsers/@ugc/ugc.coordinates.ts +110 -110
  116. package/src/@parsers/@ugc/ugc.expiry.ts +31 -31
  117. package/src/@parsers/@ugc/ugc.extract.ts +36 -36
  118. package/src/@parsers/@ugc/ugc.getCache.ts +23 -23
  119. package/src/@parsers/@ugc/ugc.header.ts +29 -29
  120. package/src/@parsers/@ugc/ugc.locations.ts +56 -56
  121. package/src/@parsers/@ugc/ugc.setCache.ts +27 -27
  122. package/src/@parsers/@ugc/ugc.zones.ts +51 -51
  123. package/src/@types/type.attributes.ts +28 -28
  124. package/src/@types/type.compiled.ts +34 -34
  125. package/src/@types/type.event.ts +69 -69
  126. package/src/@types/type.hash.ts +24 -24
  127. package/src/@types/type.hvtec.ts +25 -25
  128. package/src/@types/type.listener.ts +32 -32
  129. package/src/@types/type.properties.ts +77 -77
  130. package/src/@types/type.pvtec.ts +30 -30
  131. package/src/@types/type.settings.ts +84 -84
  132. package/src/@types/type.stanza.ts +37 -37
  133. package/src/@types/type.ugc.ts +24 -24
  134. package/src/bootstrap.ts +115 -115
  135. package/src/index.ts +74 -74
  136. package/test.js +92 -92
  137. package/tsconfig.json +13 -13
  138. package/tsup.config.ts +15 -15
  139. package/src/@core/core.createEvent.ts +0 -82
@@ -1,50 +1,50 @@
1
- /*
2
- _ _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
- Discord: https://atmosphericx-discord.scriptkitty.cafe
13
- Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
-
16
- Internal Package: @atmosx/event-product-parser
17
-
18
- */
19
-
20
- import { TypeSettings } from "../../@types/type.settings"
21
- import { bootstrap } from '../../bootstrap'
22
- import { setWarning } from '../@utilities/utilities.setWarning';
23
- import { createEvent } from '../../@building/building.create';
24
- import { validateEvents } from "../../@building/building.validate";
25
-
26
- export const getCachedEvents = async (): Promise<void> => {
27
- try {
28
- const settings = bootstrap.settings as TypeSettings;
29
- const tick = performance.now();
30
- if (settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
31
- const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxRetentionHistory ?? 500;
32
- const get = await bootstrap.database.prepare(`SELECT * FROM stanzas ORDER BY rowid DESC LIMIT ?`).all(max) as { rowid: number; stanza: string }[];
33
- setWarning({ message: `Fetched ${get.length} cached stanzas from the database in ${Math.floor(performance.now() - tick)} ms` })
34
- let events = get.map((row) => JSON.parse(row.stanza))
35
- .filter(stanza => {
36
- if (!stanza) { return }
37
- const isSkippable = stanza.isIgnored ||
38
- (stanza.isCapEvent) ||
39
- (stanza.isCapEvent && !stanza.isCapAreaDescription)
40
- return !isSkippable
41
- });
42
- events = events.sort((a, b) => b.issued - a.issued)
43
- await Promise.all(events.map(event => createEvent(event, true)))
44
- setWarning({ message: `Processed ${events.length} cached stanzas in ${Math.floor(performance.now() - tick)} ms` })
45
- validateEvents(bootstrap.cache.processed)
46
- }
47
- } catch (error) {
48
- setWarning({ message: `An error occurred while fetching cached stanzas: ${error.message} -> ${error.stack}` })
49
- }
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from "../../@types/type.settings"
21
+ import { bootstrap } from '../../bootstrap'
22
+ import { setWarning } from '../@utilities/utilities.setWarning';
23
+ import { createEvent } from '../../@building/building.create';
24
+ import { validateEvents } from "../../@building/building.validate";
25
+
26
+ export const getCachedEvents = async (): Promise<void> => {
27
+ try {
28
+ const settings = bootstrap.settings as TypeSettings;
29
+ const tick = performance.now();
30
+ if (settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) {
31
+ const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxRetentionHistory ?? 500;
32
+ const get = await bootstrap.database.prepare(`SELECT * FROM stanzas ORDER BY rowid DESC LIMIT ?`).all(max) as { rowid: number; stanza: string }[];
33
+ setWarning({ message: `Fetched ${get.length} cached stanzas from the database in ${Math.floor(performance.now() - tick)} ms` })
34
+ let events = get.map((row) => JSON.parse(row.stanza))
35
+ .filter(stanza => {
36
+ if (!stanza) { return }
37
+ const isSkippable = stanza.isIgnored ||
38
+ (stanza.isCapEvent) ||
39
+ (stanza.isCapEvent && !stanza.isCapAreaDescription)
40
+ return !isSkippable
41
+ });
42
+ events = events.sort((a, b) => b.issued - a.issued)
43
+ await Promise.all(events.map(event => createEvent(event, true)))
44
+ setWarning({ message: `Processed ${events.length} cached stanzas in ${Math.floor(performance.now() - tick)} ms` })
45
+ validateEvents(bootstrap.cache.processed)
46
+ }
47
+ } catch (error) {
48
+ setWarning({ message: `An error occurred while fetching cached stanzas: ${error.message} -> ${error.stack}` })
49
+ }
50
50
  }
@@ -1,59 +1,59 @@
1
- /*
2
- _ _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
- Discord: https://atmosphericx-discord.scriptkitty.cafe
13
- Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
-
16
- Internal Package: @atmosx/event-product-parser
17
-
18
- */
19
-
20
-
21
- import { TypeSettings } from "../../@types/type.settings"
22
- import { bootstrap } from "../../bootstrap"
23
- import { setWarning } from '../@utilities/utilities.setWarning'
24
- import { importShapefiles } from './database.shapefiles'
25
- import { importBroadcastify } from "./database.broadcastify"
26
- import { existsSync, writeFileSync } from "fs"
27
- import sqlite3 from 'better-sqlite3'
28
-
29
- export const initializeDatabase = async (): Promise<void> => {
30
- const settings = bootstrap.settings as TypeSettings;
31
- try {
32
- if (!existsSync(settings.Database)) {
33
- writeFileSync(settings.Database, '')
34
- setWarning({ message: `Creating new database at ${settings.Database}` })
35
- }
36
- bootstrap.database = new sqlite3(settings.Database);
37
- bootstrap.database
38
- .prepare(`CREATE TABLE IF NOT EXISTS stanzas ( id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, issued TEXT, stanza TEXT )`)
39
- .run();
40
- bootstrap.database
41
- .prepare(`CREATE TABLE IF NOT EXISTS shapefiles (id TEXT PRIMARY KEY, location TEXT, geometry TEXT)`)
42
- .run();
43
- const isNeedingShapefiles = bootstrap.database
44
- .prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='shapefiles';`)
45
- .get();
46
- const isNeedingBroadcastify = bootstrap.database
47
- .prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='broadcastify';`)
48
- .get();
49
-
50
- if (!isNeedingShapefiles || !isNeedingBroadcastify) {
51
- setWarning({message: `Required database tables are currently building, please ${bootstrap.ansi_colors.RED}DO NOT${bootstrap.ansi_colors.RESET} close your terminal. The building will not finish and will remain incomplete. If you do mess up, you will need to delete ${settings.Database} and restart the application.` })
52
- await importBroadcastify();
53
- await importShapefiles();
54
- setWarning({ message: `Building has completed, you can now continue or close the terminal`})
55
- }
56
- } catch (error) {
57
- setWarning({ message: `An error occurred while initializing the database: ${error.message}` })
58
- }
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+
21
+ import { TypeSettings } from "../../@types/type.settings"
22
+ import { bootstrap } from "../../bootstrap"
23
+ import { setWarning } from '../@utilities/utilities.setWarning'
24
+ import { importShapefiles } from './database.shapefiles'
25
+ import { importBroadcastify } from "./database.broadcastify"
26
+ import { existsSync, writeFileSync } from "fs"
27
+ import sqlite3 from 'better-sqlite3'
28
+
29
+ export const initializeDatabase = async (): Promise<void> => {
30
+ const settings = bootstrap.settings as TypeSettings;
31
+ try {
32
+ if (!existsSync(settings.Database)) {
33
+ writeFileSync(settings.Database, '')
34
+ setWarning({ message: `Creating new database at ${settings.Database}` })
35
+ }
36
+ bootstrap.database = new sqlite3(settings.Database);
37
+ bootstrap.database
38
+ .prepare(`CREATE TABLE IF NOT EXISTS stanzas ( id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, issued TEXT, stanza TEXT )`)
39
+ .run();
40
+ bootstrap.database
41
+ .prepare(`CREATE TABLE IF NOT EXISTS shapefiles (id TEXT PRIMARY KEY, location TEXT, geometry TEXT)`)
42
+ .run();
43
+ const isNeedingShapefiles = bootstrap.database
44
+ .prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='shapefiles';`)
45
+ .get();
46
+ const isNeedingBroadcastify = bootstrap.database
47
+ .prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='broadcastify';`)
48
+ .get();
49
+
50
+ if (!isNeedingShapefiles || !isNeedingBroadcastify) {
51
+ setWarning({message: `Required database tables are currently building, please ${bootstrap.ansi_colors.RED}DO NOT${bootstrap.ansi_colors.RESET} close your terminal. The building will not finish and will remain incomplete. If you do mess up, you will need to delete ${settings.Database} and restart the application.` })
52
+ await importBroadcastify();
53
+ await importShapefiles();
54
+ setWarning({ message: `Building has completed, you can now continue or close the terminal`})
55
+ }
56
+ } catch (error) {
57
+ setWarning({ message: `An error occurred while initializing the database: ${error.message}` })
58
+ }
59
59
  }
@@ -1,93 +1,93 @@
1
- /*
2
- _ _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
- Discord: https://atmosphericx-discord.scriptkitty.cafe
13
- Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
-
16
- Internal Package: @atmosx/event-product-parser
17
-
18
- */
19
-
20
- import { TypeSettings } from "../../@types/type.settings"
21
- import { dict_shapefiles } from '../../@dictionaries/dictionaries.shapefiles'
22
- import { bootstrap } from "../../bootstrap"
23
- import { setSleep } from '../@utilities/utilities.setSleep'
24
- import { setWarning } from '../@utilities/utilities.setWarning'
25
- import { existsSync, mkdirSync, writeFileSync, unlinkSync, rm } from "fs"
26
- import { resolve, extname} from 'path'
27
- import { loadAsync } from 'jszip'
28
- import { read } from 'shapefile'
29
-
30
- export const importShapefiles = async (): Promise<void> => {
31
- const settings = bootstrap.settings as TypeSettings;
32
- try {
33
- const tShapefiles = bootstrap.database
34
- .prepare(`SELECT COUNT(*) AS count FROM shapefiles`)
35
- .get().count;
36
- if (tShapefiles === 0) {
37
- await setSleep({timeout: 1e3});
38
- for (const shapefile of dict_shapefiles) {
39
- const response = await fetch(shapefile.link);
40
- const arrayBuff = await response.arrayBuffer();
41
- const content = await loadAsync(arrayBuff);
42
- const directory = resolve(__dirname, `../../shapefiles`);
43
- if (!existsSync(directory)) {
44
- mkdirSync(directory, { recursive: true });
45
- }
46
- for (const file of Object.keys(content.files)) {
47
- if (file.endsWith('.shp') || file.endsWith('.dbf')) {
48
- const data = await content.files[file].async(`nodebuffer`)
49
- const output = resolve(directory, `${shapefile?.name ?? ``}_${shapefile?.id ?? ``}${extname(file)}`)
50
- writeFileSync(output, data)
51
- }
52
- }
53
- const filepath = resolve(__dirname, '../../shapefiles', shapefile.name + '_' + shapefile.id)
54
- const { features } = await read(
55
- filepath,
56
- filepath,
57
- );
58
- setWarning({ message: `Importing ${features.length} features from ${shapefile.name}_${shapefile.id} for Shapefiles` })
59
- const insert = bootstrap.database
60
- .prepare(`INSERT OR REPLACE INTO shapefiles (id, location, geometry) VALUES (?, ?, ?)`)
61
- const transaction = bootstrap.database.transaction((entries: any[]) => {
62
- for (const entry of entries) {
63
- const { properties, geometry } = entry;
64
- let final: string, location: string;
65
- if (properties.FIPS) {
66
- final = `${properties.STATE}${shapefile.id}${properties.FIPS.substring(2)}`;
67
- location = `${properties.COUNTYNAME}, ${properties.STATE}`;
68
- }
69
- else if (properties.FULLSTAID) {
70
- final = `${properties.ST}${shapefile.id}${properties.WFO}`;
71
- location = `${properties.CITY}, ${properties.STATE}`;
72
- }
73
- else if (properties.STATE) {
74
- final = `${properties.STATE}${shapefile.id}${properties.ZONE ?? properties.SITE_ID}`;
75
- location = `${properties.NAME ?? `${properties.RFC_NAME} ${properties.RFC_CITY}`}, ${properties.STATE}`;
76
- }
77
- else {
78
- final = properties.ID ?? properties.WFO
79
- location = properties.NAME;
80
- }
81
- insert.run(final, location, JSON.stringify(geometry));
82
- }
83
- })
84
- unlinkSync(`${filepath}.shp`)
85
- unlinkSync(`${filepath}.dbf`)
86
- transaction(features)
87
- }
88
- rm(resolve(__dirname, '../../shapefiles'), { recursive: true, force: true }, () => {});
89
- }
90
- } catch (error) {
91
- setWarning( {message: `An error occurred while compiling shapefiles: ${error.message}` })
92
- }
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from "../../@types/type.settings"
21
+ import { dict_shapefiles } from '../../@dictionaries/dictionaries.shapefiles'
22
+ import { bootstrap } from "../../bootstrap"
23
+ import { setSleep } from '../@utilities/utilities.setSleep'
24
+ import { setWarning } from '../@utilities/utilities.setWarning'
25
+ import { existsSync, mkdirSync, writeFileSync, unlinkSync, rm } from "fs"
26
+ import { resolve, extname} from 'path'
27
+ import { loadAsync } from 'jszip'
28
+ import { read } from 'shapefile'
29
+
30
+ export const importShapefiles = async (): Promise<void> => {
31
+ const settings = bootstrap.settings as TypeSettings;
32
+ try {
33
+ const tShapefiles = bootstrap.database
34
+ .prepare(`SELECT COUNT(*) AS count FROM shapefiles`)
35
+ .get().count;
36
+ if (tShapefiles === 0) {
37
+ await setSleep({timeout: 1e3});
38
+ for (const shapefile of dict_shapefiles) {
39
+ const response = await fetch(shapefile.link);
40
+ const arrayBuff = await response.arrayBuffer();
41
+ const content = await loadAsync(arrayBuff);
42
+ const directory = resolve(__dirname, `../../shapefiles`);
43
+ if (!existsSync(directory)) {
44
+ mkdirSync(directory, { recursive: true });
45
+ }
46
+ for (const file of Object.keys(content.files)) {
47
+ if (file.endsWith('.shp') || file.endsWith('.dbf')) {
48
+ const data = await content.files[file].async(`nodebuffer`)
49
+ const output = resolve(directory, `${shapefile?.name ?? ``}_${shapefile?.id ?? ``}${extname(file)}`)
50
+ writeFileSync(output, data)
51
+ }
52
+ }
53
+ const filepath = resolve(__dirname, '../../shapefiles', shapefile.name + '_' + shapefile.id)
54
+ const { features } = await read(
55
+ filepath,
56
+ filepath,
57
+ );
58
+ setWarning({ message: `Importing ${features.length} features from ${shapefile.name}_${shapefile.id} for Shapefiles` })
59
+ const insert = bootstrap.database
60
+ .prepare(`INSERT OR REPLACE INTO shapefiles (id, location, geometry) VALUES (?, ?, ?)`)
61
+ const transaction = bootstrap.database.transaction((entries: any[]) => {
62
+ for (const entry of entries) {
63
+ const { properties, geometry } = entry;
64
+ let final: string, location: string;
65
+ if (properties.FIPS) {
66
+ final = `${properties.STATE}${shapefile.id}${properties.FIPS.substring(2)}`;
67
+ location = `${properties.COUNTYNAME}, ${properties.STATE}`;
68
+ }
69
+ else if (properties.FULLSTAID) {
70
+ final = `${properties.ST}${shapefile.id}${properties.WFO}`;
71
+ location = `${properties.CITY}, ${properties.STATE}`;
72
+ }
73
+ else if (properties.STATE) {
74
+ final = `${properties.STATE}${shapefile.id}${properties.ZONE ?? properties.SITE_ID}`;
75
+ location = `${properties.NAME ?? `${properties.RFC_NAME} ${properties.RFC_CITY}`}, ${properties.STATE}`;
76
+ }
77
+ else {
78
+ final = properties.ID ?? properties.WFO
79
+ location = properties.NAME;
80
+ }
81
+ insert.run(final, location, JSON.stringify(geometry));
82
+ }
83
+ })
84
+ unlinkSync(`${filepath}.shp`)
85
+ unlinkSync(`${filepath}.dbf`)
86
+ transaction(features)
87
+ }
88
+ rm(resolve(__dirname, '../../shapefiles'), { recursive: true, force: true }, () => {});
89
+ }
90
+ } catch (error) {
91
+ setWarning( {message: `An error occurred while compiling shapefiles: ${error.message}` })
92
+ }
93
93
  }
@@ -1,47 +1,47 @@
1
- /*
2
- _ _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
- Discord: https://atmosphericx-discord.scriptkitty.cafe
13
- Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
-
16
- Internal Package: @atmosx/event-product-parser
17
-
18
- */
19
-
20
- import { TypeSettings } from "../../@types/type.settings"
21
- import { TypeStanzaCompiled } from '../../@types/type.compiled';
22
- import { bootstrap } from '../../bootstrap'
23
- import { setWarning } from '../@utilities/utilities.setWarning';
24
-
25
- export const importStanza = async (stanza: TypeStanzaCompiled): Promise<void> => {
26
- const settings = bootstrap.settings as TypeSettings;
27
- try {
28
- if (!settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) { return }
29
- bootstrap.database
30
- .prepare(`INSERT OR IGNORE INTO stanzas (type, stanza, issued) VALUES (?, ?, ?)`)
31
- .run(stanza.getType.type, JSON.stringify(stanza), stanza.attributes.issue)
32
- const count = bootstrap.database
33
- .prepare(`SELECT COUNT(*) as total FROM stanzas`)
34
- .get() as { total: number }
35
- const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxDatabaseHistory;
36
- if (count.total > max) {
37
- const toDelete = count.total - max;
38
- if (toDelete > 0) {
39
- bootstrap.database
40
- .prepare(`DELETE FROM stanzas WHERE id IN (SELECT id FROM stanzas ORDER BY issued ASC LIMIT ?)`)
41
- .run(toDelete);
42
- }
43
- }
44
- } catch (error) {
45
- setWarning({ message: `An error occurred while importing stanza: ${error.message}` })
46
- }
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeSettings } from "../../@types/type.settings"
21
+ import { TypeStanzaCompiled } from '../../@types/type.compiled';
22
+ import { bootstrap } from '../../bootstrap'
23
+ import { setWarning } from '../@utilities/utilities.setWarning';
24
+
25
+ export const importStanza = async (stanza: TypeStanzaCompiled): Promise<void> => {
26
+ const settings = bootstrap.settings as TypeSettings;
27
+ try {
28
+ if (!settings.NOAAWeatherWireServiceSettings.CacheSettings.Enabled) { return }
29
+ bootstrap.database
30
+ .prepare(`INSERT OR IGNORE INTO stanzas (type, stanza, issued) VALUES (?, ?, ?)`)
31
+ .run(stanza.getType.type, JSON.stringify(stanza), stanza.attributes.issue)
32
+ const count = bootstrap.database
33
+ .prepare(`SELECT COUNT(*) as total FROM stanzas`)
34
+ .get() as { total: number }
35
+ const max = settings.NOAAWeatherWireServiceSettings.CacheSettings.MaxDatabaseHistory;
36
+ if (count.total > max) {
37
+ const toDelete = count.total - max;
38
+ if (toDelete > 0) {
39
+ bootstrap.database
40
+ .prepare(`DELETE FROM stanzas WHERE id IN (SELECT id FROM stanzas ORDER BY issued ASC LIMIT ?)`)
41
+ .run(toDelete);
42
+ }
43
+ }
44
+ } catch (error) {
45
+ setWarning({ message: `An error occurred while importing stanza: ${error.message}` })
46
+ }
47
47
  }