@furo/open-models 0.0.0-alpha.0
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 +21 -0
- package/README.md +27 -0
- package/dist/CustomPrototypes.d.ts +6 -0
- package/dist/CustomPrototypes.js +4 -0
- package/dist/CustomPrototypes.js.map +1 -0
- package/dist/FDM_OPTIONS.d.ts +16 -0
- package/dist/FDM_OPTIONS.js +8 -0
- package/dist/FDM_OPTIONS.js.map +1 -0
- package/dist/FieldConstraints.d.ts +15 -0
- package/dist/FieldConstraints.js +3 -0
- package/dist/FieldConstraints.js.map +1 -0
- package/dist/FieldNode.d.ts +339 -0
- package/dist/FieldNode.js +835 -0
- package/dist/FieldNode.js.map +1 -0
- package/dist/OM_OPTIONS.d.ts +16 -0
- package/dist/OM_OPTIONS.js +8 -0
- package/dist/OM_OPTIONS.js.map +1 -0
- package/dist/OPEN_MODELS_OPTIONS.d.ts +16 -0
- package/dist/OPEN_MODELS_OPTIONS.js +8 -0
- package/dist/OPEN_MODELS_OPTIONS.js.map +1 -0
- package/dist/OPTIONS.d.ts +16 -0
- package/dist/OPTIONS.js +8 -0
- package/dist/OPTIONS.js.map +1 -0
- package/dist/Registry.d.ts +17 -0
- package/dist/Registry.js +29 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Validator.d.ts +7 -0
- package/dist/Validator.js +3 -0
- package/dist/Validator.js.map +1 -0
- package/dist/ValueState.d.ts +37 -0
- package/dist/ValueState.js +39 -0
- package/dist/ValueState.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives/BOOLEAN.d.ts +14 -0
- package/dist/primitives/BOOLEAN.js +56 -0
- package/dist/primitives/BOOLEAN.js.map +1 -0
- package/dist/primitives/ENUM.d.ts +17 -0
- package/dist/primitives/ENUM.js +76 -0
- package/dist/primitives/ENUM.js.map +1 -0
- package/dist/primitives/INT32.d.ts +18 -0
- package/dist/primitives/INT32.js +98 -0
- package/dist/primitives/INT32.js.map +1 -0
- package/dist/primitives/STRING.d.ts +16 -0
- package/dist/primitives/STRING.js +99 -0
- package/dist/primitives/STRING.js.map +1 -0
- package/dist/proxies/ARRAY.d.ts +165 -0
- package/dist/proxies/ARRAY.js +398 -0
- package/dist/proxies/ARRAY.js.map +1 -0
- package/dist/proxies/MAP.d.ts +101 -0
- package/dist/proxies/MAP.js +225 -0
- package/dist/proxies/MAP.js.map +1 -0
- package/dist/proxies/RECURSION.d.ts +13 -0
- package/dist/proxies/RECURSION.js +51 -0
- package/dist/proxies/RECURSION.js.map +1 -0
- package/dist/well_known/ANY.d.ts +20 -0
- package/dist/well_known/ANY.js +91 -0
- package/dist/well_known/ANY.js.map +1 -0
- package/dist/well_known/Int32Value.d.ts +17 -0
- package/dist/well_known/Int32Value.js +115 -0
- package/dist/well_known/Int32Value.js.map +1 -0
- package/dist/well_known/Int64Value.d.ts +16 -0
- package/dist/well_known/Int64Value.js +105 -0
- package/dist/well_known/Int64Value.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
import { Registry } from '../Registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* K can only be a 'string' or 'number' because in JSON UseProtoNames you can only set a string or a number.
|
|
5
|
+
*
|
|
6
|
+
* Even https://protobuf.dev/programming-guides/proto3/#maps defines another structure,
|
|
7
|
+
* we use https://protobuf.dev/programming-guides/proto3/#json
|
|
8
|
+
*/
|
|
9
|
+
export class MAP extends FieldNode {
|
|
10
|
+
constructor(initData, parent, parentAttributeName) {
|
|
11
|
+
super(undefined, parent, parentAttributeName);
|
|
12
|
+
// ev. private machen
|
|
13
|
+
this.value = new Map();
|
|
14
|
+
if (initData !== undefined) {
|
|
15
|
+
if (initData !== undefined) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.error('Use the MAP.Builder()');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
this.__isPrimitive = true;
|
|
21
|
+
}
|
|
22
|
+
static Builder(TConstructor, initData) {
|
|
23
|
+
const m = new MAP();
|
|
24
|
+
m.initFromLiteral(TConstructor, initData);
|
|
25
|
+
return m;
|
|
26
|
+
}
|
|
27
|
+
// eslint-disable-next-line class-methods-use-this
|
|
28
|
+
toString() {
|
|
29
|
+
// resolve parent
|
|
30
|
+
return `[object MAP<..., ...>]`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param Constructor - type constructor for T
|
|
35
|
+
* @param {{ [key: string | number]: I }} initData - initial map interface type
|
|
36
|
+
*/
|
|
37
|
+
initFromLiteral(Constructor, initData) {
|
|
38
|
+
// empty the map but keep the ref.
|
|
39
|
+
this.value.clear();
|
|
40
|
+
Object.keys(initData).forEach(k => {
|
|
41
|
+
const fieldnode = new Constructor();
|
|
42
|
+
fieldnode.__updateWithLiteral(initData[k]);
|
|
43
|
+
fieldnode.__parentNode = this;
|
|
44
|
+
this.value.set(k, fieldnode);
|
|
45
|
+
});
|
|
46
|
+
this.__isEmpty = false;
|
|
47
|
+
this.__notifyMapChanges(false);
|
|
48
|
+
}
|
|
49
|
+
__getFieldNodeByPath(deepPath = '') {
|
|
50
|
+
const path = deepPath.split('.');
|
|
51
|
+
if (path.length > 0 && path[0] !== '') {
|
|
52
|
+
// eslint-disable-next-line no-param-reassign
|
|
53
|
+
deepPath = path.slice(1).join('.');
|
|
54
|
+
if (deepPath === '') {
|
|
55
|
+
if (this.value.has(path[0])) {
|
|
56
|
+
return this.value.get(path[0]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (this.value.has(path[0])) {
|
|
60
|
+
return this.value.get(path[0]).__getFieldNodeByPath(deepPath);
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
get __childNodes() {
|
|
67
|
+
const children = [];
|
|
68
|
+
this.value.forEach(v => children.push(v));
|
|
69
|
+
return children;
|
|
70
|
+
}
|
|
71
|
+
__notifyMapChanges(bubbles) {
|
|
72
|
+
this.__dispatchEvent(new CustomEvent('this-map-changed', {
|
|
73
|
+
detail: this,
|
|
74
|
+
bubbles: false,
|
|
75
|
+
}));
|
|
76
|
+
this.__dispatchEvent(new CustomEvent('this-field-value-changed', {
|
|
77
|
+
detail: this,
|
|
78
|
+
bubbles: false,
|
|
79
|
+
}));
|
|
80
|
+
if (bubbles) {
|
|
81
|
+
this.__dispatchEvent(new CustomEvent('map-changed', {
|
|
82
|
+
detail: this,
|
|
83
|
+
bubbles: true,
|
|
84
|
+
}));
|
|
85
|
+
this.__dispatchEvent(new CustomEvent('field-value-changed', {
|
|
86
|
+
detail: this,
|
|
87
|
+
bubbles: true,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.__dispatchEvent(new CustomEvent('map-changed', {
|
|
92
|
+
detail: this,
|
|
93
|
+
bubbles: false,
|
|
94
|
+
}));
|
|
95
|
+
this.__dispatchEvent(new CustomEvent('field-value-changed', {
|
|
96
|
+
detail: this,
|
|
97
|
+
bubbles: false,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param initData
|
|
104
|
+
*/
|
|
105
|
+
__updateWithLiteral(initData) {
|
|
106
|
+
// empty the map but keep the ref.
|
|
107
|
+
this.value.clear();
|
|
108
|
+
this.__meta.initialValue = initData;
|
|
109
|
+
if (this.__parentNode !== undefined) {
|
|
110
|
+
const fieldDescriptor = this.__parentNode.__meta.nodeFields.find(f => f.fieldName === this.__meta.fieldName);
|
|
111
|
+
const Constructor = fieldDescriptor?.ValueConstructor;
|
|
112
|
+
this.initFromLiteral(Constructor, initData);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
__mapJsonToLiteral(data) {
|
|
117
|
+
const literal = {};
|
|
118
|
+
if (this.__parentNode !== undefined) {
|
|
119
|
+
const fieldDescriptor = this.__parentNode.__meta.nodeFields.find(f => f.fieldName === this.__meta.fieldName);
|
|
120
|
+
const Constructor = fieldDescriptor?.ValueConstructor;
|
|
121
|
+
const dummy = new Constructor();
|
|
122
|
+
// eslint-disable-next-line guard-for-in
|
|
123
|
+
Object.entries(data).forEach(v => {
|
|
124
|
+
literal[v[0]] = dummy.__mapJsonToLiteral(v[1]);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return literal;
|
|
128
|
+
}
|
|
129
|
+
__toJson() {
|
|
130
|
+
return this.__toLiteral();
|
|
131
|
+
}
|
|
132
|
+
__toLiteral() {
|
|
133
|
+
const d = {};
|
|
134
|
+
this.value.forEach((item, k) => {
|
|
135
|
+
d[k] = item.__toLiteral();
|
|
136
|
+
});
|
|
137
|
+
return d;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
|
|
141
|
+
*
|
|
142
|
+
* The set() method adds or updates an entry in a Map object with a specified key and a value.
|
|
143
|
+
*
|
|
144
|
+
* #### Params:
|
|
145
|
+
* - **key:** The key of the element to add to the Map object. The key may be any JavaScript typeName (any primitive value or any typeName of JavaScript object ).
|
|
146
|
+
* - **value:** The value of the element to add to the Map object. The value may be any JavaScript typeName (any primitive value or any typeName of JavaScript object ).
|
|
147
|
+
*
|
|
148
|
+
* #### Returns:
|
|
149
|
+
* The Map object.
|
|
150
|
+
*/
|
|
151
|
+
set(key, value) {
|
|
152
|
+
this.__isEmpty = false;
|
|
153
|
+
const ret = this.value.set(key, value);
|
|
154
|
+
this.__notifyMapChanges(true);
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
clear() {
|
|
158
|
+
this.__clear();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The __clear() method of Map instances removes all elements from this map.
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
__clear() {
|
|
165
|
+
this.__isEmpty = true;
|
|
166
|
+
this.value.clear();
|
|
167
|
+
this.__notifyMapChanges(false);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @returns true if an element in the Map existed and has been removed, or false if the element does not exist.
|
|
171
|
+
*/
|
|
172
|
+
delete(key) {
|
|
173
|
+
const ret = this.value.delete(key);
|
|
174
|
+
this.__notifyMapChanges(true);
|
|
175
|
+
return ret;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Executes a provided function once per each key/value pair in the Map, in insertion order.
|
|
179
|
+
*
|
|
180
|
+
* #### Params:
|
|
181
|
+
* - **callbackFn:** A function to execute for each entry in the map. The function is called with the following arguments:
|
|
182
|
+
* - **value:** Value of each iteration.
|
|
183
|
+
* - **key:** Key of each iteration.
|
|
184
|
+
* - **map:** The map being iterated.
|
|
185
|
+
* - **thisArg:** A value to use as this when executing callbackFn.
|
|
186
|
+
*/
|
|
187
|
+
forEach(callbackfn, thisArg) {
|
|
188
|
+
return this.value.forEach(callbackfn, thisArg);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
|
|
192
|
+
* @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
|
|
193
|
+
*/
|
|
194
|
+
get(key) {
|
|
195
|
+
return this.value.get(key);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @returns boolean indicating whether an element with the specified key exists or not.
|
|
199
|
+
*/
|
|
200
|
+
has(key) {
|
|
201
|
+
return this.value.has(key);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The keys() method of Map instances returns a new map iterator object that contains the keys for each element in this map in insertion order.
|
|
205
|
+
* Returns:
|
|
206
|
+
* A new iterable iterator object .
|
|
207
|
+
*/
|
|
208
|
+
keys() {
|
|
209
|
+
return this.value.keys();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The entries() method of Map instances returns a new map iterator object that contains the [key, value] pairs for each element in this map in insertion order.
|
|
213
|
+
*/
|
|
214
|
+
entries() {
|
|
215
|
+
return this.value.entries();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @returns the number of elements in the Map.
|
|
219
|
+
*/
|
|
220
|
+
get size() {
|
|
221
|
+
return this.value.size;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
Registry.register('map', MAP);
|
|
225
|
+
//# sourceMappingURL=MAP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MAP.js","sourceRoot":"","sources":["../../src/proxies/MAP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,OAAO,GAIX,SAAQ,SAAS;IAIjB,YACE,QAAwC,EACxC,MAAkB,EAClB,mBAA4B;QAE5B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC;QARhD,qBAAqB;QACd,UAAK,GAAc,IAAI,GAAG,EAAQ,CAAC;QASxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,OAAO,CACZ,YAAyB,EACzB,QAAuC;QAEvC,MAAM,CAAC,GAAG,IAAI,GAAG,EAAW,CAAC;QAC7B,CAAC,CAAC,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC1C,OAAO,CAAC,CAA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KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;;OAGG;IACI,GAAG,CAAC,GAAM;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAM;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AAED,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC","sourcesContent":["import { FieldNode } from '../FieldNode';\nimport { Registry } from '../Registry';\n\n/**\n * K can only be a 'string' or 'number' because in JSON UseProtoNames you can only set a string or a number.\n *\n * Even https://protobuf.dev/programming-guides/proto3/#maps defines another structure,\n * we use https://protobuf.dev/programming-guides/proto3/#json\n */\nexport class MAP<\n K extends string | number,\n T extends FieldNode,\n I,\n> extends FieldNode {\n // ev. private machen\n public value: Map<K, T> = new Map<K, T>();\n\n constructor(\n initData?: { [key: string | number]: I },\n parent?: FieldNode,\n parentAttributeName?: string,\n ) {\n super(undefined, parent, parentAttributeName);\n\n if (initData !== undefined) {\n if (initData !== undefined) {\n // eslint-disable-next-line no-console\n console.error('Use the MAP.Builder()');\n }\n }\n\n this.__isPrimitive = true;\n }\n\n static Builder<K extends string | number, T extends FieldNode, I>(\n TConstructor: new () => T,\n initData: { [key: string | number]: I },\n ): MAP<K, T, I> {\n const m = new MAP<K, T, I>();\n m.initFromLiteral(TConstructor, initData);\n return m;\n }\n\n // eslint-disable-next-line class-methods-use-this\n toString(): string {\n // resolve parent\n return `[object MAP<..., ...>]`;\n }\n\n /**\n *\n * @param Constructor - type constructor for T\n * @param {{ [key: string | number]: I }} initData - initial map interface type\n */\n initFromLiteral(\n Constructor: { new (): T },\n initData: { [key: string | number]: I },\n ) {\n // empty the map but keep the ref.\n this.value.clear();\n\n Object.keys(initData).forEach(k => {\n const fieldnode = new Constructor();\n fieldnode.__updateWithLiteral(initData[k]);\n fieldnode.__parentNode = this;\n this.value.set(k as K, fieldnode);\n });\n\n this.__isEmpty = false;\n this.__notifyMapChanges(false);\n }\n\n __getFieldNodeByPath(deepPath: string = ''): FieldNode | undefined {\n const path = deepPath.split('.');\n if (path.length > 0 && path[0] !== '') {\n // eslint-disable-next-line no-param-reassign\n deepPath = path.slice(1).join('.');\n if (deepPath === '') {\n if (this.value.has(path[0] as K)) {\n return this.value.get(path[0] as K) as FieldNode;\n }\n } else if (this.value.has(path[0] as K)) {\n return (this.value.get(path[0] as K) as FieldNode).__getFieldNodeByPath(\n deepPath,\n );\n }\n return undefined;\n }\n return undefined;\n }\n\n public get __childNodes(): T[] {\n const children: T[] = [];\n this.value.forEach(v => children.push(v));\n return children;\n }\n\n private __notifyMapChanges(bubbles?: boolean) {\n this.__dispatchEvent(\n new CustomEvent('this-map-changed', {\n detail: this,\n bubbles: false,\n }),\n );\n this.__dispatchEvent(\n new CustomEvent('this-field-value-changed', {\n detail: this,\n bubbles: false,\n }),\n );\n if (bubbles) {\n this.__dispatchEvent(\n new CustomEvent('map-changed', {\n detail: this,\n bubbles: true,\n }),\n );\n this.__dispatchEvent(\n new CustomEvent('field-value-changed', {\n detail: this,\n bubbles: true,\n }),\n );\n } else {\n this.__dispatchEvent(\n new CustomEvent('map-changed', {\n detail: this,\n bubbles: false,\n }),\n );\n this.__dispatchEvent(\n new CustomEvent('field-value-changed', {\n detail: this,\n bubbles: false,\n }),\n );\n }\n }\n\n /**\n *\n * @param initData\n */\n __updateWithLiteral(initData: { [key: string | number]: I }) {\n // empty the map but keep the ref.\n this.value.clear();\n this.__meta.initialValue = initData;\n if (this.__parentNode !== undefined) {\n const fieldDescriptor = this.__parentNode!.__meta.nodeFields.find(\n f => f.fieldName === this.__meta.fieldName,\n );\n const Constructor = fieldDescriptor?.ValueConstructor as new () => T;\n this.initFromLiteral(Constructor, initData);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n __mapJsonToLiteral(data: any): any {\n const literal: { [key: string | number]: I } = {};\n\n if (this.__parentNode !== undefined) {\n const fieldDescriptor = this.__parentNode!.__meta.nodeFields.find(\n f => f.fieldName === this.__meta.fieldName,\n );\n const Constructor = fieldDescriptor?.ValueConstructor as new () => T;\n const dummy = new Constructor();\n\n // eslint-disable-next-line guard-for-in\n Object.entries(data).forEach(v => {\n literal[v[0]] = dummy.__mapJsonToLiteral(v[1]);\n });\n }\n\n return literal;\n }\n\n __toJson(): { [key: string | number]: I } {\n return this.__toLiteral();\n }\n\n __toLiteral(): { [key: string | number]: I } {\n const d: { [key: string | number]: I } = {};\n this.value.forEach((item: T, k: K) => {\n d[k] = item.__toLiteral();\n });\n return d;\n }\n\n /**\n * Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.\n *\n * The set() method adds or updates an entry in a Map object with a specified key and a value.\n *\n * #### Params:\n * - **key:** The key of the element to add to the Map object. The key may be any JavaScript typeName (any primitive value or any typeName of JavaScript object ).\n * - **value:** The value of the element to add to the Map object. The value may be any JavaScript typeName (any primitive value or any typeName of JavaScript object ).\n *\n * #### Returns:\n * The Map object.\n */\n public set(key: K, value: T) {\n this.__isEmpty = false;\n const ret = this.value.set(key, value);\n this.__notifyMapChanges(true);\n return ret;\n }\n\n public clear(): void {\n this.__clear();\n }\n\n /**\n * The __clear() method of Map instances removes all elements from this map.\n * @public\n */\n __clear(): void {\n this.__isEmpty = true;\n this.value.clear();\n this.__notifyMapChanges(false);\n }\n\n /**\n * @returns true if an element in the Map existed and has been removed, or false if the element does not exist.\n */\n public delete(key: K): boolean {\n const ret = this.value.delete(key);\n this.__notifyMapChanges(true);\n return ret;\n }\n\n /**\n * Executes a provided function once per each key/value pair in the Map, in insertion order.\n *\n * #### Params:\n * - **callbackFn:** A function to execute for each entry in the map. The function is called with the following arguments:\n * - **value:** Value of each iteration.\n * - **key:** Key of each iteration.\n * - **map:** The map being iterated.\n * - **thisArg:** A value to use as this when executing callbackFn.\n */\n public forEach(\n callbackfn: (value: T, key: K, map: Map<K, T>) => void,\n thisArg?: unknown,\n ): void {\n return this.value.forEach(callbackfn, thisArg);\n }\n\n /**\n * Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.\n * @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.\n */\n public get(key: K): T | undefined {\n return this.value.get(key);\n }\n\n /**\n * @returns boolean indicating whether an element with the specified key exists or not.\n */\n public has(key: K): boolean {\n return this.value.has(key);\n }\n\n /**\n * The keys() method of Map instances returns a new map iterator object that contains the keys for each element in this map in insertion order.\n * Returns:\n * A new iterable iterator object .\n */\n public keys(): IterableIterator<K> {\n return this.value.keys();\n }\n\n /**\n * The entries() method of Map instances returns a new map iterator object that contains the [key, value] pairs for each element in this map in insertion order.\n */\n public entries(): IterableIterator<[K, T]> {\n return this.value.entries();\n }\n\n /**\n * @returns the number of elements in the Map.\n */\n public get size(): number {\n return this.value.size;\n }\n}\n\nRegistry.register('map', MAP);\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
export declare class RECURSION<T extends FieldNode, I> extends FieldNode {
|
|
3
|
+
private _value;
|
|
4
|
+
constructor(initData?: I, parent?: FieldNode, parentAttributeName?: string);
|
|
5
|
+
__clear(): void;
|
|
6
|
+
get value(): T | undefined;
|
|
7
|
+
set value(a: T);
|
|
8
|
+
__toJson(): object | null;
|
|
9
|
+
__toLiteral(): object | null;
|
|
10
|
+
___pathBuilder(parts: string[]): string[];
|
|
11
|
+
__updateWithLiteral(initData: I[]): void;
|
|
12
|
+
private __getConstructor;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// scalar and recursion typeName
|
|
2
|
+
import { FieldNode } from '../FieldNode.js';
|
|
3
|
+
export class RECURSION extends FieldNode {
|
|
4
|
+
constructor(initData, parent, parentAttributeName) {
|
|
5
|
+
super(undefined, parent, parentAttributeName);
|
|
6
|
+
this.__isPrimitive = true;
|
|
7
|
+
this.__meta.typeName = `primitives.RECURSION`;
|
|
8
|
+
}
|
|
9
|
+
__clear() {
|
|
10
|
+
this.__isEmpty = true;
|
|
11
|
+
this._value = undefined;
|
|
12
|
+
}
|
|
13
|
+
get value() {
|
|
14
|
+
return this._value;
|
|
15
|
+
}
|
|
16
|
+
set value(a) {
|
|
17
|
+
this._value = a;
|
|
18
|
+
}
|
|
19
|
+
__toJson() {
|
|
20
|
+
if (this._value !== undefined) {
|
|
21
|
+
return this._value?.__toJson();
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
__toLiteral() {
|
|
26
|
+
if (this._value !== undefined) {
|
|
27
|
+
return this._value?.__toLiteral();
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
___pathBuilder(parts) {
|
|
32
|
+
// pass to parents
|
|
33
|
+
return this.__parentNode.___pathBuilder(parts);
|
|
34
|
+
}
|
|
35
|
+
__updateWithLiteral(initData) {
|
|
36
|
+
if (this.__parentNode !== undefined) {
|
|
37
|
+
this._value = new (this.__getConstructor())();
|
|
38
|
+
this._value.__parentNode = this;
|
|
39
|
+
this._value.__meta.fieldName = this.__meta.fieldName;
|
|
40
|
+
this._value.__updateWithLiteral(initData);
|
|
41
|
+
this._value.__meta.isRecursionNode = true;
|
|
42
|
+
this.__isEmpty = false;
|
|
43
|
+
this.__notifyFieldValueChange(false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
__getConstructor() {
|
|
47
|
+
const fieldDescriptor = this.__parentNode.__meta.nodeFields.find(f => f.fieldName === this.__meta.fieldName);
|
|
48
|
+
return fieldDescriptor?.FieldConstructor;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=RECURSION.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RECURSION.js","sourceRoot":"","sources":["../../src/proxies/RECURSION.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,OAAO,SAAkC,SAAQ,SAAS;IAG9D,YAAY,QAAY,EAAE,MAAkB,EAAE,mBAA4B;QACxE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC;QAC9C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,sBAAsB,CAAC;IAChD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,CAAC,CAAI;QACZ,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC;QACpC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc,CAAC,KAAe;QAC5B,kBAAkB;QAClB,OAAQ,IAAI,CAAC,YAA0B,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;IAED,mBAAmB,CAAC,QAAa;QAC/B,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC;YAC1C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAEO,gBAAgB;QACtB,MAAM,eAAe,GAAG,IAAI,CAAC,YAAa,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAC/D,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,CAC3C,CAAC;QAEF,OAAO,eAAe,EAAE,gBAA+B,CAAC;IAC1D,CAAC;CACF","sourcesContent":["// scalar and recursion typeName\nimport { FieldNode } from '../FieldNode';\n\nexport class RECURSION<T extends FieldNode, I> extends FieldNode {\n private _value: T | undefined;\n\n constructor(initData?: I, parent?: FieldNode, parentAttributeName?: string) {\n super(undefined, parent, parentAttributeName);\n this.__isPrimitive = true;\n this.__meta.typeName = `primitives.RECURSION`;\n }\n\n __clear() {\n this.__isEmpty = true;\n this._value = undefined;\n }\n\n get value(): T | undefined {\n return this._value;\n }\n\n set value(a: T) {\n this._value = a;\n }\n\n __toJson(): object | null {\n if (this._value !== undefined) {\n return this._value?.__toJson();\n }\n return null;\n }\n\n __toLiteral(): object | null {\n if (this._value !== undefined) {\n return this._value?.__toLiteral();\n }\n return null;\n }\n\n ___pathBuilder(parts: string[]): string[] {\n // pass to parents\n return (this.__parentNode as FieldNode).___pathBuilder(parts);\n }\n\n __updateWithLiteral(initData: I[]) {\n if (this.__parentNode !== undefined) {\n this._value = new (this.__getConstructor())();\n this._value.__parentNode = this;\n this._value.__meta.fieldName = this.__meta.fieldName;\n this._value.__updateWithLiteral(initData);\n this._value.__meta.isRecursionNode = true;\n this.__isEmpty = false;\n this.__notifyFieldValueChange(false);\n }\n }\n\n private __getConstructor(): new () => T {\n const fieldDescriptor = this.__parentNode!.__meta.nodeFields.find(\n f => f.fieldName === this.__meta.fieldName,\n );\n\n return fieldDescriptor?.FieldConstructor as new () => T;\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
export interface IAny {
|
|
3
|
+
'@type': string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare class ANY extends FieldNode {
|
|
7
|
+
private _value;
|
|
8
|
+
private _typeName;
|
|
9
|
+
private _originalTypeName;
|
|
10
|
+
constructor(initData?: IAny, parent?: FieldNode, parentAttributeName?: string);
|
|
11
|
+
__clear(): void;
|
|
12
|
+
get __childNodes(): FieldNode[];
|
|
13
|
+
get value(): FieldNode | undefined;
|
|
14
|
+
set value(a: FieldNode | undefined);
|
|
15
|
+
get typeName(): string;
|
|
16
|
+
__toJson(): object | null;
|
|
17
|
+
__toLiteral(): object | null;
|
|
18
|
+
__mapJsonToLiteral(data: any): any;
|
|
19
|
+
__updateWithLiteral(data: IAny): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// scalar and any typeName
|
|
2
|
+
import { FieldNode } from '../FieldNode.js';
|
|
3
|
+
import { Registry } from '../Registry.js';
|
|
4
|
+
export class ANY extends FieldNode {
|
|
5
|
+
constructor(initData, parent, parentAttributeName) {
|
|
6
|
+
super(undefined, parent, parentAttributeName);
|
|
7
|
+
this._typeName = '';
|
|
8
|
+
this._originalTypeName = '';
|
|
9
|
+
this.__meta.typeName = `google.protobuf.Any`;
|
|
10
|
+
}
|
|
11
|
+
__clear() {
|
|
12
|
+
this.__isEmpty = true;
|
|
13
|
+
this._value = undefined;
|
|
14
|
+
}
|
|
15
|
+
// used by broadcast
|
|
16
|
+
get __childNodes() {
|
|
17
|
+
if (this._value) {
|
|
18
|
+
return [this._value];
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
get value() {
|
|
23
|
+
return this._value;
|
|
24
|
+
}
|
|
25
|
+
set value(a) {
|
|
26
|
+
this._value = a;
|
|
27
|
+
}
|
|
28
|
+
get typeName() {
|
|
29
|
+
return this._typeName;
|
|
30
|
+
}
|
|
31
|
+
__toJson() {
|
|
32
|
+
if (this._value !== undefined) {
|
|
33
|
+
const d = this._value?.__toJson();
|
|
34
|
+
d['@type'] = this._originalTypeName; // send back the original type name instead of this._value?.__meta.typeName;
|
|
35
|
+
return d;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
__toLiteral() {
|
|
40
|
+
if (this._value !== undefined) {
|
|
41
|
+
const d = this._value?.__toLiteral();
|
|
42
|
+
d['@type'] = this._originalTypeName; // send back the original type name instead of this._value?.__meta.typeName;
|
|
43
|
+
return d;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
__mapJsonToLiteral(data) {
|
|
49
|
+
if (data['@type'] === undefined) {
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.error(`@type is not defined: ${data['@type']}`, data);
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const originalTypeName = data['@type'];
|
|
55
|
+
// create a dummy object
|
|
56
|
+
const fn = Registry.createInstanceByTypeName(data['@type'].split('/').pop(), // typename
|
|
57
|
+
data, this, 'value');
|
|
58
|
+
const literal = fn.__mapJsonToLiteral(data);
|
|
59
|
+
literal['@type'] = originalTypeName;
|
|
60
|
+
return literal;
|
|
61
|
+
}
|
|
62
|
+
__updateWithLiteral(data) {
|
|
63
|
+
if (data['@type'] === undefined) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.error(`@type is not defined: ${data['@type']}`, data);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this._originalTypeName = data['@type'];
|
|
69
|
+
const typeName = data['@type'].split('/').pop();
|
|
70
|
+
if (typeName) {
|
|
71
|
+
this._typeName = typeName;
|
|
72
|
+
try {
|
|
73
|
+
this.value = Registry.createInstanceByTypeName(this._typeName, data, this, 'value');
|
|
74
|
+
this.value.__meta.isAnyNode = true;
|
|
75
|
+
this.__isEmpty = false;
|
|
76
|
+
this.__notifyFieldValueChange(false);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
// eslint-disable-next-line
|
|
80
|
+
console.error(err);
|
|
81
|
+
this.__isEmpty = true;
|
|
82
|
+
this.__notifyFieldValueChange(false);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
87
|
+
console.error(`Could not resolve type from empty type field: ${data['@type']}`, data);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=ANY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ANY.js","sourceRoot":"","sources":["../../src/well_known/ANY.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,MAAM,OAAO,GAAI,SAAQ,SAAS;I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,wBAAwB,CAC5C,IAAI,CAAC,SAAS,EACd,IAAI,EACJ,IAAI,EACJ,OAAO,CACR,CAAC;gBACF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;gBACnC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;gBACvB,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,2BAA2B;gBAC3B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,sCAAsC;YACtC,OAAO,CAAC,KAAK,CACX,iDAAiD,IAAI,CAAC,OAAO,CAAC,EAAE,EAChE,IAAI,CACL,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["// scalar and any typeName\nimport { FieldNode } from '../FieldNode';\nimport { Registry } from '../Registry';\n\nexport interface IAny {\n '@type': string;\n [key: string]: unknown;\n}\n\nexport class ANY extends FieldNode {\n private _value: FieldNode | undefined;\n\n private _typeName: string = '';\n\n private _originalTypeName: string = '';\n\n constructor(\n initData?: IAny,\n parent?: FieldNode,\n parentAttributeName?: string,\n ) {\n super(undefined, parent, parentAttributeName);\n this.__meta.typeName = `google.protobuf.Any`;\n }\n\n __clear() {\n this.__isEmpty = true;\n this._value = undefined;\n }\n\n // used by broadcast\n public get __childNodes(): FieldNode[] {\n if (this._value) {\n return [this._value];\n }\n return [];\n }\n\n get value() {\n return this._value;\n }\n\n set value(a: FieldNode | undefined) {\n this._value = a;\n }\n\n get typeName(): string {\n return this._typeName;\n }\n\n __toJson(): object | null {\n if (this._value !== undefined) {\n const d = this._value?.__toJson();\n d['@type'] = this._originalTypeName; // send back the original type name instead of this._value?.__meta.typeName;\n return d;\n }\n return null;\n }\n\n __toLiteral(): object | null {\n if (this._value !== undefined) {\n const d = this._value?.__toLiteral();\n d['@type'] = this._originalTypeName; // send back the original type name instead of this._value?.__meta.typeName;\n return d;\n }\n return null;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n __mapJsonToLiteral(data: any): any {\n if (data['@type'] === undefined) {\n // eslint-disable-next-line no-console\n console.error(`@type is not defined: ${data['@type']}`, data);\n return undefined;\n }\n\n const originalTypeName = data['@type'];\n // create a dummy object\n const fn = Registry.createInstanceByTypeName(\n data['@type'].split('/').pop(), // typename\n data,\n this,\n 'value',\n );\n\n const literal = fn.__mapJsonToLiteral(data);\n literal['@type'] = originalTypeName;\n\n return literal;\n }\n\n __updateWithLiteral(data: IAny) {\n if (data['@type'] === undefined) {\n // eslint-disable-next-line no-console\n console.error(`@type is not defined: ${data['@type']}`, data);\n return;\n }\n this._originalTypeName = data['@type'];\n const typeName = data['@type'].split('/').pop();\n if (typeName) {\n this._typeName = typeName;\n try {\n this.value = Registry.createInstanceByTypeName(\n this._typeName,\n data,\n this,\n 'value',\n );\n this.value.__meta.isAnyNode = true;\n this.__isEmpty = false;\n this.__notifyFieldValueChange(false);\n } catch (err) {\n // eslint-disable-next-line\n console.error(err);\n this.__isEmpty = true;\n this.__notifyFieldValueChange(false);\n }\n } else {\n // eslint-disable-next-line no-console\n console.error(\n `Could not resolve type from empty type field: ${data['@type']}`,\n data,\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
import { FieldConstraints } from '../FieldConstraints.js';
|
|
3
|
+
export declare class Int32Value extends FieldNode {
|
|
4
|
+
get value(): number | null;
|
|
5
|
+
set value(value: number | null);
|
|
6
|
+
_value: number | null;
|
|
7
|
+
constructor(initData?: number | null, parent?: FieldNode, parentAttributeName?: string);
|
|
8
|
+
__updateWithLiteral(v: number | null): void;
|
|
9
|
+
__mapJsonToLiteral(data: number): number;
|
|
10
|
+
__toJson(): number | null;
|
|
11
|
+
valueOf(): number;
|
|
12
|
+
__toLiteral(): number | null;
|
|
13
|
+
protected __checkTypeBoundaries(): string[] | undefined;
|
|
14
|
+
protected __checkConstraints(fieldConstraints: FieldConstraints): string[] | undefined;
|
|
15
|
+
toString(): string;
|
|
16
|
+
__clear(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
import { Registry } from '../Registry.js';
|
|
3
|
+
import { OPEN_MODELS_OPTIONS } from '../OPEN_MODELS_OPTIONS.js';
|
|
4
|
+
export class Int32Value extends FieldNode {
|
|
5
|
+
get value() {
|
|
6
|
+
return this._value;
|
|
7
|
+
}
|
|
8
|
+
set value(value) {
|
|
9
|
+
this._value = value;
|
|
10
|
+
if (OPEN_MODELS_OPTIONS.EmitDefaultValues ||
|
|
11
|
+
OPEN_MODELS_OPTIONS.EmitUnpopulated) {
|
|
12
|
+
this.__isEmpty = false;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.__isEmpty = value === null;
|
|
16
|
+
}
|
|
17
|
+
this.__climbUpValidation();
|
|
18
|
+
this.__notifyFieldValueChange(true);
|
|
19
|
+
}
|
|
20
|
+
constructor(initData, parent, parentAttributeName) {
|
|
21
|
+
super(undefined, parent, parentAttributeName);
|
|
22
|
+
this._value = null;
|
|
23
|
+
this.__isEmpty = !(OPEN_MODELS_OPTIONS.EmitDefaultValues ||
|
|
24
|
+
OPEN_MODELS_OPTIONS.EmitUnpopulated);
|
|
25
|
+
this._value = Number.isInteger(initData) ? initData : null;
|
|
26
|
+
this.__meta.typeName = 'google.protobuf.Int32Value';
|
|
27
|
+
}
|
|
28
|
+
__updateWithLiteral(v) {
|
|
29
|
+
this._value = v;
|
|
30
|
+
if (OPEN_MODELS_OPTIONS.EmitDefaultValues ||
|
|
31
|
+
OPEN_MODELS_OPTIONS.EmitUnpopulated) {
|
|
32
|
+
this.__isEmpty = false;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.__isEmpty = v === null;
|
|
36
|
+
}
|
|
37
|
+
this.__notifyFieldValueChange(false);
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line class-methods-use-this
|
|
40
|
+
__mapJsonToLiteral(data) {
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
__toJson() {
|
|
44
|
+
return this.__toLiteral();
|
|
45
|
+
}
|
|
46
|
+
valueOf() {
|
|
47
|
+
return this._value || NaN;
|
|
48
|
+
}
|
|
49
|
+
__toLiteral() {
|
|
50
|
+
return this._value;
|
|
51
|
+
}
|
|
52
|
+
__checkTypeBoundaries() {
|
|
53
|
+
// check for int32 min max boundaries
|
|
54
|
+
if (this._value && this._value > 2147483647) {
|
|
55
|
+
return ['constraint.violation.range.int32.max', '2147483647'];
|
|
56
|
+
}
|
|
57
|
+
if (this._value && this._value < -2147483648) {
|
|
58
|
+
return ['constraint.violation.range.int32.min', '-2147483648'];
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
__checkConstraints(fieldConstraints) {
|
|
63
|
+
// eslint-disable-next-line guard-for-in
|
|
64
|
+
for (const [constraint, value] of Object.entries(fieldConstraints)) {
|
|
65
|
+
if (constraint === 'maximum') {
|
|
66
|
+
// By default, the minimum and maximum values are included in the range. ">" is used to check.
|
|
67
|
+
if (fieldConstraints.exclusive_maximum &&
|
|
68
|
+
this._value !== null &&
|
|
69
|
+
this._value >= value) {
|
|
70
|
+
return ['constraint.violation.exclusive_maximum', value, this._value];
|
|
71
|
+
}
|
|
72
|
+
if (this._value !== null && this._value > value) {
|
|
73
|
+
return ['constraint.violation.maximum', value, this._value];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (constraint === 'minimum') {
|
|
77
|
+
// By default, the minimum and maximum values are included in the range. "<" is used to check.
|
|
78
|
+
if (fieldConstraints.exclusive_minimum &&
|
|
79
|
+
this._value !== null &&
|
|
80
|
+
this._value <= value) {
|
|
81
|
+
return ['constraint.violation.exclusive_minimum', value, this._value];
|
|
82
|
+
}
|
|
83
|
+
if (this._value !== null && this._value < value) {
|
|
84
|
+
return ['constraint.violation.minimum', value, this._value];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (constraint === 'multiple_of') {
|
|
88
|
+
// Use the multiple_of keyword to specify that a number must be the multiple of another number
|
|
89
|
+
// use this to define the step ??
|
|
90
|
+
if (this._value !== null && this._value % value !== 0) {
|
|
91
|
+
return ['constraint.violation.multiple_of', value, this._value];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (constraint === 'required') {
|
|
95
|
+
if (this._value === null) {
|
|
96
|
+
return ['constraint.violation.required'];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
toString() {
|
|
103
|
+
if (this._value !== null && !Number.isNaN(this._value)) {
|
|
104
|
+
return this._value.toString();
|
|
105
|
+
}
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
__clear() {
|
|
109
|
+
this._value = null;
|
|
110
|
+
this.__isEmpty = !(OPEN_MODELS_OPTIONS.EmitDefaultValues ||
|
|
111
|
+
OPEN_MODELS_OPTIONS.EmitUnpopulated);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
Registry.register('Int32Value', Int32Value);
|
|
115
|
+
//# sourceMappingURL=Int32Value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Int32Value.js","sourceRoot":"","sources":["../../src/well_known/Int32Value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,IAAI,KAAK;QACP,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AC,iBAAiB;YACrC,mBAAmB,CAAC,eAAe,CACpC,CAAC;IACJ,CAAC;CACF;AAED,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC","sourcesContent":["import { FieldNode } from '../FieldNode';\nimport { Registry } from '../Registry';\nimport { FieldConstraints } from '../FieldConstraints';\nimport { OPEN_MODELS_OPTIONS } from '../OPEN_MODELS_OPTIONS';\n\nexport class Int32Value extends FieldNode {\n get value(): number | null {\n return this._value;\n }\n\n set value(value: number | null) {\n this._value = value;\n if (\n OPEN_MODELS_OPTIONS.EmitDefaultValues ||\n OPEN_MODELS_OPTIONS.EmitUnpopulated\n ) {\n this.__isEmpty = false;\n } else {\n this.__isEmpty = value === null;\n }\n\n this.__climbUpValidation();\n this.__notifyFieldValueChange(true);\n }\n\n public _value: number | null = null;\n\n constructor(\n initData?: number | null,\n parent?: FieldNode,\n parentAttributeName?: string,\n ) {\n super(undefined, parent, parentAttributeName);\n\n this.__isEmpty = !(\n OPEN_MODELS_OPTIONS.EmitDefaultValues ||\n OPEN_MODELS_OPTIONS.EmitUnpopulated\n );\n this._value = Number.isInteger(initData) ? (initData as number) : null;\n this.__meta.typeName = 'google.protobuf.Int32Value';\n }\n\n __updateWithLiteral(v: number | null) {\n this._value = v;\n if (\n OPEN_MODELS_OPTIONS.EmitDefaultValues ||\n OPEN_MODELS_OPTIONS.EmitUnpopulated\n ) {\n this.__isEmpty = false;\n } else {\n this.__isEmpty = v === null;\n }\n this.__notifyFieldValueChange(false);\n }\n\n // eslint-disable-next-line class-methods-use-this\n __mapJsonToLiteral(data: number): number {\n return data;\n }\n\n __toJson(): number | null {\n return this.__toLiteral();\n }\n\n valueOf(): number {\n return this._value || NaN;\n }\n\n __toLiteral() {\n return this._value;\n }\n\n protected __checkTypeBoundaries(): string[] | undefined {\n // check for int32 min max boundaries\n if (this._value && this._value > 2147483647) {\n return ['constraint.violation.range.int32.max', '2147483647'];\n }\n if (this._value && this._value < -2147483648) {\n return ['constraint.violation.range.int32.min', '-2147483648'];\n }\n return undefined;\n }\n\n protected __checkConstraints(\n fieldConstraints: FieldConstraints,\n ): string[] | undefined {\n // eslint-disable-next-line guard-for-in\n for (const [constraint, value] of Object.entries(fieldConstraints)) {\n if (constraint === 'maximum') {\n // By default, the minimum and maximum values are included in the range. \">\" is used to check.\n if (\n fieldConstraints.exclusive_maximum &&\n this._value !== null &&\n this._value >= value\n ) {\n return ['constraint.violation.exclusive_maximum', value, this._value];\n }\n if (this._value !== null && this._value > value) {\n return ['constraint.violation.maximum', value, this._value];\n }\n }\n if (constraint === 'minimum') {\n // By default, the minimum and maximum values are included in the range. \"<\" is used to check.\n if (\n fieldConstraints.exclusive_minimum &&\n this._value !== null &&\n this._value <= value\n ) {\n return ['constraint.violation.exclusive_minimum', value, this._value];\n }\n if (this._value !== null && this._value < value) {\n return ['constraint.violation.minimum', value, this._value];\n }\n }\n if (constraint === 'multiple_of') {\n // Use the multiple_of keyword to specify that a number must be the multiple of another number\n // use this to define the step ??\n if (this._value !== null && this._value % value !== 0) {\n return ['constraint.violation.multiple_of', value, this._value];\n }\n }\n if (constraint === 'required') {\n if (this._value === null) {\n return ['constraint.violation.required'];\n }\n }\n }\n\n return undefined;\n }\n\n toString(): string {\n if (this._value !== null && !Number.isNaN(this._value)) {\n return this._value.toString();\n }\n return '';\n }\n\n __clear() {\n this._value = null;\n this.__isEmpty = !(\n OPEN_MODELS_OPTIONS.EmitDefaultValues ||\n OPEN_MODELS_OPTIONS.EmitUnpopulated\n );\n }\n}\n\nRegistry.register('Int32Value', Int32Value);\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FieldNode } from '../FieldNode.js';
|
|
2
|
+
import { FieldConstraints } from '../FieldConstraints.js';
|
|
3
|
+
export declare class Int64Value extends FieldNode {
|
|
4
|
+
get value(): number | null;
|
|
5
|
+
set value(value: number | null);
|
|
6
|
+
_value: number | null;
|
|
7
|
+
constructor(initData?: number | null, parent?: FieldNode, parentAttributeName?: string);
|
|
8
|
+
__updateWithLiteral(v: number | null): void;
|
|
9
|
+
__mapJsonToLiteral(data: number): number;
|
|
10
|
+
__toJson(): number | null;
|
|
11
|
+
valueOf(): number;
|
|
12
|
+
__toLiteral(): number | null;
|
|
13
|
+
protected __checkConstraints(fieldConstraints: FieldConstraints): string[] | undefined;
|
|
14
|
+
toString(): string;
|
|
15
|
+
__clear(): void;
|
|
16
|
+
}
|