tempest.games 0.2.95 → 0.2.97

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.
@@ -36941,10 +36941,10 @@ class Parser {
36941
36941
  }
36942
36942
  ontextentity(cp) {
36943
36943
  var _a4, _b;
36944
- const index = this.tokenizer.getSectionStart();
36945
- this.endIndex = index - 1;
36944
+ const index2 = this.tokenizer.getSectionStart();
36945
+ this.endIndex = index2 - 1;
36946
36946
  (_b = (_a4 = this.cbs).ontext) === null || _b === undefined || _b.call(_a4, fromCodePoint(cp));
36947
- this.startIndex = index;
36947
+ this.startIndex = index2;
36948
36948
  }
36949
36949
  isVoidElement(name2) {
36950
36950
  return !this.options.xmlMode && voidElements.has(name2);
@@ -37067,8 +37067,8 @@ class Parser {
37067
37067
  this.attribvalue = "";
37068
37068
  }
37069
37069
  getInstructionName(value2) {
37070
- const index = value2.search(reNameEnd);
37071
- let name2 = index < 0 ? value2 : value2.substr(0, index);
37070
+ const index2 = value2.search(reNameEnd);
37071
+ let name2 = index2 < 0 ? value2 : value2.substr(0, index2);
37072
37072
  if (this.lowerCaseTagNames) {
37073
37073
  name2 = name2.toLowerCase();
37074
37074
  }
@@ -37117,7 +37117,7 @@ class Parser {
37117
37117
  var _a4, _b;
37118
37118
  if (this.cbs.onclosetag) {
37119
37119
  this.endIndex = this.startIndex;
37120
- for (let index = this.stack.length;index > 0; this.cbs.onclosetag(this.stack[--index], true))
37120
+ for (let index2 = this.stack.length;index2 > 0; this.cbs.onclosetag(this.stack[--index2], true))
37121
37121
  ;
37122
37122
  }
37123
37123
  (_b = (_a4 = this.cbs).onend) === null || _b === undefined || _b.call(_a4);
@@ -37345,7 +37345,7 @@ var init_escape = __esm(() => {
37345
37345
  [60, "&lt;"],
37346
37346
  [62, "&gt;"]
37347
37347
  ]);
37348
- getCodePoint = String.prototype.codePointAt != null ? (str2, index) => str2.codePointAt(index) : (c3, index) => (c3.charCodeAt(index) & 64512) === 55296 ? (c3.charCodeAt(index) - 55296) * 1024 + c3.charCodeAt(index + 1) - 56320 + 65536 : c3.charCodeAt(index);
37348
+ getCodePoint = String.prototype.codePointAt != null ? (str2, index2) => str2.codePointAt(index2) : (c3, index2) => (c3.charCodeAt(index2) & 64512) === 55296 ? (c3.charCodeAt(index2) - 55296) * 1024 + c3.charCodeAt(index2 + 1) - 56320 + 65536 : c3.charCodeAt(index2);
37349
37349
  escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
37350
37350
  escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
37351
37351
  [34, "&quot;"],
@@ -38477,11 +38477,11 @@ function putCellIntoLayout(cell, layout, baseRow, baseCol) {
38477
38477
  }
38478
38478
  }
38479
38479
  }
38480
- function getOrInitOffset(offsets, index) {
38481
- if (offsets[index] === undefined) {
38482
- offsets[index] = index === 0 ? 0 : 1 + getOrInitOffset(offsets, index - 1);
38480
+ function getOrInitOffset(offsets, index2) {
38481
+ if (offsets[index2] === undefined) {
38482
+ offsets[index2] = index2 === 0 ? 0 : 1 + getOrInitOffset(offsets, index2 - 1);
38483
38483
  }
38484
- return offsets[index];
38484
+ return offsets[index2];
38485
38485
  }
38486
38486
  function updateOffset(offsets, base, span, value2) {
38487
38487
  offsets[base + span] = Math.max(getOrInitOffset(offsets, base + span), getOrInitOffset(offsets, base) + value2);
@@ -45817,7 +45817,7 @@ for (const e of _i) {
45817
45817
  (t2.configurable || t2.enumerable || t2.writable) && (t2.configurable = false, t2.enumerable = false, t2.writable = false, Object.defineProperty(e, "prototype", t2));
45818
45818
  }
45819
45819
 
45820
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/utils-CLZnJdb_.mjs
45820
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/utils-CLZnJdb_.mjs
45821
45821
  var TRPC_ERROR_CODES_BY_KEY = {
45822
45822
  PARSE_ERROR: -32700,
45823
45823
  BAD_REQUEST: -32600,
@@ -45894,7 +45894,7 @@ function identity(it2) {
45894
45894
  return it2;
45895
45895
  }
45896
45896
 
45897
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/getErrorShape-BH60iMC2.mjs
45897
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/getErrorShape-BH60iMC2.mjs
45898
45898
  var __create2 = Object.create;
45899
45899
  var __defProp2 = Object.defineProperty;
45900
45900
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -46097,7 +46097,7 @@ function getErrorShape(opts) {
46097
46097
  return config.errorFormatter((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { shape }));
46098
46098
  }
46099
46099
 
46100
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/tracked-DBSMdVzR.mjs
46100
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/tracked-DBSMdVzR.mjs
46101
46101
  var defaultFormatter = ({ shape }) => {
46102
46102
  return shape;
46103
46103
  };
@@ -46365,7 +46365,7 @@ function isTrackedEnvelope(value) {
46365
46365
  return Array.isArray(value) && value[2] === trackedSymbol;
46366
46366
  }
46367
46367
 
46368
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
46368
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
46369
46369
  function isObservable(x2) {
46370
46370
  return typeof x2 === "object" && x2 !== null && "subscribe" in x2;
46371
46371
  }
@@ -46438,7 +46438,7 @@ function observableToAsyncIterable(observable$1, signal) {
46438
46438
  } };
46439
46439
  }
46440
46440
 
46441
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/resolveResponse-D7zvnoIM.mjs
46441
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/resolveResponse-D7zvnoIM.mjs
46442
46442
  function parseConnectionParamsFromUnknown(parsed) {
46443
46443
  try {
46444
46444
  if (parsed === null)
@@ -48159,7 +48159,7 @@ async function resolveResponse(opts) {
48159
48159
  }
48160
48160
  }
48161
48161
 
48162
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/initTRPC-DGaJyg8t.mjs
48162
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/initTRPC-DGaJyg8t.mjs
48163
48163
  var import_objectSpread2$2 = __toESM2(require_objectSpread2(), 1);
48164
48164
  var middlewareMarker = "middlewareMarker";
48165
48165
  function createMiddlewareFactory() {
@@ -48469,7 +48469,7 @@ var TRPCBuilder = class TRPCBuilder2 {
48469
48469
  };
48470
48470
  var initTRPC = new TRPCBuilder;
48471
48471
 
48472
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/node-http-Cd7-CwtL.mjs
48472
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/node-http-Cd7-CwtL.mjs
48473
48473
  function createBody(req, opts) {
48474
48474
  if ("body" in req) {
48475
48475
  if (req.body === undefined)
@@ -48675,7 +48675,7 @@ async function nodeHTTPRequestHandler(opts) {
48675
48675
  });
48676
48676
  }
48677
48677
 
48678
- // ../../node_modules/.pnpm/@trpc+server@11.7.2_typescript@5.9.3/node_modules/@trpc/server/dist/adapters/standalone.mjs
48678
+ // ../../node_modules/.pnpm/@trpc+server@11.8.0_typescript@5.9.3/node_modules/@trpc/server/dist/adapters/standalone.mjs
48679
48679
  var import_objectSpread26 = __toESM2(require_objectSpread2(), 1);
48680
48680
  function createHandler(opts) {
48681
48681
  var _opts$basePath;
@@ -51560,7 +51560,7 @@ import { createServer as createHttpServer } from "http";
51560
51560
  import { createServer as createSecureServer } from "https";
51561
51561
  import { resolve } from "path";
51562
51562
 
51563
- // ../../node_modules/.pnpm/@t3-oss+env-core@0.13.8_arktype@2.1.28_typescript@5.9.3_zod@4.1.13/node_modules/@t3-oss/env-core/dist/src-Bb3GbGAa.js
51563
+ // ../../node_modules/.pnpm/@t3-oss+env-core@0.13.10_arktype@2.1.29_typescript@5.9.3_zod@4.2.0/node_modules/@t3-oss/env-core/dist/standard.js
51564
51564
  function ensureSynchronous(value, message) {
51565
51565
  if (value instanceof Promise)
51566
51566
  throw new Error(message);
@@ -51585,17 +51585,21 @@ function parseWithDictionary(dictionary, value) {
51585
51585
  return { issues };
51586
51586
  return { value: result };
51587
51587
  }
51588
+
51589
+ // ../../node_modules/.pnpm/@t3-oss+env-core@0.13.10_arktype@2.1.29_typescript@5.9.3_zod@4.2.0/node_modules/@t3-oss/env-core/dist/index.js
51588
51590
  function createEnv(opts) {
51589
51591
  const runtimeEnv = opts.runtimeEnvStrict ?? opts.runtimeEnv ?? process.env;
51590
- const emptyStringAsUndefined = opts.emptyStringAsUndefined ?? false;
51591
- if (emptyStringAsUndefined) {
51592
+ if (opts.emptyStringAsUndefined ?? false) {
51592
51593
  for (const [key, value] of Object.entries(runtimeEnv))
51593
51594
  if (value === "")
51594
51595
  delete runtimeEnv[key];
51595
51596
  }
51596
- const skip = !!opts.skipValidation;
51597
- if (skip)
51597
+ if (!!opts.skipValidation) {
51598
+ if (opts.extends)
51599
+ for (const preset of opts.extends)
51600
+ preset.skipValidation = true;
51598
51601
  return runtimeEnv;
51602
+ }
51599
51603
  const _client = typeof opts.client === "object" ? opts.client : {};
51600
51604
  const _server = typeof opts.server === "object" ? opts.server : {};
51601
51605
  const _shared = typeof opts.shared === "object" ? opts.shared : {};
@@ -51608,7 +51612,7 @@ function createEnv(opts) {
51608
51612
  ..._client,
51609
51613
  ..._shared
51610
51614
  };
51611
- const parsed = opts.createFinalSchema?.(finalSchemaShape, isServer)["~standard"].validate(runtimeEnv) ?? parseWithDictionary(finalSchemaShape, runtimeEnv);
51615
+ const parsed = opts.createFinalSchema?.(finalSchemaShape, isServer)?.["~standard"].validate(runtimeEnv) ?? parseWithDictionary(finalSchemaShape, runtimeEnv);
51612
51616
  ensureSynchronous(parsed, "Validation must be synchronous");
51613
51617
  const onValidationError = opts.onValidationError ?? ((issues) => {
51614
51618
  console.error("\u274C Invalid environment variables:", issues);
@@ -51634,7 +51638,7 @@ function createEnv(opts) {
51634
51638
  return Object.assign(acc, curr);
51635
51639
  }, {});
51636
51640
  const fullObj = Object.assign(extendedObj, parsed.value);
51637
- const env = new Proxy(fullObj, { get(target, prop) {
51641
+ return new Proxy(fullObj, { get(target, prop) {
51638
51642
  if (typeof prop !== "string")
51639
51643
  return;
51640
51644
  if (ignoreProp(prop))
@@ -51643,7 +51647,6 @@ function createEnv(opts) {
51643
51647
  return onInvalidAccess(prop);
51644
51648
  return Reflect.get(target, prop);
51645
51649
  } });
51646
- return env;
51647
51650
  }
51648
51651
 
51649
51652
  // ../../node_modules/.pnpm/@ark+util@0.56.0/node_modules/@ark/util/out/arrays.js
@@ -58075,10 +58078,10 @@ var intrinsic = {
58075
58078
  emptyStructure: node("structure", {}, { prereduced: true })
58076
58079
  };
58077
58080
  $ark.intrinsic = { ...intrinsic };
58078
- // ../../node_modules/.pnpm/arkregex@0.0.4/node_modules/arkregex/out/regex.js
58081
+ // ../../node_modules/.pnpm/arkregex@0.0.5/node_modules/arkregex/out/regex.js
58079
58082
  var regex = (src, flags) => new RegExp(src, flags);
58080
58083
  Object.assign(regex, { as: regex });
58081
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operand/date.js
58084
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operand/date.js
58082
58085
  var isDateLiteral = (value) => typeof value === "string" && value[0] === "d" && (value[1] === "'" || value[1] === '"') && value[value.length - 1] === value[1];
58083
58086
  var isValidDate = (d2) => d2.toString() !== "Invalid Date";
58084
58087
  var extractDateLiteralSource = (literal) => literal.slice(2, -1);
@@ -58097,7 +58100,7 @@ var maybeParseDate = (source, errorOnFail) => {
58097
58100
  return errorOnFail ? throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail) : undefined;
58098
58101
  };
58099
58102
 
58100
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operand/enclosed.js
58103
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operand/enclosed.js
58101
58104
  var regexExecArray = rootSchema({
58102
58105
  proto: "Array",
58103
58106
  sequence: "string",
@@ -58171,12 +58174,12 @@ var enclosingCharDescriptions = {
58171
58174
  };
58172
58175
  var writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
58173
58176
 
58174
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/ast/validate.js
58177
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/ast/validate.js
58175
58178
  var writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
58176
58179
  var shallowOptionalMessage = "Optional definitions like 'string?' are only valid as properties in an object or tuple";
58177
58180
  var shallowDefaultableMessage = "Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple";
58178
58181
 
58179
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/tokens.js
58182
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/tokens.js
58180
58183
  var terminatingChars = {
58181
58184
  "<": 1,
58182
58185
  ">": 1,
@@ -58194,7 +58197,7 @@ var terminatingChars = {
58194
58197
  };
58195
58198
  var lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ? unscanned[0] === "=" ? unscanned[1] === "=" : unscanned.trimStart() === "" || isKeyOf(unscanned.trimStart()[0], terminatingChars) : lookahead === "=" ? unscanned[0] !== "=" : lookahead === "," || lookahead === "?";
58196
58199
 
58197
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operand/genericArgs.js
58200
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operand/genericArgs.js
58198
58201
  var parseGenericArgs = (name, g2, s2) => _parseGenericArgs(name, g2, s2, []);
58199
58202
  var _parseGenericArgs = (name, g2, s2, argNodes) => {
58200
58203
  const argState = s2.parseUntilFinalizer();
@@ -58211,7 +58214,7 @@ var _parseGenericArgs = (name, g2, s2, argNodes) => {
58211
58214
  };
58212
58215
  var writeInvalidGenericArgCountMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})`;
58213
58216
 
58214
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operand/unenclosed.js
58217
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operand/unenclosed.js
58215
58218
  var parseUnenclosed = (s2) => {
58216
58219
  const token = s2.scanner.shiftUntilLookahead(terminatingChars);
58217
58220
  if (token === "keyof")
@@ -58259,10 +58262,10 @@ var writeMissingOperandMessage = (s2) => {
58259
58262
  var writeMissingRightOperandMessage = (token, unscanned = "") => `Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
58260
58263
  var writeExpressionExpectedMessage = (unscanned) => `Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;
58261
58264
 
58262
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operand/operand.js
58265
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operand/operand.js
58263
58266
  var parseOperand = (s2) => s2.scanner.lookahead === "" ? s2.error(writeMissingOperandMessage(s2)) : s2.scanner.lookahead === "(" ? s2.shiftedBy(1).reduceGroupOpen() : s2.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s2, s2.scanner.shift()) : s2.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s2.shiftedBy(1)) : s2.scanner.lookahead === "d" ? s2.scanner.nextLookahead in enclosingQuote ? parseEnclosed(s2, `${s2.scanner.shift()}${s2.scanner.shift()}`) : parseUnenclosed(s2) : s2.scanner.lookahead === "x" ? s2.scanner.nextLookahead === "/" ? s2.shiftedBy(2) && parseEnclosed(s2, "x/") : parseUnenclosed(s2) : parseUnenclosed(s2);
58264
58267
 
58265
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/reduce/shared.js
58268
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/reduce/shared.js
58266
58269
  var minComparators = {
58267
58270
  ">": true,
58268
58271
  ">=": true
@@ -58282,7 +58285,7 @@ var writeOpenRangeMessage = (min2, comparator) => `Left bounds are only valid wh
58282
58285
  var writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
58283
58286
  var writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`;
58284
58287
 
58285
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operator/bounds.js
58288
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operator/bounds.js
58286
58289
  var parseBound = (s2, start) => {
58287
58290
  const comparator = shiftComparator(s2, start);
58288
58291
  if (s2.root.hasKind("unit")) {
@@ -58353,14 +58356,14 @@ var parseRightBound = (s2, comparator) => {
58353
58356
  };
58354
58357
  var writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
58355
58358
 
58356
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operator/brand.js
58359
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operator/brand.js
58357
58360
  var parseBrand = (s2) => {
58358
58361
  s2.scanner.shiftUntilNonWhitespace();
58359
58362
  const brandName = s2.scanner.shiftUntilLookahead(terminatingChars);
58360
58363
  s2.root = s2.root.brand(brandName);
58361
58364
  };
58362
58365
 
58363
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operator/divisor.js
58366
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operator/divisor.js
58364
58367
  var parseDivisor = (s2) => {
58365
58368
  s2.scanner.shiftUntilNonWhitespace();
58366
58369
  const divisorToken = s2.scanner.shiftUntilLookahead(terminatingChars);
@@ -58373,7 +58376,7 @@ var parseDivisor = (s2) => {
58373
58376
  };
58374
58377
  var writeInvalidDivisorMessage = (divisor2) => `% operator must be followed by a non-zero integer literal (was ${divisor2})`;
58375
58378
 
58376
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operator/operator.js
58379
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operator/operator.js
58377
58380
  var parseOperator = (s2) => {
58378
58381
  const lookahead = s2.scanner.shift();
58379
58382
  return lookahead === "" ? s2.finalize("") : lookahead === "[" ? s2.scanner.shift() === "]" ? s2.setRoot(s2.root.array()) : s2.error(incompleteArrayTokenMessage) : lookahead === "|" ? s2.scanner.lookahead === ">" ? s2.shiftedBy(1).pushRootToBranch("|>") : s2.pushRootToBranch(lookahead) : lookahead === "&" ? s2.pushRootToBranch(lookahead) : lookahead === ")" ? s2.finalizeGroup() : lookaheadIsFinalizing(lookahead, s2.scanner.unscanned) ? s2.finalize(lookahead) : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s2, lookahead) : lookahead === "%" ? parseDivisor(s2) : lookahead === "#" ? parseBrand(s2) : (lookahead in whitespaceChars) ? parseOperator(s2) : s2.error(writeUnexpectedCharacterMessage(lookahead));
@@ -58381,7 +58384,7 @@ var parseOperator = (s2) => {
58381
58384
  var writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
58382
58385
  var incompleteArrayTokenMessage = `Missing expected ']'`;
58383
58386
 
58384
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/shift/operator/default.js
58387
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/shift/operator/default.js
58385
58388
  var parseDefault = (s2) => {
58386
58389
  const baseNode = s2.unsetRoot();
58387
58390
  s2.parseOperand();
@@ -58393,7 +58396,7 @@ var parseDefault = (s2) => {
58393
58396
  };
58394
58397
  var writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must be a literal value`;
58395
58398
 
58396
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/string.js
58399
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/string.js
58397
58400
  var parseString = (def, ctx) => {
58398
58401
  const aliasResolution = ctx.$.maybeResolveRoot(def);
58399
58402
  if (aliasResolution)
@@ -58432,7 +58435,7 @@ var parseUntilFinalizer = (s2) => {
58432
58435
  };
58433
58436
  var next = (s2) => s2.hasRoot() ? s2.parseOperator() : s2.parseOperand();
58434
58437
 
58435
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/reduce/dynamic.js
58438
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/reduce/dynamic.js
58436
58439
  class RuntimeState {
58437
58440
  root;
58438
58441
  branches = {
@@ -58569,7 +58572,7 @@ class RuntimeState {
58569
58572
  }
58570
58573
  }
58571
58574
 
58572
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/generic.js
58575
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/generic.js
58573
58576
  var emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
58574
58577
  var parseGenericParamName = (scanner2, result, ctx) => {
58575
58578
  scanner2.shiftUntilNonWhitespace();
@@ -58597,7 +58600,7 @@ var _parseOptionalConstraint = (scanner2, name, result, ctx) => {
58597
58600
  result.push([name, s2.root]);
58598
58601
  return parseGenericParamName(scanner2, result, ctx);
58599
58602
  };
58600
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/fn.js
58603
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/fn.js
58601
58604
  class InternalFnParser extends Callable {
58602
58605
  constructor($2) {
58603
58606
  const attach = {
@@ -58649,7 +58652,7 @@ class InternalTypedFn extends Callable {
58649
58652
  var badFnReturnTypeMessage = `":" must be followed by exactly one return type e.g:
58650
58653
  fn("string", ":", "number")(s => s.length)`;
58651
58654
 
58652
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/match.js
58655
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/match.js
58653
58656
  class InternalMatchParser extends Callable {
58654
58657
  $;
58655
58658
  constructor($2) {
@@ -58743,7 +58746,7 @@ var throwOnDefault = (errors3) => errors3.throw();
58743
58746
  var chainedAtMessage = `A key matcher must be specified before the first case i.e. match.at('foo') or match.in<object>().at('bar')`;
58744
58747
  var doubleAtMessage = `At most one key matcher may be specified per expression`;
58745
58748
 
58746
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/property.js
58749
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/property.js
58747
58750
  var parseProperty = (def, ctx) => {
58748
58751
  if (isArray(def)) {
58749
58752
  if (def[1] === "=")
@@ -58756,7 +58759,7 @@ var parseProperty = (def, ctx) => {
58756
58759
  var invalidOptionalKeyKindMessage = `Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }`;
58757
58760
  var invalidDefaultableKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
58758
58761
 
58759
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/objectLiteral.js
58762
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/objectLiteral.js
58760
58763
  var parseObjectLiteral = (def, ctx) => {
58761
58764
  let spread;
58762
58765
  const structure3 = {};
@@ -58841,7 +58844,7 @@ var preparseKey = (key) => typeof key === "symbol" ? { kind: "required", normali
58841
58844
  };
58842
58845
  var writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
58843
58846
 
58844
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/tupleExpressions.js
58847
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/tupleExpressions.js
58845
58848
  var maybeParseTupleExpression = (def, ctx) => isIndexZeroExpression(def) ? indexZeroParsers[def[0]](def, ctx) : isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx) : null;
58846
58849
  var parseKeyOfTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[1], ctx).keyof();
58847
58850
  var parseBranchTuple = (def, ctx) => {
@@ -58902,7 +58905,7 @@ var indexZeroParsers = defineIndexZeroParsers({
58902
58905
  var isIndexZeroExpression = (def) => indexZeroParsers[def[0]] !== undefined;
58903
58906
  var writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
58904
58907
 
58905
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/tupleLiteral.js
58908
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/tupleLiteral.js
58906
58909
  var parseTupleLiteral = (def, ctx) => {
58907
58910
  let sequences = [{}];
58908
58911
  let i2 = 0;
@@ -58998,7 +59001,7 @@ var requiredPostOptionalMessage = "A required element may not follow an optional
58998
59001
  var optionalOrDefaultableAfterVariadicMessage = "An optional element may not follow a variadic element";
58999
59002
  var defaultablePostOptionalMessage = "A defaultable element may not follow an optional element without a default";
59000
59003
 
59001
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/parser/definition.js
59004
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/parser/definition.js
59002
59005
  var parseCache = {};
59003
59006
  var parseInnerDefinition = (def, ctx) => {
59004
59007
  if (typeof def === "string") {
@@ -59062,7 +59065,7 @@ var parseStandardSchema = (def, ctx) => ctx.$.intrinsic.unknown.pipe((v2, ctx2)
59062
59065
  var parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
59063
59066
  var writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
59064
59067
 
59065
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/type.js
59068
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/type.js
59066
59069
  class InternalTypeParser extends Callable {
59067
59070
  constructor($2) {
59068
59071
  const attach = Object.assign({
@@ -59104,7 +59107,7 @@ class InternalTypeParser extends Callable {
59104
59107
  }
59105
59108
  }
59106
59109
 
59107
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/scope.js
59110
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/scope.js
59108
59111
  var $arkTypeRegistry = $ark;
59109
59112
 
59110
59113
  class InternalScope extends BaseScope {
@@ -59198,7 +59201,7 @@ var scope2 = Object.assign(InternalScope.scope, {
59198
59201
  });
59199
59202
  var Scope = InternalScope;
59200
59203
 
59201
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/builtins.js
59204
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/builtins.js
59202
59205
  class MergeHkt extends Hkt {
59203
59206
  description = 'merge an object\'s properties onto another like `Merge(User, { isAdmin: "true" })`';
59204
59207
  }
@@ -59208,7 +59211,7 @@ var arkBuiltins = Scope.module({
59208
59211
  Merge
59209
59212
  });
59210
59213
 
59211
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/Array.js
59214
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/Array.js
59212
59215
  class liftFromHkt extends Hkt {
59213
59216
  }
59214
59217
  var liftFrom = genericNode("element")((args2) => {
@@ -59225,7 +59228,7 @@ var arkArray = Scope.module({
59225
59228
  name: "Array"
59226
59229
  });
59227
59230
 
59228
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/FormData.js
59231
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/FormData.js
59229
59232
  var value = rootSchema(["string", registry.FileConstructor]);
59230
59233
  var parsedFormDataValue = value.rawOr(value.array());
59231
59234
  var parsed = rootSchema({
@@ -59262,7 +59265,7 @@ var arkFormData = Scope.module({
59262
59265
  name: "FormData"
59263
59266
  });
59264
59267
 
59265
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/TypedArray.js
59268
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/TypedArray.js
59266
59269
  var TypedArray = Scope.module({
59267
59270
  Int8: ["instanceof", Int8Array],
59268
59271
  Uint8: ["instanceof", Uint8Array],
@@ -59279,7 +59282,7 @@ var TypedArray = Scope.module({
59279
59282
  name: "TypedArray"
59280
59283
  });
59281
59284
 
59282
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/constructors.js
59285
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/constructors.js
59283
59286
  var omittedPrototypes = {
59284
59287
  Boolean: 1,
59285
59288
  Number: 1,
@@ -59292,7 +59295,7 @@ var arkPrototypes = Scope.module({
59292
59295
  FormData: arkFormData
59293
59296
  });
59294
59297
 
59295
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/number.js
59298
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/number.js
59296
59299
  var epoch = rootSchema({
59297
59300
  domain: {
59298
59301
  domain: "number",
@@ -59335,7 +59338,7 @@ var number = Scope.module({
59335
59338
  name: "number"
59336
59339
  });
59337
59340
 
59338
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/string.js
59341
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/string.js
59339
59342
  var regexStringNode = (regex2, description, jsonSchemaFormat) => {
59340
59343
  const schema = {
59341
59344
  domain: "string",
@@ -59726,7 +59729,7 @@ var string = Scope.module({
59726
59729
  name: "string"
59727
59730
  });
59728
59731
 
59729
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/ts.js
59732
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/ts.js
59730
59733
  var arkTsKeywords = Scope.module({
59731
59734
  bigint: intrinsic.bigint,
59732
59735
  boolean: intrinsic.boolean,
@@ -59814,7 +59817,7 @@ var arkTsGenerics = Scope.module({
59814
59817
  Required: Required2
59815
59818
  });
59816
59819
 
59817
- // ../../node_modules/.pnpm/arktype@2.1.28/node_modules/arktype/out/keywords/keywords.js
59820
+ // ../../node_modules/.pnpm/arktype@2.1.29/node_modules/arktype/out/keywords/keywords.js
59818
59821
  var ark = scope2({
59819
59822
  ...arkTsKeywords,
59820
59823
  ...arkTsGenerics,
@@ -60092,7 +60095,7 @@ var ParentSocket = class extends CustomSocket {
60092
60095
  incompleteData = ``;
60093
60096
  unprocessedEvents = [];
60094
60097
  relays;
60095
- relayServices;
60098
+ initRelay;
60096
60099
  proc;
60097
60100
  id = `#####`;
60098
60101
  log(...args2) {
@@ -60118,7 +60121,9 @@ var ParentSocket = class extends CustomSocket {
60118
60121
  this.proc = proc;
60119
60122
  this.proc.stdin.resume();
60120
60123
  this.relays = /* @__PURE__ */ new Map;
60121
- this.relayServices = [];
60124
+ this.initRelay = () => {
60125
+ this.logger.info(`\uD83D\uDD17`, `nothing to relay`);
60126
+ };
60122
60127
  this.proc.stdin.on(`data`, (buffer) => {
60123
60128
  const pieces = buffer.toString().split(`\x03`);
60124
60129
  const initialMaybeWellFormed = pieces[0];
@@ -60173,15 +60178,13 @@ var ParentSocket = class extends CustomSocket {
60173
60178
  if (this.proc.pid)
60174
60179
  this.id = this.proc.pid?.toString();
60175
60180
  this.on(`user-joins`, (userKey) => {
60176
- this.logger.info(`\uD83D\uDC64`, `user`, userKey, `joined`);
60181
+ this.logger.info(`\uD83D\uDC64`, userKey, `joined`);
60177
60182
  const relay = new SubjectSocket(userKey);
60178
60183
  this.relays.set(userKey, relay);
60179
- this.logger.info(`\uD83D\uDD17`, `attaching services:`, `[${[...this.relayServices.keys()].join(`, `)}]`);
60180
- for (const attachRelay of this.relayServices) {
60181
- const cleanupRelay = attachRelay(relay, userKey);
60182
- if (cleanupRelay)
60183
- relay.disposalFunctions.push(cleanupRelay);
60184
- }
60184
+ this.logger.info(`\uD83D\uDD17`, `attaching services for user`, userKey);
60185
+ const cleanupRelay = this.initRelay(relay, userKey);
60186
+ if (cleanupRelay)
60187
+ relay.disposalFunctions.push(cleanupRelay);
60185
60188
  this.on(userKey, (...data) => {
60186
60189
  relay.in.next(data);
60187
60190
  });
@@ -60201,7 +60204,7 @@ var ParentSocket = class extends CustomSocket {
60201
60204
  }
60202
60205
  receiveRelay(attachServices) {
60203
60206
  this.logger.info(`\uD83D\uDD17`, `running relay method`);
60204
- this.relayServices.push(attachServices);
60207
+ this.initRelay = attachServices;
60205
60208
  }
60206
60209
  };
60207
60210
  var ChildSocket = class extends CustomSocket {
@@ -65485,6 +65488,9 @@ class Index2 {
65485
65488
  this.config = { ...config3, table };
65486
65489
  }
65487
65490
  }
65491
+ function index(name) {
65492
+ return new IndexBuilderOn(false, name);
65493
+ }
65488
65494
  function uniqueIndex(name) {
65489
65495
  return new IndexBuilderOn(true, name);
65490
65496
  }
@@ -65686,8 +65692,8 @@ class PgDialect {
65686
65692
  return;
65687
65693
  }
65688
65694
  const joinsArray = [];
65689
- for (const [index, joinMeta] of joins.entries()) {
65690
- if (index === 0) {
65695
+ for (const [index2, joinMeta] of joins.entries()) {
65696
+ if (index2 === 0) {
65691
65697
  joinsArray.push(sql` `);
65692
65698
  }
65693
65699
  const table = joinMeta.table;
@@ -65708,7 +65714,7 @@ class PgDialect {
65708
65714
  } else {
65709
65715
  joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`);
65710
65716
  }
65711
- if (index < joins.length - 1) {
65717
+ if (index2 < joins.length - 1) {
65712
65718
  joinsArray.push(sql` `);
65713
65719
  }
65714
65720
  }
@@ -67545,6 +67551,7 @@ function drizzle(...params) {
67545
67551
  var exports_tempest_db_schema = {};
67546
67552
  __export(exports_tempest_db_schema, {
67547
67553
  users: () => users,
67554
+ userSessions: () => userSessions,
67548
67555
  untrackedUserColumnNames: () => untrackedUserColumnNames,
67549
67556
  twoFactorMethod: () => twoFactorMethod,
67550
67557
  trackedUserColumnName: () => trackedUserColumnName,
@@ -67646,6 +67653,11 @@ var banishedIps = pgTable(`banishedIps`, {
67646
67653
  banishedAtIso: iso8601().notNull().default(ISO_NOW),
67647
67654
  banishedUntilIso: iso8601()
67648
67655
  });
67656
+ var userSessions = pgTable(`userSessions`, {
67657
+ sessionKey: uuid2().notNull().primaryKey(),
67658
+ userId: uuid2().notNull().references(() => users.id, { onDelete: `cascade` }),
67659
+ createdAtIso: iso8601().notNull().default(ISO_NOW)
67660
+ }, (table) => [index(`userIdIndex`).on(table.userId)]);
67649
67661
 
67650
67662
  // src/database/tempest-db-manager.ts
67651
67663
  var __dirname = "/home/runner/work/wayforge/wayforge/apps/tempest.games/src/database";
@@ -84364,51 +84376,6 @@ var {CookieMap } = globalThis.Bun;
84364
84376
  // src/backend/trpc-server.ts
84365
84377
  var trpc = initTRPC.context().create();
84366
84378
 
84367
- // src/backend/user-sessions.ts
84368
- var import_cron = __toESM(require_dist(), 1);
84369
- var ONE_WEEK_MS = 1000 * 60 * 60 * 24 * 7;
84370
- var TEN_MINUTES_MS = 1000 * 60 * 10;
84371
- var [sessionCreatedTimes, userSessions] = (() => {
84372
- let { __sessionData } = global;
84373
- if (!__sessionData) {
84374
- __sessionData = global.__sessionData = [
84375
- new Map,
84376
- new Junction({
84377
- between: [`user`, `session`],
84378
- cardinality: `1:n`
84379
- })
84380
- ];
84381
- const [createdTimes, sessions] = __sessionData;
84382
- const autoExpiry = new import_cron.CronJob(`00 00 03 * * *`, () => {
84383
- const aboutAWeekAgo = qi.Now.instant().subtract({ hours: 24 * 7 });
84384
- for (const [sessionId, sessionCreatedAt] of createdTimes.entries()) {
84385
- if (qi.Instant.compare(sessionCreatedAt, aboutAWeekAgo) <= 0) {
84386
- sessions.delete(sessionId);
84387
- }
84388
- }
84389
- });
84390
- autoExpiry.start();
84391
- process.on(`exit`, async () => {
84392
- await autoExpiry.stop();
84393
- logger.info(`\uD83D\uDEEC autoExpiry stopped`);
84394
- });
84395
- }
84396
- return __sessionData;
84397
- })();
84398
- function createSession(userId, now) {
84399
- const sessionKey = crypto.randomUUID();
84400
- sessionCreatedTimes.set(sessionKey, now);
84401
- userSessions.set(userId, sessionKey);
84402
- return sessionKey;
84403
- }
84404
- function isSessionRecent(sessionKey, now) {
84405
- const sessionCreatedAt = sessionCreatedTimes.get(sessionKey);
84406
- if (!sessionCreatedAt)
84407
- return false;
84408
- const tenMinutesAgo = now.subtract({ minutes: 10 });
84409
- return qi.Instant.compare(sessionCreatedAt, tenMinutesAgo) >= 0;
84410
- }
84411
-
84412
84379
  // src/backend/procedures.ts
84413
84380
  var loggedProcedure = trpc.procedure.use(async (opts) => {
84414
84381
  const start = performance.now();
@@ -84417,15 +84384,26 @@ var loggedProcedure = trpc.procedure.use(async (opts) => {
84417
84384
  result.ok ? opts.ctx.logger.info(`\uD83D\uDE03`, opts.path, `[${opts.type}]`, `${durationMs}ms`) : opts.ctx.logger.error(`\uD83D\uDE2D`, opts.path, `[${opts.type}]`, `${durationMs}ms`);
84418
84385
  return result;
84419
84386
  });
84420
- var userSessionProcedure = loggedProcedure.use((opts) => {
84387
+ var userSessionProcedure = loggedProcedure.use(async (opts) => {
84421
84388
  const cookieHeader = opts.ctx.req.headers.cookie ?? ``;
84422
84389
  const cookies = new CookieMap(cookieHeader);
84423
84390
  const sessionKey = cookies.get(`sessionKey`);
84424
84391
  let auth = null;
84425
84392
  if (sessionKey) {
84426
- const userId = userSessions.getRelatedKey(sessionKey);
84427
- if (userId) {
84428
- auth = { userId, sessionKey };
84393
+ const session = await opts.ctx.db.drizzle.query.userSessions.findFirst({
84394
+ columns: { createdAtIso: true, userId: true },
84395
+ where: eq(userSessions.sessionKey, sessionKey)
84396
+ });
84397
+ if (session) {
84398
+ const { createdAtIso, userId } = session;
84399
+ const aboutAWeekAgo = qi.Now.instant().subtract({ hours: 24 * 7 });
84400
+ const createdAt = qi.Instant.from(createdAtIso);
84401
+ const isExpired = qi.Instant.compare(createdAt, aboutAWeekAgo) <= 0;
84402
+ if (isExpired) {
84403
+ await opts.ctx.db.drizzle.delete(userSessions).where(eq(userSessions.sessionKey, sessionKey));
84404
+ } else if (userId) {
84405
+ auth = { userId, sessionKey };
84406
+ }
84429
84407
  }
84430
84408
  }
84431
84409
  if (!auth) {
@@ -84443,16 +84421,15 @@ var verifiedUserProcedure = userSessionProcedure.use(async (opts) => {
84443
84421
  where: eq(users.id, opts.ctx.userId)
84444
84422
  });
84445
84423
  if (!user) {
84446
- userSessions.delete(opts.ctx.sessionKey);
84447
84424
  throw new TRPCError({
84448
- code: `FORBIDDEN`,
84449
- message: `You must be logged in to perform this action.`
84425
+ code: `UNPROCESSABLE_CONTENT`,
84426
+ message: `User not found.`
84450
84427
  });
84451
84428
  }
84452
84429
  if (!user.emailVerified) {
84453
84430
  throw new TRPCError({
84454
84431
  code: `FORBIDDEN`,
84455
- message: `You must be logged in to perform this action.`
84432
+ message: `You must verify your email address before performing this action.`
84456
84433
  });
84457
84434
  }
84458
84435
  return opts.next({ ctx: { user } });
@@ -84510,6 +84487,40 @@ function instant(isoString) {
84510
84487
  return qi.Instant.from(isoString);
84511
84488
  }
84512
84489
 
84490
+ // src/backend/user-sessions.ts
84491
+ var import_cron = __toESM(require_dist(), 1);
84492
+ var sessionExpiry = (() => {
84493
+ const autoExpiry = new import_cron.CronJob(`00 00 03 * * *`, async () => {
84494
+ const aboutAWeekAgoInst = qi.Now.instant().subtract({ hours: 24 * 7 });
84495
+ const aboutAWeekAgo = iso86012(aboutAWeekAgoInst);
84496
+ await db.sql`DELETE FROM userSessions WHERE createdAtIso::timestamptz < ${aboutAWeekAgo}::timestamptz`;
84497
+ });
84498
+ autoExpiry.start();
84499
+ process.on(`exit`, async () => {
84500
+ await autoExpiry.stop();
84501
+ logger.info(`\uD83D\uDEEC autoExpiry stopped`);
84502
+ });
84503
+ return autoExpiry;
84504
+ })();
84505
+ async function createSession(userId, ctx) {
84506
+ const [{ sessionKey }] = await ctx.db.drizzle.insert(userSessions).values({
84507
+ userId,
84508
+ sessionKey: crypto.randomUUID(),
84509
+ createdAtIso: iso86012(ctx.now)
84510
+ }).returning();
84511
+ return sessionKey;
84512
+ }
84513
+ async function isSessionRecent(sessionKey, now) {
84514
+ const session = await db.drizzle.query.userSessions.findFirst({
84515
+ where: eq(userSessions.sessionKey, sessionKey)
84516
+ });
84517
+ if (!session)
84518
+ return false;
84519
+ const sessionCreatedAt = instant(session.createdAtIso);
84520
+ const tenMinutesAgo = now.subtract({ minutes: 10 });
84521
+ return qi.Instant.compare(sessionCreatedAt, tenMinutesAgo) >= 0;
84522
+ }
84523
+
84513
84524
  // src/backend/router.ts
84514
84525
  var appRouter = trpc.router({
84515
84526
  version: loggedProcedure.query(async () => {
@@ -84532,7 +84543,7 @@ var appRouter = trpc.router({
84532
84543
  offerNewEmail: userSessionProcedure.input(type({ emailOffered: `string.email`, "+": `delete` })).mutation(async ({ input, ctx }) => {
84533
84544
  const { emailOffered } = input;
84534
84545
  const { userId, sessionKey, now } = ctx;
84535
- const sessionIsRecent = isSessionRecent(sessionKey, now);
84546
+ const sessionIsRecent = await isSessionRecent(sessionKey, now);
84536
84547
  if (sessionIsRecent) {
84537
84548
  ctx.db.drizzle.update(users).set({ emailOffered }).where(eq(users.id, userId)).returning().then(async ([user2]) => {
84538
84549
  const { emailVerified: emailVerified2, username: username2 } = user2;
@@ -84644,7 +84655,7 @@ var appRouter = trpc.router({
84644
84655
  message: `${attemptsRemaining} attempts remaining.`
84645
84656
  });
84646
84657
  }
84647
- const sessionKey = createSession(userId, ctx.now);
84658
+ const sessionKey = await createSession(userId, ctx);
84648
84659
  successful = true;
84649
84660
  ctx.logger.info(`\uD83D\uDD11 sign in successful as`, email2);
84650
84661
  ctx.res.setHeader(`Set-Cookie`, `sessionKey=${sessionKey}; HttpOnly; Expires=${60 * 60 * 24 * 7}; Path=/`);
@@ -84668,8 +84679,7 @@ var appRouter = trpc.router({
84668
84679
  }),
84669
84680
  closeSession: userSessionProcedure.input(type({ username: `string` })).mutation(({ ctx }) => {
84670
84681
  const { sessionKey } = ctx;
84671
- userSessions.delete(sessionKey);
84672
- sessionCreatedTimes.delete(sessionKey);
84682
+ ctx.db.drizzle.delete(userSessions).where(eq(userSessions.sessionKey, sessionKey));
84673
84683
  }),
84674
84684
  verifyAccountAction: loggedProcedure.input(type({ oneTimeCode: `string`, userKey: `string`, "+": `delete` })).mutation(async ({ input, ctx }) => {
84675
84685
  const { oneTimeCode, userKey } = input;
@@ -84756,7 +84766,7 @@ var appRouter = trpc.router({
84756
84766
  }
84757
84767
  await ctx.db.drizzle.delete(accountActions).where(eq(accountActions.userId, user.id));
84758
84768
  const { username } = user;
84759
- const sessionKey = createSession(user.id, ctx.now);
84769
+ const sessionKey = await createSession(user.id, ctx);
84760
84770
  ctx.res.setHeader(`Set-Cookie`, `sessionKey=${sessionKey}; HttpOnly; Expires=${60 * 60 * 24 * 7}; Path=/`);
84761
84771
  return {
84762
84772
  userId,
@@ -84997,14 +85007,17 @@ var sessionMiddleware = async (socket, next2) => {
84997
85007
  }
84998
85008
  const userKey = `user::${user.id}`;
84999
85009
  const socketKey = `socket::${socket.id}`;
85000
- if (userSessions?.has(user.id, sessionKey)) {
85010
+ const session = await db.drizzle.query.userSessions.findFirst({
85011
+ where: eq(userSessions.sessionKey, sessionKey)
85012
+ });
85013
+ if (session) {
85001
85014
  const socketState = findInStore(IMPLICIT.STORE, socketAtoms, socketKey);
85002
85015
  setIntoStore(IMPLICIT.STORE, socketState, socket);
85003
85016
  editRelationsInStore(IMPLICIT.STORE, usersOfSockets, (relations) => {
85004
85017
  relations.set(userKey, socketKey);
85005
85018
  });
85006
- setIntoStore(IMPLICIT.STORE, userKeysAtom, (index) => index.add(userKey));
85007
- setIntoStore(IMPLICIT.STORE, socketKeysAtom, (index) => index.add(socketKey));
85019
+ setIntoStore(IMPLICIT.STORE, userKeysAtom, (index2) => index2.add(userKey));
85020
+ setIntoStore(IMPLICIT.STORE, socketKeysAtom, (index2) => index2.add(socketKey));
85008
85021
  logger.info(`${username} connected on ${socket.id}`);
85009
85022
  next2();
85010
85023
  } else {
@@ -85031,9 +85044,9 @@ var serveSocket = (socket) => {
85031
85044
  relations.delete(socketKey);
85032
85045
  });
85033
85046
  if (userKey) {
85034
- setIntoStore(IMPLICIT.STORE, userKeysAtom, (index) => (index.delete(userKey), index));
85047
+ setIntoStore(IMPLICIT.STORE, userKeysAtom, (index2) => (index2.delete(userKey), index2));
85035
85048
  }
85036
- setIntoStore(IMPLICIT.STORE, socketKeysAtom, (index) => (index.delete(socketKey), index));
85049
+ setIntoStore(IMPLICIT.STORE, socketKeysAtom, (index2) => (index2.delete(socketKey), index2));
85037
85050
  logger.info(`${socket.id} disconnected`);
85038
85051
  });
85039
85052
  };