@fyrestack/server 0.1.0 → 0.1.1

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,32 +1,7 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
1
  let firebase_admin_firestore = require("firebase-admin/firestore");
25
- firebase_admin_firestore = __toESM(firebase_admin_firestore);
26
- let __fyrestack_database = require("@fyrestack/database");
27
- __fyrestack_database = __toESM(__fyrestack_database);
2
+ let _fyrestack_database = require("@fyrestack/database");
28
3
 
29
- //#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
4
+ //#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
30
5
  function _typeof(o) {
31
6
  "@babel/helpers - typeof";
32
7
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
@@ -37,7 +12,7 @@ function _typeof(o) {
37
12
  }
38
13
 
39
14
  //#endregion
40
- //#region \0@oxc-project+runtime@0.95.0/helpers/toPrimitive.js
15
+ //#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
41
16
  function toPrimitive(t, r) {
42
17
  if ("object" != _typeof(t) || !t) return t;
43
18
  var e = t[Symbol.toPrimitive];
@@ -50,14 +25,14 @@ function toPrimitive(t, r) {
50
25
  }
51
26
 
52
27
  //#endregion
53
- //#region \0@oxc-project+runtime@0.95.0/helpers/toPropertyKey.js
28
+ //#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
54
29
  function toPropertyKey(t) {
55
30
  var i = toPrimitive(t, "string");
56
31
  return "symbol" == _typeof(i) ? i : i + "";
57
32
  }
58
33
 
59
34
  //#endregion
60
- //#region \0@oxc-project+runtime@0.95.0/helpers/defineProperty.js
35
+ //#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
61
36
  function _defineProperty(e, r, t) {
62
37
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
63
38
  value: t,
@@ -68,7 +43,7 @@ function _defineProperty(e, r, t) {
68
43
  }
69
44
 
70
45
  //#endregion
71
- //#region \0@oxc-project+runtime@0.95.0/helpers/objectSpread2.js
46
+ //#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
72
47
  function ownKeys(e, r) {
73
48
  var t = Object.keys(e);
74
49
  if (Object.getOwnPropertySymbols) {
@@ -94,19 +69,25 @@ function _objectSpread2(e) {
94
69
  //#endregion
95
70
  //#region src/index.ts
96
71
  /**
72
+ * Wraps a DocumentSnapshot to match our interface
73
+ */
74
+ function wrapDocumentSnapshot(snapshot) {
75
+ return {
76
+ id: snapshot.id,
77
+ exists: snapshot.exists,
78
+ data: () => snapshot.exists ? snapshot.data() : void 0
79
+ };
80
+ }
81
+ /**
97
82
  * Wraps a Firebase Admin DocumentReference to match our interface
98
83
  */
99
84
  function wrapDocumentReference(docRef) {
100
85
  return {
101
86
  id: docRef.id,
102
87
  path: docRef.path,
88
+ _native: docRef,
103
89
  async get() {
104
- const snapshot = await docRef.get();
105
- return {
106
- id: snapshot.id,
107
- exists: snapshot.exists,
108
- data: () => snapshot.exists ? snapshot.data() : void 0
109
- };
90
+ return wrapDocumentSnapshot(await docRef.get());
110
91
  },
111
92
  async set(data) {
112
93
  await docRef.set(data);
@@ -171,6 +152,52 @@ function wrapCollectionReference(collectionRef) {
171
152
  });
172
153
  }
173
154
  /**
155
+ * Wraps a Firebase Admin Transaction to match our abstract interface
156
+ */
157
+ function wrapTransaction(tx) {
158
+ const wrapper = {
159
+ get: async (docRef) => {
160
+ return wrapDocumentSnapshot(await tx.get(docRef._native));
161
+ },
162
+ set: (docRef, data) => {
163
+ tx.set(docRef._native, data);
164
+ return wrapper;
165
+ },
166
+ update: (docRef, data) => {
167
+ tx.update(docRef._native, data);
168
+ return wrapper;
169
+ },
170
+ delete: (docRef) => {
171
+ tx.delete(docRef._native);
172
+ return wrapper;
173
+ }
174
+ };
175
+ return wrapper;
176
+ }
177
+ /**
178
+ * Wraps a Firebase Admin WriteBatch to match our abstract interface
179
+ */
180
+ function wrapWriteBatch(batch) {
181
+ const wrapper = {
182
+ set: (docRef, data) => {
183
+ batch.set(docRef._native, data);
184
+ return wrapper;
185
+ },
186
+ update: (docRef, data) => {
187
+ batch.update(docRef._native, data);
188
+ return wrapper;
189
+ },
190
+ delete: (docRef) => {
191
+ batch.delete(docRef._native);
192
+ return wrapper;
193
+ },
194
+ commit: async () => {
195
+ await batch.commit();
196
+ }
197
+ };
198
+ return wrapper;
199
+ }
200
+ /**
174
201
  * Creates a FirestoreAdapter from a Firebase Admin Firestore instance
175
202
  */
176
203
  function createServerAdapter(firestore) {
@@ -183,6 +210,14 @@ function createServerAdapter(firestore) {
183
210
  },
184
211
  serverTimestamp() {
185
212
  return firebase_admin_firestore.FieldValue.serverTimestamp();
213
+ },
214
+ runTransaction(fn, options) {
215
+ return firestore.runTransaction(async (tx) => {
216
+ return fn(wrapTransaction(tx));
217
+ }, options);
218
+ },
219
+ batch() {
220
+ return wrapWriteBatch(firestore.batch());
186
221
  }
187
222
  };
188
223
  }
@@ -192,6 +227,6 @@ exports.createServerAdapter = createServerAdapter;
192
227
  Object.defineProperty(exports, 'setFirestoreAdapter', {
193
228
  enumerable: true,
194
229
  get: function () {
195
- return __fyrestack_database.setFirestoreAdapter;
230
+ return _fyrestack_database.setFirestoreAdapter;
196
231
  }
197
232
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;iBAqHgB,mBAAA,YAA+B,YAAY"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;iBA4LgB,mBAAA,YAA+B,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;iBAqHgB,mBAAA,YAA+B,YAAY"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;iBA4LgB,mBAAA,YAA+B,YAAY"}
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FieldValue } from "firebase-admin/firestore";
2
2
  import { setFirestoreAdapter } from "@fyrestack/database";
3
3
 
4
- //#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
4
+ //#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
5
5
  function _typeof(o) {
6
6
  "@babel/helpers - typeof";
7
7
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
@@ -12,7 +12,7 @@ function _typeof(o) {
12
12
  }
13
13
 
14
14
  //#endregion
15
- //#region \0@oxc-project+runtime@0.95.0/helpers/toPrimitive.js
15
+ //#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
16
16
  function toPrimitive(t, r) {
17
17
  if ("object" != _typeof(t) || !t) return t;
18
18
  var e = t[Symbol.toPrimitive];
@@ -25,14 +25,14 @@ function toPrimitive(t, r) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- //#region \0@oxc-project+runtime@0.95.0/helpers/toPropertyKey.js
28
+ //#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
29
29
  function toPropertyKey(t) {
30
30
  var i = toPrimitive(t, "string");
31
31
  return "symbol" == _typeof(i) ? i : i + "";
32
32
  }
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.95.0/helpers/defineProperty.js
35
+ //#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
36
36
  function _defineProperty(e, r, t) {
37
37
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
38
  value: t,
@@ -43,7 +43,7 @@ function _defineProperty(e, r, t) {
43
43
  }
44
44
 
45
45
  //#endregion
46
- //#region \0@oxc-project+runtime@0.95.0/helpers/objectSpread2.js
46
+ //#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
47
47
  function ownKeys(e, r) {
48
48
  var t = Object.keys(e);
49
49
  if (Object.getOwnPropertySymbols) {
@@ -69,19 +69,25 @@ function _objectSpread2(e) {
69
69
  //#endregion
70
70
  //#region src/index.ts
71
71
  /**
72
+ * Wraps a DocumentSnapshot to match our interface
73
+ */
74
+ function wrapDocumentSnapshot(snapshot) {
75
+ return {
76
+ id: snapshot.id,
77
+ exists: snapshot.exists,
78
+ data: () => snapshot.exists ? snapshot.data() : void 0
79
+ };
80
+ }
81
+ /**
72
82
  * Wraps a Firebase Admin DocumentReference to match our interface
73
83
  */
74
84
  function wrapDocumentReference(docRef) {
75
85
  return {
76
86
  id: docRef.id,
77
87
  path: docRef.path,
88
+ _native: docRef,
78
89
  async get() {
79
- const snapshot = await docRef.get();
80
- return {
81
- id: snapshot.id,
82
- exists: snapshot.exists,
83
- data: () => snapshot.exists ? snapshot.data() : void 0
84
- };
90
+ return wrapDocumentSnapshot(await docRef.get());
85
91
  },
86
92
  async set(data) {
87
93
  await docRef.set(data);
@@ -146,6 +152,52 @@ function wrapCollectionReference(collectionRef) {
146
152
  });
147
153
  }
148
154
  /**
155
+ * Wraps a Firebase Admin Transaction to match our abstract interface
156
+ */
157
+ function wrapTransaction(tx) {
158
+ const wrapper = {
159
+ get: async (docRef) => {
160
+ return wrapDocumentSnapshot(await tx.get(docRef._native));
161
+ },
162
+ set: (docRef, data) => {
163
+ tx.set(docRef._native, data);
164
+ return wrapper;
165
+ },
166
+ update: (docRef, data) => {
167
+ tx.update(docRef._native, data);
168
+ return wrapper;
169
+ },
170
+ delete: (docRef) => {
171
+ tx.delete(docRef._native);
172
+ return wrapper;
173
+ }
174
+ };
175
+ return wrapper;
176
+ }
177
+ /**
178
+ * Wraps a Firebase Admin WriteBatch to match our abstract interface
179
+ */
180
+ function wrapWriteBatch(batch) {
181
+ const wrapper = {
182
+ set: (docRef, data) => {
183
+ batch.set(docRef._native, data);
184
+ return wrapper;
185
+ },
186
+ update: (docRef, data) => {
187
+ batch.update(docRef._native, data);
188
+ return wrapper;
189
+ },
190
+ delete: (docRef) => {
191
+ batch.delete(docRef._native);
192
+ return wrapper;
193
+ },
194
+ commit: async () => {
195
+ await batch.commit();
196
+ }
197
+ };
198
+ return wrapper;
199
+ }
200
+ /**
149
201
  * Creates a FirestoreAdapter from a Firebase Admin Firestore instance
150
202
  */
151
203
  function createServerAdapter(firestore) {
@@ -158,6 +210,14 @@ function createServerAdapter(firestore) {
158
210
  },
159
211
  serverTimestamp() {
160
212
  return FieldValue.serverTimestamp();
213
+ },
214
+ runTransaction(fn, options) {
215
+ return firestore.runTransaction(async (tx) => {
216
+ return fn(wrapTransaction(tx));
217
+ }, options);
218
+ },
219
+ batch() {
220
+ return wrapWriteBatch(firestore.batch());
161
221
  }
162
222
  };
163
223
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Firebase Admin SDK Adapter for FyreStack\n *\n * Implements the FirestoreAdapter interface using firebase-admin\n * for server-side (Node.js) applications.\n */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\nimport type { Firestore } from 'firebase-admin/firestore';\nimport { FieldValue } from 'firebase-admin/firestore';\n\nimport type {\n CollectionReference,\n DocumentReference,\n DocumentSnapshot,\n FirestoreAdapter,\n OrderByDirection,\n QueryReference,\n QuerySnapshot,\n ServerTimestampSentinel,\n WhereFilterOp,\n} from '@fyrestack/database';\n\n/**\n * Wraps a Firebase Admin DocumentReference to match our interface\n */\nfunction wrapDocumentReference<T>(\n docRef: FirebaseFirestore.DocumentReference<FirebaseFirestore.DocumentData>,\n): DocumentReference<T> {\n return {\n id: docRef.id,\n path: docRef.path,\n async get(): Promise<DocumentSnapshot<T>> {\n const snapshot = await docRef.get();\n return {\n id: snapshot.id,\n exists: snapshot.exists,\n data: () => (snapshot.exists ? (snapshot.data() as T) : undefined),\n };\n },\n async set(data: T): Promise<void> {\n await docRef.set(data as FirebaseFirestore.DocumentData);\n },\n async update(data: Record<string, unknown>): Promise<void> {\n await docRef.update(data);\n },\n async delete(): Promise<void> {\n await docRef.delete();\n },\n };\n}\n\n/**\n * Wraps a Firebase Admin Query to match our QueryReference interface\n */\nfunction wrapQueryReference<T>(\n queryRef: FirebaseFirestore.Query<FirebaseFirestore.DocumentData>,\n): QueryReference<T> {\n return {\n where(field: string, op: WhereFilterOp, value: unknown): QueryReference<T> {\n return wrapQueryReference(queryRef.where(field, op, value));\n },\n orderBy(field: string, direction?: OrderByDirection): QueryReference<T> {\n return wrapQueryReference(queryRef.orderBy(field, direction));\n },\n limit(count: number): QueryReference<T> {\n return wrapQueryReference(queryRef.limit(count));\n },\n startAt(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.startAt(...values));\n },\n startAfter(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.startAfter(...values));\n },\n endAt(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.endAt(...values));\n },\n endBefore(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.endBefore(...values));\n },\n async get(): Promise<QuerySnapshot<T>> {\n const snapshot = await queryRef.get();\n return {\n docs: snapshot.docs.map((docSnap) => ({\n id: docSnap.id,\n exists: docSnap.exists,\n data: () => docSnap.data() as T,\n })),\n empty: snapshot.empty,\n size: snapshot.size,\n };\n },\n };\n}\n\n/**\n * Wraps a Firebase Admin CollectionReference to match our interface\n */\nfunction wrapCollectionReference<T>(\n collectionRef: FirebaseFirestore.CollectionReference<FirebaseFirestore.DocumentData>,\n): CollectionReference<T> {\n const queryRef = wrapQueryReference<T>(collectionRef);\n\n return {\n ...queryRef,\n path: collectionRef.path,\n doc(id?: string): DocumentReference<T> {\n const docRef = id ? collectionRef.doc(id) : collectionRef.doc();\n return wrapDocumentReference<T>(docRef);\n },\n };\n}\n\n/**\n * Creates a FirestoreAdapter from a Firebase Admin Firestore instance\n */\nexport function createServerAdapter(firestore: Firestore): FirestoreAdapter {\n return {\n collection<T>(path: string): CollectionReference<T> {\n const collectionRef = firestore.collection(path);\n return wrapCollectionReference<T>(collectionRef);\n },\n doc<T>(path: string): DocumentReference<T> {\n const docRef = firestore.doc(path);\n return wrapDocumentReference<T>(docRef);\n },\n serverTimestamp(): ServerTimestampSentinel {\n return FieldValue.serverTimestamp() as unknown as ServerTimestampSentinel;\n },\n };\n}\n\nexport { setFirestoreAdapter } from '@fyrestack/database';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,sBACP,QACsB;AACtB,QAAO;EACL,IAAI,OAAO;EACX,MAAM,OAAO;EACb,MAAM,MAAoC;GACxC,MAAM,WAAW,MAAM,OAAO,KAAK;AACnC,UAAO;IACL,IAAI,SAAS;IACb,QAAQ,SAAS;IACjB,YAAa,SAAS,SAAU,SAAS,MAAM,GAAS;IACzD;;EAEH,MAAM,IAAI,MAAwB;AAChC,SA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;;EAElD,IAAO,MAAoC;AAEzC,UAAO,sBADQ,UAAU,IAAI,KAAK,CACK;;EAEzC,kBAA2C;AACzC,UAAO,WAAW,iBAAiB;;EAEtC"}
1
+ {"version":3,"file":"index.mjs","names":["wrapper: Transaction","wrapper: WriteBatch"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Firebase Admin SDK Adapter for FyreStack\n *\n * Implements the FirestoreAdapter interface using firebase-admin\n * for server-side (Node.js) applications.\n */\nimport type { Firestore } from 'firebase-admin/firestore';\nimport { FieldValue } from 'firebase-admin/firestore';\n\nimport type {\n CollectionReference,\n DocumentReference,\n DocumentSnapshot,\n FirestoreAdapter,\n OrderByDirection,\n QueryReference,\n QuerySnapshot,\n ServerTimestampSentinel,\n Transaction,\n TransactionOptions,\n WhereFilterOp,\n WriteBatch,\n} from '@fyrestack/database';\n\n/**\n * Wraps a DocumentSnapshot to match our interface\n */\nfunction wrapDocumentSnapshot<T>(\n snapshot: FirebaseFirestore.DocumentSnapshot,\n): DocumentSnapshot<T> {\n return {\n id: snapshot.id,\n exists: snapshot.exists,\n data: () => (snapshot.exists ? (snapshot.data() as T) : undefined),\n };\n}\n\n/**\n * Wraps a Firebase Admin DocumentReference to match our interface\n */\nfunction wrapDocumentReference<T>(\n docRef: FirebaseFirestore.DocumentReference,\n): DocumentReference<T> {\n return {\n id: docRef.id,\n path: docRef.path,\n _native: docRef,\n async get(): Promise<DocumentSnapshot<T>> {\n const snapshot = await docRef.get();\n return wrapDocumentSnapshot<T>(snapshot);\n },\n async set(data: T): Promise<void> {\n await docRef.set(data as FirebaseFirestore.DocumentData);\n },\n async update(data: Record<string, unknown>): Promise<void> {\n await docRef.update(data);\n },\n async delete(): Promise<void> {\n await docRef.delete();\n },\n };\n}\n\n/**\n * Wraps a Firebase Admin Query to match our QueryReference interface\n */\nfunction wrapQueryReference<T>(\n queryRef: FirebaseFirestore.Query,\n): QueryReference<T> {\n return {\n where(field: string, op: WhereFilterOp, value: unknown): QueryReference<T> {\n return wrapQueryReference(queryRef.where(field, op, value));\n },\n orderBy(field: string, direction?: OrderByDirection): QueryReference<T> {\n return wrapQueryReference(queryRef.orderBy(field, direction));\n },\n limit(count: number): QueryReference<T> {\n return wrapQueryReference(queryRef.limit(count));\n },\n startAt(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.startAt(...values));\n },\n startAfter(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.startAfter(...values));\n },\n endAt(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.endAt(...values));\n },\n endBefore(...values: unknown[]): QueryReference<T> {\n return wrapQueryReference(queryRef.endBefore(...values));\n },\n async get(): Promise<QuerySnapshot<T>> {\n const snapshot = await queryRef.get();\n return {\n docs: snapshot.docs.map((docSnap) => ({\n id: docSnap.id,\n exists: docSnap.exists,\n data: () => docSnap.data() as T,\n })),\n empty: snapshot.empty,\n size: snapshot.size,\n };\n },\n };\n}\n\n/**\n * Wraps a Firebase Admin CollectionReference to match our interface\n */\nfunction wrapCollectionReference<T>(\n collectionRef: FirebaseFirestore.CollectionReference,\n): CollectionReference<T> {\n const queryRef = wrapQueryReference<T>(collectionRef);\n\n return {\n ...queryRef,\n path: collectionRef.path,\n doc(id?: string): DocumentReference<T> {\n const docRef = id ? collectionRef.doc(id) : collectionRef.doc();\n return wrapDocumentReference<T>(docRef);\n },\n };\n}\n\n/**\n * Wraps a Firebase Admin Transaction to match our abstract interface\n */\nfunction wrapTransaction(tx: FirebaseFirestore.Transaction): Transaction {\n const wrapper: Transaction = {\n get: async <T>(docRef: DocumentReference<T>) => {\n const snapshot = await tx.get(docRef._native as FirebaseFirestore.DocumentReference);\n return wrapDocumentSnapshot<T>(snapshot);\n },\n set: <T>(docRef: DocumentReference<T>, data: T) => {\n tx.set(\n docRef._native as FirebaseFirestore.DocumentReference,\n data as FirebaseFirestore.DocumentData,\n );\n return wrapper;\n },\n update: (docRef: DocumentReference, data: Record<string, unknown>) => {\n tx.update(\n docRef._native as FirebaseFirestore.DocumentReference,\n data as FirebaseFirestore.UpdateData<FirebaseFirestore.DocumentData>,\n );\n return wrapper;\n },\n delete: (docRef: DocumentReference) => {\n tx.delete(docRef._native as FirebaseFirestore.DocumentReference);\n return wrapper;\n },\n };\n return wrapper;\n}\n\n/**\n * Wraps a Firebase Admin WriteBatch to match our abstract interface\n */\nfunction wrapWriteBatch(batch: FirebaseFirestore.WriteBatch): WriteBatch {\n const wrapper: WriteBatch = {\n set: <T>(docRef: DocumentReference<T>, data: T) => {\n batch.set(\n docRef._native as FirebaseFirestore.DocumentReference,\n data as FirebaseFirestore.DocumentData,\n );\n return wrapper;\n },\n update: (docRef: DocumentReference, data: Record<string, unknown>) => {\n batch.update(\n docRef._native as FirebaseFirestore.DocumentReference,\n data as FirebaseFirestore.UpdateData<FirebaseFirestore.DocumentData>,\n );\n return wrapper;\n },\n delete: (docRef: DocumentReference) => {\n batch.delete(docRef._native as FirebaseFirestore.DocumentReference);\n return wrapper;\n },\n commit: async () => {\n await batch.commit();\n },\n };\n return wrapper;\n}\n\n/**\n * Creates a FirestoreAdapter from a Firebase Admin Firestore instance\n */\nexport function createServerAdapter(firestore: Firestore): FirestoreAdapter {\n return {\n collection<T>(path: string): CollectionReference<T> {\n const collectionRef = firestore.collection(path);\n return wrapCollectionReference<T>(collectionRef);\n },\n doc<T>(path: string): DocumentReference<T> {\n const docRef = firestore.doc(path);\n return wrapDocumentReference<T>(docRef);\n },\n serverTimestamp(): ServerTimestampSentinel {\n return FieldValue.serverTimestamp() as unknown as ServerTimestampSentinel;\n },\n runTransaction<T>(\n fn: (transaction: Transaction) => Promise<T>,\n options?: TransactionOptions,\n ): Promise<T> {\n return firestore.runTransaction<T>(async (tx) => {\n const wrappedTx = wrapTransaction(tx);\n return fn(wrappedTx);\n }, options);\n },\n batch(): WriteBatch {\n const nativeBatch = firestore.batch();\n return wrapWriteBatch(nativeBatch);\n },\n };\n}\n\nexport { setFirestoreAdapter } from '@fyrestack/database';\n"],"mappings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O;AAE/C,WAAO,GADW,gBAAgB,GAAG,CACjB;MACnB,QAAQ;;EAEb,QAAoB;AAElB,UAAO,eADa,UAAU,OAAO,CACH;;EAErC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fyrestack/server",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Firebase Admin SDK adapter for FyreStack",
5
5
  "license": "MIT",
6
6
  "author": "FyreStack",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "firebase-admin": "^13.0.2",
42
- "@fyrestack/database": "0.1.0"
42
+ "@fyrestack/database": "0.1.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsdown": "^0.18.0"