-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflattener.ts.notyet
48 lines (43 loc) · 1.96 KB
/
flattener.ts.notyet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//type Primitives = { string: string, number: number, boolean: boolean }
//type Flattener<currentEntity extends string, currentFields, flatResult, relations> = {
// withField: <a extends string, t extends keyof Primitives>(attribute: a, type: t) =>
// Flattener<currentEntity, currentFields & { [x in a]: Primitives[t] }, flatResult, relations>
// withMany: <r extends string, nestedResult, nestedFlatResult, relationsResult>(relation: r,
// builder: Fun<Flattener<r, {}, flatResult, relations>, Flattener<r, nestedResult, nestedFlatResult, relationsResult>>) =>
// Flattener<currentEntity, currentFields,
// nestedFlatResult & { [x in r]: nestedResult[] },
// relationsResult & { [x in currentEntity]: { [target in r]:"many" } }>
// withOne: <r extends string, nestedResult, nestedFlatResult, relationsResult>(relation: r,
// builder: Fun<Flattener<r, {}, flatResult, relations>, Flattener<r, nestedResult, nestedFlatResult, relationsResult>>) =>
// Flattener<currentEntity, currentFields,
// nestedFlatResult & { [x in r]: nestedResult[] },
// relationsResult & { [x in currentEntity]: { [target in r]: "one" } }>
// run: () => flatResult & { [x in currentEntity]: currentFields[] } & { relations: relations }
//}
///*
// * relations in type
// * multiple relations from same source in type
// * self-references
// * runtime (flattener)
// * re-hierarchify types
// * runtime (re-hierarchifier)
// */
//let f: Flattener<"person", {}, {}, {}> = null!
//const result = f
// .withField("name", "string")
// .withField("surname", "string")
// .withField("age", "number")
// .withOne("city", b => b
// .withField("name", "string")
// .withField("population", "number")
// .withOne("country", b =>
// b.withField("name", "string")
// .withField("continent", "string")
// )
// )
// .withMany("employer", b => b
// .withField("name", "string")
// .withField("employees", "number")
// )
// .run()
//const x: typeof result = null!