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.
- package/README.md +231 -4
- package/lib/index-utils.d.ts +18 -7
- package/lib/index-utils.js +70 -75
- package/lib/index-utils.js.map +1 -1
- package/lib/index.d.ts +22 -6
- package/lib/index.js +43 -34
- package/lib/index.js.map +1 -1
- package/lib/logics/view-logics.d.ts +0 -2
- package/lib/logics/view-logics.js +1 -19
- package/lib/logics/view-logics.js.map +1 -1
- package/lib/sample-custom/cleanup-configs.d.ts +2 -0
- package/lib/sample-custom/cleanup-configs.js +17 -0
- package/lib/sample-custom/cleanup-configs.js.map +1 -0
- package/lib/sample-custom/index.js +14 -1
- package/lib/sample-custom/index.js.map +1 -1
- package/lib/sample-custom/one-time-patches.d.ts +2 -0
- package/lib/sample-custom/one-time-patches.js +14 -0
- package/lib/sample-custom/one-time-patches.js.map +1 -0
- package/lib/tests/index-utils.test.js +345 -85
- package/lib/tests/index-utils.test.js.map +1 -1
- package/lib/tests/index.test.js +33 -5
- package/lib/tests/index.test.js.map +1 -1
- package/lib/tests/logics/patch-logics.test.js +50 -5
- package/lib/tests/logics/patch-logics.test.js.map +1 -1
- package/lib/tests/logics/view-logics.test.js +22 -4
- package/lib/tests/logics/view-logics.test.js.map +1 -1
- package/lib/tests/utils/cleanup.test.d.ts +1 -0
- package/lib/tests/utils/cleanup.test.js +243 -0
- package/lib/tests/utils/cleanup.test.js.map +1 -0
- package/lib/tests/utils/distribution.test.js +256 -1
- package/lib/tests/utils/distribution.test.js.map +1 -1
- package/lib/tests/utils/forms.test.js +10 -86
- package/lib/tests/utils/forms.test.js.map +1 -1
- package/lib/tests/utils/misc.test.js +96 -2
- package/lib/tests/utils/misc.test.js.map +1 -1
- package/lib/tests/utils/paths.test.js +20 -2
- package/lib/tests/utils/paths.test.js.map +1 -1
- package/lib/tests/utils/pubsub.test.js +10 -31
- package/lib/tests/utils/pubsub.test.js.map +1 -1
- package/lib/types.d.ts +51 -2
- package/lib/utils/cleanup.d.ts +5 -0
- package/lib/utils/cleanup.js +99 -0
- package/lib/utils/cleanup.js.map +1 -0
- package/lib/utils/distribution.d.ts +17 -3
- package/lib/utils/distribution.js +61 -23
- package/lib/utils/distribution.js.map +1 -1
- package/lib/utils/forms.d.ts +0 -2
- package/lib/utils/forms.js +1 -35
- package/lib/utils/forms.js.map +1 -1
- package/lib/utils/misc.d.ts +1 -0
- package/lib/utils/misc.js +32 -1
- package/lib/utils/misc.js.map +1 -1
- package/lib/utils/pubsub.d.ts +0 -2
- package/lib/utils/pubsub.js +1 -16
- package/lib/utils/pubsub.js.map +1 -1
- package/package.json +1 -1
- package/src/sample-custom/cleanup-configs.ts +15 -0
- package/src/sample-custom/index.ts +15 -11
- package/src/sample-custom/one-time-patches.ts +13 -0
package/lib/utils/pubsub.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/utils/pubsub.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
package/lib/utils/pubsub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/utils/pubsub.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/utils/pubsub.ts"],"names":[],"mappings":";;;AAAA,oCAA4B;AAE5B,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"}
|
package/package.json
CHANGED
|
@@ -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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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 {
|
|
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
|
+
];
|