@sfxcode/nuxt-mongocamp-server 2.2.0 → 2.4.0
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/README.md +74 -1
- package/dist/module.d.mts +10 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +95 -11
- package/dist/runtime/api/.openapi-generator/FILES +22 -0
- package/dist/runtime/api/apis/CollectionApi.d.ts +124 -0
- package/dist/runtime/api/apis/CollectionApi.js +205 -0
- package/dist/runtime/api/apis/DocumentApi.d.ts +162 -0
- package/dist/runtime/api/apis/DocumentApi.js +229 -0
- package/dist/runtime/api/docs/AuditEntry.md +52 -0
- package/dist/runtime/api/docs/CollectionApi.md +269 -2
- package/dist/runtime/api/docs/CollectionDeclaration.md +56 -0
- package/dist/runtime/api/docs/CollectionDeclarationAudit.md +34 -0
- package/dist/runtime/api/docs/CollectionDeclarationIndexesInner.md +38 -0
- package/dist/runtime/api/docs/CollectionDeclarationOwner.md +36 -0
- package/dist/runtime/api/docs/CollectionDeclarationRefsInner.md +38 -0
- package/dist/runtime/api/docs/CollectionDeclarationSoftDelete.md +36 -0
- package/dist/runtime/api/docs/CollectionDeclarationTimestamps.md +40 -0
- package/dist/runtime/api/docs/CollectionDeclarationVersioned.md +38 -0
- package/dist/runtime/api/docs/DocumentApi.md +303 -8
- package/dist/runtime/api/docs/ErrorDescription.md +4 -0
- package/dist/runtime/api/docs/ExportRequest.md +2 -0
- package/dist/runtime/api/docs/MongoFindRequest.md +2 -0
- package/dist/runtime/api/docs/SearchRequest.md +2 -0
- package/dist/runtime/api/docs/SuggestedValidator.md +40 -0
- package/dist/runtime/api/docs/ValidationIssue.md +36 -0
- package/dist/runtime/api/models/AuditEntry.d.ts +88 -0
- package/dist/runtime/api/models/AuditEntry.js +56 -0
- package/dist/runtime/api/models/CollectionDeclaration.d.ts +90 -0
- package/dist/runtime/api/models/CollectionDeclaration.js +87 -0
- package/dist/runtime/api/models/CollectionDeclarationAudit.d.ts +30 -0
- package/dist/runtime/api/models/CollectionDeclarationAudit.js +26 -0
- package/dist/runtime/api/models/CollectionDeclarationIndexesInner.d.ts +40 -0
- package/dist/runtime/api/models/CollectionDeclarationIndexesInner.js +32 -0
- package/dist/runtime/api/models/CollectionDeclarationOwner.d.ts +43 -0
- package/dist/runtime/api/models/CollectionDeclarationOwner.js +34 -0
- package/dist/runtime/api/models/CollectionDeclarationRefsInner.d.ts +38 -0
- package/dist/runtime/api/models/CollectionDeclarationRefsInner.js +31 -0
- package/dist/runtime/api/models/CollectionDeclarationSoftDelete.d.ts +34 -0
- package/dist/runtime/api/models/CollectionDeclarationSoftDelete.js +28 -0
- package/dist/runtime/api/models/CollectionDeclarationTimestamps.d.ts +42 -0
- package/dist/runtime/api/models/CollectionDeclarationTimestamps.js +33 -0
- package/dist/runtime/api/models/CollectionDeclarationVersioned.d.ts +46 -0
- package/dist/runtime/api/models/CollectionDeclarationVersioned.js +36 -0
- package/dist/runtime/api/models/ErrorDescription.d.ts +11 -0
- package/dist/runtime/api/models/ErrorDescription.js +10 -2
- package/dist/runtime/api/models/ExportRequest.d.ts +4 -0
- package/dist/runtime/api/models/ExportRequest.js +4 -2
- package/dist/runtime/api/models/MongoFindRequest.d.ts +4 -0
- package/dist/runtime/api/models/MongoFindRequest.js +4 -2
- package/dist/runtime/api/models/SearchRequest.d.ts +4 -0
- package/dist/runtime/api/models/SearchRequest.js +4 -2
- package/dist/runtime/api/models/SuggestedValidator.d.ts +44 -0
- package/dist/runtime/api/models/SuggestedValidator.js +35 -0
- package/dist/runtime/api/models/ValidationIssue.d.ts +34 -0
- package/dist/runtime/api/models/ValidationIssue.js +29 -0
- package/dist/runtime/api/models/index.d.ts +11 -0
- package/dist/runtime/api/models/index.js +11 -0
- package/dist/runtime/composables/mongocampApiCollection.d.ts +14 -15
- package/dist/runtime/composables/mongocampApiCollection.js +4 -1
- package/dist/runtime/composables/mongocampCollection.d.ts +144 -0
- package/dist/runtime/composables/mongocampCollection.js +241 -0
- package/dist/runtime/composables/mongocampLive.d.ts +36 -0
- package/dist/runtime/composables/mongocampLive.js +155 -0
- package/dist/runtime/composables/mongocampSearch.d.ts +12 -9
- package/dist/runtime/server/composables/mongocampServerCollection.d.ts +20 -0
- package/dist/runtime/server/composables/mongocampServerCollection.js +12 -0
- package/dist/runtime/server/mongocamp/plugin.d.ts +2 -2
- package/dist/runtime/server/mongocamp/plugin.js +10 -1
- package/dist/runtime/types/collections.d.ts +30 -0
- package/dist/runtime/types/collections.js +0 -0
- package/dist/runtime/utils/sse.d.ts +10 -0
- package/dist/runtime/utils/sse.js +33 -0
- package/dist/runtime/utils/toMongocampError.d.ts +7 -0
- package/dist/runtime/utils/toMongocampError.js +18 -1
- package/dist/types.d.mts +6 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -70,6 +70,75 @@ export default definePlugin((nitroApp) => {
|
|
|
70
70
|
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
Before-hooks (`mongocamp:document:beforeInsert`, `…:beforeReplace`, `…:beforeUpdate`, `…:beforeDelete`) are awaited and can change a
|
|
74
|
+
write or refuse it by throwing a `MongocampError`.
|
|
75
|
+
|
|
76
|
+
### Typed collections
|
|
77
|
+
|
|
78
|
+
A file in `server/mongocamp/` declares a collection with any Standard Schema library (Zod 4, Valibot, ArkType). The schema types the
|
|
79
|
+
documents on the client, validates the documents written through the API and becomes the `$jsonSchema` validator of the collection in
|
|
80
|
+
MongoDB ([docs](https://mongocamp.github.io/nuxt-mongocamp-server/server/declared-collections)):
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// server/mongocamp/orders.ts
|
|
84
|
+
import { z } from 'zod'
|
|
85
|
+
|
|
86
|
+
export default defineMongocampCollection({
|
|
87
|
+
name: 'orders',
|
|
88
|
+
schema: z.object({ customer: z.string().min(1), qty: z.int().min(1).default(1), createdAt: z.date() }),
|
|
89
|
+
validation: 'error', // 'warn' (default) logs invalid documents and writes them, 'off' does nothing
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// in a component: typed, decoded documents; invalid writes throw with the fields in `issues`
|
|
95
|
+
const orders = useMongocampCollection('orders')
|
|
96
|
+
const open = await orders.find({ filter: 'qty:[2 TO *]' }) // { customer: string, qty: number, createdAt: Date }[]
|
|
97
|
+
await orders.insert({ customer: 'Ada', createdAt: new Date() })
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Since 2.3 a declaration also switches behaviours on, one flag each — what Mongoose users know from `{ timestamps: true }`, `__v` and
|
|
101
|
+
plugins, plus per-document ownership and live data in the browser ([behaviours](https://mongocamp.github.io/nuxt-mongocamp-server/server/declared-collections#behaviours),
|
|
102
|
+
[coming from Mongoose](https://mongocamp.github.io/nuxt-mongocamp-server/guide/coming-from-mongoose)):
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
export default defineMongocampCollection({
|
|
106
|
+
name: 'orders',
|
|
107
|
+
schema,
|
|
108
|
+
timestamps: true, // createdAt, updatedAt (optionally createdBy, updatedBy, nested paths)
|
|
109
|
+
owner: true, // only the creator writes; reads 'own', 'all' or a function; others get 404
|
|
110
|
+
softDelete: true, // deletedAt, hidden everywhere, restore, withDeleted, purge
|
|
111
|
+
versioned: true, // an outdated write answers 409 with the stored document
|
|
112
|
+
audit: true, // before/after of every write, history(id)
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// a live list: changes of other users appear (replica set: Server-Sent Events, else polling)
|
|
118
|
+
const { documents, status } = useMongocampLive('orders', { filter: 'status:open' })
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Since 2.4 the declaration also holds the indexes and the references to other collections — Mongoose's `index` and `populate`
|
|
122
|
+
([indexes](https://mongocamp.github.io/nuxt-mongocamp-server/server/declared-collections#indexes),
|
|
123
|
+
[relations](https://mongocamp.github.io/nuxt-mongocamp-server/server/declared-collections#relations)):
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
export default defineMongocampCollection({
|
|
127
|
+
name: 'orders',
|
|
128
|
+
schema,
|
|
129
|
+
indexes: ['status', ['customerId', '-createdAt'], { fields: { number: 1 }, unique: true }], // created at the start
|
|
130
|
+
refs: { customerId: 'customers' },
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const list = await useMongocampCollection('orders').find({ expand: ['customerId'] }) // customerId: Customer | null, read with your rights
|
|
136
|
+
|
|
137
|
+
// server/api/orders.post.ts: the same rules as the API, for the caller of the request
|
|
138
|
+
const orders = useMongocampServerCollection('orders', { user: event })
|
|
139
|
+
await orders.insert({ customerId, total: 12.5 })
|
|
140
|
+
```
|
|
141
|
+
|
|
73
142
|
**Upgrading** from an older MongoCamp server or a 1.x version of this module: see the migration guides ([`docs/migration/to-2.0.md`](docs/migration/to-2.0.md), [`docs/migration/from-scala.md`](docs/migration/from-scala.md)).
|
|
74
143
|
|
|
75
144
|
### Standalone server
|
|
@@ -117,6 +186,7 @@ export default defineNuxtConfig({
|
|
|
117
186
|
| `server.jobs` | `boolean` | `true` | Runs the jobs (token cleanup, ...) on their schedule in this instance. |
|
|
118
187
|
| `server.requestLogging` | `boolean` | `false` | Writes every request as a document of `mc_request_logging`. |
|
|
119
188
|
| `server.metrics` | `boolean` | `false` | Serves `/system/monitoring/*` (also Prometheus text) and writes the metric snapshots. |
|
|
189
|
+
| `server.collectionsDir` | `string` | `mongocamp` | Directory of the declared collections in `server/` (app and layers). With an external server: types only, when set. |
|
|
120
190
|
| `apiKey` | `string` | — | Optional. Stored server-side only; picked up automatically by `useMongocampApi(event)`. |
|
|
121
191
|
| `paginationSize` | `number` | `500` | Default rows per page for search/list composables. Values below 10 fall back to the default. |
|
|
122
192
|
| `refreshToken` | `boolean` | `false` | Whether the client auto-refreshes the session token on an interval after login. |
|
|
@@ -136,7 +206,9 @@ A missing `url` throws during `nuxi dev`/`nuxi build`/`nuxi generate` (not durin
|
|
|
136
206
|
| `useMongocampUrl()` | The configured base URL. |
|
|
137
207
|
| `useMongocampSearch()` | `find`/`findAll`/`findByField` document search helpers. `find(..., filterCaseInsensitive)` makes wildcards of the filter ignore the case (case-sensitive by default). |
|
|
138
208
|
| `usePaginatedFind(collection, opts)`| Reactive pagination wrapper (`page`, `documents`, `pending`, `error`, `nextPage`/`previousPage`/`goToPage`); `opts.filterCaseInsensitive` as for `find`. |
|
|
139
|
-
| `
|
|
209
|
+
| `useMongocampCollection(name)` | Typed and decoded documents of a declared collection (or `<T>(name)` for any other): `find`, `findPage`, `findById`, `insert`, `replace`, `update`, `remove`, `restore`, `history`, `isMine`, `paginated()`; `expand` of references (typed); versions sent automatically, errors with `status`, `issues`, `isConflict`, `current`. |
|
|
210
|
+
| `useMongocampLive(name, opts)` | A live list kept in sync with the server (Server-Sent Events on change streams, polling without a replica set). |
|
|
211
|
+
| `useMongocampApiCollection(name)` | Per-collection insert/update/delete/aggregate/schema helpers, `suggestValidator()`. |
|
|
140
212
|
| `useMongocampApiCollections()` | List collections/databases, database info. |
|
|
141
213
|
| `useMongocampApiFiles()` | Bucket and file upload/download/list helpers. |
|
|
142
214
|
| `useMongocampApiJobs()` | List/register/update/execute/delete scheduled jobs. |
|
|
@@ -159,6 +231,7 @@ The server returns documents as relaxed MongoDB Extended JSON: `{"_id": {"$oid":
|
|
|
159
231
|
| `useMongocampApi(event, token?)` | Builds authenticated API clients using the module's `apiKey`, or the given `token` as a fallback. With the embedded server the calls are answered in-process. |
|
|
160
232
|
| `useMongocampCore()` | The embedded server (`server.enabled` only) in server routes; plugins get it on the hook `mongocamp:ready`. |
|
|
161
233
|
| `useMongocampServerApi(url, key?, token?)` | Lower-level factory when you need to authenticate against a different URL/credential explicitly. |
|
|
234
|
+
| `useMongocampServerCollection(name, { user })` | Typed documents of a collection in server code with the rules of the API (grants, scope, validation, behaviours, events) for the event's caller, a user id or `'system'` (2.4, embedded server). |
|
|
162
235
|
|
|
163
236
|
```ts
|
|
164
237
|
// server/api/mongocamp/users.ts
|
package/dist/module.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
export * from '../dist/runtime/api/index.js';
|
|
3
|
+
export { AuditEntry, CollectionFindOptions, CollectionPage, DocumentIdentity, MongocampRequestError, PaginatedCollection, TypedCollection } from '../dist/runtime/composables/mongocampCollection.js';
|
|
4
|
+
export { MongocampCollectionName, MongocampDocument, MongocampDocumentInput } from '../dist/runtime/types/collections.js';
|
|
5
|
+
export { LiveOptions, LiveState, LiveStatus } from '../dist/runtime/composables/mongocampLive.js';
|
|
3
6
|
|
|
4
7
|
/** The option `server` of the module: the MongoCamp server embedded in the Nitro of the application. */
|
|
5
8
|
interface ServerOptions {
|
|
@@ -17,6 +20,12 @@ interface ServerOptions {
|
|
|
17
20
|
requestLogging?: boolean;
|
|
18
21
|
/** Serves `/system/monitoring/*` and writes the metric snapshots of `LOGGING_METRICS_MONGODB_*` (default false). */
|
|
19
22
|
metrics?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The directory of the declared collections in the server directory of the application and its layers (default `mongocamp`, i.e.
|
|
25
|
+
* `server/mongocamp/*.ts`). Registered in the embedded server and typed for the client; with an external server only typed, and only
|
|
26
|
+
* when this option is set.
|
|
27
|
+
*/
|
|
28
|
+
collectionsDir?: string;
|
|
20
29
|
}
|
|
21
30
|
interface ResolvedServerOptions {
|
|
22
31
|
enabled: boolean;
|
|
@@ -26,6 +35,7 @@ interface ResolvedServerOptions {
|
|
|
26
35
|
jobs: boolean;
|
|
27
36
|
requestLogging: boolean;
|
|
28
37
|
metrics: boolean;
|
|
38
|
+
collectionsDir: string;
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
interface ModuleOptions {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join, relative, basename, extname, isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { defineNuxtModule, createResolver, addImportsDir, addImports, addServerImportsDir, addServerHandler, addServerPlugin, addServerImports, addTypeTemplate, addServerTemplate, updateTemplates, resolveFiles } from '@nuxt/kit';
|
|
2
3
|
import { defu } from 'defu';
|
|
3
4
|
import { consola } from 'consola';
|
|
4
5
|
export * from '../dist/runtime/api/index.js';
|
|
5
6
|
|
|
6
7
|
const name = "@sfxcode/nuxt-mongocamp-server";
|
|
7
|
-
const version = "2.
|
|
8
|
+
const version = "2.4.0";
|
|
8
9
|
|
|
9
10
|
const DefaultServerPrefix = "/api/mongocamp-server";
|
|
11
|
+
const DefaultCollectionsDir = "mongocamp";
|
|
10
12
|
function normalizePrefix(prefix) {
|
|
11
13
|
const trimmed = (prefix ?? DefaultServerPrefix).trim().replace(/\/+$/, "");
|
|
12
14
|
const path = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -23,7 +25,8 @@ function resolveServerOptions(options) {
|
|
|
23
25
|
config: options?.config ?? {},
|
|
24
26
|
jobs: options?.jobs ?? true,
|
|
25
27
|
requestLogging: options?.requestLogging ?? false,
|
|
26
|
-
metrics: options?.metrics ?? false
|
|
28
|
+
metrics: options?.metrics ?? false,
|
|
29
|
+
collectionsDir: options?.collectionsDir?.trim().replace(/^\/+|\/+$/g, "") || DefaultCollectionsDir
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
function resolveClientUrl(url, server) {
|
|
@@ -33,6 +36,68 @@ function resolveClientUrl(url, server) {
|
|
|
33
36
|
return server.enabled ? server.prefix : void 0;
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
const CollectionsVirtualModule = "#mongocamp/collections";
|
|
40
|
+
const CollectionFilePattern = "*.{ts,mts,js,mjs}";
|
|
41
|
+
function collectionDirs(layers, collectionsDir) {
|
|
42
|
+
return [...new Set(layers.map(({ config }) => join(config.serverDir ?? join(config.srcDir ?? config.rootDir, "server"), collectionsDir)))];
|
|
43
|
+
}
|
|
44
|
+
async function scanCollections(dirs, resolve) {
|
|
45
|
+
const files = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const dir of dirs) {
|
|
47
|
+
for (const path of (await resolve(dir)).sort()) {
|
|
48
|
+
if (path.endsWith(".d.ts")) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const key = basename(path, extname(path));
|
|
52
|
+
if (!files.has(key)) {
|
|
53
|
+
files.set(key, { key, path });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [...files.values()].sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
58
|
+
}
|
|
59
|
+
function importPath(from, path) {
|
|
60
|
+
const withoutExtension = /\.m?ts$/.test(path) ? path.replace(/\.m?ts$/, "") : path;
|
|
61
|
+
const relativePath = relative(from, withoutExtension).split("\\").join("/");
|
|
62
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
63
|
+
}
|
|
64
|
+
function collectionsServerTemplate(files, rootDir) {
|
|
65
|
+
const imports = files.map((file, index) => `import collection${index} from ${JSON.stringify(file.path)}`);
|
|
66
|
+
const entries = files.map((file, index) => ` { key: ${JSON.stringify(file.key)}, source: ${JSON.stringify(relative(rootDir, file.path).split("\\").join("/"))}, definition: collection${index} },`);
|
|
67
|
+
return [...imports, "", "export const declarations = [", ...entries, "]", ""].join("\n");
|
|
68
|
+
}
|
|
69
|
+
function collectionsTypeTemplate(files, typesDir) {
|
|
70
|
+
const entries = (type) => files.map((file) => ` ${JSON.stringify(file.key)}: ${type}<typeof import(${JSON.stringify(importPath(typesDir, file.path))}).default>`);
|
|
71
|
+
return [
|
|
72
|
+
"import type { InferDocument, InferDocumentInput, InferRefs } from '@sfxcode/mongocamp-server-core'",
|
|
73
|
+
"",
|
|
74
|
+
"declare global {",
|
|
75
|
+
" /** The documents of the declared collections (`server/mongocamp/<name>.ts`) as they are stored, by file name. */",
|
|
76
|
+
" interface MongocampCollections {",
|
|
77
|
+
...entries("InferDocument"),
|
|
78
|
+
" }",
|
|
79
|
+
" /** The documents of the declared collections as they are written (before the defaults of the schema), by file name. */",
|
|
80
|
+
" interface MongocampCollectionInputs {",
|
|
81
|
+
...entries("InferDocumentInput"),
|
|
82
|
+
" }",
|
|
83
|
+
" /** The references of the declared collections (2.4.0): field \u2192 target collection, for `expand`. */",
|
|
84
|
+
" interface MongocampCollectionRefs {",
|
|
85
|
+
...entries("InferRefs"),
|
|
86
|
+
" }",
|
|
87
|
+
"}",
|
|
88
|
+
"",
|
|
89
|
+
"export {}",
|
|
90
|
+
""
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
const collectionsVirtualModuleTypes = [
|
|
94
|
+
`declare module '${CollectionsVirtualModule}' {`,
|
|
95
|
+
" import type { MongocampCollectionDefinition } from '@sfxcode/mongocamp-server-core'",
|
|
96
|
+
" export const declarations: Array<{ key: string, source: string, definition: MongocampCollectionDefinition }>",
|
|
97
|
+
"}",
|
|
98
|
+
""
|
|
99
|
+
].join("\n");
|
|
100
|
+
|
|
36
101
|
const module$1 = defineNuxtModule({
|
|
37
102
|
meta: {
|
|
38
103
|
name,
|
|
@@ -79,16 +144,16 @@ const module$1 = defineNuxtModule({
|
|
|
79
144
|
}
|
|
80
145
|
);
|
|
81
146
|
nuxt.options.runtimeConfig.mongocampApiKey = nuxt.options.runtimeConfig.mongocampApiKey ?? options.apiKey ?? "";
|
|
82
|
-
const { resolve } = createResolver(import.meta.url);
|
|
83
|
-
const runtimeDir = resolve("./runtime");
|
|
84
|
-
addImportsDir(resolve(runtimeDir, "composables"));
|
|
85
|
-
addImports(["fromExtendedJson", "toExtendedJson", "documentId"].map((name2) => ({ name: name2, from: resolve(runtimeDir, "utils/extendedJson") })));
|
|
86
|
-
addServerImportsDir(resolve(runtimeDir, "server/composables"));
|
|
147
|
+
const { resolve: resolve$1 } = createResolver(import.meta.url);
|
|
148
|
+
const runtimeDir = resolve$1("./runtime");
|
|
149
|
+
addImportsDir(resolve$1(runtimeDir, "composables"));
|
|
150
|
+
addImports(["fromExtendedJson", "toExtendedJson", "documentId"].map((name2) => ({ name: name2, from: resolve$1(runtimeDir, "utils/extendedJson") })));
|
|
151
|
+
addServerImportsDir(resolve$1(runtimeDir, "server/composables"));
|
|
87
152
|
nuxt.options.runtimeConfig.mongocampServer = defu(nuxt.options.runtimeConfig.mongocampServer, { ...server, version: { name: "mongocamp-nitro-server", version } });
|
|
88
153
|
if (server.enabled) {
|
|
89
|
-
addServerHandler({ route: `${server.prefix}/**`, handler: resolve(runtimeDir, "server/mongocamp/handler") });
|
|
90
|
-
addServerPlugin(resolve(runtimeDir, "server/mongocamp/plugin"));
|
|
91
|
-
addServerImports([{ name: "useMongocampCore", from: resolve(runtimeDir, "server/mongocamp/core") }]);
|
|
154
|
+
addServerHandler({ route: `${server.prefix}/**`, handler: resolve$1(runtimeDir, "server/mongocamp/handler") });
|
|
155
|
+
addServerPlugin(resolve$1(runtimeDir, "server/mongocamp/plugin"));
|
|
156
|
+
addServerImports([{ name: "useMongocampCore", from: resolve$1(runtimeDir, "server/mongocamp/core") }]);
|
|
92
157
|
addTypeTemplate({
|
|
93
158
|
filename: "types/mongocamp-hooks.d.ts",
|
|
94
159
|
getContents: () => [
|
|
@@ -101,6 +166,25 @@ const module$1 = defineNuxtModule({
|
|
|
101
166
|
}, { nitro: true, nuxt: true });
|
|
102
167
|
consola.info(`[mongocamp] embedded server at ${server.prefix}`);
|
|
103
168
|
}
|
|
169
|
+
if (server.enabled || options.server?.collectionsDir !== void 0) {
|
|
170
|
+
const dirs = collectionDirs(nuxt.options._layers, server.collectionsDir);
|
|
171
|
+
const scan = () => scanCollections(dirs, (dir) => resolveFiles(dir, CollectionFilePattern));
|
|
172
|
+
if (server.enabled) {
|
|
173
|
+
addServerImports([{ name: "defineMongocampCollection", from: "@sfxcode/mongocamp-server-core" }]);
|
|
174
|
+
addServerTemplate({ filename: CollectionsVirtualModule, getContents: async () => collectionsServerTemplate(await scan(), nuxt.options.rootDir) });
|
|
175
|
+
addTypeTemplate({ filename: "types/mongocamp-collections-virtual.d.ts", getContents: () => collectionsVirtualModuleTypes }, { nitro: true });
|
|
176
|
+
}
|
|
177
|
+
addTypeTemplate({
|
|
178
|
+
filename: "types/mongocamp-collections.d.ts",
|
|
179
|
+
getContents: async () => collectionsTypeTemplate(await scan(), join(nuxt.options.buildDir, "types"))
|
|
180
|
+
}, { nitro: true, nuxt: true });
|
|
181
|
+
nuxt.hook("builder:watch", async (event, path) => {
|
|
182
|
+
const candidates = isAbsolute(path) ? [path] : [resolve(nuxt.options.srcDir, path), resolve(nuxt.options.rootDir, path)];
|
|
183
|
+
if ((event === "add" || event === "unlink") && candidates.some((candidate) => dirs.some((dir) => candidate.startsWith(`${dir}/`)))) {
|
|
184
|
+
await updateTemplates({ filter: (template) => template.filename === "types/mongocamp-collections.d.ts" });
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
104
188
|
consola.success("mongocamp-nuxt available");
|
|
105
189
|
}
|
|
106
190
|
});
|
|
@@ -12,6 +12,7 @@ apis/SystemApi.ts
|
|
|
12
12
|
apis/index.ts
|
|
13
13
|
docs/AdminApi.md
|
|
14
14
|
docs/ApplicationApi.md
|
|
15
|
+
docs/AuditEntry.md
|
|
15
16
|
docs/AuthApi.md
|
|
16
17
|
docs/BucketApi.md
|
|
17
18
|
docs/BucketInformation.md
|
|
@@ -21,6 +22,14 @@ docs/ClusterInformation.md
|
|
|
21
22
|
docs/ClusterMemberInformation.md
|
|
22
23
|
docs/CollectionApi.md
|
|
23
24
|
docs/CollectionCollation.md
|
|
25
|
+
docs/CollectionDeclaration.md
|
|
26
|
+
docs/CollectionDeclarationAudit.md
|
|
27
|
+
docs/CollectionDeclarationIndexesInner.md
|
|
28
|
+
docs/CollectionDeclarationOwner.md
|
|
29
|
+
docs/CollectionDeclarationRefsInner.md
|
|
30
|
+
docs/CollectionDeclarationSoftDelete.md
|
|
31
|
+
docs/CollectionDeclarationTimestamps.md
|
|
32
|
+
docs/CollectionDeclarationVersioned.md
|
|
24
33
|
docs/CollectionOptions.md
|
|
25
34
|
docs/CollectionPermission.md
|
|
26
35
|
docs/CollectionStatus.md
|
|
@@ -79,6 +88,7 @@ docs/SchemaAnalysisField.md
|
|
|
79
88
|
docs/SchemaAnalysisFieldType.md
|
|
80
89
|
docs/SearchRequest.md
|
|
81
90
|
docs/SettingsResponse.md
|
|
91
|
+
docs/SuggestedValidator.md
|
|
82
92
|
docs/SystemApi.md
|
|
83
93
|
docs/SystemInfo.md
|
|
84
94
|
docs/SystemStats.md
|
|
@@ -88,14 +98,24 @@ docs/UpdateResponse.md
|
|
|
88
98
|
docs/UpdateRoleRequest.md
|
|
89
99
|
docs/UserInformation.md
|
|
90
100
|
docs/UserProfile.md
|
|
101
|
+
docs/ValidationIssue.md
|
|
91
102
|
docs/Version.md
|
|
92
103
|
index.ts
|
|
104
|
+
models/AuditEntry.ts
|
|
93
105
|
models/BucketInformation.ts
|
|
94
106
|
models/Capabilities.ts
|
|
95
107
|
models/CapabilityLimits.ts
|
|
96
108
|
models/ClusterInformation.ts
|
|
97
109
|
models/ClusterMemberInformation.ts
|
|
98
110
|
models/CollectionCollation.ts
|
|
111
|
+
models/CollectionDeclaration.ts
|
|
112
|
+
models/CollectionDeclarationAudit.ts
|
|
113
|
+
models/CollectionDeclarationIndexesInner.ts
|
|
114
|
+
models/CollectionDeclarationOwner.ts
|
|
115
|
+
models/CollectionDeclarationRefsInner.ts
|
|
116
|
+
models/CollectionDeclarationSoftDelete.ts
|
|
117
|
+
models/CollectionDeclarationTimestamps.ts
|
|
118
|
+
models/CollectionDeclarationVersioned.ts
|
|
99
119
|
models/CollectionOptions.ts
|
|
100
120
|
models/CollectionPermission.ts
|
|
101
121
|
models/CollectionStatus.ts
|
|
@@ -149,6 +169,7 @@ models/SchemaAnalysisField.ts
|
|
|
149
169
|
models/SchemaAnalysisFieldType.ts
|
|
150
170
|
models/SearchRequest.ts
|
|
151
171
|
models/SettingsResponse.ts
|
|
172
|
+
models/SuggestedValidator.ts
|
|
152
173
|
models/SystemInfo.ts
|
|
153
174
|
models/SystemStats.ts
|
|
154
175
|
models/UpdateFileInformationRequest.ts
|
|
@@ -157,6 +178,7 @@ models/UpdateResponse.ts
|
|
|
157
178
|
models/UpdateRoleRequest.ts
|
|
158
179
|
models/UserInformation.ts
|
|
159
180
|
models/UserProfile.ts
|
|
181
|
+
models/ValidationIssue.ts
|
|
160
182
|
models/Version.ts
|
|
161
183
|
models/index.ts
|
|
162
184
|
runtime.ts
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
import * as runtime from '../runtime.js';
|
|
13
|
+
import { type AuditEntry } from '../models/AuditEntry.js';
|
|
14
|
+
import { type CollectionDeclaration } from '../models/CollectionDeclaration.js';
|
|
13
15
|
import { type CollectionOptions } from '../models/CollectionOptions.js';
|
|
14
16
|
import { type CollectionStatus } from '../models/CollectionStatus.js';
|
|
15
17
|
import { type CollectionSummary } from '../models/CollectionSummary.js';
|
|
@@ -23,6 +25,7 @@ import { type MongoAggregateRequest } from '../models/MongoAggregateRequest.js';
|
|
|
23
25
|
import { type RenameRequest } from '../models/RenameRequest.js';
|
|
24
26
|
import { type RenameResponse } from '../models/RenameResponse.js';
|
|
25
27
|
import { type SchemaAnalysis } from '../models/SchemaAnalysis.js';
|
|
28
|
+
import { type SuggestedValidator } from '../models/SuggestedValidator.js';
|
|
26
29
|
export interface AggregateRequest {
|
|
27
30
|
/**
|
|
28
31
|
* The name of your MongoDb Collection
|
|
@@ -32,6 +35,10 @@ export interface AggregateRequest {
|
|
|
32
35
|
*
|
|
33
36
|
*/
|
|
34
37
|
mongoAggregateRequest: MongoAggregateRequest;
|
|
38
|
+
/**
|
|
39
|
+
* Soft-deleted documents too (collections declared with softDelete, 2.3.0); needs the administrate grant of the collection, 403 otherwise.
|
|
40
|
+
*/
|
|
41
|
+
withDeleted?: boolean;
|
|
35
42
|
/**
|
|
36
43
|
* Count elements per page
|
|
37
44
|
*/
|
|
@@ -102,6 +109,10 @@ export interface DistinctRequest {
|
|
|
102
109
|
* The field for your distinct Request.
|
|
103
110
|
*/
|
|
104
111
|
field: string;
|
|
112
|
+
/**
|
|
113
|
+
* Soft-deleted documents too (collections declared with softDelete, 2.3.0); needs the administrate grant of the collection, 403 otherwise.
|
|
114
|
+
*/
|
|
115
|
+
withDeleted?: boolean;
|
|
105
116
|
/**
|
|
106
117
|
* Count elements per page
|
|
107
118
|
*/
|
|
@@ -119,6 +130,12 @@ export interface DistinctRequest {
|
|
|
119
130
|
*/
|
|
120
131
|
extendedJson?: DistinctExtendedJsonEnum;
|
|
121
132
|
}
|
|
133
|
+
export interface GetCollectionDeclarationRequest {
|
|
134
|
+
/**
|
|
135
|
+
* The name of your MongoDb Collection
|
|
136
|
+
*/
|
|
137
|
+
collectionName: string;
|
|
138
|
+
}
|
|
122
139
|
export interface GetCollectionFieldsRequest {
|
|
123
140
|
/**
|
|
124
141
|
* The name of your MongoDb Collection
|
|
@@ -129,6 +146,32 @@ export interface GetCollectionFieldsRequest {
|
|
|
129
146
|
*/
|
|
130
147
|
sampleSize?: number;
|
|
131
148
|
}
|
|
149
|
+
export interface GetCollectionHistoryRequest {
|
|
150
|
+
/**
|
|
151
|
+
* The name of your MongoDb Collection
|
|
152
|
+
*/
|
|
153
|
+
collectionName: string;
|
|
154
|
+
/**
|
|
155
|
+
* Only records from this time on (ISO date or time).
|
|
156
|
+
*/
|
|
157
|
+
since?: string;
|
|
158
|
+
/**
|
|
159
|
+
* Only records of this operation.
|
|
160
|
+
*/
|
|
161
|
+
operation?: GetCollectionHistoryOperationEnum;
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
rowsPerPage?: number;
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
page?: number;
|
|
170
|
+
/**
|
|
171
|
+
* relaxed (default), canonical or plain, as for the documents.
|
|
172
|
+
*/
|
|
173
|
+
extendedJson?: GetCollectionHistoryExtendedJsonEnum;
|
|
174
|
+
}
|
|
132
175
|
export interface GetCollectionInformationRequest {
|
|
133
176
|
/**
|
|
134
177
|
* The name of your MongoDb Collection
|
|
@@ -187,6 +230,24 @@ export interface GetSchemaAnalysisRequest {
|
|
|
187
230
|
*/
|
|
188
231
|
depth?: number;
|
|
189
232
|
}
|
|
233
|
+
export interface GetSuggestedValidatorRequest {
|
|
234
|
+
/**
|
|
235
|
+
* The name of your MongoDb Collection
|
|
236
|
+
*/
|
|
237
|
+
collectionName: string;
|
|
238
|
+
/**
|
|
239
|
+
* Number of documents that are analysed, 1000 by default (2.0.0; 1.x read every document); 0 reads every document. With a sample the counts and shares are estimates.
|
|
240
|
+
*/
|
|
241
|
+
sampleSize?: number;
|
|
242
|
+
/**
|
|
243
|
+
* How deep nested objects are analysed
|
|
244
|
+
*/
|
|
245
|
+
depth?: number;
|
|
246
|
+
/**
|
|
247
|
+
* The share of the objects (0 to 1) a field has to be in to be required; 1 by default (in every object of the sample).
|
|
248
|
+
*/
|
|
249
|
+
requiredThreshold?: number;
|
|
250
|
+
}
|
|
190
251
|
export interface ListCollectionInformationRequest {
|
|
191
252
|
/**
|
|
192
253
|
* Only the Collections with these names, by default all Collections that the user may read. With `database` the names are the names inside that database (`locations`), the full name (`geodata:locations`) of that database is accepted too.
|
|
@@ -315,6 +376,20 @@ export declare class CollectionApi extends runtime.BaseAPI {
|
|
|
315
376
|
* Distinct in Collection
|
|
316
377
|
*/
|
|
317
378
|
distinct(requestParameters: DistinctRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<any>>;
|
|
379
|
+
/**
|
|
380
|
+
* Creates request options for getCollectionDeclaration without sending the request
|
|
381
|
+
*/
|
|
382
|
+
getCollectionDeclarationRequestOpts(requestParameters: GetCollectionDeclarationRequest): Promise<runtime.RequestOpts>;
|
|
383
|
+
/**
|
|
384
|
+
* What a client needs to know of a declared collection (2.3.0): fields it must not send, version and owner fields, behaviours. 404 for a collection that is not declared.
|
|
385
|
+
* Declaration of a Collection
|
|
386
|
+
*/
|
|
387
|
+
getCollectionDeclarationRaw(requestParameters: GetCollectionDeclarationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<CollectionDeclaration>>;
|
|
388
|
+
/**
|
|
389
|
+
* What a client needs to know of a declared collection (2.3.0): fields it must not send, version and owner fields, behaviours. 404 for a collection that is not declared.
|
|
390
|
+
* Declaration of a Collection
|
|
391
|
+
*/
|
|
392
|
+
getCollectionDeclaration(requestParameters: GetCollectionDeclarationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<CollectionDeclaration>;
|
|
318
393
|
/**
|
|
319
394
|
* Creates request options for getCollectionFields without sending the request
|
|
320
395
|
*/
|
|
@@ -329,6 +404,20 @@ export declare class CollectionApi extends runtime.BaseAPI {
|
|
|
329
404
|
* Collection Fields
|
|
330
405
|
*/
|
|
331
406
|
getCollectionFields(requestParameters: GetCollectionFieldsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<string>>;
|
|
407
|
+
/**
|
|
408
|
+
* Creates request options for getCollectionHistory without sending the request
|
|
409
|
+
*/
|
|
410
|
+
getCollectionHistoryRequestOpts(requestParameters: GetCollectionHistoryRequest): Promise<runtime.RequestOpts>;
|
|
411
|
+
/**
|
|
412
|
+
* The audit records of a collection declared with audit, newest first (2.3.0); for the administrators of the collection. 404 for a collection without audit.
|
|
413
|
+
* History of a Collection
|
|
414
|
+
*/
|
|
415
|
+
getCollectionHistoryRaw(requestParameters: GetCollectionHistoryRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<AuditEntry>>>;
|
|
416
|
+
/**
|
|
417
|
+
* The audit records of a collection declared with audit, newest first (2.3.0); for the administrators of the collection. 404 for a collection without audit.
|
|
418
|
+
* History of a Collection
|
|
419
|
+
*/
|
|
420
|
+
getCollectionHistory(requestParameters: GetCollectionHistoryRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<AuditEntry>>;
|
|
332
421
|
/**
|
|
333
422
|
* Creates request options for getCollectionInformation without sending the request
|
|
334
423
|
*/
|
|
@@ -399,6 +488,20 @@ export declare class CollectionApi extends runtime.BaseAPI {
|
|
|
399
488
|
* Collection Fields
|
|
400
489
|
*/
|
|
401
490
|
getSchemaAnalysis(requestParameters: GetSchemaAnalysisRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SchemaAnalysis>;
|
|
491
|
+
/**
|
|
492
|
+
* Creates request options for getSuggestedValidator without sending the request
|
|
493
|
+
*/
|
|
494
|
+
getSuggestedValidatorRequestOpts(requestParameters: GetSuggestedValidatorRequest): Promise<runtime.RequestOpts>;
|
|
495
|
+
/**
|
|
496
|
+
* A $jsonSchema validator made of a sample of the documents (2.3.0): the BSON types per field, nested objects, array items and the required fields. Usable as validator of the collection options or of a declaration. 404 for a collection that does not exist.
|
|
497
|
+
* Suggested Validator
|
|
498
|
+
*/
|
|
499
|
+
getSuggestedValidatorRaw(requestParameters: GetSuggestedValidatorRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SuggestedValidator>>;
|
|
500
|
+
/**
|
|
501
|
+
* A $jsonSchema validator made of a sample of the documents (2.3.0): the BSON types per field, nested objects, array items and the required fields. Usable as validator of the collection options or of a declaration. 404 for a collection that does not exist.
|
|
502
|
+
* Suggested Validator
|
|
503
|
+
*/
|
|
504
|
+
getSuggestedValidator(requestParameters: GetSuggestedValidatorRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuggestedValidator>;
|
|
402
505
|
/**
|
|
403
506
|
* Creates request options for listCollectionInformation without sending the request
|
|
404
507
|
*/
|
|
@@ -504,3 +607,24 @@ export declare const DistinctExtendedJsonEnum: {
|
|
|
504
607
|
readonly Plain: "plain";
|
|
505
608
|
};
|
|
506
609
|
export type DistinctExtendedJsonEnum = typeof DistinctExtendedJsonEnum[keyof typeof DistinctExtendedJsonEnum];
|
|
610
|
+
/**
|
|
611
|
+
* @export
|
|
612
|
+
*/
|
|
613
|
+
export declare const GetCollectionHistoryOperationEnum: {
|
|
614
|
+
readonly Insert: "insert";
|
|
615
|
+
readonly Replace: "replace";
|
|
616
|
+
readonly Update: "update";
|
|
617
|
+
readonly Delete: "delete";
|
|
618
|
+
readonly SoftDelete: "softDelete";
|
|
619
|
+
readonly Restore: "restore";
|
|
620
|
+
};
|
|
621
|
+
export type GetCollectionHistoryOperationEnum = typeof GetCollectionHistoryOperationEnum[keyof typeof GetCollectionHistoryOperationEnum];
|
|
622
|
+
/**
|
|
623
|
+
* @export
|
|
624
|
+
*/
|
|
625
|
+
export declare const GetCollectionHistoryExtendedJsonEnum: {
|
|
626
|
+
readonly Relaxed: "relaxed";
|
|
627
|
+
readonly Canonical: "canonical";
|
|
628
|
+
readonly Plain: "plain";
|
|
629
|
+
};
|
|
630
|
+
export type GetCollectionHistoryExtendedJsonEnum = typeof GetCollectionHistoryExtendedJsonEnum[keyof typeof GetCollectionHistoryExtendedJsonEnum];
|