@terminalfour/terminalfour-js 1.0.2 → 1.0.3
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.
|
@@ -242,11 +242,15 @@ export declare class ContentTypeResource {
|
|
|
242
242
|
/**
|
|
243
243
|
* Existing fields to modify, matched by `name`. Only the provided
|
|
244
244
|
* properties are changed; omitted ones are left as-is. Use this to change
|
|
245
|
-
* an element's length (`maxSize`), description,
|
|
246
|
-
* flags
|
|
245
|
+
* an element's length (`maxSize`), description, its `required`/`shown`
|
|
246
|
+
* flags, or to rename it with `newName`. Throws if a named field does not
|
|
247
|
+
* exist on the content type. Renaming an element on a system content type
|
|
248
|
+
* is blocked (except the Section Meta Data and Extended User types).
|
|
247
249
|
*/
|
|
248
250
|
updateFields?: Array<{
|
|
249
251
|
name: string;
|
|
252
|
+
/** New name for the element. Renames are blocked on system content types. */
|
|
253
|
+
newName?: string;
|
|
250
254
|
maxSize?: number;
|
|
251
255
|
description?: string;
|
|
252
256
|
required?: boolean;
|
|
@@ -823,6 +823,14 @@ class ContentTypeResource {
|
|
|
823
823
|
field.required = change.required;
|
|
824
824
|
if (change.shown !== undefined)
|
|
825
825
|
field.shown = change.shown;
|
|
826
|
+
// Rename last: save() detects the change against the element's _elementId
|
|
827
|
+
// link and applies the system content type rename guard. Re-key the
|
|
828
|
+
// fields record so the returned model is addressable by the new name.
|
|
829
|
+
if (change.newName !== undefined && change.newName !== change.name) {
|
|
830
|
+
field.name = change.newName;
|
|
831
|
+
ct.fields[change.newName] = field;
|
|
832
|
+
delete ct.fields[change.name];
|
|
833
|
+
}
|
|
826
834
|
}
|
|
827
835
|
}
|
|
828
836
|
if (data.removeFields) {
|
|
@@ -242,11 +242,15 @@ export declare class ContentTypeResource {
|
|
|
242
242
|
/**
|
|
243
243
|
* Existing fields to modify, matched by `name`. Only the provided
|
|
244
244
|
* properties are changed; omitted ones are left as-is. Use this to change
|
|
245
|
-
* an element's length (`maxSize`), description,
|
|
246
|
-
* flags
|
|
245
|
+
* an element's length (`maxSize`), description, its `required`/`shown`
|
|
246
|
+
* flags, or to rename it with `newName`. Throws if a named field does not
|
|
247
|
+
* exist on the content type. Renaming an element on a system content type
|
|
248
|
+
* is blocked (except the Section Meta Data and Extended User types).
|
|
247
249
|
*/
|
|
248
250
|
updateFields?: Array<{
|
|
249
251
|
name: string;
|
|
252
|
+
/** New name for the element. Renames are blocked on system content types. */
|
|
253
|
+
newName?: string;
|
|
250
254
|
maxSize?: number;
|
|
251
255
|
description?: string;
|
|
252
256
|
required?: boolean;
|
|
@@ -818,6 +818,14 @@ export class ContentTypeResource {
|
|
|
818
818
|
field.required = change.required;
|
|
819
819
|
if (change.shown !== undefined)
|
|
820
820
|
field.shown = change.shown;
|
|
821
|
+
// Rename last: save() detects the change against the element's _elementId
|
|
822
|
+
// link and applies the system content type rename guard. Re-key the
|
|
823
|
+
// fields record so the returned model is addressable by the new name.
|
|
824
|
+
if (change.newName !== undefined && change.newName !== change.name) {
|
|
825
|
+
field.name = change.newName;
|
|
826
|
+
ct.fields[change.newName] = field;
|
|
827
|
+
delete ct.fields[change.name];
|
|
828
|
+
}
|
|
821
829
|
}
|
|
822
830
|
}
|
|
823
831
|
if (data.removeFields) {
|
package/docs/content-types.md
CHANGED
|
@@ -167,6 +167,8 @@ await t4.contentTypes.update(44, {
|
|
|
167
167
|
});
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
+
> **Warning:** Removing a field deletes that element's content from every content item using this content type, and it cannot be recovered. Only remove a field when you're certain the data is no longer needed. To change a field's length, description, or name, use `updateFields` rather than removing and re-adding.
|
|
171
|
+
|
|
170
172
|
Change properties of existing fields with `updateFields`. Fields are matched by `name`, and only the properties you supply are changed — anything you omit is left as-is. This is how you increase an element's length (`maxSize`):
|
|
171
173
|
|
|
172
174
|
```typescript
|
|
@@ -178,7 +180,20 @@ await t4.contentTypes.update(44, {
|
|
|
178
180
|
});
|
|
179
181
|
```
|
|
180
182
|
|
|
181
|
-
|
|
183
|
+
Rename an existing element with `newName`. The field is matched by its current `name`, and you can rename and change other properties in the same entry:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
await t4.contentTypes.update(44, {
|
|
187
|
+
updateFields: [
|
|
188
|
+
{ name: 'Title', newName: 'Headline' },
|
|
189
|
+
{ name: 'Summary', newName: 'Teaser', maxSize: 300 },
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
After a rename, the returned content type is addressable by the new name (`ct.fields['Headline']`); the old key no longer exists.
|
|
195
|
+
|
|
196
|
+
`updateFields` can change `maxSize`, `description`, `required`, `shown`, and `newName` (rename). It throws if a named field does not exist on the content type, and (like the other field operations) nothing is sent to T4 when it throws. Renaming an element on a system content type is blocked, except on the Section Meta Data and Extended User types (the same rule that applies to renames through the mutable pattern). It's currently not possible to change a field's *type*.
|
|
182
197
|
|
|
183
198
|
`updateFields`, `removeFields`, and `addFields` can be combined in a single call; updates are applied first, then removals, then additions.
|
|
184
199
|
|
|
@@ -240,6 +255,8 @@ contentType.removeField('Old Field');
|
|
|
240
255
|
await contentType.save();
|
|
241
256
|
```
|
|
242
257
|
|
|
258
|
+
> **Warning:** `removeField()` deletes the element's content from every content item using this content type once you `save()`, and it cannot be recovered. Prefer `updateFields` (or mutating the field directly) to change a field's length, description, or name.
|
|
259
|
+
|
|
243
260
|
Delete a content type through the resource:
|
|
244
261
|
|
|
245
262
|
```typescript
|