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

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 +0 -1
  2. package/dist/annotator/index.d.ts +2 -3
  3. package/dist/annotator/react.d.ts +0 -1
  4. package/dist/common/common-schema.d.ts +10 -3
  5. package/dist/common/common-schema.js +4 -3
  6. package/dist/common/common-schema.js.map +1 -1
  7. package/dist/consts.d.ts +0 -1
  8. package/dist/encoder.d.ts +7 -36
  9. package/dist/encoder.js +40 -63
  10. package/dist/encoder.js.map +1 -1
  11. package/dist/index.d.ts +6 -11
  12. package/dist/index.js +11 -37
  13. package/dist/index.js.map +1 -1
  14. package/dist/stackbit/index.d.ts +3 -7
  15. package/dist/stackbit/index.js +10 -13
  16. package/dist/stackbit/index.js.map +1 -1
  17. package/dist/utils/index.d.ts +7 -8
  18. package/dist/utils/lazy-poller.d.ts +21 -0
  19. package/dist/utils/lazy-poller.js +56 -0
  20. package/dist/utils/lazy-poller.js.map +1 -0
  21. package/dist/utils/schema-utils.d.ts +2 -3
  22. package/package.json +4 -8
  23. package/src/common/common-schema.js +14 -0
  24. package/src/{encoder.ts → encoder.js} +17 -55
  25. package/src/index.js +13 -0
  26. package/src/stackbit/{index.ts → index.js} +9 -5
  27. package/src/utils/lazy-poller.ts +74 -0
  28. package/dist/annotator/html.d.ts.map +0 -1
  29. package/dist/annotator/index.d.ts.map +0 -1
  30. package/dist/annotator/react.d.ts.map +0 -1
  31. package/dist/common/common-schema.d.ts.map +0 -1
  32. package/dist/consts.d.ts.map +0 -1
  33. package/dist/content-source-interface.d.ts +0 -324
  34. package/dist/content-source-interface.d.ts.map +0 -1
  35. package/dist/content-source-interface.js +0 -28
  36. package/dist/content-source-interface.js.map +0 -1
  37. package/dist/content-store-types.d.ts +0 -328
  38. package/dist/content-store-types.d.ts.map +0 -1
  39. package/dist/content-store-types.js +0 -3
  40. package/dist/content-store-types.js.map +0 -1
  41. package/dist/content-store.d.ts +0 -207
  42. package/dist/content-store.d.ts.map +0 -1
  43. package/dist/content-store.js +0 -1743
  44. package/dist/content-store.js.map +0 -1
  45. package/dist/encoder.d.ts.map +0 -1
  46. package/dist/index.d.ts.map +0 -1
  47. package/dist/stackbit/index.d.ts.map +0 -1
  48. package/dist/utils/index.d.ts.map +0 -1
  49. package/dist/utils/schema-utils.d.ts.map +0 -1
  50. package/dist/utils/timer.d.ts +0 -18
  51. package/dist/utils/timer.d.ts.map +0 -1
  52. package/dist/utils/timer.js +0 -36
  53. package/dist/utils/timer.js.map +0 -1
  54. package/src/common/common-schema.ts +0 -12
  55. package/src/content-source-interface.ts +0 -468
  56. package/src/content-store-types.ts +0 -416
  57. package/src/content-store.ts +0 -2233
  58. package/src/index.ts +0 -10
  59. package/src/utils/timer.ts +0 -42
@@ -1,468 +0,0 @@
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
- }