@dcupl/common 0.0.81-beta.7 → 1.0.0-beta.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.
Files changed (63) hide show
  1. package/dist/lib-cjs/computeSuggestionsNew.d.ts +2 -0
  2. package/dist/lib-cjs/computeSuggestionsNew.js +75 -0
  3. package/dist/lib-cjs/computeSuggestionsNew.js.map +1 -0
  4. package/dist/lib-cjs/getFacets.d.ts +2 -2
  5. package/dist/lib-cjs/getFacets.js.map +1 -1
  6. package/dist/lib-cjs/index.d.ts +1 -1
  7. package/dist/lib-cjs/index.js +1 -1
  8. package/dist/lib-cjs/index.js.map +1 -1
  9. package/dist/lib-cjs/query-builder.d.ts +9 -9
  10. package/dist/lib-cjs/query-builder.js.map +1 -1
  11. package/dist/lib-cjs/queryData.d.ts +3 -1
  12. package/dist/lib-cjs/queryData.js +7 -5
  13. package/dist/lib-cjs/queryData.js.map +1 -1
  14. package/dist/lib-cjs/tsconfig-cjs.tsbuildinfo +1 -1
  15. package/dist/lib-cjs/types/aggregation.types.d.ts +6 -38
  16. package/dist/lib-cjs/types/aggregation.types.js +3 -0
  17. package/dist/lib-cjs/types/aggregation.types.js.map +1 -1
  18. package/dist/lib-cjs/types/data.types.d.ts +5 -0
  19. package/dist/lib-cjs/types/group-by.types.d.ts +13 -0
  20. package/dist/lib-cjs/types/group-by.types.js +3 -0
  21. package/dist/lib-cjs/types/group-by.types.js.map +1 -0
  22. package/dist/lib-cjs/types/index.d.ts +1 -0
  23. package/dist/lib-cjs/types/index.js +1 -0
  24. package/dist/lib-cjs/types/index.js.map +1 -1
  25. package/dist/lib-cjs/types/list.types.d.ts +2 -10
  26. package/dist/lib-cjs/types/model.types.d.ts +2 -2
  27. package/dist/lib-cjs/types/query.types.d.ts +7 -2
  28. package/dist/lib-cjs/types/suggestion.types.d.ts +2 -17
  29. package/dist/lib-esm/computeSuggestionsNew.d.ts +2 -0
  30. package/dist/lib-esm/computeSuggestionsNew.js +71 -0
  31. package/dist/lib-esm/computeSuggestionsNew.js.map +1 -0
  32. package/dist/lib-esm/getFacets.d.ts +2 -2
  33. package/dist/lib-esm/getFacets.js.map +1 -1
  34. package/dist/lib-esm/index.d.ts +1 -1
  35. package/dist/lib-esm/index.js +1 -1
  36. package/dist/lib-esm/index.js.map +1 -1
  37. package/dist/lib-esm/query-builder.d.ts +9 -9
  38. package/dist/lib-esm/query-builder.js.map +1 -1
  39. package/dist/lib-esm/queryData.d.ts +3 -1
  40. package/dist/lib-esm/queryData.js +2 -2
  41. package/dist/lib-esm/queryData.js.map +1 -1
  42. package/dist/lib-esm/tsconfig.tsbuildinfo +1 -1
  43. package/dist/lib-esm/types/aggregation.types.d.ts +6 -38
  44. package/dist/lib-esm/types/aggregation.types.js +3 -0
  45. package/dist/lib-esm/types/aggregation.types.js.map +1 -1
  46. package/dist/lib-esm/types/data.types.d.ts +5 -0
  47. package/dist/lib-esm/types/group-by.types.d.ts +13 -0
  48. package/dist/lib-esm/types/group-by.types.js +2 -0
  49. package/dist/lib-esm/types/group-by.types.js.map +1 -0
  50. package/dist/lib-esm/types/index.d.ts +1 -0
  51. package/dist/lib-esm/types/index.js +1 -0
  52. package/dist/lib-esm/types/index.js.map +1 -1
  53. package/dist/lib-esm/types/list.types.d.ts +2 -10
  54. package/dist/lib-esm/types/model.types.d.ts +2 -2
  55. package/dist/lib-esm/types/query.types.d.ts +7 -2
  56. package/dist/lib-esm/types/suggestion.types.d.ts +2 -17
  57. package/package.json +1 -1
  58. package/dist/lib-cjs/computeSuggestions.d.ts +0 -2
  59. package/dist/lib-cjs/computeSuggestions.js +0 -128
  60. package/dist/lib-cjs/computeSuggestions.js.map +0 -1
  61. package/dist/lib-esm/computeSuggestions.d.ts +0 -2
  62. package/dist/lib-esm/computeSuggestions.js +0 -124
  63. package/dist/lib-esm/computeSuggestions.js.map +0 -1
@@ -1,45 +1,12 @@
1
- export type AggregationOptions = {
2
- attributeKeys: string[];
3
- };
4
- export type AggregateType = 'number' | 'reference' | 'string';
5
- export type AggregateBase = {
6
- attribute: string;
7
- type: AggregateType;
8
- };
9
- export type NumberAggregation = AggregateBase & {
10
- attribute: string;
11
- type: 'number';
12
- value: NumberAggregationValue;
13
- };
14
- export type ReferenceAggregation = AggregateBase & {
15
- attribute: string;
16
- type: 'reference';
17
- value: ReferenceAggregationValue[];
18
- };
19
- export type StringAggregation = AggregateBase & {
20
- attribute: string;
21
- type: 'string';
22
- value: StringAggregationValue[];
23
- };
24
- export type Aggregation = NumberAggregation | StringAggregation | ReferenceAggregation;
25
1
  export type NumberAggregationValue = {
26
2
  average: number;
27
3
  count: number;
28
4
  sum: number;
29
5
  };
30
- export type ReferenceAggregationValue = {
31
- value: string;
32
- count: number;
33
- itemKeys: string[];
34
- };
35
- export type StringAggregationValue = {
36
- value: string;
37
- count: number;
38
- };
39
- export type AggregationTypeNew = 'sum' | 'avg' | 'min' | 'max' | 'distinct' | 'group';
40
- export type AggregationOptionsNew = {
6
+ export type AggregationType = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'distinct' | 'group';
7
+ export type AggregationOptions = {
41
8
  attribute: string;
42
- types: AggregationTypeNew[];
9
+ types: AggregationType[];
43
10
  distinctOptions?: {
44
11
  limit?: number;
45
12
  };
@@ -67,11 +34,12 @@ export type AggregationGroupValue = {
67
34
  count: number;
68
35
  keys: string[];
69
36
  };
70
- export type AggregationNew = {
37
+ export type Aggregation = {
71
38
  attribute: string;
72
- types: AggregationTypeNew[];
39
+ types: AggregationType[];
73
40
  sum?: number;
74
41
  avg?: number;
42
+ count?: number;
75
43
  min?: number;
76
44
  max?: number;
77
45
  distinct?: AggregationDistinctValue[];
@@ -1,2 +1,5 @@
1
+ // export type AggregationOptions = {
2
+ // attributeKeys: string[];
3
+ // };
1
4
  export {};
2
5
  //# sourceMappingURL=aggregation.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregation.types.js","sourceRoot":"","sources":["../../../src/types/aggregation.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"aggregation.types.js","sourceRoot":"","sources":["../../../src/types/aggregation.types.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,6BAA6B;AAC7B,KAAK"}
@@ -12,3 +12,8 @@ export type DataContainer<ListType extends RawItem | ListItem = ListItem, ModelN
12
12
  };
13
13
  export type DataContainerType = 'upsert' | 'update' | 'set' | 'delete';
14
14
  export type ReferenceDataTypes<ListType extends ListItem = ListItem> = string | string[] | ListType | ListType[];
15
+ export type DataOptions<ModelNames extends string = string> = {
16
+ model: ModelNames;
17
+ keyProperty?: string;
18
+ autoGenerateKey?: boolean;
19
+ };
@@ -0,0 +1,13 @@
1
+ import { AggregationOptions } from './aggregation.types';
2
+ import { DcuplItemsOptions } from './list.types';
3
+ export type DcuplSectionItemOption<T> = DcuplItemsOptions<T> & {
4
+ key: string;
5
+ };
6
+ export type DcuplGroupByOptions<T> = DcuplItemsOptions<T> & {
7
+ attribute: string;
8
+ aggregates?: AggregationOptions[];
9
+ items?: DcuplSectionItemOption<T>[];
10
+ excludeZeros?: boolean;
11
+ excludeUndefineds?: boolean;
12
+ excludeUnresolved?: boolean;
13
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=group-by.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-by.types.js","sourceRoot":"","sources":["../../../src/types/group-by.types.ts"],"names":[],"mappings":""}
@@ -4,6 +4,7 @@ export * from './dcupl.types';
4
4
  export * from './facets.types';
5
5
  export * from './filter.types';
6
6
  export * from './global.types';
7
+ export * from './group-by.types';
7
8
  export * from './internal.types';
8
9
  export * from './list.types';
9
10
  export * from './model.types';
@@ -4,6 +4,7 @@ export * from './dcupl.types';
4
4
  export * from './facets.types';
5
5
  export * from './filter.types';
6
6
  export * from './global.types';
7
+ export * from './group-by.types';
7
8
  export * from './internal.types';
8
9
  export * from './list.types';
9
10
  export * from './model.types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { DcuplGlobalQueryOptionsNew } from './query.types';
1
+ import { DcuplGlobalQueryOptions } from './query.types';
2
2
  import { ViewDefinition, ModelAttribute } from './model.types';
3
3
  import { Projection, SortingProjection } from './projection.types';
4
4
  export type DcuplItemsOptions<T> = {
@@ -15,14 +15,6 @@ export type DcuplManyItemsOptions<T> = {
15
15
  projection?: Projection<T>;
16
16
  itemKeys: string[];
17
17
  };
18
- export type DcuplSectionItemOption<T> = DcuplItemsOptions<T> & {
19
- key: string;
20
- };
21
- export type DcuplSectionOptions<T> = DcuplItemsOptions<T> & {
22
- primaryAttribute: string;
23
- aggregates?: string[];
24
- items?: DcuplSectionItemOption<T>[];
25
- };
26
18
  export type DcuplFilterOptions = CatalogApiOptions & {
27
19
  calculateFacets?: boolean;
28
20
  excludeZeros?: boolean;
@@ -47,7 +39,7 @@ export type ListMetadata = {
47
39
  key: string;
48
40
  currentSize: number;
49
41
  initialSize: number;
50
- appliedQuery: DcuplGlobalQueryOptionsNew<any>;
42
+ appliedQuery: DcuplGlobalQueryOptions<any>;
51
43
  attributes: ModelAttribute[];
52
44
  views: ViewDefinition[];
53
45
  };
@@ -1,4 +1,4 @@
1
- import { RawItem } from '.';
1
+ import { AggregationOptions, RawItem } from '.';
2
2
  export type PropertyType = 'string' | 'int' | 'float' | 'json' | 'date' | 'boolean' | 'any' | 'Array<string>' | 'Array<int>' | 'Array<float>' | 'Array<date>';
3
3
  export declare const NumberPropertyTypes: PropertyType[];
4
4
  export declare const DatePropertyTypes: PropertyType[];
@@ -278,7 +278,7 @@ export type ViewDefinition = {
278
278
  * @minLength 1
279
279
  */
280
280
  primaryAttribute: string;
281
- aggregates: string[];
281
+ aggregates: AggregationOptions[];
282
282
  meta?: ModelMetadata;
283
283
  };
284
284
  /**
@@ -49,7 +49,6 @@ export type DcuplQueryGroup<ChildQuery extends DcuplQuery | DcuplQueryGroup = an
49
49
  queries: Array<ChildQuery>;
50
50
  options?: DcuplQueryOptions;
51
51
  };
52
- export type DcuplGlobalQueryOptionsNew<T> = DcuplGlobalQueryOptions<T>;
53
52
  type DcuplItemOptions<T> = {
54
53
  start?: number;
55
54
  count?: number;
@@ -62,7 +61,13 @@ export type DcuplGlobalQueryOptions<T> = {
62
61
  export type DcuplGlobalItemOptions<T> = {
63
62
  modelKey: string;
64
63
  itemKey: string;
65
- } & DcuplItemOptions<T>;
64
+ projection?: Projection<T>;
65
+ };
66
+ export type DcuplGlobalManyItemOptions<T> = {
67
+ modelKey: string;
68
+ itemKeys: string[];
69
+ projection?: Projection<T>;
70
+ };
66
71
  export type DcuplListQueryOptions<T> = DcuplItemOptions<T> & DcuplQueryGroup;
67
72
  export type DcuplListItemOptions<T> = DcuplItemOptions<T> & {
68
73
  itemKey: string;
@@ -1,28 +1,13 @@
1
1
  import { CatalogApiOptions } from './list.types';
2
- import { FilterComparisonType } from './model.types';
3
2
  import { DcuplQueryTransformOptions } from './query.types';
4
- export type SuggestionValueEntry = {
5
- key: string;
6
- value: string;
7
- };
8
- export type Suggestion<T extends string | SuggestionValueEntry = string> = {
9
- value: T;
10
- filterKey: string;
11
- };
12
3
  export type SuggestionOptions = CatalogApiOptions & {
13
- filterKey: string;
14
- searchTerm: string;
15
- max?: number;
16
- comparisonType?: FilterComparisonType;
17
- };
18
- export type SuggestionOptionsNew = CatalogApiOptions & {
19
4
  attribute: string;
20
5
  searchTerm: string;
21
6
  max?: number;
22
7
  calculateResultKeys?: boolean;
23
- transform?: DcuplQueryTransformOptions;
8
+ transform?: DcuplQueryTransformOptions[];
24
9
  };
25
- export type SuggestionNew = {
10
+ export type Suggestion = {
26
11
  value: string;
27
12
  keys: string[];
28
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcupl/common",
3
- "version": "0.0.81-beta.7",
3
+ "version": "1.0.0-beta.0",
4
4
  "description": "Dcupl Common Code",
5
5
  "main": "dist/lib-cjs/index.js",
6
6
  "module": "dist/lib-esm/index.js",
@@ -1,2 +0,0 @@
1
- import { ListItem, FilterItem, Suggestion, SuggestionOptions } from './types';
2
- export declare function computeSuggestionsForSearchTerm<ListType extends ListItem = ListItem>(data: Map<string, ListType>, filterItem: FilterItem, options: SuggestionOptions): Suggestion[];
@@ -1,128 +0,0 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.computeSuggestionsForSearchTerm = void 0;
15
- var _1 = require(".");
16
- function computeSuggestionsForSearchTerm(data, filterItem, options) {
17
- var e_1, _a;
18
- if (!options.max) {
19
- options.max = 20;
20
- }
21
- var suggestions = [];
22
- if (filterItem) {
23
- var relevantEntries = getRelevantEntries(filterItem, Array.from(data.values()), options);
24
- try {
25
- for (var relevantEntries_1 = __values(relevantEntries), relevantEntries_1_1 = relevantEntries_1.next(); !relevantEntries_1_1.done; relevantEntries_1_1 = relevantEntries_1.next()) {
26
- var entry = relevantEntries_1_1.value;
27
- var suggestion = {
28
- filterKey: options.filterKey,
29
- value: entry,
30
- };
31
- suggestions.push(suggestion);
32
- }
33
- }
34
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
35
- finally {
36
- try {
37
- if (relevantEntries_1_1 && !relevantEntries_1_1.done && (_a = relevantEntries_1.return)) _a.call(relevantEntries_1);
38
- }
39
- finally { if (e_1) throw e_1.error; }
40
- }
41
- }
42
- return suggestions;
43
- }
44
- exports.computeSuggestionsForSearchTerm = computeSuggestionsForSearchTerm;
45
- var getRelevantEntries = function (filterItem, dataEntries, options) {
46
- var e_2, _a, e_3, _b, e_4, _c;
47
- var relevantEntries = new Set();
48
- if (filterItem.type === 'text') {
49
- var constraint = {
50
- comparisonType: options.comparisonType || filterItem.comparisonType || 'containsIgnoreCase',
51
- type: 'textConstraint',
52
- filterKey: filterItem.key,
53
- attributeKey: filterItem.attributeKey,
54
- uid: '',
55
- value: options.searchTerm,
56
- };
57
- try {
58
- for (var dataEntries_1 = __values(dataEntries), dataEntries_1_1 = dataEntries_1.next(); !dataEntries_1_1.done; dataEntries_1_1 = dataEntries_1.next()) {
59
- var entry = dataEntries_1_1.value;
60
- var itemValue = entry[filterItem.attributeKey];
61
- if (Array.isArray(itemValue)) {
62
- try {
63
- for (var itemValue_1 = (e_3 = void 0, __values(itemValue)), itemValue_1_1 = itemValue_1.next(); !itemValue_1_1.done; itemValue_1_1 = itemValue_1.next()) {
64
- var arrayValue = itemValue_1_1.value;
65
- if ((0, _1.isValidTextConstraint)(arrayValue, constraint)) {
66
- relevantEntries.add(arrayValue);
67
- continue;
68
- }
69
- }
70
- }
71
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
72
- finally {
73
- try {
74
- if (itemValue_1_1 && !itemValue_1_1.done && (_b = itemValue_1.return)) _b.call(itemValue_1);
75
- }
76
- finally { if (e_3) throw e_3.error; }
77
- }
78
- }
79
- else {
80
- if ((0, _1.isValidTextConstraint)(itemValue, constraint)) {
81
- relevantEntries.add(itemValue);
82
- }
83
- }
84
- if (relevantEntries.size === options.max) {
85
- break;
86
- }
87
- }
88
- }
89
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
90
- finally {
91
- try {
92
- if (dataEntries_1_1 && !dataEntries_1_1.done && (_a = dataEntries_1.return)) _a.call(dataEntries_1);
93
- }
94
- finally { if (e_2) throw e_2.error; }
95
- }
96
- }
97
- else if (filterItem.type === 'reference') {
98
- var constraint = {
99
- comparisonType: options.comparisonType || 'containsIgnoreCase',
100
- type: 'textConstraint',
101
- filterKey: filterItem.attributeKey,
102
- attributeKey: filterItem.attributeKey,
103
- uid: '',
104
- value: options.searchTerm,
105
- };
106
- try {
107
- for (var _d = __values(filterItem.entries), _e = _d.next(); !_e.done; _e = _d.next()) {
108
- var entry = _e.value;
109
- var itemValue = entry.value;
110
- if (entry.enabled && (0, _1.isValidTextConstraint)(itemValue, constraint)) {
111
- relevantEntries.add(entry.key);
112
- }
113
- if (relevantEntries.size === options.max) {
114
- break;
115
- }
116
- }
117
- }
118
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
119
- finally {
120
- try {
121
- if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
122
- }
123
- finally { if (e_4) throw e_4.error; }
124
- }
125
- }
126
- return Array.from(relevantEntries.values());
127
- };
128
- //# sourceMappingURL=computeSuggestions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computeSuggestions.js","sourceRoot":"","sources":["../../src/computeSuggestions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,sBAA0C;AAE1C,SAAgB,+BAA+B,CAC7C,IAA2B,EAC3B,UAAsB,EACtB,OAA0B;;IAE1B,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAChB,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;KAClB;IACD,IAAM,WAAW,GAAsB,EAAE,CAAC;IAE1C,IAAI,UAAU,EAAE;QACd,IAAM,eAAe,GAAG,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAE,CAAC;;YAE5F,KAAoB,IAAA,oBAAA,SAAA,eAAe,CAAA,gDAAA,6EAAE;gBAAhC,IAAM,KAAK,4BAAA;gBACd,IAAM,UAAU,GAAe;oBAC7B,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,KAAK,EAAE,KAAK;iBACb,CAAC;gBACF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAC9B;;;;;;;;;KACF;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAvBD,0EAuBC;AAED,IAAM,kBAAkB,GAAG,UAAC,UAAsB,EAAE,WAAuB,EAAE,OAA0B;;IACrG,IAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAC1C,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE;QAC9B,IAAM,UAAU,GAAmB;YACjC,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,UAAU,CAAC,cAAc,IAAI,oBAAoB;YAC3F,IAAI,EAAE,gBAAgB;YACtB,SAAS,EAAE,UAAU,CAAC,GAAG;YACzB,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,OAAO,CAAC,UAAU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,EAAE;oBAC3E,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBAChC;gBACD,IAAI,eAAe,CAAC,IAAI,KAAK,OAAO,CAAC,GAAG,EAAE;oBACxC,MAAM;iBACP;aACF;;;;;;;;;KACF;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9C,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import { ListItem, FilterItem, Suggestion, SuggestionOptions } from './types';
2
- export declare function computeSuggestionsForSearchTerm<ListType extends ListItem = ListItem>(data: Map<string, ListType>, filterItem: FilterItem, options: SuggestionOptions): Suggestion[];
@@ -1,124 +0,0 @@
1
- var __values = (this && this.__values) || function(o) {
2
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
- if (m) return m.call(o);
4
- if (o && typeof o.length === "number") return {
5
- next: function () {
6
- if (o && i >= o.length) o = void 0;
7
- return { value: o && o[i++], done: !o };
8
- }
9
- };
10
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
- };
12
- import { isValidTextConstraint } from '.';
13
- export function computeSuggestionsForSearchTerm(data, filterItem, options) {
14
- var e_1, _a;
15
- if (!options.max) {
16
- options.max = 20;
17
- }
18
- var suggestions = [];
19
- if (filterItem) {
20
- var relevantEntries = getRelevantEntries(filterItem, Array.from(data.values()), options);
21
- try {
22
- for (var relevantEntries_1 = __values(relevantEntries), relevantEntries_1_1 = relevantEntries_1.next(); !relevantEntries_1_1.done; relevantEntries_1_1 = relevantEntries_1.next()) {
23
- var entry = relevantEntries_1_1.value;
24
- var suggestion = {
25
- filterKey: options.filterKey,
26
- value: entry,
27
- };
28
- suggestions.push(suggestion);
29
- }
30
- }
31
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
32
- finally {
33
- try {
34
- if (relevantEntries_1_1 && !relevantEntries_1_1.done && (_a = relevantEntries_1.return)) _a.call(relevantEntries_1);
35
- }
36
- finally { if (e_1) throw e_1.error; }
37
- }
38
- }
39
- return suggestions;
40
- }
41
- var getRelevantEntries = function (filterItem, dataEntries, options) {
42
- var e_2, _a, e_3, _b, e_4, _c;
43
- var relevantEntries = new Set();
44
- if (filterItem.type === 'text') {
45
- var constraint = {
46
- comparisonType: options.comparisonType || filterItem.comparisonType || 'containsIgnoreCase',
47
- type: 'textConstraint',
48
- filterKey: filterItem.key,
49
- attributeKey: filterItem.attributeKey,
50
- uid: '',
51
- value: options.searchTerm,
52
- };
53
- try {
54
- for (var dataEntries_1 = __values(dataEntries), dataEntries_1_1 = dataEntries_1.next(); !dataEntries_1_1.done; dataEntries_1_1 = dataEntries_1.next()) {
55
- var entry = dataEntries_1_1.value;
56
- var itemValue = entry[filterItem.attributeKey];
57
- if (Array.isArray(itemValue)) {
58
- try {
59
- for (var itemValue_1 = (e_3 = void 0, __values(itemValue)), itemValue_1_1 = itemValue_1.next(); !itemValue_1_1.done; itemValue_1_1 = itemValue_1.next()) {
60
- var arrayValue = itemValue_1_1.value;
61
- if (isValidTextConstraint(arrayValue, constraint)) {
62
- relevantEntries.add(arrayValue);
63
- continue;
64
- }
65
- }
66
- }
67
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
68
- finally {
69
- try {
70
- if (itemValue_1_1 && !itemValue_1_1.done && (_b = itemValue_1.return)) _b.call(itemValue_1);
71
- }
72
- finally { if (e_3) throw e_3.error; }
73
- }
74
- }
75
- else {
76
- if (isValidTextConstraint(itemValue, constraint)) {
77
- relevantEntries.add(itemValue);
78
- }
79
- }
80
- if (relevantEntries.size === options.max) {
81
- break;
82
- }
83
- }
84
- }
85
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
86
- finally {
87
- try {
88
- if (dataEntries_1_1 && !dataEntries_1_1.done && (_a = dataEntries_1.return)) _a.call(dataEntries_1);
89
- }
90
- finally { if (e_2) throw e_2.error; }
91
- }
92
- }
93
- else if (filterItem.type === 'reference') {
94
- var constraint = {
95
- comparisonType: options.comparisonType || 'containsIgnoreCase',
96
- type: 'textConstraint',
97
- filterKey: filterItem.attributeKey,
98
- attributeKey: filterItem.attributeKey,
99
- uid: '',
100
- value: options.searchTerm,
101
- };
102
- try {
103
- for (var _d = __values(filterItem.entries), _e = _d.next(); !_e.done; _e = _d.next()) {
104
- var entry = _e.value;
105
- var itemValue = entry.value;
106
- if (entry.enabled && isValidTextConstraint(itemValue, constraint)) {
107
- relevantEntries.add(entry.key);
108
- }
109
- if (relevantEntries.size === options.max) {
110
- break;
111
- }
112
- }
113
- }
114
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
115
- finally {
116
- try {
117
- if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
118
- }
119
- finally { if (e_4) throw e_4.error; }
120
- }
121
- }
122
- return Array.from(relevantEntries.values());
123
- };
124
- //# sourceMappingURL=computeSuggestions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computeSuggestions.js","sourceRoot":"","sources":["../../src/computeSuggestions.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAE1C,MAAM,UAAU,+BAA+B,CAC7C,IAA2B,EAC3B,UAAsB,EACtB,OAA0B;;IAE1B,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAChB,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;KAClB;IACD,IAAM,WAAW,GAAsB,EAAE,CAAC;IAE1C,IAAI,UAAU,EAAE;QACd,IAAM,eAAe,GAAG,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAE,CAAC;;YAE5F,KAAoB,IAAA,oBAAA,SAAA,eAAe,CAAA,gDAAA,6EAAE;gBAAhC,IAAM,KAAK,4BAAA;gBACd,IAAM,UAAU,GAAe;oBAC7B,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,KAAK,EAAE,KAAK;iBACb,CAAC;gBACF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