joist-test-utils 2.3.0 → 2.4.0-next.2
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/README.md +1 -1
- package/build/RunPlugin.cjs +219 -0
- package/build/RunPlugin.cjs.map +1 -0
- package/build/RunPlugin.d.cts +12 -0
- package/build/RunPlugin.d.cts.map +1 -0
- package/build/RunPlugin.d.mts +12 -0
- package/build/RunPlugin.d.mts.map +1 -0
- package/build/RunPlugin.js +203 -341
- package/build/RunPlugin.js.map +1 -1
- package/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/context.cjs +2 -0
- package/build/context.d.cts +9 -0
- package/build/context.d.cts.map +1 -0
- package/build/context.d.mts +9 -0
- package/build/context.d.mts.map +1 -0
- package/build/context.js +2 -3
- package/build/index.cjs +38 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +52 -0
- package/build/index.d.cts.map +1 -0
- package/build/index.d.mts +52 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.js +25 -41
- package/build/index.js.map +1 -1
- package/build/run.cjs +77 -0
- package/build/run.cjs.map +1 -0
- package/build/run.d.cts +17 -0
- package/build/run.d.cts.map +1 -0
- package/build/run.d.mts +17 -0
- package/build/run.d.mts.map +1 -0
- package/build/run.js +52 -76
- package/build/run.js.map +1 -1
- package/build/seed.cjs +54 -0
- package/build/seed.cjs.map +1 -0
- package/build/{seed.d.ts → seed.d.cts} +9 -6
- package/build/seed.d.cts.map +1 -0
- package/build/seed.d.mts +35 -0
- package/build/seed.d.mts.map +1 -0
- package/build/seed.js +47 -53
- package/build/seed.js.map +1 -1
- package/build/toMatchEntity.cjs +94 -0
- package/build/toMatchEntity.cjs.map +1 -0
- package/build/toMatchEntity.d.cts +28 -0
- package/build/toMatchEntity.d.cts.map +1 -0
- package/build/toMatchEntity.d.mts +28 -0
- package/build/toMatchEntity.d.mts.map +1 -0
- package/build/toMatchEntity.js +73 -109
- package/build/toMatchEntity.js.map +1 -1
- package/package.json +33 -13
- package/build/RunPlugin.d.ts +0 -9
- package/build/RunPlugin.d.ts.map +0 -1
- package/build/context.d.ts +0 -6
- package/build/context.d.ts.map +0 -1
- package/build/context.js.map +0 -1
- package/build/index.d.ts +0 -42
- package/build/index.d.ts.map +0 -1
- package/build/run.d.ts +0 -15
- package/build/run.d.ts.map +0 -1
- package/build/seed.d.ts.map +0 -1
- package/build/toMatchEntity.d.ts +0 -27
- package/build/toMatchEntity.d.ts.map +0 -1
package/build/RunPlugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RunPlugin.js","sourceRoot":"","sources":["../src/RunPlugin.ts"],"names":[],"mappings":";;;AAAA,2CA0BoB;AAEpB;;;;GAIG;AACH,MAAa,SAAU,SAAQ,mBAAM;IAGP;IAF5B,oHAAoH;IACpH,2FAA2F;IAC3F,YAA4B,EAAiB;QAC3C,KAAK,EAAE,CAAC;QADkB,OAAE,GAAF,EAAE,CAAe;IAE7C,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,WAAiC,EAAE,YAAyC;QACrF,MAAM,GAAG,GAAG,IAAA,6BAAgB,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtC,oHAAoH;QACpH,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAC9B,0FAA0F;QAC1F,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACvB,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAClC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACpC,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;QACxC,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED,eAAe,CAAC,WAAiC;QAC/C,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;QACpB,MAAM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Y,+BAAkB,CAClC,CAAC;AACN,CAAC"}
|
|
1
|
+
{"version":3,"file":"RunPlugin.js","names":["#syncEntityData","#syncReferences","#syncManyToManys","#syncEnumCollections","#preloadUnloadedRelations"],"sources":["../src/RunPlugin.ts"],"sourcesContent":["import {\n type Entity,\n type EntityManager,\n EnumCollectionImpl,\n type FieldColumn,\n type JoinRow,\n type JoinRowTodo,\n ManyToManyCollection,\n ManyToOneReferenceImpl,\n type MaybeAbstractEntityConstructor,\n OneToManyCollection,\n OneToOneReferenceImpl,\n Plugin,\n PojoRowData,\n PolymorphicKeySerde,\n PolymorphicReferenceImpl,\n ReactiveManyToManyImpl,\n ReactiveManyToManyOtherSideImpl,\n ReactiveReferenceImpl,\n type Todo,\n assertNever,\n createRowFromEntityData,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getRelations,\n isEntity,\n} from \"joist-core\";\n\n/*\n * `run...` helpers use this plugin to mirror any changes made to their isolated entity manager inside to the original\n * entity manager they were passed. This allows changes to be synchronously reflected between the two entity managers\n * without needing to query the database.\n */\nexport class RunPlugin extends Plugin {\n // The em passed here is the target which we'll mirror changes to. The plugin should not be added to it, but rather\n // to the new em `run..` helpers create or by downstream ems created by implementation code\n constructor(public readonly em: EntityManager) {\n super();\n }\n\n maybeCloneForNewEm() {\n return this;\n }\n\n afterWrite(entityTodos: Record<string, Todo>, joinRowTodos: Record<string, JoinRowTodo>) {\n const api = getEmInternalApi(this.em);\n // We don't want any old preloaded data leaking into our changes, so we clear it out before we start as a precaution\n api.clearPreloadedRelations();\n // Likewise, any data loaders in memory will have stale data, so we clear them out as well\n api.clearDataloaders();\n this.#syncEntityData(entityTodos);\n this.#syncReferences(entityTodos);\n this.#syncManyToManys(joinRowTodos);\n this.#syncEnumCollections(joinRowTodos);\n this.#preloadUnloadedRelations(entityTodos);\n }\n\n #syncEntityData(entityTodos: Record<string, Todo>) {\n const { em } = this;\n Object.values(entityTodos).forEach((todo) => {\n todo.inserts.forEach((newEntity) => {\n const row = createRowFromEntityData(newEntity, { preferOriginalData: false });\n em.hydrate(newEntity.constructor as MaybeAbstractEntityConstructor<any>, [row]);\n });\n todo.updates.forEach((newEntity) => {\n const oldEntity = em.findExistingInstance(newEntity.idTagged);\n // This fail shouldn't really be possible, since any entity should either have been created:\n // * via factory or em.create in the original em\n // * by the new em inside the `run` call, in which case it'd be an insert instead of an update\n // * by a previous afterWrite call, which would have already been an insert and added to the original em\n // * by a previous `run` call, which would have already been an insert as well\n if (!oldEntity) fail(`Expected to find existing entity for $ {e.idTagged}`);\n const { data: newData } = getInstanceData(newEntity);\n const { data: oldData } = getInstanceData(oldEntity);\n const meta = getMetadata(newEntity);\n (newEntity as any).changes.fields\n .values()\n .filter((fieldName: string) => fieldName in newData)\n .filter((fieldName: string) => !!meta.allFields[fieldName].serde)\n .forEach((fieldName: string) => {\n // We're imitating a round trip to the database here, so we use our field's serde to map the value back\n // and forth.\n const serde = meta.allFields[fieldName].serde!;\n let column: FieldColumn | undefined;\n let value: any;\n if (serde instanceof PolymorphicKeySerde) {\n [column, value] =\n serde.columns\n .values()\n .map((c) => [c, c.rowValue(newData)] as const)\n .find(([, v]) => v !== undefined) ?? [];\n } else {\n [column] = serde.columns;\n // the 2nd and 3rd arguments are only used if the 4th argument is defined, so it's OK to pass undefined here\n value = column.rowValue(newData);\n }\n oldData[fieldName] = serde.fromRow(new PojoRowData([column ? { [column.columnName]: value } : {}]), 0);\n });\n });\n todo.deletes.forEach((newEntity) => {\n const existing = em.findExistingInstance(newEntity.idTagged);\n // Again it shouldn't really be possible for a deletion to happen without the entity being present in the\n // original em, but just in case we'll skip if we don't find it\n if (!existing) fail(`Expected to find existing entity for $ {e.idTagged}`);\n getInstanceData(existing).markDeletedBecauseNotFound();\n });\n });\n }\n\n // Ensure m2o/rr/poly changes from the new em are reflected in the original em\n #syncReferences(entityTodos: Record<string, Todo>) {\n const { em } = this;\n Object.values(entityTodos).forEach((todo) => {\n todo.inserts.forEach((newEntity) => {\n const oldEntity = em.findExistingInstance(newEntity.idTagged)!;\n getReferences(newEntity).forEach((r) => {\n const other = r.isSet ? em.findExistingInstance(r.idTaggedMaybe) : undefined;\n preloadReference(em, r.fieldName, oldEntity, other);\n if (other) maybePreloadOtherSide(em, r.fieldName, oldEntity, other);\n });\n });\n todo.updates.forEach((newEntity) => {\n const oldEntity = em.findExistingInstance(newEntity.idTagged)!;\n getReferences(newEntity)\n .filter((r) => (newEntity as any).changes[r.fieldName].hasChanged)\n .forEach((r) => {\n const other = r.isSet ? em.findExistingInstance(r.idTaggedMaybe) : undefined;\n preloadReference(em, r.fieldName, oldEntity, other);\n if (other) maybePreloadOtherSide(em, r.fieldName, oldEntity, other);\n const originalId = (newEntity as any).changes[r.fieldName].originalValue;\n const originalOther = originalId ? em.findExistingInstance(originalId) : undefined;\n if (originalOther) maybePreloadOtherSide(em, r.fieldName, oldEntity, originalOther, true);\n });\n // If the entity was soft-deleted, then we need to clear out the caches for any o2m collections that contain it\n if (\"deletedAt\" in newEntity && (newEntity as any).changes.deletedAt.hasChanged) {\n getReferences(oldEntity).forEach((r) => {\n const other = r.isSet ? em.findExistingInstance(r.idTaggedMaybe) : undefined;\n if (other) {\n const otherSide = getOtherSide(r.fieldName, oldEntity, other);\n if (otherSide instanceof OneToManyCollection) otherSide.resetIsLoaded();\n }\n });\n }\n });\n todo.deletes.forEach((newEntity) => {\n const oldEntity = em.findExistingInstance(newEntity.idTagged)!;\n getReferences(newEntity).forEach((r) => {\n // Since both old and new entities are marked as deleted, we can't just go looking through their relations\n // for the other side's id since this will error. Likewise, we only care about the collection that this\n // entity used to belong to in the old em so we can remove it. So just grab the other id directly from the\n // old entity's data and then preload its other side relation.\n const entityOrId = getInstanceData(oldEntity).data[r.fieldName];\n const originalOther = entityOrId\n ? em.findExistingInstance(isEntity(entityOrId) ? entityOrId.idTagged : entityOrId)\n : undefined;\n if (originalOther) maybePreloadOtherSide(em, r.fieldName, oldEntity, originalOther, true);\n });\n });\n });\n }\n\n // Ensure m2m changes are propagated from the new em to the original em\n #syncManyToManys(joinRowTodos: Record<string, JoinRowTodo>) {\n const { em } = this;\n const api = getEmInternalApi(em);\n Object.entries(joinRowTodos).forEach(([joinTable, todo]) => {\n // Enum m2ms (EnumCollections) aren't entity-to-entity, so there's nothing to mirror between ems.\n if (todo.m2m.otherEnum) return;\n const preloads = new Set<ManyToManyCollection<Entity, Entity>>();\n processJoinRows(em, joinTable, todo.newRows, preloads, (oldEntity, entities) => entities.push(oldEntity));\n processJoinRows(em, joinTable, todo.deletedRows, preloads, (oldEntity, entities) =>\n entities.splice(entities.indexOf(oldEntity), 1),\n );\n // Since multiple join rows could reference the same m2m, our processJoinRows doesn't actually call preload() so\n // we need to do it now\n preloads.values().forEach((r) => {\n const id = r.entity.idTagged;\n const entities = api.getPreloadedRelation(id, r.fieldName) as Entity[];\n // unique our entities in case somehow an entity was inserted by multiple join rows\n api.setPreloadedRelation(id, r.fieldName, [...new Set(entities)]);\n r.preload();\n });\n });\n }\n\n // Ensure enum m2m (EnumCollection) membership changes are propagated from the new em to the original em\n #syncEnumCollections(joinRowTodos: Record<string, JoinRowTodo>) {\n const { em } = this;\n const api = getEmInternalApi(em);\n const touched = new Set<EnumCollectionImpl<Entity, any>>();\n Object.values(joinRowTodos).forEach((todo) => {\n // Only enum m2ms; entity-to-entity m2ms are handled by `#syncManyToManys`.\n if (!todo.m2m.otherEnum) return;\n const { columnName, otherColumnName, fieldName } = todo.m2m;\n const sync = (rows: JoinRow[], add: boolean) => {\n rows.forEach((row) => {\n const newEntity = row.columns[columnName] as Entity;\n const enumId = row.columns[otherColumnName] as number;\n const oldEntity = em.findExistingInstance(newEntity.idTagged);\n if (!oldEntity || oldEntity.isDeletedEntity) return;\n const oldCollection = (oldEntity as any)[fieldName] as EnumCollectionImpl<Entity, any>;\n // Only mirror collections the original em has loaded (or new entities, whose rows are all\n // adds); otherwise a later `.load()` will read the (same-txn) db and see the change itself.\n if (!oldCollection.isLoaded && !newEntity.isNewEntity) return;\n const joinRows = api.joinRows(oldCollection);\n if (add) {\n joinRows.addPreloadedRow(oldCollection, undefined, oldEntity, enumId);\n } else {\n joinRows.removePreloadedRow(oldCollection, oldEntity, enumId);\n }\n touched.add(oldCollection);\n });\n };\n sync(todo.newRows, true);\n sync(todo.deletedRows, false);\n });\n // Re-publish each touched collection's codes and mark it loaded.\n touched.forEach((oldCollection) => {\n const joinRows = api.joinRows(oldCollection);\n const codes = (joinRows.getOthers(oldCollection.columnName, oldCollection.entity) as number[]).map(\n (id) => oldCollection.otherEnum!.findById(id)!.code,\n );\n api.setPreloadedRelation(oldCollection.entity.idTagged, oldCollection.fieldName, codes);\n oldCollection.preload();\n });\n }\n\n // Make sure any unloaded relations on net new entities are marked as loaded. We should have already preloaded all\n // concrete references in a previous step. So we just need to load collections (plus o2os) if they haven't already\n // been preloaded by another step. Since nothing else preloaded them, they must have no data so we can just set\n // them to an empty array.\n #preloadUnloadedRelations(entityTodos: Record<string, Todo>) {\n const { em } = this;\n Object.entries(entityTodos).forEach(([, todo]) => {\n todo.inserts.forEach((newEntity) => {\n const oldEntity = em.findExistingInstance(newEntity.idTagged)!;\n getCollections(oldEntity)\n .filter((r) => !r.isPreloaded)\n .forEach((r) => {\n getEmInternalApi(em).setPreloadedRelation(oldEntity.idTagged, r.fieldName, []);\n r.preload();\n });\n });\n });\n }\n}\n\n// References that represent one (or more) foreign keys directly on the entity\ntype ConcreteReference =\n | ManyToOneReferenceImpl<Entity, Entity, any>\n | ReactiveReferenceImpl<Entity, Entity, any, any>\n | PolymorphicReferenceImpl<Entity, Entity, any>;\n\nfunction preloadReference(em: EntityManager, fieldName: string, entity: Entity, other: Entity | undefined) {\n // Preload for concrete references doesn't make us of the global preloaded cache. It just looks at its owner's data\n // to get a key, then checks if that entity is already in the em and uses that if so. So we just need to set the\n // owner's data to have the correct key then we can call preload since all entities should already be in the original\n // em\n const reference = (entity as any)[fieldName] as ConcreteReference;\n (reference as any).unload();\n const { data } = getInstanceData(entity);\n data[fieldName] = other?.idTagged;\n if (!entity.isDeletedEntity) reference.preload();\n}\n\nfunction getOtherSide(fieldName: string, entity: Entity, other: Entity) {\n const meta = getMetadata(entity);\n const metas = new Set([meta, ...meta.baseTypes]);\n return getRelations(other)\n .values()\n .filter((r) => r instanceof OneToOneReferenceImpl || r instanceof OneToManyCollection)\n .find((r) => metas.has(r.otherMeta) && r.otherFieldName === fieldName);\n}\n\nfunction maybePreloadOtherSide(\n em: EntityManager,\n fieldName: string,\n entity: Entity,\n other: Entity,\n remove: boolean = false,\n): void {\n const meta = getMetadata(entity);\n const otherSide = getOtherSide(fieldName, entity, other);\n // If our other side is a large o2m then we can just ignore it, since it isn't loadable regardless\n if (!otherSide) return;\n // Since our preload scans the entire em, we only need to run it once per collection/o2o. We clear out preloads\n // when we start the afterWrite, so if anything is preloaded we know we put it there.\n if (otherSide.isPreloaded) return;\n let otherEntities: Entity[];\n if (otherSide instanceof OneToOneReferenceImpl) {\n otherEntities = remove ? [] : [entity];\n } else if (otherSide instanceof OneToManyCollection) {\n // Scan the entire em for (non-deleted) entities of our type that reference the other side\n otherEntities = em\n .getEntities(meta.cstr)\n .values()\n .filter((e) => !e.isDeletedEntity)\n .filter((e) => ((e as any)[otherSide.otherFieldName] as ConcreteReference).idTaggedMaybe === other.idTagged)\n .toArray();\n } else {\n assertNever(otherSide);\n }\n // We don't need to worry about order here because o2ms do their own sorting internally and o2os are inherently\n // unordered (since it's just a single entity)\n getEmInternalApi(em).setPreloadedRelation(other.idTagged, otherSide.fieldName, otherEntities);\n otherSide.preload();\n // This method is confusingly name, what it actually does is clear out the sorted caches that m2m uses to avoid\n // sorting on every `.get` call. Since we just preloaded the collection with new data, we know these caches need to\n // be cleared\n if (otherSide instanceof OneToManyCollection) otherSide.resetIsLoaded();\n}\n\nfunction processJoinRows(\n em: EntityManager,\n joinTable: string,\n rows: JoinRow[],\n preloads: Set<ManyToManyCollection<Entity, Entity>>,\n callback: (oldEntity: Entity, entities: Entity[]) => void,\n) {\n const api = getEmInternalApi(em);\n rows.forEach((row) => {\n // A join row's `columns` is always an object with two key/value pairs, one for each side of the m2m.\n // This only runs for entity-to-entity m2ms (enum m2ms are skipped by the caller), so both are entities.\n const [[col1, e1], [col2, e2]] = Object.entries(row.columns) as [[string, Entity], [string, Entity]];\n (\n [\n // Each join row needs to append/remove from both sides of the m2m. So we need to do the same operation once for\n // each side.\n [col1, e1, e2],\n [col2, e2, e1],\n ] as const\n ).forEach(([column, newEntity, newOther]) => {\n const { idTagged: id } = newEntity;\n const oldEntity = em.findExistingInstance(id)!;\n if (oldEntity.isDeletedEntity) return;\n const newM2m = getManyToManys(newEntity).find((r) => r.joinTableName === joinTable && r.columnName === column)!;\n const { fieldName } = newM2m;\n const oldM2m = (oldEntity as any)[fieldName] as ManyToManyCollection<Entity, Entity>;\n let entities: Entity[];\n if (preloads.has(oldM2m)) {\n // If a previous join row has already preloaded this relation, then we can just append/remove from the\n // existing preloaded data.\n entities = api.getPreloadedRelation(id, fieldName) as Entity[];\n } else if (oldM2m.isLoaded) {\n // The order here is important. M2ms are returned in the order their join rows were inserted, so we need to\n // make sure we match that behavior here. So we get all the extant rows first and then append each new row\n // in order from there. Removals are fine since they'll modify the array in place and the correct order will\n // be preserved.\n entities = oldM2m.get;\n } else if (newEntity.isNewEntity) {\n // If this is a new entity, then all the join rows referencing it must also be inserts. So we can just use an\n // empty array initially and inserts will be appended to it.\n entities = [];\n } else {\n fail(`Expected ${fieldName} to be loaded`);\n }\n callback(em.findExistingInstance(newOther.idTagged)!, entities);\n api.setPreloadedRelation(id, fieldName, entities);\n // We only need to preload the m2m once, but multiple join rows could reference it, so we keep track of which m2ms\n // need to be preloaded as we work, then actually call preload() at the end once we're done.\n preloads.add(oldM2m);\n });\n });\n}\n\nfunction getReferences(entity: Entity): IteratorObject<ConcreteReference> {\n return getRelations(entity)\n .values()\n .filter(\n (r) =>\n r instanceof ManyToOneReferenceImpl ||\n r instanceof ReactiveReferenceImpl ||\n r instanceof PolymorphicReferenceImpl,\n );\n}\n\nfunction getManyToManys(\n entity: Entity,\n): IteratorObject<\n | ManyToManyCollection<Entity, Entity>\n | ReactiveManyToManyImpl<any, any, any>\n | ReactiveManyToManyOtherSideImpl<any, any>\n> {\n return getRelations(entity)\n .values()\n .filter(\n (r) =>\n r instanceof ManyToManyCollection ||\n r instanceof ReactiveManyToManyImpl ||\n r instanceof ReactiveManyToManyOtherSideImpl,\n );\n}\n\nfunction getCollections(entity: Entity) {\n return getRelations(entity)\n .values()\n .filter(\n (r) =>\n r instanceof ManyToManyCollection ||\n r instanceof OneToManyCollection ||\n r instanceof OneToOneReferenceImpl ||\n r instanceof ReactiveManyToManyImpl ||\n r instanceof ReactiveManyToManyOtherSideImpl ||\n r instanceof EnumCollectionImpl,\n );\n}\n"],"mappings":";;AAkCA,IAAa,YAAb,cAA+B,OAAO;CAGR;CAA5B,YAAY,IAAmC;EAC7C,MAAM;EADoB,KAAA,KAAA;CAE5B;CAEA,qBAAqB;EACnB,OAAO;CACT;CAEA,WAAW,aAAmC,cAA2C;EACvF,MAAM,MAAM,iBAAiB,KAAK,EAAE;EAEpC,IAAI,wBAAwB;EAE5B,IAAI,iBAAiB;EACrB,KAAKA,gBAAgB,WAAW;EAChC,KAAKC,gBAAgB,WAAW;EAChC,KAAKC,iBAAiB,YAAY;EAClC,KAAKC,qBAAqB,YAAY;EACtC,KAAKC,0BAA0B,WAAW;CAC5C;CAEA,gBAAgB,aAAmC;EACjD,MAAM,EAAE,OAAO;EACf,OAAO,OAAO,WAAW,CAAC,CAAC,SAAS,SAAS;GAC3C,KAAK,QAAQ,SAAS,cAAc;IAClC,MAAM,MAAM,wBAAwB,WAAW,EAAE,oBAAoB,MAAM,CAAC;IAC5E,GAAG,QAAQ,UAAU,aAAoD,CAAC,GAAG,CAAC;GAChF,CAAC;GACD,KAAK,QAAQ,SAAS,cAAc;IAClC,MAAM,YAAY,GAAG,qBAAqB,UAAU,QAAQ;IAM5D,IAAI,CAAC,WAAW,KAAK,qDAAqD;IAC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,IAAI,UAAU,iBAAiB;GAE/B,MAAM,EAAE,cADO,eAAe,SAAS,CAAC,CAAC,MAAM,MAAM,EAAE,kBAAkB,aAAa,EAAE,eAAe,MAC5E;GAC3B,MAAM,SAAU,UAAkB;GAClC,IAAI;GACJ,IAAI,SAAS,IAAI,MAAM,GAGrB,WAAW,IAAI,qBAAqB,IAAI,SAAS;QAC5C,IAAI,OAAO,UAKhB,WAAW,OAAO;QACb,IAAI,UAAU,aAGnB,WAAW,CAAC;QAEZ,KAAK,YAAY,UAAU,cAAc;GAE3C,SAAS,GAAG,qBAAqB,SAAS,QAAQ,GAAI,QAAQ;GAC9D,IAAI,qBAAqB,IAAI,WAAW,QAAQ;GAGhD,SAAS,IAAI,MAAM;EACrB,CAAC;CACH,CAAC;AACH;AAEA,SAAS,cAAc,QAAmD;CACxE,OAAO,aAAa,MAAM,CAAC,CACxB,OAAO,CAAC,CACR,QACE,MACC,aAAa,0BACb,aAAa,yBACb,aAAa,wBACjB;AACJ;AAEA,SAAS,eACP,QAKA;CACA,OAAO,aAAa,MAAM,CAAC,CACxB,OAAO,CAAC,CACR,QACE,MACC,aAAa,wBACb,aAAa,0BACb,aAAa,+BACjB;AACJ;AAEA,SAAS,eAAe,QAAgB;CACtC,OAAO,aAAa,MAAM,CAAC,CACxB,OAAO,CAAC,CACR,QACE,MACC,aAAa,wBACb,aAAa,uBACb,aAAa,yBACb,aAAa,0BACb,aAAa,mCACb,aAAa,kBACjB;AACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntityManager } from "joist-core";
|
|
2
|
+
//#region src/context.d.ts
|
|
3
|
+
/** A very basic context that has `em` as the Joist `EntityManager`. */
|
|
4
|
+
type Context = {
|
|
5
|
+
em: EntityManager;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Context };
|
|
9
|
+
//# sourceMappingURL=context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.ts"],"mappings":";;;KAGY;EAAY,IAAI"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntityManager } from "joist-core";
|
|
2
|
+
//#region src/context.d.ts
|
|
3
|
+
/** A very basic context that has `em` as the Joist `EntityManager`. */
|
|
4
|
+
type Context = {
|
|
5
|
+
em: EntityManager;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Context };
|
|
9
|
+
//# sourceMappingURL=context.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.mts","names":[],"sources":["../src/context.ts"],"mappings":";;;KAGY;EAAY,IAAI"}
|
package/build/context.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=context.js.map
|
|
1
|
+
import "joist-core";
|
|
2
|
+
export {};
|
package/build/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_RunPlugin = require("./RunPlugin.cjs");
|
|
3
|
+
const require_toMatchEntity = require("./toMatchEntity.cjs");
|
|
4
|
+
const require_run = require("./run.cjs");
|
|
5
|
+
const require_seed = require("./seed.cjs");
|
|
6
|
+
let joist_core = require("joist-core");
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* A custom equality tester for Jest, i.e. install it like:
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* import { expect } from "@jest/globals";
|
|
13
|
+
* expect.addEqualityTesters([areEntitiesEqual]);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* This is necessary because Jest's `expect` uses deep equality for instances
|
|
17
|
+
* of classes, but the `__data` key marked as non-enumerable, and all properties
|
|
18
|
+
* made lazy and defined as getters on the prototype, there are no keys on the
|
|
19
|
+
* individual objects left for Jest to see & realize "these are different".
|
|
20
|
+
*/
|
|
21
|
+
function areEntitiesEqual(a, b) {
|
|
22
|
+
if (a instanceof joist_core.BaseEntity && b instanceof joist_core.BaseEntity) return a === b || a.em !== b.em && !a.isNewEntity && !b.isNewEntity && a.id === b.id;
|
|
23
|
+
else if (typeof a === "string" && b instanceof joist_core.BaseEntity) return a === b.id;
|
|
24
|
+
else if (typeof b === "string" && a instanceof joist_core.BaseEntity) return b === a.id;
|
|
25
|
+
else return;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.RunPlugin = require_RunPlugin.RunPlugin;
|
|
29
|
+
exports.areEntitiesEqual = areEntitiesEqual;
|
|
30
|
+
exports.makeRun = require_run.makeRun;
|
|
31
|
+
exports.makeRunEach = require_run.makeRunEach;
|
|
32
|
+
exports.newContext = require_run.newContext;
|
|
33
|
+
exports.run = require_run.run;
|
|
34
|
+
exports.runEach = require_run.runEach;
|
|
35
|
+
exports.seed = require_seed.seed;
|
|
36
|
+
exports.toMatchEntity = require_toMatchEntity.toMatchEntity;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BaseEntity"],"sources":["../src/index.ts"],"sourcesContent":["import { BaseEntity } from \"joist-core\";\n\nimport { type MatchedEntity } from \"./toMatchEntity.ts\";\nexport type { Context } from \"./context.ts\";\nexport { type ContextFn, makeRun, makeRunEach, newContext, run, runEach } from \"./run.ts\";\nexport { RunPlugin } from \"./RunPlugin.ts\";\nexport { seed, type SeedConfig } from \"./seed.ts\";\nexport { toMatchEntity } from \"./toMatchEntity.ts\";\n\nexport interface CustomMatcherResult {\n pass: boolean;\n message: () => string;\n}\n\ndeclare global {\n namespace jest {\n interface Matchers<R extends void | Promise<void>, T = {}> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n }\n}\n// @ts-ignore\ndeclare module \"expect\" {\n interface Matchers<R extends void | Promise<void>, T = unknown> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n}\n\n// @ts-ignore\ndeclare module \"bun:test\" {\n interface Matchers<T = unknown> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n}\n\n// @ts-ignore\ndeclare module \"vitest\" {\n interface Assertion<T = any> {\n toMatchEntity(expected: MatchedEntity<T>): void;\n }\n interface AsymmetricMatchersContaining {\n toMatchEntity(expected: MatchedEntity<any>): void;\n }\n}\n\n/**\n * A custom equality tester for Jest, i.e. install it like:\n *\n * ```\n * import { expect } from \"@jest/globals\";\n * expect.addEqualityTesters([areEntitiesEqual]);\n * ```\n *\n * This is necessary because Jest's `expect` uses deep equality for instances\n * of classes, but the `__data` key marked as non-enumerable, and all properties\n * made lazy and defined as getters on the prototype, there are no keys on the\n * individual objects left for Jest to see & realize \"these are different\".\n */\nexport function areEntitiesEqual(a: unknown, b: unknown) {\n if (a instanceof BaseEntity && b instanceof BaseEntity) {\n return a === b || (a.em !== b.em && !a.isNewEntity && !b.isNewEntity && a.id === b.id);\n } else if (typeof a === \"string\" && b instanceof BaseEntity) {\n return a === b.id;\n } else if (typeof b === \"string\" && a instanceof BaseEntity) {\n return b === a.id;\n } else {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,iBAAiB,GAAY,GAAY;CACvD,IAAI,aAAaA,WAAAA,cAAc,aAAaA,WAAAA,YAC1C,OAAO,MAAM,KAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE;MAC9E,IAAI,OAAO,MAAM,YAAY,aAAaA,WAAAA,YAC/C,OAAO,MAAM,EAAE;MACV,IAAI,OAAO,MAAM,YAAY,aAAaA,WAAAA,YAC/C,OAAO,MAAM,EAAE;MAEf;AAEJ"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RunPlugin } from "./RunPlugin.cjs";
|
|
2
|
+
import { Context } from "./context.cjs";
|
|
3
|
+
import { MatchedEntity, toMatchEntity } from "./toMatchEntity.cjs";
|
|
4
|
+
import { ContextFn, makeRun, makeRunEach, newContext, run, runEach } from "./run.cjs";
|
|
5
|
+
import { SeedConfig, seed } from "./seed.cjs";
|
|
6
|
+
//#region src/index.d.ts
|
|
7
|
+
interface CustomMatcherResult {
|
|
8
|
+
pass: boolean;
|
|
9
|
+
message: () => string;
|
|
10
|
+
}
|
|
11
|
+
declare global {
|
|
12
|
+
namespace jest {
|
|
13
|
+
interface Matchers<R extends void | Promise<void>, T = {}> {
|
|
14
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
declare module "expect" {
|
|
19
|
+
interface Matchers<R extends void | Promise<void>, T = unknown> {
|
|
20
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
declare module "bun:test" {
|
|
24
|
+
interface Matchers<T = unknown> {
|
|
25
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
declare module "vitest" {
|
|
29
|
+
interface Assertion<T = any> {
|
|
30
|
+
toMatchEntity(expected: MatchedEntity<T>): void;
|
|
31
|
+
}
|
|
32
|
+
interface AsymmetricMatchersContaining {
|
|
33
|
+
toMatchEntity(expected: MatchedEntity<any>): void;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A custom equality tester for Jest, i.e. install it like:
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* import { expect } from "@jest/globals";
|
|
41
|
+
* expect.addEqualityTesters([areEntitiesEqual]);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* This is necessary because Jest's `expect` uses deep equality for instances
|
|
45
|
+
* of classes, but the `__data` key marked as non-enumerable, and all properties
|
|
46
|
+
* made lazy and defined as getters on the prototype, there are no keys on the
|
|
47
|
+
* individual objects left for Jest to see & realize "these are different".
|
|
48
|
+
*/
|
|
49
|
+
declare function areEntitiesEqual(a: unknown, b: unknown): boolean | undefined;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { type Context, type ContextFn, CustomMatcherResult, RunPlugin, type SeedConfig, areEntitiesEqual, makeRun, makeRunEach, newContext, run, runEach, seed, toMatchEntity };
|
|
52
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;UASiB;EACf;EACA;;QAGM;YACI;cACE,SAAS,iBAAiB,eAAe;MACjD,cAAc,UAAU,cAAc,KAAK;;;;;YAMrC,SAAS,iBAAiB,eAAe;IACjD,cAAc,UAAU,cAAc,KAAK;;;;YAMnC,SAAS;IACjB,cAAc,UAAU,cAAc,KAAK;;;;YAMnC,UAAU;IAClB,cAAc,UAAU,cAAc;;YAE9B;IACR,cAAc,UAAU;;;;;;;;;;;;;;;;iBAiBZ,iBAAiB,YAAY"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RunPlugin } from "./RunPlugin.mjs";
|
|
2
|
+
import { Context } from "./context.mjs";
|
|
3
|
+
import { MatchedEntity, toMatchEntity } from "./toMatchEntity.mjs";
|
|
4
|
+
import { ContextFn, makeRun, makeRunEach, newContext, run, runEach } from "./run.mjs";
|
|
5
|
+
import { SeedConfig, seed } from "./seed.mjs";
|
|
6
|
+
//#region src/index.d.ts
|
|
7
|
+
interface CustomMatcherResult {
|
|
8
|
+
pass: boolean;
|
|
9
|
+
message: () => string;
|
|
10
|
+
}
|
|
11
|
+
declare global {
|
|
12
|
+
namespace jest {
|
|
13
|
+
interface Matchers<R extends void | Promise<void>, T = {}> {
|
|
14
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
declare module "expect" {
|
|
19
|
+
interface Matchers<R extends void | Promise<void>, T = unknown> {
|
|
20
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
declare module "bun:test" {
|
|
24
|
+
interface Matchers<T = unknown> {
|
|
25
|
+
toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
declare module "vitest" {
|
|
29
|
+
interface Assertion<T = any> {
|
|
30
|
+
toMatchEntity(expected: MatchedEntity<T>): void;
|
|
31
|
+
}
|
|
32
|
+
interface AsymmetricMatchersContaining {
|
|
33
|
+
toMatchEntity(expected: MatchedEntity<any>): void;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A custom equality tester for Jest, i.e. install it like:
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* import { expect } from "@jest/globals";
|
|
41
|
+
* expect.addEqualityTesters([areEntitiesEqual]);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* This is necessary because Jest's `expect` uses deep equality for instances
|
|
45
|
+
* of classes, but the `__data` key marked as non-enumerable, and all properties
|
|
46
|
+
* made lazy and defined as getters on the prototype, there are no keys on the
|
|
47
|
+
* individual objects left for Jest to see & realize "these are different".
|
|
48
|
+
*/
|
|
49
|
+
declare function areEntitiesEqual(a: unknown, b: unknown): boolean | undefined;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { type Context, type ContextFn, CustomMatcherResult, RunPlugin, type SeedConfig, areEntitiesEqual, makeRun, makeRunEach, newContext, run, runEach, seed, toMatchEntity };
|
|
52
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;UASiB;EACf;EACA;;QAGM;YACI;cACE,SAAS,iBAAiB,eAAe;MACjD,cAAc,UAAU,cAAc,KAAK;;;;;YAMrC,SAAS,iBAAiB,eAAe;IACjD,cAAc,UAAU,cAAc,KAAK;;;;YAMnC,SAAS;IACjB,cAAc,UAAU,cAAc,KAAK;;;;YAMnC,UAAU;IAClB,cAAc,UAAU,cAAc;;YAE9B;IACR,cAAc,UAAU;;;;;;;;;;;;;;;;iBAiBZ,iBAAiB,YAAY"}
|
package/build/index.js
CHANGED
|
@@ -1,45 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "makeRun", { enumerable: true, get: function () { return run_1.makeRun; } });
|
|
8
|
-
Object.defineProperty(exports, "makeRunEach", { enumerable: true, get: function () { return run_1.makeRunEach; } });
|
|
9
|
-
Object.defineProperty(exports, "newContext", { enumerable: true, get: function () { return run_1.newContext; } });
|
|
10
|
-
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
|
|
11
|
-
Object.defineProperty(exports, "runEach", { enumerable: true, get: function () { return run_1.runEach; } });
|
|
12
|
-
var RunPlugin_1 = require("./RunPlugin");
|
|
13
|
-
Object.defineProperty(exports, "RunPlugin", { enumerable: true, get: function () { return RunPlugin_1.RunPlugin; } });
|
|
14
|
-
var seed_1 = require("./seed");
|
|
15
|
-
Object.defineProperty(exports, "seed", { enumerable: true, get: function () { return seed_1.seed; } });
|
|
16
|
-
var toMatchEntity_1 = require("./toMatchEntity");
|
|
17
|
-
Object.defineProperty(exports, "toMatchEntity", { enumerable: true, get: function () { return toMatchEntity_1.toMatchEntity; } });
|
|
1
|
+
import { RunPlugin } from "./RunPlugin.js";
|
|
2
|
+
import { toMatchEntity } from "./toMatchEntity.js";
|
|
3
|
+
import { makeRun, makeRunEach, newContext, run, runEach } from "./run.js";
|
|
4
|
+
import { seed } from "./seed.js";
|
|
5
|
+
import { BaseEntity } from "joist-core";
|
|
6
|
+
//#region src/index.ts
|
|
18
7
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
* A custom equality tester for Jest, i.e. install it like:
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* import { expect } from "@jest/globals";
|
|
12
|
+
* expect.addEqualityTesters([areEntitiesEqual]);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* This is necessary because Jest's `expect` uses deep equality for instances
|
|
16
|
+
* of classes, but the `__data` key marked as non-enumerable, and all properties
|
|
17
|
+
* made lazy and defined as getters on the prototype, there are no keys on the
|
|
18
|
+
* individual objects left for Jest to see & realize "these are different".
|
|
19
|
+
*/
|
|
31
20
|
function areEntitiesEqual(a, b) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return a === b.id;
|
|
37
|
-
}
|
|
38
|
-
else if (typeof b === "string" && a instanceof joist_core_1.BaseEntity) {
|
|
39
|
-
return b === a.id;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
21
|
+
if (a instanceof BaseEntity && b instanceof BaseEntity) return a === b || a.em !== b.em && !a.isNewEntity && !b.isNewEntity && a.id === b.id;
|
|
22
|
+
else if (typeof a === "string" && b instanceof BaseEntity) return a === b.id;
|
|
23
|
+
else if (typeof b === "string" && a instanceof BaseEntity) return b === a.id;
|
|
24
|
+
else return;
|
|
44
25
|
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { RunPlugin, areEntitiesEqual, makeRun, makeRunEach, newContext, run, runEach, seed, toMatchEntity };
|
|
28
|
+
|
|
45
29
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { BaseEntity } from \"joist-core\";\n\nimport { type MatchedEntity } from \"./toMatchEntity.ts\";\nexport type { Context } from \"./context.ts\";\nexport { type ContextFn, makeRun, makeRunEach, newContext, run, runEach } from \"./run.ts\";\nexport { RunPlugin } from \"./RunPlugin.ts\";\nexport { seed, type SeedConfig } from \"./seed.ts\";\nexport { toMatchEntity } from \"./toMatchEntity.ts\";\n\nexport interface CustomMatcherResult {\n pass: boolean;\n message: () => string;\n}\n\ndeclare global {\n namespace jest {\n interface Matchers<R extends void | Promise<void>, T = {}> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n }\n}\n// @ts-ignore\ndeclare module \"expect\" {\n interface Matchers<R extends void | Promise<void>, T = unknown> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n}\n\n// @ts-ignore\ndeclare module \"bun:test\" {\n interface Matchers<T = unknown> {\n toMatchEntity(expected: MatchedEntity<T>): CustomMatcherResult;\n }\n}\n\n// @ts-ignore\ndeclare module \"vitest\" {\n interface Assertion<T = any> {\n toMatchEntity(expected: MatchedEntity<T>): void;\n }\n interface AsymmetricMatchersContaining {\n toMatchEntity(expected: MatchedEntity<any>): void;\n }\n}\n\n/**\n * A custom equality tester for Jest, i.e. install it like:\n *\n * ```\n * import { expect } from \"@jest/globals\";\n * expect.addEqualityTesters([areEntitiesEqual]);\n * ```\n *\n * This is necessary because Jest's `expect` uses deep equality for instances\n * of classes, but the `__data` key marked as non-enumerable, and all properties\n * made lazy and defined as getters on the prototype, there are no keys on the\n * individual objects left for Jest to see & realize \"these are different\".\n */\nexport function areEntitiesEqual(a: unknown, b: unknown) {\n if (a instanceof BaseEntity && b instanceof BaseEntity) {\n return a === b || (a.em !== b.em && !a.isNewEntity && !b.isNewEntity && a.id === b.id);\n } else if (typeof a === \"string\" && b instanceof BaseEntity) {\n return a === b.id;\n } else if (typeof b === \"string\" && a instanceof BaseEntity) {\n return b === a.id;\n } else {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,iBAAiB,GAAY,GAAY;CACvD,IAAI,aAAa,cAAc,aAAa,YAC1C,OAAO,MAAM,KAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE;MAC9E,IAAI,OAAO,MAAM,YAAY,aAAa,YAC/C,OAAO,MAAM,EAAE;MACV,IAAI,OAAO,MAAM,YAAY,aAAa,YAC/C,OAAO,MAAM,EAAE;MAEf;AAEJ"}
|
package/build/run.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_RunPlugin = require("./RunPlugin.cjs");
|
|
3
|
+
require("./context.cjs");
|
|
4
|
+
let joist_core = require("joist-core");
|
|
5
|
+
let joist_utils = require("joist-utils");
|
|
6
|
+
//#region src/run.ts
|
|
7
|
+
let flushPromise;
|
|
8
|
+
let flushEm;
|
|
9
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work . */
|
|
10
|
+
async function run(ctx, fn, contextFn = newContext) {
|
|
11
|
+
const { em } = ctx;
|
|
12
|
+
try {
|
|
13
|
+
flushPromise ??= em.flush();
|
|
14
|
+
flushEm ??= em;
|
|
15
|
+
if (flushEm !== em) (0, joist_utils.fail)("cannot use run in parallel with multiple entity managers");
|
|
16
|
+
await flushPromise;
|
|
17
|
+
} finally {
|
|
18
|
+
flushPromise = void 0;
|
|
19
|
+
flushEm = void 0;
|
|
20
|
+
}
|
|
21
|
+
const newCtx = await contextFn(ctx);
|
|
22
|
+
const plugin = new require_RunPlugin.RunPlugin(em);
|
|
23
|
+
newCtx.em.addPlugin(plugin);
|
|
24
|
+
return mapResultToOriginalEm(em, await fn(newCtx));
|
|
25
|
+
}
|
|
26
|
+
/** Creates a `run` with a custom `newContext` method. */
|
|
27
|
+
function makeRun(contextFn) {
|
|
28
|
+
return (ctx, fn) => run(ctx, fn, contextFn);
|
|
29
|
+
}
|
|
30
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */
|
|
31
|
+
async function runEach(ctx, valuesFn, fn, contextFn = newContext) {
|
|
32
|
+
const { em } = ctx;
|
|
33
|
+
await em.flush();
|
|
34
|
+
const plugin = new require_RunPlugin.RunPlugin(em);
|
|
35
|
+
return mapResultToOriginalEm(em, await Promise.all(valuesFn().map(async (value) => {
|
|
36
|
+
const newCtx = await contextFn(ctx);
|
|
37
|
+
newCtx.em.addPlugin(plugin);
|
|
38
|
+
return fn(newCtx, value);
|
|
39
|
+
})));
|
|
40
|
+
}
|
|
41
|
+
/** Creates a `runEach` with a custom `newContext` method. */
|
|
42
|
+
function makeRunEach(contextFn) {
|
|
43
|
+
return (ctx, valuesFn, fn) => runEach(ctx, valuesFn, fn, contextFn);
|
|
44
|
+
}
|
|
45
|
+
/** A default `newContext` that assumes `ctx.em` is where the `EntityManager` lives. */
|
|
46
|
+
function newContext(ctx) {
|
|
47
|
+
const { em } = ctx;
|
|
48
|
+
const newCtx = { ...ctx };
|
|
49
|
+
const newEm = new joist_core.EntityManager(newCtx, em.driver);
|
|
50
|
+
Object.assign(newCtx, { em: newEm });
|
|
51
|
+
return newCtx;
|
|
52
|
+
}
|
|
53
|
+
function mapResultToOriginalEm(em, result) {
|
|
54
|
+
if ((0, joist_core.isEntity)(result)) return em.findExistingInstance(result.idTagged) ?? (0, joist_utils.fail)(`Could not find entity ${result.idTagged}`);
|
|
55
|
+
else if (Array.isArray(result)) return result.map((r) => mapResultToOriginalEm(em, r));
|
|
56
|
+
else if (result instanceof Map) {
|
|
57
|
+
const map = /* @__PURE__ */ new Map();
|
|
58
|
+
result.entries().forEach(([key, value]) => map.set(mapResultToOriginalEm(em, key), mapResultToOriginalEm(em, value)));
|
|
59
|
+
return map;
|
|
60
|
+
} else if (result instanceof Set) {
|
|
61
|
+
const set = /* @__PURE__ */ new Set();
|
|
62
|
+
result.forEach((r) => set.add(mapResultToOriginalEm(em, r)));
|
|
63
|
+
return set;
|
|
64
|
+
} else if (typeof result === "object" && result?.constructor === Object) {
|
|
65
|
+
const obj = {};
|
|
66
|
+
Object.entries(result).forEach(([key, value]) => obj[key] = mapResultToOriginalEm(em, value));
|
|
67
|
+
return obj;
|
|
68
|
+
} else return result;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.makeRun = makeRun;
|
|
72
|
+
exports.makeRunEach = makeRunEach;
|
|
73
|
+
exports.newContext = newContext;
|
|
74
|
+
exports.run = run;
|
|
75
|
+
exports.runEach = runEach;
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=run.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.cjs","names":["RunPlugin","EntityManager","isEntity","fail"],"sources":["../src/run.ts"],"sourcesContent":["import { EntityManager, isEntity } from \"joist-core\";\nimport { fail } from \"joist-utils\";\n\nimport { type Context } from \"./context.ts\";\nimport { RunPlugin } from \"./RunPlugin.ts\";\n\ntype MaybePromise<T> = T | Promise<T>;\n\nexport type ContextFn<C> = (ctx: C) => MaybePromise<C>;\n\n// Used to allow non-mutating run... calls to be run in parallel.\nlet flushPromise: Promise<any> | undefined;\nlet flushEm: EntityManager | undefined;\n\n/** Runs the `fn` in a dedicated / non-test Unit of Work . */\nexport async function run<C extends Context, T>(\n ctx: C,\n fn: (ctx: C) => MaybePromise<T>,\n contextFn: ContextFn<C> = newContext,\n): Promise<T> {\n const { em } = ctx;\n // Ensure any test data we've set up is flushed. If another invocation of `run` is already flushing, then we can just\n // wait on its promise. Otherwise, we will get flushLock errors.\n try {\n flushPromise ??= em.flush();\n flushEm ??= em;\n if (flushEm !== em) fail(\"cannot use run in parallel with multiple entity managers\");\n await flushPromise;\n } finally {\n flushPromise = undefined;\n flushEm = undefined;\n }\n const newCtx = await contextFn(ctx);\n const plugin = new RunPlugin(em);\n newCtx.em.addPlugin(plugin);\n const result = await fn(newCtx);\n // We expect `fn` (i.e. a resolver) to do its own UoW management, so don't flush.\n return mapResultToOriginalEm(em, result);\n}\n\n/** Creates a `run` with a custom `newContext` method. */\nexport function makeRun<C extends Context>(\n contextFn: ContextFn<C>,\n): <T>(ctx: C, fn: (ctx: C) => MaybePromise<T>) => Promise<T> {\n return (ctx, fn) => run(ctx, fn, contextFn);\n}\n\n/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */\nexport async function runEach<C extends Context, T, U>(\n ctx: C,\n valuesFn: () => U[],\n fn: (ctx: C, value: U) => MaybePromise<T>,\n contextFn: ContextFn<C> = newContext,\n): Promise<T[]> {\n const { em } = ctx;\n // Ensure any test data we've setup is flushed\n await em.flush();\n const plugin = new RunPlugin(em);\n const results = await Promise.all(\n valuesFn().map(async (value) => {\n const newCtx = await contextFn(ctx);\n newCtx.em.addPlugin(plugin);\n return fn(newCtx, value);\n }),\n );\n return mapResultToOriginalEm(em, results);\n}\n\n/** Creates a `runEach` with a custom `newContext` method. */\nexport function makeRunEach<C extends Context>(\n contextFn: ContextFn<C>,\n): <T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>) => Promise<T[]> {\n return (ctx, valuesFn, fn) => runEach(ctx, valuesFn, fn, contextFn);\n}\n\n/** A default `newContext` that assumes `ctx.em` is where the `EntityManager` lives. */\nexport function newContext<C extends Context>(ctx: C): C {\n const { em } = ctx;\n const newCtx = { ...ctx };\n const newEm = new EntityManager(newCtx, em.driver);\n Object.assign(newCtx, { em: newEm });\n return newCtx;\n}\n\n/* Returns a copy of `result` with all entities replaced with their instance from the original `em`. We assume that\n * RunPlugin has been installed prior to this call, so any entities we encounter should be present in both ems. */\nfunction mapResultToOriginalEm<R>(em: EntityManager, result: R): R {\n if (isEntity(result)) {\n return (em.findExistingInstance(result.idTagged) ?? fail(`Could not find entity ${result.idTagged}`)) as R;\n } else if (Array.isArray(result)) {\n return result.map((r) => mapResultToOriginalEm(em, r)) as any;\n } else if (result instanceof Map) {\n const map = new Map<any, any>();\n result\n .entries()\n .forEach(([key, value]) => map.set(mapResultToOriginalEm(em, key), mapResultToOriginalEm(em, value)));\n return map as R;\n } else if (result instanceof Set) {\n const set = new Set<any>();\n result.forEach((r) => set.add(mapResultToOriginalEm(em, r)));\n return set as R;\n } else if (typeof result === \"object\" && result?.constructor === Object) {\n const obj = {} as any;\n Object.entries(result).forEach(([key, value]: [string, any]) => (obj[key] = mapResultToOriginalEm(em, value)));\n return obj;\n } else {\n return result;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAI;AACJ,IAAI;;AAG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GACjB,OAAQ,GAAG,qBAAqB,OAAO,QAAQ,MAAA,GAAKC,YAAAA,KAAAA,CAAK,yBAAyB,OAAO,UAAU;MAC9F,IAAI,MAAM,QAAQ,MAAM,GAC7B,OAAO,OAAO,KAAK,MAAM,sBAAsB,IAAI,CAAC,CAAC;MAChD,IAAI,kBAAkB,KAAK;EAChC,MAAM,sBAAM,IAAI,IAAc;EAC9B,OACG,QAAQ,CAAC,CACT,SAAS,CAAC,KAAK,WAAW,IAAI,IAAI,sBAAsB,IAAI,GAAG,GAAG,sBAAsB,IAAI,KAAK,CAAC,CAAC;EACtG,OAAO;CACT,OAAO,IAAI,kBAAkB,KAAK;EAChC,MAAM,sBAAM,IAAI,IAAS;EACzB,OAAO,SAAS,MAAM,IAAI,IAAI,sBAAsB,IAAI,CAAC,CAAC,CAAC;EAC3D,OAAO;CACT,OAAO,IAAI,OAAO,WAAW,YAAY,QAAQ,gBAAgB,QAAQ;EACvE,MAAM,MAAM,CAAC;EACb,OAAO,QAAQ,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,WAA2B,IAAI,OAAO,sBAAsB,IAAI,KAAK,CAAE;EAC7G,OAAO;CACT,OACE,OAAO;AAEX"}
|
package/build/run.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from "./context.cjs";
|
|
2
|
+
//#region src/run.d.ts
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
type ContextFn<C> = (ctx: C) => MaybePromise<C>;
|
|
5
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work . */
|
|
6
|
+
declare function run<C extends Context, T>(ctx: C, fn: (ctx: C) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T>;
|
|
7
|
+
/** Creates a `run` with a custom `newContext` method. */
|
|
8
|
+
declare function makeRun<C extends Context>(contextFn: ContextFn<C>): <T>(ctx: C, fn: (ctx: C) => MaybePromise<T>) => Promise<T>;
|
|
9
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */
|
|
10
|
+
declare function runEach<C extends Context, T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T[]>;
|
|
11
|
+
/** Creates a `runEach` with a custom `newContext` method. */
|
|
12
|
+
declare function makeRunEach<C extends Context>(contextFn: ContextFn<C>): <T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>) => Promise<T[]>;
|
|
13
|
+
/** A default `newContext` that assumes `ctx.em` is where the `EntityManager` lives. */
|
|
14
|
+
declare function newContext<C extends Context>(ctx: C): C;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ContextFn, makeRun, makeRunEach, newContext, run, runEach };
|
|
17
|
+
//# sourceMappingURL=run.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.cts","names":[],"sources":["../src/run.ts"],"mappings":";;KAMK,aAAa,KAAK,IAAI,QAAQ;KAEvB,UAAU,MAAM,KAAK,MAAM,aAAa;;iBAO9B,IAAI,UAAU,SAAS,GAC3C,KAAK,GACL,KAAK,KAAK,MAAM,aAAa,IAC7B,YAAW,UAAU,KACpB,QAAQ;;iBAsBK,QAAQ,UAAU,SAChC,WAAW,UAAU,MACnB,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,aAAa,OAAO,QAAQ;;iBAKrC,QAAQ,UAAU,SAAS,GAAG,GAClD,KAAK,GACL,gBAAgB,KAChB,KAAK,KAAK,GAAG,OAAO,MAAM,aAAa,IACvC,YAAW,UAAU,KACpB,QAAQ;;iBAgBK,YAAY,UAAU,SACpC,WAAW,UAAU,MACnB,GAAG,GAAG,KAAK,GAAG,gBAAgB,KAAK,KAAK,KAAK,GAAG,OAAO,MAAM,aAAa,OAAO,QAAQ;;iBAK7E,WAAW,UAAU,SAAS,KAAK,IAAI"}
|
package/build/run.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from "./context.mjs";
|
|
2
|
+
//#region src/run.d.ts
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
type ContextFn<C> = (ctx: C) => MaybePromise<C>;
|
|
5
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work . */
|
|
6
|
+
declare function run<C extends Context, T>(ctx: C, fn: (ctx: C) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T>;
|
|
7
|
+
/** Creates a `run` with a custom `newContext` method. */
|
|
8
|
+
declare function makeRun<C extends Context>(contextFn: ContextFn<C>): <T>(ctx: C, fn: (ctx: C) => MaybePromise<T>) => Promise<T>;
|
|
9
|
+
/** Runs the `fn` in a dedicated / non-test Unit of Work for each value in `values */
|
|
10
|
+
declare function runEach<C extends Context, T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>, contextFn?: ContextFn<C>): Promise<T[]>;
|
|
11
|
+
/** Creates a `runEach` with a custom `newContext` method. */
|
|
12
|
+
declare function makeRunEach<C extends Context>(contextFn: ContextFn<C>): <T, U>(ctx: C, valuesFn: () => U[], fn: (ctx: C, value: U) => MaybePromise<T>) => Promise<T[]>;
|
|
13
|
+
/** A default `newContext` that assumes `ctx.em` is where the `EntityManager` lives. */
|
|
14
|
+
declare function newContext<C extends Context>(ctx: C): C;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ContextFn, makeRun, makeRunEach, newContext, run, runEach };
|
|
17
|
+
//# sourceMappingURL=run.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.mts","names":[],"sources":["../src/run.ts"],"mappings":";;KAMK,aAAa,KAAK,IAAI,QAAQ;KAEvB,UAAU,MAAM,KAAK,MAAM,aAAa;;iBAO9B,IAAI,UAAU,SAAS,GAC3C,KAAK,GACL,KAAK,KAAK,MAAM,aAAa,IAC7B,YAAW,UAAU,KACpB,QAAQ;;iBAsBK,QAAQ,UAAU,SAChC,WAAW,UAAU,MACnB,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,aAAa,OAAO,QAAQ;;iBAKrC,QAAQ,UAAU,SAAS,GAAG,GAClD,KAAK,GACL,gBAAgB,KAChB,KAAK,KAAK,GAAG,OAAO,MAAM,aAAa,IACvC,YAAW,UAAU,KACpB,QAAQ;;iBAgBK,YAAY,UAAU,SACpC,WAAW,UAAU,MACnB,GAAG,GAAG,KAAK,GAAG,gBAAgB,KAAK,KAAK,KAAK,GAAG,OAAO,MAAM,aAAa,OAAO,QAAQ;;iBAK7E,WAAW,UAAU,SAAS,KAAK,IAAI"}
|