Skip to content

Commit c859181

Browse files
committed
refactor: move removeSubjectIdScope to runtime core
1 parent 515b3e8 commit c859181

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

apps/api/src/instrument-records/export-worker.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { parentPort } from 'worker_threads';
22

3-
import { removeSubjectIdScope } from '@opendatacapture/subject-utils';
4-
53
/** @type {typeof import('@opendatacapture/schemas/core').DEFAULT_GROUP_NAME} */
64
const DEFAULT_GROUP_NAME = 'root';
75

6+
/** @type {typeof import( '#runtime/v1/@opendatacapture/runtime-internal/index.js').removeSubjectIdScope} */
7+
let removeSubjectIdScope;
8+
9+
// we need to resolve import correctly in development
10+
try {
11+
const runtimeInternal = await import('#runtime/v1/@opendatacapture/runtime-internal/index.js');
12+
removeSubjectIdScope = runtimeInternal.removeSubjectIdScope;
13+
} catch {
14+
const runtimeInternal = await import('@opendatacapture/runtime-v1/@opendatacapture/runtime-internal/index.js');
15+
removeSubjectIdScope = runtimeInternal.removeSubjectIdScope;
16+
}
17+
818
/**
919
* @typedef {Object} SuccessExpand
1020
* @property {string} measure

packages/runtime-internal/src/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ export declare function encodeUnicodeToBase64(s: string): string;
1313

1414
/** Decodes a Base64 string back into a Unicode string. */
1515
export declare function decodeBase64ToUnicode(s: string): string;
16+
17+
/** Remove the scope from a subject ID (e.g., root$123 -> 123) */
18+
export declare function removeSubjectIdScope(id: string): string;

packages/runtime-internal/src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ export function decodeBase64ToUnicode(s) {
2121
const bytes = Uint8Array.from(binaryString, (c) => c.charCodeAt(0));
2222
return new TextDecoder().decode(bytes);
2323
}
24+
25+
/** @type {import('./index.d.ts').removeSubjectIdScope} */
26+
export function removeSubjectIdScope(id) {
27+
if (id.includes('$')) {
28+
return /** @type {string} */ (id.split('$')[1]);
29+
}
30+
return id;
31+
}

packages/subject-utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@douglasneuroinformatics/libcrypto": "catalog:",
16+
"@opendatacapture/runtime-internal": "workspace:*",
1617
"@opendatacapture/schemas": "workspace:*",
1718
"transliteration": "^2.3.5"
1819
},

packages/subject-utils/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,4 @@ export function encodeScopedSubjectId(id: number | string, options: { groupName:
5555
return options.groupName.replaceAll(' ', '_') + '$' + id;
5656
}
5757

58-
export function removeSubjectIdScope(id: string) {
59-
if (id.includes('$')) {
60-
return id.split('$')[1]!;
61-
}
62-
return id;
63-
}
58+
export { removeSubjectIdScope } from '@opendatacapture/runtime-internal';

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)