@noego/sqlego 0.1.6-dev.6 → 0.1.6-dev.7

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/src/protocol.ts CHANGED
@@ -73,12 +73,10 @@ export type Request =
73
73
  | { id: number; op: 'stop' }
74
74
  /**
75
75
  * Asks this owner process to serve one more file: open it with `pragmas`
76
- * (its defaults when absent) and listen on that file's own socket. `claim`
77
- * is the file's claim lease the asking client holds (`<generation>:<token>`);
78
- * the owner takes it over before opening the file and refuses if it cannot
79
- * (`lease.ts`). The reply names the socket to connect to.
76
+ * (its defaults when absent), listen on that file's own socket, release
77
+ * that file's claim lock. The reply names the socket to connect to.
80
78
  */
81
- | { id: number; op: 'adopt'; file: string; pragmas?: readonly string[]; idleTimeoutMs?: number; claim?: string };
79
+ | { id: number; op: 'adopt'; file: string; pragmas?: readonly string[]; idleTimeoutMs?: number };
82
80
 
83
81
  export type RunResult = Readonly<{ changes: number; lastInsertRowid: number | bigint }>;
84
82
  export type QueryResult = Readonly<{ rows: SqlRow[] }>;
@@ -641,9 +639,7 @@ export function parseRequest(input: unknown) {
641
639
  }
642
640
  const idleTimeoutMs = fields.idleTimeoutMs;
643
641
  if (idleTimeoutMs !== undefined && (typeof idleTimeoutMs !== 'number' || !(idleTimeoutMs > 0))) return reject(id, 'idleTimeoutMs must be a positive number');
644
- const claim = fields.claim;
645
- if (claim !== undefined && (typeof claim !== 'string' || claim.length === 0)) return reject(id, 'adopt claim must be a non-empty string');
646
- const request: Request = { id, op: 'adopt', file: fields.file, pragmas: pragmas === undefined ? undefined : [...pragmas], idleTimeoutMs, claim };
642
+ const request: Request = { id, op: 'adopt', file: fields.file, pragmas: pragmas === undefined ? undefined : [...pragmas], idleTimeoutMs };
647
643
  return Result.ok(request);
648
644
  }
649
645
  default:
@@ -1130,13 +1126,6 @@ export function splitFrames(buffer: string): { frames: string[]; rest: string }
1130
1126
  return { frames: lines.filter((line) => line.length > 0), rest };
1131
1127
  }
1132
1128
 
1133
- /**
1134
- * The longest request frame the server reads, in decoded characters (the
1135
- * newline not counted). A longer one is never complete in memory: the
1136
- * server drops the connection once an unfinished frame passes it.
1137
- */
1138
- export const DEFAULT_MAX_FRAME_LENGTH = 64 * 1024 * 1024;
1139
-
1140
1129
  /**
1141
1130
  * The frames of one socket, read chunk by chunk in work proportional to what
1142
1131
  * arrives, however finely it is chunked: only the new chunk is searched for
@@ -1148,67 +1137,38 @@ export const DEFAULT_MAX_FRAME_LENGTH = 64 * 1024 * 1024;
1148
1137
  */
1149
1138
  export class FrameReader {
1150
1139
  private pieces: string[] = [];
1151
- /** Characters held in `pieces`: the length of the unfinished frame so far. */
1152
- private held = 0;
1153
- private overflowed = false;
1154
1140
  private decoder: TextDecoder | null = null;
1155
1141
  private searched = 0;
1156
1142
 
1157
- /**
1158
- * `maxFrameLength` bounds one frame in characters (its newline not
1159
- * counted); unbounded by default, as a client reads replies of any size.
1160
- */
1161
- constructor(private readonly maxFrameLength = Number.POSITIVE_INFINITY) {}
1162
-
1163
1143
  /** Characters searched for a newline so far: each one pushed is searched once. */
1164
1144
  get scannedCharacters(): number {
1165
1145
  return this.searched;
1166
1146
  }
1167
1147
 
1168
- /**
1169
- * Whether a frame passed `maxFrameLength`. Its pieces were dropped and
1170
- * nothing more is read until `reset`: the stream has no trustworthy next
1171
- * frame boundary.
1172
- */
1173
- get oversized(): boolean {
1174
- return this.overflowed;
1175
- }
1176
-
1177
1148
  /** The frames `chunk` completes, in order; its unterminated tail waits for the next chunk. */
1178
1149
  push(chunk: string): string[] {
1179
- if (this.overflowed) return [];
1180
1150
  let newline = chunk.indexOf('\n');
1181
1151
  if (newline < 0) {
1182
1152
  this.searched += chunk.length;
1183
- if (chunk.length > 0) {
1184
- this.held += chunk.length;
1185
- if (this.held > this.maxFrameLength) return this.overflow([]);
1186
- this.pieces.push(chunk);
1187
- }
1153
+ if (chunk.length > 0) this.pieces.push(chunk);
1188
1154
  return [];
1189
1155
  }
1190
1156
  const frames: string[] = [];
1191
1157
  let start = 0;
1192
1158
  while (newline >= 0) {
1193
1159
  this.searched += newline + 1 - start;
1194
- if (this.held + (newline - start) > this.maxFrameLength) return this.overflow(frames);
1195
1160
  let frame = chunk.slice(start, newline);
1196
1161
  if (this.pieces.length > 0) {
1197
1162
  this.pieces.push(frame);
1198
1163
  frame = this.pieces.join('');
1199
1164
  this.pieces = [];
1200
1165
  }
1201
- this.held = 0;
1202
1166
  if (frame.length > 0) frames.push(frame);
1203
1167
  start = newline + 1;
1204
1168
  newline = chunk.indexOf('\n', start);
1205
1169
  }
1206
1170
  this.searched += chunk.length - start;
1207
- if (start < chunk.length) {
1208
- this.held = chunk.length - start;
1209
- if (this.held > this.maxFrameLength) return this.overflow(frames);
1210
- this.pieces.push(chunk.slice(start));
1211
- }
1171
+ if (start < chunk.length) this.pieces.push(chunk.slice(start));
1212
1172
  return frames;
1213
1173
  }
1214
1174
 
@@ -1226,18 +1186,8 @@ export class FrameReader {
1226
1186
  /** Drops an unfinished frame (and a partly received character): the stream is starting over or was given up. */
1227
1187
  reset(): void {
1228
1188
  this.pieces = [];
1229
- this.held = 0;
1230
- this.overflowed = false;
1231
1189
  this.decoder = null;
1232
1190
  }
1233
-
1234
- /** Gives up the unfinished frame; `frames` are the ones completed before it. */
1235
- private overflow(frames: string[]): string[] {
1236
- this.pieces = [];
1237
- this.held = 0;
1238
- this.overflowed = true;
1239
- return frames;
1240
- }
1241
1191
  }
1242
1192
 
1243
1193
  function replaceBigInt(_key: string, value: unknown): unknown {