@stackbit/cms-core 0.1.4-alpha.0 → 0.1.4-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 (45) hide show
  1. package/dist/common/common-types.d.ts +1 -9
  2. package/dist/common/common-types.d.ts.map +1 -1
  3. package/dist/consts.d.ts +1 -24
  4. package/dist/consts.d.ts.map +1 -1
  5. package/dist/consts.js +5 -25
  6. package/dist/consts.js.map +1 -1
  7. package/dist/content-store-types.d.ts +18 -16
  8. package/dist/content-store-types.d.ts.map +1 -1
  9. package/dist/content-store-utils.d.ts +3 -2
  10. package/dist/content-store-utils.d.ts.map +1 -1
  11. package/dist/content-store-utils.js.map +1 -1
  12. package/dist/content-store.d.ts +1 -1
  13. package/dist/content-store.d.ts.map +1 -1
  14. package/dist/content-store.js +31 -14
  15. package/dist/content-store.js.map +1 -1
  16. package/dist/index.d.ts +0 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/utils/create-update-csi-docs.d.ts +4 -3
  21. package/dist/utils/create-update-csi-docs.d.ts.map +1 -1
  22. package/dist/utils/create-update-csi-docs.js +11 -1
  23. package/dist/utils/create-update-csi-docs.js.map +1 -1
  24. package/dist/utils/csi-to-store-docs-converter.d.ts +1 -1
  25. package/dist/utils/csi-to-store-docs-converter.d.ts.map +1 -1
  26. package/dist/utils/csi-to-store-docs-converter.js +8 -8
  27. package/dist/utils/csi-to-store-docs-converter.js.map +1 -1
  28. package/dist/utils/search-utils.d.ts.map +1 -1
  29. package/dist/utils/search-utils.js +8 -8
  30. package/dist/utils/search-utils.js.map +1 -1
  31. package/package.json +4 -3
  32. package/src/common/common-types.ts +1 -10
  33. package/src/consts.ts +1 -26
  34. package/src/content-store-types.ts +40 -39
  35. package/src/content-store-utils.ts +3 -2
  36. package/src/content-store.ts +45 -25
  37. package/src/index.ts +0 -1
  38. package/src/utils/create-update-csi-docs.ts +39 -22
  39. package/src/utils/csi-to-store-docs-converter.ts +3 -2
  40. package/src/utils/search-utils.ts +3 -2
  41. package/dist/content-source-interface.d.ts +0 -333
  42. package/dist/content-source-interface.d.ts.map +0 -1
  43. package/dist/content-source-interface.js +0 -28
  44. package/dist/content-source-interface.js.map +0 -1
  45. package/src/content-source-interface.ts +0 -486
@@ -1,486 +0,0 @@
1
- import type { Model, Field } from '@stackbit/sdk';
2
- import { Logger as UtilsLogger } from '@stackbit/utils';
3
- import { UserCommandSpawner } from './common/common-types';
4
-
5
- export interface Logger extends UtilsLogger {
6
- createLogger: ({ label }: { label: string }) => Logger;
7
- }
8
-
9
- export type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted';
10
-
11
- export interface Locale {
12
- code: string;
13
- default?: boolean;
14
- }
15
-
16
- export interface Document<DocumentContext = unknown> {
17
- type: 'document';
18
- id: string;
19
- manageUrl: string;
20
- modelName: string;
21
- status: DocumentStatus;
22
- createdAt: string;
23
- createdBy?: string;
24
- updatedAt: string;
25
- updatedBy?: string[];
26
- fields: Record<string, DocumentField>;
27
- context: DocumentContext;
28
- }
29
-
30
- export interface Asset<AssetContext = unknown> {
31
- type: 'asset';
32
- id: string;
33
- manageUrl: string;
34
- status: DocumentStatus;
35
- createdAt: string;
36
- createdBy?: string;
37
- updatedAt: string;
38
- updatedBy?: string[];
39
- fields: AssetFields;
40
- context: AssetContext;
41
- }
42
-
43
- export type AssetFields = {
44
- title: DocumentValueFieldForType<'string'>;
45
- file: AssetFileField;
46
- };
47
-
48
- export type DocumentField =
49
- | DocumentValueField
50
- | DocumentObjectField
51
- | DocumentModelField
52
- | DocumentReferenceField
53
- | DocumentListField
54
- | DocumentRichTextField
55
- | DocumentImageField;
56
-
57
- export type DocumentFieldLocalized =
58
- | DocumentValueFieldLocalized
59
- | DocumentObjectFieldLocalized
60
- | DocumentModelFieldLocalized
61
- | DocumentReferenceFieldLocalized
62
- | DocumentListFieldLocalized
63
- | DocumentRichTextFieldLocalized
64
- | DocumentImageFieldLocalized;
65
-
66
- export type DocumentFieldNonLocalized =
67
- | DocumentValueFieldNonLocalized
68
- | DocumentObjectFieldNonLocalized
69
- | DocumentModelFieldNonLocalized
70
- | DocumentReferenceFieldNonLocalized
71
- | DocumentListFieldNonLocalized
72
- | DocumentRichTextFieldNonLocalized
73
- | DocumentImageFieldNonLocalized;
74
-
75
- export type DocumentFieldBaseProps =
76
- | DocumentValueFieldBaseProps
77
- | DocumentObjectFieldBase
78
- | DocumentModelFieldBase
79
- | DocumentReferenceFieldBase
80
- | DocumentListFieldBase
81
- | DocumentRichTextFieldBase
82
- | DocumentImageFieldBase;
83
-
84
- export type DocumentFieldSpecificProps =
85
- | DocumentValueFieldProps
86
- | DocumentObjectFieldProps
87
- | DocumentModelFieldProps
88
- | DocumentReferenceFieldProps
89
- | DocumentListFieldProps
90
- | DocumentRichTextFieldProps
91
- | DocumentImageFieldProps;
92
-
93
- export function isLocalizedField(field: DocumentField | AssetFileField): field is DocumentFieldLocalized | AssetFileFieldLocalized {
94
- return !!field.localized;
95
- }
96
-
97
- export function getLocalizedFieldForLocale<Type extends FieldType>(
98
- field: DocumentFieldForType<Type>,
99
- locale?: string
100
- ): DocumentFieldNonLocalizedForType<Type> | null {
101
- if (field.localized) {
102
- if (!locale) {
103
- return null;
104
- }
105
- const { localized, locales, ...base } = field;
106
- const localizedField = locales[locale];
107
- if (!localizedField) {
108
- return null;
109
- }
110
- return {
111
- ...base,
112
- ...localizedField
113
- } as unknown as DocumentFieldNonLocalizedForType<Type>;
114
- } else {
115
- return field;
116
- }
117
- }
118
-
119
- export type FieldType =
120
- | 'string'
121
- | 'url'
122
- | 'slug'
123
- | 'text'
124
- | 'markdown'
125
- | 'html'
126
- | 'number'
127
- | 'boolean'
128
- | 'enum'
129
- | 'date'
130
- | 'datetime'
131
- | 'color'
132
- | 'image'
133
- | 'file'
134
- | 'json'
135
- | 'richText'
136
- | 'object'
137
- | 'model'
138
- | 'reference'
139
- | 'style'
140
- | 'list';
141
-
142
- export type Simplify<T> = {
143
- [K in keyof T]: T[K];
144
- };
145
-
146
- export type FindByType<Union extends { type: FieldType }, Type> = Union extends { type: Type } ? Union : never;
147
- export type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>;
148
- export type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>;
149
- export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>;
150
- export type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>;
151
- export type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify<
152
- Omit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'locale' | 'localized'>
153
- >;
154
-
155
- export type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
156
- BaseFieldProps & {
157
- localized: true;
158
- locales: Record<string, { locale: string } & LocalizedFieldProps>;
159
- }
160
- >;
161
-
162
- export type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<
163
- BaseFieldProps &
164
- LocalizedFieldProps & {
165
- localized?: false;
166
- locale?: string;
167
- }
168
- >;
169
-
170
- // any field that is not 'object' | 'model' | 'reference' | 'richText' | 'list'
171
- export type DocumentValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'richText' | 'list' | 'image'>;
172
-
173
- export type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType
174
- ? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type>
175
- : never;
176
- export type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>;
177
-
178
- export type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType
179
- ? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
180
- : never;
181
- export type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>;
182
-
183
- export type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType
184
- ? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps>
185
- : never;
186
- export type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>;
187
-
188
- export type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldBase<Type> : never;
189
- export type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>;
190
- export type DocumentValueFieldBase<Type extends DocumentValueFieldType> = {
191
- type: Type;
192
- };
193
- export type DocumentValueFieldProps = {
194
- value: any;
195
- };
196
-
197
- // object
198
- export type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized;
199
- export type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
200
- export type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>;
201
- export type DocumentObjectFieldBase = {
202
- type: 'object';
203
- };
204
- export type DocumentObjectFieldProps = {
205
- fields: Record<string, DocumentField>;
206
- };
207
-
208
- // model
209
- export type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized;
210
- export type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
211
- export type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentModelFieldBase, DocumentModelFieldProps>;
212
- export type DocumentModelFieldBase = {
213
- type: 'model';
214
- };
215
- export type DocumentModelFieldProps = {
216
- modelName: string;
217
- fields: Record<string, DocumentField>;
218
- };
219
-
220
- // reference
221
- export type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized;
222
- export type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
223
- export type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>;
224
- export type DocumentReferenceFieldBase = {
225
- type: 'reference';
226
- refType: 'document' | 'asset';
227
- };
228
- export type DocumentReferenceFieldProps = {
229
- refId: string;
230
- };
231
-
232
- // richText
233
- export type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized;
234
- export type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
235
- export type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>;
236
- export type DocumentRichTextFieldBase = {
237
- type: 'richText';
238
- };
239
- export type DocumentRichTextFieldProps = {
240
- hint?: string;
241
- value: any;
242
- };
243
-
244
- // list
245
- export type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized;
246
- export type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>;
247
- export type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentListFieldBase, DocumentListFieldProps>;
248
- export type DocumentListFieldBase = {
249
- type: 'list';
250
- };
251
- export type DocumentListFieldProps = {
252
- items: DocumentFieldNonLocalized[];
253
- };
254
-
255
- // image
256
- export type DocumentImageField = DocumentImageFieldLocalized | DocumentImageFieldNonLocalized;
257
- export type DocumentImageFieldLocalized = DocumentFieldTypeLocalized<DocumentImageFieldBase, DocumentImageFieldProps>;
258
- export type DocumentImageFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentImageFieldBase, DocumentImageFieldProps>;
259
- export type DocumentImageFieldBase = {
260
- type: 'image';
261
- };
262
- export type DocumentImageFieldProps = {
263
- fields: {
264
- title: DocumentValueFieldForType<'string'>;
265
- url: DocumentValueFieldForType<'string'>;
266
- };
267
- };
268
-
269
- // assetFile
270
- export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized;
271
- export type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>;
272
- export type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>;
273
- export type AssetFileFieldBase = {
274
- type: 'assetFile';
275
- };
276
- export type AssetFileFieldProps = {
277
- url: string;
278
- fileName?: string;
279
- contentType?: string;
280
- size?: number;
281
- dimensions: {
282
- width?: number;
283
- height?: number;
284
- };
285
- };
286
-
287
- export interface InitOptions {
288
- logger: Logger;
289
- userLogger: Logger;
290
- userCommandSpawner?: UserCommandSpawner;
291
- localDev: boolean;
292
- }
293
-
294
- export interface ContentChangeEvent<DocumentContext = unknown, AssetContext = unknown> {
295
- documents: Document<DocumentContext>[];
296
- assets: Asset<AssetContext>[];
297
- deletedDocumentIds: string[];
298
- deletedAssetIds: string[];
299
- }
300
-
301
- export type UpdateOperation = UpdateOperationSet | UpdateOperationUnset | UpdateOperationInsert | UpdateOperationRemove | UpdateOperationReorder;
302
-
303
- export type UpdateOperationBase = {
304
- opType: string;
305
- fieldPath: (string | number)[];
306
- modelField: Field;
307
- locale?: string;
308
- };
309
-
310
- export type UpdateOperationSet = Simplify<
311
- UpdateOperationBase & {
312
- opType: 'set';
313
- field: UpdateOperationField;
314
- }
315
- >;
316
-
317
- export type UpdateOperationUnset = Simplify<
318
- UpdateOperationBase & {
319
- opType: 'unset';
320
- }
321
- >;
322
-
323
- export type UpdateOperationInsert = Simplify<
324
- UpdateOperationBase & {
325
- opType: 'insert';
326
- index?: number;
327
- item: UpdateOperationField;
328
- }
329
- >;
330
-
331
- export type UpdateOperationRemove = Simplify<
332
- UpdateOperationBase & {
333
- opType: 'remove';
334
- index: number;
335
- }
336
- >;
337
-
338
- export type UpdateOperationReorder = Simplify<
339
- UpdateOperationBase & {
340
- opType: 'reorder';
341
- order: number[];
342
- }
343
- >;
344
-
345
- export type UpdateOperationField =
346
- | UpdateOperationValueField
347
- | UpdateOperationObjectField
348
- | UpdateOperationModelField
349
- | UpdateOperationReferenceField
350
- | UpdateOperationListField;
351
-
352
- export type UpdateOperationValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'list'>;
353
- export type UpdateOperationValueField<Type = UpdateOperationValueFieldType> = Type extends UpdateOperationValueFieldType
354
- ? UpdateOperationValueFieldForType<Type>
355
- : never;
356
- export type UpdateOperationValueFieldForType<Type extends UpdateOperationValueFieldType> = {
357
- type: Type;
358
- value: any;
359
- };
360
-
361
- export type UpdateOperationObjectField = {
362
- type: 'object';
363
- fields: Record<string, UpdateOperationField>;
364
- };
365
-
366
- export type UpdateOperationModelField = {
367
- type: 'model';
368
- modelName: string;
369
- fields: Record<string, UpdateOperationField>;
370
- };
371
-
372
- export type UpdateOperationReferenceField = {
373
- type: 'reference';
374
- refType: 'document' | 'asset';
375
- refId: string;
376
- };
377
-
378
- export type UpdateOperationListField = {
379
- type: 'list';
380
- items: UpdateOperationField[];
381
- }
382
-
383
- export type ValidationError = {
384
- message: string;
385
- objectType: 'document' | 'asset';
386
- objectId: string;
387
- fieldPath: (string | number)[];
388
- isUniqueValidation?: boolean;
389
- };
390
-
391
- export type ModelMap = Record<string, Model>;
392
-
393
- export interface ContentSourceInterface<UserContext = unknown, DocumentContext = unknown, AssetContext = unknown> {
394
- /**
395
- * This function should return the type of the content source.
396
- * The type must be unique among other content sources within the same project.
397
- */
398
- getContentSourceType(): string;
399
-
400
- /**
401
- * This function should return the project ID of the content source.
402
- * The ID must be unique among other content sources of the same type.
403
- */
404
- getProjectId(): string;
405
-
406
- getProjectEnvironment(): string;
407
-
408
- getProjectManageUrl(): string;
409
-
410
- /**
411
- * This function should initialize the content source by fetching the schema
412
- * and everything else needed to produce the StackbitSchema
413
- */
414
- init(options: InitOptions): Promise<void>;
415
-
416
- reset(): Promise<void>;
417
-
418
- onFilesChange?({
419
- updatedFiles
420
- }: {
421
- updatedFiles: string[];
422
- }): Promise<{ schemaChanged?: boolean; contentChangeEvent?: ContentChangeEvent<DocumentContext, AssetContext> }>;
423
-
424
- startWatchingContentUpdates(options: {
425
- getModelMap: () => ModelMap;
426
- getDocument: ({ documentId }: { documentId: string }) => Document<DocumentContext> | undefined;
427
- getAsset: ({ assetId }: { assetId: string }) => Asset<AssetContext> | undefined;
428
- onContentChange: (contentChangeEvent: ContentChangeEvent<DocumentContext, AssetContext>) => void;
429
- onSchemaChange: () => void;
430
- }): void;
431
-
432
- stopWatchingContentUpdates(): void;
433
-
434
- /**
435
- * This function is responsible to fetch and convert content models
436
- * to Stackbit models.
437
- */
438
- getModels(): Promise<Model[]>;
439
-
440
- getLocales(): Promise<Locale[]>;
441
-
442
- /**
443
- * This function should fetch the documents and convert them into Stackbit's
444
- * Document type
445
- */
446
- getDocuments(options: { modelMap: ModelMap }): Promise<Document<DocumentContext>[]>;
447
-
448
- getAssets(): Promise<Asset<AssetContext>[]>;
449
-
450
- hasAccess(options: { userContext?: UserContext }): Promise<{ hasConnection: boolean; hasPermissions: boolean }>;
451
-
452
- createDocument(options: {
453
- updateOperationFields: Record<string, UpdateOperationField>;
454
- model: Model;
455
- modelMap: ModelMap;
456
- locale?: string;
457
- userContext?: UserContext;
458
- }): Promise<Document<DocumentContext>>;
459
-
460
- updateDocument(options: {
461
- document: Document<DocumentContext>;
462
- operations: UpdateOperation[];
463
- modelMap: ModelMap;
464
- userContext?: UserContext;
465
- }): Promise<Document<DocumentContext>>;
466
-
467
- deleteDocument(options: { document: Document<DocumentContext>; userContext?: UserContext }): Promise<void>;
468
-
469
- uploadAsset(options: {
470
- url?: string;
471
- base64?: string;
472
- fileName: string;
473
- mimeType: string;
474
- locale?: string;
475
- userContext?: UserContext;
476
- }): Promise<Asset<AssetContext>>;
477
-
478
- validateDocuments(options: {
479
- documents: Document<DocumentContext>[];
480
- assets: Asset<AssetContext>[];
481
- locale?: string;
482
- userContext?: UserContext;
483
- }): Promise<{ errors: ValidationError[] }>;
484
-
485
- publishDocuments(options: { documents: Document<DocumentContext>[]; assets: Asset<AssetContext>[]; userContext?: UserContext }): Promise<void>;
486
- }