{"version":3,"file":"config.repository-BYcO56Dn.js","sources":["../../../src/packages/core/temporary-file/config/config.server.data-source.ts","../../../src/packages/core/temporary-file/config/config.repository.ts"],"sourcesContent":["import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\r\nimport { TemporaryFileService } from '@umbraco-cms/backoffice/external/backend-api';\r\nimport { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';\r\n\r\nexport class UmbTemporaryFileConfigServerDataSource {\r\n\t#host;\r\n\r\n\tconstructor(host: UmbControllerHost) {\r\n\t\tthis.#host = host;\r\n\t}\r\n\r\n\t/**\r\n\t * Get the temporary file configuration.\r\n\t */\r\n\tgetConfig() {\r\n\t\treturn tryExecuteAndNotify(this.#host, TemporaryFileService.getTemporaryFileConfiguration());\r\n\t}\r\n}\r\n","import type { UmbTemporaryFileConfigurationModel } from '../types.js';\r\nimport { UmbTemporaryFileConfigServerDataSource } from './config.server.data-source.js';\r\nimport { UMB_TEMPORARY_FILE_CONFIG_STORE_CONTEXT } from './config.store.token.js';\r\nimport { UMB_TEMPORARY_FILE_REPOSITORY_ALIAS } from './constants.js';\r\nimport { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';\r\nimport type { UmbApi } from '@umbraco-cms/backoffice/extension-api';\r\nimport type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\r\nimport type { Observable } from '@umbraco-cms/backoffice/observable-api';\r\n\r\nexport class UmbTemporaryFileConfigRepository extends UmbRepositoryBase implements UmbApi {\r\n\t/**\r\n\t * Promise that resolves when the repository has been initialized, i.e. when the configuration has been fetched from the server.\r\n\t */\r\n\tinitialized: Promise;\r\n\r\n\t#dataStore?: typeof UMB_TEMPORARY_FILE_CONFIG_STORE_CONTEXT.TYPE;\r\n\t#dataSource = new UmbTemporaryFileConfigServerDataSource(this);\r\n\r\n\tconstructor(host: UmbControllerHost) {\r\n\t\tsuper(host, UMB_TEMPORARY_FILE_REPOSITORY_ALIAS.toString());\r\n\t\tthis.initialized = new Promise((resolve) => {\r\n\t\t\tthis.consumeContext(UMB_TEMPORARY_FILE_CONFIG_STORE_CONTEXT, async (store) => {\r\n\t\t\t\tthis.#dataStore = store;\r\n\t\t\t\tawait this.#init();\r\n\t\t\t\tresolve();\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\tasync #init() {\r\n\t\t// Check if the store already has data\r\n\t\tif (this.#dataStore?.getState()) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tconst { data } = await this.#dataSource.getConfig();\r\n\r\n\t\tif (data) {\r\n\t\t\tthis.#dataStore?.update(data);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Subscribe to the entire configuration.\r\n\t */\r\n\tall() {\r\n\t\tif (!this.#dataStore) {\r\n\t\t\tthrow new Error('Data store not initialized');\r\n\t\t}\r\n\r\n\t\treturn this.#dataStore.all();\r\n\t}\r\n\r\n\t/**\r\n\t * Subscribe to a part of the configuration.\r\n\t * @param part\r\n\t */\r\n\tpart(\r\n\t\tpart: Part,\r\n\t): Observable {\r\n\t\tif (!this.#dataStore) {\r\n\t\t\tthrow new Error('Data store not initialized');\r\n\t\t}\r\n\r\n\t\treturn this.#dataStore.part(part);\r\n\t}\r\n}\r\n\r\nexport default UmbTemporaryFileConfigRepository;\r\n"],"names":["UmbTemporaryFileConfigServerDataSource","#host","host","tryExecuteAndNotify","TemporaryFileService","UmbTemporaryFileConfigRepository","UmbRepositoryBase","#dataStore","#dataSource","UMB_TEMPORARY_FILE_REPOSITORY_ALIAS","resolve","UMB_TEMPORARY_FILE_CONFIG_STORE_CONTEXT","store","#init","data","part"],"mappings":";;;;;AAIO,MAAMA,EAAuC;AAAA,EACnDC;AAAA,EAEA,YAAYC,GAAyB;AACpC,SAAKD,KAAQC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMd,YAAY;AACX,WAAOC,EAAoB,KAAKF,IAAOG,EAAqB,+BAA+B;AAAA,EAAA;AAE7F;ACRO,MAAMC,UAAyCC,EAAoC;AAAA,EAMzFC;AAAA,EACAC,KAAc,IAAIR,EAAuC,IAAI;AAAA,EAE7D,YAAYE,GAAyB;AAC9B,UAAAA,GAAMO,EAAoC,UAAU,GAC1D,KAAK,cAAc,IAAI,QAAc,CAACC,MAAY;AAC5C,WAAA,eAAeC,GAAyC,OAAOC,MAAU;AAC7E,aAAKL,KAAaK,GAClB,MAAM,KAAKC,GAAM,GACTH,EAAA;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAAA,EAAA;AAAA,EAGF,MAAMG,KAAQ;AAET,QAAA,KAAKN,IAAY;AACpB;AAGD,UAAM,EAAE,MAAAO,EAAK,IAAI,MAAM,KAAKN,GAAY,UAAU;AAElD,IAAIM,KACE,KAAAP,IAAY,OAAOO,CAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAMD,MAAM;AACD,QAAA,CAAC,KAAKP;AACH,YAAA,IAAI,MAAM,4BAA4B;AAGtC,WAAA,KAAKA,GAAW,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5B,KACCQ,GACuD;AACnD,QAAA,CAAC,KAAKR;AACH,YAAA,IAAI,MAAM,4BAA4B;AAGtC,WAAA,KAAKA,GAAW,KAAKQ,CAAI;AAAA,EAAA;AAElC;"}