@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,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isValidTemplate = isValidTemplate;
7
+ exports.parseTemplateShape = parseTemplateShape;
8
+ exports.parseReturnShape = parseReturnShape;
9
+ exports.createTemplateShapeName = createTemplateShapeName;
10
+ exports.untemplate = exports.knownTemplateShapes = void 0;
11
+
12
+ var _types = require("./types");
13
+
14
+ var _refs = require("./refs");
15
+
16
+ const knownTemplateShapes = new Set(['TSGetArgs', 'TSGetSingletonArgs', 'PaginatedList', 'TSListArgs', 'CreateArgs', 'UpdateArgs', 'DuplicateArgs', 'DeleteArgs', 'CreateResult', 'UpdateResult', 'DuplicateResult', 'DeleteResult']);
17
+ /**
18
+ * Check if a string is a known template such as `PaginatedList`
19
+ */
20
+
21
+ exports.knownTemplateShapes = knownTemplateShapes;
22
+
23
+ function isValidTemplate(template) {
24
+ return knownTemplateShapes.has(template);
25
+ }
26
+ /**
27
+ * Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
28
+ */
29
+
30
+
31
+ function parseTemplateShape(shape) {
32
+ const parts = shape.split('<');
33
+
34
+ if (parts.length > 1 && isValidTemplate(parts[0])) {
35
+ return {
36
+ shapeName: parts[1].replace(/(<|>)/, ''),
37
+ template: parts[0]
38
+ };
39
+ }
40
+
41
+ return {
42
+ shapeName: parts[0],
43
+ template: undefined
44
+ };
45
+ }
46
+
47
+ function parseReturnShape(projectSchema, shape) {
48
+ if (typeof shape === 'object') {
49
+ if ((0, _types.isRefSchema)(shape.items)) {
50
+ const ref = (0, _refs.getRef)(projectSchema, shape.items);
51
+
52
+ if (!ref) {
53
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid ref`);
54
+ }
55
+
56
+ return {
57
+ isArray: true,
58
+ ref,
59
+ shapeName: (0, _refs.refItemToShapeName)(ref)
60
+ };
61
+ }
62
+
63
+ if (typeof shape.items.type !== 'string') {
64
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid type`);
65
+ }
66
+
67
+ return {
68
+ isArray: true,
69
+ shapeName: shape.items.type
70
+ };
71
+ }
72
+
73
+ const ref = (0, _refs.refExpressionToRefItem)(projectSchema, shape);
74
+ const shapeName = (0, _refs.refItemToShapeName)(ref);
75
+ return {
76
+ isArray: false,
77
+ shapeName,
78
+ ref,
79
+ template: ref.template
80
+ };
81
+ }
82
+ /**
83
+ * Create a template string like `PaginatedList<Post>` from a template and shape name.
84
+ */
85
+
86
+
87
+ function createTemplateShapeName(template, shapeName) {
88
+ return `${template}<${shapeName}>`;
89
+ }
90
+ /**
91
+ * If the string is a template like `PaginatedList<Post>`, return the shape name,
92
+ * in this case `Post`. Otherwise return the input.
93
+ */
94
+
95
+
96
+ const untemplate = input => {
97
+ return parseTemplateShape(input).shapeName;
98
+ };
99
+
100
+ exports.untemplate = untemplate;
package/lib/types.d.ts ADDED
@@ -0,0 +1,187 @@
1
+ import type { Merge } from 'type-fest';
2
+ import type { AnyProjectSchema, ProjectSchema, ProjectSchemaV1_0_0, ProjectSchemaV3_0_0, ProjectSchemaV3_1_0, ProjectSchemaV3_2_0, ProjectSchemaV3_3_0, ProjectSchemaV3_4_0, ProjectSchemaV3_5_0, ProjectSchemaV3_5_1, ProjectSchemaV3_6_0, Resolver, BasicResolver, ComposeResolver, StoredServiceMap, AnyServiceConfig, ServiceConfig, ContentSchema, Query, ObjectSchema, ArraySchema, AllOfSchema, OneOfSchema, RefSchema, RefSchemaLegacy, ServiceAuthentication, BearerAuthentication, BasicAuthentication, OAuth2Authentication, SearchParamsAuthentication, ContentObjectSchema, CustomAuthentication, DirectiveMappingArray, DirectiveMappingMap, DirectiveConfig } from './project-schema';
3
+ import { Maybe, Overwrite } from '@takeshape/util';
4
+ import { SERVICE_OBJECT_PATTERN_NAME } from './schema-util';
5
+ /**
6
+ * An alias for the latest version of the project schema. This should be the
7
+ * only type used in most runtime code. Updating this to a new version should
8
+ * trigger type errors that clue you in to code that needs review.
9
+ */
10
+ export declare type ProjectSchemaV3X = ProjectSchemaV3_6_0 | ProjectSchemaV3_5_1 | ProjectSchemaV3_5_0 | ProjectSchemaV3_4_0 | ProjectSchemaV3_3_0 | ProjectSchemaV3_2_0 | ProjectSchemaV3_1_0 | ProjectSchemaV3_0_0;
11
+ export interface Content {
12
+ [name: string]: any;
13
+ _id: string;
14
+ }
15
+ export interface ServiceInfo {
16
+ service: string;
17
+ fieldName: string;
18
+ path: string[];
19
+ generators: Record<typeof SERVICE_OBJECT_PATTERN_NAME, PatternGenerator | undefined>;
20
+ }
21
+ export declare type ServiceSchema = Pick<ProjectSchema, 'shapes' | 'queries' | 'mutations'>;
22
+ export declare function isBasicResolver(resolver: Resolver | undefined): resolver is BasicResolver;
23
+ export declare function isComposeResolver(resolver: Resolver | undefined): resolver is ComposeResolver;
24
+ /**
25
+ * Remote service configuration types
26
+ */
27
+ /**
28
+ * Old service authentication
29
+ * @deprecated
30
+ */
31
+ export interface ServiceConfigAccessToken {
32
+ accessToken: string;
33
+ refreshToken?: string;
34
+ scope?: string;
35
+ }
36
+ export declare type ServiceKey = string;
37
+ export declare type ServiceMap = Map<ServiceKey, ServiceConfig>;
38
+ export interface PatternGenerator {
39
+ version: string;
40
+ currentVersion: string;
41
+ idFieldName: string;
42
+ serviceObjectType: string;
43
+ }
44
+ /**
45
+ * Test all required props, currently:
46
+ * "name", "slug", "provider", "serviceType", "authenticationType"
47
+ */
48
+ export declare function isAnyServiceConfig(maybeConfig: any): maybeConfig is AnyServiceConfig;
49
+ export declare type Headers = Record<string, string | string[]>;
50
+ export declare type RESTServiceConfig = Overwrite<ServiceConfig, {
51
+ serviceType: 'rest';
52
+ options: {
53
+ endpoint: string;
54
+ headers?: Headers;
55
+ timeout?: number;
56
+ };
57
+ }>;
58
+ export declare function isRESTServiceConfig(maybeConfig: any): maybeConfig is RESTServiceConfig;
59
+ export declare type GraphQLServiceConfig = Overwrite<ServiceConfig, {
60
+ serviceType: 'graphql';
61
+ options: {
62
+ [name: string]: any;
63
+ endpoint: string;
64
+ headers?: Headers;
65
+ timeout?: number;
66
+ };
67
+ }>;
68
+ export declare function isGraphQLServiceConfig(maybeConfig: any): maybeConfig is GraphQLServiceConfig;
69
+ export declare type OpenAPIServiceConfig = Overwrite<ServiceConfig, {
70
+ serviceType: 'openapi';
71
+ options: {
72
+ endpoint: string;
73
+ spec: string;
74
+ headers?: Headers;
75
+ timeout?: number;
76
+ };
77
+ }>;
78
+ export declare function isOpenAPIServiceConfig(maybeConfig: any): maybeConfig is OpenAPIServiceConfig;
79
+ export declare type EncryptedServiceConfig = Overwrite<ServiceConfig, {
80
+ authentication: string;
81
+ }>;
82
+ export declare function isEncryptedServiceConfig(maybeConfig: any): maybeConfig is EncryptedServiceConfig;
83
+ export declare function isServiceAuthentication(maybeAuthentication: any): maybeAuthentication is ServiceAuthentication;
84
+ export declare function isBearerAuthentication(maybeAuthentication: any): maybeAuthentication is BearerAuthentication;
85
+ export declare function isBasicAuthentication(maybeAuthentication: any): maybeAuthentication is BasicAuthentication;
86
+ export declare function isSearchParamsAuthentication(maybeAuthentication: any): maybeAuthentication is SearchParamsAuthentication;
87
+ export declare function isOAuth2Authentication(maybeAuthentication: any): maybeAuthentication is OAuth2Authentication;
88
+ export declare type ServiceConfigWithOAuth2Authentication = Merge<ServiceConfig, {
89
+ authentication: OAuth2Authentication;
90
+ }>;
91
+ export declare function isServiceConfigWithOAuth2Authentication(maybeServiceConfig: any): maybeServiceConfig is ServiceConfigWithOAuth2Authentication;
92
+ export declare type ServiceConfigWithCustomAuthentication = Merge<ServiceConfig, {
93
+ authentication: CustomAuthentication;
94
+ }>;
95
+ export declare function isServiceConfigWithCustomAuthentication(maybeServiceConfig: any): maybeServiceConfig is ServiceConfigWithCustomAuthentication;
96
+ export interface LatestProjectSchemaWithServices extends ProjectSchema {
97
+ dataKey: string;
98
+ services: StoredServiceMap;
99
+ }
100
+ export declare function isProjectSchemaWithServices(schema: ProjectSchema): schema is LatestProjectSchemaWithServices;
101
+ /**
102
+ * Types of refs
103
+ */
104
+ export declare enum RefType {
105
+ '@ref' = "@ref",
106
+ $ref = "$ref"
107
+ }
108
+ /**
109
+ * Stub of a ContentSchema that may contain a `$ref` or `@ref`.
110
+ */
111
+ export interface RefSchemaStub extends Pick<ContentSchema, RefType> {
112
+ items?: RefSchemaStub;
113
+ }
114
+ export declare type SchemaWithRef = ContentSchema | RefSchemaStub;
115
+ /**
116
+ * A utility to return the type of ref present on a schema.
117
+ *
118
+ * @param refSchema Any schema that may have a `ref` property.
119
+ */
120
+ export declare const getRefType: (refSchema: SchemaWithRef) => Maybe<RefType>;
121
+ /**
122
+ * Types of args
123
+ */
124
+ export declare enum ArgsType {
125
+ '@args' = "@args",
126
+ args = "args"
127
+ }
128
+ export declare type SchemaWithArgs = ContentSchema | Query;
129
+ /**
130
+ * A utility to return the type of args present on a schema.
131
+ *
132
+ * @param argsSchema Any schema that may have an `args` property.
133
+ */
134
+ export declare const getArgsType: (argsSchema: SchemaWithArgs) => Maybe<ArgsType>;
135
+ /**
136
+ * Typeguards for different types of shape schemas
137
+ */
138
+ export declare function isRefSchema(maybeRefSchema: ContentObjectSchema | ContentSchema): maybeRefSchema is RefSchema | RefSchemaLegacy;
139
+ export declare function isRefSchemaLegacy(maybeRefSchema: ContentObjectSchema | ContentSchema): maybeRefSchema is RefSchemaLegacy;
140
+ export declare function isAllOfSchema(maybeExtendableSchema: ContentObjectSchema | ContentSchema): maybeExtendableSchema is AllOfSchema;
141
+ export declare function isOneOfSchema(maybeExclusiveOrSchema: ContentObjectSchema | ContentSchema): maybeExclusiveOrSchema is OneOfSchema;
142
+ export declare function isArraySchema(maybeArraySchema: ContentObjectSchema | ContentSchema): maybeArraySchema is ArraySchema;
143
+ export declare function isObjectSchema(maybeObjectSchema: ContentObjectSchema | ContentSchema): maybeObjectSchema is ObjectSchema;
144
+ export declare function isContentObjectSchema(maybeSchema: ContentObjectSchema | ContentSchema): maybeSchema is ContentObjectSchema;
145
+ export declare const isProjectSchemaV1: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV1_0_0;
146
+ export declare const isProjectSchemaV3: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_0_0;
147
+ export declare const isProjectSchemaV3_1: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_1_0;
148
+ export declare const isProjectSchemaV3_2: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_2_0;
149
+ export declare const isProjectSchemaV3_3: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_3_0;
150
+ export declare const isProjectSchemaV3_4: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_4_0;
151
+ export declare const isProjectSchemaV3_5: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_5_0;
152
+ export declare const isProjectSchemaV3_5_1: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchemaV3_5_1;
153
+ export declare const isProjectSchemaV3_6: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchema;
154
+ export declare const isLatestProjectSchema: (projectSchema: AnyProjectSchema) => projectSchema is ProjectSchema;
155
+ /**
156
+ * Determine whether a given project schema is any project schema.
157
+ */
158
+ export declare function isAnyProjectSchema(maybeSchema: unknown): maybeSchema is AnyProjectSchema;
159
+ /**
160
+ * Types supporting schema iterators
161
+ */
162
+ export declare type SchemaPropertyName = string;
163
+ export declare type SchemaPropertyNode = [SchemaPropertyName, ContentSchema];
164
+ export declare type SchemaPropertyIterator = SchemaPropertyNode[];
165
+ export declare type ShopifyServiceConfig = Overwrite<ServiceConfig, {
166
+ serviceType: 'graphql';
167
+ provider: 'shopify';
168
+ options: {
169
+ shop: string;
170
+ endpoint: string;
171
+ };
172
+ }>;
173
+ export declare function isShopifyServiceConfig(maybeShopify: AnyServiceConfig): maybeShopify is ShopifyServiceConfig;
174
+ export declare type SchemaPath = Array<string | number>;
175
+ /**
176
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingMap
177
+ */
178
+ export declare function isDirectiveMappingMap(maybeMap: DirectiveMappingMap | DirectiveMappingArray | DirectiveConfig): maybeMap is DirectiveMappingMap;
179
+ /**
180
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingArray
181
+ */
182
+ export declare function isDirectiveMappingArray(maybeArray: DirectiveMappingMap | DirectiveMappingArray | DirectiveConfig): maybeArray is DirectiveMappingArray;
183
+ /**
184
+ * Determine whether the ambiguous Directive structure is a DirectiveConfig array
185
+ */
186
+ export declare function isDirectiveConfig(maybeConfig: DirectiveMappingMap | DirectiveMappingArray | DirectiveConfig): maybeConfig is DirectiveConfig;
187
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB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P,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CACF,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,gBAAgB,GAAG,YAAY,IAAI,oBAAoB,CAE3G;AAED,oBAAY,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAEhD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,eAAe,GACtE,QAAQ,IAAI,mBAAmB,CAEjC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,eAAe,GACxE,UAAU,IAAI,qBAAqB,CAErC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,eAAe,GACzE,WAAW,IAAI,eAAe,CAEhC"}
package/lib/types.js ADDED
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBasicResolver = isBasicResolver;
7
+ exports.isComposeResolver = isComposeResolver;
8
+ exports.isAnyServiceConfig = isAnyServiceConfig;
9
+ exports.isRESTServiceConfig = isRESTServiceConfig;
10
+ exports.isGraphQLServiceConfig = isGraphQLServiceConfig;
11
+ exports.isOpenAPIServiceConfig = isOpenAPIServiceConfig;
12
+ exports.isEncryptedServiceConfig = isEncryptedServiceConfig;
13
+ exports.isServiceAuthentication = isServiceAuthentication;
14
+ exports.isBearerAuthentication = isBearerAuthentication;
15
+ exports.isBasicAuthentication = isBasicAuthentication;
16
+ exports.isSearchParamsAuthentication = isSearchParamsAuthentication;
17
+ exports.isOAuth2Authentication = isOAuth2Authentication;
18
+ exports.isServiceConfigWithOAuth2Authentication = isServiceConfigWithOAuth2Authentication;
19
+ exports.isServiceConfigWithCustomAuthentication = isServiceConfigWithCustomAuthentication;
20
+ exports.isProjectSchemaWithServices = isProjectSchemaWithServices;
21
+ exports.isRefSchema = isRefSchema;
22
+ exports.isRefSchemaLegacy = isRefSchemaLegacy;
23
+ exports.isAllOfSchema = isAllOfSchema;
24
+ exports.isOneOfSchema = isOneOfSchema;
25
+ exports.isArraySchema = isArraySchema;
26
+ exports.isObjectSchema = isObjectSchema;
27
+ exports.isContentObjectSchema = isContentObjectSchema;
28
+ exports.isAnyProjectSchema = isAnyProjectSchema;
29
+ exports.isShopifyServiceConfig = isShopifyServiceConfig;
30
+ exports.isDirectiveMappingMap = isDirectiveMappingMap;
31
+ exports.isDirectiveMappingArray = isDirectiveMappingArray;
32
+ exports.isDirectiveConfig = isDirectiveConfig;
33
+ exports.isLatestProjectSchema = exports.isProjectSchemaV3_6 = exports.isProjectSchemaV3_5_1 = exports.isProjectSchemaV3_5 = exports.isProjectSchemaV3_4 = exports.isProjectSchemaV3_3 = exports.isProjectSchemaV3_2 = exports.isProjectSchemaV3_1 = exports.isProjectSchemaV3 = exports.isProjectSchemaV1 = exports.getArgsType = exports.ArgsType = exports.getRefType = exports.RefType = void 0;
34
+
35
+ var _eq = _interopRequireDefault(require("semver/functions/eq"));
36
+
37
+ var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
38
+
39
+ var _has = _interopRequireDefault(require("lodash/has"));
40
+
41
+ var _isString = _interopRequireDefault(require("lodash/isString"));
42
+
43
+ var _isObject = _interopRequireDefault(require("lodash/isObject"));
44
+
45
+ var _isArray = _interopRequireDefault(require("lodash/isArray"));
46
+
47
+ var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
48
+
49
+ var _versions = require("./versions");
50
+
51
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
+
53
+ function isBasicResolver(resolver) {
54
+ return resolver ? (0, _isString.default)(resolver.name) && (0, _isString.default)(resolver.service) : false;
55
+ }
56
+
57
+ function isComposeResolver(resolver) {
58
+ return resolver ? resolver.compose !== undefined : false;
59
+ }
60
+ /**
61
+ * Remote service configuration types
62
+ */
63
+
64
+ /**
65
+ * Old service authentication
66
+ * @deprecated
67
+ */
68
+
69
+
70
+ /**
71
+ * Test all required props, currently:
72
+ * "name", "slug", "provider", "serviceType", "authenticationType"
73
+ */
74
+ function isAnyServiceConfig(maybeConfig) {
75
+ return maybeConfig && (0, _isString.default)(maybeConfig.title) && (0, _isString.default)(maybeConfig.id) && (0, _isString.default)(maybeConfig.provider) && (0, _isString.default)(maybeConfig.serviceType) && (0, _isString.default)(maybeConfig.authenticationType);
76
+ }
77
+
78
+ function isRESTServiceConfig(maybeConfig) {
79
+ return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'rest';
80
+ }
81
+
82
+ function isGraphQLServiceConfig(maybeConfig) {
83
+ var _maybeConfig$options;
84
+
85
+ return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && (0, _isString.default)((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
86
+ }
87
+
88
+ function isOpenAPIServiceConfig(maybeConfig) {
89
+ return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'openapi';
90
+ }
91
+
92
+ function isEncryptedServiceConfig(maybeConfig) {
93
+ return isAnyServiceConfig(maybeConfig) && (0, _isString.default)(maybeConfig.authentication);
94
+ }
95
+
96
+ function isServiceAuthentication(maybeAuthentication) {
97
+ return maybeAuthentication && (0, _isObject.default)(maybeAuthentication);
98
+ }
99
+
100
+ function isBearerAuthentication(maybeAuthentication) {
101
+ return isServiceAuthentication(maybeAuthentication) && (0, _isString.default)(maybeAuthentication.token);
102
+ }
103
+
104
+ function isBasicAuthentication(maybeAuthentication) {
105
+ return isServiceAuthentication(maybeAuthentication) && ((0, _isString.default)(maybeAuthentication.username) || (0, _isString.default)(maybeAuthentication.password));
106
+ }
107
+
108
+ function isSearchParamsAuthentication(maybeAuthentication) {
109
+ return (0, _isArray.default)(maybeAuthentication) && maybeAuthentication.every(value => (0, _isObject.default)(value) && Object.entries(value).every(([k, v]) => (k === 'name' || k === 'value') && (0, _isString.default)(v)));
110
+ }
111
+
112
+ function isOAuth2Authentication(maybeAuthentication) {
113
+ return isServiceAuthentication(maybeAuthentication) && (0, _isString.default)(maybeAuthentication.clientId);
114
+ }
115
+
116
+ function isServiceConfigWithOAuth2Authentication(maybeServiceConfig) {
117
+ return isAnyServiceConfig(maybeServiceConfig) && maybeServiceConfig.authenticationType === 'oauth2' && isOAuth2Authentication(maybeServiceConfig.authentication);
118
+ }
119
+
120
+ function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
121
+ return isAnyServiceConfig(maybeServiceConfig) && maybeServiceConfig.authenticationType === 'custom' && isServiceAuthentication(maybeServiceConfig.authentication);
122
+ }
123
+
124
+ function isProjectSchemaWithServices(schema) {
125
+ return typeof schema.dataKey !== 'undefined' && typeof schema.services !== 'undefined';
126
+ }
127
+ /**
128
+ * Types of refs
129
+ */
130
+
131
+
132
+ let RefType;
133
+ /**
134
+ * Stub of a ContentSchema that may contain a `$ref` or `@ref`.
135
+ */
136
+
137
+ exports.RefType = RefType;
138
+
139
+ (function (RefType) {
140
+ RefType["@ref"] = "@ref";
141
+ RefType["$ref"] = "$ref";
142
+ })(RefType || (exports.RefType = RefType = {}));
143
+
144
+ /**
145
+ * A utility to return the type of ref present on a schema.
146
+ *
147
+ * @param refSchema Any schema that may have a `ref` property.
148
+ */
149
+ const getRefType = refSchema => {
150
+ if ((0, _has.default)(refSchema, '@ref')) {
151
+ return RefType['@ref'];
152
+ }
153
+
154
+ if ((0, _has.default)(refSchema, '$ref')) {
155
+ return RefType.$ref;
156
+ }
157
+ };
158
+ /**
159
+ * Types of args
160
+ */
161
+
162
+
163
+ exports.getRefType = getRefType;
164
+ let ArgsType;
165
+ exports.ArgsType = ArgsType;
166
+
167
+ (function (ArgsType) {
168
+ ArgsType["@args"] = "@args";
169
+ ArgsType["args"] = "args";
170
+ })(ArgsType || (exports.ArgsType = ArgsType = {}));
171
+
172
+ /**
173
+ * A utility to return the type of args present on a schema.
174
+ *
175
+ * @param argsSchema Any schema that may have an `args` property.
176
+ */
177
+ const getArgsType = argsSchema => {
178
+ if ((0, _has.default)(argsSchema, '@args')) {
179
+ return ArgsType['@args'];
180
+ }
181
+
182
+ if ((0, _has.default)(argsSchema, 'args')) {
183
+ return ArgsType.args;
184
+ }
185
+ };
186
+ /**
187
+ * Typeguards for different types of shape schemas
188
+ */
189
+
190
+
191
+ exports.getArgsType = getArgsType;
192
+
193
+ function isRefSchema(maybeRefSchema) {
194
+ return (0, _isString.default)(maybeRefSchema['@ref']) || (0, _isString.default)(maybeRefSchema.$ref);
195
+ }
196
+
197
+ function isRefSchemaLegacy(maybeRefSchema) {
198
+ return (0, _isString.default)(maybeRefSchema.$ref);
199
+ }
200
+
201
+ function isAllOfSchema(maybeExtendableSchema) {
202
+ return (0, _isArray.default)(maybeExtendableSchema.allOf);
203
+ }
204
+
205
+ function isOneOfSchema(maybeExclusiveOrSchema) {
206
+ return (0, _isArray.default)(maybeExclusiveOrSchema.oneOf);
207
+ }
208
+
209
+ function isArraySchema(maybeArraySchema) {
210
+ return maybeArraySchema.type === 'array' && (0, _isObject.default)(maybeArraySchema.items);
211
+ }
212
+
213
+ function isObjectSchema(maybeObjectSchema) {
214
+ return maybeObjectSchema.type === 'object' && (0, _isObject.default)(maybeObjectSchema.properties);
215
+ }
216
+
217
+ function isContentObjectSchema(maybeSchema) {
218
+ return isRefSchema(maybeSchema) || isAllOfSchema(maybeSchema) || isObjectSchema(maybeSchema);
219
+ }
220
+
221
+ function createVersionPredicate(schemaVersion) {
222
+ const expectedSemver = (0, _coerce.default)(schemaVersion);
223
+ return projectSchema => {
224
+ var _projectSchema$schema;
225
+
226
+ const schemaSemver = (0, _coerce.default)((_projectSchema$schema = projectSchema.schemaVersion) !== null && _projectSchema$schema !== void 0 ? _projectSchema$schema : '1');
227
+ return Boolean(expectedSemver && schemaSemver && (0, _eq.default)(schemaSemver, expectedSemver));
228
+ };
229
+ }
230
+
231
+ const isProjectSchemaV1 = createVersionPredicate('1');
232
+ exports.isProjectSchemaV1 = isProjectSchemaV1;
233
+ const isProjectSchemaV3 = createVersionPredicate('3');
234
+ exports.isProjectSchemaV3 = isProjectSchemaV3;
235
+ const isProjectSchemaV3_1 = createVersionPredicate('3.1.0');
236
+ exports.isProjectSchemaV3_1 = isProjectSchemaV3_1;
237
+ const isProjectSchemaV3_2 = createVersionPredicate('3.2.0');
238
+ exports.isProjectSchemaV3_2 = isProjectSchemaV3_2;
239
+ const isProjectSchemaV3_3 = createVersionPredicate('3.3.0');
240
+ exports.isProjectSchemaV3_3 = isProjectSchemaV3_3;
241
+ const isProjectSchemaV3_4 = createVersionPredicate('3.4.0');
242
+ exports.isProjectSchemaV3_4 = isProjectSchemaV3_4;
243
+ const isProjectSchemaV3_5 = createVersionPredicate('3.5.0');
244
+ exports.isProjectSchemaV3_5 = isProjectSchemaV3_5;
245
+ const isProjectSchemaV3_5_1 = createVersionPredicate('3.5.1');
246
+ exports.isProjectSchemaV3_5_1 = isProjectSchemaV3_5_1;
247
+ const isProjectSchemaV3_6 = createVersionPredicate('3.6.0');
248
+ exports.isProjectSchemaV3_6 = isProjectSchemaV3_6;
249
+ const isLatestProjectSchema = createVersionPredicate(_versions.CURRENT_SCHEMA_VERSION);
250
+ /**
251
+ * Determine whether a given project schema is any project schema.
252
+ */
253
+
254
+ exports.isLatestProjectSchema = isLatestProjectSchema;
255
+
256
+ function isAnyProjectSchema(maybeSchema) {
257
+ return (0, _isObject.default)(maybeSchema) && (0, _isString.default)(maybeSchema.projectId) && (isProjectSchemaV1(maybeSchema) || isProjectSchemaV3(maybeSchema) || isProjectSchemaV3_1(maybeSchema) || isProjectSchemaV3_2(maybeSchema) || isProjectSchemaV3_3(maybeSchema) || isProjectSchemaV3_4(maybeSchema) || isProjectSchemaV3_5(maybeSchema) || isProjectSchemaV3_5_1(maybeSchema) || isProjectSchemaV3_6(maybeSchema));
258
+ }
259
+ /**
260
+ * Types supporting schema iterators
261
+ */
262
+
263
+
264
+ function isShopifyServiceConfig(maybeShopify) {
265
+ return maybeShopify.provider === 'shopify';
266
+ }
267
+
268
+ /**
269
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingMap
270
+ */
271
+ function isDirectiveMappingMap(maybeMap) {
272
+ return (0, _isPlainObject.default)(maybeMap) && Object.keys(maybeMap).length > 0;
273
+ }
274
+ /**
275
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingArray
276
+ */
277
+
278
+
279
+ function isDirectiveMappingArray(maybeArray) {
280
+ return (0, _isArray.default)(maybeArray) && (0, _isArray.default)(maybeArray[0]) && (0, _isString.default)(maybeArray[0][0]) && (0, _isArray.default)(maybeArray[0][1]);
281
+ }
282
+ /**
283
+ * Determine whether the ambiguous Directive structure is a DirectiveConfig array
284
+ */
285
+
286
+
287
+ function isDirectiveConfig(maybeConfig) {
288
+ return (0, _isArray.default)(maybeConfig) && (0, _isArray.default)(maybeConfig[0]) && (0, _isString.default)(maybeConfig[0][0]) && (0, _isObject.default)(maybeConfig[0][1]);
289
+ }
@@ -0,0 +1,29 @@
1
+ import { ProjectSchema, ContentSchema, ObjectSchema, OneOfSchema } from './project-schema';
2
+ import { PropertyTransform } from './content-schema-transform';
3
+ import { ProjectSchemaV3X } from './types';
4
+ export interface UnionedShape {
5
+ propName: string;
6
+ shapeName: string;
7
+ shapeId: string;
8
+ propSchema: ContentSchema;
9
+ }
10
+ export declare function enumerateOneOfKeys(projectSchema: ProjectSchemaV3X, oneOf: ContentSchema[]): UnionedShape[];
11
+ export declare function isUnionSchema(schema: ContentSchema): schema is OneOfSchema;
12
+ export declare function oneOfToObject(projectSchema: ProjectSchemaV3X, schema: ContentSchema): ObjectSchema;
13
+ export declare type TransformProcessFactory = (projectSchema: ProjectSchema) => PropertyTransform['process'];
14
+ export declare const createUnwrapTransform: TransformProcessFactory;
15
+ export declare const createWrapTransform: TransformProcessFactory;
16
+ export declare function transformOneOf(process: TransformProcessFactory): (projectSchema: ProjectSchema, schema: ContentSchema, obj: Record<string, unknown>) => Record<string, unknown>;
17
+ /**
18
+ * Unwrap oneOf objects in "GraphQL oneOf" style wrapper objects
19
+ * See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
20
+ * Opposite of `wrapOneOfObjects`
21
+ */
22
+ export declare const unwrapOneOfObjects: (projectSchema: ProjectSchema, schema: ContentSchema, obj: Record<string, unknown>) => Record<string, unknown>;
23
+ /**
24
+ * Wrap oneOf objects in "GraphQL oneOf" style wrapper objects
25
+ * See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
26
+ * Opposite of `unwrapOneOfObjects`
27
+ */
28
+ export declare const wrapOneOfObjects: (projectSchema: ProjectSchema, schema: ContentSchema, obj: Record<string, unknown>) => Record<string, unknown>;
29
+ //# sourceMappingURL=unions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unions.d.ts","sourceRoot":"","sources":["../../src/unions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAIzF,OAAO,EAAsB,iBAAiB,EAAS,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAc,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAItD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,aAAa,CAAC;CAC3B;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,YAAY,EAAE,CAkB1G;AASD,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,IAAI,WAAW,CAE1E;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,GA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