@orkestrel/database 0.0.14 → 0.0.15

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.
@@ -83,7 +83,7 @@ var METADATA_TABLE = "_metadata";
83
83
  * ```
84
84
  */
85
85
  function matchesAbsentPath(error) {
86
- if (!(error instanceof Error) || !("code" in error)) return false;
86
+ if (!(0, _orkestrel_contract.isError)(error) || !("code" in error)) return false;
87
87
  return error.code === "ENOENT" || error.code === "ENOTDIR";
88
88
  }
89
89
  /**
@@ -293,16 +293,16 @@ function encodeValue(value, column) {
293
293
  return column.storage === "text" || column.storage === "json" ? /* @__PURE__ */ new Uint8Array() : String(null);
294
294
  }
295
295
  switch (column.storage) {
296
- case "boolean": return typeof value === "boolean" ? value ? 1 : 0 : null;
296
+ case "boolean": return (0, _orkestrel_contract.isBoolean)(value) ? value ? 1 : 0 : null;
297
297
  case "json": try {
298
298
  return JSON.stringify((0, _orkestrel_contract.cloneJSONValue)(value));
299
299
  } catch {
300
300
  return null;
301
301
  }
302
- case "integer": return typeof value === "bigint" || typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) ? value : null;
303
- case "real": return typeof value === "bigint" || typeof value === "number" && Number.isFinite(value) ? value : null;
304
- case "text": return typeof value === "string" ? value : null;
305
- case "blob": return value instanceof Uint8Array ? value : null;
302
+ case "integer": return (0, _orkestrel_contract.isBigInt)(value) || (0, _orkestrel_contract.isFiniteNumber)(value) && (0, _orkestrel_contract.isInteger)(value) ? value : null;
303
+ case "real": return (0, _orkestrel_contract.isBigInt)(value) || (0, _orkestrel_contract.isFiniteNumber)(value) ? value : null;
304
+ case "text": return (0, _orkestrel_contract.isString)(value) ? value : null;
305
+ case "blob": return (0, _orkestrel_contract.isUint8Array)(value) ? value : null;
306
306
  }
307
307
  }
308
308
  /**
@@ -327,23 +327,23 @@ function encodeValue(value, column) {
327
327
  */
328
328
  function decodeValue(value, column) {
329
329
  if (value === null) return column.nullable && !column.optional ? null : void 0;
330
- if (column.optional && column.nullable && (column.storage === "text" || column.storage === "json" ? value instanceof Uint8Array && value.byteLength === 0 : value === String(null))) return null;
330
+ if (column.optional && column.nullable && (column.storage === "text" || column.storage === "json" ? (0, _orkestrel_contract.isUint8Array)(value) && value.byteLength === 0 : value === String(null))) return null;
331
331
  switch (column.storage) {
332
332
  case "boolean":
333
333
  if (value === 0 || value === 0n) return false;
334
334
  if (value === 1 || value === 1n) return true;
335
335
  return;
336
336
  case "json":
337
- if (typeof value !== "string") return void 0;
337
+ if (!(0, _orkestrel_contract.isString)(value)) return void 0;
338
338
  try {
339
339
  return structuredClone((0, _orkestrel_contract.cloneJSONValue)(JSON.parse(value)));
340
340
  } catch {
341
341
  return;
342
342
  }
343
- case "integer": return typeof value === "bigint" || typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) ? value : void 0;
344
- case "real": return typeof value === "bigint" || typeof value === "number" && Number.isFinite(value) ? value : void 0;
345
- case "text": return typeof value === "string" ? value : void 0;
346
- case "blob": return value instanceof Uint8Array ? value : void 0;
343
+ case "integer": return (0, _orkestrel_contract.isBigInt)(value) || (0, _orkestrel_contract.isFiniteNumber)(value) && (0, _orkestrel_contract.isInteger)(value) ? value : void 0;
344
+ case "real": return (0, _orkestrel_contract.isBigInt)(value) || (0, _orkestrel_contract.isFiniteNumber)(value) ? value : void 0;
345
+ case "text": return (0, _orkestrel_contract.isString)(value) ? value : void 0;
346
+ case "blob": return (0, _orkestrel_contract.isUint8Array)(value) ? value : void 0;
347
347
  }
348
348
  }
349
349
  /**
@@ -478,10 +478,10 @@ function deriveSQLiteIndexName(table, columns) {
478
478
  * ```
479
479
  */
480
480
  function inferValueStorage(value) {
481
- if (typeof value === "boolean") return "boolean";
482
- if (typeof value === "number") return Number.isInteger(value) ? "integer" : "real";
483
- if (typeof value === "bigint") return "integer";
484
- if (typeof value === "object" && value !== null) return "json";
481
+ if ((0, _orkestrel_contract.isBoolean)(value)) return "boolean";
482
+ if ((0, _orkestrel_contract.isNumber)(value)) return (0, _orkestrel_contract.isInteger)(value) ? "integer" : "real";
483
+ if ((0, _orkestrel_contract.isBigInt)(value)) return "integer";
484
+ if ((0, _orkestrel_contract.isObject)(value)) return "json";
485
485
  return "text";
486
486
  }
487
487
  //#endregion
@@ -1396,7 +1396,7 @@ var JSONDriver = class {
1396
1396
  async #hydrate(memory, schema, tables) {
1397
1397
  for (const table of schema) {
1398
1398
  const rows = tables[table.name];
1399
- if (!Array.isArray(rows)) throw new _src_core.DatabaseError("DRIVER", "Stored JSON table is invalid", {
1399
+ if (!(0, _orkestrel_contract.isArray)(rows)) throw new _src_core.DatabaseError("DRIVER", "Stored JSON table is invalid", {
1400
1400
  path: this.#path,
1401
1401
  table: table.name,
1402
1402
  aspect: "container"
@@ -1974,7 +1974,7 @@ var SQLiteDriver = class {
1974
1974
  const keys = [];
1975
1975
  for (const row of rows) {
1976
1976
  const value = row[schema.primary];
1977
- if (typeof value === "string" || typeof value === "number") keys.push(value);
1977
+ if ((0, _orkestrel_contract.isString)(value) || (0, _orkestrel_contract.isNumber)(value)) keys.push(value);
1978
1978
  }
1979
1979
  return keys;
1980
1980
  });
@@ -2107,7 +2107,7 @@ var SQLiteDriver = class {
2107
2107
  });
2108
2108
  for (const [position, column] of group.entries()) {
2109
2109
  const entry = entries.find((candidate) => candidate.seqno === position || candidate.seqno === BigInt(position));
2110
- const stored = entry !== void 0 && (typeof entry.cid === "number" && Number.isInteger(entry.cid) && entry.cid >= 0 || typeof entry.cid === "bigint" && entry.cid >= 0n);
2110
+ const stored = entry !== void 0 && ((0, _orkestrel_contract.isInteger)(entry.cid) && entry.cid >= 0 || (0, _orkestrel_contract.isBigInt)(entry.cid) && entry.cid >= 0n);
2111
2111
  if (entry === void 0 || entry.name !== column || !stored || entry.desc !== 0 && entry.desc !== 0n || entry.coll !== "BINARY") throw new _src_core.DatabaseError("DRIVER", "SQLite index column does not match its declaration", {
2112
2112
  table: schema.name,
2113
2113
  aspect: "index",
@@ -2124,11 +2124,11 @@ var SQLiteDriver = class {
2124
2124
  if (row === void 0) return void 0;
2125
2125
  const version = row.version;
2126
2126
  const text = row.schema;
2127
- if (typeof text !== "string") throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata schema is invalid", {
2127
+ if (!(0, _orkestrel_contract.isString)(text)) throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata schema is invalid", {
2128
2128
  table: METADATA_TABLE,
2129
2129
  aspect: "metadata"
2130
2130
  });
2131
- if (typeof version !== "number" && typeof version !== "bigint") throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata version is invalid", {
2131
+ if (!(0, _orkestrel_contract.isNumber)(version) && !(0, _orkestrel_contract.isBigInt)(version)) throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata version is invalid", {
2132
2132
  table: METADATA_TABLE,
2133
2133
  aspect: "metadata"
2134
2134
  });
@@ -2142,7 +2142,7 @@ var SQLiteDriver = class {
2142
2142
  cause: error
2143
2143
  });
2144
2144
  }
2145
- if (!Array.isArray(parsed)) throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata schema is invalid", {
2145
+ if (!(0, _orkestrel_contract.isArray)(parsed)) throw new _src_core.DatabaseError("DRIVER", "Stored SQLite metadata schema is invalid", {
2146
2146
  table: METADATA_TABLE,
2147
2147
  aspect: "metadata"
2148
2148
  });
@@ -2261,7 +2261,7 @@ var SQLiteDriver = class {
2261
2261
  try {
2262
2262
  return operation();
2263
2263
  } catch (error) {
2264
- if (error instanceof _src_core.DatabaseError) throw error;
2264
+ if ((0, _src_core.isDatabaseError)(error)) throw error;
2265
2265
  if ((0, _orkestrel_sqlite.isSQLiteError)(error)) {
2266
2266
  if (error.code === "CONSTRAINT") throw new _src_core.DatabaseError("CONFLICT", error.message, {
2267
2267
  cause: error,
@@ -2281,7 +2281,7 @@ var SQLiteDriver = class {
2281
2281
  code: error.code
2282
2282
  });
2283
2283
  }
2284
- throw new _src_core.DatabaseError("DRIVER", error instanceof Error ? error.message : String(error), { cause: error });
2284
+ throw new _src_core.DatabaseError("DRIVER", (0, _orkestrel_contract.isError)(error) ? error.message : String(error), { cause: error });
2285
2285
  }
2286
2286
  }
2287
2287
  #require() {