blixify-server 0.3.1 → 0.3.3
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
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAwJD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,SAAM;IACX,WAAW,EAAE,GAAG,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAM;IAC7B,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACzC,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAgB3D,UAAU,SAAU,GAAG,SAIrB;IAEF,aAAa,YACF,GAAG,QACN,QAAQ,GAAG,QAAQ,GAAG,QAAQ,OAC/B,GAAG,UACA;QACN,GAAG,CAAC,EAAE,GAAG,CAAC;QACV,GAAG,CAAC,EAAE,GAAG,CAAC;KACX,mBA4DD;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAyE5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAkDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAuCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgKtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqGtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA0I5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAwCtC;IAEF,mBAAmB,CAAC,GAAG,EAAE,GAAG;IAiO5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBAgQlC;IAEF,IAAI,YAgFF;CACH"}
|
|
@@ -97,11 +97,20 @@ const handleParseQueryFilter = (queryList, prefix) => {
|
|
|
97
97
|
};
|
|
98
98
|
break;
|
|
99
99
|
case "exists":
|
|
100
|
-
// Check if field exists or not
|
|
101
100
|
queryValues[queryId] = {
|
|
102
|
-
$exists: value,
|
|
101
|
+
$exists: value,
|
|
103
102
|
};
|
|
104
103
|
break;
|
|
104
|
+
case ">size":
|
|
105
|
+
if (!queryValues["$expr"])
|
|
106
|
+
queryValues["$expr"] = {};
|
|
107
|
+
queryValues["$expr"]["$gt"] = [{ $size: `$${queryId}` }, value];
|
|
108
|
+
break;
|
|
109
|
+
case "<size":
|
|
110
|
+
if (!queryValues["$expr"])
|
|
111
|
+
queryValues["$expr"] = {};
|
|
112
|
+
queryValues["$expr"]["$lt"] = [{ $size: `$${queryId}` }, value];
|
|
113
|
+
break;
|
|
105
114
|
default:
|
|
106
115
|
break;
|
|
107
116
|
}
|
|
@@ -1089,13 +1098,15 @@ class MongoWrapper {
|
|
|
1089
1098
|
handleBuildPipeline(req) {
|
|
1090
1099
|
const pipelineList = [];
|
|
1091
1100
|
const addedForeignLookups = new Map();
|
|
1101
|
+
const addedSpaceReferences = new Set();
|
|
1092
1102
|
const { query, sort, cursor, limit, stopLimit, pipeline, uniqueLabel } = req.body;
|
|
1093
1103
|
try {
|
|
1094
1104
|
if (Array.isArray(pipeline) && pipeline.length > 0) {
|
|
1095
1105
|
pipeline.forEach((link) => {
|
|
1096
|
-
const { condition, referenceSpaceLabel, spaceReferenceId, spaceReferenceAs,
|
|
1106
|
+
const { condition, referenceSpaceLabel, spaceReferenceId, spaceReferenceAs, referenceSort, referenceFirstItem, referenceLimit, } = link;
|
|
1097
1107
|
if (spaceReferenceId) {
|
|
1098
1108
|
const defaultReferenceAs = spaceReferenceAs || "linkedData";
|
|
1109
|
+
addedSpaceReferences.add(defaultReferenceAs);
|
|
1099
1110
|
const lookupStage = {
|
|
1100
1111
|
$lookup: {
|
|
1101
1112
|
from: spaceReferenceId,
|
|
@@ -1157,51 +1168,50 @@ class MongoWrapper {
|
|
|
1157
1168
|
});
|
|
1158
1169
|
lookupStage.$lookup.pipeline.push(matchStage);
|
|
1159
1170
|
}
|
|
1160
|
-
pipelineList.push(lookupStage);
|
|
1161
1171
|
if (referenceSort && referenceSort.sortId) {
|
|
1162
|
-
|
|
1172
|
+
const sortStage = {
|
|
1163
1173
|
$sort: {
|
|
1164
|
-
[
|
|
1174
|
+
[referenceSort.sortId]: referenceSort.type === "asc" ? 1 : -1,
|
|
1165
1175
|
},
|
|
1166
|
-
}
|
|
1176
|
+
};
|
|
1177
|
+
lookupStage.$lookup.pipeline.push(sortStage);
|
|
1167
1178
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
}
|
|
1179
|
+
if (referenceLimit) {
|
|
1180
|
+
const limitStage = {
|
|
1181
|
+
$limit: referenceLimit,
|
|
1182
|
+
};
|
|
1183
|
+
lookupStage.$lookup.pipeline.push(limitStage);
|
|
1184
|
+
}
|
|
1185
|
+
pipelineList.push(lookupStage);
|
|
1174
1186
|
if (referenceSpaceLabel && referenceSpaceLabel.length > 0) {
|
|
1175
1187
|
const addFieldsStage = { $addFields: {} };
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1188
|
+
if (referenceFirstItem) {
|
|
1189
|
+
pipelineList.push({
|
|
1190
|
+
$addFields: {
|
|
1191
|
+
[defaultReferenceAs]: {
|
|
1192
|
+
$first: {
|
|
1193
|
+
$ifNull: [`$${defaultReferenceAs}`, []],
|
|
1194
|
+
},
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
});
|
|
1198
|
+
referenceSpaceLabel.forEach((field) => {
|
|
1199
|
+
addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] = `$${defaultReferenceAs}.${field}`;
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
referenceSpaceLabel.forEach((field) => {
|
|
1204
|
+
addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] =
|
|
1205
|
+
{
|
|
1206
|
+
$map: {
|
|
1207
|
+
input: `$${defaultReferenceAs}`,
|
|
1208
|
+
in: `$$this.${field}`,
|
|
1209
|
+
},
|
|
1210
|
+
};
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1179
1213
|
pipelineList.push(addFieldsStage);
|
|
1180
1214
|
}
|
|
1181
|
-
const groupStage = {
|
|
1182
|
-
$group: {
|
|
1183
|
-
_id: "$_id",
|
|
1184
|
-
originalData: { $first: "$$ROOT" },
|
|
1185
|
-
},
|
|
1186
|
-
};
|
|
1187
|
-
referenceSpaceLabel === null || referenceSpaceLabel === void 0 ? void 0 : referenceSpaceLabel.forEach((field) => {
|
|
1188
|
-
groupStage.$group[`${defaultReferenceAs}_${field}`] = {
|
|
1189
|
-
$push: `$${defaultReferenceAs}_${field}`,
|
|
1190
|
-
};
|
|
1191
|
-
});
|
|
1192
|
-
pipelineList.push(groupStage);
|
|
1193
|
-
// Merge back and remove 'originalData' and 'spaceReferenceAs'
|
|
1194
|
-
pipelineList.push({
|
|
1195
|
-
$replaceRoot: {
|
|
1196
|
-
newRoot: {
|
|
1197
|
-
$mergeObjects: ["$originalData", "$$ROOT"],
|
|
1198
|
-
},
|
|
1199
|
-
},
|
|
1200
|
-
});
|
|
1201
|
-
// Remove 'originalData' and 'spaceReferenceAs'
|
|
1202
|
-
pipelineList.push({
|
|
1203
|
-
$unset: ["originalData", spaceReferenceAs],
|
|
1204
|
-
});
|
|
1205
1215
|
}
|
|
1206
1216
|
});
|
|
1207
1217
|
}
|
|
@@ -1267,6 +1277,12 @@ class MongoWrapper {
|
|
|
1267
1277
|
$unset: [...foreignAliases],
|
|
1268
1278
|
});
|
|
1269
1279
|
}
|
|
1280
|
+
const spaceReferenceFields = Array.from(addedSpaceReferences);
|
|
1281
|
+
if (spaceReferenceFields.length > 0) {
|
|
1282
|
+
pipelineList.push({
|
|
1283
|
+
$unset: [...spaceReferenceFields],
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1270
1286
|
}
|
|
1271
1287
|
catch (err) { }
|
|
1272
1288
|
return pipelineList;
|
|
@@ -11,7 +11,7 @@ import SecurityConfig from "./SecurityConfig";
|
|
|
11
11
|
* @firebase - The moment search is used, sort is automatically disabled
|
|
12
12
|
*/
|
|
13
13
|
export interface Query {
|
|
14
|
-
type: "search" | "=" | "!=" | ">" | "<" | "><" | "in" | "!in" | "exists";
|
|
14
|
+
type: "search" | "=" | "!=" | ">" | "<" | "><" | "in" | "!in" | "exists" | ">size" | "<size";
|
|
15
15
|
value: any;
|
|
16
16
|
queryId?: string;
|
|
17
17
|
searchIds?: string[];
|
|
@@ -35,16 +35,20 @@ interface PipelineCondition {
|
|
|
35
35
|
* Only mongoDB is supported
|
|
36
36
|
* - condition : Condition that is applied to the reference collection
|
|
37
37
|
* - referenceSpaceLabel : Label fields of the reference collection that we wants to show.
|
|
38
|
+
* - referenceSort : Sort of the reference collection
|
|
39
|
+
* - referenceFirstItem : To show the first item of the reference collection only
|
|
40
|
+
* - referenceLimit : Limit the number of items to show from the reference collection
|
|
38
41
|
* - spaceReferenceId : Reference collection ID
|
|
39
42
|
* - spaceReferenceAs : Alias of the reference collection (any name can be given)
|
|
40
|
-
* - sort : Sort of the reference collection
|
|
41
43
|
*/
|
|
42
44
|
export interface PipeLine {
|
|
43
45
|
condition: PipelineCondition[];
|
|
44
46
|
referenceSpaceLabel: string[];
|
|
47
|
+
referenceSort?: Sort;
|
|
48
|
+
referenceFirstItem?: boolean;
|
|
49
|
+
referenceLimit?: number;
|
|
45
50
|
spaceReferenceId: string;
|
|
46
51
|
spaceReferenceAs: string;
|
|
47
|
-
sort: Sort;
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
54
|
* @SupportedAggregate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryModel.d.ts","sourceRoot":"","sources":["../../src/model/QueryModel.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,WAAW,KAAK;IACpB,IAAI,
|
|
1
|
+
{"version":3,"file":"QueryModel.d.ts","sourceRoot":"","sources":["../../src/model/QueryModel.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,WA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