Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release fix/cleanup-enhance #1083

Closed
Closed
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
16 changes: 8 additions & 8 deletions .github/release/.release-manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
".": "2.0.0-alpha.1",
".": "2.0.0-alpha.2",
"packages/ide/jetbrains": "2.0.0-alpha.2",
"packages/language": "2.0.0-alpha.2",
"packages/misc/redwood": "2.0.0-alpha.2",
"packages/plugins/openapi": "2.0.0-alpha.2",
"packages/plugins/swr": "2.0.0-alpha.2",
"packages/plugins/tanstack-query": "2.0.0-alpha.2",
"packages/plugins/trpc": "2.0.0-alpha.2",
"packages/runtime": "2.0.0-alpha.2",
"packages/sdk": "2.0.0-alpha.2",
"packages/plugins/openapi": "2.0.0-alpha.3",
"packages/plugins/swr": "2.0.0-alpha.3",
"packages/plugins/tanstack-query": "2.0.0-alpha.3",
"packages/plugins/trpc": "2.0.0-alpha.3",
"packages/runtime": "2.0.0-alpha.3",
"packages/sdk": "2.0.0-alpha.3",
"packages/server": "2.0.0-alpha.2",
"packages/testtools": "2.0.0-alpha.2"
"packages/testtools": "2.0.0-alpha.3"
}
24 changes: 20 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# 0.5.0 (2022-12-15)
# Changelog

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([cfcb1f9](https://github.com/zenstackhq/zenstack/commit/cfcb1f9aac4b6622a8897368c6e269d775b78954))
* default auth without user context ([#1015](https://github.com/zenstackhq/zenstack/issues/1015)) ([e5b5a0f](https://github.com/zenstackhq/zenstack/commit/e5b5a0fee34e46bee5557229f6f5894629c6ad96))
* foreign key constraint ambiguity in generated delegate prisma schema ([#1060](https://github.com/zenstackhq/zenstack/issues/1060)) ([ca2a314](https://github.com/zenstackhq/zenstack/commit/ca2a314a927053703e4dbc76542499159b8bf6a8))


### Performance Improvements

* improve polymorphism code generation speed ([#1073](https://github.com/zenstackhq/zenstack/issues/1073)) ([5b103ba](https://github.com/zenstackhq/zenstack/commit/5b103badea7876b7dfc1da91c26eca3213ddd413))

## 0.5.0 (2022-12-15)

### Features

Expand All @@ -12,7 +28,7 @@

- Next-auth adapter and helper are moved to a separate package `@zenstackhq/next-auth`.

# 0.4.0 (2022-12-01)
## 0.4.0 (2022-12-01)

### Features

Expand Down Expand Up @@ -50,7 +66,7 @@

Use @zenstackhq/runtime/types for type definitions shared between client and server, @zenstackhq/runtime/client for client-specific libaries (like React hooks), and @zenstackhq/runtime/server for server-specific libraries.

# 0.3.0 (2022-11-08)
## 0.3.0 (2022-11-08)

### Features

Expand All @@ -70,7 +86,7 @@

- Better overall documentation

# 0.2.0 (2022-10-29)
## 0.2.0 (2022-10-29)

### Features

Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([cfcb1f9](https://github.com/zenstackhq/zenstack/commit/cfcb1f9aac4b6622a8897368c6e269d775b78954))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


Expand Down
2 changes: 1 addition & 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": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/openapi/src/generator-base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions, getDataModels, hasAttribute } from '@zenstackhq/sdk';
import { PluginError, PluginOptions, PluginResult, getDataModels, hasAttribute } from '@zenstackhq/sdk';
import { Model } from '@zenstackhq/sdk/ast';
import type { OpenAPIV3_1 as OAPI } from 'openapi-types';
import semver from 'semver';
Expand All @@ -12,7 +12,7 @@ export abstract class OpenAPIGeneratorBase {

constructor(protected model: Model, protected options: PluginOptions, protected dmmf: DMMF.Document) {}

abstract generate(): string[];
abstract generate(): PluginResult;

protected get includedModels() {
return getDataModels(this.model).filter((d) => !hasAttribute(d, '@@openapi.ignore'));
Expand Down
14 changes: 9 additions & 5 deletions packages/plugins/openapi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions } from '@zenstackhq/sdk';
import { Model } from '@zenstackhq/sdk/ast';
import { PluginError, PluginFunction } from '@zenstackhq/sdk';
import { RESTfulOpenAPIGenerator } from './rest-generator';
import { RPCOpenAPIGenerator } from './rpc-generator';

export const name = 'OpenAPI';

export default async function run(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
const run: PluginFunction = async (model, options, dmmf) => {
if (!dmmf) {
throw new Error('DMMF is required');
}

const flavor = options.flavor ? (options.flavor as string) : 'rpc';

switch (flavor) {
Expand All @@ -17,4 +19,6 @@ export default async function run(model: Model, options: PluginOptions, dmmf: DM
default:
throw new PluginError(name, `Unknown flavor: ${flavor}`);
}
}
};

export default run;
2 changes: 1 addition & 1 deletion packages/plugins/openapi/src/rest-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
fs.writeFileSync(output, JSON.stringify(openapi, undefined, 2));
}

return this.warnings;
return { warnings: this.warnings };
}

private generatePaths(): OAPI.PathsObject {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/openapi/src/rpc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
fs.writeFileSync(output, JSON.stringify(openapi, undefined, 2));
}

return this.warnings;
return { warnings: this.warnings };
}

private generatePaths(components: OAPI.ComponentsObject): OAPI.PathsObject {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/swr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([cfcb1f9](https://github.com/zenstackhq/zenstack/commit/cfcb1f9aac4b6622a8897368c6e269d775b78954))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/swr",
"displayName": "ZenStack plugin for generating SWR hooks",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
Expand Down
9 changes: 5 additions & 4 deletions packages/plugins/swr/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,27 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
warnings.push(`Unable to find mapping for model ${dataModel.name}`);
return;
}
generateModelHooks(project, outDir, dataModel, mapping, legacyMutations);
generateModelHooks(project, outDir, dataModel, mapping, legacyMutations, options);
});

await saveProject(project);
return warnings;
return { warnings };
}

function generateModelHooks(
project: Project,
outDir: string,
model: DataModel,
mapping: DMMF.ModelMapping,
legacyMutations: boolean
legacyMutations: boolean,
options: PluginOptions
) {
const fileName = paramCase(model.name);
const sf = project.createSourceFile(path.join(outDir, `${fileName}.ts`), undefined, { overwrite: true });

sf.addStatements('/* eslint-disable */');

const prismaImport = getPrismaClientImportSpec(model.$container, outDir);
const prismaImport = getPrismaClientImportSpec(outDir, options);
sf.addImportDeclaration({
namedImports: ['Prisma'],
isTypeOnly: true,
Expand Down
13 changes: 8 additions & 5 deletions packages/plugins/swr/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { DMMF } from '@prisma/generator-helper';
import type { PluginOptions } from '@zenstackhq/sdk';
import type { Model } from '@zenstackhq/sdk/ast';
import type { PluginFunction } from '@zenstackhq/sdk';
import { generate } from './generator';

export const name = 'SWR';

export default async function run(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
const run: PluginFunction = async (model, options, dmmf) => {
if (!dmmf) {
throw new Error('DMMF is required');
}
return generate(model, options, dmmf);
}
};

export default run;
7 changes: 7 additions & 0 deletions packages/plugins/tanstack-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([cfcb1f9](https://github.com/zenstackhq/zenstack/commit/cfcb1f9aac4b6622a8897368c6e269d775b78954))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack plugin for generating tanstack-query hooks",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
Expand Down
9 changes: 5 additions & 4 deletions packages/plugins/tanstack-query/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
warnings.push(`Unable to find mapping for model ${dataModel.name}`);
return;
}
generateModelHooks(target, version, project, outDir, dataModel, mapping);
generateModelHooks(target, version, project, outDir, dataModel, mapping, options);
});

await saveProject(project);
return warnings;
return { warnings };
}

function generateQueryHook(
Expand Down Expand Up @@ -286,7 +286,8 @@ function generateModelHooks(
project: Project,
outDir: string,
model: DataModel,
mapping: DMMF.ModelMapping
mapping: DMMF.ModelMapping,
options: PluginOptions
) {
const modelNameCap = upperCaseFirst(model.name);
const prismaVersion = getPrismaVersion();
Expand All @@ -295,7 +296,7 @@ function generateModelHooks(

sf.addStatements('/* eslint-disable */');

const prismaImport = getPrismaClientImportSpec(model.$container, outDir);
const prismaImport = getPrismaClientImportSpec(outDir, options);
sf.addImportDeclaration({
namedImports: ['Prisma', model.name],
isTypeOnly: true,
Expand Down
13 changes: 8 additions & 5 deletions packages/plugins/tanstack-query/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { DMMF } from '@prisma/generator-helper';
import type { PluginOptions } from '@zenstackhq/sdk';
import type { Model } from '@zenstackhq/sdk/ast';
import type { PluginFunction } from '@zenstackhq/sdk';
import { generate } from './generator';

export const name = 'Tanstack Query';

export default async function run(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
const run: PluginFunction = async (model, options, dmmf) => {
if (!dmmf) {
throw new Error('DMMF is required');
}
return generate(model, options, dmmf);
}
};

export default run;
7 changes: 7 additions & 0 deletions packages/plugins/trpc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([cfcb1f9](https://github.com/zenstackhq/zenstack/commit/cfcb1f9aac4b6622a8897368c6e269d775b78954))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


Expand Down
2 changes: 1 addition & 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": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
18 changes: 10 additions & 8 deletions packages/plugins/trpc/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
generateModelActions,
generateClientHelpers,
model,
zodSchemasImport
zodSchemasImport,
options
);
createHelper(outDir);

Expand All @@ -86,7 +87,8 @@ function createAppRouter(
generateModelActions: string[] | undefined,
generateClientHelpers: string[] | undefined,
zmodel: Model,
zodSchemasImport: string
zodSchemasImport: string,
options: PluginOptions
) {
const indexFile = path.resolve(outDir, 'routers', `index.ts`);
const appRouter = project.createSourceFile(indexFile, undefined, {
Expand All @@ -95,7 +97,7 @@ function createAppRouter(

appRouter.addStatements('/* eslint-disable */');

const prismaImport = getPrismaClientImportSpec(zmodel, path.dirname(indexFile));
const prismaImport = getPrismaClientImportSpec(path.dirname(indexFile), options);
appRouter.addImportDeclarations([
{
namedImports: [
Expand Down Expand Up @@ -169,8 +171,8 @@ function createAppRouter(
outDir,
generateModelActions,
generateClientHelpers,
zmodel,
zodSchemasImport
zodSchemasImport,
options
);

appRouter.addImportDeclaration({
Expand Down Expand Up @@ -239,8 +241,8 @@ function generateModelCreateRouter(
outputDir: string,
generateModelActions: string[] | undefined,
generateClientHelpers: string[] | undefined,
zmodel: Model,
zodSchemasImport: string
zodSchemasImport: string,
options: PluginOptions
) {
const modelRouter = project.createSourceFile(path.resolve(outputDir, 'routers', `${model}.router.ts`), undefined, {
overwrite: true,
Expand All @@ -258,7 +260,7 @@ function generateModelCreateRouter(
generateRouterSchemaImport(modelRouter, zodSchemasImport);
generateHelperImport(modelRouter);
if (generateClientHelpers) {
generateRouterTypingImports(modelRouter, zmodel);
generateRouterTypingImports(modelRouter, options);
}

const createRouterFunc = modelRouter.addFunction({
Expand Down
Loading