mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
add map & eq to getServiceInterface
This commit is contained in:
@@ -60,6 +60,11 @@ import {
|
||||
setupOnUninit,
|
||||
} from "../../base/lib/inits"
|
||||
import { DropGenerator } from "../../base/lib/util/Drop"
|
||||
import {
|
||||
getOwnServiceInterface,
|
||||
ServiceInterfaceFilled,
|
||||
} from "../../base/lib/util/getServiceInterface"
|
||||
import { getOwnServiceInterfaces } from "../../base/lib/util/getServiceInterfaces"
|
||||
|
||||
export const OSVersion = testTypeVersion("0.4.0-alpha.16")
|
||||
|
||||
@@ -170,20 +175,10 @@ export class StartSdk<Manifest extends T.SDKManifest> {
|
||||
packageIds?: DependencyId[],
|
||||
) => Promise<CheckDependencies<DependencyId>>,
|
||||
serviceInterface: {
|
||||
getOwn: <E extends Effects>(effects: E, id: ServiceInterfaceId) =>
|
||||
getServiceInterface(effects, {
|
||||
id,
|
||||
}),
|
||||
get: <E extends Effects>(
|
||||
effects: E,
|
||||
opts: { id: ServiceInterfaceId; packageId: PackageId },
|
||||
) => getServiceInterface(effects, opts),
|
||||
getAllOwn: <E extends Effects>(effects: E) =>
|
||||
getServiceInterfaces(effects, {}),
|
||||
getAll: <E extends Effects>(
|
||||
effects: E,
|
||||
opts: { packageId: PackageId },
|
||||
) => getServiceInterfaces(effects, opts),
|
||||
getOwn: getOwnServiceInterface,
|
||||
get: getServiceInterface,
|
||||
getAllOwn: getOwnServiceInterfaces,
|
||||
getAll: getServiceInterfaces,
|
||||
},
|
||||
getContainerIp: (
|
||||
effects: T.Effects,
|
||||
|
||||
@@ -4,38 +4,11 @@ import * as TOML from "@iarna/toml"
|
||||
import * as INI from "ini"
|
||||
import * as T from "../../../base/lib/types"
|
||||
import * as fs from "node:fs/promises"
|
||||
import { asError } from "../../../base/lib/util"
|
||||
import { asError, deepEqual } from "../../../base/lib/util"
|
||||
import { DropGenerator, DropPromise } from "../../../base/lib/util/Drop"
|
||||
|
||||
const previousPath = /(.+?)\/([^/]*)$/
|
||||
|
||||
const deepEq = (left: unknown, right: unknown) => {
|
||||
if (left === right) return true
|
||||
if (Array.isArray(left) && Array.isArray(right)) {
|
||||
if (left.length === right.length) {
|
||||
for (const idx in left) {
|
||||
if (!deepEq(left[idx], right[idx])) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
} else if (
|
||||
typeof left === "object" &&
|
||||
typeof right === "object" &&
|
||||
left &&
|
||||
right
|
||||
) {
|
||||
const keys = new Set<keyof typeof left | keyof typeof right>([
|
||||
...(Object.keys(left) as (keyof typeof left)[]),
|
||||
...(Object.keys(right) as (keyof typeof right)[]),
|
||||
])
|
||||
for (let key of keys) {
|
||||
if (!deepEq(left[key], right[key])) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const exists = (path: string) =>
|
||||
fs.access(path).then(
|
||||
() => true,
|
||||
@@ -374,7 +347,7 @@ export class FileHelper<A> {
|
||||
eq?: (left: any, right: any) => boolean,
|
||||
): ReadType<any> {
|
||||
map = map ?? ((a: A) => a)
|
||||
eq = eq ?? deepEq
|
||||
eq = eq ?? deepEqual
|
||||
return {
|
||||
once: () => this.readOnce(map),
|
||||
const: (effects: T.Effects) => this.readConst(effects, map, eq),
|
||||
|
||||
Reference in New Issue
Block a user