@stackbit/cms-core 0.0.15 → 0.0.18-alpha.0

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 +292 -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 +324 -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 +1643 -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 +417 -0
  48. package/src/content-store-types.ts +406 -0
  49. package/src/content-store.ts +2112 -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
@@ -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":"AAkEA;;;;;;;;;;;GAWG;AACH,8FAFY,QAAQ,GAAG,CAAC,CAoBvB;AAED,kFAsBC;AAED,qGAmBC;AAyBD,mFAwBC;AAED,gHAsEC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,gDARW,MAAM,aACN,MAAM;;iBAIN,MAAM;4CAmDhB;AAED;;;;;;;;GAQG;AACH,mCANW,MAAM,oCAEN,MAAM,8DAYhB;AAED,0HAIC;AAED,sEAQC;AAED,qDAEC;AAED,sEASC;AAED,iEAKC;AAED,iEAKC;AAED,0EAKC;AAED,6CAEC;AAED,mEAuBC;AA2BD,8DAoBC;AA7CD,kEAuBC;AAwBD,0DAmBC;AAED,8DAGC;AAED,2DAWC;AAED;;;;;;;GAOG;AACH,iEAHW,MAAM,GAAC,MAAM,UACb,MAAM,QAahB;AAgBD;;;;;;;;GAQG;AACH,6HAsBC;AA7CD;;;;;;;;GAQG;AACH,iCALW,MAAM,SACN,MAAM,SAAS,aAAa,CAAC,2BAOvC;AAmCD,kFAKC;AAED,oFAOC;AAED,gFAKC;AAED,+EAOC;AAED,8CAIC;AAED,kDAGC;AAED,qEA4BC;AAED,0DAGC;AAaD,+DAGC;AAdD,+EASC;AAOD,uEA2BC;AAED;;;EA+DC;AAED,0CAeC;AAED,uEAIC;AAED,sFAMC;AAED,6DAaC;AAED,yDAUC;AAED,mEAGC;AAED,gDASC;AAED;;;;;;;;GAQG;AACH,mDAWC;AAED,uDAOC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,sCAJW,QAAM,MAAM,0BAEX;IAAC,IAAI,EAAE,QAAM,MAAM,CAAC;IAAC,MAAM,QAAO;CAAC,CAuB9C;AAED;;;;;;GAMG;AACH,kCAJW,QAAM,MAAM,0BAEX;IAAC,IAAI,EAAE,QAAM,MAAM,CAAC;IAAC,MAAM,QAAO;CAAC,CAwB9C;AAUD,0CAOC;AAED,0CAOC;AAED,+EAEC;AAED,oDAMC;AAED,2DAYC"}
@@ -3,12 +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.15",
3
+ "version": "0.0.18-alpha.0",
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.33",
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": "ab310b516daf58c88b67f1fb8fbc6ec815a7f44d"
46
+ "gitHead": "4f0d10545fffc1b66b9774786949362ecfd06fbe"
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,417 @@
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 {
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
+ }
36
+
37
+ export interface Asset {
38
+ type: 'asset';
39
+ id: string;
40
+ manageUrl: string;
41
+ status: DocumentStatus;
42
+ createdAt: string;
43
+ createdBy?: string;
44
+ updatedAt: string;
45
+ updatedBy?: string[];
46
+ fields: AssetFields;
47
+ }
48
+
49
+ export type AssetFields = {
50
+ title: DocumentValueFieldForType<'string'>;
51
+ file: AssetFileField;
52
+ };
53
+
54
+ export type DocumentField = DocumentValueField | DocumentObjectField | DocumentModelField | DocumentReferenceField | DocumentListField | DocumentRichTextField;
55
+
56
+ export type DocumentFieldLocalized =
57
+ | DocumentValueFieldLocalized
58
+ | DocumentObjectFieldLocalized
59
+ | DocumentModelFieldLocalized
60
+ | DocumentReferenceFieldLocalized
61
+ | DocumentListFieldLocalized
62
+ | DocumentRichTextFieldLocalized;
63
+
64
+ export type DocumentFieldNonLocalized =
65
+ | DocumentValueFieldNonLocalized
66
+ | DocumentObjectFieldNonLocalized
67
+ | DocumentModelFieldNonLocalized
68
+ | DocumentReferenceFieldNonLocalized
69
+ | DocumentListFieldNonLocalized
70
+ | DocumentRichTextFieldNonLocalized;
71
+
72
+ export type DocumentFieldBaseProps =
73
+ | DocumentValueFieldBaseProps
74
+ | DocumentObjectFieldBase
75
+ | DocumentModelFieldBase
76
+ | DocumentReferenceFieldBase
77
+ | DocumentListFieldBase
78
+ | DocumentRichTextFieldBase;
79
+
80
+ export type DocumentFieldSpecificProps =
81
+ | DocumentValueFieldProps
82
+ | DocumentObjectFieldProps
83
+ | DocumentModelFieldProps
84
+ | DocumentReferenceFieldProps
85
+ | DocumentListFieldProps
86
+ | DocumentRichTextFieldProps;
87
+
88
+ export function isLocalizedField(field: DocumentField | AssetFileField): field is DocumentFieldLocalized | AssetFileFieldLocalized {
89
+ return 'localized' in field;
90
+ }
91
+
92
+ export function getLocalizedFieldForLocale<Type extends FieldType>(
93
+ field: DocumentFieldForType<Type>,
94
+ locale?: string
95
+ ): DocumentFieldNonLocalizedForType<Type> | null {
96
+ if (field.localized) {
97
+ if (!locale) {
98
+ return null;
99
+ }
100
+ const { localized, locales, ...base } = field;
101
+ const localizedField = locales[locale];
102
+ if (!localizedField) {
103
+ return null;
104
+ }
105
+ return ({
106
+ ...base,
107
+ ...localizedField
108
+ } as unknown) as DocumentFieldNonLocalizedForType<Type>;
109
+ } else {
110
+ return field;
111
+ }
112
+ }
113
+
114
+ export type FieldType =
115
+ | 'string'
116
+ | 'url'
117
+ | 'slug'
118
+ | 'text'
119
+ | 'markdown'
120
+ | 'html'
121
+ | 'number'
122
+ | 'boolean'
123
+ | 'enum'
124
+ | 'date'
125
+ | 'datetime'
126
+ | 'color'
127
+ | 'image'
128
+ | 'file'
129
+ | 'json'
130
+ | 'richText'
131
+ | 'object'
132
+ | 'model'
133
+ | 'reference'
134
+ | 'style'
135
+ | 'list';
136
+
137
+ export type Simplify<T> = {
138
+ [K in keyof T]: T[K];
139
+ };
140
+
141
+ export type FindByType<Union extends { type: FieldType }, Type> = Union extends { type: Type } ? Union : never;
142
+ export type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>;
143
+ export type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>;
144
+ export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>;
145
+ export type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>;
146
+ export type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify<
147
+ Omit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'locale' | 'localized'>
148
+ >;
149
+
150
+ export type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
151
+ BaseFieldProps & {
152
+ localized: true;
153
+ locales: Record<string, { locale: string } & LocalizedFieldProps>;
154
+ }
155
+ >;
156
+
157
+ export type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
158
+ BaseFieldProps &
159
+ LocalizedFieldProps & {
160
+ localized?: false;
161
+ locale?: string;
162
+ }
163
+ >;
164
+
165
+ // any field that is not 'object' | 'model' | 'reference' | 'richText' | 'list'
166
+ export type DocumentValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'richText' | 'list'>;
167
+
168
+ export type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType
169
+ ? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type>
170
+ : never;
171
+ export type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>;
172
+
173
+ export type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType
174
+ ? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
175
+ : never;
176
+ export type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>;
177
+
178
+ export type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType
179
+ ? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
180
+ : never;
181
+ export type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>;
182
+
183
+ export type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldBase<Type> : never;
184
+ export type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>;
185
+ export type DocumentValueFieldBase<Type extends DocumentValueFieldType> = {
186
+ type: Type;
187
+ };
188
+ export type DocumentValueFieldProps = {
189
+ value: any;
190
+ };
191
+
192
+ // object
193
+ export type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized;
194
+ export type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
195
+ export type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
196
+ export type DocumentObjectFieldBase = {
197
+ type: 'object';
198
+ };
199
+ export type DocumentObjectFieldProps = {
200
+ fields: Record<string, DocumentField>;
201
+ };
202
+
203
+ // model
204
+ export type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized;
205
+ export type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
206
+ export type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
207
+ export type DocumentModelFieldBase = {
208
+ type: 'model';
209
+ };
210
+ export type DocumentModelFieldProps = {
211
+ modelName: string;
212
+ fields: Record<string, DocumentField>;
213
+ };
214
+
215
+ // reference
216
+ export type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized;
217
+ export type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
218
+ export type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
219
+ export type DocumentReferenceFieldBase = {
220
+ type: 'reference';
221
+ refType: 'document' | 'asset';
222
+ };
223
+ export type DocumentReferenceFieldProps = {
224
+ refId: string;
225
+ };
226
+
227
+ // richText
228
+ export type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized;
229
+ export type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
230
+ export type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
231
+ export type DocumentRichTextFieldBase = {
232
+ type: 'richText';
233
+ };
234
+ export type DocumentRichTextFieldProps = {
235
+ hint?: string;
236
+ value: any;
237
+ };
238
+
239
+ // list
240
+ export type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized;
241
+ export type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>;
242
+ export type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentListFieldBase, DocumentListFieldProps>;
243
+ export type DocumentListFieldBase = {
244
+ type: 'list';
245
+ };
246
+ export type DocumentListFieldProps = {
247
+ items: DocumentFieldNonLocalized[];
248
+ };
249
+
250
+ // assetFile
251
+ export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized;
252
+ export type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>;
253
+ export type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>;
254
+ export type AssetFileFieldBase = {
255
+ type: 'assetFile';
256
+ };
257
+ export type AssetFileFieldProps = {
258
+ url: string;
259
+ fileName?: string;
260
+ contentType?: string;
261
+ size?: number;
262
+ dimensions: {
263
+ width?: number;
264
+ height?: number;
265
+ };
266
+ };
267
+
268
+ export interface InitOptions {
269
+ logger: Logger;
270
+ userLogger: Logger;
271
+ localDev: boolean;
272
+ }
273
+
274
+ export interface ContentChangeEvent {
275
+ documents: Document[];
276
+ assets: Asset[];
277
+ deletedDocumentIds: string[];
278
+ deletedAssetIds: string[];
279
+ }
280
+
281
+ export type UpdateOperation = UpdateOperationSet | UpdateOperationUnset | UpdateOperationInsert | UpdateOperationRemove | UpdateOperationReorder;
282
+
283
+ export type UpdateOperationBase = {
284
+ opType: string;
285
+ fieldPath: (string | number)[];
286
+ modelField: Field;
287
+ locale?: string;
288
+ };
289
+
290
+ export type UpdateOperationSet = Simplify<
291
+ UpdateOperationBase & {
292
+ opType: 'set';
293
+ field: UpdateOperationField;
294
+ }
295
+ >;
296
+
297
+ export type UpdateOperationUnset = Simplify<
298
+ UpdateOperationBase & {
299
+ opType: 'unset';
300
+ }
301
+ >;
302
+
303
+ export type UpdateOperationInsert = Simplify<
304
+ UpdateOperationBase & {
305
+ opType: 'insert';
306
+ index?: number;
307
+ item: UpdateOperationField;
308
+ }
309
+ >;
310
+
311
+ export type UpdateOperationRemove = Simplify<
312
+ UpdateOperationBase & {
313
+ opType: 'remove';
314
+ index: number;
315
+ }
316
+ >;
317
+
318
+ export type UpdateOperationReorder = Simplify<
319
+ UpdateOperationBase & {
320
+ opType: 'reorder';
321
+ order: number[];
322
+ }
323
+ >;
324
+
325
+ export type UpdateOperationField =
326
+ | DocumentValueFieldNonLocalized
327
+ | DocumentObjectFieldNonLocalized
328
+ | DocumentModelFieldNonLocalized
329
+ | DocumentReferenceFieldNonLocalized
330
+ | DocumentRichTextFieldNonLocalized;
331
+
332
+ export type ValidationError = {
333
+ message: string;
334
+ objectType: 'document' | 'asset';
335
+ objectId: string;
336
+ fieldPath: (string | number)[];
337
+ isUniqueValidation?: boolean;
338
+ };
339
+
340
+ export type ModelMap = Record<string, Model>;
341
+
342
+ export interface ContentSourceInterface<UserContext = unknown> {
343
+ /**
344
+ * This function should return the type of the content source.
345
+ * The type must be unique among other content sources within the same project.
346
+ */
347
+ getContentSourceType(): string;
348
+
349
+ /**
350
+ * This function should return the project ID of the content source.
351
+ * The ID must be unique among other content sources of the same type.
352
+ */
353
+ getProjectId(): string;
354
+
355
+ getProjectEnvironment(): string;
356
+
357
+ getProjectManageUrl(): string;
358
+
359
+ /**
360
+ * This function should initialize the content source by fetching the schema
361
+ * and everything else needed to produce the StackbitSchema
362
+ */
363
+ init(options: InitOptions): Promise<void>;
364
+
365
+ reset(): Promise<void>;
366
+
367
+ onFilesChange?({ updatedFiles }: { updatedFiles: string[] }): { schemaChanged?: boolean; contentChangeEvent?: ContentChangeEvent };
368
+
369
+ startWatchingContentUpdates(options: {
370
+ getModelMap: () => ModelMap;
371
+ onContentChange: (contentChangeEvent: ContentChangeEvent) => void;
372
+ onSchemaChange: () => void;
373
+ }): void;
374
+
375
+ stopWatchingContentUpdates(): void;
376
+
377
+ /**
378
+ * This function is responsible to fetch and convert content models
379
+ * to Stackbit models.
380
+ */
381
+ getModels(): Promise<Model[]>;
382
+
383
+ getLocales(): Promise<Locale[]>;
384
+
385
+ /**
386
+ * This function should fetch the documents and convert them into Stackbit's
387
+ * Document type
388
+ */
389
+ getDocuments(options: { modelMap: ModelMap }): Promise<Document[]>;
390
+
391
+ getAssets(): Promise<Asset[]>;
392
+
393
+ hasAccess(options: { userContext?: UserContext }): Promise<boolean>;
394
+
395
+ createDocument(options: {
396
+ documentFields: Record<string, DocumentField>;
397
+ model: Model;
398
+ modelMap: ModelMap;
399
+ locale?: string;
400
+ userContext?: UserContext;
401
+ }): Promise<Document>;
402
+
403
+ updateDocument(options: { documentId: string; operations: UpdateOperation[]; modelMap: ModelMap; userContext?: UserContext }): Promise<Document>;
404
+
405
+ deleteDocument(options: { documentId: string; userContext?: UserContext }): Promise<void>;
406
+
407
+ uploadAsset(options: { url?: string; base64?: string; fileName: string; mimeType: string; locale?: string; userContext?: UserContext }): Promise<Asset>;
408
+
409
+ validateDocuments(options: {
410
+ documentIds: string[];
411
+ assetIds: string[];
412
+ locale?: string;
413
+ userContext?: UserContext;
414
+ }): Promise<{ errors: ValidationError[] }>;
415
+
416
+ publishDocuments(options: { documentIds: string[]; assetIds: string[]; userContext?: UserContext }): Promise<void>;
417
+ }