@shivaedev/effect-prisma 0.5.3 → 0.6.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 (89) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +32 -10
  3. package/dist/database.d.ts +6 -6
  4. package/dist/database.d.ts.map +1 -1
  5. package/dist/database.js +9 -2
  6. package/dist/database.js.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal/database-factory.d.ts +20 -22
  11. package/dist/internal/database-factory.d.ts.map +1 -1
  12. package/dist/internal/database-factory.js +83 -24
  13. package/dist/internal/database-factory.js.map +1 -1
  14. package/dist/internal/executor.d.ts +9 -7
  15. package/dist/internal/executor.d.ts.map +1 -1
  16. package/dist/internal/query-execution.d.ts +3 -4
  17. package/dist/internal/query-execution.d.ts.map +1 -1
  18. package/dist/internal/query-execution.js +9 -3
  19. package/dist/internal/query-execution.js.map +1 -1
  20. package/dist/internal/recipe.d.ts +1 -1
  21. package/dist/internal/recipe.d.ts.map +1 -1
  22. package/dist/internal/recipe.js +22 -9
  23. package/dist/internal/recipe.js.map +1 -1
  24. package/dist/internal/relation-plan.d.ts +6 -1
  25. package/dist/internal/relation-plan.d.ts.map +1 -1
  26. package/dist/internal/relation-plan.js +6 -5
  27. package/dist/internal/relation-plan.js.map +1 -1
  28. package/dist/internal/relation-runtime.d.ts +4 -3
  29. package/dist/internal/relation-runtime.d.ts.map +1 -1
  30. package/dist/internal/relation-runtime.js +38 -19
  31. package/dist/internal/relation-runtime.js.map +1 -1
  32. package/dist/internal/relation-stream.d.ts +3 -4
  33. package/dist/internal/relation-stream.d.ts.map +1 -1
  34. package/dist/internal/relation-stream.js +23 -21
  35. package/dist/internal/relation-stream.js.map +1 -1
  36. package/dist/internal/testing.d.ts +5 -5
  37. package/dist/internal/testing.d.ts.map +1 -1
  38. package/dist/internal/testing.js.map +1 -1
  39. package/dist/internal/transaction.d.ts +6 -3
  40. package/dist/internal/transaction.d.ts.map +1 -1
  41. package/dist/internal/transaction.js +14 -4
  42. package/dist/internal/transaction.js.map +1 -1
  43. package/dist/relation/include.d.ts +10 -8
  44. package/dist/relation/include.d.ts.map +1 -1
  45. package/dist/relation/prisma-methods.d.ts +20 -20
  46. package/dist/relation/prisma-methods.d.ts.map +1 -1
  47. package/dist/relation.d.ts +8 -7
  48. package/dist/relation.d.ts.map +1 -1
  49. package/dist/sqlite.d.ts +6 -6
  50. package/dist/sqlite.d.ts.map +1 -1
  51. package/dist/sqlite.js +12 -3
  52. package/dist/sqlite.js.map +1 -1
  53. package/dist/testing/transaction.d.ts +3 -3
  54. package/dist/testing/transaction.d.ts.map +1 -1
  55. package/dist/testing/transaction.js.map +1 -1
  56. package/dist/testing/types.d.ts +6 -4
  57. package/dist/testing/types.d.ts.map +1 -1
  58. package/dist/testing/vitest.d.ts +4 -4
  59. package/dist/testing/vitest.d.ts.map +1 -1
  60. package/dist/testing/vitest.js +8 -16
  61. package/dist/testing/vitest.js.map +1 -1
  62. package/dist/testing.d.ts +1 -1
  63. package/dist/testing.d.ts.map +1 -1
  64. package/dist/testing.js.map +1 -1
  65. package/package.json +3 -2
  66. package/src/database.ts +53 -47
  67. package/src/index.ts +0 -1
  68. package/src/internal/database-factory.ts +221 -98
  69. package/src/internal/executor.ts +9 -15
  70. package/src/internal/query-execution.ts +14 -6
  71. package/src/internal/recipe.ts +46 -7
  72. package/src/internal/relation-plan.ts +11 -11
  73. package/src/internal/relation-runtime.ts +67 -65
  74. package/src/internal/relation-stream.ts +54 -48
  75. package/src/internal/testing.ts +8 -8
  76. package/src/internal/transaction.ts +80 -56
  77. package/src/relation/include.ts +31 -22
  78. package/src/relation/prisma-methods.ts +27 -31
  79. package/src/relation.ts +19 -27
  80. package/src/sqlite.ts +62 -54
  81. package/src/testing/transaction.ts +16 -6
  82. package/src/testing/types.ts +6 -4
  83. package/src/testing/vitest.ts +19 -40
  84. package/src/testing.ts +0 -1
  85. package/dist/internal/vitest-database.d.ts +0 -18
  86. package/dist/internal/vitest-database.d.ts.map +0 -1
  87. package/dist/internal/vitest-database.js +0 -73
  88. package/dist/internal/vitest-database.js.map +0 -1
  89. package/src/internal/vitest-database.ts +0 -210
@@ -1,73 +0,0 @@
1
- import { Cause, Effect, Exit, Layer } from "effect";
2
- import * as TestClock from "effect/testing/TestClock";
3
- import * as TestConsole from "effect/testing/TestConsole";
4
- import { withTestTransaction } from "../testing/transaction.js";
5
- export const fixtureName = "__effectPrismaContext";
6
- const TestEnvironment = Layer.mergeAll(TestConsole.layer, TestClock.layer());
7
- const contextFrom = (context) => context[fixtureName];
8
- const runEffectTest = (effect, context) => Effect.runPromise(Effect.gen(function* () {
9
- const exit = yield* Effect.exit(effect);
10
- if (Exit.isFailure(exit)) {
11
- for (const error of Cause.prettyErrors(exit.cause)) {
12
- yield* Effect.logError(error);
13
- }
14
- }
15
- return yield* exit;
16
- }).pipe(Effect.scoped, Effect.provide(TestEnvironment)), { signal: context.signal });
17
- const normalizeTestOptions = (options) => typeof options === "number" ? { timeout: options } : (options ?? {});
18
- const restoreContext = (fixture, context) => ({
19
- ...context,
20
- [fixtureName]: fixture,
21
- });
22
- export const makeDatabaseTester = (fixtureIt, database) => {
23
- const run = (body, context) => {
24
- const effect = withTestTransaction(database, Effect.gen(function* () {
25
- const service = yield* database;
26
- return yield* Effect.gen(() => body(service, context));
27
- })).pipe(Effect.provide(contextFrom(context)));
28
- // The callback constraint proves that its services are in the built
29
- // Layer. TypeScript cannot reduce that generic Exclude after
30
- // Effect.provide, so the runner closes the type at this private boundary.
31
- return effect;
32
- };
33
- const register = (current) => (name, body, options) => current(name, normalizeTestOptions(options), ({ __effectPrismaContext, task, signal, onTestFailed, onTestFinished, skip, annotate, expect, _local, }) => {
34
- const testContext = restoreContext(__effectPrismaContext, {
35
- task,
36
- signal,
37
- onTestFailed,
38
- onTestFinished,
39
- skip,
40
- annotate,
41
- expect,
42
- _local,
43
- });
44
- return runEffectTest(run(body, testContext), testContext);
45
- });
46
- const make = (current) => {
47
- const test = register(current);
48
- return Object.assign(test, {
49
- skip: register(current.skip),
50
- skipIf: (condition) => register(current.skipIf(condition)),
51
- runIf: (condition) => register(current.runIf(condition)),
52
- only: register(current.only),
53
- each: (cases) => {
54
- return (name, body, options) => fixtureIt.for(cases)(name, normalizeTestOptions(options), (item, { __effectPrismaContext, task, signal, onTestFailed, onTestFinished, skip, annotate, expect, _local, }) => {
55
- const testContext = restoreContext(__effectPrismaContext, {
56
- task,
57
- signal,
58
- onTestFailed,
59
- onTestFinished,
60
- skip,
61
- annotate,
62
- expect,
63
- _local,
64
- });
65
- return runEffectTest(run((service, testContext) => body(item, service, testContext), testContext), testContext);
66
- });
67
- },
68
- fails: register(current.fails),
69
- });
70
- };
71
- return make(fixtureIt);
72
- };
73
- //# sourceMappingURL=vitest-database.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest-database.js","sourceRoot":"","sources":["../../src/internal/vitest-database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAShE,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AA0BnD,MAAM,eAAe,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;AAE7E,MAAM,WAAW,GAAG,CACnB,OAAoB,EACQ,EAAE,CAC7B,OAAqC,CAAC,WAAW,CAAC,CAAC;AAErD,MAAM,aAAa,GAAG,CACrB,MAAwC,EACxC,OAAoB,EACP,EAAE,CACf,MAAM,CAAC,UAAU,CAChB,MA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CAAC,SAAS,CAAC,CAAC;YACjE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;YAC5B,IAAI,EAAE,CAAO,KAA0B,EAAE,EAAE;gBAC1C,OAAO,CACN,IAAY,EACZ,IAI6B,EAC7B,OAA8B,EAC7B,EAAE,CACH,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CACnB,IAAI,EACJ,oBAAoB,CAAC,OAAO,CAAC,EAC7B,CACC,IAAI,EACJ,EACC,qBAAqB,EACrB,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,GACqB,EAC3B,EAAE;oBACH,MAAM,WAAW,GAAG,cAAc,CAAC,qBAAqB,EAAE;wBACzD,IAAI;wBACJ,MAAM;wBACN,YAAY;wBACZ,cAAc;wBACd,IAAI;wBACJ,QAAQ;wBACR,MAAM;wBACN,MAAM;qBACN,CAAC,CAAC;oBACH,OAAO,aAAa,CACnB,GAAG,CACF,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,EAC1D,WAAW,CACX,EACD,WAAW,CACX,CAAC;gBACH,CAAC,CACD,CAAC;YACJ,CAAC;YACD,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;SAC9B,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;AACxB,CAAC,CAAC"}
@@ -1,210 +0,0 @@
1
- import type { TestContext, TestOptions } from "@effect/vitest";
2
- import { Cause, type Context, Effect, Exit, Layer, type Scope } from "effect";
3
- import * as TestClock from "effect/testing/TestClock";
4
- import * as TestConsole from "effect/testing/TestConsole";
5
- import { withTestTransaction } from "../testing/transaction.js";
6
- import type {
7
- AnyDatabase,
8
- DatabaseRequirement,
9
- DatabaseService,
10
- DatabaseTest,
11
- DatabaseTester,
12
- } from "../testing/types.js";
13
-
14
- export const fixtureName = "__effectPrismaContext";
15
-
16
- export type DatabaseFixture<Provided> = TestContext & {
17
- readonly [fixtureName]: Context.Context<Provided>;
18
- };
19
-
20
- export interface FixtureTestApi<Provided> {
21
- (
22
- name: string,
23
- options: TestOptions,
24
- body: (context: DatabaseFixture<Provided>) => Promise<unknown>,
25
- ): void;
26
- readonly skip: FixtureTestApi<Provided>;
27
- readonly skipIf: (condition: unknown) => FixtureTestApi<Provided>;
28
- readonly runIf: (condition: unknown) => FixtureTestApi<Provided>;
29
- readonly only: FixtureTestApi<Provided>;
30
- readonly fails: FixtureTestApi<Provided>;
31
- readonly for: <Item>(
32
- cases: ReadonlyArray<Item>,
33
- ) => (
34
- name: string,
35
- options: TestOptions,
36
- body: (item: Item, context: DatabaseFixture<Provided>) => Promise<unknown>,
37
- ) => void;
38
- }
39
-
40
- const TestEnvironment = Layer.mergeAll(TestConsole.layer, TestClock.layer());
41
-
42
- const contextFrom = <Provided>(
43
- context: TestContext,
44
- ): Context.Context<Provided> =>
45
- (context as DatabaseFixture<Provided>)[fixtureName];
46
-
47
- const runEffectTest = <A, E>(
48
- effect: Effect.Effect<A, E, Scope.Scope>,
49
- context: TestContext,
50
- ): Promise<A> =>
51
- Effect.runPromise(
52
- Effect.gen(function* () {
53
- const exit = yield* Effect.exit(effect);
54
- if (Exit.isFailure(exit)) {
55
- for (const error of Cause.prettyErrors(exit.cause)) {
56
- yield* Effect.logError(error);
57
- }
58
- }
59
- return yield* exit;
60
- }).pipe(Effect.scoped, Effect.provide(TestEnvironment)),
61
- { signal: context.signal },
62
- );
63
-
64
- const normalizeTestOptions = (
65
- options: number | TestOptions | undefined,
66
- ): TestOptions =>
67
- typeof options === "number" ? { timeout: options } : (options ?? {});
68
-
69
- const restoreContext = <Provided>(
70
- fixture: Context.Context<Provided>,
71
- context: Omit<DatabaseFixture<Provided>, typeof fixtureName>,
72
- ): DatabaseFixture<Provided> =>
73
- ({
74
- ...context,
75
- [fixtureName]: fixture,
76
- }) as DatabaseFixture<Provided>;
77
-
78
- export const makeDatabaseTester = <Database extends AnyDatabase, Provided>(
79
- fixtureIt: FixtureTestApi<
80
- Provided | DatabaseRequirement<Database> | Effect.Services<Database>
81
- >,
82
- database: Database,
83
- ): DatabaseTester<
84
- Database,
85
- Provided | DatabaseRequirement<Database> | Effect.Services<Database>
86
- > => {
87
- type Services =
88
- | Provided
89
- | DatabaseRequirement<Database>
90
- | Effect.Services<Database>;
91
-
92
- const run = <A, Eff extends Effect.Effect<unknown, unknown, Services>>(
93
- body: (
94
- database: DatabaseService<Database>,
95
- context: TestContext,
96
- ) => Generator<Eff, A, never>,
97
- context: TestContext,
98
- ): Effect.Effect<A, unknown, Scope.Scope> => {
99
- const effect = withTestTransaction(
100
- database,
101
- Effect.gen(function* () {
102
- const service = yield* database as unknown as Effect.Effect<
103
- DatabaseService<Database>,
104
- never,
105
- Effect.Services<Database>
106
- >;
107
- return yield* Effect.gen(() => body(service, context));
108
- }),
109
- ).pipe(Effect.provide(contextFrom<Services>(context)));
110
-
111
- // The callback constraint proves that its services are in the built
112
- // Layer. TypeScript cannot reduce that generic Exclude after
113
- // Effect.provide, so the runner closes the type at this private boundary.
114
- return effect as unknown as Effect.Effect<A, unknown, Scope.Scope>;
115
- };
116
-
117
- const register =
118
- (current: FixtureTestApi<Services>): DatabaseTest<Database, Services> =>
119
- (name, body, options) =>
120
- current(
121
- name,
122
- normalizeTestOptions(options),
123
- ({
124
- __effectPrismaContext,
125
- task,
126
- signal,
127
- onTestFailed,
128
- onTestFinished,
129
- skip,
130
- annotate,
131
- expect,
132
- _local,
133
- }: DatabaseFixture<Services>) => {
134
- const testContext = restoreContext(__effectPrismaContext, {
135
- task,
136
- signal,
137
- onTestFailed,
138
- onTestFinished,
139
- skip,
140
- annotate,
141
- expect,
142
- _local,
143
- });
144
- return runEffectTest(run(body, testContext), testContext);
145
- },
146
- );
147
-
148
- const make = (
149
- current: FixtureTestApi<Services>,
150
- ): DatabaseTester<Database, Services> => {
151
- const test = register(current);
152
-
153
- return Object.assign(test, {
154
- skip: register(current.skip),
155
- skipIf: (condition: unknown) => register(current.skipIf(condition)),
156
- runIf: (condition: unknown) => register(current.runIf(condition)),
157
- only: register(current.only),
158
- each: <Item>(cases: ReadonlyArray<Item>) => {
159
- return <A, Eff extends Effect.Effect<unknown, unknown, Services>>(
160
- name: string,
161
- body: (
162
- item: Item,
163
- database: DatabaseService<Database>,
164
- context: TestContext,
165
- ) => Generator<Eff, A, never>,
166
- options?: number | TestOptions,
167
- ) =>
168
- fixtureIt.for(cases)(
169
- name,
170
- normalizeTestOptions(options),
171
- (
172
- item,
173
- {
174
- __effectPrismaContext,
175
- task,
176
- signal,
177
- onTestFailed,
178
- onTestFinished,
179
- skip,
180
- annotate,
181
- expect,
182
- _local,
183
- }: DatabaseFixture<Services>,
184
- ) => {
185
- const testContext = restoreContext(__effectPrismaContext, {
186
- task,
187
- signal,
188
- onTestFailed,
189
- onTestFinished,
190
- skip,
191
- annotate,
192
- expect,
193
- _local,
194
- });
195
- return runEffectTest(
196
- run(
197
- (service, testContext) => body(item, service, testContext),
198
- testContext,
199
- ),
200
- testContext,
201
- );
202
- },
203
- );
204
- },
205
- fails: register(current.fails),
206
- });
207
- };
208
-
209
- return make(fixtureIt);
210
- };