@stackbit/cms-core 0.0.20 → 0.0.21-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.
Files changed (64) 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/common/common-types.d.ts +10 -0
  12. package/dist/common/common-types.d.ts.map +1 -0
  13. package/dist/common/common-types.js +3 -0
  14. package/dist/common/common-types.js.map +1 -0
  15. package/dist/consts.d.ts +1 -0
  16. package/dist/consts.d.ts.map +1 -0
  17. package/dist/content-source-interface.d.ts +338 -0
  18. package/dist/content-source-interface.d.ts.map +1 -0
  19. package/dist/content-source-interface.js +28 -0
  20. package/dist/content-source-interface.js.map +1 -0
  21. package/dist/content-store-types.d.ts +347 -0
  22. package/dist/content-store-types.d.ts.map +1 -0
  23. package/dist/content-store-types.js +3 -0
  24. package/dist/content-store-types.js.map +1 -0
  25. package/dist/content-store.d.ts +210 -0
  26. package/dist/content-store.d.ts.map +1 -0
  27. package/dist/content-store.js +1814 -0
  28. package/dist/content-store.js.map +1 -0
  29. package/dist/encoder.d.ts +36 -7
  30. package/dist/encoder.d.ts.map +1 -0
  31. package/dist/encoder.js +63 -40
  32. package/dist/encoder.js.map +1 -1
  33. package/dist/index.d.ts +12 -6
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +38 -11
  36. package/dist/index.js.map +1 -1
  37. package/dist/stackbit/index.d.ts +7 -3
  38. package/dist/stackbit/index.d.ts.map +1 -0
  39. package/dist/stackbit/index.js +13 -10
  40. package/dist/stackbit/index.js.map +1 -1
  41. package/dist/utils/index.d.ts +8 -7
  42. package/dist/utils/index.d.ts.map +1 -0
  43. package/dist/utils/schema-utils.d.ts +3 -2
  44. package/dist/utils/schema-utils.d.ts.map +1 -0
  45. package/dist/utils/timer.d.ts +18 -0
  46. package/dist/utils/timer.d.ts.map +1 -0
  47. package/dist/utils/timer.js +36 -0
  48. package/dist/utils/timer.js.map +1 -0
  49. package/package.json +8 -4
  50. package/src/common/common-schema.ts +12 -0
  51. package/src/common/common-types.ts +10 -0
  52. package/src/content-source-interface.ts +495 -0
  53. package/src/content-store-types.ts +430 -0
  54. package/src/content-store.ts +2333 -0
  55. package/src/{encoder.js → encoder.ts} +55 -17
  56. package/src/index.ts +11 -0
  57. package/src/stackbit/{index.js → index.ts} +5 -9
  58. package/src/utils/timer.ts +42 -0
  59. package/dist/utils/lazy-poller.d.ts +0 -21
  60. package/dist/utils/lazy-poller.js +0 -56
  61. package/dist/utils/lazy-poller.js.map +0 -1
  62. package/src/common/common-schema.js +0 -14
  63. package/src/index.js +0 -13
  64. package/src/utils/lazy-poller.ts +0 -74
@@ -0,0 +1,430 @@
1
+ import { DocumentStatus, FieldType } from './content-source-interface';
2
+
3
+ export { FieldType, Logger, LeveledLogMethod, DocumentStatus } from './content-source-interface';
4
+
5
+ export interface Document {
6
+ type: 'document';
7
+ srcType: string;
8
+ srcProjectId: string;
9
+ srcProjectUrl: string;
10
+ srcEnvironment: string;
11
+ srcObjectId: string;
12
+ srcObjectUrl: string;
13
+ srcObjectLabel: string;
14
+ srcModelName: string;
15
+ srcModelLabel: string;
16
+ isChanged: boolean;
17
+ status: DocumentStatus;
18
+ createdAt: string;
19
+ createdBy?: string;
20
+ updatedAt: string;
21
+ updatedBy?: string[];
22
+ fields: Record<string, DocumentField>;
23
+ }
24
+
25
+ export interface Asset {
26
+ type: 'asset';
27
+ srcType: string;
28
+ srcProjectId: string;
29
+ srcProjectUrl: string;
30
+ srcEnvironment: string;
31
+ srcObjectId: string;
32
+ srcObjectUrl: string;
33
+ srcObjectLabel: string;
34
+ srcModelName: string;
35
+ srcModelLabel: string;
36
+ isChanged: boolean;
37
+ status: DocumentStatus;
38
+ createdAt: string;
39
+ createdBy?: string;
40
+ updatedAt: string;
41
+ updatedBy?: string[];
42
+ fields: AssetFields;
43
+ }
44
+
45
+ export type AssetFields = {
46
+ title: DocumentValueFieldForType<'string'>;
47
+ file: AssetFileField;
48
+ };
49
+
50
+ export interface UploadAssetData {
51
+ url: string;
52
+ data?: string;
53
+ metadata: {
54
+ name: string;
55
+ type: string;
56
+ };
57
+ }
58
+
59
+ export interface ContentChangeResultItem {
60
+ srcType: string;
61
+ srcProjectId: string;
62
+ srcObjectId: string;
63
+ }
64
+
65
+ export interface ContentChangeResult {
66
+ updatedDocuments: ContentChangeResultItem[];
67
+ updatedAssets: ContentChangeResultItem[];
68
+ deletedDocuments: ContentChangeResultItem[];
69
+ deletedAssets: ContentChangeResultItem[];
70
+ }
71
+
72
+ export type APIObject = APIDocumentObject | APIImageObject;
73
+
74
+ export interface APIDocumentObject extends Omit<Document, 'fields' | 'type'> {
75
+ type: 'object';
76
+ fields: Record<string, DocumentFieldAPI>;
77
+ }
78
+
79
+ export interface APIImageObject extends Omit<Asset, 'fields' | 'type'> {
80
+ type: 'image';
81
+ fields: AssetFieldsAPI;
82
+ }
83
+
84
+ export type AssetFieldsAPI = {
85
+ title: DocumentFieldAPIForType<'string'>;
86
+ url: DocumentFieldAPIForType<'string'>;
87
+ };
88
+
89
+ export interface APIAsset {
90
+ objectId: string;
91
+ createdAt: string;
92
+ url: string;
93
+ title?: string;
94
+ fileName?: string;
95
+ contentType?: string;
96
+ size?: number;
97
+ width?: number;
98
+ height?: number;
99
+ }
100
+
101
+ export type DocumentField =
102
+ | DocumentValueField
103
+ | DocumentObjectField
104
+ | DocumentModelField
105
+ | DocumentReferenceField
106
+ | DocumentListField
107
+ | DocumentMarkdownField
108
+ | DocumentRichTextField
109
+ | DocumentImageField;
110
+
111
+ export type DocumentFieldLocalized =
112
+ | DocumentValueFieldLocalized
113
+ | DocumentObjectFieldLocalized
114
+ | DocumentModelFieldLocalized
115
+ | DocumentReferenceFieldLocalized
116
+ | DocumentMarkdownFieldLocalized
117
+ | DocumentRichTextFieldLocalized
118
+ | DocumentListFieldLocalized
119
+ | DocumentImageFieldLocalized;
120
+
121
+ export type DocumentFieldNonLocalized =
122
+ | DocumentValueFieldNonLocalized
123
+ | DocumentObjectFieldNonLocalized
124
+ | DocumentModelFieldNonLocalized
125
+ | DocumentReferenceFieldNonLocalized
126
+ | DocumentMarkdownFieldNonLocalized
127
+ | DocumentRichTextFieldNonLocalized
128
+ | DocumentListFieldNonLocalized
129
+ | DocumentImageFieldNonLocalized;
130
+
131
+ export type DocumentFieldAPI =
132
+ | DocumentValueFieldAPI
133
+ | DocumentObjectFieldAPI
134
+ | DocumentModelFieldAPI
135
+ | DocumentReferenceFieldAPI
136
+ | DocumentMarkdownFieldAPI
137
+ | DocumentRichTextFieldAPI
138
+ | DocumentListFieldAPI
139
+ | DocumentImageFieldAPI;
140
+
141
+ export type DocumentFieldBaseProps =
142
+ | DocumentValueFieldBaseProps
143
+ | DocumentObjectFieldBase
144
+ | DocumentModelFieldBase
145
+ | DocumentReferenceFieldBase
146
+ | DocumentListFieldBase
147
+ | DocumentRichTextFieldBase
148
+ | DocumentImageFieldBase;
149
+
150
+ export type DistributiveOmit<T, K extends PropertyKey> = T extends any ? Omit<T, K> : never;
151
+
152
+ export type Simplify<T> = {
153
+ [K in keyof T]: T[K];
154
+ };
155
+
156
+ export type FindByType<Union extends { type: FieldType | 'unresolved_reference' }, Type> = Union extends { type: Type } ? Union : never;
157
+ export type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>;
158
+ export type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>;
159
+ export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>;
160
+ export type DocumentFieldAPIForType<Type extends FieldType | 'unresolved_reference'> = FindByType<DocumentFieldAPI, Type>;
161
+ export type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>;
162
+ export type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify<
163
+ DistributiveOmit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'label' | 'locale' | 'localized'>
164
+ >;
165
+
166
+ // helpers
167
+ export type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
168
+ BaseFieldProps & {
169
+ label?: string;
170
+ localized: true;
171
+ locales: Record<string, { locale: string } & Omit<LocalizedFieldProps, 'isUnset'>>;
172
+ }
173
+ >;
174
+
175
+ export type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
176
+ BaseFieldProps &
177
+ LocalizedFieldProps & {
178
+ label?: string;
179
+ localized?: false;
180
+ locale?: string;
181
+ }
182
+ >;
183
+
184
+ export type DocumentFieldTypeAPI<BaseFieldProps, LocalizedFieldProps> = BaseFieldProps &
185
+ LocalizedFieldProps & {
186
+ label?: string;
187
+ description?: string;
188
+ locale?: string;
189
+ localized?: boolean;
190
+ };
191
+
192
+ // any field that is not 'object' | 'model' | 'reference' | 'richText' | 'markdown' | 'list'
193
+ export type DocumentValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'markdown' | 'richText' | 'list' | 'image'>;
194
+
195
+ export type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType
196
+ ? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type>
197
+ : never;
198
+ export type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>;
199
+
200
+ export type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType
201
+ ? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
202
+ : never;
203
+ export type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>;
204
+
205
+ export type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType
206
+ ? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
207
+ : never;
208
+ export type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>;
209
+
210
+ export type DocumentValueFieldAPIForType<Type> = Type extends DocumentValueFieldType
211
+ ? DocumentFieldTypeAPI<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
212
+ : never;
213
+ export type DocumentValueFieldAPI = DocumentValueFieldAPIForType<DocumentValueFieldType>;
214
+
215
+ export type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldBase<Type> : never;
216
+ export type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>;
217
+ export type DocumentValueFieldBase<Type extends DocumentValueFieldType> = {
218
+ type: Type;
219
+ };
220
+ export type DocumentValueFieldProps = {
221
+ value: any;
222
+ };
223
+
224
+ // object
225
+ export type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized;
226
+ export type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
227
+ export type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
228
+ export type DocumentObjectFieldAPI = DocumentFieldTypeAPI<DocumentObjectFieldBase, DocumentObjectFieldPropsAPI>;
229
+ export type DocumentObjectFieldBase = { type: 'object' };
230
+ export type DocumentObjectFieldPropsCommon = {
231
+ srcObjectLabel: string;
232
+ };
233
+ export type DocumentObjectFieldProps = { isUnset: true } | ({ isUnset?: false; fields: Record<string, DocumentField> } & DocumentObjectFieldPropsCommon);
234
+ export type DocumentObjectFieldPropsAPI = { isUnset: true } | ({ isUnset?: false; fields: Record<string, DocumentFieldAPI> } & DocumentObjectFieldPropsCommon);
235
+
236
+ // model
237
+ export type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized;
238
+ export type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
239
+ export type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
240
+ export type DocumentModelFieldAPI = DocumentFieldTypeAPI<DocumentModelFieldBase, DocumentModelFieldPropsAPI>;
241
+ export type DocumentModelFieldBase = { type: 'model' };
242
+ export type DocumentModelFieldPropsCommon = {
243
+ srcObjectLabel: string;
244
+ srcModelName: string;
245
+ srcModelLabel: string;
246
+ };
247
+ export type DocumentModelFieldProps = { isUnset: true } | ({ isUnset?: false; fields: Record<string, DocumentField> } & DocumentModelFieldPropsCommon);
248
+ export type DocumentModelFieldPropsAPI = { isUnset: true } | ({ isUnset?: false; fields: Record<string, DocumentFieldAPI> } & DocumentModelFieldPropsCommon);
249
+
250
+ // reference
251
+ export type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized;
252
+ export type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
253
+ export type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
254
+ export type DocumentReferenceFieldAPI = DocumentFieldTypeAPI<DocumentReferenceFieldBaseAPI, DocumentReferenceFieldProps>;
255
+ export type DocumentReferenceFieldBase = {
256
+ type: 'reference';
257
+ refType: 'document' | 'asset';
258
+ };
259
+ export type DocumentReferenceFieldProps = { isUnset: true } | { isUnset?: false; refId: string };
260
+ export type DocumentReferenceFieldBaseAPI = {
261
+ type: 'unresolved_reference';
262
+ refType: 'object' | 'image';
263
+ };
264
+
265
+ // markdown
266
+ export type DocumentMarkdownField = DocumentMarkdownFieldLocalized | DocumentMarkdownFieldNonLocalized;
267
+ export type DocumentMarkdownFieldLocalized = DocumentFieldTypeLocalized<DocumentMarkdownFieldBase, DocumentMarkdownFieldProps>;
268
+ export type DocumentMarkdownFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentMarkdownFieldBase, DocumentMarkdownFieldProps>;
269
+ export type DocumentMarkdownFieldAPI = DocumentFieldTypeAPI<DocumentMarkdownFieldBase, DocumentMarkdownFieldProps>;
270
+ export type DocumentMarkdownFieldBase = {
271
+ type: 'markdown';
272
+ };
273
+ export type DocumentMarkdownFieldProps = {
274
+ isUnset?: boolean;
275
+ multiElement?: boolean;
276
+ value: any;
277
+ };
278
+
279
+ // richText
280
+ export type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized;
281
+ export type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
282
+ export type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
283
+ export type DocumentRichTextFieldAPI = DocumentFieldTypeAPI<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
284
+ export type DocumentRichTextFieldBase = {
285
+ type: 'richText';
286
+ };
287
+ export type DocumentRichTextFieldProps = {
288
+ isUnset?: boolean;
289
+ hint?: string;
290
+ multiElement?: boolean;
291
+ value: any;
292
+ };
293
+
294
+ // list
295
+ export type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized;
296
+ export type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>;
297
+ export type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentListFieldBase, DocumentListFieldProps>;
298
+ export type DocumentListFieldAPI = DocumentFieldTypeAPI<DocumentListFieldBase, DocumentListFieldPropsAPI>;
299
+ export type DocumentListFieldBase = {
300
+ type: 'list';
301
+ };
302
+ export type DocumentListFieldProps = {
303
+ items: DocumentField[];
304
+ };
305
+ export type DocumentListFieldPropsAPI = {
306
+ items: DocumentFieldAPI[];
307
+ };
308
+
309
+ // image
310
+ export type DocumentImageField = DocumentImageFieldLocalized | DocumentImageFieldNonLocalized;
311
+ export type DocumentImageFieldLocalized = DocumentFieldTypeLocalized<DocumentImageFieldBase, DocumentImageFieldProps>;
312
+ export type DocumentImageFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentImageFieldBase, DocumentImageFieldProps>;
313
+ export type DocumentImageFieldAPI = DocumentFieldTypeAPI<DocumentImageFieldBase, DocumentImageFieldPropsAPI>;
314
+ export type DocumentImageFieldBase = { type: 'image' };
315
+ export type DocumentImageFieldProps = { isUnset: true } | { isUnset?: false; fields: AssetFieldsAPI };
316
+ export type DocumentImageFieldPropsAPI = { isUnset: true } | { isUnset?: false; fields: AssetFieldsAPI };
317
+
318
+ // assetFile
319
+ export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized;
320
+ export type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>;
321
+ export type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>;
322
+ export type AssetFileFieldBase = {
323
+ type: 'assetFile';
324
+ };
325
+ export type AssetFileFieldProps = {
326
+ url: string;
327
+ fileName?: string;
328
+ contentType?: string;
329
+ size?: number;
330
+ dimensions?: {
331
+ width?: number;
332
+ height?: number;
333
+ };
334
+ };
335
+ export type UpdateOperation = UpdateOperationSet | UpdateOperationUnset | UpdateOperationInsert | UpdateOperationRemove | UpdateOperationReorder;
336
+
337
+ export type UpdateOperationBase = {
338
+ opType: string;
339
+ fieldPath: (string | number)[];
340
+ locale?: string;
341
+ };
342
+
343
+ export type UpdateOperationSet = Simplify<
344
+ UpdateOperationBase & {
345
+ opType: 'set';
346
+ field: UpdateOperationField;
347
+ }
348
+ >;
349
+
350
+ export type UpdateOperationUnset = Simplify<
351
+ UpdateOperationBase & {
352
+ opType: 'unset';
353
+ }
354
+ >;
355
+
356
+ export type UpdateOperationInsert = Simplify<
357
+ UpdateOperationBase & {
358
+ opType: 'insert';
359
+ index?: number;
360
+ item: UpdateOperationField;
361
+ }
362
+ >;
363
+
364
+ export type UpdateOperationRemove = Simplify<
365
+ UpdateOperationBase & {
366
+ opType: 'remove';
367
+ index: number;
368
+ }
369
+ >;
370
+
371
+ export type UpdateOperationReorder = Simplify<
372
+ UpdateOperationBase & {
373
+ opType: 'reorder';
374
+ order: number[];
375
+ }
376
+ >;
377
+
378
+ export type UpdateOperationField =
379
+ | UpdateOperationValueField
380
+ | UpdateOperationObjectField
381
+ | UpdateOperationModelField
382
+ | UpdateOperationReferenceField
383
+ | UpdateOperationListField;
384
+
385
+ export type UpdateOperationValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'list'>;
386
+ export type UpdateOperationValueField = {
387
+ type: UpdateOperationValueFieldType;
388
+ value: any;
389
+ };
390
+
391
+ export type UpdateOperationObjectField = {
392
+ type: 'object';
393
+ object: Record<string, any>;
394
+ };
395
+
396
+ export type UpdateOperationModelField = {
397
+ type: 'model';
398
+ modelName: string;
399
+ object: Record<string, any>;
400
+ };
401
+
402
+ export type UpdateOperationReferenceField = {
403
+ type: 'reference';
404
+ refType: 'document' | 'asset';
405
+ refId: string;
406
+ };
407
+
408
+ export type UpdateOperationListField = {
409
+ type: 'list';
410
+ items: any[];
411
+ };
412
+
413
+ export type User = {
414
+ name: string;
415
+ email: string;
416
+ connections: {
417
+ type: string;
418
+ [key: string]: any;
419
+ }[];
420
+ };
421
+
422
+ export type ValidationError = {
423
+ message: string;
424
+ srcType: string;
425
+ srcProjectId: string;
426
+ srcObjectType: string;
427
+ srcObjectId: string;
428
+ fieldPath: (string | number)[];
429
+ isUniqueValidation?: boolean;
430
+ };