uql-orm 0.91.0 → 0.91.1

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.
@@ -86,9 +86,6 @@ export class EntityCodeGenerator {
86
86
  if (col.type.category === 'json') {
87
87
  uqlImports.add('type Json');
88
88
  }
89
- if (isFilledColumn(col)) {
90
- uqlImports.add('type Filled');
91
- }
92
89
  }
93
90
  // Check for relation decorators
94
91
  if (this.options.includeRelations) {
@@ -353,8 +350,8 @@ export class EntityCodeGenerator {
353
350
  }
354
351
  /**
355
352
  * A column's property as source, declared the way every read and insert types it: present (`!`) where
356
- * the column is NOT NULL, `Filled` where a default fills it (a single-column key stays `!`, which an insert
357
- * leaves out anyway), `| null` where it holds NULL, `readonly` where the database computes it.
353
+ * the column is NOT NULL, left out of an insert (`?`) where a default fills it (a single-column key stays
354
+ * `!`, which an insert leaves out anyway), `| null` where it holds NULL, `readonly` where the database computes it.
358
355
  */
359
356
  function propertySource(col, propertyName) {
360
357
  const type = col.enum
@@ -366,11 +363,8 @@ function propertySource(col, propertyName) {
366
363
  if (col.nullable && !col.isPrimaryKey) {
367
364
  return `${written}${propertyName}?: ${type} | null`;
368
365
  }
369
- return `${written}${propertyName}!: ${isFilledColumn(col) ? `Filled<${type}>` : type}`;
370
- }
371
- /** A non-null column its default fills, which every read has and an insert may leave out. */
372
- function isFilledColumn(col) {
373
- return !col.nullable && !col.isPrimaryKey && col.generatedAs === undefined && col.defaultValue !== undefined;
366
+ const filled = !col.isPrimaryKey && col.defaultValue !== undefined;
367
+ return `${written}${propertyName}${filled ? '?' : '!'}: ${type}`;
374
368
  }
375
369
  /**
376
370
  * Create an EntityCodeGenerator from SchemaAST.
@@ -19,10 +19,7 @@ export function entityTypesSource(entities) {
19
19
  ];
20
20
  return `export interface ${names.get(meta.entity)} {\n${members.join('\n')}\n}`;
21
21
  });
22
- const imports = metas.some((meta) => Object.values(meta.fields).some((field) => field && isFilledField(field)))
23
- ? ["import type { Filled } from 'uql-orm';", '']
24
- : [];
25
- return ['// Generated by `uql-migrate types`. Do not edit.', '', ...imports, ...interfaces, ''].join('\n');
22
+ return ['// Generated by `uql-migrate types`. Do not edit.', '', ...interfaces, ''].join('\n');
26
23
  }
27
24
  /**
28
25
  * One interface name per entity, settled before anything is written so a relation and its target
@@ -53,8 +50,8 @@ function propertyName(key) {
53
50
  }
54
51
  /**
55
52
  * A field as an entity class declares it: required where every read has it and an insert names it, a
56
- * key included, which an insert leaves out anyway; `Filled` where a default fills it; optional where a
57
- * read skips it (`eager: false`); `| null` where the column holds NULL; `readonly` where it is computed.
53
+ * key included, which an insert leaves out anyway; optional where a default fills it or a read skips it
54
+ * (`eager: false`); `| null` where the column holds NULL; `readonly` where the database computes it.
58
55
  */
59
56
  function fieldMember(key, field) {
60
57
  const type = fieldType(field);
@@ -62,24 +59,13 @@ function fieldMember(key, field) {
62
59
  if (!field) {
63
60
  return ` ${name}?: ${type};`;
64
61
  }
65
- if (isFilledField(field)) {
66
- return ` ${name}: Filled<${type}>;`;
67
- }
68
62
  const written = field.computed === undefined ? '' : 'readonly ';
69
63
  if (!field.isId && field.nullable !== false) {
70
64
  return ` ${written}${name}?: ${type} | null;`;
71
65
  }
72
- const optional = !field.isId && field.eager === false;
66
+ const optional = !field.isId && (field.defaultValue !== undefined || field.onInsert !== undefined || field.eager === false);
73
67
  return ` ${written}${name}${optional ? '?' : ''}: ${type};`;
74
68
  }
75
- /** A non-null field a default or `onInsert` fills, which every read has and an insert may leave out. */
76
- function isFilledField(field) {
77
- return (!field.isId &&
78
- field.nullable === false &&
79
- field.eager !== false &&
80
- field.computed === undefined &&
81
- (field.defaultValue !== undefined || field.onInsert !== undefined));
82
- }
83
69
  /**
84
70
  * The property type a column reads back as, resolved the way the DDL resolves it - so a foreign key
85
71
  * reports the type of the key it points at rather than the fallback its own options carry.
@@ -13,16 +13,6 @@ export declare const idKey: unique symbol;
13
13
  * must not start demanding one.
14
14
  */
15
15
  export declare const versionKey: unique symbol;
16
- /**
17
- * A non-null field uql or the database fills on insert, by `onInsert` or a default: every read has it,
18
- * and an insert may leave it out. `createdAt!: Filled<Date>`.
19
- */
20
- export type Filled<T> = T & FilledBrand;
21
- declare const filled: unique symbol;
22
- /** The marker {@link Filled} adds: a symbol key, so no string key or autocomplete shows it. */
23
- export interface FilledBrand {
24
- readonly [filled]?: never;
25
- }
26
16
  /** The filter `@Field({ softDelete })` registers, a name reserved against an entity's own filters. */
27
17
  export declare const SOFT_DELETE_FILTER = "softDelete";
28
18
  /** A filter name an entity may declare: any but {@link SOFT_DELETE_FILTER}, which a refusal names. */
@@ -46,14 +36,11 @@ export type WritableKey<E> = {
46
36
  readonly [K in FieldKey<E>]-?: IsEqual<Pick<E, K>, Writable<Pick<E, K>>> extends true ? K : never;
47
37
  }[FieldKey<E>];
48
38
  /**
49
- * What an insert may leave out: a single-column key, which something usually generates, the version,
50
- * which uql starts at 0, and a {@link Filled} field. A composite key is the references a row is made of,
51
- * so an insert names it.
39
+ * What an insert may leave out however the entity declares it: a single-column key, which something
40
+ * usually generates, and the version, which uql starts at 0. A composite key is the references a row is
41
+ * made of, so an insert names it.
52
42
  */
53
- type FilledKey<E> = SoleIdKey<E> | VersionKey<E> | FilledFieldKey<E>;
54
- type FilledFieldKey<E> = {
55
- readonly [K in WritableKey<E>]-?: typeof filled extends keyof NonNullable<E[K]> ? K : never;
56
- }[WritableKey<E>];
43
+ type FilledKey<E> = SoleIdKey<E> | VersionKey<E>;
57
44
  /**
58
45
  * A whole-record write as a caller supplies one: {@link EntityData} without the fields it cannot write,
59
46
  * a {@link FilledKey} optional. That part is a conditional, which TypeScript leaves shut while it types a
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://uql-orm.dev",
4
4
  "description": "JSON-native TypeScript ORM for Bun, Browsers, Edge, Deno, Node, Workers. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
5
5
  "license": "MIT",
6
- "version": "0.91.0",
6
+ "version": "0.91.1",
7
7
  "type": "module",
8
8
  "engines": {
9
9
  "node": ">=24"
@@ -76,7 +76,7 @@ export class Post {
76
76
 
77
77
  - Every `@Field` states its `type` (`String`, `Number`, `Boolean`, `Date` (an instant, bound and read as UTC on every engine; `TIMESTAMPTZ` on Postgres and CockroachDB, `DATETIME(3)` on MySQL and MariaDB; `precision` sets its fractional-second digits), `BigInt`, or a column type such as `'uuid'`, `'text'`, `'jsonb'`), except a foreign key, which takes `references` and inherits the target key's type.
78
78
  - A column is nullable unless it says `nullable: false`, and its property must admit `null` to match: `title?: string | null`. A property typed without `| null` on a nullable column is a compile error.
79
- - Declare a `nullable: false` column `!` (`email!: string`): reads have it and inserts must name it, except a single-column key and a `version`, which uql fills. One `onInsert` or a `defaultValue` fills is `Filled<T>` (`createdAt!: Filled<Date>`): reads have it, inserts may leave it out. Declare `?` the rest an insert may leave out: a nullable, `eager: false` or `computed` field, and relations.
79
+ - Declare a `nullable: false` column `!` (`email!: string`): reads have it and inserts must name it, except a single-column key and a `version`, which uql fills. Declare `?` whatever an insert may leave out: a nullable, `onInsert`, `defaultValue`, `eager: false` or `computed` field, and relations.
80
80
  - An engine's own column type is a `raw` constant, ``columnType: raw`tsvector` ``, rendered verbatim and carrying its own `length`/`precision`: never a bare string.
81
81
  - Members are named by callbacks, never by strings: `mappedBy: (post) => post.author`, `references: (post) => post.authorId`.
82
82
  - `@ManyToMany({ entity: () => Tag, through: () => PostTag })` names its junction entity.