![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@ridedott/firestore-extensions
Advanced tools
A collection of Firestore utilities.
npm install @ridedott/firestore-extensions
An extension provides methods to convert Firestore IDs to UUID v4 and back.
const { idToUuid, uuidToId } = require('@ridedott/firestore-extensions');
const uuid = idToUuid('74NS2s2OIUH5KZRLFto4'); // ef8352da-cd8e-4214-87e4-a6512c5b68e0
const firestoreId = uuidToId('ef8352da-cd8e-4214-87e4-a6512c5b68e0'); // 74NS2s2OIUH5KZRLFto4
An extension that maintains an in memory cache of a Firestore collection's data with a backing subscription ensuring updates as they occur in the database.
Supports pausing and resuming subscriptions, which can optimize database usage. These operations are handled automatically, based on attached event listeners and pending promises. If there are no attached event listeners and no pending promises, the subscription is paused.
Collections expose methods to learn about the current state and better optimize
usage, such as isActive
and statistics
.
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{ structuredQuery: { from: [{ collectionId: 'my-collection' }] } },
(document) => document,
);
myCollectionSubscription.on('documentAdded', (document): void => {
// Added document data is available here.
});
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{ structuredQuery: { from: [{ collectionId: 'my-collection' }] } },
(document) => document,
);
await myCollectionSubscription.synchronize();
// Contains current documents.
myCollectionSubscription.data();
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{
structuredQuery: {
from: [{ collectionId: 'my-collection' }],
where: {
fieldFilter: {
field: { fieldPath: 'my-field-path' },
op: 'EQUAL',
value: { booleanValue: true },
},
},
},
},
},
(document) => document,
);
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{
structuredQuery: {
from: [{ collectionId: 'my-collection' }],
select: {
fields: [{ fieldPath: 'flat' }, { fieldPath: 'nested.field' }],
},
},
},
(document) => document,
);
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{ structuredQuery: { from: [{ collectionId: 'my-collection' }] } },
(document) => document,
);
const statistics = myCollectionSubscription.statistics();
Firestore usage metrics are collected per subscription. Metrics are reset after
each call to the metrics()
method. Returned object has to be logged to be used
as a source for log-based metrics.
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{ structuredQuery: { from: [{ collectionId: 'my-collection' }] } },
(document) => document,
);
await myCollectionSubscription.synchronize();
const metrics = myCollectionSubscription.metrics();
logInfo(`Subscription synchronized.`, {
metrics: {
myCollectionSubscription: myCollectionSubscription.metrics(),
},
});
For best performance, subscriptions default to use the native (API) representation of documents. This is a recommended way to interact with the library.
For convenience purposes, especially when migrating existing code, conversion helpers are provided.
import { subscriptions } from '@ridedott/firestore-extensions';
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const myCollectionSubscription = repository.makeCollectionSubscription(
{ structuredQuery: { from: [{ collectionId: 'my-collection' }] } },
(native: subscriptions.types.ToNativeDocument<MyType>): MyType =>
subscriptions.converters.toCanonical<MyType>({
mapValue: { fields: native.fields },
valueType: 'mapValue',
}),
);
It is possible to convert Firestore SDK references to native query format with the use of private APIs. This is not recommended, however it can be useful to run locally when migrating.
import { Firestore } from '@google-cloud/firestore';
import { google } from '@google-cloud/firestore/types/protos/firestore_v1_proto_api';
import { subscriptions } from '@ridedott/firestore-extensions';
const firestore = new Firestore();
const reference = (
firestore.collection('my-collection') as unknown as {
toProto: () => google.firestore.v1.IRunQueryRequest;
}
).toProto();
// Log the structured query.
console.log(reference.structuredQuery);
// Use directly (not recommended in production environments).
const repository = new subscriptions.Repository({ projectId: 'my-project' });
const subscription = repository.makeCollectionSubscription(
reference,
(document) => document,
);
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See usage notes on how to consume this package in your project.
Minimal requirements to set up the project:
Start by cloning the repository:
git clone git@github.com:ridedott/firestore-extensions.git
In case you don't have a git client, you can get the latest version directly by using this link and extracting the downloaded archive.
Go the the right directory and install dependencies:
cd ./firestore-extensions
npm install
That's it! You can now go to the next step.
This project uses Prettier to automate formatting. All supported files are being reformatted in a pre-commit hook. You can also use one of the two scripts to validate and optionally fix all of the files:
npm run format
npm run format:fix
This project uses ESLint to enable static analysis. TypeScript files are linted using a custom configuration. You can use one of the following scripts to validate and optionally fix all of the files:
npm run lint
npm run lint:fix
Publishing is handled in an automated way and must not be performed manually.
Each commit to the master branch is automatically deployed to the NPM registry
with a version specified in package.json
. All other commits are published as
pre-releases.
See CONTRIBUTING.md.
This project adheres to Semantic Versioning v2.
FAQs
A collection of Firestore utilities.
The npm package @ridedott/firestore-extensions receives a total of 374 weekly downloads. As such, @ridedott/firestore-extensions popularity was classified as not popular.
We found that @ridedott/firestore-extensions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.