@ultimat3/entity 31.30.0 → 31.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/entity",
3
- "version": "31.30.0",
3
+ "version": "31.32.0",
4
4
  "description": "A table + its domain type + invariants the database also enforces",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -44,9 +44,9 @@
44
44
  "test": "bun test"
45
45
  },
46
46
  "dependencies": {
47
- "@ultimat3/core": "31.30.0",
48
- "@ultimat3/db": "31.30.0",
49
- "@ultimat3/schema": "31.30.0",
50
- "@ultimat3/time": "31.30.0"
47
+ "@ultimat3/core": "31.32.0",
48
+ "@ultimat3/db": "31.32.0",
49
+ "@ultimat3/schema": "31.32.0",
50
+ "@ultimat3/time": "31.32.0"
51
51
  }
52
52
  }
package/src/aggregate.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  // same reason `bigint()` and `decimal()` hand back strings: a `number` loses digits past 2^53 and
8
8
  // a binary float loses cents.
9
9
 
10
+ import { renderFixShellArg } from '@ultimat3/core';
10
11
  import { columnFor } from './column';
11
12
  import type { EntityCore } from './entity';
12
13
  import { EntityError } from './errors';
@@ -64,7 +65,7 @@ export const notAggregatable = (
64
65
  fn === 'avg' && kind === 'money'
65
66
  ? `${entityName}.sum('${property}') and ${entityName}.count() — divide at the call site, where the rounding is a decision somebody made`
66
67
  : candidates.length === 0
67
- ? `x entities show ${entityName} --json # this entity declares no column ${fn} can be applied to`
68
+ ? `x entities show ${renderFixShellArg(entityName, '<entity>')} --json # this entity declares no column ${fn} can be applied to`
68
69
  : `${entityName}.${fn}('${candidates[0]}') # ${fn} takes one of: ${candidates.join(', ')}`,
69
70
  });
70
71
 
package/src/count-by.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  // a `countBy` against Postgres means; a rule added to one driver alone is the drift this file
5
5
  // exists to prevent.
6
6
 
7
+ import { renderFixShellArg } from '@ultimat3/core';
7
8
  import { columnFor } from './column';
8
9
  import type { EntityCore } from './entity';
9
10
  import { EntityError } from './errors';
@@ -57,7 +58,7 @@ const notGroupable = <Row>(
57
58
  cause: `${entity.$name}.${operation}('${property}'): ${reason}`,
58
59
  fix:
59
60
  first === undefined
60
- ? `x entities show ${entity.$name} --json # this entity declares no column a count can be keyed by`
61
+ ? `x entities show ${renderFixShellArg(entity.$name, '<entity>')} --json # this entity declares no column a count can be keyed by`
61
62
  : `${entity.$name}.${operation}('${first}') # group by one of: ${groupableColumns(entity).join(', ')}`,
62
63
  });
63
64
  };
@@ -6,6 +6,7 @@ import {
6
6
  isFixShellSafe,
7
7
  registerErrorCodes,
8
8
  registerErrorRetry,
9
+ renderFixShellArg,
9
10
  UltimateError,
10
11
  } from '@ultimat3/core';
11
12
 
@@ -184,7 +185,7 @@ export const invariantViolated = (
184
185
  new EntityError({
185
186
  code: 'X_INVARIANT_VIOLATED',
186
187
  cause: `${entityName}.${invariantName}: ${message}`,
187
- fix: `x entities show ${entityName} --json # shows the invariant and its SQL CHECK`,
188
+ fix: `x entities show ${renderFixShellArg(entityName, '<entity>')} --json # shows the invariant and its SQL CHECK`,
188
189
  });
189
190
 
190
191
  /**
package/src/errors.ts CHANGED
@@ -318,7 +318,9 @@ const BULK_WRITE_CALLS: Readonly<Record<string, string>> = {
318
318
 
319
319
  /** An op with no bulk form of its own — a batch loop, or a name this table has not met — names both. */
320
320
  const bulkWriteCall = (entityName: string, op: string | undefined): string => {
321
- const call = op === undefined ? undefined : BULK_WRITE_CALLS[op];
321
+ // The op is observed statement text: `BULK_WRITE_CALLS['constructor']` is the `Object` function.
322
+ const call =
323
+ op !== undefined && Object.hasOwn(BULK_WRITE_CALLS, op) ? BULK_WRITE_CALLS[op] : undefined;
322
324
  return call !== undefined
323
325
  ? `db.${entityName}.${call}`
324
326
  : `db.${entityName}.insertAll(rows), or db.${entityName}.updateWhere(filter, patch) for a loop of patches`;
package/src/n-plus-one.ts CHANGED
@@ -65,7 +65,8 @@ export const preloadsFor = (
65
65
  entityName: string,
66
66
  op: string | undefined,
67
67
  ): readonly PreloadCandidate[] => {
68
- const kind = op === undefined ? undefined : PRELOADABLE_BY_OP[op];
68
+ const kind =
69
+ op !== undefined && Object.hasOwn(PRELOADABLE_BY_OP, op) ? PRELOADABLE_BY_OP[op] : undefined;
69
70
  if (kind === undefined) return [];
70
71
  const candidates: PreloadCandidate[] = [];
71
72
  for (const relations of Object.values(relationMap())) {
package/src/seed.ts CHANGED
@@ -255,7 +255,7 @@ const softDeleteWipe = (entity: EntityCore): EntityError =>
255
255
  /** The row an update may write: everything the caller named, less what a match must not move. */
256
256
  const withoutPreserved = <Row>(row: Row, preserve: readonly string[]): Row => {
257
257
  const copy: Record<string, unknown> = { ...(row as Record<string, unknown>) };
258
- for (const property of preserve) delete copy[property];
258
+ for (const property of preserve) if (Object.hasOwn(copy, property)) delete copy[property];
259
259
  // `Repo` is typed for whole rows, and a partial one is exactly what keeps a column OUT of the
260
260
  // update set — `namedProperties` reads what the row owns. Same assertion the bulk live test takes.
261
261
  return copy as Row;