Skip to content

Commit

Permalink
chore(code-gen): combine all internal utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed May 9, 2023
1 parent 85918bd commit 6a61e7c
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 182 deletions.
3 changes: 1 addition & 2 deletions packages/code-gen/src/database/generator.js
@@ -1,10 +1,9 @@
import { AppError, noop } from "@compas/stdlib";
import { structureModels } from "../processors/models.js";
import { stringFormatNameForError } from "../string-format.js";
import { targetCustomSwitch } from "../target/switcher.js";
import { typesCacheGet } from "../types/cache.js";
import { typesGeneratorUseTypeName } from "../types/generator.js";
import { upperCaseFirst } from "../utils.js";
import { stringFormatNameForError, upperCaseFirst } from "../utils.js";
import {
validatorGeneratorGenerateValidator,
validatorGetNameAndImport,
Expand Down
3 changes: 1 addition & 2 deletions packages/code-gen/src/database/postgres.js
Expand Up @@ -16,9 +16,8 @@ import {
import { structureModels } from "../processors/models.js";
import { referenceUtilsGetProperty } from "../processors/reference-utils.js";
import { structureResolveReference } from "../processors/structure.js";
import { stringFormatNameForError } from "../string-format.js";
import { typesOptionalityIsOptional } from "../types/optionality.js";
import { upperCaseFirst } from "../utils.js";
import { stringFormatNameForError, upperCaseFirst } from "../utils.js";

/**
* Write the DDL out for Postgres
Expand Down
15 changes: 0 additions & 15 deletions packages/code-gen/src/errors.d.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/code-gen/src/errors.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/code-gen/src/processors/any-of.js
@@ -1,6 +1,6 @@
import { AppError, isNil } from "@compas/stdlib";
import { stringFormatNameForError } from "../string-format.js";
import { typesOptionalityIsOptional } from "../types/optionality.js";
import { stringFormatNameForError } from "../utils.js";
import { referenceUtilsGetProperty } from "./reference-utils.js";
import { structureNamedTypes, structureResolveReference } from "./structure.js";
import { typeDefinitionTraverse } from "./type-definition-traverse.js";
Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/crud-validation.js
@@ -1,6 +1,8 @@
import { AppError, isNil } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import {
crudInformationGetHasCustomReadableType,
crudInformationGetModel,
Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/model-keys.js
@@ -1,7 +1,9 @@
import { AppError, isNil } from "@compas/stdlib";
import { DateType, UuidType } from "../builders/index.js";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureModels } from "./models.js";
import { referenceUtilsGetProperty } from "./reference-utils.js";

Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/model-name.js
@@ -1,6 +1,8 @@
import { AppError } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureModels } from "./models.js";

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/code-gen/src/processors/model-relation.js
@@ -1,11 +1,11 @@
import { AppError } from "@compas/stdlib";
import { ReferenceType, RelationType } from "../builders/index.js";
import { errorsThrowCombinedError } from "../errors.js";
import { typesOptionalityIsOptional } from "../types/optionality.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
stringFormatRelation,
} from "../string-format.js";
import { typesOptionalityIsOptional } from "../types/optionality.js";
} from "../utils.js";
import { modelKeyGetPrimary } from "./model-keys.js";
import { structureModels } from "./models.js";
import { structureNamedTypes, structureResolveReference } from "./structure.js";
Expand Down
3 changes: 1 addition & 2 deletions packages/code-gen/src/processors/model-where.js
Expand Up @@ -7,8 +7,7 @@ import {
ObjectType,
ReferenceType,
} from "../builders/index.js";
import { stringFormatNameForError } from "../string-format.js";
import { upperCaseFirst } from "../utils.js";
import { stringFormatNameForError, upperCaseFirst } from "../utils.js";
import { modelKeyGetSearchable } from "./model-keys.js";
import {
modelRelationGetInformation,
Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/object-expansion.js
@@ -1,6 +1,8 @@
import { AppError } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureNamedTypes, structureResolveReference } from "./structure.js";
import { typeDefinitionTraverse } from "./type-definition-traverse.js";

Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/route-invalidation.js
@@ -1,6 +1,8 @@
import { AppError, isNil } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureRoutes } from "./routes.js";
import { structureResolveReference } from "./structure.js";

Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/route-trie.js
@@ -1,6 +1,8 @@
import { AppError } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureRoutes } from "./routes.js";

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/structure-name-checks.js
@@ -1,6 +1,8 @@
import { AppError } from "@compas/stdlib";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { structureNamedTypes } from "./structure.js";
import { typeDefinitionTraverse } from "./type-definition-traverse.js";

Expand Down
6 changes: 4 additions & 2 deletions packages/code-gen/src/processors/structure.js
@@ -1,7 +1,9 @@
import { AppError, isNil } from "@compas/stdlib";
import { isNamedTypeBuilderLike } from "../builders/index.js";
import { errorsThrowCombinedError } from "../errors.js";
import { stringFormatNameForError } from "../string-format.js";
import {
errorsThrowCombinedError,
stringFormatNameForError,
} from "../utils.js";
import { typeDefinitionTraverse } from "./type-definition-traverse.js";

/**
Expand Down
31 changes: 0 additions & 31 deletions packages/code-gen/src/string-format.d.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/code-gen/src/string-format.js

This file was deleted.

43 changes: 0 additions & 43 deletions packages/code-gen/src/string-format.test.js

This file was deleted.

44 changes: 44 additions & 0 deletions packages/code-gen/src/utils.d.ts
Expand Up @@ -12,4 +12,48 @@ export function upperCaseFirst(str?: string | undefined): string;
* @returns {string}
*/
export function lowerCaseFirst(str?: string | undefined): string;
/**
* Format a type name for error messages
*
* @param {undefined|{ group?: string, name?: string, type?: string }} type
* @returns {string}
*/
export function stringFormatNameForError(
type:
| undefined
| {
group?: string;
name?: string;
type?: string;
},
): string;
/**
* Format a full relation name
*
* @param {string} ownName
* @param {string} inverseName
* @param {string} ownKey
* @param {string} inverseKey
* @returns {string}
*/
export function stringFormatRelation(
ownName: string,
inverseName: string,
ownKey: string,
inverseKey: string,
): string;
/**
* Combine the messages of the provided errors and throw a new error.
*
* Early returns if an empty array is provided.
*
* Other supported properties:
* - messages: expected to be a string[]
*
* @param {import("@compas/stdlib").AppError[]} errors
* @returns {void}
*/
export function errorsThrowCombinedError(
errors: import("@compas/stdlib").AppError[],
): void;
//# sourceMappingURL=utils.d.ts.map

0 comments on commit 6a61e7c

Please sign in to comment.