Skip to content

Class: ShadowApplicationService ​

Defined in: application/services/core/ShadowService.ts:120

Schema-aware operations on the editing shadow of a document, bound to one profile schema and type library. Wraps the shadow model functions (normalize, patch, schema lookup) and adds helpers that editors use to render unions, arrays, identifiers and agents.

Example ​

ts
const shadow = new ShadowApplicationService(profile.schema, typeLibrary);
const view = shadow.normalize(doc.data, { seedEmpty: true });
const next = shadow.applyPatch(doc.data, path, newValue);
const label = shadow.deriveDocumentLabel(next);

Constructors ​

Constructor ​

ts
new ShadowApplicationService(profileSchema, typeLibrary?): ShadowApplicationService;

Defined in: application/services/core/ShadowService.ts:127

Parameters ​

ParameterTypeDescription
profileSchemaanyJSON Schema of the document profile.
typeLibrary?anyType library schema used to resolve $refs into its $defs.

Returns ​

ShadowApplicationService

Methods ​

applyPatch() ​

ts
applyPatch(
   documentData, 
   path, 
   value
): DocumentData;

Defined in: application/services/core/ShadowService.ts:154

Returns a normalized copy of the data with value written at path, coerced to the schema type there.

Parameters ​

ParameterType
documentDataDocumentData
pathPathSegment[]
valueany

Returns ​

DocumentData


buildSeedValueFromSchema() ​

ts
buildSeedValueFromSchema(fieldSchema, text?): any;

Defined in: application/services/core/ShadowService.ts:833

Builds an initial value for a field from plain text: a one-item Literal list for text-object array fields, the text itself for string fields, otherwise null.

Parameters ​

ParameterType
fieldSchemaany
text?string

Returns ​

any


createEmptyFromSchema() ​

ts
createEmptyFromSchema(schemaNode, options?): any;

Defined in: application/services/core/ShadowService.ts:179

Creates an empty value for a schema node. See the options of the shadow model's createEmptyFromSchema.

Parameters ​

ParameterType
schemaNodeany
options?{ includeRequired?: boolean; seedArrayItem?: boolean; }
options.includeRequired?boolean
options.seedArrayItem?boolean

Returns ​

any


createSeedForAddedField() ​

ts
createSeedForAddedField(fieldSchema): any;

Defined in: application/services/core/ShadowService.ts:702

Creates the initial value for a field the user has just added. Arrays get one empty item ([''] for Date items); unions use their first array branch when they have one.

Parameters ​

ParameterType
fieldSchemaany

Returns ​

any


createShadow() ​

ts
createShadow(documentData): DocumentData;

Defined in: application/services/core/ShadowService.ts:132

Builds the full editing shadow: normalized data merged into a template generated from the schema.

Parameters ​

ParameterType
documentDataDocumentData

Returns ​

DocumentData


deriveDocumentLabel() ​

ts
deriveDocumentLabel(documentData, options?): string;

Defined in: application/services/core/ShadowService.ts:849

Derives a display label for a document from its preferred seed field, then from the first other field with a plain string or a string text entry. Falls back to fallbackId, defaultLabel or Untitled.

Parameters ​

ParameterType
documentDataDocumentData | undefined
options?{ defaultLabel?: string; fallbackId?: string; profileSchema?: any; }
options.defaultLabel?string
options.fallbackId?string
options.profileSchema?any

Returns ​

string


getAllowedSchemas() ​

ts
getAllowedSchemas(schemaNode): IdentifierScheme[] | null;

Defined in: application/services/core/ShadowService.ts:579

Returns the identifier schemes listed in x-sidedoc.allowedSchemas of a schema node, or null if there are none. Known scheme names (such as ORCID, ROR or DOI) are expanded to their resolver URI, pattern and example; object entries inherit the pattern and example of a known scheme with the same URI.

Parameters ​

ParameterType
schemaNodeany

Returns ​

IdentifierScheme[] | null


getArrayPatterns() ​

ts
getArrayPatterns(input): object;

Defined in: application/services/core/ShadowService.ts:617

Derives how an array field should be edited: whether it is a translation list, nested language array or single multilingual value, its item limits, and whether more items can be added.

Parameters ​

ParameterType
input{ arraySchema: any; itemSchema: any; list: any[]; resolvedItemSchema: any; }
input.arraySchemaany
input.itemSchemaany
input.listany[]
input.resolvedItemSchemaany

Returns ​

object

canAddMore ​
ts
canAddMore: boolean;
hasItemUnion ​
ts
hasItemUnion: boolean;
isNestedLangArray ​
ts
isNestedLangArray: boolean;
isSingleMultilang ​
ts
isSingleMultilang: boolean;
isTranslationArray ​
ts
isTranslationArray: boolean;
maxAllowed ​
ts
maxAllowed: number;
minAllowed ​
ts
minAllowed: number;
showAddButton ​
ts
showAddButton: boolean;

getFieldDisplayLabel() ​

ts
getFieldDisplayLabel(fieldSchema, fallbackKey): string;

Defined in: application/services/core/ShadowService.ts:744

Display label for a field from x-sidedoc (labelSingularEn, labelSingular or label), falling back to a humanized form of fallbackKey.

Parameters ​

ParameterType
fieldSchemaany
fallbackKeystring

Returns ​

string


getMaxOccurrences() ​

ts
getMaxOccurrences(schemaNode): number;

Defined in: application/services/core/ShadowService.ts:174

Maximum number of items allowed by a schema node (Infinity when unbounded).

Parameters ​

ParameterType
schemaNodeany

Returns ​

number


getMinOccurrences() ​

ts
getMinOccurrences(schemaNode): number;

Defined in: application/services/core/ShadowService.ts:169

Minimum number of items allowed by a schema node (0 when unspecified).

Parameters ​

ParameterType
schemaNodeany

Returns ​

number


getPreferredSeedField() ​

ts
getPreferredSeedField(profileSchema?): object;

Defined in: application/services/core/ShadowService.ts:803

Picks the root field to seed from a title: title if present, then the first array field of text objects, then the first string field, then the first property.

Parameters ​

ParameterType
profileSchema?any

Returns ​

object

fieldName ​
ts
fieldName: string | null;
fieldSchema ​
ts
fieldSchema: any;

getSchemaForPath() ​

ts
getSchemaForPath(path): object;

Defined in: application/services/core/ShadowService.ts:159

Resolves the schema node and type name at path. Returns a null node when the path is not in the schema.

Parameters ​

ParameterType
pathPathSegment[]

Returns ​

object

node ​
ts
node: any;
refName ​
ts
refName: string | null;

getUnionLabel() ​

ts
getUnionLabel(schemaNode, index): string;

Defined in: application/services/core/ShadowService.ts:370

Display label for a union option: the type name, title, constant type value or JSON type, falling back to Option N.

Parameters ​

ParameterType
schemaNodeany
indexnumber

Returns ​

string


getUnionList() ​

ts
getUnionList(schemaNode): any[] | null;

Defined in: application/services/core/ShadowService.ts:283

Returns the alternatives of a union schema node (oneOf/anyOf, before or after resolving $ref), or null when the node is not a union. An array whose items are a union is expanded into one array option per item type. Branches that only add constraints (no type or shape of their own) do not count as a union.

Parameters ​

ParameterType
schemaNodeany

Returns ​

any[] | null


hasMeaningfulContent() ​

ts
hasMeaningfulContent(value): boolean;

Defined in: application/services/core/ShadowService.ts:265

True when a value contains any non-blank string, number or boolean, ignoring type and lang keys.

Parameters ​

ParameterType
valueany

Returns ​

boolean


isAgentLikeItem() ​

ts
isAgentLikeItem(schemaNode): boolean;

Defined in: application/services/core/ShadowService.ts:539

True when an object schema has string name, agentType and type properties, like an Agent value.

Parameters ​

ParameterType
schemaNodeany

Returns ​

boolean


isFieldPersistedPresent() ​

ts
isFieldPersistedPresent(
   parentValue, 
   key, 
   _isRequired?, 
   _parentPath?
): boolean;

Defined in: application/services/core/ShadowService.ts:684

True when parentValue has an own, non-null value for key. The last two parameters are currently unused.

Parameters ​

ParameterTypeDefault value
parentValueanyundefined
keystringundefined
_isRequired?booleanfalse
_parentPath?(string | number)[][]

Returns ​

boolean


isLiteralArrayField() ​

ts
isLiteralArrayField(fieldSchema): boolean;

Defined in: application/services/core/ShadowService.ts:673

True when the field is an array of objects that have a text property.

Parameters ​

ParameterType
fieldSchemaany

Returns ​

boolean


isUrlLikeItem() ​

ts
isUrlLikeItem(schemaNode): boolean;

Defined in: application/services/core/ShadowService.ts:530

True when an object schema has a string href and an array label, like a Url value.

Parameters ​

ParameterType
schemaNodeany

Returns ​

boolean


listAgents() ​

ts
listAgents(documentData, excludePath?): object[];

Defined in: application/services/core/ShadowService.ts:765

Lists all non-empty Agent values in the document data with their paths. Agents are returned as deep copies. The agent at excludePath is skipped.

Parameters ​

ParameterTypeDefault value
documentDataanyundefined
excludePath?PathSegment[] | nullnull

Returns ​

object[]


matchUnionIndex() ​

ts
matchUnionIndex(unionList, currentValue): number;

Defined in: application/services/core/ShadowService.ts:397

Returns the index of the union option that matches currentValue, or -1 if none matches or the value is null or undefined. Matching is based on the value's type and shape.

Parameters ​

ParameterType
unionListany[]
currentValueany

Returns ​

number


normalize() ​

ts
normalize(documentData, options?): DocumentData;

Defined in: application/services/core/ShadowService.ts:145

Normalizes document data against the profile schema.

Parameters ​

ParameterTypeDescription
documentDataDocumentData-
options?{ pruneEmpty?: boolean; seedEmpty?: boolean; }pruneEmpty drops blank Literal and RichText values (for load or clean passes); seedEmpty adds one blank starter item to empty multivalue fields (display only).
options.pruneEmpty?boolean-
options.seedEmpty?boolean-

Returns ​

DocumentData


pickTranslation() ​

ts
pickTranslation<T>(
   list, 
   targetLang?, 
   fallbackOrder?
): object;

Defined in: application/services/core/ShadowService.ts:270

Picks an entry by lang: first targetLang, then fallbackOrder, then any entry with a language.

Type Parameters ​

Type Parameter
T extends object

Parameters ​

ParameterTypeDefault value
listT[] | undefinedundefined
targetLang?stringundefined
fallbackOrder?string[][]

Returns ​

object

entry ​
ts
entry: T | null;
usedLang ​
ts
usedLang: string | null;

resolveSchemaNode() ​

ts
resolveSchemaNode(node): object;

Defined in: application/services/core/ShadowService.ts:164

Resolves $ref and takes the first oneOf/anyOf option of a schema node.

Parameters ​

ParameterType
nodeany

Returns ​

object

node ​
ts
node: any;
refName ​
ts
refName: string | null;

resolveVocabularyBinding() ​

ts
resolveVocabularyBinding(path): 
  | FieldVocabularyBinding
  | null;

Defined in: application/services/core/ShadowService.ts:188

Finds the vocabulary binding (x-sidedoc.vocab or x-sidedoc-vocab) for a field path. Array indexes and _value, type and lang segments are ignored, and all union branches are searched. When several levels declare a binding, the deepest one wins. Returns null if none is found.

Parameters ​

ParameterType
pathPathSegment[]

Returns ​

| FieldVocabularyBinding | null