mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
update sdk imports
This commit is contained in:
@@ -19,11 +19,8 @@ import {
|
||||
} from '@start9labs/marketplace'
|
||||
import { Log } from '@start9labs/shared'
|
||||
import { configBuilderToSpec } from 'src/app/util/configBuilderToSpec'
|
||||
import { Config } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/config'
|
||||
import { Value } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/value'
|
||||
import { Variants } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/variants'
|
||||
import { List } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/list'
|
||||
import { unionSelectKey } from '@start9labs/start-sdk/cjs/sdk/lib/config/configTypes'
|
||||
import { CT } from '@start9labs/start-sdk'
|
||||
import { CB } from '@start9labs/start-sdk'
|
||||
|
||||
export module Mock {
|
||||
export const ServerUpdated: ServerStatusInfo = {
|
||||
@@ -715,27 +712,27 @@ export module Mock {
|
||||
RR.GetPackageConfigRes['spec']
|
||||
> =>
|
||||
configBuilderToSpec(
|
||||
Config.of({
|
||||
bitcoin: Value.object(
|
||||
CB.Config.of({
|
||||
bitcoin: CB.Value.object(
|
||||
{
|
||||
name: 'Bitcoin Settings',
|
||||
description:
|
||||
'RPC and P2P interface configuration options for Bitcoin Core',
|
||||
},
|
||||
Config.of({
|
||||
'bitcoind-p2p': Value.union(
|
||||
CB.Config.of({
|
||||
'bitcoind-p2p': CB.Value.union(
|
||||
{
|
||||
name: 'P2P Settings',
|
||||
description:
|
||||
'<p>The Bitcoin Core node to connect to over the peer-to-peer (P2P) interface:</p><ul><li><strong>Bitcoin Core</strong>: The Bitcoin Core service installed on this device</li><li><strong>External Node</strong>: A Bitcoin node running on a different device</li></ul>',
|
||||
required: { default: 'internal' },
|
||||
},
|
||||
Variants.of({
|
||||
internal: { name: 'Bitcoin Core', spec: Config.of({}) },
|
||||
CB.Variants.of({
|
||||
internal: { name: 'Bitcoin Core', spec: CB.Config.of({}) },
|
||||
external: {
|
||||
name: 'External Node',
|
||||
spec: Config.of({
|
||||
'p2p-host': Value.text({
|
||||
spec: CB.Config.of({
|
||||
'p2p-host': CB.Value.text({
|
||||
name: 'Public Address',
|
||||
required: {
|
||||
default: null,
|
||||
@@ -743,7 +740,7 @@ export module Mock {
|
||||
description:
|
||||
'The public address of your Bitcoin Core server',
|
||||
}),
|
||||
'p2p-port': Value.number({
|
||||
'p2p-port': CB.Value.number({
|
||||
name: 'P2P Port',
|
||||
description:
|
||||
'The port that your Bitcoin Core P2P server is bound to',
|
||||
@@ -760,7 +757,7 @@ export module Mock {
|
||||
),
|
||||
}),
|
||||
),
|
||||
users: Value.multiselect({
|
||||
users: CB.Value.multiselect({
|
||||
name: 'Users',
|
||||
default: [],
|
||||
maxLength: 2,
|
||||
@@ -772,21 +769,21 @@ export module Mock {
|
||||
lucy: 'Lucy',
|
||||
},
|
||||
}),
|
||||
advanced: Value.object(
|
||||
advanced: CB.Value.object(
|
||||
{
|
||||
name: 'Advanced',
|
||||
description: 'Advanced settings',
|
||||
},
|
||||
Config.of({
|
||||
rpcsettings: Value.object(
|
||||
CB.Config.of({
|
||||
rpcsettings: CB.Value.object(
|
||||
{
|
||||
name: 'RPC Settings',
|
||||
description: 'rpc username and password',
|
||||
warning:
|
||||
'Adding RPC users gives them special permissions on your node.',
|
||||
},
|
||||
Config.of({
|
||||
rpcuser2: Value.text({
|
||||
CB.Config.of({
|
||||
rpcuser2: CB.Value.text({
|
||||
name: 'RPC Username',
|
||||
required: {
|
||||
default: 'defaultrpcusername',
|
||||
@@ -799,7 +796,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
rpcuser: Value.text({
|
||||
rpcuser: CB.Value.text({
|
||||
name: 'RPC Username',
|
||||
required: {
|
||||
default: 'defaultrpcusername',
|
||||
@@ -812,7 +809,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
rpcpass: Value.text({
|
||||
rpcpass: CB.Value.text({
|
||||
name: 'RPC User Password',
|
||||
required: {
|
||||
default: {
|
||||
@@ -822,7 +819,7 @@ export module Mock {
|
||||
},
|
||||
description: 'rpc password',
|
||||
}),
|
||||
rpcpass2: Value.text({
|
||||
rpcpass2: CB.Value.text({
|
||||
name: 'RPC User Password',
|
||||
required: {
|
||||
default: {
|
||||
@@ -836,15 +833,15 @@ export module Mock {
|
||||
),
|
||||
}),
|
||||
),
|
||||
testnet: Value.toggle({
|
||||
testnet: CB.Value.toggle({
|
||||
name: 'Testnet',
|
||||
default: true,
|
||||
description:
|
||||
'<ul><li>determines whether your node is running on testnet or mainnet</li></ul><script src="fake"></script>',
|
||||
warning: 'Chain will have to resync!',
|
||||
}),
|
||||
'object-list': Value.list(
|
||||
List.obj(
|
||||
'object-list': CB.Value.list(
|
||||
CB.List.obj(
|
||||
{
|
||||
name: 'Object List',
|
||||
minLength: 0,
|
||||
@@ -856,13 +853,13 @@ export module Mock {
|
||||
description: 'This is a list of objects, like users or something',
|
||||
},
|
||||
{
|
||||
spec: Config.of({
|
||||
'first-name': Value.text({
|
||||
spec: CB.Config.of({
|
||||
'first-name': CB.Value.text({
|
||||
name: 'First Name',
|
||||
required: false,
|
||||
description: 'User first name',
|
||||
}),
|
||||
'last-name': Value.text({
|
||||
'last-name': CB.Value.text({
|
||||
name: 'Last Name',
|
||||
required: {
|
||||
default: {
|
||||
@@ -878,7 +875,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
age: Value.number({
|
||||
age: CB.Value.number({
|
||||
name: 'Age',
|
||||
description: 'The age of the user',
|
||||
warning: 'User must be at least 18.',
|
||||
@@ -887,13 +884,13 @@ export module Mock {
|
||||
integer: false,
|
||||
}),
|
||||
}),
|
||||
displayAs: "I'm {{last-name}}, {{first-name}} {{last-name}}",
|
||||
displayAs: 'I\'m {{last-name}}, {{first-name}} {{last-name}}',
|
||||
uniqueBy: 'last-name',
|
||||
},
|
||||
),
|
||||
),
|
||||
'union-list': Value.list(
|
||||
List.obj(
|
||||
'union-list': CB.Value.list(
|
||||
CB.List.obj(
|
||||
{
|
||||
name: 'Union List',
|
||||
minLength: 0,
|
||||
@@ -903,27 +900,27 @@ export module Mock {
|
||||
warning: 'If you change this, things may work.',
|
||||
},
|
||||
{
|
||||
spec: Config.of({
|
||||
spec: CB.Config.of({
|
||||
/* TODO: Convert range for this value ([0, 2])*/
|
||||
union: Value.union(
|
||||
union: CB.Value.union(
|
||||
{
|
||||
name: 'Preference',
|
||||
description: null,
|
||||
warning: null,
|
||||
required: { default: 'summer' },
|
||||
},
|
||||
Variants.of({
|
||||
CB.Variants.of({
|
||||
summer: {
|
||||
name: 'summer',
|
||||
spec: Config.of({
|
||||
'favorite-tree': Value.text({
|
||||
spec: CB.Config.of({
|
||||
'favorite-tree': CB.Value.text({
|
||||
name: 'Favorite Tree',
|
||||
required: {
|
||||
default: 'Maple',
|
||||
},
|
||||
description: 'What is your favorite tree?',
|
||||
}),
|
||||
'favorite-flower': Value.select({
|
||||
'favorite-flower': CB.Value.select({
|
||||
name: 'Favorite Flower',
|
||||
description: 'Select your favorite flower',
|
||||
required: {
|
||||
@@ -940,8 +937,8 @@ export module Mock {
|
||||
},
|
||||
winter: {
|
||||
name: 'winter',
|
||||
spec: Config.of({
|
||||
'like-snow': Value.toggle({
|
||||
spec: CB.Config.of({
|
||||
'like-snow': CB.Value.toggle({
|
||||
name: 'Like Snow?',
|
||||
default: true,
|
||||
description: 'Do you like snow or not?',
|
||||
@@ -955,7 +952,7 @@ export module Mock {
|
||||
},
|
||||
),
|
||||
),
|
||||
'random-select': Value.select({
|
||||
'random-select': CB.Value.select({
|
||||
name: 'Random select',
|
||||
description: 'This is not even real.',
|
||||
warning: 'Be careful changing this!',
|
||||
@@ -970,7 +967,7 @@ export module Mock {
|
||||
disabled: ['option2'],
|
||||
}),
|
||||
'favorite-number':
|
||||
/* TODO: Convert range for this value ((-100,100])*/ Value.number({
|
||||
/* TODO: Convert range for this value ((-100,100])*/ CB.Value.number({
|
||||
name: 'Favorite Number',
|
||||
description: 'Your favorite number of all time',
|
||||
warning:
|
||||
@@ -981,8 +978,8 @@ export module Mock {
|
||||
integer: false,
|
||||
units: 'BTC',
|
||||
}),
|
||||
'unlucky-numbers': Value.list(
|
||||
List.number(
|
||||
'unlucky-numbers': CB.Value.list(
|
||||
CB.List.number(
|
||||
{
|
||||
name: 'Unlucky Numbers',
|
||||
minLength: 0,
|
||||
@@ -996,34 +993,34 @@ export module Mock {
|
||||
},
|
||||
),
|
||||
),
|
||||
rpcsettings: Value.object(
|
||||
rpcsettings: CB.Value.object(
|
||||
{
|
||||
name: 'RPC Settings',
|
||||
description: 'rpc username and password',
|
||||
warning:
|
||||
'Adding RPC users gives them special permissions on your node.',
|
||||
},
|
||||
Config.of({
|
||||
laws: Value.object(
|
||||
CB.Config.of({
|
||||
laws: CB.Value.object(
|
||||
{
|
||||
name: 'Laws',
|
||||
description: 'the law of the realm',
|
||||
},
|
||||
Config.of({
|
||||
law1: Value.text({
|
||||
CB.Config.of({
|
||||
law1: CB.Value.text({
|
||||
name: 'First Law',
|
||||
required: false,
|
||||
description: 'the first law',
|
||||
}),
|
||||
law2: Value.text({
|
||||
law2: CB.Value.text({
|
||||
name: 'Second Law',
|
||||
required: false,
|
||||
description: 'the second law',
|
||||
}),
|
||||
}),
|
||||
),
|
||||
rulemakers: Value.list(
|
||||
List.obj(
|
||||
rulemakers: CB.Value.list(
|
||||
CB.List.obj(
|
||||
{
|
||||
name: 'Rule Makers',
|
||||
minLength: 0,
|
||||
@@ -1031,8 +1028,8 @@ export module Mock {
|
||||
description: 'the people who make the rules',
|
||||
},
|
||||
{
|
||||
spec: Config.of({
|
||||
rulemakername: Value.text({
|
||||
spec: CB.Config.of({
|
||||
rulemakername: CB.Value.text({
|
||||
name: 'Rulemaker Name',
|
||||
required: {
|
||||
default: {
|
||||
@@ -1042,7 +1039,7 @@ export module Mock {
|
||||
},
|
||||
description: 'the name of the rule maker',
|
||||
}),
|
||||
rulemakerip: Value.text({
|
||||
rulemakerip: CB.Value.text({
|
||||
name: 'Rulemaker IP',
|
||||
required: {
|
||||
default: '192.168.1.0',
|
||||
@@ -1060,7 +1057,7 @@ export module Mock {
|
||||
},
|
||||
),
|
||||
),
|
||||
rpcuser: Value.text({
|
||||
rpcuser: CB.Value.text({
|
||||
name: 'RPC Username',
|
||||
required: {
|
||||
default: 'defaultrpcusername',
|
||||
@@ -1073,7 +1070,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
rpcpass: Value.text({
|
||||
rpcpass: CB.Value.text({
|
||||
name: 'RPC User Password',
|
||||
required: {
|
||||
default: {
|
||||
@@ -1086,7 +1083,7 @@ export module Mock {
|
||||
}),
|
||||
}),
|
||||
),
|
||||
'bitcoin-node': Value.union(
|
||||
'bitcoin-node': CB.Value.union(
|
||||
{
|
||||
name: 'Bitcoin Node',
|
||||
description: 'Options<ul><li>Item 1</li><li>Item 2</li></ul>',
|
||||
@@ -1094,25 +1091,25 @@ export module Mock {
|
||||
required: { default: 'internal' },
|
||||
disabled: ['fake'],
|
||||
},
|
||||
Variants.of({
|
||||
CB.Variants.of({
|
||||
fake: {
|
||||
name: 'Fake',
|
||||
spec: Config.of({}),
|
||||
spec: CB.Config.of({}),
|
||||
},
|
||||
internal: {
|
||||
name: 'Internal',
|
||||
spec: Config.of({}),
|
||||
spec: CB.Config.of({}),
|
||||
},
|
||||
external: {
|
||||
name: 'External',
|
||||
spec: Config.of({
|
||||
'emergency-contact': Value.object(
|
||||
spec: CB.Config.of({
|
||||
'emergency-contact': CB.Value.object(
|
||||
{
|
||||
name: 'Emergency Contact',
|
||||
description: 'The person to contact in case of emergency.',
|
||||
},
|
||||
Config.of({
|
||||
name: Value.text({
|
||||
CB.Config.of({
|
||||
name: CB.Value.text({
|
||||
name: 'Name',
|
||||
required: {
|
||||
default: null,
|
||||
@@ -1124,7 +1121,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
email: Value.text({
|
||||
email: CB.Value.text({
|
||||
name: 'Email',
|
||||
inputmode: 'email',
|
||||
required: {
|
||||
@@ -1133,7 +1130,7 @@ export module Mock {
|
||||
}),
|
||||
}),
|
||||
),
|
||||
'public-domain': Value.text({
|
||||
'public-domain': CB.Value.text({
|
||||
name: 'Public Domain',
|
||||
required: {
|
||||
default: 'bitcoinnode.com',
|
||||
@@ -1146,7 +1143,7 @@ export module Mock {
|
||||
},
|
||||
],
|
||||
}),
|
||||
'private-domain': Value.text({
|
||||
'private-domain': CB.Value.text({
|
||||
name: 'Private Domain',
|
||||
required: {
|
||||
default: null,
|
||||
@@ -1159,7 +1156,7 @@ export module Mock {
|
||||
},
|
||||
}),
|
||||
),
|
||||
port: Value.number({
|
||||
port: CB.Value.number({
|
||||
name: 'Port',
|
||||
description:
|
||||
'the default port for your Bitcoin node. default: 8333, testnet: 18333, regtest: 18444',
|
||||
@@ -1171,7 +1168,7 @@ export module Mock {
|
||||
step: 1,
|
||||
integer: true,
|
||||
}),
|
||||
'favorite-slogan': Value.text({
|
||||
'favorite-slogan': CB.Value.text({
|
||||
name: 'Favorite Slogan',
|
||||
generate: {
|
||||
charset: 'a-z,A-Z,2-9',
|
||||
@@ -1182,8 +1179,8 @@ export module Mock {
|
||||
'You most favorite slogan in the whole world, used for paying you.',
|
||||
masked: true,
|
||||
}),
|
||||
rpcallowip: Value.list(
|
||||
List.text(
|
||||
rpcallowip: CB.Value.list(
|
||||
CB.List.text(
|
||||
{
|
||||
name: 'RPC Allowed IPs',
|
||||
minLength: 1,
|
||||
@@ -1205,8 +1202,8 @@ export module Mock {
|
||||
},
|
||||
),
|
||||
),
|
||||
rpcauth: Value.list(
|
||||
List.text(
|
||||
rpcauth: CB.Value.list(
|
||||
CB.List.text(
|
||||
{
|
||||
name: 'RPC Auth',
|
||||
description:
|
||||
@@ -1251,7 +1248,7 @@ export module Mock {
|
||||
rulemakers: [],
|
||||
},
|
||||
'bitcoin-node': {
|
||||
[unionSelectKey]: 'internal',
|
||||
[CT.unionSelectKey]: 'internal',
|
||||
},
|
||||
port: 20,
|
||||
rpcallowip: undefined,
|
||||
|
||||
@@ -13,8 +13,8 @@ import {
|
||||
FollowLogsRes,
|
||||
FollowLogsReq,
|
||||
} from '@start9labs/shared'
|
||||
import { customSmtp } from '@start9labs/start-sdk/cjs/sdk/lib/config/configConstants'
|
||||
import { InputSpec } from '@start9labs/start-sdk/cjs/sdk/lib/config/configTypes'
|
||||
import { CT } from '@start9labs/start-sdk'
|
||||
import { config } from '@start9labs/start-sdk'
|
||||
|
||||
export module RR {
|
||||
// DB
|
||||
@@ -205,7 +205,8 @@ export module RR {
|
||||
|
||||
// email
|
||||
|
||||
export type ConfigureEmailReq = typeof customSmtp.validator._TYPE // email.configure
|
||||
export type ConfigureEmailReq =
|
||||
typeof config.constants.customSmtp.validator._TYPE // email.configure
|
||||
export type ConfigureEmailRes = null
|
||||
|
||||
export type TestEmailReq = ConfigureEmailReq & { to: string } // email.test
|
||||
@@ -319,7 +320,7 @@ export module RR {
|
||||
export type InstallPackageRes = null
|
||||
|
||||
export type GetPackageConfigReq = { id: string } // package.config.get
|
||||
export type GetPackageConfigRes = { spec: InputSpec; config: object }
|
||||
export type GetPackageConfigRes = { spec: CT.InputSpec; config: object }
|
||||
|
||||
export type DrySetPackageConfigReq = { id: string; config: object } // package.config.set.dry
|
||||
export type DrySetPackageConfigRes = Breakages
|
||||
@@ -361,7 +362,7 @@ export module RR {
|
||||
export type DryConfigureDependencyRes = {
|
||||
oldConfig: object
|
||||
newConfig: object
|
||||
spec: InputSpec
|
||||
spec: CT.InputSpec
|
||||
}
|
||||
|
||||
export type SideloadPackageReq = {
|
||||
|
||||
@@ -8,29 +8,7 @@ import {
|
||||
Validators,
|
||||
} from '@angular/forms'
|
||||
import { getDefaultString } from '../util/config-utilities'
|
||||
import {
|
||||
InputSpec,
|
||||
ListValueSpecNumber,
|
||||
ListValueSpecObject,
|
||||
ListValueSpecOf,
|
||||
ListValueSpecText,
|
||||
UniqueBy,
|
||||
ValueSpec,
|
||||
ValueSpecSelect,
|
||||
ValueSpecMultiselect,
|
||||
ValueSpecFile,
|
||||
ValueSpecList,
|
||||
ValueSpecNumber,
|
||||
ValueSpecObject,
|
||||
ValueSpecText,
|
||||
ValueSpecUnion,
|
||||
ValueSpecTextarea,
|
||||
ValueSpecColor,
|
||||
ValueSpecDatetime,
|
||||
unionSelectKey,
|
||||
unionValueKey,
|
||||
isValueSpecListOf,
|
||||
} from '@start9labs/start-sdk/cjs/sdk/lib/config/configTypes'
|
||||
import { CT } from '@start9labs/start-sdk'
|
||||
const Mustache = require('mustache')
|
||||
|
||||
@Injectable({
|
||||
@@ -40,16 +18,16 @@ export class FormService {
|
||||
constructor(private readonly formBuilder: UntypedFormBuilder) {}
|
||||
|
||||
createForm(
|
||||
spec: InputSpec,
|
||||
spec: CT.InputSpec,
|
||||
current: Record<string, any> = {},
|
||||
): UntypedFormGroup {
|
||||
return this.getFormGroup(spec, [], current)
|
||||
}
|
||||
|
||||
getUnionSelectSpec(
|
||||
spec: ValueSpecUnion,
|
||||
spec: CT.ValueSpecUnion,
|
||||
selection: string | null,
|
||||
): ValueSpecSelect {
|
||||
): CT.ValueSpecSelect {
|
||||
return {
|
||||
...spec,
|
||||
type: 'select',
|
||||
@@ -61,34 +39,34 @@ export class FormService {
|
||||
}
|
||||
|
||||
getUnionObject(
|
||||
spec: ValueSpecUnion,
|
||||
spec: CT.ValueSpecUnion,
|
||||
selection: string | null,
|
||||
): UntypedFormGroup {
|
||||
const group = this.getFormGroup({
|
||||
[unionSelectKey]: this.getUnionSelectSpec(spec, selection),
|
||||
[CT.unionSelectKey]: this.getUnionSelectSpec(spec, selection),
|
||||
})
|
||||
|
||||
group.setControl(
|
||||
unionValueKey,
|
||||
CT.unionValueKey,
|
||||
this.getFormGroup(selection ? spec.variants[selection].spec : {}),
|
||||
)
|
||||
|
||||
return group
|
||||
}
|
||||
|
||||
getListItem(spec: ValueSpecList, entry?: any) {
|
||||
getListItem(spec: CT.ValueSpecList, entry?: any) {
|
||||
const listItemValidators = getListItemValidators(spec)
|
||||
if (isValueSpecListOf(spec, 'text')) {
|
||||
if (CT.isValueSpecListOf(spec, 'text')) {
|
||||
return this.formBuilder.control(entry, listItemValidators)
|
||||
} else if (isValueSpecListOf(spec, 'number')) {
|
||||
} else if (CT.isValueSpecListOf(spec, 'number')) {
|
||||
return this.formBuilder.control(entry, listItemValidators)
|
||||
} else if (isValueSpecListOf(spec, 'object')) {
|
||||
} else if (CT.isValueSpecListOf(spec, 'object')) {
|
||||
return this.getFormGroup(spec.spec.spec, listItemValidators, entry)
|
||||
}
|
||||
}
|
||||
|
||||
getFormGroup(
|
||||
config: InputSpec,
|
||||
config: CT.InputSpec,
|
||||
validators: ValidatorFn[] = [],
|
||||
current?: Record<string, any> | null,
|
||||
): UntypedFormGroup {
|
||||
@@ -103,7 +81,7 @@ export class FormService {
|
||||
}
|
||||
|
||||
private getFormEntry(
|
||||
spec: ValueSpec,
|
||||
spec: CT.ValueSpec,
|
||||
currentValue?: any,
|
||||
): UntypedFormGroup | UntypedFormArray | UntypedFormControl {
|
||||
let value: any
|
||||
@@ -154,7 +132,7 @@ export class FormService {
|
||||
fileValidators(spec),
|
||||
)
|
||||
case 'union':
|
||||
const currentSelection = currentValue?.[unionSelectKey]
|
||||
const currentSelection = currentValue?.[CT.unionSelectKey]
|
||||
const isValid = !!spec.variants[currentSelection]
|
||||
|
||||
return this.getUnionObject(
|
||||
@@ -176,20 +154,20 @@ export class FormService {
|
||||
}
|
||||
}
|
||||
|
||||
function getListItemValidators(spec: ValueSpecList) {
|
||||
if (isValueSpecListOf(spec, 'text')) {
|
||||
function getListItemValidators(spec: CT.ValueSpecList) {
|
||||
if (CT.isValueSpecListOf(spec, 'text')) {
|
||||
return stringValidators(spec.spec)
|
||||
} else if (isValueSpecListOf(spec, 'number')) {
|
||||
} else if (CT.isValueSpecListOf(spec, 'number')) {
|
||||
return numberValidators(spec.spec)
|
||||
}
|
||||
}
|
||||
|
||||
function stringValidators(
|
||||
spec: ValueSpecText | ListValueSpecText,
|
||||
spec: CT.ValueSpecText | CT.ListValueSpecText,
|
||||
): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if ((spec as ValueSpecText).required) {
|
||||
if ((spec as CT.ValueSpecText).required) {
|
||||
validators.push(Validators.required)
|
||||
}
|
||||
|
||||
@@ -202,7 +180,7 @@ function stringValidators(
|
||||
return validators
|
||||
}
|
||||
|
||||
function textareaValidators(spec: ValueSpecTextarea): ValidatorFn[] {
|
||||
function textareaValidators(spec: CT.ValueSpecTextarea): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if (spec.required) {
|
||||
@@ -214,7 +192,7 @@ function textareaValidators(spec: ValueSpecTextarea): ValidatorFn[] {
|
||||
return validators
|
||||
}
|
||||
|
||||
function colorValidators({ required }: ValueSpecColor): ValidatorFn[] {
|
||||
function colorValidators({ required }: CT.ValueSpecColor): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = [Validators.pattern(/^#[0-9a-f]{6}$/i)]
|
||||
|
||||
if (required) {
|
||||
@@ -228,7 +206,7 @@ function datetimeValidators({
|
||||
required,
|
||||
min,
|
||||
max,
|
||||
}: ValueSpecDatetime): ValidatorFn[] {
|
||||
}: CT.ValueSpecDatetime): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if (required) {
|
||||
@@ -247,13 +225,13 @@ function datetimeValidators({
|
||||
}
|
||||
|
||||
function numberValidators(
|
||||
spec: ValueSpecNumber | ListValueSpecNumber,
|
||||
spec: CT.ValueSpecNumber | CT.ListValueSpecNumber,
|
||||
): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
validators.push(isNumber())
|
||||
|
||||
if ((spec as ValueSpecNumber).required) {
|
||||
if ((spec as CT.ValueSpecNumber).required) {
|
||||
validators.push(Validators.required)
|
||||
}
|
||||
|
||||
@@ -266,7 +244,7 @@ function numberValidators(
|
||||
return validators
|
||||
}
|
||||
|
||||
function selectValidators(spec: ValueSpecSelect): ValidatorFn[] {
|
||||
function selectValidators(spec: CT.ValueSpecSelect): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if (spec.required) {
|
||||
@@ -276,20 +254,20 @@ function selectValidators(spec: ValueSpecSelect): ValidatorFn[] {
|
||||
return validators
|
||||
}
|
||||
|
||||
function multiselectValidators(spec: ValueSpecMultiselect): ValidatorFn[] {
|
||||
function multiselectValidators(spec: CT.ValueSpecMultiselect): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
validators.push(listInRange(spec.minLength, spec.maxLength))
|
||||
return validators
|
||||
}
|
||||
|
||||
function listValidators(spec: ValueSpecList): ValidatorFn[] {
|
||||
function listValidators(spec: CT.ValueSpecList): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
validators.push(listInRange(spec.minLength, spec.maxLength))
|
||||
validators.push(listItemIssue())
|
||||
return validators
|
||||
}
|
||||
|
||||
function fileValidators(spec: ValueSpecFile): ValidatorFn[] {
|
||||
function fileValidators(spec: CT.ValueSpecFile): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if (spec.required) {
|
||||
@@ -397,7 +375,7 @@ export function listItemIssue(): ValidatorFn {
|
||||
}
|
||||
}
|
||||
|
||||
export function listUnique(spec: ValueSpecList): ValidatorFn {
|
||||
export function listUnique(spec: CT.ValueSpecList): ValidatorFn {
|
||||
return control => {
|
||||
const list = control.value
|
||||
for (let idx = 0; idx < list.length; idx++) {
|
||||
@@ -407,7 +385,7 @@ export function listUnique(spec: ValueSpecList): ValidatorFn {
|
||||
let display1: string
|
||||
let display2: string
|
||||
let uniqueMessage = isObject(objSpec)
|
||||
? uniqueByMessageWrapper(objSpec.uniqueBy, objSpec, list[idx])
|
||||
? uniqueByMessageWrapper(objSpec.uniqueBy, objSpec)
|
||||
: ''
|
||||
|
||||
if (isObject(objSpec) && objSpec.displayAs) {
|
||||
@@ -434,7 +412,7 @@ export function listUnique(spec: ValueSpecList): ValidatorFn {
|
||||
}
|
||||
}
|
||||
|
||||
function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean {
|
||||
function listItemEquals(spec: CT.ValueSpecList, val1: any, val2: any): boolean {
|
||||
// TODO: fix types
|
||||
switch (spec.spec.type) {
|
||||
case 'text':
|
||||
@@ -448,7 +426,7 @@ function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function itemEquals(spec: ValueSpec, val1: any, val2: any): boolean {
|
||||
function itemEquals(spec: CT.ValueSpec, val1: any, val2: any): boolean {
|
||||
switch (spec.type) {
|
||||
case 'text':
|
||||
case 'textarea':
|
||||
@@ -460,15 +438,15 @@ function itemEquals(spec: ValueSpec, val1: any, val2: any): boolean {
|
||||
// TODO: 'unique-by' does not exist on ValueSpecObject, fix types
|
||||
return objEquals(
|
||||
(spec as any)['unique-by'],
|
||||
spec as ValueSpecObject,
|
||||
spec as CT.ValueSpecObject,
|
||||
val1,
|
||||
val2,
|
||||
)
|
||||
case 'union':
|
||||
// TODO: 'unique-by' does not exist on ValueSpecUnion, fix types
|
||||
// TODO: 'unique-by' does not exist on CT.ValueSpecUnion, fix types
|
||||
return unionEquals(
|
||||
(spec as any)['unique-by'],
|
||||
spec as ValueSpecUnion,
|
||||
spec as CT.ValueSpecUnion,
|
||||
val1,
|
||||
val2,
|
||||
)
|
||||
@@ -488,8 +466,8 @@ function itemEquals(spec: ValueSpec, val1: any, val2: any): boolean {
|
||||
}
|
||||
|
||||
function listObjEquals(
|
||||
uniqueBy: UniqueBy,
|
||||
spec: ListValueSpecObject,
|
||||
uniqueBy: CT.UniqueBy,
|
||||
spec: CT.ListValueSpecObject,
|
||||
val1: any,
|
||||
val2: any,
|
||||
): boolean {
|
||||
@@ -516,8 +494,8 @@ function listObjEquals(
|
||||
}
|
||||
|
||||
function objEquals(
|
||||
uniqueBy: UniqueBy,
|
||||
spec: ValueSpecObject,
|
||||
uniqueBy: CT.UniqueBy,
|
||||
spec: CT.ValueSpecObject,
|
||||
val1: any,
|
||||
val2: any,
|
||||
): boolean {
|
||||
@@ -545,17 +523,17 @@ function objEquals(
|
||||
}
|
||||
|
||||
function unionEquals(
|
||||
uniqueBy: UniqueBy,
|
||||
spec: ValueSpecUnion,
|
||||
uniqueBy: CT.UniqueBy,
|
||||
spec: CT.ValueSpecUnion,
|
||||
val1: any,
|
||||
val2: any,
|
||||
): boolean {
|
||||
const variantSpec = spec.variants[val1[unionSelectKey]].spec
|
||||
const variantSpec = spec.variants[val1[CT.unionSelectKey]].spec
|
||||
if (!uniqueBy) {
|
||||
return false
|
||||
} else if (typeof uniqueBy === 'string') {
|
||||
if (uniqueBy === unionSelectKey) {
|
||||
return val1[unionSelectKey] === val2[unionSelectKey]
|
||||
if (uniqueBy === CT.unionSelectKey) {
|
||||
return val1[CT.unionSelectKey] === val2[CT.unionSelectKey]
|
||||
} else {
|
||||
return itemEquals(variantSpec[uniqueBy], val1[uniqueBy], val2[uniqueBy])
|
||||
}
|
||||
@@ -578,9 +556,8 @@ function unionEquals(
|
||||
}
|
||||
|
||||
function uniqueByMessageWrapper(
|
||||
uniqueBy: UniqueBy,
|
||||
spec: ListValueSpecObject,
|
||||
obj: Record<string, string>,
|
||||
uniqueBy: CT.UniqueBy,
|
||||
spec: CT.ListValueSpecObject,
|
||||
) {
|
||||
let configSpec = spec.spec
|
||||
|
||||
@@ -591,8 +568,8 @@ function uniqueByMessageWrapper(
|
||||
}
|
||||
|
||||
function uniqueByMessage(
|
||||
uniqueBy: UniqueBy,
|
||||
configSpec: InputSpec,
|
||||
uniqueBy: CT.UniqueBy,
|
||||
configSpec: CT.InputSpec,
|
||||
outermost = true,
|
||||
): string {
|
||||
let joinFunc
|
||||
@@ -601,7 +578,7 @@ function uniqueByMessage(
|
||||
return ''
|
||||
} else if (typeof uniqueBy === 'string') {
|
||||
return configSpec[uniqueBy]
|
||||
? (configSpec[uniqueBy] as ValueSpecObject).name
|
||||
? (configSpec[uniqueBy] as CT.ValueSpecObject).name
|
||||
: uniqueBy
|
||||
} else if ('any' in uniqueBy) {
|
||||
joinFunc = ' OR '
|
||||
@@ -620,13 +597,15 @@ function uniqueByMessage(
|
||||
: '(' + ret + ')'
|
||||
}
|
||||
|
||||
function isObject(spec: ListValueSpecOf<any>): spec is ListValueSpecObject {
|
||||
function isObject(
|
||||
spec: CT.ListValueSpecOf<any>,
|
||||
): spec is CT.ListValueSpecObject {
|
||||
// only lists of objects have uniqueBy
|
||||
return 'uniqueBy' in spec
|
||||
}
|
||||
|
||||
export function convertValuesRecursive(
|
||||
configSpec: InputSpec,
|
||||
configSpec: CT.InputSpec,
|
||||
group: UntypedFormGroup,
|
||||
) {
|
||||
Object.entries(configSpec).forEach(([key, valueSpec]) => {
|
||||
@@ -645,7 +624,7 @@ export function convertValuesRecursive(
|
||||
} else if (valueSpec.type === 'union') {
|
||||
const formGr = group.get(key) as UntypedFormGroup
|
||||
const spec =
|
||||
valueSpec.variants[formGr.controls[unionSelectKey].value].spec
|
||||
valueSpec.variants[formGr.controls[CT.unionSelectKey].value].spec
|
||||
convertValuesRecursive(spec, formGr)
|
||||
} else if (valueSpec.type === 'list') {
|
||||
const formArr = group.get(key) as UntypedFormArray
|
||||
@@ -661,7 +640,7 @@ export function convertValuesRecursive(
|
||||
})
|
||||
} else if (valueSpec.spec.type === 'object') {
|
||||
controls.forEach(formGroup => {
|
||||
const objectSpec = valueSpec.spec as ListValueSpecObject
|
||||
const objectSpec = valueSpec.spec as CT.ListValueSpecObject
|
||||
convertValuesRecursive(objectSpec.spec, formGroup as UntypedFormGroup)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@ import { BackupJob, ServerNotifications } from '../api/api.types'
|
||||
import { Url } from '@start9labs/shared'
|
||||
import { Manifest } from '@start9labs/marketplace'
|
||||
import { T } from '@start9labs/start-sdk'
|
||||
import {
|
||||
ActionMetadata,
|
||||
HostnameInfo,
|
||||
} from '@start9labs/start-sdk/cjs/sdk/lib/types'
|
||||
import { customSmtp } from '@start9labs/start-sdk/cjs/sdk/lib/config/configConstants'
|
||||
import { config } from '@start9labs/start-sdk'
|
||||
|
||||
export interface DataModel {
|
||||
serverInfo: ServerInfo
|
||||
@@ -59,7 +55,7 @@ export interface ServerInfo {
|
||||
id: string
|
||||
version: string
|
||||
country: string
|
||||
ui: HostnameInfo[]
|
||||
ui: T.HostnameInfo[]
|
||||
network: NetworkInfo
|
||||
lastBackup: string | null
|
||||
unreadNotifications: {
|
||||
@@ -71,7 +67,7 @@ export interface ServerInfo {
|
||||
pubkey: string
|
||||
caFingerprint: string
|
||||
ntpSynced: boolean
|
||||
smtp: typeof customSmtp.validator._TYPE
|
||||
smtp: typeof config.constants.customSmtp.validator._TYPE
|
||||
passwordHash: string
|
||||
platform: string
|
||||
}
|
||||
@@ -156,7 +152,7 @@ export type PackageDataEntry<T extends StateInfo = StateInfo> = {
|
||||
stateInfo: T
|
||||
icon: Url
|
||||
status: Status
|
||||
actions: Record<string, ActionMetadata>
|
||||
actions: Record<string, T.ActionMetadata>
|
||||
lastBackup: string | null
|
||||
currentDependencies: { [id: string]: CurrentDependencyInfo }
|
||||
dependencyInfo: {
|
||||
|
||||
@@ -11,8 +11,7 @@ import { FormDialogService } from 'src/app/services/form-dialog.service'
|
||||
import { configBuilderToSpec } from 'src/app/util/configBuilderToSpec'
|
||||
import { ApiService } from './api/embassy-api.service'
|
||||
import { DataModel } from './patch-db/data-model'
|
||||
import { Config } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/config'
|
||||
import { Value } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/value'
|
||||
import { CB } from '@start9labs/start-sdk'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -30,14 +29,12 @@ export class ProxyService {
|
||||
const network = await firstValueFrom(
|
||||
this.patch.watch$('serverInfo', 'network'),
|
||||
)
|
||||
const config = Config.of({
|
||||
proxyId: Value.select({
|
||||
const config = CB.Config.of({
|
||||
proxyId: CB.Value.select({
|
||||
name: 'Select Proxy',
|
||||
required: { default: current },
|
||||
values: network.proxies
|
||||
.filter(
|
||||
p => p.type === 'outbound' || p.type === 'inbound-outbound',
|
||||
)
|
||||
.filter(p => p.type === 'outbound' || p.type === 'inbound-outbound')
|
||||
.reduce((prev, curr) => {
|
||||
return {
|
||||
[curr.id]: curr.name,
|
||||
@@ -71,10 +68,7 @@ export class ProxyService {
|
||||
this.formDialog.open(FormComponent, options)
|
||||
}
|
||||
|
||||
private async saveOutboundProxy(
|
||||
proxy: string | null,
|
||||
packageId?: string,
|
||||
) {
|
||||
private async saveOutboundProxy(proxy: string | null, packageId?: string) {
|
||||
const loader = this.loader.open(`Saving`).subscribe()
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user