@backendrelay/core 1.1.0 → 2.0.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 (598) hide show
  1. package/dist/standalone/index.js +1 -1
  2. package/dist/standalone/index.umd.cjs +1 -1
  3. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typeUtils.d.ts +20 -0
  4. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
  5. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typeUtils.js +5 -0
  6. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typeUtils.js.map +1 -0
  7. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typesTests.d.ts +2 -0
  8. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
  9. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typesTests.js +88 -0
  10. package/node_modules/@backendrelay/admin/dist/commonjs/__types__/typesTests.js.map +1 -0
  11. package/node_modules/@backendrelay/admin/dist/commonjs/byop.live.e2e.test.d.ts +2 -0
  12. package/node_modules/@backendrelay/admin/dist/commonjs/byop.live.e2e.test.d.ts.map +1 -0
  13. package/node_modules/@backendrelay/admin/dist/commonjs/byop.live.e2e.test.js +131 -0
  14. package/node_modules/@backendrelay/admin/dist/commonjs/byop.live.e2e.test.js.map +1 -0
  15. package/node_modules/@backendrelay/admin/dist/commonjs/config.test.d.ts +2 -0
  16. package/node_modules/@backendrelay/admin/dist/commonjs/config.test.d.ts.map +1 -0
  17. package/node_modules/@backendrelay/admin/dist/commonjs/config.test.js +65 -0
  18. package/node_modules/@backendrelay/admin/dist/commonjs/config.test.js.map +1 -0
  19. package/node_modules/@backendrelay/admin/dist/commonjs/index.d.ts +725 -0
  20. package/node_modules/@backendrelay/admin/dist/commonjs/index.d.ts.map +1 -0
  21. package/node_modules/@backendrelay/admin/dist/commonjs/index.js +1159 -0
  22. package/node_modules/@backendrelay/admin/dist/commonjs/index.js.map +1 -0
  23. package/node_modules/@backendrelay/admin/dist/commonjs/live.e2e.test.d.ts +2 -0
  24. package/node_modules/@backendrelay/admin/dist/commonjs/live.e2e.test.d.ts.map +1 -0
  25. package/node_modules/@backendrelay/admin/dist/commonjs/live.e2e.test.js +91 -0
  26. package/node_modules/@backendrelay/admin/dist/commonjs/live.e2e.test.js.map +1 -0
  27. package/node_modules/@backendrelay/admin/dist/commonjs/package.json +3 -0
  28. package/node_modules/@backendrelay/admin/dist/commonjs/polyfill.d.ts +17 -0
  29. package/node_modules/@backendrelay/admin/dist/commonjs/polyfill.d.ts.map +1 -0
  30. package/node_modules/@backendrelay/admin/dist/commonjs/polyfill.js +26 -0
  31. package/node_modules/@backendrelay/admin/dist/commonjs/polyfill.js.map +1 -0
  32. package/node_modules/@backendrelay/admin/dist/commonjs/removed-features.test.d.ts +2 -0
  33. package/node_modules/@backendrelay/admin/dist/commonjs/removed-features.test.d.ts.map +1 -0
  34. package/node_modules/@backendrelay/admin/dist/commonjs/removed-features.test.js +50 -0
  35. package/node_modules/@backendrelay/admin/dist/commonjs/removed-features.test.js.map +1 -0
  36. package/node_modules/@backendrelay/admin/dist/commonjs/storage-upload.test.d.ts +2 -0
  37. package/node_modules/@backendrelay/admin/dist/commonjs/storage-upload.test.d.ts.map +1 -0
  38. package/node_modules/@backendrelay/admin/dist/commonjs/storage-upload.test.js +33 -0
  39. package/node_modules/@backendrelay/admin/dist/commonjs/storage-upload.test.js.map +1 -0
  40. package/node_modules/@backendrelay/admin/dist/commonjs/subscribe.d.ts +39 -0
  41. package/node_modules/@backendrelay/admin/dist/commonjs/subscribe.d.ts.map +1 -0
  42. package/node_modules/@backendrelay/admin/dist/commonjs/subscribe.js +306 -0
  43. package/node_modules/@backendrelay/admin/dist/commonjs/subscribe.js.map +1 -0
  44. package/node_modules/@backendrelay/admin/dist/commonjs/version.d.ts +3 -0
  45. package/node_modules/@backendrelay/admin/dist/commonjs/version.d.ts.map +1 -0
  46. package/node_modules/@backendrelay/admin/dist/commonjs/version.js +5 -0
  47. package/node_modules/@backendrelay/admin/dist/commonjs/version.js.map +1 -0
  48. package/node_modules/@backendrelay/admin/dist/esm/__types__/typeUtils.d.ts +20 -0
  49. package/node_modules/@backendrelay/admin/dist/esm/__types__/typeUtils.d.ts.map +1 -0
  50. package/node_modules/@backendrelay/admin/dist/esm/__types__/typeUtils.js +4 -0
  51. package/node_modules/@backendrelay/admin/dist/esm/__types__/typeUtils.js.map +1 -0
  52. package/node_modules/@backendrelay/admin/dist/esm/__types__/typesTests.d.ts +2 -0
  53. package/node_modules/@backendrelay/admin/dist/esm/__types__/typesTests.d.ts.map +1 -0
  54. package/node_modules/@backendrelay/admin/dist/esm/__types__/typesTests.js +86 -0
  55. package/node_modules/@backendrelay/admin/dist/esm/__types__/typesTests.js.map +1 -0
  56. package/node_modules/@backendrelay/admin/dist/esm/byop.live.e2e.test.d.ts +2 -0
  57. package/node_modules/@backendrelay/admin/dist/esm/byop.live.e2e.test.d.ts.map +1 -0
  58. package/node_modules/@backendrelay/admin/dist/esm/byop.live.e2e.test.js +129 -0
  59. package/node_modules/@backendrelay/admin/dist/esm/byop.live.e2e.test.js.map +1 -0
  60. package/node_modules/@backendrelay/admin/dist/esm/config.test.d.ts +2 -0
  61. package/node_modules/@backendrelay/admin/dist/esm/config.test.d.ts.map +1 -0
  62. package/node_modules/@backendrelay/admin/dist/esm/config.test.js +63 -0
  63. package/node_modules/@backendrelay/admin/dist/esm/config.test.js.map +1 -0
  64. package/node_modules/@backendrelay/admin/dist/esm/index.d.ts +725 -0
  65. package/node_modules/@backendrelay/admin/dist/esm/index.d.ts.map +1 -0
  66. package/node_modules/@backendrelay/admin/dist/esm/index.js +1146 -0
  67. package/node_modules/@backendrelay/admin/dist/esm/index.js.map +1 -0
  68. package/node_modules/@backendrelay/admin/dist/esm/live.e2e.test.d.ts +2 -0
  69. package/node_modules/@backendrelay/admin/dist/esm/live.e2e.test.d.ts.map +1 -0
  70. package/node_modules/@backendrelay/admin/dist/esm/live.e2e.test.js +89 -0
  71. package/node_modules/@backendrelay/admin/dist/esm/live.e2e.test.js.map +1 -0
  72. package/node_modules/@backendrelay/admin/dist/esm/package.json +3 -0
  73. package/node_modules/@backendrelay/admin/dist/esm/polyfill.d.ts +17 -0
  74. package/node_modules/@backendrelay/admin/dist/esm/polyfill.d.ts.map +1 -0
  75. package/node_modules/@backendrelay/admin/dist/esm/polyfill.js +22 -0
  76. package/node_modules/@backendrelay/admin/dist/esm/polyfill.js.map +1 -0
  77. package/node_modules/@backendrelay/admin/dist/esm/removed-features.test.d.ts +2 -0
  78. package/node_modules/@backendrelay/admin/dist/esm/removed-features.test.d.ts.map +1 -0
  79. package/node_modules/@backendrelay/admin/dist/esm/removed-features.test.js +48 -0
  80. package/node_modules/@backendrelay/admin/dist/esm/removed-features.test.js.map +1 -0
  81. package/node_modules/@backendrelay/admin/dist/esm/storage-upload.test.d.ts +2 -0
  82. package/node_modules/@backendrelay/admin/dist/esm/storage-upload.test.d.ts.map +1 -0
  83. package/node_modules/@backendrelay/admin/dist/esm/storage-upload.test.js +31 -0
  84. package/node_modules/@backendrelay/admin/dist/esm/storage-upload.test.js.map +1 -0
  85. package/node_modules/@backendrelay/admin/dist/esm/subscribe.d.ts +39 -0
  86. package/node_modules/@backendrelay/admin/dist/esm/subscribe.d.ts.map +1 -0
  87. package/node_modules/@backendrelay/admin/dist/esm/subscribe.js +300 -0
  88. package/node_modules/@backendrelay/admin/dist/esm/subscribe.js.map +1 -0
  89. package/node_modules/@backendrelay/admin/dist/esm/version.d.ts +3 -0
  90. package/node_modules/@backendrelay/admin/dist/esm/version.d.ts.map +1 -0
  91. package/{src/version.ts → node_modules/@backendrelay/admin/dist/esm/version.js} +1 -1
  92. package/node_modules/@backendrelay/admin/dist/esm/version.js.map +1 -0
  93. package/node_modules/@backendrelay/admin/package.json +52 -0
  94. package/node_modules/@backendrelay/functions/README.md +131 -0
  95. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typeUtils.d.ts +3 -0
  96. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
  97. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typeUtils.js +3 -0
  98. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typeUtils.js.map +1 -0
  99. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typesTests.d.ts +2 -0
  100. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
  101. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typesTests.js +51 -0
  102. package/node_modules/@backendrelay/functions/dist/commonjs/__types__/typesTests.js.map +1 -0
  103. package/node_modules/@backendrelay/functions/dist/commonjs/index.d.ts +230 -0
  104. package/node_modules/@backendrelay/functions/dist/commonjs/index.d.ts.map +1 -0
  105. package/node_modules/@backendrelay/functions/dist/commonjs/index.js +415 -0
  106. package/node_modules/@backendrelay/functions/dist/commonjs/index.js.map +1 -0
  107. package/node_modules/@backendrelay/functions/dist/commonjs/package.json +3 -0
  108. package/node_modules/@backendrelay/functions/dist/esm/__types__/typeUtils.d.ts +3 -0
  109. package/node_modules/@backendrelay/functions/dist/esm/__types__/typeUtils.d.ts.map +1 -0
  110. package/node_modules/@backendrelay/functions/dist/esm/__types__/typeUtils.js +2 -0
  111. package/node_modules/@backendrelay/functions/dist/esm/__types__/typeUtils.js.map +1 -0
  112. package/node_modules/@backendrelay/functions/dist/esm/__types__/typesTests.d.ts +2 -0
  113. package/node_modules/@backendrelay/functions/dist/esm/__types__/typesTests.d.ts.map +1 -0
  114. package/node_modules/@backendrelay/functions/dist/esm/__types__/typesTests.js +49 -0
  115. package/node_modules/@backendrelay/functions/dist/esm/__types__/typesTests.js.map +1 -0
  116. package/node_modules/@backendrelay/functions/dist/esm/index.d.ts +230 -0
  117. package/node_modules/@backendrelay/functions/dist/esm/index.d.ts.map +1 -0
  118. package/node_modules/@backendrelay/functions/dist/esm/index.js +403 -0
  119. package/node_modules/@backendrelay/functions/dist/esm/index.js.map +1 -0
  120. package/node_modules/@backendrelay/functions/dist/esm/package.json +3 -0
  121. package/node_modules/@backendrelay/functions/package.json +49 -0
  122. package/node_modules/@backendrelay/hatchet/dist/commonjs/index.d.ts +43 -0
  123. package/node_modules/@backendrelay/hatchet/dist/commonjs/index.d.ts.map +1 -0
  124. package/node_modules/@backendrelay/hatchet/dist/commonjs/index.js +63 -0
  125. package/node_modules/@backendrelay/hatchet/dist/commonjs/index.js.map +1 -0
  126. package/node_modules/@backendrelay/hatchet/dist/commonjs/package.json +3 -0
  127. package/node_modules/@backendrelay/hatchet/dist/esm/index.d.ts +43 -0
  128. package/node_modules/@backendrelay/hatchet/dist/esm/index.d.ts.map +1 -0
  129. package/node_modules/@backendrelay/hatchet/dist/esm/index.js +59 -0
  130. package/node_modules/@backendrelay/hatchet/dist/esm/index.js.map +1 -0
  131. package/node_modules/@backendrelay/hatchet/dist/esm/package.json +3 -0
  132. package/node_modules/@backendrelay/hatchet/package.json +46 -0
  133. package/node_modules/@backendrelay/platform/dist/commonjs/ProgressPromise.d.ts +18 -0
  134. package/node_modules/@backendrelay/platform/dist/commonjs/ProgressPromise.d.ts.map +1 -0
  135. package/node_modules/@backendrelay/platform/dist/commonjs/ProgressPromise.js +77 -0
  136. package/node_modules/@backendrelay/platform/dist/commonjs/ProgressPromise.js.map +1 -0
  137. package/node_modules/@backendrelay/platform/dist/commonjs/api/apps.d.ts +99 -0
  138. package/node_modules/@backendrelay/platform/dist/commonjs/api/apps.d.ts.map +1 -0
  139. package/node_modules/@backendrelay/platform/dist/commonjs/api/apps.js +177 -0
  140. package/node_modules/@backendrelay/platform/dist/commonjs/api/apps.js.map +1 -0
  141. package/node_modules/@backendrelay/platform/dist/commonjs/api/auth.d.ts +7 -0
  142. package/node_modules/@backendrelay/platform/dist/commonjs/api/auth.d.ts.map +1 -0
  143. package/node_modules/@backendrelay/platform/dist/commonjs/api/auth.js +15 -0
  144. package/node_modules/@backendrelay/platform/dist/commonjs/api/auth.js.map +1 -0
  145. package/node_modules/@backendrelay/platform/dist/commonjs/api/http.d.ts +3 -0
  146. package/node_modules/@backendrelay/platform/dist/commonjs/api/http.d.ts.map +1 -0
  147. package/node_modules/@backendrelay/platform/dist/commonjs/api/http.js +46 -0
  148. package/node_modules/@backendrelay/platform/dist/commonjs/api/http.js.map +1 -0
  149. package/node_modules/@backendrelay/platform/dist/commonjs/api/perms.d.ts +13 -0
  150. package/node_modules/@backendrelay/platform/dist/commonjs/api/perms.d.ts.map +1 -0
  151. package/node_modules/@backendrelay/platform/dist/commonjs/api/perms.js +25 -0
  152. package/node_modules/@backendrelay/platform/dist/commonjs/api/perms.js.map +1 -0
  153. package/node_modules/@backendrelay/platform/dist/commonjs/api/platform-api.d.ts +285 -0
  154. package/node_modules/@backendrelay/platform/dist/commonjs/api/platform-api.d.ts.map +1 -0
  155. package/node_modules/@backendrelay/platform/dist/commonjs/api/platform-api.js +426 -0
  156. package/node_modules/@backendrelay/platform/dist/commonjs/api/platform-api.js.map +1 -0
  157. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema-coerce.d.ts +24 -0
  158. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema-coerce.d.ts.map +1 -0
  159. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema-coerce.js +108 -0
  160. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema-coerce.js.map +1 -0
  161. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema.d.ts +188 -0
  162. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema.d.ts.map +1 -0
  163. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema.js +412 -0
  164. package/node_modules/@backendrelay/platform/dist/commonjs/api/schema.js.map +1 -0
  165. package/node_modules/@backendrelay/platform/dist/commonjs/api.d.ts +9 -0
  166. package/node_modules/@backendrelay/platform/dist/commonjs/api.d.ts.map +1 -0
  167. package/node_modules/@backendrelay/platform/dist/commonjs/api.js +12 -0
  168. package/node_modules/@backendrelay/platform/dist/commonjs/api.js.map +1 -0
  169. package/node_modules/@backendrelay/platform/dist/commonjs/backupDownload.d.ts +89 -0
  170. package/node_modules/@backendrelay/platform/dist/commonjs/backupDownload.d.ts.map +1 -0
  171. package/node_modules/@backendrelay/platform/dist/commonjs/backupDownload.js +357 -0
  172. package/node_modules/@backendrelay/platform/dist/commonjs/backupDownload.js.map +1 -0
  173. package/node_modules/@backendrelay/platform/dist/commonjs/backups.d.ts +146 -0
  174. package/node_modules/@backendrelay/platform/dist/commonjs/backups.d.ts.map +1 -0
  175. package/node_modules/@backendrelay/platform/dist/commonjs/backups.js +251 -0
  176. package/node_modules/@backendrelay/platform/dist/commonjs/backups.js.map +1 -0
  177. package/node_modules/@backendrelay/platform/dist/commonjs/clerk.d.ts +2 -0
  178. package/node_modules/@backendrelay/platform/dist/commonjs/clerk.d.ts.map +1 -0
  179. package/node_modules/@backendrelay/platform/dist/commonjs/clerk.js +29 -0
  180. package/node_modules/@backendrelay/platform/dist/commonjs/clerk.js.map +1 -0
  181. package/node_modules/@backendrelay/platform/dist/commonjs/consts.d.ts +11 -0
  182. package/node_modules/@backendrelay/platform/dist/commonjs/consts.d.ts.map +1 -0
  183. package/node_modules/@backendrelay/platform/dist/commonjs/consts.js +17 -0
  184. package/node_modules/@backendrelay/platform/dist/commonjs/consts.js.map +1 -0
  185. package/node_modules/@backendrelay/platform/dist/commonjs/crypto.d.ts +4 -0
  186. package/node_modules/@backendrelay/platform/dist/commonjs/crypto.d.ts.map +1 -0
  187. package/node_modules/@backendrelay/platform/dist/commonjs/crypto.js +26 -0
  188. package/node_modules/@backendrelay/platform/dist/commonjs/crypto.js.map +1 -0
  189. package/node_modules/@backendrelay/platform/dist/commonjs/index.d.ts +19 -0
  190. package/node_modules/@backendrelay/platform/dist/commonjs/index.d.ts.map +1 -0
  191. package/node_modules/@backendrelay/platform/dist/commonjs/index.js +76 -0
  192. package/node_modules/@backendrelay/platform/dist/commonjs/index.js.map +1 -0
  193. package/node_modules/@backendrelay/platform/dist/commonjs/migrationUtils.d.ts +4 -0
  194. package/node_modules/@backendrelay/platform/dist/commonjs/migrationUtils.d.ts.map +1 -0
  195. package/node_modules/@backendrelay/platform/dist/commonjs/migrationUtils.js +52 -0
  196. package/node_modules/@backendrelay/platform/dist/commonjs/migrationUtils.js.map +1 -0
  197. package/node_modules/@backendrelay/platform/dist/commonjs/migrations.d.ts +99 -0
  198. package/node_modules/@backendrelay/platform/dist/commonjs/migrations.d.ts.map +1 -0
  199. package/node_modules/@backendrelay/platform/dist/commonjs/migrations.js +597 -0
  200. package/node_modules/@backendrelay/platform/dist/commonjs/migrations.js.map +1 -0
  201. package/node_modules/@backendrelay/platform/dist/commonjs/oauth.d.ts +98 -0
  202. package/node_modules/@backendrelay/platform/dist/commonjs/oauth.d.ts.map +1 -0
  203. package/node_modules/@backendrelay/platform/dist/commonjs/oauth.js +275 -0
  204. package/node_modules/@backendrelay/platform/dist/commonjs/oauth.js.map +1 -0
  205. package/node_modules/@backendrelay/platform/dist/commonjs/oauthCommon.d.ts +12 -0
  206. package/node_modules/@backendrelay/platform/dist/commonjs/oauthCommon.d.ts.map +1 -0
  207. package/node_modules/@backendrelay/platform/dist/commonjs/oauthCommon.js +26 -0
  208. package/node_modules/@backendrelay/platform/dist/commonjs/oauthCommon.js.map +1 -0
  209. package/node_modules/@backendrelay/platform/dist/commonjs/package.json +3 -0
  210. package/node_modules/@backendrelay/platform/dist/commonjs/perms.d.ts +3 -0
  211. package/node_modules/@backendrelay/platform/dist/commonjs/perms.d.ts.map +1 -0
  212. package/node_modules/@backendrelay/platform/dist/commonjs/perms.js +66 -0
  213. package/node_modules/@backendrelay/platform/dist/commonjs/perms.js.map +1 -0
  214. package/node_modules/@backendrelay/platform/dist/commonjs/privateFields.d.ts +13 -0
  215. package/node_modules/@backendrelay/platform/dist/commonjs/privateFields.d.ts.map +1 -0
  216. package/node_modules/@backendrelay/platform/dist/commonjs/privateFields.js +31 -0
  217. package/node_modules/@backendrelay/platform/dist/commonjs/privateFields.js.map +1 -0
  218. package/node_modules/@backendrelay/platform/dist/commonjs/relationships.d.ts +7 -0
  219. package/node_modules/@backendrelay/platform/dist/commonjs/relationships.d.ts.map +1 -0
  220. package/node_modules/@backendrelay/platform/dist/commonjs/relationships.js +46 -0
  221. package/node_modules/@backendrelay/platform/dist/commonjs/relationships.js.map +1 -0
  222. package/node_modules/@backendrelay/platform/dist/commonjs/schema.d.ts +161 -0
  223. package/node_modules/@backendrelay/platform/dist/commonjs/schema.d.ts.map +1 -0
  224. package/node_modules/@backendrelay/platform/dist/commonjs/schema.js +174 -0
  225. package/node_modules/@backendrelay/platform/dist/commonjs/schema.js.map +1 -0
  226. package/node_modules/@backendrelay/platform/dist/commonjs/serverOAuth.d.ts +25 -0
  227. package/node_modules/@backendrelay/platform/dist/commonjs/serverOAuth.d.ts.map +1 -0
  228. package/node_modules/@backendrelay/platform/dist/commonjs/serverOAuth.js +68 -0
  229. package/node_modules/@backendrelay/platform/dist/commonjs/serverOAuth.js.map +1 -0
  230. package/node_modules/@backendrelay/platform/dist/commonjs/typescript-schema.d.ts +17 -0
  231. package/node_modules/@backendrelay/platform/dist/commonjs/typescript-schema.d.ts.map +1 -0
  232. package/node_modules/@backendrelay/platform/dist/commonjs/typescript-schema.js +314 -0
  233. package/node_modules/@backendrelay/platform/dist/commonjs/typescript-schema.js.map +1 -0
  234. package/node_modules/@backendrelay/platform/dist/commonjs/util.d.ts +13 -0
  235. package/node_modules/@backendrelay/platform/dist/commonjs/util.d.ts.map +1 -0
  236. package/node_modules/@backendrelay/platform/dist/commonjs/util.js +55 -0
  237. package/node_modules/@backendrelay/platform/dist/commonjs/util.js.map +1 -0
  238. package/node_modules/@backendrelay/platform/dist/commonjs/version.d.ts +3 -0
  239. package/node_modules/@backendrelay/platform/dist/commonjs/version.d.ts.map +1 -0
  240. package/node_modules/@backendrelay/platform/dist/commonjs/version.js +5 -0
  241. package/node_modules/@backendrelay/platform/dist/commonjs/version.js.map +1 -0
  242. package/node_modules/@backendrelay/platform/dist/esm/ProgressPromise.d.ts +18 -0
  243. package/node_modules/@backendrelay/platform/dist/esm/ProgressPromise.d.ts.map +1 -0
  244. package/node_modules/@backendrelay/platform/dist/esm/ProgressPromise.js +73 -0
  245. package/node_modules/@backendrelay/platform/dist/esm/ProgressPromise.js.map +1 -0
  246. package/node_modules/@backendrelay/platform/dist/esm/api/apps.d.ts +99 -0
  247. package/node_modules/@backendrelay/platform/dist/esm/api/apps.d.ts.map +1 -0
  248. package/node_modules/@backendrelay/platform/dist/esm/api/apps.js +165 -0
  249. package/node_modules/@backendrelay/platform/dist/esm/api/apps.js.map +1 -0
  250. package/node_modules/@backendrelay/platform/dist/esm/api/auth.d.ts +7 -0
  251. package/node_modules/@backendrelay/platform/dist/esm/api/auth.d.ts.map +1 -0
  252. package/node_modules/@backendrelay/platform/dist/esm/api/auth.js +12 -0
  253. package/node_modules/@backendrelay/platform/dist/esm/api/auth.js.map +1 -0
  254. package/node_modules/@backendrelay/platform/dist/esm/api/http.d.ts +3 -0
  255. package/node_modules/@backendrelay/platform/dist/esm/api/http.d.ts.map +1 -0
  256. package/node_modules/@backendrelay/platform/dist/esm/api/http.js +39 -0
  257. package/node_modules/@backendrelay/platform/dist/esm/api/http.js.map +1 -0
  258. package/node_modules/@backendrelay/platform/dist/esm/api/perms.d.ts +13 -0
  259. package/node_modules/@backendrelay/platform/dist/esm/api/perms.d.ts.map +1 -0
  260. package/node_modules/@backendrelay/platform/dist/esm/api/perms.js +21 -0
  261. package/node_modules/@backendrelay/platform/dist/esm/api/perms.js.map +1 -0
  262. package/node_modules/@backendrelay/platform/dist/esm/api/platform-api.d.ts +285 -0
  263. package/node_modules/@backendrelay/platform/dist/esm/api/platform-api.d.ts.map +1 -0
  264. package/node_modules/@backendrelay/platform/dist/esm/api/platform-api.js +421 -0
  265. package/node_modules/@backendrelay/platform/dist/esm/api/platform-api.js.map +1 -0
  266. package/node_modules/@backendrelay/platform/dist/esm/api/schema-coerce.d.ts +24 -0
  267. package/node_modules/@backendrelay/platform/dist/esm/api/schema-coerce.d.ts.map +1 -0
  268. package/node_modules/@backendrelay/platform/dist/esm/api/schema-coerce.js +99 -0
  269. package/node_modules/@backendrelay/platform/dist/esm/api/schema-coerce.js.map +1 -0
  270. package/node_modules/@backendrelay/platform/dist/esm/api/schema.d.ts +188 -0
  271. package/node_modules/@backendrelay/platform/dist/esm/api/schema.d.ts.map +1 -0
  272. package/node_modules/@backendrelay/platform/dist/esm/api/schema.js +393 -0
  273. package/node_modules/@backendrelay/platform/dist/esm/api/schema.js.map +1 -0
  274. package/node_modules/@backendrelay/platform/dist/esm/api.d.ts +9 -0
  275. package/node_modules/@backendrelay/platform/dist/esm/api.d.ts.map +1 -0
  276. package/node_modules/@backendrelay/platform/dist/esm/api.js +4 -0
  277. package/node_modules/@backendrelay/platform/dist/esm/api.js.map +1 -0
  278. package/node_modules/@backendrelay/platform/dist/esm/backupDownload.d.ts +89 -0
  279. package/node_modules/@backendrelay/platform/dist/esm/backupDownload.d.ts.map +1 -0
  280. package/node_modules/@backendrelay/platform/dist/esm/backupDownload.js +354 -0
  281. package/node_modules/@backendrelay/platform/dist/esm/backupDownload.js.map +1 -0
  282. package/node_modules/@backendrelay/platform/dist/esm/backups.d.ts +146 -0
  283. package/node_modules/@backendrelay/platform/dist/esm/backups.d.ts.map +1 -0
  284. package/node_modules/@backendrelay/platform/dist/esm/backups.js +240 -0
  285. package/node_modules/@backendrelay/platform/dist/esm/backups.js.map +1 -0
  286. package/node_modules/@backendrelay/platform/dist/esm/clerk.d.ts +2 -0
  287. package/node_modules/@backendrelay/platform/dist/esm/clerk.d.ts.map +1 -0
  288. package/node_modules/@backendrelay/platform/dist/esm/clerk.js +26 -0
  289. package/node_modules/@backendrelay/platform/dist/esm/clerk.js.map +1 -0
  290. package/node_modules/@backendrelay/platform/dist/esm/consts.d.ts +11 -0
  291. package/node_modules/@backendrelay/platform/dist/esm/consts.d.ts.map +1 -0
  292. package/node_modules/@backendrelay/platform/dist/esm/consts.js +13 -0
  293. package/node_modules/@backendrelay/platform/dist/esm/consts.js.map +1 -0
  294. package/node_modules/@backendrelay/platform/dist/esm/crypto.d.ts +4 -0
  295. package/node_modules/@backendrelay/platform/dist/esm/crypto.d.ts.map +1 -0
  296. package/node_modules/@backendrelay/platform/dist/esm/crypto.js +21 -0
  297. package/node_modules/@backendrelay/platform/dist/esm/crypto.js.map +1 -0
  298. package/node_modules/@backendrelay/platform/dist/esm/index.d.ts +19 -0
  299. package/node_modules/@backendrelay/platform/dist/esm/index.d.ts.map +1 -0
  300. package/node_modules/@backendrelay/platform/dist/esm/index.js +18 -0
  301. package/node_modules/@backendrelay/platform/dist/esm/index.js.map +1 -0
  302. package/node_modules/@backendrelay/platform/dist/esm/migrationUtils.d.ts +4 -0
  303. package/node_modules/@backendrelay/platform/dist/esm/migrationUtils.d.ts.map +1 -0
  304. package/node_modules/@backendrelay/platform/dist/esm/migrationUtils.js +47 -0
  305. package/node_modules/@backendrelay/platform/dist/esm/migrationUtils.js.map +1 -0
  306. package/node_modules/@backendrelay/platform/dist/esm/migrations.d.ts +99 -0
  307. package/node_modules/@backendrelay/platform/dist/esm/migrations.d.ts.map +1 -0
  308. package/node_modules/@backendrelay/platform/dist/esm/migrations.js +588 -0
  309. package/node_modules/@backendrelay/platform/dist/esm/migrations.js.map +1 -0
  310. package/node_modules/@backendrelay/platform/dist/esm/oauth.d.ts +98 -0
  311. package/node_modules/@backendrelay/platform/dist/esm/oauth.d.ts.map +1 -0
  312. package/node_modules/@backendrelay/platform/dist/esm/oauth.js +266 -0
  313. package/node_modules/@backendrelay/platform/dist/esm/oauth.js.map +1 -0
  314. package/node_modules/@backendrelay/platform/dist/esm/oauthCommon.d.ts +12 -0
  315. package/node_modules/@backendrelay/platform/dist/esm/oauthCommon.d.ts.map +1 -0
  316. package/node_modules/@backendrelay/platform/dist/esm/oauthCommon.js +22 -0
  317. package/node_modules/@backendrelay/platform/dist/esm/oauthCommon.js.map +1 -0
  318. package/node_modules/@backendrelay/platform/dist/esm/package.json +3 -0
  319. package/node_modules/@backendrelay/platform/dist/esm/perms.d.ts +3 -0
  320. package/node_modules/@backendrelay/platform/dist/esm/perms.d.ts.map +1 -0
  321. package/node_modules/@backendrelay/platform/dist/esm/perms.js +62 -0
  322. package/node_modules/@backendrelay/platform/dist/esm/perms.js.map +1 -0
  323. package/node_modules/@backendrelay/platform/dist/esm/privateFields.d.ts +13 -0
  324. package/node_modules/@backendrelay/platform/dist/esm/privateFields.d.ts.map +1 -0
  325. package/node_modules/@backendrelay/platform/dist/esm/privateFields.js +28 -0
  326. package/node_modules/@backendrelay/platform/dist/esm/privateFields.js.map +1 -0
  327. package/node_modules/@backendrelay/platform/dist/esm/relationships.d.ts +7 -0
  328. package/node_modules/@backendrelay/platform/dist/esm/relationships.d.ts.map +1 -0
  329. package/node_modules/@backendrelay/platform/dist/esm/relationships.js +43 -0
  330. package/node_modules/@backendrelay/platform/dist/esm/relationships.js.map +1 -0
  331. package/node_modules/@backendrelay/platform/dist/esm/schema.d.ts +161 -0
  332. package/node_modules/@backendrelay/platform/dist/esm/schema.d.ts.map +1 -0
  333. package/node_modules/@backendrelay/platform/dist/esm/schema.js +158 -0
  334. package/node_modules/@backendrelay/platform/dist/esm/schema.js.map +1 -0
  335. package/node_modules/@backendrelay/platform/dist/esm/serverOAuth.d.ts +25 -0
  336. package/node_modules/@backendrelay/platform/dist/esm/serverOAuth.d.ts.map +1 -0
  337. package/node_modules/@backendrelay/platform/dist/esm/serverOAuth.js +64 -0
  338. package/node_modules/@backendrelay/platform/dist/esm/serverOAuth.js.map +1 -0
  339. package/node_modules/@backendrelay/platform/dist/esm/typescript-schema.d.ts +17 -0
  340. package/node_modules/@backendrelay/platform/dist/esm/typescript-schema.d.ts.map +1 -0
  341. package/node_modules/@backendrelay/platform/dist/esm/typescript-schema.js +310 -0
  342. package/node_modules/@backendrelay/platform/dist/esm/typescript-schema.js.map +1 -0
  343. package/node_modules/@backendrelay/platform/dist/esm/util.d.ts +13 -0
  344. package/node_modules/@backendrelay/platform/dist/esm/util.d.ts.map +1 -0
  345. package/node_modules/@backendrelay/platform/dist/esm/util.js +46 -0
  346. package/node_modules/@backendrelay/platform/dist/esm/util.js.map +1 -0
  347. package/node_modules/@backendrelay/platform/dist/esm/version.d.ts +3 -0
  348. package/node_modules/@backendrelay/platform/dist/esm/version.d.ts.map +1 -0
  349. package/node_modules/@backendrelay/platform/dist/esm/version.js +3 -0
  350. package/node_modules/@backendrelay/platform/dist/esm/version.js.map +1 -0
  351. package/node_modules/@backendrelay/platform/dist/standalone/index.js +13738 -0
  352. package/node_modules/@backendrelay/platform/dist/standalone/index.umd.cjs +72 -0
  353. package/node_modules/@backendrelay/platform/package.json +51 -0
  354. package/node_modules/@backendrelay/resumable-stream/dist/commonjs/index.d.ts +67 -0
  355. package/node_modules/@backendrelay/resumable-stream/dist/commonjs/index.d.ts.map +1 -0
  356. package/node_modules/@backendrelay/resumable-stream/dist/commonjs/index.js +129 -0
  357. package/node_modules/@backendrelay/resumable-stream/dist/commonjs/index.js.map +1 -0
  358. package/node_modules/@backendrelay/resumable-stream/dist/commonjs/package.json +3 -0
  359. package/node_modules/@backendrelay/resumable-stream/dist/esm/index.d.ts +67 -0
  360. package/node_modules/@backendrelay/resumable-stream/dist/esm/index.d.ts.map +1 -0
  361. package/node_modules/@backendrelay/resumable-stream/dist/esm/index.js +126 -0
  362. package/node_modules/@backendrelay/resumable-stream/dist/esm/index.js.map +1 -0
  363. package/node_modules/@backendrelay/resumable-stream/dist/esm/package.json +3 -0
  364. package/node_modules/@backendrelay/resumable-stream/dist/standalone/index.js +4354 -0
  365. package/node_modules/@backendrelay/resumable-stream/dist/standalone/index.umd.cjs +6 -0
  366. package/node_modules/@backendrelay/resumable-stream/package.json +47 -0
  367. package/node_modules/@backendrelay/rules/README.md +34 -0
  368. package/node_modules/@backendrelay/rules/dist/commonjs/index.d.ts +117 -0
  369. package/node_modules/@backendrelay/rules/dist/commonjs/index.d.ts.map +1 -0
  370. package/node_modules/@backendrelay/rules/dist/commonjs/index.js +68 -0
  371. package/node_modules/@backendrelay/rules/dist/commonjs/index.js.map +1 -0
  372. package/node_modules/@backendrelay/rules/dist/commonjs/package.json +3 -0
  373. package/node_modules/@backendrelay/rules/dist/esm/index.d.ts +117 -0
  374. package/node_modules/@backendrelay/rules/dist/esm/index.d.ts.map +1 -0
  375. package/node_modules/@backendrelay/rules/dist/esm/index.js +64 -0
  376. package/node_modules/@backendrelay/rules/dist/esm/index.js.map +1 -0
  377. package/node_modules/@backendrelay/rules/dist/esm/package.json +3 -0
  378. package/node_modules/@backendrelay/rules/package.json +46 -0
  379. package/node_modules/@backendrelay/test/README.md +75 -0
  380. package/node_modules/@backendrelay/test/dist/commonjs/index.d.ts +74 -0
  381. package/node_modules/@backendrelay/test/dist/commonjs/index.d.ts.map +1 -0
  382. package/node_modules/@backendrelay/test/dist/commonjs/index.js +197 -0
  383. package/node_modules/@backendrelay/test/dist/commonjs/index.js.map +1 -0
  384. package/node_modules/@backendrelay/test/dist/commonjs/live.e2e.test.d.ts +2 -0
  385. package/node_modules/@backendrelay/test/dist/commonjs/live.e2e.test.d.ts.map +1 -0
  386. package/node_modules/@backendrelay/test/dist/commonjs/live.e2e.test.js +45 -0
  387. package/node_modules/@backendrelay/test/dist/commonjs/live.e2e.test.js.map +1 -0
  388. package/node_modules/@backendrelay/test/dist/commonjs/package.json +3 -0
  389. package/node_modules/@backendrelay/test/dist/esm/index.d.ts +74 -0
  390. package/node_modules/@backendrelay/test/dist/esm/index.d.ts.map +1 -0
  391. package/node_modules/@backendrelay/test/dist/esm/index.js +192 -0
  392. package/node_modules/@backendrelay/test/dist/esm/index.js.map +1 -0
  393. package/node_modules/@backendrelay/test/dist/esm/live.e2e.test.d.ts +2 -0
  394. package/node_modules/@backendrelay/test/dist/esm/live.e2e.test.d.ts.map +1 -0
  395. package/node_modules/@backendrelay/test/dist/esm/live.e2e.test.js +43 -0
  396. package/node_modules/@backendrelay/test/dist/esm/live.e2e.test.js.map +1 -0
  397. package/node_modules/@backendrelay/test/dist/esm/package.json +3 -0
  398. package/node_modules/@backendrelay/test/package.json +49 -0
  399. package/node_modules/@backendrelay/version/dist/commonjs/index.d.ts +3 -0
  400. package/node_modules/@backendrelay/version/dist/commonjs/index.d.ts.map +1 -0
  401. package/node_modules/@backendrelay/version/dist/commonjs/index.js +6 -0
  402. package/node_modules/@backendrelay/version/dist/commonjs/index.js.map +1 -0
  403. package/node_modules/@backendrelay/version/dist/commonjs/package.json +3 -0
  404. package/node_modules/@backendrelay/version/dist/commonjs/version.d.ts +3 -0
  405. package/node_modules/@backendrelay/version/dist/commonjs/version.d.ts.map +1 -0
  406. package/node_modules/@backendrelay/version/dist/commonjs/version.js +10 -0
  407. package/node_modules/@backendrelay/version/dist/commonjs/version.js.map +1 -0
  408. package/node_modules/@backendrelay/version/dist/esm/index.d.ts +3 -0
  409. package/node_modules/@backendrelay/version/dist/esm/index.d.ts.map +1 -0
  410. package/node_modules/@backendrelay/version/dist/esm/index.js +3 -0
  411. package/node_modules/@backendrelay/version/dist/esm/index.js.map +1 -0
  412. package/node_modules/@backendrelay/version/dist/esm/package.json +3 -0
  413. package/node_modules/@backendrelay/version/dist/esm/version.d.ts +3 -0
  414. package/node_modules/@backendrelay/version/dist/esm/version.d.ts.map +1 -0
  415. package/node_modules/@backendrelay/version/dist/esm/version.js +7 -0
  416. package/node_modules/@backendrelay/version/dist/esm/version.js.map +1 -0
  417. package/node_modules/@backendrelay/version/dist/standalone/index.js +4 -0
  418. package/node_modules/@backendrelay/version/dist/standalone/index.umd.cjs +1 -0
  419. package/node_modules/@backendrelay/version/package.json +44 -0
  420. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typeUtils.d.ts +12 -0
  421. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
  422. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typeUtils.js +5 -0
  423. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typeUtils.js.map +1 -0
  424. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typesTests.d.ts +2 -0
  425. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
  426. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typesTests.js +82 -0
  427. package/node_modules/@backendrelay/webhooks/dist/commonjs/__types__/typesTests.js.map +1 -0
  428. package/node_modules/@backendrelay/webhooks/dist/commonjs/index.d.ts +607 -0
  429. package/node_modules/@backendrelay/webhooks/dist/commonjs/index.d.ts.map +1 -0
  430. package/node_modules/@backendrelay/webhooks/dist/commonjs/index.js +830 -0
  431. package/node_modules/@backendrelay/webhooks/dist/commonjs/index.js.map +1 -0
  432. package/node_modules/@backendrelay/webhooks/dist/commonjs/live.e2e.test.d.ts +2 -0
  433. package/node_modules/@backendrelay/webhooks/dist/commonjs/live.e2e.test.d.ts.map +1 -0
  434. package/node_modules/@backendrelay/webhooks/dist/commonjs/live.e2e.test.js +139 -0
  435. package/node_modules/@backendrelay/webhooks/dist/commonjs/live.e2e.test.js.map +1 -0
  436. package/node_modules/@backendrelay/webhooks/dist/commonjs/package.json +3 -0
  437. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typeUtils.d.ts +12 -0
  438. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typeUtils.d.ts.map +1 -0
  439. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typeUtils.js +4 -0
  440. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typeUtils.js.map +1 -0
  441. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typesTests.d.ts +2 -0
  442. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typesTests.d.ts.map +1 -0
  443. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typesTests.js +80 -0
  444. package/node_modules/@backendrelay/webhooks/dist/esm/__types__/typesTests.js.map +1 -0
  445. package/node_modules/@backendrelay/webhooks/dist/esm/index.d.ts +607 -0
  446. package/node_modules/@backendrelay/webhooks/dist/esm/index.d.ts.map +1 -0
  447. package/node_modules/@backendrelay/webhooks/dist/esm/index.js +825 -0
  448. package/node_modules/@backendrelay/webhooks/dist/esm/index.js.map +1 -0
  449. package/node_modules/@backendrelay/webhooks/dist/esm/live.e2e.test.d.ts +2 -0
  450. package/node_modules/@backendrelay/webhooks/dist/esm/live.e2e.test.d.ts.map +1 -0
  451. package/node_modules/@backendrelay/webhooks/dist/esm/live.e2e.test.js +137 -0
  452. package/node_modules/@backendrelay/webhooks/dist/esm/live.e2e.test.js.map +1 -0
  453. package/node_modules/@backendrelay/webhooks/dist/esm/package.json +3 -0
  454. package/node_modules/@backendrelay/webhooks/package.json +46 -0
  455. package/package.json +129 -56
  456. package/subpaths/admin/index.cjs +1 -0
  457. package/subpaths/admin/index.d.ts +1 -0
  458. package/subpaths/admin/index.mjs +3 -0
  459. package/subpaths/functions/index.cjs +1 -0
  460. package/subpaths/functions/index.d.ts +1 -0
  461. package/subpaths/functions/index.mjs +3 -0
  462. package/subpaths/hatchet/index.cjs +1 -0
  463. package/subpaths/hatchet/index.d.ts +1 -0
  464. package/subpaths/hatchet/index.mjs +3 -0
  465. package/subpaths/platform/index.cjs +1 -0
  466. package/subpaths/platform/index.d.ts +1 -0
  467. package/subpaths/platform/index.mjs +3 -0
  468. package/subpaths/resumable-stream/index.cjs +1 -0
  469. package/subpaths/resumable-stream/index.d.ts +1 -0
  470. package/subpaths/resumable-stream/index.mjs +3 -0
  471. package/subpaths/rules/index.cjs +1 -0
  472. package/subpaths/rules/index.d.ts +1 -0
  473. package/subpaths/rules/index.mjs +3 -0
  474. package/subpaths/test/index.cjs +1 -0
  475. package/subpaths/test/index.d.ts +1 -0
  476. package/subpaths/test/index.mjs +3 -0
  477. package/subpaths/version/index.cjs +1 -0
  478. package/subpaths/version/index.d.ts +1 -0
  479. package/subpaths/version/index.mjs +3 -0
  480. package/subpaths/webhooks/index.cjs +1 -0
  481. package/subpaths/webhooks/index.d.ts +1 -0
  482. package/subpaths/webhooks/index.mjs +3 -0
  483. package/.tshy/build.json +0 -8
  484. package/.tshy/commonjs.json +0 -16
  485. package/.tshy/esm.json +0 -15
  486. package/__example__/standalone.esm.html +0 -23
  487. package/__example__/standalone.umd.html +0 -21
  488. package/__tests__/src/Connection.test.ts +0 -292
  489. package/__tests__/src/IndexedDBStorage.test.ts +0 -96
  490. package/__tests__/src/Reactor.test.ts +0 -1179
  491. package/__tests__/src/auth-extra-fields.e2e.test.ts +0 -160
  492. package/__tests__/src/byop.e2e.test.ts +0 -762
  493. package/__tests__/src/config.test.ts +0 -85
  494. package/__tests__/src/cookieSync.e2e.test.ts +0 -163
  495. package/__tests__/src/data/movies/attrs.json +0 -145
  496. package/__tests__/src/data/movies/triples.json +0 -1507
  497. package/__tests__/src/data/zeneca/attrs.json +0 -251
  498. package/__tests__/src/data/zeneca/triples.json +0 -15854
  499. package/__tests__/src/datalog.test.ts +0 -175
  500. package/__tests__/src/devtool.test.ts +0 -23
  501. package/__tests__/src/framework.test.ts +0 -173
  502. package/__tests__/src/infiniteQuery.e2e.test.ts +0 -467
  503. package/__tests__/src/instaml.test.ts +0 -1593
  504. package/__tests__/src/instaql.bench.ts +0 -34
  505. package/__tests__/src/instaql.test.ts +0 -1497
  506. package/__tests__/src/instaqlInference.test.ts +0 -243
  507. package/__tests__/src/presence.test.ts +0 -49
  508. package/__tests__/src/queryValidation.test.ts +0 -1101
  509. package/__tests__/src/schema.test.ts +0 -653
  510. package/__tests__/src/serializeSchema.test.ts +0 -123
  511. package/__tests__/src/simple.e2e.test.ts +0 -133
  512. package/__tests__/src/storage-upload.test.ts +0 -37
  513. package/__tests__/src/store.test.ts +0 -960
  514. package/__tests__/src/syncTable.e2e.test.ts +0 -245
  515. package/__tests__/src/syncTable.test.ts +0 -235
  516. package/__tests__/src/transactionValidation.test.ts +0 -450
  517. package/__tests__/src/typeUtils.ts +0 -39
  518. package/__tests__/src/upstream-improvements.e2e.test.ts +0 -54
  519. package/__tests__/src/utils/MutationStorage.test.ts +0 -77
  520. package/__tests__/src/utils/PersistedObject.test.ts +0 -569
  521. package/__tests__/src/utils/dates.test.ts +0 -111
  522. package/__tests__/src/utils/e2e.ts +0 -100
  523. package/__tests__/src/utils/msw.ts +0 -3
  524. package/__tests__/src/utils/object.test.ts +0 -78
  525. package/__tests__/src/utils/weakHash.test.ts +0 -68
  526. package/__tests__/src/utils/weakHashLegacy.test.ts +0 -22
  527. package/__tests__/src/vite.env.d.ts +0 -1
  528. package/src/BackendRelayError.ts +0 -50
  529. package/src/Connection.ts +0 -361
  530. package/src/InMemoryStorage.ts +0 -34
  531. package/src/IndexedDBStorage.ts +0 -398
  532. package/src/Reactor.js +0 -1541
  533. package/src/StorageAPI.ts +0 -147
  534. package/src/Stream.ts +0 -1252
  535. package/src/SyncTable.ts +0 -750
  536. package/src/WindowNetworkListener.js +0 -19
  537. package/src/__types__/fieldsTypeTest.ts +0 -111
  538. package/src/__types__/typeUtils.ts +0 -39
  539. package/src/__types__/useDatesTypeTest.ts +0 -66
  540. package/src/attrTypes.ts +0 -37
  541. package/src/authAPI.ts +0 -205
  542. package/src/clientTypes.ts +0 -28
  543. package/src/coreTypes.ts +0 -58
  544. package/src/createRouteHandler.ts +0 -68
  545. package/src/datalog.js +0 -116
  546. package/src/devtool.ts +0 -179
  547. package/src/framework.ts +0 -450
  548. package/src/helperTypes.ts +0 -117
  549. package/src/index.ts +0 -1293
  550. package/src/infiniteQuery.ts +0 -599
  551. package/src/instaml.ts +0 -676
  552. package/src/instaql.ts +0 -999
  553. package/src/instatx.ts +0 -265
  554. package/src/model/instaqlResult.js +0 -25
  555. package/src/parseSchemaFromJSON.ts +0 -176
  556. package/src/presence.ts +0 -123
  557. package/src/presenceTypes.ts +0 -19
  558. package/src/queryTypes.ts +0 -749
  559. package/src/queryValidation.ts +0 -598
  560. package/src/reactorAuth.js +0 -236
  561. package/src/reactorEvents.js +0 -414
  562. package/src/reactorMutations.js +0 -354
  563. package/src/reactorRooms.js +0 -297
  564. package/src/reactorStorage.js +0 -180
  565. package/src/reactorSubs.js +0 -275
  566. package/src/reactorTransport.js +0 -391
  567. package/src/reactorTypes.ts +0 -41
  568. package/src/routeHandlerProtocol.ts +0 -25
  569. package/src/rulesTypes.ts +0 -132
  570. package/src/sanityCheckQueries.ts +0 -191
  571. package/src/schema.ts +0 -206
  572. package/src/schemaTypes.ts +0 -664
  573. package/src/store.ts +0 -1165
  574. package/src/transactionValidation.ts +0 -204
  575. package/src/urls.ts +0 -50
  576. package/src/utils/Deferred.ts +0 -20
  577. package/src/utils/MutationStorage.ts +0 -89
  578. package/src/utils/PersistedObject.ts +0 -612
  579. package/src/utils/dates.ts +0 -269
  580. package/src/utils/error.ts +0 -9
  581. package/src/utils/fetch.ts +0 -131
  582. package/src/utils/flags.ts +0 -14
  583. package/src/utils/id.ts +0 -28
  584. package/src/utils/linkIndex.ts +0 -33
  585. package/src/utils/log.ts +0 -23
  586. package/src/utils/object.js +0 -180
  587. package/src/utils/pgtime.ts +0 -199
  588. package/src/utils/pick.js +0 -9
  589. package/src/utils/strings.ts +0 -19
  590. package/src/utils/weakHash.ts +0 -77
  591. package/src/utils/weakHashLegacy.ts +0 -75
  592. package/src/warningToggle.ts +0 -5
  593. package/tsconfig.cjs.dev.json +0 -15
  594. package/tsconfig.dev.json +0 -14
  595. package/tsconfig.json +0 -13
  596. package/tsconfig.test.json +0 -5
  597. package/vite.config.ts +0 -19
  598. package/vitest.config.ts +0 -54
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perms.js","sourceRoot":"","sources":["../../src/perms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA+B,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,UAAU,2BAA2B,CACzC,SAAqC,EACrC,sBAA8B;IAE9B,MAAM,QAAQ,GACZ,SAAS,IAAI,MAAM,CAAC,I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CAAC;IACH,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { parse, type ParseResult, type File } from '@babel/parser';\nimport { astToJson } from './typescript-schema.ts';\n\nexport function generatePermsTypescriptFile(\n permsCode: null | Record<string, any>,\n backendrelayModuleName: string,\n) {\n const rulesTxt =\n permsCode && Object.keys(permsCode).length\n ? JSON.stringify(permsCode, null, 2)\n : `{\n /**\n * Welcome to BackendRelay's permission system!\n * Right now your rules are empty. To start filling them in, check out the docs:\n * https://www.backendrelay.com/docs/permissions\n *\n * Here's an example to give you a feel:\n * posts: {\n * allow: {\n * view: \"true\",\n * create: \"isOwner\",\n * update: \"isOwner\",\n * delete: \"isOwner\",\n * },\n * bind: {\"isOwner\": \"auth.id != null && auth.id == data.ownerId\"},\n * },\n */\n}\n`.trim();\n\n return `// Docs: https://www.backendrelay.com/docs/permissions\n\nimport type { BackendRelayRules } from \"${backendrelayModuleName ?? '@backendrelay/core'}\";\n\nconst rules = ${rulesTxt} satisfies BackendRelayRules;\n\nexport default rules;\n`;\n}\n\nfunction astToPermsCode(ast: ParseResult<File>): Record<string, any> {\n for (const n of ast.program.body) {\n if (\n n.type !== 'VariableDeclaration' ||\n n.declarations.length !== 1 ||\n n.declarations[0].id.type !== 'Identifier' ||\n n.declarations[0].id.name !== 'rules'\n ) {\n continue;\n }\n\n const node = n.declarations[0];\n\n if (!node.init || node.init.type !== 'TSSatisfiesExpression') {\n throw new Error(`Could not extract rules`);\n }\n\n return astToJson(node.init.expression) as Record<string, any>;\n }\n\n throw new Error(\n 'Could not extract rules, did not find the rules variable declaration.',\n );\n}\n\nexport function permsTypescriptFileToCode(\n content: string,\n sourceFilename: string,\n) {\n const ast = parse(content, {\n sourceFilename,\n sourceType: 'module',\n errorRecovery: false,\n plugins: ['typescript'],\n });\n if (ast.errors?.length) {\n throw new Error(`Could not parse perms file. ${ast.errors[0].reasonCode}.`);\n }\n\n return astToPermsCode(ast);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { BackendRelaySchemaDef } from '@backendrelay/core';
2
+ type RulesDocument = Record<string, any>;
3
+ /**
4
+ * Adds a `fields.<label>: "false"` rule for every attribute marked
5
+ * `.private()` in the schema, unless the rules already define a field rule.
6
+ *
7
+ * The server already hides fields that have a field rule; this compiles the
8
+ * schema's private marker into that rule at push time, so no extra server
9
+ * state is needed.
10
+ */
11
+ export declare function applyPrivateFieldRules<Schema extends BackendRelaySchemaDef<any, any, any>, Rules extends RulesDocument>(schema: Schema, rules: Rules): Rules;
12
+ export {};
13
+ //# sourceMappingURL=privateFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privateFields.d.ts","sourceRoot":"","sources":["../../src/privateFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEzC;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACnD,KAAK,SAAS,aAAa,EAC3B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAoBrC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Adds a `fields.<label>: "false"` rule for every attribute marked
3
+ * `.private()` in the schema, unless the rules already define a field rule.
4
+ *
5
+ * The server already hides fields that have a field rule; this compiles the
6
+ * schema's private marker into that rule at push time, so no extra server
7
+ * state is needed.
8
+ */
9
+ export function applyPrivateFieldRules(schema, rules) {
10
+ const code = structuredClone(rules);
11
+ const entities = schema.entities;
12
+ for (const [etype, entity] of Object.entries(entities)) {
13
+ if (etype.startsWith('$'))
14
+ continue;
15
+ for (const [label, attr] of Object.entries(entity.attrs)) {
16
+ if (!attr.config?.private) {
17
+ continue;
18
+ }
19
+ const entityRules = (code[etype] ??= {});
20
+ const fields = (entityRules.fields ??= {});
21
+ if (fields[label] === undefined) {
22
+ fields[label] = 'false';
23
+ }
24
+ }
25
+ }
26
+ return code;
27
+ }
28
+ //# sourceMappingURL=privateFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privateFields.js","sourceRoot":"","sources":["../../src/privateFields.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAGpC,MAAc,EAAE,KAAY;IAC5B,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAkB,CAAC;IACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAGvB,CAAC;IACF,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QACpC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,IAAI,CAAE,IAA2C,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;gBAClE,SAAS;YACX,CAAC;YACD,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,CAAC,WAAW,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC;YAC3C,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { BackendRelaySchemaDef } from '@backendrelay/core';\n\ntype RulesDocument = Record<string, any>;\n\n/**\n * Adds a `fields.<label>: \"false\"` rule for every attribute marked\n * `.private()` in the schema, unless the rules already define a field rule.\n *\n * The server already hides fields that have a field rule; this compiles the\n * schema's private marker into that rule at push time, so no extra server\n * state is needed.\n */\nexport function applyPrivateFieldRules<\n Schema extends BackendRelaySchemaDef<any, any, any>,\n Rules extends RulesDocument,\n>(schema: Schema, rules: Rules): Rules {\n const code = structuredClone(rules) as RulesDocument;\n const entities = schema.entities as Record<\n string,\n { attrs: Record<string, unknown> }\n >;\n for (const [etype, entity] of Object.entries(entities)) {\n if (etype.startsWith('$')) continue;\n for (const [label, attr] of Object.entries(entity.attrs)) {\n if (!(attr as { config?: { private?: boolean } }).config?.private) {\n continue;\n }\n const entityRules = (code[etype] ??= {});\n const fields = (entityRules.fields ??= {});\n if (fields[label] === undefined) {\n fields[label] = 'false';\n }\n }\n }\n return code as Rules;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export type RelationshipKinds = `many-many` | 'one-one' | 'one-many' | 'many-one';
2
+ export declare const relationshipConstraints: Record<RelationshipKinds, {
3
+ cardinality: 'one' | 'many';
4
+ 'unique?': boolean;
5
+ }>;
6
+ export declare const relationshipConstraintsInverse: Record<string, RelationshipKinds>;
7
+ //# sourceMappingURL=relationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../src/relationships.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,SAAS,GACT,UAAU,GACV,UAAU,CAAC;AAEf,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,iBAAiB,EACjB;IAAE,WAAW,EAAE,KAAK,GAAG,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAuCpD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAM1E,CAAC"}
@@ -0,0 +1,43 @@
1
+ export const relationshipConstraints = {
2
+ /**
3
+ * users has_many tags
4
+ * tags has_many users
5
+ */
6
+ 'many-many': {
7
+ cardinality: 'many',
8
+ 'unique?': false,
9
+ },
10
+ /**
11
+ * users has_one profile
12
+ * profiles has_one owner
13
+ */
14
+ 'one-one': {
15
+ cardinality: 'one',
16
+ 'unique?': true,
17
+ },
18
+ /**
19
+ * users has_many posts
20
+ * posts has_one author
21
+ * [?users :users/posts ?posts]
22
+ * <---------------> unique!
23
+ */
24
+ 'many-one': {
25
+ cardinality: 'many',
26
+ 'unique?': true,
27
+ },
28
+ /**
29
+ * posts has_one owner
30
+ * users has_many owned_posts
31
+ * [?posts :posts/user ?users]
32
+ * <---------------> unique!
33
+ */
34
+ 'one-many': {
35
+ cardinality: 'one',
36
+ 'unique?': false,
37
+ },
38
+ };
39
+ export const relationshipConstraintsInverse = Object.fromEntries(Object.entries(relationshipConstraints).map(([k, v]) => [
40
+ `${v.cardinality}-${v['unique?']}`,
41
+ k,
42
+ ]));
43
+ //# sourceMappingURL=relationships.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationships.js","sourceRoot":"","sources":["../../src/relationships.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACF;;;OAGG;IACH,WAAW,EAAE;QACX,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,KAAK;KACjB;IACD;;;OAGG;IACH,SAAS,EAAE;QACT,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,IAAI;KAChB;IACD;;;;;OAKG;IACH,UAAU,EAAE;QACV,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,IAAI;KAChB;IAED;;;;;OAKG;IACH,UAAU,EAAE;QACV,WAAW,EAAE,KAAK;QAClB,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GACzC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACtD,GAAG,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,CAAC,EAAE;IAClC,CAAsB;CACvB,CAAC,CACH,CAAC","sourcesContent":["// Copied from www/lib/relationships.ts\nexport type RelationshipKinds =\n | `many-many`\n | 'one-one'\n | 'one-many'\n | 'many-one';\n\nexport const relationshipConstraints: Record<\n RelationshipKinds,\n { cardinality: 'one' | 'many'; 'unique?': boolean }\n> = {\n /**\n * users has_many tags\n * tags has_many users\n */\n 'many-many': {\n cardinality: 'many',\n 'unique?': false,\n },\n /**\n * users has_one profile\n * profiles has_one owner\n */\n 'one-one': {\n cardinality: 'one',\n 'unique?': true,\n },\n /**\n * users has_many posts\n * posts has_one author\n * [?users :users/posts ?posts]\n * <---------------> unique!\n */\n 'many-one': {\n cardinality: 'many',\n 'unique?': true,\n },\n\n /**\n * posts has_one owner\n * users has_many owned_posts\n * [?posts :posts/user ?users]\n * <---------------> unique!\n */\n 'one-many': {\n cardinality: 'one',\n 'unique?': false,\n },\n};\n\nexport const relationshipConstraintsInverse: Record<string, RelationshipKinds> =\n Object.fromEntries(\n Object.entries(relationshipConstraints).map(([k, v]) => [\n `${v.cardinality}-${v['unique?']}`,\n k as RelationshipKinds,\n ]),\n );\n"]}
@@ -0,0 +1,161 @@
1
+ import { BackendRelayDBAttr, BackendRelayDBCheckedDataType, BackendRelayDBIdent } from '@backendrelay/core';
2
+ import { GenericSchemaDef } from './util.ts';
3
+ export type BackendRelayAPIPlatformSchema = {
4
+ refs: Record<string, BackendRelayDBAttr>;
5
+ blobs: Record<string, Record<string, BackendRelayDBAttr>>;
6
+ };
7
+ export type BackendRelayAPISchemaPlanAddAttrStep = {
8
+ type: 'add-attr';
9
+ friendlyDescription: string;
10
+ attr: BackendRelayDBAttr;
11
+ };
12
+ export type BackendRelayAPISchemaPlanDeleteAttrStep = {
13
+ type: 'delete-attr';
14
+ friendlyDescription: string;
15
+ attrId: string;
16
+ };
17
+ export type BackendRelayAPISchemaPlanUpdateAttrStep = {
18
+ type: 'update-attr';
19
+ friendlyDescription: string;
20
+ attr: BackendRelayDBAttr;
21
+ };
22
+ export type BackendRelayAPISchemaPlanIndexStep = {
23
+ type: 'index';
24
+ friendlyDescription: string;
25
+ attrId: string;
26
+ forwardIdentity: BackendRelayDBIdent;
27
+ };
28
+ export type BackendRelayAPISchemaPlanRemoveIndexStep = {
29
+ type: 'remove-index';
30
+ friendlyDescription: string;
31
+ attrId: string;
32
+ forwardIdentity: BackendRelayDBIdent;
33
+ };
34
+ export type BackendRelayAPISchemaPlanUniqueStep = {
35
+ type: 'unique';
36
+ friendlyDescription: string;
37
+ attrId: string;
38
+ forwardIdentity: BackendRelayDBIdent;
39
+ };
40
+ export type BackendRelayAPISchemaPlanRemoveUniqueStep = {
41
+ type: 'remove-unique';
42
+ friendlyDescription: string;
43
+ attrId: string;
44
+ forwardIdentity: BackendRelayDBIdent;
45
+ };
46
+ export type BackendRelayAPISchemaPlanRequiredStep = {
47
+ type: 'required';
48
+ friendlyDescription: string;
49
+ attrId: string;
50
+ forwardIdentity: BackendRelayDBIdent;
51
+ };
52
+ export type BackendRelayAPISchemaPlanRemoveRequiredStep = {
53
+ type: 'remove-required';
54
+ friendlyDescription: string;
55
+ attrId: string;
56
+ forwardIdentity: BackendRelayDBIdent;
57
+ };
58
+ export type BackendRelayAPISchemaPlanCheckDataTypeStep = {
59
+ type: 'check-data-type';
60
+ friendlyDescription: string;
61
+ attrId: string;
62
+ forwardIdentity: BackendRelayDBIdent;
63
+ checkedDataType: BackendRelayDBCheckedDataType;
64
+ };
65
+ export type BackendRelayAPISchemaPlanRemoveDataTypeStep = {
66
+ type: 'remove-data-type';
67
+ friendlyDescription: string;
68
+ attrId: string;
69
+ forwardIdentity: BackendRelayDBIdent;
70
+ };
71
+ type BackendRelayBackgroundSchemaBaseJob = {
72
+ id: string;
73
+ createdAt: Date;
74
+ updatedAt: Date;
75
+ status: 'completed' | 'waiting' | 'processing' | 'errored';
76
+ workEstimate: number | null;
77
+ workCompleted: number | null;
78
+ error?: 'invalid-triple-error' | 'invalid-attr-state-error' | 'triple-not-unique-error' | 'triple-too-large-error' | 'missing-required-error' | 'unexpected-error';
79
+ invalidTriplesSample?: {
80
+ entityId: string;
81
+ value: any;
82
+ jsonType: 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'date';
83
+ }[];
84
+ };
85
+ type BackendRelayBackgroundSchemaBaseJobWithInvalidTriples = BackendRelayBackgroundSchemaBaseJob & {
86
+ invalidTriplesSample?: {
87
+ entityId: string;
88
+ value: any;
89
+ jsonType: 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'date';
90
+ }[];
91
+ };
92
+ export interface BackendRelayBackgroundSchemaRemoveDataTypeJob extends BackendRelayBackgroundSchemaBaseJob {
93
+ type: 'remove-data-type';
94
+ }
95
+ export interface BackendRelayBackgroundSchemaCheckDataTypeJob extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {
96
+ type: 'check-data-type';
97
+ checkedDataType: BackendRelayDBCheckedDataType;
98
+ }
99
+ export interface BackendRelayBackgroundSchemaAddIndexJob extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {
100
+ type: 'index';
101
+ }
102
+ export interface BackendRelayBackgroundSchemaRemoveIndexJob extends BackendRelayBackgroundSchemaBaseJob {
103
+ type: 'remove-index';
104
+ }
105
+ export interface BackendRelayBackgroundSchemaAddUniqueJob extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {
106
+ type: 'unique';
107
+ invalidUniqueValue?: any;
108
+ }
109
+ export interface BackendRelayBackgroundSchemaRemoveUniqueJob extends BackendRelayBackgroundSchemaBaseJob {
110
+ type: 'remove-unique';
111
+ }
112
+ export interface BackendRelayBackgroundSchemaAddRequiredJob extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {
113
+ type: 'required';
114
+ }
115
+ export interface BackendRelayBackgroundSchemaRemoveRequiredJob extends BackendRelayBackgroundSchemaBaseJob {
116
+ type: 'remove-required';
117
+ }
118
+ export type BackendRelayAPISchemaPlanStep = BackendRelayAPISchemaPlanAddAttrStep | BackendRelayAPISchemaPlanDeleteAttrStep | BackendRelayAPISchemaPlanUpdateAttrStep | BackendRelayAPISchemaPlanIndexStep | BackendRelayAPISchemaPlanRemoveIndexStep | BackendRelayAPISchemaPlanUniqueStep | BackendRelayAPISchemaPlanRemoveUniqueStep | BackendRelayAPISchemaPlanRequiredStep | BackendRelayAPISchemaPlanRemoveRequiredStep | BackendRelayAPISchemaPlanCheckDataTypeStep | BackendRelayAPISchemaPlanRemoveDataTypeStep;
119
+ type BackgroundJobByStep = {
120
+ index: BackendRelayBackgroundSchemaAddIndexJob;
121
+ 'remove-index': BackendRelayBackgroundSchemaRemoveIndexJob;
122
+ unique: BackendRelayBackgroundSchemaAddUniqueJob;
123
+ 'remove-unique': BackendRelayBackgroundSchemaRemoveUniqueJob;
124
+ required: BackendRelayBackgroundSchemaAddRequiredJob;
125
+ 'remove-required': BackendRelayBackgroundSchemaRemoveRequiredJob;
126
+ 'check-data-type': BackendRelayBackgroundSchemaCheckDataTypeJob;
127
+ 'remove-data-type': BackendRelayBackgroundSchemaRemoveDataTypeJob;
128
+ };
129
+ export type WithBackgroundJob<P extends {
130
+ type: string;
131
+ }> = P['type'] extends keyof BackgroundJobByStep ? P & {
132
+ backgroundJob: BackgroundJobByStep[P['type']];
133
+ } : P;
134
+ export type BackendRelayAPISchemaPushAddAttrStep = WithBackgroundJob<BackendRelayAPISchemaPlanAddAttrStep>;
135
+ export type BackendRelayAPISchemaPushUpdateAttrStep = WithBackgroundJob<BackendRelayAPISchemaPlanUpdateAttrStep>;
136
+ export type BackendRelayAPISchemaPushIndexStep = WithBackgroundJob<BackendRelayAPISchemaPlanIndexStep>;
137
+ export type BackendRelayAPISchemaPushRemoveIndexStep = WithBackgroundJob<BackendRelayAPISchemaPlanRemoveIndexStep>;
138
+ export type BackendRelayAPISchemaPushUniqueStep = WithBackgroundJob<BackendRelayAPISchemaPlanUniqueStep>;
139
+ export type BackendRelayAPISchemaPushRemoveUniqueStep = WithBackgroundJob<BackendRelayAPISchemaPlanRemoveUniqueStep>;
140
+ export type BackendRelayAPISchemaPushRequiredStep = WithBackgroundJob<BackendRelayAPISchemaPlanRequiredStep>;
141
+ export type BackendRelayAPISchemaPushRemoveRequiredStep = WithBackgroundJob<BackendRelayAPISchemaPlanRemoveRequiredStep>;
142
+ export type BackendRelayAPISchemaPushCheckDataTypeStep = WithBackgroundJob<BackendRelayAPISchemaPlanCheckDataTypeStep>;
143
+ export type BackendRelayAPISchemaPushRemoveDataTypeStep = WithBackgroundJob<BackendRelayAPISchemaPlanRemoveDataTypeStep>;
144
+ export type BackendRelayAPISchemaPushStep = BackendRelayAPISchemaPushAddAttrStep | BackendRelayAPISchemaPushUpdateAttrStep | BackendRelayAPISchemaPushIndexStep | BackendRelayAPISchemaPushRemoveIndexStep | BackendRelayAPISchemaPushUniqueStep | BackendRelayAPISchemaPushRemoveUniqueStep | BackendRelayAPISchemaPushRequiredStep | BackendRelayAPISchemaPushRemoveRequiredStep | BackendRelayAPISchemaPushCheckDataTypeStep | BackendRelayAPISchemaPushRemoveDataTypeStep;
145
+ export declare function identEtype(ident: BackendRelayDBIdent): string;
146
+ export declare function identLabel(ident: BackendRelayDBIdent): string;
147
+ export declare function identName(ident: BackendRelayDBIdent): string;
148
+ export declare function attrFwdLabel(attr: BackendRelayDBAttr): string;
149
+ export declare function attrFwdEtype(attr: BackendRelayDBAttr): string;
150
+ export declare function attrRevLabel(attr: BackendRelayDBAttr): string | undefined;
151
+ export declare function attrRevEtype(attr: BackendRelayDBAttr): string | undefined;
152
+ export declare function attrFwdName(attr: BackendRelayDBAttr): string;
153
+ export declare function attrRevName(attr: BackendRelayDBAttr): string | undefined;
154
+ export declare function generateSchemaTypescriptFile(prevSchema: GenericSchemaDef | null | undefined, newSchema: GenericSchemaDef, backendrelayModuleName: string): string;
155
+ export declare class SchemaValidationError extends Error {
156
+ constructor(message: string);
157
+ }
158
+ export declare function collectSystemCatalogIdentNames(currentAttrs: BackendRelayDBAttr[]): Record<string, Set<string>>;
159
+ export declare const validateSchema: (schema: GenericSchemaDef, systemCatalogIdentNames: Record<string, Set<string>>) => void;
160
+ export {};
161
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EAIpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAKL,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,UAAU,CAAC;IACjB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,kBAAkB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,aAAa,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,kBAAkB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,OAAO,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,M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gB,4BAA4B,CAC1C,UAAU,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EAC/C,SAAS,EAAE,gBAAgB,EAC3B,sBAAsB,EAAE,MAAM,GAC7B,MAAM,CAyCR;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,8BAA8B,CAC5C,YAAY,EAAE,kBAAkB,EAAE,+BAiBnC;AAED,eAAO,MAAM,cAAc,GACzB,QAAQ,gBAAgB,EACxB,yBAAyB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SA8DrD,CAAC"}
@@ -0,0 +1,158 @@
1
+ import { indentLines, joinWithTrailingSep, sortedEntries, formatKey, } from "./util.js";
2
+ function attrDefToCodeString([name, attr]) {
3
+ const type = attr.metadata.derivedType?.type || attr.valueType || 'any';
4
+ const unique = attr.config.unique ? '.unique()' : '';
5
+ const index = attr.config.indexed ? '.indexed()' : '';
6
+ const required = attr.required ? '' : '.optional()';
7
+ return `${formatKey(name)}: i.${type}()${unique}${index}${required}`;
8
+ }
9
+ function entityDefToCodeStr(name, edef) {
10
+ const attrBlock = joinWithTrailingSep(sortedEntries(edef.attrs).map(attrDefToCodeString), ',\n', ',');
11
+ // a block of code for each entity
12
+ return `${formatKey(name)}: i.entity({${attrBlock.length ? '\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\n' : ''}})`;
13
+ }
14
+ export function identEtype(ident) {
15
+ return ident[1];
16
+ }
17
+ export function identLabel(ident) {
18
+ return ident[2];
19
+ }
20
+ export function identName(ident) {
21
+ return `${identEtype(ident)}.${identLabel(ident)}`;
22
+ }
23
+ export function attrFwdLabel(attr) {
24
+ return attr['forward-identity']?.[2];
25
+ }
26
+ export function attrFwdEtype(attr) {
27
+ return attr['forward-identity']?.[1];
28
+ }
29
+ export function attrRevLabel(attr) {
30
+ return attr['reverse-identity']?.[2];
31
+ }
32
+ export function attrRevEtype(attr) {
33
+ return attr['reverse-identity']?.[1];
34
+ }
35
+ export function attrFwdName(attr) {
36
+ return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;
37
+ }
38
+ export function attrRevName(attr) {
39
+ if (attr['reverse-identity']) {
40
+ return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;
41
+ }
42
+ }
43
+ function roomDefToCodeStr(room) {
44
+ let ret = '{';
45
+ if (room.presence) {
46
+ ret += `\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;
47
+ }
48
+ if (room.topics) {
49
+ ret += `\n "topics": {`;
50
+ for (const [topicName, topicConfig] of Object.entries(room.topics)) {
51
+ ret += `\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;
52
+ }
53
+ ret += `\n }`;
54
+ }
55
+ ret += ret === '{' ? '}' : '\n }';
56
+ return ret;
57
+ }
58
+ function roomsCodeStr(rooms) {
59
+ let ret = '{';
60
+ for (const [roomType, roomDef] of Object.entries(rooms)) {
61
+ ret += `\n ${formatKey(roomType)}: ${roomDefToCodeStr(roomDef)},`;
62
+ }
63
+ ret += ret === '{' ? '}' : '\n}';
64
+ return ret;
65
+ }
66
+ export function generateSchemaTypescriptFile(prevSchema, newSchema, backendrelayModuleName) {
67
+ // entities
68
+ const entitiesEntriesCode = joinWithTrailingSep(sortedEntries(newSchema.entities).map(([etype, entityDef]) => entityDefToCodeStr(etype, entityDef)), ',\n', ',');
69
+ const entitiesObjCode = `{\n${indentLines(entitiesEntriesCode, 2)}\n}`;
70
+ const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();
71
+ // rooms
72
+ const rooms = prevSchema?.rooms || {};
73
+ const roomsCode = roomsCodeStr(rooms);
74
+ const kv = (k, v) => {
75
+ return indentLines(`${k}: ${v}`, 2);
76
+ };
77
+ const code = `// Docs: https://www.backendrelay.com/docs/modeling-data
78
+
79
+ import { i } from "${backendrelayModuleName ?? '@backendrelay/core'}";
80
+
81
+ const _schema = i.schema({
82
+ ${kv('entities', entitiesObjCode)},
83
+ ${kv('links', linksEntriesCode)},
84
+ ${kv('rooms', roomsCode)}
85
+ });
86
+
87
+ // This helps TypeScript display nicer intellisense
88
+ type _AppSchema = typeof _schema;
89
+ interface AppSchema extends _AppSchema {}
90
+ const schema: AppSchema = _schema;
91
+
92
+ export type { AppSchema }
93
+ export default schema;
94
+ `;
95
+ return code;
96
+ }
97
+ export class SchemaValidationError extends Error {
98
+ constructor(message) {
99
+ super(message);
100
+ this.name = 'SchemaValidationError';
101
+ }
102
+ }
103
+ export function collectSystemCatalogIdentNames(currentAttrs) {
104
+ const allSystemIdents = currentAttrs
105
+ .filter((attr) => attr.catalog === 'system')
106
+ .flatMap((attr) => [attr['forward-identity'], attr['reverse-identity']].filter(Boolean))
107
+ .filter((x) => Boolean(x));
108
+ let res = {};
109
+ for (const [_, etype, label] of allSystemIdents) {
110
+ res[etype] = res[etype] || new Set();
111
+ res[etype].add(label);
112
+ }
113
+ return res;
114
+ }
115
+ export const validateSchema = (schema, systemCatalogIdentNames) => {
116
+ const entityNames = Object.keys(schema.entities);
117
+ for (const [etype, entityDef] of Object.entries(schema.entities)) {
118
+ if (!etype.startsWith('$'))
119
+ continue;
120
+ if (!systemCatalogIdentNames[etype]) {
121
+ throw new SchemaValidationError('The $ keyword is reserved for system namespaces.' +
122
+ `\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`);
123
+ }
124
+ for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {
125
+ if (systemCatalogIdentNames[etype].has(attrName)) {
126
+ continue;
127
+ }
128
+ if (attrDef.required) {
129
+ throw new SchemaValidationError(`The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +
130
+ `\nMake sure to set ${etype}.${attrName} as optional.` +
131
+ `\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`);
132
+ }
133
+ }
134
+ }
135
+ for (const link of Object.values(schema.links)) {
136
+ if (systemCatalogIdentNames[link.forward.on] &&
137
+ !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&
138
+ link.forward.required) {
139
+ throw new SchemaValidationError(`The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +
140
+ `\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +
141
+ `\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`);
142
+ }
143
+ if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {
144
+ throw new SchemaValidationError(`${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: "cascade" with has: "many"`);
145
+ }
146
+ if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {
147
+ throw new SchemaValidationError(`${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: "cascade" with has: "many"`);
148
+ }
149
+ const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;
150
+ if (!entityNames.includes(link.forward.on)) {
151
+ throw new SchemaValidationError(`${linkDisplay} connects to non existing entity "${link.forward.on}".`);
152
+ }
153
+ if (!entityNames.includes(link.reverse.on)) {
154
+ throw new SchemaValidationError(`${linkDisplay} connects to non existing entity "${link.forward.on}".`);
155
+ }
156
+ }
157
+ };
158
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,SAAS,GAEV,MAAM,WAAW,CAAC;AAiPnB,SAAS,mBAAmB,CAAC,CAAC,IAAI,EAAE,IAAI,CAGvC;IACC,MAAM,IAAI,GACP,IAAI,CAAC,QAAQ,CAAC,WAAmB,EAAE,IAAI,IAAI,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IACtE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,MAAM,KAAK,GAA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,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,GAAG,WAAW,qCAAqC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,GAAG,WAAW,qCAAqC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n AttrsDefs,\n CardinalityKind,\n DataAttrDef,\n EntityDef,\n BackendRelayDBAttr,\n BackendRelayDBCheckedDataType,\n BackendRelayDBIdent,\n BackendRelaySchemaDef,\n LinkAttrDef,\n RoomsDef,\n} from '@backendrelay/core';\n\nimport {\n indentLines,\n joinWithTrailingSep,\n sortedEntries,\n formatKey,\n GenericSchemaDef,\n} from './util.ts';\n\nexport type BackendRelayAPIPlatformSchema = {\n refs: Record<string, BackendRelayDBAttr>;\n blobs: Record<string, Record<string, BackendRelayDBAttr>>;\n};\n\nexport type BackendRelayAPISchemaPlanAddAttrStep = {\n type: 'add-attr';\n friendlyDescription: string;\n attr: BackendRelayDBAttr;\n};\n\nexport type BackendRelayAPISchemaPlanDeleteAttrStep = {\n type: 'delete-attr';\n friendlyDescription: string;\n attrId: string;\n};\n\nexport type BackendRelayAPISchemaPlanUpdateAttrStep = {\n type: 'update-attr';\n friendlyDescription: string;\n attr: BackendRelayDBAttr;\n};\n\nexport type BackendRelayAPISchemaPlanIndexStep = {\n type: 'index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanRemoveIndexStep = {\n type: 'remove-index';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanUniqueStep = {\n type: 'unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanRemoveUniqueStep = {\n type: 'remove-unique';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanRequiredStep = {\n type: 'required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanRemoveRequiredStep = {\n type: 'remove-required';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\nexport type BackendRelayAPISchemaPlanCheckDataTypeStep = {\n type: 'check-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n checkedDataType: BackendRelayDBCheckedDataType;\n};\n\nexport type BackendRelayAPISchemaPlanRemoveDataTypeStep = {\n type: 'remove-data-type';\n friendlyDescription: string;\n attrId: string;\n forwardIdentity: BackendRelayDBIdent;\n};\n\ntype BackendRelayBackgroundSchemaBaseJob = {\n id: string;\n createdAt: Date;\n updatedAt: Date;\n status: 'completed' | 'waiting' | 'processing' | 'errored';\n workEstimate: number | null;\n workCompleted: number | null;\n error?:\n | 'invalid-triple-error'\n | 'invalid-attr-state-error'\n | 'triple-not-unique-error'\n | 'triple-too-large-error'\n | 'missing-required-error'\n | 'unexpected-error';\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n};\n\ntype BackendRelayBackgroundSchemaBaseJobWithInvalidTriples =\n BackendRelayBackgroundSchemaBaseJob & {\n invalidTriplesSample?: {\n entityId: string;\n value: any;\n jsonType:\n | 'string'\n | 'number'\n | 'boolean'\n | 'null'\n | 'object'\n | 'array'\n | 'date';\n }[];\n };\n\nexport interface BackendRelayBackgroundSchemaRemoveDataTypeJob\n extends BackendRelayBackgroundSchemaBaseJob {\n type: 'remove-data-type';\n}\n\nexport interface BackendRelayBackgroundSchemaCheckDataTypeJob\n extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'check-data-type';\n checkedDataType: BackendRelayDBCheckedDataType;\n}\n\nexport interface BackendRelayBackgroundSchemaAddIndexJob\n extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'index';\n}\n\nexport interface BackendRelayBackgroundSchemaRemoveIndexJob\n extends BackendRelayBackgroundSchemaBaseJob {\n type: 'remove-index';\n}\n\nexport interface BackendRelayBackgroundSchemaAddUniqueJob\n extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'unique';\n invalidUniqueValue?: any;\n}\n\nexport interface BackendRelayBackgroundSchemaRemoveUniqueJob\n extends BackendRelayBackgroundSchemaBaseJob {\n type: 'remove-unique';\n}\n\nexport interface BackendRelayBackgroundSchemaAddRequiredJob\n extends BackendRelayBackgroundSchemaBaseJobWithInvalidTriples {\n type: 'required';\n}\n\nexport interface BackendRelayBackgroundSchemaRemoveRequiredJob\n extends BackendRelayBackgroundSchemaBaseJob {\n type: 'remove-required';\n}\n\nexport type BackendRelayAPISchemaPlanStep =\n | BackendRelayAPISchemaPlanAddAttrStep\n | BackendRelayAPISchemaPlanDeleteAttrStep\n | BackendRelayAPISchemaPlanUpdateAttrStep\n | BackendRelayAPISchemaPlanIndexStep\n | BackendRelayAPISchemaPlanRemoveIndexStep\n | BackendRelayAPISchemaPlanUniqueStep\n | BackendRelayAPISchemaPlanRemoveUniqueStep\n | BackendRelayAPISchemaPlanRequiredStep\n | BackendRelayAPISchemaPlanRemoveRequiredStep\n | BackendRelayAPISchemaPlanCheckDataTypeStep\n | BackendRelayAPISchemaPlanRemoveDataTypeStep;\n\ntype BackgroundJobByStep = {\n index: BackendRelayBackgroundSchemaAddIndexJob;\n 'remove-index': BackendRelayBackgroundSchemaRemoveIndexJob;\n unique: BackendRelayBackgroundSchemaAddUniqueJob;\n 'remove-unique': BackendRelayBackgroundSchemaRemoveUniqueJob;\n required: BackendRelayBackgroundSchemaAddRequiredJob;\n 'remove-required': BackendRelayBackgroundSchemaRemoveRequiredJob;\n 'check-data-type': BackendRelayBackgroundSchemaCheckDataTypeJob;\n 'remove-data-type': BackendRelayBackgroundSchemaRemoveDataTypeJob;\n};\n\n// Adds the proper flavor of the backgroundJob type to the steps\n// that run in the background\nexport type WithBackgroundJob<P extends { type: string }> =\n P['type'] extends keyof BackgroundJobByStep\n ? P & { backgroundJob: BackgroundJobByStep[P['type']] }\n : P;\n\nexport type BackendRelayAPISchemaPushAddAttrStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanAddAttrStep>;\n\nexport type BackendRelayAPISchemaPushUpdateAttrStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanUpdateAttrStep>;\n\nexport type BackendRelayAPISchemaPushIndexStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanIndexStep>;\n\nexport type BackendRelayAPISchemaPushRemoveIndexStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanRemoveIndexStep>;\n\nexport type BackendRelayAPISchemaPushUniqueStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanUniqueStep>;\n\nexport type BackendRelayAPISchemaPushRemoveUniqueStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanRemoveUniqueStep>;\n\nexport type BackendRelayAPISchemaPushRequiredStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanRequiredStep>;\n\nexport type BackendRelayAPISchemaPushRemoveRequiredStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanRemoveRequiredStep>;\n\nexport type BackendRelayAPISchemaPushCheckDataTypeStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanCheckDataTypeStep>;\n\nexport type BackendRelayAPISchemaPushRemoveDataTypeStep =\n WithBackgroundJob<BackendRelayAPISchemaPlanRemoveDataTypeStep>;\n\nexport type BackendRelayAPISchemaPushStep =\n | BackendRelayAPISchemaPushAddAttrStep\n | BackendRelayAPISchemaPushUpdateAttrStep\n | BackendRelayAPISchemaPushIndexStep\n | BackendRelayAPISchemaPushRemoveIndexStep\n | BackendRelayAPISchemaPushUniqueStep\n | BackendRelayAPISchemaPushRemoveUniqueStep\n | BackendRelayAPISchemaPushRequiredStep\n | BackendRelayAPISchemaPushRemoveRequiredStep\n | BackendRelayAPISchemaPushCheckDataTypeStep\n | BackendRelayAPISchemaPushRemoveDataTypeStep;\n\nfunction attrDefToCodeString([name, attr]: [\n string,\n DataAttrDef<string, boolean, boolean>,\n]) {\n const type =\n (attr.metadata.derivedType as any)?.type || attr.valueType || 'any';\n const unique = attr.config.unique ? '.unique()' : '';\n const index = attr.config.indexed ? '.indexed()' : '';\n const required = attr.required ? '' : '.optional()';\n return `${formatKey(name)}: i.${type}()${unique}${index}${required}`;\n}\n\nfunction entityDefToCodeStr(\n name: string,\n edef: EntityDef<\n AttrsDefs,\n Record<string, LinkAttrDef<CardinalityKind, string>>,\n any\n >,\n) {\n const attrBlock = joinWithTrailingSep(\n sortedEntries(edef.attrs).map(attrDefToCodeString),\n ',\\n',\n ',',\n );\n\n // a block of code for each entity\n return `${formatKey(name)}: i.entity({${attrBlock.length ? '\\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\\n' : ''}})`;\n}\n\nexport function identEtype(ident: BackendRelayDBIdent) {\n return ident[1];\n}\n\nexport function identLabel(ident: BackendRelayDBIdent) {\n return ident[2];\n}\n\nexport function identName(ident: BackendRelayDBIdent) {\n return `${identEtype(ident)}.${identLabel(ident)}`;\n}\n\nexport function attrFwdLabel(attr: BackendRelayDBAttr) {\n return attr['forward-identity']?.[2];\n}\n\nexport function attrFwdEtype(attr: BackendRelayDBAttr) {\n return attr['forward-identity']?.[1];\n}\n\nexport function attrRevLabel(attr: BackendRelayDBAttr) {\n return attr['reverse-identity']?.[2];\n}\n\nexport function attrRevEtype(attr: BackendRelayDBAttr) {\n return attr['reverse-identity']?.[1];\n}\n\nexport function attrFwdName(attr: BackendRelayDBAttr) {\n return `${attrFwdEtype(attr)}.${attrFwdLabel(attr)}`;\n}\n\nexport function attrRevName(attr: BackendRelayDBAttr) {\n if (attr['reverse-identity']) {\n return `${attrRevEtype(attr)}.${attrRevLabel(attr)}`;\n }\n}\n\nfunction roomDefToCodeStr(room: RoomsDef[string]) {\n let ret = '{';\n\n if (room.presence) {\n ret += `\\n${indentLines(entityDefToCodeStr('presence', room.presence), 4)},`;\n }\n\n if (room.topics) {\n ret += `\\n \"topics\": {`;\n\n for (const [topicName, topicConfig] of Object.entries(room.topics)) {\n ret += `\\n${indentLines(entityDefToCodeStr(topicName, topicConfig), 6)},`;\n }\n ret += `\\n }`;\n }\n\n ret += ret === '{' ? '}' : '\\n }';\n\n return ret;\n}\n\nfunction roomsCodeStr(rooms: RoomsDef) {\n let ret = '{';\n\n for (const [roomType, roomDef] of Object.entries(rooms)) {\n ret += `\\n ${formatKey(roomType)}: ${roomDefToCodeStr(roomDef)},`;\n }\n ret += ret === '{' ? '}' : '\\n}';\n\n return ret;\n}\n\nexport function generateSchemaTypescriptFile(\n prevSchema: GenericSchemaDef | null | undefined,\n newSchema: GenericSchemaDef,\n backendrelayModuleName: string,\n): string {\n // entities\n const entitiesEntriesCode = joinWithTrailingSep(\n sortedEntries(newSchema.entities).map(([etype, entityDef]) =>\n entityDefToCodeStr(etype, entityDef),\n ),\n ',\\n',\n ',',\n );\n\n const entitiesObjCode = `{\\n${indentLines(entitiesEntriesCode, 2)}\\n}`;\n\n const linksEntriesCode = JSON.stringify(newSchema.links, null, 2).trim();\n\n // rooms\n const rooms = prevSchema?.rooms || {};\n const roomsCode = roomsCodeStr(rooms);\n const kv = (k: string, v: string) => {\n return indentLines(`${k}: ${v}`, 2);\n };\n\n const code = `// Docs: https://www.backendrelay.com/docs/modeling-data\n\nimport { i } from \"${backendrelayModuleName ?? '@backendrelay/core'}\";\n\nconst _schema = i.schema({\n${kv('entities', entitiesObjCode)},\n${kv('links', linksEntriesCode)},\n${kv('rooms', roomsCode)}\n});\n\n// This helps TypeScript display nicer intellisense\ntype _AppSchema = typeof _schema;\ninterface AppSchema extends _AppSchema {}\nconst schema: AppSchema = _schema;\n\nexport type { AppSchema }\nexport default schema;\n`;\n\n return code;\n}\n\nexport class SchemaValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SchemaValidationError';\n }\n}\n\nexport function collectSystemCatalogIdentNames(\n currentAttrs: BackendRelayDBAttr[],\n) {\n const allSystemIdents = currentAttrs\n .filter((attr) => attr.catalog === 'system')\n .flatMap((attr) =>\n [attr['forward-identity'], attr['reverse-identity']].filter(Boolean),\n )\n .filter((x): x is NonNullable<typeof x> => Boolean(x));\n\n let res: Record<string, Set<string>> = {};\n\n for (const [_, etype, label] of allSystemIdents) {\n res[etype] = res[etype] || new Set();\n res[etype].add(label);\n }\n\n return res;\n}\n\nexport const validateSchema = (\n schema: GenericSchemaDef,\n systemCatalogIdentNames: Record<string, Set<string>>,\n) => {\n const entityNames = Object.keys(schema.entities);\n\n for (const [etype, entityDef] of Object.entries(schema.entities)) {\n if (!etype.startsWith('$')) continue;\n if (!systemCatalogIdentNames[etype]) {\n throw new SchemaValidationError(\n 'The $ keyword is reserved for system namespaces.' +\n `\\nYou can't create '${etype}'. Perhaps call it '${etype.slice(1)}' instead?`,\n );\n }\n for (const [attrName, attrDef] of Object.entries(entityDef.attrs)) {\n if (systemCatalogIdentNames[etype].has(attrName)) {\n continue;\n }\n if (attrDef.required) {\n throw new SchemaValidationError(\n `The '${etype}' namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${etype}.${attrName} as optional.` +\n `\\n i.e { ${attrName}: i.${attrDef.valueType}().optional() }`,\n );\n }\n }\n }\n\n for (const link of Object.values(schema.links)) {\n if (\n systemCatalogIdentNames[link.forward.on] &&\n !systemCatalogIdentNames[link.forward.on].has(link.forward.label) &&\n link.forward.required\n ) {\n throw new SchemaValidationError(\n `The ${link.forward.on} namespace is managed by the system and can't modify required constraints yet.` +\n `\\nMake sure to set ${link.forward.on}${link.forward.label} as 'optional'.` +\n `\\n i.e { 'on': '${link.forward.on}', 'label': ${link.forward.label}, 'required': false }`,\n );\n }\n\n if (link.forward.has === 'many' && link.forward.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n if (link.reverse.has === 'many' && link.reverse.onDelete === 'cascade') {\n throw new SchemaValidationError(\n `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label} has onDelete: \"cascade\" with has: \"many\"`,\n );\n }\n\n const linkDisplay = `${link.forward.on}${link.forward.label} -> ${link.reverse.on}${link.reverse.label}`;\n if (!entityNames.includes(link.forward.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n if (!entityNames.includes(link.reverse.on)) {\n throw new SchemaValidationError(\n `${linkDisplay} connects to non existing entity \"${link.forward.on}\".`,\n );\n }\n }\n};\n"]}
@@ -0,0 +1,25 @@
1
+ export declare function exchangeCodeForToken({ code, clientId, clientSecret, redirectUri, apiURI, }: {
2
+ code: string;
3
+ clientId: string;
4
+ clientSecret: string;
5
+ redirectUri: string;
6
+ apiURI: string;
7
+ }): Promise<{
8
+ accessToken: string;
9
+ refreshToken: string;
10
+ expiresAt: Date;
11
+ scopes: string;
12
+ tokenType: 'Bearer';
13
+ }>;
14
+ export declare function exchangeRefreshToken({ clientId, clientSecret, refreshToken, apiURI, }: {
15
+ clientId: string;
16
+ clientSecret: string;
17
+ refreshToken: string;
18
+ apiURI: string;
19
+ }): Promise<{
20
+ accessToken: string;
21
+ expiresAt: Date;
22
+ scopes: string;
23
+ tokenType: 'Bearer';
24
+ }>;
25
+ //# sourceMappingURL=serverOAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverOAuth.d.ts","sourceRoot":"","sources":["../../src/serverOAuth.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAC,EACzC,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,MAAM,GACP,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,CAAC;CACrB,CAAC,CAkDD;AAED,wBAAsB,oBAAoB,CAAC,EACzC,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,CAAC;CACrB,CAAC,CA0BD"}
@@ -0,0 +1,64 @@
1
+ import { requireApiURI } from '@backendrelay/core';
2
+ import { BackendRelayOAuthError } from "./oauthCommon.js";
3
+ export async function exchangeCodeForToken({ code, clientId, clientSecret, redirectUri, apiURI, }) {
4
+ const base = requireApiURI(apiURI, 'BackendRelay OAuth token exchange');
5
+ const res = await fetch(`${base}/platform/oauth/token`, {
6
+ method: 'POST',
7
+ headers: { 'Content-type': 'application/json' },
8
+ body: JSON.stringify({
9
+ grant_type: 'authorization_code',
10
+ code,
11
+ redirect_uri: redirectUri,
12
+ client_id: clientId,
13
+ client_secret: clientSecret,
14
+ }),
15
+ });
16
+ if (!res.ok) {
17
+ const text = await res.text();
18
+ let error;
19
+ try {
20
+ const json = JSON.parse(text);
21
+ error = {
22
+ error: json.error,
23
+ errorDescription: json.error_description,
24
+ message: `OAuth error: ${json.error || 'server_error'}`,
25
+ };
26
+ }
27
+ catch (e) {
28
+ error = {
29
+ error: 'server_error',
30
+ message: 'OAuth error: server_error',
31
+ };
32
+ }
33
+ throw new BackendRelayOAuthError(error);
34
+ }
35
+ const json = (await res.json());
36
+ return {
37
+ accessToken: json.access_token,
38
+ expiresAt: new Date(Date.now() + (json.expires_in - 30) * 1000),
39
+ refreshToken: json.refresh_token,
40
+ scopes: json.scopes,
41
+ tokenType: json.token_type,
42
+ };
43
+ }
44
+ export async function exchangeRefreshToken({ clientId, clientSecret, refreshToken, apiURI, }) {
45
+ const base = requireApiURI(apiURI, 'BackendRelay OAuth token refresh');
46
+ const res = await fetch(`${base}/platform/oauth/token`, {
47
+ method: 'POST',
48
+ headers: { 'Content-Type': 'application/json' },
49
+ body: JSON.stringify({
50
+ grant_type: 'refresh_token',
51
+ refresh_token: refreshToken,
52
+ client_id: clientId,
53
+ client_secret: clientSecret,
54
+ }),
55
+ });
56
+ const json = (await res.json());
57
+ return {
58
+ accessToken: json.access_token,
59
+ expiresAt: new Date((json.expires_in - 30) * 1000),
60
+ scopes: json.scopes,
61
+ tokenType: json.token_type,
62
+ };
63
+ }
64
+ //# sourceMappingURL=serverOAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverOAuth.js","sourceRoot":"","sources":["../../src/serverOAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,MAAM,GAOP;IAOC,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IACxE,MAAM,GAAG,GAAG,MAAM,KAAK,CAA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AC3B,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,MAAM,GAMP;IAMC,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;IACvE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,uBAAuB,EAAE;QACtD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,YAAY;YAC3B,SAAS,EAAE,QAAQ;YACnB,aAAa,EAAE,YAAY;SAC5B,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAK7B,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,YAAY;QAC9B,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;QAClD,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import { requireApiURI } from '@backendrelay/core';\nimport { BackendRelayOAuthError } from './oauthCommon.ts';\n\nexport async function exchangeCodeForToken({\n code,\n clientId,\n clientSecret,\n redirectUri,\n apiURI,\n}: {\n code: string;\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n apiURI: string;\n}): Promise<{\n accessToken: string;\n refreshToken: string;\n expiresAt: Date;\n scopes: string;\n tokenType: 'Bearer';\n}> {\n const base = requireApiURI(apiURI, 'BackendRelay OAuth token exchange');\n const res = await fetch(`${base}/platform/oauth/token`, {\n method: 'POST',\n headers: { 'Content-type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'authorization_code',\n code,\n redirect_uri: redirectUri,\n client_id: clientId,\n client_secret: clientSecret,\n }),\n });\n\n if (!res.ok) {\n const text = await res.text();\n let error;\n\n try {\n const json = JSON.parse(text);\n error = {\n error: json.error,\n errorDescription: json.error_description,\n message: `OAuth error: ${json.error || 'server_error'}`,\n };\n } catch (e) {\n error = {\n error: 'server_error',\n message: 'OAuth error: server_error',\n };\n }\n\n throw new BackendRelayOAuthError(error);\n }\n\n const json = (await res.json()) as {\n access_token: string;\n refresh_token: string;\n expires_in: number;\n scopes: string;\n token_type: 'Bearer';\n };\n\n return {\n accessToken: json.access_token,\n expiresAt: new Date(Date.now() + (json.expires_in - 30) * 1000),\n refreshToken: json.refresh_token,\n scopes: json.scopes,\n tokenType: json.token_type,\n };\n}\n\nexport async function exchangeRefreshToken({\n clientId,\n clientSecret,\n refreshToken,\n apiURI,\n}: {\n clientId: string;\n clientSecret: string;\n refreshToken: string;\n apiURI: string;\n}): Promise<{\n accessToken: string;\n expiresAt: Date;\n scopes: string;\n tokenType: 'Bearer';\n}> {\n const base = requireApiURI(apiURI, 'BackendRelay OAuth token refresh');\n const res = await fetch(`${base}/platform/oauth/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: clientId,\n client_secret: clientSecret,\n }),\n });\n\n const json = (await res.json()) as {\n access_token: string;\n expires_in: number;\n scopes: string;\n token_type: 'Bearer';\n };\n\n return {\n accessToken: json.access_token,\n expiresAt: new Date((json.expires_in - 30) * 1000),\n scopes: json.scopes,\n tokenType: json.token_type,\n };\n}\n"]}