@sprucelabs/chroma-data-store 0.0.4 → 0.1.0

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.
@@ -1,14 +1,17 @@
1
1
  import { CreateOptions, Database, DatabaseInternalOptions, Index, IndexWithFilter, QueryOptions } from '@sprucelabs/data-stores';
2
2
  export default class ChromaDatabase implements Database {
3
+ static Class?: new (connectionString: string) => Database;
4
+ private static embeddingFields?;
3
5
  private connectionString;
4
6
  private client;
5
7
  private _isConnected;
6
8
  private embeddings;
7
9
  private collections;
8
- private static embeddingFields?;
9
10
  constructor(connectionString: string);
11
+ static Database(connectionString: string): ChromaDatabase | Database;
10
12
  static setEmbeddingsFields(collectionName: string, fields: string[]): void;
11
13
  static clearEmbeddingsFields(): void;
14
+ static getEmbeddingsFields(): Record<string, string[]> | undefined;
12
15
  syncUniqueIndexes(_collectionName: string, _indexes: Index[]): Promise<void>;
13
16
  syncIndexes(_collectionName: string, _indexes: Index[]): Promise<void>;
14
17
  dropIndex(_collectionName: string, _index: Index): Promise<void>;
@@ -24,6 +24,9 @@ class ChromaDatabase {
24
24
  }
25
25
  this.connectionString = connectionString.replace('chroma://', 'http://');
26
26
  }
27
+ static Database(connectionString) {
28
+ return new (this.Class ?? this)(connectionString);
29
+ }
27
30
  static setEmbeddingsFields(collectionName, fields) {
28
31
  if (!this.embeddingFields) {
29
32
  this.embeddingFields = {};
@@ -33,6 +36,9 @@ class ChromaDatabase {
33
36
  static clearEmbeddingsFields() {
34
37
  delete this.embeddingFields;
35
38
  }
39
+ static getEmbeddingsFields() {
40
+ return this.embeddingFields;
41
+ }
36
42
  async syncUniqueIndexes(_collectionName, _indexes) {
37
43
  throw new SpruceError_1.default({
38
44
  code: 'FEATURE_NOT_SUPPORTED',
@@ -0,0 +1,6 @@
1
+ import { NeDbDatabase } from '@sprucelabs/data-stores';
2
+ export default class MockChromaDatabase extends NeDbDatabase {
3
+ private connectionString;
4
+ constructor(connectionString: string);
5
+ assertConnectionStringEquals(connectionString: string): void;
6
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const data_stores_1 = require("@sprucelabs/data-stores");
4
+ const test_utils_1 = require("@sprucelabs/test-utils");
5
+ class MockChromaDatabase extends data_stores_1.NeDbDatabase {
6
+ constructor(connectionString) {
7
+ super();
8
+ this.connectionString = connectionString;
9
+ }
10
+ assertConnectionStringEquals(connectionString) {
11
+ test_utils_1.assert.isEqual(this.connectionString, connectionString, 'The connection string you passed to your ChromaDb does not equal what I expected!');
12
+ }
13
+ }
14
+ exports.default = MockChromaDatabase;
@@ -0,0 +1,4 @@
1
+ declare const chromaDbAssert: {
2
+ embeddingFieldsForCollectionEqual(collection: string, fields: string[]): void;
3
+ };
4
+ export default chromaDbAssert;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const schema_1 = require("@sprucelabs/schema");
7
+ const test_utils_1 = require("@sprucelabs/test-utils");
8
+ const ChromaDatabase_1 = __importDefault(require("./ChromaDatabase"));
9
+ const chromaDbAssert = {
10
+ embeddingFieldsForCollectionEqual(collection, fields) {
11
+ (0, schema_1.assertOptions)({
12
+ collection,
13
+ fields,
14
+ }, ['collection', 'fields']);
15
+ const actual = ChromaDatabase_1.default.getEmbeddingsFields()?.[collection];
16
+ test_utils_1.assert.isTruthy(actual, `I could not find any embedding fields for the collection called ${collection}`);
17
+ test_utils_1.assert.isEqualDeep(actual, fields, `The embedding fields for the collection did not match.`);
18
+ },
19
+ };
20
+ exports.default = chromaDbAssert;
@@ -1,14 +1,17 @@
1
1
  import { CreateOptions, Database, DatabaseInternalOptions, Index, IndexWithFilter, QueryOptions } from '@sprucelabs/data-stores';
2
2
  export default class ChromaDatabase implements Database {
3
+ static Class?: new (connectionString: string) => Database;
4
+ private static embeddingFields?;
3
5
  private connectionString;
4
6
  private client;
5
7
  private _isConnected;
6
8
  private embeddings;
7
9
  private collections;
8
- private static embeddingFields?;
9
10
  constructor(connectionString: string);
11
+ static Database(connectionString: string): ChromaDatabase | Database;
10
12
  static setEmbeddingsFields(collectionName: string, fields: string[]): void;
11
13
  static clearEmbeddingsFields(): void;
14
+ static getEmbeddingsFields(): Record<string, string[]> | undefined;
12
15
  syncUniqueIndexes(_collectionName: string, _indexes: Index[]): Promise<void>;
13
16
  syncIndexes(_collectionName: string, _indexes: Index[]): Promise<void>;
14
17
  dropIndex(_collectionName: string, _index: Index): Promise<void>;
@@ -39,6 +39,10 @@ export default class ChromaDatabase {
39
39
  }
40
40
  this.connectionString = connectionString.replace('chroma://', 'http://');
41
41
  }
42
+ static Database(connectionString) {
43
+ var _a;
44
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(connectionString);
45
+ }
42
46
  static setEmbeddingsFields(collectionName, fields) {
43
47
  if (!this.embeddingFields) {
44
48
  this.embeddingFields = {};
@@ -48,6 +52,9 @@ export default class ChromaDatabase {
48
52
  static clearEmbeddingsFields() {
49
53
  delete this.embeddingFields;
50
54
  }
55
+ static getEmbeddingsFields() {
56
+ return this.embeddingFields;
57
+ }
51
58
  syncUniqueIndexes(_collectionName, _indexes) {
52
59
  return __awaiter(this, void 0, void 0, function* () {
53
60
  throw new SpruceError({
@@ -0,0 +1,6 @@
1
+ import { NeDbDatabase } from '@sprucelabs/data-stores';
2
+ export default class MockChromaDatabase extends NeDbDatabase {
3
+ private connectionString;
4
+ constructor(connectionString: string);
5
+ assertConnectionStringEquals(connectionString: string): void;
6
+ }
@@ -0,0 +1,11 @@
1
+ import { NeDbDatabase } from '@sprucelabs/data-stores';
2
+ import { assert } from '@sprucelabs/test-utils';
3
+ export default class MockChromaDatabase extends NeDbDatabase {
4
+ constructor(connectionString) {
5
+ super();
6
+ this.connectionString = connectionString;
7
+ }
8
+ assertConnectionStringEquals(connectionString) {
9
+ assert.isEqual(this.connectionString, connectionString, 'The connection string you passed to your ChromaDb does not equal what I expected!');
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ declare const chromaDbAssert: {
2
+ embeddingFieldsForCollectionEqual(collection: string, fields: string[]): void;
3
+ };
4
+ export default chromaDbAssert;
@@ -0,0 +1,16 @@
1
+ import { assertOptions } from '@sprucelabs/schema';
2
+ import { assert } from '@sprucelabs/test-utils';
3
+ import ChromaDatabase from './ChromaDatabase.js';
4
+ const chromaDbAssert = {
5
+ embeddingFieldsForCollectionEqual(collection, fields) {
6
+ var _a;
7
+ assertOptions({
8
+ collection,
9
+ fields,
10
+ }, ['collection', 'fields']);
11
+ const actual = (_a = ChromaDatabase.getEmbeddingsFields()) === null || _a === void 0 ? void 0 : _a[collection];
12
+ assert.isTruthy(actual, `I could not find any embedding fields for the collection called ${collection}`);
13
+ assert.isEqualDeep(actual, fields, `The embedding fields for the collection did not match.`);
14
+ },
15
+ };
16
+ export default chromaDbAssert;
@@ -1,2 +1,4 @@
1
1
  export { default as ChromaDatabase } from './ChromaDatabase';
2
+ export { default as chromaDbAssert } from './chromaDbAssert.utility';
3
+ export { default as MockChromaDatabase } from './MockChromaDatabase';
2
4
  export * from './ChromaDatabase';
@@ -1,5 +1,7 @@
1
1
  export { default as ChromaDatabase } from './ChromaDatabase.js';
2
2
  import { DatabaseFactory } from '@sprucelabs/data-stores';
3
3
  import ChromaDatabase from './ChromaDatabase.js';
4
+ export { default as chromaDbAssert } from './chromaDbAssert.utility.js';
5
+ export { default as MockChromaDatabase } from './MockChromaDatabase.js';
4
6
  export * from './ChromaDatabase.js';
5
7
  DatabaseFactory.addAdapter('chroma://', ChromaDatabase);
package/build/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { default as ChromaDatabase } from './ChromaDatabase';
2
+ export { default as chromaDbAssert } from './chromaDbAssert.utility';
3
+ export { default as MockChromaDatabase } from './MockChromaDatabase';
2
4
  export * from './ChromaDatabase';
package/build/index.js CHANGED
@@ -17,10 +17,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ChromaDatabase = void 0;
20
+ exports.MockChromaDatabase = exports.chromaDbAssert = exports.ChromaDatabase = void 0;
21
21
  var ChromaDatabase_1 = require("./ChromaDatabase");
22
22
  Object.defineProperty(exports, "ChromaDatabase", { enumerable: true, get: function () { return __importDefault(ChromaDatabase_1).default; } });
23
23
  const data_stores_1 = require("@sprucelabs/data-stores");
24
24
  const ChromaDatabase_2 = __importDefault(require("./ChromaDatabase"));
25
+ var chromaDbAssert_utility_1 = require("./chromaDbAssert.utility");
26
+ Object.defineProperty(exports, "chromaDbAssert", { enumerable: true, get: function () { return __importDefault(chromaDbAssert_utility_1).default; } });
27
+ var MockChromaDatabase_1 = require("./MockChromaDatabase");
28
+ Object.defineProperty(exports, "MockChromaDatabase", { enumerable: true, get: function () { return __importDefault(MockChromaDatabase_1).default; } });
25
29
  __exportStar(require("./ChromaDatabase"), exports);
26
30
  data_stores_1.DatabaseFactory.addAdapter('chroma://', ChromaDatabase_2.default);
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "sprucebot",
14
14
  "sprucelabs"
15
15
  ],
16
- "version": "0.0.4",
16
+ "version": "0.1.0",
17
17
  "scripts": {
18
18
  "build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
19
19
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "dependencies": {
85
- "@sprucelabs/data-stores": "^28.4.0",
85
+ "@sprucelabs/data-stores": "^28.5.1",
86
86
  "@sprucelabs/error": "^6.0.556",
87
87
  "@sprucelabs/schema": "^31.0.3",
88
88
  "@sprucelabs/spruce-core-schemas": "^40.1.586",