Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion apps/scouting/backend/src/middleware/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,57 @@ const dbName = "scouting";

const client: MongoClient = new MongoClient(url);

let db: Db | undefined = undefined; // 😭 has to happen
let /*it happen🔥:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

It's always around me, all this noise
But not nearly as loud as the voice saying
"Let it happen, let it happen" (it's gonna feel so good)
"Just let it happen, let it happen"
All this running around
Tryin' to cover my shadow
A notion growing inside
Now, all the others seem shallow
All this running around
Bearing down on my shoulders
I can hear an alarm
Must be a morning
I heard about a whirlwind that's coming 'round
It's gonna carry off all that isn't bound
And when it happens, when it happens (I won't be holding on)
So, let it happen, let it happen
All this running around
I can't fight it much longer
Something's tryin' to get out
And it's never been closer
If my take-off fails
Make up some other story
If I never come back
Tell my mother I'm sorry
I cannot vanish, you will not scare me
Try to get through it, try to push through it
You were not thinking that I will not do it
They be lovin' someone and I'm another story
Take the next ticket, get the next train
Why would I do it? Anyone'd think that
I cannot vanish, you will not scare me
Try to get through it, try to push through it
You were not thinking that I will not do it
They be lovin' someone and I'm another story
Take the next ticket, get the next train
Why would I do it? Anyone'd think that
Try to get through it, try to push through it
You were not thinking that I will not do it
They be lovin' someone and I'm another story
Take the next ticket, get the next train
Why would I do it? Anyone'd think that
Baby, now I'm ready, moving on
Oh, but maybe I was ready all along
Oh, I'm ready for the moment and the sound
Oh, but maybe I was ready all along
Baby, now I'm ready, moving on
Oh, but maybe I was ready all along
Oh, I'm ready for the moment and the sound
Oh, but maybe I was ready all along*/
db: Db | undefined = undefined;

export const getDb = (): TaskEither<EndpointError, Db> =>
db
Expand Down
57 changes: 50 additions & 7 deletions packages/serde/serders/serde-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ export const serdeString = (): Serde<string> => ({

serdeUnsignedInt(stringLengthBitCount).serializer(
serializedData,
encodedString.length
encodedString.length,
);
serializedData.insertUInt8Array(
encodedString,
encodedString.length * BIT_ARRAY_LENGTH
encodedString.length * BIT_ARRAY_LENGTH,
);
},
deserializer(serializedData: BitArray): string {
const encodedStringLength =
serdeUnsignedInt(stringLengthBitCount).deserializer(serializedData);
const encodedString = serializedData.consumeBits(
encodedStringLength * BIT_ARRAY_LENGTH
encodedStringLength * BIT_ARRAY_LENGTH,
);
return new TextDecoder().decode(encodedString);
},
});

export const serdeEnumedString = <Options extends string>(
possibleValues: Options[]
possibleValues: Options[],
): Serde<Options> => {
function bitsNeeded(possibleValuesCount: number): number {
return Math.ceil(Math.log2(possibleValuesCount));
Expand All @@ -37,14 +37,57 @@ export const serdeEnumedString = <Options extends string>(
serializer(serializedData: BitArray, data: Options) {
const neededBits = bitsNeeded(possibleValues.length);

for (let i = 0; i < possibleValues.length; i++) {
for (
let /*it go ❄️: The snow glows white on the mountain tonight
Not a footprint to be seen
A kingdom of isolation
And it looks like I'm the queen
The wind is howling like this swirling storm inside
Couldn't keep it in, heaven knows I tried
Don't let them in, don't let them see
Be the good girl you always have to be
Conceal, don't feel, don't let them know
Well, now they know
Let it go, let it go
Can't hold it back anymore
Let it go, let it go
Turn away and slam the door
I don't care what they're going to say
Let the storm rage on
The cold never bothered me anyway
It's funny how some distance makes everything seem small
And the fears that once controlled me can't get to me at all
It's time to see what I can do
To test the limits and break through
No right, no wrong, no rules for me
I'm free
Let it go, let it go
I am one with the wind and sky
Let it go, let it go
You'll never see me cry
Here I stand and here I stay
Let the storm rage on
My power flurries through the air into the ground
My soul is spiraling in frozen fractals all around
And one thought crystallizes like an icy blast
I'm never going back, the past is in the past
Let it go, let it go
And I'll rise like the break of dawn
Let it go, let it go
That perfect girl is gone
Here I stand in the light of day
Let the storm rage on
The cold never bothered me anyway */ i = 0;
i < possibleValues.length;
i++
) {
if (data == possibleValues[i]) {
serdeUnsignedInt(neededBits).serializer(serializedData, i);
return;
}
}
throw new Error(
`value ${data} is not included in possible values: ${possibleValues.toString()}`
`value ${data} is not included in possible values: ${possibleValues.toString()}`,
);
},
deserializer(serializedData: BitArray): Options {
Expand All @@ -55,7 +98,7 @@ export const serdeEnumedString = <Options extends string>(
return possibleValues[valueIdentifier];
}
throw new Error(
`valueIdentifier ${valueIdentifier} does not exist in possible values: ${possibleValues.toString()}`
`valueIdentifier ${valueIdentifier} does not exist in possible values: ${possibleValues.toString()}`,
);
},
};
Expand Down
Loading