@cravery/firebase 0.0.40 → 0.0.41

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.
@@ -0,0 +1,11 @@
1
+ import { Timestamp } from "firebase-admin/firestore";
2
+ interface CursorData {
3
+ t: number;
4
+ i: string;
5
+ }
6
+ export declare function encodeCursor(timestamp: Timestamp, id: string): string;
7
+ export declare function decodeCursor(cursor: string): CursorData;
8
+ export declare function cursorToTimestamp(cursor: string): Timestamp;
9
+ export declare function cursorToValues(cursor: string): [Timestamp, string];
10
+ export {};
11
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/lib/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,UAAU,UAAU;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAMrE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CASvD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAG3D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAGlE"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeCursor = encodeCursor;
4
+ exports.decodeCursor = decodeCursor;
5
+ exports.cursorToTimestamp = cursorToTimestamp;
6
+ exports.cursorToValues = cursorToValues;
7
+ const firestore_1 = require("firebase-admin/firestore");
8
+ function encodeCursor(timestamp, id) {
9
+ const data = {
10
+ t: timestamp.toMillis(),
11
+ i: id,
12
+ };
13
+ return Buffer.from(JSON.stringify(data)).toString("base64url");
14
+ }
15
+ function decodeCursor(cursor) {
16
+ const json = Buffer.from(cursor, "base64url").toString("utf-8");
17
+ const data = JSON.parse(json);
18
+ if (typeof data.t !== "number" || typeof data.i !== "string") {
19
+ throw new Error("Invalid cursor");
20
+ }
21
+ return data;
22
+ }
23
+ function cursorToTimestamp(cursor) {
24
+ const { t } = decodeCursor(cursor);
25
+ return firestore_1.Timestamp.fromMillis(t);
26
+ }
27
+ function cursorToValues(cursor) {
28
+ const { t, i } = decodeCursor(cursor);
29
+ return [firestore_1.Timestamp.fromMillis(t), i];
30
+ }
31
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","sourceRoot":"","sources":["../../src/lib/cursor.ts"],"names":[],"mappings":";;AAOA,oCAMC;AAED,oCASC;AAED,8CAGC;AAED,wCAGC;AAlCD,wDAAqD;AAOrD,SAAgB,YAAY,CAAC,SAAoB,EAAE,EAAU;IAC3D,MAAM,IAAI,GAAe;QACvB,CAAC,EAAE,SAAS,CAAC,QAAQ,EAAE;QACvB,CAAC,EAAE,EAAE;KACN,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACjE,CAAC;AAED,SAAgB,YAAY,CAAC,MAAc;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAe,CAAC;IAE5C,IAAI,OAAO,IAAI,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,MAAM,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,qBAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,CAAC,qBAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtC,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from "./cursor";
1
2
  export * from "./monitoring";
2
3
  export * from "./strip-undefined";
3
4
  export * from "./timestamp";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
package/dist/lib/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cursor"), exports);
17
18
  __exportStar(require("./monitoring"), exports);
18
19
  __exportStar(require("./strip-undefined"), exports);
19
20
  __exportStar(require("./timestamp"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,oDAAkC;AAClC,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,oDAAkC;AAClC,8CAA4B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cravery/firebase",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "Shared Firebase Admin SDK utilities for Cravery",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "typescript": "^5.9.3"
29
29
  },
30
30
  "dependencies": {
31
- "@cravery/core": "^0.0.62",
31
+ "@cravery/core": "^0.0.63",
32
32
  "@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.21.0",
33
33
  "@opentelemetry/api": "^1.9.0",
34
34
  "@opentelemetry/resources": "^2.4.0",
@@ -0,0 +1,35 @@
1
+ import { Timestamp } from "firebase-admin/firestore";
2
+
3
+ interface CursorData {
4
+ t: number;
5
+ i: string;
6
+ }
7
+
8
+ export function encodeCursor(timestamp: Timestamp, id: string): string {
9
+ const data: CursorData = {
10
+ t: timestamp.toMillis(),
11
+ i: id,
12
+ };
13
+ return Buffer.from(JSON.stringify(data)).toString("base64url");
14
+ }
15
+
16
+ export function decodeCursor(cursor: string): CursorData {
17
+ const json = Buffer.from(cursor, "base64url").toString("utf-8");
18
+ const data = JSON.parse(json) as CursorData;
19
+
20
+ if (typeof data.t !== "number" || typeof data.i !== "string") {
21
+ throw new Error("Invalid cursor");
22
+ }
23
+
24
+ return data;
25
+ }
26
+
27
+ export function cursorToTimestamp(cursor: string): Timestamp {
28
+ const { t } = decodeCursor(cursor);
29
+ return Timestamp.fromMillis(t);
30
+ }
31
+
32
+ export function cursorToValues(cursor: string): [Timestamp, string] {
33
+ const { t, i } = decodeCursor(cursor);
34
+ return [Timestamp.fromMillis(t), i];
35
+ }
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./cursor";
1
2
  export * from "./monitoring";
2
3
  export * from "./strip-undefined";
3
4
  export * from "./timestamp";