@vandenberghinc/volt 1.1.21 → 1.1.23

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.
@@ -1302,7 +1302,7 @@ class Server {
1302
1302
  // })
1303
1303
  }
1304
1304
  // Create the sitemap endpoint.
1305
- _create_sitemap() {
1305
+ async _create_sitemap() {
1306
1306
  // Logs.
1307
1307
  if (this.lightweight) {
1308
1308
  return;
@@ -1332,7 +1332,7 @@ class Server {
1332
1332
  });
1333
1333
  }
1334
1334
  // Create the robots.txt endpoint.
1335
- _create_robots_txt() {
1335
+ async _create_robots_txt() {
1336
1336
  // Logs.
1337
1337
  if (this.lightweight) {
1338
1338
  return;
@@ -1705,73 +1705,77 @@ class Server {
1705
1705
  });
1706
1706
  }
1707
1707
  /* @performance */ this.performance.end("create-http-server");
1708
+ let promises = [];
1708
1709
  // Start the database.
1709
1710
  if (this.db) {
1710
- await this.db.initialize();
1711
- /* @performance */ this.performance.end("init-db");
1712
- // Database collections.
1713
- this._sys_db = await this.db.collection({
1714
- name: "Volt.System",
1715
- indexes: ["_path"],
1716
- });
1717
- /* @performance */ this.performance.end("init-collections");
1718
- // Load keys.
1719
- const keys_document = await this._sys_db.load("keys");
1720
- const gen_user_crypto_key = (doc, key) => {
1721
- if (typeof key === "string") {
1722
- doc[key] = this.generate_crypto_key(32);
1723
- }
1724
- else {
1725
- if (key.length == null) {
1726
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1727
- }
1728
- if (typeof key.length !== "number") {
1729
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1730
- }
1731
- if (key.name == null) {
1732
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1711
+ promises.push(new Promise(async (resolve) => {
1712
+ await this.db.initialize();
1713
+ // /* @performance */ this.performance.end("init-db");
1714
+ // Database collections.
1715
+ this._sys_db = await this.db.collection({
1716
+ name: "Volt.System",
1717
+ indexes: ["_path"],
1718
+ });
1719
+ // /* @performance */ this.performance.end("init-collections");
1720
+ // Load keys.
1721
+ const keys_document = await this._sys_db.load("keys");
1722
+ const gen_user_crypto_key = (doc, key) => {
1723
+ if (typeof key === "string") {
1724
+ doc[key] = this.generate_crypto_key(32);
1733
1725
  }
1734
- if (typeof key.name !== "string") {
1735
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1726
+ else {
1727
+ if (key.length == null) {
1728
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1729
+ }
1730
+ if (typeof key.length !== "number") {
1731
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1732
+ }
1733
+ if (key.name == null) {
1734
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1735
+ }
1736
+ if (typeof key.name !== "string") {
1737
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1738
+ }
1739
+ doc[key.name] = this.generate_crypto_key(key.length);
1740
+ this.keys[key.name] = doc[key.name];
1736
1741
  }
1737
- doc[key.name] = this.generate_crypto_key(key.length);
1738
- this.keys[key.name] = doc[key.name];
1739
- }
1740
- };
1741
- if (keys_document == null) {
1742
- this._hash_key = this.generate_crypto_key(32);
1743
- const doc = {
1744
- _master_sha256: this._hash_key,
1745
1742
  };
1746
- this._keys.forEach((key) => {
1747
- gen_user_crypto_key(doc, key);
1748
- });
1749
- await this._sys_db.save("keys", doc);
1750
- }
1751
- else {
1752
- // Check hash key.
1753
- this._hash_key = keys_document._master_sha256;
1754
- let perform_save = false;
1755
- if (this._hash_key === undefined) {
1743
+ if (keys_document == null) {
1756
1744
  this._hash_key = this.generate_crypto_key(32);
1757
- keys_document._master_sha256 = this._hash_key;
1758
- perform_save = true;
1745
+ const doc = {
1746
+ _master_sha256: this._hash_key,
1747
+ };
1748
+ this._keys.forEach((key) => {
1749
+ gen_user_crypto_key(doc, key);
1750
+ });
1751
+ await this._sys_db.save("keys", doc);
1759
1752
  }
1760
- // Check crypto keys.
1761
- this._keys.forEach((key) => {
1762
- let name = typeof key === "string" ? key : key.name;
1763
- if (keys_document[name] == null) {
1764
- gen_user_crypto_key(keys_document, key);
1753
+ else {
1754
+ // Check hash key.
1755
+ this._hash_key = keys_document._master_sha256;
1756
+ let perform_save = false;
1757
+ if (this._hash_key === undefined) {
1758
+ this._hash_key = this.generate_crypto_key(32);
1759
+ keys_document._master_sha256 = this._hash_key;
1765
1760
  perform_save = true;
1766
1761
  }
1767
- this.keys[name] = keys_document[name];
1768
- });
1769
- // Save.
1770
- if (perform_save) {
1771
- await this._sys_db.save("keys", keys_document);
1762
+ // Check crypto keys.
1763
+ this._keys.forEach((key) => {
1764
+ let name = typeof key === "string" ? key : key.name;
1765
+ if (keys_document[name] == null) {
1766
+ gen_user_crypto_key(keys_document, key);
1767
+ perform_save = true;
1768
+ }
1769
+ this.keys[name] = keys_document[name];
1770
+ });
1771
+ // Save.
1772
+ if (perform_save) {
1773
+ await this._sys_db.save("keys", keys_document);
1774
+ }
1772
1775
  }
1773
- }
1774
- /* @performance */ this.performance.end("load-keys");
1776
+ // /* @performance */ this.performance.end("load-keys");
1777
+ resolve();
1778
+ }));
1775
1779
  }
1776
1780
  // Initialize default headers.
1777
1781
  this._init_default_headers();
@@ -1783,12 +1787,12 @@ class Server {
1783
1787
  // this._create_admin_endpoint();
1784
1788
  // /* @performance */ this.performance.end("create-admin-endpoints");
1785
1789
  // Create static endpoints.
1786
- await this._initialize_statics();
1787
- /* @performance */ this.performance.end("create-static-endpoints");
1790
+ promises.push(this._initialize_statics());
1791
+ // /* @performance */ this.performance.end("create-static-endpoints");
1788
1792
  // Initialize users.
1789
1793
  if (this.db) {
1790
- await this.users._initialize();
1791
- /* @performance */ this.performance.end("init-users");
1794
+ promises.push(this.users._initialize());
1795
+ // /* @performance */ this.performance.end("init-users");
1792
1796
  }
1793
1797
  // Database preview endpoints (only when production mode is disabled).
1794
1798
  // if (this.db) {
@@ -1797,9 +1801,23 @@ class Server {
1797
1801
  // }
1798
1802
  // Payments.
1799
1803
  if (this.payments !== undefined) {
1800
- await this.payments._initialize();
1804
+ promises.push(this.payments._initialize());
1805
+ }
1806
+ // /* @performance */ this.performance.end("init-payments");
1807
+ // Create sitemap when it does not exist.
1808
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1809
+ if (this._find_endpoint("sitemap.xml") == null) {
1810
+ promises.push(this._create_sitemap());
1801
1811
  }
1802
- /* @performance */ this.performance.end("init-payments");
1812
+ // /* @performance */ this.performance.end("create-sitemap");
1813
+ // Create robots.txt when it does not exist.
1814
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1815
+ if (this._find_endpoint("robots.txt") == null) {
1816
+ promises.push(this._create_robots_txt());
1817
+ }
1818
+ // /* @performance */ this.performance.end("create-robots.txt");
1819
+ // Await all promises.
1820
+ await Promise.all(promises);
1803
1821
  // Get the icon and stroke icon file paths when defined.
1804
1822
  if (this.company.stroke_icon || this.company.icon) {
1805
1823
  for (const endpoint of this.endpoints.values()) {
@@ -1817,19 +1835,6 @@ class Server {
1817
1835
  throw Error(`Unable to find the company's icon endpoint "${this.company.icon}".`);
1818
1836
  }
1819
1837
  }
1820
- /* @performance */ this.performance.end("init-icons");
1821
- // Create sitemap when it does not exist.
1822
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1823
- if (this._find_endpoint("sitemap.xml") == null) {
1824
- this._create_sitemap();
1825
- }
1826
- /* @performance */ this.performance.end("create-sitemap");
1827
- // Create robots.txt when it does not exist.
1828
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1829
- if (this._find_endpoint("robots.txt") == null) {
1830
- this._create_robots_txt();
1831
- }
1832
- /* @performance */ this.performance.end("create-robots.txt");
1833
1838
  // On initialize callbacks.
1834
1839
  for (const callback of this._on_initialize) {
1835
1840
  const res = callback();
@@ -1263,7 +1263,7 @@ export class Server {
1263
1263
  // })
1264
1264
  }
1265
1265
  // Create the sitemap endpoint.
1266
- _create_sitemap() {
1266
+ async _create_sitemap() {
1267
1267
  // Logs.
1268
1268
  if (this.lightweight) {
1269
1269
  return;
@@ -1293,7 +1293,7 @@ export class Server {
1293
1293
  });
1294
1294
  }
1295
1295
  // Create the robots.txt endpoint.
1296
- _create_robots_txt() {
1296
+ async _create_robots_txt() {
1297
1297
  // Logs.
1298
1298
  if (this.lightweight) {
1299
1299
  return;
@@ -1666,73 +1666,77 @@ export class Server {
1666
1666
  });
1667
1667
  }
1668
1668
  /* @performance */ this.performance.end("create-http-server");
1669
+ let promises = [];
1669
1670
  // Start the database.
1670
1671
  if (this.db) {
1671
- await this.db.initialize();
1672
- /* @performance */ this.performance.end("init-db");
1673
- // Database collections.
1674
- this._sys_db = await this.db.collection({
1675
- name: "Volt.System",
1676
- indexes: ["_path"],
1677
- });
1678
- /* @performance */ this.performance.end("init-collections");
1679
- // Load keys.
1680
- const keys_document = await this._sys_db.load("keys");
1681
- const gen_user_crypto_key = (doc, key) => {
1682
- if (typeof key === "string") {
1683
- doc[key] = this.generate_crypto_key(32);
1684
- }
1685
- else {
1686
- if (key.length == null) {
1687
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1688
- }
1689
- if (typeof key.length !== "number") {
1690
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1691
- }
1692
- if (key.name == null) {
1693
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1672
+ promises.push(new Promise(async (resolve) => {
1673
+ await this.db.initialize();
1674
+ // /* @performance */ this.performance.end("init-db");
1675
+ // Database collections.
1676
+ this._sys_db = await this.db.collection({
1677
+ name: "Volt.System",
1678
+ indexes: ["_path"],
1679
+ });
1680
+ // /* @performance */ this.performance.end("init-collections");
1681
+ // Load keys.
1682
+ const keys_document = await this._sys_db.load("keys");
1683
+ const gen_user_crypto_key = (doc, key) => {
1684
+ if (typeof key === "string") {
1685
+ doc[key] = this.generate_crypto_key(32);
1694
1686
  }
1695
- if (typeof key.name !== "string") {
1696
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1687
+ else {
1688
+ if (key.length == null) {
1689
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1690
+ }
1691
+ if (typeof key.length !== "number") {
1692
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1693
+ }
1694
+ if (key.name == null) {
1695
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1696
+ }
1697
+ if (typeof key.name !== "string") {
1698
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1699
+ }
1700
+ doc[key.name] = this.generate_crypto_key(key.length);
1701
+ this.keys[key.name] = doc[key.name];
1697
1702
  }
1698
- doc[key.name] = this.generate_crypto_key(key.length);
1699
- this.keys[key.name] = doc[key.name];
1700
- }
1701
- };
1702
- if (keys_document == null) {
1703
- this._hash_key = this.generate_crypto_key(32);
1704
- const doc = {
1705
- _master_sha256: this._hash_key,
1706
1703
  };
1707
- this._keys.forEach((key) => {
1708
- gen_user_crypto_key(doc, key);
1709
- });
1710
- await this._sys_db.save("keys", doc);
1711
- }
1712
- else {
1713
- // Check hash key.
1714
- this._hash_key = keys_document._master_sha256;
1715
- let perform_save = false;
1716
- if (this._hash_key === undefined) {
1704
+ if (keys_document == null) {
1717
1705
  this._hash_key = this.generate_crypto_key(32);
1718
- keys_document._master_sha256 = this._hash_key;
1719
- perform_save = true;
1706
+ const doc = {
1707
+ _master_sha256: this._hash_key,
1708
+ };
1709
+ this._keys.forEach((key) => {
1710
+ gen_user_crypto_key(doc, key);
1711
+ });
1712
+ await this._sys_db.save("keys", doc);
1720
1713
  }
1721
- // Check crypto keys.
1722
- this._keys.forEach((key) => {
1723
- let name = typeof key === "string" ? key : key.name;
1724
- if (keys_document[name] == null) {
1725
- gen_user_crypto_key(keys_document, key);
1714
+ else {
1715
+ // Check hash key.
1716
+ this._hash_key = keys_document._master_sha256;
1717
+ let perform_save = false;
1718
+ if (this._hash_key === undefined) {
1719
+ this._hash_key = this.generate_crypto_key(32);
1720
+ keys_document._master_sha256 = this._hash_key;
1726
1721
  perform_save = true;
1727
1722
  }
1728
- this.keys[name] = keys_document[name];
1729
- });
1730
- // Save.
1731
- if (perform_save) {
1732
- await this._sys_db.save("keys", keys_document);
1723
+ // Check crypto keys.
1724
+ this._keys.forEach((key) => {
1725
+ let name = typeof key === "string" ? key : key.name;
1726
+ if (keys_document[name] == null) {
1727
+ gen_user_crypto_key(keys_document, key);
1728
+ perform_save = true;
1729
+ }
1730
+ this.keys[name] = keys_document[name];
1731
+ });
1732
+ // Save.
1733
+ if (perform_save) {
1734
+ await this._sys_db.save("keys", keys_document);
1735
+ }
1733
1736
  }
1734
- }
1735
- /* @performance */ this.performance.end("load-keys");
1737
+ // /* @performance */ this.performance.end("load-keys");
1738
+ resolve();
1739
+ }));
1736
1740
  }
1737
1741
  // Initialize default headers.
1738
1742
  this._init_default_headers();
@@ -1744,12 +1748,12 @@ export class Server {
1744
1748
  // this._create_admin_endpoint();
1745
1749
  // /* @performance */ this.performance.end("create-admin-endpoints");
1746
1750
  // Create static endpoints.
1747
- await this._initialize_statics();
1748
- /* @performance */ this.performance.end("create-static-endpoints");
1751
+ promises.push(this._initialize_statics());
1752
+ // /* @performance */ this.performance.end("create-static-endpoints");
1749
1753
  // Initialize users.
1750
1754
  if (this.db) {
1751
- await this.users._initialize();
1752
- /* @performance */ this.performance.end("init-users");
1755
+ promises.push(this.users._initialize());
1756
+ // /* @performance */ this.performance.end("init-users");
1753
1757
  }
1754
1758
  // Database preview endpoints (only when production mode is disabled).
1755
1759
  // if (this.db) {
@@ -1758,9 +1762,23 @@ export class Server {
1758
1762
  // }
1759
1763
  // Payments.
1760
1764
  if (this.payments !== undefined) {
1761
- await this.payments._initialize();
1765
+ promises.push(this.payments._initialize());
1766
+ }
1767
+ // /* @performance */ this.performance.end("init-payments");
1768
+ // Create sitemap when it does not exist.
1769
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1770
+ if (this._find_endpoint("sitemap.xml") == null) {
1771
+ promises.push(this._create_sitemap());
1762
1772
  }
1763
- /* @performance */ this.performance.end("init-payments");
1773
+ // /* @performance */ this.performance.end("create-sitemap");
1774
+ // Create robots.txt when it does not exist.
1775
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1776
+ if (this._find_endpoint("robots.txt") == null) {
1777
+ promises.push(this._create_robots_txt());
1778
+ }
1779
+ // /* @performance */ this.performance.end("create-robots.txt");
1780
+ // Await all promises.
1781
+ await Promise.all(promises);
1764
1782
  // Get the icon and stroke icon file paths when defined.
1765
1783
  if (this.company.stroke_icon || this.company.icon) {
1766
1784
  for (const endpoint of this.endpoints.values()) {
@@ -1778,19 +1796,6 @@ export class Server {
1778
1796
  throw Error(`Unable to find the company's icon endpoint "${this.company.icon}".`);
1779
1797
  }
1780
1798
  }
1781
- /* @performance */ this.performance.end("init-icons");
1782
- // Create sitemap when it does not exist.
1783
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1784
- if (this._find_endpoint("sitemap.xml") == null) {
1785
- this._create_sitemap();
1786
- }
1787
- /* @performance */ this.performance.end("create-sitemap");
1788
- // Create robots.txt when it does not exist.
1789
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1790
- if (this._find_endpoint("robots.txt") == null) {
1791
- this._create_robots_txt();
1792
- }
1793
- /* @performance */ this.performance.end("create-robots.txt");
1794
1799
  // On initialize callbacks.
1795
1800
  for (const callback of this._on_initialize) {
1796
1801
  const res = callback();
@@ -1263,7 +1263,7 @@ export class Server {
1263
1263
  // })
1264
1264
  }
1265
1265
  // Create the sitemap endpoint.
1266
- _create_sitemap() {
1266
+ async _create_sitemap() {
1267
1267
  // Logs.
1268
1268
  if (this.lightweight) {
1269
1269
  return;
@@ -1293,7 +1293,7 @@ export class Server {
1293
1293
  });
1294
1294
  }
1295
1295
  // Create the robots.txt endpoint.
1296
- _create_robots_txt() {
1296
+ async _create_robots_txt() {
1297
1297
  // Logs.
1298
1298
  if (this.lightweight) {
1299
1299
  return;
@@ -1666,73 +1666,77 @@ export class Server {
1666
1666
  });
1667
1667
  }
1668
1668
  /* @performance */ this.performance.end("create-http-server");
1669
+ let promises = [];
1669
1670
  // Start the database.
1670
1671
  if (this.db) {
1671
- await this.db.initialize();
1672
- /* @performance */ this.performance.end("init-db");
1673
- // Database collections.
1674
- this._sys_db = await this.db.collection({
1675
- name: "Volt.System",
1676
- indexes: ["_path"],
1677
- });
1678
- /* @performance */ this.performance.end("init-collections");
1679
- // Load keys.
1680
- const keys_document = await this._sys_db.load("keys");
1681
- const gen_user_crypto_key = (doc, key) => {
1682
- if (typeof key === "string") {
1683
- doc[key] = this.generate_crypto_key(32);
1684
- }
1685
- else {
1686
- if (key.length == null) {
1687
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1688
- }
1689
- if (typeof key.length !== "number") {
1690
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1691
- }
1692
- if (key.name == null) {
1693
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1672
+ promises.push(new Promise(async (resolve) => {
1673
+ await this.db.initialize();
1674
+ // /* @performance */ this.performance.end("init-db");
1675
+ // Database collections.
1676
+ this._sys_db = await this.db.collection({
1677
+ name: "Volt.System",
1678
+ indexes: ["_path"],
1679
+ });
1680
+ // /* @performance */ this.performance.end("init-collections");
1681
+ // Load keys.
1682
+ const keys_document = await this._sys_db.load("keys");
1683
+ const gen_user_crypto_key = (doc, key) => {
1684
+ if (typeof key === "string") {
1685
+ doc[key] = this.generate_crypto_key(32);
1694
1686
  }
1695
- if (typeof key.name !== "string") {
1696
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1687
+ else {
1688
+ if (key.length == null) {
1689
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1690
+ }
1691
+ if (typeof key.length !== "number") {
1692
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1693
+ }
1694
+ if (key.name == null) {
1695
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1696
+ }
1697
+ if (typeof key.name !== "string") {
1698
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1699
+ }
1700
+ doc[key.name] = this.generate_crypto_key(key.length);
1701
+ this.keys[key.name] = doc[key.name];
1697
1702
  }
1698
- doc[key.name] = this.generate_crypto_key(key.length);
1699
- this.keys[key.name] = doc[key.name];
1700
- }
1701
- };
1702
- if (keys_document == null) {
1703
- this._hash_key = this.generate_crypto_key(32);
1704
- const doc = {
1705
- _master_sha256: this._hash_key,
1706
1703
  };
1707
- this._keys.forEach((key) => {
1708
- gen_user_crypto_key(doc, key);
1709
- });
1710
- await this._sys_db.save("keys", doc);
1711
- }
1712
- else {
1713
- // Check hash key.
1714
- this._hash_key = keys_document._master_sha256;
1715
- let perform_save = false;
1716
- if (this._hash_key === undefined) {
1704
+ if (keys_document == null) {
1717
1705
  this._hash_key = this.generate_crypto_key(32);
1718
- keys_document._master_sha256 = this._hash_key;
1719
- perform_save = true;
1706
+ const doc = {
1707
+ _master_sha256: this._hash_key,
1708
+ };
1709
+ this._keys.forEach((key) => {
1710
+ gen_user_crypto_key(doc, key);
1711
+ });
1712
+ await this._sys_db.save("keys", doc);
1720
1713
  }
1721
- // Check crypto keys.
1722
- this._keys.forEach((key) => {
1723
- let name = typeof key === "string" ? key : key.name;
1724
- if (keys_document[name] == null) {
1725
- gen_user_crypto_key(keys_document, key);
1714
+ else {
1715
+ // Check hash key.
1716
+ this._hash_key = keys_document._master_sha256;
1717
+ let perform_save = false;
1718
+ if (this._hash_key === undefined) {
1719
+ this._hash_key = this.generate_crypto_key(32);
1720
+ keys_document._master_sha256 = this._hash_key;
1726
1721
  perform_save = true;
1727
1722
  }
1728
- this.keys[name] = keys_document[name];
1729
- });
1730
- // Save.
1731
- if (perform_save) {
1732
- await this._sys_db.save("keys", keys_document);
1723
+ // Check crypto keys.
1724
+ this._keys.forEach((key) => {
1725
+ let name = typeof key === "string" ? key : key.name;
1726
+ if (keys_document[name] == null) {
1727
+ gen_user_crypto_key(keys_document, key);
1728
+ perform_save = true;
1729
+ }
1730
+ this.keys[name] = keys_document[name];
1731
+ });
1732
+ // Save.
1733
+ if (perform_save) {
1734
+ await this._sys_db.save("keys", keys_document);
1735
+ }
1733
1736
  }
1734
- }
1735
- /* @performance */ this.performance.end("load-keys");
1737
+ // /* @performance */ this.performance.end("load-keys");
1738
+ resolve();
1739
+ }));
1736
1740
  }
1737
1741
  // Initialize default headers.
1738
1742
  this._init_default_headers();
@@ -1744,12 +1748,12 @@ export class Server {
1744
1748
  // this._create_admin_endpoint();
1745
1749
  // /* @performance */ this.performance.end("create-admin-endpoints");
1746
1750
  // Create static endpoints.
1747
- await this._initialize_statics();
1748
- /* @performance */ this.performance.end("create-static-endpoints");
1751
+ promises.push(this._initialize_statics());
1752
+ // /* @performance */ this.performance.end("create-static-endpoints");
1749
1753
  // Initialize users.
1750
1754
  if (this.db) {
1751
- await this.users._initialize();
1752
- /* @performance */ this.performance.end("init-users");
1755
+ promises.push(this.users._initialize());
1756
+ // /* @performance */ this.performance.end("init-users");
1753
1757
  }
1754
1758
  // Database preview endpoints (only when production mode is disabled).
1755
1759
  // if (this.db) {
@@ -1758,9 +1762,23 @@ export class Server {
1758
1762
  // }
1759
1763
  // Payments.
1760
1764
  if (this.payments !== undefined) {
1761
- await this.payments._initialize();
1765
+ promises.push(this.payments._initialize());
1766
+ }
1767
+ // /* @performance */ this.performance.end("init-payments");
1768
+ // Create sitemap when it does not exist.
1769
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1770
+ if (this._find_endpoint("sitemap.xml") == null) {
1771
+ promises.push(this._create_sitemap());
1762
1772
  }
1763
- /* @performance */ this.performance.end("init-payments");
1773
+ // /* @performance */ this.performance.end("create-sitemap");
1774
+ // Create robots.txt when it does not exist.
1775
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
1776
+ if (this._find_endpoint("robots.txt") == null) {
1777
+ promises.push(this._create_robots_txt());
1778
+ }
1779
+ // /* @performance */ this.performance.end("create-robots.txt");
1780
+ // Await all promises.
1781
+ await Promise.all(promises);
1764
1782
  // Get the icon and stroke icon file paths when defined.
1765
1783
  if (this.company.stroke_icon || this.company.icon) {
1766
1784
  for (const endpoint of this.endpoints.values()) {
@@ -1778,19 +1796,6 @@ export class Server {
1778
1796
  throw Error(`Unable to find the company's icon endpoint "${this.company.icon}".`);
1779
1797
  }
1780
1798
  }
1781
- /* @performance */ this.performance.end("init-icons");
1782
- // Create sitemap when it does not exist.
1783
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1784
- if (this._find_endpoint("sitemap.xml") == null) {
1785
- this._create_sitemap();
1786
- }
1787
- /* @performance */ this.performance.end("create-sitemap");
1788
- // Create robots.txt when it does not exist.
1789
- // Must be done at the end of initialization func since some funcs might still create endpoints.
1790
- if (this._find_endpoint("robots.txt") == null) {
1791
- this._create_robots_txt();
1792
- }
1793
- /* @performance */ this.performance.end("create-robots.txt");
1794
1799
  // On initialize callbacks.
1795
1800
  for (const callback of this._on_initialize) {
1796
1801
  const res = callback();
@@ -1480,7 +1480,7 @@ export class Server {
1480
1480
  }
1481
1481
 
1482
1482
  // Create the sitemap endpoint.
1483
- private _create_sitemap(): void {
1483
+ private async _create_sitemap(): Promise<void> {
1484
1484
 
1485
1485
  // Logs.
1486
1486
  if (this.lightweight) { return; }
@@ -1511,7 +1511,7 @@ export class Server {
1511
1511
  }
1512
1512
 
1513
1513
  // Create the robots.txt endpoint.
1514
- private _create_robots_txt(): void {
1514
+ private async _create_robots_txt(): Promise<void> {
1515
1515
 
1516
1516
  // Logs.
1517
1517
  if (this.lightweight) { return; }
@@ -1920,77 +1920,82 @@ export class Server {
1920
1920
  }
1921
1921
 
1922
1922
  /* @performance */ this.performance.end("create-http-server");
1923
+
1924
+ let promises: Promise<any>[] = [];
1923
1925
 
1924
1926
  // Start the database.
1925
1927
  if (this.db) {
1926
- await this.db.initialize();
1927
- /* @performance */ this.performance.end("init-db");
1928
-
1929
- // Database collections.
1930
- this._sys_db = await this.db.collection({
1931
- name: "Volt.System",
1932
- indexes: [ "_path" ],
1933
- });
1934
- /* @performance */ this.performance.end("init-collections");
1935
-
1936
- // Load keys.
1937
- const keys_document = await this._sys_db.load("keys");
1938
- const gen_user_crypto_key = (doc: Record<string, any>, key: string | {name: string, length: number}) => {
1939
- if (typeof key === "string") {
1940
- doc[key] = this.generate_crypto_key(32);
1941
- } else {
1942
- if (key.length == null) {
1943
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1944
- }
1945
- if (typeof key.length !== "number") {
1946
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1947
- }
1948
- if (key.name == null) {
1949
- throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1950
- }
1951
- if (typeof key.name !== "string") {
1952
- throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1928
+ promises.push(new Promise<void>(async resolve => {
1929
+ await this.db.initialize();
1930
+ // /* @performance */ this.performance.end("init-db");
1931
+
1932
+ // Database collections.
1933
+ this._sys_db = await this.db.collection({
1934
+ name: "Volt.System",
1935
+ indexes: [ "_path" ],
1936
+ });
1937
+ // /* @performance */ this.performance.end("init-collections");
1938
+
1939
+ // Load keys.
1940
+ const keys_document = await this._sys_db.load("keys");
1941
+ const gen_user_crypto_key = (doc: Record<string, any>, key: string | {name: string, length: number}) => {
1942
+ if (typeof key === "string") {
1943
+ doc[key] = this.generate_crypto_key(32);
1944
+ } else {
1945
+ if (key.length == null) {
1946
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "length" attribute.`);
1947
+ }
1948
+ if (typeof key.length !== "number") {
1949
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "length", the valid type is "number".`);
1950
+ }
1951
+ if (key.name == null) {
1952
+ throw Error(`Crypto key object "${JSON.stringify(key)}" does not contain a "name" attribute.`);
1953
+ }
1954
+ if (typeof key.name !== "string") {
1955
+ throw Error(`Crypto key object "${JSON.stringify(key)}" has an invalid type fo attribute "name", the valid type is "string".`);
1956
+ }
1957
+ doc[key.name] = this.generate_crypto_key(key.length);
1958
+ this.keys[key.name] = doc[key.name];
1953
1959
  }
1954
- doc[key.name] = this.generate_crypto_key(key.length);
1955
- this.keys[key.name] = doc[key.name];
1956
1960
  }
1957
- }
1958
- if (keys_document == null) {
1959
- this._hash_key = this.generate_crypto_key(32);
1960
- const doc: Record<string, string> = {
1961
- _master_sha256: this._hash_key,
1962
- };
1963
- this._keys.forEach((key) => {
1964
- gen_user_crypto_key(doc, key);
1965
- })
1966
- await this._sys_db.save("keys", doc);
1967
- } else {
1968
- // Check hash key.
1969
- this._hash_key = keys_document._master_sha256;
1970
- let perform_save = false;
1971
- if (this._hash_key === undefined) {
1961
+ if (keys_document == null) {
1972
1962
  this._hash_key = this.generate_crypto_key(32);
1973
- keys_document._master_sha256 = this._hash_key;
1974
- perform_save = true;
1975
- }
1976
-
1977
- // Check crypto keys.
1978
- this._keys.forEach((key) => {
1979
- let name = typeof key === "string" ? key : key.name;
1980
- if (keys_document[name] == null) {
1981
- gen_user_crypto_key(keys_document, key);
1963
+ const doc: Record<string, string> = {
1964
+ _master_sha256: this._hash_key,
1965
+ };
1966
+ this._keys.forEach((key) => {
1967
+ gen_user_crypto_key(doc, key);
1968
+ })
1969
+ await this._sys_db.save("keys", doc);
1970
+ } else {
1971
+ // Check hash key.
1972
+ this._hash_key = keys_document._master_sha256;
1973
+ let perform_save = false;
1974
+ if (this._hash_key === undefined) {
1975
+ this._hash_key = this.generate_crypto_key(32);
1976
+ keys_document._master_sha256 = this._hash_key;
1982
1977
  perform_save = true;
1983
1978
  }
1984
- this.keys[name] = keys_document[name];
1985
- })
1986
1979
 
1987
- // Save.
1988
- if (perform_save) {
1989
- await this._sys_db.save("keys", keys_document);
1980
+ // Check crypto keys.
1981
+ this._keys.forEach((key) => {
1982
+ let name = typeof key === "string" ? key : key.name;
1983
+ if (keys_document[name] == null) {
1984
+ gen_user_crypto_key(keys_document, key);
1985
+ perform_save = true;
1986
+ }
1987
+ this.keys[name] = keys_document[name];
1988
+ })
1989
+
1990
+ // Save.
1991
+ if (perform_save) {
1992
+ await this._sys_db.save("keys", keys_document);
1993
+ }
1990
1994
  }
1991
- }
1992
1995
 
1993
- /* @performance */ this.performance.end("load-keys");
1996
+ // /* @performance */ this.performance.end("load-keys");
1997
+ resolve();
1998
+ }));
1994
1999
  }
1995
2000
 
1996
2001
  // Initialize default headers.
@@ -2006,13 +2011,13 @@ export class Server {
2006
2011
  // /* @performance */ this.performance.end("create-admin-endpoints");
2007
2012
 
2008
2013
  // Create static endpoints.
2009
- await this._initialize_statics();
2010
- /* @performance */ this.performance.end("create-static-endpoints");
2014
+ promises.push(this._initialize_statics());
2015
+ // /* @performance */ this.performance.end("create-static-endpoints");
2011
2016
 
2012
2017
  // Initialize users.
2013
2018
  if (this.db) {
2014
- await this.users._initialize();
2015
- /* @performance */ this.performance.end("init-users");
2019
+ promises.push(this.users._initialize());
2020
+ // /* @performance */ this.performance.end("init-users");
2016
2021
  }
2017
2022
 
2018
2023
  // Database preview endpoints (only when production mode is disabled).
@@ -2023,9 +2028,26 @@ export class Server {
2023
2028
 
2024
2029
  // Payments.
2025
2030
  if (this.payments !== undefined) {
2026
- await this.payments._initialize();
2031
+ promises.push(this.payments._initialize());
2032
+ }
2033
+ // /* @performance */ this.performance.end("init-payments");
2034
+
2035
+ // Create sitemap when it does not exist.
2036
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
2037
+ if (this._find_endpoint("sitemap.xml") == null) {
2038
+ promises.push(this._create_sitemap());
2039
+ }
2040
+ // /* @performance */ this.performance.end("create-sitemap");
2041
+
2042
+ // Create robots.txt when it does not exist.
2043
+ // Must be done at the end of initialization func since some funcs might still create endpoints.
2044
+ if (this._find_endpoint("robots.txt") == null) {
2045
+ promises.push(this._create_robots_txt());
2027
2046
  }
2028
- /* @performance */ this.performance.end("init-payments");
2047
+ // /* @performance */ this.performance.end("create-robots.txt");
2048
+
2049
+ // Await all promises.
2050
+ await Promise.all(promises);
2029
2051
 
2030
2052
  // Get the icon and stroke icon file paths when defined.
2031
2053
  if (this.company.stroke_icon || this.company.icon) {
@@ -2045,22 +2067,6 @@ export class Server {
2045
2067
  }
2046
2068
  }
2047
2069
 
2048
- /* @performance */ this.performance.end("init-icons");
2049
-
2050
- // Create sitemap when it does not exist.
2051
- // Must be done at the end of initialization func since some funcs might still create endpoints.
2052
- if (this._find_endpoint("sitemap.xml") == null) {
2053
- this._create_sitemap();
2054
- }
2055
- /* @performance */ this.performance.end("create-sitemap");
2056
-
2057
- // Create robots.txt when it does not exist.
2058
- // Must be done at the end of initialization func since some funcs might still create endpoints.
2059
- if (this._find_endpoint("robots.txt") == null) {
2060
- this._create_robots_txt();
2061
- }
2062
- /* @performance */ this.performance.end("create-robots.txt");
2063
-
2064
2070
  // On initialize callbacks.
2065
2071
  for (const callback of this._on_initialize) {
2066
2072
  const res = callback();
@@ -490,7 +490,7 @@ export declare abstract class VElement extends HTMLElement {
490
490
  /**
491
491
  * Set a square frame width and height.
492
492
  */
493
- square(size: string | number): this;
493
+ square(size?: string | number): this;
494
494
  /** Set circle border radius */
495
495
  circle(): this;
496
496
  /**
@@ -1047,7 +1047,7 @@ export class VElement extends HTMLElement {
1047
1047
  /**
1048
1048
  * Set a square frame width and height.
1049
1049
  */
1050
- square(size) {
1050
+ square(size = "100%") {
1051
1051
  this.flex(0).fixed_frame(size, size);
1052
1052
  return this;
1053
1053
  }
@@ -1265,7 +1265,7 @@ export abstract class VElement extends HTMLElement {
1265
1265
  /**
1266
1266
  * Set a square frame width and height.
1267
1267
  */
1268
- square(size: string | number): this {
1268
+ square(size: string | number = "100%"): this {
1269
1269
  this.flex(0).fixed_frame(size, size);
1270
1270
  return this;
1271
1271
  }
@@ -4157,6 +4157,11 @@ export abstract class VElement extends HTMLElement {
4157
4157
  * @description Returns the instance of the element for chaining when an argument is passed, otherwise returns the current onclick handler.
4158
4158
  * @funcs: 2
4159
4159
  */
4160
+ /**
4161
+ * @warning NEVER change that this overrides the last on click callback
4162
+ * Volt & libris depend on this behaviour.
4163
+ * Let users add multiple etc using the `on()` method.
4164
+ */
4160
4165
  on_click(): null | Function;
4161
4166
  on_click(simulate_href: string | null, callback: Function): this;
4162
4167
  on_click(callback?: Function): this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Daan van den Bergh",
3
3
  "name": "@vandenberghinc/volt",
4
- "version": "1.1.21",
4
+ "version": "1.1.23",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "types": "./backend/dist/esm/volt.d.ts",
@@ -51,9 +51,9 @@
51
51
  "@rollup/plugin-terser": "^0.4.4",
52
52
  "@rollup/plugin-typescript": "^12.1.2",
53
53
  "@rollup/plugin-url": "^8.0.2",
54
- "@vandenberghinc/vhighlight": "1.3.13",
55
- "@vandenberghinc/vlib": "1.5.14",
56
- "@vandenberghinc/volt": "1.1.20",
54
+ "@vandenberghinc/vhighlight": "1.3.14",
55
+ "@vandenberghinc/vlib": "1.5.15",
56
+ "@vandenberghinc/volt": "1.1.21",
57
57
  "blob-stream": "^0.1.3",
58
58
  "clean-css": "^5.3.3",
59
59
  "esbuild": "^0.25.0",