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