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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/dist/**
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
}
77 changes: 77 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI

on:
pull_request:
branches:
- main
- dev

permissions:
contents: read

jobs:
build-test:
runs-on: buildjet-8vcpu-ubuntu-2204

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: abc123
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10.12.1

- name: Use Node.js ${{ matrix.node-version }}
uses: buildjet/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: buildjet/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm run build

- name: Lint
run: pnpm run lint

# install again for internal dependencies
- name: Install internal dependencies
run: pnpm install --frozen-lockfile

- name: Test
run: pnpm run test
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"name": "zenstack-v3",
"version": "3.0.0-alpha.1",
"description": "ZenStack",
"packageManager": "pnpm@10.0.0",
"packageManager": "pnpm@10.12.1",
"scripts": {
"build": "pnpm -r build",
"watch": "pnpm -r --parallel watch",
"lint": "pnpm -r lint",
"test": "pnpm vitest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@swc/core": "^1.10.15",
"@typescript-eslint/eslint-plugin": "~7.3.1",
"@typescript-eslint/parser": "~7.3.1",
"eslint": "~8.57.1",
"npm-run-all": "^4.1.5",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"scripts": {
"build": "tsup-node",
"watch": "tsup-node --watch",
"lint": "eslint src --ext ts",
"test": "vitest",
"pack": "pnpm pack"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/ts-schema-gen.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Expression } from '@zenstackhq/runtime/schema';
import { ExpressionUtils } from '@zenstackhq/runtime/schema';
import { generateTsSchema } from '@zenstackhq/testtools';
import { describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -36,7 +36,7 @@ model Post {
id: {
type: 'String',
id: true,
default: Expression.call('uuid'),
default: ExpressionUtils.call('uuid'),
attributes: [
{ name: '@id' },
{
Expand All @@ -56,7 +56,7 @@ model Post {
email: { type: 'String', unique: true },
createdAt: {
type: 'DateTime',
default: Expression.call('now'),
default: ExpressionUtils.call('now'),
attributes: [
{
name: '@default',
Expand Down Expand Up @@ -105,7 +105,7 @@ model Post {
id: {
type: 'String',
id: true,
default: Expression.call('cuid'),
default: ExpressionUtils.call('cuid'),
attributes: [
{ name: '@id' },
{
Expand Down
13 changes: 0 additions & 13 deletions packages/language/.eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
"devDependencies": {
"@types/node": "^18.0.0",
"@types/pluralize": "^0.0.33",
"@typescript-eslint/eslint-plugin": "~7.3.1",
"@typescript-eslint/parser": "~7.3.1",
"eslint": "~8.57.0",
"langium-cli": "~3.3.0",
"typescript": "~5.1.6"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/language/src/validators/expression-validator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { AstUtils, type AstNode, type ValidationAcceptor } from 'langium';
import {
BinaryExpr,
DataModelAttribute,
Expression,
isArrayExpr,
isDataModel,
isDataModelAttribute,
isDataModelField,
isEnum,
isLiteralExpr,
isMemberAccessExpr,
Expand All @@ -18,7 +16,6 @@ import {

import {
findUpAst,
getAttributeArgLiteral,
isAuthInvocation,
isAuthOrAuthMemberAccess,
isDataModelFieldReference,
Expand Down
4 changes: 1 addition & 3 deletions packages/language/src/validators/schema-validator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { LangiumDocuments, ValidationAcceptor } from 'langium';
import { PLUGIN_MODULE_NAME, STD_LIB_MODULE_NAME } from '../constants';
import { isDataModel, isDataSource, type Model } from '../generated/ast';
import { isDataSource, type Model } from '../generated/ast';
import {
getAllDeclarationsIncludingImports,
getDataModelAndTypeDefs,
hasAttribute,
resolveImport,
resolveTransitiveImports,
} from '../utils';
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "tsup-node && pnpm test-typecheck",
"test-typecheck": "tsc --project tsconfig.test.json",
"watch": "tsup-node --watch",
"lint": "eslint src --ext ts",
"test": "vitest",
"pack": "pnpm pack"
},
Expand Down Expand Up @@ -85,6 +86,7 @@
"dependencies": {
"@paralleldrive/cuid2": "^2.2.2",
"decimal.js": "^10.4.3",
"is-plain-object": "^5.0.0",
"kysely": "^0.27.5",
"nanoid": "^5.0.9",
"pg-connection-string": "^2.9.0",
Expand Down Expand Up @@ -112,8 +114,8 @@
"@types/pg": "^8.0.0",
"@types/tmp": "^0.2.6",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"tmp": "^0.2.3"
}
}
3 changes: 2 additions & 1 deletion packages/runtime/src/client/client-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'kysely';
import { match } from 'ts-pattern';
import type { GetModels, ProcedureDef, SchemaDef } from '../schema';
import type { AuthType } from '../schema/schema';
import type { AuthType } from '../schema/auth';
import type { ClientConstructor, ClientContract } from './contract';
import type { ModelOperations } from './crud-types';
import { AggregateOperationHandler } from './crud/operations/aggregate';
Expand Down Expand Up @@ -199,6 +199,7 @@ export class ClientImpl<Schema extends SchemaDef> {
);
}

// eslint-disable-next-line @typescript-eslint/ban-types
return (procOptions[name] as Function).apply(this, [this, ...args]);
}

Expand Down
10 changes: 4 additions & 6 deletions packages/runtime/src/client/contract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable @typescript-eslint/ban-types */

import { type GetModels, type ProcedureDef, type SchemaDef } from '../schema';
import type { Decimal } from 'decimal.js';
import {
type AuthType,
type GetModels,
type ProcedureDef,
type SchemaDef,
} from '../schema/schema';
import type { AuthType } from '../schema/auth';
import type { OrUndefinedIf } from '../utils/type-utils';
import type { ModelOperations, ModelResult } from './crud-types';
import type { ClientOptions, HasComputedFields } from './options';
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime/src/client/crud-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { ExpressionBuilder, OperandExpression, SqlBool } from 'kysely';
import type { Optional } from 'utility-types';
import type {
Expand All @@ -23,7 +25,7 @@ import type {
RelationInfo,
ScalarFields,
SchemaDef,
} from '../schema/schema';
} from '../schema';
import type {
AtLeast,
MapBaseType,
Expand Down
16 changes: 9 additions & 7 deletions packages/runtime/src/client/crud/dialects/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import type {
import { sql, type SelectQueryBuilder } from 'kysely';
import invariant from 'tiny-invariant';
import { match, P } from 'ts-pattern';
import type { GetModels, SchemaDef } from '../../../schema';
import type {
BuiltinType,
DataSourceProviderType,
FieldDef,
} from '../../../schema/schema';
GetModels,
SchemaDef,
} from '../../../schema';
import { enumerate } from '../../../utils/enumerate';
import { isPlainObject } from '../../../utils/is-plain-object';
// @ts-expect-error
import { isPlainObject } from 'is-plain-object';
import type { OrArray } from '../../../utils/type-utils';
import type {
BooleanFilter,
Expand Down Expand Up @@ -54,12 +56,12 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
}

abstract buildRelationSelection(
query: SelectQueryBuilder<any, any, {}>,
query: SelectQueryBuilder<any, any, any>,
model: string,
relationField: string,
parentAlias: string,
payload: true | FindArgs<Schema, GetModels<Schema>, true>
): SelectQueryBuilder<any, any, {}>;
): SelectQueryBuilder<any, any, any>;

abstract buildSkipTake(
query: SelectQueryBuilder<any, any, any>,
Expand All @@ -82,7 +84,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
}

let result = this.true(eb);
let _where = flattenCompoundUniqueFilters(this.schema, model, where);
const _where = flattenCompoundUniqueFilters(this.schema, model, where);

for (const [key, payload] of Object.entries(_where)) {
if (payload === undefined) {
Expand Down Expand Up @@ -284,7 +286,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
)
.select(() => eb.fn.count(eb.lit(1)).as(filterResultField));

let conditions: Expression<SqlBool>[] = [];
const conditions: Expression<SqlBool>[] = [];

if ('is' in payload || 'isNot' in payload) {
if ('is' in payload) {
Expand Down
14 changes: 9 additions & 5 deletions packages/runtime/src/client/crud/dialects/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import {
} from 'kysely';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import type { SchemaDef } from '../../../schema';
import type { BuiltinType, FieldDef, GetModels } from '../../../schema/schema';
import type {
BuiltinType,
FieldDef,
GetModels,
SchemaDef,
} from '../../../schema';
import type { FindArgs } from '../../crud-types';
import {
buildFieldRef,
Expand Down Expand Up @@ -49,12 +53,12 @@ export class PostgresCrudDialect<
}

override buildRelationSelection(
query: SelectQueryBuilder<any, any, {}>,
query: SelectQueryBuilder<any, any, any>,
model: string,
relationField: string,
parentAlias: string,
payload: true | FindArgs<Schema, GetModels<Schema>, true>
): SelectQueryBuilder<any, any, {}> {
): SelectQueryBuilder<any, any, any> {
const joinedQuery = this.buildRelationJSON(
model,
query,
Expand Down Expand Up @@ -261,7 +265,7 @@ export class PostgresCrudDialect<
const objArgs: Array<
| string
| ExpressionWrapper<any, any, any>
| SelectQueryBuilder<any, any, {}>
| SelectQueryBuilder<any, any, any>
| RawBuilder<any>
> = [];

Expand Down
Loading
Loading