@sentio/sdk 2.39.3 → 2.39.4-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +54 -32
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/convert.d.ts +32 -0
- package/lib/store/convert.d.ts.map +1 -0
- package/lib/store/convert.js +249 -0
- package/lib/store/convert.js.map +1 -0
- package/lib/store/convert.test.d.ts +2 -0
- package/lib/store/convert.test.d.ts.map +1 -0
- package/lib/store/convert.test.js.map +1 -0
- package/lib/store/entity.d.ts +11 -5
- package/lib/store/entity.d.ts.map +1 -1
- package/lib/store/entity.js +35 -26
- package/lib/store/entity.js.map +1 -1
- package/lib/store/index.d.ts +1 -0
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +1 -0
- package/lib/store/index.js.map +1 -1
- package/lib/store/store.d.ts +14 -1
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +85 -47
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +0 -2
- package/lib/store/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/store/codegen.ts +58 -35
- package/src/store/convert.ts +271 -0
- package/src/store/entity.ts +37 -24
- package/src/store/index.ts +1 -0
- package/src/store/store.ts +112 -42
- package/src/store/types.ts +0 -3
package/lib/store/entity.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/store/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/store/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY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AAE,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAA;QAC1E,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAiB,CAAA;IAC9C,CAAC;IAED,QAAQ;QACN,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,UAAU,CAAA;QACxD,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;QAClB,OAAO,GAAG,UAAU,IAAI,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IAC5D,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF"}
|
package/lib/store/index.d.ts
CHANGED
package/lib/store/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
package/lib/store/index.js
CHANGED
package/lib/store/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
package/lib/store/store.d.ts
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
import { Entity, EntityClass } from './entity.js';
|
2
2
|
import { StoreContext } from './context.js';
|
3
|
+
import { BigDecimal } from '@sentio/bigdecimal';
|
4
|
+
import { Bytes, DateTime, Float, ID, Int } from './types.js';
|
5
|
+
type Value = ID | string | Int | Float | boolean | DateTime | Bytes | BigDecimal | bigint;
|
3
6
|
export declare class Store {
|
4
7
|
private readonly context;
|
5
8
|
constructor(context: StoreContext);
|
6
9
|
get<T extends Entity>(entity: EntityClass<T> | string, id: string): Promise<T | undefined>;
|
7
10
|
delete(entity: EntityClass<any>, id: string | string[]): Promise<void>;
|
8
11
|
upsert<T extends Entity>(entity: T | T[]): Promise<void>;
|
9
|
-
list<T extends Entity>(entity: EntityClass<T>,
|
12
|
+
list<T extends Entity>(entity: EntityClass<T>, filters?: ListFilter<T>[]): AsyncGenerator<T, void, unknown>;
|
10
13
|
private newEntity;
|
11
14
|
}
|
15
|
+
export type Operators = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not in';
|
16
|
+
export interface ListFilter<T extends Entity> {
|
17
|
+
field: keyof T;
|
18
|
+
op: Operators;
|
19
|
+
value: Value | Value[] | null;
|
20
|
+
}
|
21
|
+
export interface ListOptions<T extends Entity> {
|
22
|
+
cursor: string;
|
23
|
+
}
|
24
|
+
export {};
|
12
25
|
//# sourceMappingURL=store.d.ts.map
|
package/lib/store/store.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,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,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,QAAQ,CAAA;AAE9E,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM;IAC1C,KAAK,EAAE,MAAM,CAAC,CAAA;IACd,EAAE,EAAE,SAAS,CAAA;IACb,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,IAAI,CAAA;CAC9B;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM;IAC3C,MAAM,EAAE,MAAM,CAAA;CACf"}
|
package/lib/store/store.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { Entity } from './entity.js';
|
2
2
|
import { DatabaseSchema } from '../core/index.js';
|
3
3
|
import { BigDecimal } from '@sentio/bigdecimal';
|
4
|
+
import { DBRequest_DBOperator } from '@sentio/protos';
|
5
|
+
import { toBigInteger } from './convert.js';
|
4
6
|
export class Store {
|
5
7
|
context;
|
6
8
|
constructor(context) {
|
@@ -14,8 +16,9 @@ export class Store {
|
|
14
16
|
}
|
15
17
|
});
|
16
18
|
const data = (await promise);
|
17
|
-
if (data?.[
|
18
|
-
|
19
|
+
if (data.entities?.entities[0]) {
|
20
|
+
const entityData = data.entities.entities[0];
|
21
|
+
return this.newEntity(entity, entityData);
|
19
22
|
}
|
20
23
|
return undefined;
|
21
24
|
}
|
@@ -41,67 +44,102 @@ export class Store {
|
|
41
44
|
const promise = this.context.sendRequest({
|
42
45
|
upsert: {
|
43
46
|
entity: entities.map((e) => e.constructor.prototype.entityName),
|
44
|
-
data: entities.map((e) => serialize(e.data)),
|
45
|
-
id: entities.map((e) => e.id)
|
47
|
+
// data: entities.map((e) => serialize(e.data)),
|
48
|
+
id: entities.map((e) => e.id),
|
49
|
+
entityData: entities.map((e) => e.serialize())
|
46
50
|
}
|
47
51
|
});
|
48
52
|
await promise;
|
49
53
|
}
|
50
|
-
async list(entity,
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
async *list(entity, filters) {
|
55
|
+
let cursor = undefined;
|
56
|
+
while (true) {
|
57
|
+
const promise = this.context.sendRequest({
|
58
|
+
list: {
|
59
|
+
entity: entity.prototype.entityName,
|
60
|
+
cursor,
|
61
|
+
filters: filters?.map((f) => ({
|
62
|
+
field: f.field,
|
63
|
+
op: ops[f.op],
|
64
|
+
value: { values: Array.isArray(f.value) ? f.value.map((v) => serialize(v)) : [serialize(f.value)] }
|
65
|
+
})) || []
|
66
|
+
}
|
67
|
+
});
|
68
|
+
const response = (await promise);
|
69
|
+
for (const data of response.entities?.entities || []) {
|
70
|
+
yield this.newEntity(entity, data);
|
56
71
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
72
|
+
if (!response.nextCursor) {
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
cursor = response.nextCursor;
|
76
|
+
}
|
62
77
|
}
|
63
78
|
newEntity(entity, data) {
|
64
79
|
if (typeof entity == 'string') {
|
65
80
|
const en = DatabaseSchema.findEntity(entity);
|
66
81
|
if (!en) {
|
67
82
|
// it is an interface
|
68
|
-
return new Entity(
|
83
|
+
return new Entity();
|
69
84
|
}
|
70
85
|
entity = en;
|
71
86
|
}
|
72
|
-
|
87
|
+
const res = new entity({});
|
88
|
+
res.setData(data);
|
89
|
+
return res;
|
73
90
|
}
|
74
91
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
else {
|
98
|
-
ret[k] = serialize(v);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
else {
|
102
|
-
ret[k] = v;
|
103
|
-
}
|
92
|
+
const ops = {
|
93
|
+
'=': DBRequest_DBOperator.EQ,
|
94
|
+
'!=': DBRequest_DBOperator.NE,
|
95
|
+
'<': DBRequest_DBOperator.LT,
|
96
|
+
'<=': DBRequest_DBOperator.LE,
|
97
|
+
'>': DBRequest_DBOperator.GT,
|
98
|
+
'>=': DBRequest_DBOperator.GE,
|
99
|
+
in: DBRequest_DBOperator.IN,
|
100
|
+
'not in': DBRequest_DBOperator.NOT_IN
|
101
|
+
};
|
102
|
+
function serialize(v) {
|
103
|
+
if (v == null) {
|
104
|
+
return { nullValue: 0 };
|
105
|
+
}
|
106
|
+
if (typeof v == 'boolean') {
|
107
|
+
return { boolValue: v };
|
108
|
+
}
|
109
|
+
if (typeof v == 'string') {
|
110
|
+
return { stringValue: v };
|
111
|
+
}
|
112
|
+
if (typeof v == 'number') {
|
113
|
+
return { floatValue: v };
|
104
114
|
}
|
105
|
-
|
115
|
+
if (typeof v == 'bigint') {
|
116
|
+
return {
|
117
|
+
bigintValue: toBigInteger(v)
|
118
|
+
};
|
119
|
+
}
|
120
|
+
if (v instanceof BigDecimal) {
|
121
|
+
return serializeBigDecimal(v);
|
122
|
+
}
|
123
|
+
if (v instanceof Date) {
|
124
|
+
return {
|
125
|
+
timestampValue: v
|
126
|
+
};
|
127
|
+
}
|
128
|
+
if (v instanceof Uint8Array) {
|
129
|
+
return { bytesValue: v };
|
130
|
+
}
|
131
|
+
if (Array.isArray(v)) {
|
132
|
+
return {
|
133
|
+
listValue: { values: v.map((v) => serialize(v)) }
|
134
|
+
};
|
135
|
+
}
|
136
|
+
return {
|
137
|
+
nullValue: 0
|
138
|
+
};
|
139
|
+
}
|
140
|
+
function serializeBigDecimal(v) {
|
141
|
+
return {
|
142
|
+
bigdecimalValue: undefined
|
143
|
+
};
|
106
144
|
}
|
107
145
|
//# sourceMappingURL=store.js.map
|
package/lib/store/store.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,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lib/store/types.d.ts
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
export type { BigDecimal } from '@sentio/bigdecimal';
|
2
1
|
export type ID = string;
|
3
2
|
export type String = string;
|
4
3
|
export type Int = number;
|
5
4
|
export type Float = number;
|
6
5
|
export type Boolean = boolean;
|
7
6
|
export type DateTime = Date;
|
8
|
-
export type Json = any;
|
9
7
|
export type Bytes = Uint8Array;
|
10
8
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/store/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,CAAA;AACvB,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAC3B,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AACxB,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,OAAO,GAAG,OAAO,CAAA;AAC7B,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAA;AAC3B,MAAM,MAAM,KAAK,GAAG,UAAU,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.39.
|
3
|
+
"version": "2.39.4-rc.1",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -82,8 +82,8 @@
|
|
82
82
|
"typedoc": "^0.25.7",
|
83
83
|
"utility-types": "^3.11.0",
|
84
84
|
"yaml": "^2.3.4",
|
85
|
-
"@sentio/protos": "2.39.
|
86
|
-
"@sentio/runtime": "^2.39.
|
85
|
+
"@sentio/protos": "2.39.4-rc.1",
|
86
|
+
"@sentio/runtime": "^2.39.4-rc.1"
|
87
87
|
},
|
88
88
|
"peerDependencies": {
|
89
89
|
"tsup": "npm:@sentio/tsup@^6.7.2"
|
package/src/store/codegen.ts
CHANGED
@@ -38,20 +38,17 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
38
38
|
'/* Autogenerated file. Do not edit manually. */\n',
|
39
39
|
'/* tslint:disable */',
|
40
40
|
'/* eslint-disable */',
|
41
|
-
"import {entity, derivedFrom, DateTime, Int, Float, String,
|
42
|
-
`import {
|
41
|
+
"import { entity, derivedFrom, DateTime, Int, Float, String, Bytes, Boolean, ID, Entity, Store } from '@sentio/sdk/store'",
|
42
|
+
`import { BigDecimalConverter, BigIntConverter, IntConverter, StringConverter, IDConverter, BooleanConverter, BytesConverter, DateTimeConverter, FloatConverter, StructConverter, required_, array_, enumerate_, objectId_ } from '@sentio/sdk/store'`,
|
43
|
+
`import { DatabaseSchema, BigDecimal } from "@sentio/sdk"`,
|
44
|
+
`type BigInt = bigint`
|
43
45
|
]
|
44
46
|
const entities: string[] = []
|
47
|
+
|
45
48
|
for (const t of Object.values(schema.getTypeMap())) {
|
46
49
|
if (t.name.startsWith('__')) {
|
47
50
|
continue
|
48
51
|
}
|
49
|
-
|
50
|
-
if (t instanceof GraphQLObjectType) {
|
51
|
-
const entityContent = genEntity(t)
|
52
|
-
results.push(entityContent)
|
53
|
-
entities.push(t.name)
|
54
|
-
}
|
55
52
|
if (t instanceof GraphQLEnumType) {
|
56
53
|
results.push(genEnum(t))
|
57
54
|
}
|
@@ -59,6 +56,17 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
59
56
|
results.push(genInterface(t))
|
60
57
|
}
|
61
58
|
}
|
59
|
+
for (const t of Object.values(schema.getTypeMap())) {
|
60
|
+
if (t.name.startsWith('__')) {
|
61
|
+
continue
|
62
|
+
}
|
63
|
+
|
64
|
+
if (t instanceof GraphQLObjectType) {
|
65
|
+
const entityContent = genEntity(t)
|
66
|
+
results.push(entityContent)
|
67
|
+
entities.push(t.name)
|
68
|
+
}
|
69
|
+
}
|
62
70
|
|
63
71
|
const contents =
|
64
72
|
results.join('\n') +
|
@@ -96,11 +104,11 @@ const graphqlTypes = Object.entries(JsTypes).reduce(
|
|
96
104
|
{} as Record<string, string>
|
97
105
|
)
|
98
106
|
|
99
|
-
function genType(type: GraphQLOutputType): string {
|
107
|
+
function genType(type: GraphQLOutputType, required?: boolean): string {
|
100
108
|
if (type instanceof GraphQLNonNull) {
|
101
|
-
return genType(type.ofType)
|
109
|
+
return genType(type.ofType, true)
|
102
110
|
} else if (type instanceof GraphQLScalarType) {
|
103
|
-
return type.name
|
111
|
+
return required ? type.name : `${type.name} | undefined`
|
104
112
|
} else if (type instanceof GraphQLObjectType || type instanceof GraphQLInterfaceType) {
|
105
113
|
return type.name
|
106
114
|
} else if (type instanceof GraphQLList) {
|
@@ -138,44 +146,48 @@ function getElementType(type: GraphQLOutputType) {
|
|
138
146
|
return type
|
139
147
|
}
|
140
148
|
|
149
|
+
const getConverter = (t: GraphQLOutputType): string => {
|
150
|
+
if (t instanceof GraphQLNonNull) {
|
151
|
+
return `required_(${getConverter(t.ofType)})`
|
152
|
+
}
|
153
|
+
if (t instanceof GraphQLList) {
|
154
|
+
return `array_(${getConverter(t.ofType)})`
|
155
|
+
}
|
156
|
+
if (t instanceof GraphQLEnumType) {
|
157
|
+
return `enumerate_<${t.name}>(${t.name})`
|
158
|
+
}
|
159
|
+
if (isObject(t)) {
|
160
|
+
return `objectId_<${genType(getElementType(t))}>()`
|
161
|
+
}
|
162
|
+
return `${t.name}Converter`
|
163
|
+
}
|
164
|
+
|
141
165
|
function genField(field: GraphQLField<any, any>) {
|
142
166
|
const isNonNull = field.type instanceof GraphQLNonNull
|
143
167
|
const directives = field.astNode?.directives?.map((d) => '\t' + directive2decorator(d) + '\n') || []
|
144
168
|
|
145
169
|
const type = genType(field.type)
|
146
|
-
const returnType = isNonNull ? type : `${type} | undefined`
|
147
170
|
|
148
171
|
if (isObject(field.type)) {
|
149
172
|
const t = getElementType(field.type)
|
150
173
|
const typeAsArg = isInterfaceType(t) ? `"${t}"` : genType(t)
|
151
174
|
|
152
175
|
if (isList(field.type)) {
|
176
|
+
const required = (field.type as GraphQLList<any>).ofType instanceof GraphQLNonNull
|
177
|
+
const converter = required ? `array_(required_(IDConverter))` : `array_(IDConverter)`
|
178
|
+
const returnType = required ? `ID[]` : `Array<ID | undefined>`
|
153
179
|
return `${directives.join()}\tget ${field.name}(): Promise<${genType(t)}[]> { return this.getFieldObjectArray(${typeAsArg}, "${field.name}") as Promise<${genType(t)}[]> }
|
154
|
-
set ${field.name}(value: ${type} | ID[]) { this.
|
155
|
-
get ${field.name}Ids():
|
180
|
+
set ${field.name}(value: ${type} | ID[]) { this.setObject("${field.name}", value) }
|
181
|
+
get ${field.name}Ids(): ${returnType} { return this.get("${field.name}", ${converter}) }`
|
156
182
|
}
|
157
183
|
|
158
|
-
return `${directives.join()}\tget ${field.name}(): Promise<${genType(t)} | undefined> { return this.
|
159
|
-
set ${field.name}(value: ${type} | ID) { this.set("${field.name}", value) }
|
160
|
-
get ${field.name}Id(): ID | undefined { return this.get("${field.name}") }`
|
161
|
-
}
|
162
|
-
|
163
|
-
if (returnType == 'BigInt') {
|
164
|
-
return `${directives.join()}\tget ${field.name}(): bigint { return BigInt(this.get("${field.name}")) }
|
165
|
-
set ${field.name}(value: ${type}) { this.set("${field.name}", value.toString()) }`
|
166
|
-
}
|
167
|
-
if (returnType == 'BigDecimal') {
|
168
|
-
return `${directives.join()}\tget ${field.name}(): ${returnType} { return new BigDecimal(this.get("${field.name}")) }
|
169
|
-
set ${field.name}(value: ${type}) { this.set("${field.name}", value.toString()) }`
|
170
|
-
}
|
171
|
-
|
172
|
-
if (returnType == 'Bytes') {
|
173
|
-
return `${directives.join()}\tget ${field.name}(): ${returnType} { return Uint8Array.from(Buffer.from(this.get<string>("${field.name}"), 'hex')) ) }
|
174
|
-
set ${field.name}(value: ${type}) { this.set("${field.name}", Buffer.from(value).toString('hex')) }`
|
184
|
+
return `${directives.join()}\tget ${field.name}(): Promise<${genType(t)} | undefined> { return this.getObject(${typeAsArg},"${field.name}") as Promise<${genType(t)} | undefined> }
|
185
|
+
set ${field.name}(value: ${type} | ID) { this.set("${field.name}", value, objectId_<${type}>()) }
|
186
|
+
get ${field.name}Id(): ID | undefined { return this.get("${field.name}", IDConverter) }`
|
175
187
|
}
|
176
188
|
|
177
|
-
return `${directives.join()}\tget ${field.name}(): ${
|
178
|
-
set ${field.name}(value: ${type}) { this.set("${field.name}", value) }`
|
189
|
+
return `${directives.join()}\tget ${field.name}(): ${type} { return this.get("${field.name}", ${getConverter(field.type)}) }
|
190
|
+
set ${field.name}(value: ${type}) { this.set("${field.name}", value, ${getConverter(field.type)}) }`
|
179
191
|
}
|
180
192
|
|
181
193
|
function genDataType(t: GraphQLObjectType<any, any>) {
|
@@ -217,13 +229,24 @@ ${genDataType(t)}
|
|
217
229
|
${decorators.join('\n')}
|
218
230
|
@entity("${t.name}")
|
219
231
|
export class ${t.name} extends Entity${impls} {
|
232
|
+
${genConverters(t)}
|
220
233
|
constructor(data: Partial<${t.name}Data>) {
|
221
|
-
super(data)
|
234
|
+
super(${t.name}.entityConverter.from(data))
|
222
235
|
}
|
223
236
|
${Object.values(t.getFields()).map(genField).join('\n')}
|
224
237
|
}`
|
225
238
|
}
|
226
239
|
|
240
|
+
function genConverters(t: GraphQLObjectType<any, any>) {
|
241
|
+
const fields = Object.values(t.getFields())
|
242
|
+
const converters = fields.map((f) => {
|
243
|
+
const type = genType(f.type)
|
244
|
+
const converter = getConverter(f.type)
|
245
|
+
return `\t\t${f.name}: ${converter},`
|
246
|
+
})
|
247
|
+
return `static entityConverter = new StructConverter({\n ${converters.join('\n')} \n})`
|
248
|
+
}
|
249
|
+
|
227
250
|
function genInterface(t: GraphQLInterfaceType) {
|
228
251
|
return `
|
229
252
|
export interface ${t.name} {
|
@@ -250,7 +273,7 @@ function genEnum(t: GraphQLEnumType) {
|
|
250
273
|
export enum ${t.name} {
|
251
274
|
${t
|
252
275
|
.getValues()
|
253
|
-
.map((v) => `\t${v.name}`)
|
276
|
+
.map((v) => `\t${v.name} = "${v.value}"`)
|
254
277
|
.join(', ')}
|
255
278
|
}`
|
256
279
|
}
|