@stoker-platform/cli 0.5.90 → 0.5.92

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.89",
3
+ "version": "0.5.92",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./lib/src/main.js",
@@ -126,7 +126,7 @@ export const lintSchema = async (noLog = false) => {
126
126
  }
127
127
  }
128
128
  for (const [collectionName, collectionSchema] of collectionSchemas) {
129
- const { labels, auth, fields, access, ttl, parentCollection, recordTitleField, softDelete, roleSystemFields, preloadCache, relationLists, fullTextSearch, ai, } = collectionSchema;
129
+ const { labels, auth, fields, access, singleton, ttl, parentCollection, recordTitleField, softDelete, roleSystemFields, preloadCache, relationLists, fullTextSearch, ai, } = collectionSchema;
130
130
  const { auth: authAccess, operations, attributeRestrictions, entityRestrictions, permissionWriteRestrictions, serverReadOnly, serverWriteOnly, files, } = access;
131
131
  // eslint-disable-next-line security/detect-object-injection
132
132
  const customization = customizationModules[collectionName];
@@ -238,6 +238,17 @@ export const lintSchema = async (noLog = false) => {
238
238
  errors.push(`Auth collection ${collectionName} cannot have a parent collection`);
239
239
  }
240
240
  }
241
+ if (singleton) {
242
+ if (auth) {
243
+ errors.push(`Singleton collection ${collectionName} cannot have auth enabled`);
244
+ }
245
+ if (operations.create) {
246
+ errors.push(`Singleton collection ${collectionName} cannot have create operations`);
247
+ }
248
+ if (operations.delete) {
249
+ errors.push(`Singleton collection ${collectionName} cannot have delete operations`);
250
+ }
251
+ }
241
252
  if (parentCollection) {
242
253
  if (!collectionNames.includes(parentCollection)) {
243
254
  errors.push(`Collection ${collectionName} has a parent collection ${parentCollection} that does not exist`);
@@ -8,38 +8,47 @@ export const auditRelations = async (options) => {
8
8
  await initializeStoker(options.mode || "production", options.tenant, join(process.cwd(), "lib", "main.js"), join(process.cwd(), "lib", "collections"));
9
9
  const schema = await fetchCurrentSchema();
10
10
  const db = getFirestore();
11
- for (const [collectionName, collectionSchema] of Object.entries(schema.collections)) {
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
- const collectionData = {};
11
+ const tenantPrefix = `tenants/${options.tenant}`;
12
+ const recordByDocumentPath = new Map();
13
+ const collectionDocsByName = new Map();
14
+ for (const [collectionName] of Object.entries(schema.collections)) {
14
15
  console.log(`Loading ${collectionName}...`);
15
16
  const collectionSnapshot = await db.collectionGroup(collectionName).get();
17
+ const tenantDocs = collectionSnapshot.docs.filter((doc) => doc.ref.path.includes(tenantPrefix));
18
+ collectionDocsByName.set(collectionName, tenantDocs);
19
+ for (const doc of tenantDocs) {
20
+ recordByDocumentPath.set(doc.ref.path, doc.data());
21
+ }
22
+ }
23
+ for (const [collectionName, collectionSchema] of Object.entries(schema.collections)) {
24
+ const collectionDocs = collectionDocsByName.get(collectionName) || [];
16
25
  console.log(`Auditing ${collectionName}...`);
17
- collectionSnapshot.forEach((doc) => {
18
- if (!doc.ref.path.includes(`tenants/${options.tenant}`)) {
19
- return;
26
+ for (const field of collectionSchema.fields) {
27
+ if ("collection" in field) {
28
+ field.includeFields ||= [];
29
+ if (!field.includeFields.includes("Collection_Path")) {
30
+ field.includeFields.push("Collection_Path");
31
+ }
32
+ if (!field.includeFields.includes("deleted")) {
33
+ field.includeFields.push("deleted");
34
+ }
20
35
  }
21
- collectionData[doc.id] = doc.data();
22
- });
36
+ }
23
37
  const singleFieldRelations = getSingleFieldRelations(collectionSchema, collectionSchema.fields);
24
38
  const singleFieldRelationNames = Array.from(singleFieldRelations).map((field) => field.name);
25
- for (const doc of collectionSnapshot.docs) {
26
- if (!doc.ref.path.includes(`tenants/${options.tenant}`)) {
27
- continue;
28
- }
39
+ for (const doc of collectionDocs) {
29
40
  const record = doc.data();
30
41
  for (const field of collectionSchema.fields) {
31
42
  if ("collection" in field) {
32
43
  field.includeFields ||= [];
33
- field.includeFields.push("Collection_Path");
34
- field.includeFields.push("deleted");
35
44
  const relationCollection = schema.collections[field.collection];
36
45
  if (record[field.name]) {
37
46
  for (const relationRecord of Object.entries(record[field.name])) {
38
47
  const [id, relation] = relationRecord;
39
48
  const mainRelation = relation;
40
49
  const ref = getFirestorePathRef(db, mainRelation.Collection_Path, options.tenant);
41
- const sourceRef = await ref.doc(id).get();
42
- const source = sourceRef.data();
50
+ const sourceDocRef = ref.doc(id);
51
+ const source = recordByDocumentPath.get(sourceDocRef.path);
43
52
  if (!source) {
44
53
  if (field.preserve) {
45
54
  for (const includeField of field.includeFields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/cli",
3
- "version": "0.5.90",
3
+ "version": "0.5.92",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./lib/src/main.js",