Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/npm_and_yarn/eslint-9.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lastlink committed Sep 3, 2024
2 parents d5b6275 + e7f0ef4 commit 8fd35f0
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 118 deletions.
7 changes: 4 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default [
"@typescript-eslint/no-unsafe-function-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-useless-escape": "off",
"no-control-regex": "off",
"no-multiple-empty-lines": "error",
"no-use-before-define": "off",
"@typescript-eslint/no-non-null-assertion": "off",
Expand All @@ -32,9 +33,9 @@ export default [
},
{
files: ["**/__tests__/*.{j,t}s?(x)", "**/tests/**/*.spec.{j,t}s?(x)"],
env: {
jest: true,
},
// env: {
// jest: true,
// },
},
{ languageOptions: { globals: globals.browser } }
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test": "jest -c ./jest.config.ts --forceExit --verbose -i --no-cache --detectOpenHandles",
"test:coverage": "jest --forceExit --coverage --verbose --detectOpenHandles",
"test:watch": "jest --watchAll --detectOpenHandles",
"lint": "tsc --noEmit && eslint \"{src,client}/**/*.{js,ts}\"",
"lint:fix": "tsc --noEmit && eslint \"{src,client}/**/*.{js,ts}\" --fix",
"lint": "tsc --noEmit && eslint \"{src,client,tests}/**/*.{js,ts}\"",
"lint:fix": "tsc --noEmit && eslint \"{src,client,tests}/**/*.{js,ts}\" --fix",
"create": "npm run build && npm run cli:test",
"build": "tsc && npm run build:types",
"build:types": "tsc -p tsconfig.json",
Expand Down
17 changes: 0 additions & 17 deletions src/nosql-ts.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import {
DbDefinition,
DbRelationshipDefinition,
} from "@funktechno/little-mermaid-2-the-sql/lib/src/types";
import {
DatabaseModelResult,
TableAttribute,
TableEntity,
} from "./types/sql-plugin-types";
import {
DatabaseModel,
ForeignKeyModel,
PrimaryKeyModel,
PropertyModel,
TableModel,
} from "@funktechno/sqlsimpleparser/lib/types";
import { JSONSchema4, JSONSchema4TypeName } from "json-schema";
import {
convertCoreTypesToJsonSchema,
convertOpenApiToCoreTypes,
Expand All @@ -28,17 +16,12 @@ import { convertTypeScriptToCoreTypes } from "core-types-ts/dist/lib/ts-to-core-
import { convertCoreTypesToTypeScript } from "core-types-ts";
import {
CreateTableUI,
GetColumnQuantifiers,
RemoveNameQuantifiers,
dbTypeEnds,
getDbLabel,
getMermaidDiagramDb,
} from "./utils/sharedUtils";
import { pluginVersion } from "./utils/constants";
import {
ConvertOpenApiToDatabaseModel,
dbToOpenApi,
GeneratePropertyModel,
} from "./utils/nosqlUtils";
import { defaultReset, defaultResetOpenApi } from "./utils/constants-nosql";

Expand Down
13 changes: 0 additions & 13 deletions src/nosql.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {
DbDefinition,
DbRelationshipDefinition,
} from "@funktechno/little-mermaid-2-the-sql/lib/src/types";
import { TableAttribute, TableEntity } from "./types/sql-plugin-types";
import {
DatabaseModel,
ForeignKeyModel,
PrimaryKeyModel,
PropertyModel,
TableModel,
} from "@funktechno/sqlsimpleparser/lib/types";
import { JSONSchema4, JSONSchema4TypeName } from "json-schema";
import {
convertCoreTypesToJsonSchema,
convertOpenApiToCoreTypes,
Expand All @@ -22,17 +14,12 @@ import {
} from "openapi-json-schema";
import {
CreateTableUI,
GetColumnQuantifiers,
RemoveNameQuantifiers,
dbTypeEnds,
getDbLabel,
getMermaidDiagramDb,
} from "./utils/sharedUtils";
import { pluginVersion } from "./utils/constants";
import {
ConvertOpenApiToDatabaseModel,
dbToOpenApi,
GeneratePropertyModel,
} from "./utils/nosqlUtils";
import { defaultResetOpenApi } from "./utils/constants-nosql";

Expand Down
6 changes: 0 additions & 6 deletions src/sql.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { DbParser } from "@funktechno/little-mermaid-2-the-sql/lib/src/generate-sql-ddl";
import {
DbDefinition,
DbRelationshipDefinition,
} from "@funktechno/little-mermaid-2-the-sql/lib/src/types";
import { TableAttribute, TableEntity } from "./types/sql-plugin-types";
import { SqlSimpleParser } from "@funktechno/sqlsimpleparser";
import {
ForeignKeyModel,
PrimaryKeyModel,
PropertyModel,
TableModel,
} from "@funktechno/sqlsimpleparser/lib/types";
import {
CreateTableUI,
GetColumnQuantifiers,
RemoveNameQuantifiers,
getDbLabel,
getMermaidDiagramDb,
} from "./utils/sharedUtils";
import { pluginVersion } from "./utils/constants";
Expand Down
4 changes: 0 additions & 4 deletions src/utils/nosqlUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DbDefinition } from "@funktechno/little-mermaid-2-the-sql/lib/src/types";
import {
OpenApiSchemaTypeDefinition,
PartialOpenApiSchema,
Expand All @@ -14,15 +13,12 @@ import {
} from "./constants";
import { JSONSchema4, JSONSchema4TypeName } from "json-schema";
import {
ColumnQuantifiers,
DatabaseModelResult,
} from "../types/sql-plugin-types";
import {
dbTypeEnds,
generateComment,
GetColumnQuantifiers,
getCommentIndexes,
getDbLabel,
RemoveNameQuantifiers,
} from "./sharedUtils";
import {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/sharedUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DbDefinition,
DbRelationshipDefinition,
} from "@funktechno/little-mermaid-2-the-sql/lib/src/types";
import {
Expand Down Expand Up @@ -75,7 +74,7 @@ export function dbTypeEnds(label: string): string {
* @returns
*/
export function RemoveNameQuantifiers(name: string) {
return name.replace(/\[|\]|\(|\"|\'|\`/g, "").trim();
return name.replace(/\[|\]|\(|\)|\"|\'|\`/g, "").trim();
}

/**
Expand Down
113 changes: 113 additions & 0 deletions tests/utils/nosqlUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//typescript
import {
dbToOpenApi,
GeneratePropertyModel,
ConvertOpenApiToDatabaseModel,
} from "../../src/utils/nosqlUtils";
import { JSONSchema4 } from "json-schema";
import {
OpenApiSchemaTypeDefinition,
} from "openapi-json-schema";
import {
DatabaseModelResult,
TableEntity,
} from "../../src/types/sql-plugin-types";
import { GenerateDatabaseModel } from "../../src/utils/sharedUtils";

describe("dbToOpenApi", () => {
it("should handle empty entities correctly", () => {
const dbResult = {
getEntities: () => ({}),
} as DatabaseModelResult;

const result = dbToOpenApi(dbResult);
expect(result).toEqual(
expect.objectContaining({
openapi: "3.0.0",
info: expect.anything(),
paths: {},
components: {
schemas: {},
},
})
);
});

it("should process entities and populate schemas", () => {
const entities: Record<string, TableEntity> = {
User: {
name: "User",
attributes: [
{ attributeName: "id", attributeType: "string" },
{ attributeName: "name", attributeType: "string" },
],
},
};
const dbResult = GenerateDatabaseModel(entities, []);

const result = dbToOpenApi(dbResult);
expect(result.components?.schemas).toHaveProperty("User");
expect(result.components?.schemas?.User).toEqual(
expect.objectContaining({
type: "object",
properties: {
id: expect.any(Object),
name: expect.any(Object),
},
})
);
});
});

describe("GeneratePropertyModel", () => {
it("should properly construct a PropertyModel from JSONSchema", () => {
const jsonSchema: JSONSchema4 = {
type: "string",
nullable: true,
};
const propertyName = "username";
const tableName = "User";

const propertyModel = GeneratePropertyModel(
tableName,
propertyName,
jsonSchema
);
expect(propertyModel.TableName).toEqual("`User`");
expect(propertyModel.Name).toBe("`username`");
expect(propertyModel.ColumnProperties).toContain("string nullable");
});
});

describe("ConvertOpenApiToDatabaseModel", () => {
it("should convert empty schemas to minimal DatabaseModel", () => {
const schemas: Record<string, OpenApiSchemaTypeDefinition> = {};

const model = ConvertOpenApiToDatabaseModel(schemas);
expect(model).toEqual(
expect.objectContaining({
Dialect: "nosql",
TableList: [],
PrimaryKeyList: [],
ForeignKeyList: [],
})
);
});

it("should convert populated schemas to DatabaseModel", () => {
const schemas: Record<string, OpenApiSchemaTypeDefinition> = {
User: {
properties: {
id: { type: "string", $ref: "#/components/schemas/Id" },
},
type: "object",
},
};

const model = ConvertOpenApiToDatabaseModel(schemas);
expect(model.TableList).toHaveLength(1);
expect(model.ForeignKeyList).toHaveLength(2); // Primary and foreign key relationships
});
});

//
Loading

0 comments on commit 8fd35f0

Please sign in to comment.