ultimabase 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +4 -2
  3. package/dist/access.d.ts +62 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +258 -0
  6. package/dist/adapter-errors.d.ts +43 -0
  7. package/dist/adapter-errors.d.ts.map +1 -0
  8. package/dist/adapter-errors.js +72 -0
  9. package/dist/adapter-json.d.ts +20 -0
  10. package/dist/adapter-json.d.ts.map +1 -0
  11. package/dist/adapter-json.js +2 -0
  12. package/dist/adapter-migrations.d.ts +90 -0
  13. package/dist/adapter-migrations.d.ts.map +1 -0
  14. package/dist/adapter-migrations.js +1 -0
  15. package/dist/adapter.d.ts +333 -0
  16. package/dist/adapter.d.ts.map +1 -0
  17. package/dist/adapter.js +5 -0
  18. package/dist/aggregate.d.ts +31 -0
  19. package/dist/aggregate.d.ts.map +1 -0
  20. package/dist/aggregate.js +99 -0
  21. package/dist/app-internals.d.ts +10 -0
  22. package/dist/app-internals.d.ts.map +1 -0
  23. package/dist/app-internals.js +12 -0
  24. package/dist/app-options.d.ts +22 -0
  25. package/dist/app-options.d.ts.map +1 -0
  26. package/dist/app-options.js +3 -0
  27. package/dist/cascade.d.ts +47 -0
  28. package/dist/cascade.d.ts.map +1 -0
  29. package/dist/cascade.js +209 -0
  30. package/dist/cli-config.d.ts +6 -0
  31. package/dist/cli-config.d.ts.map +1 -0
  32. package/dist/cli-config.js +45 -0
  33. package/dist/cli-deploy.d.ts +14 -0
  34. package/dist/cli-deploy.d.ts.map +1 -0
  35. package/dist/cli-deploy.js +193 -0
  36. package/dist/cli-main.d.ts +15 -0
  37. package/dist/cli-main.d.ts.map +1 -0
  38. package/dist/cli-main.js +155 -0
  39. package/dist/cli-migrate.d.ts +20 -0
  40. package/dist/cli-migrate.d.ts.map +1 -0
  41. package/dist/cli-migrate.js +105 -0
  42. package/dist/cli.d.ts +3 -0
  43. package/dist/cli.d.ts.map +1 -0
  44. package/dist/cli.js +4 -0
  45. package/dist/complete.d.ts +13 -0
  46. package/dist/complete.d.ts.map +1 -0
  47. package/dist/complete.js +60 -0
  48. package/dist/console-logger.d.ts +3 -0
  49. package/dist/console-logger.d.ts.map +1 -0
  50. package/dist/console-logger.js +62 -0
  51. package/dist/create-many.d.ts +7 -0
  52. package/dist/create-many.d.ts.map +1 -0
  53. package/dist/create-many.js +88 -0
  54. package/dist/decimal.d.ts +23 -0
  55. package/dist/decimal.d.ts.map +1 -0
  56. package/dist/decimal.js +50 -0
  57. package/dist/define-app.d.ts +59 -0
  58. package/dist/define-app.d.ts.map +1 -0
  59. package/dist/define-app.js +5 -0
  60. package/dist/define-enum.d.ts +6 -0
  61. package/dist/define-enum.d.ts.map +1 -0
  62. package/dist/define-enum.js +18 -0
  63. package/dist/define-function.d.ts +25 -0
  64. package/dist/define-function.d.ts.map +1 -0
  65. package/dist/define-function.js +111 -0
  66. package/dist/define-model.d.ts +48 -0
  67. package/dist/define-model.d.ts.map +1 -0
  68. package/dist/define-model.js +85 -0
  69. package/dist/definition.d.ts +179 -0
  70. package/dist/definition.d.ts.map +1 -0
  71. package/dist/definition.js +165 -0
  72. package/dist/delete-many.d.ts +13 -0
  73. package/dist/delete-many.d.ts.map +1 -0
  74. package/dist/delete-many.js +58 -0
  75. package/dist/engine.d.ts +16 -0
  76. package/dist/engine.d.ts.map +1 -0
  77. package/dist/engine.js +174 -0
  78. package/dist/errors.d.ts +50 -0
  79. package/dist/errors.d.ts.map +1 -0
  80. package/dist/errors.js +43 -0
  81. package/dist/exact.d.ts +20 -0
  82. package/dist/exact.d.ts.map +1 -0
  83. package/dist/exact.js +1 -0
  84. package/dist/feed.d.ts +6 -0
  85. package/dist/feed.d.ts.map +1 -0
  86. package/dist/feed.js +33 -0
  87. package/dist/field-codec.d.ts +11 -0
  88. package/dist/field-codec.d.ts.map +1 -0
  89. package/dist/field-codec.js +48 -0
  90. package/dist/field-rules.d.ts +57 -0
  91. package/dist/field-rules.d.ts.map +1 -0
  92. package/dist/field-rules.js +1 -0
  93. package/dist/field-type.d.ts +51 -0
  94. package/dist/field-type.d.ts.map +1 -0
  95. package/dist/field-type.js +106 -0
  96. package/dist/fields.d.ts +295 -0
  97. package/dist/fields.d.ts.map +1 -0
  98. package/dist/fields.js +1 -0
  99. package/dist/function.d.ts +126 -0
  100. package/dist/function.d.ts.map +1 -0
  101. package/dist/function.js +1 -0
  102. package/dist/functions.d.ts +18 -0
  103. package/dist/functions.d.ts.map +1 -0
  104. package/dist/functions.js +99 -0
  105. package/dist/group-by.d.ts +10 -0
  106. package/dist/group-by.d.ts.map +1 -0
  107. package/dist/group-by.js +145 -0
  108. package/dist/group-having.d.ts +8 -0
  109. package/dist/group-having.d.ts.map +1 -0
  110. package/dist/group-having.js +97 -0
  111. package/dist/hooks.d.ts +41 -0
  112. package/dist/hooks.d.ts.map +1 -0
  113. package/dist/hooks.js +149 -0
  114. package/dist/hosts.d.ts +3 -0
  115. package/dist/hosts.d.ts.map +1 -0
  116. package/dist/hosts.js +8 -0
  117. package/dist/identify.d.ts +15 -0
  118. package/dist/identify.d.ts.map +1 -0
  119. package/dist/identify.js +71 -0
  120. package/dist/index.d.ts +25 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +12 -0
  123. package/dist/internal.d.ts +28 -0
  124. package/dist/internal.d.ts.map +1 -0
  125. package/dist/internal.js +39 -0
  126. package/dist/lifecycle.d.ts +21 -0
  127. package/dist/lifecycle.d.ts.map +1 -0
  128. package/dist/lifecycle.js +149 -0
  129. package/dist/list-update.d.ts +12 -0
  130. package/dist/list-update.d.ts.map +1 -0
  131. package/dist/list-update.js +52 -0
  132. package/dist/live.d.ts +37 -0
  133. package/dist/live.d.ts.map +1 -0
  134. package/dist/live.js +139 -0
  135. package/dist/manifest.d.ts +11 -0
  136. package/dist/manifest.d.ts.map +1 -0
  137. package/dist/manifest.js +60 -0
  138. package/dist/memory-aggregate.d.ts +7 -0
  139. package/dist/memory-aggregate.d.ts.map +1 -0
  140. package/dist/memory-aggregate.js +107 -0
  141. package/dist/memory-conditions.d.ts +8 -0
  142. package/dist/memory-conditions.d.ts.map +1 -0
  143. package/dist/memory-conditions.js +82 -0
  144. package/dist/memory-draft.d.ts +34 -0
  145. package/dist/memory-draft.d.ts.map +1 -0
  146. package/dist/memory-draft.js +255 -0
  147. package/dist/memory-json.d.ts +6 -0
  148. package/dist/memory-json.d.ts.map +1 -0
  149. package/dist/memory-json.js +86 -0
  150. package/dist/memory-read.d.ts +45 -0
  151. package/dist/memory-read.d.ts.map +1 -0
  152. package/dist/memory-read.js +244 -0
  153. package/dist/memory-search.d.ts +16 -0
  154. package/dist/memory-search.d.ts.map +1 -0
  155. package/dist/memory-search.js +110 -0
  156. package/dist/memory-values.d.ts +23 -0
  157. package/dist/memory-values.d.ts.map +1 -0
  158. package/dist/memory-values.js +82 -0
  159. package/dist/memory.d.ts +4 -0
  160. package/dist/memory.d.ts.map +1 -0
  161. package/dist/memory.js +157 -0
  162. package/dist/migrate.d.ts +22 -0
  163. package/dist/migrate.d.ts.map +1 -0
  164. package/dist/migrate.js +131 -0
  165. package/dist/model.d.ts +239 -0
  166. package/dist/model.d.ts.map +1 -0
  167. package/dist/model.js +1 -0
  168. package/dist/nested-write.d.ts +64 -0
  169. package/dist/nested-write.d.ts.map +1 -0
  170. package/dist/nested-write.js +274 -0
  171. package/dist/number-update.d.ts +18 -0
  172. package/dist/number-update.d.ts.map +1 -0
  173. package/dist/number-update.js +96 -0
  174. package/dist/plugin-app.d.ts +48 -0
  175. package/dist/plugin-app.d.ts.map +1 -0
  176. package/dist/plugin-app.js +230 -0
  177. package/dist/plugin-code.d.ts +17 -0
  178. package/dist/plugin-code.d.ts.map +1 -0
  179. package/dist/plugin-code.js +125 -0
  180. package/dist/plugin-use.d.ts +22 -0
  181. package/dist/plugin-use.d.ts.map +1 -0
  182. package/dist/plugin-use.js +161 -0
  183. package/dist/plugin.d.ts +357 -0
  184. package/dist/plugin.d.ts.map +1 -0
  185. package/dist/plugin.js +17 -0
  186. package/dist/query-aggregate.d.ts +82 -0
  187. package/dist/query-aggregate.d.ts.map +1 -0
  188. package/dist/query-aggregate.js +1 -0
  189. package/dist/query-args.d.ts +41 -0
  190. package/dist/query-args.d.ts.map +1 -0
  191. package/dist/query-args.js +263 -0
  192. package/dist/query-bulk.d.ts +35 -0
  193. package/dist/query-bulk.d.ts.map +1 -0
  194. package/dist/query-bulk.js +1 -0
  195. package/dist/query-conditions.d.ts +9 -0
  196. package/dist/query-conditions.d.ts.map +1 -0
  197. package/dist/query-conditions.js +46 -0
  198. package/dist/query-context.d.ts +32 -0
  199. package/dist/query-context.d.ts.map +1 -0
  200. package/dist/query-context.js +55 -0
  201. package/dist/query-filter.d.ts +46 -0
  202. package/dist/query-filter.d.ts.map +1 -0
  203. package/dist/query-filter.js +1 -0
  204. package/dist/query-group.d.ts +82 -0
  205. package/dist/query-group.d.ts.map +1 -0
  206. package/dist/query-group.js +1 -0
  207. package/dist/query-json.d.ts +9 -0
  208. package/dist/query-json.d.ts.map +1 -0
  209. package/dist/query-json.js +66 -0
  210. package/dist/query-order.d.ts +15 -0
  211. package/dist/query-order.d.ts.map +1 -0
  212. package/dist/query-order.js +115 -0
  213. package/dist/query-project.d.ts +15 -0
  214. package/dist/query-project.d.ts.map +1 -0
  215. package/dist/query-project.js +45 -0
  216. package/dist/query-search.d.ts +24 -0
  217. package/dist/query-search.d.ts.map +1 -0
  218. package/dist/query-search.js +2 -0
  219. package/dist/query-values.d.ts +28 -0
  220. package/dist/query-values.d.ts.map +1 -0
  221. package/dist/query-values.js +91 -0
  222. package/dist/query-where.d.ts +46 -0
  223. package/dist/query-where.d.ts.map +1 -0
  224. package/dist/query-where.js +200 -0
  225. package/dist/query-write.d.ts +14 -0
  226. package/dist/query-write.d.ts.map +1 -0
  227. package/dist/query-write.js +260 -0
  228. package/dist/query.d.ts +254 -0
  229. package/dist/query.d.ts.map +1 -0
  230. package/dist/query.js +1 -0
  231. package/dist/record.d.ts +257 -0
  232. package/dist/record.d.ts.map +1 -0
  233. package/dist/record.js +1 -0
  234. package/dist/recorder.d.ts +32 -0
  235. package/dist/recorder.d.ts.map +1 -0
  236. package/dist/recorder.js +152 -0
  237. package/dist/relation-write.d.ts +41 -0
  238. package/dist/relation-write.d.ts.map +1 -0
  239. package/dist/relation-write.js +112 -0
  240. package/dist/relations.d.ts +42 -0
  241. package/dist/relations.d.ts.map +1 -0
  242. package/dist/relations.js +119 -0
  243. package/dist/rules.d.ts +97 -0
  244. package/dist/rules.d.ts.map +1 -0
  245. package/dist/rules.js +71 -0
  246. package/dist/running.d.ts +29 -0
  247. package/dist/running.d.ts.map +1 -0
  248. package/dist/running.js +39 -0
  249. package/dist/schema-indexes.d.ts +11 -0
  250. package/dist/schema-indexes.d.ts.map +1 -0
  251. package/dist/schema-indexes.js +59 -0
  252. package/dist/schema-virtuals.d.ts +19 -0
  253. package/dist/schema-virtuals.d.ts.map +1 -0
  254. package/dist/schema-virtuals.js +100 -0
  255. package/dist/schema.d.ts +35 -0
  256. package/dist/schema.d.ts.map +1 -0
  257. package/dist/schema.js +267 -0
  258. package/dist/scope.d.ts +46 -0
  259. package/dist/scope.d.ts.map +1 -0
  260. package/dist/scope.js +82 -0
  261. package/dist/scratch.d.ts +14 -0
  262. package/dist/scratch.d.ts.map +1 -0
  263. package/dist/scratch.js +10 -0
  264. package/dist/serve.d.ts +2 -0
  265. package/dist/serve.d.ts.map +1 -0
  266. package/dist/serve.js +4 -0
  267. package/dist/symbols.d.ts +10 -0
  268. package/dist/symbols.d.ts.map +1 -0
  269. package/dist/symbols.js +1 -0
  270. package/dist/transaction.d.ts +28 -0
  271. package/dist/transaction.d.ts.map +1 -0
  272. package/dist/transaction.js +156 -0
  273. package/dist/types.d.ts +58 -0
  274. package/dist/types.d.ts.map +1 -0
  275. package/dist/types.js +1 -0
  276. package/dist/update-many.d.ts +7 -0
  277. package/dist/update-many.d.ts.map +1 -0
  278. package/dist/update-many.js +182 -0
  279. package/dist/uuid.d.ts +7 -0
  280. package/dist/uuid.d.ts.map +1 -0
  281. package/dist/uuid.js +48 -0
  282. package/dist/validation.d.ts +24 -0
  283. package/dist/validation.d.ts.map +1 -0
  284. package/dist/validation.js +72 -0
  285. package/dist/virtual-read.d.ts +9 -0
  286. package/dist/virtual-read.d.ts.map +1 -0
  287. package/dist/virtual-read.js +145 -0
  288. package/dist/virtual.d.ts +142 -0
  289. package/dist/virtual.d.ts.map +1 -0
  290. package/dist/virtual.js +1 -0
  291. package/dist/write-context.d.ts +46 -0
  292. package/dist/write-context.d.ts.map +1 -0
  293. package/dist/write-context.js +102 -0
  294. package/dist/write-data.d.ts +26 -0
  295. package/dist/write-data.d.ts.map +1 -0
  296. package/dist/write-data.js +144 -0
  297. package/dist/write-plan.d.ts +107 -0
  298. package/dist/write-plan.d.ts.map +1 -0
  299. package/dist/write-plan.js +170 -0
  300. package/dist/write-target.d.ts +17 -0
  301. package/dist/write-target.d.ts.map +1 -0
  302. package/dist/write-target.js +59 -0
  303. package/dist/writes.d.ts +23 -0
  304. package/dist/writes.d.ts.map +1 -0
  305. package/dist/writes.js +246 -0
  306. package/dist/writing.d.ts +10 -0
  307. package/dist/writing.d.ts.map +1 -0
  308. package/dist/writing.js +66 -0
  309. package/package.json +42 -3
  310. package/src/access.ts +329 -0
  311. package/src/adapter-errors.ts +89 -0
  312. package/src/adapter-json.ts +21 -0
  313. package/src/adapter-migrations.ts +98 -0
  314. package/src/adapter.ts +363 -0
  315. package/src/aggregate.ts +136 -0
  316. package/src/app-internals.ts +26 -0
  317. package/src/app-options.ts +24 -0
  318. package/src/cascade.ts +297 -0
  319. package/src/cli-config.ts +45 -0
  320. package/src/cli-deploy.ts +235 -0
  321. package/src/cli-main.ts +166 -0
  322. package/src/cli-migrate.ts +143 -0
  323. package/src/cli.ts +5 -0
  324. package/src/complete.ts +73 -0
  325. package/src/console-logger.ts +87 -0
  326. package/src/create-many.ts +126 -0
  327. package/src/decimal.ts +74 -0
  328. package/src/define-app.ts +108 -0
  329. package/src/define-enum.ts +26 -0
  330. package/src/define-function.ts +188 -0
  331. package/src/define-model.ts +220 -0
  332. package/src/definition.ts +352 -0
  333. package/src/delete-many.ts +76 -0
  334. package/src/engine.ts +281 -0
  335. package/src/errors.ts +97 -0
  336. package/src/exact.ts +49 -0
  337. package/src/feed.ts +39 -0
  338. package/src/field-codec.ts +72 -0
  339. package/src/field-rules.ts +77 -0
  340. package/src/field-type.ts +219 -0
  341. package/src/fields.ts +383 -0
  342. package/src/function.ts +143 -0
  343. package/src/functions.ts +154 -0
  344. package/src/group-by.ts +186 -0
  345. package/src/group-having.ts +143 -0
  346. package/src/hooks.ts +215 -0
  347. package/src/hosts.ts +11 -0
  348. package/src/identify.ts +95 -0
  349. package/src/index.ts +125 -0
  350. package/src/internal.ts +68 -0
  351. package/src/lifecycle.ts +214 -0
  352. package/src/list-update.ts +71 -0
  353. package/src/live.ts +199 -0
  354. package/src/manifest.ts +71 -0
  355. package/src/memory-aggregate.ts +162 -0
  356. package/src/memory-conditions.ts +88 -0
  357. package/src/memory-draft.ts +319 -0
  358. package/src/memory-json.ts +91 -0
  359. package/src/memory-read.ts +311 -0
  360. package/src/memory-search.ts +149 -0
  361. package/src/memory-values.ts +106 -0
  362. package/src/memory.ts +173 -0
  363. package/src/migrate.ts +152 -0
  364. package/src/model.ts +312 -0
  365. package/src/nested-write.ts +390 -0
  366. package/src/number-update.ts +142 -0
  367. package/src/plugin-app.ts +308 -0
  368. package/src/plugin-code.ts +158 -0
  369. package/src/plugin-use.ts +217 -0
  370. package/src/plugin.ts +400 -0
  371. package/src/query-aggregate.ts +96 -0
  372. package/src/query-args.ts +375 -0
  373. package/src/query-bulk.ts +53 -0
  374. package/src/query-conditions.ts +53 -0
  375. package/src/query-context.ts +104 -0
  376. package/src/query-filter.ts +54 -0
  377. package/src/query-group.ts +137 -0
  378. package/src/query-json.ts +90 -0
  379. package/src/query-order.ts +158 -0
  380. package/src/query-project.ts +73 -0
  381. package/src/query-search.ts +31 -0
  382. package/src/query-values.ts +131 -0
  383. package/src/query-where.ts +318 -0
  384. package/src/query-write.ts +360 -0
  385. package/src/query.ts +400 -0
  386. package/src/record.ts +379 -0
  387. package/src/recorder.ts +212 -0
  388. package/src/relation-write.ts +176 -0
  389. package/src/relations.ts +165 -0
  390. package/src/rules.ts +188 -0
  391. package/src/running.ts +62 -0
  392. package/src/schema-indexes.ts +88 -0
  393. package/src/schema-virtuals.ts +134 -0
  394. package/src/schema.ts +367 -0
  395. package/src/scope.ts +123 -0
  396. package/src/scratch.ts +28 -0
  397. package/src/serve.ts +5 -0
  398. package/src/symbols.ts +11 -0
  399. package/src/transaction.ts +211 -0
  400. package/src/types.ts +79 -0
  401. package/src/update-many.ts +268 -0
  402. package/src/uuid.ts +51 -0
  403. package/src/validation.ts +107 -0
  404. package/src/virtual-read.ts +198 -0
  405. package/src/virtual.ts +187 -0
  406. package/src/write-context.ts +170 -0
  407. package/src/write-data.ts +188 -0
  408. package/src/write-plan.ts +273 -0
  409. package/src/write-target.ts +92 -0
  410. package/src/writes.ts +361 -0
  411. package/src/writing.ts +93 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # ultimabase
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - The published starter starts: `ultimabase dev` runs `dist/serve.js`, and `@ultimabase/realtime`, which `@ultimabase/graphql` and `@ultimabase/rest` import, is a required peer the starter lists.
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 0e885c4: The first release: the kernel, its adapters, transports and plugins, the testing helpers and the starter.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # ultimabase
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The UltimaBase kernel: models, queries, access rules, hooks, functions and transactions, the plugin contract, and the in-memory database. Everything else is a plugin.
4
+
5
+ Documentation: [Introduction](https://ultimabase.dev/docs).
@@ -0,0 +1,62 @@
1
+ import { PublicError } from './errors.ts';
2
+ import type { Filter } from './adapter.ts';
3
+ import type { Logger } from './app-options.ts';
4
+ import { Relations } from './relations.ts';
5
+ import type { Caller } from './rules.ts';
6
+ import type { ModelInfo } from './schema.ts';
7
+ import type { Models, Verb } from './query-where.ts';
8
+ type Operation = 'read' | 'create' | 'update' | 'delete';
9
+ type Values = {
10
+ readonly [field: string]: unknown;
11
+ };
12
+ /**
13
+ * Each field with a read rule: `private` when only Master reads it, which a
14
+ * transport leaves out, `rule` when it may be hidden (D-44, D-107).
15
+ */
16
+ export declare function readRules(model: ModelInfo): {
17
+ readonly [field: string]: 'private' | 'rule';
18
+ };
19
+ /** The record a rule sees: each stored `one` key as `{ id }` or `null` (D-77). */
20
+ export declare function recordOf(model: ModelInfo, row: Values): Values;
21
+ /** A refusal, logged with the caller's id before it is thrown (D-88). */
22
+ export declare function refused(details: {
23
+ readonly [key: string]: string;
24
+ }, message: string, caller: Caller, logger: Logger): PublicError;
25
+ /** A write's stored `record`, its `value`, and the relation it comes from. */
26
+ export type Write = {
27
+ readonly record?: Values;
28
+ readonly data?: unknown;
29
+ readonly via?: string;
30
+ };
31
+ /** The access rules of one query, for a caller other than Master. */
32
+ export declare class Access {
33
+ private readonly filters;
34
+ readonly models: Models;
35
+ readonly caller: Caller;
36
+ private readonly logger;
37
+ /** The query's relation filters (D-151). */
38
+ readonly relations: Relations;
39
+ constructor(models: Models, caller: Caller, logger: Logger);
40
+ /** The model's read filter (D-10); `undefined` when every row passes. */
41
+ readable(name: string): Filter | undefined;
42
+ private filterOf;
43
+ /** Whether a field read rule may hide the field, from the whole row (D-44). */
44
+ ruled(model: ModelInfo, field: string): boolean;
45
+ /** Refuses a filter or a sort on a field with a read rule (D-44, D-86). */
46
+ check(model: ModelInfo, field: string, path: string, verb: Verb): void;
47
+ /** The fields of a row its field read rules hide (D-44). */
48
+ hidden(model: ModelInfo, row: Values, fields: Iterable<string>): ReadonlySet<string>;
49
+ /**
50
+ * Fails with `ACCESS_DENIED` unless the model's rule, then each written
51
+ * field's rule, allows the write (D-10, D-44, D-67).
52
+ */
53
+ allow(model: ModelInfo, operation: Exclude<Operation, 'read'>, write: Write): void;
54
+ }
55
+ /** The query's access rules; `undefined` for Master, which skips them. */
56
+ export declare function accessFor(models: Models, caller: Caller, logger: Logger): Access | undefined;
57
+ /** `filter` and the model's read filter, both. */
58
+ export declare function and(filter: Filter, readable: Filter | undefined): Filter;
59
+ export declare function and(filter: Filter | undefined, readable: Filter): Filter;
60
+ export declare function and(filter: Filter | undefined, readable: Filter | undefined): Filter | undefined;
61
+ export {};
62
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"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"}
package/dist/access.js ADDED
@@ -0,0 +1,258 @@
1
+ // Access rules at run time (D-10, D-44, D-86): each model's read filter, the
2
+ // fields a caller may not filter on or see, and the rules a write runs.
3
+ // Master skips them all (D-48): its queries get no `Access`.
4
+ import { InvalidQuery, PublicError } from './errors.js';
5
+ import { Relations, trusted } from './relations.js';
6
+ import { allow, filterOf, isMaster, isReadFilter, readFilter } from './rules.js';
7
+ import { entries, isObject, modelOf, normalizeWhere } from './query-where.js';
8
+ import { madeId } from './uuid.js';
9
+ /** The `access` a `.with` received, on a model or a field. */
10
+ function accessOf(rules) {
11
+ return rules !== undefined && isObject(rules) ? rules['access'] : undefined;
12
+ }
13
+ /** The rule of `operation`: a function covers all, `write` the writes. */
14
+ function ruleOf(access, operation) {
15
+ if (!isObject(access))
16
+ return access;
17
+ const rule = access[operation];
18
+ return rule === undefined && operation !== 'read' ? access['write'] : rule;
19
+ }
20
+ function fieldRule(model, field, operation) {
21
+ return ruleOf(accessOf(model.definition.fields.get(field)?.rules), operation);
22
+ }
23
+ function run(rule, facts) {
24
+ if (typeof rule !== 'function') {
25
+ throw new TypeError('An access rule is a function.');
26
+ }
27
+ const result = Reflect.apply(rule, undefined, [facts]);
28
+ return result;
29
+ }
30
+ function decide(rule, facts) {
31
+ const result = run(rule, facts);
32
+ if (typeof result !== 'boolean') {
33
+ throw new TypeError('A write rule or a field rule returns a boolean.');
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * Each field with a read rule: `private` when only Master reads it, which a
39
+ * transport leaves out, `rule` when it may be hidden (D-44, D-107).
40
+ */
41
+ export function readRules(model) {
42
+ const rules = {};
43
+ for (const field of model.fields.keys()) {
44
+ const rule = fieldRule(model, field, 'read');
45
+ if (rule !== undefined) {
46
+ rules[field] = rule === allow.private ? 'private' : 'rule';
47
+ }
48
+ }
49
+ // A virtual is hidden by its own rule and by its needs' (D-151).
50
+ for (const { name, needs } of model.virtuals.values()) {
51
+ const own = fieldRule(model, name, 'read');
52
+ const found = [
53
+ ...needs.map((need) => rules[need]),
54
+ own === undefined
55
+ ? undefined
56
+ : own === allow.private
57
+ ? 'private'
58
+ : 'rule',
59
+ ];
60
+ if (found.includes('private'))
61
+ rules[name] = 'private';
62
+ else if (found.includes('rule'))
63
+ rules[name] = 'rule';
64
+ }
65
+ return rules;
66
+ }
67
+ /** The record a rule sees: each stored `one` key as `{ id }` or `null` (D-77). */
68
+ export function recordOf(model, row) {
69
+ const record = {
70
+ id: row['id'],
71
+ createdAt: row['createdAt'],
72
+ updatedAt: row['updatedAt'],
73
+ };
74
+ for (const field of model.fields.values()) {
75
+ const value = row[field.name];
76
+ if (field.kind === 'scalar')
77
+ record[field.name] = value ?? null;
78
+ else if (field.kind === 'one' && field.stored) {
79
+ record[field.name] = isObject(value) ? { id: value['id'] } : null;
80
+ }
81
+ }
82
+ return record;
83
+ }
84
+ function ids(value, key) {
85
+ const list = isObject(value) ? value[key] : undefined;
86
+ return Array.isArray(list)
87
+ ? list.map((item) => ({ id: isObject(item) ? item['id'] : null }))
88
+ : [];
89
+ }
90
+ /** The value a field rule sees (D-44, D-86): a relation's ids, not its data. */
91
+ function fieldValue(model, name, given) {
92
+ const kind = model.fields.get(name)?.kind;
93
+ const create = isObject(given) ? given['create'] : undefined;
94
+ if (kind === 'many') {
95
+ return {
96
+ connect: ids(given, 'connect'),
97
+ disconnect: ids(given, 'disconnect'),
98
+ delete: ids(given, 'delete'),
99
+ // The rows it creates, by the ids the kernel gives them (D-128).
100
+ create: Array.isArray(create)
101
+ ? create.filter(isObject).map((item) => ({ id: madeId(item) }))
102
+ : [],
103
+ };
104
+ }
105
+ if (kind !== 'one')
106
+ return given;
107
+ if (isObject(create))
108
+ return { id: madeId(create) };
109
+ const connect = isObject(given) ? given['connect'] : undefined;
110
+ return isObject(connect) ? { id: connect['id'] } : null;
111
+ }
112
+ /**
113
+ * Whether a relation value only updates linked rows: it changes no link, so
114
+ * the field rule does not judge it (D-138).
115
+ */
116
+ function updatesOnly(model, name, given) {
117
+ const kind = model.fields.get(name)?.kind;
118
+ if (!isObject(given) || given['update'] === undefined)
119
+ return false;
120
+ if (kind === 'one')
121
+ return true;
122
+ if (kind !== 'many')
123
+ return false;
124
+ const links = ['connect', 'disconnect', 'create', 'delete'];
125
+ return links.every((key) => ids(given, key).length === 0);
126
+ }
127
+ const closed = { OR: [] };
128
+ /** A refusal, logged with the caller's id before it is thrown (D-88). */
129
+ export function refused(details, message, caller, logger) {
130
+ const callerId = caller.kind === 'user' ? caller.user.id : null;
131
+ logger.warn({ ...details, callerId }, message);
132
+ return new PublicError('ACCESS_DENIED', message, { details });
133
+ }
134
+ function denied(refusal, caller, logger) {
135
+ const { model, operation, field, via } = refusal;
136
+ const details = {
137
+ model,
138
+ operation,
139
+ ...(field === undefined ? {} : { field }),
140
+ ...(via === undefined ? {} : { via }),
141
+ };
142
+ return refused(details, `${model} ${operation} refused.`, caller, logger);
143
+ }
144
+ /** The access rules of one query, for a caller other than Master. */
145
+ export class Access {
146
+ filters = new Map();
147
+ models;
148
+ caller;
149
+ logger;
150
+ /** The query's relation filters (D-151). */
151
+ relations;
152
+ constructor(models, caller, logger) {
153
+ this.models = models;
154
+ this.caller = caller;
155
+ this.logger = logger;
156
+ this.relations = new Relations(models, caller);
157
+ }
158
+ /** The model's read filter (D-10); `undefined` when every row passes. */
159
+ readable(name) {
160
+ if (this.filters.has(name))
161
+ return this.filters.get(name);
162
+ const filter = this.filterOf(modelOf(this.models, name));
163
+ this.filters.set(name, filter);
164
+ return filter;
165
+ }
166
+ filterOf(model) {
167
+ const rule = ruleOf(accessOf(model.definition.rules), 'read');
168
+ // Closed by default (D-04).
169
+ if (rule === undefined)
170
+ return closed;
171
+ const result = run(rule, {
172
+ caller: this.caller,
173
+ operation: 'read',
174
+ where: readFilter,
175
+ });
176
+ if (result === true)
177
+ return undefined;
178
+ if (result === false)
179
+ return closed;
180
+ if (!isReadFilter(result)) {
181
+ throw new TypeError('A read rule returns a boolean or a read filter.');
182
+ }
183
+ // The rule's own filter is trusted: no guard, no other rule (D-86).
184
+ const path = `${model.name}.access.read`;
185
+ return normalizeWhere(this.models, model, filterOf(result), path, trusted(this.relations));
186
+ }
187
+ /** Whether a field read rule may hide the field, from the whole row (D-44). */
188
+ ruled(model, field) {
189
+ return fieldRule(model, field, 'read') !== undefined;
190
+ }
191
+ /** Refuses a filter or a sort on a field with a read rule (D-44, D-86). */
192
+ check(model, field, path, verb) {
193
+ if (fieldRule(model, field, 'read') === undefined)
194
+ return;
195
+ throw new InvalidQuery(path, `${path}: ${model.name}.${field} has a read rule; only Master ${verb} on it.`);
196
+ }
197
+ /** The fields of a row its field read rules hide (D-44). */
198
+ hidden(model, row, fields) {
199
+ const hidden = new Set();
200
+ let record;
201
+ for (const field of fields) {
202
+ const rule = fieldRule(model, field, 'read');
203
+ if (rule === undefined)
204
+ continue;
205
+ record ??= recordOf(model, row);
206
+ const facts = { caller: this.caller, operation: 'read', record };
207
+ if (!decide(rule, facts))
208
+ hidden.add(field);
209
+ }
210
+ return hidden;
211
+ }
212
+ /**
213
+ * Fails with `ACCESS_DENIED` unless the model's rule, then each written
214
+ * field's rule, allows the write (D-10, D-44, D-67).
215
+ */
216
+ allow(model, operation, write) {
217
+ const value = write.data === undefined
218
+ ? undefined
219
+ : Object.fromEntries(entries(write.data, 'data'));
220
+ const facts = {
221
+ caller: this.caller,
222
+ operation,
223
+ ...(write.record === undefined
224
+ ? {}
225
+ : { record: recordOf(model, write.record) }),
226
+ ...(value === undefined ? {} : { value }),
227
+ };
228
+ const refusal = {
229
+ model: model.name,
230
+ operation,
231
+ ...(write.via === undefined ? {} : { via: write.via }),
232
+ };
233
+ const rule = ruleOf(accessOf(model.definition.rules), operation);
234
+ if (rule === undefined || !decide(rule, facts))
235
+ throw denied(refusal, this.caller, this.logger);
236
+ for (const [field, given] of Object.entries(value ?? {})) {
237
+ const check = fieldRule(model, field, operation);
238
+ if (check === undefined || updatesOnly(model, field, given))
239
+ continue;
240
+ const allowed = decide(check, {
241
+ ...facts,
242
+ value: fieldValue(model, field, given),
243
+ });
244
+ if (!allowed) {
245
+ throw denied({ ...refusal, field }, this.caller, this.logger);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ /** The query's access rules; `undefined` for Master, which skips them. */
251
+ export function accessFor(models, caller, logger) {
252
+ return isMaster(caller) ? undefined : new Access(models, caller, logger);
253
+ }
254
+ export function and(filter, readable) {
255
+ if (readable === undefined)
256
+ return filter;
257
+ return filter === undefined ? readable : { AND: [readable, filter] };
258
+ }
@@ -0,0 +1,43 @@
1
+ /** A unique index refused a write; the kernel reports `UNIQUE_VIOLATION`. */
2
+ export declare class UniqueViolation extends Error {
3
+ readonly model: string;
4
+ readonly fields: readonly string[];
5
+ constructor(model: string, fields: readonly string[]);
6
+ }
7
+ /**
8
+ * A foreign key refused a write that raced another (D-99): `model.field`
9
+ * links a `target` deleted meanwhile, or, `restricted`, the write deleted a
10
+ * `target` that `model.field` still links.
11
+ */
12
+ export declare class RelationViolation extends Error {
13
+ readonly model: string;
14
+ readonly field: string;
15
+ readonly target: string;
16
+ readonly restricted: boolean;
17
+ constructor(model: string, field: string, target: string, restricted: boolean);
18
+ }
19
+ /**
20
+ * A computed number fell outside its field's range, or was not finite on a
21
+ * float: nothing was written (D-132).
22
+ */
23
+ export declare class OutOfRange extends Error {
24
+ readonly model: string;
25
+ readonly field: string;
26
+ constructor(model: string, field: string);
27
+ }
28
+ /** A check of a write found another count: nothing was written (D-99). */
29
+ export declare class CheckFailed extends Error {
30
+ readonly index: number;
31
+ constructor(index: number);
32
+ }
33
+ /** The database refused a sync's statement or a deploy's file (D-105). */
34
+ export declare class MigrationFailed extends Error {
35
+ /** The statement's SQL, or the file's name. */
36
+ readonly at: string;
37
+ /** What the database said. */
38
+ readonly reason: string;
39
+ /** Whether it waited past its limit for a table another session held. */
40
+ readonly locked: boolean;
41
+ constructor(at: string, reason: string, locked?: boolean);
42
+ }
43
+ //# sourceMappingURL=adapter-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-errors.d.ts","sourceRoot":"","sources":["../src/adapter-errors.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,qBAAa,eAAgB,SAAQ,KAAK;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAElC,YAAY,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,EAKnD;CACD;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAE5B,YACC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,OAAO,EAYnB;CACD;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB,YAAY,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAKvC;CACD;AAED,0EAA0E;AAC1E,qBAAa,WAAY,SAAQ,KAAK;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB,YAAY,KAAK,EAAE,MAAM,EAIxB;CACD;AAED,0EAA0E;AAC1E,qBAAa,eAAgB,SAAQ,KAAK;IACzC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IAExB,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAQ,EAMrD;CACD"}
@@ -0,0 +1,72 @@
1
+ // The errors an adapter throws, which the kernel reports to the client (D-73).
2
+ /** A unique index refused a write; the kernel reports `UNIQUE_VIOLATION`. */
3
+ export class UniqueViolation extends Error {
4
+ model;
5
+ fields;
6
+ constructor(model, fields) {
7
+ super(`Unique constraint failed on ${model} (${fields.join(', ')}).`);
8
+ this.name = 'UniqueViolation';
9
+ this.model = model;
10
+ this.fields = fields;
11
+ }
12
+ }
13
+ /**
14
+ * A foreign key refused a write that raced another (D-99): `model.field`
15
+ * links a `target` deleted meanwhile, or, `restricted`, the write deleted a
16
+ * `target` that `model.field` still links.
17
+ */
18
+ export class RelationViolation extends Error {
19
+ model;
20
+ field;
21
+ target;
22
+ restricted;
23
+ constructor(model, field, target, restricted) {
24
+ super(restricted
25
+ ? `${model}.${field} still links a deleted ${target}.`
26
+ : `${model}.${field} links a missing ${target}.`);
27
+ this.name = 'RelationViolation';
28
+ this.model = model;
29
+ this.field = field;
30
+ this.target = target;
31
+ this.restricted = restricted;
32
+ }
33
+ }
34
+ /**
35
+ * A computed number fell outside its field's range, or was not finite on a
36
+ * float: nothing was written (D-132).
37
+ */
38
+ export class OutOfRange extends Error {
39
+ model;
40
+ field;
41
+ constructor(model, field) {
42
+ super(`The result for ${model}.${field} is out of range.`);
43
+ this.name = 'OutOfRange';
44
+ this.model = model;
45
+ this.field = field;
46
+ }
47
+ }
48
+ /** A check of a write found another count: nothing was written (D-99). */
49
+ export class CheckFailed extends Error {
50
+ index;
51
+ constructor(index) {
52
+ super(`Check ${String(index)} of the write failed.`);
53
+ this.name = 'CheckFailed';
54
+ this.index = index;
55
+ }
56
+ }
57
+ /** The database refused a sync's statement or a deploy's file (D-105). */
58
+ export class MigrationFailed extends Error {
59
+ /** The statement's SQL, or the file's name. */
60
+ at;
61
+ /** What the database said. */
62
+ reason;
63
+ /** Whether it waited past its limit for a table another session held. */
64
+ locked;
65
+ constructor(at, reason, locked = false) {
66
+ super(`The database refused ${at}: ${reason}`);
67
+ this.name = 'MigrationFailed';
68
+ this.at = at;
69
+ this.reason = reason;
70
+ this.locked = locked;
71
+ }
72
+ }
@@ -0,0 +1,20 @@
1
+ /** The operators a `Condition` on a json value adds. */
2
+ export type JsonCondition = {
3
+ /**
4
+ * A json value's operators test the value at this path into it (D-149):
5
+ * a key, or an array's index as PostgreSQL's `#>` reads it. A path the
6
+ * value lacks is unknown, as `null` is. `equals` and `not` then take a
7
+ * JSON value, `null` a JSON `null`; `lt` to `gte` a number or a string,
8
+ * matching a value of that JSON type; the `string` operators a string
9
+ * value, `mode` applying to them; the `array` ones an array.
10
+ */
11
+ readonly path?: readonly string[];
12
+ readonly stringContains?: string;
13
+ readonly stringStartsWith?: string;
14
+ readonly stringEndsWith?: string;
15
+ /** Each element is held, as PostgreSQL's `@>` holds it (D-149). */
16
+ readonly arrayContains?: readonly unknown[];
17
+ readonly arrayStartsWith?: unknown;
18
+ readonly arrayEndsWith?: unknown;
19
+ };
20
+ //# sourceMappingURL=adapter-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-json.d.ts","sourceRoot":"","sources":["../src/adapter-json.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG;IAC3B;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,mEAAmE;IACnE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,OAAO,EAAE,CAAA;IAC3C,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;IAClC,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA"}
@@ -0,0 +1,2 @@
1
+ // A json value's path condition in the adapter contract (D-73, D-149).
2
+ export {};
@@ -0,0 +1,90 @@
1
+ import type { Schema } from './adapter.ts';
2
+ /** One statement of a plan, as it runs and as a migration file shows it. */
3
+ export type Statement = {
4
+ readonly sql: string;
5
+ /** The model it changes, and how, for the log: `Locker`, `added owner`. */
6
+ readonly model: string;
7
+ readonly does: string;
8
+ /** What it deletes, when it loses data: `removing "Locker.label" deletes data`. */
9
+ readonly loses?: string;
10
+ /**
11
+ * When the database refuses it, for a change rows can break:
12
+ * `limiting "Locker.kind" to wood, glass fails when a row holds another value`.
13
+ */
14
+ readonly tries?: string;
15
+ /**
16
+ * A removal that may be a rename: the field or model that may be the same
17
+ * (`Locker.title`), the name it keeps its data under with `dbName`
18
+ * (`label`), and the SQL that renames instead.
19
+ */
20
+ readonly rename?: {
21
+ readonly to: string;
22
+ readonly dbName: string;
23
+ readonly sql: string;
24
+ };
25
+ };
26
+ /** A migration file: its file name, its SQL and its SHA-256. */
27
+ export type Migration = {
28
+ readonly name: string;
29
+ readonly sql: string;
30
+ readonly checksum: string;
31
+ /** The models' hash its header names, which a production start reads. */
32
+ readonly schema?: string;
33
+ /** False when its second line is `-- ultimabase no transaction`. */
34
+ readonly transaction: boolean;
35
+ };
36
+ /** The snapshot a database's tables match, and who wrote it (D-105). */
37
+ export type Stored = {
38
+ /** None when a deploy stopped before it stored one. */
39
+ readonly snapshot: unknown;
40
+ readonly by: 'sync' | 'deploy';
41
+ /** In name order. */
42
+ readonly applied: readonly {
43
+ readonly name: string;
44
+ readonly checksum: string;
45
+ readonly schema?: string;
46
+ }[];
47
+ };
48
+ /**
49
+ * Development sync's statements, or the migration files to deploy, each in
50
+ * its transaction; then `to` is stored.
51
+ */
52
+ export type Run = {
53
+ readonly kind: 'sync';
54
+ /** The snapshot the statements start from, checked under the lock. */
55
+ readonly from: unknown;
56
+ readonly statements: readonly Statement[];
57
+ readonly to: unknown;
58
+ } | {
59
+ readonly kind: 'deploy';
60
+ readonly files: readonly Migration[];
61
+ readonly to: unknown;
62
+ };
63
+ /**
64
+ * How a database follows the models (D-105). A snapshot is JSON in the
65
+ * adapter's own format, which it validates when it reads one back.
66
+ */
67
+ export interface Migrations {
68
+ /** What this database makes of the models. */
69
+ snapshot(schema: Schema): unknown;
70
+ /**
71
+ * The statements from a snapshot, or an empty database, to the models'
72
+ * snapshot; a required field added takes its `default` in the rows.
73
+ */
74
+ plan(from: unknown, schema: Schema): readonly Statement[];
75
+ /** The database's snapshot, if it has one; the adapter is started. */
76
+ stored(): Promise<Stored | undefined>;
77
+ /**
78
+ * Applies `run` under a lock that one database holds at a time; a
79
+ * statement or file the database refuses throws `MigrationFailed`.
80
+ */
81
+ apply(run: Run): Promise<void>;
82
+ /**
83
+ * Drops every table, for `ultimabase reset`; returns the models' tables.
84
+ * A table another session holds throws a locked `MigrationFailed`.
85
+ */
86
+ reset(): Promise<readonly string[]>;
87
+ /** The database's host when it is not on this machine: `reset` then needs `--force`. */
88
+ readonly remote?: string;
89
+ }
90
+ //# sourceMappingURL=adapter-migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-migrations.d.ts","sourceRoot":"","sources":["../src/adapter-migrations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GAAG;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE;QACjB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KACpB,CAAA;CACD,CAAA;AAED,gEAAgE;AAChE,MAAM,MAAM,SAAS,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wEAAwE;AACxE,MAAM,MAAM,MAAM,GAAG;IACpB,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAA;IAC9B,qBAAqB;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;QACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KACxB,EAAE,CAAA;CACH,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,GAAG,GACZ;IACA,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAA;IACzC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CACnB,GACD;IACA,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;IACpC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CACnB,CAAA;AAEJ;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,SAAS,EAAE,CAAA;IACzD,sEAAsE;IACtE,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IACrC;;;OAGG;IACH,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;IACnC,wFAAwF;IACxF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACxB"}
@@ -0,0 +1 @@
1
+ export {};