lucid-extension-sdk
Advanced tools
Comparing version
@@ -14,3 +14,3 @@ import { SemanticCollection } from '../core/data/datasource/semanticcollection'; | ||
import { DataUpdateFilterType } from '../data/dataupdatefiltertype'; | ||
import { FieldDefinition, SchemaDefinition } from '../data/schemadefinition'; | ||
import { FieldConstraintDefinition, FieldDefinition, SchemaDefinition } from '../data/schemadefinition'; | ||
/** | ||
@@ -36,3 +36,3 @@ * Container for an update to a data source | ||
}; | ||
type SerializedFieldConstraintForApi = { | ||
export type SerializedFieldConstraintForApi = { | ||
'type': FieldConstraintType; | ||
@@ -71,2 +71,3 @@ 'details'?: JsonSerializable; | ||
errors?: Map<string, SerializedLucidDictionary> | undefined; | ||
fieldConstraintsPerItem?: Map<string, Map<string, FieldConstraintDefinition[]>> | undefined; | ||
private readonly _brand; | ||
@@ -80,3 +81,3 @@ constructor( | ||
/** Items to remove from the collection, based on the same primary key algorithm. */ | ||
itemsDeleted?: string[] | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined); | ||
itemsDeleted?: string[] | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined, fieldConstraintsPerItem?: Map<string, Map<string, FieldConstraintDefinition[]>> | undefined); | ||
} | ||
@@ -88,4 +89,5 @@ export declare class ItemsPatchExhaustive { | ||
errors?: Map<string, SerializedLucidDictionary> | undefined; | ||
fieldConstraintsPerItem?: Map<string, Map<string, FieldConstraintDefinition[]>> | undefined; | ||
private readonly _brand; | ||
constructor(items: Map<string, SerializedFields>, rekeyingMap?: Map<string, string | null> | undefined, fieldNamesChanged?: Map<string, string | null> | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined); | ||
constructor(items: Map<string, SerializedFields>, rekeyingMap?: Map<string, string | null> | undefined, fieldNamesChanged?: Map<string, string | null> | undefined, errors?: Map<string, SerializedLucidDictionary> | undefined, fieldConstraintsPerItem?: Map<string, Map<string, FieldConstraintDefinition[]>> | undefined); | ||
} | ||
@@ -102,2 +104,7 @@ export type ItemsPatch = { | ||
errors?: Map<string, SerializedLucidDictionary>; | ||
/** | ||
*Constraints that can be defined on a per-item basis to conditionally lock fields for a specific item. | ||
*The key for this map is the primary key of an item, and the value is a map from the name a field on that item to the constraints that should be applied to that field. | ||
*/ | ||
fieldConstraintsPerItem?: Map<string, Map<string, FieldConstraintDefinition[]>>; | ||
} | ItemsPatchInexhaustive | ItemsPatchExhaustive; | ||
@@ -108,2 +115,3 @@ export type SerializedItemsPatch = { | ||
'errors'?: Record<string, SerializedLucidDictionary>; | ||
'fieldConstraintsPerItem'?: Record<string, Record<string, SerializedFieldConstraintForApi[]>>; | ||
} | { | ||
@@ -114,2 +122,3 @@ 'exhaustiveItems': Record<string, SerializedFields>; | ||
'errors'?: Record<string, SerializedLucidDictionary>; | ||
'fieldConstraintsPerItem'?: Record<string, Record<string, SerializedFieldConstraintForApi[]>>; | ||
}; | ||
@@ -116,0 +125,0 @@ export declare function serializeItemsPatch(patch: ItemsPatch): SerializedItemsPatch; |
@@ -16,6 +16,7 @@ "use strict"; | ||
/** Items to remove from the collection, based on the same primary key algorithm. */ | ||
itemsDeleted, errors) { | ||
itemsDeleted, errors, fieldConstraintsPerItem) { | ||
this.items = items; | ||
this.itemsDeleted = itemsDeleted; | ||
this.errors = errors; | ||
this.fieldConstraintsPerItem = fieldConstraintsPerItem; | ||
this._brand = ItemsPatchInexhaustive; | ||
@@ -26,3 +27,3 @@ } | ||
class ItemsPatchExhaustive { | ||
constructor(items, rekeyingMap, fieldNamesChanged, errors) { | ||
constructor(items, rekeyingMap, fieldNamesChanged, errors, fieldConstraintsPerItem) { | ||
this.items = items; | ||
@@ -32,2 +33,3 @@ this.rekeyingMap = rekeyingMap; | ||
this.errors = errors; | ||
this.fieldConstraintsPerItem = fieldConstraintsPerItem; | ||
this._brand = ItemsPatchExhaustive; | ||
@@ -37,5 +39,2 @@ } | ||
exports.ItemsPatchExhaustive = ItemsPatchExhaustive; | ||
function serializeErrors(errors) { | ||
return errors && { 'errors': (0, object_1.fromEntries)(errors) }; | ||
} | ||
function serializeRekeyingMap(rekeyingMap) { | ||
@@ -47,9 +46,25 @@ return rekeyingMap && { 'rekeyingMap': (0, object_1.fromEntries)(rekeyingMap) }; | ||
} | ||
function serializeErrors(errors) { | ||
return errors && { 'errors': (0, object_1.fromEntries)(errors) }; | ||
} | ||
function serializeFieldConstraintsPerItem(fieldConstraintsPerItem) { | ||
if (!fieldConstraintsPerItem) { | ||
return undefined; | ||
} | ||
const result = {}; | ||
fieldConstraintsPerItem.forEach((fieldNameToConstraints, key) => { | ||
result[key] = {}; | ||
fieldNameToConstraints.forEach((constraints, fieldName) => { | ||
result[key][fieldName] = constraints.map(serializeFieldConstraintForApi); | ||
}); | ||
}); | ||
return { fieldConstraintsPerItem: result }; | ||
} | ||
function serializeItemsPatch(patch) { | ||
var _a; | ||
if (patch instanceof ItemsPatchExhaustive) { | ||
return Object.assign(Object.assign(Object.assign({ 'exhaustiveItems': (0, object_1.fromEntries)(patch.items.entries()) }, serializeRekeyingMap(patch.rekeyingMap)), serializeFieldNamesChanged(patch.fieldNamesChanged)), serializeErrors(patch.errors)); | ||
return Object.assign(Object.assign(Object.assign(Object.assign({ 'exhaustiveItems': (0, object_1.fromEntries)(patch.items.entries()) }, serializeRekeyingMap(patch.rekeyingMap)), serializeFieldNamesChanged(patch.fieldNamesChanged)), serializeErrors(patch.errors)), serializeFieldConstraintsPerItem(patch.fieldConstraintsPerItem)); | ||
} | ||
else { | ||
return Object.assign({ 'items': (0, object_1.fromEntries)(patch.items.entries()), 'itemsDeleted': (_a = patch.itemsDeleted) !== null && _a !== void 0 ? _a : [] }, serializeErrors(patch.errors)); | ||
return Object.assign(Object.assign({ 'items': (0, object_1.fromEntries)(patch.items.entries()), 'itemsDeleted': (_a = patch.itemsDeleted) !== null && _a !== void 0 ? _a : [] }, serializeErrors(patch.errors)), serializeFieldConstraintsPerItem(patch.fieldConstraintsPerItem)); | ||
} | ||
@@ -56,0 +71,0 @@ } |
{ | ||
"name": "lucid-extension-sdk", | ||
"version": "0.0.375", | ||
"version": "0.0.376", | ||
"description": "Utility classes for writing Lucid Software editor extensions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
939848
0.19%21242
0.12%