Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1ea9769
spike: draft implementation of consolidated configs
hikchoi Sep 6, 2021
52dc0f0
chore: add docstrings
hikchoi Sep 6, 2021
afabae2
chore: clean up and add more docstrings
hikchoi Sep 6, 2021
5884377
chore: refactor common types
hikchoi Sep 9, 2021
34ed614
chore: add new scratch config
hikchoi Sep 9, 2021
5fab3e1
chore: add new insert note index configs
hikchoi Sep 9, 2021
8ccc860
chore: change generic type for DendronConfigEntry
hikchoi Sep 9, 2021
8c95505
chore: respect optional when generating defaults
hikchoi Sep 9, 2021
8acc3d5
chore: add new random note config
hikchoi Sep 9, 2021
a9df10a
chore: add more top level namespaces
hikchoi Sep 9, 2021
f5e1e75
chore: add namespace for insert note
hikchoi Sep 9, 2021
142fac0
chore: bunch more stuff
hikchoi Sep 9, 2021
9c41819
chore: add remaining workspace configs
hikchoi Sep 10, 2021
6780bea
chore: add graph configs
hikchoi Sep 10, 2021
c5c22be
chore: add rest of publishing configs
hikchoi Sep 10, 2021
aca742d
chore: add global configs
hikchoi Sep 10, 2021
67b1e6e
chore: add dev configs
hikchoi Sep 10, 2021
72e099b
chore: add preview configs
hikchoi Sep 10, 2021
3d06a31
chore: add dev configs to top level
hikchoi Sep 10, 2021
864561d
chore: define generic type for config entry collection
hikchoi Sep 10, 2021
5012ab1
chore: clean up commands namespace
hikchoi Sep 13, 2021
e0cae85
chore: narrow down collection type definition
hikchoi Sep 13, 2021
a20e8f8
chore: clean up workspace namespace
hikchoi Sep 13, 2021
33653b1
chore: clean up global namespace
hikchoi Sep 13, 2021
fc180be
chore: clean up dev namespace
hikchoi Sep 13, 2021
dfa32ff
chore: clean up preview namespace
hikchoi Sep 13, 2021
1fa756f
chore: clean up publishing namespace
hikchoi Sep 13, 2021
69bc20b
chore: more cleanup
hikchoi Sep 13, 2021
51900ef
chore: more and more cleanup
hikchoi Sep 13, 2021
cbc92c4
chore: fix wording, add omitted configs
hikchoi Sep 13, 2021
517facc
chore: add missing config entries in workspace
hikchoi Sep 14, 2021
b574dda
chore: conform to naming convention, various fixes
hikchoi Sep 14, 2021
dc13a17
chore: remove enableCaching config
hikchoi Sep 16, 2021
2ada327
chore: renaming and deletions
hikchoi Sep 16, 2021
609873b
chore: reduce generic type boilerplate
hikchoi Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/common-all/src/types/configs/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type DendronConfigValueType = string | boolean | number;

/**
* DendronConfigEntry
* Holds the value, label, and description of individual configuration entries.
*
* For config entries that can be an arbitrary value, only specify the label and description.
* For config entries that have pre-defined choices, provide the value as well as label and description specific to that value.
*/
export type DendronConfigEntry<DendronConfigValueType> = {
value?: DendronConfigValueType;
label: string;
desc: string;
};
34 changes: 34 additions & 0 deletions packages/common-all/src/types/configs/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
genDefaultInsertNoteLinkConfig,
InsertNoteLinkConfig,
INSERT_NOTE_LINK,
} from "./insertNoteLink";
import { genDefaultLookupConfig, LookupConfig, LOOKUP } from "./lookup";

/**
* Namespace for all command related configurations
*/
export type DendronCommandConfig = {
lookup: LookupConfig;
insertNoteLink: InsertNoteLinkConfig;
};

/**
* Constants holding all command config related {@link DendronConfigEntry}
*/
export const COMMANDS = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts between using constants vs enums? You can use Object.values to get all enum values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values in the object are also constants that themselves holding other constants or functions that produce constants.

Are you suggesting we have nested enums (not sure if that's a thing)? or we flatten it out and have a giant enum that holds all possible labels and descriptions?

LOOKUP,
INSERT_NOTE_LINK,
};

/**
* Generates default {@link DendronCommandConfig} using
* respective default config generators that each command config implements.
* @returns DendronCommandConfig
*/
export function genDefaultCommandConfig(): DendronCommandConfig {
return {
lookup: genDefaultLookupConfig(),
insertNoteLink: genDefaultInsertNoteLinkConfig(),
};
}
100 changes: 100 additions & 0 deletions packages/common-all/src/types/configs/commands/insertNoteLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { DendronConfigEntry } from "../base";

/**
* Enum definitions of possible alias mode values
*/
export enum InsertNoteLinkAliasModeEnum {
snippet = "snippet",
selection = "selection",
title = "title",
prompt = "prompt",
none = "none",
}

/**
* String literal types generated from {@link InsertNoteLinkAliasModeEnum}
*/
export type InsertNoteLinkAliasMode = keyof typeof InsertNoteLinkAliasModeEnum;

/**
* Namespace for configuring {@link InsertNoteLinkCommand}
*/
export type InsertNoteLinkConfig = {
aliasMode: InsertNoteLinkAliasModeEnum;
multiSelect: boolean;
};

/**
* Constants for possible alias mode choices.
* Each key of {@link InsertNoteLinkAliasMode} is mapped to a {@link DendronConfigEntry}
* which specifies the value, label, description of possible alias modes.
*
* These are used to generate user friendly descriptions in the configuration UI.
*/
const ALIAS_MODES: {
[key in InsertNoteLinkAliasMode]: DendronConfigEntry<string>;
} = {
snippet: {
value: InsertNoteLinkAliasModeEnum.snippet,
label: "snippet mode",
desc: "Insert note link as snippet string",
},
selection: {
value: InsertNoteLinkAliasModeEnum.selection,
label: "selection mode",
desc: "Extract selection and use as link alias",
},
title: {
value: InsertNoteLinkAliasModeEnum.title,
label: "title mode",
desc: "Use linked note's title as link alias",
},
prompt: {
value: InsertNoteLinkAliasModeEnum.prompt,
label: "prompt mode",
desc: "Prompt for input to be used as link alias",
},
none: {
value: InsertNoteLinkAliasModeEnum.none,
label: "no alias mode",
desc: "Do not add link alias",
},
};

/**
* Given a boolean value, returns a {@link DendronConfigEntry} that holds
* user friendly description of the multi-select behavior.
*
* This is a function instead of an object because object keys cannot be booleans.
*
* @param value boolean
* @returns DendronConfigEntry<boolean>
*/
const MULTI_SELECT = (value: boolean): DendronConfigEntry<boolean> => {
const valueToString = value ? "Enable" : "Disable";
return {
value,
label: `${valueToString} multi-select`,
desc: `${valueToString} multi-select when inserting note link(s)`,
};
};

/**
* Constants / functions that produce constants for
* possible insert note link configurations.
*/
export const INSERT_NOTE_LINK = {
ALIAS_MODES,
MULTI_SELECT,
};

/**
* Generates default {@link InsertNoteLinkConfig}
* @returns InsertNoteLinkConfig
*/
export function genDefaultInsertNoteLinkConfig(): InsertNoteLinkConfig {
return {
aliasMode: InsertNoteLinkAliasModeEnum.none,
multiSelect: false,
};
}
79 changes: 79 additions & 0 deletions packages/common-all/src/types/configs/commands/lookup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { DendronConfigEntry } from "../base";

/**
* Enum definition of possible lookup selection behavior values
*/
export enum NoteLookupSelectionBehaviorEnum {
extract = "extract",
link = "link",
none = "none",
}

/**
* String literal type generated from {@link NoteLookupSelectionBehaviorEnum}
*/
export type NoteLookupSelectionBehavior =
keyof typeof NoteLookupSelectionBehaviorEnum;

/**
* Namespace for configuring lookup commands
*/
export type LookupConfig = {
note: NoteLookupConfig;
};

/**
* Namespace for configuring {@link NoteLookupCommand}
*/
type NoteLookupConfig = {
selectionBehavior: NoteLookupSelectionBehavior;
};

/**
* Constants for possible note lookup selection behaviors.
* Each key holds a {@link DendronConfigEntry}
* which specifies the value, label, description of possible selection behaviors.
*
* These are used to generate user friendly descriptions in the configuration UI.
*/
const SELECTION_BEHAVIORS: {
[key in NoteLookupSelectionBehavior]: DendronConfigEntry<string>;
} = {
extract: {
value: NoteLookupSelectionBehaviorEnum.extract,
label: "extract selection",
desc: "Extract selection of active editor and use it as body of new note.",
},
link: {
value: NoteLookupSelectionBehaviorEnum.link,
label: "selection to link",
desc: "Use selection of active editor for the basename of the lookup value.",
},
none: {
value: NoteLookupSelectionBehaviorEnum.none,
label: "none",
desc: "Do not set selection behavior",
},
};

/**
* Constants / functions that produce
* constants for possible lookup configurations
*/
export const LOOKUP = {
NOTE: {
SELECTION: SELECTION_BEHAVIORS,
},
};

/**
* Generates default {@link LookupConfig}
* @returns LookupConfig
*/
export function genDefaultLookupConfig(): LookupConfig {
return {
note: {
selectionBehavior: NoteLookupSelectionBehaviorEnum.extract,
},
};
}
39 changes: 39 additions & 0 deletions packages/common-all/src/types/configs/dendronConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
DendronCommandConfig,
genDefaultCommandConfig,
COMMANDS,
} from "./commands/commands";
import {
DendronWorkspaceConfig,
genDefaultWorkspaceConfig,
WORKSPACE,
} from "./workspace/workspace";

/**
* DendronConfig
* This is the top level config that will hold everything.
*/
export type DendronConfig = {
commands: DendronCommandConfig;
workspace: DendronWorkspaceConfig;
};

/**
* Constants holding all {@link DendronConfigEntry}
*/
export const DENDRON_CONFIG = {
COMMANDS,
WORKSPACE,
};

/**
* Generates a default DendronConfig using
* respective default config generators of each sub config groups.
* @returns DendronConfig
*/
export function genDefaultDendronConfig(): DendronConfig {
return {
commands: genDefaultCommandConfig(),
workspace: genDefaultWorkspaceConfig(),
};
}
126 changes: 126 additions & 0 deletions packages/common-all/src/types/configs/workspace/journal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { DendronConfigEntry } from "../base";

/**
* Enum definition of possible note add behavior values.
*/
export enum NoteAddBehaviorEnum {
childOfDomain = "childOfDomain",
childOfDomainNamespace = "childOfDomainNamespace",
childOfCurrent = "childOfCurrent",
asOwnDomain = "asOwnDomain",
}

/**
* String literal type generated from {@link NoteAddBehaviorEnum}
*/
export type NoteAddBehavior = keyof typeof NoteAddBehaviorEnum;

/**
* Namespace for configuring journal note behavior
*/
export type JournalConfig = {
dailyDomain: string;
dailyVault?: string;
name: string;
dateFormat: string;
addBehavior: NoteAddBehaviorEnum;
firstDayOfWeek: number;
};

/**
* Constants for possible note add behaviors.
* Each key of {@link NoteAddBehavior} is mapped to a {@link DendronConfigEntry}
* which specifies the value, label, description of possible note add behaviors.
*
* These are used to generate user friendly descriptions in the configuration.
*/
const ADD_BEHAVIOR: {
[key in NoteAddBehavior]: DendronConfigEntry<string>;
} = {
childOfDomain: {
value: "childOfDomain",
label: "child of domain",
desc: "Note is added as the child of domain of the current hierarchy",
},
childOfDomainNamespace: {
value: "childOfDomainNamespace",
label: "child of domain namespace",
desc: "Note is added as child of the namespace of the current domain if it has a namespace. Otherwise added as child of domain.",
},
childOfCurrent: {
value: "childOfCurrent",
label: "child of current",
desc: "Note is added as a child of the current open note",
},
asOwnDomain: {
value: "asOwnDomain",
label: "as own domain",
desc: "Note is created under the domain specified by journal name value",
},
};

// const assertion to tell the compiler that we only want these as dayOfWeekNumber.
const possibleDayOfWeekNumber = [0, 1, 2, 3, 4, 5, 6] as const;
export type dayOfWeekNumber = typeof possibleDayOfWeekNumber[number];

/**
* Given a {@link dayOfWeekNumber}, returns a {@link DendronConfigEntry} that holds
* user friendly description of the first day of week behavior.
*
* @param value {@link dayOfWeekNumber}
* @returns DendronConfigEntry
*/
const FIRST_DAY_OF_WEEK = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a heads up that we're currently not supporting this option due to limitation in calendar widget. we'll add support back in eventually but FYI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware of this. I also have been taking note on other configs with some peculiarities that we need to address once we start actually migrating.

value: dayOfWeekNumber
): DendronConfigEntry<dayOfWeekNumber> => {
const dayOfWeek = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const valueToDay = dayOfWeek[value];
return {
label: valueToDay,
desc: `Set start of the week to ${valueToDay}`,
};
};

/**
* Constants / functions that produce constants for possible journal configurations.
* config entries that doesn't have limited choices have their values omitted.
* config entries that have specific choices have their choices predefined or generated.
*/
export const JOURNAL = {
DAILY_DOMAIN: {
label: "daily domain",
desc: "Domain where the journal notes are created",
},
NAME: {
label: "journal name",
desc: "Name used for journal notes",
},
DATE_FORMAT: {
label: "date format",
desc: "Date format used for journal notes",
},
ADD_BEHAVIOR,
FIRST_DAY_OF_WEEK,
};

/**
* Generates default {@link JournalConfig}
* @returns JouranlConfig
*/
export function genDefaultJournalConfig(): JournalConfig {
return {
dailyDomain: "daily",
name: "journal",
dateFormat: "y.MM.dd",
addBehavior: NoteAddBehaviorEnum.childOfDomain,
firstDayOfWeek: 1,
};
}
Loading