joist-core 2.5.0-next.10 → 2.5.0-next.11
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/build/batchloaders/recursiveChildrenBatchLoader.cjs +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.js +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.cjs +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.js +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveChildrenBatchLoader.cjs","names":["getMetadataForType","abbreviation","kq","deTagIds","groupBy","maybeResolveReferenceToId","getField","isLoadedCollection","isLoadedOneToOneReference"],"sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager, getEmInternalApi } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type OneToManyField,\n type OneToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n isLoadedCollection,\n isLoadedOneToOneReference,\n kq,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { type RecursiveChildrenCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation, groupBy } from \"src/utils.ts\";\n\nexport const recursiveChildrenOperation = \"o2m-recursive\";\n\nexport function recursiveChildrenBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveChildrenCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root o2m field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.o2mFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveChildrenOperation, batchKey, async (parents) => {\n const o2m = meta.allFields[collection.o2mFieldName] as OneToManyField | OneToOneField;\n const m2o = meta.allFields[o2m.otherFieldName] as ManyToOneField;\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {
|
|
1
|
+
{"version":3,"file":"recursiveChildrenBatchLoader.cjs","names":["getMetadataForType","abbreviation","kq","deTagIds","groupBy","maybeResolveReferenceToId","getField","isLoadedCollection","isLoadedOneToOneReference"],"sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager, getEmInternalApi } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type OneToManyField,\n type OneToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n isLoadedCollection,\n isLoadedOneToOneReference,\n kq,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { type RecursiveChildrenCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation, groupBy } from \"src/utils.ts\";\n\nexport const recursiveChildrenOperation = \"o2m-recursive\";\n\nexport function recursiveChildrenBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveChildrenCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root o2m field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.o2mFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveChildrenOperation, batchKey, async (parents) => {\n const o2m = meta.allFields[collection.o2mFieldName] as OneToManyField | OneToOneField;\n const m2o = meta.allFields[o2m.otherFieldName] as ManyToOneField;\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {\n alias: `${alias}_cte`,\n join: \"inner\",\n table: `${alias}_cte`,\n col1: `${kq(alias)}.id`,\n col2: `${alias}_cte.id`,\n },\n ],\n orderBys: [{ alias, column: \"id\", order: \"ASC\" }],\n ctes: [\n {\n alias: `${alias}_cte`,\n query: {\n kind: \"raw\",\n // b is our base case, which is the immediate children of the parents, and r is the\n // recursive case of finding their children.\n sql: `\n SELECT b.id, b.${columnName} FROM ${kq(meta.tableName)} b WHERE b.${columnName} = ANY(?)\n UNION\n SELECT r.id, r.${columnName} FROM ${kq(meta.tableName)} r JOIN ${alias}_cte ON r.${columnName} = ${alias}_cte.id\n `,\n // RecursiveChildrenCollectionImpl won't call `.load` on new entities, so we can assume entities have an id\n bindings: [\n deTagIds(\n meta,\n parents.map((e) => e.idTagged),\n ),\n ],\n },\n recursive: true,\n },\n ],\n };\n\n addTablePerClassJoinsAndClassTag(query, meta, alias, true);\n\n const rowData = await em[\"executeFindRowData\"](meta, recursiveChildrenOperation, query, {});\n const entities = em[\"hydrateAndFinalize\"](meta.cstr, rowData);\n\n // For all the entities we found, group them by their parent (or the root node, which has no parent)\n const entitiesById = groupBy(entities, (entity) => {\n const parentId = maybeResolveReferenceToId(getField(entity, m2o.fieldName));\n return parentId ?? \"root\";\n });\n\n // For each found parent, use the preloading infra to inject the children into the relation\n for (const [parentId, children] of entitiesById) {\n if (parentId !== \"root\") {\n getEmInternalApi(em).setPreloadedRelation(parentId, o2m.fieldName, children);\n // I thought we could delay calling this, but currently `em.populate` calls `preload()` explicitly\n (em.getEntity(parentId) as any)[o2m.fieldName].preload();\n }\n }\n\n // Any entity[o2m] still not loaded must be a leaf which didn't have any children; go ahead and mark it as loaded\n for (const entity of [...parents, ...entities]) {\n if (!isLoadedCollection(entity[o2m.fieldName]) && !isLoadedOneToOneReference(entity[o2m.fieldName])) {\n getEmInternalApi(em).setPreloadedRelation(entity.id, o2m.fieldName, []);\n entity[o2m.fieldName].preload();\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,MAAa,6BAA6B;AAE1C,SAAgB,6BACd,IACA,YACqB;CACrB,IAAI,EAAE,MAAM,cAAc;CAK1B,OAAO,EAAE,WAAW,gBAAgB,KAAK,WAAW,KAAK,UAAU,OAAOA,kBAAAA,mBAAmB,KAAK,QAAQ;CAC1G,MAAM,WAAW,GAAG,KAAK,UAAU,GAAG;CACtC,OAAO,GAAG,eAAe,4BAA4B,UAAU,OAAO,YAAY;EAChF,MAAM,MAAM,KAAK,UAAU,WAAW;EACtC,MAAM,MAAM,KAAK,UAAU,IAAI;EAC/B,MAAM,EAAE,eAAe,IAAI,MAAM,QAAQ;EAEzC,MAAM,QAAQC,cAAAA,aAAa,KAAK,SAAS;EACzC,MAAM,QAAyB;GAC7B,SAAS,CAAC,IAAI,MAAM,IAAI;GACxB,QAAQ,CAGN;IAAE;IAAO,MAAM;IAAW,OAAO,KAAK;GA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AG;GACnG,sBAAA,iBAAiB,EAAE,CAAC,CAAC,qBAAqB,OAAO,IAAI,IAAI,WAAW,CAAC,CAAC;GACtE,OAAO,IAAI,UAAU,CAAC,QAAQ;EAChC;CAEJ,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveChildrenBatchLoader.js","names":[],"sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager, getEmInternalApi } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type OneToManyField,\n type OneToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n isLoadedCollection,\n isLoadedOneToOneReference,\n kq,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { type RecursiveChildrenCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation, groupBy } from \"src/utils.ts\";\n\nexport const recursiveChildrenOperation = \"o2m-recursive\";\n\nexport function recursiveChildrenBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveChildrenCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root o2m field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.o2mFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveChildrenOperation, batchKey, async (parents) => {\n const o2m = meta.allFields[collection.o2mFieldName] as OneToManyField | OneToOneField;\n const m2o = meta.allFields[o2m.otherFieldName] as ManyToOneField;\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {
|
|
1
|
+
{"version":3,"file":"recursiveChildrenBatchLoader.js","names":[],"sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager, getEmInternalApi } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type OneToManyField,\n type OneToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n isLoadedCollection,\n isLoadedOneToOneReference,\n kq,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { type RecursiveChildrenCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation, groupBy } from \"src/utils.ts\";\n\nexport const recursiveChildrenOperation = \"o2m-recursive\";\n\nexport function recursiveChildrenBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveChildrenCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root o2m field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.o2mFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveChildrenOperation, batchKey, async (parents) => {\n const o2m = meta.allFields[collection.o2mFieldName] as OneToManyField | OneToOneField;\n const m2o = meta.allFields[o2m.otherFieldName] as ManyToOneField;\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {\n alias: `${alias}_cte`,\n join: \"inner\",\n table: `${alias}_cte`,\n col1: `${kq(alias)}.id`,\n col2: `${alias}_cte.id`,\n },\n ],\n orderBys: [{ alias, column: \"id\", order: \"ASC\" }],\n ctes: [\n {\n alias: `${alias}_cte`,\n query: {\n kind: \"raw\",\n // b is our base case, which is the immediate children of the parents, and r is the\n // recursive case of finding their children.\n sql: `\n SELECT b.id, b.${columnName} FROM ${kq(meta.tableName)} b WHERE b.${columnName} = ANY(?)\n UNION\n SELECT r.id, r.${columnName} FROM ${kq(meta.tableName)} r JOIN ${alias}_cte ON r.${columnName} = ${alias}_cte.id\n `,\n // RecursiveChildrenCollectionImpl won't call `.load` on new entities, so we can assume entities have an id\n bindings: [\n deTagIds(\n meta,\n parents.map((e) => e.idTagged),\n ),\n ],\n },\n recursive: true,\n },\n ],\n };\n\n addTablePerClassJoinsAndClassTag(query, meta, alias, true);\n\n const rowData = await em[\"executeFindRowData\"](meta, recursiveChildrenOperation, query, {});\n const entities = em[\"hydrateAndFinalize\"](meta.cstr, rowData);\n\n // For all the entities we found, group them by their parent (or the root node, which has no parent)\n const entitiesById = groupBy(entities, (entity) => {\n const parentId = maybeResolveReferenceToId(getField(entity, m2o.fieldName));\n return parentId ?? \"root\";\n });\n\n // For each found parent, use the preloading infra to inject the children into the relation\n for (const [parentId, children] of entitiesById) {\n if (parentId !== \"root\") {\n getEmInternalApi(em).setPreloadedRelation(parentId, o2m.fieldName, children);\n // I thought we could delay calling this, but currently `em.populate` calls `preload()` explicitly\n (em.getEntity(parentId) as any)[o2m.fieldName].preload();\n }\n }\n\n // Any entity[o2m] still not loaded must be a leaf which didn't have any children; go ahead and mark it as loaded\n for (const entity of [...parents, ...entities]) {\n if (!isLoadedCollection(entity[o2m.fieldName]) && !isLoadedOneToOneReference(entity[o2m.fieldName])) {\n getEmInternalApi(em).setPreloadedRelation(entity.id, o2m.fieldName, []);\n entity[o2m.fieldName].preload();\n }\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAa,6BAA6B;AAE1C,SAAgB,6BACd,IACA,YACqB;CACrB,IAAI,EAAE,MAAM,cAAc;CAK1B,OAAO,EAAE,WAAW,gBAAgB,KAAK,WAAW,KAAK,UAAU,OAAO,mBAAmB,KAAK,QAAQ;CAC1G,MAAM,WAAW,GAAG,KAAK,UAAU,GAAG;CACtC,OAAO,GAAG,eAAe,4BAA4B,UAAU,OAAO,YAAY;EAChF,MAAM,MAAM,KAAK,UAAU,WAAW;EACtC,MAAM,MAAM,KAAK,UAAU,IAAI;EAC/B,MAAM,EAAE,eAAe,IAAI,MAAM,QAAQ;EAEzC,MAAM,QAAQ,aAAa,KAAK,SAAS;EACzC,MAAM,QAAyB;GAC7B,SAAS,CAAC,IAAI,MAAM,IAAI;GACxB,QAAQ,CAGN;IAAE;IAAO,MAAM;IAAW,OAAO,KAAK;GAAU,GAChD;IACE,OAAO,GAAG,MAAM;IAChB,MAAM;IACN,OAAO,GAAG,MAAM;IAChB,MAAM,GAAG,GAAG,KAAK,EAAE;IACnB,MAAM,GAAG,MAAM;GACjB,CACF;GACA,UAAU,CAAC;IAAE;IAAO,QAAQ;IAAM,OAAO;GAAM,CAAC;GAChD,MAAM,CACJ;IACE,OAAO,GAAG,MAAM;IAChB,OAAO;KACL,MAAM;KAGN,KAAK;8BACa,WAAW,QAAQ,GAAG,KAAK,SAAS,EAAE,aAAa,WAAW;;8BAE9D,WAAW,QAAQ,GAAG,KAAK,SAAS,EAAE,UAAU,MAAM,YAAY,WAAW,KAAK,MAAM;;KAG1G,UAAU,CACR,SACE,MACA,QAAQ,KAAK,MAAM,EAAE,QAAQ,CAC/B,CACF;IACF;IACA,WAAW;GACb,CACF;EACF;EAEA,iCAAiC,OAAO,MAAM,OAAO,IAAI;EAEzD,MAAM,UAAU,MAAM,GAAG,qBAAqB,CAAC,MAAM,4BAA4B,OAAO,CAAC,CAAC;EAC1F,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,MAAM,OAAO;EAG5D,MAAM,eAAe,QAAQ,WAAW,WAAW;GAEjD,OADiB,0BAA0B,SAAS,QAAQ,IAAI,SAAS,CAC3D,KAAK;EACrB,CAAC;EAGD,KAAK,MAAM,CAAC,UAAU,aAAa,cACjC,IAAI,aAAa,QAAQ;GACvB,iBAAiB,EAAE,CAAC,CAAC,qBAAqB,UAAU,IAAI,WAAW,QAAQ;GAE3E,GAAI,UAAU,QAAQ,CAAC,CAAS,IAAI,UAAU,CAAC,QAAQ;EACzD;EAIF,KAAK,MAAM,UAAU,CAAC,GAAG,SAAS,GAAG,QAAQ,GAC3C,IAAI,CAAC,mBAAmB,OAAO,IAAI,UAAU,KAAK,CAAC,0BAA0B,OAAO,IAAI,UAAU,GAAG;GACnG,iBAAiB,EAAE,CAAC,CAAC,qBAAqB,OAAO,IAAI,IAAI,WAAW,CAAC,CAAC;GACtE,OAAO,IAAI,UAAU,CAAC,QAAQ;EAChC;CAEJ,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveParentsBatchLoader.cjs","names":["getMetadataForType","getField","abbreviation","kq","deTagIds"],"sources":["../../src/batchloaders/recursiveParentsBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n kq,\n} from \"src/index.ts\";\nimport { type RecursiveParentsCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation } from \"src/utils.ts\";\n\nexport const recursiveParentsOperation = \"m2o-recursive\";\n\nexport function recursiveParentsBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveParentsCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root m2o field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.m2oFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveParentsOperation, batchKey, async (children) => {\n const m2o = meta.allFields[collection.m2oFieldName] as ManyToOneField;\n // ...can `getField` return a new entity? In theory, we shouldn't see new entities because\n // RecursiveParentsCollectionImpl.load/isLoaded will see the `ManyToOneReferenceImpl` as loaded.\n const immediateParentIds = children.map((c) => getField(c, m2o.fieldName)).filter((id: any) => id !== undefined);\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {
|
|
1
|
+
{"version":3,"file":"recursiveParentsBatchLoader.cjs","names":["getMetadataForType","getField","abbreviation","kq","deTagIds"],"sources":["../../src/batchloaders/recursiveParentsBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n kq,\n} from \"src/index.ts\";\nimport { type RecursiveParentsCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation } from \"src/utils.ts\";\n\nexport const recursiveParentsOperation = \"m2o-recursive\";\n\nexport function recursiveParentsBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveParentsCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root m2o field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.m2oFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveParentsOperation, batchKey, async (children) => {\n const m2o = meta.allFields[collection.m2oFieldName] as ManyToOneField;\n // ...can `getField` return a new entity? In theory, we shouldn't see new entities because\n // RecursiveParentsCollectionImpl.load/isLoaded will see the `ManyToOneReferenceImpl` as loaded.\n const immediateParentIds = children.map((c) => getField(c, m2o.fieldName)).filter((id: any) => id !== undefined);\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {\n alias: `${alias}_cte`,\n join: \"inner\",\n table: `${alias}_cte`,\n col1: `${kq(alias)}.id`,\n col2: `${alias}_cte.id`,\n },\n ],\n orderBys: [{ alias, column: \"id\", order: \"ASC\" }],\n ctes: [\n {\n alias: `${alias}_cte`,\n query: {\n kind: \"raw\",\n // b is our base case, which is the immediate parents of the children we're loading,\n // and r is the recursive case of finding their parents.\n sql: `\n SELECT b.id, b.${columnName} FROM ${kq(meta.tableName)} b WHERE b.id = ANY(?)\n UNION\n SELECT r.id, r.${columnName} FROM ${kq(meta.tableName)} r JOIN ${alias}_cte ON r.id = ${alias}_cte.${columnName}\n `,\n bindings: [deTagIds(meta, immediateParentIds)],\n },\n recursive: true,\n },\n ],\n };\n\n addTablePerClassJoinsAndClassTag(query, meta, alias, true);\n\n const rowData = await em[\"executeFindRowData\"](meta, recursiveParentsOperation, query, {});\n\n // Since we're preloading m2os up the tree, merely having the entities in the EM is enough\n // for the ManyToOneReferenceImpl to find them, so we don't need to map them back to the\n // keys, or push them into the preloader cache.\n em[\"hydrateAndFinalize\"](meta.cstr, rowData);\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,4BAA4B;AAEzC,SAAgB,4BACd,IACA,YACqB;CACrB,IAAI,EAAE,MAAM,cAAc;CAK1B,OAAO,EAAE,WAAW,gBAAgB,KAAK,WAAW,KAAK,UAAU,OAAOA,kBAAAA,mBAAmB,KAAK,QAAQ;CAC1G,MAAM,WAAW,GAAG,KAAK,UAAU,GAAG;CACtC,OAAO,GAAG,eAAe,2BAA2B,UAAU,OAAO,aAAa;EAChF,MAAM,MAAM,KAAK,UAAU,WAAW;EAGtC,MAAM,qBAAqB,SAAS,KAAK,MAAMC,eAAAA,SAAS,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,QAAQ,OAAY,OAAO,KAAA,CAAS;EAC/G,MAAM,EAAE,eAAe,IAAI,MAAM,QAAQ;EAEzC,MAAM,QAAQC,cAAAA,aAAa,KAAK,SAAS;EACzC,MAAM,QAAyB;GAC7B,SAAS,CAAC,IAAI,MAAM,IAAI;GACxB,QAAQ,CAGN;IAAE;IAAO,MAAM;IAAW,OAAO,KAAK;GAAU,GAChD;IACE,OAAO,GAAG,MAAM;IAChB,MAAM;IACN,OAAO,GAAG,MAAM;IAChB,MAAM,GAAGC,6BAAAA,GAAG,KAAK,EAAE;IACnB,MAAM,GAAG,MAAM;GACjB,CACF;GACA,UAAU,CAAC;IAAE;IAAO,QAAQ;IAAM,OAAO;GAAM,CAAC;GAChD,MAAM,CACJ;IACE,OAAO,GAAG,MAAM;IAChB,OAAO;KACL,MAAM;KAGN,KAAK;+BACc,WAAW,QAAQA,6BAAAA,GAAG,KAAK,SAAS,EAAE;;+BAEtC,WAAW,QAAQA,6BAAAA,GAAG,KAAK,SAAS,EAAE,UAAU,MAAM,iBAAiB,MAAM,OAAO,WAAW;;KAElH,UAAU,CAACC,aAAAA,SAAS,MAAM,kBAAkB,CAAC;IAC/C;IACA,WAAW;GACb,CACF;EACF;EAEA,iCAAA,iCAAiC,OAAO,MAAM,OAAO,IAAI;EAEzD,MAAM,UAAU,MAAM,GAAG,qBAAqB,CAAC,MAAM,2BAA2B,OAAO,CAAC,CAAC;EAKzF,GAAG,qBAAqB,CAAC,KAAK,MAAM,OAAO;CAC7C,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveParentsBatchLoader.js","names":[],"sources":["../../src/batchloaders/recursiveParentsBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n kq,\n} from \"src/index.ts\";\nimport { type RecursiveParentsCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation } from \"src/utils.ts\";\n\nexport const recursiveParentsOperation = \"m2o-recursive\";\n\nexport function recursiveParentsBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveParentsCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root m2o field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.m2oFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveParentsOperation, batchKey, async (children) => {\n const m2o = meta.allFields[collection.m2oFieldName] as ManyToOneField;\n // ...can `getField` return a new entity? In theory, we shouldn't see new entities because\n // RecursiveParentsCollectionImpl.load/isLoaded will see the `ManyToOneReferenceImpl` as loaded.\n const immediateParentIds = children.map((c) => getField(c, m2o.fieldName)).filter((id: any) => id !== undefined);\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {
|
|
1
|
+
{"version":3,"file":"recursiveParentsBatchLoader.js","names":[],"sources":["../../src/batchloaders/recursiveParentsBatchLoader.ts"],"sourcesContent":["import { type BatchLoader } from \"src/batchloaders/BatchLoader.ts\";\nimport { getMetadataForType } from \"src/configure.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityManager } from \"src/EntityManager.ts\";\nimport {\n type ManyToOneField,\n type ParsedFindQuery,\n addTablePerClassJoinsAndClassTag,\n deTagIds,\n getField,\n kq,\n} from \"src/index.ts\";\nimport { type RecursiveParentsCollectionImpl } from \"src/relations/RecursiveCollection.ts\";\nimport { abbreviation } from \"src/utils.ts\";\n\nexport const recursiveParentsOperation = \"m2o-recursive\";\n\nexport function recursiveParentsBatchLoader<T extends Entity, U extends Entity>(\n em: EntityManager,\n collection: RecursiveParentsCollectionImpl<T, U>,\n): BatchLoader<Entity> {\n let { meta, fieldName } = collection;\n // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the\n // correct meta by walking the inheritance tree until we find the meta that actually has the root m2o field\n // We intentionally don't use getMetadataForField here because CTI-specialized fields stay on the subtype metadata,\n // while these raw recursive CTEs need the metadata/table that physically owns the FK column.\n while (!(collection.m2oFieldName in meta.fields) && meta.baseType) meta = getMetadataForType(meta.baseType);\n const batchKey = `${meta.tableName}-${fieldName}`;\n return em.getBatchLoader(recursiveParentsOperation, batchKey, async (children) => {\n const m2o = meta.allFields[collection.m2oFieldName] as ManyToOneField;\n // ...can `getField` return a new entity? In theory, we shouldn't see new entities because\n // RecursiveParentsCollectionImpl.load/isLoaded will see the `ManyToOneReferenceImpl` as loaded.\n const immediateParentIds = children.map((c) => getField(c, m2o.fieldName)).filter((id: any) => id !== undefined);\n const { columnName } = m2o.serde.columns[0];\n\n const alias = abbreviation(meta.tableName);\n const query: ParsedFindQuery = {\n selects: [`\"${alias}\".*`],\n tables: [\n // We still select directly from our table, and join into the CTE so that we\n // can use `addTablePerClassJoinsAndClassTag` to get inheritance added for free.\n { alias, join: \"primary\", table: meta.tableName },\n {\n alias: `${alias}_cte`,\n join: \"inner\",\n table: `${alias}_cte`,\n col1: `${kq(alias)}.id`,\n col2: `${alias}_cte.id`,\n },\n ],\n orderBys: [{ alias, column: \"id\", order: \"ASC\" }],\n ctes: [\n {\n alias: `${alias}_cte`,\n query: {\n kind: \"raw\",\n // b is our base case, which is the immediate parents of the children we're loading,\n // and r is the recursive case of finding their parents.\n sql: `\n SELECT b.id, b.${columnName} FROM ${kq(meta.tableName)} b WHERE b.id = ANY(?)\n UNION\n SELECT r.id, r.${columnName} FROM ${kq(meta.tableName)} r JOIN ${alias}_cte ON r.id = ${alias}_cte.${columnName}\n `,\n bindings: [deTagIds(meta, immediateParentIds)],\n },\n recursive: true,\n },\n ],\n };\n\n addTablePerClassJoinsAndClassTag(query, meta, alias, true);\n\n const rowData = await em[\"executeFindRowData\"](meta, recursiveParentsOperation, query, {});\n\n // Since we're preloading m2os up the tree, merely having the entities in the EM is enough\n // for the ManyToOneReferenceImpl to find them, so we don't need to map them back to the\n // keys, or push them into the preloader cache.\n em[\"hydrateAndFinalize\"](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,OAAO,CAAC,CAAC;EAKzF,GAAG,qBAAqB,CAAC,KAAK,MAAM,OAAO;CAC7C,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joist-core",
|
|
3
|
-
"version": "2.5.0-next.
|
|
3
|
+
"version": "2.5.0-next.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"build"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"joist-utils": "2.5.0-next.
|
|
45
|
+
"joist-utils": "2.5.0-next.11"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"ansis": "^4.4.0",
|