open-index/open-npm huggingface dataset:
npm package: @prairiebandag/hemp_hurds_hempcrete
Description: To install dependencies:
Latest version: 0.1.19

# hemp-hurds-hempcrete--variation-swatches

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run src/index.ts
```

This project was created using `bun init` in bun v1.0.7. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
npm package: @prairielearn/aws
Description: This package contains utilities that help us correctly configure AWS SDK clients.
Latest version: 3.0.3

# `@prairielearn/aws`

This package contains utilities that help us correctly configure AWS SDK clients.

Specifically, it's meant to address the fact that clients from the v3 AWS SDK don't share resolved credentials with each other. This means that, by default, every time a new client is created, it has to independently resolve credentials for itself. In production, this is problematic, as that requires talking to the IMDS, which will throttle requests if we make a ton of them in rapid succession. This results in clients being unable to obtain credentials, and thus the AWS API operations fail.

We resolve this with this package, which helps ensure that all AWS SDk clients are constructed with a shared and memoized credential provider.

## Usage

Create a config provider with `makeAwsConfigProvider`:

```ts
import { makeAwsConfigProvider } from '@prairielearn/aws';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';

const awsConfigProvider = makeAwsConfigProvider({
  credentials: fromNodeProviderChain(),
  getClientConfig: () => ({
    region: 'us-east-2',
  }),
});

export const makeAwsClientConfig = awsConfigProvider.makeAwsClientConfig;
export const makeS3ClientConfig = awsConfigProvider.makeS3ClientConfig;
```

Then, use the `makeAwsClientConfig` and `makeS3ClientConfig` functions to configure AWS clients:

```ts
import { EC2Client } from '@aws-sdk/client-ec2';
import { S3Client } from '@aws-sdk/client-s3';

const ec2 = new EC2Client(makeAwsClientConfig());
const s3 = new S3Client(makeS3ClientConfig());
```

### Providing extra config

The `get...` functions support passing in extra config. If this extra config conflicts with other config, such as that returned from `getClientConfig()`, this extra config will take precedence.

```ts
const s3 = new S3Client(
  makeS3ClientConfig({
    maxAttempts: 3,
  }),
);
```

### Customizing S3 config

The config for S3 clients can be customized independently to support pointing it to other S3-compatible stores.

For instance, to use [`s3rver`](https://github.com/jamhall/s3rver) when running in dev mode, you could use something like the following config:

```ts
const awsConfigProvider = makeAwsConfigProvider({
  credentials: fromNodeProviderChain(),
  getClientConfig: () => ({
    region: 'us-east-2',
  }),
  makeS3ClientConfig: () => {
    if (process.env.NODE_ENV !== 'production') {
      return {
        forcePathStyle: true,
        credentials: {
          accessKeyId: 'S3RVER',
          secretAccessKey: 'S3RVER',
        },
        endpoint: 'http://127.0.0.1:5000',
      };
    }

    return {};
  },
});
```
npm package: @prairielearn/aws-imds
Description: Utilities for fetching data from the [AWS EC2 Instance Metadata Service (IMDS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html).
Latest version: 3.0.2

# `@prairielearn/aws-imds`

Utilities for fetching data from the [AWS EC2 Instance Metadata Service (IMDS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html).

## Usage

```ts
import { fetchImdsText, fetchImdsJson } from '@prairielearn/aws-imds';

const hostname = await fetchImdsText('/latest/meta-data/hostname');
const identity = await fetchImdsJson('/latest/dynamic/instance-identity/document');
```

You can also use convenience functions to fetch data from common endpoints. The data is internally validated with Zod before being returned.

```ts
import { fetchInstanceHostname, fetchInstanceIdentity } from '@prairielearn/aws-imds';

const hostname = await fetchInstanceHostname();
const identity = await fetchInstanceIdentity();
```
npm package: @prairielearn/bind-mount
Description: This package allows for the creation and removal of bind mounts via native bindings to the [`mount()`](https://man7.org/linux/man-pages/man2/mount.2.html) and [`umount()`](https://man7.org/linux/man-pages/man2/umount.2.html) Linux system calls. These bind
Latest version: 2.0.2

# `@prairielearn/bind-mount`

This package allows for the creation and removal of bind mounts via native bindings to the [`mount()`](https://man7.org/linux/man-pages/man2/mount.2.html) and [`umount()`](https://man7.org/linux/man-pages/man2/umount.2.html) Linux system calls. These bindings are 1-2 orders of magnitude faster than shelling out to the `mount` and `umount` commands.

Only bind mounts are currently supported. It is not possible to create other type of mounts, or to change the flags used when creating the mount.

This package is only designed to work on Linux. It will compile on other platforms, but all functions will throw errors if they're called.

## Usage

```ts
import { mount, umount } from '@prairielearn/bind-mount';

await mount('/source', '/target');
await umount('/target');
```
npm package: @prairielearn/cache
Description: Utilities to help connect to and store information in a cache. This package _does not_ load configurations directly. Instead, configs should be passed in when the package is initialized upon loading the application. Then, the package can be used in the th
Latest version: 2.1.8

# `@prairielearn/cache`

Utilities to help connect to and store information in a cache. This package _does not_ load configurations directly. Instead, configs should be passed in when the package is initialized upon loading the application. Then, the package can be used in the throughout the application to interact with the cache.

## Usage

First, you will need to initialize the library with the cache type that you are intending to use, a prefix that will be the start of all of your cache keys, and optionally, a Redis server URL if that is the cache type being used:

```ts
import { cache } from '@prairielearn/cache';

await cache.init({
  type: 'redis',
  keyPrefix: 'my-app:',
  redisUrl: 'redis://localhost:6379/',
});
```

Alternatively, you can create new instances of the `Cache` class instead of using the global `cache` object:

```ts
import { Cache } from '@prairielearn/cache';

const myCache = new Cache();

await myCache.init({
  type: 'redis',
  keyPrefix: 'my-app:',
  redisUrl: 'redis://localhost:6379/',
});
```

After initializing, you can use `set`, `get`, `del`, `reset` or `close` functions to interact with the cache. Note that `set`, `get`, and `del` have required arguments. Calling `set` will require the intended KEY, VALUE, and length of time to store the data (in milliseconds). Calling `get` or `del` will require the KEY for the intended result.

The following example will store `foo: bar` for 10 minutes:

```ts
await cache.set('foo', 'bar', 600000);
```

The following example will use the key `foo` to retrieve the value `bar`:

```ts
await cache.get('foo');
// returns bar
```

The following example will use the key `foo` to delete the key value pair `foo: bar`:

```ts
await cache.del('foo');
```

Using `reset()` will clear the currently stored data in the cache. Using `close()` will disable the currently used cache and, if using Redis, close the connection.
npm package: @prairielearn/config
Description: Utilities to help load configuration from various sources including a JSON file and AWS Secrets Manager. Config is made type-safe through a [Zod](https://github.com/colinhacks/zod) schema.
Latest version: 4.1.1

# `@prairielearn/config`

Utilities to help load configuration from various sources including a JSON file and AWS Secrets Manager. Config is made type-safe through a [Zod](https://github.com/colinhacks/zod) schema.

This package _should not_ be depended upon by other packages directly. Instead, import it into your application, load the config, and then provide any necessary values to other packages.

## Usage

```ts
import { ConfigLoader, makeFileConfig } from '@prairielearn/config';
import { z } from 'zod';

const ConfigSchema = z.object({
  hello: z.string().default('world'),
});

const configLoader = new ConfigLoader(ConfigSchema);

await configLoader.loadAndValidate([makeFileConfig('config.json')]);

console.log(configLoader.config);
// { hello: "world" }
```

Typically, you'll want to have a `config.ts` file in your own project that encapsulates this. Then, you can import the config elsewhere in the project.

```ts
import { ConfigLoader, makeFileConfig } from '@prairielearn/config';
import { z } from 'zod';

const configLoader = new ConfigLoader(z.any());

export async function loadAndValidate(path: string) {
  await configLoader.loadAndValidate([makeFileConfig(path)]);
}

export default configLoader.config;
```

### Loading config from AWS

If you're running in AWS, you can use `makeImdsConfig()` and `makeSecretsManagerConfig()` to load config from IMDS and Secrets Manager, respectively:

- `makeImdsConfig()` will load `hostname`, `instanceId`, and `awsRegion`, which will be available if you config schema contains these values.
- `makeSecretsManagerConfig()` will look for a `ConfSecret` tag on the instance. If found, the value of that tag will be used treated as a Secrets Manager secret ID, and that secret's value will be parsed as JSON and merged into the config.

Note that both of these config sources are no-ops by default. To active them, you must do one of the following:

- Set `CONFIG_LOAD_FROM_AWS=1` in the process environment.
- Chain them after `makeFileConfig()`, and ensure that the config file contains `{"runningInEc2": true}`.
npm package: @prairielearn/csv
Description: A few helpful wrappers on top of the functionality from [`csv-stringify`](https://www.npmjs.com/package/csv-stringify).
Latest version: 3.0.2

# `@prairielearn/csv`

A few helpful wrappers on top of the functionality from [`csv-stringify`](https://www.npmjs.com/package/csv-stringify).

## Usage

Here's an example taking data from `@prairielearn/postgres#queryCursor()` and writing it to a file, though this should be applicable to any source and destination streams:

```ts
import { stringifyStream } from '@prairielearn/csv';
import { queryCursor } from '@prairielearn/postgres';
import { pipeline } from 'node:stream/promises';
import { createWriteStream } from 'node:fs';
import { IdSchema } from '@prairielearn/zod';
import { z } from 'zod';

const WorkspaceSchema = z.object({
  id: IdSchema,
  hostname: z.string(),
});
type Workspace = z.infer<typeof WorkspaceSchema>;

const cursor = await queryCursor('SELECT id, hostname FROM workspaces;', WorkspaceSchema);
const output = createWriteStream('workspaces.csv');

const stringifier = stringifyStream<Workspace>({
  header: true,
  columns: [
    { key: 'id', header: 'ID' },
    { key: 'hostname', header: 'Hostname' },
  ],
  // Optionally provide a function to transform each item in the stream.
  transform(record) {
    return {
      id: `workspace-${record.id}`,
      hostname: record.hostname,
    };
  },
});

await pipeline(cursor.stream(100), stringifier, output);
```

Note that this works best when the source stream is producing data asynchronously, such as though an async iterator. If you use a synchronous data source like `Readable.from([...])`, the conversion will still occur synchronously. If you have a large array of data in memory and want to convert it to a CSV, you can use `stringifyNonblocking`:

```ts
import { stringifyNonblocking } from '@prairielearn/csv';
import { createWriteStream } from 'node:fs';

const data = Array.from(new Array(100_000), (_, i) => ({ id: i }));
const output = createWriteStream('numbers.csv');
stringifyNonblocking<{ id: number }>(data, {
  header: true,
  columns: [{ key: 'id', header: 'ID' }],
}).pipe(output);
```

For lower-level usage, `stringify` and `Stringifier` are also re-exported from `csv-stringify`:

```ts
import { stringify, Stringifier } from '@prairielearn/csv';
```