@fibery/query-utils 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,214 @@
1
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2
+ LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3
+ CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4
+
5
+ 1. DEFINITIONS
6
+
7
+ "Contribution" means:
8
+
9
+ a) in the case of the initial Contributor, the initial code and
10
+ documentation distributed under this Agreement, and
11
+
12
+ b) in the case of each subsequent Contributor:
13
+
14
+ i) changes to the Program, and
15
+
16
+ ii) additions to the Program;
17
+
18
+ where such changes and/or additions to the Program originate from and are
19
+ distributed by that particular Contributor. A Contribution 'originates' from
20
+ a Contributor if it was added to the Program by such Contributor itself or
21
+ anyone acting on such Contributor's behalf. Contributions do not include
22
+ additions to the Program which: (i) are separate modules of software
23
+ distributed in conjunction with the Program under their own license
24
+ agreement, and (ii) are not derivative works of the Program.
25
+
26
+ "Contributor" means any person or entity that distributes the Program.
27
+
28
+ "Licensed Patents" mean patent claims licensable by a Contributor which are
29
+ necessarily infringed by the use or sale of its Contribution alone or when
30
+ combined with the Program.
31
+
32
+ "Program" means the Contributions distributed in accordance with this
33
+ Agreement.
34
+
35
+ "Recipient" means anyone who receives the Program under this Agreement,
36
+ including all Contributors.
37
+
38
+ 2. GRANT OF RIGHTS
39
+
40
+ a) Subject to the terms of this Agreement, each Contributor hereby grants
41
+ Recipient a non-exclusive, worldwide, royalty-free copyright license to
42
+ reproduce, prepare derivative works of, publicly display, publicly perform,
43
+ distribute and sublicense the Contribution of such Contributor, if any, and
44
+ such derivative works, in source code and object code form.
45
+
46
+ b) Subject to the terms of this Agreement, each Contributor hereby grants
47
+ Recipient a non-exclusive, worldwide, royalty-free patent license under
48
+ Licensed Patents to make, use, sell, offer to sell, import and otherwise
49
+ transfer the Contribution of such Contributor, if any, in source code and
50
+ object code form. This patent license shall apply to the combination of the
51
+ Contribution and the Program if, at the time the Contribution is added by the
52
+ Contributor, such addition of the Contribution causes such combination to be
53
+ covered by the Licensed Patents. The patent license shall not apply to any
54
+ other combinations which include the Contribution. No hardware per se is
55
+ licensed hereunder.
56
+
57
+ c) Recipient understands that although each Contributor grants the licenses
58
+ to its Contributions set forth herein, no assurances are provided by any
59
+ Contributor that the Program does not infringe the patent or other
60
+ intellectual property rights of any other entity. Each Contributor disclaims
61
+ any liability to Recipient for claims brought by any other entity based on
62
+ infringement of intellectual property rights or otherwise. As a condition to
63
+ exercising the rights and licenses granted hereunder, each Recipient hereby
64
+ assumes sole responsibility to secure any other intellectual property rights
65
+ needed, if any. For example, if a third party patent license is required to
66
+ allow Recipient to distribute the Program, it is Recipient's responsibility
67
+ to acquire that license before distributing the Program.
68
+
69
+ d) Each Contributor represents that to its knowledge it has sufficient
70
+ copyright rights in its Contribution, if any, to grant the copyright license
71
+ set forth in this Agreement.
72
+
73
+ 3. REQUIREMENTS
74
+
75
+ A Contributor may choose to distribute the Program in object code form under
76
+ its own license agreement, provided that:
77
+
78
+ a) it complies with the terms and conditions of this Agreement; and
79
+
80
+ b) its license agreement:
81
+
82
+ i) effectively disclaims on behalf of all Contributors all warranties and
83
+ conditions, express and implied, including warranties or conditions of title
84
+ and non-infringement, and implied warranties or conditions of merchantability
85
+ and fitness for a particular purpose;
86
+
87
+ ii) effectively excludes on behalf of all Contributors all liability for
88
+ damages, including direct, indirect, special, incidental and consequential
89
+ damages, such as lost profits;
90
+
91
+ iii) states that any provisions which differ from this Agreement are offered
92
+ by that Contributor alone and not by any other party; and
93
+
94
+ iv) states that source code for the Program is available from such
95
+ Contributor, and informs licensees how to obtain it in a reasonable manner on
96
+ or through a medium customarily used for software exchange.
97
+
98
+ When the Program is made available in source code form:
99
+
100
+ a) it must be made available under this Agreement; and
101
+
102
+ b) a copy of this Agreement must be included with each copy of the Program.
103
+
104
+ Contributors may not remove or alter any copyright notices contained within
105
+ the Program.
106
+
107
+ Each Contributor must identify itself as the originator of its Contribution,
108
+ if any, in a manner that reasonably allows subsequent Recipients to identify
109
+ the originator of the Contribution.
110
+
111
+ 4. COMMERCIAL DISTRIBUTION
112
+
113
+ Commercial distributors of software may accept certain responsibilities with
114
+ respect to end users, business partners and the like. While this license is
115
+ intended to facilitate the commercial use of the Program, the Contributor who
116
+ includes the Program in a commercial product offering should do so in a
117
+ manner which does not create potential liability for other Contributors.
118
+ Therefore, if a Contributor includes the Program in a commercial product
119
+ offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120
+ and indemnify every other Contributor ("Indemnified Contributor") against any
121
+ losses, damages and costs (collectively "Losses") arising from claims,
122
+ lawsuits and other legal actions brought by a third party against the
123
+ Indemnified Contributor to the extent caused by the acts or omissions of such
124
+ Commercial Contributor in connection with its distribution of the Program in
125
+ a commercial product offering. The obligations in this section do not apply
126
+ to any claims or Losses relating to any actual or alleged intellectual
127
+ property infringement. In order to qualify, an Indemnified Contributor must:
128
+ a) promptly notify the Commercial Contributor in writing of such claim, and
129
+ b) allow the Commercial Contributor to control, and cooperate with the
130
+ Commercial Contributor in, the defense and any related settlement
131
+ negotiations. The Indemnified Contributor may participate in any such claim
132
+ at its own expense.
133
+
134
+ For example, a Contributor might include the Program in a commercial product
135
+ offering, Product X. That Contributor is then a Commercial Contributor. If
136
+ that Commercial Contributor then makes performance claims, or offers
137
+ warranties related to Product X, those performance claims and warranties are
138
+ such Commercial Contributor's responsibility alone. Under this section, the
139
+ Commercial Contributor would have to defend claims against the other
140
+ Contributors related to those performance claims and warranties, and if a
141
+ court requires any other Contributor to pay any damages as a result, the
142
+ Commercial Contributor must pay those damages.
143
+
144
+ 5. NO WARRANTY
145
+
146
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147
+ AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148
+ EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149
+ CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150
+ PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151
+ appropriateness of using and distributing the Program and assumes all risks
152
+ associated with its exercise of rights under this Agreement , including but
153
+ not limited to the risks and costs of program errors, compliance with
154
+ applicable laws, damage to or loss of data, programs or equipment, and
155
+ unavailability or interruption of operations.
156
+
157
+ 6. DISCLAIMER OF LIABILITY
158
+
159
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160
+ CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162
+ LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164
+ ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165
+ EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166
+ OF SUCH DAMAGES.
167
+
168
+ 7. GENERAL
169
+
170
+ If any provision of this Agreement is invalid or unenforceable under
171
+ applicable law, it shall not affect the validity or enforceability of the
172
+ remainder of the terms of this Agreement, and without further action by the
173
+ parties hereto, such provision shall be reformed to the minimum extent
174
+ necessary to make such provision valid and enforceable.
175
+
176
+ If Recipient institutes patent litigation against any entity (including a
177
+ cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178
+ (excluding combinations of the Program with other software or hardware)
179
+ infringes such Recipient's patent(s), then such Recipient's rights granted
180
+ under Section 2(b) shall terminate as of the date such litigation is filed.
181
+
182
+ All Recipient's rights under this Agreement shall terminate if it fails to
183
+ comply with any of the material terms or conditions of this Agreement and
184
+ does not cure such failure in a reasonable period of time after becoming
185
+ aware of such noncompliance. If all Recipient's rights under this Agreement
186
+ terminate, Recipient agrees to cease use and distribution of the Program as
187
+ soon as reasonably practicable. However, Recipient's obligations under this
188
+ Agreement and any licenses granted by Recipient relating to the Program shall
189
+ continue and survive.
190
+
191
+ Everyone is permitted to copy and distribute copies of this Agreement, but in
192
+ order to avoid inconsistency the Agreement is copyrighted and may only be
193
+ modified in the following manner. The Agreement Steward reserves the right to
194
+ publish new versions (including revisions) of this Agreement from time to
195
+ time. No one other than the Agreement Steward has the right to modify this
196
+ Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197
+ Eclipse Foundation may assign the responsibility to serve as the Agreement
198
+ Steward to a suitable separate entity. Each new version of the Agreement will
199
+ be given a distinguishing version number. The Program (including
200
+ Contributions) may always be distributed subject to the version of the
201
+ Agreement under which it was received. In addition, after a new version of
202
+ the Agreement is published, Contributor may elect to distribute the Program
203
+ (including its Contributions) under the new version. Except as expressly
204
+ stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205
+ licenses to the intellectual property of any Contributor under this
206
+ Agreement, whether expressly, by implication, estoppel or otherwise. All
207
+ rights in the Program not expressly granted under this Agreement are
208
+ reserved.
209
+
210
+ This Agreement is governed by the laws of the State of New York and the
211
+ intellectual property laws of the United States of America. No party to this
212
+ Agreement will bring a legal action under this Agreement more than one year
213
+ after the cause of action arose. Each party waives its rights to a jury trial
214
+ in any resulting litigation.
package/README.md ADDED
File without changes
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { $TSFixMe } from "./tsfixme";
2
+ export declare class NotImplementedError extends Error {
3
+ constructor(value: $TSFixMe, itemType?: string);
4
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotImplementedError = void 0;
4
+ const stringify = (x) => {
5
+ if (x === undefined) {
6
+ return "undefined";
7
+ }
8
+ return JSON.stringify(x);
9
+ };
10
+ class NotImplementedError extends Error {
11
+ constructor(value, itemType) {
12
+ super([`"${stringify(value)}"`, itemType, "is not implemented"].filter((x) => x !== undefined).join(" "));
13
+ }
14
+ }
15
+ exports.NotImplementedError = NotImplementedError;
@@ -0,0 +1,43 @@
1
+ import { Expression, OrderBy } from "@fibery/expression-utils/src/types";
2
+ import { FieldObject, TypeObject } from "@fibery/schema";
3
+ import { $TSFixMe } from "./tsfixme";
4
+ import { FiberyObject } from "./types";
5
+ export declare const extractReferenceField: (expression: Expression) => string;
6
+ export declare const getRangeValue: (object: FiberyObject, expression: Expression) => any;
7
+ export declare const extractSingleFieldFromExpression: (expression: Expression) => string;
8
+ export declare function extractFieldObjectFromExpression({ expression, typeObject, }: {
9
+ expression: Expression | null | undefined;
10
+ typeObject: TypeObject;
11
+ }): FieldObject | null;
12
+ export declare const warnAboutNonProcessedKeys: (location: string, rest: Record<string, unknown>) => void;
13
+ export declare const getValueByFieldExpression: (object: $TSFixMe, path: Expression) => any;
14
+ export declare const parseMultiFieldValue: ({ multiFieldValue, multiFieldObject, }: {
15
+ multiFieldValue?: Record<string, unknown> | null;
16
+ multiFieldObject: FieldObject;
17
+ }) => {
18
+ value: any;
19
+ typeObject: TypeObject;
20
+ } | null;
21
+ export declare const calculateDefaultOrderBy: ({ typeObject }: {
22
+ typeObject: TypeObject;
23
+ }) => OrderBy | undefined;
24
+ export declare const calculateOrderByForRequest: ({ orderByFromMeta, typeObject, }: {
25
+ orderByFromMeta?: OrderBy;
26
+ typeObject: TypeObject;
27
+ }) => OrderBy | undefined;
28
+ export declare const calculateOrderByRankOrName: ({ typeObject }: {
29
+ typeObject: TypeObject;
30
+ }) => OrderBy | (string | string[])[][] | undefined;
31
+ export declare const calculateSortObjectsFn: ({ typeObject }: {
32
+ typeObject: TypeObject;
33
+ }) => {
34
+ <T>(value: T): T;
35
+ (): undefined;
36
+ } | ((objects: $TSFixMe) => any[]);
37
+ export declare const extractSingleField: (expression: Expression) => string;
38
+ export declare const getQuerySelectForExpression: ({ typeObject, expression, selectsByTypeLookup, }: {
39
+ typeObject: TypeObject;
40
+ expression: Expression;
41
+ selectsByTypeLookup?: Record<string, $TSFixMe>;
42
+ }) => any;
43
+ export declare const getOrderBySelect: (orderBy: OrderBy | undefined | null, typeObject: TypeObject) => any;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOrderBySelect = exports.getQuerySelectForExpression = exports.extractSingleField = exports.calculateSortObjectsFn = exports.calculateOrderByRankOrName = exports.calculateOrderByForRequest = exports.calculateDefaultOrderBy = exports.parseMultiFieldValue = exports.getValueByFieldExpression = exports.warnAboutNonProcessedKeys = exports.extractSingleFieldFromExpression = exports.getRangeValue = exports.extractReferenceField = void 0;
7
+ exports.extractFieldObjectFromExpression = extractFieldObjectFromExpression;
8
+ const utils_1 = require("@fibery/expression-utils/src/utils");
9
+ const trace_1 = require("@fibery/helpers/utils/trace");
10
+ const array_1 = require("@fibery/helpers/utils/array");
11
+ const lodash_1 = __importDefault(require("lodash"));
12
+ const memoize_one_1 = __importDefault(require("memoize-one"));
13
+ const errors_1 = require("./errors");
14
+ const select_1 = require("./select");
15
+ const extractReferenceField = (expression) => {
16
+ (0, trace_1.assert)((0, utils_1.isFieldExpression)(expression));
17
+ return (0, array_1.single)(expression);
18
+ };
19
+ exports.extractReferenceField = extractReferenceField;
20
+ const getRangeValue = (object, expression) => {
21
+ (0, trace_1.assert)((0, utils_1.isFunctionCallExpression)(expression));
22
+ const [op, path] = expression;
23
+ const range = (0, exports.getValueByFieldExpression)(object, path);
24
+ if (!range) {
25
+ return range;
26
+ }
27
+ switch (op) {
28
+ case "q/start":
29
+ return range.start;
30
+ case "q/end":
31
+ return range.end;
32
+ default:
33
+ throw new Error(`Invalid operation ${op} in expression ${expression}`);
34
+ }
35
+ };
36
+ exports.getRangeValue = getRangeValue;
37
+ const extractSingleFieldFromExpression = (expression) => {
38
+ (0, utils_1.assertIsValidExpression)(expression);
39
+ if ((0, utils_1.isFunctionCallExpression)(expression) && (0, utils_1.isDateRangeFunctionExpression)(expression)) {
40
+ const [, plainPathExpression] = expression;
41
+ (0, trace_1.assert)((0, utils_1.isFieldExpression)(plainPathExpression));
42
+ return (0, array_1.single)(plainPathExpression);
43
+ }
44
+ else {
45
+ (0, trace_1.assert)((0, utils_1.isFieldExpression)(expression));
46
+ return (0, array_1.single)(expression);
47
+ }
48
+ };
49
+ exports.extractSingleFieldFromExpression = extractSingleFieldFromExpression;
50
+ function extractFieldObjectFromExpression({ expression, typeObject, }) {
51
+ if (!expression) {
52
+ return null;
53
+ }
54
+ const field = (0, exports.extractSingleFieldFromExpression)(expression);
55
+ return typeObject.fieldObjectsByName[field];
56
+ }
57
+ const warnAboutNonProcessedKeys = (location, rest) => {
58
+ const nonProcessedKeys = Object.keys(rest);
59
+ if (nonProcessedKeys.length > 0) {
60
+ // temporary ignore filter key
61
+ if (nonProcessedKeys[0] === "filter") {
62
+ return;
63
+ }
64
+ // eslint-disable-next-line no-console
65
+ console.warn(`${location} contains non-processed params: ${nonProcessedKeys}`);
66
+ }
67
+ };
68
+ exports.warnAboutNonProcessedKeys = warnAboutNonProcessedKeys;
69
+ const getValueByFieldExpression = (object, path) => {
70
+ // TODO: review types. According to Expression it might be nested array but looks like we ignore it everywhere
71
+ return path.reduce((memo, key) => {
72
+ if (memo === undefined) {
73
+ return undefined;
74
+ }
75
+ if (memo === null) {
76
+ return null;
77
+ }
78
+ return memo[key];
79
+ }, object);
80
+ };
81
+ exports.getValueByFieldExpression = getValueByFieldExpression;
82
+ const parseMultiFieldValueInner = (multiFieldValue) => {
83
+ if (!multiFieldValue) {
84
+ return multiFieldValue;
85
+ }
86
+ const firstNotNullValue = Object.entries(multiFieldValue).find(([key]) => multiFieldValue[key] !== null);
87
+ if (!firstNotNullValue) {
88
+ return null;
89
+ }
90
+ return { type: firstNotNullValue[0], value: firstNotNullValue[1] };
91
+ };
92
+ const parseMultiFieldValue = ({ multiFieldValue, multiFieldObject, }) => {
93
+ const parsed = parseMultiFieldValueInner(multiFieldValue);
94
+ if (!parsed) {
95
+ return null;
96
+ }
97
+ const multiRelatedFieldObject = multiFieldObject.multiRelatedFieldObjects.find((f) => f.holderType === parsed.type);
98
+ if (!multiRelatedFieldObject) {
99
+ return null;
100
+ }
101
+ return { value: parsed.value, typeObject: multiRelatedFieldObject.holderTypeObject };
102
+ };
103
+ exports.parseMultiFieldValue = parseMultiFieldValue;
104
+ const calculateDefaultOrderBy = ({ typeObject }) => {
105
+ return typeObject.rankFieldObject === null ? undefined : [[[typeObject.rankField], "q/asc"]];
106
+ };
107
+ exports.calculateDefaultOrderBy = calculateDefaultOrderBy;
108
+ const calculateOrderByForRequest = ({ orderByFromMeta, typeObject, }) => {
109
+ const defaultOrderBy = (0, exports.calculateDefaultOrderBy)({ typeObject });
110
+ if (!orderByFromMeta) {
111
+ return defaultOrderBy;
112
+ }
113
+ else {
114
+ // When installing an app, we create a view with meta with explicit sorting by rank.
115
+ // Let's not add defaultOrderBy in this case, it will be just a duplicate.
116
+ if (defaultOrderBy && !lodash_1.default.isEqual(orderByFromMeta, defaultOrderBy)) {
117
+ return orderByFromMeta.concat(defaultOrderBy);
118
+ }
119
+ else {
120
+ return orderByFromMeta;
121
+ }
122
+ }
123
+ };
124
+ exports.calculateOrderByForRequest = calculateOrderByForRequest;
125
+ const calculateOrderByRankOrName = ({ typeObject }) => {
126
+ if (typeObject.isEnum) {
127
+ return (0, exports.calculateDefaultOrderBy)({ typeObject });
128
+ }
129
+ else if (typeObject.titleField) {
130
+ return [[[typeObject.titleField], "q/asc"]];
131
+ }
132
+ else {
133
+ return undefined;
134
+ }
135
+ };
136
+ exports.calculateOrderByRankOrName = calculateOrderByRankOrName;
137
+ const makeSortByRankFn = (0, memoize_one_1.default)((rankField) => {
138
+ return (objects) => lodash_1.default.sortBy(objects, (object) => object[rankField]);
139
+ });
140
+ const calculateSortObjectsFn = ({ typeObject }) => {
141
+ return typeObject.rankFieldObject === null ? lodash_1.default.identity : makeSortByRankFn(typeObject.rankField);
142
+ };
143
+ exports.calculateSortObjectsFn = calculateSortObjectsFn;
144
+ const extractSingleField = (expression) => {
145
+ (0, trace_1.assert)(lodash_1.default.last(expression) === "fibery/id", "not supported:", { expression });
146
+ return (0, array_1.single)(expression.slice(0, -1));
147
+ };
148
+ exports.extractSingleField = extractSingleField;
149
+ const getQuerySelectForExpression = ({ typeObject, expression, selectsByTypeLookup = {}, }) => {
150
+ const root = {};
151
+ const acc = { currentNode: root, currentTypeObject: typeObject };
152
+ expression.reduce((acc, field) => {
153
+ if (!acc) {
154
+ return null;
155
+ }
156
+ const { currentNode, currentTypeObject } = acc;
157
+ const fieldObject = currentTypeObject.fieldObjectsByName[field];
158
+ if (fieldObject.kind === ":field/reference") {
159
+ currentNode[field] =
160
+ selectsByTypeLookup[fieldObject.type] || (0, select_1.toSelectMapClause)([fieldObject.typeObject.idField]);
161
+ return {
162
+ currentNode: currentNode[field],
163
+ currentTypeObject: fieldObject.typeObject,
164
+ };
165
+ }
166
+ else if (fieldObject.kind === ":field/basic") {
167
+ currentNode[field] = fieldObject.name;
168
+ return null;
169
+ }
170
+ else {
171
+ throw new errors_1.NotImplementedError(fieldObject.kind);
172
+ }
173
+ }, acc);
174
+ return (0, select_1.denormalizeSelect)(root);
175
+ };
176
+ exports.getQuerySelectForExpression = getQuerySelectForExpression;
177
+ const getOrderBySelect = (orderBy, typeObject) => {
178
+ if (!orderBy) {
179
+ return {};
180
+ }
181
+ (0, trace_1.assert)(orderBy.every(lodash_1.default.isArray), `Order By should be an array of ordering expressions`);
182
+ const selects = orderBy
183
+ .map((ordering) => {
184
+ const orderingExpression = ordering[0];
185
+ return (0, exports.getQuerySelectForExpression)({
186
+ typeObject,
187
+ expression: (0, utils_1.isDateRangeFunctionExpression)(orderingExpression)
188
+ ? orderingExpression[1]
189
+ : orderingExpression,
190
+ });
191
+ })
192
+ // always include rank, as it is used for card creation, see `calculateNewCardRank`.
193
+ .concat(typeObject.rankFieldObject ? [{ [typeObject.rankFieldObject.name]: [typeObject.rankFieldObject.name] }] : []);
194
+ return (0, select_1.mergeDenormalizedSelects)(selects);
195
+ };
196
+ exports.getOrderBySelect = getOrderBySelect;
@@ -0,0 +1,107 @@
1
+ import { Expression } from "@fibery/expression-utils/src/types";
2
+ import _ from "lodash";
3
+ import { Schema } from "@fibery/schema";
4
+ import { FiberyObject, Query, Select } from "./types";
5
+ import { $TSFixMe } from "./tsfixme";
6
+ export declare const isDynamicSelectLhs: (field: string) => boolean;
7
+ export declare const isDynamicSelectRhs: (rhs: Expression) => boolean;
8
+ export declare const isSelectForMultiFieldKey = "_isSelectForMultiField_";
9
+ export declare function normalizeSelectInPath(path: Expression, value: $TSFixMe): $TSFixMe;
10
+ export declare const normalizeSelect: (denormalizedSelect: $TSFixMe) => any;
11
+ export declare function denormalizeSelectInPath(path: Expression, value: $TSFixMe): $TSFixMe;
12
+ export declare const denormalizeSelect: (normalizedSelect: $TSFixMe) => any;
13
+ export declare function mergeDenormalizedSelects(denormalizedSelects: $TSFixMe[]): any;
14
+ export declare const annotateNormalizedSelect: (normalizedSelect: Select) => ({
15
+ lhs: {
16
+ value: string;
17
+ isDynamicSelect: boolean;
18
+ };
19
+ rhs: {
20
+ value: any;
21
+ isDynamicSelect: boolean;
22
+ isQueryExpression: boolean;
23
+ isPlainObject: boolean;
24
+ };
25
+ } | null)[];
26
+ export declare const pickSelectedFields: (objects: FiberyObject[], normalizedSelect: Select) => {
27
+ object: any;
28
+ holes: unknown[];
29
+ }[];
30
+ export declare const toSelectMapClause: (simpleFields: string[]) => _.Dictionary<string | number | ((separator?: string) => string) | (() => ArrayIterator<string>) | {
31
+ [x: number]: boolean | undefined;
32
+ length?: boolean | undefined;
33
+ toString?: boolean | undefined;
34
+ toLocaleString?: boolean | undefined;
35
+ pop?: boolean | undefined;
36
+ push?: boolean | undefined;
37
+ concat?: boolean | undefined;
38
+ join?: boolean | undefined;
39
+ reverse?: boolean | undefined;
40
+ shift?: boolean | undefined;
41
+ slice?: boolean | undefined;
42
+ sort?: boolean | undefined;
43
+ splice?: boolean | undefined;
44
+ unshift?: boolean | undefined;
45
+ indexOf?: boolean | undefined;
46
+ lastIndexOf?: boolean | undefined;
47
+ every?: boolean | undefined;
48
+ some?: boolean | undefined;
49
+ forEach?: boolean | undefined;
50
+ map?: boolean | undefined;
51
+ filter?: boolean | undefined;
52
+ reduce?: boolean | undefined;
53
+ reduceRight?: boolean | undefined;
54
+ find?: boolean | undefined;
55
+ findIndex?: boolean | undefined;
56
+ fill?: boolean | undefined;
57
+ copyWithin?: boolean | undefined;
58
+ entries?: boolean | undefined;
59
+ keys?: boolean | undefined;
60
+ values?: boolean | undefined;
61
+ includes?: boolean | undefined;
62
+ flatMap?: boolean | undefined;
63
+ flat?: boolean | undefined;
64
+ at?: boolean | undefined;
65
+ findLast?: boolean | undefined;
66
+ findLastIndex?: boolean | undefined;
67
+ toReversed?: boolean | undefined;
68
+ toSorted?: boolean | undefined;
69
+ toSpliced?: boolean | undefined;
70
+ with?: boolean | undefined;
71
+ [Symbol.iterator]?: boolean | undefined;
72
+ readonly [Symbol.unscopables]?: boolean | undefined;
73
+ } | (() => string) | {
74
+ (): string;
75
+ (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
76
+ } | (() => string | undefined) | ((...items: string[]) => number) | {
77
+ (...items: ConcatArray<string>[]): string[];
78
+ (...items: (string | ConcatArray<string>)[]): string[];
79
+ } | (() => string[]) | (() => string | undefined) | ((start?: number, end?: number) => string[]) | ((compareFn?: ((a: string, b: string) => number) | undefined) => string[]) | {
80
+ (start: number, deleteCount?: number): string[];
81
+ (start: number, deleteCount: number, ...items: string[]): string[];
82
+ } | ((...items: string[]) => number) | ((searchElement: string, fromIndex?: number) => number) | ((searchElement: string, fromIndex?: number) => number) | {
83
+ <S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
84
+ (predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
85
+ } | ((predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any) => boolean) | ((callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void) | (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | {
86
+ <S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): S[];
87
+ (predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
88
+ } | {
89
+ (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
90
+ (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
91
+ <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
92
+ } | {
93
+ (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
94
+ (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
95
+ <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U;
96
+ } | {
97
+ <S extends string>(predicate: (value: string, index: number, obj: string[]) => value is S, thisArg?: any): S | undefined;
98
+ (predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
99
+ } | ((predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any) => number) | ((value: string, start?: number, end?: number) => string[]) | ((target: number, start: number, end?: number) => string[]) | (() => ArrayIterator<[number, string]>) | (() => ArrayIterator<number>) | (() => ArrayIterator<string>) | ((searchElement: string, fromIndex?: number) => boolean) | (<U, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U | readonly U[], thisArg?: This | undefined) => U[]) | (<A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]) | ((index: number) => string | undefined) | {
100
+ <S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): S | undefined;
101
+ (predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string | undefined;
102
+ } | ((predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any) => number) | (() => string[]) | ((compareFn?: ((a: string, b: string) => number) | undefined) => string[]) | {
103
+ (start: number, deleteCount: number, ...items: string[]): string[];
104
+ (start: number, deleteCount?: number): string[];
105
+ } | ((index: number, value: string) => string[])>;
106
+ export declare function calculateSelectedTypes(schema: Schema, query: Query): Set<string>;
107
+ export declare function calculateSelectedTypesFromQueries(schema: Schema, queries: Query[]): Set<string>;
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toSelectMapClause = exports.pickSelectedFields = exports.annotateNormalizedSelect = exports.denormalizeSelect = exports.normalizeSelect = exports.isSelectForMultiFieldKey = exports.isDynamicSelectRhs = exports.isDynamicSelectLhs = void 0;
7
+ exports.normalizeSelectInPath = normalizeSelectInPath;
8
+ exports.denormalizeSelectInPath = denormalizeSelectInPath;
9
+ exports.mergeDenormalizedSelects = mergeDenormalizedSelects;
10
+ exports.calculateSelectedTypes = calculateSelectedTypes;
11
+ exports.calculateSelectedTypesFromQueries = calculateSelectedTypesFromQueries;
12
+ const utils_1 = require("@fibery/expression-utils/src/utils");
13
+ const trace_1 = require("@fibery/helpers/utils/trace");
14
+ const lodash_1 = __importDefault(require("lodash"));
15
+ const errors_1 = require("./errors");
16
+ const implicitSubQueryFromTag = null;
17
+ const isDynamicSelectLhs = (field) => field.startsWith("?");
18
+ exports.isDynamicSelectLhs = isDynamicSelectLhs;
19
+ const isDynamicSelectRhs = (rhs) => (0, utils_1.isVariableExpression)(rhs) || (0, utils_1.isBinaryExpression)(rhs) || (0, utils_1.isNaryExpression)(rhs) || (0, utils_1.isFunctionCallExpression)(rhs);
20
+ exports.isDynamicSelectRhs = isDynamicSelectRhs;
21
+ // During select normalization, we remove path. We usually rely on select structure and don't have schema on our hands.
22
+ // So it's impossible to understand if this is multi-field or usual field. That's why we add this meta-info to normalized select.
23
+ // It is removed during de-normalization and should be ignored in various utils methods.
24
+ exports.isSelectForMultiFieldKey = "_isSelectForMultiField_";
25
+ function normalizeSelectInPath(path, value) {
26
+ if (!lodash_1.default.isArray(path)) {
27
+ throw new Error("path must be array");
28
+ }
29
+ if (lodash_1.default.isPlainObject(value)) {
30
+ if ((0, utils_1.isQueryExpression)(value)) {
31
+ if (lodash_1.default.isEqual(lodash_1.default.flatten(value["q/from"]), path)) {
32
+ return {
33
+ ...value,
34
+ "q/select": (0, exports.normalizeSelect)(value["q/select"]),
35
+ "q/from": implicitSubQueryFromTag,
36
+ };
37
+ }
38
+ else {
39
+ throw new Error(`strict array select invariant: ${JSON.stringify({
40
+ actual: value["q/from"],
41
+ expected: path,
42
+ })}`);
43
+ }
44
+ }
45
+ let hasMultiFieldAccess = false;
46
+ const normalized = lodash_1.default.mapValues(value, (value, key) => {
47
+ if (key === exports.isSelectForMultiFieldKey) {
48
+ return value;
49
+ }
50
+ if ((0, utils_1.isMultiFieldExpression)(value)) {
51
+ hasMultiFieldAccess = true;
52
+ return normalizeSelectInPath(path.concat([key]), lodash_1.default.flatten(value));
53
+ }
54
+ else {
55
+ return normalizeSelectInPath(path.concat([key]), value);
56
+ }
57
+ });
58
+ if (hasMultiFieldAccess) {
59
+ return { ...normalized, [exports.isSelectForMultiFieldKey]: true };
60
+ }
61
+ else {
62
+ return normalized;
63
+ }
64
+ }
65
+ if (lodash_1.default.isArray(value)) {
66
+ if (path.length > 0 && (0, exports.isDynamicSelectLhs)(lodash_1.default.last(path)) && (0, exports.isDynamicSelectRhs)(value)) {
67
+ return value;
68
+ }
69
+ if (lodash_1.default.isEqual(value, path)) {
70
+ return lodash_1.default.last(value);
71
+ }
72
+ else {
73
+ throw new Error(`strict array select invariant: ${JSON.stringify({
74
+ actual: value,
75
+ expected: path,
76
+ })}`);
77
+ }
78
+ }
79
+ if (lodash_1.default.isString(value)) {
80
+ return value;
81
+ }
82
+ throw new Error(`denormalizedSelect invariant: ${JSON.stringify({ path, value })}`);
83
+ }
84
+ const normalizeSelect = (denormalizedSelect) => {
85
+ if (!lodash_1.default.isPlainObject(denormalizedSelect)) {
86
+ throw new Error("denormalizedSelect must be an object");
87
+ }
88
+ return normalizeSelectInPath([], denormalizedSelect);
89
+ };
90
+ exports.normalizeSelect = normalizeSelect;
91
+ function denormalizeSelectInPath(path, value) {
92
+ if (!lodash_1.default.isArray(path)) {
93
+ throw new Error("path must be array");
94
+ }
95
+ if (lodash_1.default.isPlainObject(value)) {
96
+ if ((0, utils_1.isQueryExpression)(value)) {
97
+ if (value["q/from"] === implicitSubQueryFromTag) {
98
+ return {
99
+ ...value,
100
+ "q/select": (0, exports.denormalizeSelect)(value["q/select"]),
101
+ "q/from": path,
102
+ };
103
+ }
104
+ else {
105
+ const details = JSON.stringify({
106
+ actual: value["q/from"],
107
+ expected: implicitSubQueryFromTag,
108
+ });
109
+ throw new Error(`strict array select invariant: ${details}`);
110
+ }
111
+ }
112
+ const denormalized = lodash_1.default.mapValues(value, (val, key) => {
113
+ if (key === exports.isSelectForMultiFieldKey) {
114
+ return key;
115
+ }
116
+ else if (value[exports.isSelectForMultiFieldKey]) {
117
+ return denormalizeSelectInPath([path, key], val);
118
+ }
119
+ else {
120
+ return denormalizeSelectInPath(path.concat([key]), val);
121
+ }
122
+ });
123
+ return lodash_1.default.omit(denormalized, exports.isSelectForMultiFieldKey);
124
+ }
125
+ if (path.length > 0 && (0, exports.isDynamicSelectLhs)(lodash_1.default.last(path)) && (0, exports.isDynamicSelectRhs)(value)) {
126
+ return value;
127
+ }
128
+ if (lodash_1.default.isString(value)) {
129
+ if (lodash_1.default.last(path) === value) {
130
+ return path;
131
+ }
132
+ else {
133
+ throw new Error(`strict select invariant: ${path[0]} !== ${value}`);
134
+ }
135
+ }
136
+ throw new Error("normalizedSelect invariant");
137
+ }
138
+ const denormalizeSelect = (normalizedSelect) => denormalizeSelectInPath([], normalizedSelect);
139
+ exports.denormalizeSelect = denormalizeSelect;
140
+ function mergeNormalizedSelects(normalizedSelects) {
141
+ return normalizedSelects.reduce((result, normalizedSelect) => {
142
+ Object.entries(normalizedSelect).forEach(([key, value]) => {
143
+ if (key in result) {
144
+ if (value !== result[key]) {
145
+ if (lodash_1.default.isPlainObject(value) && lodash_1.default.isPlainObject(result[key])) {
146
+ result[key] = mergeNormalizedSelects([value, result[key]]);
147
+ }
148
+ else if (key === "q/limit" && (value === "q/no-limit" || result[key] === "q/no-limit")) {
149
+ result[key] = "q/no-limit";
150
+ }
151
+ else if (key === "q/limit" && lodash_1.default.isNumber(value) && lodash_1.default.isNumber(result[key])) {
152
+ result[key] = value > result[key] ? value : result[key];
153
+ }
154
+ else if (!lodash_1.default.isArray(value) || !lodash_1.default.isEqual(value, result[key])) {
155
+ throw new Error(`merge selects invariant. ${JSON.stringify(value)} ${JSON.stringify(result[key])}`);
156
+ }
157
+ }
158
+ }
159
+ else {
160
+ result[key] = value;
161
+ }
162
+ });
163
+ return result;
164
+ }, {});
165
+ }
166
+ function mergeDenormalizedSelects(denormalizedSelects) {
167
+ const normalizedSelects = denormalizedSelects.map((denormalizedSelect) => (0, exports.normalizeSelect)(denormalizedSelect));
168
+ const normalizedSelect = mergeNormalizedSelects(normalizedSelects);
169
+ return (0, exports.denormalizeSelect)(normalizedSelect);
170
+ }
171
+ const addHole = function (holesByPath, path, lhs, rhs) {
172
+ if (!holesByPath[path]) {
173
+ holesByPath[path] = { path, normalizedSelect: {} };
174
+ }
175
+ holesByPath[path].normalizedSelect[lhs] = rhs;
176
+ };
177
+ const annotateNormalizedSelect = (normalizedSelect) => Object.entries(normalizedSelect)
178
+ .map(([lhs, rhs]) => {
179
+ if (lhs === exports.isSelectForMultiFieldKey) {
180
+ return null;
181
+ }
182
+ const rhsIsPlainObject = lodash_1.default.isPlainObject(rhs);
183
+ return {
184
+ lhs: {
185
+ value: lhs,
186
+ isDynamicSelect: (0, exports.isDynamicSelectLhs)(lhs),
187
+ },
188
+ rhs: {
189
+ value: rhs,
190
+ isDynamicSelect: (0, exports.isDynamicSelectRhs)(rhs),
191
+ isQueryExpression: (0, utils_1.isQueryExpression)(rhs),
192
+ isPlainObject: rhsIsPlainObject,
193
+ },
194
+ };
195
+ })
196
+ .filter(Boolean);
197
+ exports.annotateNormalizedSelect = annotateNormalizedSelect;
198
+ const pickAndTrack = function (input, annotatedNormalizedSelect, path, holesByPath) {
199
+ const output = {};
200
+ for (const annotatedItem of annotatedNormalizedSelect) {
201
+ const lhs = annotatedItem.lhs.value;
202
+ const rhs = annotatedItem.rhs.value;
203
+ const value = input[lhs];
204
+ if (value === undefined && !rhs[exports.isSelectForMultiFieldKey]) {
205
+ addHole(holesByPath, path, lhs, rhs);
206
+ }
207
+ else if (value === null) {
208
+ output[lhs] = value;
209
+ }
210
+ else {
211
+ if (lhs === rhs) {
212
+ output[lhs] = value;
213
+ }
214
+ else if (annotatedItem.rhs.isPlainObject) {
215
+ if (annotatedItem.rhs.isQueryExpression) {
216
+ (0, trace_1.assert)(Array.isArray(value));
217
+ // In case when normalizr schema does not contain a collection field, nothing will happen with normalized ids.
218
+ // See "denormalizeAndPickFields for unknown collection items" test.
219
+ // So we will get "Tasks": ["id1", "id2"], instead of denormalized objects.
220
+ // In this case we do not want to make holes and even include something in denormalized object.
221
+ // As schema was changed, data in component should be re-queried with new schema.
222
+ if (value.length === 0 || !value.every((x) => typeof x === "string")) {
223
+ output[lhs] = value.map((item, index) => pickAndTrack(item, (0, exports.annotateNormalizedSelect)(rhs["q/select"]), path.concat([lhs, index]), holesByPath));
224
+ }
225
+ }
226
+ else if (value instanceof Object && value.constructor === Object) {
227
+ output[lhs] = pickAndTrack(value, (0, exports.annotateNormalizedSelect)(rhs), path.concat(lhs), holesByPath);
228
+ }
229
+ }
230
+ else if (annotatedItem.lhs.isDynamicSelect && annotatedItem.rhs.isDynamicSelect) {
231
+ output[lhs] = value;
232
+ }
233
+ else {
234
+ throw new errors_1.NotImplementedError({ lhs, rhs }, "select");
235
+ }
236
+ }
237
+ }
238
+ return output;
239
+ };
240
+ const pickSelectedFields = (objects, normalizedSelect) => {
241
+ const annotatedNormalizedSelect = (0, exports.annotateNormalizedSelect)(normalizedSelect);
242
+ return objects.map((object) => {
243
+ const holesByPath = {};
244
+ return {
245
+ object: pickAndTrack(object, annotatedNormalizedSelect, [], holesByPath),
246
+ holes: Object.values(holesByPath),
247
+ };
248
+ });
249
+ };
250
+ exports.pickSelectedFields = pickSelectedFields;
251
+ const toSelectMapClause = (simpleFields) => {
252
+ (0, trace_1.assert)(lodash_1.default.isArray(simpleFields), "toSelectMapClause works with arrays");
253
+ return lodash_1.default.keyBy(simpleFields, lodash_1.default.identity);
254
+ };
255
+ exports.toSelectMapClause = toSelectMapClause;
256
+ function collectSelectTypes(typeObject, normalizedSelect, resultSet) {
257
+ for (const [field, rhs] of Object.entries(normalizedSelect)) {
258
+ if ((0, exports.isDynamicSelectLhs)(field) || field === exports.isSelectForMultiFieldKey) {
259
+ continue;
260
+ }
261
+ const fieldObject = typeObject.fieldObjectsByName[field];
262
+ if (!fieldObject) {
263
+ continue;
264
+ }
265
+ const fieldTypeObject = fieldObject.typeObject;
266
+ if (!fieldTypeObject.isPrimitive) {
267
+ if (fieldObject.isMultiField) {
268
+ for (const [typeForMulti, rhsForMulti] of Object.entries(rhs)) {
269
+ const fieldObjectForMulti = fieldObject.multiRelatedFieldObjects.find((f) => f.holderTypeObject.name === typeForMulti);
270
+ if (fieldObjectForMulti) {
271
+ resultSet.add(fieldObjectForMulti.holderTypeObject.name);
272
+ collectSelectTypes(fieldObjectForMulti.holderTypeObject, rhsForMulti, resultSet);
273
+ }
274
+ }
275
+ }
276
+ else {
277
+ resultSet.add(fieldTypeObject.name);
278
+ if (lodash_1.default.isPlainObject(rhs)) {
279
+ if (Object.hasOwn(rhs, "q/from") && lodash_1.default.isPlainObject(rhs["q/select"])) {
280
+ collectSelectTypes(fieldTypeObject, rhs["q/select"], resultSet);
281
+ }
282
+ else {
283
+ collectSelectTypes(fieldTypeObject, rhs, resultSet);
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ function calculateSelectedTypes(schema, query) {
291
+ const { "q/from": type, "q/select": select } = query;
292
+ const normalizedSelect = (0, exports.normalizeSelect)(select);
293
+ const typeObject = schema.typeObjectsByName[type];
294
+ const resultSet = new Set([type]);
295
+ collectSelectTypes(typeObject, normalizedSelect, resultSet);
296
+ return resultSet;
297
+ }
298
+ function calculateSelectedTypesFromQueries(schema, queries) {
299
+ return new Set(lodash_1.default.flatMap(queries, (query) => [...calculateSelectedTypes(schema, query)]));
300
+ }
@@ -0,0 +1 @@
1
+ export type $TSFixMe = any;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ import { $TSFixMe } from "./tsfixme";
2
+ export type Ref = {
3
+ "fibery/id": string;
4
+ };
5
+ type NestedArray<T> = Array<T | NestedArray<T>>;
6
+ export type Expression = NestedArray<string>;
7
+ type SelectPart = Record<string, Expression>;
8
+ export type Select = SelectPart | Record<string, SelectPart>;
9
+ export type OrderBy = Array<[Expression, string]>;
10
+ export type Query = {
11
+ "q/from": string;
12
+ "q/select"?: Select;
13
+ "q/offset"?: number;
14
+ "q/order-by"?: OrderBy;
15
+ "q/limit"?: number | "q/no-limit";
16
+ "q/where"?: NestedArray<unknown>;
17
+ };
18
+ export type QueryLimit = number | "q/no-limit";
19
+ export type SubQuery = {
20
+ "q/from": Expression;
21
+ "q/select"?: Select;
22
+ "q/offset"?: number;
23
+ "q/order-by"?: OrderBy;
24
+ "q/limit"?: QueryLimit;
25
+ "q/where"?: NestedArray<unknown>;
26
+ };
27
+ export type Params = Record<string, Expression | null>;
28
+ export interface Request {
29
+ query: Query;
30
+ params: Params;
31
+ }
32
+ export type Response = Record<string, $TSFixMe>[];
33
+ export type FiberyObject = Record<string, unknown>;
34
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@fibery/query-utils",
3
+ "version": "1.1.0",
4
+ "description": "Construct, normalize and denormalize Fibery core queries",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "files": [
8
+ "./lib"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./lib/index.d.ts",
13
+ "default": "./lib/index.js"
14
+ },
15
+ "./src/*": {
16
+ "types": "./lib/src/*.d.ts",
17
+ "default": "./lib/src/*.js"
18
+ }
19
+ },
20
+ "fiberyDevExports": {
21
+ ".": "./index.ts",
22
+ "./src/*": "./src/*"
23
+ },
24
+ "private": false,
25
+ "dependencies": {
26
+ "lodash": "4.17.21",
27
+ "memoize-one": "6.0.0",
28
+ "moment": "2.29.4",
29
+ "uuid": "11.1.0",
30
+ "@fibery/expression-utils": "9.6.0",
31
+ "@fibery/helpers": "1.4.0"
32
+ },
33
+ "devDependencies": {
34
+ "@babel/core": "7.28.5",
35
+ "@swc/jest": "0.2.39",
36
+ "@types/lodash": "4.14.172",
37
+ "jest": "30.2.0",
38
+ "jest-junit": "16.0.0",
39
+ "typescript": "5.9.3",
40
+ "@fibery/babel-preset": "7.4.1",
41
+ "@fibery/eslint-config": "8.6.2",
42
+ "@fibery/schema": "10.2.12"
43
+ },
44
+ "peerDependencies": {
45
+ "@fibery/schema": "10.2.12"
46
+ },
47
+ "jest": {
48
+ "testEnvironment": "node",
49
+ "coveragePathIgnorePatterns": [
50
+ "/node_modules/"
51
+ ],
52
+ "collectCoverageFrom": [
53
+ "src/**/*.{js,jsx,ts,tsx}",
54
+ "!src/**/*.d.ts"
55
+ ],
56
+ "coverageReporters": [
57
+ "text",
58
+ "cobertura"
59
+ ],
60
+ "testPathIgnorePatterns": [
61
+ "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
62
+ ],
63
+ "transform": {
64
+ "^.+\\.(js|jsx|ts|tsx)$": [
65
+ "@swc/jest",
66
+ {
67
+ "jsc": {
68
+ "parser": {
69
+ "syntax": "typescript",
70
+ "tsx": true,
71
+ "decorators": true,
72
+ "dynamicImport": true
73
+ },
74
+ "transform": {
75
+ "react": {
76
+ "runtime": "automatic"
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ]
82
+ },
83
+ "testEnvironmentOptions": {
84
+ "url": "http://localhost"
85
+ }
86
+ },
87
+ "scripts": {
88
+ "build": "rm -rf lib && pnpm exec tsc --project tsconfig.build.json",
89
+ "test": "jest",
90
+ "test:ci": "jest --reporters=default --reporters=jest-junit",
91
+ "test:coverage": "jest --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/formulas --reporters=default --reporters=jest-junit",
92
+ "lint": "eslint ."
93
+ }
94
+ }