emberflow 1.0.8
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/LICENSE +21 -0
- package/README.md +40 -0
- package/lib/db-structure.d.ts +7 -0
- package/lib/db-structure.js +67 -0
- package/lib/db-structure.js.map +1 -0
- package/lib/index-utils.d.ts +20 -0
- package/lib/index-utils.js +324 -0
- package/lib/index-utils.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +197 -0
- package/lib/index.js.map +1 -0
- package/lib/init-db-structure.d.ts +17 -0
- package/lib/init-db-structure.js +111 -0
- package/lib/init-db-structure.js.map +1 -0
- package/lib/logics/index.d.ts +2 -0
- package/lib/logics/index.js +77 -0
- package/lib/logics/index.js.map +1 -0
- package/lib/logics/view-logics.d.ts +3 -0
- package/lib/logics/view-logics.js +167 -0
- package/lib/logics/view-logics.js.map +1 -0
- package/lib/sample-custom/business-logics.d.ts +3 -0
- package/lib/sample-custom/business-logics.js +67 -0
- package/lib/sample-custom/business-logics.js.map +1 -0
- package/lib/sample-custom/db-structure.d.ts +29 -0
- package/lib/sample-custom/db-structure.js +36 -0
- package/lib/sample-custom/db-structure.js.map +1 -0
- package/lib/sample-custom/security.d.ts +2 -0
- package/lib/sample-custom/security.js +63 -0
- package/lib/sample-custom/security.js.map +1 -0
- package/lib/sample-custom/validators.d.ts +9 -0
- package/lib/sample-custom/validators.js +42 -0
- package/lib/sample-custom/validators.js.map +1 -0
- package/lib/tests/index-utils.test.d.ts +1 -0
- package/lib/tests/index-utils.test.js +600 -0
- package/lib/tests/index-utils.test.js.map +1 -0
- package/lib/tests/index.test.d.ts +1 -0
- package/lib/tests/index.test.js +496 -0
- package/lib/tests/index.test.js.map +1 -0
- package/lib/tests/init-db-structure.test.d.ts +1 -0
- package/lib/tests/init-db-structure.test.js +114 -0
- package/lib/tests/init-db-structure.test.js.map +1 -0
- package/lib/tests/logics/index.test.d.ts +1 -0
- package/lib/tests/logics/index.test.js +127 -0
- package/lib/tests/logics/index.test.js.map +1 -0
- package/lib/tests/logics/view-logics.test.d.ts +1 -0
- package/lib/tests/logics/view-logics.test.js +211 -0
- package/lib/tests/logics/view-logics.test.js.map +1 -0
- package/lib/tests/utils/misc.test.d.ts +1 -0
- package/lib/tests/utils/misc.test.js +31 -0
- package/lib/tests/utils/misc.test.js.map +1 -0
- package/lib/tests/utils/paths.test.d.ts +1 -0
- package/lib/tests/utils/paths.test.js +258 -0
- package/lib/tests/utils/paths.test.js.map +1 -0
- package/lib/tests/utils/query.test.d.ts +1 -0
- package/lib/tests/utils/query.test.js +72 -0
- package/lib/tests/utils/query.test.js.map +1 -0
- package/lib/tests/utils/sample.test.d.ts +1 -0
- package/lib/tests/utils/sample.test.js +52 -0
- package/lib/tests/utils/sample.test.js.map +1 -0
- package/lib/types.d.ts +78 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/db-structure.d.ts +2 -0
- package/lib/utils/db-structure.js +9 -0
- package/lib/utils/db-structure.js.map +1 -0
- package/lib/utils/misc.d.ts +1 -0
- package/lib/utils/misc.js +53 -0
- package/lib/utils/misc.js.map +1 -0
- package/lib/utils/paths.d.ts +16 -0
- package/lib/utils/paths.js +136 -0
- package/lib/utils/paths.js.map +1 -0
- package/lib/utils/query.d.ts +2 -0
- package/lib/utils/query.js +41 -0
- package/lib/utils/query.js.map +1 -0
- package/lib/utils/sample.d.ts +5 -0
- package/lib/utils/sample.js +37 -0
- package/lib/utils/sample.js.map +1 -0
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +67 -0
- package/lib/utils.js.map +1 -0
- package/package.json +37 -0
- package/src/sample-custom/business-logics.ts +51 -0
- package/src/sample-custom/db-structure.ts +33 -0
- package/src/sample-custom/security.ts +77 -0
- package/src/sample-custom/validators.ts +46 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.onDocChange = exports.initializeEmberFlow = exports._mockable = exports.functionsConfig = exports.viewLogicConfigs = exports.docPathsRegex = exports.colPaths = exports.docPaths = exports.logicConfigs = exports.validatorConfig = exports.securityConfig = exports.Entity = exports.dbStructure = exports.admin = void 0;
|
|
38
|
+
const functions = __importStar(require("firebase-functions"));
|
|
39
|
+
const index_utils_1 = require("./index-utils");
|
|
40
|
+
const init_db_structure_1 = require("./init-db-structure");
|
|
41
|
+
const view_logics_1 = require("./logics/view-logics");
|
|
42
|
+
exports.functionsConfig = {};
|
|
43
|
+
exports._mockable = {
|
|
44
|
+
createNowTimestamp: () => exports.admin.firestore.Timestamp.now(),
|
|
45
|
+
};
|
|
46
|
+
function initializeEmberFlow(adminInstance, customDbStructure, CustomEntity, customSecurityConfig, customValidatorConfig, customLogicConfigs) {
|
|
47
|
+
exports.admin = adminInstance;
|
|
48
|
+
exports.dbStructure = customDbStructure;
|
|
49
|
+
exports.Entity = CustomEntity;
|
|
50
|
+
exports.securityConfig = customSecurityConfig;
|
|
51
|
+
exports.validatorConfig = customValidatorConfig;
|
|
52
|
+
exports.logicConfigs = customLogicConfigs;
|
|
53
|
+
const { docPaths: dp, colPaths: cp, docPathsRegex: dbr, viewDefinitions: vd } = (0, init_db_structure_1.initDbStructure)(exports.dbStructure, exports.Entity);
|
|
54
|
+
exports.docPaths = dp;
|
|
55
|
+
exports.colPaths = cp;
|
|
56
|
+
exports.docPathsRegex = dbr;
|
|
57
|
+
exports.viewLogicConfigs = vd.map((viewDef) => {
|
|
58
|
+
return {
|
|
59
|
+
name: `${viewDef.destEntity}${viewDef.destProp ? "#" + viewDef.destProp : ""} ViewLogic`,
|
|
60
|
+
entity: viewDef.srcEntity,
|
|
61
|
+
modifiedFields: viewDef.srcProps,
|
|
62
|
+
viewLogicFn: (0, view_logics_1.createViewLogicFn)(viewDef),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
Object.values(exports.docPaths).forEach((path) => {
|
|
66
|
+
const parts = path.split("/");
|
|
67
|
+
const entity = parts[parts.length - 1].replace(/{(\w+)Id}$/, "$1");
|
|
68
|
+
exports.functionsConfig[`on${entity.charAt(0).toUpperCase() + entity.slice(1)}Create`] = functions.firestore
|
|
69
|
+
.document(path)
|
|
70
|
+
.onCreate(async (snapshot, context) => {
|
|
71
|
+
await onDocChange(entity, { before: null, after: snapshot }, context, "create");
|
|
72
|
+
});
|
|
73
|
+
exports.functionsConfig[`on${entity.charAt(0).toUpperCase() + entity.slice(1)}Update`] = functions.firestore
|
|
74
|
+
.document(path)
|
|
75
|
+
.onUpdate(async (change, context) => {
|
|
76
|
+
await onDocChange(entity, change, context, "update");
|
|
77
|
+
});
|
|
78
|
+
exports.functionsConfig[`on${entity.charAt(0).toUpperCase() + entity.slice(1)}Delete`] = functions.firestore
|
|
79
|
+
.document(path)
|
|
80
|
+
.onDelete(async (snapshot, context) => {
|
|
81
|
+
await onDocChange(entity, { before: snapshot, after: null }, context, "delete");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return { docPaths: exports.docPaths, colPaths: exports.colPaths, docPathsRegex: exports.docPathsRegex, functionsConfig: exports.functionsConfig };
|
|
85
|
+
}
|
|
86
|
+
exports.initializeEmberFlow = initializeEmberFlow;
|
|
87
|
+
async function onDocChange(entity, change, context, event) {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
if (!context.auth) {
|
|
90
|
+
console.log("Auth is null, then this change is initiated by the service account and should be ignored");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const userId = context.auth.uid;
|
|
94
|
+
const afterDocument = change.after ? change.after.data() : null;
|
|
95
|
+
const beforeDocument = change.before ? change.before.data() : null;
|
|
96
|
+
const document = afterDocument || beforeDocument;
|
|
97
|
+
const snapshot = change.after || change.before;
|
|
98
|
+
if (!snapshot || !document) {
|
|
99
|
+
console.error("Snapshot or document should not be null");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const documentId = snapshot.ref.id;
|
|
103
|
+
console.log(`Document ${event}d in ${context.resource.service.split("/")[6]} collection with ID ${documentId}`);
|
|
104
|
+
console.log("After Document data: ", afterDocument);
|
|
105
|
+
console.log("Before document data: ", beforeDocument);
|
|
106
|
+
// Re save document if deleted
|
|
107
|
+
if (event === "delete") {
|
|
108
|
+
// Re-add deleted document
|
|
109
|
+
await snapshot.ref.set(document);
|
|
110
|
+
console.log(`Document re-added with ID ${documentId}`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (afterDocument) {
|
|
114
|
+
await (0, index_utils_1.revertModificationsOutsideForm)(afterDocument, beforeDocument, snapshot);
|
|
115
|
+
}
|
|
116
|
+
// if not form.@status is submit then return
|
|
117
|
+
if (((_a = document === null || document === void 0 ? void 0 : document["@form"]) === null || _a === void 0 ? void 0 : _a["@status"]) !== "submit") {
|
|
118
|
+
console.log("Form is not submitted");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Create Action document
|
|
122
|
+
const actionType = (_b = document["@form"]) === null || _b === void 0 ? void 0 : _b["@actionType"];
|
|
123
|
+
if (!actionType) {
|
|
124
|
+
console.log("No actionType found");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Validate the document
|
|
128
|
+
const [hasValidationError, validationResult] = await (0, index_utils_1.validateForm)(entity, document, snapshot.ref.path);
|
|
129
|
+
if (hasValidationError) {
|
|
130
|
+
await snapshot.ref.update({ "@form.@status": "form-validation-failed", "@form.@message": validationResult });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const formModifiedFields = (0, index_utils_1.getFormModifiedFields)(document);
|
|
134
|
+
// Run security check
|
|
135
|
+
const securityFn = (0, index_utils_1.getSecurityFn)(entity);
|
|
136
|
+
if (securityFn) {
|
|
137
|
+
const securityResult = await securityFn(entity, document, event, formModifiedFields);
|
|
138
|
+
if (securityResult.status === "rejected") {
|
|
139
|
+
console.log(`Security check failed: ${securityResult.message}`);
|
|
140
|
+
await snapshot.ref.update({ "@form.@status": "security-error", "@form.@message": securityResult.message });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Check for delay
|
|
145
|
+
const delay = (_c = document === null || document === void 0 ? void 0 : document["@form"]) === null || _c === void 0 ? void 0 : _c["@delay"];
|
|
146
|
+
if (delay) {
|
|
147
|
+
if (await (0, index_utils_1.delayFormSubmissionAndCheckIfCancelled)(delay, snapshot)) {
|
|
148
|
+
await snapshot.ref.update({ "@form.@status": "cancelled" });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await snapshot.ref.update({ "@form.@status": "processing" });
|
|
153
|
+
const path = snapshot.ref.path;
|
|
154
|
+
const status = "processing";
|
|
155
|
+
const timeCreated = exports._mockable.createNowTimestamp();
|
|
156
|
+
const action = {
|
|
157
|
+
actionType,
|
|
158
|
+
path,
|
|
159
|
+
document,
|
|
160
|
+
status,
|
|
161
|
+
timeCreated,
|
|
162
|
+
modifiedFields: formModifiedFields,
|
|
163
|
+
};
|
|
164
|
+
const actionRef = await exports.admin.firestore().collection("actions").add(action);
|
|
165
|
+
await snapshot.ref.update({ "@form.@status": "submitted" });
|
|
166
|
+
const logicResults = await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action);
|
|
167
|
+
// Save all logic results under logicResults collection of action document
|
|
168
|
+
await Promise.all(logicResults.map(async (result) => {
|
|
169
|
+
const { documents } = result, logicResult = __rest(result, ["documents"]);
|
|
170
|
+
const logicResultRef = await actionRef.collection("logicResults").add(logicResult);
|
|
171
|
+
await Promise.all(documents.map(async (doc) => {
|
|
172
|
+
await logicResultRef.collection("documents").add(doc);
|
|
173
|
+
}));
|
|
174
|
+
}));
|
|
175
|
+
const errorLogicResults = logicResults.filter((result) => result.status === "error");
|
|
176
|
+
if (errorLogicResults.length > 0) {
|
|
177
|
+
const errorMessage = errorLogicResults.map((result) => result.message).join("\n");
|
|
178
|
+
await actionRef.update({ status: "finished-with-error", message: errorMessage });
|
|
179
|
+
}
|
|
180
|
+
const dstPathLogicDocsMap = (0, index_utils_1.consolidateAndGroupByDstPath)(logicResults);
|
|
181
|
+
const { userDocsByDstPath, otherUsersDocsByDstPath, } = (0, index_utils_1.groupDocsByUserAndDstPath)(dstPathLogicDocsMap, userId);
|
|
182
|
+
const viewLogicResults = await (0, index_utils_1.runViewLogics)(userDocsByDstPath);
|
|
183
|
+
const dstPathViewLogicDocsMap = (0, index_utils_1.consolidateAndGroupByDstPath)(viewLogicResults);
|
|
184
|
+
const { userDocsByDstPath: userViewDocsByDstPath, otherUsersDocsByDstPath: otherUsersViewDocsByDstPath, } = (0, index_utils_1.groupDocsByUserAndDstPath)(dstPathViewLogicDocsMap, userId);
|
|
185
|
+
await (0, index_utils_1.distribute)(userDocsByDstPath);
|
|
186
|
+
await (0, index_utils_1.distribute)(userViewDocsByDstPath);
|
|
187
|
+
await snapshot.ref.update({ "@form.@status": "finished" });
|
|
188
|
+
const peerSyncViewLogicResults = await (0, index_utils_1.runPeerSyncViews)(userDocsByDstPath);
|
|
189
|
+
const dstPathPeerSyncViewLogicDocsMap = (0, index_utils_1.consolidateAndGroupByDstPath)(peerSyncViewLogicResults);
|
|
190
|
+
const { otherUsersDocsByDstPath: otherUsersPeerSyncViewDocsByDstPath } = (0, index_utils_1.groupDocsByUserAndDstPath)(dstPathPeerSyncViewLogicDocsMap, userId);
|
|
191
|
+
await (0, index_utils_1.distribute)(otherUsersDocsByDstPath);
|
|
192
|
+
await (0, index_utils_1.distribute)(otherUsersViewDocsByDstPath);
|
|
193
|
+
await (0, index_utils_1.distribute)(otherUsersPeerSyncViewDocsByDstPath);
|
|
194
|
+
await actionRef.update({ status: "finished" });
|
|
195
|
+
}
|
|
196
|
+
exports.onDocChange = onDocChange;
|
|
197
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ViewDefinition } from "./types";
|
|
2
|
+
export declare function traverseBFS(obj: Record<string, object>): string[];
|
|
3
|
+
export declare function mapDocPaths(paths: string[], Entity: Record<string, string>): Record<string, string>;
|
|
4
|
+
export declare function mapColPaths(docPathsMap: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}): {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function mapViewDefinitions(paths: string[], Entity: Record<string, string>, docPaths: Record<string, string>): ViewDefinition[];
|
|
10
|
+
export declare function initDbStructure(dbStructure: Record<string, object>, Entity: Record<string, string>): {
|
|
11
|
+
docPaths: Record<string, string>;
|
|
12
|
+
docPathsRegex: Record<string, RegExp>;
|
|
13
|
+
colPaths: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
viewDefinitions: ViewDefinition[];
|
|
17
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDbStructure = exports.mapViewDefinitions = exports.mapColPaths = exports.mapDocPaths = exports.traverseBFS = void 0;
|
|
4
|
+
function traverseBFS(obj) {
|
|
5
|
+
const paths = [];
|
|
6
|
+
const queue = [];
|
|
7
|
+
// Enqueue the root object with an empty path
|
|
8
|
+
queue.push({ node: obj, path: "" });
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
// Dequeue the next node
|
|
11
|
+
const item = queue.shift();
|
|
12
|
+
if (!item)
|
|
13
|
+
continue;
|
|
14
|
+
const node = item.node;
|
|
15
|
+
const path = item.path;
|
|
16
|
+
// Enqueue the child objects with their paths
|
|
17
|
+
for (const key in node) {
|
|
18
|
+
if (typeof node[key] === "object" && node[key] !== null) {
|
|
19
|
+
if (key.startsWith("View:")) {
|
|
20
|
+
const viewPath = `${path}=${key}`;
|
|
21
|
+
paths.push(viewPath);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const newPath = path === "" ? key : `${path}/${key}`;
|
|
25
|
+
paths.push(newPath);
|
|
26
|
+
queue.push({ node: node[key], path: newPath });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (typeof node[key] === "string") {
|
|
30
|
+
const value = node[key];
|
|
31
|
+
if (value.startsWith("View:")) {
|
|
32
|
+
const propView = `#${key}=${value}`;
|
|
33
|
+
const viewPath = `${path}${propView}`;
|
|
34
|
+
paths.push(viewPath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return paths;
|
|
40
|
+
}
|
|
41
|
+
exports.traverseBFS = traverseBFS;
|
|
42
|
+
function mapDocPaths(paths, Entity) {
|
|
43
|
+
const docPathsMap = {};
|
|
44
|
+
for (const entityKey of Object.values(Entity)) {
|
|
45
|
+
const entityWithModifier = new RegExp(`/${entityKey}([#=][^/]*)?$`);
|
|
46
|
+
const entityPaths = paths.filter((path) => entityWithModifier.test(path));
|
|
47
|
+
if (entityPaths.length > 0) {
|
|
48
|
+
const entityPath = entityPaths[0];
|
|
49
|
+
docPathsMap[entityKey] = entityPath.split("/").map((element) => {
|
|
50
|
+
element = element.split(/[#=]/)[0];
|
|
51
|
+
if (Object.values(Entity).includes(element)) {
|
|
52
|
+
return `{${element}Id}`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return element;
|
|
56
|
+
}
|
|
57
|
+
}).join("/");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return docPathsMap;
|
|
61
|
+
}
|
|
62
|
+
exports.mapDocPaths = mapDocPaths;
|
|
63
|
+
function mapColPaths(docPathsMap) {
|
|
64
|
+
const colPathsMap = {};
|
|
65
|
+
for (const [entityKey, docPath] of Object.entries(docPathsMap)) {
|
|
66
|
+
colPathsMap[entityKey] = docPath.split("/").slice(0, -1).join("/");
|
|
67
|
+
}
|
|
68
|
+
return colPathsMap;
|
|
69
|
+
}
|
|
70
|
+
exports.mapColPaths = mapColPaths;
|
|
71
|
+
function mapViewDefinitions(paths, Entity, docPaths) {
|
|
72
|
+
var _a;
|
|
73
|
+
const viewDefs = [];
|
|
74
|
+
for (const path of paths) {
|
|
75
|
+
const match = path.match(/^([^#]*)(#.+)?=(View:.+)$/);
|
|
76
|
+
if (match) {
|
|
77
|
+
const destPath = match[1];
|
|
78
|
+
// Get the last word of the path
|
|
79
|
+
const destEntity = destPath.split("/").slice(-1)[0];
|
|
80
|
+
const destProp = (_a = match[2]) === null || _a === void 0 ? void 0 : _a.slice(1);
|
|
81
|
+
const viewDefinitionStr = match[3];
|
|
82
|
+
const [_, srcEntity, srcPropsStr] = viewDefinitionStr.split(":");
|
|
83
|
+
const srcProps = srcPropsStr.split(",");
|
|
84
|
+
// if srcEntity in Entity and destEntity exists
|
|
85
|
+
if (Object.values(Entity).includes(srcEntity) && destEntity) {
|
|
86
|
+
viewDefs.push({
|
|
87
|
+
destEntity,
|
|
88
|
+
destProp,
|
|
89
|
+
srcProps,
|
|
90
|
+
srcEntity,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return viewDefs;
|
|
96
|
+
}
|
|
97
|
+
exports.mapViewDefinitions = mapViewDefinitions;
|
|
98
|
+
function initDbStructure(dbStructure, Entity) {
|
|
99
|
+
const paths = traverseBFS(dbStructure);
|
|
100
|
+
const docPaths = mapDocPaths(paths, Entity);
|
|
101
|
+
const viewDefinitions = mapViewDefinitions(paths, Entity, docPaths);
|
|
102
|
+
const docPathsRegex = {};
|
|
103
|
+
for (const [key, value] of Object.entries(docPaths)) {
|
|
104
|
+
const regexPattern = value.replace(/{(\w+)Id}/g, "([^/]+)");
|
|
105
|
+
docPathsRegex[key] = new RegExp(`^${regexPattern}$`);
|
|
106
|
+
}
|
|
107
|
+
const colPaths = mapColPaths(docPaths);
|
|
108
|
+
return { docPaths, docPathsRegex, colPaths, viewDefinitions };
|
|
109
|
+
}
|
|
110
|
+
exports.initDbStructure = initDbStructure;
|
|
111
|
+
//# sourceMappingURL=init-db-structure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-db-structure.js","sourceRoot":"","sources":["../src/init-db-structure.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,GAA2B;IACrD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAoD,EAAE,CAAC;IAElE,6CAA6C;IAC7C,KAAK,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC,CAAC;IAElC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACvB,wBAAwB;QACxB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI;YAAE,SAAS;QAEpB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEvB,6CAA6C;QAC7C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;gBACvD,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;oBAC3B,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;oBAClC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;iBACtB;qBAAM;oBACL,MAAM,OAAO,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;oBACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACpB,KAAK,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,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= 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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createViewLogicFn = void 0;
|
|
27
|
+
const index_1 = require("../index");
|
|
28
|
+
const admin = __importStar(require("firebase-admin"));
|
|
29
|
+
const paths_1 = require("../utils/paths");
|
|
30
|
+
function createViewLogicFn(viewDefinition) {
|
|
31
|
+
return async (action) => {
|
|
32
|
+
const { srcProps, destEntity, destProp } = viewDefinition;
|
|
33
|
+
const { document, path, actionType } = action;
|
|
34
|
+
console.log(`Executing ViewLogic on document at ${path}...`);
|
|
35
|
+
const docId = path.split("/").slice(-1)[0];
|
|
36
|
+
const destDocPath = index_1.docPaths[destEntity];
|
|
37
|
+
const destPaths = await (0, paths_1.hydrateDocPath)(destDocPath, {
|
|
38
|
+
[destEntity]: {
|
|
39
|
+
fieldName: destProp ? `${destProp}.id` : "id",
|
|
40
|
+
operator: "==",
|
|
41
|
+
value: docId,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
let documents;
|
|
45
|
+
if (actionType === "delete") {
|
|
46
|
+
documents = destPaths.map((destPath) => {
|
|
47
|
+
return {
|
|
48
|
+
action: "delete",
|
|
49
|
+
dstPath: path,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const viewDoc = {};
|
|
55
|
+
for (const srcProp of srcProps) {
|
|
56
|
+
if (document[srcProp]) {
|
|
57
|
+
viewDoc[`${destProp ? `${destProp}.` : ""}${srcProp}`] = document[srcProp];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
documents = destPaths.map((destPath) => {
|
|
61
|
+
return {
|
|
62
|
+
action: "merge",
|
|
63
|
+
dstPath: destPath,
|
|
64
|
+
doc: viewDoc,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
name: `${destEntity}#${destProp} ViewLogic`,
|
|
70
|
+
status: "finished",
|
|
71
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
72
|
+
documents,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.createViewLogicFn = createViewLogicFn;
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logics/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAAkC;AAClC,sDAAwC;AACxC,0CAA8C;AAE9C,SAAgB,iBAAiB,CAAC,cAA8B;IAC9D,OAAO,KAAK,EAAE,MAAc,EAAE,EAAE;QAC9B,MAAM,EAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAC,GAAG,cAAc,CAAC;QACxD,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAC,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,CAAC;SACJ;QAED,OAAO;YACL,IAAI,EAAE,GAAG,UAAU,IAAI,QAAQ,YAAY;YAC3C,MAAM,EAAE,UAAU;YAClB,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE;YAC7C,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAlDD,8CAkDC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.syncPeerViews = exports.createViewLogicFn = void 0;
|
|
27
|
+
const index_1 = require("../index");
|
|
28
|
+
const admin = __importStar(require("firebase-admin"));
|
|
29
|
+
const paths_1 = require("../utils/paths");
|
|
30
|
+
function createViewLogicFn(viewDefinition) {
|
|
31
|
+
return async (logicResultDoc) => {
|
|
32
|
+
const { srcProps, destEntity, destProp, } = viewDefinition;
|
|
33
|
+
const { doc, instructions, dstPath: actualSrcPath, action, } = logicResultDoc;
|
|
34
|
+
console.log(`Executing ViewLogic on document at ${actualSrcPath}...`);
|
|
35
|
+
let destPaths = [];
|
|
36
|
+
const destDocPath = index_1.docPaths[destEntity];
|
|
37
|
+
const docId = actualSrcPath.split("/").slice(-1)[0];
|
|
38
|
+
if (destProp) {
|
|
39
|
+
destPaths = await (0, paths_1.hydrateDocPath)(destDocPath, {
|
|
40
|
+
[destEntity]: {
|
|
41
|
+
fieldName: `${destProp}.id`,
|
|
42
|
+
operator: "==",
|
|
43
|
+
value: docId,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const dehydratedPath = `${destDocPath.split("/").slice(0, -1).join("/")}/${docId}`;
|
|
49
|
+
destPaths = await (0, paths_1.hydrateDocPath)(dehydratedPath, {});
|
|
50
|
+
}
|
|
51
|
+
if (action === "delete") {
|
|
52
|
+
const documents = destPaths.map((destPath) => {
|
|
53
|
+
return {
|
|
54
|
+
action: "delete",
|
|
55
|
+
dstPath: destPath,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
name: `${destEntity}#${destProp} ViewLogic`,
|
|
60
|
+
status: "finished",
|
|
61
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
62
|
+
documents,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const viewDoc = {};
|
|
67
|
+
const viewInstructions = {};
|
|
68
|
+
for (const srcProp of srcProps) {
|
|
69
|
+
if (doc === null || doc === void 0 ? void 0 : doc[srcProp]) {
|
|
70
|
+
viewDoc[`${destProp ? `${destProp}.` : ""}${srcProp}`] = doc[srcProp];
|
|
71
|
+
}
|
|
72
|
+
if (instructions === null || instructions === void 0 ? void 0 : instructions[srcProp]) {
|
|
73
|
+
viewInstructions[`${destProp ? `${destProp}.` : ""}${srcProp}`] = instructions[srcProp];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const documents = destPaths.map((destPath) => {
|
|
77
|
+
return {
|
|
78
|
+
action: "merge",
|
|
79
|
+
dstPath: destPath,
|
|
80
|
+
doc: viewDoc,
|
|
81
|
+
instructions: viewInstructions,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
name: `${destEntity}#${destProp} ViewLogic`,
|
|
86
|
+
status: "finished",
|
|
87
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
88
|
+
documents,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
exports.createViewLogicFn = createViewLogicFn;
|
|
94
|
+
const syncPeerViews = async (logicResultDoc) => {
|
|
95
|
+
const { dstPath, doc, instructions, } = logicResultDoc;
|
|
96
|
+
const { entity, regex } = (0, paths_1.findMatchingDocPathRegex)(dstPath);
|
|
97
|
+
if (!entity) {
|
|
98
|
+
return {
|
|
99
|
+
name: "SyncPeerViews",
|
|
100
|
+
status: "error",
|
|
101
|
+
message: `No matching entity found for path ${dstPath}`,
|
|
102
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
103
|
+
documents: [],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const docPath = index_1.docPaths[entity];
|
|
107
|
+
let matchedGroups = dstPath.match(regex);
|
|
108
|
+
const matchedValues = matchedGroups === null || matchedGroups === void 0 ? void 0 : matchedGroups.slice(1);
|
|
109
|
+
matchedGroups = docPath.match(regex);
|
|
110
|
+
const matchedKeys = matchedGroups === null || matchedGroups === void 0 ? void 0 : matchedGroups.slice(1);
|
|
111
|
+
if (!matchedKeys || !matchedValues) {
|
|
112
|
+
return {
|
|
113
|
+
name: "SyncPeerViews",
|
|
114
|
+
status: "error",
|
|
115
|
+
message: `No matching keys or values found for path ${dstPath}`,
|
|
116
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
117
|
+
documents: [],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const userIdKey = matchedKeys[0];
|
|
121
|
+
const userId = matchedValues[0];
|
|
122
|
+
const entityIdKey = matchedKeys[matchedKeys.length - 1];
|
|
123
|
+
const entityId = matchedValues[matchedValues.length - 1];
|
|
124
|
+
// Create a map combining matchedKeys and matchedValues
|
|
125
|
+
const matchedKeyValues = matchedKeys.reduce((acc, key, index) => {
|
|
126
|
+
acc[key] = matchedValues[index];
|
|
127
|
+
return acc;
|
|
128
|
+
}, {});
|
|
129
|
+
// Create a dehydrated path from docPath replacing keys with values except for the first key and the last key
|
|
130
|
+
const dehydratedPath = docPath.replace(/({[^/]+Id})/g, (match, ...args) => {
|
|
131
|
+
const matchedKey = args[0];
|
|
132
|
+
if (matchedKey === userIdKey || matchedKey === entityIdKey) {
|
|
133
|
+
return matchedKey;
|
|
134
|
+
}
|
|
135
|
+
return matchedKeyValues[matchedKey];
|
|
136
|
+
});
|
|
137
|
+
const forSyncPaths = await (0, paths_1.hydrateDocPath)(dehydratedPath, {
|
|
138
|
+
[entity]: {
|
|
139
|
+
fieldName: "@id",
|
|
140
|
+
operator: "==",
|
|
141
|
+
value: entityId,
|
|
142
|
+
},
|
|
143
|
+
user: {
|
|
144
|
+
fieldName: "@id",
|
|
145
|
+
operator: "!=",
|
|
146
|
+
value: userId,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
// Loop through all the paths and create a document for each
|
|
150
|
+
const documents = forSyncPaths.map((forSyncPath) => {
|
|
151
|
+
return {
|
|
152
|
+
action: "merge",
|
|
153
|
+
dstPath: forSyncPath,
|
|
154
|
+
doc: doc,
|
|
155
|
+
instructions: instructions,
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
// Return the result with the hydrated documents
|
|
159
|
+
return {
|
|
160
|
+
name: "SyncPeerViews",
|
|
161
|
+
status: "finished",
|
|
162
|
+
timeFinished: admin.firestore.Timestamp.now(),
|
|
163
|
+
documents,
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
exports.syncPeerViews = syncPeerViews;
|
|
167
|
+
//# sourceMappingURL=view-logics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-logics.js","sourceRoot":"","sources":["../../src/logics/view-logics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAAkC;AAClC,sDAAwC;AACxC,0CAAwE;AAExE,SAAgB,iBAAiB,CAAC,cAA8B;IAC9D,OAAO,KAAK,EAAE,cAA8B,EAAE,EAAE;QAC9C,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,GAAG,cAAc,CAAC;QACnB,MAAM,EACJ,GAAG,EACH,YAAY,EACZ,OAAO,EAAE,aAAa,EACtB,MAAM,GACP,GAAG,cAAc,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,sCAAsC,aAAa,KAAK,CAAC,CAAC;QACtE,IAAI,SAAS,GAAa,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,gBAAQ,CAAC,UAAU,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,IAAI,QAAQ,EAAE;YACZ,SAAS,GAAG,MAAM,IAAA,sBAAc,EAAC,WAAW,EAAE;gBAC5C,CAAC,UAAU,CAAC,EAAE;oBACZ,SAAS,EAAE,GAAG,QAAQ,KAAK;oBAC3B,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,KAAK;iBACb;aACF,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,cAAc,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,C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