@shivaedev/platform 0.0.0 → 0.1.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 ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.1.0 - 2026-08-03
6
+
7
+ ### Added
8
+
9
+ - Add an opinionated Effect Vitest harness that combines typed tRPC callers,
10
+ direct Prisma access, rollback isolation, and application-owned fixtures.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShivaeDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,47 @@
1
1
  # @shivaedev/platform
2
2
 
3
- This placeholder reserves the package for releases from
4
- [ShivaeDev/platform](https://github.com/ShivaeDev/platform).
3
+ Opinionated shared setup for ShivaeDev Effect applications. This package favors
4
+ one consistent application shape over supporting every possible combination of
5
+ database, transport, and test framework.
6
+
7
+ The first public surface is the combined integration test harness. Generic
8
+ Prisma and tRPC integrations remain available separately from
9
+ `@shivaedev/effect-prisma` and `@shivaedev/effect-trpc`.
10
+
11
+ ## Testing
12
+
13
+ Configure the application database, tRPC caller, and test Layer once:
14
+
15
+ ```ts
16
+ import { makePlatformIt } from "@shivaedev/platform/testing"
17
+
18
+ export const it = makePlatformIt(Database)({
19
+ adapter: effectTrpc,
20
+ createCaller: (options = defaultActor) => appRouter.createCaller(options),
21
+ layer: TestLive,
22
+ extend: ({ db, trpc }) =>
23
+ Effect.succeed({
24
+ actors,
25
+ factories: makeFactories(db),
26
+ fixtures: makeFixtures({ db, trpc }),
27
+ }),
28
+ })
29
+ ```
30
+
31
+ Every `effectApp` test runs inside a real transaction. tRPC procedures, direct
32
+ database calls, factories, and fixtures share that transaction, which is rolled
33
+ back after both successful and failed tests:
34
+
35
+ ```ts
36
+ it.effectApp("creates a movie", function* ({ trpc, db, factories }) {
37
+ const input = factories.movie()
38
+ const movie = yield* trpc.movie.create(input)
39
+ const stored = yield* db.Movie.where({ id: movie.id }).first()
40
+
41
+ expect(stored?.title).toBe(input.title)
42
+ })
43
+ ```
44
+
45
+ Calling `trpc(options)` creates a caller for another application actor without
46
+ rebuilding the worker-scoped test Layer. `effectApp` also supports `skip`,
47
+ `skipIf`, `runIf`, `only`, `each`, and `fails`.
@@ -0,0 +1,24 @@
1
+ import type { TestContext, Vitest } from "@effect/vitest";
2
+ import type { AnyDatabase, DatabaseRequirement, DatabaseService } from "@shivaedev/effect-prisma/testing";
3
+ import type { EffectTRPCAdapter } from "@shivaedev/effect-trpc";
4
+ import type { CallerOptions, CallerResult, EffectCallerFactory, TrpcHarnessTest, TrpcHarnessTester } from "@shivaedev/effect-trpc/testing";
5
+ import type { Effect, Layer } from "effect";
6
+ export type PlatformHarness<Database extends AnyDatabase, Options, Caller, Extension> = Readonly<{
7
+ db: DatabaseService<Database>;
8
+ trpc: EffectCallerFactory<Options, Caller>;
9
+ }> & Omit<Extension, "db" | "trpc">;
10
+ export type PlatformTest<Harness, Provided> = TrpcHarnessTest<Harness, Provided>;
11
+ export type PlatformTester<Harness, Provided> = TrpcHarnessTester<Harness, Provided>;
12
+ export type PlatformIt<Harness, Provided> = Vitest.Methods & {
13
+ readonly effectApp: PlatformTester<Harness, Provided>;
14
+ };
15
+ export interface MakePlatformItOptions<Database extends AnyDatabase, CreateCaller extends (...arguments_: never[]) => object, Provided, LayerError, Extension> {
16
+ readonly adapter: Pick<EffectTRPCAdapter<never>, "runWithServices">;
17
+ readonly createCaller: CreateCaller;
18
+ readonly extend?: (base: Readonly<{
19
+ db: DatabaseService<Database>;
20
+ trpc: EffectCallerFactory<CallerOptions<NoInfer<CreateCaller>>, CallerResult<NoInfer<CreateCaller>>>;
21
+ }>, context: TestContext) => Effect.Effect<Extension, unknown, Provided | DatabaseRequirement<Database> | Effect.Services<Database>>;
22
+ readonly layer: Layer.Layer<Provided, LayerError>;
23
+ }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EACX,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE5C,MAAM,MAAM,eAAe,CAC1B,QAAQ,SAAS,WAAW,EAC5B,OAAO,EACP,MAAM,EACN,SAAS,IACN,QAAQ,CAAC;IACZ,EAAE,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC9B,IAAI,EAAE,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC,GACD,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,IAAI,eAAe,CAC5D,OAAO,EACP,QAAQ,CACR,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,OAAO,EAAE,QAAQ,IAAI,iBAAiB,CAChE,OAAO,EACP,QAAQ,CACR,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC,OAAO,GAAG;IAC5D,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,WAAW,qBAAqB,CACrC,QAAQ,SAAS,WAAW,EAC5B,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EACvD,QAAQ,EACR,UAAU,EACV,SAAS;IAET,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC,CAAC;IACpE,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,CACjB,IAAI,EAAE,QAAQ,CAAC;QACd,EAAE,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAI,EAAE,mBAAmB,CACxB,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EACpC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CACnC,CAAC;KACF,CAAC,EACF,OAAO,EAAE,WAAW,KAChB,MAAM,CAAC,MAAM,CACjB,SAAS,EACT,OAAO,EACP,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACpE,CAAC;IACF,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CAClD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { type AnyDatabase, type DatabaseRequirement } from "@shivaedev/effect-prisma/testing";
2
+ import { type CallerOptions, type CallerResult } from "@shivaedev/effect-trpc/testing";
3
+ import { Effect, type Layer } from "effect";
4
+ import type { MakePlatformItOptions, PlatformHarness, PlatformIt } from "./types.js";
5
+ export declare const makePlatformIt: <const Database extends AnyDatabase>(database: Database) => <CreateCaller extends (...arguments_: never[]) => object, Provided, LayerError, Extension extends object = Record<never, never>>(options: MakePlatformItOptions<Database, CreateCaller, Provided, LayerError, Extension> & {
6
+ readonly layer: Layer.Layer<Provided | DatabaseRequirement<Database> | Effect.Services<Database>, LayerError>;
7
+ }) => PlatformIt<PlatformHarness<Database, CallerOptions<CreateCaller>, CallerResult<CreateCaller>, Extension>, Provided | DatabaseRequirement<Database> | Effect.Services<Database>>;
8
+ //# sourceMappingURL=vitest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAGxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EAGjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EACX,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,cAAc,GACzB,KAAK,CAAC,QAAQ,SAAS,WAAW,EAAE,UAAU,QAAQ,MAEtD,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EACvD,QAAQ,EACR,UAAU,EACV,SAAS,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE/C,SAAS,qBAAqB,CAC7B,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,CACT,GAAG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAC1B,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACpE,UAAU,CACV,CAAC;CACF,KACC,UAAU,CACZ,eAAe,CACd,QAAQ,EACR,aAAa,CAAC,YAAY,CAAC,EAC3B,YAAY,CAAC,YAAY,CAAC,EAC1B,SAAS,CACT,EACD,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CA+CpE,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { withTestTransaction, } from "@shivaedev/effect-prisma/testing";
2
+ import { makeTrpcHarnessIt, } from "@shivaedev/effect-trpc/testing";
3
+ import { Effect } from "effect";
4
+ export const makePlatformIt = (database) => (options) => {
5
+ const trpcIt = makeTrpcHarnessIt({
6
+ adapter: options.adapter,
7
+ createCaller: options.createCaller,
8
+ layer: options.layer,
9
+ around: (effect) => withTestTransaction(database, effect),
10
+ makeHarness: (trpc, context) => Effect.gen(function* () {
11
+ const databaseEffect = database;
12
+ const db = yield* databaseEffect;
13
+ const extension = options.extend
14
+ ? yield* options.extend({ db, trpc }, context)
15
+ : {};
16
+ return { ...extension, db, trpc };
17
+ }),
18
+ });
19
+ return new Proxy(trpcIt, {
20
+ get(target, property, receiver) {
21
+ if (property === "effectApp") {
22
+ return trpcIt.effectTRPC;
23
+ }
24
+ return Reflect.get(target, property, receiver);
25
+ },
26
+ });
27
+ };
28
+ //# sourceMappingURL=vitest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,mBAAmB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAIN,iBAAiB,GACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAO5C,MAAM,CAAC,MAAM,cAAc,GAC1B,CAAqC,QAAkB,EAAE,EAAE,CAC3D,CAMC,OAWC,EASA,EAAE;IASH,MAAM,MAAM,GAAG,iBAAiB,CAI9B;QACD,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC;QACzD,WAAW,EAAE,CACZ,IAA0C,EAC1C,OAAO,EACqC,EAAE,CAC9C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,cAAc,GAAG,QAItB,CAAC;YACF,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;YACjC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM;gBAC/B,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC;gBAC9C,CAAC,CAAE,EAAgB,CAAC;YACrB,OAAO,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,IAAI,EAAa,CAAC;QAC9C,CAAC,CAA8C;KAChD,CAAC,CAAC;IAEH,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACxB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ;YAC7B,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;gBAC9B,OAAO,MAAM,CAAC,UAAU,CAAC;YAC1B,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;KACD,CAEiC,CAAC;AACpC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { MakePlatformItOptions, PlatformHarness, PlatformIt, PlatformTest, PlatformTester, } from "./testing/types.js";
2
+ export { makePlatformIt } from "./testing/vitest.js";
3
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { makePlatformIt } from "./testing/vitest.js";
2
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,70 @@
1
1
  {
2
2
  "name": "@shivaedev/platform",
3
- "version": "0.0.0",
4
- "description": "Opinionated Effect application setup for ShivaeDev services",
3
+ "version": "0.1.0",
4
+ "description": "Opinionated Effect application testing for ShivaeDev services",
5
+ "type": "module",
5
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ShivaeDev/platform.git",
10
+ "directory": "packages/platform"
11
+ },
12
+ "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/platform#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/ShivaeDev/platform/issues"
15
+ },
16
+ "engines": {
17
+ "node": ">=24"
18
+ },
19
+ "sideEffects": false,
6
20
  "files": [
21
+ "dist",
22
+ "src",
23
+ "CHANGELOG.md",
7
24
  "README.md"
8
25
  ],
26
+ "exports": {
27
+ "./testing": {
28
+ "types": "./dist/testing.d.ts",
29
+ "source": "./src/testing.ts",
30
+ "import": "./dist/testing.js",
31
+ "default": "./dist/testing.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
9
35
  "publishConfig": {
10
- "access": "public"
36
+ "access": "public",
37
+ "provenance": true
38
+ },
39
+ "peerDependencies": {
40
+ "@effect/vitest": "4.0.0-beta.102",
41
+ "@shivaedev/effect-prisma": "0.3.0",
42
+ "@shivaedev/effect-trpc": "0.2.0",
43
+ "@trpc/server": "11.18.0",
44
+ "effect": "4.0.0-beta.102"
45
+ },
46
+ "devDependencies": {
47
+ "@effect/vitest": "4.0.0-beta.102",
48
+ "@prisma-next/adapter-postgres": "0.15.0",
49
+ "@prisma-next/contract": "0.15.0",
50
+ "@prisma-next/sql-contract": "0.15.0",
51
+ "@prisma-next/target-postgres": "0.15.0",
52
+ "@shivaedev/effect-prisma": "0.3.0",
53
+ "@shivaedev/effect-trpc": "0.2.0",
54
+ "@trpc/server": "11.18.0",
55
+ "@types/node": "24.10.1",
56
+ "@typescript/native": "npm:typescript@7.0.2",
57
+ "effect": "4.0.0-beta.102",
58
+ "typescript": "npm:@typescript/typescript6@6.0.2",
59
+ "vitest": "4.1.9"
60
+ },
61
+ "scripts": {
62
+ "build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc6 --project tsconfig.build.json",
63
+ "check": "biome check .",
64
+ "test": "vitest run",
65
+ "test:package": "node scripts/test-package.mjs",
66
+ "typecheck": "tsc --noEmit",
67
+ "typecheck:compat": "tsc6 --noEmit",
68
+ "ready": "pnpm check && pnpm typecheck && pnpm typecheck:compat && pnpm test && pnpm build && pnpm test:package"
11
69
  }
12
70
  }
@@ -0,0 +1,66 @@
1
+ import type { TestContext, Vitest } from "@effect/vitest";
2
+ import type {
3
+ AnyDatabase,
4
+ DatabaseRequirement,
5
+ DatabaseService,
6
+ } from "@shivaedev/effect-prisma/testing";
7
+ import type { EffectTRPCAdapter } from "@shivaedev/effect-trpc";
8
+ import type {
9
+ CallerOptions,
10
+ CallerResult,
11
+ EffectCallerFactory,
12
+ TrpcHarnessTest,
13
+ TrpcHarnessTester,
14
+ } from "@shivaedev/effect-trpc/testing";
15
+ import type { Effect, Layer } from "effect";
16
+
17
+ export type PlatformHarness<
18
+ Database extends AnyDatabase,
19
+ Options,
20
+ Caller,
21
+ Extension,
22
+ > = Readonly<{
23
+ db: DatabaseService<Database>;
24
+ trpc: EffectCallerFactory<Options, Caller>;
25
+ }> &
26
+ Omit<Extension, "db" | "trpc">;
27
+
28
+ export type PlatformTest<Harness, Provided> = TrpcHarnessTest<
29
+ Harness,
30
+ Provided
31
+ >;
32
+
33
+ export type PlatformTester<Harness, Provided> = TrpcHarnessTester<
34
+ Harness,
35
+ Provided
36
+ >;
37
+
38
+ export type PlatformIt<Harness, Provided> = Vitest.Methods & {
39
+ readonly effectApp: PlatformTester<Harness, Provided>;
40
+ };
41
+
42
+ export interface MakePlatformItOptions<
43
+ Database extends AnyDatabase,
44
+ CreateCaller extends (...arguments_: never[]) => object,
45
+ Provided,
46
+ LayerError,
47
+ Extension,
48
+ > {
49
+ readonly adapter: Pick<EffectTRPCAdapter<never>, "runWithServices">;
50
+ readonly createCaller: CreateCaller;
51
+ readonly extend?: (
52
+ base: Readonly<{
53
+ db: DatabaseService<Database>;
54
+ trpc: EffectCallerFactory<
55
+ CallerOptions<NoInfer<CreateCaller>>,
56
+ CallerResult<NoInfer<CreateCaller>>
57
+ >;
58
+ }>,
59
+ context: TestContext,
60
+ ) => Effect.Effect<
61
+ Extension,
62
+ unknown,
63
+ Provided | DatabaseRequirement<Database> | Effect.Services<Database>
64
+ >;
65
+ readonly layer: Layer.Layer<Provided, LayerError>;
66
+ }
@@ -0,0 +1,95 @@
1
+ import type { Vitest } from "@effect/vitest";
2
+ import {
3
+ type AnyDatabase,
4
+ type DatabaseRequirement,
5
+ type DatabaseService,
6
+ withTestTransaction,
7
+ } from "@shivaedev/effect-prisma/testing";
8
+ import {
9
+ type CallerOptions,
10
+ type CallerResult,
11
+ type EffectCallerFactory,
12
+ makeTrpcHarnessIt,
13
+ } from "@shivaedev/effect-trpc/testing";
14
+ import { Effect, type Layer } from "effect";
15
+ import type {
16
+ MakePlatformItOptions,
17
+ PlatformHarness,
18
+ PlatformIt,
19
+ } from "./types.js";
20
+
21
+ export const makePlatformIt =
22
+ <const Database extends AnyDatabase>(database: Database) =>
23
+ <
24
+ CreateCaller extends (...arguments_: never[]) => object,
25
+ Provided,
26
+ LayerError,
27
+ Extension extends object = Record<never, never>,
28
+ >(
29
+ options: MakePlatformItOptions<
30
+ Database,
31
+ CreateCaller,
32
+ Provided,
33
+ LayerError,
34
+ Extension
35
+ > & {
36
+ readonly layer: Layer.Layer<
37
+ Provided | DatabaseRequirement<Database> | Effect.Services<Database>,
38
+ LayerError
39
+ >;
40
+ },
41
+ ): PlatformIt<
42
+ PlatformHarness<
43
+ Database,
44
+ CallerOptions<CreateCaller>,
45
+ CallerResult<CreateCaller>,
46
+ Extension
47
+ >,
48
+ Provided | DatabaseRequirement<Database> | Effect.Services<Database>
49
+ > => {
50
+ type Options = CallerOptions<CreateCaller>;
51
+ type Caller = CallerResult<CreateCaller>;
52
+ type Services =
53
+ | Provided
54
+ | DatabaseRequirement<Database>
55
+ | Effect.Services<Database>;
56
+ type Harness = PlatformHarness<Database, Options, Caller, Extension>;
57
+
58
+ const trpcIt = makeTrpcHarnessIt<
59
+ CreateCaller,
60
+ Layer.Layer<Services, LayerError>,
61
+ Harness
62
+ >({
63
+ adapter: options.adapter,
64
+ createCaller: options.createCaller,
65
+ layer: options.layer,
66
+ around: (effect) => withTestTransaction(database, effect),
67
+ makeHarness: (
68
+ trpc: EffectCallerFactory<Options, Caller>,
69
+ context,
70
+ ): Effect.Effect<Harness, unknown, Services> =>
71
+ Effect.gen(function* () {
72
+ const databaseEffect = database as unknown as Effect.Effect<
73
+ DatabaseService<Database>,
74
+ never,
75
+ Effect.Services<Database>
76
+ >;
77
+ const db = yield* databaseEffect;
78
+ const extension = options.extend
79
+ ? yield* options.extend({ db, trpc }, context)
80
+ : ({} as Extension);
81
+ return { ...extension, db, trpc } as Harness;
82
+ }) as Effect.Effect<Harness, unknown, Services>,
83
+ });
84
+
85
+ return new Proxy(trpcIt, {
86
+ get(target, property, receiver) {
87
+ if (property === "effectApp") {
88
+ return trpcIt.effectTRPC;
89
+ }
90
+ return Reflect.get(target, property, receiver);
91
+ },
92
+ }) as unknown as Vitest.Methods & {
93
+ readonly effectApp: typeof trpcIt.effectTRPC;
94
+ } as PlatformIt<Harness, Services>;
95
+ };
package/src/testing.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type {
2
+ MakePlatformItOptions,
3
+ PlatformHarness,
4
+ PlatformIt,
5
+ PlatformTest,
6
+ PlatformTester,
7
+ } from "./testing/types.js";
8
+ export { makePlatformIt } from "./testing/vitest.js";