opticedge-cloud-utils 1.0.8 → 1.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/db/mongo.js CHANGED
@@ -3,16 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.connectToMongo = connectToMongo;
4
4
  exports.getCollection = getCollection;
5
5
  const mongodb_1 = require("mongodb");
6
- const secrets_1 = require("../utils/secrets"); // reuse your secret manager util
6
+ const secrets_1 = require("../utils/secrets");
7
7
  let client;
8
8
  let db;
9
+ let connectPromise;
9
10
  async function connectToMongo(projectId, uriSecret, dbName) {
10
- if (client)
11
- return;
12
- const uri = await (0, secrets_1.getSecret)(projectId, uriSecret);
13
- client = new mongodb_1.MongoClient(uri);
14
- await client.connect();
15
- db = client.db(dbName); // or pass DB name if needed
11
+ if (db)
12
+ return; // already connected
13
+ if (!connectPromise) {
14
+ connectPromise = (async () => {
15
+ const uri = await (0, secrets_1.getSecret)(projectId, uriSecret);
16
+ client = new mongodb_1.MongoClient(uri);
17
+ await client.connect();
18
+ db = client.db(dbName);
19
+ })();
20
+ }
21
+ await connectPromise;
16
22
  }
17
23
  function getCollection(name) {
18
24
  if (!db)
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './auth/verify';
2
2
  export * from './db/mongo';
3
+ export * from './types/pokemontcg';
3
4
  export * from './utils/env';
4
5
  export * from './utils/secrets';
5
6
  export * from './utils/task';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./auth/verify"), exports);
18
18
  __exportStar(require("./db/mongo"), exports);
19
+ __exportStar(require("./types/pokemontcg"), exports);
19
20
  __exportStar(require("./utils/env"), exports);
20
21
  __exportStar(require("./utils/secrets"), exports);
21
22
  __exportStar(require("./utils/task"), exports);
@@ -0,0 +1,115 @@
1
+ export type TCGPlayerPrices = {
2
+ low: number;
3
+ mid: number;
4
+ high: number;
5
+ market: number;
6
+ directLow: number;
7
+ };
8
+ export type CardMarketPrices = {
9
+ averageSellPrice: number;
10
+ lowPrice: number;
11
+ trendPrice: number;
12
+ germanProLow: number;
13
+ suggestedPrice: number;
14
+ reverseHoloSell: number;
15
+ reverseHoloLow: number;
16
+ reverseHoloTrend: number;
17
+ lowPriceExPlus: number;
18
+ avg1: number;
19
+ avg7: number;
20
+ avg30: number;
21
+ reverseHoloAvg1: number;
22
+ reverseHoloAvg7: number;
23
+ reverseHoloAvg30: number;
24
+ };
25
+ export type PokemonTCGCard = {
26
+ id: string;
27
+ name: string;
28
+ supertype: string;
29
+ subtypes: string[];
30
+ level: string;
31
+ hp: string;
32
+ evolvesFrom: string;
33
+ evolvesTo: string[];
34
+ rules: string[];
35
+ ancientTrait: {
36
+ name: string;
37
+ text: string;
38
+ };
39
+ abilities: [
40
+ {
41
+ name: string;
42
+ text: string;
43
+ type: string;
44
+ }
45
+ ];
46
+ attacks: [
47
+ {
48
+ cost: string[];
49
+ name: string;
50
+ text: string;
51
+ damage: string;
52
+ convertedEnergyCost: number;
53
+ }
54
+ ];
55
+ weaknesses: [
56
+ {
57
+ type: string;
58
+ value: string;
59
+ }
60
+ ];
61
+ resistances: [
62
+ {
63
+ type: string;
64
+ value: string;
65
+ }
66
+ ];
67
+ retreatCost: string[];
68
+ convertedRetreatCost: number;
69
+ set: {
70
+ id: string;
71
+ name: string;
72
+ series: string;
73
+ printedTotal: number;
74
+ total: number;
75
+ legalities: {
76
+ unlimited: string;
77
+ standard: string;
78
+ expanded: string;
79
+ };
80
+ ptcgoCode: string;
81
+ releaseDate: string;
82
+ updatedAt: string;
83
+ images: {
84
+ symbol: string;
85
+ logo: string;
86
+ };
87
+ };
88
+ number: string;
89
+ artist: string;
90
+ rarity: string;
91
+ flavorText: string;
92
+ nationalPokedexNumbers: number[];
93
+ legalities: [
94
+ {
95
+ standard: string;
96
+ expanded: string;
97
+ unlimited: string;
98
+ }
99
+ ];
100
+ regulationMark: string;
101
+ images: {
102
+ small: string;
103
+ large: string;
104
+ };
105
+ tcgplayer: {
106
+ url: string;
107
+ updatedAt: string;
108
+ prices: TCGPlayerPrices;
109
+ };
110
+ cardmarket: {
111
+ url: string;
112
+ updatedAt: string;
113
+ prices: CardMarketPrices;
114
+ };
115
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/db/mongo.ts CHANGED
@@ -1,16 +1,23 @@
1
1
  import { MongoClient, Db, Collection, Document } from 'mongodb'
2
- import { getSecret } from '../utils/secrets' // reuse your secret manager util
2
+ import { getSecret } from '../utils/secrets'
3
3
 
4
4
  let client: MongoClient
5
5
  let db: Db
6
+ let connectPromise: Promise<void> | undefined
6
7
 
7
8
  export async function connectToMongo(projectId: string, uriSecret: string, dbName: string) {
8
- if (client) return
9
+ if (db) return // already connected
9
10
 
10
- const uri = await getSecret(projectId, uriSecret)
11
- client = new MongoClient(uri)
12
- await client.connect()
13
- db = client.db(dbName) // or pass DB name if needed
11
+ if (!connectPromise) {
12
+ connectPromise = (async () => {
13
+ const uri = await getSecret(projectId, uriSecret)
14
+ client = new MongoClient(uri)
15
+ await client.connect()
16
+ db = client.db(dbName)
17
+ })()
18
+ }
19
+
20
+ await connectPromise
14
21
  }
15
22
 
16
23
  export function getCollection<T extends Document = Document>(name: string): Collection<T> {
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './auth/verify'
2
2
  export * from './db/mongo'
3
+ export * from './types/pokemontcg'
3
4
  export * from './utils/env'
4
5
  export * from './utils/secrets'
5
- export * from './utils/task'
6
+ export * from './utils/task'
@@ -0,0 +1,117 @@
1
+ export type TCGPlayerPrices = {
2
+ low: number
3
+ mid: number
4
+ high: number
5
+ market: number
6
+ directLow: number
7
+ }
8
+
9
+ export type CardMarketPrices = {
10
+ averageSellPrice: number
11
+ lowPrice: number
12
+ trendPrice: number
13
+ germanProLow: number
14
+ suggestedPrice: number
15
+ reverseHoloSell: number
16
+ reverseHoloLow: number
17
+ reverseHoloTrend: number
18
+ lowPriceExPlus: number
19
+ avg1: number
20
+ avg7: number
21
+ avg30: number
22
+ reverseHoloAvg1: number
23
+ reverseHoloAvg7: number
24
+ reverseHoloAvg30: number
25
+ }
26
+
27
+ export type PokemonTCGCard = {
28
+ id: string
29
+ name: string
30
+ supertype: string
31
+ subtypes: string[]
32
+ level: string
33
+ hp: string
34
+ evolvesFrom: string
35
+ evolvesTo: string[]
36
+ rules: string[]
37
+ ancientTrait: {
38
+ name: string
39
+ text: string
40
+ }
41
+ abilities: [
42
+ {
43
+ name: string
44
+ text: string
45
+ type: string
46
+ },
47
+ ]
48
+ attacks: [
49
+ {
50
+ cost: string[]
51
+ name: string
52
+ text: string
53
+ damage: string
54
+ convertedEnergyCost: number
55
+ },
56
+ ]
57
+ weaknesses: [
58
+ {
59
+ type: string
60
+ value: string
61
+ },
62
+ ]
63
+ resistances: [
64
+ {
65
+ type: string
66
+ value: string
67
+ },
68
+ ]
69
+ retreatCost: string[]
70
+ convertedRetreatCost: number
71
+ set: {
72
+ id: string
73
+ name: string
74
+ series: string
75
+ printedTotal: number
76
+ total: number
77
+ legalities: {
78
+ unlimited: string
79
+ standard: string
80
+ expanded: string
81
+ }
82
+ ptcgoCode: string
83
+ releaseDate: string
84
+ updatedAt: string
85
+ images: {
86
+ symbol: string
87
+ logo: string
88
+ }
89
+ }
90
+ number: string
91
+ artist: string
92
+ rarity: string
93
+ flavorText: string
94
+ nationalPokedexNumbers: number[]
95
+ legalities: [
96
+ {
97
+ standard: string
98
+ expanded: string
99
+ unlimited: string
100
+ },
101
+ ]
102
+ regulationMark: string
103
+ images: {
104
+ small: string
105
+ large: string
106
+ }
107
+ tcgplayer: {
108
+ url: string
109
+ updatedAt: string
110
+ prices: TCGPlayerPrices
111
+ }
112
+ cardmarket: {
113
+ url: string
114
+ updatedAt: string
115
+ prices: CardMarketPrices
116
+ }
117
+ }