@sitecore-feaas/clientside 0.5.5 → 0.5.6

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 (52) hide show
  1. package/build/dom/rendering.js +20 -11
  2. package/build/dom/rendering.js.map +1 -1
  3. package/build/fetch.js +21 -21
  4. package/build/fetch.js.map +1 -1
  5. package/build/utils/data.js +11 -8
  6. package/build/utils/data.js.map +1 -1
  7. package/dist/browser/headless.cjs +3 -3
  8. package/dist/browser/headless.cjs.map +3 -3
  9. package/dist/browser/headless.esm.js +5 -5
  10. package/dist/browser/headless.esm.js.map +1 -1
  11. package/dist/browser/index.cjs +5 -5
  12. package/dist/browser/index.cjs.map +3 -3
  13. package/dist/browser/index.esm.js +5 -5
  14. package/dist/browser/index.esm.js.map +1 -1
  15. package/dist/browser/react.cjs +5 -5
  16. package/dist/browser/react.cjs.map +3 -3
  17. package/dist/browser/react.esm.js +5 -5
  18. package/dist/browser/react.esm.js.map +1 -1
  19. package/dist/node/headless.cjs +5 -5
  20. package/dist/node/headless.cjs.map +3 -3
  21. package/dist/node/headless.esm.js +5 -5
  22. package/dist/node/headless.esm.js.map +3 -3
  23. package/dist/node/index.cjs +4 -4
  24. package/dist/node/index.cjs.map +3 -3
  25. package/dist/node/index.esm.js +4 -4
  26. package/dist/node/index.esm.js.map +3 -3
  27. package/dist/node/react.cjs +4 -4
  28. package/dist/node/react.cjs.map +3 -3
  29. package/dist/node/react.esm.js +4 -4
  30. package/dist/node/react.esm.js.map +3 -3
  31. package/headless.cjs +5 -5
  32. package/headless.cjs.map +3 -3
  33. package/headless.js +5 -5
  34. package/headless.js.map +3 -3
  35. package/package.json +1 -1
  36. package/react.cjs +5 -5
  37. package/react.cjs.map +3 -3
  38. package/react.js +5 -5
  39. package/react.js.map +3 -3
  40. package/src/dom/rendering.ts +31 -16
  41. package/src/dom/thumbnail.ts +1 -1
  42. package/src/fetch.ts +29 -29
  43. package/src/utils/data.ts +11 -7
  44. package/test/FEAASComponent.react.test.tsx +19 -3
  45. package/types/dom/rendering.d.ts.map +1 -1
  46. package/types/dom/thumbnail.d.ts +1 -1
  47. package/types/dom/thumbnail.d.ts.map +1 -1
  48. package/types/fetch.d.ts +15 -15
  49. package/types/fetch.d.ts.map +1 -1
  50. package/types/utils/data.d.ts +2 -2
  51. package/types/utils/data.d.ts.map +1 -1
  52. package/types/utils/settings.d.ts +5 -5
@@ -96,23 +96,33 @@ export function setDOMAttribute(element: HTMLElement, attribute: string, value:
96
96
  } else if (attribute == 'data-embed-src') {
97
97
  loadScript(element, value)
98
98
  } else if (attribute == 'data-path-attributes') {
99
- const oldKeys = element.getAttribute('data-attributes-keys')?.split(',').filter(Boolean) || []
100
- if (!Array.isArray(value))
101
- for (var property in value) {
102
- var subvalue = value[property]
103
- setDOMAttribute(
104
- element,
105
- property,
106
- typeof subvalue == 'object' && subvalue ? JSON.stringify(subvalue) : subvalue,
107
- config
108
- )
109
- }
110
- for (var i = 0; i < oldKeys.length; i++) {
111
- if (value == null || !(oldKeys[i] in value)) {
112
- setDOMAttribute(element, oldKeys[i], null, config)
99
+ if (!Array.isArray(value)) {
100
+ const oldKeys = element.getAttribute('data-attributes-keys')?.split(',').filter(Boolean) || []
101
+ if (!Array.isArray(value))
102
+ for (var property in value) {
103
+ var subvalue = value[property]
104
+ setDOMAttribute(
105
+ element,
106
+ property,
107
+ typeof subvalue == 'object' && subvalue ? JSON.stringify(subvalue) : subvalue,
108
+ config
109
+ )
110
+ }
111
+ for (var i = 0; i < oldKeys.length; i++) {
112
+ if (value == null || !(oldKeys[i] in value)) {
113
+ setDOMAttribute(element, oldKeys[i], null, config)
114
+ }
113
115
  }
116
+ setDOMAttribute(element, 'data-attributes-keys', Object.keys(value || {}).join(','))
117
+ }
118
+ // BYOC components also accept their data object in datasources attribute.
119
+ if (element.tagName == 'FEAAS-EXTERNAL') {
120
+ const datasourceId =
121
+ String(element.getAttribute('data-path-attributes') || '')
122
+ .slice(0, -1)
123
+ .split('.')[0] || '_'
124
+ setDOMAttribute(element, 'datasources', JSON.stringify({ [datasourceId]: value }))
114
125
  }
115
- setDOMAttribute(element, 'data-attributes-keys', Object.keys(value || {}).join(','))
116
126
  return
117
127
  }
118
128
  if (typeof value == 'boolean') {
@@ -198,7 +208,12 @@ export function renderDOMElement(
198
208
  for (var i = 0; i < attrs.length; i++) {
199
209
  const { name, value: datapath } = attrs[i]
200
210
  if (name.startsWith('data-path') && name != 'data-path-scope') {
201
- setDOMAttribute(element, name, queryScopes(datascopes, datapath, true), config)
211
+ setDOMAttribute(
212
+ element,
213
+ name,
214
+ queryScopes(datascopes, datapath, true, undefined, element.tagName != 'FEAAS-EXTERNAL'),
215
+ config
216
+ )
202
217
  }
203
218
  if (name == 'data-embed-src') {
204
219
  setDOMAttribute(element, name, element.getAttribute(name), config)
@@ -2,7 +2,7 @@ import type { SDK, Style, VersionModel, ComponentModel, StylesheetModel } from '
2
2
  import { fetchAndRevalidate } from '../fetch.js'
3
3
  import { renderComponent } from './component.js'
4
4
 
5
- export type Callback = (image: HTMLImageElement, isCached: boolean) => void
5
+ export type Callback = (image: HTMLImageElement | null, isCached: boolean) => void
6
6
 
7
7
  export const convertBase64toBlob = (base64: string) => fetch(base64).then((res) => res.blob())
8
8
 
package/src/fetch.ts CHANGED
@@ -1,17 +1,5 @@
1
1
  import { ControlledPromise } from './utils/promise.js'
2
2
 
3
- /**
4
- * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
5
- * settings to be set.
6
- *
7
- * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
8
- * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
9
- * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
10
- * actually fetches the new content and callback is invoked the second time.
11
- *
12
- * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
13
- * errors will not be caught. Function throws when unable to fetch valid response.
14
- */
15
3
  const phases = ['initial', 'check', 'updated'] as const
16
4
  export type ValidatableRequestPhase = (typeof phases)[number]
17
5
  export type FetchCache = Record<string, FetchCacheRequest>
@@ -38,6 +26,18 @@ export function clearFetchCache() {
38
26
  fetchCache = {}
39
27
  }
40
28
 
29
+ /**
30
+ * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
31
+ * settings to be set.
32
+ *
33
+ * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
34
+ * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
35
+ * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
36
+ * actually fetches the new content and callback is invoked the second time.
37
+ *
38
+ * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
39
+ * errors will not be caught. Function throws when unable to fetch valid response.
40
+ */
41
41
  export async function fetchAndRevalidate(
42
42
  url: ValidatableRequest['url'],
43
43
  options?: ValidatableRequest['options'],
@@ -51,23 +51,6 @@ export async function fetchAndRevalidate(
51
51
  .then((result) => result.response)
52
52
  }
53
53
 
54
- export function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate = false) {
55
- const key = String(url).replace('?head', '')
56
- var cache = fetchCache[key]
57
- if (!cache && !dontCreate) {
58
- cache = fetchCache[key] = {
59
- phase: null,
60
- initial: ControlledPromise(),
61
- check: ControlledPromise(),
62
- updated: ControlledPromise(),
63
- final: ControlledPromise()
64
- }
65
- }
66
- return cache
67
- }
68
-
69
- export class InvalidResponse extends Error {}
70
-
71
54
  /**
72
55
  * Executes a fetch request optionally validating and handling the response. Using callback function it's possible to
73
56
  * observe successful response twice: Cached version first, and up-to-date later.
@@ -123,6 +106,23 @@ export async function fetchWithCacheAwareness(
123
106
  }
124
107
  }
125
108
 
109
+ export function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate = false) {
110
+ const key = String(url).replace('?head', '')
111
+ var cache = fetchCache[key]
112
+ if (!cache && !dontCreate) {
113
+ cache = fetchCache[key] = {
114
+ phase: null,
115
+ initial: ControlledPromise(),
116
+ check: ControlledPromise(),
117
+ updated: ControlledPromise(),
118
+ final: ControlledPromise()
119
+ }
120
+ }
121
+ return cache
122
+ }
123
+
124
+ export class InvalidResponse extends Error {}
125
+
126
126
  /**
127
127
  * Validates cache of previousl fetch If the resource is cached and there is a newer version available, it will be
128
128
  * re-fetched.
package/src/utils/data.ts CHANGED
@@ -7,11 +7,15 @@ export function queryObjectRaw(json: any, path: string) {
7
7
  return []
8
8
  }
9
9
  }
10
- export function queryObject(json: any, path: string) {
11
- return queryObjectRaw(json, path)?.flat(Infinity) || []
10
+ export function queryObject(json: any, path: string, flatten = true) {
11
+ const data = queryObjectRaw(json, path) || []
12
+ if (flatten) {
13
+ return data.flat(Infinity)
14
+ }
15
+ return data
12
16
  }
13
17
 
14
- export function queryScopes(scopes: any, datapath: string, singleValue = false, json: any = scopes) {
18
+ export function queryScopes(scopes: any, datapath: string, singleValue = false, json: any = scopes, flatten = true) {
15
19
  var path = datapath
16
20
  /* find closest parent scope */
17
21
  const keys = Object.keys(scopes).sort((b, a) => a.length - b.length)
@@ -30,11 +34,11 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
30
34
  }
31
35
  }
32
36
 
33
- var collection = queryObject(json, path)
37
+ var collection = queryObject(json, path, flatten)
34
38
 
35
39
  // If regular path didn't match any data, try fallbacks
36
40
  // datasourceId.wrapper.$.path
37
- if (Array.isArray(collection) && collection?.length == 0) {
41
+ if (collection.length == 0) {
38
42
  collection = [
39
43
  // look up in `_` datasource id (catch-all id is used in JSS)
40
44
  // _.wrapper.$.path
@@ -56,11 +60,11 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
56
60
  ]
57
61
  .filter((v, i, a) => a.indexOf(v) === i)
58
62
  .reduce((v, path) => {
59
- return v.length > 0 ? v : queryObject(json, path)
63
+ return v.length > 0 ? v : queryObject(json, path, flatten)
60
64
  }, [] as any[])
61
65
  }
62
66
 
63
- if (singleValue && Array.isArray(collection)) {
67
+ if (singleValue) {
64
68
  return collection[0]
65
69
  } else {
66
70
  return collection
@@ -9,8 +9,8 @@ function Hello(props: { firstName: string; telephone: string }) {
9
9
  return React.createElement(
10
10
  'div',
11
11
  {},
12
- `Hello my name is ${props.firstName} (${typeof props.firstName}) and my tel is ${
13
- props.telephone
12
+ `Hello my name is ${props.firstName || 'Unknown'} (${typeof props.firstName}) and my tel is ${
13
+ props.telephone || 'Unknown'
14
14
  } (${typeof props.telephone}). And context value is ${context}`
15
15
  )
16
16
  }
@@ -169,7 +169,23 @@ describe('React', () => {
169
169
  ></Component>
170
170
  </section>
171
171
  </DataContext.Provider>,
172
- '<section><feaas-component class="-feaas" data="{&quot;telephone&quot;:321}"><feaas-external data-external-id="MyTestComponent" data-path-attributes="$" first-name="Yarik" telephone="321" data-attributes-keys="telephone" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 321 (number). And context value is INHERITED</div></feaas-external></feaas-component></section>'
172
+ '<section><feaas-component class="-feaas" data="{&quot;telephone&quot;:321}"><feaas-external data-external-id="MyTestComponent" data-path-attributes="$" first-name="Yarik" telephone="321" data-attributes-keys="telephone" datasources="{&quot;_&quot;:{&quot;telephone&quot;:321}}" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 321 (number). And context value is INHERITED</div></feaas-external></feaas-component></section>'
173
+ )
174
+ })
175
+ it('render not map attributes of external component with given array', async () => {
176
+ registerComponent(Hello, helloSchema)
177
+ validate(
178
+ <DataContext.Provider value='INHERITED'>
179
+ <section>
180
+ <Component
181
+ template={
182
+ '<feaas-external first-name="Yarik" data-path-attributes="$" data-external-id="MyTestComponent"></feaas-external>'
183
+ }
184
+ data={[{ telephone: 321 }]}
185
+ ></Component>
186
+ </section>
187
+ </DataContext.Provider>,
188
+ '<section><feaas-component class="-feaas" data="[{&quot;telephone&quot;:321}]"><feaas-external data-external-id="MyTestComponent" first-name="Yarik" data-path-attributes="$" datasources="{&quot;_&quot;:[{&quot;telephone&quot;:321}]}" hydrate="false"><div>Hello my name is Yarik (string) and my tel is Unknown (undefined). And context value is INHERITED</div></feaas-external></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W,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG;IAC7E,IAAI,CAAC,EAAE,CAAC,CAAA;CACT,GAAG,CAAC,gBAAgB,GAAG,sBAAsB,CAAC,GAC7C,mBAAmB,CAAA;AAsDrB,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,mBAAmB,QAkGhH;AAID,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,GAAG,gBAAgB,EACrC,UAAU,CAAC,EAAE,GAAG,EAChB,MAAM,CAAC,EAAE,mBAAmB,EAC5B,QAAQ,CAAC,EAAE,OAAO,eA+CnB;AAMD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,mBAAmB,eAc9G;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,mBAAmB,EAAE,OAAO,UAAQ,UAW7G"}
@@ -1,5 +1,5 @@
1
1
  import type { VersionModel, ComponentModel, StylesheetModel } from '@sitecore-feaas/sdk';
2
- export type Callback = (image: HTMLImageElement, isCached: boolean) => void;
2
+ export type Callback = (image: HTMLImageElement | null, isCached: boolean) => void;
3
3
  export declare const convertBase64toBlob: (base64: string) => Promise<Blob>;
4
4
  /** Parse fetch response as blob and turn it into HTMLImageElement off thread */
5
5
  export declare const responseToImage: (response: Response) => Promise<HTMLImageElement>;
@@ -1 +1 @@
1
- {"version":3,"file":"thumbnail.d.ts","sourceRoot":"","sources":["../../src/dom/thumbnail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY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,gBAAgB,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;AAElF,eAAO,MAAM,mBAAmB,WAAY,MAAM,kBAA4C,CAAA;AAE9F,gFAAgF;AAChF,eAAO,MAAM,eAAe,aAAc,QAAQ,KAAG,QAAQ,gBAAgB,CAUzE,CAAA;AAEJ;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,6BAqB/F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAE,eAAe,6BAsBnH;AAuFD;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1G"}
package/types/fetch.d.ts CHANGED
@@ -1,16 +1,4 @@
1
1
  import { ControlledPromise } from './utils/promise.js';
2
- /**
3
- * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
4
- * settings to be set.
5
- *
6
- * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
7
- * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
8
- * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
9
- * actually fetches the new content and callback is invoked the second time.
10
- *
11
- * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
12
- * errors will not be caught. Function throws when unable to fetch valid response.
13
- */
14
2
  declare const phases: readonly ["initial", "check", "updated"];
15
3
  export type ValidatableRequestPhase = (typeof phases)[number];
16
4
  export type FetchCache = Record<string, FetchCacheRequest>;
@@ -32,10 +20,19 @@ export type FetchCacheRequest = {
32
20
  };
33
21
  export declare var fetchCache: Record<string, FetchCacheRequest>;
34
22
  export declare function clearFetchCache(): void;
23
+ /**
24
+ * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
25
+ * settings to be set.
26
+ *
27
+ * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
28
+ * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
29
+ * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
30
+ * actually fetches the new content and callback is invoked the second time.
31
+ *
32
+ * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
33
+ * errors will not be caught. Function throws when unable to fetch valid response.
34
+ */
35
35
  export declare function fetchAndRevalidate(url: ValidatableRequest['url'], options?: ValidatableRequest['options'], validator?: ValidatableRequest['validator'], callback?: ValidatableRequest['callback'], cache?: FetchCache): Promise<Response>;
36
- export declare function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate?: boolean): FetchCacheRequest;
37
- export declare class InvalidResponse extends Error {
38
- }
39
36
  /**
40
37
  * Executes a fetch request optionally validating and handling the response. Using callback function it's possible to
41
38
  * observe successful response twice: Cached version first, and up-to-date later.
@@ -61,6 +58,9 @@ export declare function fetchWithCacheAwareness({ url, options, validator, callb
61
58
  callback: (response: Response, status: "initial" | "check" | "updated", isCached: boolean) => any;
62
59
  cache: FetchCache;
63
60
  }>;
61
+ export declare function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate?: boolean): FetchCacheRequest;
62
+ export declare class InvalidResponse extends Error {
63
+ }
64
64
  /**
65
65
  * Validates cache of previousl fetch If the resource is cached and there is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AAE,EAAE,kBAAkB,EAChE,KAAK,GAAE,uBAAmC;;;;;;;;GAmC3C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,UAAQ,qBAajF;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,kBAAkB,GAAG,QAAQ,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,gFA0B7E;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB;;;;;;;;GAWpE"}
@@ -1,7 +1,7 @@
1
1
  import { JSONPath } from 'jsonpath-plus';
2
2
  export declare function queryObjectRaw(json: any, path: string): any[];
3
- export declare function queryObject(json: any, path: string): any[];
4
- export declare function queryScopes(scopes: any, datapath: string, singleValue?: boolean, json?: any): any;
3
+ export declare function queryObject(json: any, path: string, flatten?: boolean): any[];
4
+ export declare function queryScopes(scopes: any, datapath: string, singleValue?: boolean, json?: any, flatten?: boolean): any;
5
5
  export type CH1Node = {
6
6
  type: string;
7
7
  text?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,SAMrD;AACD,wBAAgB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,SAElD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,UAAQ,EAAE,IAAI,GAAE,GAAY,OAsDjG;AAED,MAAM,MAAM,OAAO,GACf;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B,GACD,OAAO,EAAE,CAAA;AAQb,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAqCtF;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,SAMrD;AACD,wBAAgB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO,SAMlE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,UAAQ,EAAE,IAAI,GAAE,GAAY,EAAE,OAAO,UAAO,OAsDjH;AAED,MAAM,MAAM,OAAO,GACf;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B,GACD,OAAO,EAAE,CAAA;AAQb,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAqCtF;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
@@ -15,7 +15,7 @@ export declare function clean(settings: any): Partial<{
15
15
  params: Record<string, any>;
16
16
  headers: Record<string, string>;
17
17
  jsonpath: string;
18
- method: "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE" | "HEAD";
18
+ method: "HEAD" | "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE";
19
19
  body: Record<string, any>;
20
20
  url: string;
21
21
  }>;
@@ -29,7 +29,7 @@ export declare const isDataSettings: (data: any) => data is {
29
29
  params: Record<string, any>;
30
30
  headers: Record<string, string>;
31
31
  jsonpath: string;
32
- method: "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE" | "HEAD";
32
+ method: "HEAD" | "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE";
33
33
  body: Record<string, any>;
34
34
  url: string;
35
35
  };
@@ -51,7 +51,7 @@ export declare function DataSettings(settings: any): {
51
51
  params: Record<string, any>;
52
52
  headers: Record<string, string>;
53
53
  jsonpath: string;
54
- method: "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE" | "HEAD";
54
+ method: "HEAD" | "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE";
55
55
  body: Record<string, any>;
56
56
  url: string;
57
57
  };
@@ -62,7 +62,7 @@ export declare namespace DataSettings {
62
62
  params: Record<string, any>;
63
63
  headers: Record<string, string>;
64
64
  jsonpath: string;
65
- method: "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE" | "HEAD";
65
+ method: "HEAD" | "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE";
66
66
  body: Record<string, any>;
67
67
  url: string;
68
68
  }) => Promise<Data>;
@@ -71,7 +71,7 @@ export declare namespace DataSettings {
71
71
  params: Record<string, any>;
72
72
  headers: Record<string, string>;
73
73
  jsonpath: string;
74
- method: "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE" | "HEAD";
74
+ method: "HEAD" | "GET" | "POST" | "OPTIONS" | "PUT" | "DELETE" | "UPDATE";
75
75
  body: Record<string, any>;
76
76
  url: string;
77
77
  };