@zmdb/compiler 1.0.0-beta.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/LICENSE +674 -0
- package/README.md +40 -0
- package/dist/codegen/index.d.ts +50 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +364 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/scan.d.ts +105 -0
- package/dist/codegen/scan.d.ts.map +1 -0
- package/dist/codegen/scan.js +450 -0
- package/dist/codegen/scan.js.map +1 -0
- package/dist/codegen/witness.d.ts +76 -0
- package/dist/codegen/witness.d.ts.map +1 -0
- package/dist/codegen/witness.js +690 -0
- package/dist/codegen/witness.js.map +1 -0
- package/dist/config/contract.d.ts +41 -0
- package/dist/config/contract.d.ts.map +1 -0
- package/dist/config/contract.js +5 -0
- package/dist/config/contract.js.map +1 -0
- package/dist/config/index.d.ts +53 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +277 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.zmdb.generated.d.ts +12 -0
- package/dist/config/index.zmdb.generated.js +28 -0
- package/dist/config/index.zmdb.witness.d.ts +3 -0
- package/dist/config/index.zmdb.witness.d.ts.map +1 -0
- package/dist/config/index.zmdb.witness.js +20 -0
- package/dist/config/index.zmdb.witness.js.map +1 -0
- package/dist/configured-plugin.d.ts +11 -0
- package/dist/configured-plugin.d.ts.map +1 -0
- package/dist/configured-plugin.js +27 -0
- package/dist/configured-plugin.js.map +1 -0
- package/dist/emit/index.d.ts +103 -0
- package/dist/emit/index.d.ts.map +1 -0
- package/dist/emit/index.js +1356 -0
- package/dist/emit/index.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +254 -0
- package/dist/index.js.map +1 -0
- package/dist/lint/ast.d.ts +17 -0
- package/dist/lint/ast.d.ts.map +1 -0
- package/dist/lint/ast.js +77 -0
- package/dist/lint/ast.js.map +1 -0
- package/dist/lint/host-types.d.ts +9 -0
- package/dist/lint/host-types.d.ts.map +1 -0
- package/dist/lint/host-types.js +2 -0
- package/dist/lint/host-types.js.map +1 -0
- package/dist/lint/index.d.ts +23 -0
- package/dist/lint/index.d.ts.map +1 -0
- package/dist/lint/index.js +53 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/lint/rules/no-distributed-nullable-tags.d.ts +3 -0
- package/dist/lint/rules/no-distributed-nullable-tags.d.ts.map +1 -0
- package/dist/lint/rules/no-distributed-nullable-tags.js +71 -0
- package/dist/lint/rules/no-distributed-nullable-tags.js.map +1 -0
- package/dist/lint/rules/no-empty-patch.d.ts +3 -0
- package/dist/lint/rules/no-empty-patch.d.ts.map +1 -0
- package/dist/lint/rules/no-empty-patch.js +26 -0
- package/dist/lint/rules/no-empty-patch.js.map +1 -0
- package/dist/lint/rules/no-interpolated-sql.d.ts +3 -0
- package/dist/lint/rules/no-interpolated-sql.d.ts.map +1 -0
- package/dist/lint/rules/no-interpolated-sql.js +35 -0
- package/dist/lint/rules/no-interpolated-sql.js.map +1 -0
- package/dist/lint/rules/no-unbounded-find.d.ts +3 -0
- package/dist/lint/rules/no-unbounded-find.d.ts.map +1 -0
- package/dist/lint/rules/no-unbounded-find.js +26 -0
- package/dist/lint/rules/no-unbounded-find.js.map +1 -0
- package/dist/lint/rules/no-unknown-json-column.d.ts +3 -0
- package/dist/lint/rules/no-unknown-json-column.d.ts.map +1 -0
- package/dist/lint/rules/no-unknown-json-column.js +35 -0
- package/dist/lint/rules/no-unknown-json-column.js.map +1 -0
- package/dist/lint/rules/require-sql-on-number.d.ts +3 -0
- package/dist/lint/rules/require-sql-on-number.d.ts.map +1 -0
- package/dist/lint/rules/require-sql-on-number.js +34 -0
- package/dist/lint/rules/require-sql-on-number.js.map +1 -0
- package/dist/lint/types.d.ts +12 -0
- package/dist/lint/types.d.ts.map +1 -0
- package/dist/lint/types.js +2 -0
- package/dist/lint/types.js.map +1 -0
- package/dist/metro/metro.d.ts +22 -0
- package/dist/metro/metro.d.ts.map +1 -0
- package/dist/metro/metro.js +242 -0
- package/dist/metro/metro.js.map +1 -0
- package/dist/protobuf/decode.d.ts +20 -0
- package/dist/protobuf/decode.d.ts.map +1 -0
- package/dist/protobuf/decode.js +289 -0
- package/dist/protobuf/decode.js.map +1 -0
- package/dist/protobuf/descriptor.d.ts +16 -0
- package/dist/protobuf/descriptor.d.ts.map +1 -0
- package/dist/protobuf/descriptor.js +303 -0
- package/dist/protobuf/descriptor.js.map +1 -0
- package/dist/protobuf/encode.d.ts +20 -0
- package/dist/protobuf/encode.d.ts.map +1 -0
- package/dist/protobuf/encode.js +203 -0
- package/dist/protobuf/encode.js.map +1 -0
- package/dist/protobuf/grpc-ir.d.ts +16 -0
- package/dist/protobuf/grpc-ir.d.ts.map +1 -0
- package/dist/protobuf/grpc-ir.js +2 -0
- package/dist/protobuf/grpc-ir.js.map +1 -0
- package/dist/protobuf/plan.d.ts +42 -0
- package/dist/protobuf/plan.d.ts.map +1 -0
- package/dist/protobuf/plan.js +158 -0
- package/dist/protobuf/plan.js.map +1 -0
- package/dist/reflect/callsites.d.ts +40 -0
- package/dist/reflect/callsites.d.ts.map +1 -0
- package/dist/reflect/callsites.js +153 -0
- package/dist/reflect/callsites.js.map +1 -0
- package/dist/reflect/index.d.ts +106 -0
- package/dist/reflect/index.d.ts.map +1 -0
- package/dist/reflect/index.js +1421 -0
- package/dist/reflect/index.js.map +1 -0
- package/dist/reflect/session.d.ts +118 -0
- package/dist/reflect/session.d.ts.map +1 -0
- package/dist/reflect/session.js +228 -0
- package/dist/reflect/session.js.map +1 -0
- package/dist/testing/index.d.ts +69 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +210 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/transform/index.d.ts +74 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +572 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/unplugin/index.d.ts +53 -0
- package/dist/unplugin/index.d.ts.map +1 -0
- package/dist/unplugin/index.js +130 -0
- package/dist/unplugin/index.js.map +1 -0
- package/dist/unplugin/inline-bench.d.ts +29 -0
- package/dist/unplugin/inline-bench.d.ts.map +1 -0
- package/dist/unplugin/inline-bench.js +82 -0
- package/dist/unplugin/inline-bench.js.map +1 -0
- package/package.json +110 -0
- package/src/codegen/index.ts +451 -0
- package/src/codegen/scan.ts +574 -0
- package/src/codegen/witness.ts +819 -0
- package/src/config/contract.ts +48 -0
- package/src/config/index.ts +384 -0
- package/src/config/index.zmdb.generated.d.ts +12 -0
- package/src/config/index.zmdb.generated.js +28 -0
- package/src/config/index.zmdb.witness.ts +22 -0
- package/src/configured-plugin.ts +35 -0
- package/src/emit/index.ts +1496 -0
- package/src/errors.ts +6 -0
- package/src/index.ts +336 -0
- package/src/lint/ast.ts +96 -0
- package/src/lint/host-types.ts +9 -0
- package/src/lint/index.ts +80 -0
- package/src/lint/rules/no-distributed-nullable-tags.ts +76 -0
- package/src/lint/rules/no-empty-patch.ts +26 -0
- package/src/lint/rules/no-interpolated-sql.ts +45 -0
- package/src/lint/rules/no-unbounded-find.ts +26 -0
- package/src/lint/rules/no-unknown-json-column.ts +36 -0
- package/src/lint/rules/require-sql-on-number.ts +34 -0
- package/src/lint/types.ts +11 -0
- package/src/metro/metro.ts +313 -0
- package/src/protobuf/decode.ts +375 -0
- package/src/protobuf/descriptor.ts +353 -0
- package/src/protobuf/encode.ts +277 -0
- package/src/protobuf/grpc-ir.ts +17 -0
- package/src/protobuf/plan.ts +244 -0
- package/src/reflect/callsites.ts +198 -0
- package/src/reflect/index.ts +1723 -0
- package/src/reflect/session.ts +276 -0
- package/src/testing/index.ts +298 -0
- package/src/transform/index.ts +690 -0
- package/src/unplugin/index.ts +182 -0
- package/src/unplugin/inline-bench.ts +92 -0
|
@@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,GAAG,aAAa,GAAG,SAAS,CAuCxC;AAgCD,wBAAgB,QAAQ,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAEvG;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {} from '@zmdb/schema/ir';
|
|
2
|
+
export const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
3
|
+
const THIRTY_TWO_BIT = new Set(['int32', 'uint32', 'sint32', 'fixed32', 'sfixed32']);
|
|
4
|
+
const SIXTY_FOUR_BIT = new Set(['int64', 'uint64', 'sint64', 'fixed64', 'sfixed64']);
|
|
5
|
+
const FLOATING = new Set(['float', 'double']);
|
|
6
|
+
export function collectMessages(node, suggested, register) {
|
|
7
|
+
switch (node.kind) {
|
|
8
|
+
case 'object':
|
|
9
|
+
if (!register(node, suggested))
|
|
10
|
+
return;
|
|
11
|
+
for (const property of node.properties) {
|
|
12
|
+
collectMessages(property.type, `${suggested}${safeName(property.name)}`, register);
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
case 'array':
|
|
16
|
+
collectMessages(node.element, suggested, register);
|
|
17
|
+
return;
|
|
18
|
+
case 'tuple':
|
|
19
|
+
for (const [index, element] of node.elements.entries()) {
|
|
20
|
+
collectMessages(element, `${suggested}${index + 1}`, register);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
case 'union':
|
|
24
|
+
for (const member of node.members)
|
|
25
|
+
collectMessages(member, suggested, register);
|
|
26
|
+
return;
|
|
27
|
+
default:
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function planField(node, path, atomPlan, enumeration, refuse) {
|
|
32
|
+
if (node.kind === 'array') {
|
|
33
|
+
if (node.element.kind === 'array') {
|
|
34
|
+
return refuse(path, 'a nested array would require `repeated repeated`, which proto3 cannot spell without an explicit wrapper message');
|
|
35
|
+
}
|
|
36
|
+
const element = planField(node.element, `${path}[]`, atomPlan, enumeration, refuse);
|
|
37
|
+
if (element === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
if (element.repeated || element.nullable) {
|
|
40
|
+
return refuse(path, 'a repeated protobuf element cannot itself be repeated or nullable');
|
|
41
|
+
}
|
|
42
|
+
return { atom: element.atom, repeated: true, nullable: false };
|
|
43
|
+
}
|
|
44
|
+
if (node.kind === 'union') {
|
|
45
|
+
const values = node.members.filter(member => member.kind !== 'null' && member.kind !== 'undefined');
|
|
46
|
+
const nullable = node.members.some(member => member.kind === 'null');
|
|
47
|
+
const literals = values.filter(member => member.kind === 'literal' && typeof member.value === 'string');
|
|
48
|
+
if (literals.length === values.length && literals.length > 0) {
|
|
49
|
+
const atom = enumeration(path, literals.map(member => (member.kind === 'literal' && typeof member.value === 'string' ? member.value : '')));
|
|
50
|
+
return { atom, repeated: false, nullable };
|
|
51
|
+
}
|
|
52
|
+
const [only] = values;
|
|
53
|
+
if (values.length === 1 && only !== undefined) {
|
|
54
|
+
const resolved = planField(only, path, atomPlan, enumeration, refuse);
|
|
55
|
+
return resolved === undefined ? undefined : { ...resolved, nullable: resolved.nullable || nullable };
|
|
56
|
+
}
|
|
57
|
+
if (values.some(member => member.kind === 'object')) {
|
|
58
|
+
return refuse(path, 'a union of message types would require `oneof`, but union arms have no ProtoField<N> tag slot');
|
|
59
|
+
}
|
|
60
|
+
return refuse(path, 'this TypeScript union has no single protobuf field spelling');
|
|
61
|
+
}
|
|
62
|
+
switch (node.kind) {
|
|
63
|
+
case 'scalar':
|
|
64
|
+
case 'object':
|
|
65
|
+
case 'ref': {
|
|
66
|
+
const atom = atomPlan(node, path);
|
|
67
|
+
return atom === undefined ? undefined : { atom, repeated: false, nullable: false };
|
|
68
|
+
}
|
|
69
|
+
case 'literal':
|
|
70
|
+
return typeof node.value === 'string'
|
|
71
|
+
? { atom: enumeration(path, [node.value]), repeated: false, nullable: false }
|
|
72
|
+
: refuse(path, 'a numeric or boolean literal has no protobuf wire constraint');
|
|
73
|
+
case 'tuple':
|
|
74
|
+
return refuse(path, 'a tuple has no protobuf field spelling; declare a numbered wrapper message');
|
|
75
|
+
case 'unknown':
|
|
76
|
+
return refuse(path, '`unknown` has no protobuf wire type');
|
|
77
|
+
case 'null':
|
|
78
|
+
case 'undefined':
|
|
79
|
+
return refuse(path, 'a protobuf field cannot contain only null or undefined');
|
|
80
|
+
case 'unsupported':
|
|
81
|
+
return refuse(path, node.reason, node.source);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function planScalar(node, path, timestamp, refuse) {
|
|
85
|
+
const proto = node.proto;
|
|
86
|
+
switch (node.scalar) {
|
|
87
|
+
case 'number':
|
|
88
|
+
case 'integer':
|
|
89
|
+
if (proto === undefined)
|
|
90
|
+
return scalar('double', 1, 'number');
|
|
91
|
+
if (THIRTY_TWO_BIT.has(proto) || FLOATING.has(proto))
|
|
92
|
+
return numeric(proto);
|
|
93
|
+
if (SIXTY_FOUR_BIT.has(proto)) {
|
|
94
|
+
return refuse(path, `Proto<'${proto}'> needs bigint because a TypeScript number cannot preserve every 64-bit integer`);
|
|
95
|
+
}
|
|
96
|
+
return refuse(path, `Proto<'${proto}'> is not a numeric protobuf scalar`);
|
|
97
|
+
case 'bigint':
|
|
98
|
+
if (proto === undefined) {
|
|
99
|
+
return refuse(path, 'an untagged bigint has no inferable protobuf width or signedness; add Proto<K>');
|
|
100
|
+
}
|
|
101
|
+
return SIXTY_FOUR_BIT.has(proto)
|
|
102
|
+
? numeric(proto)
|
|
103
|
+
: refuse(path, `a bigint protobuf field needs an explicit 64-bit scalar, not Proto<'${proto}'>`);
|
|
104
|
+
case 'boolean':
|
|
105
|
+
if (proto === undefined || proto === 'bool')
|
|
106
|
+
return scalar('bool', 0, 'boolean');
|
|
107
|
+
return refuse(path, `a boolean protobuf field cannot use Proto<'${proto}'>`);
|
|
108
|
+
case 'string':
|
|
109
|
+
if (proto === undefined || proto === 'string')
|
|
110
|
+
return scalar('string', 2, 'string');
|
|
111
|
+
if (proto === 'bytes') {
|
|
112
|
+
return refuse(path, "Proto<'bytes'> needs Uint8Array, and the current reflection refuses typed-array data types");
|
|
113
|
+
}
|
|
114
|
+
return refuse(path, `a string protobuf field cannot use Proto<'${proto}'>`);
|
|
115
|
+
case 'date':
|
|
116
|
+
if (proto !== undefined) {
|
|
117
|
+
return refuse(path, `Date has the fixed google.protobuf.Timestamp mapping, not Proto<'${proto}'>`);
|
|
118
|
+
}
|
|
119
|
+
return { kind: 'timestamp', helper: timestamp(), wire: 2 };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function numeric(method) {
|
|
123
|
+
switch (method) {
|
|
124
|
+
case 'int32':
|
|
125
|
+
case 'uint32':
|
|
126
|
+
case 'sint32':
|
|
127
|
+
return scalar(method, 0, 'number');
|
|
128
|
+
case 'int64':
|
|
129
|
+
case 'uint64':
|
|
130
|
+
case 'sint64':
|
|
131
|
+
return scalar(method, 0, 'bigint');
|
|
132
|
+
case 'fixed32':
|
|
133
|
+
case 'sfixed32':
|
|
134
|
+
case 'float':
|
|
135
|
+
return scalar(method, 5, 'number');
|
|
136
|
+
case 'fixed64':
|
|
137
|
+
case 'sfixed64':
|
|
138
|
+
return scalar(method, 1, 'bigint');
|
|
139
|
+
case 'double':
|
|
140
|
+
return scalar(method, 1, 'number');
|
|
141
|
+
case 'bool':
|
|
142
|
+
case 'string':
|
|
143
|
+
case 'bytes':
|
|
144
|
+
throw new Error(`non-numeric protobuf scalar ${method}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function scalar(method, wire, zero) {
|
|
148
|
+
return { kind: 'scalar', method, wire, zero };
|
|
149
|
+
}
|
|
150
|
+
export function isPacked(atom) {
|
|
151
|
+
return atom.kind === 'enum' || (atom.kind === 'scalar' && atom.method !== 'string');
|
|
152
|
+
}
|
|
153
|
+
export function safeName(raw) {
|
|
154
|
+
const words = raw.split(/[^A-Za-z0-9_$]+/).filter(word => word.length > 0);
|
|
155
|
+
const joined = words.map(word => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`).join('');
|
|
156
|
+
return joined.length === 0 ? 'Message' : joined;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/protobuf/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,MAAM,iBAAiB,CAAC;AAmD9F,MAAM,CAAC,MAAM,UAAU,GAAG,0BAA0B,CAAC;AACrD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAClG,MAAM,cAAc,GAAG,IAAI,GAAG,CAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAClG,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAM3D,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,SAAiB,EACjB,QAAwD;IAExD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;gBAAE,OAAO;YACvC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACvC,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;YACrF,CAAC;YACD,OAAO;QACT,KAAK,OAAO;YACV,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,S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AE,QAAQ,CAAC,CAAC;QACrC,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,MAA4B,EAAE,IAAwB,EAAE,IAAwB;IAC9F,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAsB,IAAoB;IAChE,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/F,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CallExpression, SourceFile, TypeNode } from 'typescript/unstable/ast';
|
|
2
|
+
import { type Checker } from 'typescript/unstable/sync';
|
|
3
|
+
export declare const CALL_OWNERS: Readonly<Record<string, readonly string[]>>;
|
|
4
|
+
export declare const OWNED_CALLEES: ReadonlySet<string>;
|
|
5
|
+
export declare const STRICT_OWNER_CALLEES: ReadonlySet<string>;
|
|
6
|
+
export interface CallSite {
|
|
7
|
+
/** The canonical exported name, even when the local import is aliased. */
|
|
8
|
+
readonly callee: string;
|
|
9
|
+
/** The local named-import binding, or the namespace binding for `ns.callee`. */
|
|
10
|
+
readonly binding: string;
|
|
11
|
+
/** The owner module whose export resolved to this call. */
|
|
12
|
+
readonly specifier?: string;
|
|
13
|
+
/** The single type argument. A call with none is not a call site. */
|
|
14
|
+
readonly typeArgument: TypeNode;
|
|
15
|
+
readonly node: CallExpression;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Every call to one of `callees` that carries a type argument, in source order.
|
|
19
|
+
*
|
|
20
|
+
* Source order matters downstream: the transformer rewrites by text offset, and
|
|
21
|
+
* rewriting back-to-front is what keeps earlier offsets valid.
|
|
22
|
+
*/
|
|
23
|
+
export declare function findCallSites(sourceFile: SourceFile, callees: ReadonlySet<string>): readonly CallSite[];
|
|
24
|
+
export interface OwnedCallOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Test-only escape for synthetic global declarations. Production callers leave
|
|
27
|
+
* this false; strict-owner calls then require a matching `CALL_OWNERS` import.
|
|
28
|
+
*/
|
|
29
|
+
readonly allowUnbound?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calls whose resolved symbol is an allowed package export, plus legacy
|
|
33
|
+
* text-matched validator/schema calls that intentionally retain forwarding support.
|
|
34
|
+
*
|
|
35
|
+
* The canonical export table is built only from owner modules the file actually
|
|
36
|
+
* imports. Strict-owner calls therefore cannot match a foreign same-named function
|
|
37
|
+
* by structural type or text.
|
|
38
|
+
*/
|
|
39
|
+
export declare function findOwnedCallSites(sourceFile: SourceFile, checker: Checker, callees: ReadonlySet<string>, owners: Readonly<Record<string, readonly string[]>>, options?: OwnedCallOptions): readonly CallSite[];
|
|
40
|
+
//# sourceMappingURL=callsites.d.ts.map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,EAAE,CAAC,CAAC,EACnD,OAAO,GAAE,gBAAqB,GAC7B,SAAS,QAAQ,EAAE,CAsCrB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Finding the call sites the transformer replaces.
|
|
2
|
+
//
|
|
3
|
+
// The generic `findCallSites` helper remains text-based because reflection fixtures use
|
|
4
|
+
// local probe functions. Production transformation uses `findOwnedCallSites` instead.
|
|
5
|
+
// The five protobuf/gRPC calls resolve strictly to exports of `@zmdb/protobuf`, so a
|
|
6
|
+
// local shadow, foreign same-named export, or old forwarding package is not a target.
|
|
7
|
+
// Existing validator/schema calls retain their historical text-based forwarding support.
|
|
8
|
+
import { isCallExpression, isIdentifier, isImportDeclaration, isPropertyAccessExpression, isStringLiteral, } from 'typescript/unstable/ast/is';
|
|
9
|
+
import { SymbolFlags } from 'typescript/unstable/sync';
|
|
10
|
+
export const CALL_OWNERS = Object.freeze({
|
|
11
|
+
is: ['@zmdb/validator', 'zmdb', 'zmdb/validator'],
|
|
12
|
+
isShallow: ['@zmdb/validator', 'zmdb/validator'],
|
|
13
|
+
assert: ['@zmdb/validator', 'zmdb', 'zmdb/validator'],
|
|
14
|
+
assertShallow: ['@zmdb/validator', 'zmdb/validator'],
|
|
15
|
+
equals: ['@zmdb/validator', 'zmdb/validator'],
|
|
16
|
+
assertEquals: ['@zmdb/validator', 'zmdb/validator'],
|
|
17
|
+
validate: ['@zmdb/validator', 'zmdb', 'zmdb/validator'],
|
|
18
|
+
validateShallow: ['@zmdb/validator', 'zmdb/validator'],
|
|
19
|
+
random: ['@zmdb/validator', 'zmdb/validator'],
|
|
20
|
+
toJsonSchema: ['@zmdb/schema/openapi', 'zmdb/schema'],
|
|
21
|
+
schemaOf: ['@zmdb/schema', 'zmdb', 'zmdb/schema'],
|
|
22
|
+
toolFor: ['@zmdb/ai'],
|
|
23
|
+
grpcDescriptor: ['@zmdb/protobuf'],
|
|
24
|
+
loadGrpcService: ['@zmdb/protobuf'],
|
|
25
|
+
protoDescriptor: ['@zmdb/protobuf'],
|
|
26
|
+
protoDecode: ['@zmdb/protobuf'],
|
|
27
|
+
protoEncode: ['@zmdb/protobuf'],
|
|
28
|
+
});
|
|
29
|
+
export const OWNED_CALLEES = new Set(Object.keys(CALL_OWNERS));
|
|
30
|
+
export const STRICT_OWNER_CALLEES = new Set([
|
|
31
|
+
'grpcDescriptor',
|
|
32
|
+
'loadGrpcService',
|
|
33
|
+
'protoDescriptor',
|
|
34
|
+
'protoDecode',
|
|
35
|
+
'protoEncode',
|
|
36
|
+
]);
|
|
37
|
+
/** `is(...)` → `is`; `v.is(...)` → `is`; anything else → `undefined`. */
|
|
38
|
+
function calleeName(call) {
|
|
39
|
+
const target = call.expression;
|
|
40
|
+
if (isIdentifier(target))
|
|
41
|
+
return { callee: target.text, binding: target.text };
|
|
42
|
+
if (isPropertyAccessExpression(target) && isIdentifier(target.name) && isIdentifier(target.expression)) {
|
|
43
|
+
return { callee: target.name.text, binding: target.expression.text };
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Every call to one of `callees` that carries a type argument, in source order.
|
|
49
|
+
*
|
|
50
|
+
* Source order matters downstream: the transformer rewrites by text offset, and
|
|
51
|
+
* rewriting back-to-front is what keeps earlier offsets valid.
|
|
52
|
+
*/
|
|
53
|
+
export function findCallSites(sourceFile, callees) {
|
|
54
|
+
const found = [];
|
|
55
|
+
// `forEachChild` is a method on the node, not a free function: it is not among the
|
|
56
|
+
// exports of `typescript/unstable/ast`, which only offers the *visitor* (rewriting)
|
|
57
|
+
// half of the pair.
|
|
58
|
+
const visit = (node) => {
|
|
59
|
+
if (isCallExpression(node)) {
|
|
60
|
+
const typeArgument = node.typeArguments?.[0];
|
|
61
|
+
const named = calleeName(node);
|
|
62
|
+
if (typeArgument && named !== undefined && callees.has(named.callee)) {
|
|
63
|
+
found.push({ ...named, typeArgument, node });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
node.forEachChild(visit);
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
sourceFile.forEachChild(visit);
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
72
|
+
function resolved(checker, symbol) {
|
|
73
|
+
if (symbol === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
return (symbol.flags & SymbolFlags.Alias) === 0 ? symbol : checker.getAliasedSymbol(symbol);
|
|
76
|
+
}
|
|
77
|
+
function importedExports(sourceFile, checker, callees, owners) {
|
|
78
|
+
const bySymbol = new Map();
|
|
79
|
+
for (const statement of sourceFile.statements) {
|
|
80
|
+
if (!isImportDeclaration(statement) || !isStringLiteral(statement.moduleSpecifier))
|
|
81
|
+
continue;
|
|
82
|
+
const specifier = statement.moduleSpecifier.text;
|
|
83
|
+
const candidates = [...callees].filter(callee => owners[callee]?.includes(specifier) === true);
|
|
84
|
+
if (candidates.length === 0)
|
|
85
|
+
continue;
|
|
86
|
+
const module = checker.getSymbolAtLocation(statement.moduleSpecifier);
|
|
87
|
+
if (module === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const exports = new Map(checker.getExportsOfModule(module).map(symbol => [symbol.name, symbol]));
|
|
90
|
+
for (const callee of candidates) {
|
|
91
|
+
const symbol = resolved(checker, exports.get(callee));
|
|
92
|
+
if (symbol !== undefined)
|
|
93
|
+
bySymbol.set(symbol.id, { callee, specifier });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return bySymbol;
|
|
97
|
+
}
|
|
98
|
+
function callTarget(call) {
|
|
99
|
+
const target = call.expression;
|
|
100
|
+
if (isIdentifier(target))
|
|
101
|
+
return { location: target, binding: target.text };
|
|
102
|
+
if (isPropertyAccessExpression(target) && isIdentifier(target.name) && isIdentifier(target.expression)) {
|
|
103
|
+
return { location: target.name, binding: target.expression.text };
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Calls whose resolved symbol is an allowed package export, plus legacy
|
|
109
|
+
* text-matched validator/schema calls that intentionally retain forwarding support.
|
|
110
|
+
*
|
|
111
|
+
* The canonical export table is built only from owner modules the file actually
|
|
112
|
+
* imports. Strict-owner calls therefore cannot match a foreign same-named function
|
|
113
|
+
* by structural type or text.
|
|
114
|
+
*/
|
|
115
|
+
export function findOwnedCallSites(sourceFile, checker, callees, owners, options = {}) {
|
|
116
|
+
if (options.allowUnbound === true)
|
|
117
|
+
return findCallSites(sourceFile, callees);
|
|
118
|
+
const canonical = importedExports(sourceFile, checker, callees, owners);
|
|
119
|
+
const found = [];
|
|
120
|
+
const visit = (node) => {
|
|
121
|
+
if (isCallExpression(node)) {
|
|
122
|
+
const typeArgument = node.typeArguments?.[0];
|
|
123
|
+
const target = callTarget(node);
|
|
124
|
+
if (typeArgument !== undefined && target !== undefined) {
|
|
125
|
+
const symbol = resolved(checker, checker.getSymbolAtLocation(target.location));
|
|
126
|
+
const owned = symbol === undefined ? undefined : canonical.get(symbol.id);
|
|
127
|
+
if (owned !== undefined) {
|
|
128
|
+
found.push({
|
|
129
|
+
callee: owned.callee,
|
|
130
|
+
binding: target.binding,
|
|
131
|
+
specifier: owned.specifier,
|
|
132
|
+
typeArgument,
|
|
133
|
+
node,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const named = calleeName(node);
|
|
138
|
+
if (named !== undefined && callees.has(named.callee) && !STRICT_OWNER_CALLEES.has(named.callee)) {
|
|
139
|
+
// Validator/schema calls retain their established forwarding support.
|
|
140
|
+
// The new protobuf boundary is deliberately stricter because those old
|
|
141
|
+
// owners are removed rather than kept as compatibility aliases.
|
|
142
|
+
found.push({ ...named, typeArgument, node });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
node.forEachChild(visit);
|
|
148
|
+
return undefined;
|
|
149
|
+
};
|
|
150
|
+
sourceFile.forEachChild(visit);
|
|
151
|
+
return found;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=callsites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callsites.js","sourceRoot":"","sources":["../../src/reflect/callsites.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,wFAAwF;AACxF,sFAAsF;AACtF,qFAAqF;AACrF,sFAAsF;AACtF,yFAAyF;AAGzF,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAyC,MAAM,0BAA0B,CAAC;AAE9F,MAAM,CAAC,MAAM,WAAW,GAAgD,MAAM,CAAC,MAAM,CAAC;IACpF,EAAE,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,CAAC;IACjD,SAAS,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IAChD,MAAM,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,CAAC;IACrD,aAAa,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IACpD,MAAM,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IAC7C,YAAY,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IACnD,QAAQ,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,CAAC;IACvD,eAAe,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IACtD,MAAM,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IAC7C,YAAY,EAAE,CAAC,sBAAsB,EAAE,aAAa,CAAC;IACrD,QAAQ,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,CAAC;IACjD,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB,cAAc,EAAE,CAAC,gBAAgB,CAAC;IAClC,eAAe,EAAE,CAAC,gBAAgB,CAAC;IACnC,eAAe,EAAE,CAAC,gBAAgB,CAAC;IACnC,WAAW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AC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;wBAChG,sEAAsE;wBACtE,uEAAuE;wBACvE,gEAAgE;wBAChE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC/C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type SchemaIR, type ShapeIR, type TypeIR } from '@zmdb/schema/ir';
|
|
2
|
+
import { type NamingStrategy } from '@zmdb/schema/naming';
|
|
3
|
+
import type { Node } from 'typescript/unstable/ast';
|
|
4
|
+
import type { Checker, Type } from 'typescript/unstable/sync';
|
|
5
|
+
import type { GrpcServiceIR } from '../protobuf/grpc-ir.js';
|
|
6
|
+
export { apiInstanceCount, projectSourceFileNames, ReflectSession, withSession } from './session.js';
|
|
7
|
+
export type { SessionOptions, SessionUpdate, SourceFileHandle } from './session.js';
|
|
8
|
+
export type { GrpcMethodIR, GrpcServiceIR } from '../protobuf/grpc-ir.js';
|
|
9
|
+
/**
|
|
10
|
+
* A refusal, recorded rather than thrown. `path` is the property chain that reached
|
|
11
|
+
* it (`'email'`, `'profile.address.zip'`) so the message can point somewhere.
|
|
12
|
+
*/
|
|
13
|
+
export interface ReflectDiagnostic {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
/** The type as the checker prints it, when that is more use than the path. */
|
|
17
|
+
readonly source?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ReflectLimits {
|
|
20
|
+
/** Nesting depth of object/array/union recursion. */
|
|
21
|
+
readonly maxDepth: number;
|
|
22
|
+
/** Total IR nodes produced by one reflector. */
|
|
23
|
+
readonly maxNodes: number;
|
|
24
|
+
/** Distinct named objects, i.e. hoistable helpers in the emitted code. */
|
|
25
|
+
readonly maxHelpers: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Deliberately generous. These are a guard against pathological input, not a style
|
|
29
|
+
* guide: a legitimate 30-deep nested JSON payload is unusual but not wrong, and a
|
|
30
|
+
* cap that fires on real code trains people to raise it rather than to read it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_LIMITS: ReflectLimits;
|
|
33
|
+
export interface ReflectOptions {
|
|
34
|
+
readonly limits?: Partial<ReflectLimits>;
|
|
35
|
+
/** Resolved from `zmdb.config.ts` by the caller. Absent means identity. */
|
|
36
|
+
readonly naming?: NamingStrategy;
|
|
37
|
+
}
|
|
38
|
+
export { type NamingStrategy } from '@zmdb/schema/naming';
|
|
39
|
+
/**
|
|
40
|
+
* One reflector per file, not per type: the budget, the helper names and the
|
|
41
|
+
* duplicate-tag detector are all whole-program facts, and splitting them per type
|
|
42
|
+
* would let a 200-type file blow past every cap one type at a time.
|
|
43
|
+
*/
|
|
44
|
+
export declare class Reflector {
|
|
45
|
+
#private;
|
|
46
|
+
readonly diagnostics: ReflectDiagnostic[];
|
|
47
|
+
constructor(checker: Checker, location: Node, options?: ReflectOptions);
|
|
48
|
+
/** The structural IR of a type. Total: always returns a node. */
|
|
49
|
+
typeIR(type: Type, path?: string): TypeIR;
|
|
50
|
+
/**
|
|
51
|
+
* The structural IR of a protobuf message, with field-number validation enabled.
|
|
52
|
+
*
|
|
53
|
+
* Ordinary validators may reflect an object whose properties have no protobuf
|
|
54
|
+
* numbers; only a protobuf call makes complete numbering mandatory. Keeping that
|
|
55
|
+
* decision here means every protobuf back-end receives the same checked IR.
|
|
56
|
+
*/
|
|
57
|
+
protobufIR(type: Type): TypeIR;
|
|
58
|
+
/**
|
|
59
|
+
* Reflect a gRPC service while keeping every message on the protobuf path.
|
|
60
|
+
*
|
|
61
|
+
* The service shell is not a protobuf message: its properties are methods,
|
|
62
|
+
* and each method owns two message roots. Reflecting those roots here keeps
|
|
63
|
+
* field-number validation and every downstream codec on the one TypeIR walk.
|
|
64
|
+
*/
|
|
65
|
+
grpcServiceIR(type: Type): GrpcServiceIR;
|
|
66
|
+
/**
|
|
67
|
+
* The schema IR of a *tagged entity* type: the only way a table's IR is produced.
|
|
68
|
+
*
|
|
69
|
+
* There used to be a second producer that read the same document back out of a builder
|
|
70
|
+
* value, and for the length of the migration the two had to agree node for node. Now this
|
|
71
|
+
* is it, so every SQL snapshot, DDL golden and JSON Schema contract in the repository is
|
|
72
|
+
* downstream of what this returns (REQ-TF-7, REQ-TF-12). `reflect.spec.ts` writes out the
|
|
73
|
+
* answer for the two-table corpus, which is what stands in for that differential.
|
|
74
|
+
*/
|
|
75
|
+
schemaIR(type: Type, fallbackTable?: string): SchemaIR;
|
|
76
|
+
/**
|
|
77
|
+
* The columns of any object type, each with its own optionality — what the JSON
|
|
78
|
+
* Schema back-end consumes (`jsonSchemaFromShape`).
|
|
79
|
+
*
|
|
80
|
+
* `schemaIR` above is for a tagged *entity*: it wants a `Table<'name'>` tag, reads
|
|
81
|
+
* relations, and computes a primary key. A document is generated from something
|
|
82
|
+
* weaker and more general — `CreateDTO<User>`, `ReadDTO<User>`, or a `Pick` of either
|
|
83
|
+
* — and none of those carry a table name, because a mapped type drops the
|
|
84
|
+
* symbol-keyed entity tags along with everything else non-string. Demanding one would
|
|
85
|
+
* make the type-driven `toJsonSchema<T>()` work on exactly one shape per table.
|
|
86
|
+
*
|
|
87
|
+
* The optionality is the type's own, read off the property symbol. That is the whole
|
|
88
|
+
* reason this is not `schemaIR` with a flag: `CreateDTO<User>` has already applied the
|
|
89
|
+
* "a column with a default may be omitted" rule that the `'create'` variant applies by
|
|
90
|
+
* hand, and reading it back off the type is what makes the two paths agree by
|
|
91
|
+
* construction rather than by a rule written twice.
|
|
92
|
+
*
|
|
93
|
+
* Relations are skipped, as they are in `schemaIR`: a join target is not a column and
|
|
94
|
+
* has no place in a column's document. `toJsonSchemaWithRelations` adds `$ref`s on top.
|
|
95
|
+
*/
|
|
96
|
+
shapeIR(type: Type): ShapeIR;
|
|
97
|
+
}
|
|
98
|
+
export interface ReflectResult<T> {
|
|
99
|
+
readonly ir: T;
|
|
100
|
+
readonly diagnostics: readonly ReflectDiagnostic[];
|
|
101
|
+
}
|
|
102
|
+
/** One type, one IR, plus whatever the reflection had to refuse along the way. */
|
|
103
|
+
export declare function irFromType(checker: Checker, type: Type, location: Node, options?: ReflectOptions): ReflectResult<TypeIR>;
|
|
104
|
+
/** A tagged entity type, read to the `SchemaIR` every back-end takes. */
|
|
105
|
+
export declare function schemaIrFromType(checker: Checker, type: Type, location: Node, options?: ReflectOptions): ReflectResult<SchemaIR>;
|
|
106
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reflect/index.ts"],"names":[],"mappings":"AAkCA,OAAO,EAgBL,KAAK,QAAQ,EAEb,KAAK,OAAO,EAGZ,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAwC,IAAI,EAAiB,MAAM,0BAA0B,CAAC;AAEnH,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrG,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpF,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAM1E;;;GA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