@cravery/firebase 0.0.42 → 0.0.44

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,2 @@
1
+ export * from "./usage";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converters/access/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./usage"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/converters/access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
@@ -0,0 +1,4 @@
1
+ import { FirestoreDataConverter } from "firebase-admin/firestore";
2
+ import type { UsagePeriod } from "@cravery/core";
3
+ export declare const usagePeriodConverter: FirestoreDataConverter<UsagePeriod>;
4
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/converters/access/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAGvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAOjD,eAAO,MAAM,oBAAoB,EAAE,sBAAsB,CAAC,WAAW,CAepE,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usagePeriodConverter = void 0;
4
+ const lib_1 = require("../../lib");
5
+ exports.usagePeriodConverter = {
6
+ toFirestore(usage) {
7
+ return (0, lib_1.stripUndefined)({
8
+ counts: usage.counts,
9
+ updatedAt: (0, lib_1.toFirestoreTimestamp)(usage.updatedAt),
10
+ });
11
+ },
12
+ fromFirestore(snapshot) {
13
+ var _a;
14
+ const data = snapshot.data();
15
+ return {
16
+ counts: (_a = data.counts) !== null && _a !== void 0 ? _a : {},
17
+ updatedAt: (0, lib_1.toTimestamp)(data.updatedAt),
18
+ };
19
+ },
20
+ };
21
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/converters/access/usage.ts"],"names":[],"mappings":";;;AAMA,mCAImB;AAEN,QAAA,oBAAoB,GAAwC;IACvE,WAAW,CAAC,KAAkB;QAC5B,OAAO,IAAA,oBAAc,EAAC;YACpB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,IAAA,0BAAoB,EAAC,KAAK,CAAC,SAAS,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;IAED,aAAa,CAAC,QAA+B;;QAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,EAAE;YACzB,SAAS,EAAE,IAAA,iBAAW,EAAC,IAAI,CAAC,SAAS,CAAC;SACvC,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from "./access";
1
2
  export * from "./equipment";
2
3
  export * from "./ingredients";
3
4
  export * from "./recipes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
@@ -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("./access"), exports);
17
18
  __exportStar(require("./equipment"), exports);
18
19
  __exportStar(require("./ingredients"), exports);
19
20
  __exportStar(require("./recipes"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,kDAAgC;AAChC,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B;AAC5B,gDAA8B;AAC9B,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,kDAAgC;AAChC,0CAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cravery/firebase",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
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.64",
31
+ "@cravery/core": "^0.0.66",
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 @@
1
+ export * from "./usage";
@@ -0,0 +1,28 @@
1
+ import {
2
+ FirestoreDataConverter,
3
+ QueryDocumentSnapshot,
4
+ DocumentData,
5
+ } from "firebase-admin/firestore";
6
+ import type { UsagePeriod } from "@cravery/core";
7
+ import {
8
+ toTimestamp,
9
+ toFirestoreTimestamp,
10
+ stripUndefined,
11
+ } from "../../lib";
12
+
13
+ export const usagePeriodConverter: FirestoreDataConverter<UsagePeriod> = {
14
+ toFirestore(usage: UsagePeriod): DocumentData {
15
+ return stripUndefined({
16
+ counts: usage.counts,
17
+ updatedAt: toFirestoreTimestamp(usage.updatedAt),
18
+ });
19
+ },
20
+
21
+ fromFirestore(snapshot: QueryDocumentSnapshot): UsagePeriod {
22
+ const data = snapshot.data();
23
+ return {
24
+ counts: data.counts ?? {},
25
+ updatedAt: toTimestamp(data.updatedAt),
26
+ };
27
+ },
28
+ };
@@ -1,3 +1,4 @@
1
+ export * from "./access";
1
2
  export * from "./equipment";
2
3
  export * from "./ingredients";
3
4
  export * from "./recipes";
@@ -1,36 +1,36 @@
1
- import {
2
- FirestoreDataConverter,
3
- QueryDocumentSnapshot,
4
- DocumentData,
5
- } from "firebase-admin/firestore";
6
- import type { Request } from "@cravery/core";
7
- import {
8
- toTimestamp,
9
- toOptionalTimestamp,
10
- toFirestoreTimestamp,
11
- toOptionalFirestoreTimestamp,
12
- stripUndefined,
13
- } from "../../lib";
14
-
15
- export const requestConverter: FirestoreDataConverter<Request> = {
16
- toFirestore(request: Request): DocumentData {
17
- const { id, createdAt, updatedAt, deletedAt, ...rest } = request;
18
- return stripUndefined({
19
- ...rest,
20
- createdAt: toFirestoreTimestamp(createdAt),
21
- updatedAt: toFirestoreTimestamp(updatedAt),
22
- deletedAt: toOptionalFirestoreTimestamp(deletedAt),
23
- });
24
- },
25
-
26
- fromFirestore(snapshot: QueryDocumentSnapshot): Request {
27
- const { createdAt, updatedAt, deletedAt, ...rest } = snapshot.data();
28
- return {
29
- ...rest,
30
- id: snapshot.id,
31
- createdAt: toTimestamp(createdAt),
32
- updatedAt: toTimestamp(updatedAt),
33
- deletedAt: toOptionalTimestamp(deletedAt),
34
- } as Request;
35
- },
36
- };
1
+ import {
2
+ FirestoreDataConverter,
3
+ QueryDocumentSnapshot,
4
+ DocumentData,
5
+ } from "firebase-admin/firestore";
6
+ import type { Request } from "@cravery/core";
7
+ import {
8
+ toTimestamp,
9
+ toOptionalTimestamp,
10
+ toFirestoreTimestamp,
11
+ toOptionalFirestoreTimestamp,
12
+ stripUndefined,
13
+ } from "../../lib";
14
+
15
+ export const requestConverter: FirestoreDataConverter<Request> = {
16
+ toFirestore(request: Request): DocumentData {
17
+ const { id, createdAt, updatedAt, deletedAt, ...rest } = request;
18
+ return stripUndefined({
19
+ ...rest,
20
+ createdAt: toFirestoreTimestamp(createdAt),
21
+ updatedAt: toFirestoreTimestamp(updatedAt),
22
+ deletedAt: toOptionalFirestoreTimestamp(deletedAt),
23
+ });
24
+ },
25
+
26
+ fromFirestore(snapshot: QueryDocumentSnapshot): Request {
27
+ const { createdAt, updatedAt, deletedAt, ...rest } = snapshot.data();
28
+ return {
29
+ ...rest,
30
+ id: snapshot.id,
31
+ createdAt: toTimestamp(createdAt),
32
+ updatedAt: toTimestamp(updatedAt),
33
+ deletedAt: toOptionalTimestamp(deletedAt),
34
+ } as Request;
35
+ },
36
+ };
package/src/lib/cursor.ts CHANGED
@@ -1,35 +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
- }
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
+ }