venue-js 1.4.0-next.13 → 1.4.0-next.14
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/dist/data/index.d.mts +845 -0
- package/dist/data/index.d.ts +845 -0
- package/dist/data/index.js +2153 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/index.mjs +2116 -0
- package/dist/data/index.mjs.map +1 -0
- package/dist/index.d.mts +9 -844
- package/dist/index.d.ts +9 -844
- package/dist/index.js +7 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,2153 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/data/index.ts
|
|
20
|
+
var data_exports = {};
|
|
21
|
+
__export(data_exports, {
|
|
22
|
+
ALL_FEATURE_TYPES: () => ALL_FEATURE_TYPES,
|
|
23
|
+
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
24
|
+
GEOJSON_FEATURE_TYPES: () => GEOJSON_FEATURE_TYPES,
|
|
25
|
+
IMDF_FEATURE_TYPES: () => IMDF_FEATURE_TYPES,
|
|
26
|
+
NONIMDF_FEATURE_TYPES: () => NONIMDF_FEATURE_TYPES,
|
|
27
|
+
OccupantHelpers: () => occupant_helper_exports,
|
|
28
|
+
QueryObserver: () => import_query_core2.QueryObserver,
|
|
29
|
+
defaultFeatureQueryOptionsMap: () => defaultFeatureQueryOptionsMap,
|
|
30
|
+
fetchDeliveryApi: () => fetchDeliveryApi,
|
|
31
|
+
fetchPreviewApi: () => fetchPreviewApi,
|
|
32
|
+
getDataClient: () => getDataClient,
|
|
33
|
+
getSearchClient: () => getSearchClient,
|
|
34
|
+
isValidCoordinate: () => isValidCoordinate,
|
|
35
|
+
isValidLineString: () => isValidLineString,
|
|
36
|
+
isValidLineStringCoordinates: () => isValidLineStringCoordinates,
|
|
37
|
+
isValidMultiPolygon: () => isValidMultiPolygon,
|
|
38
|
+
isValidMultiPolygonCoordinates: () => isValidMultiPolygonCoordinates,
|
|
39
|
+
isValidPoint: () => isValidPoint,
|
|
40
|
+
isValidPolygon: () => isValidPolygon,
|
|
41
|
+
isValidPolygonCoordinates: () => isValidPolygonCoordinates,
|
|
42
|
+
matchFilter: () => matchFilter,
|
|
43
|
+
matchFilters: () => matchFilters,
|
|
44
|
+
safeFetchFeature: () => safeFetchFeature
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(data_exports);
|
|
47
|
+
var import_query_core2 = require("@tanstack/query-core");
|
|
48
|
+
|
|
49
|
+
// src/data/constant.ts
|
|
50
|
+
var DEFAULT_BASE_URL = "https://service.venue.in.th/api";
|
|
51
|
+
var IMDF_FEATURE_TYPES = [
|
|
52
|
+
"address",
|
|
53
|
+
"amenity",
|
|
54
|
+
"anchor",
|
|
55
|
+
"building",
|
|
56
|
+
"detail",
|
|
57
|
+
"fixture",
|
|
58
|
+
"footprint",
|
|
59
|
+
"geofence",
|
|
60
|
+
"kiosk",
|
|
61
|
+
"level",
|
|
62
|
+
"occupant",
|
|
63
|
+
"opening",
|
|
64
|
+
"relationship",
|
|
65
|
+
"section",
|
|
66
|
+
"unit",
|
|
67
|
+
"venue"
|
|
68
|
+
];
|
|
69
|
+
var NONIMDF_FEATURE_TYPES = [
|
|
70
|
+
"taxonomy",
|
|
71
|
+
"event",
|
|
72
|
+
"promotion",
|
|
73
|
+
"label",
|
|
74
|
+
"privilege"
|
|
75
|
+
];
|
|
76
|
+
var GEOJSON_FEATURE_TYPES = [
|
|
77
|
+
...IMDF_FEATURE_TYPES,
|
|
78
|
+
...NONIMDF_FEATURE_TYPES
|
|
79
|
+
];
|
|
80
|
+
var ALL_FEATURE_TYPES = [
|
|
81
|
+
...GEOJSON_FEATURE_TYPES,
|
|
82
|
+
"sponsored-content",
|
|
83
|
+
"element"
|
|
84
|
+
];
|
|
85
|
+
var defaultFeatureQueryOptionsMap = {
|
|
86
|
+
// IMDF
|
|
87
|
+
address: {},
|
|
88
|
+
amenity: {},
|
|
89
|
+
anchor: {},
|
|
90
|
+
building: {},
|
|
91
|
+
detail: { enabled: false },
|
|
92
|
+
fixture: {},
|
|
93
|
+
footprint: {},
|
|
94
|
+
geofence: { enabled: false },
|
|
95
|
+
kiosk: {},
|
|
96
|
+
level: {},
|
|
97
|
+
occupant: {
|
|
98
|
+
refetchInterval: 5 * 60 * 1e3,
|
|
99
|
+
// refresh every 5 min
|
|
100
|
+
staleTime: 5 * 60 * 1e3
|
|
101
|
+
},
|
|
102
|
+
opening: {},
|
|
103
|
+
relationship: {},
|
|
104
|
+
section: {},
|
|
105
|
+
unit: {},
|
|
106
|
+
venue: {},
|
|
107
|
+
// OTHERS GEOJSON
|
|
108
|
+
taxonomy: {},
|
|
109
|
+
privilege: {},
|
|
110
|
+
event: {},
|
|
111
|
+
promotion: {
|
|
112
|
+
refetchInterval: 0.5 * 60 * 1e3,
|
|
113
|
+
// refresh every 5 min
|
|
114
|
+
staleTime: 0.5 * 60 * 1e3
|
|
115
|
+
},
|
|
116
|
+
label: {},
|
|
117
|
+
// NON GEOJSON
|
|
118
|
+
"sponsored-content": {
|
|
119
|
+
refetchInterval: 1 * 60 * 1e3
|
|
120
|
+
// refresh every 5 min
|
|
121
|
+
},
|
|
122
|
+
element: {},
|
|
123
|
+
page: {},
|
|
124
|
+
model3d: {}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/data/api/delivery-project.ts
|
|
128
|
+
async function fetchDeliveryApi(projectId, apiKey, featureType, baseUrl = DEFAULT_BASE_URL) {
|
|
129
|
+
switch (featureType) {
|
|
130
|
+
case "label":
|
|
131
|
+
case "element": {
|
|
132
|
+
const pluralFeatureType = `${featureType}s`;
|
|
133
|
+
const res = await fetch(
|
|
134
|
+
`${baseUrl}/delivery/projects/${projectId}/${pluralFeatureType}.geojson?api-key=${apiKey}`
|
|
135
|
+
);
|
|
136
|
+
if (res.status !== 200) return [];
|
|
137
|
+
const items = await res.json();
|
|
138
|
+
return items;
|
|
139
|
+
}
|
|
140
|
+
case "model3d": {
|
|
141
|
+
const res = await fetch(
|
|
142
|
+
`${baseUrl}/delivery/projects/${projectId}/${featureType}.geojson?api-key=${apiKey}`
|
|
143
|
+
);
|
|
144
|
+
if (res.status !== 200) return [];
|
|
145
|
+
const items = await res.json();
|
|
146
|
+
return items.features;
|
|
147
|
+
}
|
|
148
|
+
case "sponsored-content": {
|
|
149
|
+
const res = await fetch(
|
|
150
|
+
`${baseUrl}/delivery/projects/${projectId}/sponsored-content.json?api-key=${apiKey}`
|
|
151
|
+
);
|
|
152
|
+
if (res.status !== 200) return [];
|
|
153
|
+
const jsonRes = await res.json();
|
|
154
|
+
const items = jsonRes.data;
|
|
155
|
+
return items.map((item) => ({
|
|
156
|
+
id: item.id,
|
|
157
|
+
...item.attributes
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
const res = await fetch(
|
|
162
|
+
`${baseUrl}/delivery/projects/${projectId}/imdf/${featureType}.geojson?api-key=${apiKey}`
|
|
163
|
+
);
|
|
164
|
+
if (res.status !== 200) return [];
|
|
165
|
+
const collections = await res.json();
|
|
166
|
+
return collections.features;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function fetchPreviewApi(projectId, previewToken, featureType, baseUrl = DEFAULT_BASE_URL) {
|
|
171
|
+
switch (featureType) {
|
|
172
|
+
case "label":
|
|
173
|
+
case "element": {
|
|
174
|
+
const pluralFeatureType = `${featureType}s`;
|
|
175
|
+
const res = await fetch(
|
|
176
|
+
`${baseUrl}/preview/projects/${projectId}/${pluralFeatureType}.geojson`,
|
|
177
|
+
{
|
|
178
|
+
headers: {
|
|
179
|
+
Authorization: `Bearer ${previewToken}`
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
if (res.status !== 200) return [];
|
|
184
|
+
const items = await res.json();
|
|
185
|
+
return items;
|
|
186
|
+
}
|
|
187
|
+
case "sponsored-content": {
|
|
188
|
+
const res = await fetch(
|
|
189
|
+
`${baseUrl}/preview/projects/${projectId}/sponsored-content.json`,
|
|
190
|
+
{
|
|
191
|
+
headers: {
|
|
192
|
+
Authorization: `Bearer ${previewToken}`
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
if (res.status !== 200) return [];
|
|
197
|
+
const jsonRes = await res.json();
|
|
198
|
+
const items = jsonRes.data;
|
|
199
|
+
return items.map((item) => ({
|
|
200
|
+
id: item.id,
|
|
201
|
+
...item.attributes
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
default: {
|
|
205
|
+
const res = await fetch(
|
|
206
|
+
`${baseUrl}/preview/projects/${projectId}/imdf/${featureType}.geojson`,
|
|
207
|
+
{
|
|
208
|
+
headers: {
|
|
209
|
+
Authorization: `Bearer ${previewToken}`
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
if (res.status !== 200) return [];
|
|
214
|
+
const collections = await res.json();
|
|
215
|
+
return collections.features;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
var safeFetchFeature = async (featureType, params) => {
|
|
220
|
+
const mode = params.mode ?? "delivery";
|
|
221
|
+
const projectId = params.projectId;
|
|
222
|
+
const apiKey = params.apiKey;
|
|
223
|
+
const previewToken = params.previewToken;
|
|
224
|
+
const baseUrl = params.baseUrl ?? DEFAULT_BASE_URL;
|
|
225
|
+
try {
|
|
226
|
+
let result = [];
|
|
227
|
+
if (mode === "delivery") {
|
|
228
|
+
result = await fetchDeliveryApi(
|
|
229
|
+
projectId,
|
|
230
|
+
apiKey,
|
|
231
|
+
featureType,
|
|
232
|
+
baseUrl
|
|
233
|
+
);
|
|
234
|
+
} else if (mode === "preview") {
|
|
235
|
+
result = await fetchPreviewApi(
|
|
236
|
+
projectId,
|
|
237
|
+
previewToken,
|
|
238
|
+
featureType,
|
|
239
|
+
baseUrl
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return result ?? [];
|
|
243
|
+
} catch (e) {
|
|
244
|
+
return Promise.resolve([]);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// src/data/utils/geometry-validator.ts
|
|
249
|
+
var isValidCoordinate = (point) => {
|
|
250
|
+
return point.length === 2 && point.every((coord) => typeof coord === "number");
|
|
251
|
+
};
|
|
252
|
+
function isValidLinearRingCoordinates(ring) {
|
|
253
|
+
if (ring.length < 4) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
return ring.every(isValidCoordinate) && ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][1];
|
|
257
|
+
}
|
|
258
|
+
var isValidPolygonCoordinates = (polygon) => {
|
|
259
|
+
if (Array.isArray(polygon[0]) && (polygon[0].length === 0 || typeof polygon[0][0] === "number")) {
|
|
260
|
+
return isValidLinearRingCoordinates(polygon);
|
|
261
|
+
}
|
|
262
|
+
if (Array.isArray(polygon) && polygon.length > 0 && Array.isArray(polygon[0])) {
|
|
263
|
+
if (!isValidLinearRingCoordinates(polygon[0])) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
for (let i = 1; i < polygon.length; i++) {
|
|
267
|
+
if (!isValidLinearRingCoordinates(polygon[i])) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
};
|
|
275
|
+
var isValidMultiPolygonCoordinates = (multipolygon) => {
|
|
276
|
+
return multipolygon.every(isValidPolygonCoordinates);
|
|
277
|
+
};
|
|
278
|
+
var isValidLineStringCoordinates = (lineString) => {
|
|
279
|
+
if (!Array.isArray(lineString) || lineString.length < 2) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const firstPoint = lineString[0];
|
|
283
|
+
const lastPoint = lineString[lineString.length - 1];
|
|
284
|
+
if (firstPoint[0] === lastPoint[0] && firstPoint[1] === lastPoint[1]) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return lineString.every(isValidCoordinate);
|
|
288
|
+
};
|
|
289
|
+
var isValidMultiPolygon = (geometry) => {
|
|
290
|
+
const { type, coordinates } = geometry;
|
|
291
|
+
return type === "MultiPolygon" && isValidMultiPolygonCoordinates(coordinates);
|
|
292
|
+
};
|
|
293
|
+
var isValidPolygon = (geometry) => {
|
|
294
|
+
const { type, coordinates } = geometry;
|
|
295
|
+
return type === "Polygon" && isValidPolygonCoordinates(coordinates);
|
|
296
|
+
};
|
|
297
|
+
var isValidLineString = (geometry) => {
|
|
298
|
+
const { type, coordinates } = geometry;
|
|
299
|
+
return type === "LineString" && isValidLineStringCoordinates(coordinates);
|
|
300
|
+
};
|
|
301
|
+
var isValidPoint = (geometry) => {
|
|
302
|
+
const { type, coordinates } = geometry;
|
|
303
|
+
return type === "Point" && isValidCoordinate(coordinates);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/data/utils/match-filters.ts
|
|
307
|
+
function isInFilter(filter) {
|
|
308
|
+
return typeof filter === "object" && filter !== null && "$in" in filter && Array.isArray(filter.$in);
|
|
309
|
+
}
|
|
310
|
+
var someIntersect = (a, b) => a.some((v) => b.includes(v));
|
|
311
|
+
function matchFilter(value, filter) {
|
|
312
|
+
if (Array.isArray(value)) {
|
|
313
|
+
if (isInFilter(filter)) return someIntersect(value, filter.$in);
|
|
314
|
+
return value.includes(filter);
|
|
315
|
+
} else {
|
|
316
|
+
if (isInFilter(filter)) return filter.$in.includes(value);
|
|
317
|
+
return value === filter;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function matchFilters(item, filters) {
|
|
321
|
+
return Object.entries(filters).every(([key, filter]) => {
|
|
322
|
+
return matchFilter(item.properties[key], filter);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/data/utils/occupant-helper.ts
|
|
327
|
+
var occupant_helper_exports = {};
|
|
328
|
+
__export(occupant_helper_exports, {
|
|
329
|
+
getOccupantCorrelatedLocations: () => getOccupantCorrelatedLocations,
|
|
330
|
+
getOccupantMainLocation: () => getOccupantMainLocation,
|
|
331
|
+
getOccupantMarkerLocations: () => getOccupantMarkerLocations
|
|
332
|
+
});
|
|
333
|
+
var import_lodash = require("lodash");
|
|
334
|
+
var getOccupantMainLocation = (occupant) => {
|
|
335
|
+
return occupant.properties.kiosk || occupant.properties.unit;
|
|
336
|
+
};
|
|
337
|
+
var getOccupantCorrelatedLocations = (occupant) => {
|
|
338
|
+
const allCorrelatedLocations = [
|
|
339
|
+
...occupant.properties.units,
|
|
340
|
+
...occupant.properties.kiosks
|
|
341
|
+
];
|
|
342
|
+
return (0, import_lodash.compact)(allCorrelatedLocations);
|
|
343
|
+
};
|
|
344
|
+
var getOccupantMarkerLocations = (occupant, options) => {
|
|
345
|
+
const placementType = options?.type ? options.type : occupant.properties.show_name_on_all_units ? "ALL_LOCATIONS" : "ONCE_PER_LEVEL";
|
|
346
|
+
const mainLocation = getOccupantMainLocation(occupant);
|
|
347
|
+
const mainLocationLevel = mainLocation?.properties?.level_id;
|
|
348
|
+
const allCorrelatedLocations = getOccupantCorrelatedLocations(occupant);
|
|
349
|
+
if (placementType === "ALL_LOCATIONS") {
|
|
350
|
+
return (0, import_lodash.compact)([mainLocation, ...allCorrelatedLocations]);
|
|
351
|
+
}
|
|
352
|
+
const otherLevelLocations = allCorrelatedLocations.filter((f) => f.properties.level_id !== mainLocationLevel);
|
|
353
|
+
const onePerLevelLocations = [...new Map(otherLevelLocations.map((loc) => [loc.properties.level_id, loc])).values()];
|
|
354
|
+
return (0, import_lodash.compact)([mainLocation, ...onePerLevelLocations]);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// src/data/getDataClient.ts
|
|
358
|
+
var import_query_core = require("@tanstack/query-core");
|
|
359
|
+
|
|
360
|
+
// src/data/populator/index.ts
|
|
361
|
+
var import_lodash2 = require("lodash");
|
|
362
|
+
var import_boolean_within = require("@turf/boolean-within");
|
|
363
|
+
var createPopulator = ({
|
|
364
|
+
internalFindById,
|
|
365
|
+
internalFilterByType
|
|
366
|
+
}) => {
|
|
367
|
+
const populateAddress = (address) => Promise.resolve(address);
|
|
368
|
+
const populateBuilding = (building) => Promise.resolve(building);
|
|
369
|
+
const populateDetail = (detail) => Promise.resolve(detail);
|
|
370
|
+
const populateFootprint = (footprint) => Promise.resolve(footprint);
|
|
371
|
+
const populateGeofence = (geofence) => Promise.resolve(geofence);
|
|
372
|
+
const populateRelationship = (relationship) => Promise.resolve(relationship);
|
|
373
|
+
const populatePrivilege = (privilege) => Promise.resolve(privilege);
|
|
374
|
+
const populateEvent = (event) => Promise.resolve(event);
|
|
375
|
+
const populatePromotion = async (promotion) => {
|
|
376
|
+
const venue = await internalFindById(promotion.properties.venue_id);
|
|
377
|
+
return {
|
|
378
|
+
...promotion,
|
|
379
|
+
properties: {
|
|
380
|
+
...promotion.properties,
|
|
381
|
+
venue
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
const populateAmenity = async (amenity) => {
|
|
386
|
+
const units = await Promise.all(
|
|
387
|
+
amenity.properties.unit_ids.map(internalFindById)
|
|
388
|
+
);
|
|
389
|
+
const populatedUnits = await Promise.all(units.map(populateUnit));
|
|
390
|
+
const venue = await internalFindById(amenity.properties.venue_id);
|
|
391
|
+
const defaultLevel = populatedUnits[0].properties.level;
|
|
392
|
+
const kiosks = await internalFilterByType("kiosk");
|
|
393
|
+
const ordinalKiosks = kiosks.filter(
|
|
394
|
+
(kiosk2) => kiosk2.properties.level_id === defaultLevel.id
|
|
395
|
+
);
|
|
396
|
+
const kiosk = ordinalKiosks.find((kiosk2) => (0, import_boolean_within.booleanWithin)(amenity, kiosk2));
|
|
397
|
+
return {
|
|
398
|
+
...amenity,
|
|
399
|
+
properties: {
|
|
400
|
+
...amenity.properties,
|
|
401
|
+
ordinal: defaultLevel.properties.ordinal,
|
|
402
|
+
level_name: defaultLevel.properties.name.en,
|
|
403
|
+
level: defaultLevel,
|
|
404
|
+
units: populatedUnits,
|
|
405
|
+
venue,
|
|
406
|
+
_experimental_kiosk: kiosk ? await populateKiosk(kiosk) : null
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
const populateAnchor = async (anchor) => {
|
|
411
|
+
const unit = await internalFindById(anchor.properties.unit_id);
|
|
412
|
+
const venue = await internalFindById(unit.properties.venue_id);
|
|
413
|
+
const level = await internalFindById(unit.properties.level_id);
|
|
414
|
+
const sections = await internalFilterByType("section");
|
|
415
|
+
const section = sections.find((section2) => (0, import_boolean_within.booleanWithin)(anchor, section2));
|
|
416
|
+
return {
|
|
417
|
+
...anchor,
|
|
418
|
+
properties: {
|
|
419
|
+
...anchor.properties,
|
|
420
|
+
level: await populateLevel(level),
|
|
421
|
+
unit: await populateUnit(unit),
|
|
422
|
+
section: section ? await populateSection(section) : null,
|
|
423
|
+
venue: await populateVenue(venue),
|
|
424
|
+
ordinal: level.properties.ordinal
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
const populateFixture = async (fixture) => {
|
|
429
|
+
const level = await internalFindById(fixture.properties.level_id);
|
|
430
|
+
const venue = await internalFindById(fixture.properties.venue_id);
|
|
431
|
+
const anchor = await internalFindById(fixture.properties.anchor_id);
|
|
432
|
+
return {
|
|
433
|
+
...fixture,
|
|
434
|
+
properties: {
|
|
435
|
+
...fixture.properties,
|
|
436
|
+
anchor: anchor ? await populateAnchor(anchor) : null,
|
|
437
|
+
level: await populateLevel(level),
|
|
438
|
+
venue: await populateVenue(venue),
|
|
439
|
+
ordinal: level.properties.ordinal
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
const populateKiosk = async (kiosk) => {
|
|
444
|
+
const level = await internalFindById(kiosk.properties.level_id);
|
|
445
|
+
const venue = await internalFindById(kiosk.properties.venue_id);
|
|
446
|
+
const anchor = await internalFindById(kiosk.properties.anchor_id);
|
|
447
|
+
const units = await internalFilterByType("unit");
|
|
448
|
+
const unit = units.find(
|
|
449
|
+
(unit2) => {
|
|
450
|
+
try {
|
|
451
|
+
return unit2.properties.category === "walkway" && unit2.properties.level_id === kiosk.properties.level_id && (0, import_boolean_within.booleanWithin)(kiosk, unit2);
|
|
452
|
+
} catch (e) {
|
|
453
|
+
console.log(`Cannot find kiosk(${kiosk.id})'s units:`, e.message);
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
);
|
|
458
|
+
let section = null;
|
|
459
|
+
if (anchor) {
|
|
460
|
+
const sections = await internalFilterByType("section");
|
|
461
|
+
section = sections.find((section2) => (0, import_boolean_within.booleanWithin)(anchor, section2));
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
...kiosk,
|
|
465
|
+
properties: {
|
|
466
|
+
...kiosk.properties,
|
|
467
|
+
anchor: anchor ? await populateAnchor(anchor) : null,
|
|
468
|
+
level: await populateLevel(level),
|
|
469
|
+
venue: await populateVenue(venue),
|
|
470
|
+
ordinal: level.properties.ordinal,
|
|
471
|
+
unit: unit ? await populateUnit(unit) : null,
|
|
472
|
+
section: section ? await populateSection(section) : null
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
const populateLevel = async (level) => {
|
|
477
|
+
const venue = await internalFindById(level.properties.venue_id);
|
|
478
|
+
return {
|
|
479
|
+
...level,
|
|
480
|
+
properties: {
|
|
481
|
+
...level.properties,
|
|
482
|
+
venue
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
const populateOccupant = async (occupant) => {
|
|
487
|
+
const {
|
|
488
|
+
anchor_id,
|
|
489
|
+
venue_id,
|
|
490
|
+
local_category_ids,
|
|
491
|
+
promotion_ids = [],
|
|
492
|
+
privilege_ids = [],
|
|
493
|
+
kiosk_id,
|
|
494
|
+
unit_id,
|
|
495
|
+
kiosk_ids = [],
|
|
496
|
+
unit_ids = []
|
|
497
|
+
} = occupant.properties;
|
|
498
|
+
const anchor = await internalFindById(anchor_id);
|
|
499
|
+
const venue = await internalFindById(venue_id);
|
|
500
|
+
const localCategories = await Promise.all(
|
|
501
|
+
local_category_ids.map(internalFindById)
|
|
502
|
+
);
|
|
503
|
+
const promotions = await Promise.all(
|
|
504
|
+
promotion_ids.map(internalFindById)
|
|
505
|
+
);
|
|
506
|
+
const privileges = await Promise.all(
|
|
507
|
+
privilege_ids.map(internalFindById)
|
|
508
|
+
);
|
|
509
|
+
const kiosk = await internalFindById(kiosk_id);
|
|
510
|
+
const unit = await internalFindById(unit_id);
|
|
511
|
+
const kiosks = await Promise.all(kiosk_ids.map(internalFindById));
|
|
512
|
+
const units = await Promise.all(unit_ids.map(internalFindById));
|
|
513
|
+
return {
|
|
514
|
+
...occupant,
|
|
515
|
+
properties: {
|
|
516
|
+
...occupant.properties,
|
|
517
|
+
anchor: anchor ? await populateAnchor(anchor) : null,
|
|
518
|
+
local_categories: await Promise.all(
|
|
519
|
+
(0, import_lodash2.compact)(localCategories).map(populateTaxonomy)
|
|
520
|
+
),
|
|
521
|
+
venue,
|
|
522
|
+
promotions,
|
|
523
|
+
privileges,
|
|
524
|
+
kiosk: kiosk ? await populateKiosk(kiosk) : null,
|
|
525
|
+
unit: unit ? await populateUnit(unit) : null,
|
|
526
|
+
kiosks: await Promise.all(kiosks.map(populateKiosk)),
|
|
527
|
+
units: await Promise.all(units.map(populateUnit))
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
const populateOpening = async (opening) => {
|
|
532
|
+
const venue = await internalFindById(opening.properties.venue_id);
|
|
533
|
+
const level = await internalFindById(opening.properties.level_id);
|
|
534
|
+
return {
|
|
535
|
+
...opening,
|
|
536
|
+
properties: {
|
|
537
|
+
venue,
|
|
538
|
+
level: await populateLevel(level),
|
|
539
|
+
ordinal: level.properties.ordinal
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
};
|
|
543
|
+
const populateSection = async (section) => {
|
|
544
|
+
const venue = await internalFindById(section.properties.venue_id);
|
|
545
|
+
const level = await internalFindById(section.properties.level_id);
|
|
546
|
+
return {
|
|
547
|
+
...section,
|
|
548
|
+
properties: {
|
|
549
|
+
...section.properties,
|
|
550
|
+
venue,
|
|
551
|
+
level: await populateLevel(level),
|
|
552
|
+
ordinal: level.properties.ordinal
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
const populateUnit = async (unit) => {
|
|
557
|
+
const venue = await internalFindById(unit.properties.venue_id);
|
|
558
|
+
const level = await internalFindById(unit.properties.level_id);
|
|
559
|
+
const sections = await internalFilterByType("section");
|
|
560
|
+
try {
|
|
561
|
+
const section = unit.geometry.type !== "MultiPolygon" ? sections.find((section2) => (0, import_boolean_within.booleanWithin)(unit, section2)) : null;
|
|
562
|
+
return {
|
|
563
|
+
...unit,
|
|
564
|
+
properties: {
|
|
565
|
+
...unit.properties,
|
|
566
|
+
venue,
|
|
567
|
+
ordinal: level.properties.ordinal,
|
|
568
|
+
level: await populateLevel(level),
|
|
569
|
+
section: section ? await populateSection(section) : null
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
} catch (err) {
|
|
573
|
+
console.log(`error finding section `, { unit, sections });
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const populateVenue = (venue) => {
|
|
577
|
+
return Promise.resolve(venue);
|
|
578
|
+
};
|
|
579
|
+
const populateTaxonomy = async (taxonomy) => {
|
|
580
|
+
const venue = await internalFindById(taxonomy.properties.venue_id);
|
|
581
|
+
return {
|
|
582
|
+
...taxonomy,
|
|
583
|
+
properties: {
|
|
584
|
+
...taxonomy.properties,
|
|
585
|
+
venue: venue ? await populateVenue(venue) : null
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
};
|
|
589
|
+
const populateModel3D = async (model3d) => {
|
|
590
|
+
const level = await internalFindById(model3d.properties.level_id);
|
|
591
|
+
try {
|
|
592
|
+
return {
|
|
593
|
+
...model3d,
|
|
594
|
+
properties: {
|
|
595
|
+
...model3d.properties,
|
|
596
|
+
level: await populateLevel(level)
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
} catch (err) {
|
|
600
|
+
console.log(`error finding level`, { model3d, level });
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const populateFeature = (feature) => Promise.resolve(feature);
|
|
604
|
+
return {
|
|
605
|
+
address: populateAddress,
|
|
606
|
+
building: populateBuilding,
|
|
607
|
+
detail: populateDetail,
|
|
608
|
+
fixture: populateFixture,
|
|
609
|
+
footprint: populateFootprint,
|
|
610
|
+
geofence: populateGeofence,
|
|
611
|
+
opening: populateOpening,
|
|
612
|
+
relationship: populateRelationship,
|
|
613
|
+
privilege: populatePrivilege,
|
|
614
|
+
promotion: populatePromotion,
|
|
615
|
+
event: populateEvent,
|
|
616
|
+
label: populateFeature,
|
|
617
|
+
element: populateFeature,
|
|
618
|
+
page: populateFeature,
|
|
619
|
+
amenity: populateAmenity,
|
|
620
|
+
anchor: populateAnchor,
|
|
621
|
+
kiosk: populateKiosk,
|
|
622
|
+
level: populateLevel,
|
|
623
|
+
occupant: populateOccupant,
|
|
624
|
+
section: populateSection,
|
|
625
|
+
unit: populateUnit,
|
|
626
|
+
venue: populateVenue,
|
|
627
|
+
taxonomy: populateTaxonomy,
|
|
628
|
+
model3d: populateModel3D
|
|
629
|
+
};
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// ../../node_modules/fuse.js/dist/fuse.mjs
|
|
633
|
+
function isArray(value) {
|
|
634
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
635
|
+
}
|
|
636
|
+
var INFINITY = 1 / 0;
|
|
637
|
+
function baseToString(value) {
|
|
638
|
+
if (typeof value == "string") {
|
|
639
|
+
return value;
|
|
640
|
+
}
|
|
641
|
+
let result = value + "";
|
|
642
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
643
|
+
}
|
|
644
|
+
function toString(value) {
|
|
645
|
+
return value == null ? "" : baseToString(value);
|
|
646
|
+
}
|
|
647
|
+
function isString(value) {
|
|
648
|
+
return typeof value === "string";
|
|
649
|
+
}
|
|
650
|
+
function isNumber(value) {
|
|
651
|
+
return typeof value === "number";
|
|
652
|
+
}
|
|
653
|
+
function isBoolean(value) {
|
|
654
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
655
|
+
}
|
|
656
|
+
function isObject(value) {
|
|
657
|
+
return typeof value === "object";
|
|
658
|
+
}
|
|
659
|
+
function isObjectLike(value) {
|
|
660
|
+
return isObject(value) && value !== null;
|
|
661
|
+
}
|
|
662
|
+
function isDefined(value) {
|
|
663
|
+
return value !== void 0 && value !== null;
|
|
664
|
+
}
|
|
665
|
+
function isBlank(value) {
|
|
666
|
+
return !value.trim().length;
|
|
667
|
+
}
|
|
668
|
+
function getTag(value) {
|
|
669
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
670
|
+
}
|
|
671
|
+
var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
672
|
+
var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
673
|
+
var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
|
|
674
|
+
var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
675
|
+
var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
676
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
677
|
+
var KeyStore = class {
|
|
678
|
+
constructor(keys) {
|
|
679
|
+
this._keys = [];
|
|
680
|
+
this._keyMap = {};
|
|
681
|
+
let totalWeight = 0;
|
|
682
|
+
keys.forEach((key) => {
|
|
683
|
+
let obj = createKey(key);
|
|
684
|
+
this._keys.push(obj);
|
|
685
|
+
this._keyMap[obj.id] = obj;
|
|
686
|
+
totalWeight += obj.weight;
|
|
687
|
+
});
|
|
688
|
+
this._keys.forEach((key) => {
|
|
689
|
+
key.weight /= totalWeight;
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
get(keyId) {
|
|
693
|
+
return this._keyMap[keyId];
|
|
694
|
+
}
|
|
695
|
+
keys() {
|
|
696
|
+
return this._keys;
|
|
697
|
+
}
|
|
698
|
+
toJSON() {
|
|
699
|
+
return JSON.stringify(this._keys);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
function createKey(key) {
|
|
703
|
+
let path = null;
|
|
704
|
+
let id = null;
|
|
705
|
+
let src = null;
|
|
706
|
+
let weight = 1;
|
|
707
|
+
let getFn = null;
|
|
708
|
+
if (isString(key) || isArray(key)) {
|
|
709
|
+
src = key;
|
|
710
|
+
path = createKeyPath(key);
|
|
711
|
+
id = createKeyId(key);
|
|
712
|
+
} else {
|
|
713
|
+
if (!hasOwn.call(key, "name")) {
|
|
714
|
+
throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
715
|
+
}
|
|
716
|
+
const name = key.name;
|
|
717
|
+
src = name;
|
|
718
|
+
if (hasOwn.call(key, "weight")) {
|
|
719
|
+
weight = key.weight;
|
|
720
|
+
if (weight <= 0) {
|
|
721
|
+
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
path = createKeyPath(name);
|
|
725
|
+
id = createKeyId(name);
|
|
726
|
+
getFn = key.getFn;
|
|
727
|
+
}
|
|
728
|
+
return { path, id, weight, src, getFn };
|
|
729
|
+
}
|
|
730
|
+
function createKeyPath(key) {
|
|
731
|
+
return isArray(key) ? key : key.split(".");
|
|
732
|
+
}
|
|
733
|
+
function createKeyId(key) {
|
|
734
|
+
return isArray(key) ? key.join(".") : key;
|
|
735
|
+
}
|
|
736
|
+
function get(obj, path) {
|
|
737
|
+
let list = [];
|
|
738
|
+
let arr = false;
|
|
739
|
+
const deepGet = (obj2, path2, index) => {
|
|
740
|
+
if (!isDefined(obj2)) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (!path2[index]) {
|
|
744
|
+
list.push(obj2);
|
|
745
|
+
} else {
|
|
746
|
+
let key = path2[index];
|
|
747
|
+
const value = obj2[key];
|
|
748
|
+
if (!isDefined(value)) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
752
|
+
list.push(toString(value));
|
|
753
|
+
} else if (isArray(value)) {
|
|
754
|
+
arr = true;
|
|
755
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
756
|
+
deepGet(value[i], path2, index + 1);
|
|
757
|
+
}
|
|
758
|
+
} else if (path2.length) {
|
|
759
|
+
deepGet(value, path2, index + 1);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
764
|
+
return arr ? list : list[0];
|
|
765
|
+
}
|
|
766
|
+
var MatchOptions = {
|
|
767
|
+
// Whether the matches should be included in the result set. When `true`, each record in the result
|
|
768
|
+
// set will include the indices of the matched characters.
|
|
769
|
+
// These can consequently be used for highlighting purposes.
|
|
770
|
+
includeMatches: false,
|
|
771
|
+
// When `true`, the matching function will continue to the end of a search pattern even if
|
|
772
|
+
// a perfect match has already been located in the string.
|
|
773
|
+
findAllMatches: false,
|
|
774
|
+
// Minimum number of characters that must be matched before a result is considered a match
|
|
775
|
+
minMatchCharLength: 1
|
|
776
|
+
};
|
|
777
|
+
var BasicOptions = {
|
|
778
|
+
// When `true`, the algorithm continues searching to the end of the input even if a perfect
|
|
779
|
+
// match is found before the end of the same input.
|
|
780
|
+
isCaseSensitive: false,
|
|
781
|
+
// When `true`, the algorithm will ignore diacritics (accents) in comparisons
|
|
782
|
+
ignoreDiacritics: false,
|
|
783
|
+
// When true, the matching function will continue to the end of a search pattern even if
|
|
784
|
+
includeScore: false,
|
|
785
|
+
// List of properties that will be searched. This also supports nested properties.
|
|
786
|
+
keys: [],
|
|
787
|
+
// Whether to sort the result list, by score
|
|
788
|
+
shouldSort: true,
|
|
789
|
+
// Default sort function: sort by ascending score, ascending index
|
|
790
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
791
|
+
};
|
|
792
|
+
var FuzzyOptions = {
|
|
793
|
+
// Approximately where in the text is the pattern expected to be found?
|
|
794
|
+
location: 0,
|
|
795
|
+
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
|
|
796
|
+
// (of both letters and location), a threshold of '1.0' would match anything.
|
|
797
|
+
threshold: 0.6,
|
|
798
|
+
// Determines how close the match must be to the fuzzy location (specified above).
|
|
799
|
+
// An exact letter match which is 'distance' characters away from the fuzzy location
|
|
800
|
+
// would score as a complete mismatch. A distance of '0' requires the match be at
|
|
801
|
+
// the exact location specified, a threshold of '1000' would require a perfect match
|
|
802
|
+
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
803
|
+
distance: 100
|
|
804
|
+
};
|
|
805
|
+
var AdvancedOptions = {
|
|
806
|
+
// When `true`, it enables the use of unix-like search commands
|
|
807
|
+
useExtendedSearch: false,
|
|
808
|
+
// The get function to use when fetching an object's properties.
|
|
809
|
+
// The default will search nested paths *ie foo.bar.baz*
|
|
810
|
+
getFn: get,
|
|
811
|
+
// When `true`, search will ignore `location` and `distance`, so it won't matter
|
|
812
|
+
// where in the string the pattern appears.
|
|
813
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
|
|
814
|
+
ignoreLocation: false,
|
|
815
|
+
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
816
|
+
// ignore the field-length norm.
|
|
817
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
818
|
+
ignoreFieldNorm: false,
|
|
819
|
+
// The weight to determine how much field length norm effects scoring.
|
|
820
|
+
fieldNormWeight: 1
|
|
821
|
+
};
|
|
822
|
+
var Config = {
|
|
823
|
+
...BasicOptions,
|
|
824
|
+
...MatchOptions,
|
|
825
|
+
...FuzzyOptions,
|
|
826
|
+
...AdvancedOptions
|
|
827
|
+
};
|
|
828
|
+
var SPACE = /[^ ]+/g;
|
|
829
|
+
function norm(weight = 1, mantissa = 3) {
|
|
830
|
+
const cache = /* @__PURE__ */ new Map();
|
|
831
|
+
const m = Math.pow(10, mantissa);
|
|
832
|
+
return {
|
|
833
|
+
get(value) {
|
|
834
|
+
const numTokens = value.match(SPACE).length;
|
|
835
|
+
if (cache.has(numTokens)) {
|
|
836
|
+
return cache.get(numTokens);
|
|
837
|
+
}
|
|
838
|
+
const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
839
|
+
const n = parseFloat(Math.round(norm2 * m) / m);
|
|
840
|
+
cache.set(numTokens, n);
|
|
841
|
+
return n;
|
|
842
|
+
},
|
|
843
|
+
clear() {
|
|
844
|
+
cache.clear();
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
var FuseIndex = class {
|
|
849
|
+
constructor({
|
|
850
|
+
getFn = Config.getFn,
|
|
851
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
852
|
+
} = {}) {
|
|
853
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
854
|
+
this.getFn = getFn;
|
|
855
|
+
this.isCreated = false;
|
|
856
|
+
this.setIndexRecords();
|
|
857
|
+
}
|
|
858
|
+
setSources(docs = []) {
|
|
859
|
+
this.docs = docs;
|
|
860
|
+
}
|
|
861
|
+
setIndexRecords(records = []) {
|
|
862
|
+
this.records = records;
|
|
863
|
+
}
|
|
864
|
+
setKeys(keys = []) {
|
|
865
|
+
this.keys = keys;
|
|
866
|
+
this._keysMap = {};
|
|
867
|
+
keys.forEach((key, idx) => {
|
|
868
|
+
this._keysMap[key.id] = idx;
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
create() {
|
|
872
|
+
if (this.isCreated || !this.docs.length) {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
this.isCreated = true;
|
|
876
|
+
if (isString(this.docs[0])) {
|
|
877
|
+
this.docs.forEach((doc, docIndex) => {
|
|
878
|
+
this._addString(doc, docIndex);
|
|
879
|
+
});
|
|
880
|
+
} else {
|
|
881
|
+
this.docs.forEach((doc, docIndex) => {
|
|
882
|
+
this._addObject(doc, docIndex);
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
this.norm.clear();
|
|
886
|
+
}
|
|
887
|
+
// Adds a doc to the end of the index
|
|
888
|
+
add(doc) {
|
|
889
|
+
const idx = this.size();
|
|
890
|
+
if (isString(doc)) {
|
|
891
|
+
this._addString(doc, idx);
|
|
892
|
+
} else {
|
|
893
|
+
this._addObject(doc, idx);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
// Removes the doc at the specified index of the index
|
|
897
|
+
removeAt(idx) {
|
|
898
|
+
this.records.splice(idx, 1);
|
|
899
|
+
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
900
|
+
this.records[i].i -= 1;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
getValueForItemAtKeyId(item, keyId) {
|
|
904
|
+
return item[this._keysMap[keyId]];
|
|
905
|
+
}
|
|
906
|
+
size() {
|
|
907
|
+
return this.records.length;
|
|
908
|
+
}
|
|
909
|
+
_addString(doc, docIndex) {
|
|
910
|
+
if (!isDefined(doc) || isBlank(doc)) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
let record = {
|
|
914
|
+
v: doc,
|
|
915
|
+
i: docIndex,
|
|
916
|
+
n: this.norm.get(doc)
|
|
917
|
+
};
|
|
918
|
+
this.records.push(record);
|
|
919
|
+
}
|
|
920
|
+
_addObject(doc, docIndex) {
|
|
921
|
+
let record = { i: docIndex, $: {} };
|
|
922
|
+
this.keys.forEach((key, keyIndex) => {
|
|
923
|
+
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
924
|
+
if (!isDefined(value)) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
if (isArray(value)) {
|
|
928
|
+
let subRecords = [];
|
|
929
|
+
const stack = [{ nestedArrIndex: -1, value }];
|
|
930
|
+
while (stack.length) {
|
|
931
|
+
const { nestedArrIndex, value: value2 } = stack.pop();
|
|
932
|
+
if (!isDefined(value2)) {
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (isString(value2) && !isBlank(value2)) {
|
|
936
|
+
let subRecord = {
|
|
937
|
+
v: value2,
|
|
938
|
+
i: nestedArrIndex,
|
|
939
|
+
n: this.norm.get(value2)
|
|
940
|
+
};
|
|
941
|
+
subRecords.push(subRecord);
|
|
942
|
+
} else if (isArray(value2)) {
|
|
943
|
+
value2.forEach((item, k) => {
|
|
944
|
+
stack.push({
|
|
945
|
+
nestedArrIndex: k,
|
|
946
|
+
value: item
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
} else ;
|
|
950
|
+
}
|
|
951
|
+
record.$[keyIndex] = subRecords;
|
|
952
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
953
|
+
let subRecord = {
|
|
954
|
+
v: value,
|
|
955
|
+
n: this.norm.get(value)
|
|
956
|
+
};
|
|
957
|
+
record.$[keyIndex] = subRecord;
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
this.records.push(record);
|
|
961
|
+
}
|
|
962
|
+
toJSON() {
|
|
963
|
+
return {
|
|
964
|
+
keys: this.keys,
|
|
965
|
+
records: this.records
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
970
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
971
|
+
myIndex.setKeys(keys.map(createKey));
|
|
972
|
+
myIndex.setSources(docs);
|
|
973
|
+
myIndex.create();
|
|
974
|
+
return myIndex;
|
|
975
|
+
}
|
|
976
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
977
|
+
const { keys, records } = data;
|
|
978
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
979
|
+
myIndex.setKeys(keys);
|
|
980
|
+
myIndex.setIndexRecords(records);
|
|
981
|
+
return myIndex;
|
|
982
|
+
}
|
|
983
|
+
function computeScore$1(pattern, {
|
|
984
|
+
errors = 0,
|
|
985
|
+
currentLocation = 0,
|
|
986
|
+
expectedLocation = 0,
|
|
987
|
+
distance = Config.distance,
|
|
988
|
+
ignoreLocation = Config.ignoreLocation
|
|
989
|
+
} = {}) {
|
|
990
|
+
const accuracy = errors / pattern.length;
|
|
991
|
+
if (ignoreLocation) {
|
|
992
|
+
return accuracy;
|
|
993
|
+
}
|
|
994
|
+
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
995
|
+
if (!distance) {
|
|
996
|
+
return proximity ? 1 : accuracy;
|
|
997
|
+
}
|
|
998
|
+
return accuracy + proximity / distance;
|
|
999
|
+
}
|
|
1000
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
1001
|
+
let indices = [];
|
|
1002
|
+
let start = -1;
|
|
1003
|
+
let end = -1;
|
|
1004
|
+
let i = 0;
|
|
1005
|
+
for (let len = matchmask.length; i < len; i += 1) {
|
|
1006
|
+
let match = matchmask[i];
|
|
1007
|
+
if (match && start === -1) {
|
|
1008
|
+
start = i;
|
|
1009
|
+
} else if (!match && start !== -1) {
|
|
1010
|
+
end = i - 1;
|
|
1011
|
+
if (end - start + 1 >= minMatchCharLength) {
|
|
1012
|
+
indices.push([start, end]);
|
|
1013
|
+
}
|
|
1014
|
+
start = -1;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
1018
|
+
indices.push([start, i - 1]);
|
|
1019
|
+
}
|
|
1020
|
+
return indices;
|
|
1021
|
+
}
|
|
1022
|
+
var MAX_BITS = 32;
|
|
1023
|
+
function search(text, pattern, patternAlphabet, {
|
|
1024
|
+
location = Config.location,
|
|
1025
|
+
distance = Config.distance,
|
|
1026
|
+
threshold = Config.threshold,
|
|
1027
|
+
findAllMatches = Config.findAllMatches,
|
|
1028
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1029
|
+
includeMatches = Config.includeMatches,
|
|
1030
|
+
ignoreLocation = Config.ignoreLocation
|
|
1031
|
+
} = {}) {
|
|
1032
|
+
if (pattern.length > MAX_BITS) {
|
|
1033
|
+
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
1034
|
+
}
|
|
1035
|
+
const patternLen = pattern.length;
|
|
1036
|
+
const textLen = text.length;
|
|
1037
|
+
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
1038
|
+
let currentThreshold = threshold;
|
|
1039
|
+
let bestLocation = expectedLocation;
|
|
1040
|
+
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
1041
|
+
const matchMask = computeMatches ? Array(textLen) : [];
|
|
1042
|
+
let index;
|
|
1043
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
1044
|
+
let score = computeScore$1(pattern, {
|
|
1045
|
+
currentLocation: index,
|
|
1046
|
+
expectedLocation,
|
|
1047
|
+
distance,
|
|
1048
|
+
ignoreLocation
|
|
1049
|
+
});
|
|
1050
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
1051
|
+
bestLocation = index + patternLen;
|
|
1052
|
+
if (computeMatches) {
|
|
1053
|
+
let i = 0;
|
|
1054
|
+
while (i < patternLen) {
|
|
1055
|
+
matchMask[index + i] = 1;
|
|
1056
|
+
i += 1;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
bestLocation = -1;
|
|
1061
|
+
let lastBitArr = [];
|
|
1062
|
+
let finalScore = 1;
|
|
1063
|
+
let binMax = patternLen + textLen;
|
|
1064
|
+
const mask = 1 << patternLen - 1;
|
|
1065
|
+
for (let i = 0; i < patternLen; i += 1) {
|
|
1066
|
+
let binMin = 0;
|
|
1067
|
+
let binMid = binMax;
|
|
1068
|
+
while (binMin < binMid) {
|
|
1069
|
+
const score2 = computeScore$1(pattern, {
|
|
1070
|
+
errors: i,
|
|
1071
|
+
currentLocation: expectedLocation + binMid,
|
|
1072
|
+
expectedLocation,
|
|
1073
|
+
distance,
|
|
1074
|
+
ignoreLocation
|
|
1075
|
+
});
|
|
1076
|
+
if (score2 <= currentThreshold) {
|
|
1077
|
+
binMin = binMid;
|
|
1078
|
+
} else {
|
|
1079
|
+
binMax = binMid;
|
|
1080
|
+
}
|
|
1081
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1082
|
+
}
|
|
1083
|
+
binMax = binMid;
|
|
1084
|
+
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
1085
|
+
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
1086
|
+
let bitArr = Array(finish + 2);
|
|
1087
|
+
bitArr[finish + 1] = (1 << i) - 1;
|
|
1088
|
+
for (let j = finish; j >= start; j -= 1) {
|
|
1089
|
+
let currentLocation = j - 1;
|
|
1090
|
+
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
1091
|
+
if (computeMatches) {
|
|
1092
|
+
matchMask[currentLocation] = +!!charMatch;
|
|
1093
|
+
}
|
|
1094
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
1095
|
+
if (i) {
|
|
1096
|
+
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
1097
|
+
}
|
|
1098
|
+
if (bitArr[j] & mask) {
|
|
1099
|
+
finalScore = computeScore$1(pattern, {
|
|
1100
|
+
errors: i,
|
|
1101
|
+
currentLocation,
|
|
1102
|
+
expectedLocation,
|
|
1103
|
+
distance,
|
|
1104
|
+
ignoreLocation
|
|
1105
|
+
});
|
|
1106
|
+
if (finalScore <= currentThreshold) {
|
|
1107
|
+
currentThreshold = finalScore;
|
|
1108
|
+
bestLocation = currentLocation;
|
|
1109
|
+
if (bestLocation <= expectedLocation) {
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
const score = computeScore$1(pattern, {
|
|
1117
|
+
errors: i + 1,
|
|
1118
|
+
currentLocation: expectedLocation,
|
|
1119
|
+
expectedLocation,
|
|
1120
|
+
distance,
|
|
1121
|
+
ignoreLocation
|
|
1122
|
+
});
|
|
1123
|
+
if (score > currentThreshold) {
|
|
1124
|
+
break;
|
|
1125
|
+
}
|
|
1126
|
+
lastBitArr = bitArr;
|
|
1127
|
+
}
|
|
1128
|
+
const result = {
|
|
1129
|
+
isMatch: bestLocation >= 0,
|
|
1130
|
+
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
1131
|
+
score: Math.max(1e-3, finalScore)
|
|
1132
|
+
};
|
|
1133
|
+
if (computeMatches) {
|
|
1134
|
+
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
1135
|
+
if (!indices.length) {
|
|
1136
|
+
result.isMatch = false;
|
|
1137
|
+
} else if (includeMatches) {
|
|
1138
|
+
result.indices = indices;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return result;
|
|
1142
|
+
}
|
|
1143
|
+
function createPatternAlphabet(pattern) {
|
|
1144
|
+
let mask = {};
|
|
1145
|
+
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
1146
|
+
const char = pattern.charAt(i);
|
|
1147
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
1148
|
+
}
|
|
1149
|
+
return mask;
|
|
1150
|
+
}
|
|
1151
|
+
var stripDiacritics = String.prototype.normalize ? ((str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "")) : ((str) => str);
|
|
1152
|
+
var BitapSearch = class {
|
|
1153
|
+
constructor(pattern, {
|
|
1154
|
+
location = Config.location,
|
|
1155
|
+
threshold = Config.threshold,
|
|
1156
|
+
distance = Config.distance,
|
|
1157
|
+
includeMatches = Config.includeMatches,
|
|
1158
|
+
findAllMatches = Config.findAllMatches,
|
|
1159
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1160
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1161
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1162
|
+
ignoreLocation = Config.ignoreLocation
|
|
1163
|
+
} = {}) {
|
|
1164
|
+
this.options = {
|
|
1165
|
+
location,
|
|
1166
|
+
threshold,
|
|
1167
|
+
distance,
|
|
1168
|
+
includeMatches,
|
|
1169
|
+
findAllMatches,
|
|
1170
|
+
minMatchCharLength,
|
|
1171
|
+
isCaseSensitive,
|
|
1172
|
+
ignoreDiacritics,
|
|
1173
|
+
ignoreLocation
|
|
1174
|
+
};
|
|
1175
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1176
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1177
|
+
this.pattern = pattern;
|
|
1178
|
+
this.chunks = [];
|
|
1179
|
+
if (!this.pattern.length) {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
const addChunk = (pattern2, startIndex) => {
|
|
1183
|
+
this.chunks.push({
|
|
1184
|
+
pattern: pattern2,
|
|
1185
|
+
alphabet: createPatternAlphabet(pattern2),
|
|
1186
|
+
startIndex
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
const len = this.pattern.length;
|
|
1190
|
+
if (len > MAX_BITS) {
|
|
1191
|
+
let i = 0;
|
|
1192
|
+
const remainder = len % MAX_BITS;
|
|
1193
|
+
const end = len - remainder;
|
|
1194
|
+
while (i < end) {
|
|
1195
|
+
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
1196
|
+
i += MAX_BITS;
|
|
1197
|
+
}
|
|
1198
|
+
if (remainder) {
|
|
1199
|
+
const startIndex = len - MAX_BITS;
|
|
1200
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
1201
|
+
}
|
|
1202
|
+
} else {
|
|
1203
|
+
addChunk(this.pattern, 0);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
searchIn(text) {
|
|
1207
|
+
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
1208
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1209
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1210
|
+
if (this.pattern === text) {
|
|
1211
|
+
let result2 = {
|
|
1212
|
+
isMatch: true,
|
|
1213
|
+
score: 0
|
|
1214
|
+
};
|
|
1215
|
+
if (includeMatches) {
|
|
1216
|
+
result2.indices = [[0, text.length - 1]];
|
|
1217
|
+
}
|
|
1218
|
+
return result2;
|
|
1219
|
+
}
|
|
1220
|
+
const {
|
|
1221
|
+
location,
|
|
1222
|
+
distance,
|
|
1223
|
+
threshold,
|
|
1224
|
+
findAllMatches,
|
|
1225
|
+
minMatchCharLength,
|
|
1226
|
+
ignoreLocation
|
|
1227
|
+
} = this.options;
|
|
1228
|
+
let allIndices = [];
|
|
1229
|
+
let totalScore = 0;
|
|
1230
|
+
let hasMatches = false;
|
|
1231
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
1232
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
1233
|
+
location: location + startIndex,
|
|
1234
|
+
distance,
|
|
1235
|
+
threshold,
|
|
1236
|
+
findAllMatches,
|
|
1237
|
+
minMatchCharLength,
|
|
1238
|
+
includeMatches,
|
|
1239
|
+
ignoreLocation
|
|
1240
|
+
});
|
|
1241
|
+
if (isMatch) {
|
|
1242
|
+
hasMatches = true;
|
|
1243
|
+
}
|
|
1244
|
+
totalScore += score;
|
|
1245
|
+
if (isMatch && indices) {
|
|
1246
|
+
allIndices = [...allIndices, ...indices];
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
let result = {
|
|
1250
|
+
isMatch: hasMatches,
|
|
1251
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
1252
|
+
};
|
|
1253
|
+
if (hasMatches && includeMatches) {
|
|
1254
|
+
result.indices = allIndices;
|
|
1255
|
+
}
|
|
1256
|
+
return result;
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
var BaseMatch = class {
|
|
1260
|
+
constructor(pattern) {
|
|
1261
|
+
this.pattern = pattern;
|
|
1262
|
+
}
|
|
1263
|
+
static isMultiMatch(pattern) {
|
|
1264
|
+
return getMatch(pattern, this.multiRegex);
|
|
1265
|
+
}
|
|
1266
|
+
static isSingleMatch(pattern) {
|
|
1267
|
+
return getMatch(pattern, this.singleRegex);
|
|
1268
|
+
}
|
|
1269
|
+
search() {
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
function getMatch(pattern, exp) {
|
|
1273
|
+
const matches = pattern.match(exp);
|
|
1274
|
+
return matches ? matches[1] : null;
|
|
1275
|
+
}
|
|
1276
|
+
var ExactMatch = class extends BaseMatch {
|
|
1277
|
+
constructor(pattern) {
|
|
1278
|
+
super(pattern);
|
|
1279
|
+
}
|
|
1280
|
+
static get type() {
|
|
1281
|
+
return "exact";
|
|
1282
|
+
}
|
|
1283
|
+
static get multiRegex() {
|
|
1284
|
+
return /^="(.*)"$/;
|
|
1285
|
+
}
|
|
1286
|
+
static get singleRegex() {
|
|
1287
|
+
return /^=(.*)$/;
|
|
1288
|
+
}
|
|
1289
|
+
search(text) {
|
|
1290
|
+
const isMatch = text === this.pattern;
|
|
1291
|
+
return {
|
|
1292
|
+
isMatch,
|
|
1293
|
+
score: isMatch ? 0 : 1,
|
|
1294
|
+
indices: [0, this.pattern.length - 1]
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
var InverseExactMatch = class extends BaseMatch {
|
|
1299
|
+
constructor(pattern) {
|
|
1300
|
+
super(pattern);
|
|
1301
|
+
}
|
|
1302
|
+
static get type() {
|
|
1303
|
+
return "inverse-exact";
|
|
1304
|
+
}
|
|
1305
|
+
static get multiRegex() {
|
|
1306
|
+
return /^!"(.*)"$/;
|
|
1307
|
+
}
|
|
1308
|
+
static get singleRegex() {
|
|
1309
|
+
return /^!(.*)$/;
|
|
1310
|
+
}
|
|
1311
|
+
search(text) {
|
|
1312
|
+
const index = text.indexOf(this.pattern);
|
|
1313
|
+
const isMatch = index === -1;
|
|
1314
|
+
return {
|
|
1315
|
+
isMatch,
|
|
1316
|
+
score: isMatch ? 0 : 1,
|
|
1317
|
+
indices: [0, text.length - 1]
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
var PrefixExactMatch = class extends BaseMatch {
|
|
1322
|
+
constructor(pattern) {
|
|
1323
|
+
super(pattern);
|
|
1324
|
+
}
|
|
1325
|
+
static get type() {
|
|
1326
|
+
return "prefix-exact";
|
|
1327
|
+
}
|
|
1328
|
+
static get multiRegex() {
|
|
1329
|
+
return /^\^"(.*)"$/;
|
|
1330
|
+
}
|
|
1331
|
+
static get singleRegex() {
|
|
1332
|
+
return /^\^(.*)$/;
|
|
1333
|
+
}
|
|
1334
|
+
search(text) {
|
|
1335
|
+
const isMatch = text.startsWith(this.pattern);
|
|
1336
|
+
return {
|
|
1337
|
+
isMatch,
|
|
1338
|
+
score: isMatch ? 0 : 1,
|
|
1339
|
+
indices: [0, this.pattern.length - 1]
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
var InversePrefixExactMatch = class extends BaseMatch {
|
|
1344
|
+
constructor(pattern) {
|
|
1345
|
+
super(pattern);
|
|
1346
|
+
}
|
|
1347
|
+
static get type() {
|
|
1348
|
+
return "inverse-prefix-exact";
|
|
1349
|
+
}
|
|
1350
|
+
static get multiRegex() {
|
|
1351
|
+
return /^!\^"(.*)"$/;
|
|
1352
|
+
}
|
|
1353
|
+
static get singleRegex() {
|
|
1354
|
+
return /^!\^(.*)$/;
|
|
1355
|
+
}
|
|
1356
|
+
search(text) {
|
|
1357
|
+
const isMatch = !text.startsWith(this.pattern);
|
|
1358
|
+
return {
|
|
1359
|
+
isMatch,
|
|
1360
|
+
score: isMatch ? 0 : 1,
|
|
1361
|
+
indices: [0, text.length - 1]
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
var SuffixExactMatch = class extends BaseMatch {
|
|
1366
|
+
constructor(pattern) {
|
|
1367
|
+
super(pattern);
|
|
1368
|
+
}
|
|
1369
|
+
static get type() {
|
|
1370
|
+
return "suffix-exact";
|
|
1371
|
+
}
|
|
1372
|
+
static get multiRegex() {
|
|
1373
|
+
return /^"(.*)"\$$/;
|
|
1374
|
+
}
|
|
1375
|
+
static get singleRegex() {
|
|
1376
|
+
return /^(.*)\$$/;
|
|
1377
|
+
}
|
|
1378
|
+
search(text) {
|
|
1379
|
+
const isMatch = text.endsWith(this.pattern);
|
|
1380
|
+
return {
|
|
1381
|
+
isMatch,
|
|
1382
|
+
score: isMatch ? 0 : 1,
|
|
1383
|
+
indices: [text.length - this.pattern.length, text.length - 1]
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
var InverseSuffixExactMatch = class extends BaseMatch {
|
|
1388
|
+
constructor(pattern) {
|
|
1389
|
+
super(pattern);
|
|
1390
|
+
}
|
|
1391
|
+
static get type() {
|
|
1392
|
+
return "inverse-suffix-exact";
|
|
1393
|
+
}
|
|
1394
|
+
static get multiRegex() {
|
|
1395
|
+
return /^!"(.*)"\$$/;
|
|
1396
|
+
}
|
|
1397
|
+
static get singleRegex() {
|
|
1398
|
+
return /^!(.*)\$$/;
|
|
1399
|
+
}
|
|
1400
|
+
search(text) {
|
|
1401
|
+
const isMatch = !text.endsWith(this.pattern);
|
|
1402
|
+
return {
|
|
1403
|
+
isMatch,
|
|
1404
|
+
score: isMatch ? 0 : 1,
|
|
1405
|
+
indices: [0, text.length - 1]
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
var FuzzyMatch = class extends BaseMatch {
|
|
1410
|
+
constructor(pattern, {
|
|
1411
|
+
location = Config.location,
|
|
1412
|
+
threshold = Config.threshold,
|
|
1413
|
+
distance = Config.distance,
|
|
1414
|
+
includeMatches = Config.includeMatches,
|
|
1415
|
+
findAllMatches = Config.findAllMatches,
|
|
1416
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1417
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1418
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1419
|
+
ignoreLocation = Config.ignoreLocation
|
|
1420
|
+
} = {}) {
|
|
1421
|
+
super(pattern);
|
|
1422
|
+
this._bitapSearch = new BitapSearch(pattern, {
|
|
1423
|
+
location,
|
|
1424
|
+
threshold,
|
|
1425
|
+
distance,
|
|
1426
|
+
includeMatches,
|
|
1427
|
+
findAllMatches,
|
|
1428
|
+
minMatchCharLength,
|
|
1429
|
+
isCaseSensitive,
|
|
1430
|
+
ignoreDiacritics,
|
|
1431
|
+
ignoreLocation
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
static get type() {
|
|
1435
|
+
return "fuzzy";
|
|
1436
|
+
}
|
|
1437
|
+
static get multiRegex() {
|
|
1438
|
+
return /^"(.*)"$/;
|
|
1439
|
+
}
|
|
1440
|
+
static get singleRegex() {
|
|
1441
|
+
return /^(.*)$/;
|
|
1442
|
+
}
|
|
1443
|
+
search(text) {
|
|
1444
|
+
return this._bitapSearch.searchIn(text);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
var IncludeMatch = class extends BaseMatch {
|
|
1448
|
+
constructor(pattern) {
|
|
1449
|
+
super(pattern);
|
|
1450
|
+
}
|
|
1451
|
+
static get type() {
|
|
1452
|
+
return "include";
|
|
1453
|
+
}
|
|
1454
|
+
static get multiRegex() {
|
|
1455
|
+
return /^'"(.*)"$/;
|
|
1456
|
+
}
|
|
1457
|
+
static get singleRegex() {
|
|
1458
|
+
return /^'(.*)$/;
|
|
1459
|
+
}
|
|
1460
|
+
search(text) {
|
|
1461
|
+
let location = 0;
|
|
1462
|
+
let index;
|
|
1463
|
+
const indices = [];
|
|
1464
|
+
const patternLen = this.pattern.length;
|
|
1465
|
+
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
1466
|
+
location = index + patternLen;
|
|
1467
|
+
indices.push([index, location - 1]);
|
|
1468
|
+
}
|
|
1469
|
+
const isMatch = !!indices.length;
|
|
1470
|
+
return {
|
|
1471
|
+
isMatch,
|
|
1472
|
+
score: isMatch ? 0 : 1,
|
|
1473
|
+
indices
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
var searchers = [
|
|
1478
|
+
ExactMatch,
|
|
1479
|
+
IncludeMatch,
|
|
1480
|
+
PrefixExactMatch,
|
|
1481
|
+
InversePrefixExactMatch,
|
|
1482
|
+
InverseSuffixExactMatch,
|
|
1483
|
+
SuffixExactMatch,
|
|
1484
|
+
InverseExactMatch,
|
|
1485
|
+
FuzzyMatch
|
|
1486
|
+
];
|
|
1487
|
+
var searchersLen = searchers.length;
|
|
1488
|
+
var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
1489
|
+
var OR_TOKEN = "|";
|
|
1490
|
+
function parseQuery(pattern, options = {}) {
|
|
1491
|
+
return pattern.split(OR_TOKEN).map((item) => {
|
|
1492
|
+
let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
|
|
1493
|
+
let results = [];
|
|
1494
|
+
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1495
|
+
const queryItem = query[i];
|
|
1496
|
+
let found = false;
|
|
1497
|
+
let idx = -1;
|
|
1498
|
+
while (!found && ++idx < searchersLen) {
|
|
1499
|
+
const searcher = searchers[idx];
|
|
1500
|
+
let token = searcher.isMultiMatch(queryItem);
|
|
1501
|
+
if (token) {
|
|
1502
|
+
results.push(new searcher(token, options));
|
|
1503
|
+
found = true;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
if (found) {
|
|
1507
|
+
continue;
|
|
1508
|
+
}
|
|
1509
|
+
idx = -1;
|
|
1510
|
+
while (++idx < searchersLen) {
|
|
1511
|
+
const searcher = searchers[idx];
|
|
1512
|
+
let token = searcher.isSingleMatch(queryItem);
|
|
1513
|
+
if (token) {
|
|
1514
|
+
results.push(new searcher(token, options));
|
|
1515
|
+
break;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return results;
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
var MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1523
|
+
var ExtendedSearch = class {
|
|
1524
|
+
constructor(pattern, {
|
|
1525
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1526
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1527
|
+
includeMatches = Config.includeMatches,
|
|
1528
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1529
|
+
ignoreLocation = Config.ignoreLocation,
|
|
1530
|
+
findAllMatches = Config.findAllMatches,
|
|
1531
|
+
location = Config.location,
|
|
1532
|
+
threshold = Config.threshold,
|
|
1533
|
+
distance = Config.distance
|
|
1534
|
+
} = {}) {
|
|
1535
|
+
this.query = null;
|
|
1536
|
+
this.options = {
|
|
1537
|
+
isCaseSensitive,
|
|
1538
|
+
ignoreDiacritics,
|
|
1539
|
+
includeMatches,
|
|
1540
|
+
minMatchCharLength,
|
|
1541
|
+
findAllMatches,
|
|
1542
|
+
ignoreLocation,
|
|
1543
|
+
location,
|
|
1544
|
+
threshold,
|
|
1545
|
+
distance
|
|
1546
|
+
};
|
|
1547
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1548
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1549
|
+
this.pattern = pattern;
|
|
1550
|
+
this.query = parseQuery(this.pattern, this.options);
|
|
1551
|
+
}
|
|
1552
|
+
static condition(_, options) {
|
|
1553
|
+
return options.useExtendedSearch;
|
|
1554
|
+
}
|
|
1555
|
+
searchIn(text) {
|
|
1556
|
+
const query = this.query;
|
|
1557
|
+
if (!query) {
|
|
1558
|
+
return {
|
|
1559
|
+
isMatch: false,
|
|
1560
|
+
score: 1
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
|
|
1564
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1565
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1566
|
+
let numMatches = 0;
|
|
1567
|
+
let allIndices = [];
|
|
1568
|
+
let totalScore = 0;
|
|
1569
|
+
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1570
|
+
const searchers2 = query[i];
|
|
1571
|
+
allIndices.length = 0;
|
|
1572
|
+
numMatches = 0;
|
|
1573
|
+
for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
|
|
1574
|
+
const searcher = searchers2[j];
|
|
1575
|
+
const { isMatch, indices, score } = searcher.search(text);
|
|
1576
|
+
if (isMatch) {
|
|
1577
|
+
numMatches += 1;
|
|
1578
|
+
totalScore += score;
|
|
1579
|
+
if (includeMatches) {
|
|
1580
|
+
const type = searcher.constructor.type;
|
|
1581
|
+
if (MultiMatchSet.has(type)) {
|
|
1582
|
+
allIndices = [...allIndices, ...indices];
|
|
1583
|
+
} else {
|
|
1584
|
+
allIndices.push(indices);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
} else {
|
|
1588
|
+
totalScore = 0;
|
|
1589
|
+
numMatches = 0;
|
|
1590
|
+
allIndices.length = 0;
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (numMatches) {
|
|
1595
|
+
let result = {
|
|
1596
|
+
isMatch: true,
|
|
1597
|
+
score: totalScore / numMatches
|
|
1598
|
+
};
|
|
1599
|
+
if (includeMatches) {
|
|
1600
|
+
result.indices = allIndices;
|
|
1601
|
+
}
|
|
1602
|
+
return result;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
return {
|
|
1606
|
+
isMatch: false,
|
|
1607
|
+
score: 1
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
var registeredSearchers = [];
|
|
1612
|
+
function register(...args) {
|
|
1613
|
+
registeredSearchers.push(...args);
|
|
1614
|
+
}
|
|
1615
|
+
function createSearcher(pattern, options) {
|
|
1616
|
+
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
1617
|
+
let searcherClass = registeredSearchers[i];
|
|
1618
|
+
if (searcherClass.condition(pattern, options)) {
|
|
1619
|
+
return new searcherClass(pattern, options);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
return new BitapSearch(pattern, options);
|
|
1623
|
+
}
|
|
1624
|
+
var LogicalOperator = {
|
|
1625
|
+
AND: "$and",
|
|
1626
|
+
OR: "$or"
|
|
1627
|
+
};
|
|
1628
|
+
var KeyType = {
|
|
1629
|
+
PATH: "$path",
|
|
1630
|
+
PATTERN: "$val"
|
|
1631
|
+
};
|
|
1632
|
+
var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1633
|
+
var isPath = (query) => !!query[KeyType.PATH];
|
|
1634
|
+
var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1635
|
+
var convertToExplicit = (query) => ({
|
|
1636
|
+
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1637
|
+
[key]: query[key]
|
|
1638
|
+
}))
|
|
1639
|
+
});
|
|
1640
|
+
function parse(query, options, { auto = true } = {}) {
|
|
1641
|
+
const next = (query2) => {
|
|
1642
|
+
let keys = Object.keys(query2);
|
|
1643
|
+
const isQueryPath = isPath(query2);
|
|
1644
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
|
|
1645
|
+
return next(convertToExplicit(query2));
|
|
1646
|
+
}
|
|
1647
|
+
if (isLeaf(query2)) {
|
|
1648
|
+
const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
|
|
1649
|
+
const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
|
|
1650
|
+
if (!isString(pattern)) {
|
|
1651
|
+
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1652
|
+
}
|
|
1653
|
+
const obj = {
|
|
1654
|
+
keyId: createKeyId(key),
|
|
1655
|
+
pattern
|
|
1656
|
+
};
|
|
1657
|
+
if (auto) {
|
|
1658
|
+
obj.searcher = createSearcher(pattern, options);
|
|
1659
|
+
}
|
|
1660
|
+
return obj;
|
|
1661
|
+
}
|
|
1662
|
+
let node = {
|
|
1663
|
+
children: [],
|
|
1664
|
+
operator: keys[0]
|
|
1665
|
+
};
|
|
1666
|
+
keys.forEach((key) => {
|
|
1667
|
+
const value = query2[key];
|
|
1668
|
+
if (isArray(value)) {
|
|
1669
|
+
value.forEach((item) => {
|
|
1670
|
+
node.children.push(next(item));
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
return node;
|
|
1675
|
+
};
|
|
1676
|
+
if (!isExpression(query)) {
|
|
1677
|
+
query = convertToExplicit(query);
|
|
1678
|
+
}
|
|
1679
|
+
return next(query);
|
|
1680
|
+
}
|
|
1681
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1682
|
+
results.forEach((result) => {
|
|
1683
|
+
let totalScore = 1;
|
|
1684
|
+
result.matches.forEach(({ key, norm: norm2, score }) => {
|
|
1685
|
+
const weight = key ? key.weight : null;
|
|
1686
|
+
totalScore *= Math.pow(
|
|
1687
|
+
score === 0 && weight ? Number.EPSILON : score,
|
|
1688
|
+
(weight || 1) * (ignoreFieldNorm ? 1 : norm2)
|
|
1689
|
+
);
|
|
1690
|
+
});
|
|
1691
|
+
result.score = totalScore;
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
function transformMatches(result, data) {
|
|
1695
|
+
const matches = result.matches;
|
|
1696
|
+
data.matches = [];
|
|
1697
|
+
if (!isDefined(matches)) {
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
matches.forEach((match) => {
|
|
1701
|
+
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
const { indices, value } = match;
|
|
1705
|
+
let obj = {
|
|
1706
|
+
indices,
|
|
1707
|
+
value
|
|
1708
|
+
};
|
|
1709
|
+
if (match.key) {
|
|
1710
|
+
obj.key = match.key.src;
|
|
1711
|
+
}
|
|
1712
|
+
if (match.idx > -1) {
|
|
1713
|
+
obj.refIndex = match.idx;
|
|
1714
|
+
}
|
|
1715
|
+
data.matches.push(obj);
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
function transformScore(result, data) {
|
|
1719
|
+
data.score = result.score;
|
|
1720
|
+
}
|
|
1721
|
+
function format(results, docs, {
|
|
1722
|
+
includeMatches = Config.includeMatches,
|
|
1723
|
+
includeScore = Config.includeScore
|
|
1724
|
+
} = {}) {
|
|
1725
|
+
const transformers = [];
|
|
1726
|
+
if (includeMatches) transformers.push(transformMatches);
|
|
1727
|
+
if (includeScore) transformers.push(transformScore);
|
|
1728
|
+
return results.map((result) => {
|
|
1729
|
+
const { idx } = result;
|
|
1730
|
+
const data = {
|
|
1731
|
+
item: docs[idx],
|
|
1732
|
+
refIndex: idx
|
|
1733
|
+
};
|
|
1734
|
+
if (transformers.length) {
|
|
1735
|
+
transformers.forEach((transformer) => {
|
|
1736
|
+
transformer(result, data);
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
return data;
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
var Fuse = class {
|
|
1743
|
+
constructor(docs, options = {}, index) {
|
|
1744
|
+
this.options = { ...Config, ...options };
|
|
1745
|
+
if (this.options.useExtendedSearch && false) {
|
|
1746
|
+
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1747
|
+
}
|
|
1748
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
1749
|
+
this.setCollection(docs, index);
|
|
1750
|
+
}
|
|
1751
|
+
setCollection(docs, index) {
|
|
1752
|
+
this._docs = docs;
|
|
1753
|
+
if (index && !(index instanceof FuseIndex)) {
|
|
1754
|
+
throw new Error(INCORRECT_INDEX_TYPE);
|
|
1755
|
+
}
|
|
1756
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1757
|
+
getFn: this.options.getFn,
|
|
1758
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
add(doc) {
|
|
1762
|
+
if (!isDefined(doc)) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
this._docs.push(doc);
|
|
1766
|
+
this._myIndex.add(doc);
|
|
1767
|
+
}
|
|
1768
|
+
remove(predicate = () => false) {
|
|
1769
|
+
const results = [];
|
|
1770
|
+
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1771
|
+
const doc = this._docs[i];
|
|
1772
|
+
if (predicate(doc, i)) {
|
|
1773
|
+
this.removeAt(i);
|
|
1774
|
+
i -= 1;
|
|
1775
|
+
len -= 1;
|
|
1776
|
+
results.push(doc);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
return results;
|
|
1780
|
+
}
|
|
1781
|
+
removeAt(idx) {
|
|
1782
|
+
this._docs.splice(idx, 1);
|
|
1783
|
+
this._myIndex.removeAt(idx);
|
|
1784
|
+
}
|
|
1785
|
+
getIndex() {
|
|
1786
|
+
return this._myIndex;
|
|
1787
|
+
}
|
|
1788
|
+
search(query, { limit = -1 } = {}) {
|
|
1789
|
+
const {
|
|
1790
|
+
includeMatches,
|
|
1791
|
+
includeScore,
|
|
1792
|
+
shouldSort,
|
|
1793
|
+
sortFn,
|
|
1794
|
+
ignoreFieldNorm
|
|
1795
|
+
} = this.options;
|
|
1796
|
+
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1797
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1798
|
+
if (shouldSort) {
|
|
1799
|
+
results.sort(sortFn);
|
|
1800
|
+
}
|
|
1801
|
+
if (isNumber(limit) && limit > -1) {
|
|
1802
|
+
results = results.slice(0, limit);
|
|
1803
|
+
}
|
|
1804
|
+
return format(results, this._docs, {
|
|
1805
|
+
includeMatches,
|
|
1806
|
+
includeScore
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
_searchStringList(query) {
|
|
1810
|
+
const searcher = createSearcher(query, this.options);
|
|
1811
|
+
const { records } = this._myIndex;
|
|
1812
|
+
const results = [];
|
|
1813
|
+
records.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1814
|
+
if (!isDefined(text)) {
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1818
|
+
if (isMatch) {
|
|
1819
|
+
results.push({
|
|
1820
|
+
item: text,
|
|
1821
|
+
idx,
|
|
1822
|
+
matches: [{ score, value: text, norm: norm2, indices }]
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
return results;
|
|
1827
|
+
}
|
|
1828
|
+
_searchLogical(query) {
|
|
1829
|
+
const expression = parse(query, this.options);
|
|
1830
|
+
const evaluate = (node, item, idx) => {
|
|
1831
|
+
if (!node.children) {
|
|
1832
|
+
const { keyId, searcher } = node;
|
|
1833
|
+
const matches = this._findMatches({
|
|
1834
|
+
key: this._keyStore.get(keyId),
|
|
1835
|
+
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1836
|
+
searcher
|
|
1837
|
+
});
|
|
1838
|
+
if (matches && matches.length) {
|
|
1839
|
+
return [
|
|
1840
|
+
{
|
|
1841
|
+
idx,
|
|
1842
|
+
item,
|
|
1843
|
+
matches
|
|
1844
|
+
}
|
|
1845
|
+
];
|
|
1846
|
+
}
|
|
1847
|
+
return [];
|
|
1848
|
+
}
|
|
1849
|
+
const res = [];
|
|
1850
|
+
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1851
|
+
const child = node.children[i];
|
|
1852
|
+
const result = evaluate(child, item, idx);
|
|
1853
|
+
if (result.length) {
|
|
1854
|
+
res.push(...result);
|
|
1855
|
+
} else if (node.operator === LogicalOperator.AND) {
|
|
1856
|
+
return [];
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
return res;
|
|
1860
|
+
};
|
|
1861
|
+
const records = this._myIndex.records;
|
|
1862
|
+
const resultMap = {};
|
|
1863
|
+
const results = [];
|
|
1864
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1865
|
+
if (isDefined(item)) {
|
|
1866
|
+
let expResults = evaluate(expression, item, idx);
|
|
1867
|
+
if (expResults.length) {
|
|
1868
|
+
if (!resultMap[idx]) {
|
|
1869
|
+
resultMap[idx] = { idx, item, matches: [] };
|
|
1870
|
+
results.push(resultMap[idx]);
|
|
1871
|
+
}
|
|
1872
|
+
expResults.forEach(({ matches }) => {
|
|
1873
|
+
resultMap[idx].matches.push(...matches);
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
return results;
|
|
1879
|
+
}
|
|
1880
|
+
_searchObjectList(query) {
|
|
1881
|
+
const searcher = createSearcher(query, this.options);
|
|
1882
|
+
const { keys, records } = this._myIndex;
|
|
1883
|
+
const results = [];
|
|
1884
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1885
|
+
if (!isDefined(item)) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
let matches = [];
|
|
1889
|
+
keys.forEach((key, keyIndex) => {
|
|
1890
|
+
matches.push(
|
|
1891
|
+
...this._findMatches({
|
|
1892
|
+
key,
|
|
1893
|
+
value: item[keyIndex],
|
|
1894
|
+
searcher
|
|
1895
|
+
})
|
|
1896
|
+
);
|
|
1897
|
+
});
|
|
1898
|
+
if (matches.length) {
|
|
1899
|
+
results.push({
|
|
1900
|
+
idx,
|
|
1901
|
+
item,
|
|
1902
|
+
matches
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
return results;
|
|
1907
|
+
}
|
|
1908
|
+
_findMatches({ key, value, searcher }) {
|
|
1909
|
+
if (!isDefined(value)) {
|
|
1910
|
+
return [];
|
|
1911
|
+
}
|
|
1912
|
+
let matches = [];
|
|
1913
|
+
if (isArray(value)) {
|
|
1914
|
+
value.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1915
|
+
if (!isDefined(text)) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1919
|
+
if (isMatch) {
|
|
1920
|
+
matches.push({
|
|
1921
|
+
score,
|
|
1922
|
+
key,
|
|
1923
|
+
value: text,
|
|
1924
|
+
idx,
|
|
1925
|
+
norm: norm2,
|
|
1926
|
+
indices
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
} else {
|
|
1931
|
+
const { v: text, n: norm2 } = value;
|
|
1932
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1933
|
+
if (isMatch) {
|
|
1934
|
+
matches.push({ score, key, value: text, norm: norm2, indices });
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return matches;
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
Fuse.version = "7.1.0";
|
|
1941
|
+
Fuse.createIndex = createIndex;
|
|
1942
|
+
Fuse.parseIndex = parseIndex;
|
|
1943
|
+
Fuse.config = Config;
|
|
1944
|
+
{
|
|
1945
|
+
Fuse.parseQuery = parse;
|
|
1946
|
+
}
|
|
1947
|
+
{
|
|
1948
|
+
register(ExtendedSearch);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// src/data/search/utils/sanitizeInput.ts
|
|
1952
|
+
var sanitizeInput = (str) => str.replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "").replace(/[\-–—_./()]+/g, "").normalize("NFC").trim();
|
|
1953
|
+
|
|
1954
|
+
// src/data/search/getSearchClient.ts
|
|
1955
|
+
var getSearchClient = ({ occupants, amenities }) => {
|
|
1956
|
+
const fuseAmenities = new Fuse(amenities, {
|
|
1957
|
+
threshold: 0.2,
|
|
1958
|
+
keys: [
|
|
1959
|
+
{ name: "properties.name", "weight": 1, getFn: (obj) => Object.values(obj.properties.name || {}) },
|
|
1960
|
+
{ name: "properties.category", "weight": 1 }
|
|
1961
|
+
]
|
|
1962
|
+
});
|
|
1963
|
+
const fuseOccupants = new Fuse(occupants, {
|
|
1964
|
+
threshold: 0.25,
|
|
1965
|
+
// 0.2 is too strict (can't find Mo-Mo Paradise with "momo" search string)
|
|
1966
|
+
includeScore: true,
|
|
1967
|
+
shouldSort: true,
|
|
1968
|
+
keys: [
|
|
1969
|
+
{ name: "properties.name", "weight": 4, getFn: (obj) => Object.values(obj.properties.name || {}) },
|
|
1970
|
+
{ name: "properties.keywords", "weight": 0.5 },
|
|
1971
|
+
{ name: "properties.category", "weight": 0.25 },
|
|
1972
|
+
{ name: "properties.local_category_names", "weight": 0.25 },
|
|
1973
|
+
{ name: "properties.description", "weight": 0.25, getFn: (occ) => Object.values(occ.properties.description || {}) },
|
|
1974
|
+
{ name: "properties.unit_name", "weight": 0.25 },
|
|
1975
|
+
{ name: "properties.kiosk_name", "weight": 0.25 }
|
|
1976
|
+
]
|
|
1977
|
+
});
|
|
1978
|
+
const search2 = (value) => {
|
|
1979
|
+
const sanitizedValue = sanitizeInput(value);
|
|
1980
|
+
const matchedAmenities = fuseAmenities.search(sanitizedValue);
|
|
1981
|
+
const matchedOccupants = fuseOccupants.search(sanitizedValue);
|
|
1982
|
+
return [...matchedAmenities, ...matchedOccupants];
|
|
1983
|
+
};
|
|
1984
|
+
return {
|
|
1985
|
+
search: search2
|
|
1986
|
+
};
|
|
1987
|
+
};
|
|
1988
|
+
|
|
1989
|
+
// src/data/getDataClient.ts
|
|
1990
|
+
var getDataClient = (options) => {
|
|
1991
|
+
let searchClient;
|
|
1992
|
+
const observers = /* @__PURE__ */ new Map();
|
|
1993
|
+
const queryClient = options.queryClient ?? new import_query_core.QueryClient();
|
|
1994
|
+
const { mode = "delivery", projectId, apiKey, baseUrl, previewToken } = options;
|
|
1995
|
+
if (!projectId)
|
|
1996
|
+
throw new Error(
|
|
1997
|
+
"Cannot create VenueDataClient. Reason: `projectId` is missing"
|
|
1998
|
+
);
|
|
1999
|
+
if (mode === "delivery" && !apiKey)
|
|
2000
|
+
throw new Error(
|
|
2001
|
+
"Cannot create VenueDataClient. Reason: `apiKey` is missing"
|
|
2002
|
+
);
|
|
2003
|
+
if (mode === "preview" && !previewToken)
|
|
2004
|
+
throw new Error(
|
|
2005
|
+
"Cannot create VenueDataClient. Reason: `previewToken` is missing"
|
|
2006
|
+
);
|
|
2007
|
+
const createDeliveryApiQueryOptions = (featureType) => ({
|
|
2008
|
+
queryKey: ["_deliveryapi", featureType],
|
|
2009
|
+
queryFn: () => safeFetchFeature(featureType, { mode, projectId, apiKey, previewToken, baseUrl })
|
|
2010
|
+
});
|
|
2011
|
+
const internalFilterByType = async (featureType) => {
|
|
2012
|
+
try {
|
|
2013
|
+
const features = await queryClient.ensureQueryData(createDeliveryApiQueryOptions(featureType));
|
|
2014
|
+
return features;
|
|
2015
|
+
} catch (error) {
|
|
2016
|
+
throw error;
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
const internalFindById = async (id) => {
|
|
2020
|
+
if (id === null || id === void 0) return null;
|
|
2021
|
+
const featureType = id.slice(0, id.lastIndexOf("-"));
|
|
2022
|
+
const feature = await queryClient.ensureQueryData({
|
|
2023
|
+
queryKey: ["_deliveryapi", featureType, id],
|
|
2024
|
+
queryFn: async () => {
|
|
2025
|
+
const features = await internalFilterByType(featureType);
|
|
2026
|
+
const feature2 = features.find(
|
|
2027
|
+
(f) => f.id === id
|
|
2028
|
+
);
|
|
2029
|
+
return feature2 ?? null;
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
return feature;
|
|
2033
|
+
};
|
|
2034
|
+
const populator = createPopulator({ internalFindById, internalFilterByType });
|
|
2035
|
+
const registerObserver = (featureType, refetchInterval) => {
|
|
2036
|
+
if (observers.has(featureType)) {
|
|
2037
|
+
console.warn(`Observer for ${featureType} already exists`);
|
|
2038
|
+
const record = observers.get(featureType);
|
|
2039
|
+
return record.observer;
|
|
2040
|
+
}
|
|
2041
|
+
const options2 = createDeliveryApiQueryOptions(featureType);
|
|
2042
|
+
const observer = new import_query_core.QueryObserver(queryClient, {
|
|
2043
|
+
...options2,
|
|
2044
|
+
refetchInterval
|
|
2045
|
+
});
|
|
2046
|
+
const unsubscribe = observer.subscribe(() => {
|
|
2047
|
+
console.log(`[venue-js] Listening to ${featureType} changes (interval = ${refetchInterval}ms)`);
|
|
2048
|
+
});
|
|
2049
|
+
observers.set(featureType, { observer, unsubscribe });
|
|
2050
|
+
return observer;
|
|
2051
|
+
};
|
|
2052
|
+
const destroyObserver = (featureType) => {
|
|
2053
|
+
const record = observers.get(featureType);
|
|
2054
|
+
if (!record) return;
|
|
2055
|
+
record.unsubscribe();
|
|
2056
|
+
observers.delete(featureType);
|
|
2057
|
+
};
|
|
2058
|
+
const destroyObservers = () => {
|
|
2059
|
+
observers.forEach(({ observer, unsubscribe }) => {
|
|
2060
|
+
unsubscribe();
|
|
2061
|
+
observer.destroy();
|
|
2062
|
+
});
|
|
2063
|
+
observers.clear();
|
|
2064
|
+
};
|
|
2065
|
+
const createFilterByTypeQueryOptions = (featureType, params = {}, options2 = {}) => ({
|
|
2066
|
+
queryKey: [featureType, "list", params],
|
|
2067
|
+
queryFn: async () => {
|
|
2068
|
+
const features = await internalFilterByType(featureType);
|
|
2069
|
+
const filters = params.filters ?? {};
|
|
2070
|
+
let result = features;
|
|
2071
|
+
if (params.filters) {
|
|
2072
|
+
result = features.filter((f) => matchFilters(f, filters));
|
|
2073
|
+
}
|
|
2074
|
+
return params.populate === true ? await Promise.all(result.map((f) => populator[featureType](f))) : result;
|
|
2075
|
+
},
|
|
2076
|
+
...options2 ?? {}
|
|
2077
|
+
});
|
|
2078
|
+
const createFindByIdQueryOptions = (featureType, id, params = {}, options2 = {}) => ({
|
|
2079
|
+
queryKey: [featureType, "detail", id, params],
|
|
2080
|
+
queryFn: async () => {
|
|
2081
|
+
const feature = await internalFindById(id);
|
|
2082
|
+
return params.populate === true ? await populator[featureType](feature) : Promise.resolve(feature);
|
|
2083
|
+
},
|
|
2084
|
+
...options2 ?? {}
|
|
2085
|
+
});
|
|
2086
|
+
async function filterByType(featureType, params) {
|
|
2087
|
+
const filterQueryOptions = createFilterByTypeQueryOptions(
|
|
2088
|
+
featureType,
|
|
2089
|
+
params
|
|
2090
|
+
);
|
|
2091
|
+
const features = await queryClient.ensureQueryData(filterQueryOptions);
|
|
2092
|
+
return params?.populate === true ? features : features;
|
|
2093
|
+
}
|
|
2094
|
+
async function findById(featureType, id, params) {
|
|
2095
|
+
const findQueryOptions = createFindByIdQueryOptions(
|
|
2096
|
+
featureType,
|
|
2097
|
+
id,
|
|
2098
|
+
params
|
|
2099
|
+
);
|
|
2100
|
+
const feature = await queryClient.ensureQueryData(findQueryOptions);
|
|
2101
|
+
return feature;
|
|
2102
|
+
}
|
|
2103
|
+
const searchFn = async (txt) => {
|
|
2104
|
+
if (!searchClient) {
|
|
2105
|
+
const [occupants, amenities] = await Promise.all([
|
|
2106
|
+
filterByType("occupant"),
|
|
2107
|
+
filterByType("amenity")
|
|
2108
|
+
]);
|
|
2109
|
+
const haystack = { occupants, amenities };
|
|
2110
|
+
searchClient = getSearchClient(haystack);
|
|
2111
|
+
}
|
|
2112
|
+
return searchClient.search(txt);
|
|
2113
|
+
};
|
|
2114
|
+
return {
|
|
2115
|
+
projectId,
|
|
2116
|
+
queryClient,
|
|
2117
|
+
registerObserver,
|
|
2118
|
+
destroyObserver,
|
|
2119
|
+
destroyObservers,
|
|
2120
|
+
createFilterByTypeQueryOptions,
|
|
2121
|
+
createFindByIdQueryOptions,
|
|
2122
|
+
filterByType,
|
|
2123
|
+
findById,
|
|
2124
|
+
search: searchFn
|
|
2125
|
+
};
|
|
2126
|
+
};
|
|
2127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2128
|
+
0 && (module.exports = {
|
|
2129
|
+
ALL_FEATURE_TYPES,
|
|
2130
|
+
DEFAULT_BASE_URL,
|
|
2131
|
+
GEOJSON_FEATURE_TYPES,
|
|
2132
|
+
IMDF_FEATURE_TYPES,
|
|
2133
|
+
NONIMDF_FEATURE_TYPES,
|
|
2134
|
+
OccupantHelpers,
|
|
2135
|
+
QueryObserver,
|
|
2136
|
+
defaultFeatureQueryOptionsMap,
|
|
2137
|
+
fetchDeliveryApi,
|
|
2138
|
+
fetchPreviewApi,
|
|
2139
|
+
getDataClient,
|
|
2140
|
+
getSearchClient,
|
|
2141
|
+
isValidCoordinate,
|
|
2142
|
+
isValidLineString,
|
|
2143
|
+
isValidLineStringCoordinates,
|
|
2144
|
+
isValidMultiPolygon,
|
|
2145
|
+
isValidMultiPolygonCoordinates,
|
|
2146
|
+
isValidPoint,
|
|
2147
|
+
isValidPolygon,
|
|
2148
|
+
isValidPolygonCoordinates,
|
|
2149
|
+
matchFilter,
|
|
2150
|
+
matchFilters,
|
|
2151
|
+
safeFetchFeature
|
|
2152
|
+
});
|
|
2153
|
+
//# sourceMappingURL=index.js.map
|