Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ The following diagram gives a high-level overview of how it works.
### Prisma schema extensions

- [Custom attributes and functions](https://zenstack.dev/docs/reference/zmodel-language#custom-attributes-and-functions)
- Multi-file schema (coming soon)
- String-typed JSON field (coming soon)
- [Multi-file schema and model inheritance](https://zenstack.dev/docs/guides/multiple-schema)
- Strong-typed JSON field (coming soon)
- 🙋🏻 [Request for an extension](https://go.zenstack.dev/chat)

## Examples
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
return reflection.isInstance(item, ReferenceTarget);
}

export type RegularID = 'in' | string;
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'in' | 'model' | 'plugin' | 'sort' | string;

export type TypeDeclaration = DataModel | Enum;

Expand Down
28 changes: 28 additions & 0 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2449,9 +2449,37 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
},
"arguments": []
},
{
"$type": "Keyword",
"value": "model"
},
{
"$type": "Keyword",
"value": "enum"
},
{
"$type": "Keyword",
"value": "attribute"
},
{
"$type": "Keyword",
"value": "datasource"
},
{
"$type": "Keyword",
"value": "plugin"
},
{
"$type": "Keyword",
"value": "abstract"
},
{
"$type": "Keyword",
"value": "in"
},
{
"$type": "Keyword",
"value": "sort"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ QualifiedName returns string:
// https://github.com/langium/langium/discussions/1012
RegularID returns string:
// include keywords that we'd like to work as ID in most places
ID | 'in';
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort';

// attribute-level attribute
AttributeAttributeName returns string:
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/next",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"displayName": "ZenStack Next.js integration",
"description": "ZenStack Next.js integration",
"homepage": "https://zenstack.dev",
Expand Down
4 changes: 3 additions & 1 deletion packages/plugins/openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand All @@ -28,6 +28,7 @@
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"change-case": "^4.1.2",
"lower-case-first": "^2.0.2",
"openapi-types": "^12.1.0",
"tiny-invariant": "^1.3.1",
"yaml": "^2.2.1",
Expand All @@ -38,6 +39,7 @@
"@prisma/internals": "^4.7.1",
"@readme/openapi-parser": "^2.4.0",
"@types/jest": "^29.5.0",
"@types/lower-case-first": "^1.0.1",
"@types/tmp": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/openapi/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
AggregateOperationSupport,
resolveAggregateOperationSupport,
} from '@zenstackhq/sdk/dmmf-helpers';
import { camelCase } from 'change-case';
import { lowerCaseFirst } from 'lower-case-first';
import * as fs from 'fs';
import type { OpenAPIV3_1 as OAPI } from 'openapi-types';
import * as path from 'path';
Expand Down Expand Up @@ -84,7 +84,7 @@ export class OpenAPIGenerator {
tags: this.includedModels.map((model) => {
const meta = getModelResourceMeta(model);
return {
name: camelCase(model.name),
name: lowerCaseFirst(model.name),
description: meta?.tagDescription ?? `${model.name} operations`,
};
}),
Expand Down Expand Up @@ -533,7 +533,7 @@ export class OpenAPIGenerator {
const def: OAPI.OperationObject = {
operationId: `${operation}${model.name}`,
description: meta?.description ?? description,
tags: meta?.tags || [camelCase(model.name)],
tags: meta?.tags || [lowerCaseFirst(model.name)],
summary: meta?.summary,
// security priority: operation-level > model-level > inferred
security: meta?.security ?? resourceMeta?.security ?? security,
Expand Down Expand Up @@ -581,7 +581,7 @@ export class OpenAPIGenerator {
}
}

result[`${prefix}/${camelCase(model.name)}/${resolvedPath}`] = {
result[`${prefix}/${lowerCaseFirst(model.name)}/${resolvedPath}`] = {
[resolvedMethod]: def,
};
}
Expand Down
14 changes: 9 additions & 5 deletions packages/plugins/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/react",
"displayName": "ZenStack plugin and runtime for ReactJS",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"description": "ZenStack plugin and runtime for ReactJS",
"main": "index.js",
"repository": {
Expand All @@ -28,26 +28,30 @@
"@zenstackhq/sdk": "workspace:*",
"change-case": "^4.1.2",
"decimal.js": "^10.4.2",
"lower-case-first": "^2.0.2",
"superjson": "^1.11.0",
"ts-morph": "^16.0.0"
"ts-morph": "^16.0.0",
"upper-case-first": "^2.0.2"
},
"peerDependencies": {
"@tanstack/react-query": "4.x",
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18",
"swr": "2.x",
"@tanstack/react-query": "4.x"
"swr": "2.x"
},
"devDependencies": {
"@tanstack/react-query": "^4.28.0",
"@types/jest": "^29.5.0",
"@types/lower-case-first": "^1.0.1",
"@types/react": "^18.0.26",
"@types/tmp": "^0.2.3",
"@types/upper-case-first": "^1.1.2",
"@zenstackhq/testtools": "workspace:*",
"copyfiles": "^2.4.1",
"jest": "^29.5.0",
"rimraf": "^3.0.2",
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18",
"rimraf": "^3.0.2",
"swr": "^2.0.3",
"ts-jest": "^29.0.5",
"typescript": "^4.9.4"
Expand Down
12 changes: 7 additions & 5 deletions packages/plugins/react/src/generator/react-query.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions, createProject, getDataModels, saveProject } from '@zenstackhq/sdk';
import { DataModel, Model } from '@zenstackhq/sdk/ast';
import { camelCase, paramCase, pascalCase } from 'change-case';
import { paramCase } from 'change-case';
import { lowerCaseFirst } from 'lower-case-first';
import * as path from 'path';
import { Project, SourceFile, VariableDeclarationKind } from 'ts-morph';
import { upperCaseFirst } from 'upper-case-first';

export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
let outDir = options.output as string;
Expand Down Expand Up @@ -45,7 +47,7 @@ function generateQueryHook(
overrideInputType?: string,
overrideTypeParameters?: string[]
) {
const capOperation = pascalCase(operation);
const capOperation = upperCaseFirst(operation);

const argsType = overrideInputType ?? `Prisma.${model}${capOperation}Args`;
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
Expand All @@ -71,7 +73,7 @@ function generateQueryHook(

func.addStatements([
'const { endpoint } = useContext(RequestHandlerContext);',
`return request.query<${returnType}>('${model}', \`\${endpoint}/${camelCase(
`return request.query<${returnType}>('${model}', \`\${endpoint}/${lowerCaseFirst(
model
)}/${operation}\`, args, options);`,
]);
Expand All @@ -84,7 +86,7 @@ function generateMutationHook(
httpVerb: 'post' | 'put' | 'delete',
overrideReturnType?: string
) {
const capOperation = pascalCase(operation);
const capOperation = upperCaseFirst(operation);

const argsType = `Prisma.${model}${capOperation}Args`;
const inputType = `Prisma.SelectSubset<T, ${argsType}>`;
Expand Down Expand Up @@ -119,7 +121,7 @@ function generateMutationHook(
initializer: `
request.${httpVerb}Mutation<${argsType}, ${
overrideReturnType ?? model
}>('${model}', \`\${endpoint}/${camelCase(model)}/${operation}\`, options, invalidateQueries)
}>('${model}', \`\${endpoint}/${lowerCaseFirst(model)}/${operation}\`, options, invalidateQueries)
`,
},
],
Expand Down
5 changes: 3 additions & 2 deletions packages/plugins/react/src/generator/swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
saveProject,
} from '@zenstackhq/sdk';
import { DataModel, Model } from '@zenstackhq/sdk/ast';
import { camelCase, paramCase } from 'change-case';
import { paramCase } from 'change-case';
import { lowerCaseFirst } from 'lower-case-first';
import * as path from 'path';
import { Project } from 'ts-morph';

Expand Down Expand Up @@ -79,7 +80,7 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
});

const prefixesToMutate = ['find', 'aggregate', 'count', 'groupBy'];
const modelRouteName = camelCase(model.name);
const modelRouteName = lowerCaseFirst(model.name);

useFunc.addStatements([
'const { endpoint } = useContext(RequestHandlerContext);',
Expand Down
4 changes: 3 additions & 1 deletion packages/plugins/trpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/trpc",
"displayName": "ZenStack plugin for tRPC",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand All @@ -28,13 +28,15 @@
"@prisma/internals": "^4.7.1",
"@zenstackhq/sdk": "workspace:*",
"change-case": "^4.1.2",
"lower-case-first": "^2.0.2",
"prettier": "^2.8.3",
"ts-morph": "^16.0.0",
"tslib": "^2.4.1",
"zod": "3.21.1"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/lower-case-first": "^1.0.1",
"@types/prettier": "^2.7.2",
"@zenstackhq/testtools": "workspace:*",
"copyfiles": "^2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/trpc/src/generator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DMMF } from '@prisma/generator-helper';
import { CrudFailureReason, PluginError, PluginOptions, RUNTIME_PACKAGE, saveProject } from '@zenstackhq/sdk';
import { Model } from '@zenstackhq/sdk/ast';
import { camelCase } from 'change-case';
import { lowerCaseFirst } from 'lower-case-first';
import { promises as fs } from 'fs';
import path from 'path';
import { Project } from 'ts-morph';
Expand Down Expand Up @@ -116,7 +116,7 @@ function createAppRouter(outDir: string, modelOperations: DMMF.ModelMapping[], h
moduleSpecifier: `./${model}.router`,
});

writer.writeLine(`${camelCase(model)}: create${model}Router<Config>(router, procedure),`);
writer.writeLine(`${lowerCaseFirst(model)}: create${model}Router<Config>(router, procedure),`);
}
});
writer.write(');');
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "1.0.0-alpha.113",
"version": "1.0.0-alpha.114",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand All @@ -28,6 +28,7 @@
"colors": "1.4.0",
"decimal.js": "^10.4.2",
"deepcopy": "^2.1.0",
"lower-case-first": "^2.0.2",
"pluralize": "^8.0.0",
"superjson": "^1.11.0",
"tslib": "^2.4.1",
Expand All @@ -45,6 +46,7 @@
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/jest": "^29.5.0",
"@types/lower-case-first": "^1.0.1",
"@types/node": "^14.18.29",
"@types/pluralize": "^0.0.29",
"copyfiles": "^2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/enhancements/model-meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { camelCase } from 'change-case';
import { lowerCaseFirst } from 'lower-case-first';
import { ModelMeta } from './types';

/**
Expand All @@ -17,5 +17,5 @@ export function getDefaultModelMeta(): ModelMeta {
* Resolves a model field to its metadata. Returns undefined if not found.
*/
export function resolveField(modelMeta: ModelMeta, model: string, field: string) {
return modelMeta.fields[camelCase(model)][field];
return modelMeta.fields[lowerCaseFirst(model)][field];
}
Loading