@sfxcode/nuxt-mongocamp-server 1.4.4 → 1.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.
Files changed (34) hide show
  1. package/README.md +63 -0
  2. package/dist/module.d.mts +16 -3
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +20 -642
  5. package/dist/runtime/composables/mongocampApi.d.ts +11 -22
  6. package/dist/runtime/composables/mongocampApi.js +4 -37
  7. package/dist/runtime/composables/mongocampApiAdmin.d.ts +15 -0
  8. package/dist/runtime/composables/mongocampApiAdmin.js +41 -0
  9. package/dist/runtime/composables/mongocampApiCollection.d.ts +26 -0
  10. package/dist/runtime/composables/mongocampApiCollection.js +40 -0
  11. package/dist/runtime/composables/mongocampApiCollections.d.ts +8 -0
  12. package/dist/runtime/composables/mongocampApiCollections.js +23 -0
  13. package/dist/runtime/composables/mongocampApiFiles.d.ts +14 -0
  14. package/dist/runtime/composables/mongocampApiFiles.js +38 -0
  15. package/dist/runtime/composables/mongocampApiJobs.d.ts +9 -0
  16. package/dist/runtime/composables/mongocampApiJobs.js +23 -0
  17. package/dist/runtime/composables/mongocampAuth.js +30 -22
  18. package/dist/runtime/composables/mongocampSearch.d.ts +23 -1
  19. package/dist/runtime/composables/mongocampSearch.js +34 -1
  20. package/dist/runtime/composables/mongocampStorage.d.ts +3 -2
  21. package/dist/runtime/composables/mongocampStorage.js +4 -3
  22. package/dist/runtime/composables/mongocampUser.js +1 -1
  23. package/dist/runtime/server/composables/mongocampApi.d.ts +14 -0
  24. package/dist/runtime/server/composables/mongocampApi.js +8 -0
  25. package/dist/runtime/server/composables/mongocampServerApi.d.ts +11 -12
  26. package/dist/runtime/server/composables/mongocampServerApi.js +4 -39
  27. package/dist/runtime/utils/buildFieldFilterExpression.d.ts +2 -0
  28. package/dist/runtime/utils/buildFieldFilterExpression.js +7 -0
  29. package/dist/runtime/utils/createMongocampApis.d.ts +15 -0
  30. package/dist/runtime/utils/createMongocampApis.js +28 -0
  31. package/dist/runtime/utils/toMongocampError.d.ts +7 -0
  32. package/dist/runtime/utils/toMongocampError.js +19 -0
  33. package/dist/types.d.mts +1 -1
  34. package/package.json +9 -3
@@ -1,43 +1,10 @@
1
- import { AdminApi } from "../api/apis/AdminApi.js";
2
- import { ApplicationApi } from "../api/apis/ApplicationApi.js";
3
- import { AuthApi } from "../api/apis/AuthApi.js";
4
- import { BucketApi } from "../api/apis/BucketApi.js";
5
- import { CollectionApi } from "../api/apis/CollectionApi.js";
6
- import { DatabaseApi } from "../api/apis/DatabaseApi.js";
7
- import { DocumentApi } from "../api/apis/DocumentApi.js";
8
- import { FileApi } from "../api/apis/FileApi.js";
9
- import { IndexApi } from "../api/apis/IndexApi.js";
10
- import { InformationApi } from "../api/apis/InformationApi.js";
11
- import { JobsApi } from "../api/apis/JobsApi.js";
12
1
  import { Configuration } from "../api/index.js";
2
+ import { createMongocampApis } from "../utils/createMongocampApis.js";
13
3
  import { useMongocampUrl } from "./mongocampUrl.js";
14
4
  import { useMongocampStorage } from "./mongocampStorage.js";
15
5
  export function useMongocampApi() {
16
6
  const url = useMongocampUrl();
17
- const token = useMongocampStorage();
18
- const configuration = new Configuration({ basePath: url, accessToken: token.value.token });
19
- const adminApi = new AdminApi(configuration);
20
- const applicationApi = new ApplicationApi(configuration);
21
- const authApi = new AuthApi(configuration);
22
- const bucketApi = new BucketApi(configuration);
23
- const collectionApi = new CollectionApi(configuration);
24
- const databaseApi = new DatabaseApi(configuration);
25
- const documentApi = new DocumentApi(configuration);
26
- const fileApi = new FileApi(configuration);
27
- const indexApi = new IndexApi(configuration);
28
- const informationApi = new InformationApi(configuration);
29
- const jobApi = new JobsApi(configuration);
30
- return {
31
- adminApi,
32
- applicationApi,
33
- authApi,
34
- bucketApi,
35
- collectionApi,
36
- databaseApi,
37
- documentApi,
38
- fileApi,
39
- indexApi,
40
- informationApi,
41
- jobApi
42
- };
7
+ const state = useMongocampStorage();
8
+ const configuration = new Configuration({ basePath: url, accessToken: () => state.value.token });
9
+ return createMongocampApis(configuration);
43
10
  }
@@ -0,0 +1,15 @@
1
+ import type { PasswordUpdateRequest, Role, UpdateRoleRequest, UserInformation } from '../api/index.js';
2
+ export declare function useMongocampApiAdmin(): {
3
+ listUsers: (filter?: string, rowsPerPage?: number, page?: number) => Promise<import("../api/index.js").UserProfile[]>;
4
+ getUser: (userId: string) => Promise<import("../api/index.js").UserProfile>;
5
+ addUser: (userInformation: UserInformation) => Promise<import("../api/index.js").UserProfile>;
6
+ deleteUser: (userId: string) => Promise<import("../api/index.js").JsonValueBoolean>;
7
+ updatePasswordForUser: (userId: string, passwordUpdateRequest: PasswordUpdateRequest) => Promise<import("../api/index.js").JsonValueBoolean>;
8
+ updateRolesForUser: (userId: string, roles: string[]) => Promise<import("../api/index.js").UserProfile>;
9
+ generateNewApiKeyForUser: (userId: string) => Promise<import("../api/index.js").JsonValueString>;
10
+ listRoles: (filter?: string, rowsPerPage?: number, page?: number) => Promise<Role[]>;
11
+ getRole: (roleName: string) => Promise<Role>;
12
+ addRole: (role: Role) => Promise<Role>;
13
+ updateRole: (roleName: string, updateRoleRequest: UpdateRoleRequest) => Promise<Role>;
14
+ deleteRole: (roleName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
15
+ };
@@ -0,0 +1,41 @@
1
+ import { useMongocampApi } from "./mongocampApi.js";
2
+ export function useMongocampApiAdmin() {
3
+ const { adminApi } = useMongocampApi();
4
+ function listUsers(filter, rowsPerPage, page) {
5
+ return adminApi.listUsers({ filter, rowsPerPage, page });
6
+ }
7
+ function getUser(userId) {
8
+ return adminApi.getUser({ userId });
9
+ }
10
+ function addUser(userInformation) {
11
+ return adminApi.addUser({ userInformation });
12
+ }
13
+ function deleteUser(userId) {
14
+ return adminApi.deleteUser({ userId });
15
+ }
16
+ function updatePasswordForUser(userId, passwordUpdateRequest) {
17
+ return adminApi.updatePasswordForUser({ userId, passwordUpdateRequest });
18
+ }
19
+ function updateRolesForUser(userId, roles) {
20
+ return adminApi.updateRolesForUser({ userId, requestBody: roles });
21
+ }
22
+ function generateNewApiKeyForUser(userId) {
23
+ return adminApi.gnerateNewApiKeyForUser({ userId });
24
+ }
25
+ function listRoles(filter, rowsPerPage, page) {
26
+ return adminApi.listRoles({ filter, rowsPerPage, page });
27
+ }
28
+ function getRole(roleName) {
29
+ return adminApi.getRole({ roleName });
30
+ }
31
+ function addRole(role) {
32
+ return adminApi.addRole({ role });
33
+ }
34
+ function updateRole(roleName, updateRoleRequest) {
35
+ return adminApi.updateRole({ roleName, updateRoleRequest });
36
+ }
37
+ function deleteRole(roleName) {
38
+ return adminApi.deleteRole({ roleName });
39
+ }
40
+ return { listUsers, getUser, addUser, deleteUser, updatePasswordForUser, updateRolesForUser, generateNewApiKeyForUser, listRoles, getRole, addRole, updateRole, deleteRole };
41
+ }
@@ -0,0 +1,26 @@
1
+ import type { MongoAggregateRequest } from '../api/index.js';
2
+ export declare function useMongocampApiCollection(collectionName: string): {
3
+ insert: (document: {
4
+ [key: string]: string;
5
+ }) => Promise<import("../api/index.js").InsertResponse>;
6
+ insertMany: (documents: Array<{
7
+ [key: string]: string;
8
+ }>) => Promise<import("../api/index.js").InsertResponse>;
9
+ update: (documentId: string, document: {
10
+ [key: string]: string;
11
+ }) => Promise<import("../api/index.js").UpdateResponse>;
12
+ updatePartial: (documentId: string, document: {
13
+ [key: string]: string;
14
+ }) => Promise<import("../api/index.js").UpdateResponse>;
15
+ remove: (documentId: string) => Promise<import("../api/index.js").DeleteResponse>;
16
+ removeMany: (query: {
17
+ [key: string]: string;
18
+ }) => Promise<import("../api/index.js").DeleteResponse>;
19
+ aggregate: (mongoAggregateRequest: MongoAggregateRequest, rowsPerPage?: number, page?: number) => Promise<{
20
+ [key: string]: string;
21
+ }[]>;
22
+ information: (includeDetails?: boolean) => Promise<import("../api/index.js").CollectionStatus>;
23
+ schemaAnalysis: () => Promise<import("../api/index.js").SchemaAnalysis>;
24
+ distinct: (field: string) => Promise<string[]>;
25
+ clear: () => Promise<import("../api/index.js").JsonValueBoolean>;
26
+ };
@@ -0,0 +1,40 @@
1
+ import { useMongocampApi } from "./mongocampApi.js";
2
+ import { useRuntimeConfig } from "#app";
3
+ export function useMongocampApiCollection(collectionName) {
4
+ const { documentApi, collectionApi } = useMongocampApi();
5
+ const config = useRuntimeConfig();
6
+ function insert(document) {
7
+ return documentApi.insert({ collectionName, requestBody: document });
8
+ }
9
+ function insertMany(documents) {
10
+ return documentApi.insertMany({ collectionName, requestBody: documents });
11
+ }
12
+ function update(documentId, document) {
13
+ return documentApi.update({ collectionName, documentId, requestBody: document });
14
+ }
15
+ function updatePartial(documentId, document) {
16
+ return documentApi.updateDocumentPartial({ collectionName, documentId, requestBody: document });
17
+ }
18
+ function remove(documentId) {
19
+ return documentApi._delete({ collectionName, documentId });
20
+ }
21
+ function removeMany(query) {
22
+ return documentApi.deleteMany({ collectionName, requestBody: query });
23
+ }
24
+ function aggregate(mongoAggregateRequest, rowsPerPage = config.public.mongocamp?.paginationSize, page = 1) {
25
+ return collectionApi.aggregate({ collectionName, mongoAggregateRequest, rowsPerPage, page });
26
+ }
27
+ function information(includeDetails = false) {
28
+ return collectionApi.getCollectionInformation({ collectionName, includeDetails });
29
+ }
30
+ function schemaAnalysis() {
31
+ return collectionApi.getSchemaAnalysis({ collectionName });
32
+ }
33
+ function distinct(field) {
34
+ return collectionApi.distinct({ collectionName, field });
35
+ }
36
+ function clear() {
37
+ return collectionApi.clearCollection({ collectionName });
38
+ }
39
+ return { insert, insertMany, update, updatePartial, remove, removeMany, aggregate, information, schemaAnalysis, distinct, clear };
40
+ }
@@ -0,0 +1,8 @@
1
+ export declare function useMongocampApiCollections(): {
2
+ list: () => Promise<string[]>;
3
+ listByDatabase: (databaseName: string) => Promise<string[]>;
4
+ listDatabases: () => Promise<string[]>;
5
+ databaseInfo: (databaseName: string) => Promise<import("../api/index.js").DatabaseInfo>;
6
+ databaseInfos: () => Promise<import("../api/index.js").DatabaseInfo[]>;
7
+ deleteDatabase: (databaseName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
8
+ };
@@ -0,0 +1,23 @@
1
+ import { useMongocampApi } from "./mongocampApi.js";
2
+ export function useMongocampApiCollections() {
3
+ const { collectionApi, databaseApi } = useMongocampApi();
4
+ function list() {
5
+ return collectionApi.listCollections();
6
+ }
7
+ function listByDatabase(databaseName) {
8
+ return collectionApi.listCollectionsByDatabase({ databaseName });
9
+ }
10
+ function listDatabases() {
11
+ return databaseApi.listDatabases();
12
+ }
13
+ function databaseInfo(databaseName) {
14
+ return databaseApi.getDatabaseInfo({ databaseName });
15
+ }
16
+ function databaseInfos() {
17
+ return databaseApi.databaseInfos();
18
+ }
19
+ function deleteDatabase(databaseName) {
20
+ return databaseApi.deleteDatabase({ databaseName });
21
+ }
22
+ return { list, listByDatabase, listDatabases, databaseInfo, databaseInfos, deleteDatabase };
23
+ }
@@ -0,0 +1,14 @@
1
+ import type { MongoFindRequest, UpdateFileInformationRequest } from '../api/index.js';
2
+ export declare function useMongocampApiFiles(): {
3
+ listBuckets: () => Promise<string[]>;
4
+ getBucket: (bucketName: string) => Promise<import("../api/index.js").BucketInformation>;
5
+ clearBucket: (bucketName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
6
+ deleteBucket: (bucketName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
7
+ list: (bucketName: string, filter?: string, sort?: string, projection?: string, rowsPerPage?: number, page?: number) => Promise<import("../api/index.js").FileInformation[]>;
8
+ find: (bucketName: string, mongoFindRequest: MongoFindRequest, rowsPerPage?: number, page?: number) => Promise<import("../api/index.js").FileInformation[]>;
9
+ info: (bucketName: string, fileId: string) => Promise<import("../api/index.js").FileInformation>;
10
+ download: (bucketName: string, fileId: string) => Promise<Blob>;
11
+ upload: (bucketName: string, file: Blob, metaData: string, fileName?: string) => Promise<import("../api/index.js").InsertResponse>;
12
+ update: (bucketName: string, fileId: string, updateFileInformationRequest: UpdateFileInformationRequest) => Promise<import("../api/index.js").UpdateResponse>;
13
+ remove: (bucketName: string, fileId: string) => Promise<import("../api/index.js").DeleteResponse>;
14
+ };
@@ -0,0 +1,38 @@
1
+ import { useMongocampApi } from "./mongocampApi.js";
2
+ export function useMongocampApiFiles() {
3
+ const { fileApi, bucketApi } = useMongocampApi();
4
+ function listBuckets() {
5
+ return bucketApi.listBuckets();
6
+ }
7
+ function getBucket(bucketName) {
8
+ return bucketApi.getBucket({ bucketName });
9
+ }
10
+ function clearBucket(bucketName) {
11
+ return bucketApi.clearBucket({ bucketName });
12
+ }
13
+ function deleteBucket(bucketName) {
14
+ return bucketApi.deleteBucket({ bucketName });
15
+ }
16
+ function list(bucketName, filter, sort, projection, rowsPerPage, page) {
17
+ return fileApi.listFiles({ bucketName, filter, sort, projection, rowsPerPage, page });
18
+ }
19
+ function find(bucketName, mongoFindRequest, rowsPerPage, page) {
20
+ return fileApi.findFiles({ bucketName, mongoFindRequest, rowsPerPage, page });
21
+ }
22
+ function info(bucketName, fileId) {
23
+ return fileApi.getFileInformation({ bucketName, fileId });
24
+ }
25
+ function download(bucketName, fileId) {
26
+ return fileApi.getFile({ bucketName, fileId });
27
+ }
28
+ function upload(bucketName, file, metaData, fileName) {
29
+ return fileApi.insertFile({ bucketName, file, metaData, fileName });
30
+ }
31
+ function update(bucketName, fileId, updateFileInformationRequest) {
32
+ return fileApi.updateFileInformation({ bucketName, fileId, updateFileInformationRequest });
33
+ }
34
+ function remove(bucketName, fileId) {
35
+ return fileApi.deleteFile({ bucketName, fileId });
36
+ }
37
+ return { listBuckets, getBucket, clearBucket, deleteBucket, list, find, info, download, upload, update, remove };
38
+ }
@@ -0,0 +1,9 @@
1
+ import type { JobConfig } from '../api/index.js';
2
+ export declare function useMongocampApiJobs(): {
3
+ list: () => Promise<import("../api/index.js").JobInformation[]>;
4
+ listAvailable: () => Promise<string[]>;
5
+ register: (jobConfig: JobConfig) => Promise<import("../api/index.js").JobInformation>;
6
+ update: (jobGroup: string, jobName: string, jobConfig: JobConfig) => Promise<import("../api/index.js").JobInformation>;
7
+ remove: (jobGroup: string, jobName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
8
+ execute: (jobGroup: string, jobName: string) => Promise<import("../api/index.js").JsonValueBoolean>;
9
+ };
@@ -0,0 +1,23 @@
1
+ import { useMongocampApi } from "./mongocampApi.js";
2
+ export function useMongocampApiJobs() {
3
+ const { jobApi } = useMongocampApi();
4
+ function list() {
5
+ return jobApi.jobsList();
6
+ }
7
+ function listAvailable() {
8
+ return jobApi.possibleJobsList();
9
+ }
10
+ function register(jobConfig) {
11
+ return jobApi.registerJob({ jobConfig });
12
+ }
13
+ function update(jobGroup, jobName, jobConfig) {
14
+ return jobApi.updateJob({ jobGroup, jobName, jobConfig });
15
+ }
16
+ function remove(jobGroup, jobName) {
17
+ return jobApi.deleteJob({ jobGroup, jobName });
18
+ }
19
+ function execute(jobGroup, jobName) {
20
+ return jobApi.executeJob({ jobGroup, jobName });
21
+ }
22
+ return { list, listAvailable, register, update, remove, execute };
23
+ }
@@ -1,17 +1,28 @@
1
- import { computed } from "vue";
1
+ import { computed, watch } from "vue";
2
2
  import { consola } from "consola";
3
+ import { toMongocampError } from "../utils/toMongocampError.js";
3
4
  import { useMongocampApi } from "./mongocampApi.js";
4
5
  import { useMongocampStorage } from "./mongocampStorage.js";
5
6
  import { useMongocampUser } from "./mongocampUser.js";
6
- import { useRuntimeConfig } from "#app";
7
+ import { useRuntimeConfig, useState } from "#app";
7
8
  export function useMongocampAuth() {
8
9
  const config = useRuntimeConfig();
9
10
  const refreshToken = config.public.mongocamp?.refreshToken;
10
- const tokenRefreshIntervall = config.public.mongocamp?.tokenRefreshIntervall;
11
+ const tokenRefreshInterval = config.public.mongocamp?.tokenRefreshInterval;
11
12
  const state = useMongocampStorage();
12
13
  const { authApi } = useMongocampApi();
13
14
  const user = useMongocampUser();
14
- let updateTokenInterval;
15
+ const updateTokenInterval = useState("mongocamp.tokenRefreshInterval", () => void 0);
16
+ function startTokenRefresh() {
17
+ if (import.meta.client && refreshToken && !updateTokenInterval.value)
18
+ updateTokenInterval.value = window.setInterval(updateToken, tokenRefreshInterval);
19
+ }
20
+ function stopTokenRefresh() {
21
+ if (import.meta.client && updateTokenInterval.value) {
22
+ window.clearInterval(updateTokenInterval.value);
23
+ updateTokenInterval.value = void 0;
24
+ }
25
+ }
15
26
  async function isAuthenticated() {
16
27
  return await authApi.isAuthenticated();
17
28
  }
@@ -20,7 +31,10 @@ export function useMongocampAuth() {
20
31
  const result = await authApi.refreshToken();
21
32
  updateUserState(result);
22
33
  } catch (e) {
23
- consola.log(e);
34
+ const error = await toMongocampError(e);
35
+ consola.error(error.message, error.cause);
36
+ if (error.status === 401 || error.status === 403)
37
+ logout();
24
38
  }
25
39
  }
26
40
  function updateUserState(result) {
@@ -33,31 +47,25 @@ export function useMongocampAuth() {
33
47
  const login2 = { userId: loginId, password: loginPassword };
34
48
  const result = await authApi.login({ login: login2 });
35
49
  updateUserState(result);
36
- if (refreshToken && import.meta.client) {
37
- updateTokenInterval = window.setInterval(updateToken, tokenRefreshIntervall);
38
- }
39
50
  return result.userProfile;
40
51
  };
41
52
  const logout = () => {
53
+ if (state.value.token)
54
+ authApi.logout().catch((e) => consola.error(e));
42
55
  state.value.token = "";
43
56
  const profile = { user: "", isAdmin: false };
44
57
  state.value.profile = profile;
45
58
  user.value = profile;
46
- if (refreshToken && import.meta.client) {
47
- window.clearInterval(updateTokenInterval);
48
- }
49
59
  };
50
- const isLoggedIn = computed(() => {
51
- const result = state.value?.token?.length > 0;
52
- if (import.meta.client) {
53
- if (result && refreshToken && !updateTokenInterval) {
54
- updateTokenInterval = window.setInterval(updateToken, tokenRefreshIntervall);
55
- } else if (!result && updateTokenInterval) {
56
- window.clearInterval(updateTokenInterval);
57
- }
58
- }
59
- return result;
60
- });
60
+ const isLoggedIn = computed(() => (state.value.token?.length ?? 0) > 0);
61
+ if (import.meta.client) {
62
+ watch(isLoggedIn, (loggedIn) => {
63
+ if (loggedIn)
64
+ startTokenRefresh();
65
+ else
66
+ stopTokenRefresh();
67
+ }, { immediate: true });
68
+ }
61
69
  const userRoles = computed(() => state.value.profile.roles ?? []);
62
70
  const userGrants = computed(() => state.value.profile.grants ?? []);
63
71
  return { login, logout, isAuthenticated, isLoggedIn, userRoles, userGrants };
@@ -1,4 +1,5 @@
1
1
  import type { FindRequest, MongoFindRequest } from '../api/index.js';
2
+ import type { FilterFieldValue } from '../utils/buildFieldFilterExpression.js';
2
3
  export declare function useMongocampSearch(): {
3
4
  mongoFindRequest: (filter?: object, sort?: object, projection?: object) => MongoFindRequest;
4
5
  findRequest: (collection: string, searchParameter?: MongoFindRequest, rows?: number, actualPage?: number) => FindRequest;
@@ -8,7 +9,28 @@ export declare function useMongocampSearch(): {
8
9
  findAll: (collectionName: string, page?: number, sort?: string[] | undefined, projection?: string[] | undefined, rowsPerPage?: number) => Promise<{
9
10
  [key: string]: string;
10
11
  }[]>;
11
- findByField: (collectionName: string, field: string, value: string, page?: number, sort?: string[] | undefined, projection?: string[] | undefined, rowsPerPage?: number) => Promise<{
12
+ findByField: (collectionName: string, field: string, value: FilterFieldValue, page?: number, sort?: string[] | undefined, projection?: string[] | undefined, rowsPerPage?: number) => Promise<{
12
13
  [key: string]: string;
13
14
  }[]>;
14
15
  };
16
+ export interface PaginatedFindOptions {
17
+ filter?: string;
18
+ sort?: string[];
19
+ projection?: string[];
20
+ rowsPerPage?: number;
21
+ }
22
+ export declare function usePaginatedFind(collectionName: string, options?: PaginatedFindOptions): {
23
+ documents: import("vue").Ref<{
24
+ [key: string]: string;
25
+ }[], {
26
+ [key: string]: string;
27
+ }[]>;
28
+ page: import("vue").Ref<number, number>;
29
+ rowsPerPage: any;
30
+ pending: import("vue").Ref<boolean, boolean>;
31
+ error: import("vue").Ref<unknown, unknown>;
32
+ load: () => Promise<void>;
33
+ nextPage: () => Promise<void>;
34
+ previousPage: () => Promise<void>;
35
+ goToPage: (target: number) => Promise<void>;
36
+ };
@@ -1,3 +1,5 @@
1
+ import { ref } from "vue";
2
+ import { buildFieldFilterExpression } from "../utils/buildFieldFilterExpression.js";
1
3
  import { useMongocampApi } from "./mongocampApi.js";
2
4
  import { useRuntimeConfig } from "#app";
3
5
  export function useMongocampSearch() {
@@ -16,8 +18,39 @@ export function useMongocampSearch() {
16
18
  return find(collectionName, void 0, page, sort, projection, rowsPerPage);
17
19
  }
18
20
  function findByField(collectionName, field, value, page = 1, sort = void 0, projection = void 0, rowsPerPage = config.public.mongocamp?.paginationSize) {
19
- const expression = `${field}: ${value}`;
21
+ const expression = buildFieldFilterExpression(field, value);
20
22
  return find(collectionName, expression, page, sort, projection, rowsPerPage);
21
23
  }
22
24
  return { mongoFindRequest, findRequest, find, findAll, findByField };
23
25
  }
26
+ export function usePaginatedFind(collectionName, options = {}) {
27
+ const { find } = useMongocampSearch();
28
+ const config = useRuntimeConfig();
29
+ const page = ref(1);
30
+ const rowsPerPage = ref(options.rowsPerPage ?? config.public.mongocamp?.paginationSize);
31
+ const documents = ref([]);
32
+ const pending = ref(false);
33
+ const error = ref(null);
34
+ async function load() {
35
+ pending.value = true;
36
+ error.value = null;
37
+ try {
38
+ documents.value = await find(collectionName, options.filter, page.value, options.sort, options.projection, rowsPerPage.value);
39
+ } catch (e) {
40
+ error.value = e;
41
+ } finally {
42
+ pending.value = false;
43
+ }
44
+ }
45
+ function goToPage(target) {
46
+ page.value = Math.max(1, target);
47
+ return load();
48
+ }
49
+ function nextPage() {
50
+ return goToPage(page.value + 1);
51
+ }
52
+ function previousPage() {
53
+ return goToPage(page.value - 1);
54
+ }
55
+ return { documents, page, rowsPerPage, pending, error, load, nextPage, previousPage, goToPage };
56
+ }
@@ -1,5 +1,6 @@
1
1
  import type { UserProfile } from '../api/index.js';
2
- export declare function useMongocampStorage(): import("@vueuse/shared").RemovableRef<{
2
+ export interface MongocampSession {
3
3
  token: string;
4
4
  profile: UserProfile;
5
- }>;
5
+ }
6
+ export declare function useMongocampStorage(): import("nuxt/app").CookieRef<MongocampSession>;
@@ -1,5 +1,6 @@
1
- import { useSessionStorage } from "@vueuse/core";
1
+ import { useCookie } from "#app";
2
2
  export function useMongocampStorage() {
3
- const profile = { user: "", isAdmin: false };
4
- return useSessionStorage("mongocamp", { token: "", profile });
3
+ return useCookie("mongocamp", {
4
+ default: () => ({ token: "", profile: { user: "", isAdmin: false } })
5
+ });
5
6
  }
@@ -1,4 +1,4 @@
1
1
  import { useState } from "#app";
2
2
  export function useMongocampUser() {
3
- return useState("mongocamp.user");
3
+ return useState("mongocamp.user", () => ({ user: "", isAdmin: false }));
4
4
  }
@@ -0,0 +1,14 @@
1
+ import type { H3Event } from 'h3';
2
+ export declare function useMongocampApi(event: H3Event, token?: string): {
3
+ adminApi: import("../../api/index.js").AdminApi;
4
+ applicationApi: import("../../api/index.js").ApplicationApi;
5
+ authApi: import("../../api/index.js").AuthApi;
6
+ bucketApi: import("../../api/index.js").BucketApi;
7
+ collectionApi: import("../../api/index.js").CollectionApi;
8
+ databaseApi: import("../../api/index.js").DatabaseApi;
9
+ documentApi: import("../../api/index.js").DocumentApi;
10
+ fileApi: import("../../api/index.js").FileApi;
11
+ indexApi: import("../../api/index.js").IndexApi;
12
+ informationApi: import("../../api/index.js").InformationApi;
13
+ jobApi: import("../../api/index.js").JobsApi;
14
+ };
@@ -0,0 +1,8 @@
1
+ import { useRuntimeConfig } from "#imports";
2
+ import { useMongocampServerApi } from "./mongocampServerApi.js";
3
+ export function useMongocampApi(event, token) {
4
+ const config = useRuntimeConfig(event);
5
+ const url = config.public.mongocamp?.url;
6
+ const apiKey = config.mongocampApiKey;
7
+ return useMongocampServerApi(url, apiKey, token);
8
+ }
@@ -1,14 +1,13 @@
1
- import { AdminApi, ApplicationApi, AuthApi, BucketApi, CollectionApi, DatabaseApi, DocumentApi, FileApi, IndexApi, InformationApi, JobsApi } from '../../api/index.js';
2
1
  export declare function useMongocampServerApi(url: string, key?: string, token?: string): {
3
- adminApi: AdminApi;
4
- applicationApi: ApplicationApi;
5
- authApi: AuthApi;
6
- bucketApi: BucketApi;
7
- collectionApi: CollectionApi;
8
- databaseApi: DatabaseApi;
9
- documentApi: DocumentApi;
10
- fileApi: FileApi;
11
- indexApi: IndexApi;
12
- informationApi: InformationApi;
13
- jobApi: JobsApi;
2
+ adminApi: import("../../api/index.js").AdminApi;
3
+ applicationApi: import("../../api/index.js").ApplicationApi;
4
+ authApi: import("../../api/index.js").AuthApi;
5
+ bucketApi: import("../../api/index.js").BucketApi;
6
+ collectionApi: import("../../api/index.js").CollectionApi;
7
+ databaseApi: import("../../api/index.js").DatabaseApi;
8
+ documentApi: import("../../api/index.js").DocumentApi;
9
+ fileApi: import("../../api/index.js").FileApi;
10
+ indexApi: import("../../api/index.js").IndexApi;
11
+ informationApi: import("../../api/index.js").InformationApi;
12
+ jobApi: import("../../api/index.js").JobsApi;
14
13
  };
@@ -1,45 +1,10 @@
1
- import {
2
- AdminApi,
3
- ApplicationApi,
4
- AuthApi,
5
- BucketApi,
6
- CollectionApi,
7
- Configuration,
8
- DatabaseApi,
9
- DocumentApi,
10
- FileApi,
11
- IndexApi,
12
- InformationApi,
13
- JobsApi
14
- } from "../../api/index.js";
1
+ import { Configuration } from "../../api/index.js";
2
+ import { createMongocampApis } from "../../utils/createMongocampApis.js";
15
3
  export function useMongocampServerApi(url, key, token) {
16
- let configuration = new Configuration();
4
+ let configuration = new Configuration({ basePath: url });
17
5
  if (key && key.length > 0)
18
6
  configuration = new Configuration({ basePath: url, apiKey: key });
19
7
  else if (token && token.length > 0)
20
8
  configuration = new Configuration({ basePath: url, accessToken: token });
21
- const adminApi = new AdminApi(configuration);
22
- const applicationApi = new ApplicationApi(configuration);
23
- const authApi = new AuthApi(configuration);
24
- const bucketApi = new BucketApi(configuration);
25
- const collectionApi = new CollectionApi(configuration);
26
- const databaseApi = new DatabaseApi(configuration);
27
- const documentApi = new DocumentApi(configuration);
28
- const fileApi = new FileApi(configuration);
29
- const indexApi = new IndexApi(configuration);
30
- const informationApi = new InformationApi(configuration);
31
- const jobApi = new JobsApi(configuration);
32
- return {
33
- adminApi,
34
- applicationApi,
35
- authApi,
36
- bucketApi,
37
- collectionApi,
38
- databaseApi,
39
- documentApi,
40
- fileApi,
41
- indexApi,
42
- informationApi,
43
- jobApi
44
- };
9
+ return createMongocampApis(configuration);
45
10
  }
@@ -0,0 +1,2 @@
1
+ export type FilterFieldValue = string | number | boolean | Date;
2
+ export declare function buildFieldFilterExpression(field: string, value: FilterFieldValue): string;
@@ -0,0 +1,7 @@
1
+ export function buildFieldFilterExpression(field, value) {
2
+ if (typeof value === "number" || typeof value === "boolean")
3
+ return `${field}: ${value}`;
4
+ const stringValue = value instanceof Date ? value.toISOString() : value;
5
+ const escapedValue = stringValue.replace(/"/g, '\\"');
6
+ return `${field}: "${escapedValue}"`;
7
+ }
@@ -0,0 +1,15 @@
1
+ import type { Configuration } from '../api/index.js';
2
+ import { AdminApi, ApplicationApi, AuthApi, BucketApi, CollectionApi, DatabaseApi, DocumentApi, FileApi, IndexApi, InformationApi, JobsApi } from '../api/index.js';
3
+ export declare function createMongocampApis(configuration: Configuration): {
4
+ adminApi: AdminApi;
5
+ applicationApi: ApplicationApi;
6
+ authApi: AuthApi;
7
+ bucketApi: BucketApi;
8
+ collectionApi: CollectionApi;
9
+ databaseApi: DatabaseApi;
10
+ documentApi: DocumentApi;
11
+ fileApi: FileApi;
12
+ indexApi: IndexApi;
13
+ informationApi: InformationApi;
14
+ jobApi: JobsApi;
15
+ };