Skip to content

Commit 07ef17f

Browse files
authored
Rename alias exists > name exists (#1100)
1 parent 3993a17 commit 07ef17f

File tree

11 files changed

+137
-64
lines changed

11 files changed

+137
-64
lines changed

.changeset/neat-tips-stick.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@e2b/python-sdk': patch
3+
'e2b': patch
4+
---
5+
6+
deprecate aliasexists and add exists

packages/js-sdk/src/template/index.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { parseDockerfile } from './dockerfileParser'
2020
import { LogEntry, LogEntryEnd, LogEntryStart } from './logger'
2121
import { ReadyCmd, waitForFile } from './readycmd'
2222
import {
23-
AliasExistsOptions,
2423
BuildInfo,
2524
BuildOptions,
2625
CopyItem,
@@ -268,13 +267,36 @@ export class TemplateBase
268267
})
269268
}
270269

270+
/**
271+
* Check if a template with the given name exists.
272+
*
273+
* @param name Template name to check
274+
* @param options Authentication options
275+
* @returns True if the name exists, false otherwise
276+
*
277+
* @example
278+
* ```ts
279+
* const exists = await Template.exists('my-python-env')
280+
* if (exists) {
281+
* console.log('Template exists!')
282+
* }
283+
* ```
284+
*/
285+
static async exists(
286+
name: string,
287+
options?: ConnectionOpts
288+
): Promise<boolean> {
289+
return TemplateBase.aliasExists(name, options)
290+
}
291+
271292
/**
272293
* Check if a template with the given alias exists.
273294
*
274295
* @param alias Template alias to check
275296
* @param options Authentication options
276297
* @returns True if the alias exists, false otherwise
277298
*
299+
* @deprecated Use `exists` instead.
278300
* @example
279301
* ```ts
280302
* const exists = await Template.aliasExists('my-python-env')
@@ -285,7 +307,7 @@ export class TemplateBase
285307
*/
286308
static async aliasExists(
287309
alias: string,
288-
options?: AliasExistsOptions
310+
options?: ConnectionOpts
289311
): Promise<boolean> {
290312
const config = new ConnectionConfig(options)
291313
const client = new ApiClient(config)
@@ -1223,14 +1245,14 @@ export function Template(options?: TemplateOptions): TemplateFromImage {
12231245
Template.build = TemplateBase.build
12241246
Template.buildInBackground = TemplateBase.buildInBackground
12251247
Template.getBuildStatus = TemplateBase.getBuildStatus
1248+
Template.exists = TemplateBase.exists
12261249
Template.aliasExists = TemplateBase.aliasExists
12271250
Template.assignTags = TemplateBase.assignTags
12281251
Template.removeTags = TemplateBase.removeTags
12291252
Template.toJSON = TemplateBase.toJSON
12301253
Template.toDockerfile = TemplateBase.toDockerfile
12311254

12321255
export type {
1233-
AliasExistsOptions,
12341256
BuildInfo,
12351257
BuildOptions,
12361258
BuildStatusReason,

packages/js-sdk/src/template/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ export type TemplateTagInfo = {
158158
tags: string[]
159159
}
160160

161-
/**
162-
* Options for checking if a template alias exists.
163-
*/
164-
export type AliasExistsOptions = ConnectionOpts
165-
166161
/**
167162
* Types of instructions that can be used in a template.
168163
*/

packages/js-sdk/tests/template/aliasExists.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { randomUUID } from 'node:crypto'
2+
import { expect, test } from 'vitest'
3+
import { Template } from '../../src'
4+
5+
test('check if base template name exists', async () => {
6+
const exists = await Template.exists('base')
7+
expect(exists).toBe(true)
8+
})
9+
10+
test('check non existing name', async () => {
11+
const nonExistingName = `nonexistent-${randomUUID()}`
12+
const exists = await Template.exists(nonExistingName)
13+
expect(exists).toBe(false)
14+
})

packages/python-sdk/e2b/template_async/main.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,29 @@ async def get_build_status(
376376
logs_offset,
377377
)
378378

379+
@staticmethod
380+
async def exists(
381+
name: str,
382+
**opts: Unpack[ApiParams],
383+
) -> bool:
384+
"""
385+
Check if a template with the given name exists.
386+
387+
:param name: Template name to check
388+
:return: True if the name exists, False otherwise
389+
390+
Example
391+
```python
392+
from e2b import AsyncTemplate
393+
394+
exists = await AsyncTemplate.exists('my-python-env')
395+
if exists:
396+
print('Template exists!')
397+
```
398+
"""
399+
400+
return await AsyncTemplate.alias_exists(name, **opts)
401+
379402
@staticmethod
380403
async def alias_exists(
381404
alias: str,
@@ -384,14 +407,16 @@ async def alias_exists(
384407
"""
385408
Check if a template with the given alias exists.
386409
410+
Deprecated Use `exists` instead.
411+
387412
:param alias: Template alias to check
388413
:return: True if the alias exists, False otherwise
389414
390415
Example
391416
```python
392417
from e2b import AsyncTemplate
393418
394-
exists = await AsyncTemplate.alias_exists('base')
419+
exists = await AsyncTemplate.alias_exists('my-python-env')
395420
if exists:
396421
print('Template exists!')
397422
```

packages/python-sdk/e2b/template_sync/main.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,29 @@ def get_build_status(
377377
logs_offset,
378378
)
379379

380+
@staticmethod
381+
def exists(
382+
name: str,
383+
**opts: Unpack[ApiParams],
384+
) -> bool:
385+
"""
386+
Check if a template with the given name exists.
387+
388+
:param name: Template name to check
389+
:return: True if the name exists, False otherwise
390+
391+
Example
392+
```python
393+
from e2b import Template
394+
395+
exists = Template.exists('my-python-env')
396+
if exists:
397+
print('Template exists!')
398+
```
399+
"""
400+
401+
return Template.alias_exists(name, **opts)
402+
380403
@staticmethod
381404
def alias_exists(
382405
alias: str,
@@ -385,14 +408,16 @@ def alias_exists(
385408
"""
386409
Check if a template with the given alias exists.
387410
411+
Deprecated Use `exists` instead.
412+
388413
:param alias: Template alias to check
389414
:return: True if the alias exists, False otherwise
390415
391416
Example
392417
```python
393418
from e2b import Template
394419
395-
exists = Template.alias_exists('base')
420+
exists = Template.alias_exists('my-python-env')
396421
if exists:
397422
print('Template exists!')
398423
```

packages/python-sdk/tests/async/template_async/test_alias_exists.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import uuid
2+
3+
import pytest
4+
5+
from e2b import AsyncTemplate
6+
7+
8+
@pytest.mark.skip_debug()
9+
async def test_check_base_template_name_exists():
10+
"""Test that the base template name exists."""
11+
exists = await AsyncTemplate.exists("base")
12+
assert exists is True
13+
14+
15+
@pytest.mark.skip_debug()
16+
async def test_check_non_existing_name():
17+
"""Test that a non-existing name returns False."""
18+
non_existing_name = f"nonexistent-{uuid.uuid4()}"
19+
exists = await AsyncTemplate.exists(non_existing_name)
20+
assert exists is False

packages/python-sdk/tests/sync/template_sync/test_alias_exists.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)