@noy-db/in-nuxt 0.1.0-pre.10

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vLannaAi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # @noy-db/in-nuxt
2
+
3
+ > Nuxt 4 module for [noy-db](https://github.com/vLannaAi/noy-db) — auto-imports, SSR-safe runtime plugin, and the `@noy-db/in-pinia` bridge.
4
+
5
+ **Nuxt 4+ exclusive.** For Nuxt 3, use `@noy-db/in-vue` and `@noy-db/in-pinia` directly with a hand-written plugin.
6
+
7
+ ```bash
8
+ pnpm add @noy-db/in-nuxt @noy-db/hub @noy-db/in-pinia @noy-db/in-vue
9
+ # pick an adapter for your environment:
10
+ pnpm add @noy-db/to-browser-idb # localStorage / IndexedDB
11
+ pnpm add @noy-db/to-file # local disk / USB (Node only)
12
+ pnpm add @noy-db/to-aws-dynamo # AWS DynamoDB
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ // nuxt.config.ts
19
+ export default defineNuxtConfig({
20
+ modules: ['@noy-db/in-nuxt'],
21
+
22
+ noydb: {
23
+ adapter: 'browser',
24
+ pinia: true,
25
+ sync: { adapter: 'dynamo', table: 'noydb-prod', region: 'ap-southeast-1' },
26
+ auth: { mode: 'biometric', sessionTimeout: '15m' },
27
+ },
28
+ })
29
+ ```
30
+
31
+ After installing the module, every component in your app gets these auto-imported:
32
+
33
+ | From `@noy-db/in-vue` | From `@noy-db/in-pinia` (when `pinia: true`, default) |
34
+ |-----------------------------|----------------------------------------------------|
35
+ | `useNoydb()` | `defineNoydbStore()` |
36
+ | `useCollection<T>()` | `createNoydbPiniaPlugin()` |
37
+ | `useSync()` | `setActiveNoydb()` |
38
+ | | `getActiveNoydb()` |
39
+
40
+ ## Bootstrap
41
+
42
+ The module exposes your typed config through `useRuntimeConfig().public.noydb` but it does **not** auto-instantiate the Noydb instance. You decide when and how to construct it — typically in a custom Nuxt plugin or your first protected page:
43
+
44
+ ```ts
45
+ // plugins/noydb.client.ts
46
+ import { createNoydb } from '@noy-db/hub'
47
+ import { browserIdbStore } from '@noy-db/to-browser-idb'
48
+ import { setActiveNoydb } from '@noy-db/in-pinia'
49
+
50
+ export default defineNuxtPlugin(async () => {
51
+ const config = useRuntimeConfig().public.noydb
52
+
53
+ const db = await createNoydb({
54
+ adapter: browser({ prefix: 'my-app' }),
55
+ user: 'owner',
56
+ secret: () => promptUserForPassphrase(),
57
+ })
58
+
59
+ setActiveNoydb(db)
60
+ })
61
+ ```
62
+
63
+ The reason it's not automatic: `createNoydb` requires a passphrase callback that can't be serialized through Nuxt's runtime config. Eager auto-instantiation is a future enhancement, gated on a real consumer signing off on the bootstrap UX.
64
+
65
+ ## Use it in a component
66
+
67
+ Once `setActiveNoydb` has been called, every Pinia store can transparently use NOYDB:
68
+
69
+ ```ts
70
+ // stores/invoices.ts
71
+ export const useInvoices = defineNoydbStore<Invoice>('invoices', {
72
+ compartment: 'C101',
73
+ })
74
+ ```
75
+
76
+ ```vue
77
+ <!-- pages/invoices.vue -->
78
+ <script setup lang="ts">
79
+ const invoices = useInvoices()
80
+ await invoices.$ready
81
+
82
+ const open = computed(() =>
83
+ invoices.query()
84
+ .where('status', '==', 'open')
85
+ .orderBy('dueDate')
86
+ .toArray()
87
+ )
88
+ </script>
89
+
90
+ <template>
91
+ <ul>
92
+ <li v-for="inv in open" :key="inv.id">
93
+ {{ inv.client }} — {{ inv.amount }}
94
+ </li>
95
+ </ul>
96
+ </template>
97
+ ```
98
+
99
+ `defineNoydbStore`, `useInvoices`, `computed`, etc. are all auto-imported — no `import` lines needed.
100
+
101
+ ## SSR safety
102
+
103
+ The module's runtime plugin is registered with `mode: 'client'`. Nuxt **never** loads it on the server, so your server bundle never imports any code that touches `crypto.subtle`. During SSR:
104
+
105
+ - `useCollection()` returns an empty reactive ref (templates render skeleton state)
106
+ - `defineNoydbStore` stores hydrate to their initial state
107
+ - No keys, no decryption, no crypto API calls reach the server
108
+
109
+ A planned CI bundle assertion will verify this property automatically by grepping the built nitro output for forbidden symbols.
110
+
111
+ ## Module options
112
+
113
+ | Option | Type | Default | Description |
114
+ |--------------|-----------------------------------------------------|---------------|-------------|
115
+ | `adapter` | `'browser' \| 'memory' \| 'file' \| 'dynamo' \| 's3'` | — | Hint for which built-in adapter to use. Just metadata — your bootstrap code constructs the actual adapter. |
116
+ | `pinia` | `boolean` | `true` | Auto-import the `@noy-db/in-pinia` helpers. Set to `false` if you don't use Pinia. |
117
+ | `sync` | `{ adapter, table, region, bucket, mode }` | — | Optional sync configuration metadata, exposed via `runtimeConfig.public.noydb.sync`. |
118
+ | `auth` | `{ mode, sessionTimeout }` | — | Optional auth metadata. The actual passphrase callback lives in your bootstrap code. |
119
+ | `devtools` | `boolean` | `true` | Enable the (planned) devtools tab. Currently a passthrough — the tab itself is a future enhancement. |
120
+
121
+ Every field is fully typed. Open `nuxt.config.ts` in your IDE and you'll get autocomplete on `noydb:`.
122
+
123
+ ## What's NOT yet included
124
+
125
+ The following features are tracked as future follow-ups:
126
+
127
+ - **Devtools tab via `@nuxt/devtools-kit`** — compartment tree, sync status, ledger tail, query playground
128
+ - **Optional Nitro server proxy** at `/api/_noydb/[...]` for behind-the-scenes auth gating
129
+ - **Optional Nitro scheduled backup task** for encrypted off-site backups
130
+ - **`nuxi noydb <cmd>` CLI extension**
131
+ - **Eager Noydb instantiation** — once a real consumer signs off on the bootstrap UX
132
+
133
+ The module ships the foundation: typed options, auto-imports, and the SSR-safe client plugin. That's the load-bearing infrastructure; everything above can be added incrementally without breaking existing apps.
134
+
135
+ ## Status
136
+
137
+ See [ROADMAP.md](../../ROADMAP.md) for the forward plan.
138
+
139
+ ## License
140
+
141
+ MIT © vLannaAi
@@ -0,0 +1,149 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ /**
4
+ * Nuxt 4 module for noy-db.
5
+ *
6
+ * Built with `@nuxt/kit`'s `defineNuxtModule`. Targets Nuxt 4+ exclusively
7
+ * (no Nuxt 3 compatibility shim — Nuxt 3 users should consume `@noy-db/vue`
8
+ * and `@noy-db/pinia` directly with a hand-written plugin).
9
+ *
10
+ * Module responsibilities:
11
+ *
12
+ * 1. Auto-import the @noy-db/in-vue composables (`useNoydb`, `useCollection`,
13
+ * `useSync`) and, when `pinia: true` (default), the @noy-db/in-pinia
14
+ * helpers (`defineNoydbStore`, `createNoydbPiniaPlugin`, `setActiveNoydb`).
15
+ *
16
+ * 2. Expose the user's `noydb:` config through `runtimeConfig.public.noydb`
17
+ * so the runtime plugin and downstream composables can read it
18
+ * without re-parsing nuxt.config.ts.
19
+ *
20
+ * 3. Register a CLIENT-ONLY runtime plugin (`runtime/plugin.client.ts`)
21
+ * that sets up the noydb context. The server bundle is never touched —
22
+ * this is the load-bearing SSR-safety property.
23
+ *
24
+ * Deferred to follow-up issues:
25
+ * - Devtools tab via @nuxt/devtools-kit
26
+ * - Optional Nitro server proxy (`/api/_noydb/...`)
27
+ * - Optional Nitro scheduled backup task
28
+ * - `nuxi noydb` CLI extension
29
+ * - Eager Noydb instantiation (requires the user's passphrase callback,
30
+ * which can't be serialized through runtime config — better to let
31
+ * users call setActiveNoydb from their own setup file)
32
+ */
33
+ /**
34
+ * Configuration shape for the `noydb:` key in `nuxt.config.ts`.
35
+ *
36
+ * Every field is optional. The defaults give a reasonable bootstrap for
37
+ * a typical Vue/Nuxt app — Pinia helpers auto-imported, `to-browser-idb`
38
+ * as the default store. Users override by passing the relevant fields.
39
+ */
40
+ interface ModuleOptions {
41
+ /**
42
+ * Which built-in store package to prefer. The runtime plugin reads this
43
+ * and picks the matching store. Defaults to `'to-browser-idb'` because
44
+ * Nuxt apps run in the browser at runtime.
45
+ *
46
+ * Note: this is just a HINT. Users can always construct their own
47
+ * store and pass it to `createNoydb()` directly — this option exists
48
+ * to keep simple cases simple.
49
+ */
50
+ store?: 'to-browser-idb' | 'to-browser-local' | 'to-memory' | 'to-file' | 'to-aws-dynamo' | 'to-aws-s3';
51
+ /**
52
+ * Auto-import the @noy-db/pinia helpers (`defineNoydbStore`,
53
+ * `createNoydbPiniaPlugin`, `setActiveNoydb`). Defaults to `true`
54
+ * because Pinia is the recommended state layer for.
55
+ *
56
+ * Set to `false` if you only want the bare @noy-db/vue composables
57
+ * (saves ~3 KB from the auto-import metadata).
58
+ */
59
+ pinia?: boolean;
60
+ /**
61
+ * Optional sync configuration. Currently a passthrough — the runtime
62
+ * plugin reads it from `runtimeConfig.public.noydb.sync` and the user
63
+ * is responsible for wiring it into their `createNoydb()` call.
64
+ */
65
+ sync?: {
66
+ store?: 'to-aws-dynamo' | 'to-aws-s3';
67
+ table?: string;
68
+ region?: string;
69
+ bucket?: string;
70
+ mode?: 'auto' | 'manual' | 'off';
71
+ };
72
+ /**
73
+ * Optional auth configuration metadata. Same passthrough pattern as
74
+ * `sync`. The user provides the actual passphrase / biometric callback
75
+ * in their own setup file.
76
+ */
77
+ auth?: {
78
+ mode?: 'passphrase' | 'biometric' | 'session';
79
+ sessionTimeout?: string;
80
+ };
81
+ /**
82
+ * Whether to enable the (planned) devtools tab in `nuxi dev`. Currently
83
+ * a passthrough — the devtools tab itself ships in a follow-up.
84
+ */
85
+ devtools?: boolean;
86
+ /**
87
+ * Optional REST API integration. When `enabled: true`, mounts a catch-all
88
+ * Nitro server handler at `basePath/**` using `@noy-db/in-rest`.
89
+ *
90
+ * The handler is scaffold-level: it reads `event.context.noydbStore` which
91
+ * a separate Nitro plugin must populate. spec follow-up for the store
92
+ * wiring. The module simply registers the route here.
93
+ */
94
+ rest?: {
95
+ /** Enable the REST API server handler. Default: false. */
96
+ enabled?: boolean;
97
+ /** Base path for all REST routes. Default: '/api/noydb'. */
98
+ basePath?: string;
99
+ /** User ID forwarded to createRestHandler. */
100
+ user?: string;
101
+ /** Session TTL in seconds. Default: 900. */
102
+ ttlSeconds?: number;
103
+ };
104
+ }
105
+ /**
106
+ * The exported Nuxt module factory.
107
+ *
108
+ * Test-friendly: `defineNuxtModule` returns a NuxtModule object whose
109
+ * `.meta`, `.getOptions`, and `.setup` fields can be inspected without a
110
+ * full Nuxt build. Unit tests use those introspection points instead of
111
+ * spinning up `@nuxt/test-utils`.
112
+ */
113
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
114
+
115
+ /**
116
+ * Module augmentation so the `noydb:` config key in `nuxt.config.ts`
117
+ * is fully typed and autocompleted in the IDE.
118
+ *
119
+ * The augmentation is a side-effect of importing the module — once a
120
+ * project adds `'@noy-db/in-nuxt'` to its `modules` array, TypeScript picks
121
+ * up the typed `noydb` option without requiring an explicit import.
122
+ */
123
+ declare module '@nuxt/schema' {
124
+ interface NuxtConfig {
125
+ noydb?: ModuleOptions;
126
+ }
127
+ interface NuxtOptions {
128
+ noydb?: ModuleOptions;
129
+ }
130
+ interface PublicRuntimeConfig {
131
+ noydb?: ModuleOptions;
132
+ }
133
+ }
134
+
135
+ /**
136
+ * @noy-db/nuxt — Nuxt 4 module for noy-db.
137
+ *
138
+ * Public API:
139
+ * - default export: the Nuxt module factory
140
+ * - `ModuleOptions` type: shape of the `noydb:` key in `nuxt.config.ts`
141
+ *
142
+ * The module auto-imports the @noy-db/vue and (optionally) @noy-db/pinia
143
+ * composables, exposes the user's options through Nuxt's runtime config,
144
+ * and registers a CLIENT-ONLY runtime plugin so the SSR bundle never
145
+ * touches `crypto.subtle`. Eager Noydb instantiation is intentionally
146
+ * left to user code — see the README "Bootstrap" section.
147
+ */
148
+
149
+ export { type ModuleOptions, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ // src/module.ts
2
+ import { defineNuxtModule, addImports, addPlugin, addServerHandler, createResolver } from "@nuxt/kit";
3
+ var module_default = defineNuxtModule({
4
+ meta: {
5
+ name: "@noy-db/in-nuxt",
6
+ configKey: "noydb",
7
+ compatibility: {
8
+ // Nuxt 4 only — see the module-level docstring for the rationale.
9
+ nuxt: "^4.0.0"
10
+ }
11
+ },
12
+ defaults: {
13
+ store: "to-browser-idb",
14
+ pinia: true,
15
+ devtools: true
16
+ },
17
+ setup(options, nuxt) {
18
+ const resolver = createResolver(import.meta.url);
19
+ nuxt.options.runtimeConfig.public.noydb = {
20
+ // The cast is necessary because Nuxt's runtimeConfig type is
21
+ // structurally `Record<string, any>` — modules are expected to
22
+ // own their own typing via module augmentation (which we do
23
+ // below).
24
+ ...nuxt.options.runtimeConfig.public.noydb ?? {},
25
+ ...options
26
+ };
27
+ addImports([
28
+ { name: "useNoydb", from: "@noy-db/in-vue" },
29
+ { name: "useCollection", from: "@noy-db/in-vue" },
30
+ { name: "useSync", from: "@noy-db/in-vue" }
31
+ ]);
32
+ if (options.pinia !== false) {
33
+ addImports([
34
+ { name: "defineNoydbStore", from: "@noy-db/in-pinia" },
35
+ { name: "createNoydbPiniaPlugin", from: "@noy-db/in-pinia" },
36
+ { name: "setActiveNoydb", from: "@noy-db/in-pinia" },
37
+ { name: "getActiveNoydb", from: "@noy-db/in-pinia" }
38
+ ]);
39
+ }
40
+ addPlugin({
41
+ src: resolver.resolve("./runtime/plugin.client.js"),
42
+ mode: "client"
43
+ });
44
+ if (options.rest?.enabled) {
45
+ const basePath = options.rest.basePath ?? "/api/noydb";
46
+ addServerHandler({
47
+ route: `${basePath}/**`,
48
+ handler: resolver.resolve("./runtime/rest")
49
+ });
50
+ }
51
+ }
52
+ });
53
+
54
+ // src/index.ts
55
+ var index_default = module_default;
56
+ export {
57
+ index_default as default
58
+ };
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/module.ts","../src/index.ts"],"sourcesContent":["/**\n * Nuxt 4 module for noy-db.\n *\n * Built with `@nuxt/kit`'s `defineNuxtModule`. Targets Nuxt 4+ exclusively\n * (no Nuxt 3 compatibility shim — Nuxt 3 users should consume `@noy-db/vue`\n * and `@noy-db/pinia` directly with a hand-written plugin).\n *\n * Module responsibilities:\n *\n * 1. Auto-import the @noy-db/in-vue composables (`useNoydb`, `useCollection`,\n * `useSync`) and, when `pinia: true` (default), the @noy-db/in-pinia\n * helpers (`defineNoydbStore`, `createNoydbPiniaPlugin`, `setActiveNoydb`).\n *\n * 2. Expose the user's `noydb:` config through `runtimeConfig.public.noydb`\n * so the runtime plugin and downstream composables can read it\n * without re-parsing nuxt.config.ts.\n *\n * 3. Register a CLIENT-ONLY runtime plugin (`runtime/plugin.client.ts`)\n * that sets up the noydb context. The server bundle is never touched —\n * this is the load-bearing SSR-safety property.\n *\n * Deferred to follow-up issues:\n * - Devtools tab via @nuxt/devtools-kit\n * - Optional Nitro server proxy (`/api/_noydb/...`)\n * - Optional Nitro scheduled backup task\n * - `nuxi noydb` CLI extension\n * - Eager Noydb instantiation (requires the user's passphrase callback,\n * which can't be serialized through runtime config — better to let\n * users call setActiveNoydb from their own setup file)\n */\n\nimport { defineNuxtModule, addImports, addPlugin, addServerHandler, createResolver } from '@nuxt/kit'\n\n/**\n * Configuration shape for the `noydb:` key in `nuxt.config.ts`.\n *\n * Every field is optional. The defaults give a reasonable bootstrap for\n * a typical Vue/Nuxt app — Pinia helpers auto-imported, `to-browser-idb`\n * as the default store. Users override by passing the relevant fields.\n */\nexport interface ModuleOptions {\n /**\n * Which built-in store package to prefer. The runtime plugin reads this\n * and picks the matching store. Defaults to `'to-browser-idb'` because\n * Nuxt apps run in the browser at runtime.\n *\n * Note: this is just a HINT. Users can always construct their own\n * store and pass it to `createNoydb()` directly — this option exists\n * to keep simple cases simple.\n */\n store?: 'to-browser-idb' | 'to-browser-local' | 'to-memory' | 'to-file' | 'to-aws-dynamo' | 'to-aws-s3'\n\n /**\n * Auto-import the @noy-db/pinia helpers (`defineNoydbStore`,\n * `createNoydbPiniaPlugin`, `setActiveNoydb`). Defaults to `true`\n * because Pinia is the recommended state layer for.\n *\n * Set to `false` if you only want the bare @noy-db/vue composables\n * (saves ~3 KB from the auto-import metadata).\n */\n pinia?: boolean\n\n /**\n * Optional sync configuration. Currently a passthrough — the runtime\n * plugin reads it from `runtimeConfig.public.noydb.sync` and the user\n * is responsible for wiring it into their `createNoydb()` call.\n */\n sync?: {\n store?: 'to-aws-dynamo' | 'to-aws-s3'\n table?: string\n region?: string\n bucket?: string\n mode?: 'auto' | 'manual' | 'off'\n }\n\n /**\n * Optional auth configuration metadata. Same passthrough pattern as\n * `sync`. The user provides the actual passphrase / biometric callback\n * in their own setup file.\n */\n auth?: {\n mode?: 'passphrase' | 'biometric' | 'session'\n sessionTimeout?: string\n }\n\n /**\n * Whether to enable the (planned) devtools tab in `nuxi dev`. Currently\n * a passthrough — the devtools tab itself ships in a follow-up.\n */\n devtools?: boolean\n\n /**\n * Optional REST API integration. When `enabled: true`, mounts a catch-all\n * Nitro server handler at `basePath/**` using `@noy-db/in-rest`.\n *\n * The handler is scaffold-level: it reads `event.context.noydbStore` which\n * a separate Nitro plugin must populate. spec follow-up for the store\n * wiring. The module simply registers the route here.\n */\n rest?: {\n /** Enable the REST API server handler. Default: false. */\n enabled?: boolean\n /** Base path for all REST routes. Default: '/api/noydb'. */\n basePath?: string\n /** User ID forwarded to createRestHandler. */\n user?: string\n /** Session TTL in seconds. Default: 900. */\n ttlSeconds?: number\n }\n}\n\n/**\n * The exported Nuxt module factory.\n *\n * Test-friendly: `defineNuxtModule` returns a NuxtModule object whose\n * `.meta`, `.getOptions`, and `.setup` fields can be inspected without a\n * full Nuxt build. Unit tests use those introspection points instead of\n * spinning up `@nuxt/test-utils`.\n */\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@noy-db/in-nuxt',\n configKey: 'noydb',\n compatibility: {\n // Nuxt 4 only — see the module-level docstring for the rationale.\n nuxt: '^4.0.0',\n },\n },\n\n defaults: {\n store: 'to-browser-idb',\n pinia: true,\n devtools: true,\n },\n\n setup(options, nuxt) {\n const resolver = createResolver(import.meta.url)\n\n // ─── 1. Expose the user's options to runtime via runtimeConfig ───\n //\n // We stash the typed options under `runtimeConfig.public.noydb` so\n // the client plugin (and any downstream composable) can read them\n // without re-parsing nuxt.config.ts. `public` is required so the\n // values reach the browser bundle — but EVERY field is metadata\n // (store name, table name, etc.), NEVER a secret. Passphrases\n // and tokens are still provided at runtime via user callbacks.\n nuxt.options.runtimeConfig.public.noydb = {\n // The cast is necessary because Nuxt's runtimeConfig type is\n // structurally `Record<string, any>` — modules are expected to\n // own their own typing via module augmentation (which we do\n // below).\n ...(nuxt.options.runtimeConfig.public.noydb ?? {}),\n ...options,\n }\n\n // ─── 2. Auto-imports for @noy-db/vue composables ────────────────\n //\n // These are the composables shipped by @noy-db/vue. Importing\n // them automatically removes one line of boilerplate per component.\n addImports([\n { name: 'useNoydb', from: '@noy-db/in-vue' },\n { name: 'useCollection', from: '@noy-db/in-vue' },\n { name: 'useSync', from: '@noy-db/in-vue' },\n ])\n\n // ─── 3. Auto-imports for @noy-db/pinia (opt-out) ────────────────\n //\n // Most users want the Pinia helpers — `defineNoydbStore` is the\n // headline API. We default to enabling them and let users\n // opt out via `pinia: false` if they're not using Pinia at all.\n if (options.pinia !== false) {\n addImports([\n { name: 'defineNoydbStore', from: '@noy-db/in-pinia' },\n { name: 'createNoydbPiniaPlugin', from: '@noy-db/in-pinia' },\n { name: 'setActiveNoydb', from: '@noy-db/in-pinia' },\n { name: 'getActiveNoydb', from: '@noy-db/in-pinia' },\n ])\n }\n\n // ─── 4. Register the client-only runtime plugin ─────────────────\n //\n // mode: 'client' is the LOAD-BEARING SSR-safety guarantee. Nuxt\n // skips this plugin entirely on the server, so the server bundle\n // never imports any code that touches `crypto.subtle`. The CI\n // bundle assertion (planned for a follow-up) verifies this by\n // grepping the built nitro output for forbidden symbols.\n //\n // The path resolves to the COMPILED runtime file in `dist/runtime/`.\n // tsup builds this as a separate entry alongside the module index.\n addPlugin({\n src: resolver.resolve('./runtime/plugin.client.js'),\n mode: 'client',\n })\n\n // ─── 5. REST API server handler (opt-in) ────────────────────────\n //\n // When `rest.enabled: true`, mount a catch-all Nitro server handler\n // at `basePath/**`. The handler delegates to `@noy-db/in-rest` via\n // the nitroAdapter. Store wiring (populating event.context.noydbStore)\n // is a follow-up concern tracked in #273.\n if (options.rest?.enabled) {\n const basePath = options.rest.basePath ?? '/api/noydb'\n addServerHandler({\n route: `${basePath}/**`,\n handler: resolver.resolve('./runtime/rest'),\n })\n }\n },\n})\n\n/**\n * Module augmentation so the `noydb:` config key in `nuxt.config.ts`\n * is fully typed and autocompleted in the IDE.\n *\n * The augmentation is a side-effect of importing the module — once a\n * project adds `'@noy-db/in-nuxt'` to its `modules` array, TypeScript picks\n * up the typed `noydb` option without requiring an explicit import.\n */\ndeclare module '@nuxt/schema' {\n interface NuxtConfig {\n noydb?: ModuleOptions\n }\n interface NuxtOptions {\n noydb?: ModuleOptions\n }\n interface PublicRuntimeConfig {\n noydb?: ModuleOptions\n }\n}\n","/**\n * @noy-db/nuxt — Nuxt 4 module for noy-db.\n *\n * Public API:\n * - default export: the Nuxt module factory\n * - `ModuleOptions` type: shape of the `noydb:` key in `nuxt.config.ts`\n *\n * The module auto-imports the @noy-db/vue and (optionally) @noy-db/pinia\n * composables, exposes the user's options through Nuxt's runtime config,\n * and registers a CLIENT-ONLY runtime plugin so the SSR bundle never\n * touches `crypto.subtle`. Eager Noydb instantiation is intentionally\n * left to user code — see the README \"Bootstrap\" section.\n */\n\nimport noydbModule, { type ModuleOptions } from './module.js'\n\nexport default noydbModule\nexport type { ModuleOptions }\n"],"mappings":";AA+BA,SAAS,kBAAkB,YAAY,WAAW,kBAAkB,sBAAsB;AAwF1F,IAAO,iBAAQ,iBAAgC;AAAA,EAC7C,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,WAAW;AAAA,IACX,eAAe;AAAA;AAAA,MAEb,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AAAA,EAEA,MAAM,SAAS,MAAM;AACnB,UAAM,WAAW,eAAe,YAAY,GAAG;AAU/C,SAAK,QAAQ,cAAc,OAAO,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,MAKxC,GAAI,KAAK,QAAQ,cAAc,OAAO,SAAS,CAAC;AAAA,MAChD,GAAG;AAAA,IACL;AAMA,eAAW;AAAA,MACT,EAAE,MAAM,YAAY,MAAM,iBAAiB;AAAA,MAC3C,EAAE,MAAM,iBAAiB,MAAM,iBAAiB;AAAA,MAChD,EAAE,MAAM,WAAW,MAAM,iBAAiB;AAAA,IAC5C,CAAC;AAOD,QAAI,QAAQ,UAAU,OAAO;AAC3B,iBAAW;AAAA,QACT,EAAE,MAAM,oBAAoB,MAAM,mBAAmB;AAAA,QACrD,EAAE,MAAM,0BAA0B,MAAM,mBAAmB;AAAA,QAC3D,EAAE,MAAM,kBAAkB,MAAM,mBAAmB;AAAA,QACnD,EAAE,MAAM,kBAAkB,MAAM,mBAAmB;AAAA,MACrD,CAAC;AAAA,IACH;AAYA,cAAU;AAAA,MACR,KAAK,SAAS,QAAQ,4BAA4B;AAAA,MAClD,MAAM;AAAA,IACR,CAAC;AAQD,QAAI,QAAQ,MAAM,SAAS;AACzB,YAAM,WAAW,QAAQ,KAAK,YAAY;AAC1C,uBAAiB;AAAA,QACf,OAAO,GAAG,QAAQ;AAAA,QAClB,SAAS,SAAS,QAAQ,gBAAgB;AAAA,MAC5C,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AChMD,IAAO,gBAAQ;","names":[]}
@@ -0,0 +1,29 @@
1
+ import * as nuxt_app from 'nuxt/app';
2
+
3
+ /**
4
+ * Client-only runtime plugin for the @noy-db/nuxt module.
5
+ *
6
+ * This file is registered with `mode: 'client'` so Nuxt NEVER imports it
7
+ * into the server bundle. Every line below assumes a browser context.
8
+ *
9
+ * The plugin's job today:
10
+ *
11
+ * 1. Read the user's noydb config from `useRuntimeConfig().public.noydb`
12
+ * and stash it on the Nuxt app context for later access via the
13
+ * auto-imported `useRuntimeConfig()` composable.
14
+ *
15
+ * 2. NOT auto-instantiate Noydb. The library requires a passphrase
16
+ * callback to derive keys, and that callback can't be serialized
17
+ * through runtime config. Users call `setActiveNoydb(instance)`
18
+ * themselves from their app's setup file (the README documents
19
+ * the recommended pattern).
20
+ *
21
+ * Future work:
22
+ * - Read a user-supplied `bootstrap` callback from a Nuxt provide()
23
+ * and call it here to construct Noydb automatically when possible
24
+ * - Wire the devtools tab via @nuxt/devtools-kit
25
+ * - Surface ledger / sync status on the Nuxt app context
26
+ */
27
+ declare const _default: nuxt_app.Plugin<Record<string, unknown>> & nuxt_app.ObjectPlugin<Record<string, unknown>>;
28
+
29
+ export { _default as default };
@@ -0,0 +1,17 @@
1
+ // src/runtime/plugin.client.ts
2
+ import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
3
+ var plugin_client_default = defineNuxtPlugin({
4
+ name: "noy-db:client",
5
+ enforce: "pre",
6
+ setup(_nuxtApp) {
7
+ const config = useRuntimeConfig().public.noydb;
8
+ if (config) {
9
+ ;
10
+ globalThis.__NOYDB_NUXT_CONFIG__ = config;
11
+ }
12
+ }
13
+ });
14
+ export {
15
+ plugin_client_default as default
16
+ };
17
+ //# sourceMappingURL=plugin.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/runtime/plugin.client.ts"],"sourcesContent":["/**\n * Client-only runtime plugin for the @noy-db/nuxt module.\n *\n * This file is registered with `mode: 'client'` so Nuxt NEVER imports it\n * into the server bundle. Every line below assumes a browser context.\n *\n * The plugin's job today:\n *\n * 1. Read the user's noydb config from `useRuntimeConfig().public.noydb`\n * and stash it on the Nuxt app context for later access via the\n * auto-imported `useRuntimeConfig()` composable.\n *\n * 2. NOT auto-instantiate Noydb. The library requires a passphrase\n * callback to derive keys, and that callback can't be serialized\n * through runtime config. Users call `setActiveNoydb(instance)`\n * themselves from their app's setup file (the README documents\n * the recommended pattern).\n *\n * Future work:\n * - Read a user-supplied `bootstrap` callback from a Nuxt provide()\n * and call it here to construct Noydb automatically when possible\n * - Wire the devtools tab via @nuxt/devtools-kit\n * - Surface ledger / sync status on the Nuxt app context\n */\n\nimport { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'\n\nexport default defineNuxtPlugin({\n name: 'noy-db:client',\n enforce: 'pre',\n setup(_nuxtApp) {\n // Read the typed module options the user passed in nuxt.config.ts.\n // The cast is safe because @noy-db/nuxt's module file augments\n // PublicRuntimeConfig with the noydb shape (see module.ts).\n const config = useRuntimeConfig().public.noydb\n\n // Surface the config on `globalThis` so non-Vue contexts (e.g.,\n // a custom error reporter or a Web Worker) can read it. This is\n // intentionally on `globalThis` rather than the Nuxt provide()\n // map so the helper packages stay framework-agnostic.\n if (config) {\n ;(globalThis as { __NOYDB_NUXT_CONFIG__?: unknown }).__NOYDB_NUXT_CONFIG__ = config\n }\n\n // No return value — the plugin's only side effect is the global\n // assignment above. Future versions will return `provide` keys\n // for first-class composable access.\n },\n})\n"],"mappings":";AAyBA,SAAS,kBAAkB,wBAAwB;AAEnD,IAAO,wBAAQ,iBAAiB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,UAAU;AAId,UAAM,SAAS,iBAAiB,EAAE,OAAO;AAMzC,QAAI,QAAQ;AACV;AAAC,MAAC,WAAmD,wBAAwB;AAAA,IAC/E;AAAA,EAKF;AACF,CAAC;","names":[]}
@@ -0,0 +1,21 @@
1
+ import * as h3 from 'h3';
2
+
3
+ /**
4
+ * Nitro catch-all server handler for the opt-in REST API integration.
5
+ *
6
+ * This file is registered as a server handler entry point by the module when
7
+ * `rest.enabled: true`. It bridges Nitro's H3 event model to
8
+ * `@noy-db/in-rest`'s `NoydbRestHandler` via the `nitroAdapter`.
9
+ *
10
+ * **Store wiring (scaffold note):**
11
+ * The handler reads the noydb store from `event.context.noydbStore`. A
12
+ * separate Nitro server plugin must populate this before requests reach this
13
+ * handler. That wiring is deferred to the follow-up PR.
14
+ *
15
+ * The handler is intentionally stateless at module scope — the lazy `_handler`
16
+ * singleton is reset on each cold-start (Nitro worker restart), which matches
17
+ * the expected lifecycle.
18
+ */
19
+ declare const _default: h3.EventHandler<h3.EventHandlerRequest, Promise<Response>>;
20
+
21
+ export { _default as default };
@@ -0,0 +1,52 @@
1
+ // src/runtime/rest.ts
2
+ import { defineEventHandler, getRequestURL, readBody } from "h3";
3
+ import { createRestHandler } from "@noy-db/in-rest";
4
+ import { nitroAdapter } from "@noy-db/in-rest/nitro";
5
+ var _handler = null;
6
+ function getHandler(store, user, ttlSeconds, basePath) {
7
+ if (!_handler) {
8
+ _handler = createRestHandler({ store, user, ttlSeconds, basePath });
9
+ }
10
+ return _handler;
11
+ }
12
+ var rest_default = defineEventHandler(async (event) => {
13
+ const ctx = event.context;
14
+ const config = ctx.nitro?.runtimeConfig?.public?.noydb?.rest ?? ctx.runtimeConfig?.public?.noydb?.rest ?? {};
15
+ const store = ctx.noydbStore;
16
+ if (!store) {
17
+ return new Response(
18
+ JSON.stringify({ error: "noydb_store_not_configured" }),
19
+ { status: 500, headers: { "content-type": "application/json" } }
20
+ );
21
+ }
22
+ const restConfig = config;
23
+ const handler = getHandler(
24
+ store,
25
+ restConfig.user ?? "api",
26
+ restConfig.ttlSeconds ?? 900,
27
+ restConfig.basePath ?? "/api/noydb"
28
+ );
29
+ const url = getRequestURL(event);
30
+ const method = (event.method ?? "GET").toUpperCase();
31
+ let body = null;
32
+ if (method !== "GET" && method !== "HEAD" && method !== "DELETE") {
33
+ try {
34
+ body = await readBody(event);
35
+ } catch {
36
+ body = null;
37
+ }
38
+ }
39
+ const h3Adapter = nitroAdapter(handler);
40
+ return h3Adapter({
41
+ method,
42
+ path: url.pathname + url.search,
43
+ // nitroAdapter's H3Event accepts Headers | Record<string,string> — pass
44
+ // the Headers instance directly to avoid lossy serialization.
45
+ headers: event.headers,
46
+ _body: body
47
+ });
48
+ });
49
+ export {
50
+ rest_default as default
51
+ };
52
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/runtime/rest.ts"],"sourcesContent":["/**\n * Nitro catch-all server handler for the opt-in REST API integration.\n *\n * This file is registered as a server handler entry point by the module when\n * `rest.enabled: true`. It bridges Nitro's H3 event model to\n * `@noy-db/in-rest`'s `NoydbRestHandler` via the `nitroAdapter`.\n *\n * **Store wiring (scaffold note):**\n * The handler reads the noydb store from `event.context.noydbStore`. A\n * separate Nitro server plugin must populate this before requests reach this\n * handler. That wiring is deferred to the follow-up PR.\n *\n * The handler is intentionally stateless at module scope — the lazy `_handler`\n * singleton is reset on each cold-start (Nitro worker restart), which matches\n * the expected lifecycle.\n */\n\nimport { defineEventHandler, getRequestURL, readBody } from 'h3'\nimport type { H3Event } from 'h3'\nimport { createRestHandler } from '@noy-db/in-rest'\nimport { nitroAdapter } from '@noy-db/in-rest/nitro'\nimport type { NoydbRestHandler } from '@noy-db/in-rest'\nimport type { NoydbStore } from '@noy-db/hub'\n\nlet _handler: NoydbRestHandler | null = null\n\nfunction getHandler(\n store: NoydbStore,\n user: string,\n ttlSeconds: number,\n basePath: string,\n): NoydbRestHandler {\n if (!_handler) {\n _handler = createRestHandler({ store, user, ttlSeconds, basePath })\n }\n return _handler\n}\n\nexport default defineEventHandler(async (event: H3Event) => {\n // Read REST config from Nitro's public runtime config. Nitro stores it at\n // `event.context.nitro.runtimeConfig` (the canonical location — confirmed\n // by reading nitropack's config.mjs). The fallback on\n // `event.context.runtimeConfig` covers bespoke setups that might inject\n // config at that alternate key.\n const ctx = event.context as {\n nitro?: { runtimeConfig?: { public?: { noydb?: { rest?: Record<string, unknown> } } } }\n runtimeConfig?: { public?: { noydb?: { rest?: Record<string, unknown> } } }\n noydbStore?: NoydbStore\n }\n const config =\n ctx.nitro?.runtimeConfig?.public?.noydb?.rest ??\n ctx.runtimeConfig?.public?.noydb?.rest ??\n {}\n\n // The store must be provided by a separate Nitro server plugin that\n // creates and populates `event.context.noydbStore` before this handler\n // runs. See module docstring above.\n const store = ctx.noydbStore\n\n if (!store) {\n return new Response(\n JSON.stringify({ error: 'noydb_store_not_configured' }),\n { status: 500, headers: { 'content-type': 'application/json' } },\n )\n }\n\n const restConfig = config as {\n user?: string\n ttlSeconds?: number\n basePath?: string\n }\n const handler = getHandler(\n store,\n restConfig.user ?? 'api',\n restConfig.ttlSeconds ?? 900,\n restConfig.basePath ?? '/api/noydb',\n )\n\n // Build the adapter-friendly event shape. We pass event.headers directly\n // because `nitroAdapter` already handles both `Headers` instances and\n // plain `Record<string, string>` objects.\n const url = getRequestURL(event)\n const method = (event.method ?? 'GET').toUpperCase()\n\n let body: unknown = null\n if (method !== 'GET' && method !== 'HEAD' && method !== 'DELETE') {\n try { body = await readBody(event) } catch { body = null }\n }\n\n const h3Adapter = nitroAdapter(handler)\n return h3Adapter({\n method,\n path: url.pathname + url.search,\n // nitroAdapter's H3Event accepts Headers | Record<string,string> — pass\n // the Headers instance directly to avoid lossy serialization.\n headers: event.headers,\n _body: body,\n })\n})\n"],"mappings":";AAiBA,SAAS,oBAAoB,eAAe,gBAAgB;AAE5D,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAI7B,IAAI,WAAoC;AAExC,SAAS,WACP,OACA,MACA,YACA,UACkB;AAClB,MAAI,CAAC,UAAU;AACb,eAAW,kBAAkB,EAAE,OAAO,MAAM,YAAY,SAAS,CAAC;AAAA,EACpE;AACA,SAAO;AACT;AAEA,IAAO,eAAQ,mBAAmB,OAAO,UAAmB;AAM1D,QAAM,MAAM,MAAM;AAKlB,QAAM,SACJ,IAAI,OAAO,eAAe,QAAQ,OAAO,QACzC,IAAI,eAAe,QAAQ,OAAO,QAClC,CAAC;AAKH,QAAM,QAAQ,IAAI;AAElB,MAAI,CAAC,OAAO;AACV,WAAO,IAAI;AAAA,MACT,KAAK,UAAU,EAAE,OAAO,6BAA6B,CAAC;AAAA,MACtD,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,IACjE;AAAA,EACF;AAEA,QAAM,aAAa;AAKnB,QAAM,UAAU;AAAA,IACd;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,WAAW,cAAc;AAAA,IACzB,WAAW,YAAY;AAAA,EACzB;AAKA,QAAM,MAAM,cAAc,KAAK;AAC/B,QAAM,UAAU,MAAM,UAAU,OAAO,YAAY;AAEnD,MAAI,OAAgB;AACpB,MAAI,WAAW,SAAS,WAAW,UAAU,WAAW,UAAU;AAChE,QAAI;AAAE,aAAO,MAAM,SAAS,KAAK;AAAA,IAAE,QAAQ;AAAE,aAAO;AAAA,IAAK;AAAA,EAC3D;AAEA,QAAM,YAAY,aAAa,OAAO;AACtC,SAAO,UAAU;AAAA,IACf;AAAA,IACA,MAAM,IAAI,WAAW,IAAI;AAAA;AAAA;AAAA,IAGzB,SAAS,MAAM;AAAA,IACf,OAAO;AAAA,EACT,CAAC;AACH,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@noy-db/in-nuxt",
3
+ "version": "0.1.0-pre.10",
4
+ "description": "Nuxt 4 module for noy-db — auto-imports, SSR-safe runtime plugin, and the @noy-db/in-pinia bridge",
5
+ "license": "MIT",
6
+ "author": "vLannaAi <vicio@lanna.ai>",
7
+ "homepage": "https://github.com/vLannaAi/noy-db/tree/main/packages/in-nuxt#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vLannaAi/noy-db.git",
11
+ "directory": "packages/in-nuxt"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/vLannaAi/noy-db/issues"
15
+ },
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ }
23
+ },
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "engines": {
33
+ "node": ">=20.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "nuxt": "^4.0.0",
37
+ "@noy-db/hub": "0.1.0-pre.10",
38
+ "@noy-db/in-rest": "0.1.0-pre.10",
39
+ "@noy-db/in-vue": "0.1.0-pre.10",
40
+ "@noy-db/in-pinia": "0.1.0-pre.10"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@noy-db/in-rest": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "@nuxt/kit": "^4.4.2",
49
+ "@nuxt/schema": "^4.4.2",
50
+ "h3": "^1.13.0",
51
+ "nuxt": "^4.4.2",
52
+ "@noy-db/in-pinia": "0.1.0-pre.10",
53
+ "@noy-db/hub": "0.1.0-pre.10",
54
+ "@noy-db/in-rest": "0.1.0-pre.10",
55
+ "@noy-db/in-vue": "0.1.0-pre.10"
56
+ },
57
+ "keywords": [
58
+ "noy-db",
59
+ "nuxt",
60
+ "nuxt4",
61
+ "module",
62
+ "encryption",
63
+ "zero-knowledge",
64
+ "offline-first",
65
+ "pinia",
66
+ "vue"
67
+ ],
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "tag": "latest"
71
+ },
72
+ "scripts": {
73
+ "build": "tsup",
74
+ "test": "vitest run",
75
+ "lint": "eslint src/",
76
+ "typecheck": "tsc --noEmit"
77
+ }
78
+ }