@looker/api-explorer 0.9.26 → 0.9.27

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.
Files changed (214) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/e2e/e2e.spec.ts +1 -1
  3. package/lib/ApiExplorer.d.ts +2 -6
  4. package/lib/ApiExplorer.js +53 -74
  5. package/lib/ApiExplorer.js.map +1 -1
  6. package/lib/StandaloneApiExplorer.js +35 -47
  7. package/lib/StandaloneApiExplorer.js.map +1 -1
  8. package/lib/components/Banner/Banner.d.ts +8 -0
  9. package/lib/components/Banner/Banner.js +70 -0
  10. package/lib/components/Banner/Banner.js.map +1 -0
  11. package/lib/components/Banner/index.d.ts +1 -0
  12. package/lib/components/Banner/index.js +14 -0
  13. package/lib/components/Banner/index.js.map +1 -0
  14. package/lib/components/DocSDKs/DocSDKs.js +3 -3
  15. package/lib/components/DocSDKs/DocSDKs.js.map +1 -1
  16. package/lib/components/ExploreType/ExploreType.js +3 -5
  17. package/lib/components/ExploreType/ExploreType.js.map +1 -1
  18. package/lib/components/Header/Header.d.ts +2 -5
  19. package/lib/components/Header/Header.js +1 -5
  20. package/lib/components/Header/Header.js.map +1 -1
  21. package/lib/components/SelectorContainer/ApiSpecSelector.d.ts +2 -5
  22. package/lib/components/SelectorContainer/ApiSpecSelector.js +5 -5
  23. package/lib/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  24. package/lib/components/SelectorContainer/SelectorContainer.d.ts +2 -5
  25. package/lib/components/SelectorContainer/SelectorContainer.js +3 -7
  26. package/lib/components/SelectorContainer/SelectorContainer.js.map +1 -1
  27. package/lib/components/SideNav/SideNav.d.ts +2 -5
  28. package/lib/components/SideNav/SideNav.js.map +1 -1
  29. package/lib/components/index.d.ts +1 -0
  30. package/lib/components/index.js +8 -0
  31. package/lib/components/index.js.map +1 -1
  32. package/lib/esm/ApiExplorer.js +54 -74
  33. package/lib/esm/ApiExplorer.js.map +1 -1
  34. package/lib/esm/StandaloneApiExplorer.js +34 -48
  35. package/lib/esm/StandaloneApiExplorer.js.map +1 -1
  36. package/lib/esm/components/Banner/Banner.js +54 -0
  37. package/lib/esm/components/Banner/Banner.js.map +1 -0
  38. package/lib/esm/components/Banner/index.js +2 -0
  39. package/lib/esm/components/Banner/index.js.map +1 -0
  40. package/lib/esm/components/DocSDKs/DocSDKs.js +2 -2
  41. package/lib/esm/components/DocSDKs/DocSDKs.js.map +1 -1
  42. package/lib/esm/components/ExploreType/ExploreType.js +3 -4
  43. package/lib/esm/components/ExploreType/ExploreType.js.map +1 -1
  44. package/lib/esm/components/Header/Header.js +1 -5
  45. package/lib/esm/components/Header/Header.js.map +1 -1
  46. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js +4 -5
  47. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  48. package/lib/esm/components/SelectorContainer/SelectorContainer.js +3 -7
  49. package/lib/esm/components/SelectorContainer/SelectorContainer.js.map +1 -1
  50. package/lib/esm/components/SideNav/SideNav.js.map +1 -1
  51. package/lib/esm/components/index.js +1 -0
  52. package/lib/esm/components/index.js.map +1 -1
  53. package/lib/esm/index.js +1 -0
  54. package/lib/esm/index.js.map +1 -1
  55. package/lib/esm/routes/AppRouter.js +3 -7
  56. package/lib/esm/routes/AppRouter.js.map +1 -1
  57. package/lib/esm/scenes/DiffScene/DiffScene.js +43 -99
  58. package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
  59. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
  60. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  61. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  62. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  63. package/lib/esm/scenes/MethodScene/MethodScene.js +4 -5
  64. package/lib/esm/scenes/MethodScene/MethodScene.js.map +1 -1
  65. package/lib/esm/state/index.js +1 -0
  66. package/lib/esm/state/index.js.map +1 -1
  67. package/lib/esm/state/specs/index.js +3 -0
  68. package/lib/esm/state/specs/index.js.map +1 -0
  69. package/lib/esm/state/specs/sagas.js +58 -0
  70. package/lib/esm/state/specs/sagas.js.map +1 -0
  71. package/lib/esm/state/specs/selectors.js +8 -0
  72. package/lib/esm/state/specs/selectors.js.map +1 -0
  73. package/lib/esm/state/specs/slice.js +55 -0
  74. package/lib/esm/state/specs/slice.js.map +1 -0
  75. package/lib/esm/state/store.js +53 -2
  76. package/lib/esm/state/store.js.map +1 -1
  77. package/lib/esm/test-utils/redux.js +9 -5
  78. package/lib/esm/test-utils/redux.js.map +1 -1
  79. package/lib/esm/utils/adaptorUtils.js +101 -0
  80. package/lib/esm/utils/adaptorUtils.js.map +1 -0
  81. package/lib/esm/utils/apixAdaptor.js +48 -0
  82. package/lib/esm/utils/apixAdaptor.js.map +1 -0
  83. package/lib/esm/utils/index.js +3 -1
  84. package/lib/esm/utils/index.js.map +1 -1
  85. package/lib/esm/utils/path.js +27 -2
  86. package/lib/esm/utils/path.js.map +1 -1
  87. package/lib/index.d.ts +1 -0
  88. package/lib/index.js +13 -0
  89. package/lib/index.js.map +1 -1
  90. package/lib/routes/AppRouter.d.ts +1 -5
  91. package/lib/routes/AppRouter.js +3 -7
  92. package/lib/routes/AppRouter.js.map +1 -1
  93. package/lib/scenes/DiffScene/DiffScene.js +45 -100
  94. package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
  95. package/lib/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
  96. package/lib/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  97. package/lib/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  98. package/lib/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  99. package/lib/scenes/MethodScene/MethodScene.d.ts +0 -4
  100. package/lib/scenes/MethodScene/MethodScene.js +5 -5
  101. package/lib/scenes/MethodScene/MethodScene.js.map +1 -1
  102. package/lib/state/index.d.ts +1 -0
  103. package/lib/state/index.js +13 -0
  104. package/lib/state/index.js.map +1 -1
  105. package/lib/state/settings/selectors.d.ts +1 -1
  106. package/lib/state/settings/slice.d.ts +1 -1
  107. package/lib/state/specs/index.d.ts +2 -0
  108. package/lib/state/specs/index.js +32 -0
  109. package/lib/state/specs/index.js.map +1 -0
  110. package/lib/state/specs/sagas.d.ts +1 -0
  111. package/lib/state/specs/sagas.js +67 -0
  112. package/lib/state/specs/sagas.js.map +1 -0
  113. package/lib/state/specs/selectors.d.ts +4 -0
  114. package/lib/state/specs/selectors.js +20 -0
  115. package/lib/state/specs/selectors.js.map +1 -0
  116. package/lib/state/specs/slice.d.ts +49 -0
  117. package/lib/state/specs/slice.js +70 -0
  118. package/lib/state/specs/slice.js.map +1 -0
  119. package/lib/state/store.d.ts +3 -0
  120. package/lib/state/store.js +56 -2
  121. package/lib/state/store.js.map +1 -1
  122. package/lib/test-data/declarations.d.ts +2 -0
  123. package/lib/test-data/examples.d.ts +2 -0
  124. package/lib/test-data/index.d.ts +3 -0
  125. package/lib/test-data/index.js +12 -42
  126. package/lib/test-data/index.js.map +1 -1
  127. package/lib/test-data/specs.d.ts +10 -0
  128. package/lib/test-data/specs.js +6 -6
  129. package/lib/test-data/specs.js.map +1 -1
  130. package/lib/test-utils/redux.d.ts +2 -1
  131. package/lib/test-utils/redux.js +9 -4
  132. package/lib/test-utils/redux.js.map +1 -1
  133. package/lib/utils/adaptorUtils.d.ts +30 -0
  134. package/lib/utils/adaptorUtils.js +124 -0
  135. package/lib/utils/adaptorUtils.js.map +1 -0
  136. package/lib/utils/apixAdaptor.d.ts +15 -0
  137. package/lib/utils/apixAdaptor.js +67 -0
  138. package/lib/utils/apixAdaptor.js.map +1 -0
  139. package/lib/utils/index.d.ts +3 -1
  140. package/lib/utils/index.js +45 -30
  141. package/lib/utils/index.js.map +1 -1
  142. package/lib/utils/path.d.ts +3 -0
  143. package/lib/utils/path.js +32 -2
  144. package/lib/utils/path.js.map +1 -1
  145. package/package.json +10 -10
  146. package/src/ApiExplorer.tsx +47 -74
  147. package/src/StandaloneApiExplorer.tsx +37 -52
  148. package/src/components/Banner/Banner.spec.tsx +99 -0
  149. package/src/components/Banner/Banner.tsx +87 -0
  150. package/src/{reducers → components/Banner}/index.ts +1 -1
  151. package/src/components/DocSDKs/DocSDKs.tsx +4 -5
  152. package/src/components/ExploreType/ExploreType.spec.tsx +0 -23
  153. package/src/components/ExploreType/ExploreType.tsx +5 -6
  154. package/src/components/ExploreType/exploreUtils.spec.tsx +1 -1
  155. package/src/components/Header/Header.spec.tsx +9 -30
  156. package/src/components/Header/Header.tsx +3 -10
  157. package/src/components/SelectorContainer/ApiSpecSelector.spec.tsx +31 -44
  158. package/src/components/SelectorContainer/ApiSpecSelector.tsx +6 -12
  159. package/src/components/SelectorContainer/SelectorContainer.spec.tsx +7 -26
  160. package/src/components/SelectorContainer/SelectorContainer.tsx +4 -10
  161. package/src/components/SideNav/SideNav.spec.tsx +12 -45
  162. package/src/components/SideNav/SideNav.tsx +1 -7
  163. package/src/components/index.ts +1 -0
  164. package/src/index.ts +1 -0
  165. package/src/routes/AppRouter.tsx +25 -37
  166. package/src/scenes/DiffScene/DiffScene.tsx +47 -84
  167. package/src/scenes/DiffScene/DocDiff/DiffItem.spec.tsx +9 -16
  168. package/src/scenes/DiffScene/DocDiff/DiffItem.tsx +11 -12
  169. package/src/scenes/DiffScene/DocDiff/DocDiff.tsx +2 -2
  170. package/src/scenes/MethodScene/MethodScene.tsx +4 -10
  171. package/src/state/index.ts +1 -0
  172. package/src/{reducers/spec → state/specs}/index.ts +2 -3
  173. package/src/state/specs/sagas.spec.ts +135 -0
  174. package/src/state/specs/sagas.ts +81 -0
  175. package/src/{reducers/spec/actions.spec.ts → state/specs/selectors.ts} +12 -11
  176. package/src/state/specs/slice.ts +109 -0
  177. package/src/state/store.ts +58 -0
  178. package/src/test-data/index.ts +1 -8
  179. package/src/test-data/specs.ts +6 -6
  180. package/src/test-utils/redux.tsx +15 -4
  181. package/src/utils/adaptorUtils.ts +181 -0
  182. package/src/utils/apixAdaptor.ts +72 -0
  183. package/src/utils/index.ts +3 -7
  184. package/src/utils/path.ts +25 -2
  185. package/lib/esm/reducers/index.js +0 -2
  186. package/lib/esm/reducers/index.js.map +0 -1
  187. package/lib/esm/reducers/spec/actions.js +0 -19
  188. package/lib/esm/reducers/spec/actions.js.map +0 -1
  189. package/lib/esm/reducers/spec/index.js +0 -4
  190. package/lib/esm/reducers/spec/index.js.map +0 -1
  191. package/lib/esm/reducers/spec/reducer.js +0 -62
  192. package/lib/esm/reducers/spec/reducer.js.map +0 -1
  193. package/lib/esm/reducers/spec/utils.js +0 -74
  194. package/lib/esm/reducers/spec/utils.js.map +0 -1
  195. package/lib/reducers/index.d.ts +0 -1
  196. package/lib/reducers/index.js +0 -19
  197. package/lib/reducers/index.js.map +0 -1
  198. package/lib/reducers/spec/actions.d.ts +0 -20
  199. package/lib/reducers/spec/actions.js +0 -31
  200. package/lib/reducers/spec/actions.js.map +0 -1
  201. package/lib/reducers/spec/index.d.ts +0 -3
  202. package/lib/reducers/spec/index.js +0 -45
  203. package/lib/reducers/spec/index.js.map +0 -1
  204. package/lib/reducers/spec/reducer.d.ts +0 -7
  205. package/lib/reducers/spec/reducer.js +0 -73
  206. package/lib/reducers/spec/reducer.js.map +0 -1
  207. package/lib/reducers/spec/utils.d.ts +0 -7
  208. package/lib/reducers/spec/utils.js +0 -91
  209. package/lib/reducers/spec/utils.js.map +0 -1
  210. package/src/reducers/spec/actions.ts +0 -62
  211. package/src/reducers/spec/reducer.spec.ts +0 -44
  212. package/src/reducers/spec/reducer.ts +0 -69
  213. package/src/reducers/spec/utils.spec.ts +0 -138
  214. package/src/reducers/spec/utils.ts +0 -123
@@ -0,0 +1,181 @@
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2021 Looker Data Sciences, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ */
26
+
27
+ import type { ILookerVersions, SpecItem, SpecList } from '@looker/sdk-codegen'
28
+ import { ApiModel, upgradeSpecObject } from '@looker/sdk-codegen'
29
+ import { api_spec } from '@looker/sdk'
30
+ import { getEnvAdaptor } from '@looker/extension-utils'
31
+ import type { RunItValues } from '@looker/run-it'
32
+ import { getUrl } from '@looker/run-it'
33
+
34
+ export type StorageLocation = 'session' | 'local'
35
+
36
+ /** Object returned from storage service */
37
+ export interface IStorageValue {
38
+ /** Location of the stored object */
39
+ location: StorageLocation
40
+ /** Stored string representation of the value (usually JSON) */
41
+ value: string
42
+ }
43
+
44
+ /** function to retrieve a spec based on version and name */
45
+ export type ApiSpecFetcher = (
46
+ version: string,
47
+ name: string
48
+ ) => Promise<string | RunItValues>
49
+
50
+ /** Either the spec is parsed or it's undefined */
51
+ export type ParsedSpec = ApiModel | undefined
52
+
53
+ /** service abstraction for extension and browser based usage */
54
+ export interface RunItConfigurator {
55
+ getStorage: (key: string, defaultValue?: string) => IStorageValue
56
+ setStorage(key: string, value: string, location: 'local' | 'session'): string
57
+ removeStorage(key: string): void
58
+ }
59
+
60
+ /** Processed specifications */
61
+ export interface ILoadedSpecs {
62
+ /** API server url */
63
+ baseUrl: string
64
+ /** Web server url */
65
+ webUrl: string
66
+ /** should APIX run headless? */
67
+ headless: boolean
68
+ /** loaded specifications */
69
+ specs: SpecList
70
+ /** communication errors */
71
+ fetchResult: string
72
+ }
73
+
74
+ /** Extends versions payload with headless toggle for API Explorer */
75
+ export interface IAPIXConfig extends ILookerVersions {
76
+ headless?: boolean
77
+ }
78
+
79
+ /**
80
+ * Convert content into an ApiModel
81
+ * @param content to convert
82
+ */
83
+ const makeApi = (content: string | RunItValues) => {
84
+ let json
85
+ if (typeof content === 'string') {
86
+ json = JSON.parse(content)
87
+ } else {
88
+ json = content
89
+ }
90
+ json = upgradeSpecObject(json)
91
+ return ApiModel.fromJson(json)
92
+ }
93
+
94
+ /**
95
+ * Ensure the URI is a full URL
96
+ * @param uri possible relative path
97
+ * @param baseUrl base url for qualifying full path
98
+ */
99
+ export const fullify = (uri: string, baseUrl: string): string => {
100
+ if (uri.match(/^https?:/)) {
101
+ return uri
102
+ }
103
+ const url = new URL(uri, baseUrl)
104
+ return url.toString()
105
+ }
106
+ /**
107
+ * parse spec url into version and name for api_spec cccall
108
+ * @param spec to parse
109
+ */
110
+ const apiSpecBits = (spec: SpecItem): string[] =>
111
+ spec.specURL?.split('/').slice(-2) || []
112
+
113
+ /**
114
+ * Use the functional api_spec fetch
115
+ * @param version to retrieve
116
+ * @param name to retrieve
117
+ */
118
+ export const funFetch = (version: string, name: string): Promise<string> => {
119
+ const sdk = getEnvAdaptor().sdk
120
+ return sdk.ok(api_spec(sdk, version, name))
121
+ }
122
+
123
+ /**
124
+ * try to fetch a spec by URL, trap any errors and return undefined
125
+ * @param url to convert to an API spec
126
+ */
127
+ export const specUrlFetch = async (url: string): Promise<ParsedSpec> => {
128
+ try {
129
+ const content = await getUrl(url)
130
+ return makeApi(content)
131
+ } catch (error) {
132
+ return undefined
133
+ }
134
+ }
135
+
136
+ /**
137
+ * fetch and compile an API specification to an ApiModel if it's not already available
138
+ *
139
+ * **NOTE**: This uses Looker API 4.0 to fetch the specification so fetch works with CORS
140
+ *
141
+ * @param spec to fetch and compile
142
+ * @param fetcher function to retrieve API spec content
143
+ */
144
+ export const sdkSpecFetch = async (
145
+ spec: SpecItem,
146
+ fetcher: ApiSpecFetcher
147
+ ): Promise<ParsedSpec> => {
148
+ if (spec.api) return spec.api
149
+ if (!spec.specURL) return undefined
150
+ const [version, name] = apiSpecBits(spec)
151
+ const content = await fetcher(version, name)
152
+ return makeApi(content)
153
+ }
154
+
155
+ /** Attempt to retrieve spec by URL, then api_spec SDK call
156
+ *
157
+ * @param spec to fetch
158
+ * @param fetcher function to retrieve and parse spec
159
+ */
160
+ export const fallbackFetch = async (
161
+ spec: SpecItem,
162
+ fetcher: ApiSpecFetcher
163
+ ): Promise<ParsedSpec> => {
164
+ if (spec.api) return spec.api
165
+ if (!spec.specURL) return undefined
166
+ let api: ParsedSpec
167
+ try {
168
+ api = await specUrlFetch(spec.specURL)
169
+ } catch (error) {
170
+ console.error({ error })
171
+ }
172
+ if (!api) {
173
+ const sdk = getEnvAdaptor().sdk
174
+ const authed = sdk.authSession.isAuthenticated()
175
+ if (!authed) {
176
+ await sdk.authSession.login()
177
+ }
178
+ api = await sdkSpecFetch(spec, fetcher)
179
+ }
180
+ return api
181
+ }
@@ -0,0 +1,72 @@
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2021 Looker Data Sciences, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ */
26
+ import type { IEnvironmentAdaptor } from '@looker/extension-utils'
27
+ import { BrowserAdaptor, getEnvAdaptor } from '@looker/extension-utils'
28
+ import type { IAPIMethods } from '@looker/sdk-rtl'
29
+ import type { SpecItem, SpecList } from '@looker/sdk-codegen'
30
+ import { getSpecsFromVersions } from '@looker/sdk-codegen'
31
+ import { RunItConfigKey, RunItNoConfig } from '@looker/run-it'
32
+ import cloneDeep from 'lodash/cloneDeep'
33
+
34
+ import { fullify, fallbackFetch, funFetch } from './adaptorUtils'
35
+
36
+ export interface IApixAdaptor extends IEnvironmentAdaptor {
37
+ fetchSpecList(versionsUrl?: string): Promise<SpecList>
38
+ fetchSpec(spec: SpecItem): Promise<SpecItem>
39
+ }
40
+
41
+ export const getApixAdaptor = () => getEnvAdaptor() as IApixAdaptor
42
+
43
+ export class ApixAdaptor extends BrowserAdaptor implements IApixAdaptor {
44
+ constructor(sdk: IAPIMethods, private readonly fallbackVersionsUrl: string) {
45
+ super(sdk)
46
+ }
47
+
48
+ async fetchSpecList(versionsUrl?: string): Promise<SpecList> {
49
+ const data = await this.localStorageGetItem(RunItConfigKey)
50
+ const config = data ? JSON.parse(data) : RunItNoConfig
51
+ let url: string
52
+
53
+ if (versionsUrl) {
54
+ url = versionsUrl
55
+ } else {
56
+ url = config.base_url
57
+ ? `${config.base_url}/versions`
58
+ : `${this.fallbackVersionsUrl}/versions.json`
59
+ }
60
+
61
+ const versions = await this.sdk.authSession.transport.rawRequest('GET', url)
62
+ const specs = await getSpecsFromVersions(JSON.parse(versions.body))
63
+ return specs
64
+ }
65
+
66
+ async fetchSpec(spec: SpecItem): Promise<SpecItem> {
67
+ const _spec = cloneDeep(spec)
68
+ _spec.specURL = fullify(spec.specURL!, origin)
69
+ _spec.api = await fallbackFetch(_spec, funFetch)
70
+ return _spec
71
+ }
72
+ }
@@ -24,12 +24,8 @@
24
24
 
25
25
  */
26
26
  export { highlightHTML } from './highlight'
27
- export {
28
- buildPath,
29
- buildMethodPath,
30
- buildTypePath,
31
- diffPath,
32
- oAuthPath,
33
- } from './path'
27
+ export * from './path'
34
28
  export { getLoded } from './lodeUtils'
35
29
  export { useWindowSize } from './useWindowSize'
30
+ export * from './apixAdaptor'
31
+ export * from './adaptorUtils'
package/src/utils/path.ts CHANGED
@@ -25,7 +25,8 @@
25
25
  */
26
26
 
27
27
  import type { ApiModel, IMethod, IType } from '@looker/sdk-codegen'
28
- import { firstMethodRef, Method } from '@looker/sdk-codegen'
28
+ import { firstMethodRef } from '@looker/sdk-codegen'
29
+ import type { Location as HLocation } from 'history'
29
30
 
30
31
  /**
31
32
  * Builds a path matching the route used by MethodScene
@@ -66,6 +67,12 @@ const getMethodTag = (api: ApiModel, methodName: string) => {
66
67
  .map(([methodTag]) => methodTag)[0]
67
68
  }
68
69
 
70
+ /**
71
+ * Is this item a method? Check without requiring `instanceof Method`
72
+ * @param item to check for method or type
73
+ */
74
+ export const isMethod = (item: IMethod | IType) => 'params' in item
75
+
69
76
  /**
70
77
  * Return the tag for a give type
71
78
  * @param api Parsed api
@@ -89,7 +96,7 @@ export const buildPath = (
89
96
  specKey: string
90
97
  ) => {
91
98
  let path
92
- if (item instanceof Method) {
99
+ if (isMethod(item)) {
93
100
  const tag = getMethodTag(api, item.name)
94
101
  path = buildMethodPath(specKey, tag, item.name)
95
102
  } else {
@@ -98,3 +105,19 @@ export const buildPath = (
98
105
  }
99
106
  return path
100
107
  }
108
+
109
+ /**
110
+ * Determine API specification keys from URL pattern
111
+ * @param location service to examine
112
+ */
113
+ export const getSpecKey = (location: HLocation | Location): string | null => {
114
+ const pathname = location.pathname
115
+ let match
116
+ if (pathname.startsWith(`/${diffPath}`)) {
117
+ const pattern = new RegExp(`(?:/${diffPath})/(?<specKey>\\w+.\\w+)`)
118
+ match = pathname.match(pattern)
119
+ } else {
120
+ match = pathname.match(/\/(?<specKey>\w+\.\w+).*/)
121
+ }
122
+ return match?.groups?.specKey || null
123
+ }
@@ -1,2 +0,0 @@
1
- export * from './spec';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/reducers/index.ts"],"names":[],"mappings":"AAyBA,cAAc,QAAd","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 './spec'\n"],"file":"index.js"}
@@ -1,19 +0,0 @@
1
- export var Actions;
2
-
3
- (function (Actions) {
4
- Actions["SELECT_SPEC"] = "SELECT_SPEC";
5
- Actions["UPDATE_SPEC_API"] = "UPDATE_SPEC_API";
6
- })(Actions || (Actions = {}));
7
-
8
- export var selectSpec = specKey => ({
9
- type: Actions.SELECT_SPEC,
10
- payload: specKey
11
- });
12
- export var updateSpecApi = (specKey, api) => ({
13
- type: Actions.UPDATE_SPEC_API,
14
- payload: {
15
- specKey,
16
- api
17
- }
18
- });
19
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/reducers/spec/actions.ts"],"names":["Actions","selectSpec","specKey","type","SELECT_SPEC","payload","updateSpecApi","api","UPDATE_SPEC_API"],"mappings":"AA4BA,WAAYA,OAAZ;;WAAYA,O;AAAAA,EAAAA,O;AAAAA,EAAAA,O;GAAAA,O,KAAAA,O;;AAsBZ,OAAO,IAAMC,UAAU,GAAIC,OAAD,KAAwC;AAChEC,EAAAA,IAAI,EAAEH,OAAO,CAACI,WADkD;AAEhEC,EAAAA,OAAO,EAAEH;AAFuD,CAAxC,CAAnB;AAKP,OAAO,IAAMI,aAAa,GAAG,CAC3BJ,OAD2B,EAE3BK,GAF2B,MAGF;AACzBJ,EAAAA,IAAI,EAAEH,OAAO,CAACQ,eADW;AAEzBH,EAAAA,OAAO,EAAE;AAAEH,IAAAA,OAAF;AAAWK,IAAAA;AAAX;AAFgB,CAHE,CAAtB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 { ApiModel } from '@looker/sdk-codegen'\n\nexport enum Actions {\n SELECT_SPEC = 'SELECT_SPEC',\n UPDATE_SPEC_API = 'UPDATE_SPEC_API',\n}\n\nexport interface ApiUpdatePayload {\n specKey: string\n api: ApiModel\n}\n\nexport interface UpdateSpecApiAction {\n type: Actions.UPDATE_SPEC_API\n payload: ApiUpdatePayload\n}\n\nexport interface SelectSpecAction {\n type: Actions.SELECT_SPEC\n payload: string\n}\n\nexport type SpecAction = SelectSpecAction | UpdateSpecApiAction\n\nexport const selectSpec = (specKey: string): SelectSpecAction => ({\n type: Actions.SELECT_SPEC,\n payload: specKey,\n})\n\nexport const updateSpecApi = (\n specKey: string,\n api: ApiModel\n): UpdateSpecApiAction => ({\n type: Actions.UPDATE_SPEC_API,\n payload: { specKey, api },\n})\n"],"file":"actions.js"}
@@ -1,4 +0,0 @@
1
- export * from './utils';
2
- export * from './actions';
3
- export * from './reducer';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/reducers/spec/index.ts"],"names":[],"mappings":"AAyBA,cAAc,SAAd;AACA,cAAc,WAAd;AACA,cAAc,WAAd","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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'\nexport * from './actions'\nexport * from './reducer'\n"],"file":"index.js"}
@@ -1,62 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- import { ApiModel } from '@looker/sdk-codegen';
8
- import { Actions } from '.';
9
- export var specReducer = (state, action) => {
10
- var {
11
- type,
12
- payload
13
- } = action;
14
-
15
- switch (type) {
16
- case Actions.UPDATE_SPEC_API:
17
- {
18
- var specList = _objectSpread({}, state.specList);
19
-
20
- var {
21
- specKey,
22
- api
23
- } = payload;
24
- var spec = specList[specKey];
25
-
26
- if (spec) {
27
- spec = _objectSpread(_objectSpread({}, spec), {}, {
28
- api
29
- });
30
- specList[specKey] = spec;
31
- }
32
-
33
- return {
34
- specList,
35
- spec
36
- };
37
- }
38
-
39
- case 'SELECT_SPEC':
40
- {
41
- var newState = _objectSpread({}, state);
42
-
43
- var _spec = newState.specList[payload];
44
-
45
- if (_spec) {
46
- if (!_spec.api && _spec.specContent) {
47
- _spec.api = ApiModel.fromJson(_spec.specContent);
48
- }
49
-
50
- return _objectSpread(_objectSpread({}, state), {}, {
51
- spec: _spec
52
- });
53
- }
54
-
55
- return state;
56
- }
57
-
58
- default:
59
- return state;
60
- }
61
- };
62
- //# sourceMappingURL=reducer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/reducers/spec/reducer.ts"],"names":["ApiModel","Actions","specReducer","state","action","type","payload","UPDATE_SPEC_API","specList","specKey","api","spec","newState","specContent","fromJson"],"mappings":";;;;;;AA2BA,SAASA,QAAT,QAAyB,qBAAzB;AAGA,SAASC,OAAT,QAAwB,GAAxB;AAOA,OAAO,IAAMC,WAAW,GAAG,CACzBC,KADyB,EAEzBC,MAFyB,KAGX;AACd,MAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAoBF,MAA1B;;AACA,UAAQC,IAAR;AACE,SAAKJ,OAAO,CAACM,eAAb;AAA8B;AAC5B,YAAMC,QAAQ,qBAAQL,KAAK,CAACK,QAAd,CAAd;;AACA,YAAM;AAAEC,UAAAA,OAAF;AAAWC,UAAAA;AAAX,YAAmBJ,OAAzB;AACA,YAAIK,IAAI,GAAGH,QAAQ,CAACC,OAAD,CAAnB;;AACA,YAAIE,IAAJ,EAAU;AACRA,UAAAA,IAAI,mCAAQA,IAAR;AAAcD,YAAAA;AAAd,YAAJ;AACAF,UAAAA,QAAQ,CAACC,OAAD,CAAR,GAAoBE,IAApB;AACD;;AACD,eAAO;AAAEH,UAAAA,QAAF;AAAYG,UAAAA;AAAZ,SAAP;AACD;;AACD,SAAK,aAAL;AAAoB;AAClB,YAAMC,QAAQ,qBAAQT,KAAR,CAAd;;AACA,YAAMQ,KAAI,GAAGC,QAAQ,CAACJ,QAAT,CAAkBF,OAAlB,CAAb;;AAEA,YAAIK,KAAJ,EAAU;AACR,cAAI,CAACA,KAAI,CAACD,GAAN,IAAaC,KAAI,CAACE,WAAtB,EAAmC;AACjCF,YAAAA,KAAI,CAACD,GAAL,GAAWV,QAAQ,CAACc,QAAT,CAAkBH,KAAI,CAACE,WAAvB,CAAX;AACD;;AACD,iDAAYV,KAAZ;AAAmBQ,YAAAA,IAAI,EAAJA;AAAnB;AACD;;AACD,eAAOR,KAAP;AACD;;AACD;AACE,aAAOA,KAAP;AAxBJ;AA0BD,CA/BM","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 { SpecItem, SpecList } from '@looker/sdk-codegen'\nimport { ApiModel } from '@looker/sdk-codegen'\nimport type { ApiUpdatePayload } from './actions'\nimport type { SpecAction } from '.'\nimport { Actions } from '.'\n\nexport interface SpecState {\n specList: SpecList\n spec: SpecItem\n}\n\nexport const specReducer = (\n state: SpecState,\n action: SpecAction\n): SpecState => {\n const { type, payload } = action\n switch (type) {\n case Actions.UPDATE_SPEC_API: {\n const specList = { ...state.specList }\n const { specKey, api } = payload as ApiUpdatePayload\n let spec = specList[specKey]\n if (spec) {\n spec = { ...spec, api }\n specList[specKey] = spec\n }\n return { specList, spec }\n }\n case 'SELECT_SPEC': {\n const newState = { ...state }\n const spec = newState.specList[payload as string]\n // Does extension API Explorer needs this?\n if (spec) {\n if (!spec.api && spec.specContent) {\n spec.api = ApiModel.fromJson(spec.specContent)\n }\n return { ...state, spec }\n }\n return state\n }\n default:\n return state\n }\n}\n"],"file":"reducer.js"}
@@ -1,74 +0,0 @@
1
- import { OAuthSession } from '@looker/sdk-rtl';
2
- import { diffPath, oAuthPath } from '../../utils';
3
- export var getDefaultSpecKey = specs => {
4
- var items = Object.entries(specs);
5
-
6
- if (items.length === 0) {
7
- throw Error('No specs found.');
8
- }
9
-
10
- var specKey = '';
11
- items.forEach(_ref => {
12
- var [key, item] = _ref;
13
-
14
- if (item.isDefault) {
15
- specKey = key;
16
- }
17
- });
18
-
19
- if (!specKey) {
20
- items.forEach(_ref2 => {
21
- var [key, item] = _ref2;
22
-
23
- if (item.status === 'current') {
24
- specKey = key;
25
- }
26
- });
27
- }
28
-
29
- if (!specKey) {
30
- specKey = Object.keys(specs)[0];
31
- }
32
-
33
- if (!specKey) {
34
- throw Error('No specs found.');
35
- }
36
-
37
- return specKey;
38
- };
39
- export var getSpecKey = (location, specs) => {
40
- var pathName = location.pathname;
41
-
42
- if (pathName === "/".concat(oAuthPath)) {
43
- var returnUrl = sessionStorage.getItem(OAuthSession.returnUrlKey);
44
-
45
- if (returnUrl) {
46
- pathName = returnUrl;
47
- }
48
- }
49
-
50
- var pathNodes = pathName.split('/');
51
- var specKey = '';
52
-
53
- if (pathNodes.length > 1 && pathNodes[1] && pathNodes[1] !== oAuthPath && pathNodes[1] !== diffPath) {
54
- specKey = pathNodes[1];
55
- } else if (specs) {
56
- specKey = getDefaultSpecKey(specs);
57
- }
58
-
59
- return specKey;
60
- };
61
- export var initDefaultSpecState = (specList, location) => {
62
- var specKey = getSpecKey(location, specList);
63
- var spec = specList[specKey];
64
-
65
- if (!spec) {
66
- spec = specList['4.0'];
67
- }
68
-
69
- return {
70
- specList,
71
- spec
72
- };
73
- };
74
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/reducers/spec/utils.ts"],"names":["OAuthSession","diffPath","oAuthPath","getDefaultSpecKey","specs","items","Object","entries","length","Error","specKey","forEach","key","item","isDefault","status","keys","getSpecKey","location","pathName","pathname","returnUrl","sessionStorage","getItem","returnUrlKey","pathNodes","split","initDefaultSpecState","specList","spec"],"mappings":"AA4BA,SAASA,YAAT,QAA6B,iBAA7B;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,aAApC;AAWA,OAAO,IAAMC,iBAAiB,GAAIC,KAAD,IAA6B;AAC5D,MAAMC,KAAK,GAAGC,MAAM,CAACC,OAAP,CAAeH,KAAf,CAAd;;AAEA,MAAIC,KAAK,CAACG,MAAN,KAAiB,CAArB,EAAwB;AACtB,UAAMC,KAAK,CAAC,iBAAD,CAAX;AACD;;AAED,MAAIC,OAAO,GAAG,EAAd;AACAL,EAAAA,KAAK,CAACM,OAAN,CAAc,QAAiB;AAAA,QAAhB,CAACC,GAAD,EAAMC,IAAN,CAAgB;;AAC7B,QAAIA,IAAI,CAACC,SAAT,EAAoB;AAClBJ,MAAAA,OAAO,GAAGE,GAAV;AACD;AACF,GAJD;;AAMA,MAAI,CAACF,OAAL,EAAc;AACZL,IAAAA,KAAK,CAACM,OAAN,CAAc,SAAiB;AAAA,UAAhB,CAACC,GAAD,EAAMC,IAAN,CAAgB;;AAC7B,UAAIA,IAAI,CAACE,MAAL,KAAgB,SAApB,EAA+B;AAC7BL,QAAAA,OAAO,GAAGE,GAAV;AACD;AACF,KAJD;AAKD;;AAED,MAAI,CAACF,OAAL,EAAc;AACZA,IAAAA,OAAO,GAAGJ,MAAM,CAACU,IAAP,CAAYZ,KAAZ,EAAmB,CAAnB,CAAV;AACD;;AAED,MAAI,CAACM,OAAL,EAAc;AACZ,UAAMD,KAAK,CAAC,iBAAD,CAAX;AACD;;AAED,SAAOC,OAAP;AACD,CA/BM;AAsCP,OAAO,IAAMO,UAAU,GAAG,CAACC,QAAD,EAA6Bd,KAA7B,KAAkD;AAC1E,MAAIe,QAAQ,GAAGD,QAAQ,CAACE,QAAxB;;AACA,MAAID,QAAQ,gBAASjB,SAAT,CAAZ,EAAkC;AAChC,QAAMmB,SAAS,GAAGC,cAAc,CAACC,OAAf,CAAuBvB,YAAY,CAACwB,YAApC,CAAlB;;AACA,QAAIH,SAAJ,EAAe;AACbF,MAAAA,QAAQ,GAAGE,SAAX;AACD;AACF;;AACD,MAAMI,SAAS,GAAGN,QAAQ,CAACO,KAAT,CAAe,GAAf,CAAlB;AACA,MAAIhB,OAAO,GAAG,EAAd;;AACA,MACEe,SAAS,CAACjB,MAAV,GAAmB,CAAnB,IACAiB,SAAS,CAAC,CAAD,CADT,IAEAA,SAAS,CAAC,CAAD,CAAT,KAAiBvB,SAFjB,IAGAuB,SAAS,CAAC,CAAD,CAAT,KAAiBxB,QAJnB,EAKE;AACAS,IAAAA,OAAO,GAAGe,SAAS,CAAC,CAAD,CAAnB;AACD,GAPD,MAOO,IAAIrB,KAAJ,EAAW;AAChBM,IAAAA,OAAO,GAAGP,iBAAiB,CAACC,KAAD,CAA3B;AACD;;AACD,SAAOM,OAAP;AACD,CArBM;AA8BP,OAAO,IAAMiB,oBAAoB,GAAG,CAClCC,QADkC,EAElCV,QAFkC,KAGpB;AACd,MAAMR,OAAO,GAAGO,UAAU,CAACC,QAAD,EAAWU,QAAX,CAA1B;AAEA,MAAIC,IAAI,GAAGD,QAAQ,CAAClB,OAAD,CAAnB;;AACA,MAAI,CAACmB,IAAL,EAAW;AACTA,IAAAA,IAAI,GAAGD,QAAQ,CAAC,KAAD,CAAf;AACD;;AACD,SAAO;AACLA,IAAAA,QADK;AAELC,IAAAA;AAFK,GAAP;AAID,CAdM","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 { SpecList } from '@looker/sdk-codegen'\nimport type { Location as HLocation } from 'history'\nimport { OAuthSession } from '@looker/sdk-rtl'\nimport { diffPath, oAuthPath } from '../../utils'\nimport type { SpecState } from './reducer'\n\nexport type AbstractLocation = HLocation | Location\n\n/**\n * Given a collection of specs, it returns the spec marked as default, the one\n * marked as current or the first one, in that order.\n * @param specs A collection of specs\n * @returns A spec\n */\nexport const getDefaultSpecKey = (specs: SpecList): string => {\n const items = Object.entries(specs)\n\n if (items.length === 0) {\n throw Error('No specs found.')\n }\n\n let specKey = ''\n items.forEach(([key, item]) => {\n if (item.isDefault) {\n specKey = key\n }\n })\n\n if (!specKey) {\n items.forEach(([key, item]) => {\n if (item.status === 'current') {\n specKey = key\n }\n })\n }\n\n if (!specKey) {\n specKey = Object.keys(specs)[0]\n }\n\n if (!specKey) {\n throw Error('No specs found.')\n }\n\n return specKey\n}\n\n/**\n * Determine the API specification key from URL pattern or default spec\n * @param location service to examine\n * @param specs to use to find the default spec key\n */\nexport const getSpecKey = (location: AbstractLocation, specs?: SpecList) => {\n let pathName = location.pathname\n if (pathName === `/${oAuthPath}`) {\n const returnUrl = sessionStorage.getItem(OAuthSession.returnUrlKey)\n if (returnUrl) {\n pathName = returnUrl\n }\n }\n const pathNodes = pathName.split('/')\n let specKey = ''\n if (\n pathNodes.length > 1 &&\n pathNodes[1] &&\n pathNodes[1] !== oAuthPath &&\n pathNodes[1] !== diffPath\n ) {\n specKey = pathNodes[1]\n } else if (specs) {\n specKey = getDefaultSpecKey(specs)\n }\n return specKey\n}\n\n/**\n * Creates a default state object with the spec matching the specKey defined\n * in the url or the default criteria in getDefaultSpecKey\n * @param specList A collection of specs\n * @param location Standalone or extension location\n * @returns An object to be used as default state\n */\nexport const initDefaultSpecState = (\n specList: SpecList,\n location: AbstractLocation\n): SpecState => {\n const specKey = getSpecKey(location, specList)\n // Handle bad spec in the URL. Fall back to 4.0\n let spec = specList[specKey]\n if (!spec) {\n spec = specList['4.0']\n }\n return {\n specList,\n spec,\n }\n}\n"],"file":"utils.js"}
@@ -1 +0,0 @@
1
- export * from './spec';
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _spec = require("./spec");
8
-
9
- Object.keys(_spec).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _spec[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function get() {
15
- return _spec[key];
16
- }
17
- });
18
- });
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/reducers/index.ts"],"names":[],"mappings":";;;;;;AAyBA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 './spec'\n"],"file":"index.js"}
@@ -1,20 +0,0 @@
1
- import type { ApiModel } from '@looker/sdk-codegen';
2
- export declare enum Actions {
3
- SELECT_SPEC = "SELECT_SPEC",
4
- UPDATE_SPEC_API = "UPDATE_SPEC_API"
5
- }
6
- export interface ApiUpdatePayload {
7
- specKey: string;
8
- api: ApiModel;
9
- }
10
- export interface UpdateSpecApiAction {
11
- type: Actions.UPDATE_SPEC_API;
12
- payload: ApiUpdatePayload;
13
- }
14
- export interface SelectSpecAction {
15
- type: Actions.SELECT_SPEC;
16
- payload: string;
17
- }
18
- export declare type SpecAction = SelectSpecAction | UpdateSpecApiAction;
19
- export declare const selectSpec: (specKey: string) => SelectSpecAction;
20
- export declare const updateSpecApi: (specKey: string, api: ApiModel) => UpdateSpecApiAction;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.updateSpecApi = exports.selectSpec = exports.Actions = void 0;
7
- var Actions;
8
- exports.Actions = Actions;
9
-
10
- (function (Actions) {
11
- Actions["SELECT_SPEC"] = "SELECT_SPEC";
12
- Actions["UPDATE_SPEC_API"] = "UPDATE_SPEC_API";
13
- })(Actions || (exports.Actions = Actions = {}));
14
-
15
- var selectSpec = specKey => ({
16
- type: Actions.SELECT_SPEC,
17
- payload: specKey
18
- });
19
-
20
- exports.selectSpec = selectSpec;
21
-
22
- var updateSpecApi = (specKey, api) => ({
23
- type: Actions.UPDATE_SPEC_API,
24
- payload: {
25
- specKey,
26
- api
27
- }
28
- });
29
-
30
- exports.updateSpecApi = updateSpecApi;
31
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/reducers/spec/actions.ts"],"names":["Actions","selectSpec","specKey","type","SELECT_SPEC","payload","updateSpecApi","api","UPDATE_SPEC_API"],"mappings":";;;;;;IA4BYA,O;;;WAAAA,O;AAAAA,EAAAA,O;AAAAA,EAAAA,O;GAAAA,O,uBAAAA,O;;AAsBL,IAAMC,UAAU,GAAIC,OAAD,KAAwC;AAChEC,EAAAA,IAAI,EAAEH,OAAO,CAACI,WADkD;AAEhEC,EAAAA,OAAO,EAAEH;AAFuD,CAAxC,CAAnB;;;;AAKA,IAAMI,aAAa,GAAG,CAC3BJ,OAD2B,EAE3BK,GAF2B,MAGF;AACzBJ,EAAAA,IAAI,EAAEH,OAAO,CAACQ,eADW;AAEzBH,EAAAA,OAAO,EAAE;AAAEH,IAAAA,OAAF;AAAWK,IAAAA;AAAX;AAFgB,CAHE,CAAtB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 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 { ApiModel } from '@looker/sdk-codegen'\n\nexport enum Actions {\n SELECT_SPEC = 'SELECT_SPEC',\n UPDATE_SPEC_API = 'UPDATE_SPEC_API',\n}\n\nexport interface ApiUpdatePayload {\n specKey: string\n api: ApiModel\n}\n\nexport interface UpdateSpecApiAction {\n type: Actions.UPDATE_SPEC_API\n payload: ApiUpdatePayload\n}\n\nexport interface SelectSpecAction {\n type: Actions.SELECT_SPEC\n payload: string\n}\n\nexport type SpecAction = SelectSpecAction | UpdateSpecApiAction\n\nexport const selectSpec = (specKey: string): SelectSpecAction => ({\n type: Actions.SELECT_SPEC,\n payload: specKey,\n})\n\nexport const updateSpecApi = (\n specKey: string,\n api: ApiModel\n): UpdateSpecApiAction => ({\n type: Actions.UPDATE_SPEC_API,\n payload: { specKey, api },\n})\n"],"file":"actions.js"}
@@ -1,3 +0,0 @@
1
- export * from './utils';
2
- export * from './actions';
3
- export * from './reducer';