orchid-orm 1.68.3 → 1.68.5
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 +15 -7
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/index.js +59 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +59 -2
- package/dist/migrations/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Adapter, AfterCommitStandaloneHook, AfterHook, Column, ColumnSchemaConfig, ColumnsShape, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateData, CreateManyMethodsNames, CreateMethodsNames, DbSharedOptions, DbSqlMethod, DbTableOptionScopes, DefaultColumnTypes, DefaultSchemaConfig, DeleteMethodsNames, EmptyObject, FromArg, FromResult, IsQuery, IsolationLevel, JoinQueryMethod, MapTableScopesOption, MaybeArray, MergeQuery, QueryAfterHook, QueryBeforeActionHook, QueryBeforeHook, QueryData, QueryHasWhere, QueryManyTake, QueryManyTakeOptional, QueryOrExpression, QueryReturnType, QuerySchema, QueryScopes, RecordUnknown, RelationConfigBase, SelectableFromShape, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, StorageOptions, TableData, TableDataFn, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TransactionOptions, UniqueConstraints, UpdateData, WhereArg } from "pqb/internal";
|
|
1
|
+
import { Adapter, AfterCommitStandaloneHook, AfterHook, Column, ColumnSchemaConfig, ColumnsShape, ComputedColumnsFromOptions, ComputedOptionsConfig, ComputedOptionsFactory, CreateData, CreateManyMethodsNames, CreateMethodsNames, DbSharedOptions, DbSqlMethod, DbTableOptionScopes, DefaultColumnTypes, DefaultSchemaConfig, DeleteMethodsNames, EmptyObject, FromArg, FromResult, IsQuery, IsolationLevel, JoinQueryMethod, MapTableScopesOption, MaybeArray, MergeQuery, QueryAfterHook, QueryBeforeActionHook, QueryBeforeHook, QueryData, QueryHasWhere, QueryManyTake, QueryManyTakeOptional, QueryOrExpression, QueryReturnType, QuerySchema, QueryScopes, RecordUnknown, RelationConfigBase, SelectableFromShape, ShallowSimplify, ShapeColumnPrimaryKeys, ShapeUniqueColumns, StorageOptions, TableData, TableDataFn, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableRlsConfig, TransactionOptions, UniqueConstraints, UpdateData, WhereArg } from "pqb/internal";
|
|
2
2
|
import { Db, Query } from "pqb";
|
|
3
3
|
export * from "pqb";
|
|
4
4
|
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends Column.Shape.QueryInit = Column.Shape.QueryInit> {
|
|
@@ -28,7 +28,7 @@ interface HasOneInfo<T extends RelationConfigSelf, Name extends string, Rel exte
|
|
|
28
28
|
query: Q;
|
|
29
29
|
params: HasOneParams<T, Rel['options']>;
|
|
30
30
|
maybeSingle: T['relations'][Name]['options']['required'] extends true ? QueryManyTake<Q> : QueryManyTakeOptional<Q>;
|
|
31
|
-
|
|
31
|
+
omitForeignKeyInCreate: never;
|
|
32
32
|
optionalDataForCreate: T['relations'][Name]['options'] extends RelationThroughOptions ? EmptyObject : { [P in Name]?: RelationToOneDataForCreate<{
|
|
33
33
|
nestedCreateQuery: CreateData<Q>;
|
|
34
34
|
table: Q;
|
|
@@ -68,7 +68,7 @@ interface HasManyInfo<T extends RelationConfigSelf, Name extends string, Rel ext
|
|
|
68
68
|
query: Q;
|
|
69
69
|
params: HasOneParams<T, Rel['options']>;
|
|
70
70
|
maybeSingle: Q;
|
|
71
|
-
|
|
71
|
+
omitForeignKeyInCreate: never;
|
|
72
72
|
optionalDataForCreate: { [P in Name]?: T['relations'][Name]['options'] extends RelationThroughOptions ? EmptyObject : {
|
|
73
73
|
create?: CreateData<Q>[];
|
|
74
74
|
connect?: WhereArg<Q>[];
|
|
@@ -122,8 +122,11 @@ interface BelongsToInfo<T extends RelationConfigSelf, Name extends string, FK ex
|
|
|
122
122
|
query: Q;
|
|
123
123
|
params: BelongsToParams<T, FK>;
|
|
124
124
|
maybeSingle: Required extends true ? QueryManyTake<Q> : QueryManyTakeOptional<Q>;
|
|
125
|
-
|
|
126
|
-
dataForCreate: {
|
|
125
|
+
omitForeignKeyInCreate: FK;
|
|
126
|
+
dataForCreate: {
|
|
127
|
+
columns: FK;
|
|
128
|
+
nested: Required extends true ? { [Key in Name]: RelationToOneDataForCreateSameQuery<Q> } : { [Key in Name]?: RelationToOneDataForCreateSameQuery<Q> };
|
|
129
|
+
};
|
|
127
130
|
optionalDataForCreate: EmptyObject;
|
|
128
131
|
dataForUpdate: {
|
|
129
132
|
disconnect: boolean;
|
|
@@ -174,6 +177,10 @@ interface FromQuery extends Query {
|
|
|
174
177
|
type OrchidORM<T extends TableClasses = TableClasses> = { [K in keyof T]: T[K] extends {
|
|
175
178
|
new (): infer R extends ORMTableInput;
|
|
176
179
|
} ? TableToDb<R> : never } & OrchidORMMethods;
|
|
180
|
+
/**
|
|
181
|
+
* Identity helper for table row-level security configuration.
|
|
182
|
+
*/
|
|
183
|
+
declare const defineRls: <T extends TableRlsConfig>(rls: T) => T;
|
|
177
184
|
interface OrchidORMMethods {
|
|
178
185
|
/**
|
|
179
186
|
* @see import('pqb').QueryTransaction.prototype.transaction
|
|
@@ -358,7 +365,7 @@ interface HasAndBelongsToManyInfo<T extends RelationConfigSelf, Name extends str
|
|
|
358
365
|
query: Q;
|
|
359
366
|
params: HasAndBelongsToManyParams<T, FK>;
|
|
360
367
|
maybeSingle: Q;
|
|
361
|
-
|
|
368
|
+
omitForeignKeyInCreate: never;
|
|
362
369
|
optionalDataForCreate: { [P in Name]?: {
|
|
363
370
|
create?: CreateData<Q>[];
|
|
364
371
|
connect?: WhereArg<Q>[];
|
|
@@ -479,6 +486,7 @@ interface ORMTableInput {
|
|
|
479
486
|
scopes?: RecordUnknown;
|
|
480
487
|
readonly softDelete?: true | string;
|
|
481
488
|
comment?: string;
|
|
489
|
+
rls?: TableRlsConfig;
|
|
482
490
|
autoForeignKeys?: TableData.References.BaseOptions | boolean;
|
|
483
491
|
}
|
|
484
492
|
type Queryable<T extends ORMTableInput> = ShallowSimplify<{ [K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['queryType'] }>;
|
|
@@ -752,4 +760,4 @@ declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(tabl
|
|
|
752
760
|
table: T["table"];
|
|
753
761
|
shape: T["shape"];
|
|
754
762
|
}>(q: Q) => Query & Q & MapMethods<T, Methods>) & T, Methods>;
|
|
755
|
-
export { BaseTableClass, BaseTableInstance, DefaultSelect, FromQuery, Insertable, MapMethods, MapQueryMethods, MethodsBase, ORMTableInput, OrchidORM, OrchidOrmParam, Queryable, Repo, Selectable, SetColumnsResult, Table, TableClass, TableClasses, TableInfo, TableToDb, Updatable, createBaseTable, createRepo, orchidORMWithAdapter };
|
|
763
|
+
export { BaseTableClass, BaseTableInstance, DefaultSelect, FromQuery, Insertable, MapMethods, MapQueryMethods, MethodsBase, ORMTableInput, OrchidORM, OrchidOrmParam, Queryable, Repo, Selectable, SetColumnsResult, Table, TableClass, TableClasses, TableInfo, TableToDb, Updatable, createBaseTable, createRepo, defineRls, orchidORMWithAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1371,6 +1371,10 @@ function isInTransaction() {
|
|
|
1371
1371
|
function afterCommit(hook) {
|
|
1372
1372
|
this.$qb.afterCommit(hook);
|
|
1373
1373
|
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Identity helper for table row-level security configuration.
|
|
1376
|
+
*/
|
|
1377
|
+
const defineRls = (rls) => rls;
|
|
1374
1378
|
const orchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPrimaryKey = "error", schema, ...options }, tables) => {
|
|
1375
1379
|
const commonOptions = {
|
|
1376
1380
|
log,
|
|
@@ -1390,6 +1394,7 @@ const orchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPrimaryKe
|
|
|
1390
1394
|
asyncStorage = new node_async_hooks.AsyncLocalStorage();
|
|
1391
1395
|
qb = (0, pqb_internal._initQueryBuilder)(adapter, (0, pqb_internal.makeColumnTypes)(pqb_internal.defaultSchemaConfig), asyncStorage, commonOptions, options);
|
|
1392
1396
|
}
|
|
1397
|
+
qb.internal.rls = options.rls;
|
|
1393
1398
|
const result = {
|
|
1394
1399
|
$transaction: transaction,
|
|
1395
1400
|
$ensureTransaction: ensureTransaction,
|
|
@@ -1432,6 +1437,7 @@ const orchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPrimaryKe
|
|
|
1432
1437
|
dbTable.db = result;
|
|
1433
1438
|
dbTable.filePath = table.filePath;
|
|
1434
1439
|
dbTable.name = table.constructor.name;
|
|
1440
|
+
dbTable.internal.tableRls = table.rls;
|
|
1435
1441
|
result[key] = dbTable;
|
|
1436
1442
|
}
|
|
1437
1443
|
applyRelations(qb, tableInstances, result, schema);
|
|
@@ -1476,6 +1482,7 @@ const createRepo = (table, methods) => {
|
|
|
1476
1482
|
};
|
|
1477
1483
|
exports.createBaseTable = createBaseTable;
|
|
1478
1484
|
exports.createRepo = createRepo;
|
|
1485
|
+
exports.defineRls = defineRls;
|
|
1479
1486
|
exports.orchidORMWithAdapter = orchidORMWithAdapter;
|
|
1480
1487
|
Object.keys(pqb).forEach(function(k) {
|
|
1481
1488
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|