MCPcopy Index your code
hub / github.com/massCodeIO/massCode / createUniqueEnvironment

Function createUniqueEnvironment

src/main/http/import/persist.ts:99–122  ·  view source on GitHub ↗
(
  storage: HttpStorageProvider,
  environment: HttpImportEnvironment,
)

Source from the content-addressed store, hash-verified

97}
98
99function createUniqueEnvironment(
100 storage: HttpStorageProvider,
101 environment: HttpImportEnvironment,
102): number {
103 const baseName = normalizeImportName(environment.name, 'Imported')
104
105 for (let suffix = 0; suffix <= 10_000; suffix += 1) {
106 const candidate = withSuffix(baseName, suffix)
107 try {
108 const { id } = storage.environments.createEnvironment({
109 name: candidate,
110 variables: environment.variables,
111 })
112 return id
113 }
114 catch (error) {
115 if (parseStorageError(error)?.code !== 'NAME_CONFLICT') {
116 throw error
117 }
118 }
119 }
120
121 throw new Error('NAME_CONFLICT:Cannot generate unique environment name')
122}
123
124function selectByIndexes<T>(items: T[], indexes: number[] | undefined): T[] {
125 if (!indexes) {

Callers 1

persistHttpImportResultFunction · 0.85

Calls 3

normalizeImportNameFunction · 0.90
withSuffixFunction · 0.85
parseStorageErrorFunction · 0.70

Tested by

no test coverage detected