@naturalcycles/db-lib 10.21.0 → 10.22.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.
@@ -175,9 +175,9 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
175
175
  private static multiGetMapByTableById;
176
176
  private static prepareMultiGetOutput;
177
177
  /**
178
- * Very @experimental.
178
+ * @experimental.
179
179
  */
180
- static multiDeleteByIds(inputs: DaoWithIds<AnyDao>[], _opt?: CommonDaoOptions): Promise<NonNegativeInteger>;
180
+ static multiDelete(inputs: (DaoWithId<AnyDao> | DaoWithIds<AnyDao>)[], opt?: CommonDaoOptions): Promise<NonNegativeInteger>;
181
181
  static multiSave(inputs: (DaoWithRows<AnyDao> | DaoWithRow<AnyDao>)[], opt?: CommonDaoSaveBatchOptions<any>): Promise<void>;
182
182
  createTransaction(opt?: CommonDBTransactionOptions): Promise<CommonDaoTransaction>;
183
183
  runInTransaction<T = void>(fn: CommonDaoTransactionFn<T>, opt?: CommonDBTransactionOptions): Promise<T>;
@@ -854,17 +854,27 @@ export class CommonDao {
854
854
  return bmsByProp;
855
855
  }
856
856
  /**
857
- * Very @experimental.
857
+ * @experimental.
858
858
  */
859
- static async multiDeleteByIds(inputs, _opt = {}) {
859
+ static async multiDelete(inputs, opt = {}) {
860
860
  if (!inputs.length)
861
861
  return 0;
862
862
  const { db } = inputs[0].dao.cfg;
863
863
  const idsByTable = {};
864
- for (const { dao, ids } of inputs) {
865
- idsByTable[dao.cfg.table] = ids;
864
+ for (const input of inputs) {
865
+ const { dao } = input;
866
+ const { table } = dao.cfg;
867
+ dao.requireWriteAccess();
868
+ dao.requireObjectMutability(opt);
869
+ idsByTable[table] ||= [];
870
+ if ('id' in input) {
871
+ idsByTable[table].push(input.id);
872
+ }
873
+ else {
874
+ idsByTable[table].push(...input.ids);
875
+ }
866
876
  }
867
- return await db.multiDelete(idsByTable);
877
+ return await db.multiDelete(idsByTable, opt);
868
878
  }
869
879
  static async multiSave(inputs, opt = {}) {
870
880
  if (!inputs.length)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.21.0",
4
+ "version": "10.22.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -1139,20 +1139,30 @@ export class CommonDao<
1139
1139
  }
1140
1140
 
1141
1141
  /**
1142
- * Very @experimental.
1142
+ * @experimental.
1143
1143
  */
1144
- static async multiDeleteByIds(
1145
- inputs: DaoWithIds<AnyDao>[],
1146
- _opt: CommonDaoOptions = {},
1144
+ static async multiDelete(
1145
+ inputs: (DaoWithId<AnyDao> | DaoWithIds<AnyDao>)[],
1146
+ opt: CommonDaoOptions = {},
1147
1147
  ): Promise<NonNegativeInteger> {
1148
1148
  if (!inputs.length) return 0
1149
1149
  const { db } = inputs[0]!.dao.cfg
1150
1150
  const idsByTable: StringMap<string[]> = {}
1151
- for (const { dao, ids } of inputs) {
1152
- idsByTable[dao.cfg.table] = ids
1151
+ for (const input of inputs) {
1152
+ const { dao } = input
1153
+ const { table } = dao.cfg
1154
+ dao.requireWriteAccess()
1155
+ dao.requireObjectMutability(opt)
1156
+ idsByTable[table] ||= []
1157
+
1158
+ if ('id' in input) {
1159
+ idsByTable[table].push(input.id)
1160
+ } else {
1161
+ idsByTable[table].push(...input.ids)
1162
+ }
1153
1163
  }
1154
1164
 
1155
- return await db.multiDelete(idsByTable)
1165
+ return await db.multiDelete(idsByTable, opt)
1156
1166
  }
1157
1167
 
1158
1168
  static async multiSave(