Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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-v3",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "ZenStack",
"packageManager": "[email protected]",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack CLI",
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"type": "module",
"author": {
"name": "ZenStack Team"
Expand Down
2 changes: 1 addition & 1 deletion packages/common-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/common-helpers",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "ZenStack Common Helpers",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-zenstack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-zenstack",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "Create a new ZenStack project",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/dialects/sql.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/kysely-sql-js",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "Kysely dialect for sql.js",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/eslint-config",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"type": "module",
"private": true,
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zenstack",
"publisher": "zenstack",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"displayName": "ZenStack Language Tools",
"description": "VSCode extension for ZenStack ZModel language",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/language",
"description": "ZenStack ZModel language specification",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"license": "MIT",
"author": "ZenStack Team",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/runtime",
"version": "3.0.0-alpha.32",
"version": "3.0.0-alpha.33",
"description": "ZenStack Runtime",
"type": "module",
"scripts": {
Expand Down
56 changes: 55 additions & 1 deletion packages/runtime/src/client/crud/dialects/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { invariant, isPlainObject } from '@zenstackhq/common-helpers';
import type { Expression, ExpressionBuilder, ExpressionWrapper, SqlBool, ValueNode } from 'kysely';
import { expressionBuilder, sql, type SelectQueryBuilder } from 'kysely';
import { match, P } from 'ts-pattern';
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, SchemaDef } from '../../../schema';
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, ModelDef, SchemaDef } from '../../../schema';
import { enumerate } from '../../../utils/enumerate';
import type { OrArray } from '../../../utils/type-utils';
import { AGGREGATE_OPERATORS, DELEGATE_JOINED_FIELD_PREFIX, LOGICAL_COMBINATORS } from '../../constants';
Expand Down Expand Up @@ -963,6 +963,31 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
return result;
}

protected buildModelSelect(
eb: ExpressionBuilder<any, any>,
model: GetModels<Schema>,
subQueryAlias: string,
payload: true | FindArgs<Schema, GetModels<Schema>, true>,
selectAllFields: boolean,
) {
let subQuery = this.buildSelectModel(eb, model, subQueryAlias);

if (selectAllFields) {
subQuery = this.buildSelectAllFields(
model,
subQuery,
typeof payload === 'object' ? payload?.omit : undefined,
subQueryAlias,
);
}

if (payload && typeof payload === 'object') {
subQuery = this.buildFilterSortTake(model, payload, subQuery, subQueryAlias);
}

return subQuery;
}

buildSelectField(
query: SelectQueryBuilder<any, any, any>,
model: string,
Expand Down Expand Up @@ -1115,6 +1140,35 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias, inlineComputedField);
}

protected canJoinWithoutNestedSelect(
modelDef: ModelDef,
payload: boolean | FindArgs<Schema, GetModels<Schema>, true>,
) {
if (modelDef.computedFields) {
// computed fields requires explicit select
return false;
}

if (modelDef.baseModel || modelDef.isDelegate) {
// delegate models require upward/downward joins
return false;
}

if (
typeof payload === 'object' &&
(payload.orderBy ||
payload.skip !== undefined ||
payload.take !== undefined ||
payload.cursor ||
(payload as any).distinct)
) {
// ordering/pagination/distinct needs to be handled before joining
return false;
}

return true;
}

// #endregion

// #region abstract methods
Expand Down
Loading