added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions

View File

@@ -10,7 +10,7 @@ import {
mark,
objectEach,
stripMark,
transformObject
transformObject,
} from "core/utils";
import {
type Connection,
@@ -20,7 +20,7 @@ import {
entity,
enumm,
jsonSchema,
number
number,
} from "data";
import { TransformPersistFailedException } from "data/errors";
import { Hono } from "hono";
@@ -42,7 +42,7 @@ export const MODULES = {
data: AppData,
auth: AppAuth,
media: AppMedia,
flows: AppFlows
flows: AppFlows,
} as const;
// get names of MODULES as an array
@@ -71,7 +71,7 @@ export type InitialModuleConfigs =
enum Verbosity {
silent = 0,
error = 1,
log = 2
log = 2,
}
export type ModuleManagerOptions = {
@@ -79,7 +79,7 @@ export type ModuleManagerOptions = {
eventManager?: EventManager<any>;
onUpdated?: <Module extends keyof Modules>(
module: Module,
config: ModuleConfigs[Module]
config: ModuleConfigs[Module],
) => Promise<void>;
// triggered when no config table existed
onFirstBoot?: () => Promise<void>;
@@ -111,16 +111,16 @@ const configJsonSchema = Type.Union([
t: StringEnum(["a", "r", "e"]),
p: Type.Array(Type.Union([Type.String(), Type.Number()])),
o: Type.Optional(Type.Any()),
n: Type.Optional(Type.Any())
})
)
n: Type.Optional(Type.Any()),
}),
),
]);
const __bknd = entity(TABLE_NAME, {
version: number().required(),
type: enumm({ enum: ["config", "diff", "backup"] }).required(),
json: jsonSchema({ schema: configJsonSchema }).required(),
created_at: datetime(),
updated_at: datetime()
updated_at: datetime(),
});
type ConfigTable2 = Schema<typeof __bknd>;
interface T_INTERNAL_EM {
@@ -147,7 +147,7 @@ export class ModuleManager {
constructor(
private readonly connection: Connection,
private options?: Partial<ModuleManagerOptions>
private options?: Partial<ModuleManagerOptions>,
) {
this.__em = new EntityManager([__bknd], this.connection);
this.modules = {} as Modules;
@@ -249,7 +249,7 @@ export class ModuleManager {
emgr: this.emgr,
guard: this.guard,
flags: Module.ctx_flags,
logger: this.logger
logger: this.logger,
};
}
@@ -263,8 +263,8 @@ export class ModuleManager {
const { data: result } = await this.repo().findOne(
{ type: "config" },
{
sort: { by: "version", dir: "desc" }
}
sort: { by: "version", dir: "desc" },
},
);
if (!result) {
@@ -273,13 +273,13 @@ export class ModuleManager {
return result as unknown as ConfigTable;
},
this.verbosity > Verbosity.silent ? [] : ["log", "error", "warn"]
this.verbosity > Verbosity.silent ? [] : ["log", "error", "warn"],
);
this.logger
.log("took", performance.now() - startTime, "ms", {
version: result.version,
id: result.id
id: result.id,
})
.clear();
return result;
@@ -300,12 +300,12 @@ export class ModuleManager {
await this.mutator().insertOne({
version: state.version,
type: "backup",
json: configs
json: configs,
});
await this.mutator().insertOne({
version: version,
type: "config",
json: configs
json: configs,
});
} else {
this.logger.log("version matches");
@@ -319,7 +319,7 @@ export class ModuleManager {
await this.mutator().insertOne({
version,
type: "diff",
json: clone(diffs)
json: clone(diffs),
});
// store new version
@@ -327,12 +327,12 @@ export class ModuleManager {
{
version,
json: configs,
updated_at: new Date()
updated_at: new Date(),
} as any,
{
type: "config",
version
}
version,
},
);
} else {
this.logger.log("no diff, not saving");
@@ -347,7 +347,7 @@ export class ModuleManager {
version,
json: configs,
created_at: new Date(),
updated_at: new Date()
updated_at: new Date(),
});
} else if (e instanceof TransformPersistFailedException) {
console.error("Cannot save invalid config");
@@ -383,7 +383,7 @@ export class ModuleManager {
if (state.version !== this.version()) {
// @todo: potentially drop provided config and use database version
throw new Error(
`Given version (${this.version()}) and fetched version (${state.version}) do not match.`
`Given version (${this.version()}) and fetched version (${state.version}) do not match.`,
);
}
} catch (e: any) {
@@ -400,7 +400,7 @@ export class ModuleManager {
}
const [_version, _configs] = await migrate(version, configs, {
db: this.db
db: this.db,
});
version = _version;
configs = _configs;
@@ -427,7 +427,7 @@ export class ModuleManager {
} catch (e) {
console.error(e);
throw new Error(
`Failed to set config for module ${key}: ${JSON.stringify(config, null, 2)}`
`Failed to set config for module ${key}: ${JSON.stringify(config, null, 2)}`,
);
}
});
@@ -493,7 +493,7 @@ export class ModuleManager {
modules: [] as ModuleKey[],
synced: false,
saved: false,
reloaded: false
reloaded: false,
};
this.logger.log("buildModules() triggered", options, this._built);
@@ -545,7 +545,7 @@ export class ModuleManager {
const ctx = {
...this.ctx(),
// disable events for initial setup
em: this.ctx().em.fork()
em: this.ctx().em.fork(),
};
// perform a sync
@@ -557,7 +557,7 @@ export class ModuleManager {
}
mutateConfigSafe<Module extends keyof Modules>(
name: Module
name: Module,
): Pick<ReturnType<Modules[Module]["schema"]>, "set" | "patch" | "overwrite" | "remove"> {
const module = this.modules[name];
const copy = structuredClone(this.configs());
@@ -602,7 +602,7 @@ export class ModuleManager {
throw e;
}
};
}
},
});
}
@@ -630,7 +630,7 @@ export class ModuleManager {
return {
version: this.version(),
...schemas
...schemas,
};
}
@@ -646,7 +646,7 @@ export class ModuleManager {
return {
version: this.version(),
...modules
...modules,
} as any;
}
}
@@ -654,7 +654,7 @@ export class ModuleManager {
export function getDefaultSchema() {
const schema = {
type: "object",
...transformObject(MODULES, (module) => module.prototype.getSchema())
...transformObject(MODULES, (module) => module.prototype.getSchema()),
};
return schema as any;