Skip to content

Commit

Permalink
Merge 8cc9846 into a46dc62
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Mar 12, 2022
2 parents a46dc62 + 8cc9846 commit d3fdcb4
Show file tree
Hide file tree
Showing 32 changed files with 25,168 additions and 11,844 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.json
Expand Up @@ -12,13 +12,20 @@
"@typescript-eslint/no-namespace": "off"
},
"overrides": [
{
"files": ["src/modular/**/*.ts"],
"rules": {
"node/no-extraneous-import": "off"
}
},
{
"files": ["test/**/*.ts"],
"env": {
"browser": true,
"mocha": true
},
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"node/no-extraneous-import": "off"
}
}
Expand Down
35,912 changes: 24,534 additions & 11,378 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 37 additions & 9 deletions package.json
Expand Up @@ -3,24 +3,51 @@
"description": "Location-based querying and filtering using Firebase's Firestore",
"version": "5.0.0",
"scripts": {
"build": "rimraf ./dist && rollup -c",
"build": "npm-run-all rimraf rollup types",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"docs": "typedoc --out docs/ src/",
"lint": "gts lint",
"start": "firebase emulators:start",
"test": "firebase emulators:exec 'npm run test:nyc'",
"test:nyc": "nyc --reporter=html --reporter=text mocha --package package.json --exit",
"test:nyc": "nyc --reporter=html --reporter=text mocha --package package.json --recursive --exit",
"release:major": "changelog -M && git add . && git commit -m 'chore(release): major version release' && npm version major",
"release:minor": "changelog -m && git add . && git commit -m 'chore(release): minor version release' && npm version minor",
"release:patch": "changelog -p && git add . && git commit -m 'chore(release): patch version release' && npm version patch",
"rimraf": "rimraf ./dist",
"rollup": "rollup -c",
"types": "tsc --project tsconfig.json --declaration --emitDeclarationOnly",
"prepare": "npm run build",
"deploy": "firebase deploy",
"postinstall": "node postinstall.js"
},
"main": "dist/index.cjs.js",
"browser": "dist/geofirestore.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"exports": {
".": {
"node": {
"require": "./dist/index.cjs.js",
"import": "./dist/index.esm.js"
},
"default": "./dist/index.esm.js",
"types": "./dist/index.d.ts"
},
"./admin": {
"node": {
"require": "./dist/admin/index.cjs.js",
"import": "./dist/admin/index.esm.js"
},
"default": "./dist/admin/index.esm.js",
"types": "./dist/admin/index.d.ts"
},
"./compat": {
"node": {
"require": "./dist/compat/index.cjs.js",
"import": "./dist/compat/index.esm.js"
},
"default": "./dist/compat/index.esm.js",
"types": "./dist/compat/index.d.ts"
},
"./package.json": "./package.json"
},
"browser": "./dist/geofirestore.js",
"author": "Michael Solati <mkslt04@gmail.com>",
"homepage": "https://geofirestore.com/",
"repository": {
Expand Down Expand Up @@ -53,10 +80,11 @@
"README.md"
],
"dependencies": {
"geofirestore-core": "^5.0.0"
"geofirestore-core": "github:MichaelSolati/geofirestore-core#refactor"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.16",
Expand All @@ -70,12 +98,12 @@
"jsdom": "^19.0.0",
"jsdom-global": "^3.0.2",
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"protobufjs": "^6.11.2",
"rimraf": "^3.0.2",
"rollup": "^2.67.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"ts-node": "^10.5.0",
"tslib": "^2.3.1",
"typedoc": "^0.22.11",
Expand Down Expand Up @@ -104,4 +132,4 @@
],
"all": true
}
}
}
72 changes: 48 additions & 24 deletions rollup.config.js
@@ -1,6 +1,6 @@
import resolve from '@rollup/plugin-node-resolve';
import typescriptPlugin from '@rollup/plugin-typescript';
import {terser} from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';

import pkg from './package.json';

Expand All @@ -10,52 +10,76 @@ const onwarn = (warning, rollupWarn) => {
}
};

const typescript = typescriptPlugin({
module: 'ESNext',
removeComments: true,
sourceMap: false,
});

export default [
// Default
{
input: 'src/index.ts',
output: [
{
file: pkg.main,
file: pkg.exports['.'].node.require,
format: 'cjs',
},
{
file: pkg.module,
file: pkg.exports['.'].default,
format: 'es',
},
],
external: ['@types/node', 'geofirestore-core'],
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
module: 'ESNext',
removeComments: true,
},
},
}),
plugins: [typescript],
onwarn,
},
// /admin
{
input: 'src/admin/index.ts',
output: [
{
file: pkg.exports['./admin'].node.require,
format: 'cjs',
},
{
file: pkg.exports['./admin'].default,
format: 'es',
},
],
external: ['@types/node', 'geofirestore-core'],
plugins: [typescript],
onwarn,
},
// /compat
{
input: 'src/index.ts',
input: 'src/compat/index.ts',
output: [
{
file: pkg.exports['./compat'].node.require,
format: 'cjs',
},
{
file: pkg.exports['./compat'].default,
format: 'es',
},
],
external: ['@types/node', 'geofirestore-core'],
plugins: [typescript],
onwarn,
},

// Browser
{
input: 'src/compat/index.ts',
output: {
file: pkg.browser,
format: 'umd',
name: 'window',
extend: true,
},
external: ['@types/node'],
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
module: 'ESNext',
},
},
}),
resolve(),
terser(),
],
plugins: [typescript, resolve(), terser()],
onwarn,
},
];
Expand Up @@ -14,17 +14,17 @@ export class GeoCollectionReference extends GeoQuery {
*/
constructor(
private _collection:
| GeoFirestoreTypes.cloud.CollectionReference
| GeoFirestoreTypes.web.CollectionReference,
| GeoFirestoreTypes.admin.CollectionReference
| GeoFirestoreTypes.compat.CollectionReference,
private _customKey?: string
) {
super(_collection);
}

/** The native `CollectionReference` instance. */
get native():
| GeoFirestoreTypes.cloud.CollectionReference
| GeoFirestoreTypes.web.CollectionReference {
| GeoFirestoreTypes.admin.CollectionReference
| GeoFirestoreTypes.compat.CollectionReference {
return this._collection;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ export class GeoCollectionReference extends GeoQuery {
documentData: GeoFirestoreTypes.DocumentData,
customKey: string = this._customKey
): Promise<GeoDocumentReference> {
return (this._collection as GeoFirestoreTypes.cloud.CollectionReference)
return (this._collection as GeoFirestoreTypes.admin.CollectionReference)
.add(encodeDocumentAdd(documentData, customKey))
.then(doc => new GeoDocumentReference(doc));
}
Expand Down
32 changes: 17 additions & 15 deletions src/GeoDocumentReference.ts → src/admin/GeoDocumentReference.ts
Expand Up @@ -4,7 +4,7 @@ import {
encodeDocumentUpdate,
} from 'geofirestore-core';

import {sanitizeSetOptions} from './utils';
import {sanitizeSetOptions} from '../utils';
import {GeoCollectionReference} from './GeoCollectionReference';
import {GeoDocumentSnapshot} from './GeoDocumentSnapshot';
import {GeoFirestore} from './GeoFirestore';
Expand All @@ -22,8 +22,8 @@ export class GeoDocumentReference {
*/
constructor(
private _document:
| GeoFirestoreTypes.cloud.DocumentReference
| GeoFirestoreTypes.web.DocumentReference
| GeoFirestoreTypes.admin.DocumentReference
| GeoFirestoreTypes.compat.DocumentReference
) {
if (Object.prototype.toString.call(_document) !== '[object Object]') {
throw new Error(
Expand All @@ -32,15 +32,15 @@ export class GeoDocumentReference {
}
this._isWeb =
Object.prototype.toString.call(
(_document as GeoFirestoreTypes.web.DocumentReference).firestore
(_document as GeoFirestoreTypes.compat.DocumentReference).firestore
.enablePersistence
) === '[object Function]';
}

/** The native `DocumentReference` instance. */
get native():
| GeoFirestoreTypes.cloud.DocumentReference
| GeoFirestoreTypes.web.DocumentReference {
| GeoFirestoreTypes.admin.DocumentReference
| GeoFirestoreTypes.compat.DocumentReference {
return this._document;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ export class GeoDocumentReference {
onError: (error: Error) => void = () => {}
) => {
const document = this
._document as GeoFirestoreTypes.web.DocumentReference;
._document as GeoFirestoreTypes.compat.DocumentReference;
return document.onSnapshot(
snapshot => onNext(new GeoDocumentSnapshot(snapshot)),
error => onError(error)
Expand Down Expand Up @@ -113,7 +113,7 @@ export class GeoDocumentReference {
* offline).
*/
delete(): Promise<void> {
return (this._document as GeoFirestoreTypes.web.DocumentReference)
return (this._document as GeoFirestoreTypes.compat.DocumentReference)
.delete()
.then(() => null);
}
Expand All @@ -128,11 +128,13 @@ export class GeoDocumentReference {
* @return A Promise resolved with a GeoDocumentSnapshot containing the current document contents.
*/
get(
options: GeoFirestoreTypes.web.GetOptions = {source: 'default'}
options: GeoFirestoreTypes.compat.GetOptions = {source: 'default'}
): Promise<GeoDocumentSnapshot> {
const get = this._isWeb
? (this._document as GeoFirestoreTypes.web.DocumentReference).get(options)
: (this._document as GeoFirestoreTypes.web.DocumentReference).get();
? (this._document as GeoFirestoreTypes.compat.DocumentReference).get(
options
)
: (this._document as GeoFirestoreTypes.compat.DocumentReference).get();
return get.then(snapshot => new GeoDocumentSnapshot(snapshot));
}

Expand All @@ -145,8 +147,8 @@ export class GeoDocumentReference {
isEqual(
other:
| GeoDocumentReference
| GeoFirestoreTypes.cloud.DocumentReference
| GeoFirestoreTypes.web.DocumentReference
| GeoFirestoreTypes.admin.DocumentReference
| GeoFirestoreTypes.compat.DocumentReference
): boolean {
const ref: any =
other instanceof GeoDocumentReference ? other['_document'] : other;
Expand All @@ -165,7 +167,7 @@ export class GeoDocumentReference {
documentData: GeoFirestoreTypes.DocumentData,
options?: GeoFirestoreTypes.SetOptions
): Promise<void> {
return (this._document as GeoFirestoreTypes.web.DocumentReference)
return (this._document as GeoFirestoreTypes.compat.DocumentReference)
.set(
encodeDocumentSet(documentData, options),
sanitizeSetOptions(options)
Expand All @@ -186,7 +188,7 @@ export class GeoDocumentReference {
data: GeoFirestoreTypes.UpdateData,
customKey?: string
): Promise<void> {
return (this._document as GeoFirestoreTypes.web.DocumentReference)
return (this._document as GeoFirestoreTypes.compat.DocumentReference)
.update(encodeDocumentUpdate(data, customKey))
.then(() => null);
}
Expand Down

0 comments on commit d3fdcb4

Please sign in to comment.