rimecms 0.28.9 → 0.29.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 +3 -3
- package/dist/adapter-sqlite/generate-schema/{util.d.ts → util.server.d.ts} +2 -2
- package/dist/adapter-sqlite/generate-schema/{util.js → util.server.js} +2 -2
- package/dist/adapter-sqlite/generate-schema/write.server.js +1 -1
- package/dist/adapter-sqlite/index.server.d.ts +2 -1
- package/dist/adapter-sqlite/index.server.js +2 -0
- package/dist/adapter-sqlite/transform.server.js +1 -1
- package/dist/adapter-sqlite/with.server.js +1 -1
- package/dist/core/areas/{api → rest}/get.server.d.ts +4 -2
- package/dist/core/areas/rest/get.server.js +45 -0
- package/dist/core/areas/rest/index.server.d.ts +6 -0
- package/dist/core/areas/rest/index.server.js +3 -0
- package/dist/core/areas/{api → rest}/update.server.d.ts +4 -2
- package/dist/core/areas/rest/update.server.js +43 -0
- package/dist/core/collections/auth/hooks/before-upsert/augment-fields-password.server.d.ts +1 -1
- package/dist/core/collections/config/augment-panel.d.ts +1 -1
- package/dist/core/collections/local-api.server.js +2 -1
- package/dist/core/collections/operations/duplicate.js +2 -2
- package/dist/core/collections/{api → rest}/create.server.d.ts +4 -2
- package/dist/core/collections/rest/create.server.js +37 -0
- package/dist/core/collections/{api → rest}/delete.server.d.ts +4 -2
- package/dist/core/collections/rest/delete.server.js +37 -0
- package/dist/core/collections/{api → rest}/deleteById.server.d.ts +4 -2
- package/dist/core/collections/rest/deleteById.server.js +21 -0
- package/dist/core/collections/{api → rest}/duplicate.server.d.ts +1 -1
- package/dist/core/collections/rest/duplicate.server.js +16 -0
- package/dist/core/collections/{api → rest}/get.server.d.ts +4 -2
- package/dist/core/collections/rest/get.server.js +50 -0
- package/dist/core/collections/{api → rest}/getById.server.d.ts +4 -2
- package/dist/core/collections/rest/getById.server.js +35 -0
- package/dist/core/collections/rest/index.server.d.ts +16 -0
- package/dist/core/collections/rest/index.server.js +16 -0
- package/dist/core/collections/{api → rest}/updateById.server.d.ts +4 -2
- package/dist/core/collections/rest/updateById.server.js +44 -0
- package/dist/core/collections/upload/hooks/convert-base64.server.d.ts +1 -1
- package/dist/core/collections/upload/hooks/extract-path.server.d.ts +1 -1
- package/dist/core/collections/upload/hooks/handle-path-creation.server.d.ts +1 -1
- package/dist/core/collections/upload/hooks/process-file-upload.server.d.ts +1 -1
- package/dist/core/config/auth/better-auth.server.d.ts +2 -2
- package/dist/core/config/client/augment-directories.js +1 -1
- package/dist/core/config/config-context.server.d.ts +3 -3
- package/dist/core/config/server/augment-directories.server.js +1 -1
- package/dist/core/config/server/augment-panel-access.server.d.ts +1 -1
- package/dist/core/config/server/build-config.server.d.ts +11 -11
- package/dist/core/config/server/validate.server.js +3 -3
- package/dist/core/config/shared/find-thumbnail.js +1 -1
- package/dist/core/constant.d.ts +1 -1
- package/dist/core/constant.js +1 -1
- package/dist/core/dev/cli/build/index.d.ts +1 -0
- package/dist/core/dev/cli/build/index.js +39 -10
- package/dist/core/dev/cli/build/templates.d.ts +1 -0
- package/dist/core/dev/cli/build/templates.js +24 -0
- package/dist/core/dev/cli/clear/index.server.js +1 -1
- package/dist/core/dev/cli/index.js +20 -0
- package/dist/core/dev/cli/init/index.server.js +3 -3
- package/dist/core/dev/cli/init/templates.d.ts +1 -1
- package/dist/core/dev/cli/init/templates.js +2 -2
- package/dist/core/dev/cli/util/log.server.d.ts +1 -0
- package/dist/core/dev/cli/util/log.server.js +4 -0
- package/dist/core/dev/cli/util/package-manager.server.d.ts +9 -0
- package/dist/core/dev/cli/{init/package-manager-util.server.js → util/package-manager.server.js} +15 -0
- package/dist/core/dev/cli/util/package.server.d.ts +9 -0
- package/dist/core/dev/cli/{init/get-package-info.server.js → util/package.server.js} +10 -0
- package/dist/core/dev/generate/routes/common.server.d.ts +10 -1
- package/dist/core/dev/generate/routes/common.server.js +248 -29
- package/dist/core/dev/generate/routes/index.server.d.ts +7 -1
- package/dist/core/dev/generate/routes/index.server.js +16 -55
- package/dist/core/dev/generate/routes/util.server.d.ts +6 -16
- package/dist/core/dev/generate/routes/util.server.js +8 -21
- package/dist/core/dev/generate/types/index.server.js +5 -3
- package/dist/core/dev/vite/index.server.js +1 -1
- package/dist/core/errors/handler.server.d.ts +22 -1
- package/dist/core/errors/handler.server.js +25 -2
- package/dist/core/errors/index.d.ts +0 -1
- package/dist/core/errors/index.js +0 -1
- package/dist/core/fields/util.d.ts +1 -1
- package/dist/core/handlers/routes.server.d.ts +70 -1
- package/dist/core/handlers/routes.server.js +55 -1
- package/dist/core/operations/hooks/before-upsert/data-config-map.server.d.ts +1 -1
- package/dist/core/operations/hooks/before-upsert/handle-new-version.server.d.ts +1 -1
- package/dist/core/operations/hooks/before-upsert/original-config-map.server.d.ts +1 -1
- package/dist/core/operations/hooks/before-upsert/set-default-values.server.d.ts +1 -1
- package/dist/core/operations/hooks/before-upsert/validate-fields.server.d.ts +1 -1
- package/dist/core/plugins/api-init/index.server.js +10 -5
- package/dist/core/plugins/cache/cache.server.js +1 -1
- package/dist/core/rime.server.d.ts +10 -10
- package/dist/core/rime.server.js +5 -1
- package/dist/fields/checkbox/index.server.js +1 -1
- package/dist/fields/combobox/index.server.js +1 -1
- package/dist/fields/date/index.server.js +1 -1
- package/dist/fields/email/index.js +1 -1
- package/dist/fields/email/index.server.js +1 -1
- package/dist/fields/link/component/RessourceInput.svelte +1 -1
- package/dist/fields/link/index.d.ts +1 -1
- package/dist/fields/link/index.js +1 -1
- package/dist/fields/link/index.server.js +1 -1
- package/dist/fields/number/index.server.js +1 -1
- package/dist/fields/radio/index.server.js +1 -1
- package/dist/fields/relation/client.d.ts +1 -1
- package/dist/fields/relation/client.js +1 -1
- package/dist/fields/relation/component/Cell.svelte +1 -1
- package/dist/fields/relation/component/Relation.svelte +1 -1
- package/dist/fields/relation/component/upload/Browse.svelte +1 -1
- package/dist/fields/relation/index.d.ts +1 -1
- package/dist/fields/relation/index.js +2 -2
- package/dist/fields/relation/index.server.js +1 -1
- package/dist/fields/rich-text/core/features/fields/extension.d.ts +2 -2
- package/dist/fields/rich-text/core/features/link/component/link-selector.svelte +1 -1
- package/dist/fields/rich-text/core/features/resource/resource-extension.d.ts +1 -1
- package/dist/fields/rich-text/core/features/resource/resource.svelte +1 -1
- package/dist/fields/rich-text/core/features/upload/upload-extension.d.ts +1 -1
- package/dist/fields/rich-text/core/features/upload/upload.svelte +1 -1
- package/dist/fields/rich-text/index.js +4 -2
- package/dist/fields/rich-text/index.server.js +1 -1
- package/dist/fields/select/index.server.js +1 -1
- package/dist/fields/slug/index.server.js +1 -1
- package/dist/fields/text/index.server.js +1 -1
- package/dist/fields/textarea/index.server.js +1 -1
- package/dist/fields/time/index.server.js +1 -1
- package/dist/fields/toggle/index.server.js +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7 -3
- package/dist/panel/components/sections/collection/folder/FolderWithActions.svelte +1 -1
- package/dist/panel/components/sections/document/ButtonStatus.svelte +1 -1
- package/dist/panel/components/sections/document/CurrentlyEdited.svelte +1 -1
- package/dist/panel/components/sections/document/Settings.svelte +1 -1
- package/dist/panel/context/collection.svelte.js +1 -1
- package/dist/panel/context/documentForm.svelte.js +1 -2
- package/dist/panel/context/form.svelte.d.ts +2 -0
- package/dist/panel/context/form.svelte.js +8 -2
- package/dist/panel/context/live.svelte.js +1 -1
- package/dist/panel/index.d.ts +9 -1
- package/dist/panel/index.js +7 -1
- package/dist/panel/pages/area/actions.server.d.ts +2 -21
- package/dist/panel/pages/area/actions.server.js +28 -27
- package/dist/panel/pages/area/load.server.d.ts +2 -17
- package/dist/panel/pages/area/load.server.js +37 -46
- package/dist/panel/pages/auth/sign-in/SignIn.svelte +7 -1
- package/dist/panel/pages/collection/load.server.d.ts +6 -6
- package/dist/panel/pages/collection/load.server.js +70 -72
- package/dist/panel/pages/collection-document/actions.server.d.ts +1 -1
- package/dist/panel/pages/collection-document/actions.server.js +78 -70
- package/dist/panel/pages/collection-document/load.server.d.ts +5 -20
- package/dist/panel/pages/collection-document/load.server.js +80 -82
- package/dist/server.d.ts +7 -0
- package/dist/server.js +7 -0
- package/dist/types.d.ts +1 -0
- package/dist/util/index.d.ts +9 -1
- package/dist/util/index.js +12 -1
- package/package.json +6 -49
- package/dist/core/api/index.d.ts +0 -7
- package/dist/core/api/index.js +0 -10
- package/dist/core/api/index.server.d.ts +0 -3
- package/dist/core/api/index.server.js +0 -3
- package/dist/core/areas/api/get.server.js +0 -36
- package/dist/core/areas/api/index.server.d.ts +0 -7
- package/dist/core/areas/api/index.server.js +0 -4
- package/dist/core/areas/api/update.server.js +0 -33
- package/dist/core/collections/api/create.server.js +0 -29
- package/dist/core/collections/api/delete.server.js +0 -32
- package/dist/core/collections/api/deleteById.server.js +0 -16
- package/dist/core/collections/api/duplicate.server.js +0 -18
- package/dist/core/collections/api/get.server.js +0 -45
- package/dist/core/collections/api/getById.server.js +0 -30
- package/dist/core/collections/api/index.server.d.ts +0 -17
- package/dist/core/collections/api/index.server.js +0 -9
- package/dist/core/collections/api/updateById.server.js +0 -38
- package/dist/core/dev/cli/init/get-package-info.server.d.ts +0 -1
- package/dist/core/dev/cli/init/package-manager-util.server.d.ts +0 -3
- package/dist/core/dev/generate/routes/area.server.d.ts +0 -7
- package/dist/core/dev/generate/routes/area.server.js +0 -69
- package/dist/core/dev/generate/routes/collection.server.d.ts +0 -14
- package/dist/core/dev/generate/routes/collection.server.js +0 -129
- package/dist/live.d.ts +0 -4
- package/dist/live.js +0 -4
- package/dist/panel/index.server.d.ts +0 -4
- package/dist/panel/index.server.js +0 -4
- package/dist/panel/pages/auth/index.d.ts +0 -4
- package/dist/panel/pages/auth/index.js +0 -4
- package/dist/panel/pages/auth/index.server.d.ts +0 -18
- package/dist/panel/pages/auth/index.server.js +0 -12
- package/dist/panel/pages/index.actions.server.d.ts +0 -13
- package/dist/panel/pages/index.actions.server.js +0 -10
- package/dist/panel/pages/index.load.server.d.ts +0 -23
- package/dist/panel/pages/index.load.server.js +0 -16
- package/dist/panel/ui.d.ts +0 -4
- package/dist/panel/ui.js +0 -5
- /package/dist/core/dev/cli/{util.server.d.ts → util/prompt.server.d.ts} +0 -0
- /package/dist/core/dev/cli/{util.server.js → util/prompt.server.js} +0 -0
|
@@ -1,85 +1,83 @@
|
|
|
1
|
-
import { UPLOAD_PATH } from '../../../core/constant.js';
|
|
2
|
-
import { withDirectoriesSuffix } from '../../../core/naming.js';
|
|
3
|
-
import { redirect } from '@sveltejs/kit';
|
|
4
1
|
import { buildUploadAria, getParentPath, removePathFromLastAria } from '../../../core/collections/upload/util/path.js';
|
|
5
|
-
import {
|
|
2
|
+
import { UPLOAD_PATH } from '../../../core/constant.js';
|
|
6
3
|
import { handleError } from '../../../core/errors/handler.server.js';
|
|
4
|
+
import { RimeError } from '../../../core/errors/index.js';
|
|
7
5
|
import { logger } from '../../../core/logger/index.server.js';
|
|
6
|
+
import { withDirectoriesSuffix } from '../../../core/naming.js';
|
|
8
7
|
import { panelUrl } from '../../util/url.js';
|
|
9
8
|
import { trycatch } from '../../../util/function.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { redirect } from '@sveltejs/kit';
|
|
10
|
+
/**
|
|
11
|
+
* Load function for the collection page in the panel.
|
|
12
|
+
*/
|
|
13
|
+
export async function collectionLoad(event) {
|
|
14
14
|
//
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const { rime, locale, user } = event.locals;
|
|
16
|
+
const slug = event.params.slug || '';
|
|
17
|
+
if (!rime.config.isCollection(slug)) {
|
|
18
|
+
throw handleError(new RimeError(RimeError.NOT_FOUND), { context: 'load' });
|
|
19
|
+
}
|
|
20
|
+
const collection = rime.collection(slug);
|
|
21
|
+
const authorizedCreate = collection.config.access.create(user, {});
|
|
22
|
+
const docs = await collection.find({
|
|
23
|
+
locale,
|
|
24
|
+
draft: true
|
|
25
|
+
});
|
|
26
|
+
let aria = [
|
|
27
|
+
{ title: 'Dashboard', url: panelUrl() },
|
|
28
|
+
{ title: collection.config.label.plural }
|
|
29
|
+
];
|
|
30
|
+
let data = {
|
|
31
|
+
aria,
|
|
32
|
+
docs,
|
|
33
|
+
canCreate: authorizedCreate,
|
|
34
|
+
status: 200
|
|
35
|
+
};
|
|
36
|
+
if (collection.config.upload) {
|
|
37
|
+
let directories = [];
|
|
38
|
+
const paramUploadPath = event.url.searchParams.get('uploadPath');
|
|
39
|
+
const currentDirectoryPath = paramUploadPath || UPLOAD_PATH.ROOT_NAME;
|
|
40
|
+
const directoryCollection = rime.collection(withDirectoriesSuffix(slug));
|
|
41
|
+
// Check if dir exists
|
|
42
|
+
const [error, currentDirectory] = await trycatch(() => directoryCollection.findById({
|
|
43
|
+
id: currentDirectoryPath
|
|
44
|
+
}));
|
|
45
|
+
// If doesn't exists and path is root then create it
|
|
46
|
+
if (!currentDirectory && currentDirectoryPath === UPLOAD_PATH.ROOT_NAME) {
|
|
47
|
+
await directoryCollection.create({
|
|
48
|
+
data: { id: UPLOAD_PATH.ROOT_NAME }
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (error) {
|
|
52
|
+
logger.error(`${paramUploadPath} doesn't exists`);
|
|
53
|
+
return redirect(301, event.url.pathname);
|
|
19
54
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
locale,
|
|
24
|
-
draft: true
|
|
55
|
+
directories = await directoryCollection.find({
|
|
56
|
+
query: `where[parent][equals]=${currentDirectoryPath}`,
|
|
57
|
+
sort: 'name'
|
|
25
58
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
aria,
|
|
32
|
-
docs,
|
|
33
|
-
canCreate: authorizedCreate,
|
|
34
|
-
status: 200
|
|
35
|
-
};
|
|
36
|
-
if (collection.config.upload) {
|
|
37
|
-
let directories = [];
|
|
38
|
-
const paramUploadPath = event.url.searchParams.get('uploadPath');
|
|
39
|
-
const currentDirectoryPath = paramUploadPath || UPLOAD_PATH.ROOT_NAME;
|
|
40
|
-
const directoryCollection = rime.collection(withDirectoriesSuffix(slug));
|
|
41
|
-
// Check if dir exists
|
|
42
|
-
const [error, currentDirectory] = await trycatch(() => directoryCollection.findById({
|
|
43
|
-
id: currentDirectoryPath
|
|
59
|
+
const parentPath = getParentPath(currentDirectoryPath);
|
|
60
|
+
let parentDirectory;
|
|
61
|
+
if (parentPath) {
|
|
62
|
+
const [parentError, result] = await trycatch(() => directoryCollection.findById({
|
|
63
|
+
id: parentPath
|
|
44
64
|
}));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
await directoryCollection.create({
|
|
48
|
-
data: { id: UPLOAD_PATH.ROOT_NAME }
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else if (error) {
|
|
52
|
-
logger.error(`${paramUploadPath} doesn't exists`);
|
|
53
|
-
return redirect(301, event.url.pathname);
|
|
65
|
+
if (parentError) {
|
|
66
|
+
throw handleError(parentError, { context: 'load' });
|
|
54
67
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const parentPath = getParentPath(currentDirectoryPath);
|
|
60
|
-
let parentDirectory;
|
|
61
|
-
if (parentPath) {
|
|
62
|
-
const [parentError, result] = await trycatch(() => directoryCollection.findById({
|
|
63
|
-
id: parentPath
|
|
64
|
-
}));
|
|
65
|
-
if (parentError) {
|
|
66
|
-
throw handleError(parentError, { context: 'load' });
|
|
67
|
-
}
|
|
68
|
-
parentDirectory = result;
|
|
69
|
-
const collectionAria = {
|
|
70
|
-
title: collection.config.label.plural,
|
|
71
|
-
url: panelUrl(collection.config.kebab)
|
|
72
|
-
};
|
|
73
|
-
aria = [...aria].slice(0, -1);
|
|
74
|
-
aria = [...aria, collectionAria, ...buildUploadAria({ path: currentDirectoryPath, slug })];
|
|
75
|
-
data.aria = removePathFromLastAria(aria);
|
|
76
|
-
}
|
|
77
|
-
data = {
|
|
78
|
-
...data,
|
|
79
|
-
upload: { directories, currentPath: currentDirectoryPath, parentDirectory }
|
|
68
|
+
parentDirectory = result;
|
|
69
|
+
const collectionAria = {
|
|
70
|
+
title: collection.config.label.plural,
|
|
71
|
+
url: panelUrl(collection.config.kebab)
|
|
80
72
|
};
|
|
73
|
+
aria = [...aria].slice(0, -1);
|
|
74
|
+
aria = [...aria, collectionAria, ...buildUploadAria({ path: currentDirectoryPath, slug })];
|
|
75
|
+
data.aria = removePathFromLastAria(aria);
|
|
81
76
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
data = {
|
|
78
|
+
...data,
|
|
79
|
+
upload: { directories, currentPath: currentDirectoryPath, parentDirectory }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return data;
|
|
85
83
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Actions } from '@sveltejs/kit';
|
|
2
|
-
export
|
|
2
|
+
export declare const collectionFormActions: Actions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PARAMS, UPLOAD_PATH } from '../../../core/constant.js';
|
|
2
|
-
import { handleError } from '../../../core/errors/handler.server.js';
|
|
2
|
+
import { ERROR_CONTEXT, handleError } from '../../../core/errors/handler.server.js';
|
|
3
3
|
import { RimeError } from '../../../core/errors/index.js';
|
|
4
4
|
import { extractData } from '../../../core/operations/extract-data.server.js';
|
|
5
5
|
import { panelUrl } from '../../util/url.js';
|
|
@@ -7,80 +7,88 @@ import { trycatch } from '../../../util/function.js';
|
|
|
7
7
|
import { toKebabCase } from '../../../util/string.js';
|
|
8
8
|
import {} from '@sveltejs/kit';
|
|
9
9
|
import { t__ } from '../../../core/i18n/index.js';
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const params = collection.config.upload
|
|
39
|
-
? `?${PARAMS.UPLOAD_PATH}=${data._path || UPLOAD_PATH.ROOT_NAME}`
|
|
40
|
-
: '';
|
|
41
|
-
const redirectUrl = `${panelUrl(toKebabCase(slug), document.id)}${params}`;
|
|
10
|
+
export const collectionFormActions = {
|
|
11
|
+
/**
|
|
12
|
+
* Create a document.
|
|
13
|
+
* Action called when posting a form from the panel :
|
|
14
|
+
* /panel/{slug}/create
|
|
15
|
+
*/
|
|
16
|
+
create: async (event) => {
|
|
17
|
+
const { rime, locale } = event.locals;
|
|
18
|
+
const slug = event.params.slug;
|
|
19
|
+
if (!rime.config.isCollection(slug)) {
|
|
20
|
+
throw handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.ACTION });
|
|
21
|
+
}
|
|
22
|
+
// Get the redirect parameter ex: ?redirect=false that can be present if we're in a nested form
|
|
23
|
+
// to prevent redirection after entry creation ex: for relation creation
|
|
24
|
+
const withoutRedirect = event.url.searchParams.get(PARAMS.REDIRECT) === 'false';
|
|
25
|
+
const [extractError, data] = await trycatch(() => extractData(event.request));
|
|
26
|
+
if (extractError) {
|
|
27
|
+
return handleError(extractError, { context: ERROR_CONTEXT.ACTION });
|
|
28
|
+
}
|
|
29
|
+
if (!rime.config.isCollection(slug)) {
|
|
30
|
+
throw handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.ACTION });
|
|
31
|
+
}
|
|
32
|
+
const collection = rime.collection(slug);
|
|
33
|
+
const [error, document] = await trycatch(() => collection.create({ data, locale }));
|
|
34
|
+
if (error) {
|
|
35
|
+
return handleError(error, { context: ERROR_CONTEXT.ACTION });
|
|
36
|
+
}
|
|
37
|
+
if (withoutRedirect) {
|
|
42
38
|
return {
|
|
43
|
-
redirectUrl,
|
|
44
39
|
document,
|
|
45
40
|
message: t__('common.doc_created')
|
|
46
41
|
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
}
|
|
43
|
+
// Redirect to proper upload directory if collection.upload
|
|
44
|
+
const params = collection.config.upload
|
|
45
|
+
? `?${PARAMS.UPLOAD_PATH}=${data._path || UPLOAD_PATH.ROOT_NAME}`
|
|
46
|
+
: '';
|
|
47
|
+
const redirectUrl = `${panelUrl(toKebabCase(slug), document.id)}${params}`;
|
|
48
|
+
return {
|
|
49
|
+
redirectUrl,
|
|
50
|
+
document,
|
|
51
|
+
message: t__('common.doc_created')
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Update a document.
|
|
56
|
+
* Action called when posting a form from the panel :
|
|
57
|
+
* /panel/{slug}/{documentId}
|
|
58
|
+
*/
|
|
59
|
+
update: async (event) => {
|
|
60
|
+
const { rime, locale } = event.locals;
|
|
61
|
+
const slug = event.params.slug || '';
|
|
62
|
+
const id = event.params.id || '';
|
|
63
|
+
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
64
|
+
const draft = event.url.searchParams.get(PARAMS.DRAFT) === 'true';
|
|
65
|
+
if (!rime.config.isCollection(slug)) {
|
|
66
|
+
throw handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.ACTION });
|
|
67
|
+
}
|
|
68
|
+
const [extractError, data] = await trycatch(() => extractData(event.request));
|
|
69
|
+
if (extractError) {
|
|
70
|
+
return handleError(extractError, { context: ERROR_CONTEXT.ACTION });
|
|
71
|
+
}
|
|
72
|
+
const [error, document] = await trycatch(() => rime.collection(slug).updateById({
|
|
73
|
+
id,
|
|
74
|
+
data,
|
|
75
|
+
versionId,
|
|
76
|
+
draft,
|
|
77
|
+
locale
|
|
78
|
+
}));
|
|
79
|
+
if (error) {
|
|
80
|
+
return handleError(error, { context: ERROR_CONTEXT.ACTION });
|
|
81
|
+
}
|
|
82
|
+
if (draft && 'versionId' in document) {
|
|
79
83
|
return {
|
|
80
84
|
document,
|
|
81
|
-
message: t__('common.
|
|
85
|
+
message: t__('common.version_created'),
|
|
86
|
+
redirectUrl: `${panelUrl(toKebabCase(slug), document.id)}/versions?versionId=${document.versionId}`
|
|
82
87
|
};
|
|
83
88
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
return {
|
|
90
|
+
document,
|
|
91
|
+
message: t__('common.doc_updated')
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Route } from '../../types.js';
|
|
1
|
+
import type { CollectionDocData } from '../../index.js';
|
|
3
2
|
import { type ServerLoadEvent } from '@sveltejs/kit';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
status: 200;
|
|
9
|
-
readOnly: boolean;
|
|
10
|
-
} & {
|
|
11
|
-
operation: "create" | "update";
|
|
12
|
-
hasMailer?: boolean;
|
|
13
|
-
}) | ({
|
|
14
|
-
aria: Partial<Route>[];
|
|
15
|
-
doc: {};
|
|
16
|
-
status: 401;
|
|
17
|
-
readOnly: true;
|
|
18
|
-
} & {
|
|
19
|
-
operation: "create" | "update";
|
|
20
|
-
hasMailer?: boolean;
|
|
21
|
-
})>;
|
|
3
|
+
/**
|
|
4
|
+
* Load function for the collection document page in the panel.
|
|
5
|
+
*/
|
|
6
|
+
export declare function documentLoad<V extends boolean = boolean>(event: ServerLoadEvent, withVersion?: V): Promise<CollectionDocData<V>>;
|
|
@@ -1,97 +1,95 @@
|
|
|
1
|
-
import { apiUrl } from '../../../core/api/index.js';
|
|
2
1
|
import { buildUploadAria } from '../../../core/collections/upload/util/path.js';
|
|
3
2
|
import { PARAMS, UPLOAD_PATH } from '../../../core/constant.js';
|
|
4
|
-
import { handleError } from '../../../core/errors/handler.server.js';
|
|
3
|
+
import { ERROR_CONTEXT, handleError } from '../../../core/errors/handler.server.js';
|
|
5
4
|
import { RimeError } from '../../../core/errors/index.js';
|
|
6
5
|
import { withVersionsSuffix } from '../../../core/naming.js';
|
|
7
6
|
import { panelUrl } from '../../util/url.js';
|
|
8
7
|
import { trycatch } from '../../../util/function.js';
|
|
8
|
+
import { apiUrl } from '../../../util/index.js';
|
|
9
9
|
import { toKebabCase } from '../../../util/string.js';
|
|
10
10
|
import { error } from '@sveltejs/kit';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function
|
|
11
|
+
/**
|
|
12
|
+
* Load function for the collection document page in the panel.
|
|
13
|
+
*/
|
|
14
|
+
export async function documentLoad(event, withVersion) {
|
|
15
15
|
//
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const { locale, user, rime } = event.locals;
|
|
17
|
+
const { id } = event.params;
|
|
18
|
+
const slug = event.params.slug || '';
|
|
19
|
+
if (!id)
|
|
20
|
+
throw error(404, 'Not found');
|
|
21
|
+
let doc;
|
|
22
|
+
let readOnly = false;
|
|
23
|
+
if (!rime.config.isCollection(slug)) {
|
|
24
|
+
throw handleError(new RimeError(RimeError.NOT_FOUND), { context: 'load' });
|
|
25
|
+
}
|
|
26
|
+
const collection = rime.collection(slug);
|
|
27
|
+
const operation = id === 'create' ? 'create' : 'update';
|
|
28
|
+
if (id === 'create') {
|
|
29
|
+
/** Check for authorizations */
|
|
30
|
+
const authorized = collection.config.access.create(user, {});
|
|
31
|
+
if (!authorized) {
|
|
32
|
+
throw handleError(new RimeError(RimeError.UNAUTHORIZED), { context: ERROR_CONTEXT.LOAD });
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
doc = collection.blank();
|
|
34
|
+
doc = collection.blank();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
/** Check for authorizations */
|
|
38
|
+
const authorizedRead = collection.config.access.read(user, { id });
|
|
39
|
+
const authorizedUpdate = collection.config.access.update(user, { id });
|
|
40
|
+
if (!authorizedRead && !authorizedUpdate) {
|
|
41
|
+
throw handleError(new RimeError(RimeError.UNAUTHORIZED), { context: ERROR_CONTEXT.LOAD });
|
|
35
42
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
44
|
-
/** Get doc */
|
|
45
|
-
const [error, document] = await trycatch(() => collection.findById({ id, locale, versionId, draft: true }));
|
|
46
|
-
doc = document;
|
|
47
|
-
if (error) {
|
|
48
|
-
throw handleError(error, { context: 'load' });
|
|
49
|
-
}
|
|
50
|
-
/** If update not allowed set doc as readOnly */
|
|
51
|
-
if (authorizedRead && !authorizedUpdate) {
|
|
52
|
-
readOnly = true;
|
|
53
|
-
}
|
|
43
|
+
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
44
|
+
/** Get doc */
|
|
45
|
+
const [error, document] = await trycatch(() => collection.findById({ id, locale, versionId, draft: true }));
|
|
46
|
+
doc = document;
|
|
47
|
+
if (error) {
|
|
48
|
+
throw handleError(error, { context: 'load' });
|
|
54
49
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
url: panelUrl(collection.config.kebab)
|
|
59
|
-
};
|
|
60
|
-
if (collection.config.upload) {
|
|
61
|
-
const paramUploadPath = event.url.searchParams.get('uploadPath');
|
|
62
|
-
const currentDirectoryPath = paramUploadPath || UPLOAD_PATH.ROOT_NAME;
|
|
63
|
-
aria = [
|
|
64
|
-
{ title: 'Dashboard', icon: 'dashboard', url: panelUrl() },
|
|
65
|
-
collectionAria,
|
|
66
|
-
...buildUploadAria({ path: currentDirectoryPath, slug }),
|
|
67
|
-
{ title: undefined } // Will be populated by title context
|
|
68
|
-
];
|
|
50
|
+
/** If update not allowed set doc as readOnly */
|
|
51
|
+
if (authorizedRead && !authorizedUpdate) {
|
|
52
|
+
readOnly = true;
|
|
69
53
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
];
|
|
76
|
-
}
|
|
77
|
-
let data = {
|
|
78
|
-
aria,
|
|
79
|
-
doc,
|
|
80
|
-
operation,
|
|
81
|
-
status: 200,
|
|
82
|
-
hasMailer: 'mailer' in rime,
|
|
83
|
-
readOnly
|
|
84
|
-
};
|
|
85
|
-
if (withVersion) {
|
|
86
|
-
const url = `${apiUrl(withVersionsSuffix(toKebabCase(doc._type)))}?where[ownerId][equals]=${doc.id}&sort=-updatedAt&select=updatedAt,status`;
|
|
87
|
-
const promise = event.fetch(url).then((r) => r.json());
|
|
88
|
-
const [error, result] = await trycatch(() => promise);
|
|
89
|
-
if (error || !Array.isArray(result.docs)) {
|
|
90
|
-
throw new RimeError(RimeError.OPERATION_ERROR, 'while getting versions');
|
|
91
|
-
}
|
|
92
|
-
data = { ...data, versions: result.docs };
|
|
93
|
-
}
|
|
94
|
-
return data;
|
|
54
|
+
}
|
|
55
|
+
let aria;
|
|
56
|
+
const collectionAria = {
|
|
57
|
+
title: collection.config.label.plural,
|
|
58
|
+
url: panelUrl(collection.config.kebab)
|
|
95
59
|
};
|
|
96
|
-
|
|
60
|
+
if (collection.config.upload) {
|
|
61
|
+
const paramUploadPath = event.url.searchParams.get('uploadPath');
|
|
62
|
+
const currentDirectoryPath = paramUploadPath || UPLOAD_PATH.ROOT_NAME;
|
|
63
|
+
aria = [
|
|
64
|
+
{ title: 'Dashboard', icon: 'dashboard', url: panelUrl() },
|
|
65
|
+
collectionAria,
|
|
66
|
+
...buildUploadAria({ path: currentDirectoryPath, slug }),
|
|
67
|
+
{ title: undefined } // Will be populated by title context
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
aria = [
|
|
72
|
+
{ title: 'Dashboard', icon: 'dashboard', url: panelUrl() },
|
|
73
|
+
{ title: collection.config.label.plural, url: panelUrl(collection.config.kebab) },
|
|
74
|
+
{ title: undefined } // Will be populated by title context
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
let data = {
|
|
78
|
+
aria,
|
|
79
|
+
doc,
|
|
80
|
+
operation,
|
|
81
|
+
status: 200,
|
|
82
|
+
hasMailer: 'mailer' in rime,
|
|
83
|
+
readOnly
|
|
84
|
+
};
|
|
85
|
+
if (withVersion) {
|
|
86
|
+
const url = `${apiUrl(withVersionsSuffix(toKebabCase(doc._type)))}?where[ownerId][equals]=${doc.id}&sort=-updatedAt&select=updatedAt,status`;
|
|
87
|
+
const promise = event.fetch(url).then((r) => r.json());
|
|
88
|
+
const [error, result] = await trycatch(() => promise);
|
|
89
|
+
if (error || !Array.isArray(result.docs)) {
|
|
90
|
+
throw new RimeError(RimeError.OPERATION_ERROR, 'while getting versions');
|
|
91
|
+
}
|
|
92
|
+
data = { ...data, versions: result.docs };
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
97
95
|
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import handlers from './core/handlers/index.js';
|
|
2
|
+
import { registerTranslation } from './core/i18n/register.server.js';
|
|
3
|
+
import { apiInit } from './core/plugins/api-init/index.server.js';
|
|
4
|
+
import { cache } from './core/plugins/cache/index.server.js';
|
|
5
|
+
import { mailer } from './core/plugins/mailer/index.server.js';
|
|
6
|
+
import { sse } from './core/plugins/sse/index.server.js';
|
|
7
|
+
export { apiInit, cache, handlers, mailer, registerTranslation, sse };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import handlers from './core/handlers/index.js';
|
|
2
|
+
import { registerTranslation } from './core/i18n/register.server.js';
|
|
3
|
+
import { apiInit } from './core/plugins/api-init/index.server.js';
|
|
4
|
+
import { cache } from './core/plugins/cache/index.server.js';
|
|
5
|
+
import { mailer } from './core/plugins/mailer/index.server.js';
|
|
6
|
+
import { sse } from './core/plugins/sse/index.server.js';
|
|
7
|
+
export { apiInit, cache, handlers, mailer, registerTranslation, sse };
|
package/dist/types.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export type { Link } from './fields/link/types.js';
|
|
|
9
9
|
export type { WithRelationPopulated } from './util/types.js';
|
|
10
10
|
export type { Plugin } from './core/plugins/index.js';
|
|
11
11
|
export type { Rime, RimeContext } from './core/rime.server.js';
|
|
12
|
+
export type { RouteHandlers } from './core/handlers/routes.server.js';
|
|
12
13
|
export type { BlocksFieldBlockRenderTitle } from './fields/blocks/index.js';
|
|
13
14
|
export type { RichTextFeature, RichTextFeatureMark, RichTextFeatureNode } from './fields/rich-text/core/types.js';
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as upload from '../core/collections/upload/util/client.js';
|
|
1
2
|
import { access } from './access/index.js';
|
|
2
3
|
import * as array from './array.js';
|
|
3
4
|
import * as doc from './doc.js';
|
|
@@ -7,4 +8,11 @@ import * as random from './random.js';
|
|
|
7
8
|
import * as state from './state.js';
|
|
8
9
|
import * as string from './string.js';
|
|
9
10
|
import * as validate from './validate.js';
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Build the api full url for given segments
|
|
13
|
+
* @example
|
|
14
|
+
* apiUrl('some-collection') // -> http://localhost:5713/api/some-collection
|
|
15
|
+
* apiUrl('some-collection', '12345') // -> http://localhost:5713/api/some-collection/12345
|
|
16
|
+
*/
|
|
17
|
+
export declare function apiUrl(...args: string[]): string;
|
|
18
|
+
export { access, array, doc, file, object, random, state, string, upload, validate };
|
package/dist/util/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { env } from '$env/dynamic/public';
|
|
2
|
+
import * as upload from '../core/collections/upload/util/client.js';
|
|
1
3
|
import { access } from './access/index.js';
|
|
2
4
|
import * as array from './array.js';
|
|
3
5
|
import * as doc from './doc.js';
|
|
@@ -7,4 +9,13 @@ import * as random from './random.js';
|
|
|
7
9
|
import * as state from './state.js';
|
|
8
10
|
import * as string from './string.js';
|
|
9
11
|
import * as validate from './validate.js';
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Build the api full url for given segments
|
|
14
|
+
* @example
|
|
15
|
+
* apiUrl('some-collection') // -> http://localhost:5713/api/some-collection
|
|
16
|
+
* apiUrl('some-collection', '12345') // -> http://localhost:5713/api/some-collection/12345
|
|
17
|
+
*/
|
|
18
|
+
export function apiUrl(...args) {
|
|
19
|
+
return `${env.PUBLIC_RIME_URL}/api/${args.join('/')}`;
|
|
20
|
+
}
|
|
21
|
+
export { access, array, doc, file, object, random, state, string, upload, validate };
|