Skip to content

Commit 6d837dd

Browse files
authored
ENG-810 Repair supabase typing (#397)
* restore type references in roam * coderabbit suggestion
1 parent 627bd18 commit 6d837dd

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

apps/obsidian/scripts/publish.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "path";
44
import { exec } from "child_process";
55
import util from "util";
66
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
7-
// TODO: Change to apps/obsidian to ESM
7+
// TODO if possible: change apps/obsidian to ESM. Use require until then.
88
// import { Octokit } from "@octokit/core";
99
const { Octokit } = require("@octokit/core");
1010
import os from "os";
@@ -162,16 +162,16 @@ Release Type Auto-Detection:
162162
BRAT Version Priority:
163163
BRAT uses alphabetical ordering, so alpha < beta < stable
164164
- 0.1.0-alpha-feature (lowest priority)
165-
- 0.1.0-beta.1 (higher priority)
165+
- 0.1.0-beta.1 (higher priority)
166166
- 0.1.0 (highest priority)
167167
168168
Examples:
169169
# Internal release with custom name
170170
tsx scripts/publish-obsidian.ts --version 0.1.0-alpha-canvas --release-name "Canvas Integration Feature"
171-
171+
172172
# Beta release with feature description
173173
tsx scripts/publish-obsidian.ts --version 1.0.0-beta.1 --release-name "Beta: New Graph View"
174-
174+
175175
# Stable release (uses default name)
176176
tsx scripts/publish-obsidian.ts --version 1.0.0
177177
`);

apps/roam/scripts/publish.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import * as path from "path";
33
import * as fs from "fs";
44
import { exec } from "child_process";
55
import util from "util";
6-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
7-
// import { Octokit } from "@octokit/core";
8-
// import { createAppAuth } from "@octokit/auth-app";
6+
// Module configuration in roam does not allow ESM import, we need to use require here.
97
const { Octokit } = require("@octokit/core");
108
const { createAppAuth } = require("@octokit/auth-app");
119

apps/roam/src/utils/cleanupOrphanedNodes.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { type SupabaseContext } from "./supabaseContext";
2-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
3-
type DGSupabaseClient = any;
1+
import type { SupabaseContext } from "./supabaseContext";
2+
import type { DGSupabaseClient } from "@repo/database/lib/client";
43

54
const getAllNodesFromSupabase = async (
65
supabaseClient: DGSupabaseClient,
@@ -22,7 +21,7 @@ const getAllNodesFromSupabase = async (
2221
return [];
2322
}
2423

25-
const schemaIds = schemas.map((s: { id: string }) => s.id);
24+
const schemaIds = schemas.map((s: { id: number }) => s.id);
2625
let nodeResult: string[] = [];
2726

2827
if (schemaIds.length > 0) {
@@ -50,10 +49,10 @@ const getAllNodesFromSupabase = async (
5049
nodeResult =
5150
conceptResponse.data
5251
?.map(
53-
(c: { Content?: { source_local_id: string } }) =>
54-
c.Content?.source_local_id,
52+
(c: { Content?: { source_local_id: string | null } }) =>
53+
c.Content?.source_local_id || null,
5554
)
56-
.filter((id: string): id is string => !!id) || [];
55+
.filter((id: string | null): id is string => !!id) || [];
5756
}
5857

5958
const blockContentResponse = await supabaseClient
@@ -73,8 +72,8 @@ const getAllNodesFromSupabase = async (
7372

7473
const blockResult =
7574
blockContentResponse.data
76-
?.map((c: { source_local_id: string }) => c.source_local_id)
77-
.filter((id: string): id is string => !!id) || [];
75+
?.map((c: { source_local_id: string | null }) => c.source_local_id)
76+
.filter((id: string | null): id is string => !!id) || [];
7877

7978
const result = [...new Set([...nodeResult, ...blockResult])];
8079

@@ -115,10 +114,10 @@ const getAllNodeSchemasFromSupabase = async (
115114
return (
116115
data
117116
?.map(
118-
(c: { Content?: { source_local_id: string } }) =>
119-
c.Content?.source_local_id,
117+
(c: { Content?: { source_local_id: string | null } }) =>
118+
c.Content?.source_local_id || null,
120119
)
121-
.filter((id: string): id is string => !!id) || []
120+
.filter((id: string | null): id is string => !!id) || []
122121
);
123122
} catch (error) {
124123
console.error("Error in getAllNodeSchemasFromSupabase:", error);
@@ -133,7 +132,7 @@ const getNonExistentRoamUids = (nodeUids: string[]): string[] => {
133132
}
134133

135134
const results = window.roamAlphaAPI.q(
136-
`[:find ?uid
135+
`[:find ?uid
137136
:in $ [?uid ...]
138137
:where (not [_ :block/uid ?uid])]`,
139138
nodeUids,
@@ -162,7 +161,7 @@ const deleteNodesFromSupabase = async (
162161
console.error("Failed to get content from Supabase:", contentError);
163162
}
164163

165-
const contentIds = contentData?.map((c: { id: string }) => c.id) || [];
164+
const contentIds = contentData?.map((c: { id: number }) => c.id) || [];
166165

167166
if (contentIds.length > 0) {
168167
const { error: conceptError } = await supabaseClient
@@ -219,7 +218,7 @@ const deleteNodeSchemasFromSupabase = async (
219218
return 0;
220219
}
221220

222-
const schemaContentIds = schemaContentData.map((c: { id: string }) => c.id);
221+
const schemaContentIds = schemaContentData.map((c: { id: number }) => c.id);
223222

224223
const { data: schemaConceptData, error: schemaConceptError } =
225224
await supabaseClient
@@ -238,7 +237,7 @@ const deleteNodeSchemasFromSupabase = async (
238237
}
239238

240239
const schemaConceptIds = (schemaConceptData || []).map(
241-
(c: { id: string }) => c.id,
240+
(c: { id: number }) => c.id,
242241
);
243242

244243
let instanceConceptIds: number[] = [];
@@ -263,11 +262,11 @@ const deleteNodeSchemasFromSupabase = async (
263262
}
264263

265264
instanceConceptIds = (instanceConceptData || []).map(
266-
(ic: { id: string }) => ic.id,
265+
(ic: { id: number }) => ic.id,
267266
);
268267
instanceContentIds = (instanceConceptData || [])
269-
.map((ic: { represented_by_id: number }) => ic.represented_by_id)
270-
.filter((x: number): x is number => typeof x === "number");
268+
.map((ic: { represented_by_id: number | null }) => ic.represented_by_id)
269+
.filter((x: number | null): x is number => typeof x === "number");
271270

272271
if (instanceContentIds.length > 0) {
273272
const { data: instanceContentData, error: instanceContentLookupError } =
@@ -284,8 +283,8 @@ const deleteNodeSchemasFromSupabase = async (
284283
return 0;
285284
}
286285
instanceSourceLocalIds = (instanceContentData || [])
287-
.map((c: { source_local_id: string }) => c.source_local_id)
288-
.filter((id: string): id is string => !!id);
286+
.map((c: { source_local_id: string | null }) => c.source_local_id)
287+
.filter((id: string | null): id is string => !!id);
289288
}
290289
}
291290

apps/roam/src/utils/syncDgNodesToSupabase.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import {
1919
import { type OnloadArgs } from "roamjs-components/types";
2020
import { fetchEmbeddingsForNodes } from "./upsertNodesAsContentWithEmbeddings";
2121
import { convertRoamNodeToLocalContent } from "./upsertNodesAsContentWithEmbeddings";
22-
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
23-
type LocalContentDataInput = any;
24-
type DGSupabaseClient = any;
25-
type Json = any;
26-
type AccountLocalInput = any;
22+
import type { DGSupabaseClient } from "@repo/database/lib/client";
23+
import type { Json, CompositeTypes } from "@repo/database/dbTypes";
24+
25+
type LocalContentDataInput = Partial<CompositeTypes<"content_local_input">>;
26+
type AccountLocalInput = CompositeTypes<"account_local_input">;
2727

2828
const SYNC_FUNCTION = "embedding";
2929
const SYNC_INTERVAL = "45s";
@@ -51,7 +51,7 @@ export const endSyncTask = async (
5151
}
5252
const { error } = await supabaseClient.rpc("end_sync_task", {
5353
s_target: context.spaceId,
54-
s_function: "embedding",
54+
s_function: SYNC_FUNCTION,
5555
s_worker: worker,
5656
s_status: status,
5757
});
@@ -157,7 +157,7 @@ const upsertNodeSchemaToContent = async ({
157157
[?e :edit/time ?edit-time]
158158
[?e :edit/user ?eu]
159159
[(get-else $ ?eu :user/display-name "Unknown-person") ?author-name]
160-
160+
161161
]
162162
`;
163163
//@ts-ignore - backend to be added to roamjs-components
@@ -311,7 +311,7 @@ const getDgNodeTypes = (extensionAPI: OnloadArgs["extensionAPI"]) => {
311311
};
312312

313313
const getAllUsers = async (): Promise<AccountLocalInput[]> => {
314-
const query = `[:find ?author_local_id ?author_name
314+
const query = `[:find ?author_local_id ?author_name
315315
:keys author_local_id name
316316
:where
317317
[?user-eid :user/uid ?author_local_id]

apps/roam/src/utils/upsertNodesAsContentWithEmbeddings.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { type RoamDiscourseNodeData } from "./getAllDiscourseNodesSince";
33
import { type SupabaseContext } from "./supabaseContext";
44
import { nextApiRoot } from "@repo/utils/execContext";
5-
type LocalContentDataInput = any;
6-
type DGSupabaseClient = any;
7-
type Json = any;
5+
import type { DGSupabaseClient } from "@repo/database/lib/client";
6+
import type { Json, CompositeTypes } from "@repo/database/dbTypes";
7+
8+
type LocalContentDataInput = Partial<CompositeTypes<"content_local_input">>;
89

910
const EMBEDDING_BATCH_SIZE = 200;
1011
const EMBEDDING_MODEL = "openai_text_embedding_3_small_1536";

0 commit comments

Comments
 (0)