@lexmata/prisma-ent-generator 0.3.0 → 0.3.1
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/README.md +8 -5
- package/dist/generator.d.ts +13 -3
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +18 -11
- package/dist/generator.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Define your data model once in Prisma and generate fully working Ent schemas —
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Full Ent install** — generates `generate.go`, `entc.go`, and `schema/*.go` so you can immediately run `go generate ./ent`
|
|
10
|
-
- **Environment variable toggle** — controlled by `GENERATE_ENT
|
|
10
|
+
- **Environment variable toggle** — controlled by `isEnabled = env("GENERATE_ENT")` in the generator config; skips when unset or `false`, runs when `true`
|
|
11
11
|
- **Scalar type mapping** — `String`, `Int`, `BigInt`, `Float`, `Decimal`, `Boolean`, `DateTime`, `Json`, `Bytes`
|
|
12
12
|
- **Enum support** — Prisma enums map to inline `field.Enum(...).Values(...)` with defaults
|
|
13
13
|
- **Relationship edges** — O2O, O2M, and M2M relations are translated to `edge.To` / `edge.From` with correct ownership, `.Ref()`, `.Unique()`, and `.Required()`
|
|
@@ -32,8 +32,9 @@ pnpm add @lexmata/prisma-ent-generator
|
|
|
32
32
|
|
|
33
33
|
```prisma
|
|
34
34
|
generator ent {
|
|
35
|
-
provider
|
|
36
|
-
output
|
|
35
|
+
provider = "@lexmata/prisma-ent-generator"
|
|
36
|
+
output = "./ent"
|
|
37
|
+
isEnabled = env("GENERATE_ENT")
|
|
37
38
|
}
|
|
38
39
|
```
|
|
39
40
|
|
|
@@ -43,12 +44,14 @@ generator ent {
|
|
|
43
44
|
GENERATE_ENT=true npx prisma generate
|
|
44
45
|
```
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
When `isEnabled` resolves to anything other than `"true"`, the generator prints a skip message and produces no output:
|
|
47
48
|
|
|
48
49
|
```
|
|
49
|
-
prisma-ent-generator: Skipping — set
|
|
50
|
+
prisma-ent-generator: Skipping — set isEnabled = env("GENERATE_ENT") to "true" in your generator config.
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
You can use any environment variable name you like — just change the `env()` argument accordingly.
|
|
54
|
+
|
|
52
55
|
### 3. Run Ent code generation
|
|
53
56
|
|
|
54
57
|
```bash
|
package/dist/generator.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { GeneratorOptions } from '@prisma/generator-helper';
|
|
2
2
|
/**
|
|
3
|
-
* Check whether the generator is enabled via the
|
|
4
|
-
*
|
|
3
|
+
* Check whether the generator is enabled via the `isEnabled` config property
|
|
4
|
+
* in the Prisma generator block.
|
|
5
|
+
*
|
|
6
|
+
* The property should reference an environment variable using Prisma's `env()`:
|
|
7
|
+
*
|
|
8
|
+
* generator ent {
|
|
9
|
+
* isEnabled = env("GENERATE_ENT")
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Prisma resolves the env var and passes the value through
|
|
13
|
+
* `options.generator.config.isEnabled`. Returns true only when the
|
|
14
|
+
* resolved value is "true" (case-insensitive).
|
|
5
15
|
*/
|
|
6
|
-
export declare function isEnabled(): boolean;
|
|
16
|
+
export declare function isEnabled(configValue?: string): boolean;
|
|
7
17
|
/**
|
|
8
18
|
* Main generator function — receives the full Prisma DMMF and generator config,
|
|
9
19
|
* then writes a complete Go Ent installation to the output directory.
|
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAKvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2DvE"}
|
package/dist/generator.js
CHANGED
|
@@ -11,16 +11,21 @@ const schema_1 = require("./helpers/schema");
|
|
|
11
11
|
const entfiles_1 = require("./helpers/entfiles");
|
|
12
12
|
const utils_1 = require("./utils");
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
14
|
+
* Check whether the generator is enabled via the `isEnabled` config property
|
|
15
|
+
* in the Prisma generator block.
|
|
16
|
+
*
|
|
17
|
+
* The property should reference an environment variable using Prisma's `env()`:
|
|
18
|
+
*
|
|
19
|
+
* generator ent {
|
|
20
|
+
* isEnabled = env("GENERATE_ENT")
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* Prisma resolves the env var and passes the value through
|
|
24
|
+
* `options.generator.config.isEnabled`. Returns true only when the
|
|
25
|
+
* resolved value is "true" (case-insensitive).
|
|
21
26
|
*/
|
|
22
|
-
function isEnabled() {
|
|
23
|
-
return
|
|
27
|
+
function isEnabled(configValue) {
|
|
28
|
+
return configValue?.toLowerCase() === 'true';
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Main generator function — receives the full Prisma DMMF and generator config,
|
|
@@ -36,8 +41,10 @@ function isEnabled() {
|
|
|
36
41
|
* ...
|
|
37
42
|
*/
|
|
38
43
|
async function generate(options) {
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const isEnabledValue = options.generator.config.isEnabled;
|
|
45
|
+
const configValue = Array.isArray(isEnabledValue) ? isEnabledValue[0] : isEnabledValue;
|
|
46
|
+
if (!isEnabled(configValue)) {
|
|
47
|
+
console.log('prisma-ent-generator: Skipping — set isEnabled = env("GENERATE_ENT") to "true" in your generator config.');
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
const outputDir = options.generator.output?.value;
|
package/dist/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;AAqBA,8BAEC;AAeD,4BA2DC;AAjGD,4CAAoB;AACpB,gDAAwB;AAExB,6CAAkD;AAClD,iDAAwE;AACxE,mCAAsD;AAEtD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CAAC,WAAoB;IAC5C,OAAO,WAAW,EAAE,WAAW,EAAE,KAAK,MAAM,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,QAAQ,CAAC,OAAyB;IACtD,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IAC1D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;IACvF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CACT,0GAA0G,CAC3G,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC;IAClD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,+CAA+C;IAC/C,2CAA2C;IAC3C,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjD,YAAE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