kysely-rizzolver 0.0.2 → 0.0.3

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 (78) hide show
  1. package/README.md +14 -10
  2. package/dist/cjs/fetch-result-factory.js +1 -0
  3. package/dist/cjs/fetch-result-factory.js.map +1 -0
  4. package/dist/cjs/fetch-result.d.ts +11 -8
  5. package/dist/cjs/fetch-result.js +5 -0
  6. package/dist/cjs/fetch-result.js.map +1 -0
  7. package/dist/cjs/fk-gather-result-factory.d.ts +69 -0
  8. package/dist/cjs/fk-gather-result-factory.js +111 -0
  9. package/dist/cjs/fk-gather-result-factory.js.map +1 -0
  10. package/dist/cjs/fk-gather-result.d.ts +115 -0
  11. package/dist/cjs/fk-gather-result.js +127 -0
  12. package/dist/cjs/fk-gather-result.js.map +1 -0
  13. package/dist/cjs/fks.d.ts +111 -0
  14. package/dist/cjs/fks.js +101 -0
  15. package/dist/cjs/fks.js.map +1 -0
  16. package/dist/cjs/index.d.ts +10 -4
  17. package/dist/cjs/index.js +17 -1
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/kysely-rizzolver-builder.d.ts +17 -0
  20. package/dist/cjs/kysely-rizzolver-builder.js +23 -0
  21. package/dist/cjs/kysely-rizzolver-builder.js.map +1 -0
  22. package/dist/cjs/kysely-rizzolver-fk-builder.d.ts +20 -0
  23. package/dist/cjs/kysely-rizzolver-fk-builder.js +23 -0
  24. package/dist/cjs/kysely-rizzolver-fk-builder.js.map +1 -0
  25. package/dist/cjs/kysely-rizzolver.d.ts +64 -85
  26. package/dist/cjs/kysely-rizzolver.js +47 -90
  27. package/dist/cjs/kysely-rizzolver.js.map +1 -0
  28. package/dist/cjs/model-collection.d.ts +5 -1
  29. package/dist/cjs/model-collection.js +24 -2
  30. package/dist/cjs/model-collection.js.map +1 -0
  31. package/dist/cjs/query-builder.d.ts +14 -12
  32. package/dist/cjs/query-builder.js +10 -4
  33. package/dist/cjs/query-builder.js.map +1 -0
  34. package/dist/cjs/selector.d.ts +71 -7
  35. package/dist/cjs/selector.js +2 -1
  36. package/dist/cjs/selector.js.map +1 -0
  37. package/dist/cjs/type-helpers.d.ts +20 -0
  38. package/dist/cjs/type-helpers.js +1 -0
  39. package/dist/cjs/type-helpers.js.map +1 -0
  40. package/dist/esm/fetch-result-factory.js +1 -0
  41. package/dist/esm/fetch-result-factory.js.map +1 -0
  42. package/dist/esm/fetch-result.js +5 -0
  43. package/dist/esm/fetch-result.js.map +1 -0
  44. package/dist/esm/fk-gather-result-factory.js +108 -0
  45. package/dist/esm/fk-gather-result-factory.js.map +1 -0
  46. package/dist/esm/fk-gather-result.js +115 -0
  47. package/dist/esm/fk-gather-result.js.map +1 -0
  48. package/dist/esm/fks.js +96 -0
  49. package/dist/esm/fks.js.map +1 -0
  50. package/dist/esm/index.js +4 -1
  51. package/dist/esm/index.js.map +1 -0
  52. package/dist/esm/kysely-rizzolver-builder.js +20 -0
  53. package/dist/esm/kysely-rizzolver-builder.js.map +1 -0
  54. package/dist/esm/kysely-rizzolver-fk-builder.js +20 -0
  55. package/dist/esm/kysely-rizzolver-fk-builder.js.map +1 -0
  56. package/dist/esm/kysely-rizzolver.js +47 -90
  57. package/dist/esm/kysely-rizzolver.js.map +1 -0
  58. package/dist/esm/model-collection.js +24 -2
  59. package/dist/esm/model-collection.js.map +1 -0
  60. package/dist/esm/query-builder.js +10 -4
  61. package/dist/esm/query-builder.js.map +1 -0
  62. package/dist/esm/selector.js +2 -1
  63. package/dist/esm/selector.js.map +1 -0
  64. package/dist/esm/type-helpers.js +1 -0
  65. package/dist/esm/type-helpers.js.map +1 -0
  66. package/dist/types/fetch-result.d.ts +11 -8
  67. package/dist/types/fk-gather-result-factory.d.ts +69 -0
  68. package/dist/types/fk-gather-result.d.ts +115 -0
  69. package/dist/types/fks.d.ts +111 -0
  70. package/dist/types/index.d.ts +10 -4
  71. package/dist/types/kysely-rizzolver-builder.d.ts +17 -0
  72. package/dist/types/kysely-rizzolver-fk-builder.d.ts +20 -0
  73. package/dist/types/kysely-rizzolver.d.ts +64 -85
  74. package/dist/types/model-collection.d.ts +5 -1
  75. package/dist/types/query-builder.d.ts +14 -12
  76. package/dist/types/selector.d.ts +71 -7
  77. package/dist/types/type-helpers.d.ts +20 -0
  78. package/package.json +1 -1
package/README.md CHANGED
@@ -4,19 +4,21 @@ Complex Kysely queries, maximum rizz, type-safe every time.
4
4
 
5
5
  ## Overview
6
6
 
7
- Kysely Rizzolver is a utility library for building complex, type-safe queries.
7
+ Kysely Rizzolver is a utility library for building complex, type-safe queries
8
+ across multiple tables with Kysely.
8
9
 
9
- There are already a bunch of [awesome
10
- tools](https://github.com/kysely-org/awesome-kysely) for working with Kysely out
10
+ There are already a bunch of [awesome tools](https://github.com/kysely-org/awesome-kysely)
11
+ for working with Kysely out
11
12
  there, but none strike the balance I'm looking for:
12
- - [kysely-orm](https://github.com/seeeden/kysely-orm) is a full-fledged ORM.
13
- It's a really cool project, but like all ORMs it works until it doesn't. If
14
- you need fine control over your queries, it gets very cumbersome.
13
+ - [kysely-orm](https://github.com/seeden/kysely-orm) is a full-fledged ORM. It's
14
+ a really cool project, but like all ORMs it works until it doesn't. If you
15
+ need fine control over your queries, it gets very cumbersome.
15
16
  - [kysely-mapper](https://github.com/jtlapp/kysely-mapper) is a bit more
16
- lightweight than an ORM, but it still wraps Kysely with a "hatch" to an
17
- underlying Kysely instance. It is also quite verbose and rigid in my opinion.
17
+ lightweight than an ORM, but it's focus is still on mapping tables to other
18
+ classes. It doesn't offer much value in the way of writing complex queries, or
19
+ working with multiple tables.
18
20
 
19
- Kysely Rizzolver in constast, works *with* Kysely. It does not replace, wrap,
21
+ Kysely Rizzolver in constast, works *inside* Kysely. It does not replace, wrap,
20
22
  abstract or hide it and can be incrementally added to an existing Kysely
21
23
  project.
22
24
 
@@ -44,7 +46,9 @@ const rizzolver = KyselyRizzolver.builderNoSchema()
44
46
  .build();
45
47
  ```
46
48
 
47
- or if you have a schema, for example from [kysely-codegen](https://github.com/RobinBlomberg/kysely-codegen), you can use it like this:
49
+ or if you have a schema, for example from
50
+ [kysely-codegen](https://github.com/RobinBlomberg/kysely-codegen), you can use
51
+ it like this:
48
52
 
49
53
  ```typescript
50
54
  import { KyselyRizzolver } from 'kysely-rizzolver';
@@ -86,3 +86,4 @@ function newFetchResultFactory() {
86
86
  }
87
87
  };
88
88
  }
89
+ //# sourceMappingURL=fetch-result-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-result-factory.js","sourceRoot":"","sources":["../../src/fetch-result-factory.ts"],"names":[],"mappings":";;AAyBA,sDA8HC;AAtJD,uDAa2B;AAC3B,+DAAiF;AAUjF,SAAgB,qBAAqB;IACpC,OAAO;QACN;;WAEG;QACH,WAAW,CACV,KAAQ,EACR,MAAqC,EACrC,MAA4B;YAE5B,MAAM,KAAK,IAAA,wCAAkB,GAAM,CAAC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,IAAA,mCAAiB,EAA2B,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3E,CAAC;QAED;;;;;;WAMG;QACH,YAAY,CACX,KAAQ,EACR,MAAqC,EACrC,MAA4B;YAE5B,MAAM,KAAK,IAAA,wCAAkB,GAAM,CAAC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,IAAA,oCAAkB,EAA2B,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;QAED;;WAEG;QACH,YAAY,CACX,KAAQ,EACR,MAA2B,EAC3B,MAA4B;YAE5B,MAAM,KAAK,IAAA,wCAAkB,GAAM,CAAC;YACpC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,C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CAAC,yCAAyC,KAAK,EAAE,CAAC,CAAC;YACnE,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Selectable } from 'kysely';
2
- import type { ModelCollection } from './model-collection.js';
2
+ import { type ModelCollection } from './model-collection.js';
3
3
  /**
4
4
  * A {@link FetchResult} is a result of a fetch operation. It can be one of
5
5
  * three types:
@@ -10,16 +10,19 @@ import type { ModelCollection } from './model-collection.js';
10
10
  * - {@link FetchSomeResult} - A result of a fetch operation that is expected to
11
11
  * return any number of rows.
12
12
  */
13
- export type FetchResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>>> = FetchOneResult<DB, T, R> | FetchOneXResult<DB, T, R> | FetchSomeResult<DB, T, R>;
13
+ export type FetchResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>> = Selectable<DB[T]>> = FetchOneResult<DB, T, R> | FetchOneXResult<DB, T, R> | FetchSomeResult<DB, T, R>;
14
14
  /**
15
15
  * A {@link FetchOneResult} is a result of a fetch operation that is expected to
16
16
  * return up to one row.
17
17
  */
18
- export type FetchOneResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>> | undefined> = {
18
+ export type FetchOneResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>> = Selectable<DB[T]>> = {
19
19
  fetchType: 'fetchOne';
20
20
  table: T;
21
21
  result: R | undefined;
22
- models?: ModelCollection<DB>;
22
+ /**
23
+ * The {@link ModelCollection} that contains the fetched models.
24
+ */
25
+ models: ModelCollection<DB>;
23
26
  /**
24
27
  * Returns this result as a {@link FetchOneXResult}.
25
28
  *
@@ -31,11 +34,11 @@ export type FetchOneResult<DB, T extends keyof DB & string, R extends Partial<Se
31
34
  * A {@link FetchOneXResult} is a result of a fetch operation that is expected
32
35
  * to return exactly one row.
33
36
  */
34
- export type FetchOneXResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>>> = {
37
+ export type FetchOneXResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>> = Selectable<DB[T]>> = {
35
38
  fetchType: 'fetchOne';
36
39
  table: T;
37
40
  result: R;
38
- models?: ModelCollection<DB>;
41
+ models: ModelCollection<DB>;
39
42
  /**
40
43
  * Returns self. This is a no-op, but it's here to make it possible to
41
44
  * cast this object back to a {@link FetchOneXResult}.
@@ -46,11 +49,11 @@ export type FetchOneXResult<DB, T extends keyof DB & string, R extends Partial<S
46
49
  * A {@link FetchSomeResult} is a result of a fetch operation that is expected
47
50
  * to return any number of rows.
48
51
  */
49
- export type FetchSomeResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>>> = {
52
+ export type FetchSomeResult<DB, T extends keyof DB & string, R extends Partial<Selectable<DB[T]>> = Selectable<DB[T]>> = {
50
53
  fetchType: 'fetchSome';
51
54
  table: T;
52
55
  result: R[];
53
- models?: ModelCollection<DB>;
56
+ models: ModelCollection<DB>;
54
57
  };
55
58
  /**
56
59
  * Used to type juggle between {@link FetchResult} and its subtypes.
@@ -10,11 +10,13 @@ exports.isFetchSomeResult = isFetchSomeResult;
10
10
  exports.assertIsFetchOneResult = assertIsFetchOneResult;
11
11
  exports.assertIsFetchOneXResult = assertIsFetchOneXResult;
12
12
  exports.assertIsFetchSomeResult = assertIsFetchSomeResult;
13
+ const model_collection_js_1 = require("./model-collection.js");
13
14
  /**
14
15
  * Creates a new {@link FetchOneResult} instance.
15
16
  */
16
17
  function newFetchOneResult(table, result, models) {
17
18
  const ref = { value: null };
19
+ models ??= (0, model_collection_js_1.newModelCollection)();
18
20
  const me = {
19
21
  fetchType: 'fetchOne',
20
22
  table,
@@ -41,6 +43,7 @@ function newFetchOneXResult(table, result, models) {
41
43
  if (!result) {
42
44
  throw new Error('Expected a fetchOneX result');
43
45
  }
46
+ models ??= (0, model_collection_js_1.newModelCollection)();
44
47
  const ref = { value: null };
45
48
  const me = {
46
49
  fetchType: 'fetchOne',
@@ -58,6 +61,7 @@ function newFetchOneXResult(table, result, models) {
58
61
  * Creates a new {@link FetchSomeResult} instance.
59
62
  */
60
63
  function newFetchSomeResult(table, result, models) {
64
+ models ??= (0, model_collection_js_1.newModelCollection)();
61
65
  return {
62
66
  fetchType: 'fetchSome',
63
67
  table,
@@ -115,3 +119,4 @@ function assertIsFetchSomeResult(value) {
115
119
  throw new Error('Expected a fetchSome result');
116
120
  }
117
121
  }
122
+ //# sourceMappingURL=fetch-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-result.js","sourceRoot":"","sources":["../../src/fetch-result.ts"],"names":[],"mappings":";;AAmGA,8CA0BC;AASD,gDA0BC;AAKD,gDAaC;AAED,sCAeC;AAaD,4CAIC;AAkBD,8CASC;AAaD,8CAIC;AAKD,wDAMC;AAKD,0DAMC;AAKD,0DAMC;AAhSD,+DAAiF;AA+FjF;;GAEG;AACH,SAAgB,iBAAiB,CAI/B,KAAQ,EAAE,MAAqB,EAAE,MAA4B;IAC9D,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,IAAwC,EAAE,CAAC;IAEhE,MAAM,KAAK,IAAA,wCAAkB,GAAM,CAAC;IAEpC,MAAM,EAAE,GAA6B;QACpC,SAAS,EAAE,UAAmB;QAC9B,KAAK;QACL,MAAM;QACN,MAAM;QACN,WAAW;YACV,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YAChD,CAAC;YAED,OAAO,GAAG,CAAC,KAAK,CAAC;QAClB,CAAC;KACD,CAAC;IAEF,GAAG,CAAC,KAAK,GAAG,EAA+B,CAAC;IAE5C,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAIhC,KAAQ,EAAE,MAAqB,EAAE,MAA4B;IAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,KAAK,IAAA,w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AAC,IAAI,KAAK,CAAC,SAAS,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC/F,CAAC;AAkBD,SAAgB,iBAAiB,CAChC,KAAc;IAEd,OAAO,CACN,aAAa,CAAC,KAAK,CAAC;QACpB,KAAK,CAAC,SAAS,KAAK,UAAU;QAC9B,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;QAC5B,CAAC,CAAC,KAAK,CAAC,MAAM,CACd,CAAC;AACH,CAAC;AAaD,SAAgB,iBAAiB,CAChC,KAAc;IAEd,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,SAAS,KAAK,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC/F,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CACrC,KAAc;IAEd,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC/C,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CACtC,KAAc;IAEd,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACrF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CACtC,KAAc;IAEd,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;AACF,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { type FkGatherOneResult, type FkGatherOneXResult, type FkGatherSomeResult } from './fk-gather-result.js';
2
+ import type { DBWithFk, ModelFkExtractSelectable, ModelFkInstance, ValidFkDepth } from './fks.js';
3
+ import type { KyselyRizzolverFKs } from './kysely-rizzolver.js';
4
+ import { type ModelCollection } from './model-collection.js';
5
+ /**
6
+ * A {@link FkGatherResultFactory} exposes variants of gather-related functions, but
7
+ * with the `DB` type parameter already set.
8
+ *
9
+ * This makes it less verbose to work with gather results in a type-safe way.
10
+ */
11
+ export type FkGatherResultFactory<DB, FKDefs extends KyselyRizzolverFKs<DB>> = ReturnType<typeof newFkGatherResultFactory<DB, FKDefs>>;
12
+ export declare function newFkGatherResultFactory<DB, FKDefs extends KyselyRizzolverFKs<DB>>(): {
13
+ /**
14
+ * Creates a new {@link GatherOneResult} instance.
15
+ */
16
+ newGatherOne<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: ModelFkInstance<DBWithFk<DB, FKDefs>, K, Depth> | undefined, models?: ModelCollection<DB>): FkGatherOneResult<DBWithFk<DB, FKDefs>, K, Depth>;
17
+ /**
18
+ * Creates a new {@link GatherOneXResult} instance.
19
+ *
20
+ * Note: it may be counterintuitive, but this function accepts `undefined` as
21
+ * input. I found it is way more convenient to assert the type once in this
22
+ * funciton rather than in every caller.
23
+ */
24
+ newGatherOneX<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: ModelFkInstance<DBWithFk<DB, FKDefs>, K, Depth> | undefined, models?: ModelCollection<DB>): FkGatherOneXResult<DBWithFk<DB, FKDefs>, K, Depth>;
25
+ /**
26
+ * Creates a new {@link GatherSomeResult} instance.
27
+ */
28
+ newGatherSome<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: ModelFkInstance<DBWithFk<DB, FKDefs>, K, Depth>[], models?: ModelCollection<DB>): FkGatherSomeResult<DBWithFk<DB, FKDefs>, K, Depth>;
29
+ /**
30
+ * Checks if a {@link GatherResult} is a {@link GatherOneResult}.
31
+ */
32
+ isGatherOne<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): result is FkGatherOneResult<DBWithFk<DB, FKDefs>, K, Depth>;
33
+ /**
34
+ * Checks if a {@link GatherResult} is a {@link GatherOneXResult}.
35
+ */
36
+ isGatherOneX<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): result is FkGatherOneXResult<DBWithFk<DB, FKDefs>, K, Depth>;
37
+ /**
38
+ * Checks if a {@link GatherResult} is a {@link GatherSomeResult}.
39
+ */
40
+ isGatherSome<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): result is FkGatherSomeResult<DBWithFk<DB, FKDefs>, K, Depth>;
41
+ /**
42
+ * Asserts that a {@link GatherResult} is a {@link GatherOneResult}.
43
+ */
44
+ assertIsGatherOne<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): asserts result is FkGatherOneResult<DBWithFk<DB, FKDefs>, K, Depth>;
45
+ /**
46
+ * Asserts that a {@link GatherResult} is a {@link GatherOneXResult}.
47
+ */
48
+ assertIsGatherOneX<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): asserts result is FkGatherOneXResult<DBWithFk<DB, FKDefs>, K, Depth>;
49
+ /**
50
+ * Asserts that a {@link GatherResult} is a {@link GatherSomeResult}.
51
+ */
52
+ assertIsGatherSome<K extends (keyof DB & string) & string, Depth extends ValidFkDepth>(table: K, depth: Depth, result: unknown): asserts result is FkGatherSomeResult<DBWithFk<DB, FKDefs>, K, Depth>;
53
+ /**
54
+ * Extracts a Kysely {@link Selectable} instance from a gathered model.
55
+ *
56
+ * This is useful because Selectables are the lowest common denominators
57
+ * for any representation of a DB model, so this allows you to convert
58
+ * any gather result to anything else that might build upon Kysely.
59
+ *
60
+ * For example, to convert a gather result to a fetch result:
61
+ * ```
62
+ * const userGather: FkGatherOneXResult<DB, 'user'>;
63
+ * const userModel = userGather.result;
64
+ * const userSelectable = rizzolver.gatherObjs.toSelectable(userModel);
65
+ * ```
66
+ *
67
+ */
68
+ toSelectable<Model>(model: Model): ModelFkExtractSelectable<DB, Model>;
69
+ };
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newFkGatherResultFactory = newFkGatherResultFactory;
4
+ const fk_gather_result_js_1 = require("./fk-gather-result.js");
5
+ function newFkGatherResultFactory() {
6
+ return {
7
+ /**
8
+ * Creates a new {@link GatherOneResult} instance.
9
+ */
10
+ newGatherOne(table, depth, result, models) {
11
+ return (0, fk_gather_result_js_1.newGatherOneResult)(table, depth, result, models);
12
+ },
13
+ /**
14
+ * Creates a new {@link GatherOneXResult} instance.
15
+ *
16
+ * Note: it may be counterintuitive, but this function accepts `undefined` as
17
+ * input. I found it is way more convenient to assert the type once in this
18
+ * funciton rather than in every caller.
19
+ */
20
+ newGatherOneX(table, depth, result, models) {
21
+ return (0, fk_gather_result_js_1.newGatherOneXResult)(table, depth, result, models);
22
+ },
23
+ /**
24
+ * Creates a new {@link GatherSomeResult} instance.
25
+ */
26
+ newGatherSome(table, depth, result, models) {
27
+ return (0, fk_gather_result_js_1.newGatherSomeResult)(table, depth, result, models);
28
+ },
29
+ /**
30
+ * Checks if a {@link GatherResult} is a {@link GatherOneResult}.
31
+ */
32
+ isGatherOne(table, depth, result) {
33
+ return (0, fk_gather_result_js_1.isGatherOneResult)(result) && result.table === table && result.depth === depth;
34
+ },
35
+ /**
36
+ * Checks if a {@link GatherResult} is a {@link GatherOneXResult}.
37
+ */
38
+ isGatherOneX(table, depth, result) {
39
+ return (0, fk_gather_result_js_1.isGatherOneXResult)(result) && result.table === table && result.depth === depth;
40
+ },
41
+ /**
42
+ * Checks if a {@link GatherResult} is a {@link GatherSomeResult}.
43
+ */
44
+ isGatherSome(table, depth, result) {
45
+ return (0, fk_gather_result_js_1.isGatherSomeResult)(result) && result.table === table && result.depth === depth;
46
+ },
47
+ /**
48
+ * Asserts that a {@link GatherResult} is a {@link GatherOneResult}.
49
+ */
50
+ assertIsGatherOne(table, depth, result) {
51
+ (0, fk_gather_result_js_1.assertIsGatherOneResult)(result);
52
+ if (result.table !== table) {
53
+ throw new Error(`Expected a gatherOne result for table ${table}`);
54
+ }
55
+ if (result.depth !== depth) {
56
+ throw new Error(`Expected a gatherOne result for table ${table} of depth ${depth}`);
57
+ }
58
+ },
59
+ /**
60
+ * Asserts that a {@link GatherResult} is a {@link GatherOneXResult}.
61
+ */
62
+ assertIsGatherOneX(table, depth, result) {
63
+ (0, fk_gather_result_js_1.assertIsGatherOneXResult)(result);
64
+ if (result.table !== table) {
65
+ throw new Error(`Expected a gatherOne result with a non-null value for table ${table}`);
66
+ }
67
+ if (result.depth !== depth) {
68
+ throw new Error(`Expected a gatherOne result with a non-null value for table ${table} of depth ${depth}`);
69
+ }
70
+ },
71
+ /**
72
+ * Asserts that a {@link GatherResult} is a {@link GatherSomeResult}.
73
+ */
74
+ assertIsGatherSome(table, depth, result) {
75
+ (0, fk_gather_result_js_1.assertIsGatherSomeResult)(result);
76
+ if (result.table !== table) {
77
+ throw new Error(`Expected a gatherSome result for table ${table}`);
78
+ }
79
+ if (result.depth !== depth) {
80
+ throw new Error(`Expected a gatherSome result for table ${table} of depth ${depth}`);
81
+ }
82
+ },
83
+ /**
84
+ * Extracts a Kysely {@link Selectable} instance from a gathered model.
85
+ *
86
+ * This is useful because Selectables are the lowest common denominators
87
+ * for any representation of a DB model, so this allows you to convert
88
+ * any gather result to anything else that might build upon Kysely.
89
+ *
90
+ * For example, to convert a gather result to a fetch result:
91
+ * ```
92
+ * const userGather: FkGatherOneXResult<DB, 'user'>;
93
+ * const userModel = userGather.result;
94
+ * const userSelectable = rizzolver.gatherObjs.toSelectable(userModel);
95
+ * ```
96
+ *
97
+ */
98
+ toSelectable(model) {
99
+ if (model === undefined || model === null) {
100
+ return model;
101
+ }
102
+ const selectable = {
103
+ ...model
104
+ };
105
+ delete selectable['__fkDepth'];
106
+ delete selectable['__table'];
107
+ return selectable;
108
+ }
109
+ };
110
+ }
111
+ //# sourceMappingURL=fk-gather-result-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fk-gather-result-factory.js","sourceRoot":"","sources":["../../src/fk-gather-result-factory.ts"],"names":[],"mappings":";;AA6BA,4DAoLC;AAhND,+DAa+B;AAe/B,SAAgB,wBAAwB;IAGvC,OAAO;QACN;;WAEG;QACH,YAAY,CACX,KAAQ,EACR,KAAY,EACZ,MAAmD,EACnD,MAA4B;YAE5B,OAAO,IAAA,wCAAkB,EACxB,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAA8B,CAC9B,CAAC;QACH,CAAC;QAED;;;;;;WAMG;QACH,aAAa,CACZ,KAAQ,EACR,KAAY,EACZ,MAAmD,EACnD,MAA4B;YAE5B,OAAO,IAAA,yCAAmB,EACzB,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAA8B,CAC9B,CAAC;QACH,CAAC;QAED;;WAEG;QACH,aAAa,CACZ,KAAQ,EACR,KAAY,EACZ,MAAyC,EACzC,MAA4B;YAE5B,OAAO,IAAA,yCAAmB,EACzB,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAA8B,CAC9B,CAAC;QACH,CAAC;QAED;;WAEG;QACH,WAAW,CACV,KAAQ,EACR,KAAY,EACZ,MAAe;YAEf,OAAO,IAAA,uCAAiB,EAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC;QACtF,CAAC;QAED;;WAEG;QACH,YAAY,CACX,KAAQ,EACR,KAAY,EACZ,MAAe;YAEf,OAAO,IAAA,wCAAkB,EAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC;QACvF,CAAC;QAED;;WAEG;QACH,YAAY,CACX,KAAQ,EACR,KAAY,EACZ,MAAe;YAEf,OAAO,IAAA,wCAAkB,EAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,IAAI,MAAM,CAAC,KAAK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,YAAY,CAAQ,KAAY;YAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAC3C,OAAO,KAAY,CAAC;YACrB,CAAC;YAED,MAAM,UAAU,GAAG;gBAClB,GAAG,KAAK;aACR,CAAC;YACF,OAAQ,UAAkB,CAAC,WAAW,CAAC,CAAC;YACxC,OAAQ,UAAkB,CAAC,SAAS,CAAC,CAAC;YAEtC,OAAO,UAAiB,CAAC;QAC1B,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,115 @@
1
+ import type { DBWithoutFk, ModelFkInstance, ValidFkDepth } from './fks.js';
2
+ import { MAX_FK_GATHER_DEPTH } from './fks.js';
3
+ import type { ModelCollection } from './model-collection.js';
4
+ /**
5
+ * A {@link FkGatherResult} is a result of a gather operation. It can be one of
6
+ * three types:
7
+ * - {@link FkGatherOneResult} - A result of a gather operation that is expected to
8
+ * return up to one row,
9
+ * - {@link FkGatherOneXResult} - A result of a gather operation that is expected to
10
+ * return exactly one row,
11
+ * - {@link FkGatherSomeResult} - A result of a gather operation that is expected to
12
+ * return any number of rows.
13
+ */
14
+ export type FkGatherResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth = typeof MAX_FK_GATHER_DEPTH> = FkGatherOneResult<DBFk, Table, Depth> | FkGatherOneXResult<DBFk, Table, Depth> | FkGatherSomeResult<DBFk, Table, Depth>;
15
+ /**
16
+ * A {@link FkGatherOneResult} is a result of a gather operation that is expected to
17
+ * return up to one row.
18
+ */
19
+ export type FkGatherOneResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth = typeof MAX_FK_GATHER_DEPTH> = {
20
+ gatherType: 'gatherOne';
21
+ table: Table;
22
+ depth: Depth;
23
+ result: ModelFkInstance<DBFk, Table, Depth> | undefined;
24
+ models?: ModelCollection<DBWithoutFk<DBFk>>;
25
+ /**
26
+ * Returns this result as a {@link FkGatherOneXResult}.
27
+ *
28
+ * @throws If the result is null or undefined.
29
+ */
30
+ asGatherOneX(): FkGatherOneXResult<DBFk, Table, Depth>;
31
+ };
32
+ /**
33
+ * A {@link FkGatherOneXResult} is a result of a gather operation that is expected
34
+ * to return exactly one row.
35
+ */
36
+ export type FkGatherOneXResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth = typeof MAX_FK_GATHER_DEPTH> = {
37
+ gatherType: 'gatherOne';
38
+ table: Table;
39
+ depth: Depth;
40
+ result: ModelFkInstance<DBFk, Table, Depth>;
41
+ models?: ModelCollection<DBWithoutFk<DBFk>>;
42
+ /**
43
+ * Returns self. This is a no-op, but it's here to make it possible to
44
+ * cast this object back to a {@link FkGatherOneXResult}.
45
+ */
46
+ asGatherOneX(): FkGatherOneXResult<DBFk, Table, Depth>;
47
+ };
48
+ /**
49
+ * A {@link FkGatherSomeResult} is a result of a gather operation that is expected
50
+ * to return any number of rows.
51
+ */
52
+ export type FkGatherSomeResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth = typeof MAX_FK_GATHER_DEPTH> = {
53
+ gatherType: 'gatherSome';
54
+ table: Table;
55
+ depth: Depth;
56
+ result: ModelFkInstance<DBFk, Table, Depth>[];
57
+ models?: ModelCollection<DBWithoutFk<DBFk>>;
58
+ };
59
+ /**
60
+ * Used to type juggle between {@link FkGatherResult} and its subtypes.
61
+ */
62
+ export type AsGatherOneResult<T extends FkGatherResult<any, string, ValidFkDepth>> = T extends FkGatherResult<infer DBFk, infer Table, infer D> ? FkGatherOneResult<DBFk, Table, D> : never;
63
+ /**
64
+ * Used to type juggle between {@link FkGatherResult} and its subtypes.
65
+ */
66
+ export type AsGatherOneXResult<T extends FkGatherResult<any, string, ValidFkDepth>> = T extends FkGatherResult<infer DBFk, infer Table, infer D> ? FkGatherOneXResult<DBFk, Table, D> : never;
67
+ /**
68
+ * Used to type juggle between {@link FkGatherResult} and its subtypes.
69
+ */
70
+ export type AsGatherSomeResult<T extends FkGatherResult<any, string, ValidFkDepth>> = T extends FkGatherResult<infer DBFk, infer Table, infer D> ? FkGatherSomeResult<DBFk, Table, D> : never;
71
+ /**
72
+ * Creates a new {@link FkGatherOneResult} instance.
73
+ */
74
+ export declare function newGatherOneResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(table: Table, depth: Depth, result: ModelFkInstance<DBFk, Table, Depth> | undefined, models?: ModelCollection<DBWithoutFk<DBFk>>): FkGatherOneResult<DBFk, Table, Depth>;
75
+ /**
76
+ * Creates a new {@link FkGatherOneXResult} instance.
77
+ *
78
+ * Note: it may be counterintuitive, but this function accepts `undefined` as
79
+ * input. I found it is way more convenient to assert the type once in this
80
+ * funciton rather than in every caller.
81
+ */
82
+ export declare function newGatherOneXResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(table: Table, depth: Depth, result: ModelFkInstance<DBFk, Table, Depth> | undefined, models?: ModelCollection<DBWithoutFk<DBFk>>): FkGatherOneXResult<DBFk, Table, Depth>;
83
+ /**
84
+ * Creates a new {@link FkGatherSomeResult} instance.
85
+ */
86
+ export declare function newGatherSomeResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(table: Table, depth: Depth, result: ModelFkInstance<DBFk, Table, Depth>[], models?: ModelCollection<DBWithoutFk<DBFk>>): FkGatherSomeResult<DBFk, Table, Depth>;
87
+ export declare function isGatherResult(result: unknown): result is FkGatherResult<any, any, ValidFkDepth>;
88
+ /**
89
+ * Checks if `value` is a {@link FkGatherOneResult}.
90
+ */
91
+ export declare function isGatherOneResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(value: FkGatherOneResult<DBFk, Table, Depth> | FkGatherOneXResult<DBFk, Table, Depth>): value is typeof value;
92
+ export declare function isGatherOneResult(value: unknown): value is FkGatherOneResult<any, any, ValidFkDepth>;
93
+ /**
94
+ * Checks if `value` is a {@link FkGatherOneXResult}.
95
+ */
96
+ export declare function isGatherOneXResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(value: FkGatherOneResult<DBFk, Table, Depth>): value is FkGatherOneXResult<DBFk, Table, Depth>;
97
+ export declare function isGatherOneXResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(value: FkGatherOneXResult<DBFk, Table, Depth>): value is typeof value;
98
+ export declare function isGatherOneXResult(value: unknown): value is FkGatherOneXResult<any, any, ValidFkDepth>;
99
+ /**
100
+ * Checks if `value` is a {@link FkGatherSomeResult}.
101
+ */
102
+ export declare function isGatherSomeResult<DBFk, Table extends keyof DBFk & string, Depth extends ValidFkDepth>(value: FkGatherSomeResult<DBFk, Table, Depth>): value is typeof value;
103
+ export declare function isGatherSomeResult(value: unknown): value is FkGatherSomeResult<any, any, ValidFkDepth>;
104
+ /**
105
+ * Asserts that `value` is a {@link FkGatherOneResult}.
106
+ */
107
+ export declare function assertIsGatherOneResult(value: unknown): asserts value is FkGatherOneResult<any, any, ValidFkDepth>;
108
+ /**
109
+ * Asserts that `value` is a {@link FkGatherOneXResult}.
110
+ */
111
+ export declare function assertIsGatherOneXResult(value: unknown): asserts value is FkGatherOneXResult<any, any, ValidFkDepth>;
112
+ /**
113
+ * Asserts that `value` is a {@link FkGatherSomeResult}.
114
+ */
115
+ export declare function assertIsGatherSomeResult(value: unknown): asserts value is FkGatherSomeResult<any, any, ValidFkDepth>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newGatherOneResult = newGatherOneResult;
4
+ exports.newGatherOneXResult = newGatherOneXResult;
5
+ exports.newGatherSomeResult = newGatherSomeResult;
6
+ exports.isGatherResult = isGatherResult;
7
+ exports.isGatherOneResult = isGatherOneResult;
8
+ exports.isGatherOneXResult = isGatherOneXResult;
9
+ exports.isGatherSomeResult = isGatherSomeResult;
10
+ exports.assertIsGatherOneResult = assertIsGatherOneResult;
11
+ exports.assertIsGatherOneXResult = assertIsGatherOneXResult;
12
+ exports.assertIsGatherSomeResult = assertIsGatherSomeResult;
13
+ const fks_js_1 = require("./fks.js");
14
+ /**
15
+ * Creates a new {@link FkGatherOneResult} instance.
16
+ */
17
+ function newGatherOneResult(table, depth, result, models) {
18
+ const ref = { value: null };
19
+ const me = {
20
+ gatherType: 'gatherOne',
21
+ table,
22
+ depth,
23
+ result,
24
+ models,
25
+ asGatherOneX() {
26
+ if (!me.result) {
27
+ throw new Error('Expected a gatherOneX result');
28
+ }
29
+ return ref.value;
30
+ }
31
+ };
32
+ ref.value = me;
33
+ return me;
34
+ }
35
+ /**
36
+ * Creates a new {@link FkGatherOneXResult} instance.
37
+ *
38
+ * Note: it may be counterintuitive, but this function accepts `undefined` as
39
+ * input. I found it is way more convenient to assert the type once in this
40
+ * funciton rather than in every caller.
41
+ */
42
+ function newGatherOneXResult(table, depth, result, models) {
43
+ if (!result) {
44
+ throw new Error('Expected a gatherOneX result');
45
+ }
46
+ const ref = { value: null };
47
+ const me = {
48
+ gatherType: 'gatherOne',
49
+ table,
50
+ depth,
51
+ result,
52
+ models,
53
+ asGatherOneX() {
54
+ return ref.value;
55
+ }
56
+ };
57
+ ref.value = me;
58
+ return me;
59
+ }
60
+ /**
61
+ * Creates a new {@link FkGatherSomeResult} instance.
62
+ */
63
+ function newGatherSomeResult(table, depth, result, models) {
64
+ return {
65
+ gatherType: 'gatherSome',
66
+ table,
67
+ depth,
68
+ result,
69
+ models
70
+ };
71
+ }
72
+ function isGatherResult(result) {
73
+ return (!!result &&
74
+ typeof result === 'object' &&
75
+ 'gatherType' in result &&
76
+ !!result.gatherType &&
77
+ typeof result.gatherType === 'string' &&
78
+ 'table' in result &&
79
+ !!result.table &&
80
+ typeof result.table === 'string' &&
81
+ 'depth' in result &&
82
+ typeof result.depth === 'number' &&
83
+ Number.isInteger(result.depth) &&
84
+ result.depth >= 0 &&
85
+ result.depth <= fks_js_1.MAX_FK_GATHER_DEPTH &&
86
+ 'result' in result &&
87
+ (result.result === undefined ||
88
+ typeof result.result === 'object' ||
89
+ (Array.isArray(result.result) && result.result.every((r) => !!r && typeof r === 'object'))));
90
+ }
91
+ function isGatherOneResult(value) {
92
+ return isGatherResult(value) && value.gatherType === 'gatherOne' && !Array.isArray(value.result);
93
+ }
94
+ function isGatherOneXResult(value) {
95
+ return (isGatherResult(value) &&
96
+ value.gatherType === 'gatherOne' &&
97
+ !Array.isArray(value.result) &&
98
+ !!value.result);
99
+ }
100
+ function isGatherSomeResult(value) {
101
+ return isGatherResult(value) && value.gatherType === 'gatherSome' && Array.isArray(value.result);
102
+ }
103
+ /**
104
+ * Asserts that `value` is a {@link FkGatherOneResult}.
105
+ */
106
+ function assertIsGatherOneResult(value) {
107
+ if (!isGatherOneResult(value)) {
108
+ throw new Error('Expected a gatherOne result');
109
+ }
110
+ }
111
+ /**
112
+ * Asserts that `value` is a {@link FkGatherOneXResult}.
113
+ */
114
+ function assertIsGatherOneXResult(value) {
115
+ if (!isGatherOneXResult(value)) {
116
+ throw new Error('Expected a gatherOne result with a non-null, non undefined result');
117
+ }
118
+ }
119
+ /**
120
+ * Asserts that `value` is a {@link FkGatherSomeResult}.
121
+ */
122
+ function assertIsGatherSomeResult(value) {
123
+ if (!isGatherSomeResult(value)) {
124
+ throw new Error('Expected a gatherSome result');
125
+ }
126
+ }
127
+ //# sourceMappingURL=fk-gather-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fk-gather-result.js","sourceRoot":"","sources":["../../src/fk-gather-result.ts"],"names":[],"mappings":";;AA6GA,gDA8BC;AASD,kDA8BC;AAKD,kDAiBC;AAED,wCAoBC;AAeD,8CAIC;AAkBD,gDASC;AAaD,gDAIC;AAKD,0DAMC;AAKD,4DAMC;AAKD,4DAMC;AA7TD,qCAA+C;AAyG/C;;GAEG;AACH,SAAgB,kBAAkB,CAKjC,KAAY,EACZ,KAAY,EACZ,MAAuD,EACvD,MAA2C;IAE3C,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,IAAqD,EAAE,CAAC;IAE7E,MAAM,EAAE,GAA0C;QACjD,UAAU,EAAE,WAAoB;QAChC,KAAK;QACL,KAAK;Q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