socket-function 0.137.0 → 0.139.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/SocketFunctionTypes.ts +4 -1
- package/package.json +1 -1
- package/require/require.ts +2 -3
- package/src/formatting/format.ts +89 -0
- package/time/trueTimeShim.ts +2 -0
package/SocketFunctionTypes.ts
CHANGED
|
@@ -117,8 +117,11 @@ export type CallerContext = Readonly<CallerContextBase>;
|
|
|
117
117
|
export type CallerContextBase = {
|
|
118
118
|
// IMPORTANT! Do not pass nodeId to other nodes with the intention of having
|
|
119
119
|
// them call functions directly using nodeId. Instead pass location, and have them use connect.
|
|
120
|
-
// - nodeId will be unique per thread, so is only useful for temporary
|
|
120
|
+
// - nodeId will be unique per thread, so is only useful for temporary communication. If you want
|
|
121
121
|
// a more permanent identity, you must derive it from certInfo yourself.
|
|
122
|
+
// ALSO IMPORTANT! DO NOT CHANGE THIS! Even though you might have a better id (a real domain name), and this might be a a weird id (`client:127.0.0.1:1758627917980.2603:0.08946007605096495`), IF you change this, it will break things.
|
|
123
|
+
// 1) It will break checks for client connections. This is used for security purposes. We do less security checks if WE established the connection, so if this is changed and it now looks like it is not a client, then it can create security vulnerabilities.
|
|
124
|
+
// 2) It will cause a connection to no longer appear to be === to it's past self.
|
|
122
125
|
nodeId: string;
|
|
123
126
|
|
|
124
127
|
// The nodeId they contacted. This is useful to determine their intention (otherwise
|
package/package.json
CHANGED
package/require/require.ts
CHANGED
|
@@ -362,9 +362,8 @@ export function requireMain() {
|
|
|
362
362
|
};
|
|
363
363
|
try {
|
|
364
364
|
resultObj = JSON.parse(rawText);
|
|
365
|
-
} catch (e) {
|
|
366
|
-
|
|
367
|
-
throw e;
|
|
365
|
+
} catch (e: any) {
|
|
366
|
+
throw new Error(`require(${JSON.stringify(requests)}). Likely a permissions error, possibly fixed by restarting the local http server. 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
|
|
package/src/formatting/format.ts
CHANGED
|
@@ -230,6 +230,95 @@ 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 + 1);
|
|
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
|
+
|
|
258
|
+
|
|
259
|
+
// Lookup table for common timezone abbreviations by UTC offset (in minutes)
|
|
260
|
+
const timezoneAbbreviations: { [offsetMinutes: string]: string } = {
|
|
261
|
+
// UTC and GMT
|
|
262
|
+
"0": "UTC",
|
|
263
|
+
|
|
264
|
+
// US/Canada timezones
|
|
265
|
+
"300": "EST", // UTC-5 (Eastern Standard Time)
|
|
266
|
+
"240": "EDT", // UTC-4 (Eastern Daylight Time)
|
|
267
|
+
"360": "CST", // UTC-6 (Central Standard Time)
|
|
268
|
+
"420": "MST", // UTC-7 (Mountain Standard Time)
|
|
269
|
+
"480": "PST", // UTC-8 (Pacific Standard Time)
|
|
270
|
+
|
|
271
|
+
// European timezones
|
|
272
|
+
"-60": "CET", // UTC+1 (Central European Time)
|
|
273
|
+
"-120": "CEST", // UTC+2 (Central European Summer Time)
|
|
274
|
+
|
|
275
|
+
// Other common timezones
|
|
276
|
+
"-480": "CST", // UTC+8 (China Standard Time)
|
|
277
|
+
"-540": "JST", // UTC+9 (Japan Standard Time)
|
|
278
|
+
"-330": "IST", // UTC+5:30 (India Standard Time)
|
|
279
|
+
"-570": "ACST", // UTC+9:30 (Australian Central Standard Time)
|
|
280
|
+
"-600": "AEST", // UTC+10 (Australian Eastern Standard Time)
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
// YYYY-MM-DD_HH-MM-SS.mmm TIMEZONE
|
|
285
|
+
export function formatFileTimestampLocal(time: number): string {
|
|
286
|
+
function p(s: number) {
|
|
287
|
+
return s.toString().padStart(2, "0");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let date = new Date(time);
|
|
291
|
+
let year = date.getFullYear();
|
|
292
|
+
let month = p(date.getMonth() + 1);
|
|
293
|
+
let day = p(date.getDate());
|
|
294
|
+
let hours = p(date.getHours());
|
|
295
|
+
let minutes = p(date.getMinutes());
|
|
296
|
+
let seconds = p(date.getSeconds());
|
|
297
|
+
let milliseconds = date.getMilliseconds();
|
|
298
|
+
let millisecondsString = milliseconds.toString().padStart(3, "0");
|
|
299
|
+
|
|
300
|
+
let timeString = time.toString();
|
|
301
|
+
let decimalIndex = timeString.indexOf(".");
|
|
302
|
+
if (decimalIndex !== -1) {
|
|
303
|
+
let fractionalPart = timeString.substring(decimalIndex + 1);
|
|
304
|
+
millisecondsString += fractionalPart;
|
|
305
|
+
}
|
|
306
|
+
// Get timezone offset in minutes (negative of getTimezoneOffset because it returns opposite sign)
|
|
307
|
+
let timezoneOffsetMinutes = date.getTimezoneOffset();
|
|
308
|
+
|
|
309
|
+
// Look up the abbreviation or fallback to numeric format
|
|
310
|
+
let timezoneString = timezoneAbbreviations[timezoneOffsetMinutes.toString()];
|
|
311
|
+
if (!timezoneString) {
|
|
312
|
+
// Fallback: format as ±HHMM
|
|
313
|
+
let offsetSign = timezoneOffsetMinutes >= 0 ? "+" : "-";
|
|
314
|
+
let offsetHours = p(Math.floor(Math.abs(timezoneOffsetMinutes) / 60));
|
|
315
|
+
let offsetMins = p(Math.abs(timezoneOffsetMinutes) % 60);
|
|
316
|
+
timezoneString = `${offsetSign}${offsetHours}${offsetMins}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}.${millisecondsString}_${timezoneString}`;
|
|
320
|
+
}
|
|
321
|
+
|
|
233
322
|
/** 2024 January 1, Monday, 12:53:02pm */
|
|
234
323
|
export function formatNiceDateTime(time: number) {
|
|
235
324
|
function p(s: number) {
|
package/time/trueTimeShim.ts
CHANGED
|
@@ -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;
|