@intx/db 0.1.2 → 0.3.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.
- package/LICENSE +176 -0
- package/README.md +23 -4
- package/dist/approval-store.d.ts +52 -0
- package/dist/approval-store.js +79 -0
- package/dist/asset-resolution.d.ts +52 -0
- package/dist/asset-resolution.js +66 -0
- package/dist/catalog-resolution.d.ts +76 -0
- package/dist/catalog-resolution.js +151 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +18 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +16 -0
- package/dist/connection.d.ts +3 -0
- package/dist/connection.js +26 -0
- package/dist/credential-resolution.d.ts +222 -0
- package/dist/credential-resolution.js +255 -0
- package/dist/grant-store.d.ts +3 -0
- package/dist/grant-store.js +59 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +20 -0
- package/dist/migrate.d.ts +36 -0
- package/dist/migrate.js +135 -0
- package/dist/model-source-resolution.d.ts +115 -0
- package/dist/model-source-resolution.js +291 -0
- package/dist/parse-row.d.ts +373 -0
- package/dist/parse-row.js +232 -0
- package/dist/pg-error.d.ts +3 -0
- package/dist/pg-error.js +19 -0
- package/dist/pricing.d.ts +15 -0
- package/dist/pricing.js +24 -0
- package/dist/rekey-credential-secrets.d.ts +13 -0
- package/dist/rekey-credential-secrets.js +61 -0
- package/dist/schema/approvals.d.ts +245 -0
- package/dist/schema/approvals.js +52 -0
- package/dist/schema/assets.d.ts +143 -0
- package/{src/schema/assets.ts → dist/schema/assets.js} +7 -16
- package/dist/schema/auth.d.ts +606 -0
- package/dist/schema/auth.js +47 -0
- package/dist/schema/catalog.d.ts +811 -0
- package/dist/schema/catalog.js +108 -0
- package/dist/schema/column-types.d.ts +26 -0
- package/dist/schema/column-types.js +15 -0
- package/dist/schema/credentials.d.ts +305 -0
- package/{src/schema/credentials.ts → dist/schema/credentials.js} +16 -22
- package/dist/schema/git-tokens.d.ts +256 -0
- package/{src/schema/git-tokens.ts → dist/schema/git-tokens.js} +16 -39
- package/dist/schema/grants.d.ts +211 -0
- package/dist/schema/grants.js +30 -0
- package/dist/schema/index.d.ts +25 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/messages.d.ts +414 -0
- package/dist/schema/messages.js +82 -0
- package/dist/schema/oauth-clients.d.ts +246 -0
- package/{src/schema/oauth-clients.ts → dist/schema/oauth-clients.js} +8 -14
- package/dist/schema/offerings.d.ts +160 -0
- package/dist/schema/offerings.js +24 -0
- package/dist/schema/principals.d.ts +128 -0
- package/dist/schema/principals.js +23 -0
- package/dist/schema/providers.d.ts +237 -0
- package/dist/schema/providers.js +22 -0
- package/dist/schema/roles.d.ts +242 -0
- package/dist/schema/roles.js +37 -0
- package/dist/schema/session-assets.d.ts +92 -0
- package/dist/schema/session-assets.js +45 -0
- package/dist/schema/sessions.d.ts +143 -0
- package/dist/schema/sessions.js +29 -0
- package/dist/schema/sidecar-allocation.d.ts +406 -0
- package/dist/schema/sidecar-allocation.js +57 -0
- package/dist/schema/sidecar.d.ts +145 -0
- package/dist/schema/sidecar.js +28 -0
- package/dist/schema/signal-correlations.d.ts +177 -0
- package/dist/schema/signal-correlations.js +31 -0
- package/dist/schema/tenants.d.ts +235 -0
- package/{src/schema/tenants.ts → dist/schema/tenants.js} +10 -27
- package/dist/schema/wallets.d.ts +354 -0
- package/dist/schema/wallets.js +43 -0
- package/dist/schema/workflow-definitions.d.ts +371 -0
- package/dist/schema/workflow-definitions.js +97 -0
- package/dist/schema/workflow-run-dispatch.d.ts +328 -0
- package/dist/schema/workflow-run-dispatch.js +56 -0
- package/dist/schema/workflow-run-execution.d.ts +126 -0
- package/dist/schema/workflow-run-execution.js +48 -0
- package/dist/schema/workflow-run-launch-spec.d.ts +200 -0
- package/dist/schema/workflow-run-launch-spec.js +26 -0
- package/dist/schema/workflow-run.d.ts +230 -0
- package/dist/schema/workflow-run.js +102 -0
- package/dist/sidecar-allocation-store.d.ts +171 -0
- package/dist/sidecar-allocation-store.js +512 -0
- package/dist/signal-correlation-store.d.ts +36 -0
- package/dist/signal-correlation-store.js +63 -0
- package/dist/tenant-hierarchy.d.ts +23 -0
- package/dist/tenant-hierarchy.js +60 -0
- package/dist/workflow-definition-store.d.ts +55 -0
- package/dist/workflow-definition-store.js +93 -0
- package/dist/workflow-run-dispatch-store.d.ts +80 -0
- package/dist/workflow-run-dispatch-store.js +298 -0
- package/dist/workflow-run-launch-spec-store.d.ts +13 -0
- package/dist/workflow-run-launch-spec-store.js +30 -0
- package/dist/workflow-run-store.d.ts +54 -0
- package/dist/workflow-run-store.js +85 -0
- package/migrations/0029_loose_warlock.sql +1 -0
- package/migrations/0030_session_asset_audit_split.sql +5 -0
- package/migrations/0031_gigantic_nicolaos.sql +68 -0
- package/migrations/0032_lethal_misty_knight.sql +1 -0
- package/migrations/0033_old_payback.sql +1 -0
- package/migrations/0034_sleepy_songbird.sql +11 -0
- package/migrations/0035_violet_giant_man.sql +3 -0
- package/migrations/0036_sharp_the_executioner.sql +2 -0
- package/migrations/0037_credential_use_backfill.sql +39 -0
- package/migrations/0038_chilly_blacklash.sql +37 -0
- package/migrations/0039_quick_carnage.sql +2 -0
- package/migrations/0040_reshape_approval_origin.sql +24 -0
- package/migrations/0041_make_approval_timeout_at_nullable.sql +1 -0
- package/migrations/0042_youthful_mantis.sql +2 -0
- package/migrations/0043_signal_correlation_deployment_fk.sql +1 -0
- package/migrations/0044_model_offering_quirks.sql +1 -0
- package/migrations/0045_create_workflow_run.sql +13 -0
- package/migrations/0046_approval_signal_correlation_run_fk.sql +2 -0
- package/migrations/0047_create_workflow_definition.sql +30 -0
- package/migrations/0048_workflow_definition_origin_agent_id.sql +2 -0
- package/migrations/0049_curly_omega_flight.sql +2 -0
- package/migrations/0050_late_crystal.sql +10 -0
- package/migrations/0051_funny_madelyne_pryor.sql +1 -0
- package/migrations/0052_drop_inference_turn_instance_fk.sql +1 -0
- package/migrations/0053_session_mail_session_id_index.sql +1 -0
- package/migrations/0054_rekey_instance_grants_to_workflow_run.sql +10 -0
- package/migrations/0055_backfill_anchor_workflow_runs.sql +69 -0
- package/migrations/0056_repoint_deployment_fks_to_anchor_run.sql +32 -0
- package/migrations/0057_drop_workflow_deployment_projection.sql +22 -0
- package/migrations/0058_repoint_offering_fk_to_definition.sql +41 -0
- package/migrations/0059_repoint_transaction_fk_to_run.sql +10 -0
- package/migrations/0060_drop_session_mail_instance_fk.sql +6 -0
- package/migrations/0061_drop_session_asset_instance_fk.sql +7 -0
- package/migrations/0062_drop_agent_asset_table.sql +11 -0
- package/migrations/0063_repoint_agent_role_fk_to_definition.sql +39 -0
- package/migrations/0064_repoint_agent_session_fk_to_definition.sql +47 -0
- package/migrations/0065_add_workflow_definition_model_requirements.sql +37 -0
- package/migrations/0066_rekey_agent_definition_principals_to_workflow.sql +27 -0
- package/migrations/0067_add_workflow_definition_kind.sql +10 -0
- package/migrations/0068_drop_agent_tables_and_origin_agent_id.sql +31 -0
- package/migrations/0069_drop_workflow_definition_kind.sql +10 -0
- package/migrations/0070_flashy_proteus.sql +13 -0
- package/migrations/0072_add_workflow_definition_credential_bindings.sql +1 -0
- package/migrations/0073_grant_target_exactly_one_check.sql +13 -0
- package/migrations/0074_add_provider_api_base_url.sql +1 -0
- package/migrations/0075_workflow_run_launch_spec.sql +17 -0
- package/migrations/0076_sidecar_allocation.sql +40 -0
- package/migrations/0077_workflow_run_dispatch.sql +29 -0
- package/migrations/0078_workflow_run_dispatch_kind.sql +2 -0
- package/migrations/0079_rename_workflow_run_deployment_id_to_anchor_run_id.sql +4 -0
- package/migrations/0080_rename_correlation_approval_deployment_id_to_anchor_run_id.sql +9 -0
- package/migrations/0081_workflow_definition_content_hash_and_approved_wire_hash.sql +4 -0
- package/migrations/0082_blue_black_queen.sql +1 -0
- package/migrations/0083_replace_launch_spec_snapshot_with_frozen_bundle.sql +3 -0
- package/migrations/0084_delete_orphaned_credential_grants.sql +22 -0
- package/migrations/meta/0029_snapshot.json +2664 -0
- package/migrations/meta/0030_snapshot.json +2670 -0
- package/migrations/meta/0031_snapshot.json +3100 -0
- package/migrations/meta/0032_snapshot.json +3106 -0
- package/migrations/meta/0033_snapshot.json +3112 -0
- package/migrations/meta/0034_snapshot.json +3198 -0
- package/migrations/meta/0035_snapshot.json +3225 -0
- package/migrations/meta/0036_snapshot.json +3237 -0
- package/migrations/meta/0037_snapshot.json +3237 -0
- package/migrations/meta/0038_snapshot.json +3470 -0
- package/migrations/meta/0039_snapshot.json +3470 -0
- package/migrations/meta/0040_snapshot.json +3489 -0
- package/migrations/meta/0041_snapshot.json +3489 -0
- package/migrations/meta/0042_snapshot.json +3489 -0
- package/migrations/meta/0043_snapshot.json +3498 -0
- package/migrations/meta/0044_snapshot.json +3504 -0
- package/migrations/meta/0045_snapshot.json +3589 -0
- package/migrations/meta/0046_snapshot.json +3607 -0
- package/migrations/meta/0047_snapshot.json +3832 -0
- package/migrations/meta/0048_snapshot.json +3853 -0
- package/migrations/meta/0049_snapshot.json +3854 -0
- package/migrations/meta/0050_snapshot.json +3924 -0
- package/migrations/meta/0051_snapshot.json +3940 -0
- package/migrations/meta/0052_snapshot.json +3931 -0
- package/migrations/meta/0053_snapshot.json +3952 -0
- package/migrations/meta/0054_snapshot.json +3952 -0
- package/migrations/meta/0055_snapshot.json +3952 -0
- package/migrations/meta/0056_snapshot.json +3952 -0
- package/migrations/meta/0057_snapshot.json +3839 -0
- package/migrations/meta/0058_snapshot.json +3839 -0
- package/migrations/meta/0059_snapshot.json +3839 -0
- package/migrations/meta/0060_snapshot.json +3830 -0
- package/migrations/meta/0061_snapshot.json +3821 -0
- package/migrations/meta/0062_snapshot.json +3723 -0
- package/migrations/meta/0063_snapshot.json +3723 -0
- package/migrations/meta/0064_snapshot.json +3723 -0
- package/migrations/meta/0065_snapshot.json +3729 -0
- package/migrations/meta/0066_snapshot.json +3729 -0
- package/migrations/meta/0067_snapshot.json +3736 -0
- package/migrations/meta/0068_snapshot.json +3347 -0
- package/migrations/meta/0069_snapshot.json +3340 -0
- package/migrations/meta/0070_snapshot.json +3444 -0
- package/migrations/meta/0072_snapshot.json +3450 -0
- package/migrations/meta/0073_snapshot.json +3455 -0
- package/migrations/meta/0074_snapshot.json +3461 -0
- package/migrations/meta/0075_snapshot.json +3567 -0
- package/migrations/meta/0076_snapshot.json +3851 -0
- package/migrations/meta/0077_snapshot.json +4067 -0
- package/migrations/meta/0078_snapshot.json +4078 -0
- package/migrations/meta/0079_snapshot.json +4078 -0
- package/migrations/meta/0080_snapshot.json +4078 -0
- package/migrations/meta/0081_snapshot.json +4096 -0
- package/migrations/meta/0082_snapshot.json +4102 -0
- package/migrations/meta/0083_snapshot.json +4096 -0
- package/migrations/meta/0084_snapshot.json +4096 -0
- package/migrations/meta/_journal.json +385 -0
- package/package.json +25 -11
- package/drizzle.config.ts +0 -23
- package/src/client.ts +0 -24
- package/src/config.ts +0 -19
- package/src/connection.ts +0 -27
- package/src/credential-resolution.ts +0 -378
- package/src/grant-store.ts +0 -51
- package/src/index.ts +0 -32
- package/src/migrate.test.ts +0 -35
- package/src/migrate.ts +0 -168
- package/src/parse-row.test.ts +0 -113
- package/src/parse-row.ts +0 -185
- package/src/schema/agent-assets.ts +0 -21
- package/src/schema/agents.ts +0 -49
- package/src/schema/auth.ts +0 -51
- package/src/schema/grants.ts +0 -26
- package/src/schema/index.ts +0 -19
- package/src/schema/instances.ts +0 -36
- package/src/schema/messages.ts +0 -108
- package/src/schema/offerings.ts +0 -20
- package/src/schema/principals.ts +0 -28
- package/src/schema/providers.ts +0 -23
- package/src/schema/roles.ts +0 -51
- package/src/schema/session-assets.ts +0 -49
- package/src/schema/sessions.ts +0 -26
- package/src/schema/sidecar.ts +0 -14
- package/src/schema/wallets.ts +0 -44
- package/src/tenant-hierarchy.ts +0 -34
- package/tsconfig.json +0 -4
- package/tsconfig.tsbuildinfo +0 -1
package/src/schema/roles.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
boolean,
|
|
3
|
-
pgTable,
|
|
4
|
-
primaryKey,
|
|
5
|
-
text,
|
|
6
|
-
timestamp,
|
|
7
|
-
} from "drizzle-orm/pg-core";
|
|
8
|
-
|
|
9
|
-
import { agent } from "./agents";
|
|
10
|
-
import { principal } from "./principals";
|
|
11
|
-
import { tenant } from "./tenants";
|
|
12
|
-
|
|
13
|
-
export const role = pgTable("role", {
|
|
14
|
-
id: text("id").primaryKey(),
|
|
15
|
-
tenantId: text("tenant_id")
|
|
16
|
-
.notNull()
|
|
17
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
18
|
-
name: text("name").notNull(),
|
|
19
|
-
description: text("description"),
|
|
20
|
-
isSystem: boolean("is_system").notNull().default(false),
|
|
21
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
22
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const agentRole = pgTable(
|
|
26
|
-
"agent_role",
|
|
27
|
-
{
|
|
28
|
-
agentId: text("agent_id")
|
|
29
|
-
.notNull()
|
|
30
|
-
.references(() => agent.id, { onDelete: "cascade" }),
|
|
31
|
-
roleId: text("role_id")
|
|
32
|
-
.notNull()
|
|
33
|
-
.references(() => role.id, { onDelete: "cascade" }),
|
|
34
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
35
|
-
},
|
|
36
|
-
(t) => [primaryKey({ columns: [t.agentId, t.roleId] })],
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export const principalRole = pgTable(
|
|
40
|
-
"principal_role",
|
|
41
|
-
{
|
|
42
|
-
principalId: text("principal_id")
|
|
43
|
-
.notNull()
|
|
44
|
-
.references(() => principal.id, { onDelete: "cascade" }),
|
|
45
|
-
roleId: text("role_id")
|
|
46
|
-
.notNull()
|
|
47
|
-
.references(() => role.id, { onDelete: "cascade" }),
|
|
48
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
49
|
-
},
|
|
50
|
-
(t) => [primaryKey({ columns: [t.principalId, t.roleId] })],
|
|
51
|
-
);
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
index,
|
|
3
|
-
pgTable,
|
|
4
|
-
primaryKey,
|
|
5
|
-
text,
|
|
6
|
-
timestamp,
|
|
7
|
-
} from "drizzle-orm/pg-core";
|
|
8
|
-
|
|
9
|
-
import { agentAsset } from "./agent-assets";
|
|
10
|
-
import { agentInstance } from "./instances";
|
|
11
|
-
|
|
12
|
-
// session_asset rows record per-(instance, agent_asset) pack
|
|
13
|
-
// acknowledgments. A row exists iff the sidecar acked the pack that
|
|
14
|
-
// materialized that asset for that instance. The launchSession flow
|
|
15
|
-
// inserts each row before the corresponding pack send and rolls it
|
|
16
|
-
// back if that single send fails, so each row reflects an ack the
|
|
17
|
-
// hub actually observed for that attachment.
|
|
18
|
-
//
|
|
19
|
-
// Caveat on multi-attachment partial-success: when a session attaches
|
|
20
|
-
// N assets and the fan-out succeeds for attachments 1..k-1 and fails
|
|
21
|
-
// on attachment k, only attachment k's row is rolled back. Rows
|
|
22
|
-
// 1..k-1 stay. The session as a whole never reached the running
|
|
23
|
-
// state — attemptCleanup runs sendAgentUndeploy — but the per-
|
|
24
|
-
// attachment ack invariant holds for the rows that remain.
|
|
25
|
-
// Forensics queries should treat row count as "packs the sidecar
|
|
26
|
-
// acked during this instance's launch," not "sessions that ran with
|
|
27
|
-
// assets." Pairing with agent_instance.status (or its successor
|
|
28
|
-
// session-lifecycle signal) is necessary to distinguish a row left
|
|
29
|
-
// behind by a partially-successful failed launch from one belonging
|
|
30
|
-
// to a fully-running session.
|
|
31
|
-
export const sessionAsset = pgTable(
|
|
32
|
-
"session_asset",
|
|
33
|
-
{
|
|
34
|
-
instanceId: text("instance_id")
|
|
35
|
-
.notNull()
|
|
36
|
-
.references(() => agentInstance.id, { onDelete: "cascade" }),
|
|
37
|
-
agentAssetId: text("agent_asset_id")
|
|
38
|
-
.notNull()
|
|
39
|
-
.references(() => agentAsset.id, { onDelete: "cascade" }),
|
|
40
|
-
mountPath: text("mount_path").notNull(),
|
|
41
|
-
assetPackSha: text("asset_pack_sha").notNull(),
|
|
42
|
-
sourceCommitSha: text("source_commit_sha").notNull(),
|
|
43
|
-
materializedAt: timestamp("materialized_at").notNull().defaultNow(),
|
|
44
|
-
},
|
|
45
|
-
(t) => [
|
|
46
|
-
primaryKey({ columns: [t.instanceId, t.agentAssetId] }),
|
|
47
|
-
index("session_asset_pack_sha_idx").on(t.assetPackSha),
|
|
48
|
-
],
|
|
49
|
-
);
|
package/src/schema/sessions.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { agent } from "./agents";
|
|
4
|
-
import { principal } from "./principals";
|
|
5
|
-
import { tenant } from "./tenants";
|
|
6
|
-
|
|
7
|
-
export const agentSession = pgTable("agent_session", {
|
|
8
|
-
id: text("id").primaryKey(),
|
|
9
|
-
tenantId: text("tenant_id")
|
|
10
|
-
.notNull()
|
|
11
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
12
|
-
agentId: text("agent_id")
|
|
13
|
-
.notNull()
|
|
14
|
-
.references(() => agent.id, { onDelete: "cascade" }),
|
|
15
|
-
principalId: text("principal_id")
|
|
16
|
-
.notNull()
|
|
17
|
-
.references(() => principal.id),
|
|
18
|
-
status: text("status", {
|
|
19
|
-
enum: ["active", "ending", "ended"],
|
|
20
|
-
})
|
|
21
|
-
.notNull()
|
|
22
|
-
.default("active"),
|
|
23
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
24
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
25
|
-
endedAt: timestamp("ended_at"),
|
|
26
|
-
});
|
package/src/schema/sidecar.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
export const sidecar = pgTable("sidecar", {
|
|
4
|
-
id: text("id").primaryKey(),
|
|
5
|
-
url: text("url").notNull(),
|
|
6
|
-
status: text("status", {
|
|
7
|
-
enum: ["online", "offline", "error"],
|
|
8
|
-
})
|
|
9
|
-
.notNull()
|
|
10
|
-
.default("online"),
|
|
11
|
-
lastHeartbeat: timestamp("last_heartbeat"),
|
|
12
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
13
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
14
|
-
});
|
package/src/schema/wallets.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
});
|
package/src/tenant-hierarchy.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
DELETED