appwrite-utils-cli 1.7.7 → 1.7.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.
@@ -143,13 +143,18 @@ export class SchemaGenerator {
143
143
  collectionsFolderPath,
144
144
  `${collection.name}.ts`
145
145
  );
146
+
147
+ // Determine if we're in tables mode for terminology
148
+ const isTablesMode = outputDir === "tables";
149
+ const securityField = isTablesMode ? "rowSecurity" : "documentSecurity";
150
+
146
151
  const collectionContent = `import { type CollectionCreate } from "appwrite-utils";
147
-
152
+
148
153
  const ${collection.name}Config: Partial<CollectionCreate> = {
149
154
  name: "${collection.name}",
150
155
  $id: "${collection.$id}",
151
156
  enabled: ${collection.enabled},
152
- documentSecurity: ${collection.documentSecurity},
157
+ ${securityField}: ${collection.documentSecurity},
153
158
  $permissions: [
154
159
  ${collection.$permissions
155
160
  .map(
@@ -163,22 +168,33 @@ export class SchemaGenerator {
163
168
  .map((attr) => {
164
169
  return `{ ${Object.entries(attr)
165
170
  .map(([key, value]) => {
171
+ // Handle table vs collection terminology for related fields
172
+ let outputKey = key;
173
+ let outputValue = value;
174
+
175
+ if (isTablesMode) {
176
+ // Convert collection terminology to table terminology
177
+ if (key === "relatedCollection") {
178
+ outputKey = "relatedTable";
179
+ }
180
+ }
181
+
166
182
  // Check the type of the value and format it accordingly
167
- if (typeof value === "string") {
183
+ if (typeof outputValue === "string") {
168
184
  // If the value is a string, wrap it in quotes
169
- return `${key}: "${value.replace(/"/g, '\\"')}"`; // Escape existing quotes in the string
170
- } else if (Array.isArray(value)) {
185
+ return `${outputKey}: "${outputValue.replace(/"/g, '\\"')}"`; // Escape existing quotes in the string
186
+ } else if (Array.isArray(outputValue)) {
171
187
  // If the value is an array, join it with commas
172
- if (value.length > 0) {
173
- return `${key}: [${value
188
+ if (outputValue.length > 0) {
189
+ return `${outputKey}: [${outputValue
174
190
  .map((item) => `"${item}"`)
175
191
  .join(", ")}]`;
176
192
  } else {
177
- return `${key}: []`;
193
+ return `${outputKey}: []`;
178
194
  }
179
195
  } else {
180
196
  // If the value is not a string (e.g., boolean or number), output it directly
181
- return `${key}: ${value}`;
197
+ return `${outputKey}: ${outputValue}`;
182
198
  }
183
199
  })
184
200
  .join(", ")} }`;
@@ -188,12 +204,13 @@ export class SchemaGenerator {
188
204
  indexes: [
189
205
  ${(
190
206
  collection.indexes?.map((index) => {
191
- // Map each attribute to ensure it is properly quoted
207
+ // Use appropriate terminology for index attributes/columns
208
+ const indexField = isTablesMode ? "columns" : "attributes";
192
209
  const formattedAttributes =
193
210
  index.attributes.map((attr) => `"${attr}"`).join(", ") ?? "";
194
211
  return `{ key: "${index.key}", type: "${
195
212
  index.type
196
- }", attributes: [${formattedAttributes}], orders: [${
213
+ }", ${indexField}: [${formattedAttributes}], orders: [${
197
214
  index.orders
198
215
  ?.filter((order) => order !== null)
199
216
  .map((order) => `"${order}"`)
@@ -203,7 +220,7 @@ export class SchemaGenerator {
203
220
  ).join(",\n ")}
204
221
  ]
205
222
  };
206
-
223
+
207
224
  export default ${collection.name}Config;
208
225
  `;
209
226
  fs.writeFileSync(collectionFilePath, collectionContent, {