Skip to content

Commit bb1640b

Browse files
authored
release: v0.3.0 (#62)
1 parent 5c813e3 commit bb1640b

Some content is hidden

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

43 files changed

+1575
-524
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,16 @@ export const getServerSideProps: GetServerSideProps = async () => {
264264
265265
**Please note** that server-side database access is not protected by access policies. This is by-design so as to provide a way of bypassing the policies. Please make sure you implement authorization properly.
266266
267-
## What's next?
267+
## Learning more
268268
269269
### [Learning the ZModel language](/docs/get-started/learning-the-zmodel-language.md)
270270
271271
### [Evolving data model with migration](/docs/ref/evolving-data-model-with-migration.md)
272272
273273
### [Database hosting considerations](/docs/ref/database-hosting-considerations.md)
274274
275+
### [Setting up logging](/docs/ref/setup-logging.md)
276+
275277
## Reach out to us for issues, feedback and ideas!
276278
277279
[Discord](https://discord.gg/dbuC9ZWc) [Twitter](https://twitter.com/zenstackhq)

docs/get-started/learning-the-zmodel-language.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,39 @@ model Post {
8989
}
9090
```
9191

92-
Please refer to [Prisma's documentation](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#attributes) for an exhaustive list of attributes and functions.
92+
ZenStack inherits most attributes and functions from Prisma, and added a number of new ones:
93+
94+
- `@password`
95+
96+
A field attribute that marks a field as a password. Before storing such a field, ZenStack hashes its value with [bcryptjs](https://github.com/dcodeIO/bcrypt.js), with a default salt length of 12.
97+
98+
You can override the default setting with the `saltLength` or `salt` named parameters, like:
99+
100+
```prisma
101+
model User {
102+
password String @password(saltLength: 16)
103+
}
104+
105+
model User {
106+
password String @password(salt: "mysalt")
107+
}
108+
```
109+
110+
If both `saltLength` and `salt` parameters are provided, `salt` is used.
111+
112+
- `@omit`
113+
114+
A field attribute that marks a field to be excluded when model entities are read from the generated service. This is often used to prevent sensitive information from being returned to the front-end code (e.g., password, even hashed).
115+
116+
E.g.:
117+
118+
```prisma
119+
model User {
120+
password String @password @omit
121+
}
122+
```
123+
124+
For attributes and functions inherited from Prisma, please refer to [Prisma's documentation](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#attributes) for details.
93125

94126
## Relations
95127

docs/ref/setup-logging.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Setting Up Logging
2+
3+
ZenStack uses the following levels to control server-side logging:
4+
5+
- error
6+
7+
Error level logging
8+
9+
- warn
10+
11+
Warning level logging
12+
13+
- info
14+
15+
Info level logging
16+
17+
- verbose
18+
19+
Verbose level logging
20+
21+
- query
22+
23+
Detailed database query logging
24+
25+
By default, ZenStack prints `error` and `warn` level of logging with `console.error` and `console.log`, respectively. You can also control the logging behavior by providing a `zenstack.config.json` file at the root of your project.
26+
27+
You can turn log levels on and off in `zenstack.config.json`:
28+
29+
```json
30+
{
31+
"log": ["verbose", "info"]
32+
}
33+
```
34+
35+
The settings shown above is an shorthand for:
36+
37+
```json
38+
{
39+
"log": [
40+
{
41+
"level": "verbose",
42+
"emit": "stdout"
43+
},
44+
{
45+
"level": "info",
46+
"emit": "stdout"
47+
}
48+
]
49+
}
50+
```
51+
52+
You can also configure ZenStack to emit log as event instead of dumping to stdout, like:
53+
54+
```json
55+
{
56+
"log": [
57+
{
58+
"level": "info",
59+
"emit": "event"
60+
}
61+
]
62+
}
63+
```
64+
65+
To consume the events:
66+
67+
```ts
68+
import service from '@zenstackhq/runtime';
69+
70+
service.$on('info', (event) => {
71+
console.log(event.timestamp, event.message);
72+
});
73+
```
74+
75+
You can also mix and match stdout output with event emitting, like:
76+
77+
```json
78+
{
79+
"log": [
80+
{
81+
"level": "info",
82+
"emit": "stdout"
83+
},
84+
{
85+
"level": "info",
86+
"emit": "event"
87+
}
88+
]
89+
}
90+
```
91+
92+
The settings in `zenstack.config.json` controls logging of both ZenStack and the underlying Prisma instance.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "0.2.4",
3+
"version": "0.3.0",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/internal/jest.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default {
1010
// Automatically clear mock calls, instances, contexts and results before every test
1111
clearMocks: true,
1212

13+
// Automatically reset mock state before every test
14+
resetMocks: true,
15+
1316
// Indicates whether the coverage information should be collected while executing the test
1417
collectCoverage: true,
1518

packages/internal/package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/internal",
3-
"version": "0.2.4",
3+
"version": "0.3.0",
44
"displayName": "ZenStack Internal Library",
55
"description": "ZenStack internal runtime library. This package is for supporting runtime functionality of ZenStack and not supposed to be used directly.",
66
"repository": {
@@ -10,9 +10,9 @@
1010
"main": "lib/index.js",
1111
"types": "lib/index.d.ts",
1212
"scripts": {
13-
"build": "tsc",
13+
"clean": "rimraf lib",
14+
"build": "npm run clean && tsc",
1415
"watch": "tsc --watch",
15-
"test": "jest",
1616
"lint": "eslint src --ext ts",
1717
"prepublishOnly": "pnpm build"
1818
},
@@ -26,13 +26,15 @@
2626
],
2727
"dependencies": {
2828
"bcryptjs": "^2.4.3",
29+
"colors": "^1.4.0",
2930
"cuid": "^2.1.8",
31+
"decimal.js": "^10.4.2",
3032
"deepcopy": "^2.1.0",
3133
"swr": "^1.3.0"
3234
},
3335
"peerDependencies": {
3436
"@prisma/client": "^4.4.0",
35-
"next": "12.3.1",
37+
"next": "^12.3.1",
3638
"react": "^17.0.2 || ^18",
3739
"react-dom": "^17.0.2 || ^18"
3840
},
@@ -42,7 +44,9 @@
4244
"@types/jest": "^29.0.3",
4345
"@types/node": "^14.18.29",
4446
"@types/uuid": "^8.3.4",
47+
"eslint": "^8.27.0",
4548
"jest": "^29.0.3",
49+
"rimraf": "^3.0.2",
4650
"ts-jest": "^29.0.1",
4751
"ts-node": "^10.9.1",
4852
"tsc-alias": "^1.7.0",

packages/internal/src/config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { LogLevel } from './types';
2+
3+
/**
4+
* Logging config definition
5+
*/
6+
export type LogDefinition = {
7+
level: LogLevel;
8+
emit: 'stdout' | 'event';
9+
};
10+
11+
/**
12+
* Service configuration
13+
*/
14+
export interface ServiceConfig {
15+
log?: Array<LogLevel | LogDefinition>;
16+
}

0 commit comments

Comments
 (0)