@purr-core/services.firebase 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-Bg9DBNtp.cjs");exports.addDocument=e.addDocument;exports.deleteDocument=e.deleteDocument;exports.getAllDocuments=e.getAllDocuments;exports.getDocumentById=e.getDocumentById;exports.getFireStorage=e.getFireStorage;exports.getFireStore=e.getFireStore;exports.initFirebaseApp=e.initFirebaseApp;exports.setDocument=e.setDocument;
1
+ 'use strict';var firestore=require('firebase/firestore'),utils_helpers=require('@purr-core/utils.helpers');var R=async(t,o)=>{let e=firestore.collection(t,o),{error:n,result:r}=await utils_helpers.tryDo(firestore.getDocs(e));if(n)return {error:n,result:null};let s=r?.docs?.map?.(u=>({...u.data(),id:u.id}));return {error:null,result:utils_helpers.cast(s)}},h=async(t,o,e)=>{let n=firestore.doc(t,o,e),{error:r,result:s}=await utils_helpers.tryDo(firestore.getDoc(n));return r?{error:r,result:null}:{error:null,result:utils_helpers.cast(s?.data())}},w=async(t,o,e)=>{let n=firestore.collection(t,o),{error:r,result:s}=await utils_helpers.tryDo(firestore.addDoc(n,e));return r?{error:r,result:null}:{error:null,result:utils_helpers.cast(s)}},P=async(t,o,e)=>{let n=firestore.doc(t,o,e.id),{error:r,result:s}=await utils_helpers.tryDo(firestore.setDoc(n,e,{merge:true}));return r?{error:r,result:null}:{error:null,result:s}},I=async(t,o,e)=>{let n=firestore.doc(t,o,e),{error:r,result:s}=await utils_helpers.tryDo(firestore.deleteDoc(n));return r?{error:r,result:null}:{error:null,result:s}};var B=async t=>(await import('firebase/app').then(e=>e.default.initializeApp))(t),Q=async t=>(await import('firebase/firestore').then(e=>e.default.getFirestore))(t),z=async t=>(await import('firebase/storage').then(e=>e.default.getStorage))(t);exports.addDocument=w;exports.deleteDocument=I;exports.getAllDocuments=R;exports.getDocumentById=h;exports.getFireStorage=z;exports.getFireStore=Q;exports.initFirebaseApp=B;exports.setDocument=P;
@@ -0,0 +1,110 @@
1
+ import { Firestore, DocumentData } from 'firebase/firestore';
2
+ import { TAsyncBoundary } from '@purr-core/utils.definitions';
3
+ import { FirebaseApp } from 'firebase/app';
4
+ import { FirebaseStorage } from 'firebase/storage';
5
+
6
+ /**
7
+ * Represents the configuration for a Firebase project.
8
+ *
9
+ * @interface IFirebaseConfig
10
+ * @property {string} [apiKey] - The API key for the Firebase project.
11
+ * @property {string} [authDomain] - The authentication domain for the Firebase project.
12
+ * @property {string} [projectId] - The project ID for the Firebase project.
13
+ * @property {string} [storageBucket] - The storage bucket for the Firebase project.
14
+ * @property {string} [messagingSenderId] - The messaging sender ID for the Firebase project.
15
+ * @property {string} [appId] - The app ID for the Firebase project.
16
+ * @property {string} [measurementId] - The measurement ID for the Firebase project.
17
+ */
18
+ interface IFirebaseConfig {
19
+ apiKey?: string;
20
+ authDomain?: string;
21
+ projectId?: string;
22
+ storageBucket?: string;
23
+ messagingSenderId?: string;
24
+ appId?: string;
25
+ measurementId?: string;
26
+ }
27
+ /**
28
+ * Represents the return type of an asynchronous Firebase operation.
29
+ *
30
+ * @interface IAsyncFirebaseReturnType
31
+ * @template T - The type of the result.
32
+ * @property {unknown | null} error - The error encountered during the asynchronous operation, if any.
33
+ * @property {T | null} result - The result of the asynchronous operation, if successful.
34
+ */
35
+ interface IAsyncFirebaseReturnType<T> {
36
+ error: unknown | null;
37
+ result: T | null;
38
+ }
39
+
40
+ /**
41
+ * Gets all documents from a collection in Firebase Firestore.
42
+ *
43
+ * @template T - The type of the documents.
44
+ * @param {Firestore} firestore - The Firestore instance.
45
+ * @param {string} c - The collection name.
46
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
47
+ */
48
+ declare const getAllDocuments: <T>(firestore: Firestore, c: string) => Promise<IAsyncFirebaseReturnType<T>>;
49
+ /**
50
+ * Gets a document from a collection in Firebase Firestore by its ID.
51
+ *
52
+ * @template T - The type of the document.
53
+ * @param {Firestore} firestore - The Firestore instance.
54
+ * @param {string} c - The collection name.
55
+ * @param {string} id - The ID of the document.
56
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
57
+ */
58
+ declare const getDocumentById: <T>(firestore: Firestore, c: string, id: string) => Promise<IAsyncFirebaseReturnType<T>>;
59
+ /**
60
+ * Adds a document to a collection in Firebase Firestore.
61
+ *
62
+ * @template T - The type of the document.
63
+ * @param {Firestore} firestore - The Firestore instance.
64
+ * @param {string} c - The collection name.
65
+ * @param {DocumentData} data - The data to add to the document.
66
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
67
+ */
68
+ declare const addDocument: <T>(firestore: Firestore, c: string, data: DocumentData) => Promise<IAsyncFirebaseReturnType<T>>;
69
+ /**
70
+ * Sets a document in a collection in Firebase Firestore.
71
+ *
72
+ * @param {Firestore} firestore - The Firestore instance.
73
+ * @param {string} c - The collection name.
74
+ * @param {DocumentData} data - The data to set in the document.
75
+ * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
76
+ */
77
+ declare const setDocument: (firestore: Firestore, c: string, data: DocumentData) => Promise<TAsyncBoundary<void>>;
78
+ /**
79
+ * Deletes a document from a collection in Firebase Firestore.
80
+ *
81
+ * @param {Firestore} firestore - The Firestore instance.
82
+ * @param {string} c - The collection name.
83
+ * @param {string} id - The ID of the document to delete.
84
+ * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
85
+ */
86
+ declare const deleteDocument: (firestore: Firestore, c: string, id: string) => Promise<TAsyncBoundary<void>>;
87
+
88
+ /**
89
+ * Initializes a Firebase app.
90
+ *
91
+ * @param {IFirebaseConfig} config - The configuration for the Firebase app.
92
+ * @returns {Promise<FirebaseApp>} A promise that resolves to the initialized Firebase app.
93
+ */
94
+ declare const initFirebaseApp: (config: IFirebaseConfig) => Promise<FirebaseApp>;
95
+ /**
96
+ * Gets a Firestore instance.
97
+ *
98
+ * @param {FirebaseApp} app - The Firebase app.
99
+ * @returns {Promise<Firestore>} A promise that resolves to the Firestore instance.
100
+ */
101
+ declare const getFireStore: (app: FirebaseApp) => Promise<Firestore>;
102
+ /**
103
+ * Gets a Firebase Storage instance.
104
+ *
105
+ * @param {FirebaseApp} app - The Firebase app.
106
+ * @returns {Promise<FirebaseStorage>} A promise that resolves to the Firebase Storage instance.
107
+ */
108
+ declare const getFireStorage: (app: FirebaseApp) => Promise<FirebaseStorage>;
109
+
110
+ export { type IAsyncFirebaseReturnType, type IFirebaseConfig, addDocument, deleteDocument, getAllDocuments, getDocumentById, getFireStorage, getFireStore, initFirebaseApp, setDocument };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,110 @@
1
- export * from './_api';
2
- export * from './_init';
3
- export * from './_types';
1
+ import { Firestore, DocumentData } from 'firebase/firestore';
2
+ import { TAsyncBoundary } from '@purr-core/utils.definitions';
3
+ import { FirebaseApp } from 'firebase/app';
4
+ import { FirebaseStorage } from 'firebase/storage';
5
+
6
+ /**
7
+ * Represents the configuration for a Firebase project.
8
+ *
9
+ * @interface IFirebaseConfig
10
+ * @property {string} [apiKey] - The API key for the Firebase project.
11
+ * @property {string} [authDomain] - The authentication domain for the Firebase project.
12
+ * @property {string} [projectId] - The project ID for the Firebase project.
13
+ * @property {string} [storageBucket] - The storage bucket for the Firebase project.
14
+ * @property {string} [messagingSenderId] - The messaging sender ID for the Firebase project.
15
+ * @property {string} [appId] - The app ID for the Firebase project.
16
+ * @property {string} [measurementId] - The measurement ID for the Firebase project.
17
+ */
18
+ interface IFirebaseConfig {
19
+ apiKey?: string;
20
+ authDomain?: string;
21
+ projectId?: string;
22
+ storageBucket?: string;
23
+ messagingSenderId?: string;
24
+ appId?: string;
25
+ measurementId?: string;
26
+ }
27
+ /**
28
+ * Represents the return type of an asynchronous Firebase operation.
29
+ *
30
+ * @interface IAsyncFirebaseReturnType
31
+ * @template T - The type of the result.
32
+ * @property {unknown | null} error - The error encountered during the asynchronous operation, if any.
33
+ * @property {T | null} result - The result of the asynchronous operation, if successful.
34
+ */
35
+ interface IAsyncFirebaseReturnType<T> {
36
+ error: unknown | null;
37
+ result: T | null;
38
+ }
39
+
40
+ /**
41
+ * Gets all documents from a collection in Firebase Firestore.
42
+ *
43
+ * @template T - The type of the documents.
44
+ * @param {Firestore} firestore - The Firestore instance.
45
+ * @param {string} c - The collection name.
46
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
47
+ */
48
+ declare const getAllDocuments: <T>(firestore: Firestore, c: string) => Promise<IAsyncFirebaseReturnType<T>>;
49
+ /**
50
+ * Gets a document from a collection in Firebase Firestore by its ID.
51
+ *
52
+ * @template T - The type of the document.
53
+ * @param {Firestore} firestore - The Firestore instance.
54
+ * @param {string} c - The collection name.
55
+ * @param {string} id - The ID of the document.
56
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
57
+ */
58
+ declare const getDocumentById: <T>(firestore: Firestore, c: string, id: string) => Promise<IAsyncFirebaseReturnType<T>>;
59
+ /**
60
+ * Adds a document to a collection in Firebase Firestore.
61
+ *
62
+ * @template T - The type of the document.
63
+ * @param {Firestore} firestore - The Firestore instance.
64
+ * @param {string} c - The collection name.
65
+ * @param {DocumentData} data - The data to add to the document.
66
+ * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
67
+ */
68
+ declare const addDocument: <T>(firestore: Firestore, c: string, data: DocumentData) => Promise<IAsyncFirebaseReturnType<T>>;
69
+ /**
70
+ * Sets a document in a collection in Firebase Firestore.
71
+ *
72
+ * @param {Firestore} firestore - The Firestore instance.
73
+ * @param {string} c - The collection name.
74
+ * @param {DocumentData} data - The data to set in the document.
75
+ * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
76
+ */
77
+ declare const setDocument: (firestore: Firestore, c: string, data: DocumentData) => Promise<TAsyncBoundary<void>>;
78
+ /**
79
+ * Deletes a document from a collection in Firebase Firestore.
80
+ *
81
+ * @param {Firestore} firestore - The Firestore instance.
82
+ * @param {string} c - The collection name.
83
+ * @param {string} id - The ID of the document to delete.
84
+ * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
85
+ */
86
+ declare const deleteDocument: (firestore: Firestore, c: string, id: string) => Promise<TAsyncBoundary<void>>;
87
+
88
+ /**
89
+ * Initializes a Firebase app.
90
+ *
91
+ * @param {IFirebaseConfig} config - The configuration for the Firebase app.
92
+ * @returns {Promise<FirebaseApp>} A promise that resolves to the initialized Firebase app.
93
+ */
94
+ declare const initFirebaseApp: (config: IFirebaseConfig) => Promise<FirebaseApp>;
95
+ /**
96
+ * Gets a Firestore instance.
97
+ *
98
+ * @param {FirebaseApp} app - The Firebase app.
99
+ * @returns {Promise<Firestore>} A promise that resolves to the Firestore instance.
100
+ */
101
+ declare const getFireStore: (app: FirebaseApp) => Promise<Firestore>;
102
+ /**
103
+ * Gets a Firebase Storage instance.
104
+ *
105
+ * @param {FirebaseApp} app - The Firebase app.
106
+ * @returns {Promise<FirebaseStorage>} A promise that resolves to the Firebase Storage instance.
107
+ */
108
+ declare const getFireStorage: (app: FirebaseApp) => Promise<FirebaseStorage>;
109
+
110
+ export { type IAsyncFirebaseReturnType, type IFirebaseConfig, addDocument, deleteDocument, getAllDocuments, getDocumentById, getFireStorage, getFireStore, initFirebaseApp, setDocument };
package/dist/index.js CHANGED
@@ -1,11 +1 @@
1
- import { bq as s, bs as a, bo as o, bp as b, bv as r, bu as m, bt as n, br as u } from "./index-TTt48kNP.js";
2
- export {
3
- s as addDocument,
4
- a as deleteDocument,
5
- o as getAllDocuments,
6
- b as getDocumentById,
7
- r as getFireStorage,
8
- m as getFireStore,
9
- n as initFirebaseApp,
10
- u as setDocument
11
- };
1
+ import {collection,getDocs,doc,getDoc,addDoc,setDoc,deleteDoc}from'firebase/firestore';import {tryDo,cast}from'@purr-core/utils.helpers';var R=async(t,o)=>{let e=collection(t,o),{error:n,result:r}=await tryDo(getDocs(e));if(n)return {error:n,result:null};let s=r?.docs?.map?.(u=>({...u.data(),id:u.id}));return {error:null,result:cast(s)}},h=async(t,o,e)=>{let n=doc(t,o,e),{error:r,result:s}=await tryDo(getDoc(n));return r?{error:r,result:null}:{error:null,result:cast(s?.data())}},w=async(t,o,e)=>{let n=collection(t,o),{error:r,result:s}=await tryDo(addDoc(n,e));return r?{error:r,result:null}:{error:null,result:cast(s)}},P=async(t,o,e)=>{let n=doc(t,o,e.id),{error:r,result:s}=await tryDo(setDoc(n,e,{merge:true}));return r?{error:r,result:null}:{error:null,result:s}},I=async(t,o,e)=>{let n=doc(t,o,e),{error:r,result:s}=await tryDo(deleteDoc(n));return r?{error:r,result:null}:{error:null,result:s}};var B=async t=>(await import('firebase/app').then(e=>e.default.initializeApp))(t),Q=async t=>(await import('firebase/firestore').then(e=>e.default.getFirestore))(t),z=async t=>(await import('firebase/storage').then(e=>e.default.getStorage))(t);export{w as addDocument,I as deleteDocument,R as getAllDocuments,h as getDocumentById,z as getFireStorage,Q as getFireStore,B as initFirebaseApp,P as setDocument};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purr-core/services.firebase",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -23,8 +23,8 @@
23
23
  "peerDependencies": {
24
24
  "typescript": "*",
25
25
  "firebase": "*",
26
- "@purr-core/utils.definitions": "0.0.10",
27
- "@purr-core/utils.helpers": "0.0.10"
26
+ "@purr-core/utils.definitions": "0.0.12",
27
+ "@purr-core/utils.helpers": "0.0.12"
28
28
  },
29
29
  "author": "@DinhThienPhuc",
30
30
  "license": "ISC",
@@ -33,6 +33,8 @@
33
33
  "scripts": {
34
34
  "dev": "vite build --watch",
35
35
  "build": "tsc && vite build",
36
+ "build:vite": "tsc && vite build",
37
+ "build:tsup": "tsup",
36
38
  "lint": "eslint . --ext ts,tsx --max-warnings 0"
37
39
  }
38
40
  }
package/dist/_api.d.ts DELETED
@@ -1,51 +0,0 @@
1
- import { DocumentData, Firestore } from 'firebase/firestore';
2
- import { TAsyncBoundary } from '@purr-core/utils.definitions';
3
- import { IAsyncFirebaseReturnType } from './_types';
4
-
5
- /**
6
- * Gets all documents from a collection in Firebase Firestore.
7
- *
8
- * @template T - The type of the documents.
9
- * @param {Firestore} firestore - The Firestore instance.
10
- * @param {string} c - The collection name.
11
- * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
12
- */
13
- export declare const getAllDocuments: <T>(firestore: Firestore, c: string) => Promise<IAsyncFirebaseReturnType<T>>;
14
- /**
15
- * Gets a document from a collection in Firebase Firestore by its ID.
16
- *
17
- * @template T - The type of the document.
18
- * @param {Firestore} firestore - The Firestore instance.
19
- * @param {string} c - The collection name.
20
- * @param {string} id - The ID of the document.
21
- * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
22
- */
23
- export declare const getDocumentById: <T>(firestore: Firestore, c: string, id: string) => Promise<IAsyncFirebaseReturnType<T>>;
24
- /**
25
- * Adds a document to a collection in Firebase Firestore.
26
- *
27
- * @template T - The type of the document.
28
- * @param {Firestore} firestore - The Firestore instance.
29
- * @param {string} c - The collection name.
30
- * @param {DocumentData} data - The data to add to the document.
31
- * @returns {Promise<IAsyncFirebaseReturnType<T>>} A promise that resolves to an object containing either the result or an error.
32
- */
33
- export declare const addDocument: <T>(firestore: Firestore, c: string, data: DocumentData) => Promise<IAsyncFirebaseReturnType<T>>;
34
- /**
35
- * Sets a document in a collection in Firebase Firestore.
36
- *
37
- * @param {Firestore} firestore - The Firestore instance.
38
- * @param {string} c - The collection name.
39
- * @param {DocumentData} data - The data to set in the document.
40
- * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
41
- */
42
- export declare const setDocument: (firestore: Firestore, c: string, data: DocumentData) => Promise<TAsyncBoundary<void>>;
43
- /**
44
- * Deletes a document from a collection in Firebase Firestore.
45
- *
46
- * @param {Firestore} firestore - The Firestore instance.
47
- * @param {string} c - The collection name.
48
- * @param {string} id - The ID of the document to delete.
49
- * @returns {Promise<TAsyncBoundary<void>>} A promise that resolves to an object containing either the result or an error.
50
- */
51
- export declare const deleteDocument: (firestore: Firestore, c: string, id: string) => Promise<TAsyncBoundary<void>>;
package/dist/_init.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { FirebaseApp } from 'firebase/app';
2
- import { Firestore } from 'firebase/firestore';
3
- import { FirebaseStorage } from 'firebase/storage';
4
- import { IFirebaseConfig } from './_types';
5
-
6
- /**
7
- * Initializes a Firebase app.
8
- *
9
- * @param {IFirebaseConfig} config - The configuration for the Firebase app.
10
- * @returns {Promise<FirebaseApp>} A promise that resolves to the initialized Firebase app.
11
- */
12
- export declare const initFirebaseApp: (config: IFirebaseConfig) => Promise<FirebaseApp>;
13
- /**
14
- * Gets a Firestore instance.
15
- *
16
- * @param {FirebaseApp} app - The Firebase app.
17
- * @returns {Promise<Firestore>} A promise that resolves to the Firestore instance.
18
- */
19
- export declare const getFireStore: (app: FirebaseApp) => Promise<Firestore>;
20
- /**
21
- * Gets a Firebase Storage instance.
22
- *
23
- * @param {FirebaseApp} app - The Firebase app.
24
- * @returns {Promise<FirebaseStorage>} A promise that resolves to the Firebase Storage instance.
25
- */
26
- export declare const getFireStorage: (app: FirebaseApp) => Promise<FirebaseStorage>;
package/dist/_types.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Represents the configuration for a Firebase project.
3
- *
4
- * @interface IFirebaseConfig
5
- * @property {string} [apiKey] - The API key for the Firebase project.
6
- * @property {string} [authDomain] - The authentication domain for the Firebase project.
7
- * @property {string} [projectId] - The project ID for the Firebase project.
8
- * @property {string} [storageBucket] - The storage bucket for the Firebase project.
9
- * @property {string} [messagingSenderId] - The messaging sender ID for the Firebase project.
10
- * @property {string} [appId] - The app ID for the Firebase project.
11
- * @property {string} [measurementId] - The measurement ID for the Firebase project.
12
- */
13
- export interface IFirebaseConfig {
14
- apiKey?: string;
15
- authDomain?: string;
16
- projectId?: string;
17
- storageBucket?: string;
18
- messagingSenderId?: string;
19
- appId?: string;
20
- measurementId?: string;
21
- }
22
- /**
23
- * Represents the return type of an asynchronous Firebase operation.
24
- *
25
- * @interface IAsyncFirebaseReturnType
26
- * @template T - The type of the result.
27
- * @property {unknown | null} error - The error encountered during the asynchronous operation, if any.
28
- * @property {T | null} result - The result of the asynchronous operation, if successful.
29
- */
30
- export interface IAsyncFirebaseReturnType<T> {
31
- error: unknown | null;
32
- result: T | null;
33
- }