@sfxcode/nuxt-mongocamp-server 2.1.0 → 2.3.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 +71 -19
- package/dist/module.d.mts +16 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +103 -11
- package/dist/runtime/api/.openapi-generator/FILES +24 -2
- package/dist/runtime/api/apis/CollectionApi.d.ts +137 -0
- package/dist/runtime/api/apis/CollectionApi.js +213 -0
- package/dist/runtime/api/apis/DocumentApi.d.ts +225 -8
- package/dist/runtime/api/apis/DocumentApi.js +364 -5
- package/dist/runtime/api/docs/AuditEntry.md +52 -0
- package/dist/runtime/api/docs/CollectionApi.md +272 -2
- package/dist/runtime/api/docs/CollectionDeclaration.md +52 -0
- package/dist/runtime/api/docs/CollectionDeclarationAudit.md +34 -0
- package/dist/runtime/api/docs/CollectionDeclarationOwner.md +36 -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/CountRequest.md +34 -0
- package/dist/runtime/api/docs/DocumentApi.md +467 -12
- package/dist/runtime/api/docs/ErrorDescription.md +4 -0
- package/dist/runtime/api/docs/ExportRequest.md +40 -0
- package/dist/runtime/api/docs/MongoAggregateRequest.md +2 -0
- package/dist/runtime/api/docs/SettingsResponse.md +0 -6
- package/dist/runtime/api/docs/SuggestedValidator.md +40 -0
- package/dist/runtime/api/docs/{UpdateRequest.md → UpdateManyRequest.md} +4 -4
- 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 +80 -0
- package/dist/runtime/api/models/CollectionDeclaration.js +73 -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/CollectionDeclarationOwner.d.ts +43 -0
- package/dist/runtime/api/models/CollectionDeclarationOwner.js +34 -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/CountRequest.d.ts +30 -0
- package/dist/runtime/api/models/CountRequest.js +25 -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 +42 -0
- package/dist/runtime/api/models/ExportRequest.js +31 -0
- package/dist/runtime/api/models/Grant.d.ts +10 -1
- package/dist/runtime/api/models/Grant.js +5 -0
- package/dist/runtime/api/models/MongoAggregateRequest.d.ts +4 -0
- package/dist/runtime/api/models/MongoAggregateRequest.js +4 -2
- package/dist/runtime/api/models/SettingsResponse.d.ts +0 -14
- package/dist/runtime/api/models/SettingsResponse.js +0 -6
- package/dist/runtime/api/models/SuggestedValidator.d.ts +44 -0
- package/dist/runtime/api/models/SuggestedValidator.js +35 -0
- package/dist/runtime/api/models/UpdateManyRequest.d.ts +38 -0
- package/dist/runtime/api/models/{UpdateRequest.js → UpdateManyRequest.js} +7 -7
- 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 +12 -1
- package/dist/runtime/api/models/index.js +12 -1
- package/dist/runtime/composables/mongocampApiCollection.d.ts +14 -15
- package/dist/runtime/composables/mongocampApiCollection.js +4 -1
- package/dist/runtime/composables/mongocampCollection.d.ts +106 -0
- package/dist/runtime/composables/mongocampCollection.js +200 -0
- package/dist/runtime/composables/mongocampLive.d.ts +33 -0
- package/dist/runtime/composables/mongocampLive.js +152 -0
- package/dist/runtime/composables/mongocampSearch.d.ts +12 -9
- package/dist/runtime/server/mongocamp/core.d.ts +2 -0
- package/dist/runtime/server/mongocamp/core.js +8 -1
- package/dist/runtime/server/mongocamp/plugin.d.ts +5 -1
- package/dist/runtime/server/mongocamp/plugin.js +21 -1
- package/dist/runtime/types/collections.d.ts +20 -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/dist/runtime/api/models/UpdateRequest.d.ts +0 -38
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
1
2
|
import type { FindRequest, MongoFindRequest } from '../api/index.js';
|
|
2
3
|
import type { FilterFieldValue } from '../utils/buildFieldFilterExpression.js';
|
|
3
4
|
export declare function useMongocampSearch(): {
|
|
@@ -21,16 +22,18 @@ export interface PaginatedFindOptions {
|
|
|
21
22
|
/** Wildcards of the filter ignore the case (server 2.0.0 matches them case-sensitively by default). */
|
|
22
23
|
filterCaseInsensitive?: boolean;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The pages of a find; `T` types the documents as the server sends them (default as before). Typed and decoded documents:
|
|
27
|
+
* `useMongocampCollection(name).paginated()` (2.3.0).
|
|
28
|
+
*/
|
|
29
|
+
export declare function usePaginatedFind<T = {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
}>(collectionName: string, options?: PaginatedFindOptions): {
|
|
32
|
+
documents: Ref<T[], T[]>;
|
|
33
|
+
page: Ref<number, number>;
|
|
31
34
|
rowsPerPage: any;
|
|
32
|
-
pending:
|
|
33
|
-
error:
|
|
35
|
+
pending: Ref<boolean, boolean>;
|
|
36
|
+
error: Ref<unknown, unknown>;
|
|
34
37
|
load: () => Promise<void>;
|
|
35
38
|
nextPage: () => Promise<void>;
|
|
36
39
|
previousPage: () => Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createMongocampServer } from "@sfxcode/mongocamp-server-core";
|
|
1
|
+
import { connectHooks, createMongocampServer } from "@sfxcode/mongocamp-server-core";
|
|
2
|
+
import { useNitroApp } from "nitro/app";
|
|
2
3
|
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
3
4
|
let server;
|
|
4
5
|
export function useMongocampCore(settings = useRuntimeConfig().mongocampServer) {
|
|
@@ -10,6 +11,12 @@ export function useMongocampCore(settings = useRuntimeConfig().mongocampServer)
|
|
|
10
11
|
config: settings.config,
|
|
11
12
|
jobs: settings.jobs,
|
|
12
13
|
version: settings.version
|
|
14
|
+
}).then(async (created) => {
|
|
15
|
+
const hooks = useNitroApp().hooks;
|
|
16
|
+
if (hooks) {
|
|
17
|
+
await connectHooks(created, hooks);
|
|
18
|
+
}
|
|
19
|
+
return created;
|
|
13
20
|
}).catch((error) => {
|
|
14
21
|
server = void 0;
|
|
15
22
|
throw error;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The Nitro plugin of the embedded server: switches on the features of the module options (`server.requestLogging`, `server.metrics`) and
|
|
3
|
+
* the declared collections of `server/mongocamp/` when the server is ready, and closes it with Nitro. An application adds its own features and listeners the same way, in its own Nitro
|
|
4
|
+
* plugin on the hooks `mongocamp:ready` and `mongocamp:<event>`.
|
|
5
|
+
*/
|
|
2
6
|
declare const _default: import("nitro/types").NitroAppPlugin;
|
|
3
7
|
export default _default;
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
import { collections, metrics, requestLogging } from "@sfxcode/mongocamp-server-core";
|
|
2
|
+
import { declarations } from "#mongocamp/collections";
|
|
1
3
|
import { definePlugin } from "nitro";
|
|
4
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
2
5
|
import { closeMongocampCore } from "./core.js";
|
|
3
6
|
export default definePlugin((nitroApp) => {
|
|
4
|
-
|
|
7
|
+
const settings = useRuntimeConfig().mongocampServer;
|
|
8
|
+
nitroApp.hooks?.hook("mongocamp:ready", async (server) => {
|
|
9
|
+
if (settings.requestLogging) {
|
|
10
|
+
await server.use(requestLogging());
|
|
11
|
+
}
|
|
12
|
+
if (settings.metrics) {
|
|
13
|
+
await server.use(metrics());
|
|
14
|
+
}
|
|
15
|
+
if (declarations.length > 0) {
|
|
16
|
+
for (const { key, source, definition } of declarations) {
|
|
17
|
+
if (definition.name !== key) {
|
|
18
|
+
server.context.logger.warn(`[mongocamp] ${source} declares the collection ${definition.name}: the types of the client know it as ${key}, name the file ${definition.name}.ts`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
await server.use(collections(declarations.map(({ source, definition }) => ({ ...definition, source }))));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
nitroApp.hooks?.hook("close", async () => {
|
|
5
25
|
await closeMongocampCore();
|
|
6
26
|
});
|
|
7
27
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The documents of the declared collections by name (2.3.0). Empty here; the module adds the declarations of `server/mongocamp/*.ts`
|
|
3
|
+
* (`.nuxt/types/mongocamp-collections.d.ts`), an application without the module's scan (external server) can add its own:
|
|
4
|
+
*
|
|
5
|
+
* declare global { interface MongocampCollections { orders: Order } }
|
|
6
|
+
*/
|
|
7
|
+
declare global {
|
|
8
|
+
/** The documents as they are stored (the output of the schema). */
|
|
9
|
+
interface MongocampCollections {
|
|
10
|
+
}
|
|
11
|
+
/** The documents as they are written (the input of the schema: fields with a default are optional); falls back to the stored type. */
|
|
12
|
+
interface MongocampCollectionInputs {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The names of the declared collections. */
|
|
16
|
+
export type MongocampCollectionName = keyof MongocampCollections & string;
|
|
17
|
+
/** The stored document type of a declared collection. */
|
|
18
|
+
export type MongocampDocument<N extends MongocampCollectionName> = MongocampCollections[N];
|
|
19
|
+
/** The written document type of a declared collection. */
|
|
20
|
+
export type MongocampDocumentInput<N extends MongocampCollectionName> = N extends keyof MongocampCollectionInputs ? MongocampCollectionInputs[N] : MongocampCollections[N];
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A parser of Server-Sent Events for a stream read with `fetch` (2.4.0, live updates): `EventSource` cannot send the bearer token of the
|
|
3
|
+
* session. Feed it the decoded text as it arrives; it calls `onEvent` for every complete event (comments are skipped).
|
|
4
|
+
*/
|
|
5
|
+
export interface SseEvent {
|
|
6
|
+
id?: string;
|
|
7
|
+
event: string;
|
|
8
|
+
data: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createSseParser(onEvent: (event: SseEvent) => void): (chunk: string) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function createSseParser(onEvent) {
|
|
2
|
+
let buffer = "";
|
|
3
|
+
return (chunk) => {
|
|
4
|
+
buffer += chunk.replace(/\r\n?/g, "\n");
|
|
5
|
+
let end = buffer.indexOf("\n\n");
|
|
6
|
+
while (end >= 0) {
|
|
7
|
+
const block = buffer.slice(0, end);
|
|
8
|
+
buffer = buffer.slice(end + 2);
|
|
9
|
+
let id;
|
|
10
|
+
let event = "message";
|
|
11
|
+
const data = [];
|
|
12
|
+
for (const line of block.split("\n")) {
|
|
13
|
+
if (line === "" || line.startsWith(":")) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const colon = line.indexOf(":");
|
|
17
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
18
|
+
const value = colon < 0 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
19
|
+
if (field === "id") {
|
|
20
|
+
id = value;
|
|
21
|
+
} else if (field === "event") {
|
|
22
|
+
event = value;
|
|
23
|
+
} else if (field === "data") {
|
|
24
|
+
data.push(value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (data.length > 0 || event !== "message") {
|
|
28
|
+
onEvent({ ...id !== void 0 ? { id } : {}, event, data: data.join("\n") });
|
|
29
|
+
}
|
|
30
|
+
end = buffer.indexOf("\n\n");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import type { ValidationIssue } from '../api/index.js';
|
|
1
2
|
export interface MongocampError {
|
|
2
3
|
status?: number;
|
|
3
4
|
message: string;
|
|
4
5
|
additionalInfo?: string;
|
|
6
|
+
/** The fields of a document that is not valid (400 of a schema, a before-hook or the validator of the collection). */
|
|
7
|
+
issues?: ValidationIssue[];
|
|
8
|
+
/** The error code of the server (`x-error-code`, e.g. 4092 for a version conflict). */
|
|
9
|
+
code?: number;
|
|
10
|
+
/** The stored document of a version conflict (409, code 4092), as the server sends it (Extended JSON). */
|
|
11
|
+
current?: Record<string, unknown>;
|
|
5
12
|
cause: unknown;
|
|
6
13
|
}
|
|
7
14
|
export declare function toMongocampError(error: unknown): Promise<MongocampError>;
|
|
@@ -4,14 +4,31 @@ export async function toMongocampError(error) {
|
|
|
4
4
|
const status = error.response.status;
|
|
5
5
|
let message = `Request failed with status ${status}`;
|
|
6
6
|
let additionalInfo;
|
|
7
|
+
let issues;
|
|
8
|
+
let code;
|
|
9
|
+
let current;
|
|
7
10
|
try {
|
|
8
11
|
const body = await error.response.clone().json();
|
|
9
12
|
if (body?.msg)
|
|
10
13
|
message = body.msg;
|
|
11
14
|
additionalInfo = body?.additionalInfo;
|
|
15
|
+
if (Array.isArray(body?.issues))
|
|
16
|
+
issues = body.issues;
|
|
17
|
+
if (typeof body?.code === "number")
|
|
18
|
+
code = body.code;
|
|
19
|
+
if (body?.current && typeof body.current === "object")
|
|
20
|
+
current = body.current;
|
|
12
21
|
} catch {
|
|
13
22
|
}
|
|
14
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
status,
|
|
25
|
+
message,
|
|
26
|
+
additionalInfo,
|
|
27
|
+
...issues ? { issues } : {},
|
|
28
|
+
...code !== void 0 ? { code } : {},
|
|
29
|
+
...current ? { current } : {},
|
|
30
|
+
cause: error
|
|
31
|
+
};
|
|
15
32
|
}
|
|
16
33
|
if (error instanceof Error)
|
|
17
34
|
return { message: error.message, cause: error };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export { type AuditEntry, type CollectionFindOptions, type CollectionPage, type DocumentIdentity, type MongocampRequestError, type PaginatedCollection, type TypedCollection } from '../dist/runtime/composables/mongocampCollection.js'
|
|
2
|
+
|
|
3
|
+
export { type MongocampCollectionName, type MongocampDocument, type MongocampDocumentInput } from '../dist/runtime/types/collections.js'
|
|
4
|
+
|
|
5
|
+
export { type LiveOptions, type LiveState, type LiveStatus } from '../dist/runtime/composables/mongocampLive.js'
|
|
6
|
+
|
|
1
7
|
export { default } from './module.mjs'
|
|
2
8
|
|
|
3
9
|
export { type ModuleOptions, type ServerOptions } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sfxcode/nuxt-mongocamp-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@nuxt/kit": "^4.7.0",
|
|
32
|
-
"@sfxcode/mongocamp-server-core": "2.
|
|
32
|
+
"@sfxcode/mongocamp-server-core": "2.3.0",
|
|
33
33
|
"@vueuse/nuxt": "^15.1.0",
|
|
34
34
|
"bson": "^7.3.4",
|
|
35
35
|
"consola": "^3.4.2",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"nuxt": "^4.7.0",
|
|
54
54
|
"srvx": "1.0.8",
|
|
55
55
|
"typescript": "6.0.3",
|
|
56
|
-
"vitest": "^5.1.2"
|
|
56
|
+
"vitest": "^5.1.2",
|
|
57
|
+
"zod": "^4.6.7"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
60
|
"nitro": ">=3.0.261103-rc",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mongocamp-library
|
|
3
|
-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
-
*
|
|
5
|
-
* The version of the OpenAPI document: 2.0.0
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
-
* https://openapi-generator.tech
|
|
10
|
-
* Do not edit the class manually.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @export
|
|
15
|
-
* @interface UpdateRequest
|
|
16
|
-
*/
|
|
17
|
-
export interface UpdateRequest {
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
document: {
|
|
22
|
-
[key: string]: any | null;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
filter: {
|
|
28
|
-
[key: string]: any | null;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Check if a given object implements the UpdateRequest interface.
|
|
33
|
-
*/
|
|
34
|
-
export declare function instanceOfUpdateRequest(value: object): value is UpdateRequest;
|
|
35
|
-
export declare function UpdateRequestFromJSON(json: any): UpdateRequest;
|
|
36
|
-
export declare function UpdateRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): UpdateRequest;
|
|
37
|
-
export declare function UpdateRequestToJSON(json: any): UpdateRequest;
|
|
38
|
-
export declare function UpdateRequestToJSONTyped(value?: UpdateRequest | null, ignoreDiscriminator?: boolean): any;
|