@aneuhold/core-ts-api-lib 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/services/DOFunctionService/DOFunction.d.ts +3 -3
- package/lib/services/DOFunctionService/DOFunction.d.ts.map +1 -1
- package/lib/services/DOFunctionService/DOFunction.js +16 -8
- package/lib/services/DOFunctionService/DOFunction.js.map +1 -1
- package/lib/services/DOFunctionService/DOFunction.ts +15 -10
- package/package.json +1 -1
|
@@ -82,11 +82,11 @@ export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput
|
|
|
82
82
|
*/
|
|
83
83
|
call(input: TInput): Promise<DOFunctionCallOutput<TOutput>>;
|
|
84
84
|
/**
|
|
85
|
-
* Decodes an {@link
|
|
85
|
+
* Decodes an {@link Response} into a {@link DOFunctionCallOutput}.
|
|
86
86
|
*
|
|
87
|
-
* @param
|
|
87
|
+
* @param responseText - The response to decode.
|
|
88
88
|
* @returns The decoded output.
|
|
89
89
|
*/
|
|
90
|
-
private
|
|
90
|
+
private decodeResponse;
|
|
91
91
|
}
|
|
92
92
|
//# sourceMappingURL=DOFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunction.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,EAAE;QACJ;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,cAAc,EAAE,0BAA0B,CAAC;KAC5C,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,gBAAgB;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CACtC,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB;IAEhC;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS;IAIT;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB;;;;;;;;OAQG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"DOFunction.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,EAAE;QACJ;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,cAAc,EAAE,0BAA0B,CAAC;KAC5C,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,gBAAgB;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CACtC,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB;IAEhC;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS;IAIT;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB;;;;;;;;OAQG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAkBjE;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CASvB"}
|
|
@@ -39,26 +39,34 @@ export default class DOFunction {
|
|
|
39
39
|
if (!this.url) {
|
|
40
40
|
throw new Error(`${this.functionName} URL is not set`);
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const serializedInput = BSON.serialize(input);
|
|
43
|
+
const base64Input = Buffer.from(serializedInput).toString('base64');
|
|
44
|
+
const response = await fetch(this.url, {
|
|
43
45
|
method: 'POST',
|
|
44
46
|
headers: {
|
|
45
47
|
'Content-Type': 'application/octet-stream'
|
|
46
48
|
},
|
|
47
49
|
// It isn't clear why this works by itself. It comes in to the function
|
|
48
50
|
// as a base64 string.
|
|
49
|
-
body:
|
|
51
|
+
body: base64Input
|
|
50
52
|
});
|
|
51
|
-
return this.
|
|
53
|
+
return this.decodeResponse(await response.text());
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
|
-
* Decodes an {@link
|
|
56
|
+
* Decodes an {@link Response} into a {@link DOFunctionCallOutput}.
|
|
55
57
|
*
|
|
56
|
-
* @param
|
|
58
|
+
* @param responseText - The response to decode.
|
|
57
59
|
* @returns The decoded output.
|
|
58
60
|
*/
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
decodeResponse(responseText) {
|
|
62
|
+
const buffer = Buffer.from(responseText, 'base64');
|
|
63
|
+
try {
|
|
64
|
+
return BSON.deserialize(buffer);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('Deserialization error:', error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
//# sourceMappingURL=DOFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunction.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAyD5B;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAItC;;OAEG;IACO,GAAG,CAAU;IAEb,YAAY,CAAS;IAE/B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,iBAAiB,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"DOFunction.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAyD5B;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAItC;;OAEG;IACO,GAAG,CAAU;IAEb,YAAY,CAAS;IAE/B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,iBAAiB,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,0BAA0B;aAC3C;YACD,uEAAuE;YACvE,sBAAsB;YACtB,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,YAAoB;QACzC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAkC,CAAC;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAC/C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -102,28 +102,33 @@ export default abstract class DOFunction<
|
|
|
102
102
|
if (!this.url) {
|
|
103
103
|
throw new Error(`${this.functionName} URL is not set`);
|
|
104
104
|
}
|
|
105
|
-
const
|
|
105
|
+
const serializedInput = BSON.serialize(input);
|
|
106
|
+
const base64Input = Buffer.from(serializedInput).toString('base64');
|
|
107
|
+
const response = await fetch(this.url, {
|
|
106
108
|
method: 'POST',
|
|
107
109
|
headers: {
|
|
108
110
|
'Content-Type': 'application/octet-stream'
|
|
109
111
|
},
|
|
110
112
|
// It isn't clear why this works by itself. It comes in to the function
|
|
111
113
|
// as a base64 string.
|
|
112
|
-
body:
|
|
114
|
+
body: base64Input
|
|
113
115
|
});
|
|
114
|
-
return this.
|
|
116
|
+
return this.decodeResponse(await response.text());
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
|
-
* Decodes an {@link
|
|
120
|
+
* Decodes an {@link Response} into a {@link DOFunctionCallOutput}.
|
|
119
121
|
*
|
|
120
|
-
* @param
|
|
122
|
+
* @param responseText - The response to decode.
|
|
121
123
|
* @returns The decoded output.
|
|
122
124
|
*/
|
|
123
|
-
private
|
|
124
|
-
buffer
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
private decodeResponse(responseText: string): DOFunctionCallOutput<TOutput> {
|
|
126
|
+
const buffer = Buffer.from(responseText, 'base64');
|
|
127
|
+
try {
|
|
128
|
+
return BSON.deserialize(buffer) as DOFunctionCallOutput<TOutput>;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Deserialization error:', error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
128
133
|
}
|
|
129
134
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@aneuhold/core-ts-api-lib",
|
|
3
3
|
"author": "Anton G. Neuhold Jr.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.2",
|
|
6
6
|
"description": "A library for interacting with the backend and defining the backend API for personal projects.",
|
|
7
7
|
"packageManager": "yarn@4.5.1",
|
|
8
8
|
"type": "module",
|