pocketbase-zod-schema 0.3.1 → 0.3.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.cjs +36 -32
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +2 -2
  5. package/dist/cli/index.d.ts +2 -2
  6. package/dist/cli/index.js +36 -32
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +36 -32
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +36 -32
  11. package/dist/cli/migrate.js.map +1 -1
  12. package/dist/cli/utils/index.d.cts +2 -2
  13. package/dist/cli/utils/index.d.ts +2 -2
  14. package/dist/{fields-RVj26U-O.d.cts → fields-DBBm06VU.d.cts} +34 -7
  15. package/dist/{fields-RVj26U-O.d.ts → fields-DBBm06VU.d.ts} +34 -7
  16. package/dist/index.cjs +125 -66
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +125 -66
  21. package/dist/index.js.map +1 -1
  22. package/dist/migration/analyzer.cjs.map +1 -1
  23. package/dist/migration/analyzer.d.cts +2 -2
  24. package/dist/migration/analyzer.d.ts +2 -2
  25. package/dist/migration/analyzer.js.map +1 -1
  26. package/dist/migration/diff.d.cts +2 -2
  27. package/dist/migration/diff.d.ts +2 -2
  28. package/dist/migration/generator.cjs +70 -60
  29. package/dist/migration/generator.cjs.map +1 -1
  30. package/dist/migration/generator.d.cts +2 -2
  31. package/dist/migration/generator.d.ts +2 -2
  32. package/dist/migration/generator.js +70 -60
  33. package/dist/migration/generator.js.map +1 -1
  34. package/dist/migration/index.cjs +70 -60
  35. package/dist/migration/index.cjs.map +1 -1
  36. package/dist/migration/index.d.cts +3 -3
  37. package/dist/migration/index.d.ts +3 -3
  38. package/dist/migration/index.js +70 -60
  39. package/dist/migration/index.js.map +1 -1
  40. package/dist/migration/snapshot.d.cts +2 -2
  41. package/dist/migration/snapshot.d.ts +2 -2
  42. package/dist/migration/utils/index.cjs.map +1 -1
  43. package/dist/migration/utils/index.d.cts +2 -2
  44. package/dist/migration/utils/index.d.ts +2 -2
  45. package/dist/migration/utils/index.js.map +1 -1
  46. package/dist/schema.cjs +55 -6
  47. package/dist/schema.cjs.map +1 -1
  48. package/dist/schema.d.cts +1 -1
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/schema.js +55 -6
  51. package/dist/schema.js.map +1 -1
  52. package/dist/{type-mapper-DaBe-1ph.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
  53. package/dist/{type-mapper-CZzVeDj7.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
  54. package/dist/{types-D-Fsdn_O.d.cts → types-CVxPCgWX.d.cts} +1 -1
  55. package/dist/{types-CUVzgZ9k.d.ts → types-Dfp-NP2D.d.ts} +1 -1
  56. package/package.json +1 -1
@@ -2,9 +2,9 @@ export { SchemaAnalyzer, SchemaAnalyzerConfig, buildFieldDefinition, buildSchema
2
2
  export { SnapshotConfig, SnapshotManager, convertPocketBaseMigration, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot } from './snapshot.cjs';
3
3
  export { ChangeSummary, DestructiveChange, DiffEngine, DiffEngineConfig, aggregateChanges, categorizeChangesBySeverity, compare, compareFieldConstraints, compareFieldOptions, compareFieldTypes, comparePermissions, compareRelationConfigurations, detectDestructiveChanges, detectFieldChanges, filterSystemCollections, findNewCollections, findNewFields, findRemovedCollections, findRemovedFields, generateChangeSummary, getUsersSystemFields, isSystemCollection, matchCollectionsByName, matchFieldsByName, requiresForceFlag } from './diff.cjs';
4
4
  export { MigrationGenerator, MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generatePermissionUpdate, generateTimestamp, generateUpMigration, writeMigrationFile } from './generator.cjs';
5
- export { d as CollectionModification, f as CollectionOperation, C as CollectionSchema, b as FieldChange, F as FieldDefinition, c as FieldModification, P as PermissionChange, R as RuleUpdate, S as SchemaDefinition, e as SchemaDiff, a as SchemaSnapshot } from '../types-D-Fsdn_O.cjs';
6
- export { E as ExtractedFieldOptions, d as FIELD_TYPE_INFO, F as FieldTypeInfo, C as FieldTypeResult, P as POCKETBASE_FIELD_TYPES, z as extractComprehensiveFieldOptions, o as extractFieldOptions, x as getArrayElementType, v as getDefaultValue, D as getFieldTypeInfo, g as getMaxSelect, c as getMinSelect, w as isArrayType, A as isEditorField, q as isFieldRequired, B as isFileFieldByName, y as isGeoPointType, a as isMultipleRelationField, b as isRelationField, i as isSingleRelationField, j as mapZodArrayType, f as mapZodBooleanType, k as mapZodDateType, h as mapZodEnumType, e as mapZodNumberType, l as mapZodRecordType, m as mapZodStringType, n as mapZodTypeToPocketBase, p as pluralize, r as resolveTargetCollection, s as singularize, t as toCollectionName, u as unwrapZodType } from '../type-mapper-DaBe-1ph.cjs';
7
- export { F as FIELD_METADATA_KEY, a as FieldMetadata, P as PocketBaseFieldType, e as extractFieldMetadata } from '../fields-RVj26U-O.cjs';
5
+ export { d as CollectionModification, f as CollectionOperation, C as CollectionSchema, b as FieldChange, F as FieldDefinition, c as FieldModification, P as PermissionChange, R as RuleUpdate, S as SchemaDefinition, e as SchemaDiff, a as SchemaSnapshot } from '../types-CVxPCgWX.cjs';
6
+ export { E as ExtractedFieldOptions, d as FIELD_TYPE_INFO, F as FieldTypeInfo, C as FieldTypeResult, P as POCKETBASE_FIELD_TYPES, z as extractComprehensiveFieldOptions, o as extractFieldOptions, x as getArrayElementType, v as getDefaultValue, D as getFieldTypeInfo, g as getMaxSelect, c as getMinSelect, w as isArrayType, A as isEditorField, q as isFieldRequired, B as isFileFieldByName, y as isGeoPointType, a as isMultipleRelationField, b as isRelationField, i as isSingleRelationField, j as mapZodArrayType, f as mapZodBooleanType, k as mapZodDateType, h as mapZodEnumType, e as mapZodNumberType, l as mapZodRecordType, m as mapZodStringType, n as mapZodTypeToPocketBase, p as pluralize, r as resolveTargetCollection, s as singularize, t as toCollectionName, u as unwrapZodType } from '../type-mapper-DsGgZwUo.cjs';
7
+ export { F as FIELD_METADATA_KEY, a as FieldMetadata, P as PocketBaseFieldType, e as extractFieldMetadata } from '../fields-DBBm06VU.cjs';
8
8
  export { A as APIRuleType } from '../permissions-ZHafVSIx.cjs';
9
9
  import 'zod';
10
10
 
@@ -2,9 +2,9 @@ export { SchemaAnalyzer, SchemaAnalyzerConfig, buildFieldDefinition, buildSchema
2
2
  export { SnapshotConfig, SnapshotManager, convertPocketBaseMigration, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot } from './snapshot.js';
3
3
  export { ChangeSummary, DestructiveChange, DiffEngine, DiffEngineConfig, aggregateChanges, categorizeChangesBySeverity, compare, compareFieldConstraints, compareFieldOptions, compareFieldTypes, comparePermissions, compareRelationConfigurations, detectDestructiveChanges, detectFieldChanges, filterSystemCollections, findNewCollections, findNewFields, findRemovedCollections, findRemovedFields, generateChangeSummary, getUsersSystemFields, isSystemCollection, matchCollectionsByName, matchFieldsByName, requiresForceFlag } from './diff.js';
4
4
  export { MigrationGenerator, MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generatePermissionUpdate, generateTimestamp, generateUpMigration, writeMigrationFile } from './generator.js';
5
- export { d as CollectionModification, f as CollectionOperation, C as CollectionSchema, b as FieldChange, F as FieldDefinition, c as FieldModification, P as PermissionChange, R as RuleUpdate, S as SchemaDefinition, e as SchemaDiff, a as SchemaSnapshot } from '../types-CUVzgZ9k.js';
6
- export { E as ExtractedFieldOptions, d as FIELD_TYPE_INFO, F as FieldTypeInfo, C as FieldTypeResult, P as POCKETBASE_FIELD_TYPES, z as extractComprehensiveFieldOptions, o as extractFieldOptions, x as getArrayElementType, v as getDefaultValue, D as getFieldTypeInfo, g as getMaxSelect, c as getMinSelect, w as isArrayType, A as isEditorField, q as isFieldRequired, B as isFileFieldByName, y as isGeoPointType, a as isMultipleRelationField, b as isRelationField, i as isSingleRelationField, j as mapZodArrayType, f as mapZodBooleanType, k as mapZodDateType, h as mapZodEnumType, e as mapZodNumberType, l as mapZodRecordType, m as mapZodStringType, n as mapZodTypeToPocketBase, p as pluralize, r as resolveTargetCollection, s as singularize, t as toCollectionName, u as unwrapZodType } from '../type-mapper-CZzVeDj7.js';
7
- export { F as FIELD_METADATA_KEY, a as FieldMetadata, P as PocketBaseFieldType, e as extractFieldMetadata } from '../fields-RVj26U-O.js';
5
+ export { d as CollectionModification, f as CollectionOperation, C as CollectionSchema, b as FieldChange, F as FieldDefinition, c as FieldModification, P as PermissionChange, R as RuleUpdate, S as SchemaDefinition, e as SchemaDiff, a as SchemaSnapshot } from '../types-Dfp-NP2D.js';
6
+ export { E as ExtractedFieldOptions, d as FIELD_TYPE_INFO, F as FieldTypeInfo, C as FieldTypeResult, P as POCKETBASE_FIELD_TYPES, z as extractComprehensiveFieldOptions, o as extractFieldOptions, x as getArrayElementType, v as getDefaultValue, D as getFieldTypeInfo, g as getMaxSelect, c as getMinSelect, w as isArrayType, A as isEditorField, q as isFieldRequired, B as isFileFieldByName, y as isGeoPointType, a as isMultipleRelationField, b as isRelationField, i as isSingleRelationField, j as mapZodArrayType, f as mapZodBooleanType, k as mapZodDateType, h as mapZodEnumType, e as mapZodNumberType, l as mapZodRecordType, m as mapZodStringType, n as mapZodTypeToPocketBase, p as pluralize, r as resolveTargetCollection, s as singularize, t as toCollectionName, u as unwrapZodType } from '../type-mapper-Dvh4QTM-.js';
7
+ export { F as FIELD_METADATA_KEY, a as FieldMetadata, P as PocketBaseFieldType, e as extractFieldMetadata } from '../fields-DBBm06VU.js';
8
8
  export { A as APIRuleType } from '../permissions-ZHafVSIx.js';
9
9
  import 'zod';
10
10
 
@@ -3471,7 +3471,7 @@ function formatValue(value) {
3471
3471
  return JSON.stringify(value).replace(/","/g, '", "');
3472
3472
  }
3473
3473
  if (typeof value === "object") {
3474
- const entries = Object.entries(value).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
3474
+ const entries = Object.entries(value).filter(([_k, v]) => v !== void 0).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
3475
3475
  return `{ ${entries} }`;
3476
3476
  }
3477
3477
  return String(value);
@@ -3765,11 +3765,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
3765
3765
  function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
3766
3766
  const lines = [];
3767
3767
  const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
3768
- const fieldVar = `${collectionVar}_field`;
3769
3768
  lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
3770
- lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
3771
3769
  lines.push(``);
3772
- lines.push(` ${collectionVar}.fields.remove(${fieldVar}.id);`);
3770
+ lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
3773
3771
  lines.push(``);
3774
3772
  lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
3775
3773
  return lines.join("\n");
@@ -3887,20 +3885,23 @@ function generateOperationUpMigration(operation, collectionIdMap) {
3887
3885
  lines.push(generateCollectionDeletion(collectionName, varName, true));
3888
3886
  }
3889
3887
  let code = lines.join("\n");
3890
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
3891
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
3892
- const saveMatches = [...code.matchAll(savePattern)];
3893
- const deleteMatches = [...code.matchAll(deletePattern)];
3894
- const allMatches = [
3895
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
3896
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
3897
- ].sort((a, b) => b.index - a.index);
3898
- if (allMatches.length > 0) {
3899
- const lastMatch = allMatches[0];
3900
- if (lastMatch.type === "save") {
3901
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
3902
- } else {
3903
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
3888
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
3889
+ if (!hasReturnStatement) {
3890
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
3891
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
3892
+ const saveMatches = [...code.matchAll(savePattern)];
3893
+ const deleteMatches = [...code.matchAll(deletePattern)];
3894
+ const allMatches = [
3895
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
3896
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
3897
+ ].sort((a, b) => b.index - a.index);
3898
+ if (allMatches.length > 0) {
3899
+ const lastMatch = allMatches[0];
3900
+ if (lastMatch.type === "save") {
3901
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
3902
+ } else {
3903
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
3904
+ }
3904
3905
  }
3905
3906
  }
3906
3907
  return code;
@@ -3989,20 +3990,23 @@ function generateOperationDownMigration(operation, collectionIdMap) {
3989
3990
  }
3990
3991
  }
3991
3992
  let code = lines.join("\n");
3992
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
3993
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
3994
- const saveMatches = [...code.matchAll(savePattern)];
3995
- const deleteMatches = [...code.matchAll(deletePattern)];
3996
- const allMatches = [
3997
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
3998
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
3999
- ].sort((a, b) => b.index - a.index);
4000
- if (allMatches.length > 0) {
4001
- const lastMatch = allMatches[0];
4002
- if (lastMatch.type === "save") {
4003
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4004
- } else {
4005
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
3993
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
3994
+ if (!hasReturnStatement) {
3995
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
3996
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
3997
+ const saveMatches = [...code.matchAll(savePattern)];
3998
+ const deleteMatches = [...code.matchAll(deletePattern)];
3999
+ const allMatches = [
4000
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
4001
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
4002
+ ].sort((a, b) => b.index - a.index);
4003
+ if (allMatches.length > 0) {
4004
+ const lastMatch = allMatches[0];
4005
+ if (lastMatch.type === "save") {
4006
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4007
+ } else {
4008
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4009
+ }
4006
4010
  }
4007
4011
  }
4008
4012
  return code;
@@ -4103,20 +4107,23 @@ function generateUpMigration(diff) {
4103
4107
  lines.push(``);
4104
4108
  }
4105
4109
  let code = lines.join("\n");
4106
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
4107
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
4108
- const saveMatches = [...code.matchAll(savePattern)];
4109
- const deleteMatches = [...code.matchAll(deletePattern)];
4110
- const allMatches = [
4111
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
4112
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
4113
- ].sort((a, b) => b.index - a.index);
4114
- if (allMatches.length > 0) {
4115
- const lastMatch = allMatches[0];
4116
- if (lastMatch.type === "save") {
4117
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4118
- } else {
4119
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4110
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
4111
+ if (!hasReturnStatement) {
4112
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
4113
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
4114
+ const saveMatches = [...code.matchAll(savePattern)];
4115
+ const deleteMatches = [...code.matchAll(deletePattern)];
4116
+ const allMatches = [
4117
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
4118
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
4119
+ ].sort((a, b) => b.index - a.index);
4120
+ if (allMatches.length > 0) {
4121
+ const lastMatch = allMatches[0];
4122
+ if (lastMatch.type === "save") {
4123
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4124
+ } else {
4125
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4126
+ }
4120
4127
  }
4121
4128
  }
4122
4129
  return code;
@@ -4233,20 +4240,23 @@ function generateDownMigration(diff) {
4233
4240
  lines.push(``);
4234
4241
  }
4235
4242
  let code = lines.join("\n");
4236
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
4237
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
4238
- const saveMatches = [...code.matchAll(savePattern)];
4239
- const deleteMatches = [...code.matchAll(deletePattern)];
4240
- const allMatches = [
4241
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
4242
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
4243
- ].sort((a, b) => b.index - a.index);
4244
- if (allMatches.length > 0) {
4245
- const lastMatch = allMatches[0];
4246
- if (lastMatch.type === "save") {
4247
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4248
- } else {
4249
- code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4243
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
4244
+ if (!hasReturnStatement) {
4245
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
4246
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
4247
+ const saveMatches = [...code.matchAll(savePattern)];
4248
+ const deleteMatches = [...code.matchAll(deletePattern)];
4249
+ const allMatches = [
4250
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
4251
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
4252
+ ].sort((a, b) => b.index - a.index);
4253
+ if (allMatches.length > 0) {
4254
+ const lastMatch = allMatches[0];
4255
+ if (lastMatch.type === "save") {
4256
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4257
+ } else {
4258
+ code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
4259
+ }
4250
4260
  }
4251
4261
  }
4252
4262
  return code;