metamigo-api: runs in docker now

* great typescript module import refactor
* refactor metamigo-cli so it is the entrypoint for the db, api, and
  worker
This commit is contained in:
Abel Luck 2023-06-02 14:05:20 +00:00
parent b45e2e8c11
commit 696ba16cb7
78 changed files with 319 additions and 180 deletions

View file

@ -3,6 +3,7 @@
"version": "0.2.0",
"description": "",
"main": "build/main/index.js",
"type": "module",
"types": "build/main/index.d.ts",
"author": "Abel Luck <abel@guardianproject.info>",
"license": "AGPL-3.0-or-later",

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface IAppMetaConfig {
name: string;

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface ISessionConfig {
sessionMaxAgeSeconds: number;

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface ICorsConfig {
allowedMethods: Array<string>;

View file

@ -1,4 +1,4 @@
import * as Joi from "joi";
import Joi from "joi";
import type { Format } from "convict";
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -1,12 +1,12 @@
import process from "node:process";
import convict, { SchemaObj } from "convict";
import { IServerConfig, ServerConfig } from "./server";
import { IMetricsConfig, MetricsConfig } from "./metrics-server";
import { IAppMetaConfig, AppMetaConfig } from "./app-meta";
import { ICorsConfig, CorsConfig } from "./cors";
import { ILoggingConfig, LoggingConfig } from "./logging";
import { ExtendedConvict } from "./types";
import { MetamigoConvictFormats } from "./formats";
import { IServerConfig, ServerConfig } from "./server.js";
import { IMetricsConfig, MetricsConfig } from "./metrics-server.js";
import { IAppMetaConfig, AppMetaConfig } from "./app-meta.js";
import { ICorsConfig, CorsConfig } from "./cors.js";
import { ILoggingConfig, LoggingConfig } from "./logging.js";
import { ExtendedConvict } from "./types.js";
import { MetamigoConvictFormats } from "./formats.js";
type IEnvConfig = "production" | "development" | "test";
@ -51,10 +51,10 @@ export type IMetamigoConvict = ExtendedConvict<IMetamigoConfig>;
export type { IMetamigoConfig };
export * from "./formats";
export * from "./generate";
export * from "./print";
export * from "./types";
export * from "./formats.js";
export * from "./generate.js";
export * from "./print.js";
export * from "./types.js";
/**
* Loads your applications configuration from environment variables and configuration files (see METAMIGO_CONFIG).
@ -137,8 +137,8 @@ export const loadConfiguration = async <T extends IMetamigoConfig>(
return c.getProperties();
};
export { type IServerConfig } from "./server";
export { type IMetricsConfig } from "./metrics-server";
export { type IAppMetaConfig } from "./app-meta";
export { type ICorsConfig } from "./cors";
export { type ILoggingConfig } from "./logging";
export { type IServerConfig } from "./server.js";
export { type IMetricsConfig } from "./metrics-server.js";
export { type IAppMetaConfig } from "./app-meta.js";
export { type ICorsConfig } from "./cors.js";
export { type ILoggingConfig } from "./logging.js";

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface ILoggingConfig {
level: string;

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface IMetricsConfig {
address: string;

View file

@ -1,4 +1,4 @@
import { ConvictSchema } from "./types";
import { ConvictSchema } from "./types.js";
export interface IServerConfig {
address: string;

View file

@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any,max-params */
import * as Boom from "@hapi/boom";
import * as Hapi from "@hapi/hapi";
import { CrudRepository } from "../records/crud-repository";
import { createResponse } from "../helpers/response";
import { CrudRepository } from "../records/crud-repository.js";
import { createResponse } from "../helpers/response.js";
import {
PgRecordInfo,
UnsavedR,
SavedR,
KeyType,
} from "../records/record-info";
} from "../records/record-info.js";
/**
*

View file

@ -1,10 +1,10 @@
/* eslint-disable unicorn/no-null,max-params */
import { createHash, randomBytes } from "node:crypto";
import omit from "lodash/omit";
import type { IMetamigoRepositories } from "../records";
import type { UnsavedAccount } from "../records/account";
import type { UserId, UnsavedUser, SavedUser } from "../records/user";
import type { UnsavedSession, SavedSession } from "../records/session";
import omit from "lodash/omit.js";
import type { IMetamigoRepositories } from "../records/index.js";
import type { UnsavedAccount } from "../records/account.js";
import type { UserId, UnsavedUser, SavedUser } from "../records/user.js";
import type { UnsavedSession, SavedSession } from "../records/session.js";
// Sessions expire after 30 days of being idle
export const defaultSessionMaxAge = 30 * 24 * 60 * 60 * 1000;

View file

@ -8,11 +8,11 @@ import PinoPlugin from "hapi-pino";
import { createServer as createPrometheusServer } from "@promster/server";
import { createHttpTerminator } from "http-terminator";
import { getPrettyPrint } from "./logger";
import RequestIdPlugin from "./plugins/request-id";
import StatusPlugin from "./plugins/status";
import ConfigPlugin from "./plugins/config";
import { IMetamigoConfig } from "./config";
import { getPrettyPrint } from "./logger.js";
import RequestIdPlugin from "./plugins/request-id.js";
import StatusPlugin from "./plugins/status.js";
import ConfigPlugin from "./plugins/config.js";
import { IMetamigoConfig } from "./config/index.js";
export interface Server {
hapiServer: Hapi.Server;

View file

@ -1,7 +1,7 @@
import process from "node:process";
import * as Hapi from "@hapi/hapi";
import * as Joi from "joi";
import Hoek from "@hapi/hoek";
import Joi from "joi";
import * as Hoek from "@hapi/hoek";
import * as Boom from "@hapi/boom";
export interface HapiValidationError extends Joi.ValidationError {

View file

@ -1,12 +1,12 @@
export * from "./config";
export * from "./controllers/crud-controller";
export * from "./controllers/nextauth-adapter";
export * from "./hapi";
export * from "./helpers";
export * from "./helpers/response";
export * from "./helpers/validation-error";
export * from "./logger";
export * from "./records";
export * from "./config/index.js";
export * from "./controllers/crud-controller.js";
export * from "./controllers/nextauth-adapter.js";
export * from "./hapi.js";
export * from "./helpers/index.js";
export * from "./helpers/response.js";
export * from "./helpers/validation-error.js";
export * from "./logger.js";
export * from "./records/index.js";
import * as pino from "pino";

View file

@ -1,5 +1,5 @@
import pino, { LoggerOptions } from "pino";
import { IMetamigoConfig } from "./config";
import { IMetamigoConfig } from "./config/index.js";
export const getPrettyPrint = <T extends IMetamigoConfig>(
config: T

View file

@ -1,6 +1,6 @@
import { Server } from "@hapi/hapi";
import cloneDeep from "lodash/cloneDeep";
import { deepFreeze } from "../helpers";
import cloneDeep from "lodash/cloneDeep.js";
import { deepFreeze } from "../helpers/index.js";
interface ConfigOptions {
config: unknown;

View file

@ -1,7 +1,7 @@
import { recordInfo } from "./record-info";
import { RepositoryBase } from "./base";
import { recordInfo } from "./record-info.js";
import { RepositoryBase } from "./base.js";
import { Flavor, UUID } from "../helpers";
import { UserId } from "./user";
import { UserId } from "./user.js";
export type AccountId = Flavor<UUID, "Account Id">;

View file

@ -1,7 +1,7 @@
import { TableName } from "pg-promise";
import { IMain } from "../db/types";
import { CrudRepository } from "./crud-repository";
import { PgRecordInfo, UnsavedR, SavedR, KeyType } from "./record-info";
import { IMain } from "../db/types.js";
import { CrudRepository } from "./crud-repository.js";
import { PgRecordInfo, UnsavedR, SavedR, KeyType } from "./record-info.js";
import type { IDatabase } from "pg-promise";
export type PgProtocol<T> = IDatabase<T> & T;

View file

@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { TableName } from "pg-promise";
import decamelcaseKeys from "decamelcase-keys";
import isObject from "lodash/isObject";
import isArray from "lodash/isArray";
import zipObject from "lodash/zipObject";
import isEmpty from "lodash/isEmpty";
import omit from "lodash/omit";
import { IDatabase, IMain, IResult } from "../db/types";
import { PgRecordInfo, idKeysOf } from "./record-info";
import isObject from "lodash/isObject.js";
import isArray from "lodash/isArray.js";
import zipObject from "lodash/zipObject.js";
import isEmpty from "lodash/isEmpty.js";
import omit from "lodash/omit.js";
import { IDatabase, IMain, IResult } from "../db/types.js";
import { PgRecordInfo, idKeysOf } from "./record-info.js";
export interface ICrudRepository<
TUnsavedR,

View file

@ -1,13 +1,13 @@
export * from "./base";
export * from "./record-info";
export * from "./crud-repository";
export * from "./user";
export * from "./session";
export * from "./account";
export * from "./base.js";
export * from "./record-info.js";
export * from "./crud-repository.js";
export * from "./user.js";
export * from "./session.js";
export * from "./account.js";
import type { AccountRecordRepository } from "./account";
import type { UserRecordRepository } from "./user";
import type { SessionRecordRepository } from "./session";
import type { AccountRecordRepository } from "./account.js";
import type { UserRecordRepository } from "./user.js";
import type { SessionRecordRepository } from "./session.js";
export interface IMetamigoRepositories {
users: UserRecordRepository;

View file

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import at from "lodash/at";
import pick from "lodash/pick";
import at from "lodash/at.js";
import pick from "lodash/pick.js";
export interface EntityType<
TUnsaved = any,

View file

@ -1,7 +1,7 @@
import { recordInfo } from "./record-info";
import { RepositoryBase } from "./base";
import { recordInfo } from "./record-info.js";
import { RepositoryBase } from "./base.js";
import { Flavor, UUID } from "../helpers";
import { UserId } from "./user";
import { UserId } from "./user.js";
export type SessionId = Flavor<UUID, "Session Id">;

View file

@ -1,5 +1,5 @@
import { recordInfo } from "./record-info";
import { RepositoryBase } from "./base";
import { recordInfo } from "./record-info.js";
import { RepositoryBase } from "./base.js";
import { Flavor, UUID } from "../helpers";
export type UserId = Flavor<UUID, "User Id">;