@terminalfour/terminalfour-js 1.0.1 → 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.
- package/dist/cjs/resources/content-type-resource.d.ts +17 -0
- package/dist/cjs/resources/content-type-resource.js +24 -0
- package/dist/esm/resources/content-type-resource.d.ts +17 -0
- package/dist/esm/resources/content-type-resource.js +24 -0
- package/docs/content-types.md +32 -0
- package/package.json +1 -1
|
@@ -239,6 +239,23 @@ export declare class ContentTypeResource {
|
|
|
239
239
|
maxRepeats?: number;
|
|
240
240
|
};
|
|
241
241
|
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Existing fields to modify, matched by `name`. Only the provided
|
|
244
|
+
* properties are changed; omitted ones are left as-is. Use this to change
|
|
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).
|
|
249
|
+
*/
|
|
250
|
+
updateFields?: Array<{
|
|
251
|
+
name: string;
|
|
252
|
+
/** New name for the element. Renames are blocked on system content types. */
|
|
253
|
+
newName?: string;
|
|
254
|
+
maxSize?: number;
|
|
255
|
+
description?: string;
|
|
256
|
+
required?: boolean;
|
|
257
|
+
shown?: boolean;
|
|
258
|
+
}>;
|
|
242
259
|
/** Field names to remove from the content type */
|
|
243
260
|
removeFields?: string[];
|
|
244
261
|
}): Promise<ContentType>;
|
|
@@ -809,6 +809,30 @@ class ContentTypeResource {
|
|
|
809
809
|
ct.sharedGroups = data.sharedGroups;
|
|
810
810
|
if (data.primaryGroup !== undefined)
|
|
811
811
|
ct.primaryGroup = data.primaryGroup;
|
|
812
|
+
if (data.updateFields) {
|
|
813
|
+
for (const change of data.updateFields) {
|
|
814
|
+
const field = ct.fields[change.name];
|
|
815
|
+
if (!field) {
|
|
816
|
+
throw new Error(`Cannot update field "${change.name}" because it does not exist on content type "${ct.name}".`);
|
|
817
|
+
}
|
|
818
|
+
if (change.maxSize !== undefined)
|
|
819
|
+
field.maxSize = change.maxSize;
|
|
820
|
+
if (change.description !== undefined)
|
|
821
|
+
field.description = change.description;
|
|
822
|
+
if (change.required !== undefined)
|
|
823
|
+
field.required = change.required;
|
|
824
|
+
if (change.shown !== undefined)
|
|
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
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
812
836
|
if (data.removeFields) {
|
|
813
837
|
for (const fieldName of data.removeFields) {
|
|
814
838
|
ct.removeField(fieldName);
|
|
@@ -239,6 +239,23 @@ export declare class ContentTypeResource {
|
|
|
239
239
|
maxRepeats?: number;
|
|
240
240
|
};
|
|
241
241
|
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Existing fields to modify, matched by `name`. Only the provided
|
|
244
|
+
* properties are changed; omitted ones are left as-is. Use this to change
|
|
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).
|
|
249
|
+
*/
|
|
250
|
+
updateFields?: Array<{
|
|
251
|
+
name: string;
|
|
252
|
+
/** New name for the element. Renames are blocked on system content types. */
|
|
253
|
+
newName?: string;
|
|
254
|
+
maxSize?: number;
|
|
255
|
+
description?: string;
|
|
256
|
+
required?: boolean;
|
|
257
|
+
shown?: boolean;
|
|
258
|
+
}>;
|
|
242
259
|
/** Field names to remove from the content type */
|
|
243
260
|
removeFields?: string[];
|
|
244
261
|
}): Promise<ContentType>;
|
|
@@ -804,6 +804,30 @@ export class ContentTypeResource {
|
|
|
804
804
|
ct.sharedGroups = data.sharedGroups;
|
|
805
805
|
if (data.primaryGroup !== undefined)
|
|
806
806
|
ct.primaryGroup = data.primaryGroup;
|
|
807
|
+
if (data.updateFields) {
|
|
808
|
+
for (const change of data.updateFields) {
|
|
809
|
+
const field = ct.fields[change.name];
|
|
810
|
+
if (!field) {
|
|
811
|
+
throw new Error(`Cannot update field "${change.name}" because it does not exist on content type "${ct.name}".`);
|
|
812
|
+
}
|
|
813
|
+
if (change.maxSize !== undefined)
|
|
814
|
+
field.maxSize = change.maxSize;
|
|
815
|
+
if (change.description !== undefined)
|
|
816
|
+
field.description = change.description;
|
|
817
|
+
if (change.required !== undefined)
|
|
818
|
+
field.required = change.required;
|
|
819
|
+
if (change.shown !== undefined)
|
|
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
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
807
831
|
if (data.removeFields) {
|
|
808
832
|
for (const fieldName of data.removeFields) {
|
|
809
833
|
ct.removeField(fieldName);
|
package/docs/content-types.md
CHANGED
|
@@ -167,6 +167,36 @@ 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
|
+
|
|
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`):
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
await t4.contentTypes.update(44, {
|
|
176
|
+
updateFields: [
|
|
177
|
+
{ name: 'Title', maxSize: 500 },
|
|
178
|
+
{ name: 'Summary', description: 'Short teaser', required: true, shown: false },
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
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*.
|
|
197
|
+
|
|
198
|
+
`updateFields`, `removeFields`, and `addFields` can be combined in a single call; updates are applied first, then removals, then additions.
|
|
199
|
+
|
|
170
200
|
### Mutable item
|
|
171
201
|
|
|
172
202
|
```typescript
|
|
@@ -225,6 +255,8 @@ contentType.removeField('Old Field');
|
|
|
225
255
|
await contentType.save();
|
|
226
256
|
```
|
|
227
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
|
+
|
|
228
260
|
Delete a content type through the resource:
|
|
229
261
|
|
|
230
262
|
```typescript
|