@baeta/plugin-prisma 0.1.2 → 0.1.4
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 +26 -0
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/index.js +11 -12
- package/dist/index.js.map +1 -1
- package/package.json +16 -11
- package/dist/index.cjs +0 -54
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @baeta/plugin-prisma
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820)]:
|
|
10
|
+
- @baeta/generator-sdk@0.1.4
|
|
11
|
+
- @baeta/plugin-exec@0.1.4
|
|
12
|
+
- @baeta/util-path@0.1.4
|
|
13
|
+
|
|
14
|
+
## 0.1.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#180](https://github.com/andreisergiu98/baeta/pull/180) [`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Raise minimum required NodeJS version to 22.12.0. Drop CommonJS builds in favor of the require_esm feature from NodeJS 22.12.0 onwards.
|
|
19
|
+
|
|
20
|
+
- [#174](https://github.com/andreisergiu98/baeta/pull/174) [`3f2befb`](https://github.com/andreisergiu98/baeta/commit/3f2befbb4b645e2970727482e970c4e78f0ed598) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - fix skip generate
|
|
21
|
+
|
|
22
|
+
- [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72), [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857)]:
|
|
25
|
+
- @baeta/generator-sdk@0.1.3
|
|
26
|
+
- @baeta/plugin-exec@0.1.3
|
|
27
|
+
- @baeta/util-path@0.1.3
|
|
28
|
+
|
|
3
29
|
## 0.1.2
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Pampu Andrei
|
|
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
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/andreisergiu98/baeta/refs/heads/main/website/static/img/logo-baeta.svg" alt="Baeta Logo" width="150"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<h1>Baeta</h1>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@baeta/cli"><img src="https://img.shields.io/npm/v/@baeta/cli.svg?style=flat" /></a>
|
|
8
|
+
<a href="https://github.com/andreisergiu98/baeta/actions/workflows/testing.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/testing.yml" /></a>
|
|
9
|
+
<a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
|
|
10
|
+
<a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
|
11
|
+
<br />
|
|
12
|
+
<br />
|
|
13
|
+
<a href="https://baeta.io/docs/getting-started/installation">Getting Started</a>
|
|
14
|
+
<span> • </span>
|
|
15
|
+
<a href="https://www.baeta.io/">Website</a>
|
|
16
|
+
<span> • </span>
|
|
17
|
+
<a href="https://baeta.io/docs/intro">Docs</a>
|
|
18
|
+
<span> • </span>
|
|
19
|
+
<a href="https://github.com/andreisergiu98/baeta/tree/main/examples">Examples</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://discord.gg/BHFXHvyj">Discord</a>
|
|
22
|
+
<br />
|
|
23
|
+
<hr />
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
# What is Baeta?
|
|
27
|
+
|
|
28
|
+
Building GraphQL APIs shouldn't be complicated. **Baeta** is a modern, modular, open-source GraphQL framework designed with flexibility in mind. It follows a granular approach where you only add what you need, helping developers focus on what matters most - creating powerful, scalable APIs without the boilerplate.
|
|
29
|
+
|
|
30
|
+
### Key Features
|
|
31
|
+
|
|
32
|
+
- **Modular Architecture**: Organize your API into manageable modules
|
|
33
|
+
- **Schema-First Development**: Define your API contract upfront
|
|
34
|
+
- **Type Safety**: Automatic code generation for type-safe development
|
|
35
|
+
- **Middleware & Directives**: Easy integration of custom behaviors
|
|
36
|
+
- **High Performance**: Built for scalability and efficiency
|
|
37
|
+
|
|
38
|
+
#### And optional extensions and plugins
|
|
39
|
+
|
|
40
|
+
- **@baeta/extension-auth**: Add powerful scope-based authorization
|
|
41
|
+
- **@baeta/extension-cache**: Implement automatic caching with simple update patterns
|
|
42
|
+
- ... and more!
|
|
43
|
+
|
|
44
|
+
## Why use Baeta?
|
|
45
|
+
|
|
46
|
+
Baeta makes it easy to build better GraphQL APIs while staying flexible. Here's how:
|
|
47
|
+
|
|
48
|
+
**Granular and Progressive:** Start small and add features as you need them. Whether you're building a simple API or a complex system, Baeta scales with your needs.
|
|
49
|
+
|
|
50
|
+
**Modular architecture:** Baeta's modular design allows you to organize your GraphQL API into smaller, more manageable modules that can be added or removed as needed. This makes it easier to maintain and scale your API over time.
|
|
51
|
+
|
|
52
|
+
**Schema-first approach:** With Baeta, you define your schema first, and then logic and resolvers. This approach ensures a consistent and well-defined API for your clients and reduces boilerplate code.
|
|
53
|
+
|
|
54
|
+
## How it Works
|
|
55
|
+
|
|
56
|
+
#### 1. Define your schema
|
|
57
|
+
|
|
58
|
+
```graphql
|
|
59
|
+
type User {
|
|
60
|
+
id: ID!
|
|
61
|
+
name: String!
|
|
62
|
+
email: String!
|
|
63
|
+
age: Int
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
input UserWhereUnique {
|
|
67
|
+
id: ID
|
|
68
|
+
email: String
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type Query {
|
|
72
|
+
user(where: UserWhereUnique!): User!
|
|
73
|
+
users: [User!]!
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### 2. Implement your resolvers
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { getUserModule } from "./typedef";
|
|
81
|
+
|
|
82
|
+
const { Query } = getUserModule();
|
|
83
|
+
|
|
84
|
+
Query.user(({ args }) => {
|
|
85
|
+
return dataSource.user.find(args.where);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
Query.users(() => {
|
|
89
|
+
return dataSource.user.findMany();
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### 3. Add authorization
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const { Query, Mutation } = getUserModule();
|
|
97
|
+
|
|
98
|
+
Query.users.$auth({
|
|
99
|
+
$or: {
|
|
100
|
+
isPublic: true,
|
|
101
|
+
isLoggedIn: true,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 4. Add caching
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { getUserModule } from "./typedef";
|
|
110
|
+
|
|
111
|
+
const { User, Query } = getUserModule();
|
|
112
|
+
|
|
113
|
+
export const userCache = User.$createCache();
|
|
114
|
+
|
|
115
|
+
Query.user.$useCache(userCache);
|
|
116
|
+
Query.users.$useCache(userCache);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Compatibility
|
|
120
|
+
|
|
121
|
+
Baeta is compatible with all GraphQL servers, which makes it easy to integrate with your existing stack. It works seamlessly with popular GraphQL server libraries such as **Graphql Yoga** and **Apollo Server**, as well as other popular tools like **Prisma**, **Drizzle** and **Kysely**.
|
|
122
|
+
|
|
123
|
+
Baeta's development tools are built for Node.js, but the runtime code is environment-agnostic. This means your Baeta applications can run anywhere JavaScript runs, including:
|
|
124
|
+
|
|
125
|
+
- Deno
|
|
126
|
+
- Cloudflare Workers
|
|
127
|
+
- AWS Lambda
|
|
128
|
+
- Vercel Edge Functions
|
|
129
|
+
- Bun
|
|
130
|
+
- Node.js
|
|
131
|
+
- Any other JavaScript runtime
|
|
132
|
+
|
|
133
|
+
## Credits
|
|
134
|
+
|
|
135
|
+
Baeta was inspired by several amazing projects and people in the GraphQL ecosystem. Check out our [Credits page](https://baeta.io/docs/credits) to learn more about the individuals and projects that influenced Baeta's development.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
Baeta is licensed under the [MIT License](./LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -7,20 +7,10 @@ async function compareSchemas(cwd, current, generated) {
|
|
|
7
7
|
readFile(resolve(cwd, current), "utf-8"),
|
|
8
8
|
readFile(resolve(cwd, generated), "utf-8").catch(() => null)
|
|
9
9
|
]);
|
|
10
|
-
return currentSchema === generatedSchema;
|
|
10
|
+
return currentSchema.replaceAll(" ", "") === generatedSchema?.replaceAll(" ", "");
|
|
11
11
|
}
|
|
12
12
|
function createPrismaClientPlugin(options) {
|
|
13
13
|
const { prismaSchema, generateCommand, generatedSchemaPath } = options;
|
|
14
|
-
const skip = async (ctx) => {
|
|
15
|
-
const schema = resolve(ctx.generatorOptions.cwd, prismaSchema);
|
|
16
|
-
if (ctx.watching && ctx.changedFile?.path !== schema) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
if (!ctx.watching && generatedSchemaPath) {
|
|
20
|
-
return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
24
14
|
return createExecPlugin({
|
|
25
15
|
name: "prisma-client",
|
|
26
16
|
actionName: "Prisma client",
|
|
@@ -35,7 +25,16 @@ function createPrismaClientPlugin(options) {
|
|
|
35
25
|
watcher.on("update", handleChange);
|
|
36
26
|
watcher.on("delete", handleChange);
|
|
37
27
|
},
|
|
38
|
-
skip
|
|
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
|
+
}
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
|
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 === generatedSchema;\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\
|
|
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\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,EAC5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
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"require": "./dist/index.cjs"
|
|
31
|
+
"default": "./dist/index.js"
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
"types": "dist/index.d.ts",
|
|
@@ -44,27 +43,26 @@
|
|
|
44
43
|
"types": "tsc --noEmit"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@baeta/generator-sdk": "^0.1.
|
|
48
|
-
"@baeta/plugin-exec": "^0.1.
|
|
49
|
-
"@baeta/util-path": "^0.1.
|
|
46
|
+
"@baeta/generator-sdk": "^0.1.4",
|
|
47
|
+
"@baeta/plugin-exec": "^0.1.4",
|
|
48
|
+
"@baeta/util-path": "^0.1.4",
|
|
50
49
|
"execa": "^9.5.1"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@baeta/builder": "^0.0.0",
|
|
54
53
|
"@baeta/tsconfig": "^0.0.0",
|
|
55
|
-
"@types/node": "^22.
|
|
56
|
-
"typescript": "^5.
|
|
54
|
+
"@types/node": "^22.10.1",
|
|
55
|
+
"typescript": "^5.7.2"
|
|
57
56
|
},
|
|
58
57
|
"engines": {
|
|
59
|
-
"node": ">=22.
|
|
58
|
+
"node": ">=22.12.0"
|
|
60
59
|
},
|
|
61
60
|
"publishConfig": {
|
|
62
61
|
"access": "public",
|
|
63
62
|
"exports": {
|
|
64
63
|
".": {
|
|
65
64
|
"types": "./dist/index.d.ts",
|
|
66
|
-
"
|
|
67
|
-
"require": "./dist/index.cjs"
|
|
65
|
+
"default": "./dist/index.js"
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
},
|
|
@@ -76,5 +74,12 @@
|
|
|
76
74
|
"--no-warnings",
|
|
77
75
|
"--experimental-transform-types"
|
|
78
76
|
]
|
|
77
|
+
},
|
|
78
|
+
"typedocOptions": {
|
|
79
|
+
"entryPoints": [
|
|
80
|
+
"./index.ts"
|
|
81
|
+
],
|
|
82
|
+
"readme": "none",
|
|
83
|
+
"tsconfig": "./tsconfig.json"
|
|
79
84
|
}
|
|
80
85
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// lib/client-generator.ts
|
|
2
|
-
var _promises = require('fs/promises');
|
|
3
|
-
var _pluginexec = require('@baeta/plugin-exec');
|
|
4
|
-
var _utilpath = require('@baeta/util-path');
|
|
5
|
-
async function compareSchemas(cwd, current, generated) {
|
|
6
|
-
const [currentSchema, generatedSchema] = await Promise.all([
|
|
7
|
-
_promises.readFile.call(void 0, _utilpath.resolve.call(void 0, cwd, current), "utf-8"),
|
|
8
|
-
_promises.readFile.call(void 0, _utilpath.resolve.call(void 0, cwd, generated), "utf-8").catch(() => null)
|
|
9
|
-
]);
|
|
10
|
-
return currentSchema === generatedSchema;
|
|
11
|
-
}
|
|
12
|
-
function createPrismaClientPlugin(options) {
|
|
13
|
-
const { prismaSchema, generateCommand, generatedSchemaPath } = options;
|
|
14
|
-
const skip = async (ctx) => {
|
|
15
|
-
const schema = _utilpath.resolve.call(void 0, ctx.generatorOptions.cwd, prismaSchema);
|
|
16
|
-
if (ctx.watching && _optionalChain([ctx, 'access', _ => _.changedFile, 'optionalAccess', _2 => _2.path]) !== schema) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
if (!ctx.watching && generatedSchemaPath) {
|
|
20
|
-
return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
24
|
-
return _pluginexec.createExecPlugin.call(void 0, {
|
|
25
|
-
name: "prisma-client",
|
|
26
|
-
actionName: "Prisma client",
|
|
27
|
-
exec: _nullishCoalesce(generateCommand, () => ( "prisma generate")),
|
|
28
|
-
watch: (generatorOptions, watcher, reload) => {
|
|
29
|
-
const prismaPath = _utilpath.resolve.call(void 0, generatorOptions.cwd, prismaSchema);
|
|
30
|
-
const handleChange = (file) => {
|
|
31
|
-
if (file.path === prismaPath) {
|
|
32
|
-
reload(file);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
watcher.on("update", handleChange);
|
|
36
|
-
watcher.on("delete", handleChange);
|
|
37
|
-
},
|
|
38
|
-
skip
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// index.ts
|
|
43
|
-
var plugin_prisma_default = prismaPlugin;
|
|
44
|
-
function prismaPlugin(options) {
|
|
45
|
-
if (options.generateClient === false) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
return [createPrismaClientPlugin(options)];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
exports.default = plugin_prisma_default; exports.prismaPlugin = prismaPlugin;
|
|
54
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/baeta/baeta/packages/plugin-prisma/dist/index.cjs","../lib/client-generator.ts","../index.ts"],"names":[],"mappings":"AAAA;ACAA,uCAAyB;AAEzB,gDAAiC;AACjC,4CAAwB;AAGxB,MAAA,SAAe,cAAA,CAAe,GAAA,EAAa,OAAA,EAAiB,SAAA,EAAmB;AAC9E,EAAA,MAAM,CAAC,aAAA,EAAe,eAAe,EAAA,EAAI,MAAM,OAAA,CAAQ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QAAA,GAAA,CAAI,IAAA,CAAK,KAAA,IAAS,UAAA,EAAY;AAC7B,UAAA,MAAA,CAAO,IAAI,CAAA;AAAA,QACZ;AAAA,MACD,CAAA;AAEA,MAAA,OAAA,CAAQ,EAAA,CAAG,QAAA,EAAU,YAAY,CAAA;AACjC,MAAA,OAAA,CAAQ,EAAA,CAAG,QAAA,EAAU,YAAY,CAAA;AAAA,IAClC,CAAA;AAAA,IACA;AAAA,EACD,CAAC,CAAA;AACF;ADTA;AACA;AErCA,IAAO,sBAAA,EAAQ,YAAA;AAER,SAAS,YAAA,CAAa,OAAA,EAA8B;AAC1D,EAAA,GAAA,CAAI,OAAA,CAAQ,eAAA,IAAmB,KAAA,EAAO;AACrC,IAAA,OAAO,CAAC,CAAA;AAAA,EACT;AACA,EAAA,OAAO,CAAC,wBAAA,CAAyB,OAAO,CAAC,CAAA;AAC1C;AFsCA;AACE;AACA;AACF,6EAAC","file":"/home/runner/work/baeta/baeta/packages/plugin-prisma/dist/index.cjs","sourcesContent":[null,"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 === generatedSchema;\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\tconst skip = async (ctx: Ctx) => {\n\t\tconst schema = resolve(ctx.generatorOptions.cwd, prismaSchema);\n\n\t\tif (ctx.watching && ctx.changedFile?.path !== schema) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!ctx.watching && generatedSchemaPath) {\n\t\t\treturn compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);\n\t\t}\n\n\t\treturn false;\n\t};\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,\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\nexport function prismaPlugin(options: PrismaPluginOptions) {\n\tif (options.generateClient === false) {\n\t\treturn [];\n\t}\n\treturn [createPrismaClientPlugin(options)];\n}\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as _baeta_generator_sdk from '@baeta/generator-sdk';
|
|
2
|
-
|
|
3
|
-
interface PrismaPluginOptions {
|
|
4
|
-
generateClient?: boolean;
|
|
5
|
-
generateCommand?: string;
|
|
6
|
-
prismaSchema: string;
|
|
7
|
-
generatedSchemaPath: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare function prismaPlugin(options: PrismaPluginOptions): _baeta_generator_sdk.GeneratorPluginV1<unknown>[];
|
|
11
|
-
|
|
12
|
-
export { type PrismaPluginOptions, prismaPlugin as default, prismaPlugin };
|