Skip to content

Typesaurus v8 #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e7b8486
Disallow removing non-optional fields
kossnocorp Jun 7, 2020
0c18cc4
Proparly type two-level deep updates
kossnocorp Jun 9, 2020
97fd8da
Rebase and promote to v8.0.0-alpha.2
kossnocorp Dec 9, 2020
e4100c9
Initiate the changes for server dates being null
kossnocorp Jan 28, 2021
d9289bc
Add server timestamps strategy & setter env
kossnocorp Jan 29, 2021
5af4f21
Hack Jest to support optional chaining while I'm offline
kossnocorp Jan 30, 2021
31347e9
Adapt set test for server dates update
kossnocorp Jan 30, 2021
3921a24
Make env assert work in set
kossnocorp Jan 30, 2021
cb0d49c
Add more tests cases for set's env assert
kossnocorp Jan 30, 2021
374abf5
Improve server dates
kossnocorp Feb 1, 2021
dcde29e
Properly install @babel/plugin-proposal-optional-chaining
kossnocorp Feb 1, 2021
ee468f7
Fix getter functions, simplify ModelData
kossnocorp Feb 1, 2021
8900503
Make ServerDateNullable optional in ModelData
kossnocorp Feb 1, 2021
990c7e2
Add environment support for add
kossnocorp Feb 1, 2021
4536909
Add operation options to every function where it makes sense
kossnocorp Feb 2, 2021
d5b131a
Fix tests after server dates updae
kossnocorp Feb 3, 2021
754e4e5
Fix type issues and promote to v8.0.0-alpha.18
kossnocorp Feb 3, 2021
ba4e2a7
Add realtime options
kossnocorp Feb 23, 2021
15cee67
Fix group typing
kossnocorp Feb 23, 2021
2de3a19
Export options types, get rid of default exports
kossnocorp Mar 20, 2021
3fa82af
Promote to v8.0.0-alpha.22
kossnocorp Mar 20, 2021
17e1dd5
Use Lazy Fire to delay importing Firebase modules
kossnocorp Jun 9, 2021
8de1cb2
Add failing test to query
kossnocorp Jul 20, 2021
07bbbd1
Upgrade TypeScript to v4.4
kossnocorp Jul 20, 2021
e4c2fa3
Promote to v8.0.0-alpha.24
kossnocorp Jul 20, 2021
1b73c03
Add support for quering optional fields
kossnocorp Jul 20, 2021
e6278eb
Add changelog entry for optional where
kossnocorp Jul 20, 2021
54ba035
Promote to v8.0.0-alpha.25
kossnocorp Jul 21, 2021
d445658
Fix `injectTestingAdaptor`
kossnocorp Feb 22, 2022
9b05237
Another attempt to fix testing adaptor
kossnocorp Feb 22, 2022
c456ca9
Nullify data passing to doc
kossnocorp Feb 23, 2022
0151195
Expose nullifyData
kossnocorp Feb 23, 2022
e7ac123
Add firestoreData property to NodeDoc and WebDoc
kossnocorp Feb 23, 2022
a2ed0b5
Allow pass falsy values to update fields
kossnocorp Apr 21, 2022
8aa31a7
Upgrade TypeScript
kossnocorp Jul 18, 2022
3a2dc06
Add retry option to onGet
kossnocorp Jul 18, 2022
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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.15.4
71 changes: 71 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,77 @@ This change log follows the format documented in [Keep a CHANGELOG].
[semantic versioning]: http://semver.org/
[keep a changelog]: http://keepachangelog.com/

## 8.0.0 - 2021-??-??

Typesaurus v8 includes two important changes that bring the type-safety to another level:

1. TODO

2. TODO

See below for details.

### Fixes

- Fixed `group` type to properly derive the collection model.

### Changed

- **BREAKING**: Use `lazyfire` for ESM-enabled web environments to make Firebase modules load on demand. It ensures maximum performance, but requires installation of additional dependency and change of application initialization.

So, if you're using webpack or another ESM-enabled bundler, install `lazyfire`:

```bash
npm install lazyfire --save
# Or using Yarn:
yarn add lazyfire
```

And then change `firebase.initializeApp` to `configureApp`:

```diff
-import * as firebase from 'firebase/app'
-import 'firebase/firestore'
+import { configureApp } from 'lazyfire'

-firebase.initializeApp({
+configureApp({
// Firebase app configuration
})
```

- **BREAKING**: Make TypeScript 3.8 the minimal supported version.

- **BREAKING**: `AnyUpdateValue` type was removed.

- **BREAKING**: `UpdateValue` type now accepts two type arguments: object and key instead of a single type.

- **BREAKING**: Disallowed using `value('remove')` on non-optional fields.

- **BREAKING**: Removed `AddModel` and `SetModel` in favor of universal `WriteModel`.

- **BREAKING**: `meta` argument in `doc` is again required.

- **BREAKING**: Make `environment` a required meta property.

- **BREAKING**: Moved `onMissing` to options in `getMany`.

- **BREAKING**: All modules now export functions as named exports instead of using `default`.

- **BREAKING**: `Query` type now exported from `typesaurus` or `typesaurus/types` instead of `typesaurus/query` and `typesaurus/onQuery`.

- **BREAKING**: Unless `firestoreData: true` is specified in the meta, `doc` will convert `undefined` to `null` in the data.

The idea of the change is to match the Firestore behavior when composing a synthetic doc, which is helpful in tests or Typesaurus extensions.

- Export options types for all functions.

- `TransactionWriteFunction` no longer expect to return a promise.

- Allow quering optional fields, inluding nested map fields using `where`.

- Added `nullifyData` that deeply replaces `undefined` with `null` in the passed data. It used to match the Firestore behavior.

## 7.2.0 - 2021-05-25

- Replace deprecated `@firebase/rules-testing` with `@firebase/rules-unit-testing`.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ test-system-browser-watch:

build:
@rm -rf lib
@${BIN}/tsc
@${BIN}/tsc --project tsconfig.lib.json
@${BIN}/prettier "lib/**/*.[jt]s" --write --loglevel silent
@cp package.json lib
@cp *.md lib
@rsync --archive --prune-empty-dirs --exclude '*.ts' --relative src/./ lib
@${BIN}/tsc --outDir lib/esm --module es2020 --target es2019
@${BIN}/tsc --project tsconfig.lib.json --outDir lib/esm --module es2020 --target es2019
@cp src/adaptor/package.esm.json lib/esm/adaptor/package.json

publish: build
Expand Down
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,53 @@ yarn add typesaurus
_Note that Typesaurus requires `firebase` package to work in the web environment and `firebase-admin` to work in Node.js. These packages aren't listed as dependencies,
so that they won't install automatically along with the Typesaurus package._

Additionally, when using with ESM-enabled bundler (like webpack), you'll need to install `lazyfire` that enables asynchronous importing of Firebase modules in the web environment:

```sh
npm install lazyfire --save
# Or using Yarn:
yarn add lazyfire
```

[Read more about Lazy Fire](https://github.com/kossnocorp/lazyfire).

## Configuration

Typesaurus does not require additional configuration, however **when using with ESM-enabled bundler, you should transpile `node_modules`**. TypeScript preserves many modern languages features when it compiles to ESM code. So if you have to support older browsers, use Babel to process the dependencies code
Typesaurus does not require additional configuration, however **when using with ESM-enabled bundler (like webpack), you should transpile `node_modules`**. TypeScript preserves many modern languages features when it compiles to ESM code. So if you have to support older browsers, use Babel to process the dependencies code.

## Get started

### Initialization

To start working with Typesaurus, initialize Firebase normally.
To start working with Typesaurus, you'll need to initialize Firebase.

In the web environment ([see Firebase docs](https://firebase.google.com/docs/web/setup#add-sdks-initialize)):
#### Web environment

In the web environment when using ESM-enabled bundler (like webpack), use [Lazy Fire](https://github.com/kossnocorp/lazyfire) to configure the Firebase application:

```ts
import { configureApp } from 'lazyfire'

configureApp({
// Firebase app configuration
})
```

#### Legacy web environment

In the web environment with ESM-disabled ([see Firebase docs](https://firebase.google.com/docs/web/setup#add-sdks-initialize)):

```ts
import * as firebase from 'firebase/app'
import 'firebase/firestore'

firebase.initializeApp({
// Project configuration
// Firebase app configuration
})
```

#### Node.js environment

In Node.js ([see Firebase docs](https://firebase.google.com/docs/admin/setup#initialize-sdk)):

```ts
Expand Down
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
'power-assert'
]
],
plugins: ['@babel/plugin-proposal-optional-chaining']
}
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const webpack = require('webpack')

process.env.CHROME_BIN = require('puppeteer').executablePath()

module.exports = config => {
module.exports = (config) => {
config.set({
files: ['test/karmaTests.ts'],

Expand Down
Loading