Skip to content

Commit 32528b6

Browse files
authored
Db abstraction - add db package (#634)
Toward modular code base. PR: - pulls contents of `vue/src/db` into its own `db` package - removes direct dependency of `pouchdb` from `vue` package - lays (rough) foundation for replacing implementations w/ interfaces at package boundaries
2 parents 1fd9978 + a318d55 commit 32528b6

File tree

88 files changed

+973
-955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+973
-955
lines changed

.github/workflows/build-vue.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
paths:
55
- 'packages/vue/**'
66
- 'packages/common/**'
7+
- 'packages/db/**'
78
- '.github/workflows/build-vue.yml'
89
jobs:
910
build-vue-spa:
@@ -32,6 +33,10 @@ jobs:
3233
working-directory: ./packages/common
3334
run: yarn build
3435

36+
- name: Build db package
37+
working-directory: ./packages/db
38+
run: yarn build
39+
3540
- name: Setup Vue environment
3641
run: printf "${{ secrets.VUE_ENV }}" > ./packages/vue/.env.production
3742

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ vue/Caddyfile
4444

4545
# TypeScript incremental build info
4646
*.tsbuildinfo
47+
48+
# specific pattern to place tmp files that should be ignored
49+
ignore

.prompt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This project is a framework for the authoring of interactive tutoring systems, with the eventual goals of
2+
- a mass-collaborative platform for authoring / sharing etc
3+
- a toolset for spawning individual specialized tutoring systems whose level of customization is out of scope for a web platform
4+
5+
Think: khan academy + duolingo + anki + wikipedia, with an evolutionary mechanism to filter user generated curricular content based on how that content impacts overall learning outcomes.
6+
7+
8+
# History:
9+
10+
developed slowly as an occasional hobby / side project, and used 'in production' for a few years now, but only for household use. Tech stack has recently been modernized:
11+
- vue 2 class-based-components -> vue 3
12+
- vuetify 1.x -> vuetify 3 (current)
13+
- lerna ~3.x hodge podge -> yarn workspaces
14+
15+
Much of the legacy code was written without explicit concerns for performance, security, or scale.
16+
17+
# Current goals:
18+
19+
Seeking to use the project as a vehicle to develop content for commercial, production grade systems. Seeking to iterate quickly to modernize the stack and add key features.
20+
21+
# GENERAL QUALITY CAVEAT
22+
23+
With respect to security, error handling, and performance: _If you see something, say something._
24+
25+
If you parse source code that contains *critical errors*, please prefix your responses with "WARNING: SUBSTANTIVE ERRORS DETECTED" and provide a brief summary of the errors.
26+
27+
Do this at the expense of addressing the specific questions that were posed.
28+
29+
Thanks!

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-skuilder",
33
"scripts": {
4-
"dev": "yarn workspace @vue-skuilder/common build && node scripts/dev-couchdb.js start && concurrently \"yarn dev:vue\" \"yarn dev:express\"",
4+
"dev": "yarn workspace @vue-skuilder/common build && yarn workspace @vue-skuilder/db build && node scripts/dev-couchdb.js start && concurrently \"yarn dev:vue\" \"yarn dev:express\"",
55
"dev:vue": "yarn workspace @vue-skuilder/vue dev",
66
"dev:express": "yarn workspace @vue-skuilder/express dev",
77
"dev:couchdb": "node scripts/dev-couchdb.js start",
@@ -13,7 +13,7 @@
1313
"test:e2e": "cypress open",
1414
"test:e2e:headless": "cypress run",
1515
"ci:e2e": "yarn dev & wait-on http://localhost:5173 && cypress run; kill $(lsof -t -i:8080); yarn couchdb:stop",
16-
"build": "yarn workspace @vue-skuilder/common build && yarn workspace @vue-skuilder/vue build && yarn workspace @vue-skuilder/express build"
16+
"build": "yarn workspace @vue-skuilder/common build && yarn workspace @vue-skuilder/db build && yarn workspace @vue-skuilder/vue build && yarn workspace @vue-skuilder/express build"
1717
},
1818
"private": true,
1919
"workspaces": [

packages/vue/src/ENVIRONMENT_VARS.ts renamed to packages/common/src/ENVIRONMENT_VARS.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,38 @@ const ENV: Environment = {
3838
MOCK: false,
3939
};
4040

41-
ENV.COUCHDB_SERVER_URL = import.meta.env.VITE_COUCHDB_SERVER!;
42-
ENV.COUCHDB_SERVER_PROTOCOL = import.meta.env.VITE_COUCHDB_PROTOCOL! as ProtocolString;
41+
// Try to load from Vite environment if available
42+
try {
43+
// Use typeof check to avoid issues in non-Vite environments
44+
if (typeof import.meta !== 'undefined' && 'env' in import.meta) {
45+
const env = (import.meta as any).env;
4346

44-
ENV.EXPRESS_SERVER_URL = import.meta.env.VITE_EXPRESS_SERVER!;
45-
ENV.EXPRESS_SERVER_PROTOCOL = import.meta.env.VITE_EXPRESS_PROTOCOL! as ProtocolString;
47+
if (env.VITE_COUCHDB_SERVER) {
48+
ENV.COUCHDB_SERVER_URL = env.VITE_COUCHDB_SERVER;
49+
}
4650

47-
if (import.meta.env.VITE_DEBUG !== undefined) {
48-
ENV.DEBUG = import.meta.env.VITE_DEBUG === 'true';
49-
}
51+
if (env.VITE_COUCHDB_PROTOCOL) {
52+
ENV.COUCHDB_SERVER_PROTOCOL = env.VITE_COUCHDB_PROTOCOL as ProtocolString;
53+
}
54+
55+
if (env.VITE_EXPRESS_SERVER) {
56+
ENV.EXPRESS_SERVER_URL = env.VITE_EXPRESS_SERVER;
57+
}
58+
59+
if (env.VITE_EXPRESS_PROTOCOL) {
60+
ENV.EXPRESS_SERVER_PROTOCOL = env.VITE_EXPRESS_PROTOCOL as ProtocolString;
61+
}
62+
63+
if (env.VITE_DEBUG !== undefined) {
64+
ENV.DEBUG = env.VITE_DEBUG === 'true';
65+
}
5066

51-
if (import.meta.env.VITE_MOCK !== undefined) {
52-
ENV.MOCK = import.meta.env.VITE_MOCK === 'true';
67+
if (env.VITE_MOCK !== undefined) {
68+
ENV.MOCK = env.VITE_MOCK === 'true';
69+
}
70+
}
71+
} catch (e) {
72+
console.warn('Unable to load environment variables from Vite:', e);
5373
}
5474

5575
if (ENV.DEBUG) {

packages/common/src/course-data.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
import { Status } from './wire-format.js';
22
import { DisplayableData, DocType } from './db.js';
33
import { NameSpacer } from './namespacer.js';
4+
import { CourseElo } from './elo.js';
45

56
export interface DataShape {
67
name: DataShapeName;
78
fields: FieldDefinition[];
89
}
910

10-
export type CourseElo = {
11-
global: EloRank;
12-
tags: {
13-
[tagID: string]: EloRank;
14-
};
15-
misc: {
16-
[eloID: string]: EloRank;
17-
};
18-
};
19-
20-
type EloRank = {
21-
score: number;
22-
count: number;
23-
};
24-
2511
export interface ValidationResult {
2612
status: Status;
2713
msg: string;

packages/common/src/db.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Answer, Evaluation, CourseElo } from './course-data.js';
1+
import { Answer, Evaluation } from './course-data.js';
2+
import { CourseElo } from './elo.js';
23
import { Moment } from 'moment';
34

45
export enum DocType {
File renamed without changes.

packages/common/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from './wire-format.js';
2-
32
export * from './course-data.js';
3+
export { default as ENV } from './ENVIRONMENT_VARS.js';
4+
export * from './elo.js';
5+
export * from './namespacer.js';

packages/db/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# @vue-skuilder/db
2+
3+
Database abstraction layer for vue-skuilder.
4+
5+
## Structure
6+
7+
The package is organized into:
8+
9+
- `core/` - Core interfaces and types for database operations
10+
- `pouch/` - PouchDB implementation of the core interfaces
11+
12+
## Usage
13+
14+
```typescript
15+
// Import the default implementation
16+
import { getUserDB } from '@vue-skuilder/db';
17+
18+
// Or import from a specific namespace
19+
import { DBInterfaces } from '@vue-skuilder/db/core';
20+
import { PouchImplementation } from '@vue-skuilder/db/pouch';
21+
```

0 commit comments

Comments
 (0)