@vantreeseba/drizzle-graphql 7.6.0 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -1
- package/dist/README.md +77 -1
- package/dist/index.cjs +384 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -3
- package/dist/index.d.ts +117 -3
- package/dist/index.js +384 -91
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -251,7 +251,7 @@ declare const drizzleExecutorKey: unique symbol;
|
|
|
251
251
|
* each dialect builder states it: `'nulls-largest'` for PostgreSQL, `'nulls-smallest'` for
|
|
252
252
|
* MySQL and SQLite.
|
|
253
253
|
*/
|
|
254
|
-
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor,
|
|
254
|
+
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor, policies?: TablePolicies) => RelationResolverFactory;
|
|
255
255
|
/** {@link BuildSchemaConfig.limits} resolved for one table. `undefined` means no policy. */
|
|
256
256
|
type ResolvedLimitPolicy = {
|
|
257
257
|
defaultLimit: number | undefined;
|
|
@@ -321,6 +321,46 @@ declare const extractFilters: <TTable extends Table>(table: TTable, tableName: s
|
|
|
321
321
|
type ScopeHook<TContext = any> = (context: TContext, table: any) => SQL | Record<string, any> | undefined | null;
|
|
322
322
|
/** Build-time lookup: the scope configured for a table, if any. */
|
|
323
323
|
type ScopeFor = (tableName: string) => ScopeHook | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* One table's soft-delete convention, resolved against the real column at build time.
|
|
326
|
+
*
|
|
327
|
+
* `nullable` picks the shape of the predicate. A nullable column marks a row deleted by
|
|
328
|
+
* holding a value at all (`deletedAt IS NOT NULL`), which is the common timestamp form; a
|
|
329
|
+
* non-nullable one marks it by holding `marker` (`isDeleted = true`), so the column has to
|
|
330
|
+
* have a constant that means "deleted" and another that means "not deleted".
|
|
331
|
+
*/
|
|
332
|
+
type SoftDeleteInfo = {
|
|
333
|
+
/** Property name of the column on the drizzle table — also the key on an aliased proxy. */
|
|
334
|
+
columnName: string;
|
|
335
|
+
column: Column;
|
|
336
|
+
nullable: boolean;
|
|
337
|
+
/** Evaluated per delete, so a timestamp form stamps the moment of the delete. */
|
|
338
|
+
writeDeleted: () => any;
|
|
339
|
+
/** Written by the restore mutation. */
|
|
340
|
+
writeRestored: any;
|
|
341
|
+
/** Non-nullable form only: the constant that means "this row is deleted". */
|
|
342
|
+
marker?: any;
|
|
343
|
+
};
|
|
344
|
+
/** Build-time lookup: the soft-delete convention of a table, if it declares one. */
|
|
345
|
+
type SoftDeleteFor = (tableName: string) => SoftDeleteInfo | undefined;
|
|
346
|
+
/** Produces one column's value from the GraphQL context. See `BuildSchemaConfig.contextValues`. */
|
|
347
|
+
type ContextValueHook<TContext = any> = (context: TContext) => any;
|
|
348
|
+
/** Build-time lookup: the context-derived columns of a table, keyed by column property name. */
|
|
349
|
+
type ContextValuesFor = (tableName: string) => Record<string, ContextValueHook> | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* The two request-time policies a generated resolver applies, passed to the dialect
|
|
352
|
+
* generators as one value so a table's read scope and its server-owned columns travel
|
|
353
|
+
* together. Both stay `undefined` when nothing is configured, and every call site checks
|
|
354
|
+
* before doing any work — an unconfigured build generates exactly the SQL it did before.
|
|
355
|
+
*/
|
|
356
|
+
type TablePolicies = {
|
|
357
|
+
/** See `BuildSchemaConfig.scope`. */
|
|
358
|
+
scope?: ScopeFor;
|
|
359
|
+
/** See `BuildSchemaConfig.contextValues`. */
|
|
360
|
+
contextValues?: ContextValuesFor;
|
|
361
|
+
/** See `BuildSchemaConfig.softDelete`. */
|
|
362
|
+
softDelete?: SoftDeleteFor;
|
|
363
|
+
};
|
|
324
364
|
/**
|
|
325
365
|
* Where a dialect's default sort places NULLs relative to non-NULL values:
|
|
326
366
|
* - `nulls-largest` — PostgreSQL: NULLs sort as the largest values (last in ASC, first in DESC).
|
|
@@ -863,6 +903,31 @@ type ScopeConfig<TContext = any> = Record<string, RowScope<TContext>>;
|
|
|
863
903
|
* request context, keyed by Drizzle schema key and then by column property name.
|
|
864
904
|
*/
|
|
865
905
|
type ContextValuesConfig<TContext = any> = Record<string, Record<string, (context: TContext) => any>>;
|
|
906
|
+
/**
|
|
907
|
+
* How one table marks a row deleted: the column's property name, or that name plus the values
|
|
908
|
+
* written on delete and on restore. See {@link BuildSchemaConfig.softDelete}.
|
|
909
|
+
*/
|
|
910
|
+
type SoftDeleteColumn = string | {
|
|
911
|
+
/** Property name of the column that marks a row deleted. */
|
|
912
|
+
column: string;
|
|
913
|
+
/**
|
|
914
|
+
* Written when a row is deleted. A function is evaluated per delete. Defaults by column
|
|
915
|
+
* type: `new Date()` for a timestamp, an ISO string for text, `Date.now()` for a number,
|
|
916
|
+
* `true` for a boolean. Required, as a constant, when the column is NOT NULL and not a
|
|
917
|
+
* boolean — the predicate that hides marked rows has to compare against it.
|
|
918
|
+
*/
|
|
919
|
+
deletedValue?: any;
|
|
920
|
+
/**
|
|
921
|
+
* Written when a row is restored. Defaults to `null` for a nullable column and `false`
|
|
922
|
+
* for a NOT NULL boolean; required for any other NOT NULL column.
|
|
923
|
+
*/
|
|
924
|
+
restoredValue?: any;
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* Per-table soft-delete declarations, either keyed by Drizzle schema key or as a rule applied
|
|
928
|
+
* to every table. See {@link BuildSchemaConfig.softDelete}.
|
|
929
|
+
*/
|
|
930
|
+
type SoftDeleteConfig = Record<string, SoftDeleteColumn> | ((table: any, tableName: string) => SoftDeleteColumn | undefined | null);
|
|
866
931
|
/**
|
|
867
932
|
* {@link BuildSchemaConfig.exclude} — tables and columns to keep out of the generated schema.
|
|
868
933
|
*
|
|
@@ -921,6 +986,11 @@ type BuildSchemaConfig = {
|
|
|
921
986
|
update?: string;
|
|
922
987
|
/** Prefix for upsert mutations (e.g., 'users' -> 'upsertUsers') */
|
|
923
988
|
upsert?: string;
|
|
989
|
+
/**
|
|
990
|
+
* Prefix for the restore mutations of a soft-deleting table (e.g., 'users' ->
|
|
991
|
+
* 'restoreUsers'). Only used when {@link BuildSchemaConfig.softDelete} names the table.
|
|
992
|
+
*/
|
|
993
|
+
restore?: string;
|
|
924
994
|
};
|
|
925
995
|
/**
|
|
926
996
|
* Customizes query name suffixes for generated GraphQL operations.
|
|
@@ -1151,6 +1221,50 @@ type BuildSchemaConfig = {
|
|
|
1151
1221
|
* name), the same keying {@link BuildSchemaConfig.exclude} uses.
|
|
1152
1222
|
*/
|
|
1153
1223
|
contextValues?: ContextValuesConfig;
|
|
1224
|
+
/**
|
|
1225
|
+
* Tables that mark rows deleted instead of removing them.
|
|
1226
|
+
*
|
|
1227
|
+
* ```ts
|
|
1228
|
+
* buildSchema(db, {
|
|
1229
|
+
* softDelete: {
|
|
1230
|
+
* users: 'deletedAt', // nullable timestamp: stamped on delete
|
|
1231
|
+
* posts: { column: 'isDeleted', deletedValue: true, restoredValue: false },
|
|
1232
|
+
* },
|
|
1233
|
+
* });
|
|
1234
|
+
*
|
|
1235
|
+
* // or as a convention across the whole schema:
|
|
1236
|
+
* buildSchema(db, { softDelete: (table) => ('deletedAt' in table ? 'deletedAt' : undefined) });
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* For a table that declares one:
|
|
1240
|
+
*
|
|
1241
|
+
* - `delete<Table>` and `delete<Table>Single` issue an `UPDATE` of the marker column
|
|
1242
|
+
* instead of a `DELETE`, and return the rows as they now stand.
|
|
1243
|
+
* - `restore<Table>` and `restore<Table>Single` are generated alongside them, matching only
|
|
1244
|
+
* marked rows and writing the restored value. The prefix is configurable through
|
|
1245
|
+
* {@link BuildSchemaConfig.prefixes}.
|
|
1246
|
+
* - Every generated read hides marked rows: list and single queries, aggregates, `groupBy`,
|
|
1247
|
+
* relation fields on both the eager and the batched path, and relation aggregates. Each
|
|
1248
|
+
* of those fields takes a `deleted: EXCLUDE | INCLUDE | ONLY` argument (default
|
|
1249
|
+
* `EXCLUDE`); `ONLY` is a trash view.
|
|
1250
|
+
* - Every generated write skips them too: an `update`, a `delete`, or a nested `connect`
|
|
1251
|
+
* cannot reach a row that is already marked.
|
|
1252
|
+
* - The marker column is removed from the create and update inputs, so the only ways to set
|
|
1253
|
+
* or clear it are the delete and restore mutations.
|
|
1254
|
+
* - The predicate is ANDed on before {@link BuildSchemaConfig.scope}, and both are ANDed
|
|
1255
|
+
* after the client's `where` — a request can only ever narrow them.
|
|
1256
|
+
*
|
|
1257
|
+
* Two consequences of the pattern itself, which this does not paper over:
|
|
1258
|
+
*
|
|
1259
|
+
* - A marked row still occupies its unique keys, so inserting a row that reuses the natural
|
|
1260
|
+
* key of a deleted one still fails on the constraint.
|
|
1261
|
+
* - An upsert whose conflict target hits a marked row updates nothing on PostgreSQL and
|
|
1262
|
+
* SQLite (the conflict predicate excludes it) but revives it on MySQL, whose
|
|
1263
|
+
* `ON DUPLICATE KEY UPDATE` takes no predicate.
|
|
1264
|
+
*
|
|
1265
|
+
* Marking a parent deleted does not mark its children — a cascade is a schema decision.
|
|
1266
|
+
*/
|
|
1267
|
+
softDelete?: SoftDeleteConfig;
|
|
1154
1268
|
/**
|
|
1155
1269
|
* Tables and columns to leave out of the generated schema entirely.
|
|
1156
1270
|
*
|
|
@@ -1439,7 +1553,7 @@ type DrizzleFieldKind = 'query' | 'mutation' | 'relation' | 'aggregate' | 'type'
|
|
|
1439
1553
|
* What the field does. Arity is carried separately by `single`, so `select` covers both
|
|
1440
1554
|
* the list query and its `…Single` sibling rather than being spelled twice.
|
|
1441
1555
|
*/
|
|
1442
|
-
type DrizzleFieldOperation = 'select' | 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'aggregate' | 'groupBy' | 'relation' | 'relationAggregate';
|
|
1556
|
+
type DrizzleFieldOperation = 'select' | 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'restore' | 'aggregate' | 'groupBy' | 'relation' | 'relationAggregate';
|
|
1443
1557
|
/** The argument holding the rows a field is about, when it has one. */
|
|
1444
1558
|
type DrizzleTargetArg = 'where' | 'values' | 'updates';
|
|
1445
1559
|
/** `extensions.drizzle` on a generated field. */
|
|
@@ -1613,4 +1727,4 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
1613
1727
|
|
|
1614
1728
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1615
1729
|
|
|
1616
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
|
1730
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
package/dist/index.d.ts
CHANGED
|
@@ -251,7 +251,7 @@ declare const drizzleExecutorKey: unique symbol;
|
|
|
251
251
|
* each dialect builder states it: `'nulls-largest'` for PostgreSQL, `'nulls-smallest'` for
|
|
252
252
|
* MySQL and SQLite.
|
|
253
253
|
*/
|
|
254
|
-
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor,
|
|
254
|
+
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor, policies?: TablePolicies) => RelationResolverFactory;
|
|
255
255
|
/** {@link BuildSchemaConfig.limits} resolved for one table. `undefined` means no policy. */
|
|
256
256
|
type ResolvedLimitPolicy = {
|
|
257
257
|
defaultLimit: number | undefined;
|
|
@@ -321,6 +321,46 @@ declare const extractFilters: <TTable extends Table>(table: TTable, tableName: s
|
|
|
321
321
|
type ScopeHook<TContext = any> = (context: TContext, table: any) => SQL | Record<string, any> | undefined | null;
|
|
322
322
|
/** Build-time lookup: the scope configured for a table, if any. */
|
|
323
323
|
type ScopeFor = (tableName: string) => ScopeHook | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* One table's soft-delete convention, resolved against the real column at build time.
|
|
326
|
+
*
|
|
327
|
+
* `nullable` picks the shape of the predicate. A nullable column marks a row deleted by
|
|
328
|
+
* holding a value at all (`deletedAt IS NOT NULL`), which is the common timestamp form; a
|
|
329
|
+
* non-nullable one marks it by holding `marker` (`isDeleted = true`), so the column has to
|
|
330
|
+
* have a constant that means "deleted" and another that means "not deleted".
|
|
331
|
+
*/
|
|
332
|
+
type SoftDeleteInfo = {
|
|
333
|
+
/** Property name of the column on the drizzle table — also the key on an aliased proxy. */
|
|
334
|
+
columnName: string;
|
|
335
|
+
column: Column;
|
|
336
|
+
nullable: boolean;
|
|
337
|
+
/** Evaluated per delete, so a timestamp form stamps the moment of the delete. */
|
|
338
|
+
writeDeleted: () => any;
|
|
339
|
+
/** Written by the restore mutation. */
|
|
340
|
+
writeRestored: any;
|
|
341
|
+
/** Non-nullable form only: the constant that means "this row is deleted". */
|
|
342
|
+
marker?: any;
|
|
343
|
+
};
|
|
344
|
+
/** Build-time lookup: the soft-delete convention of a table, if it declares one. */
|
|
345
|
+
type SoftDeleteFor = (tableName: string) => SoftDeleteInfo | undefined;
|
|
346
|
+
/** Produces one column's value from the GraphQL context. See `BuildSchemaConfig.contextValues`. */
|
|
347
|
+
type ContextValueHook<TContext = any> = (context: TContext) => any;
|
|
348
|
+
/** Build-time lookup: the context-derived columns of a table, keyed by column property name. */
|
|
349
|
+
type ContextValuesFor = (tableName: string) => Record<string, ContextValueHook> | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* The two request-time policies a generated resolver applies, passed to the dialect
|
|
352
|
+
* generators as one value so a table's read scope and its server-owned columns travel
|
|
353
|
+
* together. Both stay `undefined` when nothing is configured, and every call site checks
|
|
354
|
+
* before doing any work — an unconfigured build generates exactly the SQL it did before.
|
|
355
|
+
*/
|
|
356
|
+
type TablePolicies = {
|
|
357
|
+
/** See `BuildSchemaConfig.scope`. */
|
|
358
|
+
scope?: ScopeFor;
|
|
359
|
+
/** See `BuildSchemaConfig.contextValues`. */
|
|
360
|
+
contextValues?: ContextValuesFor;
|
|
361
|
+
/** See `BuildSchemaConfig.softDelete`. */
|
|
362
|
+
softDelete?: SoftDeleteFor;
|
|
363
|
+
};
|
|
324
364
|
/**
|
|
325
365
|
* Where a dialect's default sort places NULLs relative to non-NULL values:
|
|
326
366
|
* - `nulls-largest` — PostgreSQL: NULLs sort as the largest values (last in ASC, first in DESC).
|
|
@@ -863,6 +903,31 @@ type ScopeConfig<TContext = any> = Record<string, RowScope<TContext>>;
|
|
|
863
903
|
* request context, keyed by Drizzle schema key and then by column property name.
|
|
864
904
|
*/
|
|
865
905
|
type ContextValuesConfig<TContext = any> = Record<string, Record<string, (context: TContext) => any>>;
|
|
906
|
+
/**
|
|
907
|
+
* How one table marks a row deleted: the column's property name, or that name plus the values
|
|
908
|
+
* written on delete and on restore. See {@link BuildSchemaConfig.softDelete}.
|
|
909
|
+
*/
|
|
910
|
+
type SoftDeleteColumn = string | {
|
|
911
|
+
/** Property name of the column that marks a row deleted. */
|
|
912
|
+
column: string;
|
|
913
|
+
/**
|
|
914
|
+
* Written when a row is deleted. A function is evaluated per delete. Defaults by column
|
|
915
|
+
* type: `new Date()` for a timestamp, an ISO string for text, `Date.now()` for a number,
|
|
916
|
+
* `true` for a boolean. Required, as a constant, when the column is NOT NULL and not a
|
|
917
|
+
* boolean — the predicate that hides marked rows has to compare against it.
|
|
918
|
+
*/
|
|
919
|
+
deletedValue?: any;
|
|
920
|
+
/**
|
|
921
|
+
* Written when a row is restored. Defaults to `null` for a nullable column and `false`
|
|
922
|
+
* for a NOT NULL boolean; required for any other NOT NULL column.
|
|
923
|
+
*/
|
|
924
|
+
restoredValue?: any;
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* Per-table soft-delete declarations, either keyed by Drizzle schema key or as a rule applied
|
|
928
|
+
* to every table. See {@link BuildSchemaConfig.softDelete}.
|
|
929
|
+
*/
|
|
930
|
+
type SoftDeleteConfig = Record<string, SoftDeleteColumn> | ((table: any, tableName: string) => SoftDeleteColumn | undefined | null);
|
|
866
931
|
/**
|
|
867
932
|
* {@link BuildSchemaConfig.exclude} — tables and columns to keep out of the generated schema.
|
|
868
933
|
*
|
|
@@ -921,6 +986,11 @@ type BuildSchemaConfig = {
|
|
|
921
986
|
update?: string;
|
|
922
987
|
/** Prefix for upsert mutations (e.g., 'users' -> 'upsertUsers') */
|
|
923
988
|
upsert?: string;
|
|
989
|
+
/**
|
|
990
|
+
* Prefix for the restore mutations of a soft-deleting table (e.g., 'users' ->
|
|
991
|
+
* 'restoreUsers'). Only used when {@link BuildSchemaConfig.softDelete} names the table.
|
|
992
|
+
*/
|
|
993
|
+
restore?: string;
|
|
924
994
|
};
|
|
925
995
|
/**
|
|
926
996
|
* Customizes query name suffixes for generated GraphQL operations.
|
|
@@ -1151,6 +1221,50 @@ type BuildSchemaConfig = {
|
|
|
1151
1221
|
* name), the same keying {@link BuildSchemaConfig.exclude} uses.
|
|
1152
1222
|
*/
|
|
1153
1223
|
contextValues?: ContextValuesConfig;
|
|
1224
|
+
/**
|
|
1225
|
+
* Tables that mark rows deleted instead of removing them.
|
|
1226
|
+
*
|
|
1227
|
+
* ```ts
|
|
1228
|
+
* buildSchema(db, {
|
|
1229
|
+
* softDelete: {
|
|
1230
|
+
* users: 'deletedAt', // nullable timestamp: stamped on delete
|
|
1231
|
+
* posts: { column: 'isDeleted', deletedValue: true, restoredValue: false },
|
|
1232
|
+
* },
|
|
1233
|
+
* });
|
|
1234
|
+
*
|
|
1235
|
+
* // or as a convention across the whole schema:
|
|
1236
|
+
* buildSchema(db, { softDelete: (table) => ('deletedAt' in table ? 'deletedAt' : undefined) });
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* For a table that declares one:
|
|
1240
|
+
*
|
|
1241
|
+
* - `delete<Table>` and `delete<Table>Single` issue an `UPDATE` of the marker column
|
|
1242
|
+
* instead of a `DELETE`, and return the rows as they now stand.
|
|
1243
|
+
* - `restore<Table>` and `restore<Table>Single` are generated alongside them, matching only
|
|
1244
|
+
* marked rows and writing the restored value. The prefix is configurable through
|
|
1245
|
+
* {@link BuildSchemaConfig.prefixes}.
|
|
1246
|
+
* - Every generated read hides marked rows: list and single queries, aggregates, `groupBy`,
|
|
1247
|
+
* relation fields on both the eager and the batched path, and relation aggregates. Each
|
|
1248
|
+
* of those fields takes a `deleted: EXCLUDE | INCLUDE | ONLY` argument (default
|
|
1249
|
+
* `EXCLUDE`); `ONLY` is a trash view.
|
|
1250
|
+
* - Every generated write skips them too: an `update`, a `delete`, or a nested `connect`
|
|
1251
|
+
* cannot reach a row that is already marked.
|
|
1252
|
+
* - The marker column is removed from the create and update inputs, so the only ways to set
|
|
1253
|
+
* or clear it are the delete and restore mutations.
|
|
1254
|
+
* - The predicate is ANDed on before {@link BuildSchemaConfig.scope}, and both are ANDed
|
|
1255
|
+
* after the client's `where` — a request can only ever narrow them.
|
|
1256
|
+
*
|
|
1257
|
+
* Two consequences of the pattern itself, which this does not paper over:
|
|
1258
|
+
*
|
|
1259
|
+
* - A marked row still occupies its unique keys, so inserting a row that reuses the natural
|
|
1260
|
+
* key of a deleted one still fails on the constraint.
|
|
1261
|
+
* - An upsert whose conflict target hits a marked row updates nothing on PostgreSQL and
|
|
1262
|
+
* SQLite (the conflict predicate excludes it) but revives it on MySQL, whose
|
|
1263
|
+
* `ON DUPLICATE KEY UPDATE` takes no predicate.
|
|
1264
|
+
*
|
|
1265
|
+
* Marking a parent deleted does not mark its children — a cascade is a schema decision.
|
|
1266
|
+
*/
|
|
1267
|
+
softDelete?: SoftDeleteConfig;
|
|
1154
1268
|
/**
|
|
1155
1269
|
* Tables and columns to leave out of the generated schema entirely.
|
|
1156
1270
|
*
|
|
@@ -1439,7 +1553,7 @@ type DrizzleFieldKind = 'query' | 'mutation' | 'relation' | 'aggregate' | 'type'
|
|
|
1439
1553
|
* What the field does. Arity is carried separately by `single`, so `select` covers both
|
|
1440
1554
|
* the list query and its `…Single` sibling rather than being spelled twice.
|
|
1441
1555
|
*/
|
|
1442
|
-
type DrizzleFieldOperation = 'select' | 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'aggregate' | 'groupBy' | 'relation' | 'relationAggregate';
|
|
1556
|
+
type DrizzleFieldOperation = 'select' | 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'restore' | 'aggregate' | 'groupBy' | 'relation' | 'relationAggregate';
|
|
1443
1557
|
/** The argument holding the rows a field is about, when it has one. */
|
|
1444
1558
|
type DrizzleTargetArg = 'where' | 'values' | 'updates';
|
|
1445
1559
|
/** `extensions.drizzle` on a generated field. */
|
|
@@ -1613,4 +1727,4 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
1613
1727
|
|
|
1614
1728
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1615
1729
|
|
|
1616
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
|
1730
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|