Skip to content

Commit

Permalink
to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan committed May 19, 2024
1 parent 7b965ae commit 0540d03
Show file tree
Hide file tree
Showing 89 changed files with 292 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
dist/
node_modules/
assets/
src/index-standalone.ts
src/index-standalone.ts
index.js
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
export default {
extensionsToTreatAsEsm: [".ts"],
preset: "ts-jest",
testEnvironment: "node",
moduleNameMapper: {
"^(\\.\\.?\\/.+)\\.js?$": "$1",
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@nexys/fetchr",
"type": "module",
"version": "0.13.0",
"license": "AGPL-3.0-or-later",
"main": "dist/index.js",
Expand Down Expand Up @@ -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\""
},
Expand Down
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 1 addition & 1 deletion src/lib/database/connection.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/database/index.ts
Original file line number Diff line number Diff line change
@@ -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";
20 changes: 10 additions & 10 deletions src/lib/exec.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/lib/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
16 changes: 8 additions & 8 deletions src/lib/graphql/mutate-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
14 changes: 7 additions & 7 deletions src/lib/graphql/query-factory.ts
Original file line number Diff line number Diff line change
@@ -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 =
(
Expand Down
14 changes: 7 additions & 7 deletions src/lib/graphql/schema-factory.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
*
Expand Down
10 changes: 5 additions & 5 deletions src/lib/graphql/schema.ts
Original file line number Diff line number Diff line change
@@ -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<Permission> {
roleQLSchemaMap: Map<
Expand Down
4 changes: 2 additions & 2 deletions src/lib/graphql/submodel.test.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/graphql/submodel.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/lib/graphql/type-factory.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/graphql/type-factory.ts
Original file line number Diff line number Diff line change
@@ -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[],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/graphql/type.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/graphql/utils-mapping.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/graphql/utils-string.test.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
{
Expand Down
6 changes: 3 additions & 3 deletions src/lib/graphql/utils-string.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/graphql/utils.ts
Original file line number Diff line number Diff line change
@@ -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[]) => {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 7 additions & 7 deletions src/lib/main.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/migrations/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from "./index";
import * as I from "./index.js";

test("import/exports", () => {
expect(typeof I.Migrations).toEqual("object");
Expand Down
6 changes: 3 additions & 3 deletions src/lib/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 2 additions & 2 deletions src/lib/migrations/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/migrations/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as M from "./utils";
import * as M from "./utils.js";

describe("check sequence", () => {
test("right seq", () => {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/migrations/utils.ts
Original file line number Diff line number Diff line change
@@ -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,",
Expand All @@ -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 =>
Expand Down Expand Up @@ -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};`;
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as Utils from "./utils";
export * as Utils from "./utils.js";
Loading

0 comments on commit 0540d03

Please sign in to comment.