mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
fix(json): false error when using typed json in multi-file schemas (#1836)
This commit is contained in:
parent
13f95d270a
commit
1d1fec0019
17 changed files with 27 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "zenstack-monorepo",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"build": "pnpm -r build",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "dev.zenstack"
|
||||
version = "2.8.0"
|
||||
version = "2.8.1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jetbrains",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"displayName": "ZenStack JetBrains IDE Plugin",
|
||||
"description": "ZenStack JetBrains IDE plugin",
|
||||
"homepage": "https://zenstack.dev",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@zenstackhq/language",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"displayName": "ZenStack modeling language compiler",
|
||||
"description": "ZenStack modeling language compiler",
|
||||
"homepage": "https://zenstack.dev",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/redwood",
|
||||
"displayName": "ZenStack RedwoodJS Integration",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/openapi",
|
||||
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack plugin and runtime supporting OpenAPI",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/swr",
|
||||
"displayName": "ZenStack plugin for generating SWR hooks",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack plugin for generating SWR hooks",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/tanstack-query",
|
||||
"displayName": "ZenStack plugin for generating tanstack-query hooks",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack plugin for generating tanstack-query hooks",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/trpc",
|
||||
"displayName": "ZenStack plugin for tRPC",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack plugin for tRPC",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@zenstackhq/runtime",
|
||||
"displayName": "ZenStack Runtime Library",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "Runtime of ZenStack for both client-side and server-side environments.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"publisher": "zenstack",
|
||||
"displayName": "ZenStack Language Tools",
|
||||
"description": "FullStack enhancement for Prisma ORM: seamless integration from database to UI",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"author": {
|
||||
"name": "ZenStack Team"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import {
|
|||
isTypeDef,
|
||||
} from '@zenstackhq/language/ast';
|
||||
import {
|
||||
getDataSourceProvider,
|
||||
getModelFieldsWithBases,
|
||||
getModelIdFields,
|
||||
getModelUniqueFields,
|
||||
|
|
@ -108,10 +107,6 @@ export default class DataModelValidator implements AstValidator<DataModel> {
|
|||
if (!hasAttribute(field, '@json')) {
|
||||
accept('error', 'Custom-typed field must have @json attribute', { node: field });
|
||||
}
|
||||
|
||||
if (getDataSourceProvider(field.$container.$container) !== 'postgresql') {
|
||||
accept('error', 'Custom-typed field is only supported with "postgresql" provider', { node: field });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import {
|
|||
getAttribute,
|
||||
getAttributeArg,
|
||||
getAttributeArgLiteral,
|
||||
getDataSourceProvider,
|
||||
getInheritedFromDelegate,
|
||||
getLiteral,
|
||||
getRelationKeyPairs,
|
||||
|
|
@ -81,6 +82,7 @@ import {
|
|||
const MODEL_PASSTHROUGH_ATTR = '@@prisma.passthrough';
|
||||
const FIELD_PASSTHROUGH_ATTR = '@prisma.passthrough';
|
||||
const PROVIDERS_SUPPORTING_NAMED_CONSTRAINTS = ['postgresql', 'mysql', 'cockroachdb'];
|
||||
const PROVIDERS_SUPPORTING_TYPEDEF_FIELDS = ['postgresql'];
|
||||
|
||||
// Some database providers like postgres and mysql have default limit to the length of identifiers
|
||||
// Here we use a conservative value that should work for most cases, and truncate names if needed
|
||||
|
|
@ -794,6 +796,7 @@ export class PrismaSchemaGenerator {
|
|||
} else if (field.type.reference?.ref) {
|
||||
// model, enum, or type-def
|
||||
if (isTypeDef(field.type.reference.ref)) {
|
||||
this.ensureSupportingTypeDefFields(this.zmodel);
|
||||
fieldType = 'Json';
|
||||
} else {
|
||||
fieldType = field.type.reference.ref.name;
|
||||
|
|
@ -846,6 +849,13 @@ export class PrismaSchemaGenerator {
|
|||
return result;
|
||||
}
|
||||
|
||||
private ensureSupportingTypeDefFields(zmodel: Model) {
|
||||
const dsProvider = getDataSourceProvider(zmodel);
|
||||
if (dsProvider && !PROVIDERS_SUPPORTING_TYPEDEF_FIELDS.includes(dsProvider)) {
|
||||
throw new PluginError(name, `Datasource provider "${dsProvider}" does not support "@json" fields`);
|
||||
}
|
||||
}
|
||||
|
||||
private setDummyDefault(result: ModelField, field: DataModelField) {
|
||||
const dummyDefaultValue = match(field.type.type)
|
||||
.with('String', () => new AttributeArgValue('String', ''))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@zenstackhq/sdk",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack plugin development SDK",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@zenstackhq/server",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"displayName": "ZenStack Server-side Adapters",
|
||||
"description": "ZenStack server-side adapters",
|
||||
"homepage": "https://zenstack.dev",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@zenstackhq/testtools",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.1",
|
||||
"description": "ZenStack Test Tools",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { loadModelWithError } from '@zenstackhq/testtools';
|
||||
import { loadModelWithError, loadSchema } from '@zenstackhq/testtools';
|
||||
|
||||
describe('JSON field typing', () => {
|
||||
it('is only supported by postgres', async () => {
|
||||
await expect(
|
||||
loadModelWithError(
|
||||
loadSchema(
|
||||
`
|
||||
type Profile {
|
||||
age Int @gt(0)
|
||||
|
|
@ -16,7 +16,7 @@ describe('JSON field typing', () => {
|
|||
}
|
||||
`
|
||||
)
|
||||
).resolves.toContain('Custom-typed field is only supported with "postgresql" provider');
|
||||
).rejects.toThrow('Datasource provider "sqlite" does not support "@json" fields');
|
||||
});
|
||||
|
||||
it('requires field to have @json attribute', async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue