kysely-hydrate 0.7.0 → 0.7.2

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.
Files changed (2) hide show
  1. package/dist/index.d.mts +41 -45
  2. package/package.json +1 -1
package/dist/index.d.mts CHANGED
@@ -38,7 +38,8 @@ interface TypeErrorMessage<E extends string> {
38
38
  * - Produces readable error messages for invalid narrowing
39
39
  */
40
40
  type NarrowPartial<O$1, T> = DrainOuterGeneric<T extends object ? { [K in keyof O$1 & string]: K extends keyof T ? T[K] extends k.NotNull ? Exclude<O$1[K], null> : T[K] extends O$1[K] ? T[K] : TypeErrorMessage<`$narrowType() call failed: passed type does not exist in '${K}'s type union`> : O$1[K] } : never>;
41
- type Extend<A, B> = Flatten<keyof A & keyof B extends never ? A & B : { [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never }>;
41
+ type Extend<A, B> = Flatten<RawExtend<A, B>>;
42
+ type RawExtend<A, B> = keyof A & keyof B extends never ? A & B : { [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never };
42
43
  type ExtendWith<T, K$1 extends PropertyKey, V> = Flatten<K$1 & keyof T extends never ? T & { [_ in K$1]: V } : Omit<T, K$1> & { [_ in K$1]: V }>;
43
44
  /**
44
45
  * Ensures that U is a strict subset of T - all keys in U must exist in T
@@ -582,13 +583,18 @@ interface TQuerySet {
582
583
  * The final shape of the hydrated output row.
583
584
  */
584
585
  HydratedOutput: any;
586
+ /**
587
+ * Keys that have been omitted from the output. Tracked separately so they
588
+ * can be preserved through base query changes (e.g., .insert(), .update()).
589
+ */
590
+ OmittedKeys: PropertyKey;
585
591
  }
586
592
  interface TSelectQuerySet extends TQuerySet {
587
593
  BaseQuery: TSelectQuery;
588
594
  }
589
595
  type QuerySetFor<T extends TQuerySet> = T["IsMapped"] extends true ? MappedQuerySet<T> : QuerySet<T>;
590
596
  type TInput<T extends TQuerySet> = T["JoinedQuery"]["O"];
591
- type TOutput<T extends TQuerySet> = Flatten<T["HydratedOutput"]>;
597
+ type TOutput<T extends TQuerySet> = T["HydratedOutput"];
592
598
  interface TMapped<in out T extends TQuerySet, in out Output> {
593
599
  DB: T["DB"];
594
600
  IsMapped: true;
@@ -598,6 +604,7 @@ interface TMapped<in out T extends TQuerySet, in out Output> {
598
604
  JoinedQuery: T["JoinedQuery"];
599
605
  OrderableColumns: T["OrderableColumns"];
600
606
  HydratedOutput: Output;
607
+ OmittedKeys: T["OmittedKeys"];
601
608
  }
602
609
  interface TJoinedQueryWithBaseQuery<in out BaseAlias extends string, in out JoinedQuery extends TQuery, in out BaseQuery extends TQuery> {
603
610
  Type: "Select";
@@ -614,7 +621,8 @@ interface TWithBaseQuery<in out T extends TQuerySet, in out BaseQuery extends TQ
614
621
  Collections: T["Collections"];
615
622
  JoinedQuery: TJoinedQueryWithBaseQuery<T["BaseAlias"], T["JoinedQuery"], BaseQuery>;
616
623
  OrderableColumns: T["OrderableColumns"] | (keyof BaseQuery["O"] & string);
617
- HydratedOutput: Extend<BaseQuery["O"], TOutput<T>>;
624
+ HydratedOutput: Flatten<Omit<RawExtend<BaseQuery["O"], T["HydratedOutput"]>, T["OmittedKeys"]>>;
625
+ OmittedKeys: T["OmittedKeys"];
618
626
  }
619
627
  interface TWithOutput<in out T extends TQuerySet, in out Output> {
620
628
  DB: T["DB"];
@@ -625,6 +633,7 @@ interface TWithOutput<in out T extends TQuerySet, in out Output> {
625
633
  JoinedQuery: T["JoinedQuery"];
626
634
  OrderableColumns: T["OrderableColumns"];
627
635
  HydratedOutput: Output;
636
+ OmittedKeys: T["OmittedKeys"];
628
637
  }
629
638
  interface TWithExtendedOutput<in out T extends TQuerySet, in out Output> {
630
639
  DB: T["DB"];
@@ -635,6 +644,18 @@ interface TWithExtendedOutput<in out T extends TQuerySet, in out Output> {
635
644
  JoinedQuery: T["JoinedQuery"];
636
645
  OrderableColumns: T["OrderableColumns"];
637
646
  HydratedOutput: Extend<T["HydratedOutput"], Output>;
647
+ OmittedKeys: T["OmittedKeys"];
648
+ }
649
+ interface TWithOmit<in out T extends TQuerySet, in out K$1 extends PropertyKey> {
650
+ DB: T["DB"];
651
+ IsMapped: T["IsMapped"];
652
+ BaseAlias: T["BaseAlias"];
653
+ BaseQuery: T["BaseQuery"];
654
+ Collections: T["Collections"];
655
+ JoinedQuery: T["JoinedQuery"];
656
+ OrderableColumns: T["OrderableColumns"];
657
+ HydratedOutput: Flatten<Omit<T["HydratedOutput"], K$1>>;
658
+ OmittedKeys: T["OmittedKeys"] | K$1;
638
659
  }
639
660
  type NarrowOutput<T extends TQuerySet, Narrow> = NarrowPartial<T["HydratedOutput"], Narrow>;
640
661
  interface InitialJoinedQuery<in out DB$1, in out BaseAlias extends string, in out BaseO> {
@@ -686,7 +707,12 @@ type InferOutput<Q extends {
686
707
  _generics: {
687
708
  HydratedOutput: infer O;
688
709
  } | undefined;
689
- } ? Flatten<O> : never;
710
+ } ? O : never;
711
+ /**
712
+ * Given a TQuerySet, return a QuerySet or MappedQuerySet depending on whether the query set has
713
+ * been mapped (indicated by T["IsMapped"]).
714
+ */
715
+ type MaybeMappedQuerySet<T extends TQuerySet> = T["IsMapped"] extends true ? MappedQuerySet<T> : QuerySet<T>;
690
716
  /**
691
717
  * A query set that has been mapped with a transformation function.
692
718
  *
@@ -1220,7 +1246,7 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
1220
1246
  * This method call doesn't change the SQL in any way. This method simply
1221
1247
  * returns a copy of this query set with a new output type.
1222
1248
  */
1223
- $castTo<NewOutput>(): MappedQuerySet<TWithOutput<T, NewOutput>>;
1249
+ $castTo<NewOutput>(): MaybeMappedQuerySet<TWithOutput<T, NewOutput>>;
1224
1250
  /**
1225
1251
  * Narrows (parts of) the output type of the query.
1226
1252
  *
@@ -1229,7 +1255,7 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
1229
1255
  *
1230
1256
  * See {@link k.SelectQueryBuilder.$narrowType} for more information.
1231
1257
  */
1232
- $narrowType<Narrow>(): MappedQuerySet<TWithOutput<T, NarrowOutput<T, Narrow>>>;
1258
+ $narrowType<Narrow>(): MaybeMappedQuerySet<TWithOutput<T, NarrowOutput<T, Narrow>>>;
1233
1259
  /**
1234
1260
  * Asserts that query's output row type equals the given type `T`.
1235
1261
  *
@@ -1246,7 +1272,7 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
1246
1272
  *
1247
1273
  * See {@link k.SelectQueryBuilder.$assertType} for more information.
1248
1274
  */
1249
- $assertType<NewOutput extends TOutput<T>>(): TOutput<T> extends NewOutput ? MappedQuerySet<TWithOutput<T, NewOutput>> : TypeErrorMessage<"$assertType() call failed: The type passed in is not equal to the output type of the query.">;
1275
+ $assertType<NewOutput extends TOutput<T>>(): TOutput<T> extends NewOutput ? MaybeMappedQuerySet<TWithOutput<T, NewOutput>> : TypeErrorMessage<"$assertType() call failed: The type passed in is not equal to the output type of the query.">;
1250
1276
  /**
1251
1277
  * Switches the base query to an `INSERT` statement.
1252
1278
  *
@@ -1280,15 +1306,15 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
1280
1306
  * @param iqb - An insert query builder or factory function.
1281
1307
  * @returns A new QuerySet with the insert query as the base.
1282
1308
  */
1283
- insert<IQB extends k.InsertQueryBuilder<any, any, T["BaseQuery"]["O"]>>(iqb: InsertQueryBuilderOrFactory<T["DB"], IQB>): QuerySet<TWithBaseQuery<T, InferTInsertQuery<IQB>>>;
1309
+ insert<IQB extends k.InsertQueryBuilder<any, any, T["BaseQuery"]["O"]>>(iqb: InsertQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTInsertQuery<IQB>>>;
1284
1310
  /**
1285
1311
  * Like {@link insert}, but switches to an `UPDATE` statement.
1286
1312
  */
1287
- update<IQB extends k.UpdateQueryBuilder<any, any, any, T["BaseQuery"]["O"]>>(iqb: UpdateQueryBuilderOrFactory<T["DB"], IQB>): QuerySet<TWithBaseQuery<T, InferTUpdateQuery<IQB>>>;
1313
+ update<IQB extends k.UpdateQueryBuilder<any, any, any, T["BaseQuery"]["O"]>>(uqb: UpdateQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTUpdateQuery<IQB>>>;
1288
1314
  /**
1289
1315
  * Like {@link insert}, but switches to a `DELETE` statement.
1290
1316
  */
1291
- delete<IQB extends k.DeleteQueryBuilder<any, any, T["BaseQuery"]["O"]>>(iqb: DeleteQueryBuilderOrFactory<T["DB"], IQB>): QuerySet<TWithBaseQuery<T, InferTDeleteQuery<IQB>>>;
1317
+ delete<IQB extends k.DeleteQueryBuilder<any, any, T["BaseQuery"]["O"]>>(dqb: DeleteQueryBuilderOrFactory<T["DB"], IQB>): MaybeMappedQuerySet<TWithBaseQuery<T, InferTDeleteQuery<IQB>>>;
1292
1318
  }
1293
1319
  /**
1294
1320
  * A query set that supports nested joins and automatic hydration.
@@ -1305,39 +1331,6 @@ interface MappedQuerySet<in out T extends TQuerySet> extends k.Compilable, k.Ope
1305
1331
  * @template T - The query set's type parameters.
1306
1332
  */
1307
1333
  interface QuerySet<in out T extends TQuerySet> extends MappedQuerySet<T> {
1308
- /**
1309
- * Changes the output type of the query.
1310
- *
1311
- * This method call doesn't change the SQL in any way. This method simply
1312
- * returns a copy of this query set with a new output type.
1313
- */
1314
- $castTo<NewOutput>(): QuerySet<TWithOutput<T, NewOutput>>;
1315
- /**
1316
- * Narrows (parts of) the output type of the query.
1317
- *
1318
- * This method call doesn't change the SQL in any way. This method simply
1319
- * returns a copy of this query set with a narrowed output type.
1320
- *
1321
- * See {@link k.SelectQueryBuilder.$narrowType} for more information.
1322
- */
1323
- $narrowType<Narrow>(): QuerySet<TWithOutput<T, NarrowOutput<T, Narrow>>>;
1324
- /**
1325
- * Asserts that query's output row type equals the given type `T`.
1326
- *
1327
- * This method can be used to simplify excessively complex types to make
1328
- * TypeScript happy and faster.
1329
- *
1330
- * It's also useful as a type guard to ensure a query set matches an expected
1331
- * shape, similar to annotating a function's return type. For example,
1332
- * `.$assertType<UserDto>()` will produce a type error if the query's output
1333
- * doesn't match `UserDto`.
1334
- *
1335
- * Using this method doesn't reduce type safety at all. You have to pass in
1336
- * a type that is structurally equal to the current type.
1337
- *
1338
- * See {@link k.SelectQueryBuilder.$assertType} for more information.
1339
- */
1340
- $assertType<NewOutput extends TOutput<T>>(): TOutput<T> extends NewOutput ? QuerySet<TWithOutput<T, NewOutput>> : TypeErrorMessage<"$assertType() call failed: The type passed in is not equal to the output type of the query.">;
1341
1334
  /**
1342
1335
  * Configures extra computed fields to add to the hydrated output.
1343
1336
  * Each extra is a function that receives the full row (with prefixed columns
@@ -1409,7 +1402,7 @@ interface QuerySet<in out T extends TQuerySet> extends MappedQuerySet<T> {
1409
1402
  * @param keys - Field names to omit from the output.
1410
1403
  * @returns A new HydratedQueryBuilder with the fields omitted.
1411
1404
  */
1412
- omit<K$1 extends keyof TInput<T>>(keys: readonly K$1[]): QuerySet<TWithOutput<T, Omit<TOutput<T>, K$1>>>;
1405
+ omit<K$1 extends keyof TInput<T>>(keys: readonly K$1[]): QuerySet<TWithOmit<T, K$1>>;
1413
1406
  /**
1414
1407
  * Extends this query builder's hydration configuration with another Hydrator.
1415
1408
  * The other Hydrator's configuration takes precedence in case of conflicts.
@@ -2310,6 +2303,7 @@ interface TQuerySetWithAttach<in out T extends TQuerySet, in out Key extends str
2310
2303
  }>;
2311
2304
  OrderableColumns: T["OrderableColumns"];
2312
2305
  HydratedOutput: ExtendWith<T["HydratedOutput"], Key, AttachedOutputMap<FetchFnReturn>[Type]>;
2306
+ OmittedKeys: T["OmittedKeys"];
2313
2307
  }
2314
2308
  interface QuerySetWithAttach<in out T extends TQuerySet, in out Key extends string, in out Type extends TAttachType, in out FetchFnReturn extends SomeFetchFnReturn> extends QuerySet<TQuerySetWithAttach<T, Key, Type, FetchFnReturn>> {}
2315
2309
  type NestedQuerySetOrFactory<T extends TQuerySet, Alias extends string, TNested extends TSelectQuerySet> = MappedQuerySet<TNested> | JoinBuilderCallback<T, Alias, TNested>;
@@ -2355,6 +2349,7 @@ type TQuerySetWithJoin<T extends TQuerySet, Key extends string, Type extends TJo
2355
2349
  JoinedQuery: JoinedQueryMap<T, Key, TNested>[Type];
2356
2350
  OrderableColumns: TOrderableColumnsWithJoin<T, Key, Type, TNested>;
2357
2351
  HydratedOutput: ExtendWith<T["HydratedOutput"], Key, JoinHydratedRowMap<TNested>[Type]>;
2352
+ OmittedKeys: T["OmittedKeys"];
2358
2353
  }>;
2359
2354
  interface QuerySetWithJoin<in out T extends TQuerySet, in out Key extends string, in out Type extends TJoinType, in out TNested extends TSelectQuerySet> extends QuerySet<TQuerySetWithJoin<T, Key, Type, TNested>> {}
2360
2355
  interface InitialQuerySet<in out DB$1, in out BaseAlias extends string, in out BaseQuery extends TQuery> extends QuerySet<{
@@ -2365,7 +2360,8 @@ interface InitialQuerySet<in out DB$1, in out BaseAlias extends string, in out B
2365
2360
  Collections: {};
2366
2361
  JoinedQuery: InitialJoinedQuery<BaseQuery["DB"], BaseAlias, BaseQuery["O"]>;
2367
2362
  OrderableColumns: keyof BaseQuery["O"] & string;
2368
- HydratedOutput: BaseQuery["O"];
2363
+ HydratedOutput: Flatten<BaseQuery["O"]>;
2364
+ OmittedKeys: never;
2369
2365
  }> {}
2370
2366
  interface SelectCreator<DB$1> {
2371
2367
  selectFrom: k.QueryCreator<DB$1>["selectFrom"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely-hydrate",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Explicit ORM-style queries with Kysely",
5
5
  "homepage": "https://github.com/GiacoCorsiglia/kysely-hydrate#readme",
6
6
  "bugs": {