tsondb 0.20.3 → 0.20.5

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.
@@ -9,7 +9,6 @@ export const EntityDecl = (sourceUrl, options) => {
9
9
  return {
10
10
  ...options,
11
11
  instanceDisplayNameCustomizer: options.instanceDisplayNameCustomizer, // ignore contravariance of registered entity type
12
- customConstraints: options.customConstraints, // ignore contravariance of registered entity type
13
12
  kind: NodeKind.EntityDecl,
14
13
  sourceUrl,
15
14
  parameters: [],
@@ -55,16 +55,16 @@ export type RegisteredEnumOrTypeAlias<Name extends string, T = Register> = Regis
55
55
  */
56
56
  export declare const Case: {
57
57
  <T extends string>(type: T): Case<T>;
58
- <T extends string, V extends NonNullable<unknown> | null>(type: T, value: V): Case<T, V>;
58
+ <T extends string, V extends AnyNonNullish | null>(type: T, value: V): Case<T, V>;
59
59
  };
60
60
  /**
61
61
  * Type representing an enum case object.
62
62
  */
63
63
  export type Case<K extends string, T = undefined> = {
64
- [P in K]: T extends NonNullable<unknown> | null ? {
64
+ [P in K]: T extends AnyNonNullish | null ? {
65
65
  [Key in ENUM_DISCRIMINATOR_KEY]: P;
66
66
  } & {
67
- [Key in P]: Extract<T, NonNullable<unknown> | null>;
67
+ [Key in P]: Extract<T, AnyNonNullish | null>;
68
68
  } : {
69
69
  [Key in ENUM_DISCRIMINATOR_KEY]: P;
70
70
  };
@@ -1,2 +1,2 @@
1
1
  import type { TransactionStep } from "../transaction.ts";
2
- export declare const applyStepsToDisk: (root: string, steps: TransactionStep[]) => Promise<import("@elyukai/utils/result").Ok<void> | import("@elyukai/utils/result").Error<Error>>;
2
+ export declare const applyStepsToDisk: (root: string, steps: TransactionStep[]) => Promise<import("@elyukai/utils/result").Error<Error> | import("@elyukai/utils/result").Ok<void>>;
@@ -43,7 +43,7 @@ export const sendErrorResponse = (res, error) => {
43
43
  res.status(error.code).send(error.message);
44
44
  }
45
45
  else if (error instanceof Error) {
46
- res.status(500).send(error.message);
46
+ res.status(500).send(getErrorMessageForDisplay(error));
47
47
  }
48
48
  else {
49
49
  res.status(500).send(String(error));
@@ -2,7 +2,7 @@ import { anySameIndices } from "@elyukai/utils/array/filters";
2
2
  import { flatCombine } from "@elyukai/utils/array/transformations";
3
3
  import { deepEqual } from "@elyukai/utils/equality";
4
4
  import { error, isError, mapError, ok } from "@elyukai/utils/result";
5
- import { getValueAtKeyPath, renderKeyPath } from "../../shared/schema/utils/keyPath.js";
5
+ import { getValueAtKeyPath, getValueAtKeyPathIfDefined, renderKeyPath, } from "../../shared/schema/utils/keyPath.js";
6
6
  import {} from "./databaseInMemory.js";
7
7
  export class UniqueConstraintError extends Error {
8
8
  parts;
@@ -42,7 +42,7 @@ export const checkUniqueConstraintsForEntity = (entity, instances, instanceOverv
42
42
  const index = instances.flatMap(({ id, content }) => flatCombine(normalizedConstraint.map(elem => {
43
43
  if ("keyPath" in elem) {
44
44
  return [
45
- getValueAtKeyPath(content, elem.keyPath) ??
45
+ getValueAtKeyPathIfDefined(content, elem.keyPath) ??
46
46
  (elem.keyPathFallback
47
47
  ? getValueAtKeyPath(content, elem.keyPathFallback)
48
48
  : undefined),
@@ -51,7 +51,7 @@ export const checkUniqueConstraintsForEntity = (entity, instances, instanceOverv
51
51
  else {
52
52
  return Object.entries(getValueAtKeyPath(content, elem.entityMapKeyPath)).map(([nestedId, nestedContent]) => [
53
53
  nestedId,
54
- getValueAtKeyPath(nestedContent, elem.keyPathInEntityMap) ??
54
+ getValueAtKeyPathIfDefined(nestedContent, elem.keyPathInEntityMap) ??
55
55
  (elem.keyPathInEntityMapFallback
56
56
  ? getValueAtKeyPath(nestedContent, elem.keyPathInEntityMapFallback)
57
57
  : undefined),
@@ -14,3 +14,4 @@ export declare const renderKeyPath: (keyPath: KeyPath) => string;
14
14
  export declare const renderParsedKeyPath: (keyPath: ParsedKeyPath) => string;
15
15
  export declare const getAtKeyPath: <T>(value: T, previousPath: ParsedKeyPath, remainingKeyPath: ParsedKeyPath, throwOnPathMismatch: boolean, fArray: (value: T, index: number) => Result<T, (previousPath: string) => string>, fObject: (value: T, key: string) => Result<T, (previousPath: string) => string>, ...fs: ((value: T, key: KeyPathElement) => Result<[T, skipKey?: boolean], void>)[]) => T;
16
16
  export declare const getValueAtKeyPath: (value: unknown, keyPath: KeyPath, throwOnPathMismatch?: boolean) => unknown;
17
+ export declare const getValueAtKeyPathIfDefined: (value: unknown, keyPath: KeyPath) => unknown;
@@ -1,6 +1,6 @@
1
1
  import { isNotEmpty } from "@elyukai/utils/array/nonEmpty";
2
2
  import { error, isOk, ok, reduce } from "@elyukai/utils/result";
3
- import { assertExhaustive } from "@elyukai/utils/typeSafety";
3
+ import { assertExhaustive, trySafe } from "@elyukai/utils/typeSafety";
4
4
  const intPattern = /^(?:0|[1-9][0-9])*$/;
5
5
  export const parseKeyPath = (keyPath) => normalizeKeyPath(keyPath).map(part => {
6
6
  if (intPattern.test(part)) {
@@ -63,3 +63,4 @@ export const getValueAtKeyPath = (value, keyPath, throwOnPathMismatch = false) =
63
63
  ? ok(value[name])
64
64
  : error(previousPath => `Object at key path "${previousPath}" does not contain the key ${name}.`)
65
65
  : error(previousPath => `Key path "${previousPath}" does not contain an object.`));
66
+ export const getValueAtKeyPathIfDefined = (value, keyPath) => trySafe(() => getValueAtKeyPath(value, keyPath, true));