@psnext/slingcli 2.5.20260725-1 → 2.5.20260728-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/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +8 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +37 -35
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +11 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/error-body.js +8 -3
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-resolver.js +13 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/remote-catalog-provider.js +19 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js +3 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.js +4 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/extensions/llama/provider.js +6 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.js +10 -2
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js +22 -13
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +38 -27
- package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +12 -12
- package/node_modules/@earendil-works/pi-coding-agent/package.json +6 -5
- package/node_modules/@earendil-works/pi-server/package.json +2 -2
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +15 -13
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +2 -203
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeDeserializer.js +113 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeSerializer.js +95 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.js +609 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.js +611 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/index.js +3 -1
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/CborCodec.d.ts +3 -25
- package/node_modules/@smithy/core/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.d.ts +19 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.d.ts +22 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/index.d.ts +3 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +12 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +3 -25
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.d.ts +19 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.d.ts +22 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/index.d.ts +3 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +12 -0
- package/node_modules/@smithy/core/package.json +2 -1
- package/node_modules/@smithy/credential-provider-imds/package.json +2 -2
- package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
- package/node_modules/@smithy/signature-v4/package.json +2 -2
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/crypto.d.ts +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/package.json +7 -7
- package/slingshot/index.js +164 -164
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { cbor } from "./cbor";
|
|
5
|
-
import { dateToTag } from "./parseCborBody";
|
|
2
|
+
import { CborShapeSerializer } from "./codec-v1/CborShapeSerializer";
|
|
3
|
+
import { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer";
|
|
6
4
|
export class CborCodec extends SerdeContext {
|
|
7
5
|
createSerializer() {
|
|
8
6
|
const serializer = new CborShapeSerializer();
|
|
@@ -15,202 +13,3 @@ export class CborCodec extends SerdeContext {
|
|
|
15
13
|
return deserializer;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
|
-
export class CborShapeSerializer extends SerdeContext {
|
|
19
|
-
value;
|
|
20
|
-
write(schema, value) {
|
|
21
|
-
this.value = this.serialize(schema, value);
|
|
22
|
-
}
|
|
23
|
-
serialize(schema, source) {
|
|
24
|
-
const ns = NormalizedSchema.of(schema);
|
|
25
|
-
if (source == null) {
|
|
26
|
-
if (ns.isIdempotencyToken()) {
|
|
27
|
-
return generateIdempotencyToken();
|
|
28
|
-
}
|
|
29
|
-
return source;
|
|
30
|
-
}
|
|
31
|
-
if (ns.isBlobSchema()) {
|
|
32
|
-
if (typeof source === "string") {
|
|
33
|
-
return (this.serdeContext?.base64Decoder ?? fromBase64)(source);
|
|
34
|
-
}
|
|
35
|
-
return source;
|
|
36
|
-
}
|
|
37
|
-
if (ns.isTimestampSchema()) {
|
|
38
|
-
if (typeof source === "number" || typeof source === "bigint") {
|
|
39
|
-
return dateToTag(new Date((Number(source) / 1000) | 0));
|
|
40
|
-
}
|
|
41
|
-
return dateToTag(source);
|
|
42
|
-
}
|
|
43
|
-
if (typeof source === "function" || typeof source === "object") {
|
|
44
|
-
const sourceObject = source;
|
|
45
|
-
if (ns.isListSchema() && Array.isArray(sourceObject)) {
|
|
46
|
-
const sparse = !!ns.getMergedTraits().sparse;
|
|
47
|
-
const newArray = [];
|
|
48
|
-
let i = 0;
|
|
49
|
-
for (const item of sourceObject) {
|
|
50
|
-
const value = this.serialize(ns.getValueSchema(), item);
|
|
51
|
-
if (value != null || sparse) {
|
|
52
|
-
newArray[i++] = value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return newArray;
|
|
56
|
-
}
|
|
57
|
-
if (sourceObject instanceof Date) {
|
|
58
|
-
return dateToTag(sourceObject);
|
|
59
|
-
}
|
|
60
|
-
const newObject = {};
|
|
61
|
-
if (ns.isMapSchema()) {
|
|
62
|
-
const sparse = !!ns.getMergedTraits().sparse;
|
|
63
|
-
for (const key in sourceObject) {
|
|
64
|
-
const value = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
65
|
-
if (value != null || sparse) {
|
|
66
|
-
newObject[key] = value;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (ns.isStructSchema()) {
|
|
71
|
-
for (const [key, memberSchema] of ns.structIterator()) {
|
|
72
|
-
const value = this.serialize(memberSchema, sourceObject[key]);
|
|
73
|
-
if (value != null) {
|
|
74
|
-
newObject[key] = value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const isUnion = ns.isUnionSchema();
|
|
78
|
-
if (isUnion && Array.isArray(sourceObject.$unknown)) {
|
|
79
|
-
const [k, v] = sourceObject.$unknown;
|
|
80
|
-
newObject[k] = v;
|
|
81
|
-
}
|
|
82
|
-
else if (typeof sourceObject.__type === "string") {
|
|
83
|
-
for (const k in sourceObject) {
|
|
84
|
-
if (!(k in newObject)) {
|
|
85
|
-
newObject[k] = this.serialize(15, sourceObject[k]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (ns.isDocumentSchema()) {
|
|
91
|
-
for (const key in sourceObject) {
|
|
92
|
-
newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (ns.isBigDecimalSchema()) {
|
|
96
|
-
return sourceObject;
|
|
97
|
-
}
|
|
98
|
-
return newObject;
|
|
99
|
-
}
|
|
100
|
-
return source;
|
|
101
|
-
}
|
|
102
|
-
flush() {
|
|
103
|
-
const buffer = cbor.serialize(this.value);
|
|
104
|
-
this.value = undefined;
|
|
105
|
-
return buffer;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export class CborShapeDeserializer extends SerdeContext {
|
|
109
|
-
read(schema, bytes) {
|
|
110
|
-
const data = cbor.deserialize(bytes);
|
|
111
|
-
return this.readValue(schema, data);
|
|
112
|
-
}
|
|
113
|
-
readValue(_schema, value) {
|
|
114
|
-
const ns = NormalizedSchema.of(_schema);
|
|
115
|
-
if (ns.isTimestampSchema()) {
|
|
116
|
-
if (typeof value === "number") {
|
|
117
|
-
return _parseEpochTimestamp(value);
|
|
118
|
-
}
|
|
119
|
-
if (typeof value === "object") {
|
|
120
|
-
if (value.tag === 1 && "value" in value) {
|
|
121
|
-
return _parseEpochTimestamp(value.value);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (ns.isBlobSchema()) {
|
|
126
|
-
if (typeof value === "string") {
|
|
127
|
-
return (this.serdeContext?.base64Decoder ?? fromBase64)(value);
|
|
128
|
-
}
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
if (typeof value === "undefined" ||
|
|
132
|
-
typeof value === "boolean" ||
|
|
133
|
-
typeof value === "number" ||
|
|
134
|
-
typeof value === "string" ||
|
|
135
|
-
typeof value === "bigint" ||
|
|
136
|
-
typeof value === "symbol") {
|
|
137
|
-
return value;
|
|
138
|
-
}
|
|
139
|
-
else if (typeof value === "object") {
|
|
140
|
-
if (value === null) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
if ("byteLength" in value) {
|
|
144
|
-
return value;
|
|
145
|
-
}
|
|
146
|
-
if (value instanceof Date) {
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
if (ns.isDocumentSchema()) {
|
|
150
|
-
return value;
|
|
151
|
-
}
|
|
152
|
-
if (ns.isListSchema()) {
|
|
153
|
-
const newArray = [];
|
|
154
|
-
const memberSchema = ns.getValueSchema();
|
|
155
|
-
for (const item of value) {
|
|
156
|
-
const itemValue = this.readValue(memberSchema, item);
|
|
157
|
-
newArray.push(itemValue);
|
|
158
|
-
}
|
|
159
|
-
return newArray;
|
|
160
|
-
}
|
|
161
|
-
const newObject = {};
|
|
162
|
-
if (ns.isMapSchema()) {
|
|
163
|
-
const targetSchema = ns.getValueSchema();
|
|
164
|
-
for (const key in value) {
|
|
165
|
-
const itemValue = this.readValue(targetSchema, value[key]);
|
|
166
|
-
newObject[key] = itemValue;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (ns.isStructSchema()) {
|
|
170
|
-
const isUnion = ns.isUnionSchema();
|
|
171
|
-
let keys;
|
|
172
|
-
if (isUnion) {
|
|
173
|
-
keys = new Set();
|
|
174
|
-
for (const k in value) {
|
|
175
|
-
if (k !== "__type") {
|
|
176
|
-
keys.add(k);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
for (const [key, memberSchema] of ns.structIterator()) {
|
|
181
|
-
if (isUnion) {
|
|
182
|
-
keys.delete(key);
|
|
183
|
-
}
|
|
184
|
-
if (value[key] != null) {
|
|
185
|
-
newObject[key] = this.readValue(memberSchema, value[key]);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (isUnion && keys?.size === 1) {
|
|
189
|
-
let newObjectEmpty = true;
|
|
190
|
-
for (const _ in newObject) {
|
|
191
|
-
newObjectEmpty = false;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
if (newObjectEmpty) {
|
|
195
|
-
const k = keys.values().next().value;
|
|
196
|
-
newObject.$unknown = [k, value[k]];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
else if (typeof value.__type === "string") {
|
|
200
|
-
for (const k in value) {
|
|
201
|
-
if (!(k in newObject)) {
|
|
202
|
-
newObject[k] = value[k];
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else if (value instanceof NumericValue) {
|
|
208
|
-
return value;
|
|
209
|
-
}
|
|
210
|
-
return newObject;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
return value;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
+
import { NumericValue, _parseEpochTimestamp, fromBase64 } from "@smithy/core/serde";
|
|
4
|
+
import { cbor } from "../cbor";
|
|
5
|
+
export class CborShapeDeserializer extends SerdeContext {
|
|
6
|
+
read(schema, bytes) {
|
|
7
|
+
const data = cbor.deserialize(bytes);
|
|
8
|
+
return this.readValue(schema, data);
|
|
9
|
+
}
|
|
10
|
+
readValue(_schema, value) {
|
|
11
|
+
const ns = NormalizedSchema.of(_schema);
|
|
12
|
+
if (ns.isTimestampSchema()) {
|
|
13
|
+
if (typeof value === "number") {
|
|
14
|
+
return _parseEpochTimestamp(value);
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "object") {
|
|
17
|
+
if (value.tag === 1 && "value" in value) {
|
|
18
|
+
return _parseEpochTimestamp(value.value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (ns.isBlobSchema()) {
|
|
23
|
+
if (typeof value === "string") {
|
|
24
|
+
return (this.serdeContext?.base64Decoder ?? fromBase64)(value);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === "undefined" ||
|
|
29
|
+
typeof value === "boolean" ||
|
|
30
|
+
typeof value === "number" ||
|
|
31
|
+
typeof value === "string" ||
|
|
32
|
+
typeof value === "bigint" ||
|
|
33
|
+
typeof value === "symbol") {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
else if (typeof value === "object") {
|
|
37
|
+
if (value === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if ("byteLength" in value) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (value instanceof Date) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
if (ns.isDocumentSchema()) {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
if (ns.isListSchema()) {
|
|
50
|
+
const newArray = [];
|
|
51
|
+
const memberSchema = ns.getValueSchema();
|
|
52
|
+
for (const item of value) {
|
|
53
|
+
const itemValue = this.readValue(memberSchema, item);
|
|
54
|
+
newArray.push(itemValue);
|
|
55
|
+
}
|
|
56
|
+
return newArray;
|
|
57
|
+
}
|
|
58
|
+
const newObject = {};
|
|
59
|
+
if (ns.isMapSchema()) {
|
|
60
|
+
const targetSchema = ns.getValueSchema();
|
|
61
|
+
for (const key in value) {
|
|
62
|
+
const itemValue = this.readValue(targetSchema, value[key]);
|
|
63
|
+
newObject[key] = itemValue;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (ns.isStructSchema()) {
|
|
67
|
+
const isUnion = ns.isUnionSchema();
|
|
68
|
+
let keys;
|
|
69
|
+
if (isUnion) {
|
|
70
|
+
keys = new Set();
|
|
71
|
+
for (const k in value) {
|
|
72
|
+
if (k !== "__type") {
|
|
73
|
+
keys.add(k);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const [key, memberSchema] of ns.structIterator()) {
|
|
78
|
+
if (isUnion) {
|
|
79
|
+
keys.delete(key);
|
|
80
|
+
}
|
|
81
|
+
if (value[key] != null) {
|
|
82
|
+
newObject[key] = this.readValue(memberSchema, value[key]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (isUnion && keys?.size === 1) {
|
|
86
|
+
let newObjectEmpty = true;
|
|
87
|
+
for (const _ in newObject) {
|
|
88
|
+
newObjectEmpty = false;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (newObjectEmpty) {
|
|
92
|
+
const k = keys.values().next().value;
|
|
93
|
+
newObject.$unknown = [k, value[k]];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (typeof value.__type === "string") {
|
|
97
|
+
for (const k in value) {
|
|
98
|
+
if (!(k in newObject)) {
|
|
99
|
+
newObject[k] = value[k];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (value instanceof NumericValue) {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
return newObject;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
+
import { fromBase64, generateIdempotencyToken } from "@smithy/core/serde";
|
|
4
|
+
import { cbor } from "../cbor";
|
|
5
|
+
import { dateToTag } from "../parseCborBody";
|
|
6
|
+
export class CborShapeSerializer extends SerdeContext {
|
|
7
|
+
value;
|
|
8
|
+
write(schema, value) {
|
|
9
|
+
this.value = this.serialize(schema, value);
|
|
10
|
+
}
|
|
11
|
+
serialize(schema, source) {
|
|
12
|
+
const ns = NormalizedSchema.of(schema);
|
|
13
|
+
if (source == null) {
|
|
14
|
+
if (ns.isIdempotencyToken()) {
|
|
15
|
+
return generateIdempotencyToken();
|
|
16
|
+
}
|
|
17
|
+
return source;
|
|
18
|
+
}
|
|
19
|
+
if (ns.isBlobSchema()) {
|
|
20
|
+
if (typeof source === "string") {
|
|
21
|
+
return (this.serdeContext?.base64Decoder ?? fromBase64)(source);
|
|
22
|
+
}
|
|
23
|
+
return source;
|
|
24
|
+
}
|
|
25
|
+
if (ns.isTimestampSchema()) {
|
|
26
|
+
if (typeof source === "number" || typeof source === "bigint") {
|
|
27
|
+
return dateToTag(new Date((Number(source) / 1000) | 0));
|
|
28
|
+
}
|
|
29
|
+
return dateToTag(source);
|
|
30
|
+
}
|
|
31
|
+
if (typeof source === "function" || typeof source === "object") {
|
|
32
|
+
const sourceObject = source;
|
|
33
|
+
if (ns.isListSchema() && Array.isArray(sourceObject)) {
|
|
34
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
35
|
+
const newArray = [];
|
|
36
|
+
let i = 0;
|
|
37
|
+
for (const item of sourceObject) {
|
|
38
|
+
const value = this.serialize(ns.getValueSchema(), item);
|
|
39
|
+
if (value != null || sparse) {
|
|
40
|
+
newArray[i++] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return newArray;
|
|
44
|
+
}
|
|
45
|
+
if (sourceObject instanceof Date) {
|
|
46
|
+
return dateToTag(sourceObject);
|
|
47
|
+
}
|
|
48
|
+
const newObject = {};
|
|
49
|
+
if (ns.isMapSchema()) {
|
|
50
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
51
|
+
for (const key in sourceObject) {
|
|
52
|
+
const value = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
53
|
+
if (value != null || sparse) {
|
|
54
|
+
newObject[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (ns.isStructSchema()) {
|
|
59
|
+
for (const [key, memberSchema] of ns.structIterator()) {
|
|
60
|
+
const value = this.serialize(memberSchema, sourceObject[key]);
|
|
61
|
+
if (value != null) {
|
|
62
|
+
newObject[key] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const isUnion = ns.isUnionSchema();
|
|
66
|
+
if (isUnion && Array.isArray(sourceObject.$unknown)) {
|
|
67
|
+
const [k, v] = sourceObject.$unknown;
|
|
68
|
+
newObject[k] = v;
|
|
69
|
+
}
|
|
70
|
+
else if (typeof sourceObject.__type === "string") {
|
|
71
|
+
for (const k in sourceObject) {
|
|
72
|
+
if (!(k in newObject)) {
|
|
73
|
+
newObject[k] = this.serialize(15, sourceObject[k]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (ns.isDocumentSchema()) {
|
|
79
|
+
for (const key in sourceObject) {
|
|
80
|
+
newObject[key] = this.serialize(ns.getValueSchema(), sourceObject[key]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (ns.isBigDecimalSchema()) {
|
|
84
|
+
return sourceObject;
|
|
85
|
+
}
|
|
86
|
+
return newObject;
|
|
87
|
+
}
|
|
88
|
+
return source;
|
|
89
|
+
}
|
|
90
|
+
flush() {
|
|
91
|
+
const buffer = cbor.serialize(this.value);
|
|
92
|
+
this.value = undefined;
|
|
93
|
+
return buffer;
|
|
94
|
+
}
|
|
95
|
+
}
|