rimecms 0.28.10 → 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/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
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ export default defineConfig({
|
|
|
93
93
|
```typescript
|
|
94
94
|
// src/hooks.server.ts (should be created)
|
|
95
95
|
import config from '$lib/+rime.generated/rime.config.server.js';
|
|
96
|
-
import { handlers } from 'rimecms';
|
|
96
|
+
import { handlers } from 'rimecms/server';
|
|
97
97
|
import { sequence } from '@sveltejs/kit/hooks';
|
|
98
98
|
|
|
99
99
|
export const handle = sequence(...(await handlers(config)));
|
|
@@ -131,7 +131,7 @@ curl -v POST http://localhost:5173/api/init \
|
|
|
131
131
|
```typescript
|
|
132
132
|
// ./src/lib/+rime/rime.config.ts
|
|
133
133
|
import { rime, Collection, Area } from '$rime/config';
|
|
134
|
-
import { adapterSqlite } from 'rimecms/sqlite';
|
|
134
|
+
import { adapterSqlite } from 'rimecms/adapter-sqlite';
|
|
135
135
|
import { Settings2 } from '@lucide/svelte';
|
|
136
136
|
import { relation, link, richText, text, toggle } from 'rimecms/fields';
|
|
137
137
|
import { access } from "rimecms/util";
|
|
@@ -261,10 +261,10 @@ It's doing bascically `vite build` under the hood and create the polka server fi
|
|
|
261
261
|
- [x] more better-auth integration
|
|
262
262
|
- [x] Handle relation poperties in queries
|
|
263
263
|
- [~] Documentation
|
|
264
|
+
- [ ] Live Edit system in practice
|
|
264
265
|
- [ ] configurable files storage adapter (local, s3, etc)
|
|
265
266
|
- [ ] other storage adapter (postgress, turso, etc)
|
|
266
267
|
- [ ] auto-saved draft
|
|
267
|
-
- [ ] Live Edit system in practice
|
|
268
268
|
- [ ] Put bin commands in a separate package ex: @rime/kit
|
|
269
269
|
|
|
270
270
|
## Acknowledgments
|
|
@@ -33,8 +33,8 @@ export declare const getBlocksTableNames: (slug: string, tables: Record<string,
|
|
|
33
33
|
*/
|
|
34
34
|
export declare const makeBlockTableSlug: (slug: string, blockType: string) => string;
|
|
35
35
|
/**
|
|
36
|
-
* Generate the column
|
|
37
|
-
* Snake case is used for sqlite column name and Camel case is
|
|
36
|
+
* Generate the column and property names for a field given its name and its parent path.
|
|
37
|
+
* Snake case is used for the sqlite column name and Camel case is used for the drizzle column property name.
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* // returns { camel : 'groupTitle', snake: 'group__title' }
|
|
@@ -34,8 +34,8 @@ export const getBlocksTableNames = (slug, tables) => Object.keys(tables).filter(
|
|
|
34
34
|
*/
|
|
35
35
|
export const makeBlockTableSlug = (slug, blockType) => `${slug}Blocks${toPascalCase(blockType)}`;
|
|
36
36
|
/**
|
|
37
|
-
* Generate the column
|
|
38
|
-
* Snake case is used for sqlite column name and Camel case is
|
|
37
|
+
* Generate the column and property names for a field given its name and its parent path.
|
|
38
|
+
* Snake case is used for the sqlite column name and Camel case is used for the drizzle column property name.
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* // returns { camel : 'groupTitle', snake: 'group__title' }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cache from '../../core/dev/cache/index.server.js';
|
|
2
|
-
import { getPackageManager } from '../../core/dev/cli/
|
|
2
|
+
import { getPackageManager } from '../../core/dev/cli/util/package-manager.server.js';
|
|
3
3
|
import { logger } from '../../core/logger/index.server.js';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { spawnSync } from 'node:child_process';
|
|
@@ -15,6 +15,8 @@ import createTreeFacade from './tree.server.js';
|
|
|
15
15
|
import type { GenericTable } from './types.server.js';
|
|
16
16
|
import { updateDocumentUrl } from './url.server.js';
|
|
17
17
|
import { updateTableRecord } from './util.server.js';
|
|
18
|
+
export * as templates from './generate-schema/templates.server.js';
|
|
19
|
+
export * as util from './generate-schema/util.server.js';
|
|
18
20
|
type Schema = GetRegisterType<'Schema'>;
|
|
19
21
|
export declare function adapterSqlite(database: string): {
|
|
20
22
|
createAdapter: <C extends Config>(configCtx: ConfigContext<C>) => Promise<Adapter>;
|
|
@@ -36,4 +38,3 @@ export type Adapter = {
|
|
|
36
38
|
readonly schema: Schema;
|
|
37
39
|
readonly relationFieldsMap: RelationFieldsMap;
|
|
38
40
|
};
|
|
39
|
-
export {};
|
|
@@ -10,6 +10,8 @@ import { transformerFacade } from './transform.server.js';
|
|
|
10
10
|
import createTreeFacade from './tree.server.js';
|
|
11
11
|
import { updateDocumentUrl } from './url.server.js';
|
|
12
12
|
import { updateTableRecord } from './util.server.js';
|
|
13
|
+
export * as templates from './generate-schema/templates.server.js';
|
|
14
|
+
export * as util from './generate-schema/util.server.js';
|
|
13
15
|
export function adapterSqlite(database) {
|
|
14
16
|
//
|
|
15
17
|
return {
|
|
@@ -5,7 +5,7 @@ import { flatten, unflatten } from 'flat';
|
|
|
5
5
|
import { logger } from '../core/logger/index.server.js';
|
|
6
6
|
import { extractFieldName } from '../fields/tree/util.js';
|
|
7
7
|
import { isObjectLiteral, omit } from '../util/object.js';
|
|
8
|
-
import { getBlocksTableNames, getTreeTableNames, makeBlockTableSlug, makeTreeTableSlug } from './generate-schema/util.js';
|
|
8
|
+
import { getBlocksTableNames, getTreeTableNames, makeBlockTableSlug, makeTreeTableSlug } from './generate-schema/util.server.js';
|
|
9
9
|
import { transformDatabaseColumnsToPaths } from './util.server.js';
|
|
10
10
|
/**
|
|
11
11
|
* Facade responsible of converting raw database document
|
|
@@ -4,7 +4,7 @@ import { isBlocksFieldRaw } from '../fields/blocks/index.js';
|
|
|
4
4
|
import { isRelationField } from '../fields/relation/index.js';
|
|
5
5
|
import { isTreeFieldRaw } from '../fields/tree/index.js';
|
|
6
6
|
import { asc, eq, getTableColumns, or, SQL } from 'drizzle-orm';
|
|
7
|
-
import { getBlocksTableNames, getTreeTableNames } from './generate-schema/util.js';
|
|
7
|
+
import { getBlocksTableNames, getTreeTableNames } from './generate-schema/util.server.js';
|
|
8
8
|
export const buildWithParam = (args) => {
|
|
9
9
|
const { slug, select = [], locale, tables, config: documentConfig } = args;
|
|
10
10
|
if (!select.length) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { AreaSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* GET handler for the area API endpoint.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restGet(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PARAMS } from '../../constant.js';
|
|
2
|
+
import { RimeError } from '../../errors/index.js';
|
|
3
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
4
|
+
import { trycatch } from '../../../util/function.js';
|
|
5
|
+
import { json } from '@sveltejs/kit';
|
|
6
|
+
/**
|
|
7
|
+
* GET handler for the area API endpoint.
|
|
8
|
+
*/
|
|
9
|
+
export async function restGet(event) {
|
|
10
|
+
//
|
|
11
|
+
const { rime } = event.locals;
|
|
12
|
+
// Check if the slug corresponds to a valid area
|
|
13
|
+
const slug = event.params.slug;
|
|
14
|
+
if (!rime.config.isArea(slug)) {
|
|
15
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
16
|
+
}
|
|
17
|
+
const params = event.url.searchParams;
|
|
18
|
+
const areaAPI = rime.area(slug);
|
|
19
|
+
// Build the select parameter for the API call based on the request parameters
|
|
20
|
+
function buildSelect(params) {
|
|
21
|
+
const paramSelect = params.get(PARAMS.SELECT)
|
|
22
|
+
? params.get(PARAMS.SELECT).split(',')
|
|
23
|
+
: undefined;
|
|
24
|
+
if (paramSelect &&
|
|
25
|
+
paramSelect.includes('title') &&
|
|
26
|
+
!paramSelect.includes(areaAPI.config.asTitle)) {
|
|
27
|
+
paramSelect.push(areaAPI.config.asTitle);
|
|
28
|
+
}
|
|
29
|
+
return paramSelect;
|
|
30
|
+
}
|
|
31
|
+
// Prepare the parameters for the API call to find the area document
|
|
32
|
+
const apiParams = {
|
|
33
|
+
locale: rime.getLocale(),
|
|
34
|
+
draft: params.get(PARAMS.DRAFT) ? params.get(PARAMS.DRAFT) === 'true' : undefined,
|
|
35
|
+
versionId: params.get(PARAMS.VERSION_ID) || undefined,
|
|
36
|
+
depth: params.get(PARAMS.DEPTH) ? parseInt(params.get(PARAMS.DEPTH)) : 0,
|
|
37
|
+
select: buildSelect(params)
|
|
38
|
+
};
|
|
39
|
+
// Call the area API to find the document based on the prepared parameters
|
|
40
|
+
const [error, doc] = await trycatch(() => rime.area(slug).find(apiParams));
|
|
41
|
+
if (error) {
|
|
42
|
+
return handleError(error, { context: 'api' });
|
|
43
|
+
}
|
|
44
|
+
return json({ doc });
|
|
45
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { AreaSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* POST handler for the area API endpoint.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restUpdate(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PARAMS } from '../../constant.js';
|
|
2
|
+
import { RimeError } from '../../errors/index.js';
|
|
3
|
+
import { ERROR_CONTEXT, handleError } from '../../errors/handler.server.js';
|
|
4
|
+
import { extractData } from '../../operations/extract-data.server.js';
|
|
5
|
+
import { trycatch } from '../../../util/function.js';
|
|
6
|
+
import { json } from '@sveltejs/kit';
|
|
7
|
+
/**
|
|
8
|
+
* POST handler for the area API endpoint.
|
|
9
|
+
*/
|
|
10
|
+
export async function restUpdate(event) {
|
|
11
|
+
//
|
|
12
|
+
const { rime } = event.locals;
|
|
13
|
+
const slug = event.params.slug;
|
|
14
|
+
// Check if the slug corresponds to a valid area
|
|
15
|
+
if (!rime.config.isArea(slug)) {
|
|
16
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.API });
|
|
17
|
+
}
|
|
18
|
+
// Extract versionId and draft parameters from the request URL
|
|
19
|
+
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
20
|
+
const draft = event.url.searchParams.get(PARAMS.DRAFT)
|
|
21
|
+
? event.url.searchParams.get(PARAMS.DRAFT) === 'true'
|
|
22
|
+
: undefined;
|
|
23
|
+
// Extract data from the request body
|
|
24
|
+
const [extractError, data] = await trycatch(() => extractData(event.request));
|
|
25
|
+
if (extractError) {
|
|
26
|
+
return handleError(extractError, { context: ERROR_CONTEXT.API });
|
|
27
|
+
}
|
|
28
|
+
// Set the locale if provided in the data
|
|
29
|
+
if (data.locale) {
|
|
30
|
+
rime.setLocale(data.locale);
|
|
31
|
+
}
|
|
32
|
+
// Update the area with the extracted data, versionId, draft status, and current locale
|
|
33
|
+
const [error, doc] = await trycatch(() => rime.area(slug).update({
|
|
34
|
+
data,
|
|
35
|
+
versionId,
|
|
36
|
+
draft,
|
|
37
|
+
locale: rime.getLocale()
|
|
38
|
+
}));
|
|
39
|
+
if (error) {
|
|
40
|
+
return handleError(error, { context: ERROR_CONTEXT.API });
|
|
41
|
+
}
|
|
42
|
+
return json({ doc });
|
|
43
|
+
}
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* add fields password and confirmPassword
|
|
4
4
|
* to add validations
|
|
5
5
|
*/
|
|
6
|
-
export declare const augmentFieldsPassword: import("../../../../operations/hooks/index.server.js").Hook<"auth", "
|
|
6
|
+
export declare const augmentFieldsPassword: import("../../../../operations/hooks/index.server.js").Hook<"auth", "update" | "create", "before">;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { VERSIONS_STATUS } from '../../constant.js';
|
|
2
2
|
import { buildConfigMap } from '../../operations/configMap/index.js';
|
|
3
3
|
import { isBlocksFieldRaw } from '../../../fields/blocks/index.js';
|
|
4
|
-
import { isJSONContent } from '../../../fields/rich-text';
|
|
4
|
+
import { isJSONContent } from '../../../fields/rich-text/index.js';
|
|
5
5
|
import { richTextJSONToText } from '../../../fields/rich-text/index.js';
|
|
6
6
|
import { isTreeFieldRaw } from '../../../fields/tree/index.js';
|
|
7
7
|
import { getValueAtPath, isObjectLiteral, matchStructure, omitId, setValueAtPath } from '../../../util/object.js';
|
|
@@ -32,7 +32,7 @@ export const duplicate = async (args) => {
|
|
|
32
32
|
*/
|
|
33
33
|
function prepareDuplicate(doc, locale, keepIds) {
|
|
34
34
|
let data = setCopyTitle(doc);
|
|
35
|
-
data.
|
|
35
|
+
data.status = data.status ? VERSIONS_STATUS.DRAFT : undefined;
|
|
36
36
|
data = normalizeProps(data, locale, keepIds);
|
|
37
37
|
delete data.id;
|
|
38
38
|
return data;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* POST handler for the collection API endpoint.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restCreate(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types.js").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ERROR_CONTEXT, handleError } from '../../errors/handler.server.js';
|
|
2
|
+
import { RimeError } from '../../errors/index.js';
|
|
3
|
+
import { extractData } from '../../operations/extract-data.server.js';
|
|
4
|
+
import { trycatch } from '../../../util/function.js';
|
|
5
|
+
import { json } from '@sveltejs/kit';
|
|
6
|
+
import { isAuthConfig } from '../auth/util.js';
|
|
7
|
+
/**
|
|
8
|
+
* POST handler for the collection API endpoint.
|
|
9
|
+
*/
|
|
10
|
+
export async function restCreate(event) {
|
|
11
|
+
//
|
|
12
|
+
const { rime } = event.locals;
|
|
13
|
+
// Check if the slug corresponds to a valid collection
|
|
14
|
+
const slug = event.params.slug;
|
|
15
|
+
if (!rime.config.isCollection(slug)) {
|
|
16
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.API });
|
|
17
|
+
}
|
|
18
|
+
const collection = rime.collection(slug);
|
|
19
|
+
// Extract data from the request body
|
|
20
|
+
const [extractError, data] = await trycatch(() => extractData(event.request));
|
|
21
|
+
if (extractError) {
|
|
22
|
+
return handleError(extractError, { context: ERROR_CONTEXT.API });
|
|
23
|
+
}
|
|
24
|
+
// Bypass confirm password for api auth collection creation calls
|
|
25
|
+
if (isAuthConfig(collection.config) && 'password' in data) {
|
|
26
|
+
data.confirmPassword = data.password;
|
|
27
|
+
}
|
|
28
|
+
// Set the locale if provided in the data
|
|
29
|
+
if (data.locale) {
|
|
30
|
+
rime.setLocale(data.locale);
|
|
31
|
+
}
|
|
32
|
+
const [error, document] = await trycatch(() => collection.create({ data, locale: rime.getLocale() }));
|
|
33
|
+
if (error) {
|
|
34
|
+
return handleError(error, { context: ERROR_CONTEXT.API });
|
|
35
|
+
}
|
|
36
|
+
return json({ doc: document });
|
|
37
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* DELETE handler for the collection API endpoint.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restDelete(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { normalizeQuery } from '../../../adapter-sqlite/util.server.js';
|
|
2
|
+
import { PARAMS } from '../../constant.js';
|
|
3
|
+
import { RimeError } from '../../errors/index.js';
|
|
4
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
5
|
+
import { trycatch } from '../../../util/function.js';
|
|
6
|
+
import { json } from '@sveltejs/kit';
|
|
7
|
+
/**
|
|
8
|
+
* DELETE handler for the collection API endpoint.
|
|
9
|
+
*/
|
|
10
|
+
export async function restDelete(event) {
|
|
11
|
+
//
|
|
12
|
+
const { rime } = event.locals;
|
|
13
|
+
const slug = event.params.slug;
|
|
14
|
+
if (!rime.config.isCollection(slug)) {
|
|
15
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
16
|
+
}
|
|
17
|
+
const params = event.url.searchParams;
|
|
18
|
+
const hasQueryParams = !!params
|
|
19
|
+
.keys()
|
|
20
|
+
.filter((key) => key.startsWith('where'))
|
|
21
|
+
.toArray().length;
|
|
22
|
+
const query = hasQueryParams ? normalizeQuery(event.url.search.substring(1)) : undefined;
|
|
23
|
+
const apiParams = {
|
|
24
|
+
locale: rime.getLocale(),
|
|
25
|
+
sort: params.get(PARAMS.SORT) || undefined,
|
|
26
|
+
depth: params.get(PARAMS.DEPTH) ? parseInt(params.get(PARAMS.DEPTH)) : 0,
|
|
27
|
+
limit: params.get(PARAMS.LIMIT) ? parseInt(params.get(PARAMS.LIMIT)) : undefined,
|
|
28
|
+
offset: params.get(PARAMS.OFFSET) ? parseInt(params.get(PARAMS.OFFSET)) : undefined,
|
|
29
|
+
query,
|
|
30
|
+
select: params.get(PARAMS.SELECT) ? params.get(PARAMS.SELECT).split(',') : undefined
|
|
31
|
+
};
|
|
32
|
+
const [error, docs] = await trycatch(() => rime.collection(slug).delete(apiParams));
|
|
33
|
+
if (error) {
|
|
34
|
+
return handleError(error, { context: 'api' });
|
|
35
|
+
}
|
|
36
|
+
return json({ docs }, { status: 200 });
|
|
37
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* DELETE handler for the collection API endpoint to delete a document by its ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restDeleteById(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RimeError } from '../../errors/index.js';
|
|
2
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
3
|
+
import { trycatch } from '../../../util/function.js';
|
|
4
|
+
import { json } from '@sveltejs/kit';
|
|
5
|
+
/**
|
|
6
|
+
* DELETE handler for the collection API endpoint to delete a document by its ID.
|
|
7
|
+
*/
|
|
8
|
+
export async function restDeleteById(event) {
|
|
9
|
+
//
|
|
10
|
+
const { rime } = event.locals;
|
|
11
|
+
const slug = event.params.slug;
|
|
12
|
+
if (!rime.config.isCollection(slug)) {
|
|
13
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
14
|
+
}
|
|
15
|
+
const id = event.params.id || '';
|
|
16
|
+
const [error] = await trycatch(() => rime.collection(slug).deleteById({ id }));
|
|
17
|
+
if (error) {
|
|
18
|
+
return handleError(error, { context: 'api' });
|
|
19
|
+
}
|
|
20
|
+
return json({ id });
|
|
21
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
2
|
-
export
|
|
2
|
+
export declare function restDuplicate(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
3
3
|
form: Record<string, any>;
|
|
4
4
|
errors: import("../../../types").FormErrors;
|
|
5
5
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
2
|
+
import { RimeError } from '../../errors/index.js';
|
|
3
|
+
import { error, json } from '@sveltejs/kit';
|
|
4
|
+
export async function restDuplicate(event) {
|
|
5
|
+
//
|
|
6
|
+
const { rime } = event.locals;
|
|
7
|
+
const slug = event.params.slug;
|
|
8
|
+
if (!rime.config.isCollection(slug)) {
|
|
9
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
10
|
+
}
|
|
11
|
+
const collection = rime.collection(slug);
|
|
12
|
+
if (!event.params.id)
|
|
13
|
+
throw error(404);
|
|
14
|
+
const newId = await collection.duplicate({ id: event.params.id });
|
|
15
|
+
return json({ id: newId });
|
|
16
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* GET handler for the collection API endpoint.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restGet(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { normalizeQuery } from '../../../adapter-sqlite/util.server.js';
|
|
2
|
+
import { PARAMS } from '../../constant.js';
|
|
3
|
+
import { RimeError } from '../../errors/index.js';
|
|
4
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
5
|
+
import { trycatch } from '../../../util/function.js';
|
|
6
|
+
import { json } from '@sveltejs/kit';
|
|
7
|
+
/**
|
|
8
|
+
* GET handler for the collection API endpoint.
|
|
9
|
+
*/
|
|
10
|
+
export async function restGet(event) {
|
|
11
|
+
//
|
|
12
|
+
const { rime } = event.locals;
|
|
13
|
+
const slug = event.params.slug;
|
|
14
|
+
if (!rime.config.isCollection(slug)) {
|
|
15
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
16
|
+
}
|
|
17
|
+
const params = event.url.searchParams;
|
|
18
|
+
const hasQueryParams = !!params
|
|
19
|
+
.keys()
|
|
20
|
+
.filter((key) => key.startsWith('where'))
|
|
21
|
+
.toArray().length;
|
|
22
|
+
const collectionAPI = rime.collection(slug);
|
|
23
|
+
function buildSelect(params) {
|
|
24
|
+
const paramSelect = params.get(PARAMS.SELECT)
|
|
25
|
+
? params.get(PARAMS.SELECT).split(',')
|
|
26
|
+
: undefined;
|
|
27
|
+
if (paramSelect &&
|
|
28
|
+
paramSelect.includes('title') &&
|
|
29
|
+
!paramSelect.includes(collectionAPI.config.asTitle)) {
|
|
30
|
+
paramSelect.push(collectionAPI.config.asTitle);
|
|
31
|
+
}
|
|
32
|
+
return paramSelect;
|
|
33
|
+
}
|
|
34
|
+
const query = hasQueryParams ? normalizeQuery(event.url.search.substring(1)) : undefined;
|
|
35
|
+
const apiParams = {
|
|
36
|
+
locale: rime.getLocale(),
|
|
37
|
+
sort: params.get(PARAMS.SORT) || undefined,
|
|
38
|
+
depth: params.get(PARAMS.DEPTH) ? parseInt(params.get(PARAMS.DEPTH)) : 0,
|
|
39
|
+
limit: params.get(PARAMS.LIMIT) ? parseInt(params.get(PARAMS.LIMIT)) : undefined,
|
|
40
|
+
offset: params.get(PARAMS.OFFSET) ? parseInt(params.get(PARAMS.OFFSET)) : undefined,
|
|
41
|
+
draft: params.get(PARAMS.DRAFT) ? params.get(PARAMS.DRAFT) === 'true' : undefined,
|
|
42
|
+
query,
|
|
43
|
+
select: buildSelect(params)
|
|
44
|
+
};
|
|
45
|
+
const [error, docs] = await trycatch(() => collectionAPI.find(apiParams));
|
|
46
|
+
if (error) {
|
|
47
|
+
return handleError(error, { context: 'api' });
|
|
48
|
+
}
|
|
49
|
+
return json({ docs }, { status: 200 });
|
|
50
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* GET handler for the collection API endpoint to retrieve a document by its ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restGetById(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PARAMS } from '../../constant.js';
|
|
2
|
+
import { RimeError } from '../../errors/index.js';
|
|
3
|
+
import { handleError } from '../../errors/handler.server.js';
|
|
4
|
+
import { trycatch } from '../../../util/function.js';
|
|
5
|
+
import { json } from '@sveltejs/kit';
|
|
6
|
+
/**
|
|
7
|
+
* GET handler for the collection API endpoint to retrieve a document by its ID.
|
|
8
|
+
*/
|
|
9
|
+
export async function restGetById(event) {
|
|
10
|
+
//
|
|
11
|
+
const { rime } = event.locals;
|
|
12
|
+
const slug = event.params.slug;
|
|
13
|
+
const id = event.params.id;
|
|
14
|
+
if (!rime.config.isCollection(slug) || !id) {
|
|
15
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: 'api' });
|
|
16
|
+
}
|
|
17
|
+
const paramDepth = event.url.searchParams.get(PARAMS.DEPTH);
|
|
18
|
+
const paramDraft = event.url.searchParams.get(PARAMS.DRAFT);
|
|
19
|
+
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
20
|
+
const draft = paramDraft ? paramDraft === 'true' : undefined;
|
|
21
|
+
const depth = typeof paramDepth === 'string' ? parseInt(paramDepth) : 0;
|
|
22
|
+
const select = event.url.searchParams.get(PARAMS.SELECT)?.split(',') || undefined;
|
|
23
|
+
const [error, document] = await trycatch(() => rime.collection(slug).findById({
|
|
24
|
+
id,
|
|
25
|
+
locale: rime.getLocale(),
|
|
26
|
+
depth,
|
|
27
|
+
draft,
|
|
28
|
+
versionId,
|
|
29
|
+
select
|
|
30
|
+
}));
|
|
31
|
+
if (error) {
|
|
32
|
+
return handleError(error, { context: 'api' });
|
|
33
|
+
}
|
|
34
|
+
return json({ doc: document });
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { restCreate } from './create.server.js';
|
|
2
|
+
import { restDelete } from './delete.server.js';
|
|
3
|
+
import { restDeleteById } from './deleteById.server.js';
|
|
4
|
+
import { restDuplicate } from './duplicate.server.js';
|
|
5
|
+
import { restGet } from './get.server.js';
|
|
6
|
+
import { restGetById } from './getById.server.js';
|
|
7
|
+
import { restUpdateById } from './updateById.server.js';
|
|
8
|
+
export declare const rest: {
|
|
9
|
+
get: typeof restGet;
|
|
10
|
+
getById: typeof restGetById;
|
|
11
|
+
deleteById: typeof restDeleteById;
|
|
12
|
+
delete: typeof restDelete;
|
|
13
|
+
create: typeof restCreate;
|
|
14
|
+
updateById: typeof restUpdateById;
|
|
15
|
+
duplicate: typeof restDuplicate;
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { restCreate } from './create.server.js';
|
|
2
|
+
import { restDelete } from './delete.server.js';
|
|
3
|
+
import { restDeleteById } from './deleteById.server.js';
|
|
4
|
+
import { restDuplicate } from './duplicate.server.js';
|
|
5
|
+
import { restGet } from './get.server.js';
|
|
6
|
+
import { restGetById } from './getById.server.js';
|
|
7
|
+
import { restUpdateById } from './updateById.server.js';
|
|
8
|
+
export const rest = {
|
|
9
|
+
get: restGet,
|
|
10
|
+
getById: restGetById,
|
|
11
|
+
deleteById: restDeleteById,
|
|
12
|
+
delete: restDelete,
|
|
13
|
+
create: restCreate,
|
|
14
|
+
updateById: restUpdateById,
|
|
15
|
+
duplicate: restDuplicate
|
|
16
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { CollectionSlug } from '../../types/doc.js';
|
|
2
1
|
import { type RequestEvent } from '@sveltejs/kit';
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* PATCH handler for the collection API endpoint to update a document by its ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare function restUpdateById(event: RequestEvent): Promise<Response | import("@sveltejs/kit").ActionFailure<{
|
|
4
6
|
form: Record<string, any>;
|
|
5
7
|
errors: import("../../../types").FormErrors;
|
|
6
8
|
}> | import("@sveltejs/kit").ActionFailure<{
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PARAMS } from '../../constant.js';
|
|
2
|
+
import { ERROR_CONTEXT, handleError } from '../../errors/handler.server.js';
|
|
3
|
+
import { RimeError } from '../../errors/index.js';
|
|
4
|
+
import { extractData } from '../../operations/extract-data.server.js';
|
|
5
|
+
import { trycatch } from '../../../util/function.js';
|
|
6
|
+
import { json } from '@sveltejs/kit';
|
|
7
|
+
/**
|
|
8
|
+
* PATCH handler for the collection API endpoint to update a document by its ID.
|
|
9
|
+
*/
|
|
10
|
+
export async function restUpdateById(event) {
|
|
11
|
+
//
|
|
12
|
+
const { rime } = event.locals;
|
|
13
|
+
const slug = event.params.slug;
|
|
14
|
+
const id = event.params.id;
|
|
15
|
+
// Check if the slug corresponds to a valid collection and if the ID is provided
|
|
16
|
+
if (!rime.config.isCollection(slug) || !id) {
|
|
17
|
+
return handleError(new RimeError(RimeError.NOT_FOUND), { context: ERROR_CONTEXT.API });
|
|
18
|
+
}
|
|
19
|
+
// Extract query parameters for versioning and draft status
|
|
20
|
+
const versionId = event.url.searchParams.get(PARAMS.VERSION_ID) || undefined;
|
|
21
|
+
const draft = event.url.searchParams.get(PARAMS.DRAFT)
|
|
22
|
+
? event.url.searchParams.get(PARAMS.DRAFT) === 'true'
|
|
23
|
+
: undefined;
|
|
24
|
+
// Extract data from the request body
|
|
25
|
+
const [extractError, data] = await trycatch(() => extractData(event.request));
|
|
26
|
+
if (extractError) {
|
|
27
|
+
return handleError(extractError, { context: ERROR_CONTEXT.API });
|
|
28
|
+
}
|
|
29
|
+
// Set the locale if provided in the data
|
|
30
|
+
if (data.locale) {
|
|
31
|
+
rime.setLocale(data.locale);
|
|
32
|
+
}
|
|
33
|
+
const [error, document] = await trycatch(() => rime.collection(slug).updateById({
|
|
34
|
+
id,
|
|
35
|
+
data,
|
|
36
|
+
locale: rime.getLocale(),
|
|
37
|
+
versionId,
|
|
38
|
+
draft
|
|
39
|
+
}));
|
|
40
|
+
if (error) {
|
|
41
|
+
return handleError(error, { context: ERROR_CONTEXT.API });
|
|
42
|
+
}
|
|
43
|
+
return json({ doc: document });
|
|
44
|
+
}
|