@zlink-systems/stream-connector 0.30.0 → 0.30.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 +201 -104
- package/dist/browser/index.global.js +341 -17
- package/dist/browser/index.mjs +338 -17
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,105 +1,202 @@
|
|
|
1
|
-
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -787,8 +787,327 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
|
|
790
|
+
// packages/stream-wire/src/internal/framework-json-v1.ts
|
|
791
|
+
var SIGNED_64_MIN = -(1n << 63n);
|
|
792
|
+
var UNSIGNED_64_MAX = (1n << 64n) - 1n;
|
|
793
|
+
function stringifyFrameworkJsonV1(value, schema, replacer) {
|
|
794
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
|
|
795
|
+
throw new TypeError("framework-json-v1 payload is not a JSON value.");
|
|
796
|
+
}
|
|
797
|
+
const encoded = JSON.stringify(
|
|
798
|
+
value,
|
|
799
|
+
replacer === void 0 ? frameworkJsonV1Replacer : function(key, item) {
|
|
800
|
+
const transformed = replacer.call(this, key, item);
|
|
801
|
+
return frameworkJsonV1Replacer.call({ [key]: transformed }, key, transformed);
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
if (schema !== void 0) {
|
|
805
|
+
validateFrameworkJsonV1Value(JSON.parse(encoded), schema, "$", false);
|
|
806
|
+
}
|
|
807
|
+
return encoded;
|
|
808
|
+
}
|
|
809
|
+
function frameworkJsonV1Replacer(key, item) {
|
|
810
|
+
const source = this[key];
|
|
811
|
+
if (typeof source === "number" && !Number.isFinite(source)) {
|
|
812
|
+
throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
|
|
813
|
+
}
|
|
814
|
+
if (typeof source === "bigint") {
|
|
815
|
+
if (source < SIGNED_64_MIN || source > UNSIGNED_64_MAX) {
|
|
816
|
+
throw new RangeError("framework-json-v1 64-bit integer is outside the supported range.");
|
|
817
|
+
}
|
|
818
|
+
return source.toString(10);
|
|
819
|
+
}
|
|
820
|
+
if (source instanceof Uint8Array) {
|
|
821
|
+
return encodeBase64(source);
|
|
822
|
+
}
|
|
823
|
+
if (source instanceof Date) {
|
|
824
|
+
throw new TypeError("framework-json-v1 does not implicitly encode Date values.");
|
|
825
|
+
}
|
|
826
|
+
if (typeof source === "object" && source !== null && typeof source.toJSON === "function") {
|
|
827
|
+
throw new TypeError("framework-json-v1 does not implicitly invoke custom toJSON methods.");
|
|
828
|
+
}
|
|
829
|
+
return item;
|
|
830
|
+
}
|
|
831
|
+
function parseFrameworkJsonV1(text, options = {}, schema, reviver) {
|
|
832
|
+
if (text.charCodeAt(0) === 65279) {
|
|
833
|
+
throw new SyntaxError("framework-json-v1 does not allow a UTF-8 BOM.");
|
|
834
|
+
}
|
|
835
|
+
new JsonPropertyScanner(text, options).scan();
|
|
836
|
+
const parsed = JSON.parse(text, reviver);
|
|
837
|
+
return schema === void 0 ? parsed : validateFrameworkJsonV1Value(parsed, schema, "$", true);
|
|
838
|
+
}
|
|
839
|
+
var NUMBER_TOKEN_PATTERN = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/uy;
|
|
840
|
+
var BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
|
|
841
|
+
var INT32_MIN = -2147483648;
|
|
842
|
+
var INT32_MAX = 2147483647;
|
|
843
|
+
var UINT32_MAX2 = 4294967295;
|
|
844
|
+
function validateFrameworkJsonV1Value(value, schema, path, decode) {
|
|
845
|
+
switch (schema.type) {
|
|
846
|
+
case "boolean":
|
|
847
|
+
if (typeof value !== "boolean") schemaFailure(path, "a boolean");
|
|
848
|
+
return value;
|
|
849
|
+
case "string":
|
|
850
|
+
if (typeof value !== "string") schemaFailure(path, "a string");
|
|
851
|
+
return value;
|
|
852
|
+
case "number":
|
|
853
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
854
|
+
schemaFailure(path, "a finite number");
|
|
855
|
+
return value;
|
|
856
|
+
case "int32":
|
|
857
|
+
if (!Number.isInteger(value) || value < INT32_MIN || value > INT32_MAX) {
|
|
858
|
+
schemaFailure(path, "an int32 JSON number");
|
|
859
|
+
}
|
|
860
|
+
return value;
|
|
861
|
+
case "uint32":
|
|
862
|
+
if (!Number.isInteger(value) || value < 0 || value > UINT32_MAX2) {
|
|
863
|
+
schemaFailure(path, "a uint32 JSON number");
|
|
864
|
+
}
|
|
865
|
+
return value;
|
|
866
|
+
case "int64":
|
|
867
|
+
return validateDecimalInteger(value, path, true, decode);
|
|
868
|
+
case "uint64":
|
|
869
|
+
return validateDecimalInteger(value, path, false, decode);
|
|
870
|
+
case "bytes": {
|
|
871
|
+
if (typeof value !== "string" || !BASE64_PATTERN.test(value)) {
|
|
872
|
+
schemaFailure(path, "padded RFC 4648 base64");
|
|
873
|
+
}
|
|
874
|
+
const bytes = decodeBase64(value);
|
|
875
|
+
if (encodeBase64(bytes) !== value) schemaFailure(path, "canonical padded RFC 4648 base64");
|
|
876
|
+
return decode ? Uint8Array.from(bytes) : value;
|
|
877
|
+
}
|
|
878
|
+
case "enum":
|
|
879
|
+
if (typeof value !== "string" || !schema.names.includes(value)) {
|
|
880
|
+
schemaFailure(path, `one of ${schema.names.join(", ")}`);
|
|
881
|
+
}
|
|
882
|
+
return value;
|
|
883
|
+
case "nullable":
|
|
884
|
+
return value === null ? null : validateFrameworkJsonV1Value(value, schema.value, path, decode);
|
|
885
|
+
case "array":
|
|
886
|
+
if (!Array.isArray(value)) schemaFailure(path, "an array");
|
|
887
|
+
return value.map(
|
|
888
|
+
(item, index) => validateFrameworkJsonV1Value(item, schema.items, `${path}[${index}]`, decode)
|
|
889
|
+
);
|
|
890
|
+
case "record": {
|
|
891
|
+
if (!isJsonObject(value)) schemaFailure(path, "an object");
|
|
892
|
+
const result = {};
|
|
893
|
+
for (const [name, item] of Object.entries(value)) {
|
|
894
|
+
result[name] = validateFrameworkJsonV1Value(item, schema.values, `${path}.${name}`, decode);
|
|
895
|
+
}
|
|
896
|
+
return decode ? result : value;
|
|
897
|
+
}
|
|
898
|
+
case "object": {
|
|
899
|
+
if (!isJsonObject(value)) schemaFailure(path, "an object");
|
|
900
|
+
const input = value;
|
|
901
|
+
for (const name of schema.required) {
|
|
902
|
+
if (!Object.prototype.hasOwnProperty.call(input, name)) {
|
|
903
|
+
throw new TypeError(`framework-json-v1 required property '${path}.${name}' is missing.`);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
const result = {};
|
|
907
|
+
for (const [name, item] of Object.entries(input)) {
|
|
908
|
+
const propertySchema = schema.properties[name];
|
|
909
|
+
if (propertySchema === void 0) {
|
|
910
|
+
if (schema.additionalProperties === false) {
|
|
911
|
+
throw new TypeError(`framework-json-v1 property '${path}.${name}' is not allowed.`);
|
|
912
|
+
}
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
result[name] = validateFrameworkJsonV1Value(
|
|
916
|
+
item,
|
|
917
|
+
propertySchema,
|
|
918
|
+
`${path}.${name}`,
|
|
919
|
+
decode
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
return decode ? result : value;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
function validateDecimalInteger(value, path, signed, decode) {
|
|
927
|
+
if (typeof value !== "string" || !/^(?:0|[1-9][0-9]*|-[1-9][0-9]*)$/u.test(value)) {
|
|
928
|
+
schemaFailure(
|
|
929
|
+
path,
|
|
930
|
+
signed ? "a canonical int64 decimal string" : "a canonical uint64 decimal string"
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
const parsed = BigInt(value);
|
|
934
|
+
const minimum = signed ? SIGNED_64_MIN : 0n;
|
|
935
|
+
const maximum = signed ? (1n << 63n) - 1n : UNSIGNED_64_MAX;
|
|
936
|
+
if (parsed < minimum || parsed > maximum)
|
|
937
|
+
schemaFailure(path, signed ? "an int64 value" : "a uint64 value");
|
|
938
|
+
return decode ? parsed : value;
|
|
939
|
+
}
|
|
940
|
+
function isJsonObject(value) {
|
|
941
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
942
|
+
}
|
|
943
|
+
function schemaFailure(path, expected) {
|
|
944
|
+
throw new TypeError(`framework-json-v1 value '${path}' must be ${expected}.`);
|
|
945
|
+
}
|
|
946
|
+
var JsonPropertyScanner = class {
|
|
947
|
+
constructor(text, options) {
|
|
948
|
+
this.text = text;
|
|
949
|
+
this.options = options;
|
|
950
|
+
__publicField(this, "index", 0);
|
|
951
|
+
}
|
|
952
|
+
scan() {
|
|
953
|
+
this.skipWhitespace();
|
|
954
|
+
this.scanValue();
|
|
955
|
+
this.skipWhitespace();
|
|
956
|
+
if (this.index !== this.text.length) this.fail("trailing data");
|
|
957
|
+
}
|
|
958
|
+
scanValue() {
|
|
959
|
+
this.skipWhitespace();
|
|
960
|
+
const token = this.text[this.index];
|
|
961
|
+
if (token === "{") return this.scanObject();
|
|
962
|
+
if (token === "[") return this.scanArray();
|
|
963
|
+
if (token === '"') {
|
|
964
|
+
this.scanString();
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
if (token === "t") return this.scanLiteral("true");
|
|
968
|
+
if (token === "f") return this.scanLiteral("false");
|
|
969
|
+
if (token === "n") return this.scanLiteral("null");
|
|
970
|
+
this.scanNumber();
|
|
971
|
+
}
|
|
972
|
+
scanObject() {
|
|
973
|
+
var _a, _b;
|
|
974
|
+
this.index++;
|
|
975
|
+
this.skipWhitespace();
|
|
976
|
+
if (this.text[this.index] === "}") {
|
|
977
|
+
this.index++;
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const properties = /* @__PURE__ */ new Set();
|
|
981
|
+
for (; ; ) {
|
|
982
|
+
this.skipWhitespace();
|
|
983
|
+
if (this.text[this.index] !== '"') this.fail("object property name");
|
|
984
|
+
const property = this.scanString();
|
|
985
|
+
if (properties.has(property)) {
|
|
986
|
+
throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
|
|
987
|
+
}
|
|
988
|
+
properties.add(property);
|
|
989
|
+
if (((_b = (_a = this.options).rejectPropertyName) == null ? void 0 : _b.call(_a, property)) === true) {
|
|
990
|
+
throw new SyntaxError(`framework-json-v1 property '${property}' is not allowed.`);
|
|
991
|
+
}
|
|
992
|
+
this.skipWhitespace();
|
|
993
|
+
if (this.text[this.index] !== ":") this.fail("':' after object property");
|
|
994
|
+
this.index++;
|
|
995
|
+
this.scanValue();
|
|
996
|
+
this.skipWhitespace();
|
|
997
|
+
const delimiter = this.text[this.index++];
|
|
998
|
+
if (delimiter === "}") return;
|
|
999
|
+
if (delimiter !== ",") this.fail("',' or '}' after object property");
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
scanArray() {
|
|
1003
|
+
this.index++;
|
|
1004
|
+
this.skipWhitespace();
|
|
1005
|
+
if (this.text[this.index] === "]") {
|
|
1006
|
+
this.index++;
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
for (; ; ) {
|
|
1010
|
+
this.scanValue();
|
|
1011
|
+
this.skipWhitespace();
|
|
1012
|
+
const delimiter = this.text[this.index++];
|
|
1013
|
+
if (delimiter === "]") return;
|
|
1014
|
+
if (delimiter !== ",") this.fail("',' or ']' after array item");
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
scanString() {
|
|
1018
|
+
const start = this.index++;
|
|
1019
|
+
let sawEscape = false;
|
|
1020
|
+
for (; ; ) {
|
|
1021
|
+
if (this.index >= this.text.length) this.fail("unterminated string");
|
|
1022
|
+
const character = this.text[this.index++];
|
|
1023
|
+
if (character === '"') {
|
|
1024
|
+
return sawEscape ? JSON.parse(this.text.slice(start, this.index)) : this.text.slice(start + 1, this.index - 1);
|
|
1025
|
+
}
|
|
1026
|
+
if (character === "\\") {
|
|
1027
|
+
sawEscape = true;
|
|
1028
|
+
if (this.index >= this.text.length) this.fail("unterminated escape");
|
|
1029
|
+
const escaped = this.text[this.index++];
|
|
1030
|
+
if (escaped === "u") this.index += 4;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
scanLiteral(value) {
|
|
1035
|
+
if (!this.text.startsWith(value, this.index)) this.fail(value);
|
|
1036
|
+
this.index += value.length;
|
|
1037
|
+
}
|
|
1038
|
+
scanNumber() {
|
|
1039
|
+
NUMBER_TOKEN_PATTERN.lastIndex = this.index;
|
|
1040
|
+
const match = NUMBER_TOKEN_PATTERN.exec(this.text);
|
|
1041
|
+
if (match === null) this.fail("JSON value");
|
|
1042
|
+
if (!Number.isFinite(Number(match[0]))) {
|
|
1043
|
+
throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
|
|
1044
|
+
}
|
|
1045
|
+
this.index += match[0].length;
|
|
1046
|
+
}
|
|
1047
|
+
skipWhitespace() {
|
|
1048
|
+
for (; ; ) {
|
|
1049
|
+
const code = this.text.charCodeAt(this.index);
|
|
1050
|
+
if (code === 32 || code === 9 || code === 10 || code === 13) {
|
|
1051
|
+
this.index += 1;
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
fail(expected) {
|
|
1058
|
+
throw new SyntaxError(`framework-json-v1 expected ${expected} at offset ${this.index}.`);
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
var BASE64_STRING_CHUNK_BYTES = 8192;
|
|
1062
|
+
function encodeBase64(bytes) {
|
|
1063
|
+
let binary = "";
|
|
1064
|
+
for (let offset = 0; offset < bytes.length; offset += BASE64_STRING_CHUNK_BYTES) {
|
|
1065
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_STRING_CHUNK_BYTES));
|
|
1066
|
+
}
|
|
1067
|
+
return btoa(binary);
|
|
1068
|
+
}
|
|
1069
|
+
function decodeBase64(value) {
|
|
1070
|
+
const binary = atob(value);
|
|
1071
|
+
const bytes = new Uint8Array(binary.length);
|
|
1072
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
1073
|
+
return bytes;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// packages/stream-wire/src/internal/json-contract.ts
|
|
1077
|
+
var ZLINK_PACKET_JSON_CONTRACTS = Symbol.for("@zlink-systems/framework:packet-json-contracts");
|
|
1078
|
+
function isPrototypeKey(name) {
|
|
1079
|
+
return name === "__proto__" || name === "prototype" || name === "constructor";
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// packages/stream-wire/src/internal/packet-json-contract.ts
|
|
1083
|
+
var ZLINK_DECORATOR_METADATA = Symbol.for("@zlink-systems/framework:decorator");
|
|
1084
|
+
function readZLinkDecoratorMetadata(target) {
|
|
1085
|
+
if (!Object.prototype.hasOwnProperty.call(target, ZLINK_DECORATOR_METADATA)) {
|
|
1086
|
+
return [];
|
|
1087
|
+
}
|
|
1088
|
+
return target[ZLINK_DECORATOR_METADATA];
|
|
1089
|
+
}
|
|
1090
|
+
function readFrameworkPacketJsonContract(type, explicitPacketName) {
|
|
1091
|
+
const expectedPacketName = normalizePacketName(explicitPacketName);
|
|
1092
|
+
for (const metadata of readZLinkDecoratorMetadata(type)) {
|
|
1093
|
+
if (metadata.kind === "packet" && metadata.jsonContract !== void 0 && (expectedPacketName === void 0 || normalizePacketName(metadata.packetName) === expectedPacketName)) {
|
|
1094
|
+
return metadata.jsonContract;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
return void 0;
|
|
1098
|
+
}
|
|
1099
|
+
function normalizePacketName(value) {
|
|
1100
|
+
if (typeof value !== "string") {
|
|
1101
|
+
return void 0;
|
|
1102
|
+
}
|
|
1103
|
+
const trimmed = value.trim();
|
|
1104
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
790
1107
|
// packages/stream-connector/src/Contracts/ZlinkStreamJsonCodec.ts
|
|
791
1108
|
var zlinkStreamJsonCodecName = "json";
|
|
1109
|
+
var encoder = new TextEncoder();
|
|
1110
|
+
var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
792
1111
|
var codecOptions = {};
|
|
793
1112
|
var zlinkStreamJsonCodec = {
|
|
794
1113
|
configure(options) {
|
|
@@ -797,20 +1116,37 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
797
1116
|
encode(payload, messageType) {
|
|
798
1117
|
return toJson(payload, messageType);
|
|
799
1118
|
},
|
|
800
|
-
decode(payload) {
|
|
801
|
-
return
|
|
1119
|
+
decode(payload, messageType) {
|
|
1120
|
+
return decodeJson(payload, messageType != null ? messageType : payload.messageType);
|
|
802
1121
|
}
|
|
803
1122
|
};
|
|
804
1123
|
function toJson(value, messageType) {
|
|
1124
|
+
var _a;
|
|
1125
|
+
const type = messageType != null ? messageType : inferMessageType(value);
|
|
805
1126
|
return {
|
|
806
1127
|
codec: 1 /* Json */,
|
|
807
|
-
payload:
|
|
808
|
-
|
|
1128
|
+
payload: encoder.encode(
|
|
1129
|
+
stringifyFrameworkJsonV1(
|
|
1130
|
+
value,
|
|
1131
|
+
type === void 0 ? void 0 : (_a = readFrameworkPacketJsonContract(type)) == null ? void 0 : _a.payload,
|
|
1132
|
+
codecOptions.replacer
|
|
1133
|
+
)
|
|
1134
|
+
),
|
|
1135
|
+
messageType: type
|
|
809
1136
|
};
|
|
810
1137
|
}
|
|
811
1138
|
function fromJson(payload) {
|
|
1139
|
+
return decodeJson(payload, payload.messageType);
|
|
1140
|
+
}
|
|
1141
|
+
function decodeJson(payload, messageType) {
|
|
1142
|
+
var _a;
|
|
812
1143
|
ensureJson(payload);
|
|
813
|
-
return
|
|
1144
|
+
return parseFrameworkJsonV1(
|
|
1145
|
+
decoder.decode(payload.payload),
|
|
1146
|
+
{ rejectPropertyName: isPrototypeKey },
|
|
1147
|
+
messageType === void 0 ? void 0 : (_a = readFrameworkPacketJsonContract(messageType)) == null ? void 0 : _a.payload,
|
|
1148
|
+
codecOptions.reviver
|
|
1149
|
+
);
|
|
814
1150
|
}
|
|
815
1151
|
function ensureJson(payload) {
|
|
816
1152
|
if (payload.codec !== 1 /* Json */) {
|
|
@@ -825,18 +1161,6 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
825
1161
|
const constructor = (_a = Object.getPrototypeOf(value)) == null ? void 0 : _a.constructor;
|
|
826
1162
|
return constructor === Object ? void 0 : constructor;
|
|
827
1163
|
}
|
|
828
|
-
function safeJsonReviver(key, value) {
|
|
829
|
-
if (isPrototypeKey(key)) {
|
|
830
|
-
throw new Error(`JSON payload key '${key}' is not allowed.`);
|
|
831
|
-
}
|
|
832
|
-
if (codecOptions.reviver !== void 0) {
|
|
833
|
-
return codecOptions.reviver.call(this, key, value);
|
|
834
|
-
}
|
|
835
|
-
return value;
|
|
836
|
-
}
|
|
837
|
-
function isPrototypeKey(key) {
|
|
838
|
-
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
839
|
-
}
|
|
840
1164
|
|
|
841
1165
|
// packages/stream-connector/src/Runtime/ZlinkStreamSupport.ts
|
|
842
1166
|
var BACKING_ARRAY_COMPACTION_MIN_HEAD = 1024;
|
package/dist/browser/index.mjs
CHANGED
|
@@ -742,8 +742,326 @@ function validateMetadataKey(key) {
|
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
|
|
745
|
+
// packages/stream-wire/src/internal/framework-json-v1.ts
|
|
746
|
+
var SIGNED_64_MIN = -(1n << 63n);
|
|
747
|
+
var UNSIGNED_64_MAX = (1n << 64n) - 1n;
|
|
748
|
+
function stringifyFrameworkJsonV1(value, schema, replacer) {
|
|
749
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
|
|
750
|
+
throw new TypeError("framework-json-v1 payload is not a JSON value.");
|
|
751
|
+
}
|
|
752
|
+
const encoded = JSON.stringify(
|
|
753
|
+
value,
|
|
754
|
+
replacer === void 0 ? frameworkJsonV1Replacer : function(key, item) {
|
|
755
|
+
const transformed = replacer.call(this, key, item);
|
|
756
|
+
return frameworkJsonV1Replacer.call({ [key]: transformed }, key, transformed);
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
if (schema !== void 0) {
|
|
760
|
+
validateFrameworkJsonV1Value(JSON.parse(encoded), schema, "$", false);
|
|
761
|
+
}
|
|
762
|
+
return encoded;
|
|
763
|
+
}
|
|
764
|
+
function frameworkJsonV1Replacer(key, item) {
|
|
765
|
+
const source = this[key];
|
|
766
|
+
if (typeof source === "number" && !Number.isFinite(source)) {
|
|
767
|
+
throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
|
|
768
|
+
}
|
|
769
|
+
if (typeof source === "bigint") {
|
|
770
|
+
if (source < SIGNED_64_MIN || source > UNSIGNED_64_MAX) {
|
|
771
|
+
throw new RangeError("framework-json-v1 64-bit integer is outside the supported range.");
|
|
772
|
+
}
|
|
773
|
+
return source.toString(10);
|
|
774
|
+
}
|
|
775
|
+
if (source instanceof Uint8Array) {
|
|
776
|
+
return encodeBase64(source);
|
|
777
|
+
}
|
|
778
|
+
if (source instanceof Date) {
|
|
779
|
+
throw new TypeError("framework-json-v1 does not implicitly encode Date values.");
|
|
780
|
+
}
|
|
781
|
+
if (typeof source === "object" && source !== null && typeof source.toJSON === "function") {
|
|
782
|
+
throw new TypeError("framework-json-v1 does not implicitly invoke custom toJSON methods.");
|
|
783
|
+
}
|
|
784
|
+
return item;
|
|
785
|
+
}
|
|
786
|
+
function parseFrameworkJsonV1(text, options = {}, schema, reviver) {
|
|
787
|
+
if (text.charCodeAt(0) === 65279) {
|
|
788
|
+
throw new SyntaxError("framework-json-v1 does not allow a UTF-8 BOM.");
|
|
789
|
+
}
|
|
790
|
+
new JsonPropertyScanner(text, options).scan();
|
|
791
|
+
const parsed = JSON.parse(text, reviver);
|
|
792
|
+
return schema === void 0 ? parsed : validateFrameworkJsonV1Value(parsed, schema, "$", true);
|
|
793
|
+
}
|
|
794
|
+
var NUMBER_TOKEN_PATTERN = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/uy;
|
|
795
|
+
var BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
|
|
796
|
+
var INT32_MIN = -2147483648;
|
|
797
|
+
var INT32_MAX = 2147483647;
|
|
798
|
+
var UINT32_MAX2 = 4294967295;
|
|
799
|
+
function validateFrameworkJsonV1Value(value, schema, path, decode) {
|
|
800
|
+
switch (schema.type) {
|
|
801
|
+
case "boolean":
|
|
802
|
+
if (typeof value !== "boolean") schemaFailure(path, "a boolean");
|
|
803
|
+
return value;
|
|
804
|
+
case "string":
|
|
805
|
+
if (typeof value !== "string") schemaFailure(path, "a string");
|
|
806
|
+
return value;
|
|
807
|
+
case "number":
|
|
808
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
809
|
+
schemaFailure(path, "a finite number");
|
|
810
|
+
return value;
|
|
811
|
+
case "int32":
|
|
812
|
+
if (!Number.isInteger(value) || value < INT32_MIN || value > INT32_MAX) {
|
|
813
|
+
schemaFailure(path, "an int32 JSON number");
|
|
814
|
+
}
|
|
815
|
+
return value;
|
|
816
|
+
case "uint32":
|
|
817
|
+
if (!Number.isInteger(value) || value < 0 || value > UINT32_MAX2) {
|
|
818
|
+
schemaFailure(path, "a uint32 JSON number");
|
|
819
|
+
}
|
|
820
|
+
return value;
|
|
821
|
+
case "int64":
|
|
822
|
+
return validateDecimalInteger(value, path, true, decode);
|
|
823
|
+
case "uint64":
|
|
824
|
+
return validateDecimalInteger(value, path, false, decode);
|
|
825
|
+
case "bytes": {
|
|
826
|
+
if (typeof value !== "string" || !BASE64_PATTERN.test(value)) {
|
|
827
|
+
schemaFailure(path, "padded RFC 4648 base64");
|
|
828
|
+
}
|
|
829
|
+
const bytes = decodeBase64(value);
|
|
830
|
+
if (encodeBase64(bytes) !== value) schemaFailure(path, "canonical padded RFC 4648 base64");
|
|
831
|
+
return decode ? Uint8Array.from(bytes) : value;
|
|
832
|
+
}
|
|
833
|
+
case "enum":
|
|
834
|
+
if (typeof value !== "string" || !schema.names.includes(value)) {
|
|
835
|
+
schemaFailure(path, `one of ${schema.names.join(", ")}`);
|
|
836
|
+
}
|
|
837
|
+
return value;
|
|
838
|
+
case "nullable":
|
|
839
|
+
return value === null ? null : validateFrameworkJsonV1Value(value, schema.value, path, decode);
|
|
840
|
+
case "array":
|
|
841
|
+
if (!Array.isArray(value)) schemaFailure(path, "an array");
|
|
842
|
+
return value.map(
|
|
843
|
+
(item, index) => validateFrameworkJsonV1Value(item, schema.items, `${path}[${index}]`, decode)
|
|
844
|
+
);
|
|
845
|
+
case "record": {
|
|
846
|
+
if (!isJsonObject(value)) schemaFailure(path, "an object");
|
|
847
|
+
const result = {};
|
|
848
|
+
for (const [name, item] of Object.entries(value)) {
|
|
849
|
+
result[name] = validateFrameworkJsonV1Value(item, schema.values, `${path}.${name}`, decode);
|
|
850
|
+
}
|
|
851
|
+
return decode ? result : value;
|
|
852
|
+
}
|
|
853
|
+
case "object": {
|
|
854
|
+
if (!isJsonObject(value)) schemaFailure(path, "an object");
|
|
855
|
+
const input = value;
|
|
856
|
+
for (const name of schema.required) {
|
|
857
|
+
if (!Object.prototype.hasOwnProperty.call(input, name)) {
|
|
858
|
+
throw new TypeError(`framework-json-v1 required property '${path}.${name}' is missing.`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
const result = {};
|
|
862
|
+
for (const [name, item] of Object.entries(input)) {
|
|
863
|
+
const propertySchema = schema.properties[name];
|
|
864
|
+
if (propertySchema === void 0) {
|
|
865
|
+
if (schema.additionalProperties === false) {
|
|
866
|
+
throw new TypeError(`framework-json-v1 property '${path}.${name}' is not allowed.`);
|
|
867
|
+
}
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
result[name] = validateFrameworkJsonV1Value(
|
|
871
|
+
item,
|
|
872
|
+
propertySchema,
|
|
873
|
+
`${path}.${name}`,
|
|
874
|
+
decode
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
return decode ? result : value;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
function validateDecimalInteger(value, path, signed, decode) {
|
|
882
|
+
if (typeof value !== "string" || !/^(?:0|[1-9][0-9]*|-[1-9][0-9]*)$/u.test(value)) {
|
|
883
|
+
schemaFailure(
|
|
884
|
+
path,
|
|
885
|
+
signed ? "a canonical int64 decimal string" : "a canonical uint64 decimal string"
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
const parsed = BigInt(value);
|
|
889
|
+
const minimum = signed ? SIGNED_64_MIN : 0n;
|
|
890
|
+
const maximum = signed ? (1n << 63n) - 1n : UNSIGNED_64_MAX;
|
|
891
|
+
if (parsed < minimum || parsed > maximum)
|
|
892
|
+
schemaFailure(path, signed ? "an int64 value" : "a uint64 value");
|
|
893
|
+
return decode ? parsed : value;
|
|
894
|
+
}
|
|
895
|
+
function isJsonObject(value) {
|
|
896
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
897
|
+
}
|
|
898
|
+
function schemaFailure(path, expected) {
|
|
899
|
+
throw new TypeError(`framework-json-v1 value '${path}' must be ${expected}.`);
|
|
900
|
+
}
|
|
901
|
+
var JsonPropertyScanner = class {
|
|
902
|
+
constructor(text, options) {
|
|
903
|
+
this.text = text;
|
|
904
|
+
this.options = options;
|
|
905
|
+
}
|
|
906
|
+
index = 0;
|
|
907
|
+
scan() {
|
|
908
|
+
this.skipWhitespace();
|
|
909
|
+
this.scanValue();
|
|
910
|
+
this.skipWhitespace();
|
|
911
|
+
if (this.index !== this.text.length) this.fail("trailing data");
|
|
912
|
+
}
|
|
913
|
+
scanValue() {
|
|
914
|
+
this.skipWhitespace();
|
|
915
|
+
const token = this.text[this.index];
|
|
916
|
+
if (token === "{") return this.scanObject();
|
|
917
|
+
if (token === "[") return this.scanArray();
|
|
918
|
+
if (token === '"') {
|
|
919
|
+
this.scanString();
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (token === "t") return this.scanLiteral("true");
|
|
923
|
+
if (token === "f") return this.scanLiteral("false");
|
|
924
|
+
if (token === "n") return this.scanLiteral("null");
|
|
925
|
+
this.scanNumber();
|
|
926
|
+
}
|
|
927
|
+
scanObject() {
|
|
928
|
+
this.index++;
|
|
929
|
+
this.skipWhitespace();
|
|
930
|
+
if (this.text[this.index] === "}") {
|
|
931
|
+
this.index++;
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
const properties = /* @__PURE__ */ new Set();
|
|
935
|
+
for (; ; ) {
|
|
936
|
+
this.skipWhitespace();
|
|
937
|
+
if (this.text[this.index] !== '"') this.fail("object property name");
|
|
938
|
+
const property = this.scanString();
|
|
939
|
+
if (properties.has(property)) {
|
|
940
|
+
throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
|
|
941
|
+
}
|
|
942
|
+
properties.add(property);
|
|
943
|
+
if (this.options.rejectPropertyName?.(property) === true) {
|
|
944
|
+
throw new SyntaxError(`framework-json-v1 property '${property}' is not allowed.`);
|
|
945
|
+
}
|
|
946
|
+
this.skipWhitespace();
|
|
947
|
+
if (this.text[this.index] !== ":") this.fail("':' after object property");
|
|
948
|
+
this.index++;
|
|
949
|
+
this.scanValue();
|
|
950
|
+
this.skipWhitespace();
|
|
951
|
+
const delimiter = this.text[this.index++];
|
|
952
|
+
if (delimiter === "}") return;
|
|
953
|
+
if (delimiter !== ",") this.fail("',' or '}' after object property");
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
scanArray() {
|
|
957
|
+
this.index++;
|
|
958
|
+
this.skipWhitespace();
|
|
959
|
+
if (this.text[this.index] === "]") {
|
|
960
|
+
this.index++;
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
for (; ; ) {
|
|
964
|
+
this.scanValue();
|
|
965
|
+
this.skipWhitespace();
|
|
966
|
+
const delimiter = this.text[this.index++];
|
|
967
|
+
if (delimiter === "]") return;
|
|
968
|
+
if (delimiter !== ",") this.fail("',' or ']' after array item");
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
scanString() {
|
|
972
|
+
const start = this.index++;
|
|
973
|
+
let sawEscape = false;
|
|
974
|
+
for (; ; ) {
|
|
975
|
+
if (this.index >= this.text.length) this.fail("unterminated string");
|
|
976
|
+
const character = this.text[this.index++];
|
|
977
|
+
if (character === '"') {
|
|
978
|
+
return sawEscape ? JSON.parse(this.text.slice(start, this.index)) : this.text.slice(start + 1, this.index - 1);
|
|
979
|
+
}
|
|
980
|
+
if (character === "\\") {
|
|
981
|
+
sawEscape = true;
|
|
982
|
+
if (this.index >= this.text.length) this.fail("unterminated escape");
|
|
983
|
+
const escaped = this.text[this.index++];
|
|
984
|
+
if (escaped === "u") this.index += 4;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
scanLiteral(value) {
|
|
989
|
+
if (!this.text.startsWith(value, this.index)) this.fail(value);
|
|
990
|
+
this.index += value.length;
|
|
991
|
+
}
|
|
992
|
+
scanNumber() {
|
|
993
|
+
NUMBER_TOKEN_PATTERN.lastIndex = this.index;
|
|
994
|
+
const match = NUMBER_TOKEN_PATTERN.exec(this.text);
|
|
995
|
+
if (match === null) this.fail("JSON value");
|
|
996
|
+
if (!Number.isFinite(Number(match[0]))) {
|
|
997
|
+
throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
|
|
998
|
+
}
|
|
999
|
+
this.index += match[0].length;
|
|
1000
|
+
}
|
|
1001
|
+
skipWhitespace() {
|
|
1002
|
+
for (; ; ) {
|
|
1003
|
+
const code = this.text.charCodeAt(this.index);
|
|
1004
|
+
if (code === 32 || code === 9 || code === 10 || code === 13) {
|
|
1005
|
+
this.index += 1;
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
fail(expected) {
|
|
1012
|
+
throw new SyntaxError(`framework-json-v1 expected ${expected} at offset ${this.index}.`);
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
var BASE64_STRING_CHUNK_BYTES = 8192;
|
|
1016
|
+
function encodeBase64(bytes) {
|
|
1017
|
+
let binary = "";
|
|
1018
|
+
for (let offset = 0; offset < bytes.length; offset += BASE64_STRING_CHUNK_BYTES) {
|
|
1019
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_STRING_CHUNK_BYTES));
|
|
1020
|
+
}
|
|
1021
|
+
return btoa(binary);
|
|
1022
|
+
}
|
|
1023
|
+
function decodeBase64(value) {
|
|
1024
|
+
const binary = atob(value);
|
|
1025
|
+
const bytes = new Uint8Array(binary.length);
|
|
1026
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
1027
|
+
return bytes;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// packages/stream-wire/src/internal/json-contract.ts
|
|
1031
|
+
var ZLINK_PACKET_JSON_CONTRACTS = Symbol.for("@zlink-systems/framework:packet-json-contracts");
|
|
1032
|
+
function isPrototypeKey(name) {
|
|
1033
|
+
return name === "__proto__" || name === "prototype" || name === "constructor";
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// packages/stream-wire/src/internal/packet-json-contract.ts
|
|
1037
|
+
var ZLINK_DECORATOR_METADATA = Symbol.for("@zlink-systems/framework:decorator");
|
|
1038
|
+
function readZLinkDecoratorMetadata(target) {
|
|
1039
|
+
if (!Object.prototype.hasOwnProperty.call(target, ZLINK_DECORATOR_METADATA)) {
|
|
1040
|
+
return [];
|
|
1041
|
+
}
|
|
1042
|
+
return target[ZLINK_DECORATOR_METADATA];
|
|
1043
|
+
}
|
|
1044
|
+
function readFrameworkPacketJsonContract(type, explicitPacketName) {
|
|
1045
|
+
const expectedPacketName = normalizePacketName(explicitPacketName);
|
|
1046
|
+
for (const metadata of readZLinkDecoratorMetadata(type)) {
|
|
1047
|
+
if (metadata.kind === "packet" && metadata.jsonContract !== void 0 && (expectedPacketName === void 0 || normalizePacketName(metadata.packetName) === expectedPacketName)) {
|
|
1048
|
+
return metadata.jsonContract;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return void 0;
|
|
1052
|
+
}
|
|
1053
|
+
function normalizePacketName(value) {
|
|
1054
|
+
if (typeof value !== "string") {
|
|
1055
|
+
return void 0;
|
|
1056
|
+
}
|
|
1057
|
+
const trimmed = value.trim();
|
|
1058
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
745
1061
|
// packages/stream-connector/src/Contracts/ZlinkStreamJsonCodec.ts
|
|
746
1062
|
var zlinkStreamJsonCodecName = "json";
|
|
1063
|
+
var encoder = new TextEncoder();
|
|
1064
|
+
var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
747
1065
|
var codecOptions = {};
|
|
748
1066
|
var zlinkStreamJsonCodec = {
|
|
749
1067
|
configure(options) {
|
|
@@ -752,20 +1070,35 @@ var zlinkStreamJsonCodec = {
|
|
|
752
1070
|
encode(payload, messageType) {
|
|
753
1071
|
return toJson(payload, messageType);
|
|
754
1072
|
},
|
|
755
|
-
decode(payload) {
|
|
756
|
-
return
|
|
1073
|
+
decode(payload, messageType) {
|
|
1074
|
+
return decodeJson(payload, messageType ?? payload.messageType);
|
|
757
1075
|
}
|
|
758
1076
|
};
|
|
759
1077
|
function toJson(value, messageType) {
|
|
1078
|
+
const type = messageType ?? inferMessageType(value);
|
|
760
1079
|
return {
|
|
761
1080
|
codec: 1 /* Json */,
|
|
762
|
-
payload:
|
|
763
|
-
|
|
1081
|
+
payload: encoder.encode(
|
|
1082
|
+
stringifyFrameworkJsonV1(
|
|
1083
|
+
value,
|
|
1084
|
+
type === void 0 ? void 0 : readFrameworkPacketJsonContract(type)?.payload,
|
|
1085
|
+
codecOptions.replacer
|
|
1086
|
+
)
|
|
1087
|
+
),
|
|
1088
|
+
messageType: type
|
|
764
1089
|
};
|
|
765
1090
|
}
|
|
766
1091
|
function fromJson(payload) {
|
|
1092
|
+
return decodeJson(payload, payload.messageType);
|
|
1093
|
+
}
|
|
1094
|
+
function decodeJson(payload, messageType) {
|
|
767
1095
|
ensureJson(payload);
|
|
768
|
-
return
|
|
1096
|
+
return parseFrameworkJsonV1(
|
|
1097
|
+
decoder.decode(payload.payload),
|
|
1098
|
+
{ rejectPropertyName: isPrototypeKey },
|
|
1099
|
+
messageType === void 0 ? void 0 : readFrameworkPacketJsonContract(messageType)?.payload,
|
|
1100
|
+
codecOptions.reviver
|
|
1101
|
+
);
|
|
769
1102
|
}
|
|
770
1103
|
function ensureJson(payload) {
|
|
771
1104
|
if (payload.codec !== 1 /* Json */) {
|
|
@@ -779,18 +1112,6 @@ function inferMessageType(value) {
|
|
|
779
1112
|
const constructor = Object.getPrototypeOf(value)?.constructor;
|
|
780
1113
|
return constructor === Object ? void 0 : constructor;
|
|
781
1114
|
}
|
|
782
|
-
function safeJsonReviver(key, value) {
|
|
783
|
-
if (isPrototypeKey(key)) {
|
|
784
|
-
throw new Error(`JSON payload key '${key}' is not allowed.`);
|
|
785
|
-
}
|
|
786
|
-
if (codecOptions.reviver !== void 0) {
|
|
787
|
-
return codecOptions.reviver.call(this, key, value);
|
|
788
|
-
}
|
|
789
|
-
return value;
|
|
790
|
-
}
|
|
791
|
-
function isPrototypeKey(key) {
|
|
792
|
-
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
793
|
-
}
|
|
794
1115
|
|
|
795
1116
|
// packages/stream-connector/src/Runtime/ZlinkStreamSupport.ts
|
|
796
1117
|
var BACKING_ARRAY_COMPACTION_MIN_HEAD = 1024;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlink-systems/stream-connector",
|
|
3
|
-
"version": "0.30.
|
|
4
|
-
"license": "
|
|
3
|
+
"version": "0.30.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/zlink-systems/zlink.git",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@zlink-systems/stream-wire": "0.30.
|
|
25
|
+
"@zlink-systems/stream-wire": "0.30.1"
|
|
26
26
|
}
|
|
27
27
|
}
|