npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ivy-orm

v0.0.25

Published

A TypeScript-based "ORM" for [Azure AI Search](https://learn.microsoft.com/en-us/azure/search/search-what-is-azure-search) (formerly Cognitive Search). Define a schema for your AI Search indexes, indexers, and data sources, and get a strongly-typed [Searc

Downloads

367

Readme

Ivy ORM

A TypeScript-based "ORM" for Azure AI Search (formerly Cognitive Search). Define a schema for your AI Search indexes, indexers, and data sources, and get a strongly-typed SearchClient.

See Ivy Kit for a handy CLI migrator tool!

Documentation

Installation

npm install ivy-orm

Schemas

Define a schema for your indexes, indexers, and data sources:

import { index, indexer, dataSource, string, int32 } from "ivy-orm";

export const realEstate = index("realestate-us-sample-index", {
  listingId: string("listingId").key(),
  beds: int32("beds").filterable().sortable().facetable(),
  baths: int32("baths").filterable().sortable().facetable(),
  description: string("description").searchable(),
  squareFeet: int32("sqft").filterable().sortable().facetable(),
});

export const realEstateDataSource = dataSource(
  "realestate-us-sample",
  "azuresql",
  {
    connectionString: process.env.CONNECTION_STRING,
    container: {
      name: "Listings_5K_KingCounty_WA",
    },
  }
);

export const realEstateIndexer = indexer("realestate-us-sample-indexer", {
  targetIndex: realEstate,
  dataSourceName: realEstateDataSource.name,
});

Ivy ORM infers the appropriate TypeScript types for all fields, and maps the schema onto the underlying SearchClient. You can use all the methods you'd usually use on a SearchClient, but strongly-typed and with excellent IDE autocomplete:

const searchIndexClient = new SearchIndexClient(endpoint, identity);

const srch = connect(searchIndexClient, schema);

const data = await srch.realEstate.search(undefined, {
  top: 20,
  select: ["listingId", "description"],
});

Supported Field Types

Ivy ORM supports most of the AI Search EDM data types.

Primitives

// Edm.String
myField: string("myField");

// Edm.Int32
myField: int32("myField");

// Edm.Int64
myField: int64("myField");

//Edm.Double
myField: double("myField");

//Edm.Boolean
myField: boolean("myField");

Complex Fields

// Edm.ComplexType
myComplex: complex("myComplex", {
  myField: string("myField"),
});

Collections

// Collection(Edm.String)
myCollection: stringCollection("myCollection");

// Collection(Edm.Int32)
myCollection: int32Collection("myCollection");

// Collection(Edm.Int64)
myCollection: int64Collection("myCollection");

// Collection(Edm.Double)
myCollection: doubleCollection("myCollection");

// Collection(Edm.DateTimeOffset)
myCollection: dateCollection("myCollection");

// Collection(Edm.Boolean)
myCollection: booleanCollection("myCollection");

// Collection(Edm.ComplexType)
myCollection: collection("myCollection", {
  // ComplexType object fields
  myField: string("myField"),
});

Suggesters

Add a suggester to a field in the index schema:

import { index, string } from "ivy-orm";

const hotels = index("hotels-sample-index", {
  name: string("name").suggester(),
});

and use AI Search's suggest() method with Typescript:

const { results } = await srch.hotels.suggest("my query", "sg", {
  select: ["name"],
  searchFields: ["name"],
});

"sg" is the default suggester name.

Data Sources

Define the name, type, and configuration options for the data source. See the Azure Documentation for more detail on the configuration options.

export const realEstateDataSource = dataSource(
  "realestate-us-sample",
  "azuresql",
  {
    connectionString: process.env.CONNECTION_STRING,
    container: {
      name: "Listings_5K_KingCounty_WA",
    },
  }
);

See the Azure Documentation on defining connection strings that use a managed identity.

Extras

Field names in the ORM don't need to match the names in the datasource. This automatically creates a field mapping in the indexer.

export const realEstate = index("realestate-us-sample-index", {
  squareFeet: int32("sqft").filterable().sortable().facetable(),
  // ^ORM field name  ^datasource column name
});

Note: This only works on top-level primitives. Complex fields aren't supported in a field mapping.