Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50ba00b0af | ||
|
|
29e1069bf2 | ||
|
|
c7e57b8913 | ||
|
|
4cea6b26ec | ||
|
|
c2f4b68786 | ||
|
|
e8add5ec08 | ||
|
|
55c23e9d4c | ||
|
|
d77c3cbbe2 | ||
|
|
f89c2322b0 | ||
|
|
ded55a66d6 | ||
|
|
6fbc81675f | ||
|
|
48d97afdf6 | ||
|
|
109fc01c9a | ||
|
|
b185255a0a | ||
|
|
c2d3cddc47 | ||
|
|
8526d2510b | ||
|
|
11e566d0e5 | ||
|
|
ae0165f1fe | ||
|
|
a6505587bf | ||
|
|
b16e13678c | ||
|
|
abe03cef3f | ||
|
|
dd7239b8c1 | ||
|
|
851917e049 | ||
|
|
8d7a7eb434 | ||
|
|
0239b52385 |
@@ -30,6 +30,8 @@ Related documentation:
|
||||
|
||||
### Executables
|
||||
|
||||
They represent independently executable actions with documentation and reversibility.
|
||||
|
||||
An Executable is a logical entity that can
|
||||
|
||||
- execute once compiled,
|
||||
|
||||
5417
package-lock.json
generated
5417
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
54
package.json
54
package.json
@@ -34,54 +34,54 @@
|
||||
"postuninstall": "electron-builder install-app-deps"
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/vue": "^1.0.6",
|
||||
"@floating-ui/vue": "^1.1.1",
|
||||
"@juggle/resize-observer": "^3.4.0",
|
||||
"ace-builds": "^1.33.0",
|
||||
"electron-log": "^5.1.2",
|
||||
"ace-builds": "^1.35.3",
|
||||
"electron-log": "^5.1.6",
|
||||
"electron-progressbar": "^2.2.1",
|
||||
"electron-updater": "^6.1.9",
|
||||
"electron-updater": "^6.2.1",
|
||||
"file-saver": "^2.0.5",
|
||||
"markdown-it": "^14.1.0",
|
||||
"vue": "^3.4.27"
|
||||
"vue": "^3.4.32"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@modyfi/vite-plugin-yaml": "^1.1.0",
|
||||
"@rushstack/eslint-patch": "^1.10.2",
|
||||
"@rushstack/eslint-patch": "^1.10.3",
|
||||
"@types/ace": "^0.0.52",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/markdown-it": "^14.0.1",
|
||||
"@types/markdown-it": "^14.1.1",
|
||||
"@typescript-eslint/eslint-plugin": "6.21.0",
|
||||
"@typescript-eslint/parser": "6.21.0",
|
||||
"@vitejs/plugin-legacy": "^5.3.2",
|
||||
"@vitejs/plugin-vue": "^5.0.4",
|
||||
"@vitejs/plugin-legacy": "^5.4.1",
|
||||
"@vitejs/plugin-vue": "^5.0.5",
|
||||
"@vue/eslint-config-airbnb-with-typescript": "^8.0.0",
|
||||
"@vue/eslint-config-typescript": "12.0.0",
|
||||
"@vue/test-utils": "^2.4.5",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"cypress": "^13.7.3",
|
||||
"electron": "^31.0.2",
|
||||
"cypress": "^13.13.1",
|
||||
"electron": "^31.2.1",
|
||||
"electron-builder": "^24.13.3",
|
||||
"electron-devtools-installer": "^3.2.0",
|
||||
"electron-vite": "^2.1.0",
|
||||
"electron-vite": "^2.3.0",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-plugin-cypress": "^2.15.1",
|
||||
"eslint-plugin-vue": "^9.25.0",
|
||||
"eslint-plugin-vuejs-accessibility": "^2.2.1",
|
||||
"jsdom": "^24.0.0",
|
||||
"markdownlint-cli": "^0.39.0",
|
||||
"postcss": "^8.4.38",
|
||||
"remark-cli": "^12.0.0",
|
||||
"eslint-plugin-cypress": "^3.3.0",
|
||||
"eslint-plugin-vue": "^9.27.0",
|
||||
"eslint-plugin-vuejs-accessibility": "^2.4.0",
|
||||
"jsdom": "^24.1.0",
|
||||
"markdownlint-cli": "^0.41.0",
|
||||
"postcss": "^8.4.39",
|
||||
"remark-cli": "^12.0.1",
|
||||
"remark-lint-no-dead-urls": "^1.1.0",
|
||||
"remark-preset-lint-consistent": "^6.0.0",
|
||||
"remark-validate-links": "^13.0.1",
|
||||
"sass": "^1.75.0",
|
||||
"start-server-and-test": "^2.0.3",
|
||||
"terser": "^5.30.3",
|
||||
"tslib": "^2.6.2",
|
||||
"sass": "^1.77.8",
|
||||
"start-server-and-test": "^2.0.4",
|
||||
"terser": "^5.31.3",
|
||||
"tslib": "^2.6.3",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^5.2.8",
|
||||
"vitest": "^1.5.0",
|
||||
"vue-tsc": "^2.0.13",
|
||||
"vite": "^5.3.4",
|
||||
"vitest": "^2.0.3",
|
||||
"vue-tsc": "^2.0.26",
|
||||
"yaml-lint": "^1.7.0"
|
||||
},
|
||||
"//devDependencies": {
|
||||
|
||||
@@ -91,7 +91,7 @@ async function verifyFilesExist(directoryPath, filePatterns) {
|
||||
if (!match) {
|
||||
die(
|
||||
`No file matches the pattern ${pattern.source} in directory \`${directoryPath}\``,
|
||||
`\nFiles in directory:\n${files.map((file) => `\t- ${file}`).join('\n')}`,
|
||||
`\nFiles in directory:\n${files.map((file) => `- ${file}`).join('\n')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
25
src/application/Common/Text/FilterEmptyStrings.ts
Normal file
25
src/application/Common/Text/FilterEmptyStrings.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { isArray } from '@/TypeHelpers';
|
||||
|
||||
export type OptionalString = string | undefined | null;
|
||||
|
||||
export function filterEmptyStrings(
|
||||
texts: readonly OptionalString[],
|
||||
isArrayType: typeof isArray = isArray,
|
||||
): string[] {
|
||||
if (!isArrayType(texts)) {
|
||||
throw new Error(`Invalid input: Expected an array, but received type ${typeof texts}.`);
|
||||
}
|
||||
assertArrayItemsAreStringLike(texts);
|
||||
return texts
|
||||
.filter((title): title is string => Boolean(title));
|
||||
}
|
||||
|
||||
function assertArrayItemsAreStringLike(
|
||||
texts: readonly unknown[],
|
||||
): asserts texts is readonly OptionalString[] {
|
||||
const invalidItems = texts.filter((item) => !(typeof item === 'string' || item === undefined || item === null));
|
||||
if (invalidItems.length > 0) {
|
||||
const invalidTypes = invalidItems.map((item) => typeof item).join(', ');
|
||||
throw new Error(`Invalid array items: Expected items as string, undefined, or null. Received invalid types: ${invalidTypes}.`);
|
||||
}
|
||||
}
|
||||
29
src/application/Common/Text/IndentText.ts
Normal file
29
src/application/Common/Text/IndentText.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { isString } from '@/TypeHelpers';
|
||||
import { splitTextIntoLines } from './SplitTextIntoLines';
|
||||
|
||||
export function indentText(
|
||||
text: string,
|
||||
indentLevel = 1,
|
||||
utilities: TextIndentationUtilities = DefaultUtilities,
|
||||
): string {
|
||||
if (!utilities.isStringType(text)) {
|
||||
throw new Error(`Indentation error: The input must be a string. Received type: ${typeof text}.`);
|
||||
}
|
||||
if (indentLevel <= 0) {
|
||||
throw new Error(`Indentation error: The indent level must be a positive integer. Received: ${indentLevel}.`);
|
||||
}
|
||||
const indentation = '\t'.repeat(indentLevel);
|
||||
return utilities.splitIntoLines(text)
|
||||
.map((line) => (line ? `${indentation}${line}` : line))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
interface TextIndentationUtilities {
|
||||
readonly splitIntoLines: typeof splitTextIntoLines;
|
||||
readonly isStringType: typeof isString;
|
||||
}
|
||||
|
||||
const DefaultUtilities: TextIndentationUtilities = {
|
||||
splitIntoLines: splitTextIntoLines,
|
||||
isStringType: isString,
|
||||
};
|
||||
11
src/application/Common/Text/SplitTextIntoLines.ts
Normal file
11
src/application/Common/Text/SplitTextIntoLines.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { isString } from '@/TypeHelpers';
|
||||
|
||||
export function splitTextIntoLines(
|
||||
text: string,
|
||||
isStringType = isString,
|
||||
): string[] {
|
||||
if (!isStringType(text)) {
|
||||
throw new Error(`Line splitting error: Expected a string but received type '${typeof text}'.`);
|
||||
}
|
||||
return text.split(/\r\n|\r|\n/);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { IApplication } from '@/domain/IApplication';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||
import { assertInRange } from '@/application/Common/Enum';
|
||||
import { CategoryCollectionState } from './State/CategoryCollectionState';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { AdaptiveFilterContext } from './Filter/AdaptiveFilterContext';
|
||||
import { ApplicationCode } from './Code/ApplicationCode';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { ICodePosition } from '@/application/Context/State/Code/Position/ICodePosition';
|
||||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
import { splitTextIntoLines } from '@/application/Common/Text/SplitTextIntoLines';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import type { ICodeChangedEvent } from './ICodeChangedEvent';
|
||||
|
||||
export class CodeChangedEvent implements ICodeChangedEvent {
|
||||
@@ -36,12 +38,12 @@ export class CodeChangedEvent implements ICodeChangedEvent {
|
||||
}
|
||||
|
||||
public getScriptPositionInCode(script: Script): ICodePosition {
|
||||
return this.getPositionById(script.id);
|
||||
return this.getPositionById(script.executableId);
|
||||
}
|
||||
|
||||
private getPositionById(scriptId: string): ICodePosition {
|
||||
private getPositionById(scriptId: ExecutableId): ICodePosition {
|
||||
const position = [...this.scripts.entries()]
|
||||
.filter(([s]) => s.id === scriptId)
|
||||
.filter(([s]) => s.executableId === scriptId)
|
||||
.map(([, pos]) => pos)
|
||||
.at(0);
|
||||
if (!position) {
|
||||
@@ -52,7 +54,7 @@ export class CodeChangedEvent implements ICodeChangedEvent {
|
||||
}
|
||||
|
||||
function ensureAllPositionsExist(script: string, positions: ReadonlyArray<ICodePosition>) {
|
||||
const totalLines = script.split(/\r\n|\r|\n/).length;
|
||||
const totalLines = splitTextIntoLines(script).length;
|
||||
const missingPositions = positions.filter((position) => position.endLine > totalLines);
|
||||
if (missingPositions.length > 0) {
|
||||
throw new Error(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { splitTextIntoLines } from '@/application/Common/Text/SplitTextIntoLines';
|
||||
import type { ICodeBuilder } from './ICodeBuilder';
|
||||
|
||||
const TotalFunctionSeparatorChars = 58;
|
||||
@@ -15,7 +16,7 @@ export abstract class CodeBuilder implements ICodeBuilder {
|
||||
this.lines.push('');
|
||||
return this;
|
||||
}
|
||||
const lines = code.match(/[^\r\n]+/g);
|
||||
const lines = splitTextIntoLines(code);
|
||||
if (lines) {
|
||||
this.lines.push(...lines);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { FilterChange } from './Event/FilterChange';
|
||||
import { LinearFilterStrategy } from './Strategy/LinearFilterStrategy';
|
||||
import type { FilterResult } from './Result/FilterResult';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { FilterResult } from '../Result/FilterResult';
|
||||
|
||||
export interface FilterStrategy {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ScriptCode } from '@/domain/Executables/Script/Code/ScriptCode';
|
||||
import type { Documentable } from '@/domain/Executables/Documentable';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { AppliedFilterResult } from '../Result/AppliedFilterResult';
|
||||
import type { FilterStrategy } from './FilterStrategy';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import type { IApplicationCode } from './Code/IApplicationCode';
|
||||
import type { ReadonlyFilterContext, FilterContext } from './Filter/FilterContext';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
|
||||
type CategorySelectionStatus = {
|
||||
readonly isSelected: true;
|
||||
readonly isReverted: boolean;
|
||||
@@ -6,7 +8,7 @@ type CategorySelectionStatus = {
|
||||
};
|
||||
|
||||
export interface CategorySelectionChange {
|
||||
readonly categoryId: number;
|
||||
readonly categoryId: ExecutableId;
|
||||
readonly newStatus: CategorySelectionStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { CategorySelectionChange, CategorySelectionChangeCommand } from './CategorySelectionChange';
|
||||
import type { CategorySelection } from './CategorySelection';
|
||||
import type { ScriptSelection } from '../Script/ScriptSelection';
|
||||
@@ -23,7 +23,7 @@ export class ScriptToCategorySelectionMapper implements CategorySelection {
|
||||
return false;
|
||||
}
|
||||
return scripts.every(
|
||||
(script) => selectedScripts.some((selected) => selected.id === script.id),
|
||||
(script) => selectedScripts.some((selected) => selected.id === script.executableId),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export class ScriptToCategorySelectionMapper implements CategorySelection {
|
||||
const scripts = category.getAllScriptsRecursively();
|
||||
const scriptsChangesInCategory = scripts
|
||||
.map((script): ScriptSelectionChange => ({
|
||||
scriptId: script.id,
|
||||
scriptId: script.executableId,
|
||||
newStatus: {
|
||||
...change.newStatus,
|
||||
},
|
||||
|
||||
@@ -2,8 +2,9 @@ import { InMemoryRepository } from '@/infrastructure/Repository/InMemoryReposito
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||
import type { ReadonlyRepository, Repository } from '@/application/Repository/Repository';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { batchedDebounce } from '@/application/Common/Timing/BatchedDebounce';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import { UserSelectedScript } from './UserSelectedScript';
|
||||
import type { ScriptSelection } from './ScriptSelection';
|
||||
import type { ScriptSelectionChange, ScriptSelectionChangeCommand } from './ScriptSelectionChange';
|
||||
@@ -16,7 +17,7 @@ export type DebounceFunction = typeof batchedDebounce<ScriptSelectionChangeComma
|
||||
export class DebouncedScriptSelection implements ScriptSelection {
|
||||
public readonly changed = new EventSource<ReadonlyArray<SelectedScript>>();
|
||||
|
||||
private readonly scripts: Repository<string, SelectedScript>;
|
||||
private readonly scripts: Repository<SelectedScript>;
|
||||
|
||||
public readonly processChanges: ScriptSelection['processChanges'];
|
||||
|
||||
@@ -25,7 +26,7 @@ export class DebouncedScriptSelection implements ScriptSelection {
|
||||
selectedScripts: ReadonlyArray<SelectedScript>,
|
||||
debounce: DebounceFunction = batchedDebounce,
|
||||
) {
|
||||
this.scripts = new InMemoryRepository<string, SelectedScript>();
|
||||
this.scripts = new InMemoryRepository<SelectedScript>();
|
||||
for (const script of selectedScripts) {
|
||||
this.scripts.addItem(script);
|
||||
}
|
||||
@@ -38,8 +39,8 @@ export class DebouncedScriptSelection implements ScriptSelection {
|
||||
);
|
||||
}
|
||||
|
||||
public isSelected(scriptId: string): boolean {
|
||||
return this.scripts.exists(scriptId);
|
||||
public isSelected(scriptExecutableId: ExecutableId): boolean {
|
||||
return this.scripts.exists(scriptExecutableId);
|
||||
}
|
||||
|
||||
public get selectedScripts(): readonly SelectedScript[] {
|
||||
@@ -49,7 +50,7 @@ export class DebouncedScriptSelection implements ScriptSelection {
|
||||
public selectAll(): void {
|
||||
const scriptsToSelect = this.collection
|
||||
.getAllScripts()
|
||||
.filter((script) => !this.scripts.exists(script.id))
|
||||
.filter((script) => !this.scripts.exists(script.executableId))
|
||||
.map((script) => new UserSelectedScript(script, false));
|
||||
if (scriptsToSelect.length === 0) {
|
||||
return;
|
||||
@@ -116,12 +117,12 @@ export class DebouncedScriptSelection implements ScriptSelection {
|
||||
private applyChange(change: ScriptSelectionChange): number {
|
||||
const script = this.collection.getScript(change.scriptId);
|
||||
if (change.newStatus.isSelected) {
|
||||
return this.addOrUpdateScript(script.id, change.newStatus.isReverted);
|
||||
return this.addOrUpdateScript(script.executableId, change.newStatus.isReverted);
|
||||
}
|
||||
return this.removeScript(script.id);
|
||||
return this.removeScript(script.executableId);
|
||||
}
|
||||
|
||||
private addOrUpdateScript(scriptId: string, revert: boolean): number {
|
||||
private addOrUpdateScript(scriptId: ExecutableId, revert: boolean): number {
|
||||
const script = this.collection.getScript(scriptId);
|
||||
const selectedScript = new UserSelectedScript(script, revert);
|
||||
if (!this.scripts.exists(selectedScript.id)) {
|
||||
@@ -136,7 +137,7 @@ export class DebouncedScriptSelection implements ScriptSelection {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private removeScript(scriptId: string): number {
|
||||
private removeScript(scriptId: ExecutableId): number {
|
||||
if (!this.scripts.exists(scriptId)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -152,24 +153,24 @@ function assertNonEmptyScriptSelection(selectedItems: readonly Script[]) {
|
||||
}
|
||||
|
||||
function getScriptIdsToBeSelected(
|
||||
existingItems: ReadonlyRepository<string, SelectedScript>,
|
||||
existingItems: ReadonlyRepository<SelectedScript>,
|
||||
desiredScripts: readonly Script[],
|
||||
): string[] {
|
||||
return desiredScripts
|
||||
.filter((script) => !existingItems.exists(script.id))
|
||||
.map((script) => script.id);
|
||||
.filter((script) => !existingItems.exists(script.executableId))
|
||||
.map((script) => script.executableId);
|
||||
}
|
||||
|
||||
function getScriptIdsToBeDeselected(
|
||||
existingItems: ReadonlyRepository<string, SelectedScript>,
|
||||
existingItems: ReadonlyRepository<SelectedScript>,
|
||||
desiredScripts: readonly Script[],
|
||||
): string[] {
|
||||
return existingItems
|
||||
.getItems()
|
||||
.filter((existing) => !desiredScripts.some((script) => existing.id === script.id))
|
||||
.filter((existing) => !desiredScripts.some((script) => existing.id === script.executableId))
|
||||
.map((script) => script.id);
|
||||
}
|
||||
|
||||
function equals(a: SelectedScript, b: SelectedScript): boolean {
|
||||
return a.script.equals(b.script.id) && a.revert === b.revert;
|
||||
return a.script.executableId === b.script.executableId && a.revert === b.revert;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { IEventSource } from '@/infrastructure/Events/IEventSource';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import type { SelectedScript } from './SelectedScript';
|
||||
import type { ScriptSelectionChangeCommand } from './ScriptSelectionChange';
|
||||
|
||||
export interface ReadonlyScriptSelection {
|
||||
readonly changed: IEventSource<readonly SelectedScript[]>;
|
||||
readonly selectedScripts: readonly SelectedScript[];
|
||||
isSelected(scriptId: string): boolean;
|
||||
isSelected(scriptExecutableId: ExecutableId): boolean;
|
||||
}
|
||||
|
||||
export interface ScriptSelection extends ReadonlyScriptSelection {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
|
||||
export type ScriptSelectionStatus = {
|
||||
readonly isSelected: true;
|
||||
readonly isReverted: boolean;
|
||||
@@ -7,7 +9,7 @@ export type ScriptSelectionStatus = {
|
||||
};
|
||||
|
||||
export interface ScriptSelectionChange {
|
||||
readonly scriptId: string;
|
||||
readonly scriptId: ExecutableId;
|
||||
readonly newStatus: ScriptSelectionStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { IEntity } from '@/infrastructure/Entity/IEntity';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { RepositoryEntity } from '@/application/Repository/RepositoryEntity';
|
||||
|
||||
type ScriptId = Script['id'];
|
||||
|
||||
export interface SelectedScript extends IEntity<ScriptId> {
|
||||
export interface SelectedScript extends RepositoryEntity {
|
||||
readonly script: Script;
|
||||
readonly revert: boolean;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { SelectedScript } from './SelectedScript';
|
||||
import type { RepositoryEntity } from '@/application/Repository/RepositoryEntity';
|
||||
|
||||
type SelectedScriptId = SelectedScript['id'];
|
||||
export class UserSelectedScript implements RepositoryEntity {
|
||||
public readonly id: string;
|
||||
|
||||
export class UserSelectedScript extends BaseEntity<SelectedScriptId> {
|
||||
constructor(
|
||||
public readonly script: Script,
|
||||
public readonly revert: boolean,
|
||||
) {
|
||||
super(script.id);
|
||||
this.id = script.executableId;
|
||||
if (revert && !script.canRevert()) {
|
||||
throw new Error(`The script with ID '${script.id}' is not reversible and cannot be reverted.`);
|
||||
throw new Error(`The script with ID '${script.executableId}' is not reversible and cannot be reverted.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { ScriptToCategorySelectionMapper } from './Category/ScriptToCategorySelectionMapper';
|
||||
import { DebouncedScriptSelection } from './Script/DebouncedScriptSelection';
|
||||
import type { CategorySelection } from './Category/CategorySelection';
|
||||
|
||||
@@ -31,7 +31,7 @@ function validateCollectionsData(
|
||||
) {
|
||||
validator.assertNonEmptyCollection({
|
||||
value: collections,
|
||||
valueName: 'collections',
|
||||
valueName: 'Collections',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { CollectionData } from '@/application/collections/';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import { CategoryCollection } from '@/domain/CategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { CategoryCollection } from '@/domain/Collection/CategoryCollection';
|
||||
import type { ProjectDetails } from '@/domain/Project/ProjectDetails';
|
||||
import { createEnumParser, type EnumParser } from '../Common/Enum';
|
||||
import { parseCategory, type CategoryParser } from './Executable/CategoryParser';
|
||||
@@ -45,14 +45,14 @@ function validateCollection(
|
||||
): void {
|
||||
validator.assertObject({
|
||||
value: content,
|
||||
valueName: 'collection',
|
||||
valueName: 'Collection',
|
||||
allowedProperties: [
|
||||
'os', 'scripting', 'actions', 'functions',
|
||||
],
|
||||
});
|
||||
validator.assertNonEmptyCollection({
|
||||
value: content.actions,
|
||||
valueName: '"actions" in collection',
|
||||
valueName: '\'actions\' in collection',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +1,116 @@
|
||||
import { CustomError } from '@/application/Common/CustomError';
|
||||
import { indentText } from '@/application/Common/Text/IndentText';
|
||||
|
||||
export interface ErrorWithContextWrapper {
|
||||
(
|
||||
error: Error,
|
||||
innerError: Error,
|
||||
additionalContext: string,
|
||||
): Error;
|
||||
}
|
||||
|
||||
export const wrapErrorWithAdditionalContext: ErrorWithContextWrapper = (
|
||||
error: Error,
|
||||
additionalContext: string,
|
||||
innerError,
|
||||
additionalContext,
|
||||
) => {
|
||||
return (error instanceof ContextualError ? error : new ContextualError(error))
|
||||
.withAdditionalContext(additionalContext);
|
||||
if (!additionalContext) {
|
||||
throw new Error('Missing additional context');
|
||||
}
|
||||
return new ContextualError({
|
||||
innerError,
|
||||
additionalContext,
|
||||
});
|
||||
};
|
||||
|
||||
/* AggregateError is similar but isn't well-serialized or displayed by browsers */
|
||||
/**
|
||||
* Class for building a detailed error trace.
|
||||
*
|
||||
* Alternatives considered:
|
||||
* - `AggregateError`:
|
||||
* Similar but not well-serialized or displayed by browsers such as Chromium (last tested v126).
|
||||
* - `cause` property:
|
||||
* Not displayed by all browsers (last tested v126).
|
||||
* Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
|
||||
*
|
||||
* This is immutable where the constructor sets the values because using getter functions such as
|
||||
* `get cause()`, `get message()` does not work on Chromium (last tested v126), but works fine on
|
||||
* Firefox (last tested v127).
|
||||
*/
|
||||
class ContextualError extends CustomError {
|
||||
private readonly additionalContext = new Array<string>();
|
||||
|
||||
constructor(
|
||||
public readonly innerError: Error,
|
||||
) {
|
||||
super();
|
||||
constructor(public readonly context: ErrorContext) {
|
||||
super(
|
||||
generateDetailedErrorMessageWithContext(context),
|
||||
{
|
||||
cause: context.innerError,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public withAdditionalContext(additionalContext: string): this {
|
||||
this.additionalContext.push(additionalContext);
|
||||
return this;
|
||||
interface ErrorContext {
|
||||
readonly innerError: Error;
|
||||
readonly additionalContext: string;
|
||||
}
|
||||
|
||||
public get message(): string { // toString() is not used when Chromium logs it on console
|
||||
function generateDetailedErrorMessageWithContext(
|
||||
context: ErrorContext,
|
||||
): string {
|
||||
return [
|
||||
'\n',
|
||||
this.innerError.message,
|
||||
// Display the current error message first, then the root cause.
|
||||
// This prevents repetitive main messages for errors with a `cause:` chain,
|
||||
// aligning with browser error display conventions.
|
||||
context.additionalContext,
|
||||
'\n',
|
||||
'Error Trace (starting from root cause):',
|
||||
indentText(
|
||||
formatErrorTrace(
|
||||
// Displaying contexts from the top frame (deepest, most recent) aligns with
|
||||
// common debugger/compiler standard.
|
||||
extractErrorTraceAscendingFromDeepest(context),
|
||||
),
|
||||
),
|
||||
'\n',
|
||||
'Additional context:',
|
||||
...this.additionalContext.map((context, index) => `${index + 1}: ${context}`),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function extractErrorTraceAscendingFromDeepest(
|
||||
context: ErrorContext,
|
||||
): string[] {
|
||||
const originalError = findRootError(context.innerError);
|
||||
const contextsDescendingFromMostRecent: string[] = [
|
||||
context.additionalContext,
|
||||
...gatherContextsFromErrorChain(context.innerError),
|
||||
originalError.toString(),
|
||||
];
|
||||
const contextsAscendingFromDeepest = contextsDescendingFromMostRecent.reverse();
|
||||
return contextsAscendingFromDeepest;
|
||||
}
|
||||
|
||||
function findRootError(error: Error): Error {
|
||||
if (error instanceof ContextualError) {
|
||||
return findRootError(error.context.innerError);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
function gatherContextsFromErrorChain(
|
||||
error: Error,
|
||||
accumulatedContexts: string[] = [],
|
||||
): string[] {
|
||||
if (error instanceof ContextualError) {
|
||||
accumulatedContexts.push(error.context.additionalContext);
|
||||
return gatherContextsFromErrorChain(error.context.innerError, accumulatedContexts);
|
||||
}
|
||||
return accumulatedContexts;
|
||||
}
|
||||
|
||||
function formatErrorTrace(
|
||||
errorMessages: readonly string[],
|
||||
): string {
|
||||
if (errorMessages.length === 1) {
|
||||
return errorMessages[0];
|
||||
}
|
||||
return errorMessages
|
||||
.map((context, index) => `${index + 1}.${indentText(context)}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ function assertArray(
|
||||
valueName: string,
|
||||
): asserts value is Array<unknown> {
|
||||
if (!isArray(value)) {
|
||||
throw new Error(`'${valueName}' should be of type 'array', but is of type '${typeof value}'.`);
|
||||
throw new Error(`${valueName} should be of type 'array', but is of type '${typeof value}'.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ function assertString(
|
||||
valueName: string,
|
||||
): asserts value is string {
|
||||
if (!isString(value)) {
|
||||
throw new Error(`'${valueName}' should be of type 'string', but is of type '${typeof value}'.`);
|
||||
throw new Error(`${valueName} should be of type 'string', but is of type '${typeof value}'.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,14 @@ import type {
|
||||
} from '@/application/collections/';
|
||||
import { wrapErrorWithAdditionalContext, type ErrorWithContextWrapper } from '@/application/Parser/Common/ContextualError';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import { CollectionCategory } from '@/domain/Executables/Category/CollectionCategory';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { createCategory, type CategoryFactory } from '@/domain/Executables/Category/CategoryFactory';
|
||||
import { parseDocs, type DocsParser } from './DocumentationParser';
|
||||
import { parseScript, type ScriptParser } from './Script/ScriptParser';
|
||||
import { createExecutableDataValidator, type ExecutableValidator, type ExecutableValidatorFactory } from './Validation/ExecutableValidator';
|
||||
import { ExecutableType } from './Validation/ExecutableType';
|
||||
import type { CategoryCollectionSpecificUtilities } from './CategoryCollectionSpecificUtilities';
|
||||
|
||||
let categoryIdCounter = 0;
|
||||
|
||||
export const parseCategory: CategoryParser = (
|
||||
category: CategoryData,
|
||||
collectionUtilities: CategoryCollectionSpecificUtilities,
|
||||
@@ -59,7 +57,7 @@ function parseCategoryRecursively(
|
||||
}
|
||||
try {
|
||||
return context.categoryUtilities.createCategory({
|
||||
id: categoryIdCounter++,
|
||||
executableId: context.categoryData.category, // Pseudo-ID for uniqueness until real ID support
|
||||
name: context.categoryData.category,
|
||||
docs: context.categoryUtilities.parseDocs(context.categoryData),
|
||||
subcategories: children.subcategories,
|
||||
@@ -84,7 +82,7 @@ function ensureValidCategory(
|
||||
});
|
||||
validator.assertType((v) => v.assertObject({
|
||||
value: category,
|
||||
valueName: category.category ?? 'category',
|
||||
valueName: `Category '${category.category}'` ?? 'Category',
|
||||
allowedProperties: [
|
||||
'docs', 'children', 'category',
|
||||
],
|
||||
@@ -166,10 +164,6 @@ function hasProperty(
|
||||
return Object.prototype.hasOwnProperty.call(object, propertyName);
|
||||
}
|
||||
|
||||
export type CategoryFactory = (
|
||||
...parameters: ConstructorParameters<typeof CollectionCategory>
|
||||
) => Category;
|
||||
|
||||
interface CategoryParserUtilities {
|
||||
readonly createCategory: CategoryFactory;
|
||||
readonly wrapError: ErrorWithContextWrapper;
|
||||
@@ -179,7 +173,7 @@ interface CategoryParserUtilities {
|
||||
}
|
||||
|
||||
const DefaultCategoryParserUtilities: CategoryParserUtilities = {
|
||||
createCategory: (...parameters) => new CollectionCategory(...parameters),
|
||||
createCategory,
|
||||
wrapError: wrapErrorWithAdditionalContext,
|
||||
createValidator: createExecutableDataValidator,
|
||||
parseScript,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface IPipe {
|
||||
export interface Pipe {
|
||||
readonly name: string;
|
||||
apply(input: string): string;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { IPipe } from '../IPipe';
|
||||
import type { Pipe } from '../Pipe';
|
||||
|
||||
export class EscapeDoubleQuotes implements IPipe {
|
||||
export class EscapeDoubleQuotes implements Pipe {
|
||||
public readonly name: string = 'escapeDoubleQuotes';
|
||||
|
||||
public apply(raw: string): string {
|
||||
if (!raw) {
|
||||
return raw;
|
||||
return '';
|
||||
}
|
||||
return raw.replaceAll('"', '"^""');
|
||||
/* eslint-disable vue/max-len */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { IPipe } from '../IPipe';
|
||||
import { splitTextIntoLines } from '@/application/Common/Text/SplitTextIntoLines';
|
||||
import type { Pipe } from '../Pipe';
|
||||
|
||||
export class InlinePowerShell implements IPipe {
|
||||
export class InlinePowerShell implements Pipe {
|
||||
public readonly name: string = 'inlinePowerShell';
|
||||
|
||||
public apply(code: string): string {
|
||||
@@ -8,9 +9,11 @@ export class InlinePowerShell implements IPipe {
|
||||
return code;
|
||||
}
|
||||
const processor = new Array<(data: string) => string>(...[ // for broken ESlint "indent"
|
||||
// Order is important
|
||||
inlineComments,
|
||||
mergeLinesWithBacktick,
|
||||
mergeHereStrings,
|
||||
mergeLinesWithBacktick,
|
||||
mergeLinesWithBracketCodeBlocks,
|
||||
mergeNewLines,
|
||||
]).reduce((a, b) => (data) => b(a(data)));
|
||||
const newCode = processor(code);
|
||||
@@ -89,10 +92,6 @@ function inlineComments(code: string): string {
|
||||
*/
|
||||
}
|
||||
|
||||
function getLines(code: string): string[] {
|
||||
return (code?.split(/\r\n|\r|\n/) || []);
|
||||
}
|
||||
|
||||
/*
|
||||
Merges inline here-strings to a single lined string with Windows line terminator (\r\n)
|
||||
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4#here-strings
|
||||
@@ -102,18 +101,18 @@ function mergeHereStrings(code: string) {
|
||||
return code.replaceAll(regex, (_$, quotes, scope) => {
|
||||
const newString = getHereStringHandler(quotes);
|
||||
const escaped = scope.replaceAll(quotes, newString.escapedQuotes);
|
||||
const lines = getLines(escaped);
|
||||
const lines = splitTextIntoLines(escaped);
|
||||
const inlined = lines.join(newString.separator);
|
||||
const quoted = `${newString.quotesAround}${inlined}${newString.quotesAround}`;
|
||||
return quoted;
|
||||
});
|
||||
}
|
||||
interface IInlinedHereString {
|
||||
interface InlinedHereString {
|
||||
readonly quotesAround: string;
|
||||
readonly escapedQuotes: string;
|
||||
readonly separator: string;
|
||||
}
|
||||
function getHereStringHandler(quotes: string): IInlinedHereString {
|
||||
function getHereStringHandler(quotes: string): InlinedHereString {
|
||||
/*
|
||||
We handle @' and @" differently.
|
||||
Single quotes are interpreted literally and doubles are expandable.
|
||||
@@ -158,9 +157,33 @@ function mergeLinesWithBacktick(code: string) {
|
||||
return code.replaceAll(/ +`\s*(?:\r\n|\r|\n)\s*/g, ' ');
|
||||
}
|
||||
|
||||
function mergeNewLines(code: string) {
|
||||
return getLines(code)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
.join('; ');
|
||||
/**
|
||||
* Inlines code blocks in PowerShell scripts while preserving correct syntax.
|
||||
* It removes unnecessary newlines and spaces around brackets,
|
||||
* inlining the code where possible.
|
||||
* This prevents syntax errors like "Unexpected token '}'" when inlining brackets.
|
||||
*/
|
||||
function mergeLinesWithBracketCodeBlocks(code: string): string {
|
||||
return code
|
||||
// Opening bracket: [whitespace] Opening bracket (newline)
|
||||
.replace(/(?<=.*)\s*{[\r\n][\s\r\n]*/g, ' { ')
|
||||
// Closing bracket: [whitespace] Closing bracket (newline) (continuation keyword)
|
||||
.replace(/\s*}[\r\n][\s\r\n]*(?=elseif|else|catch|finally|until)/g, ' } ')
|
||||
.replace(/(?<=do\s*{.*)[\r\n\s]*}[\r\n][\r\n\s]*(?=while)/g, ' } '); // Do-While
|
||||
}
|
||||
|
||||
function mergeNewLines(code: string) {
|
||||
const nonEmptyLines = splitTextIntoLines(code)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
|
||||
return nonEmptyLines
|
||||
.map((line, index) => {
|
||||
const isLastLine = index === nonEmptyLines.length - 1;
|
||||
if (isLastLine) {
|
||||
return line;
|
||||
}
|
||||
return line.endsWith(';') ? line : `${line};`;
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { InlinePowerShell } from './PipeDefinitions/InlinePowerShell';
|
||||
import { EscapeDoubleQuotes } from './PipeDefinitions/EscapeDoubleQuotes';
|
||||
import type { IPipe } from './IPipe';
|
||||
import type { Pipe } from './Pipe';
|
||||
|
||||
const RegisteredPipes = [
|
||||
new EscapeDoubleQuotes(),
|
||||
@@ -8,19 +8,19 @@ const RegisteredPipes = [
|
||||
];
|
||||
|
||||
export interface IPipeFactory {
|
||||
get(pipeName: string): IPipe;
|
||||
get(pipeName: string): Pipe;
|
||||
}
|
||||
|
||||
export class PipeFactory implements IPipeFactory {
|
||||
private readonly pipes = new Map<string, IPipe>();
|
||||
private readonly pipes = new Map<string, Pipe>();
|
||||
|
||||
constructor(pipes: readonly IPipe[] = RegisteredPipes) {
|
||||
constructor(pipes: readonly Pipe[] = RegisteredPipes) {
|
||||
for (const pipe of pipes) {
|
||||
this.registerPipe(pipe);
|
||||
}
|
||||
}
|
||||
|
||||
public get(pipeName: string): IPipe {
|
||||
public get(pipeName: string): Pipe {
|
||||
validatePipeName(pipeName);
|
||||
const pipe = this.pipes.get(pipeName);
|
||||
if (!pipe) {
|
||||
@@ -29,7 +29,7 @@ export class PipeFactory implements IPipeFactory {
|
||||
return pipe;
|
||||
}
|
||||
|
||||
private registerPipe(pipe: IPipe): void {
|
||||
private registerPipe(pipe: Pipe): void {
|
||||
validatePipeName(pipe.name);
|
||||
if (this.pipes.has(pipe.name)) {
|
||||
throw new Error(`Pipe name must be unique: "${pipe.name}"`);
|
||||
|
||||
@@ -22,7 +22,7 @@ export const createFunctionCallArgument: FunctionCallArgumentFactory = (
|
||||
utilities.validateParameterName(parameterName);
|
||||
utilities.typeValidator.assertNonEmptyString({
|
||||
value: argumentValue,
|
||||
valueName: `Missing argument value for the parameter "${parameterName}".`,
|
||||
valueName: `Function parameter '${parameterName}'`,
|
||||
});
|
||||
return {
|
||||
parameterName,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { filterEmptyStrings } from '@/application/Common/Text/FilterEmptyStrings';
|
||||
import type { CompiledCode } from '../CompiledCode';
|
||||
import type { CodeSegmentMerger } from './CodeSegmentMerger';
|
||||
|
||||
@@ -8,11 +9,9 @@ export class NewlineCodeSegmentMerger implements CodeSegmentMerger {
|
||||
}
|
||||
return {
|
||||
code: joinCodeParts(codeSegments.map((f) => f.code)),
|
||||
revertCode: joinCodeParts(
|
||||
codeSegments
|
||||
.map((f) => f.revertCode)
|
||||
.filter((code): code is string => Boolean(code)),
|
||||
),
|
||||
revertCode: joinCodeParts(filterEmptyStrings(
|
||||
codeSegments.map((f) => f.revertCode),
|
||||
)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { IExpressionsCompiler } from '@/application/Parser/Executable/Scrip
|
||||
import { FunctionBodyType, type ISharedFunction } from '@/application/Parser/Executable/Script/Compiler/Function/ISharedFunction';
|
||||
import type { FunctionCall } from '@/application/Parser/Executable/Script/Compiler/Function/Call/FunctionCall';
|
||||
import type { CompiledCode } from '@/application/Parser/Executable/Script/Compiler/Function/Call/Compiler/CompiledCode';
|
||||
import { indentText } from '@/application/Common/Text/IndentText';
|
||||
import type { SingleCallCompilerStrategy } from '../SingleCallCompilerStrategy';
|
||||
|
||||
export class InlineFunctionCallCompiler implements SingleCallCompilerStrategy {
|
||||
@@ -22,10 +23,12 @@ export class InlineFunctionCallCompiler implements SingleCallCompilerStrategy {
|
||||
if (calledFunction.body.type !== FunctionBodyType.Code) {
|
||||
throw new Error([
|
||||
'Unexpected function body type.',
|
||||
`\tExpected: "${FunctionBodyType[FunctionBodyType.Code]}"`,
|
||||
`\tActual: "${FunctionBodyType[calledFunction.body.type]}"`,
|
||||
indentText([
|
||||
`Expected: "${FunctionBodyType[FunctionBodyType.Code]}"`,
|
||||
`Actual: "${FunctionBodyType[calledFunction.body.type]}"`,
|
||||
].join('\n')),
|
||||
'Function:',
|
||||
`\t${JSON.stringify(callToFunction)}`,
|
||||
indentText(JSON.stringify(callToFunction)),
|
||||
].join('\n'));
|
||||
}
|
||||
const { code } = calledFunction.body;
|
||||
|
||||
@@ -42,7 +42,7 @@ function getCallSequence(calls: FunctionCallsData, validator: TypeValidator): Fu
|
||||
if (isArray(calls)) {
|
||||
validator.assertNonEmptyCollection({
|
||||
value: calls,
|
||||
valueName: 'function call sequence',
|
||||
valueName: 'Function call sequence',
|
||||
});
|
||||
return calls as FunctionCallData[];
|
||||
}
|
||||
@@ -56,7 +56,7 @@ function parseFunctionCall(
|
||||
): FunctionCall {
|
||||
utilities.typeValidator.assertObject({
|
||||
value: call,
|
||||
valueName: 'function call',
|
||||
valueName: 'Function call',
|
||||
allowedProperties: ['function', 'parameters'],
|
||||
});
|
||||
const callArgs = parseArgs(call.parameters, utilities.createCallArgument);
|
||||
|
||||
@@ -13,7 +13,7 @@ export const validateParameterName = (
|
||||
) => {
|
||||
typeValidator.assertNonEmptyString({
|
||||
value: parameterName,
|
||||
valueName: 'parameter name',
|
||||
valueName: 'Parameter name',
|
||||
rule: {
|
||||
expectedMatch: /^[0-9a-zA-Z]+$/,
|
||||
errorMessage: `parameter name must be alphanumeric but it was "${parameterName}".`,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { NoDuplicatedLines } from '@/application/Parser/Executable/Script/Valida
|
||||
import type { ICodeValidator } from '@/application/Parser/Executable/Script/Validation/ICodeValidator';
|
||||
import { isArray, isNullOrUndefined, isPlainObject } from '@/TypeHelpers';
|
||||
import { wrapErrorWithAdditionalContext, type ErrorWithContextWrapper } from '@/application/Parser/Common/ContextualError';
|
||||
import { filterEmptyStrings } from '@/application/Common/Text/FilterEmptyStrings';
|
||||
import { createFunctionWithInlineCode, createCallerFunction } from './SharedFunction';
|
||||
import { SharedFunctionCollection } from './SharedFunctionCollection';
|
||||
import { parseFunctionCalls, type FunctionCallsParser } from './Call/FunctionCallsParser';
|
||||
@@ -82,8 +83,7 @@ function validateCode(
|
||||
syntax: ILanguageSyntax,
|
||||
validator: ICodeValidator,
|
||||
): void {
|
||||
[data.code, data.revertCode]
|
||||
.filter((code): code is string => Boolean(code))
|
||||
filterEmptyStrings([data.code, data.revertCode])
|
||||
.forEach(
|
||||
(code) => validator.throwIfInvalid(
|
||||
code,
|
||||
@@ -204,9 +204,9 @@ function ensureNoDuplicateCode(functions: readonly FunctionData[]) {
|
||||
if (duplicateCodes.length > 0) {
|
||||
throw new Error(`duplicate "code" in functions: ${printList(duplicateCodes)}`);
|
||||
}
|
||||
const duplicateRevertCodes = getDuplicates(callFunctions
|
||||
.map((func) => func.revertCode)
|
||||
.filter((code): code is string => Boolean(code)));
|
||||
const duplicateRevertCodes = getDuplicates(filterEmptyStrings(
|
||||
callFunctions.map((func) => func.revertCode),
|
||||
));
|
||||
if (duplicateRevertCodes.length > 0) {
|
||||
throw new Error(`duplicate "revertCode" in functions: ${printList(duplicateRevertCodes)}`);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { NoEmptyLines } from '@/application/Parser/Executable/Script/Validation/
|
||||
import type { ICodeValidator } from '@/application/Parser/Executable/Script/Validation/ICodeValidator';
|
||||
import { wrapErrorWithAdditionalContext, type ErrorWithContextWrapper } from '@/application/Parser/Common/ContextualError';
|
||||
import { createScriptCode, type ScriptCodeFactory } from '@/domain/Executables/Script/Code/ScriptCodeFactory';
|
||||
import { filterEmptyStrings } from '@/application/Common/Text/FilterEmptyStrings';
|
||||
import { FunctionCallSequenceCompiler } from './Function/Call/Compiler/FunctionCallSequenceCompiler';
|
||||
import { parseFunctionCalls } from './Function/Call/FunctionCallsParser';
|
||||
import { parseSharedFunctions, type SharedFunctionsParser } from './Function/SharedFunctionsParser';
|
||||
@@ -71,9 +72,7 @@ export class ScriptCompiler implements IScriptCompiler {
|
||||
}
|
||||
|
||||
function validateCompiledCode(compiledCode: CompiledCode, validator: ICodeValidator): void {
|
||||
[compiledCode.code, compiledCode.revertCode]
|
||||
.filter((code): code is string => Boolean(code))
|
||||
.map((code) => code as string)
|
||||
filterEmptyStrings([compiledCode.code, compiledCode.revertCode])
|
||||
.forEach(
|
||||
(code) => validator.throwIfInvalid(
|
||||
code,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { ScriptData, CodeScriptData, CallScriptData } from '@/application/collections/';
|
||||
import { NoEmptyLines } from '@/application/Parser/Executable/Script/Validation/Rules/NoEmptyLines';
|
||||
import type { ILanguageSyntax } from '@/application/Parser/Executable/Script/Validation/Syntax/ILanguageSyntax';
|
||||
import { CollectionScript } from '@/domain/Executables/Script/CollectionScript';
|
||||
import { RecommendationLevel } from '@/domain/Executables/Script/RecommendationLevel';
|
||||
import type { ScriptCode } from '@/domain/Executables/Script/Code/ScriptCode';
|
||||
import type { ICodeValidator } from '@/application/Parser/Executable/Script/Validation/ICodeValidator';
|
||||
@@ -10,6 +9,8 @@ import type { ScriptCodeFactory } from '@/domain/Executables/Script/Code/ScriptC
|
||||
import { createScriptCode } from '@/domain/Executables/Script/Code/ScriptCodeFactory';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { createEnumParser, type EnumParser } from '@/application/Common/Enum';
|
||||
import { filterEmptyStrings } from '@/application/Common/Text/FilterEmptyStrings';
|
||||
import { createScript, type ScriptFactory } from '@/domain/Executables/Script/ScriptFactory';
|
||||
import { parseDocs, type DocsParser } from '../DocumentationParser';
|
||||
import { ExecutableType } from '../Validation/ExecutableType';
|
||||
import { createExecutableDataValidator, type ExecutableValidator, type ExecutableValidatorFactory } from '../Validation/ExecutableValidator';
|
||||
@@ -37,6 +38,7 @@ export const parseScript: ScriptParser = (
|
||||
validateScript(data, validator);
|
||||
try {
|
||||
const script = scriptUtilities.createScript({
|
||||
executableId: data.name, // Pseudo-ID for uniqueness until real ID support
|
||||
name: data.name,
|
||||
code: parseCode(
|
||||
data,
|
||||
@@ -86,8 +88,7 @@ function validateHardcodedCodeWithoutCalls(
|
||||
validator: ICodeValidator,
|
||||
syntax: ILanguageSyntax,
|
||||
) {
|
||||
[scriptCode.execute, scriptCode.revert]
|
||||
.filter((code): code is string => Boolean(code))
|
||||
filterEmptyStrings([scriptCode.execute, scriptCode.revert])
|
||||
.forEach(
|
||||
(code) => validator.throwIfInvalid(
|
||||
code,
|
||||
@@ -102,7 +103,7 @@ function validateScript(
|
||||
): asserts script is NonNullable<ScriptData> {
|
||||
validator.assertType((v) => v.assertObject<CallScriptData & CodeScriptData>({
|
||||
value: script,
|
||||
valueName: script.name ?? 'script',
|
||||
valueName: `Script '${script.name}'` ?? 'Script',
|
||||
allowedProperties: [
|
||||
'name', 'recommend', 'code', 'revertCode', 'call', 'docs',
|
||||
],
|
||||
@@ -132,14 +133,6 @@ interface ScriptParserUtilities {
|
||||
readonly parseDocs: DocsParser;
|
||||
}
|
||||
|
||||
export type ScriptFactory = (
|
||||
...parameters: ConstructorParameters<typeof CollectionScript>
|
||||
) => Script;
|
||||
|
||||
const createScript: ScriptFactory = (...parameters) => {
|
||||
return new CollectionScript(...parameters);
|
||||
};
|
||||
|
||||
const DefaultUtilities: ScriptParserUtilities = {
|
||||
levelParser: createEnumParser(RecommendationLevel),
|
||||
createScript,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { splitTextIntoLines } from '@/application/Common/Text/SplitTextIntoLines';
|
||||
import type { ICodeLine } from './ICodeLine';
|
||||
import type { ICodeValidationRule, IInvalidCodeLine } from './ICodeValidationRule';
|
||||
import type { ICodeValidator } from './ICodeValidator';
|
||||
@@ -24,9 +25,8 @@ export class CodeValidator implements ICodeValidator {
|
||||
}
|
||||
|
||||
function extractLines(code: string): ICodeLine[] {
|
||||
return code
|
||||
.split(/\r\n|\r|\n/)
|
||||
.map((lineText, lineIndex): ICodeLine => ({
|
||||
const lines = splitTextIntoLines(code);
|
||||
return lines.map((lineText, lineIndex): ICodeLine => ({
|
||||
index: lineIndex + 1,
|
||||
text: lineText,
|
||||
}));
|
||||
|
||||
@@ -37,7 +37,7 @@ function validateData(
|
||||
): void {
|
||||
validator.assertObject({
|
||||
value: data,
|
||||
valueName: 'scripting definition',
|
||||
valueName: 'Scripting definition',
|
||||
allowedProperties: ['language', 'fileExtension', 'startCode', 'endCode'],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import type { IEntity } from '@/infrastructure/Entity/IEntity';
|
||||
import type { RepositoryEntity } from './RepositoryEntity';
|
||||
|
||||
export interface ReadonlyRepository<TKey, TEntity extends IEntity<TKey>> {
|
||||
type EntityId = RepositoryEntity['id'];
|
||||
|
||||
export interface ReadonlyRepository<TEntity extends RepositoryEntity> {
|
||||
readonly length: number;
|
||||
getItems(predicate?: (entity: TEntity) => boolean): readonly TEntity[];
|
||||
getById(id: TKey): TEntity;
|
||||
exists(id: TKey): boolean;
|
||||
getById(id: EntityId): TEntity;
|
||||
exists(id: EntityId): boolean;
|
||||
}
|
||||
|
||||
export interface MutableRepository<TKey, TEntity extends IEntity<TKey>> {
|
||||
export interface MutableRepository<TEntity extends RepositoryEntity> {
|
||||
addItem(item: TEntity): void;
|
||||
addOrUpdateItem(item: TEntity): void;
|
||||
removeItem(id: TKey): void;
|
||||
removeItem(id: EntityId): void;
|
||||
}
|
||||
|
||||
export interface Repository<TKey, TEntity extends IEntity<TKey>>
|
||||
extends ReadonlyRepository<TKey, TEntity>, MutableRepository<TKey, TEntity> { }
|
||||
export interface Repository<TEntity extends RepositoryEntity>
|
||||
extends ReadonlyRepository<TEntity>, MutableRepository<TEntity> { }
|
||||
|
||||
6
src/application/Repository/RepositoryEntity.ts
Normal file
6
src/application/Repository/RepositoryEntity.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/** Aggregate root */
|
||||
export type RepositoryEntityId = string;
|
||||
|
||||
export interface RepositoryEntity {
|
||||
readonly id: RepositoryEntityId;
|
||||
}
|
||||
@@ -69,6 +69,12 @@ definitions:
|
||||
- $ref: '#/definitions/CodeScript'
|
||||
- $ref: '#/definitions/CallScript'
|
||||
|
||||
RecommendationLevel:
|
||||
oneOf:
|
||||
- type: string
|
||||
enum: [standard, strict]
|
||||
- type: 'null'
|
||||
|
||||
ScriptDefinition:
|
||||
type: object
|
||||
allOf:
|
||||
@@ -78,8 +84,7 @@ definitions:
|
||||
name:
|
||||
type: string
|
||||
recommend:
|
||||
type: string
|
||||
enum: [standard, strict]
|
||||
$ref: '#/definitions/RecommendationLevel'
|
||||
|
||||
CodeScript:
|
||||
type: object
|
||||
|
||||
@@ -1800,7 +1800,7 @@ actions:
|
||||
# References for spctl --master-disable
|
||||
- https://web.archive.org/web/20240523173608/https://www.manpagez.com/man/8/spctl/
|
||||
# References for /var/db/SystemPolicy-prefs.plist
|
||||
- https://krypted.com/mac-security/manage-gatekeeper-from-the-command-line-in-mountain-lion/
|
||||
- https://web.archive.org/web/20240810103202/https://krypted.com/mac-security/manage-gatekeeper-from-the-command-line-in-mountain-lion/
|
||||
- https://community.jamf.com/t5/jamf-pro/users-can-t-change-password-greyed-out/m-p/54228
|
||||
code: |-
|
||||
os_major_ver=$(sw_vers -productVersion | awk -F "." '{print $1}')
|
||||
@@ -1842,10 +1842,10 @@ actions:
|
||||
fi
|
||||
-
|
||||
name: Disable library validation entitlement (library signature validation)
|
||||
docs:
|
||||
- https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-library-validation
|
||||
- https://www.macenhance.com/docs/general/sip-library-validation.html
|
||||
- https://www.naut.ca/blog/2020/11/13/forbidden-commands-to-liberate-macos/
|
||||
docs: |-
|
||||
- [Disable Library Validation Entitlement | Apple Developer Documentation | developer.apple.com](https://archive.ph/2024.07.19-101811/https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-library-validation)
|
||||
- [Forbidden Commands to Speed Up macOS | www.naut.ca](https://web.archive.org/web/20240625020749/https://www.naut.ca/blog/2020/11/13/forbidden-commands-to-liberate-macos/)
|
||||
- [macEnhance | macEnhance.com](https://web.archive.org/web/20220622212008/https://www.macenhance.com/docs/general/sip-library-validation.html)
|
||||
code: sudo defaults write /Library/Preferences/com.apple.security.libraryvalidation.plist 'DisableLibraryValidation' -bool true
|
||||
revertCode: sudo defaults write /Library/Preferences/com.apple.security.libraryvalidation.plist 'DisableLibraryValidation' -bool false
|
||||
-
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
import type { IApplication } from './IApplication';
|
||||
import type { ICategoryCollection } from './ICategoryCollection';
|
||||
import type { ICategoryCollection } from './Collection/ICategoryCollection';
|
||||
import type { ProjectDetails } from './Project/ProjectDetails';
|
||||
|
||||
export class Application implements IApplication {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { getEnumValues, assertInRange } from '@/application/Common/Enum';
|
||||
import { RecommendationLevel } from './Executables/Script/RecommendationLevel';
|
||||
import { OperatingSystem } from './OperatingSystem';
|
||||
import type { IEntity } from '../infrastructure/Entity/IEntity';
|
||||
import type { Category } from './Executables/Category/Category';
|
||||
import type { Script } from './Executables/Script/Script';
|
||||
import type { IScriptingDefinition } from './IScriptingDefinition';
|
||||
import { RecommendationLevel } from '../Executables/Script/RecommendationLevel';
|
||||
import { OperatingSystem } from '../OperatingSystem';
|
||||
import { validateCategoryCollection } from './Validation/CompositeCategoryCollectionValidator';
|
||||
import type { ExecutableId } from '../Executables/Identifiable';
|
||||
import type { Category } from '../Executables/Category/Category';
|
||||
import type { Script } from '../Executables/Script/Script';
|
||||
import type { IScriptingDefinition } from '../IScriptingDefinition';
|
||||
import type { ICategoryCollection } from './ICategoryCollection';
|
||||
import type { CategoryCollectionValidator } from './Validation/CategoryCollectionValidator';
|
||||
|
||||
export class CategoryCollection implements ICategoryCollection {
|
||||
public readonly os: OperatingSystem;
|
||||
@@ -22,22 +24,24 @@ export class CategoryCollection implements ICategoryCollection {
|
||||
|
||||
constructor(
|
||||
parameters: CategoryCollectionInitParameters,
|
||||
validate: CategoryCollectionValidator = validateCategoryCollection,
|
||||
) {
|
||||
this.os = parameters.os;
|
||||
this.actions = parameters.actions;
|
||||
this.scripting = parameters.scripting;
|
||||
|
||||
this.queryable = makeQueryable(this.actions);
|
||||
assertInRange(this.os, OperatingSystem);
|
||||
ensureValid(this.queryable);
|
||||
ensureNoDuplicates(this.queryable.allCategories);
|
||||
ensureNoDuplicates(this.queryable.allScripts);
|
||||
validate({
|
||||
allScripts: this.queryable.allScripts,
|
||||
allCategories: this.queryable.allCategories,
|
||||
operatingSystem: this.os,
|
||||
});
|
||||
}
|
||||
|
||||
public getCategory(categoryId: number): Category {
|
||||
const category = this.queryable.allCategories.find((c) => c.id === categoryId);
|
||||
public getCategory(executableId: ExecutableId): Category {
|
||||
const category = this.queryable.allCategories.find((c) => c.executableId === executableId);
|
||||
if (!category) {
|
||||
throw new Error(`Missing category with ID: "${categoryId}"`);
|
||||
throw new Error(`Missing category with ID: "${executableId}"`);
|
||||
}
|
||||
return category;
|
||||
}
|
||||
@@ -48,10 +52,10 @@ export class CategoryCollection implements ICategoryCollection {
|
||||
return scripts ?? [];
|
||||
}
|
||||
|
||||
public getScript(scriptId: string): Script {
|
||||
const script = this.queryable.allScripts.find((s) => s.id === scriptId);
|
||||
public getScript(executableId: ExecutableId): Script {
|
||||
const script = this.queryable.allScripts.find((s) => s.executableId === executableId);
|
||||
if (!script) {
|
||||
throw new Error(`missing script: ${scriptId}`);
|
||||
throw new Error(`Missing script: ${executableId}`);
|
||||
}
|
||||
return script;
|
||||
}
|
||||
@@ -65,21 +69,6 @@ export class CategoryCollection implements ICategoryCollection {
|
||||
}
|
||||
}
|
||||
|
||||
function ensureNoDuplicates<TKey>(entities: ReadonlyArray<IEntity<TKey>>) {
|
||||
const isUniqueInArray = (id: TKey, index: number, array: readonly TKey[]) => array
|
||||
.findIndex((otherId) => otherId === id) !== index;
|
||||
const duplicatedIds = entities
|
||||
.map((entity) => entity.id)
|
||||
.filter((id, index, array) => !isUniqueInArray(id, index, array))
|
||||
.filter(isUniqueInArray);
|
||||
if (duplicatedIds.length > 0) {
|
||||
const duplicatedIdsText = duplicatedIds.map((id) => `"${id}"`).join(',');
|
||||
throw new Error(
|
||||
`Duplicate entities are detected with following id(s): ${duplicatedIdsText}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export interface CategoryCollectionInitParameters {
|
||||
readonly os: OperatingSystem;
|
||||
readonly actions: ReadonlyArray<Category>;
|
||||
@@ -92,35 +81,12 @@ interface QueryableCollection {
|
||||
readonly scriptsByLevel: Map<RecommendationLevel, readonly Script[]>;
|
||||
}
|
||||
|
||||
function ensureValid(application: QueryableCollection) {
|
||||
ensureValidCategories(application.allCategories);
|
||||
ensureValidScripts(application.allScripts);
|
||||
}
|
||||
|
||||
function ensureValidCategories(allCategories: readonly Category[]) {
|
||||
if (!allCategories.length) {
|
||||
throw new Error('must consist of at least one category');
|
||||
}
|
||||
}
|
||||
|
||||
function ensureValidScripts(allScripts: readonly Script[]) {
|
||||
if (!allScripts.length) {
|
||||
throw new Error('must consist of at least one script');
|
||||
}
|
||||
const missingRecommendationLevels = getEnumValues(RecommendationLevel)
|
||||
.filter((level) => allScripts.every((script) => script.level !== level));
|
||||
if (missingRecommendationLevels.length > 0) {
|
||||
throw new Error('none of the scripts are recommended as'
|
||||
+ ` "${missingRecommendationLevels.map((level) => RecommendationLevel[level]).join(', "')}".`);
|
||||
}
|
||||
}
|
||||
|
||||
function flattenApplication(
|
||||
function flattenCategoryHierarchy(
|
||||
categories: ReadonlyArray<Category>,
|
||||
): [Category[], Script[]] {
|
||||
const [subCategories, subScripts] = (categories || [])
|
||||
// Parse children
|
||||
.map((category) => flattenApplication(category.subCategories))
|
||||
.map((category) => flattenCategoryHierarchy(category.subcategories))
|
||||
// Flatten results
|
||||
.reduce(([previousCategories, previousScripts], [currentCategories, currentScripts]) => {
|
||||
return [
|
||||
@@ -143,7 +109,7 @@ function flattenApplication(
|
||||
function makeQueryable(
|
||||
actions: ReadonlyArray<Category>,
|
||||
): QueryableCollection {
|
||||
const flattened = flattenApplication(actions);
|
||||
const flattened = flattenCategoryHierarchy(actions);
|
||||
return {
|
||||
allCategories: flattened[0],
|
||||
allScripts: flattened[1],
|
||||
@@ -3,6 +3,7 @@ import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { RecommendationLevel } from '@/domain/Executables/Script/RecommendationLevel';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ExecutableId } from '../Executables/Identifiable';
|
||||
|
||||
export interface ICategoryCollection {
|
||||
readonly scripting: IScriptingDefinition;
|
||||
@@ -12,8 +13,8 @@ export interface ICategoryCollection {
|
||||
readonly actions: ReadonlyArray<Category>;
|
||||
|
||||
getScriptsByLevel(level: RecommendationLevel): ReadonlyArray<Script>;
|
||||
getCategory(categoryId: number): Category;
|
||||
getScript(scriptId: string): Script;
|
||||
getCategory(categoryId: ExecutableId): Category;
|
||||
getScript(scriptId: ExecutableId): Script;
|
||||
getAllScripts(): ReadonlyArray<Script>;
|
||||
getAllCategories(): ReadonlyArray<Category>;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export interface CategoryCollectionValidationContext {
|
||||
readonly allScripts: readonly Script[];
|
||||
readonly allCategories: readonly Category[];
|
||||
readonly operatingSystem: OperatingSystem;
|
||||
}
|
||||
|
||||
export interface CategoryCollectionValidator {
|
||||
(
|
||||
context: CategoryCollectionValidationContext,
|
||||
): void;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ensurePresenceOfAtLeastOneScript } from './Rules/EnsurePresenceOfAtLeastOneScript';
|
||||
import { ensurePresenceOfAtLeastOneCategory } from './Rules/EnsurePresenceOfAtLeastOneCategory';
|
||||
import { ensureUniqueIdsAcrossExecutables } from './Rules/EnsureUniqueIdsAcrossExecutables';
|
||||
import { ensureKnownOperatingSystem } from './Rules/EnsureKnownOperatingSystem';
|
||||
import type { CategoryCollectionValidationContext, CategoryCollectionValidator } from './CategoryCollectionValidator';
|
||||
|
||||
export type CompositeCategoryCollectionValidator = CategoryCollectionValidator & {
|
||||
(
|
||||
...args: [
|
||||
...Parameters<CategoryCollectionValidator>,
|
||||
(readonly CategoryCollectionValidator[])?,
|
||||
]
|
||||
): void;
|
||||
};
|
||||
|
||||
export const validateCategoryCollection: CompositeCategoryCollectionValidator = (
|
||||
context: CategoryCollectionValidationContext,
|
||||
validators: readonly CategoryCollectionValidator[] = DefaultValidators,
|
||||
) => {
|
||||
if (!validators.length) {
|
||||
throw new Error('No validators provided.');
|
||||
}
|
||||
for (const validate of validators) {
|
||||
validate(context);
|
||||
}
|
||||
};
|
||||
|
||||
const DefaultValidators: readonly CategoryCollectionValidator[] = [
|
||||
ensureKnownOperatingSystem,
|
||||
ensurePresenceOfAtLeastOneScript,
|
||||
ensurePresenceOfAtLeastOneCategory,
|
||||
ensureUniqueIdsAcrossExecutables,
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
import { assertInRange } from '@/application/Common/Enum';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import type { CategoryCollectionValidator } from '../CategoryCollectionValidator';
|
||||
|
||||
export const ensureKnownOperatingSystem: CategoryCollectionValidator = (
|
||||
context,
|
||||
) => {
|
||||
assertInRange(context.operatingSystem, OperatingSystem);
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import { getEnumValues } from '@/application/Common/Enum';
|
||||
import { RecommendationLevel } from '@/domain/Executables/Script/RecommendationLevel';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { CategoryCollectionValidator } from '../CategoryCollectionValidator';
|
||||
|
||||
export const ensurePresenceOfAllRecommendationLevels: CategoryCollectionValidator = (
|
||||
context,
|
||||
) => {
|
||||
const unrepresentedRecommendationLevels = getUnrepresentedRecommendationLevels(
|
||||
context.allScripts,
|
||||
);
|
||||
if (unrepresentedRecommendationLevels.length === 0) {
|
||||
return;
|
||||
}
|
||||
const formattedRecommendationLevels = unrepresentedRecommendationLevels
|
||||
.map((level) => getDisplayName(level))
|
||||
.join(', ');
|
||||
throw new Error(`Missing recommendation levels: ${formattedRecommendationLevels}.`);
|
||||
};
|
||||
|
||||
function getUnrepresentedRecommendationLevels(
|
||||
scripts: readonly Script[],
|
||||
): (RecommendationLevel | undefined)[] {
|
||||
const expectedLevels = [
|
||||
undefined,
|
||||
...getEnumValues(RecommendationLevel),
|
||||
];
|
||||
return expectedLevels.filter(
|
||||
(level) => scripts.every((script) => script.level !== level),
|
||||
);
|
||||
}
|
||||
|
||||
function getDisplayName(level: RecommendationLevel | undefined): string {
|
||||
return level === undefined ? 'None' : RecommendationLevel[level];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { CategoryCollectionValidator } from '../CategoryCollectionValidator';
|
||||
|
||||
export const ensurePresenceOfAtLeastOneCategory: CategoryCollectionValidator = (
|
||||
context,
|
||||
) => {
|
||||
if (!context.allCategories.length) {
|
||||
throw new Error('Collection must have at least one category');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { CategoryCollectionValidator } from '../CategoryCollectionValidator';
|
||||
|
||||
export const ensurePresenceOfAtLeastOneScript: CategoryCollectionValidator = (
|
||||
context,
|
||||
) => {
|
||||
if (!context.allScripts.length) {
|
||||
throw new Error('Collection must have at least one script');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { Identifiable } from '@/domain/Executables/Identifiable';
|
||||
import type { CategoryCollectionValidator } from '../CategoryCollectionValidator';
|
||||
|
||||
export const ensureUniqueIdsAcrossExecutables: CategoryCollectionValidator = (
|
||||
context,
|
||||
) => {
|
||||
const allExecutables: readonly Identifiable[] = [
|
||||
...context.allCategories,
|
||||
...context.allScripts,
|
||||
];
|
||||
ensureNoDuplicateIds(allExecutables);
|
||||
};
|
||||
|
||||
function ensureNoDuplicateIds(
|
||||
executables: readonly Identifiable[],
|
||||
) {
|
||||
const duplicateExecutables = getExecutablesWithDuplicateIds(executables);
|
||||
if (duplicateExecutables.length === 0) {
|
||||
return;
|
||||
}
|
||||
const formattedDuplicateIds = duplicateExecutables.map(
|
||||
(executable) => `"${executable.executableId}"`,
|
||||
).join(', ');
|
||||
throw new Error(`Duplicate executable IDs found: ${formattedDuplicateIds}`);
|
||||
}
|
||||
|
||||
function getExecutablesWithDuplicateIds(
|
||||
executables: readonly Identifiable[],
|
||||
): Identifiable[] {
|
||||
return executables
|
||||
.filter(
|
||||
(executable, index, array) => {
|
||||
const otherIndex = array.findIndex(
|
||||
(otherExecutable) => haveIdenticalIds(executable, otherExecutable),
|
||||
);
|
||||
return otherIndex !== index;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function haveIdenticalIds(first: Identifiable, second: Identifiable): boolean {
|
||||
return first.executableId === second.executableId;
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { Script } from '../Script/Script';
|
||||
import type { Executable } from '../Executable';
|
||||
|
||||
export interface Category extends Executable<number> {
|
||||
readonly id: number;
|
||||
export interface Category extends Executable {
|
||||
readonly name: string;
|
||||
readonly subCategories: ReadonlyArray<Category>;
|
||||
readonly subcategories: ReadonlyArray<Category>;
|
||||
readonly scripts: ReadonlyArray<Script>;
|
||||
includes(script: Script): boolean;
|
||||
getAllScriptsRecursively(): ReadonlyArray<Script>;
|
||||
|
||||
@@ -1,29 +1,51 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import type { Category } from './Category';
|
||||
import type { Script } from '../Script/Script';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { ExecutableId } from '../Identifiable';
|
||||
|
||||
export class CollectionCategory extends BaseEntity<number> implements Category {
|
||||
private allSubScripts?: ReadonlyArray<Script> = undefined;
|
||||
export type CategoryFactory = (
|
||||
parameters: CategoryInitParameters,
|
||||
) => Category;
|
||||
|
||||
export interface CategoryInitParameters {
|
||||
readonly executableId: ExecutableId;
|
||||
readonly name: string;
|
||||
readonly docs: ReadonlyArray<string>;
|
||||
readonly subcategories: ReadonlyArray<Category>;
|
||||
readonly scripts: ReadonlyArray<Script>;
|
||||
}
|
||||
|
||||
export const createCategory: CategoryFactory = (
|
||||
parameters,
|
||||
) => {
|
||||
return new CollectionCategory(parameters);
|
||||
};
|
||||
|
||||
class CollectionCategory implements Category {
|
||||
public readonly executableId: ExecutableId;
|
||||
|
||||
public readonly name: string;
|
||||
|
||||
public readonly docs: ReadonlyArray<string>;
|
||||
|
||||
public readonly subCategories: ReadonlyArray<Category>;
|
||||
public readonly subcategories: ReadonlyArray<Category>;
|
||||
|
||||
public readonly scripts: ReadonlyArray<Script>;
|
||||
|
||||
private allSubScripts?: ReadonlyArray<Script> = undefined;
|
||||
|
||||
constructor(parameters: CategoryInitParameters) {
|
||||
super(parameters.id);
|
||||
validateParameters(parameters);
|
||||
this.executableId = parameters.executableId;
|
||||
this.name = parameters.name;
|
||||
this.docs = parameters.docs;
|
||||
this.subCategories = parameters.subcategories;
|
||||
this.subcategories = parameters.subcategories;
|
||||
this.scripts = parameters.scripts;
|
||||
}
|
||||
|
||||
public includes(script: Script): boolean {
|
||||
return this.getAllScriptsRecursively().some((childScript) => childScript.id === script.id);
|
||||
return this
|
||||
.getAllScriptsRecursively()
|
||||
.some((childScript) => childScript.executableId === script.executableId);
|
||||
}
|
||||
|
||||
public getAllScriptsRecursively(): readonly Script[] {
|
||||
@@ -34,22 +56,17 @@ export class CollectionCategory extends BaseEntity<number> implements Category {
|
||||
}
|
||||
}
|
||||
|
||||
export interface CategoryInitParameters {
|
||||
readonly id: number;
|
||||
readonly name: string;
|
||||
readonly docs: ReadonlyArray<string>;
|
||||
readonly subcategories: ReadonlyArray<Category>;
|
||||
readonly scripts: ReadonlyArray<Script>;
|
||||
}
|
||||
|
||||
function parseScriptsRecursively(category: Category): ReadonlyArray<Script> {
|
||||
return [
|
||||
...category.scripts,
|
||||
...category.subCategories.flatMap((c) => c.getAllScriptsRecursively()),
|
||||
...category.subcategories.flatMap((c) => c.getAllScriptsRecursively()),
|
||||
];
|
||||
}
|
||||
|
||||
function validateParameters(parameters: CategoryInitParameters) {
|
||||
if (!parameters.executableId) {
|
||||
throw new Error('missing ID');
|
||||
}
|
||||
if (!parameters.name) {
|
||||
throw new Error('missing name');
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { IEntity } from '@/infrastructure/Entity/IEntity';
|
||||
import type { Documentable } from './Documentable';
|
||||
import type { Identifiable } from './Identifiable';
|
||||
|
||||
export interface Executable<TExecutableKey>
|
||||
extends Documentable, IEntity<TExecutableKey> {
|
||||
export interface Executable
|
||||
extends Documentable, Identifiable {
|
||||
}
|
||||
|
||||
5
src/domain/Executables/Identifiable.ts
Normal file
5
src/domain/Executables/Identifiable.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export type ExecutableId = string;
|
||||
|
||||
export interface Identifiable {
|
||||
readonly executableId: ExecutableId;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import type { Executable } from '../Executable';
|
||||
import type { Documentable } from '../Documentable';
|
||||
import type { ScriptCode } from './Code/ScriptCode';
|
||||
|
||||
export interface Script extends Executable<string>, Documentable {
|
||||
export interface Script extends Executable, Documentable {
|
||||
readonly name: string;
|
||||
readonly level?: RecommendationLevel;
|
||||
readonly code: ScriptCode;
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import { RecommendationLevel } from './RecommendationLevel';
|
||||
import type { Script } from './Script';
|
||||
import type { ScriptCode } from './Code/ScriptCode';
|
||||
import type { Script } from './Script';
|
||||
import type { ExecutableId } from '../Identifiable';
|
||||
|
||||
export interface ScriptInitParameters {
|
||||
readonly executableId: ExecutableId;
|
||||
readonly name: string;
|
||||
readonly code: ScriptCode;
|
||||
readonly docs: ReadonlyArray<string>;
|
||||
readonly level?: RecommendationLevel;
|
||||
}
|
||||
|
||||
export type ScriptFactory = (
|
||||
parameters: ScriptInitParameters,
|
||||
) => Script;
|
||||
|
||||
export const createScript: ScriptFactory = (parameters) => {
|
||||
return new CollectionScript(parameters);
|
||||
};
|
||||
|
||||
class CollectionScript implements Script {
|
||||
public readonly executableId: ExecutableId;
|
||||
|
||||
export class CollectionScript extends BaseEntity<string> implements Script {
|
||||
public readonly name: string;
|
||||
|
||||
public readonly code: ScriptCode;
|
||||
@@ -13,7 +31,7 @@ export class CollectionScript extends BaseEntity<string> implements Script {
|
||||
public readonly level?: RecommendationLevel;
|
||||
|
||||
constructor(parameters: ScriptInitParameters) {
|
||||
super(parameters.name);
|
||||
this.executableId = parameters.executableId;
|
||||
this.name = parameters.name;
|
||||
this.code = parameters.code;
|
||||
this.docs = parameters.docs;
|
||||
@@ -26,13 +44,6 @@ export class CollectionScript extends BaseEntity<string> implements Script {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ScriptInitParameters {
|
||||
readonly name: string;
|
||||
readonly code: ScriptCode;
|
||||
readonly docs: ReadonlyArray<string>;
|
||||
readonly level?: RecommendationLevel;
|
||||
}
|
||||
|
||||
function validateLevel(level?: RecommendationLevel) {
|
||||
if (level !== undefined && !(level in RecommendationLevel)) {
|
||||
throw new Error(`invalid level: ${level}`);
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ICategoryCollection } from './ICategoryCollection';
|
||||
import type { ICategoryCollection } from './Collection/ICategoryCollection';
|
||||
import type { ProjectDetails } from './Project/ProjectDetails';
|
||||
import type { OperatingSystem } from './OperatingSystem';
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { isNumber } from '@/TypeHelpers';
|
||||
import type { IEntity } from './IEntity';
|
||||
|
||||
export abstract class BaseEntity<TId> implements IEntity<TId> {
|
||||
protected constructor(public id: TId) {
|
||||
if (!isNumber(id) && !id) {
|
||||
throw new Error('Id cannot be null or empty');
|
||||
}
|
||||
}
|
||||
|
||||
public equals(otherId: TId): boolean {
|
||||
return this.id === otherId;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
/** Aggregate root */
|
||||
export interface IEntity<TId> {
|
||||
id: TId;
|
||||
equals(other: TId): boolean;
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
import type { Repository } from '../../application/Repository/Repository';
|
||||
import type { IEntity } from '../Entity/IEntity';
|
||||
import type { RepositoryEntity, RepositoryEntityId } from '../../application/Repository/RepositoryEntity';
|
||||
|
||||
export class InMemoryRepository<TKey, TEntity extends IEntity<TKey>>
|
||||
implements Repository<TKey, TEntity> {
|
||||
export class InMemoryRepository<TEntity extends RepositoryEntity>
|
||||
implements Repository<TEntity> {
|
||||
private readonly items: TEntity[];
|
||||
|
||||
constructor(items?: TEntity[]) {
|
||||
this.items = items ?? new Array<TEntity>();
|
||||
constructor(items?: readonly TEntity[]) {
|
||||
this.items = new Array<TEntity>();
|
||||
if (items) {
|
||||
this.items.push(...items);
|
||||
}
|
||||
}
|
||||
|
||||
public get length(): number {
|
||||
@@ -17,7 +20,7 @@ implements Repository<TKey, TEntity> {
|
||||
return predicate ? this.items.filter(predicate) : this.items;
|
||||
}
|
||||
|
||||
public getById(id: TKey): TEntity {
|
||||
public getById(id: RepositoryEntityId): TEntity {
|
||||
const items = this.getItems((entity) => entity.id === id);
|
||||
if (!items.length) {
|
||||
throw new Error(`missing item: ${id}`);
|
||||
@@ -39,7 +42,7 @@ implements Repository<TKey, TEntity> {
|
||||
this.items.push(item);
|
||||
}
|
||||
|
||||
public removeItem(id: TKey): void {
|
||||
public removeItem(id: RepositoryEntityId): void {
|
||||
const index = this.items.findIndex((item) => item.id === id);
|
||||
if (index === -1) {
|
||||
throw new Error(`Cannot remove (id: ${id}) as it does not exist`);
|
||||
@@ -47,7 +50,7 @@ implements Repository<TKey, TEntity> {
|
||||
this.items.splice(index, 1);
|
||||
}
|
||||
|
||||
public exists(id: TKey): boolean {
|
||||
public exists(id: RepositoryEntityId): boolean {
|
||||
const index = this.items.findIndex((item) => item.id === id);
|
||||
return index !== -1;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
for interactive elements during hover or touch interactions.
|
||||
*/
|
||||
@mixin clickable($cursor: 'pointer') {
|
||||
cursor: #{$cursor};
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent; // Removes blue tap highlight
|
||||
cursor: #{$cursor};
|
||||
}
|
||||
|
||||
@mixin fade-transition($name) {
|
||||
@@ -120,13 +120,13 @@
|
||||
}
|
||||
|
||||
@mixin set-property-ch-value-with-fallback($property, $value-in-ch) {
|
||||
@supports (width: 1ch) {
|
||||
#{$property}: #{$value-in-ch}ch;
|
||||
}
|
||||
// For browsers that does not support `ch` unit (e.g., Opera Mini):
|
||||
// For browsers that do not support `ch` unit (e.g., Opera Mini):
|
||||
$estimated-width-per-character-in-em: calc(1em / 2); // 1 character is approximately half the font size
|
||||
$calculated-width-in-em: calc(#{$estimated-width-per-character-in-em} * #{$value-in-ch});
|
||||
#{$property}: $calculated-width-in-em;
|
||||
@supports (width: 1ch) {
|
||||
#{$property}: #{$value-in-ch}ch; // Override `em` value if `ch` is supported.
|
||||
}
|
||||
}
|
||||
|
||||
@mixin base-font-style {
|
||||
|
||||
@@ -78,15 +78,17 @@ function getOptionalDevToolkitComponent(): Component | undefined {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
max-width: 1600px;
|
||||
|
||||
.app__wrapper {
|
||||
display:flex;
|
||||
flex-direction: column;
|
||||
|
||||
background-color: $color-surface;
|
||||
color: $color-on-surface;
|
||||
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.06);
|
||||
|
||||
@include responsive-spacing;
|
||||
|
||||
display:flex;
|
||||
flex-direction: column;
|
||||
.app__row {
|
||||
margin-bottom: $spacing-absolute-large;
|
||||
}
|
||||
|
||||
@@ -79,12 +79,12 @@ export default defineComponent({
|
||||
box-shadow: 0 3px 9px $color-primary-darkest;
|
||||
border-radius: 4px;
|
||||
|
||||
@include clickable;
|
||||
|
||||
.button__icon {
|
||||
font-size: $font-size-absolute-x-large;
|
||||
}
|
||||
|
||||
@include clickable;
|
||||
|
||||
@include hover-or-touch {
|
||||
background: $color-surface;
|
||||
box-shadow: 0px 2px 10px 5px $color-secondary;
|
||||
|
||||
@@ -110,8 +110,9 @@ export default defineComponent({
|
||||
@include apply-icon-color($color-danger);
|
||||
}
|
||||
.recommendation {
|
||||
align-items: center;
|
||||
|
||||
@include horizontal-stack;
|
||||
@include apply-icon-color($color-caution);
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import { RecommendationLevel } from '@/domain/Executables/Script/RecommendationLevel';
|
||||
import { scrambledEqual } from '@/application/Common/Array';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { ReadonlyScriptSelection, ScriptSelection } from '@/application/Context/State/Selection/Script/ScriptSelection';
|
||||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
import { RecommendationStatusType } from './RecommendationStatusType';
|
||||
@@ -99,6 +99,6 @@ function areAllSelected(
|
||||
if (expectedScripts.length < selectedScriptIds.length) {
|
||||
return false;
|
||||
}
|
||||
const expectedScriptIds = expectedScripts.map((script) => script.id);
|
||||
const expectedScriptIds = expectedScripts.map((script) => script.executableId);
|
||||
return scrambledEqual(selectedScriptIds, expectedScriptIds);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ import {
|
||||
} from 'vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import TooltipWrapper from '@/presentation/components/Shared/TooltipWrapper.vue';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import MenuOptionList from '../MenuOptionList.vue';
|
||||
import MenuOptionListItem from '../MenuOptionListItem.vue';
|
||||
import { setCurrentRecommendationStatus, getCurrentRecommendationStatus } from './RecommendationStatusHandler';
|
||||
|
||||
@@ -68,9 +68,11 @@ export default defineComponent({
|
||||
@include horizontal-stack;
|
||||
@include apply-icon-color($color-caution);
|
||||
}
|
||||
|
||||
.description {
|
||||
align-items: center;
|
||||
|
||||
@include horizontal-stack;
|
||||
@include apply-icon-color($color-success);
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -58,8 +58,19 @@ $color-hover : $color-primary;
|
||||
$cursor : v-bind(cursorCssValue);
|
||||
|
||||
.handle {
|
||||
cursor: $cursor;
|
||||
|
||||
@include reset-button;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
margin-right: $spacing-absolute-small;
|
||||
margin-left: $spacing-absolute-small;
|
||||
|
||||
@include clickable($cursor: $cursor);
|
||||
|
||||
@include hover-or-touch {
|
||||
.line {
|
||||
background: $color-hover;
|
||||
@@ -68,11 +79,7 @@ $cursor : v-bind(cursorCssValue);
|
||||
color: $color-hover;
|
||||
}
|
||||
}
|
||||
cursor: $cursor;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
.line {
|
||||
flex: 1;
|
||||
background: $color;
|
||||
@@ -81,7 +88,5 @@ $cursor : v-bind(cursorCssValue);
|
||||
.icon {
|
||||
color: $color;
|
||||
}
|
||||
margin-right: $spacing-absolute-small;
|
||||
margin-left: $spacing-absolute-small;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
} from 'vue';
|
||||
import { throttle } from '@/application/Common/Timing/Throttle';
|
||||
import type { Ref } from 'vue';
|
||||
import type { LifecycleHook } from '../../Shared/Hooks/Common/LifecycleHook';
|
||||
|
||||
const ThrottleInMs = 15;
|
||||
|
||||
@@ -10,6 +11,7 @@ export function useDragHandler(
|
||||
draggableElementRef: Readonly<Ref<HTMLElement | undefined>>,
|
||||
dragDomModifier: DragDomModifier = new GlobalDocumentDragDomModifier(),
|
||||
throttler = throttle,
|
||||
onTeardown: LifecycleHook = onUnmounted,
|
||||
) {
|
||||
const displacementX = ref(0);
|
||||
const isDragging = ref(false);
|
||||
@@ -52,7 +54,7 @@ export function useDragHandler(
|
||||
element.addEventListener('pointerdown', startDrag);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
onTeardown(() => {
|
||||
stopDrag();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { watch, type Ref, onUnmounted } from 'vue';
|
||||
import type { LifecycleHook } from '../../Shared/Hooks/Common/LifecycleHook';
|
||||
|
||||
export function useGlobalCursor(
|
||||
isActive: Readonly<Ref<boolean>>,
|
||||
cursorCssValue: string,
|
||||
documentAccessor: CursorStyleDomModifier = new GlobalDocumentCursorStyleDomModifier(),
|
||||
onTeardown: LifecycleHook = onUnmounted,
|
||||
) {
|
||||
const cursorStyle = createCursorStyle(cursorCssValue, documentAccessor);
|
||||
|
||||
@@ -15,7 +17,7 @@ export function useGlobalCursor(
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onTeardown(() => {
|
||||
documentAccessor.removeElement(cursorStyle);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import {
|
||||
} from 'vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import SizeObserver from '@/presentation/components/Shared/SizeObserver.vue';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import { hasDirective } from './NonCollapsingDirective';
|
||||
import CardListItem from './CardListItem.vue';
|
||||
|
||||
@@ -58,12 +59,12 @@ export default defineComponent({
|
||||
|
||||
const width = ref<number | undefined>();
|
||||
|
||||
const categoryIds = computed<readonly number[]>(
|
||||
() => currentState.value.collection.actions.map((category) => category.id),
|
||||
const categoryIds = computed<readonly ExecutableId[]>(
|
||||
() => currentState.value.collection.actions.map((category) => category.executableId),
|
||||
);
|
||||
const activeCategoryId = ref<number | undefined>(undefined);
|
||||
const activeCategoryId = ref<ExecutableId | undefined>(undefined);
|
||||
|
||||
function onSelected(categoryId: number, isExpanded: boolean) {
|
||||
function onSelected(categoryId: ExecutableId, isExpanded: boolean) {
|
||||
activeCategoryId.value = isExpanded ? categoryId : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,14 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent, computed, shallowRef,
|
||||
type PropType,
|
||||
} from 'vue';
|
||||
import AppIcon from '@/presentation/components/Shared/Icon/AppIcon.vue';
|
||||
import FlatButton from '@/presentation/components/Shared/FlatButton.vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import ScriptsTree from '@/presentation/components/Scripts/View/Tree/ScriptsTree.vue';
|
||||
import { sleep } from '@/infrastructure/Threading/AsyncSleep';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import CardSelectionIndicator from './CardSelectionIndicator.vue';
|
||||
import CardExpandTransition from './CardExpandTransition.vue';
|
||||
import CardExpansionArrow from './CardExpansionArrow.vue';
|
||||
@@ -77,11 +79,11 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
categoryId: {
|
||||
type: Number,
|
||||
type: String as PropType<ExecutableId>,
|
||||
required: true,
|
||||
},
|
||||
activeCategoryId: {
|
||||
type: Number,
|
||||
type: String as PropType<ExecutableId>,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed } from 'vue';
|
||||
import { defineComponent, computed, type PropType } from 'vue';
|
||||
import AppIcon from '@/presentation/components/Shared/Icon/AppIcon.vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -24,7 +25,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
categoryId: {
|
||||
type: Number,
|
||||
type: String as PropType<ExecutableId>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -78,17 +78,20 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
.docs {
|
||||
color: $color-on-primary;
|
||||
background: $color-primary-darkest;
|
||||
|
||||
margin-left: $spacing-absolute-small;
|
||||
margin-top: $spacing-relative-x-small;
|
||||
color: $color-on-primary;
|
||||
text-transform: none;
|
||||
padding: $spacing-absolute-medium;
|
||||
|
||||
text-transform: none;
|
||||
cursor: auto;
|
||||
user-select: text;
|
||||
|
||||
&-collapsed {
|
||||
display: none;
|
||||
}
|
||||
cursor: auto;
|
||||
user-select: text;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, type PropType, computed } from 'vue';
|
||||
import { splitTextIntoLines } from '@/application/Common/Text/SplitTextIntoLines';
|
||||
import MarkdownText from '../Markdown/MarkdownText.vue';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -43,7 +44,7 @@ function formatAsMarkdownListItem(content: string): string {
|
||||
if (content.length === 0) {
|
||||
throw new Error('missing content');
|
||||
}
|
||||
const lines = content.split(/\r\n|\r|\n/);
|
||||
const lines = splitTextIntoLines(content);
|
||||
return `- ${lines[0]}${lines.slice(1)
|
||||
.map((line) => `\n ${line}`)
|
||||
.join()}`;
|
||||
@@ -61,3 +62,4 @@ function formatAsMarkdownListItem(content: string): string {
|
||||
font-size: $font-size-absolute-normal;
|
||||
}
|
||||
</style>
|
||||
@/application/Text/SplitTextIntoLines
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
|
||||
export enum NodeType {
|
||||
Script,
|
||||
Category,
|
||||
}
|
||||
|
||||
export interface NodeMetadata {
|
||||
readonly id: string;
|
||||
readonly executableId: ExecutableId;
|
||||
readonly text: string;
|
||||
readonly isReversible: boolean;
|
||||
readonly docs: ReadonlyArray<string>;
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from 'vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import type { NodeMetadata } from '@/presentation/components/Scripts/View/Tree/NodeContent/NodeMetadata';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { getReverter } from './Reverter/ReverterFactory';
|
||||
import ToggleSwitch from './ToggleSwitch.vue';
|
||||
import type { Reverter } from './Reverter/Reverter';
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import type { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
import { getCategoryId } from '../../TreeViewAdapter/CategoryNodeMetadataConverter';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import { createExecutableIdFromNodeId } from '../../TreeViewAdapter/CategoryNodeMetadataConverter';
|
||||
import { ScriptReverter } from './ScriptReverter';
|
||||
import type { Reverter } from './Reverter';
|
||||
import type { TreeNodeId } from '../../TreeView/Node/TreeNode';
|
||||
|
||||
export class CategoryReverter implements Reverter {
|
||||
private readonly categoryId: number;
|
||||
private readonly categoryId: ExecutableId;
|
||||
|
||||
private readonly scriptReverters: ReadonlyArray<ScriptReverter>;
|
||||
|
||||
constructor(nodeId: string, collection: ICategoryCollection) {
|
||||
this.categoryId = getCategoryId(nodeId);
|
||||
constructor(nodeId: TreeNodeId, collection: ICategoryCollection) {
|
||||
this.categoryId = createExecutableIdFromNodeId(nodeId);
|
||||
this.scriptReverters = createScriptReverters(this.categoryId, collection);
|
||||
}
|
||||
|
||||
@@ -37,12 +39,12 @@ export class CategoryReverter implements Reverter {
|
||||
}
|
||||
|
||||
function createScriptReverters(
|
||||
categoryId: number,
|
||||
categoryId: ExecutableId,
|
||||
collection: ICategoryCollection,
|
||||
): ScriptReverter[] {
|
||||
const category = collection.getCategory(categoryId);
|
||||
const scripts = category
|
||||
.getAllScriptsRecursively()
|
||||
.filter((script) => script.canRevert());
|
||||
return scripts.map((script) => new ScriptReverter(script.id));
|
||||
return scripts.map((script) => new ScriptReverter(script.executableId));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import { type NodeMetadata, NodeType } from '../NodeMetadata';
|
||||
import { ScriptReverter } from './ScriptReverter';
|
||||
import { CategoryReverter } from './CategoryReverter';
|
||||
import type { Reverter } from './Reverter';
|
||||
|
||||
export function getReverter(node: NodeMetadata, collection: ICategoryCollection): Reverter {
|
||||
export function getReverter(
|
||||
node: NodeMetadata,
|
||||
collection: ICategoryCollection,
|
||||
): Reverter {
|
||||
switch (node.type) {
|
||||
case NodeType.Category:
|
||||
return new CategoryReverter(node.id, collection);
|
||||
return new CategoryReverter(node.executableId, collection);
|
||||
case NodeType.Script:
|
||||
return new ScriptReverter(node.id);
|
||||
return new ScriptReverter(node.executableId);
|
||||
default:
|
||||
throw new Error('Unknown script type');
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import type { UserSelection } from '@/application/Context/State/Selection/UserSelection';
|
||||
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
||||
import { getScriptId } from '../../TreeViewAdapter/CategoryNodeMetadataConverter';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import { createExecutableIdFromNodeId } from '../../TreeViewAdapter/CategoryNodeMetadataConverter';
|
||||
import type { Reverter } from './Reverter';
|
||||
import type { TreeNodeId } from '../../TreeView/Node/TreeNode';
|
||||
|
||||
export class ScriptReverter implements Reverter {
|
||||
private readonly scriptId: string;
|
||||
private readonly scriptId: ExecutableId;
|
||||
|
||||
constructor(nodeId: string) {
|
||||
this.scriptId = getScriptId(nodeId);
|
||||
constructor(nodeId: TreeNodeId) {
|
||||
this.scriptId = createExecutableIdFromNodeId(nodeId);
|
||||
}
|
||||
|
||||
public getState(selectedScripts: ReadonlyArray<SelectedScript>): boolean {
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, toRef } from 'vue';
|
||||
import { defineComponent, toRef, type PropType } from 'vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import TreeView from './TreeView/TreeView.vue';
|
||||
import NodeContent from './NodeContent/NodeContent.vue';
|
||||
import { useTreeViewFilterEvent } from './TreeViewAdapter/UseTreeViewFilterEvent';
|
||||
@@ -41,7 +42,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
categoryId: {
|
||||
type: [Number],
|
||||
type: String as PropType<ExecutableId>,
|
||||
default: undefined,
|
||||
},
|
||||
hasTopPadding: {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export type TreeInputNodeDataId = string;
|
||||
|
||||
export interface TreeInputNodeData {
|
||||
readonly id: string;
|
||||
readonly id: TreeInputNodeDataId;
|
||||
readonly children?: readonly TreeInputNodeData[];
|
||||
readonly parent?: TreeInputNodeData | null;
|
||||
readonly data?: object;
|
||||
|
||||
@@ -56,7 +56,7 @@ import { useNodeState } from './UseNodeState';
|
||||
import LeafTreeNode from './LeafTreeNode.vue';
|
||||
import InteractableNode from './InteractableNode.vue';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { NodeRenderingStrategy } from '../Rendering/Scheduling/NodeRenderingStrategy';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
@@ -69,7 +69,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
@@ -133,14 +133,14 @@ export default defineComponent({
|
||||
.expansible-node {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
align-items: center;
|
||||
|
||||
.leaf-node {
|
||||
flex: 1; // Expands the node horizontally, allowing its content to utilize full width for child item alignment, such as icons and text.
|
||||
overflow: auto; // Prevents horizontal expansion of inner content (e.g., when a code block is shown)
|
||||
}
|
||||
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.expand-collapse-caret {
|
||||
$caret-size: 24px;
|
||||
$padding-right: $spacing-absolute-small;
|
||||
|
||||
@@ -18,13 +18,13 @@ import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { useNodeState } from './UseNodeState';
|
||||
import { useKeyboardInteractionState } from './UseKeyboardInteractionState';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -28,7 +28,7 @@ import { defineComponent, computed, toRef } from 'vue';
|
||||
import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import NodeCheckbox from './NodeCheckbox.vue';
|
||||
import InteractableNode from './InteractableNode.vue';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
@@ -39,7 +39,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -14,13 +14,13 @@ import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { useNodeState } from './UseNodeState';
|
||||
import { TreeNodeCheckState } from './State/CheckState';
|
||||
import type { TreeRoot } from '../TreeRoot/TreeRoot';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { PropType } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
nodeId: {
|
||||
type: String,
|
||||
type: String as PropType<TreeNodeId>,
|
||||
required: true,
|
||||
},
|
||||
treeRoot: {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { HierarchyAccess, HierarchyReader } from './Hierarchy/HierarchyAccess';
|
||||
import type { TreeNodeStateAccess, TreeNodeStateReader } from './State/StateAccess';
|
||||
|
||||
export type TreeNodeId = string;
|
||||
|
||||
export interface ReadOnlyTreeNode {
|
||||
readonly id: string;
|
||||
readonly id: TreeNodeId;
|
||||
readonly state: TreeNodeStateReader;
|
||||
readonly hierarchy: HierarchyReader;
|
||||
readonly metadata?: object;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TreeNodeHierarchy } from './Hierarchy/TreeNodeHierarchy';
|
||||
import { TreeNodeState } from './State/TreeNodeState';
|
||||
import type { TreeNode } from './TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from './TreeNode';
|
||||
import type { TreeNodeStateAccess } from './State/StateAccess';
|
||||
import type { HierarchyAccess } from './Hierarchy/HierarchyAccess';
|
||||
|
||||
@@ -9,7 +9,7 @@ export class TreeNodeManager implements TreeNode {
|
||||
|
||||
public readonly hierarchy: HierarchyAccess;
|
||||
|
||||
constructor(public readonly id: string, public readonly metadata?: object) {
|
||||
constructor(public readonly id: TreeNodeId, public readonly metadata?: object) {
|
||||
if (!id) {
|
||||
throw new Error('missing id');
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { ReadOnlyTreeNode, TreeNode } from '../../../Node/TreeNode';
|
||||
import type { ReadOnlyTreeNode, TreeNode, TreeNodeId } from '../../../Node/TreeNode';
|
||||
|
||||
export interface ReadOnlyQueryableNodes {
|
||||
readonly rootNodes: readonly ReadOnlyTreeNode[];
|
||||
readonly flattenedNodes: readonly ReadOnlyTreeNode[];
|
||||
|
||||
getNodeById(id: string): ReadOnlyTreeNode;
|
||||
getNodeById(nodeId: TreeNodeId): ReadOnlyTreeNode;
|
||||
}
|
||||
|
||||
export interface QueryableNodes extends ReadOnlyQueryableNodes {
|
||||
readonly rootNodes: readonly TreeNode[];
|
||||
readonly flattenedNodes: readonly TreeNode[];
|
||||
|
||||
getNodeById(id: string): TreeNode;
|
||||
getNodeById(nodeId: TreeNodeId): TreeNode;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { QueryableNodes } from './QueryableNodes';
|
||||
import type { TreeNode } from '../../../Node/TreeNode';
|
||||
import type { TreeNode, TreeNodeId } from '../../../Node/TreeNode';
|
||||
|
||||
export class TreeNodeNavigator implements QueryableNodes {
|
||||
public readonly flattenedNodes: readonly TreeNode[];
|
||||
@@ -8,10 +8,10 @@ export class TreeNodeNavigator implements QueryableNodes {
|
||||
this.flattenedNodes = flattenNodes(rootNodes);
|
||||
}
|
||||
|
||||
public getNodeById(id: string): TreeNode {
|
||||
const foundNode = this.flattenedNodes.find((node) => node.id === id);
|
||||
public getNodeById(nodeId: TreeNodeId): TreeNode {
|
||||
const foundNode = this.flattenedNodes.find((node) => node.id === nodeId);
|
||||
if (!foundNode) {
|
||||
throw new Error(`Node could not be found: ${id}`);
|
||||
throw new Error(`Node could not be found: ${nodeId}`);
|
||||
}
|
||||
return foundNode;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from 'vue';
|
||||
import HierarchicalTreeNode from '../Node/HierarchicalTreeNode.vue';
|
||||
import { useCurrentTreeNodes } from '../UseCurrentTreeNodes';
|
||||
import { type TreeNodeId } from '../Node/TreeNode';
|
||||
import type { NodeRenderingStrategy } from '../Rendering/Scheduling/NodeRenderingStrategy';
|
||||
import type { TreeRoot } from './TreeRoot';
|
||||
import type { PropType } from 'vue';
|
||||
@@ -43,7 +44,7 @@ export default defineComponent({
|
||||
setup(props) {
|
||||
const { nodes } = useCurrentTreeNodes(toRef(props, 'treeRoot'));
|
||||
|
||||
const renderedNodeIds = computed<string[]>(() => {
|
||||
const renderedNodeIds = computed<TreeNodeId[]>(() => {
|
||||
return nodes
|
||||
.value
|
||||
.rootNodes
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useLeafNodeCheckedStateUpdater } from './UseLeafNodeCheckedStateUpdater
|
||||
import { useAutoUpdateParentCheckState } from './UseAutoUpdateParentCheckState';
|
||||
import { useAutoUpdateChildrenCheckState } from './UseAutoUpdateChildrenCheckState';
|
||||
import { useGradualNodeRendering, type NodeRenderingControl } from './Rendering/UseGradualNodeRendering';
|
||||
import { type TreeNodeId } from './Node/TreeNode';
|
||||
import type { TreeNodeStateChangedEmittedEvent } from './Bindings/TreeNodeStateChangedEmittedEvent';
|
||||
import type { TreeInputNodeData } from './Bindings/TreeInputNodeData';
|
||||
import type { TreeViewFilterEvent } from './Bindings/TreeInputFilterEvent';
|
||||
@@ -45,7 +46,7 @@ export default defineComponent({
|
||||
default: () => undefined,
|
||||
},
|
||||
selectedLeafNodeIds: {
|
||||
type: Array as PropType<ReadonlyArray<string>>,
|
||||
type: Array as PropType<ReadonlyArray<TreeNodeId>>,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
|
||||
import type { Script } from '@/domain/Executables/Script/Script';
|
||||
import type { ExecutableId } from '@/domain/Executables/Identifiable';
|
||||
import type { Executable } from '@/domain/Executables/Executable';
|
||||
import { type NodeMetadata, NodeType } from '../NodeContent/NodeMetadata';
|
||||
import type { TreeNodeId } from '../TreeView/Node/TreeNode';
|
||||
|
||||
export function parseAllCategories(collection: ICategoryCollection): NodeMetadata[] {
|
||||
return createCategoryNodes(collection.actions);
|
||||
}
|
||||
|
||||
export function parseSingleCategory(
|
||||
categoryId: number,
|
||||
categoryId: ExecutableId,
|
||||
collection: ICategoryCollection,
|
||||
): NodeMetadata[] {
|
||||
const category = collection.getCategory(categoryId);
|
||||
@@ -16,27 +19,19 @@ export function parseSingleCategory(
|
||||
return tree;
|
||||
}
|
||||
|
||||
export function getScriptNodeId(script: Script): string {
|
||||
return script.id;
|
||||
export function createNodeIdForExecutable(executable: Executable): TreeNodeId {
|
||||
return executable.executableId;
|
||||
}
|
||||
|
||||
export function getScriptId(nodeId: string): string {
|
||||
export function createExecutableIdFromNodeId(nodeId: TreeNodeId): ExecutableId {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
export function getCategoryId(nodeId: string): number {
|
||||
return +nodeId;
|
||||
}
|
||||
|
||||
export function getCategoryNodeId(category: Category): string {
|
||||
return `${category.id}`;
|
||||
}
|
||||
|
||||
function parseCategoryRecursively(
|
||||
parentCategory: Category,
|
||||
): NodeMetadata[] {
|
||||
return [
|
||||
...createCategoryNodes(parentCategory.subCategories),
|
||||
...createCategoryNodes(parentCategory.subcategories),
|
||||
...createScriptNodes(parentCategory.scripts),
|
||||
];
|
||||
}
|
||||
@@ -57,7 +52,7 @@ function convertCategoryToNode(
|
||||
children: readonly NodeMetadata[],
|
||||
): NodeMetadata {
|
||||
return {
|
||||
id: getCategoryNodeId(category),
|
||||
executableId: createNodeIdForExecutable(category),
|
||||
type: NodeType.Category,
|
||||
text: category.name,
|
||||
children,
|
||||
@@ -68,7 +63,7 @@ function convertCategoryToNode(
|
||||
|
||||
function convertScriptToNode(script: Script): NodeMetadata {
|
||||
return {
|
||||
id: getScriptNodeId(script),
|
||||
executableId: createNodeIdForExecutable(script),
|
||||
type: NodeType.Script,
|
||||
text: script.name,
|
||||
children: [],
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user