# rstore-vite-monospace

Guides wiring Monospace into a plain Vite and Vue app through the rstore Vite plugin, generated schema, and store setup.

Skill by Directus. Category: Web and browsers.

## Install

Project (for this project only):

```sh
npx skills add directus/rstore --skill rstore-vite-monospace
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

Global (for every project on this machine):

```sh
npx skills add directus/rstore --skill rstore-vite-monospace -g
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

## Tags

- Runs on your computer: It runs as a program on your machine, with your access.

## Security audits

- Gen Agent Trust Hub: Pass
- Socket: Pass
- Snyk: Pass

Installs: 2. Installs counted by skills.sh. [Open on skills.sh](https://www.skills.sh/directus/rstore/rstore-vite-monospace)

## Source

[Open the source](https://github.com/directus/rstore/tree/HEAD/packages/vite-monospace/skills/rstore-vite-monospace). Checked 2026-10-10. This summary may contain AI-generated text, so it can be wrong. Check the source before you rely on it.

## SKILL.md

````markdown
---
name: rstore-vite-monospace
description: "Use when wiring Monospace into a plain Vite/Vue app with @rstore/vite-monospace, including rstoreMonospace config, remote or local OpenAPI generation, virtual:rstore-monospace modules, generated rstore-monospace.d.ts declarations, runtimeApiKey handling, primaryKeys, and store setup with the generated schema and monospacePlugin."
---

# Rstore Vite Monospace

Use `@rstore/vite-monospace` to generate Monospace-backed rstore schema and plugin modules in a non-Nuxt Vite app.

## Setup

Register the Vite plugin in `vite.config.ts`:

```ts
import { rstoreMonospace } from '@rstore/vite-monospace'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    rstoreMonospace({
      url: 'https://your-monospace-instance.com',
      project: 'your-project',
      schemaApiKey: process.env.MONOSPACE_API_KEY,
      scopeId: 'rstore-monospace',
    }),
  ],
})
```

Then create the store from the generated virtual module:

```ts
import { createStore, RstorePlugin } from '@rstore/vue'
import { monospacePlugin, schema } from 'virtual:rstore-monospace'

const store = await createStore({
  schema,
  plugins: [monospacePlugin],
})

app.use(RstorePlugin, { store })
```

## Options

| Option | Purpose |
| --- | --- |
| `url` | Monospace API URL used for remote schema loading and runtime client code |
| `project` | Monospace project identifier |
| `schemaApiKey` | Build-time key for remote schema loading (needs `openApiSchema:read` + `dataModel:read`) |
| `input` | Local OpenAPI JSON path, resolved from the Vite root |
| `metadataInput` | Local schema metadata snapshot JSON path, resolved from the Vite root |
| `runtimeApiKey` | Runtime API key emitted into generated client code |
| `scopeId` | rstore plugin scope id, defaulting to `rstore-monospace` |
| `primaryKeys` | Explicit primary key overrides by collection name |
| `dts` | Declaration output path, `true`/omitted for `rstore-monospace.d.ts`, or `false` to disable |

## Virtual Modules

- `virtual:rstore-monospace` re-exports `schema`, `monospace`, and `monospacePlugin`.
- `virtual:rstore-monospace/schema` exports the generated rstore schema.
- `virtual:rstore-monospace/plugin` exports the Monospace REST client and rstore plugin.

## Local Schema Mode

Use `input` plus `metadataInput` when the schema is checked into the project or generated separately. The metadata snapshot holds the raw items of the Monospace system schema meta collections keyed by collection name:

```ts
rstoreMonospace({
  input: './openapi.json',
  metadataInput: './schema-metadata.json',
})
```

With only one local file, the other schema source is loaded remotely and `url`/`project` are required.

## Guardrails

1. Keep `schemaApiKey` build-time only; it must not appear in generated virtual modules.
2. Configure `runtimeApiKey` only when the key is safe to emit into runtime/client code.
3. Do not hand-write replacement schema or plugin virtual modules; fix generator input/config instead.
4. Use the generated `schema` and `monospacePlugin` together in the same store.
5. Use `rstore-monospace` for OpenAPI, REST, query, and mutation behavior.
6. Use `rstore-vue` for component query/form/cache patterns.
````

- Previous: [rstore-vite-directus](https://syn4pse.dev/terminal/rstore-vite-directus.md)
- Next: [astronomer-data](https://syn4pse.dev/terminal/astronomer-data.md)
- [Terminal](https://syn4pse.dev/terminal.md)
- [Suggest a change](mailto:terminal@syn4pse.dev?subject=Terminal%20suggestion)
