equipped 5.0.28 → 5.0.29

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [5.0.29](https://github.com/kevinand11/equipped/compare/v5.0.28...v5.0.29) (2025-08-28)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * use snapshot mode of always ([cf3f132](https://github.com/kevinand11/equipped/commit/cf3f13204549661846fc440096f974f371269f84))
11
+
5
12
  ### [5.0.28](https://github.com/kevinand11/equipped/compare/v5.0.27...v5.0.28) (2025-08-18)
6
13
 
7
14
 
@@ -55,7 +55,7 @@ class MongoDbChange extends _changescjs.DbChange {
55
55
  "capture.mode": "change_streams_update_full_with_pre_image",
56
56
  "mongodb.connection.string": config.uri,
57
57
  "collection.include.list": dbColName,
58
- "snapshot.mode": "when_needed"
58
+ "snapshot.mode": "always"
59
59
  });
60
60
  if (started) return { done: true, value: true };
61
61
  await collection.findOneAndUpdate(condition, { $set: { colName } }, { upsert: true });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts","/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.cjs"],"names":[],"mappings":"AAAA,mtBAA6C;AAC7C,oCAAuB;AAEvB,kDAA8B;AAC9B,qDAAyB;AACzB,sDAAsB;AACtB,iDAAsC;AAK/B,MAAM,cAAA,QAA6F,qBAAwB;AAAA,EACjI,CAAA,QAAA,EAAW,KAAA;AAAA,EAEX,WAAA,CACC,MAAA,EACA,MAAA,EACA,UAAA,EACA,SAAA,EACA,MAAA,EACC;AACD,IAAA,KAAA,CAAM,MAAA,EAAQ,SAAA,EAAW,MAAM,CAAA;AAE/B,IAAA,MAAM,QAAA,EAAU,CAAC,IAAA,EAAA,GAChB,IAAA,CAAK,IAAA,EACF;AAAA,MACA,GAAG,IAAA;AAAA,MACH,GAAA,EAAK,MAAA,kBAAO,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,UAAK,IAAA,CAAK,KAAG;AAAA,IACzC,EAAA,EACC,KAAA,CAAA;AAEJ,IAAA,MAAM,OAAA,EAAS,UAAA,CAAW,MAAA;AAC1B,IAAA,MAAM,QAAA,EAAU,UAAA,CAAW,cAAA;AAC3B,IAAA,MAAM,UAAA,EAAY,CAAA,EAAA;AACD,IAAA;AAEH,IAAA;AACC,IAAA;AACG,IAAA;AAEF,IAAA;AACC,MAAA;AAEH,MAAA;AACI,MAAA;AAEL,MAAA;AACD,MAAA;AACC,MAAA;AAED,MAAA;AACC,QAAA;AACF,UAAA;AACI,UAAA;AACZ,QAAA;AACc,MAAA;AACJ,QAAA;AACG,UAAA;AACD,UAAA;AACH,UAAA;AACT,QAAA;AACc,MAAA;AACJ,QAAA;AACG,UAAA;AACN,UAAA;AACP,QAAA;AACF,IAAA;AAEQ,IAAA;AACR,MAAA;AACY,MAAA;AACF,QAAA;AACJ,QAAA;AAEC,QAAA;AACO,UAAA;AACL,YAAA;AACL,cAAA;AACA,cAAA;AACA,cAAA;AACA,cAAA;AACA,cAAA;AACA,YAAA;AAEG,YAAA;AACE,YAAA;AACA,YAAA;AACG,YAAA;AACA,YAAA;AACV,UAAA;AACA,UAAA;AACA,UAAA;AACQ,QAAA;AACV,MAAA;AACA,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAQ+B;AAC1B,EAAA;AACQ,IAAA;AACJ,EAAA;AACA,IAAA;AACR,EAAA;AACD;AC/BuB;AACA;AACA","file":"/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.cjs","sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'when_needed',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n",null]}
1
+ {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts","/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.cjs"],"names":[],"mappings":"AAAA,mtBAA6C;AAC7C,oCAAuB;AAEvB,kDAA8B;AAC9B,qDAAyB;AACzB,sDAAsB;AACt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ACQ,IAAA;AACJ,EAAA;AACA,IAAA;AACR,EAAA;AACD;AC/BuB;AACA;AACA","file":"/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.cjs","sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'always',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n",null]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _mongodb = require('mongodb');var _valleyed = require('valleyed');var _indexmincjs = require('../../errors/index.min.cjs');var _indexmincjs3 = require('../../instance/index.min.cjs');var _indexmincjs5 = require('../../utilities/index.min.cjs');var _changesmincjs = require('../base/changes.min.cjs');class z extends _changesmincjs.DbChange{#e=!1;constructor(h,d,r,g,_){super(d,g,_);const l=e=>e._id?{...e,_id:b(_nullishCoalesce(e._id.$oid, () => (e._id)))}:void 0,C=r.dbName,f=r.collectionName,n=`${C}.${f}`,m=`${_changesmincjs.TopicPrefix}.${n}`,a=b("5f5f65717569707065645f5f"),p={_id:a};d.eventBus.createStream(m,{skipScope:!0}).subscribe(async e=>{const s=e.op;let t=JSON.parse(_nullishCoalesce(e.before, () => ("null"))),o=JSON.parse(_nullishCoalesce(e.after, () => ("null")));t&&(t=l(t)),o&&(o=l(o)),!(_optionalChain([t, 'optionalAccess', _2 => _2.__id])===a||_optionalChain([o, 'optionalAccess', _3 => _3.__id])===a)&&(s==="c"&&this.callbacks.created&&o?await this.callbacks.created({before:null,after:this.mapper(o)}):s==="u"&&this.callbacks.updated&&t&&o?await this.callbacks.updated({before:this.mapper(t),after:this.mapper(o),changes:_valleyed.differ.from(_valleyed.differ.diff(t,o))}):s==="d"&&this.callbacks.deleted&&t&&await this.callbacks.deleted({before:this.mapper(t),after:null}))}),_indexmincjs3.Instance.on("start",async()=>{this.#e||(this.#e=!0,await _indexmincjs5.retry.call(void 0, async()=>await this.configureConnector(m,{"connector.class":"io.debezium.connector.mongodb.MongoDbConnector","capture.mode":"change_streams_update_full_with_pre_image","mongodb.connection.string":h.uri,"collection.include.list":n,"snapshot.mode":"when_needed"})?{done:!0,value:!0}:(await r.findOneAndUpdate(p,{$set:{colName:f}},{upsert:!0}),await r.findOneAndDelete(p),_indexmincjs3.Instance.get().log.warn(`Waiting for db changes for ${n} to start...`),{done:!1}),6,1e4).catch(e=>_indexmincjs3.Instance.crash(new (0, _indexmincjs.EquippedError)("Failed to start db changes",{dbColName:n},e))))},10)}}const b=i=>{try{return new (0, _mongodb.ObjectId)(i)}catch (e2){return i}};exports.MongoDbChange = z;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _mongodb = require('mongodb');var _valleyed = require('valleyed');var _indexmincjs = require('../../errors/index.min.cjs');var _indexmincjs3 = require('../../instance/index.min.cjs');var _indexmincjs5 = require('../../utilities/index.min.cjs');var _changesmincjs = require('../base/changes.min.cjs');class z extends _changesmincjs.DbChange{#e=!1;constructor(h,d,r,g,C){super(d,g,C);const l=e=>e._id?{...e,_id:b(_nullishCoalesce(e._id.$oid, () => (e._id)))}:void 0,_=r.dbName,f=r.collectionName,n=`${_}.${f}`,m=`${_changesmincjs.TopicPrefix}.${n}`,i=b("5f5f65717569707065645f5f"),p={_id:i};d.eventBus.createStream(m,{skipScope:!0}).subscribe(async e=>{const s=e.op;let t=JSON.parse(_nullishCoalesce(e.before, () => ("null"))),o=JSON.parse(_nullishCoalesce(e.after, () => ("null")));t&&(t=l(t)),o&&(o=l(o)),!(_optionalChain([t, 'optionalAccess', _2 => _2.__id])===i||_optionalChain([o, 'optionalAccess', _3 => _3.__id])===i)&&(s==="c"&&this.callbacks.created&&o?await this.callbacks.created({before:null,after:this.mapper(o)}):s==="u"&&this.callbacks.updated&&t&&o?await this.callbacks.updated({before:this.mapper(t),after:this.mapper(o),changes:_valleyed.differ.from(_valleyed.differ.diff(t,o))}):s==="d"&&this.callbacks.deleted&&t&&await this.callbacks.deleted({before:this.mapper(t),after:null}))}),_indexmincjs3.Instance.on("start",async()=>{this.#e||(this.#e=!0,await _indexmincjs5.retry.call(void 0, async()=>await this.configureConnector(m,{"connector.class":"io.debezium.connector.mongodb.MongoDbConnector","capture.mode":"change_streams_update_full_with_pre_image","mongodb.connection.string":h.uri,"collection.include.list":n,"snapshot.mode":"always"})?{done:!0,value:!0}:(await r.findOneAndUpdate(p,{$set:{colName:f}},{upsert:!0}),await r.findOneAndDelete(p),_indexmincjs3.Instance.get().log.warn(`Waiting for db changes for ${n} to start...`),{done:!1}),6,1e4).catch(e=>_indexmincjs3.Instance.crash(new (0, _indexmincjs.EquippedError)("Failed to start db changes",{dbColName:n},e))))},10)}}const b=a=>{try{return new (0, _mongodb.ObjectId)(a)}catch (e2){return a}};exports.MongoDbChange = z;
2
2
  //# sourceMappingURL=changes.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"names":["change","data","colName","collection","topic","dbColName","TestId"],"mappings":"AAAA,mtBAA6C,oCACtB,yDAGd,4DACa,6DACgB,wDAe9BA,MAEN,EAAA,QAAiBC,uBAChBA,CAAAA,CAAK,CAAA,CAAA,CAAA,CACF,CACA,WACYA,CAAAA,CAAK,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAWA,KAAQ,CACzC,CAAA,CACC,CAAA,CAAA,CAAA,CAAA,CAAA,MAEsB,CAAA,CAAA,CAAA,EAAA,CAAA,CACpBC,GAAUC,CAAW,CAAA,GAAA,CAAA,CAAA,GAAA,CAAA,CAAA,kBAAA,CAAA,CAAA,GACT,CAAA,IAAS,SAAA,CAAID,CAAO,KAChCE,CAAAA,CAAQ,CAAA,KAAc,CAAA,CAAIC,CAAS,CAAA,CAAA,CAGnCC,MADQ,CAAA,CAAA,CAAA,CAAA,CAAA,cAAA,CAAA,CAAA,CAAA,CAAA,EAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.min.cjs","sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'when_needed',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"names":["change","data","colName","collection","topic","dbColName","TestId"],"mappings":"AAAA,mtBAA6C,oCACtB,yDAGd,4DACa,6DACgB,wDAe9BA,MAEN,EAAA,QAAiBC,uBAChBA,CAAAA,CAAK,CAAA,CAAA,CAAA,CACF,CACA,WACYA,CAAAA,CAAK,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAWA,KAAQ,CACzC,CAAA,CACC,CAAA,CAAA,CAAA,CAAA,CAAA,MAEsB,CAAA,CAAA,CAAA,EAAA,CAAA,CACpBC,GAAUC,CAAW,CAAA,GAAA,CAAA,CAAA,GAAA,CAAA,CAAA,kBAAA,CAAA,CAAA,GACT,CAAA,IAAS,SAAA,CAAID,CAAO,KAChCE,CAAAA,CAAQ,CAAA,KAAc,CAAA,CAAIC,CAAS,CAAA,CAAA,CAGnCC,MADQ,CAAA,CAAA,CAAA,CAAA,CAAA,cAAA,CAAA,CAAA,CAAA,CAAA,EAAA","file":"/home/runner/work/equipped/equipped/dist/cjs/dbs/mongo/changes.min.cjs","sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'always',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"]}
@@ -1,2 +1,2 @@
1
- import{ObjectId as y}from"mongodb";import{differ as u}from"valleyed";import{EquippedError as D}from "../../errors/index.min.mjs";import{Instance as c}from "../../instance/index.min.mjs";import{retry as w}from "../../utilities/index.min.mjs";import{DbChange as M,TopicPrefix as k}from "../base/changes.min.mjs";class z extends M{#e=!1;constructor(h,d,r,g,_){super(d,g,_);const l=e=>e._id?{...e,_id:b(e._id.$oid??e._id)}:void 0,C=r.dbName,f=r.collectionName,n=`${C}.${f}`,m=`${k}.${n}`,a=b("5f5f65717569707065645f5f"),p={_id:a};d.eventBus.createStream(m,{skipScope:!0}).subscribe(async e=>{const s=e.op;let t=JSON.parse(e.before??"null"),o=JSON.parse(e.after??"null");t&&(t=l(t)),o&&(o=l(o)),!(t?.__id===a||o?.__id===a)&&(s==="c"&&this.callbacks.created&&o?await this.callbacks.created({before:null,after:this.mapper(o)}):s==="u"&&this.callbacks.updated&&t&&o?await this.callbacks.updated({before:this.mapper(t),after:this.mapper(o),changes:u.from(u.diff(t,o))}):s==="d"&&this.callbacks.deleted&&t&&await this.callbacks.deleted({before:this.mapper(t),after:null}))}),c.on("start",async()=>{this.#e||(this.#e=!0,await w(async()=>await this.configureConnector(m,{"connector.class":"io.debezium.connector.mongodb.MongoDbConnector","capture.mode":"change_streams_update_full_with_pre_image","mongodb.connection.string":h.uri,"collection.include.list":n,"snapshot.mode":"when_needed"})?{done:!0,value:!0}:(await r.findOneAndUpdate(p,{$set:{colName:f}},{upsert:!0}),await r.findOneAndDelete(p),c.get().log.warn(`Waiting for db changes for ${n} to start...`),{done:!1}),6,1e4).catch(e=>c.crash(new D("Failed to start db changes",{dbColName:n},e))))},10)}}const b=i=>{try{return new y(i)}catch{return i}};export{z as MongoDbChange};
1
+ import{ObjectId as y}from"mongodb";import{differ as u}from"valleyed";import{EquippedError as D}from "../../errors/index.min.mjs";import{Instance as c}from "../../instance/index.min.mjs";import{retry as w}from "../../utilities/index.min.mjs";import{DbChange as M,TopicPrefix as k}from "../base/changes.min.mjs";class z extends M{#e=!1;constructor(h,d,r,g,C){super(d,g,C);const l=e=>e._id?{...e,_id:b(e._id.$oid??e._id)}:void 0,_=r.dbName,f=r.collectionName,n=`${_}.${f}`,m=`${k}.${n}`,i=b("5f5f65717569707065645f5f"),p={_id:i};d.eventBus.createStream(m,{skipScope:!0}).subscribe(async e=>{const s=e.op;let t=JSON.parse(e.before??"null"),o=JSON.parse(e.after??"null");t&&(t=l(t)),o&&(o=l(o)),!(t?.__id===i||o?.__id===i)&&(s==="c"&&this.callbacks.created&&o?await this.callbacks.created({before:null,after:this.mapper(o)}):s==="u"&&this.callbacks.updated&&t&&o?await this.callbacks.updated({before:this.mapper(t),after:this.mapper(o),changes:u.from(u.diff(t,o))}):s==="d"&&this.callbacks.deleted&&t&&await this.callbacks.deleted({before:this.mapper(t),after:null}))}),c.on("start",async()=>{this.#e||(this.#e=!0,await w(async()=>await this.configureConnector(m,{"connector.class":"io.debezium.connector.mongodb.MongoDbConnector","capture.mode":"change_streams_update_full_with_pre_image","mongodb.connection.string":h.uri,"collection.include.list":n,"snapshot.mode":"always"})?{done:!0,value:!0}:(await r.findOneAndUpdate(p,{$set:{colName:f}},{upsert:!0}),await r.findOneAndDelete(p),c.get().log.warn(`Waiting for db changes for ${n} to start...`),{done:!1}),6,1e4).catch(e=>c.crash(new D("Failed to start db changes",{dbColName:n},e))))},10)}}const b=a=>{try{return new y(a)}catch{return a}};export{z as MongoDbChange};
2
2
  //# sourceMappingURL=changes.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'when_needed',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"],"mappings":"AAAA,OAA6B,YAAAA,MAAgB,UAC7C,OAAS,UAAAC,MAAc,WAEvB,OAAS,iBAAAC,MAAqB,eAC9B,OAAS,YAAAC,MAAgB,iBACzB,OAAS,SAAAC,MAAa,kBACtB,OAAS,YAAAC,EAAU,eAAAC,MAAmB,kBAK/B,MAAMC,UAA6FF,CAAwB,CACjIG,GAAW,GAEX,YACCC,EACAC,EACAC,EACAC,EACAC,EACC,CACD,MAAMH,EAAQE,EAAWC,CAAM,EAE/B,MAAMC,E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,4CAChB,4BAA6BX,EAAO,IACpC,0BAA2BU,EAC3B,gBAAiB,aAClB,CAAC,EAEmB,CAAE,KAAM,GAAM,MAAO,EAAK,GAC9C,MAAMR,EAAW,iBAAiBW,EAAW,CAAE,KAAM,CAAE,QAAAJ,CAAQ,CAAS,EAAG,CAAE,OAAQ,EAAK,CAAC,EAC3F,MAAMP,EAAW,iBAAiBW,CAAS,EAC3CnB,EAAS,IAAI,EAAE,IAAI,KAAK,8BAA8BgB,CAAS,cAAc,EACtE,CAAE,KAAM,EAAM,GAEtB,EACA,GACD,EAAE,MAAOO,GAAQvB,EAAS,MAAM,IAAID,EAAc,6BAA8B,CAAE,UAAAiB,CAAU,EAAGO,CAAG,CAAC,CAAC,EACrG,EACA,EACD,CACD,CACD,CAQA,MAAMV,EAAUW,GAAe,CAC9B,GAAI,CACH,OAAO,IAAI3B,EAAS2B,CAAE,CACvB,MAAQ,CACP,OAAOA,CACR,CACD","names":["ObjectId","differ","EquippedError","Instance","retry","DbChange","TopicPrefix","MongoDbChange","#started","config","change","collection","callbacks","mapper","hydrate","data","makeId","dbName","colName","dbColName","topic","TestId","condition","op","before","after","err","id"]}
1
+ {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'always',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"],"mappings":"AAAA,OAA6B,YAAAA,MAAgB,UAC7C,OAAS,UAAAC,MAAc,WAEvB,OAAS,iBAAAC,MAAqB,eAC9B,OAAS,YAAAC,MAAgB,iBACzB,OAAS,SAAAC,MAAa,kBACtB,OAAS,YAAAC,EAAU,eAAAC,MAAmB,kBAK/B,MAAMC,UAA6FF,CAAwB,CACjIG,GAAW,GAEX,YACCC,EACAC,EACAC,EACAC,EACAC,EACC,CACD,MAAMH,EAAQE,EAAWC,CAAM,EAE/B,MAAMC,EAAWC,GAChBA,EAAK,IACF,CACA,GAAGA,EACH,IAAKC,EAAOD,EAAK,IAAI,MAAWA,EAAK,GAAG,CACzC,EACC,OAEEE,EAASN,EAAW,OACpBO,EAAUP,EAAW,eACrBQ,EAAY,GAAGF,CAA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AJ,CAAQ,CAAS,EAAG,CAAE,OAAQ,EAAK,CAAC,EAC3F,MAAMP,EAAW,iBAAiBW,CAAS,EAC3CnB,EAAS,IAAI,EAAE,IAAI,KAAK,8BAA8BgB,CAAS,cAAc,EACtE,CAAE,KAAM,EAAM,GAEtB,EACA,GACD,EAAE,MAAOO,GAAQvB,EAAS,MAAM,IAAID,EAAc,6BAA8B,CAAE,UAAAiB,CAAU,EAAGO,CAAG,CAAC,CAAC,EACrG,EACA,EACD,CACD,CACD,CAQA,MAAMV,EAAUW,GAAe,CAC9B,GAAI,CACH,OAAO,IAAI3B,EAAS2B,CAAE,CACvB,MAAQ,CACP,OAAOA,CACR,CACD","names":["ObjectId","differ","EquippedError","Instance","retry","DbChange","TopicPrefix","MongoDbChange","#started","config","change","collection","callbacks","mapper","hydrate","data","makeId","dbName","colName","dbColName","topic","TestId","condition","op","before","after","err","id"]}
@@ -55,7 +55,7 @@ class MongoDbChange extends DbChange {
55
55
  "capture.mode": "change_streams_update_full_with_pre_image",
56
56
  "mongodb.connection.string": config.uri,
57
57
  "collection.include.list": dbColName,
58
- "snapshot.mode": "when_needed"
58
+ "snapshot.mode": "always"
59
59
  });
60
60
  if (started) return { done: true, value: true };
61
61
  await collection.findOneAndUpdate(condition, { $set: { colName } }, { upsert: true });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'when_needed',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"],"mappings":"AAAA,SAA6B,gBAAgB;AAC7C,SAAS,cAAc;AAEvB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAS,UAAU,mBAAmB;AAK/B,MAAM,sBAA6F,SAAwB;AAAA,EACjI,WAAW;AAAA,EAEX,YACC,QACA,QACA,YACA,WACA,QACC;AACD,UAAM,QAAQ,WAAW,MAAM;AAE/B,UAAM,UAAU,CAAC,SAChB,KAAK,MACF;AAAA,MACA,GAAG;AAAA,MACH,KAAK,OAAO,KAAK,IAAI,MAAM,KAAK,KAAK,GAAG;AAAA,I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BAAM,UAAU,MAAM,KAAK,mBAAmB,OAAO;AAAA,cACpD,mBAAmB;AAAA,cACnB,gBAAgB;AAAA,cAChB,6BAA6B,OAAO;AAAA,cACpC,2BAA2B;AAAA,cAC3B,iBAAiB;AAAA,YAClB,CAAC;AAED,gBAAI,QAAS,QAAO,EAAE,MAAM,MAAM,OAAO,KAAK;AAC9C,kBAAM,WAAW,iBAAiB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAS,GAAG,EAAE,QAAQ,KAAK,CAAC;AAC3F,kBAAM,WAAW,iBAAiB,SAAS;AAC3C,qBAAS,IAAI,EAAE,IAAI,KAAK,8BAA8B,SAAS,cAAc;AAC7E,mBAAO,EAAE,MAAM,MAAM;AAAA,UACtB;AAAA,UACA;AAAA,UACA;AAAA,QACD,EAAE,MAAM,CAAC,QAAQ,SAAS,MAAM,IAAI,cAAc,8BAA8B,EAAE,UAAU,GAAG,GAAG,CAAC,CAAC;AAAA,MACrG;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;AAQA,MAAM,SAAS,CAAC,OAAe;AAC9B,MAAI;AACH,WAAO,IAAI,SAAS,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/dbs/mongo/changes.ts"],"sourcesContent":["import { Collection, Filter, ObjectId } from 'mongodb'\nimport { differ } from 'valleyed'\n\nimport { EquippedError } from '../../errors'\nimport { Instance } from '../../instance'\nimport { retry } from '../../utilities'\nimport { DbChange, TopicPrefix } from '../base/changes'\nimport * as core from '../base/core'\nimport { DbChangeConfig } from '../base/types'\nimport { MongoDbConfig } from '../pipes'\n\nexport class MongoDbChange<Model extends core.Model<{ _id: string }>, Entity extends core.Entity> extends DbChange<Model, Entity> {\n\t#started = false\n\n\tconstructor(\n\t\tconfig: MongoDbConfig,\n\t\tchange: DbChangeConfig,\n\t\tcollection: Collection<Model>,\n\t\tcallbacks: core.DbChangeCallbacks<Model, Entity>,\n\t\tmapper: (model: Model) => Entity,\n\t) {\n\t\tsuper(change, callbacks, mapper)\n\n\t\tconst hydrate = (data: any) =>\n\t\t\tdata._id\n\t\t\t\t? {\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t_id: makeId(data._id['$oid'] ?? data._id),\n\t\t\t\t\t}\n\t\t\t\t: undefined\n\n\t\tconst dbName = collection.dbName\n\t\tconst colName = collection.collectionName\n\t\tconst dbColName = `${dbName}.${colName}`\n\t\tconst topic = `${TopicPrefix}.${dbColName}`\n\n\t\tconst hexId = '5f5f65717569707065645f5f' // __equipped__\n\t\tconst TestId = makeId(hexId)\n\t\tconst condition = { _id: TestId } as Filter<Model>\n\n\t\tchange.eventBus.createStream(topic as never, { skipScope: true }).subscribe(async (data: DbDocumentChange) => {\n\t\t\tconst op = data.op\n\n\t\t\tlet before = JSON.parse(data.before ?? 'null')\n\t\t\tlet after = JSON.parse(data.after ?? 'null')\n\n\t\t\tif (before) before = hydrate(before)\n\t\t\tif (after) after = hydrate(after)\n\t\t\tif (before?.__id === TestId || after?.__id === TestId) return\n\n\t\t\tif (op === 'c' && this.callbacks.created && after)\n\t\t\t\tawait this.callbacks.created({\n\t\t\t\t\tbefore: null,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t})\n\t\t\telse if (op === 'u' && this.callbacks.updated && before && after)\n\t\t\t\tawait this.callbacks.updated({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: this.mapper(after)!,\n\t\t\t\t\tchanges: differ.from(differ.diff(before, after)),\n\t\t\t\t})\n\t\t\telse if (op === 'd' && this.callbacks.deleted && before)\n\t\t\t\tawait this.callbacks.deleted({\n\t\t\t\t\tbefore: this.mapper(before)!,\n\t\t\t\t\tafter: null,\n\t\t\t\t})\n\t\t})\n\n\t\tInstance.on(\n\t\t\t'start',\n\t\t\tasync () => {\n\t\t\t\tif (this.#started) return\n\t\t\t\tthis.#started = true\n\n\t\t\t\tawait retry(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = await this.configureConnector(topic, {\n\t\t\t\t\t\t\t'connector.class': 'io.debezium.connector.mongodb.MongoDbConnector',\n\t\t\t\t\t\t\t'capture.mode': 'change_streams_update_full_with_pre_image',\n\t\t\t\t\t\t\t'mongodb.connection.string': config.uri,\n\t\t\t\t\t\t\t'collection.include.list': dbColName,\n\t\t\t\t\t\t\t'snapshot.mode': 'always',\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (started) return { done: true, value: true }\n\t\t\t\t\t\tawait collection.findOneAndUpdate(condition, { $set: { colName } as any }, { upsert: true })\n\t\t\t\t\t\tawait collection.findOneAndDelete(condition)\n\t\t\t\t\t\tInstance.get().log.warn(`Waiting for db changes for ${dbColName} to start...`)\n\t\t\t\t\t\treturn { done: false }\n\t\t\t\t\t},\n\t\t\t\t\t6,\n\t\t\t\t\t10_000,\n\t\t\t\t).catch((err) => Instance.crash(new EquippedError(`Failed to start db changes`, { dbColName }, err)))\n\t\t\t},\n\t\t\t10,\n\t\t)\n\t}\n}\n\ntype DbDocumentChange = {\n\tbefore: string | null\n\tafter: string | null\n\top: 'c' | 'u' | 'd'\n}\n\nconst makeId = (id: string) => {\n\ttry {\n\t\treturn new ObjectId(id)\n\t} catch {\n\t\treturn id\n\t}\n}\n"],"mappings":"AAAA,SAA6B,gBAAgB;AAC7C,SAAS,cAAc;AAEvB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAS,UAAU,mBAAmB;AAK/B,MAAM,sBAA6F,SAAwB;AAAA,EACjI,WAAW;AAAA,EAEX,YACC,QACA,QACA,YACA,WACA,QACC;AACD,UAAM,QAAQ,WAAW,MAAM;AAE/B,UAAM,UAAU,CAAC,SAChB,KAAK,MACF;AAAA,MACA,GAAG;AAAA,MACH,KAAK,OAAO,KAAK,IAAI,MAAM,KAAK,KAAK,GAAG;AAAA,IACzC,IACC;AAEJ,UAAM,SAAS,WAAW;AAC1B,UAAM,UAAU,WAAW;AA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A,cACnB,gBAAgB;AAAA,cAChB,6BAA6B,OAAO;AAAA,cACpC,2BAA2B;AAAA,cAC3B,iBAAiB;AAAA,YAClB,CAAC;AAED,gBAAI,QAAS,QAAO,EAAE,MAAM,MAAM,OAAO,KAAK;AAC9C,kBAAM,WAAW,iBAAiB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAS,GAAG,EAAE,QAAQ,KAAK,CAAC;AAC3F,kBAAM,WAAW,iBAAiB,SAAS;AAC3C,qBAAS,IAAI,EAAE,IAAI,KAAK,8BAA8B,SAAS,cAAc;AAC7E,mBAAO,EAAE,MAAM,MAAM;AAAA,UACtB;AAAA,UACA;AAAA,UACA;AAAA,QACD,EAAE,MAAM,CAAC,QAAQ,SAAS,MAAM,IAAI,cAAc,8BAA8B,EAAE,UAAU,GAAG,GAAG,CAAC,CAAC;AAAA,MACrG;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;AAQA,MAAM,SAAS,CAAC,OAAe;AAC9B,MAAI;AACH,WAAO,IAAI,SAAS,EAAE;AAAA,EACvB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -55,7 +55,7 @@ class MongoDbChange extends DbChange {
55
55
  "capture.mode": "change_streams_update_full_with_pre_image",
56
56
  "mongodb.connection.string": config.uri,
57
57
  "collection.include.list": dbColName,
58
- "snapshot.mode": "when_needed"
58
+ "snapshot.mode": "always"
59
59
  });
60
60
  if (started) return { done: true, value: true };
61
61
  await collection.findOneAndUpdate(condition, { $set: { colName } }, { upsert: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "equipped",
3
- "version": "5.0.28",
3
+ "version": "5.0.29",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "type": "module",