@slicemachine/manager 0.1.1-dev-plugins-m2.1 → 0.1.1-dev-plugins-m3.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.
- package/dist/_node_modules/execa/lib/verbose.cjs +1 -1
- package/dist/_node_modules/execa/lib/verbose.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/verbose.js +1 -1
- package/dist/_node_modules/execa/lib/verbose.js.map +1 -1
- package/dist/_node_modules/human-signals/build/src/core.cjs.map +1 -1
- package/dist/_node_modules/human-signals/build/src/core.js.map +1 -1
- package/dist/_node_modules/human-signals/build/src/main.cjs +6 -11
- package/dist/_node_modules/human-signals/build/src/main.cjs.map +1 -1
- package/dist/_node_modules/human-signals/build/src/main.js +6 -11
- package/dist/_node_modules/human-signals/build/src/main.js.map +1 -1
- package/dist/_node_modules/human-signals/build/src/realtime.cjs +8 -10
- package/dist/_node_modules/human-signals/build/src/realtime.cjs.map +1 -1
- package/dist/_node_modules/human-signals/build/src/realtime.js +8 -10
- package/dist/_node_modules/human-signals/build/src/realtime.js.map +1 -1
- package/dist/_node_modules/human-signals/build/src/signals.cjs +3 -3
- package/dist/_node_modules/human-signals/build/src/signals.cjs.map +1 -1
- package/dist/_node_modules/human-signals/build/src/signals.js +3 -3
- package/dist/_node_modules/human-signals/build/src/signals.js.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.cjs +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.cjs.map +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.js +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.js.map +1 -1
- package/dist/lib/mockSlice.cjs +31 -0
- package/dist/lib/mockSlice.cjs.map +1 -0
- package/dist/lib/mockSlice.d.ts +9 -0
- package/dist/lib/mockSlice.js +31 -0
- package/dist/lib/mockSlice.js.map +1 -0
- package/dist/managers/SliceMachineManager.cjs +1 -1
- package/dist/managers/SliceMachineManager.cjs.map +1 -1
- package/dist/managers/SliceMachineManager.d.ts +6 -6
- package/dist/managers/SliceMachineManager.js +1 -1
- package/dist/managers/SliceMachineManager.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +2 -2
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.d.ts +4 -4
- package/dist/managers/customTypes/CustomTypesManager.js +2 -2
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/prismicRepository/types.cjs.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +5 -5
- package/dist/managers/prismicRepository/types.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs +6 -1
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.js +6 -1
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +35 -5
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +14 -9
- package/dist/managers/slices/SlicesManager.js +35 -5
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/dist/test/index.d.ts +2 -1
- package/package.json +8 -6
- package/src/client/index.ts +2 -2
- package/src/index.ts +6 -8
- package/src/lib/buildPrismicRepositoryAPIEndpoint.ts +3 -3
- package/src/lib/mockSlice.ts +44 -0
- package/src/managers/SliceMachineManager.ts +10 -7
- package/src/managers/customTypes/CustomTypesManager.ts +5 -5
- package/src/managers/prismicRepository/types.ts +8 -5
- package/src/managers/project/ProjectManager.ts +8 -2
- package/src/managers/slices/SlicesManager.ts +57 -13
- package/src/test/index.ts +2 -4
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/manager",
|
|
3
|
-
"version": "0.1.1-dev-plugins-
|
|
3
|
+
"version": "0.1.1-dev-plugins-m3.0",
|
|
4
4
|
"description": "Manage all aspects of a Slice Machine project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "ssh://git@github.com/prismicio/slice-machine.git"
|
|
7
|
+
"url": "ssh://git@github.com/prismicio/slice-machine.git",
|
|
8
|
+
"directory": "packages/manager"
|
|
8
9
|
},
|
|
9
10
|
"license": "Apache-2.0",
|
|
10
11
|
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
@@ -62,8 +63,9 @@
|
|
|
62
63
|
"dependencies": {
|
|
63
64
|
"@antfu/ni": "^0.20.0",
|
|
64
65
|
"@prismicio/custom-types-client": "^1.1.0",
|
|
65
|
-
"@prismicio/
|
|
66
|
-
"@
|
|
66
|
+
"@prismicio/mocks": "2.0.0-alpha.2",
|
|
67
|
+
"@prismicio/types-internal": "2.0.0-alpha.9",
|
|
68
|
+
"@slicemachine/plugin-kit": "0.1.8-dev-plugins-m3.0",
|
|
67
69
|
"@wooorm/starry-night": "^1.6.0",
|
|
68
70
|
"analytics-node": "^6.2.0",
|
|
69
71
|
"cookie": "^0.5.0",
|
|
@@ -101,7 +103,7 @@
|
|
|
101
103
|
"@vitest/coverage-c8": "^0.27.3",
|
|
102
104
|
"better-npm-audit": "^3.7.3",
|
|
103
105
|
"depcheck": "^1.4.3",
|
|
104
|
-
"eslint": "^8.
|
|
106
|
+
"eslint": "^8.37.0",
|
|
105
107
|
"eslint-config-prettier": "^8.7.0",
|
|
106
108
|
"eslint-plugin-prettier": "^4.2.1",
|
|
107
109
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
@@ -136,5 +138,5 @@
|
|
|
136
138
|
"publishConfig": {
|
|
137
139
|
"access": "public"
|
|
138
140
|
},
|
|
139
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "9223acb43eebf3f0e1731090b48c44ebd96f4aae"
|
|
140
142
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// This file defines the `@slicemachine/manager/client` export.
|
|
2
2
|
// All exports must be designed for non-Node.js usage.
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export { createSliceMachineManagerClient } from "../managers/createSliceMachineManagerClient";
|
|
5
|
+
export type {
|
|
5
6
|
CreateSliceMachineManagerClientArgs,
|
|
6
7
|
SliceMachineManagerClient,
|
|
7
|
-
createSliceMachineManagerClient,
|
|
8
8
|
} from "../managers/createSliceMachineManagerClient";
|
|
9
9
|
|
|
10
10
|
export type {
|
package/src/index.ts
CHANGED
|
@@ -3,23 +3,21 @@
|
|
|
3
3
|
|
|
4
4
|
export type { PrismicRepository } from "./managers/prismicRepository/types";
|
|
5
5
|
|
|
6
|
-
export { SliceMachineManager } from "./managers/SliceMachineManager";
|
|
6
|
+
export type { SliceMachineManager } from "./managers/SliceMachineManager";
|
|
7
7
|
export { createSliceMachineManager } from "./managers/createSliceMachineManager";
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
createSliceMachineManagerMiddleware,
|
|
11
|
-
} from "./managers/createSliceMachineManagerMiddleware";
|
|
8
|
+
export { createSliceMachineManagerMiddleware } from "./managers/createSliceMachineManagerMiddleware";
|
|
9
|
+
export type { CreateSliceMachineManagerMiddlewareArgs } from "./managers/createSliceMachineManagerMiddleware";
|
|
12
10
|
|
|
13
|
-
export {
|
|
11
|
+
export type {
|
|
14
12
|
PrismicAuthManager,
|
|
15
13
|
PrismicUserProfile,
|
|
16
14
|
PrismicAuthState,
|
|
17
15
|
} from "./auth/PrismicAuthManager";
|
|
18
16
|
export { createPrismicAuthManager } from "./auth/createPrismicAuthManager";
|
|
19
|
-
export {
|
|
17
|
+
export { createPrismicAuthManagerMiddleware } from "./auth/createPrismicAuthManagerMiddleware";
|
|
18
|
+
export type {
|
|
20
19
|
CreatePrismicAuthManagerMiddlewareArgs,
|
|
21
20
|
PrismicAuthCheckStatusResponse,
|
|
22
|
-
createPrismicAuthManagerMiddleware,
|
|
23
21
|
} from "./auth/createPrismicAuthManagerMiddleware";
|
|
24
22
|
|
|
25
23
|
export { DecodeError } from "./lib/DecodeError";
|
|
@@ -10,7 +10,7 @@ export const buildPrismicRepositoryAPIEndpoint = (
|
|
|
10
10
|
): string => {
|
|
11
11
|
const baseEndpoint = new URL(API_ENDPOINTS.PrismicWroom);
|
|
12
12
|
|
|
13
|
-
return `${baseEndpoint.protocol}
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
return `${baseEndpoint.protocol}//${repositoryName}${withCDN ? ".cdn" : ""}.${
|
|
14
|
+
baseEndpoint.host
|
|
15
|
+
}/api/v2`;
|
|
16
16
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SharedSliceMock } from "@prismicio/mocks";
|
|
2
|
+
|
|
3
|
+
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
|
|
4
|
+
import {
|
|
5
|
+
SharedSlice,
|
|
6
|
+
SliceDiff,
|
|
7
|
+
} from "@prismicio/types-internal/lib/customtypes";
|
|
8
|
+
|
|
9
|
+
type mockSliceArgs = {
|
|
10
|
+
model: SharedSlice;
|
|
11
|
+
mocks?: SharedSliceContent[];
|
|
12
|
+
diff?: SliceDiff;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const mockSlice = (args: mockSliceArgs): SharedSliceContent[] => {
|
|
16
|
+
const { model, mocks, diff } = args;
|
|
17
|
+
|
|
18
|
+
return model.variations.map((variation) => {
|
|
19
|
+
const variationMock = mocks?.find((m) => m.variation === variation.id);
|
|
20
|
+
|
|
21
|
+
if (!variationMock) {
|
|
22
|
+
return SharedSliceMock.generate(model, {
|
|
23
|
+
type: "SharedSlice",
|
|
24
|
+
variation: variation.id,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!diff) {
|
|
28
|
+
return variationMock;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const patched = SharedSliceMock.patch(diff, variationMock);
|
|
32
|
+
if (!patched.ok) {
|
|
33
|
+
return variationMock;
|
|
34
|
+
}
|
|
35
|
+
if (!patched.result) {
|
|
36
|
+
return SharedSliceMock.generate(model, {
|
|
37
|
+
type: "SharedSlice",
|
|
38
|
+
variation: variation.id,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return patched.result;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SharedSlice,
|
|
3
|
+
CustomType,
|
|
4
|
+
} from "@prismicio/types-internal/lib/customtypes";
|
|
2
5
|
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
|
|
3
6
|
import {
|
|
4
7
|
ForbiddenError,
|
|
@@ -60,7 +63,7 @@ type SliceMachineManagerGetStateReturnType = {
|
|
|
60
63
|
pathToSlice: string;
|
|
61
64
|
fileName: string | null;
|
|
62
65
|
extension: string | null;
|
|
63
|
-
model:
|
|
66
|
+
model: SharedSlice;
|
|
64
67
|
screenshots: Record<
|
|
65
68
|
string,
|
|
66
69
|
{
|
|
@@ -68,7 +71,7 @@ type SliceMachineManagerGetStateReturnType = {
|
|
|
68
71
|
data: Buffer;
|
|
69
72
|
}
|
|
70
73
|
>;
|
|
71
|
-
|
|
74
|
+
mocks?: SharedSliceContent[];
|
|
72
75
|
}[];
|
|
73
76
|
meta: {
|
|
74
77
|
name?: string;
|
|
@@ -78,9 +81,9 @@ type SliceMachineManagerGetStateReturnType = {
|
|
|
78
81
|
isManual: boolean;
|
|
79
82
|
};
|
|
80
83
|
}[];
|
|
81
|
-
customTypes:
|
|
82
|
-
remoteCustomTypes:
|
|
83
|
-
remoteSlices:
|
|
84
|
+
customTypes: CustomType[];
|
|
85
|
+
remoteCustomTypes: CustomType[];
|
|
86
|
+
remoteSlices: SharedSlice[];
|
|
84
87
|
clientError?: {
|
|
85
88
|
name: string;
|
|
86
89
|
message: string;
|
|
@@ -324,7 +327,7 @@ export class SliceMachineManager {
|
|
|
324
327
|
extension: "extension",
|
|
325
328
|
model,
|
|
326
329
|
screenshots,
|
|
327
|
-
|
|
330
|
+
mocks,
|
|
328
331
|
});
|
|
329
332
|
}
|
|
330
333
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
3
|
import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
|
|
4
|
-
import {
|
|
4
|
+
import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
5
5
|
import {
|
|
6
6
|
CallHookReturnType,
|
|
7
7
|
CustomTypeCreateHook,
|
|
@@ -30,12 +30,12 @@ type SliceMachineManagerReadCustomTypeLibraryReturnType = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
type SliceMachineManagerReadAllCustomTypeReturnType = {
|
|
33
|
-
models: { model:
|
|
33
|
+
models: { model: CustomType }[];
|
|
34
34
|
errors: (DecodeError | HookError)[];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
type SliceMachineManagerReadCustomTypeReturnType = {
|
|
38
|
-
model:
|
|
38
|
+
model: CustomType | undefined;
|
|
39
39
|
errors: (DecodeError | HookError)[];
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -143,7 +143,7 @@ export class CustomTypesManager extends BaseManager {
|
|
|
143
143
|
);
|
|
144
144
|
const { data, errors } = decodeHookResult(
|
|
145
145
|
t.type({
|
|
146
|
-
model:
|
|
146
|
+
model: CustomType,
|
|
147
147
|
}),
|
|
148
148
|
hookResult,
|
|
149
149
|
);
|
|
@@ -302,7 +302,7 @@ export class CustomTypesManager extends BaseManager {
|
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
async fetchRemoteCustomTypes(): Promise<
|
|
305
|
+
async fetchRemoteCustomTypes(): Promise<CustomType[]> {
|
|
306
306
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
307
307
|
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
308
308
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CustomType,
|
|
3
|
+
SharedSlice,
|
|
4
|
+
} from "@prismicio/types-internal/lib/customtypes";
|
|
2
5
|
import * as t from "io-ts";
|
|
3
6
|
|
|
4
7
|
export const PrismicRepositoryUserAgent = {
|
|
@@ -50,22 +53,22 @@ interface DeleteChange extends Change {
|
|
|
50
53
|
}
|
|
51
54
|
export interface SliceInsertChange extends Change {
|
|
52
55
|
type: ChangeTypes.SLICE_INSERT;
|
|
53
|
-
payload:
|
|
56
|
+
payload: SharedSlice;
|
|
54
57
|
}
|
|
55
58
|
export interface SliceUpdateChange extends Change {
|
|
56
59
|
type: ChangeTypes.SLICE_UPDATE;
|
|
57
|
-
payload:
|
|
60
|
+
payload: SharedSlice;
|
|
58
61
|
}
|
|
59
62
|
export interface SliceDeleteChange extends DeleteChange {
|
|
60
63
|
type: ChangeTypes.SLICE_DELETE;
|
|
61
64
|
}
|
|
62
65
|
export interface CustomTypeInsertChange extends Change {
|
|
63
66
|
type: ChangeTypes.CUSTOM_TYPE_INSERT;
|
|
64
|
-
payload:
|
|
67
|
+
payload: CustomType;
|
|
65
68
|
}
|
|
66
69
|
export interface CustomTypeUpdateChange extends Change {
|
|
67
70
|
type: ChangeTypes.CUSTOM_TYPE_UPDATE;
|
|
68
|
-
payload:
|
|
71
|
+
payload: CustomType;
|
|
69
72
|
}
|
|
70
73
|
export interface CustomTypeDeleteChange extends DeleteChange {
|
|
71
74
|
type: ChangeTypes.CUSTOM_TYPE_DELETE;
|
|
@@ -153,8 +153,14 @@ export class ProjectManager extends BaseManager {
|
|
|
153
153
|
try {
|
|
154
154
|
const contents = await fs.readFile(configFilePath, "utf8");
|
|
155
155
|
rawConfig = JSON.parse(contents);
|
|
156
|
-
} catch {
|
|
157
|
-
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (error instanceof SyntaxError) {
|
|
158
|
+
throw new SliceMachineError(
|
|
159
|
+
`Could not parse config file at ${configFilePath}.\n\nError Message: ${error.message}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Noop, more specific error is thrown after
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
if (!rawConfig) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
3
|
import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
|
|
4
|
-
import { CustomTypes } from "@prismicio/types-internal";
|
|
5
4
|
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
|
|
6
5
|
import {
|
|
7
6
|
CallHookReturnType,
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
SliceRenameHook,
|
|
15
14
|
SliceRenameHookData,
|
|
16
15
|
SliceUpdateHook,
|
|
17
|
-
SliceUpdateHookData,
|
|
18
16
|
} from "@slicemachine/plugin-kit";
|
|
19
17
|
|
|
20
18
|
import { DecodeError } from "../../lib/DecodeError";
|
|
@@ -29,6 +27,9 @@ import { UnauthenticatedError, UnauthorizedError } from "../../errors";
|
|
|
29
27
|
|
|
30
28
|
import { BaseManager } from "../BaseManager";
|
|
31
29
|
import { createContentDigest } from "../../lib/createContentDigest";
|
|
30
|
+
import { mockSlice } from "../../lib/mockSlice";
|
|
31
|
+
import { SliceComparator } from "@prismicio/types-internal/lib/customtypes/diff";
|
|
32
|
+
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
32
33
|
|
|
33
34
|
type SlicesManagerReadSliceLibraryReturnType = {
|
|
34
35
|
sliceIDs: string[];
|
|
@@ -47,21 +48,27 @@ type SliceMachineManagerReadAllSlicesForLibraryArgs = {
|
|
|
47
48
|
libraryID: string;
|
|
48
49
|
};
|
|
49
50
|
|
|
51
|
+
type SliceMachineManagerUpdateSliceArgs = {
|
|
52
|
+
libraryID: string;
|
|
53
|
+
model: SharedSlice;
|
|
54
|
+
mocks?: SharedSliceContent[];
|
|
55
|
+
};
|
|
56
|
+
|
|
50
57
|
type SliceMachineManagerReadAllSlicesForLibraryReturnType = {
|
|
51
|
-
models: { model:
|
|
58
|
+
models: { model: SharedSlice }[];
|
|
52
59
|
errors: (DecodeError | HookError)[];
|
|
53
60
|
};
|
|
54
61
|
|
|
55
62
|
type SliceMachineManagerReadAllSlicesReturnType = {
|
|
56
63
|
models: {
|
|
57
64
|
libraryID: string;
|
|
58
|
-
model:
|
|
65
|
+
model: SharedSlice;
|
|
59
66
|
}[];
|
|
60
67
|
errors: (DecodeError | HookError)[];
|
|
61
68
|
};
|
|
62
69
|
|
|
63
70
|
type SliceMachineManagerReadSliceReturnType = {
|
|
64
|
-
model:
|
|
71
|
+
model: SharedSlice | undefined;
|
|
65
72
|
errors: (DecodeError | HookError)[];
|
|
66
73
|
};
|
|
67
74
|
|
|
@@ -129,7 +136,7 @@ type SliceMachineManagerUpdateSliceMocksArgsReturnType = {
|
|
|
129
136
|
|
|
130
137
|
type SlicesManagerUpsertHostedSliceScrenshotsArgs = {
|
|
131
138
|
libraryID: string;
|
|
132
|
-
model:
|
|
139
|
+
model: SharedSlice;
|
|
133
140
|
};
|
|
134
141
|
|
|
135
142
|
type SliceMachineManagerDeleteSliceArgs = {
|
|
@@ -264,8 +271,18 @@ export class SlicesManager extends BaseManager {
|
|
|
264
271
|
args,
|
|
265
272
|
);
|
|
266
273
|
|
|
274
|
+
const updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {
|
|
275
|
+
libraryID: args.libraryID,
|
|
276
|
+
sliceID: args.model.id,
|
|
277
|
+
mocks: mockSlice({ model: args.model }),
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const { errors: updateSliceHookErrors } = await this.updateSliceMocks(
|
|
281
|
+
updateSliceMocksArgs,
|
|
282
|
+
);
|
|
283
|
+
|
|
267
284
|
return {
|
|
268
|
-
errors: hookResult.errors,
|
|
285
|
+
errors: [...hookResult.errors, ...updateSliceHookErrors],
|
|
269
286
|
};
|
|
270
287
|
}
|
|
271
288
|
|
|
@@ -280,29 +297,56 @@ export class SlicesManager extends BaseManager {
|
|
|
280
297
|
);
|
|
281
298
|
const { data, errors } = decodeHookResult(
|
|
282
299
|
t.type({
|
|
283
|
-
model:
|
|
300
|
+
model: SharedSlice,
|
|
284
301
|
}),
|
|
285
302
|
hookResult,
|
|
286
303
|
);
|
|
287
304
|
|
|
288
305
|
return {
|
|
289
306
|
model: data[0]?.model,
|
|
290
|
-
errors
|
|
307
|
+
errors: errors.map((error) => {
|
|
308
|
+
error.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;
|
|
309
|
+
|
|
310
|
+
return error;
|
|
311
|
+
}),
|
|
291
312
|
};
|
|
292
313
|
}
|
|
293
314
|
|
|
294
315
|
async updateSlice(
|
|
295
|
-
args:
|
|
316
|
+
args: SliceMachineManagerUpdateSliceArgs,
|
|
296
317
|
): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {
|
|
297
318
|
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
298
319
|
|
|
320
|
+
const { mocks: previousMocks } = await this.readSliceMocks({
|
|
321
|
+
libraryID: args.libraryID,
|
|
322
|
+
sliceID: args.model.id,
|
|
323
|
+
});
|
|
324
|
+
const { model: previousModel } = await this.readSlice({
|
|
325
|
+
libraryID: args.libraryID,
|
|
326
|
+
sliceID: args.model.id,
|
|
327
|
+
});
|
|
299
328
|
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
300
329
|
"slice:update",
|
|
301
330
|
args,
|
|
302
331
|
);
|
|
303
332
|
|
|
333
|
+
const updatedMocks = mockSlice({
|
|
334
|
+
model: args.model,
|
|
335
|
+
mocks: previousMocks,
|
|
336
|
+
diff: SliceComparator.compare(previousModel, args.model),
|
|
337
|
+
});
|
|
338
|
+
const updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {
|
|
339
|
+
libraryID: args.libraryID,
|
|
340
|
+
sliceID: args.model.id,
|
|
341
|
+
mocks: updatedMocks,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const { errors: updateSliceMocksHookResult } = await this.updateSliceMocks(
|
|
345
|
+
updateSliceMocksArgs,
|
|
346
|
+
);
|
|
347
|
+
|
|
304
348
|
return {
|
|
305
|
-
errors: hookResult.errors,
|
|
349
|
+
errors: [...hookResult.errors, ...updateSliceMocksHookResult],
|
|
306
350
|
};
|
|
307
351
|
}
|
|
308
352
|
|
|
@@ -583,7 +627,7 @@ export class SlicesManager extends BaseManager {
|
|
|
583
627
|
}
|
|
584
628
|
}
|
|
585
629
|
|
|
586
|
-
async fetchRemoteSlices(): Promise<
|
|
630
|
+
async fetchRemoteSlices(): Promise<SharedSlice[]> {
|
|
587
631
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
588
632
|
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
589
633
|
|
|
@@ -599,7 +643,7 @@ export class SlicesManager extends BaseManager {
|
|
|
599
643
|
|
|
600
644
|
async updateSliceModelScreenshotsInPlace(
|
|
601
645
|
args: SlicesManagerUpsertHostedSliceScrenshotsArgs,
|
|
602
|
-
): Promise<
|
|
646
|
+
): Promise<SharedSlice> {
|
|
603
647
|
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
604
648
|
|
|
605
649
|
const variations = await Promise.all(
|
package/src/test/index.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
CreateSliceMachineManagerMSWHandlerArgs,
|
|
4
|
-
} from "./createSliceMachineManagerMSWHandler";
|
|
1
|
+
export { createSliceMachineManagerMSWHandler } from "./createSliceMachineManagerMSWHandler";
|
|
2
|
+
export type { CreateSliceMachineManagerMSWHandlerArgs } from "./createSliceMachineManagerMSWHandler";
|