@cravery/firebase 0.0.1 → 0.0.3

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.
Files changed (36) hide show
  1. package/dist/recipe/converters.d.ts.map +1 -1
  2. package/dist/recipe/converters.js +2 -2
  3. package/dist/recipe/converters.js.map +1 -1
  4. package/dist/recipe/index.d.ts +2 -0
  5. package/dist/recipe/index.d.ts.map +1 -1
  6. package/dist/recipe/index.js +2 -0
  7. package/dist/recipe/index.js.map +1 -1
  8. package/dist/recipe/repository.d.ts +5 -0
  9. package/dist/recipe/repository.d.ts.map +1 -1
  10. package/dist/recipe/repository.js +46 -3
  11. package/dist/recipe/repository.js.map +1 -1
  12. package/dist/recipe/stats_repository.d.ts +18 -0
  13. package/dist/recipe/stats_repository.d.ts.map +1 -0
  14. package/dist/recipe/stats_repository.js +195 -0
  15. package/dist/recipe/stats_repository.js.map +1 -0
  16. package/dist/recipe/user_recipe_repository.d.ts +26 -0
  17. package/dist/recipe/user_recipe_repository.d.ts.map +1 -0
  18. package/dist/recipe/user_recipe_repository.js +180 -0
  19. package/dist/recipe/user_recipe_repository.js.map +1 -0
  20. package/dist/utils/strip-undefined.js +2 -2
  21. package/dist/utils/strip-undefined.js.map +1 -1
  22. package/dist/utils/timestamp.d.ts +1 -1
  23. package/dist/utils/timestamp.d.ts.map +1 -1
  24. package/package.json +60 -58
  25. package/src/iam/converters.ts +38 -38
  26. package/src/iam/index.ts +1 -1
  27. package/src/index.ts +3 -3
  28. package/src/recipe/converters.ts +98 -93
  29. package/src/recipe/index.ts +5 -3
  30. package/src/recipe/repository.ts +284 -220
  31. package/src/recipe/stats_repository.ts +251 -0
  32. package/src/recipe/user_recipe_repository.ts +240 -0
  33. package/src/recipe/utils.ts +143 -143
  34. package/src/utils/index.ts +2 -2
  35. package/src/utils/strip-undefined.ts +32 -32
  36. package/src/utils/timestamp.ts +21 -21
@@ -17,9 +17,9 @@ function stripUndefined(obj) {
17
17
  return obj;
18
18
  }
19
19
  if (Array.isArray(obj)) {
20
- return obj.map(item => stripUndefined(item));
20
+ return obj.map((item) => stripUndefined(item));
21
21
  }
22
- if (typeof obj === 'object') {
22
+ if (typeof obj === "object") {
23
23
  const cleaned = {};
24
24
  for (const [key, value] of Object.entries(obj)) {
25
25
  if (value !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"strip-undefined.js","sourceRoot":"","sources":["../../src/utils/strip-undefined.ts"],"names":[],"mappings":";;AAWA,wCAoBC;AA/BD;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAI,GAAM;IACtC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAM,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,OAAY,CAAC;IACtB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"strip-undefined.js","sourceRoot":"","sources":["../../src/utils/strip-undefined.ts"],"names":[],"mappings":";;AAWA,wCAoBC;AA/BD;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAI,GAAM;IACtC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAM,CAAC;IACtD,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,OAAY,CAAC;IACtB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Timestamp as FirestoreTimestamp } from "firebase-admin/firestore";
2
- import type { Timestamp } from "@cravery/core/types";
2
+ import type { Timestamp } from "@cravery/core";
3
3
  export declare function toTimestamp(timestamp: FirestoreTimestamp): Timestamp;
4
4
  export declare function fromTimestamp(timestamp: Timestamp): FirestoreTimestamp;
5
5
  export declare function toOptionalTimestamp(timestamp?: FirestoreTimestamp): Timestamp | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/utils/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,wBAAgB,WAAW,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAKpE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,CAItE;AAED,wBAAgB,mBAAmB,CACjC,SAAS,CAAC,EAAE,kBAAkB,GAC7B,SAAS,GAAG,SAAS,CAEvB"}
1
+ {"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/utils/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,wBAAgB,WAAW,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAKpE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,CAItE;AAED,wBAAgB,mBAAmB,CACjC,SAAS,CAAC,EAAE,kBAAkB,GAC7B,SAAS,GAAG,SAAS,CAEvB"}
package/package.json CHANGED
@@ -1,58 +1,60 @@
1
- {
2
- "name": "@cravery/firebase",
3
- "version": "0.0.1",
4
- "description": "Shared Firebase Admin SDK utilities for Cravery",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "default": "./dist/index.js"
11
- },
12
- "./recipe": {
13
- "types": "./dist/recipe/index.d.ts",
14
- "default": "./dist/recipe/index.js"
15
- },
16
- "./iam": {
17
- "types": "./dist/iam/index.d.ts",
18
- "default": "./dist/iam/index.js"
19
- },
20
- "./utils": {
21
- "types": "./dist/utils/index.d.ts",
22
- "default": "./dist/utils/index.js"
23
- }
24
- },
25
- "typesVersions": {
26
- "*": {
27
- "recipe": [
28
- "dist/recipe/index.d.ts"
29
- ],
30
- "iam": [
31
- "dist/iam/index.d.ts"
32
- ],
33
- "utils": [
34
- "dist/utils/index.d.ts"
35
- ]
36
- }
37
- },
38
- "scripts": {
39
- "build": "tsc",
40
- "build:watch": "tsc --watch",
41
- "clean": "rimraf dist && npm run build"
42
- },
43
- "keywords": [],
44
- "peerDependencies": {
45
- "@cravery/core": "^0.0.29",
46
- "firebase-admin": "^13.6.0"
47
- },
48
- "devDependencies": {
49
- "@cravery/core": "^0.0.29",
50
- "firebase-admin": "^13.6.0",
51
- "rimraf": "^6.1.2",
52
- "typescript": "^5.9.3"
53
- },
54
- "files": [
55
- "dist/**/*",
56
- "src/**/*"
57
- ]
58
- }
1
+ {
2
+ "name": "@cravery/firebase",
3
+ "version": "0.0.3",
4
+ "description": "Shared Firebase Admin SDK utilities for Cravery",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./recipe": {
13
+ "types": "./dist/recipe/index.d.ts",
14
+ "default": "./dist/recipe/index.js"
15
+ },
16
+ "./iam": {
17
+ "types": "./dist/iam/index.d.ts",
18
+ "default": "./dist/iam/index.js"
19
+ },
20
+ "./utils": {
21
+ "types": "./dist/utils/index.d.ts",
22
+ "default": "./dist/utils/index.js"
23
+ }
24
+ },
25
+ "typesVersions": {
26
+ "*": {
27
+ "recipe": [
28
+ "dist/recipe/index.d.ts"
29
+ ],
30
+ "iam": [
31
+ "dist/iam/index.d.ts"
32
+ ],
33
+ "utils": [
34
+ "dist/utils/index.d.ts"
35
+ ]
36
+ }
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "build:watch": "tsc --watch",
41
+ "clean": "rimraf dist && npm run build"
42
+ },
43
+ "keywords": [],
44
+ "peerDependencies": {
45
+ "firebase-admin": "^13.6.0"
46
+ },
47
+ "devDependencies": {
48
+ "firebase-admin": "^13.6.0",
49
+ "rimraf": "^6.1.2",
50
+ "typescript": "^5.9.3"
51
+ },
52
+ "files": [
53
+ "dist/**/*",
54
+ "src/**/*"
55
+ ],
56
+ "dependencies": {
57
+ "@cravery/core": "^0.0.30",
58
+ "@cravery/firebase": "^0.0.1"
59
+ }
60
+ }
@@ -1,38 +1,38 @@
1
- import {
2
- FirestoreDataConverter,
3
- QueryDocumentSnapshot,
4
- DocumentData,
5
- } from "firebase-admin/firestore";
6
- import type { User } from "@cravery/core/types";
7
- import { toTimestamp, toOptionalTimestamp, fromTimestamp } from "../utils";
8
-
9
- export const userConverter: FirestoreDataConverter<User> = {
10
- toFirestore(user: User): DocumentData {
11
- const { id, createdAt, updatedAt, deletedAt, ...rest } = user;
12
-
13
- return {
14
- ...rest,
15
- createdAt: fromTimestamp(createdAt),
16
- updatedAt: fromTimestamp(updatedAt),
17
- ...(deletedAt && { deletedAt: fromTimestamp(deletedAt) }),
18
- };
19
- },
20
-
21
- fromFirestore(snapshot: QueryDocumentSnapshot): User {
22
- const data = snapshot.data();
23
-
24
- return {
25
- id: snapshot.id,
26
- email: data.email,
27
- name: data.name,
28
- role: data.role,
29
- status: data.status,
30
- verified: data.verified ?? false,
31
- createdAt: toTimestamp(data.createdAt),
32
- updatedAt: toTimestamp(data.updatedAt),
33
- deletedAt: toOptionalTimestamp(data.deletedAt),
34
- imageUrl: data.imageUrl,
35
- subscriptionId: data.subscriptionId,
36
- };
37
- },
38
- };
1
+ import {
2
+ FirestoreDataConverter,
3
+ QueryDocumentSnapshot,
4
+ DocumentData,
5
+ } from "firebase-admin/firestore";
6
+ import type { User } from "@cravery/core/types";
7
+ import { toTimestamp, toOptionalTimestamp, fromTimestamp } from "../utils";
8
+
9
+ export const userConverter: FirestoreDataConverter<User> = {
10
+ toFirestore(user: User): DocumentData {
11
+ const { id, createdAt, updatedAt, deletedAt, ...rest } = user;
12
+
13
+ return {
14
+ ...rest,
15
+ createdAt: fromTimestamp(createdAt),
16
+ updatedAt: fromTimestamp(updatedAt),
17
+ ...(deletedAt && { deletedAt: fromTimestamp(deletedAt) }),
18
+ };
19
+ },
20
+
21
+ fromFirestore(snapshot: QueryDocumentSnapshot): User {
22
+ const data = snapshot.data();
23
+
24
+ return {
25
+ id: snapshot.id,
26
+ email: data.email,
27
+ name: data.name,
28
+ role: data.role,
29
+ status: data.status,
30
+ verified: data.verified ?? false,
31
+ createdAt: toTimestamp(data.createdAt),
32
+ updatedAt: toTimestamp(data.updatedAt),
33
+ deletedAt: toOptionalTimestamp(data.deletedAt),
34
+ imageUrl: data.imageUrl,
35
+ subscriptionId: data.subscriptionId,
36
+ };
37
+ },
38
+ };
package/src/iam/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./converters";
1
+ export * from "./converters";
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./iam";
2
- export * from "./recipe";
3
- export * from "./utils";
1
+ export * from "./iam";
2
+ export * from "./recipe";
3
+ export * from "./utils";
@@ -1,93 +1,98 @@
1
- import {
2
- FirestoreDataConverter,
3
- QueryDocumentSnapshot,
4
- DocumentData,
5
- } from "firebase-admin/firestore";
6
- import type { RecipeMeta, RecipeContent } from "@cravery/core/types";
7
- import { toTimestamp, toOptionalTimestamp, fromTimestamp, stripUndefined } from "../utils";
8
-
9
- export const recipeMetaConverter: FirestoreDataConverter<RecipeMeta> = {
10
- toFirestore(recipeMeta: RecipeMeta): DocumentData {
11
- const { id, createdAt, updatedAt, deletedAt, ...rest } = recipeMeta;
12
-
13
- const convertTimestamp = (ts: any) => {
14
- if (!ts) return ts;
15
- // Handle Firestore internal format with _seconds
16
- if (typeof ts === 'object' && '_seconds' in ts) {
17
- return ts;
18
- }
19
- // Handle Firestore Timestamp objects with seconds/nanoseconds
20
- if (typeof ts === 'object' && 'seconds' in ts && 'nanoseconds' in ts) {
21
- return fromTimestamp(ts);
22
- }
23
- return ts;
24
- };
25
-
26
- // Strip undefined values before returning to Firestore
27
- return stripUndefined({
28
- ...rest,
29
- createdAt: convertTimestamp(createdAt),
30
- updatedAt: convertTimestamp(updatedAt),
31
- ...(deletedAt && { deletedAt: convertTimestamp(deletedAt) }),
32
- });
33
- },
34
-
35
- fromFirestore(snapshot: QueryDocumentSnapshot): RecipeMeta {
36
- const data = snapshot.data();
37
-
38
- return {
39
- id: snapshot.id,
40
- allergens: data.allergens,
41
- confidence: data.confidence,
42
- createdBy: data.createdBy,
43
- cuisine: data.cuisine,
44
- dietaryTags: data.dietaryTags,
45
- difficulty: data.difficulty,
46
- equipment: data.equipment,
47
- imageUrl: data.imageUrl,
48
- ingredientSections: data.ingredientSections,
49
- instructions: data.instructions,
50
- mealTypes: data.mealTypes,
51
- nutrition: data.nutrition,
52
- originalLocale: data.originalLocale,
53
- servings: data.servings,
54
- source: data.source,
55
- sourceUrl: data.sourceUrl,
56
- spiciness: data.spiciness,
57
- status: data.status,
58
- time: data.time,
59
- createdAt: toTimestamp(data.createdAt),
60
- updatedAt: toTimestamp(data.updatedAt),
61
- deletedAt: toOptionalTimestamp(data.deletedAt),
62
- };
63
- },
64
- };
65
-
66
- export const recipeContentConverter: FirestoreDataConverter<RecipeContent> = {
67
- toFirestore(content: RecipeContent): DocumentData {
68
- // Strip undefined values before returning to Firestore
69
- return stripUndefined({
70
- description: content.description,
71
- equipment: content.equipment,
72
- ingredientSections: content.ingredientSections,
73
- instructions: content.instructions,
74
- locale: content.locale,
75
- tips: content.tips,
76
- title: content.title,
77
- });
78
- },
79
-
80
- fromFirestore(snapshot: QueryDocumentSnapshot): RecipeContent {
81
- const data = snapshot.data();
82
-
83
- return {
84
- description: data.description,
85
- equipment: data.equipment,
86
- ingredientSections: data.ingredientSections,
87
- instructions: data.instructions,
88
- locale: data.locale,
89
- tips: data.tips,
90
- title: data.title,
91
- };
92
- },
93
- };
1
+ import {
2
+ FirestoreDataConverter,
3
+ QueryDocumentSnapshot,
4
+ DocumentData,
5
+ } from "firebase-admin/firestore";
6
+ import type { RecipeMeta, RecipeContent } from "@cravery/core/types";
7
+ import {
8
+ toTimestamp,
9
+ toOptionalTimestamp,
10
+ fromTimestamp,
11
+ stripUndefined,
12
+ } from "../utils";
13
+
14
+ export const recipeMetaConverter: FirestoreDataConverter<RecipeMeta> = {
15
+ toFirestore(recipeMeta: RecipeMeta): DocumentData {
16
+ const { id, createdAt, updatedAt, deletedAt, ...rest } = recipeMeta;
17
+
18
+ const convertTimestamp = (ts: any) => {
19
+ if (!ts) return ts;
20
+ // Handle Firestore internal format with _seconds
21
+ if (typeof ts === "object" && "_seconds" in ts) {
22
+ return ts;
23
+ }
24
+ // Handle Firestore Timestamp objects with seconds/nanoseconds
25
+ if (typeof ts === "object" && "seconds" in ts && "nanoseconds" in ts) {
26
+ return fromTimestamp(ts);
27
+ }
28
+ return ts;
29
+ };
30
+
31
+ // Strip undefined values before returning to Firestore
32
+ return stripUndefined({
33
+ ...rest,
34
+ createdAt: convertTimestamp(createdAt),
35
+ updatedAt: convertTimestamp(updatedAt),
36
+ ...(deletedAt && { deletedAt: convertTimestamp(deletedAt) }),
37
+ });
38
+ },
39
+
40
+ fromFirestore(snapshot: QueryDocumentSnapshot): RecipeMeta {
41
+ const data = snapshot.data();
42
+
43
+ return {
44
+ id: snapshot.id,
45
+ allergens: data.allergens,
46
+ confidence: data.confidence,
47
+ createdBy: data.createdBy,
48
+ cuisine: data.cuisine,
49
+ dietaryTags: data.dietaryTags,
50
+ difficulty: data.difficulty,
51
+ equipment: data.equipment,
52
+ imageUrl: data.imageUrl,
53
+ ingredientSections: data.ingredientSections,
54
+ instructions: data.instructions,
55
+ mealTypes: data.mealTypes,
56
+ nutrition: data.nutrition,
57
+ originalLocale: data.originalLocale,
58
+ servings: data.servings,
59
+ source: data.source,
60
+ sourceUrl: data.sourceUrl,
61
+ spiciness: data.spiciness,
62
+ status: data.status,
63
+ time: data.time,
64
+ createdAt: toTimestamp(data.createdAt),
65
+ updatedAt: toTimestamp(data.updatedAt),
66
+ deletedAt: toOptionalTimestamp(data.deletedAt),
67
+ };
68
+ },
69
+ };
70
+
71
+ export const recipeContentConverter: FirestoreDataConverter<RecipeContent> = {
72
+ toFirestore(content: RecipeContent): DocumentData {
73
+ // Strip undefined values before returning to Firestore
74
+ return stripUndefined({
75
+ description: content.description,
76
+ equipment: content.equipment,
77
+ ingredientSections: content.ingredientSections,
78
+ instructions: content.instructions,
79
+ locale: content.locale,
80
+ tips: content.tips,
81
+ title: content.title,
82
+ });
83
+ },
84
+
85
+ fromFirestore(snapshot: QueryDocumentSnapshot): RecipeContent {
86
+ const data = snapshot.data();
87
+
88
+ return {
89
+ description: data.description,
90
+ equipment: data.equipment,
91
+ ingredientSections: data.ingredientSections,
92
+ instructions: data.instructions,
93
+ locale: data.locale,
94
+ tips: data.tips,
95
+ title: data.title,
96
+ };
97
+ },
98
+ };
@@ -1,3 +1,5 @@
1
- export * from "./converters";
2
- export * from "./repository";
3
- export * from "./utils";
1
+ export * from "./converters";
2
+ export * from "./repository";
3
+ export * from "./stats_repository";
4
+ export * from "./user_recipe_repository";
5
+ export * from "./utils";