@terminalfour/terminalfour-js 1.0.1 → 1.0.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/cjs/resources/content-type-resource.d.ts +13 -0
- package/dist/cjs/resources/content-type-resource.js +16 -0
- package/dist/esm/resources/content-type-resource.d.ts +13 -0
- package/dist/esm/resources/content-type-resource.js +16 -0
- package/docs/content-types.md +15 -0
- package/package.json +1 -1
|
@@ -239,6 +239,19 @@ 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, or its `required`/`shown`
|
|
246
|
+
* flags. Throws if a named field does not exist on the content type.
|
|
247
|
+
*/
|
|
248
|
+
updateFields?: Array<{
|
|
249
|
+
name: string;
|
|
250
|
+
maxSize?: number;
|
|
251
|
+
description?: string;
|
|
252
|
+
required?: boolean;
|
|
253
|
+
shown?: boolean;
|
|
254
|
+
}>;
|
|
242
255
|
/** Field names to remove from the content type */
|
|
243
256
|
removeFields?: string[];
|
|
244
257
|
}): Promise<ContentType>;
|
|
@@ -809,6 +809,22 @@ 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
|
+
}
|
|
827
|
+
}
|
|
812
828
|
if (data.removeFields) {
|
|
813
829
|
for (const fieldName of data.removeFields) {
|
|
814
830
|
ct.removeField(fieldName);
|
|
@@ -239,6 +239,19 @@ 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, or its `required`/`shown`
|
|
246
|
+
* flags. Throws if a named field does not exist on the content type.
|
|
247
|
+
*/
|
|
248
|
+
updateFields?: Array<{
|
|
249
|
+
name: string;
|
|
250
|
+
maxSize?: number;
|
|
251
|
+
description?: string;
|
|
252
|
+
required?: boolean;
|
|
253
|
+
shown?: boolean;
|
|
254
|
+
}>;
|
|
242
255
|
/** Field names to remove from the content type */
|
|
243
256
|
removeFields?: string[];
|
|
244
257
|
}): Promise<ContentType>;
|
|
@@ -804,6 +804,22 @@ 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
|
+
}
|
|
822
|
+
}
|
|
807
823
|
if (data.removeFields) {
|
|
808
824
|
for (const fieldName of data.removeFields) {
|
|
809
825
|
ct.removeField(fieldName);
|
package/docs/content-types.md
CHANGED
|
@@ -167,6 +167,21 @@ await t4.contentTypes.update(44, {
|
|
|
167
167
|
});
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
+
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
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
await t4.contentTypes.update(44, {
|
|
174
|
+
updateFields: [
|
|
175
|
+
{ name: 'Title', maxSize: 500 },
|
|
176
|
+
{ name: 'Summary', description: 'Short teaser', required: true, shown: false },
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`updateFields` can change `maxSize`, `description`, `required`, and `shown`. 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. To change a field's *type* or *name*, remove it and add a new one instead.
|
|
182
|
+
|
|
183
|
+
`updateFields`, `removeFields`, and `addFields` can be combined in a single call; updates are applied first, then removals, then additions.
|
|
184
|
+
|
|
170
185
|
### Mutable item
|
|
171
186
|
|
|
172
187
|
```typescript
|