@builder.io/sdk-svelte 1.0.26 → 1.0.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.
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.26";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.26";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.26";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.26";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.26";
1
+ export declare const SDK_VERSION = "1.0.27";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.26";
1
+ export const SDK_VERSION = "1.0.27";
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -59,7 +59,7 @@ export const generateContentUrl = (options) => {
59
59
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
60
60
  }
61
61
  if (query) {
62
- const flattened = flatten({
62
+ const flattened = flattenMongoQuery({
63
63
  query
64
64
  });
65
65
  for (const key in flattened) {
@@ -4,3 +4,13 @@
4
4
  * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
5
  */
6
6
  export declare function flatten<T extends Record<string, any>>(object: T, path?: string | null, separator?: string): T;
7
+ /**
8
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
9
+ * $ keys are not flattened and are left as is.
10
+ *
11
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
12
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
13
+ */
14
+ export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
15
+ [key: string]: string;
16
+ };
@@ -17,3 +17,23 @@ export function flatten(object, path = null, separator = '.') {
17
17
  };
18
18
  }, {});
19
19
  }
20
+ /**
21
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
22
+ * $ keys are not flattened and are left as is.
23
+ *
24
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
25
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
26
+ */
27
+ export function flattenMongoQuery(obj, _current, _res = {}) {
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ const newKey = _current ? _current + '.' + key : key;
31
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
32
+ flattenMongoQuery(value, newKey, _res);
33
+ }
34
+ else {
35
+ _res[newKey] = value;
36
+ }
37
+ }
38
+ return _res;
39
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "1.0.26",
4
+ "version": "1.0.27",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.26"
1
+ export const SDK_VERSION = "1.0.27"
@@ -1,4 +1,4 @@
1
- import { flatten } from '../../helpers/flatten';
1
+ import { flatten, flattenMongoQuery } from '../../helpers/flatten';
2
2
  import { normalizeSearchParams } from '../../helpers/search/search';
3
3
  import { DEFAULT_API_VERSION } from '../../types/api-version';
4
4
  import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
@@ -77,11 +77,11 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
77
77
  url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
78
78
  }
79
79
  if (query) {
80
- const flattened = flatten({
80
+ const flattened = flattenMongoQuery({
81
81
  query
82
82
  });
83
83
  for (const key in flattened) {
84
- url.searchParams.set(key, JSON.stringify((flattened as any)[key]));
84
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
85
85
  }
86
86
  }
87
87
  return url;
@@ -16,4 +16,26 @@ export function flatten<T extends Record<string, any>>(object: T, path: string |
16
16
  [newPath]: value
17
17
  };
18
18
  }, ({} as T));
19
+ }
20
+
21
+ /**
22
+ * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
23
+ * $ keys are not flattened and are left as is.
24
+ *
25
+ * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
26
+ * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
27
+ */
28
+ export function flattenMongoQuery(obj: any, _current?: any, _res: any = {}): {
29
+ [key: string]: string;
30
+ } {
31
+ for (const key in obj) {
32
+ const value = obj[key];
33
+ const newKey = _current ? _current + '.' + key : key;
34
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
35
+ flattenMongoQuery(value, newKey, _res);
36
+ } else {
37
+ _res[newKey] = value;
38
+ }
39
+ }
40
+ return _res;
19
41
  }