rimecms 1.1.1 → 1.1.2
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/dist/adapter-sqlite/read.server.js +4 -4
- package/dist/adapter-sqlite/table.server.d.ts +3 -6
- package/dist/adapter-sqlite/table.server.js +3 -6
- package/dist/adapter-sqlite/transform.server.d.ts +1 -1
- package/dist/adapter-sqlite/transform.server.js +3 -2
- package/dist/adapter-sqlite/write.server.d.ts +13 -15
- package/dist/adapter-sqlite/write.server.js +15 -17
- package/dist/core/adapter.d.ts +19 -33
- package/dist/core/adapter.js +0 -12
- package/dist/core/auth/augment.js +2 -1
- package/dist/core/auth/hooks/augment-fields-password.server.d.ts +2 -2
- package/dist/core/auth/hooks/augment-fields-password.server.js +2 -2
- package/dist/core/auth/tables.d.ts +2 -5
- package/dist/core/auth/tables.js +3 -7
- package/dist/core/auth/validate-config.d.ts +3 -8
- package/dist/core/auth/validate-config.js +4 -10
- package/dist/core/config/types.d.ts +6 -6
- package/dist/core/config/validate.server.js +11 -0
- package/dist/core/fields/builders/boolean-builder.d.ts +2 -2
- package/dist/core/fields/builders/boolean-builder.js +4 -1
- package/dist/core/fields/builders/select-builder.d.ts +3 -3
- package/dist/core/fields/builders/select-builder.js +4 -2
- package/dist/core/fields/complete.d.ts +18 -0
- package/dist/core/fields/complete.js +32 -0
- package/dist/core/fields/empty.d.ts +14 -0
- package/dist/core/fields/empty.js +13 -0
- package/dist/core/fields/initial.d.ts +32 -0
- package/dist/core/fields/initial.js +47 -0
- package/dist/core/fields/util.d.ts +0 -16
- package/dist/core/fields/util.js +0 -29
- package/dist/core/pipeline/build-document.server.d.ts +4 -10
- package/dist/core/pipeline/build-document.server.js +8 -17
- package/dist/core/pipeline/hooks/data-config-map.server.d.ts +1 -1
- package/dist/core/pipeline/hooks/data-config-map.server.js +1 -1
- package/dist/core/pipeline/hooks/process-document-fields.server.d.ts +3 -2
- package/dist/core/pipeline/hooks/process-document-fields.server.js +3 -16
- package/dist/core/pipeline/hooks/set-default-values.server.d.ts +15 -4
- package/dist/core/pipeline/hooks/set-default-values.server.js +50 -25
- package/dist/core/pipeline/hooks/validate-fields.server.js +1 -1
- package/dist/core/pipeline/run.server.js +1 -2
- package/dist/core/prototype/area/api.server.d.ts +4 -6
- package/dist/core/prototype/area/api.server.js +4 -6
- package/dist/core/prototype/area/definition.server.js +23 -9
- package/dist/core/prototype/area/hooks.server.js +1 -1
- package/dist/core/prototype/collection/api.server.d.ts +5 -6
- package/dist/core/prototype/collection/api.server.js +5 -6
- package/dist/core/prototype/collection/definition.js +3 -8
- package/dist/core/prototype/collection/hooks/merge-with-initial.server.d.ts +15 -0
- package/dist/core/prototype/collection/hooks/merge-with-initial.server.js +20 -0
- package/dist/core/prototype/collection/hooks.server.js +5 -5
- package/dist/core/prototype/collection/nested/module.js +1 -1
- package/dist/core/prototype/collection/nested/module.server.js +1 -1
- package/dist/core/prototype/collection/operations/duplicate.js +4 -8
- package/dist/core/prototype/collection/upload/directories/derive.js +2 -2
- package/dist/core/prototype/collection/upload/hooks/handle-path-creation.server.js +2 -2
- package/dist/core/prototype/define.d.ts +2 -2
- package/dist/core/prototype/define.js +4 -4
- package/dist/core/prototype/initial.d.ts +23 -0
- package/dist/core/prototype/initial.js +19 -0
- package/dist/core/prototype/shared/versions/augment.d.ts +2 -4
- package/dist/core/prototype/shared/versions/augment.js +4 -6
- package/dist/core/prototype/shared/versions/configure.server.js +3 -3
- package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.d.ts +14 -2
- package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.js +28 -22
- package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +3 -4
- package/dist/core/prototype/shared/versions/{blank.d.ts → initial.d.ts} +2 -4
- package/dist/core/prototype/shared/versions/{blank.js → initial.js} +2 -4
- package/dist/core/prototype/when.d.ts +2 -6
- package/dist/core/prototype/when.js +2 -6
- package/dist/fields/blocks/component/AddBlockButton.svelte +2 -2
- package/dist/fields/blocks/component/focus/BlocksFocus.svelte +2 -13
- package/dist/fields/blocks/component/focus/Inspector.svelte +43 -3
- package/dist/fields/blocks/component/focus/Renders.svelte +29 -1
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +24 -4
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +6 -1
- package/dist/fields/blocks/component/focus/focus.svelte.d.ts +11 -3
- package/dist/fields/blocks/component/focus/focus.svelte.js +31 -10
- package/dist/fields/blocks/defaults.d.ts +22 -0
- package/dist/fields/blocks/defaults.js +23 -0
- package/dist/fields/blocks/index.d.ts +18 -2
- package/dist/fields/blocks/index.js +30 -0
- package/dist/fields/combobox/index.d.ts +2 -2
- package/dist/fields/combobox/index.js +2 -1
- package/dist/fields/date/index.d.ts +2 -2
- package/dist/fields/date/index.js +2 -1
- package/dist/fields/email/index.d.ts +2 -2
- package/dist/fields/email/index.js +2 -1
- package/dist/fields/group/index.d.ts +1 -0
- package/dist/fields/link/index.d.ts +3 -2
- package/dist/fields/link/index.js +2 -1
- package/dist/fields/number/index.d.ts +3 -2
- package/dist/fields/number/index.js +2 -1
- package/dist/fields/relation/component/default/Default.svelte +1 -1
- package/dist/fields/relation/component/upload/Create.svelte +1 -1
- package/dist/fields/relation/index.d.ts +2 -2
- package/dist/fields/relation/index.js +2 -1
- package/dist/fields/rich-text/index.d.ts +2 -2
- package/dist/fields/rich-text/index.js +2 -1
- package/dist/fields/slug/index.d.ts +3 -2
- package/dist/fields/slug/index.js +2 -1
- package/dist/fields/text/index.d.ts +3 -2
- package/dist/fields/text/index.js +2 -1
- package/dist/fields/textarea/index.d.ts +3 -2
- package/dist/fields/textarea/index.js +2 -1
- package/dist/fields/time/index.d.ts +2 -2
- package/dist/fields/time/index.js +2 -1
- package/dist/fields/toggle/index.d.ts +3 -2
- package/dist/fields/toggle/index.js +2 -2
- package/dist/fields/tree/component/AddItemButton.svelte +3 -4
- package/dist/fields/tree/component/AddItemButton.svelte.d.ts +1 -1
- package/dist/fields/tree/defaults.d.ts +21 -0
- package/dist/fields/tree/defaults.js +18 -0
- package/dist/fields/tree/index.d.ts +17 -3
- package/dist/fields/tree/index.js +27 -0
- package/dist/fields/types.d.ts +14 -0
- package/dist/panel/context/blocks-ops.d.ts +0 -1
- package/dist/panel/context/blocks-ops.js +1 -2
- package/dist/panel/pages/collection-document/load.server.js +1 -1
- package/dist/util/object.d.ts +2 -2
- package/dist/util/object.js +3 -3
- package/dist/util/random.d.ts +2 -0
- package/dist/util/random.js +2 -0
- package/package.json +1 -1
- package/dist/core/fields/blank.d.ts +0 -21
- package/dist/core/fields/blank.js +0 -37
- package/dist/core/prototype/blank.d.ts +0 -26
- package/dist/core/prototype/blank.js +0 -22
- package/dist/core/prototype/collection/hooks/merge-with-blank.server.d.ts +0 -9
- package/dist/core/prototype/collection/hooks/merge-with-blank.server.js +0 -14
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FieldBuilder } from './builders/field-builder.js';
|
|
2
|
+
import type { Field } from '../../fields/types.js';
|
|
3
|
+
import type { Dic } from '../../util/types.js';
|
|
4
|
+
/** A field whose value is rows of their own table: blocks, tree items, relations. */
|
|
5
|
+
export declare const isListField: (field: FieldBuilder) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The fields a document lacks, added empty: `[]` for blocks, tree and relations, `null` for the
|
|
8
|
+
* others. A list with no rows has no key, so a read always lacks it.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* withEmptyFields({ title: 'Home' }, fields); // { title: 'Home', sections: [], image: [] }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const withEmptyFields: <T extends Dic>(doc: T, fields: FieldBuilder<Field>[]) => T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { withDefaultValues } from '../../util/object.js';
|
|
2
|
+
import { fieldValues } from './initial.js';
|
|
3
|
+
/** A field whose value is rows of their own table: blocks, tree items, relations. */
|
|
4
|
+
export const isListField = (field) => field.type === 'blocks' || field.type === 'tree' || field.type === 'relation';
|
|
5
|
+
/**
|
|
6
|
+
* The fields a document lacks, added empty: `[]` for blocks, tree and relations, `null` for the
|
|
7
|
+
* others. A list with no rows has no key, so a read always lacks it.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* withEmptyFields({ title: 'Home' }, fields); // { title: 'Home', sections: [], image: [] }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const withEmptyFields = (doc, fields) => withDefaultValues(doc, fieldValues(fields, (field) => (isListField(field) ? [] : null)));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { FieldBuilder } from './builders/field-builder.js';
|
|
2
|
+
import type { FormFieldBuilder } from './builders/form-field-builder.js';
|
|
3
|
+
import type { Field, FormField } from '../../fields/types.js';
|
|
4
|
+
import type { Dic } from '../../util/types.js';
|
|
5
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
6
|
+
/** What a field is handed to build its initial value. The event is a default's, and boot has none. */
|
|
7
|
+
export type InitialContext = {
|
|
8
|
+
event?: RequestEvent;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A list of fields as an object, each field contributing its own members, each leaf holding what
|
|
12
|
+
* `leaf` gives it.
|
|
13
|
+
*
|
|
14
|
+
* A branch opens an object, a leaf holds its value, and a repeater is a leaf — `#` in a segment
|
|
15
|
+
* means only a document can name the children.
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* group('attributes').fields(text('title')) -> { attributes: { title: … } }
|
|
19
|
+
* tabs(tab('meta').fields(text('title'))) -> { meta: { title: … } }
|
|
20
|
+
* blocks('layout', [...]) -> { layout: … }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const fieldValues: (fields: FieldBuilder<Field>[], leaf: (field: FormFieldBuilder<FormField>) => unknown) => Dic;
|
|
24
|
+
/**
|
|
25
|
+
* What a new document, a new block or a new tree item starts with: each field's default, `null`
|
|
26
|
+
* for a field without one.
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* text('title').defaultValue('Untitled'), text('slug') -> { title: 'Untitled', slug: null }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const initialValues: (fields: FieldBuilder<Field>[], context?: InitialContext) => Dic;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isFormField } from './util.js';
|
|
2
|
+
/**
|
|
3
|
+
* A list of fields as an object, each field contributing its own members, each leaf holding what
|
|
4
|
+
* `leaf` gives it.
|
|
5
|
+
*
|
|
6
|
+
* A branch opens an object, a leaf holds its value, and a repeater is a leaf — `#` in a segment
|
|
7
|
+
* means only a document can name the children.
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* group('attributes').fields(text('title')) -> { attributes: { title: … } }
|
|
11
|
+
* tabs(tab('meta').fields(text('title'))) -> { meta: { title: … } }
|
|
12
|
+
* blocks('layout', [...]) -> { layout: … }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const fieldValues = (fields, leaf) => {
|
|
16
|
+
const doc = {};
|
|
17
|
+
for (const field of fields) {
|
|
18
|
+
try {
|
|
19
|
+
const nodes = field.use.nodes();
|
|
20
|
+
if (!nodes.length || nodes.some((node) => node.segment.includes('#'))) {
|
|
21
|
+
if (isFormField(field))
|
|
22
|
+
doc[field.name] = leaf(field);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// Its name opens an object, or it has none and its branches land on this one.
|
|
26
|
+
const target = field.name ? (doc[field.name] = {}) : doc;
|
|
27
|
+
for (const node of nodes) {
|
|
28
|
+
const bucket = node.segment ? (target[node.segment] = {}) : target;
|
|
29
|
+
Object.assign(bucket, fieldValues(node.fields, leaf));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error(`Building the value of ${field.type} field "${field.name}" failed.`);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return doc;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* What a new document, a new block or a new tree item starts with: each field's default, `null`
|
|
41
|
+
* for a field without one.
|
|
42
|
+
*
|
|
43
|
+
* ```
|
|
44
|
+
* text('title').defaultValue('Untitled'), text('slug') -> { title: 'Untitled', slug: null }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const initialValues = (fields, context = {}) => fieldValues(fields, (field) => field.use.defaultValue(context) ?? null);
|
|
@@ -20,22 +20,6 @@ export declare const isNotHidden: <T extends FormField>(field: FormFieldBuilder<
|
|
|
20
20
|
* Checks if a field has live updates enabled.
|
|
21
21
|
*/
|
|
22
22
|
export declare const isLiveField: (field: Field) => boolean | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Creates an object with empty values based on field configurations.
|
|
25
|
-
* Uses defaultValue if specified, otherwise undefined.
|
|
26
|
-
* Handles nested fields like groups and tabs recursively.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* // Returns { title: '', attributes: { name: '', description: '' } }
|
|
30
|
-
* emptyValuesFromFieldConfig([
|
|
31
|
-
* { name: 'title', type: 'text', defaultValue: '' },
|
|
32
|
-
* { name: 'attributes', type: 'group', fields: [
|
|
33
|
-
* { name: 'name', type: 'text', defaultValue: '' },
|
|
34
|
-
* { name: 'description', type: 'text', defaultValue: '' }
|
|
35
|
-
* ]}
|
|
36
|
-
* ]);
|
|
37
|
-
*/
|
|
38
|
-
export declare const emptyValuesFromFieldConfig: (fields: FieldBuilder[]) => Dic;
|
|
39
23
|
/**
|
|
40
24
|
* Converts a path with numeric indices to a regex pattern
|
|
41
25
|
* Numbers between dots or between dot and colon are converted to \d+
|
package/dist/core/fields/util.js
CHANGED
|
@@ -18,35 +18,6 @@ export const isNotHidden = (field) => !field.get.hidden;
|
|
|
18
18
|
* Checks if a field has live updates enabled.
|
|
19
19
|
*/
|
|
20
20
|
export const isLiveField = (field) => field.live;
|
|
21
|
-
/**
|
|
22
|
-
* Creates an object with empty values based on field configurations.
|
|
23
|
-
* Uses defaultValue if specified, otherwise undefined.
|
|
24
|
-
* Handles nested fields like groups and tabs recursively.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* // Returns { title: '', attributes: { name: '', description: '' } }
|
|
28
|
-
* emptyValuesFromFieldConfig([
|
|
29
|
-
* { name: 'title', type: 'text', defaultValue: '' },
|
|
30
|
-
* { name: 'attributes', type: 'group', fields: [
|
|
31
|
-
* { name: 'name', type: 'text', defaultValue: '' },
|
|
32
|
-
* { name: 'description', type: 'text', defaultValue: '' }
|
|
33
|
-
* ]}
|
|
34
|
-
* ]);
|
|
35
|
-
*/
|
|
36
|
-
export const emptyValuesFromFieldConfig = (fields) => Object.fromEntries(fields.filter(isFormField).map((config) => {
|
|
37
|
-
const nodes = config.use.nodes();
|
|
38
|
-
// A leaf, and a repeater with it: `#` means only a document can name the children, so an
|
|
39
|
-
// empty one holds the field's own default.
|
|
40
|
-
if (!nodes.length || nodes.some((node) => node.segment.includes('#'))) {
|
|
41
|
-
return [config.name, config.use.defaultValue()];
|
|
42
|
-
}
|
|
43
|
-
const value = {};
|
|
44
|
-
for (const node of nodes) {
|
|
45
|
-
const bucket = node.segment ? (value[node.segment] = {}) : value;
|
|
46
|
-
Object.assign(bucket, emptyValuesFromFieldConfig(node.fields));
|
|
47
|
-
}
|
|
48
|
-
return [config.name, value];
|
|
49
|
-
}));
|
|
50
21
|
/**
|
|
51
22
|
* Converts a path with numeric indices to a regex pattern
|
|
52
23
|
* Numbers between dots or between dot and colon are converted to \d+
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import type { DocumentRows } from '../adapter.js';
|
|
2
2
|
import type { BuiltArea, BuiltCollection } from '../config/types.js';
|
|
3
3
|
import type { GenericDoc } from '../prototype/types.js';
|
|
4
|
-
import type { RequestEvent } from '@sveltejs/kit';
|
|
5
4
|
import { type Populated } from './populate-relations.server.js';
|
|
6
5
|
/**
|
|
7
|
-
* Assembles one document out of the rows it is stored across.
|
|
8
|
-
*
|
|
9
|
-
* This half used to live in the adapter, which is why the database layer merged a blank document,
|
|
10
|
-
* read `event.params.panel` to decide which bookkeeping to keep, and called back up into the local
|
|
11
|
-
* API to walk relations. None of it needs a table: rows arrive keyed by document path, and what
|
|
12
|
-
* happens to them from here is a question about documents.
|
|
6
|
+
* Assembles one document out of the rows it is stored across. Rows arrive keyed by document path,
|
|
7
|
+
* and what happens to them from here is a question about documents, not about tables.
|
|
13
8
|
*/
|
|
14
9
|
export declare const buildDocument: <T extends GenericDoc = GenericDoc>(rows: DocumentRows, args: {
|
|
15
10
|
config: BuiltCollection | BuiltArea;
|
|
16
|
-
event: RequestEvent;
|
|
17
11
|
locale?: string | undefined;
|
|
18
12
|
depth?: number;
|
|
19
13
|
/** What the relations point at, read ahead for the whole list. Read when `depth > 0`. */
|
|
20
14
|
populated?: Populated;
|
|
21
|
-
/**
|
|
22
|
-
|
|
15
|
+
/** Every field the config declares is present, empty when nothing is stored. */
|
|
16
|
+
allFields?: boolean;
|
|
23
17
|
/**
|
|
24
18
|
* Keep a child row's own bookkeeping on it — `position`, `path`, `ownerId`, `locale` — and
|
|
25
19
|
* the edit lock on the document. An API read wants the document; an editor that writes blocks
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withEmptyFields } from '../fields/empty.js';
|
|
2
|
+
import { isObjectLiteral, omit } from '../../util/object.js';
|
|
2
3
|
import { unflatten } from 'flat';
|
|
3
4
|
import { logger } from '../logger.server.js';
|
|
4
5
|
import { populatedKey } from './populate-relations.server.js';
|
|
5
6
|
/**
|
|
6
|
-
* Assembles one document out of the rows it is stored across.
|
|
7
|
-
*
|
|
8
|
-
* This half used to live in the adapter, which is why the database layer merged a blank document,
|
|
9
|
-
* read `event.params.panel` to decide which bookkeeping to keep, and called back up into the local
|
|
10
|
-
* API to walk relations. None of it needs a table: rows arrive keyed by document path, and what
|
|
11
|
-
* happens to them from here is a question about documents.
|
|
7
|
+
* Assembles one document out of the rows it is stored across. Rows arrive keyed by document path,
|
|
8
|
+
* and what happens to them from here is a question about documents, not about tables.
|
|
12
9
|
*/
|
|
13
10
|
export const buildDocument = async (rows, args) => {
|
|
14
|
-
const { config,
|
|
15
|
-
const { rime } = event.locals;
|
|
11
|
+
const { config, locale, depth = 0, populated, allFields = true, withRowMeta = false } = args;
|
|
16
12
|
const flatDoc = { ...rows.base };
|
|
17
13
|
for (const block of rows.blocks) {
|
|
18
14
|
flatDoc[`${block.path}.${block.position}`] = stripRowMeta(block, withRowMeta);
|
|
@@ -52,14 +48,9 @@ export const buildDocument = async (rows, args) => {
|
|
|
52
48
|
}
|
|
53
49
|
flatDoc[path] = [...(flatDoc[path] || []), output];
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
? rime.collection(config.slug).blank()
|
|
59
|
-
: rime.area(config.slug).blank();
|
|
60
|
-
doc = withDefaults(doc, blank);
|
|
61
|
-
}
|
|
62
|
-
return doc;
|
|
51
|
+
const doc = cleanEmptyElementsInArrays(unflatten(flatDoc));
|
|
52
|
+
// A field with nothing stored reads empty, never as its default.
|
|
53
|
+
return (allFields ? withEmptyFields(doc, config.fields) : doc);
|
|
63
54
|
};
|
|
64
55
|
/**
|
|
65
56
|
* A child row's own bookkeeping, dropped unless the caller asked to keep it.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Maps every path in the incoming data to the field builder that describes it, on
|
|
3
3
|
* `context.configMap`.
|
|
4
4
|
*
|
|
5
|
-
* What `
|
|
5
|
+
* What `validateFields` walks, and what the write turns into
|
|
6
6
|
* `incomingPaths` — the set of paths this request is allowed to touch.
|
|
7
7
|
*/
|
|
8
8
|
export declare const buildDataConfigMap: import("../types.js").Hook<"raw", "create" | "update", "before">;
|
|
@@ -4,7 +4,7 @@ import { buildConfigMap } from '../config-map/index.js';
|
|
|
4
4
|
* Maps every path in the incoming data to the field builder that describes it, on
|
|
5
5
|
* `context.configMap`.
|
|
6
6
|
*
|
|
7
|
-
* What `
|
|
7
|
+
* What `validateFields` walks, and what the write turns into
|
|
8
8
|
* `incomingPaths` — the set of paths this request is allowed to touch.
|
|
9
9
|
*/
|
|
10
10
|
export const buildDataConfigMap = Hooks.beforeUpsert(async function buildDataConfigMap(args) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Walks every field of the document on the way out: drops what the reader may not see,
|
|
3
|
-
*
|
|
2
|
+
* Walks every field of the document on the way out: drops what the reader may not see, and hands
|
|
3
|
+
* each value to the field's own `hooks.beforeRead`. An empty value stays empty: a default is what
|
|
4
|
+
* a new document starts with, never what a read shows.
|
|
4
5
|
*
|
|
5
6
|
* One copy of the document, walked in place. A config-map key is already normalized, so it is
|
|
6
7
|
* its segments and nothing else; a copy of the document per key was most of this hook.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Hooks } from '../define-hook.js';
|
|
2
|
-
import { logger } from '../../logger.server.js';
|
|
3
2
|
import { buildConfigMap } from '../config-map/index.js';
|
|
4
|
-
import { getDefaultValue } from './set-default-values.server.js';
|
|
5
3
|
/**
|
|
6
|
-
* Walks every field of the document on the way out: drops what the reader may not see,
|
|
7
|
-
*
|
|
4
|
+
* Walks every field of the document on the way out: drops what the reader may not see, and hands
|
|
5
|
+
* each value to the field's own `hooks.beforeRead`. An empty value stays empty: a default is what
|
|
6
|
+
* a new document starts with, never what a read shows.
|
|
8
7
|
*
|
|
9
8
|
* One copy of the document, walked in place. A config-map key is already normalized, so it is
|
|
10
9
|
* its segments and nothing else; a copy of the document per key was most of this hook.
|
|
@@ -29,18 +28,6 @@ export const processDocumentFields = Hooks.beforeRead(async function processDocu
|
|
|
29
28
|
});
|
|
30
29
|
setAt(doc, parts, value);
|
|
31
30
|
}
|
|
32
|
-
let isEmpty;
|
|
33
|
-
try {
|
|
34
|
-
isEmpty = config.use.isEmpty(value);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
isEmpty = false;
|
|
38
|
-
logger.warn(`Error in config.isEmpty for field ${key}`);
|
|
39
|
-
}
|
|
40
|
-
if (isEmpty && config.get.defaultValue !== undefined) {
|
|
41
|
-
value = await getDefaultValue({ key, config, adapter: args.event.locals.rime.adapter });
|
|
42
|
-
setAt(doc, parts, value);
|
|
43
|
-
}
|
|
44
31
|
if (config.type === 'blocks') {
|
|
45
32
|
const blocks = getAt(doc, parts);
|
|
46
33
|
// Filter out possible undefined block or residual
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import type { Adapter } from '../../adapter.js';
|
|
2
2
|
import type { FormFieldBuilder } from '../../fields/builders/form-field-builder.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Gives an empty value its default on every save, for a field that says `fill: 'save'`: a value
|
|
5
|
+
* sent empty and, on an update, a field not sent whose stored value is empty. Any other field
|
|
6
|
+
* keeps what it was sent; a create gives a field not sent its default before this, in
|
|
7
|
+
* `mergeWithInitialDocument`.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* date('publishedAt').defaultValue(() => new Date(), { fill: 'save' });
|
|
11
|
+
* // PATCH { publishedAt: null } -> now
|
|
12
|
+
* // PATCH {}, stored null -> now
|
|
13
|
+
* // PATCH {}, stored 2026-02-01 -> unchanged
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* It sits above `buildDataConfigMap`, so a field it adds is written. A relation's default is one
|
|
17
|
+
* id or a list of them, and only the ids that name a document that exists survive — see
|
|
18
|
+
* `defaultRelationValue`.
|
|
8
19
|
*/
|
|
9
|
-
export declare const setDefaultValues: import("../types").Hook<"raw", "create" | "update", "before">;
|
|
20
|
+
export declare const setDefaultValues: import("../types.js").Hook<"raw", "create" | "update", "before">;
|
|
10
21
|
type GetDefaultValue = (args: {
|
|
11
22
|
key: string;
|
|
12
23
|
config: FormFieldBuilder;
|
|
@@ -1,43 +1,68 @@
|
|
|
1
1
|
import { Hooks } from '../define-hook.js';
|
|
2
2
|
import { getRequestEvent } from '$app/server';
|
|
3
|
-
import {
|
|
3
|
+
import { isFormField } from '../../fields/util.js';
|
|
4
|
+
import { walkFields } from '../../fields/walk.js';
|
|
4
5
|
import { logger } from '../../logger.server.js';
|
|
5
6
|
import { RelationFieldBuilder } from '../../../fields/relation/index.js';
|
|
6
7
|
import { getValueAtPath, setValueAtPath } from '../../../util/object.js';
|
|
8
|
+
import { buildConfigMap } from '../config-map/index.js';
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* Gives an empty value its default on every save, for a field that says `fill: 'save'`: a value
|
|
11
|
+
* sent empty and, on an update, a field not sent whose stored value is empty. Any other field
|
|
12
|
+
* keeps what it was sent; a create gives a field not sent its default before this, in
|
|
13
|
+
* `mergeWithInitialDocument`.
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* date('publishedAt').defaultValue(() => new Date(), { fill: 'save' });
|
|
17
|
+
* // PATCH { publishedAt: null } -> now
|
|
18
|
+
* // PATCH {}, stored null -> now
|
|
19
|
+
* // PATCH {}, stored 2026-02-01 -> unchanged
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* It sits above `buildDataConfigMap`, so a field it adds is written. A relation's default is one
|
|
23
|
+
* id or a list of them, and only the ids that name a document that exists survive — see
|
|
24
|
+
* `defaultRelationValue`.
|
|
12
25
|
*/
|
|
13
26
|
export const setDefaultValues = Hooks.beforeUpsert(async function setDefaultValues(args) {
|
|
14
27
|
const { operation, event } = args;
|
|
15
28
|
const { rime } = event.locals;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
throw new RimeError(RimeError.OPERATION_ERROR, 'missing configMap @setDefaultValues');
|
|
29
|
+
const fields = args.config.fields;
|
|
30
|
+
const stored = operation === 'update' ? args.context.originalDoc : undefined;
|
|
19
31
|
let output = { ...args.data };
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const fill = async (key, config) => {
|
|
33
|
+
const value = await getDefaultValue({ key, config, adapter: rime.adapter });
|
|
34
|
+
output = setValueAtPath(key, output, value);
|
|
35
|
+
};
|
|
36
|
+
// The values sent, blocks and tree items included: an empty one takes its default.
|
|
37
|
+
for (const [key, config] of Object.entries(buildConfigMap(output, fields))) {
|
|
38
|
+
if (config.get.defaultFill !== 'save')
|
|
39
|
+
continue;
|
|
40
|
+
if (isEmpty(config, key, getValueAtPath(key, output)))
|
|
41
|
+
await fill(key, config);
|
|
42
|
+
}
|
|
43
|
+
// The fields not sent, outside blocks and tree items: an empty stored value takes its default.
|
|
44
|
+
if (stored) {
|
|
45
|
+
for (const { field, path } of walkFields(fields, { determinate: true })) {
|
|
46
|
+
if (!isFormField(field) || field.get.defaultFill !== 'save')
|
|
47
|
+
continue;
|
|
48
|
+
if (getValueAtPath(path, output) !== undefined)
|
|
49
|
+
continue;
|
|
50
|
+
if (isEmpty(field, path, getValueAtPath(path, stored)))
|
|
51
|
+
await fill(path, field);
|
|
34
52
|
}
|
|
35
53
|
}
|
|
36
|
-
return {
|
|
37
|
-
...args,
|
|
38
|
-
data: output
|
|
39
|
-
};
|
|
54
|
+
return { ...args, data: output };
|
|
40
55
|
});
|
|
56
|
+
/** A field's own `isEmpty`, and not empty when it throws. */
|
|
57
|
+
const isEmpty = (config, key, value) => {
|
|
58
|
+
try {
|
|
59
|
+
return config.use.isEmpty(value);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
logger.warn(`Error in config.isEmpty for field ${key}`);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
41
66
|
/**
|
|
42
67
|
* This function convert any default value string | string[] of ids
|
|
43
68
|
* to a RelationValue from an existing relation record
|
|
@@ -142,7 +142,7 @@ export const validateFields = Hooks.beforeUpsert(async function validateFields(a
|
|
|
142
142
|
// This bit publicly-creatable collections in particular. FormFieldBuilder's default is
|
|
143
143
|
// `access.create: (user) => !!user`, so on an anonymous POST every field that does not
|
|
144
144
|
// override it gets stripped, and each `.required()` one then 400s no matter what was
|
|
145
|
-
// sent. A denied field is not the caller's to provide; it keeps whatever the
|
|
145
|
+
// sent. A denied field is not the caller's to provide; it keeps whatever the initial
|
|
146
146
|
// document or the column default gives it.
|
|
147
147
|
if (config.get.required && !accessDenied && config.use.isEmpty(value)) {
|
|
148
148
|
if (skipRequired) {
|
|
@@ -156,11 +156,10 @@ export const readDocuments = async (args) => {
|
|
|
156
156
|
throw row.reason;
|
|
157
157
|
const document = await buildDocument(row.value, {
|
|
158
158
|
config,
|
|
159
|
-
event,
|
|
160
159
|
locale,
|
|
161
160
|
depth,
|
|
162
161
|
populated,
|
|
163
|
-
|
|
162
|
+
allFields: !hasSelect,
|
|
164
163
|
/**
|
|
165
164
|
* The panel edits blocks and tree nodes in place, so it needs each child row's own
|
|
166
165
|
* bookkeeping — `position`, `path`, `ownerId`, `locale` — kept on it.
|
|
@@ -21,10 +21,8 @@ export type AreaApiArgs = {
|
|
|
21
21
|
* anywhere in these signatures. That is the whole difference from a collection, and it is why
|
|
22
22
|
* this is its own class rather than a collection with a flag.
|
|
23
23
|
*
|
|
24
|
-
* `
|
|
25
|
-
* lists no `auth`. The collection's strips auth's private members
|
|
26
|
-
* `prototypeContext` with a `shapeBlank(doc, config, intent)` between them, for a branch neither
|
|
27
|
-
* kind could reach.
|
|
24
|
+
* `initial()` is the document as its fields default it, full stop: no auth step, because an area
|
|
25
|
+
* lists no `auth`. The collection's strips auth's private members.
|
|
28
26
|
*/
|
|
29
27
|
declare class AreaAPI<Doc extends GenericDoc> implements PrototypeApiContext<BuiltArea> {
|
|
30
28
|
private readonly args;
|
|
@@ -42,7 +40,7 @@ declare class AreaAPI<Doc extends GenericDoc> implements PrototypeApiContext<Bui
|
|
|
42
40
|
*/
|
|
43
41
|
system(isSystem?: boolean): AreaAPI<Doc>;
|
|
44
42
|
/** The area's document with every default applied. */
|
|
45
|
-
|
|
43
|
+
initial(): Doc;
|
|
46
44
|
/** The locale to act in: the one asked for, else the request's, else the config's default. */
|
|
47
45
|
fallbackLocale(locale?: string): string | undefined;
|
|
48
46
|
/** Which version row a read means — see `versionsReadQuery`. */
|
|
@@ -86,6 +84,6 @@ export declare const areaApi: <Doc extends GenericDoc>(args: AreaApiArgs) => Are
|
|
|
86
84
|
* What `rime.area(slug)` hands back — written out, not read off the class. See the note on
|
|
87
85
|
* `CollectionApi` for why the plumbing must not appear in this type.
|
|
88
86
|
*/
|
|
89
|
-
export type AreaApi<Doc extends GenericDoc = GenericDoc> = Pick<AreaAPI<Doc>, 'config' | '
|
|
87
|
+
export type AreaApi<Doc extends GenericDoc = GenericDoc> = Pick<AreaAPI<Doc>, 'config' | 'initial' | 'find' | 'update' | 'system'>;
|
|
90
88
|
export type AreaAccessor = <Slug extends keyof RegisterArea>(slug: Slug) => AreaApi<RegisterArea[Slug]>;
|
|
91
89
|
export {};
|
|
@@ -9,10 +9,8 @@ import { update } from './operations/update.js';
|
|
|
9
9
|
* anywhere in these signatures. That is the whole difference from a collection, and it is why
|
|
10
10
|
* this is its own class rather than a collection with a flag.
|
|
11
11
|
*
|
|
12
|
-
* `
|
|
13
|
-
* lists no `auth`. The collection's strips auth's private members
|
|
14
|
-
* `prototypeContext` with a `shapeBlank(doc, config, intent)` between them, for a branch neither
|
|
15
|
-
* kind could reach.
|
|
12
|
+
* `initial()` is the document as its fields default it, full stop: no auth step, because an area
|
|
13
|
+
* lists no `auth`. The collection's strips auth's private members.
|
|
16
14
|
*/
|
|
17
15
|
class AreaAPI {
|
|
18
16
|
args;
|
|
@@ -38,8 +36,8 @@ class AreaAPI {
|
|
|
38
36
|
return isSystem ? new AreaAPI(this.args, true) : this;
|
|
39
37
|
}
|
|
40
38
|
/** The area's document with every default applied. */
|
|
41
|
-
|
|
42
|
-
return this.config.
|
|
39
|
+
initial() {
|
|
40
|
+
return this.config.initial(this.event);
|
|
43
41
|
}
|
|
44
42
|
/** The locale to act in: the one asked for, else the request's, else the config's default. */
|
|
45
43
|
fallbackLocale(locale) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { buildConfigMap } from '../../pipeline/config-map/index.js';
|
|
2
|
+
import { persistRelational } from '../../pipeline/run.server.js';
|
|
1
3
|
import { definePrototype } from '../define.js';
|
|
2
|
-
import {
|
|
4
|
+
import { initialVersion } from '../shared/versions/initial.js';
|
|
3
5
|
import { area as base } from './definition.js';
|
|
4
6
|
import { areaHooks } from './hooks.server.js';
|
|
5
7
|
import { rest } from './rest/index.server.js';
|
|
@@ -21,19 +23,31 @@ export const area = definePrototype({
|
|
|
21
23
|
hooks: areaHooks,
|
|
22
24
|
boot: async ({ config, adapter, defaultLocale }) => {
|
|
23
25
|
/**
|
|
24
|
-
* No request event: boot has no request. `
|
|
26
|
+
* No request event: boot has no request. `initial` takes one only to pass to a field's
|
|
25
27
|
* `defaultValue({ event })`, which already declares it optional — so a default that reads it
|
|
26
28
|
* gets `undefined` here rather than whichever request arrived first.
|
|
27
29
|
*
|
|
28
30
|
* The locale is the config's default for the same reason: the locale of an area's first row
|
|
29
31
|
* is a property of the config, not of its first reader.
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
// A versioned area's first row is its published version, unlike a draft a create starts.
|
|
34
|
+
const initial = initialVersion(config.initial(), config);
|
|
35
|
+
const created = await adapter
|
|
36
|
+
.area(config.slug)
|
|
37
|
+
.ensureExists({ initial, locale: defaultLocale });
|
|
38
|
+
// The first boot is the area's create: the blocks, tree items and relations of its initial
|
|
39
|
+
// document are written with it, on the row they hang off.
|
|
40
|
+
if (created) {
|
|
41
|
+
const configMap = buildConfigMap(initial, config.fields);
|
|
42
|
+
await persistRelational({
|
|
43
|
+
context: { params: { locale: defaultLocale }, configMap },
|
|
44
|
+
ownerId: created.contentId,
|
|
45
|
+
data: initial,
|
|
46
|
+
incomingPaths: Object.keys(configMap),
|
|
47
|
+
adapter,
|
|
48
|
+
config,
|
|
49
|
+
locale: defaultLocale
|
|
50
|
+
});
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
53
|
});
|
|
@@ -53,8 +53,8 @@ export const areaHooks = {
|
|
|
53
53
|
when(isVersioned, versions.handleNewVersion),
|
|
54
54
|
// Between the two, for the reasons the collection's list gives.
|
|
55
55
|
metas.stampUpdatedBy,
|
|
56
|
-
buildDataConfigMap,
|
|
57
56
|
setDefaultValues,
|
|
57
|
+
buildDataConfigMap,
|
|
58
58
|
normalizeResolvedReferences,
|
|
59
59
|
validateFields,
|
|
60
60
|
when(isVersioned, versions.demoteOtherVersions)
|
|
@@ -49,7 +49,7 @@ declare class CollectionAPI<Doc extends RegisterCollection[CollectionSlug]> impl
|
|
|
49
49
|
*/
|
|
50
50
|
system(isSystem?: boolean): CollectionAPI<Doc>;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* What a new document of this collection starts with: every default applied, and no id.
|
|
53
53
|
*
|
|
54
54
|
* An auth collection hands back nothing private. Only a collection signs in, which is why this
|
|
55
55
|
* step is here and not on the area's.
|
|
@@ -57,11 +57,10 @@ declare class CollectionAPI<Doc extends RegisterCollection[CollectionSlug]> impl
|
|
|
57
57
|
* **Likely dead, to be checked and dropped.** `withoutPrivateFields` strips `PRIVATE_FIELDS`, and
|
|
58
58
|
* of those only `apiKeyId` is ever a member of `config.fields` — `augment.ts` adds it, hidden, on
|
|
59
59
|
* an apiKey collection. `password` is appended per-operation by `augmentFieldsPassword`, which
|
|
60
|
-
* runs *after* the
|
|
61
|
-
* this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
|
|
62
|
-
* that holds, an auth collection's blank is a blank like any other and this line is ceremony.
|
|
60
|
+
* runs *after* the initial merge, and the rest are columns no field declares. So the one member
|
|
61
|
+
* this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
|
|
63
62
|
*/
|
|
64
|
-
|
|
63
|
+
initial(): Doc;
|
|
65
64
|
/** The locale to act in: the one asked for, else the request's, else the config's default. */
|
|
66
65
|
fallbackLocale(locale?: string): string | undefined;
|
|
67
66
|
/** Which version row a read means — see `versionsReadQuery`. */
|
|
@@ -194,6 +193,6 @@ export declare const collectionApi: <Doc extends RegisterCollection[CollectionSl
|
|
|
194
193
|
* itself and every `rime.collection(...)` in the repo would resolve to `never`. Each operation
|
|
195
194
|
* exports its caller-facing arguments separately for the same reason.
|
|
196
195
|
*/
|
|
197
|
-
export type CollectionApi<Doc extends RegisterCollection[CollectionSlug] = RegisterCollection[CollectionSlug]> = Pick<CollectionAPI<Doc>, 'config' | '
|
|
196
|
+
export type CollectionApi<Doc extends RegisterCollection[CollectionSlug] = RegisterCollection[CollectionSlug]> = Pick<CollectionAPI<Doc>, 'config' | 'initial' | 'create' | 'duplicate' | 'find' | 'findById' | 'findByIds' | 'updateById' | 'updateSlugById' | 'deleteById' | 'delete' | 'system'>;
|
|
198
197
|
export type CollectionAccessor = <Slug extends keyof RegisterCollection>(slug: Slug) => CollectionApi<RegisterCollection[Slug]>;
|
|
199
198
|
export {};
|
|
@@ -48,7 +48,7 @@ class CollectionAPI {
|
|
|
48
48
|
return isSystem ? new CollectionAPI(this.args, true) : this;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* What a new document of this collection starts with: every default applied, and no id.
|
|
52
52
|
*
|
|
53
53
|
* An auth collection hands back nothing private. Only a collection signs in, which is why this
|
|
54
54
|
* step is here and not on the area's.
|
|
@@ -56,12 +56,11 @@ class CollectionAPI {
|
|
|
56
56
|
* **Likely dead, to be checked and dropped.** `withoutPrivateFields` strips `PRIVATE_FIELDS`, and
|
|
57
57
|
* of those only `apiKeyId` is ever a member of `config.fields` — `augment.ts` adds it, hidden, on
|
|
58
58
|
* an apiKey collection. `password` is appended per-operation by `augmentFieldsPassword`, which
|
|
59
|
-
* runs *after* the
|
|
60
|
-
* this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
|
|
61
|
-
* that holds, an auth collection's blank is a blank like any other and this line is ceremony.
|
|
59
|
+
* runs *after* the initial merge, and the rest are columns no field declares. So the one member
|
|
60
|
+
* this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
|
|
62
61
|
*/
|
|
63
|
-
|
|
64
|
-
const doc = this.config.
|
|
62
|
+
initial() {
|
|
63
|
+
const doc = this.config.initial(this.event);
|
|
65
64
|
return (isAuth(this.config) ? withoutPrivateFields(doc) : doc);
|
|
66
65
|
}
|
|
67
66
|
/** The locale to act in: the one asked for, else the request's, else the config's default. */
|