diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a0cd01..36c747d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,10 @@ name: build check (mikayla dot dev) +env: + POSTGRES_URL: ${{ secrets.POSTGRES_URL }} + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + on: push: branches: diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 7851d24..f5a82d0 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,5 +1,10 @@ name: build check (mikayla dot dev) +env: + POSTGRES_URL: ${{ secrets.POSTGRES_URL }} + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + on: push: branches: diff --git a/pkg/.eslintrc.json b/pkg/.eslintrc.json new file mode 100644 index 0000000..6751428 --- /dev/null +++ b/pkg/.eslintrc.json @@ -0,0 +1,20 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + } +} diff --git a/pkg/.gitignore b/pkg/.gitignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/pkg/.gitignore @@ -0,0 +1 @@ +lib diff --git a/pkg/.npmignore b/pkg/.npmignore new file mode 100644 index 0000000..f950ebe --- /dev/null +++ b/pkg/.npmignore @@ -0,0 +1,2 @@ +src +eslintrc.json diff --git a/pkg/README.md b/pkg/README.md new file mode 100644 index 0000000..2ebf4fc --- /dev/null +++ b/pkg/README.md @@ -0,0 +1,2 @@ +# Helpers for mikayla.dev + diff --git a/pkg/package.json b/pkg/package.json new file mode 100644 index 0000000..f4af124 --- /dev/null +++ b/pkg/package.json @@ -0,0 +1,29 @@ +{ + "name": "@mkladotdev/utils", + "version": "0.0.1", + "description": "Utilities for mikayla.dev", + "main": "./lib/index.js", + "types": "./lib/index.d.ts", + "files": [ + "./lib/**/*" + ], + "scripts": { + "build": "tsc", + "lint": "eslint . --ext .ts", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Mikayla Dobson", + "license": "ISC", + "dependencies": {}, + "devDependencies": { + "@types/node": "^20.5.9", + "@typescript-eslint/eslint-plugin": "^6.6.0", + "@typescript-eslint/parser": "^6.6.0", + "eslint": "^8.49.0", + "typescript": "^5.2.2" + }, + "publishConfig": { + "registry": "http://localhost:4873" + } +} diff --git a/pkg/src/entities/audiocollection.ts b/pkg/src/entities/audiocollection.ts new file mode 100644 index 0000000..28eccb1 --- /dev/null +++ b/pkg/src/entities/audiocollection.ts @@ -0,0 +1,12 @@ +export type Track = { + name: string; + date: Date; + description: string; +} + +export type AudioCollection = { + name: string; + date: Date; + tracklist: Track[]; + directory: string; +} diff --git a/pkg/src/entities/post.ts b/pkg/src/entities/post.ts new file mode 100644 index 0000000..f2f7fb8 --- /dev/null +++ b/pkg/src/entities/post.ts @@ -0,0 +1,9 @@ +export type Post = { + name: string; + date: Date; + author: string; + description: string; + body: string; + tagIDs: string[]; + media?: string[]; // array of URLs +} diff --git a/pkg/src/entities/project.ts b/pkg/src/entities/project.ts new file mode 100644 index 0000000..a414e63 --- /dev/null +++ b/pkg/src/entities/project.ts @@ -0,0 +1,49 @@ +import { z } from "zod"; + +export type Project = { + name: string; + description: string; + created: Date; + updated?: Date; + tagIDs?: string[]; + media?: string[]; // array of URLs +} + +export class ProjectCreationError extends Error { + constructor(message: string) { + super(message); + this.name = "ProjectCreationError"; + } +} + +export const ZProject = z.object({ + name: z.string(), + description: z.string(), + created: z.date(), + updated: z.date().optional(), + tagIDs: z.array(z.string()).optional(), + media: z.array(z.string()).optional(), +}) + +export function createProject(data: Partial) { + if (!data.name) throw new ProjectCreationError("Project name is required"); + if (!data.description) throw new ProjectCreationError("Project description is required"); + + const today = new Date(); + + const completeInput = { + name: data.name, + description: data.description, + created: data.created || today, + updated: today, + } satisfies Partial; + + const parsedProject = ZProject.safeParse(completeInput); + + if (!parsedProject.success) throw new ProjectCreationError("Invalid project data"); + return parsedProject.data satisfies Project; +} + +export function isProject(data: unknown): data is Project { + return ZProject.safeParse(data).success; +} diff --git a/pkg/tsconfig.json b/pkg/tsconfig.json new file mode 100644 index 0000000..3b06fcf --- /dev/null +++ b/pkg/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + /* Projects */ + "incremental": true, + + /* Language and Environment */ + "target": "es2016", + + /* Modules */ + "module": "commonjs", + "rootDir": "./src", + + /* Emit */ + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "./lib", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + + /* Type Checking */ + "strict": true, + "noImplicitAny": true, + "skipLibCheck": true + }, + "include": ["src"], + "exclude": ["lib", "node_modules"] +}