mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
Fix/making js work (#1456)
* Feat: js action wip: Getting async js feat: Have execute get action config feat: Read + Write chore: Add typing for globals chore: Change the default path, include error on missing function, and add json File Read Write chore: Change the default path, include error on missing function, and add json File Read Write wip: Fix the unit test wip: Fix the unit test feat: module loading * fix: Change the source + add input * fix: Change the source + add input wip: Fix missing js files during running fix: Change the source + add input wip: Fix missing js files during running * fix: other paths * feat: Build the arm js snapshot * fix: test with more * chore: Make the is_subset a result
This commit is contained in:
@@ -10,19 +10,53 @@ export function properties() {
|
||||
* @returns {Promise<import('./types').ConfigRes>}
|
||||
*/
|
||||
export async function getConfig(effects) {
|
||||
try{
|
||||
await effects.writeFile({
|
||||
path: "./test.log",
|
||||
path: "../test.log",
|
||||
toWrite: "This is a test",
|
||||
volumeId: 'main',
|
||||
});
|
||||
throw new Error("Expecting that the ../test.log should not be a valid path since we are breaking out of the parent")
|
||||
} catch(e) {}
|
||||
try{
|
||||
await effects.writeFile({
|
||||
path: "./hack_back/broken.log",
|
||||
toWrite: "This is a test",
|
||||
volumeId: 'main',
|
||||
});
|
||||
throw new Error("Expecting that using a symlink to break out of parent still fails for writing")
|
||||
} catch(e) {}
|
||||
try{
|
||||
await effects.createDir({
|
||||
path: "./hack_back/broken_dir",
|
||||
volumeId: 'main',
|
||||
});
|
||||
throw new Error("Expecting that using a symlink to break out of parent still fails for writing dir")
|
||||
} catch(e) {}
|
||||
try{
|
||||
await effects.readFile({
|
||||
path: "./hack_back/data/bad_file.txt",
|
||||
volumeId: 'main',
|
||||
});
|
||||
throw new Error("Expecting that using a symlink to break out of parent still fails for reading")
|
||||
} catch(e) {}
|
||||
|
||||
// Testing dir, create + delete
|
||||
await effects.createDir({
|
||||
path: "./testing",
|
||||
volumeId: 'main',});
|
||||
await effects.writeFile({
|
||||
await effects.writeJsonFile({
|
||||
path: "./testing/test2.log",
|
||||
toWrite: "This is a test",
|
||||
toWrite: {value: "This is a test"},
|
||||
volumeId: 'main',
|
||||
});
|
||||
|
||||
(await effects.readJsonFile({
|
||||
path: "./testing/test2.log",
|
||||
volumeId: 'main',
|
||||
// @ts-ignore
|
||||
})).value;
|
||||
|
||||
await effects.removeFile({
|
||||
path: "./testing/test2.log",
|
||||
volumeId: 'main',
|
||||
@@ -30,10 +64,20 @@ export async function getConfig(effects) {
|
||||
await effects.removeDir({
|
||||
path: "./testing",
|
||||
volumeId: 'main',});
|
||||
|
||||
|
||||
// Testing reading + writing
|
||||
await effects.writeFile({
|
||||
path: "./test.log",
|
||||
toWrite: "This is a test",
|
||||
volumeId: 'main',
|
||||
});
|
||||
|
||||
effects.debug(`Read results are ${await effects.readFile({
|
||||
path: "./test.log",
|
||||
volumeId: 'main',
|
||||
})}`)
|
||||
// Testing loging
|
||||
effects.trace('trace')
|
||||
effects.debug('debug')
|
||||
effects.warn('warn')
|
||||
@@ -587,6 +631,7 @@ export async function getConfig(effects) {
|
||||
export async function setConfig(effects, input) {
|
||||
|
||||
return {
|
||||
signal: "SIGTERM",
|
||||
"depends-on": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,191 +1,266 @@
|
||||
export type Effects = {
|
||||
writeFile(input: {path: string, volumeId: string, toWrite: string}): Promise<void>,
|
||||
readFile(input: {volumeId: string,path: string}): Promise<string>,
|
||||
createDir(input: {volumeId: string,path: string}): Promise<string>,
|
||||
removeDir(input: {volumeId: string,path: string}): Promise<string>,
|
||||
removeFile(input: {volumeId: string,path: string}): Promise<void>,
|
||||
writeJsonFile(input: {volumeId: string,path: string, toWrite: object}): void,
|
||||
readJsonFile(input:{volumeId: string,path: string}): object,
|
||||
trace(whatToPrin: string),
|
||||
warn(whatToPrin: string),
|
||||
error(whatToPrin: string),
|
||||
debug(whatToPrin: string),
|
||||
info(whatToPrin: string),
|
||||
is_sandboxed(): boolean,
|
||||
}
|
||||
writeFile(input: { path: string; volumeId: string; toWrite: string }): Promise<void>;
|
||||
readFile(input: { volumeId: string; path: string }): Promise<string>;
|
||||
createDir(input: { volumeId: string; path: string }): Promise<string>;
|
||||
removeDir(input: { volumeId: string; path: string }): Promise<string>;
|
||||
removeFile(input: { volumeId: string; path: string }): Promise<void>;
|
||||
writeJsonFile(input: { volumeId: string; path: string; toWrite: object }): Promise<void>;
|
||||
readJsonFile(input: { volumeId: string; path: string }): Promise<object>;
|
||||
trace(whatToPrin: string): void;
|
||||
warn(whatToPrin: string): void;
|
||||
error(whatToPrin: string): void;
|
||||
debug(whatToPrin: string): void;
|
||||
info(whatToPrin: string): void;
|
||||
is_sandboxed(): boolean;
|
||||
};
|
||||
|
||||
export type ActionResult = {
|
||||
version: "0",
|
||||
message: string,
|
||||
value?: string,
|
||||
copyable: boolean,
|
||||
qr: boolean,
|
||||
}
|
||||
version: "0";
|
||||
message: string;
|
||||
value?: string;
|
||||
copyable: boolean;
|
||||
qr: boolean;
|
||||
};
|
||||
|
||||
export type ConfigRes = {
|
||||
config?: Config,
|
||||
spec: ConfigSpec,
|
||||
}
|
||||
config?: Config;
|
||||
spec: ConfigSpec;
|
||||
};
|
||||
export type Config = {
|
||||
[value: string]: any
|
||||
}
|
||||
[value: string]: any;
|
||||
};
|
||||
|
||||
export type ConfigSpec = {
|
||||
[value: string]: ValueSpecAny
|
||||
}
|
||||
export type WithDefault<T, Default> = T & {
|
||||
default?: Default
|
||||
}
|
||||
export type ConfigSpec = {
|
||||
[value: string]: ValueSpecAny;
|
||||
};
|
||||
export type WithDefault<T, Default> = T & {
|
||||
default?: Default;
|
||||
};
|
||||
|
||||
export type WithDescription<T> = T & {
|
||||
description?: String,
|
||||
name: string,
|
||||
warning?: string,
|
||||
}
|
||||
description?: String;
|
||||
name: string;
|
||||
warning?: string;
|
||||
};
|
||||
|
||||
export type ListSpec<T> = {
|
||||
spec: T,
|
||||
range: string
|
||||
}
|
||||
spec: T;
|
||||
range: string;
|
||||
};
|
||||
|
||||
export type Tag<T extends string, V> = V & {
|
||||
type: T
|
||||
}
|
||||
type: T;
|
||||
};
|
||||
|
||||
export type Subtype<T extends string, V> = V & {
|
||||
subtype: T
|
||||
}
|
||||
subtype: T;
|
||||
};
|
||||
|
||||
export type Target<T extends string, V> = V & {
|
||||
"target": T
|
||||
}
|
||||
target: T;
|
||||
};
|
||||
|
||||
export type UniqueBy =
|
||||
|{
|
||||
any: UniqueBy[],
|
||||
}
|
||||
| {
|
||||
all: UniqueBy[]
|
||||
}
|
||||
| string
|
||||
| null
|
||||
| {
|
||||
any: UniqueBy[];
|
||||
}
|
||||
| {
|
||||
all: UniqueBy[];
|
||||
}
|
||||
| string
|
||||
| null;
|
||||
|
||||
export type WithNullable<T> = T & {
|
||||
nullable: boolean
|
||||
}
|
||||
export type DefaultString = String | {
|
||||
charset?: string,
|
||||
len: number
|
||||
}
|
||||
nullable: boolean;
|
||||
};
|
||||
export type DefaultString =
|
||||
| String
|
||||
| {
|
||||
charset?: string;
|
||||
len: number;
|
||||
};
|
||||
|
||||
export type ValueSpecString= ({} | {
|
||||
pattern: string,
|
||||
'pattern-description': string
|
||||
}) & {
|
||||
copyable?: boolean,
|
||||
masked?: boolean,
|
||||
placeholder?: string
|
||||
|
||||
}
|
||||
export type ValueSpecString = (
|
||||
| {}
|
||||
| {
|
||||
pattern: string;
|
||||
"pattern-description": string;
|
||||
}
|
||||
) & {
|
||||
copyable?: boolean;
|
||||
masked?: boolean;
|
||||
placeholder?: string;
|
||||
};
|
||||
export type ValueSpecNumber = {
|
||||
range?: string,
|
||||
integral?: boolean,
|
||||
units?: string,
|
||||
placeholder?: number,
|
||||
}
|
||||
export type ValueSpecBoolean = {}
|
||||
export type ValueSpecAny =
|
||||
| Tag<'boolean', WithDescription<WithDefault<ValueSpecBoolean, boolean>>>
|
||||
| Tag<'string', WithDescription<WithDefault<WithNullable<ValueSpecString>, DefaultString>>>
|
||||
| Tag<'number', WithDescription<WithDefault<WithNullable<ValueSpecNumber>, number>>>
|
||||
| Tag<'enum', WithDescription<WithDefault<{
|
||||
values: string[],
|
||||
"value-names": {
|
||||
[key: string]: string
|
||||
}
|
||||
}, string>>>
|
||||
| Tag<'list', ValueSpecList>
|
||||
| Tag<'object', WithDescription<WithDefault<ValueSpecObject, Config>>>
|
||||
| Tag<'union', WithDescription<WithDefault<ValueSpecUnion, string>>>
|
||||
| Tag<'pointer', WithDescription<
|
||||
| Subtype<'package',
|
||||
| Target<'tor-key', {
|
||||
'package-id': string
|
||||
interface: string
|
||||
}>
|
||||
| Target<'tor-address', {
|
||||
'package-id': string,
|
||||
interface: string
|
||||
} >
|
||||
| Target<'lan-address',{
|
||||
'package-id': string,
|
||||
interface: string
|
||||
} >
|
||||
| Target<'config', {
|
||||
'package-id': string,
|
||||
selector: string,
|
||||
multi: boolean
|
||||
}>
|
||||
range?: string;
|
||||
integral?: boolean;
|
||||
units?: string;
|
||||
placeholder?: number;
|
||||
};
|
||||
export type ValueSpecBoolean = {};
|
||||
export type ValueSpecAny =
|
||||
| Tag<"boolean", WithDescription<WithDefault<ValueSpecBoolean, boolean>>>
|
||||
| Tag<"string", WithDescription<WithDefault<WithNullable<ValueSpecString>, DefaultString>>>
|
||||
| Tag<"number", WithDescription<WithDefault<WithNullable<ValueSpecNumber>, number>>>
|
||||
| Tag<
|
||||
"enum",
|
||||
WithDescription<
|
||||
WithDefault<
|
||||
{
|
||||
values: string[];
|
||||
"value-names": {
|
||||
[key: string]: string;
|
||||
};
|
||||
},
|
||||
string
|
||||
>
|
||||
>
|
||||
>
|
||||
| Subtype<'system', {}>
|
||||
>>
|
||||
| Tag<"list", ValueSpecList>
|
||||
| Tag<"object", WithDescription<WithDefault<ValueSpecObject, Config>>>
|
||||
| Tag<"union", WithDescription<WithDefault<ValueSpecUnion, string>>>
|
||||
| Tag<
|
||||
"pointer",
|
||||
WithDescription<
|
||||
| Subtype<
|
||||
"package",
|
||||
| Target<
|
||||
"tor-key",
|
||||
{
|
||||
"package-id": string;
|
||||
interface: string;
|
||||
}
|
||||
>
|
||||
| Target<
|
||||
"tor-address",
|
||||
{
|
||||
"package-id": string;
|
||||
interface: string;
|
||||
}
|
||||
>
|
||||
| Target<
|
||||
"lan-address",
|
||||
{
|
||||
"package-id": string;
|
||||
interface: string;
|
||||
}
|
||||
>
|
||||
| Target<
|
||||
"config",
|
||||
{
|
||||
"package-id": string;
|
||||
selector: string;
|
||||
multi: boolean;
|
||||
}
|
||||
>
|
||||
>
|
||||
| Subtype<"system", {}>
|
||||
>
|
||||
>;
|
||||
export type ValueSpecUnion = {
|
||||
tag: {
|
||||
id: string,
|
||||
name: string,
|
||||
description?: string,
|
||||
"variant-names": {
|
||||
[key: string]: string,
|
||||
}
|
||||
},
|
||||
variants: {
|
||||
[key: string]: ConfigSpec
|
||||
},
|
||||
"display-as"?: string,
|
||||
"unique-by"?: UniqueBy
|
||||
|
||||
}
|
||||
tag: {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
"variant-names": {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
variants: {
|
||||
[key: string]: ConfigSpec;
|
||||
};
|
||||
"display-as"?: string;
|
||||
"unique-by"?: UniqueBy;
|
||||
};
|
||||
export type ValueSpecObject = {
|
||||
spec : ConfigSpec,
|
||||
'display-as'?: string,
|
||||
"unique-by"?: UniqueBy
|
||||
|
||||
}
|
||||
export type ValueSpecList =
|
||||
| Subtype<'boolean', WithDescription<WithDefault<ListSpec<ValueSpecBoolean>, boolean>>>
|
||||
| Subtype<'string', WithDescription<WithDefault<ListSpec<ValueSpecString>, string>>>
|
||||
| Subtype<'number', WithDescription<WithDefault<ListSpec<ValueSpecNumber>, number>>>
|
||||
| Subtype<'enum', WithDescription<WithDefault<{
|
||||
values: string[],
|
||||
"value-names": {
|
||||
[key: string]: string
|
||||
}
|
||||
}, string>>>
|
||||
spec: ConfigSpec;
|
||||
"display-as"?: string;
|
||||
"unique-by"?: UniqueBy;
|
||||
};
|
||||
export type ValueSpecList =
|
||||
| Subtype<"boolean", WithDescription<WithDefault<ListSpec<ValueSpecBoolean>, boolean>>>
|
||||
| Subtype<"string", WithDescription<WithDefault<ListSpec<ValueSpecString>, string>>>
|
||||
| Subtype<"number", WithDescription<WithDefault<ListSpec<ValueSpecNumber>, number>>>
|
||||
| Subtype<
|
||||
"enum",
|
||||
WithDescription<
|
||||
WithDefault<
|
||||
{
|
||||
values: string[];
|
||||
"value-names": {
|
||||
[key: string]: string;
|
||||
};
|
||||
},
|
||||
string
|
||||
>
|
||||
>
|
||||
>;
|
||||
|
||||
export type SetResult = {
|
||||
signal?: string,
|
||||
'depends-on': {
|
||||
[packageId: string]: string[]
|
||||
}
|
||||
}
|
||||
signal:
|
||||
| "SIGTERM"
|
||||
| "SIGHUP"
|
||||
| "SIGINT"
|
||||
| "SIGQUIT"
|
||||
| "SIGILL"
|
||||
| "SIGTRAP"
|
||||
| "SIGABRT"
|
||||
| "SIGBUS"
|
||||
| "SIGFPE"
|
||||
| "SIGKILL"
|
||||
| "SIGUSR1"
|
||||
| "SIGSEGV"
|
||||
| "SIGUSR2"
|
||||
| "SIGPIPE"
|
||||
| "SIGALRM"
|
||||
| "SIGSTKFLT"
|
||||
| "SIGCHLD"
|
||||
| "SIGCONT"
|
||||
| "SIGSTOP"
|
||||
| "SIGTSTP"
|
||||
| "SIGTTIN"
|
||||
| "SIGTTOU"
|
||||
| "SIGURG"
|
||||
| "SIGXCPU"
|
||||
| "SIGXFSZ"
|
||||
| "SIGVTALRM"
|
||||
| "SIGPROF"
|
||||
| "SIGWINCH"
|
||||
| "SIGIO"
|
||||
| "SIGPWR"
|
||||
| "SIGSYS"
|
||||
| "SIGEMT"
|
||||
| "SIGINFO";
|
||||
"depends-on": {
|
||||
[packageId: string]: string[];
|
||||
};
|
||||
};
|
||||
export type PackagePropertiesV2 = {
|
||||
[name: string]: PackagePropertyObject | PackagePropertyString
|
||||
}
|
||||
[name: string]: PackagePropertyObject | PackagePropertyString;
|
||||
};
|
||||
export type PackagePropertyString = {
|
||||
type: 'string',
|
||||
description?: string,
|
||||
value: string,
|
||||
copyable?: boolean,
|
||||
qr?: boolean,
|
||||
masked?: boolean,
|
||||
}
|
||||
type: "string";
|
||||
description?: string;
|
||||
value: string;
|
||||
copyable?: boolean;
|
||||
qr?: boolean;
|
||||
masked?: boolean;
|
||||
};
|
||||
export type PackagePropertyObject = {
|
||||
value: PackagePropertiesV2;
|
||||
type: "object";
|
||||
description: string;
|
||||
}
|
||||
value: PackagePropertiesV2;
|
||||
type: "object";
|
||||
description: string;
|
||||
};
|
||||
|
||||
export type Properties = {
|
||||
version: 2,
|
||||
data: PackagePropertiesV2
|
||||
}
|
||||
version: 2;
|
||||
data: PackagePropertiesV2;
|
||||
};
|
||||
|
||||
|
||||
export type Dependencies = {
|
||||
[id: string]: {
|
||||
check(effects: Effects, input: Config): Promise<void | null>,
|
||||
autoConfigure(effects: Effects, input: Config): Promise<Config>,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Out of volumes
|
||||
@@ -0,0 +1 @@
|
||||
../../
|
||||
Reference in New Issue
Block a user