Skip to content
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: weekly
target-branch: dev


59 changes: 59 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and Test

on:
pull_request:
branches:
- main
- dev

env:
TELEMETRY_TRACKING_TOKEN: ${{ secrets.TELEMETRY_TRACKING_TOKEN }}
DO_NOT_TRACK: "1"

permissions:
contents: read

jobs:
build-test:
runs-on: ubuntu-latest

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

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

- 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
pnpm tsx scripts/post-build.ts
85 changes: 85 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Publish and Release

on:
workflow_dispatch:
push:
branches:
- main
env:
TELEMETRY_TRACKING_TOKEN: ${{ secrets.TELEMETRY_TRACKING_TOKEN }}
DO_NOT_TRACK: "1"

permissions:
contents: write

jobs:
publish-and-release:
runs-on: ubuntu-latest

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

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

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: |
pnpm run build
pnpm tsx scripts/post-build.ts

- name: Get version from package.json
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT

- name: Publish packages
run: pnpm run publish-all
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Generate changelog
id: changelog
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")

if [ -z "$PREVIOUS_TAG" ]; then
CHANGELOG=$(git log --oneline --no-merges --format="* %s" HEAD)
else
CHANGELOG=$(git log --oneline --no-merges --format="* %s" ${PREVIOUS_TAG}..HEAD)
fi

if [ -z "$CHANGELOG" ]; then
CHANGELOG="* Automated release"
fi

echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ZenStack Proxy Release ${{ steps.version.outputs.tag }}
body: |
## Changes in this release

${{ steps.changelog.outputs.changelog }}
draft: true
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
build
dist
*.log
.env
.DS_Store
*.tsbuildinfo
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/
14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 100,
"endOfLine": "lf",
"overrides": [
{
"files": "**/*.json",
"options": { "parser": "json" }
}
]
}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ZenStack Proxy CLI

A CLI tool to run an Express server with ZenStack proxy integration directly from the command line.

## Installation

```bash
npm install @zenstackhq/proxy
```

## Usage

### Start the Server

```bash
zenstack-proxy [options]
```

### Options

- `-z, --zenstack <path>` Path to ZenStack generated folder
- `-p, --port <number>` Port number for the server (default: `8008`)
- `-s, --schema <path>` - Path to ZModel schema file (default: "schema.zmodel")
- `-d, --datasource-url <url>` Datasource URL (overrides schema configuration)
- `-l, --log <level...>` Query log levels (e.g., query, info, warn, error)

### Examples

#### Basic Usage

Start a server with default settings (searches for ZenStack output automatically):

```bash
zenstack-proxy
```

#### Specify ZenStack schema and generated output

```bash
zenstack-proxy -s ./schema/schema.zmodel -z ./generated/zenstack
```

#### Custom Port

```bash
zenstack-proxy -p 8888
```

## Server Endpoints

The server provides the following endpoints:

### ZenStack Model API

- `POST /api/model/:model/:operation` - All ZenStack operations (find, create, update, delete, etc.)

The ZenStack middleware handles all CRUD operations for your models.

### Metadata

- `GET /api/schema` - Get complete schema metadata (models + enums)

## License

MIT
2 changes: 2 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../index.js').default()
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@zenstackhq/proxy",
"version": "0.2.0",
"description": "A CLI tool to run an Express server that proxies CRUD requests to a ZenStack backend",
"main": "index.js",
"publishConfig": {
"directory": "dist",
"linkDirectory": true
},
"bin": {
"zenstack-proxy": "./bin/cli.js"
},
"scripts": {
"clean": "rimraf dist",
"build": "pnpm clean && tsc && copyfiles -F \"bin/*\" dist && copyfiles ./README.md ./LICENSE ./package.json dist && pnpm pack dist --pack-destination ../build",
"prepublishOnly": "npm run build"
},
"keywords": ["zenstack", "proxy", "express", "cli"],
"author": "",
"license": "MIT",
"dependencies": {
"@prisma/adapter-better-sqlite3": "^6.2.1",
"@prisma/adapter-mariadb": "^7.1.0",
"@prisma/adapter-pg": "^6.18.0",
"@zenstackhq/server": "^2.0.0",
"colors": "^1.4.0",
"commander": "^12.0.0",
"cors": "^2.8.5",
"dotenv": "^17.2.3",
"express": "^4.19.2",
"mixpanel": "^0.19.1",
"semver": "^7.7.3",
"tsx": "^4.20.6"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/node": "^20.0.0",
"@types/semver": "^7.7.1",
"copyfiles": "^2.4.1",
"rimraf": "^4.0.0",
"typescript": "^5.0.0"
}
}
Loading
Loading