Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install"
// "postCreateCommand": "pnpm install",
"postCreateCommand": "bash -lc 'set -euo pipefail; sudo npm -g i n; sudo n lts; hash -r; npm -g i npm@latest; corepack enable; corepack prepare pnpm@latest --activate; npm -g i typescript npm-check-updates; pnpm install'"
}
2 changes: 2 additions & 0 deletions MY-CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ToDo

Comment thread
codebypk marked this conversation as resolved.
Outdated
33 changes: 20 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zenstack-v3",
"version": "3.2.1",
"description": "ZenStack",
"packageManager": "pnpm@10.23.0",
"packageManager": "pnpm@10.28.0",
"type": "module",
"scripts": {
"build": "turbo run build",
Expand All @@ -26,28 +26,35 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@eslint/js": "^9.29.0",
"@eslint/js": "^9.39.2",
"@types/node": "catalog:",
"@vitest/coverage-v8": "^4.0.16",
"eslint": "~9.29.0",
"glob": "^11.1.0",
"@vitest/coverage-v8": "^4.0.17",
"eslint": "^9.39.2",
"glob": "^13.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.5.3",
"prettier": "^3.8.0",
"prisma": "catalog:",
"tsup": "^8.5.0",
"tsx": "^4.20.3",
"turbo": "^2.5.4",
"tsup": "^8.5.1",
"tsx": "^4.21.0",
"turbo": "^2.7.4",
"typescript": "catalog:",
"typescript-eslint": "^8.34.1",
"vitest": "^4.0.14",
"yaml": "^2.8.0"
"typescript-eslint": "^8.53.0",
"vitest": "^4.0.17",
"yaml": "^2.8.2"
Comment thread
codebypk marked this conversation as resolved.
},
"pnpm": {
"onlyBuiltDependencies": [
"@parcel/watcher",
"better-sqlite3",
"esbuild",
"vue-demi"
]
],
"packageExtensions": {
"@sveltejs/package@*": {
"dependencies": {
"typescript": "^5.9.3"
}
}
}
}
}
8 changes: 4 additions & 4 deletions packages/auth-adapters/better-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"ts-pattern": "catalog:"
},
"peerDependencies": {
"@better-auth/core": "^1.3.0",
"better-auth": "^1.3.0"
"@better-auth/core": "^1.4.13",
"better-auth": "^1.4.13"
},
"devDependencies": {
"@better-auth/core": "^1.3.0",
"better-auth": "^1.3.0",
"@better-auth/core": "^1.4.13",
"better-auth": "^1.4.13",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/vitest-config": "workspace:*"
Expand Down
10 changes: 7 additions & 3 deletions packages/auth-adapters/better-auth/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { BetterAuthOptions } from '@better-auth/core';
import type { DBAdapter, DBAdapterDebugLogOption, Where } from '@better-auth/core/db/adapter';
import { BetterAuthError } from '@better-auth/core/error';
//import type { BetterAuthOptions } from '@better-auth/core';
//import type { DBAdapter, DBAdapterDebugLogOption, Where } from '@better-auth/core/db/adapter';
//import { BetterAuthError } from '@better-auth/core/error';
import type { ClientContract, ModelOperations, UpdateInput } from '@zenstackhq/orm';
import type { GetModels, SchemaDef } from '@zenstackhq/orm/schema';
import { BetterAuthError } from 'better-auth';
import type { BetterAuthOptions, DBAdapter, Where } from 'better-auth';
import {
createAdapterFactory,
type AdapterFactoryCustomizeAdapterCreator,
type AdapterFactoryOptions,
} from 'better-auth/adapters';
import type { DBAdapterDebugLogOption } from '@better-auth/core/db/adapter';
Comment thread
codebypk marked this conversation as resolved.
import { generateSchema } from './schema-generator';


/**
* Options for the ZenStack adapter factory.
*/
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
"@zenstackhq/sdk": "workspace:*",
"chokidar": "^5.0.0",
"colors": "1.4.0",
"commander": "^8.3.0",
"execa": "^9.6.0",
"commander": "^14.0.2",
"execa": "^9.6.1",
"jiti": "^2.6.1",
"langium": "catalog:",
"mixpanel": "^0.18.1",
"ora": "^5.4.1",
"package-manager-detector": "^1.3.0",
"mixpanel": "^0.20.0",
"ora": "^9.0.0",
"package-manager-detector": "^1.6.0",
"prisma": "catalog:",
"semver": "^7.7.2",
"semver": "^7.7.3",
"ts-pattern": "catalog:"
},
"devDependencies": {
"@types/better-sqlite3": "catalog:",
"@types/semver": "^7.7.0",
"@types/semver": "^7.7.1",
"@types/tmp": "catalog:",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/orm": "workspace:*",
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/utils/exec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { fileURLToPath } from 'url';
export function execSync(cmd: string, options?: Omit<ExecSyncOptions, 'env'> & { env?: Record<string, string> }): void {
const { env, ...restOptions } = options ?? {};
const mergedEnv = env ? { ...process.env, ...env } : undefined;

// In non-interactive environments (e.g. vitest, CI), some CLIs (including Prisma)
// may try to prompt and wait for stdin forever. Closing stdin avoids hangs.
const defaultStdio: ExecSyncOptions['stdio'] = process.stdin.isTTY ? 'inherit' : ['ignore', 'inherit', 'inherit'];
_exec(cmd, {
encoding: 'utf-8',
stdio: options?.stdio ?? 'inherit',
stdio: options?.stdio ?? defaultStdio,
env: mergedEnv,
...restOptions,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('CLI migrate commands test', () => {

// --applied
runCli(`migrate resolve --applied ${migration}`, workDir);
});
},200000);

it('should throw error when neither applied nor rolled-back is provided', () => {
const workDir = createProject(model);
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/client-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@zenstackhq/common-helpers": "workspace:*",
"@zenstackhq/schema": "workspace:*",
"decimal.js": "catalog:",
"superjson": "^2.2.3"
"superjson": "^2.2.6"
},
"devDependencies": {
"@zenstackhq/eslint-config": "workspace:*",
Expand Down
11 changes: 6 additions & 5 deletions packages/clients/tanstack-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@tanstack/svelte-query": "catalog:",
"@tanstack/vue-query": "catalog:",
"@testing-library/dom": "^10.4.1",
"@testing-library/react": "^16.3.0",
"@testing-library/react": "^16.3.1",
"@types/react": "catalog:",
"@zenstackhq/cli": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*",
Expand All @@ -65,17 +65,18 @@
"@zenstackhq/sdk": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/vitest-config": "workspace:*",
"happy-dom": "^20.0.10",
"happy-dom": "^20.3.1",
"nock": "^14.0.10",
"react": "catalog:",
"svelte": "catalog:",
"vue": "catalog:",
"typescript": "catalog:",
"@sveltejs/package": "^2.5.7"
},
"peerDependencies": {
"@tanstack/react-query": "^5.0.0",
"@tanstack/svelte-query": "^6.0.0",
"@tanstack/vue-query": "^5.0.0"
"@tanstack/react-query": "^5.90.17",
"@tanstack/svelte-query": "^6.0.15",
"@tanstack/vue-query": "^5.92.6"
},
"peerDependenciesMeta": {
"@tanstack/react-query": {
Expand Down
52 changes: 33 additions & 19 deletions packages/clients/tanstack-query/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type UseQueryOptions,
type UseQueryReturnType,
} from '@tanstack/vue-query';
import type { MutationObserverOptions } from '@tanstack/query-core';
import {
createInvalidator,
createOptimisticUpdater,
Expand Down Expand Up @@ -116,7 +117,7 @@ export type ModelInfiniteQueryOptions<T> = MaybeRefOrGetter<
export type ModelInfiniteQueryResult<T> = UseInfiniteQueryReturnType<T, DefaultError> & { queryKey: Ref<QueryKey> };

export type ModelMutationOptions<T, TArgs> = MaybeRefOrGetter<
Omit<UnwrapRef<UseMutationOptions<T, DefaultError, TArgs>>, 'mutationFn'> & ExtraMutationOptions
Omit<MutationObserverOptions<T, DefaultError, TArgs, unknown>, 'mutationFn'> & ExtraMutationOptions
>;

export type ModelMutationResult<T, TArgs> = UseMutationReturnType<T, DefaultError, TArgs, unknown>;
Expand All @@ -137,6 +138,12 @@ export type ModelMutationModelResult<
): Promise<SimplifiedResult<Schema, Model, T, Options, false, Array>>;
};

type MutationLifecycleOptions<R, TArgs> = MutationObserverOptions<R, DefaultError, TArgs, unknown>;
type ResolvedMutationOptions<R, TArgs> = MutationLifecycleOptions<R, TArgs> & ExtraMutationOptions;
type MutationCallbackParams<R, TArgs, K extends 'onSuccess' | 'onMutate' | 'onSettled'> = Parameters<
NonNullable<MutationLifecycleOptions<R, TArgs>[K]>
>;

export type ClientHooks<Schema extends SchemaDef, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
[Model in GetModels<Schema> as `${Uncapitalize<Model>}`]: ModelQueryHooks<Schema, Model, Options>;
} & ProcedureHooks<Schema>;
Expand Down Expand Up @@ -536,7 +543,7 @@ export function useInternalMutation<TArgs, R = any>(
method: 'POST' | 'PUT' | 'DELETE',
operation: string,
options?: MaybeRefOrGetter<
Omit<UnwrapRef<UseMutationOptions<R, DefaultError, TArgs>>, 'mutationFn'> & ExtraMutationOptions
Omit<MutationLifecycleOptions<R, TArgs>, 'mutationFn'> & ExtraMutationOptions
>,
) {
const queryClient = useQueryClient();
Expand All @@ -558,18 +565,19 @@ export function useInternalMutation<TArgs, R = any>(
};

// reactive mutation options
const finalOptions = computed(() => {
const optionsValue = toValue(options);
const result = {
...optionsValue,
const finalOptions = computed<ResolvedMutationOptions<R, TArgs>>(() => {
const optionsValue = toValue(options) as Partial<ResolvedMutationOptions<R, TArgs>> | undefined;
const userOptions = optionsValue ?? {};
const result: ResolvedMutationOptions<R, TArgs> = {
...userOptions,
mutationFn,
} as UnwrapRef<UseMutationOptions<R, DefaultError, TArgs>> & ExtraMutationOptions;
};

if (model !== CUSTOM_PROC_ROUTE_NAME) {
// not a custom procedure, set up optimistic update and invalidation

const invalidateQueries = optionsValue?.invalidateQueries !== false;
const optimisticUpdate = !!optionsValue?.optimisticUpdate;
const invalidateQueries = userOptions.invalidateQueries !== false;
const optimisticUpdate = !!userOptions.optimisticUpdate;

if (!optimisticUpdate) {
if (invalidateQueries) {
Expand All @@ -582,10 +590,12 @@ export function useInternalMutation<TArgs, R = any>(
logging,
);
// execute invalidator prior to user-provided onSuccess
result.onSuccess = async (...args) => {
const userOnSuccess = result.onSuccess;
result.onSuccess = async (
...args: MutationCallbackParams<R, TArgs, 'onSuccess'>
) => {
await invalidator(...args);
const origOnSuccess: any = toValue(optionsValue?.onSuccess);
await origOnSuccess?.(...args);
await unref(userOnSuccess)?.(...args);
};
}
} else {
Expand All @@ -599,13 +609,15 @@ export function useInternalMutation<TArgs, R = any>(
);

// optimistic update on mutate
const origOnMutate = result.onMutate;
result.onMutate = async (...args) => {
const userOnMutate = result.onMutate;
result.onMutate = async (
...args: MutationCallbackParams<R, TArgs, 'onMutate'>
) => {
// execute optimistic updater prior to user-provided onMutate
await optimisticUpdater(...args);

// call user-provided onMutate
return unref(origOnMutate)?.(...args);
return unref(userOnMutate)?.(...args);
};

if (invalidateQueries) {
Expand All @@ -617,13 +629,15 @@ export function useInternalMutation<TArgs, R = any>(
invalidateQueriesMatchingPredicate(queryClient, predicate),
logging,
);
const origOnSettled = result.onSettled;
result.onSettled = async (...args) => {
const userOnSettled = result.onSettled;
result.onSettled = async (
...args: MutationCallbackParams<R, TArgs, 'onSettled'>
) => {
// execute invalidator prior to user-provided onSettled
await invalidator(...args);

// call user-provided onSettled
return unref(origOnSettled)?.(...args);
return unref(userOnSettled)?.(...args);
};
}
}
Expand All @@ -632,7 +646,7 @@ export function useInternalMutation<TArgs, R = any>(
return result;
});

return useMutation(finalOptions);
return useMutation(() => finalOptions.value);
}

function useFetchOptions(options: MaybeRefOrGetter<QueryContext | undefined>) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-zenstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"dependencies": {
"colors": "1.4.0",
"commander": "^8.3.0",
"ora": "^5.4.1"
"commander": "^14.0.2",
"ora": "^9.0.0"
},
"devDependencies": {
"@zenstackhq/eslint-config": "workspace:*",
Expand Down
Loading