@baeta/plugin-prisma 2.0.0-next.2 → 2.0.0-next.7

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @baeta/plugin-prisma
2
2
 
3
+ ## 2.0.0-next.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @baeta/plugin-exec@2.0.0-next.7
9
+
10
+ ## 2.0.0-next.3
11
+
12
+ ### Patch Changes
13
+
14
+ - Update generator-sdk package
15
+
16
+ - Updated dependencies [[`6de5d15`](https://github.com/andreisergiu98/baeta/commit/6de5d15484d341a1717a1b2f3f45272912e6a886)]:
17
+ - @baeta/generator-sdk@2.0.0-next.3
18
+ - @baeta/plugin-exec@2.0.0-next.3
19
+
3
20
  ## 2.0.0-next.2
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -77,43 +77,68 @@ type Query {
77
77
  #### 2. Implement your resolvers
78
78
 
79
79
  ```typescript
80
- import { getUserModule } from "./typedef";
80
+ import { UserModule } from "./typedef.ts";
81
81
 
82
- const { Query } = getUserModule();
82
+ const { Query } = UserModule;
83
83
 
84
- Query.user(({ args }) => {
84
+ const userQuery = Query.user.resolve(({ args }) => {
85
85
  return dataSource.user.find(args.where);
86
86
  });
87
87
 
88
- Query.users(() => {
88
+ const usersQuery = Query.users.resolve(() => {
89
89
  return dataSource.user.findMany();
90
90
  });
91
+
92
+ Query.$fields({
93
+ user: userQuery,
94
+ users: usersQuery,
95
+ });
91
96
  ```
92
97
 
93
98
  #### 3. Add authorization
94
99
 
95
100
  ```typescript
96
- const { Query, Mutation } = getUserModule();
97
-
98
- Query.users.$auth({
99
- $or: {
100
- isPublic: true,
101
- isLoggedIn: true,
102
- },
103
- });
101
+ import { UserModule } from "./typedef.ts";
102
+
103
+ const { Query } = UserModule;
104
+
105
+ const userQuery = Query.user
106
+ .auth({
107
+ $or: {
108
+ isPublic: true,
109
+ isLoggedIn: true,
110
+ },
111
+ })
112
+ .resolve(async ({ args }) => {
113
+ // ...
114
+ });
104
115
  ```
105
116
 
106
117
  #### 4. Add caching
107
118
 
108
119
  ```typescript
109
- import { getUserModule } from "./typedef";
110
-
111
- const { User, Query } = getUserModule();
120
+ const { Query, Mutation, User } = UserModule;
112
121
 
113
122
  export const userCache = User.$createCache();
114
123
 
115
- Query.user.$useCache(userCache);
116
- Query.users.$useCache(userCache);
124
+ const userQuery = Query.user
125
+ .auth({
126
+ // ...
127
+ })
128
+ .useCache(userCache)
129
+ .resolve(async ({ args }) => {
130
+ // ...
131
+ });
132
+
133
+ const updateUserMutation = Mutation.updateUser
134
+ .$use(async (next) => {
135
+ const user = await next();
136
+ await userCache.save(user);
137
+ return user;
138
+ })
139
+ .resolve(async ({ args }) => {
140
+ // ...
141
+ });
117
142
  ```
118
143
 
119
144
  ## Compatibility
package/dist/index.d.ts CHANGED
@@ -1,32 +1,34 @@
1
- import * as _baeta_generator_sdk from '@baeta/generator-sdk';
1
+ import * as _baeta_generator_sdk0 from "@baeta/generator-sdk";
2
2
 
3
+ //#region lib/options.d.ts
3
4
  /**
4
5
  * Configuration options for the Prisma plugin
5
6
  */
6
7
  interface PrismaPluginOptions {
7
- /**
8
- * Whether to generate the Prisma client
9
- * @defaultValue true
10
- */
11
- generateClient?: boolean;
12
- /**
13
- * Custom command to generate Prisma client
14
- * @defaultValue 'prisma generate'
15
- */
16
- generateCommand?: string;
17
- /**
18
- * Path to the Prisma schema file
19
- * @example 'prisma/schema.prisma'
20
- */
21
- prismaSchema: string;
22
- /**
23
- * Path to the generated schema file for comparison
24
- * Used to avoid unnecessary regeneration
25
- * @example 'node_modules/@prisma/client/schema.prisma'
26
- */
27
- generatedSchemaPath: string;
8
+ /**
9
+ * Whether to generate the Prisma client
10
+ * @defaultValue true
11
+ */
12
+ generateClient?: boolean;
13
+ /**
14
+ * Custom command to generate Prisma client
15
+ * @defaultValue 'prisma generate'
16
+ */
17
+ generateCommand?: string;
18
+ /**
19
+ * Path to the Prisma schema file
20
+ * @example 'prisma/schema.prisma'
21
+ */
22
+ prismaSchema: string;
23
+ /**
24
+ * Path to the generated schema file for comparison
25
+ * Used to avoid unnecessary regeneration
26
+ * @example 'node_modules/@prisma/client/schema.prisma'
27
+ */
28
+ generatedSchemaPath: string;
28
29
  }
29
-
30
+ //#endregion
31
+ //#region index.d.ts
30
32
  /**
31
33
  * A plugin that manages Prisma client generation in your Baeta project.
32
34
  * See https://baeta.io/docs/plugins/prisma
@@ -34,6 +36,7 @@ interface PrismaPluginOptions {
34
36
  * @param options - Configuration options for the pagination plugin
35
37
  * @returns A Baeta generator plugin
36
38
  */
37
- declare function prismaPlugin(options: PrismaPluginOptions): _baeta_generator_sdk.GeneratorPluginV1<unknown>[];
38
-
39
+ declare function prismaPlugin(options: PrismaPluginOptions): _baeta_generator_sdk0.GeneratorPluginV1<unknown>[];
40
+ //#endregion
39
41
  export { type PrismaPluginOptions, prismaPlugin as default, prismaPlugin };
42
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,53 +1,50 @@
1
- // lib/client-generator.ts
2
- import { readFile } from "fs/promises";
1
+ import { readFile } from "node:fs/promises";
3
2
  import { createExecPlugin } from "@baeta/plugin-exec";
4
3
  import { resolve } from "@baeta/util-path";
4
+
5
+ //#region lib/client-generator.ts
5
6
  async function compareSchemas(cwd, current, generated) {
6
- const [currentSchema, generatedSchema] = await Promise.all([
7
- readFile(resolve(cwd, current), "utf-8"),
8
- readFile(resolve(cwd, generated), "utf-8").catch(() => null)
9
- ]);
10
- return currentSchema.replaceAll(" ", "") === generatedSchema?.replaceAll(" ", "");
7
+ const [currentSchema, generatedSchema] = await Promise.all([readFile(resolve(cwd, current), "utf-8"), readFile(resolve(cwd, generated), "utf-8").catch(() => null)]);
8
+ return currentSchema.replaceAll(" ", "") === generatedSchema?.replaceAll(" ", "");
11
9
  }
12
10
  function createPrismaClientPlugin(options) {
13
- const { prismaSchema, generateCommand, generatedSchemaPath } = options;
14
- return createExecPlugin({
15
- name: "prisma-client",
16
- actionName: "Prisma client",
17
- exec: generateCommand ?? "prisma generate",
18
- watch: (generatorOptions, watcher, reload) => {
19
- const prismaPath = resolve(generatorOptions.cwd, prismaSchema);
20
- const handleChange = (file) => {
21
- if (file.path === prismaPath) {
22
- reload(file);
23
- }
24
- };
25
- watcher.on("update", handleChange);
26
- watcher.on("delete", handleChange);
27
- },
28
- skip: async (ctx) => {
29
- const schema = resolve(ctx.generatorOptions.cwd, prismaSchema);
30
- if (ctx.watching && ctx.changedFile?.path !== schema) {
31
- return true;
32
- }
33
- if (!ctx.watching && generatedSchemaPath) {
34
- return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
35
- }
36
- return false;
37
- }
38
- });
11
+ const { prismaSchema, generateCommand, generatedSchemaPath } = options;
12
+ return createExecPlugin({
13
+ name: "prisma-client",
14
+ actionName: "Prisma client",
15
+ exec: generateCommand ?? "prisma generate",
16
+ watch: (generatorOptions, watcher, reload) => {
17
+ const prismaPath = resolve(generatorOptions.cwd, prismaSchema);
18
+ const handleChange = (file) => {
19
+ if (file.path === prismaPath) reload(file);
20
+ };
21
+ watcher.on("update", handleChange);
22
+ watcher.on("delete", handleChange);
23
+ },
24
+ skip: async (ctx) => {
25
+ const schema = resolve(ctx.generatorOptions.cwd, prismaSchema);
26
+ if (ctx.watching && ctx.changedFile?.path !== schema) return true;
27
+ if (!ctx.watching && generatedSchemaPath) return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
28
+ return false;
29
+ }
30
+ });
39
31
  }
40
32
 
41
- // index.ts
42
- var index_default = prismaPlugin;
33
+ //#endregion
34
+ //#region index.ts
35
+ var plugin_prisma_default = prismaPlugin;
36
+ /**
37
+ * A plugin that manages Prisma client generation in your Baeta project.
38
+ * See https://baeta.io/docs/plugins/prisma
39
+ *
40
+ * @param options - Configuration options for the pagination plugin
41
+ * @returns A Baeta generator plugin
42
+ */
43
43
  function prismaPlugin(options) {
44
- if (options.generateClient === false) {
45
- return [];
46
- }
47
- return [createPrismaClientPlugin(options)];
44
+ if (options.generateClient === false) return [];
45
+ return [createPrismaClientPlugin(options)];
48
46
  }
49
- export {
50
- index_default as default,
51
- prismaPlugin
52
- };
47
+
48
+ //#endregion
49
+ export { plugin_prisma_default as default, prismaPlugin };
53
50
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"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 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 };\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":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAGxB,eAAe,eAAe,KAAa,SAAiB,WAAmB;AAC9E,QAAM,CAAC,eAAe,eAAe,IAAI,MAAM,QAAQ,IAAI;AAAA,IAC1D,SAAS,QAAQ,KAAK,OAAO,GAAG,OAAO;AAAA,IACvC,SAAS,QAAQ,KAAK,SAAS,GAAG,OAAO,EAAE,MAAM,MAAM,IAAI;AAAA,EAC5D,CAAC;AACD,SAAO,cAAc,WAAW,KAAK,EAAE,MAAM,iBAAiB,WAAW,KAAK,EAAE;AACjF;AAEO,SAAS,yBAAyB,SAA8B;AACtE,QAAM,EAAE,cAAc,iBAAiB,oBAAoB,IAAI;AAE/D,SAAO,iBAAiB;AAAA,IACvB,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,MAAM,mBAAmB;AAAA,IACzB,OAAO,CAAC,kBAAkB,SAAS,WAAW;AAC7C,YAAM,aAAa,QAAQ,iBAAiB,KAAK,YAAY;AAE7D,YAAM,eAAe,CAAC,SAAsB;AAC3C,YAAI,KAAK,SAAS,YAAY;AAC7B,iBAAO,IAAI;AAAA,QACZ;AAAA,MACD;AAEA,cAAQ,GAAG,UAAU,YAAY;AACjC,cAAQ,GAAG,UAAU,YAAY;AAAA,IAClC;AAAA,IACA,MAAM,OAAO,QAAa;AACzB,YAAM,SAAS,QAAQ,IAAI,iBAAiB,KAAK,YAAY;AAE7D,UAAI,IAAI,YAAY,IAAI,aAAa,SAAS,QAAQ;AACrD,eAAO;AAAA,MACR;AAEA,UAAI,CAAC,IAAI,YAAY,qBAAqB;AACzC,eAAO,eAAe,IAAI,iBAAiB,KAAK,cAAc,mBAAmB;AAAA,MAClF;AAEA,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AACF;;;AC3CA,IAAO,gBAAQ;AASR,SAAS,aAAa,SAA8B;AAC1D,MAAI,QAAQ,mBAAmB,OAAO;AACrC,WAAO,CAAC;AAAA,EACT;AACA,SAAO,CAAC,yBAAyB,OAAO,CAAC;AAC1C;","names":[]}
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 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,QAAQ,EAAE,QAAQ,EACxC,SAAS,QAAQ,KAAK,UAAU,EAAE,QAAQ,CAAC,YAAY,KAAK,CAC5D,CAAC;AACF,QAAO,cAAc,WAAW,KAAK,GAAG,KAAK,iBAAiB,WAAW,KAAK,GAAG;;AAGlF,SAAgB,yBAAyB,SAA8B;CACtE,MAAM,EAAE,cAAc,iBAAiB,wBAAwB;AAE/D,QAAO,iBAAiB;EACvB,MAAM;EACN,YAAY;EACZ,MAAM,mBAAmB;EACzB,QAAQ,kBAAkB,SAAS,WAAW;GAC7C,MAAM,aAAa,QAAQ,iBAAiB,KAAK,aAAa;GAE9D,MAAM,gBAAgB,SAAsB;AAC3C,QAAI,KAAK,SAAS,WACjB,QAAO,KAAK;;AAId,WAAQ,GAAG,UAAU,aAAa;AAClC,WAAQ,GAAG,UAAU,aAAa;;EAEnC,MAAM,OAAO,QAAa;GACzB,MAAM,SAAS,QAAQ,IAAI,iBAAiB,KAAK,aAAa;AAE9D,OAAI,IAAI,YAAY,IAAI,aAAa,SAAS,OAC7C,QAAO;AAGR,OAAI,CAAC,IAAI,YAAY,oBACpB,QAAO,eAAe,IAAI,iBAAiB,KAAK,cAAc,oBAAoB;AAGnF,UAAO;;EAER,CAAC;;;;;ACzCH,4BAAe;;;;;;;;AASf,SAAgB,aAAa,SAA8B;AAC1D,KAAI,QAAQ,mBAAmB,MAC9B,QAAO,EAAE;AAEV,QAAO,CAAC,yBAAyB,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/plugin-prisma",
3
- "version": "2.0.0-next.2",
3
+ "version": "2.0.0-next.7",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -37,21 +37,29 @@
37
37
  "package.json"
38
38
  ],
39
39
  "scripts": {
40
- "build": "tsup",
41
- "prepack": "prep",
42
- "postpack": "prep --clean",
40
+ "build": "builder build",
41
+ "prepack": "builder prepare",
42
+ "postpack": "builder prepare --clean",
43
+ "test": "builder test",
44
+ "test:circular": "builder test-circular",
43
45
  "types": "tsc --noEmit"
44
46
  },
47
+ "ava": {
48
+ "extensions": {
49
+ "ts": "module"
50
+ }
51
+ },
45
52
  "dependencies": {
46
- "@baeta/generator-sdk": "^2.0.0-next.2",
47
- "@baeta/plugin-exec": "^2.0.0-next.2",
53
+ "@baeta/generator-sdk": "^2.0.0-next.3",
54
+ "@baeta/plugin-exec": "^2.0.0-next.7",
48
55
  "@baeta/util-path": "^2.0.0-next.2",
49
56
  "execa": "^9.6.0"
50
57
  },
51
58
  "devDependencies": {
52
59
  "@baeta/builder": "^0.0.0",
60
+ "@baeta/testing": "^0.0.0",
53
61
  "@baeta/tsconfig": "^0.0.0",
54
- "@types/node": "^22.18.11",
62
+ "@types/node": "^22.19.1",
55
63
  "typescript": "^5.9.3"
56
64
  },
57
65
  "engines": {