@minion-stack/db 0.2.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 (206) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +8 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/relations.d.ts +126 -0
  6. package/dist/relations.d.ts.map +1 -0
  7. package/dist/relations.js +178 -0
  8. package/dist/relations.js.map +1 -0
  9. package/dist/schema/activity-bins.d.ts +118 -0
  10. package/dist/schema/activity-bins.d.ts.map +1 -0
  11. package/dist/schema/activity-bins.js +19 -0
  12. package/dist/schema/activity-bins.js.map +1 -0
  13. package/dist/schema/agent-groups.d.ts +180 -0
  14. package/dist/schema/agent-groups.d.ts.map +1 -0
  15. package/dist/schema/agent-groups.js +22 -0
  16. package/dist/schema/agent-groups.js.map +1 -0
  17. package/dist/schema/agents.d.ts +196 -0
  18. package/dist/schema/agents.d.ts.map +1 -0
  19. package/dist/schema/agents.js +20 -0
  20. package/dist/schema/agents.js.map +1 -0
  21. package/dist/schema/auth/index.d.ts +1713 -0
  22. package/dist/schema/auth/index.d.ts.map +1 -0
  23. package/dist/schema/auth/index.js +152 -0
  24. package/dist/schema/auth/index.js.map +1 -0
  25. package/dist/schema/backup-configs.d.ts +207 -0
  26. package/dist/schema/backup-configs.d.ts.map +1 -0
  27. package/dist/schema/backup-configs.js +18 -0
  28. package/dist/schema/backup-configs.js.map +1 -0
  29. package/dist/schema/bugs.d.ts +232 -0
  30. package/dist/schema/bugs.d.ts.map +1 -0
  31. package/dist/schema/bugs.js +26 -0
  32. package/dist/schema/bugs.js.map +1 -0
  33. package/dist/schema/builder.d.ts +1546 -0
  34. package/dist/schema/builder.d.ts.map +1 -0
  35. package/dist/schema/builder.js +143 -0
  36. package/dist/schema/builder.js.map +1 -0
  37. package/dist/schema/channel-assignments.d.ts +120 -0
  38. package/dist/schema/channel-assignments.d.ts.map +1 -0
  39. package/dist/schema/channel-assignments.js +19 -0
  40. package/dist/schema/channel-assignments.js.map +1 -0
  41. package/dist/schema/channel-identities.d.ts +141 -0
  42. package/dist/schema/channel-identities.d.ts.map +1 -0
  43. package/dist/schema/channel-identities.js +21 -0
  44. package/dist/schema/channel-identities.js.map +1 -0
  45. package/dist/schema/channels.d.ts +213 -0
  46. package/dist/schema/channels.d.ts.map +1 -0
  47. package/dist/schema/channels.js +26 -0
  48. package/dist/schema/channels.js.map +1 -0
  49. package/dist/schema/chat-messages.d.ts +192 -0
  50. package/dist/schema/chat-messages.d.ts.map +1 -0
  51. package/dist/schema/chat-messages.js +23 -0
  52. package/dist/schema/chat-messages.js.map +1 -0
  53. package/dist/schema/config-snapshots.d.ts +120 -0
  54. package/dist/schema/config-snapshots.d.ts.map +1 -0
  55. package/dist/schema/config-snapshots.js +16 -0
  56. package/dist/schema/config-snapshots.js.map +1 -0
  57. package/dist/schema/connection-events.d.ts +173 -0
  58. package/dist/schema/connection-events.d.ts.map +1 -0
  59. package/dist/schema/connection-events.js +22 -0
  60. package/dist/schema/connection-events.js.map +1 -0
  61. package/dist/schema/credential-health.d.ts +116 -0
  62. package/dist/schema/credential-health.d.ts.map +1 -0
  63. package/dist/schema/credential-health.js +19 -0
  64. package/dist/schema/credential-health.js.map +1 -0
  65. package/dist/schema/device-identities.d.ts +120 -0
  66. package/dist/schema/device-identities.d.ts.map +1 -0
  67. package/dist/schema/device-identities.js +14 -0
  68. package/dist/schema/device-identities.js.map +1 -0
  69. package/dist/schema/files.d.ts +175 -0
  70. package/dist/schema/files.d.ts.map +1 -0
  71. package/dist/schema/files.js +16 -0
  72. package/dist/schema/files.js.map +1 -0
  73. package/dist/schema/flows.d.ts +156 -0
  74. package/dist/schema/flows.d.ts.map +1 -0
  75. package/dist/schema/flows.js +12 -0
  76. package/dist/schema/flows.js.map +1 -0
  77. package/dist/schema/gateway-heartbeats.d.ts +186 -0
  78. package/dist/schema/gateway-heartbeats.d.ts.map +1 -0
  79. package/dist/schema/gateway-heartbeats.js +23 -0
  80. package/dist/schema/gateway-heartbeats.js.map +1 -0
  81. package/dist/schema/index.d.ts +37 -0
  82. package/dist/schema/index.d.ts.map +1 -0
  83. package/dist/schema/index.js +38 -0
  84. package/dist/schema/index.js.map +1 -0
  85. package/dist/schema/marketplace-agents.d.ts +397 -0
  86. package/dist/schema/marketplace-agents.d.ts.map +1 -0
  87. package/dist/schema/marketplace-agents.js +25 -0
  88. package/dist/schema/marketplace-agents.js.map +1 -0
  89. package/dist/schema/marketplace-installs.d.ts +101 -0
  90. package/dist/schema/marketplace-installs.d.ts.map +1 -0
  91. package/dist/schema/marketplace-installs.js +21 -0
  92. package/dist/schema/marketplace-installs.js.map +1 -0
  93. package/dist/schema/missions.d.ts +194 -0
  94. package/dist/schema/missions.d.ts.map +1 -0
  95. package/dist/schema/missions.js +29 -0
  96. package/dist/schema/missions.js.map +1 -0
  97. package/dist/schema/personal-agents.d.ts +302 -0
  98. package/dist/schema/personal-agents.d.ts.map +1 -0
  99. package/dist/schema/personal-agents.js +37 -0
  100. package/dist/schema/personal-agents.js.map +1 -0
  101. package/dist/schema/reliability-events.d.ts +211 -0
  102. package/dist/schema/reliability-events.d.ts.map +1 -0
  103. package/dist/schema/reliability-events.js +28 -0
  104. package/dist/schema/reliability-events.js.map +1 -0
  105. package/dist/schema/server-backups.d.ts +154 -0
  106. package/dist/schema/server-backups.d.ts.map +1 -0
  107. package/dist/schema/server-backups.js +23 -0
  108. package/dist/schema/server-backups.js.map +1 -0
  109. package/dist/schema/server-provision-configs.d.ts +410 -0
  110. package/dist/schema/server-provision-configs.d.ts.map +1 -0
  111. package/dist/schema/server-provision-configs.js +43 -0
  112. package/dist/schema/server-provision-configs.js.map +1 -0
  113. package/dist/schema/servers.d.ts +192 -0
  114. package/dist/schema/servers.d.ts.map +1 -0
  115. package/dist/schema/servers.js +22 -0
  116. package/dist/schema/servers.js.map +1 -0
  117. package/dist/schema/session-tasks.d.ts +211 -0
  118. package/dist/schema/session-tasks.d.ts.map +1 -0
  119. package/dist/schema/session-tasks.js +26 -0
  120. package/dist/schema/session-tasks.js.map +1 -0
  121. package/dist/schema/sessions.d.ts +209 -0
  122. package/dist/schema/sessions.d.ts.map +1 -0
  123. package/dist/schema/sessions.js +27 -0
  124. package/dist/schema/sessions.js.map +1 -0
  125. package/dist/schema/settings.d.ts +118 -0
  126. package/dist/schema/settings.d.ts.map +1 -0
  127. package/dist/schema/settings.js +19 -0
  128. package/dist/schema/settings.js.map +1 -0
  129. package/dist/schema/skill-execution-stats.d.ts +209 -0
  130. package/dist/schema/skill-execution-stats.d.ts.map +1 -0
  131. package/dist/schema/skill-execution-stats.js +24 -0
  132. package/dist/schema/skill-execution-stats.js.map +1 -0
  133. package/dist/schema/skills.d.ts +209 -0
  134. package/dist/schema/skills.d.ts.map +1 -0
  135. package/dist/schema/skills.js +24 -0
  136. package/dist/schema/skills.js.map +1 -0
  137. package/dist/schema/tasks.d.ts +192 -0
  138. package/dist/schema/tasks.d.ts.map +1 -0
  139. package/dist/schema/tasks.js +22 -0
  140. package/dist/schema/tasks.js.map +1 -0
  141. package/dist/schema/unified-events.d.ts +247 -0
  142. package/dist/schema/unified-events.d.ts.map +1 -0
  143. package/dist/schema/unified-events.js +29 -0
  144. package/dist/schema/unified-events.js.map +1 -0
  145. package/dist/schema/user-agents.d.ts +82 -0
  146. package/dist/schema/user-agents.d.ts.map +1 -0
  147. package/dist/schema/user-agents.js +17 -0
  148. package/dist/schema/user-agents.js.map +1 -0
  149. package/dist/schema/user-preferences.d.ts +99 -0
  150. package/dist/schema/user-preferences.d.ts.map +1 -0
  151. package/dist/schema/user-preferences.js +15 -0
  152. package/dist/schema/user-preferences.js.map +1 -0
  153. package/dist/schema/user-servers.d.ts +63 -0
  154. package/dist/schema/user-servers.d.ts.map +1 -0
  155. package/dist/schema/user-servers.js +16 -0
  156. package/dist/schema/user-servers.js.map +1 -0
  157. package/dist/schema/workshop-saves.d.ts +156 -0
  158. package/dist/schema/workshop-saves.d.ts.map +1 -0
  159. package/dist/schema/workshop-saves.js +12 -0
  160. package/dist/schema/workshop-saves.js.map +1 -0
  161. package/dist/utils.d.ts +3 -0
  162. package/dist/utils.d.ts.map +1 -0
  163. package/dist/utils.js +9 -0
  164. package/dist/utils.js.map +1 -0
  165. package/package.json +58 -0
  166. package/src/index.ts +7 -0
  167. package/src/relations.ts +258 -0
  168. package/src/schema/activity-bins.ts +23 -0
  169. package/src/schema/agent-groups.ts +31 -0
  170. package/src/schema/agents.ts +24 -0
  171. package/src/schema/auth/index.ts +190 -0
  172. package/src/schema/backup-configs.ts +22 -0
  173. package/src/schema/bugs.ts +30 -0
  174. package/src/schema/builder.ts +151 -0
  175. package/src/schema/channel-assignments.ts +23 -0
  176. package/src/schema/channel-identities.ts +25 -0
  177. package/src/schema/channels.ts +30 -0
  178. package/src/schema/chat-messages.ts +27 -0
  179. package/src/schema/config-snapshots.ts +20 -0
  180. package/src/schema/connection-events.ts +26 -0
  181. package/src/schema/credential-health.ts +23 -0
  182. package/src/schema/device-identities.ts +14 -0
  183. package/src/schema/files.ts +20 -0
  184. package/src/schema/flows.ts +12 -0
  185. package/src/schema/gateway-heartbeats.ts +27 -0
  186. package/src/schema/index.ts +59 -0
  187. package/src/schema/marketplace-agents.ts +25 -0
  188. package/src/schema/marketplace-installs.ts +25 -0
  189. package/src/schema/missions.ts +33 -0
  190. package/src/schema/personal-agents.ts +41 -0
  191. package/src/schema/reliability-events.ts +32 -0
  192. package/src/schema/server-backups.ts +27 -0
  193. package/src/schema/server-provision-configs.ts +57 -0
  194. package/src/schema/servers.ts +26 -0
  195. package/src/schema/session-tasks.ts +30 -0
  196. package/src/schema/sessions.ts +31 -0
  197. package/src/schema/settings.ts +23 -0
  198. package/src/schema/skill-execution-stats.ts +28 -0
  199. package/src/schema/skills.ts +28 -0
  200. package/src/schema/tasks.ts +26 -0
  201. package/src/schema/unified-events.ts +33 -0
  202. package/src/schema/user-agents.ts +21 -0
  203. package/src/schema/user-preferences.ts +19 -0
  204. package/src/schema/user-servers.ts +20 -0
  205. package/src/schema/workshop-saves.ts +12 -0
  206. package/src/utils.ts +11 -0
@@ -0,0 +1,156 @@
1
+ export declare const workshopSaves: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "workshop_saves";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: "id";
7
+ tableName: "workshop_saves";
8
+ dataType: "string";
9
+ columnType: "SQLiteText";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: false;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}, {
22
+ length: number | undefined;
23
+ }>;
24
+ name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
25
+ name: "name";
26
+ tableName: "workshop_saves";
27
+ dataType: "string";
28
+ columnType: "SQLiteText";
29
+ data: string;
30
+ driverParam: string;
31
+ notNull: true;
32
+ hasDefault: false;
33
+ isPrimaryKey: false;
34
+ isAutoincrement: false;
35
+ hasRuntimeDefault: false;
36
+ enumValues: [string, ...string[]];
37
+ baseColumn: never;
38
+ identity: undefined;
39
+ generated: undefined;
40
+ }, {}, {
41
+ length: number | undefined;
42
+ }>;
43
+ state: import("drizzle-orm/sqlite-core").SQLiteColumn<{
44
+ name: "state";
45
+ tableName: "workshop_saves";
46
+ dataType: "string";
47
+ columnType: "SQLiteText";
48
+ data: string;
49
+ driverParam: string;
50
+ notNull: true;
51
+ hasDefault: false;
52
+ isPrimaryKey: false;
53
+ isAutoincrement: false;
54
+ hasRuntimeDefault: false;
55
+ enumValues: [string, ...string[]];
56
+ baseColumn: never;
57
+ identity: undefined;
58
+ generated: undefined;
59
+ }, {}, {
60
+ length: number | undefined;
61
+ }>;
62
+ thumbnail: import("drizzle-orm/sqlite-core").SQLiteColumn<{
63
+ name: "thumbnail";
64
+ tableName: "workshop_saves";
65
+ dataType: "string";
66
+ columnType: "SQLiteText";
67
+ data: string;
68
+ driverParam: string;
69
+ notNull: false;
70
+ hasDefault: false;
71
+ isPrimaryKey: false;
72
+ isAutoincrement: false;
73
+ hasRuntimeDefault: false;
74
+ enumValues: [string, ...string[]];
75
+ baseColumn: never;
76
+ identity: undefined;
77
+ generated: undefined;
78
+ }, {}, {
79
+ length: number | undefined;
80
+ }>;
81
+ userId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
82
+ name: "user_id";
83
+ tableName: "workshop_saves";
84
+ dataType: "string";
85
+ columnType: "SQLiteText";
86
+ data: string;
87
+ driverParam: string;
88
+ notNull: false;
89
+ hasDefault: false;
90
+ isPrimaryKey: false;
91
+ isAutoincrement: false;
92
+ hasRuntimeDefault: false;
93
+ enumValues: [string, ...string[]];
94
+ baseColumn: never;
95
+ identity: undefined;
96
+ generated: undefined;
97
+ }, {}, {
98
+ length: number | undefined;
99
+ }>;
100
+ tenantId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
101
+ name: "tenant_id";
102
+ tableName: "workshop_saves";
103
+ dataType: "string";
104
+ columnType: "SQLiteText";
105
+ data: string;
106
+ driverParam: string;
107
+ notNull: false;
108
+ hasDefault: false;
109
+ isPrimaryKey: false;
110
+ isAutoincrement: false;
111
+ hasRuntimeDefault: false;
112
+ enumValues: [string, ...string[]];
113
+ baseColumn: never;
114
+ identity: undefined;
115
+ generated: undefined;
116
+ }, {}, {
117
+ length: number | undefined;
118
+ }>;
119
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
120
+ name: "created_at";
121
+ tableName: "workshop_saves";
122
+ dataType: "number";
123
+ columnType: "SQLiteInteger";
124
+ data: number;
125
+ driverParam: number;
126
+ notNull: true;
127
+ hasDefault: false;
128
+ isPrimaryKey: false;
129
+ isAutoincrement: false;
130
+ hasRuntimeDefault: false;
131
+ enumValues: undefined;
132
+ baseColumn: never;
133
+ identity: undefined;
134
+ generated: undefined;
135
+ }, {}, {}>;
136
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
137
+ name: "updated_at";
138
+ tableName: "workshop_saves";
139
+ dataType: "number";
140
+ columnType: "SQLiteInteger";
141
+ data: number;
142
+ driverParam: number;
143
+ notNull: true;
144
+ hasDefault: false;
145
+ isPrimaryKey: false;
146
+ isAutoincrement: false;
147
+ hasRuntimeDefault: false;
148
+ enumValues: undefined;
149
+ baseColumn: never;
150
+ identity: undefined;
151
+ generated: undefined;
152
+ }, {}, {}>;
153
+ };
154
+ dialect: "sqlite";
155
+ }>;
156
+ //# sourceMappingURL=workshop-saves.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workshop-saves.d.ts","sourceRoot":"","sources":["../../src/schema/workshop-saves.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASxB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
2
+ export const workshopSaves = sqliteTable('workshop_saves', {
3
+ id: text('id').primaryKey(),
4
+ name: text('name').notNull(),
5
+ state: text('state').notNull(), // JSON string of WorkshopState
6
+ thumbnail: text('thumbnail'), // base64 PNG data-URI, nullable
7
+ userId: text('user_id'), // owner — null for pre-migration rows (treated as shared)
8
+ tenantId: text('tenant_id'), // tenant scope — null for pre-migration rows
9
+ createdAt: integer('created_at').notNull(),
10
+ updatedAt: integer('updated_at').notNull(),
11
+ });
12
+ //# sourceMappingURL=workshop-saves.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workshop-saves.js","sourceRoot":"","sources":["../../src/schema/workshop-saves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAErE,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,gBAAgB,EAAE;IACzD,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,+BAA+B;IAC/D,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,gCAAgC;IAC9D,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,0DAA0D;IACnF,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,6CAA6C;IAC1E,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAC1C,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CAC3C,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function newId(): string;
2
+ export declare function nowMs(): number;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED,wBAAgB,KAAK,IAAI,MAAM,CAE9B"}
package/dist/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ import { init } from '@paralleldrive/cuid2';
2
+ const createId = init({ length: 24 });
3
+ export function newId() {
4
+ return createId();
5
+ }
6
+ export function nowMs() {
7
+ return Date.now();
8
+ }
9
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAEtC,MAAM,UAAU,KAAK;IACnB,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;AACpB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@minion-stack/db",
3
+ "version": "0.2.0",
4
+ "description": "Drizzle ORM schema for the Minion shared database (LibSQL/Turso).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/NikolasP98/minion-meta.git",
9
+ "directory": "packages/db"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./schema": {
20
+ "types": "./dist/schema/index.d.ts",
21
+ "import": "./dist/schema/index.js"
22
+ },
23
+ "./auth": {
24
+ "types": "./dist/schema/auth/index.d.ts",
25
+ "import": "./dist/schema/auth/index.js"
26
+ },
27
+ "./relations": {
28
+ "types": "./dist/relations.d.ts",
29
+ "import": "./dist/relations.js"
30
+ },
31
+ "./utils": {
32
+ "types": "./dist/utils.d.ts",
33
+ "import": "./dist/utils.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "src",
42
+ "README.md"
43
+ ],
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "prepublishOnly": "tsc"
47
+ },
48
+ "peerDependencies": {
49
+ "drizzle-orm": ">=0.45.0"
50
+ },
51
+ "devDependencies": {
52
+ "@minion-stack/tsconfig": "workspace:*",
53
+ "@paralleldrive/cuid2": "^3.3.0",
54
+ "drizzle-orm": "^0.45.1",
55
+ "drizzle-kit": "^0.31.9",
56
+ "typescript": "^5.0.0"
57
+ }
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ // @minion-stack/db — main entry point
2
+ // Schema tables (all 56 table constants)
3
+ export * from './schema/index.js';
4
+ // Drizzle relational query definitions
5
+ export * from './relations.js';
6
+ // Utilities: newId(), nowMs()
7
+ export * from './utils.js';
@@ -0,0 +1,258 @@
1
+ import { relations } from 'drizzle-orm';
2
+ import {
3
+ user,
4
+ session,
5
+ account,
6
+ member,
7
+ organization,
8
+ invitation,
9
+ servers,
10
+ agents,
11
+ skills,
12
+ sessions,
13
+ chatMessages,
14
+ bugs,
15
+ connectionEvents,
16
+ settings,
17
+ files,
18
+ missions,
19
+ tasks,
20
+ sessionTasks,
21
+ userServers,
22
+ userAgents,
23
+ backupConfigs,
24
+ serverBackups,
25
+ agentGroups,
26
+ agentGroupMembers,
27
+ channelIdentities,
28
+ personalAgents,
29
+ userPreferences,
30
+ } from './schema/index.js';
31
+
32
+ // ── Better Auth: User ─────────────────────────────────────────────────────────
33
+
34
+ export const userRelations = relations(user, ({ one, many }) => ({
35
+ sessions: many(session),
36
+ accounts: many(account),
37
+ memberships: many(member),
38
+ invitations: many(invitation),
39
+ files: many(files),
40
+ userServers: many(userServers),
41
+ userAgents: many(userAgents),
42
+ channelIdentities: many(channelIdentities),
43
+ personalAgent: one(personalAgents, { fields: [user.id], references: [personalAgents.userId] }),
44
+ preferences: many(userPreferences),
45
+ }));
46
+
47
+ // ── Better Auth: Session ──────────────────────────────────────────────────────
48
+
49
+ export const sessionRelations = relations(session, ({ one }) => ({
50
+ user: one(user, { fields: [session.userId], references: [user.id] }),
51
+ }));
52
+
53
+ // ── Better Auth: Account ──────────────────────────────────────────────────────
54
+
55
+ export const accountRelations = relations(account, ({ one }) => ({
56
+ user: one(user, { fields: [account.userId], references: [user.id] }),
57
+ }));
58
+
59
+ // ── Better Auth: Organization ─────────────────────────────────────────────────
60
+
61
+ export const organizationRelations = relations(organization, ({ many }) => ({
62
+ members: many(member),
63
+ invitations: many(invitation),
64
+ servers: many(servers),
65
+ files: many(files),
66
+ }));
67
+
68
+ // ── Better Auth: Member ───────────────────────────────────────────────────────
69
+
70
+ export const memberRelations = relations(member, ({ one }) => ({
71
+ user: one(user, { fields: [member.userId], references: [user.id] }),
72
+ organization: one(organization, {
73
+ fields: [member.organizationId],
74
+ references: [organization.id],
75
+ }),
76
+ }));
77
+
78
+ // ── Better Auth: Invitation ───────────────────────────────────────────────────
79
+
80
+ export const invitationRelations = relations(invitation, ({ one }) => ({
81
+ organization: one(organization, {
82
+ fields: [invitation.organizationId],
83
+ references: [organization.id],
84
+ }),
85
+ inviter: one(user, { fields: [invitation.inviterId], references: [user.id] }),
86
+ }));
87
+
88
+ // ── Servers ──────────────────────────────────────────────────────────────────
89
+
90
+ export const serversRelations = relations(servers, ({ one, many }) => ({
91
+ organization: one(organization, { fields: [servers.tenantId], references: [organization.id] }),
92
+ agents: many(agents),
93
+ skills: many(skills),
94
+ sessions: many(sessions),
95
+ chatMessages: many(chatMessages),
96
+ bugs: many(bugs),
97
+ connectionEvents: many(connectionEvents),
98
+ settings: many(settings),
99
+ userServers: many(userServers),
100
+ userAgents: many(userAgents),
101
+ serverBackups: many(serverBackups),
102
+ agentGroups: many(agentGroups),
103
+ }));
104
+
105
+ // ── Agents ───────────────────────────────────────────────────────────────────
106
+
107
+ export const agentsRelations = relations(agents, ({ one }) => ({
108
+ server: one(servers, { fields: [agents.serverId], references: [servers.id] }),
109
+ organization: one(organization, { fields: [agents.tenantId], references: [organization.id] }),
110
+ }));
111
+
112
+ // ── Skills ───────────────────────────────────────────────────────────────────
113
+
114
+ export const skillsRelations = relations(skills, ({ one }) => ({
115
+ server: one(servers, { fields: [skills.serverId], references: [servers.id] }),
116
+ organization: one(organization, { fields: [skills.tenantId], references: [organization.id] }),
117
+ }));
118
+
119
+ // ── Sessions (gateway sessions, not auth sessions) ────────────────────────────
120
+
121
+ export const sessionsRelations = relations(sessions, ({ one, many }) => ({
122
+ server: one(servers, { fields: [sessions.serverId], references: [servers.id] }),
123
+ organization: one(organization, { fields: [sessions.tenantId], references: [organization.id] }),
124
+ missions: many(missions),
125
+ }));
126
+
127
+ // ── Chat Messages ────────────────────────────────────────────────────────────
128
+
129
+ export const chatMessagesRelations = relations(chatMessages, ({ one }) => ({
130
+ server: one(servers, { fields: [chatMessages.serverId], references: [servers.id] }),
131
+ organization: one(organization, {
132
+ fields: [chatMessages.tenantId],
133
+ references: [organization.id],
134
+ }),
135
+ }));
136
+
137
+ // ── Bugs ─────────────────────────────────────────────────────────────────────
138
+
139
+ export const bugsRelations = relations(bugs, ({ one }) => ({
140
+ server: one(servers, { fields: [bugs.serverId], references: [servers.id] }),
141
+ organization: one(organization, { fields: [bugs.tenantId], references: [organization.id] }),
142
+ }));
143
+
144
+ // ── Connection Events ────────────────────────────────────────────────────────
145
+
146
+ export const connectionEventsRelations = relations(connectionEvents, ({ one }) => ({
147
+ server: one(servers, { fields: [connectionEvents.serverId], references: [servers.id] }),
148
+ organization: one(organization, {
149
+ fields: [connectionEvents.tenantId],
150
+ references: [organization.id],
151
+ }),
152
+ }));
153
+
154
+ // ── Settings ─────────────────────────────────────────────────────────────────
155
+
156
+ export const settingsRelations = relations(settings, ({ one }) => ({
157
+ server: one(servers, { fields: [settings.serverId], references: [servers.id] }),
158
+ organization: one(organization, { fields: [settings.tenantId], references: [organization.id] }),
159
+ }));
160
+
161
+ // ── Files ────────────────────────────────────────────────────────────────────
162
+
163
+ export const filesRelations = relations(files, ({ one }) => ({
164
+ organization: one(organization, { fields: [files.tenantId], references: [organization.id] }),
165
+ uploadedByUser: one(user, { fields: [files.uploadedBy], references: [user.id] }),
166
+ }));
167
+
168
+ // ── Missions ──────────────────────────────────────────────────────────────────
169
+
170
+ export const missionsRelations = relations(missions, ({ one, many }) => ({
171
+ organization: one(organization, { fields: [missions.tenantId], references: [organization.id] }),
172
+ server: one(servers, { fields: [missions.serverId], references: [servers.id] }),
173
+ session: one(sessions, { fields: [missions.sessionId], references: [sessions.id] }),
174
+ tasks: many(tasks),
175
+ }));
176
+
177
+ // ── Tasks ─────────────────────────────────────────────────────────────────────
178
+
179
+ export const tasksRelations = relations(tasks, ({ one }) => ({
180
+ organization: one(organization, { fields: [tasks.tenantId], references: [organization.id] }),
181
+ mission: one(missions, { fields: [tasks.missionId], references: [missions.id] }),
182
+ }));
183
+
184
+ // ── Session Tasks ────────────────────────────────────────────────────────
185
+
186
+ export const sessionTasksRelations = relations(sessionTasks, ({ one }) => ({
187
+ organization: one(organization, {
188
+ fields: [sessionTasks.tenantId],
189
+ references: [organization.id],
190
+ }),
191
+ server: one(servers, { fields: [sessionTasks.serverId], references: [servers.id] }),
192
+ }));
193
+
194
+ // ── User Servers ─────────────────────────────────────────────────────────
195
+
196
+ export const userServersRelations = relations(userServers, ({ one }) => ({
197
+ user: one(user, { fields: [userServers.userId], references: [user.id] }),
198
+ server: one(servers, { fields: [userServers.serverId], references: [servers.id] }),
199
+ }));
200
+
201
+ // ── User Agents ──────────────────────────────────────────────────────────
202
+
203
+ export const userAgentsRelations = relations(userAgents, ({ one }) => ({
204
+ user: one(user, { fields: [userAgents.userId], references: [user.id] }),
205
+ server: one(servers, { fields: [userAgents.serverId], references: [servers.id] }),
206
+ }));
207
+
208
+ // ── Backup Configs ──────────────────────────────────────────────────────
209
+
210
+ export const backupConfigsRelations = relations(backupConfigs, ({ one }) => ({
211
+ organization: one(organization, {
212
+ fields: [backupConfigs.tenantId],
213
+ references: [organization.id],
214
+ }),
215
+ }));
216
+
217
+ // ── Server Backups ──────────────────────────────────────────────────────
218
+
219
+ export const serverBackupsRelations = relations(serverBackups, ({ one }) => ({
220
+ server: one(servers, { fields: [serverBackups.serverId], references: [servers.id] }),
221
+ organization: one(organization, {
222
+ fields: [serverBackups.tenantId],
223
+ references: [organization.id],
224
+ }),
225
+ }));
226
+
227
+ // ── Agent Groups ─────────────────────────────────────────────────────
228
+
229
+ export const agentGroupsRelations = relations(agentGroups, ({ one, many }) => ({
230
+ organization: one(organization, {
231
+ fields: [agentGroups.tenantId],
232
+ references: [organization.id],
233
+ }),
234
+ members: many(agentGroupMembers),
235
+ }));
236
+
237
+ export const agentGroupMembersRelations = relations(agentGroupMembers, ({ one }) => ({
238
+ group: one(agentGroups, { fields: [agentGroupMembers.groupId], references: [agentGroups.id] }),
239
+ }));
240
+
241
+ // ── Channel Identities ──────────────────────────────────────────────────
242
+
243
+ export const channelIdentitiesRelations = relations(channelIdentities, ({ one }) => ({
244
+ user: one(user, { fields: [channelIdentities.userId], references: [user.id] }),
245
+ }));
246
+
247
+ // ── Personal Agents ──────────────────────────────────────────────────────
248
+
249
+ export const personalAgentsRelations = relations(personalAgents, ({ one }) => ({
250
+ user: one(user, { fields: [personalAgents.userId], references: [user.id] }),
251
+ server: one(servers, { fields: [personalAgents.serverId], references: [servers.id] }),
252
+ }));
253
+
254
+ // ── User Preferences ────────────────────────────────────────────────────
255
+
256
+ export const userPreferencesRelations = relations(userPreferences, ({ one }) => ({
257
+ user: one(user, { fields: [userPreferences.userId], references: [user.id] }),
258
+ }));
@@ -0,0 +1,23 @@
1
+ import { sqliteTable, text, integer, index, uniqueIndex } from 'drizzle-orm/sqlite-core';
2
+ import { organization } from './auth/index.js';
3
+ import { servers } from './servers.js';
4
+
5
+ export const activityBins = sqliteTable(
6
+ 'agent_activity_bins',
7
+ {
8
+ id: text('id').primaryKey(),
9
+ tenantId: text('tenant_id')
10
+ .notNull()
11
+ .references(() => organization.id, { onDelete: 'cascade' }),
12
+ serverId: text('server_id')
13
+ .notNull()
14
+ .references(() => servers.id, { onDelete: 'cascade' }),
15
+ agentId: text('agent_id').notNull(),
16
+ binTs: integer('bin_ts').notNull(),
17
+ count: integer('count').notNull().default(0),
18
+ },
19
+ (t) => [
20
+ uniqueIndex('idx_activity_bins_unique').on(t.serverId, t.agentId, t.binTs),
21
+ index('idx_activity_bins_lookup').on(t.serverId, t.agentId, t.binTs),
22
+ ],
23
+ );
@@ -0,0 +1,31 @@
1
+ import { sqliteTable, text, integer, index, primaryKey } from 'drizzle-orm/sqlite-core';
2
+ import { organization, user } from './auth/index.js';
3
+
4
+ export const agentGroups = sqliteTable(
5
+ 'agent_groups',
6
+ {
7
+ id: text('id').primaryKey(),
8
+ userId: text('user_id')
9
+ .notNull()
10
+ .references(() => user.id, { onDelete: 'cascade' }),
11
+ tenantId: text('tenant_id')
12
+ .notNull()
13
+ .references(() => organization.id, { onDelete: 'cascade' }),
14
+ name: text('name').notNull(),
15
+ sortOrder: integer('sort_order').default(0),
16
+ createdAt: integer('created_at').notNull(),
17
+ },
18
+ (t) => [index('idx_agent_groups_user').on(t.userId, t.tenantId)],
19
+ );
20
+
21
+ export const agentGroupMembers = sqliteTable(
22
+ 'agent_group_members',
23
+ {
24
+ groupId: text('group_id')
25
+ .notNull()
26
+ .references(() => agentGroups.id, { onDelete: 'cascade' }),
27
+ agentId: text('agent_id').notNull(),
28
+ sortOrder: integer('sort_order').default(0),
29
+ },
30
+ (t) => [primaryKey({ columns: [t.groupId, t.agentId] })],
31
+ );
@@ -0,0 +1,24 @@
1
+ import { sqliteTable, text, integer, index, primaryKey } from 'drizzle-orm/sqlite-core';
2
+ import { organization } from './auth/index.js';
3
+ import { servers } from './servers.js';
4
+
5
+ export const agents = sqliteTable(
6
+ 'agents',
7
+ {
8
+ id: text('id').notNull(),
9
+ serverId: text('server_id')
10
+ .notNull()
11
+ .references(() => servers.id, { onDelete: 'cascade' }),
12
+ tenantId: text('tenant_id')
13
+ .notNull()
14
+ .references(() => organization.id, { onDelete: 'cascade' }),
15
+ name: text('name'),
16
+ emoji: text('emoji'),
17
+ description: text('description'),
18
+ model: text('model'),
19
+ status: text('status', { enum: ['active', 'inactive'] }).default('active'),
20
+ rawJson: text('raw_json').notNull(),
21
+ lastSeenAt: integer('last_seen_at').notNull(),
22
+ },
23
+ (t) => [primaryKey({ columns: [t.id, t.serverId] }), index('idx_agents_tenant').on(t.tenantId)],
24
+ );