@takeshape/schema 7.194.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/README.md +5 -0
  2. package/es/api-version.js +21 -0
  3. package/es/auth-schemas.js +0 -0
  4. package/es/builtin-schema.js +590 -0
  5. package/es/content-schema-transform.js +192 -0
  6. package/es/entitlements.js +0 -0
  7. package/es/enum.js +11 -0
  8. package/es/get-is-leaf.js +58 -0
  9. package/es/index.js +25 -0
  10. package/es/migration.js +413 -0
  11. package/es/mocks.js +47 -0
  12. package/es/patterns.js +0 -0
  13. package/es/project-schema/index.js +10 -0
  14. package/es/project-schema/v1.0.0.js +0 -0
  15. package/es/project-schema/v3.0.0.js +0 -0
  16. package/es/project-schema/v3.1.0.js +0 -0
  17. package/es/project-schema/v3.2.0.js +0 -0
  18. package/es/project-schema/v3.3.0.js +0 -0
  19. package/es/project-schema/v3.4.0.js +0 -0
  20. package/es/project-schema/v3.5.0.js +0 -0
  21. package/es/project-schema/v3.5.1.js +0 -0
  22. package/es/project-schema/v3.6.0.js +0 -0
  23. package/es/refs.js +301 -0
  24. package/es/resolvers.js +2 -0
  25. package/es/scalars.js +4 -0
  26. package/es/schema-util.js +1197 -0
  27. package/es/schemas/auth-schemas.json +313 -0
  28. package/es/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
  29. package/es/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
  30. package/es/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
  31. package/es/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
  32. package/es/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
  33. package/es/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
  34. package/es/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
  35. package/es/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
  36. package/es/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
  37. package/es/schemas/project-schema/v1.0.0.json +321 -0
  38. package/es/schemas/project-schema/v3.0.0.json +411 -0
  39. package/es/schemas/project-schema/v3.1.0.json +569 -0
  40. package/es/schemas/project-schema/v3.2.0.json +577 -0
  41. package/es/schemas/project-schema/v3.3.0.json +578 -0
  42. package/es/schemas/project-schema/v3.4.0.json +568 -0
  43. package/es/schemas/project-schema/v3.5.0.json +568 -0
  44. package/es/schemas/project-schema/v3.5.1.json +568 -0
  45. package/es/schemas/project-schema/v3.6.0.json +584 -0
  46. package/es/schemas/project-schema.json +16 -0
  47. package/es/schemas/user-schema.json +58 -0
  48. package/es/services.js +379 -0
  49. package/es/taxonomies.js +55 -0
  50. package/es/template-shapes.js +79 -0
  51. package/es/types.js +202 -0
  52. package/es/unions.js +137 -0
  53. package/es/user-schema.js +0 -0
  54. package/es/util/detect-cycles.js +54 -0
  55. package/es/util/index.js +1 -0
  56. package/es/validate.js +764 -0
  57. package/es/versions.js +4 -0
  58. package/es/workflows.js +69 -0
  59. package/examples/.pnpm-debug.log +20 -0
  60. package/examples/v1_0_0/beer-schema.json +125 -0
  61. package/examples/v1_0_0/blog-schema.json +192 -0
  62. package/examples/v1_0_0/brewery-schema.json +232 -0
  63. package/examples/v1_0_0/complex-project-schema.json +3197 -0
  64. package/examples/v1_0_0/error-schema.json +275 -0
  65. package/examples/v1_0_0/frank-and-fred-schema.json +21387 -0
  66. package/examples/v1_0_0/massive-schema.json +6930 -0
  67. package/examples/v1_0_0/post-schema.json +83 -0
  68. package/examples/v1_0_0/real-world-schema.json +797 -0
  69. package/examples/v1_0_0/recursive-repeater-schema.json +69 -0
  70. package/examples/v1_0_0/recursive-schema.json +79 -0
  71. package/examples/v1_0_0/schema-with-repeater-draftjs.json +292 -0
  72. package/examples/v1_0_0/shape-books.json +797 -0
  73. package/examples/v1_0_0/user-schema-no-required.json +84 -0
  74. package/examples/v1_0_0/user-schema-with-defaults.json +105 -0
  75. package/examples/v1_0_0/user-schema-with-obj-prop.json +92 -0
  76. package/examples/v1_0_0/user-schema.json +87 -0
  77. package/examples/v3_0_0/rick-and-morty-rest.json +62 -0
  78. package/examples/v3_0_0/shopify-lookbook.json +1172 -0
  79. package/examples/v3_0_0/shopify-store-with-widget.json +11323 -0
  80. package/examples/v3_2_0/blog-schema.json +378 -0
  81. package/examples/v3_2_0/brewery-schema.json +385 -0
  82. package/examples/v3_2_0/complex-project-schema.json +3748 -0
  83. package/examples/v3_2_0/frank-and-fred-schema.json +19217 -0
  84. package/examples/v3_2_0/massive-schema.json +6676 -0
  85. package/examples/v3_2_0/pet-oneof-array.json +323 -0
  86. package/examples/v3_2_0/post-schema.json +265 -0
  87. package/examples/v3_2_0/real-world-schema.json +970 -0
  88. package/examples/v3_2_0/recursive-repeater-schema.json +144 -0
  89. package/examples/v3_2_0/recursive-schema.json +151 -0
  90. package/examples/v3_2_0/rick-and-morty-rest.json +65 -0
  91. package/examples/v3_2_0/schema-with-repeater-draftjs.json +381 -0
  92. package/examples/v3_2_0/shape-books.json +1044 -0
  93. package/examples/v3_2_0/shopify-store-with-widget.json +11016 -0
  94. package/examples/v3_2_0/user-schema-no-required.json +174 -0
  95. package/examples/v3_2_0/user-schema-with-defaults.json +187 -0
  96. package/examples/v3_3_0/blog-schema.json +405 -0
  97. package/examples/v3_3_0/brewery-schema.json +406 -0
  98. package/examples/v3_3_0/complex-project-schema.json +4076 -0
  99. package/examples/v3_3_0/frank-and-fred-schema.json +20913 -0
  100. package/examples/v3_3_0/massive-schema.json +7309 -0
  101. package/examples/v3_3_0/pet-oneof-array.json +380 -0
  102. package/examples/v3_3_0/post-schema.json +248 -0
  103. package/examples/v3_3_0/real-world-schema.json +1046 -0
  104. package/examples/v3_3_0/recursive-repeater-schema.json +154 -0
  105. package/examples/v3_3_0/recursive-schema.json +161 -0
  106. package/examples/v3_3_0/rick-and-morty-rest.json +101 -0
  107. package/examples/v3_3_0/schema-with-repeater-draftjs.json +393 -0
  108. package/examples/v3_3_0/shape-books.json +1121 -0
  109. package/examples/v3_3_0/shopify-lookbook.json +1196 -0
  110. package/examples/v3_3_0/shopify-store-with-widget.json +11320 -0
  111. package/examples/v3_3_0/user-schema-no-required.json +185 -0
  112. package/examples/v3_3_0/user-schema-with-defaults.json +210 -0
  113. package/examples/v3_4_0/blog-schema.json +405 -0
  114. package/examples/v3_4_0/brewery-schema.json +406 -0
  115. package/examples/v3_4_0/complex-project-schema.json +4076 -0
  116. package/examples/v3_4_0/frank-and-fred-schema.json +20913 -0
  117. package/examples/v3_4_0/massive-schema.json +7309 -0
  118. package/examples/v3_4_0/pet-oneof-array.json +420 -0
  119. package/examples/v3_4_0/post-schema.json +248 -0
  120. package/examples/v3_4_0/real-world-schema.json +1046 -0
  121. package/examples/v3_4_0/recursive-repeater-schema.json +154 -0
  122. package/examples/v3_4_0/recursive-schema.json +161 -0
  123. package/examples/v3_4_0/rick-and-morty-rest.json +101 -0
  124. package/examples/v3_4_0/schema-with-repeater-draftjs.json +393 -0
  125. package/examples/v3_4_0/shape-books.json +1121 -0
  126. package/examples/v3_4_0/shopify-lookbook.json +1196 -0
  127. package/examples/v3_4_0/shopify-store-with-widget.json +11323 -0
  128. package/examples/v3_4_0/user-schema-no-required.json +185 -0
  129. package/examples/v3_4_0/user-schema-with-defaults.json +210 -0
  130. package/examples/v3_5_0/blog-schema.json +405 -0
  131. package/examples/v3_5_0/brewery-schema.json +406 -0
  132. package/examples/v3_5_0/complex-project-schema.json +4076 -0
  133. package/examples/v3_5_0/frank-and-fred-schema.json +20913 -0
  134. package/examples/v3_5_0/massive-schema.json +7309 -0
  135. package/examples/v3_5_0/pet-oneof-array.json +420 -0
  136. package/examples/v3_5_0/post-schema.json +248 -0
  137. package/examples/v3_5_0/real-world-schema.json +1046 -0
  138. package/examples/v3_5_0/recursive-repeater-schema.json +154 -0
  139. package/examples/v3_5_0/recursive-schema.json +161 -0
  140. package/examples/v3_5_0/rick-and-morty-rest.json +101 -0
  141. package/examples/v3_5_0/schema-with-repeater-draftjs.json +393 -0
  142. package/examples/v3_5_0/shape-books.json +1121 -0
  143. package/examples/v3_5_0/shopify-lookbook.json +1196 -0
  144. package/examples/v3_5_0/shopify-store-with-widget.json +12271 -0
  145. package/examples/v3_5_0/user-schema-no-required.json +185 -0
  146. package/examples/v3_5_0/user-schema-with-defaults.json +210 -0
  147. package/examples/v3_5_1/blog-schema.json +405 -0
  148. package/examples/v3_5_1/brewery-schema.json +406 -0
  149. package/examples/v3_5_1/complex-project-schema.json +4076 -0
  150. package/examples/v3_5_1/frank-and-fred-schema.json +20913 -0
  151. package/examples/v3_5_1/massive-schema.json +7309 -0
  152. package/examples/v3_5_1/pet-oneof-array.json +420 -0
  153. package/examples/v3_5_1/post-schema.json +248 -0
  154. package/examples/v3_5_1/real-world-schema.json +1046 -0
  155. package/examples/v3_5_1/recursive-repeater-schema.json +154 -0
  156. package/examples/v3_5_1/recursive-schema.json +161 -0
  157. package/examples/v3_5_1/rick-and-morty-rest.json +101 -0
  158. package/examples/v3_5_1/schema-with-repeater-draftjs.json +393 -0
  159. package/examples/v3_5_1/shape-books.json +1121 -0
  160. package/examples/v3_5_1/shopify-lookbook.json +1196 -0
  161. package/examples/v3_5_1/shopify-store-with-widget.json +12271 -0
  162. package/examples/v3_5_1/stripe-starter-resolved.json +21419 -0
  163. package/examples/v3_5_1/user-schema-no-required.json +185 -0
  164. package/examples/v3_5_1/user-schema-with-defaults.json +210 -0
  165. package/examples/v3_6_0/blog-schema.json +405 -0
  166. package/examples/v3_6_0/brewery-schema.json +406 -0
  167. package/examples/v3_6_0/complex-project-schema.json +4076 -0
  168. package/examples/v3_6_0/frank-and-fred-schema.json +20913 -0
  169. package/examples/v3_6_0/massive-schema.json +7309 -0
  170. package/examples/v3_6_0/pet-oneof-array.json +420 -0
  171. package/examples/v3_6_0/post-schema.json +248 -0
  172. package/examples/v3_6_0/real-world-schema.json +1046 -0
  173. package/examples/v3_6_0/recursive-repeater-schema.json +154 -0
  174. package/examples/v3_6_0/recursive-schema.json +161 -0
  175. package/examples/v3_6_0/rick-and-morty-rest.json +101 -0
  176. package/examples/v3_6_0/schema-with-repeater-draftjs.json +393 -0
  177. package/examples/v3_6_0/shape-books.json +1121 -0
  178. package/examples/v3_6_0/shopify-lookbook.json +1196 -0
  179. package/examples/v3_6_0/shopify-store-with-widget.json +12271 -0
  180. package/examples/v3_6_0/stripe-starter-resolved.json +21419 -0
  181. package/examples/v3_6_0/user-schema-no-required.json +185 -0
  182. package/examples/v3_6_0/user-schema-with-defaults.json +210 -0
  183. package/lib/api-version.d.ts +6 -0
  184. package/lib/api-version.d.ts.map +1 -0
  185. package/lib/api-version.js +36 -0
  186. package/lib/auth-schemas.d.ts +105 -0
  187. package/lib/auth-schemas.d.ts.map +1 -0
  188. package/lib/auth-schemas.js +1 -0
  189. package/lib/builtin-schema.d.ts +8 -0
  190. package/lib/builtin-schema.d.ts.map +1 -0
  191. package/lib/builtin-schema.js +606 -0
  192. package/lib/content-schema-transform.d.ts +41 -0
  193. package/lib/content-schema-transform.d.ts.map +1 -0
  194. package/lib/content-schema-transform.js +217 -0
  195. package/lib/entitlements.d.ts +1 -0
  196. package/lib/entitlements.d.ts.map +1 -0
  197. package/lib/entitlements.js +1 -0
  198. package/lib/enum.d.ts +3 -0
  199. package/lib/enum.d.ts.map +1 -0
  200. package/lib/enum.js +18 -0
  201. package/lib/get-is-leaf.d.ts +4 -0
  202. package/lib/get-is-leaf.d.ts.map +1 -0
  203. package/lib/get-is-leaf.js +68 -0
  204. package/lib/index.d.ts +27 -0
  205. package/lib/index.d.ts.map +1 -0
  206. package/lib/index.js +359 -0
  207. package/lib/migration.d.ts +55 -0
  208. package/lib/migration.d.ts.map +1 -0
  209. package/lib/migration.js +463 -0
  210. package/lib/mocks.d.ts +13 -0
  211. package/lib/mocks.d.ts.map +1 -0
  212. package/lib/mocks.js +61 -0
  213. package/lib/patterns.d.ts +13 -0
  214. package/lib/patterns.d.ts.map +1 -0
  215. package/lib/patterns.js +1 -0
  216. package/lib/project-schema/index.d.ts +21 -0
  217. package/lib/project-schema/index.d.ts.map +1 -0
  218. package/lib/project-schema/index.js +122 -0
  219. package/lib/project-schema/v1.0.0.d.ts +293 -0
  220. package/lib/project-schema/v1.0.0.d.ts.map +1 -0
  221. package/lib/project-schema/v1.0.0.js +1 -0
  222. package/lib/project-schema/v3.0.0.d.ts +480 -0
  223. package/lib/project-schema/v3.0.0.d.ts.map +1 -0
  224. package/lib/project-schema/v3.0.0.js +1 -0
  225. package/lib/project-schema/v3.1.0.d.ts +623 -0
  226. package/lib/project-schema/v3.1.0.d.ts.map +1 -0
  227. package/lib/project-schema/v3.1.0.js +1 -0
  228. package/lib/project-schema/v3.2.0.d.ts +634 -0
  229. package/lib/project-schema/v3.2.0.d.ts.map +1 -0
  230. package/lib/project-schema/v3.2.0.js +1 -0
  231. package/lib/project-schema/v3.3.0.d.ts +634 -0
  232. package/lib/project-schema/v3.3.0.d.ts.map +1 -0
  233. package/lib/project-schema/v3.3.0.js +1 -0
  234. package/lib/project-schema/v3.4.0.d.ts +626 -0
  235. package/lib/project-schema/v3.4.0.d.ts.map +1 -0
  236. package/lib/project-schema/v3.4.0.js +1 -0
  237. package/lib/project-schema/v3.5.0.d.ts +651 -0
  238. package/lib/project-schema/v3.5.0.d.ts.map +1 -0
  239. package/lib/project-schema/v3.5.0.js +1 -0
  240. package/lib/project-schema/v3.5.1.d.ts +651 -0
  241. package/lib/project-schema/v3.5.1.d.ts.map +1 -0
  242. package/lib/project-schema/v3.5.1.js +1 -0
  243. package/lib/project-schema/v3.6.0.d.ts +660 -0
  244. package/lib/project-schema/v3.6.0.d.ts.map +1 -0
  245. package/lib/project-schema/v3.6.0.js +1 -0
  246. package/lib/refs.d.ts +122 -0
  247. package/lib/refs.d.ts.map +1 -0
  248. package/lib/refs.js +359 -0
  249. package/lib/resolvers.d.ts +4 -0
  250. package/lib/resolvers.d.ts.map +1 -0
  251. package/lib/resolvers.js +10 -0
  252. package/lib/scalars.d.ts +3 -0
  253. package/lib/scalars.d.ts.map +1 -0
  254. package/lib/scalars.js +13 -0
  255. package/lib/schema-util.d.ts +201 -0
  256. package/lib/schema-util.d.ts.map +1 -0
  257. package/lib/schema-util.js +1353 -0
  258. package/lib/schemas/auth-schemas.json +313 -0
  259. package/lib/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
  260. package/lib/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
  261. package/lib/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
  262. package/lib/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
  263. package/lib/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
  264. package/lib/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
  265. package/lib/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
  266. package/lib/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
  267. package/lib/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
  268. package/lib/schemas/project-schema/v1.0.0.json +321 -0
  269. package/lib/schemas/project-schema/v3.0.0.json +411 -0
  270. package/lib/schemas/project-schema/v3.1.0.json +569 -0
  271. package/lib/schemas/project-schema/v3.2.0.json +577 -0
  272. package/lib/schemas/project-schema/v3.3.0.json +578 -0
  273. package/lib/schemas/project-schema/v3.4.0.json +568 -0
  274. package/lib/schemas/project-schema/v3.5.0.json +568 -0
  275. package/lib/schemas/project-schema/v3.5.1.json +568 -0
  276. package/lib/schemas/project-schema/v3.6.0.json +584 -0
  277. package/lib/schemas/project-schema.json +16 -0
  278. package/lib/schemas/user-schema.json +58 -0
  279. package/lib/services.d.ts +71 -0
  280. package/lib/services.d.ts.map +1 -0
  281. package/lib/services.js +413 -0
  282. package/lib/taxonomies.d.ts +16 -0
  283. package/lib/taxonomies.d.ts.map +1 -0
  284. package/lib/taxonomies.js +69 -0
  285. package/lib/template-shapes.d.ts +32 -0
  286. package/lib/template-shapes.d.ts.map +1 -0
  287. package/lib/template-shapes.js +100 -0
  288. package/lib/types.d.ts +187 -0
  289. package/lib/types.d.ts.map +1 -0
  290. package/lib/types.js +289 -0
  291. package/lib/unions.d.ts +29 -0
  292. package/lib/unions.d.ts.map +1 -0
  293. package/lib/unions.js +167 -0
  294. package/lib/user-schema.d.ts +39 -0
  295. package/lib/user-schema.d.ts.map +1 -0
  296. package/lib/user-schema.js +1 -0
  297. package/lib/util/detect-cycles.d.ts +6 -0
  298. package/lib/util/detect-cycles.d.ts.map +1 -0
  299. package/lib/util/detect-cycles.js +61 -0
  300. package/lib/util/index.d.ts +2 -0
  301. package/lib/util/index.d.ts.map +1 -0
  302. package/lib/util/index.js +18 -0
  303. package/lib/validate.d.ts +49 -0
  304. package/lib/validate.d.ts.map +1 -0
  305. package/lib/validate.js +823 -0
  306. package/lib/versions.d.ts +5 -0
  307. package/lib/versions.d.ts.map +1 -0
  308. package/lib/versions.js +14 -0
  309. package/lib/workflows.d.ts +15 -0
  310. package/lib/workflows.d.ts.map +1 -0
  311. package/lib/workflows.js +92 -0
  312. package/package.json +65 -0
@@ -0,0 +1,823 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addProjectSchemasToAjv = addProjectSchemasToAjv;
7
+ exports.formatError = formatError;
8
+ exports.validateSchema = validateSchema;
9
+ exports.ensureValidV3Schema = ensureValidV3Schema;
10
+ exports.ensureValidLatestSchema = ensureValidLatestSchema;
11
+ exports.validateRoleInput = validateRoleInput;
12
+ exports.validateRoleImport = validateRoleImport;
13
+ exports.validateProjectSchemaImport = validateProjectSchemaImport;
14
+
15
+ var _jsonSchema = require("@takeshape/json-schema");
16
+
17
+ var _errors = require("@takeshape/errors");
18
+
19
+ var _coerce3 = _interopRequireDefault(require("semver/functions/coerce"));
20
+
21
+ var _eq = _interopRequireDefault(require("semver/functions/eq"));
22
+
23
+ var _neq = _interopRequireDefault(require("semver/functions/neq"));
24
+
25
+ var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
26
+
27
+ var _versions = require("./versions");
28
+
29
+ var _workflows = require("./workflows");
30
+
31
+ var _v = _interopRequireDefault(require("./schemas/project-schema/v1.0.0.json"));
32
+
33
+ var _v2 = _interopRequireDefault(require("./schemas/project-schema/v3.0.0.json"));
34
+
35
+ var _v3 = _interopRequireDefault(require("./schemas/project-schema/v3.1.0.json"));
36
+
37
+ var _v4 = _interopRequireDefault(require("./schemas/project-schema/v3.2.0.json"));
38
+
39
+ var _v5 = _interopRequireDefault(require("./schemas/project-schema/v3.3.0.json"));
40
+
41
+ var _v6 = _interopRequireDefault(require("./schemas/project-schema/v3.4.0.json"));
42
+
43
+ var _v7 = _interopRequireDefault(require("./schemas/project-schema/v3.5.0.json"));
44
+
45
+ var _v8 = _interopRequireDefault(require("./schemas/project-schema/v3.5.1.json"));
46
+
47
+ var _v9 = _interopRequireDefault(require("./schemas/project-schema/v3.6.0.json"));
48
+
49
+ var _metaSchemaV = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v1.0.0.json"));
50
+
51
+ var _metaSchemaV2 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.0.0.json"));
52
+
53
+ var _metaSchemaV3 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.1.0.json"));
54
+
55
+ var _metaSchemaV4 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.2.0.json"));
56
+
57
+ var _metaSchemaV5 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.3.0.json"));
58
+
59
+ var _metaSchemaV6 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.4.0.json"));
60
+
61
+ var _metaSchemaV7 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.5.0.json"));
62
+
63
+ var _metaSchemaV8 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.5.1.json"));
64
+
65
+ var _metaSchemaV9 = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.6.0.json"));
66
+
67
+ var _authSchemas = _interopRequireDefault(require("./schemas/auth-schemas.json"));
68
+
69
+ var _resolvers = require("./resolvers");
70
+
71
+ var _schemaUtil = require("./schema-util");
72
+
73
+ var _builtinSchema = require("./builtin-schema");
74
+
75
+ var _templateShapes = require("./template-shapes");
76
+
77
+ var _types = require("./types");
78
+
79
+ var _refs = require("./refs");
80
+
81
+ var _scalars = require("./scalars");
82
+
83
+ var _unions = require("./unions");
84
+
85
+ var _enum = require("./enum");
86
+
87
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88
+
89
+ function findDuplicates(items) {
90
+ const seen = {};
91
+
92
+ for (let item of items) {
93
+ if (seen[item.value]) {
94
+ seen[item.value].push(item.path);
95
+ } else {
96
+ seen[item.value] = [item.path];
97
+ }
98
+ }
99
+
100
+ return Object.entries(seen).filter(entry => entry[1].length > 1).flatMap(entry => ({
101
+ value: entry[0],
102
+ paths: entry[1]
103
+ }));
104
+ }
105
+
106
+ function checkContentTypeNames(contentTypes) {
107
+ const items = Object.entries(contentTypes).map(entry => ({
108
+ path: ['contentType', entry[0], 'name'],
109
+ value: entry[1].name.toLowerCase()
110
+ }));
111
+ return findDuplicates(items).flatMap(dupe => dupe.paths.map(path => ({
112
+ path,
113
+ type: 'conflict',
114
+ message: `Content types must have unique names. "${dupe.value}" is not unique.`
115
+ })));
116
+ }
117
+
118
+ function checkShapeIds(shapes) {
119
+ const items = Object.entries(shapes).map(entry => ({
120
+ path: ['shapes', entry[0], 'id'],
121
+ value: entry[1].id
122
+ }));
123
+ return findDuplicates(items).flatMap(dupe => dupe.paths.map(path => ({
124
+ path,
125
+ type: 'conflict',
126
+ message: `Shapes must have unique ids. "${dupe.value}" is not unique.`
127
+ })));
128
+ }
129
+
130
+ function checkShapeNames(shapes) {
131
+ Object.entries(shapes).map(entry => ({
132
+ path: ['shapes', entry[0], 'id'],
133
+ value: entry[1].id
134
+ }));
135
+ return Object.entries(shapes).filter(([name, shape]) => name !== shape.name).map(([name, shape]) => ({
136
+ path: ['shapes', name, 'name'],
137
+ type: 'conflict',
138
+ message: `Shape.name "${shape.name}" must match key "${name}".`
139
+ }));
140
+ }
141
+
142
+ function checkWorkflowStepNames(workflows) {
143
+ return Object.entries(workflows).flatMap(([name, workflow]) => {
144
+ const items = workflow.steps.map((step, i) => ({
145
+ path: ['workflows', name, 'steps', i, 'name'],
146
+ value: step.name.toLowerCase()
147
+ }));
148
+ return findDuplicates(items).flatMap(dupe => dupe.paths.map(path => ({
149
+ path,
150
+ type: 'conflict',
151
+ message: `Workflow steps must have unique names. "${dupe.value}" is not unique in workflow "${workflow.name}."`
152
+ })));
153
+ });
154
+ }
155
+
156
+ function checkWorkflowStepKeys(workflows) {
157
+ const items = Object.entries(workflows).flatMap(([name, workflow]) => workflow.steps.map((step, i) => ({
158
+ path: ['workflows', name, 'steps', i, 'key'],
159
+ value: step.key
160
+ })));
161
+ return findDuplicates(items).flatMap(dupe => dupe.paths.map(path => ({
162
+ path,
163
+ type: 'conflict',
164
+ message: `Workflow keys must be unique at the schema level. Key "${dupe.value}" is not unique.`
165
+ })));
166
+ }
167
+
168
+ function validateWorkflowVersion(projectSchema) {
169
+ const errors = [];
170
+
171
+ if (projectSchema.apiVersion === _versions.LEGACY_API_VERSION && Object.keys(projectSchema.workflows).length) {
172
+ errors.push({
173
+ path: ['workflows'],
174
+ type: 'invalidVersion',
175
+ message: `apiVersion ${projectSchema.apiVersion} does not support workflows`
176
+ });
177
+ }
178
+
179
+ return errors;
180
+ }
181
+
182
+ function validateWorkflowsV1(projectSchema) {
183
+ const errors = validateWorkflowVersion(projectSchema);
184
+
185
+ for (const key of Object.keys(projectSchema.contentTypes)) {
186
+ const contentType = projectSchema.contentTypes[key];
187
+
188
+ if (contentType.workflow && contentType.workflow !== _workflows.defaultWorkflow.name && !projectSchema.workflows[contentType.workflow]) {
189
+ errors.push({
190
+ type: 'notFound',
191
+ path: ['contentTypes', key, 'workflow'],
192
+ message: `Invalid Workflow "${contentType.workflow}" for content type "${contentType.name}"`
193
+ });
194
+ }
195
+ }
196
+
197
+ return errors;
198
+ }
199
+
200
+ function validateWorkflowsV3(projectSchema) {
201
+ const errors = validateWorkflowVersion(projectSchema);
202
+
203
+ for (const name of Object.keys(projectSchema.shapes)) {
204
+ const shape = projectSchema.shapes[name];
205
+
206
+ if (shape.workflow && shape.workflow !== _workflows.defaultWorkflow.name && !projectSchema.workflows[shape.workflow]) {
207
+ errors.push({
208
+ type: 'notFound',
209
+ path: ['shapes', name, 'workflow'],
210
+ message: `Invalid Workflow "${shape.workflow}" for shape "${shape.name}"`
211
+ });
212
+ }
213
+ }
214
+
215
+ return errors;
216
+ }
217
+
218
+ function validateResolver(projectSchema, basePath, resolver) {
219
+ const errors = [];
220
+
221
+ const validateBasicResolver = resolver => {
222
+ var _projectSchema$servic;
223
+
224
+ if (resolver.service !== 'takeshape:local' && !((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[resolver.service])) {
225
+ errors.push({
226
+ type: 'notFound',
227
+ path: basePath.concat(['service']),
228
+ message: `Invalid service "${resolver.service}"`
229
+ });
230
+ }
231
+
232
+ if (!_resolvers.resolverList.includes(resolver.name)) {
233
+ errors.push({
234
+ type: 'notFound',
235
+ path: basePath.concat(['name']),
236
+ message: `Invalid resolver name "${resolver.name}"`
237
+ });
238
+ }
239
+
240
+ if (_resolvers.modelResolvers.includes(resolver.name)) {
241
+ var _resolver$options;
242
+
243
+ const modelShape = (_resolver$options = resolver.options) !== null && _resolver$options !== void 0 && _resolver$options.model ? projectSchema.shapes[resolver.options.model] : undefined;
244
+
245
+ if (!(modelShape !== null && modelShape !== void 0 && modelShape.model)) {
246
+ var _resolver$options$mod, _resolver$options2;
247
+
248
+ errors.push({
249
+ type: 'notFound',
250
+ path: basePath.concat(['options', 'model']),
251
+ message: `Invalid Model Shape "${(_resolver$options$mod = (_resolver$options2 = resolver.options) === null || _resolver$options2 === void 0 ? void 0 : _resolver$options2.model) !== null && _resolver$options$mod !== void 0 ? _resolver$options$mod : ''}"`
252
+ });
253
+ }
254
+ }
255
+ };
256
+
257
+ if ((0, _types.isComposeResolver)(resolver)) {
258
+ resolver.compose.forEach(validateBasicResolver);
259
+ } else {
260
+ validateBasicResolver(resolver);
261
+ }
262
+
263
+ return errors;
264
+ } // eslint-disable-next-line max-params
265
+
266
+
267
+ function validateQueryConfig(projectSchema, validReturnShapes, operation, type, name) {
268
+ const location = type === 'query' ? 'queries' : 'mutations';
269
+ const errors = validateResolver(projectSchema, [location, name, 'resolver'], operation.resolver);
270
+ const {
271
+ template,
272
+ shapeName
273
+ } = (0, _templateShapes.parseReturnShape)(projectSchema, operation.shape);
274
+
275
+ if (template && !(0, _templateShapes.isValidTemplate)(template)) {
276
+ errors.push({
277
+ type: 'notFound',
278
+ path: [location, name, 'shape'],
279
+ message: `Invalid template "${template}" for ${type} "${name}"`
280
+ });
281
+ }
282
+
283
+ if (!validReturnShapes.has(shapeName)) {
284
+ errors.push({
285
+ type: 'notFound',
286
+ path: [location, name, 'shape'],
287
+ message: `Invalid shape "${shapeName}" for ${type} "${name}"`
288
+ });
289
+ }
290
+
291
+ return errors;
292
+ }
293
+
294
+ function validateQueryConfigs(projectSchema, additionalShapeNames = builtInShapeNames) {
295
+ const validReturnShapes = new Set(Object.keys(projectSchema.shapes).concat(additionalShapeNames));
296
+ let errors = [];
297
+
298
+ for (const name of Object.keys(projectSchema.queries)) {
299
+ errors = errors.concat(validateQueryConfig(projectSchema, validReturnShapes, projectSchema.queries[name], 'query', name));
300
+ }
301
+
302
+ for (const name of Object.keys(projectSchema.mutations)) {
303
+ errors = errors.concat(validateQueryConfig(projectSchema, validReturnShapes, projectSchema.mutations[name], 'mutation', name));
304
+ }
305
+
306
+ return errors;
307
+ }
308
+
309
+ const builtInShapeNames = [...Object.keys(_builtinSchema.builtInShapes), ..._scalars.scalars];
310
+
311
+ function getModelShapeIds(shapes) {
312
+ return Object.values(shapes).filter(shape => shape.model).map(shape => shape.id);
313
+ }
314
+
315
+ const builtInModelShapeIds = getModelShapeIds(_builtinSchema.builtInShapes);
316
+
317
+ function isNumberLike(value) {
318
+ if (typeof value === 'number') {
319
+ return true;
320
+ }
321
+
322
+ return /^\d+$/.test(value);
323
+ }
324
+ /**
325
+ * Verify the path has an allOf schema and not just prop named "allOf"
326
+ */
327
+
328
+
329
+ function isAllOfPath(path) {
330
+ const index = path.indexOf('allOf');
331
+ return index !== -1 && isNumberLike(path[index + 1]);
332
+ }
333
+
334
+ function validateRefs(projectSchema, additionalShapeNames = builtInShapeNames) {
335
+ const errors = [];
336
+ const shapeNames = new Set([...additionalShapeNames, ...Object.keys(projectSchema.shapes)]);
337
+ const refs = (0, _schemaUtil.getAllRefsInShapes)(projectSchema);
338
+
339
+ if (refs.length > 0) {
340
+ refs.forEach(item => {
341
+ const shapeName = (0, _refs.refItemToShapeName)(item);
342
+
343
+ if (!shapeNames.has(shapeName)) {
344
+ errors.push({
345
+ type: 'notFound',
346
+ path: item.path,
347
+ message: `Invalid ref "${(0, _refs.refItemToAtRef)(item)}"`
348
+ });
349
+ } // Make sure refs inside allOf don't refer to their own Shape
350
+
351
+
352
+ if (item.path[1] === shapeName && isAllOfPath(item.path)) {
353
+ errors.push({
354
+ type: 'conflict',
355
+ path: item.path,
356
+ message: `allOf cannot be self-referential`
357
+ });
358
+ }
359
+ });
360
+ }
361
+
362
+ return errors;
363
+ }
364
+
365
+ function validateDirectives(projectSchema, additionalShapeIds = builtInModelShapeIds) {
366
+ const errors = [];
367
+ const projectShapeIds = new Set([...getModelShapeIds(projectSchema.shapes), ...additionalShapeIds]);
368
+ (0, _schemaUtil.visitShapeProperties)(projectSchema.shapes, (schema, path) => {
369
+ if (schema['@relationship']) {
370
+ var _schema$Relationship;
371
+
372
+ const shapeIds = (_schema$Relationship = schema['@relationship']) === null || _schema$Relationship === void 0 ? void 0 : _schema$Relationship.shapeIds;
373
+ shapeIds.forEach(shapeId => {
374
+ if (!projectShapeIds.has(shapeId)) {
375
+ const propPath = path.concat('@relationship');
376
+ errors.push({
377
+ type: 'notFound',
378
+ path: propPath,
379
+ message: `Invalid shapeId relationship "${shapeId}" for property "${propPath[4]}" in shape "${propPath[1]}"`
380
+ });
381
+ }
382
+ });
383
+ }
384
+
385
+ if (schema['@resolver']) {
386
+ const resolver = schema['@resolver'];
387
+ const propPath = path.concat('@resolver');
388
+ const resolverErrors = validateResolver(projectSchema, propPath, resolver);
389
+
390
+ if (resolverErrors) {
391
+ errors.push(...resolverErrors);
392
+ }
393
+ }
394
+ });
395
+ return errors;
396
+ }
397
+
398
+ function validateOneOfs(projectSchema) {
399
+ const errors = [];
400
+ (0, _schemaUtil.visitShapeProperties)(projectSchema.shapes, (schema, path) => {
401
+ const oneOfPath = schema.items ? ['items', 'oneOf'] : ['oneOf'];
402
+ schema = schema.items ? schema.items : schema;
403
+
404
+ if (schema.oneOf) {
405
+ if ((0, _unions.isUnionSchema)(schema)) {
406
+ const modelsReferenced = (0, _unions.enumerateOneOfKeys)(projectSchema, schema.oneOf).map(child => child.shapeName).filter(shapeName => projectSchema.shapes[shapeName].model);
407
+
408
+ if (modelsReferenced.length) {
409
+ const shapeNames = modelsReferenced.join(', ');
410
+ errors.push({
411
+ type: 'json',
412
+ path: path.concat(oneOfPath),
413
+ message: `Invalid refs to ${shapeNames}. oneOf unions cannot reference model shapes. Use @relationship instead`
414
+ });
415
+ }
416
+ } else if (!(0, _enum.isEnumSchema)(schema)) {
417
+ errors.push({
418
+ type: 'json',
419
+ path: path.concat(oneOfPath),
420
+ message: `Invalid oneOf must contain only @ref or title + enum/const schemas`
421
+ });
422
+ }
423
+ }
424
+ });
425
+ return errors;
426
+ }
427
+
428
+ function validateLocales(projectSchema) {
429
+ const {
430
+ locales,
431
+ defaultLocale
432
+ } = projectSchema;
433
+ const errors = [];
434
+
435
+ if (!locales.includes(defaultLocale)) {
436
+ errors.push({
437
+ type: 'notFound',
438
+ path: ['locales'],
439
+ message: `Default locale "${defaultLocale}" missing from locales`
440
+ });
441
+ }
442
+
443
+ return errors;
444
+ }
445
+
446
+ function addProjectSchemasToAjv(ajv) {
447
+ ajv.addSchema(_metaSchemaV.default);
448
+ ajv.addSchema(_v.default);
449
+ ajv.addSchema(_metaSchemaV2.default);
450
+ ajv.addSchema(_v2.default);
451
+ ajv.addSchema(_metaSchemaV3.default);
452
+ ajv.addSchema(_v3.default);
453
+ ajv.addSchema(_metaSchemaV4.default);
454
+ ajv.addSchema(_v4.default);
455
+ ajv.addSchema(_metaSchemaV5.default);
456
+ ajv.addSchema(_v5.default);
457
+ ajv.addSchema(_metaSchemaV6.default);
458
+ ajv.addSchema(_v6.default);
459
+ ajv.addSchema(_metaSchemaV7.default);
460
+ ajv.addSchema(_v7.default);
461
+ ajv.addSchema(_metaSchemaV8.default);
462
+ ajv.addSchema(_v8.default);
463
+ ajv.addSchema(_metaSchemaV9.default);
464
+ ajv.addSchema(_v9.default);
465
+ return ajv;
466
+ }
467
+
468
+ const bracketRegex = /\['|']\./g;
469
+
470
+ function formatError(error) {
471
+ var _error$message;
472
+
473
+ let pathStr = error.dataPath;
474
+ let message = (_error$message = error.message) !== null && _error$message !== void 0 ? _error$message : '';
475
+
476
+ if ('missingProperty' in error.params) {
477
+ pathStr = `${pathStr}.${error.params.missingProperty}`;
478
+ }
479
+
480
+ if ('additionalProperty' in error.params) {
481
+ pathStr = `${pathStr}.${error.params.additionalProperty}`;
482
+ message = `${message} "${error.params.additionalProperty}"`;
483
+ }
484
+
485
+ const path = pathStr === '' ? [] : pathStr.substr(1).replace(bracketRegex, '.').split('.');
486
+ return {
487
+ type: 'json',
488
+ message,
489
+ path
490
+ };
491
+ }
492
+
493
+ const ajv = (0, _jsonSchema.createAjv)();
494
+ addProjectSchemasToAjv(ajv);
495
+
496
+ function validateV3X(schemaId, schema, options) {
497
+ const valid = ajv.validate(schemaId, schema);
498
+
499
+ if (!valid && ajv.errors) {
500
+ return {
501
+ valid: false,
502
+ schema: undefined,
503
+ errors: ajv.errors.map(formatError)
504
+ };
505
+ }
506
+
507
+ let errors = [];
508
+ const namespaceShapes = (0, _schemaUtil.getAllNamespaceShapes)(schema);
509
+ const additionalShapeNames = (options !== null && options !== void 0 && options.additionalShapeNames ? builtInShapeNames.concat(options.additionalShapeNames) : builtInShapeNames).concat(namespaceShapes);
510
+ const additionalModelShapeIds = options !== null && options !== void 0 && options.additionalModelShapeIds ? builtInModelShapeIds.concat(options.additionalModelShapeIds) : builtInModelShapeIds;
511
+ errors = errors.concat(checkShapeNames(schema.shapes)).concat(checkShapeIds(schema.shapes)).concat(validateWorkflowsV3(schema)).concat(validateQueryConfigs(schema, additionalShapeNames)).concat(validateRefs(schema, additionalShapeNames)).concat(validateDirectives(schema, additionalModelShapeIds)).concat(validateLocales(schema)).concat(checkWorkflowStepNames(schema.workflows)).concat(checkWorkflowStepKeys(schema.workflows)).concat(validateOneOfs(schema));
512
+ return errors.length ? {
513
+ valid: false,
514
+ schema: undefined,
515
+ errors
516
+ } : {
517
+ valid: true,
518
+ schema: schema,
519
+ errors: undefined
520
+ };
521
+ }
522
+
523
+ const validators = [{
524
+ version: '1',
525
+ schemaId: _v.default.$id,
526
+
527
+ validate(schema) {
528
+ const schemaV1 = schema;
529
+ const valid = ajv.validate(this.schemaId, schemaV1);
530
+
531
+ if (!valid && ajv.errors) {
532
+ return {
533
+ valid: false,
534
+ schema: undefined,
535
+ errors: ajv.errors.map(formatError)
536
+ };
537
+ }
538
+
539
+ let errors = [];
540
+ errors = errors.concat(checkContentTypeNames(schemaV1.contentTypes)).concat(validateWorkflowsV1(schemaV1)).concat(checkWorkflowStepNames(schemaV1.workflows)).concat(checkWorkflowStepKeys(schemaV1.workflows));
541
+ return errors.length ? {
542
+ valid: false,
543
+ schema: undefined,
544
+ errors
545
+ } : {
546
+ valid: true,
547
+ schema: schemaV1,
548
+ errors: undefined
549
+ };
550
+ }
551
+
552
+ }, {
553
+ version: '3',
554
+ schemaId: _v2.default.$id,
555
+
556
+ validate(schema, options) {
557
+ return validateV3X(this.schemaId, schema, options);
558
+ }
559
+
560
+ }, {
561
+ version: '3.1.0',
562
+ schemaId: _v3.default.$id,
563
+
564
+ validate(schema, options) {
565
+ return validateV3X(this.schemaId, schema, options);
566
+ }
567
+
568
+ }, {
569
+ version: '3.2.0',
570
+ schemaId: _v4.default.$id,
571
+
572
+ validate(schema, options) {
573
+ return validateV3X(this.schemaId, schema, options);
574
+ }
575
+
576
+ }, {
577
+ version: '3.3.0',
578
+ schemaId: _v5.default.$id,
579
+
580
+ validate(schema, options) {
581
+ return validateV3X(this.schemaId, schema, options);
582
+ }
583
+
584
+ }, {
585
+ version: '3.4.0',
586
+ schemaId: _v6.default.$id,
587
+
588
+ validate(schema, options) {
589
+ return validateV3X(this.schemaId, schema, options);
590
+ }
591
+
592
+ }, {
593
+ version: '3.5.0',
594
+ schemaId: _v7.default.$id,
595
+
596
+ validate(schema, options) {
597
+ return validateV3X(this.schemaId, schema, options);
598
+ }
599
+
600
+ }, {
601
+ version: '3.5.1',
602
+ schemaId: _v8.default.$id,
603
+
604
+ validate(schema, options) {
605
+ return validateV3X(this.schemaId, schema, options);
606
+ }
607
+
608
+ }, {
609
+ version: '3.6.0',
610
+ schemaId: _v9.default.$id,
611
+
612
+ validate(schema, options) {
613
+ return validateV3X(this.schemaId, schema, options);
614
+ }
615
+
616
+ }];
617
+
618
+ function findValidator(schemaVersion) {
619
+ const schemaSemVer = (0, _coerce3.default)(schemaVersion !== null && schemaVersion !== void 0 ? schemaVersion : '1');
620
+ return validators.find(v => {
621
+ const validatorSemVer = (0, _coerce3.default)(v.version);
622
+ return validatorSemVer && schemaSemVer && (0, _eq.default)(validatorSemVer, schemaSemVer);
623
+ });
624
+ }
625
+ /**
626
+ * Validates a schema using a matching validation based on the `schemaVersion` property.
627
+ */
628
+
629
+
630
+ function validateSchema(obj, options) {
631
+ if ((0, _isUndefined.default)(obj)) {
632
+ return {
633
+ valid: false,
634
+ schema: undefined,
635
+ errors: [{
636
+ path: [],
637
+ type: 'undefined',
638
+ message: 'Schema is undefined'
639
+ }]
640
+ };
641
+ }
642
+
643
+ const schema = obj;
644
+ const validation = findValidator(schema.schemaVersion);
645
+
646
+ if (!validation) {
647
+ return {
648
+ valid: false,
649
+ schema: undefined,
650
+ errors: [{
651
+ path: [],
652
+ type: 'invalidVersion',
653
+ message: 'Unknown schema version'
654
+ }]
655
+ };
656
+ }
657
+
658
+ return validation.validate(schema, options);
659
+ }
660
+
661
+ function ensureValidV3Schema(obj) {
662
+ var _coerce;
663
+
664
+ const {
665
+ valid,
666
+ schema,
667
+ errors
668
+ } = validateSchema(obj);
669
+
670
+ if (!valid && errors) {
671
+ throw new Error(`Invalid Schema "${errors[0].path.join(',')}": "${errors[0].message}"`);
672
+ }
673
+
674
+ if ((0, _isUndefined.default)(schema)) {
675
+ throw new Error(`Invalid schema: schema is undefined`);
676
+ }
677
+
678
+ if ((0, _neq.default)('3.0.0', (_coerce = (0, _coerce3.default)(schema.schemaVersion)) !== null && _coerce !== void 0 ? _coerce : _versions.LEGACY_SCHEMA_VERSION)) {
679
+ throw new Error(`Expected schemaVersion: "3", got "${schema.schemaVersion}"`);
680
+ }
681
+
682
+ return schema;
683
+ }
684
+
685
+ function ensureValidLatestSchema(obj) {
686
+ var _coerce2;
687
+
688
+ const {
689
+ valid,
690
+ schema,
691
+ errors
692
+ } = validateSchema(obj);
693
+
694
+ if (!valid && errors) {
695
+ throw new Error(`Invalid Schema "${errors[0].path.join(',')}": "${errors[0].message}"`);
696
+ }
697
+
698
+ if ((0, _isUndefined.default)(schema)) {
699
+ throw new Error(`Invalid schema: schema is undefined`);
700
+ }
701
+
702
+ if ((0, _neq.default)(_versions.CURRENT_SCHEMA_VERSION, (_coerce2 = (0, _coerce3.default)(schema.schemaVersion)) !== null && _coerce2 !== void 0 ? _coerce2 : _versions.LEGACY_SCHEMA_VERSION)) {
703
+ throw new Error(`Expected schemaVersion: "${_versions.CURRENT_SCHEMA_VERSION}", got "${schema.schemaVersion}"`);
704
+ }
705
+
706
+ return schema;
707
+ }
708
+ /**
709
+ * The roles import validator ensures required properties, and strips several
710
+ * which might exist in an export but wouldn't apply to an import operation.
711
+ */
712
+
713
+
714
+ function createRoleInputValidator() {
715
+ const validator = (0, _jsonSchema.createAjv)({
716
+ useDefaults: true
717
+ });
718
+ const {
719
+ RoleInput,
720
+ ...definitions
721
+ } = _authSchemas.default.definitions;
722
+ return validator.compile({
723
+ $id: 'RoleInput',
724
+ definitions,
725
+ ...RoleInput
726
+ });
727
+ }
728
+ /**
729
+ * Validates and returns a `RoleInput`, which is a subset of the `Role`
730
+ * type's properties suitable for importing.
731
+ */
732
+
733
+
734
+ function validateRoleInput(maybeRoleInput) {
735
+ var _validate$errors;
736
+
737
+ const validate = createRoleInputValidator();
738
+
739
+ if (validate(maybeRoleInput)) {
740
+ return maybeRoleInput;
741
+ }
742
+
743
+ throw new _errors.SchemaValidationError('RoleInput was invalid', (_validate$errors = validate.errors) === null || _validate$errors === void 0 ? void 0 : _validate$errors.map(formatError));
744
+ }
745
+ /**
746
+ * The roles import validator ensures required properties, and strips several
747
+ * which might exist in an export but wouldn't apply to an import operation.
748
+ */
749
+
750
+
751
+ function createRoleImportValidator() {
752
+ const validator = (0, _jsonSchema.createAjv)({
753
+ useDefaults: true
754
+ });
755
+ const {
756
+ RoleImport,
757
+ ...definitions
758
+ } = _authSchemas.default.definitions;
759
+ return validator.compile({
760
+ $id: 'RoleImport',
761
+ definitions,
762
+ ...RoleImport
763
+ });
764
+ }
765
+ /**
766
+ * Validates and returns a `RoleImport` array, which is a collection of `RoleInput`s.
767
+ */
768
+
769
+
770
+ function validateRoleImport(maybeRoles) {
771
+ var _validate$errors2;
772
+
773
+ const validate = createRoleImportValidator();
774
+
775
+ if (validate(maybeRoles)) {
776
+ return maybeRoles;
777
+ }
778
+
779
+ throw new _errors.SchemaValidationError('Roles were invalid', (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(formatError));
780
+ }
781
+ /**
782
+ * Wrap the version-validator logic in a simple fn to bring it more inline with
783
+ * an ajv compiled validator.
784
+ */
785
+
786
+
787
+ function getProjectSchemaValidation(schemaVersion) {
788
+ const validation = findValidator(schemaVersion);
789
+ return maybeSchema => {
790
+ if (!validation) {
791
+ return {
792
+ errors: [{
793
+ path: [],
794
+ type: 'invalidVersion',
795
+ message: 'Invalid schema version'
796
+ }],
797
+ schema: undefined,
798
+ valid: false
799
+ };
800
+ }
801
+
802
+ return validation.validate(maybeSchema);
803
+ };
804
+ }
805
+ /**
806
+ * Only use when validating an imported schema!
807
+ *
808
+ * New style validation for parity with the `validateRoleImport` fn. Returns
809
+ * a valid, and potentially cleaned `AnyProjectSchema` or throws a
810
+ * `SchemaValidationError`.
811
+ */
812
+
813
+
814
+ function validateProjectSchemaImport(maybeSchema) {
815
+ const validate = getProjectSchemaValidation(maybeSchema === null || maybeSchema === void 0 ? void 0 : maybeSchema.schemaVersion);
816
+ const validateResult = validate(maybeSchema);
817
+
818
+ if (validateResult.valid) {
819
+ return maybeSchema;
820
+ }
821
+
822
+ throw new _errors.SchemaValidationError('ProjectSchema could not be validated', validateResult.errors);
823
+ }