From 0540d03df103558bd6d1d5cd2d95f1bb9564977a Mon Sep 17 00:00:00 2001 From: Johan Date: Sun, 19 May 2024 23:15:55 +0200 Subject: [PATCH] to ESM --- .github/workflows/publish.yml | 2 +- .gitignore | 3 +- jest.config.js | 6 +++- package.json | 3 +- src/app.ts | 8 ++--- src/index.ts | 4 +-- src/lib/database/connection.ts | 2 +- src/lib/database/index.ts | 4 +-- src/lib/exec.ts | 20 +++++------ src/lib/graphql/index.ts | 8 ++--- src/lib/graphql/mutate-factory.ts | 16 ++++----- src/lib/graphql/query-factory.ts | 14 ++++---- src/lib/graphql/schema-factory.ts | 14 ++++---- src/lib/graphql/schema.ts | 10 +++--- src/lib/graphql/submodel.test.ts | 4 +-- src/lib/graphql/submodel.ts | 4 +-- src/lib/graphql/type-factory.test.ts | 6 ++-- src/lib/graphql/type-factory.ts | 6 ++-- src/lib/graphql/type.ts | 2 +- src/lib/graphql/utils-mapping.ts | 6 ++-- src/lib/graphql/utils-string.test.ts | 6 ++-- src/lib/graphql/utils-string.ts | 6 ++-- src/lib/graphql/utils.ts | 4 +-- src/lib/index.ts | 16 ++++----- src/lib/main.ts | 14 ++++---- src/lib/migrations/index.test.ts | 2 +- src/lib/migrations/index.ts | 6 ++-- src/lib/migrations/migrations.ts | 4 +-- src/lib/migrations/utils.test.ts | 2 +- src/lib/migrations/utils.ts | 10 +++--- src/lib/model/index.ts | 2 +- src/lib/model/utils.ts | 4 +-- src/lib/query-builder/aggregate/index.test.ts | 6 ++-- src/lib/query-builder/aggregate/index.ts | 12 +++---- src/lib/query-builder/aggregate/type.ts | 2 +- src/lib/query-builder/aggregate/utils.test.ts | 2 +- src/lib/query-builder/aggregate/utils.ts | 6 ++-- src/lib/query-builder/index.ts | 14 ++++---- src/lib/query-builder/legacy.test.ts | 4 +-- src/lib/query-builder/legacy.ts | 4 +-- .../query-builder/meta-multiple-joins.test.ts | 8 ++--- src/lib/query-builder/meta-operator.test.ts | 8 ++--- src/lib/query-builder/meta.test.ts | 12 +++---- src/lib/query-builder/meta.ts | 12 +++---- src/lib/query-builder/meta2.test.ts | 8 ++--- src/lib/query-builder/meta3.test.ts | 6 ++-- src/lib/query-builder/model-academy.ts | 2 +- src/lib/query-builder/mutate.test.ts | 8 ++--- src/lib/query-builder/mutate.ts | 10 +++--- src/lib/query-builder/parse-mutate.test.ts | 2 +- src/lib/query-builder/parse-mutate.ts | 6 ++-- src/lib/query-builder/parse.ts | 8 ++--- src/lib/query-builder/parse2.test.ts | 4 +-- src/lib/query-builder/references.test.ts | 6 ++-- src/lib/query-builder/references.ts | 12 +++---- src/lib/query-builder/sql.ts | 8 ++--- src/lib/query-builder/type.ts | 2 +- src/lib/query-builder/utils.test.ts | 4 +-- src/lib/query-builder/utils.ts | 8 ++--- .../query-service/abstract-service-wdata.ts | 20 +++++------ src/lib/query-service/abstract-service.ts | 2 +- src/lib/query-service/aggregate-type.ts | 2 +- .../constraint/default-constraints.ts | 6 ++-- src/lib/query-service/constraint/exclude.ts | 2 +- src/lib/query-service/constraint/index.ts | 6 ++-- .../constraint/query-builder/data.test.ts | 6 ++-- .../constraint/query-builder/data.ts | 4 +-- .../constraint/query-builder/index.ts | 4 +-- .../constraint/query-builder/mutate.test.ts | 2 +- .../constraint/query-builder/mutate.ts | 6 ++-- .../constraint/query-builder/utils.test.ts | 2 +- src/lib/query-service/constraint/type.ts | 2 +- .../query-service/constraint/utils.test.ts | 2 +- src/lib/query-service/constraint/utils.ts | 4 +-- src/lib/query-service/index.ts | 4 +-- src/lib/query-service/service-external.ts | 8 ++--- src/lib/query-service/service.ts | 8 ++--- src/lib/query-service/utils.ts | 2 +- src/lib/utils.test.ts | 2 +- src/lib/utils.ts | 2 +- src/middleware/index.test.ts | 4 +-- src/middleware/index.ts | 2 +- src/routes/database.ts | 4 +-- src/routes/graphql.ts | 10 +++--- src/routes/main.ts | 12 +++---- src/routes/model.ts | 4 +-- src/service/database/index.ts | 6 ++-- src/service/model/index.ts | 6 ++-- tsconfig.package.json | 34 +++++++++---------- 89 files changed, 292 insertions(+), 288 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 847ea60..e7f5e74 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: node-version: 20 - run: yarn - run: yarn test - - run: yarn buildpackage + - run: yarn buildPackage - name: Publish package run: | echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc diff --git a/.gitignore b/.gitignore index 85d7da5..b442b96 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ dist/ node_modules/ assets/ -src/index-standalone.ts \ No newline at end of file +src/index-standalone.ts +index.js \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index a93551f..acf9c56 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,8 @@ -module.exports = { +export default { + extensionsToTreatAsEsm: [".ts"], preset: "ts-jest", testEnvironment: "node", + moduleNameMapper: { + "^(\\.\\.?\\/.+)\\.js?$": "$1", + }, }; diff --git a/package.json b/package.json index ba467d9..40ad9ed 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "@nexys/fetchr", + "type": "module", "version": "0.13.0", "license": "AGPL-3.0-or-later", "main": "dist/index.js", @@ -45,7 +46,7 @@ "scripts": { "start": "node dist/index.js", "build": "tsc", - "buildpackage": "rm -rf ./dist;tsc -p tsconfig.package.json", + "buildPackage": "rm -rf ./dist;tsc -p tsconfig.package.json", "test": "rm -rf dist && TZ=UTC jest", "watch": "tsc-watch --onSuccess \"node ./dist/index.js\"" }, diff --git a/src/app.ts b/src/app.ts index 237b477..d3a3e0c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,10 +1,10 @@ import Koa from "koa"; import Router from "koa-router"; -import Models from "./routes/model"; -import Database from "./routes/database"; -import Main from "./routes/main"; -import GraphQlRoutes from "./routes/graphql"; +import Models from "./routes/model.js"; +import Database from "./routes/database.js"; +import Main from "./routes/main.js"; +import GraphQlRoutes from "./routes/graphql.js"; const app = new Koa(); diff --git a/src/index.ts b/src/index.ts index 07a3693..3173108 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import app from "./app"; -import { port } from "./config"; +import app from "./app.js"; +import { port } from "./config.js"; app.listen(port, () => console.log("fetch-r started on port " + port)); diff --git a/src/lib/database/connection.ts b/src/lib/database/connection.ts index 9046e08..a3e0d2a 100644 --- a/src/lib/database/connection.ts +++ b/src/lib/database/connection.ts @@ -1,7 +1,7 @@ import mysql, { ResultSetHeader, RowDataPacket } from "mysql2"; import * as pg from "pg"; -import * as T from "./type"; +import * as T from "./type.js"; export class SQL { //connection: mysql.Connection; diff --git a/src/lib/database/index.ts b/src/lib/database/index.ts index 0b4d4f2..4950f23 100644 --- a/src/lib/database/index.ts +++ b/src/lib/database/index.ts @@ -1,2 +1,2 @@ -export * as Connection from "./connection"; -export * as Type from "./type"; +export * as Connection from "./connection.js"; +export * as Type from "./type.js"; diff --git a/src/lib/exec.ts b/src/lib/exec.ts index aee83b7..435cf8e 100644 --- a/src/lib/exec.ts +++ b/src/lib/exec.ts @@ -1,14 +1,14 @@ import { RowDataPacket, ResultSetHeader } from "mysql2"; -import * as Connection from "./database/connection"; -import * as T from "./type"; -import * as Meta from "./query-builder/meta"; -import * as MutateService from "./query-builder/mutate"; -import * as TT from "./query-builder/type"; -import * as Parse from "./query-builder/parse"; -import * as ParseMutate from "./query-builder/parse-mutate"; -import * as ReferenceService from "./query-builder/references"; -import * as U from "./query-builder/utils"; -import { DatabaseType } from "./database/type"; +import * as Connection from "./database/connection.js"; +import * as T from "./type.js"; +import * as Meta from "./query-builder/meta.js"; +import * as MutateService from "./query-builder/mutate.js"; +import * as TT from "./query-builder/type.js"; +import * as Parse from "./query-builder/parse.js"; +import * as ParseMutate from "./query-builder/parse-mutate.js"; +import * as ReferenceService from "./query-builder/references.js"; +import * as U from "./query-builder/utils.js"; +import { DatabaseType } from "./database/type.js"; const isRawDataPacket = ( response: RowDataPacket[] | RowDataPacket diff --git a/src/lib/graphql/index.ts b/src/lib/graphql/index.ts index d8afef0..9ee86ca 100644 --- a/src/lib/graphql/index.ts +++ b/src/lib/graphql/index.ts @@ -1,7 +1,7 @@ -export * as SchemaFactory from "./schema-factory"; -export * as Type from "./type"; -export * as Utils from "./utils"; +export * as SchemaFactory from "./schema-factory.js"; +export * as Type from "./type.js"; +export * as Utils from "./utils.js"; -import Schema from "./schema"; +import Schema from "./schema.js"; export { Schema }; diff --git a/src/lib/graphql/mutate-factory.ts b/src/lib/graphql/mutate-factory.ts index a5dbe0a..9cad87d 100644 --- a/src/lib/graphql/mutate-factory.ts +++ b/src/lib/graphql/mutate-factory.ts @@ -5,14 +5,14 @@ import { Mutate, MutateResponseDelete, MutateResponseInsert, -} from "../type"; -import { Connection } from "../database"; - -import * as Exec from "../exec"; -import { foreignId, foreignUuid, getArgs } from "./utils"; -import { createTypesFromModel } from "./type-factory"; -import { GLTypes } from "./type"; -import { DatabaseType } from "../database/type"; +} from "../type.js"; +import { Connection } from "../database/index.js"; + +import * as Exec from "../exec.js"; +import { foreignId, foreignUuid, getArgs } from "./utils.js"; +import { createTypesFromModel } from "./type-factory.js"; +import { GLTypes } from "./type.js"; +import { DatabaseType } from "../database/type.js"; // this is the graphql equivalent of MutateResponseInsert const mutateReponseInsertType: GL.GraphQLOutputType = new GL.GraphQLObjectType({ diff --git a/src/lib/graphql/query-factory.ts b/src/lib/graphql/query-factory.ts index 0690f4b..3aa6b93 100644 --- a/src/lib/graphql/query-factory.ts +++ b/src/lib/graphql/query-factory.ts @@ -1,15 +1,15 @@ import graphqlFields from "graphql-fields"; import * as GL from "graphql"; -import * as T from "./type"; -import * as U from "./utils"; +import * as T from "./type.js"; +import * as U from "./utils.js"; -import { Entity, Query, QueryFilters, QueryParams } from "../type"; -import { createTypesFromModel } from "./type-factory"; +import { Entity, Query, QueryFilters, QueryParams } from "../type.js"; +import { createTypesFromModel } from "./type-factory.js"; -import * as Connection from "../database/connection"; -import { DatabaseType } from "../database/type"; -import * as Exec from "../exec"; +import * as Connection from "../database/connection.js"; +import { DatabaseType } from "../database/type.js"; +import * as Exec from "../exec.js"; const fieldResolve = ( diff --git a/src/lib/graphql/schema-factory.ts b/src/lib/graphql/schema-factory.ts index 760934c..2267265 100644 --- a/src/lib/graphql/schema-factory.ts +++ b/src/lib/graphql/schema-factory.ts @@ -1,13 +1,13 @@ import * as GL from "graphql"; -import { Entity } from "../type"; -import { Connection } from "../database"; -import { DatabaseType } from "../database/type"; +import { Entity } from "../type.js"; +import { Connection } from "../database/index.js"; +import { DatabaseType } from "../database/type.js"; -import * as T from "./type"; -import * as U from "./utils"; -import { getQueryFromModel } from "./query-factory"; -import { getMutation } from "./mutate-factory"; +import * as T from "./type.js"; +import * as U from "./utils.js"; +import { getQueryFromModel } from "./query-factory.js"; +import { getMutation } from "./mutate-factory.js"; /** * diff --git a/src/lib/graphql/schema.ts b/src/lib/graphql/schema.ts index b4db696..15bba91 100644 --- a/src/lib/graphql/schema.ts +++ b/src/lib/graphql/schema.ts @@ -1,11 +1,11 @@ import { GraphQLSchema } from "graphql"; -import { Connection } from "../database"; +import { Connection } from "../database/index.js"; -import { Entity } from "../type"; +import { Entity } from "../type.js"; -import * as SchemaFactory from "./schema-factory"; -import { Submodel } from "./type"; -import { DatabaseType } from "../database/type"; +import * as SchemaFactory from "./schema-factory.js"; +import { Submodel } from "./type.js"; +import { DatabaseType } from "../database/type.js"; class GQLSchema { roleQLSchemaMap: Map< diff --git a/src/lib/graphql/submodel.test.ts b/src/lib/graphql/submodel.test.ts index 67f6fcc..5d2a36a 100644 --- a/src/lib/graphql/submodel.test.ts +++ b/src/lib/graphql/submodel.test.ts @@ -1,5 +1,5 @@ -import { Entity } from "../type"; -import * as S from "./submodel"; +import { Entity } from "../type.js"; +import * as S from "./submodel.js"; const m1: Entity[] = [ { diff --git a/src/lib/graphql/submodel.ts b/src/lib/graphql/submodel.ts index 814ed94..51dd95c 100644 --- a/src/lib/graphql/submodel.ts +++ b/src/lib/graphql/submodel.ts @@ -1,5 +1,5 @@ -import { Entity, QueryFilters, QueryProjection } from "../type"; -import * as T from "./type"; +import { Entity, QueryFilters, QueryProjection } from "../type.js"; +import * as T from "./type.js"; type Uuid = string; diff --git a/src/lib/graphql/type-factory.test.ts b/src/lib/graphql/type-factory.test.ts index 0a97ecf..f6b9659 100644 --- a/src/lib/graphql/type-factory.test.ts +++ b/src/lib/graphql/type-factory.test.ts @@ -1,8 +1,8 @@ //import { GraphQLObjectType } from "graphql"; import * as GL from "graphql"; -import { Entity } from "../type"; -import * as TF from "./type-factory"; -import { foreignId } from "./utils"; +import { Entity } from "../type.js"; +import * as TF from "./type-factory.js"; +import { foreignId } from "./utils.js"; describe("createTypesFromModel", () => { test("empty", () => { diff --git a/src/lib/graphql/type-factory.ts b/src/lib/graphql/type-factory.ts index a3d2b34..31be505 100644 --- a/src/lib/graphql/type-factory.ts +++ b/src/lib/graphql/type-factory.ts @@ -1,7 +1,7 @@ import * as GL from "graphql"; -import { Entity, Field } from "../type"; -import * as T from "./type"; -import * as UM from "./utils-mapping"; +import { Entity, Field } from "../type.js"; +import * as T from "./type.js"; +import * as UM from "./utils-mapping.js"; const getObjectType = ( filteredEntityFields: Field[], diff --git a/src/lib/graphql/type.ts b/src/lib/graphql/type.ts index ababacb..3a7e9e5 100644 --- a/src/lib/graphql/type.ts +++ b/src/lib/graphql/type.ts @@ -1,5 +1,5 @@ import * as GL from "graphql"; -import { QueryFilters, QueryProjection } from "../type"; +import { QueryFilters, QueryProjection } from "../type.js"; export interface FieldOption { id: number; diff --git a/src/lib/graphql/utils-mapping.ts b/src/lib/graphql/utils-mapping.ts index 5c8af06..dc674b8 100644 --- a/src/lib/graphql/utils-mapping.ts +++ b/src/lib/graphql/utils-mapping.ts @@ -1,7 +1,7 @@ import * as GL from "graphql"; -import { Entity, Field } from "../type"; -import * as T from "./type"; -import * as U from "./utils"; +import { Entity, Field } from "../type.js"; +import * as T from "./type.js"; +import * as U from "./utils.js"; export const mapInputType = ( { name, type }: Field, diff --git a/src/lib/graphql/utils-string.test.ts b/src/lib/graphql/utils-string.test.ts index 7cd84e0..0747399 100644 --- a/src/lib/graphql/utils-string.test.ts +++ b/src/lib/graphql/utils-string.test.ts @@ -1,6 +1,6 @@ -import * as US from "./utils-string"; -import * as U from "./utils"; -import { Entity } from "../type"; +import * as US from "./utils-string.js"; +import * as U from "./utils.js"; +import { Entity } from "../type.js"; const ddl: Entity[] = [ { diff --git a/src/lib/graphql/utils-string.ts b/src/lib/graphql/utils-string.ts index 831f7e8..09e12b7 100644 --- a/src/lib/graphql/utils-string.ts +++ b/src/lib/graphql/utils-string.ts @@ -1,7 +1,7 @@ // this file is actualy not referenced elsewhere in the code (except for tests) -import { Entity, Field } from "../type"; -import * as T from "./type"; -import * as U from "./utils"; +import { Entity, Field } from "../type.js"; +import * as T from "./type.js"; +import * as U from "./utils.js"; // not used const mapTypesString = ({ name, type }: Field): string => { diff --git a/src/lib/graphql/utils.ts b/src/lib/graphql/utils.ts index 735f0c2..e91df59 100644 --- a/src/lib/graphql/utils.ts +++ b/src/lib/graphql/utils.ts @@ -1,6 +1,6 @@ import * as GL from "graphql"; -import { QueryProjection, QueryFilters, Entity, Field } from "../type"; -import * as T from "./type"; +import { QueryProjection, QueryFilters, Entity, Field } from "../type.js"; +import * as T from "./type.js"; // not used export const getSchemaFromDDL = (def: Entity[]) => { diff --git a/src/lib/index.ts b/src/lib/index.ts index 83deb02..0e283a3 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,12 +1,12 @@ // this file is used for the package. The server should use the other files directly -export * as Database from "./database"; -export * as Model from "./model"; -export * as Exec from "./exec"; -export * as Type from "./type"; -export * as QueryBuilder from "./query-builder"; -export * as GraphQL from "./graphql"; -export * as QueryService from "./query-service"; +export * as Database from "./database/index.js"; +export * as Model from "./model/index.js"; +export * as Exec from "./exec.js"; +export * as Type from "./type.js"; +export * as QueryBuilder from "./query-builder/index.js"; +export * as GraphQL from "./graphql/index.js"; +export * as QueryService from "./query-service/index.js"; -import Main from "./main"; +import Main from "./main.js"; export default Main; diff --git a/src/lib/main.ts b/src/lib/main.ts index 7ba7795..d5b5137 100644 --- a/src/lib/main.ts +++ b/src/lib/main.ts @@ -1,11 +1,11 @@ // this file is used for the package. The server should use the other files directly -import * as Connection from "./database/connection"; -import * as Exec from "./exec"; -import * as T from "./type"; -import { addColumnsToModel } from "./model/utils"; -import { Query as AQuery } from "./query-builder/aggregate/type"; -import { Aggregate } from "./query-builder"; -import { ConnectionOptions, DatabaseType } from "./database/type"; +import * as Connection from "./database/connection.js"; +import * as Exec from "./exec.js"; +import * as T from "./type.js"; +import { addColumnsToModel } from "./model/utils.js"; +import { Query as AQuery } from "./query-builder/aggregate/type.js"; +import { Aggregate } from "./query-builder/index.js"; +import { ConnectionOptions, DatabaseType } from "./database/type.js"; interface Options { legacyMode: boolean; diff --git a/src/lib/migrations/index.test.ts b/src/lib/migrations/index.test.ts index bb0d09a..372ed85 100644 --- a/src/lib/migrations/index.test.ts +++ b/src/lib/migrations/index.test.ts @@ -1,4 +1,4 @@ -import * as I from "./index"; +import * as I from "./index.js"; test("import/exports", () => { expect(typeof I.Migrations).toEqual("object"); diff --git a/src/lib/migrations/index.ts b/src/lib/migrations/index.ts index 9dc5c13..8b11865 100644 --- a/src/lib/migrations/index.ts +++ b/src/lib/migrations/index.ts @@ -1,3 +1,3 @@ -export * as Migrations from "./migrations"; -export * as Utils from "./utils"; -export * as Type from "./type"; +export * as Migrations from "./migrations.js"; +export * as Utils from "./utils.js"; +export * as Type from "./type.js"; diff --git a/src/lib/migrations/migrations.ts b/src/lib/migrations/migrations.ts index 608cf0d..a29b64c 100644 --- a/src/lib/migrations/migrations.ts +++ b/src/lib/migrations/migrations.ts @@ -7,8 +7,8 @@ import { //import * as T from "@nexys/sql-migrations/dist/type"; //import * as U from "@nexys/sql-migrations/dist/utils"; -import * as T from "./type"; -import * as U from "./utils"; +import * as T from "./type.js"; +import * as U from "./utils.js"; type Response = [ OkPacket | ResultSetHeader | RowDataPacket[] | RowDataPacket[][] | OkPacket[], diff --git a/src/lib/migrations/utils.test.ts b/src/lib/migrations/utils.test.ts index d2540b3..97a507a 100644 --- a/src/lib/migrations/utils.test.ts +++ b/src/lib/migrations/utils.test.ts @@ -1,4 +1,4 @@ -import * as M from "./utils"; +import * as M from "./utils.js"; describe("check sequence", () => { test("right seq", () => { diff --git a/src/lib/migrations/utils.ts b/src/lib/migrations/utils.ts index fe04890..db8941e 100644 --- a/src/lib/migrations/utils.ts +++ b/src/lib/migrations/utils.ts @@ -1,13 +1,13 @@ -import * as T from "./type"; +import * as T from "./type.js"; import CRC32 from "crc-32"; // manages migration // inspiration from flyway - https://flywaydb.org/ -const table = "flyway_schema_history"; +const migrationTable = "flyway_schema_history"; export const createMigrationTable = [ - "CREATE TABLE IF NOT EXISTS `" + table + "` (", + "CREATE TABLE IF NOT EXISTS `" + migrationTable + "` (", "`installed_rank` int NOT NULL,", " `version` varchar(50) DEFAULT NULL,", " `description` varchar(200) NOT NULL,", @@ -23,7 +23,7 @@ export const createMigrationTable = [ ") ENGINE=InnoDB", ].join("\n"); -export const getMigrations = `SELECT * FROM ${table};`; +export const getMigrations = `SELECT * FROM ${migrationTable};`; export const toVersion = (version: number, idx: number) => version + "." + idx; export const toScript = (version: string, name: string): string => @@ -61,7 +61,7 @@ export const migrationsToSQL = (rows: T.MigrationRow[]) => { .map((x) => `(${x})`) .join(", "); - return `INSERT INTO \`${table}\` (${keys + return `INSERT INTO \`${migrationTable}\` (${keys .map((x) => "`" + x + "`") .join(", ")}) VALUES ${values};`; }; diff --git a/src/lib/model/index.ts b/src/lib/model/index.ts index 1e69cf0..9393b7d 100644 --- a/src/lib/model/index.ts +++ b/src/lib/model/index.ts @@ -1 +1 @@ -export * as Utils from "./utils"; +export * as Utils from "./utils.js"; diff --git a/src/lib/model/utils.ts b/src/lib/model/utils.ts index 23670dd..9c1e1fc 100644 --- a/src/lib/model/utils.ts +++ b/src/lib/model/utils.ts @@ -1,5 +1,5 @@ -import * as T from "../type"; -import { camelToSnakeCase, isStandardType } from "../utils"; +import * as T from "../type.js"; +import { camelToSnakeCase, isStandardType } from "../utils.js"; export const addColumnsToModel = (es: T.Entity[]) => { es.forEach((entity) => { diff --git a/src/lib/query-builder/aggregate/index.test.ts b/src/lib/query-builder/aggregate/index.test.ts index 3ef6276..02acc97 100644 --- a/src/lib/query-builder/aggregate/index.test.ts +++ b/src/lib/query-builder/aggregate/index.test.ts @@ -1,6 +1,6 @@ -import { Entity } from "../../type"; -import * as I from "./index"; -import * as T from "./type"; +import { Entity } from "../../type.js"; +import * as I from "./index.js"; +import * as T from "./type.js"; const sql = [ "SELECT user_module_id, SUM(passed) as sumPassed, COUNT(id) as count_id", diff --git a/src/lib/query-builder/aggregate/index.ts b/src/lib/query-builder/aggregate/index.ts index cde803f..1f95b51 100644 --- a/src/lib/query-builder/aggregate/index.ts +++ b/src/lib/query-builder/aggregate/index.ts @@ -1,11 +1,11 @@ // very first version -import * as T from "./type"; +import * as T from "./type.js"; -import { Entity, Field } from "../../type"; -import * as U from "./utils"; -import { SQL } from "../../database/connection"; -import { getFilterString } from "../utils"; -import { camelToSnakeCase } from "../../utils"; +import { Entity, Field } from "../../type.js"; +import * as U from "./utils.js"; +import { SQL } from "../../database/connection.js"; +import { getFilterString } from "../utils.js"; +import { camelToSnakeCase } from "../../utils.js"; const idField: Field = { name: "id", diff --git a/src/lib/query-builder/aggregate/type.ts b/src/lib/query-builder/aggregate/type.ts index d8296f8..d568b30 100644 --- a/src/lib/query-builder/aggregate/type.ts +++ b/src/lib/query-builder/aggregate/type.ts @@ -1,4 +1,4 @@ -import { QueryFilters } from "../../type"; +import { QueryFilters } from "../../type.js"; export type AggregateOperator = "$count" | "$sum" | "$avg" | "$min" | "$max"; diff --git a/src/lib/query-builder/aggregate/utils.test.ts b/src/lib/query-builder/aggregate/utils.test.ts index feaba5a..76f5a53 100644 --- a/src/lib/query-builder/aggregate/utils.test.ts +++ b/src/lib/query-builder/aggregate/utils.test.ts @@ -1,4 +1,4 @@ -import * as I from "./utils"; +import * as I from "./utils.js"; describe("getOperator", () => { test("true", () => { diff --git a/src/lib/query-builder/aggregate/utils.ts b/src/lib/query-builder/aggregate/utils.ts index 2bb6dd7..3be46a0 100644 --- a/src/lib/query-builder/aggregate/utils.ts +++ b/src/lib/query-builder/aggregate/utils.ts @@ -1,6 +1,6 @@ -import { Field } from "../../type"; -import { camelToSnakeCase } from "../../utils"; -import * as T from "./type"; +import { Field } from "../../type.js"; +import { camelToSnakeCase } from "../../utils.js"; +import * as T from "./type.js"; export const toSQLOperator = ( input: T.AggregateOperator diff --git a/src/lib/query-builder/index.ts b/src/lib/query-builder/index.ts index b0523dd..3ddfab0 100644 --- a/src/lib/query-builder/index.ts +++ b/src/lib/query-builder/index.ts @@ -1,7 +1,7 @@ -export * as Aggregate from "./aggregate"; -export * as Meta from "./meta"; -export * as Parse from "./parse"; -export * as ParseMutate from "./parse-mutate"; -export * as Mutate from "./mutate"; -export * as Type from "./type"; -export * as Utils from "./utils"; +export * as Aggregate from "./aggregate/index.js"; +export * as Meta from "./meta.js"; +export * as Parse from "./parse.js"; +export * as ParseMutate from "./parse-mutate.js"; +export * as Mutate from "./mutate.js"; +export * as Type from "./type.js"; +export * as Utils from "./utils.js"; diff --git a/src/lib/query-builder/legacy.test.ts b/src/lib/query-builder/legacy.test.ts index 984c638..13c45d7 100644 --- a/src/lib/query-builder/legacy.test.ts +++ b/src/lib/query-builder/legacy.test.ts @@ -1,5 +1,5 @@ -import * as L from "./legacy"; -import Model from "./model-academy"; +import * as L from "./legacy.js"; +import Model from "./model-academy.js"; test("augment", () => { const projection = {}; diff --git a/src/lib/query-builder/legacy.ts b/src/lib/query-builder/legacy.ts index cd93ef1..10010e7 100644 --- a/src/lib/query-builder/legacy.ts +++ b/src/lib/query-builder/legacy.ts @@ -1,8 +1,8 @@ /** * set of helper functions to augment queries so they would return the same results as the old API */ -import * as U from "../utils"; -import * as T from "../type"; +import * as U from "../utils.js"; +import * as T from "../type.js"; export const allFieldsAreFk = ( fs: T.Field[], projection: T.QueryProjection diff --git a/src/lib/query-builder/meta-multiple-joins.test.ts b/src/lib/query-builder/meta-multiple-joins.test.ts index 1016d19..6e33884 100644 --- a/src/lib/query-builder/meta-multiple-joins.test.ts +++ b/src/lib/query-builder/meta-multiple-joins.test.ts @@ -1,8 +1,8 @@ -import * as M from "./meta"; -import * as S from "./sql"; +import * as M from "./meta.js"; +import * as S from "./sql.js"; -import modelAcademy from "./model-academy"; -import { MetaQuery, MetaQueryUnit } from "./type"; +import modelAcademy from "./model-academy.js"; +import { MetaQuery, MetaQueryUnit } from "./type.js"; const u0: MetaQueryUnit = { entity: "UserCertificate", diff --git a/src/lib/query-builder/meta-operator.test.ts b/src/lib/query-builder/meta-operator.test.ts index 2da7eb6..b1df7a4 100644 --- a/src/lib/query-builder/meta-operator.test.ts +++ b/src/lib/query-builder/meta-operator.test.ts @@ -1,7 +1,7 @@ -import * as M from "./meta"; -import * as S from "./sql"; -import * as T from "../type"; -import model from "./model-user"; +import * as M from "./meta.js"; +import * as S from "./sql.js"; +import * as T from "../type.js"; +import model from "./model-user.js"; test("simple select w projection and filter with operator", () => { const q: T.Query = { diff --git a/src/lib/query-builder/meta.test.ts b/src/lib/query-builder/meta.test.ts index cd6829c..f7d53e0 100644 --- a/src/lib/query-builder/meta.test.ts +++ b/src/lib/query-builder/meta.test.ts @@ -1,10 +1,10 @@ -import * as M from "./meta"; -import * as P from "./parse"; -import * as S from "./sql"; -import * as TT from "./type"; -import * as T from "../type"; +import * as M from "./meta.js"; +import * as P from "./parse.js"; +import * as S from "./sql.js"; +import * as TT from "./type.js"; +import * as T from "../type.js"; import { RowDataPacket } from "mysql2"; -import model from "./model-user"; +import model from "./model-user.js"; describe("to meta and to query", () => { const q: T.Query = { diff --git a/src/lib/query-builder/meta.ts b/src/lib/query-builder/meta.ts index 0505c7c..e22456f 100644 --- a/src/lib/query-builder/meta.ts +++ b/src/lib/query-builder/meta.ts @@ -4,12 +4,12 @@ * the meta query is transformed into MySQL (or any SQL-like system, grammar to be adjusted) * teh result of the query is parsed */ -import { DatabaseType } from "../database/type"; -import * as T from "../type"; -import * as TT from "./type"; -import * as U from "../utils"; -import * as UU from "./utils"; -import { toQuery } from "./sql"; +import { DatabaseType } from "../database/type.js"; +import * as T from "../type.js"; +import * as TT from "./type.js"; +import * as U from "../utils.js"; +import * as UU from "./utils.js"; +import { toQuery } from "./sql.js"; const getField = ( fieldName: string, diff --git a/src/lib/query-builder/meta2.test.ts b/src/lib/query-builder/meta2.test.ts index aae9427..3a63683 100644 --- a/src/lib/query-builder/meta2.test.ts +++ b/src/lib/query-builder/meta2.test.ts @@ -1,8 +1,8 @@ -import * as M from "./meta"; -import * as S from "./sql"; -import * as TT from "./type"; +import * as M from "./meta.js"; +import * as S from "./sql.js"; +import * as TT from "./type.js"; -import modelAcademy from "./model-academy"; +import modelAcademy from "./model-academy.js"; test("2nd level projection", () => { const q = { diff --git a/src/lib/query-builder/meta3.test.ts b/src/lib/query-builder/meta3.test.ts index a7b161c..cd6c401 100644 --- a/src/lib/query-builder/meta3.test.ts +++ b/src/lib/query-builder/meta3.test.ts @@ -1,6 +1,6 @@ -import * as M from "./meta"; -import * as S from "./sql"; -import * as T from "../type"; +import * as M from "./meta.js"; +import * as S from "./sql.js"; +import * as T from "../type.js"; const model: T.Entity[] = [ { diff --git a/src/lib/query-builder/model-academy.ts b/src/lib/query-builder/model-academy.ts index 39cdb62..9dbe885 100644 --- a/src/lib/query-builder/model-academy.ts +++ b/src/lib/query-builder/model-academy.ts @@ -1,4 +1,4 @@ -import * as T from "../type"; +import * as T from "../type.js"; const m: T.Entity[] = [ { diff --git a/src/lib/query-builder/mutate.test.ts b/src/lib/query-builder/mutate.test.ts index ab4b71b..69341f7 100644 --- a/src/lib/query-builder/mutate.test.ts +++ b/src/lib/query-builder/mutate.test.ts @@ -1,7 +1,7 @@ -import * as S from "./mutate"; -import * as T from "../type"; -import model from "./model-user"; -import model2 from "./model-academy"; +import * as S from "./mutate.js"; +import * as T from "../type.js"; +import model from "./model-user.js"; +import model2 from "./model-academy.js"; interface User { uuid: string; diff --git a/src/lib/query-builder/mutate.ts b/src/lib/query-builder/mutate.ts index 5ecb862..68216bf 100644 --- a/src/lib/query-builder/mutate.ts +++ b/src/lib/query-builder/mutate.ts @@ -1,8 +1,8 @@ -import { getModel } from "./utils"; -import * as T from "../type"; -import * as U from "../utils"; -import * as UU from "./utils"; -import { DatabaseType } from "../database/type"; +import { getModel } from "./utils.js"; +import * as T from "../type.js"; +import * as U from "../utils.js"; +import * as UU from "./utils.js"; +import { DatabaseType } from "../database/type.js"; // SQL export const getFilterUnit = ( diff --git a/src/lib/query-builder/parse-mutate.test.ts b/src/lib/query-builder/parse-mutate.test.ts index f04db09..e7b0246 100644 --- a/src/lib/query-builder/parse-mutate.test.ts +++ b/src/lib/query-builder/parse-mutate.test.ts @@ -1,4 +1,4 @@ -import * as PM from "./parse-mutate"; +import * as PM from "./parse-mutate.js"; describe("parseMutateInsert", () => { test("insert", () => { diff --git a/src/lib/query-builder/parse-mutate.ts b/src/lib/query-builder/parse-mutate.ts index 98fa746..1c6d3b3 100644 --- a/src/lib/query-builder/parse-mutate.ts +++ b/src/lib/query-builder/parse-mutate.ts @@ -1,7 +1,7 @@ import { ResultSetHeader, RowDataPacket } from "mysql2"; -import * as T from "../type"; -import { entityToTable } from "../utils"; -import * as Connection from "../database/connection"; +import * as T from "../type.js"; +import { entityToTable } from "../utils.js"; +import * as Connection from "../database/connection.js"; export const getIdsMutateInsert = ({ affectedRows, diff --git a/src/lib/query-builder/parse.ts b/src/lib/query-builder/parse.ts index 0fc7df8..3547a68 100644 --- a/src/lib/query-builder/parse.ts +++ b/src/lib/query-builder/parse.ts @@ -6,11 +6,11 @@ * * this file handles the parsing */ -import { DatabaseType } from "../database/type"; -import * as T from "../type"; -import * as TT from "./type"; -import * as UU from "./utils"; import { RowDataPacket } from "mysql2"; +import { DatabaseType } from "../database/type.js"; +import * as T from "../type.js"; +import * as TT from "./type.js"; +import * as UU from "./utils.js"; /** * parse to the right javascript value diff --git a/src/lib/query-builder/parse2.test.ts b/src/lib/query-builder/parse2.test.ts index 1aee941..cf417e2 100644 --- a/src/lib/query-builder/parse2.test.ts +++ b/src/lib/query-builder/parse2.test.ts @@ -1,6 +1,6 @@ -import * as P from "./parse"; +import * as P from "./parse.js"; import { RowDataPacket } from "mysql2"; -import { MetaQuery } from "./type"; +import { MetaQuery } from "./type.js"; describe("get parsed value", () => { test("string", () => { diff --git a/src/lib/query-builder/references.test.ts b/src/lib/query-builder/references.test.ts index af00112..9ff0c13 100644 --- a/src/lib/query-builder/references.test.ts +++ b/src/lib/query-builder/references.test.ts @@ -1,6 +1,6 @@ -import { Entity, Field, References } from "../type"; -import * as R from "./references"; -import model from "../query-builder/model-academy"; +import { Entity, Field, References } from "../type.js"; +import * as R from "./references.js"; +import model from "../query-builder/model-academy.js"; describe("get field - joinOn", () => { const field1: Field = { name: "logUser", type: "User", optional: false }; diff --git a/src/lib/query-builder/references.ts b/src/lib/query-builder/references.ts index 3a8f2e4..858799c 100644 --- a/src/lib/query-builder/references.ts +++ b/src/lib/query-builder/references.ts @@ -1,9 +1,9 @@ -import * as Meta from "../query-builder/meta"; -import * as TT from "../query-builder/type"; -import * as Exec from "../exec"; -import { Entity, Field, References, ReturnUnit } from "../type"; -import * as Connection from "../database/connection"; -import { DatabaseType } from "../database/type"; +import * as Meta from "../query-builder/meta.js"; +import * as TT from "../query-builder/type.js"; +import * as Exec from "../exec.js"; +import { Entity, Field, References, ReturnUnit } from "../type.js"; +import * as Connection from "../database/connection.js"; +import { DatabaseType } from "../database/type.js"; interface Ref { entity: string; diff --git a/src/lib/query-builder/sql.ts b/src/lib/query-builder/sql.ts index b9ee504..7890267 100644 --- a/src/lib/query-builder/sql.ts +++ b/src/lib/query-builder/sql.ts @@ -1,7 +1,7 @@ -import * as TT from "./type"; -import * as U from "../utils"; -import * as UU from "./utils"; -import { DatabaseType } from "../database/type"; +import * as TT from "./type.js"; +import * as U from "../utils.js"; +import * as UU from "./utils.js"; +import { DatabaseType } from "../database/type.js"; export const toQuery = ( meta: TT.MetaQuery, diff --git a/src/lib/query-builder/type.ts b/src/lib/query-builder/type.ts index aa115c3..4112884 100644 --- a/src/lib/query-builder/type.ts +++ b/src/lib/query-builder/type.ts @@ -1,4 +1,4 @@ -import * as T from "../type"; +import * as T from "../type.js"; export interface MetaJoin { entity: string; diff --git a/src/lib/query-builder/utils.test.ts b/src/lib/query-builder/utils.test.ts index f3f2620..3e503b4 100644 --- a/src/lib/query-builder/utils.test.ts +++ b/src/lib/query-builder/utils.test.ts @@ -1,5 +1,5 @@ -import { MetaJoin } from "./type"; -import * as U from "./utils"; +import { MetaJoin } from "./type.js"; +import * as U from "./utils.js"; test("getAliasColumn", () => { expect(U.getAliasColumn("my_table", "my_field")).toEqual("my_table_my_field"); diff --git a/src/lib/query-builder/utils.ts b/src/lib/query-builder/utils.ts index 9aba9ad..0d2b0c6 100644 --- a/src/lib/query-builder/utils.ts +++ b/src/lib/query-builder/utils.ts @@ -1,7 +1,7 @@ -import * as T from "../type"; -import * as TT from "./type"; -import { escape } from "../utils"; -import { DatabaseType } from "../database/type"; +import * as T from "../type.js"; +import * as TT from "./type.js"; +import { escape } from "../utils.js"; +import { DatabaseType } from "../database/type.js"; export const getAliasColumn = (tableAlias: string, fieldName: string) => tableAlias + "_" + fieldName; diff --git a/src/lib/query-service/abstract-service-wdata.ts b/src/lib/query-service/abstract-service-wdata.ts index 50a04df..ed48cc9 100644 --- a/src/lib/query-service/abstract-service-wdata.ts +++ b/src/lib/query-service/abstract-service-wdata.ts @@ -1,4 +1,4 @@ -import * as QueryUtil from "./utils"; +import * as QueryUtil from "./utils.js"; import { Query, QueryFilters as Filters, @@ -10,16 +10,16 @@ import { References, MutateResponseUpdate, MutateResponseDelete, -} from "../type"; +} from "../type.js"; -import AbstractService from "./abstract-service"; -import { QueryConstraint } from "./constraint/type"; +import AbstractService from "./abstract-service.js"; +import { QueryConstraint } from "./constraint/type.js"; -import * as QueryBuilder from "./constraint/query-builder"; -import * as TT from "./constraint/type"; -import { Entity } from "../type"; -import * as TA from "./aggregate-type"; -import { mutatePostProcessing } from "./constraint/utils"; +import * as QueryBuilder from "./constraint/query-builder/index.js"; +import * as TT from "./constraint/type.js"; +import { Entity } from "../type.js"; +import * as TA from "./aggregate-type.js"; +import { mutatePostProcessing } from "./constraint/utils.js"; type QueryResponse = any; @@ -91,7 +91,7 @@ abstract class QueryService extends AbstractService { **/ async insertMultiple( entity: string, - data: Omit[] = [] + data: Omit[] = [] ): Promise { if (data.length === 0) { throw new Error(`No rows for ${entity} provided`); diff --git a/src/lib/query-service/abstract-service.ts b/src/lib/query-service/abstract-service.ts index 9264d87..ce9d65b 100644 --- a/src/lib/query-service/abstract-service.ts +++ b/src/lib/query-service/abstract-service.ts @@ -1,4 +1,4 @@ -import * as TQ from "../"; +import * as TQ from "../index.js"; abstract class QueryService { abstract list(entity: string, params?: any): Promise; diff --git a/src/lib/query-service/aggregate-type.ts b/src/lib/query-service/aggregate-type.ts index 62564ba..c180b23 100644 --- a/src/lib/query-service/aggregate-type.ts +++ b/src/lib/query-service/aggregate-type.ts @@ -1,4 +1,4 @@ -import { QueryFilters } from "../type"; +import { QueryFilters } from "../type.js"; export type AggregateOperator = "$count" | "$sum" | "$avg" | "$min" | "$max"; diff --git a/src/lib/query-service/constraint/default-constraints.ts b/src/lib/query-service/constraint/default-constraints.ts index 53f8a7d..a7fe3a8 100644 --- a/src/lib/query-service/constraint/default-constraints.ts +++ b/src/lib/query-service/constraint/default-constraints.ts @@ -1,6 +1,6 @@ -import { Entity } from "../../type"; -import * as T from "./type"; -import * as Exclude from "./exclude"; +import { Entity } from "../../type.js"; +import * as T from "./type.js"; +import * as Exclude from "./exclude.js"; export const defaultAppend = ({ uuid, diff --git a/src/lib/query-service/constraint/exclude.ts b/src/lib/query-service/constraint/exclude.ts index a7e8cf5..7aecfc9 100644 --- a/src/lib/query-service/constraint/exclude.ts +++ b/src/lib/query-service/constraint/exclude.ts @@ -3,7 +3,7 @@ import { MutateConstraint, ProjectionConstraint, QueryConstraint, -} from "./type"; +} from "./type.js"; type Uuid = string; diff --git a/src/lib/query-service/constraint/index.ts b/src/lib/query-service/constraint/index.ts index 22e34d0..7d0ecbb 100644 --- a/src/lib/query-service/constraint/index.ts +++ b/src/lib/query-service/constraint/index.ts @@ -1,8 +1,8 @@ -import { Entity } from "../../type"; +import { Entity } from "../../type.js"; -import { Profile, Constraint, Permission } from "./type"; +import { Profile, Constraint, Permission } from "./type.js"; -import DefaultConstraints from "./default-constraints"; +import DefaultConstraints from "./default-constraints.js"; const roleKeys = [Permission.app, Permission.admin, Permission.superadmin]; diff --git a/src/lib/query-service/constraint/query-builder/data.test.ts b/src/lib/query-service/constraint/query-builder/data.test.ts index 78ff919..625875a 100644 --- a/src/lib/query-service/constraint/query-builder/data.test.ts +++ b/src/lib/query-service/constraint/query-builder/data.test.ts @@ -1,7 +1,7 @@ -import { QueryParams, Entity } from "../../../type"; +import { QueryParams, Entity } from "../../../type.js"; -import * as T from "../type"; -import * as Q from "./data"; +import * as T from "../type.js"; +import * as Q from "./data.js"; const model: Entity[] = [ { diff --git a/src/lib/query-service/constraint/query-builder/data.ts b/src/lib/query-service/constraint/query-builder/data.ts index b6544c6..569140b 100644 --- a/src/lib/query-service/constraint/query-builder/data.ts +++ b/src/lib/query-service/constraint/query-builder/data.ts @@ -4,8 +4,8 @@ import { QueryParams, QueryProjection, Query, -} from "../../../type"; -import { FilterConstraint, ProjectionConstraint } from "../type"; +} from "../../../type.js"; +import { FilterConstraint, ProjectionConstraint } from "../type.js"; const getModelUnit = (entity: string, model: Entity[]): Entity => { const f = model.find((x) => x.name === entity); diff --git a/src/lib/query-service/constraint/query-builder/index.ts b/src/lib/query-service/constraint/query-builder/index.ts index 944cf3f..e4b481b 100644 --- a/src/lib/query-service/constraint/query-builder/index.ts +++ b/src/lib/query-service/constraint/query-builder/index.ts @@ -1,4 +1,4 @@ -import * as Data from "./data"; -import * as Mutate from "./mutate"; +import * as Data from "./data.js"; +import * as Mutate from "./mutate.js"; export { Data, Mutate }; diff --git a/src/lib/query-service/constraint/query-builder/mutate.test.ts b/src/lib/query-service/constraint/query-builder/mutate.test.ts index 488f6b1..d666981 100644 --- a/src/lib/query-service/constraint/query-builder/mutate.test.ts +++ b/src/lib/query-service/constraint/query-builder/mutate.test.ts @@ -1,4 +1,4 @@ -import * as Q from "./mutate"; +import * as Q from "./mutate.js"; test("constructMutatePermission", () => { const q = { User: { insert: { data: {} } } }; diff --git a/src/lib/query-service/constraint/query-builder/mutate.ts b/src/lib/query-service/constraint/query-builder/mutate.ts index 671a706..fc6c9a5 100644 --- a/src/lib/query-service/constraint/query-builder/mutate.ts +++ b/src/lib/query-service/constraint/query-builder/mutate.ts @@ -1,6 +1,6 @@ -import { Mutate, MutateParams } from "../../../type"; -import { DataConstraint, FilterConstraint } from "../type"; -import * as Utils from "./utils"; +import { Mutate, MutateParams } from "../../../type.js"; +import { DataConstraint, FilterConstraint } from "../type.js"; +import * as Utils from "./utils.js"; export const constructMutatePermission = ( query: Mutate, diff --git a/src/lib/query-service/constraint/query-builder/utils.test.ts b/src/lib/query-service/constraint/query-builder/utils.test.ts index b553a6c..9ae4872 100644 --- a/src/lib/query-service/constraint/query-builder/utils.test.ts +++ b/src/lib/query-service/constraint/query-builder/utils.test.ts @@ -1,4 +1,4 @@ -import * as U from "./utils"; +import * as U from "./utils.js"; test("random string", () => { expect(U.generateString(12).length).toEqual(12); diff --git a/src/lib/query-service/constraint/type.ts b/src/lib/query-service/constraint/type.ts index ae34a2a..03e9e42 100644 --- a/src/lib/query-service/constraint/type.ts +++ b/src/lib/query-service/constraint/type.ts @@ -1,4 +1,4 @@ -import { FilterAttribute } from "../../type"; +import { FilterAttribute } from "../../type.js"; type Uuid = string; export interface Profile { diff --git a/src/lib/query-service/constraint/utils.test.ts b/src/lib/query-service/constraint/utils.test.ts index dfedbeb..33f9596 100644 --- a/src/lib/query-service/constraint/utils.test.ts +++ b/src/lib/query-service/constraint/utils.test.ts @@ -1,4 +1,4 @@ -import * as C from "./utils"; +import * as C from "./utils.js"; test("format error", () => { const errorString = diff --git a/src/lib/query-service/constraint/utils.ts b/src/lib/query-service/constraint/utils.ts index 014cce0..80160a8 100644 --- a/src/lib/query-service/constraint/utils.ts +++ b/src/lib/query-service/constraint/utils.ts @@ -1,5 +1,5 @@ -import { MutateResponse } from "../../type"; -import * as QueryTypes from "./type"; +import { MutateResponse } from "../../type.js"; +import * as QueryTypes from "./type.js"; /** * diff --git a/src/lib/query-service/index.ts b/src/lib/query-service/index.ts index eba3157..398c5e1 100644 --- a/src/lib/query-service/index.ts +++ b/src/lib/query-service/index.ts @@ -1,4 +1,4 @@ -import Service from "./service"; -export * as Utils from "./utils"; +import Service from "./service.js"; +export * as Utils from "./utils.js"; export { Service }; diff --git a/src/lib/query-service/service-external.ts b/src/lib/query-service/service-external.ts index 26e818d..90c5eef 100644 --- a/src/lib/query-service/service-external.ts +++ b/src/lib/query-service/service-external.ts @@ -2,10 +2,10 @@ * this service allows to use the external fetchr service */ /// -import { Query, Mutate, MutateResponse } from "../type"; -import * as TF from "../type"; -import AbstractServiceWData from "./abstract-service-wdata"; -import * as TA from "../query-builder/aggregate/type"; +import { Query, Mutate, MutateResponse } from "../type.js"; +import * as TF from "../type.js"; +import AbstractServiceWData from "./abstract-service-wdata.js"; +import * as TA from "../query-builder/aggregate/type.js"; const hostDefault = "https://crud.nexys.io"; diff --git a/src/lib/query-service/service.ts b/src/lib/query-service/service.ts index 4bcd21c..de4c2cc 100644 --- a/src/lib/query-service/service.ts +++ b/src/lib/query-service/service.ts @@ -1,9 +1,9 @@ -import { Query, Mutate, MutateResponse, ReturnUnit } from "../type"; +import { Query, Mutate, MutateResponse, ReturnUnit } from "../type.js"; -import Fetchr from "../main"; +import Fetchr from "../main.js"; -import AbstractServiceWData from "./abstract-service-wdata"; -import * as TA from "../query-builder/aggregate/type"; +import AbstractServiceWData from "./abstract-service-wdata.js"; +import * as TA from "../query-builder/aggregate/type.js"; class QueryService extends AbstractServiceWData { fetchr: Fetchr; diff --git a/src/lib/query-service/utils.ts b/src/lib/query-service/utils.ts index 6c7d41f..97d29f2 100644 --- a/src/lib/query-service/utils.ts +++ b/src/lib/query-service/utils.ts @@ -1,4 +1,4 @@ -import { QueryFilters as Filters, Mutate } from "../type"; +import { QueryFilters as Filters, Mutate } from "../type.js"; export const paramsFromFilters = ( filters: number | string | Filters diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts index cc27d99..13d506f 100644 --- a/src/lib/utils.test.ts +++ b/src/lib/utils.test.ts @@ -1,4 +1,4 @@ -import * as U from "./utils"; +import * as U from "./utils.js"; test("isstandardtype", () => { expect(U.isStandardType("BigDecimal")).toEqual(true); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 396a651..e55bc9b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,5 +1,5 @@ import * as SqlString from "sqlstring"; -import * as T from "./type"; +import * as T from "./type.js"; export const types: T.Type[] = [ "String", diff --git a/src/middleware/index.test.ts b/src/middleware/index.test.ts index 935d391..e5de4c8 100644 --- a/src/middleware/index.test.ts +++ b/src/middleware/index.test.ts @@ -1,6 +1,6 @@ -import * as M from "./index"; +import * as M from "./index.js"; import JWT from "jsonwebtoken"; -import * as C from "../config"; +import * as C from "../config.js"; test("extractToken", () => { expect(M.extractToken({ authorization: "Bearer mytoken" })).toEqual( diff --git a/src/middleware/index.ts b/src/middleware/index.ts index f445d4e..c31ab66 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -1,7 +1,7 @@ import Koa from "koa"; import JWT from "jsonwebtoken"; -import * as C from "../config"; +import * as C from "../config.js"; export const isJson = (headers: { "content-type"?: string }): void => { if ( diff --git a/src/routes/database.ts b/src/routes/database.ts index 7bcc298..2f85585 100644 --- a/src/routes/database.ts +++ b/src/routes/database.ts @@ -2,8 +2,8 @@ import Router from "koa-router"; import bodyParser from "koa-body"; -import * as Middleware from "../middleware"; -import * as DatabaseService from "../service/database"; +import * as Middleware from "../middleware/index.js"; +import * as DatabaseService from "../service/database/index.js"; import * as V from "@nexys/validation"; const router: Router = new Router(); diff --git a/src/routes/graphql.ts b/src/routes/graphql.ts index 8acade9..4d44f82 100644 --- a/src/routes/graphql.ts +++ b/src/routes/graphql.ts @@ -2,12 +2,12 @@ import Router from "koa-router"; import bodyParser from "koa-body"; import { graphql, printSchema } from "graphql"; -import Schema from "../lib/graphql/schema"; -import { Submodel } from "../lib/graphql/type"; -import * as Middleware from "../middleware"; +import Schema from "../lib/graphql/schema.js"; +import { Submodel } from "../lib/graphql/type.js"; +import * as Middleware from "../middleware/index.js"; -import * as ModelService from "../service/model"; -import * as DatabaseService from "../service/database"; +import * as ModelService from "../service/model/index.js"; +import * as DatabaseService from "../service/database/index.js"; const router = new Router(); diff --git a/src/routes/main.ts b/src/routes/main.ts index 502388d..b8a8158 100644 --- a/src/routes/main.ts +++ b/src/routes/main.ts @@ -2,13 +2,13 @@ import Koa from "koa"; import Router from "koa-router"; import bodyParser from "koa-body"; -import { version, sha } from "../config"; +import { version, sha } from "../config.js"; -import * as Middleware from "../middleware"; -import * as QueryService from "../lib/exec"; -import * as ModelService from "../service/model"; -import * as DatabaseService from "../service/database"; -import * as AggregateService from "../lib/query-builder/aggregate"; +import * as Middleware from "../middleware/index.js"; +import * as QueryService from "../lib/exec.js"; +import * as ModelService from "../service/model/index.js"; +import * as DatabaseService from "../service/database/index.js"; +import * as AggregateService from "../lib/query-builder/aggregate/index.js"; const router: Router = new Router(); diff --git a/src/routes/model.ts b/src/routes/model.ts index c4a8dcf..e2f44bf 100644 --- a/src/routes/model.ts +++ b/src/routes/model.ts @@ -1,8 +1,8 @@ import Router from "koa-router"; import bodyParser from "koa-body"; -import * as Middleware from "../middleware"; -import * as ModelService from "../service/model"; +import * as Middleware from "../middleware/index.js"; +import * as ModelService from "../service/model/index.js"; import * as V from "@nexys/validation"; diff --git a/src/service/database/index.ts b/src/service/database/index.ts index 7f15535..087ca1f 100644 --- a/src/service/database/index.ts +++ b/src/service/database/index.ts @@ -1,7 +1,7 @@ import fs from "fs"; -import { JwtStructure } from "../../middleware/type"; -import * as T from "../../lib/database/type"; -import * as Connection from "../../lib/database/connection"; +import { JwtStructure } from "../../middleware/type.js"; +import * as T from "../../lib/database/type.js"; +import * as Connection from "../../lib/database/connection.js"; // diff --git a/src/service/model/index.ts b/src/service/model/index.ts index 99fc026..68e2b19 100644 --- a/src/service/model/index.ts +++ b/src/service/model/index.ts @@ -1,7 +1,7 @@ import fs from "fs"; -import { addColumnsToModel } from "../../lib/model/utils"; -import * as T from "../../lib/type"; -import { JwtStructure } from "../../middleware/type"; +import { addColumnsToModel } from "../../lib/model/utils.js"; +import * as T from "../../lib/type.js"; +import { JwtStructure } from "../../middleware/type.js"; const productIdentifier = (j: Pick) => j.product + "_" + j.env; diff --git a/tsconfig.package.json b/tsconfig.package.json index af9a453..0ef183b 100644 --- a/tsconfig.package.json +++ b/tsconfig.package.json @@ -4,28 +4,28 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "NodeNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ - "allowJs": false, /* Allow javascript files to be compiled. */ + "allowJs": false /* Allow javascript files to be compiled. */, // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist", /* Redirect output structure to the directory. */ - "rootDir": "./src/lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + "outDir": "./dist" /* Redirect output structure to the directory. */, + "rootDir": "./src/lib" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - "removeComments": true, /* Do not emit comments to output. */ + "removeComments": true /* Do not emit comments to output. */, // "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -35,8 +35,8 @@ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ - "noUnusedLocals": true, /* Report errors on unused locals. */ - "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ @@ -50,7 +50,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ //"types": ["node"], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ @@ -65,11 +65,9 @@ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ /* Advanced Options */ - "skipLibCheck": true, /* Skip type checking of declaration files. */ - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ - },"include": [ - "src/lib/**/*" - ],"exclude": [ - "src/lib/**/*.test.ts" - ] + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + }, + "include": ["src/lib/**/*"], + "exclude": ["src/lib/**/*.test.ts"] }