@prismicio/plugin-kit 0.0.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/lower-case/dist.es2015/index.js +7 -0
- package/dist/_node_modules/lower-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/no-case/dist.es2015/index.js +28 -0
- package/dist/_node_modules/no-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js +68 -0
- package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js.map +1 -0
- package/dist/_node_modules/p-limit/index.js +77 -0
- package/dist/_node_modules/p-limit/index.js.map +1 -0
- package/dist/_node_modules/pascal-case/dist.es2015/index.js +25 -0
- package/dist/_node_modules/pascal-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/tslib/tslib.es6.js +14 -0
- package/dist/_node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/createPluginHookSystem.d.ts +6 -0
- package/dist/createPluginHookSystem.js +8 -0
- package/dist/createPluginHookSystem.js.map +1 -0
- package/dist/createPluginSystemActions.d.ts +46 -0
- package/dist/createPluginSystemActions.js +96 -0
- package/dist/createPluginSystemActions.js.map +1 -0
- package/dist/createPluginSystemContext.d.ts +31 -0
- package/dist/createPluginSystemContext.js +12 -0
- package/dist/createPluginSystemContext.js.map +1 -0
- package/dist/createPluginSystemHelpers.d.ts +37 -0
- package/dist/createPluginSystemHelpers.js +72 -0
- package/dist/createPluginSystemHelpers.js.map +1 -0
- package/dist/createPluginSystemRunner.d.ts +58 -0
- package/dist/createPluginSystemRunner.js +128 -0
- package/dist/createPluginSystemRunner.js.map +1 -0
- package/dist/definePlugin.d.ts +30 -0
- package/dist/definePlugin.js +5 -0
- package/dist/definePlugin.js.map +1 -0
- package/dist/fs/buildCustomTypeDirectoryPath.d.ts +5 -0
- package/dist/fs/buildCustomTypeDirectoryPath.js +9 -0
- package/dist/fs/buildCustomTypeDirectoryPath.js.map +1 -0
- package/dist/fs/buildCustomTypeFilePath.d.ts +5 -0
- package/dist/fs/buildCustomTypeFilePath.js +9 -0
- package/dist/fs/buildCustomTypeFilePath.js.map +1 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.d.ts +6 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.js +8 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.js.map +1 -0
- package/dist/fs/buildSliceDirectoryPath.d.ts +4 -0
- package/dist/fs/buildSliceDirectoryPath.js +12 -0
- package/dist/fs/buildSliceDirectoryPath.js.map +1 -0
- package/dist/fs/buildSliceFilePath.d.ts +5 -0
- package/dist/fs/buildSliceFilePath.js +9 -0
- package/dist/fs/buildSliceFilePath.js.map +1 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.d.ts +7 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.js +8 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.js.map +1 -0
- package/dist/fs/checkHasProjectFile.d.ts +6 -0
- package/dist/fs/checkHasProjectFile.js +9 -0
- package/dist/fs/checkHasProjectFile.js.map +1 -0
- package/dist/fs/checkIsTypeScriptProject.d.ts +4 -0
- package/dist/fs/checkIsTypeScriptProject.js +12 -0
- package/dist/fs/checkIsTypeScriptProject.js.map +1 -0
- package/dist/fs/constants.d.ts +9 -0
- package/dist/fs/constants.js +15 -0
- package/dist/fs/constants.js.map +1 -0
- package/dist/fs/deleteCustomTypeDirectory.d.ts +3 -0
- package/dist/fs/deleteCustomTypeDirectory.js +18 -0
- package/dist/fs/deleteCustomTypeDirectory.js.map +1 -0
- package/dist/fs/deleteProjectFile.d.ts +6 -0
- package/dist/fs/deleteProjectFile.js +10 -0
- package/dist/fs/deleteProjectFile.js.map +1 -0
- package/dist/fs/deleteSliceDirectory.d.ts +3 -0
- package/dist/fs/deleteSliceDirectory.js +18 -0
- package/dist/fs/deleteSliceDirectory.js.map +1 -0
- package/dist/fs/deleteSliceFile.d.ts +3 -0
- package/dist/fs/deleteSliceFile.js +18 -0
- package/dist/fs/deleteSliceFile.js.map +1 -0
- package/dist/fs/index.d.ts +49 -0
- package/dist/fs/index.js +53 -0
- package/dist/fs/index.js.map +1 -0
- package/dist/fs/lib/checkPathExists.d.ts +2 -0
- package/dist/fs/lib/checkPathExists.js +13 -0
- package/dist/fs/lib/checkPathExists.js.map +1 -0
- package/dist/fs/lib/fsLimit.d.ts +31 -0
- package/dist/fs/lib/fsLimit.js +23 -0
- package/dist/fs/lib/fsLimit.js.map +1 -0
- package/dist/fs/lib/isCustomTypeModel.d.ts +2 -0
- package/dist/fs/lib/isCustomTypeModel.js +7 -0
- package/dist/fs/lib/isCustomTypeModel.js.map +1 -0
- package/dist/fs/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/fs/lib/isSharedSliceModel.js +7 -0
- package/dist/fs/lib/isSharedSliceModel.js.map +1 -0
- package/dist/fs/lib/pascalCase.d.ts +8 -0
- package/dist/fs/lib/pascalCase.js +10 -0
- package/dist/fs/lib/pascalCase.js.map +1 -0
- package/dist/fs/lib/readJSONFile.d.ts +1 -0
- package/dist/fs/lib/readJSONFile.js +9 -0
- package/dist/fs/lib/readJSONFile.js.map +1 -0
- package/dist/fs/lib/resolveSliceModel.d.ts +10 -0
- package/dist/fs/lib/resolveSliceModel.js +14 -0
- package/dist/fs/lib/resolveSliceModel.js.map +1 -0
- package/dist/fs/readCustomTypeFile.d.ts +8 -0
- package/dist/fs/readCustomTypeFile.js +14 -0
- package/dist/fs/readCustomTypeFile.js.map +1 -0
- package/dist/fs/readCustomTypeLibrary.d.ts +6 -0
- package/dist/fs/readCustomTypeLibrary.js +53 -0
- package/dist/fs/readCustomTypeLibrary.js.map +1 -0
- package/dist/fs/readCustomTypeModel.d.ts +7 -0
- package/dist/fs/readCustomTypeModel.js +16 -0
- package/dist/fs/readCustomTypeModel.js.map +1 -0
- package/dist/fs/readProjectFile.d.ts +12 -0
- package/dist/fs/readProjectFile.js +9 -0
- package/dist/fs/readProjectFile.js.map +1 -0
- package/dist/fs/readSliceFile.d.ts +8 -0
- package/dist/fs/readSliceFile.js +17 -0
- package/dist/fs/readSliceFile.js.map +1 -0
- package/dist/fs/readSliceLibrary.d.ts +7 -0
- package/dist/fs/readSliceLibrary.js +56 -0
- package/dist/fs/readSliceLibrary.js.map +1 -0
- package/dist/fs/readSliceModel.d.ts +11 -0
- package/dist/fs/readSliceModel.js +46 -0
- package/dist/fs/readSliceModel.js.map +1 -0
- package/dist/fs/renameCustomType.d.ts +3 -0
- package/dist/fs/renameCustomType.js +8 -0
- package/dist/fs/renameCustomType.js.map +1 -0
- package/dist/fs/renameSlice.d.ts +7 -0
- package/dist/fs/renameSlice.js +22 -0
- package/dist/fs/renameSlice.js.map +1 -0
- package/dist/fs/types.d.ts +3 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.d.ts +16 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.js +37 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.js.map +1 -0
- package/dist/fs/writeCustomTypeFile.d.ts +9 -0
- package/dist/fs/writeCustomTypeFile.js +18 -0
- package/dist/fs/writeCustomTypeFile.js.map +1 -0
- package/dist/fs/writeCustomTypeModel.d.ts +12 -0
- package/dist/fs/writeCustomTypeModel.js +14 -0
- package/dist/fs/writeCustomTypeModel.js.map +1 -0
- package/dist/fs/writeProjectFile.d.ts +15 -0
- package/dist/fs/writeProjectFile.js +16 -0
- package/dist/fs/writeProjectFile.js.map +1 -0
- package/dist/fs/writeSliceFile.d.ts +9 -0
- package/dist/fs/writeSliceFile.js +18 -0
- package/dist/fs/writeSliceFile.js.map +1 -0
- package/dist/fs/writeSliceModel.d.ts +11 -0
- package/dist/fs/writeSliceModel.js +13 -0
- package/dist/fs/writeSliceModel.js.map +1 -0
- package/dist/hooks/customType-create.d.ts +28 -0
- package/dist/hooks/customType-delete.d.ts +26 -0
- package/dist/hooks/customType-read.d.ts +32 -0
- package/dist/hooks/customType-rename.d.ts +29 -0
- package/dist/hooks/customType-update.d.ts +29 -0
- package/dist/hooks/customTypeLibrary-read.d.ts +25 -0
- package/dist/hooks/debug.d.ts +22 -0
- package/dist/hooks/project-init.d.ts +35 -0
- package/dist/hooks/slice-create.d.ts +30 -0
- package/dist/hooks/slice-delete.d.ts +26 -0
- package/dist/hooks/slice-read.d.ts +32 -0
- package/dist/hooks/slice-rename.d.ts +26 -0
- package/dist/hooks/slice-update.d.ts +29 -0
- package/dist/hooks/sliceLibrary-read.d.ts +27 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/DecodeError.d.ts +13 -0
- package/dist/lib/DecodeError.js +21 -0
- package/dist/lib/DecodeError.js.map +1 -0
- package/dist/lib/HookSystem.d.ts +93 -0
- package/dist/lib/HookSystem.js +121 -0
- package/dist/lib/HookSystem.js.map +1 -0
- package/dist/lib/decode.d.ts +10 -0
- package/dist/lib/decode.js +16 -0
- package/dist/lib/decode.js.map +1 -0
- package/dist/lib/decodePrismicConfig.d.ts +3 -0
- package/dist/lib/decodePrismicConfig.js +22 -0
- package/dist/lib/decodePrismicConfig.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +90 -0
- package/src/createPluginHookSystem.ts +9 -0
- package/src/createPluginSystemActions.ts +188 -0
- package/src/createPluginSystemContext.ts +51 -0
- package/src/createPluginSystemHelpers.ts +129 -0
- package/src/createPluginSystemRunner.ts +216 -0
- package/src/definePlugin.ts +48 -0
- package/src/fs/buildCustomTypeDirectoryPath.ts +19 -0
- package/src/fs/buildCustomTypeFilePath.ts +16 -0
- package/src/fs/buildCustomTypeLibraryDirectoryPath.ts +16 -0
- package/src/fs/buildSliceDirectoryPath.ts +25 -0
- package/src/fs/buildSliceFilePath.ts +16 -0
- package/src/fs/buildSliceLibraryDirectoryPath.ts +17 -0
- package/src/fs/checkHasProjectFile.ts +16 -0
- package/src/fs/checkIsTypeScriptProject.ts +16 -0
- package/src/fs/constants.ts +15 -0
- package/src/fs/deleteCustomTypeDirectory.ts +24 -0
- package/src/fs/deleteProjectFile.ts +18 -0
- package/src/fs/deleteSliceDirectory.ts +24 -0
- package/src/fs/deleteSliceFile.ts +24 -0
- package/src/fs/index.ts +103 -0
- package/src/fs/lib/checkPathExists.ts +13 -0
- package/src/fs/lib/fsLimit.ts +72 -0
- package/src/fs/lib/isCustomTypeModel.ts +7 -0
- package/src/fs/lib/isSharedSliceModel.ts +14 -0
- package/src/fs/lib/pascalCase.ts +17 -0
- package/src/fs/lib/readJSONFile.ts +7 -0
- package/src/fs/lib/resolveSliceModel.ts +28 -0
- package/src/fs/readCustomTypeFile.ts +27 -0
- package/src/fs/readCustomTypeLibrary.ts +86 -0
- package/src/fs/readCustomTypeModel.ts +27 -0
- package/src/fs/readProjectFile.ts +24 -0
- package/src/fs/readSliceFile.ts +27 -0
- package/src/fs/readSliceLibrary.ts +91 -0
- package/src/fs/readSliceModel.ts +90 -0
- package/src/fs/renameCustomType.ts +12 -0
- package/src/fs/renameSlice.ts +35 -0
- package/src/fs/types.ts +5 -0
- package/src/fs/upsertGlobalTypeScriptTypes.ts +64 -0
- package/src/fs/writeCustomTypeFile.ts +30 -0
- package/src/fs/writeCustomTypeModel.ts +31 -0
- package/src/fs/writeProjectFile.ts +39 -0
- package/src/fs/writeSliceFile.ts +30 -0
- package/src/fs/writeSliceModel.ts +26 -0
- package/src/hooks/customType-create.ts +42 -0
- package/src/hooks/customType-delete.ts +40 -0
- package/src/hooks/customType-read.ts +46 -0
- package/src/hooks/customType-rename.ts +43 -0
- package/src/hooks/customType-update.ts +43 -0
- package/src/hooks/customTypeLibrary-read.ts +38 -0
- package/src/hooks/debug.ts +31 -0
- package/src/hooks/project-init.ts +48 -0
- package/src/hooks/slice-create.ts +44 -0
- package/src/hooks/slice-delete.ts +40 -0
- package/src/hooks/slice-read.ts +44 -0
- package/src/hooks/slice-rename.ts +40 -0
- package/src/hooks/slice-update.ts +43 -0
- package/src/hooks/sliceLibrary-read.ts +41 -0
- package/src/index.ts +141 -0
- package/src/lib/DecodeError.ts +31 -0
- package/src/lib/HookSystem.ts +277 -0
- package/src/lib/decode.ts +30 -0
- package/src/lib/decodePrismicConfig.ts +26 -0
- package/src/types.ts +175 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/lower-case/dist.es2015/index.js"],"sourcesContent":["/**\n * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt\n */\nvar SUPPORTED_LOCALE = {\n tr: {\n regexp: /\\u0130|\\u0049|\\u0049\\u0307/g,\n map: {\n İ: \"\\u0069\",\n I: \"\\u0131\",\n İ: \"\\u0069\",\n },\n },\n az: {\n regexp: /\\u0130/g,\n map: {\n İ: \"\\u0069\",\n I: \"\\u0131\",\n İ: \"\\u0069\",\n },\n },\n lt: {\n regexp: /\\u0049|\\u004A|\\u012E|\\u00CC|\\u00CD|\\u0128/g,\n map: {\n I: \"\\u0069\\u0307\",\n J: \"\\u006A\\u0307\",\n Į: \"\\u012F\\u0307\",\n Ì: \"\\u0069\\u0307\\u0300\",\n Í: \"\\u0069\\u0307\\u0301\",\n Ĩ: \"\\u0069\\u0307\\u0303\",\n },\n },\n};\n/**\n * Localized lower case.\n */\nexport function localeLowerCase(str, locale) {\n var lang = SUPPORTED_LOCALE[locale.toLowerCase()];\n if (lang)\n return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));\n return lowerCase(str);\n}\n/**\n * Lower case as a function.\n */\nexport function lowerCase(str) {\n return str.toLowerCase();\n}\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":"AA4CO,SAAS,UAAU,KAAK;AAC3B,SAAO,IAAI,YAAW;AAC1B;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { lowerCase } from "../../lower-case/dist.es2015/index.js";
|
|
2
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
3
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
4
|
+
function noCase(input, options) {
|
|
5
|
+
if (options === void 0) {
|
|
6
|
+
options = {};
|
|
7
|
+
}
|
|
8
|
+
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
9
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
10
|
+
var start = 0;
|
|
11
|
+
var end = result.length;
|
|
12
|
+
while (result.charAt(start) === "\0")
|
|
13
|
+
start++;
|
|
14
|
+
while (result.charAt(end - 1) === "\0")
|
|
15
|
+
end--;
|
|
16
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
17
|
+
}
|
|
18
|
+
function replace(input, re, value) {
|
|
19
|
+
if (re instanceof RegExp)
|
|
20
|
+
return input.replace(re, value);
|
|
21
|
+
return re.reduce(function(input2, re2) {
|
|
22
|
+
return input2.replace(re2, value);
|
|
23
|
+
}, input);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
noCase
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/no-case/dist.es2015/index.js"],"sourcesContent":["import { lowerCase } from \"lower-case\";\n// Support camel case (\"camelCase\" -> \"camel Case\" and \"CAMELCase\" -> \"CAMEL Case\").\nvar DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];\n// Remove all non-word characters.\nvar DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;\n/**\n * Normalize the string into something other libraries can manipulate easier.\n */\nexport function noCase(input, options) {\n if (options === void 0) { options = {}; }\n var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? \" \" : _d;\n var result = replace(replace(input, splitRegexp, \"$1\\0$2\"), stripRegexp, \"\\0\");\n var start = 0;\n var end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n // Transform each token independently.\n return result.slice(start, end).split(\"\\0\").map(transform).join(delimiter);\n}\n/**\n * Replace `re` in the input string with the replacement value.\n */\nfunction replace(input, re, value) {\n if (re instanceof RegExp)\n return input.replace(re, value);\n return re.reduce(function (input, re) { return input.replace(re, value); }, input);\n}\n//# sourceMappingURL=index.js.map"],"names":["input","re"],"mappings":";AAEA,IAAI,uBAAuB,CAAC,sBAAsB,sBAAsB;AAExE,IAAI,uBAAuB;AAIpB,SAAS,OAAO,OAAO,SAAS;AACnC,MAAI,YAAY,QAAQ;AAAE,cAAU,CAAA;AAAA,EAAI;AACxC,MAAI,KAAK,QAAQ,aAAa,cAAc,OAAO,SAAS,uBAAuB,IAAI,KAAK,QAAQ,aAAa,cAAc,OAAO,SAAS,uBAAuB,IAAI,KAAK,QAAQ,WAAW,YAAY,OAAO,SAAS,YAAY,IAAI,KAAK,QAAQ,WAAW,YAAY,OAAO,SAAS,MAAM;AACxS,MAAI,SAAS,QAAQ,QAAQ,OAAO,aAAa,QAAQ,GAAG,aAAa,IAAI;AAC7E,MAAI,QAAQ;AACZ,MAAI,MAAM,OAAO;AAEjB,SAAO,OAAO,OAAO,KAAK,MAAM;AAC5B;AACJ,SAAO,OAAO,OAAO,MAAM,CAAC,MAAM;AAC9B;AAEJ,SAAO,OAAO,MAAM,OAAO,GAAG,EAAE,MAAM,IAAI,EAAE,IAAI,SAAS,EAAE,KAAK,SAAS;AAC7E;AAIA,SAAS,QAAQ,OAAO,IAAI,OAAO;AAC/B,MAAI,cAAc;AACd,WAAO,MAAM,QAAQ,IAAI,KAAK;AAClC,SAAO,GAAG,OAAO,SAAUA,QAAOC,KAAI;AAAE,WAAOD,OAAM,QAAQC,KAAI,KAAK;AAAA,EAAG,GAAG,KAAK;AACrF;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
class Node {
|
|
2
|
+
value;
|
|
3
|
+
next;
|
|
4
|
+
constructor(value) {
|
|
5
|
+
this.value = value;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
class Queue {
|
|
9
|
+
#head;
|
|
10
|
+
#tail;
|
|
11
|
+
#size;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.clear();
|
|
14
|
+
}
|
|
15
|
+
enqueue(value) {
|
|
16
|
+
const node = new Node(value);
|
|
17
|
+
if (this.#head) {
|
|
18
|
+
this.#tail.next = node;
|
|
19
|
+
this.#tail = node;
|
|
20
|
+
} else {
|
|
21
|
+
this.#head = node;
|
|
22
|
+
this.#tail = node;
|
|
23
|
+
}
|
|
24
|
+
this.#size++;
|
|
25
|
+
}
|
|
26
|
+
dequeue() {
|
|
27
|
+
const current = this.#head;
|
|
28
|
+
if (!current) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.#head = this.#head.next;
|
|
32
|
+
this.#size--;
|
|
33
|
+
if (!this.#head) {
|
|
34
|
+
this.#tail = void 0;
|
|
35
|
+
}
|
|
36
|
+
return current.value;
|
|
37
|
+
}
|
|
38
|
+
peek() {
|
|
39
|
+
if (!this.#head) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return this.#head.value;
|
|
43
|
+
}
|
|
44
|
+
clear() {
|
|
45
|
+
this.#head = void 0;
|
|
46
|
+
this.#tail = void 0;
|
|
47
|
+
this.#size = 0;
|
|
48
|
+
}
|
|
49
|
+
get size() {
|
|
50
|
+
return this.#size;
|
|
51
|
+
}
|
|
52
|
+
*[Symbol.iterator]() {
|
|
53
|
+
let current = this.#head;
|
|
54
|
+
while (current) {
|
|
55
|
+
yield current.value;
|
|
56
|
+
current = current.next;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
*drain() {
|
|
60
|
+
while (this.#head) {
|
|
61
|
+
yield this.dequeue();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
Queue as default
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../../node_modules/p-limit/node_modules/yocto-queue/index.js"],"sourcesContent":["/*\nHow it works:\n`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.\n*/\n\nclass Node {\n\tvalue;\n\tnext;\n\n\tconstructor(value) {\n\t\tthis.value = value;\n\t}\n}\n\nexport default class Queue {\n\t#head;\n\t#tail;\n\t#size;\n\n\tconstructor() {\n\t\tthis.clear();\n\t}\n\n\tenqueue(value) {\n\t\tconst node = new Node(value);\n\n\t\tif (this.#head) {\n\t\t\tthis.#tail.next = node;\n\t\t\tthis.#tail = node;\n\t\t} else {\n\t\t\tthis.#head = node;\n\t\t\tthis.#tail = node;\n\t\t}\n\n\t\tthis.#size++;\n\t}\n\n\tdequeue() {\n\t\tconst current = this.#head;\n\t\tif (!current) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#head = this.#head.next;\n\t\tthis.#size--;\n\n\t\t// Clean up tail reference when queue becomes empty\n\t\tif (!this.#head) {\n\t\t\tthis.#tail = undefined;\n\t\t}\n\n\t\treturn current.value;\n\t}\n\n\tpeek() {\n\t\tif (!this.#head) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#head.value;\n\n\t\t// TODO: Node.js 18.\n\t\t// return this.#head?.value;\n\t}\n\n\tclear() {\n\t\tthis.#head = undefined;\n\t\tthis.#tail = undefined;\n\t\tthis.#size = 0;\n\t}\n\n\tget size() {\n\t\treturn this.#size;\n\t}\n\n\t* [Symbol.iterator]() {\n\t\tlet current = this.#head;\n\n\t\twhile (current) {\n\t\t\tyield current.value;\n\t\t\tcurrent = current.next;\n\t\t}\n\t}\n\n\t* drain() {\n\t\twhile (this.#head) {\n\t\t\tyield this.dequeue();\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAKA,MAAM,KAAK;AAAA,EACV;AAAA,EACA;AAAA,EAEA,YAAY,OAAO;AAClB,SAAK,QAAQ;AAAA,EACd;AACD;AAEe,MAAM,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AACb,SAAK,MAAK;AAAA,EACX;AAAA,EAEA,QAAQ,OAAO;AACd,UAAM,OAAO,IAAI,KAAK,KAAK;AAE3B,QAAI,KAAK,OAAO;AACf,WAAK,MAAM,OAAO;AAClB,WAAK,QAAQ;AAAA,IACd,OAAO;AACN,WAAK,QAAQ;AACb,WAAK,QAAQ;AAAA,IACd;AAEA,SAAK;AAAA,EACN;AAAA,EAEA,UAAU;AACT,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,SAAS;AACb;AAAA,IACD;AAEA,SAAK,QAAQ,KAAK,MAAM;AACxB,SAAK;AAGL,QAAI,CAAC,KAAK,OAAO;AAChB,WAAK,QAAQ;AAAA,IACd;AAEA,WAAO,QAAQ;AAAA,EAChB;AAAA,EAEA,OAAO;AACN,QAAI,CAAC,KAAK,OAAO;AAChB;AAAA,IACD;AAEA,WAAO,KAAK,MAAM;AAAA,EAInB;AAAA,EAEA,QAAQ;AACP,SAAK,QAAQ;AACb,SAAK,QAAQ;AACb,SAAK,QAAQ;AAAA,EACd;AAAA,EAEA,IAAI,OAAO;AACV,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,EAAG,OAAO,QAAQ,IAAI;AACrB,QAAI,UAAU,KAAK;AAEnB,WAAO,SAAS;AACf,YAAM,QAAQ;AACd,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD;AAAA,EAEA,CAAE,QAAQ;AACT,WAAO,KAAK,OAAO;AAClB,YAAM,KAAK,QAAO;AAAA,IACnB;AAAA,EACD;AACD;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Queue from './_node_modules/yocto-queue/index.js';
|
|
2
|
+
function pLimit(concurrency) {
|
|
3
|
+
validateConcurrency(concurrency);
|
|
4
|
+
const queue = new Queue();
|
|
5
|
+
let activeCount = 0;
|
|
6
|
+
const resumeNext = () => {
|
|
7
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
8
|
+
activeCount++;
|
|
9
|
+
queue.dequeue()();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const next = () => {
|
|
13
|
+
activeCount--;
|
|
14
|
+
resumeNext();
|
|
15
|
+
};
|
|
16
|
+
const run = async (function_, resolve, arguments_) => {
|
|
17
|
+
const result = (async () => function_(...arguments_))();
|
|
18
|
+
resolve(result);
|
|
19
|
+
try {
|
|
20
|
+
await result;
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
next();
|
|
24
|
+
};
|
|
25
|
+
const enqueue = (function_, resolve, arguments_) => {
|
|
26
|
+
new Promise((internalResolve) => {
|
|
27
|
+
queue.enqueue(internalResolve);
|
|
28
|
+
}).then(run.bind(void 0, function_, resolve, arguments_));
|
|
29
|
+
if (activeCount < concurrency) {
|
|
30
|
+
resumeNext();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const generator = (function_, ...arguments_) => new Promise((resolve) => {
|
|
34
|
+
enqueue(function_, resolve, arguments_);
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperties(generator, {
|
|
37
|
+
activeCount: {
|
|
38
|
+
get: () => activeCount
|
|
39
|
+
},
|
|
40
|
+
pendingCount: {
|
|
41
|
+
get: () => queue.size
|
|
42
|
+
},
|
|
43
|
+
clearQueue: {
|
|
44
|
+
value() {
|
|
45
|
+
queue.clear();
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
concurrency: {
|
|
49
|
+
get: () => concurrency,
|
|
50
|
+
set(newConcurrency) {
|
|
51
|
+
validateConcurrency(newConcurrency);
|
|
52
|
+
concurrency = newConcurrency;
|
|
53
|
+
queueMicrotask(() => {
|
|
54
|
+
while (activeCount < concurrency && queue.size > 0) {
|
|
55
|
+
resumeNext();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
map: {
|
|
61
|
+
async value(iterable, function_) {
|
|
62
|
+
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
63
|
+
return Promise.all(promises);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return generator;
|
|
68
|
+
}
|
|
69
|
+
function validateConcurrency(concurrency) {
|
|
70
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
71
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
pLimit as default
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../node_modules/p-limit/index.js"],"sourcesContent":["import Queue from 'yocto-queue';\n\nexport default function pLimit(concurrency) {\n\tvalidateConcurrency(concurrency);\n\n\tconst queue = new Queue();\n\tlet activeCount = 0;\n\n\tconst resumeNext = () => {\n\t\t// Process the next queued function if we're under the concurrency limit\n\t\tif (activeCount < concurrency && queue.size > 0) {\n\t\t\tactiveCount++;\n\t\t\tqueue.dequeue()();\n\t\t}\n\t};\n\n\tconst next = () => {\n\t\tactiveCount--;\n\t\tresumeNext();\n\t};\n\n\tconst run = async (function_, resolve, arguments_) => {\n\t\t// Execute the function and capture the result promise\n\t\tconst result = (async () => function_(...arguments_))();\n\n\t\t// Resolve immediately with the promise (don't wait for completion)\n\t\tresolve(result);\n\n\t\t// Wait for the function to complete (success or failure)\n\t\t// We catch errors here to prevent unhandled rejections,\n\t\t// but the original promise rejection is preserved for the caller\n\t\ttry {\n\t\t\tawait result;\n\t\t} catch {}\n\n\t\t// Decrement active count and process next queued function\n\t\tnext();\n\t};\n\n\tconst enqueue = (function_, resolve, arguments_) => {\n\t\t// Queue the internal resolve function instead of the run function\n\t\t// to preserve the asynchronous execution context.\n\t\tnew Promise(internalResolve => { // eslint-disable-line promise/param-names\n\t\t\tqueue.enqueue(internalResolve);\n\t\t}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then\n\n\t\t// Start processing immediately if we haven't reached the concurrency limit\n\t\tif (activeCount < concurrency) {\n\t\t\tresumeNext();\n\t\t}\n\t};\n\n\tconst generator = (function_, ...arguments_) => new Promise(resolve => {\n\t\tenqueue(function_, resolve, arguments_);\n\t});\n\n\tObject.defineProperties(generator, {\n\t\tactiveCount: {\n\t\t\tget: () => activeCount,\n\t\t},\n\t\tpendingCount: {\n\t\t\tget: () => queue.size,\n\t\t},\n\t\tclearQueue: {\n\t\t\tvalue() {\n\t\t\t\tqueue.clear();\n\t\t\t},\n\t\t},\n\t\tconcurrency: {\n\t\t\tget: () => concurrency,\n\n\t\t\tset(newConcurrency) {\n\t\t\t\tvalidateConcurrency(newConcurrency);\n\t\t\t\tconcurrency = newConcurrency;\n\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t// eslint-disable-next-line no-unmodified-loop-condition\n\t\t\t\t\twhile (activeCount < concurrency && queue.size > 0) {\n\t\t\t\t\t\tresumeNext();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tmap: {\n\t\t\tasync value(iterable, function_) {\n\t\t\t\tconst promises = Array.from(iterable, (value, index) => this(function_, value, index));\n\t\t\t\treturn Promise.all(promises);\n\t\t\t},\n\t\t},\n\t});\n\n\treturn generator;\n}\n\nexport function limitFunction(function_, options) {\n\tconst {concurrency} = options;\n\tconst limit = pLimit(concurrency);\n\n\treturn (...arguments_) => limit(() => function_(...arguments_));\n}\n\nfunction validateConcurrency(concurrency) {\n\tif (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {\n\t\tthrow new TypeError('Expected `concurrency` to be a number from 1 and up');\n\t}\n}\n"],"names":[],"mappings":";AAEe,SAAS,OAAO,aAAa;AAC3C,sBAAoB,WAAW;AAE/B,QAAM,QAAQ,IAAI,MAAK;AACvB,MAAI,cAAc;AAElB,QAAM,aAAa,MAAM;AAExB,QAAI,cAAc,eAAe,MAAM,OAAO,GAAG;AAChD;AACA,YAAM,QAAO,EAAE;AAAA,IAChB;AAAA,EACD;AAEA,QAAM,OAAO,MAAM;AAClB;AACA,eAAU;AAAA,EACX;AAEA,QAAM,MAAM,OAAO,WAAW,SAAS,eAAe;AAErD,UAAM,UAAU,YAAY,UAAU,GAAG,UAAU,GAAC;AAGpD,YAAQ,MAAM;AAKd,QAAI;AACH,YAAM;AAAA,IACP,QAAQ;AAAA,IAAC;AAGT,SAAI;AAAA,EACL;AAEA,QAAM,UAAU,CAAC,WAAW,SAAS,eAAe;AAGnD,QAAI,QAAQ,qBAAmB;AAC9B,YAAM,QAAQ,eAAe;AAAA,IAC9B,CAAC,EAAE,KAAK,IAAI,KAAK,QAAW,WAAW,SAAS,UAAU,CAAC;AAG3D,QAAI,cAAc,aAAa;AAC9B,iBAAU;AAAA,IACX;AAAA,EACD;AAEA,QAAM,YAAY,CAAC,cAAc,eAAe,IAAI,QAAQ,aAAW;AACtE,YAAQ,WAAW,SAAS,UAAU;AAAA,EACvC,CAAC;AAED,SAAO,iBAAiB,WAAW;AAAA,IAClC,aAAa;AAAA,MACZ,KAAK,MAAM;AAAA,IACd;AAAA,IACE,cAAc;AAAA,MACb,KAAK,MAAM,MAAM;AAAA,IACpB;AAAA,IACE,YAAY;AAAA,MACX,QAAQ;AACP,cAAM,MAAK;AAAA,MACZ;AAAA,IACH;AAAA,IACE,aAAa;AAAA,MACZ,KAAK,MAAM;AAAA,MAEX,IAAI,gBAAgB;AACnB,4BAAoB,cAAc;AAClC,sBAAc;AAEd,uBAAe,MAAM;AAEpB,iBAAO,cAAc,eAAe,MAAM,OAAO,GAAG;AACnD,uBAAU;AAAA,UACX;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACH;AAAA,IACE,KAAK;AAAA,MACJ,MAAM,MAAM,UAAU,WAAW;AAChC,cAAM,WAAW,MAAM,KAAK,UAAU,CAAC,OAAO,UAAU,KAAK,WAAW,OAAO,KAAK,CAAC;AACrF,eAAO,QAAQ,IAAI,QAAQ;AAAA,MAC5B;AAAA,IACH;AAAA,EACA,CAAE;AAED,SAAO;AACR;AASA,SAAS,oBAAoB,aAAa;AACzC,MAAI,GAAG,OAAO,UAAU,WAAW,KAAK,gBAAgB,OAAO,sBAAsB,cAAc,IAAI;AACtG,UAAM,IAAI,UAAU,qDAAqD;AAAA,EAC1E;AACD;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { __assign } from "../../tslib/tslib.es6.js";
|
|
2
|
+
import { noCase } from "../../no-case/dist.es2015/index.js";
|
|
3
|
+
function pascalCaseTransform(input, index) {
|
|
4
|
+
var firstChar = input.charAt(0);
|
|
5
|
+
var lowerChars = input.substr(1).toLowerCase();
|
|
6
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
7
|
+
return "_" + firstChar + lowerChars;
|
|
8
|
+
}
|
|
9
|
+
return "" + firstChar.toUpperCase() + lowerChars;
|
|
10
|
+
}
|
|
11
|
+
function pascalCaseTransformMerge(input) {
|
|
12
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
function pascalCase(input, options) {
|
|
15
|
+
if (options === void 0) {
|
|
16
|
+
options = {};
|
|
17
|
+
}
|
|
18
|
+
return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
pascalCase,
|
|
22
|
+
pascalCaseTransform,
|
|
23
|
+
pascalCaseTransformMerge
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/pascal-case/dist.es2015/index.js"],"sourcesContent":["import { __assign } from \"tslib\";\nimport { noCase } from \"no-case\";\nexport function pascalCaseTransform(input, index) {\n var firstChar = input.charAt(0);\n var lowerChars = input.substr(1).toLowerCase();\n if (index > 0 && firstChar >= \"0\" && firstChar <= \"9\") {\n return \"_\" + firstChar + lowerChars;\n }\n return \"\" + firstChar.toUpperCase() + lowerChars;\n}\nexport function pascalCaseTransformMerge(input) {\n return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();\n}\nexport function pascalCase(input, options) {\n if (options === void 0) { options = {}; }\n return noCase(input, __assign({ delimiter: \"\", transform: pascalCaseTransform }, options));\n}\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;AAEO,SAAS,oBAAoB,OAAO,OAAO;AAC9C,MAAI,YAAY,MAAM,OAAO,CAAC;AAC9B,MAAI,aAAa,MAAM,OAAO,CAAC,EAAE,YAAW;AAC5C,MAAI,QAAQ,KAAK,aAAa,OAAO,aAAa,KAAK;AACnD,WAAO,MAAM,YAAY;AAAA,EAC7B;AACA,SAAO,KAAK,UAAU,YAAW,IAAK;AAC1C;AACO,SAAS,yBAAyB,OAAO;AAC5C,SAAO,MAAM,OAAO,CAAC,EAAE,gBAAgB,MAAM,MAAM,CAAC,EAAE,YAAW;AACrE;AACO,SAAS,WAAW,OAAO,SAAS;AACvC,MAAI,YAAY,QAAQ;AAAE,cAAU,CAAA;AAAA,EAAI;AACxC,SAAO,OAAO,OAAO,SAAS,EAAE,WAAW,IAAI,WAAW,uBAAuB,OAAO,CAAC;AAC7F;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __assign = function() {
|
|
2
|
+
__assign = Object.assign || function __assign2(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
+
}
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
return __assign.apply(this, arguments);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
__assign
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=tslib.es6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tslib.es6.js","sources":["../../../../../node_modules/tslib/tslib.es6.mjs"],"sourcesContent":["/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n};\n"],"names":["__assign"],"mappings":"AA+BU,IAAC,WAAW,WAAW;AAC/B,aAAW,OAAO,UAAU,SAASA,UAAS,GAAG;AAC7C,aAAS,GAAG,IAAI,GAAG,IAAI,UAAU,QAAQ,IAAI,GAAG,KAAK;AACjD,UAAI,UAAU,CAAC;AACf,eAAS,KAAK,EAAG,KAAI,OAAO,UAAU,eAAe,KAAK,GAAG,CAAC,EAAG,GAAE,CAAC,IAAI,EAAE,CAAC;AAAA,IAC/E;AACA,WAAO;AAAA,EACX;AACA,SAAO,SAAS,MAAM,MAAM,SAAS;AACvC;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPluginHookSystem.js","sources":["../../src/createPluginHookSystem.ts"],"sourcesContent":["import { HookSystem } from \"./lib/HookSystem\";\nimport type { PluginHooks } from \"./types\";\n\n/**\n * @internal\n */\nexport const createPluginHookSystem = (): HookSystem<PluginHooks> => {\n\treturn new HookSystem<PluginHooks>();\n};\n"],"names":[],"mappings":";AAMO,MAAM,yBAAyB,MAA8B;AACnE,SAAO,IAAI,WAAA;AACZ;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CustomTypeReadHookData, CustomTypeReadHookReturnType } from "./hooks/customType-read.js";
|
|
2
|
+
import { CustomTypeLibraryReadHookReturnType } from "./hooks/customTypeLibrary-read.js";
|
|
3
|
+
import { SliceReadHookData, SliceReadHookReturnType } from "./hooks/slice-read.js";
|
|
4
|
+
import { SliceLibraryReadHookData, SliceLibraryReadHookReturnType } from "./hooks/sliceLibrary-read.js";
|
|
5
|
+
import { HookSystem } from "./lib/HookSystem.js";
|
|
6
|
+
import { PluginHooks, PrismicProject } from "./types.js";
|
|
7
|
+
export type ReadAllSliceModelsActionArgs<TWithMetadata extends boolean = false> = {
|
|
8
|
+
withMetadata?: TWithMetadata;
|
|
9
|
+
};
|
|
10
|
+
export type ReadAllSliceModelsActionReturnType = (SliceReadHookReturnType & {
|
|
11
|
+
libraryID: string;
|
|
12
|
+
})[];
|
|
13
|
+
export type ReadAllSliceModelsForLibraryActionArgs = {
|
|
14
|
+
libraryID: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates Plugin System actions.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare const createPluginSystemActions: (project: PrismicProject, hookSystem: HookSystem<PluginHooks>) => PluginSystemActions;
|
|
22
|
+
/**
|
|
23
|
+
* Plugin System actions shared to plugins and hooks.
|
|
24
|
+
*/
|
|
25
|
+
export declare class PluginSystemActions {
|
|
26
|
+
/**
|
|
27
|
+
* The Prismic project's metadata.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
private _project;
|
|
32
|
+
/**
|
|
33
|
+
* The actions' hook system used to internally trigger hook calls.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
private _hookSystem;
|
|
38
|
+
constructor(project: PrismicProject, hookSystem: HookSystem<PluginHooks>);
|
|
39
|
+
readAllSliceModels: () => Promise<ReadAllSliceModelsActionReturnType>;
|
|
40
|
+
readAllSliceModelsForLibrary: (args: ReadAllSliceModelsForLibraryActionArgs) => Promise<SliceReadHookReturnType[]>;
|
|
41
|
+
readSliceModel: (args: SliceReadHookData) => Promise<SliceReadHookReturnType>;
|
|
42
|
+
readSliceLibrary: (args: SliceLibraryReadHookData) => Promise<SliceLibraryReadHookReturnType>;
|
|
43
|
+
readAllCustomTypeModels: () => Promise<CustomTypeReadHookReturnType[]>;
|
|
44
|
+
readCustomTypeModel: (args: CustomTypeReadHookData) => Promise<CustomTypeReadHookReturnType>;
|
|
45
|
+
readCustomTypeLibrary: () => Promise<CustomTypeLibraryReadHookReturnType>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const createPluginSystemActions = (project, hookSystem) => {
|
|
2
|
+
return new PluginSystemActions(project, hookSystem);
|
|
3
|
+
};
|
|
4
|
+
class PluginSystemActions {
|
|
5
|
+
/**
|
|
6
|
+
* The Prismic project's metadata.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
_project;
|
|
11
|
+
/**
|
|
12
|
+
* The actions' hook system used to internally trigger hook calls.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
_hookSystem;
|
|
17
|
+
constructor(project, hookSystem) {
|
|
18
|
+
this._project = project;
|
|
19
|
+
this._hookSystem = hookSystem;
|
|
20
|
+
}
|
|
21
|
+
readAllSliceModels = async () => {
|
|
22
|
+
const libraryIDs = this._project.config.libraries || [];
|
|
23
|
+
return (await Promise.all(libraryIDs.map(async (libraryID) => {
|
|
24
|
+
const models = await this.readAllSliceModelsForLibrary({
|
|
25
|
+
libraryID
|
|
26
|
+
});
|
|
27
|
+
return models.map((model) => {
|
|
28
|
+
return {
|
|
29
|
+
libraryID,
|
|
30
|
+
...model
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}))).flat();
|
|
34
|
+
};
|
|
35
|
+
readAllSliceModelsForLibrary = async (args) => {
|
|
36
|
+
const { sliceIDs } = await this.readSliceLibrary({
|
|
37
|
+
libraryID: args.libraryID
|
|
38
|
+
});
|
|
39
|
+
return await Promise.all(sliceIDs.map(async (sliceID) => {
|
|
40
|
+
return await this.readSliceModel({
|
|
41
|
+
libraryID: args.libraryID,
|
|
42
|
+
sliceID
|
|
43
|
+
});
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
readSliceModel = async (args) => {
|
|
47
|
+
const { data: [model], errors: [cause] } = await this._hookSystem.callHook("slice:read", {
|
|
48
|
+
libraryID: args.libraryID,
|
|
49
|
+
sliceID: args.sliceID
|
|
50
|
+
});
|
|
51
|
+
if (!model) {
|
|
52
|
+
throw new Error(`Slice \`${args.sliceID}\` not found in the \`${args.libraryID}\` library.`, { cause });
|
|
53
|
+
}
|
|
54
|
+
return model;
|
|
55
|
+
};
|
|
56
|
+
readSliceLibrary = async (args) => {
|
|
57
|
+
const { data: [library], errors: [cause] } = await this._hookSystem.callHook("slice-library:read", {
|
|
58
|
+
libraryID: args.libraryID
|
|
59
|
+
});
|
|
60
|
+
if (!library) {
|
|
61
|
+
throw new Error(`Slice library \`${args.libraryID}\` not found.`, {
|
|
62
|
+
cause
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return library;
|
|
66
|
+
};
|
|
67
|
+
readAllCustomTypeModels = async () => {
|
|
68
|
+
const { ids } = await this.readCustomTypeLibrary();
|
|
69
|
+
return await Promise.all(ids.map(async (id) => {
|
|
70
|
+
return this.readCustomTypeModel({ id });
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
readCustomTypeModel = async (args) => {
|
|
74
|
+
const { data: [model], errors: [cause] } = await this._hookSystem.callHook("custom-type:read", {
|
|
75
|
+
id: args.id
|
|
76
|
+
});
|
|
77
|
+
if (!model) {
|
|
78
|
+
throw new Error(`Custom type \`${args.id}\` not found.`, { cause });
|
|
79
|
+
}
|
|
80
|
+
return model;
|
|
81
|
+
};
|
|
82
|
+
readCustomTypeLibrary = async () => {
|
|
83
|
+
const { data: [library], errors: [cause] } = await this._hookSystem.callHook("custom-type-library:read", void 0);
|
|
84
|
+
if (!library) {
|
|
85
|
+
throw new Error(`Couldn't read custom type library.`, {
|
|
86
|
+
cause
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return library;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
PluginSystemActions,
|
|
94
|
+
createPluginSystemActions
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=createPluginSystemActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPluginSystemActions.js","sources":["../../src/createPluginSystemActions.ts"],"sourcesContent":["import {\n\tCustomTypeReadHookData,\n\tCustomTypeReadHookReturnType,\n} from \"./hooks/customType-read\";\nimport { CustomTypeLibraryReadHookReturnType } from \"./hooks/customTypeLibrary-read\";\nimport { SliceReadHookData, SliceReadHookReturnType } from \"./hooks/slice-read\";\nimport {\n\tSliceLibraryReadHookData,\n\tSliceLibraryReadHookReturnType,\n} from \"./hooks/sliceLibrary-read\";\nimport { HookSystem } from \"./lib/HookSystem\";\nimport { PluginHooks, PrismicProject } from \"./types\";\n\nexport type ReadAllSliceModelsActionArgs<\n\tTWithMetadata extends boolean = false,\n> = {\n\twithMetadata?: TWithMetadata;\n};\n\nexport type ReadAllSliceModelsActionReturnType = (SliceReadHookReturnType & {\n\tlibraryID: string;\n})[];\n\nexport type ReadAllSliceModelsForLibraryActionArgs = {\n\tlibraryID: string;\n};\n\n/**\n * Creates Plugin System actions.\n *\n * @internal\n */\nexport const createPluginSystemActions = (\n\tproject: PrismicProject,\n\thookSystem: HookSystem<PluginHooks>,\n): PluginSystemActions => {\n\treturn new PluginSystemActions(project, hookSystem);\n};\n\n/**\n * Plugin System actions shared to plugins and hooks.\n */\nexport class PluginSystemActions {\n\t/**\n\t * The Prismic project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: PrismicProject;\n\t/**\n\t * The actions' hook system used to internally trigger hook calls.\n\t *\n\t * @internal\n\t */\n\tprivate _hookSystem: HookSystem<PluginHooks>;\n\n\tconstructor(project: PrismicProject, hookSystem: HookSystem<PluginHooks>) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t}\n\n\treadAllSliceModels =\n\t\tasync (): Promise<ReadAllSliceModelsActionReturnType> => {\n\t\t\tconst libraryIDs = this._project.config.libraries || [];\n\n\t\t\treturn (\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tlibraryIDs.map(async (libraryID) => {\n\t\t\t\t\t\tconst models = await this.readAllSliceModelsForLibrary({\n\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn models.map((model) => {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t...model,\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)\n\t\t\t).flat();\n\t\t};\n\n\treadAllSliceModelsForLibrary = async (\n\t\targs: ReadAllSliceModelsForLibraryActionArgs,\n\t): Promise<SliceReadHookReturnType[]> => {\n\t\tconst { sliceIDs } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\treturn await Promise.all(\n\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\treturn await this.readSliceModel({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\t};\n\n\treadSliceModel = async (\n\t\targs: SliceReadHookData,\n\t): Promise<SliceReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(\n\t\t\t\t`Slice \\`${args.sliceID}\\` not found in the \\`${args.libraryID}\\` library.`,\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadSliceLibrary = async (\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SliceLibraryReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [library],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice-library:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\tif (!library) {\n\t\t\tthrow new Error(`Slice library \\`${args.libraryID}\\` not found.`, {\n\t\t\t\tcause,\n\t\t\t});\n\t\t}\n\n\t\treturn library;\n\t};\n\n\treadAllCustomTypeModels = async (): Promise<\n\t\tCustomTypeReadHookReturnType[]\n\t> => {\n\t\tconst { ids } = await this.readCustomTypeLibrary();\n\n\t\treturn await Promise.all(\n\t\t\tids.map(async (id) => {\n\t\t\t\treturn this.readCustomTypeModel({ id });\n\t\t\t}),\n\t\t);\n\t};\n\n\treadCustomTypeModel = async (\n\t\targs: CustomTypeReadHookData,\n\t): Promise<CustomTypeReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"custom-type:read\", {\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(`Custom type \\`${args.id}\\` not found.`, { cause });\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadCustomTypeLibrary =\n\t\tasync (): Promise<CustomTypeLibraryReadHookReturnType> => {\n\t\t\tconst {\n\t\t\t\tdata: [library],\n\t\t\t\terrors: [cause],\n\t\t\t} = await this._hookSystem.callHook(\n\t\t\t\t\"custom-type-library:read\",\n\t\t\t\tundefined,\n\t\t\t);\n\n\t\t\tif (!library) {\n\t\t\t\tthrow new Error(`Couldn't read custom type library.`, {\n\t\t\t\t\tcause,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn library;\n\t\t};\n}\n"],"names":[],"mappings":"AAgCO,MAAM,4BAA4B,CACxC,SACA,eACwB;AACxB,SAAO,IAAI,oBAAoB,SAAS,UAAU;AACnD;MAKa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA,EAER,YAAY,SAAyB,YAAmC;AACvE,SAAK,WAAW;AAChB,SAAK,cAAc;AAAA,EACpB;AAAA,EAEA,qBACC,YAAwD;AACvD,UAAM,aAAa,KAAK,SAAS,OAAO,aAAa,CAAA;AAErD,YACC,MAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,SAAS,MAAM,KAAK,6BAA6B;AAAA,QACtD;AAAA,MAAA,CACA;AAED,aAAO,OAAO,IAAI,CAAC,UAAS;AAC3B,eAAO;AAAA,UACN;AAAA,UACA,GAAG;AAAA,QAAA;AAAA,MAEL,CAAC;AAAA,IACF,CAAC,CAAC,GAEF,KAAA;AAAA,EACH;AAAA,EAED,+BAA+B,OAC9B,SACuC;AACvC,UAAM,EAAE,SAAA,IAAa,MAAM,KAAK,iBAAiB;AAAA,MAChD,WAAW,KAAK;AAAA,IAAA,CAChB;AAED,WAAO,MAAM,QAAQ,IACpB,SAAS,IAAI,OAAO,YAAW;AAC9B,aAAO,MAAM,KAAK,eAAe;AAAA,QAChC,WAAW,KAAK;AAAA,QAChB;AAAA,MAAA,CACA;AAAA,IACF,CAAC,CAAC;AAAA,EAEJ;AAAA,EAEA,iBAAiB,OAChB,SACqC;AACrC,UAAM,EACL,MAAM,CAAC,KAAK,GACZ,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,cAAc;AAAA,MACjD,WAAW,KAAK;AAAA,MAChB,SAAS,KAAK;AAAA,IAAA,CACd;AAED,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MACT,WAAW,KAAK,OAAO,yBAAyB,KAAK,SAAS,eAC9D,EAAE,MAAA,CAAO;AAAA,IAEX;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,mBAAmB,OAClB,SAC4C;AAC5C,UAAM,EACL,MAAM,CAAC,OAAO,GACd,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,sBAAsB;AAAA,MACzD,WAAW,KAAK;AAAA,IAAA,CAChB;AAED,QAAI,CAAC,SAAS;AACb,YAAM,IAAI,MAAM,mBAAmB,KAAK,SAAS,iBAAiB;AAAA,QACjE;AAAA,MAAA,CACA;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,0BAA0B,YAEtB;AACH,UAAM,EAAE,IAAA,IAAQ,MAAM,KAAK,sBAAA;AAE3B,WAAO,MAAM,QAAQ,IACpB,IAAI,IAAI,OAAO,OAAM;AACpB,aAAO,KAAK,oBAAoB,EAAE,IAAI;AAAA,IACvC,CAAC,CAAC;AAAA,EAEJ;AAAA,EAEA,sBAAsB,OACrB,SAC0C;AAC1C,UAAM,EACL,MAAM,CAAC,KAAK,GACZ,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,oBAAoB;AAAA,MACvD,IAAI,KAAK;AAAA,IAAA,CACT;AAED,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE,iBAAiB,EAAE,OAAO;AAAA,IACnE;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,wBACC,YAAyD;AACxD,UAAM,EACL,MAAM,CAAC,OAAO,GACd,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAC1B,4BACA,MAAS;AAGV,QAAI,CAAC,SAAS;AACb,YAAM,IAAI,MAAM,sCAAsC;AAAA,QACrD;AAAA,MAAA,CACA;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PluginSystemActions } from "./createPluginSystemActions.js";
|
|
2
|
+
import { PluginSystemHelpers } from "./createPluginSystemHelpers.js";
|
|
3
|
+
import { LoadedPlugin } from "./definePlugin.js";
|
|
4
|
+
import { PrismicProject } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Plugin context shared to plugins and hooks.
|
|
7
|
+
*/
|
|
8
|
+
export type PluginSystemContext<TPluginOptions extends Record<string, unknown>> = {
|
|
9
|
+
actions: PluginSystemActions;
|
|
10
|
+
helpers: PluginSystemHelpers;
|
|
11
|
+
project: PrismicProject;
|
|
12
|
+
options: TPluginOptions;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Arguments for `createPluginSystemContext()`.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam TPluginOptions - Options for the plugin's context.
|
|
18
|
+
*/
|
|
19
|
+
type CreatePluginSystemContextArgs<TPluginOptions extends Record<string, unknown>> = {
|
|
20
|
+
actions: PluginSystemActions;
|
|
21
|
+
helpers: PluginSystemHelpers;
|
|
22
|
+
project: PrismicProject;
|
|
23
|
+
plugin: LoadedPlugin<TPluginOptions>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates Plugin context.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare const createPluginSystemContext: <TPluginOptions extends Record<string, unknown>>({ actions, helpers, project, plugin, }: CreatePluginSystemContextArgs<TPluginOptions>) => PluginSystemContext<TPluginOptions>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const createPluginSystemContext = ({ actions, helpers, project, plugin }) => {
|
|
2
|
+
return {
|
|
3
|
+
actions,
|
|
4
|
+
helpers,
|
|
5
|
+
project,
|
|
6
|
+
options: plugin.options
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
createPluginSystemContext
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=createPluginSystemContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPluginSystemContext.js","sources":["../../src/createPluginSystemContext.ts"],"sourcesContent":["import { PluginSystemActions } from \"./createPluginSystemActions\";\nimport { PluginSystemHelpers } from \"./createPluginSystemHelpers\";\nimport { LoadedPlugin } from \"./definePlugin\";\nimport { PrismicProject } from \"./types\";\n\n/**\n * Plugin context shared to plugins and hooks.\n */\nexport type PluginSystemContext<\n\tTPluginOptions extends Record<string, unknown>,\n> = {\n\tactions: PluginSystemActions;\n\thelpers: PluginSystemHelpers;\n\tproject: PrismicProject;\n\toptions: TPluginOptions;\n};\n\n/**\n * Arguments for `createPluginSystemContext()`.\n *\n * @typeParam TPluginOptions - Options for the plugin's context.\n */\ntype CreatePluginSystemContextArgs<\n\tTPluginOptions extends Record<string, unknown>,\n> = {\n\tactions: PluginSystemActions;\n\thelpers: PluginSystemHelpers;\n\tproject: PrismicProject;\n\tplugin: LoadedPlugin<TPluginOptions>;\n};\n\n/**\n * Creates Plugin context.\n *\n * @internal\n */\nexport const createPluginSystemContext = <\n\tTPluginOptions extends Record<string, unknown>,\n>({\n\tactions,\n\thelpers,\n\tproject,\n\tplugin,\n}: CreatePluginSystemContextArgs<TPluginOptions>): PluginSystemContext<TPluginOptions> => {\n\treturn {\n\t\tactions,\n\t\thelpers,\n\t\tproject,\n\t\toptions: plugin.options,\n\t};\n};\n"],"names":[],"mappings":"AAoCO,MAAM,4BAA4B,CAEvC,EACD,SACA,SACA,SACA,aACwF;AACxF,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,OAAO;AAAA,EAAA;AAElB;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as prettier from "prettier";
|
|
2
|
+
import { PrismicConfig, PrismicProject } from "./types.js";
|
|
3
|
+
type UpdatePrismicConfigOptions = {
|
|
4
|
+
format?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type FormatOptions = {
|
|
7
|
+
prettier?: prettier.Options;
|
|
8
|
+
/**
|
|
9
|
+
* Determines if a newline is included at the end of the formatted result.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `true`
|
|
12
|
+
*/
|
|
13
|
+
includeNewlineAtEnd?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates Plugin System helpers.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare const createPluginSystemHelpers: (project: PrismicProject) => PluginSystemHelpers;
|
|
21
|
+
/**
|
|
22
|
+
* Plugin System helpers shared to plugins and hooks.
|
|
23
|
+
*/
|
|
24
|
+
export declare class PluginSystemHelpers {
|
|
25
|
+
/**
|
|
26
|
+
* Project's metadata.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
private _project;
|
|
31
|
+
constructor(project: PrismicProject);
|
|
32
|
+
getProject: () => Promise<PrismicProject>;
|
|
33
|
+
updatePrismicConfig: (prismicConfig: PrismicConfig, options?: UpdatePrismicConfigOptions) => Promise<void>;
|
|
34
|
+
format: (source: string, filePath?: string, options?: FormatOptions) => Promise<string>;
|
|
35
|
+
joinPathFromRoot: (...paths: string[]) => string;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { stripIndent } from "common-tags";
|
|
4
|
+
import * as prettier from "prettier";
|
|
5
|
+
import { decodePrismicConfig } from "./lib/decodePrismicConfig.js";
|
|
6
|
+
const createPluginSystemHelpers = (project) => {
|
|
7
|
+
return new PluginSystemHelpers(project);
|
|
8
|
+
};
|
|
9
|
+
class PluginSystemHelpers {
|
|
10
|
+
/**
|
|
11
|
+
* Project's metadata.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
_project;
|
|
16
|
+
constructor(project) {
|
|
17
|
+
this._project = project;
|
|
18
|
+
}
|
|
19
|
+
getProject = async () => {
|
|
20
|
+
const configFilePath = this.joinPathFromRoot("prismic.config.json");
|
|
21
|
+
let rawConfig;
|
|
22
|
+
try {
|
|
23
|
+
const contents = await fs.readFile(configFilePath, "utf8");
|
|
24
|
+
rawConfig = JSON.parse(contents);
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
if (!rawConfig) {
|
|
28
|
+
throw new Error("No Prismic config found, please initialize your project with first.");
|
|
29
|
+
}
|
|
30
|
+
const { value: prismicConfig, error } = decodePrismicConfig(rawConfig);
|
|
31
|
+
if (error) {
|
|
32
|
+
throw new Error(`Invalid Prismic config. ${error.errors.join(", ")}`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
...this._project,
|
|
36
|
+
config: prismicConfig
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
updatePrismicConfig = async (prismicConfig, options) => {
|
|
40
|
+
const { value: decodedPrismicConfig, error } = decodePrismicConfig(prismicConfig);
|
|
41
|
+
if (error) {
|
|
42
|
+
throw new Error(`Invalid Prismic config provided. ${error.errors.join(", ")}`);
|
|
43
|
+
}
|
|
44
|
+
const configFilePath = this.joinPathFromRoot("prismic.config.json");
|
|
45
|
+
let content = JSON.stringify(decodedPrismicConfig, null, 2);
|
|
46
|
+
if (options?.format) {
|
|
47
|
+
content = await this.format(content, configFilePath);
|
|
48
|
+
}
|
|
49
|
+
await fs.writeFile(configFilePath, content);
|
|
50
|
+
};
|
|
51
|
+
format = async (source, filePath, options) => {
|
|
52
|
+
let formatted = stripIndent(source);
|
|
53
|
+
const prettierOptions = await prettier.resolveConfig(filePath || this._project.root);
|
|
54
|
+
formatted = await prettier.format(formatted, {
|
|
55
|
+
...prettierOptions,
|
|
56
|
+
filepath: filePath,
|
|
57
|
+
...options?.prettier ?? {}
|
|
58
|
+
});
|
|
59
|
+
if (options?.includeNewlineAtEnd === false) {
|
|
60
|
+
formatted = formatted.replace(/[\r\n]+$/, "");
|
|
61
|
+
}
|
|
62
|
+
return formatted;
|
|
63
|
+
};
|
|
64
|
+
joinPathFromRoot = (...paths) => {
|
|
65
|
+
return path.join(this._project.root, ...paths);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
PluginSystemHelpers,
|
|
70
|
+
createPluginSystemHelpers
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=createPluginSystemHelpers.js.map
|