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.
Files changed (189) hide show
  1. package/README.md +3 -3
  2. package/dist/adapter-sqlite/generate-schema/{util.d.ts → util.server.d.ts} +2 -2
  3. package/dist/adapter-sqlite/generate-schema/{util.js → util.server.js} +2 -2
  4. package/dist/adapter-sqlite/generate-schema/write.server.js +1 -1
  5. package/dist/adapter-sqlite/index.server.d.ts +2 -1
  6. package/dist/adapter-sqlite/index.server.js +2 -0
  7. package/dist/adapter-sqlite/transform.server.js +1 -1
  8. package/dist/adapter-sqlite/with.server.js +1 -1
  9. package/dist/core/areas/{api → rest}/get.server.d.ts +4 -2
  10. package/dist/core/areas/rest/get.server.js +45 -0
  11. package/dist/core/areas/rest/index.server.d.ts +6 -0
  12. package/dist/core/areas/rest/index.server.js +3 -0
  13. package/dist/core/areas/{api → rest}/update.server.d.ts +4 -2
  14. package/dist/core/areas/rest/update.server.js +43 -0
  15. package/dist/core/collections/auth/hooks/before-upsert/augment-fields-password.server.d.ts +1 -1
  16. package/dist/core/collections/config/augment-panel.d.ts +1 -1
  17. package/dist/core/collections/local-api.server.js +2 -1
  18. package/dist/core/collections/operations/duplicate.js +2 -2
  19. package/dist/core/collections/{api → rest}/create.server.d.ts +4 -2
  20. package/dist/core/collections/rest/create.server.js +37 -0
  21. package/dist/core/collections/{api → rest}/delete.server.d.ts +4 -2
  22. package/dist/core/collections/rest/delete.server.js +37 -0
  23. package/dist/core/collections/{api → rest}/deleteById.server.d.ts +4 -2
  24. package/dist/core/collections/rest/deleteById.server.js +21 -0
  25. package/dist/core/collections/{api → rest}/duplicate.server.d.ts +1 -1
  26. package/dist/core/collections/rest/duplicate.server.js +16 -0
  27. package/dist/core/collections/{api → rest}/get.server.d.ts +4 -2
  28. package/dist/core/collections/rest/get.server.js +50 -0
  29. package/dist/core/collections/{api → rest}/getById.server.d.ts +4 -2
  30. package/dist/core/collections/rest/getById.server.js +35 -0
  31. package/dist/core/collections/rest/index.server.d.ts +16 -0
  32. package/dist/core/collections/rest/index.server.js +16 -0
  33. package/dist/core/collections/{api → rest}/updateById.server.d.ts +4 -2
  34. package/dist/core/collections/rest/updateById.server.js +44 -0
  35. package/dist/core/collections/upload/hooks/convert-base64.server.d.ts +1 -1
  36. package/dist/core/collections/upload/hooks/extract-path.server.d.ts +1 -1
  37. package/dist/core/collections/upload/hooks/handle-path-creation.server.d.ts +1 -1
  38. package/dist/core/collections/upload/hooks/process-file-upload.server.d.ts +1 -1
  39. package/dist/core/config/auth/better-auth.server.d.ts +2 -2
  40. package/dist/core/config/client/augment-directories.js +1 -1
  41. package/dist/core/config/config-context.server.d.ts +3 -3
  42. package/dist/core/config/server/augment-directories.server.js +1 -1
  43. package/dist/core/config/server/augment-panel-access.server.d.ts +1 -1
  44. package/dist/core/config/server/build-config.server.d.ts +11 -11
  45. package/dist/core/config/server/validate.server.js +3 -3
  46. package/dist/core/config/shared/find-thumbnail.js +1 -1
  47. package/dist/core/constant.d.ts +1 -1
  48. package/dist/core/constant.js +1 -1
  49. package/dist/core/dev/cli/build/index.d.ts +1 -0
  50. package/dist/core/dev/cli/build/index.js +39 -10
  51. package/dist/core/dev/cli/build/templates.d.ts +1 -0
  52. package/dist/core/dev/cli/build/templates.js +24 -0
  53. package/dist/core/dev/cli/clear/index.server.js +1 -1
  54. package/dist/core/dev/cli/index.js +20 -0
  55. package/dist/core/dev/cli/init/index.server.js +3 -3
  56. package/dist/core/dev/cli/init/templates.d.ts +1 -1
  57. package/dist/core/dev/cli/init/templates.js +2 -2
  58. package/dist/core/dev/cli/util/log.server.d.ts +1 -0
  59. package/dist/core/dev/cli/util/log.server.js +4 -0
  60. package/dist/core/dev/cli/util/package-manager.server.d.ts +9 -0
  61. package/dist/core/dev/cli/{init/package-manager-util.server.js → util/package-manager.server.js} +15 -0
  62. package/dist/core/dev/cli/util/package.server.d.ts +9 -0
  63. package/dist/core/dev/cli/{init/get-package-info.server.js → util/package.server.js} +10 -0
  64. package/dist/core/dev/generate/routes/common.server.d.ts +10 -1
  65. package/dist/core/dev/generate/routes/common.server.js +248 -29
  66. package/dist/core/dev/generate/routes/index.server.d.ts +7 -1
  67. package/dist/core/dev/generate/routes/index.server.js +16 -55
  68. package/dist/core/dev/generate/routes/util.server.d.ts +6 -16
  69. package/dist/core/dev/generate/routes/util.server.js +8 -21
  70. package/dist/core/dev/generate/types/index.server.js +5 -3
  71. package/dist/core/dev/vite/index.server.js +1 -1
  72. package/dist/core/errors/handler.server.d.ts +22 -1
  73. package/dist/core/errors/handler.server.js +25 -2
  74. package/dist/core/errors/index.d.ts +0 -1
  75. package/dist/core/errors/index.js +0 -1
  76. package/dist/core/fields/util.d.ts +1 -1
  77. package/dist/core/handlers/routes.server.d.ts +70 -1
  78. package/dist/core/handlers/routes.server.js +55 -1
  79. package/dist/core/operations/hooks/before-upsert/data-config-map.server.d.ts +1 -1
  80. package/dist/core/operations/hooks/before-upsert/handle-new-version.server.d.ts +1 -1
  81. package/dist/core/operations/hooks/before-upsert/original-config-map.server.d.ts +1 -1
  82. package/dist/core/operations/hooks/before-upsert/set-default-values.server.d.ts +1 -1
  83. package/dist/core/operations/hooks/before-upsert/validate-fields.server.d.ts +1 -1
  84. package/dist/core/plugins/api-init/index.server.js +10 -5
  85. package/dist/core/plugins/cache/cache.server.js +1 -1
  86. package/dist/core/rime.server.d.ts +10 -10
  87. package/dist/core/rime.server.js +5 -1
  88. package/dist/fields/checkbox/index.server.js +1 -1
  89. package/dist/fields/combobox/index.server.js +1 -1
  90. package/dist/fields/date/index.server.js +1 -1
  91. package/dist/fields/email/index.js +1 -1
  92. package/dist/fields/email/index.server.js +1 -1
  93. package/dist/fields/link/component/RessourceInput.svelte +1 -1
  94. package/dist/fields/link/index.d.ts +1 -1
  95. package/dist/fields/link/index.js +1 -1
  96. package/dist/fields/link/index.server.js +1 -1
  97. package/dist/fields/number/index.server.js +1 -1
  98. package/dist/fields/radio/index.server.js +1 -1
  99. package/dist/fields/relation/client.d.ts +1 -1
  100. package/dist/fields/relation/client.js +1 -1
  101. package/dist/fields/relation/component/Cell.svelte +1 -1
  102. package/dist/fields/relation/component/Relation.svelte +1 -1
  103. package/dist/fields/relation/component/upload/Browse.svelte +1 -1
  104. package/dist/fields/relation/index.d.ts +1 -1
  105. package/dist/fields/relation/index.js +2 -2
  106. package/dist/fields/relation/index.server.js +1 -1
  107. package/dist/fields/rich-text/core/features/fields/extension.d.ts +2 -2
  108. package/dist/fields/rich-text/core/features/link/component/link-selector.svelte +1 -1
  109. package/dist/fields/rich-text/core/features/resource/resource-extension.d.ts +1 -1
  110. package/dist/fields/rich-text/core/features/resource/resource.svelte +1 -1
  111. package/dist/fields/rich-text/core/features/upload/upload-extension.d.ts +1 -1
  112. package/dist/fields/rich-text/core/features/upload/upload.svelte +1 -1
  113. package/dist/fields/rich-text/index.js +4 -2
  114. package/dist/fields/rich-text/index.server.js +1 -1
  115. package/dist/fields/select/index.server.js +1 -1
  116. package/dist/fields/slug/index.server.js +1 -1
  117. package/dist/fields/text/index.server.js +1 -1
  118. package/dist/fields/textarea/index.server.js +1 -1
  119. package/dist/fields/time/index.server.js +1 -1
  120. package/dist/fields/toggle/index.server.js +1 -1
  121. package/dist/index.d.ts +8 -3
  122. package/dist/index.js +7 -3
  123. package/dist/panel/components/sections/collection/folder/FolderWithActions.svelte +1 -1
  124. package/dist/panel/components/sections/document/ButtonStatus.svelte +1 -1
  125. package/dist/panel/components/sections/document/CurrentlyEdited.svelte +1 -1
  126. package/dist/panel/components/sections/document/Settings.svelte +1 -1
  127. package/dist/panel/context/collection.svelte.js +1 -1
  128. package/dist/panel/context/documentForm.svelte.js +1 -2
  129. package/dist/panel/context/form.svelte.d.ts +2 -0
  130. package/dist/panel/context/form.svelte.js +8 -2
  131. package/dist/panel/context/live.svelte.js +1 -1
  132. package/dist/panel/index.d.ts +9 -1
  133. package/dist/panel/index.js +7 -1
  134. package/dist/panel/pages/area/actions.server.d.ts +2 -21
  135. package/dist/panel/pages/area/actions.server.js +28 -27
  136. package/dist/panel/pages/area/load.server.d.ts +2 -17
  137. package/dist/panel/pages/area/load.server.js +37 -46
  138. package/dist/panel/pages/auth/sign-in/SignIn.svelte +7 -1
  139. package/dist/panel/pages/collection/load.server.d.ts +6 -6
  140. package/dist/panel/pages/collection/load.server.js +70 -72
  141. package/dist/panel/pages/collection-document/actions.server.d.ts +1 -1
  142. package/dist/panel/pages/collection-document/actions.server.js +78 -70
  143. package/dist/panel/pages/collection-document/load.server.d.ts +5 -20
  144. package/dist/panel/pages/collection-document/load.server.js +80 -82
  145. package/dist/server.d.ts +7 -0
  146. package/dist/server.js +7 -0
  147. package/dist/types.d.ts +1 -0
  148. package/dist/util/index.d.ts +9 -1
  149. package/dist/util/index.js +12 -1
  150. package/package.json +6 -49
  151. package/dist/core/api/index.d.ts +0 -7
  152. package/dist/core/api/index.js +0 -10
  153. package/dist/core/api/index.server.d.ts +0 -3
  154. package/dist/core/api/index.server.js +0 -3
  155. package/dist/core/areas/api/get.server.js +0 -36
  156. package/dist/core/areas/api/index.server.d.ts +0 -7
  157. package/dist/core/areas/api/index.server.js +0 -4
  158. package/dist/core/areas/api/update.server.js +0 -33
  159. package/dist/core/collections/api/create.server.js +0 -29
  160. package/dist/core/collections/api/delete.server.js +0 -32
  161. package/dist/core/collections/api/deleteById.server.js +0 -16
  162. package/dist/core/collections/api/duplicate.server.js +0 -18
  163. package/dist/core/collections/api/get.server.js +0 -45
  164. package/dist/core/collections/api/getById.server.js +0 -30
  165. package/dist/core/collections/api/index.server.d.ts +0 -17
  166. package/dist/core/collections/api/index.server.js +0 -9
  167. package/dist/core/collections/api/updateById.server.js +0 -38
  168. package/dist/core/dev/cli/init/get-package-info.server.d.ts +0 -1
  169. package/dist/core/dev/cli/init/package-manager-util.server.d.ts +0 -3
  170. package/dist/core/dev/generate/routes/area.server.d.ts +0 -7
  171. package/dist/core/dev/generate/routes/area.server.js +0 -69
  172. package/dist/core/dev/generate/routes/collection.server.d.ts +0 -14
  173. package/dist/core/dev/generate/routes/collection.server.js +0 -129
  174. package/dist/live.d.ts +0 -4
  175. package/dist/live.js +0 -4
  176. package/dist/panel/index.server.d.ts +0 -4
  177. package/dist/panel/index.server.js +0 -4
  178. package/dist/panel/pages/auth/index.d.ts +0 -4
  179. package/dist/panel/pages/auth/index.js +0 -4
  180. package/dist/panel/pages/auth/index.server.d.ts +0 -18
  181. package/dist/panel/pages/auth/index.server.js +0 -12
  182. package/dist/panel/pages/index.actions.server.d.ts +0 -13
  183. package/dist/panel/pages/index.actions.server.js +0 -10
  184. package/dist/panel/pages/index.load.server.d.ts +0 -23
  185. package/dist/panel/pages/index.load.server.js +0 -16
  186. package/dist/panel/ui.d.ts +0 -4
  187. package/dist/panel/ui.js +0 -5
  188. /package/dist/core/dev/cli/{util.server.d.ts → util/prompt.server.d.ts} +0 -0
  189. /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 { RimeError } from '../../../core/errors/index.js';
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
- /* Layout load
12
- /****************************************************/
13
- export function collectionLoad(slug) {
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 load = async (event) => {
16
- const { rime, locale, user } = event.locals;
17
- if (!rime.config.isCollection(slug)) {
18
- throw handleError(new RimeError(RimeError.NOT_FOUND), { context: 'load' });
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
- const collection = rime.collection(slug);
21
- const authorizedCreate = collection.config.access.create(user, {});
22
- const docs = await collection.find({
23
- locale,
24
- draft: true
55
+ directories = await directoryCollection.find({
56
+ query: `where[parent][equals]=${currentDirectoryPath}`,
57
+ sort: 'name'
25
58
  });
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
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
- // 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);
65
+ if (parentError) {
66
+ throw handleError(parentError, { context: 'load' });
54
67
  }
55
- directories = await directoryCollection.find({
56
- query: `where[parent][equals]=${currentDirectoryPath}`,
57
- sort: 'name'
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
- return data;
83
- };
84
- return load;
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 default function (slug: string): Actions;
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 default function (slug) {
11
- const actions = {
12
- /**
13
- * Create a document.
14
- * Action called when posting a form from the panel :
15
- * /panel/{slug}/create
16
- */
17
- create: async (event) => {
18
- const { rime, locale } = event.locals;
19
- // Get the redirect parameter ex: ?redirect=0 that can be present if we're in a nested form
20
- // to prevent redirection after entry creation ex: for relation creation
21
- const withoutRedirect = event.url.searchParams.get(PARAMS.REDIRECT) === 'false';
22
- const data = await extractData(event.request);
23
- if (!rime.config.isCollection(slug)) {
24
- throw handleError(new RimeError(RimeError.NOT_FOUND), { context: 'action' });
25
- }
26
- const collection = rime.collection(slug);
27
- const [error, document] = await trycatch(() => collection.create({ data, locale }));
28
- if (error) {
29
- return handleError(error, { context: 'action' });
30
- }
31
- if (withoutRedirect) {
32
- return {
33
- document,
34
- message: t__('common.doc_created')
35
- };
36
- }
37
- // Redirect to proper upload directory if collection.upload
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
- * Update a document.
50
- * Action called when posting a form from the panel :
51
- * /panel/{slug}/{documentId}
52
- */
53
- update: async (event) => {
54
- const { rime, locale } = event.locals;
55
- const id = event.params.id || '';
56
- const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
57
- const draft = event.url.searchParams.get(PARAMS.DRAFT) === 'true';
58
- const data = await extractData(event.request);
59
- if (!rime.config.isCollection(slug)) {
60
- throw handleError(new RimeError(RimeError.NOT_FOUND), { context: 'action' });
61
- }
62
- const [error, document] = await trycatch(() => rime.collection(slug).updateById({
63
- id,
64
- data,
65
- versionId,
66
- draft,
67
- locale
68
- }));
69
- if (error) {
70
- return handleError(error, { context: 'action' });
71
- }
72
- if (draft && 'versionId' in document) {
73
- return {
74
- document,
75
- message: t__('common.version_created'),
76
- redirectUrl: `${panelUrl(toKebabCase(slug), document.id)}/versions?versionId=${document.versionId}`
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.doc_updated')
85
+ message: t__('common.version_created'),
86
+ redirectUrl: `${panelUrl(toKebabCase(slug), document.id)}/versions?versionId=${document.versionId}`
82
87
  };
83
88
  }
84
- };
85
- return actions;
86
- }
89
+ return {
90
+ document,
91
+ message: t__('common.doc_updated')
92
+ };
93
+ }
94
+ };
@@ -1,21 +1,6 @@
1
- import type { GenericDoc } from '../../../core/types/doc.js';
2
- import type { Route } from '../../types.js';
1
+ import type { CollectionDocData } from '../../index.js';
3
2
  import { type ServerLoadEvent } from '@sveltejs/kit';
4
- /****************************************************/
5
- export declare function docLoad(slug: string, withVersion?: boolean): <V extends boolean = boolean>(event: ServerLoadEvent) => Promise<({
6
- aria: Partial<Route>[];
7
- doc: GenericDoc;
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
- /* Document Load
13
- /****************************************************/
14
- export function docLoad(slug, withVersion) {
11
+ /**
12
+ * Load function for the collection document page in the panel.
13
+ */
14
+ export async function documentLoad(event, withVersion) {
15
15
  //
16
- const load = async (event) => {
17
- const { locale, user, rime } = event.locals;
18
- const { id } = event.params;
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' });
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
- 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
- return { doc: {}, operation, status: 401, readOnly: true };
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
- 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
- return { doc: {}, operation, status: 401, readOnly: true };
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
- let aria;
56
- const collectionAria = {
57
- title: collection.config.label.plural,
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
- 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;
54
+ }
55
+ let aria;
56
+ const collectionAria = {
57
+ title: collection.config.label.plural,
58
+ url: panelUrl(collection.config.kebab)
95
59
  };
96
- return load;
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
  }
@@ -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';
@@ -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
- export { access, array, doc, file, object, random, state, string, validate };
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 };
@@ -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
- export { access, array, doc, file, object, random, state, string, validate };
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 };