mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
misc sdk changes (#2934)
* misc sdk changes * delete the store ☠️ * port comments * fix build * fix removing * fix tests * beta.20 --------- Co-authored-by: Matt Hill <mattnine@protonmail.com>
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import { Affine } from "../util"
|
||||
|
||||
const pathValue = Symbol("pathValue")
|
||||
export type PathValue = typeof pathValue
|
||||
|
||||
export type PathBuilderStored<AllStore, Store> = {
|
||||
[K in PathValue]: [AllStore, Store]
|
||||
}
|
||||
|
||||
export type PathBuilder<AllStore, Store = AllStore> = (Store extends Record<
|
||||
string,
|
||||
unknown
|
||||
>
|
||||
? {
|
||||
[K in keyof Store]: PathBuilder<AllStore, Store[K]>
|
||||
}
|
||||
: {}) &
|
||||
PathBuilderStored<AllStore, Store>
|
||||
|
||||
export type StorePath = string & Affine<"StorePath">
|
||||
const privateSymbol = Symbol("jsonPath")
|
||||
export const extractJsonPath = (builder: PathBuilder<unknown>) => {
|
||||
return (builder as any)[privateSymbol] as StorePath
|
||||
}
|
||||
|
||||
export const pathBuilder = <Store, StorePath = Store>(
|
||||
paths: string[] = [],
|
||||
): PathBuilder<Store, StorePath> => {
|
||||
return new Proxy({} as PathBuilder<Store, StorePath>, {
|
||||
get(target, prop) {
|
||||
if (prop === privateSymbol) {
|
||||
if (paths.length === 0) return ""
|
||||
return `/${paths.join("/")}`
|
||||
}
|
||||
return pathBuilder<any>([...paths, prop as string])
|
||||
},
|
||||
}) as PathBuilder<Store, StorePath>
|
||||
}
|
||||
@@ -17,6 +17,5 @@ export { nullIfEmpty } from "./nullIfEmpty"
|
||||
export { deepMerge, partialDiff } from "./deepMerge"
|
||||
export { deepEqual } from "./deepEqual"
|
||||
export { hostnameInfoToAddress } from "./Hostname"
|
||||
export { PathBuilder, extractJsonPath, StorePath } from "./PathBuilder"
|
||||
export * as regexes from "./regexes"
|
||||
export { stringFromStdErrOut } from "./stringFromStdErrOut"
|
||||
|
||||
Reference in New Issue
Block a user