@stackbit/cms-core 0.1.3-alpha.0 → 0.1.3-alpha.2
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/content-source-interface.d.ts +6 -3
- package/dist/content-source-interface.d.ts.map +1 -1
- package/dist/content-store-types.d.ts +10 -0
- package/dist/content-store-types.d.ts.map +1 -1
- package/dist/content-store.d.ts +17 -3
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +54 -6
- package/dist/content-store.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types/search-filter.d.ts +42 -0
- package/dist/types/search-filter.d.ts.map +1 -0
- package/dist/types/search-filter.js +3 -0
- package/dist/types/search-filter.js.map +1 -0
- package/dist/utils/search-utils.d.ts +21 -0
- package/dist/utils/search-utils.d.ts.map +1 -0
- package/dist/utils/search-utils.js +323 -0
- package/dist/utils/search-utils.js.map +1 -0
- package/package.json +6 -5
- package/src/content-source-interface.ts +2 -2
- package/src/content-store-types.ts +11 -0
- package/src/content-store.ts +85 -7
- package/src/index.ts +2 -0
- package/src/types/search-filter.ts +53 -0
- package/src/utils/search-utils.ts +436 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Model } from '@stackbit/sdk';
|
|
2
|
+
import { SearchFilter } from '../types/search-filter';
|
|
3
|
+
import { ContentStoreTypes } from '..';
|
|
4
|
+
declare type Schema = Record<string, Record<string, Record<string, Model>>>;
|
|
5
|
+
export declare const searchDocuments: (data: {
|
|
6
|
+
query?: string;
|
|
7
|
+
filter?: SearchFilter;
|
|
8
|
+
models: Array<{
|
|
9
|
+
srcProjectId: string;
|
|
10
|
+
srcType: string;
|
|
11
|
+
modelName: string;
|
|
12
|
+
}>;
|
|
13
|
+
documents: ContentStoreTypes.Document[];
|
|
14
|
+
schema: Schema;
|
|
15
|
+
locale?: string;
|
|
16
|
+
}) => {
|
|
17
|
+
total: number;
|
|
18
|
+
items: ContentStoreTypes.Document[];
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=search-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-utils.d.ts","sourceRoot":"","sources":["../../src/utils/search-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAoB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAavC,aAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,SAAU;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IACH,SAAS,EAAE,kBAAkB,QAAQ,EAAE,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,KAAG;IACA,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,kBAAkB,QAAQ,EAAE,CAAC;CA8CvC,CAAC"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.searchDocuments = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const content_source_interface_1 = require("../content-source-interface");
|
|
9
|
+
const META_FIELD = {
|
|
10
|
+
createdAt: {
|
|
11
|
+
type: 'date'
|
|
12
|
+
},
|
|
13
|
+
updatedAt: {
|
|
14
|
+
type: 'date'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const searchDocuments = (data) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const query = (_a = data.query) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
20
|
+
const { documents, schema } = data;
|
|
21
|
+
let allDocuments = 0;
|
|
22
|
+
const matchedDocuments = documents.filter((document) => {
|
|
23
|
+
var _a;
|
|
24
|
+
const isIncludedModel = lodash_1.default.find(data.models, {
|
|
25
|
+
srcType: document.srcType,
|
|
26
|
+
srcProjectId: document.srcProjectId,
|
|
27
|
+
modelName: document.srcModelName
|
|
28
|
+
});
|
|
29
|
+
if (!isIncludedModel) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
allDocuments += 1;
|
|
33
|
+
if (query) {
|
|
34
|
+
const matches = isDocumentMatchesPattern(document, query, data.locale);
|
|
35
|
+
if (!matches) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if ((_a = data.filter) === null || _a === void 0 ? void 0 : _a.and) {
|
|
40
|
+
// only 'and' supported for now; later we can add e.g. 'or'
|
|
41
|
+
const matches = data.filter.and.every((filter) => {
|
|
42
|
+
const field = getFieldForFilter(document, filter);
|
|
43
|
+
return isFieldMatchesFilter({ field, filter, document, schema, locale: data.locale });
|
|
44
|
+
});
|
|
45
|
+
if (!matches) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
items: matchedDocuments,
|
|
53
|
+
total: allDocuments
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.searchDocuments = searchDocuments;
|
|
57
|
+
const isDocumentMatchesPattern = (document, query, locale) => {
|
|
58
|
+
return lodash_1.default.some(document.fields, (field) => {
|
|
59
|
+
var _a;
|
|
60
|
+
let value;
|
|
61
|
+
switch (field.type) {
|
|
62
|
+
case 'string':
|
|
63
|
+
case 'slug':
|
|
64
|
+
case 'url':
|
|
65
|
+
case 'text':
|
|
66
|
+
case 'markdown':
|
|
67
|
+
case 'html':
|
|
68
|
+
value = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (value) {
|
|
72
|
+
return value === null || value === void 0 ? void 0 : value.toString().toLowerCase().includes(query);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const getFieldForFilter = (document, filter) => {
|
|
78
|
+
if (filter.isMeta) {
|
|
79
|
+
const fieldDef = META_FIELD[filter.field];
|
|
80
|
+
if (!fieldDef) {
|
|
81
|
+
throw new Error(`Unsupported meta field ${filter.field}`);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
...fieldDef,
|
|
85
|
+
value: document[filter.field]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const documentField = document.fields[filter.field];
|
|
90
|
+
if (!documentField) {
|
|
91
|
+
throw new Error(`Field not found ${filter.field}`);
|
|
92
|
+
}
|
|
93
|
+
return documentField;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const isFieldMatchesFilter = ({ document, field, filter, locale, schema }) => {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
switch (field === null || field === void 0 ? void 0 : field.type) {
|
|
99
|
+
case 'string':
|
|
100
|
+
case 'slug':
|
|
101
|
+
case 'url':
|
|
102
|
+
case 'text':
|
|
103
|
+
case 'markdown':
|
|
104
|
+
case 'html':
|
|
105
|
+
return isStringFieldMatches({ field, filter, locale });
|
|
106
|
+
case 'number':
|
|
107
|
+
return isNumberFieldMatches({ field, filter, locale });
|
|
108
|
+
case 'boolean':
|
|
109
|
+
return isBooleanFieldMatches({ field, filter, locale });
|
|
110
|
+
case 'date':
|
|
111
|
+
case 'datetime':
|
|
112
|
+
return isDateFieldMatches({ field, filter, locale });
|
|
113
|
+
case 'enum':
|
|
114
|
+
return isEnumFieldMatches({ field, filter, locale });
|
|
115
|
+
case 'list': {
|
|
116
|
+
const model = (_b = (_a = schema === null || schema === void 0 ? void 0 : schema[document.srcType]) === null || _a === void 0 ? void 0 : _a[document.srcProjectId]) === null || _b === void 0 ? void 0 : _b[document.srcModelName];
|
|
117
|
+
if (!model) {
|
|
118
|
+
throw new Error(`Can't find model for the ${filter.field}`);
|
|
119
|
+
}
|
|
120
|
+
return isListFieldMatches({ field, filter, model, locale });
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unsupported filter for field ${filter.field} with type ${field === null || field === void 0 ? void 0 : field.type}`);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const isStringFieldMatches = ({ field, filter, locale }) => {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
// ignoring case
|
|
129
|
+
const fieldValue = (_b = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
130
|
+
switch (filter.operator) {
|
|
131
|
+
case 'is-undefined': return fieldValue === undefined;
|
|
132
|
+
case 'is-not-undefined': return fieldValue !== undefined;
|
|
133
|
+
case 'eq': // ===
|
|
134
|
+
case 'neq': // !==
|
|
135
|
+
case 'includes':
|
|
136
|
+
case 'not-includes': {
|
|
137
|
+
if (typeof filter.value !== 'string') {
|
|
138
|
+
throw new Error(`Filter value should be string for field ${filter.field}`);
|
|
139
|
+
}
|
|
140
|
+
const filterValue = (_c = filter.value) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase();
|
|
141
|
+
switch (filter.operator) {
|
|
142
|
+
case 'eq':
|
|
143
|
+
return fieldValue === filterValue;
|
|
144
|
+
case 'neq':
|
|
145
|
+
return fieldValue !== filterValue;
|
|
146
|
+
case 'includes':
|
|
147
|
+
return fieldValue.includes(filterValue);
|
|
148
|
+
case 'not-includes':
|
|
149
|
+
return !fieldValue.includes(filterValue);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
154
|
+
};
|
|
155
|
+
const isNumberFieldMatches = ({ field, filter, locale }) => {
|
|
156
|
+
var _a;
|
|
157
|
+
const fieldValue = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value;
|
|
158
|
+
switch (filter.operator) {
|
|
159
|
+
case 'is-undefined': return fieldValue === undefined;
|
|
160
|
+
case 'is-not-undefined': return fieldValue !== undefined;
|
|
161
|
+
case 'eq': // ===
|
|
162
|
+
case 'neq': // !==
|
|
163
|
+
case 'gte': // >=
|
|
164
|
+
case 'lte': {
|
|
165
|
+
// <=
|
|
166
|
+
if (typeof filter.value !== 'number') {
|
|
167
|
+
throw new Error(`Filter value should be number for field ${filter.field}`);
|
|
168
|
+
}
|
|
169
|
+
switch (filter.operator) {
|
|
170
|
+
case 'eq':
|
|
171
|
+
return fieldValue === filter.value;
|
|
172
|
+
case 'neq':
|
|
173
|
+
return fieldValue !== filter.value;
|
|
174
|
+
case 'gte':
|
|
175
|
+
return fieldValue >= filter.value;
|
|
176
|
+
case 'lte':
|
|
177
|
+
return fieldValue <= filter.value;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
case 'between': {
|
|
181
|
+
// ..N..
|
|
182
|
+
if (typeof filter.startValue !== 'number' || typeof filter.endValue !== 'number') {
|
|
183
|
+
throw new Error(`Filter startValue and endValue should be number for field ${filter.field}`);
|
|
184
|
+
}
|
|
185
|
+
return fieldValue >= filter.startValue && fieldValue <= filter.endValue;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
189
|
+
};
|
|
190
|
+
const isBooleanFieldMatches = ({ field, filter, locale }) => {
|
|
191
|
+
var _a;
|
|
192
|
+
const fieldValue = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value;
|
|
193
|
+
switch (filter.operator) {
|
|
194
|
+
case 'is-undefined': return fieldValue === undefined;
|
|
195
|
+
case 'is-not-undefined': return fieldValue !== undefined;
|
|
196
|
+
case 'eq':
|
|
197
|
+
case 'neq': {
|
|
198
|
+
if (typeof filter.value !== 'boolean') {
|
|
199
|
+
throw new Error(`Filter value should be boolean for field ${filter.field}`);
|
|
200
|
+
}
|
|
201
|
+
switch (filter.operator) {
|
|
202
|
+
case 'eq':
|
|
203
|
+
return fieldValue === filter.value;
|
|
204
|
+
case 'neq':
|
|
205
|
+
return fieldValue !== filter.value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
210
|
+
};
|
|
211
|
+
const parseDateValue = (value) => {
|
|
212
|
+
let dateValue;
|
|
213
|
+
if (value === null || value === void 0 ? void 0 : value.endsWith('Z')) {
|
|
214
|
+
dateValue = new Date(value);
|
|
215
|
+
}
|
|
216
|
+
else if (value === null || value === void 0 ? void 0 : value.match(/\d{1,4}-\d{1,2}-\d{1,2}$/)) {
|
|
217
|
+
// try to parse it as a date
|
|
218
|
+
// when use '-' in js dates constructor, it make the date with TZ offset
|
|
219
|
+
// 2022-10-04 => 03 Oct 2022 20:00 GMT-4
|
|
220
|
+
// 2022/10/04 => 04 Oct 2022 00:00 GMT-4
|
|
221
|
+
dateValue = new Date(value.replace(/-/g, '/'));
|
|
222
|
+
}
|
|
223
|
+
if (dateValue && !Number.isNaN(dateValue)) {
|
|
224
|
+
return dateValue;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const isDateFieldMatches = ({ field, filter, locale }) => {
|
|
228
|
+
var _a, _b, _c, _d, _e;
|
|
229
|
+
const origValue = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value;
|
|
230
|
+
const fieldValue = parseDateValue(origValue);
|
|
231
|
+
if (origValue && !fieldValue) {
|
|
232
|
+
throw new Error(`Can't parse value ${origValue} for field ${filter.field}`);
|
|
233
|
+
}
|
|
234
|
+
switch (filter.operator) {
|
|
235
|
+
case 'is-undefined': return fieldValue === undefined;
|
|
236
|
+
case 'is-not-undefined': return fieldValue !== undefined;
|
|
237
|
+
case 'eq': // ===
|
|
238
|
+
case 'neq': // !==
|
|
239
|
+
case 'gte': // >=
|
|
240
|
+
case 'lte': {
|
|
241
|
+
// <=
|
|
242
|
+
if (typeof filter.value !== 'string') {
|
|
243
|
+
throw new Error(`Filter value should be in string date format for field ${filter.field}`);
|
|
244
|
+
}
|
|
245
|
+
const filterValue = parseDateValue(filter.value);
|
|
246
|
+
if (!filterValue) {
|
|
247
|
+
throw new Error(`Filter value should be in date format for field ${filter.field}`);
|
|
248
|
+
}
|
|
249
|
+
switch (filter.operator) {
|
|
250
|
+
case 'eq':
|
|
251
|
+
case 'neq': { // check if day is the same
|
|
252
|
+
const result = ((fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getFullYear()) === filterValue.getFullYear() &&
|
|
253
|
+
(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getMonth()) === filterValue.getMonth() &&
|
|
254
|
+
(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getDate()) === filterValue.getDate());
|
|
255
|
+
return filter.operator === 'eq' ? result : !result;
|
|
256
|
+
}
|
|
257
|
+
case 'gte':
|
|
258
|
+
return ((_b = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getTime()) !== null && _b !== void 0 ? _b : 0) >= filterValue.getTime();
|
|
259
|
+
case 'lte':
|
|
260
|
+
return ((_c = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getTime()) !== null && _c !== void 0 ? _c : 0) <= filterValue.getTime();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
case 'between': {
|
|
264
|
+
// ..N..
|
|
265
|
+
if (typeof filter.startValue !== 'string' || typeof filter.endValue !== 'string') {
|
|
266
|
+
throw new Error(`Filter startValue and endValue should be in string date format for field ${filter.field}`);
|
|
267
|
+
}
|
|
268
|
+
const startDate = parseDateValue(filter.startValue);
|
|
269
|
+
const endDate = parseDateValue(filter.endValue);
|
|
270
|
+
if (!startDate || !endDate) {
|
|
271
|
+
throw new Error(`Filter startValue and endValue should be in date format for field ${filter.field}`);
|
|
272
|
+
}
|
|
273
|
+
return ((_d = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getTime()) !== null && _d !== void 0 ? _d : 0) >= startDate.getTime() && ((_e = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getTime()) !== null && _e !== void 0 ? _e : 0) <= endDate.getTime();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
277
|
+
};
|
|
278
|
+
const isEnumFieldMatches = ({ field, filter, locale }) => {
|
|
279
|
+
var _a;
|
|
280
|
+
const fieldValue = (_a = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _a === void 0 ? void 0 : _a.value;
|
|
281
|
+
switch (filter.operator) {
|
|
282
|
+
case 'is-undefined': return fieldValue === undefined;
|
|
283
|
+
case 'is-not-undefined': return fieldValue !== undefined;
|
|
284
|
+
case 'in': // one of
|
|
285
|
+
case 'nin': { // none of
|
|
286
|
+
const filterValues = filter.values;
|
|
287
|
+
switch (filter.operator) {
|
|
288
|
+
case 'in':
|
|
289
|
+
return filterValues.includes(fieldValue);
|
|
290
|
+
case 'nin':
|
|
291
|
+
return !filterValues.includes(fieldValue);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
296
|
+
};
|
|
297
|
+
const isListFieldMatches = ({ field, filter, locale, model }) => {
|
|
298
|
+
var _a, _b, _c, _d, _e;
|
|
299
|
+
const fieldModel = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.name === filter.field);
|
|
300
|
+
const listItemsType = (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === 'list' && ((_b = fieldModel.items) === null || _b === void 0 ? void 0 : _b.type);
|
|
301
|
+
const isPrimitiveList = listItemsType && ['string', 'slug', 'url', 'text', 'markdown', 'boolean', 'date', 'datetime', 'number', 'enum'].includes(listItemsType);
|
|
302
|
+
if (!isPrimitiveList) {
|
|
303
|
+
throw new Error(`Unsupported filter for list field ${filter.field} with children ${listItemsType}`);
|
|
304
|
+
}
|
|
305
|
+
const fieldValue = (_d = (_c = (0, content_source_interface_1.getLocalizedFieldForLocale)(field, locale)) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.map((item) => 'value' in item ? item.value : undefined);
|
|
306
|
+
switch (filter.operator) {
|
|
307
|
+
case 'in': // one of
|
|
308
|
+
case 'nin': // none of
|
|
309
|
+
case 'all': { // all of
|
|
310
|
+
const filterValues = filter.values;
|
|
311
|
+
switch (filter.operator) {
|
|
312
|
+
case 'in':
|
|
313
|
+
return (_e = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.some((value) => filterValues.includes(value))) !== null && _e !== void 0 ? _e : false;
|
|
314
|
+
case 'nin':
|
|
315
|
+
return !(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.some((value) => filterValues.includes(value)));
|
|
316
|
+
case 'all':
|
|
317
|
+
return filterValues.every((value) => fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.includes(value));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
throw new Error(`Not supported operator ${filter.operator} for field ${filter.field}`);
|
|
322
|
+
};
|
|
323
|
+
//# sourceMappingURL=search-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-utils.js","sourceRoot":"","sources":["../../src/utils/search-utils.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAKvB,0EAAyE;AAEzE,MAAM,UAAU,GAAG;IACf,SAAS,EAAE;QACP,IAAI,EAAE,MAAM;KACf;IACD,SAAS,EAAE;QACP,IAAI,EAAE,MAAM;KACf;CACK,CAAC;AAIJ,MAAM,eAAe,GAAG,CAAC,IAW/B,EAGC,EAAE;;IACA,MAAM,KAAK,GAAG,MAAA,IAAI,CAAC,KAAK,0CAAE,WAAW,EAAE,CAAC;IAExC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEnC,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,MAAM,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;;QACnD,MAAM,eAAe,GAAG,gBAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACxC,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,SAAS,EAAE,QAAQ,CAAC,YAAY;SACnC,CAAC,CAAC;QACH,IAAI,CAAC,eAAe,EAAE;YAClB,OAAO,KAAK,CAAC;SAChB;QAED,YAAY,IAAI,CAAC,CAAC;QAElB,IAAI,KAAK,EAAE;YACP,MAAM,OAAO,GAAG,wBAAwB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACvE,IAAI,CAAC,OAAO,EAAE;gBACV,OAAO,KAAK,CAAC;aAChB;SACJ;QAED,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,GAAG,EAAE;YAClB,2DAA2D;YAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAA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,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;aACzE;SACJ;KACJ;IAED,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,QAAQ,cAAc,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3F,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackbit/cms-core",
|
|
3
|
-
"version": "0.1.3-alpha.
|
|
3
|
+
"version": "0.1.3-alpha.2",
|
|
4
4
|
"description": "stackbit-dev",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"/src"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "jest
|
|
12
|
+
"test": "jest",
|
|
13
13
|
"build": "rm -rf dist && tsc",
|
|
14
14
|
"watch": "rm -rf dist && tsc -w",
|
|
15
15
|
"prettier": "prettier --write src",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"author": "Stackbit Inc.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
+
"@types/jest": "^27.5.2",
|
|
21
22
|
"@types/lodash": "^4.14.182",
|
|
22
23
|
"jest": "^27.4.7",
|
|
23
24
|
"prettier": "^2.5.1",
|
|
@@ -28,8 +29,8 @@
|
|
|
28
29
|
"@babel/parser": "^7.11.5",
|
|
29
30
|
"@babel/traverse": "^7.11.5",
|
|
30
31
|
"@iarna/toml": "^2.2.3",
|
|
31
|
-
"@stackbit/sdk": "^0.3.3-alpha.
|
|
32
|
-
"@stackbit/utils": "^0.2.10-alpha.
|
|
32
|
+
"@stackbit/sdk": "^0.3.3-alpha.1",
|
|
33
|
+
"@stackbit/utils": "^0.2.10-alpha.1",
|
|
33
34
|
"chalk": "^4.0.1",
|
|
34
35
|
"esm": "^3.2.25",
|
|
35
36
|
"fs-extra": "^8.1.0",
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"sanitize-filename": "^1.6.3",
|
|
44
45
|
"slugify": "^1.6.5"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c81f11963a10ee463e5072ead25eeb5a16c3df2a"
|
|
47
48
|
}
|
|
@@ -419,7 +419,7 @@ export interface ContentSourceInterface<UserContext = unknown, DocumentContext =
|
|
|
419
419
|
updatedFiles
|
|
420
420
|
}: {
|
|
421
421
|
updatedFiles: string[];
|
|
422
|
-
}): { schemaChanged?: boolean; contentChangeEvent?: ContentChangeEvent<DocumentContext, AssetContext> }
|
|
422
|
+
}): Promise<{ schemaChanged?: boolean; contentChangeEvent?: ContentChangeEvent<DocumentContext, AssetContext> }>;
|
|
423
423
|
|
|
424
424
|
startWatchingContentUpdates(options: {
|
|
425
425
|
getModelMap: () => ModelMap;
|
|
@@ -447,7 +447,7 @@ export interface ContentSourceInterface<UserContext = unknown, DocumentContext =
|
|
|
447
447
|
|
|
448
448
|
getAssets(): Promise<Asset<AssetContext>[]>;
|
|
449
449
|
|
|
450
|
-
hasAccess(options: { userContext?: UserContext }): Promise<boolean>;
|
|
450
|
+
hasAccess(options: { userContext?: UserContext }): Promise<{ hasConnection: boolean; hasPermissions: boolean }>;
|
|
451
451
|
|
|
452
452
|
createDocument(options: {
|
|
453
453
|
updateOperationFields: Record<string, UpdateOperationField>;
|
|
@@ -430,3 +430,14 @@ export type ValidationError = {
|
|
|
430
430
|
fieldPath: (string | number)[];
|
|
431
431
|
isUniqueValidation?: boolean;
|
|
432
432
|
};
|
|
433
|
+
|
|
434
|
+
export type HasAccessResult = {
|
|
435
|
+
hasConnection: boolean;
|
|
436
|
+
hasPermissions: boolean;
|
|
437
|
+
contentSources: {
|
|
438
|
+
srcType: string;
|
|
439
|
+
srcProjectId: string;
|
|
440
|
+
hasConnection: boolean;
|
|
441
|
+
hasPermissions: boolean;
|
|
442
|
+
}[]
|
|
443
|
+
};
|
package/src/content-store.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import sanitizeFilename from 'sanitize-filename';
|
|
4
|
+
|
|
4
5
|
import { Config, extendConfig, Field, loadConfigFromDir, Model, RawConfigWithPaths, Preset } from '@stackbit/sdk';
|
|
5
|
-
import { deferWhileRunning, mapPromise } from '@stackbit/utils';
|
|
6
|
+
import { deferWhileRunning, mapPromise, reducePromise } from '@stackbit/utils';
|
|
6
7
|
|
|
7
8
|
import * as CSITypes from './content-source-interface';
|
|
8
9
|
import * as ContentStoreTypes from './content-store-types';
|
|
9
10
|
import { Timer } from './utils/timer';
|
|
10
11
|
import { UserCommandSpawner } from './common/common-types';
|
|
12
|
+
import { SearchFilter } from './types/search-filter';
|
|
13
|
+
import { searchDocuments } from './utils/search-utils';
|
|
11
14
|
import { getLocalizedFieldForLocale } from './content-source-interface';
|
|
12
15
|
import { mapCSIAssetsToStoreAssets, mapCSIDocumentsToStoreDocuments } from './utils/csi-to-store-docs-converter';
|
|
13
16
|
import { getContentSourceId, getContentSourceIdForContentSource, getModelFieldForFieldAtPath, getUserContextForSrcType } from './content-store-utils';
|
|
@@ -207,7 +210,7 @@ export class ContentStore {
|
|
|
207
210
|
for (const contentSourceInstance of this.contentSources) {
|
|
208
211
|
const contentSourceId = getContentSourceIdForContentSource(contentSourceInstance);
|
|
209
212
|
this.logger.debug(`call onFilesChange for contentSource: ${contentSourceId}`);
|
|
210
|
-
const { schemaChanged, contentChangeEvent } = contentSourceInstance.onFilesChange?.({ updatedFiles: updatedFiles }) ?? {};
|
|
213
|
+
const { schemaChanged, contentChangeEvent } = await contentSourceInstance.onFilesChange?.({ updatedFiles: updatedFiles }) ?? {};
|
|
211
214
|
this.logger.debug(`schemaChanged: ${schemaChanged}, has contentChangeEvent: ${!!contentChangeEvent}`);
|
|
212
215
|
// if schema is changed, there is no need to return contentChanges
|
|
213
216
|
// because schema changes reloads everything and implies content changes
|
|
@@ -550,11 +553,53 @@ export class ContentStore {
|
|
|
550
553
|
return contentSourceData.instance.getProjectEnvironment();
|
|
551
554
|
}
|
|
552
555
|
|
|
553
|
-
hasAccess({
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
556
|
+
async hasAccess({
|
|
557
|
+
srcType,
|
|
558
|
+
srcProjectId,
|
|
559
|
+
user
|
|
560
|
+
}: {
|
|
561
|
+
srcType?: string;
|
|
562
|
+
srcProjectId?: string;
|
|
563
|
+
user?: ContentStoreTypes.User;
|
|
564
|
+
}): Promise<ContentStoreTypes.HasAccessResult> {
|
|
565
|
+
let contentSourceDataArr: ContentSourceData[];
|
|
566
|
+
if (srcType && srcProjectId) {
|
|
567
|
+
const contentSourceId = getContentSourceId(srcType, srcProjectId);
|
|
568
|
+
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
569
|
+
contentSourceDataArr = [contentSourceData];
|
|
570
|
+
} else {
|
|
571
|
+
contentSourceDataArr = Object.values(this.contentSourceDataById);
|
|
572
|
+
}
|
|
573
|
+
return reducePromise(
|
|
574
|
+
contentSourceDataArr,
|
|
575
|
+
async (accum: ContentStoreTypes.HasAccessResult, contentSourceData) => {
|
|
576
|
+
const srcType = contentSourceData.type;
|
|
577
|
+
const srcProjectId = contentSourceData.projectId;
|
|
578
|
+
const userContext = getUserContextForSrcType(srcType, user);
|
|
579
|
+
let result = await contentSourceData.instance.hasAccess({ userContext });
|
|
580
|
+
// backwards compatibility with older CSI version
|
|
581
|
+
if (typeof result === 'boolean') {
|
|
582
|
+
result = {
|
|
583
|
+
hasConnection: result,
|
|
584
|
+
hasPermissions: result
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
hasConnection: accum.hasConnection && result.hasConnection,
|
|
589
|
+
hasPermissions: accum.hasPermissions && result.hasPermissions,
|
|
590
|
+
contentSources: accum.contentSources.concat({
|
|
591
|
+
srcType,
|
|
592
|
+
srcProjectId,
|
|
593
|
+
...result
|
|
594
|
+
})
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
hasConnection: true,
|
|
599
|
+
hasPermissions: true,
|
|
600
|
+
contentSources: []
|
|
601
|
+
}
|
|
602
|
+
);
|
|
558
603
|
}
|
|
559
604
|
|
|
560
605
|
hasChanges({
|
|
@@ -1248,6 +1293,39 @@ export class ContentStore {
|
|
|
1248
1293
|
*/
|
|
1249
1294
|
}
|
|
1250
1295
|
|
|
1296
|
+
async searchDocuments(data: {
|
|
1297
|
+
query?: string;
|
|
1298
|
+
filter?: SearchFilter;
|
|
1299
|
+
models: Array<{
|
|
1300
|
+
srcProjectId: string;
|
|
1301
|
+
srcType: string;
|
|
1302
|
+
modelName: string;
|
|
1303
|
+
}>;
|
|
1304
|
+
locale?: string;
|
|
1305
|
+
}): Promise<{
|
|
1306
|
+
total: number;
|
|
1307
|
+
items: ContentStoreTypes.Document[];
|
|
1308
|
+
}> {
|
|
1309
|
+
this.logger.debug('searchDocuments');
|
|
1310
|
+
|
|
1311
|
+
const objectsBySourceId = _.groupBy(data.models, (object) => getContentSourceId(object.srcType, object.srcProjectId));
|
|
1312
|
+
const documents: ContentStoreTypes.Document[] = [];
|
|
1313
|
+
const schema: Record<string, Record<string, Record<string, Model>>> = {};
|
|
1314
|
+
|
|
1315
|
+
Object.keys(objectsBySourceId).forEach((contentSourceId) => {
|
|
1316
|
+
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1317
|
+
|
|
1318
|
+
documents.push(...contentSourceData.documents);
|
|
1319
|
+
_.set(schema, [contentSourceData.type, contentSourceData.projectId], contentSourceData.modelMap);
|
|
1320
|
+
})
|
|
1321
|
+
|
|
1322
|
+
return searchDocuments({
|
|
1323
|
+
...data,
|
|
1324
|
+
documents,
|
|
1325
|
+
schema
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1251
1329
|
async publishDocuments({ objects, user }: { objects: { srcType: string; srcProjectId: string; srcObjectId: string }[]; user?: ContentStoreTypes.User }) {
|
|
1252
1330
|
this.logger.debug('publishDocuments');
|
|
1253
1331
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * as stackbit from './stackbit';
|
|
2
2
|
export * as annotator from './annotator';
|
|
3
3
|
export * as utils from './utils';
|
|
4
|
+
export * as searchUtils from './utils/search-utils';
|
|
4
5
|
export * as consts from './consts';
|
|
5
6
|
export * from './common/common-schema';
|
|
6
7
|
export * from './common/common-types';
|
|
@@ -9,3 +10,4 @@ export * as ContentSourceTypes from './content-source-interface';
|
|
|
9
10
|
export * as ContentStoreTypes from './content-store-types';
|
|
10
11
|
export { default as encodeData } from './encoder';
|
|
11
12
|
export * from './encoder';
|
|
13
|
+
export * from './types/search-filter';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
type Distribute<U> = U extends any ? U[] : never;
|
|
2
|
+
|
|
3
|
+
type ValueType = string | number | Date | boolean;
|
|
4
|
+
|
|
5
|
+
type BaseFilterItem = {
|
|
6
|
+
field: string;
|
|
7
|
+
isMeta?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type EqualFilterItem = BaseFilterItem & {
|
|
11
|
+
operator: 'eq' | 'neq';
|
|
12
|
+
value: ValueType;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type UndefinedFilterItem = BaseFilterItem & {
|
|
16
|
+
operator: 'is-undefined' | 'is-not-undefined';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type CompareFilterItem = BaseFilterItem & {
|
|
20
|
+
operator: 'gte' | 'lte';
|
|
21
|
+
value: ValueType;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type IncludeStringFilterItem = BaseFilterItem & {
|
|
25
|
+
operator: 'includes' | 'not-includes';
|
|
26
|
+
value: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type IncludeListFilterItem = BaseFilterItem & {
|
|
30
|
+
operator: 'in' | 'nin';
|
|
31
|
+
values: Distribute<ValueType>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type IncludeAllFilterItem = BaseFilterItem & {
|
|
35
|
+
operator: 'all';
|
|
36
|
+
values: Distribute<ValueType>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type BetweenFilterItem = BaseFilterItem & {
|
|
40
|
+
operator: 'between';
|
|
41
|
+
startValue: ValueType;
|
|
42
|
+
endValue: ValueType;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type SearchFilterItem = EqualFilterItem | UndefinedFilterItem | CompareFilterItem | IncludeStringFilterItem | IncludeListFilterItem | IncludeAllFilterItem | BetweenFilterItem;
|
|
46
|
+
|
|
47
|
+
export type SearchFilter = LogicalOperator;
|
|
48
|
+
|
|
49
|
+
type LogicalOperator = LogicalAndOperator;
|
|
50
|
+
|
|
51
|
+
type LogicalAndOperator = {
|
|
52
|
+
'and': SearchFilterItem[];
|
|
53
|
+
};
|