Skip to content

Commit edf6982

Browse files
authored
merge dev to main (#617)
2 parents c89012b + c5b70b7 commit edf6982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4047
-1103
lines changed

.github/workflows/build-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ jobs:
1515
build-test:
1616
runs-on: buildjet-8vcpu-ubuntu-2204
1717

18+
services:
19+
postgres:
20+
image: postgres
21+
env:
22+
POSTGRES_PASSWORD: abc123
23+
# Set health checks to wait until postgres has started
24+
options: >-
25+
--health-cmd pg_isready
26+
--health-interval 10s
27+
--health-timeout 5s
28+
--health-retries 5
29+
ports:
30+
- 5432:5432
31+
1832
strategy:
1933
matrix:
2034
node-version: [18.x]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "1.0.0-beta.13",
3+
"version": "1.0.0-beta.15",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",
7-
"test": "ZENSTACK_TEST=1 pnpm -r run test --silent",
8-
"test-ci": "ZENSTACK_TEST=1 pnpm -r run test --silent",
7+
"test": "ZENSTACK_TEST=1 pnpm -r run test --silent --forceExit",
8+
"test-ci": "ZENSTACK_TEST=1 pnpm -r run test --silent --forceExit",
99
"lint": "pnpm -r lint",
1010
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
1111
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry http://localhost:4873"

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "1.0.0-beta.13",
3+
"version": "1.0.0-beta.15",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/plugins/openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/openapi",
33
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
4-
"version": "1.0.0-beta.13",
4+
"version": "1.0.0-beta.15",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/swr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/swr",
33
"displayName": "ZenStack plugin for generating SWR hooks",
4-
"version": "1.0.0-beta.13",
4+
"version": "1.0.0-beta.15",
55
"description": "ZenStack plugin for generating SWR hooks",
66
"main": "index.js",
77
"repository": {

packages/plugins/tanstack-query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/tanstack-query",
33
"displayName": "ZenStack plugin for generating tanstack-query hooks",
4-
"version": "1.0.0-beta.13",
4+
"version": "1.0.0-beta.15",
55
"description": "ZenStack plugin for generating tanstack-query hooks",
66
"main": "index.js",
77
"exports": {

packages/plugins/trpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/trpc",
33
"displayName": "ZenStack plugin for tRPC",
4-
"version": "1.0.0-beta.13",
4+
"version": "1.0.0-beta.15",
55
"description": "ZenStack plugin for tRPC",
66
"main": "index.js",
77
"repository": {

packages/runtime/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/runtime",
33
"displayName": "ZenStack Runtime Library",
4-
"version": "1.0.0-beta.13",
4+
"version": "1.0.0-beta.15",
55
"description": "Runtime of ZenStack for both client-side and server-side environments.",
66
"repository": {
77
"type": "git",
@@ -45,7 +45,6 @@
4545
"linkDirectory": true
4646
},
4747
"dependencies": {
48-
"@paralleldrive/cuid2": "^2.2.0",
4948
"@types/bcryptjs": "^2.4.2",
5049
"bcryptjs": "^2.4.3",
5150
"buffer": "^6.0.3",

packages/runtime/src/constants.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,38 @@ export enum CrudFailureReason {
3737
* Prisma error codes used
3838
*/
3939
export enum PrismaErrorCode {
40+
/**
41+
* Unique constraint failed
42+
*/
43+
UNIQUE_CONSTRAINT_FAILED = 'P2002',
44+
45+
/**
46+
* A constraint failed on the database
47+
*/
4048
CONSTRAINED_FAILED = 'P2004',
49+
50+
/**
51+
* The required connected records were not found
52+
*/
53+
REQUIRED_CONNECTED_RECORD_NOT_FOUND = 'P2018',
54+
55+
/**
56+
* An operation failed because it depends on one or more records that were required but not found
57+
*/
58+
DEPEND_ON_RECORD_NOT_FOUND = 'P2025',
4159
}
4260

4361
/**
4462
* Field name for storing in-transaction flag
4563
*/
46-
export const PRISIMA_TX_FLAG = '$__zenstack_tx';
64+
export const PRISMA_TX_FLAG = '$__zenstack_tx';
4765

4866
/**
4967
* Field name for getting current enhancer
5068
*/
5169
export const PRISMA_PROXY_ENHANCER = '$__zenstack_enhancer';
70+
71+
/**
72+
* Minimum Prisma version supported
73+
*/
74+
export const PRISMA_MINIMUM_VERSION = '4.8.0';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { resolveField } from './model-meta';
3+
import { ModelMeta } from './types';
4+
5+
/**
6+
* Callback for @see ModelDataVisitor.
7+
*/
8+
export type ModelDataVisitorCallback = (model: string, data: any, scalarData: any) => void;
9+
10+
/**
11+
* Visitor that traverses data returned by a Prisma query.
12+
*/
13+
export class ModelDataVisitor {
14+
constructor(private modelMeta: ModelMeta) {}
15+
16+
/**
17+
* Visits the given model data.
18+
*/
19+
visit(model: string, data: any, callback: ModelDataVisitorCallback) {
20+
if (!data || typeof data !== 'object') {
21+
return;
22+
}
23+
24+
const scalarData: Record<string, unknown> = {};
25+
const subTasks: Array<{ model: string; data: any }> = [];
26+
27+
for (const [k, v] of Object.entries(data)) {
28+
const field = resolveField(this.modelMeta, model, k);
29+
if (field && field.isDataModel) {
30+
if (field.isArray && Array.isArray(v)) {
31+
subTasks.push(...v.map((item) => ({ model: field.type, data: item })));
32+
} else {
33+
subTasks.push({ model: field.type, data: v });
34+
}
35+
} else {
36+
scalarData[k] = v;
37+
}
38+
}
39+
40+
callback(model, data, scalarData);
41+
subTasks.forEach(({ model, data }) => this.visit(model, data, callback));
42+
}
43+
}

packages/runtime/src/enhancements/model-meta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
import { lowerCaseFirst } from 'lower-case-first';
33
import path from 'path';
4+
import { FieldInfo } from '../types';
45
import { ModelMeta } from './types';
56

67
/**
@@ -26,7 +27,7 @@ export function getDefaultModelMeta(): ModelMeta {
2627
/**
2728
* Resolves a model field to its metadata. Returns undefined if not found.
2829
*/
29-
export function resolveField(modelMeta: ModelMeta, model: string, field: string) {
30+
export function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo | undefined {
3031
return modelMeta.fields[lowerCaseFirst(model)][field];
3132
}
3233

0 commit comments

Comments
 (0)