prisma-kysely 1.2.0 → 1.2.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 CHANGED
@@ -105,17 +105,6 @@ model SQLiteUser {
105
105
  [Check out the Prisma Docs for more
106
106
  info.](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#attribute-functions)
107
107
 
108
- #### Field level `@map` not supported
109
-
110
- Regrettably, `prisma-kysely` doesn't support
111
- [mapping](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#map)
112
- field names to different columns. This is due the fact that Prisma's "Data Model
113
- Meta Format" doesn't supply custom generators with the info needed. There's no
114
- easy way to implement this besides re-parsing the schema ourselves, so for now
115
- we have to wait until Prisma fix this upstream. We're keeping track of the issue
116
- here: https://github.com/valtyr/prisma-kysely/issues/4. In the meantime you can
117
- get around the issue by naming the field directly after the column.
118
-
119
108
  ### Contributions
120
109
 
121
110
  OMG you actually want to contribute? I'm so thankful! 🙇‍♂️
@@ -125,8 +114,14 @@ Here's everything you need to do (let me know if something's missing...)
125
114
  1. Fork and pull the repository
126
115
  2. Run `yarn install` and `yarn dev` to start `tsc` in watch mode.
127
116
  3. Make changes to the source code
128
- 4. Test your changes by editing `prisma/schema.prisma`, running `yarn prisma
129
- generate` and checking the output in `prisma/types.ts`.
117
+ 4. Test your changes by creating `prisma/schema.prisma`, running `yarn prisma
118
+ generate` and checking the output in `prisma/types.ts`. The provider must be set
119
+ as follows to reference the dev build:
120
+ ```prisma
121
+ generator kysely {
122
+ provider = "node ./dist/bin.js"
123
+ }
124
+ ```
130
125
  5. Create a pull request! If your changes make sense, I'll try my best to review
131
126
  and merge them quickly.
132
127
 
package/dist/generator.js CHANGED
@@ -10,11 +10,10 @@ const generateDatabaseType_1 = require("./helpers/generateDatabaseType");
10
10
  const generateFile_1 = require("./helpers/generateFile");
11
11
  const generateImplicitManyToManyModels_1 = require("./helpers/generateImplicitManyToManyModels");
12
12
  const generateModel_1 = require("./helpers/generateModel");
13
- const generateStringLiteralUnion_1 = require("./helpers/generateStringLiteralUnion");
14
- const generateTypedAliasDeclaration_1 = require("./helpers/generateTypedAliasDeclaration");
15
13
  const sorted_1 = require("./utils/sorted");
16
14
  const validateConfig_1 = require("./utils/validateConfig");
17
15
  const writeFileSafely_1 = require("./utils/writeFileSafely");
16
+ const generateEnumType_1 = require("./helpers/generateEnumType");
18
17
  const { version } = require("../package.json");
19
18
  (0, generator_helper_1.generatorHandler)({
20
19
  onManifest() {
@@ -31,11 +30,7 @@ const { version } = require("../package.json");
31
30
  databaseProvider: options.datasources[0].provider,
32
31
  });
33
32
  const enums = options.dmmf.datamodel.enums.flatMap(({ name, values }) => {
34
- const type = (0, generateStringLiteralUnion_1.generateStringLiteralUnion)(values.map((v) => v.name));
35
- if (!type)
36
- return [];
37
- const declaration = (0, generateTypedAliasDeclaration_1.generateTypedAliasDeclaration)(name, type);
38
- return declaration;
33
+ return (0, generateEnumType_1.generateEnumType)(name, values);
39
34
  });
40
35
  const implicitManyToManyModels = (0, generateImplicitManyToManyModels_1.generateImplicitManyToManyModels)(options.dmmf.datamodel.models);
41
36
  const models = (0, sorted_1.sorted)([...options.dmmf.datamodel.models, ...implicitManyToManyModels], (a, b) => a.name.localeCompare(b.name)).map((m) => (0, generateModel_1.generateModel)(m, config));
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;AACA,+DAA4D;AAC5D,gDAAwB;AAExB,2CAA6C;AAC7C,yEAAsE;AACtE,yDAAsD;AACtD,iGAA8F;AAC9F,2DAAwD;AACxD,qFAAkF;AAClF,2FAAwF;AACxF,2CAAwC;AACxC,2DAAwD;AACxD,6DAA0D;AAG1D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/C,IAAA,mCAAgB,EAAC;IACf,UAAU;QACR,OAAO;YACL,OAAO;YACP,aAAa,EAAE,aAAa;YAC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M,IAAA,iCAAe,EAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateEnumType = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const isValidTSIdentifier_1 = __importDefault(require("../utils/isValidTSIdentifier"));
9
+ const generateStringLiteralUnion_1 = require("./generateStringLiteralUnion");
10
+ const generateTypedAliasDeclaration_1 = require("./generateTypedAliasDeclaration");
11
+ const generateEnumType = (name, values) => {
12
+ const type = (0, generateStringLiteralUnion_1.generateStringLiteralUnion)(values.map((v) => v.name));
13
+ if (!type)
14
+ return [];
15
+ const objectDeclaration = typescript_1.default.factory.createVariableStatement([typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.default.factory.createVariableDeclarationList([
16
+ typescript_1.default.factory.createVariableDeclaration(name, undefined, undefined, typescript_1.default.factory.createObjectLiteralExpression(values.map((v) => {
17
+ const identifier = (0, isValidTSIdentifier_1.default)(v.name)
18
+ ? typescript_1.default.factory.createIdentifier(v.name)
19
+ : typescript_1.default.factory.createStringLiteral(v.name);
20
+ return typescript_1.default.factory.createPropertyAssignment(identifier, typescript_1.default.factory.createStringLiteral(v.name));
21
+ }), true)),
22
+ ], typescript_1.default.NodeFlags.Const));
23
+ const typeDeclaration = (0, generateTypedAliasDeclaration_1.generateTypedAliasDeclaration)(name, type);
24
+ return [typeDeclaration, objectDeclaration];
25
+ };
26
+ exports.generateEnumType = generateEnumType;
27
+ //# sourceMappingURL=generateEnumType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateEnumType.js","sourceRoot":"","sources":["../../src/helpers/generateEnumType.ts"],"names":[],"mappings":";;;;;;AACA,4DAA4B;AAE5B,uFAA8D;A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B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,gBAAgB,oBAmC3B"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "repository": {
5
5
  "url": "https://github.com/valtyr/prisma-kysely"
6
6
  },
7
- "version": "1.2.0",
7
+ "version": "1.2.1",
8
8
  "main": "dist/generator.js",
9
9
  "files": [
10
10
  "dist"