@classytic/ledger 0.12.0 → 0.12.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.
Files changed (2) hide show
  1. package/dist/index.mjs +19 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1185,12 +1185,25 @@ function wireAccountMethods(repository, country, orgField, integrations = {}) {
1185
1185
  });
1186
1186
  try {
1187
1187
  const inserted = await repository.createMany(docs, { ordered: false });
1188
- results.created = toCreate.map((item, idx) => ({
1189
- accountTypeCode: item.accountTypeCode,
1190
- active: item.active,
1191
- isCashAccount: item.isCashAccount,
1192
- _id: inserted[idx]._id
1193
- }));
1188
+ const insertedByNumber = /* @__PURE__ */ new Map();
1189
+ for (const doc of inserted) {
1190
+ const num = doc?.accountNumber;
1191
+ if (num) insertedByNumber.set(num, doc);
1192
+ }
1193
+ for (const item of toCreate) {
1194
+ const doc = insertedByNumber.get(item.accountNumber);
1195
+ if (doc) results.created.push({
1196
+ accountTypeCode: item.accountTypeCode,
1197
+ active: item.active,
1198
+ isCashAccount: item.isCashAccount,
1199
+ _id: doc._id
1200
+ });
1201
+ else results.skipped.push({
1202
+ index: item.index,
1203
+ accountTypeCode: item.accountTypeCode,
1204
+ reason: "Not returned by createMany (driver edge case)"
1205
+ });
1206
+ }
1194
1207
  } catch (err) {
1195
1208
  if (!isDuplicateKeyBulkError(err)) throw err;
1196
1209
  const insertedDocs = err.insertedDocs ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/ledger",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Production-grade double-entry accounting engine for MongoDB — schemas, reports, tax, multi-tenant",
5
5
  "type": "module",
6
6
  "sideEffects": false,