Skip to content

Commit

Permalink
merge dev to main (v1.12.0) (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Mar 31, 2024
2 parents ac60a6a + 759a0e2 commit dfa6cb4
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 107 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/update-samples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Update Samples

on:
release:
types: [published]

jobs:
dispatch:
runs-on: ubuntu-latest

strategy:
matrix:
repo:
[
'zenstackhq/sample-todo-nextjs',
'zenstackhq/sample-todo-nextjs-tanstack',
'zenstackhq/sample-todo-trpc',
'zenstackhq/sample-todo-sveltekit',
]

steps:
- name: Repository Dispatch
uses: peter-evans/[email protected]
with:
token: ${{ secrets.RELEASE_TRIGGER_TOKEN }}
repository: ${{ matrix.repo }}
event-type: zenstack-release
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.11.1",
"version": "1.12.0",
"description": "",
"scripts": {
"build": "pnpm -r 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 = "1.11.1"
version = "1.12.0"

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": "1.11.1",
"version": "1.12.0",
"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": "1.11.1",
"version": "1.12.0",
"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": "1.11.1",
"version": "1.12.0",
"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": "1.11.1",
"version": "1.12.0",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/openapi/tests/openapi-restful.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import * as tmp from 'tmp';
import YAML from 'yaml';
import generate from '../src';

tmp.setGracefulCleanup();

describe('Open API Plugin RESTful Tests', () => {
it('run plugin', async () => {
for (const specVersion of ['3.0.0', '3.1.0']) {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/openapi/tests/openapi-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import * as tmp from 'tmp';
import YAML from 'yaml';
import generate from '../src';

tmp.setGracefulCleanup();

describe('Open API Plugin RPC Tests', () => {
it('run plugin', async () => {
for (const specVersion of ['3.0.0', '3.1.0']) {
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": "1.11.1",
"version": "1.12.0",
"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": "1.11.1",
"version": "1.12.0",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
Expand Down
26 changes: 21 additions & 5 deletions packages/plugins/tanstack-query/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function generateQueryHook(
const capOperation = upperCaseFirst(operation);

const argsType = overrideInputType ?? `Prisma.${model}${capOperation}Args`;
const inputType = `Prisma.SelectSubset<TArgs, ${argsType}>`;
const inputType = makeQueryArgsType(target, argsType);

const infinite = generateMode.includes('Infinite');
const suspense = generateMode.includes('Suspense');
Expand Down Expand Up @@ -589,6 +589,7 @@ function makeBaseImports(target: TargetFramework, version: TanStackVersion) {
return [
`import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/vue-query';`,
`import { getHooksContext } from '${runtimeImportBase}/${target}';`,
`import type { MaybeRefOrGetter, ComputedRef } from 'vue';`,
...shared,
];
}
Expand All @@ -608,6 +609,15 @@ function makeBaseImports(target: TargetFramework, version: TanStackVersion) {
}
}

function makeQueryArgsType(target: string, argsType: string) {
const type = `Prisma.SelectSubset<TArgs, ${argsType}>`;
if (target === 'vue') {
return `MaybeRefOrGetter<${type}> | ComputedRef<${type}>`;
} else {
return type;
}
}

function makeQueryOptions(
target: string,
returnType: string,
Expand All @@ -625,8 +635,12 @@ function makeQueryOptions(
suspense ? 'Suspense' : ''
}InfiniteQueryOptions<${returnType}, TError, InfiniteData<${dataType}>>, 'queryKey'>`
: `Omit<Use${suspense ? 'Suspense' : ''}QueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`;
case 'vue':
return `Omit<Use${infinite ? 'Infinite' : ''}QueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`;
case 'vue': {
const baseOption = `Omit<Use${
infinite ? 'Infinite' : ''
}QueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`;
return `MaybeRefOrGetter<${baseOption}> | ComputedRef<${baseOption}>`;
}
case 'svelte':
return infinite
? version === 'v4'
Expand All @@ -644,8 +658,10 @@ function makeMutationOptions(target: string, returnType: string, argsType: strin
switch (target) {
case 'react':
return `UseMutationOptions<${returnType}, DefaultError, ${argsType}>`;
case 'vue':
return `UseMutationOptions<${returnType}, DefaultError, ${argsType}, unknown>`;
case 'vue': {
const baseOption = `UseMutationOptions<${returnType}, DefaultError, ${argsType}, unknown>`;
return `MaybeRefOrGetter<${baseOption}> | ComputedRef<${baseOption}>`;
}
case 'svelte':
return `MutationOptions<${returnType}, DefaultError, ${argsType}>`;
default:
Expand Down
58 changes: 38 additions & 20 deletions packages/plugins/tanstack-query/src/runtime/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
useMutation,
useQuery,
useQueryClient,
type QueryKey,
type UseInfiniteQueryOptions,
type UseMutationOptions,
type UseQueryOptions,
} from '@tanstack/vue-query';
import type { ModelMeta } from '@zenstackhq/runtime/cross';
import { inject, provide } from 'vue';
import { computed, inject, provide, toValue, type ComputedRef, type MaybeRefOrGetter } from 'vue';
import {
APIContext,
DEFAULT_QUERY_ENDPOINT,
Expand Down Expand Up @@ -60,17 +61,25 @@ export function getHooksContext() {
export function useModelQuery<TQueryFnData, TData, TError>(
model: string,
url: string,
args?: unknown,
options?: Omit<UseQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>,
args?: MaybeRefOrGetter<unknown> | ComputedRef<unknown>,
options?:
| MaybeRefOrGetter<Omit<UseQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>>
| ComputedRef<Omit<UseQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>>,
fetch?: FetchFn,
optimisticUpdate = false
) {
const reqUrl = makeUrl(url, args);
return useQuery<TQueryFnData, TError, TData>({
queryKey: getQueryKey(model, url, args, false, optimisticUpdate),
queryFn: () => fetcher<TQueryFnData, false>(reqUrl, undefined, fetch, false),
...options,
const queryOptions = computed(() => {
return {
queryKey: getQueryKey(model, url, toValue(args), false, optimisticUpdate),
queryFn: ({ queryKey }: { queryKey: QueryKey }) => {
const [_prefix, _model, _op, args] = queryKey;
const reqUrl = makeUrl(url, toValue(args));
return fetcher<TQueryFnData, false>(reqUrl, undefined, fetch, false);
},
...toValue(options),
};
});
return useQuery<TQueryFnData, TError, TData>(queryOptions);
}

/**
Expand All @@ -86,17 +95,24 @@ export function useModelQuery<TQueryFnData, TData, TError>(
export function useInfiniteModelQuery<TQueryFnData, TData, TError>(
model: string,
url: string,
args?: unknown,
options?: Omit<UseInfiniteQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>,
args?: MaybeRefOrGetter<unknown> | ComputedRef<unknown>,
options?:
| MaybeRefOrGetter<Omit<UseInfiniteQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>>
| ComputedRef<Omit<UseInfiniteQueryOptions<TQueryFnData, TError, TData>, 'queryKey'>>,
fetch?: FetchFn
) {
return useInfiniteQuery<TQueryFnData, TError, TData>({
queryKey: getQueryKey(model, url, args, true),
queryFn: ({ pageParam }) => {
return fetcher<TQueryFnData, false>(makeUrl(url, pageParam ?? args), undefined, fetch, false);
// CHECKME: vue-query's `useInfiniteQuery`'s input typing seems wrong
const queryOptions: any = computed(() => ({
queryKey: getQueryKey(model, url, toValue(args), true),
queryFn: ({ queryKey, pageParam }: { queryKey: QueryKey; pageParam?: unknown }) => {
const [_prefix, _model, _op, args] = queryKey;
const reqUrl = makeUrl(url, pageParam ?? toValue(args));
return fetcher<TQueryFnData, false>(reqUrl, undefined, fetch, false);
},
...options,
});
...toValue(options),
}));

return useInfiniteQuery<TQueryFnData, TError, TData>(queryOptions);
}

/**
Expand Down Expand Up @@ -124,7 +140,9 @@ export function useModelMutation<
method: 'POST' | 'PUT' | 'DELETE',
url: string,
modelMeta: ModelMeta,
options?: Omit<UseMutationOptions<Result, TError, TArgs, unknown>, 'mutationFn'>,
options?:
| MaybeRefOrGetter<Omit<UseMutationOptions<Result, TError, TArgs, unknown>, 'mutationFn'>>
| ComputedRef<Omit<UseMutationOptions<Result, TError, TArgs, unknown>, 'mutationFn'>>,
fetch?: FetchFn,
invalidateQueries = true,
checkReadBack?: C,
Expand All @@ -146,7 +164,7 @@ export function useModelMutation<
};

// TODO: figure out the typing problem
const finalOptions: any = { ...options, mutationFn };
const finalOptions: any = computed(() => ({ ...toValue(options), mutationFn }));
const operation = url.split('/').pop();
if (operation) {
const { logging } = getHooksContext();
Expand All @@ -155,7 +173,7 @@ export function useModelMutation<
model,
operation,
modelMeta,
finalOptions,
toValue(finalOptions),
(predicate) => queryClient.invalidateQueries({ predicate }),
logging
);
Expand All @@ -166,7 +184,7 @@ export function useModelMutation<
model,
operation,
modelMeta,
finalOptions,
toValue(finalOptions),
queryClient.getQueryCache().getAll(),
(queryKey, data) => queryClient.setQueryData<unknown>(queryKey, data),
invalidateQueries ? (predicate) => queryClient.invalidateQueries({ predicate }) : undefined,
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": "1.11.1",
"version": "1.12.0",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/trpc/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function generateRouterTypingImports(sourceFile: SourceFile, model: Model

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function generateRouterSchemaImport(sourceFile: SourceFile, zodSchemasImport: string) {
sourceFile.addStatements(`import $Schema from '${zodSchemasImport}/input';`);
sourceFile.addStatements(`import * as $Schema from '${zodSchemasImport}/input';`);
}

export function generateHelperImport(sourceFile: SourceFile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { type RouterFactory, type ProcBuilder, type BaseConfig, db } from '.';
import $Schema from '@zenstackhq/runtime/zod/input';
import * as $Schema from '@zenstackhq/runtime/zod/input';
import { checkRead, checkMutate } from '../helper';
import type { Prisma } from '@prisma/client';
import type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { type RouterFactory, type ProcBuilder, type BaseConfig, db } from '.';
import $Schema from '@zenstackhq/runtime/zod/input';
import * as $Schema from '@zenstackhq/runtime/zod/input';
import { checkRead, checkMutate } from '../helper';
import type { Prisma } from '@prisma/client';
import type {
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": "1.11.1",
"version": "1.12.0",
"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": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database",
"version": "1.11.1",
"version": "1.12.0",
"author": {
"name": "ZenStack Team"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/schema/tests/generator/expression-writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Project, VariableDeclarationKind } from 'ts-morph';
import { ExpressionWriter } from '../../src/plugins/access-policy/expression-writer';
import { loadModel } from '../utils';

tmp.setGracefulCleanup();

describe('Expression Writer Tests', () => {
it('boolean literal', async () => {
await check(
Expand Down
2 changes: 2 additions & 0 deletions packages/schema/tests/generator/prisma-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { loadDocument } from '../../src/cli/cli-util';
import PrismaSchemaGenerator from '../../src/plugins/prisma/schema-generator';
import { loadModel } from '../utils';

tmp.setGracefulCleanup();

describe('Prisma generator test', () => {
it('datasource coverage', async () => {
const model = await loadModel(`
Expand Down
Loading

0 comments on commit dfa6cb4

Please sign in to comment.