Skip to content

release: v0.3.0 #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,16 @@ export const getServerSideProps: GetServerSideProps = async () => {

**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.

## What's next?
## Learning more

### [Learning the ZModel language](/docs/get-started/learning-the-zmodel-language.md)

### [Evolving data model with migration](/docs/ref/evolving-data-model-with-migration.md)

### [Database hosting considerations](/docs/ref/database-hosting-considerations.md)

### [Setting up logging](/docs/ref/setup-logging.md)

## Reach out to us for issues, feedback and ideas!

[Discord](https://discord.gg/dbuC9ZWc) [Twitter](https://twitter.com/zenstackhq)
Expand Down
34 changes: 33 additions & 1 deletion docs/get-started/learning-the-zmodel-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,39 @@ model Post {
}
```

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.
ZenStack inherits most attributes and functions from Prisma, and added a number of new ones:

- `@password`

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.

You can override the default setting with the `saltLength` or `salt` named parameters, like:

```prisma
model User {
password String @password(saltLength: 16)
}

model User {
password String @password(salt: "mysalt")
}
```

If both `saltLength` and `salt` parameters are provided, `salt` is used.

- `@omit`

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).

E.g.:

```prisma
model User {
password String @password @omit
}
```

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.

## Relations

Expand Down
92 changes: 92 additions & 0 deletions docs/ref/setup-logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Setting Up Logging

ZenStack uses the following levels to control server-side logging:

- error

Error level logging

- warn

Warning level logging

- info

Info level logging

- verbose

Verbose level logging

- query

Detailed database query logging

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.

You can turn log levels on and off in `zenstack.config.json`:

```json
{
"log": ["verbose", "info"]
}
```

The settings shown above is an shorthand for:

```json
{
"log": [
{
"level": "verbose",
"emit": "stdout"
},
{
"level": "info",
"emit": "stdout"
}
]
}
```

You can also configure ZenStack to emit log as event instead of dumping to stdout, like:

```json
{
"log": [
{
"level": "info",
"emit": "event"
}
]
}
```

To consume the events:

```ts
import service from '@zenstackhq/runtime';

service.$on('info', (event) => {
console.log(event.timestamp, event.message);
});
```

You can also mix and match stdout output with event emitting, like:

```json
{
"log": [
{
"level": "info",
"emit": "stdout"
},
{
"level": "info",
"emit": "event"
}
]
}
```

The settings in `zenstack.config.json` controls logging of both ZenStack and the underlying Prisma instance.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "0.2.4",
"version": "0.3.0",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
3 changes: 3 additions & 0 deletions packages/internal/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default {
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Automatically reset mock state before every test
resetMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

Expand Down
12 changes: 8 additions & 4 deletions packages/internal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/internal",
"version": "0.2.4",
"version": "0.3.0",
"displayName": "ZenStack Internal Library",
"description": "ZenStack internal runtime library. This package is for supporting runtime functionality of ZenStack and not supposed to be used directly.",
"repository": {
Expand All @@ -10,9 +10,9 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"build": "npm run clean && tsc",
"watch": "tsc --watch",
"test": "jest",
"lint": "eslint src --ext ts",
"prepublishOnly": "pnpm build"
},
Expand All @@ -26,13 +26,15 @@
],
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"cuid": "^2.1.8",
"decimal.js": "^10.4.2",
"deepcopy": "^2.1.0",
"swr": "^1.3.0"
},
"peerDependencies": {
"@prisma/client": "^4.4.0",
"next": "12.3.1",
"next": "^12.3.1",
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18"
},
Expand All @@ -42,7 +44,9 @@
"@types/jest": "^29.0.3",
"@types/node": "^14.18.29",
"@types/uuid": "^8.3.4",
"eslint": "^8.27.0",
"jest": "^29.0.3",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.7.0",
Expand Down
16 changes: 16 additions & 0 deletions packages/internal/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LogLevel } from './types';

/**
* Logging config definition
*/
export type LogDefinition = {
level: LogLevel;
emit: 'stdout' | 'event';
};

/**
* Service configuration
*/
export interface ServiceConfig {
log?: Array<LogLevel | LogDefinition>;
}
Loading