@aeolus-fleet/trierarch-plugin 0.0.0 → 0.20.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 (157) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +39 -1
  3. package/dist/adapters/crypto/idempotency-keys.d.ts +3 -0
  4. package/dist/adapters/crypto/idempotency-keys.js +4 -0
  5. package/dist/adapters/crypto/idempotency-keys.js.map +1 -0
  6. package/dist/adapters/crypto/request-hasher.d.ts +3 -0
  7. package/dist/adapters/crypto/request-hasher.js +4 -0
  8. package/dist/adapters/crypto/request-hasher.js.map +1 -0
  9. package/dist/adapters/fleet/console-sessions.d.ts +2 -0
  10. package/dist/adapters/fleet/console-sessions.js +23 -0
  11. package/dist/adapters/fleet/console-sessions.js.map +1 -0
  12. package/dist/adapters/fleet/rest-fleet-door.d.ts +2 -0
  13. package/dist/adapters/fleet/rest-fleet-door.js +122 -0
  14. package/dist/adapters/fleet/rest-fleet-door.js.map +1 -0
  15. package/dist/adapters/http/version.d.ts +6 -0
  16. package/dist/adapters/http/version.js +12 -0
  17. package/dist/adapters/http/version.js.map +1 -0
  18. package/dist/adapters/prisma/client.d.ts +10 -0
  19. package/dist/adapters/prisma/client.js +20 -0
  20. package/dist/adapters/prisma/client.js.map +1 -0
  21. package/dist/adapters/prisma/connection-store.d.ts +4 -0
  22. package/dist/adapters/prisma/connection-store.js +28 -0
  23. package/dist/adapters/prisma/connection-store.js.map +1 -0
  24. package/dist/adapters/prisma/fleet-forgetter.d.ts +4 -0
  25. package/dist/adapters/prisma/fleet-forgetter.js +10 -0
  26. package/dist/adapters/prisma/fleet-forgetter.js.map +1 -0
  27. package/dist/adapters/prisma/fleet-switches.d.ts +4 -0
  28. package/dist/adapters/prisma/fleet-switches.js +10 -0
  29. package/dist/adapters/prisma/fleet-switches.js.map +1 -0
  30. package/dist/adapters/prisma/generated/browser.d.ts +24 -0
  31. package/dist/adapters/prisma/generated/browser.js +18 -0
  32. package/dist/adapters/prisma/generated/browser.js.map +1 -0
  33. package/dist/adapters/prisma/generated/client.d.ts +43 -0
  34. package/dist/adapters/prisma/generated/client.js +38 -0
  35. package/dist/adapters/prisma/generated/client.js.map +1 -0
  36. package/dist/adapters/prisma/generated/commonInputTypes.d.ts +235 -0
  37. package/dist/adapters/prisma/generated/commonInputTypes.js +11 -0
  38. package/dist/adapters/prisma/generated/commonInputTypes.js.map +1 -0
  39. package/dist/adapters/prisma/generated/enums.d.ts +1 -0
  40. package/dist/adapters/prisma/generated/enums.js +12 -0
  41. package/dist/adapters/prisma/generated/enums.js.map +1 -0
  42. package/dist/adapters/prisma/generated/internal/class.d.ts +154 -0
  43. package/dist/adapters/prisma/generated/internal/class.js +50 -0
  44. package/dist/adapters/prisma/generated/internal/class.js.map +1 -0
  45. package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +766 -0
  46. package/dist/adapters/prisma/generated/internal/prismaNamespace.js +117 -0
  47. package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -0
  48. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +78 -0
  49. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +87 -0
  50. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -0
  51. package/dist/adapters/prisma/generated/models/Connection.d.ts +1011 -0
  52. package/dist/adapters/prisma/generated/models/Connection.js +2 -0
  53. package/dist/adapters/prisma/generated/models/Connection.js.map +1 -0
  54. package/dist/adapters/prisma/generated/models/FleetSwitch.d.ts +945 -0
  55. package/dist/adapters/prisma/generated/models/FleetSwitch.js +2 -0
  56. package/dist/adapters/prisma/generated/models/FleetSwitch.js.map +1 -0
  57. package/dist/adapters/prisma/generated/models/InstallationRequest.d.ts +1030 -0
  58. package/dist/adapters/prisma/generated/models/InstallationRequest.js +2 -0
  59. package/dist/adapters/prisma/generated/models/InstallationRequest.js.map +1 -0
  60. package/dist/adapters/prisma/generated/models.d.ts +4 -0
  61. package/dist/adapters/prisma/generated/models.js +2 -0
  62. package/dist/adapters/prisma/generated/models.js.map +1 -0
  63. package/dist/adapters/prisma/installation-requests.d.ts +4 -0
  64. package/dist/adapters/prisma/installation-requests.js +25 -0
  65. package/dist/adapters/prisma/installation-requests.js.map +1 -0
  66. package/dist/adapters/prisma/migrate.d.ts +5 -0
  67. package/dist/adapters/prisma/migrate.js +40 -0
  68. package/dist/adapters/prisma/migrate.js.map +1 -0
  69. package/dist/adapters/trpc/router.d.ts +303 -0
  70. package/dist/adapters/trpc/router.js +227 -0
  71. package/dist/adapters/trpc/router.js.map +1 -0
  72. package/dist/app.d.ts +42 -0
  73. package/dist/app.js +205 -0
  74. package/dist/app.js.map +1 -0
  75. package/dist/bin/aeolus-trierarch-plugin.d.ts +2 -0
  76. package/dist/bin/aeolus-trierarch-plugin.js +61 -0
  77. package/dist/bin/aeolus-trierarch-plugin.js.map +1 -0
  78. package/dist/config.d.ts +32 -0
  79. package/dist/config.js +49 -0
  80. package/dist/config.js.map +1 -0
  81. package/dist/core/assignment/assign-crews.d.ts +27 -0
  82. package/dist/core/assignment/assign-crews.js +49 -0
  83. package/dist/core/assignment/assign-crews.js.map +1 -0
  84. package/dist/core/assignment/check-crew-settings.d.ts +19 -0
  85. package/dist/core/assignment/check-crew-settings.js +24 -0
  86. package/dist/core/assignment/check-crew-settings.js.map +1 -0
  87. package/dist/core/assignment/placement.d.ts +59 -0
  88. package/dist/core/assignment/placement.js +113 -0
  89. package/dist/core/assignment/placement.js.map +1 -0
  90. package/dist/core/assignment/read-placement.d.ts +17 -0
  91. package/dist/core/assignment/read-placement.js +39 -0
  92. package/dist/core/assignment/read-placement.js.map +1 -0
  93. package/dist/core/connection/connect.d.ts +26 -0
  94. package/dist/core/connection/connect.js +44 -0
  95. package/dist/core/connection/connect.js.map +1 -0
  96. package/dist/core/connection/ports.d.ts +177 -0
  97. package/dist/core/connection/ports.js +2 -0
  98. package/dist/core/connection/ports.js.map +1 -0
  99. package/dist/core/connection/read-connection.d.ts +14 -0
  100. package/dist/core/connection/read-connection.js +24 -0
  101. package/dist/core/connection/read-connection.js.map +1 -0
  102. package/dist/core/installation/delete-fleet.d.ts +21 -0
  103. package/dist/core/installation/delete-fleet.js +21 -0
  104. package/dist/core/installation/delete-fleet.js.map +1 -0
  105. package/dist/core/installation/ports.d.ts +46 -0
  106. package/dist/core/installation/ports.js +2 -0
  107. package/dist/core/installation/ports.js.map +1 -0
  108. package/dist/core/installation/read-fleet.d.ts +18 -0
  109. package/dist/core/installation/read-fleet.js +9 -0
  110. package/dist/core/installation/read-fleet.js.map +1 -0
  111. package/dist/core/installation/request-id.d.ts +8 -0
  112. package/dist/core/installation/request-id.js +10 -0
  113. package/dist/core/installation/request-id.js.map +1 -0
  114. package/dist/core/installation/served.d.ts +12 -0
  115. package/dist/core/installation/served.js +8 -0
  116. package/dist/core/installation/served.js.map +1 -0
  117. package/dist/core/installation/set-fleet-enabled.d.ts +24 -0
  118. package/dist/core/installation/set-fleet-enabled.js +21 -0
  119. package/dist/core/installation/set-fleet-enabled.js.map +1 -0
  120. package/dist/core/machines/join-machine.d.ts +40 -0
  121. package/dist/core/machines/join-machine.js +35 -0
  122. package/dist/core/machines/join-machine.js.map +1 -0
  123. package/dist/core/machines/label-machines.d.ts +25 -0
  124. package/dist/core/machines/label-machines.js +120 -0
  125. package/dist/core/machines/label-machines.js.map +1 -0
  126. package/dist/core/machines/list-machines.d.ts +34 -0
  127. package/dist/core/machines/list-machines.js +47 -0
  128. package/dist/core/machines/list-machines.js.map +1 -0
  129. package/dist/core/machines/ports.d.ts +4 -0
  130. package/dist/core/machines/ports.js +2 -0
  131. package/dist/core/machines/ports.js.map +1 -0
  132. package/dist/core/machines/silent.d.ts +9 -0
  133. package/dist/core/machines/silent.js +9 -0
  134. package/dist/core/machines/silent.js.map +1 -0
  135. package/dist/core/operator/authenticate-operator.d.ts +21 -0
  136. package/dist/core/operator/authenticate-operator.js +26 -0
  137. package/dist/core/operator/authenticate-operator.js.map +1 -0
  138. package/dist/core/operator/ports.d.ts +15 -0
  139. package/dist/core/operator/ports.js +2 -0
  140. package/dist/core/operator/ports.js.map +1 -0
  141. package/dist/core/shared/clock.d.ts +4 -0
  142. package/dist/core/shared/clock.js +2 -0
  143. package/dist/core/shared/clock.js.map +1 -0
  144. package/dist/core/shared/errors.d.ts +10 -0
  145. package/dist/core/shared/errors.js +6 -0
  146. package/dist/core/shared/errors.js.map +1 -0
  147. package/dist/core/shared/result.d.ts +16 -0
  148. package/dist/core/shared/result.js +7 -0
  149. package/dist/core/shared/result.js.map +1 -0
  150. package/dist/index.d.ts +3 -0
  151. package/dist/index.js +3 -0
  152. package/dist/index.js.map +1 -0
  153. package/package.json +47 -3
  154. package/prisma.config.ts +18 -0
  155. package/src/adapters/prisma/migrations/20261006220000_init/migration.sql +35 -0
  156. package/src/adapters/prisma/migrations/migration_lock.toml +3 -0
  157. package/src/adapters/prisma/schema.prisma +58 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1 +1,39 @@
1
- # @aeolus-fleet/trierarch-plugin: placeholder, the real package is published from 0.18.0.
1
+ # @aeolus-fleet/trierarch-plugin
2
+
3
+ The trierarchs' plugin on the server side (decision 0030): it brings machines into the fleet and assigns crew requests to their trierarchs. Optional: a fleet works without it. Aeolus knows nothing about it beyond its ship, which holds `fleet:read`, `fleet:manage` and `crew:assign` and reaches the fleet only through its public API. What it does is in [docs/trierarch.md](../../docs/trierarch.md).
4
+
5
+ So far: its own process and small database (each fleet's connection and switch), the connection the operator makes as its ship, a machine joining, the machines with their trierarchs' reports, assignment (docs/trierarch.md, "Assignment"), the installation procedures, `/api/health` and `/api/version`.
6
+
7
+ Assignment runs as a pass for every fleet it serves and is connected to. Each pass reads the fleet whole: the unassigned requests of ships that await crew, and the trierarchs that report details and are not silent. It claims each request it places, by optimistic claim, and writes the reason on each it cannot. A claim the fleet refuses because the request changed (another pass won it, or the ship was crewed or its request removed) is read again on the next pass. Run more than one process if you like: the fleet stores exactly one assignment per request.
8
+
9
+ ## Running
10
+
11
+ 1. Give it its own database and set its environment. No ship and no secret: the operator connects it.
12
+
13
+ | Variable | Required | What |
14
+ | --- | --- | --- |
15
+ | `DATABASE_URL` | yes | Its own Postgres database (`postgres://...`); it may share the Postgres server with the fleet and squadrons |
16
+ | `FLEET_URL` | yes | The fleet's public URL; it calls the ship API at `<FLEET_URL>/api/v1`, checks console sessions there, and names it in each joining machine's setup line. Not a secret; fixed here, so no caller can point it at another fleet |
17
+ | `HOST`, `PORT` | no | Where it listens; `127.0.0.1:4200` by default |
18
+ | `LOG_LEVEL` | no | `info` by default |
19
+ | `INSTALLATION_TOKEN` | no | The token a hosting service presents to its installation procedures, at least 32 characters (decision 0021). Unset: they do not exist and every fleet is served, as a self-hosted install needs |
20
+ | `TRIERARCH_SILENT_AFTER_SECONDS` | no | A trierarch whose last seen is older than this is silent: it gets no new requests. `300` by default |
21
+ | `TRIERARCH_PASS_INTERVAL_SECONDS` | no | How often assignment runs a pass for each fleet. `10` by default |
22
+
23
+ 2. `aeolus-trierarch-plugin start` migrates the database, serves, and runs an assignment pass every interval. Every fleet it serves whose kept crew token its fleet still takes is connected again; any other fleet is not connected. `aeolus-trierarch-plugin migrate` migrates alone.
24
+ 3. Each fleet's operator connects it: commission its ship with `fleet:read`, `fleet:manage` and `crew:assign`, and hand the ship's secret to `connection.connect`, server to server. It registers as a server and keeps only the crew token; the secret is never stored or logged. The console's screens for it come later.
25
+
26
+ ## API
27
+
28
+ One tRPC router at `/trpc`, called with the console's session cookie, which the fleet checks through `console.session`. Every procedure but the installation's works on the session's fleet.
29
+
30
+ | Procedure | What |
31
+ | --- | --- |
32
+ | `connection.status` | Whether it serves the fleet and is connected, as which ship, and the ship it was last connected as |
33
+ | `connection.connect` | Connects with its ship's id and secret (`fleet:manage` session). Refused while connected (CONFLICT), for a ship of another fleet or without the three scopes (BAD_REQUEST) |
34
+ | `machines.join` | Brings a machine in, by name (`fleet:manage` session): commissions a ship of type `trierarch` with `crew:run` and answers its starting prompt, crew lines, secret and setup line, `npx @aeolus-fleet/trierarch init --fleet-url <url> --ship-id <id> --secret <secret>`, each shown once. A name an active ship holds: CONFLICT |
35
+ | `machines.list` | The fleet's active ships of type `trierarch`, each with its trierarch's last report and details (null until it reports), and whether it is silent |
36
+ | `requests.check` | Whether crew settings would be placed now, by assignment's rules, before a crew is requested with them: `fits`; `refused` with the settings field at fault and why; or `noRoom` when they fit but no trierarch has room (a request would wait). Writes nothing |
37
+ | `installation.setEnabled`, `get`, `delete` | With `x-aeolus-installation-token`: switches a fleet on or off, reads it, forgets it (decision 0021) |
38
+
39
+ While it is off for the fleet, every procedure but `connection.status` answers FORBIDDEN; until it is connected, `machines.*` answer PRECONDITION_FAILED.
@@ -0,0 +1,3 @@
1
+ import type { IdempotencyKeys } from '../../core/machines/ports.js';
2
+ /** A random UUID per commission: never the same twice. */
3
+ export declare const randomIdempotencyKeys: IdempotencyKeys;
@@ -0,0 +1,4 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ /** A random UUID per commission: never the same twice. */
3
+ export const randomIdempotencyKeys = { next: () => randomUUID() };
4
+ //# sourceMappingURL=idempotency-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency-keys.js","sourceRoot":"","sources":["../../../src/adapters/crypto/idempotency-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAoB,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RequestHasher } from '../../core/installation/ports.js';
2
+ /** A request's text as its SHA-256, in hex: what the installation keeps instead of the request. */
3
+ export declare const sha256RequestHasher: RequestHasher;
@@ -0,0 +1,4 @@
1
+ import { createHash } from 'node:crypto';
2
+ /** A request's text as its SHA-256, in hex: what the installation keeps instead of the request. */
3
+ export const sha256RequestHasher = { hash: (text) => createHash('sha256').update(text).digest('hex') };
4
+ //# sourceMappingURL=request-hasher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-hasher.js","sourceRoot":"","sources":["../../../src/adapters/crypto/request-hasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,mGAAmG;AACnG,MAAM,CAAC,MAAM,mBAAmB,GAAkB,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { ConsoleSessions } from '../../core/operator/ports.js';
2
+ export declare function createFleetConsoleSessions(fleetUrl: string): ConsoleSessions;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Asks the fleet whether a forwarded console session cookie is a signed-in
3
+ * operator's or a viewer's, with its scopes, with `console.session`
4
+ * (decisions 0012 and 0022): the cookie travels from the console's server,
5
+ * server to server.
6
+ */
7
+ import { consoleSessionOutputSchema } from '@aeolus-fleet/common';
8
+ import { z } from 'zod';
9
+ import { err, ok } from '../../core/shared/result.js';
10
+ const sessionAnswer = z.object({ result: z.object({ data: consoleSessionOutputSchema }) });
11
+ export function createFleetConsoleSessions(fleetUrl) {
12
+ return {
13
+ check: async (cookie) => {
14
+ const response = await fetch(`${fleetUrl}/trpc/console.session`, { headers: { cookie } });
15
+ if (!response.ok) {
16
+ return err({ code: 'UNAUTHORIZED', message: 'No signed-in console session' });
17
+ }
18
+ const { fleetId, kind, scopes } = sessionAnswer.parse(await response.json()).result.data;
19
+ return ok({ fleetId, kind, scopes });
20
+ },
21
+ };
22
+ }
23
+ //# sourceMappingURL=console-sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-sessions.js","sourceRoot":"","sources":["../../../src/adapters/fleet/console-sessions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAC;AAEtD,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,EAAE,CAAC,CAAC;AAE3F,MAAM,UAAU,0BAA0B,CAAC,QAAgB;IACzD,OAAO;QACL,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,QAAQ,uBAAuB,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;YAC1F,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;YACzF,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { FleetDoor } from '../../core/connection/ports.js';
2
+ export declare function createRestFleetDoor(fleetUrl: string): FleetDoor;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The fleet's ship calls over its REST API (`/api/v1`), as any ship that is
3
+ * not TypeScript-bound may make them: the trierarch plugin uses the public API
4
+ * like any client (decision 0030). A refusal reads as the fleet's code and
5
+ * message.
6
+ */
7
+ import { commissionShipOutputSchema, defineLabelOutputSchema, fleetListOutputSchema, idSchema, labelsOutputSchema, shipDetailOutputSchema } from '@aeolus-fleet/common';
8
+ import { z } from 'zod';
9
+ import { err, ok } from '../../core/shared/result.js';
10
+ const refusalSchema = z.object({ code: z.string(), message: z.string() });
11
+ /** Where the trierarch plugin says its ship runs: on a server the operator runs. */
12
+ const LOCATION = { kind: 'SERVER' };
13
+ /** The harness the trierarch plugin states when it registers its ship: it is software, not a model. */
14
+ const HARNESS = 'aeolus-trierarch-plugin';
15
+ async function call(fleetUrl, request) {
16
+ const headers = {};
17
+ if (request.crewToken !== undefined) {
18
+ headers.authorization = `Bearer ${request.crewToken}`;
19
+ }
20
+ if (request.body !== undefined) {
21
+ headers['content-type'] = 'application/json';
22
+ }
23
+ let response;
24
+ let body;
25
+ try {
26
+ response = await fetch(`${fleetUrl}/api/v1${request.path}`, {
27
+ method: request.method,
28
+ headers,
29
+ body: request.body === undefined ? undefined : JSON.stringify(request.body),
30
+ });
31
+ body = await response.json();
32
+ }
33
+ catch (error) {
34
+ return err({ code: 'UNAVAILABLE', message: `The fleet did not answer: ${error instanceof Error ? error.message : String(error)}` });
35
+ }
36
+ return response.ok ? ok(request.answers.parse(body)) : err(refusalSchema.parse(body));
37
+ }
38
+ function dateOf(iso) {
39
+ return iso === null ? null : new Date(iso);
40
+ }
41
+ export function createRestFleetDoor(fleetUrl) {
42
+ return {
43
+ register: ({ shipId, secret }) => call(fleetUrl, { path: '/ship/register', method: 'POST', body: { shipId, secret, location: LOCATION, harness: HARNESS }, answers: z.object({ crewToken: z.string() }) }),
44
+ whoami: (crewToken) => call(fleetUrl, {
45
+ path: '/ship/whoami',
46
+ method: 'GET',
47
+ crewToken,
48
+ answers: z.object({ shipId: idSchema('ship'), fleetId: idSchema('fleet'), name: z.string(), type: z.string() }),
49
+ }),
50
+ getShip: async (crewToken, ship) => {
51
+ const read = await call(fleetUrl, { path: '/fleet/ship', method: 'POST', crewToken, body: ship, answers: shipDetailOutputSchema });
52
+ if (!read.isOk) {
53
+ return read;
54
+ }
55
+ const { status, scopes, commissionedAt, report, crewRequest } = read.value;
56
+ return ok({
57
+ status,
58
+ scopes,
59
+ commissionedAt: new Date(commissionedAt),
60
+ report: report && { state: report.state, note: report.note, reportedAt: new Date(report.reportedAt), details: report.details },
61
+ crewSettings: crewRequest?.settings ?? null,
62
+ });
63
+ },
64
+ deregister: async (crewToken) => {
65
+ const ended = await call(fleetUrl, { path: '/ship/deregister', method: 'POST', crewToken, body: {}, answers: z.unknown() });
66
+ return ended.isOk ? ok(undefined) : ended;
67
+ },
68
+ commission: async (crewToken, ship) => {
69
+ const commissioned = await call(fleetUrl, { path: '/fleet/commission', method: 'POST', crewToken, body: ship, answers: commissionShipOutputSchema });
70
+ if (!commissioned.isOk) {
71
+ return commissioned;
72
+ }
73
+ const { shipId, prompt, crewLines, secret } = commissioned.value;
74
+ // A new key always answers the starting prompt; a repeat of an earlier key does not, and the plugin never repeats one.
75
+ if (prompt === null || crewLines === null || secret === null) {
76
+ return err({ code: 'CONFLICT', message: 'The fleet answered an earlier commission under this idempotency key' });
77
+ }
78
+ return ok({ shipId, prompt, crewLines, secret });
79
+ },
80
+ listShips: async (crewToken) => {
81
+ const listed = await call(fleetUrl, { path: '/fleet/list', method: 'POST', crewToken, body: {}, answers: fleetListOutputSchema });
82
+ return listed.isOk
83
+ ? ok(listed.value.map(({ id, name, type, status, lastSeenAt, crewRequest, labels }) => ({
84
+ shipId: id,
85
+ name,
86
+ type,
87
+ status,
88
+ lastSeenAt: dateOf(lastSeenAt),
89
+ crewRequest: crewRequest && { requestedAt: new Date(crewRequest.requestedAt), assignedTo: crewRequest.assignedTo?.id ?? null, reason: crewRequest.reason },
90
+ labels: labels.map(({ labelId, valueId }) => ({ labelId, valueId })),
91
+ })))
92
+ : listed;
93
+ },
94
+ assignCrew: async (crewToken, claim) => {
95
+ const claimed = await call(fleetUrl, { path: '/fleet/assignCrew', method: 'POST', crewToken, body: claim, answers: z.unknown() });
96
+ return claimed.isOk ? ok(undefined) : claimed;
97
+ },
98
+ listLabels: async (crewToken) => {
99
+ const listed = await call(fleetUrl, { path: '/fleet/labels', method: 'GET', crewToken, answers: labelsOutputSchema });
100
+ return listed.isOk
101
+ ? ok(listed.value.map(({ id, key, values, owner }) => ({ labelId: id, key, values: values.map((value) => ({ valueId: value.id, value: value.value })), ownerShipId: owner.id })))
102
+ : listed;
103
+ },
104
+ defineLabel: async (crewToken, label) => {
105
+ const defined = await call(fleetUrl, { path: '/fleet/defineLabel', method: 'POST', crewToken, body: label, answers: defineLabelOutputSchema });
106
+ return defined.isOk ? ok({ labelId: defined.value.labelId, values: defined.value.values.map((value) => ({ valueId: value.id, value: value.value })) }) : defined;
107
+ },
108
+ assignLabel: async (crewToken, assignment) => {
109
+ const assigned = await call(fleetUrl, { path: '/fleet/assignLabel', method: 'POST', crewToken, body: assignment, answers: z.unknown() });
110
+ return assigned.isOk ? ok(undefined) : assigned;
111
+ },
112
+ unassignLabel: async (crewToken, assignment) => {
113
+ const unassigned = await call(fleetUrl, { path: '/fleet/unassignLabel', method: 'POST', crewToken, body: assignment, answers: z.unknown() });
114
+ return unassigned.isOk ? ok(undefined) : unassigned;
115
+ },
116
+ explainCrewRequest: async (crewToken, explanation) => {
117
+ const explained = await call(fleetUrl, { path: '/fleet/explainCrewRequest', method: 'POST', crewToken, body: explanation, answers: z.unknown() });
118
+ return explained.isOk ? ok(undefined) : explained;
119
+ },
120
+ };
121
+ }
122
+ //# sourceMappingURL=rest-fleet-door.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest-fleet-door.js","sourceRoot":"","sources":["../../../src/adapters/fleet/rest-fleet-door.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,kBAAkB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AAC;YACzI,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAClD,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;YAC7C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC7I,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACtD,CAAC;QACD,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE;YACnD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAClJ,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The version this trierarch plugin process runs, read from its package.json once:
3
+ * what runs, not what a deploy meant to ship. This file sits at
4
+ * src/adapters/http or dist/adapters/http: the package root is three levels up.
5
+ */
6
+ export declare function runningVersion(): string;
@@ -0,0 +1,12 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { z } from 'zod';
3
+ const packageJson = z.object({ version: z.string() });
4
+ /**
5
+ * The version this trierarch plugin process runs, read from its package.json once:
6
+ * what runs, not what a deploy meant to ship. This file sits at
7
+ * src/adapters/http or dist/adapters/http: the package root is three levels up.
8
+ */
9
+ export function runningVersion() {
10
+ return packageJson.parse(JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'))).version;
11
+ }
12
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/adapters/http/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACxH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { PrismaClient, type Prisma } from './generated/client.js';
2
+ export type { PrismaClient } from './generated/client.js';
3
+ /** The client itself, or the client of one interactive transaction. Repositories take either. */
4
+ export type Db = PrismaClient | Prisma.TransactionClient;
5
+ /** Creates a Prisma client on a pg connection pool for the given database. */
6
+ export declare function createPrismaClient(databaseUrl: string): PrismaClient;
7
+ /** Throws when the database cannot answer a trivial query. */
8
+ export declare function checkDatabase(prisma: PrismaClient): Promise<void>;
9
+ /** The latest migration applied to the database, by name; null before the first. */
10
+ export declare function latestMigration(db: PrismaClient): Promise<string | null>;
@@ -0,0 +1,20 @@
1
+ import { PrismaPg } from '@prisma/adapter-pg';
2
+ import { PrismaClient } from './generated/client.js';
3
+ /** Creates a Prisma client on a pg connection pool for the given database. */
4
+ export function createPrismaClient(databaseUrl) {
5
+ return new PrismaClient({ adapter: new PrismaPg({ connectionString: databaseUrl }) });
6
+ }
7
+ /** Throws when the database cannot answer a trivial query. */
8
+ export async function checkDatabase(prisma) {
9
+ await prisma.$queryRaw `SELECT 1`;
10
+ }
11
+ /** The latest migration applied to the database, by name; null before the first. */
12
+ export async function latestMigration(db) {
13
+ const [row] = await db.$queryRaw `
14
+ SELECT migration_name FROM _prisma_migrations
15
+ WHERE finished_at IS NOT NULL AND rolled_back_at IS NULL
16
+ ORDER BY migration_name DESC
17
+ LIMIT 1`;
18
+ return row?.migration_name ?? null;
19
+ }
20
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/adapters/prisma/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAe,MAAM,uBAAuB,CAAC;AAOlE,8EAA8E;AAC9E,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,QAAQ,CAAC,EAAE,gBAAgB,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAoB;IACtD,MAAM,MAAM,CAAC,SAAS,CAAA,UAAU,CAAC;AACnC,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAgB;IACpD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC,SAAS,CAA8B;;;;YAIpD,CAAC;IACX,OAAO,GAAG,EAAE,cAAc,IAAI,IAAI,CAAC;AACrC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ConnectionStore } from '../../core/connection/ports.js';
2
+ import type { Db } from './client.js';
3
+ /** Each fleet's connection, one row per fleet. */
4
+ export declare function createPrismaConnectionStore(db: Db): ConnectionStore;
@@ -0,0 +1,28 @@
1
+ import { idSchema } from '@aeolus-fleet/common';
2
+ function crewOf(row) {
3
+ return row.crewToken
4
+ ? { fleetId: idSchema('fleet').parse(row.fleetId), shipId: idSchema('ship').parse(row.shipId), name: row.shipName, crewToken: row.crewToken, crewedAt: row.crewedAt }
5
+ : undefined;
6
+ }
7
+ /** Each fleet's connection, one row per fleet. */
8
+ export function createPrismaConnectionStore(db) {
9
+ return {
10
+ find: async (fleetId) => {
11
+ const row = await db.connection.findUnique({ where: { fleetId } });
12
+ return row ? crewOf(row) : undefined;
13
+ },
14
+ binding: async (fleetId) => {
15
+ const row = await db.connection.findUnique({ where: { fleetId } });
16
+ return row ? { fleetId: idSchema('fleet').parse(row.fleetId), shipId: idSchema('ship').parse(row.shipId) } : undefined;
17
+ },
18
+ connected: async () => (await db.connection.findMany({ where: { crewToken: { not: null } }, orderBy: { fleetId: 'asc' } })).flatMap((row) => crewOf(row) ?? []),
19
+ save: async ({ fleetId, shipId, name, crewToken, crewedAt }) => {
20
+ const columns = { shipId, shipName: name, crewToken, crewedAt };
21
+ await db.connection.upsert({ where: { fleetId }, create: { fleetId, ...columns }, update: columns });
22
+ },
23
+ drop: async (fleetId) => {
24
+ await db.connection.updateMany({ where: { fleetId }, data: { crewToken: null } });
25
+ },
26
+ };
27
+ }
28
+ //# sourceMappingURL=connection-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-store.js","sourceRoot":"","sources":["../../../src/adapters/prisma/connection-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAahD,SAAS,MAAM,CAAC,GAAQ;IACtB,OAAO,GAAG,CAAC,SAAS;QAClB,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAA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AAI,EAAE,CAAC;QAC/J,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE;YAC7D,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;YAChE,MAAM,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACvG,CAAC;QACD,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACtB,MAAM,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACpF,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { FleetForgetter } from '../../core/installation/ports.js';
2
+ import type { PrismaClient } from './client.js';
3
+ /** Forgets every record the trierarch plugin holds of a fleet, in one transaction: its connection, its switch and the requests that name it. */
4
+ export declare function createPrismaFleetForgetter(db: PrismaClient): FleetForgetter;
@@ -0,0 +1,10 @@
1
+ /** Forgets every record the trierarch plugin holds of a fleet, in one transaction: its connection, its switch and the requests that name it. */
2
+ export function createPrismaFleetForgetter(db) {
3
+ return {
4
+ forget: async (fleetId) => {
5
+ const where = { where: { fleetId } };
6
+ await db.$transaction([db.connection.deleteMany(where), db.fleetSwitch.deleteMany(where), db.installationRequest.deleteMany(where)]);
7
+ },
8
+ };
9
+ }
10
+ //# sourceMappingURL=fleet-forgetter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet-forgetter.js","sourceRoot":"","sources":["../../../src/adapters/prisma/fleet-forgetter.ts"],"names":[],"mappings":"AAGA,gJAAgJ;AAChJ,MAAM,UAAU,0BAA0B,CAAC,EAAgB;IACzD,OAAO;QACL,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;YACrC,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvI,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { FleetSwitches } from '../../core/installation/ports.js';
2
+ import type { Db } from './client.js';
3
+ /** Each fleet's switch, one row per fleet. */
4
+ export declare function createPrismaFleetSwitches(db: Db): FleetSwitches;
@@ -0,0 +1,10 @@
1
+ /** Each fleet's switch, one row per fleet. */
2
+ export function createPrismaFleetSwitches(db) {
3
+ return {
4
+ find: async (fleetId) => (await db.fleetSwitch.findUnique({ where: { fleetId } }))?.enabled,
5
+ set: async (fleetId, { isEnabled, at }) => {
6
+ await db.fleetSwitch.upsert({ where: { fleetId }, create: { fleetId, enabled: isEnabled, changedAt: at }, update: { enabled: isEnabled, changedAt: at } });
7
+ },
8
+ };
9
+ }
10
+ //# sourceMappingURL=fleet-switches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet-switches.js","sourceRoot":"","sources":["../../../src/adapters/prisma/fleet-switches.ts"],"names":[],"mappings":"AAGA,8CAA8C;AAC9C,MAAM,UAAU,yBAAyB,CAAC,EAAM;IAC9C,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO;QAC3F,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,EAAE;YACxC,MAAM,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7J,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
1
+ import * as Prisma from './internal/prismaNamespaceBrowser.js';
2
+ export { Prisma };
3
+ export * as $Enums from './enums.js';
4
+ export * from './enums.js';
5
+ /**
6
+ * Model Connection
7
+ * The crew token the trierarch plugin holds for each fleet's plugin ship, so a
8
+ * restart crews it again without a new secret. One row per fleet: one install
9
+ * serves many fleets.
10
+ */
11
+ export type Connection = Prisma.ConnectionModel;
12
+ /**
13
+ * Model FleetSwitch
14
+ * Whether the hosting service switched the trierarch plugin on for a fleet
15
+ * (decisions 0021, 0030). None before the first switch.
16
+ */
17
+ export type FleetSwitch = Prisma.FleetSwitchModel;
18
+ /**
19
+ * Model InstallationRequest
20
+ * The installation's requests, by the caller's request id, so a replay answers
21
+ * what the first call answered. A switch names its fleet and goes with it; a
22
+ * delete keeps only the request's hash, so nothing of the deleted fleet stays.
23
+ */
24
+ export type InstallationRequest = Prisma.InstallationRequestModel;