@m1212e/rumble 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs.map +1 -1
- package/index.d.cts +29 -1
- package/index.d.ts +29 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../lib/abilities/builder.ts","../lib/helpers/rumbleError.ts","../lib/gql/builder.ts","../lib/helpers/helper.ts"],"names":["isSimpleCondition","condition","isSyncFunctionCondition","createAbilityBuilder","db","builder","registeredConditions","createEntityObject","entityKey","action","conditionsPerEntity","actions","conditionsPerEntityAndAction","userContext","simpleConditions","syncFunctionConditions","allConditionObjects","highestLimit","conditionObject","combinedAllowedColumns","accumulatedWhereConditions","o","or","RumbleError","message","rumble","nativeServerOptions","makeUserContext","onlyQuery","abilityBuilder","makeContext","req","nativeBuilder","SchemaBuilder","DrizzlePlugin","createYoga","tableName","name","readAction","schema","t","mapSQLTypeStringToExposedPothosType","sqlType","columnName","fields","acc","key","value","relations","_args","ctx","assertFindFirstExists","assertFirstEntryExists","v"],"mappings":"oTAwBA,SAASA,CACRC,CAAAA,CAAAA,CAC6C,CAC7C,OAAO,OAAOA,CAAAA,EAAc,UAC7B,CAEA,SAASC,CACRD,CAAAA,CAAAA,CACgE,CAChE,OACC,OAAOA,CAAc,EAAA,UAAA,EACrBA,CAAU,CAAA,WAAA,CAAY,OAAS,eAEjC,CAWO,IAAME,CAAAA,CAAuB,CAIlC,CACD,EAAAC,CAAAA,CACD,IAEM,CAIL,IAAMC,CAEF,CAAA,EAEEC,CAAAA,CAAAA,CAQF,EAAC,CAECC,EAAsBC,CAA2B,GAAA,CACtD,KAAQC,CAAAA,CAAAA,EAA8B,CACrC,IAAIC,CAAsBJ,CAAAA,CAAAA,CAAqBE,CAAS,CACnDE,CAAAA,CAAAA,GACJA,CAAsB,CAAA,GACtBJ,CAAqBE,CAAAA,CAAS,CAAIE,CAAAA,CAAAA,CAAAA,CAGnC,IAAMC,CAA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,CAA4B,EAAA,CACpE,GAAI,CAACA,CAAAA,CAAO,MAAM,IAAIxB,CAAY,CAAA,0CAA0C,CAC5E,CAAA,OAAOwB,CACR,CAyCaK,CAAAA,CAAAA,CAA6BL,CAAkB,EAAA,CAC3D,IAAMM,CAAAA,CAAIN,CAAM,CAAA,EAAA,CAAG,CAAC,CACpB,CAAA,GAAI,CAACM,CAAAA,CAAG,MAAM,IAAI9B,CAAAA,CAAY,2CAA2C,CAAA,CACzE,OAAO8B,CACR","file":"index.cjs","sourcesContent":["import { SQL, or } from \"drizzle-orm\";\nimport type { ExcludeFromUnionIfNotOnlyType } from \"../helpers/unionTypeExclude\";\nimport type { ExcludeFirst } from \"../helpers/unionTypeExtractor\";\nimport type {\n\tGenericDrizzleDbTypeConstraints,\n\tQueryConditionObject,\n} from \"../types/genericDrizzleDbType\";\n\nexport type AbilityBuilder = ReturnType<typeof createAbilityBuilder>;\n\ntype Condition<DBParameters, UserContext> =\n\t| SimpleCondition<DBParameters>\n\t| SyncFunctionCondition<DBParameters, UserContext>;\n// | AsyncFunctionCondition<DBParameters, UserContext>;\n\ntype SimpleCondition<DBParameters> = DBParameters;\ntype SyncFunctionCondition<DBParameters, UserContext> = (\n\tcontext: UserContext,\n) => DBParameters;\n// type AsyncFunctionCondition<DBParameters, UserContext> = (\n// \tcontext: UserContext,\n// ) => Promise<DBParameters>;\n\n// type guards for the condition types\nfunction isSimpleCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SimpleCondition<DBParameters> {\n\treturn typeof condition !== \"function\";\n}\n\nfunction isSyncFunctionCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SyncFunctionCondition<DBParameters, UserContext> {\n\treturn (\n\t\ttypeof condition === \"function\" &&\n\t\tcondition.constructor.name !== \"AsyncFunction\"\n\t);\n}\n\n// function isAsyncFunctionCondition<DBParameters, UserContext>(\n// \tcondition: Condition<DBParameters, UserContext>,\n// ): condition is AsyncFunctionCondition<DBParameters, UserContext> {\n// \treturn (\n// \t\ttypeof condition === \"function\" &&\n// \t\tcondition.constructor.name === \"AsyncFunction\"\n// \t);\n// }\n\nexport const createAbilityBuilder = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tAction extends string,\n>({\n\tdb,\n}: {\n\tdb: DB;\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\ttype DBParameters = Parameters<DB[\"query\"][DBQueryKey][\"findMany\"]>[0];\n\n\tconst builder: {\n\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t} = {} as any;\n\n\tconst registeredConditions: {\n\t\t[key in DBQueryKey]: {\n\t\t\t[key in Action[number]]: (\n\t\t\t\t| QueryConditionObject\n\t\t\t\t| ((context: UserContext) => QueryConditionObject)\n\t\t\t)[];\n\t\t\t// | ((context: UserContext) => Promise<QueryConditionObject>)\n\t\t};\n\t} = {} as any;\n\n\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\tallow: (action: Action | Action[]) => {\n\t\t\tlet conditionsPerEntity = registeredConditions[entityKey];\n\t\t\tif (!conditionsPerEntity) {\n\t\t\t\tconditionsPerEntity = {} as any;\n\t\t\t\tregisteredConditions[entityKey] = conditionsPerEntity;\n\t\t\t}\n\n\t\t\tconst actions = Array.isArray(action) ? action : [action];\n\t\t\tfor (const action of actions) {\n\t\t\t\tlet conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\tconditionsPerEntityAndAction = [];\n\t\t\t\t\tconditionsPerEntity[action] = conditionsPerEntityAndAction;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\twhen: (condition: Condition<DBParameters, UserContext>) => {\n\t\t\t\t\tfor (const action of actions) {\n\t\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\t\tconditionsPerEntityAndAction.push(condition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t}\n\treturn {\n\t\t...builder,\n\t\tregisteredConditions,\n\t\tbuildWithUserContext: (userContext: UserContext) => {\n\t\t\tconst builder: {\n\t\t\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t\t\t} = {} as any;\n\n\t\t\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\t\t\tfilter: (action: Action) => {\n\t\t\t\t\tconst conditionsPerEntity = registeredConditions[entityKey];\n\t\t\t\t\tif (!conditionsPerEntity) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #1\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #2\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst simpleConditions =\n\t\t\t\t\t\tconditionsPerEntityAndAction.filter(isSimpleCondition);\n\n\t\t\t\t\tconst syncFunctionConditions = conditionsPerEntityAndAction\n\t\t\t\t\t\t.filter(isSyncFunctionCondition)\n\t\t\t\t\t\t.map((condition) => condition(userContext));\n\n\t\t\t\t\t// const asyncFunctionConditions = await Promise.all(\n\t\t\t\t\t// \tconditionsPerEntityAndAction\n\t\t\t\t\t// \t\t.filter(isAsyncFunctionCondition)\n\t\t\t\t\t// \t\t.map((condition) => condition(userContext)),\n\t\t\t\t\t// );\n\n\t\t\t\t\tconst allConditionObjects = [\n\t\t\t\t\t\t...simpleConditions,\n\t\t\t\t\t\t...syncFunctionConditions,\n\t\t\t\t\t\t// ...asyncFunctionConditions,\n\t\t\t\t\t];\n\n\t\t\t\t\tlet highestLimit = undefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.limit) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\thighestLimit === undefined ||\n\t\t\t\t\t\t\t\tconditionObject.limit > highestLimit\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\thighestLimit = conditionObject.limit;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet combinedAllowedColumns: Record<string, any> | undefined =\n\t\t\t\t\t\tundefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.columns) {\n\t\t\t\t\t\t\tif (combinedAllowedColumns === undefined) {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = conditionObject.columns;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = {\n\t\t\t\t\t\t\t\t\t...combinedAllowedColumns,\n\t\t\t\t\t\t\t\t\t...conditionObject.columns,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accumulatedWhereConditions = allConditionObjects\n\t\t\t\t\t\t.filter((o) => o.where)\n\t\t\t\t\t\t.map((o) => o.where);\n\n\t\t\t\t\tconst combinedWhere =\n\t\t\t\t\t\taccumulatedWhereConditions.length > 0\n\t\t\t\t\t\t\t? or(...accumulatedWhereConditions)\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twhere: combinedWhere,\n\t\t\t\t\t\tcolumns: combinedAllowedColumns,\n\t\t\t\t\t\tlimit: highestLimit,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\t\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t\t\t}\n\n\t\t\treturn builder;\n\t\t},\n\t};\n};\n","export class RumbleError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RumbleError\";\n\t}\n}\n","import SchemaBuilder, { FieldRef } from \"@pothos/core\";\nimport DrizzlePlugin from \"@pothos/plugin-drizzle\";\nimport { type YogaServerOptions, createYoga } from \"graphql-yoga\";\nimport { createAbilityBuilder } from \"../abilities/builder\";\nimport { RumbleError } from \"../helpers/rumbleError\";\nimport type { GenericDrizzleDbTypeConstraints } from \"../types/genericDrizzleDbType\";\n\nexport const rumble = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tRequestEvent extends Record<string, any>,\n\tAction extends string = \"create\" | \"read\" | \"update\" | \"delete\",\n>({\n\tdb,\n\tnativeServerOptions,\n\tcontext: makeUserContext,\n\tonlyQuery = false,\n\tactions = [\"create\", \"read\", \"update\", \"delete\"] as Action[],\n}: {\n\t/**\n\t * Your drizzle database instance\n\t */\n\tdb: DB;\n\t/**\n\t * Optional options for the native GraphQL Yoga server\n\t */\n\tnativeServerOptions?:\n\t\t| Omit<YogaServerOptions<RequestEvent, any>, \"schema\" | \"context\">\n\t\t| undefined;\n\t/**\n\t * A function for providing context for each request based on the incoming HTTP Request.\n\t * The type of the parameter equals the HTTPRequest type of your chosen server.\n\t */\n\tcontext?:\n\t\t| ((event: RequestEvent) => Promise<UserContext> | UserContext)\n\t\t| undefined;\n\t/**\n\t * If you only want to create queries and do not need mutations, enable this\n\t */\n\tonlyQuery?: boolean;\n\t/**\n\t * The actions that are available\n\t */\n\tactions?: Action[];\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\tconst abilityBuilder = createAbilityBuilder<UserContext, DB, Action>({\n\t\tdb,\n\t});\n\n\tconst makeContext = async (req: RequestEvent) => {\n\t\tconst userContext = makeUserContext\n\t\t\t? await makeUserContext(req)\n\t\t\t: ({} as UserContext);\n\t\treturn {\n\t\t\t...userContext,\n\t\t\tabilities: abilityBuilder.buildWithUserContext(userContext),\n\t\t};\n\t};\n\n\tconst nativeBuilder = new SchemaBuilder<{\n\t\tContext: Awaited<ReturnType<typeof makeContext>>;\n\t\t// Scalars: Scalars<Prisma.Decimal, Prisma.InputJsonValue | null, Prisma.InputJsonValue> & {\n\t\t// \tFile: {\n\t\t// \t\tInput: File;\n\t\t// \t\tOutput: never;\n\t\t// \t};\n\t\t// \tJSONObject: {\n\t\t// \t\tInput: any;\n\t\t// \t\tOutput: any;\n\t\t// \t};\n\t\t// };\n\t\tDrizzleSchema: DB[\"_\"][\"fullSchema\"];\n\t\tDefaultFieldNullability: false;\n\t\tDefaultArgumentNullability: false;\n\t\tDefaultInputFieldRequiredness: true;\n\t}>({\n\t\tplugins: [DrizzlePlugin],\n\t\tdrizzle: {\n\t\t\tclient: db,\n\t\t},\n\t\tdefaultFieldNullability: false,\n\t\tdefaultInputFieldRequiredness: true,\n\t});\n\n\tnativeBuilder.queryType({});\n\n\tif (!onlyQuery) {\n\t\tnativeBuilder.mutationType({});\n\t}\n\n\tconst implementDefaultObject = <\n\t\tExplicitTableName extends DBQueryKey,\n\t\tRefName extends string,\n\t>({\n\t\ttableName,\n\t\tname,\n\t\treadAction = \"read\" as Action,\n\t}: {\n\t\ttableName: ExplicitTableName;\n\t\tname: RefName;\n\t\treadAction?: Action;\n\t}) => {\n\t\tconst schema = db._.schema![tableName as any];\n\t\treturn nativeBuilder.drizzleObject(tableName as any, {\n\t\t\tname,\n\t\t\tfields: (t) => {\n\t\t\t\tconst mapSQLTypeStringToExposedPothosType = (\n\t\t\t\t\tsqlType: string,\n\t\t\t\t\tcolumnName: string,\n\t\t\t\t) => {\n\t\t\t\t\tswitch (sqlType) {\n\t\t\t\t\t\tcase \"serial\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"int\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"boolean\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeBoolean(columnName);\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new RumbleError(\n\t\t\t\t\t\t\t\t`Unknown SQL type: ${sqlType}. Please open an issue so it can be added.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tconst fields = Object.entries(schema.columns).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = mapSQLTypeStringToExposedPothosType(\n\t\t\t\t\t\t\tvalue.getSQLType(),\n\t\t\t\t\t\t\tvalue.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\tconst relations = Object.entries(schema.relations).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = t.relation(key, {\n\t\t\t\t\t\t\tquery: (_args: any, ctx: any) =>\n\t\t\t\t\t\t\t\tctx.abilities[tableName as any].filter(readAction),\n\t\t\t\t\t\t} as any) as any;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\t...fields,\n\t\t\t\t\t...relations,\n\t\t\t\t} as any;\n\t\t\t},\n\t\t}) as any;\n\t};\n\n\treturn {\n\t\t/**\n * The ability builder. Use it to declare whats allowed for each entity in your DB.\n * \n * @example\n * \n * ```ts\n * // users can edit themselves\n abilityBuilder.users\n .allow([\"read\", \"update\", \"delete\"])\n .when(({ userId }) => ({ where: eq(schema.users.id, userId) }));\n \n // everyone can read posts\n abilityBuilder.posts.allow(\"read\");\n * \n * ```\n */\n\t\tabilityBuilder,\n\t\t/**\n\t\t * The pothos schema builder. See https://pothos-graphql.dev/docs/plugins/drizzle\n\t\t */\n\t\tschemaBuilder: nativeBuilder,\n\t\t/**\n * The native yoga instance. Can be used to run an actual HTTP server.\n * \n * @example\n * \n * ```ts\n import { createServer } from \"node:http\";\n * const server = createServer(yoga());\n server.listen(3000, () => {\n console.log(\"Visit http://localhost:3000/graphql\");\n });\n * ```\n */\n\t\tyoga: () =>\n\t\t\tcreateYoga<RequestEvent>({\n\t\t\t\t...nativeServerOptions,\n\t\t\t\tschema: nativeBuilder.toSchema(),\n\t\t\t\tcontext: makeContext,\n\t\t\t}),\n\t\t/**\n\t\t * A function for creating default objects for your schema\n\t\t */\n\t\timplementDefaultObject,\n\t};\n};\n","import { RumbleError } from \"./rumbleError\";\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n * schemaBuilder.queryFields((t) => {\n return {\n findFirstUser: t.drizzleField({\n type: UserRef,\n resolve: (query, root, args, ctx, info) => {\n return (\n db.query.users\n .findFirst({\n ...query,\n where: ctx.abilities.users.filter(\"read\").where,\n })\n // note that we need to manually raise an error if the value is not found\n .then(assertFindFirstExists)\n );\n },\n }),\n };\n });\n * ```\n */\nexport const assertFindFirstExists = <T>(value: T | undefined): T => {\n\tif (!value) throw new RumbleError(\"Value not found but required (findFirst)\");\n\treturn value;\n};\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n schemaBuilder.mutationFields((t) => {\n return {\n updateUsername: t.drizzleField({\n type: UserRef,\n args: {\n userId: t.arg.int({ required: true }),\n newName: t.arg.string({ required: true }),\n },\n resolve: (query, root, args, ctx, info) => {\n return db\n .update(schema.users)\n .set({\n name: args.newName,\n })\n .where(\n and(\n eq(schema.users.id, args.userId),\n ctx.abilities.users.filter(\"update\").where\n )\n )\n .returning({ id: schema.users.id, name: schema.users.name })\n // note that we need to manually raise an error if the value is not found\n .then(assertFirstEntryExists);\n },\n }),\n };\n });\n * ```\n */\nexport const assertFirstEntryExists = <T>(value: T[]): T => {\n\tconst v = value.at(0);\n\tif (!v) throw new RumbleError(\"Value not found but required (firstEntry)\");\n\treturn v;\n};\n"]}
|
1
|
+
{"version":3,"sources":["../lib/abilities/builder.ts","../lib/helpers/rumbleError.ts","../lib/gql/builder.ts","../lib/helpers/helper.ts"],"names":["isSimpleCondition","condition","isSyncFunctionCondition","createAbilityBuilder","db","builder","registeredConditions","createEntityObject","entityKey","action","conditionsPerEntity","actions","conditionsPerEntityAndAction","userContext","simpleConditions","syncFunctionConditions","allConditionObjects","highestLimit","conditionObject","combinedAllowedColumns","accumulatedWhereConditions","o","or","RumbleError","message","rumble","nativeServerOptions","makeUserContext","onlyQuery","abilityBuilder","makeContext","req","nativeBuilder","SchemaBuilder","DrizzlePlugin","createYoga","tableName","name","readAction","schema","t","mapSQLTypeStringToExposedPothosType","sqlType","columnName","fields","acc","key","value","relations","_args","ctx","assertFindFirstExists","assertFirstEntryExists","v"],"mappings":"oTAwBA,SAASA,CACRC,CAAAA,CAAAA,CAC6C,CAC7C,OAAO,OAAOA,CAAAA,EAAc,UAC7B,CAEA,SAASC,CACRD,CAAAA,CAAAA,CACgE,CAChE,OACC,OAAOA,CAAc,EAAA,UAAA,EACrBA,CAAU,CAAA,WAAA,CAAY,OAAS,eAEjC,CAWO,IAAME,CAAAA,CAAuB,CAIlC,CACD,EAAAC,CAAAA,CACD,IAEM,CAIL,IAAMC,CAEF,CAAA,EAEEC,CAAAA,CAAAA,CAQF,EAAC,CAECC,EAAsBC,CAA2B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,SAAA,CAAUd,CAAgB,CAAE,CAAA,MAAA,CAAOE,CAAU,CACnD,CAAQ,CAAA,CACDO,CAER,CAAA,CAAA,EAID,CAEA,CAAA,OAAO,CACN,GAAGD,EACH,GAAGI,CACJ,CACD,CACD,CAAC,CACF,CA+CA,CACD,ECxLaG,IAAAA,CAAAA,CAA4BJ,CAA4B,EAAA,CACpE,GAAI,CAACA,CAAAA,CAAO,MAAM,IAAIxB,CAAY,CAAA,0CAA0C,CAC5E,CAAA,OAAOwB,CACR,CAyCaK,CAAAA,CAAAA,CAA6BL,CAAkB,EAAA,CAC3D,IAAMM,CAAAA,CAAIN,CAAM,CAAA,EAAA,CAAG,CAAC,CACpB,CAAA,GAAI,CAACM,CAAAA,CAAG,MAAM,IAAI9B,CAAAA,CAAY,2CAA2C,CAAA,CACzE,OAAO8B,CACR","file":"index.cjs","sourcesContent":["import { SQL, or } from \"drizzle-orm\";\nimport type { ExcludeFromUnionIfNotOnlyType } from \"../helpers/unionTypeExclude\";\nimport type { ExcludeFirst } from \"../helpers/unionTypeExtractor\";\nimport type {\n\tGenericDrizzleDbTypeConstraints,\n\tQueryConditionObject,\n} from \"../types/genericDrizzleDbType\";\n\nexport type AbilityBuilder = ReturnType<typeof createAbilityBuilder>;\n\ntype Condition<DBParameters, UserContext> =\n\t| SimpleCondition<DBParameters>\n\t| SyncFunctionCondition<DBParameters, UserContext>;\n// | AsyncFunctionCondition<DBParameters, UserContext>;\n\ntype SimpleCondition<DBParameters> = DBParameters;\ntype SyncFunctionCondition<DBParameters, UserContext> = (\n\tcontext: UserContext,\n) => DBParameters;\n// type AsyncFunctionCondition<DBParameters, UserContext> = (\n// \tcontext: UserContext,\n// ) => Promise<DBParameters>;\n\n// type guards for the condition types\nfunction isSimpleCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SimpleCondition<DBParameters> {\n\treturn typeof condition !== \"function\";\n}\n\nfunction isSyncFunctionCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SyncFunctionCondition<DBParameters, UserContext> {\n\treturn (\n\t\ttypeof condition === \"function\" &&\n\t\tcondition.constructor.name !== \"AsyncFunction\"\n\t);\n}\n\n// function isAsyncFunctionCondition<DBParameters, UserContext>(\n// \tcondition: Condition<DBParameters, UserContext>,\n// ): condition is AsyncFunctionCondition<DBParameters, UserContext> {\n// \treturn (\n// \t\ttypeof condition === \"function\" &&\n// \t\tcondition.constructor.name === \"AsyncFunction\"\n// \t);\n// }\n\nexport const createAbilityBuilder = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tAction extends string,\n>({\n\tdb,\n}: {\n\tdb: DB;\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\ttype DBParameters = Parameters<DB[\"query\"][DBQueryKey][\"findMany\"]>[0];\n\n\tconst builder: {\n\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t} = {} as any;\n\n\tconst registeredConditions: {\n\t\t[key in DBQueryKey]: {\n\t\t\t[key in Action[number]]: (\n\t\t\t\t| QueryConditionObject\n\t\t\t\t| ((context: UserContext) => QueryConditionObject)\n\t\t\t)[];\n\t\t\t// | ((context: UserContext) => Promise<QueryConditionObject>)\n\t\t};\n\t} = {} as any;\n\n\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\tallow: (action: Action | Action[]) => {\n\t\t\tlet conditionsPerEntity = registeredConditions[entityKey];\n\t\t\tif (!conditionsPerEntity) {\n\t\t\t\tconditionsPerEntity = {} as any;\n\t\t\t\tregisteredConditions[entityKey] = conditionsPerEntity;\n\t\t\t}\n\n\t\t\tconst actions = Array.isArray(action) ? action : [action];\n\t\t\tfor (const action of actions) {\n\t\t\t\tlet conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\tconditionsPerEntityAndAction = [];\n\t\t\t\t\tconditionsPerEntity[action] = conditionsPerEntityAndAction;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\twhen: (condition: Condition<DBParameters, UserContext>) => {\n\t\t\t\t\tfor (const action of actions) {\n\t\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\t\tconditionsPerEntityAndAction.push(condition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t}\n\treturn {\n\t\t...builder,\n\t\tregisteredConditions,\n\t\tbuildWithUserContext: (userContext: UserContext) => {\n\t\t\tconst builder: {\n\t\t\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t\t\t} = {} as any;\n\n\t\t\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\t\t\tfilter: (action: Action) => {\n\t\t\t\t\tconst conditionsPerEntity = registeredConditions[entityKey];\n\t\t\t\t\tif (!conditionsPerEntity) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #1\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #2\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst simpleConditions =\n\t\t\t\t\t\tconditionsPerEntityAndAction.filter(isSimpleCondition);\n\n\t\t\t\t\tconst syncFunctionConditions = conditionsPerEntityAndAction\n\t\t\t\t\t\t.filter(isSyncFunctionCondition)\n\t\t\t\t\t\t.map((condition) => condition(userContext));\n\n\t\t\t\t\t// const asyncFunctionConditions = await Promise.all(\n\t\t\t\t\t// \tconditionsPerEntityAndAction\n\t\t\t\t\t// \t\t.filter(isAsyncFunctionCondition)\n\t\t\t\t\t// \t\t.map((condition) => condition(userContext)),\n\t\t\t\t\t// );\n\n\t\t\t\t\tconst allConditionObjects = [\n\t\t\t\t\t\t...simpleConditions,\n\t\t\t\t\t\t...syncFunctionConditions,\n\t\t\t\t\t\t// ...asyncFunctionConditions,\n\t\t\t\t\t];\n\n\t\t\t\t\tlet highestLimit = undefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.limit) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\thighestLimit === undefined ||\n\t\t\t\t\t\t\t\tconditionObject.limit > highestLimit\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\thighestLimit = conditionObject.limit;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet combinedAllowedColumns: Record<string, any> | undefined =\n\t\t\t\t\t\tundefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.columns) {\n\t\t\t\t\t\t\tif (combinedAllowedColumns === undefined) {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = conditionObject.columns;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = {\n\t\t\t\t\t\t\t\t\t...combinedAllowedColumns,\n\t\t\t\t\t\t\t\t\t...conditionObject.columns,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accumulatedWhereConditions = allConditionObjects\n\t\t\t\t\t\t.filter((o) => o.where)\n\t\t\t\t\t\t.map((o) => o.where);\n\n\t\t\t\t\tconst combinedWhere =\n\t\t\t\t\t\taccumulatedWhereConditions.length > 0\n\t\t\t\t\t\t\t? or(...accumulatedWhereConditions)\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twhere: combinedWhere,\n\t\t\t\t\t\tcolumns: combinedAllowedColumns,\n\t\t\t\t\t\tlimit: highestLimit,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\t\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t\t\t}\n\n\t\t\treturn builder;\n\t\t},\n\t};\n};\n","export class RumbleError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RumbleError\";\n\t}\n}\n","import SchemaBuilder, { FieldRef } from \"@pothos/core\";\nimport DrizzlePlugin from \"@pothos/plugin-drizzle\";\nimport { type YogaServerOptions, createYoga } from \"graphql-yoga\";\nimport { createAbilityBuilder } from \"../abilities/builder\";\nimport { RumbleError } from \"../helpers/rumbleError\";\nimport type { GenericDrizzleDbTypeConstraints } from \"../types/genericDrizzleDbType\";\n\nexport const rumble = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tRequestEvent extends Record<string, any>,\n\tAction extends string = \"create\" | \"read\" | \"update\" | \"delete\",\n>({\n\tdb,\n\tnativeServerOptions,\n\tcontext: makeUserContext,\n\tonlyQuery = false,\n\tactions = [\"create\", \"read\", \"update\", \"delete\"] as Action[],\n}: {\n\t/**\n\t * Your drizzle database instance\n\t */\n\tdb: DB;\n\t/**\n\t * Optional options for the native GraphQL Yoga server\n\t */\n\tnativeServerOptions?:\n\t\t| Omit<YogaServerOptions<RequestEvent, any>, \"schema\" | \"context\">\n\t\t| undefined;\n\t/**\n\t * A function for providing context for each request based on the incoming HTTP Request.\n\t * The type of the parameter equals the HTTPRequest type of your chosen server.\n\t */\n\tcontext?:\n\t\t| ((event: RequestEvent) => Promise<UserContext> | UserContext)\n\t\t| undefined;\n\t/**\n\t * If you only want to create queries and do not need mutations, enable this\n\t */\n\tonlyQuery?: boolean;\n\t/**\n\t * The actions that are available\n\t */\n\tactions?: Action[];\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\tconst abilityBuilder = createAbilityBuilder<UserContext, DB, Action>({\n\t\tdb,\n\t});\n\n\tconst makeContext = async (req: RequestEvent) => {\n\t\tconst userContext = makeUserContext\n\t\t\t? await makeUserContext(req)\n\t\t\t: ({} as UserContext);\n\t\treturn {\n\t\t\t...userContext,\n\t\t\tabilities: abilityBuilder.buildWithUserContext(userContext),\n\t\t};\n\t};\n\n\tconst nativeBuilder = new SchemaBuilder<{\n\t\tContext: Awaited<ReturnType<typeof makeContext>>;\n\t\t// Scalars: Scalars<Prisma.Decimal, Prisma.InputJsonValue | null, Prisma.InputJsonValue> & {\n\t\t// \tFile: {\n\t\t// \t\tInput: File;\n\t\t// \t\tOutput: never;\n\t\t// \t};\n\t\t// \tJSONObject: {\n\t\t// \t\tInput: any;\n\t\t// \t\tOutput: any;\n\t\t// \t};\n\t\t// };\n\t\tDrizzleSchema: DB[\"_\"][\"fullSchema\"];\n\t\tDefaultFieldNullability: false;\n\t\tDefaultArgumentNullability: false;\n\t\tDefaultInputFieldRequiredness: true;\n\t}>({\n\t\tplugins: [DrizzlePlugin],\n\t\tdrizzle: {\n\t\t\tclient: db,\n\t\t},\n\t\tdefaultFieldNullability: false,\n\t\tdefaultInputFieldRequiredness: true,\n\t});\n\n\tnativeBuilder.queryType({});\n\n\tif (!onlyQuery) {\n\t\tnativeBuilder.mutationType({});\n\t}\n\n\tconst implementDefaultObject = <\n\t\tExplicitTableName extends DBQueryKey,\n\t\tRefName extends string,\n\t>({\n\t\ttableName,\n\t\tname,\n\t\treadAction = \"read\" as Action,\n\t}: {\n\t\ttableName: ExplicitTableName;\n\t\tname: RefName;\n\t\treadAction?: Action;\n\t}) => {\n\t\tconst schema = db._.schema![tableName as any];\n\t\treturn nativeBuilder.drizzleObject(tableName as any, {\n\t\t\tname,\n\t\t\tfields: (t) => {\n\t\t\t\tconst mapSQLTypeStringToExposedPothosType = (\n\t\t\t\t\tsqlType: string,\n\t\t\t\t\tcolumnName: string,\n\t\t\t\t) => {\n\t\t\t\t\tswitch (sqlType) {\n\t\t\t\t\t\tcase \"serial\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"int\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"boolean\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeBoolean(columnName);\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new RumbleError(\n\t\t\t\t\t\t\t\t`Unknown SQL type: ${sqlType}. Please open an issue so it can be added.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tconst fields = Object.entries(schema.columns).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = mapSQLTypeStringToExposedPothosType(\n\t\t\t\t\t\t\tvalue.getSQLType(),\n\t\t\t\t\t\t\tvalue.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\tconst relations = Object.entries(schema.relations).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = t.relation(key, {\n\t\t\t\t\t\t\tquery: (_args: any, ctx: any) =>\n\t\t\t\t\t\t\t\tctx.abilities[tableName as any].filter(readAction),\n\t\t\t\t\t\t} as any) as any;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\t...fields,\n\t\t\t\t\t...relations,\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t};\n\n\treturn {\n\t\t/**\n * The ability builder. Use it to declare whats allowed for each entity in your DB.\n * \n * @example\n * \n * ```ts\n * // users can edit themselves\n abilityBuilder.users\n .allow([\"read\", \"update\", \"delete\"])\n .when(({ userId }) => ({ where: eq(schema.users.id, userId) }));\n \n // everyone can read posts\n abilityBuilder.posts.allow(\"read\");\n * \n * ```\n */\n\t\tabilityBuilder,\n\t\t/**\n\t\t * The pothos schema builder. See https://pothos-graphql.dev/docs/plugins/drizzle\n\t\t */\n\t\tschemaBuilder: nativeBuilder,\n\t\t/**\n * The native yoga instance. Can be used to run an actual HTTP server.\n * \n * @example\n * \n * ```ts\n import { createServer } from \"node:http\";\n * const server = createServer(yoga());\n server.listen(3000, () => {\n console.log(\"Visit http://localhost:3000/graphql\");\n });\n * ```\n */\n\t\tyoga: () =>\n\t\t\tcreateYoga<RequestEvent>({\n\t\t\t\t...nativeServerOptions,\n\t\t\t\tschema: nativeBuilder.toSchema(),\n\t\t\t\tcontext: makeContext,\n\t\t\t}),\n\t\t/**\n\t\t * A function for creating default objects for your schema\n\t\t */\n\t\timplementDefaultObject,\n\t};\n};\n","import { RumbleError } from \"./rumbleError\";\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n * schemaBuilder.queryFields((t) => {\n return {\n findFirstUser: t.drizzleField({\n type: UserRef,\n resolve: (query, root, args, ctx, info) => {\n return (\n db.query.users\n .findFirst({\n ...query,\n where: ctx.abilities.users.filter(\"read\").where,\n })\n // note that we need to manually raise an error if the value is not found\n .then(assertFindFirstExists)\n );\n },\n }),\n };\n });\n * ```\n */\nexport const assertFindFirstExists = <T>(value: T | undefined): T => {\n\tif (!value) throw new RumbleError(\"Value not found but required (findFirst)\");\n\treturn value;\n};\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n schemaBuilder.mutationFields((t) => {\n return {\n updateUsername: t.drizzleField({\n type: UserRef,\n args: {\n userId: t.arg.int({ required: true }),\n newName: t.arg.string({ required: true }),\n },\n resolve: (query, root, args, ctx, info) => {\n return db\n .update(schema.users)\n .set({\n name: args.newName,\n })\n .where(\n and(\n eq(schema.users.id, args.userId),\n ctx.abilities.users.filter(\"update\").where\n )\n )\n .returning({ id: schema.users.id, name: schema.users.name })\n // note that we need to manually raise an error if the value is not found\n .then(assertFirstEntryExists);\n },\n }),\n };\n });\n * ```\n */\nexport const assertFirstEntryExists = <T>(value: T[]): T => {\n\tconst v = value.at(0);\n\tif (!v) throw new RumbleError(\"Value not found but required (firstEntry)\");\n\treturn v;\n};\n"]}
|
package/index.d.cts
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
+
import { SchemaTypes, ObjectRef, abstractReturnShapeKey } from '@pothos/core';
|
2
|
+
import { WithBrand } from './types.js';
|
1
3
|
import * as graphql_yoga from 'graphql-yoga';
|
2
4
|
import { YogaServerOptions } from 'graphql-yoga';
|
3
5
|
import * as drizzle_orm from 'drizzle-orm';
|
4
6
|
import { DrizzleClient } from '@pothos/plugin-drizzle';
|
5
7
|
|
8
|
+
declare const drizzleTableKey: unique symbol;
|
9
|
+
declare class DrizzleObjectRef<Types extends SchemaTypes, Table extends keyof Types["DrizzleRelationSchema"] = keyof Types["DrizzleRelationSchema"], T = {}> extends ObjectRef<Types, T> {
|
10
|
+
[drizzleTableKey]: Types["DrizzleRelationSchema"][Table];
|
11
|
+
[abstractReturnShapeKey]: WithBrand<T>;
|
12
|
+
tableName: string;
|
13
|
+
constructor(name: string, tableName: string);
|
14
|
+
addBrand<V extends T | T[]>(value: V): V extends T[] ? {
|
15
|
+
[K in keyof V]: WithBrand<V[K]>;
|
16
|
+
} : WithBrand<V>;
|
17
|
+
hasBrand(value: unknown): boolean;
|
18
|
+
}
|
19
|
+
|
6
20
|
type QueryConditionObject = {
|
7
21
|
where: any;
|
8
22
|
columns: any;
|
@@ -108,7 +122,21 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
108
122
|
tableName: ExplicitTableName;
|
109
123
|
name: RefName;
|
110
124
|
readAction?: Action;
|
111
|
-
}) =>
|
125
|
+
}) => DrizzleObjectRef<PothosSchemaTypes.ExtendDefaultTypes<{
|
126
|
+
Context: Awaited<ReturnType<(req: RequestEvent) => Promise<UserContext & {
|
127
|
+
abilities: keyof DB["query"] extends infer T_2 extends keyof DB["query"] ? { [key_3 in T_2]: {
|
128
|
+
filter: (action: Action) => {
|
129
|
+
where: drizzle_orm.SQL<unknown> | undefined;
|
130
|
+
columns: Record<string, any> | undefined;
|
131
|
+
limit: any;
|
132
|
+
};
|
133
|
+
}; } : never;
|
134
|
+
}>>>;
|
135
|
+
DrizzleSchema: DB["_"]["fullSchema"];
|
136
|
+
DefaultFieldNullability: false;
|
137
|
+
DefaultArgumentNullability: false;
|
138
|
+
DefaultInputFieldRequiredness: true;
|
139
|
+
}>, any, ({ [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; } | undefined extends Record<string, unknown> ? { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; } extends infer T_5 ? { [K_2 in keyof T_5]: { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; }[K_2]; } : never : { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; } extends infer T_6 ? { [K_5 in keyof T_6]: { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; }[K_5]; } : never) & {} & ({ [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; } | undefined extends Record<string, unknown> ? drizzle_orm.BuildRelationResult<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, Record<string, unknown> & { [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; }, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]> : {}) extends infer T_2 ? { [K in keyof T_2]: (({ [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; } | undefined extends Record<string, unknown> ? { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; } extends infer T_3 ? { [K_2 in keyof T_3]: { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; }[K_2]; } : never : { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; } extends infer T_4 ? { [K_5 in keyof T_4]: { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; }[K_5]; } : never) & {} & ({ [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; } | undefined extends Record<string, unknown> ? drizzle_orm.BuildRelationResult<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, Record<string, unknown> & { [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; }, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]> : {}))[K]; } : never>;
|
112
140
|
};
|
113
141
|
|
114
142
|
/**
|
package/index.d.ts
CHANGED
@@ -1,8 +1,22 @@
|
|
1
|
+
import { SchemaTypes, ObjectRef, abstractReturnShapeKey } from '@pothos/core';
|
2
|
+
import { WithBrand } from './types.js';
|
1
3
|
import * as graphql_yoga from 'graphql-yoga';
|
2
4
|
import { YogaServerOptions } from 'graphql-yoga';
|
3
5
|
import * as drizzle_orm from 'drizzle-orm';
|
4
6
|
import { DrizzleClient } from '@pothos/plugin-drizzle';
|
5
7
|
|
8
|
+
declare const drizzleTableKey: unique symbol;
|
9
|
+
declare class DrizzleObjectRef<Types extends SchemaTypes, Table extends keyof Types["DrizzleRelationSchema"] = keyof Types["DrizzleRelationSchema"], T = {}> extends ObjectRef<Types, T> {
|
10
|
+
[drizzleTableKey]: Types["DrizzleRelationSchema"][Table];
|
11
|
+
[abstractReturnShapeKey]: WithBrand<T>;
|
12
|
+
tableName: string;
|
13
|
+
constructor(name: string, tableName: string);
|
14
|
+
addBrand<V extends T | T[]>(value: V): V extends T[] ? {
|
15
|
+
[K in keyof V]: WithBrand<V[K]>;
|
16
|
+
} : WithBrand<V>;
|
17
|
+
hasBrand(value: unknown): boolean;
|
18
|
+
}
|
19
|
+
|
6
20
|
type QueryConditionObject = {
|
7
21
|
where: any;
|
8
22
|
columns: any;
|
@@ -108,7 +122,21 @@ declare const rumble: <UserContext extends Record<string, any>, DB extends Gener
|
|
108
122
|
tableName: ExplicitTableName;
|
109
123
|
name: RefName;
|
110
124
|
readAction?: Action;
|
111
|
-
}) =>
|
125
|
+
}) => DrizzleObjectRef<PothosSchemaTypes.ExtendDefaultTypes<{
|
126
|
+
Context: Awaited<ReturnType<(req: RequestEvent) => Promise<UserContext & {
|
127
|
+
abilities: keyof DB["query"] extends infer T_2 extends keyof DB["query"] ? { [key_3 in T_2]: {
|
128
|
+
filter: (action: Action) => {
|
129
|
+
where: drizzle_orm.SQL<unknown> | undefined;
|
130
|
+
columns: Record<string, any> | undefined;
|
131
|
+
limit: any;
|
132
|
+
};
|
133
|
+
}; } : never;
|
134
|
+
}>>>;
|
135
|
+
DrizzleSchema: DB["_"]["fullSchema"];
|
136
|
+
DefaultFieldNullability: false;
|
137
|
+
DefaultArgumentNullability: false;
|
138
|
+
DefaultInputFieldRequiredness: true;
|
139
|
+
}>, any, ({ [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; } | undefined extends Record<string, unknown> ? { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; } extends infer T_5 ? { [K_2 in keyof T_5]: { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; }[K_2]; } : never : { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; } extends infer T_6 ? { [K_5 in keyof T_6]: { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; }[K_5]; } : never) & {} & ({ [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; } | undefined extends Record<string, unknown> ? drizzle_orm.BuildRelationResult<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, Record<string, unknown> & { [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; }, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]> : {}) extends infer T_2 ? { [K in keyof T_2]: (({ [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; } | undefined extends Record<string, unknown> ? { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; } extends infer T_3 ? { [K_2 in keyof T_3]: { [Key in (drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]) & string as Key]: { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["notNull"] extends true ? { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] : { [K_4 in drizzle_orm.Equal<Exclude<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] | (string & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"])], undefined>, false> extends true ? Exclude<keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"], drizzle_orm.NonUndefinedKeysOnly<Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; }>> : { [K_3 in keyof (Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })]: drizzle_orm.Equal<(Record<string, unknown> & { [K_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]?: boolean | undefined; })[K_3], true> extends true ? K_3 : never; }[string | keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]] & keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"]]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][K_4]; }[Key]["_"]["data"] | null; }[K_2]; } : never : { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; } extends infer T_4 ? { [K_5 in keyof T_4]: { [Key_1 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"] & string as Key_1]: drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["notNull"] extends true ? drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] : drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["columns"][Key_1]["_"]["data"] | null; }[K_5]; } : never) & {} & ({ [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; } | undefined extends Record<string, unknown> ? drizzle_orm.BuildRelationResult<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, Record<string, unknown> & { [K_6 in keyof drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]]?: true | drizzle_orm.DBQueryConfig<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6] extends drizzle_orm.One<string, boolean> ? "one" : "many", false, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.FindTableByDBName<drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"][K_6]["referencedTableName"]>> | undefined; }, drizzle_orm.ExtractTablesWithRelations<DB["_"]["fullSchema"] & {}>[any]["relations"]> : {}))[K]; } : never>;
|
112
140
|
};
|
113
141
|
|
114
142
|
/**
|
package/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../lib/abilities/builder.ts","../lib/helpers/rumbleError.ts","../lib/gql/builder.ts","../lib/helpers/helper.ts"],"names":["isSimpleCondition","condition","isSyncFunctionCondition","createAbilityBuilder","db","builder","registeredConditions","createEntityObject","entityKey","action","conditionsPerEntity","actions","conditionsPerEntityAndAction","userContext","simpleConditions","syncFunctionConditions","allConditionObjects","highestLimit","conditionObject","combinedAllowedColumns","accumulatedWhereConditions","o","or","RumbleError","message","rumble","nativeServerOptions","makeUserContext","onlyQuery","abilityBuilder","makeContext","req","nativeBuilder","SchemaBuilder","DrizzlePlugin","createYoga","tableName","name","readAction","schema","t","mapSQLTypeStringToExposedPothosType","sqlType","columnName","fields","acc","key","value","relations","_args","ctx","assertFindFirstExists","assertFirstEntryExists","v"],"mappings":"qIAwBA,SAASA,CACRC,CAAAA,CAAAA,CAC6C,CAC7C,OAAO,OAAOA,CAAAA,EAAc,UAC7B,CAEA,SAASC,CACRD,CAAAA,CAAAA,CACgE,CAChE,OACC,OAAOA,CAAc,EAAA,UAAA,EACrBA,CAAU,CAAA,WAAA,CAAY,OAAS,eAEjC,CAWO,IAAME,CAAAA,CAAuB,CAIlC,CACD,EAAAC,CAAAA,CACD,IAEM,CAIL,IAAMC,CAEF,CAAA,EAEEC,CAAAA,CAAAA,CAQF,EAAC,CAECC,EAAsBC,CAA2B,GAAA,CACtD,KAAQC,CAAAA,CAAAA,EAA8B,CACrC,IAAIC,CAAsBJ,CAAAA,CAAAA,CAAqBE,CAAS,CACnDE,CAAAA,CAAAA,GACJA,CAAsB,CAAA,GACtBJ,CAAqBE,CAAAA,CAAS,CAAIE,CAAAA,CAAAA,CAAAA,CAGnC,IAAMC,CAAU,CAAA,KAAA,CAAM,OAAQF,CAAAA,CAAM,CAAIA,CAAAA,CAAAA,CAAS,CAACA,CAAM,EACxD,IAAWA,IAAAA,CAAAA,IAAUE,CAAS,CAAA,CAC7B,IAAIC,CAAAA,CAA+BF,CAAoBD,CAAAA,CAAM,EACxDG,CACJA,GAAAA,CAAAA,CAA+B,EAAC,CAChCF,CAAoBD,CAAAA,CAAM,CAAIG,CAAAA,CAAAA,EAEhC,CAEA,OAAO,CACN,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AO8B,CACR","file":"index.js","sourcesContent":["import { SQL, or } from \"drizzle-orm\";\nimport type { ExcludeFromUnionIfNotOnlyType } from \"../helpers/unionTypeExclude\";\nimport type { ExcludeFirst } from \"../helpers/unionTypeExtractor\";\nimport type {\n\tGenericDrizzleDbTypeConstraints,\n\tQueryConditionObject,\n} from \"../types/genericDrizzleDbType\";\n\nexport type AbilityBuilder = ReturnType<typeof createAbilityBuilder>;\n\ntype Condition<DBParameters, UserContext> =\n\t| SimpleCondition<DBParameters>\n\t| SyncFunctionCondition<DBParameters, UserContext>;\n// | AsyncFunctionCondition<DBParameters, UserContext>;\n\ntype SimpleCondition<DBParameters> = DBParameters;\ntype SyncFunctionCondition<DBParameters, UserContext> = (\n\tcontext: UserContext,\n) => DBParameters;\n// type AsyncFunctionCondition<DBParameters, UserContext> = (\n// \tcontext: UserContext,\n// ) => Promise<DBParameters>;\n\n// type guards for the condition types\nfunction isSimpleCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SimpleCondition<DBParameters> {\n\treturn typeof condition !== \"function\";\n}\n\nfunction isSyncFunctionCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SyncFunctionCondition<DBParameters, UserContext> {\n\treturn (\n\t\ttypeof condition === \"function\" &&\n\t\tcondition.constructor.name !== \"AsyncFunction\"\n\t);\n}\n\n// function isAsyncFunctionCondition<DBParameters, UserContext>(\n// \tcondition: Condition<DBParameters, UserContext>,\n// ): condition is AsyncFunctionCondition<DBParameters, UserContext> {\n// \treturn (\n// \t\ttypeof condition === \"function\" &&\n// \t\tcondition.constructor.name === \"AsyncFunction\"\n// \t);\n// }\n\nexport const createAbilityBuilder = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tAction extends string,\n>({\n\tdb,\n}: {\n\tdb: DB;\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\ttype DBParameters = Parameters<DB[\"query\"][DBQueryKey][\"findMany\"]>[0];\n\n\tconst builder: {\n\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t} = {} as any;\n\n\tconst registeredConditions: {\n\t\t[key in DBQueryKey]: {\n\t\t\t[key in Action[number]]: (\n\t\t\t\t| QueryConditionObject\n\t\t\t\t| ((context: UserContext) => QueryConditionObject)\n\t\t\t)[];\n\t\t\t// | ((context: UserContext) => Promise<QueryConditionObject>)\n\t\t};\n\t} = {} as any;\n\n\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\tallow: (action: Action | Action[]) => {\n\t\t\tlet conditionsPerEntity = registeredConditions[entityKey];\n\t\t\tif (!conditionsPerEntity) {\n\t\t\t\tconditionsPerEntity = {} as any;\n\t\t\t\tregisteredConditions[entityKey] = conditionsPerEntity;\n\t\t\t}\n\n\t\t\tconst actions = Array.isArray(action) ? action : [action];\n\t\t\tfor (const action of actions) {\n\t\t\t\tlet conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\tconditionsPerEntityAndAction = [];\n\t\t\t\t\tconditionsPerEntity[action] = conditionsPerEntityAndAction;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\twhen: (condition: Condition<DBParameters, UserContext>) => {\n\t\t\t\t\tfor (const action of actions) {\n\t\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\t\tconditionsPerEntityAndAction.push(condition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t}\n\treturn {\n\t\t...builder,\n\t\tregisteredConditions,\n\t\tbuildWithUserContext: (userContext: UserContext) => {\n\t\t\tconst builder: {\n\t\t\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t\t\t} = {} as any;\n\n\t\t\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\t\t\tfilter: (action: Action) => {\n\t\t\t\t\tconst conditionsPerEntity = registeredConditions[entityKey];\n\t\t\t\t\tif (!conditionsPerEntity) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #1\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #2\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst simpleConditions =\n\t\t\t\t\t\tconditionsPerEntityAndAction.filter(isSimpleCondition);\n\n\t\t\t\t\tconst syncFunctionConditions = conditionsPerEntityAndAction\n\t\t\t\t\t\t.filter(isSyncFunctionCondition)\n\t\t\t\t\t\t.map((condition) => condition(userContext));\n\n\t\t\t\t\t// const asyncFunctionConditions = await Promise.all(\n\t\t\t\t\t// \tconditionsPerEntityAndAction\n\t\t\t\t\t// \t\t.filter(isAsyncFunctionCondition)\n\t\t\t\t\t// \t\t.map((condition) => condition(userContext)),\n\t\t\t\t\t// );\n\n\t\t\t\t\tconst allConditionObjects = [\n\t\t\t\t\t\t...simpleConditions,\n\t\t\t\t\t\t...syncFunctionConditions,\n\t\t\t\t\t\t// ...asyncFunctionConditions,\n\t\t\t\t\t];\n\n\t\t\t\t\tlet highestLimit = undefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.limit) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\thighestLimit === undefined ||\n\t\t\t\t\t\t\t\tconditionObject.limit > highestLimit\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\thighestLimit = conditionObject.limit;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet combinedAllowedColumns: Record<string, any> | undefined =\n\t\t\t\t\t\tundefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.columns) {\n\t\t\t\t\t\t\tif (combinedAllowedColumns === undefined) {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = conditionObject.columns;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = {\n\t\t\t\t\t\t\t\t\t...combinedAllowedColumns,\n\t\t\t\t\t\t\t\t\t...conditionObject.columns,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accumulatedWhereConditions = allConditionObjects\n\t\t\t\t\t\t.filter((o) => o.where)\n\t\t\t\t\t\t.map((o) => o.where);\n\n\t\t\t\t\tconst combinedWhere =\n\t\t\t\t\t\taccumulatedWhereConditions.length > 0\n\t\t\t\t\t\t\t? or(...accumulatedWhereConditions)\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twhere: combinedWhere,\n\t\t\t\t\t\tcolumns: combinedAllowedColumns,\n\t\t\t\t\t\tlimit: highestLimit,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\t\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t\t\t}\n\n\t\t\treturn builder;\n\t\t},\n\t};\n};\n","export class RumbleError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RumbleError\";\n\t}\n}\n","import SchemaBuilder, { FieldRef } from \"@pothos/core\";\nimport DrizzlePlugin from \"@pothos/plugin-drizzle\";\nimport { type YogaServerOptions, createYoga } from \"graphql-yoga\";\nimport { createAbilityBuilder } from \"../abilities/builder\";\nimport { RumbleError } from \"../helpers/rumbleError\";\nimport type { GenericDrizzleDbTypeConstraints } from \"../types/genericDrizzleDbType\";\n\nexport const rumble = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tRequestEvent extends Record<string, any>,\n\tAction extends string = \"create\" | \"read\" | \"update\" | \"delete\",\n>({\n\tdb,\n\tnativeServerOptions,\n\tcontext: makeUserContext,\n\tonlyQuery = false,\n\tactions = [\"create\", \"read\", \"update\", \"delete\"] as Action[],\n}: {\n\t/**\n\t * Your drizzle database instance\n\t */\n\tdb: DB;\n\t/**\n\t * Optional options for the native GraphQL Yoga server\n\t */\n\tnativeServerOptions?:\n\t\t| Omit<YogaServerOptions<RequestEvent, any>, \"schema\" | \"context\">\n\t\t| undefined;\n\t/**\n\t * A function for providing context for each request based on the incoming HTTP Request.\n\t * The type of the parameter equals the HTTPRequest type of your chosen server.\n\t */\n\tcontext?:\n\t\t| ((event: RequestEvent) => Promise<UserContext> | UserContext)\n\t\t| undefined;\n\t/**\n\t * If you only want to create queries and do not need mutations, enable this\n\t */\n\tonlyQuery?: boolean;\n\t/**\n\t * The actions that are available\n\t */\n\tactions?: Action[];\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\tconst abilityBuilder = createAbilityBuilder<UserContext, DB, Action>({\n\t\tdb,\n\t});\n\n\tconst makeContext = async (req: RequestEvent) => {\n\t\tconst userContext = makeUserContext\n\t\t\t? await makeUserContext(req)\n\t\t\t: ({} as UserContext);\n\t\treturn {\n\t\t\t...userContext,\n\t\t\tabilities: abilityBuilder.buildWithUserContext(userContext),\n\t\t};\n\t};\n\n\tconst nativeBuilder = new SchemaBuilder<{\n\t\tContext: Awaited<ReturnType<typeof makeContext>>;\n\t\t// Scalars: Scalars<Prisma.Decimal, Prisma.InputJsonValue | null, Prisma.InputJsonValue> & {\n\t\t// \tFile: {\n\t\t// \t\tInput: File;\n\t\t// \t\tOutput: never;\n\t\t// \t};\n\t\t// \tJSONObject: {\n\t\t// \t\tInput: any;\n\t\t// \t\tOutput: any;\n\t\t// \t};\n\t\t// };\n\t\tDrizzleSchema: DB[\"_\"][\"fullSchema\"];\n\t\tDefaultFieldNullability: false;\n\t\tDefaultArgumentNullability: false;\n\t\tDefaultInputFieldRequiredness: true;\n\t}>({\n\t\tplugins: [DrizzlePlugin],\n\t\tdrizzle: {\n\t\t\tclient: db,\n\t\t},\n\t\tdefaultFieldNullability: false,\n\t\tdefaultInputFieldRequiredness: true,\n\t});\n\n\tnativeBuilder.queryType({});\n\n\tif (!onlyQuery) {\n\t\tnativeBuilder.mutationType({});\n\t}\n\n\tconst implementDefaultObject = <\n\t\tExplicitTableName extends DBQueryKey,\n\t\tRefName extends string,\n\t>({\n\t\ttableName,\n\t\tname,\n\t\treadAction = \"read\" as Action,\n\t}: {\n\t\ttableName: ExplicitTableName;\n\t\tname: RefName;\n\t\treadAction?: Action;\n\t}) => {\n\t\tconst schema = db._.schema![tableName as any];\n\t\treturn nativeBuilder.drizzleObject(tableName as any, {\n\t\t\tname,\n\t\t\tfields: (t) => {\n\t\t\t\tconst mapSQLTypeStringToExposedPothosType = (\n\t\t\t\t\tsqlType: string,\n\t\t\t\t\tcolumnName: string,\n\t\t\t\t) => {\n\t\t\t\t\tswitch (sqlType) {\n\t\t\t\t\t\tcase \"serial\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"int\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"boolean\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeBoolean(columnName);\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new RumbleError(\n\t\t\t\t\t\t\t\t`Unknown SQL type: ${sqlType}. Please open an issue so it can be added.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tconst fields = Object.entries(schema.columns).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = mapSQLTypeStringToExposedPothosType(\n\t\t\t\t\t\t\tvalue.getSQLType(),\n\t\t\t\t\t\t\tvalue.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\tconst relations = Object.entries(schema.relations).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = t.relation(key, {\n\t\t\t\t\t\t\tquery: (_args: any, ctx: any) =>\n\t\t\t\t\t\t\t\tctx.abilities[tableName as any].filter(readAction),\n\t\t\t\t\t\t} as any) as any;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\t...fields,\n\t\t\t\t\t...relations,\n\t\t\t\t} as any;\n\t\t\t},\n\t\t}) as any;\n\t};\n\n\treturn {\n\t\t/**\n * The ability builder. Use it to declare whats allowed for each entity in your DB.\n * \n * @example\n * \n * ```ts\n * // users can edit themselves\n abilityBuilder.users\n .allow([\"read\", \"update\", \"delete\"])\n .when(({ userId }) => ({ where: eq(schema.users.id, userId) }));\n \n // everyone can read posts\n abilityBuilder.posts.allow(\"read\");\n * \n * ```\n */\n\t\tabilityBuilder,\n\t\t/**\n\t\t * The pothos schema builder. See https://pothos-graphql.dev/docs/plugins/drizzle\n\t\t */\n\t\tschemaBuilder: nativeBuilder,\n\t\t/**\n * The native yoga instance. Can be used to run an actual HTTP server.\n * \n * @example\n * \n * ```ts\n import { createServer } from \"node:http\";\n * const server = createServer(yoga());\n server.listen(3000, () => {\n console.log(\"Visit http://localhost:3000/graphql\");\n });\n * ```\n */\n\t\tyoga: () =>\n\t\t\tcreateYoga<RequestEvent>({\n\t\t\t\t...nativeServerOptions,\n\t\t\t\tschema: nativeBuilder.toSchema(),\n\t\t\t\tcontext: makeContext,\n\t\t\t}),\n\t\t/**\n\t\t * A function for creating default objects for your schema\n\t\t */\n\t\timplementDefaultObject,\n\t};\n};\n","import { RumbleError } from \"./rumbleError\";\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n * schemaBuilder.queryFields((t) => {\n return {\n findFirstUser: t.drizzleField({\n type: UserRef,\n resolve: (query, root, args, ctx, info) => {\n return (\n db.query.users\n .findFirst({\n ...query,\n where: ctx.abilities.users.filter(\"read\").where,\n })\n // note that we need to manually raise an error if the value is not found\n .then(assertFindFirstExists)\n );\n },\n }),\n };\n });\n * ```\n */\nexport const assertFindFirstExists = <T>(value: T | undefined): T => {\n\tif (!value) throw new RumbleError(\"Value not found but required (findFirst)\");\n\treturn value;\n};\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n schemaBuilder.mutationFields((t) => {\n return {\n updateUsername: t.drizzleField({\n type: UserRef,\n args: {\n userId: t.arg.int({ required: true }),\n newName: t.arg.string({ required: true }),\n },\n resolve: (query, root, args, ctx, info) => {\n return db\n .update(schema.users)\n .set({\n name: args.newName,\n })\n .where(\n and(\n eq(schema.users.id, args.userId),\n ctx.abilities.users.filter(\"update\").where\n )\n )\n .returning({ id: schema.users.id, name: schema.users.name })\n // note that we need to manually raise an error if the value is not found\n .then(assertFirstEntryExists);\n },\n }),\n };\n });\n * ```\n */\nexport const assertFirstEntryExists = <T>(value: T[]): T => {\n\tconst v = value.at(0);\n\tif (!v) throw new RumbleError(\"Value not found but required (firstEntry)\");\n\treturn v;\n};\n"]}
|
1
|
+
{"version":3,"sources":["../lib/abilities/builder.ts","../lib/helpers/rumbleError.ts","../lib/gql/builder.ts","../lib/helpers/helper.ts"],"names":["isSimpleCondition","condition","isSyncFunctionCondition","createAbilityBuilder","db","builder","registeredConditions","createEntityObject","entityKey","action","conditionsPerEntity","actions","conditionsPerEntityAndAction","userContext","simpleConditions","syncFunctionConditions","allConditionObjects","highestLimit","conditionObject","combinedAllowedColumns","accumulatedWhereConditions","o","or","RumbleError","message","rumble","nativeServerOptions","makeUserContext","onlyQuery","abilityBuilder","makeContext","req","nativeBuilder","SchemaBuilder","DrizzlePlugin","createYoga","tableName","name","readAction","schema","t","mapSQLTypeStringToExposedPothosType","sqlType","columnName","fields","acc","key","value","relations","_args","ctx","assertFindFirstExists","assertFirstEntryExists","v"],"mappings":"qIAwBA,SAASA,CACRC,CAAAA,CAAAA,CAC6C,CAC7C,OAAO,OAAOA,CAAAA,EAAc,UAC7B,CAEA,SAASC,CACRD,CAAAA,CAAAA,CACgE,CAChE,OACC,OAAOA,CAAc,EAAA,UAAA,EACrBA,CAAU,CAAA,WAAA,CAAY,OAAS,eAEjC,CAWO,IAAME,CAAAA,CAAuB,CAIlC,CACD,EAAAC,CAAAA,CACD,IAEM,CAIL,IAAMC,CAEF,CAAA,EAEEC,CAAAA,CAAAA,CAQF,EAAC,CAECC,EAAsBC,CAA2B,GAAA,CACtD,KAAQC,CAAAA,CAAAA,EAA8B,CACrC,IAAIC,CAAsBJ,CAAAA,CAAAA,CAAqBE,CAAS,CACnDE,CAAAA,CAAAA,GACJA,CAAsB,CAAA,GACtBJ,CAAqBE,CAAAA,CAAS,CAAIE,CAAAA,CAAAA,CAAAA,CAGnC,IAAMC,CAAU,CAAA,KAAA,CAAM,OAAQF,CAAAA,CAAM,CAAIA,CAAAA,CAAAA,CAAS,CAACA,CAAM,EACxD,IA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,OAAOwB,CACR,CAyCaK,CAAAA,CAAAA,CAA6BL,CAAkB,EAAA,CAC3D,IAAMM,CAAAA,CAAIN,CAAM,CAAA,EAAA,CAAG,CAAC,CACpB,CAAA,GAAI,CAACM,CAAAA,CAAG,MAAM,IAAI9B,CAAAA,CAAY,2CAA2C,CAAA,CACzE,OAAO8B,CACR","file":"index.js","sourcesContent":["import { SQL, or } from \"drizzle-orm\";\nimport type { ExcludeFromUnionIfNotOnlyType } from \"../helpers/unionTypeExclude\";\nimport type { ExcludeFirst } from \"../helpers/unionTypeExtractor\";\nimport type {\n\tGenericDrizzleDbTypeConstraints,\n\tQueryConditionObject,\n} from \"../types/genericDrizzleDbType\";\n\nexport type AbilityBuilder = ReturnType<typeof createAbilityBuilder>;\n\ntype Condition<DBParameters, UserContext> =\n\t| SimpleCondition<DBParameters>\n\t| SyncFunctionCondition<DBParameters, UserContext>;\n// | AsyncFunctionCondition<DBParameters, UserContext>;\n\ntype SimpleCondition<DBParameters> = DBParameters;\ntype SyncFunctionCondition<DBParameters, UserContext> = (\n\tcontext: UserContext,\n) => DBParameters;\n// type AsyncFunctionCondition<DBParameters, UserContext> = (\n// \tcontext: UserContext,\n// ) => Promise<DBParameters>;\n\n// type guards for the condition types\nfunction isSimpleCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SimpleCondition<DBParameters> {\n\treturn typeof condition !== \"function\";\n}\n\nfunction isSyncFunctionCondition<DBParameters, UserContext>(\n\tcondition: Condition<DBParameters, UserContext>,\n): condition is SyncFunctionCondition<DBParameters, UserContext> {\n\treturn (\n\t\ttypeof condition === \"function\" &&\n\t\tcondition.constructor.name !== \"AsyncFunction\"\n\t);\n}\n\n// function isAsyncFunctionCondition<DBParameters, UserContext>(\n// \tcondition: Condition<DBParameters, UserContext>,\n// ): condition is AsyncFunctionCondition<DBParameters, UserContext> {\n// \treturn (\n// \t\ttypeof condition === \"function\" &&\n// \t\tcondition.constructor.name === \"AsyncFunction\"\n// \t);\n// }\n\nexport const createAbilityBuilder = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tAction extends string,\n>({\n\tdb,\n}: {\n\tdb: DB;\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\ttype DBParameters = Parameters<DB[\"query\"][DBQueryKey][\"findMany\"]>[0];\n\n\tconst builder: {\n\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t} = {} as any;\n\n\tconst registeredConditions: {\n\t\t[key in DBQueryKey]: {\n\t\t\t[key in Action[number]]: (\n\t\t\t\t| QueryConditionObject\n\t\t\t\t| ((context: UserContext) => QueryConditionObject)\n\t\t\t)[];\n\t\t\t// | ((context: UserContext) => Promise<QueryConditionObject>)\n\t\t};\n\t} = {} as any;\n\n\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\tallow: (action: Action | Action[]) => {\n\t\t\tlet conditionsPerEntity = registeredConditions[entityKey];\n\t\t\tif (!conditionsPerEntity) {\n\t\t\t\tconditionsPerEntity = {} as any;\n\t\t\t\tregisteredConditions[entityKey] = conditionsPerEntity;\n\t\t\t}\n\n\t\t\tconst actions = Array.isArray(action) ? action : [action];\n\t\t\tfor (const action of actions) {\n\t\t\t\tlet conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\tconditionsPerEntityAndAction = [];\n\t\t\t\t\tconditionsPerEntity[action] = conditionsPerEntityAndAction;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\twhen: (condition: Condition<DBParameters, UserContext>) => {\n\t\t\t\t\tfor (const action of actions) {\n\t\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\t\tconditionsPerEntityAndAction.push(condition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t});\n\n\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t}\n\treturn {\n\t\t...builder,\n\t\tregisteredConditions,\n\t\tbuildWithUserContext: (userContext: UserContext) => {\n\t\t\tconst builder: {\n\t\t\t\t[key in DBQueryKey]: ReturnType<typeof createEntityObject>;\n\t\t\t} = {} as any;\n\n\t\t\tconst createEntityObject = (entityKey: DBQueryKey) => ({\n\t\t\t\tfilter: (action: Action) => {\n\t\t\t\t\tconst conditionsPerEntity = registeredConditions[entityKey];\n\t\t\t\t\tif (!conditionsPerEntity) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #1\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst conditionsPerEntityAndAction = conditionsPerEntity[action];\n\t\t\t\t\tif (!conditionsPerEntityAndAction) {\n\t\t\t\t\t\tthrow \"TODO (No allowed entry found for this condition) #2\";\n\t\t\t\t\t}\n\n\t\t\t\t\tconst simpleConditions =\n\t\t\t\t\t\tconditionsPerEntityAndAction.filter(isSimpleCondition);\n\n\t\t\t\t\tconst syncFunctionConditions = conditionsPerEntityAndAction\n\t\t\t\t\t\t.filter(isSyncFunctionCondition)\n\t\t\t\t\t\t.map((condition) => condition(userContext));\n\n\t\t\t\t\t// const asyncFunctionConditions = await Promise.all(\n\t\t\t\t\t// \tconditionsPerEntityAndAction\n\t\t\t\t\t// \t\t.filter(isAsyncFunctionCondition)\n\t\t\t\t\t// \t\t.map((condition) => condition(userContext)),\n\t\t\t\t\t// );\n\n\t\t\t\t\tconst allConditionObjects = [\n\t\t\t\t\t\t...simpleConditions,\n\t\t\t\t\t\t...syncFunctionConditions,\n\t\t\t\t\t\t// ...asyncFunctionConditions,\n\t\t\t\t\t];\n\n\t\t\t\t\tlet highestLimit = undefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.limit) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\thighestLimit === undefined ||\n\t\t\t\t\t\t\t\tconditionObject.limit > highestLimit\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\thighestLimit = conditionObject.limit;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet combinedAllowedColumns: Record<string, any> | undefined =\n\t\t\t\t\t\tundefined;\n\t\t\t\t\tfor (const conditionObject of allConditionObjects) {\n\t\t\t\t\t\tif (conditionObject.columns) {\n\t\t\t\t\t\t\tif (combinedAllowedColumns === undefined) {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = conditionObject.columns;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcombinedAllowedColumns = {\n\t\t\t\t\t\t\t\t\t...combinedAllowedColumns,\n\t\t\t\t\t\t\t\t\t...conditionObject.columns,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst accumulatedWhereConditions = allConditionObjects\n\t\t\t\t\t\t.filter((o) => o.where)\n\t\t\t\t\t\t.map((o) => o.where);\n\n\t\t\t\t\tconst combinedWhere =\n\t\t\t\t\t\taccumulatedWhereConditions.length > 0\n\t\t\t\t\t\t\t? or(...accumulatedWhereConditions)\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\twhere: combinedWhere,\n\t\t\t\t\t\tcolumns: combinedAllowedColumns,\n\t\t\t\t\t\tlimit: highestLimit,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor (const entityKey of Object.keys(db.query) as DBQueryKey[]) {\n\t\t\t\tbuilder[entityKey] = createEntityObject(entityKey);\n\t\t\t}\n\n\t\t\treturn builder;\n\t\t},\n\t};\n};\n","export class RumbleError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RumbleError\";\n\t}\n}\n","import SchemaBuilder, { FieldRef } from \"@pothos/core\";\nimport DrizzlePlugin from \"@pothos/plugin-drizzle\";\nimport { type YogaServerOptions, createYoga } from \"graphql-yoga\";\nimport { createAbilityBuilder } from \"../abilities/builder\";\nimport { RumbleError } from \"../helpers/rumbleError\";\nimport type { GenericDrizzleDbTypeConstraints } from \"../types/genericDrizzleDbType\";\n\nexport const rumble = <\n\tUserContext extends Record<string, any>,\n\tDB extends GenericDrizzleDbTypeConstraints,\n\tRequestEvent extends Record<string, any>,\n\tAction extends string = \"create\" | \"read\" | \"update\" | \"delete\",\n>({\n\tdb,\n\tnativeServerOptions,\n\tcontext: makeUserContext,\n\tonlyQuery = false,\n\tactions = [\"create\", \"read\", \"update\", \"delete\"] as Action[],\n}: {\n\t/**\n\t * Your drizzle database instance\n\t */\n\tdb: DB;\n\t/**\n\t * Optional options for the native GraphQL Yoga server\n\t */\n\tnativeServerOptions?:\n\t\t| Omit<YogaServerOptions<RequestEvent, any>, \"schema\" | \"context\">\n\t\t| undefined;\n\t/**\n\t * A function for providing context for each request based on the incoming HTTP Request.\n\t * The type of the parameter equals the HTTPRequest type of your chosen server.\n\t */\n\tcontext?:\n\t\t| ((event: RequestEvent) => Promise<UserContext> | UserContext)\n\t\t| undefined;\n\t/**\n\t * If you only want to create queries and do not need mutations, enable this\n\t */\n\tonlyQuery?: boolean;\n\t/**\n\t * The actions that are available\n\t */\n\tactions?: Action[];\n}) => {\n\ttype DBQueryKey = keyof DB[\"query\"];\n\tconst abilityBuilder = createAbilityBuilder<UserContext, DB, Action>({\n\t\tdb,\n\t});\n\n\tconst makeContext = async (req: RequestEvent) => {\n\t\tconst userContext = makeUserContext\n\t\t\t? await makeUserContext(req)\n\t\t\t: ({} as UserContext);\n\t\treturn {\n\t\t\t...userContext,\n\t\t\tabilities: abilityBuilder.buildWithUserContext(userContext),\n\t\t};\n\t};\n\n\tconst nativeBuilder = new SchemaBuilder<{\n\t\tContext: Awaited<ReturnType<typeof makeContext>>;\n\t\t// Scalars: Scalars<Prisma.Decimal, Prisma.InputJsonValue | null, Prisma.InputJsonValue> & {\n\t\t// \tFile: {\n\t\t// \t\tInput: File;\n\t\t// \t\tOutput: never;\n\t\t// \t};\n\t\t// \tJSONObject: {\n\t\t// \t\tInput: any;\n\t\t// \t\tOutput: any;\n\t\t// \t};\n\t\t// };\n\t\tDrizzleSchema: DB[\"_\"][\"fullSchema\"];\n\t\tDefaultFieldNullability: false;\n\t\tDefaultArgumentNullability: false;\n\t\tDefaultInputFieldRequiredness: true;\n\t}>({\n\t\tplugins: [DrizzlePlugin],\n\t\tdrizzle: {\n\t\t\tclient: db,\n\t\t},\n\t\tdefaultFieldNullability: false,\n\t\tdefaultInputFieldRequiredness: true,\n\t});\n\n\tnativeBuilder.queryType({});\n\n\tif (!onlyQuery) {\n\t\tnativeBuilder.mutationType({});\n\t}\n\n\tconst implementDefaultObject = <\n\t\tExplicitTableName extends DBQueryKey,\n\t\tRefName extends string,\n\t>({\n\t\ttableName,\n\t\tname,\n\t\treadAction = \"read\" as Action,\n\t}: {\n\t\ttableName: ExplicitTableName;\n\t\tname: RefName;\n\t\treadAction?: Action;\n\t}) => {\n\t\tconst schema = db._.schema![tableName as any];\n\t\treturn nativeBuilder.drizzleObject(tableName as any, {\n\t\t\tname,\n\t\t\tfields: (t) => {\n\t\t\t\tconst mapSQLTypeStringToExposedPothosType = (\n\t\t\t\t\tsqlType: string,\n\t\t\t\t\tcolumnName: string,\n\t\t\t\t) => {\n\t\t\t\t\tswitch (sqlType) {\n\t\t\t\t\t\tcase \"serial\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"int\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeInt(columnName);\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeString(columnName);\n\t\t\t\t\t\tcase \"boolean\":\n\t\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\t\treturn t.exposeBoolean(columnName);\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new RumbleError(\n\t\t\t\t\t\t\t\t`Unknown SQL type: ${sqlType}. Please open an issue so it can be added.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tconst fields = Object.entries(schema.columns).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = mapSQLTypeStringToExposedPothosType(\n\t\t\t\t\t\t\tvalue.getSQLType(),\n\t\t\t\t\t\t\tvalue.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\tconst relations = Object.entries(schema.relations).reduce(\n\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\tacc[key] = t.relation(key, {\n\t\t\t\t\t\t\tquery: (_args: any, ctx: any) =>\n\t\t\t\t\t\t\t\tctx.abilities[tableName as any].filter(readAction),\n\t\t\t\t\t\t} as any) as any;\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t},\n\t\t\t\t\t{} as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\tReturnType<typeof mapSQLTypeStringToExposedPothosType>\n\t\t\t\t\t>,\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\t...fields,\n\t\t\t\t\t...relations,\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t};\n\n\treturn {\n\t\t/**\n * The ability builder. Use it to declare whats allowed for each entity in your DB.\n * \n * @example\n * \n * ```ts\n * // users can edit themselves\n abilityBuilder.users\n .allow([\"read\", \"update\", \"delete\"])\n .when(({ userId }) => ({ where: eq(schema.users.id, userId) }));\n \n // everyone can read posts\n abilityBuilder.posts.allow(\"read\");\n * \n * ```\n */\n\t\tabilityBuilder,\n\t\t/**\n\t\t * The pothos schema builder. See https://pothos-graphql.dev/docs/plugins/drizzle\n\t\t */\n\t\tschemaBuilder: nativeBuilder,\n\t\t/**\n * The native yoga instance. Can be used to run an actual HTTP server.\n * \n * @example\n * \n * ```ts\n import { createServer } from \"node:http\";\n * const server = createServer(yoga());\n server.listen(3000, () => {\n console.log(\"Visit http://localhost:3000/graphql\");\n });\n * ```\n */\n\t\tyoga: () =>\n\t\t\tcreateYoga<RequestEvent>({\n\t\t\t\t...nativeServerOptions,\n\t\t\t\tschema: nativeBuilder.toSchema(),\n\t\t\t\tcontext: makeContext,\n\t\t\t}),\n\t\t/**\n\t\t * A function for creating default objects for your schema\n\t\t */\n\t\timplementDefaultObject,\n\t};\n};\n","import { RumbleError } from \"./rumbleError\";\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n * schemaBuilder.queryFields((t) => {\n return {\n findFirstUser: t.drizzleField({\n type: UserRef,\n resolve: (query, root, args, ctx, info) => {\n return (\n db.query.users\n .findFirst({\n ...query,\n where: ctx.abilities.users.filter(\"read\").where,\n })\n // note that we need to manually raise an error if the value is not found\n .then(assertFindFirstExists)\n );\n },\n }),\n };\n });\n * ```\n */\nexport const assertFindFirstExists = <T>(value: T | undefined): T => {\n\tif (!value) throw new RumbleError(\"Value not found but required (findFirst)\");\n\treturn value;\n};\n\n/**\n * \n * Helper function to map a drizzle findFirst query result,\n * which may be optional, to a correct drizzle type.\n * \n * @throws RumbleError\n * \n * @example\n * \n * ```ts\n schemaBuilder.mutationFields((t) => {\n return {\n updateUsername: t.drizzleField({\n type: UserRef,\n args: {\n userId: t.arg.int({ required: true }),\n newName: t.arg.string({ required: true }),\n },\n resolve: (query, root, args, ctx, info) => {\n return db\n .update(schema.users)\n .set({\n name: args.newName,\n })\n .where(\n and(\n eq(schema.users.id, args.userId),\n ctx.abilities.users.filter(\"update\").where\n )\n )\n .returning({ id: schema.users.id, name: schema.users.name })\n // note that we need to manually raise an error if the value is not found\n .then(assertFirstEntryExists);\n },\n }),\n };\n });\n * ```\n */\nexport const assertFirstEntryExists = <T>(value: T[]): T => {\n\tconst v = value.at(0);\n\tif (!v) throw new RumbleError(\"Value not found but required (firstEntry)\");\n\treturn v;\n};\n"]}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@m1212e/rumble","module":"index.ts","type":"module","peerDependencies":{"typescript":"^5.7.2","drizzle-orm":"^0.38.3"},"dependencies":{"@pothos/plugin-drizzle":"^0.5.3","graphql-yoga":"^5.10.8","@pothos/core":"^4.3.0"},"version":"0.0.
|
1
|
+
{"name":"@m1212e/rumble","module":"index.ts","type":"module","peerDependencies":{"typescript":"^5.7.2","drizzle-orm":"^0.38.3"},"dependencies":{"@pothos/plugin-drizzle":"^0.5.3","graphql-yoga":"^5.10.8","@pothos/core":"^4.3.0"},"version":"0.0.5","exports":{"./package.json":"./package.json",".":{"require":"./index.cjs","import":"./index.js","node":"./index.cjs","default":"./index.cjs"}}}
|