@dbx-tools/dbx-model-catalog 0.1.4 → 0.1.6

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 (42) hide show
  1. package/README.md +62 -10
  2. package/dist/_generated/json-schema.d.ts +3830 -0
  3. package/dist/_generated/published.d.ts +7 -0
  4. package/dist/_generated/schemas.d.ts +27 -2
  5. package/dist/browser.d.ts +12 -3
  6. package/dist/browser.js +9487 -1141
  7. package/dist/browser.js.map +32 -9
  8. package/dist/catalog-index.d.ts +28 -0
  9. package/dist/catalog.json +1 -0
  10. package/dist/cli.js +8811 -49414
  11. package/dist/cli.js.map +16 -222
  12. package/dist/filter.d.ts +2 -0
  13. package/dist/identity.d.ts +15 -0
  14. package/dist/index.d.ts +8 -4
  15. package/dist/index.js +8843 -49435
  16. package/dist/index.js.map +15 -221
  17. package/dist/local-client.d.ts +4 -0
  18. package/dist/{client.d.ts → pynect.d.ts} +1 -1
  19. package/dist/pynect.js +553 -0
  20. package/dist/pynect.js.map +15 -0
  21. package/dist/search-index.json +1 -0
  22. package/dist/search.d.ts +10 -0
  23. package/dist/snapshot.d.ts +6 -0
  24. package/dist/snapshot.js +9494 -0
  25. package/dist/snapshot.js.map +36 -0
  26. package/dist/types.d.ts +5 -0
  27. package/dist/validation.d.ts +5 -0
  28. package/package.json +27 -2
  29. package/dist/python/pyproject.toml +0 -16
  30. package/dist/python/src/dbx_model_catalog/__init__.py +0 -79
  31. package/dist/python/src/dbx_model_catalog/client.py +0 -251
  32. package/dist/python/src/dbx_model_catalog/database.py +0 -296
  33. package/dist/python/src/dbx_model_catalog/filters.py +0 -41
  34. package/dist/python/src/dbx_model_catalog/models.py +0 -847
  35. package/dist/python/src/dbx_model_catalog/publishing.py +0 -27
  36. package/dist/python/src/dbx_model_catalog/py.typed +0 -0
  37. package/dist/python/src/dbx_model_catalog/query.py +0 -593
  38. package/dist/python/src/dbx_model_catalog/schema/__init__.py +0 -0
  39. package/dist/python/src/dbx_model_catalog/schema/model-catalog.schema.json +0 -1016
  40. package/dist/python/src/dbx_model_catalog/search.py +0 -912
  41. package/dist/python/src/dbx_model_catalog_server/__init__.py +0 -3
  42. package/dist/python/src/dbx_model_catalog_server/app.py +0 -142
package/dist/types.d.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  import type { CatalogFilters, CatalogModelRecord, CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
2
+ import type { CatalogIdentityMatch } from "./catalog-index.js";
3
+ import type { CatalogSearchMatch } from "./search.js";
2
4
  export interface CatalogClient {
3
5
  catalog(): Promise<ModelCatalog>;
4
6
  searchIndex(): Promise<CatalogSearchIndexPayload>;
5
7
  list(filters?: CatalogFilters): Promise<CatalogModelRecord[]>;
8
+ get(identity: string): Promise<CatalogModelRecord | undefined>;
9
+ resolve(identity: string): Promise<CatalogIdentityMatch | undefined>;
10
+ search(query: string, limit?: number | null): Promise<CatalogSearchMatch[]>;
6
11
  stream(filters?: CatalogFilters): AsyncGenerator<CatalogModelRecord>;
7
12
  close(): void;
8
13
  }
@@ -0,0 +1,5 @@
1
+ import type { CatalogSearchIndexPayload, ModelCatalog } from "./_generated/schemas.js";
2
+ /** Validate an untrusted catalog payload against the Python-owned contract. */
3
+ export declare function parseModelCatalog(value: unknown): ModelCatalog;
4
+ /** Validate an untrusted search-index payload against the Python-owned contract. */
5
+ export declare function parseCatalogSearchIndex(value: unknown): CatalogSearchIndexPayload;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dbx-tools/dbx-model-catalog",
3
- "version": "0.1.4",
4
- "description": "Thin Node client for the Python-owned dbx-model-catalog service",
3
+ "version": "0.1.6",
4
+ "description": "Node and browser client for the published Databricks model catalog",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.4.4",
7
7
  "repository": {
@@ -33,6 +33,16 @@
33
33
  "import": "./dist/browser.js",
34
34
  "default": "./dist/browser.js"
35
35
  },
36
+ "./pynect": {
37
+ "types": "./dist/pynect.d.ts",
38
+ "import": "./dist/pynect.js",
39
+ "default": "./dist/pynect.js"
40
+ },
41
+ "./snapshot": {
42
+ "types": "./dist/snapshot.d.ts",
43
+ "import": "./dist/snapshot.js",
44
+ "default": "./dist/snapshot.js"
45
+ },
36
46
  "./package.json": "./package.json"
37
47
  },
38
48
  "files": ["dist"],
@@ -48,6 +58,21 @@
48
58
  "pynect": "^1.0.0",
49
59
  "typescript": "^5.9.3"
50
60
  },
61
+ "dependencies": {
62
+ "zod": "^4.6.7"
63
+ },
64
+ "peerDependencies": {
65
+ "@chanx-js/client": "2.3.2",
66
+ "pynect": "1.0.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@chanx-js/client": {
70
+ "optional": true
71
+ },
72
+ "pynect": {
73
+ "optional": true
74
+ }
75
+ },
51
76
  "publishConfig": {
52
77
  "access": "public"
53
78
  },
@@ -1,16 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling>=1.28,<2"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "dbx-model-catalog-runtime"
7
- version = "0.1.4"
8
- requires-python = ">=3.12"
9
- dependencies = ["brotli>=1.1,<2", "diskcache>=5.6,<6", "platformdirs>=4.3,<5", "pydantic>=2.14,<3", "python-dateutil>=2.9,<3", "rapidfuzz>=3.14,<4", "chanx[fast_channels]>=2.13,<3", "fastapi>=0.120,<1", "pynect>=1.0.0,<2", "uvicorn[standard]>=0.40,<1"]
10
-
11
- [tool.pynect]
12
- app = "dbx_model_catalog_server.app:app"
13
-
14
- [tool.hatch.build.targets.wheel]
15
- packages = ["src/dbx_model_catalog", "src/dbx_model_catalog_server"]
16
-
@@ -1,79 +0,0 @@
1
- from .client import (
2
- CatalogCacheDirectory,
3
- CatalogFetch,
4
- CatalogPayloadDecoder,
5
- CatalogPayloadEncoding,
6
- ModelCatalogClient,
7
- PUBLISHED_CATALOG_BASE_URL,
8
- PUBLISHED_CATALOG_CACHE_TTL,
9
- PUBLISHED_CATALOG_URL,
10
- fetch_published_catalog,
11
- published_catalog_cache_directory,
12
- )
13
- from .database import CATALOG_DATABASE_SCHEMA_VERSION, write_catalog_database
14
- from .filters import CapabilityName, CatalogFilters
15
- from .models import CatalogModel, CatalogModelRecord, ModelCatalog
16
- from .query import (
17
- CatalogOrderBy,
18
- CatalogOrderByField,
19
- CatalogPredicate,
20
- CatalogQuery,
21
- CatalogQueryExpression,
22
- CatalogQueryOptions,
23
- SerializableCatalogQuery,
24
- parse_catalog_query,
25
- serialize_catalog_query,
26
- )
27
- from .search import (
28
- CatalogSearchIndex,
29
- CatalogSearchIndexDocument,
30
- CatalogSearchIndexPayload,
31
- CatalogSearchQualityScores,
32
- CatalogSearchResult,
33
- CatalogSearchScores,
34
- CatalogSearchWeights,
35
- SEARCH_WEIGHTS,
36
- SearchMatchKind,
37
- build_catalog_search_index,
38
- search_catalog_records,
39
- )
40
-
41
- __all__ = [
42
- "CatalogCacheDirectory",
43
- "CATALOG_DATABASE_SCHEMA_VERSION",
44
- "CatalogFetch",
45
- "CatalogFilters",
46
- "CatalogModel",
47
- "CatalogModelRecord",
48
- "CatalogOrderBy",
49
- "CatalogOrderByField",
50
- "CatalogPayloadDecoder",
51
- "CatalogPayloadEncoding",
52
- "CatalogPredicate",
53
- "CatalogQuery",
54
- "CatalogQueryExpression",
55
- "CatalogQueryOptions",
56
- "CatalogSearchResult",
57
- "CatalogSearchIndex",
58
- "CatalogSearchIndexDocument",
59
- "CatalogSearchIndexPayload",
60
- "CatalogSearchQualityScores",
61
- "CatalogSearchScores",
62
- "CatalogSearchWeights",
63
- "CapabilityName",
64
- "ModelCatalog",
65
- "ModelCatalogClient",
66
- "PUBLISHED_CATALOG_BASE_URL",
67
- "PUBLISHED_CATALOG_CACHE_TTL",
68
- "PUBLISHED_CATALOG_URL",
69
- "SEARCH_WEIGHTS",
70
- "SerializableCatalogQuery",
71
- "SearchMatchKind",
72
- "build_catalog_search_index",
73
- "fetch_published_catalog",
74
- "parse_catalog_query",
75
- "published_catalog_cache_directory",
76
- "serialize_catalog_query",
77
- "search_catalog_records",
78
- "write_catalog_database",
79
- ]
@@ -1,251 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from collections.abc import Callable, Mapping
4
- from datetime import datetime
5
- from pathlib import Path
6
- from typing import Literal, TypeAlias
7
- from urllib.request import urlopen
8
-
9
- import brotli
10
- from diskcache import Cache
11
- from platformdirs import user_cache_path
12
-
13
- from .filters import CatalogFilters
14
- from .models import CatalogModelRecord, ModelCatalog
15
- from .query import CatalogQuery, CatalogQueryOptions, query_catalog_records
16
- from .search import (
17
- CatalogSearchIndex,
18
- CatalogSearchIndexPayload,
19
- CatalogSearchResult,
20
- )
21
-
22
- CatalogPayloadEncoding: TypeAlias = Literal["brotli", "json"]
23
- CatalogFetch: TypeAlias = Callable[[str], bytes]
24
- CatalogPayloadDecoder: TypeAlias = Callable[[bytes, CatalogPayloadEncoding], str]
25
- CatalogCacheDirectory: TypeAlias = str | Path
26
-
27
- PUBLISHED_CATALOG_BASE_URL = (
28
- "https://raw.githubusercontent.com/reggie-db/dbx-model-catalog/"
29
- "main/packages/js/web"
30
- )
31
- PUBLISHED_CATALOG_URL = f"{PUBLISHED_CATALOG_BASE_URL}/catalog.json"
32
- PUBLISHED_CATALOG_CACHE_TTL = 3600.0
33
-
34
-
35
- class ModelCatalogClient:
36
- def __init__(self, catalog: ModelCatalog) -> None:
37
- self.catalog = catalog
38
- self._records = [
39
- CatalogModelRecord(id=model_id, **model.model_dump())
40
- for model_id, model in catalog.models.items()
41
- ]
42
- self._search_index = CatalogSearchIndex(
43
- self._records,
44
- reference_date=catalog.updated_at.date(),
45
- )
46
-
47
- @classmethod
48
- def from_catalog(cls, value: ModelCatalog | Mapping[str, object]) -> ModelCatalogClient:
49
- return cls(ModelCatalog.model_validate(value))
50
-
51
- @classmethod
52
- def from_json(cls, value: str | bytes) -> ModelCatalogClient:
53
- return cls(ModelCatalog.model_validate_json(value))
54
-
55
- @classmethod
56
- def from_brotli(
57
- cls,
58
- value: bytes,
59
- *,
60
- decode: CatalogPayloadDecoder | None = None,
61
- ) -> ModelCatalogClient:
62
- decoder = decode or decode_catalog_payload
63
- return cls.from_json(decoder(value, "brotli"))
64
-
65
- @classmethod
66
- def from_url(
67
- cls,
68
- url: str,
69
- *,
70
- fetch: CatalogFetch | None = None,
71
- decode: CatalogPayloadDecoder | None = None,
72
- ) -> ModelCatalogClient:
73
- payload = (fetch or fetch_catalog)(url)
74
- encoding: CatalogPayloadEncoding = (
75
- "json" if _looks_like_json(payload) else "brotli"
76
- )
77
- return cls.from_json((decode or decode_catalog_payload)(payload, encoding))
78
-
79
- @classmethod
80
- def from_published(
81
- cls,
82
- *,
83
- refresh: bool = False,
84
- url: str = PUBLISHED_CATALOG_URL,
85
- cache_directory: CatalogCacheDirectory | None = None,
86
- cache_ttl: float = PUBLISHED_CATALOG_CACHE_TTL,
87
- fetch: CatalogFetch | None = None,
88
- decode: CatalogPayloadDecoder | None = None,
89
- ) -> ModelCatalogClient:
90
- payload = fetch_published_catalog(
91
- url,
92
- refresh=refresh,
93
- cache_directory=cache_directory,
94
- cache_ttl=cache_ttl,
95
- fetch=fetch,
96
- )
97
- encoding: CatalogPayloadEncoding = (
98
- "json" if _looks_like_json(payload) else "brotli"
99
- )
100
- return cls.from_json((decode or decode_catalog_payload)(payload, encoding))
101
-
102
- @property
103
- def schema_version(self) -> int:
104
- return self.catalog.schema_version
105
-
106
- @property
107
- def updated_at(self) -> datetime:
108
- return self.catalog.updated_at
109
-
110
- @property
111
- def size(self) -> int:
112
- return len(self.catalog.models)
113
-
114
- @property
115
- def search_index(self) -> CatalogSearchIndexPayload:
116
- return self._search_index.payload(
117
- catalog_schema_version=self.catalog.schema_version,
118
- updated_at=self.catalog.updated_at,
119
- )
120
-
121
- def get(self, model_id: str) -> CatalogModelRecord | None:
122
- model = self.catalog.models.get(model_id)
123
- if model is None:
124
- return None
125
- return CatalogModelRecord(id=model_id, **model.model_dump())
126
-
127
- def all(self) -> list[CatalogModelRecord]:
128
- return self.list()
129
-
130
- def list(self) -> list[CatalogModelRecord]:
131
- return list(self._records)
132
-
133
- def query(
134
- self,
135
- expression: CatalogQuery | None = None,
136
- options: CatalogQueryOptions | Mapping[str, object] | None = None,
137
- ) -> list[CatalogModelRecord]:
138
- return query_catalog_records(self.all(), expression, options)
139
-
140
- def filter(
141
- self,
142
- filters: CatalogFilters | Mapping[str, object] | None = None,
143
- ) -> list[CatalogModelRecord]:
144
- parsed = CatalogFilters.model_validate(filters or {})
145
- clauses: list[dict[str, object]] = []
146
- if parsed.status:
147
- clauses.append({"status": {"$in": parsed.status}})
148
- if parsed.model_type:
149
- clauses.append({"type": {"$in": parsed.model_type}})
150
- if parsed.publisher:
151
- clauses.append({"publisher": {"$in": parsed.publisher}})
152
- for task in parsed.task:
153
- clauses.append({"tasks": {"$contains": task}})
154
- for capability in parsed.capability:
155
- field = capability.replace("-", "_")
156
- clauses.append(
157
- {
158
- "capabilities": {
159
- field: (
160
- {"$ne": None}
161
- if capability == "reasoning"
162
- else {"$eq": True}
163
- )
164
- }
165
- }
166
- )
167
- expression: dict[str, object] = (
168
- {}
169
- if not clauses
170
- else clauses[0]
171
- if len(clauses) == 1
172
- else {"$and": clauses}
173
- )
174
- records = self.query(expression)
175
- if parsed.query:
176
- return [
177
- result.record
178
- for result in self._search_index.search(
179
- parsed.query,
180
- limit=parsed.limit,
181
- record_ids={record.id for record in records},
182
- )
183
- ]
184
- records.sort(key=lambda record: (record.name.casefold(), record.id.casefold()))
185
- return records if parsed.limit is None else records[: parsed.limit]
186
-
187
- def search(
188
- self,
189
- query: str,
190
- *,
191
- limit: int | None = 50,
192
- ) -> list[CatalogSearchResult]:
193
- return self._search_index.search(query, limit=limit)
194
-
195
-
196
- def fetch_catalog(url: str) -> bytes:
197
- with urlopen(url) as response:
198
- return response.read()
199
-
200
-
201
- def fetch_published_catalog(
202
- url: str = PUBLISHED_CATALOG_URL,
203
- *,
204
- refresh: bool = False,
205
- cache_directory: CatalogCacheDirectory | None = None,
206
- cache_ttl: float = PUBLISHED_CATALOG_CACHE_TTL,
207
- fetch: CatalogFetch | None = None,
208
- ) -> bytes:
209
- loader = fetch or fetch_catalog
210
- with Cache(published_catalog_cache_directory(cache_directory)) as cache:
211
- cached_fetch = cache.memoize(
212
- name="dbx-model-catalog.published-catalog",
213
- expire=cache_ttl,
214
- tag="published-catalog",
215
- )(loader)
216
- if refresh:
217
- cache.delete(cached_fetch.__cache_key__(url), retry=True)
218
- return cached_fetch(url)
219
-
220
-
221
- def published_catalog_cache_directory(
222
- directory: CatalogCacheDirectory | None = None,
223
- ) -> Path:
224
- if directory is not None:
225
- return Path(directory)
226
- return user_cache_path("dbx-model-catalog") / "published-catalog"
227
-
228
-
229
- def decode_catalog_payload(payload: bytes, encoding: CatalogPayloadEncoding) -> str:
230
- decoded = payload if encoding == "json" else brotli.decompress(payload)
231
- return decoded.decode("utf-8")
232
-
233
-
234
- def _looks_like_json(payload: bytes) -> bool:
235
- return payload.lstrip().startswith(b"{")
236
-
237
-
238
- __all__ = [
239
- "CatalogCacheDirectory",
240
- "CatalogFetch",
241
- "CatalogPayloadDecoder",
242
- "CatalogPayloadEncoding",
243
- "ModelCatalogClient",
244
- "PUBLISHED_CATALOG_BASE_URL",
245
- "PUBLISHED_CATALOG_CACHE_TTL",
246
- "PUBLISHED_CATALOG_URL",
247
- "decode_catalog_payload",
248
- "fetch_catalog",
249
- "fetch_published_catalog",
250
- "published_catalog_cache_directory",
251
- ]