init
This commit is contained in:
commit
5ac1c9bf71
57
index.js
Normal file
57
index.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/** @import * as TYPES from "./types" */
|
||||||
|
|
||||||
|
|
||||||
|
/** @type {TYPES.DeskBuilder} */
|
||||||
|
function Desk(parts, ...desks)
|
||||||
|
{
|
||||||
|
for(let id in parts)
|
||||||
|
{
|
||||||
|
const name = parts[id];
|
||||||
|
parts[id] = {name, work:[], time:0, need:[], make:[]}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i=0; i<desks.length; i++)
|
||||||
|
{
|
||||||
|
const [name, mode, needObj, ...makePartIDs] = desks[i];
|
||||||
|
const need =[];
|
||||||
|
const time =[];
|
||||||
|
|
||||||
|
const desk = {
|
||||||
|
name,
|
||||||
|
mode,
|
||||||
|
need,
|
||||||
|
time
|
||||||
|
};
|
||||||
|
|
||||||
|
for(const partId in needObj)
|
||||||
|
{
|
||||||
|
const part = parts[partId];
|
||||||
|
need.push(part);
|
||||||
|
part.need.push(desk);
|
||||||
|
time.push(needObj[partId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
desk.make = makePartIDs.map( p=>
|
||||||
|
{
|
||||||
|
const part = parts[p]
|
||||||
|
part.make.push(desk);
|
||||||
|
return part;
|
||||||
|
} )
|
||||||
|
|
||||||
|
desks[i] = desk;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(parts, desks);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Desk
|
||||||
|
(
|
||||||
|
{
|
||||||
|
p1:"hey",
|
||||||
|
p2:"sup"
|
||||||
|
},
|
||||||
|
["Desk 2", "all", {p1:1, p2:6}, "p2"],
|
||||||
|
["Desk 1", "all", {p1:1, p2:6}, "p2"]
|
||||||
|
)
|
||||||
5
tsconfig.json
Normal file
5
tsconfig.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"checkJs": true
|
||||||
|
},
|
||||||
|
}
|
||||||
26
types.ts
Normal file
26
types.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
type PartBlueprint = string
|
||||||
|
|
||||||
|
export type DeskBuilder=
|
||||||
|
<
|
||||||
|
Parts extends Record<string, PartBlueprint>,
|
||||||
|
IDs extends keyof Parts,
|
||||||
|
Desks extends [ name:string, mode:"all"|"one", Record<IDs, number>, ...make:Array<IDs>][]
|
||||||
|
>
|
||||||
|
(
|
||||||
|
parts:Parts,
|
||||||
|
...desks:Desks
|
||||||
|
)
|
||||||
|
=>void
|
||||||
|
|
||||||
|
type UserBlueprint = string
|
||||||
|
export type UserBuilder=
|
||||||
|
<
|
||||||
|
Users extends Record<string, UserBlueprint>,
|
||||||
|
IDs extends keyof Users,
|
||||||
|
Roles extends Record<string, [ name:string, ...users:Array<IDs>]>
|
||||||
|
>
|
||||||
|
(
|
||||||
|
users:Users,
|
||||||
|
roles:Roles
|
||||||
|
)
|
||||||
|
=>void
|
||||||
Loading…
Reference in New Issue
Block a user