@baeta/plugin-prisma 2.0.0-next.14 → 2.0.0-next.15
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 +10 -0
- package/README.md +29 -22
- package/dist/index.d.ts +1 -3
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @baeta/plugin-prisma
|
|
2
2
|
|
|
3
|
+
## 2.0.0-next.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Drop Node v23 and v25 by [@andreisergiu98](https://github.com/andreisergiu98) in [#474](https://github.com/andreisergiu98/baeta/pull/474)
|
|
8
|
+
- Updated dependencies [[`dc89e17`](https://github.com/andreisergiu98/baeta/commit/dc89e1728926f4bd5a5e1351635c38bf8d5938dc), [`1249b32`](https://github.com/andreisergiu98/baeta/commit/1249b32c42270151d6d6de46d54c82c1f975719b), [`3571c17`](https://github.com/andreisergiu98/baeta/commit/3571c1785a4eb1361c47b80725c990cefa27a791), [`d179c12`](https://github.com/andreisergiu98/baeta/commit/d179c12488f6ac11add26f8337e088f791d820b7), [`03c2bc9`](https://github.com/andreisergiu98/baeta/commit/03c2bc9913b6ffdc15f627f9d177347e0805defd)]:
|
|
9
|
+
- @baeta/generator-sdk@2.0.0-next.6
|
|
10
|
+
- @baeta/plugin-exec@2.0.0-next.15
|
|
11
|
+
- @baeta/util-path@2.0.0-next.5
|
|
12
|
+
|
|
3
13
|
## 2.0.0-next.14
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -35,10 +35,11 @@ Building GraphQL APIs shouldn't be complicated. **Baeta** is a modern, modular,
|
|
|
35
35
|
- **Middleware & Directives**: Easy integration of custom behaviors
|
|
36
36
|
- **High Performance**: Built for scalability and efficiency
|
|
37
37
|
|
|
38
|
-
#### And optional
|
|
38
|
+
#### And optional app plugins and libraries
|
|
39
39
|
|
|
40
|
-
- **@baeta/
|
|
41
|
-
- **@baeta/
|
|
40
|
+
- **@baeta/auth**: Add powerful scope-based authorization
|
|
41
|
+
- **@baeta/complexity**: Reject resource-exhausting queries with depth, breadth and complexity limits
|
|
42
|
+
- **@baeta/cache**: Type-safe caching with declarative queries and automatic reconciliation
|
|
42
43
|
- ... and more!
|
|
43
44
|
|
|
44
45
|
## Why use Baeta?
|
|
@@ -89,7 +90,7 @@ const usersQuery = Query.users.resolve(() => {
|
|
|
89
90
|
return dataSource.user.findMany();
|
|
90
91
|
});
|
|
91
92
|
|
|
92
|
-
Query.$fields({
|
|
93
|
+
export default Query.$fields({
|
|
93
94
|
user: userQuery,
|
|
94
95
|
users: usersQuery,
|
|
95
96
|
});
|
|
@@ -98,17 +99,13 @@ Query.$fields({
|
|
|
98
99
|
#### 3. Add authorization
|
|
99
100
|
|
|
100
101
|
```typescript
|
|
102
|
+
import { auth, rule, scope } from "./lib/auth.ts";
|
|
101
103
|
import { UserModule } from "./typedef.ts";
|
|
102
104
|
|
|
103
105
|
const { Query } = UserModule;
|
|
104
106
|
|
|
105
107
|
const userQuery = Query.user
|
|
106
|
-
.$auth(
|
|
107
|
-
$or: {
|
|
108
|
-
isPublic: true,
|
|
109
|
-
isLoggedIn: true,
|
|
110
|
-
},
|
|
111
|
-
})
|
|
108
|
+
.$use(auth(rule.or(scope.isPublic, scope.isLoggedIn)))
|
|
112
109
|
.resolve(async ({ args }) => {
|
|
113
110
|
// ...
|
|
114
111
|
});
|
|
@@ -117,23 +114,33 @@ const userQuery = Query.user
|
|
|
117
114
|
#### 4. Add caching
|
|
118
115
|
|
|
119
116
|
```typescript
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
import { createCache, defineQuery } from "@baeta/cache";
|
|
118
|
+
import { redisClient } from "./lib/redis.ts";
|
|
119
|
+
|
|
120
|
+
const { Query, Mutation } = UserModule;
|
|
121
|
+
|
|
122
|
+
export const userCache = createCache(redisClient, {
|
|
123
|
+
name: "UserCache",
|
|
124
|
+
parse: JSON.parse,
|
|
125
|
+
serialize: JSON.stringify,
|
|
126
|
+
})
|
|
127
|
+
.withQueries({
|
|
128
|
+
findUser: defineQuery({
|
|
129
|
+
resolve: async (args: { id: string }) => {
|
|
130
|
+
return dataSource.user.findUnique({ where: args });
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
127
133
|
})
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})
|
|
134
|
+
.build();
|
|
135
|
+
|
|
136
|
+
const userQuery = Query.user.map(({ args }) =>
|
|
137
|
+
userCache.queries.findUser({ id: args.where.id }),
|
|
138
|
+
);
|
|
132
139
|
|
|
133
140
|
const updateUserMutation = Mutation.updateUser
|
|
134
141
|
.$use(async (next) => {
|
|
135
142
|
const user = await next();
|
|
136
|
-
await userCache.
|
|
143
|
+
if (user) await userCache.update(user);
|
|
137
144
|
return user;
|
|
138
145
|
})
|
|
139
146
|
.resolve(async ({ args }) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as _$_baeta_generator_sdk0 from "@baeta/generator-sdk";
|
|
2
|
-
|
|
3
1
|
//#region lib/options.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Configuration options for the Prisma plugin
|
|
@@ -36,7 +34,7 @@ interface PrismaPluginOptions {
|
|
|
36
34
|
* @param options - Configuration options for the pagination plugin
|
|
37
35
|
* @returns A Baeta generator plugin
|
|
38
36
|
*/
|
|
39
|
-
declare function prismaPlugin(options: PrismaPluginOptions):
|
|
37
|
+
declare function prismaPlugin(options: PrismaPluginOptions): import("@baeta/generator-sdk").GeneratorPluginV1<unknown>[];
|
|
40
38
|
//#endregion
|
|
41
39
|
export { type PrismaPluginOptions, prismaPlugin as default, prismaPlugin };
|
|
42
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../lib/client-generator.ts","../index.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { Ctx, WatcherFile } from '@baeta/generator-sdk';\nimport { createExecPlugin } from '@baeta/plugin-exec';\nimport { resolve } from '@baeta/util-path';\nimport type { PrismaPluginOptions } from './options.ts';\n\nasync function compareSchemas(cwd: string, current: string, generated: string) {\n\tconst [currentSchema, generatedSchema] = await Promise.all([\n\t\treadFile(resolve(cwd, current), 'utf-8'),\n\t\treadFile(resolve(cwd, generated), 'utf-8').catch(() => null),\n\t]);\n\treturn currentSchema.replaceAll(' ', '') === generatedSchema?.replaceAll(' ', '');\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\treturn createExecPlugin({\n\t\tname: 'prisma-client',\n\t\tactionName: 'Prisma client',\n\t\texec: generateCommand ?? 'prisma generate',\n\t\twatch: (generatorOptions, watcher, reload) => {\n\t\t\tconst prismaPath = resolve(generatorOptions.cwd, prismaSchema);\n\n\t\t\tconst handleChange = (file: WatcherFile) => {\n\t\t\t\tif (file.path === prismaPath) {\n\t\t\t\t\treload(file);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\twatcher.on('update', handleChange);\n\t\t\twatcher.on('delete', handleChange);\n\t\t},\n\t\tskip: async (ctx: Ctx) => {\n\t\t\tconst schema = resolve(ctx.generatorOptions.cwd, prismaSchema);\n\n\t\t\tif (ctx.watching && ctx.changedFile?.path !== schema) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif (!ctx.watching && generatedSchemaPath) {\n\t\t\t\treturn await compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t});\n}\n","import { createPrismaClientPlugin } from './lib/client-generator.ts';\nimport type { PrismaPluginOptions } from './lib/options.ts';\n\nexport type { PrismaPluginOptions } from './lib/options.ts';\n\nexport default prismaPlugin;\n\n/**\n * A plugin that manages Prisma client generation in your Baeta project.\n * See https://baeta.io/docs/plugins/prisma\n *\n * @param options - Configuration options for the pagination plugin\n * @returns A Baeta generator plugin\n */\nexport function prismaPlugin(options: PrismaPluginOptions) {\n\tif (options.generateClient === false) {\n\t\treturn [];\n\t}\n\treturn [createPrismaClientPlugin(options)];\n}\n"],"mappings":";;;;AAMA,eAAe,eAAe,KAAa,SAAiB,WAAmB;CAC9E,MAAM,CAAC,eAAe,mBAAmB,MAAM,QAAQ,IAAI,CAC1D,SAAS,QAAQ,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../lib/client-generator.ts","../index.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { Ctx, WatcherFile } from '@baeta/generator-sdk';\nimport { createExecPlugin } from '@baeta/plugin-exec';\nimport { resolve } from '@baeta/util-path';\nimport type { PrismaPluginOptions } from './options.ts';\n\nasync function compareSchemas(cwd: string, current: string, generated: string) {\n\tconst [currentSchema, generatedSchema] = await Promise.all([\n\t\treadFile(resolve(cwd, current), 'utf-8'),\n\t\treadFile(resolve(cwd, generated), 'utf-8').catch(() => null),\n\t]);\n\treturn currentSchema.replaceAll(' ', '') === generatedSchema?.replaceAll(' ', '');\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\treturn createExecPlugin({\n\t\tname: 'prisma-client',\n\t\tactionName: 'Prisma client',\n\t\texec: generateCommand ?? 'prisma generate',\n\t\twatch: (generatorOptions, watcher, reload) => {\n\t\t\tconst prismaPath = resolve(generatorOptions.cwd, prismaSchema);\n\n\t\t\tconst handleChange = (file: WatcherFile) => {\n\t\t\t\tif (file.path === prismaPath) {\n\t\t\t\t\treload(file);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\twatcher.on('update', handleChange);\n\t\t\twatcher.on('delete', handleChange);\n\t\t},\n\t\tskip: async (ctx: Ctx) => {\n\t\t\tconst schema = resolve(ctx.generatorOptions.cwd, prismaSchema);\n\n\t\t\tif (ctx.watching && ctx.changedFile?.path !== schema) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif (!ctx.watching && generatedSchemaPath) {\n\t\t\t\treturn await compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t});\n}\n","import { createPrismaClientPlugin } from './lib/client-generator.ts';\nimport type { PrismaPluginOptions } from './lib/options.ts';\n\nexport type { PrismaPluginOptions } from './lib/options.ts';\n\nexport default prismaPlugin;\n\n/**\n * A plugin that manages Prisma client generation in your Baeta project.\n * See https://baeta.io/docs/plugins/prisma\n *\n * @param options - Configuration options for the pagination plugin\n * @returns A Baeta generator plugin\n */\nexport function prismaPlugin(options: PrismaPluginOptions) {\n\tif (options.generateClient === false) {\n\t\treturn [];\n\t}\n\treturn [createPrismaClientPlugin(options)];\n}\n"],"mappings":";;;;AAMA,eAAe,eAAe,KAAa,SAAiB,WAAmB;CAC9E,MAAM,CAAC,eAAe,mBAAmB,MAAM,QAAQ,IAAI,CAC1D,SAAS,QAAQ,KAAK,OAAO,GAAG,OAAO,GACvC,SAAS,QAAQ,KAAK,SAAS,GAAG,OAAO,EAAE,YAAY,IAAI,CAC5D,CAAC;CACD,OAAO,cAAc,WAAW,KAAK,EAAE,MAAM,iBAAiB,WAAW,KAAK,EAAE;AACjF;AAEA,SAAgB,yBAAyB,SAA8B;CACtE,MAAM,EAAE,cAAc,iBAAiB,wBAAwB;CAE/D,OAAO,iBAAiB;EACvB,MAAM;EACN,YAAY;EACZ,MAAM,mBAAmB;EACzB,QAAQ,kBAAkB,SAAS,WAAW;GAC7C,MAAM,aAAa,QAAQ,iBAAiB,KAAK,YAAY;GAE7D,MAAM,gBAAgB,SAAsB;IAC3C,IAAI,KAAK,SAAS,YACjB,OAAO,IAAI;GAEb;GAEA,QAAQ,GAAG,UAAU,YAAY;GACjC,QAAQ,GAAG,UAAU,YAAY;EAClC;EACA,MAAM,OAAO,QAAa;GACzB,MAAM,SAAS,QAAQ,IAAI,iBAAiB,KAAK,YAAY;GAE7D,IAAI,IAAI,YAAY,IAAI,aAAa,SAAS,QAC7C,OAAO;GAGR,IAAI,CAAC,IAAI,YAAY,qBACpB,OAAO,MAAM,eAAe,IAAI,iBAAiB,KAAK,cAAc,mBAAmB;GAGxF,OAAO;EACR;CACD,CAAC;AACF;;;AC1CA,IAAA,wBAAe;;;;;;;;AASf,SAAgB,aAAa,SAA8B;CAC1D,IAAI,QAAQ,mBAAmB,OAC9B,OAAO,CAAC;CAET,OAAO,CAAC,yBAAyB,OAAO,CAAC;AAC1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/plugin-prisma",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.15",
|
|
4
|
+
"description": "Prisma integration plugin for Baeta.",
|
|
4
5
|
"keywords": [
|
|
5
6
|
"baeta",
|
|
6
7
|
"builder",
|
|
@@ -21,14 +22,14 @@
|
|
|
21
22
|
},
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/andreisergiu98/baeta.git",
|
|
25
|
+
"url": "git+https://github.com/andreisergiu98/baeta.git",
|
|
25
26
|
"directory": "packages/plugin-prisma"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
|
-
"dist"
|
|
29
|
-
"package.json"
|
|
29
|
+
"dist"
|
|
30
30
|
],
|
|
31
31
|
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
32
33
|
"types": "dist/index.d.ts",
|
|
33
34
|
"exports": {
|
|
34
35
|
".": {
|
|
@@ -37,13 +38,13 @@
|
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
"publishConfig": {
|
|
40
|
-
"access": "public",
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|
|
43
43
|
"types": "./dist/index.d.ts",
|
|
44
44
|
"default": "./dist/index.js"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"access": "public"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"build": "builder build",
|
|
@@ -54,9 +55,9 @@
|
|
|
54
55
|
"types": "tsc --noEmit"
|
|
55
56
|
},
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@baeta/generator-sdk": "^2.0.0-next.
|
|
58
|
-
"@baeta/plugin-exec": "^2.0.0-next.
|
|
59
|
-
"@baeta/util-path": "^2.0.0-next.
|
|
58
|
+
"@baeta/generator-sdk": "^2.0.0-next.6",
|
|
59
|
+
"@baeta/plugin-exec": "^2.0.0-next.15",
|
|
60
|
+
"@baeta/util-path": "^2.0.0-next.5"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@baeta/builder": "^0.0.0",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
]
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|
|
74
|
-
"node": "
|
|
75
|
+
"node": "^22.20.0 || ^24.0.0 || >=26.0.0"
|
|
75
76
|
},
|
|
76
77
|
"typedocOptions": {
|
|
77
78
|
"entryPoints": [
|