Skip to content

Commit e4f4972

Browse files
committed
Merge commit '0c62b03109ca8619be61f122cf72a3bc389a325a' into search
2 parents 9c324c2 + 0c62b03 commit e4f4972

File tree

16 files changed

+295
-179
lines changed

16 files changed

+295
-179
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NODE_ENV=development

.github/workflows/build_and_release.yml

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,49 @@ jobs:
1919
run: bun run build
2020
env:
2121
REF_NAME: ${{ github.ref_name }}
22-
- name: Set tag
23-
id: tag
24-
run: |
25-
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
26-
echo "tag=dev" >> $GITHUB_OUTPUT
27-
elif [[ "${{ github.event.release.prerelease }}" == "false" ]]; then
28-
echo "tag=latest" >> $GITHUB_OUTPUT
29-
fi
30-
- uses: JS-DevTools/npm-publish@v3
22+
- name: Upload artifact
23+
uses: actions/upload-artifact@v4
3124
with:
32-
token: ${{ secrets.NPM_TOKEN }}
33-
package: ./out/package.json
34-
tag: ${{ steps.tag.outputs.tag }}
25+
name: client-build-output
26+
path: out
27+
28+
publish:
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
registry-url: ["https://npm.pkg.github.com", "https://registry.npmjs.org"]
33+
runs-on: ubuntu-latest
34+
permissions:
35+
packages: write
36+
contents: read
37+
id-token: write
38+
needs: [test_and_build]
39+
steps:
40+
- name: Download build output
41+
uses: actions/download-artifact@v4
42+
with:
43+
name: client-build-output
44+
path: .
45+
- name: Set tag
46+
id: tag
47+
run: |
48+
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
49+
echo "tag=dev" >> $GITHUB_OUTPUT
50+
elif [[ "${{ github.event.release.prerelease }}" == "false" ]]; then
51+
echo "tag=latest" >> $GITHUB_OUTPUT
52+
fi
53+
- name: Set registry token
54+
id: token
55+
run: |
56+
if [[ "${{ matrix.registry-url }}" == "https://npm.pkg.github.com" ]]; then
57+
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
58+
fi
59+
60+
if [[ "${{ matrix.registry-url }}" == "https://registry.npmjs.org" ]]; then
61+
echo "token=${{ secrets.NPM_TOKEN }}" >> $GITHUB_OUTPUT
62+
fi
63+
- uses: JS-DevTools/npm-publish@v3
64+
with:
65+
token: ${{ steps.token.outputs.token }}
66+
registry: ${{ matrix.registry-url }}
67+
tag: ${{ steps.tag.outputs.tag }}

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ rumble is a combined ability and graphql builder built around [drizzle](https://
55
66
> Using rumble and reading these docs requires some basic knowledge about the above mentioned tools. If you feel stuck, please make sure to familiarize yourself with those first! Especially familiarity with pothos and its drizzle plugin are very helpful!
77
8-
> This is still in a very early stage and needs more testing. Please feel free to report everything you find/your feedback via the issues/discussion section of this repo!
9-
108
## Getting started
119
The following example is an excerpt from the example setup you can find [here](./example).
1210

@@ -220,4 +218,4 @@ server.listen(3000, () => {
220218
console.info("Visit http://localhost:3000/graphql");
221219
});
222220

223-
```
221+
```

bun.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ abilityBuilder.posts.filter("read").by(({ context, entities }) => {
126126
const PostRef = schemaBuilder.drizzleObject("posts", {
127127
name: "Post",
128128
// this is how you can apply application level filter in manual object definitions
129-
applyFilters: abilityBuilder.registeredFilters.posts.read,
129+
applyFilters: abilityBuilder.z_registeredFilters.posts.read,
130130
fields: (t) => ({
131131
id: t.exposeInt("id"),
132132
content: t.exposeString("content", { nullable: false }),
@@ -156,7 +156,11 @@ const UserRef = object({
156156
return {
157157
somethingElse: t.field({
158158
type: "String",
159-
resolve: (parent, args, context, info) => "something else",
159+
args: {
160+
amount: t.arg.int({ required: true }),
161+
},
162+
resolve: (parent, args, context, info) =>
163+
`Hello ${parent.name}, you have provided the number: ${args.amount}`,
160164
}),
161165
};
162166
},

lib/abilityBuilder.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,21 @@ export const createAbilityBuilder = <
211211

212212
return {
213213
...registrators,
214-
/** @internal */
215-
registeredQueryFilters: registeredQueryFilters,
216-
/** @internal */
217-
registeredFilters,
218-
/** @internal */
219-
buildWithUserContext: (userContext: UserContext) => {
214+
/**
215+
* @internal
216+
* @ignore
217+
*/
218+
z_registeredQueryFilters: registeredQueryFilters,
219+
/**
220+
* @internal
221+
* @ignore
222+
*/
223+
z_registeredFilters: registeredFilters,
224+
/**
225+
* @internal
226+
* @ignore
227+
*/
228+
z_buildWithUserContext: (userContext: UserContext) => {
220229
const builder: {
221230
[key in TableName<DB>]: ReturnType<typeof createEntityObject<key>>;
222231
} = {} as any;
@@ -324,7 +333,6 @@ export const createAbilityBuilder = <
324333
// do some funky stuff with query resolve typing otherwise
325334
});
326335

327-
// TODO: strongly type this based on table
328336
const r = {
329337
/**
330338
* Query filters for the drizzle query API.
@@ -344,7 +352,14 @@ export const createAbilityBuilder = <
344352
return where();
345353
},
346354
columns: columns(),
347-
},
355+
} as Pick<
356+
NonNullable<
357+
NonNullable<
358+
Parameters<DB["query"][TableNameT]["findFirst"]>[0]
359+
>
360+
>,
361+
"columns" | "where"
362+
>,
348363
/**
349364
* For find many calls
350365
*/
@@ -356,7 +371,14 @@ export const createAbilityBuilder = <
356371
get limit() {
357372
return limit();
358373
},
359-
},
374+
} as Pick<
375+
NonNullable<
376+
NonNullable<
377+
Parameters<DB["query"][TableNameT]["findMany"]>[0]
378+
>
379+
>,
380+
"columns" | "where" | "limit"
381+
>,
360382
},
361383
/**
362384
* Query filters for the drizzle SQL API as used in e.g. updates.
@@ -392,11 +414,8 @@ export const createAbilityBuilder = <
392414
// as: don't return any columns
393415
// therefore we need to delete it
394416
if (!columns()) {
395-
// biome-ignore lint/performance/noDelete: we need this to not exist
396417
delete r.sql.columns;
397-
// biome-ignore lint/performance/noDelete: we need this to not exist
398418
delete r.query.many.columns;
399-
// biome-ignore lint/performance/noDelete: we need this to not exist
400419
delete r.query.single.columns;
401420
}
402421

@@ -533,7 +552,6 @@ export const createAbilityBuilder = <
533552
? { OR: accumulatedWhereConditions }
534553
: undefined;
535554

536-
//TODO make this actually typesafe
537555
return transformToResponse({
538556
where: combinedWhere,
539557
columns: combinedAllowedColumns,

lib/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const createContextFunction = <
6464
: ({} as UserContext);
6565
return {
6666
...userContext,
67-
abilities: abilityBuilder.buildWithUserContext(userContext),
67+
abilities: abilityBuilder.z_buildWithUserContext(userContext),
6868
};
6969
};
7070
};

lib/enum.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { toCamelCase } from "drizzle-orm/casing";
22
import { type PgEnum, PgEnumColumn } from "drizzle-orm/pg-core";
3-
import { capitalizeFirstLetter } from "./helpers/capitalize";
4-
import { tableHelper } from "./helpers/tableHelpers";
3+
import { capitalize } from "es-toolkit";
54
import type { SchemaBuilderType } from "./schemaBuilder";
65
import type { GenericDrizzleDbTypeConstraints } from "./types/genericDrizzleDbType";
76
import { RumbleError } from "./types/rumbleError";
@@ -132,7 +131,7 @@ Please ensure that you use the enum at least once as a column of a table!`);
132131
}
133132

134133
const graphqlImplementationName =
135-
refName ?? `${capitalizeFirstLetter(toCamelCase(enumSchemaName))}Enum`;
134+
refName ?? `${capitalize(toCamelCase(enumSchemaName))}Enum`;
136135

137136
let ret: ReturnType<typeof implement> | undefined = referenceStorage.get(
138137
graphqlImplementationName,

lib/helpers/capitalize.ts

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

0 commit comments

Comments
 (0)