Skip to content

Commit

Permalink
add toTimestamp utility
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Oct 8, 2023
1 parent 83dc0cb commit 509e2a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
</div>
<br/>

v2.6 focuses on fixing bugs, improving JSDoc and removing function overloading

# FirelordJS

FirelordJS is the only library capable of providing truly generic type safety while exposing almost all the API of the official Firestore SDK. The goal is to end Firestore typing madness.
Expand All @@ -111,31 +109,29 @@ Example of how Firelord transforms `ServerTimestamp` type in different operation

FirelordJS:

- Learning curve is the lowest (API is nearly identical to the original API).
- Lowest learning curve. API is nearly identical to the original API and simpler: Eliminates the repetitive tasks of writing collections ID and assigning the Firestore instance.
- Technical debt is the lowest (easy to revert to the official API).
- Minimum types creation and no type assertion.
- Offers truly generic type safe solutions, declare any data shape.
- Offers truly generic type safe solutions, declare any data shape and unions.
- Supports deeply nested object type: `Record<string,Record<string,Record<string,...>>>`, max 1000 levels.
- Supports deeply [nested sub collection](https://firelordjs.com/guides/metatype), all children can [track back](https://firelordjs.com/guides/metatype/#know-your-ancestors) all their ancestors type, max 100 generations.
- Generates all possible flatten paths combinations based on your declared type(e.g.: `a`, `a.b`, `a.b.c`, `a.b.d`, `a.x`, `a.x.y`, `a.x.z`) with type safety.
- Generates different types for different operations, see [Transformative Types](https://firelordjs.com/highlights/transformative_types) for complete list of type transformations.
- Package size is the [smallest](https://firelordjs.com/minified_size).
- Doesn't need code generation and schema language, just pure Typescript.
- Don't need code generation and domain specific language, just pure Typescript all the way.
- Supports [@firebase/rules-unit-testing and emulator](https://firelordjs.com/guides/tests), no extra API is needed!
- Is tested beyond source code, we also test built files and published package. (test source code -> build -> test built files -> publish -> test published)
- Beyond source code testing, we also test built files and published package. (test source code -> build -> test built files -> publish -> test published files)
- No mock test, all 250 tests test against live database to ensure the highest certainty.
- Takes care pesky runtime errors like empty array errors([filter](https://firelordjs.com/highlights/where#dealing-with-empty-array-%EF%B8%8F) & [cursors](https://firelordjs.com/highlights/cursor#empty-rest-parameter)) and [implicit data deletion in update operation](https://firelordjs.com/highlights/update#implicit-data-deletion).
- Eliminates the repetitive tasks of writing collections ID and assigning the Firestore instance.
- Blocks undocumented errors and provides over [30 custom error messages](https://github.com/tylim88/FirelordJS/blob/main/src/types/error.ts) to assist you in writing proper Firestore code! Here is an example:

Firelord is the only library capable of **[typing against](https://firelordjs.com/highlights/query_rule_typing)** Firestore limitations. It also blocks undocumented errors and prevent pesky runtime errors like empty array errors([filter](https://firelordjs.com/highlights/where#dealing-with-empty-array-%EF%B8%8F) & [cursors](https://firelordjs.com/highlights/cursor#empty-rest-parameter)) and [implicit data deletion in update operation](https://firelordjs.com/highlights/update#implicit-data-deletion). Firelord provides over [30 custom error messages](https://github.com/tylim88/FirelordJS/blob/main/src/types/error.ts) to assist you in writing proper Firestore code! Here is an example:

<p align="center">
<img
src="https://github.com/tylim88/FirelordJS/blob/main/img/custom.png?raw=true"
alt="Example of how Firelord handles `ServerTimestamp` type in different operations"
/>
</p>

FirelordJS is the only library capable of **[typing against](https://firelordjs.com/highlights/query_rule_typing)** Firestore limitations.

## Bounty

I am confident Firelord is the best among its kind in terms of best safety and developer experience. I stand behind my words, and I will buy you [x cups of coffee](https://www.buymeacoffee.com/) if you:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firelordjs",
"version": "2.6.19",
"version": "2.6.20",
"description": "🔥 High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
andCreator,
orCreator,
} from './refs'
import { Timestamp } from 'firebase/firestore'

export const getFirelordShakable: GetFirelordShakable =
({
Expand Down Expand Up @@ -49,6 +50,16 @@ export const getFirelord = getFirelordShakable({
orCreator,
})

export const toTimestamp = ({
seconds,
nanoseconds,
}: {
seconds: number
nanoseconds: number
}) => {
return new Timestamp(seconds, nanoseconds)
}

export {
getFirestore,
Timestamp,
Expand Down

0 comments on commit 509e2a4

Please sign in to comment.