@entifix/mongo 0.23.16 → 0.23.18
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/adapters/make-mongo-repository.d.ts +11 -0
- package/dist/adapters/make-mongo-repository.d.ts.map +1 -1
- package/dist/adapters/make-mongo-repository.js +9 -0
- package/dist/adapters/make-mongo-repository.js.map +1 -1
- package/dist/errors/translate-mongo-error.d.ts +7 -0
- package/dist/errors/translate-mongo-error.d.ts.map +1 -1
- package/dist/errors/translate-mongo-error.js +10 -0
- package/dist/errors/translate-mongo-error.js.map +1 -1
- package/dist/transactions/index.d.ts +1 -1
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +1 -1
- package/dist/transactions/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { EntityRepository } from '@entifix/business';
|
|
2
2
|
import { Entity, EntityConstructor, type UniqueMember } from '@entifix/core';
|
|
3
|
+
import { Effect } from 'effect';
|
|
3
4
|
import type { ClientSession, Db } from 'mongodb';
|
|
4
5
|
/** The collection an entity's records live in: its `key`, else its class name. */
|
|
5
6
|
export declare function mongoCollectionName<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>): string;
|
|
6
7
|
/** The index a unique member is held to: named for the member, partial. */
|
|
7
8
|
export declare const uniqueIndexName: (member: UniqueMember) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Make sure the indexes an entity's repository holds its writes to exist in
|
|
11
|
+
* `db`: the unique one on `id`, and one per member declared `unique`
|
|
12
|
+
* (ADR 0034). The repository does this itself before a write; a cell that
|
|
13
|
+
* writes an entity's documents through the driver, inside a unit of work,
|
|
14
|
+
* calls it first, or a fresh database enforces no uniqueness until the first
|
|
15
|
+
* repository write happens to arrive. Ensured once per database and
|
|
16
|
+
* collection, shared with the repository.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ensureEntityIndexes: <TEntity extends Entity>(db: Db, entityConstructor: EntityConstructor<TEntity>) => Effect.Effect<void, import("@entifix/core").StoreFailure, never>;
|
|
8
19
|
/**
|
|
9
20
|
* Builds an {@link EntityRepository} for a single entity type, backed by a live
|
|
10
21
|
* mongodb {@link Db}. The `db` and `entityConstructor` are captured in closures,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-mongo-repository.d.ts","sourceRoot":"","sources":["../../src/adapters/make-mongo-repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAIL,MAAM,EACN,iBAAiB,EAejB,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"make-mongo-repository.d.ts","sourceRoot":"","sources":["../../src/adapters/make-mongo-repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAIL,MAAM,EACN,iBAAiB,EAejB,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAajD,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,MAAM,CAGR;AAaD,2EAA2E;AAC3E,eAAO,MAAM,eAAe,GAAI,QAAQ,YAAY,KAAG,MAC/B,CAAC;AAgCzB;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,SAAS,MAAM,EACxD,IAAI,EAAE,EACN,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,qEAM5C,CAAC;AAQJ;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,EAAE,EAAE,EAAE,EACN,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAA;CAAE,GAC7C,gBAAgB,CAmSlB"}
|
|
@@ -56,6 +56,15 @@ const ensureIndexes = (db, name, uniques)=>Effect.suspend(()=>{
|
|
|
56
56
|
catch: (error)=>translateMongoError(error)
|
|
57
57
|
}).pipe(Effect.tap(()=>Effect.sync(()=>ensured.add(name))));
|
|
58
58
|
});
|
|
59
|
+
/**
|
|
60
|
+
* Make sure the indexes an entity's repository holds its writes to exist in
|
|
61
|
+
* `db`: the unique one on `id`, and one per member declared `unique`
|
|
62
|
+
* (ADR 0034). The repository does this itself before a write; a cell that
|
|
63
|
+
* writes an entity's documents through the driver, inside a unit of work,
|
|
64
|
+
* calls it first, or a fresh database enforces no uniqueness until the first
|
|
65
|
+
* repository write happens to arrive. Ensured once per database and
|
|
66
|
+
* collection, shared with the repository.
|
|
67
|
+
*/ export const ensureEntityIndexes = (db, entityConstructor)=>ensureIndexes(db, mongoCollectionName(entityConstructor), uniqueMembersOf(entityConstructor));
|
|
59
68
|
function toEntityId(entityOrId) {
|
|
60
69
|
return entityOrId != null && typeof entityOrId === 'object' ? entityOrId.id : entityOrId;
|
|
61
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/make-mongo-repository.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { EntityRepository, EntityWriteOptions } from '@entifix/business';\nimport {\n declaresRevision,\n deserializeEntityCollection,\n deserializeSingleEntity,\n Entity,\n EntityConstructor,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n extractMetaEntity,\n holdsStoredState,\n NotFound,\n readRevision,\n relevanceLabelKey,\n relevanceTerms,\n serializeEntity,\n StaleRevision,\n type StoredStateCondition,\n storedStateCondition,\n unavailableInState,\n type UniqueMember,\n uniqueMembersOf,\n} from '@entifix/core';\nimport { Effect } from 'effect';\nimport type { ClientSession, Db } from 'mongodb';\n\nimport { translateMongoError } from '../errors/translate-mongo-error.js';\nimport {\n RELEVANCE_FIELD,\n relevanceExpression,\n translateFiltering,\n translateSorting,\n} from './filter-translator.js';\n\n/** Projection that drops Mongo's internal `_id` from read results. */\nconst WITHOUT_MONGO_ID = { projection: { _id: 0 } } as const;\n\n/** The collection an entity's records live in: its `key`, else its class name. */\nexport function mongoCollectionName<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): string {\n const metaEntity = extractMetaEntity(entityConstructor);\n return metaEntity.key ?? metaEntity.name;\n}\n\n/**\n * The collections whose unique indexes are known to exist, per database: the\n * one on `id`, and one per member the entity declares `unique` (ADR 0034).\n *\n * A create is atomic only against an index: two concurrent creates of one\n * client-minted id — or of one vendor's code — would otherwise both insert.\n * Keyed on the `Db` so a fake or a reset database starts clean, and a rejected\n * attempt is forgotten so the next write tries again.\n */\nconst ensuredIndexes = new WeakMap<Db, Set<string>>();\n\n/** The index a unique member is held to: named for the member, partial. */\nexport const uniqueIndexName = (member: UniqueMember): string =>\n `unique_${member.key}`;\n\nconst ensureIndexes = (\n db: Db,\n name: string,\n uniques: readonly UniqueMember[],\n) =>\n Effect.suspend(() => {\n const ensured = ensuredIndexes.get(db) ?? new Set<string>();\n ensuredIndexes.set(db, ensured);\n if (ensured.has(name)) return Effect.void;\n const collection = db.collection(name);\n return Effect.tryPromise({\n try: async () => {\n await collection.createIndex({ id: 1 }, { unique: true });\n // Partial over the documents that hold a value of the member's type,\n // so an optional member left empty never collides with another.\n for (const member of uniques) {\n await collection.createIndex(\n { [member.key]: 1 },\n {\n unique: true,\n name: uniqueIndexName(member),\n partialFilterExpression: { [member.key]: { $type: member.type } },\n },\n );\n }\n },\n catch: error => translateMongoError(error),\n }).pipe(Effect.tap(() => Effect.sync(() => ensured.add(name))));\n });\n\nfunction toEntityId(entityOrId: EntityId | Entity): EntityId {\n return entityOrId != null && typeof entityOrId === 'object'\n ? (entityOrId as Entity).id\n : (entityOrId as EntityId);\n}\n\n/**\n * Builds an {@link EntityRepository} for a single entity type, backed by a live\n * mongodb {@link Db}. The `db` and `entityConstructor` are captured in closures,\n * so every method's Effect has no outstanding requirements (`R = never`), which\n * is exactly what the interface asks.\n *\n * Collection name = the entity's `key` (falling back to its class name). Reads\n * reuse the shared entifix deserializer (rebuilding links from embedded objects\n * or scalar FKs); writes reuse the shared serializer. Mongo failures surface as\n * categorised failures — `NotFound`, `DuplicateKey`, `Unavailable` and the\n * rest — through `translateMongoError`.\n *\n * This is the Mongo mirror of the REST `buildEntityRestAdapter*` builders.\n *\n * Pass `session` to make the repository part of a transaction — a unit of\n * work's handle — so its writes commit with the unit and its reads see what the\n * unit has already written.\n */\nexport function makeMongoRepository<TEntity extends Entity>(\n db: Db,\n entityConstructor: EntityConstructor<TEntity>,\n options?: { readonly session?: ClientSession },\n): EntityRepository {\n const collectionName = mongoCollectionName(entityConstructor);\n const collection = db.collection(collectionName);\n const uniques = uniqueMembersOf(entityConstructor);\n // Every write is held to the unique members' indexes, not only a create: an\n // update onto another record's value collides exactly as a create does.\n const indexed =\n uniques.length === 0\n ? Effect.void\n : ensureIndexes(db, collectionName, uniques);\n // Spread into every call, so a repository with no session passes none.\n const inSession = options?.session ? { session: options.session } : {};\n\n const load = <T extends Entity>(request: EntityLoadRequest<T>) =>\n Effect.gen(function* () {\n const filter = translateFiltering(request.filtering);\n const sort = translateSorting(request.sorting);\n const page = request.page ?? 1;\n const pageSize = request.pageSize ?? 10;\n const skip = (page - 1) * pageSize;\n\n // A relevance order is a field computed from the request's own words,\n // which a `find` cannot sort by: the same page through a pipeline\n // (ADR 0033).\n const docs = yield* Effect.tryPromise({\n try: () =>\n RELEVANCE_FIELD in sort\n ? collection\n .aggregate(\n [\n { $match: filter },\n {\n $addFields: {\n [RELEVANCE_FIELD]: relevanceExpression(\n relevanceLabelKey(entityConstructor),\n relevanceTerms(request.filtering),\n ),\n },\n },\n { $sort: sort },\n { $skip: skip },\n { $limit: pageSize },\n { $project: { _id: 0, [RELEVANCE_FIELD]: 0 } },\n ],\n inSession,\n )\n .toArray()\n : collection\n .find(filter, { ...WITHOUT_MONGO_ID, ...inSession })\n .sort(sort)\n .skip(skip)\n .limit(pageSize)\n .toArray(),\n catch: error => translateMongoError(error),\n });\n const total = yield* Effect.tryPromise({\n try: () => collection.countDocuments(filter, inSession),\n catch: error => translateMongoError(error),\n });\n\n const items = yield* deserializeEntityCollection(entityConstructor, docs);\n\n return {\n items: items as unknown as T[],\n total,\n request,\n } satisfies EntityPage<T>;\n });\n\n const get = <T extends Entity>(id: EntityId) =>\n Effect.gen(function* () {\n const doc = yield* Effect.tryPromise({\n try: () =>\n collection.findOne({ id }, { ...WITHOUT_MONGO_ID, ...inSession }),\n catch: error => translateMongoError(error),\n });\n const entity = yield* deserializeSingleEntity(entityConstructor, doc);\n if (entity === undefined) {\n return yield* Effect.fail(\n new NotFound({ entity: extractMetaEntity(entityConstructor).key }),\n );\n }\n return entity as unknown as T;\n });\n\n const revised = declaresRevision(entityConstructor);\n\n /** The `expect` of a write, resolved to the field the store holds it under. */\n const conditionOf = (\n options: EntityWriteOptions | undefined,\n ): StoredStateCondition | undefined =>\n options?.expect === undefined\n ? undefined\n : storedStateCondition(entityConstructor, options.expect);\n\n /** The filter clause a condition adds to a write. */\n const stateFilter = (condition: StoredStateCondition | undefined) =>\n condition === undefined\n ? {}\n : { [condition.key]: { $in: [...condition.in] } };\n\n /** What a write that matched nothing reads back, only to name the refusal. */\n const readBack = (id: EntityId, condition?: StoredStateCondition) =>\n Effect.tryPromise({\n try: () =>\n collection.findOne(\n { id },\n {\n projection: {\n _id: 0,\n revision: 1,\n ...(condition === undefined ? {} : { [condition.key]: 1 }),\n },\n ...inSession,\n },\n ),\n catch: error => translateMongoError(error),\n });\n\n /**\n * A save of an entity that declares a revision (ADR 0032): a create that\n * never overwrites, or one conditional write on the revision the caller read.\n * Never a read followed by a write — two saves would both read `n`.\n */\n const saveRevised = <T extends Entity>(\n entity: T,\n condition: StoredStateCondition | undefined,\n ) =>\n Effect.gen(function* () {\n const key = extractMetaEntity(entityConstructor).key;\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n const read = readRevision(entity);\n const id = entity.id ?? randomUUID();\n if (read === undefined) {\n yield* ensureIndexes(db, collectionName, uniques);\n yield* Effect.tryPromise({\n try: () =>\n collection.insertOne({ ...doc, id, revision: 1 }, inSession),\n catch: error => translateMongoError(error),\n }).pipe(\n // Only the identity's index means \"someone created it first\"; a\n // unique member's names the member, which a form shows on the field.\n Effect.mapError(failure =>\n failure._tag === 'DuplicateKey' && failure.key === 'id'\n ? new StaleRevision({ entity: key })\n : failure,\n ),\n );\n entity.id = id;\n (entity as { revision?: number }).revision = 1;\n return entity;\n }\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.replaceOne(\n { id, revision: read, ...stateFilter(condition) },\n { ...doc, id, revision: read + 1 },\n inSession,\n ),\n catch: error => translateMongoError(error),\n });\n if (result.matchedCount === 0) {\n // The write already decided; this read only names the refusal. A\n // record in another state is refused for its state before its\n // revision: a fresher read would not make the save legal.\n const stored = yield* readBack(id, condition);\n if (stored === null) return yield* new NotFound({ entity: key });\n if (condition !== undefined && !holdsStoredState(condition, stored)) {\n return yield* unavailableInState(\n entityConstructor,\n condition,\n stored,\n );\n }\n return yield* Effect.fail(\n new StaleRevision({\n entity: key,\n current: readRevision(stored),\n }),\n );\n }\n entity.id = id;\n (entity as { revision?: number }).revision = read + 1;\n return entity;\n });\n\n const save = <T extends Entity>(entity: T, options?: EntityWriteOptions) => {\n const condition = conditionOf(options);\n const write = revised\n ? saveRevised(entity, condition)\n : condition === undefined\n ? saveUnchecked(entity)\n : saveConditioned(entity, condition);\n return Effect.andThen(indexed, write);\n };\n\n /**\n * An update of a record that declares no revision, on the states it must\n * hold: one `replaceOne` on the id and the state, never an upsert — a save\n * with `expect` is an update of a stored record.\n */\n const saveConditioned = <T extends Entity>(\n entity: T,\n condition: StoredStateCondition,\n ) =>\n Effect.gen(function* () {\n const key = extractMetaEntity(entityConstructor).key;\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n const id = entity.id;\n if (id === undefined) return yield* new NotFound({ entity: key });\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.replaceOne(\n { id, ...stateFilter(condition) },\n { ...doc, id },\n inSession,\n ),\n catch: error => translateMongoError(error),\n });\n if (result.matchedCount === 0) {\n const stored = yield* readBack(id, condition);\n return yield* stored === null\n ? Effect.fail(new NotFound({ entity: key }))\n : Effect.fail(\n unavailableInState(entityConstructor, condition, stored),\n );\n }\n return entity;\n });\n\n const saveUnchecked = <T extends Entity>(entity: T) =>\n Effect.gen(function* () {\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n // A create arrives without an id, so the store mints one. Entities are\n // addressed by their own `id` field (never Mongo's `_id`, which reads\n // project away), so an inserted document without one would be\n // unreachable by `get` and by any later `replaceOne`.\n const id = entity.id ?? randomUUID();\n yield* Effect.tryPromise({\n // `doc` omits `id` when it was undefined (the serializer drops\n // undefined), hence spreading the resolved id back in.\n try: () =>\n collection.replaceOne(\n { id },\n { ...doc, id },\n { upsert: true, ...inSession },\n ),\n catch: error => translateMongoError(error),\n });\n entity.id = id;\n return entity;\n });\n\n const del = <T extends Entity>(\n entityOrId: EntityId | T,\n options?: EntityWriteOptions,\n ) =>\n Effect.gen(function* () {\n const id = toEntityId(entityOrId);\n const condition = conditionOf(options);\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.deleteOne({ id, ...stateFilter(condition) }, inSession),\n catch: error => translateMongoError(error),\n });\n if (condition === undefined || result.deletedCount > 0) return;\n // Nothing deleted: either nothing was there, which a delete accepts,\n // or the record is in a state it may not be deleted from.\n const stored = yield* readBack(id, condition);\n if (stored !== null) {\n return yield* unavailableInState(entityConstructor, condition, stored);\n }\n });\n\n // Cast through the interface to keep its generic signatures: each method here\n // is written against this entity's type, the interface against any entity's.\n return {\n load,\n get,\n save,\n delete: del,\n } as unknown as EntityRepository;\n}\n"],"names":["randomUUID","declaresRevision","deserializeEntityCollection","deserializeSingleEntity","extractMetaEntity","holdsStoredState","NotFound","readRevision","relevanceLabelKey","relevanceTerms","serializeEntity","StaleRevision","storedStateCondition","unavailableInState","uniqueMembersOf","Effect","translateMongoError","RELEVANCE_FIELD","relevanceExpression","translateFiltering","translateSorting","WITHOUT_MONGO_ID","projection","_id","mongoCollectionName","entityConstructor","metaEntity","key","name","ensuredIndexes","WeakMap","uniqueIndexName","member","ensureIndexes","db","uniques","suspend","ensured","get","Set","set","has","void","collection","tryPromise","try","createIndex","id","unique","partialFilterExpression","$type","type","catch","error","pipe","tap","sync","add","toEntityId","entityOrId","makeMongoRepository","options","collectionName","indexed","length","inSession","session","load","request","gen","filter","filtering","sort","sorting","page","pageSize","skip","docs","aggregate","$match","$addFields","$sort","$skip","$limit","$project","toArray","find","limit","total","countDocuments","items","doc","findOne","entity","undefined","fail","revised","conditionOf","expect","stateFilter","condition","$in","in","readBack","revision","saveRevised","read","insertOne","mapError","failure","_tag","result","replaceOne","matchedCount","stored","current","save","write","saveUnchecked","saveConditioned","andThen","upsert","del","deleteOne","deletedCount","delete"],"mappings":";AAAA,SAASA,UAAU,QAAQ,cAAc;AAGzC,SACEC,gBAAgB,EAChBC,2BAA2B,EAC3BC,uBAAuB,EAMvBC,iBAAiB,EACjBC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,EACZC,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,aAAa,EAEbC,oBAAoB,EACpBC,kBAAkB,EAElBC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAGhC,SAASC,mBAAmB,QAAQ,qCAAqC;AACzE,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,gBAAgB,QACX,yBAAyB;AAEhC,oEAAoE,GACpE,MAAMC,mBAAmB;IAAEC,YAAY;QAAEC,KAAK;IAAE;AAAE;AAEl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cAAcN,aAAaiB,OAAOa,YAAY,GAAG,GAAG;YACxD,qEAAqE;YACrE,0DAA0D;YAC1D,MAAMV,SAAS,OAAOX,SAASxD,IAAIqD;YACnC,IAAIc,WAAW,MAAM;gBACnB,OAAO,OAAOrG,mBAAmBY,mBAAmB2E,WAAWc;YACjE;QACF;IAEF,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO;QACL/C;QACA7B;QACA8E;QACAS,QAAQH;IACV;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/make-mongo-repository.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { EntityRepository, EntityWriteOptions } from '@entifix/business';\nimport {\n declaresRevision,\n deserializeEntityCollection,\n deserializeSingleEntity,\n Entity,\n EntityConstructor,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n extractMetaEntity,\n holdsStoredState,\n NotFound,\n readRevision,\n relevanceLabelKey,\n relevanceTerms,\n serializeEntity,\n StaleRevision,\n type StoredStateCondition,\n storedStateCondition,\n unavailableInState,\n type UniqueMember,\n uniqueMembersOf,\n} from '@entifix/core';\nimport { Effect } from 'effect';\nimport type { ClientSession, Db } from 'mongodb';\n\nimport { translateMongoError } from '../errors/translate-mongo-error.js';\nimport {\n RELEVANCE_FIELD,\n relevanceExpression,\n translateFiltering,\n translateSorting,\n} from './filter-translator.js';\n\n/** Projection that drops Mongo's internal `_id` from read results. */\nconst WITHOUT_MONGO_ID = { projection: { _id: 0 } } as const;\n\n/** The collection an entity's records live in: its `key`, else its class name. */\nexport function mongoCollectionName<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): string {\n const metaEntity = extractMetaEntity(entityConstructor);\n return metaEntity.key ?? metaEntity.name;\n}\n\n/**\n * The collections whose unique indexes are known to exist, per database: the\n * one on `id`, and one per member the entity declares `unique` (ADR 0034).\n *\n * A create is atomic only against an index: two concurrent creates of one\n * client-minted id — or of one vendor's code — would otherwise both insert.\n * Keyed on the `Db` so a fake or a reset database starts clean, and a rejected\n * attempt is forgotten so the next write tries again.\n */\nconst ensuredIndexes = new WeakMap<Db, Set<string>>();\n\n/** The index a unique member is held to: named for the member, partial. */\nexport const uniqueIndexName = (member: UniqueMember): string =>\n `unique_${member.key}`;\n\nconst ensureIndexes = (\n db: Db,\n name: string,\n uniques: readonly UniqueMember[],\n) =>\n Effect.suspend(() => {\n const ensured = ensuredIndexes.get(db) ?? new Set<string>();\n ensuredIndexes.set(db, ensured);\n if (ensured.has(name)) return Effect.void;\n const collection = db.collection(name);\n return Effect.tryPromise({\n try: async () => {\n await collection.createIndex({ id: 1 }, { unique: true });\n // Partial over the documents that hold a value of the member's type,\n // so an optional member left empty never collides with another.\n for (const member of uniques) {\n await collection.createIndex(\n { [member.key]: 1 },\n {\n unique: true,\n name: uniqueIndexName(member),\n partialFilterExpression: { [member.key]: { $type: member.type } },\n },\n );\n }\n },\n catch: error => translateMongoError(error),\n }).pipe(Effect.tap(() => Effect.sync(() => ensured.add(name))));\n });\n\n/**\n * Make sure the indexes an entity's repository holds its writes to exist in\n * `db`: the unique one on `id`, and one per member declared `unique`\n * (ADR 0034). The repository does this itself before a write; a cell that\n * writes an entity's documents through the driver, inside a unit of work,\n * calls it first, or a fresh database enforces no uniqueness until the first\n * repository write happens to arrive. Ensured once per database and\n * collection, shared with the repository.\n */\nexport const ensureEntityIndexes = <TEntity extends Entity>(\n db: Db,\n entityConstructor: EntityConstructor<TEntity>,\n) =>\n ensureIndexes(\n db,\n mongoCollectionName(entityConstructor),\n uniqueMembersOf(entityConstructor),\n );\n\nfunction toEntityId(entityOrId: EntityId | Entity): EntityId {\n return entityOrId != null && typeof entityOrId === 'object'\n ? (entityOrId as Entity).id\n : (entityOrId as EntityId);\n}\n\n/**\n * Builds an {@link EntityRepository} for a single entity type, backed by a live\n * mongodb {@link Db}. The `db` and `entityConstructor` are captured in closures,\n * so every method's Effect has no outstanding requirements (`R = never`), which\n * is exactly what the interface asks.\n *\n * Collection name = the entity's `key` (falling back to its class name). Reads\n * reuse the shared entifix deserializer (rebuilding links from embedded objects\n * or scalar FKs); writes reuse the shared serializer. Mongo failures surface as\n * categorised failures — `NotFound`, `DuplicateKey`, `Unavailable` and the\n * rest — through `translateMongoError`.\n *\n * This is the Mongo mirror of the REST `buildEntityRestAdapter*` builders.\n *\n * Pass `session` to make the repository part of a transaction — a unit of\n * work's handle — so its writes commit with the unit and its reads see what the\n * unit has already written.\n */\nexport function makeMongoRepository<TEntity extends Entity>(\n db: Db,\n entityConstructor: EntityConstructor<TEntity>,\n options?: { readonly session?: ClientSession },\n): EntityRepository {\n const collectionName = mongoCollectionName(entityConstructor);\n const collection = db.collection(collectionName);\n const uniques = uniqueMembersOf(entityConstructor);\n // Every write is held to the unique members' indexes, not only a create: an\n // update onto another record's value collides exactly as a create does.\n const indexed =\n uniques.length === 0\n ? Effect.void\n : ensureIndexes(db, collectionName, uniques);\n // Spread into every call, so a repository with no session passes none.\n const inSession = options?.session ? { session: options.session } : {};\n\n const load = <T extends Entity>(request: EntityLoadRequest<T>) =>\n Effect.gen(function* () {\n const filter = translateFiltering(request.filtering);\n const sort = translateSorting(request.sorting);\n const page = request.page ?? 1;\n const pageSize = request.pageSize ?? 10;\n const skip = (page - 1) * pageSize;\n\n // A relevance order is a field computed from the request's own words,\n // which a `find` cannot sort by: the same page through a pipeline\n // (ADR 0033).\n const docs = yield* Effect.tryPromise({\n try: () =>\n RELEVANCE_FIELD in sort\n ? collection\n .aggregate(\n [\n { $match: filter },\n {\n $addFields: {\n [RELEVANCE_FIELD]: relevanceExpression(\n relevanceLabelKey(entityConstructor),\n relevanceTerms(request.filtering),\n ),\n },\n },\n { $sort: sort },\n { $skip: skip },\n { $limit: pageSize },\n { $project: { _id: 0, [RELEVANCE_FIELD]: 0 } },\n ],\n inSession,\n )\n .toArray()\n : collection\n .find(filter, { ...WITHOUT_MONGO_ID, ...inSession })\n .sort(sort)\n .skip(skip)\n .limit(pageSize)\n .toArray(),\n catch: error => translateMongoError(error),\n });\n const total = yield* Effect.tryPromise({\n try: () => collection.countDocuments(filter, inSession),\n catch: error => translateMongoError(error),\n });\n\n const items = yield* deserializeEntityCollection(entityConstructor, docs);\n\n return {\n items: items as unknown as T[],\n total,\n request,\n } satisfies EntityPage<T>;\n });\n\n const get = <T extends Entity>(id: EntityId) =>\n Effect.gen(function* () {\n const doc = yield* Effect.tryPromise({\n try: () =>\n collection.findOne({ id }, { ...WITHOUT_MONGO_ID, ...inSession }),\n catch: error => translateMongoError(error),\n });\n const entity = yield* deserializeSingleEntity(entityConstructor, doc);\n if (entity === undefined) {\n return yield* Effect.fail(\n new NotFound({ entity: extractMetaEntity(entityConstructor).key }),\n );\n }\n return entity as unknown as T;\n });\n\n const revised = declaresRevision(entityConstructor);\n\n /** The `expect` of a write, resolved to the field the store holds it under. */\n const conditionOf = (\n options: EntityWriteOptions | undefined,\n ): StoredStateCondition | undefined =>\n options?.expect === undefined\n ? undefined\n : storedStateCondition(entityConstructor, options.expect);\n\n /** The filter clause a condition adds to a write. */\n const stateFilter = (condition: StoredStateCondition | undefined) =>\n condition === undefined\n ? {}\n : { [condition.key]: { $in: [...condition.in] } };\n\n /** What a write that matched nothing reads back, only to name the refusal. */\n const readBack = (id: EntityId, condition?: StoredStateCondition) =>\n Effect.tryPromise({\n try: () =>\n collection.findOne(\n { id },\n {\n projection: {\n _id: 0,\n revision: 1,\n ...(condition === undefined ? {} : { [condition.key]: 1 }),\n },\n ...inSession,\n },\n ),\n catch: error => translateMongoError(error),\n });\n\n /**\n * A save of an entity that declares a revision (ADR 0032): a create that\n * never overwrites, or one conditional write on the revision the caller read.\n * Never a read followed by a write — two saves would both read `n`.\n */\n const saveRevised = <T extends Entity>(\n entity: T,\n condition: StoredStateCondition | undefined,\n ) =>\n Effect.gen(function* () {\n const key = extractMetaEntity(entityConstructor).key;\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n const read = readRevision(entity);\n const id = entity.id ?? randomUUID();\n if (read === undefined) {\n yield* ensureIndexes(db, collectionName, uniques);\n yield* Effect.tryPromise({\n try: () =>\n collection.insertOne({ ...doc, id, revision: 1 }, inSession),\n catch: error => translateMongoError(error),\n }).pipe(\n // Only the identity's index means \"someone created it first\"; a\n // unique member's names the member, which a form shows on the field.\n Effect.mapError(failure =>\n failure._tag === 'DuplicateKey' && failure.key === 'id'\n ? new StaleRevision({ entity: key })\n : failure,\n ),\n );\n entity.id = id;\n (entity as { revision?: number }).revision = 1;\n return entity;\n }\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.replaceOne(\n { id, revision: read, ...stateFilter(condition) },\n { ...doc, id, revision: read + 1 },\n inSession,\n ),\n catch: error => translateMongoError(error),\n });\n if (result.matchedCount === 0) {\n // The write already decided; this read only names the refusal. A\n // record in another state is refused for its state before its\n // revision: a fresher read would not make the save legal.\n const stored = yield* readBack(id, condition);\n if (stored === null) return yield* new NotFound({ entity: key });\n if (condition !== undefined && !holdsStoredState(condition, stored)) {\n return yield* unavailableInState(\n entityConstructor,\n condition,\n stored,\n );\n }\n return yield* Effect.fail(\n new StaleRevision({\n entity: key,\n current: readRevision(stored),\n }),\n );\n }\n entity.id = id;\n (entity as { revision?: number }).revision = read + 1;\n return entity;\n });\n\n const save = <T extends Entity>(entity: T, options?: EntityWriteOptions) => {\n const condition = conditionOf(options);\n const write = revised\n ? saveRevised(entity, condition)\n : condition === undefined\n ? saveUnchecked(entity)\n : saveConditioned(entity, condition);\n return Effect.andThen(indexed, write);\n };\n\n /**\n * An update of a record that declares no revision, on the states it must\n * hold: one `replaceOne` on the id and the state, never an upsert — a save\n * with `expect` is an update of a stored record.\n */\n const saveConditioned = <T extends Entity>(\n entity: T,\n condition: StoredStateCondition,\n ) =>\n Effect.gen(function* () {\n const key = extractMetaEntity(entityConstructor).key;\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n const id = entity.id;\n if (id === undefined) return yield* new NotFound({ entity: key });\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.replaceOne(\n { id, ...stateFilter(condition) },\n { ...doc, id },\n inSession,\n ),\n catch: error => translateMongoError(error),\n });\n if (result.matchedCount === 0) {\n const stored = yield* readBack(id, condition);\n return yield* stored === null\n ? Effect.fail(new NotFound({ entity: key }))\n : Effect.fail(\n unavailableInState(entityConstructor, condition, stored),\n );\n }\n return entity;\n });\n\n const saveUnchecked = <T extends Entity>(entity: T) =>\n Effect.gen(function* () {\n const doc = serializeEntity(\n entityConstructor,\n entity as unknown as TEntity,\n );\n // A create arrives without an id, so the store mints one. Entities are\n // addressed by their own `id` field (never Mongo's `_id`, which reads\n // project away), so an inserted document without one would be\n // unreachable by `get` and by any later `replaceOne`.\n const id = entity.id ?? randomUUID();\n yield* Effect.tryPromise({\n // `doc` omits `id` when it was undefined (the serializer drops\n // undefined), hence spreading the resolved id back in.\n try: () =>\n collection.replaceOne(\n { id },\n { ...doc, id },\n { upsert: true, ...inSession },\n ),\n catch: error => translateMongoError(error),\n });\n entity.id = id;\n return entity;\n });\n\n const del = <T extends Entity>(\n entityOrId: EntityId | T,\n options?: EntityWriteOptions,\n ) =>\n Effect.gen(function* () {\n const id = toEntityId(entityOrId);\n const condition = conditionOf(options);\n const result = yield* Effect.tryPromise({\n try: () =>\n collection.deleteOne({ id, ...stateFilter(condition) }, inSession),\n catch: error => translateMongoError(error),\n });\n if (condition === undefined || result.deletedCount > 0) return;\n // Nothing deleted: either nothing was there, which a delete accepts,\n // or the record is in a state it may not be deleted from.\n const stored = yield* readBack(id, condition);\n if (stored !== null) {\n return yield* unavailableInState(entityConstructor, condition, stored);\n }\n });\n\n // Cast through the interface to keep its generic signatures: each method here\n // is written against this entity's type, the interface against any entity's.\n return {\n load,\n get,\n save,\n delete: del,\n } as unknown as EntityRepository;\n}\n"],"names":["randomUUID","declaresRevision","deserializeEntityCollection","deserializeSingleEntity","extractMetaEntity","holdsStoredState","NotFound","readRevision","relevanceLabelKey","relevanceTerms","serializeEntity","StaleRevision","storedStateCondition","unavailableInState","uniqueMembersOf","Effect","translateMongoError","RELEVANCE_FIELD","relevanceExpression","translateFiltering","translateSorting","WITHOUT_MONGO_ID","projection","_id","mongoCollectionName","entityConstructor","metaEntity","key","name","ensuredIndexes","WeakMap","uniqueIndexName","member","ensureIndexes","db","uniques","suspend","ensured","get","Set","set","has","void","collection","tryPromise","try","createIndex","id","unique","partialFilterExpression","$type","type","catch","error","pipe","tap","sync","add","ensureEntityIndexes","toEntityId","entityOrId","makeMongoRepository","options","collectionName","indexed","length","inSession","session","load","request","gen","filter","filtering","sort","sorting","page","pageSize","skip","docs","aggregate","$match","$addFields","$sort","$skip","$limit","$project","toArray","find","limit","total","countDocuments","items","doc","findOne","entity","undefined","fail","revised","conditionOf","expect","stateFilter","condition","$in","in","readBack","revision","saveRevised","read","insertOne","mapError","failure","_tag","result","replaceOne","matchedCount","stored","current","save","write","saveUnchecked","saveConditioned","andThen","upsert","del","deleteOne","deletedCount","delete"],"mappings":";AAAA,SAASA,UAAU,QAAQ,cAAc;AAGzC,SACEC,gBAAgB,EAChBC,2BAA2B,EAC3BC,uBAAuB,EAMvBC,iBAAiB,EACjBC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,EACZC,iBAAiB,EACjBC,cAAc,EACdC,eAAe,EACfC,aAAa,EAEbC,oBAAoB,EACpBC,kBAAkB,EAElBC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAGhC,SAASC,mBAAmB,QAAQ,qCAAqC;AACzE,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,gBAAgB,QACX,yBAAyB;AAEhC,oEAAoE,GACpE,MAAMC,mBAAmB;IAAEC,YAAY;QAAEC,KAAK;IAAE;AAAE;AAElD,gFAAgF,GAChF,OAAO,SAASC,oBACdC,iBAA6C;QAGtCC;IADP,MAAMA,aAAatB,kBAAkBqB;IACrC,QAAOC,kBAAAA,WAAWC,GAAG,YAAdD,kBAAkBA,WAAWE,IAAI;AAC1C;AAEA;;;;;;;;CAQC,GACD,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DAA0D;YAC1D,MAAMV,SAAS,OAAOX,SAASzD,IAAIsD;YACnC,IAAIc,WAAW,MAAM;gBACnB,OAAO,OAAOtG,mBAAmBY,mBAAmB4E,WAAWc;YACjE;QACF;IAEF,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO;QACL/C;QACA9B;QACA+E;QACAS,QAAQH;IACV;AACF"}
|
|
@@ -20,6 +20,13 @@ export interface MongoErrorContext {
|
|
|
20
20
|
}
|
|
21
21
|
/** Whether a server label is on `error` or in its cause chain. */
|
|
22
22
|
export declare const mongoErrorLabelled: (error: unknown, label: string) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The key a driver error says was duplicated (`sku`, or `a,b` for a compound
|
|
25
|
+
* index), or `undefined` when it is no duplicate. For a unit of work's body,
|
|
26
|
+
* which answers its own driver calls with {@link mongoUnitFault} and needs to
|
|
27
|
+
* tell a value already taken — a row to refuse — from the store failing.
|
|
28
|
+
*/
|
|
29
|
+
export declare const duplicatedKeyOf: (error: unknown) => string | undefined;
|
|
23
30
|
/**
|
|
24
31
|
* Whether a driver error is a transaction losing a race: a write conflict, or
|
|
25
32
|
* anything the server labels `TransientTransactionError`. A unit of work runs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate-mongo-error.d.ts","sourceRoot":"","sources":["../../src/errors/translate-mongo-error.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKV,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,WAAW,EACZ,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;CAChD;AAqBD,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,OAOlE,CA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GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,EACd,UAAS,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAM,KACjD,UAMF,CAAC"}
|
|
@@ -31,6 +31,16 @@ const isDuplicate = (error)=>{
|
|
|
31
31
|
return error.code === DUPLICATE_KEY || ((_ref = (_error_writeErrors = error.writeErrors) == null ? void 0 : _error_writeErrors.some((write)=>write.code === DUPLICATE_KEY)) != null ? _ref : false);
|
|
32
32
|
};
|
|
33
33
|
const duplicatedKey = (error)=>typeof error.keyPattern === 'object' && error.keyPattern !== null ? Object.keys(error.keyPattern).join(',') : undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The key a driver error says was duplicated (`sku`, or `a,b` for a compound
|
|
36
|
+
* index), or `undefined` when it is no duplicate. For a unit of work's body,
|
|
37
|
+
* which answers its own driver calls with {@link mongoUnitFault} and needs to
|
|
38
|
+
* tell a value already taken — a row to refuse — from the store failing.
|
|
39
|
+
*/ export const duplicatedKeyOf = (error)=>{
|
|
40
|
+
var _duplicatedKey;
|
|
41
|
+
const driver = shape(error);
|
|
42
|
+
return isDuplicate(driver) ? (_duplicatedKey = duplicatedKey(driver)) != null ? _duplicatedKey : '' : undefined;
|
|
43
|
+
};
|
|
34
44
|
/**
|
|
35
45
|
* Whether a driver error is a transaction losing a race: a write conflict, or
|
|
36
46
|
* anything the server labels `TransientTransactionError`. A unit of work runs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors/translate-mongo-error.ts"],"sourcesContent":["import {\n Contention,\n DuplicateKey,\n isFailure,\n isStoreFault,\n ProtocolFailure,\n type StoreFailure,\n type StoreFault,\n Timeout,\n Unavailable,\n} from '@entifix/core';\n\n/**\n * What a Mongo driver error means, as a categorised failure\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * Read by **name, code and label**, never by class: the driver's error classes\n * are not what a consumer can match on, and a second copy of the driver in one\n * process would answer `instanceof` with `false`.\n */\nexport interface MongoErrorContext {\n /** What the failure names as its dependency; `mongo` when absent. */\n readonly dependency?: string;\n /**\n * What a duplicate key means here. On a declared uniqueness it is a\n * `conflict` — the caller asked for something that already exists. On a\n * claim or a race (an inbox, a command claim, a saga claim) it is\n * `contention` — someone else got there first, and retrying wins or replays.\n */\n readonly duplicate?: 'conflict' | 'contention';\n}\n\ninterface DriverErrorShape {\n readonly name?: unknown;\n readonly code?: unknown;\n readonly codeName?: unknown;\n readonly keyPattern?: unknown;\n readonly writeErrors?: ReadonlyArray<{ readonly code?: unknown }>;\n readonly errorLabels?: readonly string[];\n readonly hasErrorLabel?: (label: string) => boolean;\n readonly cause?: unknown;\n}\n\nconst shape = (error: unknown): DriverErrorShape =>\n typeof error === 'object' && error !== null\n ? (error as DriverErrorShape)\n : {};\n\nconst labelled = (error: DriverErrorShape, label: string): boolean =>\n error.hasErrorLabel?.(label) ?? error.errorLabels?.includes(label) ?? false;\n\n/** Whether a server label is on `error` or in its cause chain. */\nexport const mongoErrorLabelled = (error: unknown, label: string): boolean => {\n let current: unknown = error;\n for (let depth = 0; current != null && depth < 5; depth += 1) {\n if (labelled(shape(current), label)) return true;\n current = shape(current).cause;\n }\n return false;\n};\n\nconst DUPLICATE_KEY = 11000;\nconst WRITE_CONFLICT = 112;\nconst MAX_TIME_EXPIRED = 50;\n\nconst UNREACHABLE = new Set([\n 'MongoNetworkError',\n 'MongoServerSelectionError',\n 'MongoNotConnectedError',\n 'MongoTopologyClosedError',\n 'MongoServerClosedError',\n 'MongoPoolClosedError',\n]);\n\nconst isDuplicate = (error: DriverErrorShape): boolean =>\n error.code === DUPLICATE_KEY ||\n (error.writeErrors?.some(write => write.code === DUPLICATE_KEY) ?? false);\n\nconst duplicatedKey = (error: DriverErrorShape): string | undefined =>\n typeof error.keyPattern === 'object' && error.keyPattern !== null\n ? Object.keys(error.keyPattern).join(',')\n : undefined;\n\n/**\n * Whether a driver error is a transaction losing a race: a write conflict, or\n * anything the server labels `TransientTransactionError`. A unit of work runs\n * itself again on exactly this — so a body that maps its own driver errors\n * must answer {@link Contention} for these and nothing else, or the retry\n * never happens and a contended write that would have serialized fails.\n */\nexport const isMongoContention = (error: unknown): boolean =>\n shape(error).code === WRITE_CONFLICT ||\n mongoErrorLabelled(error, 'TransientTransactionError');\n\n/**\n * A failure of a driver call a unit of work's **body** makes itself: a lost\n * race is {@link Contention}, which the unit runs itself again on, and\n * anything else is the store failing to answer.\n *\n * ⚠️ **Not an `Unavailable` for everything.** A body that answered every\n * driver error that way hid the write conflict from the unit, so a contended\n * write that the retry would have serialized failed instead — measured on a\n * burst of partial refunds against one allocation, 18 of 20 answered `503`.\n */\nexport const mongoUnitFault = (error: unknown): Contention | Unavailable =>\n isMongoContention(error)\n ? new Contention()\n : new Unavailable({ dependency: 'mongo' });\n\nexport const translateMongoError = (\n error: unknown,\n context: MongoErrorContext = {},\n): StoreFailure => {\n // Already translated, by an inner call: pass it through as it is.\n if (isFailure(error)) return error as StoreFailure;\n const dependency = context.dependency ?? 'mongo';\n const driver = shape(error);\n\n if (isDuplicate(driver)) {\n if (context.duplicate === 'contention') return new Contention();\n const key = duplicatedKey(driver);\n return new DuplicateKey(key === undefined ? {} : { key });\n }\n if (isMongoContention(error)) return new Contention();\n if (\n driver.code === MAX_TIME_EXPIRED ||\n driver.name === 'MongoNetworkTimeoutError' ||\n driver.name === 'MongoOperationTimeoutError'\n )\n return new Timeout({ dependency });\n if (driver.name === 'BSONError')\n return new ProtocolFailure({\n reason: `${dependency} answered a document that does not decode`,\n });\n if (typeof driver.name === 'string' && UNREACHABLE.has(driver.name))\n return new Unavailable({ dependency });\n // Anything else the driver raised is still the store failing to answer,\n // which is what the class tree called every one of these.\n return new Unavailable({ dependency });\n};\n\n/**\n * A driver error as the store's own fault, for the bookkeeping a mechanism\n * does around a caller's work — a claim, a commit, a remembered answer. A\n * duplicate key there means a race lost, never an answer for the caller.\n */\nexport const translateMongoFault = (\n error: unknown,\n context: Omit<MongoErrorContext, 'duplicate'> = {},\n): StoreFault => {\n const failure = translateMongoError(error, {\n ...context,\n duplicate: 'contention',\n });\n return isStoreFault(failure) ? failure : new Contention();\n};\n"],"names":["Contention","DuplicateKey","isFailure","isStoreFault","ProtocolFailure","Timeout","Unavailable","shape","error","labelled","label","hasErrorLabel","errorLabels","includes","mongoErrorLabelled","current","depth","cause","DUPLICATE_KEY","WRITE_CONFLICT","MAX_TIME_EXPIRED","UNREACHABLE","Set","isDuplicate","code","writeErrors","some","write","duplicatedKey","keyPattern","Object","keys","join","undefined","isMongoContention","mongoUnitFault","dependency","translateMongoError","context","
|
|
1
|
+
{"version":3,"sources":["../../src/errors/translate-mongo-error.ts"],"sourcesContent":["import {\n Contention,\n DuplicateKey,\n isFailure,\n isStoreFault,\n ProtocolFailure,\n type StoreFailure,\n type StoreFault,\n Timeout,\n Unavailable,\n} from '@entifix/core';\n\n/**\n * What a Mongo driver error means, as a categorised failure\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * Read by **name, code and label**, never by class: the driver's error classes\n * are not what a consumer can match on, and a second copy of the driver in one\n * process would answer `instanceof` with `false`.\n */\nexport interface MongoErrorContext {\n /** What the failure names as its dependency; `mongo` when absent. */\n readonly dependency?: string;\n /**\n * What a duplicate key means here. On a declared uniqueness it is a\n * `conflict` — the caller asked for something that already exists. On a\n * claim or a race (an inbox, a command claim, a saga claim) it is\n * `contention` — someone else got there first, and retrying wins or replays.\n */\n readonly duplicate?: 'conflict' | 'contention';\n}\n\ninterface DriverErrorShape {\n readonly name?: unknown;\n readonly code?: unknown;\n readonly codeName?: unknown;\n readonly keyPattern?: unknown;\n readonly writeErrors?: ReadonlyArray<{ readonly code?: unknown }>;\n readonly errorLabels?: readonly string[];\n readonly hasErrorLabel?: (label: string) => boolean;\n readonly cause?: unknown;\n}\n\nconst shape = (error: unknown): DriverErrorShape =>\n typeof error === 'object' && error !== null\n ? (error as DriverErrorShape)\n : {};\n\nconst labelled = (error: DriverErrorShape, label: string): boolean =>\n error.hasErrorLabel?.(label) ?? error.errorLabels?.includes(label) ?? false;\n\n/** Whether a server label is on `error` or in its cause chain. */\nexport const mongoErrorLabelled = (error: unknown, label: string): boolean => {\n let current: unknown = error;\n for (let depth = 0; current != null && depth < 5; depth += 1) {\n if (labelled(shape(current), label)) return true;\n current = shape(current).cause;\n }\n return false;\n};\n\nconst DUPLICATE_KEY = 11000;\nconst WRITE_CONFLICT = 112;\nconst MAX_TIME_EXPIRED = 50;\n\nconst UNREACHABLE = new Set([\n 'MongoNetworkError',\n 'MongoServerSelectionError',\n 'MongoNotConnectedError',\n 'MongoTopologyClosedError',\n 'MongoServerClosedError',\n 'MongoPoolClosedError',\n]);\n\nconst isDuplicate = (error: DriverErrorShape): boolean =>\n error.code === DUPLICATE_KEY ||\n (error.writeErrors?.some(write => write.code === DUPLICATE_KEY) ?? false);\n\nconst duplicatedKey = (error: DriverErrorShape): string | undefined =>\n typeof error.keyPattern === 'object' && error.keyPattern !== null\n ? Object.keys(error.keyPattern).join(',')\n : undefined;\n\n/**\n * The key a driver error says was duplicated (`sku`, or `a,b` for a compound\n * index), or `undefined` when it is no duplicate. For a unit of work's body,\n * which answers its own driver calls with {@link mongoUnitFault} and needs to\n * tell a value already taken — a row to refuse — from the store failing.\n */\nexport const duplicatedKeyOf = (error: unknown): string | undefined => {\n const driver = shape(error);\n return isDuplicate(driver) ? (duplicatedKey(driver) ?? '') : undefined;\n};\n\n/**\n * Whether a driver error is a transaction losing a race: a write conflict, or\n * anything the server labels `TransientTransactionError`. A unit of work runs\n * itself again on exactly this — so a body that maps its own driver errors\n * must answer {@link Contention} for these and nothing else, or the retry\n * never happens and a contended write that would have serialized fails.\n */\nexport const isMongoContention = (error: unknown): boolean =>\n shape(error).code === WRITE_CONFLICT ||\n mongoErrorLabelled(error, 'TransientTransactionError');\n\n/**\n * A failure of a driver call a unit of work's **body** makes itself: a lost\n * race is {@link Contention}, which the unit runs itself again on, and\n * anything else is the store failing to answer.\n *\n * ⚠️ **Not an `Unavailable` for everything.** A body that answered every\n * driver error that way hid the write conflict from the unit, so a contended\n * write that the retry would have serialized failed instead — measured on a\n * burst of partial refunds against one allocation, 18 of 20 answered `503`.\n */\nexport const mongoUnitFault = (error: unknown): Contention | Unavailable =>\n isMongoContention(error)\n ? new Contention()\n : new Unavailable({ dependency: 'mongo' });\n\nexport const translateMongoError = (\n error: unknown,\n context: MongoErrorContext = {},\n): StoreFailure => {\n // Already translated, by an inner call: pass it through as it is.\n if (isFailure(error)) return error as StoreFailure;\n const dependency = context.dependency ?? 'mongo';\n const driver = shape(error);\n\n if (isDuplicate(driver)) {\n if (context.duplicate === 'contention') return new Contention();\n const key = duplicatedKey(driver);\n return new DuplicateKey(key === undefined ? {} : { key });\n }\n if (isMongoContention(error)) return new Contention();\n if (\n driver.code === MAX_TIME_EXPIRED ||\n driver.name === 'MongoNetworkTimeoutError' ||\n driver.name === 'MongoOperationTimeoutError'\n )\n return new Timeout({ dependency });\n if (driver.name === 'BSONError')\n return new ProtocolFailure({\n reason: `${dependency} answered a document that does not decode`,\n });\n if (typeof driver.name === 'string' && UNREACHABLE.has(driver.name))\n return new Unavailable({ dependency });\n // Anything else the driver raised is still the store failing to answer,\n // which is what the class tree called every one of these.\n return new Unavailable({ dependency });\n};\n\n/**\n * A driver error as the store's own fault, for the bookkeeping a mechanism\n * does around a caller's work — a claim, a commit, a remembered answer. A\n * duplicate key there means a race lost, never an answer for the caller.\n */\nexport const translateMongoFault = (\n error: unknown,\n context: Omit<MongoErrorContext, 'duplicate'> = {},\n): StoreFault => {\n const failure = translateMongoError(error, {\n ...context,\n duplicate: 'contention',\n });\n return isStoreFault(failure) ? failure : new Contention();\n};\n"],"names":["Contention","DuplicateKey","isFailure","isStoreFault","ProtocolFailure","Timeout","Unavailable","shape","error","labelled","label","hasErrorLabel","errorLabels","includes","mongoErrorLabelled","current","depth","cause","DUPLICATE_KEY","WRITE_CONFLICT","MAX_TIME_EXPIRED","UNREACHABLE","Set","isDuplicate","code","writeErrors","some","write","duplicatedKey","keyPattern","Object","keys","join","undefined","duplicatedKeyOf","driver","isMongoContention","mongoUnitFault","dependency","translateMongoError","context","duplicate","key","name","reason","has","translateMongoFault","failure"],"mappings":";AAAA,SACEA,UAAU,EACVC,YAAY,EACZC,SAAS,EACTC,YAAY,EACZC,eAAe,EAGfC,OAAO,EACPC,WAAW,QACN,gBAAgB;AAiCvB,MAAMC,QAAQ,CAACC,QACb,OAAOA,UAAU,YAAYA,UAAU,OAClCA,QACD,CAAC;AAEP,MAAMC,WAAW,CAACD,OAAyBE;QACzCF;QAAgCA;YAAhCA,gBAAAA,MAAMG,aAAa,oBAAnBH,MAAMG,aAAa,MAAnBH,OAAsBE,2BAAUF,qBAAAA,MAAMI,WAAW,qBAAjBJ,mBAAmBK,QAAQ,CAACH,kBAA5DF,OAAsE;;AAExE,gEAAgE,GAChE,OAAO,MAAMM,qBAAqB,CAACN,OAAgBE;IACjD,IAAIK,UAAmBP;IACvB,IAAK,IAAIQ,QAAQ,GAAGD,WAAW,QAAQC,QAAQ,GAAGA,SAAS,EAAG;QAC5D,IAAIP,SAASF,MAAMQ,UAAUL,QAAQ,OAAO;QAC5CK,UAAUR,MAAMQ,SAASE,KAAK;IAChC;IACA,OAAO;AACT,EAAE;AAEF,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AACvB,MAAMC,mBAAmB;AAEzB,MAAMC,cAAc,IAAIC,IAAI;IAC1B;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,cAAc,CAACf;;QAElBA;WADDA,MAAMgB,IAAI,KAAKN,2BACdV,qBAAAA,MAAMiB,WAAW,qBAAjBjB,mBAAmBkB,IAAI,CAACC,CAAAA,QAASA,MAAMH,IAAI,KAAKN,iCAAkB;;AAErE,MAAMU,gBAAgB,CAACpB,QACrB,OAAOA,MAAMqB,UAAU,KAAK,YAAYrB,MAAMqB,UAAU,KAAK,OACzDC,OAAOC,IAAI,CAACvB,M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,GAChE,OAAO,IAAIrC,YAAY;QAAEgC;IAAW;IACtC,wEAAwE;IACxE,0DAA0D;IAC1D,OAAO,IAAIhC,YAAY;QAAEgC;IAAW;AACtC,EAAE;AAEF;;;;CAIC,GACD,OAAO,MAAMQ,sBAAsB,CACjCtC,OACAgC,UAAgD,CAAC,CAAC;IAElD,MAAMO,UAAUR,oBAAoB/B,OAAO,aACtCgC;QACHC,WAAW;;IAEb,OAAOtC,aAAa4C,WAAWA,UAAU,IAAI/C;AAC/C,EAAE"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* write conflict the unit retries on is never hidden behind a failure of the
|
|
15
15
|
* body's choosing.
|
|
16
16
|
*/
|
|
17
|
-
export { mongoUnitFault } from '../errors/translate-mongo-error.js';
|
|
17
|
+
export { duplicatedKeyOf, mongoUnitFault, } from '../errors/translate-mongo-error.js';
|
|
18
18
|
export * from '../idempotency/store.js';
|
|
19
19
|
export * from '../inbox/store.js';
|
|
20
20
|
export * from '../outbox/relay.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transactions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH;;;;GAIG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transactions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH;;;;GAIG;AACH,OAAO,EACL,eAAe,EACf,cAAc,GACf,MAAM,oCAAoC,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* How a unit of work's body answers its own driver calls' failures, so the
|
|
13
13
|
* write conflict the unit retries on is never hidden behind a failure of the
|
|
14
14
|
* body's choosing.
|
|
15
|
-
*/ export { mongoUnitFault } from '../errors/translate-mongo-error.js';
|
|
15
|
+
*/ export { duplicatedKeyOf, mongoUnitFault } from '../errors/translate-mongo-error.js';
|
|
16
16
|
export * from '../idempotency/store.js';
|
|
17
17
|
export * from '../inbox/store.js';
|
|
18
18
|
export * from '../outbox/relay.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/index.ts"],"sourcesContent":["/**\n * The half of this package that needs `@entifix/transactions`: the\n * transactional outbox written inside the entity's own Mongo\n * transaction, and the inbox that makes a redelivered command idempotent.\n *\n * Behind a subpath so entity CRUD over Mongo does not arrive with the saga\n * engine attached. Package-level dependencies are not per-subpath, so what\n * actually keeps it optional is the `peerDependenciesMeta.optional` entry in\n * the manifest — importing this module without that peer installed is the\n * error, and it is the adopter's to make deliberately.\n */\n/**\n * How a unit of work's body answers its own driver calls' failures, so the\n * write conflict the unit retries on is never hidden behind a failure of the\n * body's choosing.\n */\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/index.ts"],"sourcesContent":["/**\n * The half of this package that needs `@entifix/transactions`: the\n * transactional outbox written inside the entity's own Mongo\n * transaction, and the inbox that makes a redelivered command idempotent.\n *\n * Behind a subpath so entity CRUD over Mongo does not arrive with the saga\n * engine attached. Package-level dependencies are not per-subpath, so what\n * actually keeps it optional is the `peerDependenciesMeta.optional` entry in\n * the manifest — importing this module without that peer installed is the\n * error, and it is the adopter's to make deliberately.\n */\n/**\n * How a unit of work's body answers its own driver calls' failures, so the\n * write conflict the unit retries on is never hidden behind a failure of the\n * body's choosing.\n */\nexport {\n duplicatedKeyOf,\n mongoUnitFault,\n} from '../errors/translate-mongo-error.js';\nexport * from '../idempotency/store.js';\nexport * from '../inbox/store.js';\nexport * from '../outbox/relay.js';\nexport * from '../outbox/store.js';\nexport * from '../unit-of-work/command-inbox.js';\nexport * from '../unit-of-work/mongo-unit-of-work.js';\n"],"names":["duplicatedKeyOf","mongoUnitFault"],"mappings":"AAAA;;;;;;;;;;CAUC,GACD;;;;CAIC,GACD,SACEA,eAAe,EACfC,cAAc,QACT,qCAAqC;AAC5C,cAAc,0BAA0B;AACxC,cAAc,oBAAoB;AAClC,cAAc,qBAAqB;AACnC,cAAc,qBAAqB;AACnC,cAAc,mCAAmC;AACjD,cAAc,wCAAwC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/mongo",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.18",
|
|
4
4
|
"description": "MongoDB adapter: an entity repository, RSQL-to-Mongo query translation, per-tenant databases, and an optional transactional outbox.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@swc/helpers": "0.5.23",
|
|
59
59
|
"mongodb": "7.9.0",
|
|
60
|
-
"@entifix/business": "0.23.
|
|
61
|
-
"@entifix/core": "0.23.
|
|
60
|
+
"@entifix/business": "0.23.18",
|
|
61
|
+
"@entifix/core": "0.23.18"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"effect": "4.0.7",
|
|
65
|
-
"@entifix/testing-unit": "0.23.
|
|
66
|
-
"@entifix/transactions": "0.23.
|
|
65
|
+
"@entifix/testing-unit": "0.23.18",
|
|
66
|
+
"@entifix/transactions": "0.23.18"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"effect": "^4.0.7",
|
|
70
|
-
"@entifix/transactions": "0.23.
|
|
70
|
+
"@entifix/transactions": "0.23.18"
|
|
71
71
|
},
|
|
72
72
|
"peerDependenciesMeta": {
|
|
73
73
|
"@entifix/transactions": {
|