@digitalaidseattle/firebase 1.0.12 → 1.0.13

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.
@@ -1,8 +1,10 @@
1
1
  import { Entity, EntityService, Identifier, User } from "@digitalaidseattle/core";
2
+ import { Firestore } from "firebase/firestore";
3
+ import { FirebaseApp } from "firebase/app";
2
4
  declare class FirestoreService<T extends Entity> implements EntityService<T> {
3
5
  collectionName: string;
4
- db: import("@firebase/firestore").Firestore;
5
- constructor(collectionName: string);
6
+ db: Firestore;
7
+ constructor(collectionName: string, firebaseClient?: FirebaseApp);
6
8
  getAll(count?: number, select?: string, mapper?: (json: any) => T): Promise<T[]>;
7
9
  getById(id: string, select?: string, mapper?: (json: any) => T): Promise<T>;
8
10
  batchInsert(entities: T[], select?: string, mapper?: (json: any) => T, user?: User): Promise<T[]>;
@@ -12,4 +14,3 @@ declare class FirestoreService<T extends Entity> implements EntityService<T> {
12
14
  upsert(entity: T): Promise<T>;
13
15
  }
14
16
  export { FirestoreService };
15
- export type { Entity };
@@ -2,4 +2,3 @@ export * from "./FirebaseAuthService.js";
2
2
  export * from "./firebaseClient.js";
3
3
  export * from "./FirebaseStorageService.js";
4
4
  export * from "./FirestoreService.js";
5
- export * from "./GeminiService.js";
@@ -12,8 +12,6 @@ var app = require('firebase/app');
12
12
  var storage = require('firebase/storage');
13
13
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
14
14
  var firestore = require('firebase/firestore');
15
- var firebase = require('@digitalaidseattle/firebase');
16
- var ai = require('firebase/ai');
17
15
 
18
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
19
17
 
@@ -316,11 +314,10 @@ var FirebaseStorageService = /*#__PURE__*/function () {
316
314
  }();
317
315
 
318
316
  var FirestoreService = /*#__PURE__*/function () {
319
- function FirestoreService(collectionName) {
317
+ function FirestoreService(collectionName, firebaseClient$1) {
320
318
  _classCallCheck(this, FirestoreService);
321
- _defineProperty(this, "collectionName", "player");
322
- _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
323
319
  this.collectionName = collectionName;
320
+ this.db = firestore.getFirestore(firebaseClient$1 !== null && firebaseClient$1 !== void 0 ? firebaseClient$1 : firebaseClient);
324
321
  }
325
322
 
326
323
  // Get all documents from a collection
@@ -490,7 +487,6 @@ var FirestoreService = /*#__PURE__*/function () {
490
487
  return _regeneratorRuntime__default["default"].wrap(function (_context6) {
491
488
  while (1) switch (_context6.prev = _context6.next) {
492
489
  case 0:
493
- console.log('delete', entityId);
494
490
  return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
495
491
  case 1:
496
492
  case "end":
@@ -528,87 +524,7 @@ var FirestoreService = /*#__PURE__*/function () {
528
524
  }]);
529
525
  }();
530
526
 
531
- var GeminiService = /*#__PURE__*/function () {
532
- function GeminiService(modelType) {
533
- _classCallCheck(this, GeminiService);
534
- this.ai = ai.getAI(firebase.firebaseClient, {
535
- backend: new ai.GoogleAIBackend()
536
- });
537
- }
538
- return _createClass(GeminiService, [{
539
- key: "getModels",
540
- value: function getModels() {
541
- return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
542
- }
543
- }, {
544
- key: "calcTokenCount",
545
- value: function calcTokenCount(model, prompt) {
546
- return ai.getGenerativeModel(this.ai, {
547
- model: model
548
- }).countTokens(prompt).then(function (response) {
549
- return response.totalTokens;
550
- });
551
- }
552
-
553
- // Wrap in an async function so you can use await
554
- }, {
555
- key: "generateContent",
556
- value: function generateContent(model, prompt) {
557
- // To generate text output, call generateContent with the text input
558
- console.log('generateContent', model, prompt);
559
- return ai.getGenerativeModel(this.ai, {
560
- model: model
561
- }).generateContent(prompt).then(function (result) {
562
- return result.response.text();
563
- })["catch"](function (error) {
564
- console.error("Error querying AI: ", error);
565
- throw new Error("Failed to query AI: " + error.message);
566
- });
567
- }
568
-
569
- // Wrap in an async function so you can use await
570
- }, {
571
- key: "generateParameterizedContent",
572
- value: function generateParameterizedContent(model, prompt, schemaParams) {
573
- // Provide a JSON schema object using a standard format.
574
- // Later, pass this schema object into `responseSchema` in the generation config.
575
- var schema = ai.Schema.object({
576
- properties: {
577
- characters: ai.Schema.array({
578
- items: ai.Schema.object({
579
- properties: Object.fromEntries(schemaParams.map(function (field) {
580
- return [field, ai.Schema.string()];
581
- }))
582
- })
583
- })
584
- }
585
- });
586
-
587
- // Create a `GenerativeModel` instance with a model that supports your use case
588
- var jModel = ai.getGenerativeModel(this.ai, {
589
- model: model,
590
- // In the generation config, set the `responseMimeType` to `application/json`
591
- // and pass the JSON schema object into `responseSchema`.
592
- generationConfig: {
593
- responseMimeType: "application/json",
594
- responseSchema: schema
595
- }
596
- });
597
-
598
- // To generate text output, call generateContent with the text input
599
- return jModel.generateContent(prompt).then(function (result) {
600
- var content = result.response.text();
601
- return JSON.parse(content).characters[0];
602
- })["catch"](function (error) {
603
- console.error("Error querying AI: ", error);
604
- throw new Error("Failed to query AI: " + error.message);
605
- });
606
- }
607
- }]);
608
- }();
609
-
610
527
  exports.FirebaseAuthService = FirebaseAuthService;
611
528
  exports.FirebaseStorageService = FirebaseStorageService;
612
529
  exports.FirestoreService = FirestoreService;
613
- exports.GeminiService = GeminiService;
614
530
  exports.firebaseClient = firebaseClient;
@@ -12,8 +12,6 @@ var app = require('firebase/app');
12
12
  var storage = require('firebase/storage');
13
13
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
14
14
  var firestore = require('firebase/firestore');
15
- var firebase = require('@digitalaidseattle/firebase');
16
- var ai = require('firebase/ai');
17
15
 
18
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
19
17
 
@@ -316,11 +314,10 @@ var FirebaseStorageService = /*#__PURE__*/function () {
316
314
  }();
317
315
 
318
316
  var FirestoreService = /*#__PURE__*/function () {
319
- function FirestoreService(collectionName) {
317
+ function FirestoreService(collectionName, firebaseClient$1) {
320
318
  _classCallCheck(this, FirestoreService);
321
- _defineProperty(this, "collectionName", "player");
322
- _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
323
319
  this.collectionName = collectionName;
320
+ this.db = firestore.getFirestore(firebaseClient$1 !== null && firebaseClient$1 !== void 0 ? firebaseClient$1 : firebaseClient);
324
321
  }
325
322
 
326
323
  // Get all documents from a collection
@@ -490,7 +487,6 @@ var FirestoreService = /*#__PURE__*/function () {
490
487
  return _regeneratorRuntime__default["default"].wrap(function (_context6) {
491
488
  while (1) switch (_context6.prev = _context6.next) {
492
489
  case 0:
493
- console.log('delete', entityId);
494
490
  return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
495
491
  case 1:
496
492
  case "end":
@@ -528,87 +524,7 @@ var FirestoreService = /*#__PURE__*/function () {
528
524
  }]);
529
525
  }();
530
526
 
531
- var GeminiService = /*#__PURE__*/function () {
532
- function GeminiService(modelType) {
533
- _classCallCheck(this, GeminiService);
534
- this.ai = ai.getAI(firebase.firebaseClient, {
535
- backend: new ai.GoogleAIBackend()
536
- });
537
- }
538
- return _createClass(GeminiService, [{
539
- key: "getModels",
540
- value: function getModels() {
541
- return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
542
- }
543
- }, {
544
- key: "calcTokenCount",
545
- value: function calcTokenCount(model, prompt) {
546
- return ai.getGenerativeModel(this.ai, {
547
- model: model
548
- }).countTokens(prompt).then(function (response) {
549
- return response.totalTokens;
550
- });
551
- }
552
-
553
- // Wrap in an async function so you can use await
554
- }, {
555
- key: "generateContent",
556
- value: function generateContent(model, prompt) {
557
- // To generate text output, call generateContent with the text input
558
- console.log('generateContent', model, prompt);
559
- return ai.getGenerativeModel(this.ai, {
560
- model: model
561
- }).generateContent(prompt).then(function (result) {
562
- return result.response.text();
563
- })["catch"](function (error) {
564
- console.error("Error querying AI: ", error);
565
- throw new Error("Failed to query AI: " + error.message);
566
- });
567
- }
568
-
569
- // Wrap in an async function so you can use await
570
- }, {
571
- key: "generateParameterizedContent",
572
- value: function generateParameterizedContent(model, prompt, schemaParams) {
573
- // Provide a JSON schema object using a standard format.
574
- // Later, pass this schema object into `responseSchema` in the generation config.
575
- var schema = ai.Schema.object({
576
- properties: {
577
- characters: ai.Schema.array({
578
- items: ai.Schema.object({
579
- properties: Object.fromEntries(schemaParams.map(function (field) {
580
- return [field, ai.Schema.string()];
581
- }))
582
- })
583
- })
584
- }
585
- });
586
-
587
- // Create a `GenerativeModel` instance with a model that supports your use case
588
- var jModel = ai.getGenerativeModel(this.ai, {
589
- model: model,
590
- // In the generation config, set the `responseMimeType` to `application/json`
591
- // and pass the JSON schema object into `responseSchema`.
592
- generationConfig: {
593
- responseMimeType: "application/json",
594
- responseSchema: schema
595
- }
596
- });
597
-
598
- // To generate text output, call generateContent with the text input
599
- return jModel.generateContent(prompt).then(function (result) {
600
- var content = result.response.text();
601
- return JSON.parse(content).characters[0];
602
- })["catch"](function (error) {
603
- console.error("Error querying AI: ", error);
604
- throw new Error("Failed to query AI: " + error.message);
605
- });
606
- }
607
- }]);
608
- }();
609
-
610
527
  exports.FirebaseAuthService = FirebaseAuthService;
611
528
  exports.FirebaseStorageService = FirebaseStorageService;
612
529
  exports.FirestoreService = FirestoreService;
613
- exports.GeminiService = GeminiService;
614
530
  exports.firebaseClient = firebaseClient;
@@ -8,8 +8,6 @@ import { initializeApp } from 'firebase/app';
8
8
  import { ref, getDownloadURL, getBytes, deleteObject, getMetadata, listAll, uploadBytes, getStorage } from 'firebase/storage';
9
9
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
10
10
  import { getDocs, collection, getDoc, doc, addDoc, updateDoc, deleteDoc, setDoc, getFirestore } from 'firebase/firestore';
11
- import { firebaseClient as firebaseClient$1 } from '@digitalaidseattle/firebase';
12
- import { getGenerativeModel, Schema, getAI, GoogleAIBackend } from 'firebase/ai';
13
11
 
14
12
  var FirebaseAuthService = /*#__PURE__*/function () {
15
13
  function FirebaseAuthService(firebaseClient) {
@@ -308,11 +306,10 @@ var FirebaseStorageService = /*#__PURE__*/function () {
308
306
  }();
309
307
 
310
308
  var FirestoreService = /*#__PURE__*/function () {
311
- function FirestoreService(collectionName) {
309
+ function FirestoreService(collectionName, firebaseClient$1) {
312
310
  _classCallCheck(this, FirestoreService);
313
- _defineProperty(this, "collectionName", "player");
314
- _defineProperty(this, "db", getFirestore(firebaseClient));
315
311
  this.collectionName = collectionName;
312
+ this.db = getFirestore(firebaseClient$1 !== null && firebaseClient$1 !== void 0 ? firebaseClient$1 : firebaseClient);
316
313
  }
317
314
 
318
315
  // Get all documents from a collection
@@ -482,7 +479,6 @@ var FirestoreService = /*#__PURE__*/function () {
482
479
  return _regeneratorRuntime.wrap(function (_context6) {
483
480
  while (1) switch (_context6.prev = _context6.next) {
484
481
  case 0:
485
- console.log('delete', entityId);
486
482
  return _context6.abrupt("return", deleteDoc(doc(this.db, this.collectionName, entityId)));
487
483
  case 1:
488
484
  case "end":
@@ -520,83 +516,4 @@ var FirestoreService = /*#__PURE__*/function () {
520
516
  }]);
521
517
  }();
522
518
 
523
- var GeminiService = /*#__PURE__*/function () {
524
- function GeminiService(modelType) {
525
- _classCallCheck(this, GeminiService);
526
- this.ai = getAI(firebaseClient$1, {
527
- backend: new GoogleAIBackend()
528
- });
529
- }
530
- return _createClass(GeminiService, [{
531
- key: "getModels",
532
- value: function getModels() {
533
- return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
534
- }
535
- }, {
536
- key: "calcTokenCount",
537
- value: function calcTokenCount(model, prompt) {
538
- return getGenerativeModel(this.ai, {
539
- model: model
540
- }).countTokens(prompt).then(function (response) {
541
- return response.totalTokens;
542
- });
543
- }
544
-
545
- // Wrap in an async function so you can use await
546
- }, {
547
- key: "generateContent",
548
- value: function generateContent(model, prompt) {
549
- // To generate text output, call generateContent with the text input
550
- console.log('generateContent', model, prompt);
551
- return getGenerativeModel(this.ai, {
552
- model: model
553
- }).generateContent(prompt).then(function (result) {
554
- return result.response.text();
555
- })["catch"](function (error) {
556
- console.error("Error querying AI: ", error);
557
- throw new Error("Failed to query AI: " + error.message);
558
- });
559
- }
560
-
561
- // Wrap in an async function so you can use await
562
- }, {
563
- key: "generateParameterizedContent",
564
- value: function generateParameterizedContent(model, prompt, schemaParams) {
565
- // Provide a JSON schema object using a standard format.
566
- // Later, pass this schema object into `responseSchema` in the generation config.
567
- var schema = Schema.object({
568
- properties: {
569
- characters: Schema.array({
570
- items: Schema.object({
571
- properties: Object.fromEntries(schemaParams.map(function (field) {
572
- return [field, Schema.string()];
573
- }))
574
- })
575
- })
576
- }
577
- });
578
-
579
- // Create a `GenerativeModel` instance with a model that supports your use case
580
- var jModel = getGenerativeModel(this.ai, {
581
- model: model,
582
- // In the generation config, set the `responseMimeType` to `application/json`
583
- // and pass the JSON schema object into `responseSchema`.
584
- generationConfig: {
585
- responseMimeType: "application/json",
586
- responseSchema: schema
587
- }
588
- });
589
-
590
- // To generate text output, call generateContent with the text input
591
- return jModel.generateContent(prompt).then(function (result) {
592
- var content = result.response.text();
593
- return JSON.parse(content).characters[0];
594
- })["catch"](function (error) {
595
- console.error("Error querying AI: ", error);
596
- throw new Error("Failed to query AI: " + error.message);
597
- });
598
- }
599
- }]);
600
- }();
601
-
602
- export { FirebaseAuthService, FirebaseStorageService, FirestoreService, GeminiService, firebaseClient };
519
+ export { FirebaseAuthService, FirebaseStorageService, FirestoreService, firebaseClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalaidseattle/firebase",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Wrapper for firebase that works with DAS Component library",
5
5
  "repository": "null//github.com/null/github.com/tree/master/packages/firebase",
6
6
  "main": "dist/digitalaidseattle-firebase.cjs.js",
@@ -1,25 +0,0 @@
1
- /**
2
- * Institution AI Service
3
- *
4
- *
5
- * Provision Firebase application in Google Cloud
6
- * <ol>
7
- * <li>Go to the Google Cloud Console.</li>
8
- * <li>Select an existing project.</li>
9
- * <li>Navigate to the "APIs & Services" page.</li>
10
- * <li>Click on "Credential".</li>
11
- * <li>Edit API (the key should match the API key in the .env file).</li>
12
- * <li>Enable the "Generative Language API" and "Firebase AI Logic API" restrictions.</li>
13
- * </ol>
14
- */
15
- import { AiService } from "@digitalaidseattle/core";
16
- import { AI } from "firebase/ai";
17
- declare class GeminiService implements AiService {
18
- ai: AI;
19
- constructor(modelType?: string);
20
- getModels(): string[];
21
- calcTokenCount(model: string, prompt: string): Promise<number>;
22
- generateContent(model: string, prompt: string): Promise<any>;
23
- generateParameterizedContent(model: string, prompt: string, schemaParams: string[]): Promise<any>;
24
- }
25
- export { GeminiService };