@flowerforce/flowerbase 1.6.1-beta.0 → 1.6.1-beta.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;;uBAqDP,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BArCU,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAkChD,CAAF;iCAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAZ,CAAF;6BAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAAZ,CAAF;6BAAa,CAAC;;;;;;;;;;;;;;;4BAWI,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAerE,CAAA"}
|
|
@@ -13,6 +13,27 @@ const mongodb_1 = require("@fastify/mongodb");
|
|
|
13
13
|
* @param functionsList -> the list of all functions
|
|
14
14
|
*/
|
|
15
15
|
const generateContextData = ({ user, services, app, rules, currentFunction, functionsList, GenerateContext, request }) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const BSON = mongodb_1.mongodb.BSON;
|
|
18
|
+
const Binary = BSON === null || BSON === void 0 ? void 0 : BSON.Binary;
|
|
19
|
+
if (Binary && typeof Binary.fromBase64 !== 'function') {
|
|
20
|
+
Binary.fromBase64 = (base64, subType) => {
|
|
21
|
+
if (typeof Binary.createFromBase64 === 'function') {
|
|
22
|
+
return Binary.createFromBase64(base64, subType);
|
|
23
|
+
}
|
|
24
|
+
return new Binary(Buffer.from(base64, 'base64'), subType);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (Binary && Binary.fromBase64 && !Binary.__fb_fromBase64Wrapped) {
|
|
28
|
+
Binary.__fb_fromBase64Wrapped = true;
|
|
29
|
+
const fromBase64Binary = (_a = Binary.fromBase64Binary) !== null && _a !== void 0 ? _a : Binary.fromBase64;
|
|
30
|
+
Binary.fromBase64Binary = fromBase64Binary;
|
|
31
|
+
Binary.fromBase64 = (base64, subType) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const result = (_a = fromBase64Binary === null || fromBase64Binary === void 0 ? void 0 : fromBase64Binary(base64, subType)) !== null && _a !== void 0 ? _a : new Binary(Buffer.from(base64, 'base64'), subType);
|
|
34
|
+
return typeof result.value === 'function' ? result.value() : result;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
16
37
|
const getService = (serviceName) => {
|
|
17
38
|
try {
|
|
18
39
|
return services[serviceName](app, {
|
|
@@ -26,7 +47,7 @@ const generateContextData = ({ user, services, app, rules, currentFunction, func
|
|
|
26
47
|
}
|
|
27
48
|
};
|
|
28
49
|
return {
|
|
29
|
-
BSON
|
|
50
|
+
BSON,
|
|
30
51
|
Buffer,
|
|
31
52
|
console: {
|
|
32
53
|
log: (...args) => {
|
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ describe('generateContextData', () => {
|
|
|
45
45
|
|
|
46
46
|
it('should return an object with context configuration', async () => {
|
|
47
47
|
const mockApp = Fastify()
|
|
48
|
-
const { context, console: contextConsole } = generateContextData({
|
|
48
|
+
const { context, console: contextConsole, BSON } = generateContextData({
|
|
49
49
|
services,
|
|
50
50
|
app: mockApp,
|
|
51
51
|
functionsList: mockFunctions,
|
|
@@ -77,5 +77,16 @@ describe('generateContextData', () => {
|
|
|
77
77
|
|
|
78
78
|
context.functions.execute('test')
|
|
79
79
|
expect(GenerateContextMock).toHaveBeenCalled()
|
|
80
|
+
|
|
81
|
+
const base64 = Buffer.from('test').toString('base64')
|
|
82
|
+
const Binary = BSON.Binary as typeof BSON.Binary & {
|
|
83
|
+
fromBase64: (base64: string, subType?: number) => Uint8Array
|
|
84
|
+
fromBase64Binary: (base64: string, subType?: number) => InstanceType<typeof BSON.Binary>
|
|
85
|
+
}
|
|
86
|
+
const binaryValue = Binary.fromBase64(base64, 0)
|
|
87
|
+
expect(binaryValue).toBeInstanceOf(Uint8Array)
|
|
88
|
+
expect(Buffer.from(binaryValue).toString('utf8')).toBe('test')
|
|
89
|
+
const binaryObject = Binary.fromBase64Binary(base64, 0)
|
|
90
|
+
expect(binaryObject).toBeInstanceOf(BSON.Binary)
|
|
80
91
|
})
|
|
81
92
|
})
|
|
@@ -23,6 +23,38 @@ export const generateContextData = ({
|
|
|
23
23
|
GenerateContext,
|
|
24
24
|
request
|
|
25
25
|
}: GenerateContextDataParams) => {
|
|
26
|
+
const BSON = mongodb.BSON
|
|
27
|
+
const Binary = BSON?.Binary as
|
|
28
|
+
| (typeof mongodb.BSON.Binary & {
|
|
29
|
+
fromBase64?: (base64: string, subType?: number) => mongodb.BSON.Binary | Uint8Array
|
|
30
|
+
fromBase64Binary?: (base64: string, subType?: number) => mongodb.BSON.Binary
|
|
31
|
+
__fb_fromBase64Wrapped?: boolean
|
|
32
|
+
})
|
|
33
|
+
| undefined
|
|
34
|
+
|
|
35
|
+
if (Binary && typeof Binary.fromBase64 !== 'function') {
|
|
36
|
+
Binary.fromBase64 = (base64: string, subType?: number) => {
|
|
37
|
+
if (typeof Binary.createFromBase64 === 'function') {
|
|
38
|
+
return Binary.createFromBase64(base64, subType)
|
|
39
|
+
}
|
|
40
|
+
return new Binary(Buffer.from(base64, 'base64'), subType)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Binary && Binary.fromBase64 && !Binary.__fb_fromBase64Wrapped) {
|
|
45
|
+
Binary.__fb_fromBase64Wrapped = true
|
|
46
|
+
const fromBase64Binary =
|
|
47
|
+
Binary.fromBase64Binary ??
|
|
48
|
+
(Binary.fromBase64 as (base64: string, subType?: number) => mongodb.BSON.Binary)
|
|
49
|
+
Binary.fromBase64Binary = fromBase64Binary
|
|
50
|
+
Binary.fromBase64 = (base64: string, subType?: number) => {
|
|
51
|
+
const result =
|
|
52
|
+
fromBase64Binary?.(base64, subType) ??
|
|
53
|
+
new Binary(Buffer.from(base64, 'base64'), subType)
|
|
54
|
+
return typeof result.value === 'function' ? result.value() : result
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
26
58
|
const getService = (serviceName: keyof typeof services) => {
|
|
27
59
|
try {
|
|
28
60
|
return services[serviceName](app, {
|
|
@@ -40,7 +72,7 @@ export const generateContextData = ({
|
|
|
40
72
|
}
|
|
41
73
|
|
|
42
74
|
return {
|
|
43
|
-
BSON
|
|
75
|
+
BSON,
|
|
44
76
|
Buffer,
|
|
45
77
|
console: {
|
|
46
78
|
log: (...args: Arguments) => {
|