@stackbit/cms-core 0.8.6-develop.1 → 0.8.6-develop.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/content-store.d.ts +6 -0
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +50 -3
- package/dist/content-store.js.map +1 -1
- package/dist/utils/custom-actions.js +5 -8
- package/dist/utils/custom-actions.js.map +1 -1
- package/package.json +5 -4
- package/src/content-store.ts +50 -0
- package/src/utils/custom-actions.ts +1 -4
- package/dist/utils/custom-search-filters.d.ts +0 -12
- package/dist/utils/custom-search-filters.d.ts.map +0 -1
- package/dist/utils/custom-search-filters.js +0 -46
- package/dist/utils/custom-search-filters.js.map +0 -1
package/src/content-store.ts
CHANGED
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
pluralize
|
|
71
71
|
} from './utils/user-log-utils';
|
|
72
72
|
import { getSanitizedTreeViews } from './utils/tree-views';
|
|
73
|
+
import { ContentEnginePublicAPI, PluginRef, contentEngine } from 'content-engine';
|
|
73
74
|
|
|
74
75
|
export type HandleConfigAssets = <T extends Model>({ models, presets }: { models?: T[]; presets?: PresetMap }) => Promise<{ models: T[]; presets: PresetMap }>;
|
|
75
76
|
|
|
@@ -147,6 +148,7 @@ export class ContentStore {
|
|
|
147
148
|
private contentStoreEventQueue: ContentStoreEventQueue = [];
|
|
148
149
|
private treeViews: CSITypes.TreeViewNode[] = [];
|
|
149
150
|
private customActionRunStateMap: ContentStoreTypes.CustomActionRunStateMap = {};
|
|
151
|
+
private contentEngine?: ContentEnginePublicAPI | null;
|
|
150
152
|
|
|
151
153
|
constructor(options: ContentSourceOptions) {
|
|
152
154
|
this.logger = options.logger.createLogger({ label: 'content-store' });
|
|
@@ -388,6 +390,39 @@ export class ContentStore {
|
|
|
388
390
|
return presets;
|
|
389
391
|
}
|
|
390
392
|
|
|
393
|
+
/**
|
|
394
|
+
* If any content sources implement the `getContentEngineConfig` method then this function gets all
|
|
395
|
+
* of these plugin definitions and creates the content engine.
|
|
396
|
+
*/
|
|
397
|
+
private async createContentEngineIfNeeded() {
|
|
398
|
+
const logger = this.userLogger.createLogger({ label: 'content-engine' });
|
|
399
|
+
if (this.contentEngine) {
|
|
400
|
+
logger.info('stopping content engine');
|
|
401
|
+
this.contentEngine.clearListeners();
|
|
402
|
+
await this.contentEngine.stop();
|
|
403
|
+
this.contentEngine = null;
|
|
404
|
+
}
|
|
405
|
+
const plugins = this.contentSources?.flatMap((contentSource) => contentSource.getContentEngineConfig?.()).filter(Boolean) as PluginRef[];
|
|
406
|
+
if (plugins.length < 1) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
logger.info('creating content engine');
|
|
410
|
+
this.contentEngine = contentEngine({
|
|
411
|
+
directory: this.stackbitConfig?.dirPath,
|
|
412
|
+
engineConfig: {
|
|
413
|
+
plugins
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
this.contentEngine?.onStdOut((data) => {
|
|
418
|
+
logger.info(data.toString());
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
this.contentEngine?.onStdErr((data) => {
|
|
422
|
+
logger.error(data.toString());
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
391
426
|
/**
|
|
392
427
|
* This function reloads the data of the specified content-sources, while
|
|
393
428
|
* reusing the cached data of the rest of the content-sources, then processes
|
|
@@ -432,6 +467,14 @@ export class ContentStore {
|
|
|
432
467
|
|
|
433
468
|
this.contentSources = contentSources;
|
|
434
469
|
|
|
470
|
+
if (init) {
|
|
471
|
+
this.logger.debug('init content sources');
|
|
472
|
+
await this.createContentEngineIfNeeded();
|
|
473
|
+
await this.contentEngine?.sync({
|
|
474
|
+
runServer: true
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
435
478
|
const promises = contentSources.map((contentSourceInstance): Promise<ContentSourceRawData> => {
|
|
436
479
|
const contentSourceId = getContentSourceIdForContentSource(contentSourceInstance);
|
|
437
480
|
if (init || !contentSourceIds || contentSourceIds.includes(contentSourceId)) {
|
|
@@ -744,6 +787,10 @@ export class ContentStore {
|
|
|
744
787
|
return;
|
|
745
788
|
}
|
|
746
789
|
this.logger.debug('content source called updateContent', { contentSourceId });
|
|
790
|
+
await this.contentEngine?.sync({
|
|
791
|
+
buildSchema: false
|
|
792
|
+
});
|
|
793
|
+
|
|
747
794
|
this.pushContentSourceEvent({
|
|
748
795
|
eventName: ContentStoreEventType.ContentSourceContentChange,
|
|
749
796
|
contentSourceId: contentSourceId,
|
|
@@ -758,6 +805,9 @@ export class ContentStore {
|
|
|
758
805
|
return;
|
|
759
806
|
}
|
|
760
807
|
this.logger.debug('content source called invalidateSchema', { contentSourceId });
|
|
808
|
+
await this.contentEngine?.sync({
|
|
809
|
+
buildSchema: true
|
|
810
|
+
});
|
|
761
811
|
this.pushContentSourceEvent({
|
|
762
812
|
eventName: ContentStoreEventType.ContentSourceInvalidateSchema,
|
|
763
813
|
contentSourceId: contentSourceId
|
|
@@ -844,13 +844,10 @@ function findCustomActionById({
|
|
|
844
844
|
if (!model || (model.type !== 'page' && model.type !== 'data')) {
|
|
845
845
|
return undefined;
|
|
846
846
|
}
|
|
847
|
-
if (!('actions' in model) || !Array.isArray(model.actions)) {
|
|
848
|
-
return undefined;
|
|
849
|
-
}
|
|
850
847
|
if (typeof fieldPath === 'undefined') {
|
|
851
848
|
// fieldPath was not provided, therefore the model must be of type "page" or "data",
|
|
852
849
|
// and the action type must be 'document'
|
|
853
|
-
const action = model.actions
|
|
850
|
+
const action = model.actions?.find((action) => action.name === actionName);
|
|
854
851
|
if (!action) {
|
|
855
852
|
return undefined;
|
|
856
853
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as ContentStoreTypes from '../types';
|
|
2
|
-
import { SearchFilterItem } from '../types';
|
|
3
|
-
import { ScheduledAction } from '@stackbit/types';
|
|
4
|
-
import { SchemaForSearch } from './search-utils';
|
|
5
|
-
declare type CustomFilterMethod = (filter: SearchFilterItem, document: ContentStoreTypes.Document, opts: {
|
|
6
|
-
locale?: string;
|
|
7
|
-
schema: SchemaForSearch;
|
|
8
|
-
activeScheduledActionsByDocumentId: Record<string, ScheduledAction[]>;
|
|
9
|
-
}) => boolean;
|
|
10
|
-
export declare const CUSTOM_FILTERS: Record<string, CustomFilterMethod>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=custom-search-filters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-search-filters.d.ts","sourceRoot":"","sources":["../../src/utils/custom-search-filters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAqB,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAiE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEhH,aAAK,kBAAkB,GAAG,CACtB,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EACpC,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,eAAe,CAAC;IAAC,kCAAkC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAAA;CAAE,KACxH,OAAO,CAAC;AAEb,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAwC7D,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CUSTOM_FILTERS = void 0;
|
|
4
|
-
const search_utils_1 = require("./search-utils");
|
|
5
|
-
exports.CUSTOM_FILTERS = {
|
|
6
|
-
hasSchedules: (filter, document, opts) => {
|
|
7
|
-
var _a;
|
|
8
|
-
const field = {
|
|
9
|
-
type: 'boolean',
|
|
10
|
-
value: !!((_a = opts.activeScheduledActionsByDocumentId[document.srcObjectId]) === null || _a === void 0 ? void 0 : _a.length)
|
|
11
|
-
};
|
|
12
|
-
return (0, search_utils_1.isBooleanFieldMatches)({ field, filter, locale: opts.locale });
|
|
13
|
-
},
|
|
14
|
-
scheduledActionId: (filter, document, opts) => {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
const field = {
|
|
17
|
-
type: 'list',
|
|
18
|
-
items: (_b = (_a = opts.activeScheduledActionsByDocumentId[document.srcObjectId]) === null || _a === void 0 ? void 0 : _a.map((scheduledAction) => ({
|
|
19
|
-
type: 'string',
|
|
20
|
-
value: scheduledAction.id
|
|
21
|
-
}))) !== null && _b !== void 0 ? _b : []
|
|
22
|
-
};
|
|
23
|
-
const model = {
|
|
24
|
-
type: 'object',
|
|
25
|
-
name: '',
|
|
26
|
-
fields: [
|
|
27
|
-
{
|
|
28
|
-
name: '',
|
|
29
|
-
type: 'list',
|
|
30
|
-
items: {
|
|
31
|
-
type: 'string'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
};
|
|
36
|
-
return (0, search_utils_1.isListFieldMatches)({ field, filter, model, locale: opts.locale, document });
|
|
37
|
-
},
|
|
38
|
-
scheduledActionDate: (filter, document, opts) => {
|
|
39
|
-
var _a, _b;
|
|
40
|
-
return ((_b = (_a = opts.activeScheduledActionsByDocumentId[document.srcObjectId]) === null || _a === void 0 ? void 0 : _a.some((scheduledAction) => {
|
|
41
|
-
const field = { type: 'date', value: scheduledAction.executeAt };
|
|
42
|
-
return (0, search_utils_1.isDateFieldMatches)({ field, filter, locale: opts.locale });
|
|
43
|
-
})) !== null && _b !== void 0 ? _b : false);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=custom-search-filters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-search-filters.js","sourceRoot":"","sources":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