Skip to content

Commit e5d752c

Browse files
authored
Merge branch 'main' into feature/o-2941
2 parents d257a2c + 991584f commit e5d752c

File tree

11 files changed

+675
-234
lines changed

11 files changed

+675
-234
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ On browsers:
2525
## License
2626

2727
[AGPLv3](/LICENSE.md)
28+
29+
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=83013fff-5997-4abd-9a5c-8163b59fa6e2" />

deno.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@orama/core",
3-
"version": "1.2.1",
3+
"version": "1.2.16",
44
"exports": "./src/index.ts",
55
"nodeModulesDir": "auto",
66
"tasks": {
77
"build": "deno run -A ./dnt.ts",
88
"test": "deno test tests --allow-env --allow-read --allow-net"
99
},
1010
"fmt": {
11-
"lineWidth": 120,
11+
"lineWidth": 140,
1212
"semiColons": false,
1313
"singleQuote": true,
1414
"include": [
@@ -21,5 +21,17 @@
2121
"deno.window",
2222
"dom"
2323
]
24+
},
25+
"lint": {
26+
"include": [
27+
"src/"
28+
],
29+
"rules": {
30+
"exclude": [
31+
"no-import-prefix",
32+
"no-explicit-any",
33+
"no-process-global"
34+
]
35+
}
2436
}
2537
}

dnt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ await build({
3232
bugs: {
3333
url: 'https://github.com/oramasearch/oramacore/repo/issues',
3434
},
35+
devDependencies: {
36+
"@scarf/scarf": "1.4.0"
37+
}
3538
},
3639
testPattern: '**/*.test.{ts,js}',
3740
rootTestDir: './tests',

src/cloud.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,24 @@ export class OramaCloud {
4949
return this.client.search({ ...rest, indexes: datasources })
5050
}
5151

52-
dataSource(id: string) {
52+
dataSource(id: string): DataSourceNamespace {
5353
const index = this.client.index.set(id)
54-
return new DataSourceNamespace(index)
54+
return new DataSourceNamespace(
55+
index,
56+
this.client,
57+
undefined,
58+
)
5559
}
5660
}
5761

5862
class DataSourceNamespace {
5963
private index: Index
6064

61-
constructor(index: Index) {
65+
constructor(
66+
index: Index,
67+
private client: CollectionManager,
68+
private originalRuntimeIndexId?: string,
69+
) {
6270
this.index = index
6371
}
6472

@@ -77,4 +85,37 @@ class DataSourceNamespace {
7785
upsertDocuments(documents: AnyObject[]): Promise<void> {
7886
return this.index.upsertDocuments(documents)
7987
}
88+
89+
async createTemporaryIndex(): Promise<DataSourceNamespace> {
90+
if (this.originalRuntimeIndexId) {
91+
throw new Error('Cannot create a temporary index from a temporary index')
92+
}
93+
94+
const runtimeIndexID = this.index.getIndexID()
95+
96+
const temp_index_id = await this.index.createTemporaryIndex()
97+
98+
const index = this.client.index.set(temp_index_id)
99+
return new DataSourceNamespace(
100+
index,
101+
this.client,
102+
runtimeIndexID,
103+
)
104+
}
105+
106+
async swap(): Promise<void> {
107+
if (!this.originalRuntimeIndexId) {
108+
throw new Error('Cannot swap a non-temporary index')
109+
}
110+
const tempIndexId = this.index.getIndexID()
111+
112+
if (tempIndexId === this.originalRuntimeIndexId) {
113+
throw new Error('Cannot swap the same index')
114+
}
115+
116+
await this.index.swapTemporaryIndex(
117+
this.originalRuntimeIndexId,
118+
tempIndexId,
119+
)
120+
}
80121
}

0 commit comments

Comments
 (0)