@slicemachine/manager 0.24.15-alpha.dependabot-npm-and-yarn-nuxt-3-16-0.1 → 0.24.15-alpha.jp-update-cr-links-base.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/_node_modules/{npm-run-path → execa/_node_modules/npm-run-path}/index.cjs +1 -1
- package/dist/_node_modules/execa/_node_modules/npm-run-path/index.cjs.map +1 -0
- package/dist/_node_modules/{npm-run-path → execa/_node_modules/npm-run-path}/index.js +1 -1
- package/dist/_node_modules/execa/_node_modules/npm-run-path/index.js.map +1 -0
- package/dist/_node_modules/{onetime → execa/_node_modules/onetime}/index.cjs +1 -1
- package/dist/_node_modules/execa/_node_modules/onetime/index.cjs.map +1 -0
- package/dist/_node_modules/{onetime → execa/_node_modules/onetime}/index.js +1 -1
- package/dist/_node_modules/execa/_node_modules/onetime/index.js.map +1 -0
- package/dist/_node_modules/execa/_node_modules/path-key/index.cjs.map +1 -0
- package/dist/_node_modules/execa/_node_modules/path-key/index.js.map +1 -0
- package/dist/_node_modules/execa/index.cjs +2 -2
- package/dist/_node_modules/execa/index.js +2 -2
- package/dist/managers/customTypes/CustomTypesManager.cjs +176 -3
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.d.ts +116 -9
- package/dist/managers/customTypes/CustomTypesManager.js +178 -5
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/package.json +4 -4
- package/src/managers/customTypes/CustomTypesManager.ts +300 -3
- package/dist/_node_modules/npm-run-path/_node_modules/path-key/index.cjs.map +0 -1
- package/dist/_node_modules/npm-run-path/_node_modules/path-key/index.js.map +0 -1
- package/dist/_node_modules/npm-run-path/index.cjs.map +0 -1
- package/dist/_node_modules/npm-run-path/index.js.map +0 -1
- package/dist/_node_modules/onetime/index.cjs.map +0 -1
- package/dist/_node_modules/onetime/index.js.map +0 -1
- /package/dist/_node_modules/{npm-run-path → execa}/_node_modules/path-key/index.cjs +0 -0
- /package/dist/_node_modules/{npm-run-path → execa}/_node_modules/path-key/index.js +0 -0
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const process = require("node:process");
|
4
4
|
const path = require("node:path");
|
5
5
|
const url = require("node:url");
|
6
|
-
const index = require(
|
6
|
+
const index = require("../path-key/index.cjs");
|
7
7
|
function npmRunPath(options = {}) {
|
8
8
|
const {
|
9
9
|
cwd = process.cwd(),
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../../../node_modules/execa/node_modules/npm-run-path/index.js"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport url from 'node:url';\nimport pathKey from 'path-key';\n\nexport function npmRunPath(options = {}) {\n\tconst {\n\t\tcwd = process.cwd(),\n\t\tpath: path_ = process.env[pathKey()],\n\t\texecPath = process.execPath,\n\t} = options;\n\n\tlet previous;\n\tconst cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd;\n\tlet cwdPath = path.resolve(cwdString);\n\tconst result = [];\n\n\twhile (previous !== cwdPath) {\n\t\tresult.push(path.join(cwdPath, 'node_modules/.bin'));\n\t\tprevious = cwdPath;\n\t\tcwdPath = path.resolve(cwdPath, '..');\n\t}\n\n\t// Ensure the running `node` binary is used.\n\tresult.push(path.resolve(cwdString, execPath, '..'));\n\n\treturn [...result, path_].join(path.delimiter);\n}\n\nexport function npmRunPathEnv({env = process.env, ...options} = {}) {\n\tenv = {...env};\n\n\tconst path = pathKey({env});\n\toptions.path = env[path];\n\tenv[path] = npmRunPath(options);\n\n\treturn env;\n}\n"],"names":["pathKey","path"],"mappings":";;;;;;AAKO,SAAS,WAAW,UAAU,IAAI;AACxC,QAAM;AAAA,IACL,MAAM,QAAQ,IAAK;AAAA,IACnB,MAAM,QAAQ,QAAQ,IAAIA,MAAO,CAAE;AAAA,IACnC,WAAW,QAAQ;AAAA,EACnB,IAAG;AAEJ,MAAI;AACJ,QAAM,YAAY,eAAe,MAAM,IAAI,cAAc,GAAG,IAAI;AAChE,MAAI,UAAU,KAAK,QAAQ,SAAS;AACpC,QAAM,SAAS,CAAA;AAEf,SAAO,aAAa,SAAS;AAC5B,WAAO,KAAK,KAAK,KAAK,SAAS,mBAAmB,CAAC;AACnD,eAAW;AACX,cAAU,KAAK,QAAQ,SAAS,IAAI;AAAA,EACpC;AAGD,SAAO,KAAK,KAAK,QAAQ,WAAW,UAAU,IAAI,CAAC;AAEnD,SAAO,CAAC,GAAG,QAAQ,KAAK,EAAE,KAAK,KAAK,SAAS;AAC9C;AAEO,SAAS,cAAc,EAAC,MAAM,QAAQ,KAAK,GAAG,QAAO,IAAI,IAAI;AACnE,QAAM,EAAC,GAAG,IAAG;AAEb,QAAMC,QAAOD,MAAQ,EAAC,IAAG,CAAC;AAC1B,UAAQ,OAAO,IAAIC,KAAI;AACvB,MAAIA,KAAI,IAAI,WAAW,OAAO;AAE9B,SAAO;AACR;;;","x_google_ignoreList":[0]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import process from "node:process";
|
2
2
|
import path__default from "node:path";
|
3
3
|
import url from "node:url";
|
4
|
-
import pathKey from
|
4
|
+
import pathKey from "../path-key/index.js";
|
5
5
|
function npmRunPath(options = {}) {
|
6
6
|
const {
|
7
7
|
cwd = process.cwd(),
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../../node_modules/execa/node_modules/npm-run-path/index.js"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport url from 'node:url';\nimport pathKey from 'path-key';\n\nexport function npmRunPath(options = {}) {\n\tconst {\n\t\tcwd = process.cwd(),\n\t\tpath: path_ = process.env[pathKey()],\n\t\texecPath = process.execPath,\n\t} = options;\n\n\tlet previous;\n\tconst cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd;\n\tlet cwdPath = path.resolve(cwdString);\n\tconst result = [];\n\n\twhile (previous !== cwdPath) {\n\t\tresult.push(path.join(cwdPath, 'node_modules/.bin'));\n\t\tprevious = cwdPath;\n\t\tcwdPath = path.resolve(cwdPath, '..');\n\t}\n\n\t// Ensure the running `node` binary is used.\n\tresult.push(path.resolve(cwdString, execPath, '..'));\n\n\treturn [...result, path_].join(path.delimiter);\n}\n\nexport function npmRunPathEnv({env = process.env, ...options} = {}) {\n\tenv = {...env};\n\n\tconst path = pathKey({env});\n\toptions.path = env[path];\n\tenv[path] = npmRunPath(options);\n\n\treturn env;\n}\n"],"names":["path"],"mappings":";;;;AAKO,SAAS,WAAW,UAAU,IAAI;AACxC,QAAM;AAAA,IACL,MAAM,QAAQ,IAAK;AAAA,IACnB,MAAM,QAAQ,QAAQ,IAAI,QAAO,CAAE;AAAA,IACnC,WAAW,QAAQ;AAAA,EACnB,IAAG;AAEJ,MAAI;AACJ,QAAM,YAAY,eAAe,MAAM,IAAI,cAAc,GAAG,IAAI;AAChE,MAAI,UAAUA,cAAK,QAAQ,SAAS;AACpC,QAAM,SAAS,CAAA;AAEf,SAAO,aAAa,SAAS;AAC5B,WAAO,KAAKA,cAAK,KAAK,SAAS,mBAAmB,CAAC;AACnD,eAAW;AACX,cAAUA,cAAK,QAAQ,SAAS,IAAI;AAAA,EACpC;AAGD,SAAO,KAAKA,cAAK,QAAQ,WAAW,UAAU,IAAI,CAAC;AAEnD,SAAO,CAAC,GAAG,QAAQ,KAAK,EAAE,KAAKA,cAAK,SAAS;AAC9C;AAEO,SAAS,cAAc,EAAC,MAAM,QAAQ,KAAK,GAAG,QAAO,IAAI,IAAI;AACnE,QAAM,EAAC,GAAG,IAAG;AAEb,QAAM,OAAO,QAAQ,EAAC,IAAG,CAAC;AAC1B,UAAQ,OAAO,IAAI,IAAI;AACvB,MAAI,IAAI,IAAI,WAAW,OAAO;AAE9B,SAAO;AACR;","x_google_ignoreList":[0]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../../../node_modules/execa/node_modules/onetime/index.js"],"sourcesContent":["import mimicFunction from 'mimic-fn';\n\nconst calledFunctions = new WeakMap();\n\nconst onetime = (function_, options = {}) => {\n\tif (typeof function_ !== 'function') {\n\t\tthrow new TypeError('Expected a function');\n\t}\n\n\tlet returnValue;\n\tlet callCount = 0;\n\tconst functionName = function_.displayName || function_.name || '<anonymous>';\n\n\tconst onetime = function (...arguments_) {\n\t\tcalledFunctions.set(onetime, ++callCount);\n\n\t\tif (callCount === 1) {\n\t\t\treturnValue = function_.apply(this, arguments_);\n\t\t\tfunction_ = null;\n\t\t} else if (options.throw === true) {\n\t\t\tthrow new Error(`Function \\`${functionName}\\` can only be called once`);\n\t\t}\n\n\t\treturn returnValue;\n\t};\n\n\tmimicFunction(onetime, function_);\n\tcalledFunctions.set(onetime, callCount);\n\n\treturn onetime;\n};\n\nonetime.callCount = function_ => {\n\tif (!calledFunctions.has(function_)) {\n\t\tthrow new Error(`The given function \\`${function_.name}\\` is not wrapped by the \\`onetime\\` package`);\n\t}\n\n\treturn calledFunctions.get(function_);\n};\n\nexport default onetime;\n"],"names":["onetime","mimicFunction"],"mappings":";;AAEA,MAAM,kBAAkB,oBAAI;AAEvB,MAAC,UAAU,CAAC,WAAW,UAAU,OAAO;AAC5C,MAAI,OAAO,cAAc,YAAY;AACpC,UAAM,IAAI,UAAU,qBAAqB;AAAA,EACzC;AAED,MAAI;AACJ,MAAI,YAAY;AAChB,QAAM,eAAe,UAAU,eAAe,UAAU,QAAQ;AAEhE,QAAMA,WAAU,YAAa,YAAY;AACxC,oBAAgB,IAAIA,UAAS,EAAE,SAAS;AAExC,QAAI,cAAc,GAAG;AACpB,oBAAc,UAAU,MAAM,MAAM,UAAU;AAC9C,kBAAY;AAAA,IACf,WAAa,QAAQ,UAAU,MAAM;AAClC,YAAM,IAAI,MAAM,cAAc,wCAAwC;AAAA,IACtE;AAED,WAAO;AAAA,EACT;AAECC,QAAcD,UAAS,SAAS;AAChC,kBAAgB,IAAIA,UAAS,SAAS;AAEtC,SAAOA;AACR;AAEA,QAAQ,YAAY,eAAa;AAChC,MAAI,CAAC,gBAAgB,IAAI,SAAS,GAAG;AACpC,UAAM,IAAI,MAAM,wBAAwB,UAAU,kDAAkD;AAAA,EACpG;AAED,SAAO,gBAAgB,IAAI,SAAS;AACrC;;","x_google_ignoreList":[0]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../../node_modules/execa/node_modules/onetime/index.js"],"sourcesContent":["import mimicFunction from 'mimic-fn';\n\nconst calledFunctions = new WeakMap();\n\nconst onetime = (function_, options = {}) => {\n\tif (typeof function_ !== 'function') {\n\t\tthrow new TypeError('Expected a function');\n\t}\n\n\tlet returnValue;\n\tlet callCount = 0;\n\tconst functionName = function_.displayName || function_.name || '<anonymous>';\n\n\tconst onetime = function (...arguments_) {\n\t\tcalledFunctions.set(onetime, ++callCount);\n\n\t\tif (callCount === 1) {\n\t\t\treturnValue = function_.apply(this, arguments_);\n\t\t\tfunction_ = null;\n\t\t} else if (options.throw === true) {\n\t\t\tthrow new Error(`Function \\`${functionName}\\` can only be called once`);\n\t\t}\n\n\t\treturn returnValue;\n\t};\n\n\tmimicFunction(onetime, function_);\n\tcalledFunctions.set(onetime, callCount);\n\n\treturn onetime;\n};\n\nonetime.callCount = function_ => {\n\tif (!calledFunctions.has(function_)) {\n\t\tthrow new Error(`The given function \\`${function_.name}\\` is not wrapped by the \\`onetime\\` package`);\n\t}\n\n\treturn calledFunctions.get(function_);\n};\n\nexport default onetime;\n"],"names":["onetime"],"mappings":";AAEA,MAAM,kBAAkB,oBAAI;AAEvB,MAAC,UAAU,CAAC,WAAW,UAAU,OAAO;AAC5C,MAAI,OAAO,cAAc,YAAY;AACpC,UAAM,IAAI,UAAU,qBAAqB;AAAA,EACzC;AAED,MAAI;AACJ,MAAI,YAAY;AAChB,QAAM,eAAe,UAAU,eAAe,UAAU,QAAQ;AAEhE,QAAMA,WAAU,YAAa,YAAY;AACxC,oBAAgB,IAAIA,UAAS,EAAE,SAAS;AAExC,QAAI,cAAc,GAAG;AACpB,oBAAc,UAAU,MAAM,MAAM,UAAU;AAC9C,kBAAY;AAAA,IACf,WAAa,QAAQ,UAAU,MAAM;AAClC,YAAM,IAAI,MAAM,cAAc,wCAAwC;AAAA,IACtE;AAED,WAAO;AAAA,EACT;AAEC,gBAAcA,UAAS,SAAS;AAChC,kBAAgB,IAAIA,UAAS,SAAS;AAEtC,SAAOA;AACR;AAEA,QAAQ,YAAY,eAAa;AAChC,MAAI,CAAC,gBAAgB,IAAI,SAAS,GAAG;AACpC,UAAM,IAAI,MAAM,wBAAwB,UAAU,kDAAkD;AAAA,EACpG;AAED,SAAO,gBAAgB,IAAI,SAAS;AACrC;","x_google_ignoreList":[0]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../../../node_modules/execa/node_modules/path-key/index.js"],"sourcesContent":["export default function pathKey(options = {}) {\n\tconst {\n\t\tenv = process.env,\n\t\tplatform = process.platform\n\t} = options;\n\n\tif (platform !== 'win32') {\n\t\treturn 'PATH';\n\t}\n\n\treturn Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';\n}\n"],"names":[],"mappings":";AAAe,SAAS,QAAQ,UAAU,IAAI;AAC7C,QAAM;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,WAAW,QAAQ;AAAA,EACnB,IAAG;AAEJ,MAAI,aAAa,SAAS;AACzB,WAAO;AAAA,EACP;AAED,SAAO,OAAO,KAAK,GAAG,EAAE,QAAO,EAAG,KAAK,SAAO,IAAI,YAAW,MAAO,MAAM,KAAK;AAChF;;","x_google_ignoreList":[0]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../../node_modules/execa/node_modules/path-key/index.js"],"sourcesContent":["export default function pathKey(options = {}) {\n\tconst {\n\t\tenv = process.env,\n\t\tplatform = process.platform\n\t} = options;\n\n\tif (platform !== 'win32') {\n\t\treturn 'PATH';\n\t}\n\n\treturn Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';\n}\n"],"names":[],"mappings":"AAAe,SAAS,QAAQ,UAAU,IAAI;AAC7C,QAAM;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,WAAW,QAAQ;AAAA,EACnB,IAAG;AAEJ,MAAI,aAAa,SAAS;AACzB,WAAO;AAAA,EACP;AAED,SAAO,OAAO,KAAK,GAAG,EAAE,QAAO,EAAG,KAAK,SAAO,IAAI,YAAW,MAAO,MAAM,KAAK;AAChF;","x_google_ignoreList":[0]}
|
@@ -6,8 +6,8 @@ const childProcess = require("node:child_process");
|
|
6
6
|
const process = require("node:process");
|
7
7
|
const index = require("../cross-spawn/index.cjs");
|
8
8
|
const index$1 = require("../strip-final-newline/index.cjs");
|
9
|
-
const index$3 = require(
|
10
|
-
const index$2 = require(
|
9
|
+
const index$3 = require('./_node_modules/npm-run-path/index.cjs');
|
10
|
+
const index$2 = require('./_node_modules/onetime/index.cjs');
|
11
11
|
const error = require("./lib/error.cjs");
|
12
12
|
const stdio = require("./lib/stdio.cjs");
|
13
13
|
const kill = require("./lib/kill.cjs");
|
@@ -4,8 +4,8 @@ import childProcess from "node:child_process";
|
|
4
4
|
import process from "node:process";
|
5
5
|
import crossSpawn from "../cross-spawn/index.js";
|
6
6
|
import stripFinalNewline from "../strip-final-newline/index.js";
|
7
|
-
import { npmRunPathEnv } from
|
8
|
-
import onetime from
|
7
|
+
import { npmRunPathEnv } from './_node_modules/npm-run-path/index.js';
|
8
|
+
import onetime from './_node_modules/onetime/index.js';
|
9
9
|
import { makeError } from "./lib/error.js";
|
10
10
|
import { normalizeStdio } from "./lib/stdio.js";
|
11
11
|
import { validateTimeout, setupTimeout, setExitHandler, spawnedKill, spawnedCancel } from "./lib/kill.js";
|
@@ -80,12 +80,68 @@ class CustomTypesManager extends BaseManager.BaseManager {
|
|
80
80
|
errors: errors2
|
81
81
|
};
|
82
82
|
}
|
83
|
+
/**
|
84
|
+
* Update the Content Relationship API IDs for all existing custom types and
|
85
|
+
* slices. The change is determined by properties inside the `updateMeta`
|
86
|
+
* property.
|
87
|
+
*/
|
88
|
+
async updateContentRelationships(args) {
|
89
|
+
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
90
|
+
const { model, updateMeta } = args;
|
91
|
+
if (updateMeta == null ? void 0 : updateMeta.fieldIdChanged) {
|
92
|
+
let { previousPath, newPath } = updateMeta.fieldIdChanged;
|
93
|
+
if (previousPath.join(".") !== newPath.join(".")) {
|
94
|
+
previousPath = [model.id, ...previousPath];
|
95
|
+
newPath = [model.id, ...newPath];
|
96
|
+
const crUpdates = [];
|
97
|
+
const customTypes = await this.readAllCustomTypes();
|
98
|
+
updateCustomTypeContentRelationships({
|
99
|
+
models: customTypes.models,
|
100
|
+
onUpdate: (model2) => {
|
101
|
+
var _a;
|
102
|
+
pushIfDefined(crUpdates, (_a = this.sliceMachinePluginRunner) == null ? void 0 : _a.callHook("custom-type:update", {
|
103
|
+
model: model2
|
104
|
+
}));
|
105
|
+
},
|
106
|
+
previousPath,
|
107
|
+
newPath
|
108
|
+
});
|
109
|
+
const { libraries } = await this.slices.readAllSliceLibraries();
|
110
|
+
for (const library of libraries) {
|
111
|
+
const slices = await this.slices.readAllSlicesForLibrary({
|
112
|
+
libraryID: library.libraryID
|
113
|
+
});
|
114
|
+
updateSharedSliceContentRelationships({
|
115
|
+
models: slices.models,
|
116
|
+
onUpdate: (model2) => {
|
117
|
+
var _a;
|
118
|
+
pushIfDefined(crUpdates, (_a = this.sliceMachinePluginRunner) == null ? void 0 : _a.callHook("slice:update", {
|
119
|
+
libraryID: library.libraryID,
|
120
|
+
model: model2
|
121
|
+
}));
|
122
|
+
},
|
123
|
+
previousPath,
|
124
|
+
newPath
|
125
|
+
});
|
126
|
+
}
|
127
|
+
const crUpdatesResult = await Promise.all(crUpdates);
|
128
|
+
if (crUpdatesResult.some((result) => result.errors.length > 0)) {
|
129
|
+
return {
|
130
|
+
errors: crUpdatesResult.flatMap((result) => result.errors)
|
131
|
+
};
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return { errors: [] };
|
136
|
+
}
|
83
137
|
async updateCustomType(args) {
|
138
|
+
var _a;
|
84
139
|
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
85
140
|
const hookResult = await this.sliceMachinePluginRunner.callHook("custom-type:update", args);
|
86
|
-
|
87
|
-
|
88
|
-
}
|
141
|
+
if ((_a = args.updateMeta) == null ? void 0 : _a.fieldIdChanged) {
|
142
|
+
await this.updateContentRelationships(args);
|
143
|
+
}
|
144
|
+
return { errors: hookResult.errors };
|
89
145
|
}
|
90
146
|
async renameCustomType(args) {
|
91
147
|
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
@@ -231,5 +287,122 @@ const InferSliceResponse = index.default.object({
|
|
231
287
|
}),
|
232
288
|
langSmithUrl: index.default.string().url().optional()
|
233
289
|
});
|
290
|
+
function updateCRCustomType(args) {
|
291
|
+
const [previousCustomTypeId, previousFieldId] = args.previousPath;
|
292
|
+
const [newCustomTypeId, newFieldId] = args.newPath;
|
293
|
+
if (!previousCustomTypeId || !newCustomTypeId) {
|
294
|
+
throw new Error("Could not find a customtype id in previousPath and/or newPath, which should not be possible.");
|
295
|
+
}
|
296
|
+
if (!previousFieldId || !newFieldId) {
|
297
|
+
throw new Error("Could not find a field id in previousPath and/or newPath, which should not be possible.");
|
298
|
+
}
|
299
|
+
const customType = shallowCloneIfObject(args.customType);
|
300
|
+
if (typeof customType === "string" || !customType.fields) {
|
301
|
+
return customType;
|
302
|
+
}
|
303
|
+
const matchedCustomTypeId = customType.id === previousCustomTypeId;
|
304
|
+
const newFields = customType.fields.map((fieldArg) => {
|
305
|
+
const customTypeField = shallowCloneIfObject(fieldArg);
|
306
|
+
if (typeof customTypeField === "string") {
|
307
|
+
if (matchedCustomTypeId && customTypeField === previousFieldId && customTypeField !== newFieldId) {
|
308
|
+
return newFieldId;
|
309
|
+
}
|
310
|
+
return customTypeField;
|
311
|
+
}
|
312
|
+
if (matchedCustomTypeId && customTypeField.id === previousFieldId && customTypeField.id !== newFieldId) {
|
313
|
+
customTypeField.id = newFieldId;
|
314
|
+
}
|
315
|
+
return {
|
316
|
+
...customTypeField,
|
317
|
+
customtypes: customTypeField.customtypes.map((customTypeArg) => {
|
318
|
+
const nestedCustomType = shallowCloneIfObject(customTypeArg);
|
319
|
+
if (typeof nestedCustomType === "string" || !nestedCustomType.fields || // Since we are on the last level, if we don't start matching right
|
320
|
+
// at the custom type id, we can return exit early because it's not
|
321
|
+
// a match.
|
322
|
+
nestedCustomType.id !== previousCustomTypeId) {
|
323
|
+
return nestedCustomType;
|
324
|
+
}
|
325
|
+
return {
|
326
|
+
...nestedCustomType,
|
327
|
+
fields: nestedCustomType.fields.map((fieldArg2) => {
|
328
|
+
const nestedCustomTypeField = shallowCloneIfObject(fieldArg2);
|
329
|
+
if (nestedCustomTypeField === previousFieldId && nestedCustomTypeField !== newFieldId) {
|
330
|
+
return newFieldId;
|
331
|
+
}
|
332
|
+
return nestedCustomTypeField;
|
333
|
+
})
|
334
|
+
};
|
335
|
+
})
|
336
|
+
};
|
337
|
+
});
|
338
|
+
return { ...customType, fields: newFields };
|
339
|
+
}
|
340
|
+
function updateFieldContentRelationships(args) {
|
341
|
+
var _a, _b;
|
342
|
+
const { field, ...updateMeta } = args;
|
343
|
+
if (field.type !== "Link" || ((_a = field.config) == null ? void 0 : _a.select) !== "document" || !((_b = field.config) == null ? void 0 : _b.customtypes)) {
|
344
|
+
return field;
|
345
|
+
}
|
346
|
+
const newCustomTypes = field.config.customtypes.map((customType) => {
|
347
|
+
return updateCRCustomType({ customType, ...updateMeta });
|
348
|
+
});
|
349
|
+
return {
|
350
|
+
...field,
|
351
|
+
config: { ...field.config, customtypes: newCustomTypes }
|
352
|
+
};
|
353
|
+
}
|
354
|
+
function updateCustomTypeContentRelationships(args) {
|
355
|
+
const { models, previousPath, newPath, onUpdate } = args;
|
356
|
+
for (const { model: customType } of models) {
|
357
|
+
const updatedCustomTypeModel = customtypes.traverseCustomType({
|
358
|
+
customType,
|
359
|
+
onField: ({ field }) => {
|
360
|
+
return updateFieldContentRelationships({
|
361
|
+
field,
|
362
|
+
previousPath,
|
363
|
+
newPath
|
364
|
+
});
|
365
|
+
}
|
366
|
+
});
|
367
|
+
if (!isEqualModel(customType, updatedCustomTypeModel)) {
|
368
|
+
onUpdate(updatedCustomTypeModel);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
}
|
372
|
+
function updateSharedSliceContentRelationships(args) {
|
373
|
+
const { models, previousPath, newPath, onUpdate } = args;
|
374
|
+
for (const { model: slice } of models) {
|
375
|
+
const updatedSliceModel = customtypes.traverseSharedSlice({
|
376
|
+
path: ["."],
|
377
|
+
slice,
|
378
|
+
onField: ({ field }) => {
|
379
|
+
return updateFieldContentRelationships({
|
380
|
+
field,
|
381
|
+
previousPath,
|
382
|
+
newPath
|
383
|
+
});
|
384
|
+
}
|
385
|
+
});
|
386
|
+
if (!isEqualModel(slice, updatedSliceModel)) {
|
387
|
+
onUpdate(updatedSliceModel);
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}
|
391
|
+
function isEqualModel(modelA, modelB) {
|
392
|
+
return JSON.stringify(modelA) === JSON.stringify(modelB);
|
393
|
+
}
|
394
|
+
function shallowCloneIfObject(value) {
|
395
|
+
if (typeof value === "object") {
|
396
|
+
return { ...value };
|
397
|
+
}
|
398
|
+
return value;
|
399
|
+
}
|
400
|
+
function pushIfDefined(array, value) {
|
401
|
+
if (value) {
|
402
|
+
array.push(value);
|
403
|
+
}
|
404
|
+
}
|
234
405
|
exports.CustomTypesManager = CustomTypesManager;
|
406
|
+
exports.updateCustomTypeContentRelationships = updateCustomTypeContentRelationships;
|
407
|
+
exports.updateSharedSliceContentRelationships = updateSharedSliceContentRelationships;
|
235
408
|
//# sourceMappingURL=CustomTypesManager.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomTypesManager.cjs","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/CD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,QAAAC,QAAA,IAAW,MAAM,KAAK,sBAAqB;AACxD,QAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAGA,OAAM;AAEtC,QAAI,KAAK;AACR,iBAAW,MAAM,KAAK;AACf,cAAA,EAAE,OAAO,QAAAA,aAAW,MAAM,KAAK,eAAe,EAAE,GAAA,CAAI;AAC1D,YAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAGA,QAAM;AAEtC,YAAI,UAAU,CAAC,QAAQ,KAAK,WAAW,MAAM,S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I,YAAY;AAAA,MAC5C,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,UAAU;AAAA,IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqBG,cAAE,OAAO;AAAA,EACnC,OAAOA,MAAE,QAAA,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAASC,YAAAA,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAMD,MAAAA,QAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAOA,MAAAA,QAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAcA,MAAAA,QAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;;"}
|
1
|
+
{"version":3,"file":"CustomTypesManager.cjs","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tGroup,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeFieldIdChangedMeta = NonNullable<\n\tNonNullable<CustomTypeUpdateHookData[\"updateMeta\"]>[\"fieldIdChanged\"]\n>;\n\ntype CrCustomType =\n\t| string\n\t| { id: string; fields?: readonly CrCustomTypeNestedCr[] };\ntype CrCustomTypeNestedCr =\n\t| string\n\t| { id: string; customtypes: readonly CrCustomTypeFieldLeaf[] };\ntype CrCustomTypeFieldLeaf =\n\t| string\n\t| { id: string; fields?: readonly string[] };\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\t/**\n\t * Update the Content Relationship API IDs for all existing custom types and\n\t * slices. The change is determined by properties inside the `updateMeta`\n\t * property.\n\t */\n\tprivate async updateContentRelationships(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, updateMeta } = args;\n\n\t\tif (updateMeta?.fieldIdChanged) {\n\t\t\tlet { previousPath, newPath } = updateMeta.fieldIdChanged;\n\n\t\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\t\tconst crUpdates: Promise<{ errors: HookError[] }>[] = [];\n\n\t\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t\t// any custom type and update them to use the new one.\n\t\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\t\tupdateCustomTypeContentRelationships({\n\t\t\t\t\tmodels: customTypes.models,\n\t\t\t\t\tonUpdate: (model) => {\n\t\t\t\t\t\tpushIfDefined(\n\t\t\t\t\t\t\tcrUpdates,\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\n\t\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\t\tfor (const library of libraries) {\n\t\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tupdateSharedSliceContentRelationships({\n\t\t\t\t\t\tmodels: slices.models,\n\t\t\t\t\t\tonUpdate: (model) => {\n\t\t\t\t\t\t\tpushIfDefined(\n\t\t\t\t\t\t\t\tcrUpdates,\n\t\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpreviousPath,\n\t\t\t\t\t\tnewPath,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Process all the Content Relationship updates at once.\n\t\t\t\tconst crUpdatesResult = await Promise.all(crUpdates);\n\n\t\t\t\tif (crUpdatesResult.some((result) => result.errors.length > 0)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terrors: crUpdatesResult.flatMap((result) => result.errors),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\tif (args.updateMeta?.fieldIdChanged) {\n\t\t\tawait this.updateContentRelationships(args);\n\t\t}\n\n\t\treturn { errors: hookResult.errors };\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n\nfunction updateCRCustomType(\n\targs: { customType: CrCustomType } & CustomTypeFieldIdChangedMeta,\n): CrCustomType {\n\tconst [previousCustomTypeId, previousFieldId] = args.previousPath;\n\tconst [newCustomTypeId, newFieldId] = args.newPath;\n\n\tif (!previousCustomTypeId || !newCustomTypeId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a customtype id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tif (!previousFieldId || !newFieldId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a field id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tconst customType = shallowCloneIfObject(args.customType);\n\n\tif (typeof customType === \"string\" || !customType.fields) {\n\t\treturn customType;\n\t}\n\n\tconst matchedCustomTypeId = customType.id === previousCustomTypeId;\n\n\tconst newFields = customType.fields.map((fieldArg) => {\n\t\tconst customTypeField = shallowCloneIfObject(fieldArg);\n\n\t\tif (typeof customTypeField === \"string\") {\n\t\t\tif (\n\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\tcustomTypeField === previousFieldId &&\n\t\t\t\tcustomTypeField !== newFieldId\n\t\t\t) {\n\t\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t\t// so we update it new one. The field is a string, so return the new\n\t\t\t\t// id.\n\t\t\t\treturn newFieldId;\n\t\t\t}\n\n\t\t\treturn customTypeField;\n\t\t}\n\n\t\tif (\n\t\t\tmatchedCustomTypeId &&\n\t\t\tcustomTypeField.id === previousFieldId &&\n\t\t\tcustomTypeField.id !== newFieldId\n\t\t) {\n\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t// so we update it new one.\n\t\t\t// Since field is not a string, we don't exit, as we might have\n\t\t\t// something to update further down in customtypes.\n\t\t\tcustomTypeField.id = newFieldId;\n\t\t}\n\n\t\treturn {\n\t\t\t...customTypeField,\n\t\t\tcustomtypes: customTypeField.customtypes.map((customTypeArg) => {\n\t\t\t\tconst nestedCustomType = shallowCloneIfObject(customTypeArg);\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof nestedCustomType === \"string\" ||\n\t\t\t\t\t!nestedCustomType.fields ||\n\t\t\t\t\t// Since we are on the last level, if we don't start matching right\n\t\t\t\t\t// at the custom type id, we can return exit early because it's not\n\t\t\t\t\t// a match.\n\t\t\t\t\tnestedCustomType.id !== previousCustomTypeId\n\t\t\t\t) {\n\t\t\t\t\treturn nestedCustomType;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...nestedCustomType,\n\t\t\t\t\tfields: nestedCustomType.fields.map((fieldArg) => {\n\t\t\t\t\t\tconst nestedCustomTypeField = shallowCloneIfObject(fieldArg);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnestedCustomTypeField === previousFieldId &&\n\t\t\t\t\t\t\tnestedCustomTypeField !== newFieldId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Matches the previous id, so we update it and return because\n\t\t\t\t\t\t\t// it's the last level.\n\t\t\t\t\t\t\treturn newFieldId;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nestedCustomTypeField;\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\n\treturn { ...customType, fields: newFields };\n}\n\n/**\n * Update the Content Relationship API IDs of a single field. The change is\n * determined by the `previousPath` and `newPath` properties.\n */\nfunction updateFieldContentRelationships<\n\tT extends UID | NestableWidget | Group | NestedGroup,\n>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\tconst { field, ...updateMeta } = args;\n\tif (\n\t\tfield.type !== \"Link\" ||\n\t\tfield.config?.select !== \"document\" ||\n\t\t!field.config?.customtypes\n\t) {\n\t\t// not a content relationship field\n\t\treturn field;\n\t}\n\n\tconst newCustomTypes = field.config.customtypes.map((customType) => {\n\t\treturn updateCRCustomType({ customType, ...updateMeta });\n\t});\n\n\treturn {\n\t\t...field,\n\t\tconfig: { ...field.config, customtypes: newCustomTypes },\n\t};\n}\n\nexport function updateCustomTypeContentRelationships(\n\targs: {\n\t\tmodels: { model: CustomType }[];\n\t\tonUpdate: (model: CustomType) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: customType } of models) {\n\t\tconst updatedCustomTypeModel = traverseCustomType({\n\t\t\tcustomType,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(customType, updatedCustomTypeModel)) {\n\t\t\tonUpdate(updatedCustomTypeModel);\n\t\t}\n\t}\n}\n\nexport function updateSharedSliceContentRelationships(\n\targs: {\n\t\tmodels: { model: SharedSlice }[];\n\t\tonUpdate: (model: SharedSlice) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: slice } of models) {\n\t\tconst updatedSliceModel = traverseSharedSlice({\n\t\t\tpath: [\".\"],\n\t\t\tslice,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(slice, updatedSliceModel)) {\n\t\t\tonUpdate(updatedSliceModel);\n\t\t}\n\t}\n}\n\nfunction isEqualModel<T extends CustomType | SharedSlice>(\n\tmodelA: T,\n\tmodelB: T,\n): boolean {\n\treturn JSON.stringify(modelA) === JSON.stringify(modelB);\n}\n\nfunction shallowCloneIfObject<T>(value: T): T {\n\tif (typeof value === \"object\") {\n\t\treturn { ...value };\n\t}\n\n\treturn value;\n}\n\nfunction pushIfDefined<T>(array: T[], value: T | undefined) {\n\tif (value) {\n\t\tarray.push(value);\n\t}\n}\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","model","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice","fieldArg","traverseCustomType","traverseSharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF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gCAAgC;AAAA,UACtC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,OAAO,iBAAiB,GAAG;AAC5C,eAAS,iBAAiB;AAAA,IAC3B;AAAA,EACD;AACD;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,MAAM;AACxD;AAEA,SAAS,qBAAwB,OAAQ;AACpC,MAAA,OAAO,UAAU,UAAU;AACvB,WAAA,EAAE,GAAG;EACb;AAEO,SAAA;AACR;AAEA,SAAS,cAAiB,OAAY,OAAoB;AACzD,MAAI,OAAO;AACV,UAAM,KAAK,KAAK;AAAA,EACjB;AACD;;;;"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
1
|
+
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
2
2
|
import { CallHookReturnType, CustomTypeCreateHook, CustomTypeCreateHookData, CustomTypeReadHookData, CustomTypeRenameHook, CustomTypeRenameHookData, CustomTypeUpdateHook, CustomTypeUpdateHookData, HookError } from "@slicemachine/plugin-kit";
|
3
3
|
import { z } from "zod";
|
4
4
|
import { DecodeError } from "../../lib/DecodeError";
|
@@ -46,11 +46,18 @@ type CustomTypesMachineManagerDeleteCustomTypeArgs = {
|
|
46
46
|
type CustomTypesMachineManagerDeleteCustomTypeReturnType = {
|
47
47
|
errors: (DecodeError | HookError)[];
|
48
48
|
};
|
49
|
+
type CustomTypeFieldIdChangedMeta = NonNullable<NonNullable<CustomTypeUpdateHookData["updateMeta"]>["fieldIdChanged"]>;
|
49
50
|
export declare class CustomTypesManager extends BaseManager {
|
50
51
|
readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType>;
|
51
52
|
readAllCustomTypes(args?: CustomTypesManagerReadAllCustomTypesArgs): Promise<SliceMachineManagerReadAllCustomTypeReturnType>;
|
52
53
|
createCustomType(args: CustomTypeCreateHookData): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>>;
|
53
54
|
readCustomType(args: CustomTypeReadHookData): Promise<SliceMachineManagerReadCustomTypeReturnType>;
|
55
|
+
/**
|
56
|
+
* Update the Content Relationship API IDs for all existing custom types and
|
57
|
+
* slices. The change is determined by properties inside the `updateMeta`
|
58
|
+
* property.
|
59
|
+
*/
|
60
|
+
private updateContentRelationships;
|
54
61
|
updateCustomType(args: CustomTypeUpdateHookData): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>>;
|
55
62
|
renameCustomType(args: CustomTypeRenameHookData): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>>;
|
56
63
|
deleteCustomType(args: CustomTypesMachineManagerDeleteCustomTypeArgs): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType>;
|
@@ -208,7 +215,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
208
215
|
useAsTitle?: boolean | undefined;
|
209
216
|
placeholder?: string | undefined;
|
210
217
|
select?: "media" | "document" | "web" | null | undefined;
|
211
|
-
customtypes?: readonly string
|
218
|
+
customtypes?: readonly (string | ({
|
219
|
+
id: string;
|
220
|
+
} & {
|
221
|
+
fields?: readonly (string | {
|
222
|
+
id: string;
|
223
|
+
customtypes: readonly (string | ({
|
224
|
+
id: string;
|
225
|
+
} & {
|
226
|
+
fields?: readonly string[] | undefined;
|
227
|
+
}))[];
|
228
|
+
})[] | undefined;
|
229
|
+
}))[] | undefined;
|
212
230
|
masks?: readonly string[] | undefined;
|
213
231
|
tags?: readonly string[] | undefined;
|
214
232
|
allowTargetBlank?: boolean | undefined;
|
@@ -383,7 +401,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
383
401
|
useAsTitle?: boolean | undefined;
|
384
402
|
placeholder?: string | undefined;
|
385
403
|
select?: "media" | "document" | "web" | null | undefined;
|
386
|
-
customtypes?: readonly string
|
404
|
+
customtypes?: readonly (string | ({
|
405
|
+
id: string;
|
406
|
+
} & {
|
407
|
+
fields?: readonly (string | {
|
408
|
+
id: string;
|
409
|
+
customtypes: readonly (string | ({
|
410
|
+
id: string;
|
411
|
+
} & {
|
412
|
+
fields?: readonly string[] | undefined;
|
413
|
+
}))[];
|
414
|
+
})[] | undefined;
|
415
|
+
}))[] | undefined;
|
387
416
|
masks?: readonly string[] | undefined;
|
388
417
|
tags?: readonly string[] | undefined;
|
389
418
|
allowTargetBlank?: boolean | undefined;
|
@@ -558,7 +587,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
558
587
|
useAsTitle?: boolean | undefined;
|
559
588
|
placeholder?: string | undefined;
|
560
589
|
select?: "media" | "document" | "web" | null | undefined;
|
561
|
-
customtypes?: readonly string
|
590
|
+
customtypes?: readonly (string | ({
|
591
|
+
id: string;
|
592
|
+
} & {
|
593
|
+
fields?: readonly (string | {
|
594
|
+
id: string;
|
595
|
+
customtypes: readonly (string | ({
|
596
|
+
id: string;
|
597
|
+
} & {
|
598
|
+
fields?: readonly string[] | undefined;
|
599
|
+
}))[];
|
600
|
+
})[] | undefined;
|
601
|
+
}))[] | undefined;
|
562
602
|
masks?: readonly string[] | undefined;
|
563
603
|
tags?: readonly string[] | undefined;
|
564
604
|
allowTargetBlank?: boolean | undefined;
|
@@ -732,7 +772,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
732
772
|
useAsTitle?: boolean | undefined;
|
733
773
|
placeholder?: string | undefined;
|
734
774
|
select?: "media" | "document" | "web" | null | undefined;
|
735
|
-
customtypes?: readonly string
|
775
|
+
customtypes?: readonly (string | ({
|
776
|
+
id: string;
|
777
|
+
} & {
|
778
|
+
fields?: readonly (string | {
|
779
|
+
id: string;
|
780
|
+
customtypes: readonly (string | ({
|
781
|
+
id: string;
|
782
|
+
} & {
|
783
|
+
fields?: readonly string[] | undefined;
|
784
|
+
}))[];
|
785
|
+
})[] | undefined;
|
786
|
+
}))[] | undefined;
|
736
787
|
masks?: readonly string[] | undefined;
|
737
788
|
tags?: readonly string[] | undefined;
|
738
789
|
allowTargetBlank?: boolean | undefined;
|
@@ -922,7 +973,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
922
973
|
useAsTitle?: boolean | undefined;
|
923
974
|
placeholder?: string | undefined;
|
924
975
|
select?: "media" | "document" | "web" | null | undefined;
|
925
|
-
customtypes?: readonly string
|
976
|
+
customtypes?: readonly (string | ({
|
977
|
+
id: string;
|
978
|
+
} & {
|
979
|
+
fields?: readonly (string | {
|
980
|
+
id: string;
|
981
|
+
customtypes: readonly (string | ({
|
982
|
+
id: string;
|
983
|
+
} & {
|
984
|
+
fields?: readonly string[] | undefined;
|
985
|
+
}))[];
|
986
|
+
})[] | undefined;
|
987
|
+
}))[] | undefined;
|
926
988
|
masks?: readonly string[] | undefined;
|
927
989
|
tags?: readonly string[] | undefined;
|
928
990
|
allowTargetBlank?: boolean | undefined;
|
@@ -1097,7 +1159,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
1097
1159
|
useAsTitle?: boolean | undefined;
|
1098
1160
|
placeholder?: string | undefined;
|
1099
1161
|
select?: "media" | "document" | "web" | null | undefined;
|
1100
|
-
customtypes?: readonly string
|
1162
|
+
customtypes?: readonly (string | ({
|
1163
|
+
id: string;
|
1164
|
+
} & {
|
1165
|
+
fields?: readonly (string | {
|
1166
|
+
id: string;
|
1167
|
+
customtypes: readonly (string | ({
|
1168
|
+
id: string;
|
1169
|
+
} & {
|
1170
|
+
fields?: readonly string[] | undefined;
|
1171
|
+
}))[];
|
1172
|
+
})[] | undefined;
|
1173
|
+
}))[] | undefined;
|
1101
1174
|
masks?: readonly string[] | undefined;
|
1102
1175
|
tags?: readonly string[] | undefined;
|
1103
1176
|
allowTargetBlank?: boolean | undefined;
|
@@ -1272,7 +1345,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
1272
1345
|
useAsTitle?: boolean | undefined;
|
1273
1346
|
placeholder?: string | undefined;
|
1274
1347
|
select?: "media" | "document" | "web" | null | undefined;
|
1275
|
-
customtypes?: readonly string
|
1348
|
+
customtypes?: readonly (string | ({
|
1349
|
+
id: string;
|
1350
|
+
} & {
|
1351
|
+
fields?: readonly (string | {
|
1352
|
+
id: string;
|
1353
|
+
customtypes: readonly (string | ({
|
1354
|
+
id: string;
|
1355
|
+
} & {
|
1356
|
+
fields?: readonly string[] | undefined;
|
1357
|
+
}))[];
|
1358
|
+
})[] | undefined;
|
1359
|
+
}))[] | undefined;
|
1276
1360
|
masks?: readonly string[] | undefined;
|
1277
1361
|
tags?: readonly string[] | undefined;
|
1278
1362
|
allowTargetBlank?: boolean | undefined;
|
@@ -1446,7 +1530,18 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
1446
1530
|
useAsTitle?: boolean | undefined;
|
1447
1531
|
placeholder?: string | undefined;
|
1448
1532
|
select?: "media" | "document" | "web" | null | undefined;
|
1449
|
-
customtypes?: readonly string
|
1533
|
+
customtypes?: readonly (string | ({
|
1534
|
+
id: string;
|
1535
|
+
} & {
|
1536
|
+
fields?: readonly (string | {
|
1537
|
+
id: string;
|
1538
|
+
customtypes: readonly (string | ({
|
1539
|
+
id: string;
|
1540
|
+
} & {
|
1541
|
+
fields?: readonly string[] | undefined;
|
1542
|
+
}))[];
|
1543
|
+
})[] | undefined;
|
1544
|
+
}))[] | undefined;
|
1450
1545
|
masks?: readonly string[] | undefined;
|
1451
1546
|
tags?: readonly string[] | undefined;
|
1452
1547
|
allowTargetBlank?: boolean | undefined;
|
@@ -1495,4 +1590,16 @@ declare const InferSliceResponse: z.ZodObject<{
|
|
1495
1590
|
slice?: unknown;
|
1496
1591
|
langSmithUrl?: string | undefined;
|
1497
1592
|
}>;
|
1593
|
+
export declare function updateCustomTypeContentRelationships(args: {
|
1594
|
+
models: {
|
1595
|
+
model: CustomType;
|
1596
|
+
}[];
|
1597
|
+
onUpdate: (model: CustomType) => void;
|
1598
|
+
} & CustomTypeFieldIdChangedMeta): void;
|
1599
|
+
export declare function updateSharedSliceContentRelationships(args: {
|
1600
|
+
models: {
|
1601
|
+
model: SharedSlice;
|
1602
|
+
}[];
|
1603
|
+
onUpdate: (model: SharedSlice) => void;
|
1604
|
+
} & CustomTypeFieldIdChangedMeta): void;
|
1498
1605
|
export {};
|