-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* partial migration * chore: configured eslint and tsc * chore: tests working * chore: set up for publishing
- Loading branch information
1 parent
d5e06c3
commit 26d9a6d
Showing
31 changed files
with
1,619 additions
and
1,266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
{ | ||
"presets": [["@babel/preset-env", { "useBuiltIns": "usage", "corejs": 3 }]] | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
], | ||
"@babel/preset-typescript" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true, | ||
"jest/globals": true | ||
}, | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["eslint:recommended", "plugin:jest/recommended"], | ||
"rules": { | ||
"no-console": ["error", { "allow": ["error"] }], | ||
"indent": ["error", "tab", { "SwitchCase": 1 }], | ||
"linebreak-style": ["error", "unix"], | ||
"quotes": ["error", "single", { "avoidEscape": true }], | ||
"semi": ["error", "always"], | ||
"no-mixed-spaces-and-tabs": ["warn", "smart-tabs"] | ||
}, | ||
"plugins": ["babel", "jest"] | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true, | ||
"jest/globals": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:jest/recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"rules": { | ||
"no-console": ["error", { "allow": ["error"] }], | ||
"indent": ["error", "tab", { "SwitchCase": 1 }], | ||
"linebreak-style": ["error", "unix"], | ||
"quotes": ["error", "single", { "avoidEscape": true }], | ||
"semi": ["error", "always"], | ||
"no-mixed-spaces-and-tabs": ["warn", "smart-tabs"], | ||
"prefer-rest-params": "warn", | ||
"prefer-const": "warn", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-use-before-define": "warn", | ||
"@typescript-eslint/explicit-function-return-type": "off" | ||
}, | ||
"plugins": ["jest"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,6 @@ typings/ | |
|
||
# Firebase configuration used for testing | ||
firebaseConfig.js | ||
|
||
# build directory | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"useTabs": true, | ||
"printWidth": 120, | ||
"trailingComma": "none", | ||
"arrowParens": "avoid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { isRawDocument, decode } from './utils'; | ||
import Database from './mod'; | ||
|
||
export interface FirebaseMap { | ||
/** The map's fields */ | ||
fields?: { | ||
[key: string]: any; | ||
}; | ||
} | ||
|
||
export interface FirebaseDocument extends FirebaseMap { | ||
/** The full resource name of the document */ | ||
name: string; | ||
/** A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds */ | ||
createTime: string; | ||
/** A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds */ | ||
updateTime: string; | ||
} | ||
|
||
export interface Meta { | ||
/** The database instance used to create this document */ | ||
db: Database; | ||
/** The ID of the document inside the collection */ | ||
id: string; | ||
/** The path to the document relative to the database root */ | ||
path: string; | ||
/** The full resource name of the document */ | ||
name: string; | ||
/** A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds */ | ||
createTime: string; | ||
/** A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds */ | ||
updateTime: string; | ||
} | ||
|
||
/** | ||
* Wrapper around a fetched objects that represent a Firestore document. | ||
* It is supposed to be used as a regular JS object but has a hidden | ||
* property that holds the meta data of the document. | ||
* | ||
* That property is called `__meta__`, it should not be modified, and is non-enumerable. | ||
* It is used internally to identify the document when writing the | ||
* data to the database. | ||
*/ | ||
export class Document { | ||
__meta__: Meta; | ||
|
||
constructor(rawDoc: FirebaseDocument, db: Database) { | ||
if (db === undefined) throw Error('Argument "db" is required but missing'); | ||
if (!isRawDocument(rawDoc)) throw Error('Invalid Firestore Document'); | ||
|
||
const { name, createTime, updateTime } = rawDoc; | ||
const meta = { | ||
db, | ||
name, | ||
createTime, | ||
updateTime, | ||
path: name.replace(db.rootPath, ''), | ||
id: name.split('/').pop() | ||
}; | ||
|
||
Object.defineProperty(this, '__meta__', { value: meta }); | ||
Object.assign(this, decode(rawDoc, db)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** Represents a firebase GeoPoint value */ | ||
export default class GeoPoint { | ||
constructor(public latitude: number, public longitude: number) { | ||
if (typeof latitude !== 'number') | ||
throw Error('The latitude argument should be of type number'); | ||
if (typeof latitude !== 'number') | ||
throw Error('The longitude argument should be of type number'); | ||
if (latitude >= 90 && latitude <= -90) | ||
throw Error( | ||
"GeoPoint's latitude should be within the range of -90.0 and 90.0" | ||
); | ||
if (longitude >= 180 && longitude <= -180) | ||
throw Error( | ||
"GeoPoint's longitude should be within the range of -180.0 and 180.0" | ||
); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
geoPointValue: { ...(this as object) } | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Document, FirebaseDocument } from './Document'; | ||
import Reference from './Reference'; | ||
|
||
interface FirebaseList { | ||
documents: FirebaseDocument[]; | ||
nextPageToken: string; | ||
} | ||
|
||
export interface FirebaseListOptions { | ||
pageSize?: number; | ||
pageToken?: string; | ||
orderBy?: string; | ||
showMissing?: boolean; | ||
} | ||
|
||
/** | ||
* Represents a collection list response, with functionality | ||
* for getting the next page when available. | ||
* @param {Object} rawList The response "raw" list object. | ||
* @param {Reference} ref A reference to the collection. | ||
* @param {Object} options Any options that were passed at first to the get request. | ||
*/ | ||
export class List { | ||
ref: Reference; | ||
options: any; | ||
documents: Document[]; | ||
|
||
constructor( | ||
rawList: FirebaseList, | ||
ref: Reference, | ||
options: FirebaseListOptions = {} | ||
) { | ||
if (ref === undefined) | ||
throw Error('The "reference" argument is required when creating a List'); | ||
if (!ref.isCollection) | ||
throw Error('The reference in a list should point to a collection'); | ||
|
||
const { documents, nextPageToken } = rawList; | ||
this.ref = ref; | ||
this.options = options; | ||
this.documents = documents | ||
? documents.map(rawDoc => new Document(rawDoc, ref.db)) | ||
: []; | ||
this.options.pageToken = nextPageToken; | ||
} | ||
|
||
/** Fetches the next page in the query */ | ||
getNextPage() { | ||
return this.ref.get(this.options) as Promise<List>; | ||
} | ||
} |
Oops, something went wrong.