emberflow 1.5.1 → 2.0.0

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 (59) hide show
  1. package/README.md +231 -4
  2. package/lib/index-utils.d.ts +18 -7
  3. package/lib/index-utils.js +70 -75
  4. package/lib/index-utils.js.map +1 -1
  5. package/lib/index.d.ts +22 -6
  6. package/lib/index.js +43 -34
  7. package/lib/index.js.map +1 -1
  8. package/lib/logics/view-logics.d.ts +0 -2
  9. package/lib/logics/view-logics.js +1 -19
  10. package/lib/logics/view-logics.js.map +1 -1
  11. package/lib/sample-custom/cleanup-configs.d.ts +2 -0
  12. package/lib/sample-custom/cleanup-configs.js +17 -0
  13. package/lib/sample-custom/cleanup-configs.js.map +1 -0
  14. package/lib/sample-custom/index.js +14 -1
  15. package/lib/sample-custom/index.js.map +1 -1
  16. package/lib/sample-custom/one-time-patches.d.ts +2 -0
  17. package/lib/sample-custom/one-time-patches.js +14 -0
  18. package/lib/sample-custom/one-time-patches.js.map +1 -0
  19. package/lib/tests/index-utils.test.js +345 -85
  20. package/lib/tests/index-utils.test.js.map +1 -1
  21. package/lib/tests/index.test.js +33 -5
  22. package/lib/tests/index.test.js.map +1 -1
  23. package/lib/tests/logics/patch-logics.test.js +50 -5
  24. package/lib/tests/logics/patch-logics.test.js.map +1 -1
  25. package/lib/tests/logics/view-logics.test.js +22 -4
  26. package/lib/tests/logics/view-logics.test.js.map +1 -1
  27. package/lib/tests/utils/cleanup.test.d.ts +1 -0
  28. package/lib/tests/utils/cleanup.test.js +243 -0
  29. package/lib/tests/utils/cleanup.test.js.map +1 -0
  30. package/lib/tests/utils/distribution.test.js +256 -1
  31. package/lib/tests/utils/distribution.test.js.map +1 -1
  32. package/lib/tests/utils/forms.test.js +10 -86
  33. package/lib/tests/utils/forms.test.js.map +1 -1
  34. package/lib/tests/utils/misc.test.js +96 -2
  35. package/lib/tests/utils/misc.test.js.map +1 -1
  36. package/lib/tests/utils/paths.test.js +20 -2
  37. package/lib/tests/utils/paths.test.js.map +1 -1
  38. package/lib/tests/utils/pubsub.test.js +10 -31
  39. package/lib/tests/utils/pubsub.test.js.map +1 -1
  40. package/lib/types.d.ts +51 -2
  41. package/lib/utils/cleanup.d.ts +5 -0
  42. package/lib/utils/cleanup.js +99 -0
  43. package/lib/utils/cleanup.js.map +1 -0
  44. package/lib/utils/distribution.d.ts +17 -3
  45. package/lib/utils/distribution.js +61 -23
  46. package/lib/utils/distribution.js.map +1 -1
  47. package/lib/utils/forms.d.ts +0 -2
  48. package/lib/utils/forms.js +1 -35
  49. package/lib/utils/forms.js.map +1 -1
  50. package/lib/utils/misc.d.ts +1 -0
  51. package/lib/utils/misc.js +32 -1
  52. package/lib/utils/misc.js.map +1 -1
  53. package/lib/utils/pubsub.d.ts +0 -2
  54. package/lib/utils/pubsub.js +1 -16
  55. package/lib/utils/pubsub.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/sample-custom/cleanup-configs.ts +15 -0
  58. package/src/sample-custom/index.ts +15 -11
  59. package/src/sample-custom/one-time-patches.ts +13 -0
@@ -1,9 +1,7 @@
1
- import type { ScheduledEvent } from "firebase-functions/v2/scheduler";
2
1
  declare function trackProcessedIds(topicName: string, id: string): Promise<void>;
3
2
  declare function isProcessed(topicName: string, id: string): Promise<boolean>;
4
3
  export declare const pubsubUtils: {
5
4
  trackProcessedIds: typeof trackProcessedIds;
6
5
  isProcessed: typeof isProcessed;
7
6
  };
8
- export declare function cleanPubSubProcessedIds(_event: ScheduledEvent): Promise<void>;
9
7
  export {};
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanPubSubProcessedIds = exports.pubsubUtils = void 0;
3
+ exports.pubsubUtils = void 0;
4
4
  const index_1 = require("../index");
5
- const misc_1 = require("./misc");
6
5
  async function trackProcessedIds(topicName, id) {
7
6
  const docRef = index_1.db.doc(`@topics/${topicName}/processedIds/${id}`);
8
7
  await docRef.set({ timestamp: new Date() });
@@ -16,18 +15,4 @@ exports.pubsubUtils = {
16
15
  trackProcessedIds,
17
16
  isProcessed,
18
17
  };
19
- async function cleanPubSubProcessedIds(_event) {
20
- console.info("Running cleanPubSubProcessedIds");
21
- let i = 0;
22
- for (const pubSubTopic of index_1.pubSubTopics) {
23
- const query = index_1.db
24
- .collection(`@topics/${pubSubTopic}/processedIds`)
25
- .where("timestamp", "<", new Date(Date.now() - 1000 * 60 * 60 * 24 * 7));
26
- await (0, misc_1.deleteCollection)(query, (snapshot) => {
27
- i += snapshot.size;
28
- });
29
- }
30
- console.info(`Cleaned ${i} topics of processedIds`);
31
- }
32
- exports.cleanPubSubProcessedIds = cleanPubSubProcessedIds;
33
18
  //# sourceMappingURL=pubsub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/utils/pubsub.ts"],"names":[],"mappings":";;;AAAA,oCAA0C;AAC1C,iCAAwC;AAGxC,KAAK,UAAU,iBAAiB,CAAC,SAAiB,EAAE,EAAU;IAC5D,MAAM,MAAM,GAAG,UAAE,CAAC,GAAG,CAAC,WAAW,SAAS,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACjE,MAAM,MAAM,CAAC,GAAG,CAAC,EAAC,SAAS,EAAE,IAAI,IAAI,EAAE,EAAC,CAAC,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,SAAiB,EAAE,EAAU;IACtD,MAAM,MAAM,GAAG,UAAE,CAAC,GAAG,CAAC,WAAW,SAAS,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IAC/B,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC;AAEY,QAAA,WAAW,GAAG;IACzB,iBAAiB;IACjB,WAAW;CACZ,CAAC;AAEK,KAAK,UAAU,uBAAuB,CAAC,MAAsB;IAClE,OAAO,CAAC,IAAI,CAAC,iC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@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emberflow",
3
- "version": "1.5.1",
3
+ "version": "2.0.0",
4
4
  "description": "A Firebase Cloud Functions library for handling document changes in a structured way",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.js",
@@ -0,0 +1,15 @@
1
+ import {CleanupConfig} from "../types";
2
+
3
+ export const cleanupConfigs: CleanupConfig[] = [
4
+ {
5
+ // Purge stale askJaris documents that never got a topic assigned.
6
+ // "attribute missing" is modeled as an indexed boolean flag (hasTopic).
7
+ collectionPath: "askJaris",
8
+ isCollectionGroup: true,
9
+ timestampField: "createdAt",
10
+ olderThan: {value: 1, unit: "months"},
11
+ conditions: [
12
+ {fieldName: "hasTopic", operator: "==", value: false},
13
+ ],
14
+ },
15
+ ];
@@ -1,24 +1,28 @@
1
1
  import * as admin from "firebase-admin";
2
- import { initializeEmberFlow } from "../index";
3
- import { projectConfig } from "./project-config";
4
- import { dbStructure, Entity } from "./db-structure";
5
- import { securityConfigs } from "./security";
6
- import { validatorConfigs } from "./validators";
7
- import { logics } from "./business-logics";
8
- import { patchLogicConfigs } from "./patch-logics";
2
+ import {initializeEmberFlow} from "../index";
3
+ import {projectConfig} from "./project-config";
4
+ import {dbStructure, Entity} from "./db-structure";
5
+ import {securityConfigs} from "./security";
6
+ import {validatorConfigs} from "./validators";
7
+ import {logics} from "./business-logics";
8
+ import {patchLogicConfigs} from "./patch-logics";
9
+ import {backFillPatchConfigs} from "./one-time-patches";
10
+ import {cleanupConfigs} from "./cleanup-configs";
9
11
 
10
12
  admin.initializeApp();
11
13
 
12
- const { functionsConfig } = initializeEmberFlow(
14
+ const {functionsConfig} = initializeEmberFlow({
13
15
  projectConfig,
14
16
  admin,
15
17
  dbStructure,
16
18
  Entity,
17
19
  securityConfigs,
18
20
  validatorConfigs,
19
- logics,
20
- patchLogicConfigs
21
- );
21
+ logicConfigs: logics,
22
+ patchLogicConfigs,
23
+ cleanupConfigs,
24
+ backFillPatchConfigs,
25
+ });
22
26
 
23
27
  // Export the generated functions
24
28
  Object.entries(functionsConfig).forEach(([key, value]) => {
@@ -0,0 +1,13 @@
1
+ import {BackFillPatchConfig} from "../types";
2
+
3
+ const sampleOneTimePatch: BackFillPatchConfig = {
4
+ name: "sample-one-time-patch",
5
+ patchFn: async (collectionPath, docs) => {
6
+ console.log(`Executing sample one-time patch on collection ${collectionPath} (${docs.length} docs)...`);
7
+ // Add your custom bulk back-fill logic here, e.g. bulk-update docs via a single db.batch().
8
+ },
9
+ };
10
+
11
+ export const backFillPatchConfigs: BackFillPatchConfig[] = [
12
+ sampleOneTimePatch,
13
+ ];