CloudTwin  ROS2 Humble
Digital twin for path and trajectory optimisation
Variables
index.ts File Reference

Variables

const addNestedParams
 
export const addUrlDefault
 
export const applyUrlDefaults
 
const clearParamFamily
 
const getValue
 
type Method = "get" | "post" | "put" | "delete" | "patch" | "head" | "options"
 
export type QueryParams
 
export const queryParams
 
export type RouteDefinition< TMethod extends Method|Method[]>
 
export type RouteFormDefinition< TMethod extends Method >
 
export type RouteQueryOptions
 
export const setUrlDefaults
 
type UrlDefaults = Record<string, unknown>
 
let urlDefaults
 
export const validateParameters
 

Variable Documentation

◆ addNestedParams

const addNestedParams
Initial value:
= (
prefix: string,
params: URLSearchParams,
) => {
Object.entries(obj).forEach(([subKey, value]) => {
if (value === undefined) return;
const paramKey = `${prefix}[${subKey}]`;
if (Array.isArray(value)) {
value.forEach((v) => params.append(`${paramKey}[]`, getValue(v)));
} else if (value !== null && typeof value === "object") {
addNestedParams(value, paramKey, params);
} else if (["string", "number", "boolean"].includes(typeof value)) {
params.set(paramKey, getValue(value as string | number | boolean));
}
});
}
const getValue
Definition: index.ts:31
const addNestedParams
Definition: index.ts:43
export type QueryParams
Definition: index.ts:1

◆ addUrlDefault

export const addUrlDefault
Initial value:
= (
key: string,
value: string | number | boolean,
) => {
const previousDefaults = urlDefaults;
urlDefaults = () => ({
...previousDefaults(),
[key]: value,
});
}
let urlDefaults
Definition: index.ts:15

◆ applyUrlDefaults

export const applyUrlDefaults
Initial value:
= <T extends UrlDefaults | undefined>(
existing: T,
): T => {
const existingParams = { ...(existing ?? ({} as UrlDefaults)) };
const defaultParams = urlDefaults();
for (const key in defaultParams) {
if (
existingParams[key] === undefined &&
defaultParams[key] !== undefined
) {
(existingParams as Record<string, unknown>)[key] =
defaultParams[key];
}
}
return existingParams as T;
}
window as unknown as Record< string, unknown >['Pusher']
Definition: use-echo.ts:6
type UrlDefaults
Definition: index.ts:13

◆ clearParamFamily

const clearParamFamily
Initial value:
= (params: URLSearchParams, key: string) => {
const toDelete = new Set<string>();
params.forEach((_, paramKey) => {
if (paramKey === key || paramKey.startsWith(`${key}[`)) {
toDelete.add(paramKey);
}
});
toDelete.forEach((paramKey) => params.delete(paramKey));
}

◆ getValue

const getValue
Initial value:
= (value: string | number | boolean) => {
if (value === true) {
return "1";
}
if (value === false) {
return "0";
}
return value.toString();
}

◆ Method

type Method = "get" | "post" | "put" | "delete" | "patch" | "head" | "options"

◆ QueryParams

export type QueryParams
Initial value:
= {
[key: string]:
| string
| number
| boolean
| (string | number)[]
| null
| undefined
}

◆ queryParams

export const queryParams

◆ RouteDefinition< TMethod extends Method|Method[]>

export type RouteDefinition< TMethod extends Method|Method[]>
Initial value:
= {
url: string;
} & (TMethod extends Method[] ? { methods: TMethod } : { method: TMethod })
type Method
Definition: index.ts:12

◆ RouteFormDefinition< TMethod extends Method >

export type RouteFormDefinition< TMethod extends Method >
Initial value:
= {
action: string;
method: TMethod;
}

◆ RouteQueryOptions

export type RouteQueryOptions
Initial value:
= {
query?: QueryParams;
mergeQuery?: QueryParams;
}

◆ setUrlDefaults

export const setUrlDefaults
Initial value:
= (params: UrlDefaults | (() => UrlDefaults)) => {
urlDefaults = typeof params === "function" ? params : () => params;
}

◆ UrlDefaults

type UrlDefaults = Record<string, unknown>

◆ urlDefaults

let urlDefaults

◆ validateParameters

export const validateParameters
Initial value:
= (
args: Record<string, unknown> | undefined,
optional: string[],
) => {
const missing = optional.filter((key) => {
const value = args?.[key];
return (
value === undefined ||
value === null ||
value === "" ||
value === false
);
});
const expectedMissing = optional.slice(missing.length * -1);
for (let i = 0; i < missing.length; i++) {
if (missing[i] !== expectedMissing[i]) {
throw Error(
"Unexpected optional parameters missing. Unable to generate a URL.",
);
}
}
}