Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to module packaging #3

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/rest-api-core",
"version": "0.2.1-7",
"version": "0.2.1-8",
"repository": {
"type": "git",
"url": "git+https://github.com/logion-network/logion-rest-api-core.git"
Expand All @@ -19,14 +19,14 @@
"scripts": {
"build": "rimraf dist && yarn lint && tsc --project ./tsconfig.json",
"lint": "yarn eslint src/**",
"test": "jasmine --config=jasmine.json",
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
"integration-test": "yarn run setup-test-db && jasmine --config=jasmine-integration.json ; yarn run teardown-test-db",
"setup-test-db": "docker run -d --rm --name logion-test-db -e POSTGRES_PASSWORD=secret -p 5432:5432 logionnetwork/logion-postgres:latest",
"teardown-test-db": "docker stop logion-test-db",
"coverage": "nyc yarn run test"
},
"dependencies": {
"@logion/authenticator": "^0.3.3-1",
"@logion/authenticator": "^0.3.3-6",
"dinoloop": "^2.4.0",
"express": "^4.18.2",
"express-fileupload": "^1.4.0",
Expand Down Expand Up @@ -64,10 +64,6 @@
"engines": {
"node": ">=16"
},
"resolutions": {
"moq.ts": "9.0.2",
"node-fetch": "2.6.7",
"openapi-typescript": "5.1.0"
},
"packageManager": "yarn@3.2.3"
"packageManager": "yarn@3.2.3",
"type": "module"
}
4 changes: 2 additions & 2 deletions src/ApplicationErrorController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { injectable } from 'inversify';
import { ErrorController } from 'dinoloop';

import { Log } from "./Logging";
import { errorPayload } from './Errors';
import { Log } from "./Logging.js";
import { errorPayload } from './Errors.js';

const { logger } = Log;

Expand Down
14 changes: 7 additions & 7 deletions src/AuthenticationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { OpenAPIV3 } from "express-oas-generator";
import { injectable } from "inversify";
import { DateTime } from "luxon";

import { AuthenticationService } from "./AuthenticationService";
import { SessionRepository, SessionFactory } from "./SessionServices";
import { requireDefined } from "./Assertions";
import { AuthenticationService } from "./AuthenticationService.js";
import { SessionRepository, SessionFactory } from "./SessionServices.js";
import { requireDefined } from "./Assertions.js";
import {
getRequestBody,
getBodyContent,
getDefaultResponses,
setPathParameters,
addTag,
setControllerTag
} from "./OpenApi";
import { unauthorized } from "./AuthenticationSystemFactory";
import { AuthenticateRequestView, AuthenticateResponseView, RefreshRequestView, SignInRequestView, SignInResponseView, TokenView } from "./ApiTypes";
} from "./OpenApi.js";
import { unauthorized } from "./AuthenticationSystemFactory.js";
import { AuthenticateRequestView, AuthenticateResponseView, RefreshRequestView, SignInRequestView, SignInResponseView, TokenView } from "./ApiTypes.js";

import { Log } from './Logging';
import { Log } from './Logging.js';
const { logger } = Log;

export function fillInSpecForAuthenticationController(spec: OpenAPIV3.Document): void {
Expand Down
4 changes: 2 additions & 2 deletions src/AuthenticationService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AuthenticatedUser, AuthenticationSystem } from "@logion/authenticator";
import { injectable } from "inversify";
import { Request } from "express";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions";
import { AuthenticationSystemFactory, unauthorized } from "./AuthenticationSystemFactory";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions.js";
import { AuthenticationSystemFactory, unauthorized } from "./AuthenticationSystemFactory.js";

@injectable()
export class AuthenticationService {
Expand Down
2 changes: 1 addition & 1 deletion src/AuthenticationSystemFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { injectable } from "inversify";
import { Duration } from "luxon";
import PeerId from "peer-id";

import { PolkadotService } from "./PolkadotService";
import { PolkadotService } from "./PolkadotService.js";

export function unauthorized(error: string): UnauthorizedException<{ error: string }> {
return new UnauthorizedException({ error });
Expand Down
22 changes: 11 additions & 11 deletions src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import "./inversify.decorate";
import "./inversify.decorate.js";
import { OpenAPIV3 } from 'express-oas-generator';
import { Container } from 'inversify';
import { schemas } from './ApiTypes';
import { AuthenticationController, fillInSpecForAuthenticationController } from './AuthenticationController';
import { AuthenticationService } from './AuthenticationService';
import { AuthenticationSystemFactory } from './AuthenticationSystemFactory';
import { addSchema } from './OpenApi';
import { SessionFactory, SessionRepository } from './SessionServices';
import { schemas } from './ApiTypes.js';
import { AuthenticationController, fillInSpecForAuthenticationController } from './AuthenticationController.js';
import { AuthenticationService } from './AuthenticationService.js';
import { AuthenticationSystemFactory } from './AuthenticationSystemFactory.js';
import { addSchema } from './OpenApi.js';
import { SessionFactory, SessionRepository } from './SessionServices.js';
import { Dino } from "dinoloop";
import { ApplicationErrorController } from "./ApplicationErrorController";
import { JsonResponse } from "./JsonResponse";
import { PolkadotService } from "./PolkadotService";
import { fillInSpecForHealthController, HealthController } from "./HealthController";
import { ApplicationErrorController } from "./ApplicationErrorController.js";
import { JsonResponse } from "./JsonResponse.js";
import { PolkadotService } from "./PolkadotService.js";
import { fillInSpecForHealthController, HealthController } from "./HealthController.js";

export function configureContainer(container: Container) {
container.bind(SessionRepository).toSelf();
Expand Down
6 changes: 3 additions & 3 deletions src/DataSourceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { addTransactionalDataSource, deleteDataSourceByName, initializeTransacti
import dotenv from "dotenv";
import { existsSync, readFileSync } from "fs";

import { LogionNamingStrategy } from "./LogionNamingStrategy";
import { SessionAggregateRoot } from "./SessionEntity";
import { WrapInTransactionOptions } from "typeorm-transactional/dist/transactions/wrap-in-transaction";
import { LogionNamingStrategy } from "./LogionNamingStrategy.js";
import { SessionAggregateRoot } from "./SessionEntity.js";
import { WrapInTransactionOptions } from "typeorm-transactional/dist/transactions/wrap-in-transaction.js";

dotenv.config();

Expand Down
2 changes: 1 addition & 1 deletion src/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadRequestException, ForbiddenException } from "dinoloop/modules/builtin/exceptions/exceptions";
import { BadRequestException, ForbiddenException } from "dinoloop/modules/builtin/exceptions/exceptions.js";

export function badRequest(error: string): Error {
return new BadRequestException(errorPayload(
Expand Down
6 changes: 3 additions & 3 deletions src/HealthController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { injectable } from 'inversify';
import { ApiController, Controller, Async, HttpGet } from 'dinoloop';
import { OpenAPIV3 } from 'express-oas-generator';
import { addTag, getDefaultResponses, setControllerTag } from './OpenApi';
import { AuthenticationService } from './AuthenticationService';
import { requireDefined } from './Assertions';
import { addTag, getDefaultResponses, setControllerTag } from './OpenApi.js';
import { AuthenticationService } from './AuthenticationService.js';
import { requireDefined } from './Assertions.js';

export function fillInSpecForHealthController(spec: OpenAPIV3.Document): void {
const tagName = 'Health';
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPIV3 } from 'express-oas-generator';
import fs from "fs";
import openapiTS from "openapi-typescript";
import { requireDefined } from './Assertions';
import { requireDefined } from './Assertions.js';

export function setOpenApi3(spec: OpenAPIV3.Document) {
spec.openapi = "3.0.0";
Expand Down
6 changes: 3 additions & 3 deletions src/SessionServices.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Repository } from "typeorm";
import { injectable } from "inversify";

import { appDataSource } from "./DataSourceProvider";
import { appDataSource } from "./DataSourceProvider.js";
import { DateTime } from "luxon";
import { requireDefined } from "./Assertions";
import { SessionAggregateRoot } from "./SessionEntity";
import { requireDefined } from "./Assertions.js";
import { SessionAggregateRoot } from "./SessionEntity.js";

@injectable()
export class SessionRepository {
Expand Down
12 changes: 6 additions & 6 deletions src/TestApp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./inversify.decorate";
import "./inversify.decorate.js";
import { DateTime } from "luxon";
import {
AuthenticatedUser,
Expand All @@ -10,12 +10,12 @@ import {
import express, { Express } from 'express';
import { Dino } from 'dinoloop';
import { Container } from 'inversify';
import { ApplicationErrorController } from './ApplicationErrorController';
import { JsonResponse } from './JsonResponse';
import { ApplicationErrorController } from './ApplicationErrorController.js';
import { JsonResponse } from './JsonResponse.js';
import { Mock } from "moq.ts";
import { AuthenticationService } from "./AuthenticationService";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions";
import { buildBaseExpress } from "./Express";
import { AuthenticationService } from "./AuthenticationService.js";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions.js";
import { buildBaseExpress } from "./Express.js";

export const ALICE = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
export const BOB = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty";
Expand Down
4 changes: 2 additions & 2 deletions src/TestDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'reflect-metadata';
import fs from 'fs';
import { QueryRunner, MigrationInterface, DataSource } from "typeorm";

import { overrideDataSource } from './DataSourceProvider';
import { requireDefined } from './Assertions';
import { overrideDataSource } from './DataSourceProvider.js';
import { requireDefined } from './Assertions.js';

export async function connect(
entities: (Function | string)[], // eslint-disable-line @typescript-eslint/ban-types
Expand Down
36 changes: 18 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export * from "./ApiTypes";
export * from "./Assertions";
export * from "./AuthenticationController";
export * from "./AuthenticationService";
export * from "./AuthenticationSystemFactory";
export * from "./Config";
export * from "./DataSourceProvider";
export * from "./Errors";
export * from "./Express";
export * from "./HealthController";
export * from "./Logging";
export * from "./LogionNamingStrategy";
export * from "./OpenApi";
export * from "./PolkadotService";
export * from "./SessionEntity";
export * from "./SessionServices";
export * as TestApp from "./TestApp";
export * as TestDb from "./TestDb";
export * from "./ApiTypes.js";
export * from "./Assertions.js";
export * from "./AuthenticationController.js";
export * from "./AuthenticationService.js";
export * from "./AuthenticationSystemFactory.js";
export * from "./Config.js";
export * from "./DataSourceProvider.js";
export * from "./Errors.js";
export * from "./Express.js";
export * from "./HealthController.js";
export * from "./Logging.js";
export * from "./LogionNamingStrategy.js";
export * from "./OpenApi.js";
export * from "./PolkadotService.js";
export * from "./SessionEntity.js";
export * from "./SessionServices.js";
export * as TestApp from "./TestApp.js";
export * as TestDb from "./TestDb.js";
4 changes: 2 additions & 2 deletions test/AuthenticationController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
SessionAggregateRoot,
NewSessionParameters,
AuthenticateRequestView,
} from "../src";
} from "../src/index.js";

import {
setupApp,
ALICE,
BOB,
} from "../src/TestApp";
} from "../src/TestApp.js";

const TIMESTAMP = "2021-06-10T16:25:23.668294";
const TOKEN_ALICE = "some-fake-token-for-ALICE";
Expand Down
4 changes: 2 additions & 2 deletions test/AuthenticationService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AuthenticatedUser, AuthenticationSystem, Authenticator } from "@logion/authenticator";
import { Mock } from "moq.ts";
import { Request } from "express";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions";
import { UnauthorizedException } from "dinoloop/modules/builtin/exceptions/exceptions.js";

import { AuthenticationService, AuthenticationSystemFactory } from "../src";
import { AuthenticationService, AuthenticationSystemFactory } from "../src/index.js";

const USER_TOKEN = "eyJhbGciOiJFZERTQSJ9.eyJpYXQiOjE2MzEyMTc2MTEsImV4cCI6NDc4NDgxNzYxMSwiaXNzIjoiMTJEM0tvb1dEQ3VHVTdXWTNWYVdqQlMxRTQ0eDRFbm1UZ0szSFJ4V0ZxWUczZHFYRGZQMSIsInN1YiI6IjVINE12QXNvYmZaNmJCQ0R5ajVkc3JXWUxyQThIclJ6YXFhOXA2MVVYdHhNaFNDWSJ9.pBYUyYxq2I_HZiYyeJ-rc8ANxVgckLyd2Y1Snu685mDK4fSwanb6EHsMAP47iCtzSxhaB5bDu7zDmY-XMAyuAw"
const USER_ADDRESS = "5H4MvAsobfZ6bBCDyj5dsrWYLrA8HrRzaqa9p61UXtxMhSCY"
Expand Down
4 changes: 2 additions & 2 deletions test/HealthController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import request from 'supertest';
import { Container } from "inversify";
import { Mock } from "moq.ts";

import { setupApp, mockAuthenticationWithCondition } from "../src/TestApp";
import { HealthController, HealthService } from "../src/HealthController";
import { setupApp, mockAuthenticationWithCondition } from "../src/TestApp.js";
import { HealthController, HealthService } from "../src/HealthController.js";

describe('HealthController', () => {

Expand Down
4 changes: 2 additions & 2 deletions test/Session.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DateTime } from "luxon";
import { v4 as uuid } from "uuid";

import { SessionFactory, SessionAggregateRoot, NewSessionParameters } from "../src";
import { ALICE } from "../src/TestApp";
import { SessionFactory, SessionAggregateRoot, NewSessionParameters } from "../src/index.js";
import { ALICE } from "../src/TestApp.js";

describe("SessionFactory", () => {

Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"compilerOptions": {
"module": "es2020",
"target": "es2020",
"outDir": "dist",
"baseUrl": ".",
"declaration": true,
Expand Down
4 changes: 2 additions & 2 deletions typescript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { register } = require('ts-node')
import { register } from 'ts-node';

register({
project: 'tsconfig.json',
})
});
Loading