Skip to content

Commit 74bbc28

Browse files
authored
Merge pull request #214 from zenstackhq/dev
merge dev to main (v3.0.0-alpha.33)
2 parents c2d87a8 + 35f875b commit 74bbc28

File tree

24 files changed

+648
-272
lines changed

24 files changed

+648
-272
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-v3",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack CLI",
55
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
6-
"version": "3.0.0-alpha.32",
6+
"version": "3.0.0-alpha.33",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"

packages/common-helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/common-helpers",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"description": "ZenStack Common Helpers",
55
"type": "module",
66
"scripts": {

packages/create-zenstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-zenstack",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"description": "Create a new ZenStack project",
55
"type": "module",
66
"scripts": {

packages/dialects/sql.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/kysely-sql-js",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"description": "Kysely dialect for sql.js",
55
"type": "module",
66
"scripts": {

packages/eslint-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/eslint-config",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"type": "module",
55
"private": true,
66
"license": "MIT"

packages/ide/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zenstack",
33
"publisher": "zenstack",
4-
"version": "3.0.0-alpha.32",
4+
"version": "3.0.0-alpha.33",
55
"displayName": "ZenStack Language Tools",
66
"description": "VSCode extension for ZenStack ZModel language",
77
"private": true,

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/language",
33
"description": "ZenStack ZModel language specification",
4-
"version": "3.0.0-alpha.32",
4+
"version": "3.0.0-alpha.33",
55
"license": "MIT",
66
"author": "ZenStack Team",
77
"files": [

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/runtime",
3-
"version": "3.0.0-alpha.32",
3+
"version": "3.0.0-alpha.33",
44
"description": "ZenStack Runtime",
55
"type": "module",
66
"scripts": {

packages/runtime/src/client/crud/dialects/base.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { invariant, isPlainObject } from '@zenstackhq/common-helpers';
22
import type { Expression, ExpressionBuilder, ExpressionWrapper, SqlBool, ValueNode } from 'kysely';
33
import { expressionBuilder, sql, type SelectQueryBuilder } from 'kysely';
44
import { match, P } from 'ts-pattern';
5-
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, SchemaDef } from '../../../schema';
5+
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, ModelDef, SchemaDef } from '../../../schema';
66
import { enumerate } from '../../../utils/enumerate';
77
import type { OrArray } from '../../../utils/type-utils';
88
import { AGGREGATE_OPERATORS, DELEGATE_JOINED_FIELD_PREFIX, LOGICAL_COMBINATORS } from '../../constants';
@@ -963,6 +963,31 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
963963
return result;
964964
}
965965

966+
protected buildModelSelect(
967+
eb: ExpressionBuilder<any, any>,
968+
model: GetModels<Schema>,
969+
subQueryAlias: string,
970+
payload: true | FindArgs<Schema, GetModels<Schema>, true>,
971+
selectAllFields: boolean,
972+
) {
973+
let subQuery = this.buildSelectModel(eb, model, subQueryAlias);
974+
975+
if (selectAllFields) {
976+
subQuery = this.buildSelectAllFields(
977+
model,
978+
subQuery,
979+
typeof payload === 'object' ? payload?.omit : undefined,
980+
subQueryAlias,
981+
);
982+
}
983+
984+
if (payload && typeof payload === 'object') {
985+
subQuery = this.buildFilterSortTake(model, payload, subQuery, subQueryAlias);
986+
}
987+
988+
return subQuery;
989+
}
990+
966991
buildSelectField(
967992
query: SelectQueryBuilder<any, any, any>,
968993
model: string,
@@ -1115,6 +1140,35 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
11151140
return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias, inlineComputedField);
11161141
}
11171142

1143+
protected canJoinWithoutNestedSelect(
1144+
modelDef: ModelDef,
1145+
payload: boolean | FindArgs<Schema, GetModels<Schema>, true>,
1146+
) {
1147+
if (modelDef.computedFields) {
1148+
// computed fields requires explicit select
1149+
return false;
1150+
}
1151+
1152+
if (modelDef.baseModel || modelDef.isDelegate) {
1153+
// delegate models require upward/downward joins
1154+
return false;
1155+
}
1156+
1157+
if (
1158+
typeof payload === 'object' &&
1159+
(payload.orderBy ||
1160+
payload.skip !== undefined ||
1161+
payload.take !== undefined ||
1162+
payload.cursor ||
1163+
(payload as any).distinct)
1164+
) {
1165+
// ordering/pagination/distinct needs to be handled before joining
1166+
return false;
1167+
}
1168+
1169+
return true;
1170+
}
1171+
11181172
// #endregion
11191173

11201174
// #region abstract methods

0 commit comments

Comments
 (0)