@shivaedev/effect-prisma 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 - 2026-07-26
6
+
7
+ ### Added
8
+
9
+ - Load typed to-one and to-many relations, including nested and refined
10
+ relations and relation counts.
11
+ - Count any filtered relation directly without building an aggregate result.
12
+
5
13
  ## 0.1.0 - 2026-07-26
6
14
 
7
15
  ### Added
package/README.md CHANGED
@@ -46,24 +46,54 @@ const program = Effect.gen(function* () {
46
46
  const users = yield* newest.take(20)
47
47
  const first = yield* active.first()
48
48
  const exists = yield* active.exists()
49
+ const count = yield* active.count()
49
50
 
50
- return { users, first, exists }
51
+ return { users, first, exists, count }
51
52
  })
52
53
  ```
53
54
 
54
55
  Relations are lazy and immutable. Reusing or branching a Relation never changes
55
56
  the original, and each execution resolves the active database context again.
56
57
 
58
+ Relations can be loaded directly or refined with another immutable Relation:
59
+
60
+ ```ts
61
+ const recentPosts = db.Post
62
+ .orderBy((post) => post.createdAt.desc())
63
+ .take(5)
64
+
65
+ const usersWithPosts = yield* db.User.include("posts", recentPosts)
66
+
67
+ const usersWithPostCounts = yield* db.User.include("posts", db.Post.count())
68
+ ```
69
+
70
+ Includes can be chained and nested. Loaded to-many relations are arrays, and
71
+ nullable to-one relations remain nullable in the result type.
72
+
73
+ Named query records return several projections of the same relation:
74
+
75
+ ```ts
76
+ const publishedPosts = db.Post.where({ published: true })
77
+ const recentPublishedPosts = publishedPosts
78
+ .orderBy((post) => post.createdAt.desc())
79
+ .take(5)
80
+
81
+ const usersWithPostOverview = yield* db.User.include("posts", {
82
+ items: recentPublishedPosts,
83
+ fullCount: publishedPosts.count(),
84
+ })
85
+ ```
86
+
57
87
  Collections are also cold Effect Streams:
58
88
 
59
89
  ```ts
60
90
  const stream = db.User.where({ active: true }).stream
61
91
  ```
62
92
 
63
- The initial package covers scalar models, filtering, selection, ordering,
64
- pagination, distinct queries, aggregates, grouping, and create/update/delete
65
- terminals. Relation includes and model variants are deliberately deferred
66
- rather than exposed with weakened types.
93
+ The package covers scalar models, filtering, selection, relation loading,
94
+ ordering, pagination, distinct queries, aggregates, grouping, and
95
+ create/update/delete terminals. Model variants are deliberately deferred rather
96
+ than exposed with weakened types.
67
97
 
68
98
  ## Transactions
69
99
 
@@ -1 +1 @@
1
- {"version":3,"file":"recipe.d.ts","sourceRoot":"","sources":["../../src/internal/recipe.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,cAA6B,CAAC;AAEzE,eAAO,MAAM,eAAe,GAC3B,QAAQ,cAAc,EACtB,MAAM,WAAW,EACjB,YAAY,aAAa,CAAC,OAAO,CAAC,KAChC,cAOD,CAAC;AAkBH,eAAO,MAAM,YAAY,GACxB,QAAQ,MAAM,EACd,QAAQ,cAAc,KACpB,OAyBF,CAAC"}
1
+ {"version":3,"file":"recipe.d.ts","sourceRoot":"","sources":["../../src/internal/recipe.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,cAA6B,CAAC;AAEzE,eAAO,MAAM,eAAe,GAC3B,QAAQ,cAAc,EACtB,MAAM,WAAW,EACjB,YAAY,aAAa,CAAC,OAAO,CAAC,KAChC,cAOD,CAAC;AA8GH,eAAO,MAAM,YAAY,GACxB,QAAQ,MAAM,EACd,QAAQ,cAAc,KACpB,OAQF,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { getRelationPlan } from "./relation-plan.js";
1
2
  export const rootRecipe = (model) => ({ model });
2
3
  export const appendOperation = (parent, name, arguments_) => ({
3
4
  model: parent.model,
@@ -18,20 +19,74 @@ const operations = (recipe) => {
18
19
  }
19
20
  return reversed.reverse();
20
21
  };
21
- export const replayRecipe = (models, recipe) => {
22
- let current = Reflect.get(models, recipe.model);
23
- if (current === undefined) {
24
- throw new TypeError(`Unknown Prisma model: ${recipe.model}`);
22
+ const applyMethod = (current, name, arguments_, model) => {
23
+ if (typeof current !== "object" ||
24
+ current === null ||
25
+ typeof Reflect.get(current, name) !== "function") {
26
+ throw new TypeError(`Cannot call ${String(name)} while replaying ${model}`);
25
27
  }
26
- for (const operation of operations(recipe)) {
27
- if (typeof current !== "object" ||
28
- current === null ||
29
- typeof Reflect.get(current, operation.name) !== "function") {
30
- throw new TypeError(`Cannot call ${String(operation.name)} while replaying ${recipe.model}`);
28
+ const method = Reflect.get(current, name);
29
+ return Reflect.apply(method, current, arguments_);
30
+ };
31
+ const replayPlan = (collection, plan) => {
32
+ const relatedModel = typeof collection === "object" && collection !== null
33
+ ? Reflect.get(collection, "modelName")
34
+ : undefined;
35
+ if (typeof relatedModel === "string" && relatedModel !== plan.recipe.model) {
36
+ throw new TypeError(`Included relation expects ${relatedModel}, received ${plan.recipe.model}`);
37
+ }
38
+ const refined = replayRecipeFrom(collection, plan.recipe);
39
+ if (plan.terminal !== "count") {
40
+ return refined;
41
+ }
42
+ return applyMethod(refined, "count", [], plan.recipe.model);
43
+ };
44
+ const includeRefinement = (value) => {
45
+ const plan = getRelationPlan(value);
46
+ if (plan !== undefined) {
47
+ return (collection) => replayPlan(collection, plan);
48
+ }
49
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
50
+ throw new TypeError("An included relation must be a Relation or query record");
51
+ }
52
+ const entries = Object.entries(value);
53
+ if (entries.length === 0) {
54
+ throw new TypeError("An included query record cannot be empty");
55
+ }
56
+ const plans = entries.map(([name, query]) => {
57
+ const queryPlan = getRelationPlan(query);
58
+ if (queryPlan === undefined) {
59
+ throw new TypeError(`Included query "${name}" is not a Relation`);
31
60
  }
32
- const method = Reflect.get(current, operation.name);
33
- current = Reflect.apply(method, current, operation.arguments);
61
+ return [name, queryPlan];
62
+ });
63
+ const model = plans[0]?.[1].recipe.model;
64
+ if (plans.some(([, queryPlan]) => queryPlan.recipe.model !== model)) {
65
+ throw new TypeError("Included queries must use the same related model");
66
+ }
67
+ return (collection) => {
68
+ const branches = Object.fromEntries(plans.map(([name, queryPlan]) => [
69
+ name,
70
+ replayPlan(collection, queryPlan),
71
+ ]));
72
+ return applyMethod(collection, "combine", [branches], model ?? "relation");
73
+ };
74
+ };
75
+ const replayRecipeFrom = (root, recipe) => {
76
+ let current = root;
77
+ for (const operation of operations(recipe)) {
78
+ const arguments_ = operation.name === "include" && operation.arguments.length === 2
79
+ ? [operation.arguments[0], includeRefinement(operation.arguments[1])]
80
+ : operation.arguments;
81
+ current = applyMethod(current, operation.name, arguments_, recipe.model);
34
82
  }
35
83
  return current;
36
84
  };
85
+ export const replayRecipe = (models, recipe) => {
86
+ const current = Reflect.get(models, recipe.model);
87
+ if (current === undefined) {
88
+ throw new TypeError(`Unknown Prisma model: ${recipe.model}`);
89
+ }
90
+ return replayRecipeFrom(current, recipe);
91
+ };
37
92
  //# sourceMappingURL=recipe.js.map
@@ -1 +1 @@
1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C,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAE3D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,SAAS,CAAC,yBAAyB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { RelationRecipe } from "./recipe.js";
2
+ export declare const RelationPlanTypeId: unique symbol;
3
+ export interface RelationPlan {
4
+ readonly recipe: RelationRecipe;
5
+ readonly terminal?: PropertyKey;
6
+ }
7
+ export declare const getRelationPlan: (value: unknown) => RelationPlan | undefined;
8
+ //# sourceMappingURL=relation-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation-plan.d.ts","sourceRoot":"","sources":["../../src/internal/relation-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,kBAAkB,eAE9B,CAAC;AAEF,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;CAChC;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,YAAY,GAAG,SAU/D,CAAC"}
@@ -0,0 +1,10 @@
1
+ export const RelationPlanTypeId = Symbol.for("@shivaedev/effect-prisma/RelationPlan");
2
+ export const getRelationPlan = (value) => {
3
+ if (typeof value !== "object" ||
4
+ value === null ||
5
+ !Reflect.has(value, RelationPlanTypeId)) {
6
+ return undefined;
7
+ }
8
+ return Reflect.get(value, RelationPlanTypeId);
9
+ };
10
+ //# sourceMappingURL=relation-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation-plan.js","sourceRoot":"","sources":["../../src/internal/relation-plan.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAC3C,uCAAuC,CACvC,CAAC;AAOF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAA4B,EAAE;IAC3E,IACC,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,EACtC,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAiB,CAAC;AAC/D,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"relation-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/relation-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACX,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,eAAe,CAAC;AAkMvB,eAAO,MAAM,iBAAiB,GAC7B,UAAU,EACV,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB,EAE1D,UAAU,OAAO,CAAC,OAAO,CACxB,kBAAkB,CAAC,MAAM,CAAC,EAC1B,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC,EACD,OAAO,MAAM,KACX,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAIK,CAAC"}
1
+ {"version":3,"file":"relation-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/relation-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACX,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,eAAe,CAAC;AAkOvB,eAAO,MAAM,iBAAiB,GAC7B,UAAU,EACV,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB,EAE1D,UAAU,OAAO,CAAC,OAAO,CACxB,kBAAkB,CAAC,MAAM,CAAC,EAC1B,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC,EACD,OAAO,MAAM,KACX,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAIK,CAAC"}
@@ -2,7 +2,15 @@ import { Effect, Effectable, Option, Stream } from "effect";
2
2
  import { isPrismaFailure, toPrismaError } from "../error.js";
3
3
  import { fromPrismaPromise } from "./promise.js";
4
4
  import { appendOperation, replayRecipe, rootRecipe, } from "./recipe.js";
5
+ import { RelationPlanTypeId } from "./relation-plan.js";
5
6
  const evaluateResult = (value, terminal) => {
7
+ if (terminal === "count" &&
8
+ typeof value === "object" &&
9
+ value !== null &&
10
+ typeof Reflect.get(value, "aggregate") === "function") {
11
+ const aggregate = Reflect.apply(Reflect.get(value, "aggregate"), value, [(summary) => ({ count: summary.count() })]);
12
+ return fromPrismaPromise(() => aggregate).pipe(Effect.map((result) => result.count));
13
+ }
6
14
  if (terminal === "exists" &&
7
15
  typeof value === "object" &&
8
16
  value !== null &&
@@ -57,6 +65,10 @@ const RelationPrototype = {
57
65
  };
58
66
  const makeRelationProxy = (runtime) => {
59
67
  const target = Object.assign(Object.create(RelationPrototype), {
68
+ [RelationPlanTypeId]: {
69
+ recipe: runtime.recipe,
70
+ ...(runtime.terminal === undefined ? {} : { terminal: runtime.terminal }),
71
+ },
60
72
  runtime,
61
73
  });
62
74
  return new Proxy(target, {
@@ -73,6 +85,12 @@ const makeRelationProxy = (runtime) => {
73
85
  terminal: "exists",
74
86
  });
75
87
  }
88
+ if (property === "count") {
89
+ return () => makeRelationProxy({
90
+ ...runtime,
91
+ terminal: "count",
92
+ });
93
+ }
76
94
  return (...arguments_) => makeRelationProxy({
77
95
  ...runtime,
78
96
  recipe: appendOperation(runtime.recipe, property, arguments_),
@@ -1 +1 @@
1
- {"version":3,"file":"relation-runtime.js","sourceRoot":"","sources":["../../src/internal/relation-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAoB,aAAa,EAAE,MAAM,aAAa,CAAC;AAO/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACN,eAAe,EAEf,YAAY,EACZ,UAAU,GACV,MAAM,aAAa,CAAC;AAgBrB,MAAM,cAAc,GAAG,CACtB,KAAc,EACd,QAAiC,EACK,EAAE;IACxC,IACC,QAAQ,KAAK,QAAQ;QACrB,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,UAAU,EAChD,CAAC;QACF,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAgB,EAC1C,KAAK,EACL,EAAE,CACF,CAAC;QACF,OAAO,iBAAiB,CAAC,GAAG,EAAE,CAAC,KAA6B,CAAC,CAAC,IAAI,CACjE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CACvC,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GACf,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,UAAU;QAC9C,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAgB,EAAE,KA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CAAC,CAAC;YAC9C,CAAC;YACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAC3B,OAAO,GAAG,EAAE,CACX,iBAAiB,CAAC;oBACjB,GAAG,OAAO;oBACV,QAAQ,EAAE,QAAQ;iBAClB,CAAC,CAAC;YACL,CAAC;YACD,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC1B,OAAO,GAAG,EAAE,CACX,iBAAiB,CAAC;oBACjB,GAAG,OAAO;oBACV,QAAQ,EAAE,OAAO;iBACjB,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,GAAG,UAAkC,EAAE,EAAE,CAChD,iBAAiB,CAAC;gBACjB,GAAG,OAAO;gBACV,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC;gBAC7D,QAAQ,EAAE,QAAQ;aAClB,CAAC,CAAC;QACL,CAAC;KACD,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAKhC,QAGC,EACD,KAAa,EACsC,EAAE,CACrD,iBAAiB,CAAC;IACjB,QAAQ;IACR,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC;CACzB,CAAqD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { Contract as PrismaContract } from "@prisma-next/contract/types";
2
+ import type { SqlStorage } from "@prisma-next/sql-contract/types";
3
+ import type { RelationsOf } from "@prisma-next/sql-orm-client";
4
+ export type AnyPostgresContract = PrismaContract<SqlStorage>;
5
+ type RelationDefinition<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = RelationName extends keyof RelationsOf<Contract, Model> ? RelationsOf<Contract, Model>[RelationName] : never;
6
+ type RelationCardinalityOf<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = RelationDefinition<Contract, Model, RelationName> extends {
7
+ readonly cardinality: infer Cardinality extends string;
8
+ } ? Cardinality : never;
9
+ export type IsToManyRelation<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M" ? true : false;
10
+ export type RelatedModelNameOf<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = RelationDefinition<Contract, Model, RelationName> extends {
11
+ readonly to: {
12
+ readonly model: infer Related extends string;
13
+ };
14
+ } ? Related : never;
15
+ type RelationLocalFields<Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = RelationDefinition<Contract, Model, RelationName> extends {
16
+ readonly on: {
17
+ readonly localFields: infer Fields extends readonly string[];
18
+ };
19
+ } ? Fields : readonly [];
20
+ type DefaultNamespace<Contract extends AnyPostgresContract> = Contract["domain"]["namespaces"][keyof Contract["domain"]["namespaces"]];
21
+ type ModelFields<Contract extends AnyPostgresContract, Model extends string> = DefaultNamespace<Contract> extends {
22
+ readonly models: infer Models;
23
+ } ? Model extends keyof Models ? Models[Model] extends {
24
+ readonly fields: infer Fields;
25
+ } ? Fields : never : never : never;
26
+ type AnyNullableField<Fields, Names extends readonly string[]> = Names extends readonly [
27
+ infer Head extends string,
28
+ ...infer Tail extends readonly string[]
29
+ ] ? Head extends keyof Fields ? Fields[Head] extends {
30
+ readonly nullable: true;
31
+ } ? true : AnyNullableField<Fields, Tail> : true : false;
32
+ export type IncludedRelationValue<Contract extends AnyPostgresContract, Model extends string, RelationName extends string, Value> = RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M" ? Array<Value> : RelationCardinalityOf<Contract, Model, RelationName> extends "N:1" ? AnyNullableField<ModelFields<Contract, Model>, RelationLocalFields<Contract, Model, RelationName>> extends true ? Value | null : Value : Value | null;
33
+ export {};
34
+ //# sourceMappingURL=include-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include-metadata.d.ts","sourceRoot":"","sources":["../../src/relation/include-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EA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,YAAY,SAAS,MAAM,EAC3B,KAAK,IAEL,qBAAqB,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,SAAS,KAAK,GAAG,KAAK,GACvE,KAAK,CAAC,KAAK,CAAC,GACZ,qBAAqB,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,SAAS,KAAK,GACjE,gBAAgB,CAChB,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,EAC5B,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAClD,SAAS,IAAI,GACZ,KAAK,GAAG,IAAI,GACZ,KAAK,GACN,KAAK,GAAG,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=include-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include-metadata.js","sourceRoot":"","sources":["../../src/relation/include-metadata.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import type { DefaultModelRow, Collection as PrismaCollection, RelationNames } from "@prisma-next/sql-orm-client";
2
+ import type { Relation, RelationQuery } from "../relation.js";
3
+ import type { AnyPostgresContract, IncludedRelationValue, IsToManyRelation, RelatedModelNameOf } from "./include-metadata.js";
4
+ type Simplify<Value> = {
5
+ [Key in keyof Value]: Value[Key];
6
+ };
7
+ type QueryValue<Query> = Query extends RelationQuery<infer Value, infer _Requirement, infer _Contract, infer _Model> ? Value : never;
8
+ type AcceptRelatedQuery<Query, Contract extends AnyPostgresContract, Model extends string> = Query extends RelationQuery<infer _Value, infer _Requirement, infer QueryContract, infer QueryModel> ? [QueryContract] extends [Contract] ? [Contract] extends [QueryContract] ? QueryModel extends Model ? unknown : never : never : never : never;
9
+ type IncludedQueryValue<Query, Contract extends AnyPostgresContract, Model extends string, RelationName extends string> = QueryValue<Query> extends ReadonlyArray<infer Row> ? IncludedRelationValue<Contract, Model, RelationName, Row> : QueryValue<Query>;
10
+ type QueryShapeValue<Shape extends Readonly<Record<string, unknown>>> = {
11
+ readonly [Key in keyof Shape]: QueryValue<Shape[Key]>;
12
+ };
13
+ type AcceptRelatedQueryShape<Shape extends Readonly<Record<string, unknown>>, Contract extends AnyPostgresContract, Model extends string> = {
14
+ readonly [Key in keyof Shape]: Shape[Key] & AcceptRelatedQuery<Shape[Key], Contract, Model>;
15
+ };
16
+ type WithIncludedRelation<Collection, Contract extends AnyPostgresContract, Model extends string, RelationName extends string, Value> = Collection extends PrismaCollection<Contract, Model, infer Row, infer State> ? PrismaCollection<Contract, Model, Simplify<Row & {
17
+ readonly [Key in RelationName]: Value;
18
+ }>, State> : never;
19
+ export type IncludeMethod<Collection, Requirement, Contract, Model extends string> = Contract extends AnyPostgresContract ? Collection extends PrismaCollection<Contract, Model, infer _Row, infer _State> ? {
20
+ include<RelationName extends RelationNames<Contract, Model>>(relationName: RelationName): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, IncludedRelationValue<Contract, Model, RelationName, DefaultModelRow<Contract, RelatedModelNameOf<Contract, Model, RelationName>>>>, Requirement, Contract, Model>;
21
+ include<RelationName extends RelationNames<Contract, Model>, Query>(relationName: RelationName, query: Query & AcceptRelatedQuery<Query, Contract, RelatedModelNameOf<Contract, Model, RelationName>>): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, IncludedQueryValue<Query, Contract, Model, RelationName>>, Requirement, Contract, Model>;
22
+ include<RelationName extends RelationNames<Contract, Model>, Shape extends Readonly<Record<string, unknown>>>(relationName: RelationName, shape: IsToManyRelation<Contract, Model, RelationName> extends true ? keyof Shape extends never ? never : Shape & AcceptRelatedQueryShape<Shape, Contract, RelatedModelNameOf<Contract, Model, RelationName>> : never): Relation<WithIncludedRelation<Collection, Contract, Model, RelationName, QueryShapeValue<Shape>>, Requirement, Contract, Model>;
23
+ } : Record<never, never> : Record<never, never>;
24
+ export {};
25
+ //# sourceMappingURL=include.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../../src/relation/include.ts"],"names":[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K,EAAE,KAAK,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=include.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include.js","sourceRoot":"","sources":["../../src/relation/include.ts"],"names":[],"mappings":""}
@@ -3,7 +3,8 @@ import type { SqlStorage } from "@prisma-next/sql-contract/types";
3
3
  import type { AggregateBuilder, AggregateResult, AggregateSpec, DefaultModelRow, GroupedCollection, Collection as PrismaCollection } from "@prisma-next/sql-orm-client";
4
4
  import type { Effect, Stream } from "effect";
5
5
  import type { PrismaError } from "../error.js";
6
- import type { CollectionResult, Relation } from "../relation.js";
6
+ import type { CollectionResult, Relation, RelationQuery } from "../relation.js";
7
+ import type { IncludeMethod } from "./include.js";
7
8
  type AnyFunction = (...arguments_: ReadonlyArray<never>) => unknown;
8
9
  type AnyPostgresContract = PrismaContract<SqlStorage>;
9
10
  type FieldTuple<Row> = readonly [keyof Row & string, ...(keyof Row & string)[]];
@@ -43,11 +44,13 @@ type CollectionMethods<Collection, Requirement, Contract, Model extends string>
43
44
  } : Record<never, never>) : Record<never, never> : Record<never, never>;
44
45
  type CollectionConveniences<Collection, Requirement, Contract, Model extends string> = Contract extends AnyPostgresContract ? Collection extends PrismaCollection<Contract, Model, infer Row, infer _State> ? {
45
46
  readonly stream: Stream.Stream<Row, PrismaError, Requirement>;
47
+ count(): RelationQuery<number, Requirement, Contract, Model>;
46
48
  exists(): Effect.Effect<boolean, PrismaError, Requirement>;
47
49
  } : Record<never, never> : CollectionResult<Collection> extends ReadonlyArray<infer Row> ? {
48
50
  readonly stream: Stream.Stream<Row, PrismaError, Requirement>;
51
+ count(): Effect.Effect<number, PrismaError, Requirement>;
49
52
  exists(): Effect.Effect<boolean, PrismaError, Requirement>;
50
53
  } : Record<never, never>;
51
- export type PrismaRelationMethods<Collection, Requirement, Contract, Model extends string> = SelectMethod<Collection, Requirement, Contract, Model> & AggregateMethod<Collection, Requirement, Contract, Model> & CollectionMethods<Collection, Requirement, Contract, Model> & CollectionConveniences<Collection, Requirement, Contract, Model>;
54
+ export type PrismaRelationMethods<Collection, Requirement, Contract, Model extends string> = SelectMethod<Collection, Requirement, Contract, Model> & IncludeMethod<Collection, Requirement, Contract, Model> & AggregateMethod<Collection, Requirement, Contract, Model> & CollectionMethods<Collection, Requirement, Contract, Model> & CollectionConveniences<Collection, Requirement, Contract, Model>;
52
55
  export {};
53
56
  //# sourceMappingURL=prisma-methods.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-methods.d.ts","sourceRoot":"","sources":["../../src/relation/prisma-methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACX,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,UAAU,IAAI,gBAAgB,EAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjE,KAAK,WAAW,GAAG,CAAC,GAAG,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;AACpE,KAAK,mBAAmB,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AACtD,KAAK,UAAU,CAAC,GAAG,IAAI,SAAS,CAAC,MAAM,GAAG,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAChF,KAAK,QAAQ,CAAC,KAAK,IAAI;KAAG,GAAG,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;CAAE,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Ae,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,GACzD,iBAAiB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,GAC3D,sBAAsB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC"}
@@ -22,6 +22,13 @@ type ExplicitPrismaMethod = "aggregate" | "avg" | "combine" | "count" | "cursor"
22
22
  type RelationMethods<Collection, Requirement, Contract, Model extends string> = {
23
23
  readonly [Key in Exclude<FunctionKeys<Collection>, ExplicitPrismaMethod>]: WrapFunction<Key, Collection[Key], Requirement, Contract, Model>;
24
24
  };
25
- export type Relation<Collection, Requirement, Contract = undefined, Model extends string = string> = Effect.Effect<CollectionResult<Collection>, PrismaError, Requirement> & RelationMethods<Collection, Requirement, Contract, Model> & PrismaRelationMethods<Collection, Requirement, Contract, Model>;
25
+ declare const RelationQueryTypeId: unique symbol;
26
+ export type RelationQuery<Value, Requirement, Contract, Model extends string> = Effect.Effect<Value, PrismaError, Requirement> & {
27
+ readonly [RelationQueryTypeId]: {
28
+ readonly contract: Contract;
29
+ readonly model: Model;
30
+ };
31
+ };
32
+ export type Relation<Collection, Requirement, Contract = undefined, Model extends string = string> = RelationQuery<CollectionResult<Collection>, Requirement, Contract, Model> & RelationMethods<Collection, Requirement, Contract, Model> & PrismaRelationMethods<Collection, Requirement, Contract, Model>;
26
33
  export {};
27
34
  //# sourceMappingURL=relation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,KAAK,WAAW,GAAG,CAAC,GAAG,UAAU,EAAE,aAAa,CA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AAC,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,GAAG;IACpD,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE;QAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;KACtB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,QAAQ,CACnB,UAAU,EACV,WAAW,EACX,QAAQ,GAAG,SAAS,EACpB,KAAK,SAAS,MAAM,GAAG,MAAM,IAC1B,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,GAC5E,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,GACzD,qBAAqB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/effect-prisma",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Effect-native PostgreSQL queries and transactions for Prisma Next",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,3 +1,5 @@
1
+ import { getRelationPlan, type RelationPlan } from "./relation-plan.js";
2
+
1
3
  export interface RelationOperation {
2
4
  readonly name: PropertyKey;
3
5
  readonly arguments: ReadonlyArray<unknown>;
@@ -40,32 +42,107 @@ const operations = (
40
42
  return reversed.reverse();
41
43
  };
42
44
 
45
+ const applyMethod = (
46
+ current: unknown,
47
+ name: PropertyKey,
48
+ arguments_: ReadonlyArray<unknown>,
49
+ model: string,
50
+ ): unknown => {
51
+ if (
52
+ typeof current !== "object" ||
53
+ current === null ||
54
+ typeof Reflect.get(current, name) !== "function"
55
+ ) {
56
+ throw new TypeError(`Cannot call ${String(name)} while replaying ${model}`);
57
+ }
58
+
59
+ const method = Reflect.get(current, name) as (
60
+ ...arguments_: ReadonlyArray<unknown>
61
+ ) => unknown;
62
+ return Reflect.apply(method, current, arguments_);
63
+ };
64
+
65
+ const replayPlan = (collection: unknown, plan: RelationPlan): unknown => {
66
+ const relatedModel =
67
+ typeof collection === "object" && collection !== null
68
+ ? Reflect.get(collection, "modelName")
69
+ : undefined;
70
+ if (typeof relatedModel === "string" && relatedModel !== plan.recipe.model) {
71
+ throw new TypeError(
72
+ `Included relation expects ${relatedModel}, received ${plan.recipe.model}`,
73
+ );
74
+ }
75
+
76
+ const refined = replayRecipeFrom(collection, plan.recipe);
77
+ if (plan.terminal !== "count") {
78
+ return refined;
79
+ }
80
+ return applyMethod(refined, "count", [], plan.recipe.model);
81
+ };
82
+
83
+ const includeRefinement = (
84
+ value: unknown,
85
+ ): ((collection: unknown) => unknown) => {
86
+ const plan = getRelationPlan(value);
87
+ if (plan !== undefined) {
88
+ return (collection) => replayPlan(collection, plan);
89
+ }
90
+
91
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
92
+ throw new TypeError(
93
+ "An included relation must be a Relation or query record",
94
+ );
95
+ }
96
+
97
+ const entries = Object.entries(value);
98
+ if (entries.length === 0) {
99
+ throw new TypeError("An included query record cannot be empty");
100
+ }
101
+
102
+ const plans = entries.map(([name, query]) => {
103
+ const queryPlan = getRelationPlan(query);
104
+ if (queryPlan === undefined) {
105
+ throw new TypeError(`Included query "${name}" is not a Relation`);
106
+ }
107
+ return [name, queryPlan] as const;
108
+ });
109
+ const model = plans[0]?.[1].recipe.model;
110
+ if (plans.some(([, queryPlan]) => queryPlan.recipe.model !== model)) {
111
+ throw new TypeError("Included queries must use the same related model");
112
+ }
113
+
114
+ return (collection) => {
115
+ const branches = Object.fromEntries(
116
+ plans.map(([name, queryPlan]) => [
117
+ name,
118
+ replayPlan(collection, queryPlan),
119
+ ]),
120
+ );
121
+ return applyMethod(collection, "combine", [branches], model ?? "relation");
122
+ };
123
+ };
124
+
125
+ const replayRecipeFrom = (root: unknown, recipe: RelationRecipe): unknown => {
126
+ let current = root;
127
+ for (const operation of operations(recipe)) {
128
+ const arguments_ =
129
+ operation.name === "include" && operation.arguments.length === 2
130
+ ? [operation.arguments[0], includeRefinement(operation.arguments[1])]
131
+ : operation.arguments;
132
+ current = applyMethod(current, operation.name, arguments_, recipe.model);
133
+ }
134
+ return current;
135
+ };
136
+
43
137
  export const replayRecipe = (
44
138
  models: object,
45
139
  recipe: RelationRecipe,
46
140
  ): unknown => {
47
- let current: unknown = Reflect.get(models, recipe.model);
141
+ const current: unknown = Reflect.get(models, recipe.model);
48
142
 
49
143
  if (current === undefined) {
50
144
  throw new TypeError(`Unknown Prisma model: ${recipe.model}`);
51
145
  }
52
146
 
53
- for (const operation of operations(recipe)) {
54
- if (
55
- typeof current !== "object" ||
56
- current === null ||
57
- typeof Reflect.get(current, operation.name) !== "function"
58
- ) {
59
- throw new TypeError(
60
- `Cannot call ${String(operation.name)} while replaying ${recipe.model}`,
61
- );
62
- }
63
-
64
- const method = Reflect.get(current, operation.name) as (
65
- ...arguments_: ReadonlyArray<unknown>
66
- ) => unknown;
67
- current = Reflect.apply(method, current, operation.arguments);
68
- }
69
-
70
- return current;
147
+ return replayRecipeFrom(current, recipe);
71
148
  };
@@ -0,0 +1,22 @@
1
+ import type { RelationRecipe } from "./recipe.js";
2
+
3
+ export const RelationPlanTypeId = Symbol.for(
4
+ "@shivaedev/effect-prisma/RelationPlan",
5
+ );
6
+
7
+ export interface RelationPlan {
8
+ readonly recipe: RelationRecipe;
9
+ readonly terminal?: PropertyKey;
10
+ }
11
+
12
+ export const getRelationPlan = (value: unknown): RelationPlan | undefined => {
13
+ if (
14
+ typeof value !== "object" ||
15
+ value === null ||
16
+ !Reflect.has(value, RelationPlanTypeId)
17
+ ) {
18
+ return undefined;
19
+ }
20
+
21
+ return Reflect.get(value, RelationPlanTypeId) as RelationPlan;
22
+ };
@@ -14,6 +14,7 @@ import {
14
14
  replayRecipe,
15
15
  rootRecipe,
16
16
  } from "./recipe.js";
17
+ import { RelationPlanTypeId } from "./relation-plan.js";
17
18
 
18
19
  type AnyFunction = (...arguments_: ReadonlyArray<never>) => unknown;
19
20
 
@@ -33,6 +34,22 @@ const evaluateResult = (
33
34
  value: unknown,
34
35
  terminal: PropertyKey | undefined,
35
36
  ): Effect.Effect<unknown, PrismaError> => {
37
+ if (
38
+ terminal === "count" &&
39
+ typeof value === "object" &&
40
+ value !== null &&
41
+ typeof Reflect.get(value, "aggregate") === "function"
42
+ ) {
43
+ const aggregate = Reflect.apply(
44
+ Reflect.get(value, "aggregate") as AnyFunction,
45
+ value,
46
+ [(summary: { count(): unknown }) => ({ count: summary.count() })],
47
+ );
48
+ return fromPrismaPromise(
49
+ () => aggregate as PromiseLike<{ count: number }>,
50
+ ).pipe(Effect.map((result) => result.count));
51
+ }
52
+
36
53
  if (
37
54
  terminal === "exists" &&
38
55
  typeof value === "object" &&
@@ -75,6 +92,10 @@ interface RelationValue<
75
92
  Models extends object,
76
93
  Contract extends AnyPostgresContract,
77
94
  > extends Effect.Effect<unknown, PrismaError, ExecutorIdentifier<Models>> {
95
+ readonly [RelationPlanTypeId]: {
96
+ readonly recipe: RelationRecipe;
97
+ readonly terminal?: PropertyKey;
98
+ };
78
99
  readonly runtime: RelationRuntime<Models, Contract>;
79
100
  readonly stream: Stream.Stream<
80
101
  unknown,
@@ -172,6 +193,10 @@ const makeRelationProxy = <
172
193
  runtime: RelationRuntime<Models, Contract>,
173
194
  ): unknown => {
174
195
  const target = Object.assign(Object.create(RelationPrototype), {
196
+ [RelationPlanTypeId]: {
197
+ recipe: runtime.recipe,
198
+ ...(runtime.terminal === undefined ? {} : { terminal: runtime.terminal }),
199
+ },
175
200
  runtime,
176
201
  }) as RelationValue<Models, Contract>;
177
202
 
@@ -190,6 +215,13 @@ const makeRelationProxy = <
190
215
  terminal: "exists",
191
216
  });
192
217
  }
218
+ if (property === "count") {
219
+ return () =>
220
+ makeRelationProxy({
221
+ ...runtime,
222
+ terminal: "count",
223
+ });
224
+ }
193
225
  return (...arguments_: ReadonlyArray<unknown>) =>
194
226
  makeRelationProxy({
195
227
  ...runtime,
@@ -0,0 +1,102 @@
1
+ import type { Contract as PrismaContract } from "@prisma-next/contract/types";
2
+ import type { SqlStorage } from "@prisma-next/sql-contract/types";
3
+ import type { RelationsOf } from "@prisma-next/sql-orm-client";
4
+
5
+ export type AnyPostgresContract = PrismaContract<SqlStorage>;
6
+
7
+ type RelationDefinition<
8
+ Contract extends AnyPostgresContract,
9
+ Model extends string,
10
+ RelationName extends string,
11
+ > = RelationName extends keyof RelationsOf<Contract, Model>
12
+ ? RelationsOf<Contract, Model>[RelationName]
13
+ : never;
14
+
15
+ type RelationCardinalityOf<
16
+ Contract extends AnyPostgresContract,
17
+ Model extends string,
18
+ RelationName extends string,
19
+ > =
20
+ RelationDefinition<Contract, Model, RelationName> extends {
21
+ readonly cardinality: infer Cardinality extends string;
22
+ }
23
+ ? Cardinality
24
+ : never;
25
+
26
+ export type IsToManyRelation<
27
+ Contract extends AnyPostgresContract,
28
+ Model extends string,
29
+ RelationName extends string,
30
+ > =
31
+ RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M"
32
+ ? true
33
+ : false;
34
+
35
+ export type RelatedModelNameOf<
36
+ Contract extends AnyPostgresContract,
37
+ Model extends string,
38
+ RelationName extends string,
39
+ > =
40
+ RelationDefinition<Contract, Model, RelationName> extends {
41
+ readonly to: { readonly model: infer Related extends string };
42
+ }
43
+ ? Related
44
+ : never;
45
+
46
+ type RelationLocalFields<
47
+ Contract extends AnyPostgresContract,
48
+ Model extends string,
49
+ RelationName extends string,
50
+ > =
51
+ RelationDefinition<Contract, Model, RelationName> extends {
52
+ readonly on: {
53
+ readonly localFields: infer Fields extends readonly string[];
54
+ };
55
+ }
56
+ ? Fields
57
+ : readonly [];
58
+
59
+ type DefaultNamespace<Contract extends AnyPostgresContract> =
60
+ Contract["domain"]["namespaces"][keyof Contract["domain"]["namespaces"]];
61
+
62
+ type ModelFields<Contract extends AnyPostgresContract, Model extends string> =
63
+ DefaultNamespace<Contract> extends {
64
+ readonly models: infer Models;
65
+ }
66
+ ? Model extends keyof Models
67
+ ? Models[Model] extends { readonly fields: infer Fields }
68
+ ? Fields
69
+ : never
70
+ : never
71
+ : never;
72
+
73
+ type AnyNullableField<
74
+ Fields,
75
+ Names extends readonly string[],
76
+ > = Names extends readonly [
77
+ infer Head extends string,
78
+ ...infer Tail extends readonly string[],
79
+ ]
80
+ ? Head extends keyof Fields
81
+ ? Fields[Head] extends { readonly nullable: true }
82
+ ? true
83
+ : AnyNullableField<Fields, Tail>
84
+ : true
85
+ : false;
86
+
87
+ export type IncludedRelationValue<
88
+ Contract extends AnyPostgresContract,
89
+ Model extends string,
90
+ RelationName extends string,
91
+ Value,
92
+ > =
93
+ RelationCardinalityOf<Contract, Model, RelationName> extends "1:N" | "N:M"
94
+ ? Array<Value>
95
+ : RelationCardinalityOf<Contract, Model, RelationName> extends "N:1"
96
+ ? AnyNullableField<
97
+ ModelFields<Contract, Model>,
98
+ RelationLocalFields<Contract, Model, RelationName>
99
+ > extends true
100
+ ? Value | null
101
+ : Value
102
+ : Value | null;
@@ -0,0 +1,169 @@
1
+ import type {
2
+ DefaultModelRow,
3
+ Collection as PrismaCollection,
4
+ RelationNames,
5
+ } from "@prisma-next/sql-orm-client";
6
+ import type { Relation, RelationQuery } from "../relation.js";
7
+ import type {
8
+ AnyPostgresContract,
9
+ IncludedRelationValue,
10
+ IsToManyRelation,
11
+ RelatedModelNameOf,
12
+ } from "./include-metadata.js";
13
+
14
+ type Simplify<Value> = { [Key in keyof Value]: Value[Key] };
15
+
16
+ type QueryValue<Query> =
17
+ Query extends RelationQuery<
18
+ infer Value,
19
+ infer _Requirement,
20
+ infer _Contract,
21
+ infer _Model
22
+ >
23
+ ? Value
24
+ : never;
25
+
26
+ type AcceptRelatedQuery<
27
+ Query,
28
+ Contract extends AnyPostgresContract,
29
+ Model extends string,
30
+ > =
31
+ Query extends RelationQuery<
32
+ infer _Value,
33
+ infer _Requirement,
34
+ infer QueryContract,
35
+ infer QueryModel
36
+ >
37
+ ? [QueryContract] extends [Contract]
38
+ ? [Contract] extends [QueryContract]
39
+ ? QueryModel extends Model
40
+ ? unknown
41
+ : never
42
+ : never
43
+ : never
44
+ : never;
45
+
46
+ type IncludedQueryValue<
47
+ Query,
48
+ Contract extends AnyPostgresContract,
49
+ Model extends string,
50
+ RelationName extends string,
51
+ > =
52
+ QueryValue<Query> extends ReadonlyArray<infer Row>
53
+ ? IncludedRelationValue<Contract, Model, RelationName, Row>
54
+ : QueryValue<Query>;
55
+
56
+ type QueryShapeValue<Shape extends Readonly<Record<string, unknown>>> = {
57
+ readonly [Key in keyof Shape]: QueryValue<Shape[Key]>;
58
+ };
59
+
60
+ type AcceptRelatedQueryShape<
61
+ Shape extends Readonly<Record<string, unknown>>,
62
+ Contract extends AnyPostgresContract,
63
+ Model extends string,
64
+ > = {
65
+ readonly [Key in keyof Shape]: Shape[Key] &
66
+ AcceptRelatedQuery<Shape[Key], Contract, Model>;
67
+ };
68
+
69
+ type WithIncludedRelation<
70
+ Collection,
71
+ Contract extends AnyPostgresContract,
72
+ Model extends string,
73
+ RelationName extends string,
74
+ Value,
75
+ > =
76
+ Collection extends PrismaCollection<Contract, Model, infer Row, infer State>
77
+ ? PrismaCollection<
78
+ Contract,
79
+ Model,
80
+ Simplify<Row & { readonly [Key in RelationName]: Value }>,
81
+ State
82
+ >
83
+ : never;
84
+
85
+ export type IncludeMethod<
86
+ Collection,
87
+ Requirement,
88
+ Contract,
89
+ Model extends string,
90
+ > = Contract extends AnyPostgresContract
91
+ ? Collection extends PrismaCollection<
92
+ Contract,
93
+ Model,
94
+ infer _Row,
95
+ infer _State
96
+ >
97
+ ? {
98
+ include<RelationName extends RelationNames<Contract, Model>>(
99
+ relationName: RelationName,
100
+ ): Relation<
101
+ WithIncludedRelation<
102
+ Collection,
103
+ Contract,
104
+ Model,
105
+ RelationName,
106
+ IncludedRelationValue<
107
+ Contract,
108
+ Model,
109
+ RelationName,
110
+ DefaultModelRow<
111
+ Contract,
112
+ RelatedModelNameOf<Contract, Model, RelationName>
113
+ >
114
+ >
115
+ >,
116
+ Requirement,
117
+ Contract,
118
+ Model
119
+ >;
120
+ include<RelationName extends RelationNames<Contract, Model>, Query>(
121
+ relationName: RelationName,
122
+ query: Query &
123
+ AcceptRelatedQuery<
124
+ Query,
125
+ Contract,
126
+ RelatedModelNameOf<Contract, Model, RelationName>
127
+ >,
128
+ ): Relation<
129
+ WithIncludedRelation<
130
+ Collection,
131
+ Contract,
132
+ Model,
133
+ RelationName,
134
+ IncludedQueryValue<Query, Contract, Model, RelationName>
135
+ >,
136
+ Requirement,
137
+ Contract,
138
+ Model
139
+ >;
140
+ include<
141
+ RelationName extends RelationNames<Contract, Model>,
142
+ Shape extends Readonly<Record<string, unknown>>,
143
+ >(
144
+ relationName: RelationName,
145
+ shape: IsToManyRelation<Contract, Model, RelationName> extends true
146
+ ? keyof Shape extends never
147
+ ? never
148
+ : Shape &
149
+ AcceptRelatedQueryShape<
150
+ Shape,
151
+ Contract,
152
+ RelatedModelNameOf<Contract, Model, RelationName>
153
+ >
154
+ : never,
155
+ ): Relation<
156
+ WithIncludedRelation<
157
+ Collection,
158
+ Contract,
159
+ Model,
160
+ RelationName,
161
+ QueryShapeValue<Shape>
162
+ >,
163
+ Requirement,
164
+ Contract,
165
+ Model
166
+ >;
167
+ }
168
+ : Record<never, never>
169
+ : Record<never, never>;
@@ -10,7 +10,8 @@ import type {
10
10
  } from "@prisma-next/sql-orm-client";
11
11
  import type { Effect, Stream } from "effect";
12
12
  import type { PrismaError } from "../error.js";
13
- import type { CollectionResult, Relation } from "../relation.js";
13
+ import type { CollectionResult, Relation, RelationQuery } from "../relation.js";
14
+ import type { IncludeMethod } from "./include.js";
14
15
 
15
16
  type AnyFunction = (...arguments_: ReadonlyArray<never>) => unknown;
16
17
  type AnyPostgresContract = PrismaContract<SqlStorage>;
@@ -171,12 +172,14 @@ type CollectionConveniences<
171
172
  >
172
173
  ? {
173
174
  readonly stream: Stream.Stream<Row, PrismaError, Requirement>;
175
+ count(): RelationQuery<number, Requirement, Contract, Model>;
174
176
  exists(): Effect.Effect<boolean, PrismaError, Requirement>;
175
177
  }
176
178
  : Record<never, never>
177
179
  : CollectionResult<Collection> extends ReadonlyArray<infer Row>
178
180
  ? {
179
181
  readonly stream: Stream.Stream<Row, PrismaError, Requirement>;
182
+ count(): Effect.Effect<number, PrismaError, Requirement>;
180
183
  exists(): Effect.Effect<boolean, PrismaError, Requirement>;
181
184
  }
182
185
  : Record<never, never>;
@@ -187,6 +190,7 @@ export type PrismaRelationMethods<
187
190
  Contract,
188
191
  Model extends string,
189
192
  > = SelectMethod<Collection, Requirement, Contract, Model> &
193
+ IncludeMethod<Collection, Requirement, Contract, Model> &
190
194
  AggregateMethod<Collection, Requirement, Contract, Model> &
191
195
  CollectionMethods<Collection, Requirement, Contract, Model> &
192
196
  CollectionConveniences<Collection, Requirement, Contract, Model>;
package/src/relation.ts CHANGED
@@ -94,11 +94,25 @@ type RelationMethods<
94
94
  >]: WrapFunction<Key, Collection[Key], Requirement, Contract, Model>;
95
95
  };
96
96
 
97
+ declare const RelationQueryTypeId: unique symbol;
98
+
99
+ export type RelationQuery<
100
+ Value,
101
+ Requirement,
102
+ Contract,
103
+ Model extends string,
104
+ > = Effect.Effect<Value, PrismaError, Requirement> & {
105
+ readonly [RelationQueryTypeId]: {
106
+ readonly contract: Contract;
107
+ readonly model: Model;
108
+ };
109
+ };
110
+
97
111
  export type Relation<
98
112
  Collection,
99
113
  Requirement,
100
114
  Contract = undefined,
101
115
  Model extends string = string,
102
- > = Effect.Effect<CollectionResult<Collection>, PrismaError, Requirement> &
116
+ > = RelationQuery<CollectionResult<Collection>, Requirement, Contract, Model> &
103
117
  RelationMethods<Collection, Requirement, Contract, Model> &
104
118
  PrismaRelationMethods<Collection, Requirement, Contract, Model>;