@@ -37,11 +37,34 @@ remain compatible. Database access uses Prisma 7 with the PostgreSQL driver
3737adapter. Domain events continue to be sent through the existing Bus API wrapper;
3838this service does not connect to Kafka directly.
3939
40- The API runtime client is Prisma 7. The checked-in
41- ` packages/challenge-prisma-client ` artifact remains on Prisma 6 for its existing
42- downstream consumers, so the root generation command intentionally targets only
43- the API client. Upgrading that shared artifact requires a coordinated downstream
44- release.
40+ The API runtime client and the checked-in external client use Prisma 7. The
41+ external client has a stable package wrapper at
42+ ` packages/challenge-prisma-client ` ; generated Prisma files live below its
43+ ` generated ` directory so regeneration cannot overwrite the public contract.
44+
45+ ## External Prisma client
46+
47+ Services that need to aggregate challenge data directly can install the
48+ ` packages/challenge-prisma-client ` Git subdirectory as
49+ ` @topcoder/challenge-api-v6 ` . The package exports all generated challenge
50+ models, enums, Prisma helpers, and ` PrismaClient ` , plus this supported factory:
51+
52+ ``` ts
53+ import { createChallengePrismaClient } from ' @topcoder/challenge-api-v6' ;
54+
55+ const challenges = createChallengePrismaClient (process .env .CHALLENGE_DATABASE_URL , {
56+ log: [' warn' , ' error' ],
57+ });
58+ ```
59+
60+ ` createChallengePrismaClient(connectionString, options?) ` creates a Prisma 7
61+ PostgreSQL driver adapter, preserves the optional ` schema ` query parameter in
62+ the connection URL, and returns a disconnected client that connects lazily on
63+ its first query. Call ` $disconnect() ` during application shutdown. The factory
64+ throws ` TypeError ` when ` connectionString ` is empty or not a string; Prisma may
65+ raise its normal configuration and database errors while creating or using the
66+ client. Connection-defining ` adapter ` and ` accelerateUrl ` options are owned by
67+ the factory and intentionally excluded from its options type.
4568
4669## Configuration
4770
@@ -90,7 +113,7 @@ configuration parameters.
90113Run ` nvm use ` before pnpm commands. Make sure ` DATABASE_URL ` is set before any
91114database operation or application startup.
92115
93- 1 . Install dependencies and generate the Prisma client : ` pnpm install `
116+ 1 . Install dependencies and generate both Prisma clients : ` pnpm install `
941172 . Build the API: ` pnpm build `
951183 . Create or update local database tables: ` pnpm create-tables `
961194 . Seed tables: ` pnpm seed-tables `
@@ -130,7 +153,8 @@ database operation or application startup.
130153 DATABASE_URL=
131154 ```
132155
133- Then run ` pnpm install ` . The postinstall hook generates the Prisma 7 client.
156+ Then run ` pnpm install ` . The postinstall hook generates both the internal and
157+ external Prisma 7 clients.
134158
1351592 . 🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally
136160
@@ -239,6 +263,13 @@ To run unit tests alone
239263pnpm test
240264```
241265
266+ To smoke-test the packaged external Prisma factory without connecting to a
267+ database:
268+
269+ ``` bash
270+ pnpm test:external-client
271+ ```
272+
242273To run unit tests with coverage report
243274
244275``` bash
0 commit comments