Skip to content

Commit

Permalink
chore: unify prisma internals package to v5 (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Apr 10, 2024
1 parent b6f4a9e commit 9334a2d
Show file tree
Hide file tree
Showing 8 changed files with 1,219 additions and 1,746 deletions.
587 changes: 334 additions & 253 deletions packages/plugins/openapi/tests/baseline/rpc-3.0.0.baseline.yaml

Large diffs are not rendered by default.

537 changes: 314 additions & 223 deletions packages/plugins/openapi/tests/baseline/rpc-3.1.0.baseline.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/schema/tests/generator/prisma-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ describe('Prisma generator test', () => {
});

const content = fs.readFileSync(name, 'utf-8');
// "nanoid()" is only available in later versions of Prisma
await getDMMF({ datamodel: content }, '5.0.0');
await getDMMF({ datamodel: content });

expect(content).toContain('@default(nanoid(6))');
expect(content).toContain('@default(nanoid())');
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"license": "MIT",
"dependencies": {
"@prisma/generator-helper": "^5.0.0",
"@prisma/internals": "^4.16.0",
"@prisma/internals-v5": "npm:@prisma/internals@^5.0.0",
"@prisma/internals": "^5.0.0",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"langium": "1.3.1",
Expand Down
24 changes: 4 additions & 20 deletions packages/sdk/src/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-var-requires */

import type { DMMF } from '@prisma/generator-helper';
import { getDMMF as _getDMMF, type GetDMMFOptions } from '@prisma/internals';
import path from 'path';
import * as semver from 'semver';
import { RUNTIME_PACKAGE } from './constants';
import type { PluginOptions } from './types';

Expand Down Expand Up @@ -40,27 +40,11 @@ function normalizePath(p: string) {
return p ? p.split(path.sep).join(path.posix.sep) : p;
}

export type GetDMMFOptions = {
datamodel?: string;
cwd?: string;
prismaPath?: string;
datamodelPath?: string;
retry?: number;
previewFeatures?: string[];
};

/**
* Loads Prisma DMMF with appropriate version
* Loads Prisma DMMF
*/
export function getDMMF(options: GetDMMFOptions, defaultPrismaVersion?: string): Promise<DMMF.Document> {
const prismaVersion = getPrismaVersion() ?? defaultPrismaVersion;
if (prismaVersion && semver.gte(prismaVersion, '5.0.0')) {
const _getDMMF = require('@prisma/internals-v5').getDMMF;
return _getDMMF(options);
} else {
const _getDMMF = require('@prisma/internals').getDMMF;
return _getDMMF(options);
}
export function getDMMF(options: GetDMMFOptions): Promise<DMMF.Document> {
return _getDMMF(options);
}

/**
Expand Down
Loading

0 comments on commit 9334a2d

Please sign in to comment.