@stoker-platform/cli 0.5.140 → 0.5.141

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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/cli",
3
- "version": "0.5.139",
3
+ "version": "0.5.140",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./lib/src/main.js",
@@ -1,5 +1,5 @@
1
1
  import { getFirestorePathRef, getStokerFirestore } from "@stoker-platform/node-client";
2
- import { addDenormalized, getAllRoleGroups, getDependencyIndexFields, getFieldAccessGroupFields, getRoleGroups, isDependencyField, } from "@stoker-platform/utils";
2
+ import { addDenormalized, getAllRoleGroups, getDependencyIndexFields, getFieldAccessGroupFields, getFieldAccessGroupIndexFields, getFieldAccessGroupKey, getRoleGroups, isDependencyField, } from "@stoker-platform/utils";
3
3
  import { FieldValue } from "firebase-admin/firestore";
4
4
  import isEqual from "lodash/isEqual.js";
5
5
  const getUniqueFieldNames = (collectionSchema) => collectionSchema.fields
@@ -32,6 +32,31 @@ const getFieldAccessGroupFieldShape = (collectionSchema) => {
32
32
  }
33
33
  return shape;
34
34
  };
35
+ const getProjectionKeys = (collectionSchema, schema) => {
36
+ const keys = new Set();
37
+ const roleGroups = getRoleGroups(collectionSchema, schema);
38
+ for (const group of roleGroups) {
39
+ keys.add(group.key);
40
+ }
41
+ const fieldAccessGroups = getFieldAccessGroupFields(collectionSchema);
42
+ for (const [groupKey, groupFields] of Object.entries(fieldAccessGroups)) {
43
+ if (groupFields.length === 0)
44
+ continue;
45
+ for (const group of roleGroups) {
46
+ const indexFields = getFieldAccessGroupIndexFields(groupKey, collectionSchema, group);
47
+ if (indexFields.length === 0)
48
+ continue;
49
+ const overlayKey = getFieldAccessGroupKey(groupKey, group.key);
50
+ keys.add(overlayKey);
51
+ }
52
+ }
53
+ for (const field of collectionSchema.fields) {
54
+ if (isDependencyField(field, collectionSchema, schema)) {
55
+ keys.add(field.name);
56
+ }
57
+ }
58
+ return keys;
59
+ };
35
60
  const replayProjectionsForCollection = async (collection, currentSchema, lastSchema) => {
36
61
  console.log(`Projections for collection ${collection} have changed. Replaying...`);
37
62
  const db = getStokerFirestore();
@@ -44,8 +69,24 @@ const replayProjectionsForCollection = async (collection, currentSchema, lastSch
44
69
  const lastCollectionSchema = lastSchema.collections[collection];
45
70
  // eslint-disable-next-line security/detect-object-injection
46
71
  const currentCollectionSchema = currentSchema.collections[collection];
47
- const lastRoleGroups = getAllRoleGroups(lastSchema);
48
72
  const currentRoleGroups = getAllRoleGroups(currentSchema);
73
+ const projectionKeys = new Set([
74
+ ...getProjectionKeys(lastCollectionSchema, lastSchema),
75
+ ...getProjectionKeys(currentCollectionSchema, currentSchema),
76
+ ]);
77
+ const uniqueFieldNames = new Set([
78
+ ...getUniqueFieldNames(lastCollectionSchema),
79
+ ...getUniqueFieldNames(currentCollectionSchema),
80
+ ]);
81
+ const tenants = await db.collection("tenants").listDocuments();
82
+ for (const tenant of tenants) {
83
+ for (const key of projectionKeys) {
84
+ await db.recursiveDelete(tenant.collection("system_fields").doc(collection).collection(`${collection}-${key}`));
85
+ }
86
+ for (const fieldName of uniqueFieldNames) {
87
+ await db.recursiveDelete(tenant.collection("system_unique").doc(collection).collection(`Unique-${collection}-${fieldName}`));
88
+ }
89
+ }
49
90
  const querySnapshot = await db.collectionGroup(collection).get();
50
91
  for (const doc of querySnapshot.docs) {
51
92
  const tenantId = doc.ref.path.split("/")[1];
@@ -93,14 +134,6 @@ const replayProjectionsForCollection = async (collection, currentSchema, lastSch
93
134
  .doc(field.collection)
94
135
  .collection(`${field.collection}-${role.replaceAll(" ", "-")}`)
95
136
  .doc(id);
96
- for (const field of lastCollectionSchema.fields) {
97
- if ("unique" in field &&
98
- field.unique &&
99
- (typeof record[field.name] === "string" || typeof record[field.name] === "number")) {
100
- bulkWriter.delete(uniqueRef(field, record[field.name].toString().toLowerCase().replace(/\s/g, "---").replaceAll("/", "|||")));
101
- }
102
- }
103
- addDenormalized("delete", bulkWriter, path, doc.id, record, lastSchema, lastCollectionSchema, { noTwoWay: true }, lastRoleGroups, FieldValue.arrayUnion, FieldValue.arrayRemove, FieldValue.delete, dependencyRef, uniqueRef, privateRef, twoWayIncludeRef, twoWayDependencyRef, twoWayPrivateRef);
104
137
  addDenormalized("create", bulkWriter, path, doc.id, record, currentSchema, currentCollectionSchema, { noTwoWay: true }, currentRoleGroups, FieldValue.arrayUnion, FieldValue.arrayRemove, FieldValue.delete, dependencyRef, uniqueRef, privateRef, twoWayIncludeRef, twoWayDependencyRef, twoWayPrivateRef);
105
138
  }
106
139
  await bulkWriter.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/cli",
3
- "version": "0.5.140",
3
+ "version": "0.5.141",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./lib/src/main.js",