@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.
Files changed (235) hide show
  1. package/dist/_node_modules/lower-case/dist.es2015/index.js +7 -0
  2. package/dist/_node_modules/lower-case/dist.es2015/index.js.map +1 -0
  3. package/dist/_node_modules/no-case/dist.es2015/index.js +28 -0
  4. package/dist/_node_modules/no-case/dist.es2015/index.js.map +1 -0
  5. package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js +68 -0
  6. package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js.map +1 -0
  7. package/dist/_node_modules/p-limit/index.js +77 -0
  8. package/dist/_node_modules/p-limit/index.js.map +1 -0
  9. package/dist/_node_modules/pascal-case/dist.es2015/index.js +25 -0
  10. package/dist/_node_modules/pascal-case/dist.es2015/index.js.map +1 -0
  11. package/dist/_node_modules/tslib/tslib.es6.js +14 -0
  12. package/dist/_node_modules/tslib/tslib.es6.js.map +1 -0
  13. package/dist/createPluginHookSystem.d.ts +6 -0
  14. package/dist/createPluginHookSystem.js +8 -0
  15. package/dist/createPluginHookSystem.js.map +1 -0
  16. package/dist/createPluginSystemActions.d.ts +46 -0
  17. package/dist/createPluginSystemActions.js +96 -0
  18. package/dist/createPluginSystemActions.js.map +1 -0
  19. package/dist/createPluginSystemContext.d.ts +31 -0
  20. package/dist/createPluginSystemContext.js +12 -0
  21. package/dist/createPluginSystemContext.js.map +1 -0
  22. package/dist/createPluginSystemHelpers.d.ts +37 -0
  23. package/dist/createPluginSystemHelpers.js +72 -0
  24. package/dist/createPluginSystemHelpers.js.map +1 -0
  25. package/dist/createPluginSystemRunner.d.ts +58 -0
  26. package/dist/createPluginSystemRunner.js +128 -0
  27. package/dist/createPluginSystemRunner.js.map +1 -0
  28. package/dist/definePlugin.d.ts +30 -0
  29. package/dist/definePlugin.js +5 -0
  30. package/dist/definePlugin.js.map +1 -0
  31. package/dist/fs/buildCustomTypeDirectoryPath.d.ts +5 -0
  32. package/dist/fs/buildCustomTypeDirectoryPath.js +9 -0
  33. package/dist/fs/buildCustomTypeDirectoryPath.js.map +1 -0
  34. package/dist/fs/buildCustomTypeFilePath.d.ts +5 -0
  35. package/dist/fs/buildCustomTypeFilePath.js +9 -0
  36. package/dist/fs/buildCustomTypeFilePath.js.map +1 -0
  37. package/dist/fs/buildCustomTypeLibraryDirectoryPath.d.ts +6 -0
  38. package/dist/fs/buildCustomTypeLibraryDirectoryPath.js +8 -0
  39. package/dist/fs/buildCustomTypeLibraryDirectoryPath.js.map +1 -0
  40. package/dist/fs/buildSliceDirectoryPath.d.ts +4 -0
  41. package/dist/fs/buildSliceDirectoryPath.js +12 -0
  42. package/dist/fs/buildSliceDirectoryPath.js.map +1 -0
  43. package/dist/fs/buildSliceFilePath.d.ts +5 -0
  44. package/dist/fs/buildSliceFilePath.js +9 -0
  45. package/dist/fs/buildSliceFilePath.js.map +1 -0
  46. package/dist/fs/buildSliceLibraryDirectoryPath.d.ts +7 -0
  47. package/dist/fs/buildSliceLibraryDirectoryPath.js +8 -0
  48. package/dist/fs/buildSliceLibraryDirectoryPath.js.map +1 -0
  49. package/dist/fs/checkHasProjectFile.d.ts +6 -0
  50. package/dist/fs/checkHasProjectFile.js +9 -0
  51. package/dist/fs/checkHasProjectFile.js.map +1 -0
  52. package/dist/fs/checkIsTypeScriptProject.d.ts +4 -0
  53. package/dist/fs/checkIsTypeScriptProject.js +12 -0
  54. package/dist/fs/checkIsTypeScriptProject.js.map +1 -0
  55. package/dist/fs/constants.d.ts +9 -0
  56. package/dist/fs/constants.js +15 -0
  57. package/dist/fs/constants.js.map +1 -0
  58. package/dist/fs/deleteCustomTypeDirectory.d.ts +3 -0
  59. package/dist/fs/deleteCustomTypeDirectory.js +18 -0
  60. package/dist/fs/deleteCustomTypeDirectory.js.map +1 -0
  61. package/dist/fs/deleteProjectFile.d.ts +6 -0
  62. package/dist/fs/deleteProjectFile.js +10 -0
  63. package/dist/fs/deleteProjectFile.js.map +1 -0
  64. package/dist/fs/deleteSliceDirectory.d.ts +3 -0
  65. package/dist/fs/deleteSliceDirectory.js +18 -0
  66. package/dist/fs/deleteSliceDirectory.js.map +1 -0
  67. package/dist/fs/deleteSliceFile.d.ts +3 -0
  68. package/dist/fs/deleteSliceFile.js +18 -0
  69. package/dist/fs/deleteSliceFile.js.map +1 -0
  70. package/dist/fs/index.d.ts +49 -0
  71. package/dist/fs/index.js +53 -0
  72. package/dist/fs/index.js.map +1 -0
  73. package/dist/fs/lib/checkPathExists.d.ts +2 -0
  74. package/dist/fs/lib/checkPathExists.js +13 -0
  75. package/dist/fs/lib/checkPathExists.js.map +1 -0
  76. package/dist/fs/lib/fsLimit.d.ts +31 -0
  77. package/dist/fs/lib/fsLimit.js +23 -0
  78. package/dist/fs/lib/fsLimit.js.map +1 -0
  79. package/dist/fs/lib/isCustomTypeModel.d.ts +2 -0
  80. package/dist/fs/lib/isCustomTypeModel.js +7 -0
  81. package/dist/fs/lib/isCustomTypeModel.js.map +1 -0
  82. package/dist/fs/lib/isSharedSliceModel.d.ts +2 -0
  83. package/dist/fs/lib/isSharedSliceModel.js +7 -0
  84. package/dist/fs/lib/isSharedSliceModel.js.map +1 -0
  85. package/dist/fs/lib/pascalCase.d.ts +8 -0
  86. package/dist/fs/lib/pascalCase.js +10 -0
  87. package/dist/fs/lib/pascalCase.js.map +1 -0
  88. package/dist/fs/lib/readJSONFile.d.ts +1 -0
  89. package/dist/fs/lib/readJSONFile.js +9 -0
  90. package/dist/fs/lib/readJSONFile.js.map +1 -0
  91. package/dist/fs/lib/resolveSliceModel.d.ts +10 -0
  92. package/dist/fs/lib/resolveSliceModel.js +14 -0
  93. package/dist/fs/lib/resolveSliceModel.js.map +1 -0
  94. package/dist/fs/readCustomTypeFile.d.ts +8 -0
  95. package/dist/fs/readCustomTypeFile.js +14 -0
  96. package/dist/fs/readCustomTypeFile.js.map +1 -0
  97. package/dist/fs/readCustomTypeLibrary.d.ts +6 -0
  98. package/dist/fs/readCustomTypeLibrary.js +53 -0
  99. package/dist/fs/readCustomTypeLibrary.js.map +1 -0
  100. package/dist/fs/readCustomTypeModel.d.ts +7 -0
  101. package/dist/fs/readCustomTypeModel.js +16 -0
  102. package/dist/fs/readCustomTypeModel.js.map +1 -0
  103. package/dist/fs/readProjectFile.d.ts +12 -0
  104. package/dist/fs/readProjectFile.js +9 -0
  105. package/dist/fs/readProjectFile.js.map +1 -0
  106. package/dist/fs/readSliceFile.d.ts +8 -0
  107. package/dist/fs/readSliceFile.js +17 -0
  108. package/dist/fs/readSliceFile.js.map +1 -0
  109. package/dist/fs/readSliceLibrary.d.ts +7 -0
  110. package/dist/fs/readSliceLibrary.js +56 -0
  111. package/dist/fs/readSliceLibrary.js.map +1 -0
  112. package/dist/fs/readSliceModel.d.ts +11 -0
  113. package/dist/fs/readSliceModel.js +46 -0
  114. package/dist/fs/readSliceModel.js.map +1 -0
  115. package/dist/fs/renameCustomType.d.ts +3 -0
  116. package/dist/fs/renameCustomType.js +8 -0
  117. package/dist/fs/renameCustomType.js.map +1 -0
  118. package/dist/fs/renameSlice.d.ts +7 -0
  119. package/dist/fs/renameSlice.js +22 -0
  120. package/dist/fs/renameSlice.js.map +1 -0
  121. package/dist/fs/types.d.ts +3 -0
  122. package/dist/fs/upsertGlobalTypeScriptTypes.d.ts +16 -0
  123. package/dist/fs/upsertGlobalTypeScriptTypes.js +37 -0
  124. package/dist/fs/upsertGlobalTypeScriptTypes.js.map +1 -0
  125. package/dist/fs/writeCustomTypeFile.d.ts +9 -0
  126. package/dist/fs/writeCustomTypeFile.js +18 -0
  127. package/dist/fs/writeCustomTypeFile.js.map +1 -0
  128. package/dist/fs/writeCustomTypeModel.d.ts +12 -0
  129. package/dist/fs/writeCustomTypeModel.js +14 -0
  130. package/dist/fs/writeCustomTypeModel.js.map +1 -0
  131. package/dist/fs/writeProjectFile.d.ts +15 -0
  132. package/dist/fs/writeProjectFile.js +16 -0
  133. package/dist/fs/writeProjectFile.js.map +1 -0
  134. package/dist/fs/writeSliceFile.d.ts +9 -0
  135. package/dist/fs/writeSliceFile.js +18 -0
  136. package/dist/fs/writeSliceFile.js.map +1 -0
  137. package/dist/fs/writeSliceModel.d.ts +11 -0
  138. package/dist/fs/writeSliceModel.js +13 -0
  139. package/dist/fs/writeSliceModel.js.map +1 -0
  140. package/dist/hooks/customType-create.d.ts +28 -0
  141. package/dist/hooks/customType-delete.d.ts +26 -0
  142. package/dist/hooks/customType-read.d.ts +32 -0
  143. package/dist/hooks/customType-rename.d.ts +29 -0
  144. package/dist/hooks/customType-update.d.ts +29 -0
  145. package/dist/hooks/customTypeLibrary-read.d.ts +25 -0
  146. package/dist/hooks/debug.d.ts +22 -0
  147. package/dist/hooks/project-init.d.ts +35 -0
  148. package/dist/hooks/slice-create.d.ts +30 -0
  149. package/dist/hooks/slice-delete.d.ts +26 -0
  150. package/dist/hooks/slice-read.d.ts +32 -0
  151. package/dist/hooks/slice-rename.d.ts +26 -0
  152. package/dist/hooks/slice-update.d.ts +29 -0
  153. package/dist/hooks/sliceLibrary-read.d.ts +27 -0
  154. package/dist/index.d.ts +24 -0
  155. package/dist/index.js +15 -0
  156. package/dist/index.js.map +1 -0
  157. package/dist/lib/DecodeError.d.ts +13 -0
  158. package/dist/lib/DecodeError.js +21 -0
  159. package/dist/lib/DecodeError.js.map +1 -0
  160. package/dist/lib/HookSystem.d.ts +93 -0
  161. package/dist/lib/HookSystem.js +121 -0
  162. package/dist/lib/HookSystem.js.map +1 -0
  163. package/dist/lib/decode.d.ts +10 -0
  164. package/dist/lib/decode.js +16 -0
  165. package/dist/lib/decode.js.map +1 -0
  166. package/dist/lib/decodePrismicConfig.d.ts +3 -0
  167. package/dist/lib/decodePrismicConfig.js +22 -0
  168. package/dist/lib/decodePrismicConfig.js.map +1 -0
  169. package/dist/types.d.ts +129 -0
  170. package/dist/types.js +21 -0
  171. package/dist/types.js.map +1 -0
  172. package/package.json +90 -0
  173. package/src/createPluginHookSystem.ts +9 -0
  174. package/src/createPluginSystemActions.ts +188 -0
  175. package/src/createPluginSystemContext.ts +51 -0
  176. package/src/createPluginSystemHelpers.ts +129 -0
  177. package/src/createPluginSystemRunner.ts +216 -0
  178. package/src/definePlugin.ts +48 -0
  179. package/src/fs/buildCustomTypeDirectoryPath.ts +19 -0
  180. package/src/fs/buildCustomTypeFilePath.ts +16 -0
  181. package/src/fs/buildCustomTypeLibraryDirectoryPath.ts +16 -0
  182. package/src/fs/buildSliceDirectoryPath.ts +25 -0
  183. package/src/fs/buildSliceFilePath.ts +16 -0
  184. package/src/fs/buildSliceLibraryDirectoryPath.ts +17 -0
  185. package/src/fs/checkHasProjectFile.ts +16 -0
  186. package/src/fs/checkIsTypeScriptProject.ts +16 -0
  187. package/src/fs/constants.ts +15 -0
  188. package/src/fs/deleteCustomTypeDirectory.ts +24 -0
  189. package/src/fs/deleteProjectFile.ts +18 -0
  190. package/src/fs/deleteSliceDirectory.ts +24 -0
  191. package/src/fs/deleteSliceFile.ts +24 -0
  192. package/src/fs/index.ts +103 -0
  193. package/src/fs/lib/checkPathExists.ts +13 -0
  194. package/src/fs/lib/fsLimit.ts +72 -0
  195. package/src/fs/lib/isCustomTypeModel.ts +7 -0
  196. package/src/fs/lib/isSharedSliceModel.ts +14 -0
  197. package/src/fs/lib/pascalCase.ts +17 -0
  198. package/src/fs/lib/readJSONFile.ts +7 -0
  199. package/src/fs/lib/resolveSliceModel.ts +28 -0
  200. package/src/fs/readCustomTypeFile.ts +27 -0
  201. package/src/fs/readCustomTypeLibrary.ts +86 -0
  202. package/src/fs/readCustomTypeModel.ts +27 -0
  203. package/src/fs/readProjectFile.ts +24 -0
  204. package/src/fs/readSliceFile.ts +27 -0
  205. package/src/fs/readSliceLibrary.ts +91 -0
  206. package/src/fs/readSliceModel.ts +90 -0
  207. package/src/fs/renameCustomType.ts +12 -0
  208. package/src/fs/renameSlice.ts +35 -0
  209. package/src/fs/types.ts +5 -0
  210. package/src/fs/upsertGlobalTypeScriptTypes.ts +64 -0
  211. package/src/fs/writeCustomTypeFile.ts +30 -0
  212. package/src/fs/writeCustomTypeModel.ts +31 -0
  213. package/src/fs/writeProjectFile.ts +39 -0
  214. package/src/fs/writeSliceFile.ts +30 -0
  215. package/src/fs/writeSliceModel.ts +26 -0
  216. package/src/hooks/customType-create.ts +42 -0
  217. package/src/hooks/customType-delete.ts +40 -0
  218. package/src/hooks/customType-read.ts +46 -0
  219. package/src/hooks/customType-rename.ts +43 -0
  220. package/src/hooks/customType-update.ts +43 -0
  221. package/src/hooks/customTypeLibrary-read.ts +38 -0
  222. package/src/hooks/debug.ts +31 -0
  223. package/src/hooks/project-init.ts +48 -0
  224. package/src/hooks/slice-create.ts +44 -0
  225. package/src/hooks/slice-delete.ts +40 -0
  226. package/src/hooks/slice-read.ts +44 -0
  227. package/src/hooks/slice-rename.ts +40 -0
  228. package/src/hooks/slice-update.ts +43 -0
  229. package/src/hooks/sliceLibrary-read.ts +41 -0
  230. package/src/index.ts +141 -0
  231. package/src/lib/DecodeError.ts +31 -0
  232. package/src/lib/HookSystem.ts +277 -0
  233. package/src/lib/decode.ts +30 -0
  234. package/src/lib/decodePrismicConfig.ts +26 -0
  235. package/src/types.ts +175 -0
@@ -0,0 +1,26 @@
1
+ import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
2
+ import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
3
+ /**
4
+ * Data provided to `slice:delete` hook handlers.
5
+ */
6
+ export type SliceDeleteHookData = {
7
+ libraryID: string;
8
+ model: TypesInternal.SharedSlice;
9
+ };
10
+ /**
11
+ * Return value for `slice:delete` hook handlers.
12
+ */
13
+ export type SliceDeleteHookReturnType = void;
14
+ /**
15
+ * Base version of a `slice:delete` hook handler without plugin runner context.
16
+ *
17
+ * @internal
18
+ */
19
+ export type SliceDeleteHookBase = PluginHook<SliceDeleteHookData, SliceDeleteHookReturnType>;
20
+ /**
21
+ * Handler for the `slice:delete` hook. The hook is called when a Slice is
22
+ * deleted.
23
+ *
24
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
25
+ */
26
+ export type SliceDeleteHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceDeleteHookBase, TPluginOptions>;
@@ -0,0 +1,32 @@
1
+ import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
2
+ import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
3
+ /**
4
+ * Data provided to `slice:read` hook handlers.
5
+ */
6
+ export type SliceReadHookData = {
7
+ libraryID: string;
8
+ sliceID: string;
9
+ };
10
+ /**
11
+ * Return value for `slice:read` hook handlers.
12
+ */
13
+ export type SliceReadHookReturnType = {
14
+ model: TypesInternal.SharedSlice;
15
+ };
16
+ /**
17
+ * Base version of a `slice:read` hook handler without plugin runner context.
18
+ *
19
+ * @internal
20
+ */
21
+ export type SliceReadHookBase = PluginHook<SliceReadHookData, SliceReadHookReturnType>;
22
+ /**
23
+ * Handler for the `slice:read` hook. The hook is called when a Slice's model is
24
+ * needed.
25
+ *
26
+ * This hook is **required** to be implemented by adapters.
27
+ *
28
+ * This hook will only be called in adapters.
29
+ *
30
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
31
+ */
32
+ export type SliceReadHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceReadHookBase, TPluginOptions>;
@@ -0,0 +1,26 @@
1
+ import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
2
+ import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
3
+ /**
4
+ * Data provided to `slice:rename` hook handlers.
5
+ */
6
+ export type SliceRenameHookData = {
7
+ libraryID: string;
8
+ model: TypesInternal.SharedSlice;
9
+ };
10
+ /**
11
+ * Return value for `slice:rename` hook handlers.
12
+ */
13
+ export type SliceRenameHookReturnType = void;
14
+ /**
15
+ * Base version of a `slice:rename` hook handler without plugin runner context.
16
+ *
17
+ * @internal
18
+ */
19
+ export type SliceRenameHookBase = PluginHook<SliceRenameHookData, SliceRenameHookReturnType>;
20
+ /**
21
+ * Handler for the `slice:rename` hook. The hook is called when a Slice is
22
+ * renamed.
23
+ *
24
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
25
+ */
26
+ export type SliceRenameHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceRenameHookBase, TPluginOptions>;
@@ -0,0 +1,29 @@
1
+ import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
2
+ import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
3
+ /**
4
+ * Data provided to `slice:update` hook handlers.
5
+ */
6
+ export type SliceUpdateHookData = {
7
+ libraryID: string;
8
+ model: TypesInternal.SharedSlice;
9
+ };
10
+ /**
11
+ * Return value for `slice:update` hook handlers.
12
+ */
13
+ export type SliceUpdateHookReturnType = void;
14
+ /**
15
+ * Base version of a `slice:update` hook handler without plugin runner context.
16
+ *
17
+ * @internal
18
+ */
19
+ export type SliceUpdateHookBase = PluginHook<SliceUpdateHookData, SliceUpdateHookReturnType>;
20
+ /**
21
+ * Handler for the `slice:update` hook. The hook is called when a Slice is
22
+ * updated.
23
+ *
24
+ * `slice:update` is not called the first time a Slice is saved. The
25
+ * `slice:create` hook is called instead.
26
+ *
27
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
28
+ */
29
+ export type SliceUpdateHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceUpdateHookBase, TPluginOptions>;
@@ -0,0 +1,27 @@
1
+ import type { ExtendPluginSystemHook, PluginOptions, SliceLibrary, PluginHook } from "../types.js";
2
+ /**
3
+ * Data provided to `slice-library:read` hook handlers.
4
+ */
5
+ export type SliceLibraryReadHookData = {
6
+ libraryID: string;
7
+ };
8
+ /**
9
+ * Return value for `slice-library:read` hook handlers.
10
+ */
11
+ export type SliceLibraryReadHookReturnType = SliceLibrary & {
12
+ sliceIDs: string[];
13
+ };
14
+ /**
15
+ * Base version of a `slice-library:read` hook handler without plugin runner
16
+ * context.
17
+ *
18
+ * @internal
19
+ */
20
+ export type SliceLibraryReadHookBase = PluginHook<SliceLibraryReadHookData, SliceLibraryReadHookReturnType>;
21
+ /**
22
+ * Handler for the `slice-library:read` hook. The hook is called when a Slice
23
+ * Library's metadata is needed.
24
+ *
25
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
26
+ */
27
+ export type SliceLibraryReadHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceLibraryReadHookBase, TPluginOptions>;
@@ -0,0 +1,24 @@
1
+ export { definePlugin } from "./definePlugin.js";
2
+ export type { Plugin } from "./definePlugin.js";
3
+ export type { PluginSystemActions, ReadAllSliceModelsActionArgs, ReadAllSliceModelsActionReturnType, ReadAllSliceModelsForLibraryActionArgs, } from "./createPluginSystemActions.js";
4
+ export type { PluginSystemHelpers } from "./createPluginSystemHelpers.js";
5
+ export type { PluginSystemContext } from "./createPluginSystemContext.js";
6
+ export { PluginHookType } from "./types.js";
7
+ export type { PluginOptions, PrismicProject, PrismicConfig, SliceLibrary, PluginHooks, PluginHookTypes, } from "./types.js";
8
+ export { HookError } from "./lib/HookSystem.js";
9
+ export { DecodeError } from "./lib/DecodeError.js";
10
+ export type { SliceCreateHook, SliceCreateHookData, SliceCreateHookReturnType, } from "./hooks/slice-create.js";
11
+ export type { SliceUpdateHook, SliceUpdateHookData, SliceUpdateHookReturnType, } from "./hooks/slice-update.js";
12
+ export type { SliceRenameHook, SliceRenameHookData, SliceRenameHookReturnType, } from "./hooks/slice-rename.js";
13
+ export type { SliceDeleteHook, SliceDeleteHookData, SliceDeleteHookReturnType, } from "./hooks/slice-delete.js";
14
+ export type { SliceReadHook, SliceReadHookData, SliceReadHookReturnType, } from "./hooks/slice-read.js";
15
+ export type { SliceLibraryReadHook, SliceLibraryReadHookData, SliceLibraryReadHookReturnType, } from "./hooks/sliceLibrary-read.js";
16
+ export type { CustomTypeCreateHook, CustomTypeCreateHookData, CustomTypeCreateHookReturnType, } from "./hooks/customType-create.js";
17
+ export type { CustomTypeUpdateHook, CustomTypeUpdateHookData, CustomTypeUpdateHookReturnType, } from "./hooks/customType-update.js";
18
+ export type { CustomTypeRenameHook, CustomTypeRenameHookData, CustomTypeRenameHookReturnType, } from "./hooks/customType-rename.js";
19
+ export type { CustomTypeDeleteHook, CustomTypeDeleteHookData, CustomTypeDeleteHookReturnType, } from "./hooks/customType-delete.js";
20
+ export type { CustomTypeReadHook, CustomTypeReadHookData, CustomTypeReadHookReturnType, } from "./hooks/customType-read.js";
21
+ export type { CustomTypeLibraryReadHook, CustomTypeLibraryReadHookData, CustomTypeLibraryReadHookReturnType, } from "./hooks/customTypeLibrary-read.js";
22
+ export type { ProjectInitHook, ProjectInitHookData, ProjectInitHookReturnType, } from "./hooks/project-init.js";
23
+ export { createPluginSystemRunner, PluginSystemRunner, REQUIRED_ADAPTER_HOOKS, } from "./createPluginSystemRunner.js";
24
+ export type { CallHookReturnType } from "./lib/HookSystem.js";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { definePlugin } from "./definePlugin.js";
2
+ import { PluginHookType } from "./types.js";
3
+ import { HookError } from "./lib/HookSystem.js";
4
+ import { DecodeError } from "./lib/DecodeError.js";
5
+ import { PluginSystemRunner, REQUIRED_ADAPTER_HOOKS, createPluginSystemRunner } from "./createPluginSystemRunner.js";
6
+ export {
7
+ DecodeError,
8
+ HookError,
9
+ PluginHookType,
10
+ PluginSystemRunner,
11
+ REQUIRED_ADAPTER_HOOKS,
12
+ createPluginSystemRunner,
13
+ definePlugin
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,13 @@
1
+ import * as z from "zod";
2
+ type ZodIssue = z.ZodIssue;
3
+ type DecodeErrorConstructorArgs<TInput = unknown> = {
4
+ input: TInput;
5
+ errors: ZodIssue[];
6
+ };
7
+ export declare class DecodeError<TInput = unknown> extends Error {
8
+ name: string;
9
+ input: TInput;
10
+ errors: string[];
11
+ constructor(args: DecodeErrorConstructorArgs<TInput>);
12
+ }
13
+ export {};
@@ -0,0 +1,21 @@
1
+ function formatZodErrors(errors) {
2
+ return errors.map((err) => {
3
+ const path = err.path.length > 0 ? ` at ${err.path.join(".")}` : "";
4
+ return `${err.message}${path}`;
5
+ });
6
+ }
7
+ class DecodeError extends Error {
8
+ name = "DecodeError";
9
+ input;
10
+ errors;
11
+ constructor(args) {
12
+ const formattedErrors = formatZodErrors(args.errors);
13
+ super(formattedErrors.join(", "));
14
+ this.input = args.input;
15
+ this.errors = formattedErrors;
16
+ }
17
+ }
18
+ export {
19
+ DecodeError
20
+ };
21
+ //# sourceMappingURL=DecodeError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecodeError.js","sources":["../../../src/lib/DecodeError.ts"],"sourcesContent":["import * as z from \"zod\";\n\ntype ZodIssue = z.ZodIssue;\n\ntype DecodeErrorConstructorArgs<TInput = unknown> = {\n\tinput: TInput;\n\terrors: ZodIssue[];\n};\n\nfunction formatZodErrors(errors: ZodIssue[]): string[] {\n\treturn errors.map((err) => {\n\t\tconst path = err.path.length > 0 ? ` at ${err.path.join(\".\")}` : \"\";\n\n\t\treturn `${err.message}${path}`;\n\t});\n}\n\nexport class DecodeError<TInput = unknown> extends Error {\n\tname = \"DecodeError\";\n\tinput: TInput;\n\terrors: string[];\n\n\tconstructor(args: DecodeErrorConstructorArgs<TInput>) {\n\t\tconst formattedErrors = formatZodErrors(args.errors);\n\n\t\tsuper(formattedErrors.join(\", \"));\n\n\t\tthis.input = args.input;\n\t\tthis.errors = formattedErrors;\n\t}\n}\n"],"names":[],"mappings":"AASA,SAAS,gBAAgB,QAAkB;AAC1C,SAAO,OAAO,IAAI,CAAC,QAAO;AACzB,UAAM,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,KAAK,GAAG,CAAC,KAAK;AAEjE,WAAO,GAAG,IAAI,OAAO,GAAG,IAAI;AAAA,EAC7B,CAAC;AACF;AAEM,MAAO,oBAAsC,MAAK;AAAA,EACvD,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EAEA,YAAY,MAAwC;AACnD,UAAM,kBAAkB,gBAAgB,KAAK,MAAM;AAEnD,UAAM,gBAAgB,KAAK,IAAI,CAAC;AAEhC,SAAK,QAAQ,KAAK;AAClB,SAAK,SAAS;AAAA,EACf;AACA;"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Extends a function arguments with extra ones.
3
+ */
4
+ type FnWithExtraArgs<F extends (...args: any[]) => any, TExtraArgs extends any[] = any[]> = (...args: [...args: Parameters<F>, ...extraArgs: TExtraArgs]) => ReturnType<F>;
5
+ /**
6
+ * Defines a hook handler.
7
+ */
8
+ export type HookFn<TArgs extends any[] = any[], TReturn = any> = (...args: TArgs) => Promise<TReturn> | TReturn;
9
+ /**
10
+ * Generic hook metadata.
11
+ */
12
+ type HookMeta = Record<string, unknown>;
13
+ /**
14
+ * Defines a hook, including its function handler and optional metadata.
15
+ */
16
+ export type Hook<THookFn extends HookFn = HookFn, THookMeta extends HookMeta = HookMeta> = {
17
+ fn: THookFn;
18
+ meta?: THookMeta;
19
+ };
20
+ /**
21
+ * Represents a map of hook types to hook functions and metas.
22
+ */
23
+ type Hooks = Record<string, Hook>;
24
+ /**
25
+ * Builds hook meta arguments after hook meta requirements.
26
+ */
27
+ type HookMetaArg<THookMeta extends Record<string, unknown> | undefined> = THookMeta extends Record<string, unknown> ? [meta: THookMeta] : [meta?: never];
28
+ /**
29
+ * Defines the return type of the {@link HookSystem.callHook} functions.
30
+ *
31
+ * @internal
32
+ */
33
+ export type CallHookReturnType<THookFn extends HookFn = HookFn> = Promise<{
34
+ data: Awaited<ReturnType<THookFn>>[];
35
+ errors: HookError[];
36
+ }>;
37
+ /**
38
+ * Defines the return type of the {@link HookSystem.createScope} functions.
39
+ *
40
+ * @internal
41
+ */
42
+ export type CreateScopeReturnType<THooks extends Hooks = Record<string, {
43
+ fn: HookFn;
44
+ }>, TExtraArgs extends unknown[] = never[]> = {
45
+ hook: <TType extends keyof THooks>(type: TType, hookFn: FnWithExtraArgs<THooks[TType]["fn"], TExtraArgs>, ...[meta]: HookMetaArg<THooks[TType]["meta"]>) => void;
46
+ unhook: HookSystem<{
47
+ [P in keyof THooks]: Omit<THooks[P], "fn"> & {
48
+ fn: FnWithExtraArgs<THooks[P]["fn"], TExtraArgs>;
49
+ };
50
+ }>["unhook"];
51
+ };
52
+ type RegisteredHookMeta = {
53
+ id: string;
54
+ type: string;
55
+ owner: string;
56
+ external?: HookFn;
57
+ };
58
+ /**
59
+ * Represents a registered hook.
60
+ */
61
+ type RegisteredHook<THook extends Hook = Hook> = {
62
+ fn: THook["fn"];
63
+ meta: THook["meta"] extends Record<string, unknown> ? RegisteredHookMeta & THook["meta"] : RegisteredHookMeta;
64
+ };
65
+ export declare class HookError<TError = Error | unknown> extends Error {
66
+ type: string;
67
+ owner: string;
68
+ rawMeta: RegisteredHookMeta;
69
+ rawCause: TError;
70
+ constructor(meta: RegisteredHookMeta, cause: TError);
71
+ }
72
+ /**
73
+ * @internal
74
+ */
75
+ export declare class HookSystem<THooks extends Hooks = Hooks> {
76
+ private _registeredHooks;
77
+ hook<TType extends keyof THooks>(owner: string, type: TType, hookFn: THooks[TType]["fn"], ...[meta]: HookMetaArg<THooks[TType]["meta"]>): void;
78
+ unhook<TType extends keyof THooks>(type: TType, hookFn: THooks[TType]["fn"]): void;
79
+ callHook<TType extends Extract<keyof THooks, string>>(typeOrTypeAndHookID: TType | {
80
+ type: TType;
81
+ hookID: string;
82
+ }, ...args: Parameters<THooks[TType]["fn"]>): CallHookReturnType<THooks[TType]["fn"]>;
83
+ /**
84
+ * Returns list of hooks for a given owner
85
+ */
86
+ hooksForOwner(owner: string): RegisteredHook<THooks[string]>[];
87
+ /**
88
+ * Returns list of hooks for a given type
89
+ */
90
+ hooksForType<TType extends keyof THooks>(type: TType): RegisteredHook<THooks[TType]>[];
91
+ createScope<TExtraArgs extends unknown[] = never[]>(owner: string, extraArgs: [...TExtraArgs]): CreateScopeReturnType<THooks, TExtraArgs>;
92
+ }
93
+ export {};
@@ -0,0 +1,121 @@
1
+ class HookError extends Error {
2
+ type;
3
+ owner;
4
+ rawMeta;
5
+ rawCause;
6
+ constructor(meta, cause) {
7
+ super(`Error in \`${meta.owner}\` during \`${meta.type}\` hook: ${cause instanceof Error ? cause.message : String(cause)}`);
8
+ this.type = meta.type;
9
+ this.owner = meta.owner;
10
+ this.rawMeta = meta;
11
+ this.rawCause = cause;
12
+ this.cause = cause instanceof Error ? cause : void 0;
13
+ }
14
+ }
15
+ const uuid = () => {
16
+ return (++uuid.i).toString();
17
+ };
18
+ uuid.i = 0;
19
+ class HookSystem {
20
+ _registeredHooks = {};
21
+ hook(owner, type, hookFn, ...[meta]) {
22
+ const registeredHook = {
23
+ fn: hookFn,
24
+ meta: {
25
+ ...meta,
26
+ owner,
27
+ type,
28
+ id: uuid()
29
+ }
30
+ };
31
+ const registeredHooksForType = this._registeredHooks[type];
32
+ if (registeredHooksForType) {
33
+ registeredHooksForType.push(registeredHook);
34
+ } else {
35
+ this._registeredHooks[type] = [registeredHook];
36
+ }
37
+ }
38
+ unhook(type, hookFn) {
39
+ this._registeredHooks[type] = this._registeredHooks[type]?.filter((registeredHook) => registeredHook.fn !== hookFn);
40
+ }
41
+ async callHook(typeOrTypeAndHookID, ...args) {
42
+ let hooks;
43
+ if (typeof typeOrTypeAndHookID === "string") {
44
+ hooks = this._registeredHooks[typeOrTypeAndHookID] ?? [];
45
+ } else {
46
+ const hookForID = this._registeredHooks[typeOrTypeAndHookID.type]?.find((hook) => hook.meta.id === typeOrTypeAndHookID.hookID);
47
+ if (hookForID) {
48
+ hooks = [hookForID];
49
+ } else {
50
+ throw new Error(`Hook of type \`${typeOrTypeAndHookID.type}\` with ID \`${typeOrTypeAndHookID.hookID}\` not found.`);
51
+ }
52
+ }
53
+ const promises = hooks.map(async (hook) => {
54
+ try {
55
+ return await hook.fn(...args);
56
+ } catch (error) {
57
+ throw new HookError(hook.meta, error);
58
+ }
59
+ });
60
+ const settledPromises = await Promise.allSettled(promises);
61
+ return settledPromises.reduce((acc, settledPromise) => {
62
+ if (settledPromise.status === "fulfilled") {
63
+ acc.data.push(settledPromise.value);
64
+ } else {
65
+ acc.errors.push(settledPromise.reason);
66
+ }
67
+ return acc;
68
+ }, { data: [], errors: [] });
69
+ }
70
+ /**
71
+ * Returns list of hooks for a given owner
72
+ */
73
+ hooksForOwner(owner) {
74
+ const hooks = [];
75
+ for (const hookType in this._registeredHooks) {
76
+ const registeredHooks = this._registeredHooks[hookType];
77
+ if (Array.isArray(registeredHooks)) {
78
+ for (const registeredHook of registeredHooks) {
79
+ if (registeredHook.meta.owner === owner) {
80
+ hooks.push(registeredHook);
81
+ }
82
+ }
83
+ }
84
+ }
85
+ return hooks;
86
+ }
87
+ /**
88
+ * Returns list of hooks for a given type
89
+ */
90
+ hooksForType(type) {
91
+ return this._registeredHooks[type] ?? [];
92
+ }
93
+ createScope(owner, extraArgs) {
94
+ return {
95
+ hook: (type, hookFn, ...[meta]) => {
96
+ const internalHook = (...args) => {
97
+ return hookFn(...args, ...extraArgs);
98
+ };
99
+ const resolvedMeta = {
100
+ ...meta,
101
+ external: hookFn
102
+ };
103
+ return this.hook(
104
+ owner,
105
+ type,
106
+ internalHook,
107
+ // @ts-expect-error - TypeScript fails to assert rest argument.
108
+ resolvedMeta
109
+ );
110
+ },
111
+ unhook: (type, hookFn) => {
112
+ this._registeredHooks[type] = this._registeredHooks[type]?.filter((registeredHook) => registeredHook.meta.external !== hookFn);
113
+ }
114
+ };
115
+ }
116
+ }
117
+ export {
118
+ HookError,
119
+ HookSystem
120
+ };
121
+ //# sourceMappingURL=HookSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HookSystem.js","sources":["../../../src/lib/HookSystem.ts"],"sourcesContent":["/**\n * Extends a function arguments with extra ones.\n */\ntype FnWithExtraArgs<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tF extends (...args: any[]) => any,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTExtraArgs extends any[] = any[],\n> = (\n\t...args: [...args: Parameters<F>, ...extraArgs: TExtraArgs]\n) => ReturnType<F>;\n\n/**\n * Defines a hook handler.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type HookFn<TArgs extends any[] = any[], TReturn = any> = (\n\t...args: TArgs\n) => Promise<TReturn> | TReturn;\n\n/**\n * Generic hook metadata.\n */\ntype HookMeta = Record<string, unknown>;\n\n/**\n * Defines a hook, including its function handler and optional metadata.\n */\nexport type Hook<\n\tTHookFn extends HookFn = HookFn,\n\tTHookMeta extends HookMeta = HookMeta,\n> = {\n\tfn: THookFn;\n\tmeta?: THookMeta;\n};\n\n/**\n * Represents a map of hook types to hook functions and metas.\n */\ntype Hooks = Record<string, Hook>;\n\n/**\n * Builds hook meta arguments after hook meta requirements.\n */\ntype HookMetaArg<THookMeta extends Record<string, unknown> | undefined> =\n\tTHookMeta extends Record<string, unknown>\n\t\t? [meta: THookMeta]\n\t\t: [meta?: never];\n\n/**\n * Defines the return type of the {@link HookSystem.callHook} functions.\n *\n * @internal\n */\nexport type CallHookReturnType<THookFn extends HookFn = HookFn> = Promise<{\n\tdata: Awaited<ReturnType<THookFn>>[];\n\terrors: HookError[];\n}>;\n\n/**\n * Defines the return type of the {@link HookSystem.createScope} functions.\n *\n * @internal\n */\nexport type CreateScopeReturnType<\n\tTHooks extends Hooks = Record<string, { fn: HookFn }>,\n\tTExtraArgs extends unknown[] = never[],\n> = {\n\thook: <TType extends keyof THooks>(\n\t\ttype: TType,\n\t\thookFn: FnWithExtraArgs<THooks[TType][\"fn\"], TExtraArgs>,\n\t\t...[meta]: HookMetaArg<THooks[TType][\"meta\"]>\n\t) => void;\n\tunhook: HookSystem<{\n\t\t[P in keyof THooks]: Omit<THooks[P], \"fn\"> & {\n\t\t\tfn: FnWithExtraArgs<THooks[P][\"fn\"], TExtraArgs>;\n\t\t};\n\t}>[\"unhook\"];\n};\n\ntype RegisteredHookMeta = {\n\tid: string;\n\ttype: string;\n\towner: string;\n\texternal?: HookFn;\n};\n\n/**\n * Represents a registered hook.\n */\ntype RegisteredHook<THook extends Hook = Hook> = {\n\tfn: THook[\"fn\"];\n\tmeta: THook[\"meta\"] extends Record<string, unknown>\n\t\t? RegisteredHookMeta & THook[\"meta\"]\n\t\t: RegisteredHookMeta;\n};\n\nexport class HookError<TError = Error | unknown> extends Error {\n\ttype: string;\n\towner: string;\n\trawMeta: RegisteredHookMeta;\n\trawCause: TError;\n\n\tconstructor(meta: RegisteredHookMeta, cause: TError) {\n\t\tsuper(\n\t\t\t`Error in \\`${meta.owner}\\` during \\`${meta.type}\\` hook: ${\n\t\t\t\tcause instanceof Error ? cause.message : String(cause)\n\t\t\t}`,\n\t\t);\n\n\t\tthis.type = meta.type;\n\t\tthis.owner = meta.owner;\n\t\tthis.rawMeta = meta;\n\t\tthis.rawCause = cause;\n\t\tthis.cause = cause instanceof Error ? cause : undefined;\n\t}\n}\n\nconst uuid = (): string => {\n\treturn (++uuid.i).toString();\n};\nuuid.i = 0;\n\n/**\n * @internal\n */\nexport class HookSystem<THooks extends Hooks = Hooks> {\n\tprivate _registeredHooks: {\n\t\t[K in keyof THooks]?: RegisteredHook<THooks[K]>[];\n\t} = {};\n\n\thook<TType extends keyof THooks>(\n\t\towner: string,\n\t\ttype: TType,\n\t\thookFn: THooks[TType][\"fn\"],\n\t\t...[meta]: HookMetaArg<THooks[TType][\"meta\"]>\n\t): void {\n\t\tconst registeredHook = {\n\t\t\tfn: hookFn,\n\t\t\tmeta: {\n\t\t\t\t...meta,\n\t\t\t\towner,\n\t\t\t\ttype,\n\t\t\t\tid: uuid(),\n\t\t\t},\n\t\t} as RegisteredHook<THooks[TType]>;\n\n\t\tconst registeredHooksForType = this._registeredHooks[type];\n\n\t\tif (registeredHooksForType) {\n\t\t\tregisteredHooksForType.push(registeredHook);\n\t\t} else {\n\t\t\tthis._registeredHooks[type] = [registeredHook];\n\t\t}\n\t}\n\n\tunhook<TType extends keyof THooks>(\n\t\ttype: TType,\n\t\thookFn: THooks[TType][\"fn\"],\n\t): void {\n\t\tthis._registeredHooks[type] = this._registeredHooks[type]?.filter(\n\t\t\t(registeredHook) => registeredHook.fn !== hookFn,\n\t\t);\n\t}\n\n\tasync callHook<TType extends Extract<keyof THooks, string>>(\n\t\ttypeOrTypeAndHookID: TType | { type: TType; hookID: string },\n\t\t...args: Parameters<THooks[TType][\"fn\"]>\n\t): CallHookReturnType<THooks[TType][\"fn\"]> {\n\t\tlet hooks: RegisteredHook<THooks[TType]>[];\n\n\t\tif (typeof typeOrTypeAndHookID === \"string\") {\n\t\t\thooks = this._registeredHooks[typeOrTypeAndHookID] ?? [];\n\t\t} else {\n\t\t\tconst hookForID = this._registeredHooks[typeOrTypeAndHookID.type]?.find(\n\t\t\t\t(hook) => hook.meta.id === typeOrTypeAndHookID.hookID,\n\t\t\t);\n\n\t\t\tif (hookForID) {\n\t\t\t\thooks = [hookForID];\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Hook of type \\`${typeOrTypeAndHookID.type}\\` with ID \\`${typeOrTypeAndHookID.hookID}\\` not found.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst promises = hooks.map(async (hook) => {\n\t\t\ttry {\n\t\t\t\treturn await hook.fn(...args);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new HookError(hook.meta, error);\n\t\t\t}\n\t\t});\n\n\t\tconst settledPromises = await Promise.allSettled(promises);\n\n\t\treturn settledPromises.reduce<{\n\t\t\tdata: Awaited<ReturnType<THooks[TType][\"fn\"]>>[];\n\t\t\terrors: HookError[];\n\t\t}>(\n\t\t\t(acc, settledPromise) => {\n\t\t\t\tif (settledPromise.status === \"fulfilled\") {\n\t\t\t\t\tacc.data.push(settledPromise.value);\n\t\t\t\t} else {\n\t\t\t\t\tacc.errors.push(settledPromise.reason);\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{ data: [], errors: [] },\n\t\t);\n\t}\n\n\t/**\n\t * Returns list of hooks for a given owner\n\t */\n\thooksForOwner(owner: string): RegisteredHook<THooks[string]>[] {\n\t\tconst hooks: RegisteredHook<THooks[string]>[] = [];\n\n\t\tfor (const hookType in this._registeredHooks) {\n\t\t\tconst registeredHooks = this._registeredHooks[hookType];\n\n\t\t\tif (Array.isArray(registeredHooks)) {\n\t\t\t\tfor (const registeredHook of registeredHooks) {\n\t\t\t\t\tif (registeredHook.meta.owner === owner) {\n\t\t\t\t\t\thooks.push(registeredHook);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn hooks;\n\t}\n\n\t/**\n\t * Returns list of hooks for a given type\n\t */\n\thooksForType<TType extends keyof THooks>(\n\t\ttype: TType,\n\t): RegisteredHook<THooks[TType]>[] {\n\t\treturn this._registeredHooks[type] ?? [];\n\t}\n\n\tcreateScope<TExtraArgs extends unknown[] = never[]>(\n\t\towner: string,\n\t\textraArgs: [...TExtraArgs],\n\t): CreateScopeReturnType<THooks, TExtraArgs> {\n\t\treturn {\n\t\t\thook: (type, hookFn, ...[meta]) => {\n\t\t\t\tconst internalHook = ((\n\t\t\t\t\t...args: Parameters<THooks[typeof type][\"fn\"]>\n\t\t\t\t) => {\n\t\t\t\t\treturn hookFn(...args, ...extraArgs);\n\t\t\t\t}) as THooks[typeof type][\"fn\"];\n\n\t\t\t\tconst resolvedMeta = {\n\t\t\t\t\t...meta,\n\t\t\t\t\texternal: hookFn,\n\t\t\t\t} as HookMetaArg<THooks[typeof type][\"meta\"]>[0];\n\n\t\t\t\treturn this.hook(\n\t\t\t\t\towner,\n\t\t\t\t\ttype,\n\t\t\t\t\tinternalHook,\n\t\t\t\t\t// @ts-expect-error - TypeScript fails to assert rest argument.\n\t\t\t\t\tresolvedMeta,\n\t\t\t\t);\n\t\t\t},\n\t\t\tunhook: (type, hookFn) => {\n\t\t\t\tthis._registeredHooks[type] = this._registeredHooks[type]?.filter(\n\t\t\t\t\t(registeredHook) => registeredHook.meta.external !== hookFn,\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t}\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import * as z from "zod";
2
+ import { DecodeError } from "./DecodeError.js";
3
+ export type DecodeReturnType<A, _O, I> = {
4
+ value: A;
5
+ error?: never;
6
+ } | {
7
+ value?: never;
8
+ error: DecodeError<I>;
9
+ };
10
+ export declare const decode: <A, O, I>(codec: z.ZodType<A>, input: I) => DecodeReturnType<A, O, I>;
@@ -0,0 +1,16 @@
1
+ import { DecodeError } from "./DecodeError.js";
2
+ const decode = (codec, input) => {
3
+ const parsed = codec.safeParse(input);
4
+ if (parsed.success) {
5
+ return {
6
+ value: parsed.data
7
+ };
8
+ }
9
+ return {
10
+ error: new DecodeError({ input, errors: parsed.error.issues })
11
+ };
12
+ };
13
+ export {
14
+ decode
15
+ };
16
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sources":["../../../src/lib/decode.ts"],"sourcesContent":["import * as z from \"zod\";\n\nimport { DecodeError } from \"./DecodeError\";\n\nexport type DecodeReturnType<A, _O, I> =\n\t| {\n\t\t\tvalue: A;\n\t\t\terror?: never;\n\t }\n\t| {\n\t\t\tvalue?: never;\n\t\t\terror: DecodeError<I>;\n\t };\n\nexport const decode = <A, O, I>(\n\tcodec: z.ZodType<A>,\n\tinput: I,\n): DecodeReturnType<A, O, I> => {\n\tconst parsed = codec.safeParse(input);\n\n\tif (parsed.success) {\n\t\treturn {\n\t\t\tvalue: parsed.data,\n\t\t};\n\t}\n\n\treturn {\n\t\terror: new DecodeError({ input, errors: parsed.error.issues }),\n\t};\n};\n"],"names":[],"mappings":";AAcO,MAAM,SAAS,CACrB,OACA,UAC8B;AAC9B,QAAM,SAAS,MAAM,UAAU,KAAK;AAEpC,MAAI,OAAO,SAAS;AACnB,WAAO;AAAA,MACN,OAAO,OAAO;AAAA,IAAA;AAAA,EAEhB;AAEA,SAAO;AAAA,IACN,OAAO,IAAI,YAAY,EAAE,OAAO,QAAQ,OAAO,MAAM,OAAA,CAAQ;AAAA,EAAA;AAE/D;"}
@@ -0,0 +1,3 @@
1
+ import { PrismicConfig } from "../types.js";
2
+ import { DecodeReturnType } from "./decode.js";
3
+ export declare const decodePrismicConfig: (input: unknown) => DecodeReturnType<PrismicConfig, PrismicConfig, unknown>;
@@ -0,0 +1,22 @@
1
+ import * as z from "zod";
2
+ import { decode } from "./decode.js";
3
+ const PrismicConfigPluginRegistrationSchema = z.union([
4
+ z.string(),
5
+ z.object({
6
+ resolve: z.string(),
7
+ options: z.record(z.string(), z.unknown()).optional()
8
+ })
9
+ ]);
10
+ const PrismicConfigSchema = z.object({
11
+ repositoryName: z.string(),
12
+ adapter: PrismicConfigPluginRegistrationSchema,
13
+ apiEndpoint: z.string().optional(),
14
+ libraries: z.array(z.string()).optional()
15
+ });
16
+ const decodePrismicConfig = (input) => {
17
+ return decode(PrismicConfigSchema, input);
18
+ };
19
+ export {
20
+ decodePrismicConfig
21
+ };
22
+ //# sourceMappingURL=decodePrismicConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodePrismicConfig.js","sources":["../../../src/lib/decodePrismicConfig.ts"],"sourcesContent":["import * as z from \"zod\";\n\nimport { PrismicConfig } from \"../types\";\n\nimport { decode, DecodeReturnType } from \"./decode\";\n\nconst PrismicConfigPluginRegistrationSchema = z.union([\n\tz.string(),\n\tz.object({\n\t\tresolve: z.string(),\n\t\toptions: z.record(z.string(), z.unknown()).optional(),\n\t}),\n]);\n\nconst PrismicConfigSchema = z.object({\n\trepositoryName: z.string(),\n\tadapter: PrismicConfigPluginRegistrationSchema,\n\tapiEndpoint: z.string().optional(),\n\tlibraries: z.array(z.string()).optional(),\n});\n\nexport const decodePrismicConfig = (\n\tinput: unknown,\n): DecodeReturnType<PrismicConfig, PrismicConfig, unknown> => {\n\treturn decode(PrismicConfigSchema, input);\n};\n"],"names":[],"mappings":";;AAMA,MAAM,wCAAwC,EAAE,MAAM;AAAA,EACrD,EAAE,OAAA;AAAA,EACF,EAAE,OAAO;AAAA,IACR,SAAS,EAAE,OAAA;AAAA,IACX,SAAS,EAAE,OAAO,EAAE,OAAA,GAAU,EAAE,QAAA,CAAS,EAAE,SAAA;AAAA,EAAQ,CACnD;AACD,CAAA;AAED,MAAM,sBAAsB,EAAE,OAAO;AAAA,EACpC,gBAAgB,EAAE,OAAA;AAAA,EAClB,SAAS;AAAA,EACT,aAAa,EAAE,OAAA,EAAS,SAAA;AAAA,EACxB,WAAW,EAAE,MAAM,EAAE,OAAA,CAAQ,EAAE,SAAA;AAC/B,CAAA;AAEM,MAAM,sBAAsB,CAClC,UAC4D;AAC5D,SAAO,OAAO,qBAAqB,KAAK;AACzC;"}