@stackbit/dev 0.0.54 → 0.0.56-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.
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +4 -0
- package/dist/dev.js.map +1 -1
- package/dist/runner/index.d.ts +49 -18
- package/dist/runner/index.js +103 -119
- package/dist/runner/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes.js +25 -3
- package/dist/server/routes.js.map +1 -1
- package/dist/services/annotation-errors.d.ts +1 -1
- package/dist/services/annotation-errors.js +1 -1
- package/dist/services/annotation-errors.js.map +1 -1
- package/dist/services/logger.d.ts +7 -0
- package/dist/services/logger.js +4 -1
- package/dist/services/logger.js.map +1 -1
- package/dist/types/api-methods.d.ts +236 -0
- package/dist/types/api-methods.js +3 -0
- package/dist/types/api-methods.js.map +1 -0
- package/package.json +5 -5
- package/src/dev.ts +6 -1
- package/src/runner/index.ts +147 -129
- package/src/server/index.ts +2 -1
- package/src/server/routes.ts +31 -3
- package/src/services/annotation-errors.ts +1 -1
- package/src/services/logger.ts +12 -2
- package/src/types/api-methods.ts +292 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { ContentStoreTypes } from '@stackbit/cms-core';
|
|
2
|
+
import { CommitAuthor } from '@stackbit/dev-common';
|
|
3
|
+
|
|
4
|
+
export type APIMethodName = APIMethod['method'];
|
|
5
|
+
export type APIMethodForMethod<T, U> = U extends { method: T } ? U : never;
|
|
6
|
+
export type APIMethodByMethod<T extends APIMethodName> = APIMethodForMethod<T, APIMethod>;
|
|
7
|
+
export type APIMethodDataForMethod<T extends APIMethodName> = APIMethodByMethod<T>['data'];
|
|
8
|
+
export type APIMethodResultForMethod<T extends APIMethodName> = APIMethodByMethod<T>['result'];
|
|
9
|
+
|
|
10
|
+
export type APIMethod =
|
|
11
|
+
| APIMethodCreateDocument
|
|
12
|
+
| APIMethodCreateAndLinkDocument
|
|
13
|
+
| APIMethodUploadAndLinkAsset
|
|
14
|
+
| APIMethodDuplicateDocument
|
|
15
|
+
| APIMethodUpdateDocument
|
|
16
|
+
| APIMethodValidateDocuments
|
|
17
|
+
| APIMethodDeleteDocument
|
|
18
|
+
| APIMethodGetAssets
|
|
19
|
+
| APIMethodUploadAssets
|
|
20
|
+
| APIMethodCreatePreset
|
|
21
|
+
| APIMethodDeletePreset;
|
|
22
|
+
|
|
23
|
+
export type APIMethodCreateDocument = {
|
|
24
|
+
method: 'createDocument';
|
|
25
|
+
data: {
|
|
26
|
+
srcType: string;
|
|
27
|
+
srcProjectId: string;
|
|
28
|
+
modelName: string;
|
|
29
|
+
object?: Record<string, any>;
|
|
30
|
+
locale?: string;
|
|
31
|
+
};
|
|
32
|
+
result: { srcDocumentId: string };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type APIMethodCreateAndLinkDocument = {
|
|
36
|
+
method: 'createAndLinkDocument';
|
|
37
|
+
data: {
|
|
38
|
+
srcType: string;
|
|
39
|
+
srcProjectId: string;
|
|
40
|
+
srcDocumentId: string;
|
|
41
|
+
fieldPath: (string | number)[];
|
|
42
|
+
modelName: string;
|
|
43
|
+
object?: Record<string, any>;
|
|
44
|
+
index?: number;
|
|
45
|
+
locale?: string;
|
|
46
|
+
};
|
|
47
|
+
result: { srcDocumentId: string };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type APIMethodUploadAndLinkAsset = {
|
|
51
|
+
method: 'uploadAndLinkAsset';
|
|
52
|
+
data: {
|
|
53
|
+
srcType: string;
|
|
54
|
+
srcProjectId: string;
|
|
55
|
+
srcDocumentId: string;
|
|
56
|
+
fieldPath: (string | number)[];
|
|
57
|
+
asset: UploadAssetData;
|
|
58
|
+
index?: number;
|
|
59
|
+
locale?: string;
|
|
60
|
+
};
|
|
61
|
+
result: { srcDocumentId: string };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type APIMethodDuplicateDocument = {
|
|
65
|
+
method: 'duplicateDocument';
|
|
66
|
+
data: {
|
|
67
|
+
srcType: string;
|
|
68
|
+
srcProjectId: string;
|
|
69
|
+
srcDocumentId: string;
|
|
70
|
+
object?: Record<string, any>;
|
|
71
|
+
};
|
|
72
|
+
result: { srcDocumentId: string };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type APIMethodUpdateDocument = {
|
|
76
|
+
method: 'updateDocument';
|
|
77
|
+
data: {
|
|
78
|
+
srcType: string;
|
|
79
|
+
srcProjectId: string;
|
|
80
|
+
srcDocumentId: string;
|
|
81
|
+
updateOperations: UpdateOperation[];
|
|
82
|
+
};
|
|
83
|
+
result: { srcDocumentId: string };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type APIMethodDeleteDocument = {
|
|
87
|
+
method: 'deleteDocument';
|
|
88
|
+
data: {
|
|
89
|
+
srcType: string;
|
|
90
|
+
srcProjectId: string;
|
|
91
|
+
srcDocumentId: string;
|
|
92
|
+
};
|
|
93
|
+
result: void;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type APIMethodValidateDocuments = {
|
|
97
|
+
method: 'validateDocuments';
|
|
98
|
+
data: {
|
|
99
|
+
objects: { srcType: string; srcProjectId: string; srcObjectId: string }[];
|
|
100
|
+
locale?: string;
|
|
101
|
+
};
|
|
102
|
+
result: {
|
|
103
|
+
errors: ContentStoreTypes.ValidationError[];
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type APIMethodPublishDocuments = {
|
|
108
|
+
method: 'publishDocuments';
|
|
109
|
+
data: {
|
|
110
|
+
objects: { srcType: string; srcProjectId: string; srcObjectId: string }[];
|
|
111
|
+
};
|
|
112
|
+
result: void;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type APIMethodGetAssets = {
|
|
116
|
+
method: 'getAssets';
|
|
117
|
+
data: {
|
|
118
|
+
srcType?: string;
|
|
119
|
+
srcProjectId?: string;
|
|
120
|
+
pageSize?: number;
|
|
121
|
+
pageNum?: number;
|
|
122
|
+
searchQuery?: string;
|
|
123
|
+
};
|
|
124
|
+
result: {
|
|
125
|
+
assets: ContentStoreTypes.APIAsset[];
|
|
126
|
+
pageSize: number;
|
|
127
|
+
pageNum: number;
|
|
128
|
+
totalPages: number;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export type APIMethodUploadAssets = {
|
|
132
|
+
method: 'uploadAssets';
|
|
133
|
+
data: {
|
|
134
|
+
srcType: string;
|
|
135
|
+
srcProjectId: string;
|
|
136
|
+
assets: UploadAssetData[];
|
|
137
|
+
locale?: string;
|
|
138
|
+
user: any;
|
|
139
|
+
};
|
|
140
|
+
result: ContentStoreTypes.APIAsset[];
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type APIMethodCreatePreset = {
|
|
144
|
+
method: 'createPreset';
|
|
145
|
+
data: {
|
|
146
|
+
label: string;
|
|
147
|
+
metadata: any;
|
|
148
|
+
thumbnail: string;
|
|
149
|
+
fieldDataPath: string[];
|
|
150
|
+
user: CommitAuthor;
|
|
151
|
+
dryRun: boolean;
|
|
152
|
+
};
|
|
153
|
+
result: {
|
|
154
|
+
files: string[];
|
|
155
|
+
preset: {
|
|
156
|
+
modelName: string;
|
|
157
|
+
thumbnail?: string;
|
|
158
|
+
data: any;
|
|
159
|
+
label: string;
|
|
160
|
+
metadata: any;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export type APIMethodDeletePreset = {
|
|
166
|
+
method: 'deletePreset';
|
|
167
|
+
data: {
|
|
168
|
+
presetId: string;
|
|
169
|
+
user: CommitAuthor;
|
|
170
|
+
};
|
|
171
|
+
result: {
|
|
172
|
+
changes: {
|
|
173
|
+
filePath: string;
|
|
174
|
+
description: string;
|
|
175
|
+
}[];
|
|
176
|
+
filesRemoved: string[];
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export interface UploadAssetData {
|
|
181
|
+
url: string;
|
|
182
|
+
data?: string;
|
|
183
|
+
metadata: {
|
|
184
|
+
name: string;
|
|
185
|
+
type: string;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type UpdateOperation = UpdateOperationSet | UpdateOperationUnset | UpdateOperationInsert | UpdateOperationRemove | UpdateOperationReorder;
|
|
190
|
+
|
|
191
|
+
export type UpdateOperationBase = {
|
|
192
|
+
opType: string;
|
|
193
|
+
fieldPath: (string | number)[];
|
|
194
|
+
locale?: string;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type UpdateOperationSet = Simplify<
|
|
198
|
+
UpdateOperationBase & {
|
|
199
|
+
opType: 'set';
|
|
200
|
+
field: UpdateOperationField;
|
|
201
|
+
}
|
|
202
|
+
>;
|
|
203
|
+
|
|
204
|
+
export type UpdateOperationUnset = Simplify<
|
|
205
|
+
UpdateOperationBase & {
|
|
206
|
+
opType: 'unset';
|
|
207
|
+
}
|
|
208
|
+
>;
|
|
209
|
+
|
|
210
|
+
export type UpdateOperationInsert = Simplify<
|
|
211
|
+
UpdateOperationBase & {
|
|
212
|
+
opType: 'insert';
|
|
213
|
+
index?: number;
|
|
214
|
+
item: UpdateOperationField;
|
|
215
|
+
}
|
|
216
|
+
>;
|
|
217
|
+
|
|
218
|
+
export type UpdateOperationRemove = Simplify<
|
|
219
|
+
UpdateOperationBase & {
|
|
220
|
+
opType: 'remove';
|
|
221
|
+
index: number;
|
|
222
|
+
}
|
|
223
|
+
>;
|
|
224
|
+
|
|
225
|
+
export type UpdateOperationReorder = Simplify<
|
|
226
|
+
UpdateOperationBase & {
|
|
227
|
+
opType: 'reorder';
|
|
228
|
+
order: number[];
|
|
229
|
+
}
|
|
230
|
+
>;
|
|
231
|
+
|
|
232
|
+
export type UpdateOperationField =
|
|
233
|
+
| UpdateOperationValueField
|
|
234
|
+
| UpdateOperationObjectField
|
|
235
|
+
| UpdateOperationModelField
|
|
236
|
+
| UpdateOperationReferenceField
|
|
237
|
+
| UpdateOperationListField;
|
|
238
|
+
|
|
239
|
+
export type UpdateOperationValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'list'>;
|
|
240
|
+
export type UpdateOperationValueField = {
|
|
241
|
+
type: UpdateOperationValueFieldType;
|
|
242
|
+
value: any;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export type UpdateOperationObjectField = {
|
|
246
|
+
type: 'object';
|
|
247
|
+
object: Record<string, any>;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export type UpdateOperationModelField = {
|
|
251
|
+
type: 'model';
|
|
252
|
+
modelName: string;
|
|
253
|
+
object: Record<string, any>;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type UpdateOperationReferenceField = {
|
|
257
|
+
type: 'reference';
|
|
258
|
+
refType: 'document' | 'asset';
|
|
259
|
+
refId: string;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export type UpdateOperationListField = {
|
|
263
|
+
type: 'list';
|
|
264
|
+
items: any[];
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export type FieldType =
|
|
268
|
+
| 'string'
|
|
269
|
+
| 'url'
|
|
270
|
+
| 'slug'
|
|
271
|
+
| 'text'
|
|
272
|
+
| 'markdown'
|
|
273
|
+
| 'html'
|
|
274
|
+
| 'number'
|
|
275
|
+
| 'boolean'
|
|
276
|
+
| 'enum'
|
|
277
|
+
| 'date'
|
|
278
|
+
| 'datetime'
|
|
279
|
+
| 'color'
|
|
280
|
+
| 'image'
|
|
281
|
+
| 'file'
|
|
282
|
+
| 'json'
|
|
283
|
+
| 'richText'
|
|
284
|
+
| 'object'
|
|
285
|
+
| 'model'
|
|
286
|
+
| 'reference'
|
|
287
|
+
| 'style'
|
|
288
|
+
| 'list';
|
|
289
|
+
|
|
290
|
+
export type Simplify<T> = {
|
|
291
|
+
[K in keyof T]: T[K];
|
|
292
|
+
};
|