@sfxcode/nuxt-mongocamp-server 2.3.0 → 2.5.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 +24 -2
- package/dist/module.d.mts +10 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +41 -21
- package/dist/runtime/api/.openapi-generator/FILES +4 -0
- package/dist/runtime/api/apis/CollectionApi.d.ts +6 -6
- package/dist/runtime/api/apis/CollectionApi.js +4 -4
- package/dist/runtime/api/apis/DocumentApi.d.ts +42 -14
- package/dist/runtime/api/apis/DocumentApi.js +27 -6
- package/dist/runtime/api/docs/CollectionApi.md +6 -6
- package/dist/runtime/api/docs/CollectionDeclaration.md +4 -0
- package/dist/runtime/api/docs/CollectionDeclarationIndexesInner.md +38 -0
- package/dist/runtime/api/docs/CollectionDeclarationRefsInner.md +38 -0
- package/dist/runtime/api/docs/DocumentApi.md +47 -26
- 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/models/CollectionDeclaration.d.ts +10 -0
- package/dist/runtime/api/models/CollectionDeclaration.js +14 -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/CollectionDeclarationRefsInner.d.ts +38 -0
- package/dist/runtime/api/models/CollectionDeclarationRefsInner.js +31 -0
- package/dist/runtime/api/models/ErrorDescription.d.ts +1 -1
- 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/index.d.ts +2 -0
- package/dist/runtime/api/models/index.js +2 -0
- package/dist/runtime/composables/mongocampApi.d.ts +4 -0
- package/dist/runtime/composables/mongocampApi.js +10 -2
- package/dist/runtime/composables/mongocampAuth.js +29 -25
- package/dist/runtime/composables/mongocampCollection.d.ts +50 -11
- package/dist/runtime/composables/mongocampCollection.js +85 -21
- package/dist/runtime/composables/mongocampLive.d.ts +5 -2
- package/dist/runtime/composables/mongocampLive.js +30 -5
- package/dist/runtime/composables/mongocampSearch.js +12 -3
- package/dist/runtime/plugins/bson-payload.d.ts +8 -0
- package/dist/runtime/plugins/bson-payload.js +6 -0
- package/dist/runtime/server/composables/mongocampApi.d.ts +5 -1
- package/dist/runtime/server/composables/mongocampApi.js +1 -9
- package/dist/runtime/server/composables/mongocampServerApi.d.ts +4 -0
- package/dist/runtime/server/composables/mongocampServerApi.js +5 -0
- package/dist/runtime/server/composables/mongocampServerCollection.d.ts +20 -0
- package/dist/runtime/server/composables/mongocampServerCollection.js +12 -0
- package/dist/runtime/server/mongocamp/core.d.ts +1 -1
- package/dist/runtime/server/mongocamp/core.js +1 -1
- package/dist/runtime/server/mongocamp/embedded-api.d.ts +18 -0
- package/dist/runtime/server/mongocamp/embedded-api.js +10 -0
- package/dist/runtime/types/collections.d.ts +10 -0
- package/dist/runtime/utils/appState.d.ts +21 -0
- package/dist/runtime/utils/appState.js +11 -0
- package/dist/runtime/utils/bsonPayload.d.ts +8 -0
- package/dist/runtime/utils/bsonPayload.js +10 -0
- package/dist/runtime/utils/buildFieldFilterExpression.d.ts +4 -0
- package/dist/runtime/utils/buildFieldFilterExpression.js +5 -3
- package/dist/runtime/utils/sse.d.ts +1 -1
- package/dist/runtime/utils/sse.js +7 -1
- package/package.json +15 -7
|
@@ -0,0 +1,38 @@
|
|
|
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 CollectionDeclarationRefsInner
|
|
16
|
+
*/
|
|
17
|
+
export interface CollectionDeclarationRefsInner {
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
field: string;
|
|
22
|
+
/**
|
|
23
|
+
* The target collection (name or database:name).
|
|
24
|
+
*/
|
|
25
|
+
collection: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the field holds an array of ids (from the schema); missing when the schema does not tell.
|
|
28
|
+
*/
|
|
29
|
+
many?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if a given object implements the CollectionDeclarationRefsInner interface.
|
|
33
|
+
*/
|
|
34
|
+
export declare function instanceOfCollectionDeclarationRefsInner(value: object): value is CollectionDeclarationRefsInner;
|
|
35
|
+
export declare function CollectionDeclarationRefsInnerFromJSON(json: any): CollectionDeclarationRefsInner;
|
|
36
|
+
export declare function CollectionDeclarationRefsInnerFromJSONTyped(json: any, ignoreDiscriminator: boolean): CollectionDeclarationRefsInner;
|
|
37
|
+
export declare function CollectionDeclarationRefsInnerToJSON(json: any): CollectionDeclarationRefsInner;
|
|
38
|
+
export declare function CollectionDeclarationRefsInnerToJSONTyped(value?: CollectionDeclarationRefsInner | null, ignoreDiscriminator?: boolean): any;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function instanceOfCollectionDeclarationRefsInner(value) {
|
|
2
|
+
if (!("field" in value) || value["field"] === void 0) return false;
|
|
3
|
+
if (!("collection" in value) || value["collection"] === void 0) return false;
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
export function CollectionDeclarationRefsInnerFromJSON(json) {
|
|
7
|
+
return CollectionDeclarationRefsInnerFromJSONTyped(json, false);
|
|
8
|
+
}
|
|
9
|
+
export function CollectionDeclarationRefsInnerFromJSONTyped(json, ignoreDiscriminator) {
|
|
10
|
+
if (json == null) {
|
|
11
|
+
return json;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
"field": json["field"],
|
|
15
|
+
"collection": json["collection"],
|
|
16
|
+
"many": json["many"] == null ? void 0 : json["many"]
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function CollectionDeclarationRefsInnerToJSON(json) {
|
|
20
|
+
return CollectionDeclarationRefsInnerToJSONTyped(json, false);
|
|
21
|
+
}
|
|
22
|
+
export function CollectionDeclarationRefsInnerToJSONTyped(value, ignoreDiscriminator = false) {
|
|
23
|
+
if (value == null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
"field": value["field"],
|
|
28
|
+
"collection": value["collection"],
|
|
29
|
+
"many": value["many"]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -33,7 +33,7 @@ export interface ErrorDescription {
|
|
|
33
33
|
*/
|
|
34
34
|
issues?: Array<ValidationIssue>;
|
|
35
35
|
/**
|
|
36
|
-
* The stored document of a version conflict (409, code 4092, 2.
|
|
36
|
+
* The stored document of a version conflict (409, code 4092, 2.3.0), as Extended JSON: show it or merge with it, then send the change again with its version.
|
|
37
37
|
*/
|
|
38
38
|
current?: {
|
|
39
39
|
[key: string]: any;
|
|
@@ -12,7 +12,8 @@ export function ExportRequestFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
12
12
|
"filter": json["filter"] == null ? void 0 : json["filter"],
|
|
13
13
|
"sort": json["sort"] == null ? void 0 : json["sort"],
|
|
14
14
|
"projection": json["projection"] == null ? void 0 : json["projection"],
|
|
15
|
-
"limit": json["limit"] == null ? void 0 : json["limit"]
|
|
15
|
+
"limit": json["limit"] == null ? void 0 : json["limit"],
|
|
16
|
+
"expand": json["expand"] == null ? void 0 : json["expand"]
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
export function ExportRequestToJSON(json) {
|
|
@@ -26,6 +27,7 @@ export function ExportRequestToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
26
27
|
"filter": value["filter"],
|
|
27
28
|
"sort": value["sort"],
|
|
28
29
|
"projection": value["projection"],
|
|
29
|
-
"limit": value["limit"]
|
|
30
|
+
"limit": value["limit"],
|
|
31
|
+
"expand": value["expand"]
|
|
30
32
|
};
|
|
31
33
|
}
|
|
@@ -33,6 +33,10 @@ export interface MongoFindRequest {
|
|
|
33
33
|
projection: {
|
|
34
34
|
[key: string]: any | null;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* References to expand (2.4.0), like the query parameter expand.
|
|
38
|
+
*/
|
|
39
|
+
expand?: Array<string>;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Check if a given object implements the MongoFindRequest interface.
|
|
@@ -14,7 +14,8 @@ export function MongoFindRequestFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
14
14
|
return {
|
|
15
15
|
"filter": json["filter"],
|
|
16
16
|
"sort": json["sort"],
|
|
17
|
-
"projection": json["projection"]
|
|
17
|
+
"projection": json["projection"],
|
|
18
|
+
"expand": json["expand"] == null ? void 0 : json["expand"]
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
export function MongoFindRequestToJSON(json) {
|
|
@@ -27,6 +28,7 @@ export function MongoFindRequestToJSONTyped(value, ignoreDiscriminator = false)
|
|
|
27
28
|
return {
|
|
28
29
|
"filter": value["filter"],
|
|
29
30
|
"sort": value["sort"],
|
|
30
|
-
"projection": value["projection"]
|
|
31
|
+
"projection": value["projection"],
|
|
32
|
+
"expand": value["expand"]
|
|
31
33
|
};
|
|
32
34
|
}
|
|
@@ -27,6 +27,10 @@ export interface SearchRequest {
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
projection?: Array<string>;
|
|
30
|
+
/**
|
|
31
|
+
* References to expand (2.4.0), like the query parameter expand.
|
|
32
|
+
*/
|
|
33
|
+
expand?: Array<string>;
|
|
30
34
|
}
|
|
31
35
|
/**
|
|
32
36
|
* Check if a given object implements the SearchRequest interface.
|
|
@@ -11,7 +11,8 @@ export function SearchRequestFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
11
11
|
return {
|
|
12
12
|
"filter": json["filter"] == null ? void 0 : json["filter"],
|
|
13
13
|
"sort": json["sort"] == null ? void 0 : json["sort"],
|
|
14
|
-
"projection": json["projection"] == null ? void 0 : json["projection"]
|
|
14
|
+
"projection": json["projection"] == null ? void 0 : json["projection"],
|
|
15
|
+
"expand": json["expand"] == null ? void 0 : json["expand"]
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
export function SearchRequestToJSON(json) {
|
|
@@ -24,6 +25,7 @@ export function SearchRequestToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
24
25
|
return {
|
|
25
26
|
"filter": value["filter"],
|
|
26
27
|
"sort": value["sort"],
|
|
27
|
-
"projection": value["projection"]
|
|
28
|
+
"projection": value["projection"],
|
|
29
|
+
"expand": value["expand"]
|
|
28
30
|
};
|
|
29
31
|
}
|
|
@@ -7,7 +7,9 @@ export * from './ClusterMemberInformation.js';
|
|
|
7
7
|
export * from './CollectionCollation.js';
|
|
8
8
|
export * from './CollectionDeclaration.js';
|
|
9
9
|
export * from './CollectionDeclarationAudit.js';
|
|
10
|
+
export * from './CollectionDeclarationIndexesInner.js';
|
|
10
11
|
export * from './CollectionDeclarationOwner.js';
|
|
12
|
+
export * from './CollectionDeclarationRefsInner.js';
|
|
11
13
|
export * from './CollectionDeclarationSoftDelete.js';
|
|
12
14
|
export * from './CollectionDeclarationTimestamps.js';
|
|
13
15
|
export * from './CollectionDeclarationVersioned.js';
|
|
@@ -7,7 +7,9 @@ export * from "./ClusterMemberInformation.js";
|
|
|
7
7
|
export * from "./CollectionCollation.js";
|
|
8
8
|
export * from "./CollectionDeclaration.js";
|
|
9
9
|
export * from "./CollectionDeclarationAudit.js";
|
|
10
|
+
export * from "./CollectionDeclarationIndexesInner.js";
|
|
10
11
|
export * from "./CollectionDeclarationOwner.js";
|
|
12
|
+
export * from "./CollectionDeclarationRefsInner.js";
|
|
11
13
|
export * from "./CollectionDeclarationSoftDelete.js";
|
|
12
14
|
export * from "./CollectionDeclarationTimestamps.js";
|
|
13
15
|
export * from "./CollectionDeclarationVersioned.js";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generated clients for the browser and server side rendering, with the token of the session. Created once per Nuxt app and url
|
|
3
|
+
* (2.5.0; before, on every call): the token is read per request, so the clients stay valid after a login or a refresh.
|
|
4
|
+
*/
|
|
1
5
|
export declare function useMongocampApi(): {
|
|
2
6
|
adminApi: import("../api/index.js").AdminApi;
|
|
3
7
|
applicationApi: import("../api/index.js").ApplicationApi;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { useRequestFetch } from "#app";
|
|
2
2
|
import { Configuration } from "../api/index.js";
|
|
3
|
+
import { mongocampAppState } from "../utils/appState.js";
|
|
3
4
|
import { createMongocampApis } from "../utils/createMongocampApis.js";
|
|
4
5
|
import { useMongocampUrl } from "./mongocampUrl.js";
|
|
5
6
|
import { useMongocampStorage } from "./mongocampStorage.js";
|
|
6
7
|
export function useMongocampApi() {
|
|
7
8
|
const url = useMongocampUrl();
|
|
9
|
+
const { apis } = mongocampAppState();
|
|
10
|
+
const known = apis.get(url);
|
|
11
|
+
if (known !== void 0) {
|
|
12
|
+
return known;
|
|
13
|
+
}
|
|
8
14
|
const state = useMongocampStorage();
|
|
9
15
|
let fetchApi;
|
|
10
16
|
if (import.meta.server && url?.startsWith("/")) {
|
|
11
17
|
const requestFetch = useRequestFetch();
|
|
12
|
-
fetchApi = (
|
|
18
|
+
fetchApi = (input, init) => requestFetch.native(input, init);
|
|
13
19
|
}
|
|
14
20
|
const configuration = new Configuration({
|
|
15
21
|
basePath: url,
|
|
@@ -28,5 +34,7 @@ export function useMongocampApi() {
|
|
|
28
34
|
}
|
|
29
35
|
}]
|
|
30
36
|
});
|
|
31
|
-
|
|
37
|
+
const created = createMongocampApis(configuration);
|
|
38
|
+
apis.set(url, created);
|
|
39
|
+
return created;
|
|
32
40
|
}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
import { computed, watch } from "vue";
|
|
1
|
+
import { computed, effectScope, watch } from "vue";
|
|
2
2
|
import { consola } from "consola";
|
|
3
|
+
import { mongocampAppState } from "../utils/appState.js";
|
|
3
4
|
import { toMongocampError } from "../utils/toMongocampError.js";
|
|
4
5
|
import { useMongocampApi } from "./mongocampApi.js";
|
|
5
6
|
import { useMongocampStorage } from "./mongocampStorage.js";
|
|
6
|
-
import { useRuntimeConfig
|
|
7
|
+
import { useRuntimeConfig } from "#app";
|
|
7
8
|
export function useMongocampAuth() {
|
|
8
9
|
const config = useRuntimeConfig();
|
|
9
10
|
const refreshToken = config.public.mongocamp?.refreshToken;
|
|
10
11
|
const tokenRefreshInterval = config.public.mongocamp?.tokenRefreshInterval;
|
|
11
12
|
const state = useMongocampStorage();
|
|
12
13
|
const { authApi } = useMongocampApi();
|
|
13
|
-
const
|
|
14
|
+
const { auth } = mongocampAppState();
|
|
15
|
+
function updateUserState(result) {
|
|
16
|
+
state.value.token = result.authToken;
|
|
17
|
+
state.value.profile = result.userProfile;
|
|
18
|
+
}
|
|
19
|
+
const logout = () => {
|
|
20
|
+
if (state.value.token)
|
|
21
|
+
authApi.logout().catch((e) => consola.error(e));
|
|
22
|
+
state.value.token = "";
|
|
23
|
+
state.value.profile = { user: "", isAdmin: false };
|
|
24
|
+
};
|
|
14
25
|
function startTokenRefresh() {
|
|
15
|
-
if (import.meta.client && refreshToken &&
|
|
16
|
-
|
|
26
|
+
if (import.meta.client && refreshToken && auth.timer === void 0)
|
|
27
|
+
auth.timer = setInterval(updateToken, tokenRefreshInterval);
|
|
17
28
|
}
|
|
18
29
|
function stopTokenRefresh() {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
if (auth.timer !== void 0) {
|
|
31
|
+
clearInterval(auth.timer);
|
|
32
|
+
auth.timer = void 0;
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
async function isAuthenticated() {
|
|
@@ -35,10 +46,6 @@ export function useMongocampAuth() {
|
|
|
35
46
|
logout();
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
|
-
function updateUserState(result) {
|
|
39
|
-
state.value.token = result.authToken;
|
|
40
|
-
state.value.profile = result.userProfile;
|
|
41
|
-
}
|
|
42
49
|
const login = async (loginId, loginPassword) => {
|
|
43
50
|
logout();
|
|
44
51
|
const login2 = { userId: loginId, password: loginPassword };
|
|
@@ -46,20 +53,17 @@ export function useMongocampAuth() {
|
|
|
46
53
|
updateUserState(result);
|
|
47
54
|
return result.userProfile;
|
|
48
55
|
};
|
|
49
|
-
const logout = () => {
|
|
50
|
-
if (state.value.token)
|
|
51
|
-
authApi.logout().catch((e) => consola.error(e));
|
|
52
|
-
state.value.token = "";
|
|
53
|
-
state.value.profile = { user: "", isAdmin: false };
|
|
54
|
-
};
|
|
55
56
|
const isLoggedIn = computed(() => (state.value.token?.length ?? 0) > 0);
|
|
56
|
-
if (import.meta.client) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (import.meta.client && auth.scope === void 0) {
|
|
58
|
+
auth.scope = effectScope(true);
|
|
59
|
+
auth.scope.run(() => {
|
|
60
|
+
watch(isLoggedIn, (loggedIn) => {
|
|
61
|
+
if (loggedIn)
|
|
62
|
+
startTokenRefresh();
|
|
63
|
+
else
|
|
64
|
+
stopTokenRefresh();
|
|
65
|
+
}, { immediate: true });
|
|
66
|
+
});
|
|
63
67
|
}
|
|
64
68
|
const userRoles = computed(() => state.value.profile.roles ?? []);
|
|
65
69
|
const userGrants = computed(() => state.value.profile.grants ?? []);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Ref } from 'vue';
|
|
2
2
|
import type { DeleteResponse, InsertResponse, UpdateResponse } from '../api/index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ExpandedDocument } from '@sfxcode/mongocamp-server-core';
|
|
4
|
+
import type { MongocampCollectionName, MongocampDocument, MongocampDocumentInput, MongocampRefs } from '../types/collections.js';
|
|
4
5
|
import type { MongocampError } from '../utils/toMongocampError.js';
|
|
5
6
|
/**
|
|
6
7
|
* The documents of one collection with their types (2.3.0): `useMongocampCollection('orders')` for a declared collection
|
|
@@ -10,7 +11,7 @@ import type { MongocampError } from '../utils/toMongocampError.js';
|
|
|
10
11
|
*/
|
|
11
12
|
/**
|
|
12
13
|
* An error of a request: an `Error` with the status and the fields of the error response (`issues` for documents that are not valid).
|
|
13
|
-
* `isConflict` (2.
|
|
14
|
+
* `isConflict` (2.3.0): a change based on an outdated version; `current` is the stored document then (decoded), to show or merge.
|
|
14
15
|
*/
|
|
15
16
|
export type MongocampRequestError = Error & Omit<MongocampError, 'current'> & {
|
|
16
17
|
isConflict: boolean;
|
|
@@ -29,7 +30,26 @@ export interface CollectionFindOptions {
|
|
|
29
30
|
filterCaseInsensitive?: boolean;
|
|
30
31
|
/** Soft-deleted documents too (collections declared with `softDelete`, administrators of the collection only). */
|
|
31
32
|
withDeleted?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* References to expand (2.4.0): declared `refs` fields become the referenced documents, read with your grants on their collection
|
|
35
|
+
* (`null`, or left out of an array, when you cannot read one).
|
|
36
|
+
*/
|
|
37
|
+
expand?: readonly string[];
|
|
32
38
|
}
|
|
39
|
+
/** The options of a find that expands the references `K`. */
|
|
40
|
+
export type ExpandingFindOptions<K extends string> = Omit<CollectionFindOptions, 'expand'> & {
|
|
41
|
+
expand: readonly K[];
|
|
42
|
+
};
|
|
43
|
+
/** The options of a find: `expand` only with the references of the collection. */
|
|
44
|
+
export type FindOptionsOf<Refs> = Omit<CollectionFindOptions, 'expand'> & {
|
|
45
|
+
expand?: readonly (keyof Refs & string)[];
|
|
46
|
+
};
|
|
47
|
+
/** A document of `T` with the references `K` of `Refs` expanded to the documents of the declared collections. */
|
|
48
|
+
export type Expanded<T, Refs, K extends keyof Refs & string> = ExpandedDocument<T, Refs, K, MongocampCollections>;
|
|
49
|
+
/** Marks a document that was read with `expand`: its expanded fields (an enumerable symbol, kept by spreads, never sent). */
|
|
50
|
+
export declare const ExpandedFields: unique symbol;
|
|
51
|
+
/** Marks the documents of a read with `expand` (`ExpandedFields`), for writing them back. */
|
|
52
|
+
export declare function markExpanded<D extends Record<string, unknown>>(document: D, fields: readonly string[] | undefined): D;
|
|
33
53
|
export interface UpdateOptions {
|
|
34
54
|
/** On a version conflict, apply the changes once more to the stored document (its version) instead of failing. */
|
|
35
55
|
retryOnConflict?: boolean;
|
|
@@ -42,7 +62,7 @@ export interface CollectionPage<T> {
|
|
|
42
62
|
countRows?: number;
|
|
43
63
|
countPages?: number;
|
|
44
64
|
}
|
|
45
|
-
/** One change of a document from the audit records (collections declared with `audit`, 2.
|
|
65
|
+
/** One change of a document from the audit records (collections declared with `audit`, 2.3.0); before and after decoded and typed. */
|
|
46
66
|
export interface AuditEntry<T> {
|
|
47
67
|
operation: 'insert' | 'replace' | 'update' | 'delete' | 'softDelete' | 'restore';
|
|
48
68
|
user: string;
|
|
@@ -52,23 +72,39 @@ export interface AuditEntry<T> {
|
|
|
52
72
|
after?: T;
|
|
53
73
|
}
|
|
54
74
|
/** The id of a document: the text of the path, an `ObjectId` or a document with `_id`. */
|
|
75
|
+
/** (2.5.0: `_id` optional, as in the type of a declared schema; a document without one is refused when it is used.) */
|
|
55
76
|
export type DocumentIdentity = string | number | {
|
|
56
77
|
toHexString: () => string;
|
|
57
78
|
} | {
|
|
58
|
-
_id
|
|
79
|
+
_id?: unknown;
|
|
59
80
|
};
|
|
60
|
-
export interface TypedCollection<T, I = T
|
|
81
|
+
export interface TypedCollection<T, I = T, Refs = Record<string, string>> {
|
|
61
82
|
readonly name: string;
|
|
62
|
-
find:
|
|
63
|
-
|
|
83
|
+
find: {
|
|
84
|
+
<K extends keyof Refs & string>(options: ExpandingFindOptions<K>): Promise<Expanded<T, Refs, K>[]>;
|
|
85
|
+
(options?: FindOptionsOf<Refs>): Promise<T[]>;
|
|
86
|
+
};
|
|
87
|
+
findPage: {
|
|
88
|
+
<K extends keyof Refs & string>(options: ExpandingFindOptions<K>): Promise<CollectionPage<Expanded<T, Refs, K>>>;
|
|
89
|
+
(options?: FindOptionsOf<Refs>): Promise<CollectionPage<T>>;
|
|
90
|
+
};
|
|
64
91
|
/** The document, `null` when there is none with the id. */
|
|
65
|
-
findById:
|
|
92
|
+
findById: {
|
|
93
|
+
<K extends keyof Refs & string>(id: DocumentIdentity, options: {
|
|
94
|
+
expand: readonly K[];
|
|
95
|
+
}): Promise<Expanded<T, Refs, K> | null>;
|
|
96
|
+
(id: DocumentIdentity, options?: {
|
|
97
|
+
expand?: readonly (keyof Refs & string)[];
|
|
98
|
+
}): Promise<T | null>;
|
|
99
|
+
};
|
|
66
100
|
/** Inserts a document; fields the server writes (timestamps, owner, version) and protected fields are left out. */
|
|
67
101
|
insert: (document: I) => Promise<InsertResponse>;
|
|
68
102
|
insertMany: (documents: I[]) => Promise<InsertResponse>;
|
|
69
103
|
/**
|
|
70
104
|
* Replaces the whole document. Given the document that was read (not only its id), its version goes with the request: a change of
|
|
71
|
-
* someone else in the meantime answers 409 (`isConflict`) instead of being overwritten.
|
|
105
|
+
* someone else in the meantime answers 409 (`isConflict`) instead of being overwritten. Expanded references are sent as their ids; a
|
|
106
|
+
* document read with `expand` whose reference is `null` or an array is refused (a reference you cannot read is unknown here) — use
|
|
107
|
+
* `update` with the changed fields.
|
|
72
108
|
*/
|
|
73
109
|
replace: (target: DocumentIdentity, document: I, options?: UpdateOptions) => Promise<UpdateResponse>;
|
|
74
110
|
/** Changes the given fields (`$set`); with the document that was read, its version goes with the request (see `replace`). */
|
|
@@ -82,7 +118,10 @@ export interface TypedCollection<T, I = T> {
|
|
|
82
118
|
*/
|
|
83
119
|
isMine: (document: T | null | undefined) => boolean;
|
|
84
120
|
/** The pages of a find as reactive state. */
|
|
85
|
-
paginated:
|
|
121
|
+
paginated: {
|
|
122
|
+
<K extends keyof Refs & string>(options: Omit<ExpandingFindOptions<K>, 'page'>): PaginatedCollection<Expanded<T, Refs, K>>;
|
|
123
|
+
(options?: Omit<FindOptionsOf<Refs>, 'page'>): PaginatedCollection<T>;
|
|
124
|
+
};
|
|
86
125
|
/** The changes of a document, newest first (collections declared with `audit`). */
|
|
87
126
|
history: (id: DocumentIdentity, options?: {
|
|
88
127
|
page?: number;
|
|
@@ -102,5 +141,5 @@ export interface PaginatedCollection<T> {
|
|
|
102
141
|
nextPage: () => Promise<void>;
|
|
103
142
|
previousPage: () => Promise<void>;
|
|
104
143
|
}
|
|
105
|
-
export declare function useMongocampCollection<N extends MongocampCollectionName>(name: N): TypedCollection<MongocampDocument<N>, MongocampDocumentInput<N>>;
|
|
144
|
+
export declare function useMongocampCollection<N extends MongocampCollectionName>(name: N): TypedCollection<MongocampDocument<N>, MongocampDocumentInput<N>, MongocampRefs<N>>;
|
|
106
145
|
export declare function useMongocampCollection<T extends object = Record<string, unknown>, I = T>(name: string): TypedCollection<T, I>;
|