@m1212e/rumble 0.8.1 → 0.8.3
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/index.cjs +4 -4
- package/index.cjs.map +1 -1
- package/index.d.cts +98 -79
- package/index.d.ts +98 -79
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
2
|
-
import { PgEnum } from 'drizzle-orm/pg-core';
|
3
1
|
import * as SchemaBuilder from '@pothos/core';
|
4
2
|
import SchemaBuilder__default, { SchemaTypes, BasePlugin, PothosOutputFieldConfig } from '@pothos/core';
|
3
|
+
import { GraphQLFieldResolver, GraphQLError } from 'graphql';
|
4
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
5
|
+
import { PgEnum } from 'drizzle-orm/pg-core';
|
5
6
|
import * as _pothos_plugin_drizzle from '@pothos/plugin-drizzle';
|
6
7
|
import { DrizzleClient } from '@pothos/plugin-drizzle';
|
7
|
-
import
|
8
|
+
import * as fets from 'fets';
|
8
9
|
import * as graphql_yoga from 'graphql-yoga';
|
9
10
|
import { createPubSub, YogaServerOptions } from 'graphql-yoga';
|
10
11
|
import * as drizzle_orm from 'drizzle-orm';
|
12
|
+
import { useSofa } from 'sofa-api';
|
11
13
|
|
12
14
|
declare const pluginName = "ManualFiltersPlugin";
|
13
15
|
|
@@ -32,6 +34,78 @@ declare global {
|
|
32
34
|
}
|
33
35
|
}
|
34
36
|
|
37
|
+
/**
|
38
|
+
*
|
39
|
+
* Helper function to map a drizzle findFirst query result,
|
40
|
+
* which may be optional, to a correct drizzle type.
|
41
|
+
*
|
42
|
+
* @throws RumbleError
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
*
|
46
|
+
* ```ts
|
47
|
+
* schemaBuilder.queryFields((t) => {
|
48
|
+
return {
|
49
|
+
findFirstUser: t.drizzleField({
|
50
|
+
type: UserRef,
|
51
|
+
resolve: (query, root, args, ctx, info) => {
|
52
|
+
return (
|
53
|
+
db.query.users
|
54
|
+
.findFirst({
|
55
|
+
...query,
|
56
|
+
where: ctx.abilities.users.filter("read").single.where,
|
57
|
+
})
|
58
|
+
// note that we need to manually raise an error if the value is not found
|
59
|
+
.then(assertFindFirstExists)
|
60
|
+
);
|
61
|
+
},
|
62
|
+
}),
|
63
|
+
};
|
64
|
+
});
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
declare const assertFindFirstExists: <T>(value: T | undefined) => T;
|
68
|
+
/**
|
69
|
+
*
|
70
|
+
* Helper function to map a drizzle findFirst query result,
|
71
|
+
* which may be optional, to a correct drizzle type.
|
72
|
+
*
|
73
|
+
* @throws RumbleError
|
74
|
+
*
|
75
|
+
* @example
|
76
|
+
*
|
77
|
+
* ```ts
|
78
|
+
schemaBuilder.mutationFields((t) => {
|
79
|
+
return {
|
80
|
+
updateUsername: t.drizzleField({
|
81
|
+
type: UserRef,
|
82
|
+
args: {
|
83
|
+
userId: t.arg.int({ required: true }),
|
84
|
+
newName: t.arg.string({ required: true }),
|
85
|
+
},
|
86
|
+
resolve: (query, root, args, ctx, info) => {
|
87
|
+
return db
|
88
|
+
.update(schema.users)
|
89
|
+
.set({
|
90
|
+
name: args.newName,
|
91
|
+
})
|
92
|
+
.where(
|
93
|
+
and(
|
94
|
+
eq(schema.users.id, args.userId),
|
95
|
+
ctx.abilities.users.filter("update").single.where
|
96
|
+
)
|
97
|
+
)
|
98
|
+
.returning({ id: schema.users.id, name: schema.users.name })
|
99
|
+
// note that we need to manually raise an error if the value is not found
|
100
|
+
.then(assertFirstEntryExists);
|
101
|
+
},
|
102
|
+
}),
|
103
|
+
};
|
104
|
+
});
|
105
|
+
* ```
|
106
|
+
*/
|
107
|
+
declare const assertFirstEntryExists: <T>(value: T[]) => T;
|
108
|
+
|
35
109
|
type QueryFilterObject = Partial<{
|
36
110
|
where: any;
|
37
111
|
columns: any;
|
@@ -264,14 +338,31 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
264
338
|
* @example
|
265
339
|
*
|
266
340
|
* ```ts
|
341
|
+
*
|
267
342
|
import { createServer } from "node:http";
|
268
|
-
|
269
|
-
|
343
|
+
* const server = createServer(createYoga());
|
344
|
+
server.listen(3000, () => {
|
270
345
|
console.info("Visit http://localhost:3000/graphql");
|
271
|
-
|
272
|
-
|
346
|
+
});
|
347
|
+
* ```
|
348
|
+
* https://the-guild.dev/graphql/yoga-server/docs#server
|
273
349
|
*/
|
274
350
|
createYoga: (args?: Omit<YogaServerOptions<RequestEvent, any>, "schema" | "context"> | undefined) => graphql_yoga.YogaServerInstance<RequestEvent, {}>;
|
351
|
+
/**
|
352
|
+
* Creates a sofa instance to offer a REST API.
|
353
|
+
```ts
|
354
|
+
import express from 'express';
|
355
|
+
|
356
|
+
const app = express();
|
357
|
+
const sofa = createSofa(...);
|
358
|
+
|
359
|
+
app.use('/api', useSofa({ schema }));
|
360
|
+
```
|
361
|
+
* https://the-guild.dev/graphql/sofa-api/docs#usage
|
362
|
+
*/
|
363
|
+
createSofa: (args: Omit<Parameters<typeof useSofa>[0], "schema" | "context">) => fets.Router<any, {}, {
|
364
|
+
[TKey: string]: never;
|
365
|
+
}>;
|
275
366
|
/**
|
276
367
|
* A function for creating default objects for your schema
|
277
368
|
*/
|
@@ -557,78 +648,6 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
557
648
|
}>, any, any>;
|
558
649
|
};
|
559
650
|
|
560
|
-
/**
|
561
|
-
*
|
562
|
-
* Helper function to map a drizzle findFirst query result,
|
563
|
-
* which may be optional, to a correct drizzle type.
|
564
|
-
*
|
565
|
-
* @throws RumbleError
|
566
|
-
*
|
567
|
-
* @example
|
568
|
-
*
|
569
|
-
* ```ts
|
570
|
-
* schemaBuilder.queryFields((t) => {
|
571
|
-
return {
|
572
|
-
findFirstUser: t.drizzleField({
|
573
|
-
type: UserRef,
|
574
|
-
resolve: (query, root, args, ctx, info) => {
|
575
|
-
return (
|
576
|
-
db.query.users
|
577
|
-
.findFirst({
|
578
|
-
...query,
|
579
|
-
where: ctx.abilities.users.filter("read").single.where,
|
580
|
-
})
|
581
|
-
// note that we need to manually raise an error if the value is not found
|
582
|
-
.then(assertFindFirstExists)
|
583
|
-
);
|
584
|
-
},
|
585
|
-
}),
|
586
|
-
};
|
587
|
-
});
|
588
|
-
* ```
|
589
|
-
*/
|
590
|
-
declare const assertFindFirstExists: <T>(value: T | undefined) => T;
|
591
|
-
/**
|
592
|
-
*
|
593
|
-
* Helper function to map a drizzle findFirst query result,
|
594
|
-
* which may be optional, to a correct drizzle type.
|
595
|
-
*
|
596
|
-
* @throws RumbleError
|
597
|
-
*
|
598
|
-
* @example
|
599
|
-
*
|
600
|
-
* ```ts
|
601
|
-
schemaBuilder.mutationFields((t) => {
|
602
|
-
return {
|
603
|
-
updateUsername: t.drizzleField({
|
604
|
-
type: UserRef,
|
605
|
-
args: {
|
606
|
-
userId: t.arg.int({ required: true }),
|
607
|
-
newName: t.arg.string({ required: true }),
|
608
|
-
},
|
609
|
-
resolve: (query, root, args, ctx, info) => {
|
610
|
-
return db
|
611
|
-
.update(schema.users)
|
612
|
-
.set({
|
613
|
-
name: args.newName,
|
614
|
-
})
|
615
|
-
.where(
|
616
|
-
and(
|
617
|
-
eq(schema.users.id, args.userId),
|
618
|
-
ctx.abilities.users.filter("update").single.where
|
619
|
-
)
|
620
|
-
)
|
621
|
-
.returning({ id: schema.users.id, name: schema.users.name })
|
622
|
-
// note that we need to manually raise an error if the value is not found
|
623
|
-
.then(assertFirstEntryExists);
|
624
|
-
},
|
625
|
-
}),
|
626
|
-
};
|
627
|
-
});
|
628
|
-
* ```
|
629
|
-
*/
|
630
|
-
declare const assertFirstEntryExists: <T>(value: T[]) => T;
|
631
|
-
|
632
651
|
/**
|
633
652
|
* An error that gets raised by rumble whenever something does not go according to plan.
|
634
653
|
* Mostly internals, configuration errors or other unexpected things.
|
package/index.d.ts
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
2
|
-
import { PgEnum } from 'drizzle-orm/pg-core';
|
3
1
|
import * as SchemaBuilder from '@pothos/core';
|
4
2
|
import SchemaBuilder__default, { SchemaTypes, BasePlugin, PothosOutputFieldConfig } from '@pothos/core';
|
3
|
+
import { GraphQLFieldResolver, GraphQLError } from 'graphql';
|
4
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
5
|
+
import { PgEnum } from 'drizzle-orm/pg-core';
|
5
6
|
import * as _pothos_plugin_drizzle from '@pothos/plugin-drizzle';
|
6
7
|
import { DrizzleClient } from '@pothos/plugin-drizzle';
|
7
|
-
import
|
8
|
+
import * as fets from 'fets';
|
8
9
|
import * as graphql_yoga from 'graphql-yoga';
|
9
10
|
import { createPubSub, YogaServerOptions } from 'graphql-yoga';
|
10
11
|
import * as drizzle_orm from 'drizzle-orm';
|
12
|
+
import { useSofa } from 'sofa-api';
|
11
13
|
|
12
14
|
declare const pluginName = "ManualFiltersPlugin";
|
13
15
|
|
@@ -32,6 +34,78 @@ declare global {
|
|
32
34
|
}
|
33
35
|
}
|
34
36
|
|
37
|
+
/**
|
38
|
+
*
|
39
|
+
* Helper function to map a drizzle findFirst query result,
|
40
|
+
* which may be optional, to a correct drizzle type.
|
41
|
+
*
|
42
|
+
* @throws RumbleError
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
*
|
46
|
+
* ```ts
|
47
|
+
* schemaBuilder.queryFields((t) => {
|
48
|
+
return {
|
49
|
+
findFirstUser: t.drizzleField({
|
50
|
+
type: UserRef,
|
51
|
+
resolve: (query, root, args, ctx, info) => {
|
52
|
+
return (
|
53
|
+
db.query.users
|
54
|
+
.findFirst({
|
55
|
+
...query,
|
56
|
+
where: ctx.abilities.users.filter("read").single.where,
|
57
|
+
})
|
58
|
+
// note that we need to manually raise an error if the value is not found
|
59
|
+
.then(assertFindFirstExists)
|
60
|
+
);
|
61
|
+
},
|
62
|
+
}),
|
63
|
+
};
|
64
|
+
});
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
declare const assertFindFirstExists: <T>(value: T | undefined) => T;
|
68
|
+
/**
|
69
|
+
*
|
70
|
+
* Helper function to map a drizzle findFirst query result,
|
71
|
+
* which may be optional, to a correct drizzle type.
|
72
|
+
*
|
73
|
+
* @throws RumbleError
|
74
|
+
*
|
75
|
+
* @example
|
76
|
+
*
|
77
|
+
* ```ts
|
78
|
+
schemaBuilder.mutationFields((t) => {
|
79
|
+
return {
|
80
|
+
updateUsername: t.drizzleField({
|
81
|
+
type: UserRef,
|
82
|
+
args: {
|
83
|
+
userId: t.arg.int({ required: true }),
|
84
|
+
newName: t.arg.string({ required: true }),
|
85
|
+
},
|
86
|
+
resolve: (query, root, args, ctx, info) => {
|
87
|
+
return db
|
88
|
+
.update(schema.users)
|
89
|
+
.set({
|
90
|
+
name: args.newName,
|
91
|
+
})
|
92
|
+
.where(
|
93
|
+
and(
|
94
|
+
eq(schema.users.id, args.userId),
|
95
|
+
ctx.abilities.users.filter("update").single.where
|
96
|
+
)
|
97
|
+
)
|
98
|
+
.returning({ id: schema.users.id, name: schema.users.name })
|
99
|
+
// note that we need to manually raise an error if the value is not found
|
100
|
+
.then(assertFirstEntryExists);
|
101
|
+
},
|
102
|
+
}),
|
103
|
+
};
|
104
|
+
});
|
105
|
+
* ```
|
106
|
+
*/
|
107
|
+
declare const assertFirstEntryExists: <T>(value: T[]) => T;
|
108
|
+
|
35
109
|
type QueryFilterObject = Partial<{
|
36
110
|
where: any;
|
37
111
|
columns: any;
|
@@ -264,14 +338,31 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
264
338
|
* @example
|
265
339
|
*
|
266
340
|
* ```ts
|
341
|
+
*
|
267
342
|
import { createServer } from "node:http";
|
268
|
-
|
269
|
-
|
343
|
+
* const server = createServer(createYoga());
|
344
|
+
server.listen(3000, () => {
|
270
345
|
console.info("Visit http://localhost:3000/graphql");
|
271
|
-
|
272
|
-
|
346
|
+
});
|
347
|
+
* ```
|
348
|
+
* https://the-guild.dev/graphql/yoga-server/docs#server
|
273
349
|
*/
|
274
350
|
createYoga: (args?: Omit<YogaServerOptions<RequestEvent, any>, "schema" | "context"> | undefined) => graphql_yoga.YogaServerInstance<RequestEvent, {}>;
|
351
|
+
/**
|
352
|
+
* Creates a sofa instance to offer a REST API.
|
353
|
+
```ts
|
354
|
+
import express from 'express';
|
355
|
+
|
356
|
+
const app = express();
|
357
|
+
const sofa = createSofa(...);
|
358
|
+
|
359
|
+
app.use('/api', useSofa({ schema }));
|
360
|
+
```
|
361
|
+
* https://the-guild.dev/graphql/sofa-api/docs#usage
|
362
|
+
*/
|
363
|
+
createSofa: (args: Omit<Parameters<typeof useSofa>[0], "schema" | "context">) => fets.Router<any, {}, {
|
364
|
+
[TKey: string]: never;
|
365
|
+
}>;
|
275
366
|
/**
|
276
367
|
* A function for creating default objects for your schema
|
277
368
|
*/
|
@@ -557,78 +648,6 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
557
648
|
}>, any, any>;
|
558
649
|
};
|
559
650
|
|
560
|
-
/**
|
561
|
-
*
|
562
|
-
* Helper function to map a drizzle findFirst query result,
|
563
|
-
* which may be optional, to a correct drizzle type.
|
564
|
-
*
|
565
|
-
* @throws RumbleError
|
566
|
-
*
|
567
|
-
* @example
|
568
|
-
*
|
569
|
-
* ```ts
|
570
|
-
* schemaBuilder.queryFields((t) => {
|
571
|
-
return {
|
572
|
-
findFirstUser: t.drizzleField({
|
573
|
-
type: UserRef,
|
574
|
-
resolve: (query, root, args, ctx, info) => {
|
575
|
-
return (
|
576
|
-
db.query.users
|
577
|
-
.findFirst({
|
578
|
-
...query,
|
579
|
-
where: ctx.abilities.users.filter("read").single.where,
|
580
|
-
})
|
581
|
-
// note that we need to manually raise an error if the value is not found
|
582
|
-
.then(assertFindFirstExists)
|
583
|
-
);
|
584
|
-
},
|
585
|
-
}),
|
586
|
-
};
|
587
|
-
});
|
588
|
-
* ```
|
589
|
-
*/
|
590
|
-
declare const assertFindFirstExists: <T>(value: T | undefined) => T;
|
591
|
-
/**
|
592
|
-
*
|
593
|
-
* Helper function to map a drizzle findFirst query result,
|
594
|
-
* which may be optional, to a correct drizzle type.
|
595
|
-
*
|
596
|
-
* @throws RumbleError
|
597
|
-
*
|
598
|
-
* @example
|
599
|
-
*
|
600
|
-
* ```ts
|
601
|
-
schemaBuilder.mutationFields((t) => {
|
602
|
-
return {
|
603
|
-
updateUsername: t.drizzleField({
|
604
|
-
type: UserRef,
|
605
|
-
args: {
|
606
|
-
userId: t.arg.int({ required: true }),
|
607
|
-
newName: t.arg.string({ required: true }),
|
608
|
-
},
|
609
|
-
resolve: (query, root, args, ctx, info) => {
|
610
|
-
return db
|
611
|
-
.update(schema.users)
|
612
|
-
.set({
|
613
|
-
name: args.newName,
|
614
|
-
})
|
615
|
-
.where(
|
616
|
-
and(
|
617
|
-
eq(schema.users.id, args.userId),
|
618
|
-
ctx.abilities.users.filter("update").single.where
|
619
|
-
)
|
620
|
-
)
|
621
|
-
.returning({ id: schema.users.id, name: schema.users.name })
|
622
|
-
// note that we need to manually raise an error if the value is not found
|
623
|
-
.then(assertFirstEntryExists);
|
624
|
-
},
|
625
|
-
}),
|
626
|
-
};
|
627
|
-
});
|
628
|
-
* ```
|
629
|
-
*/
|
630
|
-
declare const assertFirstEntryExists: <T>(value: T[]) => T;
|
631
|
-
|
632
651
|
/**
|
633
652
|
* An error that gets raised by rumble whenever something does not go according to plan.
|
634
653
|
* Mostly internals, configuration errors or other unexpected things.
|
package/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import {createYoga,createPubSub}from'graphql-yoga';import {One,relationsFilterToSQL}from'drizzle-orm';import {toCamelCase}from'drizzle-orm/casing';import {PgEnumColumn}from'drizzle-orm/pg-core';import Be,{BasePlugin}from'@pothos/core';import Le from'@pothos/plugin-drizzle';import qe,{subscribeOptionsFromIterator}from'@pothos/plugin-smart-subscriptions';import {JSONResolver,DateResolver,DateTimeISOResolver}from'graphql-scalars';function
|
1
|
+
import {createYoga,createPubSub}from'graphql-yoga';import {useSofa}from'sofa-api';import {One,relationsFilterToSQL}from'drizzle-orm';import {toCamelCase}from'drizzle-orm/casing';import {PgEnumColumn}from'drizzle-orm/pg-core';import Be,{BasePlugin}from'@pothos/core';import Le from'@pothos/plugin-drizzle';import qe,{subscribeOptionsFromIterator}from'@pothos/plugin-smart-subscriptions';import {JSONResolver,DateResolver,DateTimeISOResolver}from'graphql-scalars';function M(t){return typeof t=="object"&&t!==null}function $(t,n){throw new Error("Unexpected invariant triggered.")}var ye=/\r\n|[\n\r]/g;function U(t,n){let o=0,u=1;for(let r of t.body.matchAll(ye)){if(typeof r.index=="number"||$(),r.index>=n)break;o=r.index+r[0].length,u+=1;}return {line:u,column:n+1-o}}function H(t){return W(t.source,U(t.source,t.start))}function W(t,n){let o=t.locationOffset.column-1,u="".padStart(o)+t.body,r=n.line-1,e=t.locationOffset.line-1,a=n.line+e,p=n.line===1?o:0,l=n.column+p,c=`${t.name}:${a}:${l}
|
2
2
|
`,s=u.split(/\r\n|[\n\r]/g),g=s[r];if(g.length>120){let i=Math.floor(l/80),y=l%80,d=[];for(let b=0;b<g.length;b+=80)d.push(g.slice(b,b+80));return c+J([[`${a} |`,d[0]],...d.slice(1,i+1).map(b=>["|",b]),["|","^".padStart(y)],["|",d[i+1]]])}return c+J([[`${a-1} |`,s[r-1]],[`${a} |`,g],["|","^".padStart(l)],[`${a+1} |`,s[r+1]]])}function J(t){let n=t.filter(([u,r])=>r!==void 0),o=Math.max(...n.map(([u])=>u.length));return n.map(([u,r])=>u.padStart(o)+(r?" "+r:"")).join(`
|
3
|
-
`)}function de(t){let n=t[0];return n==null||"kind"in n||"length"in n?{nodes:n,source:t[1],positions:t[2],path:t[3],originalError:t[4],extensions:t[5]}:n}var
|
3
|
+
`)}function de(t){let n=t[0];return n==null||"kind"in n||"length"in n?{nodes:n,source:t[1],positions:t[2],path:t[3],originalError:t[4],extensions:t[5]}:n}var q=class t extends Error{constructor(n,...o){var u,r,e;let{nodes:a,source:p,positions:l,path:c,originalError:s,extensions:g}=de(o);super(n),this.name="GraphQLError",this.path=c??void 0,this.originalError=s??void 0,this.nodes=Y(Array.isArray(a)?a:a?[a]:void 0);let i=Y((u=this.nodes)===null||u===void 0?void 0:u.map(d=>d.loc).filter(d=>d!=null));this.source=p??(i==null||(r=i[0])===null||r===void 0?void 0:r.source),this.positions=l??i?.map(d=>d.start),this.locations=l&&p?l.map(d=>U(p,d)):i?.map(d=>U(d.source,d.start));let y=M(s?.extensions)?s?.extensions:void 0;this.extensions=(e=g??y)!==null&&e!==void 0?e:Object.create(null),Object.defineProperties(this,{message:{writable:true,enumerable:true},name:{enumerable:false},nodes:{enumerable:false},source:{enumerable:false},positions:{enumerable:false},originalError:{enumerable:false}}),s!=null&&s.stack?Object.defineProperty(this,"stack",{value:s.stack,writable:true,configurable:true}):Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:Error().stack,writable:true,configurable:true});}get[Symbol.toStringTag](){return "GraphQLError"}toString(){let n=this.message;if(this.nodes)for(let o of this.nodes)o.loc&&(n+=`
|
4
4
|
|
5
5
|
`+H(o.loc));else if(this.source&&this.locations)for(let o of this.locations)n+=`
|
6
6
|
|
7
|
-
`+W(this.source,o);return n}toJSON(){let n={message:this.message};return this.locations!=null&&(n.locations=this.locations),this.path!=null&&(n.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(n.extensions=this.extensions),n}};function Y(t){return t===void 0||t.length===0?void 0:t}var
|
8
|
-
Please ensure that you use the enum at least once as a column of a table!`);l=y.enumValues;}else if(e){let i=Object.entries(t._.relations.schema).find(([y,d])=>d===e.config.enum);if(!i)throw new R(`Could not find enum in schema for ${e.name}!`);p=i[0],l=e.enumValues;}if(!p||!l)throw new R("Could not determine enum structure!");let c=a??`${B(toCamelCase(p))}Enum`,s=o.get(c);return s||(s=n.enumType(c,{values:l}),o.set(c,s),s)}};function G({sqlType:t,fieldName:n}){let o;if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t)&&(o="Int"),["real","decimal","double","float"].includes(t)&&(o="Float"),["string","text","varchar","char","text(256)"].includes(t)&&(n&&(n.toLowerCase().endsWith("_id")||n.toLowerCase().endsWith("id"))?o="ID":o="String"),["uuid"].includes(t)&&(o="ID"),["boolean"].includes(t)&&(o="Boolean"),["timestamp","datetime"].includes(t)&&(o="DateTime"),["date"].includes(t)&&(o="Date"),["json"].includes(t)&&(o="JSON"),o!==void 0)return o;throw Q(t,"SQL to GQL")}var Re=t=>typeof t!="object"?false:!!Object.keys(t).some(n=>["args","nullable","query","subscribe","description","type","resolve"].find(o=>o===n)),re=({db:t,schemaBuilder:n,makePubSubInstance:o,argImplementer:u,enumImplementer:r,abilityBuilder:e})=>({table:a,refName:p,readAction:l="read",adjust:c})=>{let s=N({db:t,tsName:a});Object.keys(s.primaryColumns).length===0&&console.warn(`Could not find primary key for ${a.toString()}. Cannot register subscriptions!`);let g=Object.values(s.primaryColumns)[0],{registerOnInstance:i}=o({table:a});return n.drizzleObject(a,{name:p??B(a.toString()),subscribe:(y,d,b)=>{if(!g)return;let h=d[g.name];if(!h){console.warn(`Could not find primary key value for ${JSON.stringify(d)}. Cannot register subscription!`);return}i({instance:y,action:"updated",primaryKeyValue:h});},applyFilters:e?.registeredFilters?.[a]?.[l],fields:y=>{let d=s.columns,b=(x,f,T)=>{let S=G({sqlType:x,fieldName:f});switch(S){case "Int":return y.exposeInt(f,{nullable:T});case "String":return y.exposeString(f,{nullable:T});case "Boolean":return y.exposeBoolean(f,{nullable:T});case "Date":return y.field({type:"Date",resolve:m=>m[f],nullable:T});case "DateTime":return y.field({type:"DateTime",resolve:m=>m[f],nullable:T});case "Float":return y.exposeFloat(f,{nullable:T});case "ID":return y.exposeID(f,{nullable:T});case "JSON":return y.field({type:"JSON",resolve:m=>m[f],nullable:T});default:throw new R(`Unsupported object type ${S} for column ${f}`)}},h=new Map,D=c?.(new Proxy(y,{get:(x,f)=>typeof x[f]=="function"?(...T)=>{let S=x[f](...T),m=T.find(Re);if(!m)throw new R("Expected config object to be passed to adjust field");return h.set(S,{params:T,creatorFunction:x[f],configObject:m}),S}:x[f]}))??{},I=Object.entries(d).reduce((x,[f,T])=>{if(D[f]){let{params:S,creatorFunction:m,configObject:A}=h.get(D[f]);return typeof A.nullable!="boolean"&&(A.nullable=!T.notNull),D[f]=m.bind(y)(...S),x}if(j(T)){let S=r({enumColumn:T});x[f]=y.field({type:S,resolve:m=>m[f],nullable:!T.notNull});}else x[f]=b(T.getSQLType(),f,!T.notNull);return x},{}),E=Object.entries(s.relations??{}).reduce((x,[f,T])=>{let S=N({db:t,table:T.targetTable}),m=u({dbName:S.dbName}),A=o({table:S.tsName}),P=false,w=true,v="many";T instanceof One&&(w=false,P=T.optional,v="single");let F=(C,z)=>{A.registerOnInstance({instance:C,action:"created"}),A.registerOnInstance({instance:C,action:"removed"});};if(D[f]){let{params:C,creatorFunction:z,configObject:O}=h.get(D[f]);return typeof O.nullable!="boolean"&&(O.nullable=P),typeof O.subscribe!="function"&&(O.subscribe=F),D[f]=z.bind(y)(...C),x}return x[f]=y.relation(f,{args:{where:y.arg({type:m,required:false}),...w?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{}},subscribe:F,nullable:P,query:(C,z)=>{C=JSON.parse(JSON.stringify(C));let O=z.abilities[S.tsName].filter(l,{inject:{where:C.where,limit:C.limit}}).query[v];return C.offset&&(O.offset=C.offset),O}}),x},{});return {...I,...E,...D}}})};var Se="RUMBLE_SUBSCRIPTION_NOTIFICATION",Ie="REMOVED",Ae="UPDATED",Ee="CREATED",oe=({subscriptions:t,db:n})=>{let o=t?createPubSub(...t):createPubSub();return {pubsub:o,makePubSubInstance:({table:r})=>{function e({action:a,tableName:p,primaryKeyValue:l}){let c;switch(a){case "created":c=Ee;break;case "removed":c=Ie;break;case "updated":c=Ae;break;default:throw new Error(`Unknown action: ${a}`)}return `${Se}/${p}${l?`/${l}`:""}/${c}`}return {registerOnInstance({instance:a,action:p,primaryKeyValue:l}){let c=e({tableName:r.toString(),action:p,primaryKeyValue:l});a.register(c);},created(){let a=e({tableName:r.toString(),action:"created"});return o.publish(a)},removed(a){let p=e({tableName:r.toString(),action:"removed"});return o.publish(p)},updated(a){let l=(Array.isArray(a)?a:[a]).map(s=>e({tableName:r.toString(),action:"updated",primaryKeyValue:s})),c=Array.from(new Set(l));for(let s of c)o.publish(s);}}}}};var _=t=>{if(!t)throw new q("Value not found but required (findFirst)");return t},Ne=t=>{let n=t.at(0);if(!n)throw new q("Value not found but required (firstEntry)");return n},se=async({filters:t,entities:n,context:o})=>(await Promise.all(t.map(u=>u({context:o,entities:n})))).reduce((u,r)=>(u.push(...r),u),[]);var ae=({db:t,schemaBuilder:n,argImplementer:o,makePubSubInstance:u})=>({table:r,readAction:e="read",listAction:a="read"})=>{let p=o({table:r}),{registerOnInstance:l}=u({table:r});return n.queryFields(c=>({[`findMany${B(r.toString())}`]:c.drizzleField({type:[r],nullable:false,smartSubscription:true,subscribe:(s,g,i,y,d)=>{l({instance:s,action:"created"}),l({instance:s,action:"removed"});},args:{where:c.arg({type:p,required:false}),limit:c.arg.int({required:false}),offset:c.arg.int({required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(a,i.where||i.limit||i.offset?{inject:{where:i.where,limit:i.limit}}:void 0).query.many;i.offset&&(b.offset=i.offset);let h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findMany(h)}}),[`findFirst${B(r.toString())}`]:c.drizzleField({type:r,nullable:false,smartSubscription:true,args:{where:c.arg({type:p,required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(e,i.where?{inject:{where:i.where}}:void 0).query.single,h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findFirst(h).then(_)}})}))};var le="ManualFiltersPlugin",ue=le,ve="applyFilters",V=class extends BasePlugin{wrapResolve(n,o){return async(u,r,e,a)=>{let p=(o?.type).type?.ref.currentConfig.pothosOptions[ve];if(!p||!Array.isArray(p)||p.length===0)return n(u,r,e,a);let l=await n(u,r,e,a),c=Array.isArray(l)?l:[l],s=Array.isArray(p)?p:[p],g=await se({filters:s,entities:c,context:e});return Array.isArray(l)?g:g[0]??null}}};Be.registerPlugin(le,V);var Oe=t=>`${B(toCamelCase(t.toString()))}WhereInputArgument`,pe=({db:t,schemaBuilder:n,enumImplementer:o})=>{let u=new Map,r=({table:e,refName:a,dbName:p})=>{let l=N({db:t,dbName:p,tsName:e}),c=a??Oe(l.tsName),s=u.get(c);return s||(s=n.inputType(c,{fields:i=>{let y=(h,D)=>{let I=G({sqlType:h,fieldName:D});switch(I){case "Int":return i.field({type:"IntWhereInputArgument"});case "String":return i.field({type:"StringWhereInputArgument"});case "Boolean":return i.boolean({required:false});case "Date":return i.field({type:"DateWhereInputArgument"});case "DateTime":return i.field({type:"DateWhereInputArgument"});case "Float":return i.field({type:"FloatWhereInputArgument"});case "ID":return i.id({required:false});case "JSON":return i.field({type:"JSON",required:false});default:throw new R(`Unsupported argument type ${I} for column ${h}`)}},d=Object.entries(l.columns).reduce((h,[D,I])=>{if(j(I)){let E=o({enumColumn:I});h[D]=i.field({type:E,required:false});}else h[D]=y(I.getSQLType(),D);return h},{}),b=Object.entries(l.relations??{}).reduce((h,[D,I])=>{let E=N({db:t,table:I.targetTable}),x=r({dbName:E.dbName});return h[D]=i.field({type:x,required:false}),h},{});return {...d,...b}}}),u.set(c,s),s)};return r};function me(t){let n=t.inputRef("IntWhereInputArgument").implement({fields:e=>({eq:e.int(),ne:e.int(),gt:e.int(),gte:e.int(),lt:e.int(),lte:e.int(),in:e.intList(),notIn:e.intList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.intList(),arrayContained:e.intList(),arrayContains:e.intList(),AND:e.field({type:[n]}),OR:e.field({type:[n]}),NOT:e.field({type:n})})}),o=t.inputRef("FloatWhereInputArgument").implement({fields:e=>({eq:e.float(),ne:e.float(),gt:e.float(),gte:e.float(),lt:e.float(),lte:e.float(),in:e.floatList(),notIn:e.floatList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.floatList(),arrayContained:e.floatList(),arrayContains:e.floatList(),AND:e.field({type:[o]}),OR:e.field({type:[o]}),NOT:e.field({type:o})})}),u=t.inputRef("StringWhereInputArgument").implement({fields:e=>({eq:e.string(),ne:e.string(),gt:e.string(),gte:e.string(),lt:e.string(),lte:e.string(),in:e.stringList(),notIn:e.stringList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.stringList(),arrayContained:e.stringList(),arrayContains:e.stringList(),AND:e.field({type:[u]}),OR:e.field({type:[u]}),NOT:e.field({type:u})})}),r=t.inputRef("DateWhereInputArgument").implement({fields:e=>({eq:e.field({type:"Date"}),ne:e.field({type:"Date"}),gt:e.field({type:"Date"}),gte:e.field({type:"Date"}),lt:e.field({type:"Date"}),lte:e.field({type:"Date"}),in:e.field({type:["Date"]}),notIn:e.field({type:["Date"]}),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.field({type:["Date"]}),arrayContained:e.field({type:["Date"]}),arrayContains:e.field({type:["Date"]}),AND:e.field({type:[r]}),OR:e.field({type:[r]}),NOT:e.field({type:r})})});}var ce=({db:t,disableDefaultObjects:n,pubsub:o,pothosConfig:u})=>{let r=new Be({...u,plugins:[ue,Le,qe,...u?.plugins??[]],drizzle:{client:t,relations:t._.relations,getTableConfig(e){return {columns:Object.values(e[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(e[Symbol.for("drizzle:Columns")]).filter(a=>a.primary)}}},smartSubscriptions:{...subscribeOptionsFromIterator((e,a)=>o.subscribe(e))}});return r.addScalarType("JSON",JSONResolver),r.addScalarType("Date",DateResolver),r.addScalarType("DateTime",DateTimeISOResolver),me(r),n?.query||r.queryType({}),n?.subscription||r.subscriptionType({}),n?.mutation||r.mutationType({}),{schemaBuilder:r}};var Ge=t=>{t.actions||(t.actions=["read","update","delete"]),t.defaultLimit===void 0&&(t.defaultLimit=100);let n=ee(t),o=te({...t,abilityBuilder:n}),{makePubSubInstance:u,pubsub:r}=oe({...t}),{schemaBuilder:e}=ce({...t,pubsub:r}),a=ne({...t,schemaBuilder:e}),p=pe({...t,schemaBuilder:e,enumImplementer:a}),l=re({...t,schemaBuilder:e,makePubSubInstance:u,argImplementer:p,enumImplementer:a,abilityBuilder:n}),c=ae({...t,schemaBuilder:e,argImplementer:p,makePubSubInstance:u});return {abilityBuilder:n,schemaBuilder:e,createYoga:g=>createYoga({...g,schema:e.toSchema(),context:o}),object:l,arg:p,query:c,pubsub:u,enum_:a}};export{R as RumbleError,q as RumbleErrorSafe,_ as assertFindFirstExists,Ne as assertFirstEntryExists,Ge as rumble};//# sourceMappingURL=index.js.map
|
7
|
+
`+W(this.source,o);return n}toJSON(){let n={message:this.message};return this.locations!=null&&(n.locations=this.locations),this.path!=null&&(n.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(n.extensions=this.extensions),n}};function Y(t){return t===void 0||t.length===0?void 0:t}var S=class extends Error{constructor(n){super(n),this.name="RumbleError";}},w=class extends q{};var K=t=>{if(!t)throw new w("Value not found but required (findFirst)");return t},be=t=>{let n=t.at(0);if(!n)throw new w("Value not found but required (firstEntry)");return n},X=async({filters:t,entities:n,context:o})=>(await Promise.all(t.map(u=>u({context:o,entities:n})))).reduce((u,r)=>(u.push(...r),u),[]);function z(t){let n,o=false;return ()=>(o||(n=t(),o=true),n)}var Q=(t,n)=>new S(`RumbleError: Unknown SQL type '${t}'. Please open an issue (https://github.com/m1212e/rumble/issues) so it can be added. (${n})`);function Z(t){if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t))return {value1:1,value2:2};if(["real","decimal","double","float"].includes(t))return {value1:1.1,value2:2.2};if(["string","text","varchar","char","text(256)"].includes(t))return {value1:"a",value2:"b"};if(["uuid"].includes(t))return {value1:"fba31870-5528-42d7-b27e-2e5ee657aea5",value2:"fc65db81-c2d1-483d-8a25-a30e2cf6e02d"};if(["boolean"].includes(t))return {value1:true,value2:false};if(["timestamp","datetime"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["date"].includes(t))return {value1:new Date(2022,1,1),value2:new Date(2022,1,2)};if(["json"].includes(t))return {value1:{a:1},value2:{b:2}};throw Q(t,"Distinct")}var _=Symbol.for("drizzle:Name"),ee=Symbol.for("drizzle:Columns");function N({dbName:t,tsName:n,table:o,db:u}){let r=o;if(n&&(r=u._.relations.schema[n]),t&&(r=Object.values(u._.relations.schema).find(e=>e[_]===t)),!r)throw new S(`Could not find schema for ${JSON.stringify({tsName:n,dbName:t,table:o?.[_]}).toString()}`);return {tableSchema:r,columns:r[ee],get primaryColumns(){return Object.entries(r[ee]).filter(([e,a])=>a.primary).reduce((e,[a,p])=>(e[a]=p,e),{})},relations:u._.relations.config[n],dbName:r[_],get tsName(){return Object.entries(u._.relations.schema).find(([e,a])=>a===r).at(0)}}}function he(t){return typeof t!="function"}function xe(t){return typeof t=="function"&&t.constructor.name!=="AsyncFunction"}var te=({db:t,actions:n,defaultLimit:o})=>{let u={},r={},e={},a=p=>{for(let l of n)e[p]||(e[p]={}),e[p][l]||(e[p][l]=[]);return {allow:l=>{let c=r[p];c||(c={},r[p]=c);let s=Array.isArray(l)?l:[l];for(let g of s){let i=c[g];i||(i="unspecified",c[g]=i);}return {when:g=>{for(let i of s)c[i]==="unspecified"&&(c[i]=[]),c[i].push(g);}}},filter:l=>{let c=Array.isArray(l)?l:[l];return {by:s=>{for(let g of c)e[p][g].push(s);}}}}};for(let p of Object.keys(t.query))u[p]=a(p);return {...u,registeredQueryFilters:r,registeredFilters:e,buildWithUserContext:p=>{let l={},c=s=>({filter:(g,i)=>{let y=m=>{let A=z(()=>{if(!(!m?.where&&!i?.inject?.where)){if(i?.inject?.where&&m?.where)return {AND:[m?.where,i?.inject?.where]};if(i?.inject?.where&&!m?.where)return i?.inject?.where;if(!i?.inject?.where&&m?.where)return m?.where;!i?.inject?.where&&m?.where;}}),P=z(()=>{let C=A();if(!C)return;let L=N({tsName:s,db:t});return relationsFilterToSQL(L.tableSchema,C)}),k=z(()=>{let C=m?.limit??o;return i?.inject?.limit&&(!C||C>i.inject.limit)&&(C=i.inject.limit),m?.limit&&(!C||m.limit>C)&&(C=m.limit),C??void 0}),v=z(()=>{if(!(!m?.columns&&!i?.inject?.columns))return {...m?.columns,...i?.inject?.columns}}),F={query:{single:{get where(){return A()},columns:v()},many:{get where(){return A()},columns:v(),get limit(){return k()}}},sql:{get where(){return P()},columns:v(),get limit(){return k()}}};return v()||(delete F.sql.columns,delete F.query.many.columns,delete F.query.single.columns),F},d=()=>{let m=N({db:t,tsName:s});if(Object.keys(m.primaryColumns).length===0)throw new S(`No primary key found for entity ${s.toString()}`);let A=Object.values(m.primaryColumns)[0],P=Z(A.getSQLType());return {where:{AND:[{[A.name]:P.value1},{[A.name]:P.value2}]}}},b=r?.[s]?.[g];if(b==="unspecified")return y();b||(b=[d()]);let h=b.filter(he),D=b.filter(xe).map(m=>m(p)),I=D.some(m=>m==="allow"),E=[...h,...D].filter(m=>m!==void 0).filter(m=>m!=="allow");!I&&E.length===0&&(E=[d()]);let x;for(let m of E)m?.limit&&(x===void 0||m.limit>x)&&(x=m.limit);let f;for(let m of [...E,i?.inject])m?.columns&&(f===void 0?f=m.columns:f={...f,...m.columns});let T=I?[]:E.filter(m=>m?.where).map(m=>m.where),R=T.length>0?{OR:T}:void 0;return y({where:R,columns:f,limit:x})},explicitFilters:g=>e[s][g]});for(let s of Object.keys(t.query))l[s]=c(s);return l}}};var ne=({context:t,abilityBuilder:n})=>async o=>{let u=t?await t(o):{};return {...u,abilities:n.buildWithUserContext(u)}};function B(t){return String(t).charAt(0).toUpperCase()+String(t).slice(1)}function j(t){return t instanceof PgEnumColumn}var re=({db:t,schemaBuilder:n})=>{let o=new Map;return ({tsName:r,enumColumn:e,refName:a})=>{let p,l;if(r){let i=t._.relations.schema[r];p=r.toString();let y=Object.values(t._.relations.schema).filter(d=>typeof d=="object").map(d=>Object.values(d[Symbol.for("drizzle:Columns")])).flat(2).find(d=>d.config?.enum===i);if(!y)throw new S(`Could not find applied enum column for ${r.toString()}.
|
8
|
+
Please ensure that you use the enum at least once as a column of a table!`);l=y.enumValues;}else if(e){let i=Object.entries(t._.relations.schema).find(([y,d])=>d===e.config.enum);if(!i)throw new S(`Could not find enum in schema for ${e.name}!`);p=i[0],l=e.enumValues;}if(!p||!l)throw new S("Could not determine enum structure!");let c=a??`${B(toCamelCase(p))}Enum`,s=o.get(c);return s||(s=n.enumType(c,{values:l}),o.set(c,s),s)}};function G({sqlType:t,fieldName:n}){let o;if(["serial","int","integer","tinyint","smallint","mediumint"].includes(t)&&(o="Int"),["real","decimal","double","float"].includes(t)&&(o="Float"),["string","text","varchar","char","text(256)"].includes(t)&&(n&&(n.toLowerCase().endsWith("_id")||n.toLowerCase().endsWith("id"))?o="ID":o="String"),["uuid"].includes(t)&&(o="ID"),["boolean"].includes(t)&&(o="Boolean"),["timestamp","datetime"].includes(t)&&(o="DateTime"),["date"].includes(t)&&(o="Date"),["json"].includes(t)&&(o="JSON"),o!==void 0)return o;throw Q(t,"SQL to GQL")}var Re=t=>typeof t!="object"?false:!!Object.keys(t).some(n=>["args","nullable","query","subscribe","description","type","resolve"].find(o=>o===n)),ie=({db:t,schemaBuilder:n,makePubSubInstance:o,argImplementer:u,enumImplementer:r,abilityBuilder:e})=>({table:a,refName:p,readAction:l="read",adjust:c})=>{let s=N({db:t,tsName:a});Object.keys(s.primaryColumns).length===0&&console.warn(`Could not find primary key for ${a.toString()}. Cannot register subscriptions!`);let g=Object.values(s.primaryColumns)[0],{registerOnInstance:i}=o({table:a});return n.drizzleObject(a,{name:p??B(a.toString()),subscribe:(y,d,b)=>{if(!g)return;let h=d[g.name];if(!h){console.warn(`Could not find primary key value for ${JSON.stringify(d)}. Cannot register subscription!`);return}i({instance:y,action:"updated",primaryKeyValue:h});},applyFilters:e?.registeredFilters?.[a]?.[l],fields:y=>{let d=s.columns,b=(x,f,T)=>{let R=G({sqlType:x,fieldName:f});switch(R){case "Int":return y.exposeInt(f,{nullable:T});case "String":return y.exposeString(f,{nullable:T});case "Boolean":return y.exposeBoolean(f,{nullable:T});case "Date":return y.field({type:"Date",resolve:m=>m[f],nullable:T});case "DateTime":return y.field({type:"DateTime",resolve:m=>m[f],nullable:T});case "Float":return y.exposeFloat(f,{nullable:T});case "ID":return y.exposeID(f,{nullable:T});case "JSON":return y.field({type:"JSON",resolve:m=>m[f],nullable:T});default:throw new S(`Unsupported object type ${R} for column ${f}`)}},h=new Map,D=c?.(new Proxy(y,{get:(x,f)=>typeof x[f]=="function"?(...T)=>{let R=x[f](...T),m=T.find(Re);if(!m)throw new S("Expected config object to be passed to adjust field");return h.set(R,{params:T,creatorFunction:x[f],configObject:m}),R}:x[f]}))??{},I=Object.entries(d).reduce((x,[f,T])=>{if(D[f]){let{params:R,creatorFunction:m,configObject:A}=h.get(D[f]);return typeof A.nullable!="boolean"&&(A.nullable=!T.notNull),D[f]=m.bind(y)(...R),x}if(j(T)){let R=r({enumColumn:T});x[f]=y.field({type:R,resolve:m=>m[f],nullable:!T.notNull});}else x[f]=b(T.getSQLType(),f,!T.notNull);return x},{}),E=Object.entries(s.relations??{}).reduce((x,[f,T])=>{let R=N({db:t,table:T.targetTable}),m=u({dbName:R.dbName}),A=o({table:R.tsName}),P=false,k=true,v="many";T instanceof One&&(k=false,P=T.optional,v="single");let F=(C,L)=>{A.registerOnInstance({instance:C,action:"created"}),A.registerOnInstance({instance:C,action:"removed"});};if(D[f]){let{params:C,creatorFunction:L,configObject:O}=h.get(D[f]);return typeof O.nullable!="boolean"&&(O.nullable=P),typeof O.subscribe!="function"&&(O.subscribe=F),D[f]=L.bind(y)(...C),x}return x[f]=y.relation(f,{args:{where:y.arg({type:m,required:false}),...k?{offset:y.arg.int({required:false}),limit:y.arg.int({required:false})}:{}},subscribe:F,nullable:P,query:(C,L)=>{C=JSON.parse(JSON.stringify(C));let O=L.abilities[R.tsName].filter(l,{inject:{where:C.where,limit:C.limit}}).query[v];return C.offset&&(O.offset=C.offset),O}}),x},{});return {...I,...E,...D}}})};var Ie="RUMBLE_SUBSCRIPTION_NOTIFICATION",Ae="REMOVED",Ee="UPDATED",Ne="CREATED",se=({subscriptions:t,db:n})=>{let o=t?createPubSub(...t):createPubSub();return {pubsub:o,makePubSubInstance:({table:r})=>{function e({action:a,tableName:p,primaryKeyValue:l}){let c;switch(a){case "created":c=Ne;break;case "removed":c=Ae;break;case "updated":c=Ee;break;default:throw new Error(`Unknown action: ${a}`)}return `${Ie}/${p}${l?`/${l}`:""}/${c}`}return {registerOnInstance({instance:a,action:p,primaryKeyValue:l}){let c=e({tableName:r.toString(),action:p,primaryKeyValue:l});a.register(c);},created(){let a=e({tableName:r.toString(),action:"created"});return o.publish(a)},removed(a){let p=e({tableName:r.toString(),action:"removed"});return o.publish(p)},updated(a){let l=(Array.isArray(a)?a:[a]).map(s=>e({tableName:r.toString(),action:"updated",primaryKeyValue:s})),c=Array.from(new Set(l));for(let s of c)o.publish(s);}}}}};var ae=({db:t,schemaBuilder:n,argImplementer:o,makePubSubInstance:u})=>({table:r,readAction:e="read",listAction:a="read"})=>{let p=o({table:r}),{registerOnInstance:l}=u({table:r});return n.queryFields(c=>({[`findMany${B(r.toString())}`]:c.drizzleField({type:[r],nullable:false,smartSubscription:true,subscribe:(s,g,i,y,d)=>{l({instance:s,action:"created"}),l({instance:s,action:"removed"});},args:{where:c.arg({type:p,required:false}),limit:c.arg.int({required:false}),offset:c.arg.int({required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(a,i.where||i.limit||i.offset?{inject:{where:i.where,limit:i.limit}}:void 0).query.many;i.offset&&(b.offset=i.offset);let h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findMany(h)}}),[`findFirst${B(r.toString())}`]:c.drizzleField({type:r,nullable:false,smartSubscription:true,args:{where:c.arg({type:p,required:false})},resolve:(s,g,i,y,d)=>{i=JSON.parse(JSON.stringify(i));let b=y.abilities[r].filter(e,i.where?{inject:{where:i.where}}:void 0).query.single,h=s(b);return b.columns&&(h.columns=b.columns),t.query[r].findFirst(h).then(K)}})}))};var le="ManualFiltersPlugin",ue=le,ve="applyFilters",V=class extends BasePlugin{wrapResolve(n,o){return async(u,r,e,a)=>{let p=(o?.type).type?.ref.currentConfig.pothosOptions[ve];if(!p||!Array.isArray(p)||p.length===0)return n(u,r,e,a);let l=await n(u,r,e,a),c=Array.isArray(l)?l:[l],s=Array.isArray(p)?p:[p],g=await X({filters:s,entities:c,context:e});return Array.isArray(l)?g:g[0]??null}}};Be.registerPlugin(le,V);var Oe=t=>`${B(toCamelCase(t.toString()))}WhereInputArgument`,pe=({db:t,schemaBuilder:n,enumImplementer:o})=>{let u=new Map,r=({table:e,refName:a,dbName:p})=>{let l=N({db:t,dbName:p,tsName:e}),c=a??Oe(l.tsName),s=u.get(c);return s||(s=n.inputType(c,{fields:i=>{let y=(h,D)=>{let I=G({sqlType:h,fieldName:D});switch(I){case "Int":return i.field({type:"IntWhereInputArgument"});case "String":return i.field({type:"StringWhereInputArgument"});case "Boolean":return i.boolean({required:false});case "Date":return i.field({type:"DateWhereInputArgument"});case "DateTime":return i.field({type:"DateWhereInputArgument"});case "Float":return i.field({type:"FloatWhereInputArgument"});case "ID":return i.id({required:false});case "JSON":return i.field({type:"JSON",required:false});default:throw new S(`Unsupported argument type ${I} for column ${h}`)}},d=Object.entries(l.columns).reduce((h,[D,I])=>{if(j(I)){let E=o({enumColumn:I});h[D]=i.field({type:E,required:false});}else h[D]=y(I.getSQLType(),D);return h},{}),b=Object.entries(l.relations??{}).reduce((h,[D,I])=>{let E=N({db:t,table:I.targetTable}),x=r({dbName:E.dbName});return h[D]=i.field({type:x,required:false}),h},{});return {...d,...b}}}),u.set(c,s),s)};return r};function me(t){let n=t.inputRef("IntWhereInputArgument").implement({fields:e=>({eq:e.int(),ne:e.int(),gt:e.int(),gte:e.int(),lt:e.int(),lte:e.int(),in:e.intList(),notIn:e.intList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.intList(),arrayContained:e.intList(),arrayContains:e.intList(),AND:e.field({type:[n]}),OR:e.field({type:[n]}),NOT:e.field({type:n})})}),o=t.inputRef("FloatWhereInputArgument").implement({fields:e=>({eq:e.float(),ne:e.float(),gt:e.float(),gte:e.float(),lt:e.float(),lte:e.float(),in:e.floatList(),notIn:e.floatList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.floatList(),arrayContained:e.floatList(),arrayContains:e.floatList(),AND:e.field({type:[o]}),OR:e.field({type:[o]}),NOT:e.field({type:o})})}),u=t.inputRef("StringWhereInputArgument").implement({fields:e=>({eq:e.string(),ne:e.string(),gt:e.string(),gte:e.string(),lt:e.string(),lte:e.string(),in:e.stringList(),notIn:e.stringList(),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.stringList(),arrayContained:e.stringList(),arrayContains:e.stringList(),AND:e.field({type:[u]}),OR:e.field({type:[u]}),NOT:e.field({type:u})})}),r=t.inputRef("DateWhereInputArgument").implement({fields:e=>({eq:e.field({type:"Date"}),ne:e.field({type:"Date"}),gt:e.field({type:"Date"}),gte:e.field({type:"Date"}),lt:e.field({type:"Date"}),lte:e.field({type:"Date"}),in:e.field({type:["Date"]}),notIn:e.field({type:["Date"]}),like:e.string(),ilike:e.string(),notLike:e.string(),notIlike:e.string(),isNull:e.boolean(),isNotNull:e.boolean(),arrayOverlaps:e.field({type:["Date"]}),arrayContained:e.field({type:["Date"]}),arrayContains:e.field({type:["Date"]}),AND:e.field({type:[r]}),OR:e.field({type:[r]}),NOT:e.field({type:r})})});}var ce=({db:t,disableDefaultObjects:n,pubsub:o,pothosConfig:u})=>{let r=new Be({...u,plugins:[ue,Le,qe,...u?.plugins??[]],drizzle:{client:t,relations:t._.relations,getTableConfig(e){return {columns:Object.values(e[Symbol.for("drizzle:Columns")]),primaryKeys:Object.values(e[Symbol.for("drizzle:Columns")]).filter(a=>a.primary)}}},smartSubscriptions:{...subscribeOptionsFromIterator((e,a)=>o.subscribe(e))}});return r.addScalarType("JSON",JSONResolver),r.addScalarType("Date",DateResolver),r.addScalarType("DateTime",DateTimeISOResolver),me(r),n?.query||r.queryType({}),n?.subscription||r.subscriptionType({}),n?.mutation||r.mutationType({}),{schemaBuilder:r}};var We=t=>{t.actions||(t.actions=["read","update","delete"]),t.defaultLimit===void 0&&(t.defaultLimit=100);let n=te(t),o=ne({...t,abilityBuilder:n}),{makePubSubInstance:u,pubsub:r}=se({...t}),{schemaBuilder:e}=ce({...t,pubsub:r}),a=re({...t,schemaBuilder:e}),p=pe({...t,schemaBuilder:e,enumImplementer:a}),l=ie({...t,schemaBuilder:e,makePubSubInstance:u,argImplementer:p,enumImplementer:a,abilityBuilder:n}),c=ae({...t,schemaBuilder:e,argImplementer:p,makePubSubInstance:u}),s=z(()=>e.toSchema());return {abilityBuilder:n,schemaBuilder:e,createYoga:y=>createYoga({...y,schema:s(),context:o}),createSofa:y=>useSofa({...y,schema:s(),context:o}),object:l,arg:p,query:c,pubsub:u,enum_:a}};export{S as RumbleError,w as RumbleErrorSafe,K as assertFindFirstExists,be as assertFirstEntryExists,We as rumble};//# sourceMappingURL=index.js.map
|
9
9
|
//# sourceMappingURL=index.js.map
|