socket-function 0.136.0 → 0.138.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.
package/SocketFunction.ts CHANGED
@@ -26,10 +26,10 @@ if (isNode()) {
26
26
  // not a good alternative to proper error log and notifications. Do you guys
27
27
  // not get automated emails when unexpected errors are logged? I do.
28
28
  process.on("unhandledRejection", (e) => {
29
- console.error("Unhandled rejection", e);
29
+ console.error("Unhandled rejection" + ((e as any)?.stack || e));
30
30
  });
31
31
  process.on("uncaughtException", (e) => {
32
- console.error("Uncaught exception", e);
32
+ console.error("Uncaught exception" + ((e as any)?.stack || e));
33
33
  });
34
34
  }
35
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.136.0",
3
+ "version": "0.138.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -362,9 +362,8 @@ export function requireMain() {
362
362
  };
363
363
  try {
364
364
  resultObj = JSON.parse(rawText);
365
- } catch (e) {
366
- console.log(rawText);
367
- throw e;
365
+ } catch (e: any) {
366
+ throw new Error(`Failed to require modules (likely permissions errors): ${JSON.stringify(requests)}. Start of response was: ${JSON.stringify(rawText.slice(0, 100))}. Error is: ${e.stack}`);
368
367
  }
369
368
  let { modules, requestsResolvedPaths, requireSeqNumProcessId, error } = resultObj;
370
369
 
@@ -230,6 +230,31 @@ export function formatDateTime(time: number) {
230
230
  return date.getFullYear() + "/" + p(date.getMonth() + 1) + "/" + p(date.getDate()) + " " + strTime;
231
231
  }
232
232
 
233
+ export function formatDateTimeDetailed(time: number) {
234
+ function p(s: number) {
235
+ return s.toString().padStart(2, "0");
236
+ }
237
+ let date = new Date(time);
238
+ let hours = date.getHours();
239
+ let minutes = date.getMinutes();
240
+ let seconds = date.getSeconds();
241
+ let milliseconds = date.getMilliseconds();
242
+ let millisecondsString = milliseconds.toString().padStart(3, "0");
243
+
244
+ let timeString = time.toString();
245
+ let decimalIndex = timeString.indexOf(".");
246
+ if (decimalIndex !== -1) {
247
+ let fractionalPart = timeString.substring(decimalIndex + 4);
248
+ millisecondsString += fractionalPart;
249
+ }
250
+
251
+ let ampm = hours >= 12 ? "PM" : "AM";
252
+ hours = hours % 12;
253
+ hours = hours ? hours : 12; // the hour '0' should be '12'
254
+ let strTime = p(hours) + ":" + p(minutes) + ":" + p(seconds) + "." + millisecondsString + " " + ampm;
255
+ return date.getFullYear() + "/" + p(date.getMonth() + 1) + "/" + p(date.getDate()) + " " + strTime;
256
+ }
257
+
233
258
  /** 2024 January 1, Monday, 12:53:02pm */
234
259
  export function formatNiceDateTime(time: number) {
235
260
  function p(s: number) {
package/src/https.ts CHANGED
@@ -96,7 +96,7 @@ export function httpsRequest(
96
96
  }
97
97
  return new Promise((resolve, reject) => {
98
98
  request.onload = () => {
99
- if (request.status !== 200) {
99
+ if (!request.status.toString().startsWith("2")) {
100
100
  try {
101
101
  // It should be an error.stack. But if it isn't... just throw the status text...
102
102
  let responseText = textDecoder.decode(request.response);
@@ -40,11 +40,11 @@ const noDiskLogPrefix = "█ ";
40
40
  export function measureFnc(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
41
41
  let name = propertyKey;
42
42
  if (target.name) {
43
- name = `${target.name}.${name}`;
43
+ name = `${target.name}|${name}`;
44
44
  } else {
45
45
  let constructorName = target.constructor.name;
46
46
  if (constructorName) {
47
- name = `${constructorName}().${name}`;
47
+ name = `${constructorName}()|${name}`;
48
48
  }
49
49
  }
50
50
  if (descriptor.value instanceof AsyncFunction) {
@@ -98,8 +98,7 @@ export async function startSocketServer(
98
98
  }
99
99
 
100
100
  watchTrustedCertificates(() => {
101
- // NOTE: If this is called a lot... STOP CALLING IT A LOT! Calling setSecureContext
102
- // so frequently likely leaks memory!
101
+ // NOTE: If this is called a lot... STOP CALLING IT A LOT! Calling setSecureContext frequently leaks memory! (As in, once a minute is maybe too much, once a second is definitely too much)
103
102
  console.log(`Updating websocket server trusted certificates`);
104
103
  lastOptions.ca = getTrustedCertificates();
105
104
  httpsServer.setSecureContext(lastOptions);
@@ -2,6 +2,8 @@ import { SocketFunction } from "../SocketFunction";
2
2
  import { blue, green, red, yellow } from "../src/formatting/logColors";
3
3
  import { isNode } from "../src/misc";
4
4
 
5
+ // IMPOTRANT! We don't ensure that the times of return are unique. We cannot ensure they are unique because the amount of precision is only about ten thousand date times per millisecond, Which would mean if the calling code called date.now frequently enough, which doesn't even have to be that frequent, it could slowly drift farther and farther ahead of the real time, which would be really bad.
6
+
5
7
  module.allowclient = true;
6
8
 
7
9
  const UPDATE_INTERVAL = 1000 * 60 * 10;