open-index/open-npm huggingface dataset:
npm package: @sebspark/cli-tester
Description: A wrapper for child_process spawn to simplify interactive cli tests using `@inquirer/prompt`
Latest version: 1.0.13

# `@sebspark/cli-tester`

A wrapper for child_process spawn to simplify interactive cli tests using `@inquirer/prompt`

## Install

```zsh
yarn add @sebspark/cli-tester -D
```

```zsh
npm install @sebspark/cli-tester -D
```

## Usage

```typescript
import test from 'node:test'
import assert from 'node:assert'
import { run } from '@sebspark/cli-tester'

test('awaits an input prompt and provides input', async () => {
  const cli = run('./cli/input.mjs')

  const prompt = await cli.prompt('input')
  assert.strictEqual(prompt.type, 'input')
  assert.strictEqual(prompt.message, 'type something')
  assert.strictEqual(prompt.default, undefined)

  await cli.input('hello')

  const nextPrompt = await cli.prompt('input')
  assert.strictEqual(nextPrompt.type, 'input')
  assert.strictEqual(nextPrompt.message, 'type something else')
  assert.strictEqual(nextPrompt.default, undefined)
})

test('awaits an input prompt with default and provides input', async () => {
  const cli = run('./cli/input.mjs')

  const prompt = await cli.prompt('input')
  assert.strictEqual(prompt.type, 'input')
  assert.strictEqual(prompt.message, 'type something')
  assert.strictEqual(prompt.default, 'default value')

  await cli.input('custom value')

  const nextPrompt = await cli.prompt('input')
  assert.strictEqual(nextPrompt.type, 'input')
  assert.strictEqual(nextPrompt.message, 'type something else')
  assert.strictEqual(nextPrompt.default, undefined)
})

test('awaits a select prompt and chooses an option', async () => {
  const cli = run('./cli/select.mjs')

  const prompt = await cli.prompt('select')
  assert.strictEqual(prompt.type, 'select')
  assert.strictEqual(prompt.message, 'select something')
  assert.deepStrictEqual(prompt.options, ['option 1', 'option 2', 'option 3'])

  await cli.select(1) // Select second option
  const result = await cli.output()

  assert.strictEqual(result, 'option 2')
})

test('checks CLI output after selection', async () => {
  const cli = run('./cli/select.mjs')

  await cli.prompt('select')
  await cli.select(2)

  const result = await cli.output()
  assert.strictEqual(result, 'option 3')
})

test('awaits CLI exit', async () => {
  const cli = run('./cli/input.mjs')

  await cli.prompt('input')
  await cli.input('input 1')
  await cli.prompt('input')
  await cli.input('input 2')

  const exitCode = await cli.exit()
  assert.strictEqual(exitCode, 0)
})
```
## TODO

Add support for:

- Select Separator
- Checkbox
- Confirm
- Search
- Password
- Expand
- Number
- Raw List
npm package: @sebspark/gcp-iam
Description: Google IAM utilities. This package is intended to be run in GCP contexts, such as running under a GKE service account using Workload Identity.
Latest version: 3.0.37

# `@sebspark/gcp-iam`

Google IAM utilities. This package is intended to be run in GCP contexts, such as running under a GKE service account using Workload Identity.


# Explanation

It generates the JWT that we put into the proxy-authorization header. That JWT is signed by the GCP service account and the aud part of the JWT is set to the URL we are going to call in the API Gateway.
 
Generating and signing the JWT uses a bunch of CPU cycles, so it makes sense to cache them for a short time.
npm package: @sebspark/iso-10383
Description: ISO-10383 Market Identification Codes (MIC) made available through an NPM package.
Latest version: 1.2.4

# `@sebspark/iso-10383`

ISO-10383 Market Identification Codes (MIC) made available through an NPM package.

## More information

The MICs are fetched directly from [iso20022.org](https://www.iso20022.org/market-identifier-codes).
npm package: @sebspark/openapi-client
Description: A typed REST client for the definitions from openapi-typegen
Latest version: 4.1.31

# `@sebspark/openapi-client`

A typed REST client for the definitions from openapi-typegen

## Usage

### Install

```zsh
yarn add @sebspark/openapi-client`
```

or

```zsh
npm install @sebspark/openapi-client`
```

### Generate client type

Use [@sebspark/openapi-typegen](../packages/openapi-typegen)

### Code

```typescript
import { TypedClient } from '@sebspark/openapi-client'
import { MarketdataClient } from './schemas/marketdata'

const client = TypedClient<MarketdataClient>(`https://example.com/api`)
const {data} = await client.get('/markets')
```

## Example

Example can be found in [@sebspark/openapi-e2e](../packages/openapi-e2e)
npm package: @sebspark/openapi-core
Description: Base types and utilities for OpenAPI/Typescript. Used by:
Latest version: 4.1.8

# `@sebspark/openapi-core`
Base types and utilities for OpenAPI/Typescript. Used by:

[@sebspark/openapi-typegen](__./packages/openapi-typegen__)

[@sebspark/openapi-express](__./packages/openapi-express__)

[@sebspark/openapi-client](__./packages/openapi-client__)

## Document utilities

Helper functions for transforming OpenAPI documents before rendering or serving. All functions return a cloned document and do not modify the original.

### `disableUnimplementedPaths(document, server)`

Marks paths not present in the server definition as deprecated and tagged with `not-implemented`.

### `appendVersionToServers(document, version)`

Appends a version segment to all server URLs in the document.

### `flattenEnums(document)`

Flattens `oneOf[$ref, $ref, ...]` schemas where all refs resolve to enums into a single merged enum. Enables API UI tools like Scalar to render a dropdown instead of a free-text input.

### `resolveRef(ref, document)`

Resolves a `$ref` string to its schema definition within the document.

## HTTP Errors

Typed HTTP error classes for all 4xx and 5xx status codes.

```typescript
import { NotFoundError, UnauthorizedError, createHttpError, fromAxiosError } from '@sebspark/openapi-core'

throw new NotFoundError('Instrument not found')
throw new UnauthorizedError()

// Create by status code
throw createHttpError(429, 'Slow down')

// Convert from Axios error
catch (e) {
  throw fromAxiosError(e)
}
```

All errors extend `HttpError` which exposes a `statusCode` property and a `toJSON(showStack?)` method.
npm package: @sebspark/openapi-express
Description: A typed router for express based on type definitions from openapi-typegen
Latest version: 5.3.8

# `@sebspark/openapi-express-router`

A typed router for express based on type definitions from openapi-typegen

## Usage

### Install

```zsh
yarn add @sebspark/openapi-express`
```

or

```zsh
npm install @sebspark/openapi-express`
```

### Generate client type

Use [@sebspark/openapi-typegen](../packages/openapi-typegen)

### Code

```typescript
import express from 'express'
import { TypedRouter } from '@sebspark/openapi-express'
import { MarketdataServer } from './schemas/marketdata'
import { getMarkets, getMarket } from './markets'

const api: MarketdataServer = {
  '/markets': {
    get: {
      handler: async () => {
        const markets = await getMarkets()
        return [200, {data: markets}]
      },
    },
  },
  '/markets/:id': {
    get: {
      handler: async ({ params }) => {
        const market = await getMarket(params.id)
        return [200, {data: market}]
      },
    },
  },
}

const router = TypedRouter(api)
const app = express()
app.use(router)
```

## Example

Example can be found in [@sebspark/openapi-e2e](../packages/openapi-e2e)
npm package: @sebspark/openapi-typegen
Description: Generates types and a routerdefinition from OpenAPI specs
Latest version: 5.0.24

# `@sebspark/openapi-typegen`

Generates types and a routerdefinition from OpenAPI specs

## Usage

This is an example assuming that you have one schema, `marketdata.json`. The name
of this file will be used to generate Server and Client names.

This example can be found in [@sebspark/openapi-e2e](../packages/openapi-e2e)

```zsh
yarn openapi-typegen -i ./src/schemas/ -o ./src/schemas/
```

The schema will export all types defined in the OpenAPI spec as well as:

`MarketdataAPIServer` - a server definition meant to be used with [@sebspark/openapi-express](./packages/openapi-express)

`MarketDataAPIClient` - a client definition meant to be used with [@sebspark/openapi-client](./packages/openapi-client)
npm package: @sebspark/pubsub
Description: A wrapper around [@google-cloud/pubsub](https://www.npmjs.com/package/@google-cloud/pubsub) adding simple methods for publishing and subscribing with typed messages.
Latest version: 1.8.3
Deprecated: This package is deprecated and no longer maintained. Please use vanilla @google-cloud/pubsub instead.

# `@sebspark/pubsub`

A wrapper around [@google-cloud/pubsub](https://www.npmjs.com/package/@google-cloud/pubsub) adding simple methods for publishing and subscribing with typed messages.

## Examples

```typescript
type ExampleMessage = {
  messageType: string;
  message: string;
};

type ExamplePubsubChannels = {
  example: ExampleMessage;
};
```

### SubscriptionClient

```typescript
// Instantiate subscriber.
const subscriber = createSubscriber<ExamplePubsubChannels>({
  projectId: "test",
});

// Ensure
await subscriber.topic("example").initiate("example_subscription", {
  autoAck: false, // false means you need to call acc or nack in the message event handler.
  expirationPolicy: 3600 * 24, // Seconds.
  messageRetentionDuration: 3600 * 27 * 7, // Seconds
});

await subscriber.topic("example").subscribe("example_subscription", {
  onMessage: async (message: TypedMessage<ExampleMessage>) => {
    try {
      // Do something.

      // Ack message.
      message.ack();
    } catch (err) {
      console.error(err);

      // Nack message.
      message.nack();
    }
  },
});
```

## PubSubOptions

`SubscriptionClient` supports a simplified subset of the options from `@google-cloud/pubsub` and a custom parameter that decides the ack/nack behavior of messages.

```typescript
export type PubSubOptions = {
  expirationPolicy: number;
  messageRetentionDuration: number;
  autoAck?: boolean; // Default true
};
```

Set `autoAck` to false if you want to ack/nack messages manually in your message handler.
npm package: @sebspark/retry
Description: A helper for retrying any promise call (ex an http request) with error rules and backoff
Latest version: 1.0.9

# `@sebspark/retry`

A helper for retrying any promise call (ex an http request) with error rules and backoff

## Usage

```typescript
import { retry, interval, retryCondition, RetrySettings } from '@sebspark/retry'
import axios from 'axios'

const settings: RetrySettings = {
  interval: interval.exponential(1000), // Exponential backoff starting at 1000 ms
  maxRetries: 5,
  retryCondition: retryCondition.serverErrors, // Only retries on server errors
}

const result = await retry(() => axios.get('https://example.com'), settings)
```
npm package: @sebspark/socket.io-gcp-pubsub-emitter
Description: A Socket.IO PubSub emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process
Latest version: 1.0.15

# `@sebspark/socket.io-gcp-pubsub-emitter`

A Socket.IO PubSub emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process
npm package: @sebspark/spanner-mock
Description: A (so far incomplete) mocking library for Spanner DB
Latest version: 0.2.3
Deprecated: This package is deprecated and no longer maintained. If you need to deep mock Spanner DB, you probably want to write e2e tests instead using  **Spanner Emulator**

# `@sebspark/spanner-mock`

A (so far incomplete) mocking library for Spanner DB
npm package: @sebspark/testcontainers-spanner
Description: > ⚠️ **DEPRECATED**   > This package has been donated to the Testcontainers organization.   > **Please switch to [`@testcontainers/gcloud`](https://www.npmjs.com/package/@testcontainers/gcloud).**
Latest version: 0.1.3
Deprecated: This package is deprecated and no longer maintained. Use @testcontainers/gcloud instead.

# @sebspark/testcontainers-spanner

> ⚠️ **DEPRECATED**  
> This package has been donated to the Testcontainers organization.  
> **Please switch to [`@testcontainers/gcloud`](https://www.npmjs.com/package/@testcontainers/gcloud).**

---

## 🚀 Install the new package

```bash
npm uninstall @sebspark/testcontainers-spanner
npm install @testcontainers/gcloud
```

or with Yarn:

```bash
yarn remove @sebspark/testcontainers-spanner
yarn add @testcontainers/gcloud
```

---

## 🔄 Migration guide

If you were previously doing:

```ts
import { SpannerEmulatorContainer } from '@sebspark/testcontainers-spanner'

const emulator = await new SpannerEmulatorContainer().start()

// create instance and database
await emulator.createInstance('my-instance', { nodeCount: 1 })
await emulator.createDatabase('my-instance', 'my-db')

// ... run your tests against emulator ...

// delete instance and database
await emulator.deleteDatabase('my-instance', 'my-db')
await emulator.deleteInstance('my-instance')

await emulator.stop()
```

update to:

```ts
import { SpannerEmulatorContainer, SpannerEmulatorHelper } from '@google-cloud/spanner'

// Image name required
const emulator = await new SpannerEmulatorContainer('gcr.io/cloud-spanner-emulator/emulator').start()
const helper = new SpannerEmulatorHelper(container)

// Enable emulation for single instance testing
process.env.SPANNER_EMULATOR_HOST = container.getEmulatorGrpcEndpoint()

// create instance and database
await helper.createInstance('my-instance', { nodeCount: 1 })
await helper.createDatabase('my-instance', 'my-db')

// ... run your tests against emulator ...

// delete instance and database
await helper.deleteDatabase('my-instance', 'my-db')
await helper.deleteInstance('my-instance')

await emulator.stop()
```

Everything else (methods, lifecycle hooks, etc.) remains identical — just replace the package name and class.

---

## 📚 Documentation

For full docs, examples and API reference, please see the official Testcontainers repo:

- https://node.testcontainers.org/modules/gcloud/#cloud-spanner
- https://github.com/testcontainers/testcontainers-node/tree/main/modules/gcloud

---

> _Thank you for using this library. If you have questions or run into issues, please open them over in the Testcontainers org!_
npm package: @sebspark/tracing
Description: Use Opentelemetry for collecting traces and exporting to Cloud Trace
Latest version: 0.1.2
Deprecated: This package is deprecated and no longer maintained. Use @sebspark/otel instead.

# `@sebspark/tracing`

Use Opentelemetry for collecting traces and exporting to Cloud Trace


### How to use

```javascript
/* eslint-disable @typescript-eslint/no-var-requires */
import { setupTracing } from '@sebspark/tracing'

const serviceName = 'core'

if (process.env.TRACING_PROJECT_ID) {
  setupTracing({
    serviceName,
    projectId: process.env.TRACING_PROJECT_ID,
  })
} else if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
  setupTracing({
    serviceName,
    url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
  })
}

// Sadly we need to wait a bit for the tracing to be initialized
setTimeout(() => {
  require('./run')
}, 100)
```
npm package: @sebspark/tradeinsight
Description: TradeInsight client library with helpers for creating/parsing instrument IDs and consuming ticker feeds.
Latest version: 6.0.1

# `@sebspark/tradeinsight`

TradeInsight client library with helpers for creating/parsing instrument IDs and consuming ticker feeds.

## Instrument IDs

### Create ID

```javascript
const isin = 'SE0000108656'
const mic = 'XSTO'
const currency = 'SEK'
const id = createStockId({ isin, mic, currency })

console.log(id)
// STO_SE0000108656_SEK_XSTO
```

### Parse ID

```javascript
const { type, baseCurrency, quoteCurrency } = parseId('FXS_USD_EUR')
console.log(type, baseCurrency, quoteCurrency)
// FOREX, USD, EUR
```
npm package: @sebspark/trading-hours
Description: Find trading hours of a market, when it&#x27;s closed for holidays, or when it&#x27;s only open for part of the day.
Latest version: 1.0.6

# `@sebspark/trading-hours`

Find trading hours of a market, when it&#x27;s closed for holidays, or when it&#x27;s only open for part of the day.

## API

### holidays

```typescript
holidays(mic: SebMarket, year: number): Array<string>
```

Return a list of holidays for the provided market and year. The list contains dates formatted as ISO 8601 dates (YYYY-MM-DD).

### halfdays

```typescript
halfdays(mic: SebMarket, year: number): Array<string>
```

Similar to `holidays`, but for half trading days. In Sweden, these are common the day before a holiday, but they also occur in other markets, for example around Christmas.

### isHoliday

```typescript
isHoliday(mic: SebMarket, date: Date): boolean
```

Check if the provided date is a holiday on the market. Saturday and Sunday are always considered holidays.

### isHalfday

```typescript
isHalfday(mic: SebMarket, date: Date): boolean
```

Similar to `isHoliday`, but for half trading days.

### isOpen

```typescript
isOpen(mic: SebMarket): boolean
```

Checks if the market is open. This takes into account holidays, half trading days, and opening hours.

### formatOpeningHours

```typescript
formatOpeningHours(mic: SebMarket): string
```

Returns a formatted string of the opening hours of the market. For example, `09:00 - 17:30` for `XSTO`. Takes into account half trading days and returns any irregular opening hours.

### whichHoliday

```typescript
whichHoliday(mic: SebMarket, date: Date): Holiday | null
```

Checks what holiday, if any, the provided date is. The return types is provided as a TypeScript union instead of the actual name. This way the consumer can choose what to display, which is useful for multilanguage applications.

### marketOpeningHours

```typescript
type Hours = {
  openHour: number
  openMinute: number
  closeHour: number
  closeMinute: number
}

marketOpeningHours(mic: SebMarket, date: Date): Hours | null
```

Return the open hours of the provided market and date. Handles half trading days.

## Types

```typescript
export type SebMarket =
  | "EQTB"
  | "SSME"
  | "XAMS"
  | "XETR"
  | "XHEL"
  | "XPAR"
  | "XSTO";

export type Holiday =
  | "ascensionDay"
  | "boxingDay"
  | "christmasDay"
  | "christmasEve"
  | "easterMonday"
  | "epiphany"
  | "goodFriday"
  | "independenceDayFinland"
  | "independenceDaySweden"
  | "laborDay"
  | "midsummerDay"
  | "midsummerEve"
  | "newYearsDay"
  | "newYearsEve";
```