This commit is contained in:
Florian Metz
2024-04-02 00:23:24 +02:00
parent ec516f2d02
commit 0877e706d2
56 changed files with 3936 additions and 155 deletions

View File

@@ -1,3 +0,0 @@
dist
node_modules
coverage

View File

@@ -1,12 +0,0 @@
module.exports = {
extends: ["@recodive/eslint-config"],
overrides: [
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: ["./**/*.{cjs,js,jsx}"],
},
],
parserOptions: {
project: "./tsconfig.json",
},
};

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ src/update.ini
*.app
*.xml.backup
*.js
!eslint.config.js
coverage
*.tsbuildinfo

View File

@@ -5,4 +5,6 @@
*.ts
*.vue
pnpm-lock.yaml
cache
cache
**/*/generated/**/*

View File

@@ -1 +1,2 @@
/* eslint-disable @typescript-eslint/no-var-requires */
module.exports = require("@recodive/configs").default.prettier;

1
apps/api/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
generated

26
apps/api/codegen.ts Normal file
View File

@@ -0,0 +1,26 @@
import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
generates: {
"dist/generated/schema-v4.graphql": {
plugins: ["schema-ast"],
schema: "src/graphql/schema/v4/**/*.gql",
},
"src/generated/graphql-v4.ts": {
config: {
scalars: {
StringOrStringArray: "string | string[]",
},
},
plugins: ["typescript", "typescript-resolvers"],
schema: "src/graphql/schema/v4/**/*.gql",
},
"src/generated/schema-v4.graphql": {
plugins: ["schema-ast"],
schema: "src/graphql/schema/v4/**/*.gql",
},
},
overwrite: true,
};
export default config;

7
apps/api/environment.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
/* eslint-disable unicorn/prevent-abbreviations */
declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV?: "development" | "production" | "test";
DATABASE_URL?: string;
}
}

41
apps/api/package.json Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "@premid/api",
"version": "1.0.0",
"description": "PreMiD's api",
"main": "dist/index.js",
"type": "module",
"files": [
"dist"
],
"scripts": {
"start": "node --enable-source-maps .",
"dev": "node --watch --env-file .env --enable-source-maps .",
"build": "tsc -p tsconfig.app.json",
"codegen": "graphql-codegen --config codegen.ts"
},
"private": true,
"license": "MPL-2.0",
"dependencies": {
"@envelop/sentry": "^8.0.0",
"@escape.tech/graphql-armor-max-aliases": "^2.3.0",
"@escape.tech/graphql-armor-max-depth": "^2.2.0",
"@escape.tech/graphql-armor-max-directives": "^2.1.0",
"@escape.tech/graphql-armor-max-tokens": "^2.3.0",
"@premid/db": "*",
"@sentry/node": "^7.104.0",
"@sentry/tracing": "^7.104.0",
"fastify": "^4.26.0",
"graphql": "^16.8.1",
"graphql-parse-resolve-info": "^4.13.0",
"graphql-yoga": "^5.1.1",
"mongoose": "^8.2.0"
},
"devDependencies": {
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/schema-ast": "^4.0.2",
"@graphql-codegen/typescript": "4.0.6",
"@graphql-codegen/typescript-resolvers": "4.0.6",
"@parcel/watcher": "^2.4.1",
"typescript": "^5.3.3"
}
}

View File

@@ -0,0 +1,25 @@
import { describe, expect, it, test } from "vitest";
describe.concurrent("createServer", () => {
test("should create a server", async () => {
const createServer = await import("./createServer.js"),
server = await createServer.default();
expect(server).toBeDefined();
expect(server).toHaveProperty("listen");
});
it("should handle graphql requests", async () => {
const createServer = await import("./createServer.js"),
server = await createServer.default();
expect(server).toBeDefined();
expect(server).toHaveProperty("listen");
const response = await server.inject({
method: "GET",
url: "/v4",
});
expect(response).toBeDefined();
expect(response.statusCode).toBe(200);
});
});

View File

@@ -0,0 +1,57 @@
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { useSentry } from "@envelop/sentry";
import { maxAliasesPlugin } from "@escape.tech/graphql-armor-max-aliases";
import { maxDepthPlugin } from "@escape.tech/graphql-armor-max-depth";
import { maxDirectivesPlugin } from "@escape.tech/graphql-armor-max-directives";
import { maxTokensPlugin } from "@escape.tech/graphql-armor-max-tokens";
import fastify, { FastifyReply, FastifyRequest } from "fastify";
import { createSchema, createYoga } from "graphql-yoga";
import { resolvers } from "../graphql/resolvers/v4/index.js";
export interface FastifyContext {
request: FastifyRequest;
reply: FastifyReply;
}
const __dirname = new URL(".", import.meta.url).pathname;
export default async function createServer() {
const
app = fastify({ logger: true }),
yoga = createYoga<FastifyContext>({
graphqlEndpoint: "/v4",
logging: {
/* c8 ignore next 4 */
debug: (...arguments_) => { for (const argument of arguments_) app.log.debug(argument); },
error: (...arguments_) => { for (const argument of arguments_) app.log.error(argument); },
info: (...arguments_) => { for (const argument of arguments_) app.log.info(argument); },
warn: (...arguments_) => { for (const argument of arguments_) app.log.warn(argument); },
},
plugins: [maxAliasesPlugin(), maxDepthPlugin(), maxDirectivesPlugin(), maxTokensPlugin(), useSentry()],
schema: createSchema<FastifyContext>({ resolvers, typeDefs: await readFile(resolve(__dirname, "../generated/schema-v4.graphql"), "utf8") }),
});
app.route({
handler: async (request, reply) => {
const response = await yoga.handleNodeRequest(request, {
reply,
request,
});
for (const [key, value] of response.headers.entries())
void reply.header(key, value);
void reply.status(response.status);
void reply.send(response.body);
return reply;
},
method: ["GET", "POST", "OPTIONS"],
url: "/v4",
});
return app;
}

View File

@@ -0,0 +1,8 @@
import { Resolvers } from "../../../generated/graphql-v4.js";
import presences from "./presences.js";
export const resolvers: Resolvers = {
Query: {
presences,
},
};

View File

@@ -0,0 +1,32 @@
import { Presence } from "@premid/db";
import { PresenceSchema } from "@premid/db/Presence.js";
import { parseResolveInfo } from "graphql-parse-resolve-info";
import { FilterQuery } from "mongoose";
import { QueryResolvers } from "../../../generated/graphql-v4.js";
const resolver: QueryResolvers["presences"] = async (_parent, { author, contributor, limit, query, service, start, tag }, _context, info) => {
const authorFilter: FilterQuery<PresenceSchema> = author ? { "metadata.author.name": author } : {},
contributorFilter: FilterQuery<PresenceSchema> = contributor ? { "metadata.contributors.name": contributor } : {},
serviceFilter: FilterQuery<PresenceSchema> = service ? (Array.isArray(service) ? { "metadata.service": { $in: service } } : { "metadata.service": service }) : {},
queryFilter: FilterQuery<PresenceSchema> = query ? { "metadata.service": { $options: "i", $regex: query } } : {},
tagFilter: FilterQuery<PresenceSchema> = tag ? { "metadata.tags": tag } : {},
presences = await Presence.find({
...authorFilter,
...contributorFilter,
...serviceFilter,
...queryFilter,
...tagFilter,
}, Object.assign({}, ...Object.keys(parseResolveInfo(info)!.fieldsByTypeName.Presence!).map(fieldName => ({ [fieldName]: true }))) as Record<string, boolean>, { ...(limit ? { limit } : {}), ...(start ? { skip: start } : {}) });
return presences.map(presence => ({
iframeJs: presence.iframeJs,
metadata: presence.metadata,
presenceJs: presence.presenceJs,
url: presence.url,
users: 0,
}));
};
export default resolver;

View File

@@ -0,0 +1,10 @@
type Mutation {
addScience(identifier: String!, presences: [String], os: String, arch: String): AddScienceResult
}
type AddScienceResult {
identifier: String
presences: [String]
os: String
arch: String
}

View File

@@ -0,0 +1,21 @@
type Query {
"""
Get the available languages
"""
availableLanguages: [Language!]!
}
type Language {
"""
Language code
"""
lang: String!
"""
Native name of the language, eg. 'English', 'Deutsch', 'Español', etc.
"""
nativeName: String!
"""
'ltr' or 'rtl'
"""
direction: String!
}

View File

@@ -0,0 +1,22 @@
type Query {
"""
Get the available presence languages for a specific presence
"""
availablePresenceLanguages(
"""
Presence, e.g. 'Netflix'
"""
presence: StringOrStringArray
): [PresenceLanguage!]!
}
type PresenceLanguage {
"""
Presence, e.g. 'Netflix'
"""
presence: String!
"""
The available languages for the presence
"""
languages: [Language!]!
}

View File

@@ -0,0 +1,45 @@
type Mutation {
heartbeat(identifier: String!, presence: HeartbeatPresenceInput, extension: HeartbeatExtensionInput!): HeartbeatResult!
}
input HeartbeatPresenceInput {
service: String!
version: String!
language: String!
since: Float!
}
input HeartbeatExtensionInput {
version: String!
language: String!
connected: HeartbeatConnectedInput
}
input HeartbeatConnectedInput {
app: Int!
discord: Boolean!
}
type HeartbeatResult {
identifier: String!
presence: HeartbeatPresence
extension: HeartbeatExtension!
}
type HeartbeatPresence {
service: String!
version: String!
language: String!
since: Float!
}
type HeartbeatExtension {
version: String!
language: String!
connected: HeartbeatConnected
}
type HeartbeatConnected {
app: Int!
discord: Boolean!
}

View File

@@ -0,0 +1,54 @@
type Query {
presences(service: StringOrStringArray, author: String, contributor: String, start: Int, limit: Int, query: String, tag: String): [Presence!]!
}
type Presence {
url: String!
metadata: PresenceMetadata!
presenceJs: String!
iframeJs: String
users: Int!
}
type PresenceMetadata {
author: PresenceMetadataUser!
contributors: [PresenceMetadataUser!]
altnames: [String!]
service: String!
description: Scalar! # serialize
url: Scalar! # serialize
version: String!
logo: String!
thumbnail: String!
color: String!
tags: [String!]!
category: String!
iframe: Boolean
regExp: String
iFrameRegExp: String
readLogs: Boolean
button: Boolean
warning: Boolean
settings: [PresenceMetadataSettings!]
}
type PresenceMetadataUser {
id: String!
name: String!
}
type PresenceMetadataSettings {
id: String!
title: String
icon: String
if: PresenceMetadataSettingsIf # serialize
placeholder: String
value: Scalar # serialize
values: Scalar # serialize
multiLanguage: Scalar # serialize
}
type PresenceMetadataSettingsIf {
propertyNames: String
patternProperties: Scalar
}

View File

@@ -0,0 +1 @@
scalar Scalar

View File

@@ -0,0 +1 @@
scalar StringOrStringArray

20
apps/api/src/index.ts Normal file
View File

@@ -0,0 +1,20 @@
import "@sentry/tracing";
import Sentry from "@sentry/node";
import { connect } from "mongoose";
import createServer from "./functions/createServer.js";
// TODO SETUP SENTRY
Sentry.init({
integrations: [new Sentry.Integrations.GraphQL(), new Sentry.Integrations.Mongo({ useMongoose: true })],
});
if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is not set");
await connect(process.env.DATABASE_URL, { appName: "PreMiD API" });
const server = await createServer(),
url = await server.listen({ port: 3001 });
console.log(`Server listening at ${url}`);

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src/**/*"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"composite": true
}
}

8
apps/api/tsconfig.json Normal file
View File

@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.app.json",
"include": ["environment.d.ts", "src", "codegen.ts"],
"compilerOptions": {
"rootDir": ".",
"noEmit": true
}
}

View File

@@ -2,8 +2,8 @@ import { expect, test } from "vitest";
import createKeyv from "./createKeyv.js";
test("should return keyv instance", async () => {
const keyv = await createKeyv();
test("should return keyv instance", () => {
const keyv = createKeyv();
expect(keyv).toStrictEqual(expect.any(Object));
});

View File

@@ -3,7 +3,7 @@ import Keyv from "keyv";
import redis from "../redis.js";
export default async function createKeyv() {
export default function createKeyv() {
let options: Keyv.Options<string> | undefined;
/* c8 ignore next 8 */

View File

@@ -5,10 +5,10 @@ import { Redis } from "ioredis";
/* c8 ignore start */
export default function createRedis(): Redis {
const redis = new Redis({
connectionName: `pd-${hostname()}-${process.pid}`,
connectionName: `pd-${hostname()}-${process.pid.toString()}`,
lazyConnect: true,
name: "mymaster",
sentinels: process.env.REDIS_SENTINELS?.split(",")?.map(s => ({
sentinels: process.env.REDIS_SENTINELS?.split(",").map(s => ({
host: s,
port: 26_379,
})),

View File

@@ -1,7 +1,7 @@
import got from "got";
import { describe, expect, it, vi } from "vitest";
describe.concurrent("getGoogleAddresses", async () => {
describe.concurrent("getGoogleAddresses", () => {
it("should return an array of CIDR objects", async () => {
const { default: getGoogleAddresses } = await import("./getGoogleAddresses.js");

View File

@@ -4,7 +4,7 @@ import { CIDR } from "./isInCidRange.js";
export default async function getGoogleAddresses(): Promise<CIDR> {
const { body } = await got.get("https://www.gstatic.com/ipranges/cloud.json"),
result: GoogleResult = JSON.parse(body);
result = JSON.parse(body) as GoogleResult;
return result.prefixes.map(({ ipv4Prefix, ipv6Prefix }) => {
return ipv6Prefix ? { ipv6Prefix } : { ipv4Prefix };
});

View File

@@ -2,28 +2,28 @@ import { expect, test } from "vitest";
import isInCIDRRange from "./isInCidRange.js";
test("isInCIDRRange - IPv4 - in range", async () => {
test("isInCIDRRange - IPv4 - in range", () => {
const CIDRs = [{ ipv4Prefix: "192.0.2.0/24" }],
ip = "192.0.2.123",
result = isInCIDRRange(CIDRs, ip);
expect(result).toBe(true);
});
test("isInCIDRRange - IPv4 - not in range", async () => {
test("isInCIDRRange - IPv4 - not in range", () => {
const CIDRs = [{ ipv4Prefix: "192.0.2.0/24" }],
ip = "192.0.3.123",
result = isInCIDRRange(CIDRs, ip);
expect(result).toBe(false);
});
test("isInCIDRRange - IPv6 - in range", async () => {
test("isInCIDRRange - IPv6 - in range", () => {
const CIDRs = [{ ipv6Prefix: "2001:db8::/32" }],
ip = "2001:db8::1234",
result = isInCIDRRange(CIDRs, ip);
expect(result).toBe(true);
});
test("isInCIDRRange - IPv6 - not in range", async () => {
test("isInCIDRRange - IPv6 - not in range", () => {
const CIDRs = [{ ipv6Prefix: "2001:db8::/32" }],
ip = "2001:db9::1234",
result = isInCIDRRange(CIDRs, ip);

View File

@@ -1,3 +1,3 @@
import createKeyv from "./functions/createKeyv.js";
export default await createKeyv();
export default createKeyv();

View File

@@ -17,7 +17,7 @@ const handler: RouteHandlerMethod = async (request, reply) => {
if (!matches || matches.length === 0) return reply.status(400).send("Invalid base64 string");
const type = mime.extension(matches.at(1) as string);
const type = mime.extension(matches.at(1)!);
if (!type) return reply.status(400).send("Invalid base64 string");
@@ -27,8 +27,8 @@ const handler: RouteHandlerMethod = async (request, reply) => {
existingUrl = await keyv.get(hash);
if (existingUrl) {
reply.header("Cache-control", `public, max-age=${30 * 60}`);
return reply.send(process.env.BASE_URL + existingUrl);
void reply.header("Cache-control", `public, max-age=${(30 * 60).toString()}`);
return reply.send(process.env.BASE_URL! + existingUrl);
}
const uniqueId = `${nanoid(10)}.${type}`;
@@ -36,8 +36,8 @@ const handler: RouteHandlerMethod = async (request, reply) => {
await keyv.set(hash, uniqueId, 30 * 60 * 1000);
await keyv.set(uniqueId, body, 30 * 60 * 1000);
reply.header("Cache-control", `public, max-age=${30 * 60}`);
return reply.send(process.env.BASE_URL + uniqueId);
void reply.header("Cache-control", `public, max-age=${(30 * 60).toString()}`);
return reply.send(process.env.BASE_URL! + uniqueId);
};
export default handler;

View File

@@ -24,7 +24,7 @@ describe.concurrent("createFromImage", async () => {
});
afterAll(() => {
server.close();
void server.close();
});
it("should return a 400 when request is not multipart", async ({ expect }) => {

View File

@@ -32,8 +32,8 @@ const handler: RouteHandlerMethod = async (request, reply) => {
existingUrl = await keyv.get(hash);
if (existingUrl) {
reply.header("Cache-control", `public, max-age=${30 * 60}`);
return reply.send(process.env.BASE_URL + existingUrl);
void reply.header("Cache-control", `public, max-age=${(30 * 60).toString()}`);
return reply.send(process.env.BASE_URL! + existingUrl);
}
const uniqueId = `${nanoid(10)}.${type.ext}`;
@@ -43,8 +43,8 @@ const handler: RouteHandlerMethod = async (request, reply) => {
keyv.set(uniqueId, body, 30 * 60 * 1000),
]);
reply.header("Cache-control", `public, max-age=${30 * 60}`);
return reply.send(process.env.BASE_URL + uniqueId);
void reply.header("Cache-control", `public, max-age=${(30 * 60).toString()}`);
return reply.send(process.env.BASE_URL! + uniqueId);
};
export default handler;

View File

@@ -22,14 +22,14 @@ const handler: RouteHandlerMethod = async (request, reply) => {
if (existingShortenedUrl) {
await Promise.all([keyv.set(hash, existingShortenedUrl, 1800), keyv.set(existingShortenedUrl, url, 1800)]);
return reply.send(process.env.BASE_URL + existingShortenedUrl);
return reply.send(process.env.BASE_URL! + existingShortenedUrl);
}
const uniqueId = nanoid(10);
await Promise.all([keyv.set(hash, uniqueId, 1800), keyv.set(uniqueId, url, 1800)]);
return reply.send(process.env.BASE_URL + uniqueId);
return reply.send(process.env.BASE_URL! + uniqueId);
};
export default handler;

View File

@@ -7,7 +7,8 @@ import googleCIDRs from "../googleCIDRs.js";
import keyv from "../keyv.js";
const handler: RouteHandlerMethod = async (request, reply) => {
/* c8 ignore next 1 */
/* c8 ignore next 2 */
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const ip = request.headers["cf-connecting-ip"]?.toString() || request.socket.remoteAddress || request.ip;
if (
@@ -28,7 +29,7 @@ const handler: RouteHandlerMethod = async (request, reply) => {
const hash = crypto.createHash("sha256").update(url).digest("hex");
await Promise.all([keyv.set(hash, id, 30 * 60 * 1000), keyv.set(id, url, 30 * 60 * 1000)]);
reply.header("Cache-control", "public, max-age=1800");
void reply.header("Cache-control", "public, max-age=1800");
//* If it is not a base64 string, redirect to it
if (!url.startsWith("data:image")) return reply.redirect(url);

View File

@@ -0,0 +1,2 @@
rules:
no-console: off

View File

@@ -9,12 +9,13 @@ describe("schemas", () => {
const result = await app.inject({ url: "/" });
expect(result.statusCode).toBe(200);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
expect(result.json()).toEqual({ date: expect.any(String) });
});
test("/metadata/1.0 should return metadata schema", async () => {
const result = await app.inject({ url: "/metadata/1.0" }),
schema = await import(resolve(import.meta.dirname, "../schemas/metadata/1.0.json"));
schema = await import(resolve(import.meta.dirname, "../schemas/metadata/1.0.json")) as { default: Record<string, unknown> };
expect(result.statusCode).toBe(200);
expect(result.json()).toEqual(schema.default);
@@ -22,7 +23,7 @@ describe("schemas", () => {
test("/metadata/1.0 should return cached metadata schema", async () => {
const result = await app.inject({ url: "/metadata/1.0" }),
schema = await import(resolve(import.meta.dirname, "../schemas/metadata/1.0.json"));
schema = await import(resolve(import.meta.dirname, "../schemas/metadata/1.0.json")) as { default: Record<string, unknown> };
expect(result.statusCode).toBe(200);
expect(result.json()).toEqual(schema.default);

View File

@@ -6,7 +6,7 @@ import { globby } from "globby";
export const app = fastify();
app.register(helmet);
await app.register(helmet);
app.get("/", (_, reply) => reply.send({ date: new Date() }));
@@ -30,7 +30,7 @@ for (const schemaPath of await globby(resolve(import.meta.dirname, "../schemas/*
if (!schemaVersions)
schemaVersions = [];
const { default: content } = await import(schemaPath, { with: { type: "json" } });
const { default: content } = await import(schemaPath, { with: { type: "json" } }) as { default: Record<string, unknown> };
schemaVersions.push({
content,
version: version.replace(extname(version), ""),
@@ -52,7 +52,7 @@ app.get<versionRequest>("/:schemaName/:version", async (request, reply) => {
if (process.env.NODE_ENV !== "test") {
const url = await app.listen({
host: process.env.HOST ?? "0.0.0.0",
port: Number.parseInt(process.env.PORT || "80"),
port: Number.parseInt(process.env.PORT ?? "80"),
});
// eslint-disable-next-line no-console

17
eslint.config.js Normal file
View File

@@ -0,0 +1,17 @@
import config from "@recodive/eslint-config/strictFlat";
export default [
...config,
{
files: ["apps/pd/**/*", "apps/api/**/*"],
rules: {
"no-console": "off",
},
},
{
rules: {
//* See when not to use it
"@typescript-eslint/no-non-null-assertion": "off",
},
},
];

View File

@@ -5,8 +5,8 @@
"type": "module",
"scripts": {
"prepare": "husky",
"lint": "eslint . --ext .ts,.js && prettier --check .",
"lint:fix": "eslint . --ext .ts,.js --fix && prettier --write .",
"lint": "eslint . && prettier --check .",
"lint:fix": "eslint . --fix && prettier --write .",
"build": "pnpm clean && tsc -b tsconfig.app.json",
"build:watch": "pnpm clean && tsc -b tsconfig.app.json -w",
"clean": "tsc -b tsconfig.app.json --clean",
@@ -22,7 +22,7 @@
"devDependencies": {
"@commitlint/cli": "^18.6.0",
"@recodive/configs": "^1.7.5",
"@recodive/eslint-config": "^1.7.5",
"@recodive/eslint-config": "^1.8.4",
"@rushstack/eslint-patch": "^1.7.2",
"@types/node": "^20.11.17",
"@vitest/coverage-v8": "^1.2.2",

80
packages/db/lib/Presence.d.ts vendored Normal file
View File

@@ -0,0 +1,80 @@
/// <reference types="mongoose/types/aggregate.js" />
/// <reference types="mongoose/types/callback.js" />
/// <reference types="mongoose/types/collection.js" />
/// <reference types="mongoose/types/connection.js" />
/// <reference types="mongoose/types/cursor.js" />
/// <reference types="mongoose/types/document.js" />
/// <reference types="mongoose/types/error.js" />
/// <reference types="mongoose/types/expressions.js" />
/// <reference types="mongoose/types/helpers.js" />
/// <reference types="mongoose/types/middlewares.js" />
/// <reference types="mongoose/types/indexes.js" />
/// <reference types="mongoose/types/models.js" />
/// <reference types="mongoose/types/mongooseoptions.js" />
/// <reference types="mongoose/types/pipelinestage.js" />
/// <reference types="mongoose/types/populate.js" />
/// <reference types="mongoose/types/query.js" />
/// <reference types="mongoose/types/schemaoptions.js" />
/// <reference types="mongoose/types/schematypes.js" />
/// <reference types="mongoose/types/session.js" />
/// <reference types="mongoose/types/types.js" />
/// <reference types="mongoose/types/utility.js" />
/// <reference types="mongoose/types/validation.js" />
/// <reference types="mongoose/types/virtuals.js" />
/// <reference types="mongoose/types/inferschematype.js" />
import mongoose from "mongoose";
export interface PresenceSchema {
name: string;
url: string;
githubUrl: string;
folderName: string;
presenceJs: string;
iframeJs?: string;
metadata: PresenceMetadata;
}
export interface PresenceMetadata {
$schema: string;
altnames?: string[];
author: PresenceMetadataContributor;
category: PresenceMetadataCategory;
color: string;
contributors?: PresenceMetadataContributor[];
description: Record<string, string> & {
en: string;
};
iframe?: boolean;
iFrameRegExp?: string;
logo: string;
readLogs?: boolean;
regExp?: string;
service: string;
settings?: PresenceMetadataSetting[];
tags: string[];
thumbnail: string;
url: string | string[];
version: `${number}.${number}.${number}`;
}
export interface PresenceMetadataSetting {
icon?: string;
id: string;
if?: Record<string, unknown>;
multiLanguage?: boolean;
placeholder?: string;
title?: string;
value?: string | number | boolean;
values?: string[];
}
export interface PresenceMetadataContributor {
id: string;
name: string;
}
export type PresenceMetadataCategory = "other" | "games" | "videos" | "anime" | "music" | "socials";
declare const _default: mongoose.Model<PresenceSchema, {}, {}, {}, mongoose.Document<unknown, {}, PresenceSchema> & PresenceSchema & {
_id: mongoose.Types.ObjectId;
}, mongoose.Schema<PresenceSchema, mongoose.Model<PresenceSchema, any, any, any, mongoose.Document<unknown, any, PresenceSchema> & PresenceSchema & {
_id: mongoose.Types.ObjectId;
}, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, PresenceSchema, mongoose.Document<unknown, {}, mongoose.FlatRecord<PresenceSchema>> & mongoose.FlatRecord<PresenceSchema> & {
_id: mongoose.Types.ObjectId;
}>>;
export default _default;
//# sourceMappingURL=Presence.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Presence.d.ts","sourceRoot":"","sources":["../src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,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE;IACvC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;CACzC,CAAC,EACF,cAAc,GAAG,IAAI,MAAM,CAAiB;IAC3C,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5C,SAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;IAC3C,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,sBAAsB,EAAE;IAC1D,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;IACtC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;CACrC,CAAC,CAAC;AAEJ,eAAe,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC"}

2
packages/db/lib/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export { default as Presence } from "./Presence.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC"}

18
packages/db/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "@premid/db",
"version": "1.0.0",
"type": "module",
"dependencies": {
"mongoose": "^8.2.0"
},
"files": [
"lib"
],
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/index.js"
},
"./*": "./lib/*"
}
}

View File

@@ -0,0 +1,96 @@
import mongoose, { Schema } from "mongoose";
export interface PresenceSchema {
name: string;
url: string;
githubUrl: string;
folderName: string;
presenceJs: string;
iframeJs?: string;
metadata: PresenceMetadata;
}
export interface PresenceMetadata {
$schema: string;
altnames?: string[];
author: PresenceMetadataContributor;
category: PresenceMetadataCategory;
color: string;
contributors?: PresenceMetadataContributor[];
description: Record<string, string> & { en: string };
iframe?: boolean;
iFrameRegExp?: string;
logo: string;
readLogs?: boolean;
regExp?: string;
service: string;
settings?: PresenceMetadataSetting[];
tags: string[];
thumbnail: string;
url: string | string[];
version: `${number}.${number}.${number}`;
}
export interface PresenceMetadataSetting {
icon?: string;
id: string;
if?: Record<string, unknown>;
multiLanguage?: boolean;
placeholder?: string;
title?: string;
value?: string | number | boolean;
values?: string[];
}
export interface PresenceMetadataContributor {
id: string;
name: string;
}
export type PresenceMetadataCategory = "other" | "games" | "videos" | "anime" | "music" | "socials";
const PresenceMetadataContributorSchema = new Schema<PresenceMetadataContributor>({
id: { required: true, type: String },
name: { required: true, type: String },
}),
PresenceMetadataSettingSchema = new Schema<PresenceMetadataSetting>({
icon: { type: String },
id: { required: true, type: String },
if: { type: Schema.Types.Mixed },
multiLanguage: { type: Boolean },
placeholder: { type: String },
title: { type: String },
value: Schema.Types.Mixed,
values: { type: [String] },
}),
PresenceMetadataSchema = new Schema<PresenceMetadata>({
$schema: { required: true, type: String },
altnames: { type: [String] },
author: { required: true, type: PresenceMetadataContributorSchema },
category: { required: true, type: String },
color: { required: true, type: String },
contributors: { type: [PresenceMetadataContributorSchema] },
description: { required: true, type: Schema.Types.Mixed },
iFrameRegExp: { type: String },
iframe: { type: Boolean },
logo: { required: true, type: String },
readLogs: { type: Boolean },
regExp: { type: String },
service: { required: true, type: String },
settings: { type: [PresenceMetadataSettingSchema] },
tags: { required: true, type: [String] },
thumbnail: { required: true, type: String },
url: { required: true, type: [String] },
version: { required: true, type: String },
}),
presenceSchema = new Schema<PresenceSchema>({
folderName: { required: true, type: String },
githubUrl: { required: true, type: String },
iframeJs: { type: String },
metadata: { required: true, type: PresenceMetadataSchema },
name: { required: true, type: String },
presenceJs: { required: true, type: String },
url: { required: true, type: String },
});
export default mongoose.model("Presence", presenceSchema);

1
packages/db/src/index.ts Normal file
View File

@@ -0,0 +1 @@
export { default as Presence } from "./Presence.js";

View File

@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"composite": true
}
}

3370
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,3 @@
packages:
- apps/*
- packages/*

View File

@@ -1,11 +1,17 @@
{
"files": [],
"references": [
{
"path": "./packages/db/tsconfig.build.json"
},
{
"path": "./apps/pd/tsconfig.app.json"
},
{
"path": "./apps/schema-server/tsconfig.app.json"
},
{
"path": "./apps/api/tsconfig.app.json"
}
]
}

View File

@@ -13,6 +13,7 @@
/* Strictness */
"strict": true,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
/* If transpiling with TypeScript: */

View File

@@ -2,6 +2,6 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"types": ["vitest"]
"types": ["@types/node", "vitest"]
}
}

View File

@@ -5,7 +5,7 @@ export default defineConfig({
coverage: {
all: true,
enabled: true,
exclude: [...configDefaults.coverage.exclude ?? [], "commitlint.config.cjs"],
exclude: [...configDefaults.coverage.exclude ?? [], "commitlint.config.cjs", "**/generated/**", "**/codegen.ts", "**/lib/**"],
reportOnFailure: true,
skipFull: true,
thresholds: {