rake-db 2.34.1 → 2.35.1
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 +101 -4
- package/dist/index.js +573 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +574 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _$pqb_internal0 from "pqb/internal";
|
|
2
|
+
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
3
|
import { Db } from "pqb";
|
|
3
4
|
declare namespace DbStructure {
|
|
4
5
|
interface TableNameAndSchemaName {
|
|
5
6
|
schemaName: string;
|
|
6
7
|
tableName: string;
|
|
7
8
|
}
|
|
9
|
+
type RlsPolicyMode = RlsPolicy.PolicyMode;
|
|
10
|
+
type RlsPolicyCommand = RlsPolicy.PolicyCommand;
|
|
11
|
+
interface RlsPolicy extends TableNameAndSchemaName {
|
|
12
|
+
name: string;
|
|
13
|
+
mode: RlsPolicyMode;
|
|
14
|
+
command: RlsPolicyCommand;
|
|
15
|
+
roles: string[];
|
|
16
|
+
using?: string;
|
|
17
|
+
withCheck?: string;
|
|
18
|
+
}
|
|
8
19
|
interface TableRls {
|
|
9
20
|
enable: boolean;
|
|
10
21
|
force: boolean;
|
|
22
|
+
policies?: RlsPolicy[];
|
|
11
23
|
}
|
|
12
24
|
interface Table {
|
|
13
25
|
schemaName: string;
|
|
@@ -180,6 +192,7 @@ declare namespace DbStructure {
|
|
|
180
192
|
schema?: string;
|
|
181
193
|
objectConfigs: DefaultPrivilegeObjectConfig[];
|
|
182
194
|
}
|
|
195
|
+
type Grant = Grant.InternalPrivilege;
|
|
183
196
|
}
|
|
184
197
|
interface IntrospectedStructure {
|
|
185
198
|
version: number;
|
|
@@ -196,6 +209,7 @@ interface IntrospectedStructure {
|
|
|
196
209
|
collations: DbStructure.Collation[];
|
|
197
210
|
roles?: DbStructure.Role[];
|
|
198
211
|
defaultPrivileges?: DbStructure.DefaultPrivilege[];
|
|
212
|
+
grants?: DbStructure.Grant[];
|
|
199
213
|
managedRolesSql?: string;
|
|
200
214
|
}
|
|
201
215
|
interface IntrospectDbStructureParams {
|
|
@@ -204,10 +218,11 @@ interface IntrospectDbStructureParams {
|
|
|
204
218
|
whereSql?: string;
|
|
205
219
|
};
|
|
206
220
|
loadDefaultPrivileges?: boolean;
|
|
221
|
+
loadGrants?: boolean;
|
|
207
222
|
}
|
|
208
223
|
declare function getDbVersion(db: Adapter): Promise<number>;
|
|
209
224
|
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;
|
|
225
|
+
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
226
|
declare namespace RakeDbAst {
|
|
212
227
|
export interface Table extends TableData {
|
|
213
228
|
type: 'table';
|
|
@@ -440,6 +455,42 @@ declare namespace RakeDbAst {
|
|
|
440
455
|
schema?: string;
|
|
441
456
|
table: string;
|
|
442
457
|
}
|
|
458
|
+
export interface PolicyDefinition {
|
|
459
|
+
as: RlsPolicy.PolicyMode;
|
|
460
|
+
for?: RlsPolicy.PolicyCommand;
|
|
461
|
+
to?: string[];
|
|
462
|
+
using?: string;
|
|
463
|
+
withCheck?: string;
|
|
464
|
+
}
|
|
465
|
+
export interface PolicyChangeDefinition {
|
|
466
|
+
table?: string;
|
|
467
|
+
name?: string;
|
|
468
|
+
as?: RlsPolicy.PolicyMode;
|
|
469
|
+
for?: RlsPolicy.PolicyCommand;
|
|
470
|
+
to?: string[];
|
|
471
|
+
using?: string;
|
|
472
|
+
withCheck?: string;
|
|
473
|
+
}
|
|
474
|
+
export interface Policy extends PolicyDefinition {
|
|
475
|
+
type: 'policy';
|
|
476
|
+
action: 'create' | 'drop';
|
|
477
|
+
schema?: string;
|
|
478
|
+
table: string;
|
|
479
|
+
name: string;
|
|
480
|
+
}
|
|
481
|
+
export interface PolicyChange {
|
|
482
|
+
type: 'changePolicy';
|
|
483
|
+
schema?: string;
|
|
484
|
+
table: string;
|
|
485
|
+
name: string;
|
|
486
|
+
from: PolicyChangeDefinition;
|
|
487
|
+
to: PolicyChangeDefinition;
|
|
488
|
+
}
|
|
489
|
+
export interface Grant extends Grant.InternalPrivilege {
|
|
490
|
+
type: 'grant';
|
|
491
|
+
action: 'grant' | 'revoke';
|
|
492
|
+
revokeMode?: 'CASCADE' | 'RESTRICT';
|
|
493
|
+
}
|
|
443
494
|
export {};
|
|
444
495
|
}
|
|
445
496
|
interface TableMethods {
|
|
@@ -536,6 +587,47 @@ interface ChangeDefaultPrivilegesArg {
|
|
|
536
587
|
grant?: DefaultPrivilegeObjectConfig$1;
|
|
537
588
|
revoke?: DefaultPrivilegeObjectConfig$1;
|
|
538
589
|
}
|
|
590
|
+
interface RlsPolicyForSelectOrDelete {
|
|
591
|
+
for: 'SELECT' | 'DELETE';
|
|
592
|
+
using: RawSqlBase;
|
|
593
|
+
withCheck?: never;
|
|
594
|
+
}
|
|
595
|
+
interface RlsPolicyForInsert {
|
|
596
|
+
for: 'INSERT';
|
|
597
|
+
using?: never;
|
|
598
|
+
withCheck: RawSqlBase;
|
|
599
|
+
}
|
|
600
|
+
interface RlsPolicyForAllOrUpdate {
|
|
601
|
+
for?: 'ALL' | 'UPDATE';
|
|
602
|
+
using: RawSqlBase;
|
|
603
|
+
withCheck: RawSqlBase;
|
|
604
|
+
}
|
|
605
|
+
type RlsPolicyExpressions = RlsPolicyForSelectOrDelete | RlsPolicyForInsert | RlsPolicyForAllOrUpdate;
|
|
606
|
+
type RlsPolicyDefinition = RlsPolicyExpressions & {
|
|
607
|
+
as: RlsPolicy.PolicyMode;
|
|
608
|
+
to?: string | string[];
|
|
609
|
+
};
|
|
610
|
+
interface ChangeRlsPolicyAlterDefinition {
|
|
611
|
+
name?: string;
|
|
612
|
+
to?: string | string[];
|
|
613
|
+
using?: RawSqlBase;
|
|
614
|
+
withCheck?: RawSqlBase;
|
|
615
|
+
}
|
|
616
|
+
type ChangeRlsPolicyRecreateDefinition = RlsPolicyDefinition & {
|
|
617
|
+
table?: string;
|
|
618
|
+
name?: string;
|
|
619
|
+
};
|
|
620
|
+
type ChangeRlsPolicyParams = {
|
|
621
|
+
from: ChangeRlsPolicyAlterDefinition;
|
|
622
|
+
to: ChangeRlsPolicyAlterDefinition;
|
|
623
|
+
} | {
|
|
624
|
+
from: ChangeRlsPolicyRecreateDefinition;
|
|
625
|
+
to: ChangeRlsPolicyRecreateDefinition;
|
|
626
|
+
};
|
|
627
|
+
type RevokeMode = 'CASCADE' | 'RESTRICT';
|
|
628
|
+
type GrantMigrationArg = Grant.Privilege & {
|
|
629
|
+
revokeMode?: RevokeMode;
|
|
630
|
+
};
|
|
539
631
|
type DropMode = 'CASCADE' | 'RESTRICT';
|
|
540
632
|
type TableOptions = {
|
|
541
633
|
createIfNotExists?: boolean;
|
|
@@ -1496,6 +1588,11 @@ declare class Migration<CT = unknown> {
|
|
|
1496
1588
|
disableRls(tableName: string): Promise<void>;
|
|
1497
1589
|
forceRls(tableName: string): Promise<void>;
|
|
1498
1590
|
noForceRls(tableName: string): Promise<void>;
|
|
1591
|
+
createPolicy(tableName: string, policyName: string, params: RlsPolicyDefinition): Promise<void>;
|
|
1592
|
+
dropPolicy(tableName: string, policyName: string, params: RlsPolicyDefinition): Promise<void>;
|
|
1593
|
+
changePolicy(tableName: string, policyName: string, params: ChangeRlsPolicyParams): Promise<void>;
|
|
1594
|
+
grant(params: GrantMigrationArg): Promise<void>;
|
|
1595
|
+
revoke(params: GrantMigrationArg): Promise<void>;
|
|
1499
1596
|
}
|
|
1500
1597
|
interface AddEnumValueOptions {
|
|
1501
1598
|
ifNotExists?: boolean;
|
|
@@ -1791,7 +1888,7 @@ interface RakeDbConfig<ColumnTypes = unknown> extends QueryLogOptions {
|
|
|
1791
1888
|
commands: RakeDbCommands;
|
|
1792
1889
|
}
|
|
1793
1890
|
declare const rakeDbConfigDefaults: {
|
|
1794
|
-
schemaConfig:
|
|
1891
|
+
schemaConfig: DefaultSchemaConfig;
|
|
1795
1892
|
snakeCase: boolean;
|
|
1796
1893
|
commands: {};
|
|
1797
1894
|
log: boolean;
|
|
@@ -1927,7 +2024,7 @@ interface StructureToAstTableData {
|
|
|
1927
2024
|
declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, "snakeCase" | "schemaConfig">, currentSchema: string) => StructureToAstCtx;
|
|
1928
2025
|
declare const structureToAst: (ctx: StructureToAstCtx, adapter: Adapter, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<RakeDbAst[]>;
|
|
1929
2026
|
declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
|
|
1930
|
-
declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column$1
|
|
2027
|
+
declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column$1<_$pqb_internal0.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
|
|
1931
2028
|
declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: "create" | "drop", domains: DbStructureDomainsMap) => RakeDbAst.Table;
|
|
1932
2029
|
declare const getDbStructureTableData: (data: IntrospectedStructure, {
|
|
1933
2030
|
name,
|