Skip to content

merge dev to main (v2.14.2) #2113

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

Merged
merged 2 commits into from
May 8, 2025
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
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": "2.14.1",
"version": "2.14.2",
"description": "",
"scripts": {
"build": "pnpm -r --filter=\"!./packages/ide/*\" build",
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "dev.zenstack"
version = "2.14.1"
version = "2.14.2"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetbrains",
"version": "2.14.1",
"version": "2.14.2",
"displayName": "ZenStack JetBrains IDE Plugin",
"description": "ZenStack JetBrains IDE plugin",
"homepage": "https://zenstack.dev",
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": "2.14.1",
"version": "2.14.2",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/redwood",
"displayName": "ZenStack RedwoodJS Integration",
"version": "2.14.1",
"version": "2.14.2",
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
"repository": {
"type": "git",
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.14.1",
"version": "2.14.2",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
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.14.1",
"version": "2.14.2",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
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.14.1",
"version": "2.14.2",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
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.14.1",
"version": "2.14.2",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 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": "2.14.1",
"version": "2.14.2",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "FullStack enhancement for Prisma ORM: seamless integration from database to UI",
"version": "2.14.1",
"version": "2.14.2",
"author": {
"name": "ZenStack Team"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/sdk",
"version": "2.14.1",
"version": "2.14.2",
"description": "ZenStack plugin development SDK",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/server",
"version": "2.14.1",
"version": "2.14.2",
"displayName": "ZenStack Server-side Adapters",
"description": "ZenStack server-side adapters",
"homepage": "https://zenstack.dev",
Expand Down
56 changes: 56 additions & 0 deletions packages/server/src/nestjs/api-handler.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { DbClientContract } from '@zenstackhq/runtime';
import { HttpException, Inject, Injectable, Scope } from "@nestjs/common";
import { HttpAdapterHost, REQUEST } from "@nestjs/core";
import { loadAssets } from "../shared";
import { RPCApiHandler } from '../api/rpc';
import { ENHANCED_PRISMA } from "./zenstack.constants";
import { ApiHandlerOptions } from './interfaces';

/**
* The ZenStack API handler service for NestJS. The service is used to handle API requests
* and forward them to the ZenStack API handler. It is platform agnostic and can be used
* with any HTTP adapter.
*/
@Injectable({ scope: Scope.REQUEST })
export class ApiHandlerService {
constructor(
private readonly httpAdapterHost: HttpAdapterHost,
@Inject(ENHANCED_PRISMA) private readonly prisma: DbClientContract,
@Inject(REQUEST) private readonly request: unknown
) { }

async handleRequest(options?: ApiHandlerOptions): Promise<unknown> {
const { modelMeta, zodSchemas } = loadAssets(options || {});
const requestHandler = options?.handler || RPCApiHandler();
const hostname = this.httpAdapterHost.httpAdapter.getRequestHostname(this.request);
const requestUrl = this.httpAdapterHost.httpAdapter.getRequestUrl(this.request);
// prefix with http:// to make a valid url accepted by URL constructor
const url = new URL(`http://${hostname}${requestUrl}`);
const method = this.httpAdapterHost.httpAdapter.getRequestMethod(this.request);
const path = options?.baseUrl && url.pathname.startsWith(options.baseUrl) ? url.pathname.slice(options.baseUrl.length) : url.pathname;
const searchParams = url.searchParams;
const query = Object.fromEntries(searchParams);
const requestBody = (this.request as { body: unknown }).body;

const response = await requestHandler({
method,
path,
query,
requestBody,
prisma: this.prisma,
modelMeta,
zodSchemas,
logger: options?.logger,
});

// handle handler error
// if response code >= 400 throw nestjs HttpException
// the error response will be generated by nestjs
// caller can use try/catch to deal with this manually also
if (response.status >= 400) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
throw new HttpException(response.body as Record<string, any>, response.status)
}
return response.body
}
}
2 changes: 2 additions & 0 deletions packages/server/src/nestjs/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './zenstack.module';
export * from './api-handler.service';
export * from './zenstack.constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AdapterBaseOptions } from "../../types";

export interface ApiHandlerOptions extends AdapterBaseOptions {
/**
* The base URL for the API handler. This is used to determine the base path for the API requests.
* If you are using the ApiHandlerService in a route with a prefix, you should set this to the prefix.
*
* e.g.
* without baseUrl(API handler default route):
* - RPC API handler: [model]/findMany
* - RESTful API handler: /:type
*
* with baseUrl(/api/crud):
* - RPC API handler: /api/crud/[model]/findMany
* - RESTful API handler: /api/crud/:type
*/
baseUrl?: string;
}
2 changes: 2 additions & 0 deletions packages/server/src/nestjs/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './zenstack-module-options.interface'
export * from './api-handler-options.interface'
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { FactoryProvider, ModuleMetadata, Provider } from "@nestjs/common";

/**
* ZenStack module options.
*/
export interface ZenStackModuleOptions {
/**
* A callback for getting an enhanced `PrismaClient`.
*/
getEnhancedPrisma: (model?: string | symbol) => unknown;
}

/**
* ZenStack module async registration options.
*/
export interface ZenStackModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
/**
* Whether the module is global-scoped.
*/
global?: boolean;

/**
* The token to export the enhanced Prisma service. Default is {@link ENHANCED_PRISMA}.
*/
exportToken?: string;

/**
* The factory function to create the enhancement options.
*/
useFactory: (...args: unknown[]) => Promise<ZenStackModuleOptions> | ZenStackModuleOptions;

/**
* The dependencies to inject into the factory function.
*/
inject?: FactoryProvider['inject'];

/**
* Extra providers to facilitate dependency injection.
*/
extraProviders?: Provider[];
}
4 changes: 4 additions & 0 deletions packages/server/src/nestjs/zenstack.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The default token used to export the enhanced Prisma service.
*/
export const ENHANCED_PRISMA = 'ENHANCED_PRISMA';
49 changes: 3 additions & 46 deletions packages/server/src/nestjs/zenstack.module.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
import { Module, type DynamicModule, type FactoryProvider, type ModuleMetadata, type Provider } from '@nestjs/common';

/**
* The default token used to export the enhanced Prisma service.
*/
export const ENHANCED_PRISMA = 'ENHANCED_PRISMA';

/**
* ZenStack module options.
*/
export interface ZenStackModuleOptions {
/**
* A callback for getting an enhanced `PrismaClient`.
*/
getEnhancedPrisma: (model?: string | symbol ) => unknown;
}

/**
* ZenStack module async registration options.
*/
export interface ZenStackModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
/**
* Whether the module is global-scoped.
*/
global?: boolean;

/**
* The token to export the enhanced Prisma service. Default is {@link ENHANCED_PRISMA}.
*/
exportToken?: string;

/**
* The factory function to create the enhancement options.
*/
useFactory: (...args: unknown[]) => Promise<ZenStackModuleOptions> | ZenStackModuleOptions;

/**
* The dependencies to inject into the factory function.
*/
inject?: FactoryProvider['inject'];

/**
* Extra providers to facilitate dependency injection.
*/
extraProviders?: Provider[];
}
import { Module, type DynamicModule } from '@nestjs/common';
import { ENHANCED_PRISMA } from './zenstack.constants';
import { ZenStackModuleAsyncOptions } from './interfaces';

/**
* The ZenStack module for NestJS. The module exports an enhanced Prisma service,
Expand Down
Loading
Loading