-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit separates concerns of "compiling" and "building" the application. Before, both operations were called "parsing" but now the parsing necessary is done inside the compiler and appplication object constructed is separated to its own utility. Isolating compiling to its own module allows refactoring/modifying compiler easily (to be able to for example support ahead of time compilation) without affecting the rest of the application. Key Changes: - Create DTO (data transfer objects) for compiler and make it independent of domain layer. Other supporting changes: - Refactor loading collection file to its own utility. - Refactor application factory to be functional rather than OOD. - Rename related interfaces to drop `I` prefix to align with new coding conventions. - Prefer using "Loader" in naming in place of "Parser" where its about loading information, not really parsing data. - Refactor domain objects to use more factory pattern
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { CollectionData } from '@/application/collections/'; | ||
import type { ProjectDetails } from '@/domain/Project/ProjectDetails'; | ||
import type { CompiledCollectionDto } from '../CompiledCollectionDto'; | ||
import TypeValidator, { createTypeValidator } from '@/application/Compiler/Common/TypeValidator'; | ||
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, ubuntu)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, ubuntu)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, macos)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, macos)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, windows)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, windows)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
Check failure on line 4 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, test)
|
||
|
||
export interface SingleCollectionCompiler { //TODO: CategoryCollectionParser will become this. | ||
Check failure on line 6 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, ubuntu)
Check failure on line 6 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / lint (npm run lint:eslint, macos)
|
||
( | ||
collectionData: CollectionData, | ||
projectDetails: ProjectDetails, | ||
utilities?: SingleCollectionCompilerUtilities, | ||
): CompiledCollectionDto; | ||
} | ||
|
||
interface SingleCollectionCompilerUtilities { | ||
readonly osParser: EnumParser<OperatingSystem>; | ||
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
Check failure on line 15 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, test)
|
||
readonly validator: TypeValidator; | ||
readonly parseScriptingDefinition: ScriptingDefinitionParser; | ||
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 17 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
|
||
readonly createContext: CategoryCollectionContextFactory; | ||
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 18 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
|
||
readonly parseCategory: CategoryParser; | ||
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, development)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, production)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (ubuntu, test)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, production)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, development)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (macos, test)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, production)
Check failure on line 19 in src/application/Compiler/Collection/SingleCollectionCompiler.ts GitHub Actions / build-web (windows, development)
|
||
readonly createCategoryCollection: CategoryCollectionFactory; | ||
} | ||
|
||
export const compileCollection: SingleCollectionCompiler = ( | ||
collectionData, | ||
projectDetails, | ||
utilities = DefaultUtilities, | ||
) => { | ||
validateCollection(content, utilities.validator); | ||
}; | ||
|
||
function validateCollection( | ||
content: CollectionData, | ||
validator: TypeValidator, | ||
): void { | ||
validator.assertObject({ | ||
value: content, | ||
valueName: 'Collection', | ||
allowedProperties: [ | ||
'os', 'scripting', 'actions', 'functions', | ||
], | ||
}); | ||
validator.assertNonEmptyCollection({ | ||
value: content.actions, | ||
valueName: '\'actions\' in collection', | ||
}); | ||
} | ||
|
||
const DefaultUtilities: CategoryCollectionParserUtilities = { | ||
validator: createTypeValidator(), | ||
osParser: createEnumParser(OperatingSystem), | ||
parseScriptingDefinition, | ||
createContext: createCategoryCollectionContext, | ||
parseCategory, | ||
createCategoryCollection, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export interface CompiledCollectionDto { | ||
readonly os: string; | ||
readonly startCode: string; | ||
readonly endCode: string; | ||
readonly language: string; | ||
readonly rootCategories: readonly CompiledCategoryDto[]; | ||
} | ||
|
||
export interface CompiledExecutableDto { | ||
readonly markdownDocs: string; | ||
readonly title: string; | ||
readonly executableId: string; | ||
} | ||
|
||
export interface CompiledScriptDto extends CompiledExecutableDto { | ||
readonly code: string; | ||
readonly revertCode: string; | ||
} | ||
|
||
export interface CompiledCategoryDto extends CompiledExecutableDto { | ||
readonly categories: readonly CompiledCategoryDto[]; | ||
readonly scripts: readonly CompiledScriptDto[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { CollectionData } from '@/application/collections/'; | ||
import type { ProjectDetails } from '@/domain/Project/ProjectDetails'; | ||
import { createTypeValidator, type TypeValidator } from './Common/TypeValidator'; | ||
import { compileCollection, type SingleCollectionCompiler } from './Collection/SingleCollectionCompiler'; | ||
import type { CompiledCollectionDto } from './CompiledCollectionDto'; | ||
|
||
/** | ||
* This utility is responsible for compiling collection data into an application object. | ||
* It serves as part of the application layer, parsing and compiling the application data | ||
* defined in collection YAML files. | ||
* | ||
* The compiler creates basic, decoupled abstractions without external references, | ||
* acting as an anti-corruption layer. This design allows for independent changes | ||
* to the compiler and its models. | ||
*/ | ||
export interface MultipleCollectionsCompiler { | ||
( | ||
collectionsData: readonly CollectionData[], | ||
projectDetails: ProjectDetails, | ||
utilities?: CollectionCompilerUtilities, | ||
): CompiledCollectionDto[]; | ||
} | ||
|
||
export const compileCollections: MultipleCollectionsCompiler = ( | ||
collectionsData, | ||
projectDetails, | ||
utilities = DefaultUtilities, | ||
) => { | ||
validateCollectionsData(collectionsData, utilities.validator); | ||
const collections = collectionsData.map( | ||
(collection) => utilities.compileCollection(collection, projectDetails), | ||
); | ||
return collections; | ||
}; | ||
|
||
interface CollectionCompilerUtilities { | ||
readonly validator: TypeValidator; | ||
readonly compileCollection: SingleCollectionCompiler; | ||
} | ||
|
||
const DefaultUtilities: CollectionCompilerUtilities = { | ||
validator: createTypeValidator(), | ||
compileCollection, | ||
}; | ||
|
||
function validateCollectionsData( | ||
collections: readonly CollectionData[], | ||
validator: TypeValidator, | ||
) { | ||
validator.assertNonEmptyCollection({ | ||
value: collections, | ||
valueName: 'Collections', | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import type { IScriptingDefinition } from '@/domain/IScriptingDefinition'; | ||
import type { ScriptingDefinition } from '@/domain/ScriptingDefinition'; | ||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript'; | ||
import type { IUserScript } from './IUserScript'; | ||
|
||
export interface IUserScriptGenerator { | ||
buildCode( | ||
selectedScripts: ReadonlyArray<SelectedScript>, | ||
scriptingDefinition: IScriptingDefinition, | ||
scriptingDefinition: ScriptingDefinition, | ||
): IUserScript; | ||
} |