@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
package/src/types.ts ADDED
@@ -0,0 +1,175 @@
1
+ import { PluginSystemContext } from "./createPluginSystemContext";
2
+ import { Plugin } from "./definePlugin";
3
+ import { CustomTypeCreateHookBase } from "./hooks/customType-create";
4
+ import { CustomTypeDeleteHookBase } from "./hooks/customType-delete";
5
+ import { CustomTypeReadHookBase } from "./hooks/customType-read";
6
+ import { CustomTypeRenameHookBase } from "./hooks/customType-rename";
7
+ import { CustomTypeUpdateHookBase } from "./hooks/customType-update";
8
+ import { CustomTypeLibraryReadHookBase } from "./hooks/customTypeLibrary-read";
9
+ import { DebugHookBase } from "./hooks/debug";
10
+ import { ProjectInitHookBase } from "./hooks/project-init";
11
+ import { SliceCreateHookBase } from "./hooks/slice-create";
12
+ import { SliceDeleteHookBase } from "./hooks/slice-delete";
13
+ import { SliceReadHookBase } from "./hooks/slice-read";
14
+ import { SliceRenameHookBase } from "./hooks/slice-rename";
15
+ import { SliceUpdateHookBase } from "./hooks/slice-update";
16
+ import { SliceLibraryReadHookBase } from "./hooks/sliceLibrary-read";
17
+ import { Hook } from "./lib/HookSystem";
18
+
19
+ /**
20
+ * A value optionally wrapped in a `PromiseLike`.
21
+ *
22
+ * @typeParam T - The value that can optionally be wrapped.
23
+ */
24
+ export type Promisable<T> = T | PromiseLike<T>;
25
+
26
+ /**
27
+ * A generic type for a user-provided plugin options. Prefer using a
28
+ * plugin-specific type over this type.
29
+ */
30
+ export type PluginOptions = Record<string, unknown>;
31
+
32
+ /**
33
+ * A string, object, or instance representing a registered plugin.
34
+ *
35
+ * @typeParam TPluginOptions - User-provided options for the plugin.
36
+ */
37
+ export type PrismicConfigPluginRegistration<
38
+ TPluginOptions extends PluginOptions = PluginOptions,
39
+ > =
40
+ | string
41
+ | Plugin
42
+ | {
43
+ resolve: string | Plugin;
44
+ options?: TPluginOptions;
45
+ };
46
+
47
+ /**
48
+ * Prismic configuration from `prismic.config.js`.
49
+ */
50
+ export type PrismicConfig = {
51
+ repositoryName: string;
52
+ adapter: PrismicConfigPluginRegistration;
53
+ libraries?: string[];
54
+ apiEndpoint?: string;
55
+ };
56
+
57
+ /**
58
+ * Prismic project metadata.
59
+ */
60
+ export type PrismicProject = {
61
+ /**
62
+ * An absolute path to project root.
63
+ */
64
+ root: string;
65
+ /**
66
+ * Prismic `prismic.config.json` content, validated.
67
+ */
68
+ config: PrismicConfig;
69
+ };
70
+
71
+ /**
72
+ * A Slice Library's metadata.
73
+ */
74
+ export type SliceLibrary = {
75
+ id: string;
76
+ };
77
+
78
+ // ============================================================================
79
+ //
80
+ // # HOOK TYPES
81
+ //
82
+ // ============================================================================
83
+
84
+ /**
85
+ * A hook handler.
86
+ */
87
+ export type PluginHook<TData, TReturn> = (data: TData) => Promisable<TReturn>;
88
+
89
+ /**
90
+ * Extra arguments provided to hooks when called.
91
+ *
92
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
93
+ */
94
+ export type PluginHookExtraArgs<
95
+ TPluginOptions extends PluginOptions = PluginOptions,
96
+ > = [context: PluginSystemContext<TPluginOptions>];
97
+
98
+ /**
99
+ * Utility type to extend a hook handler's type with Plugin System-specific
100
+ * extra arguments.
101
+ *
102
+ * @typeParam THook - Hook handler to extend.
103
+ * @typeParam TPluginOptions - User-provided options for the hook's plugin.
104
+ */
105
+ export type ExtendPluginSystemHook<
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ THook extends PluginHook<any, any>,
108
+ TPluginOptions extends PluginOptions = PluginOptions,
109
+ > = (
110
+ ...args: [
111
+ ...args: Parameters<THook>,
112
+ ...extraArgs: PluginHookExtraArgs<TPluginOptions>,
113
+ ]
114
+ ) => ReturnType<THook>;
115
+
116
+ /**
117
+ * Hook types.
118
+ */
119
+ export const PluginHookType = {
120
+ slice_create: "slice:create",
121
+ slice_update: "slice:update",
122
+ slice_rename: "slice:rename",
123
+ slice_delete: "slice:delete",
124
+ slice_read: "slice:read",
125
+ sliceLibrary_read: "slice-library:read",
126
+
127
+ customType_create: "custom-type:create",
128
+ customType_update: "custom-type:update",
129
+ customType_rename: "custom-type:rename",
130
+ customType_delete: "custom-type:delete",
131
+ customType_read: "custom-type:read",
132
+ customTypeLibrary_read: "custom-type-library:read",
133
+
134
+ snippet_read: "snippet:read",
135
+
136
+ project_init: "project:init",
137
+
138
+ debug: "debug",
139
+ } as const;
140
+
141
+ /**
142
+ * Hook types.
143
+ */
144
+ export type PluginHookTypes =
145
+ (typeof PluginHookType)[keyof typeof PluginHookType];
146
+
147
+ /**
148
+ * Plugin hook handlers.
149
+ */
150
+ export type PluginHooks = {
151
+ // Slices
152
+ [PluginHookType.slice_create]: Hook<SliceCreateHookBase>;
153
+ [PluginHookType.slice_update]: Hook<SliceUpdateHookBase>;
154
+ [PluginHookType.slice_rename]: Hook<SliceRenameHookBase>;
155
+ [PluginHookType.slice_delete]: Hook<SliceDeleteHookBase>;
156
+ [PluginHookType.slice_read]: Hook<SliceReadHookBase>;
157
+
158
+ // Slice Libraries
159
+ [PluginHookType.sliceLibrary_read]: Hook<SliceLibraryReadHookBase>;
160
+
161
+ // Custom Types
162
+ [PluginHookType.customType_create]: Hook<CustomTypeCreateHookBase>;
163
+ [PluginHookType.customType_update]: Hook<CustomTypeUpdateHookBase>;
164
+ [PluginHookType.customType_rename]: Hook<CustomTypeRenameHookBase>;
165
+ [PluginHookType.customType_delete]: Hook<CustomTypeDeleteHookBase>;
166
+ [PluginHookType.customType_read]: Hook<CustomTypeReadHookBase>;
167
+ // Custom Type Libraries
168
+ [PluginHookType.customTypeLibrary_read]: Hook<CustomTypeLibraryReadHookBase>;
169
+
170
+ // Project
171
+ [PluginHookType.project_init]: Hook<ProjectInitHookBase>;
172
+
173
+ // Debug
174
+ [PluginHookType.debug]: Hook<DebugHookBase>;
175
+ };