-
Notifications
You must be signed in to change notification settings - Fork 12
/
query.util.ts
113 lines (104 loc) · 3.71 KB
/
query.util.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type {
IAccessDescriptor,
IExistenceDescriptor,
TAccessQueryParameter,
TOptionalAccessQueryParameter
} from "./query.spec.ts";
import {EAccess, EExistence, ETargetType} from "./query.spec.ts";
import type {TObjectProto, TTypeProto} from "../_.spec.ts";
import type {IEntity, TTag} from "../entity/entity.spec.ts";
import {Entity} from "../entity/entity.ts";
import {accessDescSym, existenceDescSym} from "./_.ts";
export function ReadEntity(uuid?: string): TAccessQueryParameter<TTypeProto<Readonly<IEntity>>> {
return Object.assign({}, Entity, {
[accessDescSym]: {
optional: false,
data: uuid,
target: Entity,
targetType: ETargetType.entity,
type: EAccess.meta,
},
} as IAccessDescriptor<Entity>);
}
export function Read<C extends object>(componentPrototype: TTypeProto<C>): TAccessQueryParameter<TTypeProto<Readonly<C>>> {
return Object.assign({}, componentPrototype.prototype, {
[accessDescSym]: {
optional: false,
target: componentPrototype,
targetType: ETargetType.component,
type: EAccess.read,
},
} as IAccessDescriptor<C>);
}
export function ReadOptional<C extends object>(componentPrototype: TTypeProto<C>): TOptionalAccessQueryParameter<TTypeProto<Readonly<C>>> {
return Object.assign({}, componentPrototype.prototype, {
[accessDescSym]: {
optional: true,
target: componentPrototype,
targetType: ETargetType.component,
type: EAccess.read,
},
} as IAccessDescriptor<C>);
}
export function Write<C extends object>(componentPrototype: TTypeProto<C>): TAccessQueryParameter<TTypeProto<C>> {
return Object.assign({}, componentPrototype.prototype, {
[accessDescSym]: {
optional: false,
target: componentPrototype,
targetType: ETargetType.component,
type: EAccess.write,
},
} as IAccessDescriptor<C>);
}
export function WriteOptional<C extends object>(componentPrototype: TTypeProto<C>): TOptionalAccessQueryParameter<TTypeProto<C>> {
return Object.assign({}, componentPrototype.prototype, {
[accessDescSym]: {
optional: true,
target: componentPrototype,
targetType: ETargetType.component,
type: EAccess.write,
},
} as IAccessDescriptor<C>);
}
export function With<C extends object>(componentPrototype: TTypeProto<C>): IExistenceDescriptor<TTypeProto<C>> {
return {
[existenceDescSym]: {
target: componentPrototype,
targetType: ETargetType.component,
type: EExistence.set,
}
};
}
export function WithTag(tag: TTag): TAccessQueryParameter<TObjectProto> & IExistenceDescriptor<TObjectProto> {
return {
[accessDescSym]: {
optional: false,
target: tag,
targetType: ETargetType.tag,
type: EAccess.meta,
},
[existenceDescSym]: {
target: tag,
targetType: ETargetType.tag,
type: EExistence.set,
}
} as TAccessQueryParameter<TObjectProto> & IExistenceDescriptor<TObjectProto>;
}
export function Without<C extends object>(componentPrototype: TTypeProto<C>): IExistenceDescriptor<TTypeProto<C>> {
return {
[existenceDescSym]: {
target: componentPrototype,
targetType: ETargetType.component,
type: EExistence.unset,
}
};
}
export function WithoutTag(tag: TTag): IExistenceDescriptor<TObjectProto> {
return {
[existenceDescSym]: {
target: tag,
targetType: ETargetType.tag,
type: EExistence.unset,
}
};
}