rake-db 2.34.0 → 2.35.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/dist/index.d.ts CHANGED
@@ -1,13 +1,24 @@
1
- import { Adapter, Column as Column$1, ColumnSchemaConfig, ColumnsByType, ColumnsShape, DbDomainArg, DbResult, DbStructureDomainsMap, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, EmptyObject, EnumColumn, MaybeArray, MaybePromise, NoPrimaryKeyOption, NonUniqDataItem, QueryLogObject, QueryLogOptions, QueryLogger, QuerySchema, RawSqlBase, RecordOptionalString, RecordString, SearchWeight, TableData, TableDataFn, TableDataItem, TableDataMethods, raw } from "pqb/internal";
1
+ import { Adapter, Column as Column$1, ColumnSchemaConfig, ColumnsByType, ColumnsShape, DbDomainArg, DbResult, DbStructureDomainsMap, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, EmptyObject, EnumColumn, Grant, MaybeArray, MaybePromise, NoPrimaryKeyOption, NonUniqDataItem, QueryLogObject, QueryLogOptions, QueryLogger, QuerySchema, RawSqlBase, RecordOptionalString, RecordString, RlsPolicy, SearchWeight, TableData, TableDataFn, TableDataItem, TableDataMethods, raw } from "pqb/internal";
2
2
  import { Db } from "pqb";
3
3
  declare namespace DbStructure {
4
4
  interface TableNameAndSchemaName {
5
5
  schemaName: string;
6
6
  tableName: string;
7
7
  }
8
+ type RlsPolicyMode = RlsPolicy.PolicyMode;
9
+ type RlsPolicyCommand = RlsPolicy.PolicyCommand;
10
+ interface RlsPolicy extends TableNameAndSchemaName {
11
+ name: string;
12
+ mode: RlsPolicyMode;
13
+ command: RlsPolicyCommand;
14
+ roles: string[];
15
+ using?: string;
16
+ withCheck?: string;
17
+ }
8
18
  interface TableRls {
9
19
  enable: boolean;
10
20
  force: boolean;
21
+ policies?: RlsPolicy[];
11
22
  }
12
23
  interface Table {
13
24
  schemaName: string;
@@ -180,6 +191,7 @@ declare namespace DbStructure {
180
191
  schema?: string;
181
192
  objectConfigs: DefaultPrivilegeObjectConfig[];
182
193
  }
194
+ type Grant = Grant.InternalPrivilege;
183
195
  }
184
196
  interface IntrospectedStructure {
185
197
  version: number;
@@ -196,6 +208,7 @@ interface IntrospectedStructure {
196
208
  collations: DbStructure.Collation[];
197
209
  roles?: DbStructure.Role[];
198
210
  defaultPrivileges?: DbStructure.DefaultPrivilege[];
211
+ grants?: DbStructure.Grant[];
199
212
  managedRolesSql?: string;
200
213
  }
201
214
  interface IntrospectDbStructureParams {
@@ -204,10 +217,11 @@ interface IntrospectDbStructureParams {
204
217
  whereSql?: string;
205
218
  };
206
219
  loadDefaultPrivileges?: boolean;
220
+ loadGrants?: boolean;
207
221
  }
208
222
  declare function getDbVersion(db: Adapter): Promise<number>;
209
223
  declare function introspectDbSchema(db: Adapter, params?: IntrospectDbStructureParams): Promise<IntrospectedStructure>;
210
- type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.RenameSchema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.RenameTableItem | RakeDbAst.View | RakeDbAst.Role | RakeDbAst.RenameRole | RakeDbAst.ChangeRole | RakeDbAst.DefaultPrivilege | RakeDbAst.TableRls;
224
+ type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.RenameSchema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.RenameTableItem | RakeDbAst.View | RakeDbAst.Role | RakeDbAst.RenameRole | RakeDbAst.ChangeRole | RakeDbAst.DefaultPrivilege | RakeDbAst.TableRls | RakeDbAst.Policy | RakeDbAst.PolicyChange | RakeDbAst.Grant;
211
225
  declare namespace RakeDbAst {
212
226
  export interface Table extends TableData {
213
227
  type: 'table';
@@ -440,6 +454,42 @@ declare namespace RakeDbAst {
440
454
  schema?: string;
441
455
  table: string;
442
456
  }
457
+ export interface PolicyDefinition {
458
+ as: RlsPolicy.PolicyMode;
459
+ for?: RlsPolicy.PolicyCommand;
460
+ to?: string[];
461
+ using?: string;
462
+ withCheck?: string;
463
+ }
464
+ export interface PolicyChangeDefinition {
465
+ table?: string;
466
+ name?: string;
467
+ as?: RlsPolicy.PolicyMode;
468
+ for?: RlsPolicy.PolicyCommand;
469
+ to?: string[];
470
+ using?: string;
471
+ withCheck?: string;
472
+ }
473
+ export interface Policy extends PolicyDefinition {
474
+ type: 'policy';
475
+ action: 'create' | 'drop';
476
+ schema?: string;
477
+ table: string;
478
+ name: string;
479
+ }
480
+ export interface PolicyChange {
481
+ type: 'changePolicy';
482
+ schema?: string;
483
+ table: string;
484
+ name: string;
485
+ from: PolicyChangeDefinition;
486
+ to: PolicyChangeDefinition;
487
+ }
488
+ export interface Grant extends Grant.InternalPrivilege {
489
+ type: 'grant';
490
+ action: 'grant' | 'revoke';
491
+ revokeMode?: 'CASCADE' | 'RESTRICT';
492
+ }
443
493
  export {};
444
494
  }
445
495
  interface TableMethods {
@@ -536,6 +586,47 @@ interface ChangeDefaultPrivilegesArg {
536
586
  grant?: DefaultPrivilegeObjectConfig$1;
537
587
  revoke?: DefaultPrivilegeObjectConfig$1;
538
588
  }
589
+ interface RlsPolicyForSelectOrDelete {
590
+ for: 'SELECT' | 'DELETE';
591
+ using: RawSqlBase;
592
+ withCheck?: never;
593
+ }
594
+ interface RlsPolicyForInsert {
595
+ for: 'INSERT';
596
+ using?: never;
597
+ withCheck: RawSqlBase;
598
+ }
599
+ interface RlsPolicyForAllOrUpdate {
600
+ for?: 'ALL' | 'UPDATE';
601
+ using: RawSqlBase;
602
+ withCheck: RawSqlBase;
603
+ }
604
+ type RlsPolicyExpressions = RlsPolicyForSelectOrDelete | RlsPolicyForInsert | RlsPolicyForAllOrUpdate;
605
+ type RlsPolicyDefinition = RlsPolicyExpressions & {
606
+ as: RlsPolicy.PolicyMode;
607
+ to?: string | string[];
608
+ };
609
+ interface ChangeRlsPolicyAlterDefinition {
610
+ name?: string;
611
+ to?: string | string[];
612
+ using?: RawSqlBase;
613
+ withCheck?: RawSqlBase;
614
+ }
615
+ type ChangeRlsPolicyRecreateDefinition = RlsPolicyDefinition & {
616
+ table?: string;
617
+ name?: string;
618
+ };
619
+ type ChangeRlsPolicyParams = {
620
+ from: ChangeRlsPolicyAlterDefinition;
621
+ to: ChangeRlsPolicyAlterDefinition;
622
+ } | {
623
+ from: ChangeRlsPolicyRecreateDefinition;
624
+ to: ChangeRlsPolicyRecreateDefinition;
625
+ };
626
+ type RevokeMode = 'CASCADE' | 'RESTRICT';
627
+ type GrantMigrationArg = Grant.Privilege & {
628
+ revokeMode?: RevokeMode;
629
+ };
539
630
  type DropMode = 'CASCADE' | 'RESTRICT';
540
631
  type TableOptions = {
541
632
  createIfNotExists?: boolean;
@@ -1496,6 +1587,11 @@ declare class Migration<CT = unknown> {
1496
1587
  disableRls(tableName: string): Promise<void>;
1497
1588
  forceRls(tableName: string): Promise<void>;
1498
1589
  noForceRls(tableName: string): Promise<void>;
1590
+ createPolicy(tableName: string, policyName: string, params: RlsPolicyDefinition): Promise<void>;
1591
+ dropPolicy(tableName: string, policyName: string, params: RlsPolicyDefinition): Promise<void>;
1592
+ changePolicy(tableName: string, policyName: string, params: ChangeRlsPolicyParams): Promise<void>;
1593
+ grant(params: GrantMigrationArg): Promise<void>;
1594
+ revoke(params: GrantMigrationArg): Promise<void>;
1499
1595
  }
1500
1596
  interface AddEnumValueOptions {
1501
1597
  ifNotExists?: boolean;