@looker/embed-services 23.14.1 → 23.18.0
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/CHANGELOG.md +32 -0
- package/lib/EmbedUrl.js.map +1 -1
- package/lib/ItemList.js.map +1 -1
- package/lib/ServiceFactory.js.map +1 -1
- package/lib/ThemeService.js.map +1 -1
- package/lib/esm/EmbedUrl.js +2 -10
- package/lib/esm/EmbedUrl.js.map +1 -1
- package/lib/esm/EntityService.js +1 -8
- package/lib/esm/EntityService.js.map +1 -1
- package/lib/esm/ItemList.js +3 -11
- package/lib/esm/ItemList.js.map +1 -1
- package/lib/esm/ServiceFactory.js +3 -11
- package/lib/esm/ServiceFactory.js.map +1 -1
- package/lib/esm/ThemeService.js +14 -24
- package/lib/esm/ThemeService.js.map +1 -1
- package/lib/esm/index.js +3 -38
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/test-utils/index.js +1 -16
- package/lib/esm/test-utils/index.js.map +1 -1
- package/lib/esm/test-utils/utils.js +11 -25
- package/lib/esm/test-utils/utils.js.map +1 -1
- package/lib/test-utils/utils.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [23.18.0](https://github.com/looker-open-source/sdk-codegen/compare/embed-services-v23.16.0...embed-services-v23.18.0) (2023-11-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **embed-services:** Synchronize undefined versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @looker/sdk bumped from ^23.16.0 to ^23.18.0
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @looker/sdk-node bumped from ^23.16.0 to ^23.18.0
|
|
18
|
+
|
|
19
|
+
## [23.16.0](https://github.com/looker-open-source/sdk-codegen/compare/embed-services-v23.14.1...embed-services-v23.16.0) (2023-09-21)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Miscellaneous Chores
|
|
23
|
+
|
|
24
|
+
* **embed-services:** Synchronize undefined versions
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @looker/sdk bumped from ^23.14.1 to ^23.16.0
|
|
32
|
+
* devDependencies
|
|
33
|
+
* @looker/sdk-node bumped from ^23.14.1 to ^23.16.0
|
|
34
|
+
|
|
3
35
|
## [23.14.1](https://github.com/looker-open-source/sdk-codegen/compare/embed-services-v23.12.0...embed-services-v23.14.1) (2023-08-15)
|
|
4
36
|
|
|
5
37
|
|
package/lib/EmbedUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbedUrl.js","names":["ContentType","exports","THEMABLE_CONTENT","Dashboard","Explore","EmbedUrl","constructor","url","arguments","length","undefined","window","location","href","_defineProperty","_url","URL","searchParams","Object","fromEntries","path","pathname","isDashboard","test","isExplore","isLook","contentType","type","startsWith","_embedUrl","concat","origin","isThemable","includes","Look","Invalid","embedUrl","includeSearchParams","overrides","Error","embedUrlParams","entries","forEach","_ref","key","value","overrideValue","JSON","stringify","theme","searchString","keys","URLSearchParams","toString"],"sources":["../src/EmbedUrl.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport enum ContentType {\n Look = 'look',\n Explore = 'explore',\n Dashboard = 'dashboard',\n Invalid = 'invalid',\n}\n\nconst THEMABLE_CONTENT: ContentType[] = [\n ContentType.Dashboard,\n ContentType.Explore,\n]\n\nexport interface IEmbedUrl {\n /** Current url */\n readonly url: string\n /** Path of the current page */\n readonly path: string\n /** Search string of the current url */\n readonly searchParams: Record<string, string>\n /** Determines whether the current URL is for a Dashboard */\n readonly isDashboard: boolean\n /** Determines whether the current URL is for an Explore */\n readonly isExplore: boolean\n /** Determines whether the current URl is for a Look */\n readonly isLook: boolean\n /** Type of content the URL represents */\n readonly contentType: ContentType\n /** Determines if current URL represents themable content */\n readonly isThemable: boolean\n /**\n * Builds the embed target url\n * @param includeSearchParams switch determining whether to include search params from target url\n * @param overrides any search key values to include in embed url e.g. 'k1=v1&k2=v2'\n */\n embedUrl(includeSearchParams: boolean, overrides: Record<string, any>): string\n}\n\n/**\n * A class for use when implementer requires components to be context aware\n */\nexport class EmbedUrl implements IEmbedUrl {\n private _url: URL\n readonly path: string\n readonly searchParams: Record<string, string>\n readonly isDashboard: boolean\n readonly isExplore: boolean\n readonly isLook: boolean\n readonly isThemable: boolean\n readonly contentType: ContentType\n private readonly _embedUrl: string\n\n constructor(url = window.location.href) {\n this._url = new URL(url)\n this.searchParams = Object.fromEntries(this._url.searchParams)\n this.path = this._url.pathname\n this.isDashboard = /^(\\/embed)?\\/dashboards\\//i.test(this.path)\n this.isExplore = /^(\\/embed)?\\/explore\\//i.test(this.path)\n this.isLook = /^(\\/embed)?\\/looks\\//i.test(this.path)\n this.contentType = this.type()\n\n if (this.path.startsWith('/embed/')) {\n this._embedUrl = `${this._url.origin}${this._url.pathname}`\n } else {\n this._embedUrl = `${this._url.origin}/embed${this._url.pathname}`\n }\n\n this.isThemable = THEMABLE_CONTENT.includes(this.contentType)\n }\n\n get url() {\n return this._url.href\n }\n\n protected type() {\n let type: ContentType\n if (this.isLook) {\n type = ContentType.Look\n } else if (this.isExplore) {\n type = ContentType.Explore\n } else if (this.isDashboard) {\n type = ContentType.Dashboard\n } else {\n type = ContentType.Invalid\n }\n return type\n }\n\n embedUrl(includeSearchParams = false, overrides: Record<string, any> = {}) {\n if (this.contentType === ContentType.Invalid) {\n throw new Error('Invalid content type')\n }\n\n const embedUrlParams = includeSearchParams ? this.searchParams : {}\n\n if (overrides) {\n Object.entries(overrides).forEach(([key, value]) => {\n let overrideValue = value\n if (typeof value === 'object') {\n overrideValue = JSON.stringify(value)\n }\n if (key === 'theme' && overrideValue === 'Looker') {\n delete embedUrlParams.theme\n } else {\n embedUrlParams[key] = overrideValue\n }\n })\n }\n\n let searchString = ''\n if (Object.keys(embedUrlParams).length > 0) {\n searchString = '?' + new URLSearchParams(embedUrlParams).toString()\n }\n\n const url = new URL(`${this._embedUrl}${searchString}`)\n return url.href\n }\n}\n"],"mappings":";;;;;;;;;IA0BYA,WAAW,aAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAAAC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAOvB,IAAME,gBAA+B,GAAG,CACtCF,WAAW,CAACG,SAAS,EACrBH,WAAW,CAACI,OAAO,CACpB;AA8BM,MAAMC,QAAQ,CAAsB;EAWzCC,WAAWA,CAAA,EAA6B;IAAA,IAA5BC,GAAG,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,MAAM,CAACC,QAAQ,CAACC,IAAI;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACpC,IAAI,CAACC,IAAI,GAAG,IAAIC,GAAG,CAACT,GAAG,CAAC;IACxB,IAAI,CAACU,YAAY,GAAGC,MAAM,CAACC,WAAW,CAAC,IAAI,CAACJ,IAAI,CAACE,YAAY,CAAC;IAC9D,IAAI,CAACG,IAAI,GAAG,IAAI,CAACL,IAAI,CAACM,QAAQ;IAC9B,IAAI,CAACC,WAAW,GAAG,4BAA4B,CAACC,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IAC/D,IAAI,CAACI,SAAS,GAAG,yBAAyB,CAACD,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IAC1D,IAAI,CAACK,MAAM,GAAG,uBAAuB,CAACF,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IACrD,IAAI,CAACM,WAAW,GAAG,IAAI,CAACC,IAAI,
|
|
1
|
+
{"version":3,"file":"EmbedUrl.js","names":["ContentType","exports","THEMABLE_CONTENT","Dashboard","Explore","EmbedUrl","constructor","url","arguments","length","undefined","window","location","href","_defineProperty","_url","URL","searchParams","Object","fromEntries","path","pathname","isDashboard","test","isExplore","isLook","contentType","type","startsWith","_embedUrl","concat","origin","isThemable","includes","Look","Invalid","embedUrl","includeSearchParams","overrides","Error","embedUrlParams","entries","forEach","_ref","key","value","overrideValue","JSON","stringify","theme","searchString","keys","URLSearchParams","toString"],"sources":["../src/EmbedUrl.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport enum ContentType {\n Look = 'look',\n Explore = 'explore',\n Dashboard = 'dashboard',\n Invalid = 'invalid',\n}\n\nconst THEMABLE_CONTENT: ContentType[] = [\n ContentType.Dashboard,\n ContentType.Explore,\n]\n\nexport interface IEmbedUrl {\n /** Current url */\n readonly url: string\n /** Path of the current page */\n readonly path: string\n /** Search string of the current url */\n readonly searchParams: Record<string, string>\n /** Determines whether the current URL is for a Dashboard */\n readonly isDashboard: boolean\n /** Determines whether the current URL is for an Explore */\n readonly isExplore: boolean\n /** Determines whether the current URl is for a Look */\n readonly isLook: boolean\n /** Type of content the URL represents */\n readonly contentType: ContentType\n /** Determines if current URL represents themable content */\n readonly isThemable: boolean\n /**\n * Builds the embed target url\n * @param includeSearchParams switch determining whether to include search params from target url\n * @param overrides any search key values to include in embed url e.g. 'k1=v1&k2=v2'\n */\n embedUrl(includeSearchParams: boolean, overrides: Record<string, any>): string\n}\n\n/**\n * A class for use when implementer requires components to be context aware\n */\nexport class EmbedUrl implements IEmbedUrl {\n private _url: URL\n readonly path: string\n readonly searchParams: Record<string, string>\n readonly isDashboard: boolean\n readonly isExplore: boolean\n readonly isLook: boolean\n readonly isThemable: boolean\n readonly contentType: ContentType\n private readonly _embedUrl: string\n\n constructor(url = window.location.href) {\n this._url = new URL(url)\n this.searchParams = Object.fromEntries(this._url.searchParams)\n this.path = this._url.pathname\n this.isDashboard = /^(\\/embed)?\\/dashboards\\//i.test(this.path)\n this.isExplore = /^(\\/embed)?\\/explore\\//i.test(this.path)\n this.isLook = /^(\\/embed)?\\/looks\\//i.test(this.path)\n this.contentType = this.type()\n\n if (this.path.startsWith('/embed/')) {\n this._embedUrl = `${this._url.origin}${this._url.pathname}`\n } else {\n this._embedUrl = `${this._url.origin}/embed${this._url.pathname}`\n }\n\n this.isThemable = THEMABLE_CONTENT.includes(this.contentType)\n }\n\n get url() {\n return this._url.href\n }\n\n protected type() {\n let type: ContentType\n if (this.isLook) {\n type = ContentType.Look\n } else if (this.isExplore) {\n type = ContentType.Explore\n } else if (this.isDashboard) {\n type = ContentType.Dashboard\n } else {\n type = ContentType.Invalid\n }\n return type\n }\n\n embedUrl(includeSearchParams = false, overrides: Record<string, any> = {}) {\n if (this.contentType === ContentType.Invalid) {\n throw new Error('Invalid content type')\n }\n\n const embedUrlParams = includeSearchParams ? this.searchParams : {}\n\n if (overrides) {\n Object.entries(overrides).forEach(([key, value]) => {\n let overrideValue = value\n if (typeof value === 'object') {\n overrideValue = JSON.stringify(value)\n }\n if (key === 'theme' && overrideValue === 'Looker') {\n delete embedUrlParams.theme\n } else {\n embedUrlParams[key] = overrideValue\n }\n })\n }\n\n let searchString = ''\n if (Object.keys(embedUrlParams).length > 0) {\n searchString = '?' + new URLSearchParams(embedUrlParams).toString()\n }\n\n const url = new URL(`${this._embedUrl}${searchString}`)\n return url.href\n }\n}\n"],"mappings":";;;;;;;;;IA0BYA,WAAW,aAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAAAC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAOvB,IAAME,gBAA+B,GAAG,CACtCF,WAAW,CAACG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aAAa,GAAGC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;QACvC;QACA,IAAID,GAAG,KAAK,OAAO,IAAIE,aAAa,KAAK,QAAQ,EAAE;UACjD,OAAON,cAAc,CAACS,KAAK;QAC7B,CAAC,MAAM;UACLT,cAAc,CAACI,GAAG,CAAC,GAAGE,aAAa;QACrC;MACF,CAAC,CAAC;IACJ;IAEA,IAAII,YAAY,GAAG,EAAE;IACrB,IAAIhC,MAAM,CAACiC,IAAI,CAACX,cAAc,CAAC,CAAC/B,MAAM,GAAG,CAAC,EAAE;MAC1CyC,YAAY,GAAG,GAAG,GAAG,IAAIE,eAAe,CAACZ,cAAc,CAAC,CAACa,QAAQ,CAAC,CAAC;IACrE;IAEA,IAAM9C,GAAG,GAAG,IAAIS,GAAG,IAAAc,MAAA,CAAI,IAAI,CAACD,SAAS,EAAAC,MAAA,CAAGoB,YAAY,CAAE,CAAC;IACvD,OAAO3C,GAAG,CAACM,IAAI;EACjB;AACF;AAACZ,OAAA,CAAAI,QAAA,GAAAA,QAAA"}
|
package/lib/ItemList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemList.js","names":["_EntityService","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","DEFAULT_TTL","exports","ItemList","EntityService","constructor","sdk","timeToLive","arguments","length","index","keyField","indexedItems","items","forEach","el","setExpiration","expiresAt","Date","now","expired","clearIfExpired","find","expression","result","keys","rx","RegExp","item","k","_item$k","match","toString","e","Error","getCacheDefault","options","cache","useCache"],"sources":["../src/ItemList.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { EntityService } from './EntityService'\n\nexport const DEFAULT_TTL = 900 // 15 minutes\n\nexport interface GetOptions {\n useCache?: boolean\n [key: string]: any\n}\n\nexport interface IItemList<T> {\n /** Cache time to live in seconds, defaults to 15 minutes */\n readonly timeToLive: number\n /** Cached items */\n items: T[]\n /** Expiration time */\n readonly expiresAt: number\n /** Creates an indexed collection from the cached items */\n index(key?: keyof T): ItemList<T>\n /** An indexed collection of items */\n indexedItems: Record<string, T>\n /** Determines if the cache has expired */\n expired(): boolean\n /** Computes the expiration time based on timeToLive */\n setExpiration(): void\n /** Ejects cache if expired */\n clearIfExpired(): void\n /**\n * Searches the collection for an item with the specified key/value pair\n * @param key or keys to search\n * @param expression to match\n */\n find(key: keyof T | Array<keyof T>, value: any): T | undefined\n /**\n * Gets the cache option value if present, otherwise defaults to true\n * @param options to check\n */\n getCacheDefault(options?: GetOptions): boolean\n}\n\nexport interface IEntityService<T> extends IItemList<T> {\n get(id: string, options?: GetOptions): Promise<T>\n set(id: string, item: T): Promise<T>\n getAll(...options: any[]): Promise<IItemList<T>>\n delete(id: string): void\n}\n\nexport abstract class ItemList<T extends Record<string, any>>\n extends EntityService\n implements IItemList<T>\n{\n items: T[] = []\n indexedItems: Record<string, T> = {}\n expiresAt = 0\n /** Key to index by */\n private keyField = 'id'\n\n constructor(sdk: IAPIMethods, timeToLive = DEFAULT_TTL) {\n super(sdk, timeToLive)\n }\n\n index(key: keyof T = this.keyField) {\n this.keyField = key as string\n this.indexedItems = {}\n this.items.forEach((el) => {\n if (el && el?.[this.keyField]) {\n this.indexedItems[el[this.keyField]] = el\n }\n })\n return this\n }\n\n setExpiration() {\n this.expiresAt = Date.now() + this.timeToLive * 1000\n }\n\n expired() {\n return this.expiresAt <= Date.now()\n }\n\n clearIfExpired() {\n if (this.expired()) {\n this.items = []\n this.indexedItems = {}\n }\n }\n\n find(key: keyof T | Array<keyof T>, expression: string): T | undefined {\n let result: T | undefined\n let keys: Array<keyof T>\n\n if (typeof key === 'string') {\n keys = [key]\n } else {\n keys = key as Array<keyof T>\n }\n\n try {\n const rx = new RegExp(expression, 'i')\n\n for (const item of this.items) {\n for (const k of keys) {\n const match = item[k]?.toString().match(rx)\n if (match) {\n result = item as T\n return result\n }\n }\n }\n return result\n } catch (e: any) {\n throw new Error(e)\n }\n }\n\n getCacheDefault(options?: GetOptions) {\n const cache =\n options && 'useCache' in options && options.useCache !== undefined\n ? options.useCache\n : true\n return cache\n }\n}\n"],"mappings":";;;;;;AA2BA,IAAAA,cAAA,GAAAC,OAAA;AAA+C,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAA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AQ,CAAC,CAAC,GAAGI,EAAE;MAC3C;IACF,CAAC,CAAC;IACF,OAAO,IAAI;EACb;EAEAC,aAAaA,CAAA,EAAG;IACd,IAAI,CAACC,SAAS,GAAGC,IAAI,CAACC,GAAG,
|
|
1
|
+
{"version":3,"file":"ItemList.js","names":["_EntityService","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","DEFAULT_TTL","exports","ItemList","EntityService","constructor","sdk","timeToLive","arguments","length","index","keyField","indexedItems","items","forEach","el","setExpiration","expiresAt","Date","now","expired","clearIfExpired","find","expression","result","keys","rx","RegExp","item","k","_item$k","match","toString","e","Error","getCacheDefault","options","cache","useCache"],"sources":["../src/ItemList.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { EntityService } from './EntityService'\n\nexport const DEFAULT_TTL = 900 // 15 minutes\n\nexport interface GetOptions {\n useCache?: boolean\n [key: string]: any\n}\n\nexport interface IItemList<T> {\n /** Cache time to live in seconds, defaults to 15 minutes */\n readonly timeToLive: number\n /** Cached items */\n items: T[]\n /** Expiration time */\n readonly expiresAt: number\n /** Creates an indexed collection from the cached items */\n index(key?: keyof T): ItemList<T>\n /** An indexed collection of items */\n indexedItems: Record<string, T>\n /** Determines if the cache has expired */\n expired(): boolean\n /** Computes the expiration time based on timeToLive */\n setExpiration(): void\n /** Ejects cache if expired */\n clearIfExpired(): void\n /**\n * Searches the collection for an item with the specified key/value pair\n * @param key or keys to search\n * @param expression to match\n */\n find(key: keyof T | Array<keyof T>, value: any): T | undefined\n /**\n * Gets the cache option value if present, otherwise defaults to true\n * @param options to check\n */\n getCacheDefault(options?: GetOptions): boolean\n}\n\nexport interface IEntityService<T> extends IItemList<T> {\n get(id: string, options?: GetOptions): Promise<T>\n set(id: string, item: T): Promise<T>\n getAll(...options: any[]): Promise<IItemList<T>>\n delete(id: string): void\n}\n\nexport abstract class ItemList<T extends Record<string, any>>\n extends EntityService\n implements IItemList<T>\n{\n items: T[] = []\n indexedItems: Record<string, T> = {}\n expiresAt = 0\n /** Key to index by */\n private keyField = 'id'\n\n constructor(sdk: IAPIMethods, timeToLive = DEFAULT_TTL) {\n super(sdk, timeToLive)\n }\n\n index(key: keyof T = this.keyField) {\n this.keyField = key as string\n this.indexedItems = {}\n this.items.forEach((el) => {\n if (el && el?.[this.keyField]) {\n this.indexedItems[el[this.keyField]] = el\n }\n })\n return this\n }\n\n setExpiration() {\n this.expiresAt = Date.now() + this.timeToLive * 1000\n }\n\n expired() {\n return this.expiresAt <= Date.now()\n }\n\n clearIfExpired() {\n if (this.expired()) {\n this.items = []\n this.indexedItems = {}\n }\n }\n\n find(key: keyof T | Array<keyof T>, expression: string): T | undefined {\n let result: T | undefined\n let keys: Array<keyof T>\n\n if (typeof key === 'string') {\n keys = [key]\n } else {\n keys = key as Array<keyof T>\n }\n\n try {\n const rx = new RegExp(expression, 'i')\n\n for (const item of this.items) {\n for (const k of keys) {\n const match = item[k]?.toString().match(rx)\n if (match) {\n result = item as T\n return result\n }\n }\n }\n return result\n } catch (e: any) {\n throw new Error(e)\n }\n }\n\n getCacheDefault(options?: GetOptions) {\n const cache =\n options && 'useCache' in options && options.useCache !== undefined\n ? options.useCache\n : true\n return cache\n }\n}\n"],"mappings":";;;;;;AA2BA,IAAAA,cAAA,GAAAC,OAAA;AAA+C,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAExC,IAAMU,WAAW,GAAG,GAAG;AAAAC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AA4CvB,MAAeE,QAAQ,SACpBC,4BAAa,CAEvB;EAOEC,WAAWA,CAACC,GAAgB,EAA4B;IAAA,IAA1BC,UAAU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AAIC,IAAoB;IAExB,IAAI,OAAO7C,GAAG,KAAK,QAAQ,EAAE;MAC3B6C,IAAI,GAAG,CAAC7C,GAAG,CAAC;IACd,CAAC,MAAM;MACL6C,IAAI,GAAG7C,GAAqB;IAC9B;IAEA,IAAI;MACF,IAAM8C,EAAE,GAAG,IAAIC,MAAM,CAACJ,UAAU,EAAE,GAAG,CAAC;MAEtC,KAAK,IAAMK,KAAI,IAAI,IAAI,CAACf,KAAK,EAAE;QAC7B,KAAK,IAAMgB,CAAC,IAAIJ,IAAI,EAAE;UAAA,IAAAK,OAAA;UACpB,IAAMC,KAAK,IAAAD,OAAA,GAAGF,KAAI,CAACC,CAAC,CAAC,cAAAC,OAAA,uBAAPA,OAAA,CAASE,QAAQ,CAAC,CAAC,CAACD,KAAK,CAACL,EAAE,CAAC;UAC3C,IAAIK,KAAK,EAAE;YACTP,MAAM,GAAGI,KAAS;YAClB,OAAOJ,MAAM;UACf;QACF;MACF;MACA,OAAOA,MAAM;IACf,CAAC,CAAC,OAAOS,CAAM,EAAE;MACf,MAAM,IAAIC,KAAK,CAACD,CAAC,CAAC;IACpB;EACF;EAEAE,eAAeA,CAACC,OAAoB,EAAE;IACpC,IAAMC,KAAK,GACTD,OAAO,IAAI,UAAU,IAAIA,OAAO,IAAIA,OAAO,CAACE,QAAQ,KAAK1C,SAAS,GAC9DwC,OAAO,CAACE,QAAQ,GAChB,IAAI;IACV,OAAOD,KAAK;EACd;AACF;AAACnC,OAAA,CAAAC,QAAA,GAAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceFactory.js","names":["ServiceFactory","constructor","sdk","_defineProperty","get","serviceName","service","servicesMap","Error","concat","register","serviceCreator","timeToLive","factory","createFactory","getFactory","destroyFactory","undefined"],"sources":["../src/ServiceFactory.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { IAPIMethods } from '@looker/sdk-rtl'\n\nexport type ServiceCreatorFunc<T> = (sdk: IAPIMethods, timeToLive?: number) => T\n\nexport interface IServiceFactory {\n /**\n * Retrieves a service\n * @param serviceName to retrieve\n */\n get<T>(serviceName: string): T\n /**\n * Registers or creates a service\n * @param serviceName name of service.\n * @param serviceCreator function that creates the service.\n * @param timeToLive in seconds, for the service cache. Defaults to 15 minutes.\n */\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ): void\n}\n\n/**\n * A factory for registering and maintaining services\n */\nclass ServiceFactory implements IServiceFactory {\n servicesMap: Record<string, any> = {}\n constructor(private sdk: IAPIMethods) {}\n\n get<T>(serviceName: string): T {\n const service = this.servicesMap[serviceName]\n if (!service) {\n throw new Error(`Service ${serviceName} not found`)\n }\n return service\n }\n\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ) {\n let service = this.servicesMap[serviceName]\n if (!service) {\n service = serviceCreator(this.sdk, timeToLive)\n this.servicesMap[serviceName] = service\n }\n return service\n }\n}\n\nlet factory: IServiceFactory | undefined\n\n/**\n * Helper method for creating a singleton factory\n * @param sdk\n */\nexport function createFactory(sdk: IAPIMethods) {\n factory = new ServiceFactory(sdk)\n}\n\n/**\n * Helper method for getting the factory\n */\nexport function getFactory() {\n if (!factory) {\n throw new Error('Factory must be created with an SDK.')\n }\n return factory\n}\n\n/**\n * Helper method for destroying the factory\n */\nexport function destroyFactory() {\n factory = undefined\n}\n"],"mappings":";;;;;;;;;;;AAmDA,MAAMA,cAAc,CAA4B;EAE9CC,WAAWA,CAASC,GAAgB,EAAE;IAAA,KAAlBA,GAAgB,GAAhBA,GAAgB;IAAAC,eAAA,sBADD,CAAC,CAAC;EACE;EAEvCC,GAAGA,CAAIC,WAAmB,EAAK;IAC7B,IAAMC,OAAO,GAAG,IAAI,CAACC,WAAW,CAACF,WAAW,CAAC;IAC7C,IAAI,CAACC,OAAO,EAAE;MACZ,MAAM,IAAIE,KAAK,YAAAC,MAAA,CAAYJ,WAAW,
|
|
1
|
+
{"version":3,"file":"ServiceFactory.js","names":["ServiceFactory","constructor","sdk","_defineProperty","get","serviceName","service","servicesMap","Error","concat","register","serviceCreator","timeToLive","factory","createFactory","getFactory","destroyFactory","undefined"],"sources":["../src/ServiceFactory.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { IAPIMethods } from '@looker/sdk-rtl'\n\nexport type ServiceCreatorFunc<T> = (sdk: IAPIMethods, timeToLive?: number) => T\n\nexport interface IServiceFactory {\n /**\n * Retrieves a service\n * @param serviceName to retrieve\n */\n get<T>(serviceName: string): T\n /**\n * Registers or creates a service\n * @param serviceName name of service.\n * @param serviceCreator function that creates the service.\n * @param timeToLive in seconds, for the service cache. Defaults to 15 minutes.\n */\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ): void\n}\n\n/**\n * A factory for registering and maintaining services\n */\nclass ServiceFactory implements IServiceFactory {\n servicesMap: Record<string, any> = {}\n constructor(private sdk: IAPIMethods) {}\n\n get<T>(serviceName: string): T {\n const service = this.servicesMap[serviceName]\n if (!service) {\n throw new Error(`Service ${serviceName} not found`)\n }\n return service\n }\n\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ) {\n let service = this.servicesMap[serviceName]\n if (!service) {\n service = serviceCreator(this.sdk, timeToLive)\n this.servicesMap[serviceName] = service\n }\n return service\n }\n}\n\nlet factory: IServiceFactory | undefined\n\n/**\n * Helper method for creating a singleton factory\n * @param sdk\n */\nexport function createFactory(sdk: IAPIMethods) {\n factory = new ServiceFactory(sdk)\n}\n\n/**\n * Helper method for getting the factory\n */\nexport function getFactory() {\n if (!factory) {\n throw new Error('Factory must be created with an SDK.')\n }\n return factory\n}\n\n/**\n * Helper method for destroying the factory\n */\nexport function destroyFactory() {\n factory = undefined\n}\n"],"mappings":";;;;;;;;;;;AAmDA,MAAMA,cAAc,CAA4B;EAE9CC,WAAWA,CAASC,GAAgB,EAAE;IAAA,KAAlBA,GAAgB,GAAhBA,GAAgB;IAAAC,eAAA,sBADD,CAAC,CAAC;EACE;EAEvCC,GAAGA,CAAIC,WAAmB,EAAK;IAC7B,IAAMC,OAAO,GAAG,IAAI,CAACC,WAAW,CAACF,WAAW,CAAC;IAC7C,IAAI,CAACC,OAAO,EAAE;MACZ,MAAM,IAAIE,KAAK,YAAAC,MAAA,CAAYJ,WAAW,eAAY,CAAC;IACrD;IACA,OAAOC,OAAO;EAChB;EAEAI,QAAQA,CACNL,WAAmB,EACnBM,cAAqC,EACrCC,UAAmB,EACnB;IACA,IAAIN,OAAO,GAAG,IAAI,CAACC,WAAW,CAACF,WAAW,CAAC;IAC3C,IAAI,CAACC,OAAO,EAAE;MACZA,OAAO,GAAGK,cAAc,CAAC,IAAI,CAACT,GAAG,EAAEU,UAAU,CAAC;MAC9C,IAAI,CAACL,WAAW,CAACF,WAAW,CAAC,GAAGC,OAAO;IACzC;IACA,OAAOA,OAAO;EAChB;AACF;AAEA,IAAIO,OAAoC;AAMjC,SAASC,aAAaA,CAACZ,GAAgB,EAAE;EAC9CW,OAAO,GAAG,IAAIb,cAAc,CAACE,GAAG,CAAC;AACnC;AAKO,SAASa,UAAUA,CAAA,EAAG;EAC3B,IAAI,CAACF,OAAO,EAAE;IACZ,MAAM,IAAIL,KAAK,CAAC,sCAAsC,CAAC;EACzD;EACA,OAAOK,OAAO;AAChB;AAKO,SAASG,cAAcA,CAAA,EAAG;EAC/BH,OAAO,GAAGI,SAAS;AACrB"}
|
package/lib/ThemeService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeService.js","names":["_sdk","require","_ItemList","_ServiceFactory","asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","_defineProperty","obj","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","res","call","TypeError","Number","ThemeService","ItemList","constructor","get","id","options","_this","cache","getCacheDefault","clearIfExpired","item","indexedItems","sdk","ok","theme","fields","items","index","setExpiration","getAll","_this2","expired","load","set","_this3","update_theme","getDefaultTheme","ts","_this4","defaultTheme","default_theme","delete","_this5","delete_theme","filter","_this6","all_themes","THEME_SERVICE_NAME","exports","themeServiceCreator","timeToLive","registerThemeService","getFactory","register","getThemeService"],"sources":["../src/ThemeService.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { ITheme } from '@looker/sdk'\nimport {\n all_themes,\n default_theme,\n delete_theme,\n theme,\n update_theme,\n} from '@looker/sdk'\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { ItemList } from './ItemList'\nimport type { IEntityService, IItemList, GetOptions } from './ItemList'\nimport type { ServiceCreatorFunc } from './ServiceFactory'\nimport { getFactory } from './ServiceFactory'\n\nexport interface IThemeService\n extends IItemList<ITheme>,\n IEntityService<ITheme> {\n defaultTheme?: ITheme\n /**\n * Gets the default theme\n * @param ts Timestamp representing the target datetime for the active period. Defaults to 'now'\n */\n getDefaultTheme(ts?: Date, options?: GetOptions): Promise<ITheme>\n /**\n * Retrieves all themes and the default theme\n */\n load(options?: GetOptions): Promise<IThemeService>\n}\n\nclass ThemeService extends ItemList<ITheme> implements IThemeService {\n public defaultTheme?: ITheme\n\n /**\n * Get theme by id\n * @param id of theme to retrieve\n * @param options to get\n */\n async get(id: string, options?: GetOptions): Promise<Partial<ITheme>> {\n // TODO: implement logic to check if requested fields are already cached.\n const cache = this.getCacheDefault(options)\n this.clearIfExpired()\n let item = this.indexedItems[id]\n\n if (cache && item) {\n return item\n }\n\n item = await this.sdk.ok(theme(this.sdk, id, options?.fields))\n\n if (item) {\n this.items = [...this.items, item]\n this.index()\n this.setExpiration()\n }\n return item\n }\n\n /**\n * Get all themes, including the default theme\n * @param options to get\n */\n async getAll(options?: GetOptions) {\n if (this.getCacheDefault(options) && !this.expired()) {\n return this\n }\n await this.load(options)\n return this\n }\n\n /**\n * Updates a theme\n * @param id id of theme to update\n * @param item with updated fields\n */\n async set(id: string, item: ITheme) {\n this.clearIfExpired()\n const theme = await this.sdk.ok(update_theme(this.sdk, id, item))\n if (theme) {\n this.items = [...this.items, theme]\n this.index()\n this.setExpiration()\n }\n return theme\n }\n\n async getDefaultTheme(ts?: Date) {\n if (this.expired()) {\n this.defaultTheme = await this.sdk.ok(default_theme(this.sdk, ts))\n }\n return this.defaultTheme as ITheme\n }\n\n /**\n * Deletes a theme\n * @param id of theme to delete\n */\n async delete(id: string) {\n this.clearIfExpired()\n await this.sdk.ok(delete_theme(this.sdk, id))\n this.items = this.items.filter((item) => item.id !== id)\n this.index()\n }\n\n async load(options?: GetOptions) {\n await this.getDefaultTheme()\n this.items = await this.sdk.ok(all_themes(this.sdk, options?.fields))\n this.index()\n this.setExpiration()\n return this\n }\n}\n\nexport const THEME_SERVICE_NAME = 'ThemeService'\n\n/**\n * A theme service creator helper function\n * @param sdk\n * @param timeToLive in seconds for the cache\n */\nexport const themeServiceCreator: ServiceCreatorFunc<IThemeService> = (\n sdk: IAPIMethods,\n timeToLive?: number\n) => {\n return new ThemeService(sdk, timeToLive)\n}\n\n/**\n * Creates and registers the theme service with the service factory\n * @param timeToLive in seconds for the cache\n */\nexport const registerThemeService = (timeToLive?: number) => {\n getFactory().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive)\n}\n\n/**\n * Gets the theme service registered with the service factory\n */\nexport const getThemeService = () =>\n getFactory().get<IThemeService>(THEME_SERVICE_NAME)\n"],"mappings":";;;;;;AA0BA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,eAAA,GAAAF,OAAA;AAA6C,SAAAG,mBAAAC,GAAA,EAAAC,OAAA,EAAAC,MAAA,EAAAC,KAAA,EAAAC,MAAA,EAAAC,GAAA,EAAAC,GAAA,cAAAC,IAAA,GAAAP,GAAA,CAAAK,GAAA,EAAAC,GAAA,OAAAE,KAAA,GAAAD,IAAA,CAAAC,KAAA,WAAAC,KAAA,IAAAP,MAAA,CAAAO,KAAA,iBAAAF,IAAA,CAAAG,IAAA,IAAAT,OAAA,CAAAO,KAAA,YAAAG,OAAA,CAAAV,OAAA,CAAAO,KAAA,EAAAI,IAAA,CAAAT,KAAA,EAAAC,MAAA;AAAA,SAAAS,kBAAAC,EAAA,6BAAAC,IAAA,SAAAC,IAAA,GAAAC,SAAA,aAAAN,OAAA,WAAAV,OAAA,EAAAC,MAAA,QAAAF,GAAA,GAAAc,EAAA,CAAAI,KAAA,CAAAH,IAAA,EAAAC,IAAA,YAAAb,MAAAK,KAAA,IAAAT,kBAAA,CAAAC,GAAA,EAAAC,OAAA,EAAAC,MAAA,EAAAC,KAAA,EAAAC,MAAA,UAAAI,KAAA,cAAAJ,OAAAe,GAAA,IAAApB,kBAAA,CAAAC,G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F,OAAA,CAAAC,mBAAA,GAAAA,mBAAA;AAMM,IAAME,oBAAoB,GAAID,UAAmB,IAAK;EAC3D,IAAAE,0BAAU,GAAE,CAACC,QAAQ,CAACN,kBAAkB,EAAEE,mBAAmB,EAAEC,UAAU,CAAC;AAC5E,CAAC;AAAAF,OAAA,CAAAG,oBAAA,GAAAA,oBAAA;AAKM,IAAMG,eAAe,GAAGA,CAAA,KAC7B,IAAAF,0BAAU,GAAE,CAACvC,GAAG,CAAgBkC,kBAAkB,CAAC;AAAAC,OAAA,CAAAM,eAAA,GAAAA,eAAA"}
|
|
1
|
+
{"version":3,"file":"ThemeService.js","names":["_sdk","require","_ItemList","_ServiceFactory","asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","_defineProperty","obj","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","res","call","TypeError","Number","ThemeService","ItemList","constructor","get","id","options","_this","cache","getCacheDefault","clearIfExpired","item","indexedItems","sdk","ok","theme","fields","items","index","setExpiration","getAll","_this2","expired","load","set","_this3","update_theme","getDefaultTheme","ts","_this4","defaultTheme","default_theme","delete","_this5","delete_theme","filter","_this6","all_themes","THEME_SERVICE_NAME","exports","themeServiceCreator","timeToLive","registerThemeService","getFactory","register","getThemeService"],"sources":["../src/ThemeService.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { ITheme } from '@looker/sdk'\nimport {\n all_themes,\n default_theme,\n delete_theme,\n theme,\n update_theme,\n} from '@looker/sdk'\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { ItemList } from './ItemList'\nimport type { IEntityService, IItemList, GetOptions } from './ItemList'\nimport type { ServiceCreatorFunc } from './ServiceFactory'\nimport { getFactory } from './ServiceFactory'\n\nexport interface IThemeService\n extends IItemList<ITheme>,\n IEntityService<ITheme> {\n defaultTheme?: ITheme\n /**\n * Gets the default theme\n * @param ts Timestamp representing the target datetime for the active period. Defaults to 'now'\n */\n getDefaultTheme(ts?: Date, options?: GetOptions): Promise<ITheme>\n /**\n * Retrieves all themes and the default theme\n */\n load(options?: GetOptions): Promise<IThemeService>\n}\n\nclass ThemeService extends ItemList<ITheme> implements IThemeService {\n public defaultTheme?: ITheme\n\n /**\n * Get theme by id\n * @param id of theme to retrieve\n * @param options to get\n */\n async get(id: string, options?: GetOptions): Promise<Partial<ITheme>> {\n // TODO: implement logic to check if requested fields are already cached.\n const cache = this.getCacheDefault(options)\n this.clearIfExpired()\n let item = this.indexedItems[id]\n\n if (cache && item) {\n return item\n }\n\n item = await this.sdk.ok(theme(this.sdk, id, options?.fields))\n\n if (item) {\n this.items = [...this.items, item]\n this.index()\n this.setExpiration()\n }\n return item\n }\n\n /**\n * Get all themes, including the default theme\n * @param options to get\n */\n async getAll(options?: GetOptions) {\n if (this.getCacheDefault(options) && !this.expired()) {\n return this\n }\n await this.load(options)\n return this\n }\n\n /**\n * Updates a theme\n * @param id id of theme to update\n * @param item with updated fields\n */\n async set(id: string, item: ITheme) {\n this.clearIfExpired()\n const theme = await this.sdk.ok(update_theme(this.sdk, id, item))\n if (theme) {\n this.items = [...this.items, theme]\n this.index()\n this.setExpiration()\n }\n return theme\n }\n\n async getDefaultTheme(ts?: Date) {\n if (this.expired()) {\n this.defaultTheme = await this.sdk.ok(default_theme(this.sdk, ts))\n }\n return this.defaultTheme as ITheme\n }\n\n /**\n * Deletes a theme\n * @param id of theme to delete\n */\n async delete(id: string) {\n this.clearIfExpired()\n await this.sdk.ok(delete_theme(this.sdk, id))\n this.items = this.items.filter((item) => item.id !== id)\n this.index()\n }\n\n async load(options?: GetOptions) {\n await this.getDefaultTheme()\n this.items = await this.sdk.ok(all_themes(this.sdk, options?.fields))\n this.index()\n this.setExpiration()\n return this\n }\n}\n\nexport const THEME_SERVICE_NAME = 'ThemeService'\n\n/**\n * A theme service creator helper function\n * @param sdk\n * @param timeToLive in seconds for the cache\n */\nexport const themeServiceCreator: ServiceCreatorFunc<IThemeService> = (\n sdk: IAPIMethods,\n timeToLive?: number\n) => {\n return new ThemeService(sdk, timeToLive)\n}\n\n/**\n * Creates and registers the theme service with the service factory\n * @param timeToLive in seconds for the cache\n */\nexport const registerThemeService = (timeToLive?: number) => {\n getFactory().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive)\n}\n\n/**\n * Gets the theme service registered with the service factory\n */\nexport const getThemeService = () =>\n getFactory().get<IThemeService>(THEME_SERVICE_NAME)\n"],"mappings":";;;;;;AA0BA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,eAAA,GAAAF,OAAA;AAA6C,SAAAG,mBAAAC,GAAA,EAAAC,OAAA,EAAAC,MAAA,EAAAC,KAAA,EAAAC,MAAA,EAAAC,GAAA,EAAAC,GAAA,cAAAC,IAAA,GAAAP,GAAA,CAAAK,GAAA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A;EACd;EAEMK,IAAIA,CAACjB,OAAoB,EAAE;IAAA,IAAA8B,MAAA;IAAA,OAAA9D,iBAAA;MAC/B,MAAM8D,MAAI,CAACT,eAAe,CAAC,CAAC;MAC5BS,MAAI,CAACnB,KAAK,SAASmB,MAAI,CAACvB,GAAG,CAACC,EAAE,CAAC,IAAAuB,eAAU,EAACD,MAAI,CAACvB,GAAG,EAAEP,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEU,MAAM,CAAC,CAAC;MACrEoB,MAAI,CAAClB,KAAK,CAAC,CAAC;MACZkB,MAAI,CAACjB,aAAa,CAAC,CAAC;MACpB,OAAOiB,MAAI;IAAA;EACb;AACF;AAEO,IAAME,kBAAkB,GAAG,cAAc;AAAAC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAOzC,IAAME,mBAAsD,GAAGA,CACpE3B,GAAgB,EAChB4B,UAAmB,KAChB;EACH,OAAO,IAAIxC,YAAY,CAACY,GAAG,EAAE4B,UAAU,CAAC;AAC1C,CAAC;AAAAF,OAAA,CAAAC,mBAAA,GAAAA,mBAAA;AAMM,IAAME,oBAAoB,GAAID,UAAmB,IAAK;EAC3D,IAAAE,0BAAU,EAAC,CAAC,CAACC,QAAQ,CAACN,kBAAkB,EAAEE,mBAAmB,EAAEC,UAAU,CAAC;AAC5E,CAAC;AAAAF,OAAA,CAAAG,oBAAA,GAAAA,oBAAA;AAKM,IAAMG,eAAe,GAAGA,CAAA,KAC7B,IAAAF,0BAAU,EAAC,CAAC,CAACvC,GAAG,CAAgBkC,kBAAkB,CAAC;AAAAC,OAAA,CAAAM,eAAA,GAAAA,eAAA"}
|
package/lib/esm/EmbedUrl.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.EmbedUrl = exports.ContentType = void 0;
|
|
7
1
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
2
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
9
3
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
var ContentType = function (ContentType) {
|
|
4
|
+
export var ContentType = function (ContentType) {
|
|
11
5
|
ContentType["Look"] = "look";
|
|
12
6
|
ContentType["Explore"] = "explore";
|
|
13
7
|
ContentType["Dashboard"] = "dashboard";
|
|
14
8
|
ContentType["Invalid"] = "invalid";
|
|
15
9
|
return ContentType;
|
|
16
10
|
}({});
|
|
17
|
-
exports.ContentType = ContentType;
|
|
18
11
|
var THEMABLE_CONTENT = [ContentType.Dashboard, ContentType.Explore];
|
|
19
|
-
class EmbedUrl {
|
|
12
|
+
export class EmbedUrl {
|
|
20
13
|
constructor() {
|
|
21
14
|
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.href;
|
|
22
15
|
_defineProperty(this, "_url", void 0);
|
|
@@ -87,5 +80,4 @@ class EmbedUrl {
|
|
|
87
80
|
return url.href;
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
|
-
exports.EmbedUrl = EmbedUrl;
|
|
91
83
|
//# sourceMappingURL=EmbedUrl.js.map
|
package/lib/esm/EmbedUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbedUrl.js","names":["ContentType","
|
|
1
|
+
{"version":3,"file":"EmbedUrl.js","names":["ContentType","THEMABLE_CONTENT","Dashboard","Explore","EmbedUrl","constructor","url","arguments","length","undefined","window","location","href","_defineProperty","_url","URL","searchParams","Object","fromEntries","path","pathname","isDashboard","test","isExplore","isLook","contentType","type","startsWith","_embedUrl","concat","origin","isThemable","includes","Look","Invalid","embedUrl","includeSearchParams","overrides","Error","embedUrlParams","entries","forEach","_ref","key","value","overrideValue","JSON","stringify","theme","searchString","keys","URLSearchParams","toString"],"sources":["../../src/EmbedUrl.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport enum ContentType {\n Look = 'look',\n Explore = 'explore',\n Dashboard = 'dashboard',\n Invalid = 'invalid',\n}\n\nconst THEMABLE_CONTENT: ContentType[] = [\n ContentType.Dashboard,\n ContentType.Explore,\n]\n\nexport interface IEmbedUrl {\n /** Current url */\n readonly url: string\n /** Path of the current page */\n readonly path: string\n /** Search string of the current url */\n readonly searchParams: Record<string, string>\n /** Determines whether the current URL is for a Dashboard */\n readonly isDashboard: boolean\n /** Determines whether the current URL is for an Explore */\n readonly isExplore: boolean\n /** Determines whether the current URl is for a Look */\n readonly isLook: boolean\n /** Type of content the URL represents */\n readonly contentType: ContentType\n /** Determines if current URL represents themable content */\n readonly isThemable: boolean\n /**\n * Builds the embed target url\n * @param includeSearchParams switch determining whether to include search params from target url\n * @param overrides any search key values to include in embed url e.g. 'k1=v1&k2=v2'\n */\n embedUrl(includeSearchParams: boolean, overrides: Record<string, any>): string\n}\n\n/**\n * A class for use when implementer requires components to be context aware\n */\nexport class EmbedUrl implements IEmbedUrl {\n private _url: URL\n readonly path: string\n readonly searchParams: Record<string, string>\n readonly isDashboard: boolean\n readonly isExplore: boolean\n readonly isLook: boolean\n readonly isThemable: boolean\n readonly contentType: ContentType\n private readonly _embedUrl: string\n\n constructor(url = window.location.href) {\n this._url = new URL(url)\n this.searchParams = Object.fromEntries(this._url.searchParams)\n this.path = this._url.pathname\n this.isDashboard = /^(\\/embed)?\\/dashboards\\//i.test(this.path)\n this.isExplore = /^(\\/embed)?\\/explore\\//i.test(this.path)\n this.isLook = /^(\\/embed)?\\/looks\\//i.test(this.path)\n this.contentType = this.type()\n\n if (this.path.startsWith('/embed/')) {\n this._embedUrl = `${this._url.origin}${this._url.pathname}`\n } else {\n this._embedUrl = `${this._url.origin}/embed${this._url.pathname}`\n }\n\n this.isThemable = THEMABLE_CONTENT.includes(this.contentType)\n }\n\n get url() {\n return this._url.href\n }\n\n protected type() {\n let type: ContentType\n if (this.isLook) {\n type = ContentType.Look\n } else if (this.isExplore) {\n type = ContentType.Explore\n } else if (this.isDashboard) {\n type = ContentType.Dashboard\n } else {\n type = ContentType.Invalid\n }\n return type\n }\n\n embedUrl(includeSearchParams = false, overrides: Record<string, any> = {}) {\n if (this.contentType === ContentType.Invalid) {\n throw new Error('Invalid content type')\n }\n\n const embedUrlParams = includeSearchParams ? this.searchParams : {}\n\n if (overrides) {\n Object.entries(overrides).forEach(([key, value]) => {\n let overrideValue = value\n if (typeof value === 'object') {\n overrideValue = JSON.stringify(value)\n }\n if (key === 'theme' && overrideValue === 'Looker') {\n delete embedUrlParams.theme\n } else {\n embedUrlParams[key] = overrideValue\n }\n })\n }\n\n let searchString = ''\n if (Object.keys(embedUrlParams).length > 0) {\n searchString = '?' + new URLSearchParams(embedUrlParams).toString()\n }\n\n const url = new URL(`${this._embedUrl}${searchString}`)\n return url.href\n }\n}\n"],"mappings":";;;AA0BA,WAAYA,WAAW,aAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAOvB,IAAMC,gBAA+B,GAAG,CACtCD,WAAW,CAACE,SAAS,EACrBF,WAAW,CAACG,OAAO,CACpB;AA8BD,OAAO,MAAMC,QAAQ,CAAsB;EAWzCC,WAAWA,CAAA,EAA6B;IAAA,IAA5BC,GAAG,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,MAAM,CAACC,QAAQ,CAACC,IAAI;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACpC,IAAI,CAACC,IAAI,GAAG,IAAIC,GAAG,CAACT,GAAG,CAAC;IACxB,IAAI,CAACU,YAAY,GAAGC,MAAM,CAACC,WAAW,CAAC,IAAI,CAACJ,IAAI,CAACE,YAAY,CAAC;IAC9D,IAAI,CAACG,IAAI,GAAG,IAAI,CAACL,IAAI,CAACM,QAAQ;IAC9B,IAAI,CAACC,WAAW,GAAG,4BAA4B,CAACC,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IAC/D,IAAI,CAACI,SAAS,GAAG,yBAAyB,CAACD,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IAC1D,IAAI,CAACK,MAAM,GAAG,uBAAuB,CAACF,IAAI,CAAC,IAAI,CAACH,IAAI,CAAC;IACrD,IAAI,CAACM,WAAW,GAAG,IAAI,CAACC,IAAI,CAAC,CAAC;IAE9B,IAAI,IAAI,CAACP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BAAsB,CAAC;IACzC;IAEA,IAAMC,cAAc,GAAGH,mBAAmB,GAAG,IAAI,CAACpB,YAAY,GAAG,CAAC,CAAC;IAEnE,IAAIqB,SAAS,EAAE;MACbpB,MAAM,CAACuB,OAAO,CAACH,SAAS,CAAC,CAACI,OAAO,CAACC,IAAA,IAAkB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QAC7C,IAAIG,aAAa,GAAGD,KAAK;QACzB,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;UAC7BC,aAAa,GAAGC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;QACvC;QACA,IAAID,GAAG,KAAK,OAAO,IAAIE,aAAa,KAAK,QAAQ,EAAE;UACjD,OAAON,cAAc,CAACS,KAAK;QAC7B,CAAC,MAAM;UACLT,cAAc,CAACI,GAAG,CAAC,GAAGE,aAAa;QACrC;MACF,CAAC,CAAC;IACJ;IAEA,IAAII,YAAY,GAAG,EAAE;IACrB,IAAIhC,MAAM,CAACiC,IAAI,CAACX,cAAc,CAAC,CAAC/B,MAAM,GAAG,CAAC,EAAE;MAC1CyC,YAAY,GAAG,GAAG,GAAG,IAAIE,eAAe,CAACZ,cAAc,CAAC,CAACa,QAAQ,CAAC,CAAC;IACrE;IAEA,IAAM9C,GAAG,GAAG,IAAIS,GAAG,IAAAc,MAAA,CAAI,IAAI,CAACD,SAAS,EAAAC,MAAA,CAAGoB,YAAY,CAAE,CAAC;IACvD,OAAO3C,GAAG,CAACM,IAAI;EACjB;AACF"}
|
package/lib/esm/EntityService.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.EntityService = void 0;
|
|
7
|
-
class EntityService {
|
|
1
|
+
export class EntityService {
|
|
8
2
|
constructor(sdk) {
|
|
9
3
|
var timeToLive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 900;
|
|
10
4
|
this.sdk = sdk;
|
|
11
5
|
this.timeToLive = timeToLive;
|
|
12
6
|
}
|
|
13
7
|
}
|
|
14
|
-
exports.EntityService = EntityService;
|
|
15
8
|
//# sourceMappingURL=EntityService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityService.js","names":["EntityService","constructor","sdk","timeToLive","arguments","length","undefined"
|
|
1
|
+
{"version":3,"file":"EntityService.js","names":["EntityService","constructor","sdk","timeToLive","arguments","length","undefined"],"sources":["../../src/EntityService.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods } from '@looker/sdk-rtl'\n\nexport interface IEmbedService {\n /** Instantiated browser sdk */\n get sdk(): IAPIMethods\n}\n\nexport abstract class EntityService implements IEmbedService {\n /**\n *\n * @param sdk\n * @param timeToLive\n */\n constructor(public sdk: IAPIMethods, readonly timeToLive = 900) {}\n}\n"],"mappings":"AAiCA,OAAO,MAAeA,aAAa,CAA0B;EAM3DC,WAAWA,CAAQC,GAAgB,EAA6B;IAAA,IAAlBC,UAAU,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAAA,KAA3CF,GAAgB,GAAhBA,GAAgB;IAAA,KAAWC,UAAU,GAAVA,UAAU;EAAS;AACnE"}
|
package/lib/esm/ItemList.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ItemList = exports.DEFAULT_TTL = void 0;
|
|
7
|
-
var _EntityService = require("./EntityService");
|
|
8
1
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
2
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
3
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class ItemList extends
|
|
4
|
+
import { EntityService } from './EntityService';
|
|
5
|
+
export var DEFAULT_TTL = 900;
|
|
6
|
+
export class ItemList extends EntityService {
|
|
14
7
|
constructor(sdk) {
|
|
15
8
|
var timeToLive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_TTL;
|
|
16
9
|
super(sdk, timeToLive);
|
|
@@ -72,5 +65,4 @@ class ItemList extends _EntityService.EntityService {
|
|
|
72
65
|
return cache;
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
|
-
exports.ItemList = ItemList;
|
|
76
68
|
//# sourceMappingURL=ItemList.js.map
|
package/lib/esm/ItemList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemList.js","names":["
|
|
1
|
+
{"version":3,"file":"ItemList.js","names":["EntityService","DEFAULT_TTL","ItemList","constructor","sdk","timeToLive","arguments","length","undefined","_defineProperty","index","key","keyField","indexedItems","items","forEach","el","setExpiration","expiresAt","Date","now","expired","clearIfExpired","find","expression","result","keys","rx","RegExp","item","k","_item$k","match","toString","e","Error","getCacheDefault","options","cache","useCache"],"sources":["../../src/ItemList.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { EntityService } from './EntityService'\n\nexport const DEFAULT_TTL = 900 // 15 minutes\n\nexport interface GetOptions {\n useCache?: boolean\n [key: string]: any\n}\n\nexport interface IItemList<T> {\n /** Cache time to live in seconds, defaults to 15 minutes */\n readonly timeToLive: number\n /** Cached items */\n items: T[]\n /** Expiration time */\n readonly expiresAt: number\n /** Creates an indexed collection from the cached items */\n index(key?: keyof T): ItemList<T>\n /** An indexed collection of items */\n indexedItems: Record<string, T>\n /** Determines if the cache has expired */\n expired(): boolean\n /** Computes the expiration time based on timeToLive */\n setExpiration(): void\n /** Ejects cache if expired */\n clearIfExpired(): void\n /**\n * Searches the collection for an item with the specified key/value pair\n * @param key or keys to search\n * @param expression to match\n */\n find(key: keyof T | Array<keyof T>, value: any): T | undefined\n /**\n * Gets the cache option value if present, otherwise defaults to true\n * @param options to check\n */\n getCacheDefault(options?: GetOptions): boolean\n}\n\nexport interface IEntityService<T> extends IItemList<T> {\n get(id: string, options?: GetOptions): Promise<T>\n set(id: string, item: T): Promise<T>\n getAll(...options: any[]): Promise<IItemList<T>>\n delete(id: string): void\n}\n\nexport abstract class ItemList<T extends Record<string, any>>\n extends EntityService\n implements IItemList<T>\n{\n items: T[] = []\n indexedItems: Record<string, T> = {}\n expiresAt = 0\n /** Key to index by */\n private keyField = 'id'\n\n constructor(sdk: IAPIMethods, timeToLive = DEFAULT_TTL) {\n super(sdk, timeToLive)\n }\n\n index(key: keyof T = this.keyField) {\n this.keyField = key as string\n this.indexedItems = {}\n this.items.forEach((el) => {\n if (el && el?.[this.keyField]) {\n this.indexedItems[el[this.keyField]] = el\n }\n })\n return this\n }\n\n setExpiration() {\n this.expiresAt = Date.now() + this.timeToLive * 1000\n }\n\n expired() {\n return this.expiresAt <= Date.now()\n }\n\n clearIfExpired() {\n if (this.expired()) {\n this.items = []\n this.indexedItems = {}\n }\n }\n\n find(key: keyof T | Array<keyof T>, expression: string): T | undefined {\n let result: T | undefined\n let keys: Array<keyof T>\n\n if (typeof key === 'string') {\n keys = [key]\n } else {\n keys = key as Array<keyof T>\n }\n\n try {\n const rx = new RegExp(expression, 'i')\n\n for (const item of this.items) {\n for (const k of keys) {\n const match = item[k]?.toString().match(rx)\n if (match) {\n result = item as T\n return result\n }\n }\n }\n return result\n } catch (e: any) {\n throw new Error(e)\n }\n }\n\n getCacheDefault(options?: GetOptions) {\n const cache =\n options && 'useCache' in options && options.useCache !== undefined\n ? options.useCache\n : true\n return cache\n }\n}\n"],"mappings":";;;AA2BA,SAASA,aAAa,QAAQ,iBAAiB;AAE/C,OAAO,IAAMC,WAAW,GAAG,GAAG;AA4C9B,OAAO,MAAeC,QAAQ,SACpBF,aAAa,CAEvB;EAOEG,WAAWA,CAACC,GAAgB,EAA4B;IAAA,IAA1BC,UAAU,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGL,WAAW;IACpD,KAAK,CAACG,GAAG,EAAEC,UAAU,CAAC;IAAAI,eAAA,gBAPX,EAAE;IAAAA,eAAA,uBACmB,CAAC,CAAC;IAAAA,eAAA,oBACxB,CAAC;IAAAA,eAAA,mBAEM,IAAI;EAIvB;EAEAC,KAAKA,CAAA,EAA+B;IAAA,IAA9BC,GAAY,GAAAL,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI,CAACM,QAAQ;IAChC,IAAI,CAACA,QAAQ,GAAGD,GAAa;IAC7B,IAAI,CAACE,YAAY,GAAG,CAAC,CAAC;IACtB,IAAI,CAACC,KAAK,CAACC,OAAO,CAAEC,EAAE,IAAK;MACzB,IAAIA,EAAE,IAAIA,EAAE,aAAFA,EAAE,eAAFA,EAAE,CAAG,IAAI,CAACJ,QAAQ,CAAC,EAAE;QAC7B,IAAI,CAACC,YAAY,CAACG,EAAE,CAAC,IAAI,CAACJ,QAAQ,CAAC,CAAC,GAAGI,EAAE;MAC3C;IACF,CAAC,CAAC;IACF,OAAO,IAAI;EACb;EAEAC,aAAaA,CAAA,EAAG;IACd,IAAI,CAACC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACf,UAAU,GAAG,IAAI;EACtD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"}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createFactory = createFactory;
|
|
7
|
-
exports.destroyFactory = destroyFactory;
|
|
8
|
-
exports.getFactory = getFactory;
|
|
9
1
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
2
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
3
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
@@ -31,16 +23,16 @@ class ServiceFactory {
|
|
|
31
23
|
}
|
|
32
24
|
}
|
|
33
25
|
var factory;
|
|
34
|
-
function createFactory(sdk) {
|
|
26
|
+
export function createFactory(sdk) {
|
|
35
27
|
factory = new ServiceFactory(sdk);
|
|
36
28
|
}
|
|
37
|
-
function getFactory() {
|
|
29
|
+
export function getFactory() {
|
|
38
30
|
if (!factory) {
|
|
39
31
|
throw new Error('Factory must be created with an SDK.');
|
|
40
32
|
}
|
|
41
33
|
return factory;
|
|
42
34
|
}
|
|
43
|
-
function destroyFactory() {
|
|
35
|
+
export function destroyFactory() {
|
|
44
36
|
factory = undefined;
|
|
45
37
|
}
|
|
46
38
|
//# sourceMappingURL=ServiceFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceFactory.js","names":["ServiceFactory","constructor","sdk","_defineProperty","get","serviceName","service","servicesMap","Error","concat","register","serviceCreator","timeToLive","factory","createFactory","getFactory","destroyFactory","undefined"],"sources":["../../src/ServiceFactory.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { IAPIMethods } from '@looker/sdk-rtl'\n\nexport type ServiceCreatorFunc<T> = (sdk: IAPIMethods, timeToLive?: number) => T\n\nexport interface IServiceFactory {\n /**\n * Retrieves a service\n * @param serviceName to retrieve\n */\n get<T>(serviceName: string): T\n /**\n * Registers or creates a service\n * @param serviceName name of service.\n * @param serviceCreator function that creates the service.\n * @param timeToLive in seconds, for the service cache. Defaults to 15 minutes.\n */\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ): void\n}\n\n/**\n * A factory for registering and maintaining services\n */\nclass ServiceFactory implements IServiceFactory {\n servicesMap: Record<string, any> = {}\n constructor(private sdk: IAPIMethods) {}\n\n get<T>(serviceName: string): T {\n const service = this.servicesMap[serviceName]\n if (!service) {\n throw new Error(`Service ${serviceName} not found`)\n }\n return service\n }\n\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ) {\n let service = this.servicesMap[serviceName]\n if (!service) {\n service = serviceCreator(this.sdk, timeToLive)\n this.servicesMap[serviceName] = service\n }\n return service\n }\n}\n\nlet factory: IServiceFactory | undefined\n\n/**\n * Helper method for creating a singleton factory\n * @param sdk\n */\nexport function createFactory(sdk: IAPIMethods) {\n factory = new ServiceFactory(sdk)\n}\n\n/**\n * Helper method for getting the factory\n */\nexport function getFactory() {\n if (!factory) {\n throw new Error('Factory must be created with an SDK.')\n }\n return factory\n}\n\n/**\n * Helper method for destroying the factory\n */\nexport function destroyFactory() {\n factory = undefined\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceFactory.js","names":["ServiceFactory","constructor","sdk","_defineProperty","get","serviceName","service","servicesMap","Error","concat","register","serviceCreator","timeToLive","factory","createFactory","getFactory","destroyFactory","undefined"],"sources":["../../src/ServiceFactory.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { IAPIMethods } from '@looker/sdk-rtl'\n\nexport type ServiceCreatorFunc<T> = (sdk: IAPIMethods, timeToLive?: number) => T\n\nexport interface IServiceFactory {\n /**\n * Retrieves a service\n * @param serviceName to retrieve\n */\n get<T>(serviceName: string): T\n /**\n * Registers or creates a service\n * @param serviceName name of service.\n * @param serviceCreator function that creates the service.\n * @param timeToLive in seconds, for the service cache. Defaults to 15 minutes.\n */\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ): void\n}\n\n/**\n * A factory for registering and maintaining services\n */\nclass ServiceFactory implements IServiceFactory {\n servicesMap: Record<string, any> = {}\n constructor(private sdk: IAPIMethods) {}\n\n get<T>(serviceName: string): T {\n const service = this.servicesMap[serviceName]\n if (!service) {\n throw new Error(`Service ${serviceName} not found`)\n }\n return service\n }\n\n register<T>(\n serviceName: string,\n serviceCreator: ServiceCreatorFunc<T>,\n timeToLive?: number\n ) {\n let service = this.servicesMap[serviceName]\n if (!service) {\n service = serviceCreator(this.sdk, timeToLive)\n this.servicesMap[serviceName] = service\n }\n return service\n }\n}\n\nlet factory: IServiceFactory | undefined\n\n/**\n * Helper method for creating a singleton factory\n * @param sdk\n */\nexport function createFactory(sdk: IAPIMethods) {\n factory = new ServiceFactory(sdk)\n}\n\n/**\n * Helper method for getting the factory\n */\nexport function getFactory() {\n if (!factory) {\n throw new Error('Factory must be created with an SDK.')\n }\n return factory\n}\n\n/**\n * Helper method for destroying the factory\n */\nexport function destroyFactory() {\n factory = undefined\n}\n"],"mappings":";;;AAmDA,MAAMA,cAAc,CAA4B;EAE9CC,WAAWA,CAASC,GAAgB,EAAE;IAAA,KAAlBA,GAAgB,GAAhBA,GAAgB;IAAAC,eAAA,sBADD,CAAC,CAAC;EACE;EAEvCC,GAAGA,CAAIC,WAAmB,EAAK;IAC7B,IAAMC,OAAO,GAAG,IAAI,CAACC,WAAW,CAACF,WAAW,CAAC;IAC7C,IAAI,CAACC,OAAO,EAAE;MACZ,MAAM,IAAIE,KAAK,YAAAC,MAAA,CAAYJ,WAAW,eAAY,CAAC;IACrD;IACA,OAAOC,OAAO;EAChB;EAEAI,QAAQA,CACNL,WAAmB,EACnBM,cAAqC,EACrCC,UAAmB,EACnB;IACA,IAAIN,OAAO,GAAG,IAAI,CAACC,WAAW,CAACF,WAAW,CAAC;IAC3C,IAAI,CAACC,OAAO,EAAE;MACZA,OAAO,GAAGK,cAAc,CAAC,IAAI,CAACT,GAAG,EAAEU,UAAU,CAAC;MAC9C,IAAI,CAACL,WAAW,CAACF,WAAW,CAAC,GAAGC,OAAO;IACzC;IACA,OAAOA,OAAO;EAChB;AACF;AAEA,IAAIO,OAAoC;AAMxC,OAAO,SAASC,aAAaA,CAACZ,GAAgB,EAAE;EAC9CW,OAAO,GAAG,IAAIb,cAAc,CAACE,GAAG,CAAC;AACnC;AAKA,OAAO,SAASa,UAAUA,CAAA,EAAG;EAC3B,IAAI,CAACF,OAAO,EAAE;IACZ,MAAM,IAAIL,KAAK,CAAC,sCAAsC,CAAC;EACzD;EACA,OAAOK,OAAO;AAChB;AAKA,OAAO,SAASG,cAAcA,CAAA,EAAG;EAC/BH,OAAO,GAAGI,SAAS;AACrB"}
|
package/lib/esm/ThemeService.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.themeServiceCreator = exports.registerThemeService = exports.getThemeService = exports.THEME_SERVICE_NAME = void 0;
|
|
7
|
-
var _sdk = require("@looker/sdk");
|
|
8
|
-
var _ItemList = require("./ItemList");
|
|
9
|
-
var _ServiceFactory = require("./ServiceFactory");
|
|
10
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
2
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
-
|
|
6
|
+
import { all_themes, default_theme, delete_theme, theme, update_theme } from '@looker/sdk';
|
|
7
|
+
import { ItemList } from './ItemList';
|
|
8
|
+
import { getFactory } from './ServiceFactory';
|
|
9
|
+
class ThemeService extends ItemList {
|
|
16
10
|
constructor() {
|
|
17
11
|
super(...arguments);
|
|
18
12
|
_defineProperty(this, "defaultTheme", void 0);
|
|
@@ -26,7 +20,7 @@ class ThemeService extends _ItemList.ItemList {
|
|
|
26
20
|
if (cache && item) {
|
|
27
21
|
return item;
|
|
28
22
|
}
|
|
29
|
-
item = yield _this.sdk.ok(
|
|
23
|
+
item = yield _this.sdk.ok(theme(_this.sdk, id, options === null || options === void 0 ? void 0 : options.fields));
|
|
30
24
|
if (item) {
|
|
31
25
|
_this.items = [..._this.items, item];
|
|
32
26
|
_this.index();
|
|
@@ -49,7 +43,7 @@ class ThemeService extends _ItemList.ItemList {
|
|
|
49
43
|
var _this3 = this;
|
|
50
44
|
return _asyncToGenerator(function* () {
|
|
51
45
|
_this3.clearIfExpired();
|
|
52
|
-
var theme = yield _this3.sdk.ok(
|
|
46
|
+
var theme = yield _this3.sdk.ok(update_theme(_this3.sdk, id, item));
|
|
53
47
|
if (theme) {
|
|
54
48
|
_this3.items = [..._this3.items, theme];
|
|
55
49
|
_this3.index();
|
|
@@ -62,7 +56,7 @@ class ThemeService extends _ItemList.ItemList {
|
|
|
62
56
|
var _this4 = this;
|
|
63
57
|
return _asyncToGenerator(function* () {
|
|
64
58
|
if (_this4.expired()) {
|
|
65
|
-
_this4.defaultTheme = yield _this4.sdk.ok(
|
|
59
|
+
_this4.defaultTheme = yield _this4.sdk.ok(default_theme(_this4.sdk, ts));
|
|
66
60
|
}
|
|
67
61
|
return _this4.defaultTheme;
|
|
68
62
|
})();
|
|
@@ -71,7 +65,7 @@ class ThemeService extends _ItemList.ItemList {
|
|
|
71
65
|
var _this5 = this;
|
|
72
66
|
return _asyncToGenerator(function* () {
|
|
73
67
|
_this5.clearIfExpired();
|
|
74
|
-
yield _this5.sdk.ok(
|
|
68
|
+
yield _this5.sdk.ok(delete_theme(_this5.sdk, id));
|
|
75
69
|
_this5.items = _this5.items.filter(item => item.id !== id);
|
|
76
70
|
_this5.index();
|
|
77
71
|
})();
|
|
@@ -80,23 +74,19 @@ class ThemeService extends _ItemList.ItemList {
|
|
|
80
74
|
var _this6 = this;
|
|
81
75
|
return _asyncToGenerator(function* () {
|
|
82
76
|
yield _this6.getDefaultTheme();
|
|
83
|
-
_this6.items = yield _this6.sdk.ok(
|
|
77
|
+
_this6.items = yield _this6.sdk.ok(all_themes(_this6.sdk, options === null || options === void 0 ? void 0 : options.fields));
|
|
84
78
|
_this6.index();
|
|
85
79
|
_this6.setExpiration();
|
|
86
80
|
return _this6;
|
|
87
81
|
})();
|
|
88
82
|
}
|
|
89
83
|
}
|
|
90
|
-
var THEME_SERVICE_NAME = 'ThemeService';
|
|
91
|
-
|
|
92
|
-
var themeServiceCreator = (sdk, timeToLive) => {
|
|
84
|
+
export var THEME_SERVICE_NAME = 'ThemeService';
|
|
85
|
+
export var themeServiceCreator = (sdk, timeToLive) => {
|
|
93
86
|
return new ThemeService(sdk, timeToLive);
|
|
94
87
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(0, _ServiceFactory.getFactory)().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive);
|
|
88
|
+
export var registerThemeService = timeToLive => {
|
|
89
|
+
getFactory().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive);
|
|
98
90
|
};
|
|
99
|
-
|
|
100
|
-
var getThemeService = () => (0, _ServiceFactory.getFactory)().get(THEME_SERVICE_NAME);
|
|
101
|
-
exports.getThemeService = getThemeService;
|
|
91
|
+
export var getThemeService = () => getFactory().get(THEME_SERVICE_NAME);
|
|
102
92
|
//# sourceMappingURL=ThemeService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeService.js","names":["_sdk","require","_ItemList","_ServiceFactory","asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","_defineProperty","obj","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","res","call","TypeError","Number","ThemeService","ItemList","constructor","get","id","options","_this","cache","getCacheDefault","clearIfExpired","item","indexedItems","sdk","ok","theme","fields","items","index","setExpiration","getAll","_this2","expired","load","set","_this3","update_theme","getDefaultTheme","ts","_this4","defaultTheme","default_theme","delete","_this5","delete_theme","filter","_this6","all_themes","THEME_SERVICE_NAME","exports","themeServiceCreator","timeToLive","registerThemeService","getFactory","register","getThemeService"],"sources":["../../src/ThemeService.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { ITheme } from '@looker/sdk'\nimport {\n all_themes,\n default_theme,\n delete_theme,\n theme,\n update_theme,\n} from '@looker/sdk'\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { ItemList } from './ItemList'\nimport type { IEntityService, IItemList, GetOptions } from './ItemList'\nimport type { ServiceCreatorFunc } from './ServiceFactory'\nimport { getFactory } from './ServiceFactory'\n\nexport interface IThemeService\n extends IItemList<ITheme>,\n IEntityService<ITheme> {\n defaultTheme?: ITheme\n /**\n * Gets the default theme\n * @param ts Timestamp representing the target datetime for the active period. Defaults to 'now'\n */\n getDefaultTheme(ts?: Date, options?: GetOptions): Promise<ITheme>\n /**\n * Retrieves all themes and the default theme\n */\n load(options?: GetOptions): Promise<IThemeService>\n}\n\nclass ThemeService extends ItemList<ITheme> implements IThemeService {\n public defaultTheme?: ITheme\n\n /**\n * Get theme by id\n * @param id of theme to retrieve\n * @param options to get\n */\n async get(id: string, options?: GetOptions): Promise<Partial<ITheme>> {\n // TODO: implement logic to check if requested fields are already cached.\n const cache = this.getCacheDefault(options)\n this.clearIfExpired()\n let item = this.indexedItems[id]\n\n if (cache && item) {\n return item\n }\n\n item = await this.sdk.ok(theme(this.sdk, id, options?.fields))\n\n if (item) {\n this.items = [...this.items, item]\n this.index()\n this.setExpiration()\n }\n return item\n }\n\n /**\n * Get all themes, including the default theme\n * @param options to get\n */\n async getAll(options?: GetOptions) {\n if (this.getCacheDefault(options) && !this.expired()) {\n return this\n }\n await this.load(options)\n return this\n }\n\n /**\n * Updates a theme\n * @param id id of theme to update\n * @param item with updated fields\n */\n async set(id: string, item: ITheme) {\n this.clearIfExpired()\n const theme = await this.sdk.ok(update_theme(this.sdk, id, item))\n if (theme) {\n this.items = [...this.items, theme]\n this.index()\n this.setExpiration()\n }\n return theme\n }\n\n async getDefaultTheme(ts?: Date) {\n if (this.expired()) {\n this.defaultTheme = await this.sdk.ok(default_theme(this.sdk, ts))\n }\n return this.defaultTheme as ITheme\n }\n\n /**\n * Deletes a theme\n * @param id of theme to delete\n */\n async delete(id: string) {\n this.clearIfExpired()\n await this.sdk.ok(delete_theme(this.sdk, id))\n this.items = this.items.filter((item) => item.id !== id)\n this.index()\n }\n\n async load(options?: GetOptions) {\n await this.getDefaultTheme()\n this.items = await this.sdk.ok(all_themes(this.sdk, options?.fields))\n this.index()\n this.setExpiration()\n return this\n }\n}\n\nexport const THEME_SERVICE_NAME = 'ThemeService'\n\n/**\n * A theme service creator helper function\n * @param sdk\n * @param timeToLive in seconds for the cache\n */\nexport const themeServiceCreator: ServiceCreatorFunc<IThemeService> = (\n sdk: IAPIMethods,\n timeToLive?: number\n) => {\n return new ThemeService(sdk, timeToLive)\n}\n\n/**\n * Creates and registers the theme service with the service factory\n * @param timeToLive in seconds for the cache\n */\nexport const registerThemeService = (timeToLive?: number) => {\n getFactory().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive)\n}\n\n/**\n * Gets the theme service registered with the service factory\n */\nexport const getThemeService = () =>\n getFactory().get<IThemeService>(THEME_SERVICE_NAME)\n"],"mappings":";;;;;;AA0BA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,SAAA,GAAAD,OAAA;A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AChB,KAAK,CAACkB,MAAM,CAAExB,IAAI,IAAKA,IAAI,CAACN,EAAE,KAAKA,EAAE,CAAC;MACxD4B,MAAI,CAACf,KAAK,EAAE;IAAA;EACd;EAEMK,IAAIA,CAACjB,OAAoB,EAAE;IAAA,IAAA8B,MAAA;IAAA,OAAA9D,iBAAA;MAC/B,MAAM8D,MAAI,CAACT,eAAe,EAAE;MAC5BS,MAAI,CAACnB,KAAK,SAASmB,MAAI,CAACvB,GAAG,CAACC,EAAE,CAAC,IAAAuB,eAAU,EAACD,MAAI,CAACvB,GAAG,EAAEP,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEU,MAAM,CAAC,CAAC;MACrEoB,MAAI,CAAClB,KAAK,EAAE;MACZkB,MAAI,CAACjB,aAAa,EAAE;MACpB,OAAOiB,MAAI;IAAA;EACb;AACF;AAEO,IAAME,kBAAkB,GAAG,cAAc;AAAAC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAOzC,IAAME,mBAAsD,GAAGA,CACpE3B,GAAgB,EAChB4B,UAAmB,KAChB;EACH,OAAO,IAAIxC,YAAY,CAACY,GAAG,EAAE4B,UAAU,CAAC;AAC1C,CAAC;AAAAF,OAAA,CAAAC,mBAAA,GAAAA,mBAAA;AAMM,IAAME,oBAAoB,GAAID,UAAmB,IAAK;EAC3D,IAAAE,0BAAU,GAAE,CAACC,QAAQ,CAACN,kBAAkB,EAAEE,mBAAmB,EAAEC,UAAU,CAAC;AAC5E,CAAC;AAAAF,OAAA,CAAAG,oBAAA,GAAAA,oBAAA;AAKM,IAAMG,eAAe,GAAGA,CAAA,KAC7B,IAAAF,0BAAU,GAAE,CAACvC,GAAG,CAAgBkC,kBAAkB,CAAC;AAAAC,OAAA,CAAAM,eAAA,GAAAA,eAAA"}
|
|
1
|
+
{"version":3,"file":"ThemeService.js","names":["all_themes","default_theme","delete_theme","theme","update_theme","ItemList","getFactory","ThemeService","constructor","arguments","_defineProperty","get","id","options","_this","_asyncToGenerator","cache","getCacheDefault","clearIfExpired","item","indexedItems","sdk","ok","fields","items","index","setExpiration","getAll","_this2","expired","load","set","_this3","getDefaultTheme","ts","_this4","defaultTheme","delete","_this5","filter","_this6","THEME_SERVICE_NAME","themeServiceCreator","timeToLive","registerThemeService","register","getThemeService"],"sources":["../../src/ThemeService.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport type { ITheme } from '@looker/sdk'\nimport {\n all_themes,\n default_theme,\n delete_theme,\n theme,\n update_theme,\n} from '@looker/sdk'\nimport type { IAPIMethods } from '@looker/sdk-rtl'\nimport { ItemList } from './ItemList'\nimport type { IEntityService, IItemList, GetOptions } from './ItemList'\nimport type { ServiceCreatorFunc } from './ServiceFactory'\nimport { getFactory } from './ServiceFactory'\n\nexport interface IThemeService\n extends IItemList<ITheme>,\n IEntityService<ITheme> {\n defaultTheme?: ITheme\n /**\n * Gets the default theme\n * @param ts Timestamp representing the target datetime for the active period. Defaults to 'now'\n */\n getDefaultTheme(ts?: Date, options?: GetOptions): Promise<ITheme>\n /**\n * Retrieves all themes and the default theme\n */\n load(options?: GetOptions): Promise<IThemeService>\n}\n\nclass ThemeService extends ItemList<ITheme> implements IThemeService {\n public defaultTheme?: ITheme\n\n /**\n * Get theme by id\n * @param id of theme to retrieve\n * @param options to get\n */\n async get(id: string, options?: GetOptions): Promise<Partial<ITheme>> {\n // TODO: implement logic to check if requested fields are already cached.\n const cache = this.getCacheDefault(options)\n this.clearIfExpired()\n let item = this.indexedItems[id]\n\n if (cache && item) {\n return item\n }\n\n item = await this.sdk.ok(theme(this.sdk, id, options?.fields))\n\n if (item) {\n this.items = [...this.items, item]\n this.index()\n this.setExpiration()\n }\n return item\n }\n\n /**\n * Get all themes, including the default theme\n * @param options to get\n */\n async getAll(options?: GetOptions) {\n if (this.getCacheDefault(options) && !this.expired()) {\n return this\n }\n await this.load(options)\n return this\n }\n\n /**\n * Updates a theme\n * @param id id of theme to update\n * @param item with updated fields\n */\n async set(id: string, item: ITheme) {\n this.clearIfExpired()\n const theme = await this.sdk.ok(update_theme(this.sdk, id, item))\n if (theme) {\n this.items = [...this.items, theme]\n this.index()\n this.setExpiration()\n }\n return theme\n }\n\n async getDefaultTheme(ts?: Date) {\n if (this.expired()) {\n this.defaultTheme = await this.sdk.ok(default_theme(this.sdk, ts))\n }\n return this.defaultTheme as ITheme\n }\n\n /**\n * Deletes a theme\n * @param id of theme to delete\n */\n async delete(id: string) {\n this.clearIfExpired()\n await this.sdk.ok(delete_theme(this.sdk, id))\n this.items = this.items.filter((item) => item.id !== id)\n this.index()\n }\n\n async load(options?: GetOptions) {\n await this.getDefaultTheme()\n this.items = await this.sdk.ok(all_themes(this.sdk, options?.fields))\n this.index()\n this.setExpiration()\n return this\n }\n}\n\nexport const THEME_SERVICE_NAME = 'ThemeService'\n\n/**\n * A theme service creator helper function\n * @param sdk\n * @param timeToLive in seconds for the cache\n */\nexport const themeServiceCreator: ServiceCreatorFunc<IThemeService> = (\n sdk: IAPIMethods,\n timeToLive?: number\n) => {\n return new ThemeService(sdk, timeToLive)\n}\n\n/**\n * Creates and registers the theme service with the service factory\n * @param timeToLive in seconds for the cache\n */\nexport const registerThemeService = (timeToLive?: number) => {\n getFactory().register(THEME_SERVICE_NAME, themeServiceCreator, timeToLive)\n}\n\n/**\n * Gets the theme service registered with the service factory\n */\nexport const getThemeService = () =>\n getFactory().get<IThemeService>(THEME_SERVICE_NAME)\n"],"mappings":";;;;;AA0BA,SACEA,UAAU,EACVC,aAAa,EACbC,YAAY,EACZC,KAAK,EACLC,YAAY,QACP,aAAa;AAEpB,SAASC,QAAQ,QAAQ,YAAY;AAGrC,SAASC,UAAU,QAAQ,kBAAkB;AAiB7C,MAAMC,YAAY,SAASF,QAAQ,CAAkC;EAAAG,YAAA;IAAA,SAAAC,SAAA;IAAAC,eAAA;EAAA;EAQ7DC,GAAGA,CAACC,EAAU,EAAEC,OAAoB,EAA4B;IAAA,IAAAC,KAAA;IAAA,OAAAC,iBAAA;MAEpE,IAAMC,KAAK,GAAGF,KAAI,CAACG,eAAe,CAACJ,OAAO,CAAC;MAC3CC,KAAI,CAACI,cAAc,CAAC,CAAC;MACrB,IAAIC,IAAI,GAAGL,KAAI,CAACM,YAAY,CAACR,EAAE,CAAC;MAEhC,IAAII,KAAK,IAAIG,IAAI,EAAE;QACjB,OAAOA,IAAI;MACb;MAEAA,IAAI,SAASL,KAAI,CAACO,GAAG,CAACC,EAAE,CAACnB,KAAK,CAACW,KAAI,CAACO,GAAG,EAAET,EAAE,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEU,MAAM,CAAC,CAAC;MAE9D,IAAIJ,IAAI,EAAE;QACRL,KAAI,CAACU,KAAK,GAAG,CAAC,GAAGV,KAAI,CAACU,KAAK,EAAEL,IAAI,CAAC;QAClCL,KAAI,CAACW,KAAK,CAAC,CAAC;QACZX,KAAI,CAACY,aAAa,CAAC,CAAC;MACtB;MACA,OAAOP,IAAI;IAAA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
|
-
Object.keys(_EmbedUrl).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _EmbedUrl[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _EmbedUrl[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _ServiceFactory = require("./ServiceFactory");
|
|
18
|
-
Object.keys(_ServiceFactory).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _ServiceFactory[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _ServiceFactory[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _ThemeService = require("./ThemeService");
|
|
29
|
-
Object.keys(_ThemeService).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _ThemeService[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function get() {
|
|
35
|
-
return _ThemeService[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
1
|
+
export * from './EmbedUrl';
|
|
2
|
+
export * from './ServiceFactory';
|
|
3
|
+
export * from './ThemeService';
|
|
39
4
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nexport * from './EmbedUrl'\nexport * from './ServiceFactory'\nexport * from './ThemeService'\n"],"mappings":"AAyBA,cAAc,YAAY;AAC1B,cAAc,kBAAkB;AAChC,cAAc,gBAAgB"}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _utils = require("./utils");
|
|
7
|
-
Object.keys(_utils).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _utils[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _utils[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
1
|
+
export * from './utils';
|
|
17
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/test-utils/index.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nexport * from './utils'\n"],"mappings":"AAyBA,cAAc,SAAS"}
|
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.timeout = exports.session = exports.rootFile = exports.getRootPath = exports.TestConfig = void 0;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var fs = _interopRequireWildcard(require("fs"));
|
|
9
|
-
var _sdk = require("@looker/sdk");
|
|
10
|
-
var _sdkNode = require("@looker/sdk-node");
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { environmentPrefix } from '@looker/sdk';
|
|
4
|
+
import { NodeSession, NodeSettingsIniFile } from '@looker/sdk-node';
|
|
14
5
|
var homeToRoost = '../../../../';
|
|
15
|
-
var getRootPath = () =>
|
|
16
|
-
|
|
17
|
-
var rootFile = function rootFile() {
|
|
6
|
+
export var getRootPath = () => path.join(__dirname, homeToRoost);
|
|
7
|
+
export var rootFile = function rootFile() {
|
|
18
8
|
var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
19
|
-
return
|
|
9
|
+
return path.join(getRootPath(), fileName);
|
|
20
10
|
};
|
|
21
|
-
exports.rootFile = rootFile;
|
|
22
11
|
var localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini');
|
|
23
|
-
var settings = new
|
|
24
|
-
var session = new
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
exports.timeout = timeout;
|
|
28
|
-
var TestConfig = () => {
|
|
12
|
+
var settings = new NodeSettingsIniFile(environmentPrefix, localIni, 'Looker');
|
|
13
|
+
export var session = new NodeSession(settings);
|
|
14
|
+
export var timeout = 3600000;
|
|
15
|
+
export var TestConfig = () => {
|
|
29
16
|
var testFile = 'data.yml.json';
|
|
30
17
|
var testPath = rootFile('test/');
|
|
31
18
|
var dataFile = "".concat(testPath).concat(testFile);
|
|
@@ -34,5 +21,4 @@ var TestConfig = () => {
|
|
|
34
21
|
testData
|
|
35
22
|
};
|
|
36
23
|
};
|
|
37
|
-
exports.TestConfig = TestConfig;
|
|
38
24
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["
|
|
1
|
+
{"version":3,"file":"utils.js","names":["path","fs","environmentPrefix","NodeSession","NodeSettingsIniFile","homeToRoost","getRootPath","join","__dirname","rootFile","fileName","arguments","length","undefined","localIni","process","env","LOOKERSDK_INI","settings","session","timeout","TestConfig","testFile","testPath","dataFile","concat","testData","JSON","parse","readFileSync"],"sources":["../../../src/test-utils/utils.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport * as fs from 'fs'\nimport { environmentPrefix } from '@looker/sdk'\nimport { NodeSession, NodeSettingsIniFile } from '@looker/sdk-node'\n\nconst homeToRoost = '../../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\nconst localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini')\n\nconst settings = new NodeSettingsIniFile(environmentPrefix, localIni, 'Looker')\nexport const session = new NodeSession(settings)\n\nexport const timeout = 3600000 // 1 hr\n\ninterface ITestConfig {\n testData: any\n}\n\nexport const TestConfig = (): ITestConfig => {\n const testFile = 'data.yml.json'\n const testPath = rootFile('test/')\n const dataFile = `${testPath}${testFile}`\n const testData = JSON.parse(fs.readFileSync(dataFile, 'utf-8'))\n return {\n testData,\n }\n}\n"],"mappings":"AAyBA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAO,KAAKC,EAAE,MAAM,IAAI;AACxB,SAASC,iBAAiB,QAAQ,aAAa;AAC/C,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,kBAAkB;AAEnE,IAAMC,WAAW,GAAG,cAAc;AAElC,OAAO,IAAMC,WAAW,GAAGA,CAAA,KAAMN,IAAI,CAACO,IAAI,CAACC,SAAS,EAAEH,WAAW,CAAC;AAClE,OAAO,IAAMI,QAAQ,GAAG,SAAXA,QAAQA,CAAA;EAAA,IAAIC,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAAA,OAAKX,IAAI,CAACO,IAAI,CAACD,WAAW,CAAC,CAAC,EAAEI,QAAQ,CAAC;AAAA;AAC7E,IAAMI,QAAQ,GAAGC,OAAO,CAACC,GAAG,CAACC,aAAa,IAAIR,QAAQ,CAAC,YAAY,CAAC;AAEpE,IAAMS,QAAQ,GAAG,IAAId,mBAAmB,CAACF,iBAAiB,EAAEY,QAAQ,EAAE,QAAQ,CAAC;AAC/E,OAAO,IAAMK,OAAO,GAAG,IAAIhB,WAAW,CAACe,QAAQ,CAAC;AAEhD,OAAO,IAAME,OAAO,GAAG,OAAO;AAM9B,OAAO,IAAMC,UAAU,GAAGA,CAAA,KAAmB;EAC3C,IAAMC,QAAQ,GAAG,eAAe;EAChC,IAAMC,QAAQ,GAAGd,QAAQ,CAAC,OAAO,CAAC;EAClC,IAAMe,QAAQ,MAAAC,MAAA,CAAMF,QAAQ,EAAAE,MAAA,CAAGH,QAAQ,CAAE;EACzC,IAAMI,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAAC3B,EAAE,CAAC4B,YAAY,CAACL,QAAQ,EAAE,OAAO,CAAC,CAAC;EAC/D,OAAO;IACLE;EACF,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_path","_interopRequireDefault","require","fs","_interopRequireWildcard","_sdk","_sdkNode","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","homeToRoost","getRootPath","path","join","__dirname","exports","rootFile","fileName","arguments","length","undefined","localIni","process","env","LOOKERSDK_INI","settings","NodeSettingsIniFile","environmentPrefix","session","NodeSession","timeout","TestConfig","testFile","testPath","dataFile","concat","testData","JSON","parse","readFileSync"],"sources":["../../src/test-utils/utils.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport * as fs from 'fs'\nimport { environmentPrefix } from '@looker/sdk'\nimport { NodeSession, NodeSettingsIniFile } from '@looker/sdk-node'\n\nconst homeToRoost = '../../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\nconst localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini')\n\nconst settings = new NodeSettingsIniFile(environmentPrefix, localIni, 'Looker')\nexport const session = new NodeSession(settings)\n\nexport const timeout = 3600000 // 1 hr\n\ninterface ITestConfig {\n testData: any\n}\n\nexport const TestConfig = (): ITestConfig => {\n const testFile = 'data.yml.json'\n const testPath = rootFile('test/')\n const dataFile = `${testPath}${testFile}`\n const testData = JSON.parse(fs.readFileSync(dataFile, 'utf-8'))\n return {\n testData,\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,EAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAmE,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,S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C,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAAA,OAAKN,aAAI,CAACC,IAAI,CAACF,WAAW,
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_path","_interopRequireDefault","require","fs","_interopRequireWildcard","_sdk","_sdkNode","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","homeToRoost","getRootPath","path","join","__dirname","exports","rootFile","fileName","arguments","length","undefined","localIni","process","env","LOOKERSDK_INI","settings","NodeSettingsIniFile","environmentPrefix","session","NodeSession","timeout","TestConfig","testFile","testPath","dataFile","concat","testData","JSON","parse","readFileSync"],"sources":["../../src/test-utils/utils.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2023 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport * as fs from 'fs'\nimport { environmentPrefix } from '@looker/sdk'\nimport { NodeSession, NodeSettingsIniFile } from '@looker/sdk-node'\n\nconst homeToRoost = '../../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\nconst localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini')\n\nconst settings = new NodeSettingsIniFile(environmentPrefix, localIni, 'Looker')\nexport const session = new NodeSession(settings)\n\nexport const timeout = 3600000 // 1 hr\n\ninterface ITestConfig {\n testData: any\n}\n\nexport const TestConfig = (): ITestConfig => {\n const testFile = 'data.yml.json'\n const testPath = rootFile('test/')\n const dataFile = `${testPath}${testFile}`\n const testData = JSON.parse(fs.readFileSync(dataFile, 'utf-8'))\n return {\n testData,\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,EAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAmE,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA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C,sBAAiB,EAAEN,QAAQ,EAAE,QAAQ,CAAC;AACxE,IAAMO,OAAO,GAAG,IAAIC,oBAAW,CAACJ,QAAQ,CAAC;AAAAV,OAAA,CAAAa,OAAA,GAAAA,OAAA;AAEzC,IAAME,OAAO,GAAG,OAAO;AAAAf,OAAA,CAAAe,OAAA,GAAAA,OAAA;AAMvB,IAAMC,UAAU,GAAGA,CAAA,KAAmB;EAC3C,IAAMC,QAAQ,GAAG,eAAe;EAChC,IAAMC,QAAQ,GAAGjB,QAAQ,CAAC,OAAO,CAAC;EAClC,IAAMkB,QAAQ,MAAAC,MAAA,CAAMF,QAAQ,EAAAE,MAAA,CAAGH,QAAQ,CAAE;EACzC,IAAMI,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACtD,EAAE,CAACuD,YAAY,CAACL,QAAQ,EAAE,OAAO,CAAC,CAAC;EAC/D,OAAO;IACLE;EACF,CAAC;AACH,CAAC;AAAArB,OAAA,CAAAgB,UAAA,GAAAA,UAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@looker/embed-services",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.18.0",
|
|
4
4
|
"description": "Looker Embed Services",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/looker-open-source/sdk-codegen/tree/master/packages/embed-services",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@looker/sdk-node": "^23.
|
|
37
|
+
"@looker/sdk-node": "^23.18.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@looker/sdk": "^23.
|
|
40
|
+
"@looker/sdk": "^23.18.0",
|
|
41
41
|
"@looker/sdk-rtl": "^21.6.1"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"Embed",
|
|
46
46
|
"Embed Services"
|
|
47
47
|
],
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "008b8386e4019bb33465e513c022a929282b30d1"
|
|
49
49
|
}
|