Skip to content

Commit 7ac4f4a

Browse files
committed
feat: make plugins compatible with prisma client extensions
1 parent 088c41a commit 7ac4f4a

39 files changed

+1055
-716
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"label": "Build all - watch",
21-
"command": "pnpm watch",
21+
"command": "turbo watch build",
2222
"type": "shell",
2323
"group": {
2424
"kind": "build"

NEW-FEATURES.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

TODO.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
- [x] Count
5252
- [x] Aggregate
5353
- [x] Group by
54+
- [ ] Raw queries
5455
- [ ] Extensions
5556
- [x] Query builder API
5657
- [x] Computed fields
57-
- [ ] Prisma client extension
58+
- [x] Prisma client extension
5859
- [ ] Misc
5960
- [x] JSDoc for CRUD methods
6061
- [x] Cache validation schemas
@@ -66,7 +67,8 @@
6667
- [ ] Error system
6768
- [x] Custom table name
6869
- [x] Custom field name
69-
- [ ] Implement changesets
70+
- [ ] Strict undefined checks
71+
- [ ] Benchmark
7072
- [ ] Polymorphism
7173
- [ ] Validation
7274
- [ ] Access Policy

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@
2222
},
2323
"scripts": {
2424
"build": "tsup-node",
25+
"watch": "tsup-node --watch",
2526
"lint": "eslint src --ext ts",
2627
"test": "vitest run",
2728
"pack": "pnpm pack"
2829
},
2930
"dependencies": {
3031
"@zenstackhq/language": "workspace:*",
3132
"@zenstackhq/sdk": "workspace:*",
33+
"@zenstackhq/common-helpers": "workspace:*",
3234
"async-exit-hook": "^2.0.1",
3335
"colors": "1.4.0",
3436
"commander": "^8.3.0",
3537
"langium": "catalog:",
3638
"ora": "^5.4.1",
3739
"package-manager-detector": "^1.3.0",
38-
"tiny-invariant": "^1.3.3",
3940
"ts-pattern": "catalog:"
4041
},
4142
"peerDependencies": {

packages/cli/src/actions/generate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { invariant } from '@zenstackhq/common-helpers';
12
import { isPlugin, LiteralExpr, type Model } from '@zenstackhq/language/ast';
2-
import type { CliGenerator } from '@zenstackhq/runtime/client';
3-
import { PrismaSchemaGenerator, TsSchemaGenerator } from '@zenstackhq/sdk';
3+
import { PrismaSchemaGenerator, TsSchemaGenerator, type CliGenerator } from '@zenstackhq/sdk';
44
import colors from 'colors';
55
import fs from 'node:fs';
66
import path from 'node:path';
7-
import invariant from 'tiny-invariant';
87
import { getSchemaFile, loadSchemaDocument } from './action-utils';
98

109
type Options = {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@zenstackhq/common-helpers",
3+
"version": "3.0.0-alpha.4",
4+
"description": "ZenStack Common Helpers",
5+
"type": "module",
6+
"scripts": {
7+
"build": "tsup-node",
8+
"watch": "tsup-node --watch",
9+
"lint": "eslint src --ext ts",
10+
"pack": "pnpm pack"
11+
},
12+
"keywords": [],
13+
"author": "ZenStack Team",
14+
"license": "MIT",
15+
"files": [
16+
"dist"
17+
],
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.ts",
22+
"default": "./dist/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
}
29+
}
30+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from './is-plain-object';
2+
export * from './lower-case-first';
3+
export * from './param-case';
4+
export * from './sleep';
5+
export * from './tiny-invariant';
6+
export * from './upper-case-first';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function isObject(o: unknown) {
2+
return Object.prototype.toString.call(o) === '[object Object]';
3+
}
4+
5+
export function isPlainObject(o: unknown) {
6+
if (isObject(o) === false) return false;
7+
8+
// If has modified constructor
9+
const ctor = (o as { constructor: unknown }).constructor;
10+
if (ctor === undefined) return true;
11+
12+
// If has modified prototype
13+
const prot = (ctor as { prototype: unknown }).prototype;
14+
if (isObject(prot) === false) return false;
15+
16+
// If constructor does not have an Object-specific method
17+
if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {
18+
return false;
19+
}
20+
21+
// Most likely a plain Object
22+
return true;
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function lowerCaseFirst(input: string) {
2+
return input.charAt(0).toLowerCase() + input.slice(1);
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;
2+
const DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;
3+
const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
4+
5+
export function paramCase(input: string) {
6+
const result = input
7+
.replace(DEFAULT_SPLIT_REGEXP_1, "$1\0$2")
8+
.replace(DEFAULT_SPLIT_REGEXP_2, "$1\0$2")
9+
.replace(DEFAULT_STRIP_REGEXP, "\0");
10+
11+
let start = 0;
12+
let end = result.length;
13+
14+
while (result.charAt(start) === "\0") start++;
15+
while (result.charAt(end - 1) === "\0") end--;
16+
17+
return result.slice(start, end).split("\0").map((str) => str.toLowerCase()).join("-");
18+
}

0 commit comments

Comments
 (0)