@highstate/backend 0.9.18 → 0.9.20

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 (331) hide show
  1. package/dist/{chunk-OU5OQBLB.js → chunk-I7BWSAN6.js} +3 -28
  2. package/dist/{chunk-OU5OQBLB.js.map → chunk-I7BWSAN6.js.map} +1 -1
  3. package/dist/chunk-RC6Q3XQQ.js +1547 -0
  4. package/dist/chunk-RC6Q3XQQ.js.map +1 -0
  5. package/dist/chunk-VB4YL327.js +139 -0
  6. package/dist/chunk-VB4YL327.js.map +1 -0
  7. package/dist/database/local/prisma.config.js +26 -0
  8. package/dist/database/local/prisma.config.js.map +1 -0
  9. package/dist/highstate.manifest.json +2 -1
  10. package/dist/index.js +7590 -7289
  11. package/dist/index.js.map +1 -1
  12. package/dist/library/package-resolution-worker.js +1 -1
  13. package/dist/library/package-resolution-worker.js.map +1 -1
  14. package/dist/library/worker/main.js +35 -29
  15. package/dist/library/worker/main.js.map +1 -1
  16. package/dist/shared/index.js +2 -2
  17. package/package.json +18 -9
  18. package/prisma/backend/_schema/layout.prisma +7 -0
  19. package/prisma/backend/_schema/library.prisma +17 -0
  20. package/prisma/backend/_schema/project.prisma +101 -0
  21. package/prisma/backend/_schema/pulumi.prisma +17 -0
  22. package/prisma/backend/postgresql/main.prisma +17 -0
  23. package/prisma/backend/sqlite/main.prisma +17 -0
  24. package/prisma/backend/sqlite/migrations/20250817070609_initiial/migration.sql +34 -0
  25. package/prisma/backend/sqlite/migrations/20250817104948_add_fields/migration.sql +59 -0
  26. package/prisma/backend/sqlite/migrations/20250818082732_add_models/migration.sql +41 -0
  27. package/prisma/backend/sqlite/migrations/20250818083106_a/migration.sql +19 -0
  28. package/prisma/backend/sqlite/migrations/20250818101945_hi/migration.sql +1 -0
  29. package/prisma/backend/sqlite/migrations/20250819082315_a/migration.sql +5 -0
  30. package/prisma/backend/sqlite/migrations/migration_lock.toml +3 -0
  31. package/prisma/project/api-key.prisma +32 -0
  32. package/prisma/project/artifact.prisma +52 -0
  33. package/prisma/project/custom-status.prisma +46 -0
  34. package/prisma/project/evaluation.prisma +45 -0
  35. package/prisma/project/instance.prisma +157 -0
  36. package/prisma/project/layout.prisma +23 -0
  37. package/prisma/project/lock.prisma +18 -0
  38. package/prisma/project/main.prisma +17 -0
  39. package/prisma/project/migrations/20250816081310_initial/migration.sql +300 -0
  40. package/prisma/project/migrations/20250816082523_test/migration.sql +72 -0
  41. package/prisma/project/migrations/20250818065643_update/migration.sql +42 -0
  42. package/prisma/project/migrations/20250818070758_a/migration.sql +8 -0
  43. package/prisma/project/migrations/20250818070913_a/migration.sql +8 -0
  44. package/prisma/project/migrations/20250818082720_add_motels/migration.sql +11 -0
  45. package/prisma/project/migrations/20250818112523_hello/migration.sql +35 -0
  46. package/prisma/project/migrations/20250819082305_a/migration.sql +14 -0
  47. package/prisma/project/migrations/20250819165004_add_missing_fields/migration.sql +216 -0
  48. package/prisma/project/migrations/20250819171309_a/migration.sql +22 -0
  49. package/prisma/project/migrations/20250820113949_a/migration.sql +66 -0
  50. package/prisma/project/migrations/20250820144256_b/migration.sql +31 -0
  51. package/prisma/project/migrations/20250820145547_a/migration.sql +24 -0
  52. package/prisma/project/migrations/20250820182517_b/migration.sql +2 -0
  53. package/prisma/project/migrations/20250821172324_a/migration.sql +2 -0
  54. package/prisma/project/migrations/20250822081339_a/migration.sql +219 -0
  55. package/prisma/project/migrations/20250822083742_b/migration.sql +1 -0
  56. package/prisma/project/migrations/20250822105134_boom/migration.sql +1 -0
  57. package/prisma/project/migrations/20250822141028_b/migration.sql +1 -0
  58. package/prisma/project/migrations/20250822142342_b/migration.sql +16 -0
  59. package/prisma/project/migrations/20250824072720_a/migration.sql +1 -0
  60. package/prisma/project/migrations/20250824093656_b/migration.sql +21 -0
  61. package/prisma/project/migrations/20250825082518_a/migration.sql +1 -0
  62. package/prisma/project/migrations/20250825085343_b/migration.sql +1 -0
  63. package/prisma/project/migrations/20250825091312_a/migration.sql +1 -0
  64. package/prisma/project/migrations/20250903095431_hi/migration.sql +44 -0
  65. package/prisma/project/migrations/20250903174255_a/migration.sql +24 -0
  66. package/prisma/project/migrations/20250908095205_hi/migration.sql +18 -0
  67. package/prisma/project/migrations/20250909155857_hi/migration.sql +15 -0
  68. package/prisma/project/migrations/migration_lock.toml +3 -0
  69. package/prisma/project/model.prisma +37 -0
  70. package/prisma/project/operation.prisma +148 -0
  71. package/prisma/project/page.prisma +49 -0
  72. package/prisma/project/secret.prisma +54 -0
  73. package/prisma/project/service-account.prisma +42 -0
  74. package/prisma/project/terminal.prisma +107 -0
  75. package/prisma/project/trigger.prisma +37 -0
  76. package/prisma/project/unlock-method.prisma +46 -0
  77. package/prisma/project/worker.prisma +169 -0
  78. package/src/artifact/abstractions.ts +13 -13
  79. package/src/artifact/encryption.ts +30 -54
  80. package/src/artifact/factory.ts +6 -9
  81. package/src/artifact/local.ts +33 -46
  82. package/src/business/api-key.ts +24 -36
  83. package/src/business/artifact.test.ts +978 -0
  84. package/src/business/artifact.ts +136 -216
  85. package/src/business/evaluation.ts +328 -0
  86. package/src/business/index.ts +5 -2
  87. package/src/business/instance-lock.test.ts +1060 -0
  88. package/src/business/instance-lock.ts +387 -78
  89. package/src/business/instance-state.test.ts +735 -0
  90. package/src/business/instance-state.ts +582 -337
  91. package/src/business/operation.test.ts +439 -0
  92. package/src/business/operation.ts +174 -208
  93. package/src/business/project-model.ts +258 -0
  94. package/src/business/project-unlock.ts +168 -126
  95. package/src/business/project.ts +287 -179
  96. package/src/business/secret.test.ts +469 -130
  97. package/src/business/secret.ts +177 -217
  98. package/src/business/settings.test.ts +695 -0
  99. package/src/business/settings.ts +855 -0
  100. package/src/business/terminal-session.ts +90 -0
  101. package/src/business/unit-extra.test.ts +539 -0
  102. package/src/business/unit-extra.ts +160 -0
  103. package/src/business/worker.test.ts +356 -579
  104. package/src/business/worker.ts +238 -339
  105. package/src/common/codebase.ts +65 -0
  106. package/src/common/index.ts +3 -5
  107. package/src/common/logger.ts +5 -0
  108. package/src/common/utils.ts +4 -3
  109. package/src/config.ts +10 -11
  110. package/src/database/_generated/backend/postgresql/client.ts +72 -0
  111. package/src/database/_generated/backend/postgresql/commonInputTypes.ts +350 -0
  112. package/src/database/_generated/backend/postgresql/enums.ts +13 -0
  113. package/src/database/_generated/backend/postgresql/internal/class.ts +320 -0
  114. package/src/database/_generated/backend/postgresql/internal/prismaNamespace.ts +1238 -0
  115. package/src/database/_generated/backend/postgresql/models/Library.ts +1263 -0
  116. package/src/database/_generated/backend/postgresql/models/Project.ts +2175 -0
  117. package/src/database/_generated/backend/postgresql/models/ProjectModelStorage.ts +1263 -0
  118. package/src/database/_generated/backend/postgresql/models/ProjectSpace.ts +1602 -0
  119. package/src/database/_generated/backend/postgresql/models/PulumiBackend.ts +1263 -0
  120. package/src/database/_generated/backend/postgresql/models/UserWorkspaseLayout.ts +1065 -0
  121. package/src/database/_generated/backend/postgresql/models.ts +16 -0
  122. package/src/database/_generated/backend/postgresql/pjtg.ts +182 -0
  123. package/src/database/_generated/backend/sqlite/client.ts +72 -0
  124. package/src/database/_generated/backend/sqlite/commonInputTypes.ts +331 -0
  125. package/src/database/_generated/backend/sqlite/enums.ts +13 -0
  126. package/src/database/_generated/backend/sqlite/internal/class.ts +318 -0
  127. package/src/database/_generated/backend/sqlite/internal/prismaNamespace.ts +1207 -0
  128. package/src/database/_generated/backend/sqlite/models/Library.ts +1261 -0
  129. package/src/database/_generated/backend/sqlite/models/Project.ts +2169 -0
  130. package/src/database/_generated/backend/sqlite/models/ProjectModelStorage.ts +1261 -0
  131. package/src/database/_generated/backend/sqlite/models/ProjectSpace.ts +1599 -0
  132. package/src/database/_generated/backend/sqlite/models/PulumiBackend.ts +1261 -0
  133. package/src/database/_generated/backend/sqlite/models/UserWorkspaseLayout.ts +1063 -0
  134. package/src/database/_generated/backend/sqlite/models.ts +16 -0
  135. package/src/database/_generated/backend/sqlite/pjtg.ts +182 -0
  136. package/src/database/_generated/project/client.ts +204 -0
  137. package/src/database/_generated/project/commonInputTypes.ts +827 -0
  138. package/src/database/_generated/project/enums.ts +104 -0
  139. package/src/database/_generated/project/internal/class.ts +479 -0
  140. package/src/database/_generated/project/internal/prismaNamespace.ts +2974 -0
  141. package/src/database/_generated/project/models/ApiKey.ts +1506 -0
  142. package/src/database/_generated/project/models/Artifact.ts +2051 -0
  143. package/src/database/_generated/project/models/HubModel.ts +1125 -0
  144. package/src/database/_generated/project/models/InstanceCustomStatus.ts +1713 -0
  145. package/src/database/_generated/project/models/InstanceEvaluationState.ts +1312 -0
  146. package/src/database/_generated/project/models/InstanceLock.ts +1268 -0
  147. package/src/database/_generated/project/models/InstanceModel.ts +1125 -0
  148. package/src/database/_generated/project/models/InstanceOperationState.ts +1707 -0
  149. package/src/database/_generated/project/models/InstanceState.ts +4613 -0
  150. package/src/database/_generated/project/models/Operation.ts +1647 -0
  151. package/src/database/_generated/project/models/OperationLog.ts +1455 -0
  152. package/src/database/_generated/project/models/Page.ts +1838 -0
  153. package/src/database/_generated/project/models/Secret.ts +1692 -0
  154. package/src/database/_generated/project/models/ServiceAccount.ts +2165 -0
  155. package/src/database/_generated/project/models/Terminal.ts +2038 -0
  156. package/src/database/_generated/project/models/TerminalSession.ts +1454 -0
  157. package/src/database/_generated/project/models/TerminalSessionLog.ts +1280 -0
  158. package/src/database/_generated/project/models/Trigger.ts +1430 -0
  159. package/src/database/_generated/project/models/UnlockMethod.ts +1220 -0
  160. package/src/database/_generated/project/models/UserCompositeViewport.ts +1280 -0
  161. package/src/database/_generated/project/models/UserProjectViewport.ts +1059 -0
  162. package/src/database/_generated/project/models/Worker.ts +1459 -0
  163. package/src/database/_generated/project/models/WorkerUnitRegistration.ts +1524 -0
  164. package/src/database/_generated/project/models/WorkerVersion.ts +1974 -0
  165. package/src/database/_generated/project/models/WorkerVersionLog.ts +1318 -0
  166. package/src/database/_generated/project/models.ts +35 -0
  167. package/src/database/_generated/project/pjtg.ts +182 -0
  168. package/src/database/abstractions.ts +19 -0
  169. package/src/database/factory.ts +37 -0
  170. package/src/database/index.ts +6 -0
  171. package/src/database/local/backend.ts +134 -0
  172. package/src/database/local/index.ts +3 -0
  173. package/src/database/local/meta.ts +46 -0
  174. package/src/database/local/prisma.config.ts +25 -0
  175. package/src/database/local/project.ts +39 -0
  176. package/src/database/manager.ts +181 -0
  177. package/src/database/migrate.ts +35 -0
  178. package/src/database/prisma.ts +56 -0
  179. package/src/database/well-known.ts +38 -0
  180. package/src/index.ts +4 -4
  181. package/src/library/abstractions.ts +3 -5
  182. package/src/library/factory.ts +1 -1
  183. package/src/library/local.ts +81 -26
  184. package/src/library/package-resolution-worker.ts +1 -1
  185. package/src/library/worker/evaluator.ts +40 -23
  186. package/src/library/worker/loader.lite.ts +1 -1
  187. package/src/library/worker/main.ts +3 -10
  188. package/src/library/worker/protocol.ts +0 -1
  189. package/src/lock/index.ts +0 -1
  190. package/src/lock/manager.ts +0 -10
  191. package/src/orchestrator/manager.ts +190 -104
  192. package/src/orchestrator/operation-context.ts +357 -0
  193. package/src/orchestrator/operation-plan.destroy.test.md +357 -0
  194. package/src/orchestrator/operation-plan.destroy.test.ts +775 -0
  195. package/src/orchestrator/operation-plan.fixtures.ts +213 -0
  196. package/src/orchestrator/operation-plan.md +198 -0
  197. package/src/orchestrator/operation-plan.refresh.test.md +199 -0
  198. package/src/orchestrator/operation-plan.refresh.test.ts +367 -0
  199. package/src/orchestrator/operation-plan.ts +709 -0
  200. package/src/orchestrator/operation-plan.update.test.md +485 -0
  201. package/src/orchestrator/operation-plan.update.test.ts +1066 -0
  202. package/src/orchestrator/operation-workset.ts +233 -578
  203. package/src/orchestrator/operation.ts +440 -948
  204. package/src/orchestrator/plan-test-builder.ts +267 -0
  205. package/src/project-model/abstractions.ts +118 -0
  206. package/src/project-model/backends/codebase.ts +365 -0
  207. package/src/project-model/backends/database.ts +440 -0
  208. package/src/project-model/errors.ts +81 -0
  209. package/src/project-model/factory.ts +24 -0
  210. package/src/project-model/index.ts +4 -0
  211. package/src/project-model/utils.test.ts +544 -0
  212. package/src/project-model/utils.ts +242 -0
  213. package/src/pubsub/abstractions.ts +10 -1
  214. package/src/pubsub/factory.ts +4 -4
  215. package/src/pubsub/index.ts +1 -0
  216. package/src/pubsub/manager.ts +29 -13
  217. package/src/pubsub/memory.ts +31 -0
  218. package/src/runner/abstractions.ts +40 -41
  219. package/src/runner/artifact-env.ts +19 -8
  220. package/src/runner/factory.ts +6 -6
  221. package/src/runner/force-abort.ts +3 -6
  222. package/src/runner/local.ts +74 -67
  223. package/src/runner/pulumi.ts +23 -63
  224. package/src/services.ts +181 -123
  225. package/src/shared/models/backend/index.ts +3 -1
  226. package/src/shared/models/backend/library.ts +9 -1
  227. package/src/shared/models/backend/project.ts +43 -42
  228. package/src/shared/models/backend/pulumi.ts +14 -0
  229. package/src/shared/models/backend/unlock-method.ts +1 -1
  230. package/src/shared/models/backend/well-known.ts +58 -0
  231. package/src/shared/models/base.ts +40 -26
  232. package/src/shared/models/errors.ts +82 -1
  233. package/src/shared/models/index.ts +3 -2
  234. package/src/shared/models/prisma.ts +36 -0
  235. package/src/shared/models/project/api-key.ts +37 -59
  236. package/src/shared/models/project/artifact.ts +16 -76
  237. package/src/shared/models/project/custom-status.ts +12 -0
  238. package/src/shared/models/project/index.ts +8 -7
  239. package/src/shared/models/project/lock.ts +10 -78
  240. package/src/shared/models/project/model.ts +19 -1
  241. package/src/shared/models/project/operation.ts +235 -99
  242. package/src/shared/models/project/page.ts +37 -48
  243. package/src/shared/models/project/secret.ts +29 -89
  244. package/src/shared/models/project/service-account.ts +12 -17
  245. package/src/shared/models/project/state.ts +100 -407
  246. package/src/shared/models/project/terminal.ts +75 -88
  247. package/src/shared/models/project/trigger.ts +13 -49
  248. package/src/shared/models/project/unlock-method.ts +20 -26
  249. package/src/shared/models/project/worker.ts +89 -90
  250. package/src/shared/resolvers/graph-resolver.ts +21 -0
  251. package/src/shared/resolvers/index.ts +1 -1
  252. package/src/shared/resolvers/input-hash.ts +24 -14
  253. package/src/shared/resolvers/input.ts +9 -2
  254. package/src/shared/resolvers/registry.ts +5 -4
  255. package/src/shared/resolvers/state.ts +12 -1
  256. package/src/shared/resolvers/validation.ts +7 -3
  257. package/src/shared/utils/index.ts +1 -2
  258. package/src/shared/utils/promise-tracker.ts +30 -3
  259. package/src/terminal/abstractions.ts +1 -1
  260. package/src/terminal/docker.ts +3 -3
  261. package/src/terminal/manager.ts +102 -118
  262. package/src/test-utils/database.ts +119 -0
  263. package/src/test-utils/index.ts +2 -0
  264. package/src/test-utils/services.ts +134 -0
  265. package/src/unlock/abstractions.ts +5 -23
  266. package/src/unlock/memory.ts +9 -14
  267. package/src/worker/abstractions.ts +7 -4
  268. package/src/worker/docker.ts +14 -19
  269. package/src/worker/manager.ts +366 -97
  270. package/dist/chunk-NAAIDR4U.js +0 -8499
  271. package/dist/chunk-NAAIDR4U.js.map +0 -1
  272. package/dist/chunk-Y7DXREVO.js +0 -1745
  273. package/dist/chunk-Y7DXREVO.js.map +0 -1
  274. package/dist/magic-string.es-5ABAC4JN.js +0 -1292
  275. package/dist/magic-string.es-5ABAC4JN.js.map +0 -1
  276. package/src/business/__traces__/secret/update-instance-secrets/create-and-delete-secrets-simultaneously.md +0 -356
  277. package/src/business/__traces__/secret/update-instance-secrets/create-new-secrets-for-instance.md +0 -274
  278. package/src/business/__traces__/secret/update-instance-secrets/delete-existing-secrets.md +0 -223
  279. package/src/business/__traces__/secret/update-instance-secrets/no-op-when-no-changes.md +0 -147
  280. package/src/business/__traces__/secret/update-instance-secrets/update-existing-secrets.md +0 -280
  281. package/src/business/__traces__/worker/update-unit-registrations/add-new-unit-registration-when-other-exists.md +0 -360
  282. package/src/business/__traces__/worker/update-unit-registrations/add-new-unit-registration.md +0 -215
  283. package/src/business/__traces__/worker/update-unit-registrations/create-multiple-workers-with-different-identities.md +0 -427
  284. package/src/business/__traces__/worker/update-unit-registrations/handle-nonexistent-registration-id-gracefully.md +0 -217
  285. package/src/business/__traces__/worker/update-unit-registrations/no-op-when-no-changes.md +0 -132
  286. package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-when-image-changes.md +0 -454
  287. package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-when-image-version-changes.md +0 -426
  288. package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-with-same-identity-reuses-service-account.md +0 -372
  289. package/src/business/__traces__/worker/update-unit-registrations/remove-one-of-multiple-unit-registrations.md +0 -383
  290. package/src/business/__traces__/worker/update-unit-registrations/remove-unit-registration.md +0 -245
  291. package/src/business/__traces__/worker/update-unit-registrations/update-existing-unit-registration-when-params-change.md +0 -174
  292. package/src/business/__traces__/worker/update-unit-registrations/update-params-and-image-simultaneously.md +0 -432
  293. package/src/business/__traces__/worker/update-unit-registrations/worker-with-multiple-registrations-not-deleted-when-one-removed.md +0 -220
  294. package/src/business/backend-unlock.ts +0 -10
  295. package/src/common/clock.ts +0 -18
  296. package/src/common/performance.ts +0 -44
  297. package/src/common/random.ts +0 -68
  298. package/src/common/test/index.ts +0 -2
  299. package/src/common/test/render.ts +0 -98
  300. package/src/common/test/tracer.ts +0 -359
  301. package/src/hotstate/abstractions.ts +0 -48
  302. package/src/hotstate/factory.ts +0 -17
  303. package/src/hotstate/index.ts +0 -3
  304. package/src/hotstate/manager.ts +0 -192
  305. package/src/hotstate/memory.ts +0 -100
  306. package/src/hotstate/validation.ts +0 -100
  307. package/src/lock/test.ts +0 -108
  308. package/src/project/abstractions.ts +0 -78
  309. package/src/project/evaluation.ts +0 -248
  310. package/src/project/factory.ts +0 -11
  311. package/src/project/index.ts +0 -3
  312. package/src/project/local.ts +0 -417
  313. package/src/pubsub/local.ts +0 -36
  314. package/src/pubsub/validation.ts +0 -33
  315. package/src/shared/utils/args.ts +0 -25
  316. package/src/state/abstractions.ts +0 -289
  317. package/src/state/encryption.ts +0 -98
  318. package/src/state/factory.ts +0 -20
  319. package/src/state/index.ts +0 -7
  320. package/src/state/local/backend.ts +0 -106
  321. package/src/state/local/collection.ts +0 -361
  322. package/src/state/local/index.ts +0 -2
  323. package/src/state/manager.ts +0 -890
  324. package/src/state/memory/backend.ts +0 -70
  325. package/src/state/memory/collection.ts +0 -270
  326. package/src/state/memory/index.ts +0 -2
  327. package/src/state/repository/index.ts +0 -2
  328. package/src/state/repository/repository.index.ts +0 -193
  329. package/src/state/repository/repository.ts +0 -507
  330. package/src/state/test.ts +0 -457
  331. /package/src/{state → database/local}/keyring.ts +0 -0
@@ -0,0 +1,35 @@
1
+
2
+ /* !!! This is code generated by Prisma. Do not edit directly. !!! */
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+ /**
6
+ * This is a barrel export file for all models and their related types.
7
+ *
8
+ * 🟢 You can import this file directly.
9
+ */
10
+ export type * from './models/ApiKey.ts'
11
+ export type * from './models/Artifact.ts'
12
+ export type * from './models/InstanceCustomStatus.ts'
13
+ export type * from './models/InstanceEvaluationState.ts'
14
+ export type * from './models/InstanceState.ts'
15
+ export type * from './models/UserProjectViewport.ts'
16
+ export type * from './models/UserCompositeViewport.ts'
17
+ export type * from './models/InstanceLock.ts'
18
+ export type * from './models/InstanceModel.ts'
19
+ export type * from './models/HubModel.ts'
20
+ export type * from './models/Operation.ts'
21
+ export type * from './models/InstanceOperationState.ts'
22
+ export type * from './models/OperationLog.ts'
23
+ export type * from './models/Page.ts'
24
+ export type * from './models/Secret.ts'
25
+ export type * from './models/ServiceAccount.ts'
26
+ export type * from './models/Terminal.ts'
27
+ export type * from './models/TerminalSession.ts'
28
+ export type * from './models/TerminalSessionLog.ts'
29
+ export type * from './models/Trigger.ts'
30
+ export type * from './models/UnlockMethod.ts'
31
+ export type * from './models/Worker.ts'
32
+ export type * from './models/WorkerVersion.ts'
33
+ export type * from './models/WorkerUnitRegistration.ts'
34
+ export type * from './models/WorkerVersionLog.ts'
35
+ export type * from './commonInputTypes.ts'
@@ -0,0 +1,182 @@
1
+ declare global {
2
+ namespace PrismaJson {
3
+ // This namespace will always be empty. Definitions should be done by
4
+ // you manually, and merged automatically by typescript. Make sure that
5
+ // your declaration merging file is included in your tsconfig.json
6
+ //
7
+ // Learn more: https://github.com/arthurfiorette/prisma-json-types-generator/issues/143
8
+ // Declaration Merging: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
9
+ }
10
+ }
11
+
12
+ /** A filter to be used against nullable List types. */
13
+ export type NullableListFilter<T> = {
14
+ equals?: T | T[] | null;
15
+ has?: T | null;
16
+ hasEvery?: T[];
17
+ hasSome?: T[];
18
+ isEmpty?: boolean;
19
+ };
20
+
21
+ /** A type to determine how to update a json field */
22
+ export type UpdateInput<T> = T extends object ? { [P in keyof T]?: UpdateInput<T[P]> } : T;
23
+
24
+ /** A type to determine how to update a json[] field */
25
+ export type UpdateManyInput<T> = T | T[] | { set?: T[]; push?: T | T[] };
26
+
27
+ /** A type to determine how to create a json[] input */
28
+ export type CreateManyInput<T> = T | T[] | { set?: T[] };
29
+
30
+ /**
31
+ * A typed version of NestedStringFilter, allowing narrowing of string types to
32
+ * discriminated unions.
33
+ */
34
+ export type TypedNestedStringFilter<S extends string> =
35
+ //@ts-ignore - When Prisma.StringFilter is not present, this type is not used
36
+ Prisma.StringFilter & {
37
+ equals?: S;
38
+ in?: S[];
39
+ notIn?: S[];
40
+ not?: TypedNestedStringFilter<S> | S;
41
+ };
42
+
43
+ /**
44
+ * A typed version of StringFilter, allowing narrowing of string types to discriminated
45
+ * unions.
46
+ */
47
+ export type TypedStringFilter<S extends string> =
48
+ //@ts-ignore - When Prisma.StringFilter is not present, this type is not used
49
+ Prisma.StringFilter & {
50
+ equals?: S;
51
+ in?: S[];
52
+ notIn?: S[];
53
+ not?: TypedNestedStringFilter<S> | S;
54
+ };
55
+
56
+ /**
57
+ * A typed version of NestedStringNullableFilter, allowing narrowing of string types to
58
+ * discriminated unions.
59
+ */
60
+ export type TypedNestedStringNullableFilter<S extends string> =
61
+ //@ts-ignore - When Prisma.StringNullableFilter is not present, this type is not used
62
+ Prisma.StringNullableFilter & {
63
+ equals?: S | null;
64
+ in?: S[] | null;
65
+ notIn?: S[] | null;
66
+ not?: TypedNestedStringNullableFilter<S> | S | null;
67
+ };
68
+
69
+ /**
70
+ * A typed version of StringNullableFilter, allowing narrowing of string types to
71
+ * discriminated unions.
72
+ */
73
+ export type TypedStringNullableFilter<S extends string> =
74
+ //@ts-ignore - When Prisma.StringNullableFilter is not present, this type is not used
75
+ Prisma.StringNullableFilter & {
76
+ equals?: S | null;
77
+ in?: S[] | null;
78
+ notIn?: S[] | null;
79
+ not?: TypedNestedStringNullableFilter<S> | S | null;
80
+ };
81
+
82
+ /**
83
+ * A typed version of NestedStringWithAggregatesFilter, allowing narrowing of string types
84
+ * to discriminated unions.
85
+ */
86
+ export type TypedNestedStringWithAggregatesFilter<S extends string> =
87
+ //@ts-ignore - When Prisma.NestedStringWithAggregatesFilter is not present, this type is not used
88
+ Prisma.NestedStringWithAggregatesFilter & {
89
+ equals?: S;
90
+ in?: S[];
91
+ notIn?: S[];
92
+ not?: TypedNestedStringWithAggregatesFilter<S> | S;
93
+ };
94
+
95
+ /**
96
+ * A typed version of StringWithAggregatesFilter, allowing narrowing of string types to
97
+ * discriminated unions.
98
+ */
99
+ export type TypedStringWithAggregatesFilter<S extends string> =
100
+ //@ts-ignore - When Prisma.StringWithAggregatesFilter is not present, this type is not used
101
+ Prisma.StringWithAggregatesFilter & {
102
+ equals?: S;
103
+ in?: S[];
104
+ notIn?: S[];
105
+ not?: TypedNestedStringWithAggregatesFilter<S> | S;
106
+ };
107
+
108
+ /**
109
+ * A typed version of NestedStringNullableWithAggregatesFilter, allowing narrowing of
110
+ * string types to discriminated unions.
111
+ */
112
+ export type TypedNestedStringNullableWithAggregatesFilter<S extends string> =
113
+ //@ts-ignore - When Prisma.NestedStringNullableWithAggregatesFilter is not present, this type is not used
114
+ Prisma.NestedStringNullableWithAggregatesFilter & {
115
+ equals?: S | null;
116
+ in?: S[] | null;
117
+ notIn?: S[] | null;
118
+ not?: TypedNestedStringNullableWithAggregatesFilter<S> | S | null;
119
+ };
120
+
121
+ /**
122
+ * A typed version of StringNullableWithAggregatesFilter, allowing narrowing of string
123
+ * types to discriminated unions.
124
+ */
125
+ export type TypedStringNullableWithAggregatesFilter<S extends string> =
126
+ //@ts-ignore - When Prisma.StringNullableWithAggregatesFilter is not present, this type is not used
127
+ Prisma.StringNullableWithAggregatesFilter & {
128
+ equals?: S | null;
129
+ in?: S[] | null;
130
+ notIn?: S[] | null;
131
+ not?: TypedNestedStringNullableWithAggregatesFilter<S> | S | null;
132
+ };
133
+
134
+ /**
135
+ * A typed version of StringFieldUpdateOperationsInput, allowing narrowing of string types
136
+ * to discriminated unions.
137
+ */
138
+ export type TypedStringFieldUpdateOperationsInput<S extends string> =
139
+ //@ts-ignore - When Prisma.StringFieldUpdateOperationsInput is not present, this type is not used
140
+ Prisma.StringFieldUpdateOperationsInput & {
141
+ set?: S;
142
+ };
143
+
144
+ /**
145
+ * A typed version of NullableStringFieldUpdateOperationsInput, allowing narrowing of
146
+ * string types to discriminated unions.
147
+ */
148
+ export type TypedNullableStringFieldUpdateOperationsInput<S extends string> =
149
+ //@ts-ignore - When Prisma.NullableStringFieldUpdateOperationsInput is not present, this type is not used
150
+ Prisma.NullableStringFieldUpdateOperationsInput & {
151
+ set?: S | null;
152
+ };
153
+
154
+ /**
155
+ * A typed version of StringNullableListFilter, allowing narrowing of string types to
156
+ * discriminated unions.
157
+ */
158
+ export type TypedStringNullableListFilter<S extends string> =
159
+ //@ts-ignore - When Prisma.StringNullableListFilter is not present, this type is not used
160
+ Prisma.StringNullableListFilter & {
161
+ equals?: S[] | null;
162
+ has?: S | null;
163
+ hasEvery?: S[];
164
+ hasSome?: S[];
165
+ };
166
+
167
+ /**
168
+ * A typed version of the input type to update a string[] field, allowing narrowing of
169
+ * string types to discriminated unions.
170
+ */
171
+ export type UpdateStringArrayInput<S extends string> = {
172
+ set?: S[];
173
+ push?: S | S[];
174
+ };
175
+
176
+ /**
177
+ * A typed version of the input type to create a string[] field, allowing narrowing of
178
+ * string types to discriminated unions.
179
+ */
180
+ export type CreateStringArrayInput<S extends string> = {
181
+ set?: S[];
182
+ };
@@ -0,0 +1,19 @@
1
+ import type { ProjectDatabase } from "./prisma"
2
+
3
+ export interface ProjectDatabaseBackend {
4
+ /**
5
+ * Opens the database for the project with the given ID.
6
+ *
7
+ * If the project does not exist, this will throw an error.
8
+ *
9
+ * @param projectId The ID of the project to open the database for.
10
+ * @param masterKey The master key to decrypt the project database. If not provided, the encryption is assumed to be disabled.
11
+ */
12
+ openProjectDatabase(
13
+ projectId: string,
14
+ masterKey?: string,
15
+ ): Promise<[database: ProjectDatabase, url: string]>
16
+ }
17
+
18
+ export const backendDatabaseVersion = 2
19
+ export const projectDatabaseVersion = 10
@@ -0,0 +1,37 @@
1
+ import type { Logger } from "pino"
2
+ import type { ProjectDatabaseBackend } from "./abstractions"
3
+ import type { BackendDatabase } from "./prisma"
4
+ import { z } from "zod"
5
+ import {
6
+ createLocalBackendDatabase,
7
+ LocalProjectDatabaseBackend,
8
+ localBackendDatabaseConfig,
9
+ } from "./local"
10
+ import { databaseManagerConfig } from "./manager"
11
+
12
+ export const databaseConfig = z.object({
13
+ HIGHSTATE_BACKEND_DATABASE_TYPE: z.enum(["local"]).default("local"),
14
+ HIGHSTATE_PROJECT_DATABASE_TYPE: z.enum(["local"]).default("local"),
15
+ ...localBackendDatabaseConfig.shape,
16
+ ...databaseManagerConfig.shape,
17
+ })
18
+
19
+ export function createBackendDatabase(
20
+ config: z.infer<typeof databaseConfig>,
21
+ logger: Logger,
22
+ ): Promise<BackendDatabase> {
23
+ switch (config.HIGHSTATE_BACKEND_DATABASE_TYPE) {
24
+ case "local":
25
+ return createLocalBackendDatabase(config, logger)
26
+ }
27
+ }
28
+
29
+ export function createProjectDatabaseBackend(
30
+ config: z.infer<typeof databaseConfig>,
31
+ logger: Logger,
32
+ ): Promise<ProjectDatabaseBackend> {
33
+ switch (config.HIGHSTATE_PROJECT_DATABASE_TYPE) {
34
+ case "local":
35
+ return LocalProjectDatabaseBackend.create(config, logger)
36
+ }
37
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./abstractions"
2
+ export * from "./factory"
3
+ export { getOrCreateBackendIdentity } from "./local"
4
+ export * from "./manager"
5
+ export * from "./prisma"
6
+ export * from "./well-known"
@@ -0,0 +1,134 @@
1
+ import type { Logger } from "pino"
2
+ import type { BackendDatabase } from "../prisma"
3
+ import { randomBytes } from "node:crypto"
4
+ import { PrismaLibSQL } from "@prisma/adapter-libsql"
5
+ import { armor, Decrypter, Encrypter, identityToRecipient } from "age-encryption"
6
+ import { z } from "zod"
7
+ import { codebaseConfig, getCodebaseHighstatePath } from "../../common"
8
+ import { PrismaClient } from "../_generated/backend/sqlite/client"
9
+ import { backendDatabaseVersion } from "../abstractions"
10
+ import { migrateDatabase } from "../migrate"
11
+ import { ensureWellKnownEntitiesCreated } from "../well-known"
12
+ import { getOrCreateBackendIdentity } from "./keyring"
13
+ import { type DatabaseMetaFile, readMetaFile, writeMetaFile } from "./meta"
14
+
15
+ export const localBackendDatabaseConfig = z.object({
16
+ ...codebaseConfig.shape,
17
+ HIGHSTATE_BACKEND_DATABASE_LOCAL_PATH: z.string().optional(),
18
+ HIGHSTATE_ENCRYPTION_ENABLED: z.stringbool().default(true),
19
+ })
20
+
21
+ async function createMasterKey(logger: Logger) {
22
+ const identity = await getOrCreateBackendIdentity(logger)
23
+
24
+ const masterKey = randomBytes(32).toString("hex")
25
+ const encrypter = new Encrypter()
26
+
27
+ const recipient = await identityToRecipient(identity)
28
+ encrypter.addRecipient(recipient)
29
+
30
+ const encryptedMasterKey = await encrypter.encrypt(masterKey)
31
+ const armoredMasterKey = armor.encode(encryptedMasterKey)
32
+
33
+ return { armoredMasterKey, masterKey }
34
+ }
35
+
36
+ async function ensureDatabaseInitialized(
37
+ databasePath: string,
38
+ encryptionEnabled: boolean,
39
+ logger: Logger,
40
+ ) {
41
+ const meta = await readMetaFile(databasePath)
42
+
43
+ if (!meta) {
44
+ logger.info("creating new database")
45
+
46
+ const masterKey = encryptionEnabled ? await createMasterKey(logger) : undefined
47
+
48
+ const metaFile: DatabaseMetaFile = {
49
+ version: backendDatabaseVersion,
50
+ masterKey: masterKey?.armoredMasterKey,
51
+ }
52
+
53
+ return { shouldMigrate: true, masterKey: masterKey?.masterKey, metaFile }
54
+ }
55
+
56
+ if (meta.version > backendDatabaseVersion) {
57
+ throw new Error(
58
+ `Database version (${meta.version}) is newer than expected (${backendDatabaseVersion}). You likely need to update the Highstate.`,
59
+ )
60
+ }
61
+
62
+ if (!encryptionEnabled) {
63
+ return {
64
+ shouldMigrate: meta.version < backendDatabaseVersion,
65
+ masterKey: undefined,
66
+ metaFile: meta,
67
+ }
68
+ }
69
+
70
+ if (!meta.masterKey) {
71
+ throw new Error(
72
+ `Database meta file at "${databasePath}/meta.yaml" does not contain a master key.`,
73
+ )
74
+ }
75
+
76
+ const identity = await getOrCreateBackendIdentity(logger)
77
+
78
+ const decrypter = new Decrypter()
79
+ decrypter.addIdentity(identity)
80
+
81
+ const encryptedMasterKey = armor.decode(meta.masterKey)
82
+ const masterKey = await decrypter.decrypt(encryptedMasterKey, "text")
83
+
84
+ logger.info("loaded backend master key using OS keyring")
85
+
86
+ return {
87
+ shouldMigrate: meta.version < backendDatabaseVersion,
88
+ masterKey,
89
+ metaFile: meta,
90
+ }
91
+ }
92
+
93
+ export async function createLocalBackendDatabase(
94
+ config: z.infer<typeof localBackendDatabaseConfig>,
95
+ logger: Logger,
96
+ ): Promise<BackendDatabase> {
97
+ if (!config.HIGHSTATE_ENCRYPTION_ENABLED) {
98
+ logger.warn("local database encryption is disabled, this is not recommended for production use")
99
+ }
100
+
101
+ let databasePath = config.HIGHSTATE_BACKEND_DATABASE_LOCAL_PATH
102
+ databasePath ??= await getCodebaseHighstatePath(config, logger)
103
+
104
+ const { shouldMigrate, masterKey, metaFile } = await ensureDatabaseInitialized(
105
+ databasePath,
106
+ config.HIGHSTATE_ENCRYPTION_ENABLED,
107
+ logger,
108
+ )
109
+
110
+ const databaseUrl = `file:${databasePath}/backend.db`
111
+
112
+ if (shouldMigrate) {
113
+ await migrateDatabase(databaseUrl, "backend/sqlite", masterKey, logger)
114
+
115
+ // update version in meta file
116
+ await writeMetaFile(databasePath, { ...metaFile, version: backendDatabaseVersion })
117
+ }
118
+
119
+ const adapter = new PrismaLibSQL({
120
+ url: databaseUrl,
121
+ encryptionKey: masterKey,
122
+ })
123
+
124
+ const prismaClient = new PrismaClient({
125
+ adapter,
126
+ })
127
+
128
+ await ensureWellKnownEntitiesCreated(prismaClient as BackendDatabase)
129
+ logger.info("database is ready")
130
+
131
+ // yes, we return sqlite client as postgresql client
132
+ // TODO: https://github.com/prisma/prisma/issues/2443
133
+ return prismaClient as BackendDatabase
134
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./backend"
2
+ export * from "./keyring"
3
+ export * from "./project"
@@ -0,0 +1,46 @@
1
+ import { readFile, writeFile } from "node:fs/promises"
2
+ import { parse, stringify } from "yaml"
3
+ import { z } from "zod"
4
+
5
+ const databaseMetaFileSchema = z.object({
6
+ version: z.number(),
7
+ masterKey: z.string().optional(),
8
+ })
9
+
10
+ export type DatabaseMetaFile = z.infer<typeof databaseMetaFileSchema>
11
+
12
+ export async function readMetaFile(
13
+ databasePath: string,
14
+ ): Promise<z.infer<typeof databaseMetaFileSchema> | undefined> {
15
+ const metaFilePath = `${databasePath}/backend.meta.yaml`
16
+
17
+ let content: string
18
+ try {
19
+ content = await readFile(metaFilePath, "utf-8")
20
+ } catch (error) {
21
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
22
+ return undefined
23
+ }
24
+
25
+ throw new Error(`Failed to read database meta file at "${metaFilePath}"`, { cause: error })
26
+ }
27
+
28
+ try {
29
+ return databaseMetaFileSchema.parse(parse(content))
30
+ } catch (error) {
31
+ throw new Error(`Failed to parse database meta file at "${metaFilePath}"`, { cause: error })
32
+ }
33
+ }
34
+
35
+ export async function writeMetaFile(
36
+ databasePath: string,
37
+ meta: z.infer<typeof databaseMetaFileSchema>,
38
+ ): Promise<void> {
39
+ const metaFilePath = `${databasePath}/backend.meta.yaml`
40
+
41
+ try {
42
+ await writeFile(metaFilePath, stringify(meta), "utf-8")
43
+ } catch (error) {
44
+ throw new Error(`Failed to write database meta file at "${metaFilePath}"`, { cause: error })
45
+ }
46
+ }
@@ -0,0 +1,25 @@
1
+ import { PrismaLibSQL } from "@prisma/adapter-libsql"
2
+ import { defineConfig } from "prisma/config"
3
+
4
+ if (!process.env.HIGHSTATE_MIGRATION_DATABASE_SCHEMA_PATH) {
5
+ throw new Error("HIGHSTATE_MIGRATION_DATABASE_SCHEMA_PATH is not set")
6
+ }
7
+
8
+ export default defineConfig({
9
+ experimental: {
10
+ adapter: true,
11
+ },
12
+
13
+ schema: `../../../prisma/${process.env.HIGHSTATE_MIGRATION_DATABASE_SCHEMA_PATH}`,
14
+
15
+ async adapter() {
16
+ if (!process.env.HIGHSTATE_MIGRATION_DATABASE_URL) {
17
+ throw new Error("HIGHSTATE_MIGRATION_DATABASE_URL is not set")
18
+ }
19
+
20
+ return new PrismaLibSQL({
21
+ url: process.env.HIGHSTATE_MIGRATION_DATABASE_URL,
22
+ encryptionKey: process.env.HIGHSTATE_MIGRATION_DATABASE_ENCRYPTION_KEY || undefined,
23
+ })
24
+ },
25
+ })
@@ -0,0 +1,39 @@
1
+ import type { Logger } from "pino"
2
+ import type { z } from "zod"
3
+ import type { ProjectDatabaseBackend } from "../abstractions"
4
+ import { mkdir } from "node:fs/promises"
5
+ import { PrismaLibSQL } from "@prisma/adapter-libsql"
6
+ import { type codebaseConfig, getCodebaseHighstatePath } from "../../common"
7
+ import { ProjectDatabase } from "../prisma"
8
+
9
+ export class LocalProjectDatabaseBackend implements ProjectDatabaseBackend {
10
+ constructor(private readonly highstatePath: string) {}
11
+
12
+ async openProjectDatabase(
13
+ projectId: string,
14
+ masterKey?: string,
15
+ ): Promise<[database: ProjectDatabase, url: string]> {
16
+ const databasePath = `${this.highstatePath}/projects/${projectId}`
17
+ await mkdir(databasePath, { recursive: true })
18
+
19
+ const databaseUrl = `file:${databasePath}/project.db`
20
+
21
+ const adapter = new PrismaLibSQL({
22
+ url: databaseUrl,
23
+ encryptionKey: masterKey,
24
+ })
25
+
26
+ const database = new ProjectDatabase({ adapter })
27
+
28
+ return [database, databaseUrl]
29
+ }
30
+
31
+ static async create(
32
+ config: z.infer<typeof codebaseConfig>,
33
+ logger: Logger,
34
+ ): Promise<LocalProjectDatabaseBackend> {
35
+ const highstatePath = await getCodebaseHighstatePath(config, logger)
36
+
37
+ return new LocalProjectDatabaseBackend(highstatePath)
38
+ }
39
+ }