dzql 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/README.md +30 -14
- package/docs/feature-requests/applyPatch-bug-report.md +2 -2
- package/docs/feature-requests/connection-ready-profile.md +1 -1
- package/docs/feature-requests/hidden-bug-report.md +4 -4
- package/docs/feature-requests/todo.md +1 -1
- package/docs/for_ai.md +35 -23
- package/docs/project-setup.md +67 -43
- package/package.json +5 -1
- package/src/cli/codegen/client.ts +5 -5
- package/src/cli/codegen/pinia.ts +1 -1
- package/src/cli/codegen/subscribable_store.ts +1 -1
- package/src/cli/index.ts +10 -8
- package/src/client/ws.ts +14 -14
- package/src/runtime/index.ts +1 -1
- package/src/runtime/namespace.ts +47 -47
- package/dist/client/index.ts +0 -1
- package/dist/client/stores/useMyProfileStore.ts +0 -114
- package/dist/client/stores/useOrgDashboardStore.ts +0 -131
- package/dist/client/stores/useVenueDetailStore.ts +0 -117
- package/dist/client/ws.ts +0 -716
- package/dist/db/migrations/000_core.sql +0 -92
- package/dist/db/migrations/20251229T212912022Z_schema.sql +0 -3020
- package/dist/db/migrations/20251229T212912022Z_subscribables.sql +0 -371
- package/dist/runtime/manifest.json +0 -1562
- package/src/create/.env.example +0 -8
- package/src/create/README.md +0 -101
- package/src/create/compose.yml +0 -14
- package/src/create/domain.ts +0 -153
- package/src/create/package.json +0 -24
- package/src/create/server.ts +0 -18
- package/src/create/setup.sh +0 -11
- package/src/create/tsconfig.json +0 -15
package/src/create/.env.example
DELETED
package/src/create/README.md
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# {{name}}
|
|
2
|
-
|
|
3
|
-
A real-time database application powered by [DZQL](https://github.com/blueshed/dzql).
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Start PostgreSQL
|
|
9
|
-
bun run db:up
|
|
10
|
-
|
|
11
|
-
# Copy environment file
|
|
12
|
-
cp .env.example .env
|
|
13
|
-
|
|
14
|
-
# Compile domain and generate SQL
|
|
15
|
-
bun run compile
|
|
16
|
-
|
|
17
|
-
# Run migrations
|
|
18
|
-
bun run db:migrate
|
|
19
|
-
|
|
20
|
-
# Start development server
|
|
21
|
-
bun run dev
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Project Structure
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
├── domain.ts # Entity definitions and subscriptions
|
|
28
|
-
├── server.ts # Runtime server configuration
|
|
29
|
-
├── compose.yml # Docker Compose for PostgreSQL
|
|
30
|
-
├── dist/ # Generated output (after compile)
|
|
31
|
-
│ ├── db/ # SQL migrations
|
|
32
|
-
│ ├── runtime/ # Server manifest
|
|
33
|
-
│ └── client/ # TypeScript SDK & Pinia stores
|
|
34
|
-
└── .env # Environment variables
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Domain Definition
|
|
38
|
-
|
|
39
|
-
Edit `domain.ts` to define your entities:
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
export const entities = {
|
|
43
|
-
posts: {
|
|
44
|
-
schema: {
|
|
45
|
-
id: 'serial PRIMARY KEY',
|
|
46
|
-
title: 'text NOT NULL',
|
|
47
|
-
content: 'text'
|
|
48
|
-
},
|
|
49
|
-
permissions: {
|
|
50
|
-
view: [],
|
|
51
|
-
create: [],
|
|
52
|
-
update: ['@author_id'],
|
|
53
|
-
delete: ['@author_id']
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## API Endpoints
|
|
60
|
-
|
|
61
|
-
After starting the server:
|
|
62
|
-
|
|
63
|
-
- **WebSocket**: `ws://localhost:3000/ws`
|
|
64
|
-
- **Health**: `GET http://localhost:3000/health`
|
|
65
|
-
|
|
66
|
-
## Client Usage
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { TzqlClient } from './dist/client';
|
|
70
|
-
|
|
71
|
-
const client = new TzqlClient('ws://localhost:3000/ws');
|
|
72
|
-
|
|
73
|
-
// Register
|
|
74
|
-
await client.api.register_user({
|
|
75
|
-
email: 'user@example.com',
|
|
76
|
-
password: 'secret'
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Login
|
|
80
|
-
const { token } = await client.api.login_user({
|
|
81
|
-
email: 'user@example.com',
|
|
82
|
-
password: 'secret'
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// CRUD operations
|
|
86
|
-
const post = await client.api.save_posts({
|
|
87
|
-
title: 'Hello World'
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Real-time subscription
|
|
91
|
-
await client.api.subscribe_post_detail(
|
|
92
|
-
{ post_id: post.id },
|
|
93
|
-
(data) => console.log('Updated:', data)
|
|
94
|
-
);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Learn More
|
|
98
|
-
|
|
99
|
-
- [DZQL Documentation](https://github.com/blueshed/dzql)
|
|
100
|
-
- [Graph Rules](https://github.com/blueshed/dzql/docs/guides/graph-rules.md)
|
|
101
|
-
- [Subscriptions](https://github.com/blueshed/dzql/docs/guides/subscriptions.md)
|
package/src/create/compose.yml
DELETED
package/src/create/domain.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// domain.ts - DZQL Domain Definition
|
|
2
|
-
// Run: bunx dzql domain.ts
|
|
3
|
-
|
|
4
|
-
export const entities = {
|
|
5
|
-
|
|
6
|
-
// Users table with authentication
|
|
7
|
-
users: {
|
|
8
|
-
schema: {
|
|
9
|
-
id: 'serial PRIMARY KEY',
|
|
10
|
-
name: 'text NOT NULL',
|
|
11
|
-
email: 'text UNIQUE NOT NULL',
|
|
12
|
-
password_hash: 'text NOT NULL',
|
|
13
|
-
created_at: 'timestamptz DEFAULT now()'
|
|
14
|
-
},
|
|
15
|
-
label: 'name',
|
|
16
|
-
searchable: ['name', 'email'],
|
|
17
|
-
hidden: ['password_hash'],
|
|
18
|
-
permissions: {
|
|
19
|
-
view: [],
|
|
20
|
-
create: [],
|
|
21
|
-
update: ['@id'], // Users can only update themselves
|
|
22
|
-
delete: []
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// Posts table with author relationship
|
|
27
|
-
posts: {
|
|
28
|
-
schema: {
|
|
29
|
-
id: 'serial PRIMARY KEY',
|
|
30
|
-
author_id: 'int NOT NULL REFERENCES users(id)',
|
|
31
|
-
title: 'text NOT NULL',
|
|
32
|
-
content: 'text',
|
|
33
|
-
published: 'boolean DEFAULT false',
|
|
34
|
-
created_at: 'timestamptz DEFAULT now()',
|
|
35
|
-
updated_at: 'timestamptz'
|
|
36
|
-
},
|
|
37
|
-
label: 'title',
|
|
38
|
-
searchable: ['title', 'content'],
|
|
39
|
-
includes: {
|
|
40
|
-
author: 'users'
|
|
41
|
-
},
|
|
42
|
-
fieldDefaults: {
|
|
43
|
-
author_id: '@user_id',
|
|
44
|
-
created_at: '@now'
|
|
45
|
-
},
|
|
46
|
-
permissions: {
|
|
47
|
-
view: [], // Anyone can view
|
|
48
|
-
create: [], // Anyone logged in can create
|
|
49
|
-
update: ['@author_id'], // Only author can update
|
|
50
|
-
delete: ['@author_id'] // Only author can delete
|
|
51
|
-
},
|
|
52
|
-
graphRules: {
|
|
53
|
-
on_create: {
|
|
54
|
-
notify_followers: {
|
|
55
|
-
description: 'Notify when new post is created',
|
|
56
|
-
actions: [
|
|
57
|
-
{
|
|
58
|
-
type: 'reactor',
|
|
59
|
-
name: 'new_post',
|
|
60
|
-
params: { post_id: '@id', author_id: '@author_id' }
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
on_update: {
|
|
66
|
-
track_updates: {
|
|
67
|
-
description: 'Set updated_at on edit',
|
|
68
|
-
condition: "@before.title != @after.title OR @before.content != @after.content",
|
|
69
|
-
actions: [
|
|
70
|
-
{
|
|
71
|
-
type: 'update',
|
|
72
|
-
target: 'posts',
|
|
73
|
-
data: { updated_at: '@now' },
|
|
74
|
-
match: { id: '@id' }
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
// Comments on posts
|
|
83
|
-
comments: {
|
|
84
|
-
schema: {
|
|
85
|
-
id: 'serial PRIMARY KEY',
|
|
86
|
-
post_id: 'int NOT NULL REFERENCES posts(id) ON DELETE CASCADE',
|
|
87
|
-
author_id: 'int NOT NULL REFERENCES users(id)',
|
|
88
|
-
content: 'text NOT NULL',
|
|
89
|
-
created_at: 'timestamptz DEFAULT now()'
|
|
90
|
-
},
|
|
91
|
-
label: 'content',
|
|
92
|
-
searchable: ['content'],
|
|
93
|
-
includes: {
|
|
94
|
-
post: 'posts',
|
|
95
|
-
author: 'users'
|
|
96
|
-
},
|
|
97
|
-
fieldDefaults: {
|
|
98
|
-
author_id: '@user_id',
|
|
99
|
-
created_at: '@now'
|
|
100
|
-
},
|
|
101
|
-
permissions: {
|
|
102
|
-
view: [],
|
|
103
|
-
create: [],
|
|
104
|
-
update: ['@author_id'],
|
|
105
|
-
delete: ['@author_id', '@post_id->posts.author_id'] // Author or post owner can delete
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Real-time subscriptions
|
|
112
|
-
export const subscribables = {
|
|
113
|
-
|
|
114
|
-
// Post detail with comments
|
|
115
|
-
post_detail: {
|
|
116
|
-
params: {
|
|
117
|
-
post_id: 'int'
|
|
118
|
-
},
|
|
119
|
-
root: {
|
|
120
|
-
entity: 'posts',
|
|
121
|
-
key: 'post_id'
|
|
122
|
-
},
|
|
123
|
-
includes: {
|
|
124
|
-
author: 'users',
|
|
125
|
-
comments: {
|
|
126
|
-
entity: 'comments',
|
|
127
|
-
includes: {
|
|
128
|
-
author: 'users'
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
scopeTables: ['posts', 'users', 'comments'],
|
|
133
|
-
canSubscribe: [] // Anyone can subscribe
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
// User's posts feed
|
|
137
|
-
my_posts: {
|
|
138
|
-
params: {},
|
|
139
|
-
root: {
|
|
140
|
-
entity: 'users',
|
|
141
|
-
key: '@user_id'
|
|
142
|
-
},
|
|
143
|
-
includes: {
|
|
144
|
-
posts: {
|
|
145
|
-
entity: 'posts',
|
|
146
|
-
filter: { author_id: '@user_id' }
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
scopeTables: ['users', 'posts'],
|
|
150
|
-
canSubscribe: []
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
};
|
package/src/create/package.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "{{name}}",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"dev": "bun run --watch server.ts",
|
|
7
|
-
"compile": "bunx dzql domain.ts",
|
|
8
|
-
"db:up": "docker compose up -d",
|
|
9
|
-
"db:down": "docker compose down",
|
|
10
|
-
"db:migrate": "bun run compile && psql $DATABASE_URL -f dist/db/migrations/*.sql"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"dzql": "^0.6.0",
|
|
14
|
-
"postgres": "^3.4.3"
|
|
15
|
-
},
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@types/bun": "latest",
|
|
18
|
-
"typescript": "^5.0.0"
|
|
19
|
-
},
|
|
20
|
-
"bun-create": {
|
|
21
|
-
"postinstall": ["./setup.sh", "rm setup.sh"],
|
|
22
|
-
"start": "bun run dev"
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/create/server.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// server.ts - DZQL Runtime Server
|
|
2
|
-
import { createServer } from "dzql";
|
|
3
|
-
|
|
4
|
-
const server = createServer({
|
|
5
|
-
manifestPath: "./dist/runtime/manifest.json",
|
|
6
|
-
jwtSecret: process.env.JWT_SECRET || "dev-secret-change-in-production",
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const port = process.env.PORT || 3000;
|
|
10
|
-
|
|
11
|
-
console.log(`DZQL Server running at http://localhost:${port}`);
|
|
12
|
-
console.log(`WebSocket endpoint: ws://localhost:${port}/ws`);
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
port,
|
|
16
|
-
fetch: server.fetch,
|
|
17
|
-
websocket: server.websocket,
|
|
18
|
-
};
|
package/src/create/setup.sh
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Replace {{name}} with project name from package.json
|
|
3
|
-
NAME=$(grep -o '"name": *"[^"]*"' package.json | head -1 | cut -d'"' -f4)
|
|
4
|
-
if [ -z "$NAME" ] || [ "$NAME" = "{{name}}" ]; then
|
|
5
|
-
NAME=$(basename "$PWD")
|
|
6
|
-
fi
|
|
7
|
-
sed -i.bak "s/{{name}}/$NAME/g" compose.yml .env.example README.md package.json 2>/dev/null || \
|
|
8
|
-
sed -i "s/{{name}}/$NAME/g" compose.yml .env.example README.md package.json
|
|
9
|
-
cp .env.example .env
|
|
10
|
-
rm -f compose.yml.bak .env.example.bak README.md.bak package.json.bak
|
|
11
|
-
echo "✓ Configured project: $NAME"
|
package/src/create/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": ".",
|
|
11
|
-
"types": ["bun-types"]
|
|
12
|
-
},
|
|
13
|
-
"include": ["*.ts", "domain.ts"],
|
|
14
|
-
"exclude": ["node_modules", "dist"]
|
|
15
|
-
}
|