{"version":3,"file":"section-item.repository-B9ft9W21.js","sources":["../../../src/packages/core/section/repository/item/section-item.repository.ts"],"sourcesContent":["import type { UmbSectionItemModel } from './types.js';\nimport type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\nimport type { UmbItemRepository } from '@umbraco-cms/backoffice/repository';\nimport { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';\nimport type { ManifestSection } from '@umbraco-cms/backoffice/extension-registry';\nimport { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';\nimport { createObservablePart } from '@umbraco-cms/backoffice/observable-api';\n\nexport class UmbSectionItemRepository extends UmbRepositoryBase implements UmbItemRepository {\n\tconstructor(host: UmbControllerHost) {\n\t\tsuper(host);\n\t}\n\n\t/**\n\t * Requests the items for the given uniques\n\t * @param {Array} uniques\n\t * @returns {*}\n\t * @memberof UmbItemRepositoryBase\n\t */\n\tasync requestItems(uniques: Array) {\n\t\tif (!uniques) throw new Error('Uniques are missing');\n\n\t\tconst sectionManifests = umbExtensionsRegistry\n\t\t\t.getAllExtensions()\n\t\t\t.filter((manifest) => manifest.type === 'section')\n\t\t\t.filter((manifest) => uniques.includes(manifest.alias)) as Array;\n\n\t\tconst sectionItems: Array = sectionManifests.map((manifest) => itemMapper(manifest));\n\n\t\treturn { data: sectionItems, asObservable: () => sectionItemsByUniquesObservable(uniques) };\n\t}\n\n\t/**\n\t * Returns a promise with an observable of the items for the given uniques\n\t * @param {Array} uniques\n\t * @returns {*}\n\t * @memberof UmbItemRepositoryBase\n\t */\n\tasync items(uniques: Array) {\n\t\treturn sectionItemsByUniquesObservable(uniques);\n\t}\n}\n\nconst sectionItemsObservable = createObservablePart(umbExtensionsRegistry.byType('section'), (manifests) =>\n\tmanifests.map((manifest) => itemMapper(manifest)),\n);\n\nconst sectionItemsByUniquesObservable = (uniques: Array) =>\n\tcreateObservablePart(sectionItemsObservable, (items) => items.filter((x) => uniques.includes(x.unique)));\n\nconst itemMapper = (manifest: ManifestSection): UmbSectionItemModel => {\n\treturn {\n\t\t...manifest,\n\t\tunique: manifest.alias,\n\t};\n};\n\nexport default UmbSectionItemRepository;\n"],"names":["UmbSectionItemRepository","UmbRepositoryBase","host","uniques","umbExtensionsRegistry","manifest","itemMapper","sectionItemsByUniquesObservable","sectionItemsObservable","createObservablePart","manifests","items","x"],"mappings":";;;AAQO,MAAMA,UAAiCC,EAAoE;AAAA,EACjH,YAAYC,GAAyB;AACpC,UAAMA,CAAI;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAaC,GAAwB;AAC1C,QAAI,CAACA,EAAe,OAAA,IAAI,MAAM,qBAAqB;AASnD,WAAO,EAAE,MAPgBC,EACvB,iBAAA,EACA,OAAO,CAACC,MAAaA,EAAS,SAAS,SAAS,EAChD,OAAO,CAACA,MAAaF,EAAQ,SAASE,EAAS,KAAK,CAAC,EAEW,IAAI,CAACA,MAAaC,EAAWD,CAAQ,CAAC,GAE3E,cAAc,MAAME,EAAgCJ,CAAO;EACzF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,MAAMA,GAAwB;AACnC,WAAOI,EAAgCJ,CAAO;AAAA,EAC/C;AACD;AAEA,MAAMK,IAAyBC;AAAA,EAAqBL,EAAsB,OAAO,SAAS;AAAA,EAAG,CAACM,MAC7FA,EAAU,IAAI,CAACL,MAAaC,EAAWD,CAAQ,CAAC;AACjD,GAEME,IAAkC,CAACJ,MACxCM,EAAqBD,GAAwB,CAACG,MAAUA,EAAM,OAAO,CAACC,MAAMT,EAAQ,SAASS,EAAE,MAAM,CAAC,CAAC,GAElGN,IAAa,CAACD,OACZ;AAAA,EACN,GAAGA;AAAA,EACH,QAAQA,EAAS;AAAA;"}