@stackbit/cms-core 0.0.17 → 0.0.19-alpha.1

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.
Files changed (59) hide show
  1. package/dist/annotator/html.d.ts +1 -0
  2. package/dist/annotator/html.d.ts.map +1 -0
  3. package/dist/annotator/index.d.ts +3 -2
  4. package/dist/annotator/index.d.ts.map +1 -0
  5. package/dist/annotator/react.d.ts +1 -0
  6. package/dist/annotator/react.d.ts.map +1 -0
  7. package/dist/common/common-schema.d.ts +3 -10
  8. package/dist/common/common-schema.d.ts.map +1 -0
  9. package/dist/common/common-schema.js +3 -4
  10. package/dist/common/common-schema.js.map +1 -1
  11. package/dist/consts.d.ts +1 -0
  12. package/dist/consts.d.ts.map +1 -0
  13. package/dist/content-source-interface.d.ts +324 -0
  14. package/dist/content-source-interface.d.ts.map +1 -0
  15. package/dist/content-source-interface.js +28 -0
  16. package/dist/content-source-interface.js.map +1 -0
  17. package/dist/content-store-types.d.ts +328 -0
  18. package/dist/content-store-types.d.ts.map +1 -0
  19. package/dist/content-store-types.js +3 -0
  20. package/dist/content-store-types.js.map +1 -0
  21. package/dist/content-store.d.ts +207 -0
  22. package/dist/content-store.d.ts.map +1 -0
  23. package/dist/content-store.js +1743 -0
  24. package/dist/content-store.js.map +1 -0
  25. package/dist/encoder.d.ts +36 -7
  26. package/dist/encoder.d.ts.map +1 -0
  27. package/dist/encoder.js +63 -40
  28. package/dist/encoder.js.map +1 -1
  29. package/dist/index.d.ts +11 -6
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +37 -11
  32. package/dist/index.js.map +1 -1
  33. package/dist/stackbit/index.d.ts +7 -3
  34. package/dist/stackbit/index.d.ts.map +1 -0
  35. package/dist/stackbit/index.js +13 -10
  36. package/dist/stackbit/index.js.map +1 -1
  37. package/dist/utils/index.d.ts +8 -7
  38. package/dist/utils/index.d.ts.map +1 -0
  39. package/dist/utils/schema-utils.d.ts +3 -2
  40. package/dist/utils/schema-utils.d.ts.map +1 -0
  41. package/dist/utils/timer.d.ts +18 -0
  42. package/dist/utils/timer.d.ts.map +1 -0
  43. package/dist/utils/timer.js +36 -0
  44. package/dist/utils/timer.js.map +1 -0
  45. package/package.json +8 -4
  46. package/src/common/common-schema.ts +12 -0
  47. package/src/content-source-interface.ts +468 -0
  48. package/src/content-store-types.ts +416 -0
  49. package/src/content-store.ts +2233 -0
  50. package/src/{encoder.js → encoder.ts} +55 -17
  51. package/src/index.ts +10 -0
  52. package/src/stackbit/{index.js → index.ts} +5 -9
  53. package/src/utils/timer.ts +42 -0
  54. package/dist/utils/lazy-poller.d.ts +0 -21
  55. package/dist/utils/lazy-poller.js +0 -56
  56. package/dist/utils/lazy-poller.js.map +0 -1
  57. package/src/common/common-schema.js +0 -14
  58. package/src/index.js +0 -13
  59. package/src/utils/lazy-poller.ts +0 -74
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stackbit/index.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC5B,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAEjE,MAAM,CAAC,OAAO,GAAG;IACb,qBAAqB;CACxB,CAAC;AAEF,SAAS,qBAAqB,CAAC,OAAO;IAClC,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;QACxE,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;SACjC;QACD,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE;YAC1B,iBAAiB;YACjB,SAAS;YACT,YAAY;YACZ,aAAa;Y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YACjB,SAAS;YACT,YAAY;YACZ,aAAa;YACb,YAAY;YACZ,SAAS;YACT,QAAQ;YACR,YAAY;YACZ,WAAW;YACX,WAAW;YACX,QAAQ;YACR,SAAS;YACT,UAAU;YACV,eAAe;YACf,eAAe;YACf,cAAc;YACd,aAAa;YACb,eAAe;YACf,cAAc;YACd,QAAQ;YACR,SAAS;SACZ,CAAC,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC;AA/BD,sDA+BC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACtC,gBAAC,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;QAC/B,IAAI,CAAC,IAAA,qBAAe,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO;SACV;QACD,gBAAC,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE;YACnB;gBACI,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,KAAK,CAAC,KAAK;aACrB;SACJ,CAAC,CAAC;QACH,gBAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -50,16 +50,16 @@ export function copyFilesRecursively(sourceDir: string, targetDir: string, optio
50
50
  export function copy(sourceObject: Object, sourcePath: string, targetObject: Object, targetPath: string, transform?: Function | undefined): void;
51
51
  export function copyDefault(sourceObject: any, sourcePath: any, targetObject: any, targetPath: any, transform: any): void;
52
52
  export function mergeAtPath(object: any, path: any, source: any): any;
53
- export function omitByNil(object: any): any;
53
+ export function omitByNil(object: any): Partial<any>;
54
54
  export function rename(object: any, oldPath: any, newPath: any): void;
55
55
  export function append(object: any, path: any, value: any): void;
56
56
  export function concat(object: any, path: any, value: any): void;
57
57
  export function indent(str: any, indent: any, indentFirst?: boolean): any;
58
- export function pascalCase(str: any): any;
59
- export function readDirRec(dir: any, options: any): Promise<any>;
58
+ export function pascalCase(str: any): string;
59
+ export function readDirRec(dir: any, options: any): Promise<any[]>;
60
60
  export function readDirRecSync(dir: any, options: any): any[];
61
61
  export function readDirGlob(dir: any, options: any): Promise<any>;
62
- export function fieldPathToString(fieldPath: any): any;
62
+ export function fieldPathToString(fieldPath: any): string;
63
63
  export function hrtimeAndPrint(time: any): string | undefined;
64
64
  export function printHRTime(time: any): string | undefined;
65
65
  /**
@@ -93,7 +93,7 @@ export function mapDeep(value: any, iteratee: Function, options?: object | undef
93
93
  export function getFirst(object: Object, paths: Array<string | Array<string>>, defaultValue?: any): any;
94
94
  export function getFirstExistingFile(fileNames: any, inputDir: any): Promise<any>;
95
95
  export function parseFirstExistingFile(fileNames: any, inputDir: any): Promise<any>;
96
- export function getFirstExistingFileSync(fileNames: any, inputDir: any): any;
96
+ export function getFirstExistingFileSync(fileNames: any, inputDir: any): string;
97
97
  export function parseFirstExistingFileSync(fileNames: any, inputDir: any): any;
98
98
  export function parseFile(filePath: any): any;
99
99
  export function parseFileSync(filePath: any): any;
@@ -111,8 +111,8 @@ export function failFunctionWithTag(tag: any): (message: any) => never;
111
111
  export function assertFunctionWithFail(fail: any): (value: any, message: any) => void;
112
112
  export function createLogger(scope: any, transport: any): {};
113
113
  export function logObject(object: any, title: any): void;
114
- export function joinPathAndGlob(pathStr: any, glob: any): any;
115
- export function globToArray(glob: any): any;
114
+ export function joinPathAndGlob(pathStr: any, glob: any): string[];
115
+ export function globToArray(glob: any): never[];
116
116
  /**
117
117
  * Inverse of _.toPath()
118
118
  *
@@ -171,3 +171,4 @@ export function decodeJsx(data: any): any;
171
171
  export function replaceInRange(str: any, range: any, stringToInsert: any): any;
172
172
  export function isRelevantReactData(data: any): any;
173
173
  export function convertToPosixFilePath(filePath: any): any;
174
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":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3,12 @@ export function isObjectField(field: any): boolean;
3
3
  export function isModelField(field: any): boolean;
4
4
  export function isModelsField(field: any): boolean;
5
5
  export function isReferenceField(field: any): boolean;
6
- export function isCustomModelField(field: any, modelsByName: any): any;
6
+ export function isCustomModelField(field: any, modelsByName: any): boolean;
7
7
  export function isListField(field: any): boolean;
8
8
  export function isListOfObjectsField(field: any): boolean;
9
9
  export function isListOfModelField(field: any): boolean;
10
10
  export function isListOfModelsField(field: any): boolean;
11
- export function isListOfCustomModelField(field: any): any;
11
+ export function isListOfCustomModelField(field: any): boolean;
12
12
  export function isListOfReferenceField(field: any): boolean;
13
13
  /**
14
14
  * Gets a list field and returns its items field. If list field does not define
@@ -84,3 +84,4 @@ export function resolveLabelFieldForModel(model: any, modelLabelFieldPath: any,
84
84
  export function resolveLabelFieldFromFields(fields: any): any;
85
85
  export function getUrlPath(stackbitModel: any): any;
86
86
  export function getNormalizedModelType(stackbitModel: any): any;
87
+ //# sourceMappingURL=schema-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../src/utils/schema-utils.js"],"names":[],"mappings":"AAEA,mCAuBE;AA6CF,mDAEC;AAUD,kDAEC;AAED,mDAEC;AAdD,sDAEC;AAED,2EAEC;AAUD,iDAEC;AAED,0DAEC;AAED,wDAEC;AAED,yDAEC;AAED,8DAEC;AAED,4DAEC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,yCAHW,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qDAJW,MAAM,2DAgBhB;AAtJD,kGAMC;AAED,8DAWC;AAqID,oDAMC;AAED,gEAEC"}
@@ -0,0 +1,18 @@
1
+ import { Logger } from '../content-store-types';
2
+ export declare class Timer {
3
+ private readonly timerCallback;
4
+ private readonly timerMs;
5
+ private readonly logger?;
6
+ private timeout;
7
+ constructor({ timerCallback, timerMs, logger }: {
8
+ timerCallback: () => void;
9
+ timerMs?: number;
10
+ logger?: Logger;
11
+ });
12
+ isRunning(): boolean;
13
+ startTimer(): void;
14
+ resetTimer(): void;
15
+ stopTimer(): void;
16
+ handleTimeout(): void;
17
+ }
18
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/utils/timer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAa;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,OAAO,CAAwB;gBAE3B,EAAE,aAAa,EAAE,OAAwB,EAAE,MAAM,EAAE,EAAE;QAAE,aAAa,EAAE,MAAM,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAQjI,SAAS;IAIT,UAAU;IAIV,UAAU;IAKV,SAAS;IAOT,aAAa;CAKhB"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Timer = void 0;
4
+ class Timer {
5
+ constructor({ timerCallback, timerMs = 30 * 60 * 1000, logger }) {
6
+ this.timerCallback = timerCallback;
7
+ this.timerMs = timerMs;
8
+ this.logger = logger === null || logger === void 0 ? void 0 : logger.createLogger({ label: 'timer' });
9
+ this.timeout = null;
10
+ this.handleTimeout = this.handleTimeout.bind(this);
11
+ }
12
+ isRunning() {
13
+ return !!this.timeout;
14
+ }
15
+ startTimer() {
16
+ this.resetTimer();
17
+ }
18
+ resetTimer() {
19
+ this.stopTimer();
20
+ this.timeout = setTimeout(this.handleTimeout, this.timerMs);
21
+ }
22
+ stopTimer() {
23
+ if (this.timeout) {
24
+ clearTimeout(this.timeout);
25
+ this.timeout = null;
26
+ }
27
+ }
28
+ handleTimeout() {
29
+ var _a;
30
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('timer reached');
31
+ this.timeout = null;
32
+ this.timerCallback();
33
+ }
34
+ }
35
+ exports.Timer = Timer;
36
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/utils/timer.ts"],"names":[],"mappings":";;;AAEA,MAAa,KAAK;IAMd,YAAY,EAAE,aAAa,EAAE,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,EAAoE;QAC7H,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,SAAS;QACL,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,UAAU;QACN,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAED,UAAU;QACN,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAChE,CAAC;IAED,SAAS;QACL,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;SACvB;IACL,CAAC;IAED,aAAa;;QACT,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,aAAa,EAAE,CAAC;IACzB,CAAC;CACJ;AAvCD,sBAuCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbit/cms-core",
3
- "version": "0.0.17",
3
+ "version": "0.0.19-alpha.1",
4
4
  "description": "stackbit-dev",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  "author": "Stackbit Inc.",
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
+ "@types/lodash": "^4.14.182",
21
22
  "jest": "^27.4.7",
22
23
  "prettier": "^2.5.1",
23
24
  "ts-jest": "^27.1.3",
@@ -27,7 +28,8 @@
27
28
  "@babel/parser": "^7.11.5",
28
29
  "@babel/traverse": "^7.11.5",
29
30
  "@iarna/toml": "^2.2.3",
30
- "@stackbit/sdk": "^0.2.35",
31
+ "@stackbit/sdk": "^0.2.36-alpha.0",
32
+ "@stackbit/utils": "^0.2.4-alpha.0",
31
33
  "chalk": "^4.0.1",
32
34
  "esm": "^3.2.25",
33
35
  "fs-extra": "^8.1.0",
@@ -37,7 +39,9 @@
37
39
  "lodash": "^4.17.20",
38
40
  "micromatch": "^4.0.2",
39
41
  "moment": "^2.29.1",
40
- "parse5": "^6.0.1"
42
+ "parse5": "^6.0.1",
43
+ "sanitize-filename": "^1.6.3",
44
+ "slugify": "^1.6.5"
41
45
  },
42
- "gitHead": "ff31bc161f97408414a28557e7f1ed9a75afec5b"
46
+ "gitHead": "320bb64ea35d20b488c1ed75f673d58b010519a4"
43
47
  }
@@ -0,0 +1,12 @@
1
+ import type { ImageModel } from '@stackbit/sdk';
2
+
3
+ export const IMAGE_MODEL: ImageModel = {
4
+ type: 'image',
5
+ name: '__image_model',
6
+ label: 'Image',
7
+ labelField: 'title',
8
+ fields: [
9
+ { name: 'title', type: 'string' },
10
+ { name: 'url', type: 'string' }
11
+ ]
12
+ };
@@ -0,0 +1,468 @@
1
+ import type { Model, Field } from '@stackbit/sdk';
2
+
3
+ export type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted';
4
+
5
+ export interface LeveledLogMethod {
6
+ (message: string): void;
7
+ (message: string, ...meta: any[]): void;
8
+ (message: any): void;
9
+ }
10
+
11
+ export interface Logger {
12
+ error: LeveledLogMethod;
13
+ warn: LeveledLogMethod;
14
+ info: LeveledLogMethod;
15
+ debug: LeveledLogMethod;
16
+ createLogger: ({ label }: { label: string }) => Logger;
17
+ }
18
+
19
+ export interface Locale {
20
+ code: string;
21
+ default?: boolean;
22
+ }
23
+
24
+ export interface Document<DocumentContext = unknown> {
25
+ type: 'document';
26
+ id: string;
27
+ manageUrl: string;
28
+ modelName: string;
29
+ status: DocumentStatus;
30
+ createdAt: string;
31
+ createdBy?: string;
32
+ updatedAt: string;
33
+ updatedBy?: string[];
34
+ fields: Record<string, DocumentField>;
35
+ context: DocumentContext;
36
+ }
37
+
38
+ export interface Asset<AssetContext = unknown> {
39
+ type: 'asset';
40
+ id: string;
41
+ manageUrl: string;
42
+ status: DocumentStatus;
43
+ createdAt: string;
44
+ createdBy?: string;
45
+ updatedAt: string;
46
+ updatedBy?: string[];
47
+ fields: AssetFields;
48
+ context: AssetContext;
49
+ }
50
+
51
+ export type AssetFields = {
52
+ title: DocumentValueFieldForType<'string'>;
53
+ file: AssetFileField;
54
+ };
55
+
56
+ export type DocumentField = DocumentValueField | DocumentObjectField | DocumentModelField | DocumentReferenceField | DocumentListField | DocumentRichTextField;
57
+
58
+ export type DocumentFieldLocalized =
59
+ | DocumentValueFieldLocalized
60
+ | DocumentObjectFieldLocalized
61
+ | DocumentModelFieldLocalized
62
+ | DocumentReferenceFieldLocalized
63
+ | DocumentListFieldLocalized
64
+ | DocumentRichTextFieldLocalized;
65
+
66
+ export type DocumentFieldNonLocalized =
67
+ | DocumentValueFieldNonLocalized
68
+ | DocumentObjectFieldNonLocalized
69
+ | DocumentModelFieldNonLocalized
70
+ | DocumentReferenceFieldNonLocalized
71
+ | DocumentListFieldNonLocalized
72
+ | DocumentRichTextFieldNonLocalized;
73
+
74
+ export type DocumentFieldBaseProps =
75
+ | DocumentValueFieldBaseProps
76
+ | DocumentObjectFieldBase
77
+ | DocumentModelFieldBase
78
+ | DocumentReferenceFieldBase
79
+ | DocumentListFieldBase
80
+ | DocumentRichTextFieldBase;
81
+
82
+ export type DocumentFieldSpecificProps =
83
+ | DocumentValueFieldProps
84
+ | DocumentObjectFieldProps
85
+ | DocumentModelFieldProps
86
+ | DocumentReferenceFieldProps
87
+ | DocumentListFieldProps
88
+ | DocumentRichTextFieldProps;
89
+
90
+ export function isLocalizedField(field: DocumentField | AssetFileField): field is DocumentFieldLocalized | AssetFileFieldLocalized {
91
+ return !!field.localized;
92
+ }
93
+
94
+ export function getLocalizedFieldForLocale<Type extends FieldType>(
95
+ field: DocumentFieldForType<Type>,
96
+ locale?: string
97
+ ): DocumentFieldNonLocalizedForType<Type> | null {
98
+ if (field.localized) {
99
+ if (!locale) {
100
+ return null;
101
+ }
102
+ const { localized, locales, ...base } = field;
103
+ const localizedField = locales[locale];
104
+ if (!localizedField) {
105
+ return null;
106
+ }
107
+ return ({
108
+ ...base,
109
+ ...localizedField
110
+ } as unknown) as DocumentFieldNonLocalizedForType<Type>;
111
+ } else {
112
+ return field;
113
+ }
114
+ }
115
+
116
+ export type FieldType =
117
+ | 'string'
118
+ | 'url'
119
+ | 'slug'
120
+ | 'text'
121
+ | 'markdown'
122
+ | 'html'
123
+ | 'number'
124
+ | 'boolean'
125
+ | 'enum'
126
+ | 'date'
127
+ | 'datetime'
128
+ | 'color'
129
+ | 'image'
130
+ | 'file'
131
+ | 'json'
132
+ | 'richText'
133
+ | 'object'
134
+ | 'model'
135
+ | 'reference'
136
+ | 'style'
137
+ | 'list';
138
+
139
+ export type Simplify<T> = {
140
+ [K in keyof T]: T[K];
141
+ };
142
+
143
+ export type FindByType<Union extends { type: FieldType }, Type> = Union extends { type: Type } ? Union : never;
144
+ export type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>;
145
+ export type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>;
146
+ export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>;
147
+ export type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>;
148
+ export type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify<
149
+ Omit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'locale' | 'localized'>
150
+ >;
151
+
152
+ export type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
153
+ BaseFieldProps & {
154
+ localized: true;
155
+ locales: Record<string, { locale: string } & LocalizedFieldProps>;
156
+ }
157
+ >;
158
+
159
+ export type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
160
+ BaseFieldProps &
161
+ LocalizedFieldProps & {
162
+ localized?: false;
163
+ locale?: string;
164
+ }
165
+ >;
166
+
167
+ // any field that is not 'object' | 'model' | 'reference' | 'richText' | 'list'
168
+ export type DocumentValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'richText' | 'list'>;
169
+
170
+ export type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType
171
+ ? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type>
172
+ : never;
173
+ export type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>;
174
+
175
+ export type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType
176
+ ? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
177
+ : never;
178
+ export type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>;
179
+
180
+ export type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType
181
+ ? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
182
+ : never;
183
+ export type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>;
184
+
185
+ export type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldBase<Type> : never;
186
+ export type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>;
187
+ export type DocumentValueFieldBase<Type extends DocumentValueFieldType> = {
188
+ type: Type;
189
+ };
190
+ export type DocumentValueFieldProps = {
191
+ value: any;
192
+ };
193
+
194
+ // object
195
+ export type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized;
196
+ export type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
197
+ export type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
198
+ export type DocumentObjectFieldBase = {
199
+ type: 'object';
200
+ };
201
+ export type DocumentObjectFieldProps = {
202
+ fields: Record<string, DocumentField>;
203
+ };
204
+
205
+ // model
206
+ export type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized;
207
+ export type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
208
+ export type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
209
+ export type DocumentModelFieldBase = {
210
+ type: 'model';
211
+ };
212
+ export type DocumentModelFieldProps = {
213
+ modelName: string;
214
+ fields: Record<string, DocumentField>;
215
+ };
216
+
217
+ // reference
218
+ export type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized;
219
+ export type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
220
+ export type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
221
+ export type DocumentReferenceFieldBase = {
222
+ type: 'reference';
223
+ refType: 'document' | 'asset';
224
+ };
225
+ export type DocumentReferenceFieldProps = {
226
+ refId: string;
227
+ };
228
+
229
+ // richText
230
+ export type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized;
231
+ export type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
232
+ export type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
233
+ export type DocumentRichTextFieldBase = {
234
+ type: 'richText';
235
+ };
236
+ export type DocumentRichTextFieldProps = {
237
+ hint?: string;
238
+ value: any;
239
+ };
240
+
241
+ // list
242
+ export type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized;
243
+ export type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>;
244
+ export type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentListFieldBase, DocumentListFieldProps>;
245
+ export type DocumentListFieldBase = {
246
+ type: 'list';
247
+ };
248
+ export type DocumentListFieldProps = {
249
+ items: DocumentFieldNonLocalized[];
250
+ };
251
+
252
+ // assetFile
253
+ export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized;
254
+ export type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>;
255
+ export type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>;
256
+ export type AssetFileFieldBase = {
257
+ type: 'assetFile';
258
+ };
259
+ export type AssetFileFieldProps = {
260
+ url: string;
261
+ fileName?: string;
262
+ contentType?: string;
263
+ size?: number;
264
+ dimensions: {
265
+ width?: number;
266
+ height?: number;
267
+ };
268
+ };
269
+
270
+ export interface InitOptions {
271
+ logger: Logger;
272
+ userLogger: Logger;
273
+ localDev: boolean;
274
+ }
275
+
276
+ export interface ContentChangeEvent<DocumentContext = unknown, AssetContext = unknown> {
277
+ documents: Document<DocumentContext>[];
278
+ assets: Asset<AssetContext>[];
279
+ deletedDocumentIds: string[];
280
+ deletedAssetIds: string[];
281
+ }
282
+
283
+ export type UpdateOperation = UpdateOperationSet | UpdateOperationUnset | UpdateOperationInsert | UpdateOperationRemove | UpdateOperationReorder;
284
+
285
+ export type UpdateOperationBase = {
286
+ opType: string;
287
+ fieldPath: (string | number)[];
288
+ modelField: Field;
289
+ locale?: string;
290
+ };
291
+
292
+ export type UpdateOperationSet = Simplify<
293
+ UpdateOperationBase & {
294
+ opType: 'set';
295
+ field: UpdateOperationField;
296
+ }
297
+ >;
298
+
299
+ export type UpdateOperationUnset = Simplify<
300
+ UpdateOperationBase & {
301
+ opType: 'unset';
302
+ }
303
+ >;
304
+
305
+ export type UpdateOperationInsert = Simplify<
306
+ UpdateOperationBase & {
307
+ opType: 'insert';
308
+ index?: number;
309
+ item: UpdateOperationField;
310
+ }
311
+ >;
312
+
313
+ export type UpdateOperationRemove = Simplify<
314
+ UpdateOperationBase & {
315
+ opType: 'remove';
316
+ index: number;
317
+ }
318
+ >;
319
+
320
+ export type UpdateOperationReorder = Simplify<
321
+ UpdateOperationBase & {
322
+ opType: 'reorder';
323
+ order: number[];
324
+ }
325
+ >;
326
+
327
+ export type UpdateOperationField =
328
+ | UpdateOperationValueField
329
+ | UpdateOperationObjectField
330
+ | UpdateOperationModelField
331
+ | UpdateOperationReferenceField
332
+ | UpdateOperationListField;
333
+
334
+ export type UpdateOperationValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'list'>;
335
+ export type UpdateOperationValueField<Type = UpdateOperationValueFieldType> = Type extends UpdateOperationValueFieldType
336
+ ? UpdateOperationValueFieldForType<Type>
337
+ : never;
338
+ export type UpdateOperationValueFieldForType<Type extends UpdateOperationValueFieldType> = {
339
+ type: Type;
340
+ value: any;
341
+ };
342
+
343
+ export type UpdateOperationObjectField = {
344
+ type: 'object';
345
+ fields: Record<string, UpdateOperationField>;
346
+ };
347
+
348
+ export type UpdateOperationModelField = {
349
+ type: 'model';
350
+ modelName: string;
351
+ fields: Record<string, UpdateOperationField>;
352
+ };
353
+
354
+ export type UpdateOperationReferenceField = {
355
+ type: 'reference';
356
+ refType: 'document' | 'asset';
357
+ refId: string;
358
+ };
359
+
360
+ export type UpdateOperationListField = {
361
+ type: 'list';
362
+ items: UpdateOperationField[];
363
+ }
364
+
365
+ export type ValidationError = {
366
+ message: string;
367
+ objectType: 'document' | 'asset';
368
+ objectId: string;
369
+ fieldPath: (string | number)[];
370
+ isUniqueValidation?: boolean;
371
+ };
372
+
373
+ export type ModelMap = Record<string, Model>;
374
+
375
+ export interface ContentSourceInterface<UserContext = unknown, DocumentContext = unknown, AssetContext = unknown> {
376
+ /**
377
+ * This function should return the type of the content source.
378
+ * The type must be unique among other content sources within the same project.
379
+ */
380
+ getContentSourceType(): string;
381
+
382
+ /**
383
+ * This function should return the project ID of the content source.
384
+ * The ID must be unique among other content sources of the same type.
385
+ */
386
+ getProjectId(): string;
387
+
388
+ getProjectEnvironment(): string;
389
+
390
+ getProjectManageUrl(): string;
391
+
392
+ /**
393
+ * This function should initialize the content source by fetching the schema
394
+ * and everything else needed to produce the StackbitSchema
395
+ */
396
+ init(options: InitOptions): Promise<void>;
397
+
398
+ reset(): Promise<void>;
399
+
400
+ onFilesChange?({
401
+ updatedFiles
402
+ }: {
403
+ updatedFiles: string[];
404
+ }): { schemaChanged?: boolean; contentChangeEvent?: ContentChangeEvent<DocumentContext, AssetContext> };
405
+
406
+ startWatchingContentUpdates(options: {
407
+ getModelMap: () => ModelMap;
408
+ getDocument: ({ documentId }: { documentId: string }) => Document<DocumentContext> | undefined;
409
+ getAsset: ({ assetId }: { assetId: string }) => Asset<AssetContext> | undefined;
410
+ onContentChange: (contentChangeEvent: ContentChangeEvent<DocumentContext, AssetContext>) => void;
411
+ onSchemaChange: () => void;
412
+ }): void;
413
+
414
+ stopWatchingContentUpdates(): void;
415
+
416
+ /**
417
+ * This function is responsible to fetch and convert content models
418
+ * to Stackbit models.
419
+ */
420
+ getModels(): Promise<Model[]>;
421
+
422
+ getLocales(): Promise<Locale[]>;
423
+
424
+ /**
425
+ * This function should fetch the documents and convert them into Stackbit's
426
+ * Document type
427
+ */
428
+ getDocuments(options: { modelMap: ModelMap }): Promise<Document<DocumentContext>[]>;
429
+
430
+ getAssets(): Promise<Asset<AssetContext>[]>;
431
+
432
+ hasAccess(options: { userContext?: UserContext }): Promise<boolean>;
433
+
434
+ createDocument(options: {
435
+ documentFields: Record<string, DocumentField>;
436
+ model: Model;
437
+ modelMap: ModelMap;
438
+ locale?: string;
439
+ userContext?: UserContext;
440
+ }): Promise<Document<DocumentContext>>;
441
+
442
+ updateDocument(options: {
443
+ document: Document<DocumentContext>;
444
+ operations: UpdateOperation[];
445
+ modelMap: ModelMap;
446
+ userContext?: UserContext;
447
+ }): Promise<Document<DocumentContext>>;
448
+
449
+ deleteDocument(options: { document: Document<DocumentContext>; userContext?: UserContext }): Promise<void>;
450
+
451
+ uploadAsset(options: {
452
+ url?: string;
453
+ base64?: string;
454
+ fileName: string;
455
+ mimeType: string;
456
+ locale?: string;
457
+ userContext?: UserContext;
458
+ }): Promise<Asset<AssetContext>>;
459
+
460
+ validateDocuments(options: {
461
+ documents: Document<DocumentContext>[];
462
+ assets: Asset<AssetContext>[];
463
+ locale?: string;
464
+ userContext?: UserContext;
465
+ }): Promise<{ errors: ValidationError[] }>;
466
+
467
+ publishDocuments(options: { documents: Document<DocumentContext>[]; assets: Asset<AssetContext>[]; userContext?: UserContext }): Promise<void>;
468
+ }