Skip to content

Commit 7cd1ed4

Browse files
authored
Datalayer config (#675)
2 parents 6fa8cf1 + 29834ea commit 7cd1ed4

File tree

18 files changed

+126
-75
lines changed

18 files changed

+126
-75
lines changed

CLAUDE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
- Build: `yarn build`
7+
- Dev: `yarn dev` (starts CouchDB, platform-ui, express)
8+
- Lint: `yarn workspace @vue-skuilder/platform-ui lint` or `yarn workspace @vue-skuilder/express lint:fix`
9+
- Type check: `yarn workspace @vue-skuilder/express type-check`
10+
- Unit tests: `yarn workspace @vue-skuilder/platform-ui test:unit`
11+
- Run single test: `yarn workspace @vue-skuilder/platform-ui test:unit <test-file-path>`
12+
- E2E tests: `yarn workspace @vue-skuilder/platform-ui test:e2e`
13+
14+
## Style Guidelines
15+
- Use TypeScript with strict typing
16+
- Format: singleQuote, 2-space tabs (4 for JSON), 100 char line width (120 for Vue files)
17+
- Import order: external modules first, then internal modules
18+
- Vue components use PascalCase
19+
- CSS uses kebab-case
20+
- Variables/functions use camelCase
21+
- Use async/await for promises
22+
- Error handling: try/catch blocks for async code
23+
- Use ESLint and Prettier for code formatting
24+
- Follow Vue 3 Composition API patterns

packages/common-ui/vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
terserOptions: {
1111
keep_classnames: true,
1212
},
13+
sourcemap: true,
1314
lib: {
1415
entry: resolve(__dirname, 'src/index.ts'),
1516
name: 'VueSkuilderCommonUI',
@@ -28,6 +29,7 @@ export default defineConfig({
2829
assetFileNames: (assetInfo) => {
2930
return `assets/[name][extname]`;
3031
},
32+
sourcemap: true,
3133
},
3234
},
3335
// This is crucial for component libraries - allow CSS to be in chunks

packages/common/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './wire-format.js';
22
export * from './course-data.js';
3-
export { default as ENV } from './ENVIRONMENT_VARS.js';
43
export * from './elo.js';
54
export * from './namespacer.js';
65
export * from './logshim.js';

packages/db/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"scripts": {
2626
"build": "tsup",
27+
"build:debug": "tsup --sourcemap inline",
2728
"dev": "tsup --watch"
2829
},
2930
"dependencies": {

packages/db/src/factory.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22

33
import { DataLayerProvider } from './core/interfaces';
44

5+
interface DBEnv {
6+
COUCHDB_SERVER_URL: string; // URL of CouchDB server
7+
COUCHDB_SERVER_PROTOCOL: string; // Protocol of CouchDB server (http or https)
8+
}
9+
10+
export const ENV: DBEnv = {
11+
COUCHDB_SERVER_PROTOCOL: 'NOT_SET',
12+
COUCHDB_SERVER_URL: 'NOT_SET',
13+
};
14+
515
// Configuration type for data layer initialization
616
export interface DataLayerConfig {
717
type: 'pouch' | 'static';
8-
options?: {
18+
options: {
919
staticContentPath?: string; // Path to static content JSON files
1020
localStoragePrefix?: string; // Prefix for IndexedDB storage names
21+
COUCHDB_SERVER_URL?: string;
22+
COUCHDB_SERVER_PROTOCOL?: string;
1123
};
1224
}
1325

@@ -23,8 +35,14 @@ export async function initializeDataLayer(config: DataLayerConfig): Promise<Data
2335
return dataLayerInstance;
2436
}
2537

26-
// Dynamic import to avoid loading both implementations when only one is needed
2738
if (config.type === 'pouch') {
39+
if (!config.options.COUCHDB_SERVER_URL || !config.options.COUCHDB_SERVER_PROTOCOL) {
40+
throw new Error('Missing CouchDB server URL or protocol');
41+
}
42+
ENV.COUCHDB_SERVER_PROTOCOL = config.options.COUCHDB_SERVER_PROTOCOL;
43+
ENV.COUCHDB_SERVER_URL = config.options.COUCHDB_SERVER_URL;
44+
45+
// Dynamic import to avoid loading both implementations when only one is needed
2846
const { PouchDataLayerProvider } = await import('./impl/pouch/PouchDataLayerProvider');
2947
dataLayerInstance = new PouchDataLayerProvider();
3048
} else {

packages/db/src/impl/pouch/adminDB.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import pouch from 'pouchdb';
2-
import { ENV } from '@vue-skuilder/common';
1+
import pouch from './pouchdb-setup';
2+
import { ENV } from '@/factory';
33
import {
44
pouchDBincludeCredentialsConfig,
55
getStartAndEndKeys,
@@ -60,7 +60,7 @@ export class AdminDB implements AdminDBInterface {
6060
public async getClassrooms() {
6161
// const joincodes =
6262
const uuids = (
63-
await ClassroomLookupDB.allDocs<{ uuid: string }>({
63+
await ClassroomLookupDB().allDocs<{ uuid: string }>({
6464
include_docs: true,
6565
})
6666
).rows.map((r) => r.doc!.uuid);

packages/db/src/impl/pouch/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ENV } from '@vue-skuilder/common';
1+
import { ENV } from '@/factory';
22
import { GuestUsername } from '../../core/types/types-legacy';
33

44
interface SessionResponse {

packages/db/src/impl/pouch/classroomDB.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
StudySessionNewItem,
44
StudySessionReviewItem,
55
} from '@/core/interfaces/contentSource';
6-
import { ClassroomConfig, ENV } from '@vue-skuilder/common';
6+
import { ClassroomConfig } from '@vue-skuilder/common';
7+
import { ENV } from '@/factory';
78
import moment from 'moment';
8-
import pouch from 'pouchdb';
9+
import pouch from './pouchdb-setup';
910
import {
1011
getCourseDB,
1112
getStartAndEndKeys,
@@ -285,12 +286,10 @@ export class TeacherClassroomDB extends ClassroomDBBase implements TeacherClassr
285286
}
286287
}
287288

288-
export const ClassroomLookupDB: PouchDB.Database = new pouch(
289-
ENV.COUCHDB_SERVER_PROTOCOL + '://' + ENV.COUCHDB_SERVER_URL + classroomLookupDBTitle,
290-
{
289+
export const ClassroomLookupDB: () => PouchDB.Database = () =>
290+
new pouch(ENV.COUCHDB_SERVER_PROTOCOL + '://' + ENV.COUCHDB_SERVER_URL + classroomLookupDBTitle, {
291291
skip_setup: true,
292-
}
293-
);
292+
});
294293

295294
export function getClassroomDB(classID: string, version: 'student' | 'teacher'): PouchDB.Database {
296295
const dbName = `classdb-${version}-${classID}`;

packages/db/src/impl/pouch/courseAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import pouch from 'pouchdb';
1+
import pouch from './pouchdb-setup';
22
import { pouchDBincludeCredentialsConfig } from '.';
3-
import { ENV } from '@vue-skuilder/common';
3+
import { ENV } from '@/factory';
44
// import { DataShape } from '../..base-course/Interfaces/DataShape';
55
import { NameSpacer, ShapeDescriptor } from '@vue-skuilder/common';
66
import { CourseConfig, DataShape } from '@vue-skuilder/common';

packages/db/src/impl/pouch/courseLookupDB.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import pouch from 'pouchdb';
2-
import { ENV } from '@vue-skuilder/common';
1+
import pouch from './pouchdb-setup';
2+
// import { ENV } from '@/factory';
33

44
const courseLookupDBTitle = 'coursedb-lookup';
55

@@ -10,6 +10,8 @@ interface CourseLookupDoc {
1010
disambiguator?: string;
1111
}
1212

13+
console.log(`COURSELOOKUP FILE RUNNING`);
14+
1315
/**
1416
* a k-v indexes created courses.
1517
*
@@ -18,13 +20,16 @@ interface CourseLookupDoc {
1820
*/
1921
export default class CourseLookup {
2022
// [ ] this db should be read only for public, admin-write only
21-
static _db: PouchDB.Database = new pouch(
22-
ENV.COUCHDB_SERVER_PROTOCOL + '://' + ENV.COUCHDB_SERVER_URL + courseLookupDBTitle,
23-
{
24-
skip_setup: true,
25-
}
26-
);
23+
// static _db: PouchDB.Database = new pouch(
24+
// ENV.COUCHDB_SERVER_PROTOCOL + '://' + ENV.COUCHDB_SERVER_URL + courseLookupDBTitle,
25+
// {
26+
// // skip_setup: true,
27+
// }
28+
// );
2729

30+
static _db: PouchDB.Database = new pouch('http://localhost:5984/' + courseLookupDBTitle, {
31+
skip_setup: true,
32+
});
2833
/**
2934
* Adds a new course to the lookup database, and returns the courseID
3035
* @param courseName

0 commit comments

Comments
 (0)