@intx/db 0.1.2
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.
- package/README.md +37 -0
- package/drizzle.config.ts +23 -0
- package/migrations/.gitkeep +0 -0
- package/migrations/0000_brown_wither.sql +50 -0
- package/migrations/0001_white_aqueduct.sql +105 -0
- package/migrations/0002_clever_falcon.sql +56 -0
- package/migrations/0003_stiff_tyrannus.sql +44 -0
- package/migrations/0004_rename_capability_to_offering.sql +1 -0
- package/migrations/0005_gigantic_cardiac.sql +1 -0
- package/migrations/0006_sidecar.sql +8 -0
- package/migrations/0007_agent_running_session.sql +1 -0
- package/migrations/0008_session.sql +10 -0
- package/migrations/0009_session_messages.sql +18 -0
- package/migrations/0010_agent_sidecar_pubkey.sql +2 -0
- package/migrations/0011_session_message_from.sql +2 -0
- package/migrations/0012_agent_instance.sql +22 -0
- package/migrations/0013_instance_session_id.sql +2 -0
- package/migrations/0014_drop_agent_runtime_columns.sql +12 -0
- package/migrations/0015_add_instance_id_to_session_message.sql +2 -0
- package/migrations/0016_jazzy_gamma_corps.sql +3 -0
- package/migrations/0017_hesitant_marvex.sql +1 -0
- package/migrations/0018_natural_sinister_six.sql +5 -0
- package/migrations/0019_rename_grant_source_to_origin.sql +1 -0
- package/migrations/0020_add_agent_role.sql +9 -0
- package/migrations/0021_acoustic_ozymandias.sql +15 -0
- package/migrations/0022_material_sleepwalker.sql +27 -0
- package/migrations/0023_flawless_scarlet_witch.sql +2 -0
- package/migrations/0024_bumpy_sharon_ventura.sql +1 -0
- package/migrations/0025_curvy_firestar.sql +26 -0
- package/migrations/0026_keen_ultimo.sql +13 -0
- package/migrations/0027_git_tokens.sql +21 -0
- package/migrations/0028_wet_sugar_man.sql +1 -0
- package/migrations/meta/0000_snapshot.json +316 -0
- package/migrations/meta/0001_snapshot.json +968 -0
- package/migrations/meta/0002_snapshot.json +1315 -0
- package/migrations/meta/0003_snapshot.json +1594 -0
- package/migrations/meta/0004_snapshot.json +1594 -0
- package/migrations/meta/0005_snapshot.json +1600 -0
- package/migrations/meta/0011_snapshot.json +1921 -0
- package/migrations/meta/0012_snapshot.json +2067 -0
- package/migrations/meta/0013_snapshot.json +2082 -0
- package/migrations/meta/0014_snapshot.json +2049 -0
- package/migrations/meta/0015_snapshot.json +2064 -0
- package/migrations/meta/0016_snapshot.json +2085 -0
- package/migrations/meta/0017_snapshot.json +2085 -0
- package/migrations/meta/0018_snapshot.json +2070 -0
- package/migrations/meta/0019_snapshot.json +2070 -0
- package/migrations/meta/0020_snapshot.json +2126 -0
- package/migrations/meta/0021_snapshot.json +2239 -0
- package/migrations/meta/0022_snapshot.json +2425 -0
- package/migrations/meta/0023_snapshot.json +2260 -0
- package/migrations/meta/0024_snapshot.json +2254 -0
- package/migrations/meta/0025_snapshot.json +2418 -0
- package/migrations/meta/0026_snapshot.json +2508 -0
- package/migrations/meta/0027_snapshot.json +2657 -0
- package/migrations/meta/0028_snapshot.json +2657 -0
- package/migrations/meta/_journal.json +209 -0
- package/package.json +27 -0
- package/src/client.ts +24 -0
- package/src/config.ts +19 -0
- package/src/connection.ts +27 -0
- package/src/credential-resolution.ts +378 -0
- package/src/grant-store.ts +51 -0
- package/src/index.ts +32 -0
- package/src/migrate.test.ts +35 -0
- package/src/migrate.ts +168 -0
- package/src/parse-row.test.ts +113 -0
- package/src/parse-row.ts +185 -0
- package/src/schema/agent-assets.ts +21 -0
- package/src/schema/agents.ts +49 -0
- package/src/schema/assets.ts +24 -0
- package/src/schema/auth.ts +51 -0
- package/src/schema/credentials.ts +43 -0
- package/src/schema/git-tokens.ts +83 -0
- package/src/schema/grants.ts +26 -0
- package/src/schema/index.ts +19 -0
- package/src/schema/instances.ts +36 -0
- package/src/schema/messages.ts +108 -0
- package/src/schema/oauth-clients.ts +26 -0
- package/src/schema/offerings.ts +20 -0
- package/src/schema/principals.ts +28 -0
- package/src/schema/providers.ts +23 -0
- package/src/schema/roles.ts +51 -0
- package/src/schema/session-assets.ts +49 -0
- package/src/schema/sessions.ts +26 -0
- package/src/schema/sidecar.ts +14 -0
- package/src/schema/tenants.ts +41 -0
- package/src/schema/wallets.ts +44 -0
- package/src/tenant-hierarchy.ts +34 -0
- package/tsconfig.json +4 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
+
|
|
3
|
+
import { agent } from "./agents";
|
|
4
|
+
import { tenant } from "./tenants";
|
|
5
|
+
|
|
6
|
+
export const wallet = pgTable("wallet", {
|
|
7
|
+
id: text("id").primaryKey(),
|
|
8
|
+
tenantId: text("tenant_id")
|
|
9
|
+
.notNull()
|
|
10
|
+
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
11
|
+
name: text("name").notNull(),
|
|
12
|
+
backendType: text("backend_type", {
|
|
13
|
+
enum: ["crypto", "fiat", "credits"],
|
|
14
|
+
}).notNull(),
|
|
15
|
+
currency: text("currency").notNull(),
|
|
16
|
+
balance: text("balance").notNull().default("0"),
|
|
17
|
+
config: jsonb("config"),
|
|
18
|
+
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
19
|
+
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const transaction = pgTable("transaction", {
|
|
23
|
+
id: text("id").primaryKey(),
|
|
24
|
+
walletId: text("wallet_id")
|
|
25
|
+
.notNull()
|
|
26
|
+
.references(() => wallet.id, { onDelete: "cascade" }),
|
|
27
|
+
agentId: text("agent_id").references(() => agent.id, {
|
|
28
|
+
onDelete: "set null",
|
|
29
|
+
}),
|
|
30
|
+
direction: text("direction", {
|
|
31
|
+
enum: ["inbound", "outbound"],
|
|
32
|
+
}).notNull(),
|
|
33
|
+
amount: text("amount").notNull(),
|
|
34
|
+
currency: text("currency").notNull(),
|
|
35
|
+
recipientId: text("recipient_id"),
|
|
36
|
+
senderId: text("sender_id"),
|
|
37
|
+
requestId: text("request_id"),
|
|
38
|
+
status: text("status", {
|
|
39
|
+
enum: ["pending", "completed", "failed"],
|
|
40
|
+
})
|
|
41
|
+
.notNull()
|
|
42
|
+
.default("pending"),
|
|
43
|
+
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
44
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
|
|
3
|
+
import type { DB } from "./client";
|
|
4
|
+
import { tenant } from "./schema/tenants";
|
|
5
|
+
|
|
6
|
+
const MAX_DEPTH = 20;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Walks the tenant parentId chain from the given tenant up to the root.
|
|
10
|
+
* Returns an ordered array of tenant IDs: [tenantId, parentId, grandparentId, ...rootId].
|
|
11
|
+
*
|
|
12
|
+
* Protects against cycles with a depth limit.
|
|
13
|
+
*/
|
|
14
|
+
export async function getAncestorChain(
|
|
15
|
+
db: DB["db"],
|
|
16
|
+
tenantId: string,
|
|
17
|
+
): Promise<string[]> {
|
|
18
|
+
const chain: string[] = [tenantId];
|
|
19
|
+
let currentId = tenantId;
|
|
20
|
+
|
|
21
|
+
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
22
|
+
const row = await db.query.tenant.findFirst({
|
|
23
|
+
where: eq(tenant.id, currentId),
|
|
24
|
+
columns: { parentId: true },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!row?.parentId) break;
|
|
28
|
+
|
|
29
|
+
chain.push(row.parentId);
|
|
30
|
+
currentId = row.parentId;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return chain;
|
|
34
|
+
}
|
package/tsconfig.json
ADDED