Merge branch 'feat/preferred-port-design' of github.com:Start9Labs/start-os into claude

This commit is contained in:
Matt Hill
2026-02-14 08:14:43 -07:00
111 changed files with 11787 additions and 14728 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayType } from './GatewayType'
export type AddTunnelParams = { name: string; config: string; public: boolean }
export type AddTunnelParams = {
name: string
config: string
type: GatewayType | null
setAsDefaultOutbound: boolean
}

View File

@@ -1,5 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { BindOptions } from './BindOptions'
import type { DerivedAddressInfo } from './DerivedAddressInfo'
import type { NetInfo } from './NetInfo'
export type BindInfo = { enabled: boolean; options: BindOptions; net: NetInfo }
export type BindInfo = {
enabled: boolean
options: BindOptions
net: NetInfo
addresses: DerivedAddressInfo
}

View File

@@ -1,8 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayId } from './GatewayId'
export type BindingGatewaySetEnabledParams = {
export type BindingSetAddressEnabledParams = {
internalPort: number
gateway: GatewayId
address: string
enabled: boolean | null
}

View File

@@ -1,7 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { BindInfo } from './BindInfo'
export type OnionHostname = {
value: string
port: number | null
sslPort: number | null
}
export type Bindings = { [key: number]: BindInfo }

View File

@@ -0,0 +1,17 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { HostnameInfo } from './HostnameInfo'
export type DerivedAddressInfo = {
/**
* User override: enable these addresses (only for public IP & port)
*/
enabled: Array<string>
/**
* User override: disable these addresses (only for domains and private IP & port)
*/
disabled: Array<[string, number]>
/**
* COMPUTED: NetServiceData::update — all possible addresses for this binding
*/
available: Array<HostnameInfo>
}

View File

@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ErrorData = { details: string; debug: string }
export type ErrorData = { details: string; debug: string; info: unknown }

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type GatewayType = 'inbound-outbound' | 'outbound-only'

View File

@@ -1,15 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { BindInfo } from './BindInfo'
import type { HostnameInfo } from './HostnameInfo'
import type { Bindings } from './Bindings'
import type { GatewayId } from './GatewayId'
import type { PublicDomainConfig } from './PublicDomainConfig'
export type Host = {
bindings: { [key: number]: BindInfo }
onions: string[]
bindings: Bindings
publicDomains: { [key: string]: PublicDomainConfig }
privateDomains: Array<string>
/**
* COMPUTED: NetService::update
*/
hostnameInfo: { [key: number]: Array<HostnameInfo> }
privateDomains: { [key: string]: Array<GatewayId> }
}

View File

@@ -1,8 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayInfo } from './GatewayInfo'
import type { IpHostname } from './IpHostname'
import type { OnionHostname } from './OnionHostname'
import type { HostnameMetadata } from './HostnameMetadata'
export type HostnameInfo =
| { kind: 'ip'; gateway: GatewayInfo; public: boolean; hostname: IpHostname }
| { kind: 'onion'; hostname: OnionHostname }
export type HostnameInfo = {
ssl: boolean
public: boolean
host: string
port: number | null
metadata: HostnameMetadata
}

View File

@@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayId } from './GatewayId'
import type { PackageId } from './PackageId'
export type HostnameMetadata =
| { kind: 'ipv4'; gateway: GatewayId }
| { kind: 'ipv6'; gateway: GatewayId; scopeId: number }
| { kind: 'private-domain'; gateways: Array<GatewayId> }
| { kind: 'public-domain'; gateway: GatewayId }
| { kind: 'plugin'; package: PackageId }

View File

@@ -1,23 +0,0 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type IpHostname =
| { kind: 'ipv4'; value: string; port: number | null; sslPort: number | null }
| {
kind: 'ipv6'
value: string
scopeId: number
port: number | null
sslPort: number | null
}
| {
kind: 'local'
value: string
port: number | null
sslPort: number | null
}
| {
kind: 'domain'
value: string
port: number | null
sslPort: number | null
}

View File

@@ -1,9 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayId } from './GatewayId'
export type NetInfo = {
privateDisabled: Array<GatewayId>
publicEnabled: Array<GatewayId>
assignedPort: number | null
assignedSslPort: number | null
}

View File

@@ -13,4 +13,5 @@ export type NetworkInfo = {
gateways: { [key: GatewayId]: NetworkInterfaceInfo }
acme: { [key: AcmeProvider]: AcmeSettings }
dns: DnsSettings
defaultOutbound: string | null
}

View File

@@ -1,9 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GatewayType } from './GatewayType'
import type { IpInfo } from './IpInfo'
export type NetworkInterfaceInfo = {
name: string | null
public: boolean | null
secure: boolean | null
ipInfo: IpInfo | null
type: GatewayType | null
}

View File

@@ -25,4 +25,5 @@ export type PackageDataEntry = {
serviceInterfaces: { [key: ServiceInterfaceId]: ServiceInterface }
hosts: Hosts
storeExposedDependents: string[]
outboundGateway: string | null
}

View File

@@ -1,3 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { LocaleString } from './LocaleString'
export type PackageInfoShort = { releaseNotes: string }
export type PackageInfoShort = { releaseNotes: LocaleString }

View File

@@ -36,7 +36,8 @@ export { BackupTargetFS } from './BackupTargetFS'
export { Base64 } from './Base64'
export { BindId } from './BindId'
export { BindInfo } from './BindInfo'
export { BindingGatewaySetEnabledParams } from './BindingGatewaySetEnabledParams'
export { BindingSetAddressEnabledParams } from './BindingSetAddressEnabledParams'
export { Bindings } from './Bindings'
export { BindOptions } from './BindOptions'
export { BindParams } from './BindParams'
export { Blake3Commitment } from './Blake3Commitment'
@@ -64,6 +65,7 @@ export { Dependencies } from './Dependencies'
export { DependencyMetadata } from './DependencyMetadata'
export { DependencyRequirement } from './DependencyRequirement'
export { DepInfo } from './DepInfo'
export { DerivedAddressInfo } from './DerivedAddressInfo'
export { Description } from './Description'
export { DesiredStatus } from './DesiredStatus'
export { DestroySubcontainerFsParams } from './DestroySubcontainerFsParams'
@@ -83,6 +85,7 @@ export { FullIndex } from './FullIndex'
export { FullProgress } from './FullProgress'
export { GatewayId } from './GatewayId'
export { GatewayInfo } from './GatewayInfo'
export { GatewayType } from './GatewayType'
export { GetActionInputParams } from './GetActionInputParams'
export { GetContainerIpParams } from './GetContainerIpParams'
export { GetHostInfoParams } from './GetHostInfoParams'
@@ -106,6 +109,7 @@ export { HardwareRequirements } from './HardwareRequirements'
export { HealthCheckId } from './HealthCheckId'
export { HostId } from './HostId'
export { HostnameInfo } from './HostnameInfo'
export { HostnameMetadata } from './HostnameMetadata'
export { Hosts } from './Hosts'
export { Host } from './Host'
export { IdMap } from './IdMap'
@@ -119,7 +123,6 @@ export { InstalledVersionParams } from './InstalledVersionParams'
export { InstallingInfo } from './InstallingInfo'
export { InstallingState } from './InstallingState'
export { InstallParams } from './InstallParams'
export { IpHostname } from './IpHostname'
export { IpInfo } from './IpInfo'
export { KeyboardOptions } from './KeyboardOptions'
export { ListPackageSignersParams } from './ListPackageSignersParams'
@@ -149,7 +152,6 @@ export { NetInfo } from './NetInfo'
export { NetworkInfo } from './NetworkInfo'
export { NetworkInterfaceInfo } from './NetworkInterfaceInfo'
export { NetworkInterfaceType } from './NetworkInterfaceType'
export { OnionHostname } from './OnionHostname'
export { OsIndex } from './OsIndex'
export { OsVersionInfoMap } from './OsVersionInfoMap'
export { OsVersionInfo } from './OsVersionInfo'

View File

@@ -1,6 +1,12 @@
import { PackageId, ServiceInterfaceId, ServiceInterfaceType } from '../types'
import { knownProtocols } from '../interfaces/Host'
import { AddressInfo, Host, Hostname, HostnameInfo } from '../types'
import {
AddressInfo,
DerivedAddressInfo,
Host,
Hostname,
HostnameInfo,
} from '../types'
import { Effects } from '../Effects'
import { DropGenerator, DropPromise } from './Drop'
import { IpAddress, IPV6_LINK_LOCAL } from './ip'
@@ -20,7 +26,6 @@ export const getHostname = (url: string): Hostname | null => {
}
type FilterKinds =
| 'onion'
| 'mdns'
| 'domain'
| 'ip'
@@ -42,27 +47,26 @@ type VisibilityFilter<V extends 'public' | 'private'> = V extends 'public'
| (HostnameInfo & { public: false })
| VisibilityFilter<Exclude<V, 'private'>>
: never
type KindFilter<K extends FilterKinds> = K extends 'onion'
? (HostnameInfo & { kind: 'onion' }) | KindFilter<Exclude<K, 'onion'>>
: K extends 'mdns'
type KindFilter<K extends FilterKinds> = K extends 'mdns'
?
| (HostnameInfo & { metadata: { kind: 'private-domain' } })
| KindFilter<Exclude<K, 'mdns'>>
: K extends 'domain'
?
| (HostnameInfo & { kind: 'ip'; hostname: { kind: 'local' } })
| KindFilter<Exclude<K, 'mdns'>>
: K extends 'domain'
| (HostnameInfo & { metadata: { kind: 'private-domain' } })
| (HostnameInfo & { metadata: { kind: 'public-domain' } })
| KindFilter<Exclude<K, 'domain'>>
: K extends 'ipv4'
?
| (HostnameInfo & { kind: 'ip'; hostname: { kind: 'domain' } })
| KindFilter<Exclude<K, 'domain'>>
: K extends 'ipv4'
| (HostnameInfo & { metadata: { kind: 'ipv4' } })
| KindFilter<Exclude<K, 'ipv4'>>
: K extends 'ipv6'
?
| (HostnameInfo & { kind: 'ip'; hostname: { kind: 'ipv4' } })
| KindFilter<Exclude<K, 'ipv4'>>
: K extends 'ipv6'
?
| (HostnameInfo & { kind: 'ip'; hostname: { kind: 'ipv6' } })
| KindFilter<Exclude<K, 'ipv6'>>
: K extends 'ip'
? KindFilter<Exclude<K, 'ip'> | 'ipv4' | 'ipv6'>
: never
| (HostnameInfo & { metadata: { kind: 'ipv6' } })
| KindFilter<Exclude<K, 'ipv6'>>
: K extends 'ip'
? KindFilter<Exclude<K, 'ip'> | 'ipv4' | 'ipv6'>
: never
type FilterReturnTy<F extends Filter> = F extends {
visibility: infer V extends 'public' | 'private'
@@ -90,10 +94,6 @@ const nonLocalFilter = {
const publicFilter = {
visibility: 'public',
} as const
const onionFilter = {
kind: 'onion',
} as const
type Formats = 'hostname-info' | 'urlstring' | 'url'
type FormatReturnTy<
F extends Filter,
@@ -109,10 +109,7 @@ type FormatReturnTy<
export type Filled<F extends Filter = {}> = {
hostnames: HostnameInfo[]
toUrls: (h: HostnameInfo) => {
url: UrlString | null
sslUrl: UrlString | null
}
toUrl: (h: HostnameInfo) => UrlString
format: <Format extends Formats = 'urlstring'>(
format?: Format,
@@ -124,7 +121,6 @@ export type Filled<F extends Filter = {}> = {
nonLocal: Filled<typeof nonLocalFilter & Filter>
public: Filled<typeof publicFilter & Filter>
onion: Filled<typeof onionFilter & Filter>
}
export type FilledAddressInfo = AddressInfo & Filled
export type ServiceInterfaceFilled = {
@@ -154,41 +150,29 @@ const unique = <A>(values: A[]) => Array.from(new Set(values))
export const addressHostToUrl = (
{ scheme, sslScheme, username, suffix }: AddressInfo,
hostname: HostnameInfo,
): { url: UrlString | null; sslUrl: UrlString | null } => {
const res = []
const fmt = (scheme: string | null, host: HostnameInfo, port: number) => {
): UrlString => {
const effectiveScheme = hostname.ssl ? sslScheme : scheme
let host: string
if (hostname.metadata.kind === 'ipv6') {
host = IPV6_LINK_LOCAL.contains(hostname.host)
? `[${hostname.host}%${hostname.metadata.scopeId}]`
: `[${hostname.host}]`
} else {
host = hostname.host
}
let portStr = ''
if (hostname.port !== null) {
const excludePort =
scheme &&
scheme in knownProtocols &&
port === knownProtocols[scheme as keyof typeof knownProtocols].defaultPort
let hostname
if (host.kind === 'onion') {
hostname = host.hostname.value
} else if (host.kind === 'ip') {
if (host.hostname.kind === 'domain') {
hostname = host.hostname.value
} else if (host.hostname.kind === 'ipv6') {
hostname = IPV6_LINK_LOCAL.contains(host.hostname.value)
? `[${host.hostname.value}%${host.hostname.scopeId}]`
: `[${host.hostname.value}]`
} else {
hostname = host.hostname.value
}
}
return `${scheme ? `${scheme}://` : ''}${
username ? `${username}@` : ''
}${hostname}${excludePort ? '' : `:${port}`}${suffix}`
effectiveScheme &&
effectiveScheme in knownProtocols &&
hostname.port ===
knownProtocols[effectiveScheme as keyof typeof knownProtocols]
.defaultPort
if (!excludePort) portStr = `:${hostname.port}`
}
let url = null
if (hostname.hostname.port !== null) {
url = fmt(scheme, hostname, hostname.hostname.port)
}
let sslUrl = null
if (hostname.hostname.sslPort !== null) {
sslUrl = fmt(sslScheme, hostname, hostname.hostname.sslPort)
}
return { url, sslUrl }
return `${effectiveScheme ? `${effectiveScheme}://` : ''}${
username ? `${username}@` : ''
}${host}${portStr}${suffix}`
}
function filterRec(
@@ -201,13 +185,9 @@ function filterRec(
hostnames = hostnames.filter((h) => invert !== pred(h))
}
if (filter.visibility === 'public')
hostnames = hostnames.filter(
(h) => invert !== (h.kind === 'onion' || h.public),
)
hostnames = hostnames.filter((h) => invert !== h.public)
if (filter.visibility === 'private')
hostnames = hostnames.filter(
(h) => invert !== (h.kind !== 'onion' && !h.public),
)
hostnames = hostnames.filter((h) => invert !== !h.public)
if (filter.kind) {
const kind = new Set(
Array.isArray(filter.kind) ? filter.kind : [filter.kind],
@@ -219,21 +199,19 @@ function filterRec(
hostnames = hostnames.filter(
(h) =>
invert !==
((kind.has('onion') && h.kind === 'onion') ||
(kind.has('mdns') &&
h.kind === 'ip' &&
h.hostname.kind === 'local') ||
((kind.has('mdns') &&
h.metadata.kind === 'private-domain' &&
h.host.endsWith('.local')) ||
(kind.has('domain') &&
h.kind === 'ip' &&
h.hostname.kind === 'domain') ||
(kind.has('ipv4') && h.kind === 'ip' && h.hostname.kind === 'ipv4') ||
(kind.has('ipv6') && h.kind === 'ip' && h.hostname.kind === 'ipv6') ||
(h.metadata.kind === 'private-domain' ||
h.metadata.kind === 'public-domain')) ||
(kind.has('ipv4') && h.metadata.kind === 'ipv4') ||
(kind.has('ipv6') && h.metadata.kind === 'ipv6') ||
(kind.has('localhost') &&
['localhost', '127.0.0.1', '::1'].includes(h.hostname.value)) ||
['localhost', '127.0.0.1', '::1'].includes(h.host)) ||
(kind.has('link-local') &&
h.kind === 'ip' &&
h.hostname.kind === 'ipv6' &&
IPV6_LINK_LOCAL.contains(IpAddress.parse(h.hostname.value)))),
h.metadata.kind === 'ipv6' &&
IPV6_LINK_LOCAL.contains(IpAddress.parse(h.host)))),
)
}
@@ -242,16 +220,36 @@ function filterRec(
return hostnames
}
function isPublicIp(h: HostnameInfo): boolean {
return h.public && (h.metadata.kind === 'ipv4' || h.metadata.kind === 'ipv6')
}
function enabledAddresses(addr: DerivedAddressInfo): HostnameInfo[] {
return addr.available.filter((h) => {
if (isPublicIp(h)) {
// Public IPs: disabled by default, explicitly enabled via SocketAddr string
if (h.port === null) return true
const sa =
h.metadata.kind === 'ipv6'
? `[${h.host}]:${h.port}`
: `${h.host}:${h.port}`
return addr.enabled.includes(sa)
} else {
// Everything else: enabled by default, explicitly disabled via [host, port] tuple
return !addr.disabled.some(
([host, port]) => host === h.host && port === (h.port ?? 0),
)
}
})
}
export const filledAddress = (
host: Host,
addressInfo: AddressInfo,
): FilledAddressInfo => {
const toUrls = addressHostToUrl.bind(null, addressInfo)
const toUrlArray = (h: HostnameInfo) => {
const u = toUrls(h)
return [u.url, u.sslUrl].filter((u) => u !== null)
}
const hostnames = host.hostnameInfo[addressInfo.internalPort] ?? []
const toUrl = addressHostToUrl.bind(null, addressInfo)
const binding = host.bindings[addressInfo.internalPort]
const hostnames = binding ? enabledAddresses(binding.addresses) : []
function filledAddressFromHostnames<F extends Filter>(
hostnames: HostnameInfo[],
@@ -266,19 +264,14 @@ export const filledAddress = (
filterRec(hostnames, publicFilter, false),
),
)
const getOnion = once(() =>
filledAddressFromHostnames<typeof onionFilter & F>(
filterRec(hostnames, onionFilter, false),
),
)
return {
...addressInfo,
hostnames,
toUrls,
toUrl,
format: <Format extends Formats = 'urlstring'>(format?: Format) => {
let res: FormatReturnTy<{}, Format>[] = hostnames as any
if (format === 'hostname-info') return res
const urls = hostnames.flatMap(toUrlArray)
const urls = hostnames.map(toUrl)
if (format === 'url') res = urls.map((u) => new URL(u)) as any
else res = urls as any
return res
@@ -294,9 +287,6 @@ export const filledAddress = (
get public(): Filled<typeof publicFilter & F> {
return getPublic()
},
get onion(): Filled<typeof onionFilter & F> {
return getOnion()
},
}
}

View File

@@ -21,11 +21,6 @@ export const localHostname: Pattern = {
description: 'Must be a valid ".local" hostname',
}
export const torHostname: Pattern = {
regex: regexes.torHostname.matches(),
description: 'Must be a valid Tor (".onion") hostname',
}
export const url: Pattern = {
regex: regexes.url.matches(),
description: 'Must be a valid URL',
@@ -36,11 +31,6 @@ export const localUrl: Pattern = {
description: 'Must be a valid ".local" URL',
}
export const torUrl: Pattern = {
regex: regexes.torUrl.matches(),
description: 'Must be a valid Tor (".onion") URL',
}
export const ascii: Pattern = {
regex: regexes.ascii.matches(),
description:

View File

@@ -39,10 +39,6 @@ export const localHostname = new ComposableRegex(
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local/,
)
export const torHostname = new ComposableRegex(
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.onion/,
)
// https://ihateregex.io/expr/url/
export const url = new ComposableRegex(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/,
@@ -52,10 +48,6 @@ export const localUrl = new ComposableRegex(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/,
)
export const torUrl = new ComposableRegex(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.onion\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/,
)
// https://ihateregex.io/expr/ascii/
export const ascii = new ComposableRegex(/[ -~]*/)

View File

@@ -67,7 +67,7 @@ import {
import { getOwnServiceInterfaces } from '../../base/lib/util/getServiceInterfaces'
import { Volumes, createVolumes } from './util/Volume'
export const OSVersion = testTypeVersion('0.4.0-alpha.19')
export const OSVersion = testTypeVersion('0.4.0-alpha.20')
// prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> =

View File

@@ -1,9 +1,9 @@
import * as fs from "fs"
import * as fs from 'fs'
// https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case
export function camelCase(value: string) {
return value
.replace(/([\(\)\[\]])/g, "")
.replace(/([\(\)\[\]])/g, '')
.replace(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2, offset) {
if (p2) return p2.toUpperCase()
return p1.toLowerCase()
@@ -23,12 +23,12 @@ export async function oldSpecToBuilder(
}
function isString(x: unknown): x is string {
return typeof x === "string"
return typeof x === 'string'
}
export default async function makeFileContentFromOld(
inputData: Promise<any> | any,
{ StartSdk = "start-sdk", nested = true } = {},
{ StartSdk = 'start-sdk', nested = true } = {},
) {
const outputLines: string[] = []
outputLines.push(`
@@ -37,16 +37,16 @@ const {InputSpec, List, Value, Variants} = sdk
`)
const data = await inputData
const namedConsts = new Set(["InputSpec", "Value", "List"])
const inputSpecName = newConst("inputSpecSpec", convertInputSpec(data))
const namedConsts = new Set(['InputSpec', 'Value', 'List'])
const inputSpecName = newConst('inputSpecSpec', convertInputSpec(data))
outputLines.push(`export type InputSpecSpec = typeof ${inputSpecName}._TYPE;`)
return outputLines.join("\n")
return outputLines.join('\n')
function newConst(key: string, data: string, type?: string) {
const variableName = getNextConstName(camelCase(key))
outputLines.push(
`export const ${variableName}${!type ? "" : `: ${type}`} = ${data};`,
`export const ${variableName}${!type ? '' : `: ${type}`} = ${data};`,
)
return variableName
}
@@ -55,7 +55,7 @@ const {InputSpec, List, Value, Variants} = sdk
return newConst(key, data)
}
function convertInputSpecInner(data: any) {
let answer = "{"
let answer = '{'
for (const [key, value] of Object.entries(data)) {
const variableName = maybeNewConst(key, convertValueSpec(value))
@@ -69,7 +69,7 @@ const {InputSpec, List, Value, Variants} = sdk
}
function convertValueSpec(value: any): string {
switch (value.type) {
case "string": {
case 'string': {
if (value.textarea) {
return `${rangeToTodoComment(
value?.range,
@@ -99,12 +99,12 @@ const {InputSpec, List, Value, Variants} = sdk
warning: value.warning || null,
masked: value.masked || false,
placeholder: value.placeholder || null,
inputmode: "text",
inputmode: 'text',
patterns: value.pattern
? [
{
regex: value.pattern,
description: value["pattern-description"],
description: value['pattern-description'],
},
]
: [],
@@ -115,7 +115,7 @@ const {InputSpec, List, Value, Variants} = sdk
2,
)})`
}
case "number": {
case 'number': {
return `${rangeToTodoComment(
value?.range,
)}Value.number(${JSON.stringify(
@@ -136,7 +136,7 @@ const {InputSpec, List, Value, Variants} = sdk
2,
)})`
}
case "boolean": {
case 'boolean': {
return `Value.toggle(${JSON.stringify(
{
name: value.name || null,
@@ -148,15 +148,15 @@ const {InputSpec, List, Value, Variants} = sdk
2,
)})`
}
case "enum": {
case 'enum': {
const allValueNames = new Set([
...(value?.["values"] || []),
...Object.keys(value?.["value-names"] || {}),
...(value?.['values'] || []),
...Object.keys(value?.['value-names'] || {}),
])
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(isString)
.map((key) => [key, value?.spec?.["value-names"]?.[key] || key]),
.map((key) => [key, value?.spec?.['value-names']?.[key] || key]),
)
return `Value.select(${JSON.stringify(
{
@@ -170,9 +170,9 @@ const {InputSpec, List, Value, Variants} = sdk
2,
)} as const)`
}
case "object": {
case 'object': {
const specName = maybeNewConst(
value.name + "_spec",
value.name + '_spec',
convertInputSpec(value.spec),
)
return `Value.object({
@@ -180,10 +180,10 @@ const {InputSpec, List, Value, Variants} = sdk
description: ${JSON.stringify(value.description || null)},
}, ${specName})`
}
case "union": {
case 'union': {
const variants = maybeNewConst(
value.name + "_variants",
convertVariants(value.variants, value.tag["variant-names"] || {}),
value.name + '_variants',
convertVariants(value.variants, value.tag['variant-names'] || {}),
)
return `Value.union({
@@ -194,18 +194,18 @@ const {InputSpec, List, Value, Variants} = sdk
variants: ${variants},
})`
}
case "list": {
if (value.subtype === "enum") {
case 'list': {
if (value.subtype === 'enum') {
const allValueNames = new Set([
...(value?.spec?.["values"] || []),
...Object.keys(value?.spec?.["value-names"] || {}),
...(value?.spec?.['values'] || []),
...Object.keys(value?.spec?.['value-names'] || {}),
])
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(isString)
.map((key: string) => [
key,
value?.spec?.["value-names"]?.[key] ?? key,
value?.spec?.['value-names']?.[key] ?? key,
]),
)
return `Value.multiselect(${JSON.stringify(
@@ -222,10 +222,10 @@ const {InputSpec, List, Value, Variants} = sdk
2,
)})`
}
const list = maybeNewConst(value.name + "_list", convertList(value))
const list = maybeNewConst(value.name + '_list', convertList(value))
return `Value.list(${list})`
}
case "pointer": {
case 'pointer': {
return `/* TODO deal with point removed point "${value.name}" */null as any`
}
}
@@ -234,7 +234,7 @@ const {InputSpec, List, Value, Variants} = sdk
function convertList(value: any) {
switch (value.subtype) {
case "string": {
case 'string': {
return `${rangeToTodoComment(value?.range)}List.text(${JSON.stringify(
{
name: value.name || null,
@@ -253,7 +253,7 @@ const {InputSpec, List, Value, Variants} = sdk
? [
{
regex: value.spec.pattern,
description: value?.spec?.["pattern-description"],
description: value?.spec?.['pattern-description'],
},
]
: [],
@@ -281,12 +281,12 @@ const {InputSpec, List, Value, Variants} = sdk
// placeholder: value?.spec?.placeholder || null,
// })})`
// }
case "enum": {
return "/* error!! list.enum */"
case 'enum': {
return '/* error!! list.enum */'
}
case "object": {
case 'object': {
const specName = maybeNewConst(
value.name + "_spec",
value.name + '_spec',
convertInputSpec(value.spec.spec),
)
return `${rangeToTodoComment(value?.range)}List.obj({
@@ -297,20 +297,20 @@ const {InputSpec, List, Value, Variants} = sdk
description: ${JSON.stringify(value.description || null)},
}, {
spec: ${specName},
displayAs: ${JSON.stringify(value?.spec?.["display-as"] || null)},
uniqueBy: ${JSON.stringify(value?.spec?.["unique-by"] || null)},
displayAs: ${JSON.stringify(value?.spec?.['display-as'] || null)},
uniqueBy: ${JSON.stringify(value?.spec?.['unique-by'] || null)},
})`
}
case "union": {
case 'union': {
const variants = maybeNewConst(
value.name + "_variants",
value.name + '_variants',
convertVariants(
value.spec.variants,
value.spec["variant-names"] || {},
value.spec['variant-names'] || {},
),
)
const unionValueName = maybeNewConst(
value.name + "_union",
value.name + '_union',
`${rangeToTodoComment(value?.range)}
Value.union({
name: ${JSON.stringify(value?.spec?.tag?.name || null)},
@@ -324,7 +324,7 @@ const {InputSpec, List, Value, Variants} = sdk
`,
)
const listInputSpec = maybeNewConst(
value.name + "_list_inputSpec",
value.name + '_list_inputSpec',
`
InputSpec.of({
"union": ${unionValueName}
@@ -340,8 +340,8 @@ const {InputSpec, List, Value, Variants} = sdk
warning: ${JSON.stringify(value.warning || null)},
}, {
spec: ${listInputSpec},
displayAs: ${JSON.stringify(value?.spec?.["display-as"] || null)},
uniqueBy: ${JSON.stringify(value?.spec?.["unique-by"] || null)},
displayAs: ${JSON.stringify(value?.spec?.['display-as'] || null)},
uniqueBy: ${JSON.stringify(value?.spec?.['unique-by'] || null)},
})`
}
}
@@ -352,7 +352,7 @@ const {InputSpec, List, Value, Variants} = sdk
variants: Record<string, unknown>,
variantNames: Record<string, string>,
): string {
let answer = "Variants.of({"
let answer = 'Variants.of({'
for (const [key, value] of Object.entries(variants)) {
const variantSpec = maybeNewConst(key, convertInputSpec(value))
answer += `"${key}": {name: "${
@@ -373,7 +373,7 @@ const {InputSpec, List, Value, Variants} = sdk
}
function rangeToTodoComment(range: string | undefined) {
if (!range) return ""
if (!range) return ''
return `/* TODO: Convert range for this value (${range})*/`
}