@opensaas/stack-cli 0.3.0 → 0.4.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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +141 -0
  3. package/dist/commands/generate.d.ts.map +1 -1
  4. package/dist/commands/generate.js +4 -13
  5. package/dist/commands/generate.js.map +1 -1
  6. package/dist/generator/context.d.ts.map +1 -1
  7. package/dist/generator/context.js +20 -5
  8. package/dist/generator/context.js.map +1 -1
  9. package/dist/generator/index.d.ts +1 -1
  10. package/dist/generator/index.d.ts.map +1 -1
  11. package/dist/generator/index.js +1 -1
  12. package/dist/generator/index.js.map +1 -1
  13. package/dist/generator/lists.d.ts.map +1 -1
  14. package/dist/generator/lists.js +33 -1
  15. package/dist/generator/lists.js.map +1 -1
  16. package/dist/generator/prisma-extensions.d.ts +11 -0
  17. package/dist/generator/prisma-extensions.d.ts.map +1 -0
  18. package/dist/generator/prisma-extensions.js +134 -0
  19. package/dist/generator/prisma-extensions.js.map +1 -0
  20. package/dist/generator/prisma.d.ts.map +1 -1
  21. package/dist/generator/prisma.js +4 -0
  22. package/dist/generator/prisma.js.map +1 -1
  23. package/dist/generator/types.d.ts.map +1 -1
  24. package/dist/generator/types.js +151 -17
  25. package/dist/generator/types.js.map +1 -1
  26. package/package.json +9 -9
  27. package/src/commands/__snapshots__/generate.test.ts.snap +92 -21
  28. package/src/commands/generate.ts +8 -19
  29. package/src/generator/__snapshots__/context.test.ts.snap +60 -15
  30. package/src/generator/__snapshots__/types.test.ts.snap +689 -95
  31. package/src/generator/context.test.ts +3 -1
  32. package/src/generator/context.ts +20 -5
  33. package/src/generator/index.ts +1 -1
  34. package/src/generator/lists.ts +39 -1
  35. package/src/generator/prisma-extensions.ts +159 -0
  36. package/src/generator/prisma.ts +5 -0
  37. package/src/generator/types.ts +204 -17
  38. package/tsconfig.tsbuildinfo +1 -1
  39. package/dist/generator/type-patcher.d.ts +0 -13
  40. package/dist/generator/type-patcher.d.ts.map +0 -1
  41. package/dist/generator/type-patcher.js +0 -68
  42. package/dist/generator/type-patcher.js.map +0 -1
  43. package/src/generator/type-patcher.ts +0 -93
@@ -14,6 +14,7 @@ import { getContext as getOpensaasContext } from '@opensaas/stack-core'
14
14
  import type { Session as OpensaasSession, OpenSaasConfig } from '@opensaas/stack-core'
15
15
  import { PrismaClient } from './prisma-client/client'
16
16
  import type { Context } from './types'
17
+ import { prismaExtensions } from './prisma-extensions'
17
18
  import configOrPromise from '../opensaas.config'
18
19
 
19
20
  // Resolve config if it's a Promise (when plugins are present)
@@ -21,15 +22,29 @@ const configPromise = Promise.resolve(configOrPromise)
21
22
  let resolvedConfig: OpenSaasConfig | null = null
22
23
 
23
24
  // Internal Prisma singleton - managed automatically
24
- const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | null }
25
- let prisma: PrismaClient | null = null
25
+ const globalForPrisma = globalThis as unknown as { prisma: ReturnType<typeof createExtendedPrisma> | null }
26
+ let prisma: ReturnType<typeof createExtendedPrisma> | null = null
27
+
28
+ /**
29
+ * Create Prisma client with result extensions
30
+ */
31
+ function createExtendedPrisma(basePrisma: PrismaClient) {
32
+ // Check if there are any extensions to apply
33
+ if (Object.keys(prismaExtensions).length === 0) {
34
+ return basePrisma
35
+ }
36
+ // Apply result extensions
37
+ return basePrisma.$extends(prismaExtensions)
38
+ }
26
39
 
27
40
  async function getPrisma() {
28
41
  if (!prisma) {
29
42
  if (!resolvedConfig) {
30
43
  resolvedConfig = await configPromise
31
44
  }
32
- prisma = globalForPrisma.prisma ?? resolvedConfig.db.prismaClientConstructor!(PrismaClient)
45
+ const basePrisma = resolvedConfig.db.prismaClientConstructor!(PrismaClient)
46
+ const extendedPrisma = createExtendedPrisma(basePrisma)
47
+ prisma = globalForPrisma.prisma ?? extendedPrisma
33
48
  if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
34
49
  }
35
50
  return prisma
@@ -84,7 +99,7 @@ const storage = {
84
99
  export async function getContext<TSession extends OpensaasSession = OpensaasSession>(session?: TSession): Promise<Context<TSession>> {
85
100
  const config = await getConfig()
86
101
  const prismaClient = await getPrisma()
87
- return getOpensaasContext(config, prismaClient, session ?? null, storage) as Context<TSession>
102
+ return getOpensaasContext(config, prismaClient, session ?? null, storage) as unknown as Context<TSession>
88
103
  }
89
104
 
90
105
  /**
@@ -94,7 +109,7 @@ export async function getContext<TSession extends OpensaasSession = OpensaasSess
94
109
  export const rawOpensaasContext = (async () => {
95
110
  const config = await getConfig()
96
111
  const prismaClient = await getPrisma()
97
- return getOpensaasContext(config, prismaClient, null, storage)
112
+ return getOpensaasContext(config, prismaClient, null, storage) as unknown as Context
98
113
  })()
99
114
 
100
115
  /**
@@ -119,6 +134,7 @@ import { getContext as getOpensaasContext } from '@opensaas/stack-core'
119
134
  import type { Session as OpensaasSession, OpenSaasConfig } from '@opensaas/stack-core'
120
135
  import { PrismaClient } from './prisma-client/client'
121
136
  import type { Context } from './types'
137
+ import { prismaExtensions } from './prisma-extensions'
122
138
  import configOrPromise from '../opensaas.config'
123
139
 
124
140
  // Resolve config if it's a Promise (when plugins are present)
@@ -126,15 +142,29 @@ const configPromise = Promise.resolve(configOrPromise)
126
142
  let resolvedConfig: OpenSaasConfig | null = null
127
143
 
128
144
  // Internal Prisma singleton - managed automatically
129
- const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | null }
130
- let prisma: PrismaClient | null = null
145
+ const globalForPrisma = globalThis as unknown as { prisma: ReturnType<typeof createExtendedPrisma> | null }
146
+ let prisma: ReturnType<typeof createExtendedPrisma> | null = null
147
+
148
+ /**
149
+ * Create Prisma client with result extensions
150
+ */
151
+ function createExtendedPrisma(basePrisma: PrismaClient) {
152
+ // Check if there are any extensions to apply
153
+ if (Object.keys(prismaExtensions).length === 0) {
154
+ return basePrisma
155
+ }
156
+ // Apply result extensions
157
+ return basePrisma.$extends(prismaExtensions)
158
+ }
131
159
 
132
160
  async function getPrisma() {
133
161
  if (!prisma) {
134
162
  if (!resolvedConfig) {
135
163
  resolvedConfig = await configPromise
136
164
  }
137
- prisma = globalForPrisma.prisma ?? resolvedConfig.db.prismaClientConstructor!(PrismaClient)
165
+ const basePrisma = resolvedConfig.db.prismaClientConstructor!(PrismaClient)
166
+ const extendedPrisma = createExtendedPrisma(basePrisma)
167
+ prisma = globalForPrisma.prisma ?? extendedPrisma
138
168
  if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
139
169
  }
140
170
  return prisma
@@ -189,7 +219,7 @@ const storage = {
189
219
  export async function getContext<TSession extends OpensaasSession = OpensaasSession>(session?: TSession): Promise<Context<TSession>> {
190
220
  const config = await getConfig()
191
221
  const prismaClient = await getPrisma()
192
- return getOpensaasContext(config, prismaClient, session ?? null, storage) as Context<TSession>
222
+ return getOpensaasContext(config, prismaClient, session ?? null, storage) as unknown as Context<TSession>
193
223
  }
194
224
 
195
225
  /**
@@ -199,7 +229,7 @@ export async function getContext<TSession extends OpensaasSession = OpensaasSess
199
229
  export const rawOpensaasContext = (async () => {
200
230
  const config = await getConfig()
201
231
  const prismaClient = await getPrisma()
202
- return getOpensaasContext(config, prismaClient, null, storage)
232
+ return getOpensaasContext(config, prismaClient, null, storage) as unknown as Context
203
233
  })()
204
234
 
205
235
  /**
@@ -224,6 +254,7 @@ import { getContext as getOpensaasContext } from '@opensaas/stack-core'
224
254
  import type { Session as OpensaasSession, OpenSaasConfig } from '@opensaas/stack-core'
225
255
  import { PrismaClient } from './prisma-client/client'
226
256
  import type { Context } from './types'
257
+ import { prismaExtensions } from './prisma-extensions'
227
258
  import configOrPromise from '../opensaas.config'
228
259
 
229
260
  // Resolve config if it's a Promise (when plugins are present)
@@ -231,15 +262,29 @@ const configPromise = Promise.resolve(configOrPromise)
231
262
  let resolvedConfig: OpenSaasConfig | null = null
232
263
 
233
264
  // Internal Prisma singleton - managed automatically
234
- const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | null }
235
- let prisma: PrismaClient | null = null
265
+ const globalForPrisma = globalThis as unknown as { prisma: ReturnType<typeof createExtendedPrisma> | null }
266
+ let prisma: ReturnType<typeof createExtendedPrisma> | null = null
267
+
268
+ /**
269
+ * Create Prisma client with result extensions
270
+ */
271
+ function createExtendedPrisma(basePrisma: PrismaClient) {
272
+ // Check if there are any extensions to apply
273
+ if (Object.keys(prismaExtensions).length === 0) {
274
+ return basePrisma
275
+ }
276
+ // Apply result extensions
277
+ return basePrisma.$extends(prismaExtensions)
278
+ }
236
279
 
237
280
  async function getPrisma() {
238
281
  if (!prisma) {
239
282
  if (!resolvedConfig) {
240
283
  resolvedConfig = await configPromise
241
284
  }
242
- prisma = globalForPrisma.prisma ?? resolvedConfig.db.prismaClientConstructor!(PrismaClient)
285
+ const basePrisma = resolvedConfig.db.prismaClientConstructor!(PrismaClient)
286
+ const extendedPrisma = createExtendedPrisma(basePrisma)
287
+ prisma = globalForPrisma.prisma ?? extendedPrisma
243
288
  if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
244
289
  }
245
290
  return prisma
@@ -294,7 +339,7 @@ const storage = {
294
339
  export async function getContext<TSession extends OpensaasSession = OpensaasSession>(session?: TSession): Promise<Context<TSession>> {
295
340
  const config = await getConfig()
296
341
  const prismaClient = await getPrisma()
297
- return getOpensaasContext(config, prismaClient, session ?? null, storage) as Context<TSession>
342
+ return getOpensaasContext(config, prismaClient, session ?? null, storage) as unknown as Context<TSession>
298
343
  }
299
344
 
300
345
  /**
@@ -304,7 +349,7 @@ export async function getContext<TSession extends OpensaasSession = OpensaasSess
304
349
  export const rawOpensaasContext = (async () => {
305
350
  const config = await getConfig()
306
351
  const prismaClient = await getPrisma()
307
- return getOpensaasContext(config, prismaClient, null, storage)
352
+ return getOpensaasContext(config, prismaClient, null, storage) as unknown as Context
308
353
  })()
309
354
 
310
355
  /**